1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
8 * ice_setup_rx_ctx - Configure a receive ring context
9 * @ring: The Rx ring to configure
11 * Configure the Rx descriptor ring in RLAN context.
13 static int ice_setup_rx_ctx(struct ice_ring *ring)
15 struct ice_vsi *vsi = ring->vsi;
16 struct ice_hw *hw = &vsi->back->hw;
17 u32 rxdid = ICE_RXDID_FLEX_NIC;
18 struct ice_rlan_ctx rlan_ctx;
23 /* what is RX queue number in global space of 2K Rx queues */
24 pf_q = vsi->rxq_map[ring->q_index];
26 /* clear the context structure first */
27 memset(&rlan_ctx, 0, sizeof(rlan_ctx));
29 rlan_ctx.base = ring->dma >> 7;
31 rlan_ctx.qlen = ring->count;
33 /* Receive Packet Data Buffer Size.
34 * The Packet Data Buffer Size is defined in 128 byte units.
36 rlan_ctx.dbuf = vsi->rx_buf_len >> ICE_RLAN_CTX_DBUF_S;
38 /* use 32 byte descriptors */
41 /* Strip the Ethernet CRC bytes before the packet is posted to host
44 rlan_ctx.crcstrip = 1;
46 /* L2TSEL flag defines the reported L2 Tags in the receive descriptor */
49 rlan_ctx.dtype = ICE_RX_DTYPE_NO_SPLIT;
50 rlan_ctx.hsplit_0 = ICE_RLAN_RX_HSPLIT_0_NO_SPLIT;
51 rlan_ctx.hsplit_1 = ICE_RLAN_RX_HSPLIT_1_NO_SPLIT;
53 /* This controls whether VLAN is stripped from inner headers
54 * The VLAN in the inner L2 header is stripped to the receive
55 * descriptor if enabled by this flag.
59 /* Max packet size for this queue - must not be set to a larger value
62 rlan_ctx.rxmax = min_t(u16, vsi->max_frame,
63 ICE_MAX_CHAINED_RX_BUFS * vsi->rx_buf_len);
65 /* Rx queue threshold in units of 64 */
66 rlan_ctx.lrxqthresh = 1;
68 /* Enable Flexible Descriptors in the queue context which
69 * allows this driver to select a specific receive descriptor format
71 regval = rd32(hw, QRXFLXP_CNTXT(pf_q));
72 regval |= (rxdid << QRXFLXP_CNTXT_RXDID_IDX_S) &
73 QRXFLXP_CNTXT_RXDID_IDX_M;
75 /* increasing context priority to pick up profile id;
76 * default is 0x01; setting to 0x03 to ensure profile
77 * is programming if prev context is of same priority
79 regval |= (0x03 << QRXFLXP_CNTXT_RXDID_PRIO_S) &
80 QRXFLXP_CNTXT_RXDID_PRIO_M;
82 wr32(hw, QRXFLXP_CNTXT(pf_q), regval);
84 /* Absolute queue number out of 2K needs to be passed */
85 err = ice_write_rxq_ctx(hw, &rlan_ctx, pf_q);
87 dev_err(&vsi->back->pdev->dev,
88 "Failed to set LAN Rx queue context for absolute Rx queue %d error: %d\n",
93 /* init queue specific tail register */
94 ring->tail = hw->hw_addr + QRX_TAIL(pf_q);
95 writel(0, ring->tail);
96 ice_alloc_rx_bufs(ring, ICE_DESC_UNUSED(ring));
102 * ice_setup_tx_ctx - setup a struct ice_tlan_ctx instance
103 * @ring: The Tx ring to configure
104 * @tlan_ctx: Pointer to the Tx LAN queue context structure to be initialized
105 * @pf_q: queue index in the PF space
107 * Configure the Tx descriptor ring in TLAN context.
110 ice_setup_tx_ctx(struct ice_ring *ring, struct ice_tlan_ctx *tlan_ctx, u16 pf_q)
112 struct ice_vsi *vsi = ring->vsi;
113 struct ice_hw *hw = &vsi->back->hw;
115 tlan_ctx->base = ring->dma >> ICE_TLAN_CTX_BASE_S;
117 tlan_ctx->port_num = vsi->port_info->lport;
119 /* Transmit Queue Length */
120 tlan_ctx->qlen = ring->count;
123 tlan_ctx->pf_num = hw->pf_id;
125 /* queue belongs to a specific VSI type
126 * VF / VM index should be programmed per vmvf_type setting:
127 * for vmvf_type = VF, it is VF number between 0-256
128 * for vmvf_type = VM, it is VM number between 0-767
129 * for PF or EMP this field should be set to zero
133 tlan_ctx->vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_PF;
139 /* make sure the context is associated with the right VSI */
140 tlan_ctx->src_vsi = vsi->vsi_num;
142 tlan_ctx->tso_ena = ICE_TX_LEGACY;
143 tlan_ctx->tso_qnum = pf_q;
145 /* Legacy or Advanced Host Interface:
146 * 0: Advanced Host Interface
147 * 1: Legacy Host Interface
149 tlan_ctx->legacy_int = ICE_TX_LEGACY;
153 * ice_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
154 * @pf: the PF being configured
155 * @pf_q: the PF queue
156 * @ena: enable or disable state of the queue
158 * This routine will wait for the given Rx queue of the PF to reach the
159 * enabled or disabled state.
160 * Returns -ETIMEDOUT in case of failing to reach the requested state after
161 * multiple retries; else will return 0 in case of success.
163 static int ice_pf_rxq_wait(struct ice_pf *pf, int pf_q, bool ena)
167 for (i = 0; i < ICE_Q_WAIT_RETRY_LIMIT; i++) {
168 u32 rx_reg = rd32(&pf->hw, QRX_CTRL(pf_q));
170 if (ena == !!(rx_reg & QRX_CTRL_QENA_STAT_M))
173 usleep_range(10, 20);
175 if (i >= ICE_Q_WAIT_RETRY_LIMIT)
182 * ice_vsi_ctrl_rx_rings - Start or stop a VSI's Rx rings
183 * @vsi: the VSI being configured
184 * @ena: start or stop the Rx rings
186 static int ice_vsi_ctrl_rx_rings(struct ice_vsi *vsi, bool ena)
188 struct ice_pf *pf = vsi->back;
189 struct ice_hw *hw = &pf->hw;
192 for (i = 0; i < vsi->num_rxq; i++) {
193 int pf_q = vsi->rxq_map[i];
196 for (j = 0; j < ICE_Q_WAIT_MAX_RETRY; j++) {
197 rx_reg = rd32(hw, QRX_CTRL(pf_q));
198 if (((rx_reg >> QRX_CTRL_QENA_REQ_S) & 1) ==
199 ((rx_reg >> QRX_CTRL_QENA_STAT_S) & 1))
201 usleep_range(1000, 2000);
204 /* Skip if the queue is already in the requested state */
205 if (ena == !!(rx_reg & QRX_CTRL_QENA_STAT_M))
208 /* turn on/off the queue */
210 rx_reg |= QRX_CTRL_QENA_REQ_M;
212 rx_reg &= ~QRX_CTRL_QENA_REQ_M;
213 wr32(hw, QRX_CTRL(pf_q), rx_reg);
215 /* wait for the change to finish */
216 ret = ice_pf_rxq_wait(pf, pf_q, ena);
218 dev_err(&pf->pdev->dev,
219 "VSI idx %d Rx ring %d %sable timeout\n",
220 vsi->idx, pf_q, (ena ? "en" : "dis"));
229 * ice_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the VSI
231 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
233 * On error: returns error code (negative)
234 * On success: returns 0
236 static int ice_vsi_alloc_arrays(struct ice_vsi *vsi, bool alloc_qvectors)
238 struct ice_pf *pf = vsi->back;
240 /* allocate memory for both Tx and Rx ring pointers */
241 vsi->tx_rings = devm_kcalloc(&pf->pdev->dev, vsi->alloc_txq,
242 sizeof(struct ice_ring *), GFP_KERNEL);
246 vsi->rx_rings = devm_kcalloc(&pf->pdev->dev, vsi->alloc_rxq,
247 sizeof(struct ice_ring *), GFP_KERNEL);
251 if (alloc_qvectors) {
252 /* allocate memory for q_vector pointers */
253 vsi->q_vectors = devm_kcalloc(&pf->pdev->dev,
255 sizeof(struct ice_q_vector *),
264 devm_kfree(&pf->pdev->dev, vsi->rx_rings);
266 devm_kfree(&pf->pdev->dev, vsi->tx_rings);
272 * ice_vsi_set_num_qs - Set num queues, descriptors and vectors for a VSI
273 * @vsi: the VSI being configured
275 * Return 0 on success and a negative value on error
277 static void ice_vsi_set_num_qs(struct ice_vsi *vsi)
279 struct ice_pf *pf = vsi->back;
283 vsi->alloc_txq = pf->num_lan_tx;
284 vsi->alloc_rxq = pf->num_lan_rx;
285 vsi->num_desc = ALIGN(ICE_DFLT_NUM_DESC, ICE_REQ_DESC_MULTIPLE);
286 vsi->num_q_vectors = max_t(int, pf->num_lan_rx, pf->num_lan_tx);
289 dev_warn(&vsi->back->pdev->dev, "Unknown VSI type %d\n",
296 * ice_get_free_slot - get the next non-NULL location index in array
297 * @array: array to search
298 * @size: size of the array
299 * @curr: last known occupied index to be used as a search hint
301 * void * is being used to keep the functionality generic. This lets us use this
302 * function on any array of pointers.
304 static int ice_get_free_slot(void *array, int size, int curr)
306 int **tmp_array = (int **)array;
309 if (curr < (size - 1) && !tmp_array[curr + 1]) {
314 while ((i < size) && (tmp_array[i]))
325 * ice_vsi_delete - delete a VSI from the switch
326 * @vsi: pointer to VSI being removed
328 void ice_vsi_delete(struct ice_vsi *vsi)
330 struct ice_pf *pf = vsi->back;
331 struct ice_vsi_ctx ctxt;
332 enum ice_status status;
334 ctxt.vsi_num = vsi->vsi_num;
336 memcpy(&ctxt.info, &vsi->info, sizeof(struct ice_aqc_vsi_props));
338 status = ice_free_vsi(&pf->hw, vsi->idx, &ctxt, false, NULL);
340 dev_err(&pf->pdev->dev, "Failed to delete VSI %i in FW\n",
345 * ice_vsi_free_arrays - clean up VSI resources
346 * @vsi: pointer to VSI being cleared
347 * @free_qvectors: bool to specify if q_vectors should be deallocated
349 static void ice_vsi_free_arrays(struct ice_vsi *vsi, bool free_qvectors)
351 struct ice_pf *pf = vsi->back;
353 /* free the ring and vector containers */
354 if (free_qvectors && vsi->q_vectors) {
355 devm_kfree(&pf->pdev->dev, vsi->q_vectors);
356 vsi->q_vectors = NULL;
359 devm_kfree(&pf->pdev->dev, vsi->tx_rings);
360 vsi->tx_rings = NULL;
363 devm_kfree(&pf->pdev->dev, vsi->rx_rings);
364 vsi->rx_rings = NULL;
369 * ice_vsi_clear - clean up and deallocate the provided VSI
370 * @vsi: pointer to VSI being cleared
372 * This deallocates the VSI's queue resources, removes it from the PF's
373 * VSI array if necessary, and deallocates the VSI
375 * Returns 0 on success, negative on failure
377 int ice_vsi_clear(struct ice_vsi *vsi)
379 struct ice_pf *pf = NULL;
389 if (!pf->vsi[vsi->idx] || pf->vsi[vsi->idx] != vsi) {
390 dev_dbg(&pf->pdev->dev, "vsi does not exist at pf->vsi[%d]\n",
395 mutex_lock(&pf->sw_mutex);
396 /* updates the PF for this cleared VSI */
398 pf->vsi[vsi->idx] = NULL;
399 if (vsi->idx < pf->next_vsi)
400 pf->next_vsi = vsi->idx;
402 ice_vsi_free_arrays(vsi, true);
403 mutex_unlock(&pf->sw_mutex);
404 devm_kfree(&pf->pdev->dev, vsi);
410 * ice_msix_clean_rings - MSIX mode Interrupt Handler
411 * @irq: interrupt number
412 * @data: pointer to a q_vector
414 irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data)
416 struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
418 if (!q_vector->tx.ring && !q_vector->rx.ring)
421 napi_schedule(&q_vector->napi);
427 * ice_vsi_alloc - Allocates the next available struct VSI in the PF
428 * @pf: board private structure
431 * returns a pointer to a VSI on success, NULL on failure.
433 static struct ice_vsi *ice_vsi_alloc(struct ice_pf *pf, enum ice_vsi_type type)
435 struct ice_vsi *vsi = NULL;
437 /* Need to protect the allocation of the VSIs at the PF level */
438 mutex_lock(&pf->sw_mutex);
440 /* If we have already allocated our maximum number of VSIs,
441 * pf->next_vsi will be ICE_NO_VSI. If not, pf->next_vsi index
442 * is available to be populated
444 if (pf->next_vsi == ICE_NO_VSI) {
445 dev_dbg(&pf->pdev->dev, "out of VSI slots!\n");
449 vsi = devm_kzalloc(&pf->pdev->dev, sizeof(*vsi), GFP_KERNEL);
455 set_bit(__ICE_DOWN, vsi->state);
456 vsi->idx = pf->next_vsi;
457 vsi->work_lmt = ICE_DFLT_IRQ_WORK;
459 ice_vsi_set_num_qs(vsi);
463 if (ice_vsi_alloc_arrays(vsi, true))
466 /* Setup default MSIX irq handler for VSI */
467 vsi->irq_handler = ice_msix_clean_rings;
470 dev_warn(&pf->pdev->dev, "Unknown VSI type %d\n", vsi->type);
474 /* fill VSI slot in the PF struct */
475 pf->vsi[pf->next_vsi] = vsi;
477 /* prepare pf->next_vsi for next use */
478 pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi,
483 devm_kfree(&pf->pdev->dev, vsi);
486 mutex_unlock(&pf->sw_mutex);
491 * ice_vsi_get_qs_contig - Assign a contiguous chunk of queues to VSI
492 * @vsi: the VSI getting queues
494 * Return 0 on success and a negative value on error
496 static int ice_vsi_get_qs_contig(struct ice_vsi *vsi)
498 struct ice_pf *pf = vsi->back;
501 mutex_lock(&pf->avail_q_mutex);
502 /* look for contiguous block of queues for Tx */
503 offset = bitmap_find_next_zero_area(pf->avail_txqs, ICE_MAX_TXQS,
504 0, vsi->alloc_txq, 0);
505 if (offset < ICE_MAX_TXQS) {
508 bitmap_set(pf->avail_txqs, offset, vsi->alloc_txq);
509 for (i = 0; i < vsi->alloc_txq; i++)
510 vsi->txq_map[i] = i + offset;
513 vsi->tx_mapping_mode = ICE_VSI_MAP_SCATTER;
516 /* look for contiguous block of queues for Rx */
517 offset = bitmap_find_next_zero_area(pf->avail_rxqs, ICE_MAX_RXQS,
518 0, vsi->alloc_rxq, 0);
519 if (offset < ICE_MAX_RXQS) {
522 bitmap_set(pf->avail_rxqs, offset, vsi->alloc_rxq);
523 for (i = 0; i < vsi->alloc_rxq; i++)
524 vsi->rxq_map[i] = i + offset;
527 vsi->rx_mapping_mode = ICE_VSI_MAP_SCATTER;
529 mutex_unlock(&pf->avail_q_mutex);
535 * ice_vsi_get_qs_scatter - Assign a scattered queues to VSI
536 * @vsi: the VSI getting queues
538 * Return 0 on success and a negative value on error
540 static int ice_vsi_get_qs_scatter(struct ice_vsi *vsi)
542 struct ice_pf *pf = vsi->back;
545 mutex_lock(&pf->avail_q_mutex);
547 if (vsi->tx_mapping_mode == ICE_VSI_MAP_SCATTER) {
548 for (i = 0; i < vsi->alloc_txq; i++) {
549 index = find_next_zero_bit(pf->avail_txqs,
550 ICE_MAX_TXQS, index);
551 if (index < ICE_MAX_TXQS) {
552 set_bit(index, pf->avail_txqs);
553 vsi->txq_map[i] = index;
560 if (vsi->rx_mapping_mode == ICE_VSI_MAP_SCATTER) {
561 for (i = 0; i < vsi->alloc_rxq; i++) {
562 index = find_next_zero_bit(pf->avail_rxqs,
563 ICE_MAX_RXQS, index);
564 if (index < ICE_MAX_RXQS) {
565 set_bit(index, pf->avail_rxqs);
566 vsi->rxq_map[i] = index;
573 mutex_unlock(&pf->avail_q_mutex);
577 /* unflag any queues we have grabbed (i is failed position) */
578 for (index = 0; index < i; index++) {
579 clear_bit(vsi->rxq_map[index], pf->avail_rxqs);
580 vsi->rxq_map[index] = 0;
584 /* i is either position of failed attempt or vsi->alloc_txq */
585 for (index = 0; index < i; index++) {
586 clear_bit(vsi->txq_map[index], pf->avail_txqs);
587 vsi->txq_map[index] = 0;
590 mutex_unlock(&pf->avail_q_mutex);
595 * ice_vsi_get_qs - Assign queues from PF to VSI
596 * @vsi: the VSI to assign queues to
598 * Returns 0 on success and a negative value on error
600 static int ice_vsi_get_qs(struct ice_vsi *vsi)
604 vsi->tx_mapping_mode = ICE_VSI_MAP_CONTIG;
605 vsi->rx_mapping_mode = ICE_VSI_MAP_CONTIG;
607 /* NOTE: ice_vsi_get_qs_contig() will set the Rx/Tx mapping
608 * modes individually to scatter if assigning contiguous queues
611 ret = ice_vsi_get_qs_contig(vsi);
613 if (vsi->tx_mapping_mode == ICE_VSI_MAP_SCATTER)
614 vsi->alloc_txq = max_t(u16, vsi->alloc_txq,
615 ICE_MAX_SCATTER_TXQS);
616 if (vsi->rx_mapping_mode == ICE_VSI_MAP_SCATTER)
617 vsi->alloc_rxq = max_t(u16, vsi->alloc_rxq,
618 ICE_MAX_SCATTER_RXQS);
619 ret = ice_vsi_get_qs_scatter(vsi);
626 * ice_vsi_put_qs - Release queues from VSI to PF
627 * @vsi: the VSI that is going to release queues
629 void ice_vsi_put_qs(struct ice_vsi *vsi)
631 struct ice_pf *pf = vsi->back;
634 mutex_lock(&pf->avail_q_mutex);
636 for (i = 0; i < vsi->alloc_txq; i++) {
637 clear_bit(vsi->txq_map[i], pf->avail_txqs);
638 vsi->txq_map[i] = ICE_INVAL_Q_INDEX;
641 for (i = 0; i < vsi->alloc_rxq; i++) {
642 clear_bit(vsi->rxq_map[i], pf->avail_rxqs);
643 vsi->rxq_map[i] = ICE_INVAL_Q_INDEX;
646 mutex_unlock(&pf->avail_q_mutex);
650 * ice_rss_clean - Delete RSS related VSI structures that hold user inputs
651 * @vsi: the VSI being removed
653 static void ice_rss_clean(struct ice_vsi *vsi)
659 if (vsi->rss_hkey_user)
660 devm_kfree(&pf->pdev->dev, vsi->rss_hkey_user);
661 if (vsi->rss_lut_user)
662 devm_kfree(&pf->pdev->dev, vsi->rss_lut_user);
666 * ice_vsi_set_rss_params - Setup RSS capabilities per VSI type
667 * @vsi: the VSI being configured
669 static void ice_vsi_set_rss_params(struct ice_vsi *vsi)
671 struct ice_hw_common_caps *cap;
672 struct ice_pf *pf = vsi->back;
674 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
679 cap = &pf->hw.func_caps.common_cap;
682 /* PF VSI will inherit RSS instance of PF */
683 vsi->rss_table_size = cap->rss_table_size;
684 vsi->rss_size = min_t(int, num_online_cpus(),
685 BIT(cap->rss_table_entry_width));
686 vsi->rss_lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
689 dev_warn(&pf->pdev->dev, "Unknown VSI type %d\n",
696 * ice_set_dflt_vsi_ctx - Set default VSI context before adding a VSI
697 * @ctxt: the VSI context being set
699 * This initializes a default VSI context for all sections except the Queues.
701 static void ice_set_dflt_vsi_ctx(struct ice_vsi_ctx *ctxt)
705 memset(&ctxt->info, 0, sizeof(ctxt->info));
706 /* VSI's should be allocated from shared pool */
707 ctxt->alloc_from_pool = true;
708 /* Src pruning enabled by default */
709 ctxt->info.sw_flags = ICE_AQ_VSI_SW_FLAG_SRC_PRUNE;
710 /* Traffic from VSI can be sent to LAN */
711 ctxt->info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
712 /* By default bits 3 and 4 in vlan_flags are 0's which results in legacy
713 * behavior (show VLAN, DEI, and UP) in descriptor. Also, allow all
714 * packets untagged/tagged.
716 ctxt->info.vlan_flags = ((ICE_AQ_VSI_VLAN_MODE_ALL &
717 ICE_AQ_VSI_VLAN_MODE_M) >>
718 ICE_AQ_VSI_VLAN_MODE_S);
719 /* Have 1:1 UP mapping for both ingress/egress tables */
720 table |= ICE_UP_TABLE_TRANSLATE(0, 0);
721 table |= ICE_UP_TABLE_TRANSLATE(1, 1);
722 table |= ICE_UP_TABLE_TRANSLATE(2, 2);
723 table |= ICE_UP_TABLE_TRANSLATE(3, 3);
724 table |= ICE_UP_TABLE_TRANSLATE(4, 4);
725 table |= ICE_UP_TABLE_TRANSLATE(5, 5);
726 table |= ICE_UP_TABLE_TRANSLATE(6, 6);
727 table |= ICE_UP_TABLE_TRANSLATE(7, 7);
728 ctxt->info.ingress_table = cpu_to_le32(table);
729 ctxt->info.egress_table = cpu_to_le32(table);
730 /* Have 1:1 UP mapping for outer to inner UP table */
731 ctxt->info.outer_up_table = cpu_to_le32(table);
732 /* No Outer tag support outer_tag_flags remains to zero */
736 * ice_vsi_setup_q_map - Setup a VSI queue map
737 * @vsi: the VSI being configured
738 * @ctxt: VSI context structure
740 static void ice_vsi_setup_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctxt)
742 u16 offset = 0, qmap = 0, numq_tc;
743 u16 pow = 0, max_rss = 0, qcount;
744 u16 qcount_tx = vsi->alloc_txq;
745 u16 qcount_rx = vsi->alloc_rxq;
746 bool ena_tc0 = false;
749 /* at least TC0 should be enabled by default */
750 if (vsi->tc_cfg.numtc) {
751 if (!(vsi->tc_cfg.ena_tc & BIT(0)))
759 vsi->tc_cfg.ena_tc |= 1;
762 numq_tc = qcount_rx / vsi->tc_cfg.numtc;
764 /* TC mapping is a function of the number of Rx queues assigned to the
765 * VSI for each traffic class and the offset of these queues.
766 * The first 10 bits are for queue offset for TC0, next 4 bits for no:of
767 * queues allocated to TC0. No:of queues is a power-of-2.
769 * If TC is not enabled, the queue offset is set to 0, and allocate one
770 * queue, this way, traffic for the given TC will be sent to the default
773 * Setup number and offset of Rx queues for all TCs for the VSI
776 /* qcount will change if RSS is enabled */
777 if (test_bit(ICE_FLAG_RSS_ENA, vsi->back->flags)) {
778 if (vsi->type == ICE_VSI_PF)
779 max_rss = ICE_MAX_LG_RSS_QS;
781 max_rss = ICE_MAX_SMALL_RSS_QS;
783 qcount = min_t(int, numq_tc, max_rss);
784 qcount = min_t(int, qcount, vsi->rss_size);
789 /* find the (rounded up) power-of-2 of qcount */
790 pow = order_base_2(qcount);
792 for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) {
793 if (!(vsi->tc_cfg.ena_tc & BIT(i))) {
794 /* TC is not enabled */
795 vsi->tc_cfg.tc_info[i].qoffset = 0;
796 vsi->tc_cfg.tc_info[i].qcount = 1;
797 ctxt->info.tc_mapping[i] = 0;
802 vsi->tc_cfg.tc_info[i].qoffset = offset;
803 vsi->tc_cfg.tc_info[i].qcount = qcount;
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 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
813 vsi->num_txq = qcount_tx;
814 vsi->num_rxq = offset;
816 /* Rx queue mapping */
817 ctxt->info.mapping_flags |= cpu_to_le16(ICE_AQ_VSI_Q_MAP_CONTIG);
818 /* q_mapping buffer holds the info for the first queue allocated for
819 * this VSI in the PF space and also the number of queues associated
822 ctxt->info.q_mapping[0] = cpu_to_le16(vsi->rxq_map[0]);
823 ctxt->info.q_mapping[1] = cpu_to_le16(vsi->num_rxq);
827 * ice_set_rss_vsi_ctx - Set RSS VSI context before adding a VSI
828 * @ctxt: the VSI context being set
829 * @vsi: the VSI being configured
831 static void ice_set_rss_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
833 u8 lut_type, hash_type;
837 /* PF VSI will inherit RSS instance of PF */
838 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_PF;
839 hash_type = ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
842 dev_warn(&vsi->back->pdev->dev, "Unknown VSI type %d\n",
847 ctxt->info.q_opt_rss = ((lut_type << ICE_AQ_VSI_Q_OPT_RSS_LUT_S) &
848 ICE_AQ_VSI_Q_OPT_RSS_LUT_M) |
849 ((hash_type << ICE_AQ_VSI_Q_OPT_RSS_HASH_S) &
850 ICE_AQ_VSI_Q_OPT_RSS_HASH_M);
854 * ice_vsi_init - Create and initialize a VSI
855 * @vsi: the VSI being configured
857 * This initializes a VSI context depending on the VSI type to be added and
858 * passes it down to the add_vsi aq command to create a new VSI.
860 static int ice_vsi_init(struct ice_vsi *vsi)
862 struct ice_vsi_ctx ctxt = { 0 };
863 struct ice_pf *pf = vsi->back;
864 struct ice_hw *hw = &pf->hw;
869 ctxt.flags = ICE_AQ_VSI_TYPE_PF;
875 ice_set_dflt_vsi_ctx(&ctxt);
876 /* if the switch is in VEB mode, allow VSI loopback */
877 if (vsi->vsw->bridge_mode == BRIDGE_MODE_VEB)
878 ctxt.info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
880 /* Set LUT type and HASH type if RSS is enabled */
881 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
882 ice_set_rss_vsi_ctx(&ctxt, vsi);
884 ctxt.info.sw_id = vsi->port_info->sw_id;
885 ice_vsi_setup_q_map(vsi, &ctxt);
887 ret = ice_add_vsi(hw, vsi->idx, &ctxt, NULL);
889 dev_err(&pf->pdev->dev,
890 "Add VSI failed, err %d\n", ret);
894 /* keep context for update VSI operations */
895 vsi->info = ctxt.info;
897 /* record VSI number returned */
898 vsi->vsi_num = ctxt.vsi_num;
904 * ice_free_q_vector - Free memory allocated for a specific interrupt vector
905 * @vsi: VSI having the memory freed
906 * @v_idx: index of the vector to be freed
908 static void ice_free_q_vector(struct ice_vsi *vsi, int v_idx)
910 struct ice_q_vector *q_vector;
911 struct ice_ring *ring;
913 if (!vsi->q_vectors[v_idx]) {
914 dev_dbg(&vsi->back->pdev->dev, "Queue vector at index %d not found\n",
918 q_vector = vsi->q_vectors[v_idx];
920 ice_for_each_ring(ring, q_vector->tx)
921 ring->q_vector = NULL;
922 ice_for_each_ring(ring, q_vector->rx)
923 ring->q_vector = NULL;
925 /* only VSI with an associated netdev is set up with NAPI */
927 netif_napi_del(&q_vector->napi);
929 devm_kfree(&vsi->back->pdev->dev, q_vector);
930 vsi->q_vectors[v_idx] = NULL;
934 * ice_vsi_free_q_vectors - Free memory allocated for interrupt vectors
935 * @vsi: the VSI having memory freed
937 void ice_vsi_free_q_vectors(struct ice_vsi *vsi)
941 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
942 ice_free_q_vector(vsi, v_idx);
946 * ice_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
947 * @vsi: the VSI being configured
948 * @v_idx: index of the vector in the VSI struct
950 * We allocate one q_vector. If allocation fails we return -ENOMEM.
952 static int ice_vsi_alloc_q_vector(struct ice_vsi *vsi, int v_idx)
954 struct ice_pf *pf = vsi->back;
955 struct ice_q_vector *q_vector;
957 /* allocate q_vector */
958 q_vector = devm_kzalloc(&pf->pdev->dev, sizeof(*q_vector), GFP_KERNEL);
963 q_vector->v_idx = v_idx;
964 /* only set affinity_mask if the CPU is online */
965 if (cpu_online(v_idx))
966 cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
968 /* This will not be called in the driver load path because the netdev
969 * will not be created yet. All other cases with register the NAPI
970 * handler here (i.e. resume, reset/rebuild, etc.)
973 netif_napi_add(vsi->netdev, &q_vector->napi, ice_napi_poll,
976 /* tie q_vector and VSI together */
977 vsi->q_vectors[v_idx] = q_vector;
983 * ice_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
984 * @vsi: the VSI being configured
986 * We allocate one q_vector per queue interrupt. If allocation fails we
989 static int ice_vsi_alloc_q_vectors(struct ice_vsi *vsi)
991 struct ice_pf *pf = vsi->back;
992 int v_idx = 0, num_q_vectors;
995 if (vsi->q_vectors[0]) {
996 dev_dbg(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
1001 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
1002 num_q_vectors = vsi->num_q_vectors;
1008 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
1009 err = ice_vsi_alloc_q_vector(vsi, v_idx);
1018 ice_free_q_vector(vsi, v_idx);
1020 dev_err(&pf->pdev->dev,
1021 "Failed to allocate %d q_vector for VSI %d, ret=%d\n",
1022 vsi->num_q_vectors, vsi->vsi_num, err);
1023 vsi->num_q_vectors = 0;
1028 * ice_vsi_setup_vector_base - Set up the base vector for the given VSI
1029 * @vsi: ptr to the VSI
1031 * This should only be called after ice_vsi_alloc() which allocates the
1032 * corresponding SW VSI structure and initializes num_queue_pairs for the
1033 * newly allocated VSI.
1035 * Returns 0 on success or negative on failure
1037 static int ice_vsi_setup_vector_base(struct ice_vsi *vsi)
1039 struct ice_pf *pf = vsi->back;
1040 int num_q_vectors = 0;
1042 if (vsi->base_vector) {
1043 dev_dbg(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
1044 vsi->vsi_num, vsi->base_vector);
1048 if (!test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
1051 switch (vsi->type) {
1053 num_q_vectors = vsi->num_q_vectors;
1056 dev_warn(&vsi->back->pdev->dev, "Unknown VSI type %d\n",
1062 vsi->base_vector = ice_get_res(pf, pf->irq_tracker,
1063 num_q_vectors, vsi->idx);
1065 if (vsi->base_vector < 0) {
1066 dev_err(&pf->pdev->dev,
1067 "Failed to get tracking for %d vectors for VSI %d, err=%d\n",
1068 num_q_vectors, vsi->vsi_num, vsi->base_vector);
1076 * ice_vsi_clear_rings - Deallocates the Tx and Rx rings for VSI
1077 * @vsi: the VSI having rings deallocated
1079 static void ice_vsi_clear_rings(struct ice_vsi *vsi)
1083 if (vsi->tx_rings) {
1084 for (i = 0; i < vsi->alloc_txq; i++) {
1085 if (vsi->tx_rings[i]) {
1086 kfree_rcu(vsi->tx_rings[i], rcu);
1087 vsi->tx_rings[i] = NULL;
1091 if (vsi->rx_rings) {
1092 for (i = 0; i < vsi->alloc_rxq; i++) {
1093 if (vsi->rx_rings[i]) {
1094 kfree_rcu(vsi->rx_rings[i], rcu);
1095 vsi->rx_rings[i] = NULL;
1102 * ice_vsi_alloc_rings - Allocates Tx and Rx rings for the VSI
1103 * @vsi: VSI which is having rings allocated
1105 static int ice_vsi_alloc_rings(struct ice_vsi *vsi)
1107 struct ice_pf *pf = vsi->back;
1110 /* Allocate tx_rings */
1111 for (i = 0; i < vsi->alloc_txq; i++) {
1112 struct ice_ring *ring;
1114 /* allocate with kzalloc(), free with kfree_rcu() */
1115 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1121 ring->reg_idx = vsi->txq_map[i];
1122 ring->ring_active = false;
1124 ring->dev = &pf->pdev->dev;
1125 ring->count = vsi->num_desc;
1126 vsi->tx_rings[i] = ring;
1129 /* Allocate rx_rings */
1130 for (i = 0; i < vsi->alloc_rxq; i++) {
1131 struct ice_ring *ring;
1133 /* allocate with kzalloc(), free with kfree_rcu() */
1134 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1139 ring->reg_idx = vsi->rxq_map[i];
1140 ring->ring_active = false;
1142 ring->netdev = vsi->netdev;
1143 ring->dev = &pf->pdev->dev;
1144 ring->count = vsi->num_desc;
1145 vsi->rx_rings[i] = ring;
1151 ice_vsi_clear_rings(vsi);
1156 * ice_vsi_map_rings_to_vectors - Map VSI rings to interrupt vectors
1157 * @vsi: the VSI being configured
1159 * This function maps descriptor rings to the queue-specific vectors allotted
1160 * through the MSI-X enabling code. On a constrained vector budget, we map Tx
1161 * and Rx rings to the vector as "efficiently" as possible.
1163 static void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi)
1165 int q_vectors = vsi->num_q_vectors;
1166 int tx_rings_rem, rx_rings_rem;
1169 /* initially assigning remaining rings count to VSIs num queue value */
1170 tx_rings_rem = vsi->num_txq;
1171 rx_rings_rem = vsi->num_rxq;
1173 for (v_id = 0; v_id < q_vectors; v_id++) {
1174 struct ice_q_vector *q_vector = vsi->q_vectors[v_id];
1175 int tx_rings_per_v, rx_rings_per_v, q_id, q_base;
1177 /* Tx rings mapping to vector */
1178 tx_rings_per_v = DIV_ROUND_UP(tx_rings_rem, q_vectors - v_id);
1179 q_vector->num_ring_tx = tx_rings_per_v;
1180 q_vector->tx.ring = NULL;
1181 q_base = vsi->num_txq - tx_rings_rem;
1183 for (q_id = q_base; q_id < (q_base + tx_rings_per_v); q_id++) {
1184 struct ice_ring *tx_ring = vsi->tx_rings[q_id];
1186 tx_ring->q_vector = q_vector;
1187 tx_ring->next = q_vector->tx.ring;
1188 q_vector->tx.ring = tx_ring;
1190 tx_rings_rem -= tx_rings_per_v;
1192 /* Rx rings mapping to vector */
1193 rx_rings_per_v = DIV_ROUND_UP(rx_rings_rem, q_vectors - v_id);
1194 q_vector->num_ring_rx = rx_rings_per_v;
1195 q_vector->rx.ring = NULL;
1196 q_base = vsi->num_rxq - rx_rings_rem;
1198 for (q_id = q_base; q_id < (q_base + rx_rings_per_v); q_id++) {
1199 struct ice_ring *rx_ring = vsi->rx_rings[q_id];
1201 rx_ring->q_vector = q_vector;
1202 rx_ring->next = q_vector->rx.ring;
1203 q_vector->rx.ring = rx_ring;
1205 rx_rings_rem -= rx_rings_per_v;
1210 * ice_vsi_cfg_rss_lut_key - Configure RSS params for a VSI
1211 * @vsi: VSI to be configured
1213 static int ice_vsi_cfg_rss_lut_key(struct ice_vsi *vsi)
1215 u8 seed[ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE];
1216 struct ice_aqc_get_set_rss_keys *key;
1217 struct ice_pf *pf = vsi->back;
1218 enum ice_status status;
1222 vsi->rss_size = min_t(int, vsi->rss_size, vsi->num_rxq);
1224 lut = devm_kzalloc(&pf->pdev->dev, vsi->rss_table_size, GFP_KERNEL);
1228 if (vsi->rss_lut_user)
1229 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1231 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
1233 status = ice_aq_set_rss_lut(&pf->hw, vsi->vsi_num, vsi->rss_lut_type,
1234 lut, vsi->rss_table_size);
1237 dev_err(&vsi->back->pdev->dev,
1238 "set_rss_lut failed, error %d\n", status);
1240 goto ice_vsi_cfg_rss_exit;
1243 key = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*key), GFP_KERNEL);
1246 goto ice_vsi_cfg_rss_exit;
1249 if (vsi->rss_hkey_user)
1250 memcpy(seed, vsi->rss_hkey_user,
1251 ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE);
1253 netdev_rss_key_fill((void *)seed,
1254 ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE);
1255 memcpy(&key->standard_rss_key, seed,
1256 ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE);
1258 status = ice_aq_set_rss_key(&pf->hw, vsi->vsi_num, key);
1261 dev_err(&vsi->back->pdev->dev, "set_rss_key failed, error %d\n",
1266 devm_kfree(&pf->pdev->dev, key);
1267 ice_vsi_cfg_rss_exit:
1268 devm_kfree(&pf->pdev->dev, lut);
1273 * ice_add_mac_to_list - Add a mac address filter entry to the list
1274 * @vsi: the VSI to be forwarded to
1275 * @add_list: pointer to the list which contains MAC filter entries
1276 * @macaddr: the MAC address to be added.
1278 * Adds mac address filter entry to the temp list
1280 * Returns 0 on success or ENOMEM on failure.
1282 int ice_add_mac_to_list(struct ice_vsi *vsi, struct list_head *add_list,
1285 struct ice_fltr_list_entry *tmp;
1286 struct ice_pf *pf = vsi->back;
1288 tmp = devm_kzalloc(&pf->pdev->dev, sizeof(*tmp), GFP_ATOMIC);
1292 tmp->fltr_info.flag = ICE_FLTR_TX;
1293 tmp->fltr_info.src = vsi->vsi_num;
1294 tmp->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
1295 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1296 tmp->fltr_info.fwd_id.vsi_id = vsi->vsi_num;
1297 ether_addr_copy(tmp->fltr_info.l_data.mac.mac_addr, macaddr);
1299 INIT_LIST_HEAD(&tmp->list_entry);
1300 list_add(&tmp->list_entry, add_list);
1306 * ice_update_eth_stats - Update VSI-specific ethernet statistics counters
1307 * @vsi: the VSI to be updated
1309 void ice_update_eth_stats(struct ice_vsi *vsi)
1311 struct ice_eth_stats *prev_es, *cur_es;
1312 struct ice_hw *hw = &vsi->back->hw;
1313 u16 vsi_num = vsi->vsi_num; /* HW absolute index of a VSI */
1315 prev_es = &vsi->eth_stats_prev;
1316 cur_es = &vsi->eth_stats;
1318 ice_stat_update40(hw, GLV_GORCH(vsi_num), GLV_GORCL(vsi_num),
1319 vsi->stat_offsets_loaded, &prev_es->rx_bytes,
1322 ice_stat_update40(hw, GLV_UPRCH(vsi_num), GLV_UPRCL(vsi_num),
1323 vsi->stat_offsets_loaded, &prev_es->rx_unicast,
1324 &cur_es->rx_unicast);
1326 ice_stat_update40(hw, GLV_MPRCH(vsi_num), GLV_MPRCL(vsi_num),
1327 vsi->stat_offsets_loaded, &prev_es->rx_multicast,
1328 &cur_es->rx_multicast);
1330 ice_stat_update40(hw, GLV_BPRCH(vsi_num), GLV_BPRCL(vsi_num),
1331 vsi->stat_offsets_loaded, &prev_es->rx_broadcast,
1332 &cur_es->rx_broadcast);
1334 ice_stat_update32(hw, GLV_RDPC(vsi_num), vsi->stat_offsets_loaded,
1335 &prev_es->rx_discards, &cur_es->rx_discards);
1337 ice_stat_update40(hw, GLV_GOTCH(vsi_num), GLV_GOTCL(vsi_num),
1338 vsi->stat_offsets_loaded, &prev_es->tx_bytes,
1341 ice_stat_update40(hw, GLV_UPTCH(vsi_num), GLV_UPTCL(vsi_num),
1342 vsi->stat_offsets_loaded, &prev_es->tx_unicast,
1343 &cur_es->tx_unicast);
1345 ice_stat_update40(hw, GLV_MPTCH(vsi_num), GLV_MPTCL(vsi_num),
1346 vsi->stat_offsets_loaded, &prev_es->tx_multicast,
1347 &cur_es->tx_multicast);
1349 ice_stat_update40(hw, GLV_BPTCH(vsi_num), GLV_BPTCL(vsi_num),
1350 vsi->stat_offsets_loaded, &prev_es->tx_broadcast,
1351 &cur_es->tx_broadcast);
1353 ice_stat_update32(hw, GLV_TEPC(vsi_num), vsi->stat_offsets_loaded,
1354 &prev_es->tx_errors, &cur_es->tx_errors);
1356 vsi->stat_offsets_loaded = true;
1360 * ice_free_fltr_list - free filter lists helper
1361 * @dev: pointer to the device struct
1362 * @h: pointer to the list head to be freed
1364 * Helper function to free filter lists previously created using
1365 * ice_add_mac_to_list
1367 void ice_free_fltr_list(struct device *dev, struct list_head *h)
1369 struct ice_fltr_list_entry *e, *tmp;
1371 list_for_each_entry_safe(e, tmp, h, list_entry) {
1372 list_del(&e->list_entry);
1378 * ice_vsi_add_vlan - Add VSI membership for given VLAN
1379 * @vsi: the VSI being configured
1380 * @vid: VLAN id to be added
1382 int ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid)
1384 struct ice_fltr_list_entry *tmp;
1385 struct ice_pf *pf = vsi->back;
1386 LIST_HEAD(tmp_add_list);
1387 enum ice_status status;
1390 tmp = devm_kzalloc(&pf->pdev->dev, sizeof(*tmp), GFP_KERNEL);
1394 tmp->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
1395 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1396 tmp->fltr_info.flag = ICE_FLTR_TX;
1397 tmp->fltr_info.src = vsi->vsi_num;
1398 tmp->fltr_info.fwd_id.vsi_id = vsi->vsi_num;
1399 tmp->fltr_info.l_data.vlan.vlan_id = vid;
1401 INIT_LIST_HEAD(&tmp->list_entry);
1402 list_add(&tmp->list_entry, &tmp_add_list);
1404 status = ice_add_vlan(&pf->hw, &tmp_add_list);
1407 dev_err(&pf->pdev->dev, "Failure Adding VLAN %d on VSI %i\n",
1411 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
1416 * ice_vsi_kill_vlan - Remove VSI membership for a given VLAN
1417 * @vsi: the VSI being configured
1418 * @vid: VLAN id to be removed
1420 * Returns 0 on success and negative on failure
1422 int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid)
1424 struct ice_fltr_list_entry *list;
1425 struct ice_pf *pf = vsi->back;
1426 LIST_HEAD(tmp_add_list);
1429 list = devm_kzalloc(&pf->pdev->dev, sizeof(*list), GFP_KERNEL);
1433 list->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
1434 list->fltr_info.fwd_id.vsi_id = vsi->vsi_num;
1435 list->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1436 list->fltr_info.l_data.vlan.vlan_id = vid;
1437 list->fltr_info.flag = ICE_FLTR_TX;
1438 list->fltr_info.src = vsi->vsi_num;
1440 INIT_LIST_HEAD(&list->list_entry);
1441 list_add(&list->list_entry, &tmp_add_list);
1443 if (ice_remove_vlan(&pf->hw, &tmp_add_list)) {
1444 dev_err(&pf->pdev->dev, "Error removing VLAN %d on vsi %i\n",
1449 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
1454 * ice_vsi_cfg_rxqs - Configure the VSI for Rx
1455 * @vsi: the VSI being configured
1457 * Return 0 on success and a negative value on error
1458 * Configure the Rx VSI for operation.
1460 int ice_vsi_cfg_rxqs(struct ice_vsi *vsi)
1465 if (vsi->netdev && vsi->netdev->mtu > ETH_DATA_LEN)
1466 vsi->max_frame = vsi->netdev->mtu +
1467 ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
1469 vsi->max_frame = ICE_RXBUF_2048;
1471 vsi->rx_buf_len = ICE_RXBUF_2048;
1472 /* set up individual rings */
1473 for (i = 0; i < vsi->num_rxq && !err; i++)
1474 err = ice_setup_rx_ctx(vsi->rx_rings[i]);
1477 dev_err(&vsi->back->pdev->dev, "ice_setup_rx_ctx failed\n");
1484 * ice_vsi_cfg_txqs - Configure the VSI for Tx
1485 * @vsi: the VSI being configured
1487 * Return 0 on success and a negative value on error
1488 * Configure the Tx VSI for operation.
1490 int ice_vsi_cfg_txqs(struct ice_vsi *vsi)
1492 struct ice_aqc_add_tx_qgrp *qg_buf;
1493 struct ice_aqc_add_txqs_perq *txq;
1494 struct ice_pf *pf = vsi->back;
1495 enum ice_status status;
1496 u16 buf_len, i, pf_q;
1497 int err = 0, tc = 0;
1500 buf_len = sizeof(struct ice_aqc_add_tx_qgrp);
1501 qg_buf = devm_kzalloc(&pf->pdev->dev, buf_len, GFP_KERNEL);
1505 if (vsi->num_txq > ICE_MAX_TXQ_PER_TXQG) {
1509 qg_buf->num_txqs = 1;
1512 /* set up and configure the Tx queues */
1513 ice_for_each_txq(vsi, i) {
1514 struct ice_tlan_ctx tlan_ctx = { 0 };
1516 pf_q = vsi->txq_map[i];
1517 ice_setup_tx_ctx(vsi->tx_rings[i], &tlan_ctx, pf_q);
1518 /* copy context contents into the qg_buf */
1519 qg_buf->txqs[0].txq_id = cpu_to_le16(pf_q);
1520 ice_set_ctx((u8 *)&tlan_ctx, qg_buf->txqs[0].txq_ctx,
1523 /* init queue specific tail reg. It is referred as transmit
1524 * comm scheduler queue doorbell.
1526 vsi->tx_rings[i]->tail = pf->hw.hw_addr + QTX_COMM_DBELL(pf_q);
1527 status = ice_ena_vsi_txq(vsi->port_info, vsi->vsi_num, tc,
1528 num_q_grps, qg_buf, buf_len, NULL);
1530 dev_err(&vsi->back->pdev->dev,
1531 "Failed to set LAN Tx queue context, error: %d\n",
1537 /* Add Tx Queue TEID into the VSI Tx ring from the response
1538 * This will complete configuring and enabling the queue.
1540 txq = &qg_buf->txqs[0];
1541 if (pf_q == le16_to_cpu(txq->txq_id))
1542 vsi->tx_rings[i]->txq_teid =
1543 le32_to_cpu(txq->q_teid);
1546 devm_kfree(&pf->pdev->dev, qg_buf);
1551 * ice_vsi_cfg_msix - MSIX mode Interrupt Config in the HW
1552 * @vsi: the VSI being configured
1554 void ice_vsi_cfg_msix(struct ice_vsi *vsi)
1556 struct ice_pf *pf = vsi->back;
1557 u16 vector = vsi->base_vector;
1558 struct ice_hw *hw = &pf->hw;
1559 u32 txq = 0, rxq = 0;
1563 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1564 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1566 itr_gran = hw->itr_gran_200;
1568 if (q_vector->num_ring_rx) {
1570 ITR_TO_REG(vsi->rx_rings[rxq]->rx_itr_setting,
1572 q_vector->rx.latency_range = ICE_LOW_LATENCY;
1575 if (q_vector->num_ring_tx) {
1577 ITR_TO_REG(vsi->tx_rings[txq]->tx_itr_setting,
1579 q_vector->tx.latency_range = ICE_LOW_LATENCY;
1581 wr32(hw, GLINT_ITR(ICE_RX_ITR, vector), q_vector->rx.itr);
1582 wr32(hw, GLINT_ITR(ICE_TX_ITR, vector), q_vector->tx.itr);
1584 /* Both Transmit Queue Interrupt Cause Control register
1585 * and Receive Queue Interrupt Cause control register
1586 * expects MSIX_INDX field to be the vector index
1587 * within the function space and not the absolute
1588 * vector index across PF or across device.
1589 * For SR-IOV VF VSIs queue vector index always starts
1590 * with 1 since first vector index(0) is used for OICR
1591 * in VF space. Since VMDq and other PF VSIs are within
1592 * the PF function space, use the vector index that is
1593 * tracked for this PF.
1595 for (q = 0; q < q_vector->num_ring_tx; q++) {
1599 val = QINT_TQCTL_CAUSE_ENA_M |
1600 (itr << QINT_TQCTL_ITR_INDX_S) |
1601 (vector << QINT_TQCTL_MSIX_INDX_S);
1602 wr32(hw, QINT_TQCTL(vsi->txq_map[txq]), val);
1606 for (q = 0; q < q_vector->num_ring_rx; q++) {
1610 val = QINT_RQCTL_CAUSE_ENA_M |
1611 (itr << QINT_RQCTL_ITR_INDX_S) |
1612 (vector << QINT_RQCTL_MSIX_INDX_S);
1613 wr32(hw, QINT_RQCTL(vsi->rxq_map[rxq]), val);
1622 * ice_vsi_manage_vlan_insertion - Manage VLAN insertion for the VSI for Tx
1623 * @vsi: the VSI being changed
1625 int ice_vsi_manage_vlan_insertion(struct ice_vsi *vsi)
1627 struct device *dev = &vsi->back->pdev->dev;
1628 struct ice_hw *hw = &vsi->back->hw;
1629 struct ice_vsi_ctx ctxt = { 0 };
1630 enum ice_status status;
1632 /* Here we are configuring the VSI to let the driver add VLAN tags by
1633 * setting vlan_flags to ICE_AQ_VSI_VLAN_MODE_ALL. The actual VLAN tag
1634 * insertion happens in the Tx hot path, in ice_tx_map.
1636 ctxt.info.vlan_flags = ICE_AQ_VSI_VLAN_MODE_ALL;
1638 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
1639 ctxt.vsi_num = vsi->vsi_num;
1641 status = ice_aq_update_vsi(hw, &ctxt, NULL);
1643 dev_err(dev, "update VSI for VLAN insert failed, err %d aq_err %d\n",
1644 status, hw->adminq.sq_last_status);
1648 vsi->info.vlan_flags = ctxt.info.vlan_flags;
1653 * ice_vsi_manage_vlan_stripping - Manage VLAN stripping for the VSI for Rx
1654 * @vsi: the VSI being changed
1655 * @ena: boolean value indicating if this is a enable or disable request
1657 int ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
1659 struct device *dev = &vsi->back->pdev->dev;
1660 struct ice_hw *hw = &vsi->back->hw;
1661 struct ice_vsi_ctx ctxt = { 0 };
1662 enum ice_status status;
1664 /* Here we are configuring what the VSI should do with the VLAN tag in
1665 * the Rx packet. We can either leave the tag in the packet or put it in
1666 * the Rx descriptor.
1669 /* Strip VLAN tag from Rx packet and put it in the desc */
1670 ctxt.info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_STR_BOTH;
1672 /* Disable stripping. Leave tag in packet */
1673 ctxt.info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_NOTHING;
1676 /* Allow all packets untagged/tagged */
1677 ctxt.info.vlan_flags |= ICE_AQ_VSI_VLAN_MODE_ALL;
1679 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
1680 ctxt.vsi_num = vsi->vsi_num;
1682 status = ice_aq_update_vsi(hw, &ctxt, NULL);
1684 dev_err(dev, "update VSI for VLAN strip failed, ena = %d err %d aq_err %d\n",
1685 ena, status, hw->adminq.sq_last_status);
1689 vsi->info.vlan_flags = ctxt.info.vlan_flags;
1694 * ice_vsi_start_rx_rings - start VSI's Rx rings
1695 * @vsi: the VSI whose rings are to be started
1697 * Returns 0 on success and a negative value on error
1699 int ice_vsi_start_rx_rings(struct ice_vsi *vsi)
1701 return ice_vsi_ctrl_rx_rings(vsi, true);
1705 * ice_vsi_stop_rx_rings - stop VSI's Rx rings
1708 * Returns 0 on success and a negative value on error
1710 int ice_vsi_stop_rx_rings(struct ice_vsi *vsi)
1712 return ice_vsi_ctrl_rx_rings(vsi, false);
1716 * ice_vsi_stop_tx_rings - Disable Tx rings
1717 * @vsi: the VSI being configured
1719 int ice_vsi_stop_tx_rings(struct ice_vsi *vsi)
1721 struct ice_pf *pf = vsi->back;
1722 struct ice_hw *hw = &pf->hw;
1723 enum ice_status status;
1728 if (vsi->num_txq > ICE_LAN_TXQ_MAX_QDIS)
1731 q_teids = devm_kcalloc(&pf->pdev->dev, vsi->num_txq, sizeof(*q_teids),
1736 q_ids = devm_kcalloc(&pf->pdev->dev, vsi->num_txq, sizeof(*q_ids),
1740 goto err_alloc_q_ids;
1743 /* set up the Tx queue list to be disabled */
1744 ice_for_each_txq(vsi, i) {
1747 if (!vsi->tx_rings || !vsi->tx_rings[i]) {
1752 q_ids[i] = vsi->txq_map[i];
1753 q_teids[i] = vsi->tx_rings[i]->txq_teid;
1755 /* clear cause_ena bit for disabled queues */
1756 val = rd32(hw, QINT_TQCTL(vsi->tx_rings[i]->reg_idx));
1757 val &= ~QINT_TQCTL_CAUSE_ENA_M;
1758 wr32(hw, QINT_TQCTL(vsi->tx_rings[i]->reg_idx), val);
1760 /* software is expected to wait for 100 ns */
1763 /* trigger a software interrupt for the vector associated to
1764 * the queue to schedule NAPI handler
1766 v_idx = vsi->tx_rings[i]->q_vector->v_idx;
1767 wr32(hw, GLINT_DYN_CTL(vsi->base_vector + v_idx),
1768 GLINT_DYN_CTL_SWINT_TRIG_M | GLINT_DYN_CTL_INTENA_MSK_M);
1770 status = ice_dis_vsi_txq(vsi->port_info, vsi->num_txq, q_ids, q_teids,
1772 /* if the disable queue command was exercised during an active reset
1773 * flow, ICE_ERR_RESET_ONGOING is returned. This is not an error as
1774 * the reset operation disables queues at the hardware level anyway.
1776 if (status == ICE_ERR_RESET_ONGOING) {
1777 dev_info(&pf->pdev->dev,
1778 "Reset in progress. LAN Tx queues already disabled\n");
1779 } else if (status) {
1780 dev_err(&pf->pdev->dev,
1781 "Failed to disable LAN Tx queues, error: %d\n",
1787 devm_kfree(&pf->pdev->dev, q_ids);
1790 devm_kfree(&pf->pdev->dev, q_teids);
1796 * ice_cfg_vlan_pruning - enable or disable VLAN pruning on the VSI
1797 * @vsi: VSI to enable or disable VLAN pruning on
1798 * @ena: set to true to enable VLAN pruning and false to disable it
1800 * returns 0 if VSI is updated, negative otherwise
1802 int ice_cfg_vlan_pruning(struct ice_vsi *vsi, bool ena)
1804 struct ice_vsi_ctx *ctxt;
1811 dev = &vsi->back->pdev->dev;
1812 ctxt = devm_kzalloc(dev, sizeof(*ctxt), GFP_KERNEL);
1816 ctxt->info = vsi->info;
1819 ctxt->info.sec_flags |=
1820 ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
1821 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S;
1822 ctxt->info.sw_flags2 |= ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
1824 ctxt->info.sec_flags &=
1825 ~(ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
1826 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S);
1827 ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
1830 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID |
1831 ICE_AQ_VSI_PROP_SW_VALID);
1832 ctxt->vsi_num = vsi->vsi_num;
1833 status = ice_aq_update_vsi(&vsi->back->hw, ctxt, NULL);
1835 netdev_err(vsi->netdev, "%sabling VLAN pruning on VSI %d failed, err = %d, aq_err = %d\n",
1836 ena ? "Ena" : "Dis", vsi->vsi_num, status,
1837 vsi->back->hw.adminq.sq_last_status);
1841 vsi->info.sec_flags = ctxt->info.sec_flags;
1842 vsi->info.sw_flags2 = ctxt->info.sw_flags2;
1844 devm_kfree(dev, ctxt);
1848 devm_kfree(dev, ctxt);
1853 * ice_vsi_setup - Set up a VSI by a given type
1854 * @pf: board private structure
1855 * @pi: pointer to the port_info instance
1857 * @vf_id: defines VF id to which this VSI connects. This field is meant to be
1858 * used only for ICE_VSI_VF VSI type. For other VSI types, should
1859 * fill-in ICE_INVAL_VFID as input.
1861 * This allocates the sw VSI structure and its queue resources.
1863 * Returns pointer to the successfully allocated and configured VSI sw struct on
1864 * success, NULL on failure.
1867 ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
1868 enum ice_vsi_type type, u16 __always_unused vf_id)
1870 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1871 struct device *dev = &pf->pdev->dev;
1872 struct ice_vsi *vsi;
1875 vsi = ice_vsi_alloc(pf, type);
1877 dev_err(dev, "could not allocate VSI\n");
1881 vsi->port_info = pi;
1882 vsi->vsw = pf->first_sw;
1884 if (ice_vsi_get_qs(vsi)) {
1885 dev_err(dev, "Failed to allocate queues. vsi->idx = %d\n",
1890 /* set RSS capabilities */
1891 ice_vsi_set_rss_params(vsi);
1893 /* create the VSI */
1894 ret = ice_vsi_init(vsi);
1898 switch (vsi->type) {
1900 ret = ice_vsi_alloc_q_vectors(vsi);
1902 goto unroll_vsi_init;
1904 ret = ice_vsi_setup_vector_base(vsi);
1906 goto unroll_alloc_q_vector;
1908 ret = ice_vsi_alloc_rings(vsi);
1910 goto unroll_vector_base;
1912 ice_vsi_map_rings_to_vectors(vsi);
1914 /* Do not exit if configuring RSS had an issue, at least
1915 * receive traffic on first queue. Hence no need to capture
1918 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
1919 ice_vsi_cfg_rss_lut_key(vsi);
1922 /* if VSI type is not recognized, clean up the resources and
1925 goto unroll_vsi_init;
1928 ice_vsi_set_tc_cfg(vsi);
1930 /* configure VSI nodes based on number of queues and TC's */
1931 for (i = 0; i < vsi->tc_cfg.numtc; i++)
1932 max_txqs[i] = vsi->num_txq;
1934 ret = ice_cfg_vsi_lan(vsi->port_info, vsi->vsi_num,
1935 vsi->tc_cfg.ena_tc, max_txqs);
1937 dev_info(&pf->pdev->dev, "Failed VSI lan queue config\n");
1938 goto unroll_vector_base;
1944 ice_free_res(vsi->back->irq_tracker, vsi->base_vector, vsi->idx);
1945 unroll_alloc_q_vector:
1946 ice_vsi_free_q_vectors(vsi);
1948 ice_vsi_delete(vsi);
1950 ice_vsi_put_qs(vsi);
1951 pf->q_left_tx += vsi->alloc_txq;
1952 pf->q_left_rx += vsi->alloc_rxq;
1959 * ice_vsi_release_msix - Clear the queue to Interrupt mapping in HW
1960 * @vsi: the VSI being cleaned up
1962 static void ice_vsi_release_msix(struct ice_vsi *vsi)
1964 struct ice_pf *pf = vsi->back;
1965 u16 vector = vsi->base_vector;
1966 struct ice_hw *hw = &pf->hw;
1971 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1972 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1974 wr32(hw, GLINT_ITR(ICE_RX_ITR, vector), 0);
1975 wr32(hw, GLINT_ITR(ICE_TX_ITR, vector), 0);
1976 for (q = 0; q < q_vector->num_ring_tx; q++) {
1977 wr32(hw, QINT_TQCTL(vsi->txq_map[txq]), 0);
1981 for (q = 0; q < q_vector->num_ring_rx; q++) {
1982 wr32(hw, QINT_RQCTL(vsi->rxq_map[rxq]), 0);
1991 * ice_vsi_free_irq - Free the IRQ association with the OS
1992 * @vsi: the VSI being configured
1994 void ice_vsi_free_irq(struct ice_vsi *vsi)
1996 struct ice_pf *pf = vsi->back;
1997 int base = vsi->base_vector;
1999 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
2002 if (!vsi->q_vectors || !vsi->irqs_ready)
2005 vsi->irqs_ready = false;
2006 for (i = 0; i < vsi->num_q_vectors; i++) {
2007 u16 vector = i + base;
2010 irq_num = pf->msix_entries[vector].vector;
2012 /* free only the irqs that were actually requested */
2013 if (!vsi->q_vectors[i] ||
2014 !(vsi->q_vectors[i]->num_ring_tx ||
2015 vsi->q_vectors[i]->num_ring_rx))
2018 /* clear the affinity notifier in the IRQ descriptor */
2019 irq_set_affinity_notifier(irq_num, NULL);
2021 /* clear the affinity_mask in the IRQ descriptor */
2022 irq_set_affinity_hint(irq_num, NULL);
2023 synchronize_irq(irq_num);
2024 devm_free_irq(&pf->pdev->dev, irq_num,
2027 ice_vsi_release_msix(vsi);
2032 * ice_vsi_free_tx_rings - Free Tx resources for VSI queues
2033 * @vsi: the VSI having resources freed
2035 void ice_vsi_free_tx_rings(struct ice_vsi *vsi)
2042 ice_for_each_txq(vsi, i)
2043 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
2044 ice_free_tx_ring(vsi->tx_rings[i]);
2048 * ice_vsi_free_rx_rings - Free Rx resources for VSI queues
2049 * @vsi: the VSI having resources freed
2051 void ice_vsi_free_rx_rings(struct ice_vsi *vsi)
2058 ice_for_each_rxq(vsi, i)
2059 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
2060 ice_free_rx_ring(vsi->rx_rings[i]);
2064 * ice_vsi_close - Shut down a VSI
2065 * @vsi: the VSI being shut down
2067 void ice_vsi_close(struct ice_vsi *vsi)
2069 if (!test_and_set_bit(__ICE_DOWN, vsi->state))
2072 ice_vsi_free_irq(vsi);
2073 ice_vsi_free_tx_rings(vsi);
2074 ice_vsi_free_rx_rings(vsi);
2078 * ice_free_res - free a block of resources
2079 * @res: pointer to the resource
2080 * @index: starting index previously returned by ice_get_res
2081 * @id: identifier to track owner
2083 * Returns number of resources freed
2085 int ice_free_res(struct ice_res_tracker *res, u16 index, u16 id)
2090 if (!res || index >= res->num_entries)
2093 id |= ICE_RES_VALID_BIT;
2094 for (i = index; i < res->num_entries && res->list[i] == id; i++) {
2103 * ice_search_res - Search the tracker for a block of resources
2104 * @res: pointer to the resource
2105 * @needed: size of the block needed
2106 * @id: identifier to track owner
2108 * Returns the base item index of the block, or -ENOMEM for error
2110 static int ice_search_res(struct ice_res_tracker *res, u16 needed, u16 id)
2112 int start = res->search_hint;
2115 id |= ICE_RES_VALID_BIT;
2118 /* skip already allocated entries */
2119 if (res->list[end++] & ICE_RES_VALID_BIT) {
2121 if ((start + needed) > res->num_entries)
2125 if (end == (start + needed)) {
2128 /* there was enough, so assign it to the requestor */
2130 res->list[i++] = id;
2132 if (end == res->num_entries)
2135 res->search_hint = end;
2144 * ice_get_res - get a block of resources
2145 * @pf: board private structure
2146 * @res: pointer to the resource
2147 * @needed: size of the block needed
2148 * @id: identifier to track owner
2150 * Returns the base item index of the block, or -ENOMEM for error
2151 * The search_hint trick and lack of advanced fit-finding only works
2152 * because we're highly likely to have all the same sized requests.
2153 * Linear search time and any fragmentation should be minimal.
2156 ice_get_res(struct ice_pf *pf, struct ice_res_tracker *res, u16 needed, u16 id)
2163 if (!needed || needed > res->num_entries || id >= ICE_RES_VALID_BIT) {
2164 dev_err(&pf->pdev->dev,
2165 "param err: needed=%d, num_entries = %d id=0x%04x\n",
2166 needed, res->num_entries, id);
2170 /* search based on search_hint */
2171 ret = ice_search_res(res, needed, id);
2174 /* previous search failed. Reset search hint and try again */
2175 res->search_hint = 0;
2176 ret = ice_search_res(res, needed, id);
2183 * ice_vsi_dis_irq - Mask off queue interrupt generation on the VSI
2184 * @vsi: the VSI being un-configured
2186 void ice_vsi_dis_irq(struct ice_vsi *vsi)
2188 struct ice_pf *pf = vsi->back;
2189 struct ice_hw *hw = &pf->hw;
2190 int base = vsi->base_vector;
2194 /* disable interrupt causation from each queue */
2195 if (vsi->tx_rings) {
2196 ice_for_each_txq(vsi, i) {
2197 if (vsi->tx_rings[i]) {
2200 reg = vsi->tx_rings[i]->reg_idx;
2201 val = rd32(hw, QINT_TQCTL(reg));
2202 val &= ~QINT_TQCTL_CAUSE_ENA_M;
2203 wr32(hw, QINT_TQCTL(reg), val);
2208 if (vsi->rx_rings) {
2209 ice_for_each_rxq(vsi, i) {
2210 if (vsi->rx_rings[i]) {
2213 reg = vsi->rx_rings[i]->reg_idx;
2214 val = rd32(hw, QINT_RQCTL(reg));
2215 val &= ~QINT_RQCTL_CAUSE_ENA_M;
2216 wr32(hw, QINT_RQCTL(reg), val);
2221 /* disable each interrupt */
2222 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
2223 for (i = vsi->base_vector;
2224 i < (vsi->num_q_vectors + vsi->base_vector); i++)
2225 wr32(hw, GLINT_DYN_CTL(i), 0);
2228 for (i = 0; i < vsi->num_q_vectors; i++)
2229 synchronize_irq(pf->msix_entries[i + base].vector);
2234 * ice_vsi_release - Delete a VSI and free its resources
2235 * @vsi: the VSI being removed
2237 * Returns 0 on success or < 0 on error
2239 int ice_vsi_release(struct ice_vsi *vsi)
2246 /* do not unregister and free netdevs while driver is in the reset
2247 * recovery pending state. Since reset/rebuild happens through PF
2248 * service task workqueue, its not a good idea to unregister netdev
2249 * that is associated to the PF that is running the work queue items
2250 * currently. This is done to avoid check_flush_dependency() warning
2253 if (vsi->netdev && !ice_is_reset_recovery_pending(pf->state)) {
2254 unregister_netdev(vsi->netdev);
2255 free_netdev(vsi->netdev);
2259 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2262 /* Disable VSI and free resources */
2263 ice_vsi_dis_irq(vsi);
2266 /* reclaim interrupt vectors back to PF */
2267 ice_free_res(vsi->back->irq_tracker, vsi->base_vector, vsi->idx);
2268 pf->num_avail_msix += vsi->num_q_vectors;
2270 ice_remove_vsi_fltr(&pf->hw, vsi->vsi_num);
2271 ice_vsi_delete(vsi);
2272 ice_vsi_free_q_vectors(vsi);
2273 ice_vsi_clear_rings(vsi);
2275 ice_vsi_put_qs(vsi);
2276 pf->q_left_tx += vsi->alloc_txq;
2277 pf->q_left_rx += vsi->alloc_rxq;
2279 /* retain SW VSI data structure since it is needed to unregister and
2280 * free VSI netdev when PF is not in reset recovery pending state,\
2281 * for ex: during rmmod.
2283 if (!ice_is_reset_recovery_pending(pf->state))
2290 * ice_vsi_rebuild - Rebuild VSI after reset
2291 * @vsi: VSI to be rebuild
2293 * Returns 0 on success and negative value on failure
2295 int ice_vsi_rebuild(struct ice_vsi *vsi)
2297 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2303 ice_vsi_free_q_vectors(vsi);
2304 ice_free_res(vsi->back->irq_tracker, vsi->base_vector, vsi->idx);
2305 vsi->base_vector = 0;
2306 ice_vsi_clear_rings(vsi);
2307 ice_vsi_free_arrays(vsi, false);
2308 ice_vsi_set_num_qs(vsi);
2310 /* Initialize VSI struct elements and create VSI in FW */
2311 ret = ice_vsi_init(vsi);
2315 ret = ice_vsi_alloc_arrays(vsi, false);
2319 switch (vsi->type) {
2321 ret = ice_vsi_alloc_q_vectors(vsi);
2325 ret = ice_vsi_setup_vector_base(vsi);
2329 ret = ice_vsi_alloc_rings(vsi);
2333 ice_vsi_map_rings_to_vectors(vsi);
2339 ice_vsi_set_tc_cfg(vsi);
2341 /* configure VSI nodes based on number of queues and TC's */
2342 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2343 max_txqs[i] = vsi->num_txq;
2345 ret = ice_cfg_vsi_lan(vsi->port_info, vsi->vsi_num,
2346 vsi->tc_cfg.ena_tc, max_txqs);
2348 dev_info(&vsi->back->pdev->dev,
2349 "Failed VSI lan queue config\n");
2355 ice_vsi_free_q_vectors(vsi);
2358 vsi->current_netdev_flags = 0;
2359 unregister_netdev(vsi->netdev);
2360 free_netdev(vsi->netdev);
2365 set_bit(__ICE_RESET_FAILED, vsi->back->state);
2370 * ice_is_reset_recovery_pending - schedule a reset
2371 * @state: pf state field
2373 bool ice_is_reset_recovery_pending(unsigned long *state)
2375 return test_bit(__ICE_RESET_RECOVERY_PENDING, state);