1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
3
4 #include "ice.h"
5 #include "ice_base.h"
6 #include "ice_flow.h"
7 #include "ice_lib.h"
8 #include "ice_fltr.h"
9 #include "ice_dcb_lib.h"
10 #include "ice_type.h"
11 #include "ice_vsi_vlan_ops.h"
12
13 /**
14 * ice_vsi_type_str - maps VSI type enum to string equivalents
15 * @vsi_type: VSI type enum
16 */
ice_vsi_type_str(enum ice_vsi_type vsi_type)17 const char *ice_vsi_type_str(enum ice_vsi_type vsi_type)
18 {
19 switch (vsi_type) {
20 case ICE_VSI_PF:
21 return "ICE_VSI_PF";
22 case ICE_VSI_VF:
23 return "ICE_VSI_VF";
24 case ICE_VSI_SF:
25 return "ICE_VSI_SF";
26 case ICE_VSI_CTRL:
27 return "ICE_VSI_CTRL";
28 case ICE_VSI_CHNL:
29 return "ICE_VSI_CHNL";
30 case ICE_VSI_LB:
31 return "ICE_VSI_LB";
32 default:
33 return "unknown";
34 }
35 }
36
37 /**
38 * ice_vsi_ctrl_all_rx_rings - Start or stop a VSI's Rx rings
39 * @vsi: the VSI being configured
40 * @ena: start or stop the Rx rings
41 *
42 * First enable/disable all of the Rx rings, flush any remaining writes, and
43 * then verify that they have all been enabled/disabled successfully. This will
44 * let all of the register writes complete when enabling/disabling the Rx rings
45 * before waiting for the change in hardware to complete.
46 */
ice_vsi_ctrl_all_rx_rings(struct ice_vsi * vsi,bool ena)47 static int ice_vsi_ctrl_all_rx_rings(struct ice_vsi *vsi, bool ena)
48 {
49 int ret = 0;
50 u16 i;
51
52 ice_for_each_rxq(vsi, i)
53 ice_vsi_ctrl_one_rx_ring(vsi, ena, i, false);
54
55 ice_flush(&vsi->back->hw);
56
57 ice_for_each_rxq(vsi, i) {
58 ret = ice_vsi_wait_one_rx_ring(vsi, ena, i);
59 if (ret)
60 break;
61 }
62
63 return ret;
64 }
65
66 /**
67 * ice_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the VSI
68 * @vsi: VSI pointer
69 *
70 * On error: returns error code (negative)
71 * On success: returns 0
72 */
ice_vsi_alloc_arrays(struct ice_vsi * vsi)73 static int ice_vsi_alloc_arrays(struct ice_vsi *vsi)
74 {
75 struct ice_pf *pf = vsi->back;
76 struct device *dev;
77
78 dev = ice_pf_to_dev(pf);
79 if (vsi->type == ICE_VSI_CHNL)
80 return 0;
81
82 /* allocate memory for both Tx and Rx ring pointers */
83 vsi->tx_rings = devm_kcalloc(dev, vsi->alloc_txq,
84 sizeof(*vsi->tx_rings), GFP_KERNEL);
85 if (!vsi->tx_rings)
86 return -ENOMEM;
87
88 vsi->rx_rings = devm_kcalloc(dev, vsi->alloc_rxq,
89 sizeof(*vsi->rx_rings), GFP_KERNEL);
90 if (!vsi->rx_rings)
91 goto err_rings;
92
93 /* txq_map needs to have enough space to track both Tx (stack) rings
94 * and XDP rings; at this point vsi->num_xdp_txq might not be set,
95 * so use num_possible_cpus() as we want to always provide XDP ring
96 * per CPU, regardless of queue count settings from user that might
97 * have come from ethtool's set_channels() callback;
98 */
99 vsi->txq_map = devm_kcalloc(dev, (vsi->alloc_txq + num_possible_cpus()),
100 sizeof(*vsi->txq_map), GFP_KERNEL);
101
102 if (!vsi->txq_map)
103 goto err_txq_map;
104
105 vsi->rxq_map = devm_kcalloc(dev, vsi->alloc_rxq,
106 sizeof(*vsi->rxq_map), GFP_KERNEL);
107 if (!vsi->rxq_map)
108 goto err_rxq_map;
109
110 /* There is no need to allocate q_vectors for a loopback VSI. */
111 if (vsi->type == ICE_VSI_LB)
112 return 0;
113
114 /* allocate memory for q_vector pointers */
115 vsi->q_vectors = devm_kcalloc(dev, vsi->num_q_vectors,
116 sizeof(*vsi->q_vectors), GFP_KERNEL);
117 if (!vsi->q_vectors)
118 goto err_vectors;
119
120 return 0;
121
122 err_vectors:
123 devm_kfree(dev, vsi->rxq_map);
124 err_rxq_map:
125 devm_kfree(dev, vsi->txq_map);
126 err_txq_map:
127 devm_kfree(dev, vsi->rx_rings);
128 err_rings:
129 devm_kfree(dev, vsi->tx_rings);
130 return -ENOMEM;
131 }
132
133 /**
134 * ice_vsi_set_num_desc - Set number of descriptors for queues on this VSI
135 * @vsi: the VSI being configured
136 */
ice_vsi_set_num_desc(struct ice_vsi * vsi)137 static void ice_vsi_set_num_desc(struct ice_vsi *vsi)
138 {
139 switch (vsi->type) {
140 case ICE_VSI_PF:
141 case ICE_VSI_SF:
142 case ICE_VSI_CTRL:
143 case ICE_VSI_LB:
144 /* a user could change the values of num_[tr]x_desc using
145 * ethtool -G so we should keep those values instead of
146 * overwriting them with the defaults.
147 */
148 if (!vsi->num_rx_desc)
149 vsi->num_rx_desc = ICE_DFLT_NUM_RX_DESC;
150 if (!vsi->num_tx_desc)
151 vsi->num_tx_desc = ICE_DFLT_NUM_TX_DESC;
152 break;
153 default:
154 dev_dbg(ice_pf_to_dev(vsi->back), "Not setting number of Tx/Rx descriptors for VSI type %d\n",
155 vsi->type);
156 break;
157 }
158 }
159
160 /**
161 * ice_vsi_set_num_qs - Set number of queues, descriptors and vectors for a VSI
162 * @vsi: the VSI being configured
163 *
164 * Return 0 on success and a negative value on error
165 */
ice_vsi_set_num_qs(struct ice_vsi * vsi)166 static void ice_vsi_set_num_qs(struct ice_vsi *vsi)
167 {
168 enum ice_vsi_type vsi_type = vsi->type;
169 struct ice_pf *pf = vsi->back;
170 struct ice_vf *vf = vsi->vf;
171
172 if (WARN_ON(vsi_type == ICE_VSI_VF && !vf))
173 return;
174
175 switch (vsi_type) {
176 case ICE_VSI_PF:
177 if (vsi->req_txq) {
178 vsi->alloc_txq = vsi->req_txq;
179 vsi->num_txq = vsi->req_txq;
180 } else {
181 vsi->alloc_txq = min3(pf->num_lan_msix,
182 ice_get_avail_txq_count(pf),
183 (u16)num_online_cpus());
184 }
185
186 pf->num_lan_tx = vsi->alloc_txq;
187
188 /* only 1 Rx queue unless RSS is enabled */
189 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
190 vsi->alloc_rxq = 1;
191 } else {
192 if (vsi->req_rxq) {
193 vsi->alloc_rxq = vsi->req_rxq;
194 vsi->num_rxq = vsi->req_rxq;
195 } else {
196 vsi->alloc_rxq = min3(pf->num_lan_msix,
197 ice_get_avail_rxq_count(pf),
198 (u16)num_online_cpus());
199 }
200 }
201
202 pf->num_lan_rx = vsi->alloc_rxq;
203
204 vsi->num_q_vectors = min_t(int, pf->num_lan_msix,
205 max_t(int, vsi->alloc_rxq,
206 vsi->alloc_txq));
207 break;
208 case ICE_VSI_SF:
209 vsi->alloc_txq = 1;
210 vsi->alloc_rxq = 1;
211 vsi->num_q_vectors = 1;
212 vsi->irq_dyn_alloc = true;
213 break;
214 case ICE_VSI_VF:
215 if (vf->num_req_qs)
216 vf->num_vf_qs = vf->num_req_qs;
217 vsi->alloc_txq = vf->num_vf_qs;
218 vsi->alloc_rxq = vf->num_vf_qs;
219 /* pf->vfs.num_msix_per includes (VF miscellaneous vector +
220 * data queue interrupts). Since vsi->num_q_vectors is number
221 * of queues vectors, subtract 1 (ICE_NONQ_VECS_VF) from the
222 * original vector count
223 */
224 vsi->num_q_vectors = vf->num_msix - ICE_NONQ_VECS_VF;
225 break;
226 case ICE_VSI_CTRL:
227 vsi->alloc_txq = 1;
228 vsi->alloc_rxq = 1;
229 vsi->num_q_vectors = 1;
230 break;
231 case ICE_VSI_CHNL:
232 vsi->alloc_txq = 0;
233 vsi->alloc_rxq = 0;
234 break;
235 case ICE_VSI_LB:
236 vsi->alloc_txq = 1;
237 vsi->alloc_rxq = 1;
238 break;
239 default:
240 dev_warn(ice_pf_to_dev(pf), "Unknown VSI type %d\n", vsi_type);
241 break;
242 }
243
244 ice_vsi_set_num_desc(vsi);
245 }
246
247 /**
248 * ice_get_free_slot - get the next non-NULL location index in array
249 * @array: array to search
250 * @size: size of the array
251 * @curr: last known occupied index to be used as a search hint
252 *
253 * void * is being used to keep the functionality generic. This lets us use this
254 * function on any array of pointers.
255 */
ice_get_free_slot(void * array,int size,int curr)256 static int ice_get_free_slot(void *array, int size, int curr)
257 {
258 int **tmp_array = (int **)array;
259 int next;
260
261 if (curr < (size - 1) && !tmp_array[curr + 1]) {
262 next = curr + 1;
263 } else {
264 int i = 0;
265
266 while ((i < size) && (tmp_array[i]))
267 i++;
268 if (i == size)
269 next = ICE_NO_VSI;
270 else
271 next = i;
272 }
273 return next;
274 }
275
276 /**
277 * ice_vsi_delete_from_hw - delete a VSI from the switch
278 * @vsi: pointer to VSI being removed
279 */
ice_vsi_delete_from_hw(struct ice_vsi * vsi)280 static void ice_vsi_delete_from_hw(struct ice_vsi *vsi)
281 {
282 struct ice_pf *pf = vsi->back;
283 struct ice_vsi_ctx *ctxt;
284 int status;
285
286 ice_fltr_remove_all(vsi);
287 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
288 if (!ctxt)
289 return;
290
291 if (vsi->type == ICE_VSI_VF)
292 ctxt->vf_num = vsi->vf->vf_id;
293 ctxt->vsi_num = vsi->vsi_num;
294
295 memcpy(&ctxt->info, &vsi->info, sizeof(ctxt->info));
296
297 status = ice_free_vsi(&pf->hw, vsi->idx, ctxt, false, NULL);
298 if (status)
299 dev_err(ice_pf_to_dev(pf), "Failed to delete VSI %i in FW - error: %d\n",
300 vsi->vsi_num, status);
301
302 kfree(ctxt);
303 }
304
305 /**
306 * ice_vsi_free_arrays - De-allocate queue and vector pointer arrays for the VSI
307 * @vsi: pointer to VSI being cleared
308 */
ice_vsi_free_arrays(struct ice_vsi * vsi)309 static void ice_vsi_free_arrays(struct ice_vsi *vsi)
310 {
311 struct ice_pf *pf = vsi->back;
312 struct device *dev;
313
314 dev = ice_pf_to_dev(pf);
315
316 /* free the ring and vector containers */
317 devm_kfree(dev, vsi->q_vectors);
318 vsi->q_vectors = NULL;
319 devm_kfree(dev, vsi->tx_rings);
320 vsi->tx_rings = NULL;
321 devm_kfree(dev, vsi->rx_rings);
322 vsi->rx_rings = NULL;
323 devm_kfree(dev, vsi->txq_map);
324 vsi->txq_map = NULL;
325 devm_kfree(dev, vsi->rxq_map);
326 vsi->rxq_map = NULL;
327 }
328
329 /**
330 * ice_vsi_free_stats - Free the ring statistics structures
331 * @vsi: VSI pointer
332 */
ice_vsi_free_stats(struct ice_vsi * vsi)333 static void ice_vsi_free_stats(struct ice_vsi *vsi)
334 {
335 struct ice_vsi_stats *vsi_stat;
336 struct ice_pf *pf = vsi->back;
337 int i;
338
339 if (vsi->type == ICE_VSI_CHNL)
340 return;
341 if (!pf->vsi_stats)
342 return;
343
344 vsi_stat = pf->vsi_stats[vsi->idx];
345 if (!vsi_stat)
346 return;
347
348 ice_for_each_alloc_txq(vsi, i) {
349 if (vsi_stat->tx_ring_stats[i]) {
350 kfree_rcu(vsi_stat->tx_ring_stats[i], rcu);
351 WRITE_ONCE(vsi_stat->tx_ring_stats[i], NULL);
352 }
353 }
354
355 ice_for_each_alloc_rxq(vsi, i) {
356 if (vsi_stat->rx_ring_stats[i]) {
357 kfree_rcu(vsi_stat->rx_ring_stats[i], rcu);
358 WRITE_ONCE(vsi_stat->rx_ring_stats[i], NULL);
359 }
360 }
361
362 kfree(vsi_stat->tx_ring_stats);
363 kfree(vsi_stat->rx_ring_stats);
364 kfree(vsi_stat);
365 pf->vsi_stats[vsi->idx] = NULL;
366 }
367
368 /**
369 * ice_vsi_alloc_ring_stats - Allocates Tx and Rx ring stats for the VSI
370 * @vsi: VSI which is having stats allocated
371 */
ice_vsi_alloc_ring_stats(struct ice_vsi * vsi)372 static int ice_vsi_alloc_ring_stats(struct ice_vsi *vsi)
373 {
374 struct ice_ring_stats **tx_ring_stats;
375 struct ice_ring_stats **rx_ring_stats;
376 struct ice_vsi_stats *vsi_stats;
377 struct ice_pf *pf = vsi->back;
378 u16 i;
379
380 vsi_stats = pf->vsi_stats[vsi->idx];
381 tx_ring_stats = vsi_stats->tx_ring_stats;
382 rx_ring_stats = vsi_stats->rx_ring_stats;
383
384 /* Allocate Tx ring stats */
385 ice_for_each_alloc_txq(vsi, i) {
386 struct ice_ring_stats *ring_stats;
387 struct ice_tx_ring *ring;
388
389 ring = vsi->tx_rings[i];
390 ring_stats = tx_ring_stats[i];
391
392 if (!ring_stats) {
393 ring_stats = kzalloc(sizeof(*ring_stats), GFP_KERNEL);
394 if (!ring_stats)
395 goto err_out;
396
397 WRITE_ONCE(tx_ring_stats[i], ring_stats);
398 }
399
400 ring->ring_stats = ring_stats;
401 }
402
403 /* Allocate Rx ring stats */
404 ice_for_each_alloc_rxq(vsi, i) {
405 struct ice_ring_stats *ring_stats;
406 struct ice_rx_ring *ring;
407
408 ring = vsi->rx_rings[i];
409 ring_stats = rx_ring_stats[i];
410
411 if (!ring_stats) {
412 ring_stats = kzalloc(sizeof(*ring_stats), GFP_KERNEL);
413 if (!ring_stats)
414 goto err_out;
415
416 WRITE_ONCE(rx_ring_stats[i], ring_stats);
417 }
418
419 ring->ring_stats = ring_stats;
420 }
421
422 return 0;
423
424 err_out:
425 ice_vsi_free_stats(vsi);
426 return -ENOMEM;
427 }
428
429 /**
430 * ice_vsi_free - clean up and deallocate the provided VSI
431 * @vsi: pointer to VSI being cleared
432 *
433 * This deallocates the VSI's queue resources, removes it from the PF's
434 * VSI array if necessary, and deallocates the VSI
435 */
ice_vsi_free(struct ice_vsi * vsi)436 void ice_vsi_free(struct ice_vsi *vsi)
437 {
438 struct ice_pf *pf = NULL;
439 struct device *dev;
440
441 if (!vsi || !vsi->back)
442 return;
443
444 pf = vsi->back;
445 dev = ice_pf_to_dev(pf);
446
447 if (!pf->vsi[vsi->idx] || pf->vsi[vsi->idx] != vsi) {
448 dev_dbg(dev, "vsi does not exist at pf->vsi[%d]\n", vsi->idx);
449 return;
450 }
451
452 mutex_lock(&pf->sw_mutex);
453 /* updates the PF for this cleared VSI */
454
455 pf->vsi[vsi->idx] = NULL;
456 pf->next_vsi = vsi->idx;
457
458 ice_vsi_free_stats(vsi);
459 ice_vsi_free_arrays(vsi);
460 mutex_destroy(&vsi->xdp_state_lock);
461 mutex_unlock(&pf->sw_mutex);
462 devm_kfree(dev, vsi);
463 }
464
ice_vsi_delete(struct ice_vsi * vsi)465 void ice_vsi_delete(struct ice_vsi *vsi)
466 {
467 ice_vsi_delete_from_hw(vsi);
468 ice_vsi_free(vsi);
469 }
470
471 /**
472 * ice_msix_clean_ctrl_vsi - MSIX mode interrupt handler for ctrl VSI
473 * @irq: interrupt number
474 * @data: pointer to a q_vector
475 */
ice_msix_clean_ctrl_vsi(int __always_unused irq,void * data)476 static irqreturn_t ice_msix_clean_ctrl_vsi(int __always_unused irq, void *data)
477 {
478 struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
479
480 if (!q_vector->tx.tx_ring)
481 return IRQ_HANDLED;
482
483 #define FDIR_RX_DESC_CLEAN_BUDGET 64
484 ice_clean_rx_irq(q_vector->rx.rx_ring, FDIR_RX_DESC_CLEAN_BUDGET);
485 ice_clean_ctrl_tx_irq(q_vector->tx.tx_ring);
486
487 return IRQ_HANDLED;
488 }
489
490 /**
491 * ice_msix_clean_rings - MSIX mode Interrupt Handler
492 * @irq: interrupt number
493 * @data: pointer to a q_vector
494 */
ice_msix_clean_rings(int __always_unused irq,void * data)495 static irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data)
496 {
497 struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
498
499 if (!q_vector->tx.tx_ring && !q_vector->rx.rx_ring)
500 return IRQ_HANDLED;
501
502 q_vector->total_events++;
503
504 napi_schedule(&q_vector->napi);
505
506 return IRQ_HANDLED;
507 }
508
509 /**
510 * ice_vsi_alloc_stat_arrays - Allocate statistics arrays
511 * @vsi: VSI pointer
512 */
ice_vsi_alloc_stat_arrays(struct ice_vsi * vsi)513 static int ice_vsi_alloc_stat_arrays(struct ice_vsi *vsi)
514 {
515 struct ice_vsi_stats *vsi_stat;
516 struct ice_pf *pf = vsi->back;
517
518 if (vsi->type == ICE_VSI_CHNL)
519 return 0;
520 if (!pf->vsi_stats)
521 return -ENOENT;
522
523 if (pf->vsi_stats[vsi->idx])
524 /* realloc will happen in rebuild path */
525 return 0;
526
527 vsi_stat = kzalloc(sizeof(*vsi_stat), GFP_KERNEL);
528 if (!vsi_stat)
529 return -ENOMEM;
530
531 vsi_stat->tx_ring_stats =
532 kcalloc(vsi->alloc_txq, sizeof(*vsi_stat->tx_ring_stats),
533 GFP_KERNEL);
534 if (!vsi_stat->tx_ring_stats)
535 goto err_alloc_tx;
536
537 vsi_stat->rx_ring_stats =
538 kcalloc(vsi->alloc_rxq, sizeof(*vsi_stat->rx_ring_stats),
539 GFP_KERNEL);
540 if (!vsi_stat->rx_ring_stats)
541 goto err_alloc_rx;
542
543 pf->vsi_stats[vsi->idx] = vsi_stat;
544
545 return 0;
546
547 err_alloc_rx:
548 kfree(vsi_stat->rx_ring_stats);
549 err_alloc_tx:
550 kfree(vsi_stat->tx_ring_stats);
551 kfree(vsi_stat);
552 pf->vsi_stats[vsi->idx] = NULL;
553 return -ENOMEM;
554 }
555
556 /**
557 * ice_vsi_alloc_def - set default values for already allocated VSI
558 * @vsi: ptr to VSI
559 * @ch: ptr to channel
560 */
561 static int
ice_vsi_alloc_def(struct ice_vsi * vsi,struct ice_channel * ch)562 ice_vsi_alloc_def(struct ice_vsi *vsi, struct ice_channel *ch)
563 {
564 if (vsi->type != ICE_VSI_CHNL) {
565 ice_vsi_set_num_qs(vsi);
566 if (ice_vsi_alloc_arrays(vsi))
567 return -ENOMEM;
568 }
569
570 vsi->irq_dyn_alloc = pci_msix_can_alloc_dyn(vsi->back->pdev);
571
572 switch (vsi->type) {
573 case ICE_VSI_PF:
574 case ICE_VSI_SF:
575 /* Setup default MSIX irq handler for VSI */
576 vsi->irq_handler = ice_msix_clean_rings;
577 break;
578 case ICE_VSI_CTRL:
579 /* Setup ctrl VSI MSIX irq handler */
580 vsi->irq_handler = ice_msix_clean_ctrl_vsi;
581 break;
582 case ICE_VSI_CHNL:
583 if (!ch)
584 return -EINVAL;
585
586 vsi->num_rxq = ch->num_rxq;
587 vsi->num_txq = ch->num_txq;
588 vsi->next_base_q = ch->base_q;
589 break;
590 case ICE_VSI_VF:
591 case ICE_VSI_LB:
592 break;
593 default:
594 ice_vsi_free_arrays(vsi);
595 return -EINVAL;
596 }
597
598 return 0;
599 }
600
601 /**
602 * ice_vsi_alloc - Allocates the next available struct VSI in the PF
603 * @pf: board private structure
604 *
605 * Reserves a VSI index from the PF and allocates an empty VSI structure
606 * without a type. The VSI structure must later be initialized by calling
607 * ice_vsi_cfg().
608 *
609 * returns a pointer to a VSI on success, NULL on failure.
610 */
ice_vsi_alloc(struct ice_pf * pf)611 struct ice_vsi *ice_vsi_alloc(struct ice_pf *pf)
612 {
613 struct device *dev = ice_pf_to_dev(pf);
614 struct ice_vsi *vsi = NULL;
615
616 /* Need to protect the allocation of the VSIs at the PF level */
617 mutex_lock(&pf->sw_mutex);
618
619 /* If we have already allocated our maximum number of VSIs,
620 * pf->next_vsi will be ICE_NO_VSI. If not, pf->next_vsi index
621 * is available to be populated
622 */
623 if (pf->next_vsi == ICE_NO_VSI) {
624 dev_dbg(dev, "out of VSI slots!\n");
625 goto unlock_pf;
626 }
627
628 vsi = devm_kzalloc(dev, sizeof(*vsi), GFP_KERNEL);
629 if (!vsi)
630 goto unlock_pf;
631
632 vsi->back = pf;
633 set_bit(ICE_VSI_DOWN, vsi->state);
634
635 /* fill slot and make note of the index */
636 vsi->idx = pf->next_vsi;
637 pf->vsi[pf->next_vsi] = vsi;
638
639 /* prepare pf->next_vsi for next use */
640 pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi,
641 pf->next_vsi);
642
643 mutex_init(&vsi->xdp_state_lock);
644
645 unlock_pf:
646 mutex_unlock(&pf->sw_mutex);
647 return vsi;
648 }
649
650 /**
651 * ice_alloc_fd_res - Allocate FD resource for a VSI
652 * @vsi: pointer to the ice_vsi
653 *
654 * This allocates the FD resources
655 *
656 * Returns 0 on success, -EPERM on no-op or -EIO on failure
657 */
ice_alloc_fd_res(struct ice_vsi * vsi)658 static int ice_alloc_fd_res(struct ice_vsi *vsi)
659 {
660 struct ice_pf *pf = vsi->back;
661 u32 g_val, b_val;
662
663 /* Flow Director filters are only allocated/assigned to the PF VSI or
664 * CHNL VSI which passes the traffic. The CTRL VSI is only used to
665 * add/delete filters so resources are not allocated to it
666 */
667 if (!test_bit(ICE_FLAG_FD_ENA, pf->flags))
668 return -EPERM;
669
670 if (!(vsi->type == ICE_VSI_PF || vsi->type == ICE_VSI_VF ||
671 vsi->type == ICE_VSI_CHNL))
672 return -EPERM;
673
674 /* FD filters from guaranteed pool per VSI */
675 g_val = pf->hw.func_caps.fd_fltr_guar;
676 if (!g_val)
677 return -EPERM;
678
679 /* FD filters from best effort pool */
680 b_val = pf->hw.func_caps.fd_fltr_best_effort;
681 if (!b_val)
682 return -EPERM;
683
684 /* PF main VSI gets only 64 FD resources from guaranteed pool
685 * when ADQ is configured.
686 */
687 #define ICE_PF_VSI_GFLTR 64
688
689 /* determine FD filter resources per VSI from shared(best effort) and
690 * dedicated pool
691 */
692 if (vsi->type == ICE_VSI_PF) {
693 vsi->num_gfltr = g_val;
694 /* if MQPRIO is configured, main VSI doesn't get all FD
695 * resources from guaranteed pool. PF VSI gets 64 FD resources
696 */
697 if (test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) {
698 if (g_val < ICE_PF_VSI_GFLTR)
699 return -EPERM;
700 /* allow bare minimum entries for PF VSI */
701 vsi->num_gfltr = ICE_PF_VSI_GFLTR;
702 }
703
704 /* each VSI gets same "best_effort" quota */
705 vsi->num_bfltr = b_val;
706 } else if (vsi->type == ICE_VSI_VF) {
707 vsi->num_gfltr = 0;
708
709 /* each VSI gets same "best_effort" quota */
710 vsi->num_bfltr = b_val;
711 } else {
712 struct ice_vsi *main_vsi;
713 int numtc;
714
715 main_vsi = ice_get_main_vsi(pf);
716 if (!main_vsi)
717 return -EPERM;
718
719 if (!main_vsi->all_numtc)
720 return -EINVAL;
721
722 /* figure out ADQ numtc */
723 numtc = main_vsi->all_numtc - ICE_CHNL_START_TC;
724
725 /* only one TC but still asking resources for channels,
726 * invalid config
727 */
728 if (numtc < ICE_CHNL_START_TC)
729 return -EPERM;
730
731 g_val -= ICE_PF_VSI_GFLTR;
732 /* channel VSIs gets equal share from guaranteed pool */
733 vsi->num_gfltr = g_val / numtc;
734
735 /* each VSI gets same "best_effort" quota */
736 vsi->num_bfltr = b_val;
737 }
738
739 return 0;
740 }
741
742 /**
743 * ice_vsi_get_qs - Assign queues from PF to VSI
744 * @vsi: the VSI to assign queues to
745 *
746 * Returns 0 on success and a negative value on error
747 */
ice_vsi_get_qs(struct ice_vsi * vsi)748 static int ice_vsi_get_qs(struct ice_vsi *vsi)
749 {
750 struct ice_pf *pf = vsi->back;
751 struct ice_qs_cfg tx_qs_cfg = {
752 .qs_mutex = &pf->avail_q_mutex,
753 .pf_map = pf->avail_txqs,
754 .pf_map_size = pf->max_pf_txqs,
755 .q_count = vsi->alloc_txq,
756 .scatter_count = ICE_MAX_SCATTER_TXQS,
757 .vsi_map = vsi->txq_map,
758 .vsi_map_offset = 0,
759 .mapping_mode = ICE_VSI_MAP_CONTIG
760 };
761 struct ice_qs_cfg rx_qs_cfg = {
762 .qs_mutex = &pf->avail_q_mutex,
763 .pf_map = pf->avail_rxqs,
764 .pf_map_size = pf->max_pf_rxqs,
765 .q_count = vsi->alloc_rxq,
766 .scatter_count = ICE_MAX_SCATTER_RXQS,
767 .vsi_map = vsi->rxq_map,
768 .vsi_map_offset = 0,
769 .mapping_mode = ICE_VSI_MAP_CONTIG
770 };
771 int ret;
772
773 if (vsi->type == ICE_VSI_CHNL)
774 return 0;
775
776 ret = __ice_vsi_get_qs(&tx_qs_cfg);
777 if (ret)
778 return ret;
779 vsi->tx_mapping_mode = tx_qs_cfg.mapping_mode;
780
781 ret = __ice_vsi_get_qs(&rx_qs_cfg);
782 if (ret)
783 return ret;
784 vsi->rx_mapping_mode = rx_qs_cfg.mapping_mode;
785
786 return 0;
787 }
788
789 /**
790 * ice_vsi_put_qs - Release queues from VSI to PF
791 * @vsi: the VSI that is going to release queues
792 */
ice_vsi_put_qs(struct ice_vsi * vsi)793 static void ice_vsi_put_qs(struct ice_vsi *vsi)
794 {
795 struct ice_pf *pf = vsi->back;
796 int i;
797
798 mutex_lock(&pf->avail_q_mutex);
799
800 ice_for_each_alloc_txq(vsi, i) {
801 clear_bit(vsi->txq_map[i], pf->avail_txqs);
802 vsi->txq_map[i] = ICE_INVAL_Q_INDEX;
803 }
804
805 ice_for_each_alloc_rxq(vsi, i) {
806 clear_bit(vsi->rxq_map[i], pf->avail_rxqs);
807 vsi->rxq_map[i] = ICE_INVAL_Q_INDEX;
808 }
809
810 mutex_unlock(&pf->avail_q_mutex);
811 }
812
813 /**
814 * ice_is_safe_mode
815 * @pf: pointer to the PF struct
816 *
817 * returns true if driver is in safe mode, false otherwise
818 */
ice_is_safe_mode(struct ice_pf * pf)819 bool ice_is_safe_mode(struct ice_pf *pf)
820 {
821 return !test_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
822 }
823
824 /**
825 * ice_is_rdma_ena
826 * @pf: pointer to the PF struct
827 *
828 * returns true if RDMA is currently supported, false otherwise
829 */
ice_is_rdma_ena(struct ice_pf * pf)830 bool ice_is_rdma_ena(struct ice_pf *pf)
831 {
832 return test_bit(ICE_FLAG_RDMA_ENA, pf->flags);
833 }
834
835 /**
836 * ice_vsi_clean_rss_flow_fld - Delete RSS configuration
837 * @vsi: the VSI being cleaned up
838 *
839 * This function deletes RSS input set for all flows that were configured
840 * for this VSI
841 */
ice_vsi_clean_rss_flow_fld(struct ice_vsi * vsi)842 static void ice_vsi_clean_rss_flow_fld(struct ice_vsi *vsi)
843 {
844 struct ice_pf *pf = vsi->back;
845 int status;
846
847 if (ice_is_safe_mode(pf))
848 return;
849
850 status = ice_rem_vsi_rss_cfg(&pf->hw, vsi->idx);
851 if (status)
852 dev_dbg(ice_pf_to_dev(pf), "ice_rem_vsi_rss_cfg failed for vsi = %d, error = %d\n",
853 vsi->vsi_num, status);
854 }
855
856 /**
857 * ice_rss_clean - Delete RSS related VSI structures and configuration
858 * @vsi: the VSI being removed
859 */
ice_rss_clean(struct ice_vsi * vsi)860 static void ice_rss_clean(struct ice_vsi *vsi)
861 {
862 struct ice_pf *pf = vsi->back;
863 struct device *dev;
864
865 dev = ice_pf_to_dev(pf);
866
867 devm_kfree(dev, vsi->rss_hkey_user);
868 devm_kfree(dev, vsi->rss_lut_user);
869
870 ice_vsi_clean_rss_flow_fld(vsi);
871 /* remove RSS replay list */
872 if (!ice_is_safe_mode(pf))
873 ice_rem_vsi_rss_list(&pf->hw, vsi->idx);
874 }
875
876 /**
877 * ice_vsi_set_rss_params - Setup RSS capabilities per VSI type
878 * @vsi: the VSI being configured
879 */
ice_vsi_set_rss_params(struct ice_vsi * vsi)880 static void ice_vsi_set_rss_params(struct ice_vsi *vsi)
881 {
882 struct ice_hw_common_caps *cap;
883 struct ice_pf *pf = vsi->back;
884 u16 max_rss_size;
885
886 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
887 vsi->rss_size = 1;
888 return;
889 }
890
891 cap = &pf->hw.func_caps.common_cap;
892 max_rss_size = BIT(cap->rss_table_entry_width);
893 switch (vsi->type) {
894 case ICE_VSI_CHNL:
895 case ICE_VSI_PF:
896 /* PF VSI will inherit RSS instance of PF */
897 vsi->rss_table_size = (u16)cap->rss_table_size;
898 if (vsi->type == ICE_VSI_CHNL)
899 vsi->rss_size = min_t(u16, vsi->num_rxq, max_rss_size);
900 else
901 vsi->rss_size = min_t(u16, num_online_cpus(),
902 max_rss_size);
903 vsi->rss_lut_type = ICE_LUT_PF;
904 break;
905 case ICE_VSI_SF:
906 vsi->rss_table_size = ICE_LUT_VSI_SIZE;
907 vsi->rss_size = min_t(u16, num_online_cpus(), max_rss_size);
908 vsi->rss_lut_type = ICE_LUT_VSI;
909 break;
910 case ICE_VSI_VF:
911 /* VF VSI will get a small RSS table.
912 * For VSI_LUT, LUT size should be set to 64 bytes.
913 */
914 vsi->rss_table_size = ICE_LUT_VSI_SIZE;
915 vsi->rss_size = ICE_MAX_RSS_QS_PER_VF;
916 vsi->rss_lut_type = ICE_LUT_VSI;
917 break;
918 case ICE_VSI_LB:
919 break;
920 default:
921 dev_dbg(ice_pf_to_dev(pf), "Unsupported VSI type %s\n",
922 ice_vsi_type_str(vsi->type));
923 break;
924 }
925 }
926
927 /**
928 * ice_set_dflt_vsi_ctx - Set default VSI context before adding a VSI
929 * @hw: HW structure used to determine the VLAN mode of the device
930 * @ctxt: the VSI context being set
931 *
932 * This initializes a default VSI context for all sections except the Queues.
933 */
ice_set_dflt_vsi_ctx(struct ice_hw * hw,struct ice_vsi_ctx * ctxt)934 static void ice_set_dflt_vsi_ctx(struct ice_hw *hw, struct ice_vsi_ctx *ctxt)
935 {
936 u32 table = 0;
937
938 memset(&ctxt->info, 0, sizeof(ctxt->info));
939 /* VSI's should be allocated from shared pool */
940 ctxt->alloc_from_pool = true;
941 /* Src pruning enabled by default */
942 ctxt->info.sw_flags = ICE_AQ_VSI_SW_FLAG_SRC_PRUNE;
943 /* Traffic from VSI can be sent to LAN */
944 ctxt->info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
945 /* allow all untagged/tagged packets by default on Tx */
946 ctxt->info.inner_vlan_flags = FIELD_PREP(ICE_AQ_VSI_INNER_VLAN_TX_MODE_M,
947 ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL);
948 /* SVM - by default bits 3 and 4 in inner_vlan_flags are 0's which
949 * results in legacy behavior (show VLAN, DEI, and UP) in descriptor.
950 *
951 * DVM - leave inner VLAN in packet by default
952 */
953 if (ice_is_dvm_ena(hw)) {
954 ctxt->info.inner_vlan_flags |=
955 FIELD_PREP(ICE_AQ_VSI_INNER_VLAN_EMODE_M,
956 ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING);
957 ctxt->info.outer_vlan_flags =
958 FIELD_PREP(ICE_AQ_VSI_OUTER_VLAN_TX_MODE_M,
959 ICE_AQ_VSI_OUTER_VLAN_TX_MODE_ALL);
960 ctxt->info.outer_vlan_flags |=
961 FIELD_PREP(ICE_AQ_VSI_OUTER_TAG_TYPE_M,
962 ICE_AQ_VSI_OUTER_TAG_VLAN_8100);
963 ctxt->info.outer_vlan_flags |=
964 FIELD_PREP(ICE_AQ_VSI_OUTER_VLAN_EMODE_M,
965 ICE_AQ_VSI_OUTER_VLAN_EMODE_NOTHING);
966 }
967 /* Have 1:1 UP mapping for both ingress/egress tables */
968 table |= ICE_UP_TABLE_TRANSLATE(0, 0);
969 table |= ICE_UP_TABLE_TRANSLATE(1, 1);
970 table |= ICE_UP_TABLE_TRANSLATE(2, 2);
971 table |= ICE_UP_TABLE_TRANSLATE(3, 3);
972 table |= ICE_UP_TABLE_TRANSLATE(4, 4);
973 table |= ICE_UP_TABLE_TRANSLATE(5, 5);
974 table |= ICE_UP_TABLE_TRANSLATE(6, 6);
975 table |= ICE_UP_TABLE_TRANSLATE(7, 7);
976 ctxt->info.ingress_table = cpu_to_le32(table);
977 ctxt->info.egress_table = cpu_to_le32(table);
978 /* Have 1:1 UP mapping for outer to inner UP table */
979 ctxt->info.outer_up_table = cpu_to_le32(table);
980 /* No Outer tag support outer_tag_flags remains to zero */
981 }
982
983 /**
984 * ice_vsi_setup_q_map - Setup a VSI queue map
985 * @vsi: the VSI being configured
986 * @ctxt: VSI context structure
987 */
ice_vsi_setup_q_map(struct ice_vsi * vsi,struct ice_vsi_ctx * ctxt)988 static int ice_vsi_setup_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctxt)
989 {
990 u16 offset = 0, qmap = 0, tx_count = 0, rx_count = 0, pow = 0;
991 u16 num_txq_per_tc, num_rxq_per_tc;
992 u16 qcount_tx = vsi->alloc_txq;
993 u16 qcount_rx = vsi->alloc_rxq;
994 u8 netdev_tc = 0;
995 int i;
996
997 if (!vsi->tc_cfg.numtc) {
998 /* at least TC0 should be enabled by default */
999 vsi->tc_cfg.numtc = 1;
1000 vsi->tc_cfg.ena_tc = 1;
1001 }
1002
1003 num_rxq_per_tc = min_t(u16, qcount_rx / vsi->tc_cfg.numtc, ICE_MAX_RXQS_PER_TC);
1004 if (!num_rxq_per_tc)
1005 num_rxq_per_tc = 1;
1006 num_txq_per_tc = qcount_tx / vsi->tc_cfg.numtc;
1007 if (!num_txq_per_tc)
1008 num_txq_per_tc = 1;
1009
1010 /* find the (rounded up) power-of-2 of qcount */
1011 pow = (u16)order_base_2(num_rxq_per_tc);
1012
1013 /* TC mapping is a function of the number of Rx queues assigned to the
1014 * VSI for each traffic class and the offset of these queues.
1015 * The first 10 bits are for queue offset for TC0, next 4 bits for no:of
1016 * queues allocated to TC0. No:of queues is a power-of-2.
1017 *
1018 * If TC is not enabled, the queue offset is set to 0, and allocate one
1019 * queue, this way, traffic for the given TC will be sent to the default
1020 * queue.
1021 *
1022 * Setup number and offset of Rx queues for all TCs for the VSI
1023 */
1024 ice_for_each_traffic_class(i) {
1025 if (!(vsi->tc_cfg.ena_tc & BIT(i))) {
1026 /* TC is not enabled */
1027 vsi->tc_cfg.tc_info[i].qoffset = 0;
1028 vsi->tc_cfg.tc_info[i].qcount_rx = 1;
1029 vsi->tc_cfg.tc_info[i].qcount_tx = 1;
1030 vsi->tc_cfg.tc_info[i].netdev_tc = 0;
1031 ctxt->info.tc_mapping[i] = 0;
1032 continue;
1033 }
1034
1035 /* TC is enabled */
1036 vsi->tc_cfg.tc_info[i].qoffset = offset;
1037 vsi->tc_cfg.tc_info[i].qcount_rx = num_rxq_per_tc;
1038 vsi->tc_cfg.tc_info[i].qcount_tx = num_txq_per_tc;
1039 vsi->tc_cfg.tc_info[i].netdev_tc = netdev_tc++;
1040
1041 qmap = FIELD_PREP(ICE_AQ_VSI_TC_Q_OFFSET_M, offset);
1042 qmap |= FIELD_PREP(ICE_AQ_VSI_TC_Q_NUM_M, pow);
1043 offset += num_rxq_per_tc;
1044 tx_count += num_txq_per_tc;
1045 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
1046 }
1047
1048 /* if offset is non-zero, means it is calculated correctly based on
1049 * enabled TCs for a given VSI otherwise qcount_rx will always
1050 * be correct and non-zero because it is based off - VSI's
1051 * allocated Rx queues which is at least 1 (hence qcount_tx will be
1052 * at least 1)
1053 */
1054 if (offset)
1055 rx_count = offset;
1056 else
1057 rx_count = num_rxq_per_tc;
1058
1059 if (rx_count > vsi->alloc_rxq) {
1060 dev_err(ice_pf_to_dev(vsi->back), "Trying to use more Rx queues (%u), than were allocated (%u)!\n",
1061 rx_count, vsi->alloc_rxq);
1062 return -EINVAL;
1063 }
1064
1065 if (tx_count > vsi->alloc_txq) {
1066 dev_err(ice_pf_to_dev(vsi->back), "Trying to use more Tx queues (%u), than were allocated (%u)!\n",
1067 tx_count, vsi->alloc_txq);
1068 return -EINVAL;
1069 }
1070
1071 vsi->num_txq = tx_count;
1072 vsi->num_rxq = rx_count;
1073
1074 if (vsi->type == ICE_VSI_VF && vsi->num_txq != vsi->num_rxq) {
1075 dev_dbg(ice_pf_to_dev(vsi->back), "VF VSI should have same number of Tx and Rx queues. Hence making them equal\n");
1076 /* since there is a chance that num_rxq could have been changed
1077 * in the above for loop, make num_txq equal to num_rxq.
1078 */
1079 vsi->num_txq = vsi->num_rxq;
1080 }
1081
1082 /* Rx queue mapping */
1083 ctxt->info.mapping_flags |= cpu_to_le16(ICE_AQ_VSI_Q_MAP_CONTIG);
1084 /* q_mapping buffer holds the info for the first queue allocated for
1085 * this VSI in the PF space and also the number of queues associated
1086 * with this VSI.
1087 */
1088 ctxt->info.q_mapping[0] = cpu_to_le16(vsi->rxq_map[0]);
1089 ctxt->info.q_mapping[1] = cpu_to_le16(vsi->num_rxq);
1090
1091 return 0;
1092 }
1093
1094 /**
1095 * ice_set_fd_vsi_ctx - Set FD VSI context before adding a VSI
1096 * @ctxt: the VSI context being set
1097 * @vsi: the VSI being configured
1098 */
ice_set_fd_vsi_ctx(struct ice_vsi_ctx * ctxt,struct ice_vsi * vsi)1099 static void ice_set_fd_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
1100 {
1101 u8 dflt_q_group, dflt_q_prio;
1102 u16 dflt_q, report_q, val;
1103
1104 if (vsi->type != ICE_VSI_PF && vsi->type != ICE_VSI_CTRL &&
1105 vsi->type != ICE_VSI_VF && vsi->type != ICE_VSI_CHNL)
1106 return;
1107
1108 val = ICE_AQ_VSI_PROP_FLOW_DIR_VALID;
1109 ctxt->info.valid_sections |= cpu_to_le16(val);
1110 dflt_q = 0;
1111 dflt_q_group = 0;
1112 report_q = 0;
1113 dflt_q_prio = 0;
1114
1115 /* enable flow director filtering/programming */
1116 val = ICE_AQ_VSI_FD_ENABLE | ICE_AQ_VSI_FD_PROG_ENABLE;
1117 ctxt->info.fd_options = cpu_to_le16(val);
1118 /* max of allocated flow director filters */
1119 ctxt->info.max_fd_fltr_dedicated =
1120 cpu_to_le16(vsi->num_gfltr);
1121 /* max of shared flow director filters any VSI may program */
1122 ctxt->info.max_fd_fltr_shared =
1123 cpu_to_le16(vsi->num_bfltr);
1124 /* default queue index within the VSI of the default FD */
1125 val = FIELD_PREP(ICE_AQ_VSI_FD_DEF_Q_M, dflt_q);
1126 /* target queue or queue group to the FD filter */
1127 val |= FIELD_PREP(ICE_AQ_VSI_FD_DEF_GRP_M, dflt_q_group);
1128 ctxt->info.fd_def_q = cpu_to_le16(val);
1129 /* queue index on which FD filter completion is reported */
1130 val = FIELD_PREP(ICE_AQ_VSI_FD_REPORT_Q_M, report_q);
1131 /* priority of the default qindex action */
1132 val |= FIELD_PREP(ICE_AQ_VSI_FD_DEF_PRIORITY_M, dflt_q_prio);
1133 ctxt->info.fd_report_opt = cpu_to_le16(val);
1134 }
1135
1136 /**
1137 * ice_set_rss_vsi_ctx - Set RSS VSI context before adding a VSI
1138 * @ctxt: the VSI context being set
1139 * @vsi: the VSI being configured
1140 */
ice_set_rss_vsi_ctx(struct ice_vsi_ctx * ctxt,struct ice_vsi * vsi)1141 static void ice_set_rss_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
1142 {
1143 u8 lut_type, hash_type;
1144 struct device *dev;
1145 struct ice_pf *pf;
1146
1147 pf = vsi->back;
1148 dev = ice_pf_to_dev(pf);
1149
1150 switch (vsi->type) {
1151 case ICE_VSI_CHNL:
1152 case ICE_VSI_PF:
1153 /* PF VSI will inherit RSS instance of PF */
1154 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_PF;
1155 break;
1156 case ICE_VSI_VF:
1157 case ICE_VSI_SF:
1158 /* VF VSI will gets a small RSS table which is a VSI LUT type */
1159 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI;
1160 break;
1161 default:
1162 dev_dbg(dev, "Unsupported VSI type %s\n",
1163 ice_vsi_type_str(vsi->type));
1164 return;
1165 }
1166
1167 hash_type = ICE_AQ_VSI_Q_OPT_RSS_HASH_TPLZ;
1168 vsi->rss_hfunc = hash_type;
1169
1170 ctxt->info.q_opt_rss =
1171 FIELD_PREP(ICE_AQ_VSI_Q_OPT_RSS_LUT_M, lut_type) |
1172 FIELD_PREP(ICE_AQ_VSI_Q_OPT_RSS_HASH_M, hash_type);
1173 }
1174
1175 static void
ice_chnl_vsi_setup_q_map(struct ice_vsi * vsi,struct ice_vsi_ctx * ctxt)1176 ice_chnl_vsi_setup_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctxt)
1177 {
1178 struct ice_pf *pf = vsi->back;
1179 u16 qcount, qmap;
1180 u8 offset = 0;
1181 int pow;
1182
1183 qcount = min_t(int, vsi->num_rxq, pf->num_lan_msix);
1184
1185 pow = order_base_2(qcount);
1186 qmap = FIELD_PREP(ICE_AQ_VSI_TC_Q_OFFSET_M, offset);
1187 qmap |= FIELD_PREP(ICE_AQ_VSI_TC_Q_NUM_M, pow);
1188
1189 ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
1190 ctxt->info.mapping_flags |= cpu_to_le16(ICE_AQ_VSI_Q_MAP_CONTIG);
1191 ctxt->info.q_mapping[0] = cpu_to_le16(vsi->next_base_q);
1192 ctxt->info.q_mapping[1] = cpu_to_le16(qcount);
1193 }
1194
1195 /**
1196 * ice_vsi_is_vlan_pruning_ena - check if VLAN pruning is enabled or not
1197 * @vsi: VSI to check whether or not VLAN pruning is enabled.
1198 *
1199 * returns true if Rx VLAN pruning is enabled and false otherwise.
1200 */
ice_vsi_is_vlan_pruning_ena(struct ice_vsi * vsi)1201 static bool ice_vsi_is_vlan_pruning_ena(struct ice_vsi *vsi)
1202 {
1203 return vsi->info.sw_flags2 & ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
1204 }
1205
1206 /**
1207 * ice_vsi_init - Create and initialize a VSI
1208 * @vsi: the VSI being configured
1209 * @vsi_flags: VSI configuration flags
1210 *
1211 * Set ICE_FLAG_VSI_INIT to initialize a new VSI context, clear it to
1212 * reconfigure an existing context.
1213 *
1214 * This initializes a VSI context depending on the VSI type to be added and
1215 * passes it down to the add_vsi aq command to create a new VSI.
1216 */
ice_vsi_init(struct ice_vsi * vsi,u32 vsi_flags)1217 static int ice_vsi_init(struct ice_vsi *vsi, u32 vsi_flags)
1218 {
1219 struct ice_pf *pf = vsi->back;
1220 struct ice_hw *hw = &pf->hw;
1221 struct ice_vsi_ctx *ctxt;
1222 struct device *dev;
1223 int ret = 0;
1224
1225 dev = ice_pf_to_dev(pf);
1226 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
1227 if (!ctxt)
1228 return -ENOMEM;
1229
1230 switch (vsi->type) {
1231 case ICE_VSI_CTRL:
1232 case ICE_VSI_LB:
1233 case ICE_VSI_PF:
1234 ctxt->flags = ICE_AQ_VSI_TYPE_PF;
1235 break;
1236 case ICE_VSI_SF:
1237 case ICE_VSI_CHNL:
1238 ctxt->flags = ICE_AQ_VSI_TYPE_VMDQ2;
1239 break;
1240 case ICE_VSI_VF:
1241 ctxt->flags = ICE_AQ_VSI_TYPE_VF;
1242 /* VF number here is the absolute VF number (0-255) */
1243 ctxt->vf_num = vsi->vf->vf_id + hw->func_caps.vf_base_id;
1244 break;
1245 default:
1246 ret = -ENODEV;
1247 goto out;
1248 }
1249
1250 /* Handle VLAN pruning for channel VSI if main VSI has VLAN
1251 * prune enabled
1252 */
1253 if (vsi->type == ICE_VSI_CHNL) {
1254 struct ice_vsi *main_vsi;
1255
1256 main_vsi = ice_get_main_vsi(pf);
1257 if (main_vsi && ice_vsi_is_vlan_pruning_ena(main_vsi))
1258 ctxt->info.sw_flags2 |=
1259 ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
1260 else
1261 ctxt->info.sw_flags2 &=
1262 ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
1263 }
1264
1265 ice_set_dflt_vsi_ctx(hw, ctxt);
1266 if (test_bit(ICE_FLAG_FD_ENA, pf->flags))
1267 ice_set_fd_vsi_ctx(ctxt, vsi);
1268 /* if the switch is in VEB mode, allow VSI loopback */
1269 if (vsi->vsw->bridge_mode == BRIDGE_MODE_VEB)
1270 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
1271
1272 /* Set LUT type and HASH type if RSS is enabled */
1273 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags) &&
1274 vsi->type != ICE_VSI_CTRL) {
1275 ice_set_rss_vsi_ctx(ctxt, vsi);
1276 /* if updating VSI context, make sure to set valid_section:
1277 * to indicate which section of VSI context being updated
1278 */
1279 if (!(vsi_flags & ICE_VSI_FLAG_INIT))
1280 ctxt->info.valid_sections |=
1281 cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
1282 }
1283
1284 ctxt->info.sw_id = vsi->port_info->sw_id;
1285 if (vsi->type == ICE_VSI_CHNL) {
1286 ice_chnl_vsi_setup_q_map(vsi, ctxt);
1287 } else {
1288 ret = ice_vsi_setup_q_map(vsi, ctxt);
1289 if (ret)
1290 goto out;
1291
1292 if (!(vsi_flags & ICE_VSI_FLAG_INIT))
1293 /* means VSI being updated */
1294 /* must to indicate which section of VSI context are
1295 * being modified
1296 */
1297 ctxt->info.valid_sections |=
1298 cpu_to_le16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
1299 }
1300
1301 /* Allow control frames out of main VSI */
1302 if (vsi->type == ICE_VSI_PF) {
1303 ctxt->info.sec_flags |= ICE_AQ_VSI_SEC_FLAG_ALLOW_DEST_OVRD;
1304 ctxt->info.valid_sections |=
1305 cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID);
1306 }
1307
1308 if (vsi_flags & ICE_VSI_FLAG_INIT) {
1309 ret = ice_add_vsi(hw, vsi->idx, ctxt, NULL);
1310 if (ret) {
1311 dev_err(dev, "Add VSI failed, err %d\n", ret);
1312 ret = -EIO;
1313 goto out;
1314 }
1315 } else {
1316 ret = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1317 if (ret) {
1318 dev_err(dev, "Update VSI failed, err %d\n", ret);
1319 ret = -EIO;
1320 goto out;
1321 }
1322 }
1323
1324 /* keep context for update VSI operations */
1325 vsi->info = ctxt->info;
1326
1327 /* record VSI number returned */
1328 vsi->vsi_num = ctxt->vsi_num;
1329
1330 out:
1331 kfree(ctxt);
1332 return ret;
1333 }
1334
1335 /**
1336 * ice_vsi_clear_rings - Deallocates the Tx and Rx rings for VSI
1337 * @vsi: the VSI having rings deallocated
1338 */
ice_vsi_clear_rings(struct ice_vsi * vsi)1339 static void ice_vsi_clear_rings(struct ice_vsi *vsi)
1340 {
1341 int i;
1342
1343 /* Avoid stale references by clearing map from vector to ring */
1344 if (vsi->q_vectors) {
1345 ice_for_each_q_vector(vsi, i) {
1346 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1347
1348 if (q_vector) {
1349 q_vector->tx.tx_ring = NULL;
1350 q_vector->rx.rx_ring = NULL;
1351 }
1352 }
1353 }
1354
1355 if (vsi->tx_rings) {
1356 ice_for_each_alloc_txq(vsi, i) {
1357 if (vsi->tx_rings[i]) {
1358 kfree_rcu(vsi->tx_rings[i], rcu);
1359 WRITE_ONCE(vsi->tx_rings[i], NULL);
1360 }
1361 }
1362 }
1363 if (vsi->rx_rings) {
1364 ice_for_each_alloc_rxq(vsi, i) {
1365 if (vsi->rx_rings[i]) {
1366 kfree_rcu(vsi->rx_rings[i], rcu);
1367 WRITE_ONCE(vsi->rx_rings[i], NULL);
1368 }
1369 }
1370 }
1371 }
1372
1373 /**
1374 * ice_vsi_alloc_rings - Allocates Tx and Rx rings for the VSI
1375 * @vsi: VSI which is having rings allocated
1376 */
ice_vsi_alloc_rings(struct ice_vsi * vsi)1377 static int ice_vsi_alloc_rings(struct ice_vsi *vsi)
1378 {
1379 bool dvm_ena = ice_is_dvm_ena(&vsi->back->hw);
1380 struct ice_pf *pf = vsi->back;
1381 struct device *dev;
1382 u16 i;
1383
1384 dev = ice_pf_to_dev(pf);
1385 /* Allocate Tx rings */
1386 ice_for_each_alloc_txq(vsi, i) {
1387 struct ice_tx_ring *ring;
1388
1389 /* allocate with kzalloc(), free with kfree_rcu() */
1390 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1391
1392 if (!ring)
1393 goto err_out;
1394
1395 ring->q_index = i;
1396 ring->reg_idx = vsi->txq_map[i];
1397 ring->vsi = vsi;
1398 ring->tx_tstamps = &pf->ptp.port.tx;
1399 ring->dev = dev;
1400 ring->count = vsi->num_tx_desc;
1401 ring->txq_teid = ICE_INVAL_TEID;
1402 if (dvm_ena)
1403 ring->flags |= ICE_TX_FLAGS_RING_VLAN_L2TAG2;
1404 else
1405 ring->flags |= ICE_TX_FLAGS_RING_VLAN_L2TAG1;
1406 WRITE_ONCE(vsi->tx_rings[i], ring);
1407 }
1408
1409 /* Allocate Rx rings */
1410 ice_for_each_alloc_rxq(vsi, i) {
1411 struct ice_rx_ring *ring;
1412
1413 /* allocate with kzalloc(), free with kfree_rcu() */
1414 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1415 if (!ring)
1416 goto err_out;
1417
1418 ring->q_index = i;
1419 ring->reg_idx = vsi->rxq_map[i];
1420 ring->vsi = vsi;
1421 ring->netdev = vsi->netdev;
1422 ring->dev = dev;
1423 ring->count = vsi->num_rx_desc;
1424 ring->cached_phctime = pf->ptp.cached_phc_time;
1425 WRITE_ONCE(vsi->rx_rings[i], ring);
1426 }
1427
1428 return 0;
1429
1430 err_out:
1431 ice_vsi_clear_rings(vsi);
1432 return -ENOMEM;
1433 }
1434
1435 /**
1436 * ice_vsi_manage_rss_lut - disable/enable RSS
1437 * @vsi: the VSI being changed
1438 * @ena: boolean value indicating if this is an enable or disable request
1439 *
1440 * In the event of disable request for RSS, this function will zero out RSS
1441 * LUT, while in the event of enable request for RSS, it will reconfigure RSS
1442 * LUT.
1443 */
ice_vsi_manage_rss_lut(struct ice_vsi * vsi,bool ena)1444 void ice_vsi_manage_rss_lut(struct ice_vsi *vsi, bool ena)
1445 {
1446 u8 *lut;
1447
1448 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
1449 if (!lut)
1450 return;
1451
1452 if (ena) {
1453 if (vsi->rss_lut_user)
1454 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1455 else
1456 ice_fill_rss_lut(lut, vsi->rss_table_size,
1457 vsi->rss_size);
1458 }
1459
1460 ice_set_rss_lut(vsi, lut, vsi->rss_table_size);
1461 kfree(lut);
1462 }
1463
1464 /**
1465 * ice_vsi_cfg_crc_strip - Configure CRC stripping for a VSI
1466 * @vsi: VSI to be configured
1467 * @disable: set to true to have FCS / CRC in the frame data
1468 */
ice_vsi_cfg_crc_strip(struct ice_vsi * vsi,bool disable)1469 void ice_vsi_cfg_crc_strip(struct ice_vsi *vsi, bool disable)
1470 {
1471 int i;
1472
1473 ice_for_each_rxq(vsi, i)
1474 if (disable)
1475 vsi->rx_rings[i]->flags |= ICE_RX_FLAGS_CRC_STRIP_DIS;
1476 else
1477 vsi->rx_rings[i]->flags &= ~ICE_RX_FLAGS_CRC_STRIP_DIS;
1478 }
1479
1480 /**
1481 * ice_vsi_cfg_rss_lut_key - Configure RSS params for a VSI
1482 * @vsi: VSI to be configured
1483 */
ice_vsi_cfg_rss_lut_key(struct ice_vsi * vsi)1484 int ice_vsi_cfg_rss_lut_key(struct ice_vsi *vsi)
1485 {
1486 struct ice_pf *pf = vsi->back;
1487 struct device *dev;
1488 u8 *lut, *key;
1489 int err;
1490
1491 dev = ice_pf_to_dev(pf);
1492 if (vsi->type == ICE_VSI_PF && vsi->ch_rss_size &&
1493 (test_bit(ICE_FLAG_TC_MQPRIO, pf->flags))) {
1494 vsi->rss_size = min_t(u16, vsi->rss_size, vsi->ch_rss_size);
1495 } else {
1496 vsi->rss_size = min_t(u16, vsi->rss_size, vsi->num_rxq);
1497
1498 /* If orig_rss_size is valid and it is less than determined
1499 * main VSI's rss_size, update main VSI's rss_size to be
1500 * orig_rss_size so that when tc-qdisc is deleted, main VSI
1501 * RSS table gets programmed to be correct (whatever it was
1502 * to begin with (prior to setup-tc for ADQ config)
1503 */
1504 if (vsi->orig_rss_size && vsi->rss_size < vsi->orig_rss_size &&
1505 vsi->orig_rss_size <= vsi->num_rxq) {
1506 vsi->rss_size = vsi->orig_rss_size;
1507 /* now orig_rss_size is used, reset it to zero */
1508 vsi->orig_rss_size = 0;
1509 }
1510 }
1511
1512 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
1513 if (!lut)
1514 return -ENOMEM;
1515
1516 if (vsi->rss_lut_user)
1517 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1518 else
1519 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
1520
1521 err = ice_set_rss_lut(vsi, lut, vsi->rss_table_size);
1522 if (err) {
1523 dev_err(dev, "set_rss_lut failed, error %d\n", err);
1524 goto ice_vsi_cfg_rss_exit;
1525 }
1526
1527 key = kzalloc(ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE, GFP_KERNEL);
1528 if (!key) {
1529 err = -ENOMEM;
1530 goto ice_vsi_cfg_rss_exit;
1531 }
1532
1533 if (vsi->rss_hkey_user)
1534 memcpy(key, vsi->rss_hkey_user, ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE);
1535 else
1536 netdev_rss_key_fill((void *)key, ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE);
1537
1538 err = ice_set_rss_key(vsi, key);
1539 if (err)
1540 dev_err(dev, "set_rss_key failed, error %d\n", err);
1541
1542 kfree(key);
1543 ice_vsi_cfg_rss_exit:
1544 kfree(lut);
1545 return err;
1546 }
1547
1548 /**
1549 * ice_vsi_set_vf_rss_flow_fld - Sets VF VSI RSS input set for different flows
1550 * @vsi: VSI to be configured
1551 *
1552 * This function will only be called during the VF VSI setup. Upon successful
1553 * completion of package download, this function will configure default RSS
1554 * input sets for VF VSI.
1555 */
ice_vsi_set_vf_rss_flow_fld(struct ice_vsi * vsi)1556 static void ice_vsi_set_vf_rss_flow_fld(struct ice_vsi *vsi)
1557 {
1558 struct ice_pf *pf = vsi->back;
1559 struct device *dev;
1560 int status;
1561
1562 dev = ice_pf_to_dev(pf);
1563 if (ice_is_safe_mode(pf)) {
1564 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
1565 vsi->vsi_num);
1566 return;
1567 }
1568
1569 status = ice_add_avf_rss_cfg(&pf->hw, vsi, ICE_DEFAULT_RSS_HENA);
1570 if (status)
1571 dev_dbg(dev, "ice_add_avf_rss_cfg failed for vsi = %d, error = %d\n",
1572 vsi->vsi_num, status);
1573 }
1574
1575 static const struct ice_rss_hash_cfg default_rss_cfgs[] = {
1576 /* configure RSS for IPv4 with input set IP src/dst */
1577 {ICE_FLOW_SEG_HDR_IPV4, ICE_FLOW_HASH_IPV4, ICE_RSS_ANY_HEADERS, false},
1578 /* configure RSS for IPv6 with input set IPv6 src/dst */
1579 {ICE_FLOW_SEG_HDR_IPV6, ICE_FLOW_HASH_IPV6, ICE_RSS_ANY_HEADERS, false},
1580 /* configure RSS for tcp4 with input set IP src/dst, TCP src/dst */
1581 {ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4,
1582 ICE_HASH_TCP_IPV4, ICE_RSS_ANY_HEADERS, false},
1583 /* configure RSS for udp4 with input set IP src/dst, UDP src/dst */
1584 {ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4,
1585 ICE_HASH_UDP_IPV4, ICE_RSS_ANY_HEADERS, false},
1586 /* configure RSS for sctp4 with input set IP src/dst - only support
1587 * RSS on SCTPv4 on outer headers (non-tunneled)
1588 */
1589 {ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4,
1590 ICE_HASH_SCTP_IPV4, ICE_RSS_OUTER_HEADERS, false},
1591 /* configure RSS for gtpc4 with input set IPv4 src/dst */
1592 {ICE_FLOW_SEG_HDR_GTPC | ICE_FLOW_SEG_HDR_IPV4,
1593 ICE_FLOW_HASH_IPV4, ICE_RSS_OUTER_HEADERS, false},
1594 /* configure RSS for gtpc4t with input set IPv4 src/dst */
1595 {ICE_FLOW_SEG_HDR_GTPC_TEID | ICE_FLOW_SEG_HDR_IPV4,
1596 ICE_FLOW_HASH_GTP_C_IPV4_TEID, ICE_RSS_OUTER_HEADERS, false},
1597 /* configure RSS for gtpu4 with input set IPv4 src/dst */
1598 {ICE_FLOW_SEG_HDR_GTPU_IP | ICE_FLOW_SEG_HDR_IPV4,
1599 ICE_FLOW_HASH_GTP_U_IPV4_TEID, ICE_RSS_OUTER_HEADERS, false},
1600 /* configure RSS for gtpu4e with input set IPv4 src/dst */
1601 {ICE_FLOW_SEG_HDR_GTPU_EH | ICE_FLOW_SEG_HDR_IPV4,
1602 ICE_FLOW_HASH_GTP_U_IPV4_EH, ICE_RSS_OUTER_HEADERS, false},
1603 /* configure RSS for gtpu4u with input set IPv4 src/dst */
1604 { ICE_FLOW_SEG_HDR_GTPU_UP | ICE_FLOW_SEG_HDR_IPV4,
1605 ICE_FLOW_HASH_GTP_U_IPV4_UP, ICE_RSS_OUTER_HEADERS, false},
1606 /* configure RSS for gtpu4d with input set IPv4 src/dst */
1607 {ICE_FLOW_SEG_HDR_GTPU_DWN | ICE_FLOW_SEG_HDR_IPV4,
1608 ICE_FLOW_HASH_GTP_U_IPV4_DWN, ICE_RSS_OUTER_HEADERS, false},
1609
1610 /* configure RSS for tcp6 with input set IPv6 src/dst, TCP src/dst */
1611 {ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6,
1612 ICE_HASH_TCP_IPV6, ICE_RSS_ANY_HEADERS, false},
1613 /* configure RSS for udp6 with input set IPv6 src/dst, UDP src/dst */
1614 {ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6,
1615 ICE_HASH_UDP_IPV6, ICE_RSS_ANY_HEADERS, false},
1616 /* configure RSS for sctp6 with input set IPv6 src/dst - only support
1617 * RSS on SCTPv6 on outer headers (non-tunneled)
1618 */
1619 {ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6,
1620 ICE_HASH_SCTP_IPV6, ICE_RSS_OUTER_HEADERS, false},
1621 /* configure RSS for IPSEC ESP SPI with input set MAC_IPV4_SPI */
1622 {ICE_FLOW_SEG_HDR_ESP,
1623 ICE_FLOW_HASH_ESP_SPI, ICE_RSS_OUTER_HEADERS, false},
1624 /* configure RSS for gtpc6 with input set IPv6 src/dst */
1625 {ICE_FLOW_SEG_HDR_GTPC | ICE_FLOW_SEG_HDR_IPV6,
1626 ICE_FLOW_HASH_IPV6, ICE_RSS_OUTER_HEADERS, false},
1627 /* configure RSS for gtpc6t with input set IPv6 src/dst */
1628 {ICE_FLOW_SEG_HDR_GTPC_TEID | ICE_FLOW_SEG_HDR_IPV6,
1629 ICE_FLOW_HASH_GTP_C_IPV6_TEID, ICE_RSS_OUTER_HEADERS, false},
1630 /* configure RSS for gtpu6 with input set IPv6 src/dst */
1631 {ICE_FLOW_SEG_HDR_GTPU_IP | ICE_FLOW_SEG_HDR_IPV6,
1632 ICE_FLOW_HASH_GTP_U_IPV6_TEID, ICE_RSS_OUTER_HEADERS, false},
1633 /* configure RSS for gtpu6e with input set IPv6 src/dst */
1634 {ICE_FLOW_SEG_HDR_GTPU_EH | ICE_FLOW_SEG_HDR_IPV6,
1635 ICE_FLOW_HASH_GTP_U_IPV6_EH, ICE_RSS_OUTER_HEADERS, false},
1636 /* configure RSS for gtpu6u with input set IPv6 src/dst */
1637 { ICE_FLOW_SEG_HDR_GTPU_UP | ICE_FLOW_SEG_HDR_IPV6,
1638 ICE_FLOW_HASH_GTP_U_IPV6_UP, ICE_RSS_OUTER_HEADERS, false},
1639 /* configure RSS for gtpu6d with input set IPv6 src/dst */
1640 {ICE_FLOW_SEG_HDR_GTPU_DWN | ICE_FLOW_SEG_HDR_IPV6,
1641 ICE_FLOW_HASH_GTP_U_IPV6_DWN, ICE_RSS_OUTER_HEADERS, false},
1642 };
1643
1644 /**
1645 * ice_vsi_set_rss_flow_fld - Sets RSS input set for different flows
1646 * @vsi: VSI to be configured
1647 *
1648 * This function will only be called after successful download package call
1649 * during initialization of PF. Since the downloaded package will erase the
1650 * RSS section, this function will configure RSS input sets for different
1651 * flow types. The last profile added has the highest priority, therefore 2
1652 * tuple profiles (i.e. IPv4 src/dst) are added before 4 tuple profiles
1653 * (i.e. IPv4 src/dst TCP src/dst port).
1654 */
ice_vsi_set_rss_flow_fld(struct ice_vsi * vsi)1655 static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi)
1656 {
1657 u16 vsi_num = vsi->vsi_num;
1658 struct ice_pf *pf = vsi->back;
1659 struct ice_hw *hw = &pf->hw;
1660 struct device *dev;
1661 int status;
1662 u32 i;
1663
1664 dev = ice_pf_to_dev(pf);
1665 if (ice_is_safe_mode(pf)) {
1666 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
1667 vsi_num);
1668 return;
1669 }
1670 for (i = 0; i < ARRAY_SIZE(default_rss_cfgs); i++) {
1671 const struct ice_rss_hash_cfg *cfg = &default_rss_cfgs[i];
1672
1673 status = ice_add_rss_cfg(hw, vsi, cfg);
1674 if (status)
1675 dev_dbg(dev, "ice_add_rss_cfg failed, addl_hdrs = %x, hash_flds = %llx, hdr_type = %d, symm = %d\n",
1676 cfg->addl_hdrs, cfg->hash_flds,
1677 cfg->hdr_type, cfg->symm);
1678 }
1679 }
1680
1681 /**
1682 * ice_pf_state_is_nominal - checks the PF for nominal state
1683 * @pf: pointer to PF to check
1684 *
1685 * Check the PF's state for a collection of bits that would indicate
1686 * the PF is in a state that would inhibit normal operation for
1687 * driver functionality.
1688 *
1689 * Returns true if PF is in a nominal state, false otherwise
1690 */
ice_pf_state_is_nominal(struct ice_pf * pf)1691 bool ice_pf_state_is_nominal(struct ice_pf *pf)
1692 {
1693 DECLARE_BITMAP(check_bits, ICE_STATE_NBITS) = { 0 };
1694
1695 if (!pf)
1696 return false;
1697
1698 bitmap_set(check_bits, 0, ICE_STATE_NOMINAL_CHECK_BITS);
1699 if (bitmap_intersects(pf->state, check_bits, ICE_STATE_NBITS))
1700 return false;
1701
1702 return true;
1703 }
1704
1705 /**
1706 * ice_update_eth_stats - Update VSI-specific ethernet statistics counters
1707 * @vsi: the VSI to be updated
1708 */
ice_update_eth_stats(struct ice_vsi * vsi)1709 void ice_update_eth_stats(struct ice_vsi *vsi)
1710 {
1711 struct ice_eth_stats *prev_es, *cur_es;
1712 struct ice_hw *hw = &vsi->back->hw;
1713 struct ice_pf *pf = vsi->back;
1714 u16 vsi_num = vsi->vsi_num; /* HW absolute index of a VSI */
1715
1716 prev_es = &vsi->eth_stats_prev;
1717 cur_es = &vsi->eth_stats;
1718
1719 if (ice_is_reset_in_progress(pf->state))
1720 vsi->stat_offsets_loaded = false;
1721
1722 ice_stat_update40(hw, GLV_GORCL(vsi_num), vsi->stat_offsets_loaded,
1723 &prev_es->rx_bytes, &cur_es->rx_bytes);
1724
1725 ice_stat_update40(hw, GLV_UPRCL(vsi_num), vsi->stat_offsets_loaded,
1726 &prev_es->rx_unicast, &cur_es->rx_unicast);
1727
1728 ice_stat_update40(hw, GLV_MPRCL(vsi_num), vsi->stat_offsets_loaded,
1729 &prev_es->rx_multicast, &cur_es->rx_multicast);
1730
1731 ice_stat_update40(hw, GLV_BPRCL(vsi_num), vsi->stat_offsets_loaded,
1732 &prev_es->rx_broadcast, &cur_es->rx_broadcast);
1733
1734 ice_stat_update32(hw, GLV_RDPC(vsi_num), vsi->stat_offsets_loaded,
1735 &prev_es->rx_discards, &cur_es->rx_discards);
1736
1737 ice_stat_update40(hw, GLV_GOTCL(vsi_num), vsi->stat_offsets_loaded,
1738 &prev_es->tx_bytes, &cur_es->tx_bytes);
1739
1740 ice_stat_update40(hw, GLV_UPTCL(vsi_num), vsi->stat_offsets_loaded,
1741 &prev_es->tx_unicast, &cur_es->tx_unicast);
1742
1743 ice_stat_update40(hw, GLV_MPTCL(vsi_num), vsi->stat_offsets_loaded,
1744 &prev_es->tx_multicast, &cur_es->tx_multicast);
1745
1746 ice_stat_update40(hw, GLV_BPTCL(vsi_num), vsi->stat_offsets_loaded,
1747 &prev_es->tx_broadcast, &cur_es->tx_broadcast);
1748
1749 ice_stat_update32(hw, GLV_TEPC(vsi_num), vsi->stat_offsets_loaded,
1750 &prev_es->tx_errors, &cur_es->tx_errors);
1751
1752 vsi->stat_offsets_loaded = true;
1753 }
1754
1755 /**
1756 * ice_write_qrxflxp_cntxt - write/configure QRXFLXP_CNTXT register
1757 * @hw: HW pointer
1758 * @pf_q: index of the Rx queue in the PF's queue space
1759 * @rxdid: flexible descriptor RXDID
1760 * @prio: priority for the RXDID for this queue
1761 * @ena_ts: true to enable timestamp and false to disable timestamp
1762 */
1763 void
ice_write_qrxflxp_cntxt(struct ice_hw * hw,u16 pf_q,u32 rxdid,u32 prio,bool ena_ts)1764 ice_write_qrxflxp_cntxt(struct ice_hw *hw, u16 pf_q, u32 rxdid, u32 prio,
1765 bool ena_ts)
1766 {
1767 int regval = rd32(hw, QRXFLXP_CNTXT(pf_q));
1768
1769 /* clear any previous values */
1770 regval &= ~(QRXFLXP_CNTXT_RXDID_IDX_M |
1771 QRXFLXP_CNTXT_RXDID_PRIO_M |
1772 QRXFLXP_CNTXT_TS_M);
1773
1774 regval |= FIELD_PREP(QRXFLXP_CNTXT_RXDID_IDX_M, rxdid);
1775 regval |= FIELD_PREP(QRXFLXP_CNTXT_RXDID_PRIO_M, prio);
1776
1777 if (ena_ts)
1778 /* Enable TimeSync on this queue */
1779 regval |= QRXFLXP_CNTXT_TS_M;
1780
1781 wr32(hw, QRXFLXP_CNTXT(pf_q), regval);
1782 }
1783
1784 /**
1785 * ice_intrl_usec_to_reg - convert interrupt rate limit to register value
1786 * @intrl: interrupt rate limit in usecs
1787 * @gran: interrupt rate limit granularity in usecs
1788 *
1789 * This function converts a decimal interrupt rate limit in usecs to the format
1790 * expected by firmware.
1791 */
ice_intrl_usec_to_reg(u8 intrl,u8 gran)1792 static u32 ice_intrl_usec_to_reg(u8 intrl, u8 gran)
1793 {
1794 u32 val = intrl / gran;
1795
1796 if (val)
1797 return val | GLINT_RATE_INTRL_ENA_M;
1798 return 0;
1799 }
1800
1801 /**
1802 * ice_write_intrl - write throttle rate limit to interrupt specific register
1803 * @q_vector: pointer to interrupt specific structure
1804 * @intrl: throttle rate limit in microseconds to write
1805 */
ice_write_intrl(struct ice_q_vector * q_vector,u8 intrl)1806 void ice_write_intrl(struct ice_q_vector *q_vector, u8 intrl)
1807 {
1808 struct ice_hw *hw = &q_vector->vsi->back->hw;
1809
1810 wr32(hw, GLINT_RATE(q_vector->reg_idx),
1811 ice_intrl_usec_to_reg(intrl, ICE_INTRL_GRAN_ABOVE_25));
1812 }
1813
ice_pull_qvec_from_rc(struct ice_ring_container * rc)1814 static struct ice_q_vector *ice_pull_qvec_from_rc(struct ice_ring_container *rc)
1815 {
1816 switch (rc->type) {
1817 case ICE_RX_CONTAINER:
1818 if (rc->rx_ring)
1819 return rc->rx_ring->q_vector;
1820 break;
1821 case ICE_TX_CONTAINER:
1822 if (rc->tx_ring)
1823 return rc->tx_ring->q_vector;
1824 break;
1825 default:
1826 break;
1827 }
1828
1829 return NULL;
1830 }
1831
1832 /**
1833 * __ice_write_itr - write throttle rate to register
1834 * @q_vector: pointer to interrupt data structure
1835 * @rc: pointer to ring container
1836 * @itr: throttle rate in microseconds to write
1837 */
__ice_write_itr(struct ice_q_vector * q_vector,struct ice_ring_container * rc,u16 itr)1838 static void __ice_write_itr(struct ice_q_vector *q_vector,
1839 struct ice_ring_container *rc, u16 itr)
1840 {
1841 struct ice_hw *hw = &q_vector->vsi->back->hw;
1842
1843 wr32(hw, GLINT_ITR(rc->itr_idx, q_vector->reg_idx),
1844 ITR_REG_ALIGN(itr) >> ICE_ITR_GRAN_S);
1845 }
1846
1847 /**
1848 * ice_write_itr - write throttle rate to queue specific register
1849 * @rc: pointer to ring container
1850 * @itr: throttle rate in microseconds to write
1851 */
ice_write_itr(struct ice_ring_container * rc,u16 itr)1852 void ice_write_itr(struct ice_ring_container *rc, u16 itr)
1853 {
1854 struct ice_q_vector *q_vector;
1855
1856 q_vector = ice_pull_qvec_from_rc(rc);
1857 if (!q_vector)
1858 return;
1859
1860 __ice_write_itr(q_vector, rc, itr);
1861 }
1862
1863 /**
1864 * ice_set_q_vector_intrl - set up interrupt rate limiting
1865 * @q_vector: the vector to be configured
1866 *
1867 * Interrupt rate limiting is local to the vector, not per-queue so we must
1868 * detect if either ring container has dynamic moderation enabled to decide
1869 * what to set the interrupt rate limit to via INTRL settings. In the case that
1870 * dynamic moderation is disabled on both, write the value with the cached
1871 * setting to make sure INTRL register matches the user visible value.
1872 */
ice_set_q_vector_intrl(struct ice_q_vector * q_vector)1873 void ice_set_q_vector_intrl(struct ice_q_vector *q_vector)
1874 {
1875 if (ITR_IS_DYNAMIC(&q_vector->tx) || ITR_IS_DYNAMIC(&q_vector->rx)) {
1876 /* in the case of dynamic enabled, cap each vector to no more
1877 * than (4 us) 250,000 ints/sec, which allows low latency
1878 * but still less than 500,000 interrupts per second, which
1879 * reduces CPU a bit in the case of the lowest latency
1880 * setting. The 4 here is a value in microseconds.
1881 */
1882 ice_write_intrl(q_vector, 4);
1883 } else {
1884 ice_write_intrl(q_vector, q_vector->intrl);
1885 }
1886 }
1887
1888 /**
1889 * ice_vsi_cfg_msix - MSIX mode Interrupt Config in the HW
1890 * @vsi: the VSI being configured
1891 *
1892 * This configures MSIX mode interrupts for the PF VSI, and should not be used
1893 * for the VF VSI.
1894 */
ice_vsi_cfg_msix(struct ice_vsi * vsi)1895 void ice_vsi_cfg_msix(struct ice_vsi *vsi)
1896 {
1897 struct ice_pf *pf = vsi->back;
1898 struct ice_hw *hw = &pf->hw;
1899 u16 txq = 0, rxq = 0;
1900 int i, q;
1901
1902 ice_for_each_q_vector(vsi, i) {
1903 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1904 u16 reg_idx = q_vector->reg_idx;
1905
1906 ice_cfg_itr(hw, q_vector);
1907
1908 /* Both Transmit Queue Interrupt Cause Control register
1909 * and Receive Queue Interrupt Cause control register
1910 * expects MSIX_INDX field to be the vector index
1911 * within the function space and not the absolute
1912 * vector index across PF or across device.
1913 * For SR-IOV VF VSIs queue vector index always starts
1914 * with 1 since first vector index(0) is used for OICR
1915 * in VF space. Since VMDq and other PF VSIs are within
1916 * the PF function space, use the vector index that is
1917 * tracked for this PF.
1918 */
1919 for (q = 0; q < q_vector->num_ring_tx; q++) {
1920 ice_cfg_txq_interrupt(vsi, txq, reg_idx,
1921 q_vector->tx.itr_idx);
1922 txq++;
1923 }
1924
1925 for (q = 0; q < q_vector->num_ring_rx; q++) {
1926 ice_cfg_rxq_interrupt(vsi, rxq, reg_idx,
1927 q_vector->rx.itr_idx);
1928 rxq++;
1929 }
1930 }
1931 }
1932
1933 /**
1934 * ice_vsi_start_all_rx_rings - start/enable all of a VSI's Rx rings
1935 * @vsi: the VSI whose rings are to be enabled
1936 *
1937 * Returns 0 on success and a negative value on error
1938 */
ice_vsi_start_all_rx_rings(struct ice_vsi * vsi)1939 int ice_vsi_start_all_rx_rings(struct ice_vsi *vsi)
1940 {
1941 return ice_vsi_ctrl_all_rx_rings(vsi, true);
1942 }
1943
1944 /**
1945 * ice_vsi_stop_all_rx_rings - stop/disable all of a VSI's Rx rings
1946 * @vsi: the VSI whose rings are to be disabled
1947 *
1948 * Returns 0 on success and a negative value on error
1949 */
ice_vsi_stop_all_rx_rings(struct ice_vsi * vsi)1950 int ice_vsi_stop_all_rx_rings(struct ice_vsi *vsi)
1951 {
1952 return ice_vsi_ctrl_all_rx_rings(vsi, false);
1953 }
1954
1955 /**
1956 * ice_vsi_stop_tx_rings - Disable Tx rings
1957 * @vsi: the VSI being configured
1958 * @rst_src: reset source
1959 * @rel_vmvf_num: Relative ID of VF/VM
1960 * @rings: Tx ring array to be stopped
1961 * @count: number of Tx ring array elements
1962 */
1963 static int
ice_vsi_stop_tx_rings(struct ice_vsi * vsi,enum ice_disq_rst_src rst_src,u16 rel_vmvf_num,struct ice_tx_ring ** rings,u16 count)1964 ice_vsi_stop_tx_rings(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
1965 u16 rel_vmvf_num, struct ice_tx_ring **rings, u16 count)
1966 {
1967 u16 q_idx;
1968
1969 if (vsi->num_txq > ICE_LAN_TXQ_MAX_QDIS)
1970 return -EINVAL;
1971
1972 for (q_idx = 0; q_idx < count; q_idx++) {
1973 struct ice_txq_meta txq_meta = { };
1974 int status;
1975
1976 if (!rings || !rings[q_idx])
1977 return -EINVAL;
1978
1979 ice_fill_txq_meta(vsi, rings[q_idx], &txq_meta);
1980 status = ice_vsi_stop_tx_ring(vsi, rst_src, rel_vmvf_num,
1981 rings[q_idx], &txq_meta);
1982
1983 if (status)
1984 return status;
1985 }
1986
1987 return 0;
1988 }
1989
1990 /**
1991 * ice_vsi_stop_lan_tx_rings - Disable LAN Tx rings
1992 * @vsi: the VSI being configured
1993 * @rst_src: reset source
1994 * @rel_vmvf_num: Relative ID of VF/VM
1995 */
1996 int
ice_vsi_stop_lan_tx_rings(struct ice_vsi * vsi,enum ice_disq_rst_src rst_src,u16 rel_vmvf_num)1997 ice_vsi_stop_lan_tx_rings(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
1998 u16 rel_vmvf_num)
1999 {
2000 return ice_vsi_stop_tx_rings(vsi, rst_src, rel_vmvf_num, vsi->tx_rings, vsi->num_txq);
2001 }
2002
2003 /**
2004 * ice_vsi_stop_xdp_tx_rings - Disable XDP Tx rings
2005 * @vsi: the VSI being configured
2006 */
ice_vsi_stop_xdp_tx_rings(struct ice_vsi * vsi)2007 int ice_vsi_stop_xdp_tx_rings(struct ice_vsi *vsi)
2008 {
2009 return ice_vsi_stop_tx_rings(vsi, ICE_NO_RESET, 0, vsi->xdp_rings, vsi->num_xdp_txq);
2010 }
2011
2012 /**
2013 * ice_vsi_is_rx_queue_active
2014 * @vsi: the VSI being configured
2015 *
2016 * Return true if at least one queue is active.
2017 */
ice_vsi_is_rx_queue_active(struct ice_vsi * vsi)2018 bool ice_vsi_is_rx_queue_active(struct ice_vsi *vsi)
2019 {
2020 struct ice_pf *pf = vsi->back;
2021 struct ice_hw *hw = &pf->hw;
2022 int i;
2023
2024 ice_for_each_rxq(vsi, i) {
2025 u32 rx_reg;
2026 int pf_q;
2027
2028 pf_q = vsi->rxq_map[i];
2029 rx_reg = rd32(hw, QRX_CTRL(pf_q));
2030 if (rx_reg & QRX_CTRL_QENA_STAT_M)
2031 return true;
2032 }
2033
2034 return false;
2035 }
2036
ice_vsi_set_tc_cfg(struct ice_vsi * vsi)2037 static void ice_vsi_set_tc_cfg(struct ice_vsi *vsi)
2038 {
2039 if (!test_bit(ICE_FLAG_DCB_ENA, vsi->back->flags)) {
2040 vsi->tc_cfg.ena_tc = ICE_DFLT_TRAFFIC_CLASS;
2041 vsi->tc_cfg.numtc = 1;
2042 return;
2043 }
2044
2045 /* set VSI TC information based on DCB config */
2046 ice_vsi_set_dcb_tc_cfg(vsi);
2047 }
2048
2049 /**
2050 * ice_cfg_sw_lldp - Config switch rules for LLDP packet handling
2051 * @vsi: the VSI being configured
2052 * @tx: bool to determine Tx or Rx rule
2053 * @create: bool to determine create or remove Rule
2054 */
ice_cfg_sw_lldp(struct ice_vsi * vsi,bool tx,bool create)2055 void ice_cfg_sw_lldp(struct ice_vsi *vsi, bool tx, bool create)
2056 {
2057 int (*eth_fltr)(struct ice_vsi *v, u16 type, u16 flag,
2058 enum ice_sw_fwd_act_type act);
2059 struct ice_pf *pf = vsi->back;
2060 struct device *dev;
2061 int status;
2062
2063 dev = ice_pf_to_dev(pf);
2064 eth_fltr = create ? ice_fltr_add_eth : ice_fltr_remove_eth;
2065
2066 if (tx) {
2067 status = eth_fltr(vsi, ETH_P_LLDP, ICE_FLTR_TX,
2068 ICE_DROP_PACKET);
2069 } else {
2070 if (ice_fw_supports_lldp_fltr_ctrl(&pf->hw)) {
2071 status = ice_lldp_fltr_add_remove(&pf->hw, vsi->vsi_num,
2072 create);
2073 } else {
2074 status = eth_fltr(vsi, ETH_P_LLDP, ICE_FLTR_RX,
2075 ICE_FWD_TO_VSI);
2076 }
2077 }
2078
2079 if (status)
2080 dev_dbg(dev, "Fail %s %s LLDP rule on VSI %i error: %d\n",
2081 create ? "adding" : "removing", tx ? "TX" : "RX",
2082 vsi->vsi_num, status);
2083 }
2084
2085 /**
2086 * ice_set_agg_vsi - sets up scheduler aggregator node and move VSI into it
2087 * @vsi: pointer to the VSI
2088 *
2089 * This function will allocate new scheduler aggregator now if needed and will
2090 * move specified VSI into it.
2091 */
ice_set_agg_vsi(struct ice_vsi * vsi)2092 static void ice_set_agg_vsi(struct ice_vsi *vsi)
2093 {
2094 struct device *dev = ice_pf_to_dev(vsi->back);
2095 struct ice_agg_node *agg_node_iter = NULL;
2096 u32 agg_id = ICE_INVALID_AGG_NODE_ID;
2097 struct ice_agg_node *agg_node = NULL;
2098 int node_offset, max_agg_nodes = 0;
2099 struct ice_port_info *port_info;
2100 struct ice_pf *pf = vsi->back;
2101 u32 agg_node_id_start = 0;
2102 int status;
2103
2104 /* create (as needed) scheduler aggregator node and move VSI into
2105 * corresponding aggregator node
2106 * - PF aggregator node to contains VSIs of type _PF and _CTRL
2107 * - VF aggregator nodes will contain VF VSI
2108 */
2109 port_info = pf->hw.port_info;
2110 if (!port_info)
2111 return;
2112
2113 switch (vsi->type) {
2114 case ICE_VSI_CTRL:
2115 case ICE_VSI_CHNL:
2116 case ICE_VSI_LB:
2117 case ICE_VSI_PF:
2118 case ICE_VSI_SF:
2119 max_agg_nodes = ICE_MAX_PF_AGG_NODES;
2120 agg_node_id_start = ICE_PF_AGG_NODE_ID_START;
2121 agg_node_iter = &pf->pf_agg_node[0];
2122 break;
2123 case ICE_VSI_VF:
2124 /* user can create 'n' VFs on a given PF, but since max children
2125 * per aggregator node can be only 64. Following code handles
2126 * aggregator(s) for VF VSIs, either selects a agg_node which
2127 * was already created provided num_vsis < 64, otherwise
2128 * select next available node, which will be created
2129 */
2130 max_agg_nodes = ICE_MAX_VF_AGG_NODES;
2131 agg_node_id_start = ICE_VF_AGG_NODE_ID_START;
2132 agg_node_iter = &pf->vf_agg_node[0];
2133 break;
2134 default:
2135 /* other VSI type, handle later if needed */
2136 dev_dbg(dev, "unexpected VSI type %s\n",
2137 ice_vsi_type_str(vsi->type));
2138 return;
2139 }
2140
2141 /* find the appropriate aggregator node */
2142 for (node_offset = 0; node_offset < max_agg_nodes; node_offset++) {
2143 /* see if we can find space in previously created
2144 * node if num_vsis < 64, otherwise skip
2145 */
2146 if (agg_node_iter->num_vsis &&
2147 agg_node_iter->num_vsis == ICE_MAX_VSIS_IN_AGG_NODE) {
2148 agg_node_iter++;
2149 continue;
2150 }
2151
2152 if (agg_node_iter->valid &&
2153 agg_node_iter->agg_id != ICE_INVALID_AGG_NODE_ID) {
2154 agg_id = agg_node_iter->agg_id;
2155 agg_node = agg_node_iter;
2156 break;
2157 }
2158
2159 /* find unclaimed agg_id */
2160 if (agg_node_iter->agg_id == ICE_INVALID_AGG_NODE_ID) {
2161 agg_id = node_offset + agg_node_id_start;
2162 agg_node = agg_node_iter;
2163 break;
2164 }
2165 /* move to next agg_node */
2166 agg_node_iter++;
2167 }
2168
2169 if (!agg_node)
2170 return;
2171
2172 /* if selected aggregator node was not created, create it */
2173 if (!agg_node->valid) {
2174 status = ice_cfg_agg(port_info, agg_id, ICE_AGG_TYPE_AGG,
2175 (u8)vsi->tc_cfg.ena_tc);
2176 if (status) {
2177 dev_err(dev, "unable to create aggregator node with agg_id %u\n",
2178 agg_id);
2179 return;
2180 }
2181 /* aggregator node is created, store the needed info */
2182 agg_node->valid = true;
2183 agg_node->agg_id = agg_id;
2184 }
2185
2186 /* move VSI to corresponding aggregator node */
2187 status = ice_move_vsi_to_agg(port_info, agg_id, vsi->idx,
2188 (u8)vsi->tc_cfg.ena_tc);
2189 if (status) {
2190 dev_err(dev, "unable to move VSI idx %u into aggregator %u node",
2191 vsi->idx, agg_id);
2192 return;
2193 }
2194
2195 /* keep active children count for aggregator node */
2196 agg_node->num_vsis++;
2197
2198 /* cache the 'agg_id' in VSI, so that after reset - VSI will be moved
2199 * to aggregator node
2200 */
2201 vsi->agg_node = agg_node;
2202 dev_dbg(dev, "successfully moved VSI idx %u tc_bitmap 0x%x) into aggregator node %d which has num_vsis %u\n",
2203 vsi->idx, vsi->tc_cfg.ena_tc, vsi->agg_node->agg_id,
2204 vsi->agg_node->num_vsis);
2205 }
2206
ice_vsi_cfg_tc_lan(struct ice_pf * pf,struct ice_vsi * vsi)2207 static int ice_vsi_cfg_tc_lan(struct ice_pf *pf, struct ice_vsi *vsi)
2208 {
2209 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2210 struct device *dev = ice_pf_to_dev(pf);
2211 int ret, i;
2212
2213 /* configure VSI nodes based on number of queues and TC's */
2214 ice_for_each_traffic_class(i) {
2215 if (!(vsi->tc_cfg.ena_tc & BIT(i)))
2216 continue;
2217
2218 if (vsi->type == ICE_VSI_CHNL) {
2219 if (!vsi->alloc_txq && vsi->num_txq)
2220 max_txqs[i] = vsi->num_txq;
2221 else
2222 max_txqs[i] = pf->num_lan_tx;
2223 } else {
2224 max_txqs[i] = vsi->alloc_txq;
2225 }
2226
2227 if (vsi->type == ICE_VSI_PF)
2228 max_txqs[i] += vsi->num_xdp_txq;
2229 }
2230
2231 dev_dbg(dev, "vsi->tc_cfg.ena_tc = %d\n", vsi->tc_cfg.ena_tc);
2232 ret = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2233 max_txqs);
2234 if (ret) {
2235 dev_err(dev, "VSI %d failed lan queue config, error %d\n",
2236 vsi->vsi_num, ret);
2237 return ret;
2238 }
2239
2240 return 0;
2241 }
2242
2243 /**
2244 * ice_vsi_cfg_def - configure default VSI based on the type
2245 * @vsi: pointer to VSI
2246 */
ice_vsi_cfg_def(struct ice_vsi * vsi)2247 static int ice_vsi_cfg_def(struct ice_vsi *vsi)
2248 {
2249 struct device *dev = ice_pf_to_dev(vsi->back);
2250 struct ice_pf *pf = vsi->back;
2251 int ret;
2252
2253 vsi->vsw = pf->first_sw;
2254
2255 ret = ice_vsi_alloc_def(vsi, vsi->ch);
2256 if (ret)
2257 return ret;
2258
2259 /* allocate memory for Tx/Rx ring stat pointers */
2260 ret = ice_vsi_alloc_stat_arrays(vsi);
2261 if (ret)
2262 goto unroll_vsi_alloc;
2263
2264 ice_alloc_fd_res(vsi);
2265
2266 ret = ice_vsi_get_qs(vsi);
2267 if (ret) {
2268 dev_err(dev, "Failed to allocate queues. vsi->idx = %d\n",
2269 vsi->idx);
2270 goto unroll_vsi_alloc_stat;
2271 }
2272
2273 /* set RSS capabilities */
2274 ice_vsi_set_rss_params(vsi);
2275
2276 /* set TC configuration */
2277 ice_vsi_set_tc_cfg(vsi);
2278
2279 /* create the VSI */
2280 ret = ice_vsi_init(vsi, vsi->flags);
2281 if (ret)
2282 goto unroll_get_qs;
2283
2284 ice_vsi_init_vlan_ops(vsi);
2285
2286 switch (vsi->type) {
2287 case ICE_VSI_CTRL:
2288 case ICE_VSI_SF:
2289 case ICE_VSI_PF:
2290 ret = ice_vsi_alloc_q_vectors(vsi);
2291 if (ret)
2292 goto unroll_vsi_init;
2293
2294 ret = ice_vsi_alloc_rings(vsi);
2295 if (ret)
2296 goto unroll_vector_base;
2297
2298 ret = ice_vsi_alloc_ring_stats(vsi);
2299 if (ret)
2300 goto unroll_vector_base;
2301
2302 if (ice_is_xdp_ena_vsi(vsi)) {
2303 ret = ice_vsi_determine_xdp_res(vsi);
2304 if (ret)
2305 goto unroll_vector_base;
2306 ret = ice_prepare_xdp_rings(vsi, vsi->xdp_prog,
2307 ICE_XDP_CFG_PART);
2308 if (ret)
2309 goto unroll_vector_base;
2310 }
2311
2312 ice_vsi_map_rings_to_vectors(vsi);
2313
2314 vsi->stat_offsets_loaded = false;
2315
2316 /* ICE_VSI_CTRL does not need RSS so skip RSS processing */
2317 if (vsi->type != ICE_VSI_CTRL)
2318 /* Do not exit if configuring RSS had an issue, at
2319 * least receive traffic on first queue. Hence no
2320 * need to capture return value
2321 */
2322 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
2323 ice_vsi_cfg_rss_lut_key(vsi);
2324 ice_vsi_set_rss_flow_fld(vsi);
2325 }
2326 ice_init_arfs(vsi);
2327 break;
2328 case ICE_VSI_CHNL:
2329 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
2330 ice_vsi_cfg_rss_lut_key(vsi);
2331 ice_vsi_set_rss_flow_fld(vsi);
2332 }
2333 break;
2334 case ICE_VSI_VF:
2335 /* VF driver will take care of creating netdev for this type and
2336 * map queues to vectors through Virtchnl, PF driver only
2337 * creates a VSI and corresponding structures for bookkeeping
2338 * purpose
2339 */
2340 ret = ice_vsi_alloc_q_vectors(vsi);
2341 if (ret)
2342 goto unroll_vsi_init;
2343
2344 ret = ice_vsi_alloc_rings(vsi);
2345 if (ret)
2346 goto unroll_alloc_q_vector;
2347
2348 ret = ice_vsi_alloc_ring_stats(vsi);
2349 if (ret)
2350 goto unroll_vector_base;
2351
2352 vsi->stat_offsets_loaded = false;
2353
2354 /* Do not exit if configuring RSS had an issue, at least
2355 * receive traffic on first queue. Hence no need to capture
2356 * return value
2357 */
2358 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
2359 ice_vsi_cfg_rss_lut_key(vsi);
2360 ice_vsi_set_vf_rss_flow_fld(vsi);
2361 }
2362 break;
2363 case ICE_VSI_LB:
2364 ret = ice_vsi_alloc_rings(vsi);
2365 if (ret)
2366 goto unroll_vsi_init;
2367
2368 ret = ice_vsi_alloc_ring_stats(vsi);
2369 if (ret)
2370 goto unroll_vector_base;
2371
2372 break;
2373 default:
2374 /* clean up the resources and exit */
2375 ret = -EINVAL;
2376 goto unroll_vsi_init;
2377 }
2378
2379 return 0;
2380
2381 unroll_vector_base:
2382 /* reclaim SW interrupts back to the common pool */
2383 unroll_alloc_q_vector:
2384 ice_vsi_free_q_vectors(vsi);
2385 unroll_vsi_init:
2386 ice_vsi_delete_from_hw(vsi);
2387 unroll_get_qs:
2388 ice_vsi_put_qs(vsi);
2389 unroll_vsi_alloc_stat:
2390 ice_vsi_free_stats(vsi);
2391 unroll_vsi_alloc:
2392 ice_vsi_free_arrays(vsi);
2393 return ret;
2394 }
2395
2396 /**
2397 * ice_vsi_cfg - configure a previously allocated VSI
2398 * @vsi: pointer to VSI
2399 */
ice_vsi_cfg(struct ice_vsi * vsi)2400 int ice_vsi_cfg(struct ice_vsi *vsi)
2401 {
2402 struct ice_pf *pf = vsi->back;
2403 int ret;
2404
2405 if (WARN_ON(vsi->type == ICE_VSI_VF && !vsi->vf))
2406 return -EINVAL;
2407
2408 ret = ice_vsi_cfg_def(vsi);
2409 if (ret)
2410 return ret;
2411
2412 ret = ice_vsi_cfg_tc_lan(vsi->back, vsi);
2413 if (ret)
2414 ice_vsi_decfg(vsi);
2415
2416 if (vsi->type == ICE_VSI_CTRL) {
2417 if (vsi->vf) {
2418 WARN_ON(vsi->vf->ctrl_vsi_idx != ICE_NO_VSI);
2419 vsi->vf->ctrl_vsi_idx = vsi->idx;
2420 } else {
2421 WARN_ON(pf->ctrl_vsi_idx != ICE_NO_VSI);
2422 pf->ctrl_vsi_idx = vsi->idx;
2423 }
2424 }
2425
2426 return ret;
2427 }
2428
2429 /**
2430 * ice_vsi_decfg - remove all VSI configuration
2431 * @vsi: pointer to VSI
2432 */
ice_vsi_decfg(struct ice_vsi * vsi)2433 void ice_vsi_decfg(struct ice_vsi *vsi)
2434 {
2435 struct ice_pf *pf = vsi->back;
2436 int err;
2437
2438 ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx);
2439 err = ice_rm_vsi_rdma_cfg(vsi->port_info, vsi->idx);
2440 if (err)
2441 dev_err(ice_pf_to_dev(pf), "Failed to remove RDMA scheduler config for VSI %u, err %d\n",
2442 vsi->vsi_num, err);
2443
2444 if (vsi->xdp_rings)
2445 /* return value check can be skipped here, it always returns
2446 * 0 if reset is in progress
2447 */
2448 ice_destroy_xdp_rings(vsi, ICE_XDP_CFG_PART);
2449
2450 ice_vsi_clear_rings(vsi);
2451 ice_vsi_free_q_vectors(vsi);
2452 ice_vsi_put_qs(vsi);
2453 ice_vsi_free_arrays(vsi);
2454
2455 /* SR-IOV determines needed MSIX resources all at once instead of per
2456 * VSI since when VFs are spawned we know how many VFs there are and how
2457 * many interrupts each VF needs. SR-IOV MSIX resources are also
2458 * cleared in the same manner.
2459 */
2460
2461 if (vsi->type == ICE_VSI_VF &&
2462 vsi->agg_node && vsi->agg_node->valid)
2463 vsi->agg_node->num_vsis--;
2464 }
2465
2466 /**
2467 * ice_vsi_setup - Set up a VSI by a given type
2468 * @pf: board private structure
2469 * @params: parameters to use when creating the VSI
2470 *
2471 * This allocates the sw VSI structure and its queue resources.
2472 *
2473 * Returns pointer to the successfully allocated and configured VSI sw struct on
2474 * success, NULL on failure.
2475 */
2476 struct ice_vsi *
ice_vsi_setup(struct ice_pf * pf,struct ice_vsi_cfg_params * params)2477 ice_vsi_setup(struct ice_pf *pf, struct ice_vsi_cfg_params *params)
2478 {
2479 struct device *dev = ice_pf_to_dev(pf);
2480 struct ice_vsi *vsi;
2481 int ret;
2482
2483 /* ice_vsi_setup can only initialize a new VSI, and we must have
2484 * a port_info structure for it.
2485 */
2486 if (WARN_ON(!(params->flags & ICE_VSI_FLAG_INIT)) ||
2487 WARN_ON(!params->port_info))
2488 return NULL;
2489
2490 vsi = ice_vsi_alloc(pf);
2491 if (!vsi) {
2492 dev_err(dev, "could not allocate VSI\n");
2493 return NULL;
2494 }
2495
2496 vsi->params = *params;
2497 ret = ice_vsi_cfg(vsi);
2498 if (ret)
2499 goto err_vsi_cfg;
2500
2501 /* Add switch rule to drop all Tx Flow Control Frames, of look up
2502 * type ETHERTYPE from VSIs, and restrict malicious VF from sending
2503 * out PAUSE or PFC frames. If enabled, FW can still send FC frames.
2504 * The rule is added once for PF VSI in order to create appropriate
2505 * recipe, since VSI/VSI list is ignored with drop action...
2506 * Also add rules to handle LLDP Tx packets. Tx LLDP packets need to
2507 * be dropped so that VFs cannot send LLDP packets to reconfig DCB
2508 * settings in the HW.
2509 */
2510 if (!ice_is_safe_mode(pf) && vsi->type == ICE_VSI_PF) {
2511 ice_fltr_add_eth(vsi, ETH_P_PAUSE, ICE_FLTR_TX,
2512 ICE_DROP_PACKET);
2513 ice_cfg_sw_lldp(vsi, true, true);
2514 }
2515
2516 if (!vsi->agg_node)
2517 ice_set_agg_vsi(vsi);
2518
2519 return vsi;
2520
2521 err_vsi_cfg:
2522 ice_vsi_free(vsi);
2523
2524 return NULL;
2525 }
2526
2527 /**
2528 * ice_vsi_release_msix - Clear the queue to Interrupt mapping in HW
2529 * @vsi: the VSI being cleaned up
2530 */
ice_vsi_release_msix(struct ice_vsi * vsi)2531 static void ice_vsi_release_msix(struct ice_vsi *vsi)
2532 {
2533 struct ice_pf *pf = vsi->back;
2534 struct ice_hw *hw = &pf->hw;
2535 u32 txq = 0;
2536 u32 rxq = 0;
2537 int i, q;
2538
2539 ice_for_each_q_vector(vsi, i) {
2540 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2541
2542 ice_write_intrl(q_vector, 0);
2543 for (q = 0; q < q_vector->num_ring_tx; q++) {
2544 ice_write_itr(&q_vector->tx, 0);
2545 wr32(hw, QINT_TQCTL(vsi->txq_map[txq]), 0);
2546 if (vsi->xdp_rings) {
2547 u32 xdp_txq = txq + vsi->num_xdp_txq;
2548
2549 wr32(hw, QINT_TQCTL(vsi->txq_map[xdp_txq]), 0);
2550 }
2551 txq++;
2552 }
2553
2554 for (q = 0; q < q_vector->num_ring_rx; q++) {
2555 ice_write_itr(&q_vector->rx, 0);
2556 wr32(hw, QINT_RQCTL(vsi->rxq_map[rxq]), 0);
2557 rxq++;
2558 }
2559 }
2560
2561 ice_flush(hw);
2562 }
2563
2564 /**
2565 * ice_vsi_free_irq - Free the IRQ association with the OS
2566 * @vsi: the VSI being configured
2567 */
ice_vsi_free_irq(struct ice_vsi * vsi)2568 void ice_vsi_free_irq(struct ice_vsi *vsi)
2569 {
2570 struct ice_pf *pf = vsi->back;
2571 int i;
2572
2573 if (!vsi->q_vectors || !vsi->irqs_ready)
2574 return;
2575
2576 ice_vsi_release_msix(vsi);
2577 if (vsi->type == ICE_VSI_VF)
2578 return;
2579
2580 vsi->irqs_ready = false;
2581 ice_free_cpu_rx_rmap(vsi);
2582
2583 ice_for_each_q_vector(vsi, i) {
2584 int irq_num;
2585
2586 irq_num = vsi->q_vectors[i]->irq.virq;
2587
2588 /* free only the irqs that were actually requested */
2589 if (!vsi->q_vectors[i] ||
2590 !(vsi->q_vectors[i]->num_ring_tx ||
2591 vsi->q_vectors[i]->num_ring_rx))
2592 continue;
2593
2594 /* clear the affinity notifier in the IRQ descriptor */
2595 if (!IS_ENABLED(CONFIG_RFS_ACCEL))
2596 irq_set_affinity_notifier(irq_num, NULL);
2597
2598 /* clear the affinity_hint in the IRQ descriptor */
2599 irq_update_affinity_hint(irq_num, NULL);
2600 synchronize_irq(irq_num);
2601 devm_free_irq(ice_pf_to_dev(pf), irq_num, vsi->q_vectors[i]);
2602 }
2603 }
2604
2605 /**
2606 * ice_vsi_free_tx_rings - Free Tx resources for VSI queues
2607 * @vsi: the VSI having resources freed
2608 */
ice_vsi_free_tx_rings(struct ice_vsi * vsi)2609 void ice_vsi_free_tx_rings(struct ice_vsi *vsi)
2610 {
2611 int i;
2612
2613 if (!vsi->tx_rings)
2614 return;
2615
2616 ice_for_each_txq(vsi, i)
2617 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
2618 ice_free_tx_ring(vsi->tx_rings[i]);
2619 }
2620
2621 /**
2622 * ice_vsi_free_rx_rings - Free Rx resources for VSI queues
2623 * @vsi: the VSI having resources freed
2624 */
ice_vsi_free_rx_rings(struct ice_vsi * vsi)2625 void ice_vsi_free_rx_rings(struct ice_vsi *vsi)
2626 {
2627 int i;
2628
2629 if (!vsi->rx_rings)
2630 return;
2631
2632 ice_for_each_rxq(vsi, i)
2633 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
2634 ice_free_rx_ring(vsi->rx_rings[i]);
2635 }
2636
2637 /**
2638 * ice_vsi_close - Shut down a VSI
2639 * @vsi: the VSI being shut down
2640 */
ice_vsi_close(struct ice_vsi * vsi)2641 void ice_vsi_close(struct ice_vsi *vsi)
2642 {
2643 if (!test_and_set_bit(ICE_VSI_DOWN, vsi->state))
2644 ice_down(vsi);
2645
2646 ice_vsi_clear_napi_queues(vsi);
2647 ice_vsi_free_irq(vsi);
2648 ice_vsi_free_tx_rings(vsi);
2649 ice_vsi_free_rx_rings(vsi);
2650 }
2651
2652 /**
2653 * ice_ena_vsi - resume a VSI
2654 * @vsi: the VSI being resume
2655 * @locked: is the rtnl_lock already held
2656 */
ice_ena_vsi(struct ice_vsi * vsi,bool locked)2657 int ice_ena_vsi(struct ice_vsi *vsi, bool locked)
2658 {
2659 int err = 0;
2660
2661 if (!test_bit(ICE_VSI_NEEDS_RESTART, vsi->state))
2662 return 0;
2663
2664 clear_bit(ICE_VSI_NEEDS_RESTART, vsi->state);
2665
2666 if (vsi->netdev && (vsi->type == ICE_VSI_PF ||
2667 vsi->type == ICE_VSI_SF)) {
2668 if (netif_running(vsi->netdev)) {
2669 if (!locked)
2670 rtnl_lock();
2671
2672 err = ice_open_internal(vsi->netdev);
2673
2674 if (!locked)
2675 rtnl_unlock();
2676 }
2677 } else if (vsi->type == ICE_VSI_CTRL) {
2678 err = ice_vsi_open_ctrl(vsi);
2679 }
2680
2681 return err;
2682 }
2683
2684 /**
2685 * ice_dis_vsi - pause a VSI
2686 * @vsi: the VSI being paused
2687 * @locked: is the rtnl_lock already held
2688 */
ice_dis_vsi(struct ice_vsi * vsi,bool locked)2689 void ice_dis_vsi(struct ice_vsi *vsi, bool locked)
2690 {
2691 bool already_down = test_bit(ICE_VSI_DOWN, vsi->state);
2692
2693 set_bit(ICE_VSI_NEEDS_RESTART, vsi->state);
2694
2695 if (vsi->netdev && (vsi->type == ICE_VSI_PF ||
2696 vsi->type == ICE_VSI_SF)) {
2697 if (netif_running(vsi->netdev)) {
2698 if (!locked)
2699 rtnl_lock();
2700 already_down = test_bit(ICE_VSI_DOWN, vsi->state);
2701 if (!already_down)
2702 ice_vsi_close(vsi);
2703
2704 if (!locked)
2705 rtnl_unlock();
2706 } else if (!already_down) {
2707 ice_vsi_close(vsi);
2708 }
2709 } else if (vsi->type == ICE_VSI_CTRL && !already_down) {
2710 ice_vsi_close(vsi);
2711 }
2712 }
2713
2714 /**
2715 * ice_vsi_set_napi_queues - associate netdev queues with napi
2716 * @vsi: VSI pointer
2717 *
2718 * Associate queue[s] with napi for all vectors.
2719 * The caller must hold rtnl_lock.
2720 */
ice_vsi_set_napi_queues(struct ice_vsi * vsi)2721 void ice_vsi_set_napi_queues(struct ice_vsi *vsi)
2722 {
2723 struct net_device *netdev = vsi->netdev;
2724 int q_idx, v_idx;
2725
2726 if (!netdev)
2727 return;
2728
2729 ice_for_each_rxq(vsi, q_idx)
2730 netif_queue_set_napi(netdev, q_idx, NETDEV_QUEUE_TYPE_RX,
2731 &vsi->rx_rings[q_idx]->q_vector->napi);
2732
2733 ice_for_each_txq(vsi, q_idx)
2734 netif_queue_set_napi(netdev, q_idx, NETDEV_QUEUE_TYPE_TX,
2735 &vsi->tx_rings[q_idx]->q_vector->napi);
2736 /* Also set the interrupt number for the NAPI */
2737 ice_for_each_q_vector(vsi, v_idx) {
2738 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
2739
2740 netif_napi_set_irq(&q_vector->napi, q_vector->irq.virq);
2741 }
2742 }
2743
2744 /**
2745 * ice_vsi_clear_napi_queues - dissociate netdev queues from napi
2746 * @vsi: VSI pointer
2747 *
2748 * Clear the association between all VSI queues queue[s] and napi.
2749 * The caller must hold rtnl_lock.
2750 */
ice_vsi_clear_napi_queues(struct ice_vsi * vsi)2751 void ice_vsi_clear_napi_queues(struct ice_vsi *vsi)
2752 {
2753 struct net_device *netdev = vsi->netdev;
2754 int q_idx;
2755
2756 if (!netdev)
2757 return;
2758
2759 ice_for_each_txq(vsi, q_idx)
2760 netif_queue_set_napi(netdev, q_idx, NETDEV_QUEUE_TYPE_TX, NULL);
2761
2762 ice_for_each_rxq(vsi, q_idx)
2763 netif_queue_set_napi(netdev, q_idx, NETDEV_QUEUE_TYPE_RX, NULL);
2764 }
2765
2766 /**
2767 * ice_napi_add - register NAPI handler for the VSI
2768 * @vsi: VSI for which NAPI handler is to be registered
2769 *
2770 * This function is only called in the driver's load path. Registering the NAPI
2771 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
2772 * reset/rebuild, etc.)
2773 */
ice_napi_add(struct ice_vsi * vsi)2774 void ice_napi_add(struct ice_vsi *vsi)
2775 {
2776 int v_idx;
2777
2778 if (!vsi->netdev)
2779 return;
2780
2781 ice_for_each_q_vector(vsi, v_idx)
2782 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
2783 ice_napi_poll);
2784 }
2785
2786 /**
2787 * ice_vsi_release - Delete a VSI and free its resources
2788 * @vsi: the VSI being removed
2789 *
2790 * Returns 0 on success or < 0 on error
2791 */
ice_vsi_release(struct ice_vsi * vsi)2792 int ice_vsi_release(struct ice_vsi *vsi)
2793 {
2794 struct ice_pf *pf;
2795
2796 if (!vsi->back)
2797 return -ENODEV;
2798 pf = vsi->back;
2799
2800 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2801 ice_rss_clean(vsi);
2802
2803 ice_vsi_close(vsi);
2804
2805 /* The Rx rule will only exist to remove if the LLDP FW
2806 * engine is currently stopped
2807 */
2808 if (!ice_is_safe_mode(pf) && vsi->type == ICE_VSI_PF &&
2809 !test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags))
2810 ice_cfg_sw_lldp(vsi, false, false);
2811
2812 ice_vsi_decfg(vsi);
2813
2814 /* retain SW VSI data structure since it is needed to unregister and
2815 * free VSI netdev when PF is not in reset recovery pending state,\
2816 * for ex: during rmmod.
2817 */
2818 if (!ice_is_reset_in_progress(pf->state))
2819 ice_vsi_delete(vsi);
2820
2821 return 0;
2822 }
2823
2824 /**
2825 * ice_vsi_rebuild_get_coalesce - get coalesce from all q_vectors
2826 * @vsi: VSI connected with q_vectors
2827 * @coalesce: array of struct with stored coalesce
2828 *
2829 * Returns array size.
2830 */
2831 static int
ice_vsi_rebuild_get_coalesce(struct ice_vsi * vsi,struct ice_coalesce_stored * coalesce)2832 ice_vsi_rebuild_get_coalesce(struct ice_vsi *vsi,
2833 struct ice_coalesce_stored *coalesce)
2834 {
2835 int i;
2836
2837 ice_for_each_q_vector(vsi, i) {
2838 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2839
2840 coalesce[i].itr_tx = q_vector->tx.itr_settings;
2841 coalesce[i].itr_rx = q_vector->rx.itr_settings;
2842 coalesce[i].intrl = q_vector->intrl;
2843
2844 if (i < vsi->num_txq)
2845 coalesce[i].tx_valid = true;
2846 if (i < vsi->num_rxq)
2847 coalesce[i].rx_valid = true;
2848 }
2849
2850 return vsi->num_q_vectors;
2851 }
2852
2853 /**
2854 * ice_vsi_rebuild_set_coalesce - set coalesce from earlier saved arrays
2855 * @vsi: VSI connected with q_vectors
2856 * @coalesce: pointer to array of struct with stored coalesce
2857 * @size: size of coalesce array
2858 *
2859 * Before this function, ice_vsi_rebuild_get_coalesce should be called to save
2860 * ITR params in arrays. If size is 0 or coalesce wasn't stored set coalesce
2861 * to default value.
2862 */
2863 static void
ice_vsi_rebuild_set_coalesce(struct ice_vsi * vsi,struct ice_coalesce_stored * coalesce,int size)2864 ice_vsi_rebuild_set_coalesce(struct ice_vsi *vsi,
2865 struct ice_coalesce_stored *coalesce, int size)
2866 {
2867 struct ice_ring_container *rc;
2868 int i;
2869
2870 if ((size && !coalesce) || !vsi)
2871 return;
2872
2873 /* There are a couple of cases that have to be handled here:
2874 * 1. The case where the number of queue vectors stays the same, but
2875 * the number of Tx or Rx rings changes (the first for loop)
2876 * 2. The case where the number of queue vectors increased (the
2877 * second for loop)
2878 */
2879 for (i = 0; i < size && i < vsi->num_q_vectors; i++) {
2880 /* There are 2 cases to handle here and they are the same for
2881 * both Tx and Rx:
2882 * if the entry was valid previously (coalesce[i].[tr]x_valid
2883 * and the loop variable is less than the number of rings
2884 * allocated, then write the previous values
2885 *
2886 * if the entry was not valid previously, but the number of
2887 * rings is less than are allocated (this means the number of
2888 * rings increased from previously), then write out the
2889 * values in the first element
2890 *
2891 * Also, always write the ITR, even if in ITR_IS_DYNAMIC
2892 * as there is no harm because the dynamic algorithm
2893 * will just overwrite.
2894 */
2895 if (i < vsi->alloc_rxq && coalesce[i].rx_valid) {
2896 rc = &vsi->q_vectors[i]->rx;
2897 rc->itr_settings = coalesce[i].itr_rx;
2898 ice_write_itr(rc, rc->itr_setting);
2899 } else if (i < vsi->alloc_rxq) {
2900 rc = &vsi->q_vectors[i]->rx;
2901 rc->itr_settings = coalesce[0].itr_rx;
2902 ice_write_itr(rc, rc->itr_setting);
2903 }
2904
2905 if (i < vsi->alloc_txq && coalesce[i].tx_valid) {
2906 rc = &vsi->q_vectors[i]->tx;
2907 rc->itr_settings = coalesce[i].itr_tx;
2908 ice_write_itr(rc, rc->itr_setting);
2909 } else if (i < vsi->alloc_txq) {
2910 rc = &vsi->q_vectors[i]->tx;
2911 rc->itr_settings = coalesce[0].itr_tx;
2912 ice_write_itr(rc, rc->itr_setting);
2913 }
2914
2915 vsi->q_vectors[i]->intrl = coalesce[i].intrl;
2916 ice_set_q_vector_intrl(vsi->q_vectors[i]);
2917 }
2918
2919 /* the number of queue vectors increased so write whatever is in
2920 * the first element
2921 */
2922 for (; i < vsi->num_q_vectors; i++) {
2923 /* transmit */
2924 rc = &vsi->q_vectors[i]->tx;
2925 rc->itr_settings = coalesce[0].itr_tx;
2926 ice_write_itr(rc, rc->itr_setting);
2927
2928 /* receive */
2929 rc = &vsi->q_vectors[i]->rx;
2930 rc->itr_settings = coalesce[0].itr_rx;
2931 ice_write_itr(rc, rc->itr_setting);
2932
2933 vsi->q_vectors[i]->intrl = coalesce[0].intrl;
2934 ice_set_q_vector_intrl(vsi->q_vectors[i]);
2935 }
2936 }
2937
2938 /**
2939 * ice_vsi_realloc_stat_arrays - Frees unused stat structures or alloc new ones
2940 * @vsi: VSI pointer
2941 */
2942 static int
ice_vsi_realloc_stat_arrays(struct ice_vsi * vsi)2943 ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi)
2944 {
2945 u16 req_txq = vsi->req_txq ? vsi->req_txq : vsi->alloc_txq;
2946 u16 req_rxq = vsi->req_rxq ? vsi->req_rxq : vsi->alloc_rxq;
2947 struct ice_ring_stats **tx_ring_stats;
2948 struct ice_ring_stats **rx_ring_stats;
2949 struct ice_vsi_stats *vsi_stat;
2950 struct ice_pf *pf = vsi->back;
2951 u16 prev_txq = vsi->alloc_txq;
2952 u16 prev_rxq = vsi->alloc_rxq;
2953 int i;
2954
2955 vsi_stat = pf->vsi_stats[vsi->idx];
2956
2957 if (req_txq < prev_txq) {
2958 for (i = req_txq; i < prev_txq; i++) {
2959 if (vsi_stat->tx_ring_stats[i]) {
2960 kfree_rcu(vsi_stat->tx_ring_stats[i], rcu);
2961 WRITE_ONCE(vsi_stat->tx_ring_stats[i], NULL);
2962 }
2963 }
2964 }
2965
2966 tx_ring_stats = vsi_stat->tx_ring_stats;
2967 vsi_stat->tx_ring_stats =
2968 krealloc_array(vsi_stat->tx_ring_stats, req_txq,
2969 sizeof(*vsi_stat->tx_ring_stats),
2970 GFP_KERNEL | __GFP_ZERO);
2971 if (!vsi_stat->tx_ring_stats) {
2972 vsi_stat->tx_ring_stats = tx_ring_stats;
2973 return -ENOMEM;
2974 }
2975
2976 if (req_rxq < prev_rxq) {
2977 for (i = req_rxq; i < prev_rxq; i++) {
2978 if (vsi_stat->rx_ring_stats[i]) {
2979 kfree_rcu(vsi_stat->rx_ring_stats[i], rcu);
2980 WRITE_ONCE(vsi_stat->rx_ring_stats[i], NULL);
2981 }
2982 }
2983 }
2984
2985 rx_ring_stats = vsi_stat->rx_ring_stats;
2986 vsi_stat->rx_ring_stats =
2987 krealloc_array(vsi_stat->rx_ring_stats, req_rxq,
2988 sizeof(*vsi_stat->rx_ring_stats),
2989 GFP_KERNEL | __GFP_ZERO);
2990 if (!vsi_stat->rx_ring_stats) {
2991 vsi_stat->rx_ring_stats = rx_ring_stats;
2992 return -ENOMEM;
2993 }
2994
2995 return 0;
2996 }
2997
2998 /**
2999 * ice_vsi_rebuild - Rebuild VSI after reset
3000 * @vsi: VSI to be rebuild
3001 * @vsi_flags: flags used for VSI rebuild flow
3002 *
3003 * Set vsi_flags to ICE_VSI_FLAG_INIT to initialize a new VSI, or
3004 * ICE_VSI_FLAG_NO_INIT to rebuild an existing VSI in hardware.
3005 *
3006 * Returns 0 on success and negative value on failure
3007 */
ice_vsi_rebuild(struct ice_vsi * vsi,u32 vsi_flags)3008 int ice_vsi_rebuild(struct ice_vsi *vsi, u32 vsi_flags)
3009 {
3010 struct ice_coalesce_stored *coalesce;
3011 int prev_num_q_vectors;
3012 struct ice_pf *pf;
3013 int ret;
3014
3015 if (!vsi)
3016 return -EINVAL;
3017
3018 vsi->flags = vsi_flags;
3019 pf = vsi->back;
3020 if (WARN_ON(vsi->type == ICE_VSI_VF && !vsi->vf))
3021 return -EINVAL;
3022
3023 mutex_lock(&vsi->xdp_state_lock);
3024
3025 ret = ice_vsi_realloc_stat_arrays(vsi);
3026 if (ret)
3027 goto unlock;
3028
3029 ice_vsi_decfg(vsi);
3030 ret = ice_vsi_cfg_def(vsi);
3031 if (ret)
3032 goto unlock;
3033
3034 coalesce = kcalloc(vsi->num_q_vectors,
3035 sizeof(struct ice_coalesce_stored), GFP_KERNEL);
3036 if (!coalesce) {
3037 ret = -ENOMEM;
3038 goto decfg;
3039 }
3040
3041 prev_num_q_vectors = ice_vsi_rebuild_get_coalesce(vsi, coalesce);
3042
3043 ret = ice_vsi_cfg_tc_lan(pf, vsi);
3044 if (ret) {
3045 if (vsi_flags & ICE_VSI_FLAG_INIT) {
3046 ret = -EIO;
3047 goto free_coalesce;
3048 }
3049
3050 ret = ice_schedule_reset(pf, ICE_RESET_PFR);
3051 goto free_coalesce;
3052 }
3053
3054 ice_vsi_rebuild_set_coalesce(vsi, coalesce, prev_num_q_vectors);
3055 clear_bit(ICE_VSI_REBUILD_PENDING, vsi->state);
3056
3057 free_coalesce:
3058 kfree(coalesce);
3059 decfg:
3060 if (ret)
3061 ice_vsi_decfg(vsi);
3062 unlock:
3063 mutex_unlock(&vsi->xdp_state_lock);
3064 return ret;
3065 }
3066
3067 /**
3068 * ice_is_reset_in_progress - check for a reset in progress
3069 * @state: PF state field
3070 */
ice_is_reset_in_progress(unsigned long * state)3071 bool ice_is_reset_in_progress(unsigned long *state)
3072 {
3073 return test_bit(ICE_RESET_OICR_RECV, state) ||
3074 test_bit(ICE_PFR_REQ, state) ||
3075 test_bit(ICE_CORER_REQ, state) ||
3076 test_bit(ICE_GLOBR_REQ, state);
3077 }
3078
3079 /**
3080 * ice_wait_for_reset - Wait for driver to finish reset and rebuild
3081 * @pf: pointer to the PF structure
3082 * @timeout: length of time to wait, in jiffies
3083 *
3084 * Wait (sleep) for a short time until the driver finishes cleaning up from
3085 * a device reset. The caller must be able to sleep. Use this to delay
3086 * operations that could fail while the driver is cleaning up after a device
3087 * reset.
3088 *
3089 * Returns 0 on success, -EBUSY if the reset is not finished within the
3090 * timeout, and -ERESTARTSYS if the thread was interrupted.
3091 */
ice_wait_for_reset(struct ice_pf * pf,unsigned long timeout)3092 int ice_wait_for_reset(struct ice_pf *pf, unsigned long timeout)
3093 {
3094 long ret;
3095
3096 ret = wait_event_interruptible_timeout(pf->reset_wait_queue,
3097 !ice_is_reset_in_progress(pf->state),
3098 timeout);
3099 if (ret < 0)
3100 return ret;
3101 else if (!ret)
3102 return -EBUSY;
3103 else
3104 return 0;
3105 }
3106
3107 /**
3108 * ice_vsi_update_q_map - update our copy of the VSI info with new queue map
3109 * @vsi: VSI being configured
3110 * @ctx: the context buffer returned from AQ VSI update command
3111 */
ice_vsi_update_q_map(struct ice_vsi * vsi,struct ice_vsi_ctx * ctx)3112 static void ice_vsi_update_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctx)
3113 {
3114 vsi->info.mapping_flags = ctx->info.mapping_flags;
3115 memcpy(&vsi->info.q_mapping, &ctx->info.q_mapping,
3116 sizeof(vsi->info.q_mapping));
3117 memcpy(&vsi->info.tc_mapping, ctx->info.tc_mapping,
3118 sizeof(vsi->info.tc_mapping));
3119 }
3120
3121 /**
3122 * ice_vsi_cfg_netdev_tc - Setup the netdev TC configuration
3123 * @vsi: the VSI being configured
3124 * @ena_tc: TC map to be enabled
3125 */
ice_vsi_cfg_netdev_tc(struct ice_vsi * vsi,u8 ena_tc)3126 void ice_vsi_cfg_netdev_tc(struct ice_vsi *vsi, u8 ena_tc)
3127 {
3128 struct net_device *netdev = vsi->netdev;
3129 struct ice_pf *pf = vsi->back;
3130 int numtc = vsi->tc_cfg.numtc;
3131 struct ice_dcbx_cfg *dcbcfg;
3132 u8 netdev_tc;
3133 int i;
3134
3135 if (!netdev)
3136 return;
3137
3138 /* CHNL VSI doesn't have it's own netdev, hence, no netdev_tc */
3139 if (vsi->type == ICE_VSI_CHNL)
3140 return;
3141
3142 if (!ena_tc) {
3143 netdev_reset_tc(netdev);
3144 return;
3145 }
3146
3147 if (vsi->type == ICE_VSI_PF && ice_is_adq_active(pf))
3148 numtc = vsi->all_numtc;
3149
3150 if (netdev_set_num_tc(netdev, numtc))
3151 return;
3152
3153 dcbcfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg;
3154
3155 ice_for_each_traffic_class(i)
3156 if (vsi->tc_cfg.ena_tc & BIT(i))
3157 netdev_set_tc_queue(netdev,
3158 vsi->tc_cfg.tc_info[i].netdev_tc,
3159 vsi->tc_cfg.tc_info[i].qcount_tx,
3160 vsi->tc_cfg.tc_info[i].qoffset);
3161 /* setup TC queue map for CHNL TCs */
3162 ice_for_each_chnl_tc(i) {
3163 if (!(vsi->all_enatc & BIT(i)))
3164 break;
3165 if (!vsi->mqprio_qopt.qopt.count[i])
3166 break;
3167 netdev_set_tc_queue(netdev, i,
3168 vsi->mqprio_qopt.qopt.count[i],
3169 vsi->mqprio_qopt.qopt.offset[i]);
3170 }
3171
3172 if (test_bit(ICE_FLAG_TC_MQPRIO, pf->flags))
3173 return;
3174
3175 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
3176 u8 ets_tc = dcbcfg->etscfg.prio_table[i];
3177
3178 /* Get the mapped netdev TC# for the UP */
3179 netdev_tc = vsi->tc_cfg.tc_info[ets_tc].netdev_tc;
3180 netdev_set_prio_tc_map(netdev, i, netdev_tc);
3181 }
3182 }
3183
3184 /**
3185 * ice_vsi_setup_q_map_mqprio - Prepares mqprio based tc_config
3186 * @vsi: the VSI being configured,
3187 * @ctxt: VSI context structure
3188 * @ena_tc: number of traffic classes to enable
3189 *
3190 * Prepares VSI tc_config to have queue configurations based on MQPRIO options.
3191 */
3192 static int
ice_vsi_setup_q_map_mqprio(struct ice_vsi * vsi,struct ice_vsi_ctx * ctxt,u8 ena_tc)3193 ice_vsi_setup_q_map_mqprio(struct ice_vsi *vsi, struct ice_vsi_ctx *ctxt,
3194 u8 ena_tc)
3195 {
3196 u16 pow, offset = 0, qcount_tx = 0, qcount_rx = 0, qmap;
3197 u16 tc0_offset = vsi->mqprio_qopt.qopt.offset[0];
3198 int tc0_qcount = vsi->mqprio_qopt.qopt.count[0];
3199 u16 new_txq, new_rxq;
3200 u8 netdev_tc = 0;
3201 int i;
3202
3203 vsi->tc_cfg.ena_tc = ena_tc ? ena_tc : 1;
3204
3205 pow = order_base_2(tc0_qcount);
3206 qmap = FIELD_PREP(ICE_AQ_VSI_TC_Q_OFFSET_M, tc0_offset);
3207 qmap |= FIELD_PREP(ICE_AQ_VSI_TC_Q_NUM_M, pow);
3208
3209 ice_for_each_traffic_class(i) {
3210 if (!(vsi->tc_cfg.ena_tc & BIT(i))) {
3211 /* TC is not enabled */
3212 vsi->tc_cfg.tc_info[i].qoffset = 0;
3213 vsi->tc_cfg.tc_info[i].qcount_rx = 1;
3214 vsi->tc_cfg.tc_info[i].qcount_tx = 1;
3215 vsi->tc_cfg.tc_info[i].netdev_tc = 0;
3216 ctxt->info.tc_mapping[i] = 0;
3217 continue;
3218 }
3219
3220 offset = vsi->mqprio_qopt.qopt.offset[i];
3221 qcount_rx = vsi->mqprio_qopt.qopt.count[i];
3222 qcount_tx = vsi->mqprio_qopt.qopt.count[i];
3223 vsi->tc_cfg.tc_info[i].qoffset = offset;
3224 vsi->tc_cfg.tc_info[i].qcount_rx = qcount_rx;
3225 vsi->tc_cfg.tc_info[i].qcount_tx = qcount_tx;
3226 vsi->tc_cfg.tc_info[i].netdev_tc = netdev_tc++;
3227 }
3228
3229 if (vsi->all_numtc && vsi->all_numtc != vsi->tc_cfg.numtc) {
3230 ice_for_each_chnl_tc(i) {
3231 if (!(vsi->all_enatc & BIT(i)))
3232 continue;
3233 offset = vsi->mqprio_qopt.qopt.offset[i];
3234 qcount_rx = vsi->mqprio_qopt.qopt.count[i];
3235 qcount_tx = vsi->mqprio_qopt.qopt.count[i];
3236 }
3237 }
3238
3239 new_txq = offset + qcount_tx;
3240 if (new_txq > vsi->alloc_txq) {
3241 dev_err(ice_pf_to_dev(vsi->back), "Trying to use more Tx queues (%u), than were allocated (%u)!\n",
3242 new_txq, vsi->alloc_txq);
3243 return -EINVAL;
3244 }
3245
3246 new_rxq = offset + qcount_rx;
3247 if (new_rxq > vsi->alloc_rxq) {
3248 dev_err(ice_pf_to_dev(vsi->back), "Trying to use more Rx queues (%u), than were allocated (%u)!\n",
3249 new_rxq, vsi->alloc_rxq);
3250 return -EINVAL;
3251 }
3252
3253 /* Set actual Tx/Rx queue pairs */
3254 vsi->num_txq = new_txq;
3255 vsi->num_rxq = new_rxq;
3256
3257 /* Setup queue TC[0].qmap for given VSI context */
3258 ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
3259 ctxt->info.q_mapping[0] = cpu_to_le16(vsi->rxq_map[0]);
3260 ctxt->info.q_mapping[1] = cpu_to_le16(tc0_qcount);
3261
3262 /* Find queue count available for channel VSIs and starting offset
3263 * for channel VSIs
3264 */
3265 if (tc0_qcount && tc0_qcount < vsi->num_rxq) {
3266 vsi->cnt_q_avail = vsi->num_rxq - tc0_qcount;
3267 vsi->next_base_q = tc0_qcount;
3268 }
3269 dev_dbg(ice_pf_to_dev(vsi->back), "vsi->num_txq = %d\n", vsi->num_txq);
3270 dev_dbg(ice_pf_to_dev(vsi->back), "vsi->num_rxq = %d\n", vsi->num_rxq);
3271 dev_dbg(ice_pf_to_dev(vsi->back), "all_numtc %u, all_enatc: 0x%04x, tc_cfg.numtc %u\n",
3272 vsi->all_numtc, vsi->all_enatc, vsi->tc_cfg.numtc);
3273
3274 return 0;
3275 }
3276
3277 /**
3278 * ice_vsi_cfg_tc - Configure VSI Tx Sched for given TC map
3279 * @vsi: VSI to be configured
3280 * @ena_tc: TC bitmap
3281 *
3282 * VSI queues expected to be quiesced before calling this function
3283 */
ice_vsi_cfg_tc(struct ice_vsi * vsi,u8 ena_tc)3284 int ice_vsi_cfg_tc(struct ice_vsi *vsi, u8 ena_tc)
3285 {
3286 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
3287 struct ice_pf *pf = vsi->back;
3288 struct ice_tc_cfg old_tc_cfg;
3289 struct ice_vsi_ctx *ctx;
3290 struct device *dev;
3291 int i, ret = 0;
3292 u8 num_tc = 0;
3293
3294 dev = ice_pf_to_dev(pf);
3295 if (vsi->tc_cfg.ena_tc == ena_tc &&
3296 vsi->mqprio_qopt.mode != TC_MQPRIO_MODE_CHANNEL)
3297 return 0;
3298
3299 ice_for_each_traffic_class(i) {
3300 /* build bitmap of enabled TCs */
3301 if (ena_tc & BIT(i))
3302 num_tc++;
3303 /* populate max_txqs per TC */
3304 max_txqs[i] = vsi->alloc_txq;
3305 /* Update max_txqs if it is CHNL VSI, because alloc_t[r]xq are
3306 * zero for CHNL VSI, hence use num_txq instead as max_txqs
3307 */
3308 if (vsi->type == ICE_VSI_CHNL &&
3309 test_bit(ICE_FLAG_TC_MQPRIO, pf->flags))
3310 max_txqs[i] = vsi->num_txq;
3311 }
3312
3313 memcpy(&old_tc_cfg, &vsi->tc_cfg, sizeof(old_tc_cfg));
3314 vsi->tc_cfg.ena_tc = ena_tc;
3315 vsi->tc_cfg.numtc = num_tc;
3316
3317 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
3318 if (!ctx)
3319 return -ENOMEM;
3320
3321 ctx->vf_num = 0;
3322 ctx->info = vsi->info;
3323
3324 if (vsi->type == ICE_VSI_PF &&
3325 test_bit(ICE_FLAG_TC_MQPRIO, pf->flags))
3326 ret = ice_vsi_setup_q_map_mqprio(vsi, ctx, ena_tc);
3327 else
3328 ret = ice_vsi_setup_q_map(vsi, ctx);
3329
3330 if (ret) {
3331 memcpy(&vsi->tc_cfg, &old_tc_cfg, sizeof(vsi->tc_cfg));
3332 goto out;
3333 }
3334
3335 /* must to indicate which section of VSI context are being modified */
3336 ctx->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
3337 ret = ice_update_vsi(&pf->hw, vsi->idx, ctx, NULL);
3338 if (ret) {
3339 dev_info(dev, "Failed VSI Update\n");
3340 goto out;
3341 }
3342
3343 if (vsi->type == ICE_VSI_PF &&
3344 test_bit(ICE_FLAG_TC_MQPRIO, pf->flags))
3345 ret = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, 1, max_txqs);
3346 else
3347 ret = ice_cfg_vsi_lan(vsi->port_info, vsi->idx,
3348 vsi->tc_cfg.ena_tc, max_txqs);
3349
3350 if (ret) {
3351 dev_err(dev, "VSI %d failed TC config, error %d\n",
3352 vsi->vsi_num, ret);
3353 goto out;
3354 }
3355 ice_vsi_update_q_map(vsi, ctx);
3356 vsi->info.valid_sections = 0;
3357
3358 ice_vsi_cfg_netdev_tc(vsi, ena_tc);
3359 out:
3360 kfree(ctx);
3361 return ret;
3362 }
3363
3364 /**
3365 * ice_update_ring_stats - Update ring statistics
3366 * @stats: stats to be updated
3367 * @pkts: number of processed packets
3368 * @bytes: number of processed bytes
3369 *
3370 * This function assumes that caller has acquired a u64_stats_sync lock.
3371 */
ice_update_ring_stats(struct ice_q_stats * stats,u64 pkts,u64 bytes)3372 static void ice_update_ring_stats(struct ice_q_stats *stats, u64 pkts, u64 bytes)
3373 {
3374 stats->bytes += bytes;
3375 stats->pkts += pkts;
3376 }
3377
3378 /**
3379 * ice_update_tx_ring_stats - Update Tx ring specific counters
3380 * @tx_ring: ring to update
3381 * @pkts: number of processed packets
3382 * @bytes: number of processed bytes
3383 */
ice_update_tx_ring_stats(struct ice_tx_ring * tx_ring,u64 pkts,u64 bytes)3384 void ice_update_tx_ring_stats(struct ice_tx_ring *tx_ring, u64 pkts, u64 bytes)
3385 {
3386 u64_stats_update_begin(&tx_ring->ring_stats->syncp);
3387 ice_update_ring_stats(&tx_ring->ring_stats->stats, pkts, bytes);
3388 u64_stats_update_end(&tx_ring->ring_stats->syncp);
3389 }
3390
3391 /**
3392 * ice_update_rx_ring_stats - Update Rx ring specific counters
3393 * @rx_ring: ring to update
3394 * @pkts: number of processed packets
3395 * @bytes: number of processed bytes
3396 */
ice_update_rx_ring_stats(struct ice_rx_ring * rx_ring,u64 pkts,u64 bytes)3397 void ice_update_rx_ring_stats(struct ice_rx_ring *rx_ring, u64 pkts, u64 bytes)
3398 {
3399 u64_stats_update_begin(&rx_ring->ring_stats->syncp);
3400 ice_update_ring_stats(&rx_ring->ring_stats->stats, pkts, bytes);
3401 u64_stats_update_end(&rx_ring->ring_stats->syncp);
3402 }
3403
3404 /**
3405 * ice_is_dflt_vsi_in_use - check if the default forwarding VSI is being used
3406 * @pi: port info of the switch with default VSI
3407 *
3408 * Return true if the there is a single VSI in default forwarding VSI list
3409 */
ice_is_dflt_vsi_in_use(struct ice_port_info * pi)3410 bool ice_is_dflt_vsi_in_use(struct ice_port_info *pi)
3411 {
3412 bool exists = false;
3413
3414 ice_check_if_dflt_vsi(pi, 0, &exists);
3415 return exists;
3416 }
3417
3418 /**
3419 * ice_is_vsi_dflt_vsi - check if the VSI passed in is the default VSI
3420 * @vsi: VSI to compare against default forwarding VSI
3421 *
3422 * If this VSI passed in is the default forwarding VSI then return true, else
3423 * return false
3424 */
ice_is_vsi_dflt_vsi(struct ice_vsi * vsi)3425 bool ice_is_vsi_dflt_vsi(struct ice_vsi *vsi)
3426 {
3427 return ice_check_if_dflt_vsi(vsi->port_info, vsi->idx, NULL);
3428 }
3429
3430 /**
3431 * ice_set_dflt_vsi - set the default forwarding VSI
3432 * @vsi: VSI getting set as the default forwarding VSI on the switch
3433 *
3434 * If the VSI passed in is already the default VSI and it's enabled just return
3435 * success.
3436 *
3437 * Otherwise try to set the VSI passed in as the switch's default VSI and
3438 * return the result.
3439 */
ice_set_dflt_vsi(struct ice_vsi * vsi)3440 int ice_set_dflt_vsi(struct ice_vsi *vsi)
3441 {
3442 struct device *dev;
3443 int status;
3444
3445 if (!vsi)
3446 return -EINVAL;
3447
3448 dev = ice_pf_to_dev(vsi->back);
3449
3450 if (ice_lag_is_switchdev_running(vsi->back)) {
3451 dev_dbg(dev, "VSI %d passed is a part of LAG containing interfaces in switchdev mode, nothing to do\n",
3452 vsi->vsi_num);
3453 return 0;
3454 }
3455
3456 /* the VSI passed in is already the default VSI */
3457 if (ice_is_vsi_dflt_vsi(vsi)) {
3458 dev_dbg(dev, "VSI %d passed in is already the default forwarding VSI, nothing to do\n",
3459 vsi->vsi_num);
3460 return 0;
3461 }
3462
3463 status = ice_cfg_dflt_vsi(vsi->port_info, vsi->idx, true, ICE_FLTR_RX);
3464 if (status) {
3465 dev_err(dev, "Failed to set VSI %d as the default forwarding VSI, error %d\n",
3466 vsi->vsi_num, status);
3467 return status;
3468 }
3469
3470 return 0;
3471 }
3472
3473 /**
3474 * ice_clear_dflt_vsi - clear the default forwarding VSI
3475 * @vsi: VSI to remove from filter list
3476 *
3477 * If the switch has no default VSI or it's not enabled then return error.
3478 *
3479 * Otherwise try to clear the default VSI and return the result.
3480 */
ice_clear_dflt_vsi(struct ice_vsi * vsi)3481 int ice_clear_dflt_vsi(struct ice_vsi *vsi)
3482 {
3483 struct device *dev;
3484 int status;
3485
3486 if (!vsi)
3487 return -EINVAL;
3488
3489 dev = ice_pf_to_dev(vsi->back);
3490
3491 /* there is no default VSI configured */
3492 if (!ice_is_dflt_vsi_in_use(vsi->port_info))
3493 return -ENODEV;
3494
3495 status = ice_cfg_dflt_vsi(vsi->port_info, vsi->idx, false,
3496 ICE_FLTR_RX);
3497 if (status) {
3498 dev_err(dev, "Failed to clear the default forwarding VSI %d, error %d\n",
3499 vsi->vsi_num, status);
3500 return -EIO;
3501 }
3502
3503 return 0;
3504 }
3505
3506 /**
3507 * ice_get_link_speed_mbps - get link speed in Mbps
3508 * @vsi: the VSI whose link speed is being queried
3509 *
3510 * Return current VSI link speed and 0 if the speed is unknown.
3511 */
ice_get_link_speed_mbps(struct ice_vsi * vsi)3512 int ice_get_link_speed_mbps(struct ice_vsi *vsi)
3513 {
3514 unsigned int link_speed;
3515
3516 link_speed = vsi->port_info->phy.link_info.link_speed;
3517
3518 return (int)ice_get_link_speed(fls(link_speed) - 1);
3519 }
3520
3521 /**
3522 * ice_get_link_speed_kbps - get link speed in Kbps
3523 * @vsi: the VSI whose link speed is being queried
3524 *
3525 * Return current VSI link speed and 0 if the speed is unknown.
3526 */
ice_get_link_speed_kbps(struct ice_vsi * vsi)3527 int ice_get_link_speed_kbps(struct ice_vsi *vsi)
3528 {
3529 int speed_mbps;
3530
3531 speed_mbps = ice_get_link_speed_mbps(vsi);
3532
3533 return speed_mbps * 1000;
3534 }
3535
3536 /**
3537 * ice_set_min_bw_limit - setup minimum BW limit for Tx based on min_tx_rate
3538 * @vsi: VSI to be configured
3539 * @min_tx_rate: min Tx rate in Kbps to be configured as BW limit
3540 *
3541 * If the min_tx_rate is specified as 0 that means to clear the minimum BW limit
3542 * profile, otherwise a non-zero value will force a minimum BW limit for the VSI
3543 * on TC 0.
3544 */
ice_set_min_bw_limit(struct ice_vsi * vsi,u64 min_tx_rate)3545 int ice_set_min_bw_limit(struct ice_vsi *vsi, u64 min_tx_rate)
3546 {
3547 struct ice_pf *pf = vsi->back;
3548 struct device *dev;
3549 int status;
3550 int speed;
3551
3552 dev = ice_pf_to_dev(pf);
3553 if (!vsi->port_info) {
3554 dev_dbg(dev, "VSI %d, type %u specified doesn't have valid port_info\n",
3555 vsi->idx, vsi->type);
3556 return -EINVAL;
3557 }
3558
3559 speed = ice_get_link_speed_kbps(vsi);
3560 if (min_tx_rate > (u64)speed) {
3561 dev_err(dev, "invalid min Tx rate %llu Kbps specified for %s %d is greater than current link speed %u Kbps\n",
3562 min_tx_rate, ice_vsi_type_str(vsi->type), vsi->idx,
3563 speed);
3564 return -EINVAL;
3565 }
3566
3567 /* Configure min BW for VSI limit */
3568 if (min_tx_rate) {
3569 status = ice_cfg_vsi_bw_lmt_per_tc(vsi->port_info, vsi->idx, 0,
3570 ICE_MIN_BW, min_tx_rate);
3571 if (status) {
3572 dev_err(dev, "failed to set min Tx rate(%llu Kbps) for %s %d\n",
3573 min_tx_rate, ice_vsi_type_str(vsi->type),
3574 vsi->idx);
3575 return status;
3576 }
3577
3578 dev_dbg(dev, "set min Tx rate(%llu Kbps) for %s\n",
3579 min_tx_rate, ice_vsi_type_str(vsi->type));
3580 } else {
3581 status = ice_cfg_vsi_bw_dflt_lmt_per_tc(vsi->port_info,
3582 vsi->idx, 0,
3583 ICE_MIN_BW);
3584 if (status) {
3585 dev_err(dev, "failed to clear min Tx rate configuration for %s %d\n",
3586 ice_vsi_type_str(vsi->type), vsi->idx);
3587 return status;
3588 }
3589
3590 dev_dbg(dev, "cleared min Tx rate configuration for %s %d\n",
3591 ice_vsi_type_str(vsi->type), vsi->idx);
3592 }
3593
3594 return 0;
3595 }
3596
3597 /**
3598 * ice_set_max_bw_limit - setup maximum BW limit for Tx based on max_tx_rate
3599 * @vsi: VSI to be configured
3600 * @max_tx_rate: max Tx rate in Kbps to be configured as BW limit
3601 *
3602 * If the max_tx_rate is specified as 0 that means to clear the maximum BW limit
3603 * profile, otherwise a non-zero value will force a maximum BW limit for the VSI
3604 * on TC 0.
3605 */
ice_set_max_bw_limit(struct ice_vsi * vsi,u64 max_tx_rate)3606 int ice_set_max_bw_limit(struct ice_vsi *vsi, u64 max_tx_rate)
3607 {
3608 struct ice_pf *pf = vsi->back;
3609 struct device *dev;
3610 int status;
3611 int speed;
3612
3613 dev = ice_pf_to_dev(pf);
3614 if (!vsi->port_info) {
3615 dev_dbg(dev, "VSI %d, type %u specified doesn't have valid port_info\n",
3616 vsi->idx, vsi->type);
3617 return -EINVAL;
3618 }
3619
3620 speed = ice_get_link_speed_kbps(vsi);
3621 if (max_tx_rate > (u64)speed) {
3622 dev_err(dev, "invalid max Tx rate %llu Kbps specified for %s %d is greater than current link speed %u Kbps\n",
3623 max_tx_rate, ice_vsi_type_str(vsi->type), vsi->idx,
3624 speed);
3625 return -EINVAL;
3626 }
3627
3628 /* Configure max BW for VSI limit */
3629 if (max_tx_rate) {
3630 status = ice_cfg_vsi_bw_lmt_per_tc(vsi->port_info, vsi->idx, 0,
3631 ICE_MAX_BW, max_tx_rate);
3632 if (status) {
3633 dev_err(dev, "failed setting max Tx rate(%llu Kbps) for %s %d\n",
3634 max_tx_rate, ice_vsi_type_str(vsi->type),
3635 vsi->idx);
3636 return status;
3637 }
3638
3639 dev_dbg(dev, "set max Tx rate(%llu Kbps) for %s %d\n",
3640 max_tx_rate, ice_vsi_type_str(vsi->type), vsi->idx);
3641 } else {
3642 status = ice_cfg_vsi_bw_dflt_lmt_per_tc(vsi->port_info,
3643 vsi->idx, 0,
3644 ICE_MAX_BW);
3645 if (status) {
3646 dev_err(dev, "failed clearing max Tx rate configuration for %s %d\n",
3647 ice_vsi_type_str(vsi->type), vsi->idx);
3648 return status;
3649 }
3650
3651 dev_dbg(dev, "cleared max Tx rate configuration for %s %d\n",
3652 ice_vsi_type_str(vsi->type), vsi->idx);
3653 }
3654
3655 return 0;
3656 }
3657
3658 /**
3659 * ice_set_link - turn on/off physical link
3660 * @vsi: VSI to modify physical link on
3661 * @ena: turn on/off physical link
3662 */
ice_set_link(struct ice_vsi * vsi,bool ena)3663 int ice_set_link(struct ice_vsi *vsi, bool ena)
3664 {
3665 struct device *dev = ice_pf_to_dev(vsi->back);
3666 struct ice_port_info *pi = vsi->port_info;
3667 struct ice_hw *hw = pi->hw;
3668 int status;
3669
3670 if (vsi->type != ICE_VSI_PF)
3671 return -EINVAL;
3672
3673 status = ice_aq_set_link_restart_an(pi, ena, NULL);
3674
3675 /* if link is owned by manageability, FW will return ICE_AQ_RC_EMODE.
3676 * this is not a fatal error, so print a warning message and return
3677 * a success code. Return an error if FW returns an error code other
3678 * than ICE_AQ_RC_EMODE
3679 */
3680 if (status == -EIO) {
3681 if (hw->adminq.sq_last_status == ICE_AQ_RC_EMODE)
3682 dev_dbg(dev, "can't set link to %s, err %d aq_err %s. not fatal, continuing\n",
3683 (ena ? "ON" : "OFF"), status,
3684 ice_aq_str(hw->adminq.sq_last_status));
3685 } else if (status) {
3686 dev_err(dev, "can't set link to %s, err %d aq_err %s\n",
3687 (ena ? "ON" : "OFF"), status,
3688 ice_aq_str(hw->adminq.sq_last_status));
3689 return status;
3690 }
3691
3692 return 0;
3693 }
3694
3695 /**
3696 * ice_vsi_add_vlan_zero - add VLAN 0 filter(s) for this VSI
3697 * @vsi: VSI used to add VLAN filters
3698 *
3699 * In Single VLAN Mode (SVM), single VLAN filters via ICE_SW_LKUP_VLAN are based
3700 * on the inner VLAN ID, so the VLAN TPID (i.e. 0x8100 or 0x888a8) doesn't
3701 * matter. In Double VLAN Mode (DVM), outer/single VLAN filters via
3702 * ICE_SW_LKUP_VLAN are based on the outer/single VLAN ID + VLAN TPID.
3703 *
3704 * For both modes add a VLAN 0 + no VLAN TPID filter to handle untagged traffic
3705 * when VLAN pruning is enabled. Also, this handles VLAN 0 priority tagged
3706 * traffic in SVM, since the VLAN TPID isn't part of filtering.
3707 *
3708 * If DVM is enabled then an explicit VLAN 0 + VLAN TPID filter needs to be
3709 * added to allow VLAN 0 priority tagged traffic in DVM, since the VLAN TPID is
3710 * part of filtering.
3711 */
ice_vsi_add_vlan_zero(struct ice_vsi * vsi)3712 int ice_vsi_add_vlan_zero(struct ice_vsi *vsi)
3713 {
3714 struct ice_vsi_vlan_ops *vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
3715 struct ice_vlan vlan;
3716 int err;
3717
3718 vlan = ICE_VLAN(0, 0, 0);
3719 err = vlan_ops->add_vlan(vsi, &vlan);
3720 if (err && err != -EEXIST)
3721 return err;
3722
3723 /* in SVM both VLAN 0 filters are identical */
3724 if (!ice_is_dvm_ena(&vsi->back->hw))
3725 return 0;
3726
3727 vlan = ICE_VLAN(ETH_P_8021Q, 0, 0);
3728 err = vlan_ops->add_vlan(vsi, &vlan);
3729 if (err && err != -EEXIST)
3730 return err;
3731
3732 return 0;
3733 }
3734
3735 /**
3736 * ice_vsi_del_vlan_zero - delete VLAN 0 filter(s) for this VSI
3737 * @vsi: VSI used to add VLAN filters
3738 *
3739 * Delete the VLAN 0 filters in the same manner that they were added in
3740 * ice_vsi_add_vlan_zero.
3741 */
ice_vsi_del_vlan_zero(struct ice_vsi * vsi)3742 int ice_vsi_del_vlan_zero(struct ice_vsi *vsi)
3743 {
3744 struct ice_vsi_vlan_ops *vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
3745 struct ice_vlan vlan;
3746 int err;
3747
3748 vlan = ICE_VLAN(0, 0, 0);
3749 err = vlan_ops->del_vlan(vsi, &vlan);
3750 if (err && err != -EEXIST)
3751 return err;
3752
3753 /* in SVM both VLAN 0 filters are identical */
3754 if (!ice_is_dvm_ena(&vsi->back->hw))
3755 return 0;
3756
3757 vlan = ICE_VLAN(ETH_P_8021Q, 0, 0);
3758 err = vlan_ops->del_vlan(vsi, &vlan);
3759 if (err && err != -EEXIST)
3760 return err;
3761
3762 /* when deleting the last VLAN filter, make sure to disable the VLAN
3763 * promisc mode so the filter isn't left by accident
3764 */
3765 return ice_clear_vsi_promisc(&vsi->back->hw, vsi->idx,
3766 ICE_MCAST_VLAN_PROMISC_BITS, 0);
3767 }
3768
3769 /**
3770 * ice_vsi_num_zero_vlans - get number of VLAN 0 filters based on VLAN mode
3771 * @vsi: VSI used to get the VLAN mode
3772 *
3773 * If DVM is enabled then 2 VLAN 0 filters are added, else if SVM is enabled
3774 * then 1 VLAN 0 filter is added. See ice_vsi_add_vlan_zero for more details.
3775 */
ice_vsi_num_zero_vlans(struct ice_vsi * vsi)3776 static u16 ice_vsi_num_zero_vlans(struct ice_vsi *vsi)
3777 {
3778 #define ICE_DVM_NUM_ZERO_VLAN_FLTRS 2
3779 #define ICE_SVM_NUM_ZERO_VLAN_FLTRS 1
3780 /* no VLAN 0 filter is created when a port VLAN is active */
3781 if (vsi->type == ICE_VSI_VF) {
3782 if (WARN_ON(!vsi->vf))
3783 return 0;
3784
3785 if (ice_vf_is_port_vlan_ena(vsi->vf))
3786 return 0;
3787 }
3788
3789 if (ice_is_dvm_ena(&vsi->back->hw))
3790 return ICE_DVM_NUM_ZERO_VLAN_FLTRS;
3791 else
3792 return ICE_SVM_NUM_ZERO_VLAN_FLTRS;
3793 }
3794
3795 /**
3796 * ice_vsi_has_non_zero_vlans - check if VSI has any non-zero VLANs
3797 * @vsi: VSI used to determine if any non-zero VLANs have been added
3798 */
ice_vsi_has_non_zero_vlans(struct ice_vsi * vsi)3799 bool ice_vsi_has_non_zero_vlans(struct ice_vsi *vsi)
3800 {
3801 return (vsi->num_vlan > ice_vsi_num_zero_vlans(vsi));
3802 }
3803
3804 /**
3805 * ice_vsi_num_non_zero_vlans - get the number of non-zero VLANs for this VSI
3806 * @vsi: VSI used to get the number of non-zero VLANs added
3807 */
ice_vsi_num_non_zero_vlans(struct ice_vsi * vsi)3808 u16 ice_vsi_num_non_zero_vlans(struct ice_vsi *vsi)
3809 {
3810 return (vsi->num_vlan - ice_vsi_num_zero_vlans(vsi));
3811 }
3812
3813 /**
3814 * ice_is_feature_supported
3815 * @pf: pointer to the struct ice_pf instance
3816 * @f: feature enum to be checked
3817 *
3818 * returns true if feature is supported, false otherwise
3819 */
ice_is_feature_supported(struct ice_pf * pf,enum ice_feature f)3820 bool ice_is_feature_supported(struct ice_pf *pf, enum ice_feature f)
3821 {
3822 if (f < 0 || f >= ICE_F_MAX)
3823 return false;
3824
3825 return test_bit(f, pf->features);
3826 }
3827
3828 /**
3829 * ice_set_feature_support
3830 * @pf: pointer to the struct ice_pf instance
3831 * @f: feature enum to set
3832 */
ice_set_feature_support(struct ice_pf * pf,enum ice_feature f)3833 void ice_set_feature_support(struct ice_pf *pf, enum ice_feature f)
3834 {
3835 if (f < 0 || f >= ICE_F_MAX)
3836 return;
3837
3838 set_bit(f, pf->features);
3839 }
3840
3841 /**
3842 * ice_clear_feature_support
3843 * @pf: pointer to the struct ice_pf instance
3844 * @f: feature enum to clear
3845 */
ice_clear_feature_support(struct ice_pf * pf,enum ice_feature f)3846 void ice_clear_feature_support(struct ice_pf *pf, enum ice_feature f)
3847 {
3848 if (f < 0 || f >= ICE_F_MAX)
3849 return;
3850
3851 clear_bit(f, pf->features);
3852 }
3853
3854 /**
3855 * ice_init_feature_support
3856 * @pf: pointer to the struct ice_pf instance
3857 *
3858 * called during init to setup supported feature
3859 */
ice_init_feature_support(struct ice_pf * pf)3860 void ice_init_feature_support(struct ice_pf *pf)
3861 {
3862 switch (pf->hw.device_id) {
3863 case ICE_DEV_ID_E810C_BACKPLANE:
3864 case ICE_DEV_ID_E810C_QSFP:
3865 case ICE_DEV_ID_E810C_SFP:
3866 case ICE_DEV_ID_E810_XXV_BACKPLANE:
3867 case ICE_DEV_ID_E810_XXV_QSFP:
3868 case ICE_DEV_ID_E810_XXV_SFP:
3869 ice_set_feature_support(pf, ICE_F_DSCP);
3870 if (ice_is_phy_rclk_in_netlist(&pf->hw))
3871 ice_set_feature_support(pf, ICE_F_PHY_RCLK);
3872 /* If we don't own the timer - don't enable other caps */
3873 if (!ice_pf_src_tmr_owned(pf))
3874 break;
3875 if (ice_is_cgu_in_netlist(&pf->hw))
3876 ice_set_feature_support(pf, ICE_F_CGU);
3877 if (ice_is_clock_mux_in_netlist(&pf->hw))
3878 ice_set_feature_support(pf, ICE_F_SMA_CTRL);
3879 if (ice_gnss_is_gps_present(&pf->hw))
3880 ice_set_feature_support(pf, ICE_F_GNSS);
3881 break;
3882 default:
3883 break;
3884 }
3885
3886 if (pf->hw.mac_type == ICE_MAC_E830)
3887 ice_set_feature_support(pf, ICE_F_MBX_LIMIT);
3888 }
3889
3890 /**
3891 * ice_vsi_update_security - update security block in VSI
3892 * @vsi: pointer to VSI structure
3893 * @fill: function pointer to fill ctx
3894 */
3895 int
ice_vsi_update_security(struct ice_vsi * vsi,void (* fill)(struct ice_vsi_ctx *))3896 ice_vsi_update_security(struct ice_vsi *vsi, void (*fill)(struct ice_vsi_ctx *))
3897 {
3898 struct ice_vsi_ctx ctx = { 0 };
3899
3900 ctx.info = vsi->info;
3901 ctx.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID);
3902 fill(&ctx);
3903
3904 if (ice_update_vsi(&vsi->back->hw, vsi->idx, &ctx, NULL))
3905 return -ENODEV;
3906
3907 vsi->info = ctx.info;
3908 return 0;
3909 }
3910
3911 /**
3912 * ice_vsi_ctx_set_antispoof - set antispoof function in VSI ctx
3913 * @ctx: pointer to VSI ctx structure
3914 */
ice_vsi_ctx_set_antispoof(struct ice_vsi_ctx * ctx)3915 void ice_vsi_ctx_set_antispoof(struct ice_vsi_ctx *ctx)
3916 {
3917 ctx->info.sec_flags |= ICE_AQ_VSI_SEC_FLAG_ENA_MAC_ANTI_SPOOF |
3918 (ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
3919 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S);
3920 }
3921
3922 /**
3923 * ice_vsi_ctx_clear_antispoof - clear antispoof function in VSI ctx
3924 * @ctx: pointer to VSI ctx structure
3925 */
ice_vsi_ctx_clear_antispoof(struct ice_vsi_ctx * ctx)3926 void ice_vsi_ctx_clear_antispoof(struct ice_vsi_ctx *ctx)
3927 {
3928 ctx->info.sec_flags &= ~ICE_AQ_VSI_SEC_FLAG_ENA_MAC_ANTI_SPOOF &
3929 ~(ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
3930 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S);
3931 }
3932
3933 /**
3934 * ice_vsi_update_local_lb - update sw block in VSI with local loopback bit
3935 * @vsi: pointer to VSI structure
3936 * @set: set or unset the bit
3937 */
3938 int
ice_vsi_update_local_lb(struct ice_vsi * vsi,bool set)3939 ice_vsi_update_local_lb(struct ice_vsi *vsi, bool set)
3940 {
3941 struct ice_vsi_ctx ctx = {
3942 .info = vsi->info,
3943 };
3944
3945 ctx.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
3946 if (set)
3947 ctx.info.sw_flags |= ICE_AQ_VSI_SW_FLAG_LOCAL_LB;
3948 else
3949 ctx.info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_LOCAL_LB;
3950
3951 if (ice_update_vsi(&vsi->back->hw, vsi->idx, &ctx, NULL))
3952 return -ENODEV;
3953
3954 vsi->info = ctx.info;
3955 return 0;
3956 }
3957