staging: rtl8188eu: Replace function name in string with __func__
[linux/fpc-iii.git] / drivers / net / ethernet / intel / i40evf / i40evf_virtchnl.c
blob50ce0d6c09ef70d5a1789563b2e71369aa026e7f
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
13 * more details.
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 ******************************************************************************/
27 #include "i40evf.h"
28 #include "i40e_prototype.h"
29 #include "i40evf_client.h"
31 /* busy wait delay in msec */
32 #define I40EVF_BUSY_WAIT_DELAY 10
33 #define I40EVF_BUSY_WAIT_COUNT 50
35 /**
36 * i40evf_send_pf_msg
37 * @adapter: adapter structure
38 * @op: virtual channel opcode
39 * @msg: pointer to message buffer
40 * @len: message length
42 * Send message to PF and print status if failure.
43 **/
44 static int i40evf_send_pf_msg(struct i40evf_adapter *adapter,
45 enum virtchnl_ops op, u8 *msg, u16 len)
47 struct i40e_hw *hw = &adapter->hw;
48 i40e_status err;
50 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
51 return 0; /* nothing to see here, move along */
53 err = i40e_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
54 if (err)
55 dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n",
56 op, i40evf_stat_str(hw, err),
57 i40evf_aq_str(hw, hw->aq.asq_last_status));
58 return err;
61 /**
62 * i40evf_send_api_ver
63 * @adapter: adapter structure
65 * Send API version admin queue message to the PF. The reply is not checked
66 * in this function. Returns 0 if the message was successfully
67 * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
68 **/
69 int i40evf_send_api_ver(struct i40evf_adapter *adapter)
71 struct virtchnl_version_info vvi;
73 vvi.major = VIRTCHNL_VERSION_MAJOR;
74 vvi.minor = VIRTCHNL_VERSION_MINOR;
76 return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
77 sizeof(vvi));
80 /**
81 * i40evf_verify_api_ver
82 * @adapter: adapter structure
84 * Compare API versions with the PF. Must be called after admin queue is
85 * initialized. Returns 0 if API versions match, -EIO if they do not,
86 * I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
87 * from the firmware are propagated.
88 **/
89 int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
91 struct virtchnl_version_info *pf_vvi;
92 struct i40e_hw *hw = &adapter->hw;
93 struct i40e_arq_event_info event;
94 enum virtchnl_ops op;
95 i40e_status err;
97 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
98 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
99 if (!event.msg_buf) {
100 err = -ENOMEM;
101 goto out;
104 while (1) {
105 err = i40evf_clean_arq_element(hw, &event, NULL);
106 /* When the AQ is empty, i40evf_clean_arq_element will return
107 * nonzero and this loop will terminate.
109 if (err)
110 goto out_alloc;
111 op =
112 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
113 if (op == VIRTCHNL_OP_VERSION)
114 break;
118 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
119 if (err)
120 goto out_alloc;
122 if (op != VIRTCHNL_OP_VERSION) {
123 dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n",
124 op);
125 err = -EIO;
126 goto out_alloc;
129 pf_vvi = (struct virtchnl_version_info *)event.msg_buf;
130 adapter->pf_version = *pf_vvi;
132 if ((pf_vvi->major > VIRTCHNL_VERSION_MAJOR) ||
133 ((pf_vvi->major == VIRTCHNL_VERSION_MAJOR) &&
134 (pf_vvi->minor > VIRTCHNL_VERSION_MINOR)))
135 err = -EIO;
137 out_alloc:
138 kfree(event.msg_buf);
139 out:
140 return err;
144 * i40evf_send_vf_config_msg
145 * @adapter: adapter structure
147 * Send VF configuration request admin queue message to the PF. The reply
148 * is not checked in this function. Returns 0 if the message was
149 * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
151 int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
153 u32 caps;
155 caps = VIRTCHNL_VF_OFFLOAD_L2 |
156 VIRTCHNL_VF_OFFLOAD_RSS_PF |
157 VIRTCHNL_VF_OFFLOAD_RSS_AQ |
158 VIRTCHNL_VF_OFFLOAD_RSS_REG |
159 VIRTCHNL_VF_OFFLOAD_VLAN |
160 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
161 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
162 VIRTCHNL_VF_OFFLOAD_ENCAP |
163 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM |
164 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES;
166 adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
167 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
168 if (PF_IS_V11(adapter))
169 return i40evf_send_pf_msg(adapter,
170 VIRTCHNL_OP_GET_VF_RESOURCES,
171 (u8 *)&caps, sizeof(caps));
172 else
173 return i40evf_send_pf_msg(adapter,
174 VIRTCHNL_OP_GET_VF_RESOURCES,
175 NULL, 0);
179 * i40evf_get_vf_config
180 * @hw: pointer to the hardware structure
181 * @len: length of buffer
183 * Get VF configuration from PF and populate hw structure. Must be called after
184 * admin queue is initialized. Busy waits until response is received from PF,
185 * with maximum timeout. Response from PF is returned in the buffer for further
186 * processing by the caller.
188 int i40evf_get_vf_config(struct i40evf_adapter *adapter)
190 struct i40e_hw *hw = &adapter->hw;
191 struct i40e_arq_event_info event;
192 enum virtchnl_ops op;
193 i40e_status err;
194 u16 len;
196 len = sizeof(struct virtchnl_vf_resource) +
197 I40E_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
198 event.buf_len = len;
199 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
200 if (!event.msg_buf) {
201 err = -ENOMEM;
202 goto out;
205 while (1) {
206 /* When the AQ is empty, i40evf_clean_arq_element will return
207 * nonzero and this loop will terminate.
209 err = i40evf_clean_arq_element(hw, &event, NULL);
210 if (err)
211 goto out_alloc;
212 op =
213 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
214 if (op == VIRTCHNL_OP_GET_VF_RESOURCES)
215 break;
218 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
219 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
221 i40e_vf_parse_hw_config(hw, adapter->vf_res);
222 out_alloc:
223 kfree(event.msg_buf);
224 out:
225 return err;
229 * i40evf_configure_queues
230 * @adapter: adapter structure
232 * Request that the PF set up our (previously allocated) queues.
234 void i40evf_configure_queues(struct i40evf_adapter *adapter)
236 struct virtchnl_vsi_queue_config_info *vqci;
237 struct virtchnl_queue_pair_info *vqpi;
238 int pairs = adapter->num_active_queues;
239 int i, len, max_frame = I40E_MAX_RXBUFFER;
241 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
242 /* bail because we already have a command pending */
243 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
244 adapter->current_op);
245 return;
247 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
248 len = sizeof(struct virtchnl_vsi_queue_config_info) +
249 (sizeof(struct virtchnl_queue_pair_info) * pairs);
250 vqci = kzalloc(len, GFP_KERNEL);
251 if (!vqci)
252 return;
254 /* Limit maximum frame size when jumbo frames is not enabled */
255 if (!(adapter->flags & I40EVF_FLAG_LEGACY_RX) &&
256 (adapter->netdev->mtu <= ETH_DATA_LEN))
257 max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
259 vqci->vsi_id = adapter->vsi_res->vsi_id;
260 vqci->num_queue_pairs = pairs;
261 vqpi = vqci->qpair;
262 /* Size check is not needed here - HW max is 16 queue pairs, and we
263 * can fit info for 31 of them into the AQ buffer before it overflows.
265 for (i = 0; i < pairs; i++) {
266 vqpi->txq.vsi_id = vqci->vsi_id;
267 vqpi->txq.queue_id = i;
268 vqpi->txq.ring_len = adapter->tx_rings[i].count;
269 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
270 vqpi->rxq.vsi_id = vqci->vsi_id;
271 vqpi->rxq.queue_id = i;
272 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
273 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
274 vqpi->rxq.max_pkt_size = max_frame;
275 vqpi->rxq.databuffer_size =
276 ALIGN(adapter->rx_rings[i].rx_buf_len,
277 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
278 vqpi++;
281 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
282 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
283 (u8 *)vqci, len);
284 kfree(vqci);
288 * i40evf_enable_queues
289 * @adapter: adapter structure
291 * Request that the PF enable all of our queues.
293 void i40evf_enable_queues(struct i40evf_adapter *adapter)
295 struct virtchnl_queue_select vqs;
297 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
298 /* bail because we already have a command pending */
299 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
300 adapter->current_op);
301 return;
303 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
304 vqs.vsi_id = adapter->vsi_res->vsi_id;
305 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
306 vqs.rx_queues = vqs.tx_queues;
307 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
308 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
309 (u8 *)&vqs, sizeof(vqs));
313 * i40evf_disable_queues
314 * @adapter: adapter structure
316 * Request that the PF disable all of our queues.
318 void i40evf_disable_queues(struct i40evf_adapter *adapter)
320 struct virtchnl_queue_select vqs;
322 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
323 /* bail because we already have a command pending */
324 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
325 adapter->current_op);
326 return;
328 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
329 vqs.vsi_id = adapter->vsi_res->vsi_id;
330 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
331 vqs.rx_queues = vqs.tx_queues;
332 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
333 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
334 (u8 *)&vqs, sizeof(vqs));
338 * i40evf_map_queues
339 * @adapter: adapter structure
341 * Request that the PF map queues to interrupt vectors. Misc causes, including
342 * admin queue, are always mapped to vector 0.
344 void i40evf_map_queues(struct i40evf_adapter *adapter)
346 struct virtchnl_irq_map_info *vimi;
347 int v_idx, q_vectors, len;
348 struct i40e_q_vector *q_vector;
350 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
351 /* bail because we already have a command pending */
352 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
353 adapter->current_op);
354 return;
356 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
358 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
360 len = sizeof(struct virtchnl_irq_map_info) +
361 (adapter->num_msix_vectors *
362 sizeof(struct virtchnl_vector_map));
363 vimi = kzalloc(len, GFP_KERNEL);
364 if (!vimi)
365 return;
367 vimi->num_vectors = adapter->num_msix_vectors;
368 /* Queue vectors first */
369 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
370 q_vector = adapter->q_vectors + v_idx;
371 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
372 vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
373 vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
374 vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
376 /* Misc vector last - this is only for AdminQ messages */
377 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
378 vimi->vecmap[v_idx].vector_id = 0;
379 vimi->vecmap[v_idx].txq_map = 0;
380 vimi->vecmap[v_idx].rxq_map = 0;
382 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
383 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
384 (u8 *)vimi, len);
385 kfree(vimi);
389 * i40evf_request_queues
390 * @adapter: adapter structure
391 * @num: number of requested queues
393 * We get a default number of queues from the PF. This enables us to request a
394 * different number. Returns 0 on success, negative on failure
396 int i40evf_request_queues(struct i40evf_adapter *adapter, int num)
398 struct virtchnl_vf_res_request vfres;
400 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
401 /* bail because we already have a command pending */
402 dev_err(&adapter->pdev->dev, "Cannot request queues, command %d pending\n",
403 adapter->current_op);
404 return -EBUSY;
407 vfres.num_queue_pairs = num;
409 adapter->current_op = VIRTCHNL_OP_REQUEST_QUEUES;
410 adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
411 return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_REQUEST_QUEUES,
412 (u8 *)&vfres, sizeof(vfres));
416 * i40evf_add_ether_addrs
417 * @adapter: adapter structure
418 * @addrs: the MAC address filters to add (contiguous)
419 * @count: number of filters
421 * Request that the PF add one or more addresses to our filters.
423 void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
425 struct virtchnl_ether_addr_list *veal;
426 int len, i = 0, count = 0;
427 struct i40evf_mac_filter *f;
428 bool more = false;
430 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
431 /* bail because we already have a command pending */
432 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
433 adapter->current_op);
434 return;
437 spin_lock_bh(&adapter->mac_vlan_list_lock);
439 list_for_each_entry(f, &adapter->mac_filter_list, list) {
440 if (f->add)
441 count++;
443 if (!count) {
444 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
445 spin_unlock_bh(&adapter->mac_vlan_list_lock);
446 return;
448 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
450 len = sizeof(struct virtchnl_ether_addr_list) +
451 (count * sizeof(struct virtchnl_ether_addr));
452 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
453 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
454 count = (I40EVF_MAX_AQ_BUF_SIZE -
455 sizeof(struct virtchnl_ether_addr_list)) /
456 sizeof(struct virtchnl_ether_addr);
457 len = sizeof(struct virtchnl_ether_addr_list) +
458 (count * sizeof(struct virtchnl_ether_addr));
459 more = true;
462 veal = kzalloc(len, GFP_KERNEL);
463 if (!veal) {
464 spin_unlock_bh(&adapter->mac_vlan_list_lock);
465 return;
468 veal->vsi_id = adapter->vsi_res->vsi_id;
469 veal->num_elements = count;
470 list_for_each_entry(f, &adapter->mac_filter_list, list) {
471 if (f->add) {
472 ether_addr_copy(veal->list[i].addr, f->macaddr);
473 i++;
474 f->add = false;
475 if (i == count)
476 break;
479 if (!more)
480 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
482 spin_unlock_bh(&adapter->mac_vlan_list_lock);
484 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR,
485 (u8 *)veal, len);
486 kfree(veal);
490 * i40evf_del_ether_addrs
491 * @adapter: adapter structure
492 * @addrs: the MAC address filters to remove (contiguous)
493 * @count: number of filtes
495 * Request that the PF remove one or more addresses from our filters.
497 void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
499 struct virtchnl_ether_addr_list *veal;
500 struct i40evf_mac_filter *f, *ftmp;
501 int len, i = 0, count = 0;
502 bool more = false;
504 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
505 /* bail because we already have a command pending */
506 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
507 adapter->current_op);
508 return;
511 spin_lock_bh(&adapter->mac_vlan_list_lock);
513 list_for_each_entry(f, &adapter->mac_filter_list, list) {
514 if (f->remove)
515 count++;
517 if (!count) {
518 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
519 spin_unlock_bh(&adapter->mac_vlan_list_lock);
520 return;
522 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
524 len = sizeof(struct virtchnl_ether_addr_list) +
525 (count * sizeof(struct virtchnl_ether_addr));
526 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
527 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
528 count = (I40EVF_MAX_AQ_BUF_SIZE -
529 sizeof(struct virtchnl_ether_addr_list)) /
530 sizeof(struct virtchnl_ether_addr);
531 len = sizeof(struct virtchnl_ether_addr_list) +
532 (count * sizeof(struct virtchnl_ether_addr));
533 more = true;
535 veal = kzalloc(len, GFP_KERNEL);
536 if (!veal) {
537 spin_unlock_bh(&adapter->mac_vlan_list_lock);
538 return;
541 veal->vsi_id = adapter->vsi_res->vsi_id;
542 veal->num_elements = count;
543 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
544 if (f->remove) {
545 ether_addr_copy(veal->list[i].addr, f->macaddr);
546 i++;
547 list_del(&f->list);
548 kfree(f);
549 if (i == count)
550 break;
553 if (!more)
554 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
556 spin_unlock_bh(&adapter->mac_vlan_list_lock);
558 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR,
559 (u8 *)veal, len);
560 kfree(veal);
564 * i40evf_add_vlans
565 * @adapter: adapter structure
566 * @vlans: the VLANs to add
567 * @count: number of VLANs
569 * Request that the PF add one or more VLAN filters to our VSI.
571 void i40evf_add_vlans(struct i40evf_adapter *adapter)
573 struct virtchnl_vlan_filter_list *vvfl;
574 int len, i = 0, count = 0;
575 struct i40evf_vlan_filter *f;
576 bool more = false;
578 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
579 /* bail because we already have a command pending */
580 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
581 adapter->current_op);
582 return;
585 spin_lock_bh(&adapter->mac_vlan_list_lock);
587 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
588 if (f->add)
589 count++;
591 if (!count) {
592 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
593 spin_unlock_bh(&adapter->mac_vlan_list_lock);
594 return;
596 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
598 len = sizeof(struct virtchnl_vlan_filter_list) +
599 (count * sizeof(u16));
600 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
601 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
602 count = (I40EVF_MAX_AQ_BUF_SIZE -
603 sizeof(struct virtchnl_vlan_filter_list)) /
604 sizeof(u16);
605 len = sizeof(struct virtchnl_vlan_filter_list) +
606 (count * sizeof(u16));
607 more = true;
609 vvfl = kzalloc(len, GFP_KERNEL);
610 if (!vvfl) {
611 spin_unlock_bh(&adapter->mac_vlan_list_lock);
612 return;
615 vvfl->vsi_id = adapter->vsi_res->vsi_id;
616 vvfl->num_elements = count;
617 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
618 if (f->add) {
619 vvfl->vlan_id[i] = f->vlan;
620 i++;
621 f->add = false;
622 if (i == count)
623 break;
626 if (!more)
627 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
629 spin_unlock_bh(&adapter->mac_vlan_list_lock);
631 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
632 kfree(vvfl);
636 * i40evf_del_vlans
637 * @adapter: adapter structure
638 * @vlans: the VLANs to remove
639 * @count: number of VLANs
641 * Request that the PF remove one or more VLAN filters from our VSI.
643 void i40evf_del_vlans(struct i40evf_adapter *adapter)
645 struct virtchnl_vlan_filter_list *vvfl;
646 struct i40evf_vlan_filter *f, *ftmp;
647 int len, i = 0, count = 0;
648 bool more = false;
650 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
651 /* bail because we already have a command pending */
652 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
653 adapter->current_op);
654 return;
657 spin_lock_bh(&adapter->mac_vlan_list_lock);
659 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
660 if (f->remove)
661 count++;
663 if (!count) {
664 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
665 spin_unlock_bh(&adapter->mac_vlan_list_lock);
666 return;
668 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
670 len = sizeof(struct virtchnl_vlan_filter_list) +
671 (count * sizeof(u16));
672 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
673 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
674 count = (I40EVF_MAX_AQ_BUF_SIZE -
675 sizeof(struct virtchnl_vlan_filter_list)) /
676 sizeof(u16);
677 len = sizeof(struct virtchnl_vlan_filter_list) +
678 (count * sizeof(u16));
679 more = true;
681 vvfl = kzalloc(len, GFP_KERNEL);
682 if (!vvfl) {
683 spin_unlock_bh(&adapter->mac_vlan_list_lock);
684 return;
687 vvfl->vsi_id = adapter->vsi_res->vsi_id;
688 vvfl->num_elements = count;
689 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
690 if (f->remove) {
691 vvfl->vlan_id[i] = f->vlan;
692 i++;
693 list_del(&f->list);
694 kfree(f);
695 if (i == count)
696 break;
699 if (!more)
700 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
702 spin_unlock_bh(&adapter->mac_vlan_list_lock);
704 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
705 kfree(vvfl);
709 * i40evf_set_promiscuous
710 * @adapter: adapter structure
711 * @flags: bitmask to control unicast/multicast promiscuous.
713 * Request that the PF enable promiscuous mode for our VSI.
715 void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
717 struct virtchnl_promisc_info vpi;
718 int promisc_all;
720 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
721 /* bail because we already have a command pending */
722 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
723 adapter->current_op);
724 return;
727 promisc_all = FLAG_VF_UNICAST_PROMISC |
728 FLAG_VF_MULTICAST_PROMISC;
729 if ((flags & promisc_all) == promisc_all) {
730 adapter->flags |= I40EVF_FLAG_PROMISC_ON;
731 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
732 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
735 if (flags & FLAG_VF_MULTICAST_PROMISC) {
736 adapter->flags |= I40EVF_FLAG_ALLMULTI_ON;
737 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
738 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
741 if (!flags) {
742 adapter->flags &= ~(I40EVF_FLAG_PROMISC_ON |
743 I40EVF_FLAG_ALLMULTI_ON);
744 adapter->aq_required &= ~(I40EVF_FLAG_AQ_RELEASE_PROMISC |
745 I40EVF_FLAG_AQ_RELEASE_ALLMULTI);
746 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
749 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
750 vpi.vsi_id = adapter->vsi_res->vsi_id;
751 vpi.flags = flags;
752 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
753 (u8 *)&vpi, sizeof(vpi));
757 * i40evf_request_stats
758 * @adapter: adapter structure
760 * Request VSI statistics from PF.
762 void i40evf_request_stats(struct i40evf_adapter *adapter)
764 struct virtchnl_queue_select vqs;
766 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
767 /* no error message, this isn't crucial */
768 return;
770 adapter->current_op = VIRTCHNL_OP_GET_STATS;
771 vqs.vsi_id = adapter->vsi_res->vsi_id;
772 /* queue maps are ignored for this message - only the vsi is used */
773 if (i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS,
774 (u8 *)&vqs, sizeof(vqs)))
775 /* if the request failed, don't lock out others */
776 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
780 * i40evf_get_hena
781 * @adapter: adapter structure
783 * Request hash enable capabilities from PF
785 void i40evf_get_hena(struct i40evf_adapter *adapter)
787 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
788 /* bail because we already have a command pending */
789 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
790 adapter->current_op);
791 return;
793 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
794 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
795 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS,
796 NULL, 0);
800 * i40evf_set_hena
801 * @adapter: adapter structure
803 * Request the PF to set our RSS hash capabilities
805 void i40evf_set_hena(struct i40evf_adapter *adapter)
807 struct virtchnl_rss_hena vrh;
809 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
810 /* bail because we already have a command pending */
811 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
812 adapter->current_op);
813 return;
815 vrh.hena = adapter->hena;
816 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
817 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
818 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA,
819 (u8 *)&vrh, sizeof(vrh));
823 * i40evf_set_rss_key
824 * @adapter: adapter structure
826 * Request the PF to set our RSS hash key
828 void i40evf_set_rss_key(struct i40evf_adapter *adapter)
830 struct virtchnl_rss_key *vrk;
831 int len;
833 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
834 /* bail because we already have a command pending */
835 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
836 adapter->current_op);
837 return;
839 len = sizeof(struct virtchnl_rss_key) +
840 (adapter->rss_key_size * sizeof(u8)) - 1;
841 vrk = kzalloc(len, GFP_KERNEL);
842 if (!vrk)
843 return;
844 vrk->vsi_id = adapter->vsi.id;
845 vrk->key_len = adapter->rss_key_size;
846 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
848 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
849 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
850 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY,
851 (u8 *)vrk, len);
852 kfree(vrk);
856 * i40evf_set_rss_lut
857 * @adapter: adapter structure
859 * Request the PF to set our RSS lookup table
861 void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
863 struct virtchnl_rss_lut *vrl;
864 int len;
866 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
867 /* bail because we already have a command pending */
868 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
869 adapter->current_op);
870 return;
872 len = sizeof(struct virtchnl_rss_lut) +
873 (adapter->rss_lut_size * sizeof(u8)) - 1;
874 vrl = kzalloc(len, GFP_KERNEL);
875 if (!vrl)
876 return;
877 vrl->vsi_id = adapter->vsi.id;
878 vrl->lut_entries = adapter->rss_lut_size;
879 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
880 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
881 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
882 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT,
883 (u8 *)vrl, len);
884 kfree(vrl);
888 * i40evf_enable_vlan_stripping
889 * @adapter: adapter structure
891 * Request VLAN header stripping to be enabled
893 void i40evf_enable_vlan_stripping(struct i40evf_adapter *adapter)
895 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
896 /* bail because we already have a command pending */
897 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
898 adapter->current_op);
899 return;
901 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
902 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
903 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
904 NULL, 0);
908 * i40evf_disable_vlan_stripping
909 * @adapter: adapter structure
911 * Request VLAN header stripping to be disabled
913 void i40evf_disable_vlan_stripping(struct i40evf_adapter *adapter)
915 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
916 /* bail because we already have a command pending */
917 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
918 adapter->current_op);
919 return;
921 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
922 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
923 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
924 NULL, 0);
928 * i40evf_print_link_message - print link up or down
929 * @adapter: adapter structure
931 * Log a message telling the world of our wonderous link status
933 static void i40evf_print_link_message(struct i40evf_adapter *adapter)
935 struct net_device *netdev = adapter->netdev;
936 char *speed = "Unknown ";
938 if (!adapter->link_up) {
939 netdev_info(netdev, "NIC Link is Down\n");
940 return;
943 switch (adapter->link_speed) {
944 case I40E_LINK_SPEED_40GB:
945 speed = "40 G";
946 break;
947 case I40E_LINK_SPEED_25GB:
948 speed = "25 G";
949 break;
950 case I40E_LINK_SPEED_20GB:
951 speed = "20 G";
952 break;
953 case I40E_LINK_SPEED_10GB:
954 speed = "10 G";
955 break;
956 case I40E_LINK_SPEED_1GB:
957 speed = "1000 M";
958 break;
959 case I40E_LINK_SPEED_100MB:
960 speed = "100 M";
961 break;
962 default:
963 break;
966 netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
970 * i40evf_request_reset
971 * @adapter: adapter structure
973 * Request that the PF reset this VF. No response is expected.
975 void i40evf_request_reset(struct i40evf_adapter *adapter)
977 /* Don't check CURRENT_OP - this is always higher priority */
978 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
979 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
983 * i40evf_virtchnl_completion
984 * @adapter: adapter structure
985 * @v_opcode: opcode sent by PF
986 * @v_retval: retval sent by PF
987 * @msg: message sent by PF
988 * @msglen: message length
990 * Asynchronous completion function for admin queue messages. Rather than busy
991 * wait, we fire off our requests and assume that no errors will be returned.
992 * This function handles the reply messages.
994 void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
995 enum virtchnl_ops v_opcode,
996 i40e_status v_retval,
997 u8 *msg, u16 msglen)
999 struct net_device *netdev = adapter->netdev;
1001 if (v_opcode == VIRTCHNL_OP_EVENT) {
1002 struct virtchnl_pf_event *vpe =
1003 (struct virtchnl_pf_event *)msg;
1004 bool link_up = vpe->event_data.link_event.link_status;
1005 switch (vpe->event) {
1006 case VIRTCHNL_EVENT_LINK_CHANGE:
1007 adapter->link_speed =
1008 vpe->event_data.link_event.link_speed;
1010 /* we've already got the right link status, bail */
1011 if (adapter->link_up == link_up)
1012 break;
1014 /* If we get link up message and start queues before
1015 * our queues are configured it will trigger a TX hang.
1016 * In that case, just ignore the link status message,
1017 * we'll get another one after we enable queues and
1018 * actually prepared to send traffic.
1020 if (link_up && adapter->state != __I40EVF_RUNNING)
1021 break;
1023 adapter->link_up = link_up;
1024 if (link_up) {
1025 netif_tx_start_all_queues(netdev);
1026 netif_carrier_on(netdev);
1027 } else {
1028 netif_tx_stop_all_queues(netdev);
1029 netif_carrier_off(netdev);
1031 i40evf_print_link_message(adapter);
1032 break;
1033 case VIRTCHNL_EVENT_RESET_IMPENDING:
1034 dev_info(&adapter->pdev->dev, "PF reset warning received\n");
1035 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
1036 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
1037 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
1038 schedule_work(&adapter->reset_task);
1040 break;
1041 default:
1042 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
1043 vpe->event);
1044 break;
1046 return;
1048 if (v_retval) {
1049 switch (v_opcode) {
1050 case VIRTCHNL_OP_ADD_VLAN:
1051 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
1052 i40evf_stat_str(&adapter->hw, v_retval));
1053 break;
1054 case VIRTCHNL_OP_ADD_ETH_ADDR:
1055 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
1056 i40evf_stat_str(&adapter->hw, v_retval));
1057 break;
1058 case VIRTCHNL_OP_DEL_VLAN:
1059 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1060 i40evf_stat_str(&adapter->hw, v_retval));
1061 break;
1062 case VIRTCHNL_OP_DEL_ETH_ADDR:
1063 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1064 i40evf_stat_str(&adapter->hw, v_retval));
1065 break;
1066 default:
1067 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
1068 v_retval,
1069 i40evf_stat_str(&adapter->hw, v_retval),
1070 v_opcode);
1073 switch (v_opcode) {
1074 case VIRTCHNL_OP_GET_STATS: {
1075 struct i40e_eth_stats *stats =
1076 (struct i40e_eth_stats *)msg;
1077 netdev->stats.rx_packets = stats->rx_unicast +
1078 stats->rx_multicast +
1079 stats->rx_broadcast;
1080 netdev->stats.tx_packets = stats->tx_unicast +
1081 stats->tx_multicast +
1082 stats->tx_broadcast;
1083 netdev->stats.rx_bytes = stats->rx_bytes;
1084 netdev->stats.tx_bytes = stats->tx_bytes;
1085 netdev->stats.tx_errors = stats->tx_errors;
1086 netdev->stats.rx_dropped = stats->rx_discards;
1087 netdev->stats.tx_dropped = stats->tx_discards;
1088 adapter->current_stats = *stats;
1090 break;
1091 case VIRTCHNL_OP_GET_VF_RESOURCES: {
1092 u16 len = sizeof(struct virtchnl_vf_resource) +
1093 I40E_MAX_VF_VSI *
1094 sizeof(struct virtchnl_vsi_resource);
1095 memcpy(adapter->vf_res, msg, min(msglen, len));
1096 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
1097 /* restore current mac address */
1098 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1099 i40evf_process_config(adapter);
1101 break;
1102 case VIRTCHNL_OP_ENABLE_QUEUES:
1103 /* enable transmits */
1104 i40evf_irq_enable(adapter, true);
1105 break;
1106 case VIRTCHNL_OP_DISABLE_QUEUES:
1107 i40evf_free_all_tx_resources(adapter);
1108 i40evf_free_all_rx_resources(adapter);
1109 if (adapter->state == __I40EVF_DOWN_PENDING) {
1110 adapter->state = __I40EVF_DOWN;
1111 wake_up(&adapter->down_waitqueue);
1113 break;
1114 case VIRTCHNL_OP_VERSION:
1115 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1116 /* Don't display an error if we get these out of sequence.
1117 * If the firmware needed to get kicked, we'll get these and
1118 * it's no problem.
1120 if (v_opcode != adapter->current_op)
1121 return;
1122 break;
1123 case VIRTCHNL_OP_IWARP:
1124 /* Gobble zero-length replies from the PF. They indicate that
1125 * a previous message was received OK, and the client doesn't
1126 * care about that.
1128 if (msglen && CLIENT_ENABLED(adapter))
1129 i40evf_notify_client_message(&adapter->vsi,
1130 msg, msglen);
1131 break;
1133 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
1134 adapter->client_pending &=
1135 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
1136 break;
1137 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
1138 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
1139 if (msglen == sizeof(*vrh))
1140 adapter->hena = vrh->hena;
1141 else
1142 dev_warn(&adapter->pdev->dev,
1143 "Invalid message %d from PF\n", v_opcode);
1145 break;
1146 case VIRTCHNL_OP_REQUEST_QUEUES: {
1147 struct virtchnl_vf_res_request *vfres =
1148 (struct virtchnl_vf_res_request *)msg;
1149 if (vfres->num_queue_pairs != adapter->num_req_queues) {
1150 dev_info(&adapter->pdev->dev,
1151 "Requested %d queues, PF can support %d\n",
1152 adapter->num_req_queues,
1153 vfres->num_queue_pairs);
1154 adapter->num_req_queues = 0;
1155 adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED;
1158 break;
1159 default:
1160 if (adapter->current_op && (v_opcode != adapter->current_op))
1161 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
1162 adapter->current_op, v_opcode);
1163 break;
1164 } /* switch v_opcode */
1165 adapter->current_op = VIRTCHNL_OP_UNKNOWN;