1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
5 #include "iavf_prototype.h"
6 #include "iavf_client.h"
8 /* busy wait delay in msec */
9 #define IAVF_BUSY_WAIT_DELAY 10
10 #define IAVF_BUSY_WAIT_COUNT 50
14 * @adapter: adapter structure
15 * @op: virtual channel opcode
16 * @msg: pointer to message buffer
17 * @len: message length
19 * Send message to PF and print status if failure.
21 static int iavf_send_pf_msg(struct iavf_adapter *adapter,
22 enum virtchnl_ops op, u8 *msg, u16 len)
24 struct iavf_hw *hw = &adapter->hw;
25 enum iavf_status status;
27 if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)
28 return 0; /* nothing to see here, move along */
30 status = iavf_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
32 dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, status %s, aq_err %s\n",
33 op, iavf_stat_str(hw, status),
34 iavf_aq_str(hw, hw->aq.asq_last_status));
35 return iavf_status_to_errno(status);
40 * @adapter: adapter structure
42 * Send API version admin queue message to the PF. The reply is not checked
43 * in this function. Returns 0 if the message was successfully
44 * sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
46 int iavf_send_api_ver(struct iavf_adapter *adapter)
48 struct virtchnl_version_info vvi;
50 vvi.major = VIRTCHNL_VERSION_MAJOR;
51 vvi.minor = VIRTCHNL_VERSION_MINOR;
53 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
58 * iavf_poll_virtchnl_msg
59 * @hw: HW configuration structure
60 * @event: event to populate on success
61 * @op_to_poll: requested virtchnl op to poll for
63 * Initialize poll for virtchnl msg matching the requested_op. Returns 0
64 * if a message of the correct opcode is in the queue or an error code
65 * if no message matching the op code is waiting and other failures.
68 iavf_poll_virtchnl_msg(struct iavf_hw *hw, struct iavf_arq_event_info *event,
69 enum virtchnl_ops op_to_poll)
71 enum virtchnl_ops received_op;
72 enum iavf_status status;
76 /* When the AQ is empty, iavf_clean_arq_element will return
77 * nonzero and this loop will terminate.
79 status = iavf_clean_arq_element(hw, event, NULL);
80 if (status != IAVF_SUCCESS)
81 return iavf_status_to_errno(status);
83 (enum virtchnl_ops)le32_to_cpu(event->desc.cookie_high);
84 if (op_to_poll == received_op)
88 v_retval = le32_to_cpu(event->desc.cookie_low);
89 return virtchnl_status_to_errno((enum virtchnl_status_code)v_retval);
94 * @adapter: adapter structure
96 * Compare API versions with the PF. Must be called after admin queue is
97 * initialized. Returns 0 if API versions match, -EIO if they do not,
98 * IAVF_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
99 * from the firmware are propagated.
101 int iavf_verify_api_ver(struct iavf_adapter *adapter)
103 struct iavf_arq_event_info event;
106 event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
107 event.msg_buf = kzalloc(IAVF_MAX_AQ_BUF_SIZE, GFP_KERNEL);
111 err = iavf_poll_virtchnl_msg(&adapter->hw, &event, VIRTCHNL_OP_VERSION);
113 struct virtchnl_version_info *pf_vvi =
114 (struct virtchnl_version_info *)event.msg_buf;
115 adapter->pf_version = *pf_vvi;
117 if (pf_vvi->major > VIRTCHNL_VERSION_MAJOR ||
118 (pf_vvi->major == VIRTCHNL_VERSION_MAJOR &&
119 pf_vvi->minor > VIRTCHNL_VERSION_MINOR))
123 kfree(event.msg_buf);
129 * iavf_send_vf_config_msg
130 * @adapter: adapter structure
132 * Send VF configuration request admin queue message to the PF. The reply
133 * is not checked in this function. Returns 0 if the message was
134 * successfully sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
136 int iavf_send_vf_config_msg(struct iavf_adapter *adapter)
140 caps = VIRTCHNL_VF_OFFLOAD_L2 |
141 VIRTCHNL_VF_OFFLOAD_RSS_PF |
142 VIRTCHNL_VF_OFFLOAD_RSS_AQ |
143 VIRTCHNL_VF_OFFLOAD_RSS_REG |
144 VIRTCHNL_VF_OFFLOAD_VLAN |
145 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
146 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
147 VIRTCHNL_VF_OFFLOAD_ENCAP |
148 VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
149 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM |
150 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
151 VIRTCHNL_VF_OFFLOAD_ADQ |
152 VIRTCHNL_VF_OFFLOAD_USO |
153 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
154 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
155 VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
157 adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
158 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_CONFIG;
159 if (PF_IS_V11(adapter))
160 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
161 (u8 *)&caps, sizeof(caps));
163 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
167 int iavf_send_vf_offload_vlan_v2_msg(struct iavf_adapter *adapter)
169 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_OFFLOAD_VLAN_V2_CAPS;
171 if (!VLAN_V2_ALLOWED(adapter))
174 adapter->current_op = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
176 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
181 * iavf_validate_num_queues
182 * @adapter: adapter structure
184 * Validate that the number of queues the PF has sent in
185 * VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle.
187 static void iavf_validate_num_queues(struct iavf_adapter *adapter)
189 if (adapter->vf_res->num_queue_pairs > IAVF_MAX_REQ_QUEUES) {
190 struct virtchnl_vsi_resource *vsi_res;
193 dev_info(&adapter->pdev->dev, "Received %d queues, but can only have a max of %d\n",
194 adapter->vf_res->num_queue_pairs,
195 IAVF_MAX_REQ_QUEUES);
196 dev_info(&adapter->pdev->dev, "Fixing by reducing queues to %d\n",
197 IAVF_MAX_REQ_QUEUES);
198 adapter->vf_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
199 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
200 vsi_res = &adapter->vf_res->vsi_res[i];
201 vsi_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
208 * @adapter: private adapter structure
210 * Get VF configuration from PF and populate hw structure. Must be called after
211 * admin queue is initialized. Busy waits until response is received from PF,
212 * with maximum timeout. Response from PF is returned in the buffer for further
213 * processing by the caller.
215 int iavf_get_vf_config(struct iavf_adapter *adapter)
217 struct iavf_hw *hw = &adapter->hw;
218 struct iavf_arq_event_info event;
222 len = sizeof(struct virtchnl_vf_resource) +
223 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
225 event.msg_buf = kzalloc(len, GFP_KERNEL);
229 err = iavf_poll_virtchnl_msg(hw, &event, VIRTCHNL_OP_GET_VF_RESOURCES);
230 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
232 /* some PFs send more queues than we should have so validate that
233 * we aren't getting too many queues
236 iavf_validate_num_queues(adapter);
237 iavf_vf_parse_hw_config(hw, adapter->vf_res);
239 kfree(event.msg_buf);
244 int iavf_get_vf_vlan_v2_caps(struct iavf_adapter *adapter)
246 struct iavf_arq_event_info event;
250 len = sizeof(struct virtchnl_vlan_caps);
252 event.msg_buf = kzalloc(len, GFP_KERNEL);
256 err = iavf_poll_virtchnl_msg(&adapter->hw, &event,
257 VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS);
259 memcpy(&adapter->vlan_v2_caps, event.msg_buf,
260 min(event.msg_len, len));
262 kfree(event.msg_buf);
268 * iavf_configure_queues
269 * @adapter: adapter structure
271 * Request that the PF set up our (previously allocated) queues.
273 void iavf_configure_queues(struct iavf_adapter *adapter)
275 struct virtchnl_vsi_queue_config_info *vqci;
276 struct virtchnl_queue_pair_info *vqpi;
277 int pairs = adapter->num_active_queues;
278 int i, max_frame = IAVF_MAX_RXBUFFER;
281 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
282 /* bail because we already have a command pending */
283 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
284 adapter->current_op);
287 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
288 len = struct_size(vqci, qpair, pairs);
289 vqci = kzalloc(len, GFP_KERNEL);
293 /* Limit maximum frame size when jumbo frames is not enabled */
294 if (!(adapter->flags & IAVF_FLAG_LEGACY_RX) &&
295 (adapter->netdev->mtu <= ETH_DATA_LEN))
296 max_frame = IAVF_RXBUFFER_1536 - NET_IP_ALIGN;
298 vqci->vsi_id = adapter->vsi_res->vsi_id;
299 vqci->num_queue_pairs = pairs;
301 /* Size check is not needed here - HW max is 16 queue pairs, and we
302 * can fit info for 31 of them into the AQ buffer before it overflows.
304 for (i = 0; i < pairs; i++) {
305 vqpi->txq.vsi_id = vqci->vsi_id;
306 vqpi->txq.queue_id = i;
307 vqpi->txq.ring_len = adapter->tx_rings[i].count;
308 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
309 vqpi->rxq.vsi_id = vqci->vsi_id;
310 vqpi->rxq.queue_id = i;
311 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
312 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
313 vqpi->rxq.max_pkt_size = max_frame;
314 vqpi->rxq.databuffer_size =
315 ALIGN(adapter->rx_rings[i].rx_buf_len,
316 BIT_ULL(IAVF_RXQ_CTX_DBUFF_SHIFT));
320 adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES;
321 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
328 * @adapter: adapter structure
330 * Request that the PF enable all of our queues.
332 void iavf_enable_queues(struct iavf_adapter *adapter)
334 struct virtchnl_queue_select vqs;
336 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
337 /* bail because we already have a command pending */
338 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
339 adapter->current_op);
342 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
343 vqs.vsi_id = adapter->vsi_res->vsi_id;
344 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
345 vqs.rx_queues = vqs.tx_queues;
346 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_QUEUES;
347 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
348 (u8 *)&vqs, sizeof(vqs));
352 * iavf_disable_queues
353 * @adapter: adapter structure
355 * Request that the PF disable all of our queues.
357 void iavf_disable_queues(struct iavf_adapter *adapter)
359 struct virtchnl_queue_select vqs;
361 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
362 /* bail because we already have a command pending */
363 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
364 adapter->current_op);
367 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
368 vqs.vsi_id = adapter->vsi_res->vsi_id;
369 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
370 vqs.rx_queues = vqs.tx_queues;
371 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_QUEUES;
372 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
373 (u8 *)&vqs, sizeof(vqs));
378 * @adapter: adapter structure
380 * Request that the PF map queues to interrupt vectors. Misc causes, including
381 * admin queue, are always mapped to vector 0.
383 void iavf_map_queues(struct iavf_adapter *adapter)
385 struct virtchnl_irq_map_info *vimi;
386 struct virtchnl_vector_map *vecmap;
387 struct iavf_q_vector *q_vector;
388 int v_idx, q_vectors;
391 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
392 /* bail because we already have a command pending */
393 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
394 adapter->current_op);
397 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
399 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
401 len = struct_size(vimi, vecmap, adapter->num_msix_vectors);
402 vimi = kzalloc(len, GFP_KERNEL);
406 vimi->num_vectors = adapter->num_msix_vectors;
407 /* Queue vectors first */
408 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
409 q_vector = &adapter->q_vectors[v_idx];
410 vecmap = &vimi->vecmap[v_idx];
412 vecmap->vsi_id = adapter->vsi_res->vsi_id;
413 vecmap->vector_id = v_idx + NONQ_VECS;
414 vecmap->txq_map = q_vector->ring_mask;
415 vecmap->rxq_map = q_vector->ring_mask;
416 vecmap->rxitr_idx = IAVF_RX_ITR;
417 vecmap->txitr_idx = IAVF_TX_ITR;
419 /* Misc vector last - this is only for AdminQ messages */
420 vecmap = &vimi->vecmap[v_idx];
421 vecmap->vsi_id = adapter->vsi_res->vsi_id;
422 vecmap->vector_id = 0;
426 adapter->aq_required &= ~IAVF_FLAG_AQ_MAP_VECTORS;
427 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
433 * iavf_set_mac_addr_type - Set the correct request type from the filter type
434 * @virtchnl_ether_addr: pointer to requested list element
435 * @filter: pointer to requested filter
438 iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr,
439 const struct iavf_mac_filter *filter)
441 virtchnl_ether_addr->type = filter->is_primary ?
442 VIRTCHNL_ETHER_ADDR_PRIMARY :
443 VIRTCHNL_ETHER_ADDR_EXTRA;
447 * iavf_add_ether_addrs
448 * @adapter: adapter structure
450 * Request that the PF add one or more addresses to our filters.
452 void iavf_add_ether_addrs(struct iavf_adapter *adapter)
454 struct virtchnl_ether_addr_list *veal;
455 struct iavf_mac_filter *f;
456 int i = 0, count = 0;
460 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
461 /* bail because we already have a command pending */
462 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
463 adapter->current_op);
467 spin_lock_bh(&adapter->mac_vlan_list_lock);
469 list_for_each_entry(f, &adapter->mac_filter_list, list) {
474 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
475 spin_unlock_bh(&adapter->mac_vlan_list_lock);
478 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
480 len = struct_size(veal, list, count);
481 if (len > IAVF_MAX_AQ_BUF_SIZE) {
482 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
483 count = (IAVF_MAX_AQ_BUF_SIZE -
484 sizeof(struct virtchnl_ether_addr_list)) /
485 sizeof(struct virtchnl_ether_addr);
486 len = struct_size(veal, list, count);
490 veal = kzalloc(len, GFP_ATOMIC);
492 spin_unlock_bh(&adapter->mac_vlan_list_lock);
496 veal->vsi_id = adapter->vsi_res->vsi_id;
497 veal->num_elements = count;
498 list_for_each_entry(f, &adapter->mac_filter_list, list) {
500 ether_addr_copy(veal->list[i].addr, f->macaddr);
501 iavf_set_mac_addr_type(&veal->list[i], f);
509 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
511 spin_unlock_bh(&adapter->mac_vlan_list_lock);
513 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len);
518 * iavf_del_ether_addrs
519 * @adapter: adapter structure
521 * Request that the PF remove one or more addresses from our filters.
523 void iavf_del_ether_addrs(struct iavf_adapter *adapter)
525 struct virtchnl_ether_addr_list *veal;
526 struct iavf_mac_filter *f, *ftmp;
527 int i = 0, count = 0;
531 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
532 /* bail because we already have a command pending */
533 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
534 adapter->current_op);
538 spin_lock_bh(&adapter->mac_vlan_list_lock);
540 list_for_each_entry(f, &adapter->mac_filter_list, list) {
545 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
546 spin_unlock_bh(&adapter->mac_vlan_list_lock);
549 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
551 len = struct_size(veal, list, count);
552 if (len > IAVF_MAX_AQ_BUF_SIZE) {
553 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
554 count = (IAVF_MAX_AQ_BUF_SIZE -
555 sizeof(struct virtchnl_ether_addr_list)) /
556 sizeof(struct virtchnl_ether_addr);
557 len = struct_size(veal, list, count);
560 veal = kzalloc(len, GFP_ATOMIC);
562 spin_unlock_bh(&adapter->mac_vlan_list_lock);
566 veal->vsi_id = adapter->vsi_res->vsi_id;
567 veal->num_elements = count;
568 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
570 ether_addr_copy(veal->list[i].addr, f->macaddr);
571 iavf_set_mac_addr_type(&veal->list[i], f);
580 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
582 spin_unlock_bh(&adapter->mac_vlan_list_lock);
584 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, (u8 *)veal, len);
590 * @adapter: adapter structure
592 * Submit list of filters based on PF response.
594 static void iavf_mac_add_ok(struct iavf_adapter *adapter)
596 struct iavf_mac_filter *f, *ftmp;
598 spin_lock_bh(&adapter->mac_vlan_list_lock);
599 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
600 f->is_new_mac = false;
602 spin_unlock_bh(&adapter->mac_vlan_list_lock);
606 * iavf_mac_add_reject
607 * @adapter: adapter structure
609 * Remove filters from list based on PF response.
611 static void iavf_mac_add_reject(struct iavf_adapter *adapter)
613 struct net_device *netdev = adapter->netdev;
614 struct iavf_mac_filter *f, *ftmp;
616 spin_lock_bh(&adapter->mac_vlan_list_lock);
617 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
618 if (f->remove && ether_addr_equal(f->macaddr, netdev->dev_addr))
626 spin_unlock_bh(&adapter->mac_vlan_list_lock);
630 * iavf_vlan_add_reject
631 * @adapter: adapter structure
633 * Remove VLAN filters from list based on PF response.
635 static void iavf_vlan_add_reject(struct iavf_adapter *adapter)
637 struct iavf_vlan_filter *f, *ftmp;
639 spin_lock_bh(&adapter->mac_vlan_list_lock);
640 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
641 if (f->is_new_vlan) {
642 if (f->vlan.tpid == ETH_P_8021Q)
643 clear_bit(f->vlan.vid,
644 adapter->vsi.active_cvlans);
646 clear_bit(f->vlan.vid,
647 adapter->vsi.active_svlans);
653 spin_unlock_bh(&adapter->mac_vlan_list_lock);
658 * @adapter: adapter structure
660 * Request that the PF add one or more VLAN filters to our VSI.
662 void iavf_add_vlans(struct iavf_adapter *adapter)
664 int len, i = 0, count = 0;
665 struct iavf_vlan_filter *f;
668 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
669 /* bail because we already have a command pending */
670 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
671 adapter->current_op);
675 spin_lock_bh(&adapter->mac_vlan_list_lock);
677 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
681 if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
682 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
683 spin_unlock_bh(&adapter->mac_vlan_list_lock);
687 if (VLAN_ALLOWED(adapter)) {
688 struct virtchnl_vlan_filter_list *vvfl;
690 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
692 len = sizeof(*vvfl) + (count * sizeof(u16));
693 if (len > IAVF_MAX_AQ_BUF_SIZE) {
694 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
695 count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl)) /
697 len = sizeof(*vvfl) + (count * sizeof(u16));
700 vvfl = kzalloc(len, GFP_ATOMIC);
702 spin_unlock_bh(&adapter->mac_vlan_list_lock);
706 vvfl->vsi_id = adapter->vsi_res->vsi_id;
707 vvfl->num_elements = count;
708 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
710 vvfl->vlan_id[i] = f->vlan.vid;
713 f->is_new_vlan = true;
719 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
721 spin_unlock_bh(&adapter->mac_vlan_list_lock);
723 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
726 u16 max_vlans = adapter->vlan_v2_caps.filtering.max_filters;
727 u16 current_vlans = iavf_get_num_vlans_added(adapter);
728 struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
730 adapter->current_op = VIRTCHNL_OP_ADD_VLAN_V2;
732 if ((count + current_vlans) > max_vlans &&
733 current_vlans < max_vlans) {
734 count = max_vlans - iavf_get_num_vlans_added(adapter);
738 len = sizeof(*vvfl_v2) + ((count - 1) *
739 sizeof(struct virtchnl_vlan_filter));
740 if (len > IAVF_MAX_AQ_BUF_SIZE) {
741 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
742 count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl_v2)) /
743 sizeof(struct virtchnl_vlan_filter);
744 len = sizeof(*vvfl_v2) +
746 sizeof(struct virtchnl_vlan_filter));
750 vvfl_v2 = kzalloc(len, GFP_ATOMIC);
752 spin_unlock_bh(&adapter->mac_vlan_list_lock);
756 vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
757 vvfl_v2->num_elements = count;
758 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
760 struct virtchnl_vlan_supported_caps *filtering_support =
761 &adapter->vlan_v2_caps.filtering.filtering_support;
762 struct virtchnl_vlan *vlan;
767 /* give priority over outer if it's enabled */
768 if (filtering_support->outer)
769 vlan = &vvfl_v2->filters[i].outer;
771 vlan = &vvfl_v2->filters[i].inner;
773 vlan->tci = f->vlan.vid;
774 vlan->tpid = f->vlan.tpid;
778 f->is_new_vlan = true;
783 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
785 spin_unlock_bh(&adapter->mac_vlan_list_lock);
787 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN_V2,
795 * @adapter: adapter structure
797 * Request that the PF remove one or more VLAN filters from our VSI.
799 void iavf_del_vlans(struct iavf_adapter *adapter)
801 struct iavf_vlan_filter *f, *ftmp;
802 int len, i = 0, count = 0;
805 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
806 /* bail because we already have a command pending */
807 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
808 adapter->current_op);
812 spin_lock_bh(&adapter->mac_vlan_list_lock);
814 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
815 /* since VLAN capabilities are not allowed, we dont want to send
816 * a VLAN delete request because it will most likely fail and
817 * create unnecessary errors/noise, so just free the VLAN
818 * filters marked for removal to enable bailing out before
819 * sending a virtchnl message
821 if (f->remove && !VLAN_FILTERING_ALLOWED(adapter)) {
824 } else if (f->remove) {
828 if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
829 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
830 spin_unlock_bh(&adapter->mac_vlan_list_lock);
834 if (VLAN_ALLOWED(adapter)) {
835 struct virtchnl_vlan_filter_list *vvfl;
837 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
839 len = sizeof(*vvfl) + (count * sizeof(u16));
840 if (len > IAVF_MAX_AQ_BUF_SIZE) {
841 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
842 count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl)) /
844 len = sizeof(*vvfl) + (count * sizeof(u16));
847 vvfl = kzalloc(len, GFP_ATOMIC);
849 spin_unlock_bh(&adapter->mac_vlan_list_lock);
853 vvfl->vsi_id = adapter->vsi_res->vsi_id;
854 vvfl->num_elements = count;
855 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
857 vvfl->vlan_id[i] = f->vlan.vid;
867 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
869 spin_unlock_bh(&adapter->mac_vlan_list_lock);
871 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
874 struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
876 adapter->current_op = VIRTCHNL_OP_DEL_VLAN_V2;
878 len = sizeof(*vvfl_v2) +
879 ((count - 1) * sizeof(struct virtchnl_vlan_filter));
880 if (len > IAVF_MAX_AQ_BUF_SIZE) {
881 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
882 count = (IAVF_MAX_AQ_BUF_SIZE -
884 sizeof(struct virtchnl_vlan_filter);
885 len = sizeof(*vvfl_v2) +
887 sizeof(struct virtchnl_vlan_filter));
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) {
901 struct virtchnl_vlan_supported_caps *filtering_support =
902 &adapter->vlan_v2_caps.filtering.filtering_support;
903 struct virtchnl_vlan *vlan;
905 /* give priority over outer if it's enabled */
906 if (filtering_support->outer)
907 vlan = &vvfl_v2->filters[i].outer;
909 vlan = &vvfl_v2->filters[i].inner;
911 vlan->tci = f->vlan.vid;
912 vlan->tpid = f->vlan.tpid;
923 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
925 spin_unlock_bh(&adapter->mac_vlan_list_lock);
927 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN_V2,
934 * iavf_set_promiscuous
935 * @adapter: adapter structure
936 * @flags: bitmask to control unicast/multicast promiscuous.
938 * Request that the PF enable promiscuous mode for our VSI.
940 void iavf_set_promiscuous(struct iavf_adapter *adapter, int flags)
942 struct virtchnl_promisc_info vpi;
945 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
946 /* bail because we already have a command pending */
947 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
948 adapter->current_op);
952 promisc_all = FLAG_VF_UNICAST_PROMISC |
953 FLAG_VF_MULTICAST_PROMISC;
954 if ((flags & promisc_all) == promisc_all) {
955 adapter->flags |= IAVF_FLAG_PROMISC_ON;
956 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_PROMISC;
957 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
960 if (flags & FLAG_VF_MULTICAST_PROMISC) {
961 adapter->flags |= IAVF_FLAG_ALLMULTI_ON;
962 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_ALLMULTI;
963 dev_info(&adapter->pdev->dev, "%s is entering multicast promiscuous mode\n",
964 adapter->netdev->name);
968 if (adapter->flags & IAVF_FLAG_PROMISC_ON) {
969 adapter->flags &= ~IAVF_FLAG_PROMISC_ON;
970 adapter->aq_required &= ~IAVF_FLAG_AQ_RELEASE_PROMISC;
971 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
974 if (adapter->flags & IAVF_FLAG_ALLMULTI_ON) {
975 adapter->flags &= ~IAVF_FLAG_ALLMULTI_ON;
976 adapter->aq_required &= ~IAVF_FLAG_AQ_RELEASE_ALLMULTI;
977 dev_info(&adapter->pdev->dev, "%s is leaving multicast promiscuous mode\n",
978 adapter->netdev->name);
982 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
983 vpi.vsi_id = adapter->vsi_res->vsi_id;
985 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
986 (u8 *)&vpi, sizeof(vpi));
991 * @adapter: adapter structure
993 * Request VSI statistics from PF.
995 void iavf_request_stats(struct iavf_adapter *adapter)
997 struct virtchnl_queue_select vqs;
999 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1000 /* no error message, this isn't crucial */
1004 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_STATS;
1005 adapter->current_op = VIRTCHNL_OP_GET_STATS;
1006 vqs.vsi_id = adapter->vsi_res->vsi_id;
1007 /* queue maps are ignored for this message - only the vsi is used */
1008 if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs,
1010 /* if the request failed, don't lock out others */
1011 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1016 * @adapter: adapter structure
1018 * Request hash enable capabilities from PF
1020 void iavf_get_hena(struct iavf_adapter *adapter)
1022 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1023 /* bail because we already have a command pending */
1024 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
1025 adapter->current_op);
1028 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
1029 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA;
1030 iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0);
1035 * @adapter: adapter structure
1037 * Request the PF to set our RSS hash capabilities
1039 void iavf_set_hena(struct iavf_adapter *adapter)
1041 struct virtchnl_rss_hena vrh;
1043 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1044 /* bail because we already have a command pending */
1045 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
1046 adapter->current_op);
1049 vrh.hena = adapter->hena;
1050 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
1051 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA;
1052 iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh,
1058 * @adapter: adapter structure
1060 * Request the PF to set our RSS hash key
1062 void iavf_set_rss_key(struct iavf_adapter *adapter)
1064 struct virtchnl_rss_key *vrk;
1067 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1068 /* bail because we already have a command pending */
1069 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
1070 adapter->current_op);
1073 len = sizeof(struct virtchnl_rss_key) +
1074 (adapter->rss_key_size * sizeof(u8)) - 1;
1075 vrk = kzalloc(len, GFP_KERNEL);
1078 vrk->vsi_id = adapter->vsi.id;
1079 vrk->key_len = adapter->rss_key_size;
1080 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
1082 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
1083 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY;
1084 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len);
1090 * @adapter: adapter structure
1092 * Request the PF to set our RSS lookup table
1094 void iavf_set_rss_lut(struct iavf_adapter *adapter)
1096 struct virtchnl_rss_lut *vrl;
1099 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1100 /* bail because we already have a command pending */
1101 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
1102 adapter->current_op);
1105 len = sizeof(struct virtchnl_rss_lut) +
1106 (adapter->rss_lut_size * sizeof(u8)) - 1;
1107 vrl = kzalloc(len, GFP_KERNEL);
1110 vrl->vsi_id = adapter->vsi.id;
1111 vrl->lut_entries = adapter->rss_lut_size;
1112 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
1113 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
1114 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT;
1115 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len);
1120 * iavf_enable_vlan_stripping
1121 * @adapter: adapter structure
1123 * Request VLAN header stripping to be enabled
1125 void iavf_enable_vlan_stripping(struct iavf_adapter *adapter)
1127 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1128 /* bail because we already have a command pending */
1129 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
1130 adapter->current_op);
1133 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
1134 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
1135 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0);
1139 * iavf_disable_vlan_stripping
1140 * @adapter: adapter structure
1142 * Request VLAN header stripping to be disabled
1144 void iavf_disable_vlan_stripping(struct iavf_adapter *adapter)
1146 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1147 /* bail because we already have a command pending */
1148 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
1149 adapter->current_op);
1152 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
1153 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
1154 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0);
1158 * iavf_tpid_to_vc_ethertype - transform from VLAN TPID to virtchnl ethertype
1159 * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1161 static u32 iavf_tpid_to_vc_ethertype(u16 tpid)
1165 return VIRTCHNL_VLAN_ETHERTYPE_8100;
1167 return VIRTCHNL_VLAN_ETHERTYPE_88A8;
1174 * iavf_set_vc_offload_ethertype - set virtchnl ethertype for offload message
1175 * @adapter: adapter structure
1176 * @msg: message structure used for updating offloads over virtchnl to update
1177 * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1178 * @offload_op: opcode used to determine which support structure to check
1181 iavf_set_vc_offload_ethertype(struct iavf_adapter *adapter,
1182 struct virtchnl_vlan_setting *msg, u16 tpid,
1183 enum virtchnl_ops offload_op)
1185 struct virtchnl_vlan_supported_caps *offload_support;
1186 u16 vc_ethertype = iavf_tpid_to_vc_ethertype(tpid);
1188 /* reference the correct offload support structure */
1189 switch (offload_op) {
1190 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1191 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1193 &adapter->vlan_v2_caps.offloads.stripping_support;
1195 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1196 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1198 &adapter->vlan_v2_caps.offloads.insertion_support;
1201 dev_err(&adapter->pdev->dev, "Invalid opcode %d for setting virtchnl ethertype to enable/disable VLAN offloads\n",
1206 /* make sure ethertype is supported */
1207 if (offload_support->outer & vc_ethertype &&
1208 offload_support->outer & VIRTCHNL_VLAN_TOGGLE) {
1209 msg->outer_ethertype_setting = vc_ethertype;
1210 } else if (offload_support->inner & vc_ethertype &&
1211 offload_support->inner & VIRTCHNL_VLAN_TOGGLE) {
1212 msg->inner_ethertype_setting = vc_ethertype;
1214 dev_dbg(&adapter->pdev->dev, "opcode %d unsupported for VLAN TPID 0x%04x\n",
1223 * iavf_clear_offload_v2_aq_required - clear AQ required bit for offload request
1224 * @adapter: adapter structure
1226 * @offload_op: opcode used to determine which AQ required bit to clear
1229 iavf_clear_offload_v2_aq_required(struct iavf_adapter *adapter, u16 tpid,
1230 enum virtchnl_ops offload_op)
1232 switch (offload_op) {
1233 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1234 if (tpid == ETH_P_8021Q)
1235 adapter->aq_required &=
1236 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_STRIPPING;
1237 else if (tpid == ETH_P_8021AD)
1238 adapter->aq_required &=
1239 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_STRIPPING;
1241 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1242 if (tpid == ETH_P_8021Q)
1243 adapter->aq_required &=
1244 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_STRIPPING;
1245 else if (tpid == ETH_P_8021AD)
1246 adapter->aq_required &=
1247 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_STRIPPING;
1249 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1250 if (tpid == ETH_P_8021Q)
1251 adapter->aq_required &=
1252 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_INSERTION;
1253 else if (tpid == ETH_P_8021AD)
1254 adapter->aq_required &=
1255 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_INSERTION;
1257 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1258 if (tpid == ETH_P_8021Q)
1259 adapter->aq_required &=
1260 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_INSERTION;
1261 else if (tpid == ETH_P_8021AD)
1262 adapter->aq_required &=
1263 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_INSERTION;
1266 dev_err(&adapter->pdev->dev, "Unsupported opcode %d specified for clearing aq_required bits for VIRTCHNL_VF_OFFLOAD_VLAN_V2 offload request\n",
1272 * iavf_send_vlan_offload_v2 - send offload enable/disable over virtchnl
1273 * @adapter: adapter structure
1274 * @tpid: VLAN TPID used for the command (i.e. 0x8100 or 0x88a8)
1275 * @offload_op: offload_op used to make the request over virtchnl
1278 iavf_send_vlan_offload_v2(struct iavf_adapter *adapter, u16 tpid,
1279 enum virtchnl_ops offload_op)
1281 struct virtchnl_vlan_setting *msg;
1282 int len = sizeof(*msg);
1284 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1285 /* bail because we already have a command pending */
1286 dev_err(&adapter->pdev->dev, "Cannot send %d, command %d pending\n",
1287 offload_op, adapter->current_op);
1291 adapter->current_op = offload_op;
1293 msg = kzalloc(len, GFP_KERNEL);
1297 msg->vport_id = adapter->vsi_res->vsi_id;
1299 /* always clear to prevent unsupported and endless requests */
1300 iavf_clear_offload_v2_aq_required(adapter, tpid, offload_op);
1302 /* only send valid offload requests */
1303 if (!iavf_set_vc_offload_ethertype(adapter, msg, tpid, offload_op))
1304 iavf_send_pf_msg(adapter, offload_op, (u8 *)msg, len);
1306 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1312 * iavf_enable_vlan_stripping_v2 - enable VLAN stripping
1313 * @adapter: adapter structure
1314 * @tpid: VLAN TPID used to enable VLAN stripping
1316 void iavf_enable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1318 iavf_send_vlan_offload_v2(adapter, tpid,
1319 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2);
1323 * iavf_disable_vlan_stripping_v2 - disable VLAN stripping
1324 * @adapter: adapter structure
1325 * @tpid: VLAN TPID used to disable VLAN stripping
1327 void iavf_disable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1329 iavf_send_vlan_offload_v2(adapter, tpid,
1330 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2);
1334 * iavf_enable_vlan_insertion_v2 - enable VLAN insertion
1335 * @adapter: adapter structure
1336 * @tpid: VLAN TPID used to enable VLAN insertion
1338 void iavf_enable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1340 iavf_send_vlan_offload_v2(adapter, tpid,
1341 VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2);
1345 * iavf_disable_vlan_insertion_v2 - disable VLAN insertion
1346 * @adapter: adapter structure
1347 * @tpid: VLAN TPID used to disable VLAN insertion
1349 void iavf_disable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1351 iavf_send_vlan_offload_v2(adapter, tpid,
1352 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2);
1355 #define IAVF_MAX_SPEED_STRLEN 13
1358 * iavf_print_link_message - print link up or down
1359 * @adapter: adapter structure
1361 * Log a message telling the world of our wonderous link status
1363 static void iavf_print_link_message(struct iavf_adapter *adapter)
1365 struct net_device *netdev = adapter->netdev;
1366 int link_speed_mbps;
1369 if (!adapter->link_up) {
1370 netdev_info(netdev, "NIC Link is Down\n");
1374 speed = kzalloc(IAVF_MAX_SPEED_STRLEN, GFP_KERNEL);
1378 if (ADV_LINK_SUPPORT(adapter)) {
1379 link_speed_mbps = adapter->link_speed_mbps;
1380 goto print_link_msg;
1383 switch (adapter->link_speed) {
1384 case VIRTCHNL_LINK_SPEED_40GB:
1385 link_speed_mbps = SPEED_40000;
1387 case VIRTCHNL_LINK_SPEED_25GB:
1388 link_speed_mbps = SPEED_25000;
1390 case VIRTCHNL_LINK_SPEED_20GB:
1391 link_speed_mbps = SPEED_20000;
1393 case VIRTCHNL_LINK_SPEED_10GB:
1394 link_speed_mbps = SPEED_10000;
1396 case VIRTCHNL_LINK_SPEED_5GB:
1397 link_speed_mbps = SPEED_5000;
1399 case VIRTCHNL_LINK_SPEED_2_5GB:
1400 link_speed_mbps = SPEED_2500;
1402 case VIRTCHNL_LINK_SPEED_1GB:
1403 link_speed_mbps = SPEED_1000;
1405 case VIRTCHNL_LINK_SPEED_100MB:
1406 link_speed_mbps = SPEED_100;
1409 link_speed_mbps = SPEED_UNKNOWN;
1414 if (link_speed_mbps > SPEED_1000) {
1415 if (link_speed_mbps == SPEED_2500)
1416 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "2.5 Gbps");
1418 /* convert to Gbps inline */
1419 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1420 link_speed_mbps / 1000, "Gbps");
1421 } else if (link_speed_mbps == SPEED_UNKNOWN) {
1422 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%s", "Unknown Mbps");
1424 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1425 link_speed_mbps, "Mbps");
1428 netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed);
1433 * iavf_get_vpe_link_status
1434 * @adapter: adapter structure
1435 * @vpe: virtchnl_pf_event structure
1437 * Helper function for determining the link status
1440 iavf_get_vpe_link_status(struct iavf_adapter *adapter,
1441 struct virtchnl_pf_event *vpe)
1443 if (ADV_LINK_SUPPORT(adapter))
1444 return vpe->event_data.link_event_adv.link_status;
1446 return vpe->event_data.link_event.link_status;
1450 * iavf_set_adapter_link_speed_from_vpe
1451 * @adapter: adapter structure for which we are setting the link speed
1452 * @vpe: virtchnl_pf_event structure that contains the link speed we are setting
1454 * Helper function for setting iavf_adapter link speed
1457 iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter *adapter,
1458 struct virtchnl_pf_event *vpe)
1460 if (ADV_LINK_SUPPORT(adapter))
1461 adapter->link_speed_mbps =
1462 vpe->event_data.link_event_adv.link_speed;
1464 adapter->link_speed = vpe->event_data.link_event.link_speed;
1468 * iavf_enable_channels
1469 * @adapter: adapter structure
1471 * Request that the PF enable channels as specified by
1472 * the user via tc tool.
1474 void iavf_enable_channels(struct iavf_adapter *adapter)
1476 struct virtchnl_tc_info *vti = NULL;
1480 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1481 /* bail because we already have a command pending */
1482 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1483 adapter->current_op);
1487 len = struct_size(vti, list, adapter->num_tc - 1);
1488 vti = kzalloc(len, GFP_KERNEL);
1491 vti->num_tc = adapter->num_tc;
1492 for (i = 0; i < vti->num_tc; i++) {
1493 vti->list[i].count = adapter->ch_config.ch_info[i].count;
1494 vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
1495 vti->list[i].pad = 0;
1496 vti->list[i].max_tx_rate =
1497 adapter->ch_config.ch_info[i].max_tx_rate;
1500 adapter->ch_config.state = __IAVF_TC_RUNNING;
1501 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1502 adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
1503 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS;
1504 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len);
1509 * iavf_disable_channels
1510 * @adapter: adapter structure
1512 * Request that the PF disable channels that are configured
1514 void iavf_disable_channels(struct iavf_adapter *adapter)
1516 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1517 /* bail because we already have a command pending */
1518 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1519 adapter->current_op);
1523 adapter->ch_config.state = __IAVF_TC_INVALID;
1524 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1525 adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
1526 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS;
1527 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0);
1531 * iavf_print_cloud_filter
1532 * @adapter: adapter structure
1533 * @f: cloud filter to print
1535 * Print the cloud filter
1537 static void iavf_print_cloud_filter(struct iavf_adapter *adapter,
1538 struct virtchnl_filter *f)
1540 switch (f->flow_type) {
1541 case VIRTCHNL_TCP_V4_FLOW:
1542 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",
1543 &f->data.tcp_spec.dst_mac,
1544 &f->data.tcp_spec.src_mac,
1545 ntohs(f->data.tcp_spec.vlan_id),
1546 &f->data.tcp_spec.dst_ip[0],
1547 &f->data.tcp_spec.src_ip[0],
1548 ntohs(f->data.tcp_spec.dst_port),
1549 ntohs(f->data.tcp_spec.src_port));
1551 case VIRTCHNL_TCP_V6_FLOW:
1552 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",
1553 &f->data.tcp_spec.dst_mac,
1554 &f->data.tcp_spec.src_mac,
1555 ntohs(f->data.tcp_spec.vlan_id),
1556 &f->data.tcp_spec.dst_ip,
1557 &f->data.tcp_spec.src_ip,
1558 ntohs(f->data.tcp_spec.dst_port),
1559 ntohs(f->data.tcp_spec.src_port));
1565 * iavf_add_cloud_filter
1566 * @adapter: adapter structure
1568 * Request that the PF add cloud filters as specified
1569 * by the user via tc tool.
1571 void iavf_add_cloud_filter(struct iavf_adapter *adapter)
1573 struct iavf_cloud_filter *cf;
1574 struct virtchnl_filter *f;
1575 int len = 0, count = 0;
1577 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1578 /* bail because we already have a command pending */
1579 dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1580 adapter->current_op);
1583 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1590 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER;
1593 adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1595 len = sizeof(struct virtchnl_filter);
1596 f = kzalloc(len, GFP_KERNEL);
1600 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1602 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1604 cf->state = __IAVF_CF_ADD_PENDING;
1605 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER,
1613 * iavf_del_cloud_filter
1614 * @adapter: adapter structure
1616 * Request that the PF delete cloud filters as specified
1617 * by the user via tc tool.
1619 void iavf_del_cloud_filter(struct iavf_adapter *adapter)
1621 struct iavf_cloud_filter *cf, *cftmp;
1622 struct virtchnl_filter *f;
1623 int len = 0, count = 0;
1625 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1626 /* bail because we already have a command pending */
1627 dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1628 adapter->current_op);
1631 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1638 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER;
1641 adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1643 len = sizeof(struct virtchnl_filter);
1644 f = kzalloc(len, GFP_KERNEL);
1648 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1650 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1652 cf->state = __IAVF_CF_DEL_PENDING;
1653 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER,
1661 * iavf_add_fdir_filter
1662 * @adapter: the VF adapter structure
1664 * Request that the PF add Flow Director filters as specified
1665 * by the user via ethtool.
1667 void iavf_add_fdir_filter(struct iavf_adapter *adapter)
1669 struct iavf_fdir_fltr *fdir;
1670 struct virtchnl_fdir_add *f;
1671 bool process_fltr = false;
1674 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1675 /* bail because we already have a command pending */
1676 dev_err(&adapter->pdev->dev, "Cannot add Flow Director filter, command %d pending\n",
1677 adapter->current_op);
1681 len = sizeof(struct virtchnl_fdir_add);
1682 f = kzalloc(len, GFP_KERNEL);
1686 spin_lock_bh(&adapter->fdir_fltr_lock);
1687 list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1688 if (fdir->state == IAVF_FDIR_FLTR_ADD_REQUEST) {
1689 process_fltr = true;
1690 fdir->state = IAVF_FDIR_FLTR_ADD_PENDING;
1691 memcpy(f, &fdir->vc_add_msg, len);
1695 spin_unlock_bh(&adapter->fdir_fltr_lock);
1697 if (!process_fltr) {
1698 /* prevent iavf_add_fdir_filter() from being called when there
1699 * are no filters to add
1701 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_FDIR_FILTER;
1705 adapter->current_op = VIRTCHNL_OP_ADD_FDIR_FILTER;
1706 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_FDIR_FILTER, (u8 *)f, len);
1711 * iavf_del_fdir_filter
1712 * @adapter: the VF adapter structure
1714 * Request that the PF delete Flow Director filters as specified
1715 * by the user via ethtool.
1717 void iavf_del_fdir_filter(struct iavf_adapter *adapter)
1719 struct iavf_fdir_fltr *fdir;
1720 struct virtchnl_fdir_del f;
1721 bool process_fltr = false;
1724 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1725 /* bail because we already have a command pending */
1726 dev_err(&adapter->pdev->dev, "Cannot remove Flow Director filter, command %d pending\n",
1727 adapter->current_op);
1731 len = sizeof(struct virtchnl_fdir_del);
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_DEL_REQUEST) {
1736 process_fltr = true;
1738 f.vsi_id = fdir->vc_add_msg.vsi_id;
1739 f.flow_id = fdir->flow_id;
1740 fdir->state = IAVF_FDIR_FLTR_DEL_PENDING;
1744 spin_unlock_bh(&adapter->fdir_fltr_lock);
1746 if (!process_fltr) {
1747 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_FDIR_FILTER;
1751 adapter->current_op = VIRTCHNL_OP_DEL_FDIR_FILTER;
1752 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_FDIR_FILTER, (u8 *)&f, len);
1756 * iavf_add_adv_rss_cfg
1757 * @adapter: the VF adapter structure
1759 * Request that the PF add RSS configuration as specified
1760 * by the user via ethtool.
1762 void iavf_add_adv_rss_cfg(struct iavf_adapter *adapter)
1764 struct virtchnl_rss_cfg *rss_cfg;
1765 struct iavf_adv_rss *rss;
1766 bool process_rss = false;
1769 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1770 /* bail because we already have a command pending */
1771 dev_err(&adapter->pdev->dev, "Cannot add RSS configuration, command %d pending\n",
1772 adapter->current_op);
1776 len = sizeof(struct virtchnl_rss_cfg);
1777 rss_cfg = kzalloc(len, GFP_KERNEL);
1781 spin_lock_bh(&adapter->adv_rss_lock);
1782 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1783 if (rss->state == IAVF_ADV_RSS_ADD_REQUEST) {
1785 rss->state = IAVF_ADV_RSS_ADD_PENDING;
1786 memcpy(rss_cfg, &rss->cfg_msg, len);
1787 iavf_print_adv_rss_cfg(adapter, rss,
1788 "Input set change for",
1793 spin_unlock_bh(&adapter->adv_rss_lock);
1796 adapter->current_op = VIRTCHNL_OP_ADD_RSS_CFG;
1797 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_RSS_CFG,
1798 (u8 *)rss_cfg, len);
1800 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_ADV_RSS_CFG;
1807 * iavf_del_adv_rss_cfg
1808 * @adapter: the VF adapter structure
1810 * Request that the PF delete RSS configuration as specified
1811 * by the user via ethtool.
1813 void iavf_del_adv_rss_cfg(struct iavf_adapter *adapter)
1815 struct virtchnl_rss_cfg *rss_cfg;
1816 struct iavf_adv_rss *rss;
1817 bool process_rss = false;
1820 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1821 /* bail because we already have a command pending */
1822 dev_err(&adapter->pdev->dev, "Cannot remove RSS configuration, command %d pending\n",
1823 adapter->current_op);
1827 len = sizeof(struct virtchnl_rss_cfg);
1828 rss_cfg = kzalloc(len, GFP_KERNEL);
1832 spin_lock_bh(&adapter->adv_rss_lock);
1833 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1834 if (rss->state == IAVF_ADV_RSS_DEL_REQUEST) {
1836 rss->state = IAVF_ADV_RSS_DEL_PENDING;
1837 memcpy(rss_cfg, &rss->cfg_msg, len);
1841 spin_unlock_bh(&adapter->adv_rss_lock);
1844 adapter->current_op = VIRTCHNL_OP_DEL_RSS_CFG;
1845 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_RSS_CFG,
1846 (u8 *)rss_cfg, len);
1848 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_ADV_RSS_CFG;
1855 * iavf_request_reset
1856 * @adapter: adapter structure
1858 * Request that the PF reset this VF. No response is expected.
1860 int iavf_request_reset(struct iavf_adapter *adapter)
1863 /* Don't check CURRENT_OP - this is always higher priority */
1864 err = iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
1865 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1870 * iavf_netdev_features_vlan_strip_set - update vlan strip status
1871 * @netdev: ptr to netdev being adjusted
1872 * @enable: enable or disable vlan strip
1874 * Helper function to change vlan strip status in netdev->features.
1876 static void iavf_netdev_features_vlan_strip_set(struct net_device *netdev,
1880 netdev->features |= NETIF_F_HW_VLAN_CTAG_RX;
1882 netdev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
1886 * iavf_virtchnl_completion
1887 * @adapter: adapter structure
1888 * @v_opcode: opcode sent by PF
1889 * @v_retval: retval sent by PF
1890 * @msg: message sent by PF
1891 * @msglen: message length
1893 * Asynchronous completion function for admin queue messages. Rather than busy
1894 * wait, we fire off our requests and assume that no errors will be returned.
1895 * This function handles the reply messages.
1897 void iavf_virtchnl_completion(struct iavf_adapter *adapter,
1898 enum virtchnl_ops v_opcode,
1899 enum iavf_status v_retval, u8 *msg, u16 msglen)
1901 struct net_device *netdev = adapter->netdev;
1903 if (v_opcode == VIRTCHNL_OP_EVENT) {
1904 struct virtchnl_pf_event *vpe =
1905 (struct virtchnl_pf_event *)msg;
1906 bool link_up = iavf_get_vpe_link_status(adapter, vpe);
1908 switch (vpe->event) {
1909 case VIRTCHNL_EVENT_LINK_CHANGE:
1910 iavf_set_adapter_link_speed_from_vpe(adapter, vpe);
1912 /* we've already got the right link status, bail */
1913 if (adapter->link_up == link_up)
1917 /* If we get link up message and start queues
1918 * before our queues are configured it will
1919 * trigger a TX hang. In that case, just ignore
1920 * the link status message,we'll get another one
1921 * after we enable queues and actually prepared
1924 if (adapter->state != __IAVF_RUNNING)
1927 /* For ADq enabled VF, we reconfigure VSIs and
1928 * re-allocate queues. Hence wait till all
1929 * queues are enabled.
1931 if (adapter->flags &
1932 IAVF_FLAG_QUEUES_DISABLED)
1936 adapter->link_up = link_up;
1938 netif_tx_start_all_queues(netdev);
1939 netif_carrier_on(netdev);
1941 netif_tx_stop_all_queues(netdev);
1942 netif_carrier_off(netdev);
1944 iavf_print_link_message(adapter);
1946 case VIRTCHNL_EVENT_RESET_IMPENDING:
1947 dev_info(&adapter->pdev->dev, "Reset indication received from the PF\n");
1948 if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) {
1949 adapter->flags |= IAVF_FLAG_RESET_PENDING;
1950 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
1951 queue_work(iavf_wq, &adapter->reset_task);
1955 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
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));
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);
1974 case VIRTCHNL_OP_DEL_VLAN:
1975 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1976 iavf_stat_str(&adapter->hw, v_retval));
1978 case VIRTCHNL_OP_DEL_ETH_ADDR:
1979 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1980 iavf_stat_str(&adapter->hw, v_retval));
1982 case VIRTCHNL_OP_ENABLE_CHANNELS:
1983 dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
1984 iavf_stat_str(&adapter->hw, v_retval));
1985 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1986 adapter->ch_config.state = __IAVF_TC_INVALID;
1987 netdev_reset_tc(netdev);
1988 netif_tx_start_all_queues(netdev);
1990 case VIRTCHNL_OP_DISABLE_CHANNELS:
1991 dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
1992 iavf_stat_str(&adapter->hw, v_retval));
1993 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1994 adapter->ch_config.state = __IAVF_TC_RUNNING;
1995 netif_tx_start_all_queues(netdev);
1997 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
1998 struct iavf_cloud_filter *cf, *cftmp;
2000 list_for_each_entry_safe(cf, cftmp,
2001 &adapter->cloud_filter_list,
2003 if (cf->state == __IAVF_CF_ADD_PENDING) {
2004 cf->state = __IAVF_CF_INVALID;
2005 dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
2006 iavf_stat_str(&adapter->hw,
2008 iavf_print_cloud_filter(adapter,
2010 list_del(&cf->list);
2012 adapter->num_cloud_filters--;
2017 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2018 struct iavf_cloud_filter *cf;
2020 list_for_each_entry(cf, &adapter->cloud_filter_list,
2022 if (cf->state == __IAVF_CF_DEL_PENDING) {
2023 cf->state = __IAVF_CF_ACTIVE;
2024 dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
2025 iavf_stat_str(&adapter->hw,
2027 iavf_print_cloud_filter(adapter,
2033 case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2034 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2036 spin_lock_bh(&adapter->fdir_fltr_lock);
2037 list_for_each_entry_safe(fdir, fdir_tmp,
2038 &adapter->fdir_list_head,
2040 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2041 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter, error %s\n",
2042 iavf_stat_str(&adapter->hw,
2044 iavf_print_fdir_fltr(adapter, fdir);
2046 dev_err(&adapter->pdev->dev,
2048 list_del(&fdir->list);
2050 adapter->fdir_active_fltr--;
2053 spin_unlock_bh(&adapter->fdir_fltr_lock);
2056 case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2057 struct iavf_fdir_fltr *fdir;
2059 spin_lock_bh(&adapter->fdir_fltr_lock);
2060 list_for_each_entry(fdir, &adapter->fdir_list_head,
2062 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2063 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2064 dev_info(&adapter->pdev->dev, "Failed to del Flow Director filter, error %s\n",
2065 iavf_stat_str(&adapter->hw,
2067 iavf_print_fdir_fltr(adapter, fdir);
2070 spin_unlock_bh(&adapter->fdir_fltr_lock);
2073 case VIRTCHNL_OP_ADD_RSS_CFG: {
2074 struct iavf_adv_rss *rss, *rss_tmp;
2076 spin_lock_bh(&adapter->adv_rss_lock);
2077 list_for_each_entry_safe(rss, rss_tmp,
2078 &adapter->adv_rss_list_head,
2080 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2081 iavf_print_adv_rss_cfg(adapter, rss,
2082 "Failed to change the input set for",
2084 list_del(&rss->list);
2088 spin_unlock_bh(&adapter->adv_rss_lock);
2091 case VIRTCHNL_OP_DEL_RSS_CFG: {
2092 struct iavf_adv_rss *rss;
2094 spin_lock_bh(&adapter->adv_rss_lock);
2095 list_for_each_entry(rss, &adapter->adv_rss_list_head,
2097 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2098 rss->state = IAVF_ADV_RSS_ACTIVE;
2099 dev_err(&adapter->pdev->dev, "Failed to delete RSS configuration, error %s\n",
2100 iavf_stat_str(&adapter->hw,
2104 spin_unlock_bh(&adapter->adv_rss_lock);
2107 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2108 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2109 /* Vlan stripping could not be enabled by ethtool.
2110 * Disable it in netdev->features.
2112 iavf_netdev_features_vlan_strip_set(netdev, false);
2114 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2115 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2116 /* Vlan stripping could not be disabled by ethtool.
2117 * Enable it in netdev->features.
2119 iavf_netdev_features_vlan_strip_set(netdev, true);
2121 case VIRTCHNL_OP_ADD_VLAN_V2:
2122 iavf_vlan_add_reject(adapter);
2123 dev_warn(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
2124 iavf_stat_str(&adapter->hw, v_retval));
2127 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
2128 v_retval, iavf_stat_str(&adapter->hw, v_retval),
2133 case VIRTCHNL_OP_ADD_ETH_ADDR:
2135 iavf_mac_add_ok(adapter);
2136 if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr))
2137 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2139 case VIRTCHNL_OP_GET_STATS: {
2140 struct iavf_eth_stats *stats =
2141 (struct iavf_eth_stats *)msg;
2142 netdev->stats.rx_packets = stats->rx_unicast +
2143 stats->rx_multicast +
2144 stats->rx_broadcast;
2145 netdev->stats.tx_packets = stats->tx_unicast +
2146 stats->tx_multicast +
2147 stats->tx_broadcast;
2148 netdev->stats.rx_bytes = stats->rx_bytes;
2149 netdev->stats.tx_bytes = stats->tx_bytes;
2150 netdev->stats.tx_errors = stats->tx_errors;
2151 netdev->stats.rx_dropped = stats->rx_discards;
2152 netdev->stats.tx_dropped = stats->tx_discards;
2153 adapter->current_stats = *stats;
2156 case VIRTCHNL_OP_GET_VF_RESOURCES: {
2157 u16 len = sizeof(struct virtchnl_vf_resource) +
2159 sizeof(struct virtchnl_vsi_resource);
2160 memcpy(adapter->vf_res, msg, min(msglen, len));
2161 iavf_validate_num_queues(adapter);
2162 iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
2163 if (is_zero_ether_addr(adapter->hw.mac.addr)) {
2164 /* restore current mac address */
2165 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2167 /* refresh current mac address if changed */
2168 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2169 ether_addr_copy(netdev->perm_addr,
2170 adapter->hw.mac.addr);
2172 spin_lock_bh(&adapter->mac_vlan_list_lock);
2173 iavf_add_filter(adapter, adapter->hw.mac.addr);
2175 if (VLAN_ALLOWED(adapter)) {
2176 if (!list_empty(&adapter->vlan_filter_list)) {
2177 struct iavf_vlan_filter *vlf;
2179 /* re-add all VLAN filters over virtchnl */
2180 list_for_each_entry(vlf,
2181 &adapter->vlan_filter_list,
2185 adapter->aq_required |=
2186 IAVF_FLAG_AQ_ADD_VLAN_FILTER;
2190 spin_unlock_bh(&adapter->mac_vlan_list_lock);
2192 iavf_parse_vf_resource_msg(adapter);
2194 /* negotiated VIRTCHNL_VF_OFFLOAD_VLAN_V2, so wait for the
2195 * response to VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS to finish
2198 if (VLAN_V2_ALLOWED(adapter))
2200 /* fallthrough and finish config if VIRTCHNL_VF_OFFLOAD_VLAN_V2
2201 * wasn't successfully negotiated with the PF
2205 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS: {
2206 if (v_opcode == VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS)
2207 memcpy(&adapter->vlan_v2_caps, msg,
2209 sizeof(adapter->vlan_v2_caps)));
2211 iavf_process_config(adapter);
2212 adapter->flags |= IAVF_FLAG_SETUP_NETDEV_FEATURES;
2215 case VIRTCHNL_OP_ENABLE_QUEUES:
2216 /* enable transmits */
2217 iavf_irq_enable(adapter, true);
2218 adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED;
2220 case VIRTCHNL_OP_DISABLE_QUEUES:
2221 iavf_free_all_tx_resources(adapter);
2222 iavf_free_all_rx_resources(adapter);
2223 if (adapter->state == __IAVF_DOWN_PENDING) {
2224 iavf_change_state(adapter, __IAVF_DOWN);
2225 wake_up(&adapter->down_waitqueue);
2228 case VIRTCHNL_OP_VERSION:
2229 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
2230 /* Don't display an error if we get these out of sequence.
2231 * If the firmware needed to get kicked, we'll get these and
2234 if (v_opcode != adapter->current_op)
2237 case VIRTCHNL_OP_IWARP:
2238 /* Gobble zero-length replies from the PF. They indicate that
2239 * a previous message was received OK, and the client doesn't
2242 if (msglen && CLIENT_ENABLED(adapter))
2243 iavf_notify_client_message(&adapter->vsi, msg, msglen);
2246 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
2247 adapter->client_pending &=
2248 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
2250 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
2251 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
2253 if (msglen == sizeof(*vrh))
2254 adapter->hena = vrh->hena;
2256 dev_warn(&adapter->pdev->dev,
2257 "Invalid message %d from PF\n", v_opcode);
2260 case VIRTCHNL_OP_REQUEST_QUEUES: {
2261 struct virtchnl_vf_res_request *vfres =
2262 (struct virtchnl_vf_res_request *)msg;
2264 if (vfres->num_queue_pairs != adapter->num_req_queues) {
2265 dev_info(&adapter->pdev->dev,
2266 "Requested %d queues, PF can support %d\n",
2267 adapter->num_req_queues,
2268 vfres->num_queue_pairs);
2269 adapter->num_req_queues = 0;
2270 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2274 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2275 struct iavf_cloud_filter *cf;
2277 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
2278 if (cf->state == __IAVF_CF_ADD_PENDING)
2279 cf->state = __IAVF_CF_ACTIVE;
2283 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2284 struct iavf_cloud_filter *cf, *cftmp;
2286 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
2288 if (cf->state == __IAVF_CF_DEL_PENDING) {
2289 cf->state = __IAVF_CF_INVALID;
2290 list_del(&cf->list);
2292 adapter->num_cloud_filters--;
2297 case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2298 struct virtchnl_fdir_add *add_fltr = (struct virtchnl_fdir_add *)msg;
2299 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2301 spin_lock_bh(&adapter->fdir_fltr_lock);
2302 list_for_each_entry_safe(fdir, fdir_tmp,
2303 &adapter->fdir_list_head,
2305 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2306 if (add_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2307 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is added\n",
2309 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2310 fdir->flow_id = add_fltr->flow_id;
2312 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter with status: %d\n",
2314 iavf_print_fdir_fltr(adapter, fdir);
2315 list_del(&fdir->list);
2317 adapter->fdir_active_fltr--;
2321 spin_unlock_bh(&adapter->fdir_fltr_lock);
2324 case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2325 struct virtchnl_fdir_del *del_fltr = (struct virtchnl_fdir_del *)msg;
2326 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2328 spin_lock_bh(&adapter->fdir_fltr_lock);
2329 list_for_each_entry_safe(fdir, fdir_tmp, &adapter->fdir_list_head,
2331 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2332 if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2333 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is deleted\n",
2335 list_del(&fdir->list);
2337 adapter->fdir_active_fltr--;
2339 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2340 dev_info(&adapter->pdev->dev, "Failed to delete Flow Director filter with status: %d\n",
2342 iavf_print_fdir_fltr(adapter, fdir);
2346 spin_unlock_bh(&adapter->fdir_fltr_lock);
2349 case VIRTCHNL_OP_ADD_RSS_CFG: {
2350 struct iavf_adv_rss *rss;
2352 spin_lock_bh(&adapter->adv_rss_lock);
2353 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
2354 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2355 iavf_print_adv_rss_cfg(adapter, rss,
2356 "Input set change for",
2358 rss->state = IAVF_ADV_RSS_ACTIVE;
2361 spin_unlock_bh(&adapter->adv_rss_lock);
2364 case VIRTCHNL_OP_DEL_RSS_CFG: {
2365 struct iavf_adv_rss *rss, *rss_tmp;
2367 spin_lock_bh(&adapter->adv_rss_lock);
2368 list_for_each_entry_safe(rss, rss_tmp,
2369 &adapter->adv_rss_list_head, list) {
2370 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2371 list_del(&rss->list);
2375 spin_unlock_bh(&adapter->adv_rss_lock);
2378 case VIRTCHNL_OP_ADD_VLAN_V2: {
2379 struct iavf_vlan_filter *f;
2381 spin_lock_bh(&adapter->mac_vlan_list_lock);
2382 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
2383 if (f->is_new_vlan) {
2384 f->is_new_vlan = false;
2385 if (f->vlan.tpid == ETH_P_8021Q)
2386 set_bit(f->vlan.vid,
2387 adapter->vsi.active_cvlans);
2389 set_bit(f->vlan.vid,
2390 adapter->vsi.active_svlans);
2393 spin_unlock_bh(&adapter->mac_vlan_list_lock);
2396 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2397 /* PF enabled vlan strip on this VF.
2398 * Update netdev->features if needed to be in sync with ethtool.
2401 iavf_netdev_features_vlan_strip_set(netdev, true);
2403 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2404 /* PF disabled vlan strip on this VF.
2405 * Update netdev->features if needed to be in sync with ethtool.
2408 iavf_netdev_features_vlan_strip_set(netdev, false);
2411 if (adapter->current_op && (v_opcode != adapter->current_op))
2412 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
2413 adapter->current_op, v_opcode);
2415 } /* switch v_opcode */
2416 adapter->current_op = VIRTCHNL_OP_UNKNOWN;