1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
3
4 #include "i40evf.h"
5 #include "i40e_prototype.h"
6 #include "i40evf_client.h"
7
8 /* busy wait delay in msec */
9 #define I40EVF_BUSY_WAIT_DELAY 10
10 #define I40EVF_BUSY_WAIT_COUNT 50
11
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
18 *
19 * Send message to PF and print status if failure.
20 **/
i40evf_send_pf_msg(struct i40evf_adapter * adapter,enum virtchnl_ops op,u8 * msg,u16 len)21 static int i40evf_send_pf_msg(struct i40evf_adapter *adapter,
22 enum virtchnl_ops op, u8 *msg, u16 len)
23 {
24 struct i40e_hw *hw = &adapter->hw;
25 i40e_status err;
26
27 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
28 return 0; /* nothing to see here, move along */
29
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;
36 }
37
38 /**
39 * i40evf_send_api_ver
40 * @adapter: adapter structure
41 *
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 **/
i40evf_send_api_ver(struct i40evf_adapter * adapter)46 int i40evf_send_api_ver(struct i40evf_adapter *adapter)
47 {
48 struct virtchnl_version_info vvi;
49
50 vvi.major = VIRTCHNL_VERSION_MAJOR;
51 vvi.minor = VIRTCHNL_VERSION_MINOR;
52
53 return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
54 sizeof(vvi));
55 }
56
57 /**
58 * i40evf_verify_api_ver
59 * @adapter: adapter structure
60 *
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 **/
i40evf_verify_api_ver(struct i40evf_adapter * adapter)66 int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
67 {
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;
73
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;
79 }
80
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.
85 */
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;
92 }
93
94
95 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
96 if (err)
97 goto out_alloc;
98
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;
104 }
105
106 pf_vvi = (struct virtchnl_version_info *)event.msg_buf;
107 adapter->pf_version = *pf_vvi;
108
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;
113
114 out_alloc:
115 kfree(event.msg_buf);
116 out:
117 return err;
118 }
119
120 /**
121 * i40evf_send_vf_config_msg
122 * @adapter: adapter structure
123 *
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.
127 **/
i40evf_send_vf_config_msg(struct i40evf_adapter * adapter)128 int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
129 {
130 u32 caps;
131
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;
143
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);
154 }
155
156 /**
157 * i40evf_get_vf_config
158 * @adapter: private adapter structure
159 *
160 * Get VF configuration from PF and populate hw structure. Must be called after
161 * admin queue is initialized. Busy waits until response is received from PF,
162 * with maximum timeout. Response from PF is returned in the buffer for further
163 * processing by the caller.
164 **/
i40evf_get_vf_config(struct i40evf_adapter * adapter)165 int i40evf_get_vf_config(struct i40evf_adapter *adapter)
166 {
167 struct i40e_hw *hw = &adapter->hw;
168 struct i40e_arq_event_info event;
169 enum virtchnl_ops op;
170 i40e_status err;
171 u16 len;
172
173 len = sizeof(struct virtchnl_vf_resource) +
174 I40E_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
175 event.buf_len = len;
176 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
177 if (!event.msg_buf) {
178 err = -ENOMEM;
179 goto out;
180 }
181
182 while (1) {
183 /* When the AQ is empty, i40evf_clean_arq_element will return
184 * nonzero and this loop will terminate.
185 */
186 err = i40evf_clean_arq_element(hw, &event, NULL);
187 if (err)
188 goto out_alloc;
189 op =
190 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
191 if (op == VIRTCHNL_OP_GET_VF_RESOURCES)
192 break;
193 }
194
195 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
196 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
197
198 i40e_vf_parse_hw_config(hw, adapter->vf_res);
199 out_alloc:
200 kfree(event.msg_buf);
201 out:
202 return err;
203 }
204
205 /**
206 * i40evf_configure_queues
207 * @adapter: adapter structure
208 *
209 * Request that the PF set up our (previously allocated) queues.
210 **/
i40evf_configure_queues(struct i40evf_adapter * adapter)211 void i40evf_configure_queues(struct i40evf_adapter *adapter)
212 {
213 struct virtchnl_vsi_queue_config_info *vqci;
214 struct virtchnl_queue_pair_info *vqpi;
215 int pairs = adapter->num_active_queues;
216 int i, len, max_frame = I40E_MAX_RXBUFFER;
217
218 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
219 /* bail because we already have a command pending */
220 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
221 adapter->current_op);
222 return;
223 }
224 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
225 len = sizeof(struct virtchnl_vsi_queue_config_info) +
226 (sizeof(struct virtchnl_queue_pair_info) * pairs);
227 vqci = kzalloc(len, GFP_KERNEL);
228 if (!vqci)
229 return;
230
231 /* Limit maximum frame size when jumbo frames is not enabled */
232 if (!(adapter->flags & I40EVF_FLAG_LEGACY_RX) &&
233 (adapter->netdev->mtu <= ETH_DATA_LEN))
234 max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
235
236 vqci->vsi_id = adapter->vsi_res->vsi_id;
237 vqci->num_queue_pairs = pairs;
238 vqpi = vqci->qpair;
239 /* Size check is not needed here - HW max is 16 queue pairs, and we
240 * can fit info for 31 of them into the AQ buffer before it overflows.
241 */
242 for (i = 0; i < pairs; i++) {
243 vqpi->txq.vsi_id = vqci->vsi_id;
244 vqpi->txq.queue_id = i;
245 vqpi->txq.ring_len = adapter->tx_rings[i].count;
246 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
247 vqpi->rxq.vsi_id = vqci->vsi_id;
248 vqpi->rxq.queue_id = i;
249 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
250 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
251 vqpi->rxq.max_pkt_size = max_frame;
252 vqpi->rxq.databuffer_size =
253 ALIGN(adapter->rx_rings[i].rx_buf_len,
254 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
255 vqpi++;
256 }
257
258 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
259 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
260 (u8 *)vqci, len);
261 kfree(vqci);
262 }
263
264 /**
265 * i40evf_enable_queues
266 * @adapter: adapter structure
267 *
268 * Request that the PF enable all of our queues.
269 **/
i40evf_enable_queues(struct i40evf_adapter * adapter)270 void i40evf_enable_queues(struct i40evf_adapter *adapter)
271 {
272 struct virtchnl_queue_select vqs;
273
274 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
275 /* bail because we already have a command pending */
276 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
277 adapter->current_op);
278 return;
279 }
280 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
281 vqs.vsi_id = adapter->vsi_res->vsi_id;
282 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
283 vqs.rx_queues = vqs.tx_queues;
284 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
285 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
286 (u8 *)&vqs, sizeof(vqs));
287 }
288
289 /**
290 * i40evf_disable_queues
291 * @adapter: adapter structure
292 *
293 * Request that the PF disable all of our queues.
294 **/
i40evf_disable_queues(struct i40evf_adapter * adapter)295 void i40evf_disable_queues(struct i40evf_adapter *adapter)
296 {
297 struct virtchnl_queue_select vqs;
298
299 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
300 /* bail because we already have a command pending */
301 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
302 adapter->current_op);
303 return;
304 }
305 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
306 vqs.vsi_id = adapter->vsi_res->vsi_id;
307 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
308 vqs.rx_queues = vqs.tx_queues;
309 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
310 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
311 (u8 *)&vqs, sizeof(vqs));
312 }
313
314 /**
315 * i40evf_map_queues
316 * @adapter: adapter structure
317 *
318 * Request that the PF map queues to interrupt vectors. Misc causes, including
319 * admin queue, are always mapped to vector 0.
320 **/
i40evf_map_queues(struct i40evf_adapter * adapter)321 void i40evf_map_queues(struct i40evf_adapter *adapter)
322 {
323 struct virtchnl_irq_map_info *vimi;
324 struct virtchnl_vector_map *vecmap;
325 int v_idx, q_vectors, len;
326 struct i40e_q_vector *q_vector;
327
328 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
329 /* bail because we already have a command pending */
330 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
331 adapter->current_op);
332 return;
333 }
334 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
335
336 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
337
338 len = sizeof(struct virtchnl_irq_map_info) +
339 (adapter->num_msix_vectors *
340 sizeof(struct virtchnl_vector_map));
341 vimi = kzalloc(len, GFP_KERNEL);
342 if (!vimi)
343 return;
344
345 vimi->num_vectors = adapter->num_msix_vectors;
346 /* Queue vectors first */
347 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
348 q_vector = &adapter->q_vectors[v_idx];
349 vecmap = &vimi->vecmap[v_idx];
350
351 vecmap->vsi_id = adapter->vsi_res->vsi_id;
352 vecmap->vector_id = v_idx + NONQ_VECS;
353 vecmap->txq_map = q_vector->ring_mask;
354 vecmap->rxq_map = q_vector->ring_mask;
355 vecmap->rxitr_idx = I40E_RX_ITR;
356 vecmap->txitr_idx = I40E_TX_ITR;
357 }
358 /* Misc vector last - this is only for AdminQ messages */
359 vecmap = &vimi->vecmap[v_idx];
360 vecmap->vsi_id = adapter->vsi_res->vsi_id;
361 vecmap->vector_id = 0;
362 vecmap->txq_map = 0;
363 vecmap->rxq_map = 0;
364
365 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
366 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
367 (u8 *)vimi, len);
368 kfree(vimi);
369 }
370
371 /**
372 * i40evf_request_queues
373 * @adapter: adapter structure
374 * @num: number of requested queues
375 *
376 * We get a default number of queues from the PF. This enables us to request a
377 * different number. Returns 0 on success, negative on failure
378 **/
i40evf_request_queues(struct i40evf_adapter * adapter,int num)379 int i40evf_request_queues(struct i40evf_adapter *adapter, int num)
380 {
381 struct virtchnl_vf_res_request vfres;
382
383 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
384 /* bail because we already have a command pending */
385 dev_err(&adapter->pdev->dev, "Cannot request queues, command %d pending\n",
386 adapter->current_op);
387 return -EBUSY;
388 }
389
390 vfres.num_queue_pairs = num;
391
392 adapter->current_op = VIRTCHNL_OP_REQUEST_QUEUES;
393 adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
394 return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_REQUEST_QUEUES,
395 (u8 *)&vfres, sizeof(vfres));
396 }
397
398 /**
399 * i40evf_add_ether_addrs
400 * @adapter: adapter structure
401 *
402 * Request that the PF add one or more addresses to our filters.
403 **/
i40evf_add_ether_addrs(struct i40evf_adapter * adapter)404 void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
405 {
406 struct virtchnl_ether_addr_list *veal;
407 int len, i = 0, count = 0;
408 struct i40evf_mac_filter *f;
409 bool more = false;
410
411 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
412 /* bail because we already have a command pending */
413 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
414 adapter->current_op);
415 return;
416 }
417
418 spin_lock_bh(&adapter->mac_vlan_list_lock);
419
420 list_for_each_entry(f, &adapter->mac_filter_list, list) {
421 if (f->add)
422 count++;
423 }
424 if (!count) {
425 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
426 spin_unlock_bh(&adapter->mac_vlan_list_lock);
427 return;
428 }
429 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
430
431 len = sizeof(struct virtchnl_ether_addr_list) +
432 (count * sizeof(struct virtchnl_ether_addr));
433 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
434 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
435 count = (I40EVF_MAX_AQ_BUF_SIZE -
436 sizeof(struct virtchnl_ether_addr_list)) /
437 sizeof(struct virtchnl_ether_addr);
438 len = sizeof(struct virtchnl_ether_addr_list) +
439 (count * sizeof(struct virtchnl_ether_addr));
440 more = true;
441 }
442
443 veal = kzalloc(len, GFP_ATOMIC);
444 if (!veal) {
445 spin_unlock_bh(&adapter->mac_vlan_list_lock);
446 return;
447 }
448
449 veal->vsi_id = adapter->vsi_res->vsi_id;
450 veal->num_elements = count;
451 list_for_each_entry(f, &adapter->mac_filter_list, list) {
452 if (f->add) {
453 ether_addr_copy(veal->list[i].addr, f->macaddr);
454 i++;
455 f->add = false;
456 if (i == count)
457 break;
458 }
459 }
460 if (!more)
461 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
462
463 spin_unlock_bh(&adapter->mac_vlan_list_lock);
464
465 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR,
466 (u8 *)veal, len);
467 kfree(veal);
468 }
469
470 /**
471 * i40evf_del_ether_addrs
472 * @adapter: adapter structure
473 *
474 * Request that the PF remove one or more addresses from our filters.
475 **/
i40evf_del_ether_addrs(struct i40evf_adapter * adapter)476 void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
477 {
478 struct virtchnl_ether_addr_list *veal;
479 struct i40evf_mac_filter *f, *ftmp;
480 int len, i = 0, count = 0;
481 bool more = false;
482
483 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
484 /* bail because we already have a command pending */
485 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
486 adapter->current_op);
487 return;
488 }
489
490 spin_lock_bh(&adapter->mac_vlan_list_lock);
491
492 list_for_each_entry(f, &adapter->mac_filter_list, list) {
493 if (f->remove)
494 count++;
495 }
496 if (!count) {
497 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
498 spin_unlock_bh(&adapter->mac_vlan_list_lock);
499 return;
500 }
501 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
502
503 len = sizeof(struct virtchnl_ether_addr_list) +
504 (count * sizeof(struct virtchnl_ether_addr));
505 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
506 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
507 count = (I40EVF_MAX_AQ_BUF_SIZE -
508 sizeof(struct virtchnl_ether_addr_list)) /
509 sizeof(struct virtchnl_ether_addr);
510 len = sizeof(struct virtchnl_ether_addr_list) +
511 (count * sizeof(struct virtchnl_ether_addr));
512 more = true;
513 }
514 veal = kzalloc(len, GFP_ATOMIC);
515 if (!veal) {
516 spin_unlock_bh(&adapter->mac_vlan_list_lock);
517 return;
518 }
519
520 veal->vsi_id = adapter->vsi_res->vsi_id;
521 veal->num_elements = count;
522 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
523 if (f->remove) {
524 ether_addr_copy(veal->list[i].addr, f->macaddr);
525 i++;
526 list_del(&f->list);
527 kfree(f);
528 if (i == count)
529 break;
530 }
531 }
532 if (!more)
533 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
534
535 spin_unlock_bh(&adapter->mac_vlan_list_lock);
536
537 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR,
538 (u8 *)veal, len);
539 kfree(veal);
540 }
541
542 /**
543 * i40evf_add_vlans
544 * @adapter: adapter structure
545 *
546 * Request that the PF add one or more VLAN filters to our VSI.
547 **/
i40evf_add_vlans(struct i40evf_adapter * adapter)548 void i40evf_add_vlans(struct i40evf_adapter *adapter)
549 {
550 struct virtchnl_vlan_filter_list *vvfl;
551 int len, i = 0, count = 0;
552 struct i40evf_vlan_filter *f;
553 bool more = false;
554
555 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
556 /* bail because we already have a command pending */
557 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
558 adapter->current_op);
559 return;
560 }
561
562 spin_lock_bh(&adapter->mac_vlan_list_lock);
563
564 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
565 if (f->add)
566 count++;
567 }
568 if (!count) {
569 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
570 spin_unlock_bh(&adapter->mac_vlan_list_lock);
571 return;
572 }
573 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
574
575 len = sizeof(struct virtchnl_vlan_filter_list) +
576 (count * sizeof(u16));
577 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
578 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
579 count = (I40EVF_MAX_AQ_BUF_SIZE -
580 sizeof(struct virtchnl_vlan_filter_list)) /
581 sizeof(u16);
582 len = sizeof(struct virtchnl_vlan_filter_list) +
583 (count * sizeof(u16));
584 more = true;
585 }
586 vvfl = kzalloc(len, GFP_ATOMIC);
587 if (!vvfl) {
588 spin_unlock_bh(&adapter->mac_vlan_list_lock);
589 return;
590 }
591
592 vvfl->vsi_id = adapter->vsi_res->vsi_id;
593 vvfl->num_elements = count;
594 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
595 if (f->add) {
596 vvfl->vlan_id[i] = f->vlan;
597 i++;
598 f->add = false;
599 if (i == count)
600 break;
601 }
602 }
603 if (!more)
604 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
605
606 spin_unlock_bh(&adapter->mac_vlan_list_lock);
607
608 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
609 kfree(vvfl);
610 }
611
612 /**
613 * i40evf_del_vlans
614 * @adapter: adapter structure
615 *
616 * Request that the PF remove one or more VLAN filters from our VSI.
617 **/
i40evf_del_vlans(struct i40evf_adapter * adapter)618 void i40evf_del_vlans(struct i40evf_adapter *adapter)
619 {
620 struct virtchnl_vlan_filter_list *vvfl;
621 struct i40evf_vlan_filter *f, *ftmp;
622 int len, i = 0, count = 0;
623 bool more = false;
624
625 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
626 /* bail because we already have a command pending */
627 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
628 adapter->current_op);
629 return;
630 }
631
632 spin_lock_bh(&adapter->mac_vlan_list_lock);
633
634 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
635 if (f->remove)
636 count++;
637 }
638 if (!count) {
639 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
640 spin_unlock_bh(&adapter->mac_vlan_list_lock);
641 return;
642 }
643 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
644
645 len = sizeof(struct virtchnl_vlan_filter_list) +
646 (count * sizeof(u16));
647 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
648 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
649 count = (I40EVF_MAX_AQ_BUF_SIZE -
650 sizeof(struct virtchnl_vlan_filter_list)) /
651 sizeof(u16);
652 len = sizeof(struct virtchnl_vlan_filter_list) +
653 (count * sizeof(u16));
654 more = true;
655 }
656 vvfl = kzalloc(len, GFP_ATOMIC);
657 if (!vvfl) {
658 spin_unlock_bh(&adapter->mac_vlan_list_lock);
659 return;
660 }
661
662 vvfl->vsi_id = adapter->vsi_res->vsi_id;
663 vvfl->num_elements = count;
664 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
665 if (f->remove) {
666 vvfl->vlan_id[i] = f->vlan;
667 i++;
668 list_del(&f->list);
669 kfree(f);
670 if (i == count)
671 break;
672 }
673 }
674 if (!more)
675 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
676
677 spin_unlock_bh(&adapter->mac_vlan_list_lock);
678
679 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
680 kfree(vvfl);
681 }
682
683 /**
684 * i40evf_set_promiscuous
685 * @adapter: adapter structure
686 * @flags: bitmask to control unicast/multicast promiscuous.
687 *
688 * Request that the PF enable promiscuous mode for our VSI.
689 **/
i40evf_set_promiscuous(struct i40evf_adapter * adapter,int flags)690 void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
691 {
692 struct virtchnl_promisc_info vpi;
693 int promisc_all;
694
695 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
696 /* bail because we already have a command pending */
697 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
698 adapter->current_op);
699 return;
700 }
701
702 promisc_all = FLAG_VF_UNICAST_PROMISC |
703 FLAG_VF_MULTICAST_PROMISC;
704 if ((flags & promisc_all) == promisc_all) {
705 adapter->flags |= I40EVF_FLAG_PROMISC_ON;
706 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
707 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
708 }
709
710 if (flags & FLAG_VF_MULTICAST_PROMISC) {
711 adapter->flags |= I40EVF_FLAG_ALLMULTI_ON;
712 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
713 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
714 }
715
716 if (!flags) {
717 adapter->flags &= ~(I40EVF_FLAG_PROMISC_ON |
718 I40EVF_FLAG_ALLMULTI_ON);
719 adapter->aq_required &= ~(I40EVF_FLAG_AQ_RELEASE_PROMISC |
720 I40EVF_FLAG_AQ_RELEASE_ALLMULTI);
721 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
722 }
723
724 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
725 vpi.vsi_id = adapter->vsi_res->vsi_id;
726 vpi.flags = flags;
727 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
728 (u8 *)&vpi, sizeof(vpi));
729 }
730
731 /**
732 * i40evf_request_stats
733 * @adapter: adapter structure
734 *
735 * Request VSI statistics from PF.
736 **/
i40evf_request_stats(struct i40evf_adapter * adapter)737 void i40evf_request_stats(struct i40evf_adapter *adapter)
738 {
739 struct virtchnl_queue_select vqs;
740
741 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
742 /* no error message, this isn't crucial */
743 return;
744 }
745 adapter->current_op = VIRTCHNL_OP_GET_STATS;
746 vqs.vsi_id = adapter->vsi_res->vsi_id;
747 /* queue maps are ignored for this message - only the vsi is used */
748 if (i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS,
749 (u8 *)&vqs, sizeof(vqs)))
750 /* if the request failed, don't lock out others */
751 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
752 }
753
754 /**
755 * i40evf_get_hena
756 * @adapter: adapter structure
757 *
758 * Request hash enable capabilities from PF
759 **/
i40evf_get_hena(struct i40evf_adapter * adapter)760 void i40evf_get_hena(struct i40evf_adapter *adapter)
761 {
762 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
763 /* bail because we already have a command pending */
764 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
765 adapter->current_op);
766 return;
767 }
768 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
769 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
770 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS,
771 NULL, 0);
772 }
773
774 /**
775 * i40evf_set_hena
776 * @adapter: adapter structure
777 *
778 * Request the PF to set our RSS hash capabilities
779 **/
i40evf_set_hena(struct i40evf_adapter * adapter)780 void i40evf_set_hena(struct i40evf_adapter *adapter)
781 {
782 struct virtchnl_rss_hena vrh;
783
784 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
785 /* bail because we already have a command pending */
786 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
787 adapter->current_op);
788 return;
789 }
790 vrh.hena = adapter->hena;
791 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
792 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
793 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA,
794 (u8 *)&vrh, sizeof(vrh));
795 }
796
797 /**
798 * i40evf_set_rss_key
799 * @adapter: adapter structure
800 *
801 * Request the PF to set our RSS hash key
802 **/
i40evf_set_rss_key(struct i40evf_adapter * adapter)803 void i40evf_set_rss_key(struct i40evf_adapter *adapter)
804 {
805 struct virtchnl_rss_key *vrk;
806 int len;
807
808 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
809 /* bail because we already have a command pending */
810 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
811 adapter->current_op);
812 return;
813 }
814 len = sizeof(struct virtchnl_rss_key) +
815 (adapter->rss_key_size * sizeof(u8)) - 1;
816 vrk = kzalloc(len, GFP_KERNEL);
817 if (!vrk)
818 return;
819 vrk->vsi_id = adapter->vsi.id;
820 vrk->key_len = adapter->rss_key_size;
821 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
822
823 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
824 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
825 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY,
826 (u8 *)vrk, len);
827 kfree(vrk);
828 }
829
830 /**
831 * i40evf_set_rss_lut
832 * @adapter: adapter structure
833 *
834 * Request the PF to set our RSS lookup table
835 **/
i40evf_set_rss_lut(struct i40evf_adapter * adapter)836 void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
837 {
838 struct virtchnl_rss_lut *vrl;
839 int len;
840
841 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
842 /* bail because we already have a command pending */
843 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
844 adapter->current_op);
845 return;
846 }
847 len = sizeof(struct virtchnl_rss_lut) +
848 (adapter->rss_lut_size * sizeof(u8)) - 1;
849 vrl = kzalloc(len, GFP_KERNEL);
850 if (!vrl)
851 return;
852 vrl->vsi_id = adapter->vsi.id;
853 vrl->lut_entries = adapter->rss_lut_size;
854 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
855 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
856 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
857 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT,
858 (u8 *)vrl, len);
859 kfree(vrl);
860 }
861
862 /**
863 * i40evf_enable_vlan_stripping
864 * @adapter: adapter structure
865 *
866 * Request VLAN header stripping to be enabled
867 **/
i40evf_enable_vlan_stripping(struct i40evf_adapter * adapter)868 void i40evf_enable_vlan_stripping(struct i40evf_adapter *adapter)
869 {
870 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
871 /* bail because we already have a command pending */
872 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
873 adapter->current_op);
874 return;
875 }
876 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
877 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
878 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
879 NULL, 0);
880 }
881
882 /**
883 * i40evf_disable_vlan_stripping
884 * @adapter: adapter structure
885 *
886 * Request VLAN header stripping to be disabled
887 **/
i40evf_disable_vlan_stripping(struct i40evf_adapter * adapter)888 void i40evf_disable_vlan_stripping(struct i40evf_adapter *adapter)
889 {
890 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
891 /* bail because we already have a command pending */
892 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
893 adapter->current_op);
894 return;
895 }
896 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
897 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
898 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
899 NULL, 0);
900 }
901
902 /**
903 * i40evf_print_link_message - print link up or down
904 * @adapter: adapter structure
905 *
906 * Log a message telling the world of our wonderous link status
907 */
i40evf_print_link_message(struct i40evf_adapter * adapter)908 static void i40evf_print_link_message(struct i40evf_adapter *adapter)
909 {
910 struct net_device *netdev = adapter->netdev;
911 char *speed = "Unknown ";
912
913 if (!adapter->link_up) {
914 netdev_info(netdev, "NIC Link is Down\n");
915 return;
916 }
917
918 switch (adapter->link_speed) {
919 case I40E_LINK_SPEED_40GB:
920 speed = "40 G";
921 break;
922 case I40E_LINK_SPEED_25GB:
923 speed = "25 G";
924 break;
925 case I40E_LINK_SPEED_20GB:
926 speed = "20 G";
927 break;
928 case I40E_LINK_SPEED_10GB:
929 speed = "10 G";
930 break;
931 case I40E_LINK_SPEED_1GB:
932 speed = "1000 M";
933 break;
934 case I40E_LINK_SPEED_100MB:
935 speed = "100 M";
936 break;
937 default:
938 break;
939 }
940
941 netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
942 }
943
944 /**
945 * i40evf_enable_channel
946 * @adapter: adapter structure
947 *
948 * Request that the PF enable channels as specified by
949 * the user via tc tool.
950 **/
i40evf_enable_channels(struct i40evf_adapter * adapter)951 void i40evf_enable_channels(struct i40evf_adapter *adapter)
952 {
953 struct virtchnl_tc_info *vti = NULL;
954 u16 len;
955 int i;
956
957 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
958 /* bail because we already have a command pending */
959 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
960 adapter->current_op);
961 return;
962 }
963
964 len = (adapter->num_tc * sizeof(struct virtchnl_channel_info)) +
965 sizeof(struct virtchnl_tc_info);
966
967 vti = kzalloc(len, GFP_KERNEL);
968 if (!vti)
969 return;
970 vti->num_tc = adapter->num_tc;
971 for (i = 0; i < vti->num_tc; i++) {
972 vti->list[i].count = adapter->ch_config.ch_info[i].count;
973 vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
974 vti->list[i].pad = 0;
975 vti->list[i].max_tx_rate =
976 adapter->ch_config.ch_info[i].max_tx_rate;
977 }
978
979 adapter->ch_config.state = __I40EVF_TC_RUNNING;
980 adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
981 adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
982 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_CHANNELS;
983 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS,
984 (u8 *)vti, len);
985 kfree(vti);
986 }
987
988 /**
989 * i40evf_disable_channel
990 * @adapter: adapter structure
991 *
992 * Request that the PF disable channels that are configured
993 **/
i40evf_disable_channels(struct i40evf_adapter * adapter)994 void i40evf_disable_channels(struct i40evf_adapter *adapter)
995 {
996 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
997 /* bail because we already have a command pending */
998 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
999 adapter->current_op);
1000 return;
1001 }
1002
1003 adapter->ch_config.state = __I40EVF_TC_INVALID;
1004 adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
1005 adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
1006 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_CHANNELS;
1007 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS,
1008 NULL, 0);
1009 }
1010
1011 /**
1012 * i40evf_print_cloud_filter
1013 * @adapter: adapter structure
1014 * @f: cloud filter to print
1015 *
1016 * Print the cloud filter
1017 **/
i40evf_print_cloud_filter(struct i40evf_adapter * adapter,struct virtchnl_filter * f)1018 static void i40evf_print_cloud_filter(struct i40evf_adapter *adapter,
1019 struct virtchnl_filter *f)
1020 {
1021 switch (f->flow_type) {
1022 case VIRTCHNL_TCP_V4_FLOW:
1023 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",
1024 &f->data.tcp_spec.dst_mac,
1025 &f->data.tcp_spec.src_mac,
1026 ntohs(f->data.tcp_spec.vlan_id),
1027 &f->data.tcp_spec.dst_ip[0],
1028 &f->data.tcp_spec.src_ip[0],
1029 ntohs(f->data.tcp_spec.dst_port),
1030 ntohs(f->data.tcp_spec.src_port));
1031 break;
1032 case VIRTCHNL_TCP_V6_FLOW:
1033 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",
1034 &f->data.tcp_spec.dst_mac,
1035 &f->data.tcp_spec.src_mac,
1036 ntohs(f->data.tcp_spec.vlan_id),
1037 &f->data.tcp_spec.dst_ip,
1038 &f->data.tcp_spec.src_ip,
1039 ntohs(f->data.tcp_spec.dst_port),
1040 ntohs(f->data.tcp_spec.src_port));
1041 break;
1042 }
1043 }
1044
1045 /**
1046 * i40evf_add_cloud_filter
1047 * @adapter: adapter structure
1048 *
1049 * Request that the PF add cloud filters as specified
1050 * by the user via tc tool.
1051 **/
i40evf_add_cloud_filter(struct i40evf_adapter * adapter)1052 void i40evf_add_cloud_filter(struct i40evf_adapter *adapter)
1053 {
1054 struct i40evf_cloud_filter *cf;
1055 struct virtchnl_filter *f;
1056 int len = 0, count = 0;
1057
1058 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1059 /* bail because we already have a command pending */
1060 dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1061 adapter->current_op);
1062 return;
1063 }
1064 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1065 if (cf->add) {
1066 count++;
1067 break;
1068 }
1069 }
1070 if (!count) {
1071 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_CLOUD_FILTER;
1072 return;
1073 }
1074 adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1075
1076 len = sizeof(struct virtchnl_filter);
1077 f = kzalloc(len, GFP_KERNEL);
1078 if (!f)
1079 return;
1080
1081 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1082 if (cf->add) {
1083 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1084 cf->add = false;
1085 cf->state = __I40EVF_CF_ADD_PENDING;
1086 i40evf_send_pf_msg(adapter,
1087 VIRTCHNL_OP_ADD_CLOUD_FILTER,
1088 (u8 *)f, len);
1089 }
1090 }
1091 kfree(f);
1092 }
1093
1094 /**
1095 * i40evf_del_cloud_filter
1096 * @adapter: adapter structure
1097 *
1098 * Request that the PF delete cloud filters as specified
1099 * by the user via tc tool.
1100 **/
i40evf_del_cloud_filter(struct i40evf_adapter * adapter)1101 void i40evf_del_cloud_filter(struct i40evf_adapter *adapter)
1102 {
1103 struct i40evf_cloud_filter *cf, *cftmp;
1104 struct virtchnl_filter *f;
1105 int len = 0, count = 0;
1106
1107 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1108 /* bail because we already have a command pending */
1109 dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1110 adapter->current_op);
1111 return;
1112 }
1113 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1114 if (cf->del) {
1115 count++;
1116 break;
1117 }
1118 }
1119 if (!count) {
1120 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_CLOUD_FILTER;
1121 return;
1122 }
1123 adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1124
1125 len = sizeof(struct virtchnl_filter);
1126 f = kzalloc(len, GFP_KERNEL);
1127 if (!f)
1128 return;
1129
1130 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1131 if (cf->del) {
1132 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1133 cf->del = false;
1134 cf->state = __I40EVF_CF_DEL_PENDING;
1135 i40evf_send_pf_msg(adapter,
1136 VIRTCHNL_OP_DEL_CLOUD_FILTER,
1137 (u8 *)f, len);
1138 }
1139 }
1140 kfree(f);
1141 }
1142
1143 /**
1144 * i40evf_request_reset
1145 * @adapter: adapter structure
1146 *
1147 * Request that the PF reset this VF. No response is expected.
1148 **/
i40evf_request_reset(struct i40evf_adapter * adapter)1149 void i40evf_request_reset(struct i40evf_adapter *adapter)
1150 {
1151 /* Don't check CURRENT_OP - this is always higher priority */
1152 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
1153 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1154 }
1155
1156 /**
1157 * i40evf_virtchnl_completion
1158 * @adapter: adapter structure
1159 * @v_opcode: opcode sent by PF
1160 * @v_retval: retval sent by PF
1161 * @msg: message sent by PF
1162 * @msglen: message length
1163 *
1164 * Asynchronous completion function for admin queue messages. Rather than busy
1165 * wait, we fire off our requests and assume that no errors will be returned.
1166 * This function handles the reply messages.
1167 **/
i40evf_virtchnl_completion(struct i40evf_adapter * adapter,enum virtchnl_ops v_opcode,i40e_status v_retval,u8 * msg,u16 msglen)1168 void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
1169 enum virtchnl_ops v_opcode,
1170 i40e_status v_retval,
1171 u8 *msg, u16 msglen)
1172 {
1173 struct net_device *netdev = adapter->netdev;
1174
1175 if (v_opcode == VIRTCHNL_OP_EVENT) {
1176 struct virtchnl_pf_event *vpe =
1177 (struct virtchnl_pf_event *)msg;
1178 bool link_up = vpe->event_data.link_event.link_status;
1179 switch (vpe->event) {
1180 case VIRTCHNL_EVENT_LINK_CHANGE:
1181 adapter->link_speed =
1182 vpe->event_data.link_event.link_speed;
1183
1184 /* we've already got the right link status, bail */
1185 if (adapter->link_up == link_up)
1186 break;
1187
1188 if (link_up) {
1189 /* If we get link up message and start queues
1190 * before our queues are configured it will
1191 * trigger a TX hang. In that case, just ignore
1192 * the link status message,we'll get another one
1193 * after we enable queues and actually prepared
1194 * to send traffic.
1195 */
1196 if (adapter->state != __I40EVF_RUNNING)
1197 break;
1198
1199 /* For ADq enabled VF, we reconfigure VSIs and
1200 * re-allocate queues. Hence wait till all
1201 * queues are enabled.
1202 */
1203 if (adapter->flags &
1204 I40EVF_FLAG_QUEUES_DISABLED)
1205 break;
1206 }
1207
1208 adapter->link_up = link_up;
1209 if (link_up) {
1210 netif_tx_start_all_queues(netdev);
1211 netif_carrier_on(netdev);
1212 } else {
1213 netif_tx_stop_all_queues(netdev);
1214 netif_carrier_off(netdev);
1215 }
1216 i40evf_print_link_message(adapter);
1217 break;
1218 case VIRTCHNL_EVENT_RESET_IMPENDING:
1219 dev_info(&adapter->pdev->dev, "Reset warning received from the PF\n");
1220 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
1221 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
1222 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
1223 schedule_work(&adapter->reset_task);
1224 }
1225 break;
1226 default:
1227 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
1228 vpe->event);
1229 break;
1230 }
1231 return;
1232 }
1233 if (v_retval) {
1234 switch (v_opcode) {
1235 case VIRTCHNL_OP_ADD_VLAN:
1236 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
1237 i40evf_stat_str(&adapter->hw, v_retval));
1238 break;
1239 case VIRTCHNL_OP_ADD_ETH_ADDR:
1240 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
1241 i40evf_stat_str(&adapter->hw, v_retval));
1242 break;
1243 case VIRTCHNL_OP_DEL_VLAN:
1244 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1245 i40evf_stat_str(&adapter->hw, v_retval));
1246 break;
1247 case VIRTCHNL_OP_DEL_ETH_ADDR:
1248 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1249 i40evf_stat_str(&adapter->hw, v_retval));
1250 break;
1251 case VIRTCHNL_OP_ENABLE_CHANNELS:
1252 dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
1253 i40evf_stat_str(&adapter->hw, v_retval));
1254 adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED;
1255 adapter->ch_config.state = __I40EVF_TC_INVALID;
1256 netdev_reset_tc(netdev);
1257 netif_tx_start_all_queues(netdev);
1258 break;
1259 case VIRTCHNL_OP_DISABLE_CHANNELS:
1260 dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
1261 i40evf_stat_str(&adapter->hw, v_retval));
1262 adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED;
1263 adapter->ch_config.state = __I40EVF_TC_RUNNING;
1264 netif_tx_start_all_queues(netdev);
1265 break;
1266 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
1267 struct i40evf_cloud_filter *cf, *cftmp;
1268
1269 list_for_each_entry_safe(cf, cftmp,
1270 &adapter->cloud_filter_list,
1271 list) {
1272 if (cf->state == __I40EVF_CF_ADD_PENDING) {
1273 cf->state = __I40EVF_CF_INVALID;
1274 dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
1275 i40evf_stat_str(&adapter->hw,
1276 v_retval));
1277 i40evf_print_cloud_filter(adapter,
1278 &cf->f);
1279 list_del(&cf->list);
1280 kfree(cf);
1281 adapter->num_cloud_filters--;
1282 }
1283 }
1284 }
1285 break;
1286 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
1287 struct i40evf_cloud_filter *cf;
1288
1289 list_for_each_entry(cf, &adapter->cloud_filter_list,
1290 list) {
1291 if (cf->state == __I40EVF_CF_DEL_PENDING) {
1292 cf->state = __I40EVF_CF_ACTIVE;
1293 dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
1294 i40evf_stat_str(&adapter->hw,
1295 v_retval));
1296 i40evf_print_cloud_filter(adapter,
1297 &cf->f);
1298 }
1299 }
1300 }
1301 break;
1302 default:
1303 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
1304 v_retval,
1305 i40evf_stat_str(&adapter->hw, v_retval),
1306 v_opcode);
1307 }
1308 }
1309 switch (v_opcode) {
1310 case VIRTCHNL_OP_GET_STATS: {
1311 struct i40e_eth_stats *stats =
1312 (struct i40e_eth_stats *)msg;
1313 netdev->stats.rx_packets = stats->rx_unicast +
1314 stats->rx_multicast +
1315 stats->rx_broadcast;
1316 netdev->stats.tx_packets = stats->tx_unicast +
1317 stats->tx_multicast +
1318 stats->tx_broadcast;
1319 netdev->stats.rx_bytes = stats->rx_bytes;
1320 netdev->stats.tx_bytes = stats->tx_bytes;
1321 netdev->stats.tx_errors = stats->tx_errors;
1322 netdev->stats.rx_dropped = stats->rx_discards;
1323 netdev->stats.tx_dropped = stats->tx_discards;
1324 adapter->current_stats = *stats;
1325 }
1326 break;
1327 case VIRTCHNL_OP_GET_VF_RESOURCES: {
1328 u16 len = sizeof(struct virtchnl_vf_resource) +
1329 I40E_MAX_VF_VSI *
1330 sizeof(struct virtchnl_vsi_resource);
1331 memcpy(adapter->vf_res, msg, min(msglen, len));
1332 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
1333 /* restore current mac address */
1334 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1335 i40evf_process_config(adapter);
1336 }
1337 break;
1338 case VIRTCHNL_OP_ENABLE_QUEUES:
1339 /* enable transmits */
1340 i40evf_irq_enable(adapter, true);
1341 adapter->flags &= ~I40EVF_FLAG_QUEUES_DISABLED;
1342 break;
1343 case VIRTCHNL_OP_DISABLE_QUEUES:
1344 i40evf_free_all_tx_resources(adapter);
1345 i40evf_free_all_rx_resources(adapter);
1346 if (adapter->state == __I40EVF_DOWN_PENDING) {
1347 adapter->state = __I40EVF_DOWN;
1348 wake_up(&adapter->down_waitqueue);
1349 }
1350 break;
1351 case VIRTCHNL_OP_VERSION:
1352 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1353 /* Don't display an error if we get these out of sequence.
1354 * If the firmware needed to get kicked, we'll get these and
1355 * it's no problem.
1356 */
1357 if (v_opcode != adapter->current_op)
1358 return;
1359 break;
1360 case VIRTCHNL_OP_IWARP:
1361 /* Gobble zero-length replies from the PF. They indicate that
1362 * a previous message was received OK, and the client doesn't
1363 * care about that.
1364 */
1365 if (msglen && CLIENT_ENABLED(adapter))
1366 i40evf_notify_client_message(&adapter->vsi,
1367 msg, msglen);
1368 break;
1369
1370 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
1371 adapter->client_pending &=
1372 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
1373 break;
1374 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
1375 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
1376 if (msglen == sizeof(*vrh))
1377 adapter->hena = vrh->hena;
1378 else
1379 dev_warn(&adapter->pdev->dev,
1380 "Invalid message %d from PF\n", v_opcode);
1381 }
1382 break;
1383 case VIRTCHNL_OP_REQUEST_QUEUES: {
1384 struct virtchnl_vf_res_request *vfres =
1385 (struct virtchnl_vf_res_request *)msg;
1386 if (vfres->num_queue_pairs != adapter->num_req_queues) {
1387 dev_info(&adapter->pdev->dev,
1388 "Requested %d queues, PF can support %d\n",
1389 adapter->num_req_queues,
1390 vfres->num_queue_pairs);
1391 adapter->num_req_queues = 0;
1392 adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED;
1393 }
1394 }
1395 break;
1396 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
1397 struct i40evf_cloud_filter *cf;
1398
1399 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1400 if (cf->state == __I40EVF_CF_ADD_PENDING)
1401 cf->state = __I40EVF_CF_ACTIVE;
1402 }
1403 }
1404 break;
1405 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
1406 struct i40evf_cloud_filter *cf, *cftmp;
1407
1408 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
1409 list) {
1410 if (cf->state == __I40EVF_CF_DEL_PENDING) {
1411 cf->state = __I40EVF_CF_INVALID;
1412 list_del(&cf->list);
1413 kfree(cf);
1414 adapter->num_cloud_filters--;
1415 }
1416 }
1417 }
1418 break;
1419 default:
1420 if (adapter->current_op && (v_opcode != adapter->current_op))
1421 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
1422 adapter->current_op, v_opcode);
1423 break;
1424 } /* switch v_opcode */
1425 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1426 }
1427