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_PF |
158 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ |
159 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
160 I40E_VIRTCHNL_VF_OFFLOAD_VLAN |
161 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
162 I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
164 adapter->current_op = I40E_VIRTCHNL_OP_GET_VF_RESOURCES;
165 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
166 if (PF_IS_V11(adapter))
167 return i40evf_send_pf_msg(adapter,
168 I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
169 (u8 *)&caps, sizeof(caps));
171 return i40evf_send_pf_msg(adapter,
172 I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
177 * i40evf_get_vf_config
178 * @hw: pointer to the hardware structure
179 * @len: length of buffer
181 * Get VF configuration from PF and populate hw structure. Must be called after
182 * admin queue is initialized. Busy waits until response is received from PF,
183 * with maximum timeout. Response from PF is returned in the buffer for further
184 * processing by the caller.
186 int i40evf_get_vf_config(struct i40evf_adapter *adapter)
188 struct i40e_hw *hw = &adapter->hw;
189 struct i40e_arq_event_info event;
190 enum i40e_virtchnl_ops op;
194 len = sizeof(struct i40e_virtchnl_vf_resource) +
195 I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
197 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
198 if (!event.msg_buf) {
204 /* When the AQ is empty, i40evf_clean_arq_element will return
205 * nonzero and this loop will terminate.
207 err = i40evf_clean_arq_element(hw, &event, NULL);
211 (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
212 if (op == I40E_VIRTCHNL_OP_GET_VF_RESOURCES)
216 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
217 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
219 i40e_vf_parse_hw_config(hw, adapter->vf_res);
221 kfree(event.msg_buf);
227 * i40evf_configure_queues
228 * @adapter: adapter structure
230 * Request that the PF set up our (previously allocated) queues.
232 void i40evf_configure_queues(struct i40evf_adapter *adapter)
234 struct i40e_virtchnl_vsi_queue_config_info *vqci;
235 struct i40e_virtchnl_queue_pair_info *vqpi;
236 int pairs = adapter->num_active_queues;
239 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
240 /* bail because we already have a command pending */
241 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
242 adapter->current_op);
245 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
246 len = sizeof(struct i40e_virtchnl_vsi_queue_config_info) +
247 (sizeof(struct i40e_virtchnl_queue_pair_info) * pairs);
248 vqci = kzalloc(len, GFP_KERNEL);
252 vqci->vsi_id = adapter->vsi_res->vsi_id;
253 vqci->num_queue_pairs = pairs;
255 /* Size check is not needed here - HW max is 16 queue pairs, and we
256 * can fit info for 31 of them into the AQ buffer before it overflows.
258 for (i = 0; i < pairs; i++) {
259 vqpi->txq.vsi_id = vqci->vsi_id;
260 vqpi->txq.queue_id = i;
261 vqpi->txq.ring_len = adapter->tx_rings[i].count;
262 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
263 vqpi->txq.headwb_enabled = 1;
264 vqpi->txq.dma_headwb_addr = vqpi->txq.dma_ring_addr +
265 (vqpi->txq.ring_len * sizeof(struct i40e_tx_desc));
267 vqpi->rxq.vsi_id = vqci->vsi_id;
268 vqpi->rxq.queue_id = i;
269 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
270 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
271 vqpi->rxq.max_pkt_size = adapter->netdev->mtu
272 + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN;
273 vqpi->rxq.databuffer_size = adapter->rx_rings[i].rx_buf_len;
277 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
278 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
284 * i40evf_enable_queues
285 * @adapter: adapter structure
287 * Request that the PF enable all of our queues.
289 void i40evf_enable_queues(struct i40evf_adapter *adapter)
291 struct i40e_virtchnl_queue_select vqs;
293 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
294 /* bail because we already have a command pending */
295 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
296 adapter->current_op);
299 adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
300 vqs.vsi_id = adapter->vsi_res->vsi_id;
301 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
302 vqs.rx_queues = vqs.tx_queues;
303 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
304 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
305 (u8 *)&vqs, sizeof(vqs));
309 * i40evf_disable_queues
310 * @adapter: adapter structure
312 * Request that the PF disable all of our queues.
314 void i40evf_disable_queues(struct i40evf_adapter *adapter)
316 struct i40e_virtchnl_queue_select vqs;
318 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
319 /* bail because we already have a command pending */
320 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
321 adapter->current_op);
324 adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
325 vqs.vsi_id = adapter->vsi_res->vsi_id;
326 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
327 vqs.rx_queues = vqs.tx_queues;
328 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
329 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
330 (u8 *)&vqs, sizeof(vqs));
335 * @adapter: adapter structure
337 * Request that the PF map queues to interrupt vectors. Misc causes, including
338 * admin queue, are always mapped to vector 0.
340 void i40evf_map_queues(struct i40evf_adapter *adapter)
342 struct i40e_virtchnl_irq_map_info *vimi;
343 int v_idx, q_vectors, len;
344 struct i40e_q_vector *q_vector;
346 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
347 /* bail because we already have a command pending */
348 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
349 adapter->current_op);
352 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
354 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
356 len = sizeof(struct i40e_virtchnl_irq_map_info) +
357 (adapter->num_msix_vectors *
358 sizeof(struct i40e_virtchnl_vector_map));
359 vimi = kzalloc(len, GFP_KERNEL);
363 vimi->num_vectors = adapter->num_msix_vectors;
364 /* Queue vectors first */
365 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
366 q_vector = adapter->q_vectors + v_idx;
367 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
368 vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
369 vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
370 vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
372 /* Misc vector last - this is only for AdminQ messages */
373 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
374 vimi->vecmap[v_idx].vector_id = 0;
375 vimi->vecmap[v_idx].txq_map = 0;
376 vimi->vecmap[v_idx].rxq_map = 0;
378 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
379 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
385 * i40evf_add_ether_addrs
386 * @adapter: adapter structure
387 * @addrs: the MAC address filters to add (contiguous)
388 * @count: number of filters
390 * Request that the PF add one or more addresses to our filters.
392 void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
394 struct i40e_virtchnl_ether_addr_list *veal;
395 int len, i = 0, count = 0;
396 struct i40evf_mac_filter *f;
399 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
400 /* bail because we already have a command pending */
401 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
402 adapter->current_op);
405 list_for_each_entry(f, &adapter->mac_filter_list, list) {
410 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
413 adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
415 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
416 (count * sizeof(struct i40e_virtchnl_ether_addr));
417 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
418 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
419 count = (I40EVF_MAX_AQ_BUF_SIZE -
420 sizeof(struct i40e_virtchnl_ether_addr_list)) /
421 sizeof(struct i40e_virtchnl_ether_addr);
422 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
423 (count * sizeof(struct i40e_virtchnl_ether_addr));
427 veal = kzalloc(len, GFP_KERNEL);
431 veal->vsi_id = adapter->vsi_res->vsi_id;
432 veal->num_elements = count;
433 list_for_each_entry(f, &adapter->mac_filter_list, list) {
435 ether_addr_copy(veal->list[i].addr, f->macaddr);
443 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
444 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
450 * i40evf_del_ether_addrs
451 * @adapter: adapter structure
452 * @addrs: the MAC address filters to remove (contiguous)
453 * @count: number of filtes
455 * Request that the PF remove one or more addresses from our filters.
457 void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
459 struct i40e_virtchnl_ether_addr_list *veal;
460 struct i40evf_mac_filter *f, *ftmp;
461 int len, i = 0, count = 0;
464 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
465 /* bail because we already have a command pending */
466 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
467 adapter->current_op);
470 list_for_each_entry(f, &adapter->mac_filter_list, list) {
475 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
478 adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
480 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
481 (count * sizeof(struct i40e_virtchnl_ether_addr));
482 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
483 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
484 count = (I40EVF_MAX_AQ_BUF_SIZE -
485 sizeof(struct i40e_virtchnl_ether_addr_list)) /
486 sizeof(struct i40e_virtchnl_ether_addr);
487 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
488 (count * sizeof(struct i40e_virtchnl_ether_addr));
491 veal = kzalloc(len, GFP_KERNEL);
495 veal->vsi_id = adapter->vsi_res->vsi_id;
496 veal->num_elements = count;
497 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
499 ether_addr_copy(veal->list[i].addr, f->macaddr);
508 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
509 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
516 * @adapter: adapter structure
517 * @vlans: the VLANs to add
518 * @count: number of VLANs
520 * Request that the PF add one or more VLAN filters to our VSI.
522 void i40evf_add_vlans(struct i40evf_adapter *adapter)
524 struct i40e_virtchnl_vlan_filter_list *vvfl;
525 int len, i = 0, count = 0;
526 struct i40evf_vlan_filter *f;
529 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
530 /* bail because we already have a command pending */
531 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
532 adapter->current_op);
536 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
541 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
544 adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN;
546 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
547 (count * sizeof(u16));
548 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
549 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
550 count = (I40EVF_MAX_AQ_BUF_SIZE -
551 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
553 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
554 (count * sizeof(u16));
557 vvfl = kzalloc(len, GFP_KERNEL);
561 vvfl->vsi_id = adapter->vsi_res->vsi_id;
562 vvfl->num_elements = count;
563 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
565 vvfl->vlan_id[i] = f->vlan;
573 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
574 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
580 * @adapter: adapter structure
581 * @vlans: the VLANs to remove
582 * @count: number of VLANs
584 * Request that the PF remove one or more VLAN filters from our VSI.
586 void i40evf_del_vlans(struct i40evf_adapter *adapter)
588 struct i40e_virtchnl_vlan_filter_list *vvfl;
589 struct i40evf_vlan_filter *f, *ftmp;
590 int len, i = 0, count = 0;
593 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
594 /* bail because we already have a command pending */
595 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
596 adapter->current_op);
600 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
605 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
608 adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN;
610 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
611 (count * sizeof(u16));
612 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
613 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
614 count = (I40EVF_MAX_AQ_BUF_SIZE -
615 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
617 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
618 (count * sizeof(u16));
621 vvfl = kzalloc(len, GFP_KERNEL);
625 vvfl->vsi_id = adapter->vsi_res->vsi_id;
626 vvfl->num_elements = count;
627 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
629 vvfl->vlan_id[i] = f->vlan;
638 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
639 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
644 * i40evf_set_promiscuous
645 * @adapter: adapter structure
646 * @flags: bitmask to control unicast/multicast promiscuous.
648 * Request that the PF enable promiscuous mode for our VSI.
650 void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
652 struct i40e_virtchnl_promisc_info vpi;
655 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
656 /* bail because we already have a command pending */
657 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
658 adapter->current_op);
662 promisc_all = I40E_FLAG_VF_UNICAST_PROMISC |
663 I40E_FLAG_VF_MULTICAST_PROMISC;
664 if ((flags & promisc_all) == promisc_all) {
665 adapter->flags |= I40EVF_FLAG_PROMISC_ON;
666 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
667 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
670 if (flags & I40E_FLAG_VF_MULTICAST_PROMISC) {
671 adapter->flags |= I40EVF_FLAG_ALLMULTI_ON;
672 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
673 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
677 adapter->flags &= ~I40EVF_FLAG_PROMISC_ON;
678 adapter->aq_required &= ~I40EVF_FLAG_AQ_RELEASE_PROMISC;
679 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
682 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
683 vpi.vsi_id = adapter->vsi_res->vsi_id;
685 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
686 (u8 *)&vpi, sizeof(vpi));
690 * i40evf_request_stats
691 * @adapter: adapter structure
693 * Request VSI statistics from PF.
695 void i40evf_request_stats(struct i40evf_adapter *adapter)
697 struct i40e_virtchnl_queue_select vqs;
699 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
700 /* no error message, this isn't crucial */
703 adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS;
704 vqs.vsi_id = adapter->vsi_res->vsi_id;
705 /* queue maps are ignored for this message - only the vsi is used */
706 if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS,
707 (u8 *)&vqs, sizeof(vqs)))
708 /* if the request failed, don't lock out others */
709 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
714 * @adapter: adapter structure
716 * Request hash enable capabilities from PF
718 void i40evf_get_hena(struct i40evf_adapter *adapter)
720 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
721 /* bail because we already have a command pending */
722 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
723 adapter->current_op);
726 adapter->current_op = I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS;
727 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
728 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS,
734 * @adapter: adapter structure
736 * Request the PF to set our RSS hash capabilities
738 void i40evf_set_hena(struct i40evf_adapter *adapter)
740 struct i40e_virtchnl_rss_hena vrh;
742 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
743 /* bail because we already have a command pending */
744 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
745 adapter->current_op);
748 vrh.hena = adapter->hena;
749 adapter->current_op = I40E_VIRTCHNL_OP_SET_RSS_HENA;
750 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
751 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_SET_RSS_HENA,
752 (u8 *)&vrh, sizeof(vrh));
757 * @adapter: adapter structure
759 * Request the PF to set our RSS hash key
761 void i40evf_set_rss_key(struct i40evf_adapter *adapter)
763 struct i40e_virtchnl_rss_key *vrk;
766 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
767 /* bail because we already have a command pending */
768 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
769 adapter->current_op);
772 len = sizeof(struct i40e_virtchnl_rss_key) +
773 (adapter->rss_key_size * sizeof(u8)) - 1;
774 vrk = kzalloc(len, GFP_KERNEL);
777 vrk->vsi_id = adapter->vsi.id;
778 vrk->key_len = adapter->rss_key_size;
779 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
781 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_RSS_KEY;
782 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
783 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_RSS_KEY,
790 * @adapter: adapter structure
792 * Request the PF to set our RSS lookup table
794 void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
796 struct i40e_virtchnl_rss_lut *vrl;
799 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
800 /* bail because we already have a command pending */
801 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
802 adapter->current_op);
805 len = sizeof(struct i40e_virtchnl_rss_lut) +
806 (adapter->rss_lut_size * sizeof(u8)) - 1;
807 vrl = kzalloc(len, GFP_KERNEL);
810 vrl->vsi_id = adapter->vsi.id;
811 vrl->lut_entries = adapter->rss_lut_size;
812 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
813 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_RSS_LUT;
814 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
815 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_RSS_LUT,
821 * i40evf_print_link_message - print link up or down
822 * @adapter: adapter structure
824 * Log a message telling the world of our wonderous link status
826 static void i40evf_print_link_message(struct i40evf_adapter *adapter)
828 struct net_device *netdev = adapter->netdev;
829 char *speed = "Unknown ";
831 if (!adapter->link_up) {
832 netdev_info(netdev, "NIC Link is Down\n");
836 switch (adapter->link_speed) {
837 case I40E_LINK_SPEED_40GB:
840 case I40E_LINK_SPEED_20GB:
843 case I40E_LINK_SPEED_10GB:
846 case I40E_LINK_SPEED_1GB:
849 case I40E_LINK_SPEED_100MB:
856 netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
860 * i40evf_request_reset
861 * @adapter: adapter structure
863 * Request that the PF reset this VF. No response is expected.
865 void i40evf_request_reset(struct i40evf_adapter *adapter)
867 /* Don't check CURRENT_OP - this is always higher priority */
868 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
869 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
873 * i40evf_virtchnl_completion
874 * @adapter: adapter structure
875 * @v_opcode: opcode sent by PF
876 * @v_retval: retval sent by PF
877 * @msg: message sent by PF
878 * @msglen: message length
880 * Asynchronous completion function for admin queue messages. Rather than busy
881 * wait, we fire off our requests and assume that no errors will be returned.
882 * This function handles the reply messages.
884 void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
885 enum i40e_virtchnl_ops v_opcode,
886 i40e_status v_retval,
889 struct net_device *netdev = adapter->netdev;
891 if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
892 struct i40e_virtchnl_pf_event *vpe =
893 (struct i40e_virtchnl_pf_event *)msg;
894 switch (vpe->event) {
895 case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
896 adapter->link_speed =
897 vpe->event_data.link_event.link_speed;
898 if (adapter->link_up !=
899 vpe->event_data.link_event.link_status) {
901 vpe->event_data.link_event.link_status;
902 if (adapter->link_up) {
903 netif_tx_start_all_queues(netdev);
904 netif_carrier_on(netdev);
906 netif_tx_stop_all_queues(netdev);
907 netif_carrier_off(netdev);
909 i40evf_print_link_message(adapter);
912 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
913 dev_info(&adapter->pdev->dev, "PF reset warning received\n");
914 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
915 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
916 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
917 schedule_work(&adapter->reset_task);
921 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
929 case I40E_VIRTCHNL_OP_ADD_VLAN:
930 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
931 i40evf_stat_str(&adapter->hw, v_retval));
933 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
934 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
935 i40evf_stat_str(&adapter->hw, v_retval));
937 case I40E_VIRTCHNL_OP_DEL_VLAN:
938 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
939 i40evf_stat_str(&adapter->hw, v_retval));
941 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
942 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
943 i40evf_stat_str(&adapter->hw, v_retval));
946 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
948 i40evf_stat_str(&adapter->hw, v_retval),
953 case I40E_VIRTCHNL_OP_GET_STATS: {
954 struct i40e_eth_stats *stats =
955 (struct i40e_eth_stats *)msg;
956 adapter->net_stats.rx_packets = stats->rx_unicast +
957 stats->rx_multicast +
959 adapter->net_stats.tx_packets = stats->tx_unicast +
960 stats->tx_multicast +
962 adapter->net_stats.rx_bytes = stats->rx_bytes;
963 adapter->net_stats.tx_bytes = stats->tx_bytes;
964 adapter->net_stats.tx_errors = stats->tx_errors;
965 adapter->net_stats.rx_dropped = stats->rx_discards;
966 adapter->net_stats.tx_dropped = stats->tx_discards;
967 adapter->current_stats = *stats;
970 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: {
971 u16 len = sizeof(struct i40e_virtchnl_vf_resource) +
973 sizeof(struct i40e_virtchnl_vsi_resource);
974 memcpy(adapter->vf_res, msg, min(msglen, len));
975 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
976 /* restore current mac address */
977 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
978 i40evf_process_config(adapter);
981 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
982 /* enable transmits */
983 i40evf_irq_enable(adapter, true);
985 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
986 i40evf_free_all_tx_resources(adapter);
987 i40evf_free_all_rx_resources(adapter);
988 if (adapter->state == __I40EVF_DOWN_PENDING)
989 adapter->state = __I40EVF_DOWN;
991 case I40E_VIRTCHNL_OP_VERSION:
992 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
993 /* Don't display an error if we get these out of sequence.
994 * If the firmware needed to get kicked, we'll get these and
997 if (v_opcode != adapter->current_op)
1000 case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
1001 struct i40e_virtchnl_rss_hena *vrh =
1002 (struct i40e_virtchnl_rss_hena *)msg;
1003 if (msglen == sizeof(*vrh))
1004 adapter->hena = vrh->hena;
1006 dev_warn(&adapter->pdev->dev,
1007 "Invalid message %d from PF\n", v_opcode);
1011 if (v_opcode != adapter->current_op)
1012 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
1013 adapter->current_op, v_opcode);
1015 } /* switch v_opcode */
1016 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;