Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2001-2020 Intel Corporation
3 : : */
4 : :
5 : : #include <inttypes.h>
6 : :
7 : : #include "i40e_type.h"
8 : : #include "i40e_adminq.h"
9 : : #include "i40e_prototype.h"
10 : : #include "virtchnl.h"
11 : :
12 : : /**
13 : : * i40e_set_mac_type - Sets MAC type
14 : : * @hw: pointer to the HW structure
15 : : *
16 : : * This function sets the mac type of the adapter based on the
17 : : * vendor ID and device ID stored in the hw structure.
18 : : **/
19 : 0 : enum i40e_status_code i40e_set_mac_type(struct i40e_hw *hw)
20 : : {
21 : : enum i40e_status_code status = I40E_SUCCESS;
22 : :
23 : 0 : DEBUGFUNC("i40e_set_mac_type\n");
24 : :
25 [ # # ]: 0 : if (hw->vendor_id == I40E_INTEL_VENDOR_ID) {
26 [ # # # # : 0 : switch (hw->device_id) {
# ]
27 : 0 : case I40E_DEV_ID_SFP_XL710:
28 : : case I40E_DEV_ID_QEMU:
29 : : case I40E_DEV_ID_KX_B:
30 : : case I40E_DEV_ID_KX_C:
31 : : case I40E_DEV_ID_QSFP_A:
32 : : case I40E_DEV_ID_QSFP_B:
33 : : case I40E_DEV_ID_QSFP_C:
34 : : case I40E_DEV_ID_10G_BASE_T:
35 : : case I40E_DEV_ID_10G_BASE_T4:
36 : : case I40E_DEV_ID_10G_BASE_T_BC:
37 : : case I40E_DEV_ID_10G_B:
38 : : case I40E_DEV_ID_10G_SFP:
39 : : case I40E_DEV_ID_5G_BASE_T_BC:
40 : : case I40E_DEV_ID_1G_BASE_T_BC:
41 : : case I40E_DEV_ID_20G_KR2:
42 : : case I40E_DEV_ID_20G_KR2_A:
43 : : case I40E_DEV_ID_25G_B:
44 : : case I40E_DEV_ID_25G_SFP28:
45 : : case I40E_DEV_ID_X710_N3000:
46 : : case I40E_DEV_ID_XXV710_N3000:
47 : 0 : hw->mac.type = I40E_MAC_XL710;
48 : 0 : break;
49 : : #ifdef X722_A0_SUPPORT
50 : 0 : case I40E_DEV_ID_X722_A0:
51 : : #endif
52 : : case I40E_DEV_ID_KX_X722:
53 : : case I40E_DEV_ID_QSFP_X722:
54 : : case I40E_DEV_ID_SFP_X722:
55 : : case I40E_DEV_ID_1G_BASE_T_X722:
56 : : case I40E_DEV_ID_10G_BASE_T_X722:
57 : : case I40E_DEV_ID_SFP_I_X722:
58 : : case I40E_DEV_ID_SFP_X722_A:
59 : 0 : hw->mac.type = I40E_MAC_X722;
60 : 0 : break;
61 : : #if defined(INTEGRATED_VF) || defined(VF_DRIVER)
62 : 0 : case I40E_DEV_ID_X722_VF:
63 : : #ifdef X722_A0_SUPPORT
64 : : case I40E_DEV_ID_X722_A0_VF:
65 : : #endif
66 : 0 : hw->mac.type = I40E_MAC_X722_VF;
67 : 0 : break;
68 : : #endif /* INTEGRATED_VF || VF_DRIVER */
69 : : #if defined(INTEGRATED_VF) || defined(VF_DRIVER)
70 : 0 : case I40E_DEV_ID_VF:
71 : : case I40E_DEV_ID_VF_HV:
72 : : case I40E_DEV_ID_ADAPTIVE_VF:
73 : 0 : hw->mac.type = I40E_MAC_VF;
74 : 0 : break;
75 : : #endif
76 : 0 : default:
77 : 0 : hw->mac.type = I40E_MAC_GENERIC;
78 : 0 : break;
79 : : }
80 : : } else {
81 : : status = I40E_ERR_DEVICE_NOT_SUPPORTED;
82 : : }
83 : :
84 : 0 : DEBUGOUT2("i40e_set_mac_type found mac: %d, returns: %d\n",
85 : : hw->mac.type, status);
86 : 0 : return status;
87 : : }
88 : :
89 : : /**
90 : : * i40e_aq_str - convert AQ err code to a string
91 : : * @hw: pointer to the HW structure
92 : : * @aq_err: the AQ error code to convert
93 : : **/
94 : 0 : const char *i40e_aq_str(struct i40e_hw *hw, enum i40e_admin_queue_err aq_err)
95 : : {
96 [ # # # # : 0 : switch (aq_err) {
# # # # #
# # # # #
# # # # #
# # # #
# ]
97 : : case I40E_AQ_RC_OK:
98 : : return "OK";
99 : 0 : case I40E_AQ_RC_EPERM:
100 : 0 : return "I40E_AQ_RC_EPERM";
101 : 0 : case I40E_AQ_RC_ENOENT:
102 : 0 : return "I40E_AQ_RC_ENOENT";
103 : 0 : case I40E_AQ_RC_ESRCH:
104 : 0 : return "I40E_AQ_RC_ESRCH";
105 : 0 : case I40E_AQ_RC_EINTR:
106 : 0 : return "I40E_AQ_RC_EINTR";
107 : 0 : case I40E_AQ_RC_EIO:
108 : 0 : return "I40E_AQ_RC_EIO";
109 : 0 : case I40E_AQ_RC_ENXIO:
110 : 0 : return "I40E_AQ_RC_ENXIO";
111 : 0 : case I40E_AQ_RC_E2BIG:
112 : 0 : return "I40E_AQ_RC_E2BIG";
113 : 0 : case I40E_AQ_RC_EAGAIN:
114 : 0 : return "I40E_AQ_RC_EAGAIN";
115 : 0 : case I40E_AQ_RC_ENOMEM:
116 : 0 : return "I40E_AQ_RC_ENOMEM";
117 : 0 : case I40E_AQ_RC_EACCES:
118 : 0 : return "I40E_AQ_RC_EACCES";
119 : 0 : case I40E_AQ_RC_EFAULT:
120 : 0 : return "I40E_AQ_RC_EFAULT";
121 : 0 : case I40E_AQ_RC_EBUSY:
122 : 0 : return "I40E_AQ_RC_EBUSY";
123 : 0 : case I40E_AQ_RC_EEXIST:
124 : 0 : return "I40E_AQ_RC_EEXIST";
125 : 0 : case I40E_AQ_RC_EINVAL:
126 : 0 : return "I40E_AQ_RC_EINVAL";
127 : 0 : case I40E_AQ_RC_ENOTTY:
128 : 0 : return "I40E_AQ_RC_ENOTTY";
129 : 0 : case I40E_AQ_RC_ENOSPC:
130 : 0 : return "I40E_AQ_RC_ENOSPC";
131 : 0 : case I40E_AQ_RC_ENOSYS:
132 : 0 : return "I40E_AQ_RC_ENOSYS";
133 : 0 : case I40E_AQ_RC_ERANGE:
134 : 0 : return "I40E_AQ_RC_ERANGE";
135 : 0 : case I40E_AQ_RC_EFLUSHED:
136 : 0 : return "I40E_AQ_RC_EFLUSHED";
137 : 0 : case I40E_AQ_RC_BAD_ADDR:
138 : 0 : return "I40E_AQ_RC_BAD_ADDR";
139 : 0 : case I40E_AQ_RC_EMODE:
140 : 0 : return "I40E_AQ_RC_EMODE";
141 : 0 : case I40E_AQ_RC_EFBIG:
142 : 0 : return "I40E_AQ_RC_EFBIG";
143 : : }
144 : :
145 : 0 : snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
146 : 0 : return hw->err_str;
147 : : }
148 : :
149 : : /**
150 : : * i40e_stat_str - convert status err code to a string
151 : : * @hw: pointer to the HW structure
152 : : * @stat_err: the status error code to convert
153 : : **/
154 : 0 : const char *i40e_stat_str(struct i40e_hw *hw, enum i40e_status_code stat_err)
155 : : {
156 [ # # # # : 0 : switch (stat_err) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
157 : : case I40E_SUCCESS:
158 : : return "OK";
159 : 0 : case I40E_ERR_NVM:
160 : 0 : return "I40E_ERR_NVM";
161 : 0 : case I40E_ERR_NVM_CHECKSUM:
162 : 0 : return "I40E_ERR_NVM_CHECKSUM";
163 : 0 : case I40E_ERR_PHY:
164 : 0 : return "I40E_ERR_PHY";
165 : 0 : case I40E_ERR_CONFIG:
166 : 0 : return "I40E_ERR_CONFIG";
167 : 0 : case I40E_ERR_PARAM:
168 : 0 : return "I40E_ERR_PARAM";
169 : 0 : case I40E_ERR_MAC_TYPE:
170 : 0 : return "I40E_ERR_MAC_TYPE";
171 : 0 : case I40E_ERR_UNKNOWN_PHY:
172 : 0 : return "I40E_ERR_UNKNOWN_PHY";
173 : 0 : case I40E_ERR_LINK_SETUP:
174 : 0 : return "I40E_ERR_LINK_SETUP";
175 : 0 : case I40E_ERR_ADAPTER_STOPPED:
176 : 0 : return "I40E_ERR_ADAPTER_STOPPED";
177 : 0 : case I40E_ERR_INVALID_MAC_ADDR:
178 : 0 : return "I40E_ERR_INVALID_MAC_ADDR";
179 : 0 : case I40E_ERR_DEVICE_NOT_SUPPORTED:
180 : 0 : return "I40E_ERR_DEVICE_NOT_SUPPORTED";
181 : 0 : case I40E_ERR_MASTER_REQUESTS_PENDING:
182 : 0 : return "I40E_ERR_MASTER_REQUESTS_PENDING";
183 : 0 : case I40E_ERR_INVALID_LINK_SETTINGS:
184 : 0 : return "I40E_ERR_INVALID_LINK_SETTINGS";
185 : 0 : case I40E_ERR_AUTONEG_NOT_COMPLETE:
186 : 0 : return "I40E_ERR_AUTONEG_NOT_COMPLETE";
187 : 0 : case I40E_ERR_RESET_FAILED:
188 : 0 : return "I40E_ERR_RESET_FAILED";
189 : 0 : case I40E_ERR_SWFW_SYNC:
190 : 0 : return "I40E_ERR_SWFW_SYNC";
191 : 0 : case I40E_ERR_NO_AVAILABLE_VSI:
192 : 0 : return "I40E_ERR_NO_AVAILABLE_VSI";
193 : 0 : case I40E_ERR_NO_MEMORY:
194 : 0 : return "I40E_ERR_NO_MEMORY";
195 : 0 : case I40E_ERR_BAD_PTR:
196 : 0 : return "I40E_ERR_BAD_PTR";
197 : 0 : case I40E_ERR_RING_FULL:
198 : 0 : return "I40E_ERR_RING_FULL";
199 : 0 : case I40E_ERR_INVALID_PD_ID:
200 : 0 : return "I40E_ERR_INVALID_PD_ID";
201 : 0 : case I40E_ERR_INVALID_QP_ID:
202 : 0 : return "I40E_ERR_INVALID_QP_ID";
203 : 0 : case I40E_ERR_INVALID_CQ_ID:
204 : 0 : return "I40E_ERR_INVALID_CQ_ID";
205 : 0 : case I40E_ERR_INVALID_CEQ_ID:
206 : 0 : return "I40E_ERR_INVALID_CEQ_ID";
207 : 0 : case I40E_ERR_INVALID_AEQ_ID:
208 : 0 : return "I40E_ERR_INVALID_AEQ_ID";
209 : 0 : case I40E_ERR_INVALID_SIZE:
210 : 0 : return "I40E_ERR_INVALID_SIZE";
211 : 0 : case I40E_ERR_INVALID_ARP_INDEX:
212 : 0 : return "I40E_ERR_INVALID_ARP_INDEX";
213 : 0 : case I40E_ERR_INVALID_FPM_FUNC_ID:
214 : 0 : return "I40E_ERR_INVALID_FPM_FUNC_ID";
215 : 0 : case I40E_ERR_QP_INVALID_MSG_SIZE:
216 : 0 : return "I40E_ERR_QP_INVALID_MSG_SIZE";
217 : 0 : case I40E_ERR_QP_TOOMANY_WRS_POSTED:
218 : 0 : return "I40E_ERR_QP_TOOMANY_WRS_POSTED";
219 : 0 : case I40E_ERR_INVALID_FRAG_COUNT:
220 : 0 : return "I40E_ERR_INVALID_FRAG_COUNT";
221 : 0 : case I40E_ERR_QUEUE_EMPTY:
222 : 0 : return "I40E_ERR_QUEUE_EMPTY";
223 : 0 : case I40E_ERR_INVALID_ALIGNMENT:
224 : 0 : return "I40E_ERR_INVALID_ALIGNMENT";
225 : 0 : case I40E_ERR_FLUSHED_QUEUE:
226 : 0 : return "I40E_ERR_FLUSHED_QUEUE";
227 : 0 : case I40E_ERR_INVALID_PUSH_PAGE_INDEX:
228 : 0 : return "I40E_ERR_INVALID_PUSH_PAGE_INDEX";
229 : 0 : case I40E_ERR_INVALID_IMM_DATA_SIZE:
230 : 0 : return "I40E_ERR_INVALID_IMM_DATA_SIZE";
231 : 0 : case I40E_ERR_TIMEOUT:
232 : 0 : return "I40E_ERR_TIMEOUT";
233 : 0 : case I40E_ERR_OPCODE_MISMATCH:
234 : 0 : return "I40E_ERR_OPCODE_MISMATCH";
235 : 0 : case I40E_ERR_CQP_COMPL_ERROR:
236 : 0 : return "I40E_ERR_CQP_COMPL_ERROR";
237 : 0 : case I40E_ERR_INVALID_VF_ID:
238 : 0 : return "I40E_ERR_INVALID_VF_ID";
239 : 0 : case I40E_ERR_INVALID_HMCFN_ID:
240 : 0 : return "I40E_ERR_INVALID_HMCFN_ID";
241 : 0 : case I40E_ERR_BACKING_PAGE_ERROR:
242 : 0 : return "I40E_ERR_BACKING_PAGE_ERROR";
243 : 0 : case I40E_ERR_NO_PBLCHUNKS_AVAILABLE:
244 : 0 : return "I40E_ERR_NO_PBLCHUNKS_AVAILABLE";
245 : 0 : case I40E_ERR_INVALID_PBLE_INDEX:
246 : 0 : return "I40E_ERR_INVALID_PBLE_INDEX";
247 : 0 : case I40E_ERR_INVALID_SD_INDEX:
248 : 0 : return "I40E_ERR_INVALID_SD_INDEX";
249 : 0 : case I40E_ERR_INVALID_PAGE_DESC_INDEX:
250 : 0 : return "I40E_ERR_INVALID_PAGE_DESC_INDEX";
251 : 0 : case I40E_ERR_INVALID_SD_TYPE:
252 : 0 : return "I40E_ERR_INVALID_SD_TYPE";
253 : 0 : case I40E_ERR_MEMCPY_FAILED:
254 : 0 : return "I40E_ERR_MEMCPY_FAILED";
255 : 0 : case I40E_ERR_INVALID_HMC_OBJ_INDEX:
256 : 0 : return "I40E_ERR_INVALID_HMC_OBJ_INDEX";
257 : 0 : case I40E_ERR_INVALID_HMC_OBJ_COUNT:
258 : 0 : return "I40E_ERR_INVALID_HMC_OBJ_COUNT";
259 : 0 : case I40E_ERR_INVALID_SRQ_ARM_LIMIT:
260 : 0 : return "I40E_ERR_INVALID_SRQ_ARM_LIMIT";
261 : 0 : case I40E_ERR_SRQ_ENABLED:
262 : 0 : return "I40E_ERR_SRQ_ENABLED";
263 : 0 : case I40E_ERR_ADMIN_QUEUE_ERROR:
264 : 0 : return "I40E_ERR_ADMIN_QUEUE_ERROR";
265 : 0 : case I40E_ERR_ADMIN_QUEUE_TIMEOUT:
266 : 0 : return "I40E_ERR_ADMIN_QUEUE_TIMEOUT";
267 : 0 : case I40E_ERR_BUF_TOO_SHORT:
268 : 0 : return "I40E_ERR_BUF_TOO_SHORT";
269 : 0 : case I40E_ERR_ADMIN_QUEUE_FULL:
270 : 0 : return "I40E_ERR_ADMIN_QUEUE_FULL";
271 : 0 : case I40E_ERR_ADMIN_QUEUE_NO_WORK:
272 : 0 : return "I40E_ERR_ADMIN_QUEUE_NO_WORK";
273 : 0 : case I40E_ERR_BAD_IWARP_CQE:
274 : 0 : return "I40E_ERR_BAD_IWARP_CQE";
275 : 0 : case I40E_ERR_NVM_BLANK_MODE:
276 : 0 : return "I40E_ERR_NVM_BLANK_MODE";
277 : 0 : case I40E_ERR_NOT_IMPLEMENTED:
278 : 0 : return "I40E_ERR_NOT_IMPLEMENTED";
279 : 0 : case I40E_ERR_PE_DOORBELL_NOT_ENABLED:
280 : 0 : return "I40E_ERR_PE_DOORBELL_NOT_ENABLED";
281 : 0 : case I40E_ERR_DIAG_TEST_FAILED:
282 : 0 : return "I40E_ERR_DIAG_TEST_FAILED";
283 : 0 : case I40E_ERR_NOT_READY:
284 : 0 : return "I40E_ERR_NOT_READY";
285 : 0 : case I40E_NOT_SUPPORTED:
286 : 0 : return "I40E_NOT_SUPPORTED";
287 : 0 : case I40E_ERR_FIRMWARE_API_VERSION:
288 : 0 : return "I40E_ERR_FIRMWARE_API_VERSION";
289 : 0 : case I40E_ERR_ADMIN_QUEUE_CRITICAL_ERROR:
290 : 0 : return "I40E_ERR_ADMIN_QUEUE_CRITICAL_ERROR";
291 : : }
292 : :
293 : 0 : snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
294 : 0 : return hw->err_str;
295 : : }
296 : :
297 : : /**
298 : : * i40e_debug_aq
299 : : * @hw: debug mask related to admin queue
300 : : * @mask: debug mask
301 : : * @desc: pointer to admin queue descriptor
302 : : * @buffer: pointer to command buffer
303 : : * @buf_len: max length of buffer
304 : : *
305 : : * Dumps debug log about adminq command with descriptor contents.
306 : : **/
307 : 0 : void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
308 : : void *buffer, u16 buf_len)
309 : : {
310 : : struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
311 : 0 : u32 effective_mask = hw->debug_mask & mask;
312 : : u8 *buf = (u8 *)buffer;
313 : : u16 len;
314 : : u16 i;
315 : :
316 [ # # ]: 0 : if (!effective_mask || !desc)
317 : : return;
318 : :
319 : 0 : len = LE16_TO_CPU(aq_desc->datalen);
320 : :
321 [ # # ]: 0 : i40e_debug(hw, mask & I40E_DEBUG_AQ_DESCRIPTOR,
322 : : "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
323 : : LE16_TO_CPU(aq_desc->opcode),
324 : : LE16_TO_CPU(aq_desc->flags),
325 : : LE16_TO_CPU(aq_desc->datalen),
326 : : LE16_TO_CPU(aq_desc->retval));
327 [ # # ]: 0 : i40e_debug(hw, mask & I40E_DEBUG_AQ_DESCRIPTOR,
328 : : "\tcookie (h,l) 0x%08X 0x%08X\n",
329 : : LE32_TO_CPU(aq_desc->cookie_high),
330 : : LE32_TO_CPU(aq_desc->cookie_low));
331 [ # # ]: 0 : i40e_debug(hw, mask & I40E_DEBUG_AQ_DESCRIPTOR,
332 : : "\tparam (0,1) 0x%08X 0x%08X\n",
333 : : LE32_TO_CPU(aq_desc->params.internal.param0),
334 : : LE32_TO_CPU(aq_desc->params.internal.param1));
335 [ # # ]: 0 : i40e_debug(hw, mask & I40E_DEBUG_AQ_DESCRIPTOR,
336 : : "\taddr (h,l) 0x%08X 0x%08X\n",
337 : : LE32_TO_CPU(aq_desc->params.external.addr_high),
338 : : LE32_TO_CPU(aq_desc->params.external.addr_low));
339 : :
340 [ # # # # ]: 0 : if (buffer && (buf_len != 0) && (len != 0) &&
341 [ # # ]: 0 : (effective_mask & I40E_DEBUG_AQ_DESC_BUFFER)) {
342 [ # # ]: 0 : i40e_debug(hw, mask, "AQ CMD Buffer:\n");
343 : : if (buf_len < len)
344 : : len = buf_len;
345 : : /* write the full 16-byte chunks */
346 [ # # ]: 0 : for (i = 0; i < (len - 16); i += 16)
347 [ # # ]: 0 : i40e_debug(hw, mask,
348 : : "\t0x%04X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
349 : : i, buf[i], buf[i+1], buf[i+2], buf[i+3],
350 : : buf[i+4], buf[i+5], buf[i+6], buf[i+7],
351 : : buf[i+8], buf[i+9], buf[i+10], buf[i+11],
352 : : buf[i+12], buf[i+13], buf[i+14], buf[i+15]);
353 : : /* the most we could have left is 16 bytes, pad with zeros */
354 [ # # ]: 0 : if (i < len) {
355 : : char d_buf[16];
356 : : int j, i_sav;
357 : :
358 : : i_sav = i;
359 : : memset(d_buf, 0, sizeof(d_buf));
360 [ # # ]: 0 : for (j = 0; i < len; j++, i++)
361 : 0 : d_buf[j] = buf[i];
362 [ # # ]: 0 : i40e_debug(hw, mask,
363 : : "\t0x%04X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
364 : : i_sav, d_buf[0], d_buf[1], d_buf[2], d_buf[3],
365 : : d_buf[4], d_buf[5], d_buf[6], d_buf[7],
366 : : d_buf[8], d_buf[9], d_buf[10], d_buf[11],
367 : : d_buf[12], d_buf[13], d_buf[14], d_buf[15]);
368 : : }
369 : : }
370 : : }
371 : :
372 : : /**
373 : : * i40e_check_asq_alive
374 : : * @hw: pointer to the hw struct
375 : : *
376 : : * Returns true if Queue is enabled else false.
377 : : **/
378 : 0 : bool i40e_check_asq_alive(struct i40e_hw *hw)
379 : : {
380 [ # # ]: 0 : if (hw->aq.asq.len)
381 : : #ifdef PF_DRIVER
382 : : #ifdef INTEGRATED_VF
383 [ # # ]: 0 : if (!i40e_is_vf(hw))
384 : 0 : return !!(rd32(hw, hw->aq.asq.len) &
385 : : I40E_PF_ATQLEN_ATQENABLE_MASK);
386 : : #else
387 : : return !!(rd32(hw, hw->aq.asq.len) &
388 : : I40E_PF_ATQLEN_ATQENABLE_MASK);
389 : : #endif /* INTEGRATED_VF */
390 : : #endif /* PF_DRIVER */
391 : : #ifdef VF_DRIVER
392 : : #ifdef INTEGRATED_VF
393 [ # # ]: 0 : if (i40e_is_vf(hw))
394 : 0 : return !!(rd32(hw, hw->aq.asq.len) &
395 : : I40E_VF_ATQLEN1_ATQENABLE_MASK);
396 : : #else
397 : : return !!(rd32(hw, hw->aq.asq.len) &
398 : : I40E_VF_ATQLEN1_ATQENABLE_MASK);
399 : : #endif /* INTEGRATED_VF */
400 : : #endif /* VF_DRIVER */
401 : : return false;
402 : : }
403 : :
404 : : /**
405 : : * i40e_aq_queue_shutdown
406 : : * @hw: pointer to the hw struct
407 : : * @unloading: is the driver unloading itself
408 : : *
409 : : * Tell the Firmware that we're shutting down the AdminQ and whether
410 : : * or not the driver is unloading as well.
411 : : **/
412 : 0 : enum i40e_status_code i40e_aq_queue_shutdown(struct i40e_hw *hw,
413 : : bool unloading)
414 : : {
415 : : struct i40e_aq_desc desc;
416 : : struct i40e_aqc_queue_shutdown *cmd =
417 : : (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
418 : : enum i40e_status_code status;
419 : :
420 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
421 : : i40e_aqc_opc_queue_shutdown);
422 : :
423 [ # # ]: 0 : if (unloading)
424 : 0 : cmd->driver_unloading = CPU_TO_LE32(I40E_AQ_DRIVER_UNLOADING);
425 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
426 : :
427 : 0 : return status;
428 : : }
429 : :
430 : : /**
431 : : * i40e_aq_get_set_rss_lut
432 : : * @hw: pointer to the hardware structure
433 : : * @vsi_id: vsi fw index
434 : : * @pf_lut: for PF table set true, for VSI table set false
435 : : * @lut: pointer to the lut buffer provided by the caller
436 : : * @lut_size: size of the lut buffer
437 : : * @set: set true to set the table, false to get the table
438 : : *
439 : : * Internal function to get or set RSS look up table
440 : : **/
441 : 0 : STATIC enum i40e_status_code i40e_aq_get_set_rss_lut(struct i40e_hw *hw,
442 : : u16 vsi_id, bool pf_lut,
443 : : u8 *lut, u16 lut_size,
444 : : bool set)
445 : : {
446 : : enum i40e_status_code status;
447 : : struct i40e_aq_desc desc;
448 : : struct i40e_aqc_get_set_rss_lut *cmd_resp =
449 : : (struct i40e_aqc_get_set_rss_lut *)&desc.params.raw;
450 : :
451 [ # # ]: 0 : if (set)
452 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
453 : : i40e_aqc_opc_set_rss_lut);
454 : : else
455 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
456 : : i40e_aqc_opc_get_rss_lut);
457 : :
458 : : /* Indirect command */
459 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
460 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
461 : :
462 : : cmd_resp->vsi_id =
463 : 0 : CPU_TO_LE16((u16)((vsi_id <<
464 : : I40E_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
465 : : I40E_AQC_SET_RSS_LUT_VSI_ID_MASK));
466 : 0 : cmd_resp->vsi_id |= CPU_TO_LE16((u16)I40E_AQC_SET_RSS_LUT_VSI_VALID);
467 : :
468 [ # # ]: 0 : if (pf_lut)
469 : 0 : cmd_resp->flags |= CPU_TO_LE16((u16)
470 : : ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
471 : : I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
472 : : I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
473 : : else
474 : : cmd_resp->flags |= CPU_TO_LE16((u16)
475 : : ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
476 : : I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
477 : : I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
478 : :
479 : 0 : status = i40e_asq_send_command(hw, &desc, lut, lut_size, NULL);
480 : :
481 : 0 : return status;
482 : : }
483 : :
484 : : /**
485 : : * i40e_aq_get_rss_lut
486 : : * @hw: pointer to the hardware structure
487 : : * @vsi_id: vsi fw index
488 : : * @pf_lut: for PF table set true, for VSI table set false
489 : : * @lut: pointer to the lut buffer provided by the caller
490 : : * @lut_size: size of the lut buffer
491 : : *
492 : : * get the RSS lookup table, PF or VSI type
493 : : **/
494 : 0 : enum i40e_status_code i40e_aq_get_rss_lut(struct i40e_hw *hw, u16 vsi_id,
495 : : bool pf_lut, u8 *lut, u16 lut_size)
496 : : {
497 : 0 : return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
498 : : false);
499 : : }
500 : :
501 : : /**
502 : : * i40e_aq_set_rss_lut
503 : : * @hw: pointer to the hardware structure
504 : : * @vsi_id: vsi fw index
505 : : * @pf_lut: for PF table set true, for VSI table set false
506 : : * @lut: pointer to the lut buffer provided by the caller
507 : : * @lut_size: size of the lut buffer
508 : : *
509 : : * set the RSS lookup table, PF or VSI type
510 : : **/
511 : 0 : enum i40e_status_code i40e_aq_set_rss_lut(struct i40e_hw *hw, u16 vsi_id,
512 : : bool pf_lut, u8 *lut, u16 lut_size)
513 : : {
514 : 0 : return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
515 : : }
516 : :
517 : : /**
518 : : * i40e_aq_get_set_rss_key
519 : : * @hw: pointer to the hw struct
520 : : * @vsi_id: vsi fw index
521 : : * @key: pointer to key info struct
522 : : * @set: set true to set the key, false to get the key
523 : : *
524 : : * get the RSS key per VSI
525 : : **/
526 : 0 : STATIC enum i40e_status_code i40e_aq_get_set_rss_key(struct i40e_hw *hw,
527 : : u16 vsi_id,
528 : : struct i40e_aqc_get_set_rss_key_data *key,
529 : : bool set)
530 : : {
531 : : enum i40e_status_code status;
532 : : struct i40e_aq_desc desc;
533 : : struct i40e_aqc_get_set_rss_key *cmd_resp =
534 : : (struct i40e_aqc_get_set_rss_key *)&desc.params.raw;
535 : : u16 key_size = sizeof(struct i40e_aqc_get_set_rss_key_data);
536 : :
537 [ # # ]: 0 : if (set)
538 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
539 : : i40e_aqc_opc_set_rss_key);
540 : : else
541 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
542 : : i40e_aqc_opc_get_rss_key);
543 : :
544 : : /* Indirect command */
545 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
546 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
547 : :
548 : : cmd_resp->vsi_id =
549 : 0 : CPU_TO_LE16((u16)((vsi_id <<
550 : : I40E_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
551 : : I40E_AQC_SET_RSS_KEY_VSI_ID_MASK));
552 : 0 : cmd_resp->vsi_id |= CPU_TO_LE16((u16)I40E_AQC_SET_RSS_KEY_VSI_VALID);
553 : :
554 : 0 : status = i40e_asq_send_command(hw, &desc, key, key_size, NULL);
555 : :
556 : 0 : return status;
557 : : }
558 : :
559 : : /**
560 : : * i40e_aq_get_rss_key
561 : : * @hw: pointer to the hw struct
562 : : * @vsi_id: vsi fw index
563 : : * @key: pointer to key info struct
564 : : *
565 : : **/
566 : 0 : enum i40e_status_code i40e_aq_get_rss_key(struct i40e_hw *hw,
567 : : u16 vsi_id,
568 : : struct i40e_aqc_get_set_rss_key_data *key)
569 : : {
570 : 0 : return i40e_aq_get_set_rss_key(hw, vsi_id, key, false);
571 : : }
572 : :
573 : : /**
574 : : * i40e_aq_set_rss_key
575 : : * @hw: pointer to the hw struct
576 : : * @vsi_id: vsi fw index
577 : : * @key: pointer to key info struct
578 : : *
579 : : * set the RSS key per VSI
580 : : **/
581 : 0 : enum i40e_status_code i40e_aq_set_rss_key(struct i40e_hw *hw,
582 : : u16 vsi_id,
583 : : struct i40e_aqc_get_set_rss_key_data *key)
584 : : {
585 : 0 : return i40e_aq_get_set_rss_key(hw, vsi_id, key, true);
586 : : }
587 : :
588 : : /* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
589 : : * hardware to a bit-field that can be used by SW to more easily determine the
590 : : * packet type.
591 : : *
592 : : * Macros are used to shorten the table lines and make this table human
593 : : * readable.
594 : : *
595 : : * We store the PTYPE in the top byte of the bit field - this is just so that
596 : : * we can check that the table doesn't have a row missing, as the index into
597 : : * the table should be the PTYPE.
598 : : *
599 : : * Typical work flow:
600 : : *
601 : : * IF NOT i40e_ptype_lookup[ptype].known
602 : : * THEN
603 : : * Packet is unknown
604 : : * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
605 : : * Use the rest of the fields to look at the tunnels, inner protocols, etc
606 : : * ELSE
607 : : * Use the enum i40e_rx_l2_ptype to decode the packet type
608 : : * ENDIF
609 : : */
610 : :
611 : : /* macro to make the table lines short */
612 : : #define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
613 : : { PTYPE, \
614 : : 1, \
615 : : I40E_RX_PTYPE_OUTER_##OUTER_IP, \
616 : : I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
617 : : I40E_RX_PTYPE_##OUTER_FRAG, \
618 : : I40E_RX_PTYPE_TUNNEL_##T, \
619 : : I40E_RX_PTYPE_TUNNEL_END_##TE, \
620 : : I40E_RX_PTYPE_##TEF, \
621 : : I40E_RX_PTYPE_INNER_PROT_##I, \
622 : : I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
623 : :
624 : : #define I40E_PTT_UNUSED_ENTRY(PTYPE) \
625 : : { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
626 : :
627 : : /* shorter macros makes the table fit but are terse */
628 : : #define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
629 : : #define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
630 : : #define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
631 : :
632 : : /* Lookup table mapping the HW PTYPE to the bit field for decoding */
633 : : struct i40e_rx_ptype_decoded i40e_ptype_lookup[] = {
634 : : /* L2 Packet types */
635 : : I40E_PTT_UNUSED_ENTRY(0),
636 : : I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
637 : : I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
638 : : I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
639 : : I40E_PTT_UNUSED_ENTRY(4),
640 : : I40E_PTT_UNUSED_ENTRY(5),
641 : : I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
642 : : I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
643 : : I40E_PTT_UNUSED_ENTRY(8),
644 : : I40E_PTT_UNUSED_ENTRY(9),
645 : : I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
646 : : I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
647 : : I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
648 : : I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
649 : : I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
650 : : I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
651 : : I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
652 : : I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
653 : : I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
654 : : I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
655 : : I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
656 : : I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
657 : :
658 : : /* Non Tunneled IPv4 */
659 : : I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
660 : : I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
661 : : I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
662 : : I40E_PTT_UNUSED_ENTRY(25),
663 : : I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
664 : : I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
665 : : I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
666 : :
667 : : /* IPv4 --> IPv4 */
668 : : I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
669 : : I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
670 : : I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
671 : : I40E_PTT_UNUSED_ENTRY(32),
672 : : I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
673 : : I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
674 : : I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
675 : :
676 : : /* IPv4 --> IPv6 */
677 : : I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
678 : : I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
679 : : I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
680 : : I40E_PTT_UNUSED_ENTRY(39),
681 : : I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
682 : : I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
683 : : I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
684 : :
685 : : /* IPv4 --> GRE/NAT */
686 : : I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
687 : :
688 : : /* IPv4 --> GRE/NAT --> IPv4 */
689 : : I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
690 : : I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
691 : : I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
692 : : I40E_PTT_UNUSED_ENTRY(47),
693 : : I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
694 : : I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
695 : : I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
696 : :
697 : : /* IPv4 --> GRE/NAT --> IPv6 */
698 : : I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
699 : : I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
700 : : I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
701 : : I40E_PTT_UNUSED_ENTRY(54),
702 : : I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
703 : : I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
704 : : I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
705 : :
706 : : /* IPv4 --> GRE/NAT --> MAC */
707 : : I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
708 : :
709 : : /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
710 : : I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
711 : : I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
712 : : I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
713 : : I40E_PTT_UNUSED_ENTRY(62),
714 : : I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
715 : : I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
716 : : I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
717 : :
718 : : /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
719 : : I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
720 : : I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
721 : : I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
722 : : I40E_PTT_UNUSED_ENTRY(69),
723 : : I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
724 : : I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
725 : : I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
726 : :
727 : : /* IPv4 --> GRE/NAT --> MAC/VLAN */
728 : : I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
729 : :
730 : : /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
731 : : I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
732 : : I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
733 : : I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
734 : : I40E_PTT_UNUSED_ENTRY(77),
735 : : I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
736 : : I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
737 : : I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
738 : :
739 : : /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
740 : : I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
741 : : I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
742 : : I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
743 : : I40E_PTT_UNUSED_ENTRY(84),
744 : : I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
745 : : I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
746 : : I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
747 : :
748 : : /* Non Tunneled IPv6 */
749 : : I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
750 : : I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
751 : : I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY4),
752 : : I40E_PTT_UNUSED_ENTRY(91),
753 : : I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
754 : : I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
755 : : I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
756 : :
757 : : /* IPv6 --> IPv4 */
758 : : I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
759 : : I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
760 : : I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
761 : : I40E_PTT_UNUSED_ENTRY(98),
762 : : I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
763 : : I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
764 : : I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
765 : :
766 : : /* IPv6 --> IPv6 */
767 : : I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
768 : : I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
769 : : I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
770 : : I40E_PTT_UNUSED_ENTRY(105),
771 : : I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
772 : : I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
773 : : I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
774 : :
775 : : /* IPv6 --> GRE/NAT */
776 : : I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
777 : :
778 : : /* IPv6 --> GRE/NAT -> IPv4 */
779 : : I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
780 : : I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
781 : : I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
782 : : I40E_PTT_UNUSED_ENTRY(113),
783 : : I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
784 : : I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
785 : : I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
786 : :
787 : : /* IPv6 --> GRE/NAT -> IPv6 */
788 : : I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
789 : : I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
790 : : I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
791 : : I40E_PTT_UNUSED_ENTRY(120),
792 : : I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
793 : : I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
794 : : I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
795 : :
796 : : /* IPv6 --> GRE/NAT -> MAC */
797 : : I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
798 : :
799 : : /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
800 : : I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
801 : : I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
802 : : I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
803 : : I40E_PTT_UNUSED_ENTRY(128),
804 : : I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
805 : : I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
806 : : I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
807 : :
808 : : /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
809 : : I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
810 : : I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
811 : : I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
812 : : I40E_PTT_UNUSED_ENTRY(135),
813 : : I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
814 : : I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
815 : : I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
816 : :
817 : : /* IPv6 --> GRE/NAT -> MAC/VLAN */
818 : : I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
819 : :
820 : : /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
821 : : I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
822 : : I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
823 : : I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
824 : : I40E_PTT_UNUSED_ENTRY(143),
825 : : I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
826 : : I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
827 : : I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
828 : :
829 : : /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
830 : : I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
831 : : I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
832 : : I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
833 : : I40E_PTT_UNUSED_ENTRY(150),
834 : : I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
835 : : I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
836 : : I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
837 : :
838 : : /* unused entries */
839 : : I40E_PTT_UNUSED_ENTRY(154),
840 : : I40E_PTT_UNUSED_ENTRY(155),
841 : : I40E_PTT_UNUSED_ENTRY(156),
842 : : I40E_PTT_UNUSED_ENTRY(157),
843 : : I40E_PTT_UNUSED_ENTRY(158),
844 : : I40E_PTT_UNUSED_ENTRY(159),
845 : :
846 : : I40E_PTT_UNUSED_ENTRY(160),
847 : : I40E_PTT_UNUSED_ENTRY(161),
848 : : I40E_PTT_UNUSED_ENTRY(162),
849 : : I40E_PTT_UNUSED_ENTRY(163),
850 : : I40E_PTT_UNUSED_ENTRY(164),
851 : : I40E_PTT_UNUSED_ENTRY(165),
852 : : I40E_PTT_UNUSED_ENTRY(166),
853 : : I40E_PTT_UNUSED_ENTRY(167),
854 : : I40E_PTT_UNUSED_ENTRY(168),
855 : : I40E_PTT_UNUSED_ENTRY(169),
856 : :
857 : : I40E_PTT_UNUSED_ENTRY(170),
858 : : I40E_PTT_UNUSED_ENTRY(171),
859 : : I40E_PTT_UNUSED_ENTRY(172),
860 : : I40E_PTT_UNUSED_ENTRY(173),
861 : : I40E_PTT_UNUSED_ENTRY(174),
862 : : I40E_PTT_UNUSED_ENTRY(175),
863 : : I40E_PTT_UNUSED_ENTRY(176),
864 : : I40E_PTT_UNUSED_ENTRY(177),
865 : : I40E_PTT_UNUSED_ENTRY(178),
866 : : I40E_PTT_UNUSED_ENTRY(179),
867 : :
868 : : I40E_PTT_UNUSED_ENTRY(180),
869 : : I40E_PTT_UNUSED_ENTRY(181),
870 : : I40E_PTT_UNUSED_ENTRY(182),
871 : : I40E_PTT_UNUSED_ENTRY(183),
872 : : I40E_PTT_UNUSED_ENTRY(184),
873 : : I40E_PTT_UNUSED_ENTRY(185),
874 : : I40E_PTT_UNUSED_ENTRY(186),
875 : : I40E_PTT_UNUSED_ENTRY(187),
876 : : I40E_PTT_UNUSED_ENTRY(188),
877 : : I40E_PTT_UNUSED_ENTRY(189),
878 : :
879 : : I40E_PTT_UNUSED_ENTRY(190),
880 : : I40E_PTT_UNUSED_ENTRY(191),
881 : : I40E_PTT_UNUSED_ENTRY(192),
882 : : I40E_PTT_UNUSED_ENTRY(193),
883 : : I40E_PTT_UNUSED_ENTRY(194),
884 : : I40E_PTT_UNUSED_ENTRY(195),
885 : : I40E_PTT_UNUSED_ENTRY(196),
886 : : I40E_PTT_UNUSED_ENTRY(197),
887 : : I40E_PTT_UNUSED_ENTRY(198),
888 : : I40E_PTT_UNUSED_ENTRY(199),
889 : :
890 : : I40E_PTT_UNUSED_ENTRY(200),
891 : : I40E_PTT_UNUSED_ENTRY(201),
892 : : I40E_PTT_UNUSED_ENTRY(202),
893 : : I40E_PTT_UNUSED_ENTRY(203),
894 : : I40E_PTT_UNUSED_ENTRY(204),
895 : : I40E_PTT_UNUSED_ENTRY(205),
896 : : I40E_PTT_UNUSED_ENTRY(206),
897 : : I40E_PTT_UNUSED_ENTRY(207),
898 : : I40E_PTT_UNUSED_ENTRY(208),
899 : : I40E_PTT_UNUSED_ENTRY(209),
900 : :
901 : : I40E_PTT_UNUSED_ENTRY(210),
902 : : I40E_PTT_UNUSED_ENTRY(211),
903 : : I40E_PTT_UNUSED_ENTRY(212),
904 : : I40E_PTT_UNUSED_ENTRY(213),
905 : : I40E_PTT_UNUSED_ENTRY(214),
906 : : I40E_PTT_UNUSED_ENTRY(215),
907 : : I40E_PTT_UNUSED_ENTRY(216),
908 : : I40E_PTT_UNUSED_ENTRY(217),
909 : : I40E_PTT_UNUSED_ENTRY(218),
910 : : I40E_PTT_UNUSED_ENTRY(219),
911 : :
912 : : I40E_PTT_UNUSED_ENTRY(220),
913 : : I40E_PTT_UNUSED_ENTRY(221),
914 : : I40E_PTT_UNUSED_ENTRY(222),
915 : : I40E_PTT_UNUSED_ENTRY(223),
916 : : I40E_PTT_UNUSED_ENTRY(224),
917 : : I40E_PTT_UNUSED_ENTRY(225),
918 : : I40E_PTT_UNUSED_ENTRY(226),
919 : : I40E_PTT_UNUSED_ENTRY(227),
920 : : I40E_PTT_UNUSED_ENTRY(228),
921 : : I40E_PTT_UNUSED_ENTRY(229),
922 : :
923 : : I40E_PTT_UNUSED_ENTRY(230),
924 : : I40E_PTT_UNUSED_ENTRY(231),
925 : : I40E_PTT_UNUSED_ENTRY(232),
926 : : I40E_PTT_UNUSED_ENTRY(233),
927 : : I40E_PTT_UNUSED_ENTRY(234),
928 : : I40E_PTT_UNUSED_ENTRY(235),
929 : : I40E_PTT_UNUSED_ENTRY(236),
930 : : I40E_PTT_UNUSED_ENTRY(237),
931 : : I40E_PTT_UNUSED_ENTRY(238),
932 : : I40E_PTT_UNUSED_ENTRY(239),
933 : :
934 : : I40E_PTT_UNUSED_ENTRY(240),
935 : : I40E_PTT_UNUSED_ENTRY(241),
936 : : I40E_PTT_UNUSED_ENTRY(242),
937 : : I40E_PTT_UNUSED_ENTRY(243),
938 : : I40E_PTT_UNUSED_ENTRY(244),
939 : : I40E_PTT_UNUSED_ENTRY(245),
940 : : I40E_PTT_UNUSED_ENTRY(246),
941 : : I40E_PTT_UNUSED_ENTRY(247),
942 : : I40E_PTT_UNUSED_ENTRY(248),
943 : : I40E_PTT_UNUSED_ENTRY(249),
944 : :
945 : : I40E_PTT_UNUSED_ENTRY(250),
946 : : I40E_PTT_UNUSED_ENTRY(251),
947 : : I40E_PTT_UNUSED_ENTRY(252),
948 : : I40E_PTT_UNUSED_ENTRY(253),
949 : : I40E_PTT_UNUSED_ENTRY(254),
950 : : I40E_PTT_UNUSED_ENTRY(255)
951 : : };
952 : :
953 : :
954 : : /**
955 : : * i40e_validate_mac_addr - Validate unicast MAC address
956 : : * @mac_addr: pointer to MAC address
957 : : *
958 : : * Tests a MAC address to ensure it is a valid Individual Address
959 : : **/
960 : 0 : enum i40e_status_code i40e_validate_mac_addr(u8 *mac_addr)
961 : : {
962 : : enum i40e_status_code status = I40E_SUCCESS;
963 : :
964 : 0 : DEBUGFUNC("i40e_validate_mac_addr");
965 : :
966 : : /* Broadcast addresses ARE multicast addresses
967 : : * Make sure it is not a multicast address
968 : : * Reject the zero address
969 : : */
970 [ # # # # ]: 0 : if (I40E_IS_MULTICAST(mac_addr) ||
971 [ # # # # ]: 0 : (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
972 [ # # # # : 0 : mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0))
# # ]
973 : : status = I40E_ERR_INVALID_MAC_ADDR;
974 : :
975 : 0 : return status;
976 : : }
977 : : #ifdef PF_DRIVER
978 : :
979 : : /**
980 : : * i40e_init_shared_code - Initialize the shared code
981 : : * @hw: pointer to hardware structure
982 : : *
983 : : * This assigns the MAC type and PHY code and inits the NVM.
984 : : * Does not touch the hardware. This function must be called prior to any
985 : : * other function in the shared code. The i40e_hw structure should be
986 : : * memset to 0 prior to calling this function. The following fields in
987 : : * hw structure should be filled in prior to calling this function:
988 : : * hw_addr, back, device_id, vendor_id, subsystem_device_id,
989 : : * subsystem_vendor_id, and revision_id
990 : : **/
991 : 0 : enum i40e_status_code i40e_init_shared_code(struct i40e_hw *hw)
992 : : {
993 : : enum i40e_status_code status = I40E_SUCCESS;
994 : : u32 port, ari, func_rid;
995 : :
996 : 0 : DEBUGFUNC("i40e_init_shared_code");
997 : :
998 : 0 : i40e_set_mac_type(hw);
999 : :
1000 [ # # ]: 0 : switch (hw->mac.type) {
1001 : : case I40E_MAC_XL710:
1002 : : case I40E_MAC_X722:
1003 : : break;
1004 : : default:
1005 : : return I40E_ERR_DEVICE_NOT_SUPPORTED;
1006 : : }
1007 : :
1008 : 0 : hw->phy.get_link_info = true;
1009 : :
1010 : : /* Determine port number and PF number*/
1011 : 0 : port = (rd32(hw, I40E_PFGEN_PORTNUM) & I40E_PFGEN_PORTNUM_PORT_NUM_MASK)
1012 : : >> I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
1013 : 0 : hw->port = (u8)port;
1014 : 0 : ari = (rd32(hw, I40E_GLPCI_CAPSUP) & I40E_GLPCI_CAPSUP_ARI_EN_MASK) >>
1015 : : I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
1016 : 0 : func_rid = rd32(hw, I40E_PF_FUNC_RID);
1017 [ # # ]: 0 : if (ari)
1018 : 0 : hw->pf_id = (u8)(func_rid & 0xff);
1019 : : else
1020 : 0 : hw->pf_id = (u8)(func_rid & 0x7);
1021 : :
1022 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
1023 : 0 : hw->flags |= I40E_HW_FLAG_AQ_SRCTL_ACCESS_ENABLE |
1024 : : I40E_HW_FLAG_NVM_READ_REQUIRES_LOCK;
1025 : : /* NVMUpdate features structure initialization */
1026 : 0 : hw->nvmupd_features.major = I40E_NVMUPD_FEATURES_API_VER_MAJOR;
1027 : 0 : hw->nvmupd_features.minor = I40E_NVMUPD_FEATURES_API_VER_MINOR;
1028 : 0 : hw->nvmupd_features.size = sizeof(hw->nvmupd_features);
1029 : 0 : i40e_memset(hw->nvmupd_features.features, 0x0,
1030 : : I40E_NVMUPD_FEATURES_API_FEATURES_ARRAY_LEN *
1031 : : sizeof(*hw->nvmupd_features.features),
1032 : : I40E_NONDMA_MEM);
1033 : :
1034 : : /* No features supported at the moment */
1035 : : hw->nvmupd_features.features[0] = 0;
1036 : :
1037 : 0 : status = i40e_init_nvm(hw);
1038 : 0 : return status;
1039 : : }
1040 : :
1041 : : /**
1042 : : * i40e_aq_mac_address_read - Retrieve the MAC addresses
1043 : : * @hw: pointer to the hw struct
1044 : : * @flags: a return indicator of what addresses were added to the addr store
1045 : : * @addrs: the requestor's mac addr store
1046 : : * @cmd_details: pointer to command details structure or NULL
1047 : : **/
1048 : 0 : STATIC enum i40e_status_code i40e_aq_mac_address_read(struct i40e_hw *hw,
1049 : : u16 *flags,
1050 : : struct i40e_aqc_mac_address_read_data *addrs,
1051 : : struct i40e_asq_cmd_details *cmd_details)
1052 : : {
1053 : : struct i40e_aq_desc desc;
1054 : : struct i40e_aqc_mac_address_read *cmd_data =
1055 : : (struct i40e_aqc_mac_address_read *)&desc.params.raw;
1056 : : enum i40e_status_code status;
1057 : :
1058 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
1059 : 0 : desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_BUF);
1060 : :
1061 : 0 : status = i40e_asq_send_command(hw, &desc, addrs,
1062 : : sizeof(*addrs), cmd_details);
1063 : 0 : *flags = LE16_TO_CPU(cmd_data->command_flags);
1064 : :
1065 : 0 : return status;
1066 : : }
1067 : :
1068 : : /**
1069 : : * i40e_aq_mac_address_write - Change the MAC addresses
1070 : : * @hw: pointer to the hw struct
1071 : : * @flags: indicates which MAC to be written
1072 : : * @mac_addr: address to write
1073 : : * @cmd_details: pointer to command details structure or NULL
1074 : : **/
1075 : 0 : enum i40e_status_code i40e_aq_mac_address_write(struct i40e_hw *hw,
1076 : : u16 flags, u8 *mac_addr,
1077 : : struct i40e_asq_cmd_details *cmd_details)
1078 : : {
1079 : : struct i40e_aq_desc desc;
1080 : : struct i40e_aqc_mac_address_write *cmd_data =
1081 : : (struct i40e_aqc_mac_address_write *)&desc.params.raw;
1082 : : enum i40e_status_code status;
1083 : :
1084 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
1085 : : i40e_aqc_opc_mac_address_write);
1086 : 0 : cmd_data->command_flags = CPU_TO_LE16(flags);
1087 : 0 : cmd_data->mac_sah = CPU_TO_LE16((u16)mac_addr[0] << 8 | mac_addr[1]);
1088 : 0 : cmd_data->mac_sal = CPU_TO_LE32(((u32)mac_addr[2] << 24) |
1089 : : ((u32)mac_addr[3] << 16) |
1090 : : ((u32)mac_addr[4] << 8) |
1091 : : mac_addr[5]);
1092 : :
1093 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1094 : :
1095 : 0 : return status;
1096 : : }
1097 : :
1098 : : /**
1099 : : * i40e_get_mac_addr - get MAC address
1100 : : * @hw: pointer to the HW structure
1101 : : * @mac_addr: pointer to MAC address
1102 : : *
1103 : : * Reads the adapter's MAC address from register
1104 : : **/
1105 : 0 : enum i40e_status_code i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1106 : : {
1107 : : struct i40e_aqc_mac_address_read_data addrs;
1108 : : enum i40e_status_code status;
1109 : 0 : u16 flags = 0;
1110 : :
1111 : 0 : status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1112 : :
1113 [ # # ]: 0 : if (flags & I40E_AQC_LAN_ADDR_VALID)
1114 : : i40e_memcpy(mac_addr, &addrs.pf_lan_mac, sizeof(addrs.pf_lan_mac),
1115 : : I40E_NONDMA_TO_NONDMA);
1116 : :
1117 : 0 : return status;
1118 : : }
1119 : :
1120 : : /**
1121 : : * i40e_get_port_mac_addr - get Port MAC address
1122 : : * @hw: pointer to the HW structure
1123 : : * @mac_addr: pointer to Port MAC address
1124 : : *
1125 : : * Reads the adapter's Port MAC address
1126 : : **/
1127 : 0 : enum i40e_status_code i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
1128 : : {
1129 : : struct i40e_aqc_mac_address_read_data addrs;
1130 : : enum i40e_status_code status;
1131 : 0 : u16 flags = 0;
1132 : :
1133 : 0 : status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1134 [ # # ]: 0 : if (status)
1135 : : return status;
1136 : :
1137 [ # # ]: 0 : if (flags & I40E_AQC_PORT_ADDR_VALID)
1138 : : i40e_memcpy(mac_addr, &addrs.port_mac, sizeof(addrs.port_mac),
1139 : : I40E_NONDMA_TO_NONDMA);
1140 : : else
1141 : : status = I40E_ERR_INVALID_MAC_ADDR;
1142 : :
1143 : : return status;
1144 : : }
1145 : :
1146 : : /**
1147 : : * i40e_pre_tx_queue_cfg - pre tx queue configure
1148 : : * @hw: pointer to the HW structure
1149 : : * @queue: target pf queue index
1150 : : * @enable: state change request
1151 : : *
1152 : : * Handles hw requirement to indicate intention to enable
1153 : : * or disable target queue.
1154 : : **/
1155 : 0 : void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
1156 : : {
1157 : 0 : u32 abs_queue_idx = hw->func_caps.base_queue + queue;
1158 : : u32 reg_block = 0;
1159 : : u32 reg_val;
1160 : :
1161 [ # # ]: 0 : if (abs_queue_idx >= 128) {
1162 : 0 : reg_block = abs_queue_idx / 128;
1163 : 0 : abs_queue_idx %= 128;
1164 : : }
1165 : :
1166 : 0 : reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1167 : 0 : reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1168 : 0 : reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1169 : :
1170 [ # # ]: 0 : if (enable)
1171 : 0 : reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
1172 : : else
1173 : 0 : reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1174 : :
1175 : 0 : wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
1176 : 0 : }
1177 : :
1178 : : /**
1179 : : * i40e_get_san_mac_addr - get SAN MAC address
1180 : : * @hw: pointer to the HW structure
1181 : : * @mac_addr: pointer to SAN MAC address
1182 : : *
1183 : : * Reads the adapter's SAN MAC address from NVM
1184 : : **/
1185 : 0 : enum i40e_status_code i40e_get_san_mac_addr(struct i40e_hw *hw,
1186 : : u8 *mac_addr)
1187 : : {
1188 : : struct i40e_aqc_mac_address_read_data addrs;
1189 : : enum i40e_status_code status;
1190 : 0 : u16 flags = 0;
1191 : :
1192 : 0 : status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
1193 [ # # ]: 0 : if (status)
1194 : : return status;
1195 : :
1196 [ # # ]: 0 : if (flags & I40E_AQC_SAN_ADDR_VALID)
1197 : : i40e_memcpy(mac_addr, &addrs.pf_san_mac, sizeof(addrs.pf_san_mac),
1198 : : I40E_NONDMA_TO_NONDMA);
1199 : : else
1200 : : status = I40E_ERR_INVALID_MAC_ADDR;
1201 : :
1202 : : return status;
1203 : : }
1204 : :
1205 : : /**
1206 : : * i40e_read_pba_string - Reads part number string from EEPROM
1207 : : * @hw: pointer to hardware structure
1208 : : * @pba_num: stores the part number string from the EEPROM
1209 : : * @pba_num_size: part number string buffer length
1210 : : *
1211 : : * Reads the part number string from the EEPROM.
1212 : : **/
1213 : 0 : enum i40e_status_code i40e_read_pba_string(struct i40e_hw *hw, u8 *pba_num,
1214 : : u32 pba_num_size)
1215 : : {
1216 : : enum i40e_status_code status = I40E_SUCCESS;
1217 : 0 : u16 pba_word = 0;
1218 : 0 : u16 pba_size = 0;
1219 : 0 : u16 pba_ptr = 0;
1220 : : u16 i = 0;
1221 : :
1222 : 0 : status = i40e_read_nvm_word(hw, I40E_SR_PBA_FLAGS, &pba_word);
1223 [ # # # # ]: 0 : if ((status != I40E_SUCCESS) || (pba_word != 0xFAFA)) {
1224 : 0 : DEBUGOUT("Failed to read PBA flags or flag is invalid.\n");
1225 : 0 : return status;
1226 : : }
1227 : :
1228 : 0 : status = i40e_read_nvm_word(hw, I40E_SR_PBA_BLOCK_PTR, &pba_ptr);
1229 [ # # ]: 0 : if (status != I40E_SUCCESS) {
1230 : 0 : DEBUGOUT("Failed to read PBA Block pointer.\n");
1231 : 0 : return status;
1232 : : }
1233 : :
1234 : 0 : status = i40e_read_nvm_word(hw, pba_ptr, &pba_size);
1235 [ # # ]: 0 : if (status != I40E_SUCCESS) {
1236 : 0 : DEBUGOUT("Failed to read PBA Block size.\n");
1237 : 0 : return status;
1238 : : }
1239 : :
1240 : : /* Subtract one to get PBA word count (PBA Size word is included in
1241 : : * total size)
1242 : : */
1243 : 0 : pba_size--;
1244 [ # # ]: 0 : if (pba_num_size < (((u32)pba_size * 2) + 1)) {
1245 : 0 : DEBUGOUT("Buffer to small for PBA data.\n");
1246 : 0 : return I40E_ERR_PARAM;
1247 : : }
1248 : :
1249 [ # # ]: 0 : for (i = 0; i < pba_size; i++) {
1250 : 0 : status = i40e_read_nvm_word(hw, (pba_ptr + 1) + i, &pba_word);
1251 [ # # ]: 0 : if (status != I40E_SUCCESS) {
1252 : 0 : DEBUGOUT1("Failed to read PBA Block word %d.\n", i);
1253 : 0 : return status;
1254 : : }
1255 : :
1256 : 0 : pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
1257 : 0 : pba_num[(i * 2) + 1] = pba_word & 0xFF;
1258 : : }
1259 : 0 : pba_num[(pba_size * 2)] = '\0';
1260 : :
1261 : 0 : return status;
1262 : : }
1263 : :
1264 : : /**
1265 : : * i40e_get_media_type - Gets media type
1266 : : * @hw: pointer to the hardware structure
1267 : : **/
1268 : : STATIC enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
1269 : : {
1270 : : enum i40e_media_type media;
1271 : :
1272 : : switch (hw->phy.link_info.phy_type) {
1273 : : case I40E_PHY_TYPE_10GBASE_SR:
1274 : : case I40E_PHY_TYPE_10GBASE_LR:
1275 : : case I40E_PHY_TYPE_1000BASE_SX:
1276 : : case I40E_PHY_TYPE_1000BASE_LX:
1277 : : case I40E_PHY_TYPE_40GBASE_SR4:
1278 : : case I40E_PHY_TYPE_40GBASE_LR4:
1279 : : case I40E_PHY_TYPE_25GBASE_LR:
1280 : : case I40E_PHY_TYPE_25GBASE_SR:
1281 : : case I40E_PHY_TYPE_10GBASE_AOC:
1282 : : case I40E_PHY_TYPE_25GBASE_AOC:
1283 : : case I40E_PHY_TYPE_40GBASE_AOC:
1284 : : media = I40E_MEDIA_TYPE_FIBER;
1285 : : break;
1286 : : case I40E_PHY_TYPE_100BASE_TX:
1287 : : case I40E_PHY_TYPE_1000BASE_T:
1288 : : case I40E_PHY_TYPE_2_5GBASE_T_LINK_STATUS:
1289 : : case I40E_PHY_TYPE_5GBASE_T_LINK_STATUS:
1290 : : case I40E_PHY_TYPE_10GBASE_T:
1291 : : media = I40E_MEDIA_TYPE_BASET;
1292 : : break;
1293 : : case I40E_PHY_TYPE_10GBASE_CR1_CU:
1294 : : case I40E_PHY_TYPE_40GBASE_CR4_CU:
1295 : : case I40E_PHY_TYPE_10GBASE_CR1:
1296 : : case I40E_PHY_TYPE_40GBASE_CR4:
1297 : : case I40E_PHY_TYPE_10GBASE_SFPP_CU:
1298 : : case I40E_PHY_TYPE_25GBASE_CR:
1299 : : case I40E_PHY_TYPE_25GBASE_ACC:
1300 : : media = I40E_MEDIA_TYPE_DA;
1301 : : break;
1302 : : case I40E_PHY_TYPE_1000BASE_KX:
1303 : : case I40E_PHY_TYPE_10GBASE_KX4:
1304 : : case I40E_PHY_TYPE_10GBASE_KR:
1305 : : case I40E_PHY_TYPE_40GBASE_KR4:
1306 : : case I40E_PHY_TYPE_20GBASE_KR2:
1307 : : case I40E_PHY_TYPE_25GBASE_KR:
1308 : : media = I40E_MEDIA_TYPE_BACKPLANE;
1309 : : break;
1310 : : case I40E_PHY_TYPE_SGMII:
1311 : : case I40E_PHY_TYPE_XAUI:
1312 : : case I40E_PHY_TYPE_XFI:
1313 : : case I40E_PHY_TYPE_XLAUI:
1314 : : case I40E_PHY_TYPE_XLPPI:
1315 : : default:
1316 : : media = I40E_MEDIA_TYPE_UNKNOWN;
1317 : : break;
1318 : : }
1319 : :
1320 : : return media;
1321 : : }
1322 : :
1323 : : /**
1324 : : * i40e_poll_globr - Poll for Global Reset completion
1325 : : * @hw: pointer to the hardware structure
1326 : : * @retry_limit: how many times to retry before failure
1327 : : **/
1328 : 0 : STATIC enum i40e_status_code i40e_poll_globr(struct i40e_hw *hw,
1329 : : u32 retry_limit)
1330 : : {
1331 : : u32 cnt, reg = 0;
1332 : :
1333 [ # # ]: 0 : for (cnt = 0; cnt < retry_limit; cnt++) {
1334 : 0 : reg = rd32(hw, I40E_GLGEN_RSTAT);
1335 [ # # ]: 0 : if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
1336 : : return I40E_SUCCESS;
1337 : 0 : i40e_msec_delay(100);
1338 : : }
1339 : :
1340 : 0 : DEBUGOUT("Global reset failed.\n");
1341 : 0 : DEBUGOUT1("I40E_GLGEN_RSTAT = 0x%x\n", reg);
1342 : :
1343 : 0 : return I40E_ERR_RESET_FAILED;
1344 : : }
1345 : :
1346 : : #define I40E_PF_RESET_WAIT_COUNT 1000
1347 : : /**
1348 : : * i40e_pf_reset - Reset the PF
1349 : : * @hw: pointer to the hardware structure
1350 : : *
1351 : : * Assuming someone else has triggered a global reset,
1352 : : * assure the global reset is complete and then reset the PF
1353 : : **/
1354 : 0 : enum i40e_status_code i40e_pf_reset(struct i40e_hw *hw)
1355 : : {
1356 : : u32 cnt = 0;
1357 : : u32 cnt1 = 0;
1358 : : u32 reg = 0;
1359 : : u32 grst_del;
1360 : :
1361 : : /* Poll for Global Reset steady state in case of recent GRST.
1362 : : * The grst delay value is in 100ms units, and we'll wait a
1363 : : * couple counts longer to be sure we don't just miss the end.
1364 : : */
1365 : 0 : grst_del = (rd32(hw, I40E_GLGEN_RSTCTL) &
1366 : : I40E_GLGEN_RSTCTL_GRSTDEL_MASK) >>
1367 : : I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
1368 : :
1369 : 0 : grst_del = min(grst_del * 20, 160U);
1370 : :
1371 [ # # ]: 0 : for (cnt = 0; cnt < grst_del; cnt++) {
1372 : 0 : reg = rd32(hw, I40E_GLGEN_RSTAT);
1373 [ # # ]: 0 : if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
1374 : : break;
1375 : 0 : i40e_msec_delay(100);
1376 : : }
1377 [ # # ]: 0 : if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
1378 : 0 : DEBUGOUT("Global reset polling failed to complete.\n");
1379 : 0 : return I40E_ERR_RESET_FAILED;
1380 : : }
1381 : :
1382 : : /* Now Wait for the FW to be ready */
1383 [ # # ]: 0 : for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
1384 : 0 : reg = rd32(hw, I40E_GLNVM_ULD);
1385 : 0 : reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1386 : : I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
1387 [ # # ]: 0 : if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1388 : : I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
1389 : 0 : DEBUGOUT1("Core and Global modules ready %d\n", cnt1);
1390 : 0 : break;
1391 : : }
1392 : 0 : i40e_msec_delay(10);
1393 : : }
1394 [ # # ]: 0 : if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
1395 : : I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
1396 : 0 : DEBUGOUT("wait for FW Reset complete timedout\n");
1397 : 0 : DEBUGOUT1("I40E_GLNVM_ULD = 0x%x\n", reg);
1398 : 0 : return I40E_ERR_RESET_FAILED;
1399 : : }
1400 : :
1401 : : /* If there was a Global Reset in progress when we got here,
1402 : : * we don't need to do the PF Reset
1403 : : */
1404 [ # # ]: 0 : if (!cnt) {
1405 : : u32 reg2 = 0;
1406 : :
1407 : 0 : reg = rd32(hw, I40E_PFGEN_CTRL);
1408 : 0 : wr32(hw, I40E_PFGEN_CTRL,
1409 : : (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
1410 [ # # ]: 0 : for (cnt = 0; cnt < I40E_PF_RESET_WAIT_COUNT; cnt++) {
1411 : 0 : reg = rd32(hw, I40E_PFGEN_CTRL);
1412 [ # # ]: 0 : if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
1413 : : break;
1414 : 0 : reg2 = rd32(hw, I40E_GLGEN_RSTAT);
1415 [ # # ]: 0 : if (reg2 & I40E_GLGEN_RSTAT_DEVSTATE_MASK)
1416 : : break;
1417 : 0 : i40e_msec_delay(1);
1418 : : }
1419 [ # # ]: 0 : if (reg2 & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
1420 [ # # ]: 0 : if (i40e_poll_globr(hw, grst_del) != I40E_SUCCESS)
1421 : : return I40E_ERR_RESET_FAILED;
1422 [ # # ]: 0 : } else if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
1423 : 0 : DEBUGOUT("PF reset polling failed to complete.\n");
1424 : 0 : return I40E_ERR_RESET_FAILED;
1425 : : }
1426 : : }
1427 : :
1428 : 0 : i40e_clear_pxe_mode(hw);
1429 : :
1430 : :
1431 : 0 : return I40E_SUCCESS;
1432 : : }
1433 : :
1434 : : /**
1435 : : * i40e_clear_hw - clear out any left over hw state
1436 : : * @hw: pointer to the hw struct
1437 : : *
1438 : : * Clear queues and interrupts, typically called at init time,
1439 : : * but after the capabilities have been found so we know how many
1440 : : * queues and msix vectors have been allocated.
1441 : : **/
1442 : 0 : void i40e_clear_hw(struct i40e_hw *hw)
1443 : : {
1444 : : u32 num_queues, base_queue;
1445 : : u32 num_pf_int;
1446 : : u32 num_vf_int;
1447 : : u32 num_vfs;
1448 : : u32 i, j;
1449 : : u32 val;
1450 : : u32 eol = 0x7ff;
1451 : :
1452 : : /* get number of interrupts, queues, and vfs */
1453 : 0 : val = rd32(hw, I40E_GLPCI_CNF2);
1454 : 0 : num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
1455 : : I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
1456 : 0 : num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
1457 : : I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
1458 : :
1459 : 0 : val = rd32(hw, I40E_PFLAN_QALLOC);
1460 : 0 : base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
1461 : : I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
1462 : 0 : j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
1463 : : I40E_PFLAN_QALLOC_LASTQ_SHIFT;
1464 [ # # ]: 0 : if (val & I40E_PFLAN_QALLOC_VALID_MASK)
1465 : 0 : num_queues = (j - base_queue) + 1;
1466 : : else
1467 : : num_queues = 0;
1468 : :
1469 : 0 : val = rd32(hw, I40E_PF_VT_PFALLOC);
1470 : 0 : i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
1471 : : I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
1472 : 0 : j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
1473 : : I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
1474 [ # # ]: 0 : if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
1475 : 0 : num_vfs = (j - i) + 1;
1476 : : else
1477 : : num_vfs = 0;
1478 : :
1479 : : /* stop all the interrupts */
1480 : 0 : wr32(hw, I40E_PFINT_ICR0_ENA, 0);
1481 : : val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
1482 [ # # ]: 0 : for (i = 0; i < num_pf_int - 2; i++)
1483 : 0 : wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
1484 : :
1485 : : /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
1486 : : val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1487 : 0 : wr32(hw, I40E_PFINT_LNKLST0, val);
1488 [ # # ]: 0 : for (i = 0; i < num_pf_int - 2; i++)
1489 : 0 : wr32(hw, I40E_PFINT_LNKLSTN(i), val);
1490 : : val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1491 [ # # ]: 0 : for (i = 0; i < num_vfs; i++)
1492 : 0 : wr32(hw, I40E_VPINT_LNKLST0(i), val);
1493 [ # # ]: 0 : for (i = 0; i < num_vf_int - 2; i++)
1494 : 0 : wr32(hw, I40E_VPINT_LNKLSTN(i), val);
1495 : :
1496 : : /* warn the HW of the coming Tx disables */
1497 [ # # ]: 0 : for (i = 0; i < num_queues; i++) {
1498 : 0 : u32 abs_queue_idx = base_queue + i;
1499 : : u32 reg_block = 0;
1500 : :
1501 [ # # ]: 0 : if (abs_queue_idx >= 128) {
1502 : 0 : reg_block = abs_queue_idx / 128;
1503 : 0 : abs_queue_idx %= 128;
1504 : : }
1505 : :
1506 : 0 : val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1507 : 0 : val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1508 : 0 : val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1509 : 0 : val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1510 : :
1511 : 0 : wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
1512 : : }
1513 : 0 : i40e_usec_delay(400);
1514 : :
1515 : : /* stop all the queues */
1516 [ # # ]: 0 : for (i = 0; i < num_queues; i++) {
1517 : 0 : wr32(hw, I40E_QINT_TQCTL(i), 0);
1518 : 0 : wr32(hw, I40E_QTX_ENA(i), 0);
1519 : 0 : wr32(hw, I40E_QINT_RQCTL(i), 0);
1520 : 0 : wr32(hw, I40E_QRX_ENA(i), 0);
1521 : : }
1522 : :
1523 : : /* short wait for all queue disables to settle */
1524 : 0 : i40e_usec_delay(50);
1525 : 0 : }
1526 : :
1527 : : /**
1528 : : * i40e_clear_pxe_mode - clear pxe operations mode
1529 : : * @hw: pointer to the hw struct
1530 : : *
1531 : : * Make sure all PXE mode settings are cleared, including things
1532 : : * like descriptor fetch/write-back mode.
1533 : : **/
1534 : 0 : void i40e_clear_pxe_mode(struct i40e_hw *hw)
1535 : : {
1536 [ # # ]: 0 : if (i40e_check_asq_alive(hw))
1537 : 0 : i40e_aq_clear_pxe_mode(hw, NULL);
1538 : 0 : }
1539 : :
1540 : : /**
1541 : : * i40e_led_is_mine - helper to find matching led
1542 : : * @hw: pointer to the hw struct
1543 : : * @idx: index into GPIO registers
1544 : : *
1545 : : * returns: 0 if no match, otherwise the value of the GPIO_CTL register
1546 : : */
1547 : 0 : static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
1548 : : {
1549 : : u32 gpio_val = 0;
1550 : : u32 port;
1551 : :
1552 [ # # ]: 0 : if (!I40E_IS_X710TL_DEVICE(hw->device_id) &&
1553 [ # # ]: 0 : !hw->func_caps.led[idx])
1554 : : return 0;
1555 : 0 : gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
1556 : 0 : port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
1557 : : I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
1558 : :
1559 : : /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
1560 : : * if it is not our port then ignore
1561 : : */
1562 [ # # ]: 0 : if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
1563 [ # # ]: 0 : (port != hw->port))
1564 : 0 : return 0;
1565 : :
1566 : : return gpio_val;
1567 : : }
1568 : :
1569 : : #define I40E_COMBINED_ACTIVITY 0xA
1570 : : #define I40E_FILTER_ACTIVITY 0xE
1571 : : #define I40E_LINK_ACTIVITY 0xC
1572 : : #define I40E_MAC_ACTIVITY 0xD
1573 : : #define I40E_FW_LED BIT(4)
1574 : : #define I40E_LED_MODE_VALID (I40E_GLGEN_GPIO_CTL_LED_MODE_MASK >> \
1575 : : I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT)
1576 : :
1577 : : #define I40E_LED0 22
1578 : :
1579 : : #define I40E_PIN_FUNC_SDP 0x0
1580 : : #define I40E_PIN_FUNC_LED 0x1
1581 : :
1582 : : /**
1583 : : * i40e_led_get - return current on/off mode
1584 : : * @hw: pointer to the hw struct
1585 : : *
1586 : : * The value returned is the 'mode' field as defined in the
1587 : : * GPIO register definitions: 0x0 = off, 0xf = on, and other
1588 : : * values are variations of possible behaviors relating to
1589 : : * blink, link, and wire.
1590 : : **/
1591 : 0 : u32 i40e_led_get(struct i40e_hw *hw)
1592 : : {
1593 : : u32 current_mode = 0;
1594 : : u32 mode = 0;
1595 : : int i;
1596 : :
1597 : : /* as per the documentation GPIO 22-29 are the LED
1598 : : * GPIO pins named LED0..LED7
1599 : : */
1600 [ # # ]: 0 : for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1601 : 0 : u32 gpio_val = i40e_led_is_mine(hw, i);
1602 : :
1603 [ # # ]: 0 : if (!gpio_val)
1604 : 0 : continue;
1605 : :
1606 : : /* ignore gpio LED src mode entries related to the activity
1607 : : * LEDs
1608 : : */
1609 : 0 : current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1610 : 0 : >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1611 [ # # ]: 0 : switch (current_mode) {
1612 : 0 : case I40E_COMBINED_ACTIVITY:
1613 : : case I40E_FILTER_ACTIVITY:
1614 : : case I40E_MAC_ACTIVITY:
1615 : : case I40E_LINK_ACTIVITY:
1616 : 0 : continue;
1617 : : default:
1618 : : break;
1619 : : }
1620 : :
1621 : : mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
1622 : : I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
1623 : : break;
1624 : : }
1625 : :
1626 : 0 : return mode;
1627 : : }
1628 : :
1629 : : /**
1630 : : * i40e_led_set - set new on/off mode
1631 : : * @hw: pointer to the hw struct
1632 : : * @mode: 0=off, 0xf=on (else see manual for mode details)
1633 : : * @blink: true if the LED should blink when on, false if steady
1634 : : *
1635 : : * if this function is used to turn on the blink it should
1636 : : * be used to disable the blink when restoring the original state.
1637 : : **/
1638 : 0 : void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
1639 : : {
1640 : : u32 current_mode = 0;
1641 : : int i;
1642 : :
1643 [ # # ]: 0 : if (mode & ~I40E_LED_MODE_VALID) {
1644 : 0 : DEBUGOUT1("invalid mode passed in %X\n", mode);
1645 : 0 : return;
1646 : : }
1647 : :
1648 : : /* as per the documentation GPIO 22-29 are the LED
1649 : : * GPIO pins named LED0..LED7
1650 : : */
1651 [ # # ]: 0 : for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1652 : 0 : u32 gpio_val = i40e_led_is_mine(hw, i);
1653 : :
1654 [ # # ]: 0 : if (!gpio_val)
1655 : 0 : continue;
1656 : :
1657 : : /* ignore gpio LED src mode entries related to the activity
1658 : : * LEDs
1659 : : */
1660 : 0 : current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK)
1661 : 0 : >> I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1662 [ # # ]: 0 : switch (current_mode) {
1663 : 0 : case I40E_COMBINED_ACTIVITY:
1664 : : case I40E_FILTER_ACTIVITY:
1665 : : case I40E_MAC_ACTIVITY:
1666 : : case I40E_LINK_ACTIVITY:
1667 : 0 : continue;
1668 : : default:
1669 : : break;
1670 : : }
1671 : :
1672 [ # # ]: 0 : if (I40E_IS_X710TL_DEVICE(hw->device_id)) {
1673 : : u32 pin_func = 0;
1674 : :
1675 [ # # ]: 0 : if (mode & I40E_FW_LED)
1676 : : pin_func = I40E_PIN_FUNC_SDP;
1677 : : else
1678 : : pin_func = I40E_PIN_FUNC_LED;
1679 : :
1680 : 0 : gpio_val &= ~I40E_GLGEN_GPIO_CTL_PIN_FUNC_MASK;
1681 : 0 : gpio_val |= ((pin_func <<
1682 : : I40E_GLGEN_GPIO_CTL_PIN_FUNC_SHIFT) &
1683 : : I40E_GLGEN_GPIO_CTL_PIN_FUNC_MASK);
1684 : : }
1685 : 0 : gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
1686 : : /* this & is a bit of paranoia, but serves as a range check */
1687 : 0 : gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
1688 : : I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
1689 : :
1690 [ # # ]: 0 : if (blink)
1691 : 0 : gpio_val |= BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
1692 : : else
1693 : 0 : gpio_val &= ~BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
1694 : :
1695 : 0 : wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
1696 : : break;
1697 : : }
1698 : : }
1699 : :
1700 : : /* Admin command wrappers */
1701 : :
1702 : : /**
1703 : : * i40e_aq_get_phy_capabilities
1704 : : * @hw: pointer to the hw struct
1705 : : * @abilities: structure for PHY capabilities to be filled
1706 : : * @qualified_modules: report Qualified Modules
1707 : : * @report_init: report init capabilities (active are default)
1708 : : * @cmd_details: pointer to command details structure or NULL
1709 : : *
1710 : : * Returns the various PHY abilities supported on the Port.
1711 : : **/
1712 : 0 : enum i40e_status_code i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
1713 : : bool qualified_modules, bool report_init,
1714 : : struct i40e_aq_get_phy_abilities_resp *abilities,
1715 : : struct i40e_asq_cmd_details *cmd_details)
1716 : : {
1717 : : struct i40e_aq_desc desc;
1718 : : enum i40e_status_code status;
1719 : : u16 max_delay = I40E_MAX_PHY_TIMEOUT, total_delay = 0;
1720 : : u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
1721 : :
1722 [ # # ]: 0 : if (!abilities)
1723 : : return I40E_ERR_PARAM;
1724 : :
1725 : : do {
1726 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
1727 : : i40e_aqc_opc_get_phy_abilities);
1728 : :
1729 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
1730 : : if (abilities_size > I40E_AQ_LARGE_BUF)
1731 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
1732 : :
1733 [ # # ]: 0 : if (qualified_modules)
1734 : 0 : desc.params.external.param0 |=
1735 : : CPU_TO_LE32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
1736 : :
1737 [ # # ]: 0 : if (report_init)
1738 : 0 : desc.params.external.param0 |=
1739 : : CPU_TO_LE32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
1740 : :
1741 : 0 : status = i40e_asq_send_command(hw, &desc, abilities,
1742 : : abilities_size, cmd_details);
1743 : :
1744 [ # # # ]: 0 : switch (hw->aq.asq_last_status) {
1745 : 0 : case I40E_AQ_RC_EIO:
1746 : : status = I40E_ERR_UNKNOWN_PHY;
1747 : 0 : break;
1748 : 0 : case I40E_AQ_RC_EAGAIN:
1749 : 0 : i40e_msec_delay(1);
1750 : 0 : total_delay++;
1751 : : status = I40E_ERR_TIMEOUT;
1752 : 0 : break;
1753 : : /* also covers I40E_AQ_RC_OK */
1754 : : default:
1755 : : break;
1756 : : }
1757 : :
1758 [ # # # # ]: 0 : } while ((hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN) &&
1759 : : (total_delay < max_delay));
1760 : :
1761 [ # # ]: 0 : if (status != I40E_SUCCESS)
1762 : : return status;
1763 : :
1764 [ # # ]: 0 : if (report_init) {
1765 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_XL710 &&
1766 [ # # ]: 0 : hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
1767 [ # # ]: 0 : hw->aq.api_min_ver >= I40E_MINOR_VER_GET_LINK_INFO_XL710) {
1768 : 0 : status = i40e_aq_get_link_info(hw, true, NULL, NULL);
1769 : : } else {
1770 : 0 : hw->phy.phy_types = LE32_TO_CPU(abilities->phy_type);
1771 : 0 : hw->phy.phy_types |=
1772 : 0 : ((u64)abilities->phy_type_ext << 32);
1773 : : }
1774 : : }
1775 : :
1776 : : return status;
1777 : : }
1778 : :
1779 : : /**
1780 : : * i40e_aq_set_phy_config
1781 : : * @hw: pointer to the hw struct
1782 : : * @config: structure with PHY configuration to be set
1783 : : * @cmd_details: pointer to command details structure or NULL
1784 : : *
1785 : : * Set the various PHY configuration parameters
1786 : : * supported on the Port.One or more of the Set PHY config parameters may be
1787 : : * ignored in an MFP mode as the PF may not have the privilege to set some
1788 : : * of the PHY Config parameters. This status will be indicated by the
1789 : : * command response.
1790 : : **/
1791 : 0 : enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
1792 : : struct i40e_aq_set_phy_config *config,
1793 : : struct i40e_asq_cmd_details *cmd_details)
1794 : : {
1795 : : struct i40e_aq_desc desc;
1796 : : struct i40e_aq_set_phy_config *cmd =
1797 : : (struct i40e_aq_set_phy_config *)&desc.params.raw;
1798 : : enum i40e_status_code status;
1799 : :
1800 [ # # ]: 0 : if (!config)
1801 : : return I40E_ERR_PARAM;
1802 : :
1803 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
1804 : : i40e_aqc_opc_set_phy_config);
1805 : :
1806 : 0 : *cmd = *config;
1807 : :
1808 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1809 : :
1810 : 0 : return status;
1811 : : }
1812 : :
1813 : : /**
1814 : : * i40e_set_fc
1815 : : * @hw: pointer to the hw struct
1816 : : * @aq_failures: buffer to return AdminQ failure information
1817 : : * @atomic_restart: whether to enable atomic link restart
1818 : : *
1819 : : * Set the requested flow control mode using set_phy_config.
1820 : : **/
1821 : 0 : enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
1822 : : bool atomic_restart)
1823 : : {
1824 : 0 : enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
1825 : : struct i40e_aq_get_phy_abilities_resp abilities;
1826 : : struct i40e_aq_set_phy_config config;
1827 : : enum i40e_status_code status;
1828 : : u8 pause_mask = 0x0;
1829 : :
1830 [ # # ]: 0 : *aq_failures = 0x0;
1831 : :
1832 : : switch (fc_mode) {
1833 : : case I40E_FC_FULL:
1834 : : pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1835 : : pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1836 : : break;
1837 : : case I40E_FC_RX_PAUSE:
1838 : : pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1839 : : break;
1840 : : case I40E_FC_TX_PAUSE:
1841 : : pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1842 : : break;
1843 : : default:
1844 : : break;
1845 : : }
1846 : :
1847 : : /* Get the current phy config */
1848 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
1849 : : NULL);
1850 [ # # ]: 0 : if (status) {
1851 : 0 : *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
1852 : 0 : return status;
1853 : : }
1854 : :
1855 : : memset(&config, 0, sizeof(config));
1856 : : /* clear the old pause settings */
1857 : 0 : config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
1858 : : ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
1859 : : /* set the new abilities */
1860 : 0 : config.abilities |= pause_mask;
1861 : : /* If the abilities have changed, then set the new config */
1862 [ # # ]: 0 : if (config.abilities != abilities.abilities) {
1863 : : /* Auto restart link so settings take effect */
1864 [ # # ]: 0 : if (atomic_restart)
1865 : 0 : config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1866 : : /* Copy over all the old settings */
1867 : 0 : config.phy_type = abilities.phy_type;
1868 : 0 : config.phy_type_ext = abilities.phy_type_ext;
1869 : 0 : config.link_speed = abilities.link_speed;
1870 : 0 : config.eee_capability = abilities.eee_capability;
1871 : 0 : config.eeer = abilities.eeer_val;
1872 : 0 : config.low_power_ctrl = abilities.d3_lpan;
1873 : 0 : config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
1874 : : I40E_AQ_PHY_FEC_CONFIG_MASK;
1875 : 0 : status = i40e_aq_set_phy_config(hw, &config, NULL);
1876 : :
1877 [ # # ]: 0 : if (status)
1878 : 0 : *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
1879 : : }
1880 : : /* Update the link info */
1881 : 0 : status = i40e_update_link_info(hw);
1882 [ # # ]: 0 : if (status) {
1883 : : /* Wait a little bit (on 40G cards it sometimes takes a really
1884 : : * long time for link to come back from the atomic reset)
1885 : : * and try once more
1886 : : */
1887 : 0 : i40e_msec_delay(1000);
1888 : 0 : status = i40e_update_link_info(hw);
1889 : : }
1890 [ # # ]: 0 : if (status)
1891 : 0 : *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
1892 : :
1893 : : return status;
1894 : : }
1895 : :
1896 : : /**
1897 : : * i40e_aq_set_mac_config
1898 : : * @hw: pointer to the hw struct
1899 : : * @max_frame_size: Maximum Frame Size to be supported by the port
1900 : : * @crc_en: Tell HW to append a CRC to outgoing frames
1901 : : * @pacing: Pacing configurations
1902 : : * @auto_drop_blocking_packets: Tell HW to drop packets if TC queue is blocked
1903 : : * @cmd_details: pointer to command details structure or NULL
1904 : : *
1905 : : * Configure MAC settings for frame size, jumbo frame support and the
1906 : : * addition of a CRC by the hardware.
1907 : : **/
1908 : 0 : enum i40e_status_code i40e_aq_set_mac_config(struct i40e_hw *hw,
1909 : : u16 max_frame_size,
1910 : : bool crc_en, u16 pacing,
1911 : : bool auto_drop_blocking_packets,
1912 : : struct i40e_asq_cmd_details *cmd_details)
1913 : : {
1914 : : struct i40e_aq_desc desc;
1915 : : struct i40e_aq_set_mac_config *cmd =
1916 : : (struct i40e_aq_set_mac_config *)&desc.params.raw;
1917 : : enum i40e_status_code status;
1918 : :
1919 [ # # ]: 0 : if (max_frame_size == 0)
1920 : : return I40E_ERR_PARAM;
1921 : :
1922 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
1923 : : i40e_aqc_opc_set_mac_config);
1924 : :
1925 : 0 : cmd->max_frame_size = CPU_TO_LE16(max_frame_size);
1926 : 0 : cmd->params = ((u8)pacing & 0x0F) << 3;
1927 [ # # ]: 0 : if (crc_en)
1928 : 0 : cmd->params |= I40E_AQ_SET_MAC_CONFIG_CRC_EN;
1929 : :
1930 [ # # ]: 0 : if (auto_drop_blocking_packets) {
1931 [ # # ]: 0 : if (hw->flags & I40E_HW_FLAG_DROP_MODE)
1932 : 0 : cmd->params |=
1933 : : I40E_AQ_SET_MAC_CONFIG_DROP_BLOCKING_PACKET_EN;
1934 : : else
1935 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_ALL,
1936 : : "This FW api version does not support drop mode.\n");
1937 : : }
1938 : :
1939 : : #define I40E_AQ_SET_MAC_CONFIG_FC_DEFAULT_THRESHOLD 0x7FFF
1940 : 0 : cmd->fc_refresh_threshold =
1941 : : CPU_TO_LE16(I40E_AQ_SET_MAC_CONFIG_FC_DEFAULT_THRESHOLD);
1942 : :
1943 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1944 : :
1945 : 0 : return status;
1946 : : }
1947 : :
1948 : : /**
1949 : : * i40e_aq_clear_pxe_mode
1950 : : * @hw: pointer to the hw struct
1951 : : * @cmd_details: pointer to command details structure or NULL
1952 : : *
1953 : : * Tell the firmware that the driver is taking over from PXE
1954 : : **/
1955 : 0 : enum i40e_status_code i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
1956 : : struct i40e_asq_cmd_details *cmd_details)
1957 : : {
1958 : : enum i40e_status_code status;
1959 : : struct i40e_aq_desc desc;
1960 : : struct i40e_aqc_clear_pxe *cmd =
1961 : : (struct i40e_aqc_clear_pxe *)&desc.params.raw;
1962 : :
1963 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
1964 : : i40e_aqc_opc_clear_pxe_mode);
1965 : :
1966 : 0 : cmd->rx_cnt = 0x2;
1967 : :
1968 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1969 : :
1970 : 0 : wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
1971 : :
1972 : 0 : return status;
1973 : : }
1974 : :
1975 : : /**
1976 : : * i40e_aq_set_link_restart_an
1977 : : * @hw: pointer to the hw struct
1978 : : * @enable_link: if true: enable link, if false: disable link
1979 : : * @cmd_details: pointer to command details structure or NULL
1980 : : *
1981 : : * Sets up the link and restarts the Auto-Negotiation over the link.
1982 : : **/
1983 : 0 : enum i40e_status_code i40e_aq_set_link_restart_an(struct i40e_hw *hw,
1984 : : bool enable_link, struct i40e_asq_cmd_details *cmd_details)
1985 : : {
1986 : : struct i40e_aq_desc desc;
1987 : : struct i40e_aqc_set_link_restart_an *cmd =
1988 : : (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
1989 : : enum i40e_status_code status;
1990 : :
1991 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
1992 : : i40e_aqc_opc_set_link_restart_an);
1993 : :
1994 : 0 : cmd->command = I40E_AQ_PHY_RESTART_AN;
1995 [ # # ]: 0 : if (enable_link)
1996 : 0 : cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
1997 : : else
1998 : : cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
1999 : :
2000 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2001 : :
2002 : 0 : return status;
2003 : : }
2004 : :
2005 : : /**
2006 : : * i40e_aq_get_link_info
2007 : : * @hw: pointer to the hw struct
2008 : : * @enable_lse: enable/disable LinkStatusEvent reporting
2009 : : * @link: pointer to link status structure - optional
2010 : : * @cmd_details: pointer to command details structure or NULL
2011 : : *
2012 : : * Returns the link status of the adapter.
2013 : : **/
2014 : 0 : enum i40e_status_code i40e_aq_get_link_info(struct i40e_hw *hw,
2015 : : bool enable_lse, struct i40e_link_status *link,
2016 : : struct i40e_asq_cmd_details *cmd_details)
2017 : : {
2018 : : struct i40e_aq_desc desc;
2019 : : struct i40e_aqc_get_link_status *resp =
2020 : : (struct i40e_aqc_get_link_status *)&desc.params.raw;
2021 : 0 : struct i40e_link_status *hw_link_info = &hw->phy.link_info;
2022 : : enum i40e_status_code status;
2023 : : bool tx_pause, rx_pause;
2024 : : u16 command_flags;
2025 : :
2026 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
2027 : :
2028 [ # # ]: 0 : if (enable_lse)
2029 : : command_flags = I40E_AQ_LSE_ENABLE;
2030 : : else
2031 : : command_flags = I40E_AQ_LSE_DISABLE;
2032 : 0 : resp->command_flags = CPU_TO_LE16(command_flags);
2033 : :
2034 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2035 : :
2036 [ # # ]: 0 : if (status != I40E_SUCCESS)
2037 : 0 : goto aq_get_link_info_exit;
2038 : :
2039 : : /* save off old link status information */
2040 [ # # ]: 0 : i40e_memcpy(&hw->phy.link_info_old, hw_link_info,
2041 : : sizeof(*hw_link_info), I40E_NONDMA_TO_NONDMA);
2042 : :
2043 : : /* update link status */
2044 [ # # ]: 0 : hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
2045 : 0 : hw->phy.media_type = i40e_get_media_type(hw);
2046 : 0 : hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
2047 : 0 : hw_link_info->link_info = resp->link_info;
2048 : 0 : hw_link_info->an_info = resp->an_info;
2049 : 0 : hw_link_info->fec_info = resp->config & (I40E_AQ_CONFIG_FEC_KR_ENA |
2050 : : I40E_AQ_CONFIG_FEC_RS_ENA);
2051 : 0 : hw_link_info->ext_info = resp->ext_info;
2052 : 0 : hw_link_info->loopback = resp->loopback & I40E_AQ_LOOPBACK_MASK;
2053 : 0 : hw_link_info->max_frame_size = LE16_TO_CPU(resp->max_frame_size);
2054 : 0 : hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
2055 : :
2056 : : /* update fc info */
2057 : 0 : tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
2058 : 0 : rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
2059 [ # # ]: 0 : if (tx_pause & rx_pause)
2060 : 0 : hw->fc.current_mode = I40E_FC_FULL;
2061 [ # # ]: 0 : else if (tx_pause)
2062 : 0 : hw->fc.current_mode = I40E_FC_TX_PAUSE;
2063 [ # # ]: 0 : else if (rx_pause)
2064 : 0 : hw->fc.current_mode = I40E_FC_RX_PAUSE;
2065 : : else
2066 : 0 : hw->fc.current_mode = I40E_FC_NONE;
2067 : :
2068 [ # # ]: 0 : if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
2069 : 0 : hw_link_info->crc_enable = true;
2070 : : else
2071 : 0 : hw_link_info->crc_enable = false;
2072 : :
2073 [ # # ]: 0 : if (resp->command_flags & CPU_TO_LE16(I40E_AQ_LSE_IS_ENABLED))
2074 : 0 : hw_link_info->lse_enable = true;
2075 : : else
2076 : 0 : hw_link_info->lse_enable = false;
2077 : :
2078 [ # # ]: 0 : if ((hw->mac.type == I40E_MAC_XL710) &&
2079 [ # # # # ]: 0 : (hw->aq.fw_maj_ver < 4 || (hw->aq.fw_maj_ver == 4 &&
2080 [ # # # # ]: 0 : hw->aq.fw_min_ver < 40)) && hw_link_info->phy_type == 0xE)
2081 : 0 : hw_link_info->phy_type = I40E_PHY_TYPE_10GBASE_SFPP_CU;
2082 : :
2083 : : /* 'Get Link Status' response data structure from X722 FW has
2084 : : * different format and does not contain this information
2085 : : */
2086 [ # # # # ]: 0 : if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE &&
2087 : : hw->mac.type != I40E_MAC_X722) {
2088 : : __le32 tmp;
2089 : :
2090 : : i40e_memcpy(&tmp, resp->link_type, sizeof(tmp),
2091 : : I40E_NONDMA_TO_NONDMA);
2092 : 0 : hw->phy.phy_types = LE32_TO_CPU(tmp);
2093 : 0 : hw->phy.phy_types |= ((u64)resp->link_type_ext << 32);
2094 : : }
2095 : :
2096 : : /* save link status information */
2097 [ # # ]: 0 : if (link)
2098 : : i40e_memcpy(link, hw_link_info, sizeof(*hw_link_info),
2099 : : I40E_NONDMA_TO_NONDMA);
2100 : :
2101 : : /* flag cleared so helper functions don't call AQ again */
2102 : 0 : hw->phy.get_link_info = false;
2103 : :
2104 : 0 : aq_get_link_info_exit:
2105 : 0 : return status;
2106 : : }
2107 : :
2108 : : /**
2109 : : * i40e_aq_set_phy_int_mask
2110 : : * @hw: pointer to the hw struct
2111 : : * @mask: interrupt mask to be set
2112 : : * @cmd_details: pointer to command details structure or NULL
2113 : : *
2114 : : * Set link interrupt mask.
2115 : : **/
2116 : 0 : enum i40e_status_code i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
2117 : : u16 mask,
2118 : : struct i40e_asq_cmd_details *cmd_details)
2119 : : {
2120 : : struct i40e_aq_desc desc;
2121 : : struct i40e_aqc_set_phy_int_mask *cmd =
2122 : : (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
2123 : : enum i40e_status_code status;
2124 : :
2125 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2126 : : i40e_aqc_opc_set_phy_int_mask);
2127 : :
2128 : 0 : cmd->event_mask = CPU_TO_LE16(mask);
2129 : :
2130 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2131 : :
2132 : 0 : return status;
2133 : : }
2134 : :
2135 : : /**
2136 : : * i40e_aq_get_local_advt_reg
2137 : : * @hw: pointer to the hw struct
2138 : : * @advt_reg: local AN advertisement register value
2139 : : * @cmd_details: pointer to command details structure or NULL
2140 : : *
2141 : : * Get the Local AN advertisement register value.
2142 : : **/
2143 : 0 : enum i40e_status_code i40e_aq_get_local_advt_reg(struct i40e_hw *hw,
2144 : : u64 *advt_reg,
2145 : : struct i40e_asq_cmd_details *cmd_details)
2146 : : {
2147 : : struct i40e_aq_desc desc;
2148 : : struct i40e_aqc_an_advt_reg *resp =
2149 : : (struct i40e_aqc_an_advt_reg *)&desc.params.raw;
2150 : : enum i40e_status_code status;
2151 : :
2152 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2153 : : i40e_aqc_opc_get_local_advt_reg);
2154 : :
2155 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2156 : :
2157 [ # # ]: 0 : if (status != I40E_SUCCESS)
2158 : 0 : goto aq_get_local_advt_reg_exit;
2159 : :
2160 : 0 : *advt_reg = (u64)(LE16_TO_CPU(resp->local_an_reg1)) << 32;
2161 : 0 : *advt_reg |= LE32_TO_CPU(resp->local_an_reg0);
2162 : :
2163 : 0 : aq_get_local_advt_reg_exit:
2164 : 0 : return status;
2165 : : }
2166 : :
2167 : : /**
2168 : : * i40e_aq_set_local_advt_reg
2169 : : * @hw: pointer to the hw struct
2170 : : * @advt_reg: local AN advertisement register value
2171 : : * @cmd_details: pointer to command details structure or NULL
2172 : : *
2173 : : * Get the Local AN advertisement register value.
2174 : : **/
2175 : 0 : enum i40e_status_code i40e_aq_set_local_advt_reg(struct i40e_hw *hw,
2176 : : u64 advt_reg,
2177 : : struct i40e_asq_cmd_details *cmd_details)
2178 : : {
2179 : : struct i40e_aq_desc desc;
2180 : : struct i40e_aqc_an_advt_reg *cmd =
2181 : : (struct i40e_aqc_an_advt_reg *)&desc.params.raw;
2182 : : enum i40e_status_code status;
2183 : :
2184 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2185 : : i40e_aqc_opc_get_local_advt_reg);
2186 : :
2187 : 0 : cmd->local_an_reg0 = CPU_TO_LE32(I40E_LO_DWORD(advt_reg));
2188 : 0 : cmd->local_an_reg1 = CPU_TO_LE16(I40E_HI_DWORD(advt_reg));
2189 : :
2190 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2191 : :
2192 : 0 : return status;
2193 : : }
2194 : :
2195 : : /**
2196 : : * i40e_aq_get_partner_advt
2197 : : * @hw: pointer to the hw struct
2198 : : * @advt_reg: AN partner advertisement register value
2199 : : * @cmd_details: pointer to command details structure or NULL
2200 : : *
2201 : : * Get the link partner AN advertisement register value.
2202 : : **/
2203 : 0 : enum i40e_status_code i40e_aq_get_partner_advt(struct i40e_hw *hw,
2204 : : u64 *advt_reg,
2205 : : struct i40e_asq_cmd_details *cmd_details)
2206 : : {
2207 : : struct i40e_aq_desc desc;
2208 : : struct i40e_aqc_an_advt_reg *resp =
2209 : : (struct i40e_aqc_an_advt_reg *)&desc.params.raw;
2210 : : enum i40e_status_code status;
2211 : :
2212 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2213 : : i40e_aqc_opc_get_partner_advt);
2214 : :
2215 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2216 : :
2217 [ # # ]: 0 : if (status != I40E_SUCCESS)
2218 : 0 : goto aq_get_partner_advt_exit;
2219 : :
2220 : 0 : *advt_reg = (u64)(LE16_TO_CPU(resp->local_an_reg1)) << 32;
2221 : 0 : *advt_reg |= LE32_TO_CPU(resp->local_an_reg0);
2222 : :
2223 : 0 : aq_get_partner_advt_exit:
2224 : 0 : return status;
2225 : : }
2226 : :
2227 : : /**
2228 : : * i40e_aq_set_lb_modes
2229 : : * @hw: pointer to the hw struct
2230 : : * @lb_modes: loopback mode to be set
2231 : : * @cmd_details: pointer to command details structure or NULL
2232 : : *
2233 : : * Sets loopback modes.
2234 : : **/
2235 : 0 : enum i40e_status_code i40e_aq_set_lb_modes(struct i40e_hw *hw,
2236 : : u16 lb_modes,
2237 : : struct i40e_asq_cmd_details *cmd_details)
2238 : : {
2239 : : struct i40e_aq_desc desc;
2240 : : struct i40e_aqc_set_lb_mode *cmd =
2241 : : (struct i40e_aqc_set_lb_mode *)&desc.params.raw;
2242 : : enum i40e_status_code status;
2243 : :
2244 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2245 : : i40e_aqc_opc_set_lb_modes);
2246 : :
2247 : 0 : cmd->lb_mode = CPU_TO_LE16(lb_modes);
2248 : :
2249 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2250 : :
2251 : 0 : return status;
2252 : : }
2253 : :
2254 : : /**
2255 : : * i40e_aq_set_phy_debug
2256 : : * @hw: pointer to the hw struct
2257 : : * @cmd_flags: debug command flags
2258 : : * @cmd_details: pointer to command details structure or NULL
2259 : : *
2260 : : * Reset the external PHY.
2261 : : **/
2262 : 0 : enum i40e_status_code i40e_aq_set_phy_debug(struct i40e_hw *hw, u8 cmd_flags,
2263 : : struct i40e_asq_cmd_details *cmd_details)
2264 : : {
2265 : : struct i40e_aq_desc desc;
2266 : : struct i40e_aqc_set_phy_debug *cmd =
2267 : : (struct i40e_aqc_set_phy_debug *)&desc.params.raw;
2268 : : enum i40e_status_code status;
2269 : :
2270 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2271 : : i40e_aqc_opc_set_phy_debug);
2272 : :
2273 : 0 : cmd->command_flags = cmd_flags;
2274 : :
2275 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2276 : :
2277 : 0 : return status;
2278 : : }
2279 : :
2280 : : /**
2281 : : * i40e_hw_ver_ge
2282 : : * @hw: pointer to the hw struct
2283 : : * @maj: api major value
2284 : : * @min: api minor value
2285 : : *
2286 : : * Assert whether current HW api version is greater/equal than provided.
2287 : : **/
2288 : : static bool i40e_hw_ver_ge(struct i40e_hw *hw, u16 maj, u16 min)
2289 : : {
2290 [ # # # # : 0 : if (hw->aq.api_maj_ver > maj ||
# # # # #
# # # ]
2291 [ # # # # : 0 : (hw->aq.api_maj_ver == maj && hw->aq.api_min_ver >= min))
# # # # ]
2292 : : return true;
2293 : : return false;
2294 : : }
2295 : :
2296 : : /**
2297 : : * i40e_aq_add_vsi
2298 : : * @hw: pointer to the hw struct
2299 : : * @vsi_ctx: pointer to a vsi context struct
2300 : : * @cmd_details: pointer to command details structure or NULL
2301 : : *
2302 : : * Add a VSI context to the hardware.
2303 : : **/
2304 : 0 : enum i40e_status_code i40e_aq_add_vsi(struct i40e_hw *hw,
2305 : : struct i40e_vsi_context *vsi_ctx,
2306 : : struct i40e_asq_cmd_details *cmd_details)
2307 : : {
2308 : : struct i40e_aq_desc desc;
2309 : : struct i40e_aqc_add_get_update_vsi *cmd =
2310 : : (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
2311 : : struct i40e_aqc_add_get_update_vsi_completion *resp =
2312 : : (struct i40e_aqc_add_get_update_vsi_completion *)
2313 : : &desc.params.raw;
2314 : : enum i40e_status_code status;
2315 : :
2316 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2317 : : i40e_aqc_opc_add_vsi);
2318 : :
2319 : 0 : cmd->uplink_seid = CPU_TO_LE16(vsi_ctx->uplink_seid);
2320 : 0 : cmd->connection_type = vsi_ctx->connection_type;
2321 : 0 : cmd->vf_id = vsi_ctx->vf_num;
2322 : 0 : cmd->vsi_flags = CPU_TO_LE16(vsi_ctx->flags);
2323 : :
2324 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2325 : :
2326 : 0 : status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2327 : : sizeof(vsi_ctx->info), cmd_details);
2328 : :
2329 [ # # ]: 0 : if (status != I40E_SUCCESS)
2330 : 0 : goto aq_add_vsi_exit;
2331 : :
2332 : 0 : vsi_ctx->seid = LE16_TO_CPU(resp->seid);
2333 : 0 : vsi_ctx->vsi_number = LE16_TO_CPU(resp->vsi_number);
2334 : 0 : vsi_ctx->vsis_allocated = LE16_TO_CPU(resp->vsi_used);
2335 : 0 : vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
2336 : :
2337 : 0 : aq_add_vsi_exit:
2338 : 0 : return status;
2339 : : }
2340 : :
2341 : : /**
2342 : : * i40e_aq_set_default_vsi
2343 : : * @hw: pointer to the hw struct
2344 : : * @seid: vsi number
2345 : : * @cmd_details: pointer to command details structure or NULL
2346 : : **/
2347 : 0 : enum i40e_status_code i40e_aq_set_default_vsi(struct i40e_hw *hw,
2348 : : u16 seid,
2349 : : struct i40e_asq_cmd_details *cmd_details)
2350 : : {
2351 : : struct i40e_aq_desc desc;
2352 : : struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2353 : : (struct i40e_aqc_set_vsi_promiscuous_modes *)
2354 : : &desc.params.raw;
2355 : : enum i40e_status_code status;
2356 : :
2357 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2358 : : i40e_aqc_opc_set_vsi_promiscuous_modes);
2359 : :
2360 : 0 : cmd->promiscuous_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_DEFAULT);
2361 : 0 : cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_DEFAULT);
2362 : 0 : cmd->seid = CPU_TO_LE16(seid);
2363 : :
2364 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2365 : :
2366 : 0 : return status;
2367 : : }
2368 : :
2369 : : /**
2370 : : * i40e_aq_clear_default_vsi
2371 : : * @hw: pointer to the hw struct
2372 : : * @seid: vsi number
2373 : : * @cmd_details: pointer to command details structure or NULL
2374 : : **/
2375 : 0 : enum i40e_status_code i40e_aq_clear_default_vsi(struct i40e_hw *hw,
2376 : : u16 seid,
2377 : : struct i40e_asq_cmd_details *cmd_details)
2378 : : {
2379 : : struct i40e_aq_desc desc;
2380 : : struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2381 : : (struct i40e_aqc_set_vsi_promiscuous_modes *)
2382 : : &desc.params.raw;
2383 : : enum i40e_status_code status;
2384 : :
2385 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2386 : : i40e_aqc_opc_set_vsi_promiscuous_modes);
2387 : :
2388 : 0 : cmd->promiscuous_flags = CPU_TO_LE16(0);
2389 : 0 : cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_DEFAULT);
2390 : 0 : cmd->seid = CPU_TO_LE16(seid);
2391 : :
2392 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2393 : :
2394 : 0 : return status;
2395 : : }
2396 : :
2397 : : /**
2398 : : * i40e_aq_set_vsi_unicast_promiscuous
2399 : : * @hw: pointer to the hw struct
2400 : : * @seid: vsi number
2401 : : * @set: set unicast promiscuous enable/disable
2402 : : * @cmd_details: pointer to command details structure or NULL
2403 : : * @rx_only_promisc: flag to decide if egress traffic gets mirrored in promisc
2404 : : **/
2405 : 0 : enum i40e_status_code i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
2406 : : u16 seid, bool set,
2407 : : struct i40e_asq_cmd_details *cmd_details,
2408 : : bool rx_only_promisc)
2409 : : {
2410 : : struct i40e_aq_desc desc;
2411 : : struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2412 : : (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2413 : : enum i40e_status_code status;
2414 : : u16 flags = 0;
2415 : :
2416 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2417 : : i40e_aqc_opc_set_vsi_promiscuous_modes);
2418 : :
2419 [ # # ]: 0 : if (set) {
2420 : : flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
2421 [ # # ]: 0 : if (rx_only_promisc && i40e_hw_ver_ge(hw, 1, 5))
2422 : : flags |= I40E_AQC_SET_VSI_PROMISC_RX_ONLY;
2423 : : }
2424 : :
2425 : 0 : cmd->promiscuous_flags = CPU_TO_LE16(flags);
2426 : :
2427 [ # # ]: 0 : cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
2428 : : if (i40e_hw_ver_ge(hw, 1, 5))
2429 : 0 : cmd->valid_flags |=
2430 : : CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_RX_ONLY);
2431 : :
2432 : 0 : cmd->seid = CPU_TO_LE16(seid);
2433 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2434 : :
2435 : 0 : return status;
2436 : : }
2437 : :
2438 : : /**
2439 : : * i40e_aq_set_vsi_multicast_promiscuous
2440 : : * @hw: pointer to the hw struct
2441 : : * @seid: vsi number
2442 : : * @set: set multicast promiscuous enable/disable
2443 : : * @cmd_details: pointer to command details structure or NULL
2444 : : **/
2445 : 0 : enum i40e_status_code i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
2446 : : u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
2447 : : {
2448 : : struct i40e_aq_desc desc;
2449 : : struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2450 : : (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2451 : : enum i40e_status_code status;
2452 : : u16 flags = 0;
2453 : :
2454 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2455 : : i40e_aqc_opc_set_vsi_promiscuous_modes);
2456 : :
2457 [ # # ]: 0 : if (set)
2458 : : flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
2459 : :
2460 : 0 : cmd->promiscuous_flags = CPU_TO_LE16(flags);
2461 : :
2462 : 0 : cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
2463 : :
2464 : 0 : cmd->seid = CPU_TO_LE16(seid);
2465 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2466 : :
2467 : 0 : return status;
2468 : : }
2469 : :
2470 : : /**
2471 : : * i40e_aq_set_vsi_full_promiscuous
2472 : : * @hw: pointer to the hw struct
2473 : : * @seid: VSI number
2474 : : * @set: set promiscuous enable/disable
2475 : : * @cmd_details: pointer to command details structure or NULL
2476 : : **/
2477 : 0 : enum i40e_status_code i40e_aq_set_vsi_full_promiscuous(struct i40e_hw *hw,
2478 : : u16 seid, bool set,
2479 : : struct i40e_asq_cmd_details *cmd_details)
2480 : : {
2481 : : struct i40e_aq_desc desc;
2482 : : struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2483 : : (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2484 : : enum i40e_status_code status;
2485 : : u16 flags = 0;
2486 : :
2487 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2488 : : i40e_aqc_opc_set_vsi_promiscuous_modes);
2489 : :
2490 [ # # ]: 0 : if (set)
2491 : : flags = I40E_AQC_SET_VSI_PROMISC_UNICAST |
2492 : : I40E_AQC_SET_VSI_PROMISC_MULTICAST |
2493 : : I40E_AQC_SET_VSI_PROMISC_BROADCAST;
2494 : :
2495 : 0 : cmd->promiscuous_flags = CPU_TO_LE16(flags);
2496 : :
2497 : 0 : cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_UNICAST |
2498 : : I40E_AQC_SET_VSI_PROMISC_MULTICAST |
2499 : : I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2500 : :
2501 : 0 : cmd->seid = CPU_TO_LE16(seid);
2502 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2503 : :
2504 : 0 : return status;
2505 : : }
2506 : :
2507 : : /**
2508 : : * i40e_aq_set_vsi_mc_promisc_on_vlan
2509 : : * @hw: pointer to the hw struct
2510 : : * @seid: vsi number
2511 : : * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2512 : : * @vid: The VLAN tag filter - capture any multicast packet with this VLAN tag
2513 : : * @cmd_details: pointer to command details structure or NULL
2514 : : **/
2515 : 0 : enum i40e_status_code i40e_aq_set_vsi_mc_promisc_on_vlan(struct i40e_hw *hw,
2516 : : u16 seid, bool enable, u16 vid,
2517 : : struct i40e_asq_cmd_details *cmd_details)
2518 : : {
2519 : : struct i40e_aq_desc desc;
2520 : : struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2521 : : (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2522 : : enum i40e_status_code status;
2523 : : u16 flags = 0;
2524 : :
2525 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2526 : : i40e_aqc_opc_set_vsi_promiscuous_modes);
2527 : :
2528 [ # # ]: 0 : if (enable)
2529 : : flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
2530 : :
2531 : 0 : cmd->promiscuous_flags = CPU_TO_LE16(flags);
2532 : 0 : cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
2533 : 0 : cmd->seid = CPU_TO_LE16(seid);
2534 : 0 : cmd->vlan_tag = CPU_TO_LE16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2535 : :
2536 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2537 : :
2538 : 0 : return status;
2539 : : }
2540 : :
2541 : : /**
2542 : : * i40e_aq_set_vsi_uc_promisc_on_vlan
2543 : : * @hw: pointer to the hw struct
2544 : : * @seid: vsi number
2545 : : * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2546 : : * @vid: The VLAN tag filter - capture any unicast packet with this VLAN tag
2547 : : * @cmd_details: pointer to command details structure or NULL
2548 : : **/
2549 : 0 : enum i40e_status_code i40e_aq_set_vsi_uc_promisc_on_vlan(struct i40e_hw *hw,
2550 : : u16 seid, bool enable, u16 vid,
2551 : : struct i40e_asq_cmd_details *cmd_details)
2552 : : {
2553 : : struct i40e_aq_desc desc;
2554 : : struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2555 : : (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2556 : : enum i40e_status_code status;
2557 : : u16 flags = 0;
2558 : :
2559 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2560 : : i40e_aqc_opc_set_vsi_promiscuous_modes);
2561 : :
2562 [ # # ]: 0 : if (enable) {
2563 : : flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
2564 : : if (i40e_hw_ver_ge(hw, 1, 5))
2565 : : flags |= I40E_AQC_SET_VSI_PROMISC_RX_ONLY;
2566 : : }
2567 : :
2568 : 0 : cmd->promiscuous_flags = CPU_TO_LE16(flags);
2569 [ # # ]: 0 : cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
2570 : : if (i40e_hw_ver_ge(hw, 1, 5))
2571 : 0 : cmd->valid_flags |=
2572 : : CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_RX_ONLY);
2573 : 0 : cmd->seid = CPU_TO_LE16(seid);
2574 : 0 : cmd->vlan_tag = CPU_TO_LE16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2575 : :
2576 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2577 : :
2578 : 0 : return status;
2579 : : }
2580 : :
2581 : : /**
2582 : : * i40e_aq_set_vsi_bc_promisc_on_vlan
2583 : : * @hw: pointer to the hw struct
2584 : : * @seid: vsi number
2585 : : * @enable: set broadcast promiscuous enable/disable for a given VLAN
2586 : : * @vid: The VLAN tag filter - capture any broadcast packet with this VLAN tag
2587 : : * @cmd_details: pointer to command details structure or NULL
2588 : : **/
2589 : 0 : enum i40e_status_code i40e_aq_set_vsi_bc_promisc_on_vlan(struct i40e_hw *hw,
2590 : : u16 seid, bool enable, u16 vid,
2591 : : struct i40e_asq_cmd_details *cmd_details)
2592 : : {
2593 : : struct i40e_aq_desc desc;
2594 : : struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2595 : : (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2596 : : enum i40e_status_code status;
2597 : : u16 flags = 0;
2598 : :
2599 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2600 : : i40e_aqc_opc_set_vsi_promiscuous_modes);
2601 : :
2602 [ # # ]: 0 : if (enable)
2603 : : flags |= I40E_AQC_SET_VSI_PROMISC_BROADCAST;
2604 : :
2605 : 0 : cmd->promiscuous_flags = CPU_TO_LE16(flags);
2606 : 0 : cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2607 : 0 : cmd->seid = CPU_TO_LE16(seid);
2608 : 0 : cmd->vlan_tag = CPU_TO_LE16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
2609 : :
2610 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2611 : :
2612 : 0 : return status;
2613 : : }
2614 : :
2615 : : /**
2616 : : * i40e_aq_set_vsi_broadcast
2617 : : * @hw: pointer to the hw struct
2618 : : * @seid: vsi number
2619 : : * @set_filter: true to set filter, false to clear filter
2620 : : * @cmd_details: pointer to command details structure or NULL
2621 : : *
2622 : : * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
2623 : : **/
2624 : 0 : enum i40e_status_code i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
2625 : : u16 seid, bool set_filter,
2626 : : struct i40e_asq_cmd_details *cmd_details)
2627 : : {
2628 : : struct i40e_aq_desc desc;
2629 : : struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2630 : : (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2631 : : enum i40e_status_code status;
2632 : :
2633 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2634 : : i40e_aqc_opc_set_vsi_promiscuous_modes);
2635 : :
2636 [ # # ]: 0 : if (set_filter)
2637 : : cmd->promiscuous_flags
2638 : 0 : |= CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2639 : : else
2640 : : cmd->promiscuous_flags
2641 : 0 : &= CPU_TO_LE16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2642 : :
2643 : 0 : cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
2644 : 0 : cmd->seid = CPU_TO_LE16(seid);
2645 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2646 : :
2647 : 0 : return status;
2648 : : }
2649 : :
2650 : : /**
2651 : : * i40e_aq_set_vsi_vlan_promisc - control the VLAN promiscuous setting
2652 : : * @hw: pointer to the hw struct
2653 : : * @seid: vsi number
2654 : : * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
2655 : : * @cmd_details: pointer to command details structure or NULL
2656 : : **/
2657 : 0 : enum i40e_status_code i40e_aq_set_vsi_vlan_promisc(struct i40e_hw *hw,
2658 : : u16 seid, bool enable,
2659 : : struct i40e_asq_cmd_details *cmd_details)
2660 : : {
2661 : : struct i40e_aq_desc desc;
2662 : : struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
2663 : : (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
2664 : : enum i40e_status_code status;
2665 : : u16 flags = 0;
2666 : :
2667 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2668 : : i40e_aqc_opc_set_vsi_promiscuous_modes);
2669 [ # # ]: 0 : if (enable)
2670 : : flags |= I40E_AQC_SET_VSI_PROMISC_VLAN;
2671 : :
2672 : 0 : cmd->promiscuous_flags = CPU_TO_LE16(flags);
2673 : 0 : cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_VLAN);
2674 : 0 : cmd->seid = CPU_TO_LE16(seid);
2675 : :
2676 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2677 : :
2678 : 0 : return status;
2679 : : }
2680 : :
2681 : : /**
2682 : : * i40e_aq_get_vsi_params - get VSI configuration info
2683 : : * @hw: pointer to the hw struct
2684 : : * @vsi_ctx: pointer to a vsi context struct
2685 : : * @cmd_details: pointer to command details structure or NULL
2686 : : **/
2687 : 0 : enum i40e_status_code i40e_aq_get_vsi_params(struct i40e_hw *hw,
2688 : : struct i40e_vsi_context *vsi_ctx,
2689 : : struct i40e_asq_cmd_details *cmd_details)
2690 : : {
2691 : : struct i40e_aq_desc desc;
2692 : : struct i40e_aqc_add_get_update_vsi *cmd =
2693 : : (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
2694 : : struct i40e_aqc_add_get_update_vsi_completion *resp =
2695 : : (struct i40e_aqc_add_get_update_vsi_completion *)
2696 : : &desc.params.raw;
2697 : : enum i40e_status_code status;
2698 : :
2699 : : UNREFERENCED_1PARAMETER(cmd_details);
2700 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2701 : : i40e_aqc_opc_get_vsi_parameters);
2702 : :
2703 : 0 : cmd->uplink_seid = CPU_TO_LE16(vsi_ctx->seid);
2704 : :
2705 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
2706 : :
2707 : 0 : status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2708 : : sizeof(vsi_ctx->info), NULL);
2709 : :
2710 [ # # ]: 0 : if (status != I40E_SUCCESS)
2711 : 0 : goto aq_get_vsi_params_exit;
2712 : :
2713 : 0 : vsi_ctx->seid = LE16_TO_CPU(resp->seid);
2714 : 0 : vsi_ctx->vsi_number = LE16_TO_CPU(resp->vsi_number);
2715 : 0 : vsi_ctx->vsis_allocated = LE16_TO_CPU(resp->vsi_used);
2716 : 0 : vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
2717 : :
2718 : 0 : aq_get_vsi_params_exit:
2719 : 0 : return status;
2720 : : }
2721 : :
2722 : : /**
2723 : : * i40e_aq_update_vsi_params
2724 : : * @hw: pointer to the hw struct
2725 : : * @vsi_ctx: pointer to a vsi context struct
2726 : : * @cmd_details: pointer to command details structure or NULL
2727 : : *
2728 : : * Update a VSI context.
2729 : : **/
2730 : 0 : enum i40e_status_code i40e_aq_update_vsi_params(struct i40e_hw *hw,
2731 : : struct i40e_vsi_context *vsi_ctx,
2732 : : struct i40e_asq_cmd_details *cmd_details)
2733 : : {
2734 : : struct i40e_aq_desc desc;
2735 : : struct i40e_aqc_add_get_update_vsi *cmd =
2736 : : (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
2737 : : struct i40e_aqc_add_get_update_vsi_completion *resp =
2738 : : (struct i40e_aqc_add_get_update_vsi_completion *)
2739 : : &desc.params.raw;
2740 : : enum i40e_status_code status;
2741 : :
2742 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2743 : : i40e_aqc_opc_update_vsi_parameters);
2744 : 0 : cmd->uplink_seid = CPU_TO_LE16(vsi_ctx->seid);
2745 : :
2746 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2747 : :
2748 : 0 : status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
2749 : : sizeof(vsi_ctx->info), cmd_details);
2750 : :
2751 : 0 : vsi_ctx->vsis_allocated = LE16_TO_CPU(resp->vsi_used);
2752 : 0 : vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
2753 : :
2754 : 0 : return status;
2755 : : }
2756 : :
2757 : : /**
2758 : : * i40e_aq_get_switch_config
2759 : : * @hw: pointer to the hardware structure
2760 : : * @buf: pointer to the result buffer
2761 : : * @buf_size: length of input buffer
2762 : : * @start_seid: seid to start for the report, 0 == beginning
2763 : : * @cmd_details: pointer to command details structure or NULL
2764 : : *
2765 : : * Fill the buf with switch configuration returned from AdminQ command
2766 : : **/
2767 : 0 : enum i40e_status_code i40e_aq_get_switch_config(struct i40e_hw *hw,
2768 : : struct i40e_aqc_get_switch_config_resp *buf,
2769 : : u16 buf_size, u16 *start_seid,
2770 : : struct i40e_asq_cmd_details *cmd_details)
2771 : : {
2772 : : struct i40e_aq_desc desc;
2773 : : struct i40e_aqc_switch_seid *scfg =
2774 : : (struct i40e_aqc_switch_seid *)&desc.params.raw;
2775 : : enum i40e_status_code status;
2776 : :
2777 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2778 : : i40e_aqc_opc_get_switch_config);
2779 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
2780 [ # # ]: 0 : if (buf_size > I40E_AQ_LARGE_BUF)
2781 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
2782 : 0 : scfg->seid = CPU_TO_LE16(*start_seid);
2783 : :
2784 : 0 : status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
2785 : 0 : *start_seid = LE16_TO_CPU(scfg->seid);
2786 : :
2787 : 0 : return status;
2788 : : }
2789 : :
2790 : : /**
2791 : : * i40e_aq_set_switch_config
2792 : : * @hw: pointer to the hardware structure
2793 : : * @flags: bit flag values to set
2794 : : * @mode: cloud filter mode
2795 : : * @valid_flags: which bit flags to set
2796 : : * @cmd_details: pointer to command details structure or NULL
2797 : : *
2798 : : * Set switch configuration bits
2799 : : **/
2800 : 0 : enum i40e_status_code i40e_aq_set_switch_config(struct i40e_hw *hw,
2801 : : u16 flags, u16 valid_flags, u8 mode,
2802 : : struct i40e_asq_cmd_details *cmd_details)
2803 : : {
2804 : : struct i40e_aq_desc desc;
2805 : : struct i40e_aqc_set_switch_config *scfg =
2806 : : (struct i40e_aqc_set_switch_config *)&desc.params.raw;
2807 : : enum i40e_status_code status;
2808 : :
2809 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
2810 : : i40e_aqc_opc_set_switch_config);
2811 : 0 : scfg->flags = CPU_TO_LE16(flags);
2812 : 0 : scfg->valid_flags = CPU_TO_LE16(valid_flags);
2813 : 0 : scfg->mode = mode;
2814 [ # # ]: 0 : if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
2815 : 0 : scfg->switch_tag = CPU_TO_LE16(hw->switch_tag);
2816 : 0 : scfg->first_tag = CPU_TO_LE16(hw->first_tag);
2817 : 0 : scfg->second_tag = CPU_TO_LE16(hw->second_tag);
2818 : : }
2819 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2820 : :
2821 : 0 : return status;
2822 : : }
2823 : :
2824 : : /**
2825 : : * i40e_aq_get_firmware_version
2826 : : * @hw: pointer to the hw struct
2827 : : * @fw_major_version: firmware major version
2828 : : * @fw_minor_version: firmware minor version
2829 : : * @fw_build: firmware build number
2830 : : * @api_major_version: major queue version
2831 : : * @api_minor_version: minor queue version
2832 : : * @cmd_details: pointer to command details structure or NULL
2833 : : *
2834 : : * Get the firmware version from the admin queue commands
2835 : : **/
2836 : 0 : enum i40e_status_code i40e_aq_get_firmware_version(struct i40e_hw *hw,
2837 : : u16 *fw_major_version, u16 *fw_minor_version,
2838 : : u32 *fw_build,
2839 : : u16 *api_major_version, u16 *api_minor_version,
2840 : : struct i40e_asq_cmd_details *cmd_details)
2841 : : {
2842 : : struct i40e_aq_desc desc;
2843 : : struct i40e_aqc_get_version *resp =
2844 : : (struct i40e_aqc_get_version *)&desc.params.raw;
2845 : : enum i40e_status_code status;
2846 : :
2847 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
2848 : :
2849 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2850 : :
2851 [ # # ]: 0 : if (status == I40E_SUCCESS) {
2852 [ # # ]: 0 : if (fw_major_version != NULL)
2853 : 0 : *fw_major_version = LE16_TO_CPU(resp->fw_major);
2854 [ # # ]: 0 : if (fw_minor_version != NULL)
2855 : 0 : *fw_minor_version = LE16_TO_CPU(resp->fw_minor);
2856 [ # # ]: 0 : if (fw_build != NULL)
2857 : 0 : *fw_build = LE32_TO_CPU(resp->fw_build);
2858 [ # # ]: 0 : if (api_major_version != NULL)
2859 : 0 : *api_major_version = LE16_TO_CPU(resp->api_major);
2860 [ # # ]: 0 : if (api_minor_version != NULL)
2861 : 0 : *api_minor_version = LE16_TO_CPU(resp->api_minor);
2862 : :
2863 : : /* A workaround to fix the API version in SW */
2864 [ # # ]: 0 : if (api_major_version && api_minor_version &&
2865 [ # # ]: 0 : fw_major_version && fw_minor_version &&
2866 [ # # # # ]: 0 : ((*api_major_version == 1) && (*api_minor_version == 1)) &&
2867 [ # # # # : 0 : (((*fw_major_version == 4) && (*fw_minor_version >= 2)) ||
# # ]
2868 : : (*fw_major_version > 4)))
2869 : 0 : *api_minor_version = 2;
2870 : : }
2871 : :
2872 : 0 : return status;
2873 : : }
2874 : :
2875 : : /**
2876 : : * i40e_aq_send_driver_version
2877 : : * @hw: pointer to the hw struct
2878 : : * @dv: driver's major, minor version
2879 : : * @cmd_details: pointer to command details structure or NULL
2880 : : *
2881 : : * Send the driver version to the firmware
2882 : : **/
2883 : 0 : enum i40e_status_code i40e_aq_send_driver_version(struct i40e_hw *hw,
2884 : : struct i40e_driver_version *dv,
2885 : : struct i40e_asq_cmd_details *cmd_details)
2886 : : {
2887 : : struct i40e_aq_desc desc;
2888 : : struct i40e_aqc_driver_version *cmd =
2889 : : (struct i40e_aqc_driver_version *)&desc.params.raw;
2890 : : enum i40e_status_code status;
2891 : : u16 len;
2892 : :
2893 [ # # ]: 0 : if (dv == NULL)
2894 : : return I40E_ERR_PARAM;
2895 : :
2896 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
2897 : :
2898 : 0 : desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
2899 : 0 : cmd->driver_major_ver = dv->major_version;
2900 : 0 : cmd->driver_minor_ver = dv->minor_version;
2901 : 0 : cmd->driver_build_ver = dv->build_version;
2902 : 0 : cmd->driver_subbuild_ver = dv->subbuild_version;
2903 : :
2904 : : len = 0;
2905 : 0 : while (len < sizeof(dv->driver_string) &&
2906 [ # # # # : 0 : (dv->driver_string[len] < 0x80) &&
# # ]
2907 : : dv->driver_string[len])
2908 : 0 : len++;
2909 : 0 : status = i40e_asq_send_command(hw, &desc, dv->driver_string,
2910 : : len, cmd_details);
2911 : :
2912 : 0 : return status;
2913 : : }
2914 : :
2915 : : /**
2916 : : * i40e_get_link_status - get status of the HW network link
2917 : : * @hw: pointer to the hw struct
2918 : : * @link_up: pointer to bool (true/false = linkup/linkdown)
2919 : : *
2920 : : * Variable link_up true if link is up, false if link is down.
2921 : : * The variable link_up is invalid if returned value of status != I40E_SUCCESS
2922 : : *
2923 : : * Side effect: LinkStatusEvent reporting becomes enabled
2924 : : **/
2925 : 0 : enum i40e_status_code i40e_get_link_status(struct i40e_hw *hw, bool *link_up)
2926 : : {
2927 : : enum i40e_status_code status = I40E_SUCCESS;
2928 : :
2929 [ # # ]: 0 : if (hw->phy.get_link_info) {
2930 : 0 : status = i40e_update_link_info(hw);
2931 : :
2932 [ # # ]: 0 : if (status != I40E_SUCCESS)
2933 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_LINK, "get link failed: status %d\n",
2934 : : status);
2935 : : }
2936 : :
2937 : 0 : *link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
2938 : :
2939 : 0 : return status;
2940 : : }
2941 : :
2942 : : /**
2943 : : * i40e_update_link_info - update status of the HW network link
2944 : : * @hw: pointer to the hw struct
2945 : : **/
2946 : 0 : enum i40e_status_code i40e_update_link_info(struct i40e_hw *hw)
2947 : : {
2948 : : struct i40e_aq_get_phy_abilities_resp abilities;
2949 : : enum i40e_status_code status = I40E_SUCCESS;
2950 : :
2951 : 0 : status = i40e_aq_get_link_info(hw, true, NULL, NULL);
2952 [ # # ]: 0 : if (status)
2953 : : return status;
2954 : :
2955 : : /* extra checking needed to ensure link info to user is timely */
2956 [ # # # # ]: 0 : if (((hw->phy.link_info.link_info & I40E_AQ_MEDIA_AVAILABLE) &&
2957 : 0 : ((hw->phy.link_info.link_info & I40E_AQ_LINK_UP) ||
2958 [ # # ]: 0 : !(hw->phy.link_info_old.link_info & I40E_AQ_LINK_UP))) ||
2959 [ # # ]: 0 : hw->mac.type == I40E_MAC_X722) {
2960 : 0 : status = i40e_aq_get_phy_capabilities(hw, false,
2961 : 0 : hw->mac.type ==
2962 : : I40E_MAC_X722,
2963 : : &abilities, NULL);
2964 [ # # ]: 0 : if (status)
2965 : : return status;
2966 : :
2967 [ # # ]: 0 : if (abilities.fec_cfg_curr_mod_ext_info &
2968 : : I40E_AQ_ENABLE_FEC_AUTO)
2969 : 0 : hw->phy.link_info.req_fec_info =
2970 : : (I40E_AQ_REQUEST_FEC_KR |
2971 : : I40E_AQ_REQUEST_FEC_RS);
2972 : : else
2973 : 0 : hw->phy.link_info.req_fec_info =
2974 : 0 : abilities.fec_cfg_curr_mod_ext_info &
2975 : : (I40E_AQ_REQUEST_FEC_KR |
2976 : : I40E_AQ_REQUEST_FEC_RS);
2977 : :
2978 [ # # ]: 0 : i40e_memcpy(hw->phy.link_info.module_type, &abilities.module_type,
2979 : : sizeof(hw->phy.link_info.module_type), I40E_NONDMA_TO_NONDMA);
2980 : : }
2981 : : return status;
2982 : : }
2983 : :
2984 : :
2985 : : /**
2986 : : * i40e_get_link_speed
2987 : : * @hw: pointer to the hw struct
2988 : : *
2989 : : * Returns the link speed of the adapter.
2990 : : **/
2991 : 0 : enum i40e_aq_link_speed i40e_get_link_speed(struct i40e_hw *hw)
2992 : : {
2993 : : enum i40e_aq_link_speed speed = I40E_LINK_SPEED_UNKNOWN;
2994 : : enum i40e_status_code status = I40E_SUCCESS;
2995 : :
2996 [ # # ]: 0 : if (hw->phy.get_link_info) {
2997 : 0 : status = i40e_aq_get_link_info(hw, true, NULL, NULL);
2998 : :
2999 [ # # ]: 0 : if (status != I40E_SUCCESS)
3000 : 0 : goto i40e_link_speed_exit;
3001 : : }
3002 : :
3003 : 0 : speed = hw->phy.link_info.link_speed;
3004 : :
3005 : 0 : i40e_link_speed_exit:
3006 : 0 : return speed;
3007 : : }
3008 : :
3009 : : /**
3010 : : * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
3011 : : * @hw: pointer to the hw struct
3012 : : * @uplink_seid: the MAC or other gizmo SEID
3013 : : * @downlink_seid: the VSI SEID
3014 : : * @enabled_tc: bitmap of TCs to be enabled
3015 : : * @default_port: true for default port VSI, false for control port
3016 : : * @veb_seid: pointer to where to put the resulting VEB SEID
3017 : : * @enable_stats: true to turn on VEB stats
3018 : : * @cmd_details: pointer to command details structure or NULL
3019 : : *
3020 : : * This asks the FW to add a VEB between the uplink and downlink
3021 : : * elements. If the uplink SEID is 0, this will be a floating VEB.
3022 : : **/
3023 : 0 : enum i40e_status_code i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
3024 : : u16 downlink_seid, u8 enabled_tc,
3025 : : bool default_port, u16 *veb_seid,
3026 : : bool enable_stats,
3027 : : struct i40e_asq_cmd_details *cmd_details)
3028 : : {
3029 : : struct i40e_aq_desc desc;
3030 : : struct i40e_aqc_add_veb *cmd =
3031 : : (struct i40e_aqc_add_veb *)&desc.params.raw;
3032 : : struct i40e_aqc_add_veb_completion *resp =
3033 : : (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
3034 : : enum i40e_status_code status;
3035 : : u16 veb_flags = 0;
3036 : :
3037 : : /* SEIDs need to either both be set or both be 0 for floating VEB */
3038 [ # # ]: 0 : if (!!uplink_seid != !!downlink_seid)
3039 : : return I40E_ERR_PARAM;
3040 : :
3041 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
3042 : :
3043 : 0 : cmd->uplink_seid = CPU_TO_LE16(uplink_seid);
3044 : 0 : cmd->downlink_seid = CPU_TO_LE16(downlink_seid);
3045 : 0 : cmd->enable_tcs = enabled_tc;
3046 [ # # ]: 0 : if (!uplink_seid)
3047 : : veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
3048 [ # # ]: 0 : if (default_port)
3049 : 0 : veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
3050 : : else
3051 : 0 : veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
3052 : :
3053 : : /* reverse logic here: set the bitflag to disable the stats */
3054 [ # # ]: 0 : if (!enable_stats)
3055 : 0 : veb_flags |= I40E_AQC_ADD_VEB_ENABLE_DISABLE_STATS;
3056 : :
3057 : 0 : cmd->veb_flags = CPU_TO_LE16(veb_flags);
3058 : :
3059 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3060 : :
3061 [ # # ]: 0 : if (!status && veb_seid)
3062 : 0 : *veb_seid = LE16_TO_CPU(resp->veb_seid);
3063 : :
3064 : : return status;
3065 : : }
3066 : :
3067 : : /**
3068 : : * i40e_aq_get_veb_parameters - Retrieve VEB parameters
3069 : : * @hw: pointer to the hw struct
3070 : : * @veb_seid: the SEID of the VEB to query
3071 : : * @switch_id: the uplink switch id
3072 : : * @floating: set to true if the VEB is floating
3073 : : * @statistic_index: index of the stats counter block for this VEB
3074 : : * @vebs_used: number of VEB's used by function
3075 : : * @vebs_free: total VEB's not reserved by any function
3076 : : * @cmd_details: pointer to command details structure or NULL
3077 : : *
3078 : : * This retrieves the parameters for a particular VEB, specified by
3079 : : * uplink_seid, and returns them to the caller.
3080 : : **/
3081 : 0 : enum i40e_status_code i40e_aq_get_veb_parameters(struct i40e_hw *hw,
3082 : : u16 veb_seid, u16 *switch_id,
3083 : : bool *floating, u16 *statistic_index,
3084 : : u16 *vebs_used, u16 *vebs_free,
3085 : : struct i40e_asq_cmd_details *cmd_details)
3086 : : {
3087 : : struct i40e_aq_desc desc;
3088 : : struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
3089 : : (struct i40e_aqc_get_veb_parameters_completion *)
3090 : : &desc.params.raw;
3091 : : enum i40e_status_code status;
3092 : :
3093 [ # # ]: 0 : if (veb_seid == 0)
3094 : : return I40E_ERR_PARAM;
3095 : :
3096 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
3097 : : i40e_aqc_opc_get_veb_parameters);
3098 : 0 : cmd_resp->seid = CPU_TO_LE16(veb_seid);
3099 : :
3100 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3101 [ # # ]: 0 : if (status)
3102 : 0 : goto get_veb_exit;
3103 : :
3104 [ # # ]: 0 : if (switch_id)
3105 : 0 : *switch_id = LE16_TO_CPU(cmd_resp->switch_id);
3106 [ # # ]: 0 : if (statistic_index)
3107 : 0 : *statistic_index = LE16_TO_CPU(cmd_resp->statistic_index);
3108 [ # # ]: 0 : if (vebs_used)
3109 : 0 : *vebs_used = LE16_TO_CPU(cmd_resp->vebs_used);
3110 [ # # ]: 0 : if (vebs_free)
3111 : 0 : *vebs_free = LE16_TO_CPU(cmd_resp->vebs_free);
3112 [ # # ]: 0 : if (floating) {
3113 : 0 : u16 flags = LE16_TO_CPU(cmd_resp->veb_flags);
3114 : :
3115 [ # # ]: 0 : if (flags & I40E_AQC_ADD_VEB_FLOATING)
3116 : 0 : *floating = true;
3117 : : else
3118 : 0 : *floating = false;
3119 : : }
3120 : :
3121 : 0 : get_veb_exit:
3122 : : return status;
3123 : : }
3124 : :
3125 : : /**
3126 : : * i40e_prepare_add_macvlan
3127 : : * @mv_list: list of macvlans to be added
3128 : : * @desc: pointer to AQ descriptor structure
3129 : : * @count: length of the list
3130 : : * @seid: VSI for the mac address
3131 : : *
3132 : : * Internal helper function that prepares the add macvlan request
3133 : : * and returns the buffer size.
3134 : : **/
3135 : : static u16
3136 : 0 : i40e_prepare_add_macvlan(struct i40e_aqc_add_macvlan_element_data *mv_list,
3137 : : struct i40e_aq_desc *desc, u16 count, u16 seid)
3138 : : {
3139 : : struct i40e_aqc_macvlan *cmd =
3140 : : (struct i40e_aqc_macvlan *)&desc->params.raw;
3141 : : u16 buf_size;
3142 : : int i;
3143 : :
3144 : 0 : buf_size = count * sizeof(*mv_list);
3145 : :
3146 : : /* prep the rest of the request */
3147 : 0 : i40e_fill_default_direct_cmd_desc(desc, i40e_aqc_opc_add_macvlan);
3148 : 0 : cmd->num_addresses = CPU_TO_LE16(count);
3149 : 0 : cmd->seid[0] = CPU_TO_LE16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
3150 : 0 : cmd->seid[1] = 0;
3151 : 0 : cmd->seid[2] = 0;
3152 : :
3153 [ # # ]: 0 : for (i = 0; i < count; i++)
3154 [ # # ]: 0 : if (I40E_IS_MULTICAST(mv_list[i].mac_addr))
3155 : 0 : mv_list[i].flags |=
3156 : : CPU_TO_LE16(I40E_AQC_MACVLAN_ADD_USE_SHARED_MAC);
3157 : :
3158 : 0 : desc->flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3159 [ # # ]: 0 : if (buf_size > I40E_AQ_LARGE_BUF)
3160 : 0 : desc->flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3161 : :
3162 : 0 : return buf_size;
3163 : : }
3164 : :
3165 : : /**
3166 : : * i40e_aq_add_macvlan
3167 : : * @hw: pointer to the hw struct
3168 : : * @seid: VSI for the mac address
3169 : : * @mv_list: list of macvlans to be added
3170 : : * @count: length of the list
3171 : : * @cmd_details: pointer to command details structure or NULL
3172 : : *
3173 : : * Add MAC/VLAN addresses to the HW filtering
3174 : : **/
3175 : : enum i40e_status_code
3176 : 0 : i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
3177 : : struct i40e_aqc_add_macvlan_element_data *mv_list,
3178 : : u16 count, struct i40e_asq_cmd_details *cmd_details)
3179 : : {
3180 : : struct i40e_aq_desc desc;
3181 : : enum i40e_status_code status;
3182 : : u16 buf_size;
3183 : :
3184 [ # # # # ]: 0 : if (count == 0 || !mv_list || !hw)
3185 : : return I40E_ERR_PARAM;
3186 : :
3187 : 0 : buf_size = i40e_prepare_add_macvlan(mv_list, &desc, count, seid);
3188 : :
3189 : 0 : status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
3190 : : cmd_details);
3191 : :
3192 : 0 : return status;
3193 : : }
3194 : :
3195 : : /**
3196 : : * i40e_aq_add_macvlan_v2
3197 : : * @hw: pointer to the hw struct
3198 : : * @seid: VSI for the mac address
3199 : : * @mv_list: list of macvlans to be added
3200 : : * @count: length of the list
3201 : : * @cmd_details: pointer to command details structure or NULL
3202 : : * @aq_status: pointer to Admin Queue status return value
3203 : : *
3204 : : * Add MAC/VLAN addresses to the HW filtering.
3205 : : * The _v2 version returns the last Admin Queue status in aq_status
3206 : : * to avoid race conditions in access to hw->aq.asq_last_status.
3207 : : * It also calls _v2 versions of asq_send_command functions to
3208 : : * get the aq_status on the stack.
3209 : : **/
3210 : : enum i40e_status_code
3211 : 0 : i40e_aq_add_macvlan_v2(struct i40e_hw *hw, u16 seid,
3212 : : struct i40e_aqc_add_macvlan_element_data *mv_list,
3213 : : u16 count, struct i40e_asq_cmd_details *cmd_details,
3214 : : enum i40e_admin_queue_err *aq_status)
3215 : : {
3216 : : struct i40e_aq_desc desc;
3217 : : enum i40e_status_code status;
3218 : : u16 buf_size;
3219 : :
3220 [ # # # # ]: 0 : if (count == 0 || !mv_list || !hw)
3221 : : return I40E_ERR_PARAM;
3222 : :
3223 : 0 : buf_size = i40e_prepare_add_macvlan(mv_list, &desc, count, seid);
3224 : :
3225 : 0 : status = i40e_asq_send_command_v2(hw, &desc, mv_list, buf_size,
3226 : : cmd_details, aq_status);
3227 : :
3228 : 0 : return status;
3229 : : }
3230 : :
3231 : : /**
3232 : : * i40e_aq_remove_macvlan
3233 : : * @hw: pointer to the hw struct
3234 : : * @seid: VSI for the mac address
3235 : : * @mv_list: list of macvlans to be removed
3236 : : * @count: length of the list
3237 : : * @cmd_details: pointer to command details structure or NULL
3238 : : *
3239 : : * Remove MAC/VLAN addresses from the HW filtering
3240 : : **/
3241 : 0 : enum i40e_status_code i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
3242 : : struct i40e_aqc_remove_macvlan_element_data *mv_list,
3243 : : u16 count, struct i40e_asq_cmd_details *cmd_details)
3244 : : {
3245 : : struct i40e_aq_desc desc;
3246 : : struct i40e_aqc_macvlan *cmd =
3247 : : (struct i40e_aqc_macvlan *)&desc.params.raw;
3248 : : enum i40e_status_code status;
3249 : : u16 buf_size;
3250 : :
3251 [ # # # # ]: 0 : if (count == 0 || !mv_list || !hw)
3252 : : return I40E_ERR_PARAM;
3253 : :
3254 : 0 : buf_size = count * sizeof(*mv_list);
3255 : :
3256 : : /* prep the rest of the request */
3257 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
3258 : 0 : cmd->num_addresses = CPU_TO_LE16(count);
3259 : 0 : cmd->seid[0] = CPU_TO_LE16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
3260 : 0 : cmd->seid[1] = 0;
3261 : 0 : cmd->seid[2] = 0;
3262 : :
3263 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3264 [ # # ]: 0 : if (buf_size > I40E_AQ_LARGE_BUF)
3265 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3266 : :
3267 : 0 : status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
3268 : : cmd_details);
3269 : :
3270 : 0 : return status;
3271 : : }
3272 : :
3273 : : /**
3274 : : * i40e_aq_remove_macvlan_v2
3275 : : * @hw: pointer to the hw struct
3276 : : * @seid: VSI for the mac address
3277 : : * @mv_list: list of macvlans to be removed
3278 : : * @count: length of the list
3279 : : * @cmd_details: pointer to command details structure or NULL
3280 : : * @aq_status: pointer to Admin Queue status return value
3281 : : *
3282 : : * Remove MAC/VLAN addresses from the HW filtering.
3283 : : * The _v2 version returns the last Admin Queue status in aq_status
3284 : : * to avoid race conditions in access to hw->aq.asq_last_status.
3285 : : * It also calls _v2 versions of asq_send_command functions to
3286 : : * get the aq_status on the stack.
3287 : : **/
3288 : : enum i40e_status_code
3289 : 0 : i40e_aq_remove_macvlan_v2(struct i40e_hw *hw, u16 seid,
3290 : : struct i40e_aqc_remove_macvlan_element_data *mv_list,
3291 : : u16 count, struct i40e_asq_cmd_details *cmd_details,
3292 : : enum i40e_admin_queue_err *aq_status)
3293 : : {
3294 : : struct i40e_aq_desc desc;
3295 : : struct i40e_aqc_macvlan *cmd =
3296 : : (struct i40e_aqc_macvlan *)&desc.params.raw;
3297 : : enum i40e_status_code status;
3298 : : u16 buf_size;
3299 : :
3300 [ # # # # ]: 0 : if (count == 0 || !mv_list || !hw)
3301 : : return I40E_ERR_PARAM;
3302 : :
3303 : 0 : buf_size = count * sizeof(*mv_list);
3304 : :
3305 : : /* prep the rest of the request */
3306 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
3307 : 0 : cmd->num_addresses = CPU_TO_LE16(count);
3308 : 0 : cmd->seid[0] = CPU_TO_LE16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
3309 : 0 : cmd->seid[1] = 0;
3310 : 0 : cmd->seid[2] = 0;
3311 : :
3312 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3313 [ # # ]: 0 : if (buf_size > I40E_AQ_LARGE_BUF)
3314 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3315 : :
3316 : 0 : status = i40e_asq_send_command_v2(hw, &desc, mv_list, buf_size,
3317 : : cmd_details, aq_status);
3318 : :
3319 : 0 : return status;
3320 : : }
3321 : :
3322 : : /**
3323 : : * i40e_mirrorrule_op - Internal helper function to add/delete mirror rule
3324 : : * @hw: pointer to the hw struct
3325 : : * @opcode: AQ opcode for add or delete mirror rule
3326 : : * @sw_seid: Switch SEID (to which rule refers)
3327 : : * @rule_type: Rule Type (ingress/egress/VLAN)
3328 : : * @id: Destination VSI SEID or Rule ID
3329 : : * @count: length of the list
3330 : : * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
3331 : : * @cmd_details: pointer to command details structure or NULL
3332 : : * @rule_id: Rule ID returned from FW
3333 : : * @rules_used: Number of rules used in internal switch
3334 : : * @rules_free: Number of rules free in internal switch
3335 : : *
3336 : : * Add/Delete a mirror rule to a specific switch. Mirror rules are supported for
3337 : : * VEBs/VEPA elements only
3338 : : **/
3339 : 0 : static enum i40e_status_code i40e_mirrorrule_op(struct i40e_hw *hw,
3340 : : u16 opcode, u16 sw_seid, u16 rule_type, u16 id,
3341 : : u16 count, __le16 *mr_list,
3342 : : struct i40e_asq_cmd_details *cmd_details,
3343 : : u16 *rule_id, u16 *rules_used, u16 *rules_free)
3344 : : {
3345 : : struct i40e_aq_desc desc;
3346 : : struct i40e_aqc_add_delete_mirror_rule *cmd =
3347 : : (struct i40e_aqc_add_delete_mirror_rule *)&desc.params.raw;
3348 : : struct i40e_aqc_add_delete_mirror_rule_completion *resp =
3349 : : (struct i40e_aqc_add_delete_mirror_rule_completion *)&desc.params.raw;
3350 : : enum i40e_status_code status;
3351 : : u16 buf_size;
3352 : :
3353 : 0 : buf_size = count * sizeof(*mr_list);
3354 : :
3355 : : /* prep the rest of the request */
3356 : 0 : i40e_fill_default_direct_cmd_desc(&desc, opcode);
3357 : 0 : cmd->seid = CPU_TO_LE16(sw_seid);
3358 : 0 : cmd->rule_type = CPU_TO_LE16(rule_type &
3359 : : I40E_AQC_MIRROR_RULE_TYPE_MASK);
3360 : 0 : cmd->num_entries = CPU_TO_LE16(count);
3361 : : /* Dest VSI for add, rule_id for delete */
3362 : 0 : cmd->destination = CPU_TO_LE16(id);
3363 [ # # ]: 0 : if (mr_list) {
3364 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF |
3365 : : I40E_AQ_FLAG_RD));
3366 [ # # ]: 0 : if (buf_size > I40E_AQ_LARGE_BUF)
3367 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3368 : : }
3369 : :
3370 : 0 : status = i40e_asq_send_command(hw, &desc, mr_list, buf_size,
3371 : : cmd_details);
3372 [ # # ]: 0 : if (status == I40E_SUCCESS ||
3373 [ # # ]: 0 : hw->aq.asq_last_status == I40E_AQ_RC_ENOSPC) {
3374 [ # # ]: 0 : if (rule_id)
3375 : 0 : *rule_id = LE16_TO_CPU(resp->rule_id);
3376 [ # # ]: 0 : if (rules_used)
3377 : 0 : *rules_used = LE16_TO_CPU(resp->mirror_rules_used);
3378 [ # # ]: 0 : if (rules_free)
3379 : 0 : *rules_free = LE16_TO_CPU(resp->mirror_rules_free);
3380 : : }
3381 : 0 : return status;
3382 : : }
3383 : :
3384 : : /**
3385 : : * i40e_aq_add_mirrorrule - add a mirror rule
3386 : : * @hw: pointer to the hw struct
3387 : : * @sw_seid: Switch SEID (to which rule refers)
3388 : : * @rule_type: Rule Type (ingress/egress/VLAN)
3389 : : * @dest_vsi: SEID of VSI to which packets will be mirrored
3390 : : * @count: length of the list
3391 : : * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
3392 : : * @cmd_details: pointer to command details structure or NULL
3393 : : * @rule_id: Rule ID returned from FW
3394 : : * @rules_used: Number of rules used in internal switch
3395 : : * @rules_free: Number of rules free in internal switch
3396 : : *
3397 : : * Add mirror rule. Mirror rules are supported for VEBs or VEPA elements only
3398 : : **/
3399 : 0 : enum i40e_status_code i40e_aq_add_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
3400 : : u16 rule_type, u16 dest_vsi, u16 count, __le16 *mr_list,
3401 : : struct i40e_asq_cmd_details *cmd_details,
3402 : : u16 *rule_id, u16 *rules_used, u16 *rules_free)
3403 : : {
3404 [ # # ]: 0 : if (!(rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS ||
3405 : : rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS)) {
3406 [ # # ]: 0 : if (count == 0 || !mr_list)
3407 : : return I40E_ERR_PARAM;
3408 : : }
3409 : :
3410 : 0 : return i40e_mirrorrule_op(hw, i40e_aqc_opc_add_mirror_rule, sw_seid,
3411 : : rule_type, dest_vsi, count, mr_list,
3412 : : cmd_details, rule_id, rules_used, rules_free);
3413 : : }
3414 : :
3415 : : /**
3416 : : * i40e_aq_delete_mirrorrule - delete a mirror rule
3417 : : * @hw: pointer to the hw struct
3418 : : * @sw_seid: Switch SEID (to which rule refers)
3419 : : * @rule_type: Rule Type (ingress/egress/VLAN)
3420 : : * @count: length of the list
3421 : : * @rule_id: Rule ID that is returned in the receive desc as part of
3422 : : * add_mirrorrule.
3423 : : * @mr_list: list of mirrored VLAN IDs to be removed
3424 : : * @cmd_details: pointer to command details structure or NULL
3425 : : * @rules_used: Number of rules used in internal switch
3426 : : * @rules_free: Number of rules free in internal switch
3427 : : *
3428 : : * Delete a mirror rule. Mirror rules are supported for VEBs/VEPA elements only
3429 : : **/
3430 : 0 : enum i40e_status_code i40e_aq_delete_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
3431 : : u16 rule_type, u16 rule_id, u16 count, __le16 *mr_list,
3432 : : struct i40e_asq_cmd_details *cmd_details,
3433 : : u16 *rules_used, u16 *rules_free)
3434 : : {
3435 : : /* Rule ID has to be valid except rule_type: INGRESS VLAN mirroring */
3436 [ # # ]: 0 : if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
3437 : : /* count and mr_list shall be valid for rule_type INGRESS VLAN
3438 : : * mirroring. For other rule_type, count and rule_type should
3439 : : * not matter.
3440 : : */
3441 [ # # ]: 0 : if (count == 0 || !mr_list)
3442 : : return I40E_ERR_PARAM;
3443 : : }
3444 : :
3445 : 0 : return i40e_mirrorrule_op(hw, i40e_aqc_opc_delete_mirror_rule, sw_seid,
3446 : : rule_type, rule_id, count, mr_list,
3447 : : cmd_details, NULL, rules_used, rules_free);
3448 : : }
3449 : :
3450 : : /**
3451 : : * i40e_aq_add_vlan - Add VLAN ids to the HW filtering
3452 : : * @hw: pointer to the hw struct
3453 : : * @seid: VSI for the vlan filters
3454 : : * @v_list: list of vlan filters to be added
3455 : : * @count: length of the list
3456 : : * @cmd_details: pointer to command details structure or NULL
3457 : : **/
3458 : 0 : enum i40e_status_code i40e_aq_add_vlan(struct i40e_hw *hw, u16 seid,
3459 : : struct i40e_aqc_add_remove_vlan_element_data *v_list,
3460 : : u8 count, struct i40e_asq_cmd_details *cmd_details)
3461 : : {
3462 : : struct i40e_aq_desc desc;
3463 : : struct i40e_aqc_macvlan *cmd =
3464 : : (struct i40e_aqc_macvlan *)&desc.params.raw;
3465 : : enum i40e_status_code status;
3466 : : u16 buf_size;
3467 : :
3468 [ # # # # ]: 0 : if (count == 0 || !v_list || !hw)
3469 : : return I40E_ERR_PARAM;
3470 : :
3471 : 0 : buf_size = count * sizeof(*v_list);
3472 : :
3473 : : /* prep the rest of the request */
3474 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_vlan);
3475 : 0 : cmd->num_addresses = CPU_TO_LE16(count);
3476 : 0 : cmd->seid[0] = CPU_TO_LE16(seid | I40E_AQC_MACVLAN_CMD_SEID_VALID);
3477 : 0 : cmd->seid[1] = 0;
3478 : 0 : cmd->seid[2] = 0;
3479 : :
3480 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3481 [ # # ]: 0 : if (buf_size > I40E_AQ_LARGE_BUF)
3482 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3483 : :
3484 : 0 : status = i40e_asq_send_command(hw, &desc, v_list, buf_size,
3485 : : cmd_details);
3486 : :
3487 : 0 : return status;
3488 : : }
3489 : :
3490 : : /**
3491 : : * i40e_aq_remove_vlan - Remove VLANs from the HW filtering
3492 : : * @hw: pointer to the hw struct
3493 : : * @seid: VSI for the vlan filters
3494 : : * @v_list: list of macvlans to be removed
3495 : : * @count: length of the list
3496 : : * @cmd_details: pointer to command details structure or NULL
3497 : : **/
3498 : 0 : enum i40e_status_code i40e_aq_remove_vlan(struct i40e_hw *hw, u16 seid,
3499 : : struct i40e_aqc_add_remove_vlan_element_data *v_list,
3500 : : u8 count, struct i40e_asq_cmd_details *cmd_details)
3501 : : {
3502 : : struct i40e_aq_desc desc;
3503 : : struct i40e_aqc_macvlan *cmd =
3504 : : (struct i40e_aqc_macvlan *)&desc.params.raw;
3505 : : enum i40e_status_code status;
3506 : : u16 buf_size;
3507 : :
3508 [ # # # # ]: 0 : if (count == 0 || !v_list || !hw)
3509 : : return I40E_ERR_PARAM;
3510 : :
3511 : 0 : buf_size = count * sizeof(*v_list);
3512 : :
3513 : : /* prep the rest of the request */
3514 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_vlan);
3515 : 0 : cmd->num_addresses = CPU_TO_LE16(count);
3516 : 0 : cmd->seid[0] = CPU_TO_LE16(seid | I40E_AQC_MACVLAN_CMD_SEID_VALID);
3517 : 0 : cmd->seid[1] = 0;
3518 : 0 : cmd->seid[2] = 0;
3519 : :
3520 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3521 [ # # ]: 0 : if (buf_size > I40E_AQ_LARGE_BUF)
3522 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3523 : :
3524 : 0 : status = i40e_asq_send_command(hw, &desc, v_list, buf_size,
3525 : : cmd_details);
3526 : :
3527 : 0 : return status;
3528 : : }
3529 : :
3530 : : /**
3531 : : * i40e_aq_send_msg_to_vf
3532 : : * @hw: pointer to the hardware structure
3533 : : * @vfid: vf id to send msg
3534 : : * @v_opcode: opcodes for VF-PF communication
3535 : : * @v_retval: return error code
3536 : : * @msg: pointer to the msg buffer
3537 : : * @msglen: msg length
3538 : : * @cmd_details: pointer to command details
3539 : : *
3540 : : * send msg to vf
3541 : : **/
3542 : 0 : enum i40e_status_code i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
3543 : : u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
3544 : : struct i40e_asq_cmd_details *cmd_details)
3545 : : {
3546 : : struct i40e_aq_desc desc;
3547 : : struct i40e_aqc_pf_vf_message *cmd =
3548 : : (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
3549 : : enum i40e_status_code status;
3550 : :
3551 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
3552 : 0 : cmd->id = CPU_TO_LE32(vfid);
3553 : 0 : desc.cookie_high = CPU_TO_LE32(v_opcode);
3554 : 0 : desc.cookie_low = CPU_TO_LE32(v_retval);
3555 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_SI);
3556 [ # # ]: 0 : if (msglen) {
3557 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF |
3558 : : I40E_AQ_FLAG_RD));
3559 [ # # ]: 0 : if (msglen > I40E_AQ_LARGE_BUF)
3560 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3561 : 0 : desc.datalen = CPU_TO_LE16(msglen);
3562 : : }
3563 : 0 : status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
3564 : :
3565 : 0 : return status;
3566 : : }
3567 : :
3568 : : /**
3569 : : * i40e_aq_debug_read_register
3570 : : * @hw: pointer to the hw struct
3571 : : * @reg_addr: register address
3572 : : * @reg_val: register value
3573 : : * @cmd_details: pointer to command details structure or NULL
3574 : : *
3575 : : * Read the register using the admin queue commands
3576 : : **/
3577 : 0 : enum i40e_status_code i40e_aq_debug_read_register(struct i40e_hw *hw,
3578 : : u32 reg_addr, u64 *reg_val,
3579 : : struct i40e_asq_cmd_details *cmd_details)
3580 : : {
3581 : : struct i40e_aq_desc desc;
3582 : : struct i40e_aqc_debug_reg_read_write *cmd_resp =
3583 : : (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
3584 : : enum i40e_status_code status;
3585 : :
3586 [ # # ]: 0 : if (reg_val == NULL)
3587 : : return I40E_ERR_PARAM;
3588 : :
3589 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
3590 : :
3591 : 0 : cmd_resp->address = CPU_TO_LE32(reg_addr);
3592 : :
3593 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3594 : :
3595 [ # # ]: 0 : if (status == I40E_SUCCESS) {
3596 : 0 : *reg_val = ((u64)LE32_TO_CPU(cmd_resp->value_high) << 32) |
3597 : 0 : (u64)LE32_TO_CPU(cmd_resp->value_low);
3598 : : }
3599 : :
3600 : : return status;
3601 : : }
3602 : :
3603 : : /**
3604 : : * i40e_aq_debug_write_register
3605 : : * @hw: pointer to the hw struct
3606 : : * @reg_addr: register address
3607 : : * @reg_val: register value
3608 : : * @cmd_details: pointer to command details structure or NULL
3609 : : *
3610 : : * Write to a register using the admin queue commands
3611 : : **/
3612 : 0 : enum i40e_status_code i40e_aq_debug_write_register(struct i40e_hw *hw,
3613 : : u32 reg_addr, u64 reg_val,
3614 : : struct i40e_asq_cmd_details *cmd_details)
3615 : : {
3616 : : struct i40e_aq_desc desc;
3617 : : struct i40e_aqc_debug_reg_read_write *cmd =
3618 : : (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
3619 : : enum i40e_status_code status;
3620 : :
3621 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
3622 : :
3623 : 0 : cmd->address = CPU_TO_LE32(reg_addr);
3624 : 0 : cmd->value_high = CPU_TO_LE32((u32)(reg_val >> 32));
3625 : 0 : cmd->value_low = CPU_TO_LE32((u32)(reg_val & 0xFFFFFFFF));
3626 : :
3627 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3628 : :
3629 : 0 : return status;
3630 : : }
3631 : :
3632 : : /**
3633 : : * i40e_aq_request_resource
3634 : : * @hw: pointer to the hw struct
3635 : : * @resource: resource id
3636 : : * @access: access type
3637 : : * @sdp_number: resource number
3638 : : * @timeout: the maximum time in ms that the driver may hold the resource
3639 : : * @cmd_details: pointer to command details structure or NULL
3640 : : *
3641 : : * requests common resource using the admin queue commands
3642 : : **/
3643 : 0 : enum i40e_status_code i40e_aq_request_resource(struct i40e_hw *hw,
3644 : : enum i40e_aq_resources_ids resource,
3645 : : enum i40e_aq_resource_access_type access,
3646 : : u8 sdp_number, u64 *timeout,
3647 : : struct i40e_asq_cmd_details *cmd_details)
3648 : : {
3649 : : struct i40e_aq_desc desc;
3650 : : struct i40e_aqc_request_resource *cmd_resp =
3651 : : (struct i40e_aqc_request_resource *)&desc.params.raw;
3652 : : enum i40e_status_code status;
3653 : :
3654 : 0 : DEBUGFUNC("i40e_aq_request_resource");
3655 : :
3656 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
3657 : :
3658 : 0 : cmd_resp->resource_id = CPU_TO_LE16(resource);
3659 : 0 : cmd_resp->access_type = CPU_TO_LE16(access);
3660 : 0 : cmd_resp->resource_number = CPU_TO_LE32(sdp_number);
3661 : :
3662 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3663 : : /* The completion specifies the maximum time in ms that the driver
3664 : : * may hold the resource in the Timeout field.
3665 : : * If the resource is held by someone else, the command completes with
3666 : : * busy return value and the timeout field indicates the maximum time
3667 : : * the current owner of the resource has to free it.
3668 : : */
3669 [ # # # # ]: 0 : if (status == I40E_SUCCESS || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
3670 : 0 : *timeout = LE32_TO_CPU(cmd_resp->timeout);
3671 : :
3672 : 0 : return status;
3673 : : }
3674 : :
3675 : : /**
3676 : : * i40e_aq_release_resource
3677 : : * @hw: pointer to the hw struct
3678 : : * @resource: resource id
3679 : : * @sdp_number: resource number
3680 : : * @cmd_details: pointer to command details structure or NULL
3681 : : *
3682 : : * release common resource using the admin queue commands
3683 : : **/
3684 : 0 : enum i40e_status_code i40e_aq_release_resource(struct i40e_hw *hw,
3685 : : enum i40e_aq_resources_ids resource,
3686 : : u8 sdp_number,
3687 : : struct i40e_asq_cmd_details *cmd_details)
3688 : : {
3689 : : struct i40e_aq_desc desc;
3690 : : struct i40e_aqc_request_resource *cmd =
3691 : : (struct i40e_aqc_request_resource *)&desc.params.raw;
3692 : : enum i40e_status_code status;
3693 : :
3694 : 0 : DEBUGFUNC("i40e_aq_release_resource");
3695 : :
3696 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
3697 : :
3698 : 0 : cmd->resource_id = CPU_TO_LE16(resource);
3699 : 0 : cmd->resource_number = CPU_TO_LE32(sdp_number);
3700 : :
3701 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3702 : :
3703 : 0 : return status;
3704 : : }
3705 : :
3706 : : /**
3707 : : * i40e_aq_read_nvm
3708 : : * @hw: pointer to the hw struct
3709 : : * @module_pointer: module pointer location in words from the NVM beginning
3710 : : * @offset: byte offset from the module beginning
3711 : : * @length: length of the section to be read (in bytes from the offset)
3712 : : * @data: command buffer (size [bytes] = length)
3713 : : * @last_command: tells if this is the last command in a series
3714 : : * @cmd_details: pointer to command details structure or NULL
3715 : : *
3716 : : * Read the NVM using the admin queue commands
3717 : : **/
3718 : 0 : enum i40e_status_code i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
3719 : : u32 offset, u16 length, void *data,
3720 : : bool last_command,
3721 : : struct i40e_asq_cmd_details *cmd_details)
3722 : : {
3723 : : struct i40e_aq_desc desc;
3724 : : struct i40e_aqc_nvm_update *cmd =
3725 : : (struct i40e_aqc_nvm_update *)&desc.params.raw;
3726 : : enum i40e_status_code status;
3727 : :
3728 : 0 : DEBUGFUNC("i40e_aq_read_nvm");
3729 : :
3730 : : /* In offset the highest byte must be zeroed. */
3731 [ # # ]: 0 : if (offset & 0xFF000000) {
3732 : : status = I40E_ERR_PARAM;
3733 : 0 : goto i40e_aq_read_nvm_exit;
3734 : : }
3735 : :
3736 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
3737 : :
3738 : : /* If this is the last command in a series, set the proper flag. */
3739 [ # # ]: 0 : if (last_command)
3740 : 0 : cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3741 : 0 : cmd->module_pointer = module_pointer;
3742 : 0 : cmd->offset = CPU_TO_LE32(offset);
3743 : 0 : cmd->length = CPU_TO_LE16(length);
3744 : :
3745 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
3746 [ # # ]: 0 : if (length > I40E_AQ_LARGE_BUF)
3747 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3748 : :
3749 : 0 : status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3750 : :
3751 : 0 : i40e_aq_read_nvm_exit:
3752 : 0 : return status;
3753 : : }
3754 : :
3755 : : /**
3756 : : * i40e_aq_read_nvm_config - read an nvm config block
3757 : : * @hw: pointer to the hw struct
3758 : : * @cmd_flags: NVM access admin command bits
3759 : : * @field_id: field or feature id
3760 : : * @data: buffer for result
3761 : : * @buf_size: buffer size
3762 : : * @element_count: pointer to count of elements read by FW
3763 : : * @cmd_details: pointer to command details structure or NULL
3764 : : **/
3765 : 0 : enum i40e_status_code i40e_aq_read_nvm_config(struct i40e_hw *hw,
3766 : : u8 cmd_flags, u32 field_id, void *data,
3767 : : u16 buf_size, u16 *element_count,
3768 : : struct i40e_asq_cmd_details *cmd_details)
3769 : : {
3770 : : struct i40e_aq_desc desc;
3771 : : struct i40e_aqc_nvm_config_read *cmd =
3772 : : (struct i40e_aqc_nvm_config_read *)&desc.params.raw;
3773 : : enum i40e_status_code status;
3774 : :
3775 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_config_read);
3776 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF));
3777 [ # # ]: 0 : if (buf_size > I40E_AQ_LARGE_BUF)
3778 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3779 : :
3780 : 0 : cmd->cmd_flags = CPU_TO_LE16(cmd_flags);
3781 : 0 : cmd->element_id = CPU_TO_LE16((u16)(0xffff & field_id));
3782 [ # # ]: 0 : if (cmd_flags & I40E_AQ_ANVM_FEATURE_OR_IMMEDIATE_MASK)
3783 : 0 : cmd->element_id_msw = CPU_TO_LE16((u16)(field_id >> 16));
3784 : : else
3785 : 0 : cmd->element_id_msw = 0;
3786 : :
3787 : 0 : status = i40e_asq_send_command(hw, &desc, data, buf_size, cmd_details);
3788 : :
3789 [ # # ]: 0 : if (!status && element_count)
3790 : 0 : *element_count = LE16_TO_CPU(cmd->element_count);
3791 : :
3792 : 0 : return status;
3793 : : }
3794 : :
3795 : : /**
3796 : : * i40e_aq_write_nvm_config - write an nvm config block
3797 : : * @hw: pointer to the hw struct
3798 : : * @cmd_flags: NVM access admin command bits
3799 : : * @data: buffer for result
3800 : : * @buf_size: buffer size
3801 : : * @element_count: count of elements to be written
3802 : : * @cmd_details: pointer to command details structure or NULL
3803 : : **/
3804 : 0 : enum i40e_status_code i40e_aq_write_nvm_config(struct i40e_hw *hw,
3805 : : u8 cmd_flags, void *data, u16 buf_size,
3806 : : u16 element_count,
3807 : : struct i40e_asq_cmd_details *cmd_details)
3808 : : {
3809 : : struct i40e_aq_desc desc;
3810 : : struct i40e_aqc_nvm_config_write *cmd =
3811 : : (struct i40e_aqc_nvm_config_write *)&desc.params.raw;
3812 : : enum i40e_status_code status;
3813 : :
3814 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_config_write);
3815 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3816 [ # # ]: 0 : if (buf_size > I40E_AQ_LARGE_BUF)
3817 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3818 : :
3819 : 0 : cmd->element_count = CPU_TO_LE16(element_count);
3820 : 0 : cmd->cmd_flags = CPU_TO_LE16(cmd_flags);
3821 : 0 : status = i40e_asq_send_command(hw, &desc, data, buf_size, cmd_details);
3822 : :
3823 : 0 : return status;
3824 : : }
3825 : :
3826 : : /**
3827 : : * i40e_aq_nvm_update_in_process
3828 : : * @hw: pointer to the hw struct
3829 : : * @update_flow_state: True indicates that update flow starts, false that ends
3830 : : * @cmd_details: pointer to command details structure or NULL
3831 : : *
3832 : : * Indicate NVM update in process.
3833 : : **/
3834 : : enum i40e_status_code
3835 : 0 : i40e_aq_nvm_update_in_process(struct i40e_hw *hw,
3836 : : bool update_flow_state,
3837 : : struct i40e_asq_cmd_details *cmd_details)
3838 : : {
3839 : : struct i40e_aq_desc desc;
3840 : : struct i40e_aqc_nvm_update_in_process *cmd =
3841 : : (struct i40e_aqc_nvm_update_in_process *)&desc.params.raw;
3842 : : enum i40e_status_code status;
3843 : :
3844 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
3845 : : i40e_aqc_opc_nvm_update_in_process);
3846 : :
3847 : 0 : cmd->command = I40E_AQ_UPDATE_FLOW_END;
3848 : :
3849 [ # # ]: 0 : if (update_flow_state)
3850 : 0 : cmd->command |= I40E_AQ_UPDATE_FLOW_START;
3851 : :
3852 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3853 : :
3854 : 0 : return status;
3855 : : }
3856 : :
3857 : : /**
3858 : : * i40e_aq_min_rollback_rev_update - triggers an ow after update
3859 : : * @hw: pointer to the hw struct
3860 : : * @mode: opt-in mode, 1b for single module update, 0b for bulk update
3861 : : * @module: module to be updated. Ignored if mode is 0b
3862 : : * @min_rrev: value of the new minimal version. Ignored if mode is 0b
3863 : : * @cmd_details: pointer to command details structure or NULL
3864 : : **/
3865 : : enum i40e_status_code
3866 : 0 : i40e_aq_min_rollback_rev_update(struct i40e_hw *hw, u8 mode, u8 module,
3867 : : u32 min_rrev,
3868 : : struct i40e_asq_cmd_details *cmd_details)
3869 : : {
3870 : : struct i40e_aq_desc desc;
3871 : : struct i40e_aqc_rollback_revision_update *cmd =
3872 : : (struct i40e_aqc_rollback_revision_update *)&desc.params.raw;
3873 : : enum i40e_status_code status;
3874 : :
3875 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
3876 : : i40e_aqc_opc_rollback_revision_update);
3877 : 0 : cmd->optin_mode = mode;
3878 : 0 : cmd->module_selected = module;
3879 : 0 : cmd->min_rrev = min_rrev;
3880 : :
3881 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3882 : :
3883 : 0 : return status;
3884 : : }
3885 : :
3886 : : /**
3887 : : * i40e_aq_oem_post_update - triggers an OEM specific flow after update
3888 : : * @hw: pointer to the hw struct
3889 : : * @buff: buffer for result
3890 : : * @buff_size: buffer size
3891 : : * @cmd_details: pointer to command details structure or NULL
3892 : : **/
3893 : 0 : enum i40e_status_code i40e_aq_oem_post_update(struct i40e_hw *hw,
3894 : : void *buff, u16 buff_size,
3895 : : struct i40e_asq_cmd_details *cmd_details)
3896 : : {
3897 : : struct i40e_aq_desc desc;
3898 : : enum i40e_status_code status;
3899 : :
3900 : : UNREFERENCED_2PARAMETER(buff, buff_size);
3901 : :
3902 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_oem_post_update);
3903 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3904 [ # # # # ]: 0 : if (status && LE16_TO_CPU(desc.retval) == I40E_AQ_RC_ESRCH)
3905 : : status = I40E_ERR_NOT_IMPLEMENTED;
3906 : :
3907 : 0 : return status;
3908 : : }
3909 : :
3910 : : /**
3911 : : * i40e_aq_erase_nvm
3912 : : * @hw: pointer to the hw struct
3913 : : * @module_pointer: module pointer location in words from the NVM beginning
3914 : : * @offset: offset in the module (expressed in 4 KB from module's beginning)
3915 : : * @length: length of the section to be erased (expressed in 4 KB)
3916 : : * @last_command: tells if this is the last command in a series
3917 : : * @cmd_details: pointer to command details structure or NULL
3918 : : *
3919 : : * Erase the NVM sector using the admin queue commands
3920 : : **/
3921 : 0 : enum i40e_status_code i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
3922 : : u32 offset, u16 length, bool last_command,
3923 : : struct i40e_asq_cmd_details *cmd_details)
3924 : : {
3925 : : struct i40e_aq_desc desc;
3926 : : struct i40e_aqc_nvm_update *cmd =
3927 : : (struct i40e_aqc_nvm_update *)&desc.params.raw;
3928 : : enum i40e_status_code status;
3929 : :
3930 : 0 : DEBUGFUNC("i40e_aq_erase_nvm");
3931 : :
3932 : : /* In offset the highest byte must be zeroed. */
3933 [ # # ]: 0 : if (offset & 0xFF000000) {
3934 : : status = I40E_ERR_PARAM;
3935 : 0 : goto i40e_aq_erase_nvm_exit;
3936 : : }
3937 : :
3938 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
3939 : :
3940 : : /* If this is the last command in a series, set the proper flag. */
3941 [ # # ]: 0 : if (last_command)
3942 : 0 : cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3943 : 0 : cmd->module_pointer = module_pointer;
3944 : 0 : cmd->offset = CPU_TO_LE32(offset);
3945 : 0 : cmd->length = CPU_TO_LE16(length);
3946 : :
3947 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3948 : :
3949 : 0 : i40e_aq_erase_nvm_exit:
3950 : 0 : return status;
3951 : : }
3952 : :
3953 : : /**
3954 : : * i40e_parse_discover_capabilities
3955 : : * @hw: pointer to the hw struct
3956 : : * @buff: pointer to a buffer containing device/function capability records
3957 : : * @cap_count: number of capability records in the list
3958 : : * @list_type_opc: type of capabilities list to parse
3959 : : *
3960 : : * Parse the device/function capabilities list.
3961 : : **/
3962 : 0 : STATIC void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
3963 : : u32 cap_count,
3964 : : enum i40e_admin_queue_opc list_type_opc)
3965 : : {
3966 : : struct i40e_aqc_list_capabilities_element_resp *cap;
3967 : : u32 valid_functions, num_functions;
3968 : : u32 number, logical_id, phys_id;
3969 : : struct i40e_hw_capabilities *p;
3970 : : enum i40e_status_code status;
3971 : : u16 id, ocp_cfg_word0;
3972 : : u8 major_rev;
3973 : : u32 i = 0;
3974 : :
3975 : : cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
3976 : :
3977 [ # # ]: 0 : if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
3978 : 0 : p = (struct i40e_hw_capabilities *)&hw->dev_caps;
3979 [ # # ]: 0 : else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
3980 : 0 : p = (struct i40e_hw_capabilities *)&hw->func_caps;
3981 : : else
3982 : 0 : return;
3983 : :
3984 [ # # ]: 0 : for (i = 0; i < cap_count; i++, cap++) {
3985 : 0 : id = LE16_TO_CPU(cap->id);
3986 : 0 : number = LE32_TO_CPU(cap->number);
3987 : 0 : logical_id = LE32_TO_CPU(cap->logical_id);
3988 : 0 : phys_id = LE32_TO_CPU(cap->phys_id);
3989 : 0 : major_rev = cap->major_rev;
3990 : :
3991 [ # # # # : 0 : switch (id) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
3992 : 0 : case I40E_AQ_CAP_ID_SWITCH_MODE:
3993 : 0 : p->switch_mode = number;
3994 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
3995 : : "HW Capability: Switch mode = %d\n",
3996 : : p->switch_mode);
3997 : : break;
3998 : 0 : case I40E_AQ_CAP_ID_MNG_MODE:
3999 : 0 : p->management_mode = number;
4000 [ # # ]: 0 : if (major_rev > 1) {
4001 : 0 : p->mng_protocols_over_mctp = logical_id;
4002 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4003 : : "HW Capability: Protocols over MCTP = %d\n",
4004 : : p->mng_protocols_over_mctp);
4005 : : } else {
4006 : 0 : p->mng_protocols_over_mctp = 0;
4007 : : }
4008 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4009 : : "HW Capability: Management Mode = %d\n",
4010 : : p->management_mode);
4011 : : break;
4012 : 0 : case I40E_AQ_CAP_ID_NPAR_ACTIVE:
4013 : 0 : p->npar_enable = number;
4014 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4015 : : "HW Capability: NPAR enable = %d\n",
4016 : : p->npar_enable);
4017 : : break;
4018 : 0 : case I40E_AQ_CAP_ID_OS2BMC_CAP:
4019 : 0 : p->os2bmc = number;
4020 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4021 : : "HW Capability: OS2BMC = %d\n", p->os2bmc);
4022 : : break;
4023 : 0 : case I40E_AQ_CAP_ID_FUNCTIONS_VALID:
4024 : 0 : p->valid_functions = number;
4025 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4026 : : "HW Capability: Valid Functions = %d\n",
4027 : : p->valid_functions);
4028 : : break;
4029 : 0 : case I40E_AQ_CAP_ID_SRIOV:
4030 [ # # ]: 0 : if (number == 1)
4031 : 0 : p->sr_iov_1_1 = true;
4032 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4033 : : "HW Capability: SR-IOV = %d\n",
4034 : : p->sr_iov_1_1);
4035 : : break;
4036 : 0 : case I40E_AQ_CAP_ID_VF:
4037 : 0 : p->num_vfs = number;
4038 : 0 : p->vf_base_id = logical_id;
4039 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4040 : : "HW Capability: VF count = %d\n",
4041 : : p->num_vfs);
4042 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4043 : : "HW Capability: VF base_id = %d\n",
4044 : : p->vf_base_id);
4045 : : break;
4046 : 0 : case I40E_AQ_CAP_ID_VMDQ:
4047 [ # # ]: 0 : if (number == 1)
4048 : 0 : p->vmdq = true;
4049 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4050 : : "HW Capability: VMDQ = %d\n", p->vmdq);
4051 : : break;
4052 : 0 : case I40E_AQ_CAP_ID_8021QBG:
4053 [ # # ]: 0 : if (number == 1)
4054 : 0 : p->evb_802_1_qbg = true;
4055 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4056 : : "HW Capability: 802.1Qbg = %d\n", number);
4057 : : break;
4058 : 0 : case I40E_AQ_CAP_ID_8021QBR:
4059 [ # # ]: 0 : if (number == 1)
4060 : 0 : p->evb_802_1_qbh = true;
4061 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4062 : : "HW Capability: 802.1Qbh = %d\n", number);
4063 : : break;
4064 : 0 : case I40E_AQ_CAP_ID_VSI:
4065 : 0 : p->num_vsis = number;
4066 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4067 : : "HW Capability: VSI count = %d\n",
4068 : : p->num_vsis);
4069 : : break;
4070 : 0 : case I40E_AQ_CAP_ID_DCB:
4071 [ # # ]: 0 : if (number == 1) {
4072 : 0 : p->dcb = true;
4073 : 0 : p->enabled_tcmap = logical_id;
4074 : 0 : p->maxtc = phys_id;
4075 : : }
4076 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4077 : : "HW Capability: DCB = %d\n", p->dcb);
4078 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4079 : : "HW Capability: TC Mapping = %d\n",
4080 : : logical_id);
4081 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4082 : : "HW Capability: TC Max = %d\n", p->maxtc);
4083 : : break;
4084 : 0 : case I40E_AQ_CAP_ID_FCOE:
4085 [ # # ]: 0 : if (number == 1)
4086 : 0 : p->fcoe = true;
4087 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4088 : : "HW Capability: FCOE = %d\n", p->fcoe);
4089 : : break;
4090 : 0 : case I40E_AQ_CAP_ID_ISCSI:
4091 [ # # ]: 0 : if (number == 1)
4092 : 0 : p->iscsi = true;
4093 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4094 : : "HW Capability: iSCSI = %d\n", p->iscsi);
4095 : : break;
4096 : 0 : case I40E_AQ_CAP_ID_RSS:
4097 : 0 : p->rss = true;
4098 : 0 : p->rss_table_size = number;
4099 : 0 : p->rss_table_entry_width = logical_id;
4100 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4101 : : "HW Capability: RSS = %d\n", p->rss);
4102 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4103 : : "HW Capability: RSS table size = %d\n",
4104 : : p->rss_table_size);
4105 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4106 : : "HW Capability: RSS table width = %d\n",
4107 : : p->rss_table_entry_width);
4108 : : break;
4109 : 0 : case I40E_AQ_CAP_ID_RXQ:
4110 : 0 : p->num_rx_qp = number;
4111 : 0 : p->base_queue = phys_id;
4112 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4113 : : "HW Capability: Rx QP = %d\n", number);
4114 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4115 : : "HW Capability: base_queue = %d\n",
4116 : : p->base_queue);
4117 : : break;
4118 : 0 : case I40E_AQ_CAP_ID_TXQ:
4119 : 0 : p->num_tx_qp = number;
4120 : 0 : p->base_queue = phys_id;
4121 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4122 : : "HW Capability: Tx QP = %d\n", number);
4123 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4124 : : "HW Capability: base_queue = %d\n",
4125 : : p->base_queue);
4126 : : break;
4127 : 0 : case I40E_AQ_CAP_ID_MSIX:
4128 : 0 : p->num_msix_vectors = number;
4129 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4130 : : "HW Capability: MSIX vector count = %d\n",
4131 : : p->num_msix_vectors);
4132 : : break;
4133 : 0 : case I40E_AQ_CAP_ID_VF_MSIX:
4134 : 0 : p->num_msix_vectors_vf = number;
4135 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4136 : : "HW Capability: MSIX VF vector count = %d\n",
4137 : : p->num_msix_vectors_vf);
4138 : : break;
4139 : 0 : case I40E_AQ_CAP_ID_FLEX10:
4140 [ # # ]: 0 : if (major_rev == 1) {
4141 [ # # ]: 0 : if (number == 1) {
4142 : 0 : p->flex10_enable = true;
4143 : 0 : p->flex10_capable = true;
4144 : : }
4145 : : } else {
4146 : : /* Capability revision >= 2 */
4147 [ # # ]: 0 : if (number & 1)
4148 : 0 : p->flex10_enable = true;
4149 [ # # ]: 0 : if (number & 2)
4150 : 0 : p->flex10_capable = true;
4151 : : }
4152 : 0 : p->flex10_mode = logical_id;
4153 : 0 : p->flex10_status = phys_id;
4154 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4155 : : "HW Capability: Flex10 mode = %d\n",
4156 : : p->flex10_mode);
4157 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4158 : : "HW Capability: Flex10 status = %d\n",
4159 : : p->flex10_status);
4160 : : break;
4161 : 0 : case I40E_AQ_CAP_ID_CEM:
4162 [ # # ]: 0 : if (number == 1)
4163 : 0 : p->mgmt_cem = true;
4164 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4165 : : "HW Capability: CEM = %d\n", p->mgmt_cem);
4166 : : break;
4167 : 0 : case I40E_AQ_CAP_ID_IWARP:
4168 [ # # ]: 0 : if (number == 1)
4169 : 0 : p->iwarp = true;
4170 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4171 : : "HW Capability: iWARP = %d\n", p->iwarp);
4172 : : break;
4173 : 0 : case I40E_AQ_CAP_ID_LED:
4174 [ # # ]: 0 : if (phys_id < I40E_HW_CAP_MAX_GPIO)
4175 : 0 : p->led[phys_id] = true;
4176 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4177 : : "HW Capability: LED - PIN %d\n", phys_id);
4178 : : break;
4179 : 0 : case I40E_AQ_CAP_ID_SDP:
4180 [ # # ]: 0 : if (phys_id < I40E_HW_CAP_MAX_GPIO)
4181 : 0 : p->sdp[phys_id] = true;
4182 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4183 : : "HW Capability: SDP - PIN %d\n", phys_id);
4184 : : break;
4185 : 0 : case I40E_AQ_CAP_ID_MDIO:
4186 [ # # ]: 0 : if (number == 1) {
4187 : 0 : p->mdio_port_num = phys_id;
4188 : 0 : p->mdio_port_mode = logical_id;
4189 : : }
4190 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4191 : : "HW Capability: MDIO port number = %d\n",
4192 : : p->mdio_port_num);
4193 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4194 : : "HW Capability: MDIO port mode = %d\n",
4195 : : p->mdio_port_mode);
4196 : : break;
4197 : 0 : case I40E_AQ_CAP_ID_1588:
4198 [ # # ]: 0 : if (number == 1)
4199 : 0 : p->ieee_1588 = true;
4200 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4201 : : "HW Capability: IEEE 1588 = %d\n",
4202 : : p->ieee_1588);
4203 : : break;
4204 : 0 : case I40E_AQ_CAP_ID_FLOW_DIRECTOR:
4205 : 0 : p->fd = true;
4206 : 0 : p->fd_filters_guaranteed = number;
4207 : 0 : p->fd_filters_best_effort = logical_id;
4208 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4209 : : "HW Capability: Flow Director = 1\n");
4210 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4211 : : "HW Capability: Guaranteed FD filters = %d\n",
4212 : : p->fd_filters_guaranteed);
4213 : : break;
4214 : 0 : case I40E_AQ_CAP_ID_WSR_PROT:
4215 : 0 : p->wr_csr_prot = (u64)number;
4216 : 0 : p->wr_csr_prot |= (u64)logical_id << 32;
4217 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4218 : : "HW Capability: wr_csr_prot = 0x%" PRIX64 "\n\n",
4219 : : (p->wr_csr_prot & 0xffff));
4220 : : break;
4221 : 0 : case I40E_AQ_CAP_ID_DIS_UNUSED_PORTS:
4222 : 0 : p->dis_unused_ports = (bool)number;
4223 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4224 : : "HW Capability: dis_unused_ports = %d\n\n",
4225 : : p->dis_unused_ports);
4226 : : break;
4227 : 0 : case I40E_AQ_CAP_ID_NVM_MGMT:
4228 [ # # ]: 0 : if (number & I40E_NVM_MGMT_SEC_REV_DISABLED)
4229 : 0 : p->sec_rev_disabled = true;
4230 [ # # ]: 0 : if (number & I40E_NVM_MGMT_UPDATE_DISABLED)
4231 : 0 : p->update_disabled = true;
4232 : : break;
4233 : 0 : case I40E_AQ_CAP_ID_WOL_AND_PROXY:
4234 : 0 : hw->num_wol_proxy_filters = (u16)number;
4235 : 0 : hw->wol_proxy_vsi_seid = (u16)logical_id;
4236 : 0 : p->apm_wol_support = phys_id & I40E_WOL_SUPPORT_MASK;
4237 [ # # ]: 0 : if (phys_id & I40E_ACPI_PROGRAMMING_METHOD_MASK)
4238 : 0 : p->acpi_prog_method = I40E_ACPI_PROGRAMMING_METHOD_AQC_FPK;
4239 : : else
4240 : 0 : p->acpi_prog_method = I40E_ACPI_PROGRAMMING_METHOD_HW_FVL;
4241 : 0 : p->proxy_support = (phys_id & I40E_PROXY_SUPPORT_MASK) ? 1 : 0;
4242 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_INIT,
4243 : : "HW Capability: WOL proxy filters = %d\n",
4244 : : hw->num_wol_proxy_filters);
4245 : : break;
4246 : : default:
4247 : : break;
4248 : : }
4249 : : }
4250 : :
4251 [ # # ]: 0 : if (p->fcoe)
4252 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_ALL, "device is FCoE capable\n");
4253 : :
4254 : : /* Always disable FCoE if compiled without the I40E_FCOE_ENA flag */
4255 : 0 : p->fcoe = false;
4256 : :
4257 : : /* count the enabled ports (aka the "not disabled" ports) */
4258 : 0 : hw->num_ports = 0;
4259 [ # # ]: 0 : for (i = 0; i < 4; i++) {
4260 : 0 : u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
4261 : 0 : u64 port_cfg = 0;
4262 : :
4263 : : /* use AQ read to get the physical register offset instead
4264 : : * of the port relative offset
4265 : : */
4266 : 0 : i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
4267 [ # # ]: 0 : if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
4268 : 0 : hw->num_ports++;
4269 : : }
4270 : :
4271 : : /* OCP cards case: if a mezz is removed the ethernet port is at
4272 : : * disabled state in PRTGEN_CNF register. Additional NVM read is
4273 : : * needed in order to check if we are dealing with OCP card.
4274 : : * Those cards have 4 PFs at minimum, so using PRTGEN_CNF for counting
4275 : : * physical ports results in wrong partition id calculation and thus
4276 : : * not supporting WoL.
4277 : : */
4278 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
4279 [ # # ]: 0 : if (i40e_acquire_nvm(hw, I40E_RESOURCE_READ) == I40E_SUCCESS) {
4280 : 0 : status = i40e_aq_read_nvm(hw, I40E_SR_EMP_MODULE_PTR,
4281 : : 2 * I40E_SR_OCP_CFG_WORD0,
4282 : : sizeof(ocp_cfg_word0),
4283 : : &ocp_cfg_word0, true, NULL);
4284 [ # # # # ]: 0 : if (status == I40E_SUCCESS &&
4285 : : (ocp_cfg_word0 & I40E_SR_OCP_ENABLED))
4286 : 0 : hw->num_ports = 4;
4287 : 0 : i40e_release_nvm(hw);
4288 : : }
4289 : : }
4290 : :
4291 : 0 : valid_functions = p->valid_functions;
4292 : : num_functions = 0;
4293 [ # # ]: 0 : while (valid_functions) {
4294 [ # # ]: 0 : if (valid_functions & 1)
4295 : 0 : num_functions++;
4296 : 0 : valid_functions >>= 1;
4297 : : }
4298 : :
4299 : : /* partition id is 1-based, and functions are evenly spread
4300 : : * across the ports as partitions
4301 : : */
4302 [ # # ]: 0 : if (hw->num_ports != 0) {
4303 : 0 : hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
4304 : 0 : hw->num_partitions = num_functions / hw->num_ports;
4305 : : }
4306 : :
4307 : : /* additional HW specific goodies that might
4308 : : * someday be HW version specific
4309 : : */
4310 : 0 : p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
4311 : : }
4312 : :
4313 : : /**
4314 : : * i40e_aq_discover_capabilities
4315 : : * @hw: pointer to the hw struct
4316 : : * @buff: a virtual buffer to hold the capabilities
4317 : : * @buff_size: Size of the virtual buffer
4318 : : * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
4319 : : * @list_type_opc: capabilities type to discover - pass in the command opcode
4320 : : * @cmd_details: pointer to command details structure or NULL
4321 : : *
4322 : : * Get the device capabilities descriptions from the firmware
4323 : : **/
4324 : 0 : enum i40e_status_code i40e_aq_discover_capabilities(struct i40e_hw *hw,
4325 : : void *buff, u16 buff_size, u16 *data_size,
4326 : : enum i40e_admin_queue_opc list_type_opc,
4327 : : struct i40e_asq_cmd_details *cmd_details)
4328 : : {
4329 : : struct i40e_aqc_list_capabilites *cmd;
4330 : : struct i40e_aq_desc desc;
4331 : : enum i40e_status_code status = I40E_SUCCESS;
4332 : :
4333 : : cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
4334 : :
4335 [ # # ]: 0 : if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
4336 : : list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
4337 : : status = I40E_ERR_PARAM;
4338 : 0 : goto exit;
4339 : : }
4340 : :
4341 : 0 : i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
4342 : :
4343 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
4344 [ # # ]: 0 : if (buff_size > I40E_AQ_LARGE_BUF)
4345 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
4346 : :
4347 : 0 : status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
4348 : 0 : *data_size = LE16_TO_CPU(desc.datalen);
4349 : :
4350 [ # # ]: 0 : if (status)
4351 : 0 : goto exit;
4352 : :
4353 : 0 : i40e_parse_discover_capabilities(hw, buff, LE32_TO_CPU(cmd->count),
4354 : : list_type_opc);
4355 : :
4356 : 0 : exit:
4357 : 0 : return status;
4358 : : }
4359 : :
4360 : : /**
4361 : : * i40e_aq_update_nvm
4362 : : * @hw: pointer to the hw struct
4363 : : * @module_pointer: module pointer location in words from the NVM beginning
4364 : : * @offset: byte offset from the module beginning
4365 : : * @length: length of the section to be written (in bytes from the offset)
4366 : : * @data: command buffer (size [bytes] = length)
4367 : : * @last_command: tells if this is the last command in a series
4368 : : * @preservation_flags: Preservation mode flags
4369 : : * @cmd_details: pointer to command details structure or NULL
4370 : : *
4371 : : * Update the NVM using the admin queue commands
4372 : : **/
4373 : 0 : enum i40e_status_code i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
4374 : : u32 offset, u16 length, void *data,
4375 : : bool last_command, u8 preservation_flags,
4376 : : struct i40e_asq_cmd_details *cmd_details)
4377 : : {
4378 : : struct i40e_aq_desc desc;
4379 : : struct i40e_aqc_nvm_update *cmd =
4380 : : (struct i40e_aqc_nvm_update *)&desc.params.raw;
4381 : : enum i40e_status_code status;
4382 : :
4383 : 0 : DEBUGFUNC("i40e_aq_update_nvm");
4384 : :
4385 : : /* In offset the highest byte must be zeroed. */
4386 [ # # ]: 0 : if (offset & 0xFF000000) {
4387 : : status = I40E_ERR_PARAM;
4388 : 0 : goto i40e_aq_update_nvm_exit;
4389 : : }
4390 : :
4391 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
4392 : :
4393 : : /* If this is the last command in a series, set the proper flag. */
4394 [ # # ]: 0 : if (last_command)
4395 : 0 : cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
4396 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
4397 [ # # ]: 0 : if (preservation_flags == I40E_NVM_PRESERVATION_FLAGS_SELECTED)
4398 : 0 : cmd->command_flags |=
4399 : : (I40E_AQ_NVM_PRESERVATION_FLAGS_SELECTED <<
4400 : : I40E_AQ_NVM_PRESERVATION_FLAGS_SHIFT);
4401 [ # # ]: 0 : else if (preservation_flags == I40E_NVM_PRESERVATION_FLAGS_ALL)
4402 : 0 : cmd->command_flags |=
4403 : : (I40E_AQ_NVM_PRESERVATION_FLAGS_ALL <<
4404 : : I40E_AQ_NVM_PRESERVATION_FLAGS_SHIFT);
4405 : : }
4406 : 0 : cmd->module_pointer = module_pointer;
4407 : 0 : cmd->offset = CPU_TO_LE32(offset);
4408 : 0 : cmd->length = CPU_TO_LE16(length);
4409 : :
4410 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
4411 [ # # ]: 0 : if (length > I40E_AQ_LARGE_BUF)
4412 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
4413 : :
4414 : 0 : status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
4415 : :
4416 : 0 : i40e_aq_update_nvm_exit:
4417 : 0 : return status;
4418 : : }
4419 : :
4420 : : /**
4421 : : * i40e_aq_rearrange_nvm
4422 : : * @hw: pointer to the hw struct
4423 : : * @rearrange_nvm: defines direction of rearrangement
4424 : : * @cmd_details: pointer to command details structure or NULL
4425 : : *
4426 : : * Rearrange NVM structure, available only for transition FW
4427 : : **/
4428 : 0 : enum i40e_status_code i40e_aq_rearrange_nvm(struct i40e_hw *hw,
4429 : : u8 rearrange_nvm,
4430 : : struct i40e_asq_cmd_details *cmd_details)
4431 : : {
4432 : : struct i40e_aqc_nvm_update *cmd;
4433 : : enum i40e_status_code status;
4434 : : struct i40e_aq_desc desc;
4435 : :
4436 : 0 : DEBUGFUNC("i40e_aq_rearrange_nvm");
4437 : :
4438 : : cmd = (struct i40e_aqc_nvm_update *)&desc.params.raw;
4439 : :
4440 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
4441 : :
4442 : 0 : rearrange_nvm &= (I40E_AQ_NVM_REARRANGE_TO_FLAT |
4443 : : I40E_AQ_NVM_REARRANGE_TO_STRUCT);
4444 : :
4445 [ # # ]: 0 : if (!rearrange_nvm) {
4446 : : status = I40E_ERR_PARAM;
4447 : 0 : goto i40e_aq_rearrange_nvm_exit;
4448 : : }
4449 : :
4450 : 0 : cmd->command_flags |= rearrange_nvm;
4451 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4452 : :
4453 : 0 : i40e_aq_rearrange_nvm_exit:
4454 : 0 : return status;
4455 : : }
4456 : :
4457 : : /**
4458 : : * i40e_aq_get_lldp_mib
4459 : : * @hw: pointer to the hw struct
4460 : : * @bridge_type: type of bridge requested
4461 : : * @mib_type: Local, Remote or both Local and Remote MIBs
4462 : : * @buff: pointer to a user supplied buffer to store the MIB block
4463 : : * @buff_size: size of the buffer (in bytes)
4464 : : * @local_len : length of the returned Local LLDP MIB
4465 : : * @remote_len: length of the returned Remote LLDP MIB
4466 : : * @cmd_details: pointer to command details structure or NULL
4467 : : *
4468 : : * Requests the complete LLDP MIB (entire packet).
4469 : : **/
4470 : 0 : enum i40e_status_code i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
4471 : : u8 mib_type, void *buff, u16 buff_size,
4472 : : u16 *local_len, u16 *remote_len,
4473 : : struct i40e_asq_cmd_details *cmd_details)
4474 : : {
4475 : : struct i40e_aq_desc desc;
4476 : : struct i40e_aqc_lldp_get_mib *cmd =
4477 : : (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
4478 : : struct i40e_aqc_lldp_get_mib *resp =
4479 : : (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
4480 : : enum i40e_status_code status;
4481 : :
4482 [ # # ]: 0 : if (buff_size == 0 || !buff)
4483 : : return I40E_ERR_PARAM;
4484 : :
4485 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
4486 : : /* Indirect Command */
4487 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
4488 : :
4489 : 0 : cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
4490 : 0 : cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
4491 : : I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
4492 : :
4493 : 0 : desc.datalen = CPU_TO_LE16(buff_size);
4494 : :
4495 : : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
4496 [ # # ]: 0 : if (buff_size > I40E_AQ_LARGE_BUF)
4497 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
4498 : :
4499 : 0 : status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
4500 [ # # ]: 0 : if (!status) {
4501 [ # # ]: 0 : if (local_len != NULL)
4502 : 0 : *local_len = LE16_TO_CPU(resp->local_len);
4503 [ # # ]: 0 : if (remote_len != NULL)
4504 : 0 : *remote_len = LE16_TO_CPU(resp->remote_len);
4505 : : }
4506 : :
4507 : : return status;
4508 : : }
4509 : :
4510 : : /**
4511 : : * i40e_aq_set_lldp_mib - Set the LLDP MIB
4512 : : * @hw: pointer to the hw struct
4513 : : * @mib_type: Local, Remote or both Local and Remote MIBs
4514 : : * @buff: pointer to a user supplied buffer to store the MIB block
4515 : : * @buff_size: size of the buffer (in bytes)
4516 : : * @cmd_details: pointer to command details structure or NULL
4517 : : *
4518 : : * Set the LLDP MIB.
4519 : : **/
4520 : 0 : enum i40e_status_code i40e_aq_set_lldp_mib(struct i40e_hw *hw,
4521 : : u8 mib_type, void *buff, u16 buff_size,
4522 : : struct i40e_asq_cmd_details *cmd_details)
4523 : : {
4524 : : struct i40e_aq_desc desc;
4525 : : struct i40e_aqc_lldp_set_local_mib *cmd =
4526 : : (struct i40e_aqc_lldp_set_local_mib *)&desc.params.raw;
4527 : : enum i40e_status_code status;
4528 : :
4529 [ # # ]: 0 : if (buff_size == 0 || !buff)
4530 : : return I40E_ERR_PARAM;
4531 : :
4532 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
4533 : : i40e_aqc_opc_lldp_set_local_mib);
4534 : : /* Indirect Command */
4535 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
4536 [ # # ]: 0 : if (buff_size > I40E_AQ_LARGE_BUF)
4537 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
4538 : 0 : desc.datalen = CPU_TO_LE16(buff_size);
4539 : :
4540 : 0 : cmd->type = mib_type;
4541 : 0 : cmd->length = CPU_TO_LE16(buff_size);
4542 : 0 : cmd->address_high = CPU_TO_LE32(I40E_HI_DWORD((u64)buff));
4543 : 0 : cmd->address_low = CPU_TO_LE32(I40E_LO_DWORD((u64)buff));
4544 : :
4545 : 0 : status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
4546 : 0 : return status;
4547 : : }
4548 : :
4549 : : /**
4550 : : * i40e_aq_cfg_lldp_mib_change_event
4551 : : * @hw: pointer to the hw struct
4552 : : * @enable_update: Enable or Disable event posting
4553 : : * @cmd_details: pointer to command details structure or NULL
4554 : : *
4555 : : * Enable or Disable posting of an event on ARQ when LLDP MIB
4556 : : * associated with the interface changes
4557 : : **/
4558 : 0 : enum i40e_status_code i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
4559 : : bool enable_update,
4560 : : struct i40e_asq_cmd_details *cmd_details)
4561 : : {
4562 : : struct i40e_aq_desc desc;
4563 : : struct i40e_aqc_lldp_update_mib *cmd =
4564 : : (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
4565 : : enum i40e_status_code status;
4566 : :
4567 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
4568 : :
4569 [ # # ]: 0 : if (!enable_update)
4570 : 0 : cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
4571 : :
4572 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4573 : :
4574 : 0 : return status;
4575 : : }
4576 : :
4577 : : /**
4578 : : * i40e_aq_restore_lldp
4579 : : * @hw: pointer to the hw struct
4580 : : * @setting: pointer to factory setting variable or NULL
4581 : : * @restore: True if factory settings should be restored
4582 : : * @cmd_details: pointer to command details structure or NULL
4583 : : *
4584 : : * Restore LLDP Agent factory settings if @restore set to True. In other case
4585 : : * only returns factory setting in AQ response.
4586 : : **/
4587 : : enum i40e_status_code
4588 : 0 : i40e_aq_restore_lldp(struct i40e_hw *hw, u8 *setting, bool restore,
4589 : : struct i40e_asq_cmd_details *cmd_details)
4590 : : {
4591 : : struct i40e_aq_desc desc;
4592 : : struct i40e_aqc_lldp_restore *cmd =
4593 : : (struct i40e_aqc_lldp_restore *)&desc.params.raw;
4594 : : enum i40e_status_code status;
4595 : :
4596 [ # # ]: 0 : if (!(hw->flags & I40E_HW_FLAG_FW_LLDP_PERSISTENT)) {
4597 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_ALL,
4598 : : "Restore LLDP not supported by current FW version.\n");
4599 : 0 : return I40E_ERR_DEVICE_NOT_SUPPORTED;
4600 : : }
4601 : :
4602 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_restore);
4603 : :
4604 [ # # ]: 0 : if (restore)
4605 : 0 : cmd->command |= I40E_AQ_LLDP_AGENT_RESTORE;
4606 : :
4607 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4608 : :
4609 [ # # ]: 0 : if (setting)
4610 : 0 : *setting = cmd->command & 1;
4611 : :
4612 : : return status;
4613 : : }
4614 : :
4615 : : /**
4616 : : * i40e_aq_stop_lldp
4617 : : * @hw: pointer to the hw struct
4618 : : * @shutdown_agent: True if LLDP Agent needs to be Shutdown
4619 : : * @persist: True if stop of LLDP should be persistent across power cycles
4620 : : * @cmd_details: pointer to command details structure or NULL
4621 : : *
4622 : : * Stop or Shutdown the embedded LLDP Agent
4623 : : **/
4624 : 0 : enum i40e_status_code i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
4625 : : bool persist,
4626 : : struct i40e_asq_cmd_details *cmd_details)
4627 : : {
4628 : : struct i40e_aq_desc desc;
4629 : : struct i40e_aqc_lldp_stop *cmd =
4630 : : (struct i40e_aqc_lldp_stop *)&desc.params.raw;
4631 : : enum i40e_status_code status;
4632 : :
4633 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
4634 : :
4635 [ # # ]: 0 : if (shutdown_agent)
4636 : 0 : cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
4637 : :
4638 [ # # ]: 0 : if (persist) {
4639 [ # # ]: 0 : if (hw->flags & I40E_HW_FLAG_FW_LLDP_PERSISTENT)
4640 : 0 : cmd->command |= I40E_AQ_LLDP_AGENT_STOP_PERSIST;
4641 : : else
4642 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_ALL,
4643 : : "Persistent Stop LLDP not supported by current FW version.\n");
4644 : : }
4645 : :
4646 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4647 : :
4648 : 0 : return status;
4649 : : }
4650 : :
4651 : : /**
4652 : : * i40e_aq_start_lldp
4653 : : * @hw: pointer to the hw struct
4654 : : * @persist: True if start of LLDP should be persistent across power cycles
4655 : : * @cmd_details: pointer to command details structure or NULL
4656 : : *
4657 : : * Start the embedded LLDP Agent on all ports.
4658 : : **/
4659 : 0 : enum i40e_status_code i40e_aq_start_lldp(struct i40e_hw *hw,
4660 : : bool persist,
4661 : : struct i40e_asq_cmd_details *cmd_details)
4662 : : {
4663 : : struct i40e_aq_desc desc;
4664 : : struct i40e_aqc_lldp_start *cmd =
4665 : : (struct i40e_aqc_lldp_start *)&desc.params.raw;
4666 : : enum i40e_status_code status;
4667 : :
4668 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
4669 : :
4670 : 0 : cmd->command = I40E_AQ_LLDP_AGENT_START;
4671 : :
4672 [ # # ]: 0 : if (persist) {
4673 [ # # ]: 0 : if (hw->flags & I40E_HW_FLAG_FW_LLDP_PERSISTENT)
4674 : 0 : cmd->command |= I40E_AQ_LLDP_AGENT_START_PERSIST;
4675 : : else
4676 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_ALL,
4677 : : "Persistent Start LLDP not supported by current FW version.\n");
4678 : : }
4679 : :
4680 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4681 : :
4682 : 0 : return status;
4683 : : }
4684 : :
4685 : : /**
4686 : : * i40e_aq_set_dcb_parameters
4687 : : * @hw: pointer to the hw struct
4688 : : * @cmd_details: pointer to command details structure or NULL
4689 : : * @dcb_enable: True if DCB configuration needs to be applied
4690 : : *
4691 : : **/
4692 : : enum i40e_status_code
4693 : 0 : i40e_aq_set_dcb_parameters(struct i40e_hw *hw, bool dcb_enable,
4694 : : struct i40e_asq_cmd_details *cmd_details)
4695 : : {
4696 : : struct i40e_aq_desc desc;
4697 : : struct i40e_aqc_set_dcb_parameters *cmd =
4698 : : (struct i40e_aqc_set_dcb_parameters *)&desc.params.raw;
4699 : : enum i40e_status_code status;
4700 : :
4701 [ # # ]: 0 : if (!(hw->flags & I40E_HW_FLAG_FW_LLDP_STOPPABLE))
4702 : : return I40E_ERR_DEVICE_NOT_SUPPORTED;
4703 : :
4704 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
4705 : : i40e_aqc_opc_set_dcb_parameters);
4706 : :
4707 [ # # ]: 0 : if (dcb_enable) {
4708 : 0 : cmd->valid_flags = I40E_DCB_VALID;
4709 : 0 : cmd->command = I40E_AQ_DCB_SET_AGENT;
4710 : : }
4711 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4712 : :
4713 : 0 : return status;
4714 : : }
4715 : :
4716 : : /**
4717 : : * i40e_aq_get_cee_dcb_config
4718 : : * @hw: pointer to the hw struct
4719 : : * @buff: response buffer that stores CEE operational configuration
4720 : : * @buff_size: size of the buffer passed
4721 : : * @cmd_details: pointer to command details structure or NULL
4722 : : *
4723 : : * Get CEE DCBX mode operational configuration from firmware
4724 : : **/
4725 : 0 : enum i40e_status_code i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
4726 : : void *buff, u16 buff_size,
4727 : : struct i40e_asq_cmd_details *cmd_details)
4728 : : {
4729 : : struct i40e_aq_desc desc;
4730 : : enum i40e_status_code status;
4731 : :
4732 [ # # ]: 0 : if (buff_size == 0 || !buff)
4733 : : return I40E_ERR_PARAM;
4734 : :
4735 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
4736 : :
4737 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
4738 : 0 : status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
4739 : : cmd_details);
4740 : :
4741 : 0 : return status;
4742 : : }
4743 : :
4744 : : /**
4745 : : * i40e_aq_start_stop_dcbx - Start/Stop DCBx service in FW
4746 : : * @hw: pointer to the hw struct
4747 : : * @start_agent: True if DCBx Agent needs to be Started
4748 : : * False if DCBx Agent needs to be Stopped
4749 : : * @cmd_details: pointer to command details structure or NULL
4750 : : *
4751 : : * Start/Stop the embedded dcbx Agent
4752 : : **/
4753 : 0 : enum i40e_status_code i40e_aq_start_stop_dcbx(struct i40e_hw *hw,
4754 : : bool start_agent,
4755 : : struct i40e_asq_cmd_details *cmd_details)
4756 : : {
4757 : : struct i40e_aq_desc desc;
4758 : : struct i40e_aqc_lldp_stop_start_specific_agent *cmd =
4759 : : (struct i40e_aqc_lldp_stop_start_specific_agent *)
4760 : : &desc.params.raw;
4761 : : enum i40e_status_code status;
4762 : :
4763 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
4764 : : i40e_aqc_opc_lldp_stop_start_spec_agent);
4765 : :
4766 [ # # ]: 0 : if (start_agent)
4767 : 0 : cmd->command = I40E_AQC_START_SPECIFIC_AGENT_MASK;
4768 : :
4769 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4770 : :
4771 : 0 : return status;
4772 : : }
4773 : :
4774 : : /**
4775 : : * i40e_aq_add_udp_tunnel
4776 : : * @hw: pointer to the hw struct
4777 : : * @udp_port: the UDP port to add in Host byte order
4778 : : * @protocol_index: protocol index type
4779 : : * @filter_index: pointer to filter index
4780 : : * @cmd_details: pointer to command details structure or NULL
4781 : : *
4782 : : * Note: Firmware expects the udp_port value to be in Little Endian format,
4783 : : * and this function will call CPU_TO_LE16 to convert from Host byte order to
4784 : : * Little Endian order.
4785 : : **/
4786 : 0 : enum i40e_status_code i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
4787 : : u16 udp_port, u8 protocol_index,
4788 : : u8 *filter_index,
4789 : : struct i40e_asq_cmd_details *cmd_details)
4790 : : {
4791 : : struct i40e_aq_desc desc;
4792 : : struct i40e_aqc_add_udp_tunnel *cmd =
4793 : : (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
4794 : : struct i40e_aqc_del_udp_tunnel_completion *resp =
4795 : : (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
4796 : : enum i40e_status_code status;
4797 : :
4798 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
4799 : :
4800 : 0 : cmd->udp_port = CPU_TO_LE16(udp_port);
4801 : 0 : cmd->protocol_type = protocol_index;
4802 : :
4803 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4804 : :
4805 [ # # ]: 0 : if (!status && filter_index)
4806 : 0 : *filter_index = resp->index;
4807 : :
4808 : 0 : return status;
4809 : : }
4810 : :
4811 : : /**
4812 : : * i40e_aq_del_udp_tunnel
4813 : : * @hw: pointer to the hw struct
4814 : : * @index: filter index
4815 : : * @cmd_details: pointer to command details structure or NULL
4816 : : **/
4817 : 0 : enum i40e_status_code i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
4818 : : struct i40e_asq_cmd_details *cmd_details)
4819 : : {
4820 : : struct i40e_aq_desc desc;
4821 : : struct i40e_aqc_remove_udp_tunnel *cmd =
4822 : : (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
4823 : : enum i40e_status_code status;
4824 : :
4825 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
4826 : :
4827 : 0 : cmd->index = index;
4828 : :
4829 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4830 : :
4831 : 0 : return status;
4832 : : }
4833 : :
4834 : : /**
4835 : : * i40e_aq_get_switch_resource_alloc - command (0x0204) to get allocations
4836 : : * @hw: pointer to the hw struct
4837 : : * @num_entries: pointer to u8 to store the number of resource entries returned
4838 : : * @buf: pointer to a user supplied buffer. This buffer must be large enough
4839 : : * to store the resource information for all resource types. Each
4840 : : * resource type is a i40e_aqc_switch_resource_alloc_data structure.
4841 : : * @count: size, in bytes, of the buffer provided
4842 : : * @cmd_details: pointer to command details structure or NULL
4843 : : *
4844 : : * Query the resources allocated to a function.
4845 : : **/
4846 : 0 : enum i40e_status_code i40e_aq_get_switch_resource_alloc(struct i40e_hw *hw,
4847 : : u8 *num_entries,
4848 : : struct i40e_aqc_switch_resource_alloc_element_resp *buf,
4849 : : u16 count,
4850 : : struct i40e_asq_cmd_details *cmd_details)
4851 : : {
4852 : : struct i40e_aq_desc desc;
4853 : : struct i40e_aqc_get_switch_resource_alloc *cmd_resp =
4854 : : (struct i40e_aqc_get_switch_resource_alloc *)&desc.params.raw;
4855 : : enum i40e_status_code status;
4856 : 0 : u16 length = count * sizeof(*buf);
4857 : :
4858 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
4859 : : i40e_aqc_opc_get_switch_resource_alloc);
4860 : :
4861 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
4862 [ # # ]: 0 : if (length > I40E_AQ_LARGE_BUF)
4863 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
4864 : :
4865 : 0 : status = i40e_asq_send_command(hw, &desc, buf, length, cmd_details);
4866 : :
4867 [ # # ]: 0 : if (!status && num_entries)
4868 : 0 : *num_entries = cmd_resp->num_entries;
4869 : :
4870 : 0 : return status;
4871 : : }
4872 : :
4873 : : /**
4874 : : * i40e_aq_delete_element - Delete switch element
4875 : : * @hw: pointer to the hw struct
4876 : : * @seid: the SEID to delete from the switch
4877 : : * @cmd_details: pointer to command details structure or NULL
4878 : : *
4879 : : * This deletes a switch element from the switch.
4880 : : **/
4881 : 0 : enum i40e_status_code i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
4882 : : struct i40e_asq_cmd_details *cmd_details)
4883 : : {
4884 : : struct i40e_aq_desc desc;
4885 : : struct i40e_aqc_switch_seid *cmd =
4886 : : (struct i40e_aqc_switch_seid *)&desc.params.raw;
4887 : : enum i40e_status_code status;
4888 : :
4889 [ # # ]: 0 : if (seid == 0)
4890 : : return I40E_ERR_PARAM;
4891 : :
4892 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
4893 : :
4894 : 0 : cmd->seid = CPU_TO_LE16(seid);
4895 : :
4896 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4897 : :
4898 : 0 : return status;
4899 : : }
4900 : :
4901 : : /**
4902 : : * i40e_aq_add_pvirt - Instantiate a Port Virtualizer on a port
4903 : : * @hw: pointer to the hw struct
4904 : : * @flags: component flags
4905 : : * @mac_seid: uplink seid (MAC SEID)
4906 : : * @vsi_seid: connected vsi seid
4907 : : * @ret_seid: seid of create pv component
4908 : : *
4909 : : * This instantiates an i40e port virtualizer with specified flags.
4910 : : * Depending on specified flags the port virtualizer can act as a
4911 : : * 802.1Qbr port virtualizer or a 802.1Qbg S-component.
4912 : : */
4913 : 0 : enum i40e_status_code i40e_aq_add_pvirt(struct i40e_hw *hw, u16 flags,
4914 : : u16 mac_seid, u16 vsi_seid,
4915 : : u16 *ret_seid)
4916 : : {
4917 : : struct i40e_aq_desc desc;
4918 : : struct i40e_aqc_add_update_pv *cmd =
4919 : : (struct i40e_aqc_add_update_pv *)&desc.params.raw;
4920 : : struct i40e_aqc_add_update_pv_completion *resp =
4921 : : (struct i40e_aqc_add_update_pv_completion *)&desc.params.raw;
4922 : : enum i40e_status_code status;
4923 : :
4924 [ # # ]: 0 : if (vsi_seid == 0)
4925 : : return I40E_ERR_PARAM;
4926 : :
4927 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_pv);
4928 : 0 : cmd->command_flags = CPU_TO_LE16(flags);
4929 : 0 : cmd->uplink_seid = CPU_TO_LE16(mac_seid);
4930 : 0 : cmd->connected_seid = CPU_TO_LE16(vsi_seid);
4931 : :
4932 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
4933 [ # # ]: 0 : if (!status && ret_seid)
4934 : 0 : *ret_seid = LE16_TO_CPU(resp->pv_seid);
4935 : :
4936 : : return status;
4937 : : }
4938 : :
4939 : : /**
4940 : : * i40e_aq_add_tag - Add an S/E-tag
4941 : : * @hw: pointer to the hw struct
4942 : : * @direct_to_queue: should s-tag direct flow to a specific queue
4943 : : * @vsi_seid: VSI SEID to use this tag
4944 : : * @tag: value of the tag
4945 : : * @queue_num: queue number, only valid is direct_to_queue is true
4946 : : * @tags_used: return value, number of tags in use by this PF
4947 : : * @tags_free: return value, number of unallocated tags
4948 : : * @cmd_details: pointer to command details structure or NULL
4949 : : *
4950 : : * This associates an S- or E-tag to a VSI in the switch complex. It returns
4951 : : * the number of tags allocated by the PF, and the number of unallocated
4952 : : * tags available.
4953 : : **/
4954 : 0 : enum i40e_status_code i40e_aq_add_tag(struct i40e_hw *hw, bool direct_to_queue,
4955 : : u16 vsi_seid, u16 tag, u16 queue_num,
4956 : : u16 *tags_used, u16 *tags_free,
4957 : : struct i40e_asq_cmd_details *cmd_details)
4958 : : {
4959 : : struct i40e_aq_desc desc;
4960 : : struct i40e_aqc_add_tag *cmd =
4961 : : (struct i40e_aqc_add_tag *)&desc.params.raw;
4962 : : struct i40e_aqc_add_remove_tag_completion *resp =
4963 : : (struct i40e_aqc_add_remove_tag_completion *)&desc.params.raw;
4964 : : enum i40e_status_code status;
4965 : :
4966 [ # # ]: 0 : if (vsi_seid == 0)
4967 : : return I40E_ERR_PARAM;
4968 : :
4969 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_tag);
4970 : :
4971 : 0 : cmd->seid = CPU_TO_LE16(vsi_seid);
4972 : 0 : cmd->tag = CPU_TO_LE16(tag);
4973 [ # # ]: 0 : if (direct_to_queue) {
4974 : 0 : cmd->flags = CPU_TO_LE16(I40E_AQC_ADD_TAG_FLAG_TO_QUEUE);
4975 : 0 : cmd->queue_number = CPU_TO_LE16(queue_num);
4976 : : }
4977 : :
4978 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4979 : :
4980 [ # # ]: 0 : if (!status) {
4981 [ # # ]: 0 : if (tags_used != NULL)
4982 : 0 : *tags_used = LE16_TO_CPU(resp->tags_used);
4983 [ # # ]: 0 : if (tags_free != NULL)
4984 : 0 : *tags_free = LE16_TO_CPU(resp->tags_free);
4985 : : }
4986 : :
4987 : : return status;
4988 : : }
4989 : :
4990 : : /**
4991 : : * i40e_aq_remove_tag - Remove an S- or E-tag
4992 : : * @hw: pointer to the hw struct
4993 : : * @vsi_seid: VSI SEID this tag is associated with
4994 : : * @tag: value of the S-tag to delete
4995 : : * @tags_used: return value, number of tags in use by this PF
4996 : : * @tags_free: return value, number of unallocated tags
4997 : : * @cmd_details: pointer to command details structure or NULL
4998 : : *
4999 : : * This deletes an S- or E-tag from a VSI in the switch complex. It returns
5000 : : * the number of tags allocated by the PF, and the number of unallocated
5001 : : * tags available.
5002 : : **/
5003 : 0 : enum i40e_status_code i40e_aq_remove_tag(struct i40e_hw *hw, u16 vsi_seid,
5004 : : u16 tag, u16 *tags_used, u16 *tags_free,
5005 : : struct i40e_asq_cmd_details *cmd_details)
5006 : : {
5007 : : struct i40e_aq_desc desc;
5008 : : struct i40e_aqc_remove_tag *cmd =
5009 : : (struct i40e_aqc_remove_tag *)&desc.params.raw;
5010 : : struct i40e_aqc_add_remove_tag_completion *resp =
5011 : : (struct i40e_aqc_add_remove_tag_completion *)&desc.params.raw;
5012 : : enum i40e_status_code status;
5013 : :
5014 [ # # ]: 0 : if (vsi_seid == 0)
5015 : : return I40E_ERR_PARAM;
5016 : :
5017 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_tag);
5018 : :
5019 : 0 : cmd->seid = CPU_TO_LE16(vsi_seid);
5020 : 0 : cmd->tag = CPU_TO_LE16(tag);
5021 : :
5022 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5023 : :
5024 [ # # ]: 0 : if (!status) {
5025 [ # # ]: 0 : if (tags_used != NULL)
5026 : 0 : *tags_used = LE16_TO_CPU(resp->tags_used);
5027 [ # # ]: 0 : if (tags_free != NULL)
5028 : 0 : *tags_free = LE16_TO_CPU(resp->tags_free);
5029 : : }
5030 : :
5031 : : return status;
5032 : : }
5033 : :
5034 : : /**
5035 : : * i40e_aq_add_mcast_etag - Add a multicast E-tag
5036 : : * @hw: pointer to the hw struct
5037 : : * @pv_seid: Port Virtualizer of this SEID to associate E-tag with
5038 : : * @etag: value of E-tag to add
5039 : : * @num_tags_in_buf: number of unicast E-tags in indirect buffer
5040 : : * @buf: address of indirect buffer
5041 : : * @tags_used: return value, number of E-tags in use by this port
5042 : : * @tags_free: return value, number of unallocated M-tags
5043 : : * @cmd_details: pointer to command details structure or NULL
5044 : : *
5045 : : * This associates a multicast E-tag to a port virtualizer. It will return
5046 : : * the number of tags allocated by the PF, and the number of unallocated
5047 : : * tags available.
5048 : : *
5049 : : * The indirect buffer pointed to by buf is a list of 2-byte E-tags,
5050 : : * num_tags_in_buf long.
5051 : : **/
5052 : 0 : enum i40e_status_code i40e_aq_add_mcast_etag(struct i40e_hw *hw, u16 pv_seid,
5053 : : u16 etag, u8 num_tags_in_buf, void *buf,
5054 : : u16 *tags_used, u16 *tags_free,
5055 : : struct i40e_asq_cmd_details *cmd_details)
5056 : : {
5057 : : struct i40e_aq_desc desc;
5058 : : struct i40e_aqc_add_remove_mcast_etag *cmd =
5059 : : (struct i40e_aqc_add_remove_mcast_etag *)&desc.params.raw;
5060 : : struct i40e_aqc_add_remove_mcast_etag_completion *resp =
5061 : : (struct i40e_aqc_add_remove_mcast_etag_completion *)&desc.params.raw;
5062 : : enum i40e_status_code status;
5063 : 0 : u16 length = sizeof(u16) * num_tags_in_buf;
5064 : :
5065 [ # # # # ]: 0 : if ((pv_seid == 0) || (buf == NULL) || (num_tags_in_buf == 0))
5066 : : return I40E_ERR_PARAM;
5067 : :
5068 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
5069 : : i40e_aqc_opc_add_multicast_etag);
5070 : :
5071 : 0 : cmd->pv_seid = CPU_TO_LE16(pv_seid);
5072 : 0 : cmd->etag = CPU_TO_LE16(etag);
5073 : 0 : cmd->num_unicast_etags = num_tags_in_buf;
5074 : :
5075 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5076 : :
5077 : 0 : status = i40e_asq_send_command(hw, &desc, buf, length, cmd_details);
5078 : :
5079 [ # # ]: 0 : if (!status) {
5080 [ # # ]: 0 : if (tags_used != NULL)
5081 : 0 : *tags_used = LE16_TO_CPU(resp->mcast_etags_used);
5082 [ # # ]: 0 : if (tags_free != NULL)
5083 : 0 : *tags_free = LE16_TO_CPU(resp->mcast_etags_free);
5084 : : }
5085 : :
5086 : : return status;
5087 : : }
5088 : :
5089 : : /**
5090 : : * i40e_aq_remove_mcast_etag - Remove a multicast E-tag
5091 : : * @hw: pointer to the hw struct
5092 : : * @pv_seid: Port Virtualizer SEID this M-tag is associated with
5093 : : * @etag: value of the E-tag to remove
5094 : : * @tags_used: return value, number of tags in use by this port
5095 : : * @tags_free: return value, number of unallocated tags
5096 : : * @cmd_details: pointer to command details structure or NULL
5097 : : *
5098 : : * This deletes an E-tag from the port virtualizer. It will return
5099 : : * the number of tags allocated by the port, and the number of unallocated
5100 : : * tags available.
5101 : : **/
5102 : 0 : enum i40e_status_code i40e_aq_remove_mcast_etag(struct i40e_hw *hw, u16 pv_seid,
5103 : : u16 etag, u16 *tags_used, u16 *tags_free,
5104 : : struct i40e_asq_cmd_details *cmd_details)
5105 : : {
5106 : : struct i40e_aq_desc desc;
5107 : : struct i40e_aqc_add_remove_mcast_etag *cmd =
5108 : : (struct i40e_aqc_add_remove_mcast_etag *)&desc.params.raw;
5109 : : struct i40e_aqc_add_remove_mcast_etag_completion *resp =
5110 : : (struct i40e_aqc_add_remove_mcast_etag_completion *)&desc.params.raw;
5111 : : enum i40e_status_code status;
5112 : :
5113 : :
5114 [ # # ]: 0 : if (pv_seid == 0)
5115 : : return I40E_ERR_PARAM;
5116 : :
5117 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
5118 : : i40e_aqc_opc_remove_multicast_etag);
5119 : :
5120 : 0 : cmd->pv_seid = CPU_TO_LE16(pv_seid);
5121 : 0 : cmd->etag = CPU_TO_LE16(etag);
5122 : :
5123 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5124 : :
5125 [ # # ]: 0 : if (!status) {
5126 [ # # ]: 0 : if (tags_used != NULL)
5127 : 0 : *tags_used = LE16_TO_CPU(resp->mcast_etags_used);
5128 [ # # ]: 0 : if (tags_free != NULL)
5129 : 0 : *tags_free = LE16_TO_CPU(resp->mcast_etags_free);
5130 : : }
5131 : :
5132 : : return status;
5133 : : }
5134 : :
5135 : : /**
5136 : : * i40e_aq_update_tag - Update an S/E-tag
5137 : : * @hw: pointer to the hw struct
5138 : : * @vsi_seid: VSI SEID using this S-tag
5139 : : * @old_tag: old tag value
5140 : : * @new_tag: new tag value
5141 : : * @tags_used: return value, number of tags in use by this PF
5142 : : * @tags_free: return value, number of unallocated tags
5143 : : * @cmd_details: pointer to command details structure or NULL
5144 : : *
5145 : : * This updates the value of the tag currently attached to this VSI
5146 : : * in the switch complex. It will return the number of tags allocated
5147 : : * by the PF, and the number of unallocated tags available.
5148 : : **/
5149 : 0 : enum i40e_status_code i40e_aq_update_tag(struct i40e_hw *hw, u16 vsi_seid,
5150 : : u16 old_tag, u16 new_tag, u16 *tags_used,
5151 : : u16 *tags_free,
5152 : : struct i40e_asq_cmd_details *cmd_details)
5153 : : {
5154 : : struct i40e_aq_desc desc;
5155 : : struct i40e_aqc_update_tag *cmd =
5156 : : (struct i40e_aqc_update_tag *)&desc.params.raw;
5157 : : struct i40e_aqc_update_tag_completion *resp =
5158 : : (struct i40e_aqc_update_tag_completion *)&desc.params.raw;
5159 : : enum i40e_status_code status;
5160 : :
5161 [ # # ]: 0 : if (vsi_seid == 0)
5162 : : return I40E_ERR_PARAM;
5163 : :
5164 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_update_tag);
5165 : :
5166 : 0 : cmd->seid = CPU_TO_LE16(vsi_seid);
5167 : 0 : cmd->old_tag = CPU_TO_LE16(old_tag);
5168 : 0 : cmd->new_tag = CPU_TO_LE16(new_tag);
5169 : :
5170 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5171 : :
5172 [ # # ]: 0 : if (!status) {
5173 [ # # ]: 0 : if (tags_used != NULL)
5174 : 0 : *tags_used = LE16_TO_CPU(resp->tags_used);
5175 [ # # ]: 0 : if (tags_free != NULL)
5176 : 0 : *tags_free = LE16_TO_CPU(resp->tags_free);
5177 : : }
5178 : :
5179 : : return status;
5180 : : }
5181 : :
5182 : : /**
5183 : : * i40e_aq_dcb_ignore_pfc - Ignore PFC for given TCs
5184 : : * @hw: pointer to the hw struct
5185 : : * @tcmap: TC map for request/release any ignore PFC condition
5186 : : * @request: request or release ignore PFC condition
5187 : : * @tcmap_ret: return TCs for which PFC is currently ignored
5188 : : * @cmd_details: pointer to command details structure or NULL
5189 : : *
5190 : : * This sends out request/release to ignore PFC condition for a TC.
5191 : : * It will return the TCs for which PFC is currently ignored.
5192 : : **/
5193 : 0 : enum i40e_status_code i40e_aq_dcb_ignore_pfc(struct i40e_hw *hw, u8 tcmap,
5194 : : bool request, u8 *tcmap_ret,
5195 : : struct i40e_asq_cmd_details *cmd_details)
5196 : : {
5197 : : struct i40e_aq_desc desc;
5198 : : struct i40e_aqc_pfc_ignore *cmd_resp =
5199 : : (struct i40e_aqc_pfc_ignore *)&desc.params.raw;
5200 : : enum i40e_status_code status;
5201 : :
5202 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_ignore_pfc);
5203 : :
5204 [ # # ]: 0 : if (request)
5205 : 0 : cmd_resp->command_flags = I40E_AQC_PFC_IGNORE_SET;
5206 : :
5207 : 0 : cmd_resp->tc_bitmap = tcmap;
5208 : :
5209 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5210 : :
5211 [ # # ]: 0 : if (!status) {
5212 [ # # ]: 0 : if (tcmap_ret != NULL)
5213 : 0 : *tcmap_ret = cmd_resp->tc_bitmap;
5214 : : }
5215 : :
5216 : 0 : return status;
5217 : : }
5218 : :
5219 : : /**
5220 : : * i40e_aq_dcb_updated - DCB Updated Command
5221 : : * @hw: pointer to the hw struct
5222 : : * @cmd_details: pointer to command details structure or NULL
5223 : : *
5224 : : * When LLDP is handled in PF this command is used by the PF
5225 : : * to notify EMP that a DCB setting is modified.
5226 : : * When LLDP is handled in EMP this command is used by the PF
5227 : : * to notify EMP whenever one of the following parameters get
5228 : : * modified:
5229 : : * - PFCLinkDelayAllowance in PRTDCB_GENC.PFCLDA
5230 : : * - PCIRTT in PRTDCB_GENC.PCIRTT
5231 : : * - Maximum Frame Size for non-FCoE TCs set by PRTDCB_TDPUC.MAX_TXFRAME.
5232 : : * EMP will return when the shared RPB settings have been
5233 : : * recomputed and modified. The retval field in the descriptor
5234 : : * will be set to 0 when RPB is modified.
5235 : : **/
5236 : 0 : enum i40e_status_code i40e_aq_dcb_updated(struct i40e_hw *hw,
5237 : : struct i40e_asq_cmd_details *cmd_details)
5238 : : {
5239 : : struct i40e_aq_desc desc;
5240 : : enum i40e_status_code status;
5241 : :
5242 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
5243 : :
5244 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5245 : :
5246 : 0 : return status;
5247 : : }
5248 : :
5249 : : /**
5250 : : * i40e_aq_add_statistics - Add a statistics block to a VLAN in a switch.
5251 : : * @hw: pointer to the hw struct
5252 : : * @seid: defines the SEID of the switch for which the stats are requested
5253 : : * @vlan_id: the VLAN ID for which the statistics are requested
5254 : : * @stat_index: index of the statistics counters block assigned to this VLAN
5255 : : * @cmd_details: pointer to command details structure or NULL
5256 : : *
5257 : : * XL710 supports 128 smonVlanStats counters.This command is used to
5258 : : * allocate a set of smonVlanStats counters to a specific VLAN in a specific
5259 : : * switch.
5260 : : **/
5261 : 0 : enum i40e_status_code i40e_aq_add_statistics(struct i40e_hw *hw, u16 seid,
5262 : : u16 vlan_id, u16 *stat_index,
5263 : : struct i40e_asq_cmd_details *cmd_details)
5264 : : {
5265 : : struct i40e_aq_desc desc;
5266 : : struct i40e_aqc_add_remove_statistics *cmd_resp =
5267 : : (struct i40e_aqc_add_remove_statistics *)&desc.params.raw;
5268 : : enum i40e_status_code status;
5269 : :
5270 [ # # ]: 0 : if ((seid == 0) || (stat_index == NULL))
5271 : : return I40E_ERR_PARAM;
5272 : :
5273 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_statistics);
5274 : :
5275 : 0 : cmd_resp->seid = CPU_TO_LE16(seid);
5276 : 0 : cmd_resp->vlan = CPU_TO_LE16(vlan_id);
5277 : :
5278 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5279 : :
5280 [ # # ]: 0 : if (!status && stat_index)
5281 : 0 : *stat_index = LE16_TO_CPU(cmd_resp->stat_index);
5282 : :
5283 : : return status;
5284 : : }
5285 : :
5286 : : /**
5287 : : * i40e_aq_remove_statistics - Remove a statistics block to a VLAN in a switch.
5288 : : * @hw: pointer to the hw struct
5289 : : * @seid: defines the SEID of the switch for which the stats are requested
5290 : : * @vlan_id: the VLAN ID for which the statistics are requested
5291 : : * @stat_index: index of the statistics counters block assigned to this VLAN
5292 : : * @cmd_details: pointer to command details structure or NULL
5293 : : *
5294 : : * XL710 supports 128 smonVlanStats counters.This command is used to
5295 : : * deallocate a set of smonVlanStats counters to a specific VLAN in a specific
5296 : : * switch.
5297 : : **/
5298 : 0 : enum i40e_status_code i40e_aq_remove_statistics(struct i40e_hw *hw, u16 seid,
5299 : : u16 vlan_id, u16 stat_index,
5300 : : struct i40e_asq_cmd_details *cmd_details)
5301 : : {
5302 : : struct i40e_aq_desc desc;
5303 : : struct i40e_aqc_add_remove_statistics *cmd =
5304 : : (struct i40e_aqc_add_remove_statistics *)&desc.params.raw;
5305 : : enum i40e_status_code status;
5306 : :
5307 [ # # ]: 0 : if (seid == 0)
5308 : : return I40E_ERR_PARAM;
5309 : :
5310 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
5311 : : i40e_aqc_opc_remove_statistics);
5312 : :
5313 : 0 : cmd->seid = CPU_TO_LE16(seid);
5314 : 0 : cmd->vlan = CPU_TO_LE16(vlan_id);
5315 : 0 : cmd->stat_index = CPU_TO_LE16(stat_index);
5316 : :
5317 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5318 : :
5319 : 0 : return status;
5320 : : }
5321 : :
5322 : : /**
5323 : : * i40e_aq_set_port_parameters - set physical port parameters.
5324 : : * @hw: pointer to the hw struct
5325 : : * @bad_frame_vsi: defines the VSI to which bad frames are forwarded
5326 : : * @save_bad_pac: if set packets with errors are forwarded to the bad frames VSI
5327 : : * @pad_short_pac: if set transmit packets smaller than 60 bytes are padded
5328 : : * @double_vlan: if set double VLAN is enabled
5329 : : * @cmd_details: pointer to command details structure or NULL
5330 : : **/
5331 : 0 : enum i40e_status_code i40e_aq_set_port_parameters(struct i40e_hw *hw,
5332 : : u16 bad_frame_vsi, bool save_bad_pac,
5333 : : bool pad_short_pac, bool double_vlan,
5334 : : struct i40e_asq_cmd_details *cmd_details)
5335 : : {
5336 : : struct i40e_aqc_set_port_parameters *cmd;
5337 : : enum i40e_status_code status;
5338 : : struct i40e_aq_desc desc;
5339 : : u16 command_flags = 0;
5340 : :
5341 : : cmd = (struct i40e_aqc_set_port_parameters *)&desc.params.raw;
5342 : :
5343 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
5344 : : i40e_aqc_opc_set_port_parameters);
5345 : :
5346 : 0 : cmd->bad_frame_vsi = CPU_TO_LE16(bad_frame_vsi);
5347 [ # # ]: 0 : if (save_bad_pac)
5348 : : command_flags |= I40E_AQ_SET_P_PARAMS_SAVE_BAD_PACKETS;
5349 [ # # ]: 0 : if (pad_short_pac)
5350 : 0 : command_flags |= I40E_AQ_SET_P_PARAMS_PAD_SHORT_PACKETS;
5351 [ # # ]: 0 : if (double_vlan)
5352 : 0 : command_flags |= I40E_AQ_SET_P_PARAMS_DOUBLE_VLAN_ENA;
5353 : 0 : cmd->command_flags = CPU_TO_LE16(command_flags);
5354 : :
5355 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5356 : :
5357 : 0 : return status;
5358 : : }
5359 : :
5360 : : /**
5361 : : * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
5362 : : * @hw: pointer to the hw struct
5363 : : * @seid: seid for the physical port/switching component/vsi
5364 : : * @buff: Indirect buffer to hold data parameters and response
5365 : : * @buff_size: Indirect buffer size
5366 : : * @opcode: Tx scheduler AQ command opcode
5367 : : * @cmd_details: pointer to command details structure or NULL
5368 : : *
5369 : : * Generic command handler for Tx scheduler AQ commands
5370 : : **/
5371 : 0 : static enum i40e_status_code i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
5372 : : void *buff, u16 buff_size,
5373 : : enum i40e_admin_queue_opc opcode,
5374 : : struct i40e_asq_cmd_details *cmd_details)
5375 : : {
5376 : : struct i40e_aq_desc desc;
5377 : : struct i40e_aqc_tx_sched_ind *cmd =
5378 : : (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
5379 : : enum i40e_status_code status;
5380 : : bool cmd_param_flag = false;
5381 : :
5382 [ # # # ]: 0 : switch (opcode) {
5383 : : case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
5384 : : case i40e_aqc_opc_configure_vsi_tc_bw:
5385 : : case i40e_aqc_opc_enable_switching_comp_ets:
5386 : : case i40e_aqc_opc_modify_switching_comp_ets:
5387 : : case i40e_aqc_opc_disable_switching_comp_ets:
5388 : : case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
5389 : : case i40e_aqc_opc_configure_switching_comp_bw_config:
5390 : : cmd_param_flag = true;
5391 : : break;
5392 : 0 : case i40e_aqc_opc_query_vsi_bw_config:
5393 : : case i40e_aqc_opc_query_vsi_ets_sla_config:
5394 : : case i40e_aqc_opc_query_switching_comp_ets_config:
5395 : : case i40e_aqc_opc_query_port_ets_config:
5396 : : case i40e_aqc_opc_query_switching_comp_bw_config:
5397 : : cmd_param_flag = false;
5398 : 0 : break;
5399 : : default:
5400 : : return I40E_ERR_PARAM;
5401 : : }
5402 : :
5403 : 0 : i40e_fill_default_direct_cmd_desc(&desc, opcode);
5404 : :
5405 : : /* Indirect command */
5406 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
5407 [ # # ]: 0 : if (cmd_param_flag)
5408 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
5409 [ # # ]: 0 : if (buff_size > I40E_AQ_LARGE_BUF)
5410 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
5411 : :
5412 : 0 : desc.datalen = CPU_TO_LE16(buff_size);
5413 : :
5414 : 0 : cmd->vsi_seid = CPU_TO_LE16(seid);
5415 : :
5416 : 0 : status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
5417 : :
5418 : 0 : return status;
5419 : : }
5420 : :
5421 : : /**
5422 : : * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
5423 : : * @hw: pointer to the hw struct
5424 : : * @seid: VSI seid
5425 : : * @credit: BW limit credits (0 = disabled)
5426 : : * @max_credit: Max BW limit credits
5427 : : * @cmd_details: pointer to command details structure or NULL
5428 : : **/
5429 : 0 : enum i40e_status_code i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
5430 : : u16 seid, u16 credit, u8 max_credit,
5431 : : struct i40e_asq_cmd_details *cmd_details)
5432 : : {
5433 : : struct i40e_aq_desc desc;
5434 : : struct i40e_aqc_configure_vsi_bw_limit *cmd =
5435 : : (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
5436 : : enum i40e_status_code status;
5437 : :
5438 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
5439 : : i40e_aqc_opc_configure_vsi_bw_limit);
5440 : :
5441 : 0 : cmd->vsi_seid = CPU_TO_LE16(seid);
5442 : 0 : cmd->credit = CPU_TO_LE16(credit);
5443 : 0 : cmd->max_credit = max_credit;
5444 : :
5445 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5446 : :
5447 : 0 : return status;
5448 : : }
5449 : :
5450 : : /**
5451 : : * i40e_aq_config_switch_comp_bw_limit - Configure Switching component BW Limit
5452 : : * @hw: pointer to the hw struct
5453 : : * @seid: switching component seid
5454 : : * @credit: BW limit credits (0 = disabled)
5455 : : * @max_bw: Max BW limit credits
5456 : : * @cmd_details: pointer to command details structure or NULL
5457 : : **/
5458 : 0 : enum i40e_status_code i40e_aq_config_switch_comp_bw_limit(struct i40e_hw *hw,
5459 : : u16 seid, u16 credit, u8 max_bw,
5460 : : struct i40e_asq_cmd_details *cmd_details)
5461 : : {
5462 : : struct i40e_aq_desc desc;
5463 : : struct i40e_aqc_configure_switching_comp_bw_limit *cmd =
5464 : : (struct i40e_aqc_configure_switching_comp_bw_limit *)&desc.params.raw;
5465 : : enum i40e_status_code status;
5466 : :
5467 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
5468 : : i40e_aqc_opc_configure_switching_comp_bw_limit);
5469 : :
5470 : 0 : cmd->seid = CPU_TO_LE16(seid);
5471 : 0 : cmd->credit = CPU_TO_LE16(credit);
5472 : 0 : cmd->max_bw = max_bw;
5473 : :
5474 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5475 : :
5476 : 0 : return status;
5477 : : }
5478 : :
5479 : : /**
5480 : : * i40e_aq_config_vsi_ets_sla_bw_limit - Config VSI BW Limit per TC
5481 : : * @hw: pointer to the hw struct
5482 : : * @seid: VSI seid
5483 : : * @bw_data: Buffer holding enabled TCs, per TC BW limit/credits
5484 : : * @cmd_details: pointer to command details structure or NULL
5485 : : **/
5486 : 0 : enum i40e_status_code i40e_aq_config_vsi_ets_sla_bw_limit(struct i40e_hw *hw,
5487 : : u16 seid,
5488 : : struct i40e_aqc_configure_vsi_ets_sla_bw_data *bw_data,
5489 : : struct i40e_asq_cmd_details *cmd_details)
5490 : : {
5491 : 0 : return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
5492 : : i40e_aqc_opc_configure_vsi_ets_sla_bw_limit,
5493 : : cmd_details);
5494 : : }
5495 : :
5496 : : /**
5497 : : * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
5498 : : * @hw: pointer to the hw struct
5499 : : * @seid: VSI seid
5500 : : * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
5501 : : * @cmd_details: pointer to command details structure or NULL
5502 : : **/
5503 : 0 : enum i40e_status_code i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
5504 : : u16 seid,
5505 : : struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
5506 : : struct i40e_asq_cmd_details *cmd_details)
5507 : : {
5508 : 0 : return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
5509 : : i40e_aqc_opc_configure_vsi_tc_bw,
5510 : : cmd_details);
5511 : : }
5512 : :
5513 : : /**
5514 : : * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
5515 : : * @hw: pointer to the hw struct
5516 : : * @seid: seid of the switching component connected to Physical Port
5517 : : * @ets_data: Buffer holding ETS parameters
5518 : : * @opcode: Tx scheduler AQ command opcode
5519 : : * @cmd_details: pointer to command details structure or NULL
5520 : : **/
5521 : 0 : enum i40e_status_code i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
5522 : : u16 seid,
5523 : : struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
5524 : : enum i40e_admin_queue_opc opcode,
5525 : : struct i40e_asq_cmd_details *cmd_details)
5526 : : {
5527 : 0 : return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
5528 : : sizeof(*ets_data), opcode, cmd_details);
5529 : : }
5530 : :
5531 : : /**
5532 : : * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
5533 : : * @hw: pointer to the hw struct
5534 : : * @seid: seid of the switching component
5535 : : * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
5536 : : * @cmd_details: pointer to command details structure or NULL
5537 : : **/
5538 : 0 : enum i40e_status_code i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
5539 : : u16 seid,
5540 : : struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
5541 : : struct i40e_asq_cmd_details *cmd_details)
5542 : : {
5543 : 0 : return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
5544 : : i40e_aqc_opc_configure_switching_comp_bw_config,
5545 : : cmd_details);
5546 : : }
5547 : :
5548 : : /**
5549 : : * i40e_aq_config_switch_comp_ets_bw_limit - Config Switch comp BW Limit per TC
5550 : : * @hw: pointer to the hw struct
5551 : : * @seid: seid of the switching component
5552 : : * @bw_data: Buffer holding enabled TCs, per TC BW limit/credits
5553 : : * @cmd_details: pointer to command details structure or NULL
5554 : : **/
5555 : 0 : enum i40e_status_code i40e_aq_config_switch_comp_ets_bw_limit(
5556 : : struct i40e_hw *hw, u16 seid,
5557 : : struct i40e_aqc_configure_switching_comp_ets_bw_limit_data *bw_data,
5558 : : struct i40e_asq_cmd_details *cmd_details)
5559 : : {
5560 : 0 : return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
5561 : : i40e_aqc_opc_configure_switching_comp_ets_bw_limit,
5562 : : cmd_details);
5563 : : }
5564 : :
5565 : : /**
5566 : : * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
5567 : : * @hw: pointer to the hw struct
5568 : : * @seid: seid of the VSI
5569 : : * @bw_data: Buffer to hold VSI BW configuration
5570 : : * @cmd_details: pointer to command details structure or NULL
5571 : : **/
5572 : 0 : enum i40e_status_code i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
5573 : : u16 seid,
5574 : : struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
5575 : : struct i40e_asq_cmd_details *cmd_details)
5576 : : {
5577 : 0 : return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
5578 : : i40e_aqc_opc_query_vsi_bw_config,
5579 : : cmd_details);
5580 : : }
5581 : :
5582 : : /**
5583 : : * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
5584 : : * @hw: pointer to the hw struct
5585 : : * @seid: seid of the VSI
5586 : : * @bw_data: Buffer to hold VSI BW configuration per TC
5587 : : * @cmd_details: pointer to command details structure or NULL
5588 : : **/
5589 : 0 : enum i40e_status_code i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
5590 : : u16 seid,
5591 : : struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
5592 : : struct i40e_asq_cmd_details *cmd_details)
5593 : : {
5594 : 0 : return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
5595 : : i40e_aqc_opc_query_vsi_ets_sla_config,
5596 : : cmd_details);
5597 : : }
5598 : :
5599 : : /**
5600 : : * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
5601 : : * @hw: pointer to the hw struct
5602 : : * @seid: seid of the switching component
5603 : : * @bw_data: Buffer to hold switching component's per TC BW config
5604 : : * @cmd_details: pointer to command details structure or NULL
5605 : : **/
5606 : 0 : enum i40e_status_code i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
5607 : : u16 seid,
5608 : : struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
5609 : : struct i40e_asq_cmd_details *cmd_details)
5610 : : {
5611 : 0 : return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
5612 : : i40e_aqc_opc_query_switching_comp_ets_config,
5613 : : cmd_details);
5614 : : }
5615 : :
5616 : : /**
5617 : : * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
5618 : : * @hw: pointer to the hw struct
5619 : : * @seid: seid of the VSI or switching component connected to Physical Port
5620 : : * @bw_data: Buffer to hold current ETS configuration for the Physical Port
5621 : : * @cmd_details: pointer to command details structure or NULL
5622 : : **/
5623 : 0 : enum i40e_status_code i40e_aq_query_port_ets_config(struct i40e_hw *hw,
5624 : : u16 seid,
5625 : : struct i40e_aqc_query_port_ets_config_resp *bw_data,
5626 : : struct i40e_asq_cmd_details *cmd_details)
5627 : : {
5628 : 0 : return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
5629 : : i40e_aqc_opc_query_port_ets_config,
5630 : : cmd_details);
5631 : : }
5632 : :
5633 : : /**
5634 : : * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
5635 : : * @hw: pointer to the hw struct
5636 : : * @seid: seid of the switching component
5637 : : * @bw_data: Buffer to hold switching component's BW configuration
5638 : : * @cmd_details: pointer to command details structure or NULL
5639 : : **/
5640 : 0 : enum i40e_status_code i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
5641 : : u16 seid,
5642 : : struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
5643 : : struct i40e_asq_cmd_details *cmd_details)
5644 : : {
5645 : 0 : return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
5646 : : i40e_aqc_opc_query_switching_comp_bw_config,
5647 : : cmd_details);
5648 : : }
5649 : :
5650 : : /**
5651 : : * i40e_validate_filter_settings
5652 : : * @hw: pointer to the hardware structure
5653 : : * @settings: Filter control settings
5654 : : *
5655 : : * Check and validate the filter control settings passed.
5656 : : * The function checks for the valid filter/context sizes being
5657 : : * passed for FCoE and PE.
5658 : : *
5659 : : * Returns I40E_SUCCESS if the values passed are valid and within
5660 : : * range else returns an error.
5661 : : **/
5662 : 0 : STATIC enum i40e_status_code i40e_validate_filter_settings(struct i40e_hw *hw,
5663 : : struct i40e_filter_control_settings *settings)
5664 : : {
5665 : : u32 fcoe_cntx_size, fcoe_filt_size;
5666 : : u32 pe_cntx_size, pe_filt_size;
5667 : : u32 fcoe_fmax;
5668 : :
5669 : : u32 val;
5670 : :
5671 : : /* Validate FCoE settings passed */
5672 [ # # ]: 0 : switch (settings->fcoe_filt_num) {
5673 : 0 : case I40E_HASH_FILTER_SIZE_1K:
5674 : : case I40E_HASH_FILTER_SIZE_2K:
5675 : : case I40E_HASH_FILTER_SIZE_4K:
5676 : : case I40E_HASH_FILTER_SIZE_8K:
5677 : : case I40E_HASH_FILTER_SIZE_16K:
5678 : : case I40E_HASH_FILTER_SIZE_32K:
5679 : : fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
5680 : 0 : fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
5681 : : break;
5682 : : default:
5683 : : return I40E_ERR_PARAM;
5684 : : }
5685 : :
5686 [ # # ]: 0 : switch (settings->fcoe_cntx_num) {
5687 : 0 : case I40E_DMA_CNTX_SIZE_512:
5688 : : case I40E_DMA_CNTX_SIZE_1K:
5689 : : case I40E_DMA_CNTX_SIZE_2K:
5690 : : case I40E_DMA_CNTX_SIZE_4K:
5691 : : fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
5692 : 0 : fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
5693 : : break;
5694 : : default:
5695 : : return I40E_ERR_PARAM;
5696 : : }
5697 : :
5698 : : /* Validate PE settings passed */
5699 [ # # ]: 0 : switch (settings->pe_filt_num) {
5700 : 0 : case I40E_HASH_FILTER_SIZE_1K:
5701 : : case I40E_HASH_FILTER_SIZE_2K:
5702 : : case I40E_HASH_FILTER_SIZE_4K:
5703 : : case I40E_HASH_FILTER_SIZE_8K:
5704 : : case I40E_HASH_FILTER_SIZE_16K:
5705 : : case I40E_HASH_FILTER_SIZE_32K:
5706 : : case I40E_HASH_FILTER_SIZE_64K:
5707 : : case I40E_HASH_FILTER_SIZE_128K:
5708 : : case I40E_HASH_FILTER_SIZE_256K:
5709 : : case I40E_HASH_FILTER_SIZE_512K:
5710 : : case I40E_HASH_FILTER_SIZE_1M:
5711 : : pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
5712 : : pe_filt_size <<= (u32)settings->pe_filt_num;
5713 : : break;
5714 : : default:
5715 : : return I40E_ERR_PARAM;
5716 : : }
5717 : :
5718 [ # # ]: 0 : switch (settings->pe_cntx_num) {
5719 : 0 : case I40E_DMA_CNTX_SIZE_512:
5720 : : case I40E_DMA_CNTX_SIZE_1K:
5721 : : case I40E_DMA_CNTX_SIZE_2K:
5722 : : case I40E_DMA_CNTX_SIZE_4K:
5723 : : case I40E_DMA_CNTX_SIZE_8K:
5724 : : case I40E_DMA_CNTX_SIZE_16K:
5725 : : case I40E_DMA_CNTX_SIZE_32K:
5726 : : case I40E_DMA_CNTX_SIZE_64K:
5727 : : case I40E_DMA_CNTX_SIZE_128K:
5728 : : case I40E_DMA_CNTX_SIZE_256K:
5729 : : pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
5730 : : pe_cntx_size <<= (u32)settings->pe_cntx_num;
5731 : : break;
5732 : : default:
5733 : : return I40E_ERR_PARAM;
5734 : : }
5735 : :
5736 : : /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
5737 : 0 : val = rd32(hw, I40E_GLHMC_FCOEFMAX);
5738 : 0 : fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
5739 : : >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
5740 [ # # ]: 0 : if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
5741 : 0 : return I40E_ERR_INVALID_SIZE;
5742 : :
5743 : : return I40E_SUCCESS;
5744 : : }
5745 : :
5746 : : /**
5747 : : * i40e_set_filter_control
5748 : : * @hw: pointer to the hardware structure
5749 : : * @settings: Filter control settings
5750 : : *
5751 : : * Set the Queue Filters for PE/FCoE and enable filters required
5752 : : * for a single PF. It is expected that these settings are programmed
5753 : : * at the driver initialization time.
5754 : : **/
5755 : 0 : enum i40e_status_code i40e_set_filter_control(struct i40e_hw *hw,
5756 : : struct i40e_filter_control_settings *settings)
5757 : : {
5758 : : enum i40e_status_code ret = I40E_SUCCESS;
5759 : : u32 hash_lut_size = 0;
5760 : : u32 val;
5761 : :
5762 [ # # ]: 0 : if (!settings)
5763 : : return I40E_ERR_PARAM;
5764 : :
5765 : : /* Validate the input settings */
5766 : 0 : ret = i40e_validate_filter_settings(hw, settings);
5767 [ # # ]: 0 : if (ret)
5768 : : return ret;
5769 : :
5770 : : /* Read the PF Queue Filter control register */
5771 : 0 : val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
5772 : :
5773 : : /* Program required PE hash buckets for the PF */
5774 : 0 : val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
5775 : 0 : val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
5776 : : I40E_PFQF_CTL_0_PEHSIZE_MASK;
5777 : : /* Program required PE contexts for the PF */
5778 : 0 : val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
5779 : 0 : val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
5780 : : I40E_PFQF_CTL_0_PEDSIZE_MASK;
5781 : :
5782 : : /* Program required FCoE hash buckets for the PF */
5783 : 0 : val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
5784 : 0 : val |= ((u32)settings->fcoe_filt_num <<
5785 : 0 : I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
5786 : : I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
5787 : : /* Program required FCoE DDP contexts for the PF */
5788 : 0 : val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
5789 : 0 : val |= ((u32)settings->fcoe_cntx_num <<
5790 : 0 : I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
5791 : : I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
5792 : :
5793 : : /* Program Hash LUT size for the PF */
5794 : 0 : val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
5795 [ # # ]: 0 : if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
5796 : : hash_lut_size = 1;
5797 : 0 : val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
5798 : : I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
5799 : :
5800 : : /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
5801 [ # # ]: 0 : if (settings->enable_fdir)
5802 : 0 : val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
5803 [ # # ]: 0 : if (settings->enable_ethtype)
5804 : 0 : val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
5805 [ # # ]: 0 : if (settings->enable_macvlan)
5806 : 0 : val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
5807 : :
5808 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
5809 : :
5810 : 0 : return I40E_SUCCESS;
5811 : : }
5812 : :
5813 : : /**
5814 : : * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
5815 : : * @hw: pointer to the hw struct
5816 : : * @mac_addr: MAC address to use in the filter
5817 : : * @ethtype: Ethertype to use in the filter
5818 : : * @flags: Flags that needs to be applied to the filter
5819 : : * @vsi_seid: seid of the control VSI
5820 : : * @queue: VSI queue number to send the packet to
5821 : : * @is_add: Add control packet filter if True else remove
5822 : : * @stats: Structure to hold information on control filter counts
5823 : : * @cmd_details: pointer to command details structure or NULL
5824 : : *
5825 : : * This command will Add or Remove control packet filter for a control VSI.
5826 : : * In return it will update the total number of perfect filter count in
5827 : : * the stats member.
5828 : : **/
5829 : 0 : enum i40e_status_code i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
5830 : : u8 *mac_addr, u16 ethtype, u16 flags,
5831 : : u16 vsi_seid, u16 queue, bool is_add,
5832 : : struct i40e_control_filter_stats *stats,
5833 : : struct i40e_asq_cmd_details *cmd_details)
5834 : : {
5835 : : struct i40e_aq_desc desc;
5836 : : struct i40e_aqc_add_remove_control_packet_filter *cmd =
5837 : : (struct i40e_aqc_add_remove_control_packet_filter *)
5838 : : &desc.params.raw;
5839 : : struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
5840 : : (struct i40e_aqc_add_remove_control_packet_filter_completion *)
5841 : : &desc.params.raw;
5842 : : enum i40e_status_code status;
5843 : :
5844 [ # # ]: 0 : if (vsi_seid == 0)
5845 : : return I40E_ERR_PARAM;
5846 : :
5847 [ # # ]: 0 : if (is_add) {
5848 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
5849 : : i40e_aqc_opc_add_control_packet_filter);
5850 : 0 : cmd->queue = CPU_TO_LE16(queue);
5851 : : } else {
5852 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
5853 : : i40e_aqc_opc_remove_control_packet_filter);
5854 : : }
5855 : :
5856 [ # # ]: 0 : if (mac_addr)
5857 : : i40e_memcpy(cmd->mac, mac_addr, ETH_ALEN,
5858 : : I40E_NONDMA_TO_NONDMA);
5859 : :
5860 : 0 : cmd->etype = CPU_TO_LE16(ethtype);
5861 : 0 : cmd->flags = CPU_TO_LE16(flags);
5862 : 0 : cmd->seid = CPU_TO_LE16(vsi_seid);
5863 : :
5864 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
5865 : :
5866 [ # # ]: 0 : if (!status && stats) {
5867 : 0 : stats->mac_etype_used = LE16_TO_CPU(resp->mac_etype_used);
5868 : 0 : stats->etype_used = LE16_TO_CPU(resp->etype_used);
5869 : 0 : stats->mac_etype_free = LE16_TO_CPU(resp->mac_etype_free);
5870 : 0 : stats->etype_free = LE16_TO_CPU(resp->etype_free);
5871 : : }
5872 : :
5873 : : return status;
5874 : : }
5875 : :
5876 : : /**
5877 : : * i40e_add_filter_to_drop_tx_flow_control_frames- filter to drop flow control
5878 : : * @hw: pointer to the hw struct
5879 : : * @seid: VSI seid to add ethertype filter from
5880 : : **/
5881 : 0 : void i40e_add_filter_to_drop_tx_flow_control_frames(struct i40e_hw *hw,
5882 : : u16 seid)
5883 : : {
5884 : : #define I40E_FLOW_CONTROL_ETHTYPE 0x8808
5885 : : u16 flag = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
5886 : : I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
5887 : : I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
5888 : : u16 ethtype = I40E_FLOW_CONTROL_ETHTYPE;
5889 : : enum i40e_status_code status;
5890 : :
5891 : 0 : status = i40e_aq_add_rem_control_packet_filter(hw, NULL, ethtype, flag,
5892 : : seid, 0, true, NULL,
5893 : : NULL);
5894 [ # # ]: 0 : if (status)
5895 : 0 : DEBUGOUT("Ethtype Filter Add failed: Error pruning Tx flow control frames\n");
5896 : 0 : }
5897 : :
5898 : : /**
5899 : : * i40e_fix_up_geneve_vni - adjust Geneve VNI for HW issue
5900 : : * @filters: list of cloud filters
5901 : : * @filter_count: length of list
5902 : : *
5903 : : * There's an issue in the device where the Geneve VNI layout needs
5904 : : * to be shifted 1 byte over from the VxLAN VNI
5905 : : **/
5906 : : STATIC void i40e_fix_up_geneve_vni(
5907 : : struct i40e_aqc_cloud_filters_element_data *filters,
5908 : : u8 filter_count)
5909 : : {
5910 : : struct i40e_aqc_cloud_filters_element_data *f = filters;
5911 : : int i;
5912 : :
5913 [ # # # # ]: 0 : for (i = 0; i < filter_count; i++) {
5914 : : u16 tnl_type;
5915 : : u32 ti;
5916 : :
5917 : 0 : tnl_type = (LE16_TO_CPU(f[i].flags) &
5918 : 0 : I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
5919 : : I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
5920 [ # # # # ]: 0 : if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
5921 : 0 : ti = LE32_TO_CPU(f[i].tenant_id);
5922 : 0 : f[i].tenant_id = CPU_TO_LE32(ti << 8);
5923 : : }
5924 : : }
5925 : : }
5926 : :
5927 : : /**
5928 : : * i40e_aq_add_cloud_filters
5929 : : * @hw: pointer to the hardware structure
5930 : : * @seid: VSI seid to add cloud filters from
5931 : : * @filters: Buffer which contains the filters to be added
5932 : : * @filter_count: number of filters contained in the buffer
5933 : : *
5934 : : * Set the cloud filters for a given VSI. The contents of the
5935 : : * i40e_aqc_cloud_filters_element_data are filled
5936 : : * in by the caller of the function.
5937 : : *
5938 : : **/
5939 : 0 : enum i40e_status_code i40e_aq_add_cloud_filters(struct i40e_hw *hw,
5940 : : u16 seid,
5941 : : struct i40e_aqc_cloud_filters_element_data *filters,
5942 : : u8 filter_count)
5943 : : {
5944 : : struct i40e_aq_desc desc;
5945 : : struct i40e_aqc_add_remove_cloud_filters *cmd =
5946 : : (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5947 : : enum i40e_status_code status;
5948 : : u16 buff_len;
5949 : :
5950 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
5951 : : i40e_aqc_opc_add_cloud_filters);
5952 : :
5953 : 0 : buff_len = filter_count * sizeof(*filters);
5954 : 0 : desc.datalen = CPU_TO_LE16(buff_len);
5955 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5956 : 0 : cmd->num_filters = filter_count;
5957 : 0 : cmd->seid = CPU_TO_LE16(seid);
5958 : :
5959 : 0 : i40e_fix_up_geneve_vni(filters, filter_count);
5960 : :
5961 : 0 : status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
5962 : :
5963 : 0 : return status;
5964 : : }
5965 : :
5966 : : /**
5967 : : * i40e_aq_add_cloud_filters_bb
5968 : : * @hw: pointer to the hardware structure
5969 : : * @seid: VSI seid to add cloud filters from
5970 : : * @filters: Buffer which contains the filters in big buffer to be added
5971 : : * @filter_count: number of filters contained in the buffer
5972 : : *
5973 : : * Set the cloud filters for a given VSI. The contents of the
5974 : : * i40e_aqc_cloud_filters_element_bb are filled in by the caller of
5975 : : * the function.
5976 : : *
5977 : : **/
5978 : : enum i40e_status_code
5979 : 0 : i40e_aq_add_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
5980 : : struct i40e_aqc_cloud_filters_element_bb *filters,
5981 : : u8 filter_count)
5982 : : {
5983 : : struct i40e_aq_desc desc;
5984 : : struct i40e_aqc_add_remove_cloud_filters *cmd =
5985 : : (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
5986 : : enum i40e_status_code status;
5987 : : u16 buff_len;
5988 : : int i;
5989 : :
5990 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
5991 : : i40e_aqc_opc_add_cloud_filters);
5992 : :
5993 : 0 : buff_len = filter_count * sizeof(*filters);
5994 : 0 : desc.datalen = CPU_TO_LE16(buff_len);
5995 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
5996 : 0 : cmd->num_filters = filter_count;
5997 : 0 : cmd->seid = CPU_TO_LE16(seid);
5998 : 0 : cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
5999 : :
6000 [ # # ]: 0 : for (i = 0; i < filter_count; i++) {
6001 : : u16 tnl_type;
6002 : : u32 ti;
6003 : :
6004 : 0 : tnl_type = (LE16_TO_CPU(filters[i].element.flags) &
6005 : 0 : I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
6006 : : I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
6007 : :
6008 : : /* Due to hardware eccentricities, the VNI for Geneve is shifted
6009 : : * one more byte further than normally used for Tenant ID in
6010 : : * other tunnel types.
6011 : : */
6012 [ # # ]: 0 : if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
6013 : 0 : ti = LE32_TO_CPU(filters[i].element.tenant_id);
6014 : 0 : filters[i].element.tenant_id = CPU_TO_LE32(ti << 8);
6015 : : }
6016 : : }
6017 : :
6018 : 0 : status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
6019 : :
6020 : 0 : return status;
6021 : : }
6022 : :
6023 : : /**
6024 : : * i40e_aq_rem_cloud_filters
6025 : : * @hw: pointer to the hardware structure
6026 : : * @seid: VSI seid to remove cloud filters from
6027 : : * @filters: Buffer which contains the filters to be removed
6028 : : * @filter_count: number of filters contained in the buffer
6029 : : *
6030 : : * Remove the cloud filters for a given VSI. The contents of the
6031 : : * i40e_aqc_cloud_filters_element_data are filled in by the caller
6032 : : * of the function.
6033 : : *
6034 : : **/
6035 : : enum i40e_status_code
6036 : 0 : i40e_aq_rem_cloud_filters(struct i40e_hw *hw, u16 seid,
6037 : : struct i40e_aqc_cloud_filters_element_data *filters,
6038 : : u8 filter_count)
6039 : : {
6040 : : struct i40e_aq_desc desc;
6041 : : struct i40e_aqc_add_remove_cloud_filters *cmd =
6042 : : (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
6043 : : enum i40e_status_code status;
6044 : : u16 buff_len;
6045 : :
6046 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
6047 : : i40e_aqc_opc_remove_cloud_filters);
6048 : :
6049 : 0 : buff_len = filter_count * sizeof(*filters);
6050 : 0 : desc.datalen = CPU_TO_LE16(buff_len);
6051 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
6052 : 0 : cmd->num_filters = filter_count;
6053 : 0 : cmd->seid = CPU_TO_LE16(seid);
6054 : :
6055 : 0 : i40e_fix_up_geneve_vni(filters, filter_count);
6056 : :
6057 : 0 : status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
6058 : :
6059 : 0 : return status;
6060 : : }
6061 : :
6062 : : /**
6063 : : * i40e_aq_rem_cloud_filters_bb
6064 : : * @hw: pointer to the hardware structure
6065 : : * @seid: VSI seid to remove cloud filters from
6066 : : * @filters: Buffer which contains the filters in big buffer to be removed
6067 : : * @filter_count: number of filters contained in the buffer
6068 : : *
6069 : : * Remove the big buffer cloud filters for a given VSI. The contents of the
6070 : : * i40e_aqc_cloud_filters_element_bb are filled in by the caller of the
6071 : : * function.
6072 : : *
6073 : : **/
6074 : : enum i40e_status_code
6075 : 0 : i40e_aq_rem_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
6076 : : struct i40e_aqc_cloud_filters_element_bb *filters,
6077 : : u8 filter_count)
6078 : : {
6079 : : struct i40e_aq_desc desc;
6080 : : struct i40e_aqc_add_remove_cloud_filters *cmd =
6081 : : (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
6082 : : enum i40e_status_code status;
6083 : : u16 buff_len;
6084 : : int i;
6085 : :
6086 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
6087 : : i40e_aqc_opc_remove_cloud_filters);
6088 : :
6089 : 0 : buff_len = filter_count * sizeof(*filters);
6090 : 0 : desc.datalen = CPU_TO_LE16(buff_len);
6091 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
6092 : 0 : cmd->num_filters = filter_count;
6093 : 0 : cmd->seid = CPU_TO_LE16(seid);
6094 : 0 : cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
6095 : :
6096 [ # # ]: 0 : for (i = 0; i < filter_count; i++) {
6097 : : u16 tnl_type;
6098 : : u32 ti;
6099 : :
6100 : 0 : tnl_type = (LE16_TO_CPU(filters[i].element.flags) &
6101 : 0 : I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
6102 : : I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
6103 : :
6104 : : /* Due to hardware eccentricities, the VNI for Geneve is shifted
6105 : : * one more byte further than normally used for Tenant ID in
6106 : : * other tunnel types.
6107 : : */
6108 [ # # ]: 0 : if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
6109 : 0 : ti = LE32_TO_CPU(filters[i].element.tenant_id);
6110 : 0 : filters[i].element.tenant_id = CPU_TO_LE32(ti << 8);
6111 : : }
6112 : : }
6113 : :
6114 : 0 : status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
6115 : :
6116 : 0 : return status;
6117 : : }
6118 : :
6119 : : /**
6120 : : * i40e_aq_replace_cloud_filters - Replace cloud filter command
6121 : : * @hw: pointer to the hw struct
6122 : : * @filters: pointer to the i40e_aqc_replace_cloud_filter_cmd struct
6123 : : * @cmd_buf: pointer to the i40e_aqc_replace_cloud_filter_cmd_buf struct
6124 : : *
6125 : : **/
6126 : : enum
6127 : 0 : i40e_status_code i40e_aq_replace_cloud_filters(struct i40e_hw *hw,
6128 : : struct i40e_aqc_replace_cloud_filters_cmd *filters,
6129 : : struct i40e_aqc_replace_cloud_filters_cmd_buf *cmd_buf)
6130 : : {
6131 : : struct i40e_aq_desc desc;
6132 : : struct i40e_aqc_replace_cloud_filters_cmd *cmd =
6133 : : (struct i40e_aqc_replace_cloud_filters_cmd *)&desc.params.raw;
6134 : : enum i40e_status_code status = I40E_SUCCESS;
6135 : : int i = 0;
6136 : :
6137 : : /* X722 doesn't support this command */
6138 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
6139 : : return I40E_ERR_DEVICE_NOT_SUPPORTED;
6140 : :
6141 : : /* need FW version greater than 6.00 */
6142 [ # # ]: 0 : if (hw->aq.fw_maj_ver < 6)
6143 : : return I40E_NOT_SUPPORTED;
6144 : :
6145 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
6146 : : i40e_aqc_opc_replace_cloud_filters);
6147 : :
6148 : 0 : desc.datalen = CPU_TO_LE16(32);
6149 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
6150 : 0 : cmd->old_filter_type = filters->old_filter_type;
6151 : 0 : cmd->new_filter_type = filters->new_filter_type;
6152 : 0 : cmd->valid_flags = filters->valid_flags;
6153 : 0 : cmd->tr_bit = filters->tr_bit;
6154 : 0 : cmd->tr_bit2 = filters->tr_bit2;
6155 : :
6156 : 0 : status = i40e_asq_send_command(hw, &desc, cmd_buf,
6157 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf), NULL);
6158 : :
6159 : : /* for get cloud filters command */
6160 [ # # ]: 0 : for (i = 0; i < 32; i += 4) {
6161 : 0 : cmd_buf->filters[i / 4].filter_type = cmd_buf->data[i];
6162 : 0 : cmd_buf->filters[i / 4].input[0] = cmd_buf->data[i + 1];
6163 : 0 : cmd_buf->filters[i / 4].input[1] = cmd_buf->data[i + 2];
6164 : 0 : cmd_buf->filters[i / 4].input[2] = cmd_buf->data[i + 3];
6165 : : }
6166 : :
6167 : : return status;
6168 : : }
6169 : :
6170 : :
6171 : : /**
6172 : : * i40e_aq_alternate_write
6173 : : * @hw: pointer to the hardware structure
6174 : : * @reg_addr0: address of first dword to be read
6175 : : * @reg_val0: value to be written under 'reg_addr0'
6176 : : * @reg_addr1: address of second dword to be read
6177 : : * @reg_val1: value to be written under 'reg_addr1'
6178 : : *
6179 : : * Write one or two dwords to alternate structure. Fields are indicated
6180 : : * by 'reg_addr0' and 'reg_addr1' register numbers.
6181 : : *
6182 : : **/
6183 : 0 : enum i40e_status_code i40e_aq_alternate_write(struct i40e_hw *hw,
6184 : : u32 reg_addr0, u32 reg_val0,
6185 : : u32 reg_addr1, u32 reg_val1)
6186 : : {
6187 : : struct i40e_aq_desc desc;
6188 : : struct i40e_aqc_alternate_write *cmd_resp =
6189 : : (struct i40e_aqc_alternate_write *)&desc.params.raw;
6190 : : enum i40e_status_code status;
6191 : :
6192 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_write);
6193 : 0 : cmd_resp->address0 = CPU_TO_LE32(reg_addr0);
6194 : 0 : cmd_resp->address1 = CPU_TO_LE32(reg_addr1);
6195 : 0 : cmd_resp->data0 = CPU_TO_LE32(reg_val0);
6196 : 0 : cmd_resp->data1 = CPU_TO_LE32(reg_val1);
6197 : :
6198 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
6199 : :
6200 : 0 : return status;
6201 : : }
6202 : :
6203 : : /**
6204 : : * i40e_aq_alternate_write_indirect
6205 : : * @hw: pointer to the hardware structure
6206 : : * @addr: address of a first register to be modified
6207 : : * @dw_count: number of alternate structure fields to write
6208 : : * @buffer: pointer to the command buffer
6209 : : *
6210 : : * Write 'dw_count' dwords from 'buffer' to alternate structure
6211 : : * starting at 'addr'.
6212 : : *
6213 : : **/
6214 : 0 : enum i40e_status_code i40e_aq_alternate_write_indirect(struct i40e_hw *hw,
6215 : : u32 addr, u32 dw_count, void *buffer)
6216 : : {
6217 : : struct i40e_aq_desc desc;
6218 : : struct i40e_aqc_alternate_ind_write *cmd_resp =
6219 : : (struct i40e_aqc_alternate_ind_write *)&desc.params.raw;
6220 : : enum i40e_status_code status;
6221 : :
6222 [ # # ]: 0 : if (buffer == NULL)
6223 : : return I40E_ERR_PARAM;
6224 : :
6225 : : /* Indirect command */
6226 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
6227 : : i40e_aqc_opc_alternate_write_indirect);
6228 : :
6229 : 0 : desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_RD);
6230 : 0 : desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_BUF);
6231 [ # # ]: 0 : if (dw_count > (I40E_AQ_LARGE_BUF/4))
6232 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
6233 : :
6234 : 0 : cmd_resp->address = CPU_TO_LE32(addr);
6235 : 0 : cmd_resp->length = CPU_TO_LE32(dw_count);
6236 : :
6237 : 0 : status = i40e_asq_send_command(hw, &desc, buffer,
6238 : : I40E_LO_DWORD(4*dw_count), NULL);
6239 : :
6240 : 0 : return status;
6241 : : }
6242 : :
6243 : : /**
6244 : : * i40e_aq_alternate_read
6245 : : * @hw: pointer to the hardware structure
6246 : : * @reg_addr0: address of first dword to be read
6247 : : * @reg_val0: pointer for data read from 'reg_addr0'
6248 : : * @reg_addr1: address of second dword to be read
6249 : : * @reg_val1: pointer for data read from 'reg_addr1'
6250 : : *
6251 : : * Read one or two dwords from alternate structure. Fields are indicated
6252 : : * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
6253 : : * is not passed then only register at 'reg_addr0' is read.
6254 : : *
6255 : : **/
6256 : 0 : enum i40e_status_code i40e_aq_alternate_read(struct i40e_hw *hw,
6257 : : u32 reg_addr0, u32 *reg_val0,
6258 : : u32 reg_addr1, u32 *reg_val1)
6259 : : {
6260 : : struct i40e_aq_desc desc;
6261 : : struct i40e_aqc_alternate_write *cmd_resp =
6262 : : (struct i40e_aqc_alternate_write *)&desc.params.raw;
6263 : : enum i40e_status_code status;
6264 : :
6265 [ # # ]: 0 : if (reg_val0 == NULL)
6266 : : return I40E_ERR_PARAM;
6267 : :
6268 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
6269 : 0 : cmd_resp->address0 = CPU_TO_LE32(reg_addr0);
6270 : 0 : cmd_resp->address1 = CPU_TO_LE32(reg_addr1);
6271 : :
6272 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
6273 : :
6274 [ # # ]: 0 : if (status == I40E_SUCCESS) {
6275 : 0 : *reg_val0 = LE32_TO_CPU(cmd_resp->data0);
6276 : :
6277 [ # # ]: 0 : if (reg_val1 != NULL)
6278 : 0 : *reg_val1 = LE32_TO_CPU(cmd_resp->data1);
6279 : : }
6280 : :
6281 : : return status;
6282 : : }
6283 : :
6284 : : /**
6285 : : * i40e_aq_alternate_read_indirect
6286 : : * @hw: pointer to the hardware structure
6287 : : * @addr: address of the alternate structure field
6288 : : * @dw_count: number of alternate structure fields to read
6289 : : * @buffer: pointer to the command buffer
6290 : : *
6291 : : * Read 'dw_count' dwords from alternate structure starting at 'addr' and
6292 : : * place them in 'buffer'. The buffer should be allocated by caller.
6293 : : *
6294 : : **/
6295 : 0 : enum i40e_status_code i40e_aq_alternate_read_indirect(struct i40e_hw *hw,
6296 : : u32 addr, u32 dw_count, void *buffer)
6297 : : {
6298 : : struct i40e_aq_desc desc;
6299 : : struct i40e_aqc_alternate_ind_write *cmd_resp =
6300 : : (struct i40e_aqc_alternate_ind_write *)&desc.params.raw;
6301 : : enum i40e_status_code status;
6302 : :
6303 [ # # ]: 0 : if (buffer == NULL)
6304 : : return I40E_ERR_PARAM;
6305 : :
6306 : : /* Indirect command */
6307 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
6308 : : i40e_aqc_opc_alternate_read_indirect);
6309 : :
6310 : 0 : desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_RD);
6311 : 0 : desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_BUF);
6312 [ # # ]: 0 : if (dw_count > (I40E_AQ_LARGE_BUF/4))
6313 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
6314 : :
6315 : 0 : cmd_resp->address = CPU_TO_LE32(addr);
6316 : 0 : cmd_resp->length = CPU_TO_LE32(dw_count);
6317 : :
6318 : 0 : status = i40e_asq_send_command(hw, &desc, buffer,
6319 : : I40E_LO_DWORD(4*dw_count), NULL);
6320 : :
6321 : 0 : return status;
6322 : : }
6323 : :
6324 : : /**
6325 : : * i40e_aq_alternate_clear
6326 : : * @hw: pointer to the HW structure.
6327 : : *
6328 : : * Clear the alternate structures of the port from which the function
6329 : : * is called.
6330 : : *
6331 : : **/
6332 : 0 : enum i40e_status_code i40e_aq_alternate_clear(struct i40e_hw *hw)
6333 : : {
6334 : : struct i40e_aq_desc desc;
6335 : : enum i40e_status_code status;
6336 : :
6337 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
6338 : : i40e_aqc_opc_alternate_clear_port);
6339 : :
6340 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
6341 : :
6342 : 0 : return status;
6343 : : }
6344 : :
6345 : : /**
6346 : : * i40e_aq_alternate_write_done
6347 : : * @hw: pointer to the HW structure.
6348 : : * @bios_mode: indicates whether the command is executed by UEFI or legacy BIOS
6349 : : * @reset_needed: indicates the SW should trigger GLOBAL reset
6350 : : *
6351 : : * Indicates to the FW that alternate structures have been changed.
6352 : : *
6353 : : **/
6354 : 0 : enum i40e_status_code i40e_aq_alternate_write_done(struct i40e_hw *hw,
6355 : : u8 bios_mode, bool *reset_needed)
6356 : : {
6357 : : struct i40e_aq_desc desc;
6358 : : struct i40e_aqc_alternate_write_done *cmd =
6359 : : (struct i40e_aqc_alternate_write_done *)&desc.params.raw;
6360 : : enum i40e_status_code status;
6361 : :
6362 [ # # ]: 0 : if (reset_needed == NULL)
6363 : : return I40E_ERR_PARAM;
6364 : :
6365 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
6366 : : i40e_aqc_opc_alternate_write_done);
6367 : :
6368 : 0 : cmd->cmd_flags = CPU_TO_LE16(bios_mode);
6369 : :
6370 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
6371 [ # # ]: 0 : if (!status && reset_needed)
6372 : 0 : *reset_needed = ((LE16_TO_CPU(cmd->cmd_flags) &
6373 : 0 : I40E_AQ_ALTERNATE_RESET_NEEDED) != 0);
6374 : :
6375 : : return status;
6376 : : }
6377 : :
6378 : : /**
6379 : : * i40e_aq_set_oem_mode
6380 : : * @hw: pointer to the HW structure.
6381 : : * @oem_mode: the OEM mode to be used
6382 : : *
6383 : : * Sets the device to a specific operating mode. Currently the only supported
6384 : : * mode is no_clp, which causes FW to refrain from using Alternate RAM.
6385 : : *
6386 : : **/
6387 : 0 : enum i40e_status_code i40e_aq_set_oem_mode(struct i40e_hw *hw,
6388 : : u8 oem_mode)
6389 : : {
6390 : : struct i40e_aq_desc desc;
6391 : : struct i40e_aqc_alternate_write_done *cmd =
6392 : : (struct i40e_aqc_alternate_write_done *)&desc.params.raw;
6393 : : enum i40e_status_code status;
6394 : :
6395 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
6396 : : i40e_aqc_opc_alternate_set_mode);
6397 : :
6398 : 0 : cmd->cmd_flags = CPU_TO_LE16(oem_mode);
6399 : :
6400 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
6401 : :
6402 : 0 : return status;
6403 : : }
6404 : :
6405 : : /**
6406 : : * i40e_aq_resume_port_tx
6407 : : * @hw: pointer to the hardware structure
6408 : : * @cmd_details: pointer to command details structure or NULL
6409 : : *
6410 : : * Resume port's Tx traffic
6411 : : **/
6412 : 0 : enum i40e_status_code i40e_aq_resume_port_tx(struct i40e_hw *hw,
6413 : : struct i40e_asq_cmd_details *cmd_details)
6414 : : {
6415 : : struct i40e_aq_desc desc;
6416 : : enum i40e_status_code status;
6417 : :
6418 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
6419 : :
6420 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
6421 : :
6422 : 0 : return status;
6423 : : }
6424 : :
6425 : : /**
6426 : : * i40e_set_pci_config_data - store PCI bus info
6427 : : * @hw: pointer to hardware structure
6428 : : * @link_status: the link status word from PCI config space
6429 : : *
6430 : : * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
6431 : : **/
6432 : 0 : void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
6433 : : {
6434 : 0 : hw->bus.type = i40e_bus_type_pci_express;
6435 : :
6436 [ # # # # : 0 : switch (link_status & I40E_PCI_LINK_WIDTH) {
# ]
6437 : 0 : case I40E_PCI_LINK_WIDTH_1:
6438 : 0 : hw->bus.width = i40e_bus_width_pcie_x1;
6439 : 0 : break;
6440 : 0 : case I40E_PCI_LINK_WIDTH_2:
6441 : 0 : hw->bus.width = i40e_bus_width_pcie_x2;
6442 : 0 : break;
6443 : 0 : case I40E_PCI_LINK_WIDTH_4:
6444 : 0 : hw->bus.width = i40e_bus_width_pcie_x4;
6445 : 0 : break;
6446 : 0 : case I40E_PCI_LINK_WIDTH_8:
6447 : 0 : hw->bus.width = i40e_bus_width_pcie_x8;
6448 : 0 : break;
6449 : 0 : default:
6450 : 0 : hw->bus.width = i40e_bus_width_unknown;
6451 : 0 : break;
6452 : : }
6453 : :
6454 [ # # # # ]: 0 : switch (link_status & I40E_PCI_LINK_SPEED) {
6455 : 0 : case I40E_PCI_LINK_SPEED_2500:
6456 : 0 : hw->bus.speed = i40e_bus_speed_2500;
6457 : 0 : break;
6458 : 0 : case I40E_PCI_LINK_SPEED_5000:
6459 : 0 : hw->bus.speed = i40e_bus_speed_5000;
6460 : 0 : break;
6461 : 0 : case I40E_PCI_LINK_SPEED_8000:
6462 : 0 : hw->bus.speed = i40e_bus_speed_8000;
6463 : 0 : break;
6464 : 0 : default:
6465 : 0 : hw->bus.speed = i40e_bus_speed_unknown;
6466 : 0 : break;
6467 : : }
6468 : 0 : }
6469 : :
6470 : : /**
6471 : : * i40e_aq_debug_dump
6472 : : * @hw: pointer to the hardware structure
6473 : : * @cluster_id: specific cluster to dump
6474 : : * @table_id: table id within cluster
6475 : : * @start_index: index of line in the block to read
6476 : : * @buff_size: dump buffer size
6477 : : * @buff: dump buffer
6478 : : * @ret_buff_size: actual buffer size returned
6479 : : * @ret_next_table: next block to read
6480 : : * @ret_next_index: next index to read
6481 : : * @cmd_details: pointer to command details structure or NULL
6482 : : *
6483 : : * Dump internal FW/HW data for debug purposes.
6484 : : *
6485 : : **/
6486 : 0 : enum i40e_status_code i40e_aq_debug_dump(struct i40e_hw *hw, u8 cluster_id,
6487 : : u8 table_id, u32 start_index, u16 buff_size,
6488 : : void *buff, u16 *ret_buff_size,
6489 : : u8 *ret_next_table, u32 *ret_next_index,
6490 : : struct i40e_asq_cmd_details *cmd_details)
6491 : : {
6492 : : struct i40e_aq_desc desc;
6493 : : struct i40e_aqc_debug_dump_internals *cmd =
6494 : : (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
6495 : : struct i40e_aqc_debug_dump_internals *resp =
6496 : : (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
6497 : : enum i40e_status_code status;
6498 : :
6499 [ # # ]: 0 : if (buff_size == 0 || !buff)
6500 : : return I40E_ERR_PARAM;
6501 : :
6502 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
6503 : : i40e_aqc_opc_debug_dump_internals);
6504 : : /* Indirect Command */
6505 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
6506 [ # # ]: 0 : if (buff_size > I40E_AQ_LARGE_BUF)
6507 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
6508 : :
6509 : 0 : cmd->cluster_id = cluster_id;
6510 : 0 : cmd->table_id = table_id;
6511 : 0 : cmd->idx = CPU_TO_LE32(start_index);
6512 : :
6513 : 0 : desc.datalen = CPU_TO_LE16(buff_size);
6514 : :
6515 : 0 : status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
6516 [ # # ]: 0 : if (!status) {
6517 [ # # ]: 0 : if (ret_buff_size != NULL)
6518 : 0 : *ret_buff_size = LE16_TO_CPU(desc.datalen);
6519 [ # # ]: 0 : if (ret_next_table != NULL)
6520 : 0 : *ret_next_table = resp->table_id;
6521 [ # # ]: 0 : if (ret_next_index != NULL)
6522 : 0 : *ret_next_index = LE32_TO_CPU(resp->idx);
6523 : : }
6524 : :
6525 : : return status;
6526 : : }
6527 : :
6528 : :
6529 : : /**
6530 : : * i40e_enable_eee
6531 : : * @hw: pointer to the hardware structure
6532 : : * @enable: state of Energy Efficient Ethernet mode to be set
6533 : : *
6534 : : * Enables or disables Energy Efficient Ethernet (EEE) mode
6535 : : * accordingly to @enable parameter.
6536 : : **/
6537 : 0 : enum i40e_status_code i40e_enable_eee(struct i40e_hw *hw, bool enable)
6538 : : {
6539 : : struct i40e_aq_get_phy_abilities_resp abilities;
6540 : : struct i40e_aq_set_phy_config config;
6541 : : enum i40e_status_code status;
6542 : : __le16 eee_capability;
6543 : :
6544 : : /* Get initial PHY capabilities */
6545 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, true, &abilities,
6546 : : NULL);
6547 [ # # ]: 0 : if (status)
6548 : 0 : goto err;
6549 : :
6550 : : /* Check whether NIC configuration is compatible with Energy Efficient
6551 : : * Ethernet (EEE) mode.
6552 : : */
6553 [ # # ]: 0 : if (abilities.eee_capability == 0) {
6554 : : status = I40E_ERR_CONFIG;
6555 : 0 : goto err;
6556 : : }
6557 : :
6558 : : /* Cache initial EEE capability */
6559 : : eee_capability = abilities.eee_capability;
6560 : :
6561 : : /* Get current configuration */
6562 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
6563 : : NULL);
6564 [ # # ]: 0 : if (status)
6565 : 0 : goto err;
6566 : :
6567 : : /* Cache current configuration */
6568 : 0 : config.phy_type = abilities.phy_type;
6569 : 0 : config.phy_type_ext = abilities.phy_type_ext;
6570 : 0 : config.link_speed = abilities.link_speed;
6571 : 0 : config.abilities = abilities.abilities |
6572 : : I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
6573 : 0 : config.eeer = abilities.eeer_val;
6574 : 0 : config.low_power_ctrl = abilities.d3_lpan;
6575 : 0 : config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
6576 : : I40E_AQ_PHY_FEC_CONFIG_MASK;
6577 : :
6578 : : /* Set desired EEE state */
6579 [ # # ]: 0 : if (enable) {
6580 : 0 : config.eee_capability = eee_capability;
6581 : 0 : config.eeer |= I40E_PRTPM_EEER_TX_LPI_EN_MASK;
6582 : : } else {
6583 : 0 : config.eee_capability = 0;
6584 : 0 : config.eeer &= ~I40E_PRTPM_EEER_TX_LPI_EN_MASK;
6585 : : }
6586 : :
6587 : : /* Save modified config */
6588 : 0 : status = i40e_aq_set_phy_config(hw, &config, NULL);
6589 : 0 : err:
6590 : 0 : return status;
6591 : : }
6592 : :
6593 : : /**
6594 : : * i40e_read_bw_from_alt_ram
6595 : : * @hw: pointer to the hardware structure
6596 : : * @max_bw: pointer for max_bw read
6597 : : * @min_bw: pointer for min_bw read
6598 : : * @min_valid: pointer for bool that is true if min_bw is a valid value
6599 : : * @max_valid: pointer for bool that is true if max_bw is a valid value
6600 : : *
6601 : : * Read bw from the alternate ram for the given pf
6602 : : **/
6603 : 0 : enum i40e_status_code i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
6604 : : u32 *max_bw, u32 *min_bw,
6605 : : bool *min_valid, bool *max_valid)
6606 : : {
6607 : : enum i40e_status_code status;
6608 : : u32 max_bw_addr, min_bw_addr;
6609 : :
6610 : : /* Calculate the address of the min/max bw registers */
6611 : 0 : max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
6612 : 0 : I40E_ALT_STRUCT_MAX_BW_OFFSET +
6613 : 0 : (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
6614 : 0 : min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
6615 : 0 : I40E_ALT_STRUCT_MIN_BW_OFFSET +
6616 : : (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
6617 : :
6618 : : /* Read the bandwidths from alt ram */
6619 : 0 : status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
6620 : : min_bw_addr, min_bw);
6621 : :
6622 [ # # ]: 0 : if (*min_bw & I40E_ALT_BW_VALID_MASK)
6623 : 0 : *min_valid = true;
6624 : : else
6625 : 0 : *min_valid = false;
6626 : :
6627 [ # # ]: 0 : if (*max_bw & I40E_ALT_BW_VALID_MASK)
6628 : 0 : *max_valid = true;
6629 : : else
6630 : 0 : *max_valid = false;
6631 : :
6632 : 0 : return status;
6633 : : }
6634 : :
6635 : : /**
6636 : : * i40e_aq_configure_partition_bw
6637 : : * @hw: pointer to the hardware structure
6638 : : * @bw_data: Buffer holding valid pfs and bw limits
6639 : : * @cmd_details: pointer to command details
6640 : : *
6641 : : * Configure partitions guaranteed/max bw
6642 : : **/
6643 : 0 : enum i40e_status_code i40e_aq_configure_partition_bw(struct i40e_hw *hw,
6644 : : struct i40e_aqc_configure_partition_bw_data *bw_data,
6645 : : struct i40e_asq_cmd_details *cmd_details)
6646 : : {
6647 : : enum i40e_status_code status;
6648 : : struct i40e_aq_desc desc;
6649 : : u16 bwd_size = sizeof(*bw_data);
6650 : :
6651 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
6652 : : i40e_aqc_opc_configure_partition_bw);
6653 : :
6654 : : /* Indirect command */
6655 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
6656 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
6657 : :
6658 : 0 : desc.datalen = CPU_TO_LE16(bwd_size);
6659 : :
6660 : 0 : status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size, cmd_details);
6661 : :
6662 : 0 : return status;
6663 : : }
6664 : :
6665 : : /**
6666 : : * i40e_read_phy_register_clause22
6667 : : * @hw: pointer to the HW structure
6668 : : * @reg: register address in the page
6669 : : * @phy_addr: PHY address on MDIO interface
6670 : : * @value: PHY register value
6671 : : *
6672 : : * Reads specified PHY register value
6673 : : **/
6674 : 0 : enum i40e_status_code i40e_read_phy_register_clause22(struct i40e_hw *hw,
6675 : : u16 reg, u8 phy_addr, u16 *value)
6676 : : {
6677 : : enum i40e_status_code status = I40E_ERR_TIMEOUT;
6678 : 0 : u8 port_num = (u8)hw->func_caps.mdio_port_num;
6679 : : u32 command = 0;
6680 : : u16 retry = 1000;
6681 : :
6682 : 0 : command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
6683 : 0 : (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
6684 : : (I40E_MDIO_CLAUSE22_OPCODE_READ_MASK) |
6685 : 0 : (I40E_MDIO_CLAUSE22_STCODE_MASK) |
6686 : : (I40E_GLGEN_MSCA_MDICMD_MASK);
6687 : 0 : wr32(hw, I40E_GLGEN_MSCA(port_num), command);
6688 : : do {
6689 : 0 : command = rd32(hw, I40E_GLGEN_MSCA(port_num));
6690 [ # # ]: 0 : if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
6691 : : status = I40E_SUCCESS;
6692 : : break;
6693 : : }
6694 : 0 : i40e_usec_delay(10);
6695 : 0 : retry--;
6696 [ # # ]: 0 : } while (retry);
6697 : :
6698 [ # # ]: 0 : if (status) {
6699 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_PHY,
6700 : : "PHY: Can't write command to external PHY.\n");
6701 : : } else {
6702 : 0 : command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
6703 : 0 : *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
6704 : : I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
6705 : : }
6706 : :
6707 : 0 : return status;
6708 : : }
6709 : :
6710 : : /**
6711 : : * i40e_write_phy_register_clause22
6712 : : * @hw: pointer to the HW structure
6713 : : * @reg: register address in the page
6714 : : * @phy_addr: PHY address on MDIO interface
6715 : : * @value: PHY register value
6716 : : *
6717 : : * Writes specified PHY register value
6718 : : **/
6719 : 0 : enum i40e_status_code i40e_write_phy_register_clause22(struct i40e_hw *hw,
6720 : : u16 reg, u8 phy_addr, u16 value)
6721 : : {
6722 : : enum i40e_status_code status = I40E_ERR_TIMEOUT;
6723 : 0 : u8 port_num = (u8)hw->func_caps.mdio_port_num;
6724 : : u32 command = 0;
6725 : : u16 retry = 1000;
6726 : :
6727 : 0 : command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
6728 : 0 : wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
6729 : :
6730 : 0 : command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
6731 : 0 : (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
6732 : : (I40E_MDIO_CLAUSE22_OPCODE_WRITE_MASK) |
6733 : 0 : (I40E_MDIO_CLAUSE22_STCODE_MASK) |
6734 : : (I40E_GLGEN_MSCA_MDICMD_MASK);
6735 : :
6736 : 0 : wr32(hw, I40E_GLGEN_MSCA(port_num), command);
6737 : : do {
6738 : 0 : command = rd32(hw, I40E_GLGEN_MSCA(port_num));
6739 [ # # ]: 0 : if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
6740 : : status = I40E_SUCCESS;
6741 : : break;
6742 : : }
6743 : 0 : i40e_usec_delay(10);
6744 : 0 : retry--;
6745 [ # # ]: 0 : } while (retry);
6746 : :
6747 : 0 : return status;
6748 : : }
6749 : :
6750 : : /**
6751 : : * i40e_read_phy_register_clause45
6752 : : * @hw: pointer to the HW structure
6753 : : * @page: registers page number
6754 : : * @reg: register address in the page
6755 : : * @phy_addr: PHY address on MDIO interface
6756 : : * @value: PHY register value
6757 : : *
6758 : : * Reads specified PHY register value
6759 : : **/
6760 : 0 : enum i40e_status_code i40e_read_phy_register_clause45(struct i40e_hw *hw,
6761 : : u8 page, u16 reg, u8 phy_addr, u16 *value)
6762 : : {
6763 : : enum i40e_status_code status = I40E_ERR_TIMEOUT;
6764 : : u32 command = 0;
6765 : : u16 retry = 1000;
6766 : 0 : u8 port_num = (u8)hw->func_caps.mdio_port_num;
6767 : :
6768 : 0 : command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
6769 : 0 : (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
6770 : 0 : (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
6771 : 0 : (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
6772 : : (I40E_MDIO_CLAUSE45_STCODE_MASK) |
6773 : 0 : (I40E_GLGEN_MSCA_MDICMD_MASK) |
6774 : : (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
6775 : 0 : wr32(hw, I40E_GLGEN_MSCA(port_num), command);
6776 : : do {
6777 : 0 : command = rd32(hw, I40E_GLGEN_MSCA(port_num));
6778 [ # # ]: 0 : if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
6779 : : status = I40E_SUCCESS;
6780 : : break;
6781 : : }
6782 : 0 : i40e_usec_delay(10);
6783 : 0 : retry--;
6784 [ # # ]: 0 : } while (retry);
6785 : :
6786 [ # # ]: 0 : if (status) {
6787 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_PHY,
6788 : : "PHY: Can't write command to external PHY.\n");
6789 : 0 : goto phy_read_end;
6790 : : }
6791 : :
6792 : 0 : command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
6793 : : (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
6794 : : (I40E_MDIO_CLAUSE45_OPCODE_READ_MASK) |
6795 : : (I40E_MDIO_CLAUSE45_STCODE_MASK) |
6796 : 0 : (I40E_GLGEN_MSCA_MDICMD_MASK) |
6797 : : (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
6798 : : status = I40E_ERR_TIMEOUT;
6799 : : retry = 1000;
6800 : 0 : wr32(hw, I40E_GLGEN_MSCA(port_num), command);
6801 : : do {
6802 : 0 : command = rd32(hw, I40E_GLGEN_MSCA(port_num));
6803 [ # # ]: 0 : if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
6804 : : status = I40E_SUCCESS;
6805 : : break;
6806 : : }
6807 : 0 : i40e_usec_delay(10);
6808 : 0 : retry--;
6809 [ # # ]: 0 : } while (retry);
6810 : :
6811 [ # # ]: 0 : if (!status) {
6812 : 0 : command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
6813 : 0 : *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
6814 : : I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
6815 : : } else {
6816 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_PHY,
6817 : : "PHY: Can't read register value from external PHY.\n");
6818 : : }
6819 : :
6820 : 0 : phy_read_end:
6821 : 0 : return status;
6822 : : }
6823 : :
6824 : : /**
6825 : : * i40e_write_phy_register_clause45
6826 : : * @hw: pointer to the HW structure
6827 : : * @page: registers page number
6828 : : * @reg: register address in the page
6829 : : * @phy_addr: PHY address on MDIO interface
6830 : : * @value: PHY register value
6831 : : *
6832 : : * Writes value to specified PHY register
6833 : : **/
6834 : 0 : enum i40e_status_code i40e_write_phy_register_clause45(struct i40e_hw *hw,
6835 : : u8 page, u16 reg, u8 phy_addr, u16 value)
6836 : : {
6837 : : enum i40e_status_code status = I40E_ERR_TIMEOUT;
6838 : : u32 command = 0;
6839 : : u16 retry = 1000;
6840 : 0 : u8 port_num = (u8)hw->func_caps.mdio_port_num;
6841 : :
6842 : 0 : command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
6843 : 0 : (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
6844 : 0 : (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
6845 : 0 : (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
6846 : : (I40E_MDIO_CLAUSE45_STCODE_MASK) |
6847 : 0 : (I40E_GLGEN_MSCA_MDICMD_MASK) |
6848 : : (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
6849 : 0 : wr32(hw, I40E_GLGEN_MSCA(port_num), command);
6850 : : do {
6851 : 0 : command = rd32(hw, I40E_GLGEN_MSCA(port_num));
6852 [ # # ]: 0 : if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
6853 : : status = I40E_SUCCESS;
6854 : : break;
6855 : : }
6856 : 0 : i40e_usec_delay(10);
6857 : 0 : retry--;
6858 [ # # ]: 0 : } while (retry);
6859 [ # # ]: 0 : if (status) {
6860 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_PHY,
6861 : : "PHY: Can't write command to external PHY.\n");
6862 : 0 : goto phy_write_end;
6863 : : }
6864 : :
6865 : 0 : command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
6866 : 0 : wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
6867 : :
6868 : 0 : command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
6869 : : (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
6870 : : (I40E_MDIO_CLAUSE45_OPCODE_WRITE_MASK) |
6871 : : (I40E_MDIO_CLAUSE45_STCODE_MASK) |
6872 : 0 : (I40E_GLGEN_MSCA_MDICMD_MASK) |
6873 : : (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
6874 : : status = I40E_ERR_TIMEOUT;
6875 : : retry = 1000;
6876 : 0 : wr32(hw, I40E_GLGEN_MSCA(port_num), command);
6877 : : do {
6878 : 0 : command = rd32(hw, I40E_GLGEN_MSCA(port_num));
6879 [ # # ]: 0 : if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
6880 : : status = I40E_SUCCESS;
6881 : : break;
6882 : : }
6883 : 0 : i40e_usec_delay(10);
6884 : 0 : retry--;
6885 [ # # ]: 0 : } while (retry);
6886 : :
6887 : 0 : phy_write_end:
6888 : 0 : return status;
6889 : : }
6890 : :
6891 : : /**
6892 : : * i40e_write_phy_register
6893 : : * @hw: pointer to the HW structure
6894 : : * @page: registers page number
6895 : : * @reg: register address in the page
6896 : : * @phy_addr: PHY address on MDIO interface
6897 : : * @value: PHY register value
6898 : : *
6899 : : * Writes value to specified PHY register
6900 : : **/
6901 : 0 : enum i40e_status_code i40e_write_phy_register(struct i40e_hw *hw,
6902 : : u8 page, u16 reg, u8 phy_addr, u16 value)
6903 : : {
6904 : : enum i40e_status_code status;
6905 : :
6906 [ # # # ]: 0 : switch (hw->device_id) {
6907 : 0 : case I40E_DEV_ID_1G_BASE_T_X722:
6908 : 0 : status = i40e_write_phy_register_clause22(hw,
6909 : : reg, phy_addr, value);
6910 : 0 : break;
6911 : 0 : case I40E_DEV_ID_10G_BASE_T:
6912 : : case I40E_DEV_ID_10G_BASE_T4:
6913 : : case I40E_DEV_ID_10G_BASE_T_BC:
6914 : : case I40E_DEV_ID_5G_BASE_T_BC:
6915 : : case I40E_DEV_ID_1G_BASE_T_BC:
6916 : : case I40E_DEV_ID_10G_BASE_T_X722:
6917 : : case I40E_DEV_ID_25G_B:
6918 : : case I40E_DEV_ID_25G_SFP28:
6919 : 0 : status = i40e_write_phy_register_clause45(hw,
6920 : : page, reg, phy_addr, value);
6921 : 0 : break;
6922 : : default:
6923 : : status = I40E_ERR_UNKNOWN_PHY;
6924 : : break;
6925 : : }
6926 : :
6927 : 0 : return status;
6928 : : }
6929 : :
6930 : : /**
6931 : : * i40e_read_phy_register
6932 : : * @hw: pointer to the HW structure
6933 : : * @page: registers page number
6934 : : * @reg: register address in the page
6935 : : * @phy_addr: PHY address on MDIO interface
6936 : : * @value: PHY register value
6937 : : *
6938 : : * Reads specified PHY register value
6939 : : **/
6940 : 0 : enum i40e_status_code i40e_read_phy_register(struct i40e_hw *hw,
6941 : : u8 page, u16 reg, u8 phy_addr, u16 *value)
6942 : : {
6943 : : enum i40e_status_code status;
6944 : :
6945 [ # # # ]: 0 : switch (hw->device_id) {
6946 : 0 : case I40E_DEV_ID_1G_BASE_T_X722:
6947 : 0 : status = i40e_read_phy_register_clause22(hw, reg, phy_addr,
6948 : : value);
6949 : 0 : break;
6950 : 0 : case I40E_DEV_ID_10G_BASE_T:
6951 : : case I40E_DEV_ID_10G_BASE_T4:
6952 : : case I40E_DEV_ID_10G_BASE_T_BC:
6953 : : case I40E_DEV_ID_5G_BASE_T_BC:
6954 : : case I40E_DEV_ID_1G_BASE_T_BC:
6955 : : case I40E_DEV_ID_10G_BASE_T_X722:
6956 : : case I40E_DEV_ID_25G_B:
6957 : : case I40E_DEV_ID_25G_SFP28:
6958 : 0 : status = i40e_read_phy_register_clause45(hw, page, reg,
6959 : : phy_addr, value);
6960 : 0 : break;
6961 : : default:
6962 : : status = I40E_ERR_UNKNOWN_PHY;
6963 : : break;
6964 : : }
6965 : :
6966 : 0 : return status;
6967 : : }
6968 : :
6969 : : /**
6970 : : * i40e_get_phy_address
6971 : : * @hw: pointer to the HW structure
6972 : : * @dev_num: PHY port num that address we want
6973 : : *
6974 : : * Gets PHY address for current port
6975 : : **/
6976 : 0 : u8 i40e_get_phy_address(struct i40e_hw *hw, u8 dev_num)
6977 : : {
6978 : 0 : u8 port_num = (u8)hw->func_caps.mdio_port_num;
6979 : 0 : u32 reg_val = rd32(hw, I40E_GLGEN_MDIO_I2C_SEL(port_num));
6980 : :
6981 : 0 : return (u8)(reg_val >> ((dev_num + 1) * 5)) & 0x1f;
6982 : : }
6983 : :
6984 : : /**
6985 : : * i40e_blink_phy_link_led
6986 : : * @hw: pointer to the HW structure
6987 : : * @time: time how long led will blinks in secs
6988 : : * @interval: gap between LED on and off in msecs
6989 : : *
6990 : : * Blinks PHY link LED
6991 : : **/
6992 : 0 : enum i40e_status_code i40e_blink_phy_link_led(struct i40e_hw *hw,
6993 : : u32 time, u32 interval)
6994 : : {
6995 : : enum i40e_status_code status = I40E_SUCCESS;
6996 : : u32 i;
6997 : : u16 led_ctl = 0;
6998 : : u16 gpio_led_port;
6999 : : u16 led_reg;
7000 : : u16 led_addr = I40E_PHY_LED_PROV_REG_1;
7001 : : u8 phy_addr = 0;
7002 : : u8 port_num;
7003 : :
7004 : 0 : i = rd32(hw, I40E_PFGEN_PORTNUM);
7005 : 0 : port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
7006 : 0 : phy_addr = i40e_get_phy_address(hw, port_num);
7007 : :
7008 [ # # ]: 0 : for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
7009 : 0 : led_addr++) {
7010 : 0 : status = i40e_read_phy_register_clause45(hw,
7011 : : I40E_PHY_COM_REG_PAGE,
7012 : : led_addr, phy_addr,
7013 : : &led_reg);
7014 [ # # ]: 0 : if (status)
7015 : 0 : goto phy_blinking_end;
7016 : 0 : led_ctl = led_reg;
7017 [ # # ]: 0 : if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
7018 : 0 : led_reg = 0;
7019 : 0 : status = i40e_write_phy_register_clause45(hw,
7020 : : I40E_PHY_COM_REG_PAGE,
7021 : : led_addr, phy_addr,
7022 : : led_reg);
7023 [ # # ]: 0 : if (status)
7024 : 0 : goto phy_blinking_end;
7025 : : break;
7026 : : }
7027 : : }
7028 : :
7029 [ # # ]: 0 : if (time > 0 && interval > 0) {
7030 [ # # ]: 0 : for (i = 0; i < time * 1000; i += interval) {
7031 : 0 : status = i40e_read_phy_register_clause45(hw,
7032 : : I40E_PHY_COM_REG_PAGE,
7033 : : led_addr, phy_addr, &led_reg);
7034 [ # # ]: 0 : if (status)
7035 : 0 : goto restore_config;
7036 [ # # ]: 0 : if (led_reg & I40E_PHY_LED_MANUAL_ON)
7037 : 0 : led_reg = 0;
7038 : : else
7039 : 0 : led_reg = I40E_PHY_LED_MANUAL_ON;
7040 : 0 : status = i40e_write_phy_register_clause45(hw,
7041 : : I40E_PHY_COM_REG_PAGE,
7042 : : led_addr, phy_addr, led_reg);
7043 [ # # ]: 0 : if (status)
7044 : 0 : goto restore_config;
7045 : 0 : i40e_msec_delay(interval);
7046 : : }
7047 : : }
7048 : :
7049 : 0 : restore_config:
7050 : 0 : status = i40e_write_phy_register_clause45(hw,
7051 : : I40E_PHY_COM_REG_PAGE,
7052 : : led_addr, phy_addr, led_ctl);
7053 : :
7054 : 0 : phy_blinking_end:
7055 : 0 : return status;
7056 : : }
7057 : :
7058 : : /**
7059 : : * i40e_led_get_reg - read LED register
7060 : : * @hw: pointer to the HW structure
7061 : : * @led_addr: LED register address
7062 : : * @reg_val: read register value
7063 : : **/
7064 : 0 : enum i40e_status_code i40e_led_get_reg(struct i40e_hw *hw, u16 led_addr,
7065 : : u32 *reg_val)
7066 : : {
7067 : : enum i40e_status_code status;
7068 : : u8 phy_addr = 0;
7069 : :
7070 : 0 : *reg_val = 0;
7071 [ # # ]: 0 : if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
7072 : 0 : status = i40e_aq_get_phy_register(hw,
7073 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
7074 : : I40E_PHY_COM_REG_PAGE, true,
7075 : : I40E_PHY_LED_PROV_REG_1,
7076 : : reg_val, NULL);
7077 : : } else {
7078 : 0 : phy_addr = i40e_get_phy_address(hw, hw->port);
7079 : 0 : status = i40e_read_phy_register_clause45(hw,
7080 : : I40E_PHY_COM_REG_PAGE,
7081 : : led_addr, phy_addr,
7082 : : (u16 *)reg_val);
7083 : : }
7084 : 0 : return status;
7085 : : }
7086 : :
7087 : : /**
7088 : : * i40e_led_set_reg - write LED register
7089 : : * @hw: pointer to the HW structure
7090 : : * @led_addr: LED register address
7091 : : * @reg_val: register value to write
7092 : : **/
7093 : 0 : enum i40e_status_code i40e_led_set_reg(struct i40e_hw *hw, u16 led_addr,
7094 : : u32 reg_val)
7095 : : {
7096 : : enum i40e_status_code status;
7097 : : u8 phy_addr = 0;
7098 : :
7099 [ # # ]: 0 : if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
7100 : 0 : status = i40e_aq_set_phy_register(hw,
7101 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
7102 : : I40E_PHY_COM_REG_PAGE, true,
7103 : : I40E_PHY_LED_PROV_REG_1,
7104 : : reg_val, NULL);
7105 : : } else {
7106 : 0 : phy_addr = i40e_get_phy_address(hw, hw->port);
7107 : 0 : status = i40e_write_phy_register_clause45(hw,
7108 : : I40E_PHY_COM_REG_PAGE,
7109 : : led_addr, phy_addr,
7110 : : (u16)reg_val);
7111 : : }
7112 : :
7113 : 0 : return status;
7114 : : }
7115 : :
7116 : : /**
7117 : : * i40e_led_get_phy - return current on/off mode
7118 : : * @hw: pointer to the hw struct
7119 : : * @led_addr: address of led register to use
7120 : : * @val: original value of register to use
7121 : : *
7122 : : **/
7123 : 0 : enum i40e_status_code i40e_led_get_phy(struct i40e_hw *hw, u16 *led_addr,
7124 : : u16 *val)
7125 : : {
7126 : : enum i40e_status_code status = I40E_SUCCESS;
7127 : : u16 gpio_led_port;
7128 : : u32 reg_val_aq;
7129 : : u16 temp_addr;
7130 : : u8 phy_addr = 0;
7131 : : u16 reg_val;
7132 : :
7133 [ # # ]: 0 : if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
7134 : 0 : status = i40e_aq_get_phy_register(hw,
7135 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
7136 : : I40E_PHY_COM_REG_PAGE, true,
7137 : : I40E_PHY_LED_PROV_REG_1,
7138 : : ®_val_aq, NULL);
7139 [ # # ]: 0 : if (status == I40E_SUCCESS)
7140 : 0 : *val = (u16)reg_val_aq;
7141 : 0 : return status;
7142 : : }
7143 : : temp_addr = I40E_PHY_LED_PROV_REG_1;
7144 : 0 : phy_addr = i40e_get_phy_address(hw, hw->port);
7145 [ # # ]: 0 : for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
7146 : 0 : temp_addr++) {
7147 : 0 : status = i40e_read_phy_register_clause45(hw,
7148 : : I40E_PHY_COM_REG_PAGE,
7149 : : temp_addr, phy_addr,
7150 : : ®_val);
7151 [ # # ]: 0 : if (status)
7152 : 0 : return status;
7153 : 0 : *val = reg_val;
7154 [ # # ]: 0 : if (reg_val & I40E_PHY_LED_LINK_MODE_MASK) {
7155 : 0 : *led_addr = temp_addr;
7156 : 0 : break;
7157 : : }
7158 : : }
7159 : : return status;
7160 : : }
7161 : :
7162 : : /**
7163 : : * i40e_led_set_phy
7164 : : * @hw: pointer to the HW structure
7165 : : * @on: true or false
7166 : : * @led_addr: address of led register to use
7167 : : * @mode: original val plus bit for set or ignore
7168 : : *
7169 : : * Set led's on or off when controlled by the PHY
7170 : : *
7171 : : **/
7172 : 0 : enum i40e_status_code i40e_led_set_phy(struct i40e_hw *hw, bool on,
7173 : : u16 led_addr, u32 mode)
7174 : : {
7175 : : enum i40e_status_code status = I40E_SUCCESS;
7176 : : u32 led_ctl = 0;
7177 : 0 : u32 led_reg = 0;
7178 : :
7179 : 0 : status = i40e_led_get_reg(hw, led_addr, &led_reg);
7180 [ # # ]: 0 : if (status)
7181 : : return status;
7182 : 0 : led_ctl = led_reg;
7183 [ # # ]: 0 : if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
7184 : 0 : led_reg = 0;
7185 : 0 : status = i40e_led_set_reg(hw, led_addr, led_reg);
7186 [ # # ]: 0 : if (status)
7187 : : return status;
7188 : : }
7189 : 0 : status = i40e_led_get_reg(hw, led_addr, &led_reg);
7190 [ # # ]: 0 : if (status)
7191 : 0 : goto restore_config;
7192 [ # # ]: 0 : if (on)
7193 : 0 : led_reg = I40E_PHY_LED_MANUAL_ON;
7194 : : else
7195 : 0 : led_reg = 0;
7196 : 0 : status = i40e_led_set_reg(hw, led_addr, led_reg);
7197 [ # # ]: 0 : if (status)
7198 : 0 : goto restore_config;
7199 [ # # ]: 0 : if (mode & I40E_PHY_LED_MODE_ORIG) {
7200 : 0 : led_ctl = (mode & I40E_PHY_LED_MODE_MASK);
7201 : 0 : status = i40e_led_set_reg(hw, led_addr, led_ctl);
7202 : : }
7203 : : return status;
7204 : :
7205 : 0 : restore_config:
7206 : 0 : status = i40e_led_set_reg(hw, led_addr, led_ctl);
7207 : 0 : return status;
7208 : : }
7209 : : #endif /* PF_DRIVER */
7210 : : /**
7211 : : * i40e_get_phy_lpi_status - read LPI status from PHY or MAC register
7212 : : * @hw: pointer to the hw struct
7213 : : * @stat: pointer to structure with status of rx and tx lpi
7214 : : *
7215 : : * Read LPI state directly from external PHY register or from MAC
7216 : : * register, depending on device ID and current link speed.
7217 : : */
7218 : 0 : enum i40e_status_code i40e_get_phy_lpi_status(struct i40e_hw *hw,
7219 : : struct i40e_hw_port_stats *stat)
7220 : : {
7221 : : enum i40e_status_code ret = I40E_SUCCESS;
7222 : : bool eee_mrvl_phy;
7223 : : bool eee_bcm_phy;
7224 : : u32 val;
7225 : :
7226 : 0 : stat->rx_lpi_status = 0;
7227 : 0 : stat->tx_lpi_status = 0;
7228 : :
7229 : 0 : eee_bcm_phy =
7230 : 0 : (hw->device_id == I40E_DEV_ID_10G_BASE_T_BC ||
7231 [ # # ]: 0 : hw->device_id == I40E_DEV_ID_5G_BASE_T_BC) &&
7232 [ # # ]: 0 : (hw->phy.link_info.link_speed == I40E_LINK_SPEED_2_5GB ||
7233 : : hw->phy.link_info.link_speed == I40E_LINK_SPEED_5GB);
7234 : 0 : eee_mrvl_phy =
7235 : : hw->device_id == I40E_DEV_ID_1G_BASE_T_X722;
7236 : :
7237 [ # # ]: 0 : if (eee_bcm_phy || eee_mrvl_phy) {
7238 : : /* read Clause 45 PCS Status 1 register */
7239 : 0 : ret = i40e_aq_get_phy_register(hw,
7240 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
7241 : : I40E_BCM_PHY_PCS_STATUS1_PAGE,
7242 : : true,
7243 : : I40E_BCM_PHY_PCS_STATUS1_REG,
7244 : : &val, NULL);
7245 : :
7246 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7247 : : return ret;
7248 : :
7249 : 0 : stat->rx_lpi_status = !!(val & I40E_BCM_PHY_PCS_STATUS1_RX_LPI);
7250 : 0 : stat->tx_lpi_status = !!(val & I40E_BCM_PHY_PCS_STATUS1_TX_LPI);
7251 : :
7252 : 0 : return ret;
7253 : : }
7254 : :
7255 : 0 : val = rd32(hw, I40E_PRTPM_EEE_STAT);
7256 : 0 : stat->rx_lpi_status = (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
7257 : : I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
7258 : 0 : stat->tx_lpi_status = (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
7259 : : I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
7260 : :
7261 : 0 : return ret;
7262 : : }
7263 : :
7264 : : /**
7265 : : * i40e_get_lpi_counters - read LPI counters from EEE statistics
7266 : : * @hw: pointer to the hw struct
7267 : : * @tx_counter: pointer to memory for TX LPI counter
7268 : : * @rx_counter: pointer to memory for RX LPI counter
7269 : : * @is_clear: returns true if counters are clear after read
7270 : : *
7271 : : * Read Low Power Idle (LPI) mode counters from Energy Efficient
7272 : : * Ethernet (EEE) statistics.
7273 : : **/
7274 : 0 : enum i40e_status_code i40e_get_lpi_counters(struct i40e_hw *hw,
7275 : : u32 *tx_counter, u32 *rx_counter,
7276 : : bool *is_clear)
7277 : : {
7278 : : /* only X710-T*L requires special handling of counters
7279 : : * for other devices we just read the MAC registers
7280 : : */
7281 [ # # ]: 0 : if ((hw->device_id == I40E_DEV_ID_10G_BASE_T_BC ||
7282 : 0 : hw->device_id == I40E_DEV_ID_5G_BASE_T_BC) &&
7283 [ # # ]: 0 : hw->phy.link_info.link_speed != I40E_LINK_SPEED_1GB) {
7284 : : enum i40e_status_code retval;
7285 : 0 : u32 cmd_status = 0;
7286 : :
7287 : 0 : *is_clear = false;
7288 : 0 : retval = i40e_aq_run_phy_activity(hw,
7289 : : I40E_AQ_RUN_PHY_ACT_ID_USR_DFND,
7290 : : I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_STAT,
7291 : : &cmd_status, tx_counter, rx_counter, NULL);
7292 : :
7293 [ # # # # ]: 0 : if (!retval && cmd_status != I40E_AQ_RUN_PHY_ACT_CMD_STAT_SUCC)
7294 : : retval = I40E_ERR_ADMIN_QUEUE_ERROR;
7295 : :
7296 : : return retval;
7297 : : }
7298 : :
7299 : 0 : *is_clear = true;
7300 : 0 : *tx_counter = rd32(hw, I40E_PRTPM_TLPIC);
7301 : 0 : *rx_counter = rd32(hw, I40E_PRTPM_RLPIC);
7302 : :
7303 : 0 : return I40E_SUCCESS;
7304 : : }
7305 : :
7306 : : /**
7307 : : * i40e_get_lpi_duration - read LPI time duration from EEE statistics
7308 : : * @hw: pointer to the hw struct
7309 : : * @stat: pointer to structure with status of rx and tx lpi
7310 : : * @tx_duration: pointer to memory for TX LPI time duration
7311 : : * @rx_duration: pointer to memory for RX LPI time duration
7312 : : *
7313 : : * Read Low Power Idle (LPI) mode time duration from Energy Efficient
7314 : : * Ethernet (EEE) statistics.
7315 : : */
7316 : 0 : enum i40e_status_code i40e_get_lpi_duration(struct i40e_hw *hw,
7317 : : struct i40e_hw_port_stats *stat,
7318 : : u64 *tx_duration, u64 *rx_duration)
7319 : : {
7320 : : u32 tx_time_dur, rx_time_dur;
7321 : : enum i40e_status_code retval;
7322 : : u32 cmd_status;
7323 : :
7324 [ # # ]: 0 : if (hw->device_id != I40E_DEV_ID_10G_BASE_T_BC &&
7325 : : hw->device_id != I40E_DEV_ID_5G_BASE_T_BC)
7326 : : return I40E_ERR_NOT_IMPLEMENTED;
7327 : :
7328 : 0 : retval = i40e_aq_run_phy_activity
7329 : : (hw, I40E_AQ_RUN_PHY_ACT_ID_USR_DFND,
7330 : : I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_DUR,
7331 : : &cmd_status, &tx_time_dur, &rx_time_dur, NULL);
7332 : :
7333 [ # # ]: 0 : if (retval)
7334 : : return retval;
7335 [ # # ]: 0 : if ((cmd_status & I40E_AQ_RUN_PHY_ACT_CMD_STAT_MASK) !=
7336 : : I40E_AQ_RUN_PHY_ACT_CMD_STAT_SUCC)
7337 : : return I40E_ERR_ADMIN_QUEUE_ERROR;
7338 : :
7339 [ # # ]: 0 : if (hw->phy.link_info.link_speed == I40E_LINK_SPEED_1GB &&
7340 [ # # # # ]: 0 : !tx_time_dur && !rx_time_dur &&
7341 [ # # # # ]: 0 : stat->tx_lpi_status && stat->rx_lpi_status) {
7342 : 0 : retval = i40e_aq_run_phy_activity
7343 : : (hw, I40E_AQ_RUN_PHY_ACT_ID_USR_DFND,
7344 : : I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_STAT_DUR,
7345 : : &cmd_status,
7346 : : &tx_time_dur, &rx_time_dur, NULL);
7347 : :
7348 [ # # ]: 0 : if (retval)
7349 : : return retval;
7350 [ # # ]: 0 : if ((cmd_status & I40E_AQ_RUN_PHY_ACT_CMD_STAT_MASK) !=
7351 : : I40E_AQ_RUN_PHY_ACT_CMD_STAT_SUCC)
7352 : : return I40E_ERR_ADMIN_QUEUE_ERROR;
7353 : 0 : tx_time_dur = 0;
7354 : 0 : rx_time_dur = 0;
7355 : : }
7356 : :
7357 : 0 : *tx_duration = tx_time_dur;
7358 : 0 : *rx_duration = rx_time_dur;
7359 : :
7360 : 0 : return retval;
7361 : : }
7362 : :
7363 : : /**
7364 : : * i40e_lpi_stat_update - update LPI counters with values relative to offset
7365 : : * @hw: pointer to the hw struct
7366 : : * @offset_loaded: flag indicating need of writing current value to offset
7367 : : * @tx_offset: pointer to offset of TX LPI counter
7368 : : * @tx_stat: pointer to value of TX LPI counter
7369 : : * @rx_offset: pointer to offset of RX LPI counter
7370 : : * @rx_stat: pointer to value of RX LPI counter
7371 : : *
7372 : : * Update Low Power Idle (LPI) mode counters while having regard to passed
7373 : : * offsets.
7374 : : **/
7375 : 0 : enum i40e_status_code i40e_lpi_stat_update(struct i40e_hw *hw,
7376 : : bool offset_loaded, u64 *tx_offset,
7377 : : u64 *tx_stat, u64 *rx_offset,
7378 : : u64 *rx_stat)
7379 : : {
7380 : : enum i40e_status_code retval;
7381 : : u32 tx_counter, rx_counter;
7382 : : bool is_clear;
7383 : :
7384 : 0 : retval = i40e_get_lpi_counters(hw, &tx_counter, &rx_counter, &is_clear);
7385 [ # # ]: 0 : if (retval)
7386 : 0 : goto err;
7387 : :
7388 [ # # ]: 0 : if (is_clear) {
7389 : 0 : *tx_stat += tx_counter;
7390 : 0 : *rx_stat += rx_counter;
7391 : : } else {
7392 [ # # ]: 0 : if (!offset_loaded) {
7393 : 0 : *tx_offset = tx_counter;
7394 : 0 : *rx_offset = rx_counter;
7395 : : }
7396 : :
7397 : 0 : *tx_stat = (tx_counter >= *tx_offset) ?
7398 : 0 : (u32)(tx_counter - *tx_offset) :
7399 : : (u32)((tx_counter + BIT_ULL(32)) - *tx_offset);
7400 : 0 : *rx_stat = (rx_counter >= *rx_offset) ?
7401 : 0 : (u32)(rx_counter - *rx_offset) :
7402 : : (u32)((rx_counter + BIT_ULL(32)) - *rx_offset);
7403 : : }
7404 : 0 : err:
7405 : 0 : return retval;
7406 : : }
7407 : :
7408 : : /**
7409 : : * i40e_aq_rx_ctl_read_register - use FW to read from an Rx control register
7410 : : * @hw: pointer to the hw struct
7411 : : * @reg_addr: register address
7412 : : * @reg_val: ptr to register value
7413 : : * @cmd_details: pointer to command details structure or NULL
7414 : : *
7415 : : * Use the firmware to read the Rx control register,
7416 : : * especially useful if the Rx unit is under heavy pressure
7417 : : **/
7418 : 0 : enum i40e_status_code i40e_aq_rx_ctl_read_register(struct i40e_hw *hw,
7419 : : u32 reg_addr, u32 *reg_val,
7420 : : struct i40e_asq_cmd_details *cmd_details)
7421 : : {
7422 : : struct i40e_aq_desc desc;
7423 : : struct i40e_aqc_rx_ctl_reg_read_write *cmd_resp =
7424 : : (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
7425 : : enum i40e_status_code status;
7426 : :
7427 [ # # ]: 0 : if (reg_val == NULL)
7428 : : return I40E_ERR_PARAM;
7429 : :
7430 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_read);
7431 : :
7432 : 0 : cmd_resp->address = CPU_TO_LE32(reg_addr);
7433 : :
7434 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
7435 : :
7436 [ # # ]: 0 : if (status == I40E_SUCCESS)
7437 : 0 : *reg_val = LE32_TO_CPU(cmd_resp->value);
7438 : :
7439 : : return status;
7440 : : }
7441 : :
7442 : : /**
7443 : : * i40e_read_rx_ctl - read from an Rx control register
7444 : : * @hw: pointer to the hw struct
7445 : : * @reg_addr: register address
7446 : : **/
7447 : 0 : u32 i40e_read_rx_ctl(struct i40e_hw *hw, u32 reg_addr)
7448 : : {
7449 : : enum i40e_status_code status = I40E_SUCCESS;
7450 : : bool use_register;
7451 : : int retry = 5;
7452 : 0 : u32 val = 0;
7453 : :
7454 : 0 : use_register = (((hw->aq.api_maj_ver == 1) &&
7455 [ # # # # ]: 0 : (hw->aq.api_min_ver < 5)) ||
7456 [ # # ]: 0 : (hw->mac.type == I40E_MAC_X722));
7457 [ # # ]: 0 : if (!use_register) {
7458 : 0 : do_retry:
7459 : 0 : status = i40e_aq_rx_ctl_read_register(hw, reg_addr, &val, NULL);
7460 [ # # # # ]: 0 : if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
7461 : 0 : i40e_msec_delay(1);
7462 : 0 : retry--;
7463 : 0 : goto do_retry;
7464 : : }
7465 : : }
7466 : :
7467 : : /* if the AQ access failed, try the old-fashioned way */
7468 [ # # ]: 0 : if (status || use_register)
7469 : 0 : val = rd32(hw, reg_addr);
7470 : :
7471 : 0 : return val;
7472 : : }
7473 : :
7474 : : /**
7475 : : * i40e_aq_rx_ctl_write_register
7476 : : * @hw: pointer to the hw struct
7477 : : * @reg_addr: register address
7478 : : * @reg_val: register value
7479 : : * @cmd_details: pointer to command details structure or NULL
7480 : : *
7481 : : * Use the firmware to write to an Rx control register,
7482 : : * especially useful if the Rx unit is under heavy pressure
7483 : : **/
7484 : 0 : enum i40e_status_code i40e_aq_rx_ctl_write_register(struct i40e_hw *hw,
7485 : : u32 reg_addr, u32 reg_val,
7486 : : struct i40e_asq_cmd_details *cmd_details)
7487 : : {
7488 : : struct i40e_aq_desc desc;
7489 : : struct i40e_aqc_rx_ctl_reg_read_write *cmd =
7490 : : (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
7491 : : enum i40e_status_code status;
7492 : :
7493 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_write);
7494 : :
7495 : 0 : cmd->address = CPU_TO_LE32(reg_addr);
7496 : 0 : cmd->value = CPU_TO_LE32(reg_val);
7497 : :
7498 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
7499 : :
7500 : 0 : return status;
7501 : : }
7502 : :
7503 : : /**
7504 : : * i40e_write_rx_ctl - write to an Rx control register
7505 : : * @hw: pointer to the hw struct
7506 : : * @reg_addr: register address
7507 : : * @reg_val: register value
7508 : : **/
7509 : 0 : void i40e_write_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
7510 : : {
7511 : : enum i40e_status_code status = I40E_SUCCESS;
7512 : : bool use_register;
7513 : : int retry = 5;
7514 : :
7515 : 0 : use_register = (((hw->aq.api_maj_ver == 1) &&
7516 [ # # # # ]: 0 : (hw->aq.api_min_ver < 5)) ||
7517 [ # # ]: 0 : (hw->mac.type == I40E_MAC_X722));
7518 [ # # ]: 0 : if (!use_register) {
7519 : 0 : do_retry:
7520 : 0 : status = i40e_aq_rx_ctl_write_register(hw, reg_addr,
7521 : : reg_val, NULL);
7522 [ # # # # ]: 0 : if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
7523 : 0 : i40e_msec_delay(1);
7524 : 0 : retry--;
7525 : 0 : goto do_retry;
7526 : : }
7527 : : }
7528 : :
7529 : : /* if the AQ access failed, try the old-fashioned way */
7530 [ # # ]: 0 : if (status || use_register)
7531 : 0 : wr32(hw, reg_addr, reg_val);
7532 : 0 : }
7533 : :
7534 : : /**
7535 : : * i40e_mdio_if_number_selection - MDIO I/F number selection
7536 : : * @hw: pointer to the hw struct
7537 : : * @set_mdio: use MDIO I/F number specified by mdio_num
7538 : : * @mdio_num: MDIO I/F number
7539 : : * @cmd: pointer to PHY Register command structure
7540 : : **/
7541 : : static void
7542 : 0 : i40e_mdio_if_number_selection(struct i40e_hw *hw, bool set_mdio, u8 mdio_num,
7543 : : struct i40e_aqc_phy_register_access *cmd)
7544 : : {
7545 [ # # # # ]: 0 : if (set_mdio && cmd->phy_interface == I40E_AQ_PHY_REG_ACCESS_EXTERNAL) {
7546 [ # # ]: 0 : if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_EXTENDED)
7547 : 0 : cmd->cmd_flags |=
7548 : : I40E_AQ_PHY_REG_ACCESS_SET_MDIO_IF_NUMBER |
7549 : 0 : ((mdio_num <<
7550 : : I40E_AQ_PHY_REG_ACCESS_MDIO_IF_NUMBER_SHIFT) &
7551 : : I40E_AQ_PHY_REG_ACCESS_MDIO_IF_NUMBER_MASK);
7552 : : else
7553 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_PHY,
7554 : : "MDIO I/F number selection not supported by current FW version.\n");
7555 : : }
7556 : 0 : }
7557 : :
7558 : : /**
7559 : : * i40e_aq_set_phy_register_ext
7560 : : * @hw: pointer to the hw struct
7561 : : * @phy_select: select which phy should be accessed
7562 : : * @dev_addr: PHY device address
7563 : : * @page_change: enable auto page change
7564 : : * @set_mdio: use MDIO I/F number specified by mdio_num
7565 : : * @mdio_num: MDIO I/F number
7566 : : * @reg_addr: PHY register address
7567 : : * @reg_val: new register value
7568 : : * @cmd_details: pointer to command details structure or NULL
7569 : : *
7570 : : * Write the external PHY register.
7571 : : * NOTE: In common cases MDIO I/F number should not be changed, thats why you
7572 : : * may use simple wrapper i40e_aq_set_phy_register.
7573 : : **/
7574 : : enum i40e_status_code
7575 : 0 : i40e_aq_set_phy_register_ext(struct i40e_hw *hw,
7576 : : u8 phy_select, u8 dev_addr, bool page_change,
7577 : : bool set_mdio, u8 mdio_num,
7578 : : u32 reg_addr, u32 reg_val,
7579 : : struct i40e_asq_cmd_details *cmd_details)
7580 : : {
7581 : : struct i40e_aq_desc desc;
7582 : : struct i40e_aqc_phy_register_access *cmd =
7583 : : (struct i40e_aqc_phy_register_access *)&desc.params.raw;
7584 : : enum i40e_status_code status;
7585 : :
7586 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
7587 : : i40e_aqc_opc_set_phy_register);
7588 : :
7589 : 0 : cmd->phy_interface = phy_select;
7590 : 0 : cmd->dev_addres = dev_addr;
7591 : 0 : cmd->reg_address = CPU_TO_LE32(reg_addr);
7592 : 0 : cmd->reg_value = CPU_TO_LE32(reg_val);
7593 : :
7594 [ # # ]: 0 : if (!page_change)
7595 : 0 : cmd->cmd_flags = I40E_AQ_PHY_REG_ACCESS_DONT_CHANGE_QSFP_PAGE;
7596 : :
7597 : 0 : i40e_mdio_if_number_selection(hw, set_mdio, mdio_num, cmd);
7598 : :
7599 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
7600 : :
7601 : 0 : return status;
7602 : : }
7603 : :
7604 : : /**
7605 : : * i40e_aq_get_phy_register_ext
7606 : : * @hw: pointer to the hw struct
7607 : : * @phy_select: select which phy should be accessed
7608 : : * @dev_addr: PHY device address
7609 : : * @page_change: enable auto page change
7610 : : * @set_mdio: use MDIO I/F number specified by mdio_num
7611 : : * @mdio_num: MDIO I/F number
7612 : : * @reg_addr: PHY register address
7613 : : * @reg_val: read register value
7614 : : * @cmd_details: pointer to command details structure or NULL
7615 : : *
7616 : : * Read the external PHY register.
7617 : : * NOTE: In common cases MDIO I/F number should not be changed, thats why you
7618 : : * may use simple wrapper i40e_aq_get_phy_register.
7619 : : **/
7620 : : enum i40e_status_code
7621 : 0 : i40e_aq_get_phy_register_ext(struct i40e_hw *hw,
7622 : : u8 phy_select, u8 dev_addr, bool page_change,
7623 : : bool set_mdio, u8 mdio_num,
7624 : : u32 reg_addr, u32 *reg_val,
7625 : : struct i40e_asq_cmd_details *cmd_details)
7626 : : {
7627 : : struct i40e_aq_desc desc;
7628 : : struct i40e_aqc_phy_register_access *cmd =
7629 : : (struct i40e_aqc_phy_register_access *)&desc.params.raw;
7630 : : enum i40e_status_code status;
7631 : :
7632 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
7633 : : i40e_aqc_opc_get_phy_register);
7634 : :
7635 : 0 : cmd->phy_interface = phy_select;
7636 : 0 : cmd->dev_addres = dev_addr;
7637 : 0 : cmd->reg_address = CPU_TO_LE32(reg_addr);
7638 : :
7639 [ # # ]: 0 : if (!page_change)
7640 : 0 : cmd->cmd_flags = I40E_AQ_PHY_REG_ACCESS_DONT_CHANGE_QSFP_PAGE;
7641 : :
7642 : 0 : i40e_mdio_if_number_selection(hw, set_mdio, mdio_num, cmd);
7643 : :
7644 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
7645 [ # # ]: 0 : if (!status)
7646 : 0 : *reg_val = LE32_TO_CPU(cmd->reg_value);
7647 : :
7648 : 0 : return status;
7649 : : }
7650 : :
7651 : : /**
7652 : : * i40e_aq_run_phy_activity
7653 : : * @hw: pointer to the hw struct
7654 : : * @activity_id: ID of DNL activity to run
7655 : : * @dnl_opcode: opcode passed to DNL script
7656 : : * @cmd_status: pointer to memory to write return value of DNL script
7657 : : * @data0: pointer to memory for first 4 bytes of data returned by DNL script
7658 : : * @data1: pointer to memory for last 4 bytes of data returned by DNL script
7659 : : * @cmd_details: pointer to command details structure or NULL
7660 : : *
7661 : : * Run DNL admin command.
7662 : : **/
7663 : : enum i40e_status_code
7664 : 0 : i40e_aq_run_phy_activity(struct i40e_hw *hw, u16 activity_id, u32 dnl_opcode,
7665 : : u32 *cmd_status, u32 *data0, u32 *data1,
7666 : : struct i40e_asq_cmd_details *cmd_details)
7667 : : {
7668 : : struct i40e_aqc_run_phy_activity *cmd;
7669 : : enum i40e_status_code retval;
7670 : : struct i40e_aq_desc desc;
7671 : :
7672 : : cmd = (struct i40e_aqc_run_phy_activity *)&desc.params.raw;
7673 : :
7674 [ # # # # ]: 0 : if (!cmd_status || !data0 || !data1) {
7675 : : retval = I40E_ERR_PARAM;
7676 : 0 : goto err;
7677 : : }
7678 : :
7679 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
7680 : : i40e_aqc_opc_run_phy_activity);
7681 : :
7682 : 0 : cmd->activity_id = CPU_TO_LE16(activity_id);
7683 : 0 : cmd->params.cmd.dnl_opcode = CPU_TO_LE32(dnl_opcode);
7684 : :
7685 : 0 : retval = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
7686 [ # # ]: 0 : if (retval)
7687 : 0 : goto err;
7688 : :
7689 : 0 : *cmd_status = LE32_TO_CPU(cmd->params.resp.cmd_status);
7690 : 0 : *data0 = LE32_TO_CPU(cmd->params.resp.data0);
7691 : 0 : *data1 = LE32_TO_CPU(cmd->params.resp.data1);
7692 : 0 : err:
7693 : 0 : return retval;
7694 : : }
7695 : :
7696 : : #ifdef VF_DRIVER
7697 : :
7698 : : /**
7699 : : * i40e_aq_send_msg_to_pf
7700 : : * @hw: pointer to the hardware structure
7701 : : * @v_opcode: opcodes for VF-PF communication
7702 : : * @v_retval: return error code
7703 : : * @msg: pointer to the msg buffer
7704 : : * @msglen: msg length
7705 : : * @cmd_details: pointer to command details
7706 : : *
7707 : : * Send message to PF driver using admin queue. By default, this message
7708 : : * is sent asynchronously, i.e. i40e_asq_send_command() does not wait for
7709 : : * completion before returning.
7710 : : **/
7711 : 0 : enum i40e_status_code i40e_aq_send_msg_to_pf(struct i40e_hw *hw,
7712 : : enum virtchnl_ops v_opcode,
7713 : : enum i40e_status_code v_retval,
7714 : : u8 *msg, u16 msglen,
7715 : : struct i40e_asq_cmd_details *cmd_details)
7716 : : {
7717 : : struct i40e_aq_desc desc;
7718 : : struct i40e_asq_cmd_details details;
7719 : : enum i40e_status_code status;
7720 : :
7721 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_pf);
7722 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_SI);
7723 : 0 : desc.cookie_high = CPU_TO_LE32(v_opcode);
7724 : 0 : desc.cookie_low = CPU_TO_LE32(v_retval);
7725 [ # # ]: 0 : if (msglen) {
7726 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF
7727 : : | I40E_AQ_FLAG_RD));
7728 [ # # ]: 0 : if (msglen > I40E_AQ_LARGE_BUF)
7729 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
7730 : 0 : desc.datalen = CPU_TO_LE16(msglen);
7731 : : }
7732 [ # # ]: 0 : if (!cmd_details) {
7733 : : i40e_memset(&details, 0, sizeof(details), I40E_NONDMA_MEM);
7734 : 0 : details.async = true;
7735 : : cmd_details = &details;
7736 : : }
7737 : 0 : status = i40e_asq_send_command(hw, (struct i40e_aq_desc *)&desc, msg,
7738 : : msglen, cmd_details);
7739 : 0 : return status;
7740 : : }
7741 : :
7742 : : /**
7743 : : * i40e_vf_parse_hw_config
7744 : : * @hw: pointer to the hardware structure
7745 : : * @msg: pointer to the virtual channel VF resource structure
7746 : : *
7747 : : * Given a VF resource message from the PF, populate the hw struct
7748 : : * with appropriate information.
7749 : : **/
7750 : 0 : void i40e_vf_parse_hw_config(struct i40e_hw *hw,
7751 : : struct virtchnl_vf_resource *msg)
7752 : : {
7753 : : struct virtchnl_vsi_resource *vsi_res;
7754 : : int i;
7755 : :
7756 : 0 : vsi_res = &msg->vsi_res[0];
7757 : :
7758 : 0 : hw->dev_caps.num_vsis = msg->num_vsis;
7759 : 0 : hw->dev_caps.num_rx_qp = msg->num_queue_pairs;
7760 : 0 : hw->dev_caps.num_tx_qp = msg->num_queue_pairs;
7761 : 0 : hw->dev_caps.num_msix_vectors_vf = msg->max_vectors;
7762 : 0 : hw->dev_caps.dcb = msg->vf_cap_flags &
7763 : : VIRTCHNL_VF_OFFLOAD_L2;
7764 : 0 : hw->dev_caps.iwarp = (msg->vf_cap_flags &
7765 : 0 : VIRTCHNL_VF_OFFLOAD_IWARP) ? 1 : 0;
7766 [ # # ]: 0 : for (i = 0; i < msg->num_vsis; i++) {
7767 [ # # ]: 0 : if (vsi_res->vsi_type == VIRTCHNL_VSI_SRIOV) {
7768 [ # # ]: 0 : i40e_memcpy(hw->mac.perm_addr,
7769 : : vsi_res->default_mac_addr,
7770 : : ETH_ALEN,
7771 : : I40E_NONDMA_TO_NONDMA);
7772 [ # # ]: 0 : i40e_memcpy(hw->mac.addr, vsi_res->default_mac_addr,
7773 : : ETH_ALEN,
7774 : : I40E_NONDMA_TO_NONDMA);
7775 : : }
7776 : 0 : vsi_res++;
7777 : : }
7778 : 0 : }
7779 : :
7780 : : /**
7781 : : * i40e_vf_reset
7782 : : * @hw: pointer to the hardware structure
7783 : : *
7784 : : * Send a VF_RESET message to the PF. Does not wait for response from PF
7785 : : * as none will be forthcoming. Immediately after calling this function,
7786 : : * the admin queue should be shut down and (optionally) reinitialized.
7787 : : **/
7788 : 0 : enum i40e_status_code i40e_vf_reset(struct i40e_hw *hw)
7789 : : {
7790 : 0 : return i40e_aq_send_msg_to_pf(hw, VIRTCHNL_OP_RESET_VF,
7791 : : I40E_SUCCESS, NULL, 0, NULL);
7792 : : }
7793 : : #endif /* VF_DRIVER */
7794 : :
7795 : : /**
7796 : : * i40e_aq_set_arp_proxy_config
7797 : : * @hw: pointer to the HW structure
7798 : : * @proxy_config: pointer to proxy config command table struct
7799 : : * @cmd_details: pointer to command details
7800 : : *
7801 : : * Set ARP offload parameters from pre-populated
7802 : : * i40e_aqc_arp_proxy_data struct
7803 : : **/
7804 : 0 : enum i40e_status_code i40e_aq_set_arp_proxy_config(struct i40e_hw *hw,
7805 : : struct i40e_aqc_arp_proxy_data *proxy_config,
7806 : : struct i40e_asq_cmd_details *cmd_details)
7807 : : {
7808 : : struct i40e_aq_desc desc;
7809 : : enum i40e_status_code status;
7810 : :
7811 [ # # ]: 0 : if (!proxy_config)
7812 : : return I40E_ERR_PARAM;
7813 : :
7814 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_set_proxy_config);
7815 : :
7816 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
7817 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
7818 : 0 : desc.params.external.addr_high =
7819 : 0 : CPU_TO_LE32(I40E_HI_DWORD((u64)proxy_config));
7820 : 0 : desc.params.external.addr_low =
7821 : 0 : CPU_TO_LE32(I40E_LO_DWORD((u64)proxy_config));
7822 : 0 : desc.datalen = CPU_TO_LE16(sizeof(struct i40e_aqc_arp_proxy_data));
7823 : :
7824 : 0 : status = i40e_asq_send_command(hw, &desc, proxy_config,
7825 : : sizeof(struct i40e_aqc_arp_proxy_data),
7826 : : cmd_details);
7827 : :
7828 : 0 : return status;
7829 : : }
7830 : :
7831 : : /**
7832 : : * i40e_aq_set_ns_proxy_table_entry
7833 : : * @hw: pointer to the HW structure
7834 : : * @ns_proxy_table_entry: pointer to NS table entry command struct
7835 : : * @cmd_details: pointer to command details
7836 : : *
7837 : : * Set IPv6 Neighbor Solicitation (NS) protocol offload parameters
7838 : : * from pre-populated i40e_aqc_ns_proxy_data struct
7839 : : **/
7840 : 0 : enum i40e_status_code i40e_aq_set_ns_proxy_table_entry(struct i40e_hw *hw,
7841 : : struct i40e_aqc_ns_proxy_data *ns_proxy_table_entry,
7842 : : struct i40e_asq_cmd_details *cmd_details)
7843 : : {
7844 : : struct i40e_aq_desc desc;
7845 : : enum i40e_status_code status;
7846 : :
7847 [ # # ]: 0 : if (!ns_proxy_table_entry)
7848 : : return I40E_ERR_PARAM;
7849 : :
7850 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
7851 : : i40e_aqc_opc_set_ns_proxy_table_entry);
7852 : :
7853 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
7854 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
7855 : 0 : desc.params.external.addr_high =
7856 : 0 : CPU_TO_LE32(I40E_HI_DWORD((u64)ns_proxy_table_entry));
7857 : 0 : desc.params.external.addr_low =
7858 : 0 : CPU_TO_LE32(I40E_LO_DWORD((u64)ns_proxy_table_entry));
7859 : 0 : desc.datalen = CPU_TO_LE16(sizeof(struct i40e_aqc_ns_proxy_data));
7860 : :
7861 : 0 : status = i40e_asq_send_command(hw, &desc, ns_proxy_table_entry,
7862 : : sizeof(struct i40e_aqc_ns_proxy_data),
7863 : : cmd_details);
7864 : :
7865 : 0 : return status;
7866 : : }
7867 : :
7868 : : /**
7869 : : * i40e_aq_set_clear_wol_filter
7870 : : * @hw: pointer to the hw struct
7871 : : * @filter_index: index of filter to modify (0-7)
7872 : : * @filter: buffer containing filter to be set
7873 : : * @set_filter: true to set filter, false to clear filter
7874 : : * @no_wol_tco: if true, pass through packets cannot cause wake-up
7875 : : * if false, pass through packets may cause wake-up
7876 : : * @filter_valid: true if filter action is valid
7877 : : * @no_wol_tco_valid: true if no WoL in TCO traffic action valid
7878 : : * @cmd_details: pointer to command details structure or NULL
7879 : : *
7880 : : * Set or clear WoL filter for port attached to the PF
7881 : : **/
7882 : 0 : enum i40e_status_code i40e_aq_set_clear_wol_filter(struct i40e_hw *hw,
7883 : : u8 filter_index,
7884 : : struct i40e_aqc_set_wol_filter_data *filter,
7885 : : bool set_filter, bool no_wol_tco,
7886 : : bool filter_valid, bool no_wol_tco_valid,
7887 : : struct i40e_asq_cmd_details *cmd_details)
7888 : : {
7889 : : struct i40e_aq_desc desc;
7890 : : struct i40e_aqc_set_wol_filter *cmd =
7891 : : (struct i40e_aqc_set_wol_filter *)&desc.params.raw;
7892 : : enum i40e_status_code status;
7893 : : u16 cmd_flags = 0;
7894 : : u16 valid_flags = 0;
7895 : : u16 buff_len = 0;
7896 : :
7897 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_set_wol_filter);
7898 : :
7899 [ # # ]: 0 : if (filter_index >= I40E_AQC_MAX_NUM_WOL_FILTERS)
7900 : : return I40E_ERR_PARAM;
7901 : 0 : cmd->filter_index = CPU_TO_LE16(filter_index);
7902 : :
7903 [ # # ]: 0 : if (set_filter) {
7904 [ # # ]: 0 : if (!filter)
7905 : : return I40E_ERR_PARAM;
7906 : :
7907 : : cmd_flags |= I40E_AQC_SET_WOL_FILTER;
7908 : : cmd_flags |= I40E_AQC_SET_WOL_FILTER_WOL_PRESERVE_ON_PFR;
7909 : : }
7910 : :
7911 [ # # ]: 0 : if (no_wol_tco)
7912 : 0 : cmd_flags |= I40E_AQC_SET_WOL_FILTER_NO_TCO_WOL;
7913 : 0 : cmd->cmd_flags = CPU_TO_LE16(cmd_flags);
7914 : :
7915 [ # # ]: 0 : if (filter_valid)
7916 : : valid_flags |= I40E_AQC_SET_WOL_FILTER_ACTION_VALID;
7917 [ # # ]: 0 : if (no_wol_tco_valid)
7918 : 0 : valid_flags |= I40E_AQC_SET_WOL_FILTER_NO_TCO_ACTION_VALID;
7919 : 0 : cmd->valid_flags = CPU_TO_LE16(valid_flags);
7920 : :
7921 : : buff_len = sizeof(*filter);
7922 : 0 : desc.datalen = CPU_TO_LE16(buff_len);
7923 : :
7924 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
7925 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
7926 : :
7927 : 0 : cmd->address_high = CPU_TO_LE32(I40E_HI_DWORD((u64)filter));
7928 : 0 : cmd->address_low = CPU_TO_LE32(I40E_LO_DWORD((u64)filter));
7929 : :
7930 : 0 : status = i40e_asq_send_command(hw, &desc, filter,
7931 : : buff_len, cmd_details);
7932 : :
7933 : 0 : return status;
7934 : : }
7935 : :
7936 : : /**
7937 : : * i40e_aq_get_wake_event_reason
7938 : : * @hw: pointer to the hw struct
7939 : : * @wake_reason: return value, index of matching filter
7940 : : * @cmd_details: pointer to command details structure or NULL
7941 : : *
7942 : : * Get information for the reason of a Wake Up event
7943 : : **/
7944 : 0 : enum i40e_status_code i40e_aq_get_wake_event_reason(struct i40e_hw *hw,
7945 : : u16 *wake_reason,
7946 : : struct i40e_asq_cmd_details *cmd_details)
7947 : : {
7948 : : struct i40e_aq_desc desc;
7949 : : struct i40e_aqc_get_wake_reason_completion *resp =
7950 : : (struct i40e_aqc_get_wake_reason_completion *)&desc.params.raw;
7951 : : enum i40e_status_code status;
7952 : :
7953 : 0 : i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_wake_reason);
7954 : :
7955 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
7956 : :
7957 [ # # ]: 0 : if (status == I40E_SUCCESS)
7958 : 0 : *wake_reason = LE16_TO_CPU(resp->wake_reason);
7959 : :
7960 : 0 : return status;
7961 : : }
7962 : :
7963 : : /**
7964 : : * i40e_aq_clear_all_wol_filters
7965 : : * @hw: pointer to the hw struct
7966 : : * @cmd_details: pointer to command details structure or NULL
7967 : : *
7968 : : * Get information for the reason of a Wake Up event
7969 : : **/
7970 : 0 : enum i40e_status_code i40e_aq_clear_all_wol_filters(struct i40e_hw *hw,
7971 : : struct i40e_asq_cmd_details *cmd_details)
7972 : : {
7973 : : struct i40e_aq_desc desc;
7974 : : enum i40e_status_code status;
7975 : :
7976 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
7977 : : i40e_aqc_opc_clear_all_wol_filters);
7978 : :
7979 : 0 : status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
7980 : :
7981 : 0 : return status;
7982 : : }
7983 : :
7984 : : /**
7985 : : * i40e_aq_write_ddp - Write dynamic device personalization (ddp)
7986 : : * @hw: pointer to the hw struct
7987 : : * @buff: command buffer (size in bytes = buff_size)
7988 : : * @buff_size: buffer size in bytes
7989 : : * @track_id: package tracking id
7990 : : * @error_offset: returns error offset
7991 : : * @error_info: returns error information
7992 : : * @cmd_details: pointer to command details structure or NULL
7993 : : **/
7994 : : enum
7995 : 0 : i40e_status_code i40e_aq_write_ddp(struct i40e_hw *hw, void *buff,
7996 : : u16 buff_size, u32 track_id,
7997 : : u32 *error_offset, u32 *error_info,
7998 : : struct i40e_asq_cmd_details *cmd_details)
7999 : : {
8000 : : struct i40e_aq_desc desc;
8001 : : struct i40e_aqc_write_personalization_profile *cmd =
8002 : : (struct i40e_aqc_write_personalization_profile *)
8003 : : &desc.params.raw;
8004 : : struct i40e_aqc_write_ddp_resp *resp;
8005 : : enum i40e_status_code status;
8006 : :
8007 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
8008 : : i40e_aqc_opc_write_personalization_profile);
8009 : :
8010 : 0 : desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
8011 [ # # ]: 0 : if (buff_size > I40E_AQ_LARGE_BUF)
8012 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
8013 : :
8014 : 0 : desc.datalen = CPU_TO_LE16(buff_size);
8015 : :
8016 : 0 : cmd->profile_track_id = CPU_TO_LE32(track_id);
8017 : :
8018 : 0 : status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
8019 [ # # ]: 0 : if (!status) {
8020 : : resp = (struct i40e_aqc_write_ddp_resp *)&desc.params.raw;
8021 [ # # ]: 0 : if (error_offset)
8022 : 0 : *error_offset = LE32_TO_CPU(resp->error_offset);
8023 [ # # ]: 0 : if (error_info)
8024 : 0 : *error_info = LE32_TO_CPU(resp->error_info);
8025 : : }
8026 : :
8027 : 0 : return status;
8028 : : }
8029 : :
8030 : : /**
8031 : : * i40e_aq_get_ddp_list - Read dynamic device personalization (ddp)
8032 : : * @hw: pointer to the hw struct
8033 : : * @buff: command buffer (size in bytes = buff_size)
8034 : : * @buff_size: buffer size in bytes
8035 : : * @flags: AdminQ command flags
8036 : : * @cmd_details: pointer to command details structure or NULL
8037 : : **/
8038 : : enum
8039 : 0 : i40e_status_code i40e_aq_get_ddp_list(struct i40e_hw *hw, void *buff,
8040 : : u16 buff_size, u8 flags,
8041 : : struct i40e_asq_cmd_details *cmd_details)
8042 : : {
8043 : : struct i40e_aq_desc desc;
8044 : : struct i40e_aqc_get_applied_profiles *cmd =
8045 : : (struct i40e_aqc_get_applied_profiles *)&desc.params.raw;
8046 : : enum i40e_status_code status;
8047 : :
8048 : 0 : i40e_fill_default_direct_cmd_desc(&desc,
8049 : : i40e_aqc_opc_get_personalization_profile_list);
8050 : :
8051 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
8052 [ # # ]: 0 : if (buff_size > I40E_AQ_LARGE_BUF)
8053 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
8054 : 0 : desc.datalen = CPU_TO_LE16(buff_size);
8055 : :
8056 : 0 : cmd->flags = flags;
8057 : :
8058 : 0 : status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
8059 : :
8060 : 0 : return status;
8061 : : }
8062 : :
8063 : : /**
8064 : : * i40e_find_segment_in_package
8065 : : * @segment_type: the segment type to search for (i.e., SEGMENT_TYPE_I40E)
8066 : : * @pkg_hdr: pointer to the package header to be searched
8067 : : *
8068 : : * This function searches a package file for a particular segment type. On
8069 : : * success it returns a pointer to the segment header, otherwise it will
8070 : : * return NULL.
8071 : : **/
8072 : : struct i40e_generic_seg_header *
8073 : 0 : i40e_find_segment_in_package(u32 segment_type,
8074 : : struct i40e_package_header *pkg_hdr)
8075 : : {
8076 : : struct i40e_generic_seg_header *segment;
8077 : : u32 i;
8078 : :
8079 : : /* Search all package segments for the requested segment type */
8080 [ # # ]: 0 : for (i = 0; i < pkg_hdr->segment_count; i++) {
8081 : 0 : segment =
8082 : : (struct i40e_generic_seg_header *)((u8 *)pkg_hdr +
8083 : 0 : pkg_hdr->segment_offset[i]);
8084 : :
8085 [ # # ]: 0 : if (segment->type == segment_type)
8086 : 0 : return segment;
8087 : : }
8088 : :
8089 : : return NULL;
8090 : : }
8091 : :
8092 : : /* Get section table in profile */
8093 : : #define I40E_SECTION_TABLE(profile, sec_tbl) \
8094 : : do { \
8095 : : struct i40e_profile_segment *p = (profile); \
8096 : : u32 count; \
8097 : : u32 *nvm; \
8098 : : count = p->device_table_count; \
8099 : : nvm = (u32 *)&p->device_table[count]; \
8100 : : sec_tbl = (struct i40e_section_table *)&nvm[nvm[0] + 1]; \
8101 : : } while (0)
8102 : :
8103 : : /* Get section header in profile */
8104 : : #define I40E_SECTION_HEADER(profile, offset) \
8105 : : (struct i40e_profile_section_header *)((u8 *)(profile) + (offset))
8106 : :
8107 : : /**
8108 : : * i40e_find_section_in_profile
8109 : : * @section_type: the section type to search for (i.e., SECTION_TYPE_NOTE)
8110 : : * @profile: pointer to the i40e segment header to be searched
8111 : : *
8112 : : * This function searches i40e segment for a particular section type. On
8113 : : * success it returns a pointer to the section header, otherwise it will
8114 : : * return NULL.
8115 : : **/
8116 : : struct i40e_profile_section_header *
8117 : 0 : i40e_find_section_in_profile(u32 section_type,
8118 : : struct i40e_profile_segment *profile)
8119 : : {
8120 : : struct i40e_profile_section_header *sec;
8121 : : struct i40e_section_table *sec_tbl;
8122 : : u32 sec_off;
8123 : : u32 i;
8124 : :
8125 [ # # ]: 0 : if (profile->header.type != SEGMENT_TYPE_I40E)
8126 : : return NULL;
8127 : :
8128 : 0 : I40E_SECTION_TABLE(profile, sec_tbl);
8129 : :
8130 [ # # ]: 0 : for (i = 0; i < sec_tbl->section_count; i++) {
8131 : 0 : sec_off = sec_tbl->section_offset[i];
8132 : 0 : sec = I40E_SECTION_HEADER(profile, sec_off);
8133 [ # # ]: 0 : if (sec->section.type == section_type)
8134 : 0 : return sec;
8135 : : }
8136 : :
8137 : : return NULL;
8138 : : }
8139 : :
8140 : : /**
8141 : : * i40e_ddp_exec_aq_section - Execute generic AQ for DDP
8142 : : * @hw: pointer to the hw struct
8143 : : * @aq: command buffer containing all data to execute AQ
8144 : : **/
8145 : : STATIC enum
8146 : 0 : i40e_status_code i40e_ddp_exec_aq_section(struct i40e_hw *hw,
8147 : : struct i40e_profile_aq_section *aq)
8148 : : {
8149 : : enum i40e_status_code status;
8150 : : struct i40e_aq_desc desc;
8151 : : u8 *msg = NULL;
8152 : : u16 msglen;
8153 : :
8154 : 0 : i40e_fill_default_direct_cmd_desc(&desc, aq->opcode);
8155 : 0 : desc.flags |= CPU_TO_LE16(aq->flags);
8156 [ # # ]: 0 : i40e_memcpy(desc.params.raw, aq->param, sizeof(desc.params.raw),
8157 : : I40E_NONDMA_TO_NONDMA);
8158 : :
8159 : 0 : msglen = aq->datalen;
8160 [ # # ]: 0 : if (msglen) {
8161 : 0 : desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF |
8162 : : I40E_AQ_FLAG_RD));
8163 [ # # ]: 0 : if (msglen > I40E_AQ_LARGE_BUF)
8164 : 0 : desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
8165 : 0 : desc.datalen = CPU_TO_LE16(msglen);
8166 : 0 : msg = &aq->data[0];
8167 : : }
8168 : :
8169 : 0 : status = i40e_asq_send_command(hw, &desc, msg, msglen, NULL);
8170 : :
8171 [ # # ]: 0 : if (status != I40E_SUCCESS) {
8172 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_PACKAGE,
8173 : : "unable to exec DDP AQ opcode %u, error %d\n",
8174 : : aq->opcode, status);
8175 : 0 : return status;
8176 : : }
8177 : :
8178 : : /* copy returned desc to aq_buf */
8179 : : i40e_memcpy(aq->param, desc.params.raw, sizeof(desc.params.raw),
8180 : : I40E_NONDMA_TO_NONDMA);
8181 : :
8182 : : return I40E_SUCCESS;
8183 : : }
8184 : :
8185 : : /**
8186 : : * i40e_validate_profile
8187 : : * @hw: pointer to the hardware structure
8188 : : * @profile: pointer to the profile segment of the package to be validated
8189 : : * @track_id: package tracking id
8190 : : * @rollback: flag if the profile is for rollback.
8191 : : *
8192 : : * Validates supported devices and profile's sections.
8193 : : */
8194 : : STATIC enum i40e_status_code
8195 : 0 : i40e_validate_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
8196 : : u32 track_id, bool rollback)
8197 : : {
8198 : : struct i40e_profile_section_header *sec = NULL;
8199 : : enum i40e_status_code status = I40E_SUCCESS;
8200 : : struct i40e_section_table *sec_tbl;
8201 : : u32 vendor_dev_id;
8202 : : u32 dev_cnt;
8203 : : u32 sec_off;
8204 : : u32 i;
8205 : :
8206 [ # # ]: 0 : if (track_id == I40E_DDP_TRACKID_INVALID) {
8207 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_PACKAGE, "Invalid track_id\n");
8208 : 0 : return I40E_NOT_SUPPORTED;
8209 : : }
8210 : :
8211 : 0 : dev_cnt = profile->device_table_count;
8212 [ # # ]: 0 : for (i = 0; i < dev_cnt; i++) {
8213 : 0 : vendor_dev_id = profile->device_table[i].vendor_dev_id;
8214 [ # # ]: 0 : if ((vendor_dev_id >> 16) == I40E_INTEL_VENDOR_ID &&
8215 [ # # ]: 0 : hw->device_id == (vendor_dev_id & 0xFFFF))
8216 : : break;
8217 : : }
8218 [ # # ]: 0 : if (dev_cnt && (i == dev_cnt)) {
8219 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_PACKAGE,
8220 : : "Device doesn't support DDP\n");
8221 : 0 : return I40E_ERR_DEVICE_NOT_SUPPORTED;
8222 : : }
8223 : :
8224 : 0 : I40E_SECTION_TABLE(profile, sec_tbl);
8225 : :
8226 : : /* Validate sections types */
8227 [ # # ]: 0 : for (i = 0; i < sec_tbl->section_count; i++) {
8228 : 0 : sec_off = sec_tbl->section_offset[i];
8229 : 0 : sec = I40E_SECTION_HEADER(profile, sec_off);
8230 [ # # ]: 0 : if (rollback) {
8231 : 0 : if (sec->section.type == SECTION_TYPE_MMIO ||
8232 [ # # ]: 0 : sec->section.type == SECTION_TYPE_AQ ||
8233 : : sec->section.type == SECTION_TYPE_RB_AQ) {
8234 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_PACKAGE,
8235 : : "Not a roll-back package\n");
8236 : 0 : return I40E_NOT_SUPPORTED;
8237 : : }
8238 : : } else {
8239 [ # # ]: 0 : if (sec->section.type == SECTION_TYPE_RB_AQ ||
8240 : : sec->section.type == SECTION_TYPE_RB_MMIO) {
8241 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_PACKAGE,
8242 : : "Not an original package\n");
8243 : 0 : return I40E_NOT_SUPPORTED;
8244 : : }
8245 : : }
8246 : : }
8247 : :
8248 : : return status;
8249 : : }
8250 : :
8251 : : /**
8252 : : * i40e_write_profile
8253 : : * @hw: pointer to the hardware structure
8254 : : * @profile: pointer to the profile segment of the package to be downloaded
8255 : : * @track_id: package tracking id
8256 : : *
8257 : : * Handles the download of a complete package.
8258 : : */
8259 : : enum i40e_status_code
8260 : 0 : i40e_write_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
8261 : : u32 track_id)
8262 : : {
8263 : : enum i40e_status_code status = I40E_SUCCESS;
8264 : : struct i40e_section_table *sec_tbl;
8265 : : struct i40e_profile_section_header *sec = NULL;
8266 : : struct i40e_profile_aq_section *ddp_aq;
8267 : : u32 section_size = 0;
8268 : 0 : u32 offset = 0, info = 0;
8269 : : u32 sec_off;
8270 : : u32 i;
8271 : :
8272 : 0 : status = i40e_validate_profile(hw, profile, track_id, false);
8273 [ # # ]: 0 : if (status)
8274 : : return status;
8275 : :
8276 : 0 : I40E_SECTION_TABLE(profile, sec_tbl);
8277 : :
8278 [ # # ]: 0 : for (i = 0; i < sec_tbl->section_count; i++) {
8279 : 0 : sec_off = sec_tbl->section_offset[i];
8280 : 0 : sec = I40E_SECTION_HEADER(profile, sec_off);
8281 : : /* Process generic admin command */
8282 [ # # ]: 0 : if (sec->section.type == SECTION_TYPE_AQ) {
8283 : 0 : ddp_aq = (struct i40e_profile_aq_section *)&sec[1];
8284 : 0 : status = i40e_ddp_exec_aq_section(hw, ddp_aq);
8285 [ # # ]: 0 : if (status) {
8286 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_PACKAGE,
8287 : : "Failed to execute aq: section %d, opcode %u\n",
8288 : : i, ddp_aq->opcode);
8289 : : break;
8290 : : }
8291 : 0 : sec->section.type = SECTION_TYPE_RB_AQ;
8292 : : }
8293 : :
8294 : : /* Skip any non-mmio sections */
8295 [ # # ]: 0 : if (sec->section.type != SECTION_TYPE_MMIO)
8296 : 0 : continue;
8297 : :
8298 : 0 : section_size = sec->section.size +
8299 : : sizeof(struct i40e_profile_section_header);
8300 : :
8301 : : /* Write MMIO section */
8302 : 0 : status = i40e_aq_write_ddp(hw, (void *)sec, (u16)section_size,
8303 : : track_id, &offset, &info, NULL);
8304 [ # # ]: 0 : if (status) {
8305 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_PACKAGE,
8306 : : "Failed to write profile: section %d, offset %d, info %d\n",
8307 : : i, offset, info);
8308 : : break;
8309 : : }
8310 : : }
8311 : : return status;
8312 : : }
8313 : :
8314 : : /**
8315 : : * i40e_rollback_profile
8316 : : * @hw: pointer to the hardware structure
8317 : : * @profile: pointer to the profile segment of the package to be removed
8318 : : * @track_id: package tracking id
8319 : : *
8320 : : * Rolls back previously loaded package.
8321 : : */
8322 : : enum i40e_status_code
8323 : 0 : i40e_rollback_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
8324 : : u32 track_id)
8325 : : {
8326 : : struct i40e_profile_section_header *sec = NULL;
8327 : : enum i40e_status_code status = I40E_SUCCESS;
8328 : : struct i40e_section_table *sec_tbl;
8329 : 0 : u32 offset = 0, info = 0;
8330 : : u32 section_size = 0;
8331 : : u32 sec_off;
8332 : : int i;
8333 : :
8334 : 0 : status = i40e_validate_profile(hw, profile, track_id, true);
8335 [ # # ]: 0 : if (status)
8336 : : return status;
8337 : :
8338 : 0 : I40E_SECTION_TABLE(profile, sec_tbl);
8339 : :
8340 : : /* For rollback write sections in reverse */
8341 [ # # ]: 0 : for (i = sec_tbl->section_count - 1; i >= 0; i--) {
8342 : 0 : sec_off = sec_tbl->section_offset[i];
8343 : 0 : sec = I40E_SECTION_HEADER(profile, sec_off);
8344 : :
8345 : : /* Skip any non-rollback sections */
8346 [ # # ]: 0 : if (sec->section.type != SECTION_TYPE_RB_MMIO)
8347 : 0 : continue;
8348 : :
8349 : 0 : section_size = sec->section.size +
8350 : : sizeof(struct i40e_profile_section_header);
8351 : :
8352 : : /* Write roll-back MMIO section */
8353 : 0 : status = i40e_aq_write_ddp(hw, (void *)sec, (u16)section_size,
8354 : : track_id, &offset, &info, NULL);
8355 [ # # ]: 0 : if (status) {
8356 [ # # ]: 0 : i40e_debug(hw, I40E_DEBUG_PACKAGE,
8357 : : "Failed to write profile: section %d, offset %d, info %d\n",
8358 : : i, offset, info);
8359 : : break;
8360 : : }
8361 : : }
8362 : : return status;
8363 : : }
8364 : :
8365 : : /**
8366 : : * i40e_add_pinfo_to_list
8367 : : * @hw: pointer to the hardware structure
8368 : : * @profile: pointer to the profile segment of the package
8369 : : * @profile_info_sec: buffer for information section
8370 : : * @track_id: package tracking id
8371 : : *
8372 : : * Register a profile to the list of loaded profiles.
8373 : : */
8374 : : enum i40e_status_code
8375 : 0 : i40e_add_pinfo_to_list(struct i40e_hw *hw,
8376 : : struct i40e_profile_segment *profile,
8377 : : u8 *profile_info_sec, u32 track_id)
8378 : : {
8379 : : enum i40e_status_code status = I40E_SUCCESS;
8380 : : struct i40e_profile_section_header *sec = NULL;
8381 : : struct i40e_profile_info *pinfo;
8382 : 0 : u32 offset = 0, info = 0;
8383 : :
8384 : : sec = (struct i40e_profile_section_header *)profile_info_sec;
8385 : 0 : sec->tbl_size = 1;
8386 : 0 : sec->data_end = sizeof(struct i40e_profile_section_header) +
8387 : : sizeof(struct i40e_profile_info);
8388 : 0 : sec->section.type = SECTION_TYPE_INFO;
8389 : 0 : sec->section.offset = sizeof(struct i40e_profile_section_header);
8390 : 0 : sec->section.size = sizeof(struct i40e_profile_info);
8391 : 0 : pinfo = (struct i40e_profile_info *)(profile_info_sec +
8392 : : sec->section.offset);
8393 : 0 : pinfo->track_id = track_id;
8394 : 0 : pinfo->version = profile->version;
8395 : 0 : pinfo->op = I40E_DDP_ADD_TRACKID;
8396 [ # # ]: 0 : i40e_memcpy(pinfo->name, profile->name, I40E_DDP_NAME_SIZE,
8397 : : I40E_NONDMA_TO_NONDMA);
8398 : :
8399 : 0 : status = i40e_aq_write_ddp(hw, (void *)sec, sec->data_end,
8400 : : track_id, &offset, &info, NULL);
8401 : 0 : return status;
8402 : : }
|