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, error %d, aq status %d\n",
55 op, err, hw->aq.asq_last_status);
61 * @adapter: adapter structure
63 * Send API version admin queue message to the PF. The reply is not checked
64 * in this function. Returns 0 if the message was successfully
65 * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
67 int i40evf_send_api_ver(struct i40evf_adapter *adapter)
69 struct i40e_virtchnl_version_info vvi;
71 vvi.major = I40E_VIRTCHNL_VERSION_MAJOR;
72 vvi.minor = I40E_VIRTCHNL_VERSION_MINOR;
74 return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_VERSION, (u8 *)&vvi,
79 * i40evf_verify_api_ver
80 * @adapter: adapter structure
82 * Compare API versions with the PF. Must be called after admin queue is
83 * initialized. Returns 0 if API versions match, -EIO if they do not,
84 * I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
85 * from the firmware are propagated.
87 int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
89 struct i40e_virtchnl_version_info *pf_vvi;
90 struct i40e_hw *hw = &adapter->hw;
91 struct i40e_arq_event_info event;
94 event.msg_size = I40EVF_MAX_AQ_BUF_SIZE;
95 event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
101 err = i40evf_clean_arq_element(hw, &event, NULL);
102 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
105 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
109 if ((enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high) !=
110 I40E_VIRTCHNL_OP_VERSION) {
111 dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n",
112 le32_to_cpu(event.desc.cookie_high));
117 pf_vvi = (struct i40e_virtchnl_version_info *)event.msg_buf;
118 if ((pf_vvi->major != I40E_VIRTCHNL_VERSION_MAJOR) ||
119 (pf_vvi->minor != I40E_VIRTCHNL_VERSION_MINOR))
123 kfree(event.msg_buf);
129 * i40evf_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 I40E_ADMIN_QUEUE_ERROR_ statuses if not.
136 int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
138 return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
143 * i40evf_get_vf_config
144 * @hw: pointer to the hardware structure
145 * @len: length of buffer
147 * Get VF configuration from PF and populate hw structure. Must be called after
148 * admin queue is initialized. Busy waits until response is received from PF,
149 * with maximum timeout. Response from PF is returned in the buffer for further
150 * processing by the caller.
152 int i40evf_get_vf_config(struct i40evf_adapter *adapter)
154 struct i40e_hw *hw = &adapter->hw;
155 struct i40e_arq_event_info event;
159 len = sizeof(struct i40e_virtchnl_vf_resource) +
160 I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
161 event.msg_size = len;
162 event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
163 if (!event.msg_buf) {
168 err = i40evf_clean_arq_element(hw, &event, NULL);
169 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
172 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
174 dev_err(&adapter->pdev->dev,
175 "%s: Error returned from PF, %d, %d\n", __func__,
176 le32_to_cpu(event.desc.cookie_high),
177 le32_to_cpu(event.desc.cookie_low));
182 if ((enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high) !=
183 I40E_VIRTCHNL_OP_GET_VF_RESOURCES) {
184 dev_err(&adapter->pdev->dev,
185 "%s: Invalid response from PF, %d, %d\n", __func__,
186 le32_to_cpu(event.desc.cookie_high),
187 le32_to_cpu(event.desc.cookie_low));
191 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_size, len));
193 i40e_vf_parse_hw_config(hw, adapter->vf_res);
195 kfree(event.msg_buf);
201 * i40evf_configure_queues
202 * @adapter: adapter structure
204 * Request that the PF set up our (previously allocated) queues.
206 void i40evf_configure_queues(struct i40evf_adapter *adapter)
208 struct i40e_virtchnl_vsi_queue_config_info *vqci;
209 struct i40e_virtchnl_queue_pair_info *vqpi;
210 int pairs = adapter->vsi_res->num_queue_pairs;
213 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
214 /* bail because we already have a command pending */
215 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
216 __func__, adapter->current_op);
219 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
220 len = sizeof(struct i40e_virtchnl_vsi_queue_config_info) +
221 (sizeof(struct i40e_virtchnl_queue_pair_info) * pairs);
222 vqci = kzalloc(len, GFP_ATOMIC);
226 vqci->vsi_id = adapter->vsi_res->vsi_id;
227 vqci->num_queue_pairs = pairs;
229 /* Size check is not needed here - HW max is 16 queue pairs, and we
230 * can fit info for 31 of them into the AQ buffer before it overflows.
232 for (i = 0; i < pairs; i++) {
233 vqpi->txq.vsi_id = vqci->vsi_id;
234 vqpi->txq.queue_id = i;
235 vqpi->txq.ring_len = adapter->tx_rings[i]->count;
236 vqpi->txq.dma_ring_addr = adapter->tx_rings[i]->dma;
237 vqpi->txq.headwb_enabled = 1;
238 vqpi->txq.dma_headwb_addr = vqpi->txq.dma_ring_addr +
239 (vqpi->txq.ring_len * sizeof(struct i40e_tx_desc));
241 vqpi->rxq.vsi_id = vqci->vsi_id;
242 vqpi->rxq.queue_id = i;
243 vqpi->rxq.ring_len = adapter->rx_rings[i]->count;
244 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i]->dma;
245 vqpi->rxq.max_pkt_size = adapter->netdev->mtu
246 + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN;
247 vqpi->rxq.databuffer_size = adapter->rx_rings[i]->rx_buf_len;
251 adapter->aq_pending |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
252 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
253 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
259 * i40evf_enable_queues
260 * @adapter: adapter structure
262 * Request that the PF enable all of our queues.
264 void i40evf_enable_queues(struct i40evf_adapter *adapter)
266 struct i40e_virtchnl_queue_select vqs;
268 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
269 /* bail because we already have a command pending */
270 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
271 __func__, adapter->current_op);
274 adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
275 vqs.vsi_id = adapter->vsi_res->vsi_id;
276 vqs.tx_queues = (1 << adapter->vsi_res->num_queue_pairs) - 1;
277 vqs.rx_queues = vqs.tx_queues;
278 adapter->aq_pending |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
279 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
280 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
281 (u8 *)&vqs, sizeof(vqs));
285 * i40evf_disable_queues
286 * @adapter: adapter structure
288 * Request that the PF disable all of our queues.
290 void i40evf_disable_queues(struct i40evf_adapter *adapter)
292 struct i40e_virtchnl_queue_select vqs;
294 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
295 /* bail because we already have a command pending */
296 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
297 __func__, adapter->current_op);
300 adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
301 vqs.vsi_id = adapter->vsi_res->vsi_id;
302 vqs.tx_queues = (1 << adapter->vsi_res->num_queue_pairs) - 1;
303 vqs.rx_queues = vqs.tx_queues;
304 adapter->aq_pending |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
305 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
306 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
307 (u8 *)&vqs, sizeof(vqs));
312 * @adapter: adapter structure
314 * Request that the PF map queues to interrupt vectors. Misc causes, including
315 * admin queue, are always mapped to vector 0.
317 void i40evf_map_queues(struct i40evf_adapter *adapter)
319 struct i40e_virtchnl_irq_map_info *vimi;
320 int v_idx, q_vectors, len;
321 struct i40e_q_vector *q_vector;
323 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
324 /* bail because we already have a command pending */
325 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
326 __func__, adapter->current_op);
329 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
331 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
333 len = sizeof(struct i40e_virtchnl_irq_map_info) +
334 (adapter->num_msix_vectors *
335 sizeof(struct i40e_virtchnl_vector_map));
336 vimi = kzalloc(len, GFP_ATOMIC);
340 vimi->num_vectors = adapter->num_msix_vectors;
341 /* Queue vectors first */
342 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
343 q_vector = adapter->q_vector[v_idx];
344 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
345 vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
346 vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
347 vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
349 /* Misc vector last - this is only for AdminQ messages */
350 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
351 vimi->vecmap[v_idx].vector_id = 0;
352 vimi->vecmap[v_idx].txq_map = 0;
353 vimi->vecmap[v_idx].rxq_map = 0;
355 adapter->aq_pending |= I40EVF_FLAG_AQ_MAP_VECTORS;
356 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
357 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
363 * i40evf_add_ether_addrs
364 * @adapter: adapter structure
365 * @addrs: the MAC address filters to add (contiguous)
366 * @count: number of filters
368 * Request that the PF add one or more addresses to our filters.
370 void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
372 struct i40e_virtchnl_ether_addr_list *veal;
373 int len, i = 0, count = 0;
374 struct i40evf_mac_filter *f;
376 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
377 /* bail because we already have a command pending */
378 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
379 __func__, adapter->current_op);
382 list_for_each_entry(f, &adapter->mac_filter_list, list) {
387 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
390 adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
392 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
393 (count * sizeof(struct i40e_virtchnl_ether_addr));
394 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
395 dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request\n",
397 count = (I40EVF_MAX_AQ_BUF_SIZE -
398 sizeof(struct i40e_virtchnl_ether_addr_list)) /
399 sizeof(struct i40e_virtchnl_ether_addr);
400 len = I40EVF_MAX_AQ_BUF_SIZE;
403 veal = kzalloc(len, GFP_ATOMIC);
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 ether_addr_copy(veal->list[i].addr, f->macaddr);
416 adapter->aq_pending |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
417 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
418 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
424 * i40evf_del_ether_addrs
425 * @adapter: adapter structure
426 * @addrs: the MAC address filters to remove (contiguous)
427 * @count: number of filtes
429 * Request that the PF remove one or more addresses from our filters.
431 void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
433 struct i40e_virtchnl_ether_addr_list *veal;
434 struct i40evf_mac_filter *f, *ftmp;
435 int len, i = 0, count = 0;
437 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
438 /* bail because we already have a command pending */
439 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
440 __func__, adapter->current_op);
443 list_for_each_entry(f, &adapter->mac_filter_list, list) {
448 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
451 adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
453 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
454 (count * sizeof(struct i40e_virtchnl_ether_addr));
455 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
456 dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request\n",
458 count = (I40EVF_MAX_AQ_BUF_SIZE -
459 sizeof(struct i40e_virtchnl_ether_addr_list)) /
460 sizeof(struct i40e_virtchnl_ether_addr);
461 len = I40EVF_MAX_AQ_BUF_SIZE;
463 veal = kzalloc(len, GFP_ATOMIC);
467 veal->vsi_id = adapter->vsi_res->vsi_id;
468 veal->num_elements = count;
469 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
471 ether_addr_copy(veal->list[i].addr, f->macaddr);
477 adapter->aq_pending |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
478 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
479 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
486 * @adapter: adapter structure
487 * @vlans: the VLANs to add
488 * @count: number of VLANs
490 * Request that the PF add one or more VLAN filters to our VSI.
492 void i40evf_add_vlans(struct i40evf_adapter *adapter)
494 struct i40e_virtchnl_vlan_filter_list *vvfl;
495 int len, i = 0, count = 0;
496 struct i40evf_vlan_filter *f;
498 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
499 /* bail because we already have a command pending */
500 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
501 __func__, adapter->current_op);
505 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
510 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
513 adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN;
515 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
516 (count * sizeof(u16));
517 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
518 dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request\n",
520 count = (I40EVF_MAX_AQ_BUF_SIZE -
521 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
523 len = I40EVF_MAX_AQ_BUF_SIZE;
525 vvfl = kzalloc(len, GFP_ATOMIC);
529 vvfl->vsi_id = adapter->vsi_res->vsi_id;
530 vvfl->num_elements = count;
531 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
533 vvfl->vlan_id[i] = f->vlan;
538 adapter->aq_pending |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
539 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
540 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
546 * @adapter: adapter structure
547 * @vlans: the VLANs to remove
548 * @count: number of VLANs
550 * Request that the PF remove one or more VLAN filters from our VSI.
552 void i40evf_del_vlans(struct i40evf_adapter *adapter)
554 struct i40e_virtchnl_vlan_filter_list *vvfl;
555 struct i40evf_vlan_filter *f, *ftmp;
556 int len, i = 0, count = 0;
558 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
559 /* bail because we already have a command pending */
560 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
561 __func__, adapter->current_op);
565 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
570 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
573 adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN;
575 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
576 (count * sizeof(u16));
577 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
578 dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request\n",
580 count = (I40EVF_MAX_AQ_BUF_SIZE -
581 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
583 len = I40EVF_MAX_AQ_BUF_SIZE;
585 vvfl = kzalloc(len, GFP_ATOMIC);
589 vvfl->vsi_id = adapter->vsi_res->vsi_id;
590 vvfl->num_elements = count;
591 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
593 vvfl->vlan_id[i] = f->vlan;
599 adapter->aq_pending |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
600 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
601 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
606 * i40evf_set_promiscuous
607 * @adapter: adapter structure
608 * @flags: bitmask to control unicast/multicast promiscuous.
610 * Request that the PF enable promiscuous mode for our VSI.
612 void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
614 struct i40e_virtchnl_promisc_info vpi;
616 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
617 /* bail because we already have a command pending */
618 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
619 __func__, adapter->current_op);
622 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
623 vpi.vsi_id = adapter->vsi_res->vsi_id;
625 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
626 (u8 *)&vpi, sizeof(vpi));
630 * i40evf_request_stats
631 * @adapter: adapter structure
633 * Request VSI statistics from PF.
635 void i40evf_request_stats(struct i40evf_adapter *adapter)
637 struct i40e_virtchnl_queue_select vqs;
638 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
639 /* no error message, this isn't crucial */
642 adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS;
643 vqs.vsi_id = adapter->vsi_res->vsi_id;
644 /* queue maps are ignored for this message - only the vsi is used */
645 if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS,
646 (u8 *)&vqs, sizeof(vqs)))
647 /* if the request failed, don't lock out others */
648 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
651 * i40evf_request_reset
652 * @adapter: adapter structure
654 * Request that the PF reset this VF. No response is expected.
656 void i40evf_request_reset(struct i40evf_adapter *adapter)
658 /* Don't check CURRENT_OP - this is always higher priority */
659 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
660 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
664 * i40evf_virtchnl_completion
665 * @adapter: adapter structure
666 * @v_opcode: opcode sent by PF
667 * @v_retval: retval sent by PF
668 * @msg: message sent by PF
669 * @msglen: message length
671 * Asynchronous completion function for admin queue messages. Rather than busy
672 * wait, we fire off our requests and assume that no errors will be returned.
673 * This function handles the reply messages.
675 void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
676 enum i40e_virtchnl_ops v_opcode,
677 i40e_status v_retval,
680 struct net_device *netdev = adapter->netdev;
682 if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
683 struct i40e_virtchnl_pf_event *vpe =
684 (struct i40e_virtchnl_pf_event *)msg;
685 switch (vpe->event) {
686 case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
688 vpe->event_data.link_event.link_status;
689 if (adapter->link_up && !netif_carrier_ok(netdev)) {
690 dev_info(&adapter->pdev->dev, "NIC Link is Up\n");
691 netif_carrier_on(netdev);
692 netif_tx_wake_all_queues(netdev);
693 } else if (!adapter->link_up) {
694 dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
695 netif_carrier_off(netdev);
696 netif_tx_stop_all_queues(netdev);
699 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
700 dev_info(&adapter->pdev->dev, "PF reset warning received\n");
701 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
702 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
703 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
704 schedule_work(&adapter->reset_task);
708 dev_err(&adapter->pdev->dev,
709 "%s: Unknown event %d from pf\n",
710 __func__, vpe->event);
716 if (v_opcode != adapter->current_op) {
717 dev_err(&adapter->pdev->dev, "%s: Pending op is %d, received %d\n",
718 __func__, adapter->current_op, v_opcode);
719 /* We're probably completely screwed at this point, but clear
720 * the current op and try to carry on....
722 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
726 dev_err(&adapter->pdev->dev, "%s: PF returned error %d to our request %d\n",
727 __func__, v_retval, v_opcode);
730 case I40E_VIRTCHNL_OP_GET_STATS: {
731 struct i40e_eth_stats *stats =
732 (struct i40e_eth_stats *)msg;
733 adapter->net_stats.rx_packets = stats->rx_unicast +
734 stats->rx_multicast +
736 adapter->net_stats.tx_packets = stats->tx_unicast +
737 stats->tx_multicast +
739 adapter->net_stats.rx_bytes = stats->rx_bytes;
740 adapter->net_stats.tx_bytes = stats->tx_bytes;
741 adapter->net_stats.tx_errors = stats->tx_errors;
742 adapter->net_stats.rx_dropped = stats->rx_discards;
743 adapter->net_stats.tx_dropped = stats->tx_discards;
744 adapter->current_stats = *stats;
747 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
748 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ADD_MAC_FILTER);
750 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
751 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DEL_MAC_FILTER);
753 case I40E_VIRTCHNL_OP_ADD_VLAN:
754 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ADD_VLAN_FILTER);
756 case I40E_VIRTCHNL_OP_DEL_VLAN:
757 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DEL_VLAN_FILTER);
759 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
760 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ENABLE_QUEUES);
761 /* enable transmits */
762 i40evf_irq_enable(adapter, true);
763 netif_tx_start_all_queues(adapter->netdev);
764 netif_carrier_on(adapter->netdev);
766 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
767 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DISABLE_QUEUES);
769 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
770 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_CONFIGURE_QUEUES);
772 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
773 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_MAP_VECTORS);
776 dev_warn(&adapter->pdev->dev, "%s: Received unexpected message %d from PF\n",
779 } /* switch v_opcode */
780 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;