xref: /freebsd/sys/dev/iavf/iavf_common.c (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2021, Intel Corporation
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above copyright notice,
9  *      this list of conditions and the following disclaimer.
10  *
11  *   2. Redistributions in binary form must reproduce the above copyright
12  *      notice, this list of conditions and the following disclaimer in the
13  *      documentation and/or other materials provided with the distribution.
14  *
15  *   3. Neither the name of the Intel Corporation nor the names of its
16  *      contributors may be used to endorse or promote products derived from
17  *      this software without specific prior written permission.
18  *
19  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *  POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "iavf_type.h"
33 #include "iavf_adminq.h"
34 #include "iavf_prototype.h"
35 #include "virtchnl.h"
36 
37 /**
38  * iavf_set_mac_type - Sets MAC type
39  * @hw: pointer to the HW structure
40  *
41  * This function sets the mac type of the adapter based on the
42  * vendor ID and device ID stored in the hw structure.
43  **/
iavf_set_mac_type(struct iavf_hw * hw)44 enum iavf_status iavf_set_mac_type(struct iavf_hw *hw)
45 {
46 	enum iavf_status status = IAVF_SUCCESS;
47 
48 	DEBUGFUNC("iavf_set_mac_type\n");
49 
50 	if (hw->vendor_id == IAVF_INTEL_VENDOR_ID) {
51 		switch (hw->device_id) {
52 		case IAVF_DEV_ID_X722_VF:
53 			hw->mac.type = IAVF_MAC_X722_VF;
54 			break;
55 		case IAVF_DEV_ID_VF:
56 		case IAVF_DEV_ID_VF_HV:
57 		case IAVF_DEV_ID_ADAPTIVE_VF:
58 			hw->mac.type = IAVF_MAC_VF;
59 			break;
60 		default:
61 			hw->mac.type = IAVF_MAC_GENERIC;
62 			break;
63 		}
64 	} else {
65 		status = IAVF_ERR_DEVICE_NOT_SUPPORTED;
66 	}
67 
68 	DEBUGOUT2("iavf_set_mac_type found mac: %d, returns: %d\n",
69 		  hw->mac.type, status);
70 	return status;
71 }
72 
73 /**
74  * iavf_aq_str - convert AQ err code to a string
75  * @hw: pointer to the HW structure
76  * @aq_err: the AQ error code to convert
77  **/
iavf_aq_str(struct iavf_hw * hw,enum iavf_admin_queue_err aq_err)78 const char *iavf_aq_str(struct iavf_hw *hw, enum iavf_admin_queue_err aq_err)
79 {
80 	switch (aq_err) {
81 	case IAVF_AQ_RC_OK:
82 		return "OK";
83 	case IAVF_AQ_RC_EPERM:
84 		return "IAVF_AQ_RC_EPERM";
85 	case IAVF_AQ_RC_ENOENT:
86 		return "IAVF_AQ_RC_ENOENT";
87 	case IAVF_AQ_RC_ESRCH:
88 		return "IAVF_AQ_RC_ESRCH";
89 	case IAVF_AQ_RC_EINTR:
90 		return "IAVF_AQ_RC_EINTR";
91 	case IAVF_AQ_RC_EIO:
92 		return "IAVF_AQ_RC_EIO";
93 	case IAVF_AQ_RC_ENXIO:
94 		return "IAVF_AQ_RC_ENXIO";
95 	case IAVF_AQ_RC_E2BIG:
96 		return "IAVF_AQ_RC_E2BIG";
97 	case IAVF_AQ_RC_EAGAIN:
98 		return "IAVF_AQ_RC_EAGAIN";
99 	case IAVF_AQ_RC_ENOMEM:
100 		return "IAVF_AQ_RC_ENOMEM";
101 	case IAVF_AQ_RC_EACCES:
102 		return "IAVF_AQ_RC_EACCES";
103 	case IAVF_AQ_RC_EFAULT:
104 		return "IAVF_AQ_RC_EFAULT";
105 	case IAVF_AQ_RC_EBUSY:
106 		return "IAVF_AQ_RC_EBUSY";
107 	case IAVF_AQ_RC_EEXIST:
108 		return "IAVF_AQ_RC_EEXIST";
109 	case IAVF_AQ_RC_EINVAL:
110 		return "IAVF_AQ_RC_EINVAL";
111 	case IAVF_AQ_RC_ENOTTY:
112 		return "IAVF_AQ_RC_ENOTTY";
113 	case IAVF_AQ_RC_ENOSPC:
114 		return "IAVF_AQ_RC_ENOSPC";
115 	case IAVF_AQ_RC_ENOSYS:
116 		return "IAVF_AQ_RC_ENOSYS";
117 	case IAVF_AQ_RC_ERANGE:
118 		return "IAVF_AQ_RC_ERANGE";
119 	case IAVF_AQ_RC_EFLUSHED:
120 		return "IAVF_AQ_RC_EFLUSHED";
121 	case IAVF_AQ_RC_BAD_ADDR:
122 		return "IAVF_AQ_RC_BAD_ADDR";
123 	case IAVF_AQ_RC_EMODE:
124 		return "IAVF_AQ_RC_EMODE";
125 	case IAVF_AQ_RC_EFBIG:
126 		return "IAVF_AQ_RC_EFBIG";
127 	}
128 
129 	snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
130 	return hw->err_str;
131 }
132 
133 /**
134  * iavf_stat_str - convert status err code to a string
135  * @hw: pointer to the HW structure
136  * @stat_err: the status error code to convert
137  **/
iavf_stat_str(struct iavf_hw * hw,enum iavf_status stat_err)138 const char *iavf_stat_str(struct iavf_hw *hw, enum iavf_status stat_err)
139 {
140 	switch (stat_err) {
141 	case IAVF_SUCCESS:
142 		return "OK";
143 	case IAVF_ERR_NVM:
144 		return "IAVF_ERR_NVM";
145 	case IAVF_ERR_NVM_CHECKSUM:
146 		return "IAVF_ERR_NVM_CHECKSUM";
147 	case IAVF_ERR_PHY:
148 		return "IAVF_ERR_PHY";
149 	case IAVF_ERR_CONFIG:
150 		return "IAVF_ERR_CONFIG";
151 	case IAVF_ERR_PARAM:
152 		return "IAVF_ERR_PARAM";
153 	case IAVF_ERR_MAC_TYPE:
154 		return "IAVF_ERR_MAC_TYPE";
155 	case IAVF_ERR_UNKNOWN_PHY:
156 		return "IAVF_ERR_UNKNOWN_PHY";
157 	case IAVF_ERR_LINK_SETUP:
158 		return "IAVF_ERR_LINK_SETUP";
159 	case IAVF_ERR_ADAPTER_STOPPED:
160 		return "IAVF_ERR_ADAPTER_STOPPED";
161 	case IAVF_ERR_INVALID_MAC_ADDR:
162 		return "IAVF_ERR_INVALID_MAC_ADDR";
163 	case IAVF_ERR_DEVICE_NOT_SUPPORTED:
164 		return "IAVF_ERR_DEVICE_NOT_SUPPORTED";
165 	case IAVF_ERR_MASTER_REQUESTS_PENDING:
166 		return "IAVF_ERR_MASTER_REQUESTS_PENDING";
167 	case IAVF_ERR_INVALID_LINK_SETTINGS:
168 		return "IAVF_ERR_INVALID_LINK_SETTINGS";
169 	case IAVF_ERR_AUTONEG_NOT_COMPLETE:
170 		return "IAVF_ERR_AUTONEG_NOT_COMPLETE";
171 	case IAVF_ERR_RESET_FAILED:
172 		return "IAVF_ERR_RESET_FAILED";
173 	case IAVF_ERR_SWFW_SYNC:
174 		return "IAVF_ERR_SWFW_SYNC";
175 	case IAVF_ERR_NO_AVAILABLE_VSI:
176 		return "IAVF_ERR_NO_AVAILABLE_VSI";
177 	case IAVF_ERR_NO_MEMORY:
178 		return "IAVF_ERR_NO_MEMORY";
179 	case IAVF_ERR_BAD_PTR:
180 		return "IAVF_ERR_BAD_PTR";
181 	case IAVF_ERR_RING_FULL:
182 		return "IAVF_ERR_RING_FULL";
183 	case IAVF_ERR_INVALID_PD_ID:
184 		return "IAVF_ERR_INVALID_PD_ID";
185 	case IAVF_ERR_INVALID_QP_ID:
186 		return "IAVF_ERR_INVALID_QP_ID";
187 	case IAVF_ERR_INVALID_CQ_ID:
188 		return "IAVF_ERR_INVALID_CQ_ID";
189 	case IAVF_ERR_INVALID_CEQ_ID:
190 		return "IAVF_ERR_INVALID_CEQ_ID";
191 	case IAVF_ERR_INVALID_AEQ_ID:
192 		return "IAVF_ERR_INVALID_AEQ_ID";
193 	case IAVF_ERR_INVALID_SIZE:
194 		return "IAVF_ERR_INVALID_SIZE";
195 	case IAVF_ERR_INVALID_ARP_INDEX:
196 		return "IAVF_ERR_INVALID_ARP_INDEX";
197 	case IAVF_ERR_INVALID_FPM_FUNC_ID:
198 		return "IAVF_ERR_INVALID_FPM_FUNC_ID";
199 	case IAVF_ERR_QP_INVALID_MSG_SIZE:
200 		return "IAVF_ERR_QP_INVALID_MSG_SIZE";
201 	case IAVF_ERR_QP_TOOMANY_WRS_POSTED:
202 		return "IAVF_ERR_QP_TOOMANY_WRS_POSTED";
203 	case IAVF_ERR_INVALID_FRAG_COUNT:
204 		return "IAVF_ERR_INVALID_FRAG_COUNT";
205 	case IAVF_ERR_QUEUE_EMPTY:
206 		return "IAVF_ERR_QUEUE_EMPTY";
207 	case IAVF_ERR_INVALID_ALIGNMENT:
208 		return "IAVF_ERR_INVALID_ALIGNMENT";
209 	case IAVF_ERR_FLUSHED_QUEUE:
210 		return "IAVF_ERR_FLUSHED_QUEUE";
211 	case IAVF_ERR_INVALID_PUSH_PAGE_INDEX:
212 		return "IAVF_ERR_INVALID_PUSH_PAGE_INDEX";
213 	case IAVF_ERR_INVALID_IMM_DATA_SIZE:
214 		return "IAVF_ERR_INVALID_IMM_DATA_SIZE";
215 	case IAVF_ERR_TIMEOUT:
216 		return "IAVF_ERR_TIMEOUT";
217 	case IAVF_ERR_OPCODE_MISMATCH:
218 		return "IAVF_ERR_OPCODE_MISMATCH";
219 	case IAVF_ERR_CQP_COMPL_ERROR:
220 		return "IAVF_ERR_CQP_COMPL_ERROR";
221 	case IAVF_ERR_INVALID_VF_ID:
222 		return "IAVF_ERR_INVALID_VF_ID";
223 	case IAVF_ERR_INVALID_HMCFN_ID:
224 		return "IAVF_ERR_INVALID_HMCFN_ID";
225 	case IAVF_ERR_BACKING_PAGE_ERROR:
226 		return "IAVF_ERR_BACKING_PAGE_ERROR";
227 	case IAVF_ERR_NO_PBLCHUNKS_AVAILABLE:
228 		return "IAVF_ERR_NO_PBLCHUNKS_AVAILABLE";
229 	case IAVF_ERR_INVALID_PBLE_INDEX:
230 		return "IAVF_ERR_INVALID_PBLE_INDEX";
231 	case IAVF_ERR_INVALID_SD_INDEX:
232 		return "IAVF_ERR_INVALID_SD_INDEX";
233 	case IAVF_ERR_INVALID_PAGE_DESC_INDEX:
234 		return "IAVF_ERR_INVALID_PAGE_DESC_INDEX";
235 	case IAVF_ERR_INVALID_SD_TYPE:
236 		return "IAVF_ERR_INVALID_SD_TYPE";
237 	case IAVF_ERR_MEMCPY_FAILED:
238 		return "IAVF_ERR_MEMCPY_FAILED";
239 	case IAVF_ERR_INVALID_HMC_OBJ_INDEX:
240 		return "IAVF_ERR_INVALID_HMC_OBJ_INDEX";
241 	case IAVF_ERR_INVALID_HMC_OBJ_COUNT:
242 		return "IAVF_ERR_INVALID_HMC_OBJ_COUNT";
243 	case IAVF_ERR_INVALID_SRQ_ARM_LIMIT:
244 		return "IAVF_ERR_INVALID_SRQ_ARM_LIMIT";
245 	case IAVF_ERR_SRQ_ENABLED:
246 		return "IAVF_ERR_SRQ_ENABLED";
247 	case IAVF_ERR_ADMIN_QUEUE_ERROR:
248 		return "IAVF_ERR_ADMIN_QUEUE_ERROR";
249 	case IAVF_ERR_ADMIN_QUEUE_TIMEOUT:
250 		return "IAVF_ERR_ADMIN_QUEUE_TIMEOUT";
251 	case IAVF_ERR_BUF_TOO_SHORT:
252 		return "IAVF_ERR_BUF_TOO_SHORT";
253 	case IAVF_ERR_ADMIN_QUEUE_FULL:
254 		return "IAVF_ERR_ADMIN_QUEUE_FULL";
255 	case IAVF_ERR_ADMIN_QUEUE_NO_WORK:
256 		return "IAVF_ERR_ADMIN_QUEUE_NO_WORK";
257 	case IAVF_ERR_BAD_IWARP_CQE:
258 		return "IAVF_ERR_BAD_IWARP_CQE";
259 	case IAVF_ERR_NVM_BLANK_MODE:
260 		return "IAVF_ERR_NVM_BLANK_MODE";
261 	case IAVF_ERR_NOT_IMPLEMENTED:
262 		return "IAVF_ERR_NOT_IMPLEMENTED";
263 	case IAVF_ERR_PE_DOORBELL_NOT_ENABLED:
264 		return "IAVF_ERR_PE_DOORBELL_NOT_ENABLED";
265 	case IAVF_ERR_DIAG_TEST_FAILED:
266 		return "IAVF_ERR_DIAG_TEST_FAILED";
267 	case IAVF_ERR_NOT_READY:
268 		return "IAVF_ERR_NOT_READY";
269 	case IAVF_NOT_SUPPORTED:
270 		return "IAVF_NOT_SUPPORTED";
271 	case IAVF_ERR_FIRMWARE_API_VERSION:
272 		return "IAVF_ERR_FIRMWARE_API_VERSION";
273 	case IAVF_ERR_ADMIN_QUEUE_CRITICAL_ERROR:
274 		return "IAVF_ERR_ADMIN_QUEUE_CRITICAL_ERROR";
275 	}
276 
277 	snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
278 	return hw->err_str;
279 }
280 
281 /**
282  * iavf_debug_aq
283  * @hw: debug mask related to admin queue
284  * @mask: debug mask
285  * @desc: pointer to admin queue descriptor
286  * @buffer: pointer to command buffer
287  * @buf_len: max length of buffer
288  *
289  * Dumps debug log about adminq command with descriptor contents.
290  **/
iavf_debug_aq(struct iavf_hw * hw,enum iavf_debug_mask mask,void * desc,void * buffer,u16 buf_len)291 void iavf_debug_aq(struct iavf_hw *hw, enum iavf_debug_mask mask, void *desc,
292 		   void *buffer, u16 buf_len)
293 {
294 	struct iavf_aq_desc *aq_desc = (struct iavf_aq_desc *)desc;
295 	u8 *buf = (u8 *)buffer;
296 	u16 len;
297 	u16 i = 0;
298 
299 	if ((!(mask & hw->debug_mask)) || (desc == NULL))
300 		return;
301 
302 	len = LE16_TO_CPU(aq_desc->datalen);
303 
304 	iavf_debug(hw, mask,
305 		   "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
306 		   LE16_TO_CPU(aq_desc->opcode),
307 		   LE16_TO_CPU(aq_desc->flags),
308 		   LE16_TO_CPU(aq_desc->datalen),
309 		   LE16_TO_CPU(aq_desc->retval));
310 	iavf_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
311 		   LE32_TO_CPU(aq_desc->cookie_high),
312 		   LE32_TO_CPU(aq_desc->cookie_low));
313 	iavf_debug(hw, mask, "\tparam (0,1)  0x%08X 0x%08X\n",
314 		   LE32_TO_CPU(aq_desc->params.internal.param0),
315 		   LE32_TO_CPU(aq_desc->params.internal.param1));
316 	iavf_debug(hw, mask, "\taddr (h,l)   0x%08X 0x%08X\n",
317 		   LE32_TO_CPU(aq_desc->params.external.addr_high),
318 		   LE32_TO_CPU(aq_desc->params.external.addr_low));
319 
320 	if ((buffer != NULL) && (aq_desc->datalen != 0)) {
321 		iavf_debug(hw, mask, "AQ CMD Buffer:\n");
322 		if (buf_len < len)
323 			len = buf_len;
324 		/* write the full 16-byte chunks */
325 		for (i = 0; i < (len - 16); i += 16)
326 			iavf_debug(hw, mask,
327 				   "\t0x%04X  %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
328 				   i, buf[i], buf[i+1], buf[i+2], buf[i+3],
329 				   buf[i+4], buf[i+5], buf[i+6], buf[i+7],
330 				   buf[i+8], buf[i+9], buf[i+10], buf[i+11],
331 				   buf[i+12], buf[i+13], buf[i+14], buf[i+15]);
332 		/* the most we could have left is 16 bytes, pad with zeros */
333 		if (i < len) {
334 			char d_buf[16];
335 			int j, i_sav;
336 
337 			i_sav = i;
338 			memset(d_buf, 0, sizeof(d_buf));
339 			for (j = 0; i < len; j++, i++)
340 				d_buf[j] = buf[i];
341 			iavf_debug(hw, mask,
342 				   "\t0x%04X  %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
343 				   i_sav, d_buf[0], d_buf[1], d_buf[2], d_buf[3],
344 				   d_buf[4], d_buf[5], d_buf[6], d_buf[7],
345 				   d_buf[8], d_buf[9], d_buf[10], d_buf[11],
346 				   d_buf[12], d_buf[13], d_buf[14], d_buf[15]);
347 		}
348 	}
349 }
350 
351 /**
352  * iavf_check_asq_alive
353  * @hw: pointer to the hw struct
354  *
355  * Returns true if Queue is enabled else false.
356  **/
iavf_check_asq_alive(struct iavf_hw * hw)357 bool iavf_check_asq_alive(struct iavf_hw *hw)
358 {
359 	if (hw->aq.asq.len)
360 		return !!(rd32(hw, hw->aq.asq.len) &
361 			IAVF_VF_ATQLEN1_ATQENABLE_MASK);
362 	else
363 		return false;
364 }
365 
366 /**
367  * iavf_aq_queue_shutdown
368  * @hw: pointer to the hw struct
369  * @unloading: is the driver unloading itself
370  *
371  * Tell the Firmware that we're shutting down the AdminQ and whether
372  * or not the driver is unloading as well.
373  **/
iavf_aq_queue_shutdown(struct iavf_hw * hw,bool unloading)374 enum iavf_status iavf_aq_queue_shutdown(struct iavf_hw *hw,
375 					bool unloading)
376 {
377 	struct iavf_aq_desc desc;
378 	struct iavf_aqc_queue_shutdown *cmd =
379 		(struct iavf_aqc_queue_shutdown *)&desc.params.raw;
380 	enum iavf_status status;
381 
382 	iavf_fill_default_direct_cmd_desc(&desc,
383 					  iavf_aqc_opc_queue_shutdown);
384 
385 	if (unloading)
386 		cmd->driver_unloading = CPU_TO_LE32(IAVF_AQ_DRIVER_UNLOADING);
387 	status = iavf_asq_send_command(hw, &desc, NULL, 0, NULL);
388 
389 	return status;
390 }
391 
392 /**
393  * iavf_aq_get_set_rss_lut
394  * @hw: pointer to the hardware structure
395  * @vsi_id: vsi fw index
396  * @pf_lut: for PF table set true, for VSI table set false
397  * @lut: pointer to the lut buffer provided by the caller
398  * @lut_size: size of the lut buffer
399  * @set: set true to set the table, false to get the table
400  *
401  * Internal function to get or set RSS look up table
402  **/
iavf_aq_get_set_rss_lut(struct iavf_hw * hw,u16 vsi_id,bool pf_lut,u8 * lut,u16 lut_size,bool set)403 STATIC enum iavf_status iavf_aq_get_set_rss_lut(struct iavf_hw *hw,
404 						u16 vsi_id, bool pf_lut,
405 						u8 *lut, u16 lut_size,
406 						bool set)
407 {
408 	enum iavf_status status;
409 	struct iavf_aq_desc desc;
410 	struct iavf_aqc_get_set_rss_lut *cmd_resp =
411 		   (struct iavf_aqc_get_set_rss_lut *)&desc.params.raw;
412 
413 	if (set)
414 		iavf_fill_default_direct_cmd_desc(&desc,
415 						  iavf_aqc_opc_set_rss_lut);
416 	else
417 		iavf_fill_default_direct_cmd_desc(&desc,
418 						  iavf_aqc_opc_get_rss_lut);
419 
420 	/* Indirect command */
421 	desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_BUF);
422 	desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_RD);
423 
424 	cmd_resp->vsi_id =
425 			CPU_TO_LE16((u16)((vsi_id <<
426 					  IAVF_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
427 					  IAVF_AQC_SET_RSS_LUT_VSI_ID_MASK));
428 	cmd_resp->vsi_id |= CPU_TO_LE16((u16)IAVF_AQC_SET_RSS_LUT_VSI_VALID);
429 
430 	if (pf_lut)
431 		cmd_resp->flags |= CPU_TO_LE16((u16)
432 					((IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
433 					IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
434 					IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
435 	else
436 		cmd_resp->flags |= CPU_TO_LE16((u16)
437 					((IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
438 					IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
439 					IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
440 
441 	status = iavf_asq_send_command(hw, &desc, lut, lut_size, NULL);
442 
443 	return status;
444 }
445 
446 /**
447  * iavf_aq_get_rss_lut
448  * @hw: pointer to the hardware structure
449  * @vsi_id: vsi fw index
450  * @pf_lut: for PF table set true, for VSI table set false
451  * @lut: pointer to the lut buffer provided by the caller
452  * @lut_size: size of the lut buffer
453  *
454  * get the RSS lookup table, PF or VSI type
455  **/
iavf_aq_get_rss_lut(struct iavf_hw * hw,u16 vsi_id,bool pf_lut,u8 * lut,u16 lut_size)456 enum iavf_status iavf_aq_get_rss_lut(struct iavf_hw *hw, u16 vsi_id,
457 				     bool pf_lut, u8 *lut, u16 lut_size)
458 {
459 	return iavf_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
460 				       false);
461 }
462 
463 /**
464  * iavf_aq_set_rss_lut
465  * @hw: pointer to the hardware structure
466  * @vsi_id: vsi fw index
467  * @pf_lut: for PF table set true, for VSI table set false
468  * @lut: pointer to the lut buffer provided by the caller
469  * @lut_size: size of the lut buffer
470  *
471  * set the RSS lookup table, PF or VSI type
472  **/
iavf_aq_set_rss_lut(struct iavf_hw * hw,u16 vsi_id,bool pf_lut,u8 * lut,u16 lut_size)473 enum iavf_status iavf_aq_set_rss_lut(struct iavf_hw *hw, u16 vsi_id,
474 				     bool pf_lut, u8 *lut, u16 lut_size)
475 {
476 	return iavf_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
477 }
478 
479 /**
480  * iavf_aq_get_set_rss_key
481  * @hw: pointer to the hw struct
482  * @vsi_id: vsi fw index
483  * @key: pointer to key info struct
484  * @set: set true to set the key, false to get the key
485  *
486  * get the RSS key per VSI
487  **/
iavf_aq_get_set_rss_key(struct iavf_hw * hw,u16 vsi_id,struct iavf_aqc_get_set_rss_key_data * key,bool set)488 STATIC enum iavf_status iavf_aq_get_set_rss_key(struct iavf_hw *hw,
489 				      u16 vsi_id,
490 				      struct iavf_aqc_get_set_rss_key_data *key,
491 				      bool set)
492 {
493 	enum iavf_status status;
494 	struct iavf_aq_desc desc;
495 	struct iavf_aqc_get_set_rss_key *cmd_resp =
496 			(struct iavf_aqc_get_set_rss_key *)&desc.params.raw;
497 	u16 key_size = sizeof(struct iavf_aqc_get_set_rss_key_data);
498 
499 	if (set)
500 		iavf_fill_default_direct_cmd_desc(&desc,
501 						  iavf_aqc_opc_set_rss_key);
502 	else
503 		iavf_fill_default_direct_cmd_desc(&desc,
504 						  iavf_aqc_opc_get_rss_key);
505 
506 	/* Indirect command */
507 	desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_BUF);
508 	desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_RD);
509 
510 	cmd_resp->vsi_id =
511 			CPU_TO_LE16((u16)((vsi_id <<
512 					  IAVF_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
513 					  IAVF_AQC_SET_RSS_KEY_VSI_ID_MASK));
514 	cmd_resp->vsi_id |= CPU_TO_LE16((u16)IAVF_AQC_SET_RSS_KEY_VSI_VALID);
515 
516 	status = iavf_asq_send_command(hw, &desc, key, key_size, NULL);
517 
518 	return status;
519 }
520 
521 /**
522  * iavf_aq_get_rss_key
523  * @hw: pointer to the hw struct
524  * @vsi_id: vsi fw index
525  * @key: pointer to key info struct
526  *
527  **/
iavf_aq_get_rss_key(struct iavf_hw * hw,u16 vsi_id,struct iavf_aqc_get_set_rss_key_data * key)528 enum iavf_status iavf_aq_get_rss_key(struct iavf_hw *hw,
529 				     u16 vsi_id,
530 				     struct iavf_aqc_get_set_rss_key_data *key)
531 {
532 	return iavf_aq_get_set_rss_key(hw, vsi_id, key, false);
533 }
534 
535 /**
536  * iavf_aq_set_rss_key
537  * @hw: pointer to the hw struct
538  * @vsi_id: vsi fw index
539  * @key: pointer to key info struct
540  *
541  * set the RSS key per VSI
542  **/
iavf_aq_set_rss_key(struct iavf_hw * hw,u16 vsi_id,struct iavf_aqc_get_set_rss_key_data * key)543 enum iavf_status iavf_aq_set_rss_key(struct iavf_hw *hw,
544 				     u16 vsi_id,
545 				     struct iavf_aqc_get_set_rss_key_data *key)
546 {
547 	return iavf_aq_get_set_rss_key(hw, vsi_id, key, true);
548 }
549 
550 /* The iavf_ptype_lookup table is used to convert from the 8-bit ptype in the
551  * hardware to a bit-field that can be used by SW to more easily determine the
552  * packet type.
553  *
554  * Macros are used to shorten the table lines and make this table human
555  * readable.
556  *
557  * We store the PTYPE in the top byte of the bit field - this is just so that
558  * we can check that the table doesn't have a row missing, as the index into
559  * the table should be the PTYPE.
560  *
561  * Typical work flow:
562  *
563  * IF NOT iavf_ptype_lookup[ptype].known
564  * THEN
565  *      Packet is unknown
566  * ELSE IF iavf_ptype_lookup[ptype].outer_ip == IAVF_RX_PTYPE_OUTER_IP
567  *      Use the rest of the fields to look at the tunnels, inner protocols, etc
568  * ELSE
569  *      Use the enum iavf_rx_l2_ptype to decode the packet type
570  * ENDIF
571  */
572 
573 /* macro to make the table lines short */
574 #define IAVF_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
575 	{	PTYPE, \
576 		1, \
577 		IAVF_RX_PTYPE_OUTER_##OUTER_IP, \
578 		IAVF_RX_PTYPE_OUTER_##OUTER_IP_VER, \
579 		IAVF_RX_PTYPE_##OUTER_FRAG, \
580 		IAVF_RX_PTYPE_TUNNEL_##T, \
581 		IAVF_RX_PTYPE_TUNNEL_END_##TE, \
582 		IAVF_RX_PTYPE_##TEF, \
583 		IAVF_RX_PTYPE_INNER_PROT_##I, \
584 		IAVF_RX_PTYPE_PAYLOAD_LAYER_##PL }
585 
586 #define IAVF_PTT_UNUSED_ENTRY(PTYPE) \
587 		{ PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
588 
589 /* shorter macros makes the table fit but are terse */
590 #define IAVF_RX_PTYPE_NOF		IAVF_RX_PTYPE_NOT_FRAG
591 #define IAVF_RX_PTYPE_FRG		IAVF_RX_PTYPE_FRAG
592 #define IAVF_RX_PTYPE_INNER_PROT_TS	IAVF_RX_PTYPE_INNER_PROT_TIMESYNC
593 
594 /* Lookup table mapping the HW PTYPE to the bit field for decoding */
595 struct iavf_rx_ptype_decoded iavf_ptype_lookup[] = {
596 	/* L2 Packet types */
597 	IAVF_PTT_UNUSED_ENTRY(0),
598 	IAVF_PTT(1,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
599 	IAVF_PTT(2,  L2, NONE, NOF, NONE, NONE, NOF, TS,   PAY2),
600 	IAVF_PTT(3,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
601 	IAVF_PTT_UNUSED_ENTRY(4),
602 	IAVF_PTT_UNUSED_ENTRY(5),
603 	IAVF_PTT(6,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
604 	IAVF_PTT(7,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
605 	IAVF_PTT_UNUSED_ENTRY(8),
606 	IAVF_PTT_UNUSED_ENTRY(9),
607 	IAVF_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
608 	IAVF_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
609 	IAVF_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
610 	IAVF_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
611 	IAVF_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
612 	IAVF_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
613 	IAVF_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
614 	IAVF_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
615 	IAVF_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
616 	IAVF_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
617 	IAVF_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
618 	IAVF_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
619 
620 	/* Non Tunneled IPv4 */
621 	IAVF_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
622 	IAVF_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
623 	IAVF_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP,  PAY4),
624 	IAVF_PTT_UNUSED_ENTRY(25),
625 	IAVF_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP,  PAY4),
626 	IAVF_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
627 	IAVF_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
628 
629 	/* IPv4 --> IPv4 */
630 	IAVF_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
631 	IAVF_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
632 	IAVF_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
633 	IAVF_PTT_UNUSED_ENTRY(32),
634 	IAVF_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
635 	IAVF_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
636 	IAVF_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
637 
638 	/* IPv4 --> IPv6 */
639 	IAVF_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
640 	IAVF_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
641 	IAVF_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
642 	IAVF_PTT_UNUSED_ENTRY(39),
643 	IAVF_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
644 	IAVF_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
645 	IAVF_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
646 
647 	/* IPv4 --> GRE/NAT */
648 	IAVF_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
649 
650 	/* IPv4 --> GRE/NAT --> IPv4 */
651 	IAVF_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
652 	IAVF_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
653 	IAVF_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
654 	IAVF_PTT_UNUSED_ENTRY(47),
655 	IAVF_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
656 	IAVF_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
657 	IAVF_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
658 
659 	/* IPv4 --> GRE/NAT --> IPv6 */
660 	IAVF_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
661 	IAVF_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
662 	IAVF_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
663 	IAVF_PTT_UNUSED_ENTRY(54),
664 	IAVF_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
665 	IAVF_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
666 	IAVF_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
667 
668 	/* IPv4 --> GRE/NAT --> MAC */
669 	IAVF_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
670 
671 	/* IPv4 --> GRE/NAT --> MAC --> IPv4 */
672 	IAVF_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
673 	IAVF_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
674 	IAVF_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
675 	IAVF_PTT_UNUSED_ENTRY(62),
676 	IAVF_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
677 	IAVF_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
678 	IAVF_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
679 
680 	/* IPv4 --> GRE/NAT -> MAC --> IPv6 */
681 	IAVF_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
682 	IAVF_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
683 	IAVF_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
684 	IAVF_PTT_UNUSED_ENTRY(69),
685 	IAVF_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
686 	IAVF_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
687 	IAVF_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
688 
689 	/* IPv4 --> GRE/NAT --> MAC/VLAN */
690 	IAVF_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
691 
692 	/* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
693 	IAVF_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
694 	IAVF_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
695 	IAVF_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
696 	IAVF_PTT_UNUSED_ENTRY(77),
697 	IAVF_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
698 	IAVF_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
699 	IAVF_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
700 
701 	/* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
702 	IAVF_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
703 	IAVF_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
704 	IAVF_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
705 	IAVF_PTT_UNUSED_ENTRY(84),
706 	IAVF_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
707 	IAVF_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
708 	IAVF_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
709 
710 	/* Non Tunneled IPv6 */
711 	IAVF_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
712 	IAVF_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
713 	IAVF_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP,  PAY4),
714 	IAVF_PTT_UNUSED_ENTRY(91),
715 	IAVF_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP,  PAY4),
716 	IAVF_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
717 	IAVF_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
718 
719 	/* IPv6 --> IPv4 */
720 	IAVF_PTT(95,  IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
721 	IAVF_PTT(96,  IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
722 	IAVF_PTT(97,  IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
723 	IAVF_PTT_UNUSED_ENTRY(98),
724 	IAVF_PTT(99,  IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
725 	IAVF_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
726 	IAVF_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
727 
728 	/* IPv6 --> IPv6 */
729 	IAVF_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
730 	IAVF_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
731 	IAVF_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
732 	IAVF_PTT_UNUSED_ENTRY(105),
733 	IAVF_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
734 	IAVF_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
735 	IAVF_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
736 
737 	/* IPv6 --> GRE/NAT */
738 	IAVF_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
739 
740 	/* IPv6 --> GRE/NAT -> IPv4 */
741 	IAVF_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
742 	IAVF_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
743 	IAVF_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
744 	IAVF_PTT_UNUSED_ENTRY(113),
745 	IAVF_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
746 	IAVF_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
747 	IAVF_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
748 
749 	/* IPv6 --> GRE/NAT -> IPv6 */
750 	IAVF_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
751 	IAVF_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
752 	IAVF_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
753 	IAVF_PTT_UNUSED_ENTRY(120),
754 	IAVF_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
755 	IAVF_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
756 	IAVF_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
757 
758 	/* IPv6 --> GRE/NAT -> MAC */
759 	IAVF_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
760 
761 	/* IPv6 --> GRE/NAT -> MAC -> IPv4 */
762 	IAVF_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
763 	IAVF_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
764 	IAVF_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
765 	IAVF_PTT_UNUSED_ENTRY(128),
766 	IAVF_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
767 	IAVF_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
768 	IAVF_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
769 
770 	/* IPv6 --> GRE/NAT -> MAC -> IPv6 */
771 	IAVF_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
772 	IAVF_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
773 	IAVF_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
774 	IAVF_PTT_UNUSED_ENTRY(135),
775 	IAVF_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
776 	IAVF_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
777 	IAVF_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
778 
779 	/* IPv6 --> GRE/NAT -> MAC/VLAN */
780 	IAVF_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
781 
782 	/* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
783 	IAVF_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
784 	IAVF_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
785 	IAVF_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
786 	IAVF_PTT_UNUSED_ENTRY(143),
787 	IAVF_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
788 	IAVF_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
789 	IAVF_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
790 
791 	/* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
792 	IAVF_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
793 	IAVF_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
794 	IAVF_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
795 	IAVF_PTT_UNUSED_ENTRY(150),
796 	IAVF_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
797 	IAVF_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
798 	IAVF_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
799 
800 	/* unused entries */
801 	IAVF_PTT_UNUSED_ENTRY(154),
802 	IAVF_PTT_UNUSED_ENTRY(155),
803 	IAVF_PTT_UNUSED_ENTRY(156),
804 	IAVF_PTT_UNUSED_ENTRY(157),
805 	IAVF_PTT_UNUSED_ENTRY(158),
806 	IAVF_PTT_UNUSED_ENTRY(159),
807 
808 	IAVF_PTT_UNUSED_ENTRY(160),
809 	IAVF_PTT_UNUSED_ENTRY(161),
810 	IAVF_PTT_UNUSED_ENTRY(162),
811 	IAVF_PTT_UNUSED_ENTRY(163),
812 	IAVF_PTT_UNUSED_ENTRY(164),
813 	IAVF_PTT_UNUSED_ENTRY(165),
814 	IAVF_PTT_UNUSED_ENTRY(166),
815 	IAVF_PTT_UNUSED_ENTRY(167),
816 	IAVF_PTT_UNUSED_ENTRY(168),
817 	IAVF_PTT_UNUSED_ENTRY(169),
818 
819 	IAVF_PTT_UNUSED_ENTRY(170),
820 	IAVF_PTT_UNUSED_ENTRY(171),
821 	IAVF_PTT_UNUSED_ENTRY(172),
822 	IAVF_PTT_UNUSED_ENTRY(173),
823 	IAVF_PTT_UNUSED_ENTRY(174),
824 	IAVF_PTT_UNUSED_ENTRY(175),
825 	IAVF_PTT_UNUSED_ENTRY(176),
826 	IAVF_PTT_UNUSED_ENTRY(177),
827 	IAVF_PTT_UNUSED_ENTRY(178),
828 	IAVF_PTT_UNUSED_ENTRY(179),
829 
830 	IAVF_PTT_UNUSED_ENTRY(180),
831 	IAVF_PTT_UNUSED_ENTRY(181),
832 	IAVF_PTT_UNUSED_ENTRY(182),
833 	IAVF_PTT_UNUSED_ENTRY(183),
834 	IAVF_PTT_UNUSED_ENTRY(184),
835 	IAVF_PTT_UNUSED_ENTRY(185),
836 	IAVF_PTT_UNUSED_ENTRY(186),
837 	IAVF_PTT_UNUSED_ENTRY(187),
838 	IAVF_PTT_UNUSED_ENTRY(188),
839 	IAVF_PTT_UNUSED_ENTRY(189),
840 
841 	IAVF_PTT_UNUSED_ENTRY(190),
842 	IAVF_PTT_UNUSED_ENTRY(191),
843 	IAVF_PTT_UNUSED_ENTRY(192),
844 	IAVF_PTT_UNUSED_ENTRY(193),
845 	IAVF_PTT_UNUSED_ENTRY(194),
846 	IAVF_PTT_UNUSED_ENTRY(195),
847 	IAVF_PTT_UNUSED_ENTRY(196),
848 	IAVF_PTT_UNUSED_ENTRY(197),
849 	IAVF_PTT_UNUSED_ENTRY(198),
850 	IAVF_PTT_UNUSED_ENTRY(199),
851 
852 	IAVF_PTT_UNUSED_ENTRY(200),
853 	IAVF_PTT_UNUSED_ENTRY(201),
854 	IAVF_PTT_UNUSED_ENTRY(202),
855 	IAVF_PTT_UNUSED_ENTRY(203),
856 	IAVF_PTT_UNUSED_ENTRY(204),
857 	IAVF_PTT_UNUSED_ENTRY(205),
858 	IAVF_PTT_UNUSED_ENTRY(206),
859 	IAVF_PTT_UNUSED_ENTRY(207),
860 	IAVF_PTT_UNUSED_ENTRY(208),
861 	IAVF_PTT_UNUSED_ENTRY(209),
862 
863 	IAVF_PTT_UNUSED_ENTRY(210),
864 	IAVF_PTT_UNUSED_ENTRY(211),
865 	IAVF_PTT_UNUSED_ENTRY(212),
866 	IAVF_PTT_UNUSED_ENTRY(213),
867 	IAVF_PTT_UNUSED_ENTRY(214),
868 	IAVF_PTT_UNUSED_ENTRY(215),
869 	IAVF_PTT_UNUSED_ENTRY(216),
870 	IAVF_PTT_UNUSED_ENTRY(217),
871 	IAVF_PTT_UNUSED_ENTRY(218),
872 	IAVF_PTT_UNUSED_ENTRY(219),
873 
874 	IAVF_PTT_UNUSED_ENTRY(220),
875 	IAVF_PTT_UNUSED_ENTRY(221),
876 	IAVF_PTT_UNUSED_ENTRY(222),
877 	IAVF_PTT_UNUSED_ENTRY(223),
878 	IAVF_PTT_UNUSED_ENTRY(224),
879 	IAVF_PTT_UNUSED_ENTRY(225),
880 	IAVF_PTT_UNUSED_ENTRY(226),
881 	IAVF_PTT_UNUSED_ENTRY(227),
882 	IAVF_PTT_UNUSED_ENTRY(228),
883 	IAVF_PTT_UNUSED_ENTRY(229),
884 
885 	IAVF_PTT_UNUSED_ENTRY(230),
886 	IAVF_PTT_UNUSED_ENTRY(231),
887 	IAVF_PTT_UNUSED_ENTRY(232),
888 	IAVF_PTT_UNUSED_ENTRY(233),
889 	IAVF_PTT_UNUSED_ENTRY(234),
890 	IAVF_PTT_UNUSED_ENTRY(235),
891 	IAVF_PTT_UNUSED_ENTRY(236),
892 	IAVF_PTT_UNUSED_ENTRY(237),
893 	IAVF_PTT_UNUSED_ENTRY(238),
894 	IAVF_PTT_UNUSED_ENTRY(239),
895 
896 	IAVF_PTT_UNUSED_ENTRY(240),
897 	IAVF_PTT_UNUSED_ENTRY(241),
898 	IAVF_PTT_UNUSED_ENTRY(242),
899 	IAVF_PTT_UNUSED_ENTRY(243),
900 	IAVF_PTT_UNUSED_ENTRY(244),
901 	IAVF_PTT_UNUSED_ENTRY(245),
902 	IAVF_PTT_UNUSED_ENTRY(246),
903 	IAVF_PTT_UNUSED_ENTRY(247),
904 	IAVF_PTT_UNUSED_ENTRY(248),
905 	IAVF_PTT_UNUSED_ENTRY(249),
906 
907 	IAVF_PTT_UNUSED_ENTRY(250),
908 	IAVF_PTT_UNUSED_ENTRY(251),
909 	IAVF_PTT_UNUSED_ENTRY(252),
910 	IAVF_PTT_UNUSED_ENTRY(253),
911 	IAVF_PTT_UNUSED_ENTRY(254),
912 	IAVF_PTT_UNUSED_ENTRY(255)
913 };
914 
915 /**
916  * iavf_validate_mac_addr - Validate unicast MAC address
917  * @mac_addr: pointer to MAC address
918  *
919  * Tests a MAC address to ensure it is a valid Individual Address
920  **/
iavf_validate_mac_addr(u8 * mac_addr)921 enum iavf_status iavf_validate_mac_addr(u8 *mac_addr)
922 {
923 	enum iavf_status status = IAVF_SUCCESS;
924 
925 	DEBUGFUNC("iavf_validate_mac_addr");
926 
927 	/* Broadcast addresses ARE multicast addresses
928 	 * Make sure it is not a multicast address
929 	 * Reject the zero address
930 	 */
931 	if (IAVF_IS_MULTICAST(mac_addr) ||
932 	    (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
933 	      mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0))
934 		status = IAVF_ERR_INVALID_MAC_ADDR;
935 
936 	return status;
937 }
938 
939 /**
940  * iavf_aq_send_msg_to_pf
941  * @hw: pointer to the hardware structure
942  * @v_opcode: opcodes for VF-PF communication
943  * @v_retval: return error code
944  * @msg: pointer to the msg buffer
945  * @msglen: msg length
946  * @cmd_details: pointer to command details
947  *
948  * Send message to PF driver using admin queue. By default, this message
949  * is sent asynchronously, i.e. iavf_asq_send_command() does not wait for
950  * completion before returning.
951  **/
iavf_aq_send_msg_to_pf(struct iavf_hw * hw,enum virtchnl_ops v_opcode,enum iavf_status v_retval,u8 * msg,u16 msglen,struct iavf_asq_cmd_details * cmd_details)952 enum iavf_status iavf_aq_send_msg_to_pf(struct iavf_hw *hw,
953 				enum virtchnl_ops v_opcode,
954 				enum iavf_status v_retval,
955 				u8 *msg, u16 msglen,
956 				struct iavf_asq_cmd_details *cmd_details)
957 {
958 	struct iavf_aq_desc desc;
959 	struct iavf_asq_cmd_details details;
960 	enum iavf_status status;
961 
962 	iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_send_msg_to_pf);
963 	desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_SI);
964 	desc.cookie_high = CPU_TO_LE32(v_opcode);
965 	desc.cookie_low = CPU_TO_LE32(v_retval);
966 	if (msglen) {
967 		desc.flags |= CPU_TO_LE16((u16)(IAVF_AQ_FLAG_BUF
968 						| IAVF_AQ_FLAG_RD));
969 		if (msglen > IAVF_AQ_LARGE_BUF)
970 			desc.flags |= CPU_TO_LE16((u16)IAVF_AQ_FLAG_LB);
971 		desc.datalen = CPU_TO_LE16(msglen);
972 	}
973 	if (!cmd_details) {
974 		iavf_memset(&details, 0, sizeof(details), IAVF_NONDMA_MEM);
975 		details.async = true;
976 		cmd_details = &details;
977 	}
978 	status = iavf_asq_send_command(hw, (struct iavf_aq_desc *)&desc, msg,
979 				       msglen, cmd_details);
980 	return status;
981 }
982 
983 /**
984  * iavf_vf_parse_hw_config
985  * @hw: pointer to the hardware structure
986  * @msg: pointer to the virtual channel VF resource structure
987  *
988  * Given a VF resource message from the PF, populate the hw struct
989  * with appropriate information.
990  **/
iavf_vf_parse_hw_config(struct iavf_hw * hw,struct virtchnl_vf_resource * msg)991 void iavf_vf_parse_hw_config(struct iavf_hw *hw,
992 			     struct virtchnl_vf_resource *msg)
993 {
994 	struct virtchnl_vsi_resource *vsi_res;
995 	int i;
996 
997 	vsi_res = &msg->vsi_res[0];
998 
999 	hw->dev_caps.num_vsis = msg->num_vsis;
1000 	hw->dev_caps.num_rx_qp = msg->num_queue_pairs;
1001 	hw->dev_caps.num_tx_qp = msg->num_queue_pairs;
1002 	hw->dev_caps.num_msix_vectors_vf = msg->max_vectors;
1003 	hw->dev_caps.dcb = msg->vf_cap_flags &
1004 			   VIRTCHNL_VF_OFFLOAD_L2;
1005 	for (i = 0; i < msg->num_vsis; i++) {
1006 		if (vsi_res->vsi_type == VIRTCHNL_VSI_SRIOV) {
1007 			iavf_memcpy(hw->mac.perm_addr,
1008 				    vsi_res->default_mac_addr,
1009 				    ETH_ALEN,
1010 				    IAVF_NONDMA_TO_NONDMA);
1011 			iavf_memcpy(hw->mac.addr, vsi_res->default_mac_addr,
1012 				    ETH_ALEN,
1013 				    IAVF_NONDMA_TO_NONDMA);
1014 		}
1015 		vsi_res++;
1016 	}
1017 }
1018 
1019 /**
1020  * iavf_vf_reset
1021  * @hw: pointer to the hardware structure
1022  *
1023  * Send a VF_RESET message to the PF. Does not wait for response from PF
1024  * as none will be forthcoming. Immediately after calling this function,
1025  * the admin queue should be shut down and (optionally) reinitialized.
1026  **/
iavf_vf_reset(struct iavf_hw * hw)1027 enum iavf_status iavf_vf_reset(struct iavf_hw *hw)
1028 {
1029 	return iavf_aq_send_msg_to_pf(hw, VIRTCHNL_OP_RESET_VF,
1030 				      IAVF_SUCCESS, NULL, 0, NULL);
1031 }
1032 
1033 /**
1034 * iavf_aq_clear_all_wol_filters
1035 * @hw: pointer to the hw struct
1036 * @cmd_details: pointer to command details structure or NULL
1037 *
1038 * Get information for the reason of a Wake Up event
1039 **/
iavf_aq_clear_all_wol_filters(struct iavf_hw * hw,struct iavf_asq_cmd_details * cmd_details)1040 enum iavf_status iavf_aq_clear_all_wol_filters(struct iavf_hw *hw,
1041 			struct iavf_asq_cmd_details *cmd_details)
1042 {
1043 	struct iavf_aq_desc desc;
1044 	enum iavf_status status;
1045 
1046 	iavf_fill_default_direct_cmd_desc(&desc,
1047 					  iavf_aqc_opc_clear_all_wol_filters);
1048 
1049 	status = iavf_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1050 
1051 	return status;
1052 }
1053