1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
3 
4 #include "iavf.h"
5 #include "iavf_prototype.h"
6 #include "iavf_client.h"
7 
8 /* busy wait delay in msec */
9 #define IAVF_BUSY_WAIT_DELAY 10
10 #define IAVF_BUSY_WAIT_COUNT 50
11 
12 /**
13  * iavf_send_pf_msg
14  * @adapter: adapter structure
15  * @op: virtual channel opcode
16  * @msg: pointer to message buffer
17  * @len: message length
18  *
19  * Send message to PF and print status if failure.
20  **/
21 static int iavf_send_pf_msg(struct iavf_adapter *adapter,
22 			    enum virtchnl_ops op, u8 *msg, u16 len)
23 {
24 	struct iavf_hw *hw = &adapter->hw;
25 	enum iavf_status err;
26 
27 	if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)
28 		return 0; /* nothing to see here, move along */
29 
30 	err = iavf_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
31 	if (err)
32 		dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n",
33 			op, iavf_stat_str(hw, err),
34 			iavf_aq_str(hw, hw->aq.asq_last_status));
35 	return err;
36 }
37 
38 /**
39  * iavf_send_api_ver
40  * @adapter: adapter structure
41  *
42  * Send API version admin queue message to the PF. The reply is not checked
43  * in this function. Returns 0 if the message was successfully
44  * sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
45  **/
46 int iavf_send_api_ver(struct iavf_adapter *adapter)
47 {
48 	struct virtchnl_version_info vvi;
49 
50 	vvi.major = VIRTCHNL_VERSION_MAJOR;
51 	vvi.minor = VIRTCHNL_VERSION_MINOR;
52 
53 	return iavf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
54 				sizeof(vvi));
55 }
56 
57 /**
58  * iavf_verify_api_ver
59  * @adapter: adapter structure
60  *
61  * Compare API versions with the PF. Must be called after admin queue is
62  * initialized. Returns 0 if API versions match, -EIO if they do not,
63  * IAVF_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
64  * from the firmware are propagated.
65  **/
66 int iavf_verify_api_ver(struct iavf_adapter *adapter)
67 {
68 	struct virtchnl_version_info *pf_vvi;
69 	struct iavf_hw *hw = &adapter->hw;
70 	struct iavf_arq_event_info event;
71 	enum virtchnl_ops op;
72 	enum iavf_status err;
73 
74 	event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
75 	event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
76 	if (!event.msg_buf) {
77 		err = -ENOMEM;
78 		goto out;
79 	}
80 
81 	while (1) {
82 		err = iavf_clean_arq_element(hw, &event, NULL);
83 		/* When the AQ is empty, iavf_clean_arq_element will return
84 		 * nonzero and this loop will terminate.
85 		 */
86 		if (err)
87 			goto out_alloc;
88 		op =
89 		    (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
90 		if (op == VIRTCHNL_OP_VERSION)
91 			break;
92 	}
93 
94 
95 	err = (enum iavf_status)le32_to_cpu(event.desc.cookie_low);
96 	if (err)
97 		goto out_alloc;
98 
99 	if (op != VIRTCHNL_OP_VERSION) {
100 		dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n",
101 			op);
102 		err = -EIO;
103 		goto out_alloc;
104 	}
105 
106 	pf_vvi = (struct virtchnl_version_info *)event.msg_buf;
107 	adapter->pf_version = *pf_vvi;
108 
109 	if ((pf_vvi->major > VIRTCHNL_VERSION_MAJOR) ||
110 	    ((pf_vvi->major == VIRTCHNL_VERSION_MAJOR) &&
111 	     (pf_vvi->minor > VIRTCHNL_VERSION_MINOR)))
112 		err = -EIO;
113 
114 out_alloc:
115 	kfree(event.msg_buf);
116 out:
117 	return err;
118 }
119 
120 /**
121  * iavf_send_vf_config_msg
122  * @adapter: adapter structure
123  *
124  * Send VF configuration request admin queue message to the PF. The reply
125  * is not checked in this function. Returns 0 if the message was
126  * successfully sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
127  **/
128 int iavf_send_vf_config_msg(struct iavf_adapter *adapter)
129 {
130 	u32 caps;
131 
132 	caps = VIRTCHNL_VF_OFFLOAD_L2 |
133 	       VIRTCHNL_VF_OFFLOAD_RSS_PF |
134 	       VIRTCHNL_VF_OFFLOAD_RSS_AQ |
135 	       VIRTCHNL_VF_OFFLOAD_RSS_REG |
136 	       VIRTCHNL_VF_OFFLOAD_VLAN |
137 	       VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
138 	       VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
139 	       VIRTCHNL_VF_OFFLOAD_ENCAP |
140 	       VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM |
141 	       VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
142 	       VIRTCHNL_VF_OFFLOAD_ADQ;
143 
144 	adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
145 	adapter->aq_required &= ~IAVF_FLAG_AQ_GET_CONFIG;
146 	if (PF_IS_V11(adapter))
147 		return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
148 					(u8 *)&caps, sizeof(caps));
149 	else
150 		return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
151 					NULL, 0);
152 }
153 
154 /**
155  * iavf_validate_num_queues
156  * @adapter: adapter structure
157  *
158  * Validate that the number of queues the PF has sent in
159  * VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle.
160  **/
161 static void iavf_validate_num_queues(struct iavf_adapter *adapter)
162 {
163 	if (adapter->vf_res->num_queue_pairs > IAVF_MAX_REQ_QUEUES) {
164 		struct virtchnl_vsi_resource *vsi_res;
165 		int i;
166 
167 		dev_info(&adapter->pdev->dev, "Received %d queues, but can only have a max of %d\n",
168 			 adapter->vf_res->num_queue_pairs,
169 			 IAVF_MAX_REQ_QUEUES);
170 		dev_info(&adapter->pdev->dev, "Fixing by reducing queues to %d\n",
171 			 IAVF_MAX_REQ_QUEUES);
172 		adapter->vf_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
173 		for (i = 0; i < adapter->vf_res->num_vsis; i++) {
174 			vsi_res = &adapter->vf_res->vsi_res[i];
175 			vsi_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
176 		}
177 	}
178 }
179 
180 /**
181  * iavf_get_vf_config
182  * @adapter: private adapter structure
183  *
184  * Get VF configuration from PF and populate hw structure. Must be called after
185  * admin queue is initialized. Busy waits until response is received from PF,
186  * with maximum timeout. Response from PF is returned in the buffer for further
187  * processing by the caller.
188  **/
189 int iavf_get_vf_config(struct iavf_adapter *adapter)
190 {
191 	struct iavf_hw *hw = &adapter->hw;
192 	struct iavf_arq_event_info event;
193 	enum virtchnl_ops op;
194 	enum iavf_status err;
195 	u16 len;
196 
197 	len =  sizeof(struct virtchnl_vf_resource) +
198 		IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
199 	event.buf_len = len;
200 	event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
201 	if (!event.msg_buf) {
202 		err = -ENOMEM;
203 		goto out;
204 	}
205 
206 	while (1) {
207 		/* When the AQ is empty, iavf_clean_arq_element will return
208 		 * nonzero and this loop will terminate.
209 		 */
210 		err = iavf_clean_arq_element(hw, &event, NULL);
211 		if (err)
212 			goto out_alloc;
213 		op =
214 		    (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
215 		if (op == VIRTCHNL_OP_GET_VF_RESOURCES)
216 			break;
217 	}
218 
219 	err = (enum iavf_status)le32_to_cpu(event.desc.cookie_low);
220 	memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
221 
222 	/* some PFs send more queues than we should have so validate that
223 	 * we aren't getting too many queues
224 	 */
225 	if (!err)
226 		iavf_validate_num_queues(adapter);
227 	iavf_vf_parse_hw_config(hw, adapter->vf_res);
228 out_alloc:
229 	kfree(event.msg_buf);
230 out:
231 	return err;
232 }
233 
234 /**
235  * iavf_configure_queues
236  * @adapter: adapter structure
237  *
238  * Request that the PF set up our (previously allocated) queues.
239  **/
240 void iavf_configure_queues(struct iavf_adapter *adapter)
241 {
242 	struct virtchnl_vsi_queue_config_info *vqci;
243 	struct virtchnl_queue_pair_info *vqpi;
244 	int pairs = adapter->num_active_queues;
245 	int i, max_frame = IAVF_MAX_RXBUFFER;
246 	size_t len;
247 
248 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
249 		/* bail because we already have a command pending */
250 		dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
251 			adapter->current_op);
252 		return;
253 	}
254 	adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
255 	len = struct_size(vqci, qpair, pairs);
256 	vqci = kzalloc(len, GFP_KERNEL);
257 	if (!vqci)
258 		return;
259 
260 	/* Limit maximum frame size when jumbo frames is not enabled */
261 	if (!(adapter->flags & IAVF_FLAG_LEGACY_RX) &&
262 	    (adapter->netdev->mtu <= ETH_DATA_LEN))
263 		max_frame = IAVF_RXBUFFER_1536 - NET_IP_ALIGN;
264 
265 	vqci->vsi_id = adapter->vsi_res->vsi_id;
266 	vqci->num_queue_pairs = pairs;
267 	vqpi = vqci->qpair;
268 	/* Size check is not needed here - HW max is 16 queue pairs, and we
269 	 * can fit info for 31 of them into the AQ buffer before it overflows.
270 	 */
271 	for (i = 0; i < pairs; i++) {
272 		vqpi->txq.vsi_id = vqci->vsi_id;
273 		vqpi->txq.queue_id = i;
274 		vqpi->txq.ring_len = adapter->tx_rings[i].count;
275 		vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
276 		vqpi->rxq.vsi_id = vqci->vsi_id;
277 		vqpi->rxq.queue_id = i;
278 		vqpi->rxq.ring_len = adapter->rx_rings[i].count;
279 		vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
280 		vqpi->rxq.max_pkt_size = max_frame;
281 		vqpi->rxq.databuffer_size =
282 			ALIGN(adapter->rx_rings[i].rx_buf_len,
283 			      BIT_ULL(IAVF_RXQ_CTX_DBUFF_SHIFT));
284 		vqpi++;
285 	}
286 
287 	adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES;
288 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
289 			 (u8 *)vqci, len);
290 	kfree(vqci);
291 }
292 
293 /**
294  * iavf_enable_queues
295  * @adapter: adapter structure
296  *
297  * Request that the PF enable all of our queues.
298  **/
299 void iavf_enable_queues(struct iavf_adapter *adapter)
300 {
301 	struct virtchnl_queue_select vqs;
302 
303 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
304 		/* bail because we already have a command pending */
305 		dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
306 			adapter->current_op);
307 		return;
308 	}
309 	adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
310 	vqs.vsi_id = adapter->vsi_res->vsi_id;
311 	vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
312 	vqs.rx_queues = vqs.tx_queues;
313 	adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_QUEUES;
314 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
315 			 (u8 *)&vqs, sizeof(vqs));
316 }
317 
318 /**
319  * iavf_disable_queues
320  * @adapter: adapter structure
321  *
322  * Request that the PF disable all of our queues.
323  **/
324 void iavf_disable_queues(struct iavf_adapter *adapter)
325 {
326 	struct virtchnl_queue_select vqs;
327 
328 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
329 		/* bail because we already have a command pending */
330 		dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
331 			adapter->current_op);
332 		return;
333 	}
334 	adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
335 	vqs.vsi_id = adapter->vsi_res->vsi_id;
336 	vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
337 	vqs.rx_queues = vqs.tx_queues;
338 	adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_QUEUES;
339 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
340 			 (u8 *)&vqs, sizeof(vqs));
341 }
342 
343 /**
344  * iavf_map_queues
345  * @adapter: adapter structure
346  *
347  * Request that the PF map queues to interrupt vectors. Misc causes, including
348  * admin queue, are always mapped to vector 0.
349  **/
350 void iavf_map_queues(struct iavf_adapter *adapter)
351 {
352 	struct virtchnl_irq_map_info *vimi;
353 	struct virtchnl_vector_map *vecmap;
354 	struct iavf_q_vector *q_vector;
355 	int v_idx, q_vectors;
356 	size_t len;
357 
358 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
359 		/* bail because we already have a command pending */
360 		dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
361 			adapter->current_op);
362 		return;
363 	}
364 	adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
365 
366 	q_vectors = adapter->num_msix_vectors - NONQ_VECS;
367 
368 	len = struct_size(vimi, vecmap, adapter->num_msix_vectors);
369 	vimi = kzalloc(len, GFP_KERNEL);
370 	if (!vimi)
371 		return;
372 
373 	vimi->num_vectors = adapter->num_msix_vectors;
374 	/* Queue vectors first */
375 	for (v_idx = 0; v_idx < q_vectors; v_idx++) {
376 		q_vector = &adapter->q_vectors[v_idx];
377 		vecmap = &vimi->vecmap[v_idx];
378 
379 		vecmap->vsi_id = adapter->vsi_res->vsi_id;
380 		vecmap->vector_id = v_idx + NONQ_VECS;
381 		vecmap->txq_map = q_vector->ring_mask;
382 		vecmap->rxq_map = q_vector->ring_mask;
383 		vecmap->rxitr_idx = IAVF_RX_ITR;
384 		vecmap->txitr_idx = IAVF_TX_ITR;
385 	}
386 	/* Misc vector last - this is only for AdminQ messages */
387 	vecmap = &vimi->vecmap[v_idx];
388 	vecmap->vsi_id = adapter->vsi_res->vsi_id;
389 	vecmap->vector_id = 0;
390 	vecmap->txq_map = 0;
391 	vecmap->rxq_map = 0;
392 
393 	adapter->aq_required &= ~IAVF_FLAG_AQ_MAP_VECTORS;
394 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
395 			 (u8 *)vimi, len);
396 	kfree(vimi);
397 }
398 
399 /**
400  * iavf_add_ether_addrs
401  * @adapter: adapter structure
402  *
403  * Request that the PF add one or more addresses to our filters.
404  **/
405 void iavf_add_ether_addrs(struct iavf_adapter *adapter)
406 {
407 	struct virtchnl_ether_addr_list *veal;
408 	struct iavf_mac_filter *f;
409 	int i = 0, count = 0;
410 	bool more = false;
411 	size_t len;
412 
413 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
414 		/* bail because we already have a command pending */
415 		dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
416 			adapter->current_op);
417 		return;
418 	}
419 
420 	spin_lock_bh(&adapter->mac_vlan_list_lock);
421 
422 	list_for_each_entry(f, &adapter->mac_filter_list, list) {
423 		if (f->add)
424 			count++;
425 	}
426 	if (!count) {
427 		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
428 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
429 		return;
430 	}
431 	adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
432 
433 	len = struct_size(veal, list, count);
434 	if (len > IAVF_MAX_AQ_BUF_SIZE) {
435 		dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
436 		count = (IAVF_MAX_AQ_BUF_SIZE -
437 			 sizeof(struct virtchnl_ether_addr_list)) /
438 			sizeof(struct virtchnl_ether_addr);
439 		len = struct_size(veal, list, count);
440 		more = true;
441 	}
442 
443 	veal = kzalloc(len, GFP_ATOMIC);
444 	if (!veal) {
445 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
446 		return;
447 	}
448 
449 	veal->vsi_id = adapter->vsi_res->vsi_id;
450 	veal->num_elements = count;
451 	list_for_each_entry(f, &adapter->mac_filter_list, list) {
452 		if (f->add) {
453 			ether_addr_copy(veal->list[i].addr, f->macaddr);
454 			i++;
455 			f->add = false;
456 			if (i == count)
457 				break;
458 		}
459 	}
460 	if (!more)
461 		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
462 
463 	spin_unlock_bh(&adapter->mac_vlan_list_lock);
464 
465 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len);
466 	kfree(veal);
467 }
468 
469 /**
470  * iavf_del_ether_addrs
471  * @adapter: adapter structure
472  *
473  * Request that the PF remove one or more addresses from our filters.
474  **/
475 void iavf_del_ether_addrs(struct iavf_adapter *adapter)
476 {
477 	struct virtchnl_ether_addr_list *veal;
478 	struct iavf_mac_filter *f, *ftmp;
479 	int i = 0, count = 0;
480 	bool more = false;
481 	size_t len;
482 
483 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
484 		/* bail because we already have a command pending */
485 		dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
486 			adapter->current_op);
487 		return;
488 	}
489 
490 	spin_lock_bh(&adapter->mac_vlan_list_lock);
491 
492 	list_for_each_entry(f, &adapter->mac_filter_list, list) {
493 		if (f->remove)
494 			count++;
495 	}
496 	if (!count) {
497 		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
498 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
499 		return;
500 	}
501 	adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
502 
503 	len = struct_size(veal, list, count);
504 	if (len > IAVF_MAX_AQ_BUF_SIZE) {
505 		dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
506 		count = (IAVF_MAX_AQ_BUF_SIZE -
507 			 sizeof(struct virtchnl_ether_addr_list)) /
508 			sizeof(struct virtchnl_ether_addr);
509 		len = struct_size(veal, list, count);
510 		more = true;
511 	}
512 	veal = kzalloc(len, GFP_ATOMIC);
513 	if (!veal) {
514 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
515 		return;
516 	}
517 
518 	veal->vsi_id = adapter->vsi_res->vsi_id;
519 	veal->num_elements = count;
520 	list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
521 		if (f->remove) {
522 			ether_addr_copy(veal->list[i].addr, f->macaddr);
523 			i++;
524 			list_del(&f->list);
525 			kfree(f);
526 			if (i == count)
527 				break;
528 		}
529 	}
530 	if (!more)
531 		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
532 
533 	spin_unlock_bh(&adapter->mac_vlan_list_lock);
534 
535 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, (u8 *)veal, len);
536 	kfree(veal);
537 }
538 
539 /**
540  * iavf_add_vlans
541  * @adapter: adapter structure
542  *
543  * Request that the PF add one or more VLAN filters to our VSI.
544  **/
545 void iavf_add_vlans(struct iavf_adapter *adapter)
546 {
547 	struct virtchnl_vlan_filter_list *vvfl;
548 	int len, i = 0, count = 0;
549 	struct iavf_vlan_filter *f;
550 	bool more = false;
551 
552 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
553 		/* bail because we already have a command pending */
554 		dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
555 			adapter->current_op);
556 		return;
557 	}
558 
559 	spin_lock_bh(&adapter->mac_vlan_list_lock);
560 
561 	list_for_each_entry(f, &adapter->vlan_filter_list, list) {
562 		if (f->add)
563 			count++;
564 	}
565 	if (!count) {
566 		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
567 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
568 		return;
569 	}
570 	adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
571 
572 	len = sizeof(struct virtchnl_vlan_filter_list) +
573 	      (count * sizeof(u16));
574 	if (len > IAVF_MAX_AQ_BUF_SIZE) {
575 		dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
576 		count = (IAVF_MAX_AQ_BUF_SIZE -
577 			 sizeof(struct virtchnl_vlan_filter_list)) /
578 			sizeof(u16);
579 		len = sizeof(struct virtchnl_vlan_filter_list) +
580 		      (count * sizeof(u16));
581 		more = true;
582 	}
583 	vvfl = kzalloc(len, GFP_ATOMIC);
584 	if (!vvfl) {
585 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
586 		return;
587 	}
588 
589 	vvfl->vsi_id = adapter->vsi_res->vsi_id;
590 	vvfl->num_elements = count;
591 	list_for_each_entry(f, &adapter->vlan_filter_list, list) {
592 		if (f->add) {
593 			vvfl->vlan_id[i] = f->vlan;
594 			i++;
595 			f->add = false;
596 			if (i == count)
597 				break;
598 		}
599 	}
600 	if (!more)
601 		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
602 
603 	spin_unlock_bh(&adapter->mac_vlan_list_lock);
604 
605 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
606 	kfree(vvfl);
607 }
608 
609 /**
610  * iavf_del_vlans
611  * @adapter: adapter structure
612  *
613  * Request that the PF remove one or more VLAN filters from our VSI.
614  **/
615 void iavf_del_vlans(struct iavf_adapter *adapter)
616 {
617 	struct virtchnl_vlan_filter_list *vvfl;
618 	struct iavf_vlan_filter *f, *ftmp;
619 	int len, i = 0, count = 0;
620 	bool more = false;
621 
622 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
623 		/* bail because we already have a command pending */
624 		dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
625 			adapter->current_op);
626 		return;
627 	}
628 
629 	spin_lock_bh(&adapter->mac_vlan_list_lock);
630 
631 	list_for_each_entry(f, &adapter->vlan_filter_list, list) {
632 		if (f->remove)
633 			count++;
634 	}
635 	if (!count) {
636 		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
637 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
638 		return;
639 	}
640 	adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
641 
642 	len = sizeof(struct virtchnl_vlan_filter_list) +
643 	      (count * sizeof(u16));
644 	if (len > IAVF_MAX_AQ_BUF_SIZE) {
645 		dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
646 		count = (IAVF_MAX_AQ_BUF_SIZE -
647 			 sizeof(struct virtchnl_vlan_filter_list)) /
648 			sizeof(u16);
649 		len = sizeof(struct virtchnl_vlan_filter_list) +
650 		      (count * sizeof(u16));
651 		more = true;
652 	}
653 	vvfl = kzalloc(len, GFP_ATOMIC);
654 	if (!vvfl) {
655 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
656 		return;
657 	}
658 
659 	vvfl->vsi_id = adapter->vsi_res->vsi_id;
660 	vvfl->num_elements = count;
661 	list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
662 		if (f->remove) {
663 			vvfl->vlan_id[i] = f->vlan;
664 			i++;
665 			list_del(&f->list);
666 			kfree(f);
667 			if (i == count)
668 				break;
669 		}
670 	}
671 	if (!more)
672 		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
673 
674 	spin_unlock_bh(&adapter->mac_vlan_list_lock);
675 
676 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
677 	kfree(vvfl);
678 }
679 
680 /**
681  * iavf_set_promiscuous
682  * @adapter: adapter structure
683  * @flags: bitmask to control unicast/multicast promiscuous.
684  *
685  * Request that the PF enable promiscuous mode for our VSI.
686  **/
687 void iavf_set_promiscuous(struct iavf_adapter *adapter, int flags)
688 {
689 	struct virtchnl_promisc_info vpi;
690 	int promisc_all;
691 
692 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
693 		/* bail because we already have a command pending */
694 		dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
695 			adapter->current_op);
696 		return;
697 	}
698 
699 	promisc_all = FLAG_VF_UNICAST_PROMISC |
700 		      FLAG_VF_MULTICAST_PROMISC;
701 	if ((flags & promisc_all) == promisc_all) {
702 		adapter->flags |= IAVF_FLAG_PROMISC_ON;
703 		adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_PROMISC;
704 		dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
705 	}
706 
707 	if (flags & FLAG_VF_MULTICAST_PROMISC) {
708 		adapter->flags |= IAVF_FLAG_ALLMULTI_ON;
709 		adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_ALLMULTI;
710 		dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
711 	}
712 
713 	if (!flags) {
714 		adapter->flags &= ~(IAVF_FLAG_PROMISC_ON |
715 				    IAVF_FLAG_ALLMULTI_ON);
716 		adapter->aq_required &= ~(IAVF_FLAG_AQ_RELEASE_PROMISC |
717 					  IAVF_FLAG_AQ_RELEASE_ALLMULTI);
718 		dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
719 	}
720 
721 	adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
722 	vpi.vsi_id = adapter->vsi_res->vsi_id;
723 	vpi.flags = flags;
724 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
725 			 (u8 *)&vpi, sizeof(vpi));
726 }
727 
728 /**
729  * iavf_request_stats
730  * @adapter: adapter structure
731  *
732  * Request VSI statistics from PF.
733  **/
734 void iavf_request_stats(struct iavf_adapter *adapter)
735 {
736 	struct virtchnl_queue_select vqs;
737 
738 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
739 		/* no error message, this isn't crucial */
740 		return;
741 	}
742 	adapter->current_op = VIRTCHNL_OP_GET_STATS;
743 	vqs.vsi_id = adapter->vsi_res->vsi_id;
744 	/* queue maps are ignored for this message - only the vsi is used */
745 	if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs,
746 			     sizeof(vqs)))
747 		/* if the request failed, don't lock out others */
748 		adapter->current_op = VIRTCHNL_OP_UNKNOWN;
749 }
750 
751 /**
752  * iavf_get_hena
753  * @adapter: adapter structure
754  *
755  * Request hash enable capabilities from PF
756  **/
757 void iavf_get_hena(struct iavf_adapter *adapter)
758 {
759 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
760 		/* bail because we already have a command pending */
761 		dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
762 			adapter->current_op);
763 		return;
764 	}
765 	adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
766 	adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA;
767 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0);
768 }
769 
770 /**
771  * iavf_set_hena
772  * @adapter: adapter structure
773  *
774  * Request the PF to set our RSS hash capabilities
775  **/
776 void iavf_set_hena(struct iavf_adapter *adapter)
777 {
778 	struct virtchnl_rss_hena vrh;
779 
780 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
781 		/* bail because we already have a command pending */
782 		dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
783 			adapter->current_op);
784 		return;
785 	}
786 	vrh.hena = adapter->hena;
787 	adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
788 	adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA;
789 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh,
790 			 sizeof(vrh));
791 }
792 
793 /**
794  * iavf_set_rss_key
795  * @adapter: adapter structure
796  *
797  * Request the PF to set our RSS hash key
798  **/
799 void iavf_set_rss_key(struct iavf_adapter *adapter)
800 {
801 	struct virtchnl_rss_key *vrk;
802 	int len;
803 
804 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
805 		/* bail because we already have a command pending */
806 		dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
807 			adapter->current_op);
808 		return;
809 	}
810 	len = sizeof(struct virtchnl_rss_key) +
811 	      (adapter->rss_key_size * sizeof(u8)) - 1;
812 	vrk = kzalloc(len, GFP_KERNEL);
813 	if (!vrk)
814 		return;
815 	vrk->vsi_id = adapter->vsi.id;
816 	vrk->key_len = adapter->rss_key_size;
817 	memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
818 
819 	adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
820 	adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY;
821 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len);
822 	kfree(vrk);
823 }
824 
825 /**
826  * iavf_set_rss_lut
827  * @adapter: adapter structure
828  *
829  * Request the PF to set our RSS lookup table
830  **/
831 void iavf_set_rss_lut(struct iavf_adapter *adapter)
832 {
833 	struct virtchnl_rss_lut *vrl;
834 	int len;
835 
836 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
837 		/* bail because we already have a command pending */
838 		dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
839 			adapter->current_op);
840 		return;
841 	}
842 	len = sizeof(struct virtchnl_rss_lut) +
843 	      (adapter->rss_lut_size * sizeof(u8)) - 1;
844 	vrl = kzalloc(len, GFP_KERNEL);
845 	if (!vrl)
846 		return;
847 	vrl->vsi_id = adapter->vsi.id;
848 	vrl->lut_entries = adapter->rss_lut_size;
849 	memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
850 	adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
851 	adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT;
852 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len);
853 	kfree(vrl);
854 }
855 
856 /**
857  * iavf_enable_vlan_stripping
858  * @adapter: adapter structure
859  *
860  * Request VLAN header stripping to be enabled
861  **/
862 void iavf_enable_vlan_stripping(struct iavf_adapter *adapter)
863 {
864 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
865 		/* bail because we already have a command pending */
866 		dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
867 			adapter->current_op);
868 		return;
869 	}
870 	adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
871 	adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
872 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0);
873 }
874 
875 /**
876  * iavf_disable_vlan_stripping
877  * @adapter: adapter structure
878  *
879  * Request VLAN header stripping to be disabled
880  **/
881 void iavf_disable_vlan_stripping(struct iavf_adapter *adapter)
882 {
883 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
884 		/* bail because we already have a command pending */
885 		dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
886 			adapter->current_op);
887 		return;
888 	}
889 	adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
890 	adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
891 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0);
892 }
893 
894 /**
895  * iavf_print_link_message - print link up or down
896  * @adapter: adapter structure
897  *
898  * Log a message telling the world of our wonderous link status
899  */
900 static void iavf_print_link_message(struct iavf_adapter *adapter)
901 {
902 	struct net_device *netdev = adapter->netdev;
903 	char *speed = "Unknown ";
904 
905 	if (!adapter->link_up) {
906 		netdev_info(netdev, "NIC Link is Down\n");
907 		return;
908 	}
909 
910 	switch (adapter->link_speed) {
911 	case IAVF_LINK_SPEED_40GB:
912 		speed = "40 G";
913 		break;
914 	case IAVF_LINK_SPEED_25GB:
915 		speed = "25 G";
916 		break;
917 	case IAVF_LINK_SPEED_20GB:
918 		speed = "20 G";
919 		break;
920 	case IAVF_LINK_SPEED_10GB:
921 		speed = "10 G";
922 		break;
923 	case IAVF_LINK_SPEED_1GB:
924 		speed = "1000 M";
925 		break;
926 	case IAVF_LINK_SPEED_100MB:
927 		speed = "100 M";
928 		break;
929 	default:
930 		break;
931 	}
932 
933 	netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
934 }
935 
936 /**
937  * iavf_enable_channel
938  * @adapter: adapter structure
939  *
940  * Request that the PF enable channels as specified by
941  * the user via tc tool.
942  **/
943 void iavf_enable_channels(struct iavf_adapter *adapter)
944 {
945 	struct virtchnl_tc_info *vti = NULL;
946 	size_t len;
947 	int i;
948 
949 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
950 		/* bail because we already have a command pending */
951 		dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
952 			adapter->current_op);
953 		return;
954 	}
955 
956 	len = struct_size(vti, list, adapter->num_tc - 1);
957 	vti = kzalloc(len, GFP_KERNEL);
958 	if (!vti)
959 		return;
960 	vti->num_tc = adapter->num_tc;
961 	for (i = 0; i < vti->num_tc; i++) {
962 		vti->list[i].count = adapter->ch_config.ch_info[i].count;
963 		vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
964 		vti->list[i].pad = 0;
965 		vti->list[i].max_tx_rate =
966 				adapter->ch_config.ch_info[i].max_tx_rate;
967 	}
968 
969 	adapter->ch_config.state = __IAVF_TC_RUNNING;
970 	adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
971 	adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
972 	adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS;
973 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len);
974 	kfree(vti);
975 }
976 
977 /**
978  * iavf_disable_channel
979  * @adapter: adapter structure
980  *
981  * Request that the PF disable channels that are configured
982  **/
983 void iavf_disable_channels(struct iavf_adapter *adapter)
984 {
985 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
986 		/* bail because we already have a command pending */
987 		dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
988 			adapter->current_op);
989 		return;
990 	}
991 
992 	adapter->ch_config.state = __IAVF_TC_INVALID;
993 	adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
994 	adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
995 	adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS;
996 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0);
997 }
998 
999 /**
1000  * iavf_print_cloud_filter
1001  * @adapter: adapter structure
1002  * @f: cloud filter to print
1003  *
1004  * Print the cloud filter
1005  **/
1006 static void iavf_print_cloud_filter(struct iavf_adapter *adapter,
1007 				    struct virtchnl_filter *f)
1008 {
1009 	switch (f->flow_type) {
1010 	case VIRTCHNL_TCP_V4_FLOW:
1011 		dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI4 src_ip %pI4 dst_port %hu src_port %hu\n",
1012 			 &f->data.tcp_spec.dst_mac,
1013 			 &f->data.tcp_spec.src_mac,
1014 			 ntohs(f->data.tcp_spec.vlan_id),
1015 			 &f->data.tcp_spec.dst_ip[0],
1016 			 &f->data.tcp_spec.src_ip[0],
1017 			 ntohs(f->data.tcp_spec.dst_port),
1018 			 ntohs(f->data.tcp_spec.src_port));
1019 		break;
1020 	case VIRTCHNL_TCP_V6_FLOW:
1021 		dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI6 src_ip %pI6 dst_port %hu src_port %hu\n",
1022 			 &f->data.tcp_spec.dst_mac,
1023 			 &f->data.tcp_spec.src_mac,
1024 			 ntohs(f->data.tcp_spec.vlan_id),
1025 			 &f->data.tcp_spec.dst_ip,
1026 			 &f->data.tcp_spec.src_ip,
1027 			 ntohs(f->data.tcp_spec.dst_port),
1028 			 ntohs(f->data.tcp_spec.src_port));
1029 		break;
1030 	}
1031 }
1032 
1033 /**
1034  * iavf_add_cloud_filter
1035  * @adapter: adapter structure
1036  *
1037  * Request that the PF add cloud filters as specified
1038  * by the user via tc tool.
1039  **/
1040 void iavf_add_cloud_filter(struct iavf_adapter *adapter)
1041 {
1042 	struct iavf_cloud_filter *cf;
1043 	struct virtchnl_filter *f;
1044 	int len = 0, count = 0;
1045 
1046 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1047 		/* bail because we already have a command pending */
1048 		dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1049 			adapter->current_op);
1050 		return;
1051 	}
1052 	list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1053 		if (cf->add) {
1054 			count++;
1055 			break;
1056 		}
1057 	}
1058 	if (!count) {
1059 		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER;
1060 		return;
1061 	}
1062 	adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1063 
1064 	len = sizeof(struct virtchnl_filter);
1065 	f = kzalloc(len, GFP_KERNEL);
1066 	if (!f)
1067 		return;
1068 
1069 	list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1070 		if (cf->add) {
1071 			memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1072 			cf->add = false;
1073 			cf->state = __IAVF_CF_ADD_PENDING;
1074 			iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER,
1075 					 (u8 *)f, len);
1076 		}
1077 	}
1078 	kfree(f);
1079 }
1080 
1081 /**
1082  * iavf_del_cloud_filter
1083  * @adapter: adapter structure
1084  *
1085  * Request that the PF delete cloud filters as specified
1086  * by the user via tc tool.
1087  **/
1088 void iavf_del_cloud_filter(struct iavf_adapter *adapter)
1089 {
1090 	struct iavf_cloud_filter *cf, *cftmp;
1091 	struct virtchnl_filter *f;
1092 	int len = 0, count = 0;
1093 
1094 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1095 		/* bail because we already have a command pending */
1096 		dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1097 			adapter->current_op);
1098 		return;
1099 	}
1100 	list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1101 		if (cf->del) {
1102 			count++;
1103 			break;
1104 		}
1105 	}
1106 	if (!count) {
1107 		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER;
1108 		return;
1109 	}
1110 	adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1111 
1112 	len = sizeof(struct virtchnl_filter);
1113 	f = kzalloc(len, GFP_KERNEL);
1114 	if (!f)
1115 		return;
1116 
1117 	list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1118 		if (cf->del) {
1119 			memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1120 			cf->del = false;
1121 			cf->state = __IAVF_CF_DEL_PENDING;
1122 			iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER,
1123 					 (u8 *)f, len);
1124 		}
1125 	}
1126 	kfree(f);
1127 }
1128 
1129 /**
1130  * iavf_request_reset
1131  * @adapter: adapter structure
1132  *
1133  * Request that the PF reset this VF. No response is expected.
1134  **/
1135 void iavf_request_reset(struct iavf_adapter *adapter)
1136 {
1137 	/* Don't check CURRENT_OP - this is always higher priority */
1138 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
1139 	adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1140 }
1141 
1142 /**
1143  * iavf_virtchnl_completion
1144  * @adapter: adapter structure
1145  * @v_opcode: opcode sent by PF
1146  * @v_retval: retval sent by PF
1147  * @msg: message sent by PF
1148  * @msglen: message length
1149  *
1150  * Asynchronous completion function for admin queue messages. Rather than busy
1151  * wait, we fire off our requests and assume that no errors will be returned.
1152  * This function handles the reply messages.
1153  **/
1154 void iavf_virtchnl_completion(struct iavf_adapter *adapter,
1155 			      enum virtchnl_ops v_opcode,
1156 			      enum iavf_status v_retval, u8 *msg, u16 msglen)
1157 {
1158 	struct net_device *netdev = adapter->netdev;
1159 
1160 	if (v_opcode == VIRTCHNL_OP_EVENT) {
1161 		struct virtchnl_pf_event *vpe =
1162 			(struct virtchnl_pf_event *)msg;
1163 		bool link_up = vpe->event_data.link_event.link_status;
1164 
1165 		switch (vpe->event) {
1166 		case VIRTCHNL_EVENT_LINK_CHANGE:
1167 			adapter->link_speed =
1168 				vpe->event_data.link_event.link_speed;
1169 
1170 			/* we've already got the right link status, bail */
1171 			if (adapter->link_up == link_up)
1172 				break;
1173 
1174 			if (link_up) {
1175 				/* If we get link up message and start queues
1176 				 * before our queues are configured it will
1177 				 * trigger a TX hang. In that case, just ignore
1178 				 * the link status message,we'll get another one
1179 				 * after we enable queues and actually prepared
1180 				 * to send traffic.
1181 				 */
1182 				if (adapter->state != __IAVF_RUNNING)
1183 					break;
1184 
1185 				/* For ADq enabled VF, we reconfigure VSIs and
1186 				 * re-allocate queues. Hence wait till all
1187 				 * queues are enabled.
1188 				 */
1189 				if (adapter->flags &
1190 				    IAVF_FLAG_QUEUES_DISABLED)
1191 					break;
1192 			}
1193 
1194 			adapter->link_up = link_up;
1195 			if (link_up) {
1196 				netif_tx_start_all_queues(netdev);
1197 				netif_carrier_on(netdev);
1198 			} else {
1199 				netif_tx_stop_all_queues(netdev);
1200 				netif_carrier_off(netdev);
1201 			}
1202 			iavf_print_link_message(adapter);
1203 			break;
1204 		case VIRTCHNL_EVENT_RESET_IMPENDING:
1205 			dev_info(&adapter->pdev->dev, "Reset warning received from the PF\n");
1206 			if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) {
1207 				adapter->flags |= IAVF_FLAG_RESET_PENDING;
1208 				dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
1209 				queue_work(iavf_wq, &adapter->reset_task);
1210 			}
1211 			break;
1212 		default:
1213 			dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
1214 				vpe->event);
1215 			break;
1216 		}
1217 		return;
1218 	}
1219 	if (v_retval) {
1220 		switch (v_opcode) {
1221 		case VIRTCHNL_OP_ADD_VLAN:
1222 			dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
1223 				iavf_stat_str(&adapter->hw, v_retval));
1224 			break;
1225 		case VIRTCHNL_OP_ADD_ETH_ADDR:
1226 			dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
1227 				iavf_stat_str(&adapter->hw, v_retval));
1228 			/* restore administratively set MAC address */
1229 			ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1230 			break;
1231 		case VIRTCHNL_OP_DEL_VLAN:
1232 			dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1233 				iavf_stat_str(&adapter->hw, v_retval));
1234 			break;
1235 		case VIRTCHNL_OP_DEL_ETH_ADDR:
1236 			dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1237 				iavf_stat_str(&adapter->hw, v_retval));
1238 			break;
1239 		case VIRTCHNL_OP_ENABLE_CHANNELS:
1240 			dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
1241 				iavf_stat_str(&adapter->hw, v_retval));
1242 			adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1243 			adapter->ch_config.state = __IAVF_TC_INVALID;
1244 			netdev_reset_tc(netdev);
1245 			netif_tx_start_all_queues(netdev);
1246 			break;
1247 		case VIRTCHNL_OP_DISABLE_CHANNELS:
1248 			dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
1249 				iavf_stat_str(&adapter->hw, v_retval));
1250 			adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1251 			adapter->ch_config.state = __IAVF_TC_RUNNING;
1252 			netif_tx_start_all_queues(netdev);
1253 			break;
1254 		case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
1255 			struct iavf_cloud_filter *cf, *cftmp;
1256 
1257 			list_for_each_entry_safe(cf, cftmp,
1258 						 &adapter->cloud_filter_list,
1259 						 list) {
1260 				if (cf->state == __IAVF_CF_ADD_PENDING) {
1261 					cf->state = __IAVF_CF_INVALID;
1262 					dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
1263 						 iavf_stat_str(&adapter->hw,
1264 							       v_retval));
1265 					iavf_print_cloud_filter(adapter,
1266 								&cf->f);
1267 					list_del(&cf->list);
1268 					kfree(cf);
1269 					adapter->num_cloud_filters--;
1270 				}
1271 			}
1272 			}
1273 			break;
1274 		case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
1275 			struct iavf_cloud_filter *cf;
1276 
1277 			list_for_each_entry(cf, &adapter->cloud_filter_list,
1278 					    list) {
1279 				if (cf->state == __IAVF_CF_DEL_PENDING) {
1280 					cf->state = __IAVF_CF_ACTIVE;
1281 					dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
1282 						 iavf_stat_str(&adapter->hw,
1283 							       v_retval));
1284 					iavf_print_cloud_filter(adapter,
1285 								&cf->f);
1286 				}
1287 			}
1288 			}
1289 			break;
1290 		default:
1291 			dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
1292 				v_retval, iavf_stat_str(&adapter->hw, v_retval),
1293 				v_opcode);
1294 		}
1295 	}
1296 	switch (v_opcode) {
1297 	case VIRTCHNL_OP_ADD_ETH_ADDR: {
1298 		if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr))
1299 			ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
1300 		}
1301 		break;
1302 	case VIRTCHNL_OP_GET_STATS: {
1303 		struct iavf_eth_stats *stats =
1304 			(struct iavf_eth_stats *)msg;
1305 		netdev->stats.rx_packets = stats->rx_unicast +
1306 					   stats->rx_multicast +
1307 					   stats->rx_broadcast;
1308 		netdev->stats.tx_packets = stats->tx_unicast +
1309 					   stats->tx_multicast +
1310 					   stats->tx_broadcast;
1311 		netdev->stats.rx_bytes = stats->rx_bytes;
1312 		netdev->stats.tx_bytes = stats->tx_bytes;
1313 		netdev->stats.tx_errors = stats->tx_errors;
1314 		netdev->stats.rx_dropped = stats->rx_discards;
1315 		netdev->stats.tx_dropped = stats->tx_discards;
1316 		adapter->current_stats = *stats;
1317 		}
1318 		break;
1319 	case VIRTCHNL_OP_GET_VF_RESOURCES: {
1320 		u16 len = sizeof(struct virtchnl_vf_resource) +
1321 			  IAVF_MAX_VF_VSI *
1322 			  sizeof(struct virtchnl_vsi_resource);
1323 		memcpy(adapter->vf_res, msg, min(msglen, len));
1324 		iavf_validate_num_queues(adapter);
1325 		iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
1326 		if (is_zero_ether_addr(adapter->hw.mac.addr)) {
1327 			/* restore current mac address */
1328 			ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1329 		} else {
1330 			/* refresh current mac address if changed */
1331 			ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
1332 			ether_addr_copy(netdev->perm_addr,
1333 					adapter->hw.mac.addr);
1334 		}
1335 		spin_lock_bh(&adapter->mac_vlan_list_lock);
1336 		iavf_add_filter(adapter, adapter->hw.mac.addr);
1337 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
1338 		iavf_process_config(adapter);
1339 		}
1340 		break;
1341 	case VIRTCHNL_OP_ENABLE_QUEUES:
1342 		/* enable transmits */
1343 		iavf_irq_enable(adapter, true);
1344 		adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED;
1345 		break;
1346 	case VIRTCHNL_OP_DISABLE_QUEUES:
1347 		iavf_free_all_tx_resources(adapter);
1348 		iavf_free_all_rx_resources(adapter);
1349 		if (adapter->state == __IAVF_DOWN_PENDING) {
1350 			adapter->state = __IAVF_DOWN;
1351 			wake_up(&adapter->down_waitqueue);
1352 		}
1353 		break;
1354 	case VIRTCHNL_OP_VERSION:
1355 	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1356 		/* Don't display an error if we get these out of sequence.
1357 		 * If the firmware needed to get kicked, we'll get these and
1358 		 * it's no problem.
1359 		 */
1360 		if (v_opcode != adapter->current_op)
1361 			return;
1362 		break;
1363 	case VIRTCHNL_OP_IWARP:
1364 		/* Gobble zero-length replies from the PF. They indicate that
1365 		 * a previous message was received OK, and the client doesn't
1366 		 * care about that.
1367 		 */
1368 		if (msglen && CLIENT_ENABLED(adapter))
1369 			iavf_notify_client_message(&adapter->vsi, msg, msglen);
1370 		break;
1371 
1372 	case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
1373 		adapter->client_pending &=
1374 				~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
1375 		break;
1376 	case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
1377 		struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
1378 
1379 		if (msglen == sizeof(*vrh))
1380 			adapter->hena = vrh->hena;
1381 		else
1382 			dev_warn(&adapter->pdev->dev,
1383 				 "Invalid message %d from PF\n", v_opcode);
1384 		}
1385 		break;
1386 	case VIRTCHNL_OP_REQUEST_QUEUES: {
1387 		struct virtchnl_vf_res_request *vfres =
1388 			(struct virtchnl_vf_res_request *)msg;
1389 
1390 		if (vfres->num_queue_pairs != adapter->num_req_queues) {
1391 			dev_info(&adapter->pdev->dev,
1392 				 "Requested %d queues, PF can support %d\n",
1393 				 adapter->num_req_queues,
1394 				 vfres->num_queue_pairs);
1395 			adapter->num_req_queues = 0;
1396 			adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1397 		}
1398 		}
1399 		break;
1400 	case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
1401 		struct iavf_cloud_filter *cf;
1402 
1403 		list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1404 			if (cf->state == __IAVF_CF_ADD_PENDING)
1405 				cf->state = __IAVF_CF_ACTIVE;
1406 		}
1407 		}
1408 		break;
1409 	case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
1410 		struct iavf_cloud_filter *cf, *cftmp;
1411 
1412 		list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
1413 					 list) {
1414 			if (cf->state == __IAVF_CF_DEL_PENDING) {
1415 				cf->state = __IAVF_CF_INVALID;
1416 				list_del(&cf->list);
1417 				kfree(cf);
1418 				adapter->num_cloud_filters--;
1419 			}
1420 		}
1421 		}
1422 		break;
1423 	default:
1424 		if (adapter->current_op && (v_opcode != adapter->current_op))
1425 			dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
1426 				 adapter->current_op, v_opcode);
1427 		break;
1428 	} /* switch v_opcode */
1429 	adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1430 }
1431