Linux 4.19.133
[linux/fpc-iii.git] / drivers / net / ethernet / intel / i40evf / i40evf_virtchnl.c
blob94dabc9d89f731f436c90ed7bf56eebd56297e63
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
4 #include "i40evf.h"
5 #include "i40e_prototype.h"
6 #include "i40evf_client.h"
8 /* busy wait delay in msec */
9 #define I40EVF_BUSY_WAIT_DELAY 10
10 #define I40EVF_BUSY_WAIT_COUNT 50
12 /**
13 * i40evf_send_pf_msg
14 * @adapter: adapter structure
15 * @op: virtual channel opcode
16 * @msg: pointer to message buffer
17 * @len: message length
19 * Send message to PF and print status if failure.
20 **/
21 static int i40evf_send_pf_msg(struct i40evf_adapter *adapter,
22 enum virtchnl_ops op, u8 *msg, u16 len)
24 struct i40e_hw *hw = &adapter->hw;
25 i40e_status err;
27 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
28 return 0; /* nothing to see here, move along */
30 err = i40e_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
31 if (err)
32 dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n",
33 op, i40evf_stat_str(hw, err),
34 i40evf_aq_str(hw, hw->aq.asq_last_status));
35 return err;
38 /**
39 * i40evf_send_api_ver
40 * @adapter: adapter structure
42 * Send API version admin queue message to the PF. The reply is not checked
43 * in this function. Returns 0 if the message was successfully
44 * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
45 **/
46 int i40evf_send_api_ver(struct i40evf_adapter *adapter)
48 struct virtchnl_version_info vvi;
50 vvi.major = VIRTCHNL_VERSION_MAJOR;
51 vvi.minor = VIRTCHNL_VERSION_MINOR;
53 return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
54 sizeof(vvi));
57 /**
58 * i40evf_verify_api_ver
59 * @adapter: adapter structure
61 * Compare API versions with the PF. Must be called after admin queue is
62 * initialized. Returns 0 if API versions match, -EIO if they do not,
63 * I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
64 * from the firmware are propagated.
65 **/
66 int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
68 struct virtchnl_version_info *pf_vvi;
69 struct i40e_hw *hw = &adapter->hw;
70 struct i40e_arq_event_info event;
71 enum virtchnl_ops op;
72 i40e_status err;
74 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
75 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
76 if (!event.msg_buf) {
77 err = -ENOMEM;
78 goto out;
81 while (1) {
82 err = i40evf_clean_arq_element(hw, &event, NULL);
83 /* When the AQ is empty, i40evf_clean_arq_element will return
84 * nonzero and this loop will terminate.
86 if (err)
87 goto out_alloc;
88 op =
89 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
90 if (op == VIRTCHNL_OP_VERSION)
91 break;
95 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
96 if (err)
97 goto out_alloc;
99 if (op != VIRTCHNL_OP_VERSION) {
100 dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n",
101 op);
102 err = -EIO;
103 goto out_alloc;
106 pf_vvi = (struct virtchnl_version_info *)event.msg_buf;
107 adapter->pf_version = *pf_vvi;
109 if ((pf_vvi->major > VIRTCHNL_VERSION_MAJOR) ||
110 ((pf_vvi->major == VIRTCHNL_VERSION_MAJOR) &&
111 (pf_vvi->minor > VIRTCHNL_VERSION_MINOR)))
112 err = -EIO;
114 out_alloc:
115 kfree(event.msg_buf);
116 out:
117 return err;
121 * i40evf_send_vf_config_msg
122 * @adapter: adapter structure
124 * Send VF configuration request admin queue message to the PF. The reply
125 * is not checked in this function. Returns 0 if the message was
126 * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
128 int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
130 u32 caps;
132 caps = VIRTCHNL_VF_OFFLOAD_L2 |
133 VIRTCHNL_VF_OFFLOAD_RSS_PF |
134 VIRTCHNL_VF_OFFLOAD_RSS_AQ |
135 VIRTCHNL_VF_OFFLOAD_RSS_REG |
136 VIRTCHNL_VF_OFFLOAD_VLAN |
137 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
138 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
139 VIRTCHNL_VF_OFFLOAD_ENCAP |
140 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM |
141 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
142 VIRTCHNL_VF_OFFLOAD_ADQ;
144 adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
145 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
146 if (PF_IS_V11(adapter))
147 return i40evf_send_pf_msg(adapter,
148 VIRTCHNL_OP_GET_VF_RESOURCES,
149 (u8 *)&caps, sizeof(caps));
150 else
151 return i40evf_send_pf_msg(adapter,
152 VIRTCHNL_OP_GET_VF_RESOURCES,
153 NULL, 0);
157 * i40evf_validate_num_queues
158 * @adapter: adapter structure
160 * Validate that the number of queues the PF has sent in
161 * VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle.
163 static void i40evf_validate_num_queues(struct i40evf_adapter *adapter)
165 if (adapter->vf_res->num_queue_pairs > I40EVF_MAX_REQ_QUEUES) {
166 struct virtchnl_vsi_resource *vsi_res;
167 int i;
169 dev_info(&adapter->pdev->dev, "Received %d queues, but can only have a max of %d\n",
170 adapter->vf_res->num_queue_pairs,
171 I40EVF_MAX_REQ_QUEUES);
172 dev_info(&adapter->pdev->dev, "Fixing by reducing queues to %d\n",
173 I40EVF_MAX_REQ_QUEUES);
174 adapter->vf_res->num_queue_pairs = I40EVF_MAX_REQ_QUEUES;
175 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
176 vsi_res = &adapter->vf_res->vsi_res[i];
177 vsi_res->num_queue_pairs = I40EVF_MAX_REQ_QUEUES;
183 * i40evf_get_vf_config
184 * @adapter: private adapter structure
186 * Get VF configuration from PF and populate hw structure. Must be called after
187 * admin queue is initialized. Busy waits until response is received from PF,
188 * with maximum timeout. Response from PF is returned in the buffer for further
189 * processing by the caller.
191 int i40evf_get_vf_config(struct i40evf_adapter *adapter)
193 struct i40e_hw *hw = &adapter->hw;
194 struct i40e_arq_event_info event;
195 enum virtchnl_ops op;
196 i40e_status err;
197 u16 len;
199 len = sizeof(struct virtchnl_vf_resource) +
200 I40E_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
201 event.buf_len = len;
202 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
203 if (!event.msg_buf) {
204 err = -ENOMEM;
205 goto out;
208 while (1) {
209 /* When the AQ is empty, i40evf_clean_arq_element will return
210 * nonzero and this loop will terminate.
212 err = i40evf_clean_arq_element(hw, &event, NULL);
213 if (err)
214 goto out_alloc;
215 op =
216 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
217 if (op == VIRTCHNL_OP_GET_VF_RESOURCES)
218 break;
221 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
222 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
224 /* some PFs send more queues than we should have so validate that
225 * we aren't getting too many queues
227 if (!err)
228 i40evf_validate_num_queues(adapter);
229 i40e_vf_parse_hw_config(hw, adapter->vf_res);
230 out_alloc:
231 kfree(event.msg_buf);
232 out:
233 return err;
237 * i40evf_configure_queues
238 * @adapter: adapter structure
240 * Request that the PF set up our (previously allocated) queues.
242 void i40evf_configure_queues(struct i40evf_adapter *adapter)
244 struct virtchnl_vsi_queue_config_info *vqci;
245 struct virtchnl_queue_pair_info *vqpi;
246 int pairs = adapter->num_active_queues;
247 int i, len, max_frame = I40E_MAX_RXBUFFER;
249 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
250 /* bail because we already have a command pending */
251 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
252 adapter->current_op);
253 return;
255 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
256 len = sizeof(struct virtchnl_vsi_queue_config_info) +
257 (sizeof(struct virtchnl_queue_pair_info) * pairs);
258 vqci = kzalloc(len, GFP_KERNEL);
259 if (!vqci)
260 return;
262 /* Limit maximum frame size when jumbo frames is not enabled */
263 if (!(adapter->flags & I40EVF_FLAG_LEGACY_RX) &&
264 (adapter->netdev->mtu <= ETH_DATA_LEN))
265 max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
267 vqci->vsi_id = adapter->vsi_res->vsi_id;
268 vqci->num_queue_pairs = pairs;
269 vqpi = vqci->qpair;
270 /* Size check is not needed here - HW max is 16 queue pairs, and we
271 * can fit info for 31 of them into the AQ buffer before it overflows.
273 for (i = 0; i < pairs; i++) {
274 vqpi->txq.vsi_id = vqci->vsi_id;
275 vqpi->txq.queue_id = i;
276 vqpi->txq.ring_len = adapter->tx_rings[i].count;
277 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
278 vqpi->rxq.vsi_id = vqci->vsi_id;
279 vqpi->rxq.queue_id = i;
280 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
281 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
282 vqpi->rxq.max_pkt_size = max_frame;
283 vqpi->rxq.databuffer_size =
284 ALIGN(adapter->rx_rings[i].rx_buf_len,
285 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
286 vqpi++;
289 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
290 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
291 (u8 *)vqci, len);
292 kfree(vqci);
296 * i40evf_enable_queues
297 * @adapter: adapter structure
299 * Request that the PF enable all of our queues.
301 void i40evf_enable_queues(struct i40evf_adapter *adapter)
303 struct virtchnl_queue_select vqs;
305 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
306 /* bail because we already have a command pending */
307 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
308 adapter->current_op);
309 return;
311 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
312 vqs.vsi_id = adapter->vsi_res->vsi_id;
313 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
314 vqs.rx_queues = vqs.tx_queues;
315 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
316 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
317 (u8 *)&vqs, sizeof(vqs));
321 * i40evf_disable_queues
322 * @adapter: adapter structure
324 * Request that the PF disable all of our queues.
326 void i40evf_disable_queues(struct i40evf_adapter *adapter)
328 struct virtchnl_queue_select vqs;
330 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
331 /* bail because we already have a command pending */
332 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
333 adapter->current_op);
334 return;
336 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
337 vqs.vsi_id = adapter->vsi_res->vsi_id;
338 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
339 vqs.rx_queues = vqs.tx_queues;
340 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
341 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
342 (u8 *)&vqs, sizeof(vqs));
346 * i40evf_map_queues
347 * @adapter: adapter structure
349 * Request that the PF map queues to interrupt vectors. Misc causes, including
350 * admin queue, are always mapped to vector 0.
352 void i40evf_map_queues(struct i40evf_adapter *adapter)
354 struct virtchnl_irq_map_info *vimi;
355 struct virtchnl_vector_map *vecmap;
356 int v_idx, q_vectors, len;
357 struct i40e_q_vector *q_vector;
359 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
360 /* bail because we already have a command pending */
361 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
362 adapter->current_op);
363 return;
365 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
367 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
369 len = sizeof(struct virtchnl_irq_map_info) +
370 (adapter->num_msix_vectors *
371 sizeof(struct virtchnl_vector_map));
372 vimi = kzalloc(len, GFP_KERNEL);
373 if (!vimi)
374 return;
376 vimi->num_vectors = adapter->num_msix_vectors;
377 /* Queue vectors first */
378 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
379 q_vector = &adapter->q_vectors[v_idx];
380 vecmap = &vimi->vecmap[v_idx];
382 vecmap->vsi_id = adapter->vsi_res->vsi_id;
383 vecmap->vector_id = v_idx + NONQ_VECS;
384 vecmap->txq_map = q_vector->ring_mask;
385 vecmap->rxq_map = q_vector->ring_mask;
386 vecmap->rxitr_idx = I40E_RX_ITR;
387 vecmap->txitr_idx = I40E_TX_ITR;
389 /* Misc vector last - this is only for AdminQ messages */
390 vecmap = &vimi->vecmap[v_idx];
391 vecmap->vsi_id = adapter->vsi_res->vsi_id;
392 vecmap->vector_id = 0;
393 vecmap->txq_map = 0;
394 vecmap->rxq_map = 0;
396 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
397 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
398 (u8 *)vimi, len);
399 kfree(vimi);
403 * i40evf_request_queues
404 * @adapter: adapter structure
405 * @num: number of requested queues
407 * We get a default number of queues from the PF. This enables us to request a
408 * different number. Returns 0 on success, negative on failure
410 int i40evf_request_queues(struct i40evf_adapter *adapter, int num)
412 struct virtchnl_vf_res_request vfres;
414 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
415 /* bail because we already have a command pending */
416 dev_err(&adapter->pdev->dev, "Cannot request queues, command %d pending\n",
417 adapter->current_op);
418 return -EBUSY;
421 vfres.num_queue_pairs = num;
423 adapter->current_op = VIRTCHNL_OP_REQUEST_QUEUES;
424 adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
425 return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_REQUEST_QUEUES,
426 (u8 *)&vfres, sizeof(vfres));
430 * i40evf_add_ether_addrs
431 * @adapter: adapter structure
433 * Request that the PF add one or more addresses to our filters.
435 void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
437 struct virtchnl_ether_addr_list *veal;
438 int len, i = 0, count = 0;
439 struct i40evf_mac_filter *f;
440 bool more = false;
442 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
443 /* bail because we already have a command pending */
444 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
445 adapter->current_op);
446 return;
449 spin_lock_bh(&adapter->mac_vlan_list_lock);
451 list_for_each_entry(f, &adapter->mac_filter_list, list) {
452 if (f->add)
453 count++;
455 if (!count) {
456 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
457 spin_unlock_bh(&adapter->mac_vlan_list_lock);
458 return;
460 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
462 len = sizeof(struct virtchnl_ether_addr_list) +
463 (count * sizeof(struct virtchnl_ether_addr));
464 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
465 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
466 count = (I40EVF_MAX_AQ_BUF_SIZE -
467 sizeof(struct virtchnl_ether_addr_list)) /
468 sizeof(struct virtchnl_ether_addr);
469 len = sizeof(struct virtchnl_ether_addr_list) +
470 (count * sizeof(struct virtchnl_ether_addr));
471 more = true;
474 veal = kzalloc(len, GFP_ATOMIC);
475 if (!veal) {
476 spin_unlock_bh(&adapter->mac_vlan_list_lock);
477 return;
480 veal->vsi_id = adapter->vsi_res->vsi_id;
481 veal->num_elements = count;
482 list_for_each_entry(f, &adapter->mac_filter_list, list) {
483 if (f->add) {
484 ether_addr_copy(veal->list[i].addr, f->macaddr);
485 i++;
486 f->add = false;
487 if (i == count)
488 break;
491 if (!more)
492 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
494 spin_unlock_bh(&adapter->mac_vlan_list_lock);
496 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR,
497 (u8 *)veal, len);
498 kfree(veal);
502 * i40evf_del_ether_addrs
503 * @adapter: adapter structure
505 * Request that the PF remove one or more addresses from our filters.
507 void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
509 struct virtchnl_ether_addr_list *veal;
510 struct i40evf_mac_filter *f, *ftmp;
511 int len, i = 0, count = 0;
512 bool more = false;
514 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
515 /* bail because we already have a command pending */
516 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
517 adapter->current_op);
518 return;
521 spin_lock_bh(&adapter->mac_vlan_list_lock);
523 list_for_each_entry(f, &adapter->mac_filter_list, list) {
524 if (f->remove)
525 count++;
527 if (!count) {
528 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
529 spin_unlock_bh(&adapter->mac_vlan_list_lock);
530 return;
532 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
534 len = sizeof(struct virtchnl_ether_addr_list) +
535 (count * sizeof(struct virtchnl_ether_addr));
536 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
537 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
538 count = (I40EVF_MAX_AQ_BUF_SIZE -
539 sizeof(struct virtchnl_ether_addr_list)) /
540 sizeof(struct virtchnl_ether_addr);
541 len = sizeof(struct virtchnl_ether_addr_list) +
542 (count * sizeof(struct virtchnl_ether_addr));
543 more = true;
545 veal = kzalloc(len, GFP_ATOMIC);
546 if (!veal) {
547 spin_unlock_bh(&adapter->mac_vlan_list_lock);
548 return;
551 veal->vsi_id = adapter->vsi_res->vsi_id;
552 veal->num_elements = count;
553 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
554 if (f->remove) {
555 ether_addr_copy(veal->list[i].addr, f->macaddr);
556 i++;
557 list_del(&f->list);
558 kfree(f);
559 if (i == count)
560 break;
563 if (!more)
564 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
566 spin_unlock_bh(&adapter->mac_vlan_list_lock);
568 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR,
569 (u8 *)veal, len);
570 kfree(veal);
574 * i40evf_add_vlans
575 * @adapter: adapter structure
577 * Request that the PF add one or more VLAN filters to our VSI.
579 void i40evf_add_vlans(struct i40evf_adapter *adapter)
581 struct virtchnl_vlan_filter_list *vvfl;
582 int len, i = 0, count = 0;
583 struct i40evf_vlan_filter *f;
584 bool more = false;
586 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
587 /* bail because we already have a command pending */
588 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
589 adapter->current_op);
590 return;
593 spin_lock_bh(&adapter->mac_vlan_list_lock);
595 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
596 if (f->add)
597 count++;
599 if (!count) {
600 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
601 spin_unlock_bh(&adapter->mac_vlan_list_lock);
602 return;
604 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
606 len = sizeof(struct virtchnl_vlan_filter_list) +
607 (count * sizeof(u16));
608 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
609 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
610 count = (I40EVF_MAX_AQ_BUF_SIZE -
611 sizeof(struct virtchnl_vlan_filter_list)) /
612 sizeof(u16);
613 len = sizeof(struct virtchnl_vlan_filter_list) +
614 (count * sizeof(u16));
615 more = true;
617 vvfl = kzalloc(len, GFP_ATOMIC);
618 if (!vvfl) {
619 spin_unlock_bh(&adapter->mac_vlan_list_lock);
620 return;
623 vvfl->vsi_id = adapter->vsi_res->vsi_id;
624 vvfl->num_elements = count;
625 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
626 if (f->add) {
627 vvfl->vlan_id[i] = f->vlan;
628 i++;
629 f->add = false;
630 if (i == count)
631 break;
634 if (!more)
635 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
637 spin_unlock_bh(&adapter->mac_vlan_list_lock);
639 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
640 kfree(vvfl);
644 * i40evf_del_vlans
645 * @adapter: adapter structure
647 * Request that the PF remove one or more VLAN filters from our VSI.
649 void i40evf_del_vlans(struct i40evf_adapter *adapter)
651 struct virtchnl_vlan_filter_list *vvfl;
652 struct i40evf_vlan_filter *f, *ftmp;
653 int len, i = 0, count = 0;
654 bool more = false;
656 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
657 /* bail because we already have a command pending */
658 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
659 adapter->current_op);
660 return;
663 spin_lock_bh(&adapter->mac_vlan_list_lock);
665 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
666 if (f->remove)
667 count++;
669 if (!count) {
670 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
671 spin_unlock_bh(&adapter->mac_vlan_list_lock);
672 return;
674 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
676 len = sizeof(struct virtchnl_vlan_filter_list) +
677 (count * sizeof(u16));
678 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
679 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
680 count = (I40EVF_MAX_AQ_BUF_SIZE -
681 sizeof(struct virtchnl_vlan_filter_list)) /
682 sizeof(u16);
683 len = sizeof(struct virtchnl_vlan_filter_list) +
684 (count * sizeof(u16));
685 more = true;
687 vvfl = kzalloc(len, GFP_ATOMIC);
688 if (!vvfl) {
689 spin_unlock_bh(&adapter->mac_vlan_list_lock);
690 return;
693 vvfl->vsi_id = adapter->vsi_res->vsi_id;
694 vvfl->num_elements = count;
695 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
696 if (f->remove) {
697 vvfl->vlan_id[i] = f->vlan;
698 i++;
699 list_del(&f->list);
700 kfree(f);
701 if (i == count)
702 break;
705 if (!more)
706 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
708 spin_unlock_bh(&adapter->mac_vlan_list_lock);
710 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
711 kfree(vvfl);
715 * i40evf_set_promiscuous
716 * @adapter: adapter structure
717 * @flags: bitmask to control unicast/multicast promiscuous.
719 * Request that the PF enable promiscuous mode for our VSI.
721 void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
723 struct virtchnl_promisc_info vpi;
724 int promisc_all;
726 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
727 /* bail because we already have a command pending */
728 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
729 adapter->current_op);
730 return;
733 promisc_all = FLAG_VF_UNICAST_PROMISC |
734 FLAG_VF_MULTICAST_PROMISC;
735 if ((flags & promisc_all) == promisc_all) {
736 adapter->flags |= I40EVF_FLAG_PROMISC_ON;
737 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
738 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
741 if (flags & FLAG_VF_MULTICAST_PROMISC) {
742 adapter->flags |= I40EVF_FLAG_ALLMULTI_ON;
743 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
744 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
747 if (!flags) {
748 adapter->flags &= ~(I40EVF_FLAG_PROMISC_ON |
749 I40EVF_FLAG_ALLMULTI_ON);
750 adapter->aq_required &= ~(I40EVF_FLAG_AQ_RELEASE_PROMISC |
751 I40EVF_FLAG_AQ_RELEASE_ALLMULTI);
752 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
755 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
756 vpi.vsi_id = adapter->vsi_res->vsi_id;
757 vpi.flags = flags;
758 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
759 (u8 *)&vpi, sizeof(vpi));
763 * i40evf_request_stats
764 * @adapter: adapter structure
766 * Request VSI statistics from PF.
768 void i40evf_request_stats(struct i40evf_adapter *adapter)
770 struct virtchnl_queue_select vqs;
772 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
773 /* no error message, this isn't crucial */
774 return;
776 adapter->current_op = VIRTCHNL_OP_GET_STATS;
777 vqs.vsi_id = adapter->vsi_res->vsi_id;
778 /* queue maps are ignored for this message - only the vsi is used */
779 if (i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS,
780 (u8 *)&vqs, sizeof(vqs)))
781 /* if the request failed, don't lock out others */
782 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
786 * i40evf_get_hena
787 * @adapter: adapter structure
789 * Request hash enable capabilities from PF
791 void i40evf_get_hena(struct i40evf_adapter *adapter)
793 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
794 /* bail because we already have a command pending */
795 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
796 adapter->current_op);
797 return;
799 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
800 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
801 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS,
802 NULL, 0);
806 * i40evf_set_hena
807 * @adapter: adapter structure
809 * Request the PF to set our RSS hash capabilities
811 void i40evf_set_hena(struct i40evf_adapter *adapter)
813 struct virtchnl_rss_hena vrh;
815 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
816 /* bail because we already have a command pending */
817 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
818 adapter->current_op);
819 return;
821 vrh.hena = adapter->hena;
822 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
823 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
824 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA,
825 (u8 *)&vrh, sizeof(vrh));
829 * i40evf_set_rss_key
830 * @adapter: adapter structure
832 * Request the PF to set our RSS hash key
834 void i40evf_set_rss_key(struct i40evf_adapter *adapter)
836 struct virtchnl_rss_key *vrk;
837 int len;
839 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
840 /* bail because we already have a command pending */
841 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
842 adapter->current_op);
843 return;
845 len = sizeof(struct virtchnl_rss_key) +
846 (adapter->rss_key_size * sizeof(u8)) - 1;
847 vrk = kzalloc(len, GFP_KERNEL);
848 if (!vrk)
849 return;
850 vrk->vsi_id = adapter->vsi.id;
851 vrk->key_len = adapter->rss_key_size;
852 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
854 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
855 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
856 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY,
857 (u8 *)vrk, len);
858 kfree(vrk);
862 * i40evf_set_rss_lut
863 * @adapter: adapter structure
865 * Request the PF to set our RSS lookup table
867 void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
869 struct virtchnl_rss_lut *vrl;
870 int len;
872 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
873 /* bail because we already have a command pending */
874 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
875 adapter->current_op);
876 return;
878 len = sizeof(struct virtchnl_rss_lut) +
879 (adapter->rss_lut_size * sizeof(u8)) - 1;
880 vrl = kzalloc(len, GFP_KERNEL);
881 if (!vrl)
882 return;
883 vrl->vsi_id = adapter->vsi.id;
884 vrl->lut_entries = adapter->rss_lut_size;
885 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
886 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
887 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
888 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT,
889 (u8 *)vrl, len);
890 kfree(vrl);
894 * i40evf_enable_vlan_stripping
895 * @adapter: adapter structure
897 * Request VLAN header stripping to be enabled
899 void i40evf_enable_vlan_stripping(struct i40evf_adapter *adapter)
901 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
902 /* bail because we already have a command pending */
903 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
904 adapter->current_op);
905 return;
907 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
908 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
909 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
910 NULL, 0);
914 * i40evf_disable_vlan_stripping
915 * @adapter: adapter structure
917 * Request VLAN header stripping to be disabled
919 void i40evf_disable_vlan_stripping(struct i40evf_adapter *adapter)
921 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
922 /* bail because we already have a command pending */
923 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
924 adapter->current_op);
925 return;
927 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
928 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
929 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
930 NULL, 0);
934 * i40evf_print_link_message - print link up or down
935 * @adapter: adapter structure
937 * Log a message telling the world of our wonderous link status
939 static void i40evf_print_link_message(struct i40evf_adapter *adapter)
941 struct net_device *netdev = adapter->netdev;
942 char *speed = "Unknown ";
944 if (!adapter->link_up) {
945 netdev_info(netdev, "NIC Link is Down\n");
946 return;
949 switch (adapter->link_speed) {
950 case I40E_LINK_SPEED_40GB:
951 speed = "40 G";
952 break;
953 case I40E_LINK_SPEED_25GB:
954 speed = "25 G";
955 break;
956 case I40E_LINK_SPEED_20GB:
957 speed = "20 G";
958 break;
959 case I40E_LINK_SPEED_10GB:
960 speed = "10 G";
961 break;
962 case I40E_LINK_SPEED_1GB:
963 speed = "1000 M";
964 break;
965 case I40E_LINK_SPEED_100MB:
966 speed = "100 M";
967 break;
968 default:
969 break;
972 netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
976 * i40evf_enable_channel
977 * @adapter: adapter structure
979 * Request that the PF enable channels as specified by
980 * the user via tc tool.
982 void i40evf_enable_channels(struct i40evf_adapter *adapter)
984 struct virtchnl_tc_info *vti = NULL;
985 u16 len;
986 int i;
988 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
989 /* bail because we already have a command pending */
990 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
991 adapter->current_op);
992 return;
995 len = (adapter->num_tc * sizeof(struct virtchnl_channel_info)) +
996 sizeof(struct virtchnl_tc_info);
998 vti = kzalloc(len, GFP_KERNEL);
999 if (!vti)
1000 return;
1001 vti->num_tc = adapter->num_tc;
1002 for (i = 0; i < vti->num_tc; i++) {
1003 vti->list[i].count = adapter->ch_config.ch_info[i].count;
1004 vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
1005 vti->list[i].pad = 0;
1006 vti->list[i].max_tx_rate =
1007 adapter->ch_config.ch_info[i].max_tx_rate;
1010 adapter->ch_config.state = __I40EVF_TC_RUNNING;
1011 adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
1012 adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
1013 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_CHANNELS;
1014 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS,
1015 (u8 *)vti, len);
1016 kfree(vti);
1020 * i40evf_disable_channel
1021 * @adapter: adapter structure
1023 * Request that the PF disable channels that are configured
1025 void i40evf_disable_channels(struct i40evf_adapter *adapter)
1027 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1028 /* bail because we already have a command pending */
1029 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1030 adapter->current_op);
1031 return;
1034 adapter->ch_config.state = __I40EVF_TC_INVALID;
1035 adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
1036 adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
1037 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_CHANNELS;
1038 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS,
1039 NULL, 0);
1043 * i40evf_print_cloud_filter
1044 * @adapter: adapter structure
1045 * @f: cloud filter to print
1047 * Print the cloud filter
1049 static void i40evf_print_cloud_filter(struct i40evf_adapter *adapter,
1050 struct virtchnl_filter *f)
1052 switch (f->flow_type) {
1053 case VIRTCHNL_TCP_V4_FLOW:
1054 dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI4 src_ip %pI4 dst_port %hu src_port %hu\n",
1055 &f->data.tcp_spec.dst_mac,
1056 &f->data.tcp_spec.src_mac,
1057 ntohs(f->data.tcp_spec.vlan_id),
1058 &f->data.tcp_spec.dst_ip[0],
1059 &f->data.tcp_spec.src_ip[0],
1060 ntohs(f->data.tcp_spec.dst_port),
1061 ntohs(f->data.tcp_spec.src_port));
1062 break;
1063 case VIRTCHNL_TCP_V6_FLOW:
1064 dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI6 src_ip %pI6 dst_port %hu src_port %hu\n",
1065 &f->data.tcp_spec.dst_mac,
1066 &f->data.tcp_spec.src_mac,
1067 ntohs(f->data.tcp_spec.vlan_id),
1068 &f->data.tcp_spec.dst_ip,
1069 &f->data.tcp_spec.src_ip,
1070 ntohs(f->data.tcp_spec.dst_port),
1071 ntohs(f->data.tcp_spec.src_port));
1072 break;
1077 * i40evf_add_cloud_filter
1078 * @adapter: adapter structure
1080 * Request that the PF add cloud filters as specified
1081 * by the user via tc tool.
1083 void i40evf_add_cloud_filter(struct i40evf_adapter *adapter)
1085 struct i40evf_cloud_filter *cf;
1086 struct virtchnl_filter *f;
1087 int len = 0, count = 0;
1089 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1090 /* bail because we already have a command pending */
1091 dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1092 adapter->current_op);
1093 return;
1095 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1096 if (cf->add) {
1097 count++;
1098 break;
1101 if (!count) {
1102 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_CLOUD_FILTER;
1103 return;
1105 adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1107 len = sizeof(struct virtchnl_filter);
1108 f = kzalloc(len, GFP_KERNEL);
1109 if (!f)
1110 return;
1112 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1113 if (cf->add) {
1114 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1115 cf->add = false;
1116 cf->state = __I40EVF_CF_ADD_PENDING;
1117 i40evf_send_pf_msg(adapter,
1118 VIRTCHNL_OP_ADD_CLOUD_FILTER,
1119 (u8 *)f, len);
1122 kfree(f);
1126 * i40evf_del_cloud_filter
1127 * @adapter: adapter structure
1129 * Request that the PF delete cloud filters as specified
1130 * by the user via tc tool.
1132 void i40evf_del_cloud_filter(struct i40evf_adapter *adapter)
1134 struct i40evf_cloud_filter *cf, *cftmp;
1135 struct virtchnl_filter *f;
1136 int len = 0, count = 0;
1138 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1139 /* bail because we already have a command pending */
1140 dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1141 adapter->current_op);
1142 return;
1144 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1145 if (cf->del) {
1146 count++;
1147 break;
1150 if (!count) {
1151 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_CLOUD_FILTER;
1152 return;
1154 adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1156 len = sizeof(struct virtchnl_filter);
1157 f = kzalloc(len, GFP_KERNEL);
1158 if (!f)
1159 return;
1161 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1162 if (cf->del) {
1163 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1164 cf->del = false;
1165 cf->state = __I40EVF_CF_DEL_PENDING;
1166 i40evf_send_pf_msg(adapter,
1167 VIRTCHNL_OP_DEL_CLOUD_FILTER,
1168 (u8 *)f, len);
1171 kfree(f);
1175 * i40evf_request_reset
1176 * @adapter: adapter structure
1178 * Request that the PF reset this VF. No response is expected.
1180 void i40evf_request_reset(struct i40evf_adapter *adapter)
1182 /* Don't check CURRENT_OP - this is always higher priority */
1183 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
1184 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1188 * i40evf_virtchnl_completion
1189 * @adapter: adapter structure
1190 * @v_opcode: opcode sent by PF
1191 * @v_retval: retval sent by PF
1192 * @msg: message sent by PF
1193 * @msglen: message length
1195 * Asynchronous completion function for admin queue messages. Rather than busy
1196 * wait, we fire off our requests and assume that no errors will be returned.
1197 * This function handles the reply messages.
1199 void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
1200 enum virtchnl_ops v_opcode,
1201 i40e_status v_retval,
1202 u8 *msg, u16 msglen)
1204 struct net_device *netdev = adapter->netdev;
1206 if (v_opcode == VIRTCHNL_OP_EVENT) {
1207 struct virtchnl_pf_event *vpe =
1208 (struct virtchnl_pf_event *)msg;
1209 bool link_up = vpe->event_data.link_event.link_status;
1210 switch (vpe->event) {
1211 case VIRTCHNL_EVENT_LINK_CHANGE:
1212 adapter->link_speed =
1213 vpe->event_data.link_event.link_speed;
1215 /* we've already got the right link status, bail */
1216 if (adapter->link_up == link_up)
1217 break;
1219 if (link_up) {
1220 /* If we get link up message and start queues
1221 * before our queues are configured it will
1222 * trigger a TX hang. In that case, just ignore
1223 * the link status message,we'll get another one
1224 * after we enable queues and actually prepared
1225 * to send traffic.
1227 if (adapter->state != __I40EVF_RUNNING)
1228 break;
1230 /* For ADq enabled VF, we reconfigure VSIs and
1231 * re-allocate queues. Hence wait till all
1232 * queues are enabled.
1234 if (adapter->flags &
1235 I40EVF_FLAG_QUEUES_DISABLED)
1236 break;
1239 adapter->link_up = link_up;
1240 if (link_up) {
1241 netif_tx_start_all_queues(netdev);
1242 netif_carrier_on(netdev);
1243 } else {
1244 netif_tx_stop_all_queues(netdev);
1245 netif_carrier_off(netdev);
1247 i40evf_print_link_message(adapter);
1248 break;
1249 case VIRTCHNL_EVENT_RESET_IMPENDING:
1250 dev_info(&adapter->pdev->dev, "Reset warning received from the PF\n");
1251 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
1252 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
1253 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
1254 schedule_work(&adapter->reset_task);
1256 break;
1257 default:
1258 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
1259 vpe->event);
1260 break;
1262 return;
1264 if (v_retval) {
1265 switch (v_opcode) {
1266 case VIRTCHNL_OP_ADD_VLAN:
1267 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
1268 i40evf_stat_str(&adapter->hw, v_retval));
1269 break;
1270 case VIRTCHNL_OP_ADD_ETH_ADDR:
1271 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
1272 i40evf_stat_str(&adapter->hw, v_retval));
1273 break;
1274 case VIRTCHNL_OP_DEL_VLAN:
1275 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1276 i40evf_stat_str(&adapter->hw, v_retval));
1277 break;
1278 case VIRTCHNL_OP_DEL_ETH_ADDR:
1279 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1280 i40evf_stat_str(&adapter->hw, v_retval));
1281 break;
1282 case VIRTCHNL_OP_ENABLE_CHANNELS:
1283 dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
1284 i40evf_stat_str(&adapter->hw, v_retval));
1285 adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED;
1286 adapter->ch_config.state = __I40EVF_TC_INVALID;
1287 netdev_reset_tc(netdev);
1288 netif_tx_start_all_queues(netdev);
1289 break;
1290 case VIRTCHNL_OP_DISABLE_CHANNELS:
1291 dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
1292 i40evf_stat_str(&adapter->hw, v_retval));
1293 adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED;
1294 adapter->ch_config.state = __I40EVF_TC_RUNNING;
1295 netif_tx_start_all_queues(netdev);
1296 break;
1297 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
1298 struct i40evf_cloud_filter *cf, *cftmp;
1300 list_for_each_entry_safe(cf, cftmp,
1301 &adapter->cloud_filter_list,
1302 list) {
1303 if (cf->state == __I40EVF_CF_ADD_PENDING) {
1304 cf->state = __I40EVF_CF_INVALID;
1305 dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
1306 i40evf_stat_str(&adapter->hw,
1307 v_retval));
1308 i40evf_print_cloud_filter(adapter,
1309 &cf->f);
1310 list_del(&cf->list);
1311 kfree(cf);
1312 adapter->num_cloud_filters--;
1316 break;
1317 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
1318 struct i40evf_cloud_filter *cf;
1320 list_for_each_entry(cf, &adapter->cloud_filter_list,
1321 list) {
1322 if (cf->state == __I40EVF_CF_DEL_PENDING) {
1323 cf->state = __I40EVF_CF_ACTIVE;
1324 dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
1325 i40evf_stat_str(&adapter->hw,
1326 v_retval));
1327 i40evf_print_cloud_filter(adapter,
1328 &cf->f);
1332 break;
1333 default:
1334 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
1335 v_retval,
1336 i40evf_stat_str(&adapter->hw, v_retval),
1337 v_opcode);
1340 switch (v_opcode) {
1341 case VIRTCHNL_OP_GET_STATS: {
1342 struct i40e_eth_stats *stats =
1343 (struct i40e_eth_stats *)msg;
1344 netdev->stats.rx_packets = stats->rx_unicast +
1345 stats->rx_multicast +
1346 stats->rx_broadcast;
1347 netdev->stats.tx_packets = stats->tx_unicast +
1348 stats->tx_multicast +
1349 stats->tx_broadcast;
1350 netdev->stats.rx_bytes = stats->rx_bytes;
1351 netdev->stats.tx_bytes = stats->tx_bytes;
1352 netdev->stats.tx_errors = stats->tx_errors;
1353 netdev->stats.rx_dropped = stats->rx_discards;
1354 netdev->stats.tx_dropped = stats->tx_discards;
1355 adapter->current_stats = *stats;
1357 break;
1358 case VIRTCHNL_OP_GET_VF_RESOURCES: {
1359 u16 len = sizeof(struct virtchnl_vf_resource) +
1360 I40E_MAX_VF_VSI *
1361 sizeof(struct virtchnl_vsi_resource);
1362 memcpy(adapter->vf_res, msg, min(msglen, len));
1363 i40evf_validate_num_queues(adapter);
1364 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
1365 /* restore current mac address */
1366 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1367 i40evf_process_config(adapter);
1369 break;
1370 case VIRTCHNL_OP_ENABLE_QUEUES:
1371 /* enable transmits */
1372 i40evf_irq_enable(adapter, true);
1373 adapter->flags &= ~I40EVF_FLAG_QUEUES_DISABLED;
1374 break;
1375 case VIRTCHNL_OP_DISABLE_QUEUES:
1376 i40evf_free_all_tx_resources(adapter);
1377 i40evf_free_all_rx_resources(adapter);
1378 if (adapter->state == __I40EVF_DOWN_PENDING) {
1379 adapter->state = __I40EVF_DOWN;
1380 wake_up(&adapter->down_waitqueue);
1382 break;
1383 case VIRTCHNL_OP_VERSION:
1384 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1385 /* Don't display an error if we get these out of sequence.
1386 * If the firmware needed to get kicked, we'll get these and
1387 * it's no problem.
1389 if (v_opcode != adapter->current_op)
1390 return;
1391 break;
1392 case VIRTCHNL_OP_IWARP:
1393 /* Gobble zero-length replies from the PF. They indicate that
1394 * a previous message was received OK, and the client doesn't
1395 * care about that.
1397 if (msglen && CLIENT_ENABLED(adapter))
1398 i40evf_notify_client_message(&adapter->vsi,
1399 msg, msglen);
1400 break;
1402 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
1403 adapter->client_pending &=
1404 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
1405 break;
1406 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
1407 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
1408 if (msglen == sizeof(*vrh))
1409 adapter->hena = vrh->hena;
1410 else
1411 dev_warn(&adapter->pdev->dev,
1412 "Invalid message %d from PF\n", v_opcode);
1414 break;
1415 case VIRTCHNL_OP_REQUEST_QUEUES: {
1416 struct virtchnl_vf_res_request *vfres =
1417 (struct virtchnl_vf_res_request *)msg;
1418 if (vfres->num_queue_pairs != adapter->num_req_queues) {
1419 dev_info(&adapter->pdev->dev,
1420 "Requested %d queues, PF can support %d\n",
1421 adapter->num_req_queues,
1422 vfres->num_queue_pairs);
1423 adapter->num_req_queues = 0;
1424 adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED;
1427 break;
1428 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
1429 struct i40evf_cloud_filter *cf;
1431 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1432 if (cf->state == __I40EVF_CF_ADD_PENDING)
1433 cf->state = __I40EVF_CF_ACTIVE;
1436 break;
1437 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
1438 struct i40evf_cloud_filter *cf, *cftmp;
1440 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
1441 list) {
1442 if (cf->state == __I40EVF_CF_DEL_PENDING) {
1443 cf->state = __I40EVF_CF_INVALID;
1444 list_del(&cf->list);
1445 kfree(cf);
1446 adapter->num_cloud_filters--;
1450 break;
1451 default:
1452 if (adapter->current_op && (v_opcode != adapter->current_op))
1453 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
1454 adapter->current_op, v_opcode);
1455 break;
1456 } /* switch v_opcode */
1457 adapter->current_op = VIRTCHNL_OP_UNKNOWN;