1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
3 
4 #include <linux/avf/virtchnl.h>
5 #include <linux/bitfield.h>
6 #include "iavf_type.h"
7 #include "iavf_adminq.h"
8 #include "iavf_prototype.h"
9 
10 /**
11  * iavf_set_mac_type - Sets MAC type
12  * @hw: pointer to the HW structure
13  *
14  * This function sets the mac type of the adapter based on the
15  * vendor ID and device ID stored in the hw structure.
16  **/
iavf_set_mac_type(struct iavf_hw * hw)17 enum iavf_status iavf_set_mac_type(struct iavf_hw *hw)
18 {
19 	enum iavf_status status = 0;
20 
21 	if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
22 		switch (hw->device_id) {
23 		case IAVF_DEV_ID_X722_VF:
24 			hw->mac.type = IAVF_MAC_X722_VF;
25 			break;
26 		case IAVF_DEV_ID_VF:
27 		case IAVF_DEV_ID_VF_HV:
28 		case IAVF_DEV_ID_ADAPTIVE_VF:
29 			hw->mac.type = IAVF_MAC_VF;
30 			break;
31 		default:
32 			hw->mac.type = IAVF_MAC_GENERIC;
33 			break;
34 		}
35 	} else {
36 		status = IAVF_ERR_DEVICE_NOT_SUPPORTED;
37 	}
38 
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_RDMA_CQE:
227 		return "IAVF_ERR_BAD_RDMA_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_set_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  * set the RSS lookup table, PF or VSI type
409  **/
iavf_aq_set_rss_lut(struct iavf_hw * hw,u16 vsi_id,bool pf_lut,u8 * lut,u16 lut_size)410 enum iavf_status iavf_aq_set_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, true);
414 }
415 
416 /**
417  * iavf_aq_get_set_rss_key
418  * @hw: pointer to the hw struct
419  * @vsi_id: vsi fw index
420  * @key: pointer to key info struct
421  * @set: set true to set the key, false to get the key
422  *
423  * get the RSS key per VSI
424  **/
425 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)426 iavf_status iavf_aq_get_set_rss_key(struct iavf_hw *hw, u16 vsi_id,
427 				    struct iavf_aqc_get_set_rss_key_data *key,
428 				    bool set)
429 {
430 	enum iavf_status status;
431 	struct iavf_aq_desc desc;
432 	struct iavf_aqc_get_set_rss_key *cmd_resp =
433 			(struct iavf_aqc_get_set_rss_key *)&desc.params.raw;
434 	u16 key_size = sizeof(struct iavf_aqc_get_set_rss_key_data);
435 
436 	if (set)
437 		iavf_fill_default_direct_cmd_desc(&desc,
438 						  iavf_aqc_opc_set_rss_key);
439 	else
440 		iavf_fill_default_direct_cmd_desc(&desc,
441 						  iavf_aqc_opc_get_rss_key);
442 
443 	/* Indirect command */
444 	desc.flags |= cpu_to_le16((u16)IAVF_AQ_FLAG_BUF);
445 	desc.flags |= cpu_to_le16((u16)IAVF_AQ_FLAG_RD);
446 
447 	cmd_resp->vsi_id =
448 			cpu_to_le16((u16)((vsi_id <<
449 					  IAVF_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
450 					  IAVF_AQC_SET_RSS_KEY_VSI_ID_MASK));
451 	cmd_resp->vsi_id |= cpu_to_le16((u16)IAVF_AQC_SET_RSS_KEY_VSI_VALID);
452 
453 	status = iavf_asq_send_command(hw, &desc, key, key_size, NULL);
454 
455 	return status;
456 }
457 
458 /**
459  * iavf_aq_set_rss_key
460  * @hw: pointer to the hw struct
461  * @vsi_id: vsi fw index
462  * @key: pointer to key info struct
463  *
464  * set the RSS key per VSI
465  **/
iavf_aq_set_rss_key(struct iavf_hw * hw,u16 vsi_id,struct iavf_aqc_get_set_rss_key_data * key)466 enum iavf_status iavf_aq_set_rss_key(struct iavf_hw *hw, u16 vsi_id,
467 				     struct iavf_aqc_get_set_rss_key_data *key)
468 {
469 	return iavf_aq_get_set_rss_key(hw, vsi_id, key, true);
470 }
471 
472 /* The iavf_ptype_lookup table is used to convert from the 8-bit ptype in the
473  * hardware to a bit-field that can be used by SW to more easily determine the
474  * packet type.
475  *
476  * Macros are used to shorten the table lines and make this table human
477  * readable.
478  *
479  * We store the PTYPE in the top byte of the bit field - this is just so that
480  * we can check that the table doesn't have a row missing, as the index into
481  * the table should be the PTYPE.
482  *
483  * Typical work flow:
484  *
485  * IF NOT iavf_ptype_lookup[ptype].known
486  * THEN
487  *      Packet is unknown
488  * ELSE IF iavf_ptype_lookup[ptype].outer_ip == IAVF_RX_PTYPE_OUTER_IP
489  *      Use the rest of the fields to look at the tunnels, inner protocols, etc
490  * ELSE
491  *      Use the enum iavf_rx_l2_ptype to decode the packet type
492  * ENDIF
493  */
494 
495 /* macro to make the table lines short, use explicit indexing with [PTYPE] */
496 #define IAVF_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
497 	[PTYPE] = { \
498 		1, \
499 		IAVF_RX_PTYPE_OUTER_##OUTER_IP, \
500 		IAVF_RX_PTYPE_OUTER_##OUTER_IP_VER, \
501 		IAVF_RX_PTYPE_##OUTER_FRAG, \
502 		IAVF_RX_PTYPE_TUNNEL_##T, \
503 		IAVF_RX_PTYPE_TUNNEL_END_##TE, \
504 		IAVF_RX_PTYPE_##TEF, \
505 		IAVF_RX_PTYPE_INNER_PROT_##I, \
506 		IAVF_RX_PTYPE_PAYLOAD_LAYER_##PL }
507 
508 #define IAVF_PTT_UNUSED_ENTRY(PTYPE) [PTYPE] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
509 
510 /* shorter macros makes the table fit but are terse */
511 #define IAVF_RX_PTYPE_NOF		IAVF_RX_PTYPE_NOT_FRAG
512 #define IAVF_RX_PTYPE_FRG		IAVF_RX_PTYPE_FRAG
513 #define IAVF_RX_PTYPE_INNER_PROT_TS	IAVF_RX_PTYPE_INNER_PROT_TIMESYNC
514 
515 /* Lookup table mapping the 8-bit HW PTYPE to the bit field for decoding */
516 struct iavf_rx_ptype_decoded iavf_ptype_lookup[BIT(8)] = {
517 	/* L2 Packet types */
518 	IAVF_PTT_UNUSED_ENTRY(0),
519 	IAVF_PTT(1,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
520 	IAVF_PTT(2,  L2, NONE, NOF, NONE, NONE, NOF, TS,   PAY2),
521 	IAVF_PTT(3,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
522 	IAVF_PTT_UNUSED_ENTRY(4),
523 	IAVF_PTT_UNUSED_ENTRY(5),
524 	IAVF_PTT(6,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
525 	IAVF_PTT(7,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
526 	IAVF_PTT_UNUSED_ENTRY(8),
527 	IAVF_PTT_UNUSED_ENTRY(9),
528 	IAVF_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
529 	IAVF_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
530 	IAVF_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
531 	IAVF_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
532 	IAVF_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
533 	IAVF_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
534 	IAVF_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
535 	IAVF_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
536 	IAVF_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
537 	IAVF_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
538 	IAVF_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
539 	IAVF_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
540 
541 	/* Non Tunneled IPv4 */
542 	IAVF_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
543 	IAVF_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
544 	IAVF_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP,  PAY4),
545 	IAVF_PTT_UNUSED_ENTRY(25),
546 	IAVF_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP,  PAY4),
547 	IAVF_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
548 	IAVF_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
549 
550 	/* IPv4 --> IPv4 */
551 	IAVF_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
552 	IAVF_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
553 	IAVF_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
554 	IAVF_PTT_UNUSED_ENTRY(32),
555 	IAVF_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
556 	IAVF_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
557 	IAVF_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
558 
559 	/* IPv4 --> IPv6 */
560 	IAVF_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
561 	IAVF_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
562 	IAVF_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
563 	IAVF_PTT_UNUSED_ENTRY(39),
564 	IAVF_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
565 	IAVF_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
566 	IAVF_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
567 
568 	/* IPv4 --> GRE/NAT */
569 	IAVF_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
570 
571 	/* IPv4 --> GRE/NAT --> IPv4 */
572 	IAVF_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
573 	IAVF_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
574 	IAVF_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
575 	IAVF_PTT_UNUSED_ENTRY(47),
576 	IAVF_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
577 	IAVF_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
578 	IAVF_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
579 
580 	/* IPv4 --> GRE/NAT --> IPv6 */
581 	IAVF_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
582 	IAVF_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
583 	IAVF_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
584 	IAVF_PTT_UNUSED_ENTRY(54),
585 	IAVF_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
586 	IAVF_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
587 	IAVF_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
588 
589 	/* IPv4 --> GRE/NAT --> MAC */
590 	IAVF_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
591 
592 	/* IPv4 --> GRE/NAT --> MAC --> IPv4 */
593 	IAVF_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
594 	IAVF_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
595 	IAVF_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
596 	IAVF_PTT_UNUSED_ENTRY(62),
597 	IAVF_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
598 	IAVF_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
599 	IAVF_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
600 
601 	/* IPv4 --> GRE/NAT -> MAC --> IPv6 */
602 	IAVF_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
603 	IAVF_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
604 	IAVF_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
605 	IAVF_PTT_UNUSED_ENTRY(69),
606 	IAVF_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
607 	IAVF_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
608 	IAVF_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
609 
610 	/* IPv4 --> GRE/NAT --> MAC/VLAN */
611 	IAVF_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
612 
613 	/* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
614 	IAVF_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
615 	IAVF_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
616 	IAVF_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
617 	IAVF_PTT_UNUSED_ENTRY(77),
618 	IAVF_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
619 	IAVF_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
620 	IAVF_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
621 
622 	/* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
623 	IAVF_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
624 	IAVF_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
625 	IAVF_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
626 	IAVF_PTT_UNUSED_ENTRY(84),
627 	IAVF_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
628 	IAVF_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
629 	IAVF_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
630 
631 	/* Non Tunneled IPv6 */
632 	IAVF_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
633 	IAVF_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
634 	IAVF_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP,  PAY4),
635 	IAVF_PTT_UNUSED_ENTRY(91),
636 	IAVF_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP,  PAY4),
637 	IAVF_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
638 	IAVF_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
639 
640 	/* IPv6 --> IPv4 */
641 	IAVF_PTT(95,  IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
642 	IAVF_PTT(96,  IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
643 	IAVF_PTT(97,  IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
644 	IAVF_PTT_UNUSED_ENTRY(98),
645 	IAVF_PTT(99,  IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
646 	IAVF_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
647 	IAVF_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
648 
649 	/* IPv6 --> IPv6 */
650 	IAVF_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
651 	IAVF_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
652 	IAVF_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
653 	IAVF_PTT_UNUSED_ENTRY(105),
654 	IAVF_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
655 	IAVF_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
656 	IAVF_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
657 
658 	/* IPv6 --> GRE/NAT */
659 	IAVF_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
660 
661 	/* IPv6 --> GRE/NAT -> IPv4 */
662 	IAVF_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
663 	IAVF_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
664 	IAVF_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
665 	IAVF_PTT_UNUSED_ENTRY(113),
666 	IAVF_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
667 	IAVF_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
668 	IAVF_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
669 
670 	/* IPv6 --> GRE/NAT -> IPv6 */
671 	IAVF_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
672 	IAVF_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
673 	IAVF_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
674 	IAVF_PTT_UNUSED_ENTRY(120),
675 	IAVF_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
676 	IAVF_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
677 	IAVF_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
678 
679 	/* IPv6 --> GRE/NAT -> MAC */
680 	IAVF_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
681 
682 	/* IPv6 --> GRE/NAT -> MAC -> IPv4 */
683 	IAVF_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
684 	IAVF_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
685 	IAVF_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
686 	IAVF_PTT_UNUSED_ENTRY(128),
687 	IAVF_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
688 	IAVF_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
689 	IAVF_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
690 
691 	/* IPv6 --> GRE/NAT -> MAC -> IPv6 */
692 	IAVF_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
693 	IAVF_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
694 	IAVF_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
695 	IAVF_PTT_UNUSED_ENTRY(135),
696 	IAVF_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
697 	IAVF_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
698 	IAVF_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
699 
700 	/* IPv6 --> GRE/NAT -> MAC/VLAN */
701 	IAVF_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
702 
703 	/* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
704 	IAVF_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
705 	IAVF_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
706 	IAVF_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
707 	IAVF_PTT_UNUSED_ENTRY(143),
708 	IAVF_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
709 	IAVF_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
710 	IAVF_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
711 
712 	/* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
713 	IAVF_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
714 	IAVF_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
715 	IAVF_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
716 	IAVF_PTT_UNUSED_ENTRY(150),
717 	IAVF_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
718 	IAVF_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
719 	IAVF_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
720 
721 	/* unused entries */
722 	[154 ... 255] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
723 };
724 
725 /**
726  * iavf_aq_send_msg_to_pf
727  * @hw: pointer to the hardware structure
728  * @v_opcode: opcodes for VF-PF communication
729  * @v_retval: return error code
730  * @msg: pointer to the msg buffer
731  * @msglen: msg length
732  * @cmd_details: pointer to command details
733  *
734  * Send message to PF driver using admin queue. By default, this message
735  * is sent asynchronously, i.e. iavf_asq_send_command() does not wait for
736  * completion before returning.
737  **/
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)738 enum iavf_status iavf_aq_send_msg_to_pf(struct iavf_hw *hw,
739 					enum virtchnl_ops v_opcode,
740 					enum iavf_status v_retval,
741 					u8 *msg, u16 msglen,
742 					struct iavf_asq_cmd_details *cmd_details)
743 {
744 	struct iavf_asq_cmd_details details;
745 	struct iavf_aq_desc desc;
746 	enum iavf_status status;
747 
748 	iavf_fill_default_direct_cmd_desc(&desc, iavf_aqc_opc_send_msg_to_pf);
749 	desc.flags |= cpu_to_le16((u16)IAVF_AQ_FLAG_SI);
750 	desc.cookie_high = cpu_to_le32(v_opcode);
751 	desc.cookie_low = cpu_to_le32(v_retval);
752 	if (msglen) {
753 		desc.flags |= cpu_to_le16((u16)(IAVF_AQ_FLAG_BUF
754 						| IAVF_AQ_FLAG_RD));
755 		if (msglen > IAVF_AQ_LARGE_BUF)
756 			desc.flags |= cpu_to_le16((u16)IAVF_AQ_FLAG_LB);
757 		desc.datalen = cpu_to_le16(msglen);
758 	}
759 	if (!cmd_details) {
760 		memset(&details, 0, sizeof(details));
761 		details.async = true;
762 		cmd_details = &details;
763 	}
764 	status = iavf_asq_send_command(hw, &desc, msg, msglen, cmd_details);
765 	return status;
766 }
767 
768 /**
769  * iavf_vf_parse_hw_config
770  * @hw: pointer to the hardware structure
771  * @msg: pointer to the virtual channel VF resource structure
772  *
773  * Given a VF resource message from the PF, populate the hw struct
774  * with appropriate information.
775  **/
iavf_vf_parse_hw_config(struct iavf_hw * hw,struct virtchnl_vf_resource * msg)776 void iavf_vf_parse_hw_config(struct iavf_hw *hw,
777 			     struct virtchnl_vf_resource *msg)
778 {
779 	struct virtchnl_vsi_resource *vsi_res;
780 	int i;
781 
782 	vsi_res = &msg->vsi_res[0];
783 
784 	hw->dev_caps.num_vsis = msg->num_vsis;
785 	hw->dev_caps.num_rx_qp = msg->num_queue_pairs;
786 	hw->dev_caps.num_tx_qp = msg->num_queue_pairs;
787 	hw->dev_caps.num_msix_vectors_vf = msg->max_vectors;
788 	hw->dev_caps.dcb = msg->vf_cap_flags &
789 			   VIRTCHNL_VF_OFFLOAD_L2;
790 	hw->dev_caps.fcoe = 0;
791 	for (i = 0; i < msg->num_vsis; i++) {
792 		if (vsi_res->vsi_type == VIRTCHNL_VSI_SRIOV) {
793 			ether_addr_copy(hw->mac.perm_addr,
794 					vsi_res->default_mac_addr);
795 			ether_addr_copy(hw->mac.addr,
796 					vsi_res->default_mac_addr);
797 		}
798 		vsi_res++;
799 	}
800 }
801