1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
5 #include "iavf_prototype.h"
9 * @adapter: adapter structure
10 * @op: virtual channel opcode
11 * @msg: pointer to message buffer
12 * @len: message length
14 * Send message to PF and print status if failure.
16 static int iavf_send_pf_msg(struct iavf_adapter *adapter,
17 enum virtchnl_ops op, u8 *msg, u16 len)
19 struct iavf_hw *hw = &adapter->hw;
20 enum iavf_status status;
22 if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)
23 return 0; /* nothing to see here, move along */
25 status = iavf_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
27 dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, status %s, aq_err %s\n",
28 op, iavf_stat_str(hw, status),
29 iavf_aq_str(hw, hw->aq.asq_last_status));
30 return iavf_status_to_errno(status);
35 * @adapter: adapter structure
37 * Send API version admin queue message to the PF. The reply is not checked
38 * in this function. Returns 0 if the message was successfully
39 * sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
41 int iavf_send_api_ver(struct iavf_adapter *adapter)
43 struct virtchnl_version_info vvi;
45 vvi.major = VIRTCHNL_VERSION_MAJOR;
46 vvi.minor = VIRTCHNL_VERSION_MINOR;
48 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
53 * iavf_poll_virtchnl_msg
54 * @hw: HW configuration structure
55 * @event: event to populate on success
56 * @op_to_poll: requested virtchnl op to poll for
58 * Initialize poll for virtchnl msg matching the requested_op. Returns 0
59 * if a message of the correct opcode is in the queue or an error code
60 * if no message matching the op code is waiting and other failures.
63 iavf_poll_virtchnl_msg(struct iavf_hw *hw, struct iavf_arq_event_info *event,
64 enum virtchnl_ops op_to_poll)
66 enum virtchnl_ops received_op;
67 enum iavf_status status;
71 /* When the AQ is empty, iavf_clean_arq_element will return
72 * nonzero and this loop will terminate.
74 status = iavf_clean_arq_element(hw, event, NULL);
75 if (status != IAVF_SUCCESS)
76 return iavf_status_to_errno(status);
78 (enum virtchnl_ops)le32_to_cpu(event->desc.cookie_high);
79 if (op_to_poll == received_op)
83 v_retval = le32_to_cpu(event->desc.cookie_low);
84 return virtchnl_status_to_errno((enum virtchnl_status_code)v_retval);
89 * @adapter: adapter structure
91 * Compare API versions with the PF. Must be called after admin queue is
92 * initialized. Returns 0 if API versions match, -EIO if they do not,
93 * IAVF_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
94 * from the firmware are propagated.
96 int iavf_verify_api_ver(struct iavf_adapter *adapter)
98 struct iavf_arq_event_info event;
101 event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
102 event.msg_buf = kzalloc(IAVF_MAX_AQ_BUF_SIZE, GFP_KERNEL);
106 err = iavf_poll_virtchnl_msg(&adapter->hw, &event, VIRTCHNL_OP_VERSION);
108 struct virtchnl_version_info *pf_vvi =
109 (struct virtchnl_version_info *)event.msg_buf;
110 adapter->pf_version = *pf_vvi;
112 if (pf_vvi->major > VIRTCHNL_VERSION_MAJOR ||
113 (pf_vvi->major == VIRTCHNL_VERSION_MAJOR &&
114 pf_vvi->minor > VIRTCHNL_VERSION_MINOR))
118 kfree(event.msg_buf);
124 * iavf_send_vf_config_msg
125 * @adapter: adapter structure
127 * Send VF configuration request admin queue message to the PF. The reply
128 * is not checked in this function. Returns 0 if the message was
129 * successfully sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
131 int iavf_send_vf_config_msg(struct iavf_adapter *adapter)
135 caps = VIRTCHNL_VF_OFFLOAD_L2 |
136 VIRTCHNL_VF_OFFLOAD_RSS_PF |
137 VIRTCHNL_VF_OFFLOAD_RSS_AQ |
138 VIRTCHNL_VF_OFFLOAD_RSS_REG |
139 VIRTCHNL_VF_OFFLOAD_VLAN |
140 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
141 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
142 VIRTCHNL_VF_OFFLOAD_ENCAP |
143 VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
144 VIRTCHNL_VF_OFFLOAD_CRC |
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;
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));
159 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
163 int iavf_send_vf_offload_vlan_v2_msg(struct iavf_adapter *adapter)
165 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_OFFLOAD_VLAN_V2_CAPS;
167 if (!VLAN_V2_ALLOWED(adapter))
170 adapter->current_op = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
172 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
177 * iavf_validate_num_queues
178 * @adapter: adapter structure
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.
183 static void iavf_validate_num_queues(struct iavf_adapter *adapter)
185 if (adapter->vf_res->num_queue_pairs > IAVF_MAX_REQ_QUEUES) {
186 struct virtchnl_vsi_resource *vsi_res;
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;
204 * @adapter: private adapter structure
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.
211 int iavf_get_vf_config(struct iavf_adapter *adapter)
213 struct iavf_hw *hw = &adapter->hw;
214 struct iavf_arq_event_info event;
218 len = IAVF_VIRTCHNL_VF_RESOURCE_SIZE;
220 event.msg_buf = kzalloc(len, GFP_KERNEL);
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));
227 /* some PFs send more queues than we should have so validate that
228 * we aren't getting too many queues
231 iavf_validate_num_queues(adapter);
232 iavf_vf_parse_hw_config(hw, adapter->vf_res);
234 kfree(event.msg_buf);
239 int iavf_get_vf_vlan_v2_caps(struct iavf_adapter *adapter)
241 struct iavf_arq_event_info event;
245 len = sizeof(struct virtchnl_vlan_caps);
247 event.msg_buf = kzalloc(len, GFP_KERNEL);
251 err = iavf_poll_virtchnl_msg(&adapter->hw, &event,
252 VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS);
254 memcpy(&adapter->vlan_v2_caps, event.msg_buf,
255 min(event.msg_len, len));
257 kfree(event.msg_buf);
263 * iavf_configure_queues
264 * @adapter: adapter structure
266 * Request that the PF set up our (previously allocated) queues.
268 void iavf_configure_queues(struct iavf_adapter *adapter)
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;
276 if (max_frame > IAVF_MAX_RXBUFFER || !max_frame)
277 max_frame = IAVF_MAX_RXBUFFER;
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);
285 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
286 len = virtchnl_struct_size(vqci, qpair, pairs);
287 vqci = kzalloc(len, GFP_KERNEL);
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;
296 vqci->vsi_id = adapter->vsi_res->vsi_id;
297 vqci->num_queue_pairs = pairs;
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.
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 if (CRC_OFFLOAD_ALLOWED(adapter))
316 vqpi->rxq.crc_disable = !!(adapter->netdev->features &
321 adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES;
322 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
329 * @adapter: adapter structure
331 * Request that the PF enable all of our queues.
333 void iavf_enable_queues(struct iavf_adapter *adapter)
335 struct virtchnl_queue_select vqs;
337 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
338 /* bail because we already have a command pending */
339 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
340 adapter->current_op);
343 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
344 vqs.vsi_id = adapter->vsi_res->vsi_id;
345 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
346 vqs.rx_queues = vqs.tx_queues;
347 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_QUEUES;
348 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
349 (u8 *)&vqs, sizeof(vqs));
353 * iavf_disable_queues
354 * @adapter: adapter structure
356 * Request that the PF disable all of our queues.
358 void iavf_disable_queues(struct iavf_adapter *adapter)
360 struct virtchnl_queue_select vqs;
362 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
363 /* bail because we already have a command pending */
364 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
365 adapter->current_op);
368 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
369 vqs.vsi_id = adapter->vsi_res->vsi_id;
370 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
371 vqs.rx_queues = vqs.tx_queues;
372 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_QUEUES;
373 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
374 (u8 *)&vqs, sizeof(vqs));
379 * @adapter: adapter structure
381 * Request that the PF map queues to interrupt vectors. Misc causes, including
382 * admin queue, are always mapped to vector 0.
384 void iavf_map_queues(struct iavf_adapter *adapter)
386 struct virtchnl_irq_map_info *vimi;
387 struct virtchnl_vector_map *vecmap;
388 struct iavf_q_vector *q_vector;
389 int v_idx, q_vectors;
392 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
393 /* bail because we already have a command pending */
394 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
395 adapter->current_op);
398 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
400 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
402 len = virtchnl_struct_size(vimi, vecmap, adapter->num_msix_vectors);
403 vimi = kzalloc(len, GFP_KERNEL);
407 vimi->num_vectors = adapter->num_msix_vectors;
408 /* Queue vectors first */
409 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
410 q_vector = &adapter->q_vectors[v_idx];
411 vecmap = &vimi->vecmap[v_idx];
413 vecmap->vsi_id = adapter->vsi_res->vsi_id;
414 vecmap->vector_id = v_idx + NONQ_VECS;
415 vecmap->txq_map = q_vector->ring_mask;
416 vecmap->rxq_map = q_vector->ring_mask;
417 vecmap->rxitr_idx = IAVF_RX_ITR;
418 vecmap->txitr_idx = IAVF_TX_ITR;
420 /* Misc vector last - this is only for AdminQ messages */
421 vecmap = &vimi->vecmap[v_idx];
422 vecmap->vsi_id = adapter->vsi_res->vsi_id;
423 vecmap->vector_id = 0;
427 adapter->aq_required &= ~IAVF_FLAG_AQ_MAP_VECTORS;
428 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
434 * iavf_set_mac_addr_type - Set the correct request type from the filter type
435 * @virtchnl_ether_addr: pointer to requested list element
436 * @filter: pointer to requested filter
439 iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr,
440 const struct iavf_mac_filter *filter)
442 virtchnl_ether_addr->type = filter->is_primary ?
443 VIRTCHNL_ETHER_ADDR_PRIMARY :
444 VIRTCHNL_ETHER_ADDR_EXTRA;
448 * iavf_add_ether_addrs
449 * @adapter: adapter structure
451 * Request that the PF add one or more addresses to our filters.
453 void iavf_add_ether_addrs(struct iavf_adapter *adapter)
455 struct virtchnl_ether_addr_list *veal;
456 struct iavf_mac_filter *f;
457 int i = 0, count = 0;
461 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
462 /* bail because we already have a command pending */
463 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
464 adapter->current_op);
468 spin_lock_bh(&adapter->mac_vlan_list_lock);
470 list_for_each_entry(f, &adapter->mac_filter_list, list) {
475 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
476 spin_unlock_bh(&adapter->mac_vlan_list_lock);
479 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
481 len = virtchnl_struct_size(veal, list, count);
482 if (len > IAVF_MAX_AQ_BUF_SIZE) {
483 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
484 while (len > IAVF_MAX_AQ_BUF_SIZE)
485 len = virtchnl_struct_size(veal, list, --count);
489 veal = kzalloc(len, GFP_ATOMIC);
491 spin_unlock_bh(&adapter->mac_vlan_list_lock);
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) {
499 ether_addr_copy(veal->list[i].addr, f->macaddr);
500 iavf_set_mac_addr_type(&veal->list[i], f);
508 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
510 spin_unlock_bh(&adapter->mac_vlan_list_lock);
512 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len);
517 * iavf_del_ether_addrs
518 * @adapter: adapter structure
520 * Request that the PF remove one or more addresses from our filters.
522 void iavf_del_ether_addrs(struct iavf_adapter *adapter)
524 struct virtchnl_ether_addr_list *veal;
525 struct iavf_mac_filter *f, *ftmp;
526 int i = 0, count = 0;
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);
537 spin_lock_bh(&adapter->mac_vlan_list_lock);
539 list_for_each_entry(f, &adapter->mac_filter_list, list) {
544 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
545 spin_unlock_bh(&adapter->mac_vlan_list_lock);
548 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
550 len = virtchnl_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 while (len > IAVF_MAX_AQ_BUF_SIZE)
554 len = virtchnl_struct_size(veal, list, --count);
557 veal = kzalloc(len, GFP_ATOMIC);
559 spin_unlock_bh(&adapter->mac_vlan_list_lock);
563 veal->vsi_id = adapter->vsi_res->vsi_id;
564 veal->num_elements = count;
565 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
567 ether_addr_copy(veal->list[i].addr, f->macaddr);
568 iavf_set_mac_addr_type(&veal->list[i], f);
577 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
579 spin_unlock_bh(&adapter->mac_vlan_list_lock);
581 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, (u8 *)veal, len);
587 * @adapter: adapter structure
589 * Submit list of filters based on PF response.
591 static void iavf_mac_add_ok(struct iavf_adapter *adapter)
593 struct iavf_mac_filter *f, *ftmp;
595 spin_lock_bh(&adapter->mac_vlan_list_lock);
596 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
597 f->is_new_mac = false;
598 if (!f->add && !f->add_handled)
599 f->add_handled = true;
601 spin_unlock_bh(&adapter->mac_vlan_list_lock);
605 * iavf_mac_add_reject
606 * @adapter: adapter structure
608 * Remove filters from list based on PF response.
610 static void iavf_mac_add_reject(struct iavf_adapter *adapter)
612 struct net_device *netdev = adapter->netdev;
613 struct iavf_mac_filter *f, *ftmp;
615 spin_lock_bh(&adapter->mac_vlan_list_lock);
616 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
617 if (f->remove && ether_addr_equal(f->macaddr, netdev->dev_addr))
620 if (!f->add && !f->add_handled)
621 f->add_handled = true;
628 spin_unlock_bh(&adapter->mac_vlan_list_lock);
632 * iavf_vlan_add_reject
633 * @adapter: adapter structure
635 * Remove VLAN filters from list based on PF response.
637 static void iavf_vlan_add_reject(struct iavf_adapter *adapter)
639 struct iavf_vlan_filter *f, *ftmp;
641 spin_lock_bh(&adapter->mac_vlan_list_lock);
642 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
643 if (f->state == IAVF_VLAN_IS_NEW) {
646 adapter->num_vlan_filters--;
649 spin_unlock_bh(&adapter->mac_vlan_list_lock);
654 * @adapter: adapter structure
656 * Request that the PF add one or more VLAN filters to our VSI.
658 void iavf_add_vlans(struct iavf_adapter *adapter)
660 int len, i = 0, count = 0;
661 struct iavf_vlan_filter *f;
664 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
665 /* bail because we already have a command pending */
666 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
667 adapter->current_op);
671 spin_lock_bh(&adapter->mac_vlan_list_lock);
673 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
674 if (f->state == IAVF_VLAN_ADD)
677 if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
678 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
679 spin_unlock_bh(&adapter->mac_vlan_list_lock);
683 if (VLAN_ALLOWED(adapter)) {
684 struct virtchnl_vlan_filter_list *vvfl;
686 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
688 len = virtchnl_struct_size(vvfl, vlan_id, count);
689 if (len > IAVF_MAX_AQ_BUF_SIZE) {
690 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
691 while (len > IAVF_MAX_AQ_BUF_SIZE)
692 len = virtchnl_struct_size(vvfl, vlan_id,
696 vvfl = kzalloc(len, GFP_ATOMIC);
698 spin_unlock_bh(&adapter->mac_vlan_list_lock);
702 vvfl->vsi_id = adapter->vsi_res->vsi_id;
703 vvfl->num_elements = count;
704 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
705 if (f->state == IAVF_VLAN_ADD) {
706 vvfl->vlan_id[i] = f->vlan.vid;
708 f->state = IAVF_VLAN_IS_NEW;
714 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
716 spin_unlock_bh(&adapter->mac_vlan_list_lock);
718 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
721 u16 max_vlans = adapter->vlan_v2_caps.filtering.max_filters;
722 u16 current_vlans = iavf_get_num_vlans_added(adapter);
723 struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
725 adapter->current_op = VIRTCHNL_OP_ADD_VLAN_V2;
727 if ((count + current_vlans) > max_vlans &&
728 current_vlans < max_vlans) {
729 count = max_vlans - iavf_get_num_vlans_added(adapter);
733 len = virtchnl_struct_size(vvfl_v2, filters, count);
734 if (len > IAVF_MAX_AQ_BUF_SIZE) {
735 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
736 while (len > IAVF_MAX_AQ_BUF_SIZE)
737 len = virtchnl_struct_size(vvfl_v2, filters,
742 vvfl_v2 = kzalloc(len, GFP_ATOMIC);
744 spin_unlock_bh(&adapter->mac_vlan_list_lock);
748 vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
749 vvfl_v2->num_elements = count;
750 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
751 if (f->state == IAVF_VLAN_ADD) {
752 struct virtchnl_vlan_supported_caps *filtering_support =
753 &adapter->vlan_v2_caps.filtering.filtering_support;
754 struct virtchnl_vlan *vlan;
759 /* give priority over outer if it's enabled */
760 if (filtering_support->outer)
761 vlan = &vvfl_v2->filters[i].outer;
763 vlan = &vvfl_v2->filters[i].inner;
765 vlan->tci = f->vlan.vid;
766 vlan->tpid = f->vlan.tpid;
769 f->state = IAVF_VLAN_IS_NEW;
774 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
776 spin_unlock_bh(&adapter->mac_vlan_list_lock);
778 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN_V2,
786 * @adapter: adapter structure
788 * Request that the PF remove one or more VLAN filters from our VSI.
790 void iavf_del_vlans(struct iavf_adapter *adapter)
792 struct iavf_vlan_filter *f, *ftmp;
793 int len, i = 0, count = 0;
796 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
797 /* bail because we already have a command pending */
798 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
799 adapter->current_op);
803 spin_lock_bh(&adapter->mac_vlan_list_lock);
805 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
806 /* since VLAN capabilities are not allowed, we dont want to send
807 * a VLAN delete request because it will most likely fail and
808 * create unnecessary errors/noise, so just free the VLAN
809 * filters marked for removal to enable bailing out before
810 * sending a virtchnl message
812 if (f->state == IAVF_VLAN_REMOVE &&
813 !VLAN_FILTERING_ALLOWED(adapter)) {
816 adapter->num_vlan_filters--;
817 } else if (f->state == IAVF_VLAN_DISABLE &&
818 !VLAN_FILTERING_ALLOWED(adapter)) {
819 f->state = IAVF_VLAN_INACTIVE;
820 } else if (f->state == IAVF_VLAN_REMOVE ||
821 f->state == IAVF_VLAN_DISABLE) {
825 if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
826 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
827 spin_unlock_bh(&adapter->mac_vlan_list_lock);
831 if (VLAN_ALLOWED(adapter)) {
832 struct virtchnl_vlan_filter_list *vvfl;
834 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
836 len = virtchnl_struct_size(vvfl, vlan_id, count);
837 if (len > IAVF_MAX_AQ_BUF_SIZE) {
838 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
839 while (len > IAVF_MAX_AQ_BUF_SIZE)
840 len = virtchnl_struct_size(vvfl, vlan_id,
844 vvfl = kzalloc(len, GFP_ATOMIC);
846 spin_unlock_bh(&adapter->mac_vlan_list_lock);
850 vvfl->vsi_id = adapter->vsi_res->vsi_id;
851 vvfl->num_elements = count;
852 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
853 if (f->state == IAVF_VLAN_DISABLE) {
854 vvfl->vlan_id[i] = f->vlan.vid;
855 f->state = IAVF_VLAN_INACTIVE;
859 } else if (f->state == IAVF_VLAN_REMOVE) {
860 vvfl->vlan_id[i] = f->vlan.vid;
863 adapter->num_vlan_filters--;
871 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
873 spin_unlock_bh(&adapter->mac_vlan_list_lock);
875 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
878 struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
880 adapter->current_op = VIRTCHNL_OP_DEL_VLAN_V2;
882 len = virtchnl_struct_size(vvfl_v2, filters, count);
883 if (len > IAVF_MAX_AQ_BUF_SIZE) {
884 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
885 while (len > IAVF_MAX_AQ_BUF_SIZE)
886 len = virtchnl_struct_size(vvfl_v2, filters,
891 vvfl_v2 = kzalloc(len, GFP_ATOMIC);
893 spin_unlock_bh(&adapter->mac_vlan_list_lock);
897 vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
898 vvfl_v2->num_elements = count;
899 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
900 if (f->state == IAVF_VLAN_DISABLE ||
901 f->state == IAVF_VLAN_REMOVE) {
902 struct virtchnl_vlan_supported_caps *filtering_support =
903 &adapter->vlan_v2_caps.filtering.filtering_support;
904 struct virtchnl_vlan *vlan;
906 /* give priority over outer if it's enabled */
907 if (filtering_support->outer)
908 vlan = &vvfl_v2->filters[i].outer;
910 vlan = &vvfl_v2->filters[i].inner;
912 vlan->tci = f->vlan.vid;
913 vlan->tpid = f->vlan.tpid;
915 if (f->state == IAVF_VLAN_DISABLE) {
916 f->state = IAVF_VLAN_INACTIVE;
920 adapter->num_vlan_filters--;
929 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
931 spin_unlock_bh(&adapter->mac_vlan_list_lock);
933 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN_V2,
940 * iavf_set_promiscuous
941 * @adapter: adapter structure
943 * Request that the PF enable promiscuous mode for our VSI.
945 void iavf_set_promiscuous(struct iavf_adapter *adapter)
947 struct net_device *netdev = adapter->netdev;
948 struct virtchnl_promisc_info vpi;
951 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
952 /* bail because we already have a command pending */
953 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
954 adapter->current_op);
958 /* prevent changes to promiscuous flags */
959 spin_lock_bh(&adapter->current_netdev_promisc_flags_lock);
961 /* sanity check to prevent duplicate AQ calls */
962 if (!iavf_promiscuous_mode_changed(adapter)) {
963 adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_PROMISC_MODE;
964 dev_dbg(&adapter->pdev->dev, "No change in promiscuous mode\n");
965 /* allow changes to promiscuous flags */
966 spin_unlock_bh(&adapter->current_netdev_promisc_flags_lock);
970 /* there are 2 bits, but only 3 states */
971 if (!(netdev->flags & IFF_PROMISC) &&
972 netdev->flags & IFF_ALLMULTI) {
973 /* State 1 - only multicast promiscuous mode enabled
974 * - !IFF_PROMISC && IFF_ALLMULTI
976 flags = FLAG_VF_MULTICAST_PROMISC;
977 adapter->current_netdev_promisc_flags |= IFF_ALLMULTI;
978 adapter->current_netdev_promisc_flags &= ~IFF_PROMISC;
979 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
980 } else if (!(netdev->flags & IFF_PROMISC) &&
981 !(netdev->flags & IFF_ALLMULTI)) {
982 /* State 2 - unicast/multicast promiscuous mode disabled
983 * - !IFF_PROMISC && !IFF_ALLMULTI
986 adapter->current_netdev_promisc_flags &=
987 ~(IFF_PROMISC | IFF_ALLMULTI);
988 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
990 /* State 3 - unicast/multicast promiscuous mode enabled
991 * - IFF_PROMISC && IFF_ALLMULTI
992 * - IFF_PROMISC && !IFF_ALLMULTI
994 flags = FLAG_VF_UNICAST_PROMISC | FLAG_VF_MULTICAST_PROMISC;
995 adapter->current_netdev_promisc_flags |= IFF_PROMISC;
996 if (netdev->flags & IFF_ALLMULTI)
997 adapter->current_netdev_promisc_flags |= IFF_ALLMULTI;
999 adapter->current_netdev_promisc_flags &= ~IFF_ALLMULTI;
1001 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
1004 adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_PROMISC_MODE;
1006 /* allow changes to promiscuous flags */
1007 spin_unlock_bh(&adapter->current_netdev_promisc_flags_lock);
1009 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
1010 vpi.vsi_id = adapter->vsi_res->vsi_id;
1012 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1013 (u8 *)&vpi, sizeof(vpi));
1017 * iavf_request_stats
1018 * @adapter: adapter structure
1020 * Request VSI statistics from PF.
1022 void iavf_request_stats(struct iavf_adapter *adapter)
1024 struct virtchnl_queue_select vqs;
1026 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1027 /* no error message, this isn't crucial */
1031 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_STATS;
1032 adapter->current_op = VIRTCHNL_OP_GET_STATS;
1033 vqs.vsi_id = adapter->vsi_res->vsi_id;
1034 /* queue maps are ignored for this message - only the vsi is used */
1035 if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs,
1037 /* if the request failed, don't lock out others */
1038 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1043 * @adapter: adapter structure
1045 * Request hash enable capabilities from PF
1047 void iavf_get_hena(struct iavf_adapter *adapter)
1049 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1050 /* bail because we already have a command pending */
1051 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
1052 adapter->current_op);
1055 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
1056 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA;
1057 iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0);
1062 * @adapter: adapter structure
1064 * Request the PF to set our RSS hash capabilities
1066 void iavf_set_hena(struct iavf_adapter *adapter)
1068 struct virtchnl_rss_hena vrh;
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 hash enable, command %d pending\n",
1073 adapter->current_op);
1076 vrh.hena = adapter->hena;
1077 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
1078 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA;
1079 iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh,
1085 * @adapter: adapter structure
1087 * Request the PF to set our RSS hash key
1089 void iavf_set_rss_key(struct iavf_adapter *adapter)
1091 struct virtchnl_rss_key *vrk;
1094 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1095 /* bail because we already have a command pending */
1096 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
1097 adapter->current_op);
1100 len = virtchnl_struct_size(vrk, key, adapter->rss_key_size);
1101 vrk = kzalloc(len, GFP_KERNEL);
1104 vrk->vsi_id = adapter->vsi.id;
1105 vrk->key_len = adapter->rss_key_size;
1106 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
1108 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
1109 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY;
1110 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len);
1116 * @adapter: adapter structure
1118 * Request the PF to set our RSS lookup table
1120 void iavf_set_rss_lut(struct iavf_adapter *adapter)
1122 struct virtchnl_rss_lut *vrl;
1125 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1126 /* bail because we already have a command pending */
1127 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
1128 adapter->current_op);
1131 len = virtchnl_struct_size(vrl, lut, adapter->rss_lut_size);
1132 vrl = kzalloc(len, GFP_KERNEL);
1135 vrl->vsi_id = adapter->vsi.id;
1136 vrl->lut_entries = adapter->rss_lut_size;
1137 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
1138 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
1139 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT;
1140 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len);
1145 * iavf_set_rss_hfunc
1146 * @adapter: adapter structure
1148 * Request the PF to set our RSS Hash function
1150 void iavf_set_rss_hfunc(struct iavf_adapter *adapter)
1152 struct virtchnl_rss_hfunc *vrh;
1153 int len = sizeof(*vrh);
1155 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1156 /* bail because we already have a command pending */
1157 dev_err(&adapter->pdev->dev, "Cannot set RSS Hash function, command %d pending\n",
1158 adapter->current_op);
1161 vrh = kzalloc(len, GFP_KERNEL);
1164 vrh->vsi_id = adapter->vsi.id;
1165 vrh->rss_algorithm = adapter->hfunc;
1166 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_HFUNC;
1167 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_HFUNC;
1168 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_HFUNC, (u8 *)vrh, len);
1173 * iavf_enable_vlan_stripping
1174 * @adapter: adapter structure
1176 * Request VLAN header stripping to be enabled
1178 void iavf_enable_vlan_stripping(struct iavf_adapter *adapter)
1180 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1181 /* bail because we already have a command pending */
1182 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
1183 adapter->current_op);
1186 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
1187 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
1188 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0);
1192 * iavf_disable_vlan_stripping
1193 * @adapter: adapter structure
1195 * Request VLAN header stripping to be disabled
1197 void iavf_disable_vlan_stripping(struct iavf_adapter *adapter)
1199 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1200 /* bail because we already have a command pending */
1201 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
1202 adapter->current_op);
1205 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
1206 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
1207 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0);
1211 * iavf_tpid_to_vc_ethertype - transform from VLAN TPID to virtchnl ethertype
1212 * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1214 static u32 iavf_tpid_to_vc_ethertype(u16 tpid)
1218 return VIRTCHNL_VLAN_ETHERTYPE_8100;
1220 return VIRTCHNL_VLAN_ETHERTYPE_88A8;
1227 * iavf_set_vc_offload_ethertype - set virtchnl ethertype for offload message
1228 * @adapter: adapter structure
1229 * @msg: message structure used for updating offloads over virtchnl to update
1230 * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1231 * @offload_op: opcode used to determine which support structure to check
1234 iavf_set_vc_offload_ethertype(struct iavf_adapter *adapter,
1235 struct virtchnl_vlan_setting *msg, u16 tpid,
1236 enum virtchnl_ops offload_op)
1238 struct virtchnl_vlan_supported_caps *offload_support;
1239 u16 vc_ethertype = iavf_tpid_to_vc_ethertype(tpid);
1241 /* reference the correct offload support structure */
1242 switch (offload_op) {
1243 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1244 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1246 &adapter->vlan_v2_caps.offloads.stripping_support;
1248 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1249 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1251 &adapter->vlan_v2_caps.offloads.insertion_support;
1254 dev_err(&adapter->pdev->dev, "Invalid opcode %d for setting virtchnl ethertype to enable/disable VLAN offloads\n",
1259 /* make sure ethertype is supported */
1260 if (offload_support->outer & vc_ethertype &&
1261 offload_support->outer & VIRTCHNL_VLAN_TOGGLE) {
1262 msg->outer_ethertype_setting = vc_ethertype;
1263 } else if (offload_support->inner & vc_ethertype &&
1264 offload_support->inner & VIRTCHNL_VLAN_TOGGLE) {
1265 msg->inner_ethertype_setting = vc_ethertype;
1267 dev_dbg(&adapter->pdev->dev, "opcode %d unsupported for VLAN TPID 0x%04x\n",
1276 * iavf_clear_offload_v2_aq_required - clear AQ required bit for offload request
1277 * @adapter: adapter structure
1279 * @offload_op: opcode used to determine which AQ required bit to clear
1282 iavf_clear_offload_v2_aq_required(struct iavf_adapter *adapter, u16 tpid,
1283 enum virtchnl_ops offload_op)
1285 switch (offload_op) {
1286 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1287 if (tpid == ETH_P_8021Q)
1288 adapter->aq_required &=
1289 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_STRIPPING;
1290 else if (tpid == ETH_P_8021AD)
1291 adapter->aq_required &=
1292 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_STRIPPING;
1294 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1295 if (tpid == ETH_P_8021Q)
1296 adapter->aq_required &=
1297 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_STRIPPING;
1298 else if (tpid == ETH_P_8021AD)
1299 adapter->aq_required &=
1300 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_STRIPPING;
1302 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1303 if (tpid == ETH_P_8021Q)
1304 adapter->aq_required &=
1305 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_INSERTION;
1306 else if (tpid == ETH_P_8021AD)
1307 adapter->aq_required &=
1308 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_INSERTION;
1310 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1311 if (tpid == ETH_P_8021Q)
1312 adapter->aq_required &=
1313 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_INSERTION;
1314 else if (tpid == ETH_P_8021AD)
1315 adapter->aq_required &=
1316 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_INSERTION;
1319 dev_err(&adapter->pdev->dev, "Unsupported opcode %d specified for clearing aq_required bits for VIRTCHNL_VF_OFFLOAD_VLAN_V2 offload request\n",
1325 * iavf_send_vlan_offload_v2 - send offload enable/disable over virtchnl
1326 * @adapter: adapter structure
1327 * @tpid: VLAN TPID used for the command (i.e. 0x8100 or 0x88a8)
1328 * @offload_op: offload_op used to make the request over virtchnl
1331 iavf_send_vlan_offload_v2(struct iavf_adapter *adapter, u16 tpid,
1332 enum virtchnl_ops offload_op)
1334 struct virtchnl_vlan_setting *msg;
1335 int len = sizeof(*msg);
1337 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1338 /* bail because we already have a command pending */
1339 dev_err(&adapter->pdev->dev, "Cannot send %d, command %d pending\n",
1340 offload_op, adapter->current_op);
1344 adapter->current_op = offload_op;
1346 msg = kzalloc(len, GFP_KERNEL);
1350 msg->vport_id = adapter->vsi_res->vsi_id;
1352 /* always clear to prevent unsupported and endless requests */
1353 iavf_clear_offload_v2_aq_required(adapter, tpid, offload_op);
1355 /* only send valid offload requests */
1356 if (!iavf_set_vc_offload_ethertype(adapter, msg, tpid, offload_op))
1357 iavf_send_pf_msg(adapter, offload_op, (u8 *)msg, len);
1359 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1365 * iavf_enable_vlan_stripping_v2 - enable VLAN stripping
1366 * @adapter: adapter structure
1367 * @tpid: VLAN TPID used to enable VLAN stripping
1369 void iavf_enable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1371 iavf_send_vlan_offload_v2(adapter, tpid,
1372 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2);
1376 * iavf_disable_vlan_stripping_v2 - disable VLAN stripping
1377 * @adapter: adapter structure
1378 * @tpid: VLAN TPID used to disable VLAN stripping
1380 void iavf_disable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1382 iavf_send_vlan_offload_v2(adapter, tpid,
1383 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2);
1387 * iavf_enable_vlan_insertion_v2 - enable VLAN insertion
1388 * @adapter: adapter structure
1389 * @tpid: VLAN TPID used to enable VLAN insertion
1391 void iavf_enable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1393 iavf_send_vlan_offload_v2(adapter, tpid,
1394 VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2);
1398 * iavf_disable_vlan_insertion_v2 - disable VLAN insertion
1399 * @adapter: adapter structure
1400 * @tpid: VLAN TPID used to disable VLAN insertion
1402 void iavf_disable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1404 iavf_send_vlan_offload_v2(adapter, tpid,
1405 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2);
1409 * iavf_print_link_message - print link up or down
1410 * @adapter: adapter structure
1412 * Log a message telling the world of our wonderous link status
1414 static void iavf_print_link_message(struct iavf_adapter *adapter)
1416 struct net_device *netdev = adapter->netdev;
1417 int link_speed_mbps;
1420 if (!adapter->link_up) {
1421 netdev_info(netdev, "NIC Link is Down\n");
1425 if (ADV_LINK_SUPPORT(adapter)) {
1426 link_speed_mbps = adapter->link_speed_mbps;
1427 goto print_link_msg;
1430 switch (adapter->link_speed) {
1431 case VIRTCHNL_LINK_SPEED_40GB:
1432 link_speed_mbps = SPEED_40000;
1434 case VIRTCHNL_LINK_SPEED_25GB:
1435 link_speed_mbps = SPEED_25000;
1437 case VIRTCHNL_LINK_SPEED_20GB:
1438 link_speed_mbps = SPEED_20000;
1440 case VIRTCHNL_LINK_SPEED_10GB:
1441 link_speed_mbps = SPEED_10000;
1443 case VIRTCHNL_LINK_SPEED_5GB:
1444 link_speed_mbps = SPEED_5000;
1446 case VIRTCHNL_LINK_SPEED_2_5GB:
1447 link_speed_mbps = SPEED_2500;
1449 case VIRTCHNL_LINK_SPEED_1GB:
1450 link_speed_mbps = SPEED_1000;
1452 case VIRTCHNL_LINK_SPEED_100MB:
1453 link_speed_mbps = SPEED_100;
1456 link_speed_mbps = SPEED_UNKNOWN;
1461 if (link_speed_mbps > SPEED_1000) {
1462 if (link_speed_mbps == SPEED_2500) {
1463 speed = kasprintf(GFP_KERNEL, "%s", "2.5 Gbps");
1465 /* convert to Gbps inline */
1466 speed = kasprintf(GFP_KERNEL, "%d Gbps",
1467 link_speed_mbps / 1000);
1469 } else if (link_speed_mbps == SPEED_UNKNOWN) {
1470 speed = kasprintf(GFP_KERNEL, "%s", "Unknown Mbps");
1472 speed = kasprintf(GFP_KERNEL, "%d Mbps", link_speed_mbps);
1475 netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed);
1480 * iavf_get_vpe_link_status
1481 * @adapter: adapter structure
1482 * @vpe: virtchnl_pf_event structure
1484 * Helper function for determining the link status
1487 iavf_get_vpe_link_status(struct iavf_adapter *adapter,
1488 struct virtchnl_pf_event *vpe)
1490 if (ADV_LINK_SUPPORT(adapter))
1491 return vpe->event_data.link_event_adv.link_status;
1493 return vpe->event_data.link_event.link_status;
1497 * iavf_set_adapter_link_speed_from_vpe
1498 * @adapter: adapter structure for which we are setting the link speed
1499 * @vpe: virtchnl_pf_event structure that contains the link speed we are setting
1501 * Helper function for setting iavf_adapter link speed
1504 iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter *adapter,
1505 struct virtchnl_pf_event *vpe)
1507 if (ADV_LINK_SUPPORT(adapter))
1508 adapter->link_speed_mbps =
1509 vpe->event_data.link_event_adv.link_speed;
1511 adapter->link_speed = vpe->event_data.link_event.link_speed;
1515 * iavf_enable_channels
1516 * @adapter: adapter structure
1518 * Request that the PF enable channels as specified by
1519 * the user via tc tool.
1521 void iavf_enable_channels(struct iavf_adapter *adapter)
1523 struct virtchnl_tc_info *vti = NULL;
1527 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1528 /* bail because we already have a command pending */
1529 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1530 adapter->current_op);
1534 len = virtchnl_struct_size(vti, list, adapter->num_tc);
1535 vti = kzalloc(len, GFP_KERNEL);
1538 vti->num_tc = adapter->num_tc;
1539 for (i = 0; i < vti->num_tc; i++) {
1540 vti->list[i].count = adapter->ch_config.ch_info[i].count;
1541 vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
1542 vti->list[i].pad = 0;
1543 vti->list[i].max_tx_rate =
1544 adapter->ch_config.ch_info[i].max_tx_rate;
1547 adapter->ch_config.state = __IAVF_TC_RUNNING;
1548 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1549 adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
1550 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS;
1551 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len);
1556 * iavf_disable_channels
1557 * @adapter: adapter structure
1559 * Request that the PF disable channels that are configured
1561 void iavf_disable_channels(struct iavf_adapter *adapter)
1563 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1564 /* bail because we already have a command pending */
1565 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1566 adapter->current_op);
1570 adapter->ch_config.state = __IAVF_TC_INVALID;
1571 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1572 adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
1573 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS;
1574 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0);
1578 * iavf_print_cloud_filter
1579 * @adapter: adapter structure
1580 * @f: cloud filter to print
1582 * Print the cloud filter
1584 static void iavf_print_cloud_filter(struct iavf_adapter *adapter,
1585 struct virtchnl_filter *f)
1587 switch (f->flow_type) {
1588 case VIRTCHNL_TCP_V4_FLOW:
1589 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",
1590 &f->data.tcp_spec.dst_mac,
1591 &f->data.tcp_spec.src_mac,
1592 ntohs(f->data.tcp_spec.vlan_id),
1593 &f->data.tcp_spec.dst_ip[0],
1594 &f->data.tcp_spec.src_ip[0],
1595 ntohs(f->data.tcp_spec.dst_port),
1596 ntohs(f->data.tcp_spec.src_port));
1598 case VIRTCHNL_TCP_V6_FLOW:
1599 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",
1600 &f->data.tcp_spec.dst_mac,
1601 &f->data.tcp_spec.src_mac,
1602 ntohs(f->data.tcp_spec.vlan_id),
1603 &f->data.tcp_spec.dst_ip,
1604 &f->data.tcp_spec.src_ip,
1605 ntohs(f->data.tcp_spec.dst_port),
1606 ntohs(f->data.tcp_spec.src_port));
1612 * iavf_add_cloud_filter
1613 * @adapter: adapter structure
1615 * Request that the PF add cloud filters as specified
1616 * by the user via tc tool.
1618 void iavf_add_cloud_filter(struct iavf_adapter *adapter)
1620 struct iavf_cloud_filter *cf;
1621 struct virtchnl_filter *f;
1622 int len = 0, count = 0;
1624 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1625 /* bail because we already have a command pending */
1626 dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1627 adapter->current_op);
1630 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1637 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER;
1640 adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1642 len = sizeof(struct virtchnl_filter);
1643 f = kzalloc(len, GFP_KERNEL);
1647 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1649 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1651 cf->state = __IAVF_CF_ADD_PENDING;
1652 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER,
1660 * iavf_del_cloud_filter
1661 * @adapter: adapter structure
1663 * Request that the PF delete cloud filters as specified
1664 * by the user via tc tool.
1666 void iavf_del_cloud_filter(struct iavf_adapter *adapter)
1668 struct iavf_cloud_filter *cf, *cftmp;
1669 struct virtchnl_filter *f;
1670 int len = 0, count = 0;
1672 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1673 /* bail because we already have a command pending */
1674 dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1675 adapter->current_op);
1678 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1685 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER;
1688 adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1690 len = sizeof(struct virtchnl_filter);
1691 f = kzalloc(len, GFP_KERNEL);
1695 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1697 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1699 cf->state = __IAVF_CF_DEL_PENDING;
1700 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER,
1708 * iavf_add_fdir_filter
1709 * @adapter: the VF adapter structure
1711 * Request that the PF add Flow Director filters as specified
1712 * by the user via ethtool.
1714 void iavf_add_fdir_filter(struct iavf_adapter *adapter)
1716 struct iavf_fdir_fltr *fdir;
1717 struct virtchnl_fdir_add *f;
1718 bool process_fltr = false;
1721 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1722 /* bail because we already have a command pending */
1723 dev_err(&adapter->pdev->dev, "Cannot add Flow Director filter, command %d pending\n",
1724 adapter->current_op);
1728 len = sizeof(struct virtchnl_fdir_add);
1729 f = kzalloc(len, GFP_KERNEL);
1733 spin_lock_bh(&adapter->fdir_fltr_lock);
1734 list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1735 if (fdir->state == IAVF_FDIR_FLTR_ADD_REQUEST) {
1736 process_fltr = true;
1737 fdir->state = IAVF_FDIR_FLTR_ADD_PENDING;
1738 memcpy(f, &fdir->vc_add_msg, len);
1742 spin_unlock_bh(&adapter->fdir_fltr_lock);
1744 if (!process_fltr) {
1745 /* prevent iavf_add_fdir_filter() from being called when there
1746 * are no filters to add
1748 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_FDIR_FILTER;
1752 adapter->current_op = VIRTCHNL_OP_ADD_FDIR_FILTER;
1753 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_FDIR_FILTER, (u8 *)f, len);
1758 * iavf_del_fdir_filter
1759 * @adapter: the VF adapter structure
1761 * Request that the PF delete Flow Director filters as specified
1762 * by the user via ethtool.
1764 void iavf_del_fdir_filter(struct iavf_adapter *adapter)
1766 struct virtchnl_fdir_del f = {};
1767 struct iavf_fdir_fltr *fdir;
1768 bool process_fltr = false;
1771 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1772 /* bail because we already have a command pending */
1773 dev_err(&adapter->pdev->dev, "Cannot remove Flow Director filter, command %d pending\n",
1774 adapter->current_op);
1778 len = sizeof(struct virtchnl_fdir_del);
1780 spin_lock_bh(&adapter->fdir_fltr_lock);
1781 list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1782 if (fdir->state == IAVF_FDIR_FLTR_DEL_REQUEST) {
1783 process_fltr = true;
1784 f.vsi_id = fdir->vc_add_msg.vsi_id;
1785 f.flow_id = fdir->flow_id;
1786 fdir->state = IAVF_FDIR_FLTR_DEL_PENDING;
1788 } else if (fdir->state == IAVF_FDIR_FLTR_DIS_REQUEST) {
1789 process_fltr = true;
1790 f.vsi_id = fdir->vc_add_msg.vsi_id;
1791 f.flow_id = fdir->flow_id;
1792 fdir->state = IAVF_FDIR_FLTR_DIS_PENDING;
1796 spin_unlock_bh(&adapter->fdir_fltr_lock);
1798 if (!process_fltr) {
1799 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_FDIR_FILTER;
1803 adapter->current_op = VIRTCHNL_OP_DEL_FDIR_FILTER;
1804 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_FDIR_FILTER, (u8 *)&f, len);
1808 * iavf_add_adv_rss_cfg
1809 * @adapter: the VF adapter structure
1811 * Request that the PF add RSS configuration as specified
1812 * by the user via ethtool.
1814 void iavf_add_adv_rss_cfg(struct iavf_adapter *adapter)
1816 struct virtchnl_rss_cfg *rss_cfg;
1817 struct iavf_adv_rss *rss;
1818 bool process_rss = false;
1821 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1822 /* bail because we already have a command pending */
1823 dev_err(&adapter->pdev->dev, "Cannot add RSS configuration, command %d pending\n",
1824 adapter->current_op);
1828 len = sizeof(struct virtchnl_rss_cfg);
1829 rss_cfg = kzalloc(len, GFP_KERNEL);
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_ADD_REQUEST) {
1837 rss->state = IAVF_ADV_RSS_ADD_PENDING;
1838 memcpy(rss_cfg, &rss->cfg_msg, len);
1839 iavf_print_adv_rss_cfg(adapter, rss,
1840 "Input set change for",
1845 spin_unlock_bh(&adapter->adv_rss_lock);
1848 adapter->current_op = VIRTCHNL_OP_ADD_RSS_CFG;
1849 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_RSS_CFG,
1850 (u8 *)rss_cfg, len);
1852 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_ADV_RSS_CFG;
1859 * iavf_del_adv_rss_cfg
1860 * @adapter: the VF adapter structure
1862 * Request that the PF delete RSS configuration as specified
1863 * by the user via ethtool.
1865 void iavf_del_adv_rss_cfg(struct iavf_adapter *adapter)
1867 struct virtchnl_rss_cfg *rss_cfg;
1868 struct iavf_adv_rss *rss;
1869 bool process_rss = false;
1872 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1873 /* bail because we already have a command pending */
1874 dev_err(&adapter->pdev->dev, "Cannot remove RSS configuration, command %d pending\n",
1875 adapter->current_op);
1879 len = sizeof(struct virtchnl_rss_cfg);
1880 rss_cfg = kzalloc(len, GFP_KERNEL);
1884 spin_lock_bh(&adapter->adv_rss_lock);
1885 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1886 if (rss->state == IAVF_ADV_RSS_DEL_REQUEST) {
1888 rss->state = IAVF_ADV_RSS_DEL_PENDING;
1889 memcpy(rss_cfg, &rss->cfg_msg, len);
1893 spin_unlock_bh(&adapter->adv_rss_lock);
1896 adapter->current_op = VIRTCHNL_OP_DEL_RSS_CFG;
1897 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_RSS_CFG,
1898 (u8 *)rss_cfg, len);
1900 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_ADV_RSS_CFG;
1907 * iavf_request_reset
1908 * @adapter: adapter structure
1910 * Request that the PF reset this VF. No response is expected.
1912 int iavf_request_reset(struct iavf_adapter *adapter)
1915 /* Don't check CURRENT_OP - this is always higher priority */
1916 err = iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
1917 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1922 * iavf_netdev_features_vlan_strip_set - update vlan strip status
1923 * @netdev: ptr to netdev being adjusted
1924 * @enable: enable or disable vlan strip
1926 * Helper function to change vlan strip status in netdev->features.
1928 static void iavf_netdev_features_vlan_strip_set(struct net_device *netdev,
1932 netdev->features |= NETIF_F_HW_VLAN_CTAG_RX;
1934 netdev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
1938 * iavf_activate_fdir_filters - Reactivate all FDIR filters after a reset
1939 * @adapter: private adapter structure
1941 * Called after a reset to re-add all FDIR filters and delete some of them
1942 * if they were pending to be deleted.
1944 static void iavf_activate_fdir_filters(struct iavf_adapter *adapter)
1946 struct iavf_fdir_fltr *f, *ftmp;
1947 bool add_filters = false;
1949 spin_lock_bh(&adapter->fdir_fltr_lock);
1950 list_for_each_entry_safe(f, ftmp, &adapter->fdir_list_head, list) {
1951 if (f->state == IAVF_FDIR_FLTR_ADD_REQUEST ||
1952 f->state == IAVF_FDIR_FLTR_ADD_PENDING ||
1953 f->state == IAVF_FDIR_FLTR_ACTIVE) {
1954 /* All filters and requests have been removed in PF,
1957 f->state = IAVF_FDIR_FLTR_ADD_REQUEST;
1959 } else if (f->state == IAVF_FDIR_FLTR_DIS_REQUEST ||
1960 f->state == IAVF_FDIR_FLTR_DIS_PENDING) {
1961 /* Link down state, leave filters as inactive */
1962 f->state = IAVF_FDIR_FLTR_INACTIVE;
1963 } else if (f->state == IAVF_FDIR_FLTR_DEL_REQUEST ||
1964 f->state == IAVF_FDIR_FLTR_DEL_PENDING) {
1965 /* Delete filters that were pending to be deleted, the
1966 * list on PF is already cleared after a reset
1970 adapter->fdir_active_fltr--;
1973 spin_unlock_bh(&adapter->fdir_fltr_lock);
1976 adapter->aq_required |= IAVF_FLAG_AQ_ADD_FDIR_FILTER;
1980 * iavf_virtchnl_completion
1981 * @adapter: adapter structure
1982 * @v_opcode: opcode sent by PF
1983 * @v_retval: retval sent by PF
1984 * @msg: message sent by PF
1985 * @msglen: message length
1987 * Asynchronous completion function for admin queue messages. Rather than busy
1988 * wait, we fire off our requests and assume that no errors will be returned.
1989 * This function handles the reply messages.
1991 void iavf_virtchnl_completion(struct iavf_adapter *adapter,
1992 enum virtchnl_ops v_opcode,
1993 enum iavf_status v_retval, u8 *msg, u16 msglen)
1995 struct net_device *netdev = adapter->netdev;
1997 if (v_opcode == VIRTCHNL_OP_EVENT) {
1998 struct virtchnl_pf_event *vpe =
1999 (struct virtchnl_pf_event *)msg;
2000 bool link_up = iavf_get_vpe_link_status(adapter, vpe);
2002 switch (vpe->event) {
2003 case VIRTCHNL_EVENT_LINK_CHANGE:
2004 iavf_set_adapter_link_speed_from_vpe(adapter, vpe);
2006 /* we've already got the right link status, bail */
2007 if (adapter->link_up == link_up)
2011 /* If we get link up message and start queues
2012 * before our queues are configured it will
2013 * trigger a TX hang. In that case, just ignore
2014 * the link status message,we'll get another one
2015 * after we enable queues and actually prepared
2018 if (adapter->state != __IAVF_RUNNING)
2021 /* For ADq enabled VF, we reconfigure VSIs and
2022 * re-allocate queues. Hence wait till all
2023 * queues are enabled.
2025 if (adapter->flags &
2026 IAVF_FLAG_QUEUES_DISABLED)
2030 adapter->link_up = link_up;
2032 netif_tx_start_all_queues(netdev);
2033 netif_carrier_on(netdev);
2035 netif_tx_stop_all_queues(netdev);
2036 netif_carrier_off(netdev);
2038 iavf_print_link_message(adapter);
2040 case VIRTCHNL_EVENT_RESET_IMPENDING:
2041 dev_info(&adapter->pdev->dev, "Reset indication received from the PF\n");
2042 if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) {
2043 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
2044 iavf_schedule_reset(adapter, IAVF_FLAG_RESET_PENDING);
2048 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
2056 case VIRTCHNL_OP_ADD_VLAN:
2057 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
2058 iavf_stat_str(&adapter->hw, v_retval));
2060 case VIRTCHNL_OP_ADD_ETH_ADDR:
2061 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
2062 iavf_stat_str(&adapter->hw, v_retval));
2063 iavf_mac_add_reject(adapter);
2064 /* restore administratively set MAC address */
2065 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2066 wake_up(&adapter->vc_waitqueue);
2068 case VIRTCHNL_OP_DEL_VLAN:
2069 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
2070 iavf_stat_str(&adapter->hw, v_retval));
2072 case VIRTCHNL_OP_DEL_ETH_ADDR:
2073 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
2074 iavf_stat_str(&adapter->hw, v_retval));
2076 case VIRTCHNL_OP_ENABLE_CHANNELS:
2077 dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
2078 iavf_stat_str(&adapter->hw, v_retval));
2079 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2080 adapter->ch_config.state = __IAVF_TC_INVALID;
2081 netdev_reset_tc(netdev);
2082 netif_tx_start_all_queues(netdev);
2084 case VIRTCHNL_OP_DISABLE_CHANNELS:
2085 dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
2086 iavf_stat_str(&adapter->hw, v_retval));
2087 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2088 adapter->ch_config.state = __IAVF_TC_RUNNING;
2089 netif_tx_start_all_queues(netdev);
2091 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2092 struct iavf_cloud_filter *cf, *cftmp;
2094 list_for_each_entry_safe(cf, cftmp,
2095 &adapter->cloud_filter_list,
2097 if (cf->state == __IAVF_CF_ADD_PENDING) {
2098 cf->state = __IAVF_CF_INVALID;
2099 dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
2100 iavf_stat_str(&adapter->hw,
2102 iavf_print_cloud_filter(adapter,
2104 list_del(&cf->list);
2106 adapter->num_cloud_filters--;
2111 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2112 struct iavf_cloud_filter *cf;
2114 list_for_each_entry(cf, &adapter->cloud_filter_list,
2116 if (cf->state == __IAVF_CF_DEL_PENDING) {
2117 cf->state = __IAVF_CF_ACTIVE;
2118 dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
2119 iavf_stat_str(&adapter->hw,
2121 iavf_print_cloud_filter(adapter,
2127 case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2128 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2130 spin_lock_bh(&adapter->fdir_fltr_lock);
2131 list_for_each_entry_safe(fdir, fdir_tmp,
2132 &adapter->fdir_list_head,
2134 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2135 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter, error %s\n",
2136 iavf_stat_str(&adapter->hw,
2138 iavf_print_fdir_fltr(adapter, fdir);
2140 dev_err(&adapter->pdev->dev,
2142 list_del(&fdir->list);
2144 adapter->fdir_active_fltr--;
2147 spin_unlock_bh(&adapter->fdir_fltr_lock);
2150 case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2151 struct iavf_fdir_fltr *fdir;
2153 spin_lock_bh(&adapter->fdir_fltr_lock);
2154 list_for_each_entry(fdir, &adapter->fdir_list_head,
2156 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING ||
2157 fdir->state == IAVF_FDIR_FLTR_DIS_PENDING) {
2158 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2159 dev_info(&adapter->pdev->dev, "Failed to del Flow Director filter, error %s\n",
2160 iavf_stat_str(&adapter->hw,
2162 iavf_print_fdir_fltr(adapter, fdir);
2165 spin_unlock_bh(&adapter->fdir_fltr_lock);
2168 case VIRTCHNL_OP_ADD_RSS_CFG: {
2169 struct iavf_adv_rss *rss, *rss_tmp;
2171 spin_lock_bh(&adapter->adv_rss_lock);
2172 list_for_each_entry_safe(rss, rss_tmp,
2173 &adapter->adv_rss_list_head,
2175 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2176 iavf_print_adv_rss_cfg(adapter, rss,
2177 "Failed to change the input set for",
2179 list_del(&rss->list);
2183 spin_unlock_bh(&adapter->adv_rss_lock);
2186 case VIRTCHNL_OP_DEL_RSS_CFG: {
2187 struct iavf_adv_rss *rss;
2189 spin_lock_bh(&adapter->adv_rss_lock);
2190 list_for_each_entry(rss, &adapter->adv_rss_list_head,
2192 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2193 rss->state = IAVF_ADV_RSS_ACTIVE;
2194 dev_err(&adapter->pdev->dev, "Failed to delete RSS configuration, error %s\n",
2195 iavf_stat_str(&adapter->hw,
2199 spin_unlock_bh(&adapter->adv_rss_lock);
2202 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2203 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2204 /* Vlan stripping could not be enabled by ethtool.
2205 * Disable it in netdev->features.
2207 iavf_netdev_features_vlan_strip_set(netdev, false);
2209 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2210 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2211 /* Vlan stripping could not be disabled by ethtool.
2212 * Enable it in netdev->features.
2214 iavf_netdev_features_vlan_strip_set(netdev, true);
2216 case VIRTCHNL_OP_ADD_VLAN_V2:
2217 iavf_vlan_add_reject(adapter);
2218 dev_warn(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
2219 iavf_stat_str(&adapter->hw, v_retval));
2221 case VIRTCHNL_OP_CONFIG_RSS_HFUNC:
2222 dev_warn(&adapter->pdev->dev, "Failed to configure hash function, error %s\n",
2223 iavf_stat_str(&adapter->hw, v_retval));
2225 if (adapter->hfunc ==
2226 VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC)
2228 VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC;
2231 VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC;
2235 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
2236 v_retval, iavf_stat_str(&adapter->hw, v_retval),
2241 case VIRTCHNL_OP_ADD_ETH_ADDR:
2243 iavf_mac_add_ok(adapter);
2244 if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr))
2245 if (!ether_addr_equal(netdev->dev_addr,
2246 adapter->hw.mac.addr)) {
2247 netif_addr_lock_bh(netdev);
2248 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2249 netif_addr_unlock_bh(netdev);
2251 wake_up(&adapter->vc_waitqueue);
2253 case VIRTCHNL_OP_GET_STATS: {
2254 struct iavf_eth_stats *stats =
2255 (struct iavf_eth_stats *)msg;
2256 netdev->stats.rx_packets = stats->rx_unicast +
2257 stats->rx_multicast +
2258 stats->rx_broadcast;
2259 netdev->stats.tx_packets = stats->tx_unicast +
2260 stats->tx_multicast +
2261 stats->tx_broadcast;
2262 netdev->stats.rx_bytes = stats->rx_bytes;
2263 netdev->stats.tx_bytes = stats->tx_bytes;
2264 netdev->stats.tx_errors = stats->tx_errors;
2265 netdev->stats.rx_dropped = stats->rx_discards;
2266 netdev->stats.tx_dropped = stats->tx_discards;
2267 adapter->current_stats = *stats;
2270 case VIRTCHNL_OP_GET_VF_RESOURCES: {
2271 u16 len = IAVF_VIRTCHNL_VF_RESOURCE_SIZE;
2273 memcpy(adapter->vf_res, msg, min(msglen, len));
2274 iavf_validate_num_queues(adapter);
2275 iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
2276 if (is_zero_ether_addr(adapter->hw.mac.addr)) {
2277 /* restore current mac address */
2278 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2280 netif_addr_lock_bh(netdev);
2281 /* refresh current mac address if changed */
2282 ether_addr_copy(netdev->perm_addr,
2283 adapter->hw.mac.addr);
2284 netif_addr_unlock_bh(netdev);
2286 spin_lock_bh(&adapter->mac_vlan_list_lock);
2287 iavf_add_filter(adapter, adapter->hw.mac.addr);
2289 if (VLAN_ALLOWED(adapter)) {
2290 if (!list_empty(&adapter->vlan_filter_list)) {
2291 struct iavf_vlan_filter *vlf;
2293 /* re-add all VLAN filters over virtchnl */
2294 list_for_each_entry(vlf,
2295 &adapter->vlan_filter_list,
2297 vlf->state = IAVF_VLAN_ADD;
2299 adapter->aq_required |=
2300 IAVF_FLAG_AQ_ADD_VLAN_FILTER;
2304 spin_unlock_bh(&adapter->mac_vlan_list_lock);
2306 iavf_activate_fdir_filters(adapter);
2308 iavf_parse_vf_resource_msg(adapter);
2310 /* negotiated VIRTCHNL_VF_OFFLOAD_VLAN_V2, so wait for the
2311 * response to VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS to finish
2314 if (VLAN_V2_ALLOWED(adapter))
2316 /* fallthrough and finish config if VIRTCHNL_VF_OFFLOAD_VLAN_V2
2317 * wasn't successfully negotiated with the PF
2321 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS: {
2322 struct iavf_mac_filter *f;
2323 bool was_mac_changed;
2324 u64 aq_required = 0;
2326 if (v_opcode == VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS)
2327 memcpy(&adapter->vlan_v2_caps, msg,
2329 sizeof(adapter->vlan_v2_caps)));
2331 iavf_process_config(adapter);
2332 adapter->flags |= IAVF_FLAG_SETUP_NETDEV_FEATURES;
2333 iavf_schedule_finish_config(adapter);
2335 iavf_set_queue_vlan_tag_loc(adapter);
2337 was_mac_changed = !ether_addr_equal(netdev->dev_addr,
2338 adapter->hw.mac.addr);
2340 spin_lock_bh(&adapter->mac_vlan_list_lock);
2342 /* re-add all MAC filters */
2343 list_for_each_entry(f, &adapter->mac_filter_list, list) {
2344 if (was_mac_changed &&
2345 ether_addr_equal(netdev->dev_addr, f->macaddr))
2346 ether_addr_copy(f->macaddr,
2347 adapter->hw.mac.addr);
2349 f->is_new_mac = true;
2351 f->add_handled = false;
2355 /* re-add all VLAN filters */
2356 if (VLAN_FILTERING_ALLOWED(adapter)) {
2357 struct iavf_vlan_filter *vlf;
2359 if (!list_empty(&adapter->vlan_filter_list)) {
2360 list_for_each_entry(vlf,
2361 &adapter->vlan_filter_list,
2363 vlf->state = IAVF_VLAN_ADD;
2365 aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER;
2369 spin_unlock_bh(&adapter->mac_vlan_list_lock);
2371 netif_addr_lock_bh(netdev);
2372 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2373 netif_addr_unlock_bh(netdev);
2375 adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER |
2379 case VIRTCHNL_OP_ENABLE_QUEUES:
2380 /* enable transmits */
2381 iavf_irq_enable(adapter, true);
2382 wake_up(&adapter->reset_waitqueue);
2383 adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED;
2385 case VIRTCHNL_OP_DISABLE_QUEUES:
2386 iavf_free_all_tx_resources(adapter);
2387 iavf_free_all_rx_resources(adapter);
2388 if (adapter->state == __IAVF_DOWN_PENDING) {
2389 iavf_change_state(adapter, __IAVF_DOWN);
2390 wake_up(&adapter->down_waitqueue);
2393 case VIRTCHNL_OP_VERSION:
2394 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
2395 /* Don't display an error if we get these out of sequence.
2396 * If the firmware needed to get kicked, we'll get these and
2399 if (v_opcode != adapter->current_op)
2402 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
2403 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
2405 if (msglen == sizeof(*vrh))
2406 adapter->hena = vrh->hena;
2408 dev_warn(&adapter->pdev->dev,
2409 "Invalid message %d from PF\n", v_opcode);
2412 case VIRTCHNL_OP_REQUEST_QUEUES: {
2413 struct virtchnl_vf_res_request *vfres =
2414 (struct virtchnl_vf_res_request *)msg;
2416 if (vfres->num_queue_pairs != adapter->num_req_queues) {
2417 dev_info(&adapter->pdev->dev,
2418 "Requested %d queues, PF can support %d\n",
2419 adapter->num_req_queues,
2420 vfres->num_queue_pairs);
2421 adapter->num_req_queues = 0;
2422 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2426 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2427 struct iavf_cloud_filter *cf;
2429 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
2430 if (cf->state == __IAVF_CF_ADD_PENDING)
2431 cf->state = __IAVF_CF_ACTIVE;
2435 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2436 struct iavf_cloud_filter *cf, *cftmp;
2438 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
2440 if (cf->state == __IAVF_CF_DEL_PENDING) {
2441 cf->state = __IAVF_CF_INVALID;
2442 list_del(&cf->list);
2444 adapter->num_cloud_filters--;
2449 case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2450 struct virtchnl_fdir_add *add_fltr = (struct virtchnl_fdir_add *)msg;
2451 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2453 spin_lock_bh(&adapter->fdir_fltr_lock);
2454 list_for_each_entry_safe(fdir, fdir_tmp,
2455 &adapter->fdir_list_head,
2457 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2458 if (add_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2459 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is added\n",
2461 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2462 fdir->flow_id = add_fltr->flow_id;
2464 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter with status: %d\n",
2466 iavf_print_fdir_fltr(adapter, fdir);
2467 list_del(&fdir->list);
2469 adapter->fdir_active_fltr--;
2473 spin_unlock_bh(&adapter->fdir_fltr_lock);
2476 case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2477 struct virtchnl_fdir_del *del_fltr = (struct virtchnl_fdir_del *)msg;
2478 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2480 spin_lock_bh(&adapter->fdir_fltr_lock);
2481 list_for_each_entry_safe(fdir, fdir_tmp, &adapter->fdir_list_head,
2483 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2484 if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS ||
2486 VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
2487 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is deleted\n",
2489 list_del(&fdir->list);
2491 adapter->fdir_active_fltr--;
2493 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2494 dev_info(&adapter->pdev->dev, "Failed to delete Flow Director filter with status: %d\n",
2496 iavf_print_fdir_fltr(adapter, fdir);
2498 } else if (fdir->state == IAVF_FDIR_FLTR_DIS_PENDING) {
2499 if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS ||
2501 VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
2502 fdir->state = IAVF_FDIR_FLTR_INACTIVE;
2504 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2505 dev_info(&adapter->pdev->dev, "Failed to disable Flow Director filter with status: %d\n",
2507 iavf_print_fdir_fltr(adapter, fdir);
2511 spin_unlock_bh(&adapter->fdir_fltr_lock);
2514 case VIRTCHNL_OP_ADD_RSS_CFG: {
2515 struct iavf_adv_rss *rss;
2517 spin_lock_bh(&adapter->adv_rss_lock);
2518 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
2519 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2520 iavf_print_adv_rss_cfg(adapter, rss,
2521 "Input set change for",
2523 rss->state = IAVF_ADV_RSS_ACTIVE;
2526 spin_unlock_bh(&adapter->adv_rss_lock);
2529 case VIRTCHNL_OP_DEL_RSS_CFG: {
2530 struct iavf_adv_rss *rss, *rss_tmp;
2532 spin_lock_bh(&adapter->adv_rss_lock);
2533 list_for_each_entry_safe(rss, rss_tmp,
2534 &adapter->adv_rss_list_head, list) {
2535 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2536 list_del(&rss->list);
2540 spin_unlock_bh(&adapter->adv_rss_lock);
2543 case VIRTCHNL_OP_ADD_VLAN_V2: {
2544 struct iavf_vlan_filter *f;
2546 spin_lock_bh(&adapter->mac_vlan_list_lock);
2547 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
2548 if (f->state == IAVF_VLAN_IS_NEW)
2549 f->state = IAVF_VLAN_ACTIVE;
2551 spin_unlock_bh(&adapter->mac_vlan_list_lock);
2554 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2555 /* PF enabled vlan strip on this VF.
2556 * Update netdev->features if needed to be in sync with ethtool.
2559 iavf_netdev_features_vlan_strip_set(netdev, true);
2561 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2562 /* PF disabled vlan strip on this VF.
2563 * Update netdev->features if needed to be in sync with ethtool.
2566 iavf_netdev_features_vlan_strip_set(netdev, false);
2569 if (adapter->current_op && (v_opcode != adapter->current_op))
2570 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
2571 adapter->current_op, v_opcode);
2573 } /* switch v_opcode */
2574 adapter->current_op = VIRTCHNL_OP_UNKNOWN;