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 static 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 static 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 static 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 /* Avoid stale references by clearing map from vector to ring */
1200 if (vsi->q_vectors) {
1201 ice_for_each_q_vector(vsi, i) {
1202 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1205 q_vector->tx.ring = NULL;
1206 q_vector->rx.ring = NULL;
1211 if (vsi->tx_rings) {
1212 for (i = 0; i < vsi->alloc_txq; i++) {
1213 if (vsi->tx_rings[i]) {
1214 kfree_rcu(vsi->tx_rings[i], rcu);
1215 WRITE_ONCE(vsi->tx_rings[i], NULL);
1219 if (vsi->rx_rings) {
1220 for (i = 0; i < vsi->alloc_rxq; i++) {
1221 if (vsi->rx_rings[i]) {
1222 kfree_rcu(vsi->rx_rings[i], rcu);
1223 WRITE_ONCE(vsi->rx_rings[i], NULL);
1230 * ice_vsi_alloc_rings - Allocates Tx and Rx rings for the VSI
1231 * @vsi: VSI which is having rings allocated
1233 static int ice_vsi_alloc_rings(struct ice_vsi *vsi)
1235 struct ice_pf *pf = vsi->back;
1239 dev = ice_pf_to_dev(pf);
1240 /* Allocate Tx rings */
1241 for (i = 0; i < vsi->alloc_txq; i++) {
1242 struct ice_ring *ring;
1244 /* allocate with kzalloc(), free with kfree_rcu() */
1245 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1251 ring->reg_idx = vsi->txq_map[i];
1252 ring->ring_active = false;
1255 ring->count = vsi->num_tx_desc;
1256 WRITE_ONCE(vsi->tx_rings[i], ring);
1259 /* Allocate Rx rings */
1260 for (i = 0; i < vsi->alloc_rxq; i++) {
1261 struct ice_ring *ring;
1263 /* allocate with kzalloc(), free with kfree_rcu() */
1264 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1269 ring->reg_idx = vsi->rxq_map[i];
1270 ring->ring_active = false;
1272 ring->netdev = vsi->netdev;
1274 ring->count = vsi->num_rx_desc;
1275 WRITE_ONCE(vsi->rx_rings[i], ring);
1281 ice_vsi_clear_rings(vsi);
1286 * ice_vsi_manage_rss_lut - disable/enable RSS
1287 * @vsi: the VSI being changed
1288 * @ena: boolean value indicating if this is an enable or disable request
1290 * In the event of disable request for RSS, this function will zero out RSS
1291 * LUT, while in the event of enable request for RSS, it will reconfigure RSS
1294 int ice_vsi_manage_rss_lut(struct ice_vsi *vsi, bool ena)
1299 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
1304 if (vsi->rss_lut_user)
1305 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1307 ice_fill_rss_lut(lut, vsi->rss_table_size,
1311 err = ice_set_rss(vsi, NULL, lut, vsi->rss_table_size);
1317 * ice_vsi_cfg_rss_lut_key - Configure RSS params for a VSI
1318 * @vsi: VSI to be configured
1320 static int ice_vsi_cfg_rss_lut_key(struct ice_vsi *vsi)
1322 struct ice_aqc_get_set_rss_keys *key;
1323 struct ice_pf *pf = vsi->back;
1324 enum ice_status status;
1329 dev = ice_pf_to_dev(pf);
1330 vsi->rss_size = min_t(u16, vsi->rss_size, vsi->num_rxq);
1332 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
1336 if (vsi->rss_lut_user)
1337 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1339 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
1341 status = ice_aq_set_rss_lut(&pf->hw, vsi->idx, vsi->rss_lut_type, lut,
1342 vsi->rss_table_size);
1345 dev_err(dev, "set_rss_lut failed, error %s\n",
1346 ice_stat_str(status));
1348 goto ice_vsi_cfg_rss_exit;
1351 key = kzalloc(sizeof(*key), GFP_KERNEL);
1354 goto ice_vsi_cfg_rss_exit;
1357 if (vsi->rss_hkey_user)
1359 (struct ice_aqc_get_set_rss_keys *)vsi->rss_hkey_user,
1360 ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE);
1362 netdev_rss_key_fill((void *)key,
1363 ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE);
1365 status = ice_aq_set_rss_key(&pf->hw, vsi->idx, key);
1368 dev_err(dev, "set_rss_key failed, error %s\n",
1369 ice_stat_str(status));
1374 ice_vsi_cfg_rss_exit:
1380 * ice_vsi_set_vf_rss_flow_fld - Sets VF VSI RSS input set for different flows
1381 * @vsi: VSI to be configured
1383 * This function will only be called during the VF VSI setup. Upon successful
1384 * completion of package download, this function will configure default RSS
1385 * input sets for VF VSI.
1387 static void ice_vsi_set_vf_rss_flow_fld(struct ice_vsi *vsi)
1389 struct ice_pf *pf = vsi->back;
1390 enum ice_status status;
1393 dev = ice_pf_to_dev(pf);
1394 if (ice_is_safe_mode(pf)) {
1395 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
1400 status = ice_add_avf_rss_cfg(&pf->hw, vsi->idx, ICE_DEFAULT_RSS_HENA);
1402 dev_dbg(dev, "ice_add_avf_rss_cfg failed for vsi = %d, error = %s\n",
1403 vsi->vsi_num, ice_stat_str(status));
1407 * ice_vsi_set_rss_flow_fld - Sets RSS input set for different flows
1408 * @vsi: VSI to be configured
1410 * This function will only be called after successful download package call
1411 * during initialization of PF. Since the downloaded package will erase the
1412 * RSS section, this function will configure RSS input sets for different
1413 * flow types. The last profile added has the highest priority, therefore 2
1414 * tuple profiles (i.e. IPv4 src/dst) are added before 4 tuple profiles
1415 * (i.e. IPv4 src/dst TCP src/dst port).
1417 static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi)
1419 u16 vsi_handle = vsi->idx, vsi_num = vsi->vsi_num;
1420 struct ice_pf *pf = vsi->back;
1421 struct ice_hw *hw = &pf->hw;
1422 enum ice_status status;
1425 dev = ice_pf_to_dev(pf);
1426 if (ice_is_safe_mode(pf)) {
1427 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
1431 /* configure RSS for IPv4 with input set IP src/dst */
1432 status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV4,
1433 ICE_FLOW_SEG_HDR_IPV4);
1435 dev_dbg(dev, "ice_add_rss_cfg failed for ipv4 flow, vsi = %d, error = %s\n",
1436 vsi_num, ice_stat_str(status));
1438 /* configure RSS for IPv6 with input set IPv6 src/dst */
1439 status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV6,
1440 ICE_FLOW_SEG_HDR_IPV6);
1442 dev_dbg(dev, "ice_add_rss_cfg failed for ipv6 flow, vsi = %d, error = %s\n",
1443 vsi_num, ice_stat_str(status));
1445 /* configure RSS for tcp4 with input set IP src/dst, TCP src/dst */
1446 status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_TCP_IPV4,
1447 ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4);
1449 dev_dbg(dev, "ice_add_rss_cfg failed for tcp4 flow, vsi = %d, error = %s\n",
1450 vsi_num, ice_stat_str(status));
1452 /* configure RSS for udp4 with input set IP src/dst, UDP src/dst */
1453 status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_UDP_IPV4,
1454 ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4);
1456 dev_dbg(dev, "ice_add_rss_cfg failed for udp4 flow, vsi = %d, error = %s\n",
1457 vsi_num, ice_stat_str(status));
1459 /* configure RSS for sctp4 with input set IP src/dst */
1460 status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV4,
1461 ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4);
1463 dev_dbg(dev, "ice_add_rss_cfg failed for sctp4 flow, vsi = %d, error = %s\n",
1464 vsi_num, ice_stat_str(status));
1466 /* configure RSS for tcp6 with input set IPv6 src/dst, TCP src/dst */
1467 status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_TCP_IPV6,
1468 ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6);
1470 dev_dbg(dev, "ice_add_rss_cfg failed for tcp6 flow, vsi = %d, error = %s\n",
1471 vsi_num, ice_stat_str(status));
1473 /* configure RSS for udp6 with input set IPv6 src/dst, UDP src/dst */
1474 status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_UDP_IPV6,
1475 ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6);
1477 dev_dbg(dev, "ice_add_rss_cfg failed for udp6 flow, vsi = %d, error = %s\n",
1478 vsi_num, ice_stat_str(status));
1480 /* configure RSS for sctp6 with input set IPv6 src/dst */
1481 status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV6,
1482 ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6);
1484 dev_dbg(dev, "ice_add_rss_cfg failed for sctp6 flow, vsi = %d, error = %s\n",
1485 vsi_num, ice_stat_str(status));
1489 * ice_pf_state_is_nominal - checks the PF for nominal state
1490 * @pf: pointer to PF to check
1492 * Check the PF's state for a collection of bits that would indicate
1493 * the PF is in a state that would inhibit normal operation for
1494 * driver functionality.
1496 * Returns true if PF is in a nominal state, false otherwise
1498 bool ice_pf_state_is_nominal(struct ice_pf *pf)
1500 DECLARE_BITMAP(check_bits, __ICE_STATE_NBITS) = { 0 };
1505 bitmap_set(check_bits, 0, __ICE_STATE_NOMINAL_CHECK_BITS);
1506 if (bitmap_intersects(pf->state, check_bits, __ICE_STATE_NBITS))
1513 * ice_update_eth_stats - Update VSI-specific ethernet statistics counters
1514 * @vsi: the VSI to be updated
1516 void ice_update_eth_stats(struct ice_vsi *vsi)
1518 struct ice_eth_stats *prev_es, *cur_es;
1519 struct ice_hw *hw = &vsi->back->hw;
1520 u16 vsi_num = vsi->vsi_num; /* HW absolute index of a VSI */
1522 prev_es = &vsi->eth_stats_prev;
1523 cur_es = &vsi->eth_stats;
1525 ice_stat_update40(hw, GLV_GORCL(vsi_num), vsi->stat_offsets_loaded,
1526 &prev_es->rx_bytes, &cur_es->rx_bytes);
1528 ice_stat_update40(hw, GLV_UPRCL(vsi_num), vsi->stat_offsets_loaded,
1529 &prev_es->rx_unicast, &cur_es->rx_unicast);
1531 ice_stat_update40(hw, GLV_MPRCL(vsi_num), vsi->stat_offsets_loaded,
1532 &prev_es->rx_multicast, &cur_es->rx_multicast);
1534 ice_stat_update40(hw, GLV_BPRCL(vsi_num), vsi->stat_offsets_loaded,
1535 &prev_es->rx_broadcast, &cur_es->rx_broadcast);
1537 ice_stat_update32(hw, GLV_RDPC(vsi_num), vsi->stat_offsets_loaded,
1538 &prev_es->rx_discards, &cur_es->rx_discards);
1540 ice_stat_update40(hw, GLV_GOTCL(vsi_num), vsi->stat_offsets_loaded,
1541 &prev_es->tx_bytes, &cur_es->tx_bytes);
1543 ice_stat_update40(hw, GLV_UPTCL(vsi_num), vsi->stat_offsets_loaded,
1544 &prev_es->tx_unicast, &cur_es->tx_unicast);
1546 ice_stat_update40(hw, GLV_MPTCL(vsi_num), vsi->stat_offsets_loaded,
1547 &prev_es->tx_multicast, &cur_es->tx_multicast);
1549 ice_stat_update40(hw, GLV_BPTCL(vsi_num), vsi->stat_offsets_loaded,
1550 &prev_es->tx_broadcast, &cur_es->tx_broadcast);
1552 ice_stat_update32(hw, GLV_TEPC(vsi_num), vsi->stat_offsets_loaded,
1553 &prev_es->tx_errors, &cur_es->tx_errors);
1555 vsi->stat_offsets_loaded = true;
1559 * ice_vsi_add_vlan - Add VSI membership for given VLAN
1560 * @vsi: the VSI being configured
1561 * @vid: VLAN ID to be added
1562 * @action: filter action to be performed on match
1565 ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid, enum ice_sw_fwd_act_type action)
1567 struct ice_pf *pf = vsi->back;
1571 dev = ice_pf_to_dev(pf);
1573 if (!ice_fltr_add_vlan(vsi, vid, action)) {
1577 dev_err(dev, "Failure Adding VLAN %d on VSI %i\n", vid,
1585 * ice_vsi_kill_vlan - Remove VSI membership for a given VLAN
1586 * @vsi: the VSI being configured
1587 * @vid: VLAN ID to be removed
1589 * Returns 0 on success and negative on failure
1591 int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid)
1593 struct ice_pf *pf = vsi->back;
1594 enum ice_status status;
1598 dev = ice_pf_to_dev(pf);
1600 status = ice_fltr_remove_vlan(vsi, vid, ICE_FWD_TO_VSI);
1603 } else if (status == ICE_ERR_DOES_NOT_EXIST) {
1604 dev_dbg(dev, "Failed to remove VLAN %d on VSI %i, it does not exist, status: %s\n",
1605 vid, vsi->vsi_num, ice_stat_str(status));
1607 dev_err(dev, "Error removing VLAN %d on vsi %i error: %s\n",
1608 vid, vsi->vsi_num, ice_stat_str(status));
1616 * ice_vsi_cfg_frame_size - setup max frame size and Rx buffer length
1619 void ice_vsi_cfg_frame_size(struct ice_vsi *vsi)
1621 if (!vsi->netdev || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags)) {
1622 vsi->max_frame = ICE_AQ_SET_MAC_FRAME_SIZE_MAX;
1623 vsi->rx_buf_len = ICE_RXBUF_2048;
1624 #if (PAGE_SIZE < 8192)
1625 } else if (!ICE_2K_TOO_SMALL_WITH_PADDING &&
1626 (vsi->netdev->mtu <= ETH_DATA_LEN)) {
1627 vsi->max_frame = ICE_RXBUF_1536 - NET_IP_ALIGN;
1628 vsi->rx_buf_len = ICE_RXBUF_1536 - NET_IP_ALIGN;
1631 vsi->max_frame = ICE_AQ_SET_MAC_FRAME_SIZE_MAX;
1632 #if (PAGE_SIZE < 8192)
1633 vsi->rx_buf_len = ICE_RXBUF_3072;
1635 vsi->rx_buf_len = ICE_RXBUF_2048;
1641 * ice_write_qrxflxp_cntxt - write/configure QRXFLXP_CNTXT register
1643 * @pf_q: index of the Rx queue in the PF's queue space
1644 * @rxdid: flexible descriptor RXDID
1645 * @prio: priority for the RXDID for this queue
1648 ice_write_qrxflxp_cntxt(struct ice_hw *hw, u16 pf_q, u32 rxdid, u32 prio)
1650 int regval = rd32(hw, QRXFLXP_CNTXT(pf_q));
1652 /* clear any previous values */
1653 regval &= ~(QRXFLXP_CNTXT_RXDID_IDX_M |
1654 QRXFLXP_CNTXT_RXDID_PRIO_M |
1655 QRXFLXP_CNTXT_TS_M);
1657 regval |= (rxdid << QRXFLXP_CNTXT_RXDID_IDX_S) &
1658 QRXFLXP_CNTXT_RXDID_IDX_M;
1660 regval |= (prio << QRXFLXP_CNTXT_RXDID_PRIO_S) &
1661 QRXFLXP_CNTXT_RXDID_PRIO_M;
1663 wr32(hw, QRXFLXP_CNTXT(pf_q), regval);
1667 * ice_vsi_cfg_rxqs - Configure the VSI for Rx
1668 * @vsi: the VSI being configured
1670 * Return 0 on success and a negative value on error
1671 * Configure the Rx VSI for operation.
1673 int ice_vsi_cfg_rxqs(struct ice_vsi *vsi)
1677 if (vsi->type == ICE_VSI_VF)
1680 ice_vsi_cfg_frame_size(vsi);
1682 /* set up individual rings */
1683 for (i = 0; i < vsi->num_rxq; i++) {
1686 err = ice_setup_rx_ctx(vsi->rx_rings[i]);
1688 dev_err(ice_pf_to_dev(vsi->back), "ice_setup_rx_ctx failed for RxQ %d, err %d\n",
1698 * ice_vsi_cfg_txqs - Configure the VSI for Tx
1699 * @vsi: the VSI being configured
1700 * @rings: Tx ring array to be configured
1702 * Return 0 on success and a negative value on error
1703 * Configure the Tx VSI for operation.
1706 ice_vsi_cfg_txqs(struct ice_vsi *vsi, struct ice_ring **rings)
1708 struct ice_aqc_add_tx_qgrp *qg_buf;
1712 qg_buf = kzalloc(struct_size(qg_buf, txqs, 1), GFP_KERNEL);
1716 qg_buf->num_txqs = 1;
1718 for (q_idx = 0; q_idx < vsi->num_txq; q_idx++) {
1719 err = ice_vsi_cfg_txq(vsi, rings[q_idx], qg_buf);
1730 * ice_vsi_cfg_lan_txqs - Configure the VSI for Tx
1731 * @vsi: the VSI being configured
1733 * Return 0 on success and a negative value on error
1734 * Configure the Tx VSI for operation.
1736 int ice_vsi_cfg_lan_txqs(struct ice_vsi *vsi)
1738 return ice_vsi_cfg_txqs(vsi, vsi->tx_rings);
1742 * ice_vsi_cfg_xdp_txqs - Configure Tx queues dedicated for XDP in given VSI
1743 * @vsi: the VSI being configured
1745 * Return 0 on success and a negative value on error
1746 * Configure the Tx queues dedicated for XDP in given VSI for operation.
1748 int ice_vsi_cfg_xdp_txqs(struct ice_vsi *vsi)
1753 ret = ice_vsi_cfg_txqs(vsi, vsi->xdp_rings);
1757 for (i = 0; i < vsi->num_xdp_txq; i++)
1758 vsi->xdp_rings[i]->xsk_umem = ice_xsk_umem(vsi->xdp_rings[i]);
1764 * ice_intrl_usec_to_reg - convert interrupt rate limit to register value
1765 * @intrl: interrupt rate limit in usecs
1766 * @gran: interrupt rate limit granularity in usecs
1768 * This function converts a decimal interrupt rate limit in usecs to the format
1769 * expected by firmware.
1771 u32 ice_intrl_usec_to_reg(u8 intrl, u8 gran)
1773 u32 val = intrl / gran;
1776 return val | GLINT_RATE_INTRL_ENA_M;
1781 * ice_vsi_cfg_msix - MSIX mode Interrupt Config in the HW
1782 * @vsi: the VSI being configured
1784 * This configures MSIX mode interrupts for the PF VSI, and should not be used
1787 void ice_vsi_cfg_msix(struct ice_vsi *vsi)
1789 struct ice_pf *pf = vsi->back;
1790 struct ice_hw *hw = &pf->hw;
1791 u16 txq = 0, rxq = 0;
1794 for (i = 0; i < vsi->num_q_vectors; i++) {
1795 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1796 u16 reg_idx = q_vector->reg_idx;
1798 ice_cfg_itr(hw, q_vector);
1800 wr32(hw, GLINT_RATE(reg_idx),
1801 ice_intrl_usec_to_reg(q_vector->intrl, hw->intrl_gran));
1803 /* Both Transmit Queue Interrupt Cause Control register
1804 * and Receive Queue Interrupt Cause control register
1805 * expects MSIX_INDX field to be the vector index
1806 * within the function space and not the absolute
1807 * vector index across PF or across device.
1808 * For SR-IOV VF VSIs queue vector index always starts
1809 * with 1 since first vector index(0) is used for OICR
1810 * in VF space. Since VMDq and other PF VSIs are within
1811 * the PF function space, use the vector index that is
1812 * tracked for this PF.
1814 for (q = 0; q < q_vector->num_ring_tx; q++) {
1815 ice_cfg_txq_interrupt(vsi, txq, reg_idx,
1816 q_vector->tx.itr_idx);
1820 for (q = 0; q < q_vector->num_ring_rx; q++) {
1821 ice_cfg_rxq_interrupt(vsi, rxq, reg_idx,
1822 q_vector->rx.itr_idx);
1829 * ice_vsi_manage_vlan_insertion - Manage VLAN insertion for the VSI for Tx
1830 * @vsi: the VSI being changed
1832 int ice_vsi_manage_vlan_insertion(struct ice_vsi *vsi)
1834 struct ice_hw *hw = &vsi->back->hw;
1835 struct ice_vsi_ctx *ctxt;
1836 enum ice_status status;
1839 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
1843 /* Here we are configuring the VSI to let the driver add VLAN tags by
1844 * setting vlan_flags to ICE_AQ_VSI_VLAN_MODE_ALL. The actual VLAN tag
1845 * insertion happens in the Tx hot path, in ice_tx_map.
1847 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_MODE_ALL;
1849 /* Preserve existing VLAN strip setting */
1850 ctxt->info.vlan_flags |= (vsi->info.vlan_flags &
1851 ICE_AQ_VSI_VLAN_EMOD_M);
1853 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
1855 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1857 dev_err(ice_pf_to_dev(vsi->back), "update VSI for VLAN insert failed, err %s aq_err %s\n",
1858 ice_stat_str(status),
1859 ice_aq_str(hw->adminq.sq_last_status));
1864 vsi->info.vlan_flags = ctxt->info.vlan_flags;
1871 * ice_vsi_manage_vlan_stripping - Manage VLAN stripping for the VSI for Rx
1872 * @vsi: the VSI being changed
1873 * @ena: boolean value indicating if this is a enable or disable request
1875 int ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
1877 struct ice_hw *hw = &vsi->back->hw;
1878 struct ice_vsi_ctx *ctxt;
1879 enum ice_status status;
1882 /* do not allow modifying VLAN stripping when a port VLAN is configured
1888 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
1892 /* Here we are configuring what the VSI should do with the VLAN tag in
1893 * the Rx packet. We can either leave the tag in the packet or put it in
1894 * the Rx descriptor.
1897 /* Strip VLAN tag from Rx packet and put it in the desc */
1898 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_STR_BOTH;
1900 /* Disable stripping. Leave tag in packet */
1901 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_NOTHING;
1903 /* Allow all packets untagged/tagged */
1904 ctxt->info.vlan_flags |= ICE_AQ_VSI_VLAN_MODE_ALL;
1906 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
1908 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1910 dev_err(ice_pf_to_dev(vsi->back), "update VSI for VLAN strip failed, ena = %d err %s aq_err %s\n",
1911 ena, ice_stat_str(status),
1912 ice_aq_str(hw->adminq.sq_last_status));
1917 vsi->info.vlan_flags = ctxt->info.vlan_flags;
1924 * ice_vsi_start_all_rx_rings - start/enable all of a VSI's Rx rings
1925 * @vsi: the VSI whose rings are to be enabled
1927 * Returns 0 on success and a negative value on error
1929 int ice_vsi_start_all_rx_rings(struct ice_vsi *vsi)
1931 return ice_vsi_ctrl_all_rx_rings(vsi, true);
1935 * ice_vsi_stop_all_rx_rings - stop/disable all of a VSI's Rx rings
1936 * @vsi: the VSI whose rings are to be disabled
1938 * Returns 0 on success and a negative value on error
1940 int ice_vsi_stop_all_rx_rings(struct ice_vsi *vsi)
1942 return ice_vsi_ctrl_all_rx_rings(vsi, false);
1946 * ice_vsi_stop_tx_rings - Disable Tx rings
1947 * @vsi: the VSI being configured
1948 * @rst_src: reset source
1949 * @rel_vmvf_num: Relative ID of VF/VM
1950 * @rings: Tx ring array to be stopped
1953 ice_vsi_stop_tx_rings(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
1954 u16 rel_vmvf_num, struct ice_ring **rings)
1958 if (vsi->num_txq > ICE_LAN_TXQ_MAX_QDIS)
1961 for (q_idx = 0; q_idx < vsi->num_txq; q_idx++) {
1962 struct ice_txq_meta txq_meta = { };
1965 if (!rings || !rings[q_idx])
1968 ice_fill_txq_meta(vsi, rings[q_idx], &txq_meta);
1969 status = ice_vsi_stop_tx_ring(vsi, rst_src, rel_vmvf_num,
1970 rings[q_idx], &txq_meta);
1980 * ice_vsi_stop_lan_tx_rings - Disable LAN Tx rings
1981 * @vsi: the VSI being configured
1982 * @rst_src: reset source
1983 * @rel_vmvf_num: Relative ID of VF/VM
1986 ice_vsi_stop_lan_tx_rings(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
1989 return ice_vsi_stop_tx_rings(vsi, rst_src, rel_vmvf_num, vsi->tx_rings);
1993 * ice_vsi_stop_xdp_tx_rings - Disable XDP Tx rings
1994 * @vsi: the VSI being configured
1996 int ice_vsi_stop_xdp_tx_rings(struct ice_vsi *vsi)
1998 return ice_vsi_stop_tx_rings(vsi, ICE_NO_RESET, 0, vsi->xdp_rings);
2002 * ice_vsi_is_vlan_pruning_ena - check if VLAN pruning is enabled or not
2003 * @vsi: VSI to check whether or not VLAN pruning is enabled.
2005 * returns true if Rx VLAN pruning is enabled and false otherwise.
2007 bool ice_vsi_is_vlan_pruning_ena(struct ice_vsi *vsi)
2012 return (vsi->info.sw_flags2 & ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA);
2016 * ice_cfg_vlan_pruning - enable or disable VLAN pruning on the VSI
2017 * @vsi: VSI to enable or disable VLAN pruning on
2018 * @ena: set to true to enable VLAN pruning and false to disable it
2019 * @vlan_promisc: enable valid security flags if not in VLAN promiscuous mode
2021 * returns 0 if VSI is updated, negative otherwise
2023 int ice_cfg_vlan_pruning(struct ice_vsi *vsi, bool ena, bool vlan_promisc)
2025 struct ice_vsi_ctx *ctxt;
2032 /* Don't enable VLAN pruning if the netdev is currently in promiscuous
2033 * mode. VLAN pruning will be enabled when the interface exits
2034 * promiscuous mode if any VLAN filters are active.
2036 if (vsi->netdev && vsi->netdev->flags & IFF_PROMISC && ena)
2040 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
2044 ctxt->info = vsi->info;
2047 ctxt->info.sw_flags2 |= ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
2049 ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
2052 ctxt->info.valid_sections =
2053 cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
2055 status = ice_update_vsi(&pf->hw, vsi->idx, ctxt, NULL);
2057 netdev_err(vsi->netdev, "%sabling VLAN pruning on VSI handle: %d, VSI HW ID: %d failed, err = %s, aq_err = %s\n",
2058 ena ? "En" : "Dis", vsi->idx, vsi->vsi_num,
2059 ice_stat_str(status),
2060 ice_aq_str(pf->hw.adminq.sq_last_status));
2064 vsi->info.sw_flags2 = ctxt->info.sw_flags2;
2074 static void ice_vsi_set_tc_cfg(struct ice_vsi *vsi)
2076 struct ice_dcbx_cfg *cfg = &vsi->port_info->local_dcbx_cfg;
2078 vsi->tc_cfg.ena_tc = ice_dcb_get_ena_tc(cfg);
2079 vsi->tc_cfg.numtc = ice_dcb_get_num_tc(cfg);
2083 * ice_vsi_set_q_vectors_reg_idx - set the HW register index for all q_vectors
2084 * @vsi: VSI to set the q_vectors register index on
2087 ice_vsi_set_q_vectors_reg_idx(struct ice_vsi *vsi)
2091 if (!vsi || !vsi->q_vectors)
2094 ice_for_each_q_vector(vsi, i) {
2095 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2098 dev_err(ice_pf_to_dev(vsi->back), "Failed to set reg_idx on q_vector %d VSI %d\n",
2103 if (vsi->type == ICE_VSI_VF) {
2104 struct ice_vf *vf = &vsi->back->vf[vsi->vf_id];
2106 q_vector->reg_idx = ice_calc_vf_reg_idx(vf, q_vector);
2109 q_vector->v_idx + vsi->base_vector;
2116 ice_for_each_q_vector(vsi, i) {
2117 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2120 q_vector->reg_idx = 0;
2127 * ice_cfg_sw_lldp - Config switch rules for LLDP packet handling
2128 * @vsi: the VSI being configured
2129 * @tx: bool to determine Tx or Rx rule
2130 * @create: bool to determine create or remove Rule
2132 void ice_cfg_sw_lldp(struct ice_vsi *vsi, bool tx, bool create)
2134 enum ice_status (*eth_fltr)(struct ice_vsi *v, u16 type, u16 flag,
2135 enum ice_sw_fwd_act_type act);
2136 struct ice_pf *pf = vsi->back;
2137 enum ice_status status;
2140 dev = ice_pf_to_dev(pf);
2141 eth_fltr = create ? ice_fltr_add_eth : ice_fltr_remove_eth;
2144 status = eth_fltr(vsi, ETH_P_LLDP, ICE_FLTR_TX,
2147 status = eth_fltr(vsi, ETH_P_LLDP, ICE_FLTR_RX, ICE_FWD_TO_VSI);
2150 dev_err(dev, "Fail %s %s LLDP rule on VSI %i error: %s\n",
2151 create ? "adding" : "removing", tx ? "TX" : "RX",
2152 vsi->vsi_num, ice_stat_str(status));
2156 * ice_vsi_setup - Set up a VSI by a given type
2157 * @pf: board private structure
2158 * @pi: pointer to the port_info instance
2159 * @vsi_type: VSI type
2160 * @vf_id: defines VF ID to which this VSI connects. This field is meant to be
2161 * used only for ICE_VSI_VF VSI type. For other VSI types, should
2162 * fill-in ICE_INVAL_VFID as input.
2164 * This allocates the sw VSI structure and its queue resources.
2166 * Returns pointer to the successfully allocated and configured VSI sw struct on
2167 * success, NULL on failure.
2170 ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
2171 enum ice_vsi_type vsi_type, u16 vf_id)
2173 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2174 struct device *dev = ice_pf_to_dev(pf);
2175 enum ice_status status;
2176 struct ice_vsi *vsi;
2179 if (vsi_type == ICE_VSI_VF)
2180 vsi = ice_vsi_alloc(pf, vsi_type, vf_id);
2182 vsi = ice_vsi_alloc(pf, vsi_type, ICE_INVAL_VFID);
2185 dev_err(dev, "could not allocate VSI\n");
2189 vsi->port_info = pi;
2190 vsi->vsw = pf->first_sw;
2191 if (vsi->type == ICE_VSI_PF)
2192 vsi->ethtype = ETH_P_PAUSE;
2194 if (vsi->type == ICE_VSI_VF)
2197 ice_alloc_fd_res(vsi);
2199 if (ice_vsi_get_qs(vsi)) {
2200 dev_err(dev, "Failed to allocate queues. vsi->idx = %d\n",
2202 goto unroll_vsi_alloc;
2205 /* set RSS capabilities */
2206 ice_vsi_set_rss_params(vsi);
2208 /* set TC configuration */
2209 ice_vsi_set_tc_cfg(vsi);
2211 /* create the VSI */
2212 ret = ice_vsi_init(vsi, true);
2216 switch (vsi->type) {
2219 ret = ice_vsi_alloc_q_vectors(vsi);
2221 goto unroll_vsi_init;
2223 ret = ice_vsi_setup_vector_base(vsi);
2225 goto unroll_alloc_q_vector;
2227 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2229 goto unroll_vector_base;
2231 ret = ice_vsi_alloc_rings(vsi);
2233 goto unroll_vector_base;
2235 /* Always add VLAN ID 0 switch rule by default. This is needed
2236 * in order to allow all untagged and 0 tagged priority traffic
2237 * if Rx VLAN pruning is enabled. Also there are cases where we
2238 * don't get the call to add VLAN 0 via ice_vlan_rx_add_vid()
2239 * so this handles those cases (i.e. adding the PF to a bridge
2240 * without the 8021q module loaded).
2242 ret = ice_vsi_add_vlan(vsi, 0, ICE_FWD_TO_VSI);
2244 goto unroll_clear_rings;
2246 ice_vsi_map_rings_to_vectors(vsi);
2248 /* ICE_VSI_CTRL does not need RSS so skip RSS processing */
2249 if (vsi->type != ICE_VSI_CTRL)
2250 /* Do not exit if configuring RSS had an issue, at
2251 * least receive traffic on first queue. Hence no
2252 * need to capture return value
2254 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
2255 ice_vsi_cfg_rss_lut_key(vsi);
2256 ice_vsi_set_rss_flow_fld(vsi);
2261 /* VF driver will take care of creating netdev for this type and
2262 * map queues to vectors through Virtchnl, PF driver only
2263 * creates a VSI and corresponding structures for bookkeeping
2266 ret = ice_vsi_alloc_q_vectors(vsi);
2268 goto unroll_vsi_init;
2270 ret = ice_vsi_alloc_rings(vsi);
2272 goto unroll_alloc_q_vector;
2274 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2276 goto unroll_vector_base;
2278 /* Do not exit if configuring RSS had an issue, at least
2279 * receive traffic on first queue. Hence no need to capture
2282 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
2283 ice_vsi_cfg_rss_lut_key(vsi);
2284 ice_vsi_set_vf_rss_flow_fld(vsi);
2288 ret = ice_vsi_alloc_rings(vsi);
2290 goto unroll_vsi_init;
2293 /* clean up the resources and exit */
2294 goto unroll_vsi_init;
2297 /* configure VSI nodes based on number of queues and TC's */
2298 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2299 max_txqs[i] = vsi->alloc_txq;
2301 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2304 dev_err(dev, "VSI %d failed lan queue config, error %s\n",
2305 vsi->vsi_num, ice_stat_str(status));
2306 goto unroll_clear_rings;
2309 /* Add switch rule to drop all Tx Flow Control Frames, of look up
2310 * type ETHERTYPE from VSIs, and restrict malicious VF from sending
2311 * out PAUSE or PFC frames. If enabled, FW can still send FC frames.
2312 * The rule is added once for PF VSI in order to create appropriate
2313 * recipe, since VSI/VSI list is ignored with drop action...
2314 * Also add rules to handle LLDP Tx packets. Tx LLDP packets need to
2315 * be dropped so that VFs cannot send LLDP packets to reconfig DCB
2316 * settings in the HW.
2318 if (!ice_is_safe_mode(pf))
2319 if (vsi->type == ICE_VSI_PF) {
2320 ice_fltr_add_eth(vsi, ETH_P_PAUSE, ICE_FLTR_TX,
2322 ice_cfg_sw_lldp(vsi, true, true);
2328 ice_vsi_clear_rings(vsi);
2330 /* reclaim SW interrupts back to the common pool */
2331 ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
2332 pf->num_avail_sw_msix += vsi->num_q_vectors;
2333 unroll_alloc_q_vector:
2334 ice_vsi_free_q_vectors(vsi);
2336 ice_vsi_delete(vsi);
2338 ice_vsi_put_qs(vsi);
2346 * ice_vsi_release_msix - Clear the queue to Interrupt mapping in HW
2347 * @vsi: the VSI being cleaned up
2349 static void ice_vsi_release_msix(struct ice_vsi *vsi)
2351 struct ice_pf *pf = vsi->back;
2352 struct ice_hw *hw = &pf->hw;
2357 for (i = 0; i < vsi->num_q_vectors; i++) {
2358 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2359 u16 reg_idx = q_vector->reg_idx;
2361 wr32(hw, GLINT_ITR(ICE_IDX_ITR0, reg_idx), 0);
2362 wr32(hw, GLINT_ITR(ICE_IDX_ITR1, reg_idx), 0);
2363 for (q = 0; q < q_vector->num_ring_tx; q++) {
2364 wr32(hw, QINT_TQCTL(vsi->txq_map[txq]), 0);
2365 if (ice_is_xdp_ena_vsi(vsi)) {
2366 u32 xdp_txq = txq + vsi->num_xdp_txq;
2368 wr32(hw, QINT_TQCTL(vsi->txq_map[xdp_txq]), 0);
2373 for (q = 0; q < q_vector->num_ring_rx; q++) {
2374 wr32(hw, QINT_RQCTL(vsi->rxq_map[rxq]), 0);
2383 * ice_vsi_free_irq - Free the IRQ association with the OS
2384 * @vsi: the VSI being configured
2386 void ice_vsi_free_irq(struct ice_vsi *vsi)
2388 struct ice_pf *pf = vsi->back;
2389 int base = vsi->base_vector;
2392 if (!vsi->q_vectors || !vsi->irqs_ready)
2395 ice_vsi_release_msix(vsi);
2396 if (vsi->type == ICE_VSI_VF)
2399 vsi->irqs_ready = false;
2400 ice_for_each_q_vector(vsi, i) {
2401 u16 vector = i + base;
2404 irq_num = pf->msix_entries[vector].vector;
2406 /* free only the irqs that were actually requested */
2407 if (!vsi->q_vectors[i] ||
2408 !(vsi->q_vectors[i]->num_ring_tx ||
2409 vsi->q_vectors[i]->num_ring_rx))
2412 /* clear the affinity notifier in the IRQ descriptor */
2413 irq_set_affinity_notifier(irq_num, NULL);
2415 /* clear the affinity_mask in the IRQ descriptor */
2416 irq_set_affinity_hint(irq_num, NULL);
2417 synchronize_irq(irq_num);
2418 devm_free_irq(ice_pf_to_dev(pf), irq_num, vsi->q_vectors[i]);
2423 * ice_vsi_free_tx_rings - Free Tx resources for VSI queues
2424 * @vsi: the VSI having resources freed
2426 void ice_vsi_free_tx_rings(struct ice_vsi *vsi)
2433 ice_for_each_txq(vsi, i)
2434 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
2435 ice_free_tx_ring(vsi->tx_rings[i]);
2439 * ice_vsi_free_rx_rings - Free Rx resources for VSI queues
2440 * @vsi: the VSI having resources freed
2442 void ice_vsi_free_rx_rings(struct ice_vsi *vsi)
2449 ice_for_each_rxq(vsi, i)
2450 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
2451 ice_free_rx_ring(vsi->rx_rings[i]);
2455 * ice_vsi_close - Shut down a VSI
2456 * @vsi: the VSI being shut down
2458 void ice_vsi_close(struct ice_vsi *vsi)
2460 if (!test_and_set_bit(__ICE_DOWN, vsi->state))
2463 ice_vsi_free_irq(vsi);
2464 ice_vsi_free_tx_rings(vsi);
2465 ice_vsi_free_rx_rings(vsi);
2469 * ice_ena_vsi - resume a VSI
2470 * @vsi: the VSI being resume
2471 * @locked: is the rtnl_lock already held
2473 int ice_ena_vsi(struct ice_vsi *vsi, bool locked)
2477 if (!test_bit(__ICE_NEEDS_RESTART, vsi->state))
2480 clear_bit(__ICE_NEEDS_RESTART, vsi->state);
2482 if (vsi->netdev && vsi->type == ICE_VSI_PF) {
2483 if (netif_running(vsi->netdev)) {
2487 err = ice_open(vsi->netdev);
2492 } else if (vsi->type == ICE_VSI_CTRL) {
2493 err = ice_vsi_open_ctrl(vsi);
2500 * ice_dis_vsi - pause a VSI
2501 * @vsi: the VSI being paused
2502 * @locked: is the rtnl_lock already held
2504 void ice_dis_vsi(struct ice_vsi *vsi, bool locked)
2506 if (test_bit(__ICE_DOWN, vsi->state))
2509 set_bit(__ICE_NEEDS_RESTART, vsi->state);
2511 if (vsi->type == ICE_VSI_PF && vsi->netdev) {
2512 if (netif_running(vsi->netdev)) {
2516 ice_stop(vsi->netdev);
2523 } else if (vsi->type == ICE_VSI_CTRL) {
2529 * ice_vsi_dis_irq - Mask off queue interrupt generation on the VSI
2530 * @vsi: the VSI being un-configured
2532 void ice_vsi_dis_irq(struct ice_vsi *vsi)
2534 int base = vsi->base_vector;
2535 struct ice_pf *pf = vsi->back;
2536 struct ice_hw *hw = &pf->hw;
2540 /* disable interrupt causation from each queue */
2541 if (vsi->tx_rings) {
2542 ice_for_each_txq(vsi, i) {
2543 if (vsi->tx_rings[i]) {
2546 reg = vsi->tx_rings[i]->reg_idx;
2547 val = rd32(hw, QINT_TQCTL(reg));
2548 val &= ~QINT_TQCTL_CAUSE_ENA_M;
2549 wr32(hw, QINT_TQCTL(reg), val);
2554 if (vsi->rx_rings) {
2555 ice_for_each_rxq(vsi, i) {
2556 if (vsi->rx_rings[i]) {
2559 reg = vsi->rx_rings[i]->reg_idx;
2560 val = rd32(hw, QINT_RQCTL(reg));
2561 val &= ~QINT_RQCTL_CAUSE_ENA_M;
2562 wr32(hw, QINT_RQCTL(reg), val);
2567 /* disable each interrupt */
2568 ice_for_each_q_vector(vsi, i) {
2569 if (!vsi->q_vectors[i])
2571 wr32(hw, GLINT_DYN_CTL(vsi->q_vectors[i]->reg_idx), 0);
2576 /* don't call synchronize_irq() for VF's from the host */
2577 if (vsi->type == ICE_VSI_VF)
2580 ice_for_each_q_vector(vsi, i)
2581 synchronize_irq(pf->msix_entries[i + base].vector);
2585 * ice_napi_del - Remove NAPI handler for the VSI
2586 * @vsi: VSI for which NAPI handler is to be removed
2588 void ice_napi_del(struct ice_vsi *vsi)
2595 ice_for_each_q_vector(vsi, v_idx)
2596 netif_napi_del(&vsi->q_vectors[v_idx]->napi);
2600 * ice_vsi_release - Delete a VSI and free its resources
2601 * @vsi: the VSI being removed
2603 * Returns 0 on success or < 0 on error
2605 int ice_vsi_release(struct ice_vsi *vsi)
2613 /* do not unregister while driver is in the reset recovery pending
2614 * state. Since reset/rebuild happens through PF service task workqueue,
2615 * it's not a good idea to unregister netdev that is associated to the
2616 * PF that is running the work queue items currently. This is done to
2617 * avoid check_flush_dependency() warning on this wq
2619 if (vsi->netdev && !ice_is_reset_in_progress(pf->state))
2620 unregister_netdev(vsi->netdev);
2622 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2625 /* Disable VSI and free resources */
2626 if (vsi->type != ICE_VSI_LB)
2627 ice_vsi_dis_irq(vsi);
2630 /* SR-IOV determines needed MSIX resources all at once instead of per
2631 * VSI since when VFs are spawned we know how many VFs there are and how
2632 * many interrupts each VF needs. SR-IOV MSIX resources are also
2633 * cleared in the same manner.
2635 if (vsi->type != ICE_VSI_VF) {
2636 /* reclaim SW interrupts back to the common pool */
2637 ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
2638 pf->num_avail_sw_msix += vsi->num_q_vectors;
2641 if (!ice_is_safe_mode(pf)) {
2642 if (vsi->type == ICE_VSI_PF) {
2643 ice_fltr_remove_eth(vsi, ETH_P_PAUSE, ICE_FLTR_TX,
2645 ice_cfg_sw_lldp(vsi, true, false);
2646 /* The Rx rule will only exist to remove if the LLDP FW
2647 * engine is currently stopped
2649 if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags))
2650 ice_cfg_sw_lldp(vsi, false, false);
2654 ice_fltr_remove_all(vsi);
2655 ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx);
2656 ice_vsi_delete(vsi);
2657 ice_vsi_free_q_vectors(vsi);
2659 /* make sure unregister_netdev() was called by checking __ICE_DOWN */
2660 if (vsi->netdev && test_bit(__ICE_DOWN, vsi->state)) {
2661 free_netdev(vsi->netdev);
2665 ice_vsi_clear_rings(vsi);
2667 ice_vsi_put_qs(vsi);
2669 /* retain SW VSI data structure since it is needed to unregister and
2670 * free VSI netdev when PF is not in reset recovery pending state,\
2671 * for ex: during rmmod.
2673 if (!ice_is_reset_in_progress(pf->state))
2680 * ice_vsi_rebuild_update_coalesce - set coalesce for a q_vector
2681 * @q_vector: pointer to q_vector which is being updated
2682 * @coalesce: pointer to array of struct with stored coalesce
2684 * Set coalesce param in q_vector and update these parameters in HW.
2687 ice_vsi_rebuild_update_coalesce(struct ice_q_vector *q_vector,
2688 struct ice_coalesce_stored *coalesce)
2690 struct ice_ring_container *rx_rc = &q_vector->rx;
2691 struct ice_ring_container *tx_rc = &q_vector->tx;
2692 struct ice_hw *hw = &q_vector->vsi->back->hw;
2694 tx_rc->itr_setting = coalesce->itr_tx;
2695 rx_rc->itr_setting = coalesce->itr_rx;
2697 /* dynamic ITR values will be updated during Tx/Rx */
2698 if (!ITR_IS_DYNAMIC(tx_rc->itr_setting))
2699 wr32(hw, GLINT_ITR(tx_rc->itr_idx, q_vector->reg_idx),
2700 ITR_REG_ALIGN(tx_rc->itr_setting) >>
2702 if (!ITR_IS_DYNAMIC(rx_rc->itr_setting))
2703 wr32(hw, GLINT_ITR(rx_rc->itr_idx, q_vector->reg_idx),
2704 ITR_REG_ALIGN(rx_rc->itr_setting) >>
2707 q_vector->intrl = coalesce->intrl;
2708 wr32(hw, GLINT_RATE(q_vector->reg_idx),
2709 ice_intrl_usec_to_reg(q_vector->intrl, hw->intrl_gran));
2713 * ice_vsi_rebuild_get_coalesce - get coalesce from all q_vectors
2714 * @vsi: VSI connected with q_vectors
2715 * @coalesce: array of struct with stored coalesce
2717 * Returns array size.
2720 ice_vsi_rebuild_get_coalesce(struct ice_vsi *vsi,
2721 struct ice_coalesce_stored *coalesce)
2725 ice_for_each_q_vector(vsi, i) {
2726 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2728 coalesce[i].itr_tx = q_vector->tx.itr_setting;
2729 coalesce[i].itr_rx = q_vector->rx.itr_setting;
2730 coalesce[i].intrl = q_vector->intrl;
2733 return vsi->num_q_vectors;
2737 * ice_vsi_rebuild_set_coalesce - set coalesce from earlier saved arrays
2738 * @vsi: VSI connected with q_vectors
2739 * @coalesce: pointer to array of struct with stored coalesce
2740 * @size: size of coalesce array
2742 * Before this function, ice_vsi_rebuild_get_coalesce should be called to save
2743 * ITR params in arrays. If size is 0 or coalesce wasn't stored set coalesce
2747 ice_vsi_rebuild_set_coalesce(struct ice_vsi *vsi,
2748 struct ice_coalesce_stored *coalesce, int size)
2752 if ((size && !coalesce) || !vsi)
2755 for (i = 0; i < size && i < vsi->num_q_vectors; i++)
2756 ice_vsi_rebuild_update_coalesce(vsi->q_vectors[i],
2759 /* number of q_vectors increased, so assume coalesce settings were
2760 * changed globally (i.e. ethtool -C eth0 instead of per-queue) and use
2761 * the previous settings from q_vector 0 for all of the new q_vectors
2763 for (; i < vsi->num_q_vectors; i++)
2764 ice_vsi_rebuild_update_coalesce(vsi->q_vectors[i],
2769 * ice_vsi_rebuild - Rebuild VSI after reset
2770 * @vsi: VSI to be rebuild
2771 * @init_vsi: is this an initialization or a reconfigure of the VSI
2773 * Returns 0 on success and negative value on failure
2775 int ice_vsi_rebuild(struct ice_vsi *vsi, bool init_vsi)
2777 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2778 struct ice_coalesce_stored *coalesce;
2779 int prev_num_q_vectors = 0;
2780 struct ice_vf *vf = NULL;
2781 enum ice_status status;
2789 if (vsi->type == ICE_VSI_VF)
2790 vf = &pf->vf[vsi->vf_id];
2792 coalesce = kcalloc(vsi->num_q_vectors,
2793 sizeof(struct ice_coalesce_stored), GFP_KERNEL);
2795 prev_num_q_vectors = ice_vsi_rebuild_get_coalesce(vsi,
2797 ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx);
2798 ice_vsi_free_q_vectors(vsi);
2800 /* SR-IOV determines needed MSIX resources all at once instead of per
2801 * VSI since when VFs are spawned we know how many VFs there are and how
2802 * many interrupts each VF needs. SR-IOV MSIX resources are also
2803 * cleared in the same manner.
2805 if (vsi->type != ICE_VSI_VF) {
2806 /* reclaim SW interrupts back to the common pool */
2807 ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
2808 pf->num_avail_sw_msix += vsi->num_q_vectors;
2809 vsi->base_vector = 0;
2812 if (ice_is_xdp_ena_vsi(vsi))
2813 /* return value check can be skipped here, it always returns
2814 * 0 if reset is in progress
2816 ice_destroy_xdp_rings(vsi);
2817 ice_vsi_put_qs(vsi);
2818 ice_vsi_clear_rings(vsi);
2819 ice_vsi_free_arrays(vsi);
2820 if (vsi->type == ICE_VSI_VF)
2821 ice_vsi_set_num_qs(vsi, vf->vf_id);
2823 ice_vsi_set_num_qs(vsi, ICE_INVAL_VFID);
2825 ret = ice_vsi_alloc_arrays(vsi);
2829 ice_vsi_get_qs(vsi);
2831 ice_alloc_fd_res(vsi);
2832 ice_vsi_set_tc_cfg(vsi);
2834 /* Initialize VSI struct elements and create VSI in FW */
2835 ret = ice_vsi_init(vsi, init_vsi);
2839 switch (vsi->type) {
2842 ret = ice_vsi_alloc_q_vectors(vsi);
2846 ret = ice_vsi_setup_vector_base(vsi);
2850 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2854 ret = ice_vsi_alloc_rings(vsi);
2858 ice_vsi_map_rings_to_vectors(vsi);
2859 if (ice_is_xdp_ena_vsi(vsi)) {
2860 vsi->num_xdp_txq = vsi->alloc_rxq;
2861 ret = ice_prepare_xdp_rings(vsi, vsi->xdp_prog);
2865 /* ICE_VSI_CTRL does not need RSS so skip RSS processing */
2866 if (vsi->type != ICE_VSI_CTRL)
2867 /* Do not exit if configuring RSS had an issue, at
2868 * least receive traffic on first queue. Hence no
2869 * need to capture return value
2871 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2872 ice_vsi_cfg_rss_lut_key(vsi);
2875 ret = ice_vsi_alloc_q_vectors(vsi);
2879 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2883 ret = ice_vsi_alloc_rings(vsi);
2892 /* configure VSI nodes based on number of queues and TC's */
2893 for (i = 0; i < vsi->tc_cfg.numtc; i++) {
2894 max_txqs[i] = vsi->alloc_txq;
2896 if (ice_is_xdp_ena_vsi(vsi))
2897 max_txqs[i] += vsi->num_xdp_txq;
2900 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2903 dev_err(ice_pf_to_dev(pf), "VSI %d failed lan queue config, error %s\n",
2904 vsi->vsi_num, ice_stat_str(status));
2909 return ice_schedule_reset(pf, ICE_RESET_PFR);
2912 ice_vsi_rebuild_set_coalesce(vsi, coalesce, prev_num_q_vectors);
2918 ice_vsi_free_q_vectors(vsi);
2921 vsi->current_netdev_flags = 0;
2922 unregister_netdev(vsi->netdev);
2923 free_netdev(vsi->netdev);
2928 set_bit(__ICE_RESET_FAILED, pf->state);
2934 * ice_is_reset_in_progress - check for a reset in progress
2935 * @state: PF state field
2937 bool ice_is_reset_in_progress(unsigned long *state)
2939 return test_bit(__ICE_RESET_OICR_RECV, state) ||
2940 test_bit(__ICE_DCBNL_DEVRESET, state) ||
2941 test_bit(__ICE_PFR_REQ, state) ||
2942 test_bit(__ICE_CORER_REQ, state) ||
2943 test_bit(__ICE_GLOBR_REQ, state);
2948 * ice_vsi_update_q_map - update our copy of the VSI info with new queue map
2949 * @vsi: VSI being configured
2950 * @ctx: the context buffer returned from AQ VSI update command
2952 static void ice_vsi_update_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctx)
2954 vsi->info.mapping_flags = ctx->info.mapping_flags;
2955 memcpy(&vsi->info.q_mapping, &ctx->info.q_mapping,
2956 sizeof(vsi->info.q_mapping));
2957 memcpy(&vsi->info.tc_mapping, ctx->info.tc_mapping,
2958 sizeof(vsi->info.tc_mapping));
2962 * ice_vsi_cfg_tc - Configure VSI Tx Sched for given TC map
2963 * @vsi: VSI to be configured
2964 * @ena_tc: TC bitmap
2966 * VSI queues expected to be quiesced before calling this function
2968 int ice_vsi_cfg_tc(struct ice_vsi *vsi, u8 ena_tc)
2970 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2971 struct ice_pf *pf = vsi->back;
2972 struct ice_vsi_ctx *ctx;
2973 enum ice_status status;
2978 dev = ice_pf_to_dev(pf);
2980 ice_for_each_traffic_class(i) {
2981 /* build bitmap of enabled TCs */
2982 if (ena_tc & BIT(i))
2984 /* populate max_txqs per TC */
2985 max_txqs[i] = vsi->alloc_txq;
2988 vsi->tc_cfg.ena_tc = ena_tc;
2989 vsi->tc_cfg.numtc = num_tc;
2991 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
2996 ctx->info = vsi->info;
2998 ice_vsi_setup_q_map(vsi, ctx);
3000 /* must to indicate which section of VSI context are being modified */
3001 ctx->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
3002 status = ice_update_vsi(&pf->hw, vsi->idx, ctx, NULL);
3004 dev_info(dev, "Failed VSI Update\n");
3009 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
3013 dev_err(dev, "VSI %d failed TC config, error %s\n",
3014 vsi->vsi_num, ice_stat_str(status));
3018 ice_vsi_update_q_map(vsi, ctx);
3019 vsi->info.valid_sections = 0;
3021 ice_vsi_cfg_netdev_tc(vsi, ena_tc);
3026 #endif /* CONFIG_DCB */
3029 * ice_update_ring_stats - Update ring statistics
3030 * @ring: ring to update
3031 * @cont: used to increment per-vector counters
3032 * @pkts: number of processed packets
3033 * @bytes: number of processed bytes
3035 * This function assumes that caller has acquired a u64_stats_sync lock.
3038 ice_update_ring_stats(struct ice_ring *ring, struct ice_ring_container *cont,
3039 u64 pkts, u64 bytes)
3041 ring->stats.bytes += bytes;
3042 ring->stats.pkts += pkts;
3043 cont->total_bytes += bytes;
3044 cont->total_pkts += pkts;
3048 * ice_update_tx_ring_stats - Update Tx ring specific counters
3049 * @tx_ring: ring to update
3050 * @pkts: number of processed packets
3051 * @bytes: number of processed bytes
3053 void ice_update_tx_ring_stats(struct ice_ring *tx_ring, u64 pkts, u64 bytes)
3055 u64_stats_update_begin(&tx_ring->syncp);
3056 ice_update_ring_stats(tx_ring, &tx_ring->q_vector->tx, pkts, bytes);
3057 u64_stats_update_end(&tx_ring->syncp);
3061 * ice_update_rx_ring_stats - Update Rx ring specific counters
3062 * @rx_ring: ring to update
3063 * @pkts: number of processed packets
3064 * @bytes: number of processed bytes
3066 void ice_update_rx_ring_stats(struct ice_ring *rx_ring, u64 pkts, u64 bytes)
3068 u64_stats_update_begin(&rx_ring->syncp);
3069 ice_update_ring_stats(rx_ring, &rx_ring->q_vector->rx, pkts, bytes);
3070 u64_stats_update_end(&rx_ring->syncp);
3074 * ice_status_to_errno - convert from enum ice_status to Linux errno
3075 * @err: ice_status value to convert
3077 int ice_status_to_errno(enum ice_status err)
3082 case ICE_ERR_DOES_NOT_EXIST:
3084 case ICE_ERR_OUT_OF_RANGE:
3088 case ICE_ERR_NO_MEMORY:
3090 case ICE_ERR_MAX_LIMIT:
3098 * ice_is_dflt_vsi_in_use - check if the default forwarding VSI is being used
3099 * @sw: switch to check if its default forwarding VSI is free
3101 * Return true if the default forwarding VSI is already being used, else returns
3102 * false signalling that it's available to use.
3104 bool ice_is_dflt_vsi_in_use(struct ice_sw *sw)
3106 return (sw->dflt_vsi && sw->dflt_vsi_ena);
3110 * ice_is_vsi_dflt_vsi - check if the VSI passed in is the default VSI
3111 * @sw: switch for the default forwarding VSI to compare against
3112 * @vsi: VSI to compare against default forwarding VSI
3114 * If this VSI passed in is the default forwarding VSI then return true, else
3117 bool ice_is_vsi_dflt_vsi(struct ice_sw *sw, struct ice_vsi *vsi)
3119 return (sw->dflt_vsi == vsi && sw->dflt_vsi_ena);
3123 * ice_set_dflt_vsi - set the default forwarding VSI
3124 * @sw: switch used to assign the default forwarding VSI
3125 * @vsi: VSI getting set as the default forwarding VSI on the switch
3127 * If the VSI passed in is already the default VSI and it's enabled just return
3130 * If there is already a default VSI on the switch and it's enabled then return
3131 * -EEXIST since there can only be one default VSI per switch.
3133 * Otherwise try to set the VSI passed in as the switch's default VSI and
3134 * return the result.
3136 int ice_set_dflt_vsi(struct ice_sw *sw, struct ice_vsi *vsi)
3138 enum ice_status status;
3144 dev = ice_pf_to_dev(vsi->back);
3146 /* the VSI passed in is already the default VSI */
3147 if (ice_is_vsi_dflt_vsi(sw, vsi)) {
3148 dev_dbg(dev, "VSI %d passed in is already the default forwarding VSI, nothing to do\n",
3153 /* another VSI is already the default VSI for this switch */
3154 if (ice_is_dflt_vsi_in_use(sw)) {
3155 dev_err(dev, "Default forwarding VSI %d already in use, disable it and try again\n",
3156 sw->dflt_vsi->vsi_num);
3160 status = ice_cfg_dflt_vsi(&vsi->back->hw, vsi->idx, true, ICE_FLTR_RX);
3162 dev_err(dev, "Failed to set VSI %d as the default forwarding VSI, error %s\n",
3163 vsi->vsi_num, ice_stat_str(status));
3168 sw->dflt_vsi_ena = true;
3174 * ice_clear_dflt_vsi - clear the default forwarding VSI
3175 * @sw: switch used to clear the default VSI
3177 * If the switch has no default VSI or it's not enabled then return error.
3179 * Otherwise try to clear the default VSI and return the result.
3181 int ice_clear_dflt_vsi(struct ice_sw *sw)
3183 struct ice_vsi *dflt_vsi;
3184 enum ice_status status;
3190 dev = ice_pf_to_dev(sw->pf);
3192 dflt_vsi = sw->dflt_vsi;
3194 /* there is no default VSI configured */
3195 if (!ice_is_dflt_vsi_in_use(sw))
3198 status = ice_cfg_dflt_vsi(&dflt_vsi->back->hw, dflt_vsi->idx, false,
3201 dev_err(dev, "Failed to clear the default forwarding VSI %d, error %s\n",
3202 dflt_vsi->vsi_num, ice_stat_str(status));
3206 sw->dflt_vsi = NULL;
3207 sw->dflt_vsi_ena = false;