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 * The full GNU General Public License is included in this distribution in
16 * the file called "COPYING".
18 * Contact Information:
19 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
20 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
22 ******************************************************************************/
25 #include "i40e_prototype.h"
27 /* busy wait delay in msec */
28 #define I40EVF_BUSY_WAIT_DELAY 10
29 #define I40EVF_BUSY_WAIT_COUNT 50
33 * @adapter: adapter structure
34 * @op: virtual channel opcode
35 * @msg: pointer to message buffer
36 * @len: message length
38 * Send message to PF and print status if failure.
40 static int i40evf_send_pf_msg(struct i40evf_adapter *adapter,
41 enum i40e_virtchnl_ops op, u8 *msg, u16 len)
43 struct i40e_hw *hw = &adapter->hw;
46 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
47 return 0; /* nothing to see here, move along */
49 err = i40e_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
51 dev_err(&adapter->pdev->dev, "Unable to send opcode %d to PF, error %d, aq status %d\n",
52 op, err, hw->aq.asq_last_status);
58 * @adapter: adapter structure
60 * Send API version admin queue message to the PF. The reply is not checked
61 * in this function. Returns 0 if the message was successfully
62 * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
64 int i40evf_send_api_ver(struct i40evf_adapter *adapter)
66 struct i40e_virtchnl_version_info vvi;
68 vvi.major = I40E_VIRTCHNL_VERSION_MAJOR;
69 vvi.minor = I40E_VIRTCHNL_VERSION_MINOR;
71 return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_VERSION, (u8 *)&vvi,
76 * i40evf_verify_api_ver
77 * @adapter: adapter structure
79 * Compare API versions with the PF. Must be called after admin queue is
80 * initialized. Returns 0 if API versions match, -EIO if
81 * they do not, or I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty.
83 int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
85 struct i40e_virtchnl_version_info *pf_vvi;
86 struct i40e_hw *hw = &adapter->hw;
87 struct i40e_arq_event_info event;
90 event.msg_size = I40EVF_MAX_AQ_BUF_SIZE;
91 event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
97 err = i40evf_clean_arq_element(hw, &event, NULL);
98 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
101 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
107 if ((enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high) !=
108 I40E_VIRTCHNL_OP_VERSION) {
113 pf_vvi = (struct i40e_virtchnl_version_info *)event.msg_buf;
114 if ((pf_vvi->major != I40E_VIRTCHNL_VERSION_MAJOR) ||
115 (pf_vvi->minor != I40E_VIRTCHNL_VERSION_MINOR))
119 kfree(event.msg_buf);
125 * i40evf_send_vf_config_msg
126 * @adapter: adapter structure
128 * Send VF configuration request admin queue message to the PF. The reply
129 * is not checked in this function. Returns 0 if the message was
130 * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
132 int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
134 return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
139 * i40evf_get_vf_config
140 * @hw: pointer to the hardware structure
141 * @len: length of buffer
143 * Get VF configuration from PF and populate hw structure. Must be called after
144 * admin queue is initialized. Busy waits until response is received from PF,
145 * with maximum timeout. Response from PF is returned in the buffer for further
146 * processing by the caller.
148 int i40evf_get_vf_config(struct i40evf_adapter *adapter)
150 struct i40e_hw *hw = &adapter->hw;
151 struct i40e_arq_event_info event;
155 len = sizeof(struct i40e_virtchnl_vf_resource) +
156 I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
157 event.msg_size = len;
158 event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
159 if (!event.msg_buf) {
164 err = i40evf_clean_arq_element(hw, &event, NULL);
165 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
168 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
170 dev_err(&adapter->pdev->dev,
171 "%s: Error returned from PF, %d, %d\n", __func__,
172 le32_to_cpu(event.desc.cookie_high),
173 le32_to_cpu(event.desc.cookie_low));
178 if ((enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high) !=
179 I40E_VIRTCHNL_OP_GET_VF_RESOURCES) {
180 dev_err(&adapter->pdev->dev,
181 "%s: Invalid response from PF, %d, %d\n", __func__,
182 le32_to_cpu(event.desc.cookie_high),
183 le32_to_cpu(event.desc.cookie_low));
187 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_size, len));
189 i40e_vf_parse_hw_config(hw, adapter->vf_res);
191 kfree(event.msg_buf);
197 * i40evf_configure_queues
198 * @adapter: adapter structure
200 * Request that the PF set up our (previously allocated) queues.
202 void i40evf_configure_queues(struct i40evf_adapter *adapter)
204 struct i40e_virtchnl_vsi_queue_config_info *vqci;
205 struct i40e_virtchnl_queue_pair_info *vqpi;
206 int pairs = adapter->vsi_res->num_queue_pairs;
209 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
210 /* bail because we already have a command pending */
211 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
212 __func__, adapter->current_op);
215 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
216 len = sizeof(struct i40e_virtchnl_vsi_queue_config_info) +
217 (sizeof(struct i40e_virtchnl_queue_pair_info) * pairs);
218 vqci = kzalloc(len, GFP_ATOMIC);
220 dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
224 vqci->vsi_id = adapter->vsi_res->vsi_id;
225 vqci->num_queue_pairs = pairs;
227 /* Size check is not needed here - HW max is 16 queue pairs, and we
228 * can fit info for 31 of them into the AQ buffer before it overflows.
230 for (i = 0; i < pairs; i++) {
231 vqpi->txq.vsi_id = vqci->vsi_id;
232 vqpi->txq.queue_id = i;
233 vqpi->txq.ring_len = adapter->tx_rings[i]->count;
234 vqpi->txq.dma_ring_addr = adapter->tx_rings[i]->dma;
236 vqpi->rxq.vsi_id = vqci->vsi_id;
237 vqpi->rxq.queue_id = i;
238 vqpi->rxq.ring_len = adapter->rx_rings[i]->count;
239 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i]->dma;
240 vqpi->rxq.max_pkt_size = adapter->netdev->mtu
241 + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN;
242 vqpi->rxq.databuffer_size = adapter->rx_rings[i]->rx_buf_len;
246 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
249 adapter->aq_pending |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
250 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
254 * i40evf_enable_queues
255 * @adapter: adapter structure
257 * Request that the PF enable all of our queues.
259 void i40evf_enable_queues(struct i40evf_adapter *adapter)
261 struct i40e_virtchnl_queue_select vqs;
263 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
264 /* bail because we already have a command pending */
265 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
266 __func__, adapter->current_op);
269 adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
270 vqs.vsi_id = adapter->vsi_res->vsi_id;
271 vqs.tx_queues = (1 << adapter->vsi_res->num_queue_pairs) - 1;
272 vqs.rx_queues = vqs.tx_queues;
273 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
274 (u8 *)&vqs, sizeof(vqs));
275 adapter->aq_pending |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
276 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
280 * i40evf_disable_queues
281 * @adapter: adapter structure
283 * Request that the PF disable all of our queues.
285 void i40evf_disable_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_DISABLE_QUEUES;
296 vqs.vsi_id = adapter->vsi_res->vsi_id;
297 vqs.tx_queues = (1 << adapter->vsi_res->num_queue_pairs) - 1;
298 vqs.rx_queues = vqs.tx_queues;
299 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
300 (u8 *)&vqs, sizeof(vqs));
301 adapter->aq_pending |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
302 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
307 * @adapter: adapter structure
309 * Request that the PF map queues to interrupt vectors. Misc causes, including
310 * admin queue, are always mapped to vector 0.
312 void i40evf_map_queues(struct i40evf_adapter *adapter)
314 struct i40e_virtchnl_irq_map_info *vimi;
315 int v_idx, q_vectors, len;
316 struct i40e_q_vector *q_vector;
318 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
319 /* bail because we already have a command pending */
320 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
321 __func__, adapter->current_op);
324 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
326 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
328 len = sizeof(struct i40e_virtchnl_irq_map_info) +
329 (adapter->num_msix_vectors *
330 sizeof(struct i40e_virtchnl_vector_map));
331 vimi = kzalloc(len, GFP_ATOMIC);
333 dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
338 vimi->num_vectors = adapter->num_msix_vectors;
339 /* Queue vectors first */
340 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
341 q_vector = adapter->q_vector[v_idx];
342 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
343 vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
344 vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
345 vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
347 /* Misc vector last - this is only for AdminQ messages */
348 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
349 vimi->vecmap[v_idx].vector_id = 0;
350 vimi->vecmap[v_idx].txq_map = 0;
351 vimi->vecmap[v_idx].rxq_map = 0;
353 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
356 adapter->aq_pending |= I40EVF_FLAG_AQ_MAP_VECTORS;
357 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
361 * i40evf_add_ether_addrs
362 * @adapter: adapter structure
363 * @addrs: the MAC address filters to add (contiguous)
364 * @count: number of filters
366 * Request that the PF add one or more addresses to our filters.
368 void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
370 struct i40e_virtchnl_ether_addr_list *veal;
371 int len, i = 0, count = 0;
372 struct i40evf_mac_filter *f;
374 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
375 /* bail because we already have a command pending */
376 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
377 __func__, adapter->current_op);
380 list_for_each_entry(f, &adapter->mac_filter_list, list) {
385 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
388 adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
390 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
391 (count * sizeof(struct i40e_virtchnl_ether_addr));
392 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
393 dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request.\n",
395 count = (I40EVF_MAX_AQ_BUF_SIZE -
396 sizeof(struct i40e_virtchnl_ether_addr_list)) /
397 sizeof(struct i40e_virtchnl_ether_addr);
398 len = I40EVF_MAX_AQ_BUF_SIZE;
401 veal = kzalloc(len, GFP_ATOMIC);
403 dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
407 veal->vsi_id = adapter->vsi_res->vsi_id;
408 veal->num_elements = count;
409 list_for_each_entry(f, &adapter->mac_filter_list, list) {
411 memcpy(veal->list[i].addr, f->macaddr, ETH_ALEN);
416 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
419 adapter->aq_pending |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
420 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
425 * i40evf_del_ether_addrs
426 * @adapter: adapter structure
427 * @addrs: the MAC address filters to remove (contiguous)
428 * @count: number of filtes
430 * Request that the PF remove one or more addresses from our filters.
432 void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
434 struct i40e_virtchnl_ether_addr_list *veal;
435 struct i40evf_mac_filter *f, *ftmp;
436 int len, i = 0, count = 0;
438 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
439 /* bail because we already have a command pending */
440 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
441 __func__, adapter->current_op);
444 list_for_each_entry(f, &adapter->mac_filter_list, list) {
449 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
452 adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
454 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
455 (count * sizeof(struct i40e_virtchnl_ether_addr));
456 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
457 dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request.\n",
459 count = (I40EVF_MAX_AQ_BUF_SIZE -
460 sizeof(struct i40e_virtchnl_ether_addr_list)) /
461 sizeof(struct i40e_virtchnl_ether_addr);
462 len = I40EVF_MAX_AQ_BUF_SIZE;
464 veal = kzalloc(len, GFP_ATOMIC);
466 dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
470 veal->vsi_id = adapter->vsi_res->vsi_id;
471 veal->num_elements = count;
472 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
474 memcpy(veal->list[i].addr, f->macaddr, ETH_ALEN);
480 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
483 adapter->aq_pending |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
484 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
489 * @adapter: adapter structure
490 * @vlans: the VLANs to add
491 * @count: number of VLANs
493 * Request that the PF add one or more VLAN filters to our VSI.
495 void i40evf_add_vlans(struct i40evf_adapter *adapter)
497 struct i40e_virtchnl_vlan_filter_list *vvfl;
498 int len, i = 0, count = 0;
499 struct i40evf_vlan_filter *f;
501 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
502 /* bail because we already have a command pending */
503 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
504 __func__, adapter->current_op);
508 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
513 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
516 adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN;
518 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
519 (count * sizeof(u16));
520 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
521 dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request.\n",
523 count = (I40EVF_MAX_AQ_BUF_SIZE -
524 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
526 len = I40EVF_MAX_AQ_BUF_SIZE;
528 vvfl = kzalloc(len, GFP_ATOMIC);
530 dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
534 vvfl->vsi_id = adapter->vsi_res->vsi_id;
535 vvfl->num_elements = count;
536 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
538 vvfl->vlan_id[i] = f->vlan;
543 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
545 adapter->aq_pending |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
546 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
551 * @adapter: adapter structure
552 * @vlans: the VLANs to remove
553 * @count: number of VLANs
555 * Request that the PF remove one or more VLAN filters from our VSI.
557 void i40evf_del_vlans(struct i40evf_adapter *adapter)
559 struct i40e_virtchnl_vlan_filter_list *vvfl;
560 struct i40evf_vlan_filter *f, *ftmp;
561 int len, i = 0, count = 0;
563 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
564 /* bail because we already have a command pending */
565 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
566 __func__, adapter->current_op);
570 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
575 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
578 adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN;
580 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
581 (count * sizeof(u16));
582 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
583 dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request.\n",
585 count = (I40EVF_MAX_AQ_BUF_SIZE -
586 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
588 len = I40EVF_MAX_AQ_BUF_SIZE;
590 vvfl = kzalloc(len, GFP_ATOMIC);
592 dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
596 vvfl->vsi_id = adapter->vsi_res->vsi_id;
597 vvfl->num_elements = count;
598 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
600 vvfl->vlan_id[i] = f->vlan;
606 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
608 adapter->aq_pending |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
609 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
613 * i40evf_set_promiscuous
614 * @adapter: adapter structure
615 * @flags: bitmask to control unicast/multicast promiscuous.
617 * Request that the PF enable promiscuous mode for our VSI.
619 void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
621 struct i40e_virtchnl_promisc_info vpi;
623 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
624 /* bail because we already have a command pending */
625 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
626 __func__, adapter->current_op);
629 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
630 vpi.vsi_id = adapter->vsi_res->vsi_id;
632 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
633 (u8 *)&vpi, sizeof(vpi));
637 * i40evf_request_stats
638 * @adapter: adapter structure
640 * Request VSI statistics from PF.
642 void i40evf_request_stats(struct i40evf_adapter *adapter)
644 struct i40e_virtchnl_queue_select vqs;
645 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
646 /* no error message, this isn't crucial */
649 adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS;
650 vqs.vsi_id = adapter->vsi_res->vsi_id;
651 /* queue maps are ignored for this message - only the vsi is used */
652 if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS,
653 (u8 *)&vqs, sizeof(vqs)))
654 /* if the request failed, don't lock out others */
655 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
658 * i40evf_request_reset
659 * @adapter: adapter structure
661 * Request that the PF reset this VF. No response is expected.
663 void i40evf_request_reset(struct i40evf_adapter *adapter)
665 /* Don't check CURRENT_OP - this is always higher priority */
666 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
667 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
671 * i40evf_virtchnl_completion
672 * @adapter: adapter structure
673 * @v_opcode: opcode sent by PF
674 * @v_retval: retval sent by PF
675 * @msg: message sent by PF
676 * @msglen: message length
678 * Asynchronous completion function for admin queue messages. Rather than busy
679 * wait, we fire off our requests and assume that no errors will be returned.
680 * This function handles the reply messages.
682 void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
683 enum i40e_virtchnl_ops v_opcode,
684 i40e_status v_retval,
687 struct net_device *netdev = adapter->netdev;
689 if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
690 struct i40e_virtchnl_pf_event *vpe =
691 (struct i40e_virtchnl_pf_event *)msg;
692 switch (vpe->event) {
693 case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
695 vpe->event_data.link_event.link_status;
696 if (adapter->link_up && !netif_carrier_ok(netdev)) {
697 dev_info(&adapter->pdev->dev, "NIC Link is Up\n");
698 netif_carrier_on(netdev);
699 netif_tx_wake_all_queues(netdev);
700 } else if (!adapter->link_up) {
701 dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
702 netif_carrier_off(netdev);
703 netif_tx_stop_all_queues(netdev);
706 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
707 dev_info(&adapter->pdev->dev, "PF reset warning received\n");
708 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
709 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
710 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
711 schedule_work(&adapter->reset_task);
715 dev_err(&adapter->pdev->dev,
716 "%s: Unknown event %d from pf\n",
717 __func__, vpe->event);
723 if (v_opcode != adapter->current_op) {
724 dev_err(&adapter->pdev->dev, "%s: Pending op is %d, received %d.\n",
725 __func__, adapter->current_op, v_opcode);
726 /* We're probably completely screwed at this point, but clear
727 * the current op and try to carry on....
729 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
733 dev_err(&adapter->pdev->dev, "%s: PF returned error %d to our request %d!\n",
734 __func__, v_retval, v_opcode);
737 case I40E_VIRTCHNL_OP_GET_STATS: {
738 struct i40e_eth_stats *stats =
739 (struct i40e_eth_stats *)msg;
740 adapter->net_stats.rx_packets = stats->rx_unicast +
741 stats->rx_multicast +
743 adapter->net_stats.tx_packets = stats->tx_unicast +
744 stats->tx_multicast +
746 adapter->net_stats.rx_bytes = stats->rx_bytes;
747 adapter->net_stats.tx_bytes = stats->tx_bytes;
748 adapter->net_stats.rx_errors = stats->rx_errors;
749 adapter->net_stats.tx_errors = stats->tx_errors;
750 adapter->net_stats.rx_dropped = stats->rx_missed;
751 adapter->net_stats.tx_dropped = stats->tx_discards;
752 adapter->current_stats = *stats;
755 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
756 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ADD_MAC_FILTER);
758 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
759 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DEL_MAC_FILTER);
761 case I40E_VIRTCHNL_OP_ADD_VLAN:
762 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ADD_VLAN_FILTER);
764 case I40E_VIRTCHNL_OP_DEL_VLAN:
765 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DEL_VLAN_FILTER);
767 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
768 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ENABLE_QUEUES);
769 /* enable transmits */
770 i40evf_irq_enable(adapter, true);
771 netif_tx_start_all_queues(adapter->netdev);
772 netif_carrier_on(adapter->netdev);
774 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
775 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DISABLE_QUEUES);
777 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
778 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_CONFIGURE_QUEUES);
780 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
781 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_MAP_VECTORS);
784 dev_warn(&adapter->pdev->dev, "%s: Received unexpected message %d from PF.\n",
787 } /* switch v_opcode */
788 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;