1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
3 
4 #include "iavf_type.h"
5 #include "iavf_adminq.h"
6 #include "iavf_prototype.h"
7 #include <linux/avf/virtchnl.h>
8 
9 /**
10  * iavf_set_mac_type - Sets MAC type
11  * @hw: pointer to the HW structure
12  *
13  * This function sets the mac type of the adapter based on the
14  * vendor ID and device ID stored in the hw structure.
15  **/
iavf_set_mac_type(struct iavf_hw * hw)16 enum iavf_status iavf_set_mac_type(struct iavf_hw *hw)
17 {
18 	enum iavf_status status = 0;
19 
20 	if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
21 		switch (hw->device_id) {
22 		case IAVF_DEV_ID_X722_VF:
23 			hw->mac.type = IAVF_MAC_X722_VF;
24 			break;
25 		case IAVF_DEV_ID_VF:
26 		case IAVF_DEV_ID_VF_HV:
27 		case IAVF_DEV_ID_ADAPTIVE_VF:
28 			hw->mac.type = IAVF_MAC_VF;
29 			break;
30 		default:
31 			hw->mac.type = IAVF_MAC_GENERIC;
32 			break;
33 		}
34 	} else {
35 		status = IAVF_ERR_DEVICE_NOT_SUPPORTED;
36 	}
37 
38 	hw_dbg(hw, "found mac: %d, returns: %d\n", hw->mac.type, status);
39 	return status;
40 }
41 
42 /**
43  * iavf_aq_str - convert AQ err code to a string
44  * @hw: pointer to the HW structure
45  * @aq_err: the AQ error code to convert
46  **/
iavf_aq_str(struct iavf_hw * hw,enum iavf_admin_queue_err aq_err)47 const char *iavf_aq_str(struct iavf_hw *hw, enum iavf_admin_queue_err aq_err)
48 {
49 	switch (aq_err) {
50 	case IAVF_AQ_RC_OK:
51 		return "OK";
52 	case IAVF_AQ_RC_EPERM:
53 		return "IAVF_AQ_RC_EPERM";
54 	case IAVF_AQ_RC_ENOENT:
55 		return "IAVF_AQ_RC_ENOENT";
56 	case IAVF_AQ_RC_ESRCH:
57 		return "IAVF_AQ_RC_ESRCH";
58 	case IAVF_AQ_RC_EINTR:
59 		return "IAVF_AQ_RC_EINTR";
60 	case IAVF_AQ_RC_EIO:
61 		return "IAVF_AQ_RC_EIO";
62 	case IAVF_AQ_RC_ENXIO:
63 		return "IAVF_AQ_RC_ENXIO";
64 	case IAVF_AQ_RC_E2BIG:
65 		return "IAVF_AQ_RC_E2BIG";
66 	case IAVF_AQ_RC_EAGAIN:
67 		return "IAVF_AQ_RC_EAGAIN";
68 	case IAVF_AQ_RC_ENOMEM:
69 		return "IAVF_AQ_RC_ENOMEM";
70 	case IAVF_AQ_RC_EACCES:
71 		return "IAVF_AQ_RC_EACCES";
72 	case IAVF_AQ_RC_EFAULT:
73 		return "IAVF_AQ_RC_EFAULT";
74 	case IAVF_AQ_RC_EBUSY:
75 		return "IAVF_AQ_RC_EBUSY";
76 	case IAVF_AQ_RC_EEXIST:
77 		return "IAVF_AQ_RC_EEXIST";
78 	case IAVF_AQ_RC_EINVAL:
79 		return "IAVF_AQ_RC_EINVAL";
80 	case IAVF_AQ_RC_ENOTTY:
81 		return "IAVF_AQ_RC_ENOTTY";
82 	case IAVF_AQ_RC_ENOSPC:
83 		return "IAVF_AQ_RC_ENOSPC";
84 	case IAVF_AQ_RC_ENOSYS:
85 		return "IAVF_AQ_RC_ENOSYS";
86 	case IAVF_AQ_RC_ERANGE:
87 		return "IAVF_AQ_RC_ERANGE";
88 	case IAVF_AQ_RC_EFLUSHED:
89 		return "IAVF_AQ_RC_EFLUSHED";
90 	case IAVF_AQ_RC_BAD_ADDR:
91 		return "IAVF_AQ_RC_BAD_ADDR";
92 	case IAVF_AQ_RC_EMODE:
93 		return "IAVF_AQ_RC_EMODE";
94 	case IAVF_AQ_RC_EFBIG:
95 		return "IAVF_AQ_RC_EFBIG";
96 	}
97 
98 	snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
99 	return hw->err_str;
100 }
101 
102 /**
103  * iavf_stat_str - convert status err code to a string
104  * @hw: pointer to the HW structure
105  * @stat_err: the status error code to convert
106  **/
iavf_stat_str(struct iavf_hw * hw,enum iavf_status stat_err)107 const char *iavf_stat_str(struct iavf_hw *hw, enum iavf_status stat_err)
108 {
109 	switch (stat_err) {
110 	case 0:
111 		return "OK";
112 	case IAVF_ERR_NVM:
113 		return "IAVF_ERR_NVM";
114 	case IAVF_ERR_NVM_CHECKSUM:
115 		return "IAVF_ERR_NVM_CHECKSUM";
116 	case IAVF_ERR_PHY:
117 		return "IAVF_ERR_PHY";
118 	case IAVF_ERR_CONFIG:
119 		return "IAVF_ERR_CONFIG";
120 	case IAVF_ERR_PARAM:
121 		return "IAVF_ERR_PARAM";
122 	case IAVF_ERR_MAC_TYPE:
123 		return "IAVF_ERR_MAC_TYPE";
124 	case IAVF_ERR_UNKNOWN_PHY:
125 		return "IAVF_ERR_UNKNOWN_PHY";
126 	case IAVF_ERR_LINK_SETUP:
127 		return "IAVF_ERR_LINK_SETUP";
128 	case IAVF_ERR_ADAPTER_STOPPED:
129 		return "IAVF_ERR_ADAPTER_STOPPED";
130 	case IAVF_ERR_INVALID_MAC_ADDR:
131 		return "IAVF_ERR_INVALID_MAC_ADDR";
132 	case IAVF_ERR_DEVICE_NOT_SUPPORTED:
133 		return "IAVF_ERR_DEVICE_NOT_SUPPORTED";
134 	case IAVF_ERR_PRIMARY_REQUESTS_PENDING:
135 		return "IAVF_ERR_PRIMARY_REQUESTS_PENDING";
136 	case IAVF_ERR_INVALID_LINK_SETTINGS:
137 		return "IAVF_ERR_INVALID_LINK_SETTINGS";
138 	case IAVF_ERR_AUTONEG_NOT_COMPLETE:
139 		return "IAVF_ERR_AUTONEG_NOT_COMPLETE";
140 	case IAVF_ERR_RESET_FAILED:
141 		return "IAVF_ERR_RESET_FAILED";
142 	case IAVF_ERR_SWFW_SYNC:
143 		return "IAVF_ERR_SWFW_SYNC";
144 	case IAVF_ERR_NO_AVAILABLE_VSI:
145 		return "IAVF_ERR_NO_AVAILABLE_VSI";
146 	case IAVF_ERR_NO_MEMORY:
147 		return "IAVF_ERR_NO_MEMORY";
148 	case IAVF_ERR_BAD_PTR:
149 		return "IAVF_ERR_BAD_PTR";
150 	case IAVF_ERR_RING_FULL:
151 		return "IAVF_ERR_RING_FULL";
152 	case IAVF_ERR_INVALID_PD_ID:
153 		return "IAVF_ERR_INVALID_PD_ID";
154 	case IAVF_ERR_INVALID_QP_ID:
155 		return "IAVF_ERR_INVALID_QP_ID";
156 	case IAVF_ERR_INVALID_CQ_ID:
157 		return "IAVF_ERR_INVALID_CQ_ID";
158 	case IAVF_ERR_INVALID_CEQ_ID:
159 		return "IAVF_ERR_INVALID_CEQ_ID";
160 	case IAVF_ERR_INVALID_AEQ_ID:
161 		return "IAVF_ERR_INVALID_AEQ_ID";
162 	case IAVF_ERR_INVALID_SIZE:
163 		return "IAVF_ERR_INVALID_SIZE";
164 	case IAVF_ERR_INVALID_ARP_INDEX:
165 		return "IAVF_ERR_INVALID_ARP_INDEX";
166 	case IAVF_ERR_INVALID_FPM_FUNC_ID:
167 		return "IAVF_ERR_INVALID_FPM_FUNC_ID";
168 	case IAVF_ERR_QP_INVALID_MSG_SIZE:
169 		return "IAVF_ERR_QP_INVALID_MSG_SIZE";
170 	case IAVF_ERR_QP_TOOMANY_WRS_POSTED:
171 		return "IAVF_ERR_QP_TOOMANY_WRS_POSTED";
172 	case IAVF_ERR_INVALID_FRAG_COUNT:
173 		return "IAVF_ERR_INVALID_FRAG_COUNT";
174 	case IAVF_ERR_QUEUE_EMPTY:
175 		return "IAVF_ERR_QUEUE_EMPTY";
176 	case IAVF_ERR_INVALID_ALIGNMENT:
177 		return "IAVF_ERR_INVALID_ALIGNMENT";
178 	case IAVF_ERR_FLUSHED_QUEUE:
179 		return "IAVF_ERR_FLUSHED_QUEUE";
180 	case IAVF_ERR_INVALID_PUSH_PAGE_INDEX:
181 		return "IAVF_ERR_INVALID_PUSH_PAGE_INDEX";
182 	case IAVF_ERR_INVALID_IMM_DATA_SIZE:
183 		return "IAVF_ERR_INVALID_IMM_DATA_SIZE";
184 	case IAVF_ERR_TIMEOUT:
185 		return "IAVF_ERR_TIMEOUT";
186 	case IAVF_ERR_OPCODE_MISMATCH:
187 		return "IAVF_ERR_OPCODE_MISMATCH";
188 	case IAVF_ERR_CQP_COMPL_ERROR:
189 		return "IAVF_ERR_CQP_COMPL_ERROR";
190 	case IAVF_ERR_INVALID_VF_ID:
191 		return "IAVF_ERR_INVALID_VF_ID";
192 	case IAVF_ERR_INVALID_HMCFN_ID:
193 		return "IAVF_ERR_INVALID_HMCFN_ID";
194 	case IAVF_ERR_BACKING_PAGE_ERROR:
195 		return "IAVF_ERR_BACKING_PAGE_ERROR";
196 	case IAVF_ERR_NO_PBLCHUNKS_AVAILABLE:
197 		return "IAVF_ERR_NO_PBLCHUNKS_AVAILABLE";
198 	case IAVF_ERR_INVALID_PBLE_INDEX:
199 		return "IAVF_ERR_INVALID_PBLE_INDEX";
200 	case IAVF_ERR_INVALID_SD_INDEX:
201 		return "IAVF_ERR_INVALID_SD_INDEX";
202 	case IAVF_ERR_INVALID_PAGE_DESC_INDEX:
203 		return "IAVF_ERR_INVALID_PAGE_DESC_INDEX";
204 	case IAVF_ERR_INVALID_SD_TYPE:
205 		return "IAVF_ERR_INVALID_SD_TYPE";
206 	case IAVF_ERR_MEMCPY_FAILED:
207 		return "IAVF_ERR_MEMCPY_FAILED";
208 	case IAVF_ERR_INVALID_HMC_OBJ_INDEX:
209 		return "IAVF_ERR_INVALID_HMC_OBJ_INDEX";
210 	case IAVF_ERR_INVALID_HMC_OBJ_COUNT:
211 		return "IAVF_ERR_INVALID_HMC_OBJ_COUNT";
212 	case IAVF_ERR_INVALID_SRQ_ARM_LIMIT:
213 		return "IAVF_ERR_INVALID_SRQ_ARM_LIMIT";
214 	case IAVF_ERR_SRQ_ENABLED:
215 		return "IAVF_ERR_SRQ_ENABLED";
216 	case IAVF_ERR_ADMIN_QUEUE_ERROR:
217 		return "IAVF_ERR_ADMIN_QUEUE_ERROR";
218 	case IAVF_ERR_ADMIN_QUEUE_TIMEOUT:
219 		return "IAVF_ERR_ADMIN_QUEUE_TIMEOUT";
220 	case IAVF_ERR_BUF_TOO_SHORT:
221 		return "IAVF_ERR_BUF_TOO_SHORT";
222 	case IAVF_ERR_ADMIN_QUEUE_FULL:
223 		return "IAVF_ERR_ADMIN_QUEUE_FULL";
224 	case IAVF_ERR_ADMIN_QUEUE_NO_WORK:
225 		return "IAVF_ERR_ADMIN_QUEUE_NO_WORK";
226 	case IAVF_ERR_BAD_IWARP_CQE:
227 		return "IAVF_ERR_BAD_IWARP_CQE";
228 	case IAVF_ERR_NVM_BLANK_MODE:
229 		return "IAVF_ERR_NVM_BLANK_MODE";
230 	case IAVF_ERR_NOT_IMPLEMENTED:
231 		return "IAVF_ERR_NOT_IMPLEMENTED";
232 	case IAVF_ERR_PE_DOORBELL_NOT_ENABLED:
233 		return "IAVF_ERR_PE_DOORBELL_NOT_ENABLED";
234 	case IAVF_ERR_DIAG_TEST_FAILED:
235 		return "IAVF_ERR_DIAG_TEST_FAILED";
236 	case IAVF_ERR_NOT_READY:
237 		return "IAVF_ERR_NOT_READY";
238 	case IAVF_NOT_SUPPORTED:
239 		return "IAVF_NOT_SUPPORTED";
240 	case IAVF_ERR_FIRMWARE_API_VERSION:
241 		return "IAVF_ERR_FIRMWARE_API_VERSION";
242 	case IAVF_ERR_ADMIN_QUEUE_CRITICAL_ERROR:
243 		return "IAVF_ERR_ADMIN_QUEUE_CRITICAL_ERROR";
244 	}
245 
246 	snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
247 	return hw->err_str;
248 }
249 
250 /**
251  * iavf_debug_aq
252  * @hw: debug mask related to admin queue
253  * @mask: debug mask
254  * @desc: pointer to admin queue descriptor
255  * @buffer: pointer to command buffer
256  * @buf_len: max length of buffer
257  *
258  * Dumps debug log about adminq command with descriptor contents.
259  **/
iavf_debug_aq(struct iavf_hw * hw,enum iavf_debug_mask mask,void * desc,void * buffer,u16 buf_len)260 void iavf_debug_aq(struct iavf_hw *hw, enum iavf_debug_mask mask, void *desc,
261 		   void *buffer, u16 buf_len)
262 {
263 	struct iavf_aq_desc *aq_desc = (struct iavf_aq_desc *)desc;
264 	u8 *buf = (u8 *)buffer;
265 
266 	if ((!(mask & hw->debug_mask)) || !desc)
267 		return;
268 
269 	iavf_debug(hw, mask,
270 		   "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
271 		   le16_to_cpu(aq_desc->opcode),
272 		   le16_to_cpu(aq_desc->flags),
273 		   le16_to_cpu(aq_desc->datalen),
274 		   le16_to_cpu(aq_desc->retval));
275 	iavf_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
276 		   le32_to_cpu(aq_desc->cookie_high),
277 		   le32_to_cpu(aq_desc->cookie_low));
278 	iavf_debug(hw, mask, "\tparam (0,1)  0x%08X 0x%08X\n",
279 		   le32_to_cpu(aq_desc->params.internal.param0),
280 		   le32_to_cpu(aq_desc->params.internal.param1));
281 	iavf_debug(hw, mask, "\taddr (h,l)   0x%08X 0x%08X\n",
282 		   le32_to_cpu(aq_desc->params.external.addr_high),
283 		   le32_to_cpu(aq_desc->params.external.addr_low));
284 
285 	if (buffer && aq_desc->datalen) {
286 		u16 len = le16_to_cpu(aq_desc->datalen);
287 
288 		iavf_debug(hw, mask, "AQ CMD Buffer:\n");
289 		if (buf_len < len)
290 			len = buf_len;
291 		/* write the full 16-byte chunks */
292 		if (hw->debug_mask & mask) {
293 			char prefix[27];
294 
295 			snprintf(prefix, sizeof(prefix),
296 				 "iavf %02x:%02x.%x: \t0x",
297 				 hw->bus.bus_id,
298 				 hw->bus.device,
299 				 hw->bus.func);
300 
301 			print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET,
302 				       16, 1, buf, len, false);
303 		}
304 	}
305 }
306 
307 /**
308  * iavf_check_asq_alive
309  * @hw: pointer to the hw struct
310  *
311  * Returns true if Queue is enabled else false.
312  **/
iavf_check_asq_alive(struct iavf_hw * hw)313 bool iavf_check_asq_alive(struct iavf_hw *hw)
314 {
315 	if (hw->aq.asq.len)
316 		return !!(rd32(hw, hw->aq.asq.len) &
317 			  IAVF_VF_ATQLEN1_ATQENABLE_MASK);
318 	else
319 		return false;
320 }
321 
322 /**
323  * iavf_aq_queue_shutdown
324  * @hw: pointer to the hw struct
325  * @unloading: is the driver unloading itself
326  *
327  * Tell the Firmware that we're shutting down the AdminQ and whether
328  * or not the driver is unloading as well.
329  **/
iavf_aq_queue_shutdown(struct iavf_hw * hw,bool unloading)330 enum iavf_status iavf_aq_queue_shutdown(struct iavf_hw *hw, bool unloading)
331 {
332 	struct iavf_aq_desc desc;
333 	struct iavf_aqc_queue_shutdown *cmd =
334 		(struct iavf_aqc_queue_shutdown *)&desc.params.raw;
335 	enum iavf_status status;
336 
337 	iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_queue_shutdown);
338 
339 	if (unloading)
340 		cmd->driver_unloading = cpu_to_le32(IAVF_AQ_DRIVER_UNLOADING);
341 	status = iavf_asq_send_command(hw, &desc, NULL, 0, NULL);
342 
343 	return status;
344 }
345 
346 /**
347  * iavf_aq_get_set_rss_lut
348  * @hw: pointer to the hardware structure
349  * @vsi_id: vsi fw index
350  * @pf_lut: for PF table set true, for VSI table set false
351  * @lut: pointer to the lut buffer provided by the caller
352  * @lut_size: size of the lut buffer
353  * @set: set true to set the table, false to get the table
354  *
355  * Internal function to get or set RSS look up table
356  **/
iavf_aq_get_set_rss_lut(struct iavf_hw * hw,u16 vsi_id,bool pf_lut,u8 * lut,u16 lut_size,bool set)357 static enum iavf_status iavf_aq_get_set_rss_lut(struct iavf_hw *hw,
358 						u16 vsi_id, bool pf_lut,
359 						u8 *lut, u16 lut_size,
360 						bool set)
361 {
362 	enum iavf_status status;
363 	struct iavf_aq_desc desc;
364 	struct iavf_aqc_get_set_rss_lut *cmd_resp =
365 		   (struct iavf_aqc_get_set_rss_lut *)&desc.params.raw;
366 
367 	if (set)
368 		iavf_fill_default_direct_cmd_desc(&desc,
369 						  iavf_aqc_opc_set_rss_lut);
370 	else
371 		iavf_fill_default_direct_cmd_desc(&desc,
372 						  iavf_aqc_opc_get_rss_lut);
373 
374 	/* Indirect command */
375 	desc.flags |= cpu_to_le16((u16)IAVF_AQ_FLAG_BUF);
376 	desc.flags |= cpu_to_le16((u16)IAVF_AQ_FLAG_RD);
377 
378 	cmd_resp->vsi_id =
379 			cpu_to_le16((u16)((vsi_id <<
380 					  IAVF_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
381 					  IAVF_AQC_SET_RSS_LUT_VSI_ID_MASK));
382 	cmd_resp->vsi_id |= cpu_to_le16((u16)IAVF_AQC_SET_RSS_LUT_VSI_VALID);
383 
384 	if (pf_lut)
385 		cmd_resp->flags |= cpu_to_le16((u16)
386 					((IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
387 					IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
388 					IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
389 	else
390 		cmd_resp->flags |= cpu_to_le16((u16)
391 					((IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
392 					IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
393 					IAVF_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
394 
395 	status = iavf_asq_send_command(hw, &desc, lut, lut_size, NULL);
396 
397 	return status;
398 }
399 
400 /**
401  * iavf_aq_get_rss_lut
402  * @hw: pointer to the hardware structure
403  * @vsi_id: vsi fw index
404  * @pf_lut: for PF table set true, for VSI table set false
405  * @lut: pointer to the lut buffer provided by the caller
406  * @lut_size: size of the lut buffer
407  *
408  * get the RSS lookup table, PF or VSI type
409  **/
iavf_aq_get_rss_lut(struct iavf_hw * hw,u16 vsi_id,bool pf_lut,u8 * lut,u16 lut_size)410 enum iavf_status iavf_aq_get_rss_lut(struct iavf_hw *hw, u16 vsi_id,
411 				     bool pf_lut, u8 *lut, u16 lut_size)
412 {
413 	return iavf_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
414 				       false);
415 }
416 
417 /**
418  * iavf_aq_set_rss_lut
419  * @hw: pointer to the hardware structure
420  * @vsi_id: vsi fw index
421  * @pf_lut: for PF table set true, for VSI table set false
422  * @lut: pointer to the lut buffer provided by the caller
423  * @lut_size: size of the lut buffer
424  *
425  * set the RSS lookup table, PF or VSI type
426  **/
iavf_aq_set_rss_lut(struct iavf_hw * hw,u16 vsi_id,bool pf_lut,u8 * lut,u16 lut_size)427 enum iavf_status iavf_aq_set_rss_lut(struct iavf_hw *hw, u16 vsi_id,
428 				     bool pf_lut, u8 *lut, u16 lut_size)
429 {
430 	return iavf_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
431 }
432 
433 /**
434  * iavf_aq_get_set_rss_key
435  * @hw: pointer to the hw struct
436  * @vsi_id: vsi fw index
437  * @key: pointer to key info struct
438  * @set: set true to set the key, false to get the key
439  *
440  * get the RSS key per VSI
441  **/
442 static enum
iavf_aq_get_set_rss_key(struct iavf_hw * hw,u16 vsi_id,struct iavf_aqc_get_set_rss_key_data * key,bool set)443 iavf_status iavf_aq_get_set_rss_key(struct iavf_hw *hw, u16 vsi_id,
444 				    struct iavf_aqc_get_set_rss_key_data *key,
445 				    bool set)
446 {
447 	enum iavf_status status;
448 	struct iavf_aq_desc desc;
449 	struct iavf_aqc_get_set_rss_key *cmd_resp =
450 			(struct iavf_aqc_get_set_rss_key *)&desc.params.raw;
451 	u16 key_size = sizeof(struct iavf_aqc_get_set_rss_key_data);
452 
453 	if (set)
454 		iavf_fill_default_direct_cmd_desc(&desc,
455 						  iavf_aqc_opc_set_rss_key);
456 	else
457 		iavf_fill_default_direct_cmd_desc(&desc,
458 						  iavf_aqc_opc_get_rss_key);
459 
460 	/* Indirect command */
461 	desc.flags |= cpu_to_le16((u16)IAVF_AQ_FLAG_BUF);
462 	desc.flags |= cpu_to_le16((u16)IAVF_AQ_FLAG_RD);
463 
464 	cmd_resp->vsi_id =
465 			cpu_to_le16((u16)((vsi_id <<
466 					  IAVF_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
467 					  IAVF_AQC_SET_RSS_KEY_VSI_ID_MASK));
468 	cmd_resp->vsi_id |= cpu_to_le16((u16)IAVF_AQC_SET_RSS_KEY_VSI_VALID);
469 
470 	status = iavf_asq_send_command(hw, &desc, key, key_size, NULL);
471 
472 	return status;
473 }
474 
475 /**
476  * iavf_aq_get_rss_key
477  * @hw: pointer to the hw struct
478  * @vsi_id: vsi fw index
479  * @key: pointer to key info struct
480  *
481  **/
iavf_aq_get_rss_key(struct iavf_hw * hw,u16 vsi_id,struct iavf_aqc_get_set_rss_key_data * key)482 enum iavf_status iavf_aq_get_rss_key(struct iavf_hw *hw, u16 vsi_id,
483 				     struct iavf_aqc_get_set_rss_key_data *key)
484 {
485 	return iavf_aq_get_set_rss_key(hw, vsi_id, key, false);
486 }
487 
488 /**
489  * iavf_aq_set_rss_key
490  * @hw: pointer to the hw struct
491  * @vsi_id: vsi fw index
492  * @key: pointer to key info struct
493  *
494  * set the RSS key per VSI
495  **/
iavf_aq_set_rss_key(struct iavf_hw * hw,u16 vsi_id,struct iavf_aqc_get_set_rss_key_data * key)496 enum iavf_status iavf_aq_set_rss_key(struct iavf_hw *hw, u16 vsi_id,
497 				     struct iavf_aqc_get_set_rss_key_data *key)
498 {
499 	return iavf_aq_get_set_rss_key(hw, vsi_id, key, true);
500 }
501 
502 /* The iavf_ptype_lookup table is used to convert from the 8-bit ptype in the
503  * hardware to a bit-field that can be used by SW to more easily determine the
504  * packet type.
505  *
506  * Macros are used to shorten the table lines and make this table human
507  * readable.
508  *
509  * We store the PTYPE in the top byte of the bit field - this is just so that
510  * we can check that the table doesn't have a row missing, as the index into
511  * the table should be the PTYPE.
512  *
513  * Typical work flow:
514  *
515  * IF NOT iavf_ptype_lookup[ptype].known
516  * THEN
517  *      Packet is unknown
518  * ELSE IF iavf_ptype_lookup[ptype].outer_ip == IAVF_RX_PTYPE_OUTER_IP
519  *      Use the rest of the fields to look at the tunnels, inner protocols, etc
520  * ELSE
521  *      Use the enum iavf_rx_l2_ptype to decode the packet type
522  * ENDIF
523  */
524 
525 /* macro to make the table lines short, use explicit indexing with [PTYPE] */
526 #define IAVF_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
527 	[PTYPE] = { \
528 		1, \
529 		IAVF_RX_PTYPE_OUTER_##OUTER_IP, \
530 		IAVF_RX_PTYPE_OUTER_##OUTER_IP_VER, \
531 		IAVF_RX_PTYPE_##OUTER_FRAG, \
532 		IAVF_RX_PTYPE_TUNNEL_##T, \
533 		IAVF_RX_PTYPE_TUNNEL_END_##TE, \
534 		IAVF_RX_PTYPE_##TEF, \
535 		IAVF_RX_PTYPE_INNER_PROT_##I, \
536 		IAVF_RX_PTYPE_PAYLOAD_LAYER_##PL }
537 
538 #define IAVF_PTT_UNUSED_ENTRY(PTYPE) [PTYPE] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
539 
540 /* shorter macros makes the table fit but are terse */
541 #define IAVF_RX_PTYPE_NOF		IAVF_RX_PTYPE_NOT_FRAG
542 #define IAVF_RX_PTYPE_FRG		IAVF_RX_PTYPE_FRAG
543 #define IAVF_RX_PTYPE_INNER_PROT_TS	IAVF_RX_PTYPE_INNER_PROT_TIMESYNC
544 
545 /* Lookup table mapping the 8-bit HW PTYPE to the bit field for decoding */
546 struct iavf_rx_ptype_decoded iavf_ptype_lookup[BIT(8)] = {
547 	/* L2 Packet types */
548 	IAVF_PTT_UNUSED_ENTRY(0),
549 	IAVF_PTT(1,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
550 	IAVF_PTT(2,  L2, NONE, NOF, NONE, NONE, NOF, TS,   PAY2),
551 	IAVF_PTT(3,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
552 	IAVF_PTT_UNUSED_ENTRY(4),
553 	IAVF_PTT_UNUSED_ENTRY(5),
554 	IAVF_PTT(6,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
555 	IAVF_PTT(7,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
556 	IAVF_PTT_UNUSED_ENTRY(8),
557 	IAVF_PTT_UNUSED_ENTRY(9),
558 	IAVF_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
559 	IAVF_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
560 	IAVF_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
561 	IAVF_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
562 	IAVF_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
563 	IAVF_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
564 	IAVF_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
565 	IAVF_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
566 	IAVF_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
567 	IAVF_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
568 	IAVF_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
569 	IAVF_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
570 
571 	/* Non Tunneled IPv4 */
572 	IAVF_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
573 	IAVF_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
574 	IAVF_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP,  PAY4),
575 	IAVF_PTT_UNUSED_ENTRY(25),
576 	IAVF_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP,  PAY4),
577 	IAVF_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
578 	IAVF_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
579 
580 	/* IPv4 --> IPv4 */
581 	IAVF_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
582 	IAVF_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
583 	IAVF_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
584 	IAVF_PTT_UNUSED_ENTRY(32),
585 	IAVF_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
586 	IAVF_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
587 	IAVF_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
588 
589 	/* IPv4 --> IPv6 */
590 	IAVF_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
591 	IAVF_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
592 	IAVF_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
593 	IAVF_PTT_UNUSED_ENTRY(39),
594 	IAVF_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
595 	IAVF_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
596 	IAVF_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
597 
598 	/* IPv4 --> GRE/NAT */
599 	IAVF_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
600 
601 	/* IPv4 --> GRE/NAT --> IPv4 */
602 	IAVF_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
603 	IAVF_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
604 	IAVF_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
605 	IAVF_PTT_UNUSED_ENTRY(47),
606 	IAVF_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
607 	IAVF_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
608 	IAVF_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
609 
610 	/* IPv4 --> GRE/NAT --> IPv6 */
611 	IAVF_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
612 	IAVF_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
613 	IAVF_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
614 	IAVF_PTT_UNUSED_ENTRY(54),
615 	IAVF_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
616 	IAVF_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
617 	IAVF_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
618 
619 	/* IPv4 --> GRE/NAT --> MAC */
620 	IAVF_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
621 
622 	/* IPv4 --> GRE/NAT --> MAC --> IPv4 */
623 	IAVF_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
624 	IAVF_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
625 	IAVF_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
626 	IAVF_PTT_UNUSED_ENTRY(62),
627 	IAVF_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
628 	IAVF_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
629 	IAVF_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
630 
631 	/* IPv4 --> GRE/NAT -> MAC --> IPv6 */
632 	IAVF_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
633 	IAVF_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
634 	IAVF_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
635 	IAVF_PTT_UNUSED_ENTRY(69),
636 	IAVF_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
637 	IAVF_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
638 	IAVF_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
639 
640 	/* IPv4 --> GRE/NAT --> MAC/VLAN */
641 	IAVF_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
642 
643 	/* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
644 	IAVF_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
645 	IAVF_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
646 	IAVF_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
647 	IAVF_PTT_UNUSED_ENTRY(77),
648 	IAVF_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
649 	IAVF_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
650 	IAVF_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
651 
652 	/* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
653 	IAVF_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
654 	IAVF_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
655 	IAVF_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
656 	IAVF_PTT_UNUSED_ENTRY(84),
657 	IAVF_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
658 	IAVF_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
659 	IAVF_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
660 
661 	/* Non Tunneled IPv6 */
662 	IAVF_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
663 	IAVF_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
664 	IAVF_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP,  PAY3),
665 	IAVF_PTT_UNUSED_ENTRY(91),
666 	IAVF_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP,  PAY4),
667 	IAVF_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
668 	IAVF_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
669 
670 	/* IPv6 --> IPv4 */
671 	IAVF_PTT(95,  IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
672 	IAVF_PTT(96,  IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
673 	IAVF_PTT(97,  IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
674 	IAVF_PTT_UNUSED_ENTRY(98),
675 	IAVF_PTT(99,  IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
676 	IAVF_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
677 	IAVF_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
678 
679 	/* IPv6 --> IPv6 */
680 	IAVF_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
681 	IAVF_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
682 	IAVF_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
683 	IAVF_PTT_UNUSED_ENTRY(105),
684 	IAVF_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
685 	IAVF_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
686 	IAVF_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
687 
688 	/* IPv6 --> GRE/NAT */
689 	IAVF_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
690 
691 	/* IPv6 --> GRE/NAT -> IPv4 */
692 	IAVF_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
693 	IAVF_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
694 	IAVF_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
695 	IAVF_PTT_UNUSED_ENTRY(113),
696 	IAVF_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
697 	IAVF_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
698 	IAVF_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
699 
700 	/* IPv6 --> GRE/NAT -> IPv6 */
701 	IAVF_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
702 	IAVF_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
703 	IAVF_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
704 	IAVF_PTT_UNUSED_ENTRY(120),
705 	IAVF_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
706 	IAVF_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
707 	IAVF_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
708 
709 	/* IPv6 --> GRE/NAT -> MAC */
710 	IAVF_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
711 
712 	/* IPv6 --> GRE/NAT -> MAC -> IPv4 */
713 	IAVF_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
714 	IAVF_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
715 	IAVF_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
716 	IAVF_PTT_UNUSED_ENTRY(128),
717 	IAVF_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
718 	IAVF_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
719 	IAVF_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
720 
721 	/* IPv6 --> GRE/NAT -> MAC -> IPv6 */
722 	IAVF_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
723 	IAVF_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
724 	IAVF_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
725 	IAVF_PTT_UNUSED_ENTRY(135),
726 	IAVF_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
727 	IAVF_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
728 	IAVF_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
729 
730 	/* IPv6 --> GRE/NAT -> MAC/VLAN */
731 	IAVF_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
732 
733 	/* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
734 	IAVF_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
735 	IAVF_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
736 	IAVF_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
737 	IAVF_PTT_UNUSED_ENTRY(143),
738 	IAVF_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
739 	IAVF_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
740 	IAVF_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
741 
742 	/* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
743 	IAVF_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
744 	IAVF_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
745 	IAVF_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
746 	IAVF_PTT_UNUSED_ENTRY(150),
747 	IAVF_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
748 	IAVF_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
749 	IAVF_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
750 
751 	/* unused entries */
752 	[154 ... 255] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
753 };
754 
755 /**
756  * iavf_aq_send_msg_to_pf
757  * @hw: pointer to the hardware structure
758  * @v_opcode: opcodes for VF-PF communication
759  * @v_retval: return error code
760  * @msg: pointer to the msg buffer
761  * @msglen: msg length
762  * @cmd_details: pointer to command details
763  *
764  * Send message to PF driver using admin queue. By default, this message
765  * is sent asynchronously, i.e. iavf_asq_send_command() does not wait for
766  * completion before returning.
767  **/
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)768 enum iavf_status iavf_aq_send_msg_to_pf(struct iavf_hw *hw,
769 					enum virtchnl_ops v_opcode,
770 					enum iavf_status v_retval,
771 					u8 *msg, u16 msglen,
772 					struct iavf_asq_cmd_details *cmd_details)
773 {
774 	struct iavf_asq_cmd_details details;
775 	struct iavf_aq_desc desc;
776 	enum iavf_status status;
777 
778 	iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_send_msg_to_pf);
779 	desc.flags |= cpu_to_le16((u16)IAVF_AQ_FLAG_SI);
780 	desc.cookie_high = cpu_to_le32(v_opcode);
781 	desc.cookie_low = cpu_to_le32(v_retval);
782 	if (msglen) {
783 		desc.flags |= cpu_to_le16((u16)(IAVF_AQ_FLAG_BUF
784 						| IAVF_AQ_FLAG_RD));
785 		if (msglen > IAVF_AQ_LARGE_BUF)
786 			desc.flags |= cpu_to_le16((u16)IAVF_AQ_FLAG_LB);
787 		desc.datalen = cpu_to_le16(msglen);
788 	}
789 	if (!cmd_details) {
790 		memset(&details, 0, sizeof(details));
791 		details.async = true;
792 		cmd_details = &details;
793 	}
794 	status = iavf_asq_send_command(hw, &desc, msg, msglen, cmd_details);
795 	return status;
796 }
797 
798 /**
799  * iavf_vf_parse_hw_config
800  * @hw: pointer to the hardware structure
801  * @msg: pointer to the virtual channel VF resource structure
802  *
803  * Given a VF resource message from the PF, populate the hw struct
804  * with appropriate information.
805  **/
iavf_vf_parse_hw_config(struct iavf_hw * hw,struct virtchnl_vf_resource * msg)806 void iavf_vf_parse_hw_config(struct iavf_hw *hw,
807 			     struct virtchnl_vf_resource *msg)
808 {
809 	struct virtchnl_vsi_resource *vsi_res;
810 	int i;
811 
812 	vsi_res = &msg->vsi_res[0];
813 
814 	hw->dev_caps.num_vsis = msg->num_vsis;
815 	hw->dev_caps.num_rx_qp = msg->num_queue_pairs;
816 	hw->dev_caps.num_tx_qp = msg->num_queue_pairs;
817 	hw->dev_caps.num_msix_vectors_vf = msg->max_vectors;
818 	hw->dev_caps.dcb = msg->vf_cap_flags &
819 			   VIRTCHNL_VF_OFFLOAD_L2;
820 	hw->dev_caps.fcoe = 0;
821 	for (i = 0; i < msg->num_vsis; i++) {
822 		if (vsi_res->vsi_type == VIRTCHNL_VSI_SRIOV) {
823 			ether_addr_copy(hw->mac.perm_addr,
824 					vsi_res->default_mac_addr);
825 			ether_addr_copy(hw->mac.addr,
826 					vsi_res->default_mac_addr);
827 		}
828 		vsi_res++;
829 	}
830 }
831 
832 /**
833  * iavf_vf_reset
834  * @hw: pointer to the hardware structure
835  *
836  * Send a VF_RESET message to the PF. Does not wait for response from PF
837  * as none will be forthcoming. Immediately after calling this function,
838  * the admin queue should be shut down and (optionally) reinitialized.
839  **/
iavf_vf_reset(struct iavf_hw * hw)840 enum iavf_status iavf_vf_reset(struct iavf_hw *hw)
841 {
842 	return iavf_aq_send_msg_to_pf(hw, VIRTCHNL_OP_RESET_VF,
843 				      0, NULL, 0, NULL);
844 }
845