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 /**
9  * iavf_send_pf_msg
10  * @adapter: adapter structure
11  * @op: virtual channel opcode
12  * @msg: pointer to message buffer
13  * @len: message length
14  *
15  * Send message to PF and print status if failure.
16  **/
17 static int iavf_send_pf_msg(struct iavf_adapter *adapter,
18 			    enum virtchnl_ops op, u8 *msg, u16 len)
19 {
20 	struct iavf_hw *hw = &adapter->hw;
21 	enum iavf_status status;
22 
23 	if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)
24 		return 0; /* nothing to see here, move along */
25 
26 	status = iavf_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
27 	if (status)
28 		dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, status %s, aq_err %s\n",
29 			op, iavf_stat_str(hw, status),
30 			iavf_aq_str(hw, hw->aq.asq_last_status));
31 	return iavf_status_to_errno(status);
32 }
33 
34 /**
35  * iavf_send_api_ver
36  * @adapter: adapter structure
37  *
38  * Send API version admin queue message to the PF. The reply is not checked
39  * in this function. Returns 0 if the message was successfully
40  * sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
41  **/
42 int iavf_send_api_ver(struct iavf_adapter *adapter)
43 {
44 	struct virtchnl_version_info vvi;
45 
46 	vvi.major = VIRTCHNL_VERSION_MAJOR;
47 	vvi.minor = VIRTCHNL_VERSION_MINOR;
48 
49 	return iavf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
50 				sizeof(vvi));
51 }
52 
53 /**
54  * iavf_poll_virtchnl_msg
55  * @hw: HW configuration structure
56  * @event: event to populate on success
57  * @op_to_poll: requested virtchnl op to poll for
58  *
59  * Initialize poll for virtchnl msg matching the requested_op. Returns 0
60  * if a message of the correct opcode is in the queue or an error code
61  * if no message matching the op code is waiting and other failures.
62  */
63 static int
64 iavf_poll_virtchnl_msg(struct iavf_hw *hw, struct iavf_arq_event_info *event,
65 		       enum virtchnl_ops op_to_poll)
66 {
67 	enum virtchnl_ops received_op;
68 	enum iavf_status status;
69 	u32 v_retval;
70 
71 	while (1) {
72 		/* When the AQ is empty, iavf_clean_arq_element will return
73 		 * nonzero and this loop will terminate.
74 		 */
75 		status = iavf_clean_arq_element(hw, event, NULL);
76 		if (status != IAVF_SUCCESS)
77 			return iavf_status_to_errno(status);
78 		received_op =
79 		    (enum virtchnl_ops)le32_to_cpu(event->desc.cookie_high);
80 		if (op_to_poll == received_op)
81 			break;
82 	}
83 
84 	v_retval = le32_to_cpu(event->desc.cookie_low);
85 	return virtchnl_status_to_errno((enum virtchnl_status_code)v_retval);
86 }
87 
88 /**
89  * iavf_verify_api_ver
90  * @adapter: adapter structure
91  *
92  * Compare API versions with the PF. Must be called after admin queue is
93  * initialized. Returns 0 if API versions match, -EIO if they do not,
94  * IAVF_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
95  * from the firmware are propagated.
96  **/
97 int iavf_verify_api_ver(struct iavf_adapter *adapter)
98 {
99 	struct iavf_arq_event_info event;
100 	int err;
101 
102 	event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
103 	event.msg_buf = kzalloc(IAVF_MAX_AQ_BUF_SIZE, GFP_KERNEL);
104 	if (!event.msg_buf)
105 		return -ENOMEM;
106 
107 	err = iavf_poll_virtchnl_msg(&adapter->hw, &event, VIRTCHNL_OP_VERSION);
108 	if (!err) {
109 		struct virtchnl_version_info *pf_vvi =
110 			(struct virtchnl_version_info *)event.msg_buf;
111 		adapter->pf_version = *pf_vvi;
112 
113 		if (pf_vvi->major > VIRTCHNL_VERSION_MAJOR ||
114 		    (pf_vvi->major == VIRTCHNL_VERSION_MAJOR &&
115 		     pf_vvi->minor > VIRTCHNL_VERSION_MINOR))
116 			err = -EIO;
117 	}
118 
119 	kfree(event.msg_buf);
120 
121 	return err;
122 }
123 
124 /**
125  * iavf_send_vf_config_msg
126  * @adapter: adapter structure
127  *
128  * Send VF configuration request admin queue message to the PF. The reply
129  * is not checked in this function. Returns 0 if the message was
130  * successfully sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
131  **/
132 int iavf_send_vf_config_msg(struct iavf_adapter *adapter)
133 {
134 	u32 caps;
135 
136 	caps = VIRTCHNL_VF_OFFLOAD_L2 |
137 	       VIRTCHNL_VF_OFFLOAD_RSS_PF |
138 	       VIRTCHNL_VF_OFFLOAD_RSS_AQ |
139 	       VIRTCHNL_VF_OFFLOAD_RSS_REG |
140 	       VIRTCHNL_VF_OFFLOAD_VLAN |
141 	       VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
142 	       VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
143 	       VIRTCHNL_VF_OFFLOAD_ENCAP |
144 	       VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
145 	       VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM |
146 	       VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
147 	       VIRTCHNL_VF_OFFLOAD_ADQ |
148 	       VIRTCHNL_VF_OFFLOAD_USO |
149 	       VIRTCHNL_VF_OFFLOAD_FDIR_PF |
150 	       VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
151 	       VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
152 
153 	adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
154 	adapter->aq_required &= ~IAVF_FLAG_AQ_GET_CONFIG;
155 	if (PF_IS_V11(adapter))
156 		return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
157 					(u8 *)&caps, sizeof(caps));
158 	else
159 		return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
160 					NULL, 0);
161 }
162 
163 int iavf_send_vf_offload_vlan_v2_msg(struct iavf_adapter *adapter)
164 {
165 	adapter->aq_required &= ~IAVF_FLAG_AQ_GET_OFFLOAD_VLAN_V2_CAPS;
166 
167 	if (!VLAN_V2_ALLOWED(adapter))
168 		return -EOPNOTSUPP;
169 
170 	adapter->current_op = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
171 
172 	return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
173 				NULL, 0);
174 }
175 
176 /**
177  * iavf_validate_num_queues
178  * @adapter: adapter structure
179  *
180  * Validate that the number of queues the PF has sent in
181  * VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle.
182  **/
183 static void iavf_validate_num_queues(struct iavf_adapter *adapter)
184 {
185 	if (adapter->vf_res->num_queue_pairs > IAVF_MAX_REQ_QUEUES) {
186 		struct virtchnl_vsi_resource *vsi_res;
187 		int i;
188 
189 		dev_info(&adapter->pdev->dev, "Received %d queues, but can only have a max of %d\n",
190 			 adapter->vf_res->num_queue_pairs,
191 			 IAVF_MAX_REQ_QUEUES);
192 		dev_info(&adapter->pdev->dev, "Fixing by reducing queues to %d\n",
193 			 IAVF_MAX_REQ_QUEUES);
194 		adapter->vf_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
195 		for (i = 0; i < adapter->vf_res->num_vsis; i++) {
196 			vsi_res = &adapter->vf_res->vsi_res[i];
197 			vsi_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
198 		}
199 	}
200 }
201 
202 /**
203  * iavf_get_vf_config
204  * @adapter: private adapter structure
205  *
206  * Get VF configuration from PF and populate hw structure. Must be called after
207  * admin queue is initialized. Busy waits until response is received from PF,
208  * with maximum timeout. Response from PF is returned in the buffer for further
209  * processing by the caller.
210  **/
211 int iavf_get_vf_config(struct iavf_adapter *adapter)
212 {
213 	struct iavf_hw *hw = &adapter->hw;
214 	struct iavf_arq_event_info event;
215 	u16 len;
216 	int err;
217 
218 	len = sizeof(struct virtchnl_vf_resource) +
219 		IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
220 	event.buf_len = len;
221 	event.msg_buf = kzalloc(len, GFP_KERNEL);
222 	if (!event.msg_buf)
223 		return -ENOMEM;
224 
225 	err = iavf_poll_virtchnl_msg(hw, &event, VIRTCHNL_OP_GET_VF_RESOURCES);
226 	memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
227 
228 	/* some PFs send more queues than we should have so validate that
229 	 * we aren't getting too many queues
230 	 */
231 	if (!err)
232 		iavf_validate_num_queues(adapter);
233 	iavf_vf_parse_hw_config(hw, adapter->vf_res);
234 
235 	kfree(event.msg_buf);
236 
237 	return err;
238 }
239 
240 int iavf_get_vf_vlan_v2_caps(struct iavf_adapter *adapter)
241 {
242 	struct iavf_arq_event_info event;
243 	int err;
244 	u16 len;
245 
246 	len = sizeof(struct virtchnl_vlan_caps);
247 	event.buf_len = len;
248 	event.msg_buf = kzalloc(len, GFP_KERNEL);
249 	if (!event.msg_buf)
250 		return -ENOMEM;
251 
252 	err = iavf_poll_virtchnl_msg(&adapter->hw, &event,
253 				     VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS);
254 	if (!err)
255 		memcpy(&adapter->vlan_v2_caps, event.msg_buf,
256 		       min(event.msg_len, len));
257 
258 	kfree(event.msg_buf);
259 
260 	return err;
261 }
262 
263 /**
264  * iavf_configure_queues
265  * @adapter: adapter structure
266  *
267  * Request that the PF set up our (previously allocated) queues.
268  **/
269 void iavf_configure_queues(struct iavf_adapter *adapter)
270 {
271 	struct virtchnl_vsi_queue_config_info *vqci;
272 	int i, max_frame = adapter->vf_res->max_mtu;
273 	int pairs = adapter->num_active_queues;
274 	struct virtchnl_queue_pair_info *vqpi;
275 	size_t len;
276 
277 	if (max_frame > IAVF_MAX_RXBUFFER || !max_frame)
278 		max_frame = IAVF_MAX_RXBUFFER;
279 
280 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
281 		/* bail because we already have a command pending */
282 		dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
283 			adapter->current_op);
284 		return;
285 	}
286 	adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
287 	len = struct_size(vqci, qpair, pairs);
288 	vqci = kzalloc(len, GFP_KERNEL);
289 	if (!vqci)
290 		return;
291 
292 	/* Limit maximum frame size when jumbo frames is not enabled */
293 	if (!(adapter->flags & IAVF_FLAG_LEGACY_RX) &&
294 	    (adapter->netdev->mtu <= ETH_DATA_LEN))
295 		max_frame = IAVF_RXBUFFER_1536 - NET_IP_ALIGN;
296 
297 	vqci->vsi_id = adapter->vsi_res->vsi_id;
298 	vqci->num_queue_pairs = pairs;
299 	vqpi = vqci->qpair;
300 	/* Size check is not needed here - HW max is 16 queue pairs, and we
301 	 * can fit info for 31 of them into the AQ buffer before it overflows.
302 	 */
303 	for (i = 0; i < pairs; i++) {
304 		vqpi->txq.vsi_id = vqci->vsi_id;
305 		vqpi->txq.queue_id = i;
306 		vqpi->txq.ring_len = adapter->tx_rings[i].count;
307 		vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
308 		vqpi->rxq.vsi_id = vqci->vsi_id;
309 		vqpi->rxq.queue_id = i;
310 		vqpi->rxq.ring_len = adapter->rx_rings[i].count;
311 		vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
312 		vqpi->rxq.max_pkt_size = max_frame;
313 		vqpi->rxq.databuffer_size =
314 			ALIGN(adapter->rx_rings[i].rx_buf_len,
315 			      BIT_ULL(IAVF_RXQ_CTX_DBUFF_SHIFT));
316 		vqpi++;
317 	}
318 
319 	adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES;
320 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
321 			 (u8 *)vqci, len);
322 	kfree(vqci);
323 }
324 
325 /**
326  * iavf_enable_queues
327  * @adapter: adapter structure
328  *
329  * Request that the PF enable all of our queues.
330  **/
331 void iavf_enable_queues(struct iavf_adapter *adapter)
332 {
333 	struct virtchnl_queue_select vqs;
334 
335 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
336 		/* bail because we already have a command pending */
337 		dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
338 			adapter->current_op);
339 		return;
340 	}
341 	adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
342 	vqs.vsi_id = adapter->vsi_res->vsi_id;
343 	vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
344 	vqs.rx_queues = vqs.tx_queues;
345 	adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_QUEUES;
346 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
347 			 (u8 *)&vqs, sizeof(vqs));
348 }
349 
350 /**
351  * iavf_disable_queues
352  * @adapter: adapter structure
353  *
354  * Request that the PF disable all of our queues.
355  **/
356 void iavf_disable_queues(struct iavf_adapter *adapter)
357 {
358 	struct virtchnl_queue_select vqs;
359 
360 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
361 		/* bail because we already have a command pending */
362 		dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
363 			adapter->current_op);
364 		return;
365 	}
366 	adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
367 	vqs.vsi_id = adapter->vsi_res->vsi_id;
368 	vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
369 	vqs.rx_queues = vqs.tx_queues;
370 	adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_QUEUES;
371 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
372 			 (u8 *)&vqs, sizeof(vqs));
373 }
374 
375 /**
376  * iavf_map_queues
377  * @adapter: adapter structure
378  *
379  * Request that the PF map queues to interrupt vectors. Misc causes, including
380  * admin queue, are always mapped to vector 0.
381  **/
382 void iavf_map_queues(struct iavf_adapter *adapter)
383 {
384 	struct virtchnl_irq_map_info *vimi;
385 	struct virtchnl_vector_map *vecmap;
386 	struct iavf_q_vector *q_vector;
387 	int v_idx, q_vectors;
388 	size_t len;
389 
390 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
391 		/* bail because we already have a command pending */
392 		dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
393 			adapter->current_op);
394 		return;
395 	}
396 	adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
397 
398 	q_vectors = adapter->num_msix_vectors - NONQ_VECS;
399 
400 	len = struct_size(vimi, vecmap, adapter->num_msix_vectors);
401 	vimi = kzalloc(len, GFP_KERNEL);
402 	if (!vimi)
403 		return;
404 
405 	vimi->num_vectors = adapter->num_msix_vectors;
406 	/* Queue vectors first */
407 	for (v_idx = 0; v_idx < q_vectors; v_idx++) {
408 		q_vector = &adapter->q_vectors[v_idx];
409 		vecmap = &vimi->vecmap[v_idx];
410 
411 		vecmap->vsi_id = adapter->vsi_res->vsi_id;
412 		vecmap->vector_id = v_idx + NONQ_VECS;
413 		vecmap->txq_map = q_vector->ring_mask;
414 		vecmap->rxq_map = q_vector->ring_mask;
415 		vecmap->rxitr_idx = IAVF_RX_ITR;
416 		vecmap->txitr_idx = IAVF_TX_ITR;
417 	}
418 	/* Misc vector last - this is only for AdminQ messages */
419 	vecmap = &vimi->vecmap[v_idx];
420 	vecmap->vsi_id = adapter->vsi_res->vsi_id;
421 	vecmap->vector_id = 0;
422 	vecmap->txq_map = 0;
423 	vecmap->rxq_map = 0;
424 
425 	adapter->aq_required &= ~IAVF_FLAG_AQ_MAP_VECTORS;
426 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
427 			 (u8 *)vimi, len);
428 	kfree(vimi);
429 }
430 
431 /**
432  * iavf_set_mac_addr_type - Set the correct request type from the filter type
433  * @virtchnl_ether_addr: pointer to requested list element
434  * @filter: pointer to requested filter
435  **/
436 static void
437 iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr,
438 		       const struct iavf_mac_filter *filter)
439 {
440 	virtchnl_ether_addr->type = filter->is_primary ?
441 		VIRTCHNL_ETHER_ADDR_PRIMARY :
442 		VIRTCHNL_ETHER_ADDR_EXTRA;
443 }
444 
445 /**
446  * iavf_add_ether_addrs
447  * @adapter: adapter structure
448  *
449  * Request that the PF add one or more addresses to our filters.
450  **/
451 void iavf_add_ether_addrs(struct iavf_adapter *adapter)
452 {
453 	struct virtchnl_ether_addr_list *veal;
454 	struct iavf_mac_filter *f;
455 	int i = 0, count = 0;
456 	bool more = false;
457 	size_t len;
458 
459 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
460 		/* bail because we already have a command pending */
461 		dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
462 			adapter->current_op);
463 		return;
464 	}
465 
466 	spin_lock_bh(&adapter->mac_vlan_list_lock);
467 
468 	list_for_each_entry(f, &adapter->mac_filter_list, list) {
469 		if (f->add)
470 			count++;
471 	}
472 	if (!count) {
473 		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
474 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
475 		return;
476 	}
477 	adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
478 
479 	len = struct_size(veal, list, count);
480 	if (len > IAVF_MAX_AQ_BUF_SIZE) {
481 		dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
482 		count = (IAVF_MAX_AQ_BUF_SIZE -
483 			 sizeof(struct virtchnl_ether_addr_list)) /
484 			sizeof(struct virtchnl_ether_addr);
485 		len = struct_size(veal, list, count);
486 		more = true;
487 	}
488 
489 	veal = kzalloc(len, GFP_ATOMIC);
490 	if (!veal) {
491 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
492 		return;
493 	}
494 
495 	veal->vsi_id = adapter->vsi_res->vsi_id;
496 	veal->num_elements = count;
497 	list_for_each_entry(f, &adapter->mac_filter_list, list) {
498 		if (f->add) {
499 			ether_addr_copy(veal->list[i].addr, f->macaddr);
500 			iavf_set_mac_addr_type(&veal->list[i], f);
501 			i++;
502 			f->add = false;
503 			if (i == count)
504 				break;
505 		}
506 	}
507 	if (!more)
508 		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
509 
510 	spin_unlock_bh(&adapter->mac_vlan_list_lock);
511 
512 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len);
513 	kfree(veal);
514 }
515 
516 /**
517  * iavf_del_ether_addrs
518  * @adapter: adapter structure
519  *
520  * Request that the PF remove one or more addresses from our filters.
521  **/
522 void iavf_del_ether_addrs(struct iavf_adapter *adapter)
523 {
524 	struct virtchnl_ether_addr_list *veal;
525 	struct iavf_mac_filter *f, *ftmp;
526 	int i = 0, count = 0;
527 	bool more = false;
528 	size_t len;
529 
530 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
531 		/* bail because we already have a command pending */
532 		dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
533 			adapter->current_op);
534 		return;
535 	}
536 
537 	spin_lock_bh(&adapter->mac_vlan_list_lock);
538 
539 	list_for_each_entry(f, &adapter->mac_filter_list, list) {
540 		if (f->remove)
541 			count++;
542 	}
543 	if (!count) {
544 		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
545 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
546 		return;
547 	}
548 	adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
549 
550 	len = struct_size(veal, list, count);
551 	if (len > IAVF_MAX_AQ_BUF_SIZE) {
552 		dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
553 		count = (IAVF_MAX_AQ_BUF_SIZE -
554 			 sizeof(struct virtchnl_ether_addr_list)) /
555 			sizeof(struct virtchnl_ether_addr);
556 		len = struct_size(veal, list, count);
557 		more = true;
558 	}
559 	veal = kzalloc(len, GFP_ATOMIC);
560 	if (!veal) {
561 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
562 		return;
563 	}
564 
565 	veal->vsi_id = adapter->vsi_res->vsi_id;
566 	veal->num_elements = count;
567 	list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
568 		if (f->remove) {
569 			ether_addr_copy(veal->list[i].addr, f->macaddr);
570 			iavf_set_mac_addr_type(&veal->list[i], f);
571 			i++;
572 			list_del(&f->list);
573 			kfree(f);
574 			if (i == count)
575 				break;
576 		}
577 	}
578 	if (!more)
579 		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
580 
581 	spin_unlock_bh(&adapter->mac_vlan_list_lock);
582 
583 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, (u8 *)veal, len);
584 	kfree(veal);
585 }
586 
587 /**
588  * iavf_mac_add_ok
589  * @adapter: adapter structure
590  *
591  * Submit list of filters based on PF response.
592  **/
593 static void iavf_mac_add_ok(struct iavf_adapter *adapter)
594 {
595 	struct iavf_mac_filter *f, *ftmp;
596 
597 	spin_lock_bh(&adapter->mac_vlan_list_lock);
598 	list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
599 		f->is_new_mac = false;
600 		if (!f->add && !f->add_handled)
601 			f->add_handled = true;
602 	}
603 	spin_unlock_bh(&adapter->mac_vlan_list_lock);
604 }
605 
606 /**
607  * iavf_mac_add_reject
608  * @adapter: adapter structure
609  *
610  * Remove filters from list based on PF response.
611  **/
612 static void iavf_mac_add_reject(struct iavf_adapter *adapter)
613 {
614 	struct net_device *netdev = adapter->netdev;
615 	struct iavf_mac_filter *f, *ftmp;
616 
617 	spin_lock_bh(&adapter->mac_vlan_list_lock);
618 	list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
619 		if (f->remove && ether_addr_equal(f->macaddr, netdev->dev_addr))
620 			f->remove = false;
621 
622 		if (!f->add && !f->add_handled)
623 			f->add_handled = true;
624 
625 		if (f->is_new_mac) {
626 			list_del(&f->list);
627 			kfree(f);
628 		}
629 	}
630 	spin_unlock_bh(&adapter->mac_vlan_list_lock);
631 }
632 
633 /**
634  * iavf_vlan_add_reject
635  * @adapter: adapter structure
636  *
637  * Remove VLAN filters from list based on PF response.
638  **/
639 static void iavf_vlan_add_reject(struct iavf_adapter *adapter)
640 {
641 	struct iavf_vlan_filter *f, *ftmp;
642 
643 	spin_lock_bh(&adapter->mac_vlan_list_lock);
644 	list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
645 		if (f->state == IAVF_VLAN_IS_NEW) {
646 			list_del(&f->list);
647 			kfree(f);
648 			adapter->num_vlan_filters--;
649 		}
650 	}
651 	spin_unlock_bh(&adapter->mac_vlan_list_lock);
652 }
653 
654 /**
655  * iavf_add_vlans
656  * @adapter: adapter structure
657  *
658  * Request that the PF add one or more VLAN filters to our VSI.
659  **/
660 void iavf_add_vlans(struct iavf_adapter *adapter)
661 {
662 	int len, i = 0, count = 0;
663 	struct iavf_vlan_filter *f;
664 	bool more = false;
665 
666 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
667 		/* bail because we already have a command pending */
668 		dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
669 			adapter->current_op);
670 		return;
671 	}
672 
673 	spin_lock_bh(&adapter->mac_vlan_list_lock);
674 
675 	list_for_each_entry(f, &adapter->vlan_filter_list, list) {
676 		if (f->state == IAVF_VLAN_ADD)
677 			count++;
678 	}
679 	if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
680 		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
681 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
682 		return;
683 	}
684 
685 	if (VLAN_ALLOWED(adapter)) {
686 		struct virtchnl_vlan_filter_list *vvfl;
687 
688 		adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
689 
690 		len = sizeof(*vvfl) + (count * sizeof(u16));
691 		if (len > IAVF_MAX_AQ_BUF_SIZE) {
692 			dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
693 			count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl)) /
694 				sizeof(u16);
695 			len = sizeof(*vvfl) + (count * sizeof(u16));
696 			more = true;
697 		}
698 		vvfl = kzalloc(len, GFP_ATOMIC);
699 		if (!vvfl) {
700 			spin_unlock_bh(&adapter->mac_vlan_list_lock);
701 			return;
702 		}
703 
704 		vvfl->vsi_id = adapter->vsi_res->vsi_id;
705 		vvfl->num_elements = count;
706 		list_for_each_entry(f, &adapter->vlan_filter_list, list) {
707 			if (f->state == IAVF_VLAN_ADD) {
708 				vvfl->vlan_id[i] = f->vlan.vid;
709 				i++;
710 				f->state = IAVF_VLAN_IS_NEW;
711 				if (i == count)
712 					break;
713 			}
714 		}
715 		if (!more)
716 			adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
717 
718 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
719 
720 		iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
721 		kfree(vvfl);
722 	} else {
723 		u16 max_vlans = adapter->vlan_v2_caps.filtering.max_filters;
724 		u16 current_vlans = iavf_get_num_vlans_added(adapter);
725 		struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
726 
727 		adapter->current_op = VIRTCHNL_OP_ADD_VLAN_V2;
728 
729 		if ((count + current_vlans) > max_vlans &&
730 		    current_vlans < max_vlans) {
731 			count = max_vlans - iavf_get_num_vlans_added(adapter);
732 			more = true;
733 		}
734 
735 		len = sizeof(*vvfl_v2) + ((count - 1) *
736 					  sizeof(struct virtchnl_vlan_filter));
737 		if (len > IAVF_MAX_AQ_BUF_SIZE) {
738 			dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
739 			count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl_v2)) /
740 				sizeof(struct virtchnl_vlan_filter);
741 			len = sizeof(*vvfl_v2) +
742 				((count - 1) *
743 				 sizeof(struct virtchnl_vlan_filter));
744 			more = true;
745 		}
746 
747 		vvfl_v2 = kzalloc(len, GFP_ATOMIC);
748 		if (!vvfl_v2) {
749 			spin_unlock_bh(&adapter->mac_vlan_list_lock);
750 			return;
751 		}
752 
753 		vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
754 		vvfl_v2->num_elements = count;
755 		list_for_each_entry(f, &adapter->vlan_filter_list, list) {
756 			if (f->state == IAVF_VLAN_ADD) {
757 				struct virtchnl_vlan_supported_caps *filtering_support =
758 					&adapter->vlan_v2_caps.filtering.filtering_support;
759 				struct virtchnl_vlan *vlan;
760 
761 				if (i == count)
762 					break;
763 
764 				/* give priority over outer if it's enabled */
765 				if (filtering_support->outer)
766 					vlan = &vvfl_v2->filters[i].outer;
767 				else
768 					vlan = &vvfl_v2->filters[i].inner;
769 
770 				vlan->tci = f->vlan.vid;
771 				vlan->tpid = f->vlan.tpid;
772 
773 				i++;
774 				f->state = IAVF_VLAN_IS_NEW;
775 			}
776 		}
777 
778 		if (!more)
779 			adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
780 
781 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
782 
783 		iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN_V2,
784 				 (u8 *)vvfl_v2, len);
785 		kfree(vvfl_v2);
786 	}
787 }
788 
789 /**
790  * iavf_del_vlans
791  * @adapter: adapter structure
792  *
793  * Request that the PF remove one or more VLAN filters from our VSI.
794  **/
795 void iavf_del_vlans(struct iavf_adapter *adapter)
796 {
797 	struct iavf_vlan_filter *f, *ftmp;
798 	int len, i = 0, count = 0;
799 	bool more = false;
800 
801 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
802 		/* bail because we already have a command pending */
803 		dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
804 			adapter->current_op);
805 		return;
806 	}
807 
808 	spin_lock_bh(&adapter->mac_vlan_list_lock);
809 
810 	list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
811 		/* since VLAN capabilities are not allowed, we dont want to send
812 		 * a VLAN delete request because it will most likely fail and
813 		 * create unnecessary errors/noise, so just free the VLAN
814 		 * filters marked for removal to enable bailing out before
815 		 * sending a virtchnl message
816 		 */
817 		if (f->state == IAVF_VLAN_REMOVE &&
818 		    !VLAN_FILTERING_ALLOWED(adapter)) {
819 			list_del(&f->list);
820 			kfree(f);
821 			adapter->num_vlan_filters--;
822 		} else if (f->state == IAVF_VLAN_DISABLE &&
823 		    !VLAN_FILTERING_ALLOWED(adapter)) {
824 			f->state = IAVF_VLAN_INACTIVE;
825 		} else if (f->state == IAVF_VLAN_REMOVE ||
826 			   f->state == IAVF_VLAN_DISABLE) {
827 			count++;
828 		}
829 	}
830 	if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
831 		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
832 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
833 		return;
834 	}
835 
836 	if (VLAN_ALLOWED(adapter)) {
837 		struct virtchnl_vlan_filter_list *vvfl;
838 
839 		adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
840 
841 		len = sizeof(*vvfl) + (count * sizeof(u16));
842 		if (len > IAVF_MAX_AQ_BUF_SIZE) {
843 			dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
844 			count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl)) /
845 				sizeof(u16);
846 			len = sizeof(*vvfl) + (count * sizeof(u16));
847 			more = true;
848 		}
849 		vvfl = kzalloc(len, GFP_ATOMIC);
850 		if (!vvfl) {
851 			spin_unlock_bh(&adapter->mac_vlan_list_lock);
852 			return;
853 		}
854 
855 		vvfl->vsi_id = adapter->vsi_res->vsi_id;
856 		vvfl->num_elements = count;
857 		list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
858 			if (f->state == IAVF_VLAN_DISABLE) {
859 				vvfl->vlan_id[i] = f->vlan.vid;
860 				f->state = IAVF_VLAN_INACTIVE;
861 				i++;
862 				if (i == count)
863 					break;
864 			} else if (f->state == IAVF_VLAN_REMOVE) {
865 				vvfl->vlan_id[i] = f->vlan.vid;
866 				list_del(&f->list);
867 				kfree(f);
868 				adapter->num_vlan_filters--;
869 				i++;
870 				if (i == count)
871 					break;
872 			}
873 		}
874 
875 		if (!more)
876 			adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
877 
878 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
879 
880 		iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
881 		kfree(vvfl);
882 	} else {
883 		struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
884 
885 		adapter->current_op = VIRTCHNL_OP_DEL_VLAN_V2;
886 
887 		len = sizeof(*vvfl_v2) +
888 			((count - 1) * sizeof(struct virtchnl_vlan_filter));
889 		if (len > IAVF_MAX_AQ_BUF_SIZE) {
890 			dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
891 			count = (IAVF_MAX_AQ_BUF_SIZE -
892 				 sizeof(*vvfl_v2)) /
893 				sizeof(struct virtchnl_vlan_filter);
894 			len = sizeof(*vvfl_v2) +
895 				((count - 1) *
896 				 sizeof(struct virtchnl_vlan_filter));
897 			more = true;
898 		}
899 
900 		vvfl_v2 = kzalloc(len, GFP_ATOMIC);
901 		if (!vvfl_v2) {
902 			spin_unlock_bh(&adapter->mac_vlan_list_lock);
903 			return;
904 		}
905 
906 		vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
907 		vvfl_v2->num_elements = count;
908 		list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
909 			if (f->state == IAVF_VLAN_DISABLE ||
910 			    f->state == IAVF_VLAN_REMOVE) {
911 				struct virtchnl_vlan_supported_caps *filtering_support =
912 					&adapter->vlan_v2_caps.filtering.filtering_support;
913 				struct virtchnl_vlan *vlan;
914 
915 				/* give priority over outer if it's enabled */
916 				if (filtering_support->outer)
917 					vlan = &vvfl_v2->filters[i].outer;
918 				else
919 					vlan = &vvfl_v2->filters[i].inner;
920 
921 				vlan->tci = f->vlan.vid;
922 				vlan->tpid = f->vlan.tpid;
923 
924 				if (f->state == IAVF_VLAN_DISABLE) {
925 					f->state = IAVF_VLAN_INACTIVE;
926 				} else {
927 					list_del(&f->list);
928 					kfree(f);
929 					adapter->num_vlan_filters--;
930 				}
931 				i++;
932 				if (i == count)
933 					break;
934 			}
935 		}
936 
937 		if (!more)
938 			adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
939 
940 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
941 
942 		iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN_V2,
943 				 (u8 *)vvfl_v2, len);
944 		kfree(vvfl_v2);
945 	}
946 }
947 
948 /**
949  * iavf_set_promiscuous
950  * @adapter: adapter structure
951  * @flags: bitmask to control unicast/multicast promiscuous.
952  *
953  * Request that the PF enable promiscuous mode for our VSI.
954  **/
955 void iavf_set_promiscuous(struct iavf_adapter *adapter, int flags)
956 {
957 	struct virtchnl_promisc_info vpi;
958 	int promisc_all;
959 
960 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
961 		/* bail because we already have a command pending */
962 		dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
963 			adapter->current_op);
964 		return;
965 	}
966 
967 	promisc_all = FLAG_VF_UNICAST_PROMISC |
968 		      FLAG_VF_MULTICAST_PROMISC;
969 	if ((flags & promisc_all) == promisc_all) {
970 		adapter->flags |= IAVF_FLAG_PROMISC_ON;
971 		adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_PROMISC;
972 		dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
973 	}
974 
975 	if (flags & FLAG_VF_MULTICAST_PROMISC) {
976 		adapter->flags |= IAVF_FLAG_ALLMULTI_ON;
977 		adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_ALLMULTI;
978 		dev_info(&adapter->pdev->dev, "%s is entering multicast promiscuous mode\n",
979 			 adapter->netdev->name);
980 	}
981 
982 	if (!flags) {
983 		if (adapter->flags & IAVF_FLAG_PROMISC_ON) {
984 			adapter->flags &= ~IAVF_FLAG_PROMISC_ON;
985 			adapter->aq_required &= ~IAVF_FLAG_AQ_RELEASE_PROMISC;
986 			dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
987 		}
988 
989 		if (adapter->flags & IAVF_FLAG_ALLMULTI_ON) {
990 			adapter->flags &= ~IAVF_FLAG_ALLMULTI_ON;
991 			adapter->aq_required &= ~IAVF_FLAG_AQ_RELEASE_ALLMULTI;
992 			dev_info(&adapter->pdev->dev, "%s is leaving multicast promiscuous mode\n",
993 				 adapter->netdev->name);
994 		}
995 	}
996 
997 	adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
998 	vpi.vsi_id = adapter->vsi_res->vsi_id;
999 	vpi.flags = flags;
1000 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1001 			 (u8 *)&vpi, sizeof(vpi));
1002 }
1003 
1004 /**
1005  * iavf_request_stats
1006  * @adapter: adapter structure
1007  *
1008  * Request VSI statistics from PF.
1009  **/
1010 void iavf_request_stats(struct iavf_adapter *adapter)
1011 {
1012 	struct virtchnl_queue_select vqs;
1013 
1014 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1015 		/* no error message, this isn't crucial */
1016 		return;
1017 	}
1018 
1019 	adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_STATS;
1020 	adapter->current_op = VIRTCHNL_OP_GET_STATS;
1021 	vqs.vsi_id = adapter->vsi_res->vsi_id;
1022 	/* queue maps are ignored for this message - only the vsi is used */
1023 	if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs,
1024 			     sizeof(vqs)))
1025 		/* if the request failed, don't lock out others */
1026 		adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1027 }
1028 
1029 /**
1030  * iavf_get_hena
1031  * @adapter: adapter structure
1032  *
1033  * Request hash enable capabilities from PF
1034  **/
1035 void iavf_get_hena(struct iavf_adapter *adapter)
1036 {
1037 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1038 		/* bail because we already have a command pending */
1039 		dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
1040 			adapter->current_op);
1041 		return;
1042 	}
1043 	adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
1044 	adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA;
1045 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0);
1046 }
1047 
1048 /**
1049  * iavf_set_hena
1050  * @adapter: adapter structure
1051  *
1052  * Request the PF to set our RSS hash capabilities
1053  **/
1054 void iavf_set_hena(struct iavf_adapter *adapter)
1055 {
1056 	struct virtchnl_rss_hena vrh;
1057 
1058 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1059 		/* bail because we already have a command pending */
1060 		dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
1061 			adapter->current_op);
1062 		return;
1063 	}
1064 	vrh.hena = adapter->hena;
1065 	adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
1066 	adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA;
1067 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh,
1068 			 sizeof(vrh));
1069 }
1070 
1071 /**
1072  * iavf_set_rss_key
1073  * @adapter: adapter structure
1074  *
1075  * Request the PF to set our RSS hash key
1076  **/
1077 void iavf_set_rss_key(struct iavf_adapter *adapter)
1078 {
1079 	struct virtchnl_rss_key *vrk;
1080 	int len;
1081 
1082 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1083 		/* bail because we already have a command pending */
1084 		dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
1085 			adapter->current_op);
1086 		return;
1087 	}
1088 	len = sizeof(struct virtchnl_rss_key) +
1089 	      (adapter->rss_key_size * sizeof(u8)) - 1;
1090 	vrk = kzalloc(len, GFP_KERNEL);
1091 	if (!vrk)
1092 		return;
1093 	vrk->vsi_id = adapter->vsi.id;
1094 	vrk->key_len = adapter->rss_key_size;
1095 	memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
1096 
1097 	adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
1098 	adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY;
1099 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len);
1100 	kfree(vrk);
1101 }
1102 
1103 /**
1104  * iavf_set_rss_lut
1105  * @adapter: adapter structure
1106  *
1107  * Request the PF to set our RSS lookup table
1108  **/
1109 void iavf_set_rss_lut(struct iavf_adapter *adapter)
1110 {
1111 	struct virtchnl_rss_lut *vrl;
1112 	int len;
1113 
1114 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1115 		/* bail because we already have a command pending */
1116 		dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
1117 			adapter->current_op);
1118 		return;
1119 	}
1120 	len = sizeof(struct virtchnl_rss_lut) +
1121 	      (adapter->rss_lut_size * sizeof(u8)) - 1;
1122 	vrl = kzalloc(len, GFP_KERNEL);
1123 	if (!vrl)
1124 		return;
1125 	vrl->vsi_id = adapter->vsi.id;
1126 	vrl->lut_entries = adapter->rss_lut_size;
1127 	memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
1128 	adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
1129 	adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT;
1130 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len);
1131 	kfree(vrl);
1132 }
1133 
1134 /**
1135  * iavf_enable_vlan_stripping
1136  * @adapter: adapter structure
1137  *
1138  * Request VLAN header stripping to be enabled
1139  **/
1140 void iavf_enable_vlan_stripping(struct iavf_adapter *adapter)
1141 {
1142 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1143 		/* bail because we already have a command pending */
1144 		dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
1145 			adapter->current_op);
1146 		return;
1147 	}
1148 	adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
1149 	adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
1150 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0);
1151 }
1152 
1153 /**
1154  * iavf_disable_vlan_stripping
1155  * @adapter: adapter structure
1156  *
1157  * Request VLAN header stripping to be disabled
1158  **/
1159 void iavf_disable_vlan_stripping(struct iavf_adapter *adapter)
1160 {
1161 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1162 		/* bail because we already have a command pending */
1163 		dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
1164 			adapter->current_op);
1165 		return;
1166 	}
1167 	adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
1168 	adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
1169 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0);
1170 }
1171 
1172 /**
1173  * iavf_tpid_to_vc_ethertype - transform from VLAN TPID to virtchnl ethertype
1174  * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1175  */
1176 static u32 iavf_tpid_to_vc_ethertype(u16 tpid)
1177 {
1178 	switch (tpid) {
1179 	case ETH_P_8021Q:
1180 		return VIRTCHNL_VLAN_ETHERTYPE_8100;
1181 	case ETH_P_8021AD:
1182 		return VIRTCHNL_VLAN_ETHERTYPE_88A8;
1183 	}
1184 
1185 	return 0;
1186 }
1187 
1188 /**
1189  * iavf_set_vc_offload_ethertype - set virtchnl ethertype for offload message
1190  * @adapter: adapter structure
1191  * @msg: message structure used for updating offloads over virtchnl to update
1192  * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1193  * @offload_op: opcode used to determine which support structure to check
1194  */
1195 static int
1196 iavf_set_vc_offload_ethertype(struct iavf_adapter *adapter,
1197 			      struct virtchnl_vlan_setting *msg, u16 tpid,
1198 			      enum virtchnl_ops offload_op)
1199 {
1200 	struct virtchnl_vlan_supported_caps *offload_support;
1201 	u16 vc_ethertype = iavf_tpid_to_vc_ethertype(tpid);
1202 
1203 	/* reference the correct offload support structure */
1204 	switch (offload_op) {
1205 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1206 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1207 		offload_support =
1208 			&adapter->vlan_v2_caps.offloads.stripping_support;
1209 		break;
1210 	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1211 	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1212 		offload_support =
1213 			&adapter->vlan_v2_caps.offloads.insertion_support;
1214 		break;
1215 	default:
1216 		dev_err(&adapter->pdev->dev, "Invalid opcode %d for setting virtchnl ethertype to enable/disable VLAN offloads\n",
1217 			offload_op);
1218 		return -EINVAL;
1219 	}
1220 
1221 	/* make sure ethertype is supported */
1222 	if (offload_support->outer & vc_ethertype &&
1223 	    offload_support->outer & VIRTCHNL_VLAN_TOGGLE) {
1224 		msg->outer_ethertype_setting = vc_ethertype;
1225 	} else if (offload_support->inner & vc_ethertype &&
1226 		   offload_support->inner & VIRTCHNL_VLAN_TOGGLE) {
1227 		msg->inner_ethertype_setting = vc_ethertype;
1228 	} else {
1229 		dev_dbg(&adapter->pdev->dev, "opcode %d unsupported for VLAN TPID 0x%04x\n",
1230 			offload_op, tpid);
1231 		return -EINVAL;
1232 	}
1233 
1234 	return 0;
1235 }
1236 
1237 /**
1238  * iavf_clear_offload_v2_aq_required - clear AQ required bit for offload request
1239  * @adapter: adapter structure
1240  * @tpid: VLAN TPID
1241  * @offload_op: opcode used to determine which AQ required bit to clear
1242  */
1243 static void
1244 iavf_clear_offload_v2_aq_required(struct iavf_adapter *adapter, u16 tpid,
1245 				  enum virtchnl_ops offload_op)
1246 {
1247 	switch (offload_op) {
1248 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1249 		if (tpid == ETH_P_8021Q)
1250 			adapter->aq_required &=
1251 				~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_STRIPPING;
1252 		else if (tpid == ETH_P_8021AD)
1253 			adapter->aq_required &=
1254 				~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_STRIPPING;
1255 		break;
1256 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1257 		if (tpid == ETH_P_8021Q)
1258 			adapter->aq_required &=
1259 				~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_STRIPPING;
1260 		else if (tpid == ETH_P_8021AD)
1261 			adapter->aq_required &=
1262 				~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_STRIPPING;
1263 		break;
1264 	case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1265 		if (tpid == ETH_P_8021Q)
1266 			adapter->aq_required &=
1267 				~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_INSERTION;
1268 		else if (tpid == ETH_P_8021AD)
1269 			adapter->aq_required &=
1270 				~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_INSERTION;
1271 		break;
1272 	case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1273 		if (tpid == ETH_P_8021Q)
1274 			adapter->aq_required &=
1275 				~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_INSERTION;
1276 		else if (tpid == ETH_P_8021AD)
1277 			adapter->aq_required &=
1278 				~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_INSERTION;
1279 		break;
1280 	default:
1281 		dev_err(&adapter->pdev->dev, "Unsupported opcode %d specified for clearing aq_required bits for VIRTCHNL_VF_OFFLOAD_VLAN_V2 offload request\n",
1282 			offload_op);
1283 	}
1284 }
1285 
1286 /**
1287  * iavf_send_vlan_offload_v2 - send offload enable/disable over virtchnl
1288  * @adapter: adapter structure
1289  * @tpid: VLAN TPID used for the command (i.e. 0x8100 or 0x88a8)
1290  * @offload_op: offload_op used to make the request over virtchnl
1291  */
1292 static void
1293 iavf_send_vlan_offload_v2(struct iavf_adapter *adapter, u16 tpid,
1294 			  enum virtchnl_ops offload_op)
1295 {
1296 	struct virtchnl_vlan_setting *msg;
1297 	int len = sizeof(*msg);
1298 
1299 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1300 		/* bail because we already have a command pending */
1301 		dev_err(&adapter->pdev->dev, "Cannot send %d, command %d pending\n",
1302 			offload_op, adapter->current_op);
1303 		return;
1304 	}
1305 
1306 	adapter->current_op = offload_op;
1307 
1308 	msg = kzalloc(len, GFP_KERNEL);
1309 	if (!msg)
1310 		return;
1311 
1312 	msg->vport_id = adapter->vsi_res->vsi_id;
1313 
1314 	/* always clear to prevent unsupported and endless requests */
1315 	iavf_clear_offload_v2_aq_required(adapter, tpid, offload_op);
1316 
1317 	/* only send valid offload requests */
1318 	if (!iavf_set_vc_offload_ethertype(adapter, msg, tpid, offload_op))
1319 		iavf_send_pf_msg(adapter, offload_op, (u8 *)msg, len);
1320 	else
1321 		adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1322 
1323 	kfree(msg);
1324 }
1325 
1326 /**
1327  * iavf_enable_vlan_stripping_v2 - enable VLAN stripping
1328  * @adapter: adapter structure
1329  * @tpid: VLAN TPID used to enable VLAN stripping
1330  */
1331 void iavf_enable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1332 {
1333 	iavf_send_vlan_offload_v2(adapter, tpid,
1334 				  VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2);
1335 }
1336 
1337 /**
1338  * iavf_disable_vlan_stripping_v2 - disable VLAN stripping
1339  * @adapter: adapter structure
1340  * @tpid: VLAN TPID used to disable VLAN stripping
1341  */
1342 void iavf_disable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1343 {
1344 	iavf_send_vlan_offload_v2(adapter, tpid,
1345 				  VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2);
1346 }
1347 
1348 /**
1349  * iavf_enable_vlan_insertion_v2 - enable VLAN insertion
1350  * @adapter: adapter structure
1351  * @tpid: VLAN TPID used to enable VLAN insertion
1352  */
1353 void iavf_enable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1354 {
1355 	iavf_send_vlan_offload_v2(adapter, tpid,
1356 				  VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2);
1357 }
1358 
1359 /**
1360  * iavf_disable_vlan_insertion_v2 - disable VLAN insertion
1361  * @adapter: adapter structure
1362  * @tpid: VLAN TPID used to disable VLAN insertion
1363  */
1364 void iavf_disable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1365 {
1366 	iavf_send_vlan_offload_v2(adapter, tpid,
1367 				  VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2);
1368 }
1369 
1370 #define IAVF_MAX_SPEED_STRLEN	13
1371 
1372 /**
1373  * iavf_print_link_message - print link up or down
1374  * @adapter: adapter structure
1375  *
1376  * Log a message telling the world of our wonderous link status
1377  */
1378 static void iavf_print_link_message(struct iavf_adapter *adapter)
1379 {
1380 	struct net_device *netdev = adapter->netdev;
1381 	int link_speed_mbps;
1382 	char *speed;
1383 
1384 	if (!adapter->link_up) {
1385 		netdev_info(netdev, "NIC Link is Down\n");
1386 		return;
1387 	}
1388 
1389 	speed = kzalloc(IAVF_MAX_SPEED_STRLEN, GFP_KERNEL);
1390 	if (!speed)
1391 		return;
1392 
1393 	if (ADV_LINK_SUPPORT(adapter)) {
1394 		link_speed_mbps = adapter->link_speed_mbps;
1395 		goto print_link_msg;
1396 	}
1397 
1398 	switch (adapter->link_speed) {
1399 	case VIRTCHNL_LINK_SPEED_40GB:
1400 		link_speed_mbps = SPEED_40000;
1401 		break;
1402 	case VIRTCHNL_LINK_SPEED_25GB:
1403 		link_speed_mbps = SPEED_25000;
1404 		break;
1405 	case VIRTCHNL_LINK_SPEED_20GB:
1406 		link_speed_mbps = SPEED_20000;
1407 		break;
1408 	case VIRTCHNL_LINK_SPEED_10GB:
1409 		link_speed_mbps = SPEED_10000;
1410 		break;
1411 	case VIRTCHNL_LINK_SPEED_5GB:
1412 		link_speed_mbps = SPEED_5000;
1413 		break;
1414 	case VIRTCHNL_LINK_SPEED_2_5GB:
1415 		link_speed_mbps = SPEED_2500;
1416 		break;
1417 	case VIRTCHNL_LINK_SPEED_1GB:
1418 		link_speed_mbps = SPEED_1000;
1419 		break;
1420 	case VIRTCHNL_LINK_SPEED_100MB:
1421 		link_speed_mbps = SPEED_100;
1422 		break;
1423 	default:
1424 		link_speed_mbps = SPEED_UNKNOWN;
1425 		break;
1426 	}
1427 
1428 print_link_msg:
1429 	if (link_speed_mbps > SPEED_1000) {
1430 		if (link_speed_mbps == SPEED_2500)
1431 			snprintf(speed, IAVF_MAX_SPEED_STRLEN, "2.5 Gbps");
1432 		else
1433 			/* convert to Gbps inline */
1434 			snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1435 				 link_speed_mbps / 1000, "Gbps");
1436 	} else if (link_speed_mbps == SPEED_UNKNOWN) {
1437 		snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%s", "Unknown Mbps");
1438 	} else {
1439 		snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1440 			 link_speed_mbps, "Mbps");
1441 	}
1442 
1443 	netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed);
1444 	kfree(speed);
1445 }
1446 
1447 /**
1448  * iavf_get_vpe_link_status
1449  * @adapter: adapter structure
1450  * @vpe: virtchnl_pf_event structure
1451  *
1452  * Helper function for determining the link status
1453  **/
1454 static bool
1455 iavf_get_vpe_link_status(struct iavf_adapter *adapter,
1456 			 struct virtchnl_pf_event *vpe)
1457 {
1458 	if (ADV_LINK_SUPPORT(adapter))
1459 		return vpe->event_data.link_event_adv.link_status;
1460 	else
1461 		return vpe->event_data.link_event.link_status;
1462 }
1463 
1464 /**
1465  * iavf_set_adapter_link_speed_from_vpe
1466  * @adapter: adapter structure for which we are setting the link speed
1467  * @vpe: virtchnl_pf_event structure that contains the link speed we are setting
1468  *
1469  * Helper function for setting iavf_adapter link speed
1470  **/
1471 static void
1472 iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter *adapter,
1473 				     struct virtchnl_pf_event *vpe)
1474 {
1475 	if (ADV_LINK_SUPPORT(adapter))
1476 		adapter->link_speed_mbps =
1477 			vpe->event_data.link_event_adv.link_speed;
1478 	else
1479 		adapter->link_speed = vpe->event_data.link_event.link_speed;
1480 }
1481 
1482 /**
1483  * iavf_enable_channels
1484  * @adapter: adapter structure
1485  *
1486  * Request that the PF enable channels as specified by
1487  * the user via tc tool.
1488  **/
1489 void iavf_enable_channels(struct iavf_adapter *adapter)
1490 {
1491 	struct virtchnl_tc_info *vti = NULL;
1492 	size_t len;
1493 	int i;
1494 
1495 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1496 		/* bail because we already have a command pending */
1497 		dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1498 			adapter->current_op);
1499 		return;
1500 	}
1501 
1502 	len = struct_size(vti, list, adapter->num_tc - 1);
1503 	vti = kzalloc(len, GFP_KERNEL);
1504 	if (!vti)
1505 		return;
1506 	vti->num_tc = adapter->num_tc;
1507 	for (i = 0; i < vti->num_tc; i++) {
1508 		vti->list[i].count = adapter->ch_config.ch_info[i].count;
1509 		vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
1510 		vti->list[i].pad = 0;
1511 		vti->list[i].max_tx_rate =
1512 				adapter->ch_config.ch_info[i].max_tx_rate;
1513 	}
1514 
1515 	adapter->ch_config.state = __IAVF_TC_RUNNING;
1516 	adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1517 	adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
1518 	adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS;
1519 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len);
1520 	kfree(vti);
1521 }
1522 
1523 /**
1524  * iavf_disable_channels
1525  * @adapter: adapter structure
1526  *
1527  * Request that the PF disable channels that are configured
1528  **/
1529 void iavf_disable_channels(struct iavf_adapter *adapter)
1530 {
1531 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1532 		/* bail because we already have a command pending */
1533 		dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1534 			adapter->current_op);
1535 		return;
1536 	}
1537 
1538 	adapter->ch_config.state = __IAVF_TC_INVALID;
1539 	adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1540 	adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
1541 	adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS;
1542 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0);
1543 }
1544 
1545 /**
1546  * iavf_print_cloud_filter
1547  * @adapter: adapter structure
1548  * @f: cloud filter to print
1549  *
1550  * Print the cloud filter
1551  **/
1552 static void iavf_print_cloud_filter(struct iavf_adapter *adapter,
1553 				    struct virtchnl_filter *f)
1554 {
1555 	switch (f->flow_type) {
1556 	case VIRTCHNL_TCP_V4_FLOW:
1557 		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",
1558 			 &f->data.tcp_spec.dst_mac,
1559 			 &f->data.tcp_spec.src_mac,
1560 			 ntohs(f->data.tcp_spec.vlan_id),
1561 			 &f->data.tcp_spec.dst_ip[0],
1562 			 &f->data.tcp_spec.src_ip[0],
1563 			 ntohs(f->data.tcp_spec.dst_port),
1564 			 ntohs(f->data.tcp_spec.src_port));
1565 		break;
1566 	case VIRTCHNL_TCP_V6_FLOW:
1567 		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",
1568 			 &f->data.tcp_spec.dst_mac,
1569 			 &f->data.tcp_spec.src_mac,
1570 			 ntohs(f->data.tcp_spec.vlan_id),
1571 			 &f->data.tcp_spec.dst_ip,
1572 			 &f->data.tcp_spec.src_ip,
1573 			 ntohs(f->data.tcp_spec.dst_port),
1574 			 ntohs(f->data.tcp_spec.src_port));
1575 		break;
1576 	}
1577 }
1578 
1579 /**
1580  * iavf_add_cloud_filter
1581  * @adapter: adapter structure
1582  *
1583  * Request that the PF add cloud filters as specified
1584  * by the user via tc tool.
1585  **/
1586 void iavf_add_cloud_filter(struct iavf_adapter *adapter)
1587 {
1588 	struct iavf_cloud_filter *cf;
1589 	struct virtchnl_filter *f;
1590 	int len = 0, count = 0;
1591 
1592 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1593 		/* bail because we already have a command pending */
1594 		dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1595 			adapter->current_op);
1596 		return;
1597 	}
1598 	list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1599 		if (cf->add) {
1600 			count++;
1601 			break;
1602 		}
1603 	}
1604 	if (!count) {
1605 		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER;
1606 		return;
1607 	}
1608 	adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1609 
1610 	len = sizeof(struct virtchnl_filter);
1611 	f = kzalloc(len, GFP_KERNEL);
1612 	if (!f)
1613 		return;
1614 
1615 	list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1616 		if (cf->add) {
1617 			memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1618 			cf->add = false;
1619 			cf->state = __IAVF_CF_ADD_PENDING;
1620 			iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER,
1621 					 (u8 *)f, len);
1622 		}
1623 	}
1624 	kfree(f);
1625 }
1626 
1627 /**
1628  * iavf_del_cloud_filter
1629  * @adapter: adapter structure
1630  *
1631  * Request that the PF delete cloud filters as specified
1632  * by the user via tc tool.
1633  **/
1634 void iavf_del_cloud_filter(struct iavf_adapter *adapter)
1635 {
1636 	struct iavf_cloud_filter *cf, *cftmp;
1637 	struct virtchnl_filter *f;
1638 	int len = 0, count = 0;
1639 
1640 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1641 		/* bail because we already have a command pending */
1642 		dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1643 			adapter->current_op);
1644 		return;
1645 	}
1646 	list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1647 		if (cf->del) {
1648 			count++;
1649 			break;
1650 		}
1651 	}
1652 	if (!count) {
1653 		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER;
1654 		return;
1655 	}
1656 	adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1657 
1658 	len = sizeof(struct virtchnl_filter);
1659 	f = kzalloc(len, GFP_KERNEL);
1660 	if (!f)
1661 		return;
1662 
1663 	list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1664 		if (cf->del) {
1665 			memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1666 			cf->del = false;
1667 			cf->state = __IAVF_CF_DEL_PENDING;
1668 			iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER,
1669 					 (u8 *)f, len);
1670 		}
1671 	}
1672 	kfree(f);
1673 }
1674 
1675 /**
1676  * iavf_add_fdir_filter
1677  * @adapter: the VF adapter structure
1678  *
1679  * Request that the PF add Flow Director filters as specified
1680  * by the user via ethtool.
1681  **/
1682 void iavf_add_fdir_filter(struct iavf_adapter *adapter)
1683 {
1684 	struct iavf_fdir_fltr *fdir;
1685 	struct virtchnl_fdir_add *f;
1686 	bool process_fltr = false;
1687 	int len;
1688 
1689 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1690 		/* bail because we already have a command pending */
1691 		dev_err(&adapter->pdev->dev, "Cannot add Flow Director filter, command %d pending\n",
1692 			adapter->current_op);
1693 		return;
1694 	}
1695 
1696 	len = sizeof(struct virtchnl_fdir_add);
1697 	f = kzalloc(len, GFP_KERNEL);
1698 	if (!f)
1699 		return;
1700 
1701 	spin_lock_bh(&adapter->fdir_fltr_lock);
1702 	list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1703 		if (fdir->state == IAVF_FDIR_FLTR_ADD_REQUEST) {
1704 			process_fltr = true;
1705 			fdir->state = IAVF_FDIR_FLTR_ADD_PENDING;
1706 			memcpy(f, &fdir->vc_add_msg, len);
1707 			break;
1708 		}
1709 	}
1710 	spin_unlock_bh(&adapter->fdir_fltr_lock);
1711 
1712 	if (!process_fltr) {
1713 		/* prevent iavf_add_fdir_filter() from being called when there
1714 		 * are no filters to add
1715 		 */
1716 		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_FDIR_FILTER;
1717 		kfree(f);
1718 		return;
1719 	}
1720 	adapter->current_op = VIRTCHNL_OP_ADD_FDIR_FILTER;
1721 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_FDIR_FILTER, (u8 *)f, len);
1722 	kfree(f);
1723 }
1724 
1725 /**
1726  * iavf_del_fdir_filter
1727  * @adapter: the VF adapter structure
1728  *
1729  * Request that the PF delete Flow Director filters as specified
1730  * by the user via ethtool.
1731  **/
1732 void iavf_del_fdir_filter(struct iavf_adapter *adapter)
1733 {
1734 	struct iavf_fdir_fltr *fdir;
1735 	struct virtchnl_fdir_del f;
1736 	bool process_fltr = false;
1737 	int len;
1738 
1739 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1740 		/* bail because we already have a command pending */
1741 		dev_err(&adapter->pdev->dev, "Cannot remove Flow Director filter, command %d pending\n",
1742 			adapter->current_op);
1743 		return;
1744 	}
1745 
1746 	len = sizeof(struct virtchnl_fdir_del);
1747 
1748 	spin_lock_bh(&adapter->fdir_fltr_lock);
1749 	list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1750 		if (fdir->state == IAVF_FDIR_FLTR_DEL_REQUEST) {
1751 			process_fltr = true;
1752 			memset(&f, 0, len);
1753 			f.vsi_id = fdir->vc_add_msg.vsi_id;
1754 			f.flow_id = fdir->flow_id;
1755 			fdir->state = IAVF_FDIR_FLTR_DEL_PENDING;
1756 			break;
1757 		}
1758 	}
1759 	spin_unlock_bh(&adapter->fdir_fltr_lock);
1760 
1761 	if (!process_fltr) {
1762 		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_FDIR_FILTER;
1763 		return;
1764 	}
1765 
1766 	adapter->current_op = VIRTCHNL_OP_DEL_FDIR_FILTER;
1767 	iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_FDIR_FILTER, (u8 *)&f, len);
1768 }
1769 
1770 /**
1771  * iavf_add_adv_rss_cfg
1772  * @adapter: the VF adapter structure
1773  *
1774  * Request that the PF add RSS configuration as specified
1775  * by the user via ethtool.
1776  **/
1777 void iavf_add_adv_rss_cfg(struct iavf_adapter *adapter)
1778 {
1779 	struct virtchnl_rss_cfg *rss_cfg;
1780 	struct iavf_adv_rss *rss;
1781 	bool process_rss = false;
1782 	int len;
1783 
1784 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1785 		/* bail because we already have a command pending */
1786 		dev_err(&adapter->pdev->dev, "Cannot add RSS configuration, command %d pending\n",
1787 			adapter->current_op);
1788 		return;
1789 	}
1790 
1791 	len = sizeof(struct virtchnl_rss_cfg);
1792 	rss_cfg = kzalloc(len, GFP_KERNEL);
1793 	if (!rss_cfg)
1794 		return;
1795 
1796 	spin_lock_bh(&adapter->adv_rss_lock);
1797 	list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1798 		if (rss->state == IAVF_ADV_RSS_ADD_REQUEST) {
1799 			process_rss = true;
1800 			rss->state = IAVF_ADV_RSS_ADD_PENDING;
1801 			memcpy(rss_cfg, &rss->cfg_msg, len);
1802 			iavf_print_adv_rss_cfg(adapter, rss,
1803 					       "Input set change for",
1804 					       "is pending");
1805 			break;
1806 		}
1807 	}
1808 	spin_unlock_bh(&adapter->adv_rss_lock);
1809 
1810 	if (process_rss) {
1811 		adapter->current_op = VIRTCHNL_OP_ADD_RSS_CFG;
1812 		iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_RSS_CFG,
1813 				 (u8 *)rss_cfg, len);
1814 	} else {
1815 		adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_ADV_RSS_CFG;
1816 	}
1817 
1818 	kfree(rss_cfg);
1819 }
1820 
1821 /**
1822  * iavf_del_adv_rss_cfg
1823  * @adapter: the VF adapter structure
1824  *
1825  * Request that the PF delete RSS configuration as specified
1826  * by the user via ethtool.
1827  **/
1828 void iavf_del_adv_rss_cfg(struct iavf_adapter *adapter)
1829 {
1830 	struct virtchnl_rss_cfg *rss_cfg;
1831 	struct iavf_adv_rss *rss;
1832 	bool process_rss = false;
1833 	int len;
1834 
1835 	if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1836 		/* bail because we already have a command pending */
1837 		dev_err(&adapter->pdev->dev, "Cannot remove RSS configuration, command %d pending\n",
1838 			adapter->current_op);
1839 		return;
1840 	}
1841 
1842 	len = sizeof(struct virtchnl_rss_cfg);
1843 	rss_cfg = kzalloc(len, GFP_KERNEL);
1844 	if (!rss_cfg)
1845 		return;
1846 
1847 	spin_lock_bh(&adapter->adv_rss_lock);
1848 	list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1849 		if (rss->state == IAVF_ADV_RSS_DEL_REQUEST) {
1850 			process_rss = true;
1851 			rss->state = IAVF_ADV_RSS_DEL_PENDING;
1852 			memcpy(rss_cfg, &rss->cfg_msg, len);
1853 			break;
1854 		}
1855 	}
1856 	spin_unlock_bh(&adapter->adv_rss_lock);
1857 
1858 	if (process_rss) {
1859 		adapter->current_op = VIRTCHNL_OP_DEL_RSS_CFG;
1860 		iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_RSS_CFG,
1861 				 (u8 *)rss_cfg, len);
1862 	} else {
1863 		adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_ADV_RSS_CFG;
1864 	}
1865 
1866 	kfree(rss_cfg);
1867 }
1868 
1869 /**
1870  * iavf_request_reset
1871  * @adapter: adapter structure
1872  *
1873  * Request that the PF reset this VF. No response is expected.
1874  **/
1875 int iavf_request_reset(struct iavf_adapter *adapter)
1876 {
1877 	int err;
1878 	/* Don't check CURRENT_OP - this is always higher priority */
1879 	err = iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
1880 	adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1881 	return err;
1882 }
1883 
1884 /**
1885  * iavf_netdev_features_vlan_strip_set - update vlan strip status
1886  * @netdev: ptr to netdev being adjusted
1887  * @enable: enable or disable vlan strip
1888  *
1889  * Helper function to change vlan strip status in netdev->features.
1890  */
1891 static void iavf_netdev_features_vlan_strip_set(struct net_device *netdev,
1892 						const bool enable)
1893 {
1894 	if (enable)
1895 		netdev->features |= NETIF_F_HW_VLAN_CTAG_RX;
1896 	else
1897 		netdev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
1898 }
1899 
1900 /**
1901  * iavf_virtchnl_completion
1902  * @adapter: adapter structure
1903  * @v_opcode: opcode sent by PF
1904  * @v_retval: retval sent by PF
1905  * @msg: message sent by PF
1906  * @msglen: message length
1907  *
1908  * Asynchronous completion function for admin queue messages. Rather than busy
1909  * wait, we fire off our requests and assume that no errors will be returned.
1910  * This function handles the reply messages.
1911  **/
1912 void iavf_virtchnl_completion(struct iavf_adapter *adapter,
1913 			      enum virtchnl_ops v_opcode,
1914 			      enum iavf_status v_retval, u8 *msg, u16 msglen)
1915 {
1916 	struct net_device *netdev = adapter->netdev;
1917 
1918 	if (v_opcode == VIRTCHNL_OP_EVENT) {
1919 		struct virtchnl_pf_event *vpe =
1920 			(struct virtchnl_pf_event *)msg;
1921 		bool link_up = iavf_get_vpe_link_status(adapter, vpe);
1922 
1923 		switch (vpe->event) {
1924 		case VIRTCHNL_EVENT_LINK_CHANGE:
1925 			iavf_set_adapter_link_speed_from_vpe(adapter, vpe);
1926 
1927 			/* we've already got the right link status, bail */
1928 			if (adapter->link_up == link_up)
1929 				break;
1930 
1931 			if (link_up) {
1932 				/* If we get link up message and start queues
1933 				 * before our queues are configured it will
1934 				 * trigger a TX hang. In that case, just ignore
1935 				 * the link status message,we'll get another one
1936 				 * after we enable queues and actually prepared
1937 				 * to send traffic.
1938 				 */
1939 				if (adapter->state != __IAVF_RUNNING)
1940 					break;
1941 
1942 				/* For ADq enabled VF, we reconfigure VSIs and
1943 				 * re-allocate queues. Hence wait till all
1944 				 * queues are enabled.
1945 				 */
1946 				if (adapter->flags &
1947 				    IAVF_FLAG_QUEUES_DISABLED)
1948 					break;
1949 			}
1950 
1951 			adapter->link_up = link_up;
1952 			if (link_up) {
1953 				netif_tx_start_all_queues(netdev);
1954 				netif_carrier_on(netdev);
1955 			} else {
1956 				netif_tx_stop_all_queues(netdev);
1957 				netif_carrier_off(netdev);
1958 			}
1959 			iavf_print_link_message(adapter);
1960 			break;
1961 		case VIRTCHNL_EVENT_RESET_IMPENDING:
1962 			dev_info(&adapter->pdev->dev, "Reset indication received from the PF\n");
1963 			if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) {
1964 				adapter->flags |= IAVF_FLAG_RESET_PENDING;
1965 				dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
1966 				queue_work(adapter->wq, &adapter->reset_task);
1967 			}
1968 			break;
1969 		default:
1970 			dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
1971 				vpe->event);
1972 			break;
1973 		}
1974 		return;
1975 	}
1976 	if (v_retval) {
1977 		switch (v_opcode) {
1978 		case VIRTCHNL_OP_ADD_VLAN:
1979 			dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
1980 				iavf_stat_str(&adapter->hw, v_retval));
1981 			break;
1982 		case VIRTCHNL_OP_ADD_ETH_ADDR:
1983 			dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
1984 				iavf_stat_str(&adapter->hw, v_retval));
1985 			iavf_mac_add_reject(adapter);
1986 			/* restore administratively set MAC address */
1987 			ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1988 			wake_up(&adapter->vc_waitqueue);
1989 			break;
1990 		case VIRTCHNL_OP_DEL_VLAN:
1991 			dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1992 				iavf_stat_str(&adapter->hw, v_retval));
1993 			break;
1994 		case VIRTCHNL_OP_DEL_ETH_ADDR:
1995 			dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1996 				iavf_stat_str(&adapter->hw, v_retval));
1997 			break;
1998 		case VIRTCHNL_OP_ENABLE_CHANNELS:
1999 			dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
2000 				iavf_stat_str(&adapter->hw, v_retval));
2001 			adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2002 			adapter->ch_config.state = __IAVF_TC_INVALID;
2003 			netdev_reset_tc(netdev);
2004 			netif_tx_start_all_queues(netdev);
2005 			break;
2006 		case VIRTCHNL_OP_DISABLE_CHANNELS:
2007 			dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
2008 				iavf_stat_str(&adapter->hw, v_retval));
2009 			adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2010 			adapter->ch_config.state = __IAVF_TC_RUNNING;
2011 			netif_tx_start_all_queues(netdev);
2012 			break;
2013 		case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2014 			struct iavf_cloud_filter *cf, *cftmp;
2015 
2016 			list_for_each_entry_safe(cf, cftmp,
2017 						 &adapter->cloud_filter_list,
2018 						 list) {
2019 				if (cf->state == __IAVF_CF_ADD_PENDING) {
2020 					cf->state = __IAVF_CF_INVALID;
2021 					dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
2022 						 iavf_stat_str(&adapter->hw,
2023 							       v_retval));
2024 					iavf_print_cloud_filter(adapter,
2025 								&cf->f);
2026 					list_del(&cf->list);
2027 					kfree(cf);
2028 					adapter->num_cloud_filters--;
2029 				}
2030 			}
2031 			}
2032 			break;
2033 		case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2034 			struct iavf_cloud_filter *cf;
2035 
2036 			list_for_each_entry(cf, &adapter->cloud_filter_list,
2037 					    list) {
2038 				if (cf->state == __IAVF_CF_DEL_PENDING) {
2039 					cf->state = __IAVF_CF_ACTIVE;
2040 					dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
2041 						 iavf_stat_str(&adapter->hw,
2042 							       v_retval));
2043 					iavf_print_cloud_filter(adapter,
2044 								&cf->f);
2045 				}
2046 			}
2047 			}
2048 			break;
2049 		case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2050 			struct iavf_fdir_fltr *fdir, *fdir_tmp;
2051 
2052 			spin_lock_bh(&adapter->fdir_fltr_lock);
2053 			list_for_each_entry_safe(fdir, fdir_tmp,
2054 						 &adapter->fdir_list_head,
2055 						 list) {
2056 				if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2057 					dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter, error %s\n",
2058 						 iavf_stat_str(&adapter->hw,
2059 							       v_retval));
2060 					iavf_print_fdir_fltr(adapter, fdir);
2061 					if (msglen)
2062 						dev_err(&adapter->pdev->dev,
2063 							"%s\n", msg);
2064 					list_del(&fdir->list);
2065 					kfree(fdir);
2066 					adapter->fdir_active_fltr--;
2067 				}
2068 			}
2069 			spin_unlock_bh(&adapter->fdir_fltr_lock);
2070 			}
2071 			break;
2072 		case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2073 			struct iavf_fdir_fltr *fdir;
2074 
2075 			spin_lock_bh(&adapter->fdir_fltr_lock);
2076 			list_for_each_entry(fdir, &adapter->fdir_list_head,
2077 					    list) {
2078 				if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2079 					fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2080 					dev_info(&adapter->pdev->dev, "Failed to del Flow Director filter, error %s\n",
2081 						 iavf_stat_str(&adapter->hw,
2082 							       v_retval));
2083 					iavf_print_fdir_fltr(adapter, fdir);
2084 				}
2085 			}
2086 			spin_unlock_bh(&adapter->fdir_fltr_lock);
2087 			}
2088 			break;
2089 		case VIRTCHNL_OP_ADD_RSS_CFG: {
2090 			struct iavf_adv_rss *rss, *rss_tmp;
2091 
2092 			spin_lock_bh(&adapter->adv_rss_lock);
2093 			list_for_each_entry_safe(rss, rss_tmp,
2094 						 &adapter->adv_rss_list_head,
2095 						 list) {
2096 				if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2097 					iavf_print_adv_rss_cfg(adapter, rss,
2098 							       "Failed to change the input set for",
2099 							       NULL);
2100 					list_del(&rss->list);
2101 					kfree(rss);
2102 				}
2103 			}
2104 			spin_unlock_bh(&adapter->adv_rss_lock);
2105 			}
2106 			break;
2107 		case VIRTCHNL_OP_DEL_RSS_CFG: {
2108 			struct iavf_adv_rss *rss;
2109 
2110 			spin_lock_bh(&adapter->adv_rss_lock);
2111 			list_for_each_entry(rss, &adapter->adv_rss_list_head,
2112 					    list) {
2113 				if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2114 					rss->state = IAVF_ADV_RSS_ACTIVE;
2115 					dev_err(&adapter->pdev->dev, "Failed to delete RSS configuration, error %s\n",
2116 						iavf_stat_str(&adapter->hw,
2117 							      v_retval));
2118 				}
2119 			}
2120 			spin_unlock_bh(&adapter->adv_rss_lock);
2121 			}
2122 			break;
2123 		case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2124 			dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2125 			/* Vlan stripping could not be enabled by ethtool.
2126 			 * Disable it in netdev->features.
2127 			 */
2128 			iavf_netdev_features_vlan_strip_set(netdev, false);
2129 			break;
2130 		case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2131 			dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2132 			/* Vlan stripping could not be disabled by ethtool.
2133 			 * Enable it in netdev->features.
2134 			 */
2135 			iavf_netdev_features_vlan_strip_set(netdev, true);
2136 			break;
2137 		case VIRTCHNL_OP_ADD_VLAN_V2:
2138 			iavf_vlan_add_reject(adapter);
2139 			dev_warn(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
2140 				 iavf_stat_str(&adapter->hw, v_retval));
2141 			break;
2142 		default:
2143 			dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
2144 				v_retval, iavf_stat_str(&adapter->hw, v_retval),
2145 				v_opcode);
2146 		}
2147 	}
2148 	switch (v_opcode) {
2149 	case VIRTCHNL_OP_ADD_ETH_ADDR:
2150 		if (!v_retval)
2151 			iavf_mac_add_ok(adapter);
2152 		if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr))
2153 			if (!ether_addr_equal(netdev->dev_addr,
2154 					      adapter->hw.mac.addr)) {
2155 				netif_addr_lock_bh(netdev);
2156 				eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2157 				netif_addr_unlock_bh(netdev);
2158 			}
2159 		wake_up(&adapter->vc_waitqueue);
2160 		break;
2161 	case VIRTCHNL_OP_GET_STATS: {
2162 		struct iavf_eth_stats *stats =
2163 			(struct iavf_eth_stats *)msg;
2164 		netdev->stats.rx_packets = stats->rx_unicast +
2165 					   stats->rx_multicast +
2166 					   stats->rx_broadcast;
2167 		netdev->stats.tx_packets = stats->tx_unicast +
2168 					   stats->tx_multicast +
2169 					   stats->tx_broadcast;
2170 		netdev->stats.rx_bytes = stats->rx_bytes;
2171 		netdev->stats.tx_bytes = stats->tx_bytes;
2172 		netdev->stats.tx_errors = stats->tx_errors;
2173 		netdev->stats.rx_dropped = stats->rx_discards;
2174 		netdev->stats.tx_dropped = stats->tx_discards;
2175 		adapter->current_stats = *stats;
2176 		}
2177 		break;
2178 	case VIRTCHNL_OP_GET_VF_RESOURCES: {
2179 		u16 len = sizeof(struct virtchnl_vf_resource) +
2180 			  IAVF_MAX_VF_VSI *
2181 			  sizeof(struct virtchnl_vsi_resource);
2182 		memcpy(adapter->vf_res, msg, min(msglen, len));
2183 		iavf_validate_num_queues(adapter);
2184 		iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
2185 		if (is_zero_ether_addr(adapter->hw.mac.addr)) {
2186 			/* restore current mac address */
2187 			ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2188 		} else {
2189 			netif_addr_lock_bh(netdev);
2190 			/* refresh current mac address if changed */
2191 			ether_addr_copy(netdev->perm_addr,
2192 					adapter->hw.mac.addr);
2193 			netif_addr_unlock_bh(netdev);
2194 		}
2195 		spin_lock_bh(&adapter->mac_vlan_list_lock);
2196 		iavf_add_filter(adapter, adapter->hw.mac.addr);
2197 
2198 		if (VLAN_ALLOWED(adapter)) {
2199 			if (!list_empty(&adapter->vlan_filter_list)) {
2200 				struct iavf_vlan_filter *vlf;
2201 
2202 				/* re-add all VLAN filters over virtchnl */
2203 				list_for_each_entry(vlf,
2204 						    &adapter->vlan_filter_list,
2205 						    list)
2206 					vlf->state = IAVF_VLAN_ADD;
2207 
2208 				adapter->aq_required |=
2209 					IAVF_FLAG_AQ_ADD_VLAN_FILTER;
2210 			}
2211 		}
2212 
2213 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
2214 
2215 		iavf_parse_vf_resource_msg(adapter);
2216 
2217 		/* negotiated VIRTCHNL_VF_OFFLOAD_VLAN_V2, so wait for the
2218 		 * response to VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS to finish
2219 		 * configuration
2220 		 */
2221 		if (VLAN_V2_ALLOWED(adapter))
2222 			break;
2223 		/* fallthrough and finish config if VIRTCHNL_VF_OFFLOAD_VLAN_V2
2224 		 * wasn't successfully negotiated with the PF
2225 		 */
2226 		}
2227 		fallthrough;
2228 	case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS: {
2229 		struct iavf_mac_filter *f;
2230 		bool was_mac_changed;
2231 		u64 aq_required = 0;
2232 
2233 		if (v_opcode == VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS)
2234 			memcpy(&adapter->vlan_v2_caps, msg,
2235 			       min_t(u16, msglen,
2236 				     sizeof(adapter->vlan_v2_caps)));
2237 
2238 		iavf_process_config(adapter);
2239 		adapter->flags |= IAVF_FLAG_SETUP_NETDEV_FEATURES;
2240 
2241 		/* Request VLAN offload settings */
2242 		if (VLAN_V2_ALLOWED(adapter))
2243 			iavf_set_vlan_offload_features(adapter, 0,
2244 						       netdev->features);
2245 
2246 		iavf_set_queue_vlan_tag_loc(adapter);
2247 
2248 		was_mac_changed = !ether_addr_equal(netdev->dev_addr,
2249 						    adapter->hw.mac.addr);
2250 
2251 		spin_lock_bh(&adapter->mac_vlan_list_lock);
2252 
2253 		/* re-add all MAC filters */
2254 		list_for_each_entry(f, &adapter->mac_filter_list, list) {
2255 			if (was_mac_changed &&
2256 			    ether_addr_equal(netdev->dev_addr, f->macaddr))
2257 				ether_addr_copy(f->macaddr,
2258 						adapter->hw.mac.addr);
2259 
2260 			f->is_new_mac = true;
2261 			f->add = true;
2262 			f->add_handled = false;
2263 			f->remove = false;
2264 		}
2265 
2266 		/* re-add all VLAN filters */
2267 		if (VLAN_FILTERING_ALLOWED(adapter)) {
2268 			struct iavf_vlan_filter *vlf;
2269 
2270 			if (!list_empty(&adapter->vlan_filter_list)) {
2271 				list_for_each_entry(vlf,
2272 						    &adapter->vlan_filter_list,
2273 						    list)
2274 					vlf->state = IAVF_VLAN_ADD;
2275 
2276 				aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER;
2277 			}
2278 		}
2279 
2280 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
2281 
2282 		netif_addr_lock_bh(netdev);
2283 		eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2284 		netif_addr_unlock_bh(netdev);
2285 
2286 		adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER |
2287 			aq_required;
2288 		}
2289 		break;
2290 	case VIRTCHNL_OP_ENABLE_QUEUES:
2291 		/* enable transmits */
2292 		iavf_irq_enable(adapter, true);
2293 		adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED;
2294 		break;
2295 	case VIRTCHNL_OP_DISABLE_QUEUES:
2296 		iavf_free_all_tx_resources(adapter);
2297 		iavf_free_all_rx_resources(adapter);
2298 		if (adapter->state == __IAVF_DOWN_PENDING) {
2299 			iavf_change_state(adapter, __IAVF_DOWN);
2300 			wake_up(&adapter->down_waitqueue);
2301 		}
2302 		break;
2303 	case VIRTCHNL_OP_VERSION:
2304 	case VIRTCHNL_OP_CONFIG_IRQ_MAP:
2305 		/* Don't display an error if we get these out of sequence.
2306 		 * If the firmware needed to get kicked, we'll get these and
2307 		 * it's no problem.
2308 		 */
2309 		if (v_opcode != adapter->current_op)
2310 			return;
2311 		break;
2312 	case VIRTCHNL_OP_RDMA:
2313 		/* Gobble zero-length replies from the PF. They indicate that
2314 		 * a previous message was received OK, and the client doesn't
2315 		 * care about that.
2316 		 */
2317 		if (msglen && CLIENT_ENABLED(adapter))
2318 			iavf_notify_client_message(&adapter->vsi, msg, msglen);
2319 		break;
2320 
2321 	case VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP:
2322 		adapter->client_pending &=
2323 				~(BIT(VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP));
2324 		break;
2325 	case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
2326 		struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
2327 
2328 		if (msglen == sizeof(*vrh))
2329 			adapter->hena = vrh->hena;
2330 		else
2331 			dev_warn(&adapter->pdev->dev,
2332 				 "Invalid message %d from PF\n", v_opcode);
2333 		}
2334 		break;
2335 	case VIRTCHNL_OP_REQUEST_QUEUES: {
2336 		struct virtchnl_vf_res_request *vfres =
2337 			(struct virtchnl_vf_res_request *)msg;
2338 
2339 		if (vfres->num_queue_pairs != adapter->num_req_queues) {
2340 			dev_info(&adapter->pdev->dev,
2341 				 "Requested %d queues, PF can support %d\n",
2342 				 adapter->num_req_queues,
2343 				 vfres->num_queue_pairs);
2344 			adapter->num_req_queues = 0;
2345 			adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2346 		}
2347 		}
2348 		break;
2349 	case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2350 		struct iavf_cloud_filter *cf;
2351 
2352 		list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
2353 			if (cf->state == __IAVF_CF_ADD_PENDING)
2354 				cf->state = __IAVF_CF_ACTIVE;
2355 		}
2356 		}
2357 		break;
2358 	case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2359 		struct iavf_cloud_filter *cf, *cftmp;
2360 
2361 		list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
2362 					 list) {
2363 			if (cf->state == __IAVF_CF_DEL_PENDING) {
2364 				cf->state = __IAVF_CF_INVALID;
2365 				list_del(&cf->list);
2366 				kfree(cf);
2367 				adapter->num_cloud_filters--;
2368 			}
2369 		}
2370 		}
2371 		break;
2372 	case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2373 		struct virtchnl_fdir_add *add_fltr = (struct virtchnl_fdir_add *)msg;
2374 		struct iavf_fdir_fltr *fdir, *fdir_tmp;
2375 
2376 		spin_lock_bh(&adapter->fdir_fltr_lock);
2377 		list_for_each_entry_safe(fdir, fdir_tmp,
2378 					 &adapter->fdir_list_head,
2379 					 list) {
2380 			if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2381 				if (add_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2382 					dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is added\n",
2383 						 fdir->loc);
2384 					fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2385 					fdir->flow_id = add_fltr->flow_id;
2386 				} else {
2387 					dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter with status: %d\n",
2388 						 add_fltr->status);
2389 					iavf_print_fdir_fltr(adapter, fdir);
2390 					list_del(&fdir->list);
2391 					kfree(fdir);
2392 					adapter->fdir_active_fltr--;
2393 				}
2394 			}
2395 		}
2396 		spin_unlock_bh(&adapter->fdir_fltr_lock);
2397 		}
2398 		break;
2399 	case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2400 		struct virtchnl_fdir_del *del_fltr = (struct virtchnl_fdir_del *)msg;
2401 		struct iavf_fdir_fltr *fdir, *fdir_tmp;
2402 
2403 		spin_lock_bh(&adapter->fdir_fltr_lock);
2404 		list_for_each_entry_safe(fdir, fdir_tmp, &adapter->fdir_list_head,
2405 					 list) {
2406 			if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2407 				if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2408 					dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is deleted\n",
2409 						 fdir->loc);
2410 					list_del(&fdir->list);
2411 					kfree(fdir);
2412 					adapter->fdir_active_fltr--;
2413 				} else {
2414 					fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2415 					dev_info(&adapter->pdev->dev, "Failed to delete Flow Director filter with status: %d\n",
2416 						 del_fltr->status);
2417 					iavf_print_fdir_fltr(adapter, fdir);
2418 				}
2419 			}
2420 		}
2421 		spin_unlock_bh(&adapter->fdir_fltr_lock);
2422 		}
2423 		break;
2424 	case VIRTCHNL_OP_ADD_RSS_CFG: {
2425 		struct iavf_adv_rss *rss;
2426 
2427 		spin_lock_bh(&adapter->adv_rss_lock);
2428 		list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
2429 			if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2430 				iavf_print_adv_rss_cfg(adapter, rss,
2431 						       "Input set change for",
2432 						       "successful");
2433 				rss->state = IAVF_ADV_RSS_ACTIVE;
2434 			}
2435 		}
2436 		spin_unlock_bh(&adapter->adv_rss_lock);
2437 		}
2438 		break;
2439 	case VIRTCHNL_OP_DEL_RSS_CFG: {
2440 		struct iavf_adv_rss *rss, *rss_tmp;
2441 
2442 		spin_lock_bh(&adapter->adv_rss_lock);
2443 		list_for_each_entry_safe(rss, rss_tmp,
2444 					 &adapter->adv_rss_list_head, list) {
2445 			if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2446 				list_del(&rss->list);
2447 				kfree(rss);
2448 			}
2449 		}
2450 		spin_unlock_bh(&adapter->adv_rss_lock);
2451 		}
2452 		break;
2453 	case VIRTCHNL_OP_ADD_VLAN_V2: {
2454 		struct iavf_vlan_filter *f;
2455 
2456 		spin_lock_bh(&adapter->mac_vlan_list_lock);
2457 		list_for_each_entry(f, &adapter->vlan_filter_list, list) {
2458 			if (f->state == IAVF_VLAN_IS_NEW)
2459 				f->state = IAVF_VLAN_ACTIVE;
2460 		}
2461 		spin_unlock_bh(&adapter->mac_vlan_list_lock);
2462 		}
2463 		break;
2464 	case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2465 		/* PF enabled vlan strip on this VF.
2466 		 * Update netdev->features if needed to be in sync with ethtool.
2467 		 */
2468 		if (!v_retval)
2469 			iavf_netdev_features_vlan_strip_set(netdev, true);
2470 		break;
2471 	case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2472 		/* PF disabled vlan strip on this VF.
2473 		 * Update netdev->features if needed to be in sync with ethtool.
2474 		 */
2475 		if (!v_retval)
2476 			iavf_netdev_features_vlan_strip_set(netdev, false);
2477 		break;
2478 	default:
2479 		if (adapter->current_op && (v_opcode != adapter->current_op))
2480 			dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
2481 				 adapter->current_op, v_opcode);
2482 		break;
2483 	} /* switch v_opcode */
2484 	adapter->current_op = VIRTCHNL_OP_UNKNOWN;
2485 }
2486