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 int i, max_frame = adapter->vf_res->max_mtu;
277 int pairs = adapter->num_active_queues;
278 struct virtchnl_queue_pair_info *vqpi;
281 if (max_frame > IAVF_MAX_RXBUFFER || !max_frame)
282 max_frame = IAVF_MAX_RXBUFFER;
284 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
285 /* bail because we already have a command pending */
286 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
287 adapter->current_op);
290 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
291 len = struct_size(vqci, qpair, pairs);
292 vqci = kzalloc(len, GFP_KERNEL);
296 /* Limit maximum frame size when jumbo frames is not enabled */
297 if (!(adapter->flags & IAVF_FLAG_LEGACY_RX) &&
298 (adapter->netdev->mtu <= ETH_DATA_LEN))
299 max_frame = IAVF_RXBUFFER_1536 - NET_IP_ALIGN;
301 vqci->vsi_id = adapter->vsi_res->vsi_id;
302 vqci->num_queue_pairs = pairs;
304 /* Size check is not needed here - HW max is 16 queue pairs, and we
305 * can fit info for 31 of them into the AQ buffer before it overflows.
307 for (i = 0; i < pairs; i++) {
308 vqpi->txq.vsi_id = vqci->vsi_id;
309 vqpi->txq.queue_id = i;
310 vqpi->txq.ring_len = adapter->tx_rings[i].count;
311 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
312 vqpi->rxq.vsi_id = vqci->vsi_id;
313 vqpi->rxq.queue_id = i;
314 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
315 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
316 vqpi->rxq.max_pkt_size = max_frame;
317 vqpi->rxq.databuffer_size =
318 ALIGN(adapter->rx_rings[i].rx_buf_len,
319 BIT_ULL(IAVF_RXQ_CTX_DBUFF_SHIFT));
323 adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES;
324 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
331 * @adapter: adapter structure
333 * Request that the PF enable all of our queues.
335 void iavf_enable_queues(struct iavf_adapter *adapter)
337 struct virtchnl_queue_select vqs;
339 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
340 /* bail because we already have a command pending */
341 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
342 adapter->current_op);
345 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
346 vqs.vsi_id = adapter->vsi_res->vsi_id;
347 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
348 vqs.rx_queues = vqs.tx_queues;
349 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_QUEUES;
350 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
351 (u8 *)&vqs, sizeof(vqs));
355 * iavf_disable_queues
356 * @adapter: adapter structure
358 * Request that the PF disable all of our queues.
360 void iavf_disable_queues(struct iavf_adapter *adapter)
362 struct virtchnl_queue_select vqs;
364 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
365 /* bail because we already have a command pending */
366 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
367 adapter->current_op);
370 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
371 vqs.vsi_id = adapter->vsi_res->vsi_id;
372 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
373 vqs.rx_queues = vqs.tx_queues;
374 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_QUEUES;
375 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
376 (u8 *)&vqs, sizeof(vqs));
381 * @adapter: adapter structure
383 * Request that the PF map queues to interrupt vectors. Misc causes, including
384 * admin queue, are always mapped to vector 0.
386 void iavf_map_queues(struct iavf_adapter *adapter)
388 struct virtchnl_irq_map_info *vimi;
389 struct virtchnl_vector_map *vecmap;
390 struct iavf_q_vector *q_vector;
391 int v_idx, q_vectors;
394 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
395 /* bail because we already have a command pending */
396 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
397 adapter->current_op);
400 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
402 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
404 len = struct_size(vimi, vecmap, adapter->num_msix_vectors);
405 vimi = kzalloc(len, GFP_KERNEL);
409 vimi->num_vectors = adapter->num_msix_vectors;
410 /* Queue vectors first */
411 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
412 q_vector = &adapter->q_vectors[v_idx];
413 vecmap = &vimi->vecmap[v_idx];
415 vecmap->vsi_id = adapter->vsi_res->vsi_id;
416 vecmap->vector_id = v_idx + NONQ_VECS;
417 vecmap->txq_map = q_vector->ring_mask;
418 vecmap->rxq_map = q_vector->ring_mask;
419 vecmap->rxitr_idx = IAVF_RX_ITR;
420 vecmap->txitr_idx = IAVF_TX_ITR;
422 /* Misc vector last - this is only for AdminQ messages */
423 vecmap = &vimi->vecmap[v_idx];
424 vecmap->vsi_id = adapter->vsi_res->vsi_id;
425 vecmap->vector_id = 0;
429 adapter->aq_required &= ~IAVF_FLAG_AQ_MAP_VECTORS;
430 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
436 * iavf_set_mac_addr_type - Set the correct request type from the filter type
437 * @virtchnl_ether_addr: pointer to requested list element
438 * @filter: pointer to requested filter
441 iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr,
442 const struct iavf_mac_filter *filter)
444 virtchnl_ether_addr->type = filter->is_primary ?
445 VIRTCHNL_ETHER_ADDR_PRIMARY :
446 VIRTCHNL_ETHER_ADDR_EXTRA;
450 * iavf_add_ether_addrs
451 * @adapter: adapter structure
453 * Request that the PF add one or more addresses to our filters.
455 void iavf_add_ether_addrs(struct iavf_adapter *adapter)
457 struct virtchnl_ether_addr_list *veal;
458 struct iavf_mac_filter *f;
459 int i = 0, count = 0;
463 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
464 /* bail because we already have a command pending */
465 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
466 adapter->current_op);
470 spin_lock_bh(&adapter->mac_vlan_list_lock);
472 list_for_each_entry(f, &adapter->mac_filter_list, list) {
477 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
478 spin_unlock_bh(&adapter->mac_vlan_list_lock);
481 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
483 len = struct_size(veal, list, count);
484 if (len > IAVF_MAX_AQ_BUF_SIZE) {
485 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
486 count = (IAVF_MAX_AQ_BUF_SIZE -
487 sizeof(struct virtchnl_ether_addr_list)) /
488 sizeof(struct virtchnl_ether_addr);
489 len = struct_size(veal, list, count);
493 veal = kzalloc(len, GFP_ATOMIC);
495 spin_unlock_bh(&adapter->mac_vlan_list_lock);
499 veal->vsi_id = adapter->vsi_res->vsi_id;
500 veal->num_elements = count;
501 list_for_each_entry(f, &adapter->mac_filter_list, list) {
503 ether_addr_copy(veal->list[i].addr, f->macaddr);
504 iavf_set_mac_addr_type(&veal->list[i], f);
512 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
514 spin_unlock_bh(&adapter->mac_vlan_list_lock);
516 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len);
521 * iavf_del_ether_addrs
522 * @adapter: adapter structure
524 * Request that the PF remove one or more addresses from our filters.
526 void iavf_del_ether_addrs(struct iavf_adapter *adapter)
528 struct virtchnl_ether_addr_list *veal;
529 struct iavf_mac_filter *f, *ftmp;
530 int i = 0, count = 0;
534 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
535 /* bail because we already have a command pending */
536 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
537 adapter->current_op);
541 spin_lock_bh(&adapter->mac_vlan_list_lock);
543 list_for_each_entry(f, &adapter->mac_filter_list, list) {
548 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
549 spin_unlock_bh(&adapter->mac_vlan_list_lock);
552 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
554 len = struct_size(veal, list, count);
555 if (len > IAVF_MAX_AQ_BUF_SIZE) {
556 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
557 count = (IAVF_MAX_AQ_BUF_SIZE -
558 sizeof(struct virtchnl_ether_addr_list)) /
559 sizeof(struct virtchnl_ether_addr);
560 len = struct_size(veal, list, count);
563 veal = kzalloc(len, GFP_ATOMIC);
565 spin_unlock_bh(&adapter->mac_vlan_list_lock);
569 veal->vsi_id = adapter->vsi_res->vsi_id;
570 veal->num_elements = count;
571 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
573 ether_addr_copy(veal->list[i].addr, f->macaddr);
574 iavf_set_mac_addr_type(&veal->list[i], f);
583 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
585 spin_unlock_bh(&adapter->mac_vlan_list_lock);
587 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, (u8 *)veal, len);
593 * @adapter: adapter structure
595 * Submit list of filters based on PF response.
597 static void iavf_mac_add_ok(struct iavf_adapter *adapter)
599 struct iavf_mac_filter *f, *ftmp;
601 spin_lock_bh(&adapter->mac_vlan_list_lock);
602 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
603 f->is_new_mac = false;
605 spin_unlock_bh(&adapter->mac_vlan_list_lock);
609 * iavf_mac_add_reject
610 * @adapter: adapter structure
612 * Remove filters from list based on PF response.
614 static void iavf_mac_add_reject(struct iavf_adapter *adapter)
616 struct net_device *netdev = adapter->netdev;
617 struct iavf_mac_filter *f, *ftmp;
619 spin_lock_bh(&adapter->mac_vlan_list_lock);
620 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
621 if (f->remove && ether_addr_equal(f->macaddr, netdev->dev_addr))
629 spin_unlock_bh(&adapter->mac_vlan_list_lock);
633 * iavf_vlan_add_reject
634 * @adapter: adapter structure
636 * Remove VLAN filters from list based on PF response.
638 static void iavf_vlan_add_reject(struct iavf_adapter *adapter)
640 struct iavf_vlan_filter *f, *ftmp;
642 spin_lock_bh(&adapter->mac_vlan_list_lock);
643 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
644 if (f->is_new_vlan) {
645 if (f->vlan.tpid == ETH_P_8021Q)
646 clear_bit(f->vlan.vid,
647 adapter->vsi.active_cvlans);
649 clear_bit(f->vlan.vid,
650 adapter->vsi.active_svlans);
656 spin_unlock_bh(&adapter->mac_vlan_list_lock);
661 * @adapter: adapter structure
663 * Request that the PF add one or more VLAN filters to our VSI.
665 void iavf_add_vlans(struct iavf_adapter *adapter)
667 int len, i = 0, count = 0;
668 struct iavf_vlan_filter *f;
671 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
672 /* bail because we already have a command pending */
673 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
674 adapter->current_op);
678 spin_lock_bh(&adapter->mac_vlan_list_lock);
680 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
684 if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
685 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
686 spin_unlock_bh(&adapter->mac_vlan_list_lock);
690 if (VLAN_ALLOWED(adapter)) {
691 struct virtchnl_vlan_filter_list *vvfl;
693 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
695 len = sizeof(*vvfl) + (count * sizeof(u16));
696 if (len > IAVF_MAX_AQ_BUF_SIZE) {
697 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
698 count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl)) /
700 len = sizeof(*vvfl) + (count * sizeof(u16));
703 vvfl = kzalloc(len, GFP_ATOMIC);
705 spin_unlock_bh(&adapter->mac_vlan_list_lock);
709 vvfl->vsi_id = adapter->vsi_res->vsi_id;
710 vvfl->num_elements = count;
711 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
713 vvfl->vlan_id[i] = f->vlan.vid;
716 f->is_new_vlan = true;
722 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
724 spin_unlock_bh(&adapter->mac_vlan_list_lock);
726 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
729 u16 max_vlans = adapter->vlan_v2_caps.filtering.max_filters;
730 u16 current_vlans = iavf_get_num_vlans_added(adapter);
731 struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
733 adapter->current_op = VIRTCHNL_OP_ADD_VLAN_V2;
735 if ((count + current_vlans) > max_vlans &&
736 current_vlans < max_vlans) {
737 count = max_vlans - iavf_get_num_vlans_added(adapter);
741 len = sizeof(*vvfl_v2) + ((count - 1) *
742 sizeof(struct virtchnl_vlan_filter));
743 if (len > IAVF_MAX_AQ_BUF_SIZE) {
744 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
745 count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl_v2)) /
746 sizeof(struct virtchnl_vlan_filter);
747 len = sizeof(*vvfl_v2) +
749 sizeof(struct virtchnl_vlan_filter));
753 vvfl_v2 = kzalloc(len, GFP_ATOMIC);
755 spin_unlock_bh(&adapter->mac_vlan_list_lock);
759 vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
760 vvfl_v2->num_elements = count;
761 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
763 struct virtchnl_vlan_supported_caps *filtering_support =
764 &adapter->vlan_v2_caps.filtering.filtering_support;
765 struct virtchnl_vlan *vlan;
770 /* give priority over outer if it's enabled */
771 if (filtering_support->outer)
772 vlan = &vvfl_v2->filters[i].outer;
774 vlan = &vvfl_v2->filters[i].inner;
776 vlan->tci = f->vlan.vid;
777 vlan->tpid = f->vlan.tpid;
781 f->is_new_vlan = true;
786 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
788 spin_unlock_bh(&adapter->mac_vlan_list_lock);
790 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN_V2,
798 * @adapter: adapter structure
800 * Request that the PF remove one or more VLAN filters from our VSI.
802 void iavf_del_vlans(struct iavf_adapter *adapter)
804 struct iavf_vlan_filter *f, *ftmp;
805 int len, i = 0, count = 0;
808 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
809 /* bail because we already have a command pending */
810 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
811 adapter->current_op);
815 spin_lock_bh(&adapter->mac_vlan_list_lock);
817 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
818 /* since VLAN capabilities are not allowed, we dont want to send
819 * a VLAN delete request because it will most likely fail and
820 * create unnecessary errors/noise, so just free the VLAN
821 * filters marked for removal to enable bailing out before
822 * sending a virtchnl message
824 if (f->remove && !VLAN_FILTERING_ALLOWED(adapter)) {
827 } else if (f->remove) {
831 if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
832 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
833 spin_unlock_bh(&adapter->mac_vlan_list_lock);
837 if (VLAN_ALLOWED(adapter)) {
838 struct virtchnl_vlan_filter_list *vvfl;
840 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
842 len = sizeof(*vvfl) + (count * sizeof(u16));
843 if (len > IAVF_MAX_AQ_BUF_SIZE) {
844 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
845 count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl)) /
847 len = sizeof(*vvfl) + (count * sizeof(u16));
850 vvfl = kzalloc(len, GFP_ATOMIC);
852 spin_unlock_bh(&adapter->mac_vlan_list_lock);
856 vvfl->vsi_id = adapter->vsi_res->vsi_id;
857 vvfl->num_elements = count;
858 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
860 vvfl->vlan_id[i] = f->vlan.vid;
870 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
872 spin_unlock_bh(&adapter->mac_vlan_list_lock);
874 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
877 struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
879 adapter->current_op = VIRTCHNL_OP_DEL_VLAN_V2;
881 len = sizeof(*vvfl_v2) +
882 ((count - 1) * sizeof(struct virtchnl_vlan_filter));
883 if (len > IAVF_MAX_AQ_BUF_SIZE) {
884 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
885 count = (IAVF_MAX_AQ_BUF_SIZE -
887 sizeof(struct virtchnl_vlan_filter);
888 len = sizeof(*vvfl_v2) +
890 sizeof(struct virtchnl_vlan_filter));
894 vvfl_v2 = kzalloc(len, GFP_ATOMIC);
896 spin_unlock_bh(&adapter->mac_vlan_list_lock);
900 vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
901 vvfl_v2->num_elements = count;
902 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
904 struct virtchnl_vlan_supported_caps *filtering_support =
905 &adapter->vlan_v2_caps.filtering.filtering_support;
906 struct virtchnl_vlan *vlan;
908 /* give priority over outer if it's enabled */
909 if (filtering_support->outer)
910 vlan = &vvfl_v2->filters[i].outer;
912 vlan = &vvfl_v2->filters[i].inner;
914 vlan->tci = f->vlan.vid;
915 vlan->tpid = f->vlan.tpid;
926 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
928 spin_unlock_bh(&adapter->mac_vlan_list_lock);
930 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN_V2,
937 * iavf_set_promiscuous
938 * @adapter: adapter structure
939 * @flags: bitmask to control unicast/multicast promiscuous.
941 * Request that the PF enable promiscuous mode for our VSI.
943 void iavf_set_promiscuous(struct iavf_adapter *adapter, int flags)
945 struct virtchnl_promisc_info vpi;
948 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
949 /* bail because we already have a command pending */
950 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
951 adapter->current_op);
955 promisc_all = FLAG_VF_UNICAST_PROMISC |
956 FLAG_VF_MULTICAST_PROMISC;
957 if ((flags & promisc_all) == promisc_all) {
958 adapter->flags |= IAVF_FLAG_PROMISC_ON;
959 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_PROMISC;
960 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
963 if (flags & FLAG_VF_MULTICAST_PROMISC) {
964 adapter->flags |= IAVF_FLAG_ALLMULTI_ON;
965 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_ALLMULTI;
966 dev_info(&adapter->pdev->dev, "%s is entering multicast promiscuous mode\n",
967 adapter->netdev->name);
971 if (adapter->flags & IAVF_FLAG_PROMISC_ON) {
972 adapter->flags &= ~IAVF_FLAG_PROMISC_ON;
973 adapter->aq_required &= ~IAVF_FLAG_AQ_RELEASE_PROMISC;
974 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
977 if (adapter->flags & IAVF_FLAG_ALLMULTI_ON) {
978 adapter->flags &= ~IAVF_FLAG_ALLMULTI_ON;
979 adapter->aq_required &= ~IAVF_FLAG_AQ_RELEASE_ALLMULTI;
980 dev_info(&adapter->pdev->dev, "%s is leaving multicast promiscuous mode\n",
981 adapter->netdev->name);
985 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
986 vpi.vsi_id = adapter->vsi_res->vsi_id;
988 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
989 (u8 *)&vpi, sizeof(vpi));
994 * @adapter: adapter structure
996 * Request VSI statistics from PF.
998 void iavf_request_stats(struct iavf_adapter *adapter)
1000 struct virtchnl_queue_select vqs;
1002 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1003 /* no error message, this isn't crucial */
1007 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_STATS;
1008 adapter->current_op = VIRTCHNL_OP_GET_STATS;
1009 vqs.vsi_id = adapter->vsi_res->vsi_id;
1010 /* queue maps are ignored for this message - only the vsi is used */
1011 if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs,
1013 /* if the request failed, don't lock out others */
1014 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1019 * @adapter: adapter structure
1021 * Request hash enable capabilities from PF
1023 void iavf_get_hena(struct iavf_adapter *adapter)
1025 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1026 /* bail because we already have a command pending */
1027 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
1028 adapter->current_op);
1031 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
1032 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA;
1033 iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0);
1038 * @adapter: adapter structure
1040 * Request the PF to set our RSS hash capabilities
1042 void iavf_set_hena(struct iavf_adapter *adapter)
1044 struct virtchnl_rss_hena vrh;
1046 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1047 /* bail because we already have a command pending */
1048 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
1049 adapter->current_op);
1052 vrh.hena = adapter->hena;
1053 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
1054 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA;
1055 iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh,
1061 * @adapter: adapter structure
1063 * Request the PF to set our RSS hash key
1065 void iavf_set_rss_key(struct iavf_adapter *adapter)
1067 struct virtchnl_rss_key *vrk;
1070 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1071 /* bail because we already have a command pending */
1072 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
1073 adapter->current_op);
1076 len = sizeof(struct virtchnl_rss_key) +
1077 (adapter->rss_key_size * sizeof(u8)) - 1;
1078 vrk = kzalloc(len, GFP_KERNEL);
1081 vrk->vsi_id = adapter->vsi.id;
1082 vrk->key_len = adapter->rss_key_size;
1083 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
1085 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
1086 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY;
1087 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len);
1093 * @adapter: adapter structure
1095 * Request the PF to set our RSS lookup table
1097 void iavf_set_rss_lut(struct iavf_adapter *adapter)
1099 struct virtchnl_rss_lut *vrl;
1102 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1103 /* bail because we already have a command pending */
1104 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
1105 adapter->current_op);
1108 len = sizeof(struct virtchnl_rss_lut) +
1109 (adapter->rss_lut_size * sizeof(u8)) - 1;
1110 vrl = kzalloc(len, GFP_KERNEL);
1113 vrl->vsi_id = adapter->vsi.id;
1114 vrl->lut_entries = adapter->rss_lut_size;
1115 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
1116 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
1117 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT;
1118 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len);
1123 * iavf_enable_vlan_stripping
1124 * @adapter: adapter structure
1126 * Request VLAN header stripping to be enabled
1128 void iavf_enable_vlan_stripping(struct iavf_adapter *adapter)
1130 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1131 /* bail because we already have a command pending */
1132 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
1133 adapter->current_op);
1136 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
1137 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
1138 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0);
1142 * iavf_disable_vlan_stripping
1143 * @adapter: adapter structure
1145 * Request VLAN header stripping to be disabled
1147 void iavf_disable_vlan_stripping(struct iavf_adapter *adapter)
1149 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1150 /* bail because we already have a command pending */
1151 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
1152 adapter->current_op);
1155 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
1156 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
1157 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0);
1161 * iavf_tpid_to_vc_ethertype - transform from VLAN TPID to virtchnl ethertype
1162 * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1164 static u32 iavf_tpid_to_vc_ethertype(u16 tpid)
1168 return VIRTCHNL_VLAN_ETHERTYPE_8100;
1170 return VIRTCHNL_VLAN_ETHERTYPE_88A8;
1177 * iavf_set_vc_offload_ethertype - set virtchnl ethertype for offload message
1178 * @adapter: adapter structure
1179 * @msg: message structure used for updating offloads over virtchnl to update
1180 * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1181 * @offload_op: opcode used to determine which support structure to check
1184 iavf_set_vc_offload_ethertype(struct iavf_adapter *adapter,
1185 struct virtchnl_vlan_setting *msg, u16 tpid,
1186 enum virtchnl_ops offload_op)
1188 struct virtchnl_vlan_supported_caps *offload_support;
1189 u16 vc_ethertype = iavf_tpid_to_vc_ethertype(tpid);
1191 /* reference the correct offload support structure */
1192 switch (offload_op) {
1193 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1194 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1196 &adapter->vlan_v2_caps.offloads.stripping_support;
1198 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1199 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1201 &adapter->vlan_v2_caps.offloads.insertion_support;
1204 dev_err(&adapter->pdev->dev, "Invalid opcode %d for setting virtchnl ethertype to enable/disable VLAN offloads\n",
1209 /* make sure ethertype is supported */
1210 if (offload_support->outer & vc_ethertype &&
1211 offload_support->outer & VIRTCHNL_VLAN_TOGGLE) {
1212 msg->outer_ethertype_setting = vc_ethertype;
1213 } else if (offload_support->inner & vc_ethertype &&
1214 offload_support->inner & VIRTCHNL_VLAN_TOGGLE) {
1215 msg->inner_ethertype_setting = vc_ethertype;
1217 dev_dbg(&adapter->pdev->dev, "opcode %d unsupported for VLAN TPID 0x%04x\n",
1226 * iavf_clear_offload_v2_aq_required - clear AQ required bit for offload request
1227 * @adapter: adapter structure
1229 * @offload_op: opcode used to determine which AQ required bit to clear
1232 iavf_clear_offload_v2_aq_required(struct iavf_adapter *adapter, u16 tpid,
1233 enum virtchnl_ops offload_op)
1235 switch (offload_op) {
1236 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1237 if (tpid == ETH_P_8021Q)
1238 adapter->aq_required &=
1239 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_STRIPPING;
1240 else if (tpid == ETH_P_8021AD)
1241 adapter->aq_required &=
1242 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_STRIPPING;
1244 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1245 if (tpid == ETH_P_8021Q)
1246 adapter->aq_required &=
1247 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_STRIPPING;
1248 else if (tpid == ETH_P_8021AD)
1249 adapter->aq_required &=
1250 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_STRIPPING;
1252 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1253 if (tpid == ETH_P_8021Q)
1254 adapter->aq_required &=
1255 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_INSERTION;
1256 else if (tpid == ETH_P_8021AD)
1257 adapter->aq_required &=
1258 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_INSERTION;
1260 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1261 if (tpid == ETH_P_8021Q)
1262 adapter->aq_required &=
1263 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_INSERTION;
1264 else if (tpid == ETH_P_8021AD)
1265 adapter->aq_required &=
1266 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_INSERTION;
1269 dev_err(&adapter->pdev->dev, "Unsupported opcode %d specified for clearing aq_required bits for VIRTCHNL_VF_OFFLOAD_VLAN_V2 offload request\n",
1275 * iavf_send_vlan_offload_v2 - send offload enable/disable over virtchnl
1276 * @adapter: adapter structure
1277 * @tpid: VLAN TPID used for the command (i.e. 0x8100 or 0x88a8)
1278 * @offload_op: offload_op used to make the request over virtchnl
1281 iavf_send_vlan_offload_v2(struct iavf_adapter *adapter, u16 tpid,
1282 enum virtchnl_ops offload_op)
1284 struct virtchnl_vlan_setting *msg;
1285 int len = sizeof(*msg);
1287 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1288 /* bail because we already have a command pending */
1289 dev_err(&adapter->pdev->dev, "Cannot send %d, command %d pending\n",
1290 offload_op, adapter->current_op);
1294 adapter->current_op = offload_op;
1296 msg = kzalloc(len, GFP_KERNEL);
1300 msg->vport_id = adapter->vsi_res->vsi_id;
1302 /* always clear to prevent unsupported and endless requests */
1303 iavf_clear_offload_v2_aq_required(adapter, tpid, offload_op);
1305 /* only send valid offload requests */
1306 if (!iavf_set_vc_offload_ethertype(adapter, msg, tpid, offload_op))
1307 iavf_send_pf_msg(adapter, offload_op, (u8 *)msg, len);
1309 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1315 * iavf_enable_vlan_stripping_v2 - enable VLAN stripping
1316 * @adapter: adapter structure
1317 * @tpid: VLAN TPID used to enable VLAN stripping
1319 void iavf_enable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1321 iavf_send_vlan_offload_v2(adapter, tpid,
1322 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2);
1326 * iavf_disable_vlan_stripping_v2 - disable VLAN stripping
1327 * @adapter: adapter structure
1328 * @tpid: VLAN TPID used to disable VLAN stripping
1330 void iavf_disable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1332 iavf_send_vlan_offload_v2(adapter, tpid,
1333 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2);
1337 * iavf_enable_vlan_insertion_v2 - enable VLAN insertion
1338 * @adapter: adapter structure
1339 * @tpid: VLAN TPID used to enable VLAN insertion
1341 void iavf_enable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1343 iavf_send_vlan_offload_v2(adapter, tpid,
1344 VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2);
1348 * iavf_disable_vlan_insertion_v2 - disable VLAN insertion
1349 * @adapter: adapter structure
1350 * @tpid: VLAN TPID used to disable VLAN insertion
1352 void iavf_disable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1354 iavf_send_vlan_offload_v2(adapter, tpid,
1355 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2);
1358 #define IAVF_MAX_SPEED_STRLEN 13
1361 * iavf_print_link_message - print link up or down
1362 * @adapter: adapter structure
1364 * Log a message telling the world of our wonderous link status
1366 static void iavf_print_link_message(struct iavf_adapter *adapter)
1368 struct net_device *netdev = adapter->netdev;
1369 int link_speed_mbps;
1372 if (!adapter->link_up) {
1373 netdev_info(netdev, "NIC Link is Down\n");
1377 speed = kzalloc(IAVF_MAX_SPEED_STRLEN, GFP_KERNEL);
1381 if (ADV_LINK_SUPPORT(adapter)) {
1382 link_speed_mbps = adapter->link_speed_mbps;
1383 goto print_link_msg;
1386 switch (adapter->link_speed) {
1387 case VIRTCHNL_LINK_SPEED_40GB:
1388 link_speed_mbps = SPEED_40000;
1390 case VIRTCHNL_LINK_SPEED_25GB:
1391 link_speed_mbps = SPEED_25000;
1393 case VIRTCHNL_LINK_SPEED_20GB:
1394 link_speed_mbps = SPEED_20000;
1396 case VIRTCHNL_LINK_SPEED_10GB:
1397 link_speed_mbps = SPEED_10000;
1399 case VIRTCHNL_LINK_SPEED_5GB:
1400 link_speed_mbps = SPEED_5000;
1402 case VIRTCHNL_LINK_SPEED_2_5GB:
1403 link_speed_mbps = SPEED_2500;
1405 case VIRTCHNL_LINK_SPEED_1GB:
1406 link_speed_mbps = SPEED_1000;
1408 case VIRTCHNL_LINK_SPEED_100MB:
1409 link_speed_mbps = SPEED_100;
1412 link_speed_mbps = SPEED_UNKNOWN;
1417 if (link_speed_mbps > SPEED_1000) {
1418 if (link_speed_mbps == SPEED_2500)
1419 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "2.5 Gbps");
1421 /* convert to Gbps inline */
1422 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1423 link_speed_mbps / 1000, "Gbps");
1424 } else if (link_speed_mbps == SPEED_UNKNOWN) {
1425 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%s", "Unknown Mbps");
1427 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1428 link_speed_mbps, "Mbps");
1431 netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed);
1436 * iavf_get_vpe_link_status
1437 * @adapter: adapter structure
1438 * @vpe: virtchnl_pf_event structure
1440 * Helper function for determining the link status
1443 iavf_get_vpe_link_status(struct iavf_adapter *adapter,
1444 struct virtchnl_pf_event *vpe)
1446 if (ADV_LINK_SUPPORT(adapter))
1447 return vpe->event_data.link_event_adv.link_status;
1449 return vpe->event_data.link_event.link_status;
1453 * iavf_set_adapter_link_speed_from_vpe
1454 * @adapter: adapter structure for which we are setting the link speed
1455 * @vpe: virtchnl_pf_event structure that contains the link speed we are setting
1457 * Helper function for setting iavf_adapter link speed
1460 iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter *adapter,
1461 struct virtchnl_pf_event *vpe)
1463 if (ADV_LINK_SUPPORT(adapter))
1464 adapter->link_speed_mbps =
1465 vpe->event_data.link_event_adv.link_speed;
1467 adapter->link_speed = vpe->event_data.link_event.link_speed;
1471 * iavf_enable_channels
1472 * @adapter: adapter structure
1474 * Request that the PF enable channels as specified by
1475 * the user via tc tool.
1477 void iavf_enable_channels(struct iavf_adapter *adapter)
1479 struct virtchnl_tc_info *vti = NULL;
1483 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1484 /* bail because we already have a command pending */
1485 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1486 adapter->current_op);
1490 len = struct_size(vti, list, adapter->num_tc - 1);
1491 vti = kzalloc(len, GFP_KERNEL);
1494 vti->num_tc = adapter->num_tc;
1495 for (i = 0; i < vti->num_tc; i++) {
1496 vti->list[i].count = adapter->ch_config.ch_info[i].count;
1497 vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
1498 vti->list[i].pad = 0;
1499 vti->list[i].max_tx_rate =
1500 adapter->ch_config.ch_info[i].max_tx_rate;
1503 adapter->ch_config.state = __IAVF_TC_RUNNING;
1504 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1505 adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
1506 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS;
1507 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len);
1512 * iavf_disable_channels
1513 * @adapter: adapter structure
1515 * Request that the PF disable channels that are configured
1517 void iavf_disable_channels(struct iavf_adapter *adapter)
1519 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1520 /* bail because we already have a command pending */
1521 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1522 adapter->current_op);
1526 adapter->ch_config.state = __IAVF_TC_INVALID;
1527 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1528 adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
1529 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS;
1530 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0);
1534 * iavf_print_cloud_filter
1535 * @adapter: adapter structure
1536 * @f: cloud filter to print
1538 * Print the cloud filter
1540 static void iavf_print_cloud_filter(struct iavf_adapter *adapter,
1541 struct virtchnl_filter *f)
1543 switch (f->flow_type) {
1544 case VIRTCHNL_TCP_V4_FLOW:
1545 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",
1546 &f->data.tcp_spec.dst_mac,
1547 &f->data.tcp_spec.src_mac,
1548 ntohs(f->data.tcp_spec.vlan_id),
1549 &f->data.tcp_spec.dst_ip[0],
1550 &f->data.tcp_spec.src_ip[0],
1551 ntohs(f->data.tcp_spec.dst_port),
1552 ntohs(f->data.tcp_spec.src_port));
1554 case VIRTCHNL_TCP_V6_FLOW:
1555 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",
1556 &f->data.tcp_spec.dst_mac,
1557 &f->data.tcp_spec.src_mac,
1558 ntohs(f->data.tcp_spec.vlan_id),
1559 &f->data.tcp_spec.dst_ip,
1560 &f->data.tcp_spec.src_ip,
1561 ntohs(f->data.tcp_spec.dst_port),
1562 ntohs(f->data.tcp_spec.src_port));
1568 * iavf_add_cloud_filter
1569 * @adapter: adapter structure
1571 * Request that the PF add cloud filters as specified
1572 * by the user via tc tool.
1574 void iavf_add_cloud_filter(struct iavf_adapter *adapter)
1576 struct iavf_cloud_filter *cf;
1577 struct virtchnl_filter *f;
1578 int len = 0, count = 0;
1580 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1581 /* bail because we already have a command pending */
1582 dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1583 adapter->current_op);
1586 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1593 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER;
1596 adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1598 len = sizeof(struct virtchnl_filter);
1599 f = kzalloc(len, GFP_KERNEL);
1603 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1605 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1607 cf->state = __IAVF_CF_ADD_PENDING;
1608 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER,
1616 * iavf_del_cloud_filter
1617 * @adapter: adapter structure
1619 * Request that the PF delete cloud filters as specified
1620 * by the user via tc tool.
1622 void iavf_del_cloud_filter(struct iavf_adapter *adapter)
1624 struct iavf_cloud_filter *cf, *cftmp;
1625 struct virtchnl_filter *f;
1626 int len = 0, count = 0;
1628 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1629 /* bail because we already have a command pending */
1630 dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1631 adapter->current_op);
1634 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1641 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER;
1644 adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1646 len = sizeof(struct virtchnl_filter);
1647 f = kzalloc(len, GFP_KERNEL);
1651 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1653 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1655 cf->state = __IAVF_CF_DEL_PENDING;
1656 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER,
1664 * iavf_add_fdir_filter
1665 * @adapter: the VF adapter structure
1667 * Request that the PF add Flow Director filters as specified
1668 * by the user via ethtool.
1670 void iavf_add_fdir_filter(struct iavf_adapter *adapter)
1672 struct iavf_fdir_fltr *fdir;
1673 struct virtchnl_fdir_add *f;
1674 bool process_fltr = false;
1677 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1678 /* bail because we already have a command pending */
1679 dev_err(&adapter->pdev->dev, "Cannot add Flow Director filter, command %d pending\n",
1680 adapter->current_op);
1684 len = sizeof(struct virtchnl_fdir_add);
1685 f = kzalloc(len, GFP_KERNEL);
1689 spin_lock_bh(&adapter->fdir_fltr_lock);
1690 list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1691 if (fdir->state == IAVF_FDIR_FLTR_ADD_REQUEST) {
1692 process_fltr = true;
1693 fdir->state = IAVF_FDIR_FLTR_ADD_PENDING;
1694 memcpy(f, &fdir->vc_add_msg, len);
1698 spin_unlock_bh(&adapter->fdir_fltr_lock);
1700 if (!process_fltr) {
1701 /* prevent iavf_add_fdir_filter() from being called when there
1702 * are no filters to add
1704 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_FDIR_FILTER;
1708 adapter->current_op = VIRTCHNL_OP_ADD_FDIR_FILTER;
1709 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_FDIR_FILTER, (u8 *)f, len);
1714 * iavf_del_fdir_filter
1715 * @adapter: the VF adapter structure
1717 * Request that the PF delete Flow Director filters as specified
1718 * by the user via ethtool.
1720 void iavf_del_fdir_filter(struct iavf_adapter *adapter)
1722 struct iavf_fdir_fltr *fdir;
1723 struct virtchnl_fdir_del f;
1724 bool process_fltr = false;
1727 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1728 /* bail because we already have a command pending */
1729 dev_err(&adapter->pdev->dev, "Cannot remove Flow Director filter, command %d pending\n",
1730 adapter->current_op);
1734 len = sizeof(struct virtchnl_fdir_del);
1736 spin_lock_bh(&adapter->fdir_fltr_lock);
1737 list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1738 if (fdir->state == IAVF_FDIR_FLTR_DEL_REQUEST) {
1739 process_fltr = true;
1741 f.vsi_id = fdir->vc_add_msg.vsi_id;
1742 f.flow_id = fdir->flow_id;
1743 fdir->state = IAVF_FDIR_FLTR_DEL_PENDING;
1747 spin_unlock_bh(&adapter->fdir_fltr_lock);
1749 if (!process_fltr) {
1750 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_FDIR_FILTER;
1754 adapter->current_op = VIRTCHNL_OP_DEL_FDIR_FILTER;
1755 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_FDIR_FILTER, (u8 *)&f, len);
1759 * iavf_add_adv_rss_cfg
1760 * @adapter: the VF adapter structure
1762 * Request that the PF add RSS configuration as specified
1763 * by the user via ethtool.
1765 void iavf_add_adv_rss_cfg(struct iavf_adapter *adapter)
1767 struct virtchnl_rss_cfg *rss_cfg;
1768 struct iavf_adv_rss *rss;
1769 bool process_rss = false;
1772 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1773 /* bail because we already have a command pending */
1774 dev_err(&adapter->pdev->dev, "Cannot add RSS configuration, command %d pending\n",
1775 adapter->current_op);
1779 len = sizeof(struct virtchnl_rss_cfg);
1780 rss_cfg = kzalloc(len, GFP_KERNEL);
1784 spin_lock_bh(&adapter->adv_rss_lock);
1785 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1786 if (rss->state == IAVF_ADV_RSS_ADD_REQUEST) {
1788 rss->state = IAVF_ADV_RSS_ADD_PENDING;
1789 memcpy(rss_cfg, &rss->cfg_msg, len);
1790 iavf_print_adv_rss_cfg(adapter, rss,
1791 "Input set change for",
1796 spin_unlock_bh(&adapter->adv_rss_lock);
1799 adapter->current_op = VIRTCHNL_OP_ADD_RSS_CFG;
1800 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_RSS_CFG,
1801 (u8 *)rss_cfg, len);
1803 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_ADV_RSS_CFG;
1810 * iavf_del_adv_rss_cfg
1811 * @adapter: the VF adapter structure
1813 * Request that the PF delete RSS configuration as specified
1814 * by the user via ethtool.
1816 void iavf_del_adv_rss_cfg(struct iavf_adapter *adapter)
1818 struct virtchnl_rss_cfg *rss_cfg;
1819 struct iavf_adv_rss *rss;
1820 bool process_rss = false;
1823 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1824 /* bail because we already have a command pending */
1825 dev_err(&adapter->pdev->dev, "Cannot remove RSS configuration, command %d pending\n",
1826 adapter->current_op);
1830 len = sizeof(struct virtchnl_rss_cfg);
1831 rss_cfg = kzalloc(len, GFP_KERNEL);
1835 spin_lock_bh(&adapter->adv_rss_lock);
1836 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1837 if (rss->state == IAVF_ADV_RSS_DEL_REQUEST) {
1839 rss->state = IAVF_ADV_RSS_DEL_PENDING;
1840 memcpy(rss_cfg, &rss->cfg_msg, len);
1844 spin_unlock_bh(&adapter->adv_rss_lock);
1847 adapter->current_op = VIRTCHNL_OP_DEL_RSS_CFG;
1848 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_RSS_CFG,
1849 (u8 *)rss_cfg, len);
1851 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_ADV_RSS_CFG;
1858 * iavf_request_reset
1859 * @adapter: adapter structure
1861 * Request that the PF reset this VF. No response is expected.
1863 int iavf_request_reset(struct iavf_adapter *adapter)
1866 /* Don't check CURRENT_OP - this is always higher priority */
1867 err = iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
1868 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1873 * iavf_netdev_features_vlan_strip_set - update vlan strip status
1874 * @netdev: ptr to netdev being adjusted
1875 * @enable: enable or disable vlan strip
1877 * Helper function to change vlan strip status in netdev->features.
1879 static void iavf_netdev_features_vlan_strip_set(struct net_device *netdev,
1883 netdev->features |= NETIF_F_HW_VLAN_CTAG_RX;
1885 netdev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
1889 * iavf_virtchnl_completion
1890 * @adapter: adapter structure
1891 * @v_opcode: opcode sent by PF
1892 * @v_retval: retval sent by PF
1893 * @msg: message sent by PF
1894 * @msglen: message length
1896 * Asynchronous completion function for admin queue messages. Rather than busy
1897 * wait, we fire off our requests and assume that no errors will be returned.
1898 * This function handles the reply messages.
1900 void iavf_virtchnl_completion(struct iavf_adapter *adapter,
1901 enum virtchnl_ops v_opcode,
1902 enum iavf_status v_retval, u8 *msg, u16 msglen)
1904 struct net_device *netdev = adapter->netdev;
1906 if (v_opcode == VIRTCHNL_OP_EVENT) {
1907 struct virtchnl_pf_event *vpe =
1908 (struct virtchnl_pf_event *)msg;
1909 bool link_up = iavf_get_vpe_link_status(adapter, vpe);
1911 switch (vpe->event) {
1912 case VIRTCHNL_EVENT_LINK_CHANGE:
1913 iavf_set_adapter_link_speed_from_vpe(adapter, vpe);
1915 /* we've already got the right link status, bail */
1916 if (adapter->link_up == link_up)
1920 /* If we get link up message and start queues
1921 * before our queues are configured it will
1922 * trigger a TX hang. In that case, just ignore
1923 * the link status message,we'll get another one
1924 * after we enable queues and actually prepared
1927 if (adapter->state != __IAVF_RUNNING)
1930 /* For ADq enabled VF, we reconfigure VSIs and
1931 * re-allocate queues. Hence wait till all
1932 * queues are enabled.
1934 if (adapter->flags &
1935 IAVF_FLAG_QUEUES_DISABLED)
1939 adapter->link_up = link_up;
1941 netif_tx_start_all_queues(netdev);
1942 netif_carrier_on(netdev);
1944 netif_tx_stop_all_queues(netdev);
1945 netif_carrier_off(netdev);
1947 iavf_print_link_message(adapter);
1949 case VIRTCHNL_EVENT_RESET_IMPENDING:
1950 dev_info(&adapter->pdev->dev, "Reset indication received from the PF\n");
1951 if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) {
1952 adapter->flags |= IAVF_FLAG_RESET_PENDING;
1953 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
1954 queue_work(iavf_wq, &adapter->reset_task);
1958 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
1966 case VIRTCHNL_OP_ADD_VLAN:
1967 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
1968 iavf_stat_str(&adapter->hw, v_retval));
1970 case VIRTCHNL_OP_ADD_ETH_ADDR:
1971 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
1972 iavf_stat_str(&adapter->hw, v_retval));
1973 iavf_mac_add_reject(adapter);
1974 /* restore administratively set MAC address */
1975 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1977 case VIRTCHNL_OP_DEL_VLAN:
1978 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1979 iavf_stat_str(&adapter->hw, v_retval));
1981 case VIRTCHNL_OP_DEL_ETH_ADDR:
1982 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1983 iavf_stat_str(&adapter->hw, v_retval));
1985 case VIRTCHNL_OP_ENABLE_CHANNELS:
1986 dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
1987 iavf_stat_str(&adapter->hw, v_retval));
1988 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1989 adapter->ch_config.state = __IAVF_TC_INVALID;
1990 netdev_reset_tc(netdev);
1991 netif_tx_start_all_queues(netdev);
1993 case VIRTCHNL_OP_DISABLE_CHANNELS:
1994 dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
1995 iavf_stat_str(&adapter->hw, v_retval));
1996 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1997 adapter->ch_config.state = __IAVF_TC_RUNNING;
1998 netif_tx_start_all_queues(netdev);
2000 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2001 struct iavf_cloud_filter *cf, *cftmp;
2003 list_for_each_entry_safe(cf, cftmp,
2004 &adapter->cloud_filter_list,
2006 if (cf->state == __IAVF_CF_ADD_PENDING) {
2007 cf->state = __IAVF_CF_INVALID;
2008 dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
2009 iavf_stat_str(&adapter->hw,
2011 iavf_print_cloud_filter(adapter,
2013 list_del(&cf->list);
2015 adapter->num_cloud_filters--;
2020 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2021 struct iavf_cloud_filter *cf;
2023 list_for_each_entry(cf, &adapter->cloud_filter_list,
2025 if (cf->state == __IAVF_CF_DEL_PENDING) {
2026 cf->state = __IAVF_CF_ACTIVE;
2027 dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
2028 iavf_stat_str(&adapter->hw,
2030 iavf_print_cloud_filter(adapter,
2036 case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2037 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2039 spin_lock_bh(&adapter->fdir_fltr_lock);
2040 list_for_each_entry_safe(fdir, fdir_tmp,
2041 &adapter->fdir_list_head,
2043 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2044 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter, error %s\n",
2045 iavf_stat_str(&adapter->hw,
2047 iavf_print_fdir_fltr(adapter, fdir);
2049 dev_err(&adapter->pdev->dev,
2051 list_del(&fdir->list);
2053 adapter->fdir_active_fltr--;
2056 spin_unlock_bh(&adapter->fdir_fltr_lock);
2059 case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2060 struct iavf_fdir_fltr *fdir;
2062 spin_lock_bh(&adapter->fdir_fltr_lock);
2063 list_for_each_entry(fdir, &adapter->fdir_list_head,
2065 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2066 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2067 dev_info(&adapter->pdev->dev, "Failed to del Flow Director filter, error %s\n",
2068 iavf_stat_str(&adapter->hw,
2070 iavf_print_fdir_fltr(adapter, fdir);
2073 spin_unlock_bh(&adapter->fdir_fltr_lock);
2076 case VIRTCHNL_OP_ADD_RSS_CFG: {
2077 struct iavf_adv_rss *rss, *rss_tmp;
2079 spin_lock_bh(&adapter->adv_rss_lock);
2080 list_for_each_entry_safe(rss, rss_tmp,
2081 &adapter->adv_rss_list_head,
2083 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2084 iavf_print_adv_rss_cfg(adapter, rss,
2085 "Failed to change the input set for",
2087 list_del(&rss->list);
2091 spin_unlock_bh(&adapter->adv_rss_lock);
2094 case VIRTCHNL_OP_DEL_RSS_CFG: {
2095 struct iavf_adv_rss *rss;
2097 spin_lock_bh(&adapter->adv_rss_lock);
2098 list_for_each_entry(rss, &adapter->adv_rss_list_head,
2100 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2101 rss->state = IAVF_ADV_RSS_ACTIVE;
2102 dev_err(&adapter->pdev->dev, "Failed to delete RSS configuration, error %s\n",
2103 iavf_stat_str(&adapter->hw,
2107 spin_unlock_bh(&adapter->adv_rss_lock);
2110 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2111 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2112 /* Vlan stripping could not be enabled by ethtool.
2113 * Disable it in netdev->features.
2115 iavf_netdev_features_vlan_strip_set(netdev, false);
2117 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2118 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2119 /* Vlan stripping could not be disabled by ethtool.
2120 * Enable it in netdev->features.
2122 iavf_netdev_features_vlan_strip_set(netdev, true);
2124 case VIRTCHNL_OP_ADD_VLAN_V2:
2125 iavf_vlan_add_reject(adapter);
2126 dev_warn(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
2127 iavf_stat_str(&adapter->hw, v_retval));
2130 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
2131 v_retval, iavf_stat_str(&adapter->hw, v_retval),
2136 case VIRTCHNL_OP_ADD_ETH_ADDR:
2138 iavf_mac_add_ok(adapter);
2139 if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr))
2140 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2142 case VIRTCHNL_OP_GET_STATS: {
2143 struct iavf_eth_stats *stats =
2144 (struct iavf_eth_stats *)msg;
2145 netdev->stats.rx_packets = stats->rx_unicast +
2146 stats->rx_multicast +
2147 stats->rx_broadcast;
2148 netdev->stats.tx_packets = stats->tx_unicast +
2149 stats->tx_multicast +
2150 stats->tx_broadcast;
2151 netdev->stats.rx_bytes = stats->rx_bytes;
2152 netdev->stats.tx_bytes = stats->tx_bytes;
2153 netdev->stats.tx_errors = stats->tx_errors;
2154 netdev->stats.rx_dropped = stats->rx_discards;
2155 netdev->stats.tx_dropped = stats->tx_discards;
2156 adapter->current_stats = *stats;
2159 case VIRTCHNL_OP_GET_VF_RESOURCES: {
2160 u16 len = sizeof(struct virtchnl_vf_resource) +
2162 sizeof(struct virtchnl_vsi_resource);
2163 memcpy(adapter->vf_res, msg, min(msglen, len));
2164 iavf_validate_num_queues(adapter);
2165 iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
2166 if (is_zero_ether_addr(adapter->hw.mac.addr)) {
2167 /* restore current mac address */
2168 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2170 /* refresh current mac address if changed */
2171 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2172 ether_addr_copy(netdev->perm_addr,
2173 adapter->hw.mac.addr);
2175 spin_lock_bh(&adapter->mac_vlan_list_lock);
2176 iavf_add_filter(adapter, adapter->hw.mac.addr);
2178 if (VLAN_ALLOWED(adapter)) {
2179 if (!list_empty(&adapter->vlan_filter_list)) {
2180 struct iavf_vlan_filter *vlf;
2182 /* re-add all VLAN filters over virtchnl */
2183 list_for_each_entry(vlf,
2184 &adapter->vlan_filter_list,
2188 adapter->aq_required |=
2189 IAVF_FLAG_AQ_ADD_VLAN_FILTER;
2193 spin_unlock_bh(&adapter->mac_vlan_list_lock);
2195 iavf_parse_vf_resource_msg(adapter);
2197 /* negotiated VIRTCHNL_VF_OFFLOAD_VLAN_V2, so wait for the
2198 * response to VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS to finish
2201 if (VLAN_V2_ALLOWED(adapter))
2203 /* fallthrough and finish config if VIRTCHNL_VF_OFFLOAD_VLAN_V2
2204 * wasn't successfully negotiated with the PF
2208 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS: {
2209 if (v_opcode == VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS)
2210 memcpy(&adapter->vlan_v2_caps, msg,
2212 sizeof(adapter->vlan_v2_caps)));
2214 iavf_process_config(adapter);
2215 adapter->flags |= IAVF_FLAG_SETUP_NETDEV_FEATURES;
2218 case VIRTCHNL_OP_ENABLE_QUEUES:
2219 /* enable transmits */
2220 iavf_irq_enable(adapter, true);
2221 adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED;
2223 case VIRTCHNL_OP_DISABLE_QUEUES:
2224 iavf_free_all_tx_resources(adapter);
2225 iavf_free_all_rx_resources(adapter);
2226 if (adapter->state == __IAVF_DOWN_PENDING) {
2227 iavf_change_state(adapter, __IAVF_DOWN);
2228 wake_up(&adapter->down_waitqueue);
2231 case VIRTCHNL_OP_VERSION:
2232 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
2233 /* Don't display an error if we get these out of sequence.
2234 * If the firmware needed to get kicked, we'll get these and
2237 if (v_opcode != adapter->current_op)
2240 case VIRTCHNL_OP_IWARP:
2241 /* Gobble zero-length replies from the PF. They indicate that
2242 * a previous message was received OK, and the client doesn't
2245 if (msglen && CLIENT_ENABLED(adapter))
2246 iavf_notify_client_message(&adapter->vsi, msg, msglen);
2249 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
2250 adapter->client_pending &=
2251 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
2253 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
2254 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
2256 if (msglen == sizeof(*vrh))
2257 adapter->hena = vrh->hena;
2259 dev_warn(&adapter->pdev->dev,
2260 "Invalid message %d from PF\n", v_opcode);
2263 case VIRTCHNL_OP_REQUEST_QUEUES: {
2264 struct virtchnl_vf_res_request *vfres =
2265 (struct virtchnl_vf_res_request *)msg;
2267 if (vfres->num_queue_pairs != adapter->num_req_queues) {
2268 dev_info(&adapter->pdev->dev,
2269 "Requested %d queues, PF can support %d\n",
2270 adapter->num_req_queues,
2271 vfres->num_queue_pairs);
2272 adapter->num_req_queues = 0;
2273 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2277 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2278 struct iavf_cloud_filter *cf;
2280 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
2281 if (cf->state == __IAVF_CF_ADD_PENDING)
2282 cf->state = __IAVF_CF_ACTIVE;
2286 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2287 struct iavf_cloud_filter *cf, *cftmp;
2289 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
2291 if (cf->state == __IAVF_CF_DEL_PENDING) {
2292 cf->state = __IAVF_CF_INVALID;
2293 list_del(&cf->list);
2295 adapter->num_cloud_filters--;
2300 case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2301 struct virtchnl_fdir_add *add_fltr = (struct virtchnl_fdir_add *)msg;
2302 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2304 spin_lock_bh(&adapter->fdir_fltr_lock);
2305 list_for_each_entry_safe(fdir, fdir_tmp,
2306 &adapter->fdir_list_head,
2308 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2309 if (add_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2310 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is added\n",
2312 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2313 fdir->flow_id = add_fltr->flow_id;
2315 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter with status: %d\n",
2317 iavf_print_fdir_fltr(adapter, fdir);
2318 list_del(&fdir->list);
2320 adapter->fdir_active_fltr--;
2324 spin_unlock_bh(&adapter->fdir_fltr_lock);
2327 case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2328 struct virtchnl_fdir_del *del_fltr = (struct virtchnl_fdir_del *)msg;
2329 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2331 spin_lock_bh(&adapter->fdir_fltr_lock);
2332 list_for_each_entry_safe(fdir, fdir_tmp, &adapter->fdir_list_head,
2334 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2335 if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2336 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is deleted\n",
2338 list_del(&fdir->list);
2340 adapter->fdir_active_fltr--;
2342 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2343 dev_info(&adapter->pdev->dev, "Failed to delete Flow Director filter with status: %d\n",
2345 iavf_print_fdir_fltr(adapter, fdir);
2349 spin_unlock_bh(&adapter->fdir_fltr_lock);
2352 case VIRTCHNL_OP_ADD_RSS_CFG: {
2353 struct iavf_adv_rss *rss;
2355 spin_lock_bh(&adapter->adv_rss_lock);
2356 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
2357 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2358 iavf_print_adv_rss_cfg(adapter, rss,
2359 "Input set change for",
2361 rss->state = IAVF_ADV_RSS_ACTIVE;
2364 spin_unlock_bh(&adapter->adv_rss_lock);
2367 case VIRTCHNL_OP_DEL_RSS_CFG: {
2368 struct iavf_adv_rss *rss, *rss_tmp;
2370 spin_lock_bh(&adapter->adv_rss_lock);
2371 list_for_each_entry_safe(rss, rss_tmp,
2372 &adapter->adv_rss_list_head, list) {
2373 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2374 list_del(&rss->list);
2378 spin_unlock_bh(&adapter->adv_rss_lock);
2381 case VIRTCHNL_OP_ADD_VLAN_V2: {
2382 struct iavf_vlan_filter *f;
2384 spin_lock_bh(&adapter->mac_vlan_list_lock);
2385 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
2386 if (f->is_new_vlan) {
2387 f->is_new_vlan = false;
2388 if (f->vlan.tpid == ETH_P_8021Q)
2389 set_bit(f->vlan.vid,
2390 adapter->vsi.active_cvlans);
2392 set_bit(f->vlan.vid,
2393 adapter->vsi.active_svlans);
2396 spin_unlock_bh(&adapter->mac_vlan_list_lock);
2399 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2400 /* PF enabled vlan strip on this VF.
2401 * Update netdev->features if needed to be in sync with ethtool.
2404 iavf_netdev_features_vlan_strip_set(netdev, true);
2406 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2407 /* PF disabled vlan strip on this VF.
2408 * Update netdev->features if needed to be in sync with ethtool.
2411 iavf_netdev_features_vlan_strip_set(netdev, false);
2414 if (adapter->current_op && (v_opcode != adapter->current_op))
2415 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
2416 adapter->current_op, v_opcode);
2418 } /* switch v_opcode */
2419 adapter->current_op = VIRTCHNL_OP_UNKNOWN;