1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
4 * Copyright(c) 2013 - 2014 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
28 #include "i40e_prototype.h"
29 #include "i40evf_client.h"
31 /* busy wait delay in msec */
32 #define I40EVF_BUSY_WAIT_DELAY 10
33 #define I40EVF_BUSY_WAIT_COUNT 50
37 * @adapter: adapter structure
38 * @op: virtual channel opcode
39 * @msg: pointer to message buffer
40 * @len: message length
42 * Send message to PF and print status if failure.
44 static int i40evf_send_pf_msg(struct i40evf_adapter *adapter,
45 enum virtchnl_ops op, u8 *msg, u16 len)
47 struct i40e_hw *hw = &adapter->hw;
50 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
51 return 0; /* nothing to see here, move along */
53 err = i40e_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
55 dev_err(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n",
56 op, i40evf_stat_str(hw, err),
57 i40evf_aq_str(hw, hw->aq.asq_last_status));
63 * @adapter: adapter structure
65 * Send API version admin queue message to the PF. The reply is not checked
66 * in this function. Returns 0 if the message was successfully
67 * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
69 int i40evf_send_api_ver(struct i40evf_adapter *adapter)
71 struct virtchnl_version_info vvi;
73 vvi.major = VIRTCHNL_VERSION_MAJOR;
74 vvi.minor = VIRTCHNL_VERSION_MINOR;
76 return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
81 * i40evf_verify_api_ver
82 * @adapter: adapter structure
84 * Compare API versions with the PF. Must be called after admin queue is
85 * initialized. Returns 0 if API versions match, -EIO if they do not,
86 * I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
87 * from the firmware are propagated.
89 int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
91 struct virtchnl_version_info *pf_vvi;
92 struct i40e_hw *hw = &adapter->hw;
93 struct i40e_arq_event_info event;
97 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
98 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
105 err = i40evf_clean_arq_element(hw, &event, NULL);
106 /* When the AQ is empty, i40evf_clean_arq_element will return
107 * nonzero and this loop will terminate.
112 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
113 if (op == VIRTCHNL_OP_VERSION)
118 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
122 if (op != VIRTCHNL_OP_VERSION) {
123 dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n",
129 pf_vvi = (struct virtchnl_version_info *)event.msg_buf;
130 adapter->pf_version = *pf_vvi;
132 if ((pf_vvi->major > VIRTCHNL_VERSION_MAJOR) ||
133 ((pf_vvi->major == VIRTCHNL_VERSION_MAJOR) &&
134 (pf_vvi->minor > VIRTCHNL_VERSION_MINOR)))
138 kfree(event.msg_buf);
144 * i40evf_send_vf_config_msg
145 * @adapter: adapter structure
147 * Send VF configuration request admin queue message to the PF. The reply
148 * is not checked in this function. Returns 0 if the message was
149 * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
151 int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
155 caps = VIRTCHNL_VF_OFFLOAD_L2 |
156 VIRTCHNL_VF_OFFLOAD_RSS_PF |
157 VIRTCHNL_VF_OFFLOAD_RSS_AQ |
158 VIRTCHNL_VF_OFFLOAD_RSS_REG |
159 VIRTCHNL_VF_OFFLOAD_VLAN |
160 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
161 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
162 VIRTCHNL_VF_OFFLOAD_ENCAP |
163 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
165 adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
166 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
167 if (PF_IS_V11(adapter))
168 return i40evf_send_pf_msg(adapter,
169 VIRTCHNL_OP_GET_VF_RESOURCES,
170 (u8 *)&caps, sizeof(caps));
172 return i40evf_send_pf_msg(adapter,
173 VIRTCHNL_OP_GET_VF_RESOURCES,
178 * i40evf_get_vf_config
179 * @hw: pointer to the hardware structure
180 * @len: length of buffer
182 * Get VF configuration from PF and populate hw structure. Must be called after
183 * admin queue is initialized. Busy waits until response is received from PF,
184 * with maximum timeout. Response from PF is returned in the buffer for further
185 * processing by the caller.
187 int i40evf_get_vf_config(struct i40evf_adapter *adapter)
189 struct i40e_hw *hw = &adapter->hw;
190 struct i40e_arq_event_info event;
191 enum virtchnl_ops op;
195 len = sizeof(struct virtchnl_vf_resource) +
196 I40E_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
198 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
199 if (!event.msg_buf) {
205 /* When the AQ is empty, i40evf_clean_arq_element will return
206 * nonzero and this loop will terminate.
208 err = i40evf_clean_arq_element(hw, &event, NULL);
212 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
213 if (op == VIRTCHNL_OP_GET_VF_RESOURCES)
217 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
218 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
220 i40e_vf_parse_hw_config(hw, adapter->vf_res);
222 kfree(event.msg_buf);
228 * i40evf_configure_queues
229 * @adapter: adapter structure
231 * Request that the PF set up our (previously allocated) queues.
233 void i40evf_configure_queues(struct i40evf_adapter *adapter)
235 struct virtchnl_vsi_queue_config_info *vqci;
236 struct virtchnl_queue_pair_info *vqpi;
237 int pairs = adapter->num_active_queues;
238 int i, len, max_frame = I40E_MAX_RXBUFFER;
240 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
241 /* bail because we already have a command pending */
242 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
243 adapter->current_op);
246 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
247 len = sizeof(struct virtchnl_vsi_queue_config_info) +
248 (sizeof(struct virtchnl_queue_pair_info) * pairs);
249 vqci = kzalloc(len, GFP_KERNEL);
253 /* Limit maximum frame size when jumbo frames is not enabled */
254 if (!(adapter->flags & I40EVF_FLAG_LEGACY_RX) &&
255 (adapter->netdev->mtu <= ETH_DATA_LEN))
256 max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
258 vqci->vsi_id = adapter->vsi_res->vsi_id;
259 vqci->num_queue_pairs = pairs;
261 /* Size check is not needed here - HW max is 16 queue pairs, and we
262 * can fit info for 31 of them into the AQ buffer before it overflows.
264 for (i = 0; i < pairs; i++) {
265 vqpi->txq.vsi_id = vqci->vsi_id;
266 vqpi->txq.queue_id = i;
267 vqpi->txq.ring_len = adapter->tx_rings[i].count;
268 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
269 vqpi->rxq.vsi_id = vqci->vsi_id;
270 vqpi->rxq.queue_id = i;
271 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
272 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
273 vqpi->rxq.max_pkt_size = max_frame;
274 vqpi->rxq.databuffer_size =
275 ALIGN(adapter->rx_rings[i].rx_buf_len,
276 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
280 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
281 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
287 * i40evf_enable_queues
288 * @adapter: adapter structure
290 * Request that the PF enable all of our queues.
292 void i40evf_enable_queues(struct i40evf_adapter *adapter)
294 struct virtchnl_queue_select vqs;
296 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
297 /* bail because we already have a command pending */
298 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
299 adapter->current_op);
302 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
303 vqs.vsi_id = adapter->vsi_res->vsi_id;
304 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
305 vqs.rx_queues = vqs.tx_queues;
306 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
307 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
308 (u8 *)&vqs, sizeof(vqs));
312 * i40evf_disable_queues
313 * @adapter: adapter structure
315 * Request that the PF disable all of our queues.
317 void i40evf_disable_queues(struct i40evf_adapter *adapter)
319 struct virtchnl_queue_select vqs;
321 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
322 /* bail because we already have a command pending */
323 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
324 adapter->current_op);
327 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
328 vqs.vsi_id = adapter->vsi_res->vsi_id;
329 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
330 vqs.rx_queues = vqs.tx_queues;
331 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
332 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
333 (u8 *)&vqs, sizeof(vqs));
338 * @adapter: adapter structure
340 * Request that the PF map queues to interrupt vectors. Misc causes, including
341 * admin queue, are always mapped to vector 0.
343 void i40evf_map_queues(struct i40evf_adapter *adapter)
345 struct virtchnl_irq_map_info *vimi;
346 int v_idx, q_vectors, len;
347 struct i40e_q_vector *q_vector;
349 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
350 /* bail because we already have a command pending */
351 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
352 adapter->current_op);
355 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
357 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
359 len = sizeof(struct virtchnl_irq_map_info) +
360 (adapter->num_msix_vectors *
361 sizeof(struct virtchnl_vector_map));
362 vimi = kzalloc(len, GFP_KERNEL);
366 vimi->num_vectors = adapter->num_msix_vectors;
367 /* Queue vectors first */
368 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
369 q_vector = adapter->q_vectors + v_idx;
370 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
371 vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
372 vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
373 vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
375 /* Misc vector last - this is only for AdminQ messages */
376 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
377 vimi->vecmap[v_idx].vector_id = 0;
378 vimi->vecmap[v_idx].txq_map = 0;
379 vimi->vecmap[v_idx].rxq_map = 0;
381 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
382 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
388 * i40evf_add_ether_addrs
389 * @adapter: adapter structure
390 * @addrs: the MAC address filters to add (contiguous)
391 * @count: number of filters
393 * Request that the PF add one or more addresses to our filters.
395 void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
397 struct virtchnl_ether_addr_list *veal;
398 int len, i = 0, count = 0;
399 struct i40evf_mac_filter *f;
402 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
403 /* bail because we already have a command pending */
404 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
405 adapter->current_op);
408 list_for_each_entry(f, &adapter->mac_filter_list, list) {
413 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
416 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
418 len = sizeof(struct virtchnl_ether_addr_list) +
419 (count * sizeof(struct virtchnl_ether_addr));
420 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
421 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
422 count = (I40EVF_MAX_AQ_BUF_SIZE -
423 sizeof(struct virtchnl_ether_addr_list)) /
424 sizeof(struct virtchnl_ether_addr);
425 len = sizeof(struct virtchnl_ether_addr_list) +
426 (count * sizeof(struct virtchnl_ether_addr));
430 veal = kzalloc(len, GFP_KERNEL);
434 veal->vsi_id = adapter->vsi_res->vsi_id;
435 veal->num_elements = count;
436 list_for_each_entry(f, &adapter->mac_filter_list, list) {
438 ether_addr_copy(veal->list[i].addr, f->macaddr);
446 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
447 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR,
453 * i40evf_del_ether_addrs
454 * @adapter: adapter structure
455 * @addrs: the MAC address filters to remove (contiguous)
456 * @count: number of filtes
458 * Request that the PF remove one or more addresses from our filters.
460 void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
462 struct virtchnl_ether_addr_list *veal;
463 struct i40evf_mac_filter *f, *ftmp;
464 int len, i = 0, count = 0;
467 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
468 /* bail because we already have a command pending */
469 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
470 adapter->current_op);
473 list_for_each_entry(f, &adapter->mac_filter_list, list) {
478 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
481 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
483 len = sizeof(struct virtchnl_ether_addr_list) +
484 (count * sizeof(struct virtchnl_ether_addr));
485 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
486 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
487 count = (I40EVF_MAX_AQ_BUF_SIZE -
488 sizeof(struct virtchnl_ether_addr_list)) /
489 sizeof(struct virtchnl_ether_addr);
490 len = sizeof(struct virtchnl_ether_addr_list) +
491 (count * sizeof(struct virtchnl_ether_addr));
494 veal = kzalloc(len, GFP_KERNEL);
498 veal->vsi_id = adapter->vsi_res->vsi_id;
499 veal->num_elements = count;
500 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
502 ether_addr_copy(veal->list[i].addr, f->macaddr);
511 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
512 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR,
519 * @adapter: adapter structure
520 * @vlans: the VLANs to add
521 * @count: number of VLANs
523 * Request that the PF add one or more VLAN filters to our VSI.
525 void i40evf_add_vlans(struct i40evf_adapter *adapter)
527 struct virtchnl_vlan_filter_list *vvfl;
528 int len, i = 0, count = 0;
529 struct i40evf_vlan_filter *f;
532 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
533 /* bail because we already have a command pending */
534 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
535 adapter->current_op);
539 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
544 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
547 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
549 len = sizeof(struct virtchnl_vlan_filter_list) +
550 (count * sizeof(u16));
551 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
552 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
553 count = (I40EVF_MAX_AQ_BUF_SIZE -
554 sizeof(struct virtchnl_vlan_filter_list)) /
556 len = sizeof(struct virtchnl_vlan_filter_list) +
557 (count * sizeof(u16));
560 vvfl = kzalloc(len, GFP_KERNEL);
564 vvfl->vsi_id = adapter->vsi_res->vsi_id;
565 vvfl->num_elements = count;
566 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
568 vvfl->vlan_id[i] = f->vlan;
576 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
577 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
583 * @adapter: adapter structure
584 * @vlans: the VLANs to remove
585 * @count: number of VLANs
587 * Request that the PF remove one or more VLAN filters from our VSI.
589 void i40evf_del_vlans(struct i40evf_adapter *adapter)
591 struct virtchnl_vlan_filter_list *vvfl;
592 struct i40evf_vlan_filter *f, *ftmp;
593 int len, i = 0, count = 0;
596 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
597 /* bail because we already have a command pending */
598 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
599 adapter->current_op);
603 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
608 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
611 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
613 len = sizeof(struct virtchnl_vlan_filter_list) +
614 (count * sizeof(u16));
615 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
616 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
617 count = (I40EVF_MAX_AQ_BUF_SIZE -
618 sizeof(struct virtchnl_vlan_filter_list)) /
620 len = sizeof(struct virtchnl_vlan_filter_list) +
621 (count * sizeof(u16));
624 vvfl = kzalloc(len, GFP_KERNEL);
628 vvfl->vsi_id = adapter->vsi_res->vsi_id;
629 vvfl->num_elements = count;
630 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
632 vvfl->vlan_id[i] = f->vlan;
641 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
642 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
647 * i40evf_set_promiscuous
648 * @adapter: adapter structure
649 * @flags: bitmask to control unicast/multicast promiscuous.
651 * Request that the PF enable promiscuous mode for our VSI.
653 void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
655 struct virtchnl_promisc_info vpi;
658 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
659 /* bail because we already have a command pending */
660 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
661 adapter->current_op);
665 promisc_all = FLAG_VF_UNICAST_PROMISC |
666 FLAG_VF_MULTICAST_PROMISC;
667 if ((flags & promisc_all) == promisc_all) {
668 adapter->flags |= I40EVF_FLAG_PROMISC_ON;
669 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
670 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
673 if (flags & FLAG_VF_MULTICAST_PROMISC) {
674 adapter->flags |= I40EVF_FLAG_ALLMULTI_ON;
675 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
676 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
680 adapter->flags &= ~I40EVF_FLAG_PROMISC_ON;
681 adapter->aq_required &= ~I40EVF_FLAG_AQ_RELEASE_PROMISC;
682 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
685 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
686 vpi.vsi_id = adapter->vsi_res->vsi_id;
688 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
689 (u8 *)&vpi, sizeof(vpi));
693 * i40evf_request_stats
694 * @adapter: adapter structure
696 * Request VSI statistics from PF.
698 void i40evf_request_stats(struct i40evf_adapter *adapter)
700 struct virtchnl_queue_select vqs;
702 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
703 /* no error message, this isn't crucial */
706 adapter->current_op = VIRTCHNL_OP_GET_STATS;
707 vqs.vsi_id = adapter->vsi_res->vsi_id;
708 /* queue maps are ignored for this message - only the vsi is used */
709 if (i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS,
710 (u8 *)&vqs, sizeof(vqs)))
711 /* if the request failed, don't lock out others */
712 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
717 * @adapter: adapter structure
719 * Request hash enable capabilities from PF
721 void i40evf_get_hena(struct i40evf_adapter *adapter)
723 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
724 /* bail because we already have a command pending */
725 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
726 adapter->current_op);
729 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
730 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
731 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS,
737 * @adapter: adapter structure
739 * Request the PF to set our RSS hash capabilities
741 void i40evf_set_hena(struct i40evf_adapter *adapter)
743 struct virtchnl_rss_hena vrh;
745 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
746 /* bail because we already have a command pending */
747 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
748 adapter->current_op);
751 vrh.hena = adapter->hena;
752 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
753 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
754 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA,
755 (u8 *)&vrh, sizeof(vrh));
760 * @adapter: adapter structure
762 * Request the PF to set our RSS hash key
764 void i40evf_set_rss_key(struct i40evf_adapter *adapter)
766 struct virtchnl_rss_key *vrk;
769 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
770 /* bail because we already have a command pending */
771 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
772 adapter->current_op);
775 len = sizeof(struct virtchnl_rss_key) +
776 (adapter->rss_key_size * sizeof(u8)) - 1;
777 vrk = kzalloc(len, GFP_KERNEL);
780 vrk->vsi_id = adapter->vsi.id;
781 vrk->key_len = adapter->rss_key_size;
782 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
784 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
785 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
786 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY,
793 * @adapter: adapter structure
795 * Request the PF to set our RSS lookup table
797 void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
799 struct virtchnl_rss_lut *vrl;
802 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
803 /* bail because we already have a command pending */
804 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
805 adapter->current_op);
808 len = sizeof(struct virtchnl_rss_lut) +
809 (adapter->rss_lut_size * sizeof(u8)) - 1;
810 vrl = kzalloc(len, GFP_KERNEL);
813 vrl->vsi_id = adapter->vsi.id;
814 vrl->lut_entries = adapter->rss_lut_size;
815 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
816 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
817 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
818 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT,
824 * i40evf_enable_vlan_stripping
825 * @adapter: adapter structure
827 * Request VLAN header stripping to be enabled
829 void i40evf_enable_vlan_stripping(struct i40evf_adapter *adapter)
831 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
832 /* bail because we already have a command pending */
833 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
834 adapter->current_op);
837 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
838 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
839 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
844 * i40evf_disable_vlan_stripping
845 * @adapter: adapter structure
847 * Request VLAN header stripping to be disabled
849 void i40evf_disable_vlan_stripping(struct i40evf_adapter *adapter)
851 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
852 /* bail because we already have a command pending */
853 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
854 adapter->current_op);
857 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
858 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
859 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
864 * i40evf_print_link_message - print link up or down
865 * @adapter: adapter structure
867 * Log a message telling the world of our wonderous link status
869 static void i40evf_print_link_message(struct i40evf_adapter *adapter)
871 struct net_device *netdev = adapter->netdev;
872 char *speed = "Unknown ";
874 if (!adapter->link_up) {
875 netdev_info(netdev, "NIC Link is Down\n");
879 switch (adapter->link_speed) {
880 case I40E_LINK_SPEED_40GB:
883 case I40E_LINK_SPEED_25GB:
886 case I40E_LINK_SPEED_20GB:
889 case I40E_LINK_SPEED_10GB:
892 case I40E_LINK_SPEED_1GB:
895 case I40E_LINK_SPEED_100MB:
902 netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
906 * i40evf_request_reset
907 * @adapter: adapter structure
909 * Request that the PF reset this VF. No response is expected.
911 void i40evf_request_reset(struct i40evf_adapter *adapter)
913 /* Don't check CURRENT_OP - this is always higher priority */
914 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
915 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
919 * i40evf_virtchnl_completion
920 * @adapter: adapter structure
921 * @v_opcode: opcode sent by PF
922 * @v_retval: retval sent by PF
923 * @msg: message sent by PF
924 * @msglen: message length
926 * Asynchronous completion function for admin queue messages. Rather than busy
927 * wait, we fire off our requests and assume that no errors will be returned.
928 * This function handles the reply messages.
930 void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
931 enum virtchnl_ops v_opcode,
932 i40e_status v_retval,
935 struct net_device *netdev = adapter->netdev;
937 if (v_opcode == VIRTCHNL_OP_EVENT) {
938 struct virtchnl_pf_event *vpe =
939 (struct virtchnl_pf_event *)msg;
940 bool link_up = vpe->event_data.link_event.link_status;
941 switch (vpe->event) {
942 case VIRTCHNL_EVENT_LINK_CHANGE:
943 adapter->link_speed =
944 vpe->event_data.link_event.link_speed;
946 /* we've already got the right link status, bail */
947 if (adapter->link_up == link_up)
950 /* If we get link up message and start queues before
951 * our queues are configured it will trigger a TX hang.
952 * In that case, just ignore the link status message,
953 * we'll get another one after we enable queues and
954 * actually prepared to send traffic.
956 if (link_up && adapter->state != __I40EVF_RUNNING)
959 adapter->link_up = link_up;
961 netif_tx_start_all_queues(netdev);
962 netif_carrier_on(netdev);
964 netif_tx_stop_all_queues(netdev);
965 netif_carrier_off(netdev);
967 i40evf_print_link_message(adapter);
969 case VIRTCHNL_EVENT_RESET_IMPENDING:
970 dev_info(&adapter->pdev->dev, "PF reset warning received\n");
971 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
972 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
973 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
974 schedule_work(&adapter->reset_task);
978 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
986 case VIRTCHNL_OP_ADD_VLAN:
987 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
988 i40evf_stat_str(&adapter->hw, v_retval));
990 case VIRTCHNL_OP_ADD_ETH_ADDR:
991 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
992 i40evf_stat_str(&adapter->hw, v_retval));
994 case VIRTCHNL_OP_DEL_VLAN:
995 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
996 i40evf_stat_str(&adapter->hw, v_retval));
998 case VIRTCHNL_OP_DEL_ETH_ADDR:
999 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1000 i40evf_stat_str(&adapter->hw, v_retval));
1003 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
1005 i40evf_stat_str(&adapter->hw, v_retval),
1010 case VIRTCHNL_OP_GET_STATS: {
1011 struct i40e_eth_stats *stats =
1012 (struct i40e_eth_stats *)msg;
1013 netdev->stats.rx_packets = stats->rx_unicast +
1014 stats->rx_multicast +
1015 stats->rx_broadcast;
1016 netdev->stats.tx_packets = stats->tx_unicast +
1017 stats->tx_multicast +
1018 stats->tx_broadcast;
1019 netdev->stats.rx_bytes = stats->rx_bytes;
1020 netdev->stats.tx_bytes = stats->tx_bytes;
1021 netdev->stats.tx_errors = stats->tx_errors;
1022 netdev->stats.rx_dropped = stats->rx_discards;
1023 netdev->stats.tx_dropped = stats->tx_discards;
1024 adapter->current_stats = *stats;
1027 case VIRTCHNL_OP_GET_VF_RESOURCES: {
1028 u16 len = sizeof(struct virtchnl_vf_resource) +
1030 sizeof(struct virtchnl_vsi_resource);
1031 memcpy(adapter->vf_res, msg, min(msglen, len));
1032 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
1033 /* restore current mac address */
1034 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1035 i40evf_process_config(adapter);
1038 case VIRTCHNL_OP_ENABLE_QUEUES:
1039 /* enable transmits */
1040 i40evf_irq_enable(adapter, true);
1042 case VIRTCHNL_OP_DISABLE_QUEUES:
1043 i40evf_free_all_tx_resources(adapter);
1044 i40evf_free_all_rx_resources(adapter);
1045 if (adapter->state == __I40EVF_DOWN_PENDING) {
1046 adapter->state = __I40EVF_DOWN;
1047 wake_up(&adapter->down_waitqueue);
1050 case VIRTCHNL_OP_VERSION:
1051 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1052 /* Don't display an error if we get these out of sequence.
1053 * If the firmware needed to get kicked, we'll get these and
1056 if (v_opcode != adapter->current_op)
1059 case VIRTCHNL_OP_IWARP:
1060 /* Gobble zero-length replies from the PF. They indicate that
1061 * a previous message was received OK, and the client doesn't
1064 if (msglen && CLIENT_ENABLED(adapter))
1065 i40evf_notify_client_message(&adapter->vsi,
1069 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
1070 adapter->client_pending &=
1071 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
1073 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
1074 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
1075 if (msglen == sizeof(*vrh))
1076 adapter->hena = vrh->hena;
1078 dev_warn(&adapter->pdev->dev,
1079 "Invalid message %d from PF\n", v_opcode);
1083 if (adapter->current_op && (v_opcode != adapter->current_op))
1084 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
1085 adapter->current_op, v_opcode);
1087 } /* switch v_opcode */
1088 adapter->current_op = VIRTCHNL_OP_UNKNOWN;