1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
9 #include "ice_dcb_lib.h"
10 #include "ice_devlink.h"
13 * ice_vsi_type_str - maps VSI type enum to string equivalents
14 * @vsi_type: VSI type enum
16 const char *ice_vsi_type_str(enum ice_vsi_type vsi_type)
24 return "ICE_VSI_CTRL";
33 * ice_vsi_ctrl_all_rx_rings - Start or stop a VSI's Rx rings
34 * @vsi: the VSI being configured
35 * @ena: start or stop the Rx rings
37 * First enable/disable all of the Rx rings, flush any remaining writes, and
38 * then verify that they have all been enabled/disabled successfully. This will
39 * let all of the register writes complete when enabling/disabling the Rx rings
40 * before waiting for the change in hardware to complete.
42 static int ice_vsi_ctrl_all_rx_rings(struct ice_vsi *vsi, bool ena)
47 for (i = 0; i < vsi->num_rxq; i++)
48 ice_vsi_ctrl_one_rx_ring(vsi, ena, i, false);
50 ice_flush(&vsi->back->hw);
52 for (i = 0; i < vsi->num_rxq; i++) {
53 ret = ice_vsi_wait_one_rx_ring(vsi, ena, i);
62 * ice_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the VSI
65 * On error: returns error code (negative)
66 * On success: returns 0
68 static int ice_vsi_alloc_arrays(struct ice_vsi *vsi)
70 struct ice_pf *pf = vsi->back;
73 dev = ice_pf_to_dev(pf);
75 /* allocate memory for both Tx and Rx ring pointers */
76 vsi->tx_rings = devm_kcalloc(dev, vsi->alloc_txq,
77 sizeof(*vsi->tx_rings), GFP_KERNEL);
81 vsi->rx_rings = devm_kcalloc(dev, vsi->alloc_rxq,
82 sizeof(*vsi->rx_rings), GFP_KERNEL);
86 /* XDP will have vsi->alloc_txq Tx queues as well, so double the size */
87 vsi->txq_map = devm_kcalloc(dev, (2 * vsi->alloc_txq),
88 sizeof(*vsi->txq_map), GFP_KERNEL);
93 vsi->rxq_map = devm_kcalloc(dev, vsi->alloc_rxq,
94 sizeof(*vsi->rxq_map), GFP_KERNEL);
98 /* There is no need to allocate q_vectors for a loopback VSI. */
99 if (vsi->type == ICE_VSI_LB)
102 /* allocate memory for q_vector pointers */
103 vsi->q_vectors = devm_kcalloc(dev, vsi->num_q_vectors,
104 sizeof(*vsi->q_vectors), GFP_KERNEL);
111 devm_kfree(dev, vsi->rxq_map);
113 devm_kfree(dev, vsi->txq_map);
115 devm_kfree(dev, vsi->rx_rings);
117 devm_kfree(dev, vsi->tx_rings);
122 * ice_vsi_set_num_desc - Set number of descriptors for queues on this VSI
123 * @vsi: the VSI being configured
125 static void ice_vsi_set_num_desc(struct ice_vsi *vsi)
131 /* a user could change the values of num_[tr]x_desc using
132 * ethtool -G so we should keep those values instead of
133 * overwriting them with the defaults.
135 if (!vsi->num_rx_desc)
136 vsi->num_rx_desc = ICE_DFLT_NUM_RX_DESC;
137 if (!vsi->num_tx_desc)
138 vsi->num_tx_desc = ICE_DFLT_NUM_TX_DESC;
141 dev_dbg(ice_pf_to_dev(vsi->back), "Not setting number of Tx/Rx descriptors for VSI type %d\n",
148 * ice_vsi_set_num_qs - Set number of queues, descriptors and vectors for a VSI
149 * @vsi: the VSI being configured
150 * @vf_id: ID of the VF being configured
152 * Return 0 on success and a negative value on error
154 static void ice_vsi_set_num_qs(struct ice_vsi *vsi, u16 vf_id)
156 struct ice_pf *pf = vsi->back;
157 struct ice_vf *vf = NULL;
159 if (vsi->type == ICE_VSI_VF)
164 vsi->alloc_txq = min_t(int, ice_get_avail_txq_count(pf),
167 vsi->alloc_txq = vsi->req_txq;
168 vsi->num_txq = vsi->req_txq;
171 pf->num_lan_tx = vsi->alloc_txq;
173 /* only 1 Rx queue unless RSS is enabled */
174 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
177 vsi->alloc_rxq = min_t(int, ice_get_avail_rxq_count(pf),
180 vsi->alloc_rxq = vsi->req_rxq;
181 vsi->num_rxq = vsi->req_rxq;
185 pf->num_lan_rx = vsi->alloc_rxq;
187 vsi->num_q_vectors = max_t(int, vsi->alloc_rxq, vsi->alloc_txq);
190 vf = &pf->vf[vsi->vf_id];
191 vsi->alloc_txq = vf->num_vf_qs;
192 vsi->alloc_rxq = vf->num_vf_qs;
193 /* pf->num_msix_per_vf includes (VF miscellaneous vector +
194 * data queue interrupts). Since vsi->num_q_vectors is number
195 * of queues vectors, subtract 1 (ICE_NONQ_VECS_VF) from the
196 * original vector count
198 vsi->num_q_vectors = pf->num_msix_per_vf - ICE_NONQ_VECS_VF;
203 vsi->num_q_vectors = 1;
210 dev_warn(ice_pf_to_dev(pf), "Unknown VSI type %d\n", vsi->type);
214 ice_vsi_set_num_desc(vsi);
218 * ice_get_free_slot - get the next non-NULL location index in array
219 * @array: array to search
220 * @size: size of the array
221 * @curr: last known occupied index to be used as a search hint
223 * void * is being used to keep the functionality generic. This lets us use this
224 * function on any array of pointers.
226 static int ice_get_free_slot(void *array, int size, int curr)
228 int **tmp_array = (int **)array;
231 if (curr < (size - 1) && !tmp_array[curr + 1]) {
236 while ((i < size) && (tmp_array[i]))
247 * ice_vsi_delete - delete a VSI from the switch
248 * @vsi: pointer to VSI being removed
250 static void ice_vsi_delete(struct ice_vsi *vsi)
252 struct ice_pf *pf = vsi->back;
253 struct ice_vsi_ctx *ctxt;
254 enum ice_status status;
256 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
260 if (vsi->type == ICE_VSI_VF)
261 ctxt->vf_num = vsi->vf_id;
262 ctxt->vsi_num = vsi->vsi_num;
264 memcpy(&ctxt->info, &vsi->info, sizeof(ctxt->info));
266 status = ice_free_vsi(&pf->hw, vsi->idx, ctxt, false, NULL);
268 dev_err(ice_pf_to_dev(pf), "Failed to delete VSI %i in FW - error: %s\n",
269 vsi->vsi_num, ice_stat_str(status));
275 * ice_vsi_free_arrays - De-allocate queue and vector pointer arrays for the VSI
276 * @vsi: pointer to VSI being cleared
278 static void ice_vsi_free_arrays(struct ice_vsi *vsi)
280 struct ice_pf *pf = vsi->back;
283 dev = ice_pf_to_dev(pf);
285 /* free the ring and vector containers */
286 if (vsi->q_vectors) {
287 devm_kfree(dev, vsi->q_vectors);
288 vsi->q_vectors = NULL;
291 devm_kfree(dev, vsi->tx_rings);
292 vsi->tx_rings = NULL;
295 devm_kfree(dev, vsi->rx_rings);
296 vsi->rx_rings = NULL;
299 devm_kfree(dev, vsi->txq_map);
303 devm_kfree(dev, vsi->rxq_map);
309 * ice_vsi_clear - clean up and deallocate the provided VSI
310 * @vsi: pointer to VSI being cleared
312 * This deallocates the VSI's queue resources, removes it from the PF's
313 * VSI array if necessary, and deallocates the VSI
315 * Returns 0 on success, negative on failure
317 static int ice_vsi_clear(struct ice_vsi *vsi)
319 struct ice_pf *pf = NULL;
329 dev = ice_pf_to_dev(pf);
331 if (!pf->vsi[vsi->idx] || pf->vsi[vsi->idx] != vsi) {
332 dev_dbg(dev, "vsi does not exist at pf->vsi[%d]\n", vsi->idx);
336 mutex_lock(&pf->sw_mutex);
337 /* updates the PF for this cleared VSI */
339 pf->vsi[vsi->idx] = NULL;
340 if (vsi->idx < pf->next_vsi && vsi->type != ICE_VSI_CTRL)
341 pf->next_vsi = vsi->idx;
343 ice_vsi_free_arrays(vsi);
344 mutex_unlock(&pf->sw_mutex);
345 devm_kfree(dev, vsi);
351 * ice_msix_clean_ctrl_vsi - MSIX mode interrupt handler for ctrl VSI
352 * @irq: interrupt number
353 * @data: pointer to a q_vector
355 static irqreturn_t ice_msix_clean_ctrl_vsi(int __always_unused irq, void *data)
357 struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
359 if (!q_vector->tx.ring)
362 #define FDIR_RX_DESC_CLEAN_BUDGET 64
363 ice_clean_rx_irq(q_vector->rx.ring, FDIR_RX_DESC_CLEAN_BUDGET);
364 ice_clean_ctrl_tx_irq(q_vector->tx.ring);
370 * ice_msix_clean_rings - MSIX mode Interrupt Handler
371 * @irq: interrupt number
372 * @data: pointer to a q_vector
374 static irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data)
376 struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
378 if (!q_vector->tx.ring && !q_vector->rx.ring)
381 napi_schedule(&q_vector->napi);
387 * ice_vsi_alloc - Allocates the next available struct VSI in the PF
388 * @pf: board private structure
389 * @vsi_type: type of VSI
390 * @vf_id: ID of the VF being configured
392 * returns a pointer to a VSI on success, NULL on failure.
394 static struct ice_vsi *
395 ice_vsi_alloc(struct ice_pf *pf, enum ice_vsi_type vsi_type, u16 vf_id)
397 struct device *dev = ice_pf_to_dev(pf);
398 struct ice_vsi *vsi = NULL;
400 /* Need to protect the allocation of the VSIs at the PF level */
401 mutex_lock(&pf->sw_mutex);
403 /* If we have already allocated our maximum number of VSIs,
404 * pf->next_vsi will be ICE_NO_VSI. If not, pf->next_vsi index
405 * is available to be populated
407 if (pf->next_vsi == ICE_NO_VSI) {
408 dev_dbg(dev, "out of VSI slots!\n");
412 vsi = devm_kzalloc(dev, sizeof(*vsi), GFP_KERNEL);
416 vsi->type = vsi_type;
418 set_bit(__ICE_DOWN, vsi->state);
420 if (vsi_type == ICE_VSI_VF)
421 ice_vsi_set_num_qs(vsi, vf_id);
423 ice_vsi_set_num_qs(vsi, ICE_INVAL_VFID);
427 if (ice_vsi_alloc_arrays(vsi))
430 /* Setup default MSIX irq handler for VSI */
431 vsi->irq_handler = ice_msix_clean_rings;
434 if (ice_vsi_alloc_arrays(vsi))
437 /* Setup ctrl VSI MSIX irq handler */
438 vsi->irq_handler = ice_msix_clean_ctrl_vsi;
441 if (ice_vsi_alloc_arrays(vsi))
445 if (ice_vsi_alloc_arrays(vsi))
449 dev_warn(dev, "Unknown VSI type %d\n", vsi->type);
453 if (vsi->type == ICE_VSI_CTRL) {
454 /* Use the last VSI slot as the index for the control VSI */
455 vsi->idx = pf->num_alloc_vsi - 1;
456 pf->ctrl_vsi_idx = vsi->idx;
457 pf->vsi[vsi->idx] = vsi;
459 /* fill slot and make note of the index */
460 vsi->idx = pf->next_vsi;
461 pf->vsi[pf->next_vsi] = vsi;
463 /* prepare pf->next_vsi for next use */
464 pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi,
470 devm_kfree(dev, vsi);
473 mutex_unlock(&pf->sw_mutex);
478 * ice_alloc_fd_res - Allocate FD resource for a VSI
479 * @vsi: pointer to the ice_vsi
481 * This allocates the FD resources
483 * Returns 0 on success, -EPERM on no-op or -EIO on failure
485 static int ice_alloc_fd_res(struct ice_vsi *vsi)
487 struct ice_pf *pf = vsi->back;
490 /* Flow Director filters are only allocated/assigned to the PF VSI which
491 * passes the traffic. The CTRL VSI is only used to add/delete filters
492 * so we don't allocate resources to it
495 /* FD filters from guaranteed pool per VSI */
496 g_val = pf->hw.func_caps.fd_fltr_guar;
500 /* FD filters from best effort pool */
501 b_val = pf->hw.func_caps.fd_fltr_best_effort;
505 if (vsi->type != ICE_VSI_PF)
508 if (!test_bit(ICE_FLAG_FD_ENA, pf->flags))
511 vsi->num_gfltr = g_val / pf->num_alloc_vsi;
513 /* each VSI gets same "best_effort" quota */
514 vsi->num_bfltr = b_val;
520 * ice_vsi_get_qs - Assign queues from PF to VSI
521 * @vsi: the VSI to assign queues to
523 * Returns 0 on success and a negative value on error
525 static int ice_vsi_get_qs(struct ice_vsi *vsi)
527 struct ice_pf *pf = vsi->back;
528 struct ice_qs_cfg tx_qs_cfg = {
529 .qs_mutex = &pf->avail_q_mutex,
530 .pf_map = pf->avail_txqs,
531 .pf_map_size = pf->max_pf_txqs,
532 .q_count = vsi->alloc_txq,
533 .scatter_count = ICE_MAX_SCATTER_TXQS,
534 .vsi_map = vsi->txq_map,
536 .mapping_mode = ICE_VSI_MAP_CONTIG
538 struct ice_qs_cfg rx_qs_cfg = {
539 .qs_mutex = &pf->avail_q_mutex,
540 .pf_map = pf->avail_rxqs,
541 .pf_map_size = pf->max_pf_rxqs,
542 .q_count = vsi->alloc_rxq,
543 .scatter_count = ICE_MAX_SCATTER_RXQS,
544 .vsi_map = vsi->rxq_map,
546 .mapping_mode = ICE_VSI_MAP_CONTIG
550 ret = __ice_vsi_get_qs(&tx_qs_cfg);
553 vsi->tx_mapping_mode = tx_qs_cfg.mapping_mode;
555 ret = __ice_vsi_get_qs(&rx_qs_cfg);
558 vsi->rx_mapping_mode = rx_qs_cfg.mapping_mode;
564 * ice_vsi_put_qs - Release queues from VSI to PF
565 * @vsi: the VSI that is going to release queues
567 static void ice_vsi_put_qs(struct ice_vsi *vsi)
569 struct ice_pf *pf = vsi->back;
572 mutex_lock(&pf->avail_q_mutex);
574 for (i = 0; i < vsi->alloc_txq; i++) {
575 clear_bit(vsi->txq_map[i], pf->avail_txqs);
576 vsi->txq_map[i] = ICE_INVAL_Q_INDEX;
579 for (i = 0; i < vsi->alloc_rxq; i++) {
580 clear_bit(vsi->rxq_map[i], pf->avail_rxqs);
581 vsi->rxq_map[i] = ICE_INVAL_Q_INDEX;
584 mutex_unlock(&pf->avail_q_mutex);
589 * @pf: pointer to the PF struct
591 * returns true if driver is in safe mode, false otherwise
593 bool ice_is_safe_mode(struct ice_pf *pf)
595 return !test_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
599 * ice_vsi_clean_rss_flow_fld - Delete RSS configuration
600 * @vsi: the VSI being cleaned up
602 * This function deletes RSS input set for all flows that were configured
605 static void ice_vsi_clean_rss_flow_fld(struct ice_vsi *vsi)
607 struct ice_pf *pf = vsi->back;
608 enum ice_status status;
610 if (ice_is_safe_mode(pf))
613 status = ice_rem_vsi_rss_cfg(&pf->hw, vsi->idx);
615 dev_dbg(ice_pf_to_dev(pf), "ice_rem_vsi_rss_cfg failed for vsi = %d, error = %s\n",
616 vsi->vsi_num, ice_stat_str(status));
620 * ice_rss_clean - Delete RSS related VSI structures and configuration
621 * @vsi: the VSI being removed
623 static void ice_rss_clean(struct ice_vsi *vsi)
625 struct ice_pf *pf = vsi->back;
628 dev = ice_pf_to_dev(pf);
630 if (vsi->rss_hkey_user)
631 devm_kfree(dev, vsi->rss_hkey_user);
632 if (vsi->rss_lut_user)
633 devm_kfree(dev, vsi->rss_lut_user);
635 ice_vsi_clean_rss_flow_fld(vsi);
636 /* remove RSS replay list */
637 if (!ice_is_safe_mode(pf))
638 ice_rem_vsi_rss_list(&pf->hw, vsi->idx);
642 * ice_vsi_set_rss_params - Setup RSS capabilities per VSI type
643 * @vsi: the VSI being configured
645 static void ice_vsi_set_rss_params(struct ice_vsi *vsi)
647 struct ice_hw_common_caps *cap;
648 struct ice_pf *pf = vsi->back;
650 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
655 cap = &pf->hw.func_caps.common_cap;
658 /* PF VSI will inherit RSS instance of PF */
659 vsi->rss_table_size = (u16)cap->rss_table_size;
660 vsi->rss_size = min_t(u16, num_online_cpus(),
661 BIT(cap->rss_table_entry_width));
662 vsi->rss_lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
665 /* VF VSI will get a small RSS table.
666 * For VSI_LUT, LUT size should be set to 64 bytes.
668 vsi->rss_table_size = ICE_VSIQF_HLUT_ARRAY_SIZE;
669 vsi->rss_size = ICE_MAX_RSS_QS_PER_VF;
670 vsi->rss_lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_VSI;
675 dev_dbg(ice_pf_to_dev(pf), "Unsupported VSI type %s\n",
676 ice_vsi_type_str(vsi->type));
682 * ice_set_dflt_vsi_ctx - Set default VSI context before adding a VSI
683 * @ctxt: the VSI context being set
685 * This initializes a default VSI context for all sections except the Queues.
687 static void ice_set_dflt_vsi_ctx(struct ice_vsi_ctx *ctxt)
691 memset(&ctxt->info, 0, sizeof(ctxt->info));
692 /* VSI's should be allocated from shared pool */
693 ctxt->alloc_from_pool = true;
694 /* Src pruning enabled by default */
695 ctxt->info.sw_flags = ICE_AQ_VSI_SW_FLAG_SRC_PRUNE;
696 /* Traffic from VSI can be sent to LAN */
697 ctxt->info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
698 /* By default bits 3 and 4 in vlan_flags are 0's which results in legacy
699 * behavior (show VLAN, DEI, and UP) in descriptor. Also, allow all
700 * packets untagged/tagged.
702 ctxt->info.vlan_flags = ((ICE_AQ_VSI_VLAN_MODE_ALL &
703 ICE_AQ_VSI_VLAN_MODE_M) >>
704 ICE_AQ_VSI_VLAN_MODE_S);
705 /* Have 1:1 UP mapping for both ingress/egress tables */
706 table |= ICE_UP_TABLE_TRANSLATE(0, 0);
707 table |= ICE_UP_TABLE_TRANSLATE(1, 1);
708 table |= ICE_UP_TABLE_TRANSLATE(2, 2);
709 table |= ICE_UP_TABLE_TRANSLATE(3, 3);
710 table |= ICE_UP_TABLE_TRANSLATE(4, 4);
711 table |= ICE_UP_TABLE_TRANSLATE(5, 5);
712 table |= ICE_UP_TABLE_TRANSLATE(6, 6);
713 table |= ICE_UP_TABLE_TRANSLATE(7, 7);
714 ctxt->info.ingress_table = cpu_to_le32(table);
715 ctxt->info.egress_table = cpu_to_le32(table);
716 /* Have 1:1 UP mapping for outer to inner UP table */
717 ctxt->info.outer_up_table = cpu_to_le32(table);
718 /* No Outer tag support outer_tag_flags remains to zero */
722 * ice_vsi_setup_q_map - Setup a VSI queue map
723 * @vsi: the VSI being configured
724 * @ctxt: VSI context structure
726 static void ice_vsi_setup_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctxt)
728 u16 offset = 0, qmap = 0, tx_count = 0;
729 u16 qcount_tx = vsi->alloc_txq;
730 u16 qcount_rx = vsi->alloc_rxq;
731 u16 tx_numq_tc, rx_numq_tc;
732 u16 pow = 0, max_rss = 0;
733 bool ena_tc0 = false;
737 /* at least TC0 should be enabled by default */
738 if (vsi->tc_cfg.numtc) {
739 if (!(vsi->tc_cfg.ena_tc & BIT(0)))
747 vsi->tc_cfg.ena_tc |= 1;
750 rx_numq_tc = qcount_rx / vsi->tc_cfg.numtc;
753 tx_numq_tc = qcount_tx / vsi->tc_cfg.numtc;
757 /* TC mapping is a function of the number of Rx queues assigned to the
758 * VSI for each traffic class and the offset of these queues.
759 * The first 10 bits are for queue offset for TC0, next 4 bits for no:of
760 * queues allocated to TC0. No:of queues is a power-of-2.
762 * If TC is not enabled, the queue offset is set to 0, and allocate one
763 * queue, this way, traffic for the given TC will be sent to the default
766 * Setup number and offset of Rx queues for all TCs for the VSI
769 qcount_rx = rx_numq_tc;
771 /* qcount will change if RSS is enabled */
772 if (test_bit(ICE_FLAG_RSS_ENA, vsi->back->flags)) {
773 if (vsi->type == ICE_VSI_PF || vsi->type == ICE_VSI_VF) {
774 if (vsi->type == ICE_VSI_PF)
775 max_rss = ICE_MAX_LG_RSS_QS;
777 max_rss = ICE_MAX_RSS_QS_PER_VF;
778 qcount_rx = min_t(u16, rx_numq_tc, max_rss);
780 qcount_rx = min_t(u16, qcount_rx,
785 /* find the (rounded up) power-of-2 of qcount */
786 pow = (u16)order_base_2(qcount_rx);
788 ice_for_each_traffic_class(i) {
789 if (!(vsi->tc_cfg.ena_tc & BIT(i))) {
790 /* TC is not enabled */
791 vsi->tc_cfg.tc_info[i].qoffset = 0;
792 vsi->tc_cfg.tc_info[i].qcount_rx = 1;
793 vsi->tc_cfg.tc_info[i].qcount_tx = 1;
794 vsi->tc_cfg.tc_info[i].netdev_tc = 0;
795 ctxt->info.tc_mapping[i] = 0;
800 vsi->tc_cfg.tc_info[i].qoffset = offset;
801 vsi->tc_cfg.tc_info[i].qcount_rx = qcount_rx;
802 vsi->tc_cfg.tc_info[i].qcount_tx = tx_numq_tc;
803 vsi->tc_cfg.tc_info[i].netdev_tc = netdev_tc++;
805 qmap = ((offset << ICE_AQ_VSI_TC_Q_OFFSET_S) &
806 ICE_AQ_VSI_TC_Q_OFFSET_M) |
807 ((pow << ICE_AQ_VSI_TC_Q_NUM_S) &
808 ICE_AQ_VSI_TC_Q_NUM_M);
810 tx_count += tx_numq_tc;
811 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
814 /* if offset is non-zero, means it is calculated correctly based on
815 * enabled TCs for a given VSI otherwise qcount_rx will always
816 * be correct and non-zero because it is based off - VSI's
817 * allocated Rx queues which is at least 1 (hence qcount_tx will be
821 vsi->num_rxq = offset;
823 vsi->num_rxq = qcount_rx;
825 vsi->num_txq = tx_count;
827 if (vsi->type == ICE_VSI_VF && vsi->num_txq != vsi->num_rxq) {
828 dev_dbg(ice_pf_to_dev(vsi->back), "VF VSI should have same number of Tx and Rx queues. Hence making them equal\n");
829 /* since there is a chance that num_rxq could have been changed
830 * in the above for loop, make num_txq equal to num_rxq.
832 vsi->num_txq = vsi->num_rxq;
835 /* Rx queue mapping */
836 ctxt->info.mapping_flags |= cpu_to_le16(ICE_AQ_VSI_Q_MAP_CONTIG);
837 /* q_mapping buffer holds the info for the first queue allocated for
838 * this VSI in the PF space and also the number of queues associated
841 ctxt->info.q_mapping[0] = cpu_to_le16(vsi->rxq_map[0]);
842 ctxt->info.q_mapping[1] = cpu_to_le16(vsi->num_rxq);
846 * ice_set_fd_vsi_ctx - Set FD VSI context before adding a VSI
847 * @ctxt: the VSI context being set
848 * @vsi: the VSI being configured
850 static void ice_set_fd_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
852 u8 dflt_q_group, dflt_q_prio;
853 u16 dflt_q, report_q, val;
855 if (vsi->type != ICE_VSI_PF && vsi->type != ICE_VSI_CTRL)
858 val = ICE_AQ_VSI_PROP_FLOW_DIR_VALID;
859 ctxt->info.valid_sections |= cpu_to_le16(val);
865 /* enable flow director filtering/programming */
866 val = ICE_AQ_VSI_FD_ENABLE | ICE_AQ_VSI_FD_PROG_ENABLE;
867 ctxt->info.fd_options = cpu_to_le16(val);
868 /* max of allocated flow director filters */
869 ctxt->info.max_fd_fltr_dedicated =
870 cpu_to_le16(vsi->num_gfltr);
871 /* max of shared flow director filters any VSI may program */
872 ctxt->info.max_fd_fltr_shared =
873 cpu_to_le16(vsi->num_bfltr);
874 /* default queue index within the VSI of the default FD */
875 val = ((dflt_q << ICE_AQ_VSI_FD_DEF_Q_S) &
876 ICE_AQ_VSI_FD_DEF_Q_M);
877 /* target queue or queue group to the FD filter */
878 val |= ((dflt_q_group << ICE_AQ_VSI_FD_DEF_GRP_S) &
879 ICE_AQ_VSI_FD_DEF_GRP_M);
880 ctxt->info.fd_def_q = cpu_to_le16(val);
881 /* queue index on which FD filter completion is reported */
882 val = ((report_q << ICE_AQ_VSI_FD_REPORT_Q_S) &
883 ICE_AQ_VSI_FD_REPORT_Q_M);
884 /* priority of the default qindex action */
885 val |= ((dflt_q_prio << ICE_AQ_VSI_FD_DEF_PRIORITY_S) &
886 ICE_AQ_VSI_FD_DEF_PRIORITY_M);
887 ctxt->info.fd_report_opt = cpu_to_le16(val);
891 * ice_set_rss_vsi_ctx - Set RSS VSI context before adding a VSI
892 * @ctxt: the VSI context being set
893 * @vsi: the VSI being configured
895 static void ice_set_rss_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
897 u8 lut_type, hash_type;
902 dev = ice_pf_to_dev(pf);
906 /* PF VSI will inherit RSS instance of PF */
907 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_PF;
908 hash_type = ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
911 /* VF VSI will gets a small RSS table which is a VSI LUT type */
912 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI;
913 hash_type = ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
916 dev_dbg(dev, "Unsupported VSI type %s\n",
917 ice_vsi_type_str(vsi->type));
921 ctxt->info.q_opt_rss = ((lut_type << ICE_AQ_VSI_Q_OPT_RSS_LUT_S) &
922 ICE_AQ_VSI_Q_OPT_RSS_LUT_M) |
923 ((hash_type << ICE_AQ_VSI_Q_OPT_RSS_HASH_S) &
924 ICE_AQ_VSI_Q_OPT_RSS_HASH_M);
928 * ice_vsi_init - Create and initialize a VSI
929 * @vsi: the VSI being configured
930 * @init_vsi: is this call creating a VSI
932 * This initializes a VSI context depending on the VSI type to be added and
933 * passes it down to the add_vsi aq command to create a new VSI.
935 static int ice_vsi_init(struct ice_vsi *vsi, bool init_vsi)
937 struct ice_pf *pf = vsi->back;
938 struct ice_hw *hw = &pf->hw;
939 struct ice_vsi_ctx *ctxt;
943 dev = ice_pf_to_dev(pf);
944 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
952 ctxt->flags = ICE_AQ_VSI_TYPE_PF;
955 ctxt->flags = ICE_AQ_VSI_TYPE_VF;
956 /* VF number here is the absolute VF number (0-255) */
957 ctxt->vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
964 ice_set_dflt_vsi_ctx(ctxt);
965 if (test_bit(ICE_FLAG_FD_ENA, pf->flags))
966 ice_set_fd_vsi_ctx(ctxt, vsi);
967 /* if the switch is in VEB mode, allow VSI loopback */
968 if (vsi->vsw->bridge_mode == BRIDGE_MODE_VEB)
969 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
971 /* Set LUT type and HASH type if RSS is enabled */
972 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags) &&
973 vsi->type != ICE_VSI_CTRL) {
974 ice_set_rss_vsi_ctx(ctxt, vsi);
975 /* if updating VSI context, make sure to set valid_section:
976 * to indicate which section of VSI context being updated
979 ctxt->info.valid_sections |=
980 cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
983 ctxt->info.sw_id = vsi->port_info->sw_id;
984 ice_vsi_setup_q_map(vsi, ctxt);
985 if (!init_vsi) /* means VSI being updated */
986 /* must to indicate which section of VSI context are
989 ctxt->info.valid_sections |=
990 cpu_to_le16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
992 /* enable/disable MAC and VLAN anti-spoof when spoofchk is on/off
995 if (vsi->type == ICE_VSI_VF) {
996 ctxt->info.valid_sections |=
997 cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID);
998 if (pf->vf[vsi->vf_id].spoofchk) {
999 ctxt->info.sec_flags |=
1000 ICE_AQ_VSI_SEC_FLAG_ENA_MAC_ANTI_SPOOF |
1001 (ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
1002 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S);
1004 ctxt->info.sec_flags &=
1005 ~(ICE_AQ_VSI_SEC_FLAG_ENA_MAC_ANTI_SPOOF |
1006 (ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
1007 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S));
1011 /* Allow control frames out of main VSI */
1012 if (vsi->type == ICE_VSI_PF) {
1013 ctxt->info.sec_flags |= ICE_AQ_VSI_SEC_FLAG_ALLOW_DEST_OVRD;
1014 ctxt->info.valid_sections |=
1015 cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID);
1019 ret = ice_add_vsi(hw, vsi->idx, ctxt, NULL);
1021 dev_err(dev, "Add VSI failed, err %d\n", ret);
1026 ret = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1028 dev_err(dev, "Update VSI failed, err %d\n", ret);
1034 /* keep context for update VSI operations */
1035 vsi->info = ctxt->info;
1037 /* record VSI number returned */
1038 vsi->vsi_num = ctxt->vsi_num;
1046 * ice_free_res - free a block of resources
1047 * @res: pointer to the resource
1048 * @index: starting index previously returned by ice_get_res
1049 * @id: identifier to track owner
1051 * Returns number of resources freed
1053 int ice_free_res(struct ice_res_tracker *res, u16 index, u16 id)
1058 if (!res || index >= res->end)
1061 id |= ICE_RES_VALID_BIT;
1062 for (i = index; i < res->end && res->list[i] == id; i++) {
1071 * ice_search_res - Search the tracker for a block of resources
1072 * @res: pointer to the resource
1073 * @needed: size of the block needed
1074 * @id: identifier to track owner
1076 * Returns the base item index of the block, or -ENOMEM for error
1078 static int ice_search_res(struct ice_res_tracker *res, u16 needed, u16 id)
1080 u16 start = 0, end = 0;
1082 if (needed > res->end)
1085 id |= ICE_RES_VALID_BIT;
1088 /* skip already allocated entries */
1089 if (res->list[end++] & ICE_RES_VALID_BIT) {
1091 if ((start + needed) > res->end)
1095 if (end == (start + needed)) {
1098 /* there was enough, so assign it to the requestor */
1100 res->list[i++] = id;
1104 } while (end < res->end);
1110 * ice_get_free_res_count - Get free count from a resource tracker
1111 * @res: Resource tracker instance
1113 static u16 ice_get_free_res_count(struct ice_res_tracker *res)
1117 for (i = 0; i < res->end; i++)
1118 if (!(res->list[i] & ICE_RES_VALID_BIT))
1125 * ice_get_res - get a block of resources
1126 * @pf: board private structure
1127 * @res: pointer to the resource
1128 * @needed: size of the block needed
1129 * @id: identifier to track owner
1131 * Returns the base item index of the block, or negative for error
1134 ice_get_res(struct ice_pf *pf, struct ice_res_tracker *res, u16 needed, u16 id)
1139 if (!needed || needed > res->num_entries || id >= ICE_RES_VALID_BIT) {
1140 dev_err(ice_pf_to_dev(pf), "param err: needed=%d, num_entries = %d id=0x%04x\n",
1141 needed, res->num_entries, id);
1145 return ice_search_res(res, needed, id);
1149 * ice_vsi_setup_vector_base - Set up the base vector for the given VSI
1150 * @vsi: ptr to the VSI
1152 * This should only be called after ice_vsi_alloc() which allocates the
1153 * corresponding SW VSI structure and initializes num_queue_pairs for the
1154 * newly allocated VSI.
1156 * Returns 0 on success or negative on failure
1158 static int ice_vsi_setup_vector_base(struct ice_vsi *vsi)
1160 struct ice_pf *pf = vsi->back;
1165 dev = ice_pf_to_dev(pf);
1166 /* SRIOV doesn't grab irq_tracker entries for each VSI */
1167 if (vsi->type == ICE_VSI_VF)
1170 if (vsi->base_vector) {
1171 dev_dbg(dev, "VSI %d has non-zero base vector %d\n",
1172 vsi->vsi_num, vsi->base_vector);
1176 num_q_vectors = vsi->num_q_vectors;
1177 /* reserve slots from OS requested IRQs */
1178 base = ice_get_res(pf, pf->irq_tracker, num_q_vectors, vsi->idx);
1181 dev_err(dev, "%d MSI-X interrupts available. %s %d failed to get %d MSI-X vectors\n",
1182 ice_get_free_res_count(pf->irq_tracker),
1183 ice_vsi_type_str(vsi->type), vsi->idx, num_q_vectors);
1186 vsi->base_vector = (u16)base;
1187 pf->num_avail_sw_msix -= num_q_vectors;
1193 * ice_vsi_clear_rings - Deallocates the Tx and Rx rings for VSI
1194 * @vsi: the VSI having rings deallocated
1196 static void ice_vsi_clear_rings(struct ice_vsi *vsi)
1200 /* Avoid stale references by clearing map from vector to ring */
1201 if (vsi->q_vectors) {
1202 ice_for_each_q_vector(vsi, i) {
1203 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1206 q_vector->tx.ring = NULL;
1207 q_vector->rx.ring = NULL;
1212 if (vsi->tx_rings) {
1213 for (i = 0; i < vsi->alloc_txq; i++) {
1214 if (vsi->tx_rings[i]) {
1215 kfree_rcu(vsi->tx_rings[i], rcu);
1216 WRITE_ONCE(vsi->tx_rings[i], NULL);
1220 if (vsi->rx_rings) {
1221 for (i = 0; i < vsi->alloc_rxq; i++) {
1222 if (vsi->rx_rings[i]) {
1223 kfree_rcu(vsi->rx_rings[i], rcu);
1224 WRITE_ONCE(vsi->rx_rings[i], NULL);
1231 * ice_vsi_alloc_rings - Allocates Tx and Rx rings for the VSI
1232 * @vsi: VSI which is having rings allocated
1234 static int ice_vsi_alloc_rings(struct ice_vsi *vsi)
1236 struct ice_pf *pf = vsi->back;
1240 dev = ice_pf_to_dev(pf);
1241 /* Allocate Tx rings */
1242 for (i = 0; i < vsi->alloc_txq; i++) {
1243 struct ice_ring *ring;
1245 /* allocate with kzalloc(), free with kfree_rcu() */
1246 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1252 ring->reg_idx = vsi->txq_map[i];
1253 ring->ring_active = false;
1256 ring->count = vsi->num_tx_desc;
1257 WRITE_ONCE(vsi->tx_rings[i], ring);
1260 /* Allocate Rx rings */
1261 for (i = 0; i < vsi->alloc_rxq; i++) {
1262 struct ice_ring *ring;
1264 /* allocate with kzalloc(), free with kfree_rcu() */
1265 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1270 ring->reg_idx = vsi->rxq_map[i];
1271 ring->ring_active = false;
1273 ring->netdev = vsi->netdev;
1275 ring->count = vsi->num_rx_desc;
1276 WRITE_ONCE(vsi->rx_rings[i], ring);
1282 ice_vsi_clear_rings(vsi);
1287 * ice_vsi_manage_rss_lut - disable/enable RSS
1288 * @vsi: the VSI being changed
1289 * @ena: boolean value indicating if this is an enable or disable request
1291 * In the event of disable request for RSS, this function will zero out RSS
1292 * LUT, while in the event of enable request for RSS, it will reconfigure RSS
1295 int ice_vsi_manage_rss_lut(struct ice_vsi *vsi, bool ena)
1300 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
1305 if (vsi->rss_lut_user)
1306 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1308 ice_fill_rss_lut(lut, vsi->rss_table_size,
1312 err = ice_set_rss(vsi, NULL, lut, vsi->rss_table_size);
1318 * ice_vsi_cfg_rss_lut_key - Configure RSS params for a VSI
1319 * @vsi: VSI to be configured
1321 static int ice_vsi_cfg_rss_lut_key(struct ice_vsi *vsi)
1323 struct ice_aqc_get_set_rss_keys *key;
1324 struct ice_pf *pf = vsi->back;
1325 enum ice_status status;
1330 dev = ice_pf_to_dev(pf);
1331 vsi->rss_size = min_t(u16, vsi->rss_size, vsi->num_rxq);
1333 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
1337 if (vsi->rss_lut_user)
1338 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1340 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
1342 status = ice_aq_set_rss_lut(&pf->hw, vsi->idx, vsi->rss_lut_type, lut,
1343 vsi->rss_table_size);
1346 dev_err(dev, "set_rss_lut failed, error %s\n",
1347 ice_stat_str(status));
1349 goto ice_vsi_cfg_rss_exit;
1352 key = kzalloc(sizeof(*key), GFP_KERNEL);
1355 goto ice_vsi_cfg_rss_exit;
1358 if (vsi->rss_hkey_user)
1360 (struct ice_aqc_get_set_rss_keys *)vsi->rss_hkey_user,
1361 ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE);
1363 netdev_rss_key_fill((void *)key,
1364 ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE);
1366 status = ice_aq_set_rss_key(&pf->hw, vsi->idx, key);
1369 dev_err(dev, "set_rss_key failed, error %s\n",
1370 ice_stat_str(status));
1375 ice_vsi_cfg_rss_exit:
1381 * ice_vsi_set_vf_rss_flow_fld - Sets VF VSI RSS input set for different flows
1382 * @vsi: VSI to be configured
1384 * This function will only be called during the VF VSI setup. Upon successful
1385 * completion of package download, this function will configure default RSS
1386 * input sets for VF VSI.
1388 static void ice_vsi_set_vf_rss_flow_fld(struct ice_vsi *vsi)
1390 struct ice_pf *pf = vsi->back;
1391 enum ice_status status;
1394 dev = ice_pf_to_dev(pf);
1395 if (ice_is_safe_mode(pf)) {
1396 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
1401 status = ice_add_avf_rss_cfg(&pf->hw, vsi->idx, ICE_DEFAULT_RSS_HENA);
1403 dev_dbg(dev, "ice_add_avf_rss_cfg failed for vsi = %d, error = %s\n",
1404 vsi->vsi_num, ice_stat_str(status));
1408 * ice_vsi_set_rss_flow_fld - Sets RSS input set for different flows
1409 * @vsi: VSI to be configured
1411 * This function will only be called after successful download package call
1412 * during initialization of PF. Since the downloaded package will erase the
1413 * RSS section, this function will configure RSS input sets for different
1414 * flow types. The last profile added has the highest priority, therefore 2
1415 * tuple profiles (i.e. IPv4 src/dst) are added before 4 tuple profiles
1416 * (i.e. IPv4 src/dst TCP src/dst port).
1418 static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi)
1420 u16 vsi_handle = vsi->idx, vsi_num = vsi->vsi_num;
1421 struct ice_pf *pf = vsi->back;
1422 struct ice_hw *hw = &pf->hw;
1423 enum ice_status status;
1426 dev = ice_pf_to_dev(pf);
1427 if (ice_is_safe_mode(pf)) {
1428 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
1432 /* configure RSS for IPv4 with input set IP src/dst */
1433 status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV4,
1434 ICE_FLOW_SEG_HDR_IPV4);
1436 dev_dbg(dev, "ice_add_rss_cfg failed for ipv4 flow, vsi = %d, error = %s\n",
1437 vsi_num, ice_stat_str(status));
1439 /* configure RSS for IPv6 with input set IPv6 src/dst */
1440 status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV6,
1441 ICE_FLOW_SEG_HDR_IPV6);
1443 dev_dbg(dev, "ice_add_rss_cfg failed for ipv6 flow, vsi = %d, error = %s\n",
1444 vsi_num, ice_stat_str(status));
1446 /* configure RSS for tcp4 with input set IP src/dst, TCP src/dst */
1447 status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_TCP_IPV4,
1448 ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4);
1450 dev_dbg(dev, "ice_add_rss_cfg failed for tcp4 flow, vsi = %d, error = %s\n",
1451 vsi_num, ice_stat_str(status));
1453 /* configure RSS for udp4 with input set IP src/dst, UDP src/dst */
1454 status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_UDP_IPV4,
1455 ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4);
1457 dev_dbg(dev, "ice_add_rss_cfg failed for udp4 flow, vsi = %d, error = %s\n",
1458 vsi_num, ice_stat_str(status));
1460 /* configure RSS for sctp4 with input set IP src/dst */
1461 status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV4,
1462 ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4);
1464 dev_dbg(dev, "ice_add_rss_cfg failed for sctp4 flow, vsi = %d, error = %s\n",
1465 vsi_num, ice_stat_str(status));
1467 /* configure RSS for tcp6 with input set IPv6 src/dst, TCP src/dst */
1468 status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_TCP_IPV6,
1469 ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6);
1471 dev_dbg(dev, "ice_add_rss_cfg failed for tcp6 flow, vsi = %d, error = %s\n",
1472 vsi_num, ice_stat_str(status));
1474 /* configure RSS for udp6 with input set IPv6 src/dst, UDP src/dst */
1475 status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_UDP_IPV6,
1476 ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6);
1478 dev_dbg(dev, "ice_add_rss_cfg failed for udp6 flow, vsi = %d, error = %s\n",
1479 vsi_num, ice_stat_str(status));
1481 /* configure RSS for sctp6 with input set IPv6 src/dst */
1482 status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV6,
1483 ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6);
1485 dev_dbg(dev, "ice_add_rss_cfg failed for sctp6 flow, vsi = %d, error = %s\n",
1486 vsi_num, ice_stat_str(status));
1490 * ice_pf_state_is_nominal - checks the PF for nominal state
1491 * @pf: pointer to PF to check
1493 * Check the PF's state for a collection of bits that would indicate
1494 * the PF is in a state that would inhibit normal operation for
1495 * driver functionality.
1497 * Returns true if PF is in a nominal state, false otherwise
1499 bool ice_pf_state_is_nominal(struct ice_pf *pf)
1501 DECLARE_BITMAP(check_bits, __ICE_STATE_NBITS) = { 0 };
1506 bitmap_set(check_bits, 0, __ICE_STATE_NOMINAL_CHECK_BITS);
1507 if (bitmap_intersects(pf->state, check_bits, __ICE_STATE_NBITS))
1514 * ice_update_eth_stats - Update VSI-specific ethernet statistics counters
1515 * @vsi: the VSI to be updated
1517 void ice_update_eth_stats(struct ice_vsi *vsi)
1519 struct ice_eth_stats *prev_es, *cur_es;
1520 struct ice_hw *hw = &vsi->back->hw;
1521 u16 vsi_num = vsi->vsi_num; /* HW absolute index of a VSI */
1523 prev_es = &vsi->eth_stats_prev;
1524 cur_es = &vsi->eth_stats;
1526 ice_stat_update40(hw, GLV_GORCL(vsi_num), vsi->stat_offsets_loaded,
1527 &prev_es->rx_bytes, &cur_es->rx_bytes);
1529 ice_stat_update40(hw, GLV_UPRCL(vsi_num), vsi->stat_offsets_loaded,
1530 &prev_es->rx_unicast, &cur_es->rx_unicast);
1532 ice_stat_update40(hw, GLV_MPRCL(vsi_num), vsi->stat_offsets_loaded,
1533 &prev_es->rx_multicast, &cur_es->rx_multicast);
1535 ice_stat_update40(hw, GLV_BPRCL(vsi_num), vsi->stat_offsets_loaded,
1536 &prev_es->rx_broadcast, &cur_es->rx_broadcast);
1538 ice_stat_update32(hw, GLV_RDPC(vsi_num), vsi->stat_offsets_loaded,
1539 &prev_es->rx_discards, &cur_es->rx_discards);
1541 ice_stat_update40(hw, GLV_GOTCL(vsi_num), vsi->stat_offsets_loaded,
1542 &prev_es->tx_bytes, &cur_es->tx_bytes);
1544 ice_stat_update40(hw, GLV_UPTCL(vsi_num), vsi->stat_offsets_loaded,
1545 &prev_es->tx_unicast, &cur_es->tx_unicast);
1547 ice_stat_update40(hw, GLV_MPTCL(vsi_num), vsi->stat_offsets_loaded,
1548 &prev_es->tx_multicast, &cur_es->tx_multicast);
1550 ice_stat_update40(hw, GLV_BPTCL(vsi_num), vsi->stat_offsets_loaded,
1551 &prev_es->tx_broadcast, &cur_es->tx_broadcast);
1553 ice_stat_update32(hw, GLV_TEPC(vsi_num), vsi->stat_offsets_loaded,
1554 &prev_es->tx_errors, &cur_es->tx_errors);
1556 vsi->stat_offsets_loaded = true;
1560 * ice_vsi_add_vlan - Add VSI membership for given VLAN
1561 * @vsi: the VSI being configured
1562 * @vid: VLAN ID to be added
1563 * @action: filter action to be performed on match
1566 ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid, enum ice_sw_fwd_act_type action)
1568 struct ice_pf *pf = vsi->back;
1572 dev = ice_pf_to_dev(pf);
1574 if (!ice_fltr_add_vlan(vsi, vid, action)) {
1578 dev_err(dev, "Failure Adding VLAN %d on VSI %i\n", vid,
1586 * ice_vsi_kill_vlan - Remove VSI membership for a given VLAN
1587 * @vsi: the VSI being configured
1588 * @vid: VLAN ID to be removed
1590 * Returns 0 on success and negative on failure
1592 int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid)
1594 struct ice_pf *pf = vsi->back;
1595 enum ice_status status;
1599 dev = ice_pf_to_dev(pf);
1601 status = ice_fltr_remove_vlan(vsi, vid, ICE_FWD_TO_VSI);
1604 } else if (status == ICE_ERR_DOES_NOT_EXIST) {
1605 dev_dbg(dev, "Failed to remove VLAN %d on VSI %i, it does not exist, status: %s\n",
1606 vid, vsi->vsi_num, ice_stat_str(status));
1608 dev_err(dev, "Error removing VLAN %d on vsi %i error: %s\n",
1609 vid, vsi->vsi_num, ice_stat_str(status));
1617 * ice_vsi_cfg_frame_size - setup max frame size and Rx buffer length
1620 void ice_vsi_cfg_frame_size(struct ice_vsi *vsi)
1622 if (!vsi->netdev || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags)) {
1623 vsi->max_frame = ICE_AQ_SET_MAC_FRAME_SIZE_MAX;
1624 vsi->rx_buf_len = ICE_RXBUF_2048;
1625 #if (PAGE_SIZE < 8192)
1626 } else if (!ICE_2K_TOO_SMALL_WITH_PADDING &&
1627 (vsi->netdev->mtu <= ETH_DATA_LEN)) {
1628 vsi->max_frame = ICE_RXBUF_1536 - NET_IP_ALIGN;
1629 vsi->rx_buf_len = ICE_RXBUF_1536 - NET_IP_ALIGN;
1632 vsi->max_frame = ICE_AQ_SET_MAC_FRAME_SIZE_MAX;
1633 #if (PAGE_SIZE < 8192)
1634 vsi->rx_buf_len = ICE_RXBUF_3072;
1636 vsi->rx_buf_len = ICE_RXBUF_2048;
1642 * ice_write_qrxflxp_cntxt - write/configure QRXFLXP_CNTXT register
1644 * @pf_q: index of the Rx queue in the PF's queue space
1645 * @rxdid: flexible descriptor RXDID
1646 * @prio: priority for the RXDID for this queue
1649 ice_write_qrxflxp_cntxt(struct ice_hw *hw, u16 pf_q, u32 rxdid, u32 prio)
1651 int regval = rd32(hw, QRXFLXP_CNTXT(pf_q));
1653 /* clear any previous values */
1654 regval &= ~(QRXFLXP_CNTXT_RXDID_IDX_M |
1655 QRXFLXP_CNTXT_RXDID_PRIO_M |
1656 QRXFLXP_CNTXT_TS_M);
1658 regval |= (rxdid << QRXFLXP_CNTXT_RXDID_IDX_S) &
1659 QRXFLXP_CNTXT_RXDID_IDX_M;
1661 regval |= (prio << QRXFLXP_CNTXT_RXDID_PRIO_S) &
1662 QRXFLXP_CNTXT_RXDID_PRIO_M;
1664 wr32(hw, QRXFLXP_CNTXT(pf_q), regval);
1668 * ice_vsi_cfg_rxqs - Configure the VSI for Rx
1669 * @vsi: the VSI being configured
1671 * Return 0 on success and a negative value on error
1672 * Configure the Rx VSI for operation.
1674 int ice_vsi_cfg_rxqs(struct ice_vsi *vsi)
1678 if (vsi->type == ICE_VSI_VF)
1681 ice_vsi_cfg_frame_size(vsi);
1683 /* set up individual rings */
1684 for (i = 0; i < vsi->num_rxq; i++) {
1687 err = ice_setup_rx_ctx(vsi->rx_rings[i]);
1689 dev_err(ice_pf_to_dev(vsi->back), "ice_setup_rx_ctx failed for RxQ %d, err %d\n",
1699 * ice_vsi_cfg_txqs - Configure the VSI for Tx
1700 * @vsi: the VSI being configured
1701 * @rings: Tx ring array to be configured
1703 * Return 0 on success and a negative value on error
1704 * Configure the Tx VSI for operation.
1707 ice_vsi_cfg_txqs(struct ice_vsi *vsi, struct ice_ring **rings)
1709 struct ice_aqc_add_tx_qgrp *qg_buf;
1713 qg_buf = kzalloc(struct_size(qg_buf, txqs, 1), GFP_KERNEL);
1717 qg_buf->num_txqs = 1;
1719 for (q_idx = 0; q_idx < vsi->num_txq; q_idx++) {
1720 err = ice_vsi_cfg_txq(vsi, rings[q_idx], qg_buf);
1731 * ice_vsi_cfg_lan_txqs - Configure the VSI for Tx
1732 * @vsi: the VSI being configured
1734 * Return 0 on success and a negative value on error
1735 * Configure the Tx VSI for operation.
1737 int ice_vsi_cfg_lan_txqs(struct ice_vsi *vsi)
1739 return ice_vsi_cfg_txqs(vsi, vsi->tx_rings);
1743 * ice_vsi_cfg_xdp_txqs - Configure Tx queues dedicated for XDP in given VSI
1744 * @vsi: the VSI being configured
1746 * Return 0 on success and a negative value on error
1747 * Configure the Tx queues dedicated for XDP in given VSI for operation.
1749 int ice_vsi_cfg_xdp_txqs(struct ice_vsi *vsi)
1754 ret = ice_vsi_cfg_txqs(vsi, vsi->xdp_rings);
1758 for (i = 0; i < vsi->num_xdp_txq; i++)
1759 vsi->xdp_rings[i]->xsk_pool = ice_xsk_pool(vsi->xdp_rings[i]);
1765 * ice_intrl_usec_to_reg - convert interrupt rate limit to register value
1766 * @intrl: interrupt rate limit in usecs
1767 * @gran: interrupt rate limit granularity in usecs
1769 * This function converts a decimal interrupt rate limit in usecs to the format
1770 * expected by firmware.
1772 u32 ice_intrl_usec_to_reg(u8 intrl, u8 gran)
1774 u32 val = intrl / gran;
1777 return val | GLINT_RATE_INTRL_ENA_M;
1782 * ice_vsi_cfg_msix - MSIX mode Interrupt Config in the HW
1783 * @vsi: the VSI being configured
1785 * This configures MSIX mode interrupts for the PF VSI, and should not be used
1788 void ice_vsi_cfg_msix(struct ice_vsi *vsi)
1790 struct ice_pf *pf = vsi->back;
1791 struct ice_hw *hw = &pf->hw;
1792 u16 txq = 0, rxq = 0;
1795 for (i = 0; i < vsi->num_q_vectors; i++) {
1796 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1797 u16 reg_idx = q_vector->reg_idx;
1799 ice_cfg_itr(hw, q_vector);
1801 wr32(hw, GLINT_RATE(reg_idx),
1802 ice_intrl_usec_to_reg(q_vector->intrl, hw->intrl_gran));
1804 /* Both Transmit Queue Interrupt Cause Control register
1805 * and Receive Queue Interrupt Cause control register
1806 * expects MSIX_INDX field to be the vector index
1807 * within the function space and not the absolute
1808 * vector index across PF or across device.
1809 * For SR-IOV VF VSIs queue vector index always starts
1810 * with 1 since first vector index(0) is used for OICR
1811 * in VF space. Since VMDq and other PF VSIs are within
1812 * the PF function space, use the vector index that is
1813 * tracked for this PF.
1815 for (q = 0; q < q_vector->num_ring_tx; q++) {
1816 ice_cfg_txq_interrupt(vsi, txq, reg_idx,
1817 q_vector->tx.itr_idx);
1821 for (q = 0; q < q_vector->num_ring_rx; q++) {
1822 ice_cfg_rxq_interrupt(vsi, rxq, reg_idx,
1823 q_vector->rx.itr_idx);
1830 * ice_vsi_manage_vlan_insertion - Manage VLAN insertion for the VSI for Tx
1831 * @vsi: the VSI being changed
1833 int ice_vsi_manage_vlan_insertion(struct ice_vsi *vsi)
1835 struct ice_hw *hw = &vsi->back->hw;
1836 struct ice_vsi_ctx *ctxt;
1837 enum ice_status status;
1840 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
1844 /* Here we are configuring the VSI to let the driver add VLAN tags by
1845 * setting vlan_flags to ICE_AQ_VSI_VLAN_MODE_ALL. The actual VLAN tag
1846 * insertion happens in the Tx hot path, in ice_tx_map.
1848 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_MODE_ALL;
1850 /* Preserve existing VLAN strip setting */
1851 ctxt->info.vlan_flags |= (vsi->info.vlan_flags &
1852 ICE_AQ_VSI_VLAN_EMOD_M);
1854 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
1856 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1858 dev_err(ice_pf_to_dev(vsi->back), "update VSI for VLAN insert failed, err %s aq_err %s\n",
1859 ice_stat_str(status),
1860 ice_aq_str(hw->adminq.sq_last_status));
1865 vsi->info.vlan_flags = ctxt->info.vlan_flags;
1872 * ice_vsi_manage_vlan_stripping - Manage VLAN stripping for the VSI for Rx
1873 * @vsi: the VSI being changed
1874 * @ena: boolean value indicating if this is a enable or disable request
1876 int ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
1878 struct ice_hw *hw = &vsi->back->hw;
1879 struct ice_vsi_ctx *ctxt;
1880 enum ice_status status;
1883 /* do not allow modifying VLAN stripping when a port VLAN is configured
1889 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
1893 /* Here we are configuring what the VSI should do with the VLAN tag in
1894 * the Rx packet. We can either leave the tag in the packet or put it in
1895 * the Rx descriptor.
1898 /* Strip VLAN tag from Rx packet and put it in the desc */
1899 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_STR_BOTH;
1901 /* Disable stripping. Leave tag in packet */
1902 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_NOTHING;
1904 /* Allow all packets untagged/tagged */
1905 ctxt->info.vlan_flags |= ICE_AQ_VSI_VLAN_MODE_ALL;
1907 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
1909 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1911 dev_err(ice_pf_to_dev(vsi->back), "update VSI for VLAN strip failed, ena = %d err %s aq_err %s\n",
1912 ena, ice_stat_str(status),
1913 ice_aq_str(hw->adminq.sq_last_status));
1918 vsi->info.vlan_flags = ctxt->info.vlan_flags;
1925 * ice_vsi_start_all_rx_rings - start/enable all of a VSI's Rx rings
1926 * @vsi: the VSI whose rings are to be enabled
1928 * Returns 0 on success and a negative value on error
1930 int ice_vsi_start_all_rx_rings(struct ice_vsi *vsi)
1932 return ice_vsi_ctrl_all_rx_rings(vsi, true);
1936 * ice_vsi_stop_all_rx_rings - stop/disable all of a VSI's Rx rings
1937 * @vsi: the VSI whose rings are to be disabled
1939 * Returns 0 on success and a negative value on error
1941 int ice_vsi_stop_all_rx_rings(struct ice_vsi *vsi)
1943 return ice_vsi_ctrl_all_rx_rings(vsi, false);
1947 * ice_vsi_stop_tx_rings - Disable Tx rings
1948 * @vsi: the VSI being configured
1949 * @rst_src: reset source
1950 * @rel_vmvf_num: Relative ID of VF/VM
1951 * @rings: Tx ring array to be stopped
1954 ice_vsi_stop_tx_rings(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
1955 u16 rel_vmvf_num, struct ice_ring **rings)
1959 if (vsi->num_txq > ICE_LAN_TXQ_MAX_QDIS)
1962 for (q_idx = 0; q_idx < vsi->num_txq; q_idx++) {
1963 struct ice_txq_meta txq_meta = { };
1966 if (!rings || !rings[q_idx])
1969 ice_fill_txq_meta(vsi, rings[q_idx], &txq_meta);
1970 status = ice_vsi_stop_tx_ring(vsi, rst_src, rel_vmvf_num,
1971 rings[q_idx], &txq_meta);
1981 * ice_vsi_stop_lan_tx_rings - Disable LAN Tx rings
1982 * @vsi: the VSI being configured
1983 * @rst_src: reset source
1984 * @rel_vmvf_num: Relative ID of VF/VM
1987 ice_vsi_stop_lan_tx_rings(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
1990 return ice_vsi_stop_tx_rings(vsi, rst_src, rel_vmvf_num, vsi->tx_rings);
1994 * ice_vsi_stop_xdp_tx_rings - Disable XDP Tx rings
1995 * @vsi: the VSI being configured
1997 int ice_vsi_stop_xdp_tx_rings(struct ice_vsi *vsi)
1999 return ice_vsi_stop_tx_rings(vsi, ICE_NO_RESET, 0, vsi->xdp_rings);
2003 * ice_vsi_is_vlan_pruning_ena - check if VLAN pruning is enabled or not
2004 * @vsi: VSI to check whether or not VLAN pruning is enabled.
2006 * returns true if Rx VLAN pruning is enabled and false otherwise.
2008 bool ice_vsi_is_vlan_pruning_ena(struct ice_vsi *vsi)
2013 return (vsi->info.sw_flags2 & ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA);
2017 * ice_cfg_vlan_pruning - enable or disable VLAN pruning on the VSI
2018 * @vsi: VSI to enable or disable VLAN pruning on
2019 * @ena: set to true to enable VLAN pruning and false to disable it
2020 * @vlan_promisc: enable valid security flags if not in VLAN promiscuous mode
2022 * returns 0 if VSI is updated, negative otherwise
2024 int ice_cfg_vlan_pruning(struct ice_vsi *vsi, bool ena, bool vlan_promisc)
2026 struct ice_vsi_ctx *ctxt;
2033 /* Don't enable VLAN pruning if the netdev is currently in promiscuous
2034 * mode. VLAN pruning will be enabled when the interface exits
2035 * promiscuous mode if any VLAN filters are active.
2037 if (vsi->netdev && vsi->netdev->flags & IFF_PROMISC && ena)
2041 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
2045 ctxt->info = vsi->info;
2048 ctxt->info.sw_flags2 |= ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
2050 ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
2053 ctxt->info.valid_sections =
2054 cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
2056 status = ice_update_vsi(&pf->hw, vsi->idx, ctxt, NULL);
2058 netdev_err(vsi->netdev, "%sabling VLAN pruning on VSI handle: %d, VSI HW ID: %d failed, err = %s, aq_err = %s\n",
2059 ena ? "En" : "Dis", vsi->idx, vsi->vsi_num,
2060 ice_stat_str(status),
2061 ice_aq_str(pf->hw.adminq.sq_last_status));
2065 vsi->info.sw_flags2 = ctxt->info.sw_flags2;
2075 static void ice_vsi_set_tc_cfg(struct ice_vsi *vsi)
2077 struct ice_dcbx_cfg *cfg = &vsi->port_info->local_dcbx_cfg;
2079 vsi->tc_cfg.ena_tc = ice_dcb_get_ena_tc(cfg);
2080 vsi->tc_cfg.numtc = ice_dcb_get_num_tc(cfg);
2084 * ice_vsi_set_q_vectors_reg_idx - set the HW register index for all q_vectors
2085 * @vsi: VSI to set the q_vectors register index on
2088 ice_vsi_set_q_vectors_reg_idx(struct ice_vsi *vsi)
2092 if (!vsi || !vsi->q_vectors)
2095 ice_for_each_q_vector(vsi, i) {
2096 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2099 dev_err(ice_pf_to_dev(vsi->back), "Failed to set reg_idx on q_vector %d VSI %d\n",
2104 if (vsi->type == ICE_VSI_VF) {
2105 struct ice_vf *vf = &vsi->back->vf[vsi->vf_id];
2107 q_vector->reg_idx = ice_calc_vf_reg_idx(vf, q_vector);
2110 q_vector->v_idx + vsi->base_vector;
2117 ice_for_each_q_vector(vsi, i) {
2118 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2121 q_vector->reg_idx = 0;
2128 * ice_cfg_sw_lldp - Config switch rules for LLDP packet handling
2129 * @vsi: the VSI being configured
2130 * @tx: bool to determine Tx or Rx rule
2131 * @create: bool to determine create or remove Rule
2133 void ice_cfg_sw_lldp(struct ice_vsi *vsi, bool tx, bool create)
2135 enum ice_status (*eth_fltr)(struct ice_vsi *v, u16 type, u16 flag,
2136 enum ice_sw_fwd_act_type act);
2137 struct ice_pf *pf = vsi->back;
2138 enum ice_status status;
2141 dev = ice_pf_to_dev(pf);
2142 eth_fltr = create ? ice_fltr_add_eth : ice_fltr_remove_eth;
2145 status = eth_fltr(vsi, ETH_P_LLDP, ICE_FLTR_TX,
2148 status = eth_fltr(vsi, ETH_P_LLDP, ICE_FLTR_RX, ICE_FWD_TO_VSI);
2151 dev_err(dev, "Fail %s %s LLDP rule on VSI %i error: %s\n",
2152 create ? "adding" : "removing", tx ? "TX" : "RX",
2153 vsi->vsi_num, ice_stat_str(status));
2157 * ice_vsi_setup - Set up a VSI by a given type
2158 * @pf: board private structure
2159 * @pi: pointer to the port_info instance
2160 * @vsi_type: VSI type
2161 * @vf_id: defines VF ID to which this VSI connects. This field is meant to be
2162 * used only for ICE_VSI_VF VSI type. For other VSI types, should
2163 * fill-in ICE_INVAL_VFID as input.
2165 * This allocates the sw VSI structure and its queue resources.
2167 * Returns pointer to the successfully allocated and configured VSI sw struct on
2168 * success, NULL on failure.
2171 ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
2172 enum ice_vsi_type vsi_type, u16 vf_id)
2174 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2175 struct device *dev = ice_pf_to_dev(pf);
2176 enum ice_status status;
2177 struct ice_vsi *vsi;
2180 if (vsi_type == ICE_VSI_VF)
2181 vsi = ice_vsi_alloc(pf, vsi_type, vf_id);
2183 vsi = ice_vsi_alloc(pf, vsi_type, ICE_INVAL_VFID);
2186 dev_err(dev, "could not allocate VSI\n");
2190 vsi->port_info = pi;
2191 vsi->vsw = pf->first_sw;
2192 if (vsi->type == ICE_VSI_PF)
2193 vsi->ethtype = ETH_P_PAUSE;
2195 if (vsi->type == ICE_VSI_VF)
2198 ice_alloc_fd_res(vsi);
2200 if (ice_vsi_get_qs(vsi)) {
2201 dev_err(dev, "Failed to allocate queues. vsi->idx = %d\n",
2203 goto unroll_vsi_alloc;
2206 /* set RSS capabilities */
2207 ice_vsi_set_rss_params(vsi);
2209 /* set TC configuration */
2210 ice_vsi_set_tc_cfg(vsi);
2212 /* create the VSI */
2213 ret = ice_vsi_init(vsi, true);
2217 switch (vsi->type) {
2220 ret = ice_vsi_alloc_q_vectors(vsi);
2222 goto unroll_vsi_init;
2224 ret = ice_vsi_setup_vector_base(vsi);
2226 goto unroll_alloc_q_vector;
2228 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2230 goto unroll_vector_base;
2232 ret = ice_vsi_alloc_rings(vsi);
2234 goto unroll_vector_base;
2236 /* Always add VLAN ID 0 switch rule by default. This is needed
2237 * in order to allow all untagged and 0 tagged priority traffic
2238 * if Rx VLAN pruning is enabled. Also there are cases where we
2239 * don't get the call to add VLAN 0 via ice_vlan_rx_add_vid()
2240 * so this handles those cases (i.e. adding the PF to a bridge
2241 * without the 8021q module loaded).
2243 ret = ice_vsi_add_vlan(vsi, 0, ICE_FWD_TO_VSI);
2245 goto unroll_clear_rings;
2247 ice_vsi_map_rings_to_vectors(vsi);
2249 /* ICE_VSI_CTRL does not need RSS so skip RSS processing */
2250 if (vsi->type != ICE_VSI_CTRL)
2251 /* Do not exit if configuring RSS had an issue, at
2252 * least receive traffic on first queue. Hence no
2253 * need to capture return value
2255 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
2256 ice_vsi_cfg_rss_lut_key(vsi);
2257 ice_vsi_set_rss_flow_fld(vsi);
2262 /* VF driver will take care of creating netdev for this type and
2263 * map queues to vectors through Virtchnl, PF driver only
2264 * creates a VSI and corresponding structures for bookkeeping
2267 ret = ice_vsi_alloc_q_vectors(vsi);
2269 goto unroll_vsi_init;
2271 ret = ice_vsi_alloc_rings(vsi);
2273 goto unroll_alloc_q_vector;
2275 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2277 goto unroll_vector_base;
2279 /* Do not exit if configuring RSS had an issue, at least
2280 * receive traffic on first queue. Hence no need to capture
2283 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
2284 ice_vsi_cfg_rss_lut_key(vsi);
2285 ice_vsi_set_vf_rss_flow_fld(vsi);
2289 ret = ice_vsi_alloc_rings(vsi);
2291 goto unroll_vsi_init;
2294 /* clean up the resources and exit */
2295 goto unroll_vsi_init;
2298 /* configure VSI nodes based on number of queues and TC's */
2299 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2300 max_txqs[i] = vsi->alloc_txq;
2302 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2305 dev_err(dev, "VSI %d failed lan queue config, error %s\n",
2306 vsi->vsi_num, ice_stat_str(status));
2307 goto unroll_clear_rings;
2310 /* Add switch rule to drop all Tx Flow Control Frames, of look up
2311 * type ETHERTYPE from VSIs, and restrict malicious VF from sending
2312 * out PAUSE or PFC frames. If enabled, FW can still send FC frames.
2313 * The rule is added once for PF VSI in order to create appropriate
2314 * recipe, since VSI/VSI list is ignored with drop action...
2315 * Also add rules to handle LLDP Tx packets. Tx LLDP packets need to
2316 * be dropped so that VFs cannot send LLDP packets to reconfig DCB
2317 * settings in the HW.
2319 if (!ice_is_safe_mode(pf))
2320 if (vsi->type == ICE_VSI_PF) {
2321 ice_fltr_add_eth(vsi, ETH_P_PAUSE, ICE_FLTR_TX,
2323 ice_cfg_sw_lldp(vsi, true, true);
2329 ice_vsi_clear_rings(vsi);
2331 /* reclaim SW interrupts back to the common pool */
2332 ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
2333 pf->num_avail_sw_msix += vsi->num_q_vectors;
2334 unroll_alloc_q_vector:
2335 ice_vsi_free_q_vectors(vsi);
2337 ice_vsi_delete(vsi);
2339 ice_vsi_put_qs(vsi);
2347 * ice_vsi_release_msix - Clear the queue to Interrupt mapping in HW
2348 * @vsi: the VSI being cleaned up
2350 static void ice_vsi_release_msix(struct ice_vsi *vsi)
2352 struct ice_pf *pf = vsi->back;
2353 struct ice_hw *hw = &pf->hw;
2358 for (i = 0; i < vsi->num_q_vectors; i++) {
2359 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2360 u16 reg_idx = q_vector->reg_idx;
2362 wr32(hw, GLINT_ITR(ICE_IDX_ITR0, reg_idx), 0);
2363 wr32(hw, GLINT_ITR(ICE_IDX_ITR1, reg_idx), 0);
2364 for (q = 0; q < q_vector->num_ring_tx; q++) {
2365 wr32(hw, QINT_TQCTL(vsi->txq_map[txq]), 0);
2366 if (ice_is_xdp_ena_vsi(vsi)) {
2367 u32 xdp_txq = txq + vsi->num_xdp_txq;
2369 wr32(hw, QINT_TQCTL(vsi->txq_map[xdp_txq]), 0);
2374 for (q = 0; q < q_vector->num_ring_rx; q++) {
2375 wr32(hw, QINT_RQCTL(vsi->rxq_map[rxq]), 0);
2384 * ice_vsi_free_irq - Free the IRQ association with the OS
2385 * @vsi: the VSI being configured
2387 void ice_vsi_free_irq(struct ice_vsi *vsi)
2389 struct ice_pf *pf = vsi->back;
2390 int base = vsi->base_vector;
2393 if (!vsi->q_vectors || !vsi->irqs_ready)
2396 ice_vsi_release_msix(vsi);
2397 if (vsi->type == ICE_VSI_VF)
2400 vsi->irqs_ready = false;
2401 ice_for_each_q_vector(vsi, i) {
2402 u16 vector = i + base;
2405 irq_num = pf->msix_entries[vector].vector;
2407 /* free only the irqs that were actually requested */
2408 if (!vsi->q_vectors[i] ||
2409 !(vsi->q_vectors[i]->num_ring_tx ||
2410 vsi->q_vectors[i]->num_ring_rx))
2413 /* clear the affinity notifier in the IRQ descriptor */
2414 irq_set_affinity_notifier(irq_num, NULL);
2416 /* clear the affinity_mask in the IRQ descriptor */
2417 irq_set_affinity_hint(irq_num, NULL);
2418 synchronize_irq(irq_num);
2419 devm_free_irq(ice_pf_to_dev(pf), irq_num, vsi->q_vectors[i]);
2424 * ice_vsi_free_tx_rings - Free Tx resources for VSI queues
2425 * @vsi: the VSI having resources freed
2427 void ice_vsi_free_tx_rings(struct ice_vsi *vsi)
2434 ice_for_each_txq(vsi, i)
2435 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
2436 ice_free_tx_ring(vsi->tx_rings[i]);
2440 * ice_vsi_free_rx_rings - Free Rx resources for VSI queues
2441 * @vsi: the VSI having resources freed
2443 void ice_vsi_free_rx_rings(struct ice_vsi *vsi)
2450 ice_for_each_rxq(vsi, i)
2451 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
2452 ice_free_rx_ring(vsi->rx_rings[i]);
2456 * ice_vsi_close - Shut down a VSI
2457 * @vsi: the VSI being shut down
2459 void ice_vsi_close(struct ice_vsi *vsi)
2461 if (!test_and_set_bit(__ICE_DOWN, vsi->state))
2464 ice_vsi_free_irq(vsi);
2465 ice_vsi_free_tx_rings(vsi);
2466 ice_vsi_free_rx_rings(vsi);
2470 * ice_ena_vsi - resume a VSI
2471 * @vsi: the VSI being resume
2472 * @locked: is the rtnl_lock already held
2474 int ice_ena_vsi(struct ice_vsi *vsi, bool locked)
2478 if (!test_bit(__ICE_NEEDS_RESTART, vsi->state))
2481 clear_bit(__ICE_NEEDS_RESTART, vsi->state);
2483 if (vsi->netdev && vsi->type == ICE_VSI_PF) {
2484 if (netif_running(vsi->netdev)) {
2488 err = ice_open(vsi->netdev);
2493 } else if (vsi->type == ICE_VSI_CTRL) {
2494 err = ice_vsi_open_ctrl(vsi);
2501 * ice_dis_vsi - pause a VSI
2502 * @vsi: the VSI being paused
2503 * @locked: is the rtnl_lock already held
2505 void ice_dis_vsi(struct ice_vsi *vsi, bool locked)
2507 if (test_bit(__ICE_DOWN, vsi->state))
2510 set_bit(__ICE_NEEDS_RESTART, vsi->state);
2512 if (vsi->type == ICE_VSI_PF && vsi->netdev) {
2513 if (netif_running(vsi->netdev)) {
2517 ice_stop(vsi->netdev);
2524 } else if (vsi->type == ICE_VSI_CTRL) {
2530 * ice_vsi_dis_irq - Mask off queue interrupt generation on the VSI
2531 * @vsi: the VSI being un-configured
2533 void ice_vsi_dis_irq(struct ice_vsi *vsi)
2535 int base = vsi->base_vector;
2536 struct ice_pf *pf = vsi->back;
2537 struct ice_hw *hw = &pf->hw;
2541 /* disable interrupt causation from each queue */
2542 if (vsi->tx_rings) {
2543 ice_for_each_txq(vsi, i) {
2544 if (vsi->tx_rings[i]) {
2547 reg = vsi->tx_rings[i]->reg_idx;
2548 val = rd32(hw, QINT_TQCTL(reg));
2549 val &= ~QINT_TQCTL_CAUSE_ENA_M;
2550 wr32(hw, QINT_TQCTL(reg), val);
2555 if (vsi->rx_rings) {
2556 ice_for_each_rxq(vsi, i) {
2557 if (vsi->rx_rings[i]) {
2560 reg = vsi->rx_rings[i]->reg_idx;
2561 val = rd32(hw, QINT_RQCTL(reg));
2562 val &= ~QINT_RQCTL_CAUSE_ENA_M;
2563 wr32(hw, QINT_RQCTL(reg), val);
2568 /* disable each interrupt */
2569 ice_for_each_q_vector(vsi, i) {
2570 if (!vsi->q_vectors[i])
2572 wr32(hw, GLINT_DYN_CTL(vsi->q_vectors[i]->reg_idx), 0);
2577 /* don't call synchronize_irq() for VF's from the host */
2578 if (vsi->type == ICE_VSI_VF)
2581 ice_for_each_q_vector(vsi, i)
2582 synchronize_irq(pf->msix_entries[i + base].vector);
2586 * ice_napi_del - Remove NAPI handler for the VSI
2587 * @vsi: VSI for which NAPI handler is to be removed
2589 void ice_napi_del(struct ice_vsi *vsi)
2596 ice_for_each_q_vector(vsi, v_idx)
2597 netif_napi_del(&vsi->q_vectors[v_idx]->napi);
2601 * ice_vsi_release - Delete a VSI and free its resources
2602 * @vsi: the VSI being removed
2604 * Returns 0 on success or < 0 on error
2606 int ice_vsi_release(struct ice_vsi *vsi)
2614 /* do not unregister while driver is in the reset recovery pending
2615 * state. Since reset/rebuild happens through PF service task workqueue,
2616 * it's not a good idea to unregister netdev that is associated to the
2617 * PF that is running the work queue items currently. This is done to
2618 * avoid check_flush_dependency() warning on this wq
2620 if (vsi->netdev && !ice_is_reset_in_progress(pf->state)) {
2621 unregister_netdev(vsi->netdev);
2622 ice_devlink_destroy_port(vsi);
2625 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2628 /* Disable VSI and free resources */
2629 if (vsi->type != ICE_VSI_LB)
2630 ice_vsi_dis_irq(vsi);
2633 /* SR-IOV determines needed MSIX resources all at once instead of per
2634 * VSI since when VFs are spawned we know how many VFs there are and how
2635 * many interrupts each VF needs. SR-IOV MSIX resources are also
2636 * cleared in the same manner.
2638 if (vsi->type != ICE_VSI_VF) {
2639 /* reclaim SW interrupts back to the common pool */
2640 ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
2641 pf->num_avail_sw_msix += vsi->num_q_vectors;
2644 if (!ice_is_safe_mode(pf)) {
2645 if (vsi->type == ICE_VSI_PF) {
2646 ice_fltr_remove_eth(vsi, ETH_P_PAUSE, ICE_FLTR_TX,
2648 ice_cfg_sw_lldp(vsi, true, false);
2649 /* The Rx rule will only exist to remove if the LLDP FW
2650 * engine is currently stopped
2652 if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags))
2653 ice_cfg_sw_lldp(vsi, false, false);
2657 ice_fltr_remove_all(vsi);
2658 ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx);
2659 ice_vsi_delete(vsi);
2660 ice_vsi_free_q_vectors(vsi);
2662 /* make sure unregister_netdev() was called by checking __ICE_DOWN */
2663 if (vsi->netdev && test_bit(__ICE_DOWN, vsi->state)) {
2664 free_netdev(vsi->netdev);
2668 ice_vsi_clear_rings(vsi);
2670 ice_vsi_put_qs(vsi);
2672 /* retain SW VSI data structure since it is needed to unregister and
2673 * free VSI netdev when PF is not in reset recovery pending state,\
2674 * for ex: during rmmod.
2676 if (!ice_is_reset_in_progress(pf->state))
2683 * ice_vsi_rebuild_update_coalesce - set coalesce for a q_vector
2684 * @q_vector: pointer to q_vector which is being updated
2685 * @coalesce: pointer to array of struct with stored coalesce
2687 * Set coalesce param in q_vector and update these parameters in HW.
2690 ice_vsi_rebuild_update_coalesce(struct ice_q_vector *q_vector,
2691 struct ice_coalesce_stored *coalesce)
2693 struct ice_ring_container *rx_rc = &q_vector->rx;
2694 struct ice_ring_container *tx_rc = &q_vector->tx;
2695 struct ice_hw *hw = &q_vector->vsi->back->hw;
2697 tx_rc->itr_setting = coalesce->itr_tx;
2698 rx_rc->itr_setting = coalesce->itr_rx;
2700 /* dynamic ITR values will be updated during Tx/Rx */
2701 if (!ITR_IS_DYNAMIC(tx_rc->itr_setting))
2702 wr32(hw, GLINT_ITR(tx_rc->itr_idx, q_vector->reg_idx),
2703 ITR_REG_ALIGN(tx_rc->itr_setting) >>
2705 if (!ITR_IS_DYNAMIC(rx_rc->itr_setting))
2706 wr32(hw, GLINT_ITR(rx_rc->itr_idx, q_vector->reg_idx),
2707 ITR_REG_ALIGN(rx_rc->itr_setting) >>
2710 q_vector->intrl = coalesce->intrl;
2711 wr32(hw, GLINT_RATE(q_vector->reg_idx),
2712 ice_intrl_usec_to_reg(q_vector->intrl, hw->intrl_gran));
2716 * ice_vsi_rebuild_get_coalesce - get coalesce from all q_vectors
2717 * @vsi: VSI connected with q_vectors
2718 * @coalesce: array of struct with stored coalesce
2720 * Returns array size.
2723 ice_vsi_rebuild_get_coalesce(struct ice_vsi *vsi,
2724 struct ice_coalesce_stored *coalesce)
2728 ice_for_each_q_vector(vsi, i) {
2729 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2731 coalesce[i].itr_tx = q_vector->tx.itr_setting;
2732 coalesce[i].itr_rx = q_vector->rx.itr_setting;
2733 coalesce[i].intrl = q_vector->intrl;
2736 return vsi->num_q_vectors;
2740 * ice_vsi_rebuild_set_coalesce - set coalesce from earlier saved arrays
2741 * @vsi: VSI connected with q_vectors
2742 * @coalesce: pointer to array of struct with stored coalesce
2743 * @size: size of coalesce array
2745 * Before this function, ice_vsi_rebuild_get_coalesce should be called to save
2746 * ITR params in arrays. If size is 0 or coalesce wasn't stored set coalesce
2750 ice_vsi_rebuild_set_coalesce(struct ice_vsi *vsi,
2751 struct ice_coalesce_stored *coalesce, int size)
2755 if ((size && !coalesce) || !vsi)
2758 for (i = 0; i < size && i < vsi->num_q_vectors; i++)
2759 ice_vsi_rebuild_update_coalesce(vsi->q_vectors[i],
2762 /* number of q_vectors increased, so assume coalesce settings were
2763 * changed globally (i.e. ethtool -C eth0 instead of per-queue) and use
2764 * the previous settings from q_vector 0 for all of the new q_vectors
2766 for (; i < vsi->num_q_vectors; i++)
2767 ice_vsi_rebuild_update_coalesce(vsi->q_vectors[i],
2772 * ice_vsi_rebuild - Rebuild VSI after reset
2773 * @vsi: VSI to be rebuild
2774 * @init_vsi: is this an initialization or a reconfigure of the VSI
2776 * Returns 0 on success and negative value on failure
2778 int ice_vsi_rebuild(struct ice_vsi *vsi, bool init_vsi)
2780 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2781 struct ice_coalesce_stored *coalesce;
2782 int prev_num_q_vectors = 0;
2783 struct ice_vf *vf = NULL;
2784 enum ice_status status;
2792 if (vsi->type == ICE_VSI_VF)
2793 vf = &pf->vf[vsi->vf_id];
2795 coalesce = kcalloc(vsi->num_q_vectors,
2796 sizeof(struct ice_coalesce_stored), GFP_KERNEL);
2798 prev_num_q_vectors = ice_vsi_rebuild_get_coalesce(vsi,
2800 ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx);
2801 ice_vsi_free_q_vectors(vsi);
2803 /* SR-IOV determines needed MSIX resources all at once instead of per
2804 * VSI since when VFs are spawned we know how many VFs there are and how
2805 * many interrupts each VF needs. SR-IOV MSIX resources are also
2806 * cleared in the same manner.
2808 if (vsi->type != ICE_VSI_VF) {
2809 /* reclaim SW interrupts back to the common pool */
2810 ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
2811 pf->num_avail_sw_msix += vsi->num_q_vectors;
2812 vsi->base_vector = 0;
2815 if (ice_is_xdp_ena_vsi(vsi))
2816 /* return value check can be skipped here, it always returns
2817 * 0 if reset is in progress
2819 ice_destroy_xdp_rings(vsi);
2820 ice_vsi_put_qs(vsi);
2821 ice_vsi_clear_rings(vsi);
2822 ice_vsi_free_arrays(vsi);
2823 if (vsi->type == ICE_VSI_VF)
2824 ice_vsi_set_num_qs(vsi, vf->vf_id);
2826 ice_vsi_set_num_qs(vsi, ICE_INVAL_VFID);
2828 ret = ice_vsi_alloc_arrays(vsi);
2832 ice_vsi_get_qs(vsi);
2834 ice_alloc_fd_res(vsi);
2835 ice_vsi_set_tc_cfg(vsi);
2837 /* Initialize VSI struct elements and create VSI in FW */
2838 ret = ice_vsi_init(vsi, init_vsi);
2842 switch (vsi->type) {
2845 ret = ice_vsi_alloc_q_vectors(vsi);
2849 ret = ice_vsi_setup_vector_base(vsi);
2853 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2857 ret = ice_vsi_alloc_rings(vsi);
2861 ice_vsi_map_rings_to_vectors(vsi);
2862 if (ice_is_xdp_ena_vsi(vsi)) {
2863 vsi->num_xdp_txq = vsi->alloc_rxq;
2864 ret = ice_prepare_xdp_rings(vsi, vsi->xdp_prog);
2868 /* ICE_VSI_CTRL does not need RSS so skip RSS processing */
2869 if (vsi->type != ICE_VSI_CTRL)
2870 /* Do not exit if configuring RSS had an issue, at
2871 * least receive traffic on first queue. Hence no
2872 * need to capture return value
2874 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2875 ice_vsi_cfg_rss_lut_key(vsi);
2878 ret = ice_vsi_alloc_q_vectors(vsi);
2882 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2886 ret = ice_vsi_alloc_rings(vsi);
2895 /* configure VSI nodes based on number of queues and TC's */
2896 for (i = 0; i < vsi->tc_cfg.numtc; i++) {
2897 max_txqs[i] = vsi->alloc_txq;
2899 if (ice_is_xdp_ena_vsi(vsi))
2900 max_txqs[i] += vsi->num_xdp_txq;
2903 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2906 dev_err(ice_pf_to_dev(pf), "VSI %d failed lan queue config, error %s\n",
2907 vsi->vsi_num, ice_stat_str(status));
2912 return ice_schedule_reset(pf, ICE_RESET_PFR);
2915 ice_vsi_rebuild_set_coalesce(vsi, coalesce, prev_num_q_vectors);
2921 ice_vsi_free_q_vectors(vsi);
2924 vsi->current_netdev_flags = 0;
2925 unregister_netdev(vsi->netdev);
2926 free_netdev(vsi->netdev);
2931 set_bit(__ICE_RESET_FAILED, pf->state);
2937 * ice_is_reset_in_progress - check for a reset in progress
2938 * @state: PF state field
2940 bool ice_is_reset_in_progress(unsigned long *state)
2942 return test_bit(__ICE_RESET_OICR_RECV, state) ||
2943 test_bit(__ICE_DCBNL_DEVRESET, state) ||
2944 test_bit(__ICE_PFR_REQ, state) ||
2945 test_bit(__ICE_CORER_REQ, state) ||
2946 test_bit(__ICE_GLOBR_REQ, state);
2951 * ice_vsi_update_q_map - update our copy of the VSI info with new queue map
2952 * @vsi: VSI being configured
2953 * @ctx: the context buffer returned from AQ VSI update command
2955 static void ice_vsi_update_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctx)
2957 vsi->info.mapping_flags = ctx->info.mapping_flags;
2958 memcpy(&vsi->info.q_mapping, &ctx->info.q_mapping,
2959 sizeof(vsi->info.q_mapping));
2960 memcpy(&vsi->info.tc_mapping, ctx->info.tc_mapping,
2961 sizeof(vsi->info.tc_mapping));
2965 * ice_vsi_cfg_tc - Configure VSI Tx Sched for given TC map
2966 * @vsi: VSI to be configured
2967 * @ena_tc: TC bitmap
2969 * VSI queues expected to be quiesced before calling this function
2971 int ice_vsi_cfg_tc(struct ice_vsi *vsi, u8 ena_tc)
2973 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2974 struct ice_pf *pf = vsi->back;
2975 struct ice_vsi_ctx *ctx;
2976 enum ice_status status;
2981 dev = ice_pf_to_dev(pf);
2983 ice_for_each_traffic_class(i) {
2984 /* build bitmap of enabled TCs */
2985 if (ena_tc & BIT(i))
2987 /* populate max_txqs per TC */
2988 max_txqs[i] = vsi->alloc_txq;
2991 vsi->tc_cfg.ena_tc = ena_tc;
2992 vsi->tc_cfg.numtc = num_tc;
2994 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
2999 ctx->info = vsi->info;
3001 ice_vsi_setup_q_map(vsi, ctx);
3003 /* must to indicate which section of VSI context are being modified */
3004 ctx->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
3005 status = ice_update_vsi(&pf->hw, vsi->idx, ctx, NULL);
3007 dev_info(dev, "Failed VSI Update\n");
3012 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
3016 dev_err(dev, "VSI %d failed TC config, error %s\n",
3017 vsi->vsi_num, ice_stat_str(status));
3021 ice_vsi_update_q_map(vsi, ctx);
3022 vsi->info.valid_sections = 0;
3024 ice_vsi_cfg_netdev_tc(vsi, ena_tc);
3029 #endif /* CONFIG_DCB */
3032 * ice_update_ring_stats - Update ring statistics
3033 * @ring: ring to update
3034 * @cont: used to increment per-vector counters
3035 * @pkts: number of processed packets
3036 * @bytes: number of processed bytes
3038 * This function assumes that caller has acquired a u64_stats_sync lock.
3041 ice_update_ring_stats(struct ice_ring *ring, struct ice_ring_container *cont,
3042 u64 pkts, u64 bytes)
3044 ring->stats.bytes += bytes;
3045 ring->stats.pkts += pkts;
3046 cont->total_bytes += bytes;
3047 cont->total_pkts += pkts;
3051 * ice_update_tx_ring_stats - Update Tx ring specific counters
3052 * @tx_ring: ring to update
3053 * @pkts: number of processed packets
3054 * @bytes: number of processed bytes
3056 void ice_update_tx_ring_stats(struct ice_ring *tx_ring, u64 pkts, u64 bytes)
3058 u64_stats_update_begin(&tx_ring->syncp);
3059 ice_update_ring_stats(tx_ring, &tx_ring->q_vector->tx, pkts, bytes);
3060 u64_stats_update_end(&tx_ring->syncp);
3064 * ice_update_rx_ring_stats - Update Rx ring specific counters
3065 * @rx_ring: ring to update
3066 * @pkts: number of processed packets
3067 * @bytes: number of processed bytes
3069 void ice_update_rx_ring_stats(struct ice_ring *rx_ring, u64 pkts, u64 bytes)
3071 u64_stats_update_begin(&rx_ring->syncp);
3072 ice_update_ring_stats(rx_ring, &rx_ring->q_vector->rx, pkts, bytes);
3073 u64_stats_update_end(&rx_ring->syncp);
3077 * ice_status_to_errno - convert from enum ice_status to Linux errno
3078 * @err: ice_status value to convert
3080 int ice_status_to_errno(enum ice_status err)
3085 case ICE_ERR_DOES_NOT_EXIST:
3087 case ICE_ERR_OUT_OF_RANGE:
3091 case ICE_ERR_NO_MEMORY:
3093 case ICE_ERR_MAX_LIMIT:
3101 * ice_is_dflt_vsi_in_use - check if the default forwarding VSI is being used
3102 * @sw: switch to check if its default forwarding VSI is free
3104 * Return true if the default forwarding VSI is already being used, else returns
3105 * false signalling that it's available to use.
3107 bool ice_is_dflt_vsi_in_use(struct ice_sw *sw)
3109 return (sw->dflt_vsi && sw->dflt_vsi_ena);
3113 * ice_is_vsi_dflt_vsi - check if the VSI passed in is the default VSI
3114 * @sw: switch for the default forwarding VSI to compare against
3115 * @vsi: VSI to compare against default forwarding VSI
3117 * If this VSI passed in is the default forwarding VSI then return true, else
3120 bool ice_is_vsi_dflt_vsi(struct ice_sw *sw, struct ice_vsi *vsi)
3122 return (sw->dflt_vsi == vsi && sw->dflt_vsi_ena);
3126 * ice_set_dflt_vsi - set the default forwarding VSI
3127 * @sw: switch used to assign the default forwarding VSI
3128 * @vsi: VSI getting set as the default forwarding VSI on the switch
3130 * If the VSI passed in is already the default VSI and it's enabled just return
3133 * If there is already a default VSI on the switch and it's enabled then return
3134 * -EEXIST since there can only be one default VSI per switch.
3136 * Otherwise try to set the VSI passed in as the switch's default VSI and
3137 * return the result.
3139 int ice_set_dflt_vsi(struct ice_sw *sw, struct ice_vsi *vsi)
3141 enum ice_status status;
3147 dev = ice_pf_to_dev(vsi->back);
3149 /* the VSI passed in is already the default VSI */
3150 if (ice_is_vsi_dflt_vsi(sw, vsi)) {
3151 dev_dbg(dev, "VSI %d passed in is already the default forwarding VSI, nothing to do\n",
3156 /* another VSI is already the default VSI for this switch */
3157 if (ice_is_dflt_vsi_in_use(sw)) {
3158 dev_err(dev, "Default forwarding VSI %d already in use, disable it and try again\n",
3159 sw->dflt_vsi->vsi_num);
3163 status = ice_cfg_dflt_vsi(&vsi->back->hw, vsi->idx, true, ICE_FLTR_RX);
3165 dev_err(dev, "Failed to set VSI %d as the default forwarding VSI, error %s\n",
3166 vsi->vsi_num, ice_stat_str(status));
3171 sw->dflt_vsi_ena = true;
3177 * ice_clear_dflt_vsi - clear the default forwarding VSI
3178 * @sw: switch used to clear the default VSI
3180 * If the switch has no default VSI or it's not enabled then return error.
3182 * Otherwise try to clear the default VSI and return the result.
3184 int ice_clear_dflt_vsi(struct ice_sw *sw)
3186 struct ice_vsi *dflt_vsi;
3187 enum ice_status status;
3193 dev = ice_pf_to_dev(sw->pf);
3195 dflt_vsi = sw->dflt_vsi;
3197 /* there is no default VSI configured */
3198 if (!ice_is_dflt_vsi_in_use(sw))
3201 status = ice_cfg_dflt_vsi(&dflt_vsi->back->hw, dflt_vsi->idx, false,
3204 dev_err(dev, "Failed to clear the default forwarding VSI %d, error %s\n",
3205 dflt_vsi->vsi_num, ice_stat_str(status));
3209 sw->dflt_vsi = NULL;
3210 sw->dflt_vsi_ena = false;