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