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);
631 * @adapter: adapter structure
633 * Request that the PF add one or more VLAN filters to our VSI.
635 void iavf_add_vlans(struct iavf_adapter *adapter)
637 int len, i = 0, count = 0;
638 struct iavf_vlan_filter *f;
641 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
642 /* bail because we already have a command pending */
643 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
644 adapter->current_op);
648 spin_lock_bh(&adapter->mac_vlan_list_lock);
650 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
654 if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
655 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
656 spin_unlock_bh(&adapter->mac_vlan_list_lock);
660 if (VLAN_ALLOWED(adapter)) {
661 struct virtchnl_vlan_filter_list *vvfl;
663 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
665 len = sizeof(*vvfl) + (count * sizeof(u16));
666 if (len > IAVF_MAX_AQ_BUF_SIZE) {
667 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
668 count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl)) /
670 len = sizeof(*vvfl) + (count * sizeof(u16));
673 vvfl = kzalloc(len, GFP_ATOMIC);
675 spin_unlock_bh(&adapter->mac_vlan_list_lock);
679 vvfl->vsi_id = adapter->vsi_res->vsi_id;
680 vvfl->num_elements = count;
681 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
683 vvfl->vlan_id[i] = f->vlan.vid;
691 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
693 spin_unlock_bh(&adapter->mac_vlan_list_lock);
695 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
698 struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
700 adapter->current_op = VIRTCHNL_OP_ADD_VLAN_V2;
702 len = sizeof(*vvfl_v2) + ((count - 1) *
703 sizeof(struct virtchnl_vlan_filter));
704 if (len > IAVF_MAX_AQ_BUF_SIZE) {
705 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
706 count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl_v2)) /
707 sizeof(struct virtchnl_vlan_filter);
708 len = sizeof(*vvfl_v2) +
710 sizeof(struct virtchnl_vlan_filter));
714 vvfl_v2 = kzalloc(len, GFP_ATOMIC);
716 spin_unlock_bh(&adapter->mac_vlan_list_lock);
720 vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
721 vvfl_v2->num_elements = count;
722 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
724 struct virtchnl_vlan_supported_caps *filtering_support =
725 &adapter->vlan_v2_caps.filtering.filtering_support;
726 struct virtchnl_vlan *vlan;
728 /* give priority over outer if it's enabled */
729 if (filtering_support->outer)
730 vlan = &vvfl_v2->filters[i].outer;
732 vlan = &vvfl_v2->filters[i].inner;
734 vlan->tci = f->vlan.vid;
735 vlan->tpid = f->vlan.tpid;
745 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
747 spin_unlock_bh(&adapter->mac_vlan_list_lock);
749 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN_V2,
757 * @adapter: adapter structure
759 * Request that the PF remove one or more VLAN filters from our VSI.
761 void iavf_del_vlans(struct iavf_adapter *adapter)
763 struct iavf_vlan_filter *f, *ftmp;
764 int len, i = 0, count = 0;
767 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
768 /* bail because we already have a command pending */
769 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
770 adapter->current_op);
774 spin_lock_bh(&adapter->mac_vlan_list_lock);
776 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
777 /* since VLAN capabilities are not allowed, we dont want to send
778 * a VLAN delete request because it will most likely fail and
779 * create unnecessary errors/noise, so just free the VLAN
780 * filters marked for removal to enable bailing out before
781 * sending a virtchnl message
783 if (f->remove && !VLAN_FILTERING_ALLOWED(adapter)) {
786 } else if (f->remove) {
790 if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
791 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
792 spin_unlock_bh(&adapter->mac_vlan_list_lock);
796 if (VLAN_ALLOWED(adapter)) {
797 struct virtchnl_vlan_filter_list *vvfl;
799 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
801 len = sizeof(*vvfl) + (count * sizeof(u16));
802 if (len > IAVF_MAX_AQ_BUF_SIZE) {
803 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
804 count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl)) /
806 len = sizeof(*vvfl) + (count * sizeof(u16));
809 vvfl = kzalloc(len, GFP_ATOMIC);
811 spin_unlock_bh(&adapter->mac_vlan_list_lock);
815 vvfl->vsi_id = adapter->vsi_res->vsi_id;
816 vvfl->num_elements = count;
817 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
819 vvfl->vlan_id[i] = f->vlan.vid;
829 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
831 spin_unlock_bh(&adapter->mac_vlan_list_lock);
833 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
836 struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
838 adapter->current_op = VIRTCHNL_OP_DEL_VLAN_V2;
840 len = sizeof(*vvfl_v2) +
841 ((count - 1) * sizeof(struct virtchnl_vlan_filter));
842 if (len > IAVF_MAX_AQ_BUF_SIZE) {
843 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
844 count = (IAVF_MAX_AQ_BUF_SIZE -
846 sizeof(struct virtchnl_vlan_filter);
847 len = sizeof(*vvfl_v2) +
849 sizeof(struct virtchnl_vlan_filter));
853 vvfl_v2 = kzalloc(len, GFP_ATOMIC);
855 spin_unlock_bh(&adapter->mac_vlan_list_lock);
859 vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
860 vvfl_v2->num_elements = count;
861 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
863 struct virtchnl_vlan_supported_caps *filtering_support =
864 &adapter->vlan_v2_caps.filtering.filtering_support;
865 struct virtchnl_vlan *vlan;
867 /* give priority over outer if it's enabled */
868 if (filtering_support->outer)
869 vlan = &vvfl_v2->filters[i].outer;
871 vlan = &vvfl_v2->filters[i].inner;
873 vlan->tci = f->vlan.vid;
874 vlan->tpid = f->vlan.tpid;
885 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
887 spin_unlock_bh(&adapter->mac_vlan_list_lock);
889 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN_V2,
896 * iavf_set_promiscuous
897 * @adapter: adapter structure
898 * @flags: bitmask to control unicast/multicast promiscuous.
900 * Request that the PF enable promiscuous mode for our VSI.
902 void iavf_set_promiscuous(struct iavf_adapter *adapter, int flags)
904 struct virtchnl_promisc_info vpi;
907 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
908 /* bail because we already have a command pending */
909 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
910 adapter->current_op);
914 promisc_all = FLAG_VF_UNICAST_PROMISC |
915 FLAG_VF_MULTICAST_PROMISC;
916 if ((flags & promisc_all) == promisc_all) {
917 adapter->flags |= IAVF_FLAG_PROMISC_ON;
918 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_PROMISC;
919 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
922 if (flags & FLAG_VF_MULTICAST_PROMISC) {
923 adapter->flags |= IAVF_FLAG_ALLMULTI_ON;
924 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_ALLMULTI;
925 dev_info(&adapter->pdev->dev, "%s is entering multicast promiscuous mode\n",
926 adapter->netdev->name);
930 if (adapter->flags & IAVF_FLAG_PROMISC_ON) {
931 adapter->flags &= ~IAVF_FLAG_PROMISC_ON;
932 adapter->aq_required &= ~IAVF_FLAG_AQ_RELEASE_PROMISC;
933 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
936 if (adapter->flags & IAVF_FLAG_ALLMULTI_ON) {
937 adapter->flags &= ~IAVF_FLAG_ALLMULTI_ON;
938 adapter->aq_required &= ~IAVF_FLAG_AQ_RELEASE_ALLMULTI;
939 dev_info(&adapter->pdev->dev, "%s is leaving multicast promiscuous mode\n",
940 adapter->netdev->name);
944 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
945 vpi.vsi_id = adapter->vsi_res->vsi_id;
947 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
948 (u8 *)&vpi, sizeof(vpi));
953 * @adapter: adapter structure
955 * Request VSI statistics from PF.
957 void iavf_request_stats(struct iavf_adapter *adapter)
959 struct virtchnl_queue_select vqs;
961 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
962 /* no error message, this isn't crucial */
966 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_STATS;
967 adapter->current_op = VIRTCHNL_OP_GET_STATS;
968 vqs.vsi_id = adapter->vsi_res->vsi_id;
969 /* queue maps are ignored for this message - only the vsi is used */
970 if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs,
972 /* if the request failed, don't lock out others */
973 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
978 * @adapter: adapter structure
980 * Request hash enable capabilities from PF
982 void iavf_get_hena(struct iavf_adapter *adapter)
984 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
985 /* bail because we already have a command pending */
986 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
987 adapter->current_op);
990 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
991 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA;
992 iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0);
997 * @adapter: adapter structure
999 * Request the PF to set our RSS hash capabilities
1001 void iavf_set_hena(struct iavf_adapter *adapter)
1003 struct virtchnl_rss_hena vrh;
1005 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1006 /* bail because we already have a command pending */
1007 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
1008 adapter->current_op);
1011 vrh.hena = adapter->hena;
1012 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
1013 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA;
1014 iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh,
1020 * @adapter: adapter structure
1022 * Request the PF to set our RSS hash key
1024 void iavf_set_rss_key(struct iavf_adapter *adapter)
1026 struct virtchnl_rss_key *vrk;
1029 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1030 /* bail because we already have a command pending */
1031 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
1032 adapter->current_op);
1035 len = sizeof(struct virtchnl_rss_key) +
1036 (adapter->rss_key_size * sizeof(u8)) - 1;
1037 vrk = kzalloc(len, GFP_KERNEL);
1040 vrk->vsi_id = adapter->vsi.id;
1041 vrk->key_len = adapter->rss_key_size;
1042 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
1044 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
1045 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY;
1046 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len);
1052 * @adapter: adapter structure
1054 * Request the PF to set our RSS lookup table
1056 void iavf_set_rss_lut(struct iavf_adapter *adapter)
1058 struct virtchnl_rss_lut *vrl;
1061 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1062 /* bail because we already have a command pending */
1063 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
1064 adapter->current_op);
1067 len = sizeof(struct virtchnl_rss_lut) +
1068 (adapter->rss_lut_size * sizeof(u8)) - 1;
1069 vrl = kzalloc(len, GFP_KERNEL);
1072 vrl->vsi_id = adapter->vsi.id;
1073 vrl->lut_entries = adapter->rss_lut_size;
1074 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
1075 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
1076 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT;
1077 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len);
1082 * iavf_enable_vlan_stripping
1083 * @adapter: adapter structure
1085 * Request VLAN header stripping to be enabled
1087 void iavf_enable_vlan_stripping(struct iavf_adapter *adapter)
1089 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1090 /* bail because we already have a command pending */
1091 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
1092 adapter->current_op);
1095 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
1096 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
1097 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0);
1101 * iavf_disable_vlan_stripping
1102 * @adapter: adapter structure
1104 * Request VLAN header stripping to be disabled
1106 void iavf_disable_vlan_stripping(struct iavf_adapter *adapter)
1108 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1109 /* bail because we already have a command pending */
1110 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
1111 adapter->current_op);
1114 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
1115 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
1116 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0);
1120 * iavf_tpid_to_vc_ethertype - transform from VLAN TPID to virtchnl ethertype
1121 * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1123 static u32 iavf_tpid_to_vc_ethertype(u16 tpid)
1127 return VIRTCHNL_VLAN_ETHERTYPE_8100;
1129 return VIRTCHNL_VLAN_ETHERTYPE_88A8;
1136 * iavf_set_vc_offload_ethertype - set virtchnl ethertype for offload message
1137 * @adapter: adapter structure
1138 * @msg: message structure used for updating offloads over virtchnl to update
1139 * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1140 * @offload_op: opcode used to determine which support structure to check
1143 iavf_set_vc_offload_ethertype(struct iavf_adapter *adapter,
1144 struct virtchnl_vlan_setting *msg, u16 tpid,
1145 enum virtchnl_ops offload_op)
1147 struct virtchnl_vlan_supported_caps *offload_support;
1148 u16 vc_ethertype = iavf_tpid_to_vc_ethertype(tpid);
1150 /* reference the correct offload support structure */
1151 switch (offload_op) {
1152 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1153 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1155 &adapter->vlan_v2_caps.offloads.stripping_support;
1157 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1158 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1160 &adapter->vlan_v2_caps.offloads.insertion_support;
1163 dev_err(&adapter->pdev->dev, "Invalid opcode %d for setting virtchnl ethertype to enable/disable VLAN offloads\n",
1168 /* make sure ethertype is supported */
1169 if (offload_support->outer & vc_ethertype &&
1170 offload_support->outer & VIRTCHNL_VLAN_TOGGLE) {
1171 msg->outer_ethertype_setting = vc_ethertype;
1172 } else if (offload_support->inner & vc_ethertype &&
1173 offload_support->inner & VIRTCHNL_VLAN_TOGGLE) {
1174 msg->inner_ethertype_setting = vc_ethertype;
1176 dev_dbg(&adapter->pdev->dev, "opcode %d unsupported for VLAN TPID 0x%04x\n",
1185 * iavf_clear_offload_v2_aq_required - clear AQ required bit for offload request
1186 * @adapter: adapter structure
1188 * @offload_op: opcode used to determine which AQ required bit to clear
1191 iavf_clear_offload_v2_aq_required(struct iavf_adapter *adapter, u16 tpid,
1192 enum virtchnl_ops offload_op)
1194 switch (offload_op) {
1195 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1196 if (tpid == ETH_P_8021Q)
1197 adapter->aq_required &=
1198 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_STRIPPING;
1199 else if (tpid == ETH_P_8021AD)
1200 adapter->aq_required &=
1201 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_STRIPPING;
1203 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1204 if (tpid == ETH_P_8021Q)
1205 adapter->aq_required &=
1206 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_STRIPPING;
1207 else if (tpid == ETH_P_8021AD)
1208 adapter->aq_required &=
1209 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_STRIPPING;
1211 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1212 if (tpid == ETH_P_8021Q)
1213 adapter->aq_required &=
1214 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_INSERTION;
1215 else if (tpid == ETH_P_8021AD)
1216 adapter->aq_required &=
1217 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_INSERTION;
1219 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1220 if (tpid == ETH_P_8021Q)
1221 adapter->aq_required &=
1222 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_INSERTION;
1223 else if (tpid == ETH_P_8021AD)
1224 adapter->aq_required &=
1225 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_INSERTION;
1228 dev_err(&adapter->pdev->dev, "Unsupported opcode %d specified for clearing aq_required bits for VIRTCHNL_VF_OFFLOAD_VLAN_V2 offload request\n",
1234 * iavf_send_vlan_offload_v2 - send offload enable/disable over virtchnl
1235 * @adapter: adapter structure
1236 * @tpid: VLAN TPID used for the command (i.e. 0x8100 or 0x88a8)
1237 * @offload_op: offload_op used to make the request over virtchnl
1240 iavf_send_vlan_offload_v2(struct iavf_adapter *adapter, u16 tpid,
1241 enum virtchnl_ops offload_op)
1243 struct virtchnl_vlan_setting *msg;
1244 int len = sizeof(*msg);
1246 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1247 /* bail because we already have a command pending */
1248 dev_err(&adapter->pdev->dev, "Cannot send %d, command %d pending\n",
1249 offload_op, adapter->current_op);
1253 adapter->current_op = offload_op;
1255 msg = kzalloc(len, GFP_KERNEL);
1259 msg->vport_id = adapter->vsi_res->vsi_id;
1261 /* always clear to prevent unsupported and endless requests */
1262 iavf_clear_offload_v2_aq_required(adapter, tpid, offload_op);
1264 /* only send valid offload requests */
1265 if (!iavf_set_vc_offload_ethertype(adapter, msg, tpid, offload_op))
1266 iavf_send_pf_msg(adapter, offload_op, (u8 *)msg, len);
1268 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1274 * iavf_enable_vlan_stripping_v2 - enable VLAN stripping
1275 * @adapter: adapter structure
1276 * @tpid: VLAN TPID used to enable VLAN stripping
1278 void iavf_enable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1280 iavf_send_vlan_offload_v2(adapter, tpid,
1281 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2);
1285 * iavf_disable_vlan_stripping_v2 - disable VLAN stripping
1286 * @adapter: adapter structure
1287 * @tpid: VLAN TPID used to disable VLAN stripping
1289 void iavf_disable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1291 iavf_send_vlan_offload_v2(adapter, tpid,
1292 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2);
1296 * iavf_enable_vlan_insertion_v2 - enable VLAN insertion
1297 * @adapter: adapter structure
1298 * @tpid: VLAN TPID used to enable VLAN insertion
1300 void iavf_enable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1302 iavf_send_vlan_offload_v2(adapter, tpid,
1303 VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2);
1307 * iavf_disable_vlan_insertion_v2 - disable VLAN insertion
1308 * @adapter: adapter structure
1309 * @tpid: VLAN TPID used to disable VLAN insertion
1311 void iavf_disable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1313 iavf_send_vlan_offload_v2(adapter, tpid,
1314 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2);
1317 #define IAVF_MAX_SPEED_STRLEN 13
1320 * iavf_print_link_message - print link up or down
1321 * @adapter: adapter structure
1323 * Log a message telling the world of our wonderous link status
1325 static void iavf_print_link_message(struct iavf_adapter *adapter)
1327 struct net_device *netdev = adapter->netdev;
1328 int link_speed_mbps;
1331 if (!adapter->link_up) {
1332 netdev_info(netdev, "NIC Link is Down\n");
1336 speed = kzalloc(IAVF_MAX_SPEED_STRLEN, GFP_KERNEL);
1340 if (ADV_LINK_SUPPORT(adapter)) {
1341 link_speed_mbps = adapter->link_speed_mbps;
1342 goto print_link_msg;
1345 switch (adapter->link_speed) {
1346 case VIRTCHNL_LINK_SPEED_40GB:
1347 link_speed_mbps = SPEED_40000;
1349 case VIRTCHNL_LINK_SPEED_25GB:
1350 link_speed_mbps = SPEED_25000;
1352 case VIRTCHNL_LINK_SPEED_20GB:
1353 link_speed_mbps = SPEED_20000;
1355 case VIRTCHNL_LINK_SPEED_10GB:
1356 link_speed_mbps = SPEED_10000;
1358 case VIRTCHNL_LINK_SPEED_5GB:
1359 link_speed_mbps = SPEED_5000;
1361 case VIRTCHNL_LINK_SPEED_2_5GB:
1362 link_speed_mbps = SPEED_2500;
1364 case VIRTCHNL_LINK_SPEED_1GB:
1365 link_speed_mbps = SPEED_1000;
1367 case VIRTCHNL_LINK_SPEED_100MB:
1368 link_speed_mbps = SPEED_100;
1371 link_speed_mbps = SPEED_UNKNOWN;
1376 if (link_speed_mbps > SPEED_1000) {
1377 if (link_speed_mbps == SPEED_2500)
1378 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "2.5 Gbps");
1380 /* convert to Gbps inline */
1381 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1382 link_speed_mbps / 1000, "Gbps");
1383 } else if (link_speed_mbps == SPEED_UNKNOWN) {
1384 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%s", "Unknown Mbps");
1386 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1387 link_speed_mbps, "Mbps");
1390 netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed);
1395 * iavf_get_vpe_link_status
1396 * @adapter: adapter structure
1397 * @vpe: virtchnl_pf_event structure
1399 * Helper function for determining the link status
1402 iavf_get_vpe_link_status(struct iavf_adapter *adapter,
1403 struct virtchnl_pf_event *vpe)
1405 if (ADV_LINK_SUPPORT(adapter))
1406 return vpe->event_data.link_event_adv.link_status;
1408 return vpe->event_data.link_event.link_status;
1412 * iavf_set_adapter_link_speed_from_vpe
1413 * @adapter: adapter structure for which we are setting the link speed
1414 * @vpe: virtchnl_pf_event structure that contains the link speed we are setting
1416 * Helper function for setting iavf_adapter link speed
1419 iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter *adapter,
1420 struct virtchnl_pf_event *vpe)
1422 if (ADV_LINK_SUPPORT(adapter))
1423 adapter->link_speed_mbps =
1424 vpe->event_data.link_event_adv.link_speed;
1426 adapter->link_speed = vpe->event_data.link_event.link_speed;
1430 * iavf_enable_channels
1431 * @adapter: adapter structure
1433 * Request that the PF enable channels as specified by
1434 * the user via tc tool.
1436 void iavf_enable_channels(struct iavf_adapter *adapter)
1438 struct virtchnl_tc_info *vti = NULL;
1442 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1443 /* bail because we already have a command pending */
1444 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1445 adapter->current_op);
1449 len = struct_size(vti, list, adapter->num_tc - 1);
1450 vti = kzalloc(len, GFP_KERNEL);
1453 vti->num_tc = adapter->num_tc;
1454 for (i = 0; i < vti->num_tc; i++) {
1455 vti->list[i].count = adapter->ch_config.ch_info[i].count;
1456 vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
1457 vti->list[i].pad = 0;
1458 vti->list[i].max_tx_rate =
1459 adapter->ch_config.ch_info[i].max_tx_rate;
1462 adapter->ch_config.state = __IAVF_TC_RUNNING;
1463 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1464 adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
1465 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS;
1466 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len);
1471 * iavf_disable_channels
1472 * @adapter: adapter structure
1474 * Request that the PF disable channels that are configured
1476 void iavf_disable_channels(struct iavf_adapter *adapter)
1478 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1479 /* bail because we already have a command pending */
1480 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1481 adapter->current_op);
1485 adapter->ch_config.state = __IAVF_TC_INVALID;
1486 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1487 adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
1488 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS;
1489 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0);
1493 * iavf_print_cloud_filter
1494 * @adapter: adapter structure
1495 * @f: cloud filter to print
1497 * Print the cloud filter
1499 static void iavf_print_cloud_filter(struct iavf_adapter *adapter,
1500 struct virtchnl_filter *f)
1502 switch (f->flow_type) {
1503 case VIRTCHNL_TCP_V4_FLOW:
1504 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",
1505 &f->data.tcp_spec.dst_mac,
1506 &f->data.tcp_spec.src_mac,
1507 ntohs(f->data.tcp_spec.vlan_id),
1508 &f->data.tcp_spec.dst_ip[0],
1509 &f->data.tcp_spec.src_ip[0],
1510 ntohs(f->data.tcp_spec.dst_port),
1511 ntohs(f->data.tcp_spec.src_port));
1513 case VIRTCHNL_TCP_V6_FLOW:
1514 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",
1515 &f->data.tcp_spec.dst_mac,
1516 &f->data.tcp_spec.src_mac,
1517 ntohs(f->data.tcp_spec.vlan_id),
1518 &f->data.tcp_spec.dst_ip,
1519 &f->data.tcp_spec.src_ip,
1520 ntohs(f->data.tcp_spec.dst_port),
1521 ntohs(f->data.tcp_spec.src_port));
1527 * iavf_add_cloud_filter
1528 * @adapter: adapter structure
1530 * Request that the PF add cloud filters as specified
1531 * by the user via tc tool.
1533 void iavf_add_cloud_filter(struct iavf_adapter *adapter)
1535 struct iavf_cloud_filter *cf;
1536 struct virtchnl_filter *f;
1537 int len = 0, count = 0;
1539 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1540 /* bail because we already have a command pending */
1541 dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1542 adapter->current_op);
1545 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1552 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER;
1555 adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1557 len = sizeof(struct virtchnl_filter);
1558 f = kzalloc(len, GFP_KERNEL);
1562 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1564 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1566 cf->state = __IAVF_CF_ADD_PENDING;
1567 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER,
1575 * iavf_del_cloud_filter
1576 * @adapter: adapter structure
1578 * Request that the PF delete cloud filters as specified
1579 * by the user via tc tool.
1581 void iavf_del_cloud_filter(struct iavf_adapter *adapter)
1583 struct iavf_cloud_filter *cf, *cftmp;
1584 struct virtchnl_filter *f;
1585 int len = 0, count = 0;
1587 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1588 /* bail because we already have a command pending */
1589 dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1590 adapter->current_op);
1593 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1600 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER;
1603 adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1605 len = sizeof(struct virtchnl_filter);
1606 f = kzalloc(len, GFP_KERNEL);
1610 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1612 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1614 cf->state = __IAVF_CF_DEL_PENDING;
1615 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER,
1623 * iavf_add_fdir_filter
1624 * @adapter: the VF adapter structure
1626 * Request that the PF add Flow Director filters as specified
1627 * by the user via ethtool.
1629 void iavf_add_fdir_filter(struct iavf_adapter *adapter)
1631 struct iavf_fdir_fltr *fdir;
1632 struct virtchnl_fdir_add *f;
1633 bool process_fltr = false;
1636 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1637 /* bail because we already have a command pending */
1638 dev_err(&adapter->pdev->dev, "Cannot add Flow Director filter, command %d pending\n",
1639 adapter->current_op);
1643 len = sizeof(struct virtchnl_fdir_add);
1644 f = kzalloc(len, GFP_KERNEL);
1648 spin_lock_bh(&adapter->fdir_fltr_lock);
1649 list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1650 if (fdir->state == IAVF_FDIR_FLTR_ADD_REQUEST) {
1651 process_fltr = true;
1652 fdir->state = IAVF_FDIR_FLTR_ADD_PENDING;
1653 memcpy(f, &fdir->vc_add_msg, len);
1657 spin_unlock_bh(&adapter->fdir_fltr_lock);
1659 if (!process_fltr) {
1660 /* prevent iavf_add_fdir_filter() from being called when there
1661 * are no filters to add
1663 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_FDIR_FILTER;
1667 adapter->current_op = VIRTCHNL_OP_ADD_FDIR_FILTER;
1668 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_FDIR_FILTER, (u8 *)f, len);
1673 * iavf_del_fdir_filter
1674 * @adapter: the VF adapter structure
1676 * Request that the PF delete Flow Director filters as specified
1677 * by the user via ethtool.
1679 void iavf_del_fdir_filter(struct iavf_adapter *adapter)
1681 struct iavf_fdir_fltr *fdir;
1682 struct virtchnl_fdir_del f;
1683 bool process_fltr = false;
1686 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1687 /* bail because we already have a command pending */
1688 dev_err(&adapter->pdev->dev, "Cannot remove Flow Director filter, command %d pending\n",
1689 adapter->current_op);
1693 len = sizeof(struct virtchnl_fdir_del);
1695 spin_lock_bh(&adapter->fdir_fltr_lock);
1696 list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1697 if (fdir->state == IAVF_FDIR_FLTR_DEL_REQUEST) {
1698 process_fltr = true;
1700 f.vsi_id = fdir->vc_add_msg.vsi_id;
1701 f.flow_id = fdir->flow_id;
1702 fdir->state = IAVF_FDIR_FLTR_DEL_PENDING;
1706 spin_unlock_bh(&adapter->fdir_fltr_lock);
1708 if (!process_fltr) {
1709 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_FDIR_FILTER;
1713 adapter->current_op = VIRTCHNL_OP_DEL_FDIR_FILTER;
1714 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_FDIR_FILTER, (u8 *)&f, len);
1718 * iavf_add_adv_rss_cfg
1719 * @adapter: the VF adapter structure
1721 * Request that the PF add RSS configuration as specified
1722 * by the user via ethtool.
1724 void iavf_add_adv_rss_cfg(struct iavf_adapter *adapter)
1726 struct virtchnl_rss_cfg *rss_cfg;
1727 struct iavf_adv_rss *rss;
1728 bool process_rss = false;
1731 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1732 /* bail because we already have a command pending */
1733 dev_err(&adapter->pdev->dev, "Cannot add RSS configuration, command %d pending\n",
1734 adapter->current_op);
1738 len = sizeof(struct virtchnl_rss_cfg);
1739 rss_cfg = kzalloc(len, GFP_KERNEL);
1743 spin_lock_bh(&adapter->adv_rss_lock);
1744 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1745 if (rss->state == IAVF_ADV_RSS_ADD_REQUEST) {
1747 rss->state = IAVF_ADV_RSS_ADD_PENDING;
1748 memcpy(rss_cfg, &rss->cfg_msg, len);
1749 iavf_print_adv_rss_cfg(adapter, rss,
1750 "Input set change for",
1755 spin_unlock_bh(&adapter->adv_rss_lock);
1758 adapter->current_op = VIRTCHNL_OP_ADD_RSS_CFG;
1759 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_RSS_CFG,
1760 (u8 *)rss_cfg, len);
1762 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_ADV_RSS_CFG;
1769 * iavf_del_adv_rss_cfg
1770 * @adapter: the VF adapter structure
1772 * Request that the PF delete RSS configuration as specified
1773 * by the user via ethtool.
1775 void iavf_del_adv_rss_cfg(struct iavf_adapter *adapter)
1777 struct virtchnl_rss_cfg *rss_cfg;
1778 struct iavf_adv_rss *rss;
1779 bool process_rss = false;
1782 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1783 /* bail because we already have a command pending */
1784 dev_err(&adapter->pdev->dev, "Cannot remove RSS configuration, command %d pending\n",
1785 adapter->current_op);
1789 len = sizeof(struct virtchnl_rss_cfg);
1790 rss_cfg = kzalloc(len, GFP_KERNEL);
1794 spin_lock_bh(&adapter->adv_rss_lock);
1795 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1796 if (rss->state == IAVF_ADV_RSS_DEL_REQUEST) {
1798 rss->state = IAVF_ADV_RSS_DEL_PENDING;
1799 memcpy(rss_cfg, &rss->cfg_msg, len);
1803 spin_unlock_bh(&adapter->adv_rss_lock);
1806 adapter->current_op = VIRTCHNL_OP_DEL_RSS_CFG;
1807 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_RSS_CFG,
1808 (u8 *)rss_cfg, len);
1810 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_ADV_RSS_CFG;
1817 * iavf_request_reset
1818 * @adapter: adapter structure
1820 * Request that the PF reset this VF. No response is expected.
1822 int iavf_request_reset(struct iavf_adapter *adapter)
1825 /* Don't check CURRENT_OP - this is always higher priority */
1826 err = iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
1827 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1832 * iavf_netdev_features_vlan_strip_set - update vlan strip status
1833 * @netdev: ptr to netdev being adjusted
1834 * @enable: enable or disable vlan strip
1836 * Helper function to change vlan strip status in netdev->features.
1838 static void iavf_netdev_features_vlan_strip_set(struct net_device *netdev,
1842 netdev->features |= NETIF_F_HW_VLAN_CTAG_RX;
1844 netdev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
1848 * iavf_virtchnl_completion
1849 * @adapter: adapter structure
1850 * @v_opcode: opcode sent by PF
1851 * @v_retval: retval sent by PF
1852 * @msg: message sent by PF
1853 * @msglen: message length
1855 * Asynchronous completion function for admin queue messages. Rather than busy
1856 * wait, we fire off our requests and assume that no errors will be returned.
1857 * This function handles the reply messages.
1859 void iavf_virtchnl_completion(struct iavf_adapter *adapter,
1860 enum virtchnl_ops v_opcode,
1861 enum iavf_status v_retval, u8 *msg, u16 msglen)
1863 struct net_device *netdev = adapter->netdev;
1865 if (v_opcode == VIRTCHNL_OP_EVENT) {
1866 struct virtchnl_pf_event *vpe =
1867 (struct virtchnl_pf_event *)msg;
1868 bool link_up = iavf_get_vpe_link_status(adapter, vpe);
1870 switch (vpe->event) {
1871 case VIRTCHNL_EVENT_LINK_CHANGE:
1872 iavf_set_adapter_link_speed_from_vpe(adapter, vpe);
1874 /* we've already got the right link status, bail */
1875 if (adapter->link_up == link_up)
1879 /* If we get link up message and start queues
1880 * before our queues are configured it will
1881 * trigger a TX hang. In that case, just ignore
1882 * the link status message,we'll get another one
1883 * after we enable queues and actually prepared
1886 if (adapter->state != __IAVF_RUNNING)
1889 /* For ADq enabled VF, we reconfigure VSIs and
1890 * re-allocate queues. Hence wait till all
1891 * queues are enabled.
1893 if (adapter->flags &
1894 IAVF_FLAG_QUEUES_DISABLED)
1898 adapter->link_up = link_up;
1900 netif_tx_start_all_queues(netdev);
1901 netif_carrier_on(netdev);
1903 netif_tx_stop_all_queues(netdev);
1904 netif_carrier_off(netdev);
1906 iavf_print_link_message(adapter);
1908 case VIRTCHNL_EVENT_RESET_IMPENDING:
1909 dev_info(&adapter->pdev->dev, "Reset indication received from the PF\n");
1910 if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) {
1911 adapter->flags |= IAVF_FLAG_RESET_PENDING;
1912 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
1913 queue_work(iavf_wq, &adapter->reset_task);
1917 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
1925 case VIRTCHNL_OP_ADD_VLAN:
1926 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
1927 iavf_stat_str(&adapter->hw, v_retval));
1929 case VIRTCHNL_OP_ADD_ETH_ADDR:
1930 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
1931 iavf_stat_str(&adapter->hw, v_retval));
1932 iavf_mac_add_reject(adapter);
1933 /* restore administratively set MAC address */
1934 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1936 case VIRTCHNL_OP_DEL_VLAN:
1937 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1938 iavf_stat_str(&adapter->hw, v_retval));
1940 case VIRTCHNL_OP_DEL_ETH_ADDR:
1941 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1942 iavf_stat_str(&adapter->hw, v_retval));
1944 case VIRTCHNL_OP_ENABLE_CHANNELS:
1945 dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
1946 iavf_stat_str(&adapter->hw, v_retval));
1947 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1948 adapter->ch_config.state = __IAVF_TC_INVALID;
1949 netdev_reset_tc(netdev);
1950 netif_tx_start_all_queues(netdev);
1952 case VIRTCHNL_OP_DISABLE_CHANNELS:
1953 dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
1954 iavf_stat_str(&adapter->hw, v_retval));
1955 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1956 adapter->ch_config.state = __IAVF_TC_RUNNING;
1957 netif_tx_start_all_queues(netdev);
1959 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
1960 struct iavf_cloud_filter *cf, *cftmp;
1962 list_for_each_entry_safe(cf, cftmp,
1963 &adapter->cloud_filter_list,
1965 if (cf->state == __IAVF_CF_ADD_PENDING) {
1966 cf->state = __IAVF_CF_INVALID;
1967 dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
1968 iavf_stat_str(&adapter->hw,
1970 iavf_print_cloud_filter(adapter,
1972 list_del(&cf->list);
1974 adapter->num_cloud_filters--;
1979 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
1980 struct iavf_cloud_filter *cf;
1982 list_for_each_entry(cf, &adapter->cloud_filter_list,
1984 if (cf->state == __IAVF_CF_DEL_PENDING) {
1985 cf->state = __IAVF_CF_ACTIVE;
1986 dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
1987 iavf_stat_str(&adapter->hw,
1989 iavf_print_cloud_filter(adapter,
1995 case VIRTCHNL_OP_ADD_FDIR_FILTER: {
1996 struct iavf_fdir_fltr *fdir, *fdir_tmp;
1998 spin_lock_bh(&adapter->fdir_fltr_lock);
1999 list_for_each_entry_safe(fdir, fdir_tmp,
2000 &adapter->fdir_list_head,
2002 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2003 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter, error %s\n",
2004 iavf_stat_str(&adapter->hw,
2006 iavf_print_fdir_fltr(adapter, fdir);
2008 dev_err(&adapter->pdev->dev,
2010 list_del(&fdir->list);
2012 adapter->fdir_active_fltr--;
2015 spin_unlock_bh(&adapter->fdir_fltr_lock);
2018 case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2019 struct iavf_fdir_fltr *fdir;
2021 spin_lock_bh(&adapter->fdir_fltr_lock);
2022 list_for_each_entry(fdir, &adapter->fdir_list_head,
2024 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2025 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2026 dev_info(&adapter->pdev->dev, "Failed to del Flow Director filter, error %s\n",
2027 iavf_stat_str(&adapter->hw,
2029 iavf_print_fdir_fltr(adapter, fdir);
2032 spin_unlock_bh(&adapter->fdir_fltr_lock);
2035 case VIRTCHNL_OP_ADD_RSS_CFG: {
2036 struct iavf_adv_rss *rss, *rss_tmp;
2038 spin_lock_bh(&adapter->adv_rss_lock);
2039 list_for_each_entry_safe(rss, rss_tmp,
2040 &adapter->adv_rss_list_head,
2042 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2043 iavf_print_adv_rss_cfg(adapter, rss,
2044 "Failed to change the input set for",
2046 list_del(&rss->list);
2050 spin_unlock_bh(&adapter->adv_rss_lock);
2053 case VIRTCHNL_OP_DEL_RSS_CFG: {
2054 struct iavf_adv_rss *rss;
2056 spin_lock_bh(&adapter->adv_rss_lock);
2057 list_for_each_entry(rss, &adapter->adv_rss_list_head,
2059 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2060 rss->state = IAVF_ADV_RSS_ACTIVE;
2061 dev_err(&adapter->pdev->dev, "Failed to delete RSS configuration, error %s\n",
2062 iavf_stat_str(&adapter->hw,
2066 spin_unlock_bh(&adapter->adv_rss_lock);
2069 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2070 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2071 /* Vlan stripping could not be enabled by ethtool.
2072 * Disable it in netdev->features.
2074 iavf_netdev_features_vlan_strip_set(netdev, false);
2076 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2077 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2078 /* Vlan stripping could not be disabled by ethtool.
2079 * Enable it in netdev->features.
2081 iavf_netdev_features_vlan_strip_set(netdev, true);
2084 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
2085 v_retval, iavf_stat_str(&adapter->hw, v_retval),
2090 case VIRTCHNL_OP_ADD_ETH_ADDR:
2092 iavf_mac_add_ok(adapter);
2093 if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr))
2094 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2096 case VIRTCHNL_OP_GET_STATS: {
2097 struct iavf_eth_stats *stats =
2098 (struct iavf_eth_stats *)msg;
2099 netdev->stats.rx_packets = stats->rx_unicast +
2100 stats->rx_multicast +
2101 stats->rx_broadcast;
2102 netdev->stats.tx_packets = stats->tx_unicast +
2103 stats->tx_multicast +
2104 stats->tx_broadcast;
2105 netdev->stats.rx_bytes = stats->rx_bytes;
2106 netdev->stats.tx_bytes = stats->tx_bytes;
2107 netdev->stats.tx_errors = stats->tx_errors;
2108 netdev->stats.rx_dropped = stats->rx_discards;
2109 netdev->stats.tx_dropped = stats->tx_discards;
2110 adapter->current_stats = *stats;
2113 case VIRTCHNL_OP_GET_VF_RESOURCES: {
2114 u16 len = sizeof(struct virtchnl_vf_resource) +
2116 sizeof(struct virtchnl_vsi_resource);
2117 memcpy(adapter->vf_res, msg, min(msglen, len));
2118 iavf_validate_num_queues(adapter);
2119 iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
2120 if (is_zero_ether_addr(adapter->hw.mac.addr)) {
2121 /* restore current mac address */
2122 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2124 /* refresh current mac address if changed */
2125 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2126 ether_addr_copy(netdev->perm_addr,
2127 adapter->hw.mac.addr);
2129 spin_lock_bh(&adapter->mac_vlan_list_lock);
2130 iavf_add_filter(adapter, adapter->hw.mac.addr);
2132 if (VLAN_ALLOWED(adapter)) {
2133 if (!list_empty(&adapter->vlan_filter_list)) {
2134 struct iavf_vlan_filter *vlf;
2136 /* re-add all VLAN filters over virtchnl */
2137 list_for_each_entry(vlf,
2138 &adapter->vlan_filter_list,
2142 adapter->aq_required |=
2143 IAVF_FLAG_AQ_ADD_VLAN_FILTER;
2147 spin_unlock_bh(&adapter->mac_vlan_list_lock);
2149 iavf_parse_vf_resource_msg(adapter);
2151 /* negotiated VIRTCHNL_VF_OFFLOAD_VLAN_V2, so wait for the
2152 * response to VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS to finish
2155 if (VLAN_V2_ALLOWED(adapter))
2157 /* fallthrough and finish config if VIRTCHNL_VF_OFFLOAD_VLAN_V2
2158 * wasn't successfully negotiated with the PF
2162 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS: {
2163 if (v_opcode == VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS)
2164 memcpy(&adapter->vlan_v2_caps, msg,
2166 sizeof(adapter->vlan_v2_caps)));
2168 iavf_process_config(adapter);
2169 adapter->flags |= IAVF_FLAG_SETUP_NETDEV_FEATURES;
2172 case VIRTCHNL_OP_ENABLE_QUEUES:
2173 /* enable transmits */
2174 iavf_irq_enable(adapter, true);
2175 adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED;
2177 case VIRTCHNL_OP_DISABLE_QUEUES:
2178 iavf_free_all_tx_resources(adapter);
2179 iavf_free_all_rx_resources(adapter);
2180 if (adapter->state == __IAVF_DOWN_PENDING) {
2181 iavf_change_state(adapter, __IAVF_DOWN);
2182 wake_up(&adapter->down_waitqueue);
2185 case VIRTCHNL_OP_VERSION:
2186 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
2187 /* Don't display an error if we get these out of sequence.
2188 * If the firmware needed to get kicked, we'll get these and
2191 if (v_opcode != adapter->current_op)
2194 case VIRTCHNL_OP_IWARP:
2195 /* Gobble zero-length replies from the PF. They indicate that
2196 * a previous message was received OK, and the client doesn't
2199 if (msglen && CLIENT_ENABLED(adapter))
2200 iavf_notify_client_message(&adapter->vsi, msg, msglen);
2203 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
2204 adapter->client_pending &=
2205 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
2207 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
2208 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
2210 if (msglen == sizeof(*vrh))
2211 adapter->hena = vrh->hena;
2213 dev_warn(&adapter->pdev->dev,
2214 "Invalid message %d from PF\n", v_opcode);
2217 case VIRTCHNL_OP_REQUEST_QUEUES: {
2218 struct virtchnl_vf_res_request *vfres =
2219 (struct virtchnl_vf_res_request *)msg;
2221 if (vfres->num_queue_pairs != adapter->num_req_queues) {
2222 dev_info(&adapter->pdev->dev,
2223 "Requested %d queues, PF can support %d\n",
2224 adapter->num_req_queues,
2225 vfres->num_queue_pairs);
2226 adapter->num_req_queues = 0;
2227 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2231 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2232 struct iavf_cloud_filter *cf;
2234 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
2235 if (cf->state == __IAVF_CF_ADD_PENDING)
2236 cf->state = __IAVF_CF_ACTIVE;
2240 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2241 struct iavf_cloud_filter *cf, *cftmp;
2243 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
2245 if (cf->state == __IAVF_CF_DEL_PENDING) {
2246 cf->state = __IAVF_CF_INVALID;
2247 list_del(&cf->list);
2249 adapter->num_cloud_filters--;
2254 case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2255 struct virtchnl_fdir_add *add_fltr = (struct virtchnl_fdir_add *)msg;
2256 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2258 spin_lock_bh(&adapter->fdir_fltr_lock);
2259 list_for_each_entry_safe(fdir, fdir_tmp,
2260 &adapter->fdir_list_head,
2262 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2263 if (add_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2264 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is added\n",
2266 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2267 fdir->flow_id = add_fltr->flow_id;
2269 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter with status: %d\n",
2271 iavf_print_fdir_fltr(adapter, fdir);
2272 list_del(&fdir->list);
2274 adapter->fdir_active_fltr--;
2278 spin_unlock_bh(&adapter->fdir_fltr_lock);
2281 case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2282 struct virtchnl_fdir_del *del_fltr = (struct virtchnl_fdir_del *)msg;
2283 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2285 spin_lock_bh(&adapter->fdir_fltr_lock);
2286 list_for_each_entry_safe(fdir, fdir_tmp, &adapter->fdir_list_head,
2288 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2289 if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2290 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is deleted\n",
2292 list_del(&fdir->list);
2294 adapter->fdir_active_fltr--;
2296 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2297 dev_info(&adapter->pdev->dev, "Failed to delete Flow Director filter with status: %d\n",
2299 iavf_print_fdir_fltr(adapter, fdir);
2303 spin_unlock_bh(&adapter->fdir_fltr_lock);
2306 case VIRTCHNL_OP_ADD_RSS_CFG: {
2307 struct iavf_adv_rss *rss;
2309 spin_lock_bh(&adapter->adv_rss_lock);
2310 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
2311 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2312 iavf_print_adv_rss_cfg(adapter, rss,
2313 "Input set change for",
2315 rss->state = IAVF_ADV_RSS_ACTIVE;
2318 spin_unlock_bh(&adapter->adv_rss_lock);
2321 case VIRTCHNL_OP_DEL_RSS_CFG: {
2322 struct iavf_adv_rss *rss, *rss_tmp;
2324 spin_lock_bh(&adapter->adv_rss_lock);
2325 list_for_each_entry_safe(rss, rss_tmp,
2326 &adapter->adv_rss_list_head, list) {
2327 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2328 list_del(&rss->list);
2332 spin_unlock_bh(&adapter->adv_rss_lock);
2335 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2336 /* PF enabled vlan strip on this VF.
2337 * Update netdev->features if needed to be in sync with ethtool.
2340 iavf_netdev_features_vlan_strip_set(netdev, true);
2342 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2343 /* PF disabled vlan strip on this VF.
2344 * Update netdev->features if needed to be in sync with ethtool.
2347 iavf_netdev_features_vlan_strip_set(netdev, false);
2350 if (adapter->current_op && (v_opcode != adapter->current_op))
2351 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
2352 adapter->current_op, v_opcode);
2354 } /* switch v_opcode */
2355 adapter->current_op = VIRTCHNL_OP_UNKNOWN;