1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
7 #include "ice_dcb_lib.h"
10 * ice_vsi_ctrl_rx_rings - Start or stop a VSI's Rx rings
11 * @vsi: the VSI being configured
12 * @ena: start or stop the Rx rings
14 static int ice_vsi_ctrl_rx_rings(struct ice_vsi *vsi, bool ena)
18 for (i = 0; i < vsi->num_rxq; i++) {
19 ret = ice_vsi_ctrl_rx_ring(vsi, ena, i);
28 * ice_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the VSI
31 * On error: returns error code (negative)
32 * On success: returns 0
34 static int ice_vsi_alloc_arrays(struct ice_vsi *vsi)
36 struct ice_pf *pf = vsi->back;
38 /* allocate memory for both Tx and Rx ring pointers */
39 vsi->tx_rings = devm_kcalloc(&pf->pdev->dev, vsi->alloc_txq,
40 sizeof(*vsi->tx_rings), GFP_KERNEL);
44 vsi->rx_rings = devm_kcalloc(&pf->pdev->dev, vsi->alloc_rxq,
45 sizeof(*vsi->rx_rings), GFP_KERNEL);
49 /* XDP will have vsi->alloc_txq Tx queues as well, so double the size */
50 vsi->txq_map = devm_kcalloc(&pf->pdev->dev, (2 * vsi->alloc_txq),
51 sizeof(*vsi->txq_map), GFP_KERNEL);
56 vsi->rxq_map = devm_kcalloc(&pf->pdev->dev, vsi->alloc_rxq,
57 sizeof(*vsi->rxq_map), GFP_KERNEL);
61 /* There is no need to allocate q_vectors for a loopback VSI. */
62 if (vsi->type == ICE_VSI_LB)
65 /* allocate memory for q_vector pointers */
66 vsi->q_vectors = devm_kcalloc(&pf->pdev->dev, vsi->num_q_vectors,
67 sizeof(*vsi->q_vectors), GFP_KERNEL);
74 devm_kfree(&pf->pdev->dev, vsi->rxq_map);
76 devm_kfree(&pf->pdev->dev, vsi->txq_map);
78 devm_kfree(&pf->pdev->dev, vsi->rx_rings);
80 devm_kfree(&pf->pdev->dev, vsi->tx_rings);
85 * ice_vsi_set_num_desc - Set number of descriptors for queues on this VSI
86 * @vsi: the VSI being configured
88 static void ice_vsi_set_num_desc(struct ice_vsi *vsi)
94 vsi->num_rx_desc = ICE_DFLT_NUM_RX_DESC;
95 vsi->num_tx_desc = ICE_DFLT_NUM_TX_DESC;
98 dev_dbg(&vsi->back->pdev->dev,
99 "Not setting number of Tx/Rx descriptors for VSI type %d\n",
106 * ice_vsi_set_num_qs - Set number of queues, descriptors and vectors for a VSI
107 * @vsi: the VSI being configured
108 * @vf_id: ID of the VF being configured
110 * Return 0 on success and a negative value on error
112 static void ice_vsi_set_num_qs(struct ice_vsi *vsi, u16 vf_id)
114 struct ice_pf *pf = vsi->back;
115 struct ice_vf *vf = NULL;
117 if (vsi->type == ICE_VSI_VF)
122 vsi->alloc_txq = min_t(int, ice_get_avail_txq_count(pf),
125 pf->num_lan_tx = vsi->alloc_txq;
127 /* only 1 Rx queue unless RSS is enabled */
128 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags))
131 vsi->alloc_rxq = min_t(int, ice_get_avail_rxq_count(pf),
134 pf->num_lan_rx = vsi->alloc_rxq;
136 vsi->num_q_vectors = max_t(int, vsi->alloc_rxq, vsi->alloc_txq);
139 vf = &pf->vf[vsi->vf_id];
140 vsi->alloc_txq = vf->num_vf_qs;
141 vsi->alloc_rxq = vf->num_vf_qs;
142 /* pf->num_vf_msix includes (VF miscellaneous vector +
143 * data queue interrupts). Since vsi->num_q_vectors is number
144 * of queues vectors, subtract 1 (ICE_NONQ_VECS_VF) from the
145 * original vector count
147 vsi->num_q_vectors = pf->num_vf_msix - ICE_NONQ_VECS_VF;
154 dev_warn(&pf->pdev->dev, "Unknown VSI type %d\n", vsi->type);
158 ice_vsi_set_num_desc(vsi);
162 * ice_get_free_slot - get the next non-NULL location index in array
163 * @array: array to search
164 * @size: size of the array
165 * @curr: last known occupied index to be used as a search hint
167 * void * is being used to keep the functionality generic. This lets us use this
168 * function on any array of pointers.
170 static int ice_get_free_slot(void *array, int size, int curr)
172 int **tmp_array = (int **)array;
175 if (curr < (size - 1) && !tmp_array[curr + 1]) {
180 while ((i < size) && (tmp_array[i]))
191 * ice_vsi_delete - delete a VSI from the switch
192 * @vsi: pointer to VSI being removed
194 void ice_vsi_delete(struct ice_vsi *vsi)
196 struct ice_pf *pf = vsi->back;
197 struct ice_vsi_ctx *ctxt;
198 enum ice_status status;
200 ctxt = devm_kzalloc(&pf->pdev->dev, sizeof(*ctxt), GFP_KERNEL);
204 if (vsi->type == ICE_VSI_VF)
205 ctxt->vf_num = vsi->vf_id;
206 ctxt->vsi_num = vsi->vsi_num;
208 memcpy(&ctxt->info, &vsi->info, sizeof(ctxt->info));
210 status = ice_free_vsi(&pf->hw, vsi->idx, ctxt, false, NULL);
212 dev_err(&pf->pdev->dev, "Failed to delete VSI %i in FW\n",
215 devm_kfree(&pf->pdev->dev, ctxt);
219 * ice_vsi_free_arrays - De-allocate queue and vector pointer arrays for the VSI
220 * @vsi: pointer to VSI being cleared
222 static void ice_vsi_free_arrays(struct ice_vsi *vsi)
224 struct ice_pf *pf = vsi->back;
226 /* free the ring and vector containers */
227 if (vsi->q_vectors) {
228 devm_kfree(&pf->pdev->dev, vsi->q_vectors);
229 vsi->q_vectors = NULL;
232 devm_kfree(&pf->pdev->dev, vsi->tx_rings);
233 vsi->tx_rings = NULL;
236 devm_kfree(&pf->pdev->dev, vsi->rx_rings);
237 vsi->rx_rings = NULL;
240 devm_kfree(&pf->pdev->dev, vsi->txq_map);
244 devm_kfree(&pf->pdev->dev, vsi->rxq_map);
250 * ice_vsi_clear - clean up and deallocate the provided VSI
251 * @vsi: pointer to VSI being cleared
253 * This deallocates the VSI's queue resources, removes it from the PF's
254 * VSI array if necessary, and deallocates the VSI
256 * Returns 0 on success, negative on failure
258 int ice_vsi_clear(struct ice_vsi *vsi)
260 struct ice_pf *pf = NULL;
270 if (!pf->vsi[vsi->idx] || pf->vsi[vsi->idx] != vsi) {
271 dev_dbg(&pf->pdev->dev, "vsi does not exist at pf->vsi[%d]\n",
276 mutex_lock(&pf->sw_mutex);
277 /* updates the PF for this cleared VSI */
279 pf->vsi[vsi->idx] = NULL;
280 if (vsi->idx < pf->next_vsi)
281 pf->next_vsi = vsi->idx;
283 ice_vsi_free_arrays(vsi);
284 mutex_unlock(&pf->sw_mutex);
285 devm_kfree(&pf->pdev->dev, vsi);
291 * ice_msix_clean_rings - MSIX mode Interrupt Handler
292 * @irq: interrupt number
293 * @data: pointer to a q_vector
295 static irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data)
297 struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
299 if (!q_vector->tx.ring && !q_vector->rx.ring)
302 napi_schedule(&q_vector->napi);
308 * ice_vsi_alloc - Allocates the next available struct VSI in the PF
309 * @pf: board private structure
311 * @vf_id: ID of the VF being configured
313 * returns a pointer to a VSI on success, NULL on failure.
315 static struct ice_vsi *
316 ice_vsi_alloc(struct ice_pf *pf, enum ice_vsi_type type, u16 vf_id)
318 struct ice_vsi *vsi = NULL;
320 /* Need to protect the allocation of the VSIs at the PF level */
321 mutex_lock(&pf->sw_mutex);
323 /* If we have already allocated our maximum number of VSIs,
324 * pf->next_vsi will be ICE_NO_VSI. If not, pf->next_vsi index
325 * is available to be populated
327 if (pf->next_vsi == ICE_NO_VSI) {
328 dev_dbg(&pf->pdev->dev, "out of VSI slots!\n");
332 vsi = devm_kzalloc(&pf->pdev->dev, sizeof(*vsi), GFP_KERNEL);
338 set_bit(__ICE_DOWN, vsi->state);
340 vsi->idx = pf->next_vsi;
342 if (type == ICE_VSI_VF)
343 ice_vsi_set_num_qs(vsi, vf_id);
345 ice_vsi_set_num_qs(vsi, ICE_INVAL_VFID);
349 if (ice_vsi_alloc_arrays(vsi))
352 /* Setup default MSIX irq handler for VSI */
353 vsi->irq_handler = ice_msix_clean_rings;
356 if (ice_vsi_alloc_arrays(vsi))
360 if (ice_vsi_alloc_arrays(vsi))
364 dev_warn(&pf->pdev->dev, "Unknown VSI type %d\n", vsi->type);
368 /* fill VSI slot in the PF struct */
369 pf->vsi[pf->next_vsi] = vsi;
371 /* prepare pf->next_vsi for next use */
372 pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi,
377 devm_kfree(&pf->pdev->dev, vsi);
380 mutex_unlock(&pf->sw_mutex);
385 * ice_vsi_get_qs - Assign queues from PF to VSI
386 * @vsi: the VSI to assign queues to
388 * Returns 0 on success and a negative value on error
390 static int ice_vsi_get_qs(struct ice_vsi *vsi)
392 struct ice_pf *pf = vsi->back;
393 struct ice_qs_cfg tx_qs_cfg = {
394 .qs_mutex = &pf->avail_q_mutex,
395 .pf_map = pf->avail_txqs,
396 .pf_map_size = pf->max_pf_txqs,
397 .q_count = vsi->alloc_txq,
398 .scatter_count = ICE_MAX_SCATTER_TXQS,
399 .vsi_map = vsi->txq_map,
401 .mapping_mode = vsi->tx_mapping_mode
403 struct ice_qs_cfg rx_qs_cfg = {
404 .qs_mutex = &pf->avail_q_mutex,
405 .pf_map = pf->avail_rxqs,
406 .pf_map_size = pf->max_pf_rxqs,
407 .q_count = vsi->alloc_rxq,
408 .scatter_count = ICE_MAX_SCATTER_RXQS,
409 .vsi_map = vsi->rxq_map,
411 .mapping_mode = vsi->rx_mapping_mode
415 vsi->tx_mapping_mode = ICE_VSI_MAP_CONTIG;
416 vsi->rx_mapping_mode = ICE_VSI_MAP_CONTIG;
418 ret = __ice_vsi_get_qs(&tx_qs_cfg);
420 ret = __ice_vsi_get_qs(&rx_qs_cfg);
426 * ice_vsi_put_qs - Release queues from VSI to PF
427 * @vsi: the VSI that is going to release queues
429 void ice_vsi_put_qs(struct ice_vsi *vsi)
431 struct ice_pf *pf = vsi->back;
434 mutex_lock(&pf->avail_q_mutex);
436 for (i = 0; i < vsi->alloc_txq; i++) {
437 clear_bit(vsi->txq_map[i], pf->avail_txqs);
438 vsi->txq_map[i] = ICE_INVAL_Q_INDEX;
441 for (i = 0; i < vsi->alloc_rxq; i++) {
442 clear_bit(vsi->rxq_map[i], pf->avail_rxqs);
443 vsi->rxq_map[i] = ICE_INVAL_Q_INDEX;
446 mutex_unlock(&pf->avail_q_mutex);
451 * @pf: pointer to the PF struct
453 * returns true if driver is in safe mode, false otherwise
455 bool ice_is_safe_mode(struct ice_pf *pf)
457 return !test_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
461 * ice_rss_clean - Delete RSS related VSI structures that hold user inputs
462 * @vsi: the VSI being removed
464 static void ice_rss_clean(struct ice_vsi *vsi)
470 if (vsi->rss_hkey_user)
471 devm_kfree(&pf->pdev->dev, vsi->rss_hkey_user);
472 if (vsi->rss_lut_user)
473 devm_kfree(&pf->pdev->dev, vsi->rss_lut_user);
477 * ice_vsi_set_rss_params - Setup RSS capabilities per VSI type
478 * @vsi: the VSI being configured
480 static void ice_vsi_set_rss_params(struct ice_vsi *vsi)
482 struct ice_hw_common_caps *cap;
483 struct ice_pf *pf = vsi->back;
485 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
490 cap = &pf->hw.func_caps.common_cap;
493 /* PF VSI will inherit RSS instance of PF */
494 vsi->rss_table_size = cap->rss_table_size;
495 vsi->rss_size = min_t(int, num_online_cpus(),
496 BIT(cap->rss_table_entry_width));
497 vsi->rss_lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
500 /* VF VSI will gets a small RSS table
501 * For VSI_LUT, LUT size should be set to 64 bytes
503 vsi->rss_table_size = ICE_VSIQF_HLUT_ARRAY_SIZE;
504 vsi->rss_size = min_t(int, num_online_cpus(),
505 BIT(cap->rss_table_entry_width));
506 vsi->rss_lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_VSI;
511 dev_warn(&pf->pdev->dev, "Unknown VSI type %d\n",
518 * ice_set_dflt_vsi_ctx - Set default VSI context before adding a VSI
519 * @ctxt: the VSI context being set
521 * This initializes a default VSI context for all sections except the Queues.
523 static void ice_set_dflt_vsi_ctx(struct ice_vsi_ctx *ctxt)
527 memset(&ctxt->info, 0, sizeof(ctxt->info));
528 /* VSI's should be allocated from shared pool */
529 ctxt->alloc_from_pool = true;
530 /* Src pruning enabled by default */
531 ctxt->info.sw_flags = ICE_AQ_VSI_SW_FLAG_SRC_PRUNE;
532 /* Traffic from VSI can be sent to LAN */
533 ctxt->info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
534 /* By default bits 3 and 4 in vlan_flags are 0's which results in legacy
535 * behavior (show VLAN, DEI, and UP) in descriptor. Also, allow all
536 * packets untagged/tagged.
538 ctxt->info.vlan_flags = ((ICE_AQ_VSI_VLAN_MODE_ALL &
539 ICE_AQ_VSI_VLAN_MODE_M) >>
540 ICE_AQ_VSI_VLAN_MODE_S);
541 /* Have 1:1 UP mapping for both ingress/egress tables */
542 table |= ICE_UP_TABLE_TRANSLATE(0, 0);
543 table |= ICE_UP_TABLE_TRANSLATE(1, 1);
544 table |= ICE_UP_TABLE_TRANSLATE(2, 2);
545 table |= ICE_UP_TABLE_TRANSLATE(3, 3);
546 table |= ICE_UP_TABLE_TRANSLATE(4, 4);
547 table |= ICE_UP_TABLE_TRANSLATE(5, 5);
548 table |= ICE_UP_TABLE_TRANSLATE(6, 6);
549 table |= ICE_UP_TABLE_TRANSLATE(7, 7);
550 ctxt->info.ingress_table = cpu_to_le32(table);
551 ctxt->info.egress_table = cpu_to_le32(table);
552 /* Have 1:1 UP mapping for outer to inner UP table */
553 ctxt->info.outer_up_table = cpu_to_le32(table);
554 /* No Outer tag support outer_tag_flags remains to zero */
558 * ice_vsi_setup_q_map - Setup a VSI queue map
559 * @vsi: the VSI being configured
560 * @ctxt: VSI context structure
562 static void ice_vsi_setup_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctxt)
564 u16 offset = 0, qmap = 0, tx_count = 0;
565 u16 qcount_tx = vsi->alloc_txq;
566 u16 qcount_rx = vsi->alloc_rxq;
567 u16 tx_numq_tc, rx_numq_tc;
568 u16 pow = 0, max_rss = 0;
569 bool ena_tc0 = false;
573 /* at least TC0 should be enabled by default */
574 if (vsi->tc_cfg.numtc) {
575 if (!(vsi->tc_cfg.ena_tc & BIT(0)))
583 vsi->tc_cfg.ena_tc |= 1;
586 rx_numq_tc = qcount_rx / vsi->tc_cfg.numtc;
589 tx_numq_tc = qcount_tx / vsi->tc_cfg.numtc;
593 /* TC mapping is a function of the number of Rx queues assigned to the
594 * VSI for each traffic class and the offset of these queues.
595 * The first 10 bits are for queue offset for TC0, next 4 bits for no:of
596 * queues allocated to TC0. No:of queues is a power-of-2.
598 * If TC is not enabled, the queue offset is set to 0, and allocate one
599 * queue, this way, traffic for the given TC will be sent to the default
602 * Setup number and offset of Rx queues for all TCs for the VSI
605 qcount_rx = rx_numq_tc;
607 /* qcount will change if RSS is enabled */
608 if (test_bit(ICE_FLAG_RSS_ENA, vsi->back->flags)) {
609 if (vsi->type == ICE_VSI_PF || vsi->type == ICE_VSI_VF) {
610 if (vsi->type == ICE_VSI_PF)
611 max_rss = ICE_MAX_LG_RSS_QS;
613 max_rss = ICE_MAX_SMALL_RSS_QS;
614 qcount_rx = min_t(int, rx_numq_tc, max_rss);
615 qcount_rx = min_t(int, qcount_rx, vsi->rss_size);
619 /* find the (rounded up) power-of-2 of qcount */
620 pow = order_base_2(qcount_rx);
622 ice_for_each_traffic_class(i) {
623 if (!(vsi->tc_cfg.ena_tc & BIT(i))) {
624 /* TC is not enabled */
625 vsi->tc_cfg.tc_info[i].qoffset = 0;
626 vsi->tc_cfg.tc_info[i].qcount_rx = 1;
627 vsi->tc_cfg.tc_info[i].qcount_tx = 1;
628 vsi->tc_cfg.tc_info[i].netdev_tc = 0;
629 ctxt->info.tc_mapping[i] = 0;
634 vsi->tc_cfg.tc_info[i].qoffset = offset;
635 vsi->tc_cfg.tc_info[i].qcount_rx = qcount_rx;
636 vsi->tc_cfg.tc_info[i].qcount_tx = tx_numq_tc;
637 vsi->tc_cfg.tc_info[i].netdev_tc = netdev_tc++;
639 qmap = ((offset << ICE_AQ_VSI_TC_Q_OFFSET_S) &
640 ICE_AQ_VSI_TC_Q_OFFSET_M) |
641 ((pow << ICE_AQ_VSI_TC_Q_NUM_S) &
642 ICE_AQ_VSI_TC_Q_NUM_M);
644 tx_count += tx_numq_tc;
645 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
648 /* if offset is non-zero, means it is calculated correctly based on
649 * enabled TCs for a given VSI otherwise qcount_rx will always
650 * be correct and non-zero because it is based off - VSI's
651 * allocated Rx queues which is at least 1 (hence qcount_tx will be
655 vsi->num_rxq = offset;
657 vsi->num_rxq = qcount_rx;
659 vsi->num_txq = tx_count;
661 if (vsi->type == ICE_VSI_VF && vsi->num_txq != vsi->num_rxq) {
662 dev_dbg(&vsi->back->pdev->dev, "VF VSI should have same number of Tx and Rx queues. Hence making them equal\n");
663 /* since there is a chance that num_rxq could have been changed
664 * in the above for loop, make num_txq equal to num_rxq.
666 vsi->num_txq = vsi->num_rxq;
669 /* Rx queue mapping */
670 ctxt->info.mapping_flags |= cpu_to_le16(ICE_AQ_VSI_Q_MAP_CONTIG);
671 /* q_mapping buffer holds the info for the first queue allocated for
672 * this VSI in the PF space and also the number of queues associated
675 ctxt->info.q_mapping[0] = cpu_to_le16(vsi->rxq_map[0]);
676 ctxt->info.q_mapping[1] = cpu_to_le16(vsi->num_rxq);
680 * ice_set_rss_vsi_ctx - Set RSS VSI context before adding a VSI
681 * @ctxt: the VSI context being set
682 * @vsi: the VSI being configured
684 static void ice_set_rss_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
686 u8 lut_type, hash_type;
693 /* PF VSI will inherit RSS instance of PF */
694 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_PF;
695 hash_type = ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
698 /* VF VSI will gets a small RSS table which is a VSI LUT type */
699 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI;
700 hash_type = ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
703 dev_dbg(&pf->pdev->dev, "Unsupported VSI type %d\n", vsi->type);
706 dev_warn(&pf->pdev->dev, "Unknown VSI type %d\n", vsi->type);
710 ctxt->info.q_opt_rss = ((lut_type << ICE_AQ_VSI_Q_OPT_RSS_LUT_S) &
711 ICE_AQ_VSI_Q_OPT_RSS_LUT_M) |
712 ((hash_type << ICE_AQ_VSI_Q_OPT_RSS_HASH_S) &
713 ICE_AQ_VSI_Q_OPT_RSS_HASH_M);
717 * ice_vsi_init - Create and initialize a VSI
718 * @vsi: the VSI being configured
720 * This initializes a VSI context depending on the VSI type to be added and
721 * passes it down to the add_vsi aq command to create a new VSI.
723 static int ice_vsi_init(struct ice_vsi *vsi)
725 struct ice_pf *pf = vsi->back;
726 struct ice_hw *hw = &pf->hw;
727 struct ice_vsi_ctx *ctxt;
730 ctxt = devm_kzalloc(&pf->pdev->dev, sizeof(*ctxt), GFP_KERNEL);
734 ctxt->info = vsi->info;
739 ctxt->flags = ICE_AQ_VSI_TYPE_PF;
742 ctxt->flags = ICE_AQ_VSI_TYPE_VF;
743 /* VF number here is the absolute VF number (0-255) */
744 ctxt->vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
750 ice_set_dflt_vsi_ctx(ctxt);
751 /* if the switch is in VEB mode, allow VSI loopback */
752 if (vsi->vsw->bridge_mode == BRIDGE_MODE_VEB)
753 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
755 /* Set LUT type and HASH type if RSS is enabled */
756 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
757 ice_set_rss_vsi_ctx(ctxt, vsi);
759 ctxt->info.sw_id = vsi->port_info->sw_id;
760 ice_vsi_setup_q_map(vsi, ctxt);
762 /* Enable MAC Antispoof with new VSI being initialized or updated */
763 if (vsi->type == ICE_VSI_VF && pf->vf[vsi->vf_id].spoofchk) {
764 ctxt->info.valid_sections |=
765 cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID);
766 ctxt->info.sec_flags |=
767 ICE_AQ_VSI_SEC_FLAG_ENA_MAC_ANTI_SPOOF;
770 /* Allow control frames out of main VSI */
771 if (vsi->type == ICE_VSI_PF) {
772 ctxt->info.sec_flags |= ICE_AQ_VSI_SEC_FLAG_ALLOW_DEST_OVRD;
773 ctxt->info.valid_sections |=
774 cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID);
777 ret = ice_add_vsi(hw, vsi->idx, ctxt, NULL);
779 dev_err(&pf->pdev->dev,
780 "Add VSI failed, err %d\n", ret);
784 /* keep context for update VSI operations */
785 vsi->info = ctxt->info;
787 /* record VSI number returned */
788 vsi->vsi_num = ctxt->vsi_num;
790 devm_kfree(&pf->pdev->dev, ctxt);
795 * ice_vsi_setup_vector_base - Set up the base vector for the given VSI
796 * @vsi: ptr to the VSI
798 * This should only be called after ice_vsi_alloc() which allocates the
799 * corresponding SW VSI structure and initializes num_queue_pairs for the
800 * newly allocated VSI.
802 * Returns 0 on success or negative on failure
804 static int ice_vsi_setup_vector_base(struct ice_vsi *vsi)
806 struct ice_pf *pf = vsi->back;
809 /* SRIOV doesn't grab irq_tracker entries for each VSI */
810 if (vsi->type == ICE_VSI_VF)
813 if (vsi->base_vector) {
814 dev_dbg(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
815 vsi->vsi_num, vsi->base_vector);
819 num_q_vectors = vsi->num_q_vectors;
820 /* reserve slots from OS requested IRQs */
821 vsi->base_vector = ice_get_res(pf, pf->irq_tracker, num_q_vectors,
823 if (vsi->base_vector < 0) {
824 dev_err(&pf->pdev->dev,
825 "Failed to get tracking for %d vectors for VSI %d, err=%d\n",
826 num_q_vectors, vsi->vsi_num, vsi->base_vector);
829 pf->num_avail_sw_msix -= num_q_vectors;
835 * ice_vsi_clear_rings - Deallocates the Tx and Rx rings for VSI
836 * @vsi: the VSI having rings deallocated
838 static void ice_vsi_clear_rings(struct ice_vsi *vsi)
843 for (i = 0; i < vsi->alloc_txq; i++) {
844 if (vsi->tx_rings[i]) {
845 kfree_rcu(vsi->tx_rings[i], rcu);
846 vsi->tx_rings[i] = NULL;
851 for (i = 0; i < vsi->alloc_rxq; i++) {
852 if (vsi->rx_rings[i]) {
853 kfree_rcu(vsi->rx_rings[i], rcu);
854 vsi->rx_rings[i] = NULL;
861 * ice_vsi_alloc_rings - Allocates Tx and Rx rings for the VSI
862 * @vsi: VSI which is having rings allocated
864 static int ice_vsi_alloc_rings(struct ice_vsi *vsi)
866 struct ice_pf *pf = vsi->back;
869 /* Allocate Tx rings */
870 for (i = 0; i < vsi->alloc_txq; i++) {
871 struct ice_ring *ring;
873 /* allocate with kzalloc(), free with kfree_rcu() */
874 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
880 ring->reg_idx = vsi->txq_map[i];
881 ring->ring_active = false;
883 ring->dev = &pf->pdev->dev;
884 ring->count = vsi->num_tx_desc;
885 vsi->tx_rings[i] = ring;
888 /* Allocate Rx rings */
889 for (i = 0; i < vsi->alloc_rxq; i++) {
890 struct ice_ring *ring;
892 /* allocate with kzalloc(), free with kfree_rcu() */
893 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
898 ring->reg_idx = vsi->rxq_map[i];
899 ring->ring_active = false;
901 ring->netdev = vsi->netdev;
902 ring->dev = &pf->pdev->dev;
903 ring->count = vsi->num_rx_desc;
904 vsi->rx_rings[i] = ring;
910 ice_vsi_clear_rings(vsi);
915 * ice_vsi_manage_rss_lut - disable/enable RSS
916 * @vsi: the VSI being changed
917 * @ena: boolean value indicating if this is an enable or disable request
919 * In the event of disable request for RSS, this function will zero out RSS
920 * LUT, while in the event of enable request for RSS, it will reconfigure RSS
923 int ice_vsi_manage_rss_lut(struct ice_vsi *vsi, bool ena)
928 lut = devm_kzalloc(&vsi->back->pdev->dev, vsi->rss_table_size,
934 if (vsi->rss_lut_user)
935 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
937 ice_fill_rss_lut(lut, vsi->rss_table_size,
941 err = ice_set_rss(vsi, NULL, lut, vsi->rss_table_size);
942 devm_kfree(&vsi->back->pdev->dev, lut);
947 * ice_vsi_cfg_rss_lut_key - Configure RSS params for a VSI
948 * @vsi: VSI to be configured
950 static int ice_vsi_cfg_rss_lut_key(struct ice_vsi *vsi)
952 struct ice_aqc_get_set_rss_keys *key;
953 struct ice_pf *pf = vsi->back;
954 enum ice_status status;
958 vsi->rss_size = min_t(int, vsi->rss_size, vsi->num_rxq);
960 lut = devm_kzalloc(&pf->pdev->dev, vsi->rss_table_size, GFP_KERNEL);
964 if (vsi->rss_lut_user)
965 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
967 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
969 status = ice_aq_set_rss_lut(&pf->hw, vsi->idx, vsi->rss_lut_type, lut,
970 vsi->rss_table_size);
973 dev_err(&pf->pdev->dev,
974 "set_rss_lut failed, error %d\n", status);
976 goto ice_vsi_cfg_rss_exit;
979 key = devm_kzalloc(&pf->pdev->dev, sizeof(*key), GFP_KERNEL);
982 goto ice_vsi_cfg_rss_exit;
985 if (vsi->rss_hkey_user)
987 (struct ice_aqc_get_set_rss_keys *)vsi->rss_hkey_user,
988 ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE);
990 netdev_rss_key_fill((void *)key,
991 ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE);
993 status = ice_aq_set_rss_key(&pf->hw, vsi->idx, key);
996 dev_err(&pf->pdev->dev, "set_rss_key failed, error %d\n",
1001 devm_kfree(&pf->pdev->dev, key);
1002 ice_vsi_cfg_rss_exit:
1003 devm_kfree(&pf->pdev->dev, lut);
1008 * ice_add_mac_to_list - Add a MAC address filter entry to the list
1009 * @vsi: the VSI to be forwarded to
1010 * @add_list: pointer to the list which contains MAC filter entries
1011 * @macaddr: the MAC address to be added.
1013 * Adds MAC address filter entry to the temp list
1015 * Returns 0 on success or ENOMEM on failure.
1017 int ice_add_mac_to_list(struct ice_vsi *vsi, struct list_head *add_list,
1020 struct ice_fltr_list_entry *tmp;
1021 struct ice_pf *pf = vsi->back;
1023 tmp = devm_kzalloc(&pf->pdev->dev, sizeof(*tmp), GFP_ATOMIC);
1027 tmp->fltr_info.flag = ICE_FLTR_TX;
1028 tmp->fltr_info.src_id = ICE_SRC_ID_VSI;
1029 tmp->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
1030 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1031 tmp->fltr_info.vsi_handle = vsi->idx;
1032 ether_addr_copy(tmp->fltr_info.l_data.mac.mac_addr, macaddr);
1034 INIT_LIST_HEAD(&tmp->list_entry);
1035 list_add(&tmp->list_entry, add_list);
1041 * ice_update_eth_stats - Update VSI-specific ethernet statistics counters
1042 * @vsi: the VSI to be updated
1044 void ice_update_eth_stats(struct ice_vsi *vsi)
1046 struct ice_eth_stats *prev_es, *cur_es;
1047 struct ice_hw *hw = &vsi->back->hw;
1048 u16 vsi_num = vsi->vsi_num; /* HW absolute index of a VSI */
1050 prev_es = &vsi->eth_stats_prev;
1051 cur_es = &vsi->eth_stats;
1053 ice_stat_update40(hw, GLV_GORCL(vsi_num), vsi->stat_offsets_loaded,
1054 &prev_es->rx_bytes, &cur_es->rx_bytes);
1056 ice_stat_update40(hw, GLV_UPRCL(vsi_num), vsi->stat_offsets_loaded,
1057 &prev_es->rx_unicast, &cur_es->rx_unicast);
1059 ice_stat_update40(hw, GLV_MPRCL(vsi_num), vsi->stat_offsets_loaded,
1060 &prev_es->rx_multicast, &cur_es->rx_multicast);
1062 ice_stat_update40(hw, GLV_BPRCL(vsi_num), vsi->stat_offsets_loaded,
1063 &prev_es->rx_broadcast, &cur_es->rx_broadcast);
1065 ice_stat_update32(hw, GLV_RDPC(vsi_num), vsi->stat_offsets_loaded,
1066 &prev_es->rx_discards, &cur_es->rx_discards);
1068 ice_stat_update40(hw, GLV_GOTCL(vsi_num), vsi->stat_offsets_loaded,
1069 &prev_es->tx_bytes, &cur_es->tx_bytes);
1071 ice_stat_update40(hw, GLV_UPTCL(vsi_num), vsi->stat_offsets_loaded,
1072 &prev_es->tx_unicast, &cur_es->tx_unicast);
1074 ice_stat_update40(hw, GLV_MPTCL(vsi_num), vsi->stat_offsets_loaded,
1075 &prev_es->tx_multicast, &cur_es->tx_multicast);
1077 ice_stat_update40(hw, GLV_BPTCL(vsi_num), vsi->stat_offsets_loaded,
1078 &prev_es->tx_broadcast, &cur_es->tx_broadcast);
1080 ice_stat_update32(hw, GLV_TEPC(vsi_num), vsi->stat_offsets_loaded,
1081 &prev_es->tx_errors, &cur_es->tx_errors);
1083 vsi->stat_offsets_loaded = true;
1087 * ice_free_fltr_list - free filter lists helper
1088 * @dev: pointer to the device struct
1089 * @h: pointer to the list head to be freed
1091 * Helper function to free filter lists previously created using
1092 * ice_add_mac_to_list
1094 void ice_free_fltr_list(struct device *dev, struct list_head *h)
1096 struct ice_fltr_list_entry *e, *tmp;
1098 list_for_each_entry_safe(e, tmp, h, list_entry) {
1099 list_del(&e->list_entry);
1105 * ice_vsi_add_vlan - Add VSI membership for given VLAN
1106 * @vsi: the VSI being configured
1107 * @vid: VLAN ID to be added
1109 int ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid)
1111 struct ice_fltr_list_entry *tmp;
1112 struct ice_pf *pf = vsi->back;
1113 LIST_HEAD(tmp_add_list);
1114 enum ice_status status;
1117 tmp = devm_kzalloc(&pf->pdev->dev, sizeof(*tmp), GFP_KERNEL);
1121 tmp->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
1122 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1123 tmp->fltr_info.flag = ICE_FLTR_TX;
1124 tmp->fltr_info.src_id = ICE_SRC_ID_VSI;
1125 tmp->fltr_info.vsi_handle = vsi->idx;
1126 tmp->fltr_info.l_data.vlan.vlan_id = vid;
1128 INIT_LIST_HEAD(&tmp->list_entry);
1129 list_add(&tmp->list_entry, &tmp_add_list);
1131 status = ice_add_vlan(&pf->hw, &tmp_add_list);
1134 dev_err(&pf->pdev->dev, "Failure Adding VLAN %d on VSI %i\n",
1138 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
1143 * ice_vsi_kill_vlan - Remove VSI membership for a given VLAN
1144 * @vsi: the VSI being configured
1145 * @vid: VLAN ID to be removed
1147 * Returns 0 on success and negative on failure
1149 int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid)
1151 struct ice_fltr_list_entry *list;
1152 struct ice_pf *pf = vsi->back;
1153 LIST_HEAD(tmp_add_list);
1154 enum ice_status status;
1157 list = devm_kzalloc(&pf->pdev->dev, sizeof(*list), GFP_KERNEL);
1161 list->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
1162 list->fltr_info.vsi_handle = vsi->idx;
1163 list->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1164 list->fltr_info.l_data.vlan.vlan_id = vid;
1165 list->fltr_info.flag = ICE_FLTR_TX;
1166 list->fltr_info.src_id = ICE_SRC_ID_VSI;
1168 INIT_LIST_HEAD(&list->list_entry);
1169 list_add(&list->list_entry, &tmp_add_list);
1171 status = ice_remove_vlan(&pf->hw, &tmp_add_list);
1172 if (status == ICE_ERR_DOES_NOT_EXIST) {
1173 dev_dbg(&pf->pdev->dev,
1174 "Failed to remove VLAN %d on VSI %i, it does not exist, status: %d\n",
1175 vid, vsi->vsi_num, status);
1176 } else if (status) {
1177 dev_err(&pf->pdev->dev,
1178 "Error removing VLAN %d on vsi %i error: %d\n",
1179 vid, vsi->vsi_num, status);
1183 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
1188 * ice_vsi_cfg_frame_size - setup max frame size and Rx buffer length
1191 void ice_vsi_cfg_frame_size(struct ice_vsi *vsi)
1193 if (!vsi->netdev || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags)) {
1194 vsi->max_frame = ICE_AQ_SET_MAC_FRAME_SIZE_MAX;
1195 vsi->rx_buf_len = ICE_RXBUF_2048;
1196 #if (PAGE_SIZE < 8192)
1197 } else if (!ICE_2K_TOO_SMALL_WITH_PADDING &&
1198 (vsi->netdev->mtu <= ETH_DATA_LEN)) {
1199 vsi->max_frame = ICE_RXBUF_1536 - NET_IP_ALIGN;
1200 vsi->rx_buf_len = ICE_RXBUF_1536 - NET_IP_ALIGN;
1203 vsi->max_frame = ICE_AQ_SET_MAC_FRAME_SIZE_MAX;
1204 #if (PAGE_SIZE < 8192)
1205 vsi->rx_buf_len = ICE_RXBUF_3072;
1207 vsi->rx_buf_len = ICE_RXBUF_2048;
1213 * ice_vsi_cfg_rxqs - Configure the VSI for Rx
1214 * @vsi: the VSI being configured
1216 * Return 0 on success and a negative value on error
1217 * Configure the Rx VSI for operation.
1219 int ice_vsi_cfg_rxqs(struct ice_vsi *vsi)
1223 if (vsi->type == ICE_VSI_VF)
1226 ice_vsi_cfg_frame_size(vsi);
1228 /* set up individual rings */
1229 for (i = 0; i < vsi->num_rxq; i++) {
1232 err = ice_setup_rx_ctx(vsi->rx_rings[i]);
1234 dev_err(&vsi->back->pdev->dev,
1235 "ice_setup_rx_ctx failed for RxQ %d, err %d\n",
1245 * ice_vsi_cfg_txqs - Configure the VSI for Tx
1246 * @vsi: the VSI being configured
1247 * @rings: Tx ring array to be configured
1249 * Return 0 on success and a negative value on error
1250 * Configure the Tx VSI for operation.
1253 ice_vsi_cfg_txqs(struct ice_vsi *vsi, struct ice_ring **rings)
1255 struct ice_aqc_add_tx_qgrp *qg_buf;
1259 qg_buf = kzalloc(sizeof(*qg_buf), GFP_KERNEL);
1263 qg_buf->num_txqs = 1;
1265 for (q_idx = 0; q_idx < vsi->num_txq; q_idx++) {
1266 err = ice_vsi_cfg_txq(vsi, rings[q_idx], qg_buf);
1277 * ice_vsi_cfg_lan_txqs - Configure the VSI for Tx
1278 * @vsi: the VSI being configured
1280 * Return 0 on success and a negative value on error
1281 * Configure the Tx VSI for operation.
1283 int ice_vsi_cfg_lan_txqs(struct ice_vsi *vsi)
1285 return ice_vsi_cfg_txqs(vsi, vsi->tx_rings);
1289 * ice_vsi_cfg_xdp_txqs - Configure Tx queues dedicated for XDP in given VSI
1290 * @vsi: the VSI being configured
1292 * Return 0 on success and a negative value on error
1293 * Configure the Tx queues dedicated for XDP in given VSI for operation.
1295 int ice_vsi_cfg_xdp_txqs(struct ice_vsi *vsi)
1300 ret = ice_vsi_cfg_txqs(vsi, vsi->xdp_rings);
1304 for (i = 0; i < vsi->num_xdp_txq; i++)
1305 vsi->xdp_rings[i]->xsk_umem = ice_xsk_umem(vsi->xdp_rings[i]);
1311 * ice_intrl_usec_to_reg - convert interrupt rate limit to register value
1312 * @intrl: interrupt rate limit in usecs
1313 * @gran: interrupt rate limit granularity in usecs
1315 * This function converts a decimal interrupt rate limit in usecs to the format
1316 * expected by firmware.
1318 u32 ice_intrl_usec_to_reg(u8 intrl, u8 gran)
1320 u32 val = intrl / gran;
1323 return val | GLINT_RATE_INTRL_ENA_M;
1328 * ice_vsi_cfg_msix - MSIX mode Interrupt Config in the HW
1329 * @vsi: the VSI being configured
1331 * This configures MSIX mode interrupts for the PF VSI, and should not be used
1334 void ice_vsi_cfg_msix(struct ice_vsi *vsi)
1336 struct ice_pf *pf = vsi->back;
1337 struct ice_hw *hw = &pf->hw;
1338 u32 txq = 0, rxq = 0;
1341 for (i = 0; i < vsi->num_q_vectors; i++) {
1342 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1343 u16 reg_idx = q_vector->reg_idx;
1345 ice_cfg_itr(hw, q_vector);
1347 wr32(hw, GLINT_RATE(reg_idx),
1348 ice_intrl_usec_to_reg(q_vector->intrl, hw->intrl_gran));
1350 /* Both Transmit Queue Interrupt Cause Control register
1351 * and Receive Queue Interrupt Cause control register
1352 * expects MSIX_INDX field to be the vector index
1353 * within the function space and not the absolute
1354 * vector index across PF or across device.
1355 * For SR-IOV VF VSIs queue vector index always starts
1356 * with 1 since first vector index(0) is used for OICR
1357 * in VF space. Since VMDq and other PF VSIs are within
1358 * the PF function space, use the vector index that is
1359 * tracked for this PF.
1361 for (q = 0; q < q_vector->num_ring_tx; q++) {
1362 ice_cfg_txq_interrupt(vsi, txq, reg_idx,
1363 q_vector->tx.itr_idx);
1367 for (q = 0; q < q_vector->num_ring_rx; q++) {
1368 ice_cfg_rxq_interrupt(vsi, rxq, reg_idx,
1369 q_vector->rx.itr_idx);
1376 * ice_vsi_manage_vlan_insertion - Manage VLAN insertion for the VSI for Tx
1377 * @vsi: the VSI being changed
1379 int ice_vsi_manage_vlan_insertion(struct ice_vsi *vsi)
1381 struct device *dev = &vsi->back->pdev->dev;
1382 struct ice_hw *hw = &vsi->back->hw;
1383 struct ice_vsi_ctx *ctxt;
1384 enum ice_status status;
1387 ctxt = devm_kzalloc(dev, sizeof(*ctxt), GFP_KERNEL);
1391 /* Here we are configuring the VSI to let the driver add VLAN tags by
1392 * setting vlan_flags to ICE_AQ_VSI_VLAN_MODE_ALL. The actual VLAN tag
1393 * insertion happens in the Tx hot path, in ice_tx_map.
1395 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_MODE_ALL;
1397 /* Preserve existing VLAN strip setting */
1398 ctxt->info.vlan_flags |= (vsi->info.vlan_flags &
1399 ICE_AQ_VSI_VLAN_EMOD_M);
1401 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
1403 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1405 dev_err(dev, "update VSI for VLAN insert failed, err %d aq_err %d\n",
1406 status, hw->adminq.sq_last_status);
1411 vsi->info.vlan_flags = ctxt->info.vlan_flags;
1413 devm_kfree(dev, ctxt);
1418 * ice_vsi_manage_vlan_stripping - Manage VLAN stripping for the VSI for Rx
1419 * @vsi: the VSI being changed
1420 * @ena: boolean value indicating if this is a enable or disable request
1422 int ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
1424 struct device *dev = &vsi->back->pdev->dev;
1425 struct ice_hw *hw = &vsi->back->hw;
1426 struct ice_vsi_ctx *ctxt;
1427 enum ice_status status;
1430 ctxt = devm_kzalloc(dev, sizeof(*ctxt), GFP_KERNEL);
1434 /* Here we are configuring what the VSI should do with the VLAN tag in
1435 * the Rx packet. We can either leave the tag in the packet or put it in
1436 * the Rx descriptor.
1439 /* Strip VLAN tag from Rx packet and put it in the desc */
1440 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_STR_BOTH;
1442 /* Disable stripping. Leave tag in packet */
1443 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_NOTHING;
1445 /* Allow all packets untagged/tagged */
1446 ctxt->info.vlan_flags |= ICE_AQ_VSI_VLAN_MODE_ALL;
1448 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
1450 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1452 dev_err(dev, "update VSI for VLAN strip failed, ena = %d err %d aq_err %d\n",
1453 ena, status, hw->adminq.sq_last_status);
1458 vsi->info.vlan_flags = ctxt->info.vlan_flags;
1460 devm_kfree(dev, ctxt);
1465 * ice_vsi_start_rx_rings - start VSI's Rx rings
1466 * @vsi: the VSI whose rings are to be started
1468 * Returns 0 on success and a negative value on error
1470 int ice_vsi_start_rx_rings(struct ice_vsi *vsi)
1472 return ice_vsi_ctrl_rx_rings(vsi, true);
1476 * ice_vsi_stop_rx_rings - stop VSI's Rx rings
1479 * Returns 0 on success and a negative value on error
1481 int ice_vsi_stop_rx_rings(struct ice_vsi *vsi)
1483 return ice_vsi_ctrl_rx_rings(vsi, false);
1487 * ice_vsi_stop_tx_rings - Disable Tx rings
1488 * @vsi: the VSI being configured
1489 * @rst_src: reset source
1490 * @rel_vmvf_num: Relative ID of VF/VM
1491 * @rings: Tx ring array to be stopped
1494 ice_vsi_stop_tx_rings(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
1495 u16 rel_vmvf_num, struct ice_ring **rings)
1499 if (vsi->num_txq > ICE_LAN_TXQ_MAX_QDIS)
1502 for (q_idx = 0; q_idx < vsi->num_txq; q_idx++) {
1503 struct ice_txq_meta txq_meta = { };
1506 if (!rings || !rings[q_idx])
1509 ice_fill_txq_meta(vsi, rings[q_idx], &txq_meta);
1510 status = ice_vsi_stop_tx_ring(vsi, rst_src, rel_vmvf_num,
1511 rings[q_idx], &txq_meta);
1521 * ice_vsi_stop_lan_tx_rings - Disable LAN Tx rings
1522 * @vsi: the VSI being configured
1523 * @rst_src: reset source
1524 * @rel_vmvf_num: Relative ID of VF/VM
1527 ice_vsi_stop_lan_tx_rings(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
1530 return ice_vsi_stop_tx_rings(vsi, rst_src, rel_vmvf_num, vsi->tx_rings);
1534 * ice_vsi_stop_xdp_tx_rings - Disable XDP Tx rings
1535 * @vsi: the VSI being configured
1537 int ice_vsi_stop_xdp_tx_rings(struct ice_vsi *vsi)
1539 return ice_vsi_stop_tx_rings(vsi, ICE_NO_RESET, 0, vsi->xdp_rings);
1543 * ice_cfg_vlan_pruning - enable or disable VLAN pruning on the VSI
1544 * @vsi: VSI to enable or disable VLAN pruning on
1545 * @ena: set to true to enable VLAN pruning and false to disable it
1546 * @vlan_promisc: enable valid security flags if not in VLAN promiscuous mode
1548 * returns 0 if VSI is updated, negative otherwise
1550 int ice_cfg_vlan_pruning(struct ice_vsi *vsi, bool ena, bool vlan_promisc)
1552 struct ice_vsi_ctx *ctxt;
1561 dev = &pf->pdev->dev;
1562 ctxt = devm_kzalloc(dev, sizeof(*ctxt), GFP_KERNEL);
1566 ctxt->info = vsi->info;
1569 ctxt->info.sec_flags |=
1570 ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
1571 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S;
1572 ctxt->info.sw_flags2 |= ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
1574 ctxt->info.sec_flags &=
1575 ~(ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
1576 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S);
1577 ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
1581 ctxt->info.valid_sections =
1582 cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID |
1583 ICE_AQ_VSI_PROP_SW_VALID);
1585 status = ice_update_vsi(&pf->hw, vsi->idx, ctxt, NULL);
1587 netdev_err(vsi->netdev, "%sabling VLAN pruning on VSI handle: %d, VSI HW ID: %d failed, err = %d, aq_err = %d\n",
1588 ena ? "En" : "Dis", vsi->idx, vsi->vsi_num, status,
1589 pf->hw.adminq.sq_last_status);
1593 vsi->info.sec_flags = ctxt->info.sec_flags;
1594 vsi->info.sw_flags2 = ctxt->info.sw_flags2;
1596 devm_kfree(dev, ctxt);
1600 devm_kfree(dev, ctxt);
1604 static void ice_vsi_set_tc_cfg(struct ice_vsi *vsi)
1606 struct ice_dcbx_cfg *cfg = &vsi->port_info->local_dcbx_cfg;
1608 vsi->tc_cfg.ena_tc = ice_dcb_get_ena_tc(cfg);
1609 vsi->tc_cfg.numtc = ice_dcb_get_num_tc(cfg);
1613 * ice_vsi_set_q_vectors_reg_idx - set the HW register index for all q_vectors
1614 * @vsi: VSI to set the q_vectors register index on
1617 ice_vsi_set_q_vectors_reg_idx(struct ice_vsi *vsi)
1621 if (!vsi || !vsi->q_vectors)
1624 ice_for_each_q_vector(vsi, i) {
1625 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1628 dev_err(&vsi->back->pdev->dev,
1629 "Failed to set reg_idx on q_vector %d VSI %d\n",
1634 if (vsi->type == ICE_VSI_VF) {
1635 struct ice_vf *vf = &vsi->back->vf[vsi->vf_id];
1637 q_vector->reg_idx = ice_calc_vf_reg_idx(vf, q_vector);
1640 q_vector->v_idx + vsi->base_vector;
1647 ice_for_each_q_vector(vsi, i) {
1648 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1651 q_vector->reg_idx = 0;
1658 * ice_vsi_add_rem_eth_mac - Program VSI ethertype based filter with rule
1659 * @vsi: the VSI being configured
1660 * @add_rule: boolean value to add or remove ethertype filter rule
1663 ice_vsi_add_rem_eth_mac(struct ice_vsi *vsi, bool add_rule)
1665 struct ice_fltr_list_entry *list;
1666 struct ice_pf *pf = vsi->back;
1667 LIST_HEAD(tmp_add_list);
1668 enum ice_status status;
1670 list = devm_kzalloc(&pf->pdev->dev, sizeof(*list), GFP_KERNEL);
1674 list->fltr_info.lkup_type = ICE_SW_LKUP_ETHERTYPE;
1675 list->fltr_info.fltr_act = ICE_DROP_PACKET;
1676 list->fltr_info.flag = ICE_FLTR_TX;
1677 list->fltr_info.src_id = ICE_SRC_ID_VSI;
1678 list->fltr_info.vsi_handle = vsi->idx;
1679 list->fltr_info.l_data.ethertype_mac.ethertype = vsi->ethtype;
1681 INIT_LIST_HEAD(&list->list_entry);
1682 list_add(&list->list_entry, &tmp_add_list);
1685 status = ice_add_eth_mac(&pf->hw, &tmp_add_list);
1687 status = ice_remove_eth_mac(&pf->hw, &tmp_add_list);
1690 dev_err(&pf->pdev->dev,
1691 "Failure Adding or Removing Ethertype on VSI %i error: %d\n",
1692 vsi->vsi_num, status);
1694 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
1698 * ice_cfg_sw_lldp - Config switch rules for LLDP packet handling
1699 * @vsi: the VSI being configured
1700 * @tx: bool to determine Tx or Rx rule
1701 * @create: bool to determine create or remove Rule
1703 void ice_cfg_sw_lldp(struct ice_vsi *vsi, bool tx, bool create)
1705 struct ice_fltr_list_entry *list;
1706 struct ice_pf *pf = vsi->back;
1707 LIST_HEAD(tmp_add_list);
1708 enum ice_status status;
1710 list = devm_kzalloc(&pf->pdev->dev, sizeof(*list), GFP_KERNEL);
1714 list->fltr_info.lkup_type = ICE_SW_LKUP_ETHERTYPE;
1715 list->fltr_info.vsi_handle = vsi->idx;
1716 list->fltr_info.l_data.ethertype_mac.ethertype = ETH_P_LLDP;
1719 list->fltr_info.fltr_act = ICE_DROP_PACKET;
1720 list->fltr_info.flag = ICE_FLTR_TX;
1721 list->fltr_info.src_id = ICE_SRC_ID_VSI;
1723 list->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1724 list->fltr_info.flag = ICE_FLTR_RX;
1725 list->fltr_info.src_id = ICE_SRC_ID_LPORT;
1728 INIT_LIST_HEAD(&list->list_entry);
1729 list_add(&list->list_entry, &tmp_add_list);
1732 status = ice_add_eth_mac(&pf->hw, &tmp_add_list);
1734 status = ice_remove_eth_mac(&pf->hw, &tmp_add_list);
1737 dev_err(&pf->pdev->dev,
1738 "Fail %s %s LLDP rule on VSI %i error: %d\n",
1739 create ? "adding" : "removing", tx ? "TX" : "RX",
1740 vsi->vsi_num, status);
1742 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
1746 * ice_vsi_setup - Set up a VSI by a given type
1747 * @pf: board private structure
1748 * @pi: pointer to the port_info instance
1750 * @vf_id: defines VF ID to which this VSI connects. This field is meant to be
1751 * used only for ICE_VSI_VF VSI type. For other VSI types, should
1752 * fill-in ICE_INVAL_VFID as input.
1754 * This allocates the sw VSI structure and its queue resources.
1756 * Returns pointer to the successfully allocated and configured VSI sw struct on
1757 * success, NULL on failure.
1760 ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
1761 enum ice_vsi_type type, u16 vf_id)
1763 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1764 struct device *dev = &pf->pdev->dev;
1765 enum ice_status status;
1766 struct ice_vsi *vsi;
1769 if (type == ICE_VSI_VF)
1770 vsi = ice_vsi_alloc(pf, type, vf_id);
1772 vsi = ice_vsi_alloc(pf, type, ICE_INVAL_VFID);
1775 dev_err(dev, "could not allocate VSI\n");
1779 vsi->port_info = pi;
1780 vsi->vsw = pf->first_sw;
1781 if (vsi->type == ICE_VSI_PF)
1782 vsi->ethtype = ETH_P_PAUSE;
1784 if (vsi->type == ICE_VSI_VF)
1787 if (ice_vsi_get_qs(vsi)) {
1788 dev_err(dev, "Failed to allocate queues. vsi->idx = %d\n",
1793 /* set RSS capabilities */
1794 ice_vsi_set_rss_params(vsi);
1796 /* set TC configuration */
1797 ice_vsi_set_tc_cfg(vsi);
1799 /* create the VSI */
1800 ret = ice_vsi_init(vsi);
1804 switch (vsi->type) {
1806 ret = ice_vsi_alloc_q_vectors(vsi);
1808 goto unroll_vsi_init;
1810 ret = ice_vsi_setup_vector_base(vsi);
1812 goto unroll_alloc_q_vector;
1814 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
1816 goto unroll_vector_base;
1818 ret = ice_vsi_alloc_rings(vsi);
1820 goto unroll_vector_base;
1822 ice_vsi_map_rings_to_vectors(vsi);
1824 /* Do not exit if configuring RSS had an issue, at least
1825 * receive traffic on first queue. Hence no need to capture
1828 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
1829 ice_vsi_cfg_rss_lut_key(vsi);
1832 /* VF driver will take care of creating netdev for this type and
1833 * map queues to vectors through Virtchnl, PF driver only
1834 * creates a VSI and corresponding structures for bookkeeping
1837 ret = ice_vsi_alloc_q_vectors(vsi);
1839 goto unroll_vsi_init;
1841 ret = ice_vsi_alloc_rings(vsi);
1843 goto unroll_alloc_q_vector;
1845 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
1847 goto unroll_vector_base;
1849 /* Do not exit if configuring RSS had an issue, at least
1850 * receive traffic on first queue. Hence no need to capture
1853 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
1854 ice_vsi_cfg_rss_lut_key(vsi);
1857 ret = ice_vsi_alloc_rings(vsi);
1859 goto unroll_vsi_init;
1862 /* clean up the resources and exit */
1863 goto unroll_vsi_init;
1866 /* configure VSI nodes based on number of queues and TC's */
1867 for (i = 0; i < vsi->tc_cfg.numtc; i++)
1868 max_txqs[i] = vsi->alloc_txq;
1870 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
1873 dev_err(&pf->pdev->dev,
1874 "VSI %d failed lan queue config, error %d\n",
1875 vsi->vsi_num, status);
1876 goto unroll_vector_base;
1879 /* Add switch rule to drop all Tx Flow Control Frames, of look up
1880 * type ETHERTYPE from VSIs, and restrict malicious VF from sending
1881 * out PAUSE or PFC frames. If enabled, FW can still send FC frames.
1882 * The rule is added once for PF VSI in order to create appropriate
1883 * recipe, since VSI/VSI list is ignored with drop action...
1884 * Also add rules to handle LLDP Tx packets. Tx LLDP packets need to
1885 * be dropped so that VFs cannot send LLDP packets to reconfig DCB
1886 * settings in the HW.
1888 if (!ice_is_safe_mode(pf))
1889 if (vsi->type == ICE_VSI_PF) {
1890 ice_vsi_add_rem_eth_mac(vsi, true);
1892 /* Tx LLDP packets */
1893 ice_cfg_sw_lldp(vsi, true, true);
1899 /* reclaim SW interrupts back to the common pool */
1900 ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
1901 pf->num_avail_sw_msix += vsi->num_q_vectors;
1902 unroll_alloc_q_vector:
1903 ice_vsi_free_q_vectors(vsi);
1905 ice_vsi_delete(vsi);
1907 ice_vsi_put_qs(vsi);
1914 * ice_vsi_release_msix - Clear the queue to Interrupt mapping in HW
1915 * @vsi: the VSI being cleaned up
1917 static void ice_vsi_release_msix(struct ice_vsi *vsi)
1919 struct ice_pf *pf = vsi->back;
1920 struct ice_hw *hw = &pf->hw;
1925 for (i = 0; i < vsi->num_q_vectors; i++) {
1926 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1927 u16 reg_idx = q_vector->reg_idx;
1929 wr32(hw, GLINT_ITR(ICE_IDX_ITR0, reg_idx), 0);
1930 wr32(hw, GLINT_ITR(ICE_IDX_ITR1, reg_idx), 0);
1931 for (q = 0; q < q_vector->num_ring_tx; q++) {
1932 wr32(hw, QINT_TQCTL(vsi->txq_map[txq]), 0);
1933 if (ice_is_xdp_ena_vsi(vsi)) {
1934 u32 xdp_txq = txq + vsi->num_xdp_txq;
1936 wr32(hw, QINT_TQCTL(vsi->txq_map[xdp_txq]), 0);
1941 for (q = 0; q < q_vector->num_ring_rx; q++) {
1942 wr32(hw, QINT_RQCTL(vsi->rxq_map[rxq]), 0);
1951 * ice_vsi_free_irq - Free the IRQ association with the OS
1952 * @vsi: the VSI being configured
1954 void ice_vsi_free_irq(struct ice_vsi *vsi)
1956 struct ice_pf *pf = vsi->back;
1957 int base = vsi->base_vector;
1960 if (!vsi->q_vectors || !vsi->irqs_ready)
1963 ice_vsi_release_msix(vsi);
1964 if (vsi->type == ICE_VSI_VF)
1967 vsi->irqs_ready = false;
1968 ice_for_each_q_vector(vsi, i) {
1969 u16 vector = i + base;
1972 irq_num = pf->msix_entries[vector].vector;
1974 /* free only the irqs that were actually requested */
1975 if (!vsi->q_vectors[i] ||
1976 !(vsi->q_vectors[i]->num_ring_tx ||
1977 vsi->q_vectors[i]->num_ring_rx))
1980 /* clear the affinity notifier in the IRQ descriptor */
1981 irq_set_affinity_notifier(irq_num, NULL);
1983 /* clear the affinity_mask in the IRQ descriptor */
1984 irq_set_affinity_hint(irq_num, NULL);
1985 synchronize_irq(irq_num);
1986 devm_free_irq(&pf->pdev->dev, irq_num,
1992 * ice_vsi_free_tx_rings - Free Tx resources for VSI queues
1993 * @vsi: the VSI having resources freed
1995 void ice_vsi_free_tx_rings(struct ice_vsi *vsi)
2002 ice_for_each_txq(vsi, i)
2003 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
2004 ice_free_tx_ring(vsi->tx_rings[i]);
2008 * ice_vsi_free_rx_rings - Free Rx resources for VSI queues
2009 * @vsi: the VSI having resources freed
2011 void ice_vsi_free_rx_rings(struct ice_vsi *vsi)
2018 ice_for_each_rxq(vsi, i)
2019 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
2020 ice_free_rx_ring(vsi->rx_rings[i]);
2024 * ice_vsi_close - Shut down a VSI
2025 * @vsi: the VSI being shut down
2027 void ice_vsi_close(struct ice_vsi *vsi)
2029 if (!test_and_set_bit(__ICE_DOWN, vsi->state))
2032 ice_vsi_free_irq(vsi);
2033 ice_vsi_free_tx_rings(vsi);
2034 ice_vsi_free_rx_rings(vsi);
2038 * ice_ena_vsi - resume a VSI
2039 * @vsi: the VSI being resume
2040 * @locked: is the rtnl_lock already held
2042 int ice_ena_vsi(struct ice_vsi *vsi, bool locked)
2046 if (!test_bit(__ICE_NEEDS_RESTART, vsi->state))
2049 clear_bit(__ICE_NEEDS_RESTART, vsi->state);
2051 if (vsi->netdev && vsi->type == ICE_VSI_PF) {
2052 if (netif_running(vsi->netdev)) {
2056 err = ice_open(vsi->netdev);
2067 * ice_dis_vsi - pause a VSI
2068 * @vsi: the VSI being paused
2069 * @locked: is the rtnl_lock already held
2071 void ice_dis_vsi(struct ice_vsi *vsi, bool locked)
2073 if (test_bit(__ICE_DOWN, vsi->state))
2076 set_bit(__ICE_NEEDS_RESTART, vsi->state);
2078 if (vsi->type == ICE_VSI_PF && vsi->netdev) {
2079 if (netif_running(vsi->netdev)) {
2083 ice_stop(vsi->netdev);
2094 * ice_free_res - free a block of resources
2095 * @res: pointer to the resource
2096 * @index: starting index previously returned by ice_get_res
2097 * @id: identifier to track owner
2099 * Returns number of resources freed
2101 int ice_free_res(struct ice_res_tracker *res, u16 index, u16 id)
2106 if (!res || index >= res->end)
2109 id |= ICE_RES_VALID_BIT;
2110 for (i = index; i < res->end && res->list[i] == id; i++) {
2119 * ice_search_res - Search the tracker for a block of resources
2120 * @res: pointer to the resource
2121 * @needed: size of the block needed
2122 * @id: identifier to track owner
2124 * Returns the base item index of the block, or -ENOMEM for error
2126 static int ice_search_res(struct ice_res_tracker *res, u16 needed, u16 id)
2128 int start = 0, end = 0;
2130 if (needed > res->end)
2133 id |= ICE_RES_VALID_BIT;
2136 /* skip already allocated entries */
2137 if (res->list[end++] & ICE_RES_VALID_BIT) {
2139 if ((start + needed) > res->end)
2143 if (end == (start + needed)) {
2146 /* there was enough, so assign it to the requestor */
2148 res->list[i++] = id;
2152 } while (end < res->end);
2158 * ice_get_res - get a block of resources
2159 * @pf: board private structure
2160 * @res: pointer to the resource
2161 * @needed: size of the block needed
2162 * @id: identifier to track owner
2164 * Returns the base item index of the block, or negative for error
2167 ice_get_res(struct ice_pf *pf, struct ice_res_tracker *res, u16 needed, u16 id)
2172 if (!needed || needed > res->num_entries || id >= ICE_RES_VALID_BIT) {
2173 dev_err(&pf->pdev->dev,
2174 "param err: needed=%d, num_entries = %d id=0x%04x\n",
2175 needed, res->num_entries, id);
2179 return ice_search_res(res, needed, id);
2183 * ice_vsi_dis_irq - Mask off queue interrupt generation on the VSI
2184 * @vsi: the VSI being un-configured
2186 void ice_vsi_dis_irq(struct ice_vsi *vsi)
2188 int base = vsi->base_vector;
2189 struct ice_pf *pf = vsi->back;
2190 struct ice_hw *hw = &pf->hw;
2194 /* disable interrupt causation from each queue */
2195 if (vsi->tx_rings) {
2196 ice_for_each_txq(vsi, i) {
2197 if (vsi->tx_rings[i]) {
2200 reg = vsi->tx_rings[i]->reg_idx;
2201 val = rd32(hw, QINT_TQCTL(reg));
2202 val &= ~QINT_TQCTL_CAUSE_ENA_M;
2203 wr32(hw, QINT_TQCTL(reg), val);
2208 if (vsi->rx_rings) {
2209 ice_for_each_rxq(vsi, i) {
2210 if (vsi->rx_rings[i]) {
2213 reg = vsi->rx_rings[i]->reg_idx;
2214 val = rd32(hw, QINT_RQCTL(reg));
2215 val &= ~QINT_RQCTL_CAUSE_ENA_M;
2216 wr32(hw, QINT_RQCTL(reg), val);
2221 /* disable each interrupt */
2222 ice_for_each_q_vector(vsi, i) {
2223 if (!vsi->q_vectors[i])
2225 wr32(hw, GLINT_DYN_CTL(vsi->q_vectors[i]->reg_idx), 0);
2230 /* don't call synchronize_irq() for VF's from the host */
2231 if (vsi->type == ICE_VSI_VF)
2234 ice_for_each_q_vector(vsi, i)
2235 synchronize_irq(pf->msix_entries[i + base].vector);
2239 * ice_napi_del - Remove NAPI handler for the VSI
2240 * @vsi: VSI for which NAPI handler is to be removed
2242 void ice_napi_del(struct ice_vsi *vsi)
2249 ice_for_each_q_vector(vsi, v_idx)
2250 netif_napi_del(&vsi->q_vectors[v_idx]->napi);
2254 * ice_vsi_release - Delete a VSI and free its resources
2255 * @vsi: the VSI being removed
2257 * Returns 0 on success or < 0 on error
2259 int ice_vsi_release(struct ice_vsi *vsi)
2267 /* do not unregister while driver is in the reset recovery pending
2268 * state. Since reset/rebuild happens through PF service task workqueue,
2269 * it's not a good idea to unregister netdev that is associated to the
2270 * PF that is running the work queue items currently. This is done to
2271 * avoid check_flush_dependency() warning on this wq
2273 if (vsi->netdev && !ice_is_reset_in_progress(pf->state))
2274 unregister_netdev(vsi->netdev);
2276 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2279 /* Disable VSI and free resources */
2280 if (vsi->type != ICE_VSI_LB)
2281 ice_vsi_dis_irq(vsi);
2284 /* SR-IOV determines needed MSIX resources all at once instead of per
2285 * VSI since when VFs are spawned we know how many VFs there are and how
2286 * many interrupts each VF needs. SR-IOV MSIX resources are also
2287 * cleared in the same manner.
2289 if (vsi->type != ICE_VSI_VF) {
2290 /* reclaim SW interrupts back to the common pool */
2291 ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
2292 pf->num_avail_sw_msix += vsi->num_q_vectors;
2295 if (!ice_is_safe_mode(pf)) {
2296 if (vsi->type == ICE_VSI_PF) {
2297 ice_vsi_add_rem_eth_mac(vsi, false);
2298 ice_cfg_sw_lldp(vsi, true, false);
2299 /* The Rx rule will only exist to remove if the LLDP FW
2300 * engine is currently stopped
2302 if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags))
2303 ice_cfg_sw_lldp(vsi, false, false);
2307 ice_remove_vsi_fltr(&pf->hw, vsi->idx);
2308 ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx);
2309 ice_vsi_delete(vsi);
2310 ice_vsi_free_q_vectors(vsi);
2312 /* make sure unregister_netdev() was called by checking __ICE_DOWN */
2313 if (vsi->netdev && test_bit(__ICE_DOWN, vsi->state)) {
2314 free_netdev(vsi->netdev);
2318 ice_vsi_clear_rings(vsi);
2320 ice_vsi_put_qs(vsi);
2322 /* retain SW VSI data structure since it is needed to unregister and
2323 * free VSI netdev when PF is not in reset recovery pending state,\
2324 * for ex: during rmmod.
2326 if (!ice_is_reset_in_progress(pf->state))
2333 * ice_vsi_rebuild - Rebuild VSI after reset
2334 * @vsi: VSI to be rebuild
2336 * Returns 0 on success and negative value on failure
2338 int ice_vsi_rebuild(struct ice_vsi *vsi)
2340 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2341 struct ice_vf *vf = NULL;
2342 enum ice_status status;
2350 if (vsi->type == ICE_VSI_VF)
2351 vf = &pf->vf[vsi->vf_id];
2353 ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx);
2354 ice_vsi_free_q_vectors(vsi);
2356 /* SR-IOV determines needed MSIX resources all at once instead of per
2357 * VSI since when VFs are spawned we know how many VFs there are and how
2358 * many interrupts each VF needs. SR-IOV MSIX resources are also
2359 * cleared in the same manner.
2361 if (vsi->type != ICE_VSI_VF) {
2362 /* reclaim SW interrupts back to the common pool */
2363 ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
2364 pf->num_avail_sw_msix += vsi->num_q_vectors;
2365 vsi->base_vector = 0;
2368 if (ice_is_xdp_ena_vsi(vsi))
2369 /* return value check can be skipped here, it always returns
2370 * 0 if reset is in progress
2372 ice_destroy_xdp_rings(vsi);
2373 ice_vsi_put_qs(vsi);
2374 ice_vsi_clear_rings(vsi);
2375 ice_vsi_free_arrays(vsi);
2376 ice_dev_onetime_setup(&pf->hw);
2377 if (vsi->type == ICE_VSI_VF)
2378 ice_vsi_set_num_qs(vsi, vf->vf_id);
2380 ice_vsi_set_num_qs(vsi, ICE_INVAL_VFID);
2382 ret = ice_vsi_alloc_arrays(vsi);
2386 ice_vsi_get_qs(vsi);
2387 ice_vsi_set_tc_cfg(vsi);
2389 /* Initialize VSI struct elements and create VSI in FW */
2390 ret = ice_vsi_init(vsi);
2394 switch (vsi->type) {
2396 ret = ice_vsi_alloc_q_vectors(vsi);
2400 ret = ice_vsi_setup_vector_base(vsi);
2404 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2408 ret = ice_vsi_alloc_rings(vsi);
2412 ice_vsi_map_rings_to_vectors(vsi);
2413 if (ice_is_xdp_ena_vsi(vsi)) {
2414 vsi->num_xdp_txq = vsi->alloc_txq;
2415 ret = ice_prepare_xdp_rings(vsi, vsi->xdp_prog);
2419 /* Do not exit if configuring RSS had an issue, at least
2420 * receive traffic on first queue. Hence no need to capture
2423 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2424 ice_vsi_cfg_rss_lut_key(vsi);
2427 ret = ice_vsi_alloc_q_vectors(vsi);
2431 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2435 ret = ice_vsi_alloc_rings(vsi);
2444 /* configure VSI nodes based on number of queues and TC's */
2445 for (i = 0; i < vsi->tc_cfg.numtc; i++) {
2446 max_txqs[i] = vsi->alloc_txq;
2448 if (ice_is_xdp_ena_vsi(vsi))
2449 max_txqs[i] += vsi->num_xdp_txq;
2452 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2455 dev_err(&pf->pdev->dev,
2456 "VSI %d failed lan queue config, error %d\n",
2457 vsi->vsi_num, status);
2463 ice_vsi_free_q_vectors(vsi);
2466 vsi->current_netdev_flags = 0;
2467 unregister_netdev(vsi->netdev);
2468 free_netdev(vsi->netdev);
2473 set_bit(__ICE_RESET_FAILED, pf->state);
2478 * ice_is_reset_in_progress - check for a reset in progress
2479 * @state: PF state field
2481 bool ice_is_reset_in_progress(unsigned long *state)
2483 return test_bit(__ICE_RESET_OICR_RECV, state) ||
2484 test_bit(__ICE_DCBNL_DEVRESET, state) ||
2485 test_bit(__ICE_PFR_REQ, state) ||
2486 test_bit(__ICE_CORER_REQ, state) ||
2487 test_bit(__ICE_GLOBR_REQ, state);
2492 * ice_vsi_update_q_map - update our copy of the VSI info with new queue map
2493 * @vsi: VSI being configured
2494 * @ctx: the context buffer returned from AQ VSI update command
2496 static void ice_vsi_update_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctx)
2498 vsi->info.mapping_flags = ctx->info.mapping_flags;
2499 memcpy(&vsi->info.q_mapping, &ctx->info.q_mapping,
2500 sizeof(vsi->info.q_mapping));
2501 memcpy(&vsi->info.tc_mapping, ctx->info.tc_mapping,
2502 sizeof(vsi->info.tc_mapping));
2506 * ice_vsi_cfg_tc - Configure VSI Tx Sched for given TC map
2507 * @vsi: VSI to be configured
2508 * @ena_tc: TC bitmap
2510 * VSI queues expected to be quiesced before calling this function
2512 int ice_vsi_cfg_tc(struct ice_vsi *vsi, u8 ena_tc)
2514 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2515 struct ice_vsi_ctx *ctx;
2516 struct ice_pf *pf = vsi->back;
2517 enum ice_status status;
2521 ice_for_each_traffic_class(i) {
2522 /* build bitmap of enabled TCs */
2523 if (ena_tc & BIT(i))
2525 /* populate max_txqs per TC */
2526 max_txqs[i] = vsi->alloc_txq;
2529 vsi->tc_cfg.ena_tc = ena_tc;
2530 vsi->tc_cfg.numtc = num_tc;
2532 ctx = devm_kzalloc(&pf->pdev->dev, sizeof(*ctx), GFP_KERNEL);
2537 ctx->info = vsi->info;
2539 ice_vsi_setup_q_map(vsi, ctx);
2541 /* must to indicate which section of VSI context are being modified */
2542 ctx->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
2543 status = ice_update_vsi(&pf->hw, vsi->idx, ctx, NULL);
2545 dev_info(&pf->pdev->dev, "Failed VSI Update\n");
2550 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2554 dev_err(&pf->pdev->dev,
2555 "VSI %d failed TC config, error %d\n",
2556 vsi->vsi_num, status);
2560 ice_vsi_update_q_map(vsi, ctx);
2561 vsi->info.valid_sections = 0;
2563 ice_vsi_cfg_netdev_tc(vsi, ena_tc);
2565 devm_kfree(&pf->pdev->dev, ctx);
2568 #endif /* CONFIG_DCB */
2571 * ice_nvm_version_str - format the NVM version strings
2572 * @hw: ptr to the hardware info
2574 char *ice_nvm_version_str(struct ice_hw *hw)
2576 u8 oem_ver, oem_patch, ver_hi, ver_lo;
2577 static char buf[ICE_NVM_VER_LEN];
2580 ice_get_nvm_version(hw, &oem_ver, &oem_build, &oem_patch, &ver_hi,
2583 snprintf(buf, sizeof(buf), "%x.%02x 0x%x %d.%d.%d", ver_hi, ver_lo,
2584 hw->nvm.eetrack, oem_ver, oem_build, oem_patch);
2590 * ice_update_ring_stats - Update ring statistics
2591 * @ring: ring to update
2592 * @cont: used to increment per-vector counters
2593 * @pkts: number of processed packets
2594 * @bytes: number of processed bytes
2596 * This function assumes that caller has acquired a u64_stats_sync lock.
2599 ice_update_ring_stats(struct ice_ring *ring, struct ice_ring_container *cont,
2600 u64 pkts, u64 bytes)
2602 ring->stats.bytes += bytes;
2603 ring->stats.pkts += pkts;
2604 cont->total_bytes += bytes;
2605 cont->total_pkts += pkts;
2609 * ice_update_tx_ring_stats - Update Tx ring specific counters
2610 * @tx_ring: ring to update
2611 * @pkts: number of processed packets
2612 * @bytes: number of processed bytes
2614 void ice_update_tx_ring_stats(struct ice_ring *tx_ring, u64 pkts, u64 bytes)
2616 u64_stats_update_begin(&tx_ring->syncp);
2617 ice_update_ring_stats(tx_ring, &tx_ring->q_vector->tx, pkts, bytes);
2618 u64_stats_update_end(&tx_ring->syncp);
2622 * ice_update_rx_ring_stats - Update Rx ring specific counters
2623 * @rx_ring: ring to update
2624 * @pkts: number of processed packets
2625 * @bytes: number of processed bytes
2627 void ice_update_rx_ring_stats(struct ice_ring *rx_ring, u64 pkts, u64 bytes)
2629 u64_stats_update_begin(&rx_ring->syncp);
2630 ice_update_ring_stats(rx_ring, &rx_ring->q_vector->rx, pkts, bytes);
2631 u64_stats_update_end(&rx_ring->syncp);
2635 * ice_vsi_cfg_mac_fltr - Add or remove a MAC address filter for a VSI
2636 * @vsi: the VSI being configured MAC filter
2637 * @macaddr: the MAC address to be added.
2638 * @set: Add or delete a MAC filter
2640 * Adds or removes MAC address filter entry for VF VSI
2643 ice_vsi_cfg_mac_fltr(struct ice_vsi *vsi, const u8 *macaddr, bool set)
2645 LIST_HEAD(tmp_add_list);
2646 enum ice_status status;
2648 /* Update MAC filter list to be added or removed for a VSI */
2649 if (ice_add_mac_to_list(vsi, &tmp_add_list, macaddr)) {
2650 status = ICE_ERR_NO_MEMORY;
2651 goto cfg_mac_fltr_exit;
2655 status = ice_add_mac(&vsi->back->hw, &tmp_add_list);
2657 status = ice_remove_mac(&vsi->back->hw, &tmp_add_list);
2660 ice_free_fltr_list(&vsi->back->pdev->dev, &tmp_add_list);