net/iavf/base: rename error code enum
[dpdk.git] / drivers / net / iavf / base / iavf_common.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2013 - 2015 Intel Corporation
3  */
4
5 #include "iavf_type.h"
6 #include "iavf_adminq.h"
7 #include "iavf_prototype.h"
8 #include "virtchnl.h"
9
10
11 /**
12  * iavf_set_mac_type - Sets MAC type
13  * @hw: pointer to the HW structure
14  *
15  * This function sets the mac type of the adapter based on the
16  * vendor ID and device ID stored in the hw structure.
17  **/
18 enum iavf_status iavf_set_mac_type(struct iavf_hw *hw)
19 {
20         enum iavf_status status = IAVF_SUCCESS;
21
22         DEBUGFUNC("iavf_set_mac_type\n");
23
24         if (hw->vendor_id == IAVF_INTEL_VENDOR_ID) {
25                 switch (hw->device_id) {
26         /* TODO: remove undefined device ID now, need to think how to
27          * remove them in share code
28          */
29                 case IAVF_DEV_ID_ADAPTIVE_VF:
30                         hw->mac.type = IAVF_MAC_VF;
31                         break;
32                 default:
33                         hw->mac.type = IAVF_MAC_GENERIC;
34                         break;
35                 }
36         } else {
37                 status = IAVF_ERR_DEVICE_NOT_SUPPORTED;
38         }
39
40         DEBUGOUT2("iavf_set_mac_type found mac: %d, returns: %d\n",
41                   hw->mac.type, status);
42         return status;
43 }
44
45 /**
46  * iavf_aq_str - convert AQ err code to a string
47  * @hw: pointer to the HW structure
48  * @aq_err: the AQ error code to convert
49  **/
50 const char *iavf_aq_str(struct iavf_hw *hw, enum iavf_admin_queue_err aq_err)
51 {
52         switch (aq_err) {
53         case IAVF_AQ_RC_OK:
54                 return "OK";
55         case IAVF_AQ_RC_EPERM:
56                 return "IAVF_AQ_RC_EPERM";
57         case IAVF_AQ_RC_ENOENT:
58                 return "IAVF_AQ_RC_ENOENT";
59         case IAVF_AQ_RC_ESRCH:
60                 return "IAVF_AQ_RC_ESRCH";
61         case IAVF_AQ_RC_EINTR:
62                 return "IAVF_AQ_RC_EINTR";
63         case IAVF_AQ_RC_EIO:
64                 return "IAVF_AQ_RC_EIO";
65         case IAVF_AQ_RC_ENXIO:
66                 return "IAVF_AQ_RC_ENXIO";
67         case IAVF_AQ_RC_E2BIG:
68                 return "IAVF_AQ_RC_E2BIG";
69         case IAVF_AQ_RC_EAGAIN:
70                 return "IAVF_AQ_RC_EAGAIN";
71         case IAVF_AQ_RC_ENOMEM:
72                 return "IAVF_AQ_RC_ENOMEM";
73         case IAVF_AQ_RC_EACCES:
74                 return "IAVF_AQ_RC_EACCES";
75         case IAVF_AQ_RC_EFAULT:
76                 return "IAVF_AQ_RC_EFAULT";
77         case IAVF_AQ_RC_EBUSY:
78                 return "IAVF_AQ_RC_EBUSY";
79         case IAVF_AQ_RC_EEXIST:
80                 return "IAVF_AQ_RC_EEXIST";
81         case IAVF_AQ_RC_EINVAL:
82                 return "IAVF_AQ_RC_EINVAL";
83         case IAVF_AQ_RC_ENOTTY:
84                 return "IAVF_AQ_RC_ENOTTY";
85         case IAVF_AQ_RC_ENOSPC:
86                 return "IAVF_AQ_RC_ENOSPC";
87         case IAVF_AQ_RC_ENOSYS:
88                 return "IAVF_AQ_RC_ENOSYS";
89         case IAVF_AQ_RC_ERANGE:
90                 return "IAVF_AQ_RC_ERANGE";
91         case IAVF_AQ_RC_EFLUSHED:
92                 return "IAVF_AQ_RC_EFLUSHED";
93         case IAVF_AQ_RC_BAD_ADDR:
94                 return "IAVF_AQ_RC_BAD_ADDR";
95         case IAVF_AQ_RC_EMODE:
96                 return "IAVF_AQ_RC_EMODE";
97         case IAVF_AQ_RC_EFBIG:
98                 return "IAVF_AQ_RC_EFBIG";
99         }
100
101         snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
102         return hw->err_str;
103 }
104
105 /**
106  * iavf_stat_str - convert status err code to a string
107  * @hw: pointer to the HW structure
108  * @stat_err: the status error code to convert
109  **/
110 const char *iavf_stat_str(struct iavf_hw *hw, enum iavf_status stat_err)
111 {
112         switch (stat_err) {
113         case IAVF_SUCCESS:
114                 return "OK";
115         case IAVF_ERR_NVM:
116                 return "IAVF_ERR_NVM";
117         case IAVF_ERR_NVM_CHECKSUM:
118                 return "IAVF_ERR_NVM_CHECKSUM";
119         case IAVF_ERR_PHY:
120                 return "IAVF_ERR_PHY";
121         case IAVF_ERR_CONFIG:
122                 return "IAVF_ERR_CONFIG";
123         case IAVF_ERR_PARAM:
124                 return "IAVF_ERR_PARAM";
125         case IAVF_ERR_MAC_TYPE:
126                 return "IAVF_ERR_MAC_TYPE";
127         case IAVF_ERR_UNKNOWN_PHY:
128                 return "IAVF_ERR_UNKNOWN_PHY";
129         case IAVF_ERR_LINK_SETUP:
130                 return "IAVF_ERR_LINK_SETUP";
131         case IAVF_ERR_ADAPTER_STOPPED:
132                 return "IAVF_ERR_ADAPTER_STOPPED";
133         case IAVF_ERR_INVALID_MAC_ADDR:
134                 return "IAVF_ERR_INVALID_MAC_ADDR";
135         case IAVF_ERR_DEVICE_NOT_SUPPORTED:
136                 return "IAVF_ERR_DEVICE_NOT_SUPPORTED";
137         case IAVF_ERR_MASTER_REQUESTS_PENDING:
138                 return "IAVF_ERR_MASTER_REQUESTS_PENDING";
139         case IAVF_ERR_INVALID_LINK_SETTINGS:
140                 return "IAVF_ERR_INVALID_LINK_SETTINGS";
141         case IAVF_ERR_AUTONEG_NOT_COMPLETE:
142                 return "IAVF_ERR_AUTONEG_NOT_COMPLETE";
143         case IAVF_ERR_RESET_FAILED:
144                 return "IAVF_ERR_RESET_FAILED";
145         case IAVF_ERR_SWFW_SYNC:
146                 return "IAVF_ERR_SWFW_SYNC";
147         case IAVF_ERR_NO_AVAILABLE_VSI:
148                 return "IAVF_ERR_NO_AVAILABLE_VSI";
149         case IAVF_ERR_NO_MEMORY:
150                 return "IAVF_ERR_NO_MEMORY";
151         case IAVF_ERR_BAD_PTR:
152                 return "IAVF_ERR_BAD_PTR";
153         case IAVF_ERR_RING_FULL:
154                 return "IAVF_ERR_RING_FULL";
155         case IAVF_ERR_INVALID_PD_ID:
156                 return "IAVF_ERR_INVALID_PD_ID";
157         case IAVF_ERR_INVALID_QP_ID:
158                 return "IAVF_ERR_INVALID_QP_ID";
159         case IAVF_ERR_INVALID_CQ_ID:
160                 return "IAVF_ERR_INVALID_CQ_ID";
161         case IAVF_ERR_INVALID_CEQ_ID:
162                 return "IAVF_ERR_INVALID_CEQ_ID";
163         case IAVF_ERR_INVALID_AEQ_ID:
164                 return "IAVF_ERR_INVALID_AEQ_ID";
165         case IAVF_ERR_INVALID_SIZE:
166                 return "IAVF_ERR_INVALID_SIZE";
167         case IAVF_ERR_INVALID_ARP_INDEX:
168                 return "IAVF_ERR_INVALID_ARP_INDEX";
169         case IAVF_ERR_INVALID_FPM_FUNC_ID:
170                 return "IAVF_ERR_INVALID_FPM_FUNC_ID";
171         case IAVF_ERR_QP_INVALID_MSG_SIZE:
172                 return "IAVF_ERR_QP_INVALID_MSG_SIZE";
173         case IAVF_ERR_QP_TOOMANY_WRS_POSTED:
174                 return "IAVF_ERR_QP_TOOMANY_WRS_POSTED";
175         case IAVF_ERR_INVALID_FRAG_COUNT:
176                 return "IAVF_ERR_INVALID_FRAG_COUNT";
177         case IAVF_ERR_QUEUE_EMPTY:
178                 return "IAVF_ERR_QUEUE_EMPTY";
179         case IAVF_ERR_INVALID_ALIGNMENT:
180                 return "IAVF_ERR_INVALID_ALIGNMENT";
181         case IAVF_ERR_FLUSHED_QUEUE:
182                 return "IAVF_ERR_FLUSHED_QUEUE";
183         case IAVF_ERR_INVALID_PUSH_PAGE_INDEX:
184                 return "IAVF_ERR_INVALID_PUSH_PAGE_INDEX";
185         case IAVF_ERR_INVALID_IMM_DATA_SIZE:
186                 return "IAVF_ERR_INVALID_IMM_DATA_SIZE";
187         case IAVF_ERR_TIMEOUT:
188                 return "IAVF_ERR_TIMEOUT";
189         case IAVF_ERR_OPCODE_MISMATCH:
190                 return "IAVF_ERR_OPCODE_MISMATCH";
191         case IAVF_ERR_CQP_COMPL_ERROR:
192                 return "IAVF_ERR_CQP_COMPL_ERROR";
193         case IAVF_ERR_INVALID_VF_ID:
194                 return "IAVF_ERR_INVALID_VF_ID";
195         case IAVF_ERR_INVALID_HMCFN_ID:
196                 return "IAVF_ERR_INVALID_HMCFN_ID";
197         case IAVF_ERR_BACKING_PAGE_ERROR:
198                 return "IAVF_ERR_BACKING_PAGE_ERROR";
199         case IAVF_ERR_NO_PBLCHUNKS_AVAILABLE:
200                 return "IAVF_ERR_NO_PBLCHUNKS_AVAILABLE";
201         case IAVF_ERR_INVALID_PBLE_INDEX:
202                 return "IAVF_ERR_INVALID_PBLE_INDEX";
203         case IAVF_ERR_INVALID_SD_INDEX:
204                 return "IAVF_ERR_INVALID_SD_INDEX";
205         case IAVF_ERR_INVALID_PAGE_DESC_INDEX:
206                 return "IAVF_ERR_INVALID_PAGE_DESC_INDEX";
207         case IAVF_ERR_INVALID_SD_TYPE:
208                 return "IAVF_ERR_INVALID_SD_TYPE";
209         case IAVF_ERR_MEMCPY_FAILED:
210                 return "IAVF_ERR_MEMCPY_FAILED";
211         case IAVF_ERR_INVALID_HMC_OBJ_INDEX:
212                 return "IAVF_ERR_INVALID_HMC_OBJ_INDEX";
213         case IAVF_ERR_INVALID_HMC_OBJ_COUNT:
214                 return "IAVF_ERR_INVALID_HMC_OBJ_COUNT";
215         case IAVF_ERR_INVALID_SRQ_ARM_LIMIT:
216                 return "IAVF_ERR_INVALID_SRQ_ARM_LIMIT";
217         case IAVF_ERR_SRQ_ENABLED:
218                 return "IAVF_ERR_SRQ_ENABLED";
219         case IAVF_ERR_ADMIN_QUEUE_ERROR:
220                 return "IAVF_ERR_ADMIN_QUEUE_ERROR";
221         case IAVF_ERR_ADMIN_QUEUE_TIMEOUT:
222                 return "IAVF_ERR_ADMIN_QUEUE_TIMEOUT";
223         case IAVF_ERR_BUF_TOO_SHORT:
224                 return "IAVF_ERR_BUF_TOO_SHORT";
225         case IAVF_ERR_ADMIN_QUEUE_FULL:
226                 return "IAVF_ERR_ADMIN_QUEUE_FULL";
227         case IAVF_ERR_ADMIN_QUEUE_NO_WORK:
228                 return "IAVF_ERR_ADMIN_QUEUE_NO_WORK";
229         case IAVF_ERR_BAD_IWARP_CQE:
230                 return "IAVF_ERR_BAD_IWARP_CQE";
231         case IAVF_ERR_NVM_BLANK_MODE:
232                 return "IAVF_ERR_NVM_BLANK_MODE";
233         case IAVF_ERR_NOT_IMPLEMENTED:
234                 return "IAVF_ERR_NOT_IMPLEMENTED";
235         case IAVF_ERR_PE_DOORBELL_NOT_ENABLED:
236                 return "IAVF_ERR_PE_DOORBELL_NOT_ENABLED";
237         case IAVF_ERR_DIAG_TEST_FAILED:
238                 return "IAVF_ERR_DIAG_TEST_FAILED";
239         case IAVF_ERR_NOT_READY:
240                 return "IAVF_ERR_NOT_READY";
241         case IAVF_NOT_SUPPORTED:
242                 return "IAVF_NOT_SUPPORTED";
243         case IAVF_ERR_FIRMWARE_API_VERSION:
244                 return "IAVF_ERR_FIRMWARE_API_VERSION";
245         case IAVF_ERR_ADMIN_QUEUE_CRITICAL_ERROR:
246                 return "IAVF_ERR_ADMIN_QUEUE_CRITICAL_ERROR";
247         }
248
249         snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
250         return hw->err_str;
251 }
252
253 /**
254  * iavf_debug_aq
255  * @hw: debug mask related to admin queue
256  * @mask: debug mask
257  * @desc: pointer to admin queue descriptor
258  * @buffer: pointer to command buffer
259  * @buf_len: max length of buffer
260  *
261  * Dumps debug log about adminq command with descriptor contents.
262  **/
263 void iavf_debug_aq(struct iavf_hw *hw, enum iavf_debug_mask mask, void *desc,
264                    void *buffer, u16 buf_len)
265 {
266         struct iavf_aq_desc *aq_desc = (struct iavf_aq_desc *)desc;
267         u8 *buf = (u8 *)buffer;
268         u16 len;
269         u16 i = 0;
270
271         if ((!(mask & hw->debug_mask)) || (desc == NULL))
272                 return;
273
274         len = LE16_TO_CPU(aq_desc->datalen);
275
276         iavf_debug(hw, mask,
277                    "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
278                    LE16_TO_CPU(aq_desc->opcode),
279                    LE16_TO_CPU(aq_desc->flags),
280                    LE16_TO_CPU(aq_desc->datalen),
281                    LE16_TO_CPU(aq_desc->retval));
282         iavf_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
283                    LE32_TO_CPU(aq_desc->cookie_high),
284                    LE32_TO_CPU(aq_desc->cookie_low));
285         iavf_debug(hw, mask, "\tparam (0,1)  0x%08X 0x%08X\n",
286                    LE32_TO_CPU(aq_desc->params.internal.param0),
287                    LE32_TO_CPU(aq_desc->params.internal.param1));
288         iavf_debug(hw, mask, "\taddr (h,l)   0x%08X 0x%08X\n",
289                    LE32_TO_CPU(aq_desc->params.external.addr_high),
290                    LE32_TO_CPU(aq_desc->params.external.addr_low));
291
292         if ((buffer != NULL) && (aq_desc->datalen != 0)) {
293                 iavf_debug(hw, mask, "AQ CMD Buffer:\n");
294                 if (buf_len < len)
295                         len = buf_len;
296                 /* write the full 16-byte chunks */
297                 for (i = 0; i < (len - 16); i += 16)
298                         iavf_debug(hw, mask,
299                                    "\t0x%04X  %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
300                                    i, buf[i], buf[i+1], buf[i+2], buf[i+3],
301                                    buf[i+4], buf[i+5], buf[i+6], buf[i+7],
302                                    buf[i+8], buf[i+9], buf[i+10], buf[i+11],
303                                    buf[i+12], buf[i+13], buf[i+14], buf[i+15]);
304                 /* the most we could have left is 16 bytes, pad with zeros */
305                 if (i < len) {
306                         char d_buf[16];
307                         int j, i_sav;
308
309                         i_sav = i;
310                         memset(d_buf, 0, sizeof(d_buf));
311                         for (j = 0; i < len; j++, i++)
312                                 d_buf[j] = buf[i];
313                         iavf_debug(hw, mask,
314                                    "\t0x%04X  %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
315                                    i_sav, d_buf[0], d_buf[1], d_buf[2], d_buf[3],
316                                    d_buf[4], d_buf[5], d_buf[6], d_buf[7],
317                                    d_buf[8], d_buf[9], d_buf[10], d_buf[11],
318                                    d_buf[12], d_buf[13], d_buf[14], d_buf[15]);
319                 }
320         }
321 }
322
323 /**
324  * iavf_check_asq_alive
325  * @hw: pointer to the hw struct
326  *
327  * Returns true if Queue is enabled else false.
328  **/
329 bool iavf_check_asq_alive(struct iavf_hw *hw)
330 {
331         if (hw->aq.asq.len)
332 #ifdef INTEGRATED_VF
333                 if (iavf_is_vf(hw))
334                         return !!(rd32(hw, hw->aq.asq.len) &
335                                 IAVF_ATQLEN1_ATQENABLE_MASK);
336 #else
337                 return !!(rd32(hw, hw->aq.asq.len) &
338                         IAVF_ATQLEN1_ATQENABLE_MASK);
339 #endif /* INTEGRATED_VF */
340         return false;
341 }
342
343 /**
344  * iavf_aq_queue_shutdown
345  * @hw: pointer to the hw struct
346  * @unloading: is the driver unloading itself
347  *
348  * Tell the Firmware that we're shutting down the AdminQ and whether
349  * or not the driver is unloading as well.
350  **/
351 enum iavf_status iavf_aq_queue_shutdown(struct iavf_hw *hw,
352                                              bool unloading)
353 {
354         struct iavf_aq_desc desc;
355         struct iavf_aqc_queue_shutdown *cmd =
356                 (struct iavf_aqc_queue_shutdown *)&desc.params.raw;
357         enum iavf_status status;
358
359         iavf_fill_default_direct_cmd_desc(&desc,
360                                           iavf_aqc_opc_queue_shutdown);
361
362         if (unloading)
363                 cmd->driver_unloading = CPU_TO_LE32(IAVF_AQ_DRIVER_UNLOADING);
364         status = iavf_asq_send_command(hw, &desc, NULL, 0, NULL);
365
366         return status;
367 }
368
369 /**
370  * iavf_aq_get_set_rss_lut
371  * @hw: pointer to the hardware structure
372  * @vsi_id: vsi fw index
373  * @pf_lut: for PF table set true, for VSI table set false
374  * @lut: pointer to the lut buffer provided by the caller
375  * @lut_size: size of the lut buffer
376  * @set: set true to set the table, false to get the table
377  *
378  * Internal function to get or set RSS look up table
379  **/
380 STATIC enum iavf_status iavf_aq_get_set_rss_lut(struct iavf_hw *hw,
381                                                      u16 vsi_id, bool pf_lut,
382                                                      u8 *lut, u16 lut_size,
383                                                      bool set)
384 {
385         enum iavf_status status;
386         struct iavf_aq_desc desc;
387         struct iavf_aqc_get_set_rss_lut *cmd_resp =
388                    (struct iavf_aqc_get_set_rss_lut *)&desc.params.raw;
389
390         if (set)
391                 iavf_fill_default_direct_cmd_desc(&desc,
392                                                   iavf_aqc_opc_set_rss_lut);
393         else
394                 iavf_fill_default_direct_cmd_desc(&desc,
395                                                   iavf_aqc_opc_get_rss_lut);
396
397         /* Indirect command */
398         desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_BUF);
399         desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_RD);
400
401         cmd_resp->vsi_id =
402                         CPU_TO_LE16((u16)((vsi_id <<
403                                           IAVF_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
404                                           IAVF_AQC_SET_RSS_LUT_VSI_ID_MASK));
405         cmd_resp->vsi_id |= CPU_TO_LE16((u16)IAVF_AQC_SET_RSS_LUT_VSI_VALID);
406
407         if (pf_lut)
408                 cmd_resp->flags |= CPU_TO_LE16((u16)
409                                         ((IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
410                                         IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
411                                         IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
412         else
413                 cmd_resp->flags |= CPU_TO_LE16((u16)
414                                         ((IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
415                                         IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
416                                         IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
417
418         status = iavf_asq_send_command(hw, &desc, lut, lut_size, NULL);
419
420         return status;
421 }
422
423 /**
424  * iavf_aq_get_rss_lut
425  * @hw: pointer to the hardware structure
426  * @vsi_id: vsi fw index
427  * @pf_lut: for PF table set true, for VSI table set false
428  * @lut: pointer to the lut buffer provided by the caller
429  * @lut_size: size of the lut buffer
430  *
431  * get the RSS lookup table, PF or VSI type
432  **/
433 enum iavf_status iavf_aq_get_rss_lut(struct iavf_hw *hw, u16 vsi_id,
434                                           bool pf_lut, u8 *lut, u16 lut_size)
435 {
436         return iavf_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
437                                        false);
438 }
439
440 /**
441  * iavf_aq_set_rss_lut
442  * @hw: pointer to the hardware structure
443  * @vsi_id: vsi fw index
444  * @pf_lut: for PF table set true, for VSI table set false
445  * @lut: pointer to the lut buffer provided by the caller
446  * @lut_size: size of the lut buffer
447  *
448  * set the RSS lookup table, PF or VSI type
449  **/
450 enum iavf_status iavf_aq_set_rss_lut(struct iavf_hw *hw, u16 vsi_id,
451                                           bool pf_lut, u8 *lut, u16 lut_size)
452 {
453         return iavf_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
454 }
455
456 /**
457  * iavf_aq_get_set_rss_key
458  * @hw: pointer to the hw struct
459  * @vsi_id: vsi fw index
460  * @key: pointer to key info struct
461  * @set: set true to set the key, false to get the key
462  *
463  * get the RSS key per VSI
464  **/
465 STATIC enum iavf_status iavf_aq_get_set_rss_key(struct iavf_hw *hw,
466                                       u16 vsi_id,
467                                       struct iavf_aqc_get_set_rss_key_data *key,
468                                       bool set)
469 {
470         enum iavf_status status;
471         struct iavf_aq_desc desc;
472         struct iavf_aqc_get_set_rss_key *cmd_resp =
473                         (struct iavf_aqc_get_set_rss_key *)&desc.params.raw;
474         u16 key_size = sizeof(struct iavf_aqc_get_set_rss_key_data);
475
476         if (set)
477                 iavf_fill_default_direct_cmd_desc(&desc,
478                                                   iavf_aqc_opc_set_rss_key);
479         else
480                 iavf_fill_default_direct_cmd_desc(&desc,
481                                                   iavf_aqc_opc_get_rss_key);
482
483         /* Indirect command */
484         desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_BUF);
485         desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_RD);
486
487         cmd_resp->vsi_id =
488                         CPU_TO_LE16((u16)((vsi_id <<
489                                           IAVF_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
490                                           IAVF_AQC_SET_RSS_KEY_VSI_ID_MASK));
491         cmd_resp->vsi_id |= CPU_TO_LE16((u16)IAVF_AQC_SET_RSS_KEY_VSI_VALID);
492
493         status = iavf_asq_send_command(hw, &desc, key, key_size, NULL);
494
495         return status;
496 }
497
498 /**
499  * iavf_aq_get_rss_key
500  * @hw: pointer to the hw struct
501  * @vsi_id: vsi fw index
502  * @key: pointer to key info struct
503  *
504  **/
505 enum iavf_status iavf_aq_get_rss_key(struct iavf_hw *hw,
506                                       u16 vsi_id,
507                                       struct iavf_aqc_get_set_rss_key_data *key)
508 {
509         return iavf_aq_get_set_rss_key(hw, vsi_id, key, false);
510 }
511
512 /**
513  * iavf_aq_set_rss_key
514  * @hw: pointer to the hw struct
515  * @vsi_id: vsi fw index
516  * @key: pointer to key info struct
517  *
518  * set the RSS key per VSI
519  **/
520 enum iavf_status iavf_aq_set_rss_key(struct iavf_hw *hw,
521                                       u16 vsi_id,
522                                       struct iavf_aqc_get_set_rss_key_data *key)
523 {
524         return iavf_aq_get_set_rss_key(hw, vsi_id, key, true);
525 }
526
527 /* The iavf_ptype_lookup table is used to convert from the 8-bit ptype in the
528  * hardware to a bit-field that can be used by SW to more easily determine the
529  * packet type.
530  *
531  * Macros are used to shorten the table lines and make this table human
532  * readable.
533  *
534  * We store the PTYPE in the top byte of the bit field - this is just so that
535  * we can check that the table doesn't have a row missing, as the index into
536  * the table should be the PTYPE.
537  *
538  * Typical work flow:
539  *
540  * IF NOT iavf_ptype_lookup[ptype].known
541  * THEN
542  *      Packet is unknown
543  * ELSE IF iavf_ptype_lookup[ptype].outer_ip == IAVF_RX_PTYPE_OUTER_IP
544  *      Use the rest of the fields to look at the tunnels, inner protocols, etc
545  * ELSE
546  *      Use the enum iavf_rx_l2_ptype to decode the packet type
547  * ENDIF
548  */
549
550 /* macro to make the table lines short */
551 #define IAVF_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
552         {       PTYPE, \
553                 1, \
554                 IAVF_RX_PTYPE_OUTER_##OUTER_IP, \
555                 IAVF_RX_PTYPE_OUTER_##OUTER_IP_VER, \
556                 IAVF_RX_PTYPE_##OUTER_FRAG, \
557                 IAVF_RX_PTYPE_TUNNEL_##T, \
558                 IAVF_RX_PTYPE_TUNNEL_END_##TE, \
559                 IAVF_RX_PTYPE_##TEF, \
560                 IAVF_RX_PTYPE_INNER_PROT_##I, \
561                 IAVF_RX_PTYPE_PAYLOAD_LAYER_##PL }
562
563 #define IAVF_PTT_UNUSED_ENTRY(PTYPE) \
564                 { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
565
566 /* shorter macros makes the table fit but are terse */
567 #define IAVF_RX_PTYPE_NOF               IAVF_RX_PTYPE_NOT_FRAG
568 #define IAVF_RX_PTYPE_FRG               IAVF_RX_PTYPE_FRAG
569 #define IAVF_RX_PTYPE_INNER_PROT_TS     IAVF_RX_PTYPE_INNER_PROT_TIMESYNC
570
571 /* Lookup table mapping the HW PTYPE to the bit field for decoding */
572 struct iavf_rx_ptype_decoded iavf_ptype_lookup[] = {
573         /* L2 Packet types */
574         IAVF_PTT_UNUSED_ENTRY(0),
575         IAVF_PTT(1,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
576         IAVF_PTT(2,  L2, NONE, NOF, NONE, NONE, NOF, TS,   PAY2),
577         IAVF_PTT(3,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
578         IAVF_PTT_UNUSED_ENTRY(4),
579         IAVF_PTT_UNUSED_ENTRY(5),
580         IAVF_PTT(6,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
581         IAVF_PTT(7,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
582         IAVF_PTT_UNUSED_ENTRY(8),
583         IAVF_PTT_UNUSED_ENTRY(9),
584         IAVF_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
585         IAVF_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
586         IAVF_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
587         IAVF_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
588         IAVF_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
589         IAVF_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
590         IAVF_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
591         IAVF_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
592         IAVF_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
593         IAVF_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
594         IAVF_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
595         IAVF_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
596
597         /* Non Tunneled IPv4 */
598         IAVF_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
599         IAVF_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
600         IAVF_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP,  PAY4),
601         IAVF_PTT_UNUSED_ENTRY(25),
602         IAVF_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP,  PAY4),
603         IAVF_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
604         IAVF_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
605
606         /* IPv4 --> IPv4 */
607         IAVF_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
608         IAVF_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
609         IAVF_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
610         IAVF_PTT_UNUSED_ENTRY(32),
611         IAVF_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
612         IAVF_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
613         IAVF_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
614
615         /* IPv4 --> IPv6 */
616         IAVF_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
617         IAVF_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
618         IAVF_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
619         IAVF_PTT_UNUSED_ENTRY(39),
620         IAVF_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
621         IAVF_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
622         IAVF_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
623
624         /* IPv4 --> GRE/NAT */
625         IAVF_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
626
627         /* IPv4 --> GRE/NAT --> IPv4 */
628         IAVF_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
629         IAVF_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
630         IAVF_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
631         IAVF_PTT_UNUSED_ENTRY(47),
632         IAVF_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
633         IAVF_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
634         IAVF_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
635
636         /* IPv4 --> GRE/NAT --> IPv6 */
637         IAVF_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
638         IAVF_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
639         IAVF_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
640         IAVF_PTT_UNUSED_ENTRY(54),
641         IAVF_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
642         IAVF_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
643         IAVF_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
644
645         /* IPv4 --> GRE/NAT --> MAC */
646         IAVF_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
647
648         /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
649         IAVF_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
650         IAVF_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
651         IAVF_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
652         IAVF_PTT_UNUSED_ENTRY(62),
653         IAVF_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
654         IAVF_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
655         IAVF_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
656
657         /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
658         IAVF_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
659         IAVF_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
660         IAVF_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
661         IAVF_PTT_UNUSED_ENTRY(69),
662         IAVF_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
663         IAVF_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
664         IAVF_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
665
666         /* IPv4 --> GRE/NAT --> MAC/VLAN */
667         IAVF_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
668
669         /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
670         IAVF_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
671         IAVF_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
672         IAVF_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
673         IAVF_PTT_UNUSED_ENTRY(77),
674         IAVF_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
675         IAVF_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
676         IAVF_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
677
678         /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
679         IAVF_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
680         IAVF_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
681         IAVF_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
682         IAVF_PTT_UNUSED_ENTRY(84),
683         IAVF_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
684         IAVF_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
685         IAVF_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
686
687         /* Non Tunneled IPv6 */
688         IAVF_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
689         IAVF_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
690         IAVF_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP,  PAY4),
691         IAVF_PTT_UNUSED_ENTRY(91),
692         IAVF_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP,  PAY4),
693         IAVF_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
694         IAVF_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
695
696         /* IPv6 --> IPv4 */
697         IAVF_PTT(95,  IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
698         IAVF_PTT(96,  IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
699         IAVF_PTT(97,  IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
700         IAVF_PTT_UNUSED_ENTRY(98),
701         IAVF_PTT(99,  IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
702         IAVF_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
703         IAVF_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
704
705         /* IPv6 --> IPv6 */
706         IAVF_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
707         IAVF_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
708         IAVF_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
709         IAVF_PTT_UNUSED_ENTRY(105),
710         IAVF_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
711         IAVF_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
712         IAVF_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
713
714         /* IPv6 --> GRE/NAT */
715         IAVF_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
716
717         /* IPv6 --> GRE/NAT -> IPv4 */
718         IAVF_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
719         IAVF_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
720         IAVF_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
721         IAVF_PTT_UNUSED_ENTRY(113),
722         IAVF_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
723         IAVF_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
724         IAVF_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
725
726         /* IPv6 --> GRE/NAT -> IPv6 */
727         IAVF_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
728         IAVF_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
729         IAVF_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
730         IAVF_PTT_UNUSED_ENTRY(120),
731         IAVF_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
732         IAVF_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
733         IAVF_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
734
735         /* IPv6 --> GRE/NAT -> MAC */
736         IAVF_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
737
738         /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
739         IAVF_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
740         IAVF_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
741         IAVF_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
742         IAVF_PTT_UNUSED_ENTRY(128),
743         IAVF_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
744         IAVF_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
745         IAVF_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
746
747         /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
748         IAVF_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
749         IAVF_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
750         IAVF_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
751         IAVF_PTT_UNUSED_ENTRY(135),
752         IAVF_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
753         IAVF_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
754         IAVF_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
755
756         /* IPv6 --> GRE/NAT -> MAC/VLAN */
757         IAVF_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
758
759         /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
760         IAVF_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
761         IAVF_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
762         IAVF_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
763         IAVF_PTT_UNUSED_ENTRY(143),
764         IAVF_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
765         IAVF_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
766         IAVF_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
767
768         /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
769         IAVF_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
770         IAVF_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
771         IAVF_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
772         IAVF_PTT_UNUSED_ENTRY(150),
773         IAVF_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
774         IAVF_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
775         IAVF_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
776
777         /* unused entries */
778         IAVF_PTT_UNUSED_ENTRY(154),
779         IAVF_PTT_UNUSED_ENTRY(155),
780         IAVF_PTT_UNUSED_ENTRY(156),
781         IAVF_PTT_UNUSED_ENTRY(157),
782         IAVF_PTT_UNUSED_ENTRY(158),
783         IAVF_PTT_UNUSED_ENTRY(159),
784
785         IAVF_PTT_UNUSED_ENTRY(160),
786         IAVF_PTT_UNUSED_ENTRY(161),
787         IAVF_PTT_UNUSED_ENTRY(162),
788         IAVF_PTT_UNUSED_ENTRY(163),
789         IAVF_PTT_UNUSED_ENTRY(164),
790         IAVF_PTT_UNUSED_ENTRY(165),
791         IAVF_PTT_UNUSED_ENTRY(166),
792         IAVF_PTT_UNUSED_ENTRY(167),
793         IAVF_PTT_UNUSED_ENTRY(168),
794         IAVF_PTT_UNUSED_ENTRY(169),
795
796         IAVF_PTT_UNUSED_ENTRY(170),
797         IAVF_PTT_UNUSED_ENTRY(171),
798         IAVF_PTT_UNUSED_ENTRY(172),
799         IAVF_PTT_UNUSED_ENTRY(173),
800         IAVF_PTT_UNUSED_ENTRY(174),
801         IAVF_PTT_UNUSED_ENTRY(175),
802         IAVF_PTT_UNUSED_ENTRY(176),
803         IAVF_PTT_UNUSED_ENTRY(177),
804         IAVF_PTT_UNUSED_ENTRY(178),
805         IAVF_PTT_UNUSED_ENTRY(179),
806
807         IAVF_PTT_UNUSED_ENTRY(180),
808         IAVF_PTT_UNUSED_ENTRY(181),
809         IAVF_PTT_UNUSED_ENTRY(182),
810         IAVF_PTT_UNUSED_ENTRY(183),
811         IAVF_PTT_UNUSED_ENTRY(184),
812         IAVF_PTT_UNUSED_ENTRY(185),
813         IAVF_PTT_UNUSED_ENTRY(186),
814         IAVF_PTT_UNUSED_ENTRY(187),
815         IAVF_PTT_UNUSED_ENTRY(188),
816         IAVF_PTT_UNUSED_ENTRY(189),
817
818         IAVF_PTT_UNUSED_ENTRY(190),
819         IAVF_PTT_UNUSED_ENTRY(191),
820         IAVF_PTT_UNUSED_ENTRY(192),
821         IAVF_PTT_UNUSED_ENTRY(193),
822         IAVF_PTT_UNUSED_ENTRY(194),
823         IAVF_PTT_UNUSED_ENTRY(195),
824         IAVF_PTT_UNUSED_ENTRY(196),
825         IAVF_PTT_UNUSED_ENTRY(197),
826         IAVF_PTT_UNUSED_ENTRY(198),
827         IAVF_PTT_UNUSED_ENTRY(199),
828
829         IAVF_PTT_UNUSED_ENTRY(200),
830         IAVF_PTT_UNUSED_ENTRY(201),
831         IAVF_PTT_UNUSED_ENTRY(202),
832         IAVF_PTT_UNUSED_ENTRY(203),
833         IAVF_PTT_UNUSED_ENTRY(204),
834         IAVF_PTT_UNUSED_ENTRY(205),
835         IAVF_PTT_UNUSED_ENTRY(206),
836         IAVF_PTT_UNUSED_ENTRY(207),
837         IAVF_PTT_UNUSED_ENTRY(208),
838         IAVF_PTT_UNUSED_ENTRY(209),
839
840         IAVF_PTT_UNUSED_ENTRY(210),
841         IAVF_PTT_UNUSED_ENTRY(211),
842         IAVF_PTT_UNUSED_ENTRY(212),
843         IAVF_PTT_UNUSED_ENTRY(213),
844         IAVF_PTT_UNUSED_ENTRY(214),
845         IAVF_PTT_UNUSED_ENTRY(215),
846         IAVF_PTT_UNUSED_ENTRY(216),
847         IAVF_PTT_UNUSED_ENTRY(217),
848         IAVF_PTT_UNUSED_ENTRY(218),
849         IAVF_PTT_UNUSED_ENTRY(219),
850
851         IAVF_PTT_UNUSED_ENTRY(220),
852         IAVF_PTT_UNUSED_ENTRY(221),
853         IAVF_PTT_UNUSED_ENTRY(222),
854         IAVF_PTT_UNUSED_ENTRY(223),
855         IAVF_PTT_UNUSED_ENTRY(224),
856         IAVF_PTT_UNUSED_ENTRY(225),
857         IAVF_PTT_UNUSED_ENTRY(226),
858         IAVF_PTT_UNUSED_ENTRY(227),
859         IAVF_PTT_UNUSED_ENTRY(228),
860         IAVF_PTT_UNUSED_ENTRY(229),
861
862         IAVF_PTT_UNUSED_ENTRY(230),
863         IAVF_PTT_UNUSED_ENTRY(231),
864         IAVF_PTT_UNUSED_ENTRY(232),
865         IAVF_PTT_UNUSED_ENTRY(233),
866         IAVF_PTT_UNUSED_ENTRY(234),
867         IAVF_PTT_UNUSED_ENTRY(235),
868         IAVF_PTT_UNUSED_ENTRY(236),
869         IAVF_PTT_UNUSED_ENTRY(237),
870         IAVF_PTT_UNUSED_ENTRY(238),
871         IAVF_PTT_UNUSED_ENTRY(239),
872
873         IAVF_PTT_UNUSED_ENTRY(240),
874         IAVF_PTT_UNUSED_ENTRY(241),
875         IAVF_PTT_UNUSED_ENTRY(242),
876         IAVF_PTT_UNUSED_ENTRY(243),
877         IAVF_PTT_UNUSED_ENTRY(244),
878         IAVF_PTT_UNUSED_ENTRY(245),
879         IAVF_PTT_UNUSED_ENTRY(246),
880         IAVF_PTT_UNUSED_ENTRY(247),
881         IAVF_PTT_UNUSED_ENTRY(248),
882         IAVF_PTT_UNUSED_ENTRY(249),
883
884         IAVF_PTT_UNUSED_ENTRY(250),
885         IAVF_PTT_UNUSED_ENTRY(251),
886         IAVF_PTT_UNUSED_ENTRY(252),
887         IAVF_PTT_UNUSED_ENTRY(253),
888         IAVF_PTT_UNUSED_ENTRY(254),
889         IAVF_PTT_UNUSED_ENTRY(255)
890 };
891
892
893 /**
894  * iavf_validate_mac_addr - Validate unicast MAC address
895  * @mac_addr: pointer to MAC address
896  *
897  * Tests a MAC address to ensure it is a valid Individual Address
898  **/
899 enum iavf_status iavf_validate_mac_addr(u8 *mac_addr)
900 {
901         enum iavf_status status = IAVF_SUCCESS;
902
903         DEBUGFUNC("iavf_validate_mac_addr");
904
905         /* Broadcast addresses ARE multicast addresses
906          * Make sure it is not a multicast address
907          * Reject the zero address
908          */
909         if (IAVF_IS_MULTICAST(mac_addr) ||
910             (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
911               mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0))
912                 status = IAVF_ERR_INVALID_MAC_ADDR;
913
914         return status;
915 }
916
917 /**
918  * iavf_aq_rx_ctl_read_register - use FW to read from an Rx control register
919  * @hw: pointer to the hw struct
920  * @reg_addr: register address
921  * @reg_val: ptr to register value
922  * @cmd_details: pointer to command details structure or NULL
923  *
924  * Use the firmware to read the Rx control register,
925  * especially useful if the Rx unit is under heavy pressure
926  **/
927 enum iavf_status iavf_aq_rx_ctl_read_register(struct iavf_hw *hw,
928                                 u32 reg_addr, u32 *reg_val,
929                                 struct iavf_asq_cmd_details *cmd_details)
930 {
931         struct iavf_aq_desc desc;
932         struct iavf_aqc_rx_ctl_reg_read_write *cmd_resp =
933                 (struct iavf_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
934         enum iavf_status status;
935
936         if (reg_val == NULL)
937                 return IAVF_ERR_PARAM;
938
939         iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_rx_ctl_reg_read);
940
941         cmd_resp->address = CPU_TO_LE32(reg_addr);
942
943         status = iavf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
944
945         if (status == IAVF_SUCCESS)
946                 *reg_val = LE32_TO_CPU(cmd_resp->value);
947
948         return status;
949 }
950
951 /**
952  * iavf_read_rx_ctl - read from an Rx control register
953  * @hw: pointer to the hw struct
954  * @reg_addr: register address
955  **/
956 u32 iavf_read_rx_ctl(struct iavf_hw *hw, u32 reg_addr)
957 {
958         enum iavf_status status = IAVF_SUCCESS;
959         bool use_register;
960         int retry = 5;
961         u32 val = 0;
962
963         use_register = (((hw->aq.api_maj_ver == 1) &&
964                         (hw->aq.api_min_ver < 5)) ||
965                         (hw->mac.type == IAVF_MAC_X722));
966         if (!use_register) {
967 do_retry:
968                 status = iavf_aq_rx_ctl_read_register(hw, reg_addr, &val, NULL);
969                 if (hw->aq.asq_last_status == IAVF_AQ_RC_EAGAIN && retry) {
970                         iavf_msec_delay(1);
971                         retry--;
972                         goto do_retry;
973                 }
974         }
975
976         /* if the AQ access failed, try the old-fashioned way */
977         if (status || use_register)
978                 val = rd32(hw, reg_addr);
979
980         return val;
981 }
982
983 /**
984  * iavf_aq_rx_ctl_write_register
985  * @hw: pointer to the hw struct
986  * @reg_addr: register address
987  * @reg_val: register value
988  * @cmd_details: pointer to command details structure or NULL
989  *
990  * Use the firmware to write to an Rx control register,
991  * especially useful if the Rx unit is under heavy pressure
992  **/
993 enum iavf_status iavf_aq_rx_ctl_write_register(struct iavf_hw *hw,
994                                 u32 reg_addr, u32 reg_val,
995                                 struct iavf_asq_cmd_details *cmd_details)
996 {
997         struct iavf_aq_desc desc;
998         struct iavf_aqc_rx_ctl_reg_read_write *cmd =
999                 (struct iavf_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
1000         enum iavf_status status;
1001
1002         iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_rx_ctl_reg_write);
1003
1004         cmd->address = CPU_TO_LE32(reg_addr);
1005         cmd->value = CPU_TO_LE32(reg_val);
1006
1007         status = iavf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1008
1009         return status;
1010 }
1011
1012 /**
1013  * iavf_write_rx_ctl - write to an Rx control register
1014  * @hw: pointer to the hw struct
1015  * @reg_addr: register address
1016  * @reg_val: register value
1017  **/
1018 void iavf_write_rx_ctl(struct iavf_hw *hw, u32 reg_addr, u32 reg_val)
1019 {
1020         enum iavf_status status = IAVF_SUCCESS;
1021         bool use_register;
1022         int retry = 5;
1023
1024         use_register = (((hw->aq.api_maj_ver == 1) &&
1025                         (hw->aq.api_min_ver < 5)) ||
1026                         (hw->mac.type == IAVF_MAC_X722));
1027         if (!use_register) {
1028 do_retry:
1029                 status = iavf_aq_rx_ctl_write_register(hw, reg_addr,
1030                                                        reg_val, NULL);
1031                 if (hw->aq.asq_last_status == IAVF_AQ_RC_EAGAIN && retry) {
1032                         iavf_msec_delay(1);
1033                         retry--;
1034                         goto do_retry;
1035                 }
1036         }
1037
1038         /* if the AQ access failed, try the old-fashioned way */
1039         if (status || use_register)
1040                 wr32(hw, reg_addr, reg_val);
1041 }
1042
1043 /**
1044  * iavf_aq_set_phy_register
1045  * @hw: pointer to the hw struct
1046  * @phy_select: select which phy should be accessed
1047  * @dev_addr: PHY device address
1048  * @reg_addr: PHY register address
1049  * @reg_val: new register value
1050  * @cmd_details: pointer to command details structure or NULL
1051  *
1052  * Write the external PHY register.
1053  **/
1054 enum iavf_status iavf_aq_set_phy_register(struct iavf_hw *hw,
1055                                 u8 phy_select, u8 dev_addr,
1056                                 u32 reg_addr, u32 reg_val,
1057                                 struct iavf_asq_cmd_details *cmd_details)
1058 {
1059         struct iavf_aq_desc desc;
1060         struct iavf_aqc_phy_register_access *cmd =
1061                 (struct iavf_aqc_phy_register_access *)&desc.params.raw;
1062         enum iavf_status status;
1063
1064         iavf_fill_default_direct_cmd_desc(&desc,
1065                                           iavf_aqc_opc_set_phy_register);
1066
1067         cmd->phy_interface = phy_select;
1068         cmd->dev_addres = dev_addr;
1069         cmd->reg_address = CPU_TO_LE32(reg_addr);
1070         cmd->reg_value = CPU_TO_LE32(reg_val);
1071
1072         status = iavf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1073
1074         return status;
1075 }
1076
1077 /**
1078  * iavf_aq_get_phy_register
1079  * @hw: pointer to the hw struct
1080  * @phy_select: select which phy should be accessed
1081  * @dev_addr: PHY device address
1082  * @reg_addr: PHY register address
1083  * @reg_val: read register value
1084  * @cmd_details: pointer to command details structure or NULL
1085  *
1086  * Read the external PHY register.
1087  **/
1088 enum iavf_status iavf_aq_get_phy_register(struct iavf_hw *hw,
1089                                 u8 phy_select, u8 dev_addr,
1090                                 u32 reg_addr, u32 *reg_val,
1091                                 struct iavf_asq_cmd_details *cmd_details)
1092 {
1093         struct iavf_aq_desc desc;
1094         struct iavf_aqc_phy_register_access *cmd =
1095                 (struct iavf_aqc_phy_register_access *)&desc.params.raw;
1096         enum iavf_status status;
1097
1098         iavf_fill_default_direct_cmd_desc(&desc,
1099                                           iavf_aqc_opc_get_phy_register);
1100
1101         cmd->phy_interface = phy_select;
1102         cmd->dev_addres = dev_addr;
1103         cmd->reg_address = CPU_TO_LE32(reg_addr);
1104
1105         status = iavf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1106         if (!status)
1107                 *reg_val = LE32_TO_CPU(cmd->reg_value);
1108
1109         return status;
1110 }
1111
1112
1113 /**
1114  * iavf_aq_send_msg_to_pf
1115  * @hw: pointer to the hardware structure
1116  * @v_opcode: opcodes for VF-PF communication
1117  * @v_retval: return error code
1118  * @msg: pointer to the msg buffer
1119  * @msglen: msg length
1120  * @cmd_details: pointer to command details
1121  *
1122  * Send message to PF driver using admin queue. By default, this message
1123  * is sent asynchronously, i.e. iavf_asq_send_command() does not wait for
1124  * completion before returning.
1125  **/
1126 enum iavf_status iavf_aq_send_msg_to_pf(struct iavf_hw *hw,
1127                                 enum virtchnl_ops v_opcode,
1128                                 enum iavf_status v_retval,
1129                                 u8 *msg, u16 msglen,
1130                                 struct iavf_asq_cmd_details *cmd_details)
1131 {
1132         struct iavf_aq_desc desc;
1133         struct iavf_asq_cmd_details details;
1134         enum iavf_status status;
1135
1136         iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_send_msg_to_pf);
1137         desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_SI);
1138         desc.cookie_high = CPU_TO_LE32(v_opcode);
1139         desc.cookie_low = CPU_TO_LE32(v_retval);
1140         if (msglen) {
1141                 desc.flags |= CPU_TO_LE16((u16)(IAVF_AQ_FLAG_BUF
1142                                                 | IAVF_AQ_FLAG_RD));
1143                 if (msglen > IAVF_AQ_LARGE_BUF)
1144                         desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_LB);
1145                 desc.datalen = CPU_TO_LE16(msglen);
1146         }
1147         if (!cmd_details) {
1148                 iavf_memset(&details, 0, sizeof(details), IAVF_NONDMA_MEM);
1149                 details.async = true;
1150                 cmd_details = &details;
1151         }
1152         status = iavf_asq_send_command(hw, (struct iavf_aq_desc *)&desc, msg,
1153                                        msglen, cmd_details);
1154         return status;
1155 }
1156
1157 /**
1158  * iavf_parse_hw_config
1159  * @hw: pointer to the hardware structure
1160  * @msg: pointer to the virtual channel VF resource structure
1161  *
1162  * Given a VF resource message from the PF, populate the hw struct
1163  * with appropriate information.
1164  **/
1165 void iavf_parse_hw_config(struct iavf_hw *hw,
1166                              struct virtchnl_vf_resource *msg)
1167 {
1168         struct virtchnl_vsi_resource *vsi_res;
1169         int i;
1170
1171         vsi_res = &msg->vsi_res[0];
1172
1173         hw->dev_caps.num_vsis = msg->num_vsis;
1174         hw->dev_caps.num_rx_qp = msg->num_queue_pairs;
1175         hw->dev_caps.num_tx_qp = msg->num_queue_pairs;
1176         hw->dev_caps.num_msix_vectors_vf = msg->max_vectors;
1177         hw->dev_caps.dcb = msg->vf_cap_flags &
1178                            VIRTCHNL_VF_OFFLOAD_L2;
1179         hw->dev_caps.iwarp = (msg->vf_cap_flags &
1180                               VIRTCHNL_VF_OFFLOAD_IWARP) ? 1 : 0;
1181         for (i = 0; i < msg->num_vsis; i++) {
1182                 if (vsi_res->vsi_type == VIRTCHNL_VSI_SRIOV) {
1183                         iavf_memcpy(hw->mac.perm_addr,
1184                                     vsi_res->default_mac_addr,
1185                                     ETH_ALEN,
1186                                     IAVF_NONDMA_TO_NONDMA);
1187                         iavf_memcpy(hw->mac.addr, vsi_res->default_mac_addr,
1188                                     ETH_ALEN,
1189                                     IAVF_NONDMA_TO_NONDMA);
1190                 }
1191                 vsi_res++;
1192         }
1193 }
1194
1195 /**
1196  * iavf_reset
1197  * @hw: pointer to the hardware structure
1198  *
1199  * Send a VF_RESET message to the PF. Does not wait for response from PF
1200  * as none will be forthcoming. Immediately after calling this function,
1201  * the admin queue should be shut down and (optionally) reinitialized.
1202  **/
1203 enum iavf_status iavf_reset(struct iavf_hw *hw)
1204 {
1205         return iavf_aq_send_msg_to_pf(hw, VIRTCHNL_OP_RESET_VF,
1206                                       IAVF_SUCCESS, NULL, 0, NULL);
1207 }
1208
1209 /**
1210  * iavf_aq_set_arp_proxy_config
1211  * @hw: pointer to the HW structure
1212  * @proxy_config: pointer to proxy config command table struct
1213  * @cmd_details: pointer to command details
1214  *
1215  * Set ARP offload parameters from pre-populated
1216  * iavf_aqc_arp_proxy_data struct
1217  **/
1218 enum iavf_status iavf_aq_set_arp_proxy_config(struct iavf_hw *hw,
1219                                 struct iavf_aqc_arp_proxy_data *proxy_config,
1220                                 struct iavf_asq_cmd_details *cmd_details)
1221 {
1222         struct iavf_aq_desc desc;
1223         enum iavf_status status;
1224
1225         if (!proxy_config)
1226                 return IAVF_ERR_PARAM;
1227
1228         iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_set_proxy_config);
1229
1230         desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_BUF);
1231         desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_RD);
1232         desc.params.external.addr_high =
1233                                   CPU_TO_LE32(IAVF_HI_DWORD((u64)proxy_config));
1234         desc.params.external.addr_low =
1235                                   CPU_TO_LE32(IAVF_LO_DWORD((u64)proxy_config));
1236         desc.datalen = CPU_TO_LE16(sizeof(struct iavf_aqc_arp_proxy_data));
1237
1238         status = iavf_asq_send_command(hw, &desc, proxy_config,
1239                                        sizeof(struct iavf_aqc_arp_proxy_data),
1240                                        cmd_details);
1241
1242         return status;
1243 }
1244
1245 /**
1246  * iavf_aq_opc_set_ns_proxy_table_entry
1247  * @hw: pointer to the HW structure
1248  * @ns_proxy_table_entry: pointer to NS table entry command struct
1249  * @cmd_details: pointer to command details
1250  *
1251  * Set IPv6 Neighbor Solicitation (NS) protocol offload parameters
1252  * from pre-populated iavf_aqc_ns_proxy_data struct
1253  **/
1254 enum iavf_status iavf_aq_set_ns_proxy_table_entry(struct iavf_hw *hw,
1255                         struct iavf_aqc_ns_proxy_data *ns_proxy_table_entry,
1256                         struct iavf_asq_cmd_details *cmd_details)
1257 {
1258         struct iavf_aq_desc desc;
1259         enum iavf_status status;
1260
1261         if (!ns_proxy_table_entry)
1262                 return IAVF_ERR_PARAM;
1263
1264         iavf_fill_default_direct_cmd_desc(&desc,
1265                                 iavf_aqc_opc_set_ns_proxy_table_entry);
1266
1267         desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_BUF);
1268         desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_RD);
1269         desc.params.external.addr_high =
1270                 CPU_TO_LE32(IAVF_HI_DWORD((u64)ns_proxy_table_entry));
1271         desc.params.external.addr_low =
1272                 CPU_TO_LE32(IAVF_LO_DWORD((u64)ns_proxy_table_entry));
1273         desc.datalen = CPU_TO_LE16(sizeof(struct iavf_aqc_ns_proxy_data));
1274
1275         status = iavf_asq_send_command(hw, &desc, ns_proxy_table_entry,
1276                                        sizeof(struct iavf_aqc_ns_proxy_data),
1277                                        cmd_details);
1278
1279         return status;
1280 }
1281
1282 /**
1283  * iavf_aq_set_clear_wol_filter
1284  * @hw: pointer to the hw struct
1285  * @filter_index: index of filter to modify (0-7)
1286  * @filter: buffer containing filter to be set
1287  * @set_filter: true to set filter, false to clear filter
1288  * @no_wol_tco: if true, pass through packets cannot cause wake-up
1289  *              if false, pass through packets may cause wake-up
1290  * @filter_valid: true if filter action is valid
1291  * @no_wol_tco_valid: true if no WoL in TCO traffic action valid
1292  * @cmd_details: pointer to command details structure or NULL
1293  *
1294  * Set or clear WoL filter for port attached to the PF
1295  **/
1296 enum iavf_status iavf_aq_set_clear_wol_filter(struct iavf_hw *hw,
1297                                 u8 filter_index,
1298                                 struct iavf_aqc_set_wol_filter_data *filter,
1299                                 bool set_filter, bool no_wol_tco,
1300                                 bool filter_valid, bool no_wol_tco_valid,
1301                                 struct iavf_asq_cmd_details *cmd_details)
1302 {
1303         struct iavf_aq_desc desc;
1304         struct iavf_aqc_set_wol_filter *cmd =
1305                 (struct iavf_aqc_set_wol_filter *)&desc.params.raw;
1306         enum iavf_status status;
1307         u16 cmd_flags = 0;
1308         u16 valid_flags = 0;
1309         u16 buff_len = 0;
1310
1311         iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_set_wol_filter);
1312
1313         if (filter_index >= IAVF_AQC_MAX_NUM_WOL_FILTERS)
1314                 return  IAVF_ERR_PARAM;
1315         cmd->filter_index = CPU_TO_LE16(filter_index);
1316
1317         if (set_filter) {
1318                 if (!filter)
1319                         return  IAVF_ERR_PARAM;
1320
1321                 cmd_flags |= IAVF_AQC_SET_WOL_FILTER;
1322                 cmd_flags |= IAVF_AQC_SET_WOL_FILTER_WOL_PRESERVE_ON_PFR;
1323         }
1324
1325         if (no_wol_tco)
1326                 cmd_flags |= IAVF_AQC_SET_WOL_FILTER_NO_TCO_WOL;
1327         cmd->cmd_flags = CPU_TO_LE16(cmd_flags);
1328
1329         if (filter_valid)
1330                 valid_flags |= IAVF_AQC_SET_WOL_FILTER_ACTION_VALID;
1331         if (no_wol_tco_valid)
1332                 valid_flags |= IAVF_AQC_SET_WOL_FILTER_NO_TCO_ACTION_VALID;
1333         cmd->valid_flags = CPU_TO_LE16(valid_flags);
1334
1335         buff_len = sizeof(*filter);
1336         desc.datalen = CPU_TO_LE16(buff_len);
1337
1338         desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_BUF);
1339         desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_RD);
1340
1341         cmd->address_high = CPU_TO_LE32(IAVF_HI_DWORD((u64)filter));
1342         cmd->address_low = CPU_TO_LE32(IAVF_LO_DWORD((u64)filter));
1343
1344         status = iavf_asq_send_command(hw, &desc, filter,
1345                                        buff_len, cmd_details);
1346
1347         return status;
1348 }
1349
1350 /**
1351  * iavf_aq_get_wake_event_reason
1352  * @hw: pointer to the hw struct
1353  * @wake_reason: return value, index of matching filter
1354  * @cmd_details: pointer to command details structure or NULL
1355  *
1356  * Get information for the reason of a Wake Up event
1357  **/
1358 enum iavf_status iavf_aq_get_wake_event_reason(struct iavf_hw *hw,
1359                                 u16 *wake_reason,
1360                                 struct iavf_asq_cmd_details *cmd_details)
1361 {
1362         struct iavf_aq_desc desc;
1363         struct iavf_aqc_get_wake_reason_completion *resp =
1364                 (struct iavf_aqc_get_wake_reason_completion *)&desc.params.raw;
1365         enum iavf_status status;
1366
1367         iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_get_wake_reason);
1368
1369         status = iavf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1370
1371         if (status == IAVF_SUCCESS)
1372                 *wake_reason = LE16_TO_CPU(resp->wake_reason);
1373
1374         return status;
1375 }
1376
1377 /**
1378 * iavf_aq_clear_all_wol_filters
1379 * @hw: pointer to the hw struct
1380 * @cmd_details: pointer to command details structure or NULL
1381 *
1382 * Get information for the reason of a Wake Up event
1383 **/
1384 enum iavf_status iavf_aq_clear_all_wol_filters(struct iavf_hw *hw,
1385         struct iavf_asq_cmd_details *cmd_details)
1386 {
1387         struct iavf_aq_desc desc;
1388         enum iavf_status status;
1389
1390         iavf_fill_default_direct_cmd_desc(&desc,
1391                                           iavf_aqc_opc_clear_all_wol_filters);
1392
1393         status = iavf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1394
1395         return status;
1396 }
1397
1398 /**
1399  * iavf_aq_write_ddp - Write dynamic device personalization (ddp)
1400  * @hw: pointer to the hw struct
1401  * @buff: command buffer (size in bytes = buff_size)
1402  * @buff_size: buffer size in bytes
1403  * @track_id: package tracking id
1404  * @error_offset: returns error offset
1405  * @error_info: returns error information
1406  * @cmd_details: pointer to command details structure or NULL
1407  **/
1408 enum
1409 iavf_status iavf_aq_write_ddp(struct iavf_hw *hw, void *buff,
1410                                    u16 buff_size, u32 track_id,
1411                                    u32 *error_offset, u32 *error_info,
1412                                    struct iavf_asq_cmd_details *cmd_details)
1413 {
1414         struct iavf_aq_desc desc;
1415         struct iavf_aqc_write_personalization_profile *cmd =
1416                 (struct iavf_aqc_write_personalization_profile *)
1417                 &desc.params.raw;
1418         struct iavf_aqc_write_ddp_resp *resp;
1419         enum iavf_status status;
1420
1421         iavf_fill_default_direct_cmd_desc(&desc,
1422                                   iavf_aqc_opc_write_personalization_profile);
1423
1424         desc.flags |= CPU_TO_LE16(IAVF_AQ_FLAG_BUF | IAVF_AQ_FLAG_RD);
1425         if (buff_size > IAVF_AQ_LARGE_BUF)
1426                 desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_LB);
1427
1428         desc.datalen = CPU_TO_LE16(buff_size);
1429
1430         cmd->profile_track_id = CPU_TO_LE32(track_id);
1431
1432         status = iavf_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
1433         if (!status) {
1434                 resp = (struct iavf_aqc_write_ddp_resp *)&desc.params.raw;
1435                 if (error_offset)
1436                         *error_offset = LE32_TO_CPU(resp->error_offset);
1437                 if (error_info)
1438                         *error_info = LE32_TO_CPU(resp->error_info);
1439         }
1440
1441         return status;
1442 }
1443
1444 /**
1445  * iavf_aq_get_ddp_list - Read dynamic device personalization (ddp)
1446  * @hw: pointer to the hw struct
1447  * @buff: command buffer (size in bytes = buff_size)
1448  * @buff_size: buffer size in bytes
1449  * @flags: AdminQ command flags
1450  * @cmd_details: pointer to command details structure or NULL
1451  **/
1452 enum
1453 iavf_status iavf_aq_get_ddp_list(struct iavf_hw *hw, void *buff,
1454                                       u16 buff_size, u8 flags,
1455                                       struct iavf_asq_cmd_details *cmd_details)
1456 {
1457         struct iavf_aq_desc desc;
1458         struct iavf_aqc_get_applied_profiles *cmd =
1459                 (struct iavf_aqc_get_applied_profiles *)&desc.params.raw;
1460         enum iavf_status status;
1461
1462         iavf_fill_default_direct_cmd_desc(&desc,
1463                           iavf_aqc_opc_get_personalization_profile_list);
1464
1465         desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_BUF);
1466         if (buff_size > IAVF_AQ_LARGE_BUF)
1467                 desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_LB);
1468         desc.datalen = CPU_TO_LE16(buff_size);
1469
1470         cmd->flags = flags;
1471
1472         status = iavf_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
1473
1474         return status;
1475 }
1476
1477 /**
1478  * iavf_find_segment_in_package
1479  * @segment_type: the segment type to search for (i.e., SEGMENT_TYPE_IAVF)
1480  * @pkg_hdr: pointer to the package header to be searched
1481  *
1482  * This function searches a package file for a particular segment type. On
1483  * success it returns a pointer to the segment header, otherwise it will
1484  * return NULL.
1485  **/
1486 struct iavf_generic_seg_header *
1487 iavf_find_segment_in_package(u32 segment_type,
1488                              struct iavf_package_header *pkg_hdr)
1489 {
1490         struct iavf_generic_seg_header *segment;
1491         u32 i;
1492
1493         /* Search all package segments for the requested segment type */
1494         for (i = 0; i < pkg_hdr->segment_count; i++) {
1495                 segment =
1496                         (struct iavf_generic_seg_header *)((u8 *)pkg_hdr +
1497                          pkg_hdr->segment_offset[i]);
1498
1499                 if (segment->type == segment_type)
1500                         return segment;
1501         }
1502
1503         return NULL;
1504 }
1505
1506 /* Get section table in profile */
1507 #define IAVF_SECTION_TABLE(profile, sec_tbl)                            \
1508         do {                                                            \
1509                 struct iavf_profile_segment *p = (profile);             \
1510                 u32 count;                                              \
1511                 u32 *nvm;                                               \
1512                 count = p->device_table_count;                          \
1513                 nvm = (u32 *)&p->device_table[count];                   \
1514                 sec_tbl = (struct iavf_section_table *)&nvm[nvm[0] + 1]; \
1515         } while (0)
1516
1517 /* Get section header in profile */
1518 #define IAVF_SECTION_HEADER(profile, offset)                            \
1519         (struct iavf_profile_section_header *)((u8 *)(profile) + (offset))
1520
1521 /**
1522  * iavf_find_section_in_profile
1523  * @section_type: the section type to search for (i.e., SECTION_TYPE_NOTE)
1524  * @profile: pointer to the iavf segment header to be searched
1525  *
1526  * This function searches iavf segment for a particular section type. On
1527  * success it returns a pointer to the section header, otherwise it will
1528  * return NULL.
1529  **/
1530 struct iavf_profile_section_header *
1531 iavf_find_section_in_profile(u32 section_type,
1532                              struct iavf_profile_segment *profile)
1533 {
1534         struct iavf_profile_section_header *sec;
1535         struct iavf_section_table *sec_tbl;
1536         u32 sec_off;
1537         u32 i;
1538
1539         if (profile->header.type != SEGMENT_TYPE_IAVF)
1540                 return NULL;
1541
1542         IAVF_SECTION_TABLE(profile, sec_tbl);
1543
1544         for (i = 0; i < sec_tbl->section_count; i++) {
1545                 sec_off = sec_tbl->section_offset[i];
1546                 sec = IAVF_SECTION_HEADER(profile, sec_off);
1547                 if (sec->section.type == section_type)
1548                         return sec;
1549         }
1550
1551         return NULL;
1552 }
1553
1554 /**
1555  * iavf_ddp_exec_aq_section - Execute generic AQ for DDP
1556  * @hw: pointer to the hw struct
1557  * @aq: command buffer containing all data to execute AQ
1558  **/
1559 STATIC enum
1560 iavf_status iavf_ddp_exec_aq_section(struct iavf_hw *hw,
1561                                           struct iavf_profile_aq_section *aq)
1562 {
1563         enum iavf_status status;
1564         struct iavf_aq_desc desc;
1565         u8 *msg = NULL;
1566         u16 msglen;
1567
1568         iavf_fill_default_direct_cmd_desc(&desc, aq->opcode);
1569         desc.flags |= CPU_TO_LE16(aq->flags);
1570         iavf_memcpy(desc.params.raw, aq->param, sizeof(desc.params.raw),
1571                     IAVF_NONDMA_TO_NONDMA);
1572
1573         msglen = aq->datalen;
1574         if (msglen) {
1575                 desc.flags |= CPU_TO_LE16((u16)(IAVF_AQ_FLAG_BUF |
1576                                                 IAVF_AQ_FLAG_RD));
1577                 if (msglen > IAVF_AQ_LARGE_BUF)
1578                         desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_LB);
1579                 desc.datalen = CPU_TO_LE16(msglen);
1580                 msg = &aq->data[0];
1581         }
1582
1583         status = iavf_asq_send_command(hw, &desc, msg, msglen, NULL);
1584
1585         if (status != IAVF_SUCCESS) {
1586                 iavf_debug(hw, IAVF_DEBUG_PACKAGE,
1587                            "unable to exec DDP AQ opcode %u, error %d\n",
1588                            aq->opcode, status);
1589                 return status;
1590         }
1591
1592         /* copy returned desc to aq_buf */
1593         iavf_memcpy(aq->param, desc.params.raw, sizeof(desc.params.raw),
1594                     IAVF_NONDMA_TO_NONDMA);
1595
1596         return IAVF_SUCCESS;
1597 }
1598
1599 /**
1600  * iavf_validate_profile
1601  * @hw: pointer to the hardware structure
1602  * @profile: pointer to the profile segment of the package to be validated
1603  * @track_id: package tracking id
1604  * @rollback: flag if the profile is for rollback.
1605  *
1606  * Validates supported devices and profile's sections.
1607  */
1608 STATIC enum iavf_status
1609 iavf_validate_profile(struct iavf_hw *hw, struct iavf_profile_segment *profile,
1610                       u32 track_id, bool rollback)
1611 {
1612         struct iavf_profile_section_header *sec = NULL;
1613         enum iavf_status status = IAVF_SUCCESS;
1614         struct iavf_section_table *sec_tbl;
1615         u32 vendor_dev_id;
1616         u32 dev_cnt;
1617         u32 sec_off;
1618         u32 i;
1619
1620         if (track_id == IAVF_DDP_TRACKID_INVALID) {
1621                 iavf_debug(hw, IAVF_DEBUG_PACKAGE, "Invalid track_id\n");
1622                 return IAVF_NOT_SUPPORTED;
1623         }
1624
1625         dev_cnt = profile->device_table_count;
1626         for (i = 0; i < dev_cnt; i++) {
1627                 vendor_dev_id = profile->device_table[i].vendor_dev_id;
1628                 if ((vendor_dev_id >> 16) == IAVF_INTEL_VENDOR_ID &&
1629                     hw->device_id == (vendor_dev_id & 0xFFFF))
1630                         break;
1631         }
1632         if (dev_cnt && (i == dev_cnt)) {
1633                 iavf_debug(hw, IAVF_DEBUG_PACKAGE,
1634                            "Device doesn't support DDP\n");
1635                 return IAVF_ERR_DEVICE_NOT_SUPPORTED;
1636         }
1637
1638         IAVF_SECTION_TABLE(profile, sec_tbl);
1639
1640         /* Validate sections types */
1641         for (i = 0; i < sec_tbl->section_count; i++) {
1642                 sec_off = sec_tbl->section_offset[i];
1643                 sec = IAVF_SECTION_HEADER(profile, sec_off);
1644                 if (rollback) {
1645                         if (sec->section.type == SECTION_TYPE_MMIO ||
1646                             sec->section.type == SECTION_TYPE_AQ ||
1647                             sec->section.type == SECTION_TYPE_RB_AQ) {
1648                                 iavf_debug(hw, IAVF_DEBUG_PACKAGE,
1649                                            "Not a roll-back package\n");
1650                                 return IAVF_NOT_SUPPORTED;
1651                         }
1652                 } else {
1653                         if (sec->section.type == SECTION_TYPE_RB_AQ ||
1654                             sec->section.type == SECTION_TYPE_RB_MMIO) {
1655                                 iavf_debug(hw, IAVF_DEBUG_PACKAGE,
1656                                            "Not an original package\n");
1657                                 return IAVF_NOT_SUPPORTED;
1658                         }
1659                 }
1660         }
1661
1662         return status;
1663 }
1664
1665 /**
1666  * iavf_write_profile
1667  * @hw: pointer to the hardware structure
1668  * @profile: pointer to the profile segment of the package to be downloaded
1669  * @track_id: package tracking id
1670  *
1671  * Handles the download of a complete package.
1672  */
1673 enum iavf_status
1674 iavf_write_profile(struct iavf_hw *hw, struct iavf_profile_segment *profile,
1675                    u32 track_id)
1676 {
1677         enum iavf_status status = IAVF_SUCCESS;
1678         struct iavf_section_table *sec_tbl;
1679         struct iavf_profile_section_header *sec = NULL;
1680         struct iavf_profile_aq_section *ddp_aq;
1681         u32 section_size = 0;
1682         u32 offset = 0, info = 0;
1683         u32 sec_off;
1684         u32 i;
1685
1686         status = iavf_validate_profile(hw, profile, track_id, false);
1687         if (status)
1688                 return status;
1689
1690         IAVF_SECTION_TABLE(profile, sec_tbl);
1691
1692         for (i = 0; i < sec_tbl->section_count; i++) {
1693                 sec_off = sec_tbl->section_offset[i];
1694                 sec = IAVF_SECTION_HEADER(profile, sec_off);
1695                 /* Process generic admin command */
1696                 if (sec->section.type == SECTION_TYPE_AQ) {
1697                         ddp_aq = (struct iavf_profile_aq_section *)&sec[1];
1698                         status = iavf_ddp_exec_aq_section(hw, ddp_aq);
1699                         if (status) {
1700                                 iavf_debug(hw, IAVF_DEBUG_PACKAGE,
1701                                            "Failed to execute aq: section %d, opcode %u\n",
1702                                            i, ddp_aq->opcode);
1703                                 break;
1704                         }
1705                         sec->section.type = SECTION_TYPE_RB_AQ;
1706                 }
1707
1708                 /* Skip any non-mmio sections */
1709                 if (sec->section.type != SECTION_TYPE_MMIO)
1710                         continue;
1711
1712                 section_size = sec->section.size +
1713                         sizeof(struct iavf_profile_section_header);
1714
1715                 /* Write MMIO section */
1716                 status = iavf_aq_write_ddp(hw, (void *)sec, (u16)section_size,
1717                                            track_id, &offset, &info, NULL);
1718                 if (status) {
1719                         iavf_debug(hw, IAVF_DEBUG_PACKAGE,
1720                                    "Failed to write profile: section %d, offset %d, info %d\n",
1721                                    i, offset, info);
1722                         break;
1723                 }
1724         }
1725         return status;
1726 }
1727
1728 /**
1729  * iavf_rollback_profile
1730  * @hw: pointer to the hardware structure
1731  * @profile: pointer to the profile segment of the package to be removed
1732  * @track_id: package tracking id
1733  *
1734  * Rolls back previously loaded package.
1735  */
1736 enum iavf_status
1737 iavf_rollback_profile(struct iavf_hw *hw, struct iavf_profile_segment *profile,
1738                       u32 track_id)
1739 {
1740         struct iavf_profile_section_header *sec = NULL;
1741         enum iavf_status status = IAVF_SUCCESS;
1742         struct iavf_section_table *sec_tbl;
1743         u32 offset = 0, info = 0;
1744         u32 section_size = 0;
1745         u32 sec_off;
1746         int i;
1747
1748         status = iavf_validate_profile(hw, profile, track_id, true);
1749         if (status)
1750                 return status;
1751
1752         IAVF_SECTION_TABLE(profile, sec_tbl);
1753
1754         /* For rollback write sections in reverse */
1755         for (i = sec_tbl->section_count - 1; i >= 0; i--) {
1756                 sec_off = sec_tbl->section_offset[i];
1757                 sec = IAVF_SECTION_HEADER(profile, sec_off);
1758
1759                 /* Skip any non-rollback sections */
1760                 if (sec->section.type != SECTION_TYPE_RB_MMIO)
1761                         continue;
1762
1763                 section_size = sec->section.size +
1764                         sizeof(struct iavf_profile_section_header);
1765
1766                 /* Write roll-back MMIO section */
1767                 status = iavf_aq_write_ddp(hw, (void *)sec, (u16)section_size,
1768                                            track_id, &offset, &info, NULL);
1769                 if (status) {
1770                         iavf_debug(hw, IAVF_DEBUG_PACKAGE,
1771                                    "Failed to write profile: section %d, offset %d, info %d\n",
1772                                    i, offset, info);
1773                         break;
1774                 }
1775         }
1776         return status;
1777 }
1778
1779 /**
1780  * iavf_add_pinfo_to_list
1781  * @hw: pointer to the hardware structure
1782  * @profile: pointer to the profile segment of the package
1783  * @profile_info_sec: buffer for information section
1784  * @track_id: package tracking id
1785  *
1786  * Register a profile to the list of loaded profiles.
1787  */
1788 enum iavf_status
1789 iavf_add_pinfo_to_list(struct iavf_hw *hw,
1790                        struct iavf_profile_segment *profile,
1791                        u8 *profile_info_sec, u32 track_id)
1792 {
1793         enum iavf_status status = IAVF_SUCCESS;
1794         struct iavf_profile_section_header *sec = NULL;
1795         struct iavf_profile_info *pinfo;
1796         u32 offset = 0, info = 0;
1797
1798         sec = (struct iavf_profile_section_header *)profile_info_sec;
1799         sec->tbl_size = 1;
1800         sec->data_end = sizeof(struct iavf_profile_section_header) +
1801                         sizeof(struct iavf_profile_info);
1802         sec->section.type = SECTION_TYPE_INFO;
1803         sec->section.offset = sizeof(struct iavf_profile_section_header);
1804         sec->section.size = sizeof(struct iavf_profile_info);
1805         pinfo = (struct iavf_profile_info *)(profile_info_sec +
1806                                              sec->section.offset);
1807         pinfo->track_id = track_id;
1808         pinfo->version = profile->version;
1809         pinfo->op = IAVF_DDP_ADD_TRACKID;
1810         iavf_memcpy(pinfo->name, profile->name, IAVF_DDP_NAME_SIZE,
1811                     IAVF_NONDMA_TO_NONDMA);
1812
1813         status = iavf_aq_write_ddp(hw, (void *)sec, sec->data_end,
1814                                    track_id, &offset, &info, NULL);
1815         return status;
1816 }