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"
30 /* busy wait delay in msec */
31 #define I40EVF_BUSY_WAIT_DELAY 10
32 #define I40EVF_BUSY_WAIT_COUNT 50
36 * @adapter: adapter structure
37 * @op: virtual channel opcode
38 * @msg: pointer to message buffer
39 * @len: message length
41 * Send message to PF and print status if failure.
43 static int i40evf_send_pf_msg(struct i40evf_adapter *adapter,
44 enum i40e_virtchnl_ops op, u8 *msg, u16 len)
46 struct i40e_hw *hw = &adapter->hw;
49 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
50 return 0; /* nothing to see here, move along */
52 err = i40e_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
54 dev_err(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n",
55 op, i40evf_stat_str(hw, err),
56 i40evf_aq_str(hw, hw->aq.asq_last_status));
62 * @adapter: adapter structure
64 * Send API version admin queue message to the PF. The reply is not checked
65 * in this function. Returns 0 if the message was successfully
66 * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
68 int i40evf_send_api_ver(struct i40evf_adapter *adapter)
70 struct i40e_virtchnl_version_info vvi;
72 vvi.major = I40E_VIRTCHNL_VERSION_MAJOR;
73 vvi.minor = I40E_VIRTCHNL_VERSION_MINOR;
75 return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_VERSION, (u8 *)&vvi,
80 * i40evf_verify_api_ver
81 * @adapter: adapter structure
83 * Compare API versions with the PF. Must be called after admin queue is
84 * initialized. Returns 0 if API versions match, -EIO if they do not,
85 * I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
86 * from the firmware are propagated.
88 int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
90 struct i40e_virtchnl_version_info *pf_vvi;
91 struct i40e_hw *hw = &adapter->hw;
92 struct i40e_arq_event_info event;
93 enum i40e_virtchnl_ops op;
96 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
97 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
104 err = i40evf_clean_arq_element(hw, &event, NULL);
105 /* When the AQ is empty, i40evf_clean_arq_element will return
106 * nonzero and this loop will terminate.
111 (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
112 if (op == I40E_VIRTCHNL_OP_VERSION)
117 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
121 if (op != I40E_VIRTCHNL_OP_VERSION) {
122 dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n",
128 pf_vvi = (struct i40e_virtchnl_version_info *)event.msg_buf;
129 adapter->pf_version = *pf_vvi;
131 if ((pf_vvi->major > I40E_VIRTCHNL_VERSION_MAJOR) ||
132 ((pf_vvi->major == I40E_VIRTCHNL_VERSION_MAJOR) &&
133 (pf_vvi->minor > I40E_VIRTCHNL_VERSION_MINOR)))
137 kfree(event.msg_buf);
143 * i40evf_send_vf_config_msg
144 * @adapter: adapter structure
146 * Send VF configuration request admin queue message to the PF. The reply
147 * is not checked in this function. Returns 0 if the message was
148 * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
150 int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
154 adapter->current_op = I40E_VIRTCHNL_OP_GET_VF_RESOURCES;
155 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
156 caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
157 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ |
158 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
159 I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
160 adapter->current_op = I40E_VIRTCHNL_OP_GET_VF_RESOURCES;
161 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
162 if (PF_IS_V11(adapter))
163 return i40evf_send_pf_msg(adapter,
164 I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
165 (u8 *)&caps, sizeof(caps));
167 return i40evf_send_pf_msg(adapter,
168 I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
173 * i40evf_get_vf_config
174 * @hw: pointer to the hardware structure
175 * @len: length of buffer
177 * Get VF configuration from PF and populate hw structure. Must be called after
178 * admin queue is initialized. Busy waits until response is received from PF,
179 * with maximum timeout. Response from PF is returned in the buffer for further
180 * processing by the caller.
182 int i40evf_get_vf_config(struct i40evf_adapter *adapter)
184 struct i40e_hw *hw = &adapter->hw;
185 struct i40e_arq_event_info event;
186 enum i40e_virtchnl_ops op;
190 len = sizeof(struct i40e_virtchnl_vf_resource) +
191 I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
193 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
194 if (!event.msg_buf) {
200 /* When the AQ is empty, i40evf_clean_arq_element will return
201 * nonzero and this loop will terminate.
203 err = i40evf_clean_arq_element(hw, &event, NULL);
207 (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
208 if (op == I40E_VIRTCHNL_OP_GET_VF_RESOURCES)
212 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
213 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
215 i40e_vf_parse_hw_config(hw, adapter->vf_res);
217 kfree(event.msg_buf);
223 * i40evf_configure_queues
224 * @adapter: adapter structure
226 * Request that the PF set up our (previously allocated) queues.
228 void i40evf_configure_queues(struct i40evf_adapter *adapter)
230 struct i40e_virtchnl_vsi_queue_config_info *vqci;
231 struct i40e_virtchnl_queue_pair_info *vqpi;
232 int pairs = adapter->num_active_queues;
235 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
236 /* bail because we already have a command pending */
237 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
238 __func__, adapter->current_op);
241 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
242 len = sizeof(struct i40e_virtchnl_vsi_queue_config_info) +
243 (sizeof(struct i40e_virtchnl_queue_pair_info) * pairs);
244 vqci = kzalloc(len, GFP_ATOMIC);
248 vqci->vsi_id = adapter->vsi_res->vsi_id;
249 vqci->num_queue_pairs = pairs;
251 /* Size check is not needed here - HW max is 16 queue pairs, and we
252 * can fit info for 31 of them into the AQ buffer before it overflows.
254 for (i = 0; i < pairs; i++) {
255 vqpi->txq.vsi_id = vqci->vsi_id;
256 vqpi->txq.queue_id = i;
257 vqpi->txq.ring_len = adapter->tx_rings[i]->count;
258 vqpi->txq.dma_ring_addr = adapter->tx_rings[i]->dma;
259 vqpi->txq.headwb_enabled = 1;
260 vqpi->txq.dma_headwb_addr = vqpi->txq.dma_ring_addr +
261 (vqpi->txq.ring_len * sizeof(struct i40e_tx_desc));
263 vqpi->rxq.vsi_id = vqci->vsi_id;
264 vqpi->rxq.queue_id = i;
265 vqpi->rxq.ring_len = adapter->rx_rings[i]->count;
266 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i]->dma;
267 vqpi->rxq.max_pkt_size = adapter->netdev->mtu
268 + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN;
269 vqpi->rxq.databuffer_size = adapter->rx_rings[i]->rx_buf_len;
273 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
274 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
280 * i40evf_enable_queues
281 * @adapter: adapter structure
283 * Request that the PF enable all of our queues.
285 void i40evf_enable_queues(struct i40evf_adapter *adapter)
287 struct i40e_virtchnl_queue_select vqs;
289 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
290 /* bail because we already have a command pending */
291 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
292 __func__, adapter->current_op);
295 adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
296 vqs.vsi_id = adapter->vsi_res->vsi_id;
297 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
298 vqs.rx_queues = vqs.tx_queues;
299 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
300 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
301 (u8 *)&vqs, sizeof(vqs));
305 * i40evf_disable_queues
306 * @adapter: adapter structure
308 * Request that the PF disable all of our queues.
310 void i40evf_disable_queues(struct i40evf_adapter *adapter)
312 struct i40e_virtchnl_queue_select vqs;
314 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
315 /* bail because we already have a command pending */
316 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
317 __func__, adapter->current_op);
320 adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
321 vqs.vsi_id = adapter->vsi_res->vsi_id;
322 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
323 vqs.rx_queues = vqs.tx_queues;
324 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
325 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
326 (u8 *)&vqs, sizeof(vqs));
331 * @adapter: adapter structure
333 * Request that the PF map queues to interrupt vectors. Misc causes, including
334 * admin queue, are always mapped to vector 0.
336 void i40evf_map_queues(struct i40evf_adapter *adapter)
338 struct i40e_virtchnl_irq_map_info *vimi;
339 int v_idx, q_vectors, len;
340 struct i40e_q_vector *q_vector;
342 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
343 /* bail because we already have a command pending */
344 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
345 __func__, adapter->current_op);
348 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
350 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
352 len = sizeof(struct i40e_virtchnl_irq_map_info) +
353 (adapter->num_msix_vectors *
354 sizeof(struct i40e_virtchnl_vector_map));
355 vimi = kzalloc(len, GFP_ATOMIC);
359 vimi->num_vectors = adapter->num_msix_vectors;
360 /* Queue vectors first */
361 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
362 q_vector = adapter->q_vector[v_idx];
363 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
364 vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
365 vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
366 vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
368 /* Misc vector last - this is only for AdminQ messages */
369 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
370 vimi->vecmap[v_idx].vector_id = 0;
371 vimi->vecmap[v_idx].txq_map = 0;
372 vimi->vecmap[v_idx].rxq_map = 0;
374 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
375 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
381 * i40evf_add_ether_addrs
382 * @adapter: adapter structure
383 * @addrs: the MAC address filters to add (contiguous)
384 * @count: number of filters
386 * Request that the PF add one or more addresses to our filters.
388 void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
390 struct i40e_virtchnl_ether_addr_list *veal;
391 int len, i = 0, count = 0;
392 struct i40evf_mac_filter *f;
394 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
395 /* bail because we already have a command pending */
396 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
397 __func__, adapter->current_op);
400 list_for_each_entry(f, &adapter->mac_filter_list, list) {
405 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
408 adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
410 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
411 (count * sizeof(struct i40e_virtchnl_ether_addr));
412 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
413 dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request\n",
415 count = (I40EVF_MAX_AQ_BUF_SIZE -
416 sizeof(struct i40e_virtchnl_ether_addr_list)) /
417 sizeof(struct i40e_virtchnl_ether_addr);
418 len = I40EVF_MAX_AQ_BUF_SIZE;
421 veal = kzalloc(len, GFP_ATOMIC);
425 veal->vsi_id = adapter->vsi_res->vsi_id;
426 veal->num_elements = count;
427 list_for_each_entry(f, &adapter->mac_filter_list, list) {
429 ether_addr_copy(veal->list[i].addr, f->macaddr);
434 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
435 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
441 * i40evf_del_ether_addrs
442 * @adapter: adapter structure
443 * @addrs: the MAC address filters to remove (contiguous)
444 * @count: number of filtes
446 * Request that the PF remove one or more addresses from our filters.
448 void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
450 struct i40e_virtchnl_ether_addr_list *veal;
451 struct i40evf_mac_filter *f, *ftmp;
452 int len, i = 0, count = 0;
454 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
455 /* bail because we already have a command pending */
456 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
457 __func__, adapter->current_op);
460 list_for_each_entry(f, &adapter->mac_filter_list, list) {
465 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
468 adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
470 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
471 (count * sizeof(struct i40e_virtchnl_ether_addr));
472 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
473 dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request\n",
475 count = (I40EVF_MAX_AQ_BUF_SIZE -
476 sizeof(struct i40e_virtchnl_ether_addr_list)) /
477 sizeof(struct i40e_virtchnl_ether_addr);
478 len = I40EVF_MAX_AQ_BUF_SIZE;
480 veal = kzalloc(len, GFP_ATOMIC);
484 veal->vsi_id = adapter->vsi_res->vsi_id;
485 veal->num_elements = count;
486 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
488 ether_addr_copy(veal->list[i].addr, f->macaddr);
494 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
495 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
502 * @adapter: adapter structure
503 * @vlans: the VLANs to add
504 * @count: number of VLANs
506 * Request that the PF add one or more VLAN filters to our VSI.
508 void i40evf_add_vlans(struct i40evf_adapter *adapter)
510 struct i40e_virtchnl_vlan_filter_list *vvfl;
511 int len, i = 0, count = 0;
512 struct i40evf_vlan_filter *f;
514 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
515 /* bail because we already have a command pending */
516 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
517 __func__, adapter->current_op);
521 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
526 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
529 adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN;
531 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
532 (count * sizeof(u16));
533 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
534 dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request\n",
536 count = (I40EVF_MAX_AQ_BUF_SIZE -
537 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
539 len = I40EVF_MAX_AQ_BUF_SIZE;
541 vvfl = kzalloc(len, GFP_ATOMIC);
545 vvfl->vsi_id = adapter->vsi_res->vsi_id;
546 vvfl->num_elements = count;
547 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
549 vvfl->vlan_id[i] = f->vlan;
554 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
555 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
561 * @adapter: adapter structure
562 * @vlans: the VLANs to remove
563 * @count: number of VLANs
565 * Request that the PF remove one or more VLAN filters from our VSI.
567 void i40evf_del_vlans(struct i40evf_adapter *adapter)
569 struct i40e_virtchnl_vlan_filter_list *vvfl;
570 struct i40evf_vlan_filter *f, *ftmp;
571 int len, i = 0, count = 0;
573 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
574 /* bail because we already have a command pending */
575 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
576 __func__, adapter->current_op);
580 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
585 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
588 adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN;
590 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
591 (count * sizeof(u16));
592 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
593 dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request\n",
595 count = (I40EVF_MAX_AQ_BUF_SIZE -
596 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
598 len = I40EVF_MAX_AQ_BUF_SIZE;
600 vvfl = kzalloc(len, GFP_ATOMIC);
604 vvfl->vsi_id = adapter->vsi_res->vsi_id;
605 vvfl->num_elements = count;
606 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
608 vvfl->vlan_id[i] = f->vlan;
614 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
615 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
620 * i40evf_set_promiscuous
621 * @adapter: adapter structure
622 * @flags: bitmask to control unicast/multicast promiscuous.
624 * Request that the PF enable promiscuous mode for our VSI.
626 void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
628 struct i40e_virtchnl_promisc_info vpi;
630 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
631 /* bail because we already have a command pending */
632 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
633 __func__, adapter->current_op);
636 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
637 vpi.vsi_id = adapter->vsi_res->vsi_id;
639 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
640 (u8 *)&vpi, sizeof(vpi));
644 * i40evf_request_stats
645 * @adapter: adapter structure
647 * Request VSI statistics from PF.
649 void i40evf_request_stats(struct i40evf_adapter *adapter)
651 struct i40e_virtchnl_queue_select vqs;
653 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
654 /* no error message, this isn't crucial */
657 adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS;
658 vqs.vsi_id = adapter->vsi_res->vsi_id;
659 /* queue maps are ignored for this message - only the vsi is used */
660 if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS,
661 (u8 *)&vqs, sizeof(vqs)))
662 /* if the request failed, don't lock out others */
663 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
666 * i40evf_request_reset
667 * @adapter: adapter structure
669 * Request that the PF reset this VF. No response is expected.
671 void i40evf_request_reset(struct i40evf_adapter *adapter)
673 /* Don't check CURRENT_OP - this is always higher priority */
674 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
675 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
679 * i40evf_virtchnl_completion
680 * @adapter: adapter structure
681 * @v_opcode: opcode sent by PF
682 * @v_retval: retval sent by PF
683 * @msg: message sent by PF
684 * @msglen: message length
686 * Asynchronous completion function for admin queue messages. Rather than busy
687 * wait, we fire off our requests and assume that no errors will be returned.
688 * This function handles the reply messages.
690 void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
691 enum i40e_virtchnl_ops v_opcode,
692 i40e_status v_retval,
695 struct net_device *netdev = adapter->netdev;
697 if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
698 struct i40e_virtchnl_pf_event *vpe =
699 (struct i40e_virtchnl_pf_event *)msg;
700 switch (vpe->event) {
701 case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
703 vpe->event_data.link_event.link_status;
704 if (adapter->link_up && !netif_carrier_ok(netdev)) {
705 dev_info(&adapter->pdev->dev, "NIC Link is Up\n");
706 netif_carrier_on(netdev);
707 netif_tx_wake_all_queues(netdev);
708 } else if (!adapter->link_up) {
709 dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
710 netif_carrier_off(netdev);
711 netif_tx_stop_all_queues(netdev);
714 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
715 dev_info(&adapter->pdev->dev, "PF reset warning received\n");
716 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
717 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
718 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
719 schedule_work(&adapter->reset_task);
723 dev_err(&adapter->pdev->dev,
724 "%s: Unknown event %d from pf\n",
725 __func__, vpe->event);
731 dev_err(&adapter->pdev->dev, "%s: PF returned error %d (%s) to our request %d\n",
733 i40evf_stat_str(&adapter->hw, v_retval), v_opcode);
736 case I40E_VIRTCHNL_OP_GET_STATS: {
737 struct i40e_eth_stats *stats =
738 (struct i40e_eth_stats *)msg;
739 adapter->net_stats.rx_packets = stats->rx_unicast +
740 stats->rx_multicast +
742 adapter->net_stats.tx_packets = stats->tx_unicast +
743 stats->tx_multicast +
745 adapter->net_stats.rx_bytes = stats->rx_bytes;
746 adapter->net_stats.tx_bytes = stats->tx_bytes;
747 adapter->net_stats.tx_errors = stats->tx_errors;
748 adapter->net_stats.rx_dropped = stats->rx_discards;
749 adapter->net_stats.tx_dropped = stats->tx_discards;
750 adapter->current_stats = *stats;
753 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: {
754 u16 len = sizeof(struct i40e_virtchnl_vf_resource) +
756 sizeof(struct i40e_virtchnl_vsi_resource);
757 memcpy(adapter->vf_res, msg, min(msglen, len));
758 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
759 i40evf_process_config(adapter);
762 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
763 /* enable transmits */
764 i40evf_irq_enable(adapter, true);
765 netif_tx_start_all_queues(adapter->netdev);
766 netif_carrier_on(adapter->netdev);
768 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
769 i40evf_free_all_tx_resources(adapter);
770 i40evf_free_all_rx_resources(adapter);
772 case I40E_VIRTCHNL_OP_VERSION:
773 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
774 /* Don't display an error if we get these out of sequence.
775 * If the firmware needed to get kicked, we'll get these and
778 if (v_opcode != adapter->current_op)
782 if (v_opcode != adapter->current_op)
783 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
784 adapter->current_op, v_opcode);
786 } /* switch v_opcode */
787 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;