1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
9 #include "ice_dcb_lib.h"
12 * ice_vsi_type_str - maps VSI type enum to string equivalents
13 * @vsi_type: VSI type enum
15 const char *ice_vsi_type_str(enum ice_vsi_type vsi_type)
23 return "ICE_VSI_CTRL";
32 * ice_vsi_ctrl_all_rx_rings - Start or stop a VSI's Rx rings
33 * @vsi: the VSI being configured
34 * @ena: start or stop the Rx rings
36 * First enable/disable all of the Rx rings, flush any remaining writes, and
37 * then verify that they have all been enabled/disabled successfully. This will
38 * let all of the register writes complete when enabling/disabling the Rx rings
39 * before waiting for the change in hardware to complete.
41 static int ice_vsi_ctrl_all_rx_rings(struct ice_vsi *vsi, bool ena)
46 for (i = 0; i < vsi->num_rxq; i++)
47 ice_vsi_ctrl_one_rx_ring(vsi, ena, i, false);
49 ice_flush(&vsi->back->hw);
51 for (i = 0; i < vsi->num_rxq; i++) {
52 ret = ice_vsi_wait_one_rx_ring(vsi, ena, i);
61 * ice_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the VSI
64 * On error: returns error code (negative)
65 * On success: returns 0
67 static int ice_vsi_alloc_arrays(struct ice_vsi *vsi)
69 struct ice_pf *pf = vsi->back;
72 dev = ice_pf_to_dev(pf);
74 /* allocate memory for both Tx and Rx ring pointers */
75 vsi->tx_rings = devm_kcalloc(dev, vsi->alloc_txq,
76 sizeof(*vsi->tx_rings), GFP_KERNEL);
80 vsi->rx_rings = devm_kcalloc(dev, vsi->alloc_rxq,
81 sizeof(*vsi->rx_rings), GFP_KERNEL);
85 /* XDP will have vsi->alloc_txq Tx queues as well, so double the size */
86 vsi->txq_map = devm_kcalloc(dev, (2 * vsi->alloc_txq),
87 sizeof(*vsi->txq_map), GFP_KERNEL);
92 vsi->rxq_map = devm_kcalloc(dev, vsi->alloc_rxq,
93 sizeof(*vsi->rxq_map), GFP_KERNEL);
97 /* There is no need to allocate q_vectors for a loopback VSI. */
98 if (vsi->type == ICE_VSI_LB)
101 /* allocate memory for q_vector pointers */
102 vsi->q_vectors = devm_kcalloc(dev, vsi->num_q_vectors,
103 sizeof(*vsi->q_vectors), GFP_KERNEL);
110 devm_kfree(dev, vsi->rxq_map);
112 devm_kfree(dev, vsi->txq_map);
114 devm_kfree(dev, vsi->rx_rings);
116 devm_kfree(dev, vsi->tx_rings);
121 * ice_vsi_set_num_desc - Set number of descriptors for queues on this VSI
122 * @vsi: the VSI being configured
124 static void ice_vsi_set_num_desc(struct ice_vsi *vsi)
130 /* a user could change the values of num_[tr]x_desc using
131 * ethtool -G so we should keep those values instead of
132 * overwriting them with the defaults.
134 if (!vsi->num_rx_desc)
135 vsi->num_rx_desc = ICE_DFLT_NUM_RX_DESC;
136 if (!vsi->num_tx_desc)
137 vsi->num_tx_desc = ICE_DFLT_NUM_TX_DESC;
140 dev_dbg(ice_pf_to_dev(vsi->back), "Not setting number of Tx/Rx descriptors for VSI type %d\n",
147 * ice_vsi_set_num_qs - Set number of queues, descriptors and vectors for a VSI
148 * @vsi: the VSI being configured
149 * @vf_id: ID of the VF being configured
151 * Return 0 on success and a negative value on error
153 static void ice_vsi_set_num_qs(struct ice_vsi *vsi, u16 vf_id)
155 struct ice_pf *pf = vsi->back;
156 struct ice_vf *vf = NULL;
158 if (vsi->type == ICE_VSI_VF)
163 vsi->alloc_txq = min_t(int, ice_get_avail_txq_count(pf),
166 vsi->alloc_txq = vsi->req_txq;
167 vsi->num_txq = vsi->req_txq;
170 pf->num_lan_tx = vsi->alloc_txq;
172 /* only 1 Rx queue unless RSS is enabled */
173 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
176 vsi->alloc_rxq = min_t(int, ice_get_avail_rxq_count(pf),
179 vsi->alloc_rxq = vsi->req_rxq;
180 vsi->num_rxq = vsi->req_rxq;
184 pf->num_lan_rx = vsi->alloc_rxq;
186 vsi->num_q_vectors = max_t(int, vsi->alloc_rxq, vsi->alloc_txq);
189 vf = &pf->vf[vsi->vf_id];
190 vsi->alloc_txq = vf->num_vf_qs;
191 vsi->alloc_rxq = vf->num_vf_qs;
192 /* pf->num_msix_per_vf includes (VF miscellaneous vector +
193 * data queue interrupts). Since vsi->num_q_vectors is number
194 * of queues vectors, subtract 1 (ICE_NONQ_VECS_VF) from the
195 * original vector count
197 vsi->num_q_vectors = pf->num_msix_per_vf - ICE_NONQ_VECS_VF;
202 vsi->num_q_vectors = 1;
209 dev_warn(ice_pf_to_dev(pf), "Unknown VSI type %d\n", vsi->type);
213 ice_vsi_set_num_desc(vsi);
217 * ice_get_free_slot - get the next non-NULL location index in array
218 * @array: array to search
219 * @size: size of the array
220 * @curr: last known occupied index to be used as a search hint
222 * void * is being used to keep the functionality generic. This lets us use this
223 * function on any array of pointers.
225 static int ice_get_free_slot(void *array, int size, int curr)
227 int **tmp_array = (int **)array;
230 if (curr < (size - 1) && !tmp_array[curr + 1]) {
235 while ((i < size) && (tmp_array[i]))
246 * ice_vsi_delete - delete a VSI from the switch
247 * @vsi: pointer to VSI being removed
249 void ice_vsi_delete(struct ice_vsi *vsi)
251 struct ice_pf *pf = vsi->back;
252 struct ice_vsi_ctx *ctxt;
253 enum ice_status status;
255 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
259 if (vsi->type == ICE_VSI_VF)
260 ctxt->vf_num = vsi->vf_id;
261 ctxt->vsi_num = vsi->vsi_num;
263 memcpy(&ctxt->info, &vsi->info, sizeof(ctxt->info));
265 status = ice_free_vsi(&pf->hw, vsi->idx, ctxt, false, NULL);
267 dev_err(ice_pf_to_dev(pf), "Failed to delete VSI %i in FW - error: %s\n",
268 vsi->vsi_num, ice_stat_str(status));
274 * ice_vsi_free_arrays - De-allocate queue and vector pointer arrays for the VSI
275 * @vsi: pointer to VSI being cleared
277 static void ice_vsi_free_arrays(struct ice_vsi *vsi)
279 struct ice_pf *pf = vsi->back;
282 dev = ice_pf_to_dev(pf);
284 /* free the ring and vector containers */
285 if (vsi->q_vectors) {
286 devm_kfree(dev, vsi->q_vectors);
287 vsi->q_vectors = NULL;
290 devm_kfree(dev, vsi->tx_rings);
291 vsi->tx_rings = NULL;
294 devm_kfree(dev, vsi->rx_rings);
295 vsi->rx_rings = NULL;
298 devm_kfree(dev, vsi->txq_map);
302 devm_kfree(dev, vsi->rxq_map);
308 * ice_vsi_clear - clean up and deallocate the provided VSI
309 * @vsi: pointer to VSI being cleared
311 * This deallocates the VSI's queue resources, removes it from the PF's
312 * VSI array if necessary, and deallocates the VSI
314 * Returns 0 on success, negative on failure
316 int ice_vsi_clear(struct ice_vsi *vsi)
318 struct ice_pf *pf = NULL;
328 dev = ice_pf_to_dev(pf);
330 if (!pf->vsi[vsi->idx] || pf->vsi[vsi->idx] != vsi) {
331 dev_dbg(dev, "vsi does not exist at pf->vsi[%d]\n", vsi->idx);
335 mutex_lock(&pf->sw_mutex);
336 /* updates the PF for this cleared VSI */
338 pf->vsi[vsi->idx] = NULL;
339 if (vsi->idx < pf->next_vsi && vsi->type != ICE_VSI_CTRL)
340 pf->next_vsi = vsi->idx;
342 ice_vsi_free_arrays(vsi);
343 mutex_unlock(&pf->sw_mutex);
344 devm_kfree(dev, vsi);
350 * ice_msix_clean_ctrl_vsi - MSIX mode interrupt handler for ctrl VSI
351 * @irq: interrupt number
352 * @data: pointer to a q_vector
354 static irqreturn_t ice_msix_clean_ctrl_vsi(int __always_unused irq, void *data)
356 struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
358 if (!q_vector->tx.ring)
361 #define FDIR_RX_DESC_CLEAN_BUDGET 64
362 ice_clean_rx_irq(q_vector->rx.ring, FDIR_RX_DESC_CLEAN_BUDGET);
363 ice_clean_ctrl_tx_irq(q_vector->tx.ring);
369 * ice_msix_clean_rings - MSIX mode Interrupt Handler
370 * @irq: interrupt number
371 * @data: pointer to a q_vector
373 static irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data)
375 struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
377 if (!q_vector->tx.ring && !q_vector->rx.ring)
380 napi_schedule(&q_vector->napi);
386 * ice_vsi_alloc - Allocates the next available struct VSI in the PF
387 * @pf: board private structure
388 * @vsi_type: type of VSI
389 * @vf_id: ID of the VF being configured
391 * returns a pointer to a VSI on success, NULL on failure.
393 static struct ice_vsi *
394 ice_vsi_alloc(struct ice_pf *pf, enum ice_vsi_type vsi_type, u16 vf_id)
396 struct device *dev = ice_pf_to_dev(pf);
397 struct ice_vsi *vsi = NULL;
399 /* Need to protect the allocation of the VSIs at the PF level */
400 mutex_lock(&pf->sw_mutex);
402 /* If we have already allocated our maximum number of VSIs,
403 * pf->next_vsi will be ICE_NO_VSI. If not, pf->next_vsi index
404 * is available to be populated
406 if (pf->next_vsi == ICE_NO_VSI) {
407 dev_dbg(dev, "out of VSI slots!\n");
411 vsi = devm_kzalloc(dev, sizeof(*vsi), GFP_KERNEL);
415 vsi->type = vsi_type;
417 set_bit(__ICE_DOWN, vsi->state);
419 if (vsi_type == ICE_VSI_VF)
420 ice_vsi_set_num_qs(vsi, vf_id);
422 ice_vsi_set_num_qs(vsi, ICE_INVAL_VFID);
426 if (ice_vsi_alloc_arrays(vsi))
429 /* Setup default MSIX irq handler for VSI */
430 vsi->irq_handler = ice_msix_clean_rings;
433 if (ice_vsi_alloc_arrays(vsi))
436 /* Setup ctrl VSI MSIX irq handler */
437 vsi->irq_handler = ice_msix_clean_ctrl_vsi;
440 if (ice_vsi_alloc_arrays(vsi))
444 if (ice_vsi_alloc_arrays(vsi))
448 dev_warn(dev, "Unknown VSI type %d\n", vsi->type);
452 if (vsi->type == ICE_VSI_CTRL) {
453 /* Use the last VSI slot as the index for the control VSI */
454 vsi->idx = pf->num_alloc_vsi - 1;
455 pf->ctrl_vsi_idx = vsi->idx;
456 pf->vsi[vsi->idx] = vsi;
458 /* fill slot and make note of the index */
459 vsi->idx = pf->next_vsi;
460 pf->vsi[pf->next_vsi] = vsi;
462 /* prepare pf->next_vsi for next use */
463 pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi,
469 devm_kfree(dev, vsi);
472 mutex_unlock(&pf->sw_mutex);
477 * ice_alloc_fd_res - Allocate FD resource for a VSI
478 * @vsi: pointer to the ice_vsi
480 * This allocates the FD resources
482 * Returns 0 on success, -EPERM on no-op or -EIO on failure
484 static int ice_alloc_fd_res(struct ice_vsi *vsi)
486 struct ice_pf *pf = vsi->back;
489 /* Flow Director filters are only allocated/assigned to the PF VSI which
490 * passes the traffic. The CTRL VSI is only used to add/delete filters
491 * so we don't allocate resources to it
494 /* FD filters from guaranteed pool per VSI */
495 g_val = pf->hw.func_caps.fd_fltr_guar;
499 /* FD filters from best effort pool */
500 b_val = pf->hw.func_caps.fd_fltr_best_effort;
504 if (vsi->type != ICE_VSI_PF)
507 if (!test_bit(ICE_FLAG_FD_ENA, pf->flags))
510 vsi->num_gfltr = g_val / pf->num_alloc_vsi;
512 /* each VSI gets same "best_effort" quota */
513 vsi->num_bfltr = b_val;
519 * ice_vsi_get_qs - Assign queues from PF to VSI
520 * @vsi: the VSI to assign queues to
522 * Returns 0 on success and a negative value on error
524 static int ice_vsi_get_qs(struct ice_vsi *vsi)
526 struct ice_pf *pf = vsi->back;
527 struct ice_qs_cfg tx_qs_cfg = {
528 .qs_mutex = &pf->avail_q_mutex,
529 .pf_map = pf->avail_txqs,
530 .pf_map_size = pf->max_pf_txqs,
531 .q_count = vsi->alloc_txq,
532 .scatter_count = ICE_MAX_SCATTER_TXQS,
533 .vsi_map = vsi->txq_map,
535 .mapping_mode = ICE_VSI_MAP_CONTIG
537 struct ice_qs_cfg rx_qs_cfg = {
538 .qs_mutex = &pf->avail_q_mutex,
539 .pf_map = pf->avail_rxqs,
540 .pf_map_size = pf->max_pf_rxqs,
541 .q_count = vsi->alloc_rxq,
542 .scatter_count = ICE_MAX_SCATTER_RXQS,
543 .vsi_map = vsi->rxq_map,
545 .mapping_mode = ICE_VSI_MAP_CONTIG
549 ret = __ice_vsi_get_qs(&tx_qs_cfg);
552 vsi->tx_mapping_mode = tx_qs_cfg.mapping_mode;
554 ret = __ice_vsi_get_qs(&rx_qs_cfg);
557 vsi->rx_mapping_mode = rx_qs_cfg.mapping_mode;
563 * ice_vsi_put_qs - Release queues from VSI to PF
564 * @vsi: the VSI that is going to release queues
566 void ice_vsi_put_qs(struct ice_vsi *vsi)
568 struct ice_pf *pf = vsi->back;
571 mutex_lock(&pf->avail_q_mutex);
573 for (i = 0; i < vsi->alloc_txq; i++) {
574 clear_bit(vsi->txq_map[i], pf->avail_txqs);
575 vsi->txq_map[i] = ICE_INVAL_Q_INDEX;
578 for (i = 0; i < vsi->alloc_rxq; i++) {
579 clear_bit(vsi->rxq_map[i], pf->avail_rxqs);
580 vsi->rxq_map[i] = ICE_INVAL_Q_INDEX;
583 mutex_unlock(&pf->avail_q_mutex);
588 * @pf: pointer to the PF struct
590 * returns true if driver is in safe mode, false otherwise
592 bool ice_is_safe_mode(struct ice_pf *pf)
594 return !test_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
598 * ice_vsi_clean_rss_flow_fld - Delete RSS configuration
599 * @vsi: the VSI being cleaned up
601 * This function deletes RSS input set for all flows that were configured
604 static void ice_vsi_clean_rss_flow_fld(struct ice_vsi *vsi)
606 struct ice_pf *pf = vsi->back;
607 enum ice_status status;
609 if (ice_is_safe_mode(pf))
612 status = ice_rem_vsi_rss_cfg(&pf->hw, vsi->idx);
614 dev_dbg(ice_pf_to_dev(pf), "ice_rem_vsi_rss_cfg failed for vsi = %d, error = %s\n",
615 vsi->vsi_num, ice_stat_str(status));
619 * ice_rss_clean - Delete RSS related VSI structures and configuration
620 * @vsi: the VSI being removed
622 static void ice_rss_clean(struct ice_vsi *vsi)
624 struct ice_pf *pf = vsi->back;
627 dev = ice_pf_to_dev(pf);
629 if (vsi->rss_hkey_user)
630 devm_kfree(dev, vsi->rss_hkey_user);
631 if (vsi->rss_lut_user)
632 devm_kfree(dev, vsi->rss_lut_user);
634 ice_vsi_clean_rss_flow_fld(vsi);
635 /* remove RSS replay list */
636 if (!ice_is_safe_mode(pf))
637 ice_rem_vsi_rss_list(&pf->hw, vsi->idx);
641 * ice_vsi_set_rss_params - Setup RSS capabilities per VSI type
642 * @vsi: the VSI being configured
644 static void ice_vsi_set_rss_params(struct ice_vsi *vsi)
646 struct ice_hw_common_caps *cap;
647 struct ice_pf *pf = vsi->back;
649 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
654 cap = &pf->hw.func_caps.common_cap;
657 /* PF VSI will inherit RSS instance of PF */
658 vsi->rss_table_size = (u16)cap->rss_table_size;
659 vsi->rss_size = min_t(u16, num_online_cpus(),
660 BIT(cap->rss_table_entry_width));
661 vsi->rss_lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
664 /* VF VSI will get a small RSS table.
665 * For VSI_LUT, LUT size should be set to 64 bytes.
667 vsi->rss_table_size = ICE_VSIQF_HLUT_ARRAY_SIZE;
668 vsi->rss_size = ICE_MAX_RSS_QS_PER_VF;
669 vsi->rss_lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_VSI;
674 dev_dbg(ice_pf_to_dev(pf), "Unsupported VSI type %s\n",
675 ice_vsi_type_str(vsi->type));
681 * ice_set_dflt_vsi_ctx - Set default VSI context before adding a VSI
682 * @ctxt: the VSI context being set
684 * This initializes a default VSI context for all sections except the Queues.
686 static void ice_set_dflt_vsi_ctx(struct ice_vsi_ctx *ctxt)
690 memset(&ctxt->info, 0, sizeof(ctxt->info));
691 /* VSI's should be allocated from shared pool */
692 ctxt->alloc_from_pool = true;
693 /* Src pruning enabled by default */
694 ctxt->info.sw_flags = ICE_AQ_VSI_SW_FLAG_SRC_PRUNE;
695 /* Traffic from VSI can be sent to LAN */
696 ctxt->info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
697 /* By default bits 3 and 4 in vlan_flags are 0's which results in legacy
698 * behavior (show VLAN, DEI, and UP) in descriptor. Also, allow all
699 * packets untagged/tagged.
701 ctxt->info.vlan_flags = ((ICE_AQ_VSI_VLAN_MODE_ALL &
702 ICE_AQ_VSI_VLAN_MODE_M) >>
703 ICE_AQ_VSI_VLAN_MODE_S);
704 /* Have 1:1 UP mapping for both ingress/egress tables */
705 table |= ICE_UP_TABLE_TRANSLATE(0, 0);
706 table |= ICE_UP_TABLE_TRANSLATE(1, 1);
707 table |= ICE_UP_TABLE_TRANSLATE(2, 2);
708 table |= ICE_UP_TABLE_TRANSLATE(3, 3);
709 table |= ICE_UP_TABLE_TRANSLATE(4, 4);
710 table |= ICE_UP_TABLE_TRANSLATE(5, 5);
711 table |= ICE_UP_TABLE_TRANSLATE(6, 6);
712 table |= ICE_UP_TABLE_TRANSLATE(7, 7);
713 ctxt->info.ingress_table = cpu_to_le32(table);
714 ctxt->info.egress_table = cpu_to_le32(table);
715 /* Have 1:1 UP mapping for outer to inner UP table */
716 ctxt->info.outer_up_table = cpu_to_le32(table);
717 /* No Outer tag support outer_tag_flags remains to zero */
721 * ice_vsi_setup_q_map - Setup a VSI queue map
722 * @vsi: the VSI being configured
723 * @ctxt: VSI context structure
725 static void ice_vsi_setup_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctxt)
727 u16 offset = 0, qmap = 0, tx_count = 0;
728 u16 qcount_tx = vsi->alloc_txq;
729 u16 qcount_rx = vsi->alloc_rxq;
730 u16 tx_numq_tc, rx_numq_tc;
731 u16 pow = 0, max_rss = 0;
732 bool ena_tc0 = false;
736 /* at least TC0 should be enabled by default */
737 if (vsi->tc_cfg.numtc) {
738 if (!(vsi->tc_cfg.ena_tc & BIT(0)))
746 vsi->tc_cfg.ena_tc |= 1;
749 rx_numq_tc = qcount_rx / vsi->tc_cfg.numtc;
752 tx_numq_tc = qcount_tx / vsi->tc_cfg.numtc;
756 /* TC mapping is a function of the number of Rx queues assigned to the
757 * VSI for each traffic class and the offset of these queues.
758 * The first 10 bits are for queue offset for TC0, next 4 bits for no:of
759 * queues allocated to TC0. No:of queues is a power-of-2.
761 * If TC is not enabled, the queue offset is set to 0, and allocate one
762 * queue, this way, traffic for the given TC will be sent to the default
765 * Setup number and offset of Rx queues for all TCs for the VSI
768 qcount_rx = rx_numq_tc;
770 /* qcount will change if RSS is enabled */
771 if (test_bit(ICE_FLAG_RSS_ENA, vsi->back->flags)) {
772 if (vsi->type == ICE_VSI_PF || vsi->type == ICE_VSI_VF) {
773 if (vsi->type == ICE_VSI_PF)
774 max_rss = ICE_MAX_LG_RSS_QS;
776 max_rss = ICE_MAX_RSS_QS_PER_VF;
777 qcount_rx = min_t(u16, rx_numq_tc, max_rss);
779 qcount_rx = min_t(u16, qcount_rx,
784 /* find the (rounded up) power-of-2 of qcount */
785 pow = (u16)order_base_2(qcount_rx);
787 ice_for_each_traffic_class(i) {
788 if (!(vsi->tc_cfg.ena_tc & BIT(i))) {
789 /* TC is not enabled */
790 vsi->tc_cfg.tc_info[i].qoffset = 0;
791 vsi->tc_cfg.tc_info[i].qcount_rx = 1;
792 vsi->tc_cfg.tc_info[i].qcount_tx = 1;
793 vsi->tc_cfg.tc_info[i].netdev_tc = 0;
794 ctxt->info.tc_mapping[i] = 0;
799 vsi->tc_cfg.tc_info[i].qoffset = offset;
800 vsi->tc_cfg.tc_info[i].qcount_rx = qcount_rx;
801 vsi->tc_cfg.tc_info[i].qcount_tx = tx_numq_tc;
802 vsi->tc_cfg.tc_info[i].netdev_tc = netdev_tc++;
804 qmap = ((offset << ICE_AQ_VSI_TC_Q_OFFSET_S) &
805 ICE_AQ_VSI_TC_Q_OFFSET_M) |
806 ((pow << ICE_AQ_VSI_TC_Q_NUM_S) &
807 ICE_AQ_VSI_TC_Q_NUM_M);
809 tx_count += tx_numq_tc;
810 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
813 /* if offset is non-zero, means it is calculated correctly based on
814 * enabled TCs for a given VSI otherwise qcount_rx will always
815 * be correct and non-zero because it is based off - VSI's
816 * allocated Rx queues which is at least 1 (hence qcount_tx will be
820 vsi->num_rxq = offset;
822 vsi->num_rxq = qcount_rx;
824 vsi->num_txq = tx_count;
826 if (vsi->type == ICE_VSI_VF && vsi->num_txq != vsi->num_rxq) {
827 dev_dbg(ice_pf_to_dev(vsi->back), "VF VSI should have same number of Tx and Rx queues. Hence making them equal\n");
828 /* since there is a chance that num_rxq could have been changed
829 * in the above for loop, make num_txq equal to num_rxq.
831 vsi->num_txq = vsi->num_rxq;
834 /* Rx queue mapping */
835 ctxt->info.mapping_flags |= cpu_to_le16(ICE_AQ_VSI_Q_MAP_CONTIG);
836 /* q_mapping buffer holds the info for the first queue allocated for
837 * this VSI in the PF space and also the number of queues associated
840 ctxt->info.q_mapping[0] = cpu_to_le16(vsi->rxq_map[0]);
841 ctxt->info.q_mapping[1] = cpu_to_le16(vsi->num_rxq);
845 * ice_set_fd_vsi_ctx - Set FD VSI context before adding a VSI
846 * @ctxt: the VSI context being set
847 * @vsi: the VSI being configured
849 static void ice_set_fd_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
851 u8 dflt_q_group, dflt_q_prio;
852 u16 dflt_q, report_q, val;
854 if (vsi->type != ICE_VSI_PF && vsi->type != ICE_VSI_CTRL)
857 val = ICE_AQ_VSI_PROP_FLOW_DIR_VALID;
858 ctxt->info.valid_sections |= cpu_to_le16(val);
864 /* enable flow director filtering/programming */
865 val = ICE_AQ_VSI_FD_ENABLE | ICE_AQ_VSI_FD_PROG_ENABLE;
866 ctxt->info.fd_options = cpu_to_le16(val);
867 /* max of allocated flow director filters */
868 ctxt->info.max_fd_fltr_dedicated =
869 cpu_to_le16(vsi->num_gfltr);
870 /* max of shared flow director filters any VSI may program */
871 ctxt->info.max_fd_fltr_shared =
872 cpu_to_le16(vsi->num_bfltr);
873 /* default queue index within the VSI of the default FD */
874 val = ((dflt_q << ICE_AQ_VSI_FD_DEF_Q_S) &
875 ICE_AQ_VSI_FD_DEF_Q_M);
876 /* target queue or queue group to the FD filter */
877 val |= ((dflt_q_group << ICE_AQ_VSI_FD_DEF_GRP_S) &
878 ICE_AQ_VSI_FD_DEF_GRP_M);
879 ctxt->info.fd_def_q = cpu_to_le16(val);
880 /* queue index on which FD filter completion is reported */
881 val = ((report_q << ICE_AQ_VSI_FD_REPORT_Q_S) &
882 ICE_AQ_VSI_FD_REPORT_Q_M);
883 /* priority of the default qindex action */
884 val |= ((dflt_q_prio << ICE_AQ_VSI_FD_DEF_PRIORITY_S) &
885 ICE_AQ_VSI_FD_DEF_PRIORITY_M);
886 ctxt->info.fd_report_opt = cpu_to_le16(val);
890 * ice_set_rss_vsi_ctx - Set RSS VSI context before adding a VSI
891 * @ctxt: the VSI context being set
892 * @vsi: the VSI being configured
894 static void ice_set_rss_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
896 u8 lut_type, hash_type;
901 dev = ice_pf_to_dev(pf);
905 /* PF VSI will inherit RSS instance of PF */
906 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_PF;
907 hash_type = ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
910 /* VF VSI will gets a small RSS table which is a VSI LUT type */
911 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI;
912 hash_type = ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
915 dev_dbg(dev, "Unsupported VSI type %s\n",
916 ice_vsi_type_str(vsi->type));
920 ctxt->info.q_opt_rss = ((lut_type << ICE_AQ_VSI_Q_OPT_RSS_LUT_S) &
921 ICE_AQ_VSI_Q_OPT_RSS_LUT_M) |
922 ((hash_type << ICE_AQ_VSI_Q_OPT_RSS_HASH_S) &
923 ICE_AQ_VSI_Q_OPT_RSS_HASH_M);
927 * ice_vsi_init - Create and initialize a VSI
928 * @vsi: the VSI being configured
929 * @init_vsi: is this call creating a VSI
931 * This initializes a VSI context depending on the VSI type to be added and
932 * passes it down to the add_vsi aq command to create a new VSI.
934 static int ice_vsi_init(struct ice_vsi *vsi, bool init_vsi)
936 struct ice_pf *pf = vsi->back;
937 struct ice_hw *hw = &pf->hw;
938 struct ice_vsi_ctx *ctxt;
942 dev = ice_pf_to_dev(pf);
943 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
951 ctxt->flags = ICE_AQ_VSI_TYPE_PF;
954 ctxt->flags = ICE_AQ_VSI_TYPE_VF;
955 /* VF number here is the absolute VF number (0-255) */
956 ctxt->vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
963 ice_set_dflt_vsi_ctx(ctxt);
964 if (test_bit(ICE_FLAG_FD_ENA, pf->flags))
965 ice_set_fd_vsi_ctx(ctxt, vsi);
966 /* if the switch is in VEB mode, allow VSI loopback */
967 if (vsi->vsw->bridge_mode == BRIDGE_MODE_VEB)
968 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
970 /* Set LUT type and HASH type if RSS is enabled */
971 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags) &&
972 vsi->type != ICE_VSI_CTRL) {
973 ice_set_rss_vsi_ctx(ctxt, vsi);
974 /* if updating VSI context, make sure to set valid_section:
975 * to indicate which section of VSI context being updated
978 ctxt->info.valid_sections |=
979 cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
982 ctxt->info.sw_id = vsi->port_info->sw_id;
983 ice_vsi_setup_q_map(vsi, ctxt);
984 if (!init_vsi) /* means VSI being updated */
985 /* must to indicate which section of VSI context are
988 ctxt->info.valid_sections |=
989 cpu_to_le16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
991 /* enable/disable MAC and VLAN anti-spoof when spoofchk is on/off
994 if (vsi->type == ICE_VSI_VF) {
995 ctxt->info.valid_sections |=
996 cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID);
997 if (pf->vf[vsi->vf_id].spoofchk) {
998 ctxt->info.sec_flags |=
999 ICE_AQ_VSI_SEC_FLAG_ENA_MAC_ANTI_SPOOF |
1000 (ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
1001 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S);
1003 ctxt->info.sec_flags &=
1004 ~(ICE_AQ_VSI_SEC_FLAG_ENA_MAC_ANTI_SPOOF |
1005 (ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
1006 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S));
1010 /* Allow control frames out of main VSI */
1011 if (vsi->type == ICE_VSI_PF) {
1012 ctxt->info.sec_flags |= ICE_AQ_VSI_SEC_FLAG_ALLOW_DEST_OVRD;
1013 ctxt->info.valid_sections |=
1014 cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID);
1018 ret = ice_add_vsi(hw, vsi->idx, ctxt, NULL);
1020 dev_err(dev, "Add VSI failed, err %d\n", ret);
1025 ret = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1027 dev_err(dev, "Update VSI failed, err %d\n", ret);
1033 /* keep context for update VSI operations */
1034 vsi->info = ctxt->info;
1036 /* record VSI number returned */
1037 vsi->vsi_num = ctxt->vsi_num;
1045 * ice_free_res - free a block of resources
1046 * @res: pointer to the resource
1047 * @index: starting index previously returned by ice_get_res
1048 * @id: identifier to track owner
1050 * Returns number of resources freed
1052 int ice_free_res(struct ice_res_tracker *res, u16 index, u16 id)
1057 if (!res || index >= res->end)
1060 id |= ICE_RES_VALID_BIT;
1061 for (i = index; i < res->end && res->list[i] == id; i++) {
1070 * ice_search_res - Search the tracker for a block of resources
1071 * @res: pointer to the resource
1072 * @needed: size of the block needed
1073 * @id: identifier to track owner
1075 * Returns the base item index of the block, or -ENOMEM for error
1077 static int ice_search_res(struct ice_res_tracker *res, u16 needed, u16 id)
1079 u16 start = 0, end = 0;
1081 if (needed > res->end)
1084 id |= ICE_RES_VALID_BIT;
1087 /* skip already allocated entries */
1088 if (res->list[end++] & ICE_RES_VALID_BIT) {
1090 if ((start + needed) > res->end)
1094 if (end == (start + needed)) {
1097 /* there was enough, so assign it to the requestor */
1099 res->list[i++] = id;
1103 } while (end < res->end);
1109 * ice_get_free_res_count - Get free count from a resource tracker
1110 * @res: Resource tracker instance
1112 static u16 ice_get_free_res_count(struct ice_res_tracker *res)
1116 for (i = 0; i < res->end; i++)
1117 if (!(res->list[i] & ICE_RES_VALID_BIT))
1124 * ice_get_res - get a block of resources
1125 * @pf: board private structure
1126 * @res: pointer to the resource
1127 * @needed: size of the block needed
1128 * @id: identifier to track owner
1130 * Returns the base item index of the block, or negative for error
1133 ice_get_res(struct ice_pf *pf, struct ice_res_tracker *res, u16 needed, u16 id)
1138 if (!needed || needed > res->num_entries || id >= ICE_RES_VALID_BIT) {
1139 dev_err(ice_pf_to_dev(pf), "param err: needed=%d, num_entries = %d id=0x%04x\n",
1140 needed, res->num_entries, id);
1144 return ice_search_res(res, needed, id);
1148 * ice_vsi_setup_vector_base - Set up the base vector for the given VSI
1149 * @vsi: ptr to the VSI
1151 * This should only be called after ice_vsi_alloc() which allocates the
1152 * corresponding SW VSI structure and initializes num_queue_pairs for the
1153 * newly allocated VSI.
1155 * Returns 0 on success or negative on failure
1157 static int ice_vsi_setup_vector_base(struct ice_vsi *vsi)
1159 struct ice_pf *pf = vsi->back;
1164 dev = ice_pf_to_dev(pf);
1165 /* SRIOV doesn't grab irq_tracker entries for each VSI */
1166 if (vsi->type == ICE_VSI_VF)
1169 if (vsi->base_vector) {
1170 dev_dbg(dev, "VSI %d has non-zero base vector %d\n",
1171 vsi->vsi_num, vsi->base_vector);
1175 num_q_vectors = vsi->num_q_vectors;
1176 /* reserve slots from OS requested IRQs */
1177 base = ice_get_res(pf, pf->irq_tracker, num_q_vectors, vsi->idx);
1180 dev_err(dev, "%d MSI-X interrupts available. %s %d failed to get %d MSI-X vectors\n",
1181 ice_get_free_res_count(pf->irq_tracker),
1182 ice_vsi_type_str(vsi->type), vsi->idx, num_q_vectors);
1185 vsi->base_vector = (u16)base;
1186 pf->num_avail_sw_msix -= num_q_vectors;
1192 * ice_vsi_clear_rings - Deallocates the Tx and Rx rings for VSI
1193 * @vsi: the VSI having rings deallocated
1195 static void ice_vsi_clear_rings(struct ice_vsi *vsi)
1199 if (vsi->tx_rings) {
1200 for (i = 0; i < vsi->alloc_txq; i++) {
1201 if (vsi->tx_rings[i]) {
1202 kfree_rcu(vsi->tx_rings[i], rcu);
1203 WRITE_ONCE(vsi->tx_rings[i], NULL);
1207 if (vsi->rx_rings) {
1208 for (i = 0; i < vsi->alloc_rxq; i++) {
1209 if (vsi->rx_rings[i]) {
1210 kfree_rcu(vsi->rx_rings[i], rcu);
1211 WRITE_ONCE(vsi->rx_rings[i], NULL);
1218 * ice_vsi_alloc_rings - Allocates Tx and Rx rings for the VSI
1219 * @vsi: VSI which is having rings allocated
1221 static int ice_vsi_alloc_rings(struct ice_vsi *vsi)
1223 struct ice_pf *pf = vsi->back;
1227 dev = ice_pf_to_dev(pf);
1228 /* Allocate Tx rings */
1229 for (i = 0; i < vsi->alloc_txq; i++) {
1230 struct ice_ring *ring;
1232 /* allocate with kzalloc(), free with kfree_rcu() */
1233 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1239 ring->reg_idx = vsi->txq_map[i];
1240 ring->ring_active = false;
1243 ring->count = vsi->num_tx_desc;
1244 WRITE_ONCE(vsi->tx_rings[i], ring);
1247 /* Allocate Rx rings */
1248 for (i = 0; i < vsi->alloc_rxq; i++) {
1249 struct ice_ring *ring;
1251 /* allocate with kzalloc(), free with kfree_rcu() */
1252 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1257 ring->reg_idx = vsi->rxq_map[i];
1258 ring->ring_active = false;
1260 ring->netdev = vsi->netdev;
1262 ring->count = vsi->num_rx_desc;
1263 WRITE_ONCE(vsi->rx_rings[i], ring);
1269 ice_vsi_clear_rings(vsi);
1274 * ice_vsi_manage_rss_lut - disable/enable RSS
1275 * @vsi: the VSI being changed
1276 * @ena: boolean value indicating if this is an enable or disable request
1278 * In the event of disable request for RSS, this function will zero out RSS
1279 * LUT, while in the event of enable request for RSS, it will reconfigure RSS
1282 int ice_vsi_manage_rss_lut(struct ice_vsi *vsi, bool ena)
1287 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
1292 if (vsi->rss_lut_user)
1293 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1295 ice_fill_rss_lut(lut, vsi->rss_table_size,
1299 err = ice_set_rss(vsi, NULL, lut, vsi->rss_table_size);
1305 * ice_vsi_cfg_rss_lut_key - Configure RSS params for a VSI
1306 * @vsi: VSI to be configured
1308 static int ice_vsi_cfg_rss_lut_key(struct ice_vsi *vsi)
1310 struct ice_aqc_get_set_rss_keys *key;
1311 struct ice_pf *pf = vsi->back;
1312 enum ice_status status;
1317 dev = ice_pf_to_dev(pf);
1318 vsi->rss_size = min_t(u16, vsi->rss_size, vsi->num_rxq);
1320 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
1324 if (vsi->rss_lut_user)
1325 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1327 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
1329 status = ice_aq_set_rss_lut(&pf->hw, vsi->idx, vsi->rss_lut_type, lut,
1330 vsi->rss_table_size);
1333 dev_err(dev, "set_rss_lut failed, error %s\n",
1334 ice_stat_str(status));
1336 goto ice_vsi_cfg_rss_exit;
1339 key = kzalloc(sizeof(*key), GFP_KERNEL);
1342 goto ice_vsi_cfg_rss_exit;
1345 if (vsi->rss_hkey_user)
1347 (struct ice_aqc_get_set_rss_keys *)vsi->rss_hkey_user,
1348 ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE);
1350 netdev_rss_key_fill((void *)key,
1351 ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE);
1353 status = ice_aq_set_rss_key(&pf->hw, vsi->idx, key);
1356 dev_err(dev, "set_rss_key failed, error %s\n",
1357 ice_stat_str(status));
1362 ice_vsi_cfg_rss_exit:
1368 * ice_vsi_set_vf_rss_flow_fld - Sets VF VSI RSS input set for different flows
1369 * @vsi: VSI to be configured
1371 * This function will only be called during the VF VSI setup. Upon successful
1372 * completion of package download, this function will configure default RSS
1373 * input sets for VF VSI.
1375 static void ice_vsi_set_vf_rss_flow_fld(struct ice_vsi *vsi)
1377 struct ice_pf *pf = vsi->back;
1378 enum ice_status status;
1381 dev = ice_pf_to_dev(pf);
1382 if (ice_is_safe_mode(pf)) {
1383 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
1388 status = ice_add_avf_rss_cfg(&pf->hw, vsi->idx, ICE_DEFAULT_RSS_HENA);
1390 dev_dbg(dev, "ice_add_avf_rss_cfg failed for vsi = %d, error = %s\n",
1391 vsi->vsi_num, ice_stat_str(status));
1395 * ice_vsi_set_rss_flow_fld - Sets RSS input set for different flows
1396 * @vsi: VSI to be configured
1398 * This function will only be called after successful download package call
1399 * during initialization of PF. Since the downloaded package will erase the
1400 * RSS section, this function will configure RSS input sets for different
1401 * flow types. The last profile added has the highest priority, therefore 2
1402 * tuple profiles (i.e. IPv4 src/dst) are added before 4 tuple profiles
1403 * (i.e. IPv4 src/dst TCP src/dst port).
1405 static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi)
1407 u16 vsi_handle = vsi->idx, vsi_num = vsi->vsi_num;
1408 struct ice_pf *pf = vsi->back;
1409 struct ice_hw *hw = &pf->hw;
1410 enum ice_status status;
1413 dev = ice_pf_to_dev(pf);
1414 if (ice_is_safe_mode(pf)) {
1415 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
1419 /* configure RSS for IPv4 with input set IP src/dst */
1420 status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV4,
1421 ICE_FLOW_SEG_HDR_IPV4);
1423 dev_dbg(dev, "ice_add_rss_cfg failed for ipv4 flow, vsi = %d, error = %s\n",
1424 vsi_num, ice_stat_str(status));
1426 /* configure RSS for IPv6 with input set IPv6 src/dst */
1427 status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV6,
1428 ICE_FLOW_SEG_HDR_IPV6);
1430 dev_dbg(dev, "ice_add_rss_cfg failed for ipv6 flow, vsi = %d, error = %s\n",
1431 vsi_num, ice_stat_str(status));
1433 /* configure RSS for tcp4 with input set IP src/dst, TCP src/dst */
1434 status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_TCP_IPV4,
1435 ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4);
1437 dev_dbg(dev, "ice_add_rss_cfg failed for tcp4 flow, vsi = %d, error = %s\n",
1438 vsi_num, ice_stat_str(status));
1440 /* configure RSS for udp4 with input set IP src/dst, UDP src/dst */
1441 status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_UDP_IPV4,
1442 ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4);
1444 dev_dbg(dev, "ice_add_rss_cfg failed for udp4 flow, vsi = %d, error = %s\n",
1445 vsi_num, ice_stat_str(status));
1447 /* configure RSS for sctp4 with input set IP src/dst */
1448 status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV4,
1449 ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4);
1451 dev_dbg(dev, "ice_add_rss_cfg failed for sctp4 flow, vsi = %d, error = %s\n",
1452 vsi_num, ice_stat_str(status));
1454 /* configure RSS for tcp6 with input set IPv6 src/dst, TCP src/dst */
1455 status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_TCP_IPV6,
1456 ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6);
1458 dev_dbg(dev, "ice_add_rss_cfg failed for tcp6 flow, vsi = %d, error = %s\n",
1459 vsi_num, ice_stat_str(status));
1461 /* configure RSS for udp6 with input set IPv6 src/dst, UDP src/dst */
1462 status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_UDP_IPV6,
1463 ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6);
1465 dev_dbg(dev, "ice_add_rss_cfg failed for udp6 flow, vsi = %d, error = %s\n",
1466 vsi_num, ice_stat_str(status));
1468 /* configure RSS for sctp6 with input set IPv6 src/dst */
1469 status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV6,
1470 ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6);
1472 dev_dbg(dev, "ice_add_rss_cfg failed for sctp6 flow, vsi = %d, error = %s\n",
1473 vsi_num, ice_stat_str(status));
1477 * ice_pf_state_is_nominal - checks the PF for nominal state
1478 * @pf: pointer to PF to check
1480 * Check the PF's state for a collection of bits that would indicate
1481 * the PF is in a state that would inhibit normal operation for
1482 * driver functionality.
1484 * Returns true if PF is in a nominal state, false otherwise
1486 bool ice_pf_state_is_nominal(struct ice_pf *pf)
1488 DECLARE_BITMAP(check_bits, __ICE_STATE_NBITS) = { 0 };
1493 bitmap_set(check_bits, 0, __ICE_STATE_NOMINAL_CHECK_BITS);
1494 if (bitmap_intersects(pf->state, check_bits, __ICE_STATE_NBITS))
1501 * ice_update_eth_stats - Update VSI-specific ethernet statistics counters
1502 * @vsi: the VSI to be updated
1504 void ice_update_eth_stats(struct ice_vsi *vsi)
1506 struct ice_eth_stats *prev_es, *cur_es;
1507 struct ice_hw *hw = &vsi->back->hw;
1508 u16 vsi_num = vsi->vsi_num; /* HW absolute index of a VSI */
1510 prev_es = &vsi->eth_stats_prev;
1511 cur_es = &vsi->eth_stats;
1513 ice_stat_update40(hw, GLV_GORCL(vsi_num), vsi->stat_offsets_loaded,
1514 &prev_es->rx_bytes, &cur_es->rx_bytes);
1516 ice_stat_update40(hw, GLV_UPRCL(vsi_num), vsi->stat_offsets_loaded,
1517 &prev_es->rx_unicast, &cur_es->rx_unicast);
1519 ice_stat_update40(hw, GLV_MPRCL(vsi_num), vsi->stat_offsets_loaded,
1520 &prev_es->rx_multicast, &cur_es->rx_multicast);
1522 ice_stat_update40(hw, GLV_BPRCL(vsi_num), vsi->stat_offsets_loaded,
1523 &prev_es->rx_broadcast, &cur_es->rx_broadcast);
1525 ice_stat_update32(hw, GLV_RDPC(vsi_num), vsi->stat_offsets_loaded,
1526 &prev_es->rx_discards, &cur_es->rx_discards);
1528 ice_stat_update40(hw, GLV_GOTCL(vsi_num), vsi->stat_offsets_loaded,
1529 &prev_es->tx_bytes, &cur_es->tx_bytes);
1531 ice_stat_update40(hw, GLV_UPTCL(vsi_num), vsi->stat_offsets_loaded,
1532 &prev_es->tx_unicast, &cur_es->tx_unicast);
1534 ice_stat_update40(hw, GLV_MPTCL(vsi_num), vsi->stat_offsets_loaded,
1535 &prev_es->tx_multicast, &cur_es->tx_multicast);
1537 ice_stat_update40(hw, GLV_BPTCL(vsi_num), vsi->stat_offsets_loaded,
1538 &prev_es->tx_broadcast, &cur_es->tx_broadcast);
1540 ice_stat_update32(hw, GLV_TEPC(vsi_num), vsi->stat_offsets_loaded,
1541 &prev_es->tx_errors, &cur_es->tx_errors);
1543 vsi->stat_offsets_loaded = true;
1547 * ice_vsi_add_vlan - Add VSI membership for given VLAN
1548 * @vsi: the VSI being configured
1549 * @vid: VLAN ID to be added
1550 * @action: filter action to be performed on match
1553 ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid, enum ice_sw_fwd_act_type action)
1555 struct ice_pf *pf = vsi->back;
1559 dev = ice_pf_to_dev(pf);
1561 if (!ice_fltr_add_vlan(vsi, vid, action)) {
1565 dev_err(dev, "Failure Adding VLAN %d on VSI %i\n", vid,
1573 * ice_vsi_kill_vlan - Remove VSI membership for a given VLAN
1574 * @vsi: the VSI being configured
1575 * @vid: VLAN ID to be removed
1577 * Returns 0 on success and negative on failure
1579 int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid)
1581 struct ice_pf *pf = vsi->back;
1582 enum ice_status status;
1586 dev = ice_pf_to_dev(pf);
1588 status = ice_fltr_remove_vlan(vsi, vid, ICE_FWD_TO_VSI);
1591 } else if (status == ICE_ERR_DOES_NOT_EXIST) {
1592 dev_dbg(dev, "Failed to remove VLAN %d on VSI %i, it does not exist, status: %s\n",
1593 vid, vsi->vsi_num, ice_stat_str(status));
1595 dev_err(dev, "Error removing VLAN %d on vsi %i error: %s\n",
1596 vid, vsi->vsi_num, ice_stat_str(status));
1604 * ice_vsi_cfg_frame_size - setup max frame size and Rx buffer length
1607 void ice_vsi_cfg_frame_size(struct ice_vsi *vsi)
1609 if (!vsi->netdev || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags)) {
1610 vsi->max_frame = ICE_AQ_SET_MAC_FRAME_SIZE_MAX;
1611 vsi->rx_buf_len = ICE_RXBUF_2048;
1612 #if (PAGE_SIZE < 8192)
1613 } else if (!ICE_2K_TOO_SMALL_WITH_PADDING &&
1614 (vsi->netdev->mtu <= ETH_DATA_LEN)) {
1615 vsi->max_frame = ICE_RXBUF_1536 - NET_IP_ALIGN;
1616 vsi->rx_buf_len = ICE_RXBUF_1536 - NET_IP_ALIGN;
1619 vsi->max_frame = ICE_AQ_SET_MAC_FRAME_SIZE_MAX;
1620 #if (PAGE_SIZE < 8192)
1621 vsi->rx_buf_len = ICE_RXBUF_3072;
1623 vsi->rx_buf_len = ICE_RXBUF_2048;
1629 * ice_write_qrxflxp_cntxt - write/configure QRXFLXP_CNTXT register
1631 * @pf_q: index of the Rx queue in the PF's queue space
1632 * @rxdid: flexible descriptor RXDID
1633 * @prio: priority for the RXDID for this queue
1636 ice_write_qrxflxp_cntxt(struct ice_hw *hw, u16 pf_q, u32 rxdid, u32 prio)
1638 int regval = rd32(hw, QRXFLXP_CNTXT(pf_q));
1640 /* clear any previous values */
1641 regval &= ~(QRXFLXP_CNTXT_RXDID_IDX_M |
1642 QRXFLXP_CNTXT_RXDID_PRIO_M |
1643 QRXFLXP_CNTXT_TS_M);
1645 regval |= (rxdid << QRXFLXP_CNTXT_RXDID_IDX_S) &
1646 QRXFLXP_CNTXT_RXDID_IDX_M;
1648 regval |= (prio << QRXFLXP_CNTXT_RXDID_PRIO_S) &
1649 QRXFLXP_CNTXT_RXDID_PRIO_M;
1651 wr32(hw, QRXFLXP_CNTXT(pf_q), regval);
1655 * ice_vsi_cfg_rxqs - Configure the VSI for Rx
1656 * @vsi: the VSI being configured
1658 * Return 0 on success and a negative value on error
1659 * Configure the Rx VSI for operation.
1661 int ice_vsi_cfg_rxqs(struct ice_vsi *vsi)
1665 if (vsi->type == ICE_VSI_VF)
1668 ice_vsi_cfg_frame_size(vsi);
1670 /* set up individual rings */
1671 for (i = 0; i < vsi->num_rxq; i++) {
1674 err = ice_setup_rx_ctx(vsi->rx_rings[i]);
1676 dev_err(ice_pf_to_dev(vsi->back), "ice_setup_rx_ctx failed for RxQ %d, err %d\n",
1686 * ice_vsi_cfg_txqs - Configure the VSI for Tx
1687 * @vsi: the VSI being configured
1688 * @rings: Tx ring array to be configured
1690 * Return 0 on success and a negative value on error
1691 * Configure the Tx VSI for operation.
1694 ice_vsi_cfg_txqs(struct ice_vsi *vsi, struct ice_ring **rings)
1696 struct ice_aqc_add_tx_qgrp *qg_buf;
1700 qg_buf = kzalloc(struct_size(qg_buf, txqs, 1), GFP_KERNEL);
1704 qg_buf->num_txqs = 1;
1706 for (q_idx = 0; q_idx < vsi->num_txq; q_idx++) {
1707 err = ice_vsi_cfg_txq(vsi, rings[q_idx], qg_buf);
1718 * ice_vsi_cfg_lan_txqs - Configure the VSI for Tx
1719 * @vsi: the VSI being configured
1721 * Return 0 on success and a negative value on error
1722 * Configure the Tx VSI for operation.
1724 int ice_vsi_cfg_lan_txqs(struct ice_vsi *vsi)
1726 return ice_vsi_cfg_txqs(vsi, vsi->tx_rings);
1730 * ice_vsi_cfg_xdp_txqs - Configure Tx queues dedicated for XDP in given VSI
1731 * @vsi: the VSI being configured
1733 * Return 0 on success and a negative value on error
1734 * Configure the Tx queues dedicated for XDP in given VSI for operation.
1736 int ice_vsi_cfg_xdp_txqs(struct ice_vsi *vsi)
1741 ret = ice_vsi_cfg_txqs(vsi, vsi->xdp_rings);
1745 for (i = 0; i < vsi->num_xdp_txq; i++)
1746 vsi->xdp_rings[i]->xsk_umem = ice_xsk_umem(vsi->xdp_rings[i]);
1752 * ice_intrl_usec_to_reg - convert interrupt rate limit to register value
1753 * @intrl: interrupt rate limit in usecs
1754 * @gran: interrupt rate limit granularity in usecs
1756 * This function converts a decimal interrupt rate limit in usecs to the format
1757 * expected by firmware.
1759 u32 ice_intrl_usec_to_reg(u8 intrl, u8 gran)
1761 u32 val = intrl / gran;
1764 return val | GLINT_RATE_INTRL_ENA_M;
1769 * ice_vsi_cfg_msix - MSIX mode Interrupt Config in the HW
1770 * @vsi: the VSI being configured
1772 * This configures MSIX mode interrupts for the PF VSI, and should not be used
1775 void ice_vsi_cfg_msix(struct ice_vsi *vsi)
1777 struct ice_pf *pf = vsi->back;
1778 struct ice_hw *hw = &pf->hw;
1779 u16 txq = 0, rxq = 0;
1782 for (i = 0; i < vsi->num_q_vectors; i++) {
1783 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1784 u16 reg_idx = q_vector->reg_idx;
1786 ice_cfg_itr(hw, q_vector);
1788 wr32(hw, GLINT_RATE(reg_idx),
1789 ice_intrl_usec_to_reg(q_vector->intrl, hw->intrl_gran));
1791 /* Both Transmit Queue Interrupt Cause Control register
1792 * and Receive Queue Interrupt Cause control register
1793 * expects MSIX_INDX field to be the vector index
1794 * within the function space and not the absolute
1795 * vector index across PF or across device.
1796 * For SR-IOV VF VSIs queue vector index always starts
1797 * with 1 since first vector index(0) is used for OICR
1798 * in VF space. Since VMDq and other PF VSIs are within
1799 * the PF function space, use the vector index that is
1800 * tracked for this PF.
1802 for (q = 0; q < q_vector->num_ring_tx; q++) {
1803 ice_cfg_txq_interrupt(vsi, txq, reg_idx,
1804 q_vector->tx.itr_idx);
1808 for (q = 0; q < q_vector->num_ring_rx; q++) {
1809 ice_cfg_rxq_interrupt(vsi, rxq, reg_idx,
1810 q_vector->rx.itr_idx);
1817 * ice_vsi_manage_vlan_insertion - Manage VLAN insertion for the VSI for Tx
1818 * @vsi: the VSI being changed
1820 int ice_vsi_manage_vlan_insertion(struct ice_vsi *vsi)
1822 struct ice_hw *hw = &vsi->back->hw;
1823 struct ice_vsi_ctx *ctxt;
1824 enum ice_status status;
1827 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
1831 /* Here we are configuring the VSI to let the driver add VLAN tags by
1832 * setting vlan_flags to ICE_AQ_VSI_VLAN_MODE_ALL. The actual VLAN tag
1833 * insertion happens in the Tx hot path, in ice_tx_map.
1835 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_MODE_ALL;
1837 /* Preserve existing VLAN strip setting */
1838 ctxt->info.vlan_flags |= (vsi->info.vlan_flags &
1839 ICE_AQ_VSI_VLAN_EMOD_M);
1841 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
1843 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1845 dev_err(ice_pf_to_dev(vsi->back), "update VSI for VLAN insert failed, err %s aq_err %s\n",
1846 ice_stat_str(status),
1847 ice_aq_str(hw->adminq.sq_last_status));
1852 vsi->info.vlan_flags = ctxt->info.vlan_flags;
1859 * ice_vsi_manage_vlan_stripping - Manage VLAN stripping for the VSI for Rx
1860 * @vsi: the VSI being changed
1861 * @ena: boolean value indicating if this is a enable or disable request
1863 int ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
1865 struct ice_hw *hw = &vsi->back->hw;
1866 struct ice_vsi_ctx *ctxt;
1867 enum ice_status status;
1870 /* do not allow modifying VLAN stripping when a port VLAN is configured
1876 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
1880 /* Here we are configuring what the VSI should do with the VLAN tag in
1881 * the Rx packet. We can either leave the tag in the packet or put it in
1882 * the Rx descriptor.
1885 /* Strip VLAN tag from Rx packet and put it in the desc */
1886 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_STR_BOTH;
1888 /* Disable stripping. Leave tag in packet */
1889 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_NOTHING;
1891 /* Allow all packets untagged/tagged */
1892 ctxt->info.vlan_flags |= ICE_AQ_VSI_VLAN_MODE_ALL;
1894 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
1896 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1898 dev_err(ice_pf_to_dev(vsi->back), "update VSI for VLAN strip failed, ena = %d err %s aq_err %s\n",
1899 ena, ice_stat_str(status),
1900 ice_aq_str(hw->adminq.sq_last_status));
1905 vsi->info.vlan_flags = ctxt->info.vlan_flags;
1912 * ice_vsi_start_all_rx_rings - start/enable all of a VSI's Rx rings
1913 * @vsi: the VSI whose rings are to be enabled
1915 * Returns 0 on success and a negative value on error
1917 int ice_vsi_start_all_rx_rings(struct ice_vsi *vsi)
1919 return ice_vsi_ctrl_all_rx_rings(vsi, true);
1923 * ice_vsi_stop_all_rx_rings - stop/disable all of a VSI's Rx rings
1924 * @vsi: the VSI whose rings are to be disabled
1926 * Returns 0 on success and a negative value on error
1928 int ice_vsi_stop_all_rx_rings(struct ice_vsi *vsi)
1930 return ice_vsi_ctrl_all_rx_rings(vsi, false);
1934 * ice_vsi_stop_tx_rings - Disable Tx rings
1935 * @vsi: the VSI being configured
1936 * @rst_src: reset source
1937 * @rel_vmvf_num: Relative ID of VF/VM
1938 * @rings: Tx ring array to be stopped
1941 ice_vsi_stop_tx_rings(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
1942 u16 rel_vmvf_num, struct ice_ring **rings)
1946 if (vsi->num_txq > ICE_LAN_TXQ_MAX_QDIS)
1949 for (q_idx = 0; q_idx < vsi->num_txq; q_idx++) {
1950 struct ice_txq_meta txq_meta = { };
1953 if (!rings || !rings[q_idx])
1956 ice_fill_txq_meta(vsi, rings[q_idx], &txq_meta);
1957 status = ice_vsi_stop_tx_ring(vsi, rst_src, rel_vmvf_num,
1958 rings[q_idx], &txq_meta);
1968 * ice_vsi_stop_lan_tx_rings - Disable LAN Tx rings
1969 * @vsi: the VSI being configured
1970 * @rst_src: reset source
1971 * @rel_vmvf_num: Relative ID of VF/VM
1974 ice_vsi_stop_lan_tx_rings(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
1977 return ice_vsi_stop_tx_rings(vsi, rst_src, rel_vmvf_num, vsi->tx_rings);
1981 * ice_vsi_stop_xdp_tx_rings - Disable XDP Tx rings
1982 * @vsi: the VSI being configured
1984 int ice_vsi_stop_xdp_tx_rings(struct ice_vsi *vsi)
1986 return ice_vsi_stop_tx_rings(vsi, ICE_NO_RESET, 0, vsi->xdp_rings);
1990 * ice_vsi_is_vlan_pruning_ena - check if VLAN pruning is enabled or not
1991 * @vsi: VSI to check whether or not VLAN pruning is enabled.
1993 * returns true if Rx VLAN pruning is enabled and false otherwise.
1995 bool ice_vsi_is_vlan_pruning_ena(struct ice_vsi *vsi)
2000 return (vsi->info.sw_flags2 & ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA);
2004 * ice_cfg_vlan_pruning - enable or disable VLAN pruning on the VSI
2005 * @vsi: VSI to enable or disable VLAN pruning on
2006 * @ena: set to true to enable VLAN pruning and false to disable it
2007 * @vlan_promisc: enable valid security flags if not in VLAN promiscuous mode
2009 * returns 0 if VSI is updated, negative otherwise
2011 int ice_cfg_vlan_pruning(struct ice_vsi *vsi, bool ena, bool vlan_promisc)
2013 struct ice_vsi_ctx *ctxt;
2020 /* Don't enable VLAN pruning if the netdev is currently in promiscuous
2021 * mode. VLAN pruning will be enabled when the interface exits
2022 * promiscuous mode if any VLAN filters are active.
2024 if (vsi->netdev && vsi->netdev->flags & IFF_PROMISC && ena)
2028 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
2032 ctxt->info = vsi->info;
2035 ctxt->info.sw_flags2 |= ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
2037 ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
2040 ctxt->info.valid_sections =
2041 cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
2043 status = ice_update_vsi(&pf->hw, vsi->idx, ctxt, NULL);
2045 netdev_err(vsi->netdev, "%sabling VLAN pruning on VSI handle: %d, VSI HW ID: %d failed, err = %s, aq_err = %s\n",
2046 ena ? "En" : "Dis", vsi->idx, vsi->vsi_num,
2047 ice_stat_str(status),
2048 ice_aq_str(pf->hw.adminq.sq_last_status));
2052 vsi->info.sw_flags2 = ctxt->info.sw_flags2;
2062 static void ice_vsi_set_tc_cfg(struct ice_vsi *vsi)
2064 struct ice_dcbx_cfg *cfg = &vsi->port_info->local_dcbx_cfg;
2066 vsi->tc_cfg.ena_tc = ice_dcb_get_ena_tc(cfg);
2067 vsi->tc_cfg.numtc = ice_dcb_get_num_tc(cfg);
2071 * ice_vsi_set_q_vectors_reg_idx - set the HW register index for all q_vectors
2072 * @vsi: VSI to set the q_vectors register index on
2075 ice_vsi_set_q_vectors_reg_idx(struct ice_vsi *vsi)
2079 if (!vsi || !vsi->q_vectors)
2082 ice_for_each_q_vector(vsi, i) {
2083 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2086 dev_err(ice_pf_to_dev(vsi->back), "Failed to set reg_idx on q_vector %d VSI %d\n",
2091 if (vsi->type == ICE_VSI_VF) {
2092 struct ice_vf *vf = &vsi->back->vf[vsi->vf_id];
2094 q_vector->reg_idx = ice_calc_vf_reg_idx(vf, q_vector);
2097 q_vector->v_idx + vsi->base_vector;
2104 ice_for_each_q_vector(vsi, i) {
2105 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2108 q_vector->reg_idx = 0;
2115 * ice_cfg_sw_lldp - Config switch rules for LLDP packet handling
2116 * @vsi: the VSI being configured
2117 * @tx: bool to determine Tx or Rx rule
2118 * @create: bool to determine create or remove Rule
2120 void ice_cfg_sw_lldp(struct ice_vsi *vsi, bool tx, bool create)
2122 enum ice_status (*eth_fltr)(struct ice_vsi *v, u16 type, u16 flag,
2123 enum ice_sw_fwd_act_type act);
2124 struct ice_pf *pf = vsi->back;
2125 enum ice_status status;
2128 dev = ice_pf_to_dev(pf);
2129 eth_fltr = create ? ice_fltr_add_eth : ice_fltr_remove_eth;
2132 status = eth_fltr(vsi, ETH_P_LLDP, ICE_FLTR_TX,
2135 status = eth_fltr(vsi, ETH_P_LLDP, ICE_FLTR_RX, ICE_FWD_TO_VSI);
2138 dev_err(dev, "Fail %s %s LLDP rule on VSI %i error: %s\n",
2139 create ? "adding" : "removing", tx ? "TX" : "RX",
2140 vsi->vsi_num, ice_stat_str(status));
2144 * ice_vsi_setup - Set up a VSI by a given type
2145 * @pf: board private structure
2146 * @pi: pointer to the port_info instance
2147 * @vsi_type: VSI type
2148 * @vf_id: defines VF ID to which this VSI connects. This field is meant to be
2149 * used only for ICE_VSI_VF VSI type. For other VSI types, should
2150 * fill-in ICE_INVAL_VFID as input.
2152 * This allocates the sw VSI structure and its queue resources.
2154 * Returns pointer to the successfully allocated and configured VSI sw struct on
2155 * success, NULL on failure.
2158 ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
2159 enum ice_vsi_type vsi_type, u16 vf_id)
2161 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2162 struct device *dev = ice_pf_to_dev(pf);
2163 enum ice_status status;
2164 struct ice_vsi *vsi;
2167 if (vsi_type == ICE_VSI_VF)
2168 vsi = ice_vsi_alloc(pf, vsi_type, vf_id);
2170 vsi = ice_vsi_alloc(pf, vsi_type, ICE_INVAL_VFID);
2173 dev_err(dev, "could not allocate VSI\n");
2177 vsi->port_info = pi;
2178 vsi->vsw = pf->first_sw;
2179 if (vsi->type == ICE_VSI_PF)
2180 vsi->ethtype = ETH_P_PAUSE;
2182 if (vsi->type == ICE_VSI_VF)
2185 ice_alloc_fd_res(vsi);
2187 if (ice_vsi_get_qs(vsi)) {
2188 dev_err(dev, "Failed to allocate queues. vsi->idx = %d\n",
2190 goto unroll_vsi_alloc;
2193 /* set RSS capabilities */
2194 ice_vsi_set_rss_params(vsi);
2196 /* set TC configuration */
2197 ice_vsi_set_tc_cfg(vsi);
2199 /* create the VSI */
2200 ret = ice_vsi_init(vsi, true);
2204 switch (vsi->type) {
2207 ret = ice_vsi_alloc_q_vectors(vsi);
2209 goto unroll_vsi_init;
2211 ret = ice_vsi_setup_vector_base(vsi);
2213 goto unroll_alloc_q_vector;
2215 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2217 goto unroll_vector_base;
2219 ret = ice_vsi_alloc_rings(vsi);
2221 goto unroll_vector_base;
2223 /* Always add VLAN ID 0 switch rule by default. This is needed
2224 * in order to allow all untagged and 0 tagged priority traffic
2225 * if Rx VLAN pruning is enabled. Also there are cases where we
2226 * don't get the call to add VLAN 0 via ice_vlan_rx_add_vid()
2227 * so this handles those cases (i.e. adding the PF to a bridge
2228 * without the 8021q module loaded).
2230 ret = ice_vsi_add_vlan(vsi, 0, ICE_FWD_TO_VSI);
2232 goto unroll_clear_rings;
2234 ice_vsi_map_rings_to_vectors(vsi);
2236 /* ICE_VSI_CTRL does not need RSS so skip RSS processing */
2237 if (vsi->type != ICE_VSI_CTRL)
2238 /* Do not exit if configuring RSS had an issue, at
2239 * least receive traffic on first queue. Hence no
2240 * need to capture return value
2242 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
2243 ice_vsi_cfg_rss_lut_key(vsi);
2244 ice_vsi_set_rss_flow_fld(vsi);
2249 /* VF driver will take care of creating netdev for this type and
2250 * map queues to vectors through Virtchnl, PF driver only
2251 * creates a VSI and corresponding structures for bookkeeping
2254 ret = ice_vsi_alloc_q_vectors(vsi);
2256 goto unroll_vsi_init;
2258 ret = ice_vsi_alloc_rings(vsi);
2260 goto unroll_alloc_q_vector;
2262 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2264 goto unroll_vector_base;
2266 /* Do not exit if configuring RSS had an issue, at least
2267 * receive traffic on first queue. Hence no need to capture
2270 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
2271 ice_vsi_cfg_rss_lut_key(vsi);
2272 ice_vsi_set_vf_rss_flow_fld(vsi);
2276 ret = ice_vsi_alloc_rings(vsi);
2278 goto unroll_vsi_init;
2281 /* clean up the resources and exit */
2282 goto unroll_vsi_init;
2285 /* configure VSI nodes based on number of queues and TC's */
2286 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2287 max_txqs[i] = vsi->alloc_txq;
2289 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2292 dev_err(dev, "VSI %d failed lan queue config, error %s\n",
2293 vsi->vsi_num, ice_stat_str(status));
2294 goto unroll_vector_base;
2297 /* Add switch rule to drop all Tx Flow Control Frames, of look up
2298 * type ETHERTYPE from VSIs, and restrict malicious VF from sending
2299 * out PAUSE or PFC frames. If enabled, FW can still send FC frames.
2300 * The rule is added once for PF VSI in order to create appropriate
2301 * recipe, since VSI/VSI list is ignored with drop action...
2302 * Also add rules to handle LLDP Tx packets. Tx LLDP packets need to
2303 * be dropped so that VFs cannot send LLDP packets to reconfig DCB
2304 * settings in the HW.
2306 if (!ice_is_safe_mode(pf))
2307 if (vsi->type == ICE_VSI_PF) {
2308 ice_fltr_add_eth(vsi, ETH_P_PAUSE, ICE_FLTR_TX,
2310 ice_cfg_sw_lldp(vsi, true, true);
2316 ice_vsi_clear_rings(vsi);
2318 /* reclaim SW interrupts back to the common pool */
2319 ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
2320 pf->num_avail_sw_msix += vsi->num_q_vectors;
2321 unroll_alloc_q_vector:
2322 ice_vsi_free_q_vectors(vsi);
2324 ice_vsi_delete(vsi);
2326 ice_vsi_put_qs(vsi);
2334 * ice_vsi_release_msix - Clear the queue to Interrupt mapping in HW
2335 * @vsi: the VSI being cleaned up
2337 static void ice_vsi_release_msix(struct ice_vsi *vsi)
2339 struct ice_pf *pf = vsi->back;
2340 struct ice_hw *hw = &pf->hw;
2345 for (i = 0; i < vsi->num_q_vectors; i++) {
2346 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2347 u16 reg_idx = q_vector->reg_idx;
2349 wr32(hw, GLINT_ITR(ICE_IDX_ITR0, reg_idx), 0);
2350 wr32(hw, GLINT_ITR(ICE_IDX_ITR1, reg_idx), 0);
2351 for (q = 0; q < q_vector->num_ring_tx; q++) {
2352 wr32(hw, QINT_TQCTL(vsi->txq_map[txq]), 0);
2353 if (ice_is_xdp_ena_vsi(vsi)) {
2354 u32 xdp_txq = txq + vsi->num_xdp_txq;
2356 wr32(hw, QINT_TQCTL(vsi->txq_map[xdp_txq]), 0);
2361 for (q = 0; q < q_vector->num_ring_rx; q++) {
2362 wr32(hw, QINT_RQCTL(vsi->rxq_map[rxq]), 0);
2371 * ice_vsi_free_irq - Free the IRQ association with the OS
2372 * @vsi: the VSI being configured
2374 void ice_vsi_free_irq(struct ice_vsi *vsi)
2376 struct ice_pf *pf = vsi->back;
2377 int base = vsi->base_vector;
2380 if (!vsi->q_vectors || !vsi->irqs_ready)
2383 ice_vsi_release_msix(vsi);
2384 if (vsi->type == ICE_VSI_VF)
2387 vsi->irqs_ready = false;
2388 ice_for_each_q_vector(vsi, i) {
2389 u16 vector = i + base;
2392 irq_num = pf->msix_entries[vector].vector;
2394 /* free only the irqs that were actually requested */
2395 if (!vsi->q_vectors[i] ||
2396 !(vsi->q_vectors[i]->num_ring_tx ||
2397 vsi->q_vectors[i]->num_ring_rx))
2400 /* clear the affinity notifier in the IRQ descriptor */
2401 irq_set_affinity_notifier(irq_num, NULL);
2403 /* clear the affinity_mask in the IRQ descriptor */
2404 irq_set_affinity_hint(irq_num, NULL);
2405 synchronize_irq(irq_num);
2406 devm_free_irq(ice_pf_to_dev(pf), irq_num, vsi->q_vectors[i]);
2411 * ice_vsi_free_tx_rings - Free Tx resources for VSI queues
2412 * @vsi: the VSI having resources freed
2414 void ice_vsi_free_tx_rings(struct ice_vsi *vsi)
2421 ice_for_each_txq(vsi, i)
2422 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
2423 ice_free_tx_ring(vsi->tx_rings[i]);
2427 * ice_vsi_free_rx_rings - Free Rx resources for VSI queues
2428 * @vsi: the VSI having resources freed
2430 void ice_vsi_free_rx_rings(struct ice_vsi *vsi)
2437 ice_for_each_rxq(vsi, i)
2438 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
2439 ice_free_rx_ring(vsi->rx_rings[i]);
2443 * ice_vsi_close - Shut down a VSI
2444 * @vsi: the VSI being shut down
2446 void ice_vsi_close(struct ice_vsi *vsi)
2448 if (!test_and_set_bit(__ICE_DOWN, vsi->state))
2451 ice_vsi_free_irq(vsi);
2452 ice_vsi_free_tx_rings(vsi);
2453 ice_vsi_free_rx_rings(vsi);
2457 * ice_ena_vsi - resume a VSI
2458 * @vsi: the VSI being resume
2459 * @locked: is the rtnl_lock already held
2461 int ice_ena_vsi(struct ice_vsi *vsi, bool locked)
2465 if (!test_bit(__ICE_NEEDS_RESTART, vsi->state))
2468 clear_bit(__ICE_NEEDS_RESTART, vsi->state);
2470 if (vsi->netdev && vsi->type == ICE_VSI_PF) {
2471 if (netif_running(vsi->netdev)) {
2475 err = ice_open(vsi->netdev);
2480 } else if (vsi->type == ICE_VSI_CTRL) {
2481 err = ice_vsi_open_ctrl(vsi);
2488 * ice_dis_vsi - pause a VSI
2489 * @vsi: the VSI being paused
2490 * @locked: is the rtnl_lock already held
2492 void ice_dis_vsi(struct ice_vsi *vsi, bool locked)
2494 if (test_bit(__ICE_DOWN, vsi->state))
2497 set_bit(__ICE_NEEDS_RESTART, vsi->state);
2499 if (vsi->type == ICE_VSI_PF && vsi->netdev) {
2500 if (netif_running(vsi->netdev)) {
2504 ice_stop(vsi->netdev);
2511 } else if (vsi->type == ICE_VSI_CTRL) {
2517 * ice_vsi_dis_irq - Mask off queue interrupt generation on the VSI
2518 * @vsi: the VSI being un-configured
2520 void ice_vsi_dis_irq(struct ice_vsi *vsi)
2522 int base = vsi->base_vector;
2523 struct ice_pf *pf = vsi->back;
2524 struct ice_hw *hw = &pf->hw;
2528 /* disable interrupt causation from each queue */
2529 if (vsi->tx_rings) {
2530 ice_for_each_txq(vsi, i) {
2531 if (vsi->tx_rings[i]) {
2534 reg = vsi->tx_rings[i]->reg_idx;
2535 val = rd32(hw, QINT_TQCTL(reg));
2536 val &= ~QINT_TQCTL_CAUSE_ENA_M;
2537 wr32(hw, QINT_TQCTL(reg), val);
2542 if (vsi->rx_rings) {
2543 ice_for_each_rxq(vsi, i) {
2544 if (vsi->rx_rings[i]) {
2547 reg = vsi->rx_rings[i]->reg_idx;
2548 val = rd32(hw, QINT_RQCTL(reg));
2549 val &= ~QINT_RQCTL_CAUSE_ENA_M;
2550 wr32(hw, QINT_RQCTL(reg), val);
2555 /* disable each interrupt */
2556 ice_for_each_q_vector(vsi, i) {
2557 if (!vsi->q_vectors[i])
2559 wr32(hw, GLINT_DYN_CTL(vsi->q_vectors[i]->reg_idx), 0);
2564 /* don't call synchronize_irq() for VF's from the host */
2565 if (vsi->type == ICE_VSI_VF)
2568 ice_for_each_q_vector(vsi, i)
2569 synchronize_irq(pf->msix_entries[i + base].vector);
2573 * ice_napi_del - Remove NAPI handler for the VSI
2574 * @vsi: VSI for which NAPI handler is to be removed
2576 void ice_napi_del(struct ice_vsi *vsi)
2583 ice_for_each_q_vector(vsi, v_idx)
2584 netif_napi_del(&vsi->q_vectors[v_idx]->napi);
2588 * ice_vsi_release - Delete a VSI and free its resources
2589 * @vsi: the VSI being removed
2591 * Returns 0 on success or < 0 on error
2593 int ice_vsi_release(struct ice_vsi *vsi)
2601 /* do not unregister while driver is in the reset recovery pending
2602 * state. Since reset/rebuild happens through PF service task workqueue,
2603 * it's not a good idea to unregister netdev that is associated to the
2604 * PF that is running the work queue items currently. This is done to
2605 * avoid check_flush_dependency() warning on this wq
2607 if (vsi->netdev && !ice_is_reset_in_progress(pf->state))
2608 unregister_netdev(vsi->netdev);
2610 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2613 /* Disable VSI and free resources */
2614 if (vsi->type != ICE_VSI_LB)
2615 ice_vsi_dis_irq(vsi);
2618 /* SR-IOV determines needed MSIX resources all at once instead of per
2619 * VSI since when VFs are spawned we know how many VFs there are and how
2620 * many interrupts each VF needs. SR-IOV MSIX resources are also
2621 * cleared in the same manner.
2623 if (vsi->type != ICE_VSI_VF) {
2624 /* reclaim SW interrupts back to the common pool */
2625 ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
2626 pf->num_avail_sw_msix += vsi->num_q_vectors;
2629 if (!ice_is_safe_mode(pf)) {
2630 if (vsi->type == ICE_VSI_PF) {
2631 ice_fltr_remove_eth(vsi, ETH_P_PAUSE, ICE_FLTR_TX,
2633 ice_cfg_sw_lldp(vsi, true, false);
2634 /* The Rx rule will only exist to remove if the LLDP FW
2635 * engine is currently stopped
2637 if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags))
2638 ice_cfg_sw_lldp(vsi, false, false);
2642 ice_fltr_remove_all(vsi);
2643 ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx);
2644 ice_vsi_delete(vsi);
2645 ice_vsi_free_q_vectors(vsi);
2647 /* make sure unregister_netdev() was called by checking __ICE_DOWN */
2648 if (vsi->netdev && test_bit(__ICE_DOWN, vsi->state)) {
2649 free_netdev(vsi->netdev);
2653 ice_vsi_clear_rings(vsi);
2655 ice_vsi_put_qs(vsi);
2657 /* retain SW VSI data structure since it is needed to unregister and
2658 * free VSI netdev when PF is not in reset recovery pending state,\
2659 * for ex: during rmmod.
2661 if (!ice_is_reset_in_progress(pf->state))
2668 * ice_vsi_rebuild_update_coalesce - set coalesce for a q_vector
2669 * @q_vector: pointer to q_vector which is being updated
2670 * @coalesce: pointer to array of struct with stored coalesce
2672 * Set coalesce param in q_vector and update these parameters in HW.
2675 ice_vsi_rebuild_update_coalesce(struct ice_q_vector *q_vector,
2676 struct ice_coalesce_stored *coalesce)
2678 struct ice_ring_container *rx_rc = &q_vector->rx;
2679 struct ice_ring_container *tx_rc = &q_vector->tx;
2680 struct ice_hw *hw = &q_vector->vsi->back->hw;
2682 tx_rc->itr_setting = coalesce->itr_tx;
2683 rx_rc->itr_setting = coalesce->itr_rx;
2685 /* dynamic ITR values will be updated during Tx/Rx */
2686 if (!ITR_IS_DYNAMIC(tx_rc->itr_setting))
2687 wr32(hw, GLINT_ITR(tx_rc->itr_idx, q_vector->reg_idx),
2688 ITR_REG_ALIGN(tx_rc->itr_setting) >>
2690 if (!ITR_IS_DYNAMIC(rx_rc->itr_setting))
2691 wr32(hw, GLINT_ITR(rx_rc->itr_idx, q_vector->reg_idx),
2692 ITR_REG_ALIGN(rx_rc->itr_setting) >>
2695 q_vector->intrl = coalesce->intrl;
2696 wr32(hw, GLINT_RATE(q_vector->reg_idx),
2697 ice_intrl_usec_to_reg(q_vector->intrl, hw->intrl_gran));
2701 * ice_vsi_rebuild_get_coalesce - get coalesce from all q_vectors
2702 * @vsi: VSI connected with q_vectors
2703 * @coalesce: array of struct with stored coalesce
2705 * Returns array size.
2708 ice_vsi_rebuild_get_coalesce(struct ice_vsi *vsi,
2709 struct ice_coalesce_stored *coalesce)
2713 ice_for_each_q_vector(vsi, i) {
2714 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2716 coalesce[i].itr_tx = q_vector->tx.itr_setting;
2717 coalesce[i].itr_rx = q_vector->rx.itr_setting;
2718 coalesce[i].intrl = q_vector->intrl;
2721 return vsi->num_q_vectors;
2725 * ice_vsi_rebuild_set_coalesce - set coalesce from earlier saved arrays
2726 * @vsi: VSI connected with q_vectors
2727 * @coalesce: pointer to array of struct with stored coalesce
2728 * @size: size of coalesce array
2730 * Before this function, ice_vsi_rebuild_get_coalesce should be called to save
2731 * ITR params in arrays. If size is 0 or coalesce wasn't stored set coalesce
2735 ice_vsi_rebuild_set_coalesce(struct ice_vsi *vsi,
2736 struct ice_coalesce_stored *coalesce, int size)
2740 if ((size && !coalesce) || !vsi)
2743 for (i = 0; i < size && i < vsi->num_q_vectors; i++)
2744 ice_vsi_rebuild_update_coalesce(vsi->q_vectors[i],
2747 /* number of q_vectors increased, so assume coalesce settings were
2748 * changed globally (i.e. ethtool -C eth0 instead of per-queue) and use
2749 * the previous settings from q_vector 0 for all of the new q_vectors
2751 for (; i < vsi->num_q_vectors; i++)
2752 ice_vsi_rebuild_update_coalesce(vsi->q_vectors[i],
2757 * ice_vsi_rebuild - Rebuild VSI after reset
2758 * @vsi: VSI to be rebuild
2759 * @init_vsi: is this an initialization or a reconfigure of the VSI
2761 * Returns 0 on success and negative value on failure
2763 int ice_vsi_rebuild(struct ice_vsi *vsi, bool init_vsi)
2765 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2766 struct ice_coalesce_stored *coalesce;
2767 int prev_num_q_vectors = 0;
2768 struct ice_vf *vf = NULL;
2769 enum ice_status status;
2777 if (vsi->type == ICE_VSI_VF)
2778 vf = &pf->vf[vsi->vf_id];
2780 coalesce = kcalloc(vsi->num_q_vectors,
2781 sizeof(struct ice_coalesce_stored), GFP_KERNEL);
2783 prev_num_q_vectors = ice_vsi_rebuild_get_coalesce(vsi,
2785 ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx);
2786 ice_vsi_free_q_vectors(vsi);
2788 /* SR-IOV determines needed MSIX resources all at once instead of per
2789 * VSI since when VFs are spawned we know how many VFs there are and how
2790 * many interrupts each VF needs. SR-IOV MSIX resources are also
2791 * cleared in the same manner.
2793 if (vsi->type != ICE_VSI_VF) {
2794 /* reclaim SW interrupts back to the common pool */
2795 ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
2796 pf->num_avail_sw_msix += vsi->num_q_vectors;
2797 vsi->base_vector = 0;
2800 if (ice_is_xdp_ena_vsi(vsi))
2801 /* return value check can be skipped here, it always returns
2802 * 0 if reset is in progress
2804 ice_destroy_xdp_rings(vsi);
2805 ice_vsi_put_qs(vsi);
2806 ice_vsi_clear_rings(vsi);
2807 ice_vsi_free_arrays(vsi);
2808 if (vsi->type == ICE_VSI_VF)
2809 ice_vsi_set_num_qs(vsi, vf->vf_id);
2811 ice_vsi_set_num_qs(vsi, ICE_INVAL_VFID);
2813 ret = ice_vsi_alloc_arrays(vsi);
2817 ice_vsi_get_qs(vsi);
2819 ice_alloc_fd_res(vsi);
2820 ice_vsi_set_tc_cfg(vsi);
2822 /* Initialize VSI struct elements and create VSI in FW */
2823 ret = ice_vsi_init(vsi, init_vsi);
2827 switch (vsi->type) {
2830 ret = ice_vsi_alloc_q_vectors(vsi);
2834 ret = ice_vsi_setup_vector_base(vsi);
2838 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2842 ret = ice_vsi_alloc_rings(vsi);
2846 ice_vsi_map_rings_to_vectors(vsi);
2847 if (ice_is_xdp_ena_vsi(vsi)) {
2848 vsi->num_xdp_txq = vsi->alloc_rxq;
2849 ret = ice_prepare_xdp_rings(vsi, vsi->xdp_prog);
2853 /* ICE_VSI_CTRL does not need RSS so skip RSS processing */
2854 if (vsi->type != ICE_VSI_CTRL)
2855 /* Do not exit if configuring RSS had an issue, at
2856 * least receive traffic on first queue. Hence no
2857 * need to capture return value
2859 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2860 ice_vsi_cfg_rss_lut_key(vsi);
2863 ret = ice_vsi_alloc_q_vectors(vsi);
2867 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2871 ret = ice_vsi_alloc_rings(vsi);
2880 /* configure VSI nodes based on number of queues and TC's */
2881 for (i = 0; i < vsi->tc_cfg.numtc; i++) {
2882 max_txqs[i] = vsi->alloc_txq;
2884 if (ice_is_xdp_ena_vsi(vsi))
2885 max_txqs[i] += vsi->num_xdp_txq;
2888 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2891 dev_err(ice_pf_to_dev(pf), "VSI %d failed lan queue config, error %s\n",
2892 vsi->vsi_num, ice_stat_str(status));
2897 return ice_schedule_reset(pf, ICE_RESET_PFR);
2900 ice_vsi_rebuild_set_coalesce(vsi, coalesce, prev_num_q_vectors);
2906 ice_vsi_free_q_vectors(vsi);
2909 vsi->current_netdev_flags = 0;
2910 unregister_netdev(vsi->netdev);
2911 free_netdev(vsi->netdev);
2916 set_bit(__ICE_RESET_FAILED, pf->state);
2922 * ice_is_reset_in_progress - check for a reset in progress
2923 * @state: PF state field
2925 bool ice_is_reset_in_progress(unsigned long *state)
2927 return test_bit(__ICE_RESET_OICR_RECV, state) ||
2928 test_bit(__ICE_DCBNL_DEVRESET, state) ||
2929 test_bit(__ICE_PFR_REQ, state) ||
2930 test_bit(__ICE_CORER_REQ, state) ||
2931 test_bit(__ICE_GLOBR_REQ, state);
2936 * ice_vsi_update_q_map - update our copy of the VSI info with new queue map
2937 * @vsi: VSI being configured
2938 * @ctx: the context buffer returned from AQ VSI update command
2940 static void ice_vsi_update_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctx)
2942 vsi->info.mapping_flags = ctx->info.mapping_flags;
2943 memcpy(&vsi->info.q_mapping, &ctx->info.q_mapping,
2944 sizeof(vsi->info.q_mapping));
2945 memcpy(&vsi->info.tc_mapping, ctx->info.tc_mapping,
2946 sizeof(vsi->info.tc_mapping));
2950 * ice_vsi_cfg_tc - Configure VSI Tx Sched for given TC map
2951 * @vsi: VSI to be configured
2952 * @ena_tc: TC bitmap
2954 * VSI queues expected to be quiesced before calling this function
2956 int ice_vsi_cfg_tc(struct ice_vsi *vsi, u8 ena_tc)
2958 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2959 struct ice_pf *pf = vsi->back;
2960 struct ice_vsi_ctx *ctx;
2961 enum ice_status status;
2966 dev = ice_pf_to_dev(pf);
2968 ice_for_each_traffic_class(i) {
2969 /* build bitmap of enabled TCs */
2970 if (ena_tc & BIT(i))
2972 /* populate max_txqs per TC */
2973 max_txqs[i] = vsi->alloc_txq;
2976 vsi->tc_cfg.ena_tc = ena_tc;
2977 vsi->tc_cfg.numtc = num_tc;
2979 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
2984 ctx->info = vsi->info;
2986 ice_vsi_setup_q_map(vsi, ctx);
2988 /* must to indicate which section of VSI context are being modified */
2989 ctx->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
2990 status = ice_update_vsi(&pf->hw, vsi->idx, ctx, NULL);
2992 dev_info(dev, "Failed VSI Update\n");
2997 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
3001 dev_err(dev, "VSI %d failed TC config, error %s\n",
3002 vsi->vsi_num, ice_stat_str(status));
3006 ice_vsi_update_q_map(vsi, ctx);
3007 vsi->info.valid_sections = 0;
3009 ice_vsi_cfg_netdev_tc(vsi, ena_tc);
3014 #endif /* CONFIG_DCB */
3017 * ice_update_ring_stats - Update ring statistics
3018 * @ring: ring to update
3019 * @cont: used to increment per-vector counters
3020 * @pkts: number of processed packets
3021 * @bytes: number of processed bytes
3023 * This function assumes that caller has acquired a u64_stats_sync lock.
3026 ice_update_ring_stats(struct ice_ring *ring, struct ice_ring_container *cont,
3027 u64 pkts, u64 bytes)
3029 ring->stats.bytes += bytes;
3030 ring->stats.pkts += pkts;
3031 cont->total_bytes += bytes;
3032 cont->total_pkts += pkts;
3036 * ice_update_tx_ring_stats - Update Tx ring specific counters
3037 * @tx_ring: ring to update
3038 * @pkts: number of processed packets
3039 * @bytes: number of processed bytes
3041 void ice_update_tx_ring_stats(struct ice_ring *tx_ring, u64 pkts, u64 bytes)
3043 u64_stats_update_begin(&tx_ring->syncp);
3044 ice_update_ring_stats(tx_ring, &tx_ring->q_vector->tx, pkts, bytes);
3045 u64_stats_update_end(&tx_ring->syncp);
3049 * ice_update_rx_ring_stats - Update Rx ring specific counters
3050 * @rx_ring: ring to update
3051 * @pkts: number of processed packets
3052 * @bytes: number of processed bytes
3054 void ice_update_rx_ring_stats(struct ice_ring *rx_ring, u64 pkts, u64 bytes)
3056 u64_stats_update_begin(&rx_ring->syncp);
3057 ice_update_ring_stats(rx_ring, &rx_ring->q_vector->rx, pkts, bytes);
3058 u64_stats_update_end(&rx_ring->syncp);
3062 * ice_status_to_errno - convert from enum ice_status to Linux errno
3063 * @err: ice_status value to convert
3065 int ice_status_to_errno(enum ice_status err)
3070 case ICE_ERR_DOES_NOT_EXIST:
3072 case ICE_ERR_OUT_OF_RANGE:
3076 case ICE_ERR_NO_MEMORY:
3078 case ICE_ERR_MAX_LIMIT:
3086 * ice_is_dflt_vsi_in_use - check if the default forwarding VSI is being used
3087 * @sw: switch to check if its default forwarding VSI is free
3089 * Return true if the default forwarding VSI is already being used, else returns
3090 * false signalling that it's available to use.
3092 bool ice_is_dflt_vsi_in_use(struct ice_sw *sw)
3094 return (sw->dflt_vsi && sw->dflt_vsi_ena);
3098 * ice_is_vsi_dflt_vsi - check if the VSI passed in is the default VSI
3099 * @sw: switch for the default forwarding VSI to compare against
3100 * @vsi: VSI to compare against default forwarding VSI
3102 * If this VSI passed in is the default forwarding VSI then return true, else
3105 bool ice_is_vsi_dflt_vsi(struct ice_sw *sw, struct ice_vsi *vsi)
3107 return (sw->dflt_vsi == vsi && sw->dflt_vsi_ena);
3111 * ice_set_dflt_vsi - set the default forwarding VSI
3112 * @sw: switch used to assign the default forwarding VSI
3113 * @vsi: VSI getting set as the default forwarding VSI on the switch
3115 * If the VSI passed in is already the default VSI and it's enabled just return
3118 * If there is already a default VSI on the switch and it's enabled then return
3119 * -EEXIST since there can only be one default VSI per switch.
3121 * Otherwise try to set the VSI passed in as the switch's default VSI and
3122 * return the result.
3124 int ice_set_dflt_vsi(struct ice_sw *sw, struct ice_vsi *vsi)
3126 enum ice_status status;
3132 dev = ice_pf_to_dev(vsi->back);
3134 /* the VSI passed in is already the default VSI */
3135 if (ice_is_vsi_dflt_vsi(sw, vsi)) {
3136 dev_dbg(dev, "VSI %d passed in is already the default forwarding VSI, nothing to do\n",
3141 /* another VSI is already the default VSI for this switch */
3142 if (ice_is_dflt_vsi_in_use(sw)) {
3143 dev_err(dev, "Default forwarding VSI %d already in use, disable it and try again\n",
3144 sw->dflt_vsi->vsi_num);
3148 status = ice_cfg_dflt_vsi(&vsi->back->hw, vsi->idx, true, ICE_FLTR_RX);
3150 dev_err(dev, "Failed to set VSI %d as the default forwarding VSI, error %s\n",
3151 vsi->vsi_num, ice_stat_str(status));
3156 sw->dflt_vsi_ena = true;
3162 * ice_clear_dflt_vsi - clear the default forwarding VSI
3163 * @sw: switch used to clear the default VSI
3165 * If the switch has no default VSI or it's not enabled then return error.
3167 * Otherwise try to clear the default VSI and return the result.
3169 int ice_clear_dflt_vsi(struct ice_sw *sw)
3171 struct ice_vsi *dflt_vsi;
3172 enum ice_status status;
3178 dev = ice_pf_to_dev(sw->pf);
3180 dflt_vsi = sw->dflt_vsi;
3182 /* there is no default VSI configured */
3183 if (!ice_is_dflt_vsi_in_use(sw))
3186 status = ice_cfg_dflt_vsi(&dflt_vsi->back->hw, dflt_vsi->idx, false,
3189 dev_err(dev, "Failed to clear the default forwarding VSI %d, error %s\n",
3190 dflt_vsi->vsi_num, ice_stat_str(status));
3194 sw->dflt_vsi = NULL;
3195 sw->dflt_vsi_ena = false;