New upstream version 18.02
[deb_dpdk.git] / drivers / net / avf / base / avf_common.c
1 /*******************************************************************************
2
3 Copyright (c) 2013 - 2015, Intel Corporation
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8
9  1. Redistributions of source code must retain the above copyright notice,
10     this list of conditions and the following disclaimer.
11
12  2. Redistributions in binary form must reproduce the above copyright
13     notice, this list of conditions and the following disclaimer in the
14     documentation and/or other materials provided with the distribution.
15
16  3. Neither the name of the Intel Corporation nor the names of its
17     contributors may be used to endorse or promote products derived from
18     this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
31
32 ***************************************************************************/
33
34 #include "avf_type.h"
35 #include "avf_adminq.h"
36 #include "avf_prototype.h"
37 #include "virtchnl.h"
38
39
40 /**
41  * avf_set_mac_type - Sets MAC type
42  * @hw: pointer to the HW structure
43  *
44  * This function sets the mac type of the adapter based on the
45  * vendor ID and device ID stored in the hw structure.
46  **/
47 enum avf_status_code avf_set_mac_type(struct avf_hw *hw)
48 {
49         enum avf_status_code status = AVF_SUCCESS;
50
51         DEBUGFUNC("avf_set_mac_type\n");
52
53         if (hw->vendor_id == AVF_INTEL_VENDOR_ID) {
54                 switch (hw->device_id) {
55         /* TODO: remove undefined device ID now, need to think how to
56          * remove them in share code
57          */
58                 case AVF_DEV_ID_ADAPTIVE_VF:
59                         hw->mac.type = AVF_MAC_VF;
60                         break;
61                 default:
62                         hw->mac.type = AVF_MAC_GENERIC;
63                         break;
64                 }
65         } else {
66                 status = AVF_ERR_DEVICE_NOT_SUPPORTED;
67         }
68
69         DEBUGOUT2("avf_set_mac_type found mac: %d, returns: %d\n",
70                   hw->mac.type, status);
71         return status;
72 }
73
74 /**
75  * avf_aq_str - convert AQ err code to a string
76  * @hw: pointer to the HW structure
77  * @aq_err: the AQ error code to convert
78  **/
79 const char *avf_aq_str(struct avf_hw *hw, enum avf_admin_queue_err aq_err)
80 {
81         switch (aq_err) {
82         case AVF_AQ_RC_OK:
83                 return "OK";
84         case AVF_AQ_RC_EPERM:
85                 return "AVF_AQ_RC_EPERM";
86         case AVF_AQ_RC_ENOENT:
87                 return "AVF_AQ_RC_ENOENT";
88         case AVF_AQ_RC_ESRCH:
89                 return "AVF_AQ_RC_ESRCH";
90         case AVF_AQ_RC_EINTR:
91                 return "AVF_AQ_RC_EINTR";
92         case AVF_AQ_RC_EIO:
93                 return "AVF_AQ_RC_EIO";
94         case AVF_AQ_RC_ENXIO:
95                 return "AVF_AQ_RC_ENXIO";
96         case AVF_AQ_RC_E2BIG:
97                 return "AVF_AQ_RC_E2BIG";
98         case AVF_AQ_RC_EAGAIN:
99                 return "AVF_AQ_RC_EAGAIN";
100         case AVF_AQ_RC_ENOMEM:
101                 return "AVF_AQ_RC_ENOMEM";
102         case AVF_AQ_RC_EACCES:
103                 return "AVF_AQ_RC_EACCES";
104         case AVF_AQ_RC_EFAULT:
105                 return "AVF_AQ_RC_EFAULT";
106         case AVF_AQ_RC_EBUSY:
107                 return "AVF_AQ_RC_EBUSY";
108         case AVF_AQ_RC_EEXIST:
109                 return "AVF_AQ_RC_EEXIST";
110         case AVF_AQ_RC_EINVAL:
111                 return "AVF_AQ_RC_EINVAL";
112         case AVF_AQ_RC_ENOTTY:
113                 return "AVF_AQ_RC_ENOTTY";
114         case AVF_AQ_RC_ENOSPC:
115                 return "AVF_AQ_RC_ENOSPC";
116         case AVF_AQ_RC_ENOSYS:
117                 return "AVF_AQ_RC_ENOSYS";
118         case AVF_AQ_RC_ERANGE:
119                 return "AVF_AQ_RC_ERANGE";
120         case AVF_AQ_RC_EFLUSHED:
121                 return "AVF_AQ_RC_EFLUSHED";
122         case AVF_AQ_RC_BAD_ADDR:
123                 return "AVF_AQ_RC_BAD_ADDR";
124         case AVF_AQ_RC_EMODE:
125                 return "AVF_AQ_RC_EMODE";
126         case AVF_AQ_RC_EFBIG:
127                 return "AVF_AQ_RC_EFBIG";
128         }
129
130         snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
131         return hw->err_str;
132 }
133
134 /**
135  * avf_stat_str - convert status err code to a string
136  * @hw: pointer to the HW structure
137  * @stat_err: the status error code to convert
138  **/
139 const char *avf_stat_str(struct avf_hw *hw, enum avf_status_code stat_err)
140 {
141         switch (stat_err) {
142         case AVF_SUCCESS:
143                 return "OK";
144         case AVF_ERR_NVM:
145                 return "AVF_ERR_NVM";
146         case AVF_ERR_NVM_CHECKSUM:
147                 return "AVF_ERR_NVM_CHECKSUM";
148         case AVF_ERR_PHY:
149                 return "AVF_ERR_PHY";
150         case AVF_ERR_CONFIG:
151                 return "AVF_ERR_CONFIG";
152         case AVF_ERR_PARAM:
153                 return "AVF_ERR_PARAM";
154         case AVF_ERR_MAC_TYPE:
155                 return "AVF_ERR_MAC_TYPE";
156         case AVF_ERR_UNKNOWN_PHY:
157                 return "AVF_ERR_UNKNOWN_PHY";
158         case AVF_ERR_LINK_SETUP:
159                 return "AVF_ERR_LINK_SETUP";
160         case AVF_ERR_ADAPTER_STOPPED:
161                 return "AVF_ERR_ADAPTER_STOPPED";
162         case AVF_ERR_INVALID_MAC_ADDR:
163                 return "AVF_ERR_INVALID_MAC_ADDR";
164         case AVF_ERR_DEVICE_NOT_SUPPORTED:
165                 return "AVF_ERR_DEVICE_NOT_SUPPORTED";
166         case AVF_ERR_MASTER_REQUESTS_PENDING:
167                 return "AVF_ERR_MASTER_REQUESTS_PENDING";
168         case AVF_ERR_INVALID_LINK_SETTINGS:
169                 return "AVF_ERR_INVALID_LINK_SETTINGS";
170         case AVF_ERR_AUTONEG_NOT_COMPLETE:
171                 return "AVF_ERR_AUTONEG_NOT_COMPLETE";
172         case AVF_ERR_RESET_FAILED:
173                 return "AVF_ERR_RESET_FAILED";
174         case AVF_ERR_SWFW_SYNC:
175                 return "AVF_ERR_SWFW_SYNC";
176         case AVF_ERR_NO_AVAILABLE_VSI:
177                 return "AVF_ERR_NO_AVAILABLE_VSI";
178         case AVF_ERR_NO_MEMORY:
179                 return "AVF_ERR_NO_MEMORY";
180         case AVF_ERR_BAD_PTR:
181                 return "AVF_ERR_BAD_PTR";
182         case AVF_ERR_RING_FULL:
183                 return "AVF_ERR_RING_FULL";
184         case AVF_ERR_INVALID_PD_ID:
185                 return "AVF_ERR_INVALID_PD_ID";
186         case AVF_ERR_INVALID_QP_ID:
187                 return "AVF_ERR_INVALID_QP_ID";
188         case AVF_ERR_INVALID_CQ_ID:
189                 return "AVF_ERR_INVALID_CQ_ID";
190         case AVF_ERR_INVALID_CEQ_ID:
191                 return "AVF_ERR_INVALID_CEQ_ID";
192         case AVF_ERR_INVALID_AEQ_ID:
193                 return "AVF_ERR_INVALID_AEQ_ID";
194         case AVF_ERR_INVALID_SIZE:
195                 return "AVF_ERR_INVALID_SIZE";
196         case AVF_ERR_INVALID_ARP_INDEX:
197                 return "AVF_ERR_INVALID_ARP_INDEX";
198         case AVF_ERR_INVALID_FPM_FUNC_ID:
199                 return "AVF_ERR_INVALID_FPM_FUNC_ID";
200         case AVF_ERR_QP_INVALID_MSG_SIZE:
201                 return "AVF_ERR_QP_INVALID_MSG_SIZE";
202         case AVF_ERR_QP_TOOMANY_WRS_POSTED:
203                 return "AVF_ERR_QP_TOOMANY_WRS_POSTED";
204         case AVF_ERR_INVALID_FRAG_COUNT:
205                 return "AVF_ERR_INVALID_FRAG_COUNT";
206         case AVF_ERR_QUEUE_EMPTY:
207                 return "AVF_ERR_QUEUE_EMPTY";
208         case AVF_ERR_INVALID_ALIGNMENT:
209                 return "AVF_ERR_INVALID_ALIGNMENT";
210         case AVF_ERR_FLUSHED_QUEUE:
211                 return "AVF_ERR_FLUSHED_QUEUE";
212         case AVF_ERR_INVALID_PUSH_PAGE_INDEX:
213                 return "AVF_ERR_INVALID_PUSH_PAGE_INDEX";
214         case AVF_ERR_INVALID_IMM_DATA_SIZE:
215                 return "AVF_ERR_INVALID_IMM_DATA_SIZE";
216         case AVF_ERR_TIMEOUT:
217                 return "AVF_ERR_TIMEOUT";
218         case AVF_ERR_OPCODE_MISMATCH:
219                 return "AVF_ERR_OPCODE_MISMATCH";
220         case AVF_ERR_CQP_COMPL_ERROR:
221                 return "AVF_ERR_CQP_COMPL_ERROR";
222         case AVF_ERR_INVALID_VF_ID:
223                 return "AVF_ERR_INVALID_VF_ID";
224         case AVF_ERR_INVALID_HMCFN_ID:
225                 return "AVF_ERR_INVALID_HMCFN_ID";
226         case AVF_ERR_BACKING_PAGE_ERROR:
227                 return "AVF_ERR_BACKING_PAGE_ERROR";
228         case AVF_ERR_NO_PBLCHUNKS_AVAILABLE:
229                 return "AVF_ERR_NO_PBLCHUNKS_AVAILABLE";
230         case AVF_ERR_INVALID_PBLE_INDEX:
231                 return "AVF_ERR_INVALID_PBLE_INDEX";
232         case AVF_ERR_INVALID_SD_INDEX:
233                 return "AVF_ERR_INVALID_SD_INDEX";
234         case AVF_ERR_INVALID_PAGE_DESC_INDEX:
235                 return "AVF_ERR_INVALID_PAGE_DESC_INDEX";
236         case AVF_ERR_INVALID_SD_TYPE:
237                 return "AVF_ERR_INVALID_SD_TYPE";
238         case AVF_ERR_MEMCPY_FAILED:
239                 return "AVF_ERR_MEMCPY_FAILED";
240         case AVF_ERR_INVALID_HMC_OBJ_INDEX:
241                 return "AVF_ERR_INVALID_HMC_OBJ_INDEX";
242         case AVF_ERR_INVALID_HMC_OBJ_COUNT:
243                 return "AVF_ERR_INVALID_HMC_OBJ_COUNT";
244         case AVF_ERR_INVALID_SRQ_ARM_LIMIT:
245                 return "AVF_ERR_INVALID_SRQ_ARM_LIMIT";
246         case AVF_ERR_SRQ_ENABLED:
247                 return "AVF_ERR_SRQ_ENABLED";
248         case AVF_ERR_ADMIN_QUEUE_ERROR:
249                 return "AVF_ERR_ADMIN_QUEUE_ERROR";
250         case AVF_ERR_ADMIN_QUEUE_TIMEOUT:
251                 return "AVF_ERR_ADMIN_QUEUE_TIMEOUT";
252         case AVF_ERR_BUF_TOO_SHORT:
253                 return "AVF_ERR_BUF_TOO_SHORT";
254         case AVF_ERR_ADMIN_QUEUE_FULL:
255                 return "AVF_ERR_ADMIN_QUEUE_FULL";
256         case AVF_ERR_ADMIN_QUEUE_NO_WORK:
257                 return "AVF_ERR_ADMIN_QUEUE_NO_WORK";
258         case AVF_ERR_BAD_IWARP_CQE:
259                 return "AVF_ERR_BAD_IWARP_CQE";
260         case AVF_ERR_NVM_BLANK_MODE:
261                 return "AVF_ERR_NVM_BLANK_MODE";
262         case AVF_ERR_NOT_IMPLEMENTED:
263                 return "AVF_ERR_NOT_IMPLEMENTED";
264         case AVF_ERR_PE_DOORBELL_NOT_ENABLED:
265                 return "AVF_ERR_PE_DOORBELL_NOT_ENABLED";
266         case AVF_ERR_DIAG_TEST_FAILED:
267                 return "AVF_ERR_DIAG_TEST_FAILED";
268         case AVF_ERR_NOT_READY:
269                 return "AVF_ERR_NOT_READY";
270         case AVF_NOT_SUPPORTED:
271                 return "AVF_NOT_SUPPORTED";
272         case AVF_ERR_FIRMWARE_API_VERSION:
273                 return "AVF_ERR_FIRMWARE_API_VERSION";
274         case AVF_ERR_ADMIN_QUEUE_CRITICAL_ERROR:
275                 return "AVF_ERR_ADMIN_QUEUE_CRITICAL_ERROR";
276         }
277
278         snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
279         return hw->err_str;
280 }
281
282 /**
283  * avf_debug_aq
284  * @hw: debug mask related to admin queue
285  * @mask: debug mask
286  * @desc: pointer to admin queue descriptor
287  * @buffer: pointer to command buffer
288  * @buf_len: max length of buffer
289  *
290  * Dumps debug log about adminq command with descriptor contents.
291  **/
292 void avf_debug_aq(struct avf_hw *hw, enum avf_debug_mask mask, void *desc,
293                    void *buffer, u16 buf_len)
294 {
295         struct avf_aq_desc *aq_desc = (struct avf_aq_desc *)desc;
296         u8 *buf = (u8 *)buffer;
297         u16 len;
298         u16 i = 0;
299
300         if ((!(mask & hw->debug_mask)) || (desc == NULL))
301                 return;
302
303         len = LE16_TO_CPU(aq_desc->datalen);
304
305         avf_debug(hw, mask,
306                    "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
307                    LE16_TO_CPU(aq_desc->opcode),
308                    LE16_TO_CPU(aq_desc->flags),
309                    LE16_TO_CPU(aq_desc->datalen),
310                    LE16_TO_CPU(aq_desc->retval));
311         avf_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
312                    LE32_TO_CPU(aq_desc->cookie_high),
313                    LE32_TO_CPU(aq_desc->cookie_low));
314         avf_debug(hw, mask, "\tparam (0,1)  0x%08X 0x%08X\n",
315                    LE32_TO_CPU(aq_desc->params.internal.param0),
316                    LE32_TO_CPU(aq_desc->params.internal.param1));
317         avf_debug(hw, mask, "\taddr (h,l)   0x%08X 0x%08X\n",
318                    LE32_TO_CPU(aq_desc->params.external.addr_high),
319                    LE32_TO_CPU(aq_desc->params.external.addr_low));
320
321         if ((buffer != NULL) && (aq_desc->datalen != 0)) {
322                 avf_debug(hw, mask, "AQ CMD Buffer:\n");
323                 if (buf_len < len)
324                         len = buf_len;
325                 /* write the full 16-byte chunks */
326                 for (i = 0; i < (len - 16); i += 16)
327                         avf_debug(hw, mask,
328                                    "\t0x%04X  %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
329                                    i, buf[i], buf[i+1], buf[i+2], buf[i+3],
330                                    buf[i+4], buf[i+5], buf[i+6], buf[i+7],
331                                    buf[i+8], buf[i+9], buf[i+10], buf[i+11],
332                                    buf[i+12], buf[i+13], buf[i+14], buf[i+15]);
333                 /* the most we could have left is 16 bytes, pad with zeros */
334                 if (i < len) {
335                         char d_buf[16];
336                         int j, i_sav;
337
338                         i_sav = i;
339                         memset(d_buf, 0, sizeof(d_buf));
340                         for (j = 0; i < len; j++, i++)
341                                 d_buf[j] = buf[i];
342                         avf_debug(hw, mask,
343                                    "\t0x%04X  %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
344                                    i_sav, d_buf[0], d_buf[1], d_buf[2], d_buf[3],
345                                    d_buf[4], d_buf[5], d_buf[6], d_buf[7],
346                                    d_buf[8], d_buf[9], d_buf[10], d_buf[11],
347                                    d_buf[12], d_buf[13], d_buf[14], d_buf[15]);
348                 }
349         }
350 }
351
352 /**
353  * avf_check_asq_alive
354  * @hw: pointer to the hw struct
355  *
356  * Returns true if Queue is enabled else false.
357  **/
358 bool avf_check_asq_alive(struct avf_hw *hw)
359 {
360         if (hw->aq.asq.len)
361 #ifdef INTEGRATED_VF
362                 if (avf_is_vf(hw))
363                         return !!(rd32(hw, hw->aq.asq.len) &
364                                 AVF_ATQLEN1_ATQENABLE_MASK);
365 #else
366                 return !!(rd32(hw, hw->aq.asq.len) &
367                         AVF_ATQLEN1_ATQENABLE_MASK);
368 #endif /* INTEGRATED_VF */
369         return false;
370 }
371
372 /**
373  * avf_aq_queue_shutdown
374  * @hw: pointer to the hw struct
375  * @unloading: is the driver unloading itself
376  *
377  * Tell the Firmware that we're shutting down the AdminQ and whether
378  * or not the driver is unloading as well.
379  **/
380 enum avf_status_code avf_aq_queue_shutdown(struct avf_hw *hw,
381                                              bool unloading)
382 {
383         struct avf_aq_desc desc;
384         struct avf_aqc_queue_shutdown *cmd =
385                 (struct avf_aqc_queue_shutdown *)&desc.params.raw;
386         enum avf_status_code status;
387
388         avf_fill_default_direct_cmd_desc(&desc,
389                                           avf_aqc_opc_queue_shutdown);
390
391         if (unloading)
392                 cmd->driver_unloading = CPU_TO_LE32(AVF_AQ_DRIVER_UNLOADING);
393         status = avf_asq_send_command(hw, &desc, NULL, 0, NULL);
394
395         return status;
396 }
397
398 /**
399  * avf_aq_get_set_rss_lut
400  * @hw: pointer to the hardware structure
401  * @vsi_id: vsi fw index
402  * @pf_lut: for PF table set true, for VSI table set false
403  * @lut: pointer to the lut buffer provided by the caller
404  * @lut_size: size of the lut buffer
405  * @set: set true to set the table, false to get the table
406  *
407  * Internal function to get or set RSS look up table
408  **/
409 STATIC enum avf_status_code avf_aq_get_set_rss_lut(struct avf_hw *hw,
410                                                      u16 vsi_id, bool pf_lut,
411                                                      u8 *lut, u16 lut_size,
412                                                      bool set)
413 {
414         enum avf_status_code status;
415         struct avf_aq_desc desc;
416         struct avf_aqc_get_set_rss_lut *cmd_resp =
417                    (struct avf_aqc_get_set_rss_lut *)&desc.params.raw;
418
419         if (set)
420                 avf_fill_default_direct_cmd_desc(&desc,
421                                                   avf_aqc_opc_set_rss_lut);
422         else
423                 avf_fill_default_direct_cmd_desc(&desc,
424                                                   avf_aqc_opc_get_rss_lut);
425
426         /* Indirect command */
427         desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_BUF);
428         desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_RD);
429
430         cmd_resp->vsi_id =
431                         CPU_TO_LE16((u16)((vsi_id <<
432                                           AVF_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
433                                           AVF_AQC_SET_RSS_LUT_VSI_ID_MASK));
434         cmd_resp->vsi_id |= CPU_TO_LE16((u16)AVF_AQC_SET_RSS_LUT_VSI_VALID);
435
436         if (pf_lut)
437                 cmd_resp->flags |= CPU_TO_LE16((u16)
438                                         ((AVF_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
439                                         AVF_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
440                                         AVF_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
441         else
442                 cmd_resp->flags |= CPU_TO_LE16((u16)
443                                         ((AVF_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
444                                         AVF_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
445                                         AVF_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
446
447         status = avf_asq_send_command(hw, &desc, lut, lut_size, NULL);
448
449         return status;
450 }
451
452 /**
453  * avf_aq_get_rss_lut
454  * @hw: pointer to the hardware structure
455  * @vsi_id: vsi fw index
456  * @pf_lut: for PF table set true, for VSI table set false
457  * @lut: pointer to the lut buffer provided by the caller
458  * @lut_size: size of the lut buffer
459  *
460  * get the RSS lookup table, PF or VSI type
461  **/
462 enum avf_status_code avf_aq_get_rss_lut(struct avf_hw *hw, u16 vsi_id,
463                                           bool pf_lut, u8 *lut, u16 lut_size)
464 {
465         return avf_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
466                                        false);
467 }
468
469 /**
470  * avf_aq_set_rss_lut
471  * @hw: pointer to the hardware structure
472  * @vsi_id: vsi fw index
473  * @pf_lut: for PF table set true, for VSI table set false
474  * @lut: pointer to the lut buffer provided by the caller
475  * @lut_size: size of the lut buffer
476  *
477  * set the RSS lookup table, PF or VSI type
478  **/
479 enum avf_status_code avf_aq_set_rss_lut(struct avf_hw *hw, u16 vsi_id,
480                                           bool pf_lut, u8 *lut, u16 lut_size)
481 {
482         return avf_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
483 }
484
485 /**
486  * avf_aq_get_set_rss_key
487  * @hw: pointer to the hw struct
488  * @vsi_id: vsi fw index
489  * @key: pointer to key info struct
490  * @set: set true to set the key, false to get the key
491  *
492  * get the RSS key per VSI
493  **/
494 STATIC enum avf_status_code avf_aq_get_set_rss_key(struct avf_hw *hw,
495                                       u16 vsi_id,
496                                       struct avf_aqc_get_set_rss_key_data *key,
497                                       bool set)
498 {
499         enum avf_status_code status;
500         struct avf_aq_desc desc;
501         struct avf_aqc_get_set_rss_key *cmd_resp =
502                         (struct avf_aqc_get_set_rss_key *)&desc.params.raw;
503         u16 key_size = sizeof(struct avf_aqc_get_set_rss_key_data);
504
505         if (set)
506                 avf_fill_default_direct_cmd_desc(&desc,
507                                                   avf_aqc_opc_set_rss_key);
508         else
509                 avf_fill_default_direct_cmd_desc(&desc,
510                                                   avf_aqc_opc_get_rss_key);
511
512         /* Indirect command */
513         desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_BUF);
514         desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_RD);
515
516         cmd_resp->vsi_id =
517                         CPU_TO_LE16((u16)((vsi_id <<
518                                           AVF_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
519                                           AVF_AQC_SET_RSS_KEY_VSI_ID_MASK));
520         cmd_resp->vsi_id |= CPU_TO_LE16((u16)AVF_AQC_SET_RSS_KEY_VSI_VALID);
521
522         status = avf_asq_send_command(hw, &desc, key, key_size, NULL);
523
524         return status;
525 }
526
527 /**
528  * avf_aq_get_rss_key
529  * @hw: pointer to the hw struct
530  * @vsi_id: vsi fw index
531  * @key: pointer to key info struct
532  *
533  **/
534 enum avf_status_code avf_aq_get_rss_key(struct avf_hw *hw,
535                                       u16 vsi_id,
536                                       struct avf_aqc_get_set_rss_key_data *key)
537 {
538         return avf_aq_get_set_rss_key(hw, vsi_id, key, false);
539 }
540
541 /**
542  * avf_aq_set_rss_key
543  * @hw: pointer to the hw struct
544  * @vsi_id: vsi fw index
545  * @key: pointer to key info struct
546  *
547  * set the RSS key per VSI
548  **/
549 enum avf_status_code avf_aq_set_rss_key(struct avf_hw *hw,
550                                       u16 vsi_id,
551                                       struct avf_aqc_get_set_rss_key_data *key)
552 {
553         return avf_aq_get_set_rss_key(hw, vsi_id, key, true);
554 }
555
556 /* The avf_ptype_lookup table is used to convert from the 8-bit ptype in the
557  * hardware to a bit-field that can be used by SW to more easily determine the
558  * packet type.
559  *
560  * Macros are used to shorten the table lines and make this table human
561  * readable.
562  *
563  * We store the PTYPE in the top byte of the bit field - this is just so that
564  * we can check that the table doesn't have a row missing, as the index into
565  * the table should be the PTYPE.
566  *
567  * Typical work flow:
568  *
569  * IF NOT avf_ptype_lookup[ptype].known
570  * THEN
571  *      Packet is unknown
572  * ELSE IF avf_ptype_lookup[ptype].outer_ip == AVF_RX_PTYPE_OUTER_IP
573  *      Use the rest of the fields to look at the tunnels, inner protocols, etc
574  * ELSE
575  *      Use the enum avf_rx_l2_ptype to decode the packet type
576  * ENDIF
577  */
578
579 /* macro to make the table lines short */
580 #define AVF_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
581         {       PTYPE, \
582                 1, \
583                 AVF_RX_PTYPE_OUTER_##OUTER_IP, \
584                 AVF_RX_PTYPE_OUTER_##OUTER_IP_VER, \
585                 AVF_RX_PTYPE_##OUTER_FRAG, \
586                 AVF_RX_PTYPE_TUNNEL_##T, \
587                 AVF_RX_PTYPE_TUNNEL_END_##TE, \
588                 AVF_RX_PTYPE_##TEF, \
589                 AVF_RX_PTYPE_INNER_PROT_##I, \
590                 AVF_RX_PTYPE_PAYLOAD_LAYER_##PL }
591
592 #define AVF_PTT_UNUSED_ENTRY(PTYPE) \
593                 { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
594
595 /* shorter macros makes the table fit but are terse */
596 #define AVF_RX_PTYPE_NOF                AVF_RX_PTYPE_NOT_FRAG
597 #define AVF_RX_PTYPE_FRG                AVF_RX_PTYPE_FRAG
598 #define AVF_RX_PTYPE_INNER_PROT_TS      AVF_RX_PTYPE_INNER_PROT_TIMESYNC
599
600 /* Lookup table mapping the HW PTYPE to the bit field for decoding */
601 struct avf_rx_ptype_decoded avf_ptype_lookup[] = {
602         /* L2 Packet types */
603         AVF_PTT_UNUSED_ENTRY(0),
604         AVF_PTT(1,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
605         AVF_PTT(2,  L2, NONE, NOF, NONE, NONE, NOF, TS,   PAY2),
606         AVF_PTT(3,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
607         AVF_PTT_UNUSED_ENTRY(4),
608         AVF_PTT_UNUSED_ENTRY(5),
609         AVF_PTT(6,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
610         AVF_PTT(7,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
611         AVF_PTT_UNUSED_ENTRY(8),
612         AVF_PTT_UNUSED_ENTRY(9),
613         AVF_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
614         AVF_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
615         AVF_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
616         AVF_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
617         AVF_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
618         AVF_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
619         AVF_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
620         AVF_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
621         AVF_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
622         AVF_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
623         AVF_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
624         AVF_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
625
626         /* Non Tunneled IPv4 */
627         AVF_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
628         AVF_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
629         AVF_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP,  PAY4),
630         AVF_PTT_UNUSED_ENTRY(25),
631         AVF_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP,  PAY4),
632         AVF_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
633         AVF_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
634
635         /* IPv4 --> IPv4 */
636         AVF_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
637         AVF_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
638         AVF_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
639         AVF_PTT_UNUSED_ENTRY(32),
640         AVF_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
641         AVF_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
642         AVF_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
643
644         /* IPv4 --> IPv6 */
645         AVF_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
646         AVF_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
647         AVF_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
648         AVF_PTT_UNUSED_ENTRY(39),
649         AVF_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
650         AVF_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
651         AVF_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
652
653         /* IPv4 --> GRE/NAT */
654         AVF_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
655
656         /* IPv4 --> GRE/NAT --> IPv4 */
657         AVF_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
658         AVF_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
659         AVF_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
660         AVF_PTT_UNUSED_ENTRY(47),
661         AVF_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
662         AVF_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
663         AVF_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
664
665         /* IPv4 --> GRE/NAT --> IPv6 */
666         AVF_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
667         AVF_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
668         AVF_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
669         AVF_PTT_UNUSED_ENTRY(54),
670         AVF_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
671         AVF_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
672         AVF_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
673
674         /* IPv4 --> GRE/NAT --> MAC */
675         AVF_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
676
677         /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
678         AVF_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
679         AVF_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
680         AVF_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
681         AVF_PTT_UNUSED_ENTRY(62),
682         AVF_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
683         AVF_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
684         AVF_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
685
686         /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
687         AVF_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
688         AVF_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
689         AVF_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
690         AVF_PTT_UNUSED_ENTRY(69),
691         AVF_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
692         AVF_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
693         AVF_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
694
695         /* IPv4 --> GRE/NAT --> MAC/VLAN */
696         AVF_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
697
698         /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
699         AVF_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
700         AVF_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
701         AVF_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
702         AVF_PTT_UNUSED_ENTRY(77),
703         AVF_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
704         AVF_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
705         AVF_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
706
707         /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
708         AVF_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
709         AVF_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
710         AVF_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
711         AVF_PTT_UNUSED_ENTRY(84),
712         AVF_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
713         AVF_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
714         AVF_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
715
716         /* Non Tunneled IPv6 */
717         AVF_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
718         AVF_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
719         AVF_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP,  PAY4),
720         AVF_PTT_UNUSED_ENTRY(91),
721         AVF_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP,  PAY4),
722         AVF_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
723         AVF_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
724
725         /* IPv6 --> IPv4 */
726         AVF_PTT(95,  IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
727         AVF_PTT(96,  IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
728         AVF_PTT(97,  IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
729         AVF_PTT_UNUSED_ENTRY(98),
730         AVF_PTT(99,  IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
731         AVF_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
732         AVF_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
733
734         /* IPv6 --> IPv6 */
735         AVF_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
736         AVF_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
737         AVF_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
738         AVF_PTT_UNUSED_ENTRY(105),
739         AVF_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
740         AVF_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
741         AVF_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
742
743         /* IPv6 --> GRE/NAT */
744         AVF_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
745
746         /* IPv6 --> GRE/NAT -> IPv4 */
747         AVF_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
748         AVF_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
749         AVF_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
750         AVF_PTT_UNUSED_ENTRY(113),
751         AVF_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
752         AVF_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
753         AVF_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
754
755         /* IPv6 --> GRE/NAT -> IPv6 */
756         AVF_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
757         AVF_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
758         AVF_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
759         AVF_PTT_UNUSED_ENTRY(120),
760         AVF_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
761         AVF_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
762         AVF_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
763
764         /* IPv6 --> GRE/NAT -> MAC */
765         AVF_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
766
767         /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
768         AVF_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
769         AVF_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
770         AVF_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
771         AVF_PTT_UNUSED_ENTRY(128),
772         AVF_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
773         AVF_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
774         AVF_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
775
776         /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
777         AVF_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
778         AVF_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
779         AVF_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
780         AVF_PTT_UNUSED_ENTRY(135),
781         AVF_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
782         AVF_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
783         AVF_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
784
785         /* IPv6 --> GRE/NAT -> MAC/VLAN */
786         AVF_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
787
788         /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
789         AVF_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
790         AVF_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
791         AVF_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
792         AVF_PTT_UNUSED_ENTRY(143),
793         AVF_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
794         AVF_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
795         AVF_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
796
797         /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
798         AVF_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
799         AVF_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
800         AVF_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
801         AVF_PTT_UNUSED_ENTRY(150),
802         AVF_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
803         AVF_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
804         AVF_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
805
806         /* unused entries */
807         AVF_PTT_UNUSED_ENTRY(154),
808         AVF_PTT_UNUSED_ENTRY(155),
809         AVF_PTT_UNUSED_ENTRY(156),
810         AVF_PTT_UNUSED_ENTRY(157),
811         AVF_PTT_UNUSED_ENTRY(158),
812         AVF_PTT_UNUSED_ENTRY(159),
813
814         AVF_PTT_UNUSED_ENTRY(160),
815         AVF_PTT_UNUSED_ENTRY(161),
816         AVF_PTT_UNUSED_ENTRY(162),
817         AVF_PTT_UNUSED_ENTRY(163),
818         AVF_PTT_UNUSED_ENTRY(164),
819         AVF_PTT_UNUSED_ENTRY(165),
820         AVF_PTT_UNUSED_ENTRY(166),
821         AVF_PTT_UNUSED_ENTRY(167),
822         AVF_PTT_UNUSED_ENTRY(168),
823         AVF_PTT_UNUSED_ENTRY(169),
824
825         AVF_PTT_UNUSED_ENTRY(170),
826         AVF_PTT_UNUSED_ENTRY(171),
827         AVF_PTT_UNUSED_ENTRY(172),
828         AVF_PTT_UNUSED_ENTRY(173),
829         AVF_PTT_UNUSED_ENTRY(174),
830         AVF_PTT_UNUSED_ENTRY(175),
831         AVF_PTT_UNUSED_ENTRY(176),
832         AVF_PTT_UNUSED_ENTRY(177),
833         AVF_PTT_UNUSED_ENTRY(178),
834         AVF_PTT_UNUSED_ENTRY(179),
835
836         AVF_PTT_UNUSED_ENTRY(180),
837         AVF_PTT_UNUSED_ENTRY(181),
838         AVF_PTT_UNUSED_ENTRY(182),
839         AVF_PTT_UNUSED_ENTRY(183),
840         AVF_PTT_UNUSED_ENTRY(184),
841         AVF_PTT_UNUSED_ENTRY(185),
842         AVF_PTT_UNUSED_ENTRY(186),
843         AVF_PTT_UNUSED_ENTRY(187),
844         AVF_PTT_UNUSED_ENTRY(188),
845         AVF_PTT_UNUSED_ENTRY(189),
846
847         AVF_PTT_UNUSED_ENTRY(190),
848         AVF_PTT_UNUSED_ENTRY(191),
849         AVF_PTT_UNUSED_ENTRY(192),
850         AVF_PTT_UNUSED_ENTRY(193),
851         AVF_PTT_UNUSED_ENTRY(194),
852         AVF_PTT_UNUSED_ENTRY(195),
853         AVF_PTT_UNUSED_ENTRY(196),
854         AVF_PTT_UNUSED_ENTRY(197),
855         AVF_PTT_UNUSED_ENTRY(198),
856         AVF_PTT_UNUSED_ENTRY(199),
857
858         AVF_PTT_UNUSED_ENTRY(200),
859         AVF_PTT_UNUSED_ENTRY(201),
860         AVF_PTT_UNUSED_ENTRY(202),
861         AVF_PTT_UNUSED_ENTRY(203),
862         AVF_PTT_UNUSED_ENTRY(204),
863         AVF_PTT_UNUSED_ENTRY(205),
864         AVF_PTT_UNUSED_ENTRY(206),
865         AVF_PTT_UNUSED_ENTRY(207),
866         AVF_PTT_UNUSED_ENTRY(208),
867         AVF_PTT_UNUSED_ENTRY(209),
868
869         AVF_PTT_UNUSED_ENTRY(210),
870         AVF_PTT_UNUSED_ENTRY(211),
871         AVF_PTT_UNUSED_ENTRY(212),
872         AVF_PTT_UNUSED_ENTRY(213),
873         AVF_PTT_UNUSED_ENTRY(214),
874         AVF_PTT_UNUSED_ENTRY(215),
875         AVF_PTT_UNUSED_ENTRY(216),
876         AVF_PTT_UNUSED_ENTRY(217),
877         AVF_PTT_UNUSED_ENTRY(218),
878         AVF_PTT_UNUSED_ENTRY(219),
879
880         AVF_PTT_UNUSED_ENTRY(220),
881         AVF_PTT_UNUSED_ENTRY(221),
882         AVF_PTT_UNUSED_ENTRY(222),
883         AVF_PTT_UNUSED_ENTRY(223),
884         AVF_PTT_UNUSED_ENTRY(224),
885         AVF_PTT_UNUSED_ENTRY(225),
886         AVF_PTT_UNUSED_ENTRY(226),
887         AVF_PTT_UNUSED_ENTRY(227),
888         AVF_PTT_UNUSED_ENTRY(228),
889         AVF_PTT_UNUSED_ENTRY(229),
890
891         AVF_PTT_UNUSED_ENTRY(230),
892         AVF_PTT_UNUSED_ENTRY(231),
893         AVF_PTT_UNUSED_ENTRY(232),
894         AVF_PTT_UNUSED_ENTRY(233),
895         AVF_PTT_UNUSED_ENTRY(234),
896         AVF_PTT_UNUSED_ENTRY(235),
897         AVF_PTT_UNUSED_ENTRY(236),
898         AVF_PTT_UNUSED_ENTRY(237),
899         AVF_PTT_UNUSED_ENTRY(238),
900         AVF_PTT_UNUSED_ENTRY(239),
901
902         AVF_PTT_UNUSED_ENTRY(240),
903         AVF_PTT_UNUSED_ENTRY(241),
904         AVF_PTT_UNUSED_ENTRY(242),
905         AVF_PTT_UNUSED_ENTRY(243),
906         AVF_PTT_UNUSED_ENTRY(244),
907         AVF_PTT_UNUSED_ENTRY(245),
908         AVF_PTT_UNUSED_ENTRY(246),
909         AVF_PTT_UNUSED_ENTRY(247),
910         AVF_PTT_UNUSED_ENTRY(248),
911         AVF_PTT_UNUSED_ENTRY(249),
912
913         AVF_PTT_UNUSED_ENTRY(250),
914         AVF_PTT_UNUSED_ENTRY(251),
915         AVF_PTT_UNUSED_ENTRY(252),
916         AVF_PTT_UNUSED_ENTRY(253),
917         AVF_PTT_UNUSED_ENTRY(254),
918         AVF_PTT_UNUSED_ENTRY(255)
919 };
920
921
922 /**
923  * avf_validate_mac_addr - Validate unicast MAC address
924  * @mac_addr: pointer to MAC address
925  *
926  * Tests a MAC address to ensure it is a valid Individual Address
927  **/
928 enum avf_status_code avf_validate_mac_addr(u8 *mac_addr)
929 {
930         enum avf_status_code status = AVF_SUCCESS;
931
932         DEBUGFUNC("avf_validate_mac_addr");
933
934         /* Broadcast addresses ARE multicast addresses
935          * Make sure it is not a multicast address
936          * Reject the zero address
937          */
938         if (AVF_IS_MULTICAST(mac_addr) ||
939             (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
940               mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0))
941                 status = AVF_ERR_INVALID_MAC_ADDR;
942
943         return status;
944 }
945
946 /**
947  * avf_aq_rx_ctl_read_register - use FW to read from an Rx control register
948  * @hw: pointer to the hw struct
949  * @reg_addr: register address
950  * @reg_val: ptr to register value
951  * @cmd_details: pointer to command details structure or NULL
952  *
953  * Use the firmware to read the Rx control register,
954  * especially useful if the Rx unit is under heavy pressure
955  **/
956 enum avf_status_code avf_aq_rx_ctl_read_register(struct avf_hw *hw,
957                                 u32 reg_addr, u32 *reg_val,
958                                 struct avf_asq_cmd_details *cmd_details)
959 {
960         struct avf_aq_desc desc;
961         struct avf_aqc_rx_ctl_reg_read_write *cmd_resp =
962                 (struct avf_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
963         enum avf_status_code status;
964
965         if (reg_val == NULL)
966                 return AVF_ERR_PARAM;
967
968         avf_fill_default_direct_cmd_desc(&desc, avf_aqc_opc_rx_ctl_reg_read);
969
970         cmd_resp->address = CPU_TO_LE32(reg_addr);
971
972         status = avf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
973
974         if (status == AVF_SUCCESS)
975                 *reg_val = LE32_TO_CPU(cmd_resp->value);
976
977         return status;
978 }
979
980 /**
981  * avf_read_rx_ctl - read from an Rx control register
982  * @hw: pointer to the hw struct
983  * @reg_addr: register address
984  **/
985 u32 avf_read_rx_ctl(struct avf_hw *hw, u32 reg_addr)
986 {
987         enum avf_status_code status = AVF_SUCCESS;
988         bool use_register;
989         int retry = 5;
990         u32 val = 0;
991
992         use_register = (((hw->aq.api_maj_ver == 1) &&
993                         (hw->aq.api_min_ver < 5)) ||
994                         (hw->mac.type == AVF_MAC_X722));
995         if (!use_register) {
996 do_retry:
997                 status = avf_aq_rx_ctl_read_register(hw, reg_addr, &val, NULL);
998                 if (hw->aq.asq_last_status == AVF_AQ_RC_EAGAIN && retry) {
999                         avf_msec_delay(1);
1000                         retry--;
1001                         goto do_retry;
1002                 }
1003         }
1004
1005         /* if the AQ access failed, try the old-fashioned way */
1006         if (status || use_register)
1007                 val = rd32(hw, reg_addr);
1008
1009         return val;
1010 }
1011
1012 /**
1013  * avf_aq_rx_ctl_write_register
1014  * @hw: pointer to the hw struct
1015  * @reg_addr: register address
1016  * @reg_val: register value
1017  * @cmd_details: pointer to command details structure or NULL
1018  *
1019  * Use the firmware to write to an Rx control register,
1020  * especially useful if the Rx unit is under heavy pressure
1021  **/
1022 enum avf_status_code avf_aq_rx_ctl_write_register(struct avf_hw *hw,
1023                                 u32 reg_addr, u32 reg_val,
1024                                 struct avf_asq_cmd_details *cmd_details)
1025 {
1026         struct avf_aq_desc desc;
1027         struct avf_aqc_rx_ctl_reg_read_write *cmd =
1028                 (struct avf_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
1029         enum avf_status_code status;
1030
1031         avf_fill_default_direct_cmd_desc(&desc, avf_aqc_opc_rx_ctl_reg_write);
1032
1033         cmd->address = CPU_TO_LE32(reg_addr);
1034         cmd->value = CPU_TO_LE32(reg_val);
1035
1036         status = avf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1037
1038         return status;
1039 }
1040
1041 /**
1042  * avf_write_rx_ctl - write to an Rx control register
1043  * @hw: pointer to the hw struct
1044  * @reg_addr: register address
1045  * @reg_val: register value
1046  **/
1047 void avf_write_rx_ctl(struct avf_hw *hw, u32 reg_addr, u32 reg_val)
1048 {
1049         enum avf_status_code status = AVF_SUCCESS;
1050         bool use_register;
1051         int retry = 5;
1052
1053         use_register = (((hw->aq.api_maj_ver == 1) &&
1054                         (hw->aq.api_min_ver < 5)) ||
1055                         (hw->mac.type == AVF_MAC_X722));
1056         if (!use_register) {
1057 do_retry:
1058                 status = avf_aq_rx_ctl_write_register(hw, reg_addr,
1059                                                        reg_val, NULL);
1060                 if (hw->aq.asq_last_status == AVF_AQ_RC_EAGAIN && retry) {
1061                         avf_msec_delay(1);
1062                         retry--;
1063                         goto do_retry;
1064                 }
1065         }
1066
1067         /* if the AQ access failed, try the old-fashioned way */
1068         if (status || use_register)
1069                 wr32(hw, reg_addr, reg_val);
1070 }
1071
1072 /**
1073  * avf_aq_set_phy_register
1074  * @hw: pointer to the hw struct
1075  * @phy_select: select which phy should be accessed
1076  * @dev_addr: PHY device address
1077  * @reg_addr: PHY register address
1078  * @reg_val: new register value
1079  * @cmd_details: pointer to command details structure or NULL
1080  *
1081  * Write the external PHY register.
1082  **/
1083 enum avf_status_code avf_aq_set_phy_register(struct avf_hw *hw,
1084                                 u8 phy_select, u8 dev_addr,
1085                                 u32 reg_addr, u32 reg_val,
1086                                 struct avf_asq_cmd_details *cmd_details)
1087 {
1088         struct avf_aq_desc desc;
1089         struct avf_aqc_phy_register_access *cmd =
1090                 (struct avf_aqc_phy_register_access *)&desc.params.raw;
1091         enum avf_status_code status;
1092
1093         avf_fill_default_direct_cmd_desc(&desc,
1094                                           avf_aqc_opc_set_phy_register);
1095
1096         cmd->phy_interface = phy_select;
1097         cmd->dev_addres = dev_addr;
1098         cmd->reg_address = CPU_TO_LE32(reg_addr);
1099         cmd->reg_value = CPU_TO_LE32(reg_val);
1100
1101         status = avf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1102
1103         return status;
1104 }
1105
1106 /**
1107  * avf_aq_get_phy_register
1108  * @hw: pointer to the hw struct
1109  * @phy_select: select which phy should be accessed
1110  * @dev_addr: PHY device address
1111  * @reg_addr: PHY register address
1112  * @reg_val: read register value
1113  * @cmd_details: pointer to command details structure or NULL
1114  *
1115  * Read the external PHY register.
1116  **/
1117 enum avf_status_code avf_aq_get_phy_register(struct avf_hw *hw,
1118                                 u8 phy_select, u8 dev_addr,
1119                                 u32 reg_addr, u32 *reg_val,
1120                                 struct avf_asq_cmd_details *cmd_details)
1121 {
1122         struct avf_aq_desc desc;
1123         struct avf_aqc_phy_register_access *cmd =
1124                 (struct avf_aqc_phy_register_access *)&desc.params.raw;
1125         enum avf_status_code status;
1126
1127         avf_fill_default_direct_cmd_desc(&desc,
1128                                           avf_aqc_opc_get_phy_register);
1129
1130         cmd->phy_interface = phy_select;
1131         cmd->dev_addres = dev_addr;
1132         cmd->reg_address = CPU_TO_LE32(reg_addr);
1133
1134         status = avf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1135         if (!status)
1136                 *reg_val = LE32_TO_CPU(cmd->reg_value);
1137
1138         return status;
1139 }
1140
1141
1142 /**
1143  * avf_aq_send_msg_to_pf
1144  * @hw: pointer to the hardware structure
1145  * @v_opcode: opcodes for VF-PF communication
1146  * @v_retval: return error code
1147  * @msg: pointer to the msg buffer
1148  * @msglen: msg length
1149  * @cmd_details: pointer to command details
1150  *
1151  * Send message to PF driver using admin queue. By default, this message
1152  * is sent asynchronously, i.e. avf_asq_send_command() does not wait for
1153  * completion before returning.
1154  **/
1155 enum avf_status_code avf_aq_send_msg_to_pf(struct avf_hw *hw,
1156                                 enum virtchnl_ops v_opcode,
1157                                 enum avf_status_code v_retval,
1158                                 u8 *msg, u16 msglen,
1159                                 struct avf_asq_cmd_details *cmd_details)
1160 {
1161         struct avf_aq_desc desc;
1162         struct avf_asq_cmd_details details;
1163         enum avf_status_code status;
1164
1165         avf_fill_default_direct_cmd_desc(&desc, avf_aqc_opc_send_msg_to_pf);
1166         desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_SI);
1167         desc.cookie_high = CPU_TO_LE32(v_opcode);
1168         desc.cookie_low = CPU_TO_LE32(v_retval);
1169         if (msglen) {
1170                 desc.flags |= CPU_TO_LE16((u16)(AVF_AQ_FLAG_BUF
1171                                                 | AVF_AQ_FLAG_RD));
1172                 if (msglen > AVF_AQ_LARGE_BUF)
1173                         desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_LB);
1174                 desc.datalen = CPU_TO_LE16(msglen);
1175         }
1176         if (!cmd_details) {
1177                 avf_memset(&details, 0, sizeof(details), AVF_NONDMA_MEM);
1178                 details.async = true;
1179                 cmd_details = &details;
1180         }
1181         status = avf_asq_send_command(hw, (struct avf_aq_desc *)&desc, msg,
1182                                        msglen, cmd_details);
1183         return status;
1184 }
1185
1186 /**
1187  * avf_parse_hw_config
1188  * @hw: pointer to the hardware structure
1189  * @msg: pointer to the virtual channel VF resource structure
1190  *
1191  * Given a VF resource message from the PF, populate the hw struct
1192  * with appropriate information.
1193  **/
1194 void avf_parse_hw_config(struct avf_hw *hw,
1195                              struct virtchnl_vf_resource *msg)
1196 {
1197         struct virtchnl_vsi_resource *vsi_res;
1198         int i;
1199
1200         vsi_res = &msg->vsi_res[0];
1201
1202         hw->dev_caps.num_vsis = msg->num_vsis;
1203         hw->dev_caps.num_rx_qp = msg->num_queue_pairs;
1204         hw->dev_caps.num_tx_qp = msg->num_queue_pairs;
1205         hw->dev_caps.num_msix_vectors_vf = msg->max_vectors;
1206         hw->dev_caps.dcb = msg->vf_cap_flags &
1207                            VIRTCHNL_VF_OFFLOAD_L2;
1208         hw->dev_caps.iwarp = (msg->vf_cap_flags &
1209                               VIRTCHNL_VF_OFFLOAD_IWARP) ? 1 : 0;
1210         for (i = 0; i < msg->num_vsis; i++) {
1211                 if (vsi_res->vsi_type == VIRTCHNL_VSI_SRIOV) {
1212                         avf_memcpy(hw->mac.perm_addr,
1213                                     vsi_res->default_mac_addr,
1214                                     ETH_ALEN,
1215                                     AVF_NONDMA_TO_NONDMA);
1216                         avf_memcpy(hw->mac.addr, vsi_res->default_mac_addr,
1217                                     ETH_ALEN,
1218                                     AVF_NONDMA_TO_NONDMA);
1219                 }
1220                 vsi_res++;
1221         }
1222 }
1223
1224 /**
1225  * avf_reset
1226  * @hw: pointer to the hardware structure
1227  *
1228  * Send a VF_RESET message to the PF. Does not wait for response from PF
1229  * as none will be forthcoming. Immediately after calling this function,
1230  * the admin queue should be shut down and (optionally) reinitialized.
1231  **/
1232 enum avf_status_code avf_reset(struct avf_hw *hw)
1233 {
1234         return avf_aq_send_msg_to_pf(hw, VIRTCHNL_OP_RESET_VF,
1235                                       AVF_SUCCESS, NULL, 0, NULL);
1236 }
1237
1238 /**
1239  * avf_aq_set_arp_proxy_config
1240  * @hw: pointer to the HW structure
1241  * @proxy_config: pointer to proxy config command table struct
1242  * @cmd_details: pointer to command details
1243  *
1244  * Set ARP offload parameters from pre-populated
1245  * avf_aqc_arp_proxy_data struct
1246  **/
1247 enum avf_status_code avf_aq_set_arp_proxy_config(struct avf_hw *hw,
1248                                 struct avf_aqc_arp_proxy_data *proxy_config,
1249                                 struct avf_asq_cmd_details *cmd_details)
1250 {
1251         struct avf_aq_desc desc;
1252         enum avf_status_code status;
1253
1254         if (!proxy_config)
1255                 return AVF_ERR_PARAM;
1256
1257         avf_fill_default_direct_cmd_desc(&desc, avf_aqc_opc_set_proxy_config);
1258
1259         desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_BUF);
1260         desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_RD);
1261         desc.params.external.addr_high =
1262                                   CPU_TO_LE32(AVF_HI_DWORD((u64)proxy_config));
1263         desc.params.external.addr_low =
1264                                   CPU_TO_LE32(AVF_LO_DWORD((u64)proxy_config));
1265         desc.datalen = CPU_TO_LE16(sizeof(struct avf_aqc_arp_proxy_data));
1266
1267         status = avf_asq_send_command(hw, &desc, proxy_config,
1268                                        sizeof(struct avf_aqc_arp_proxy_data),
1269                                        cmd_details);
1270
1271         return status;
1272 }
1273
1274 /**
1275  * avf_aq_opc_set_ns_proxy_table_entry
1276  * @hw: pointer to the HW structure
1277  * @ns_proxy_table_entry: pointer to NS table entry command struct
1278  * @cmd_details: pointer to command details
1279  *
1280  * Set IPv6 Neighbor Solicitation (NS) protocol offload parameters
1281  * from pre-populated avf_aqc_ns_proxy_data struct
1282  **/
1283 enum avf_status_code avf_aq_set_ns_proxy_table_entry(struct avf_hw *hw,
1284                         struct avf_aqc_ns_proxy_data *ns_proxy_table_entry,
1285                         struct avf_asq_cmd_details *cmd_details)
1286 {
1287         struct avf_aq_desc desc;
1288         enum avf_status_code status;
1289
1290         if (!ns_proxy_table_entry)
1291                 return AVF_ERR_PARAM;
1292
1293         avf_fill_default_direct_cmd_desc(&desc,
1294                                 avf_aqc_opc_set_ns_proxy_table_entry);
1295
1296         desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_BUF);
1297         desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_RD);
1298         desc.params.external.addr_high =
1299                 CPU_TO_LE32(AVF_HI_DWORD((u64)ns_proxy_table_entry));
1300         desc.params.external.addr_low =
1301                 CPU_TO_LE32(AVF_LO_DWORD((u64)ns_proxy_table_entry));
1302         desc.datalen = CPU_TO_LE16(sizeof(struct avf_aqc_ns_proxy_data));
1303
1304         status = avf_asq_send_command(hw, &desc, ns_proxy_table_entry,
1305                                        sizeof(struct avf_aqc_ns_proxy_data),
1306                                        cmd_details);
1307
1308         return status;
1309 }
1310
1311 /**
1312  * avf_aq_set_clear_wol_filter
1313  * @hw: pointer to the hw struct
1314  * @filter_index: index of filter to modify (0-7)
1315  * @filter: buffer containing filter to be set
1316  * @set_filter: true to set filter, false to clear filter
1317  * @no_wol_tco: if true, pass through packets cannot cause wake-up
1318  *              if false, pass through packets may cause wake-up
1319  * @filter_valid: true if filter action is valid
1320  * @no_wol_tco_valid: true if no WoL in TCO traffic action valid
1321  * @cmd_details: pointer to command details structure or NULL
1322  *
1323  * Set or clear WoL filter for port attached to the PF
1324  **/
1325 enum avf_status_code avf_aq_set_clear_wol_filter(struct avf_hw *hw,
1326                                 u8 filter_index,
1327                                 struct avf_aqc_set_wol_filter_data *filter,
1328                                 bool set_filter, bool no_wol_tco,
1329                                 bool filter_valid, bool no_wol_tco_valid,
1330                                 struct avf_asq_cmd_details *cmd_details)
1331 {
1332         struct avf_aq_desc desc;
1333         struct avf_aqc_set_wol_filter *cmd =
1334                 (struct avf_aqc_set_wol_filter *)&desc.params.raw;
1335         enum avf_status_code status;
1336         u16 cmd_flags = 0;
1337         u16 valid_flags = 0;
1338         u16 buff_len = 0;
1339
1340         avf_fill_default_direct_cmd_desc(&desc, avf_aqc_opc_set_wol_filter);
1341
1342         if (filter_index >= AVF_AQC_MAX_NUM_WOL_FILTERS)
1343                 return  AVF_ERR_PARAM;
1344         cmd->filter_index = CPU_TO_LE16(filter_index);
1345
1346         if (set_filter) {
1347                 if (!filter)
1348                         return  AVF_ERR_PARAM;
1349
1350                 cmd_flags |= AVF_AQC_SET_WOL_FILTER;
1351                 cmd_flags |= AVF_AQC_SET_WOL_FILTER_WOL_PRESERVE_ON_PFR;
1352         }
1353
1354         if (no_wol_tco)
1355                 cmd_flags |= AVF_AQC_SET_WOL_FILTER_NO_TCO_WOL;
1356         cmd->cmd_flags = CPU_TO_LE16(cmd_flags);
1357
1358         if (filter_valid)
1359                 valid_flags |= AVF_AQC_SET_WOL_FILTER_ACTION_VALID;
1360         if (no_wol_tco_valid)
1361                 valid_flags |= AVF_AQC_SET_WOL_FILTER_NO_TCO_ACTION_VALID;
1362         cmd->valid_flags = CPU_TO_LE16(valid_flags);
1363
1364         buff_len = sizeof(*filter);
1365         desc.datalen = CPU_TO_LE16(buff_len);
1366
1367         desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_BUF);
1368         desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_RD);
1369
1370         cmd->address_high = CPU_TO_LE32(AVF_HI_DWORD((u64)filter));
1371         cmd->address_low = CPU_TO_LE32(AVF_LO_DWORD((u64)filter));
1372
1373         status = avf_asq_send_command(hw, &desc, filter,
1374                                        buff_len, cmd_details);
1375
1376         return status;
1377 }
1378
1379 /**
1380  * avf_aq_get_wake_event_reason
1381  * @hw: pointer to the hw struct
1382  * @wake_reason: return value, index of matching filter
1383  * @cmd_details: pointer to command details structure or NULL
1384  *
1385  * Get information for the reason of a Wake Up event
1386  **/
1387 enum avf_status_code avf_aq_get_wake_event_reason(struct avf_hw *hw,
1388                                 u16 *wake_reason,
1389                                 struct avf_asq_cmd_details *cmd_details)
1390 {
1391         struct avf_aq_desc desc;
1392         struct avf_aqc_get_wake_reason_completion *resp =
1393                 (struct avf_aqc_get_wake_reason_completion *)&desc.params.raw;
1394         enum avf_status_code status;
1395
1396         avf_fill_default_direct_cmd_desc(&desc, avf_aqc_opc_get_wake_reason);
1397
1398         status = avf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1399
1400         if (status == AVF_SUCCESS)
1401                 *wake_reason = LE16_TO_CPU(resp->wake_reason);
1402
1403         return status;
1404 }
1405
1406 /**
1407 * avf_aq_clear_all_wol_filters
1408 * @hw: pointer to the hw struct
1409 * @cmd_details: pointer to command details structure or NULL
1410 *
1411 * Get information for the reason of a Wake Up event
1412 **/
1413 enum avf_status_code avf_aq_clear_all_wol_filters(struct avf_hw *hw,
1414         struct avf_asq_cmd_details *cmd_details)
1415 {
1416         struct avf_aq_desc desc;
1417         enum avf_status_code status;
1418
1419         avf_fill_default_direct_cmd_desc(&desc,
1420                                           avf_aqc_opc_clear_all_wol_filters);
1421
1422         status = avf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1423
1424         return status;
1425 }
1426
1427 /**
1428  * avf_aq_write_ddp - Write dynamic device personalization (ddp)
1429  * @hw: pointer to the hw struct
1430  * @buff: command buffer (size in bytes = buff_size)
1431  * @buff_size: buffer size in bytes
1432  * @track_id: package tracking id
1433  * @error_offset: returns error offset
1434  * @error_info: returns error information
1435  * @cmd_details: pointer to command details structure or NULL
1436  **/
1437 enum
1438 avf_status_code avf_aq_write_ddp(struct avf_hw *hw, void *buff,
1439                                    u16 buff_size, u32 track_id,
1440                                    u32 *error_offset, u32 *error_info,
1441                                    struct avf_asq_cmd_details *cmd_details)
1442 {
1443         struct avf_aq_desc desc;
1444         struct avf_aqc_write_personalization_profile *cmd =
1445                 (struct avf_aqc_write_personalization_profile *)
1446                 &desc.params.raw;
1447         struct avf_aqc_write_ddp_resp *resp;
1448         enum avf_status_code status;
1449
1450         avf_fill_default_direct_cmd_desc(&desc,
1451                                   avf_aqc_opc_write_personalization_profile);
1452
1453         desc.flags |= CPU_TO_LE16(AVF_AQ_FLAG_BUF | AVF_AQ_FLAG_RD);
1454         if (buff_size > AVF_AQ_LARGE_BUF)
1455                 desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_LB);
1456
1457         desc.datalen = CPU_TO_LE16(buff_size);
1458
1459         cmd->profile_track_id = CPU_TO_LE32(track_id);
1460
1461         status = avf_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
1462         if (!status) {
1463                 resp = (struct avf_aqc_write_ddp_resp *)&desc.params.raw;
1464                 if (error_offset)
1465                         *error_offset = LE32_TO_CPU(resp->error_offset);
1466                 if (error_info)
1467                         *error_info = LE32_TO_CPU(resp->error_info);
1468         }
1469
1470         return status;
1471 }
1472
1473 /**
1474  * avf_aq_get_ddp_list - Read dynamic device personalization (ddp)
1475  * @hw: pointer to the hw struct
1476  * @buff: command buffer (size in bytes = buff_size)
1477  * @buff_size: buffer size in bytes
1478  * @flags: AdminQ command flags
1479  * @cmd_details: pointer to command details structure or NULL
1480  **/
1481 enum
1482 avf_status_code avf_aq_get_ddp_list(struct avf_hw *hw, void *buff,
1483                                       u16 buff_size, u8 flags,
1484                                       struct avf_asq_cmd_details *cmd_details)
1485 {
1486         struct avf_aq_desc desc;
1487         struct avf_aqc_get_applied_profiles *cmd =
1488                 (struct avf_aqc_get_applied_profiles *)&desc.params.raw;
1489         enum avf_status_code status;
1490
1491         avf_fill_default_direct_cmd_desc(&desc,
1492                           avf_aqc_opc_get_personalization_profile_list);
1493
1494         desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_BUF);
1495         if (buff_size > AVF_AQ_LARGE_BUF)
1496                 desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_LB);
1497         desc.datalen = CPU_TO_LE16(buff_size);
1498
1499         cmd->flags = flags;
1500
1501         status = avf_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
1502
1503         return status;
1504 }
1505
1506 /**
1507  * avf_find_segment_in_package
1508  * @segment_type: the segment type to search for (i.e., SEGMENT_TYPE_AVF)
1509  * @pkg_hdr: pointer to the package header to be searched
1510  *
1511  * This function searches a package file for a particular segment type. On
1512  * success it returns a pointer to the segment header, otherwise it will
1513  * return NULL.
1514  **/
1515 struct avf_generic_seg_header *
1516 avf_find_segment_in_package(u32 segment_type,
1517                              struct avf_package_header *pkg_hdr)
1518 {
1519         struct avf_generic_seg_header *segment;
1520         u32 i;
1521
1522         /* Search all package segments for the requested segment type */
1523         for (i = 0; i < pkg_hdr->segment_count; i++) {
1524                 segment =
1525                         (struct avf_generic_seg_header *)((u8 *)pkg_hdr +
1526                          pkg_hdr->segment_offset[i]);
1527
1528                 if (segment->type == segment_type)
1529                         return segment;
1530         }
1531
1532         return NULL;
1533 }
1534
1535 /* Get section table in profile */
1536 #define AVF_SECTION_TABLE(profile, sec_tbl)                             \
1537         do {                                                            \
1538                 struct avf_profile_segment *p = (profile);              \
1539                 u32 count;                                              \
1540                 u32 *nvm;                                               \
1541                 count = p->device_table_count;                          \
1542                 nvm = (u32 *)&p->device_table[count];                   \
1543                 sec_tbl = (struct avf_section_table *)&nvm[nvm[0] + 1]; \
1544         } while (0)
1545
1546 /* Get section header in profile */
1547 #define AVF_SECTION_HEADER(profile, offset)                             \
1548         (struct avf_profile_section_header *)((u8 *)(profile) + (offset))
1549
1550 /**
1551  * avf_find_section_in_profile
1552  * @section_type: the section type to search for (i.e., SECTION_TYPE_NOTE)
1553  * @profile: pointer to the avf segment header to be searched
1554  *
1555  * This function searches avf segment for a particular section type. On
1556  * success it returns a pointer to the section header, otherwise it will
1557  * return NULL.
1558  **/
1559 struct avf_profile_section_header *
1560 avf_find_section_in_profile(u32 section_type,
1561                              struct avf_profile_segment *profile)
1562 {
1563         struct avf_profile_section_header *sec;
1564         struct avf_section_table *sec_tbl;
1565         u32 sec_off;
1566         u32 i;
1567
1568         if (profile->header.type != SEGMENT_TYPE_AVF)
1569                 return NULL;
1570
1571         AVF_SECTION_TABLE(profile, sec_tbl);
1572
1573         for (i = 0; i < sec_tbl->section_count; i++) {
1574                 sec_off = sec_tbl->section_offset[i];
1575                 sec = AVF_SECTION_HEADER(profile, sec_off);
1576                 if (sec->section.type == section_type)
1577                         return sec;
1578         }
1579
1580         return NULL;
1581 }
1582
1583 /**
1584  * avf_ddp_exec_aq_section - Execute generic AQ for DDP
1585  * @hw: pointer to the hw struct
1586  * @aq: command buffer containing all data to execute AQ
1587  **/
1588 STATIC enum
1589 avf_status_code avf_ddp_exec_aq_section(struct avf_hw *hw,
1590                                           struct avf_profile_aq_section *aq)
1591 {
1592         enum avf_status_code status;
1593         struct avf_aq_desc desc;
1594         u8 *msg = NULL;
1595         u16 msglen;
1596
1597         avf_fill_default_direct_cmd_desc(&desc, aq->opcode);
1598         desc.flags |= CPU_TO_LE16(aq->flags);
1599         avf_memcpy(desc.params.raw, aq->param, sizeof(desc.params.raw),
1600                     AVF_NONDMA_TO_NONDMA);
1601
1602         msglen = aq->datalen;
1603         if (msglen) {
1604                 desc.flags |= CPU_TO_LE16((u16)(AVF_AQ_FLAG_BUF |
1605                                                 AVF_AQ_FLAG_RD));
1606                 if (msglen > AVF_AQ_LARGE_BUF)
1607                         desc.flags |= CPU_TO_LE16((u16)AVF_AQ_FLAG_LB);
1608                 desc.datalen = CPU_TO_LE16(msglen);
1609                 msg = &aq->data[0];
1610         }
1611
1612         status = avf_asq_send_command(hw, &desc, msg, msglen, NULL);
1613
1614         if (status != AVF_SUCCESS) {
1615                 avf_debug(hw, AVF_DEBUG_PACKAGE,
1616                            "unable to exec DDP AQ opcode %u, error %d\n",
1617                            aq->opcode, status);
1618                 return status;
1619         }
1620
1621         /* copy returned desc to aq_buf */
1622         avf_memcpy(aq->param, desc.params.raw, sizeof(desc.params.raw),
1623                     AVF_NONDMA_TO_NONDMA);
1624
1625         return AVF_SUCCESS;
1626 }
1627
1628 /**
1629  * avf_validate_profile
1630  * @hw: pointer to the hardware structure
1631  * @profile: pointer to the profile segment of the package to be validated
1632  * @track_id: package tracking id
1633  * @rollback: flag if the profile is for rollback.
1634  *
1635  * Validates supported devices and profile's sections.
1636  */
1637 STATIC enum avf_status_code
1638 avf_validate_profile(struct avf_hw *hw, struct avf_profile_segment *profile,
1639                       u32 track_id, bool rollback)
1640 {
1641         struct avf_profile_section_header *sec = NULL;
1642         enum avf_status_code status = AVF_SUCCESS;
1643         struct avf_section_table *sec_tbl;
1644         u32 vendor_dev_id;
1645         u32 dev_cnt;
1646         u32 sec_off;
1647         u32 i;
1648
1649         if (track_id == AVF_DDP_TRACKID_INVALID) {
1650                 avf_debug(hw, AVF_DEBUG_PACKAGE, "Invalid track_id\n");
1651                 return AVF_NOT_SUPPORTED;
1652         }
1653
1654         dev_cnt = profile->device_table_count;
1655         for (i = 0; i < dev_cnt; i++) {
1656                 vendor_dev_id = profile->device_table[i].vendor_dev_id;
1657                 if ((vendor_dev_id >> 16) == AVF_INTEL_VENDOR_ID &&
1658                     hw->device_id == (vendor_dev_id & 0xFFFF))
1659                         break;
1660         }
1661         if (dev_cnt && (i == dev_cnt)) {
1662                 avf_debug(hw, AVF_DEBUG_PACKAGE,
1663                            "Device doesn't support DDP\n");
1664                 return AVF_ERR_DEVICE_NOT_SUPPORTED;
1665         }
1666
1667         AVF_SECTION_TABLE(profile, sec_tbl);
1668
1669         /* Validate sections types */
1670         for (i = 0; i < sec_tbl->section_count; i++) {
1671                 sec_off = sec_tbl->section_offset[i];
1672                 sec = AVF_SECTION_HEADER(profile, sec_off);
1673                 if (rollback) {
1674                         if (sec->section.type == SECTION_TYPE_MMIO ||
1675                             sec->section.type == SECTION_TYPE_AQ ||
1676                             sec->section.type == SECTION_TYPE_RB_AQ) {
1677                                 avf_debug(hw, AVF_DEBUG_PACKAGE,
1678                                            "Not a roll-back package\n");
1679                                 return AVF_NOT_SUPPORTED;
1680                         }
1681                 } else {
1682                         if (sec->section.type == SECTION_TYPE_RB_AQ ||
1683                             sec->section.type == SECTION_TYPE_RB_MMIO) {
1684                                 avf_debug(hw, AVF_DEBUG_PACKAGE,
1685                                            "Not an original package\n");
1686                                 return AVF_NOT_SUPPORTED;
1687                         }
1688                 }
1689         }
1690
1691         return status;
1692 }
1693
1694 /**
1695  * avf_write_profile
1696  * @hw: pointer to the hardware structure
1697  * @profile: pointer to the profile segment of the package to be downloaded
1698  * @track_id: package tracking id
1699  *
1700  * Handles the download of a complete package.
1701  */
1702 enum avf_status_code
1703 avf_write_profile(struct avf_hw *hw, struct avf_profile_segment *profile,
1704                    u32 track_id)
1705 {
1706         enum avf_status_code status = AVF_SUCCESS;
1707         struct avf_section_table *sec_tbl;
1708         struct avf_profile_section_header *sec = NULL;
1709         struct avf_profile_aq_section *ddp_aq;
1710         u32 section_size = 0;
1711         u32 offset = 0, info = 0;
1712         u32 sec_off;
1713         u32 i;
1714
1715         status = avf_validate_profile(hw, profile, track_id, false);
1716         if (status)
1717                 return status;
1718
1719         AVF_SECTION_TABLE(profile, sec_tbl);
1720
1721         for (i = 0; i < sec_tbl->section_count; i++) {
1722                 sec_off = sec_tbl->section_offset[i];
1723                 sec = AVF_SECTION_HEADER(profile, sec_off);
1724                 /* Process generic admin command */
1725                 if (sec->section.type == SECTION_TYPE_AQ) {
1726                         ddp_aq = (struct avf_profile_aq_section *)&sec[1];
1727                         status = avf_ddp_exec_aq_section(hw, ddp_aq);
1728                         if (status) {
1729                                 avf_debug(hw, AVF_DEBUG_PACKAGE,
1730                                            "Failed to execute aq: section %d, opcode %u\n",
1731                                            i, ddp_aq->opcode);
1732                                 break;
1733                         }
1734                         sec->section.type = SECTION_TYPE_RB_AQ;
1735                 }
1736
1737                 /* Skip any non-mmio sections */
1738                 if (sec->section.type != SECTION_TYPE_MMIO)
1739                         continue;
1740
1741                 section_size = sec->section.size +
1742                         sizeof(struct avf_profile_section_header);
1743
1744                 /* Write MMIO section */
1745                 status = avf_aq_write_ddp(hw, (void *)sec, (u16)section_size,
1746                                            track_id, &offset, &info, NULL);
1747                 if (status) {
1748                         avf_debug(hw, AVF_DEBUG_PACKAGE,
1749                                    "Failed to write profile: section %d, offset %d, info %d\n",
1750                                    i, offset, info);
1751                         break;
1752                 }
1753         }
1754         return status;
1755 }
1756
1757 /**
1758  * avf_rollback_profile
1759  * @hw: pointer to the hardware structure
1760  * @profile: pointer to the profile segment of the package to be removed
1761  * @track_id: package tracking id
1762  *
1763  * Rolls back previously loaded package.
1764  */
1765 enum avf_status_code
1766 avf_rollback_profile(struct avf_hw *hw, struct avf_profile_segment *profile,
1767                       u32 track_id)
1768 {
1769         struct avf_profile_section_header *sec = NULL;
1770         enum avf_status_code status = AVF_SUCCESS;
1771         struct avf_section_table *sec_tbl;
1772         u32 offset = 0, info = 0;
1773         u32 section_size = 0;
1774         u32 sec_off;
1775         int i;
1776
1777         status = avf_validate_profile(hw, profile, track_id, true);
1778         if (status)
1779                 return status;
1780
1781         AVF_SECTION_TABLE(profile, sec_tbl);
1782
1783         /* For rollback write sections in reverse */
1784         for (i = sec_tbl->section_count - 1; i >= 0; i--) {
1785                 sec_off = sec_tbl->section_offset[i];
1786                 sec = AVF_SECTION_HEADER(profile, sec_off);
1787
1788                 /* Skip any non-rollback sections */
1789                 if (sec->section.type != SECTION_TYPE_RB_MMIO)
1790                         continue;
1791
1792                 section_size = sec->section.size +
1793                         sizeof(struct avf_profile_section_header);
1794
1795                 /* Write roll-back MMIO section */
1796                 status = avf_aq_write_ddp(hw, (void *)sec, (u16)section_size,
1797                                            track_id, &offset, &info, NULL);
1798                 if (status) {
1799                         avf_debug(hw, AVF_DEBUG_PACKAGE,
1800                                    "Failed to write profile: section %d, offset %d, info %d\n",
1801                                    i, offset, info);
1802                         break;
1803                 }
1804         }
1805         return status;
1806 }
1807
1808 /**
1809  * avf_add_pinfo_to_list
1810  * @hw: pointer to the hardware structure
1811  * @profile: pointer to the profile segment of the package
1812  * @profile_info_sec: buffer for information section
1813  * @track_id: package tracking id
1814  *
1815  * Register a profile to the list of loaded profiles.
1816  */
1817 enum avf_status_code
1818 avf_add_pinfo_to_list(struct avf_hw *hw,
1819                        struct avf_profile_segment *profile,
1820                        u8 *profile_info_sec, u32 track_id)
1821 {
1822         enum avf_status_code status = AVF_SUCCESS;
1823         struct avf_profile_section_header *sec = NULL;
1824         struct avf_profile_info *pinfo;
1825         u32 offset = 0, info = 0;
1826
1827         sec = (struct avf_profile_section_header *)profile_info_sec;
1828         sec->tbl_size = 1;
1829         sec->data_end = sizeof(struct avf_profile_section_header) +
1830                         sizeof(struct avf_profile_info);
1831         sec->section.type = SECTION_TYPE_INFO;
1832         sec->section.offset = sizeof(struct avf_profile_section_header);
1833         sec->section.size = sizeof(struct avf_profile_info);
1834         pinfo = (struct avf_profile_info *)(profile_info_sec +
1835                                              sec->section.offset);
1836         pinfo->track_id = track_id;
1837         pinfo->version = profile->version;
1838         pinfo->op = AVF_DDP_ADD_TRACKID;
1839         avf_memcpy(pinfo->name, profile->name, AVF_DDP_NAME_SIZE,
1840                     AVF_NONDMA_TO_NONDMA);
1841
1842         status = avf_aq_write_ddp(hw, (void *)sec, sec->data_end,
1843                                    track_id, &offset, &info, NULL);
1844         return status;
1845 }