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