1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
6 #include "ice_dcb_lib.h"
9 * ice_setup_rx_ctx - Configure a receive ring context
10 * @ring: The Rx ring to configure
12 * Configure the Rx descriptor ring in RLAN context.
14 static int ice_setup_rx_ctx(struct ice_ring *ring)
16 struct ice_vsi *vsi = ring->vsi;
17 struct ice_hw *hw = &vsi->back->hw;
18 u32 rxdid = ICE_RXDID_FLEX_NIC;
19 struct ice_rlan_ctx rlan_ctx;
24 /* what is Rx queue number in global space of 2K Rx queues */
25 pf_q = vsi->rxq_map[ring->q_index];
27 /* clear the context structure first */
28 memset(&rlan_ctx, 0, sizeof(rlan_ctx));
30 rlan_ctx.base = ring->dma >> 7;
32 rlan_ctx.qlen = ring->count;
34 /* Receive Packet Data Buffer Size.
35 * The Packet Data Buffer Size is defined in 128 byte units.
37 rlan_ctx.dbuf = vsi->rx_buf_len >> ICE_RLAN_CTX_DBUF_S;
39 /* use 32 byte descriptors */
42 /* Strip the Ethernet CRC bytes before the packet is posted to host
45 rlan_ctx.crcstrip = 1;
47 /* L2TSEL flag defines the reported L2 Tags in the receive descriptor */
50 rlan_ctx.dtype = ICE_RX_DTYPE_NO_SPLIT;
51 rlan_ctx.hsplit_0 = ICE_RLAN_RX_HSPLIT_0_NO_SPLIT;
52 rlan_ctx.hsplit_1 = ICE_RLAN_RX_HSPLIT_1_NO_SPLIT;
54 /* This controls whether VLAN is stripped from inner headers
55 * The VLAN in the inner L2 header is stripped to the receive
56 * descriptor if enabled by this flag.
60 /* Max packet size for this queue - must not be set to a larger value
63 rlan_ctx.rxmax = min_t(u16, vsi->max_frame,
64 ICE_MAX_CHAINED_RX_BUFS * vsi->rx_buf_len);
66 /* Rx queue threshold in units of 64 */
67 rlan_ctx.lrxqthresh = 1;
69 /* Enable Flexible Descriptors in the queue context which
70 * allows this driver to select a specific receive descriptor format
72 if (vsi->type != ICE_VSI_VF) {
73 regval = rd32(hw, QRXFLXP_CNTXT(pf_q));
74 regval |= (rxdid << QRXFLXP_CNTXT_RXDID_IDX_S) &
75 QRXFLXP_CNTXT_RXDID_IDX_M;
77 /* increasing context priority to pick up profile ID;
78 * default is 0x01; setting to 0x03 to ensure profile
79 * is programming if prev context is of same priority
81 regval |= (0x03 << QRXFLXP_CNTXT_RXDID_PRIO_S) &
82 QRXFLXP_CNTXT_RXDID_PRIO_M;
84 wr32(hw, QRXFLXP_CNTXT(pf_q), regval);
87 /* Absolute queue number out of 2K needs to be passed */
88 err = ice_write_rxq_ctx(hw, &rlan_ctx, pf_q);
90 dev_err(&vsi->back->pdev->dev,
91 "Failed to set LAN Rx queue context for absolute Rx queue %d error: %d\n",
96 if (vsi->type == ICE_VSI_VF)
99 /* init queue specific tail register */
100 ring->tail = hw->hw_addr + QRX_TAIL(pf_q);
101 writel(0, ring->tail);
102 ice_alloc_rx_bufs(ring, ICE_DESC_UNUSED(ring));
108 * ice_setup_tx_ctx - setup a struct ice_tlan_ctx instance
109 * @ring: The Tx ring to configure
110 * @tlan_ctx: Pointer to the Tx LAN queue context structure to be initialized
111 * @pf_q: queue index in the PF space
113 * Configure the Tx descriptor ring in TLAN context.
116 ice_setup_tx_ctx(struct ice_ring *ring, struct ice_tlan_ctx *tlan_ctx, u16 pf_q)
118 struct ice_vsi *vsi = ring->vsi;
119 struct ice_hw *hw = &vsi->back->hw;
121 tlan_ctx->base = ring->dma >> ICE_TLAN_CTX_BASE_S;
123 tlan_ctx->port_num = vsi->port_info->lport;
125 /* Transmit Queue Length */
126 tlan_ctx->qlen = ring->count;
128 ice_set_cgd_num(tlan_ctx, ring);
131 tlan_ctx->pf_num = hw->pf_id;
133 /* queue belongs to a specific VSI type
134 * VF / VM index should be programmed per vmvf_type setting:
135 * for vmvf_type = VF, it is VF number between 0-256
136 * for vmvf_type = VM, it is VM number between 0-767
137 * for PF or EMP this field should be set to zero
141 tlan_ctx->vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_PF;
144 /* Firmware expects vmvf_num to be absolute VF ID */
145 tlan_ctx->vmvf_num = hw->func_caps.vf_base_id + vsi->vf_id;
146 tlan_ctx->vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_VF;
152 /* make sure the context is associated with the right VSI */
153 tlan_ctx->src_vsi = ice_get_hw_vsi_num(hw, vsi->idx);
155 tlan_ctx->tso_ena = ICE_TX_LEGACY;
156 tlan_ctx->tso_qnum = pf_q;
158 /* Legacy or Advanced Host Interface:
159 * 0: Advanced Host Interface
160 * 1: Legacy Host Interface
162 tlan_ctx->legacy_int = ICE_TX_LEGACY;
166 * ice_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
167 * @pf: the PF being configured
168 * @pf_q: the PF queue
169 * @ena: enable or disable state of the queue
171 * This routine will wait for the given Rx queue of the PF to reach the
172 * enabled or disabled state.
173 * Returns -ETIMEDOUT in case of failing to reach the requested state after
174 * multiple retries; else will return 0 in case of success.
176 static int ice_pf_rxq_wait(struct ice_pf *pf, int pf_q, bool ena)
180 for (i = 0; i < ICE_Q_WAIT_MAX_RETRY; i++) {
181 if (ena == !!(rd32(&pf->hw, QRX_CTRL(pf_q)) &
182 QRX_CTRL_QENA_STAT_M))
185 usleep_range(20, 40);
192 * ice_vsi_ctrl_rx_rings - Start or stop a VSI's Rx rings
193 * @vsi: the VSI being configured
194 * @ena: start or stop the Rx rings
196 static int ice_vsi_ctrl_rx_rings(struct ice_vsi *vsi, bool ena)
198 struct ice_pf *pf = vsi->back;
199 struct ice_hw *hw = &pf->hw;
202 for (i = 0; i < vsi->num_rxq; i++) {
203 int pf_q = vsi->rxq_map[i];
206 rx_reg = rd32(hw, QRX_CTRL(pf_q));
208 /* Skip if the queue is already in the requested state */
209 if (ena == !!(rx_reg & QRX_CTRL_QENA_STAT_M))
212 /* turn on/off the queue */
214 rx_reg |= QRX_CTRL_QENA_REQ_M;
216 rx_reg &= ~QRX_CTRL_QENA_REQ_M;
217 wr32(hw, QRX_CTRL(pf_q), rx_reg);
219 /* wait for the change to finish */
220 ret = ice_pf_rxq_wait(pf, pf_q, ena);
222 dev_err(&pf->pdev->dev,
223 "VSI idx %d Rx ring %d %sable timeout\n",
224 vsi->idx, pf_q, (ena ? "en" : "dis"));
233 * ice_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the VSI
236 * On error: returns error code (negative)
237 * On success: returns 0
239 static int ice_vsi_alloc_arrays(struct ice_vsi *vsi)
241 struct ice_pf *pf = vsi->back;
243 /* allocate memory for both Tx and Rx ring pointers */
244 vsi->tx_rings = devm_kcalloc(&pf->pdev->dev, vsi->alloc_txq,
245 sizeof(*vsi->tx_rings), GFP_KERNEL);
249 vsi->rx_rings = devm_kcalloc(&pf->pdev->dev, vsi->alloc_rxq,
250 sizeof(*vsi->rx_rings), GFP_KERNEL);
254 /* allocate memory for q_vector pointers */
255 vsi->q_vectors = devm_kcalloc(&pf->pdev->dev, vsi->num_q_vectors,
256 sizeof(*vsi->q_vectors), GFP_KERNEL);
263 devm_kfree(&pf->pdev->dev, vsi->rx_rings);
265 devm_kfree(&pf->pdev->dev, vsi->tx_rings);
271 * ice_vsi_set_num_desc - Set number of descriptors for queues on this VSI
272 * @vsi: the VSI being configured
274 static void ice_vsi_set_num_desc(struct ice_vsi *vsi)
278 vsi->num_rx_desc = ICE_DFLT_NUM_RX_DESC;
279 vsi->num_tx_desc = ICE_DFLT_NUM_TX_DESC;
282 dev_dbg(&vsi->back->pdev->dev,
283 "Not setting number of Tx/Rx descriptors for VSI type %d\n",
290 * ice_vsi_set_num_qs - Set number of queues, descriptors and vectors for a VSI
291 * @vsi: the VSI being configured
292 * @vf_id: ID of the VF being configured
294 * Return 0 on success and a negative value on error
296 static void ice_vsi_set_num_qs(struct ice_vsi *vsi, u16 vf_id)
298 struct ice_pf *pf = vsi->back;
299 struct ice_vf *vf = NULL;
301 if (vsi->type == ICE_VSI_VF)
306 vsi->alloc_txq = pf->num_lan_tx;
307 vsi->alloc_rxq = pf->num_lan_rx;
308 vsi->num_q_vectors = max_t(int, pf->num_lan_rx, pf->num_lan_tx);
311 vf = &pf->vf[vsi->vf_id];
312 vsi->alloc_txq = vf->num_vf_qs;
313 vsi->alloc_rxq = vf->num_vf_qs;
314 /* pf->num_vf_msix includes (VF miscellaneous vector +
315 * data queue interrupts). Since vsi->num_q_vectors is number
316 * of queues vectors, subtract 1 from the original vector
319 vsi->num_q_vectors = pf->num_vf_msix - 1;
322 dev_warn(&pf->pdev->dev, "Unknown VSI type %d\n", vsi->type);
326 ice_vsi_set_num_desc(vsi);
330 * ice_get_free_slot - get the next non-NULL location index in array
331 * @array: array to search
332 * @size: size of the array
333 * @curr: last known occupied index to be used as a search hint
335 * void * is being used to keep the functionality generic. This lets us use this
336 * function on any array of pointers.
338 static int ice_get_free_slot(void *array, int size, int curr)
340 int **tmp_array = (int **)array;
343 if (curr < (size - 1) && !tmp_array[curr + 1]) {
348 while ((i < size) && (tmp_array[i]))
359 * ice_vsi_delete - delete a VSI from the switch
360 * @vsi: pointer to VSI being removed
362 void ice_vsi_delete(struct ice_vsi *vsi)
364 struct ice_pf *pf = vsi->back;
365 struct ice_vsi_ctx *ctxt;
366 enum ice_status status;
368 ctxt = devm_kzalloc(&pf->pdev->dev, sizeof(*ctxt), GFP_KERNEL);
372 if (vsi->type == ICE_VSI_VF)
373 ctxt->vf_num = vsi->vf_id;
374 ctxt->vsi_num = vsi->vsi_num;
376 memcpy(&ctxt->info, &vsi->info, sizeof(ctxt->info));
378 status = ice_free_vsi(&pf->hw, vsi->idx, ctxt, false, NULL);
380 dev_err(&pf->pdev->dev, "Failed to delete VSI %i in FW\n",
383 devm_kfree(&pf->pdev->dev, ctxt);
387 * ice_vsi_free_arrays - De-allocate queue and vector pointer arrays for the VSI
388 * @vsi: pointer to VSI being cleared
390 static void ice_vsi_free_arrays(struct ice_vsi *vsi)
392 struct ice_pf *pf = vsi->back;
394 /* free the ring and vector containers */
395 if (vsi->q_vectors) {
396 devm_kfree(&pf->pdev->dev, vsi->q_vectors);
397 vsi->q_vectors = NULL;
400 devm_kfree(&pf->pdev->dev, vsi->tx_rings);
401 vsi->tx_rings = NULL;
404 devm_kfree(&pf->pdev->dev, vsi->rx_rings);
405 vsi->rx_rings = NULL;
410 * ice_vsi_clear - clean up and deallocate the provided VSI
411 * @vsi: pointer to VSI being cleared
413 * This deallocates the VSI's queue resources, removes it from the PF's
414 * VSI array if necessary, and deallocates the VSI
416 * Returns 0 on success, negative on failure
418 int ice_vsi_clear(struct ice_vsi *vsi)
420 struct ice_pf *pf = NULL;
430 if (!pf->vsi[vsi->idx] || pf->vsi[vsi->idx] != vsi) {
431 dev_dbg(&pf->pdev->dev, "vsi does not exist at pf->vsi[%d]\n",
436 mutex_lock(&pf->sw_mutex);
437 /* updates the PF for this cleared VSI */
439 pf->vsi[vsi->idx] = NULL;
440 if (vsi->idx < pf->next_vsi)
441 pf->next_vsi = vsi->idx;
443 ice_vsi_free_arrays(vsi);
444 mutex_unlock(&pf->sw_mutex);
445 devm_kfree(&pf->pdev->dev, vsi);
451 * ice_msix_clean_rings - MSIX mode Interrupt Handler
452 * @irq: interrupt number
453 * @data: pointer to a q_vector
455 static irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data)
457 struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
459 if (!q_vector->tx.ring && !q_vector->rx.ring)
462 napi_schedule(&q_vector->napi);
468 * ice_vsi_alloc - Allocates the next available struct VSI in the PF
469 * @pf: board private structure
471 * @vf_id: ID of the VF being configured
473 * returns a pointer to a VSI on success, NULL on failure.
475 static struct ice_vsi *
476 ice_vsi_alloc(struct ice_pf *pf, enum ice_vsi_type type, u16 vf_id)
478 struct ice_vsi *vsi = NULL;
480 /* Need to protect the allocation of the VSIs at the PF level */
481 mutex_lock(&pf->sw_mutex);
483 /* If we have already allocated our maximum number of VSIs,
484 * pf->next_vsi will be ICE_NO_VSI. If not, pf->next_vsi index
485 * is available to be populated
487 if (pf->next_vsi == ICE_NO_VSI) {
488 dev_dbg(&pf->pdev->dev, "out of VSI slots!\n");
492 vsi = devm_kzalloc(&pf->pdev->dev, sizeof(*vsi), GFP_KERNEL);
498 set_bit(__ICE_DOWN, vsi->state);
499 vsi->idx = pf->next_vsi;
500 vsi->work_lmt = ICE_DFLT_IRQ_WORK;
502 if (type == ICE_VSI_VF)
503 ice_vsi_set_num_qs(vsi, vf_id);
505 ice_vsi_set_num_qs(vsi, ICE_INVAL_VFID);
509 if (ice_vsi_alloc_arrays(vsi))
512 /* Setup default MSIX irq handler for VSI */
513 vsi->irq_handler = ice_msix_clean_rings;
516 if (ice_vsi_alloc_arrays(vsi))
520 dev_warn(&pf->pdev->dev, "Unknown VSI type %d\n", vsi->type);
524 /* fill VSI slot in the PF struct */
525 pf->vsi[pf->next_vsi] = vsi;
527 /* prepare pf->next_vsi for next use */
528 pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi,
533 devm_kfree(&pf->pdev->dev, vsi);
536 mutex_unlock(&pf->sw_mutex);
541 * __ice_vsi_get_qs_contig - Assign a contiguous chunk of queues to VSI
542 * @qs_cfg: gathered variables needed for PF->VSI queues assignment
544 * Return 0 on success and -ENOMEM in case of no left space in PF queue bitmap
546 static int __ice_vsi_get_qs_contig(struct ice_qs_cfg *qs_cfg)
550 mutex_lock(qs_cfg->qs_mutex);
551 offset = bitmap_find_next_zero_area(qs_cfg->pf_map, qs_cfg->pf_map_size,
552 0, qs_cfg->q_count, 0);
553 if (offset >= qs_cfg->pf_map_size) {
554 mutex_unlock(qs_cfg->qs_mutex);
558 bitmap_set(qs_cfg->pf_map, offset, qs_cfg->q_count);
559 for (i = 0; i < qs_cfg->q_count; i++)
560 qs_cfg->vsi_map[i + qs_cfg->vsi_map_offset] = i + offset;
561 mutex_unlock(qs_cfg->qs_mutex);
567 * __ice_vsi_get_qs_sc - Assign a scattered queues from PF to VSI
568 * @qs_cfg: gathered variables needed for pf->vsi queues assignment
570 * Return 0 on success and -ENOMEM in case of no left space in PF queue bitmap
572 static int __ice_vsi_get_qs_sc(struct ice_qs_cfg *qs_cfg)
576 mutex_lock(qs_cfg->qs_mutex);
577 for (i = 0; i < qs_cfg->q_count; i++) {
578 index = find_next_zero_bit(qs_cfg->pf_map,
579 qs_cfg->pf_map_size, index);
580 if (index >= qs_cfg->pf_map_size)
582 set_bit(index, qs_cfg->pf_map);
583 qs_cfg->vsi_map[i + qs_cfg->vsi_map_offset] = index;
585 mutex_unlock(qs_cfg->qs_mutex);
589 for (index = 0; index < i; index++) {
590 clear_bit(qs_cfg->vsi_map[index], qs_cfg->pf_map);
591 qs_cfg->vsi_map[index + qs_cfg->vsi_map_offset] = 0;
593 mutex_unlock(qs_cfg->qs_mutex);
599 * __ice_vsi_get_qs - helper function for assigning queues from PF to VSI
600 * @qs_cfg: gathered variables needed for pf->vsi queues assignment
602 * This function first tries to find contiguous space. If it is not successful,
603 * it tries with the scatter approach.
605 * Return 0 on success and -ENOMEM in case of no left space in PF queue bitmap
607 static int __ice_vsi_get_qs(struct ice_qs_cfg *qs_cfg)
611 ret = __ice_vsi_get_qs_contig(qs_cfg);
613 /* contig failed, so try with scatter approach */
614 qs_cfg->mapping_mode = ICE_VSI_MAP_SCATTER;
615 qs_cfg->q_count = min_t(u16, qs_cfg->q_count,
616 qs_cfg->scatter_count);
617 ret = __ice_vsi_get_qs_sc(qs_cfg);
623 * ice_vsi_get_qs - Assign queues from PF to VSI
624 * @vsi: the VSI to assign queues to
626 * Returns 0 on success and a negative value on error
628 static int ice_vsi_get_qs(struct ice_vsi *vsi)
630 struct ice_pf *pf = vsi->back;
631 struct ice_qs_cfg tx_qs_cfg = {
632 .qs_mutex = &pf->avail_q_mutex,
633 .pf_map = pf->avail_txqs,
634 .pf_map_size = ICE_MAX_TXQS,
635 .q_count = vsi->alloc_txq,
636 .scatter_count = ICE_MAX_SCATTER_TXQS,
637 .vsi_map = vsi->txq_map,
639 .mapping_mode = vsi->tx_mapping_mode
641 struct ice_qs_cfg rx_qs_cfg = {
642 .qs_mutex = &pf->avail_q_mutex,
643 .pf_map = pf->avail_rxqs,
644 .pf_map_size = ICE_MAX_RXQS,
645 .q_count = vsi->alloc_rxq,
646 .scatter_count = ICE_MAX_SCATTER_RXQS,
647 .vsi_map = vsi->rxq_map,
649 .mapping_mode = vsi->rx_mapping_mode
653 vsi->tx_mapping_mode = ICE_VSI_MAP_CONTIG;
654 vsi->rx_mapping_mode = ICE_VSI_MAP_CONTIG;
656 ret = __ice_vsi_get_qs(&tx_qs_cfg);
658 ret = __ice_vsi_get_qs(&rx_qs_cfg);
664 * ice_vsi_put_qs - Release queues from VSI to PF
665 * @vsi: the VSI that is going to release queues
667 void ice_vsi_put_qs(struct ice_vsi *vsi)
669 struct ice_pf *pf = vsi->back;
672 mutex_lock(&pf->avail_q_mutex);
674 for (i = 0; i < vsi->alloc_txq; i++) {
675 clear_bit(vsi->txq_map[i], pf->avail_txqs);
676 vsi->txq_map[i] = ICE_INVAL_Q_INDEX;
679 for (i = 0; i < vsi->alloc_rxq; i++) {
680 clear_bit(vsi->rxq_map[i], pf->avail_rxqs);
681 vsi->rxq_map[i] = ICE_INVAL_Q_INDEX;
684 mutex_unlock(&pf->avail_q_mutex);
688 * ice_rss_clean - Delete RSS related VSI structures that hold user inputs
689 * @vsi: the VSI being removed
691 static void ice_rss_clean(struct ice_vsi *vsi)
697 if (vsi->rss_hkey_user)
698 devm_kfree(&pf->pdev->dev, vsi->rss_hkey_user);
699 if (vsi->rss_lut_user)
700 devm_kfree(&pf->pdev->dev, vsi->rss_lut_user);
704 * ice_vsi_set_rss_params - Setup RSS capabilities per VSI type
705 * @vsi: the VSI being configured
707 static void ice_vsi_set_rss_params(struct ice_vsi *vsi)
709 struct ice_hw_common_caps *cap;
710 struct ice_pf *pf = vsi->back;
712 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
717 cap = &pf->hw.func_caps.common_cap;
720 /* PF VSI will inherit RSS instance of PF */
721 vsi->rss_table_size = cap->rss_table_size;
722 vsi->rss_size = min_t(int, num_online_cpus(),
723 BIT(cap->rss_table_entry_width));
724 vsi->rss_lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
727 /* VF VSI will gets a small RSS table
728 * For VSI_LUT, LUT size should be set to 64 bytes
730 vsi->rss_table_size = ICE_VSIQF_HLUT_ARRAY_SIZE;
731 vsi->rss_size = min_t(int, num_online_cpus(),
732 BIT(cap->rss_table_entry_width));
733 vsi->rss_lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_VSI;
736 dev_warn(&pf->pdev->dev, "Unknown VSI type %d\n",
743 * ice_set_dflt_vsi_ctx - Set default VSI context before adding a VSI
744 * @ctxt: the VSI context being set
746 * This initializes a default VSI context for all sections except the Queues.
748 static void ice_set_dflt_vsi_ctx(struct ice_vsi_ctx *ctxt)
752 memset(&ctxt->info, 0, sizeof(ctxt->info));
753 /* VSI's should be allocated from shared pool */
754 ctxt->alloc_from_pool = true;
755 /* Src pruning enabled by default */
756 ctxt->info.sw_flags = ICE_AQ_VSI_SW_FLAG_SRC_PRUNE;
757 /* Traffic from VSI can be sent to LAN */
758 ctxt->info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
759 /* By default bits 3 and 4 in vlan_flags are 0's which results in legacy
760 * behavior (show VLAN, DEI, and UP) in descriptor. Also, allow all
761 * packets untagged/tagged.
763 ctxt->info.vlan_flags = ((ICE_AQ_VSI_VLAN_MODE_ALL &
764 ICE_AQ_VSI_VLAN_MODE_M) >>
765 ICE_AQ_VSI_VLAN_MODE_S);
766 /* Have 1:1 UP mapping for both ingress/egress tables */
767 table |= ICE_UP_TABLE_TRANSLATE(0, 0);
768 table |= ICE_UP_TABLE_TRANSLATE(1, 1);
769 table |= ICE_UP_TABLE_TRANSLATE(2, 2);
770 table |= ICE_UP_TABLE_TRANSLATE(3, 3);
771 table |= ICE_UP_TABLE_TRANSLATE(4, 4);
772 table |= ICE_UP_TABLE_TRANSLATE(5, 5);
773 table |= ICE_UP_TABLE_TRANSLATE(6, 6);
774 table |= ICE_UP_TABLE_TRANSLATE(7, 7);
775 ctxt->info.ingress_table = cpu_to_le32(table);
776 ctxt->info.egress_table = cpu_to_le32(table);
777 /* Have 1:1 UP mapping for outer to inner UP table */
778 ctxt->info.outer_up_table = cpu_to_le32(table);
779 /* No Outer tag support outer_tag_flags remains to zero */
783 * ice_vsi_setup_q_map - Setup a VSI queue map
784 * @vsi: the VSI being configured
785 * @ctxt: VSI context structure
787 static void ice_vsi_setup_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctxt)
789 u16 offset = 0, qmap = 0, tx_count = 0;
790 u16 qcount_tx = vsi->alloc_txq;
791 u16 qcount_rx = vsi->alloc_rxq;
792 u16 tx_numq_tc, rx_numq_tc;
793 u16 pow = 0, max_rss = 0;
794 bool ena_tc0 = false;
798 /* at least TC0 should be enabled by default */
799 if (vsi->tc_cfg.numtc) {
800 if (!(vsi->tc_cfg.ena_tc & BIT(0)))
808 vsi->tc_cfg.ena_tc |= 1;
811 rx_numq_tc = qcount_rx / vsi->tc_cfg.numtc;
814 tx_numq_tc = qcount_tx / vsi->tc_cfg.numtc;
818 /* TC mapping is a function of the number of Rx queues assigned to the
819 * VSI for each traffic class and the offset of these queues.
820 * The first 10 bits are for queue offset for TC0, next 4 bits for no:of
821 * queues allocated to TC0. No:of queues is a power-of-2.
823 * If TC is not enabled, the queue offset is set to 0, and allocate one
824 * queue, this way, traffic for the given TC will be sent to the default
827 * Setup number and offset of Rx queues for all TCs for the VSI
830 qcount_rx = rx_numq_tc;
832 /* qcount will change if RSS is enabled */
833 if (test_bit(ICE_FLAG_RSS_ENA, vsi->back->flags)) {
834 if (vsi->type == ICE_VSI_PF || vsi->type == ICE_VSI_VF) {
835 if (vsi->type == ICE_VSI_PF)
836 max_rss = ICE_MAX_LG_RSS_QS;
838 max_rss = ICE_MAX_SMALL_RSS_QS;
839 qcount_rx = min_t(int, rx_numq_tc, max_rss);
840 qcount_rx = min_t(int, qcount_rx, vsi->rss_size);
844 /* find the (rounded up) power-of-2 of qcount */
845 pow = order_base_2(qcount_rx);
847 ice_for_each_traffic_class(i) {
848 if (!(vsi->tc_cfg.ena_tc & BIT(i))) {
849 /* TC is not enabled */
850 vsi->tc_cfg.tc_info[i].qoffset = 0;
851 vsi->tc_cfg.tc_info[i].qcount_rx = 1;
852 vsi->tc_cfg.tc_info[i].qcount_tx = 1;
853 vsi->tc_cfg.tc_info[i].netdev_tc = 0;
854 ctxt->info.tc_mapping[i] = 0;
859 vsi->tc_cfg.tc_info[i].qoffset = offset;
860 vsi->tc_cfg.tc_info[i].qcount_rx = qcount_rx;
861 vsi->tc_cfg.tc_info[i].qcount_tx = tx_numq_tc;
862 vsi->tc_cfg.tc_info[i].netdev_tc = netdev_tc++;
864 qmap = ((offset << ICE_AQ_VSI_TC_Q_OFFSET_S) &
865 ICE_AQ_VSI_TC_Q_OFFSET_M) |
866 ((pow << ICE_AQ_VSI_TC_Q_NUM_S) &
867 ICE_AQ_VSI_TC_Q_NUM_M);
869 tx_count += tx_numq_tc;
870 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
873 /* if offset is non-zero, means it is calculated correctly based on
874 * enabled TCs for a given VSI otherwise qcount_rx will always
875 * be correct and non-zero because it is based off - VSI's
876 * allocated Rx queues which is at least 1 (hence qcount_tx will be
880 vsi->num_rxq = offset;
882 vsi->num_rxq = qcount_rx;
884 vsi->num_txq = tx_count;
886 if (vsi->type == ICE_VSI_VF && vsi->num_txq != vsi->num_rxq) {
887 dev_dbg(&vsi->back->pdev->dev, "VF VSI should have same number of Tx and Rx queues. Hence making them equal\n");
888 /* since there is a chance that num_rxq could have been changed
889 * in the above for loop, make num_txq equal to num_rxq.
891 vsi->num_txq = vsi->num_rxq;
894 /* Rx queue mapping */
895 ctxt->info.mapping_flags |= cpu_to_le16(ICE_AQ_VSI_Q_MAP_CONTIG);
896 /* q_mapping buffer holds the info for the first queue allocated for
897 * this VSI in the PF space and also the number of queues associated
900 ctxt->info.q_mapping[0] = cpu_to_le16(vsi->rxq_map[0]);
901 ctxt->info.q_mapping[1] = cpu_to_le16(vsi->num_rxq);
905 * ice_set_rss_vsi_ctx - Set RSS VSI context before adding a VSI
906 * @ctxt: the VSI context being set
907 * @vsi: the VSI being configured
909 static void ice_set_rss_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
911 u8 lut_type, hash_type;
918 /* PF VSI will inherit RSS instance of PF */
919 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_PF;
920 hash_type = ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
923 /* VF VSI will gets a small RSS table which is a VSI LUT type */
924 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI;
925 hash_type = ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
928 dev_warn(&pf->pdev->dev, "Unknown VSI type %d\n", vsi->type);
932 ctxt->info.q_opt_rss = ((lut_type << ICE_AQ_VSI_Q_OPT_RSS_LUT_S) &
933 ICE_AQ_VSI_Q_OPT_RSS_LUT_M) |
934 ((hash_type << ICE_AQ_VSI_Q_OPT_RSS_HASH_S) &
935 ICE_AQ_VSI_Q_OPT_RSS_HASH_M);
939 * ice_vsi_init - Create and initialize a VSI
940 * @vsi: the VSI being configured
942 * This initializes a VSI context depending on the VSI type to be added and
943 * passes it down to the add_vsi aq command to create a new VSI.
945 static int ice_vsi_init(struct ice_vsi *vsi)
947 struct ice_pf *pf = vsi->back;
948 struct ice_hw *hw = &pf->hw;
949 struct ice_vsi_ctx *ctxt;
952 ctxt = devm_kzalloc(&pf->pdev->dev, sizeof(*ctxt), GFP_KERNEL);
956 ctxt->info = vsi->info;
959 ctxt->flags = ICE_AQ_VSI_TYPE_PF;
962 ctxt->flags = ICE_AQ_VSI_TYPE_VF;
963 /* VF number here is the absolute VF number (0-255) */
964 ctxt->vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
970 ice_set_dflt_vsi_ctx(ctxt);
971 /* if the switch is in VEB mode, allow VSI loopback */
972 if (vsi->vsw->bridge_mode == BRIDGE_MODE_VEB)
973 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
975 /* Set LUT type and HASH type if RSS is enabled */
976 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
977 ice_set_rss_vsi_ctx(ctxt, vsi);
979 ctxt->info.sw_id = vsi->port_info->sw_id;
980 ice_vsi_setup_q_map(vsi, ctxt);
982 /* Enable MAC Antispoof with new VSI being initialized or updated */
983 if (vsi->type == ICE_VSI_VF && pf->vf[vsi->vf_id].spoofchk) {
984 ctxt->info.valid_sections |=
985 cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID);
986 ctxt->info.sec_flags |=
987 ICE_AQ_VSI_SEC_FLAG_ENA_MAC_ANTI_SPOOF;
990 ret = ice_add_vsi(hw, vsi->idx, ctxt, NULL);
992 dev_err(&pf->pdev->dev,
993 "Add VSI failed, err %d\n", ret);
997 /* keep context for update VSI operations */
998 vsi->info = ctxt->info;
1000 /* record VSI number returned */
1001 vsi->vsi_num = ctxt->vsi_num;
1003 devm_kfree(&pf->pdev->dev, ctxt);
1008 * ice_free_q_vector - Free memory allocated for a specific interrupt vector
1009 * @vsi: VSI having the memory freed
1010 * @v_idx: index of the vector to be freed
1012 static void ice_free_q_vector(struct ice_vsi *vsi, int v_idx)
1014 struct ice_q_vector *q_vector;
1015 struct ice_pf *pf = vsi->back;
1016 struct ice_ring *ring;
1018 if (!vsi->q_vectors[v_idx]) {
1019 dev_dbg(&pf->pdev->dev, "Queue vector at index %d not found\n",
1023 q_vector = vsi->q_vectors[v_idx];
1025 ice_for_each_ring(ring, q_vector->tx)
1026 ring->q_vector = NULL;
1027 ice_for_each_ring(ring, q_vector->rx)
1028 ring->q_vector = NULL;
1030 /* only VSI with an associated netdev is set up with NAPI */
1032 netif_napi_del(&q_vector->napi);
1034 devm_kfree(&pf->pdev->dev, q_vector);
1035 vsi->q_vectors[v_idx] = NULL;
1039 * ice_vsi_free_q_vectors - Free memory allocated for interrupt vectors
1040 * @vsi: the VSI having memory freed
1042 void ice_vsi_free_q_vectors(struct ice_vsi *vsi)
1046 ice_for_each_q_vector(vsi, v_idx)
1047 ice_free_q_vector(vsi, v_idx);
1051 * ice_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
1052 * @vsi: the VSI being configured
1053 * @v_idx: index of the vector in the VSI struct
1055 * We allocate one q_vector. If allocation fails we return -ENOMEM.
1057 static int ice_vsi_alloc_q_vector(struct ice_vsi *vsi, int v_idx)
1059 struct ice_pf *pf = vsi->back;
1060 struct ice_q_vector *q_vector;
1062 /* allocate q_vector */
1063 q_vector = devm_kzalloc(&pf->pdev->dev, sizeof(*q_vector), GFP_KERNEL);
1067 q_vector->vsi = vsi;
1068 q_vector->v_idx = v_idx;
1069 if (vsi->type == ICE_VSI_VF)
1071 /* only set affinity_mask if the CPU is online */
1072 if (cpu_online(v_idx))
1073 cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
1075 /* This will not be called in the driver load path because the netdev
1076 * will not be created yet. All other cases with register the NAPI
1077 * handler here (i.e. resume, reset/rebuild, etc.)
1080 netif_napi_add(vsi->netdev, &q_vector->napi, ice_napi_poll,
1084 /* tie q_vector and VSI together */
1085 vsi->q_vectors[v_idx] = q_vector;
1091 * ice_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
1092 * @vsi: the VSI being configured
1094 * We allocate one q_vector per queue interrupt. If allocation fails we
1097 static int ice_vsi_alloc_q_vectors(struct ice_vsi *vsi)
1099 struct ice_pf *pf = vsi->back;
1100 int v_idx = 0, num_q_vectors;
1103 if (vsi->q_vectors[0]) {
1104 dev_dbg(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
1109 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
1110 num_q_vectors = vsi->num_q_vectors;
1116 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
1117 err = ice_vsi_alloc_q_vector(vsi, v_idx);
1126 ice_free_q_vector(vsi, v_idx);
1128 dev_err(&pf->pdev->dev,
1129 "Failed to allocate %d q_vector for VSI %d, ret=%d\n",
1130 vsi->num_q_vectors, vsi->vsi_num, err);
1131 vsi->num_q_vectors = 0;
1136 * ice_vsi_setup_vector_base - Set up the base vector for the given VSI
1137 * @vsi: ptr to the VSI
1139 * This should only be called after ice_vsi_alloc() which allocates the
1140 * corresponding SW VSI structure and initializes num_queue_pairs for the
1141 * newly allocated VSI.
1143 * Returns 0 on success or negative on failure
1145 static int ice_vsi_setup_vector_base(struct ice_vsi *vsi)
1147 struct ice_pf *pf = vsi->back;
1148 int num_q_vectors = 0;
1150 if (vsi->sw_base_vector || vsi->hw_base_vector) {
1151 dev_dbg(&pf->pdev->dev, "VSI %d has non-zero HW base vector %d or SW base vector %d\n",
1152 vsi->vsi_num, vsi->hw_base_vector, vsi->sw_base_vector);
1156 if (!test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
1159 switch (vsi->type) {
1161 num_q_vectors = vsi->num_q_vectors;
1162 /* reserve slots from OS requested IRQs */
1163 vsi->sw_base_vector = ice_get_res(pf, pf->sw_irq_tracker,
1164 num_q_vectors, vsi->idx);
1165 if (vsi->sw_base_vector < 0) {
1166 dev_err(&pf->pdev->dev,
1167 "Failed to get tracking for %d SW vectors for VSI %d, err=%d\n",
1168 num_q_vectors, vsi->vsi_num,
1169 vsi->sw_base_vector);
1172 pf->num_avail_sw_msix -= num_q_vectors;
1174 /* reserve slots from HW interrupts */
1175 vsi->hw_base_vector = ice_get_res(pf, pf->hw_irq_tracker,
1176 num_q_vectors, vsi->idx);
1179 /* take VF misc vector and data vectors into account */
1180 num_q_vectors = pf->num_vf_msix;
1181 /* For VF VSI, reserve slots only from HW interrupts */
1182 vsi->hw_base_vector = ice_get_res(pf, pf->hw_irq_tracker,
1183 num_q_vectors, vsi->idx);
1186 dev_warn(&pf->pdev->dev, "Unknown VSI type %d\n", vsi->type);
1190 if (vsi->hw_base_vector < 0) {
1191 dev_err(&pf->pdev->dev,
1192 "Failed to get tracking for %d HW vectors for VSI %d, err=%d\n",
1193 num_q_vectors, vsi->vsi_num, vsi->hw_base_vector);
1194 if (vsi->type != ICE_VSI_VF) {
1195 ice_free_res(pf->sw_irq_tracker,
1196 vsi->sw_base_vector, vsi->idx);
1197 pf->num_avail_sw_msix += num_q_vectors;
1202 pf->num_avail_hw_msix -= num_q_vectors;
1208 * ice_vsi_clear_rings - Deallocates the Tx and Rx rings for VSI
1209 * @vsi: the VSI having rings deallocated
1211 static void ice_vsi_clear_rings(struct ice_vsi *vsi)
1215 if (vsi->tx_rings) {
1216 for (i = 0; i < vsi->alloc_txq; i++) {
1217 if (vsi->tx_rings[i]) {
1218 kfree_rcu(vsi->tx_rings[i], rcu);
1219 vsi->tx_rings[i] = NULL;
1223 if (vsi->rx_rings) {
1224 for (i = 0; i < vsi->alloc_rxq; i++) {
1225 if (vsi->rx_rings[i]) {
1226 kfree_rcu(vsi->rx_rings[i], rcu);
1227 vsi->rx_rings[i] = NULL;
1234 * ice_vsi_alloc_rings - Allocates Tx and Rx rings for the VSI
1235 * @vsi: VSI which is having rings allocated
1237 static int ice_vsi_alloc_rings(struct ice_vsi *vsi)
1239 struct ice_pf *pf = vsi->back;
1242 /* Allocate Tx rings */
1243 for (i = 0; i < vsi->alloc_txq; i++) {
1244 struct ice_ring *ring;
1246 /* allocate with kzalloc(), free with kfree_rcu() */
1247 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1253 ring->reg_idx = vsi->txq_map[i];
1254 ring->ring_active = false;
1256 ring->dev = &pf->pdev->dev;
1257 ring->count = vsi->num_tx_desc;
1258 vsi->tx_rings[i] = ring;
1261 /* Allocate Rx rings */
1262 for (i = 0; i < vsi->alloc_rxq; i++) {
1263 struct ice_ring *ring;
1265 /* allocate with kzalloc(), free with kfree_rcu() */
1266 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1271 ring->reg_idx = vsi->rxq_map[i];
1272 ring->ring_active = false;
1274 ring->netdev = vsi->netdev;
1275 ring->dev = &pf->pdev->dev;
1276 ring->count = vsi->num_rx_desc;
1277 vsi->rx_rings[i] = ring;
1283 ice_vsi_clear_rings(vsi);
1288 * ice_vsi_map_rings_to_vectors - Map VSI rings to interrupt vectors
1289 * @vsi: the VSI being configured
1291 * This function maps descriptor rings to the queue-specific vectors allotted
1292 * through the MSI-X enabling code. On a constrained vector budget, we map Tx
1293 * and Rx rings to the vector as "efficiently" as possible.
1296 void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi)
1298 static void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi)
1299 #endif /* CONFIG_DCB */
1301 int q_vectors = vsi->num_q_vectors;
1302 int tx_rings_rem, rx_rings_rem;
1305 /* initially assigning remaining rings count to VSIs num queue value */
1306 tx_rings_rem = vsi->num_txq;
1307 rx_rings_rem = vsi->num_rxq;
1309 for (v_id = 0; v_id < q_vectors; v_id++) {
1310 struct ice_q_vector *q_vector = vsi->q_vectors[v_id];
1311 int tx_rings_per_v, rx_rings_per_v, q_id, q_base;
1313 /* Tx rings mapping to vector */
1314 tx_rings_per_v = DIV_ROUND_UP(tx_rings_rem, q_vectors - v_id);
1315 q_vector->num_ring_tx = tx_rings_per_v;
1316 q_vector->tx.ring = NULL;
1317 q_vector->tx.itr_idx = ICE_TX_ITR;
1318 q_base = vsi->num_txq - tx_rings_rem;
1320 for (q_id = q_base; q_id < (q_base + tx_rings_per_v); q_id++) {
1321 struct ice_ring *tx_ring = vsi->tx_rings[q_id];
1323 tx_ring->q_vector = q_vector;
1324 tx_ring->next = q_vector->tx.ring;
1325 q_vector->tx.ring = tx_ring;
1327 tx_rings_rem -= tx_rings_per_v;
1329 /* Rx rings mapping to vector */
1330 rx_rings_per_v = DIV_ROUND_UP(rx_rings_rem, q_vectors - v_id);
1331 q_vector->num_ring_rx = rx_rings_per_v;
1332 q_vector->rx.ring = NULL;
1333 q_vector->rx.itr_idx = ICE_RX_ITR;
1334 q_base = vsi->num_rxq - rx_rings_rem;
1336 for (q_id = q_base; q_id < (q_base + rx_rings_per_v); q_id++) {
1337 struct ice_ring *rx_ring = vsi->rx_rings[q_id];
1339 rx_ring->q_vector = q_vector;
1340 rx_ring->next = q_vector->rx.ring;
1341 q_vector->rx.ring = rx_ring;
1343 rx_rings_rem -= rx_rings_per_v;
1348 * ice_vsi_manage_rss_lut - disable/enable RSS
1349 * @vsi: the VSI being changed
1350 * @ena: boolean value indicating if this is an enable or disable request
1352 * In the event of disable request for RSS, this function will zero out RSS
1353 * LUT, while in the event of enable request for RSS, it will reconfigure RSS
1356 int ice_vsi_manage_rss_lut(struct ice_vsi *vsi, bool ena)
1361 lut = devm_kzalloc(&vsi->back->pdev->dev, vsi->rss_table_size,
1367 if (vsi->rss_lut_user)
1368 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1370 ice_fill_rss_lut(lut, vsi->rss_table_size,
1374 err = ice_set_rss(vsi, NULL, lut, vsi->rss_table_size);
1375 devm_kfree(&vsi->back->pdev->dev, lut);
1380 * ice_vsi_cfg_rss_lut_key - Configure RSS params for a VSI
1381 * @vsi: VSI to be configured
1383 static int ice_vsi_cfg_rss_lut_key(struct ice_vsi *vsi)
1385 struct ice_aqc_get_set_rss_keys *key;
1386 struct ice_pf *pf = vsi->back;
1387 enum ice_status status;
1391 vsi->rss_size = min_t(int, vsi->rss_size, vsi->num_rxq);
1393 lut = devm_kzalloc(&pf->pdev->dev, vsi->rss_table_size, GFP_KERNEL);
1397 if (vsi->rss_lut_user)
1398 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1400 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
1402 status = ice_aq_set_rss_lut(&pf->hw, vsi->idx, vsi->rss_lut_type, lut,
1403 vsi->rss_table_size);
1406 dev_err(&pf->pdev->dev,
1407 "set_rss_lut failed, error %d\n", status);
1409 goto ice_vsi_cfg_rss_exit;
1412 key = devm_kzalloc(&pf->pdev->dev, sizeof(*key), GFP_KERNEL);
1415 goto ice_vsi_cfg_rss_exit;
1418 if (vsi->rss_hkey_user)
1420 (struct ice_aqc_get_set_rss_keys *)vsi->rss_hkey_user,
1421 ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE);
1423 netdev_rss_key_fill((void *)key,
1424 ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE);
1426 status = ice_aq_set_rss_key(&pf->hw, vsi->idx, key);
1429 dev_err(&pf->pdev->dev, "set_rss_key failed, error %d\n",
1434 devm_kfree(&pf->pdev->dev, key);
1435 ice_vsi_cfg_rss_exit:
1436 devm_kfree(&pf->pdev->dev, lut);
1441 * ice_add_mac_to_list - Add a MAC address filter entry to the list
1442 * @vsi: the VSI to be forwarded to
1443 * @add_list: pointer to the list which contains MAC filter entries
1444 * @macaddr: the MAC address to be added.
1446 * Adds MAC address filter entry to the temp list
1448 * Returns 0 on success or ENOMEM on failure.
1450 int ice_add_mac_to_list(struct ice_vsi *vsi, struct list_head *add_list,
1453 struct ice_fltr_list_entry *tmp;
1454 struct ice_pf *pf = vsi->back;
1456 tmp = devm_kzalloc(&pf->pdev->dev, sizeof(*tmp), GFP_ATOMIC);
1460 tmp->fltr_info.flag = ICE_FLTR_TX;
1461 tmp->fltr_info.src_id = ICE_SRC_ID_VSI;
1462 tmp->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
1463 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1464 tmp->fltr_info.vsi_handle = vsi->idx;
1465 ether_addr_copy(tmp->fltr_info.l_data.mac.mac_addr, macaddr);
1467 INIT_LIST_HEAD(&tmp->list_entry);
1468 list_add(&tmp->list_entry, add_list);
1474 * ice_update_eth_stats - Update VSI-specific ethernet statistics counters
1475 * @vsi: the VSI to be updated
1477 void ice_update_eth_stats(struct ice_vsi *vsi)
1479 struct ice_eth_stats *prev_es, *cur_es;
1480 struct ice_hw *hw = &vsi->back->hw;
1481 u16 vsi_num = vsi->vsi_num; /* HW absolute index of a VSI */
1483 prev_es = &vsi->eth_stats_prev;
1484 cur_es = &vsi->eth_stats;
1486 ice_stat_update40(hw, GLV_GORCH(vsi_num), GLV_GORCL(vsi_num),
1487 vsi->stat_offsets_loaded, &prev_es->rx_bytes,
1490 ice_stat_update40(hw, GLV_UPRCH(vsi_num), GLV_UPRCL(vsi_num),
1491 vsi->stat_offsets_loaded, &prev_es->rx_unicast,
1492 &cur_es->rx_unicast);
1494 ice_stat_update40(hw, GLV_MPRCH(vsi_num), GLV_MPRCL(vsi_num),
1495 vsi->stat_offsets_loaded, &prev_es->rx_multicast,
1496 &cur_es->rx_multicast);
1498 ice_stat_update40(hw, GLV_BPRCH(vsi_num), GLV_BPRCL(vsi_num),
1499 vsi->stat_offsets_loaded, &prev_es->rx_broadcast,
1500 &cur_es->rx_broadcast);
1502 ice_stat_update32(hw, GLV_RDPC(vsi_num), vsi->stat_offsets_loaded,
1503 &prev_es->rx_discards, &cur_es->rx_discards);
1505 ice_stat_update40(hw, GLV_GOTCH(vsi_num), GLV_GOTCL(vsi_num),
1506 vsi->stat_offsets_loaded, &prev_es->tx_bytes,
1509 ice_stat_update40(hw, GLV_UPTCH(vsi_num), GLV_UPTCL(vsi_num),
1510 vsi->stat_offsets_loaded, &prev_es->tx_unicast,
1511 &cur_es->tx_unicast);
1513 ice_stat_update40(hw, GLV_MPTCH(vsi_num), GLV_MPTCL(vsi_num),
1514 vsi->stat_offsets_loaded, &prev_es->tx_multicast,
1515 &cur_es->tx_multicast);
1517 ice_stat_update40(hw, GLV_BPTCH(vsi_num), GLV_BPTCL(vsi_num),
1518 vsi->stat_offsets_loaded, &prev_es->tx_broadcast,
1519 &cur_es->tx_broadcast);
1521 ice_stat_update32(hw, GLV_TEPC(vsi_num), vsi->stat_offsets_loaded,
1522 &prev_es->tx_errors, &cur_es->tx_errors);
1524 vsi->stat_offsets_loaded = true;
1528 * ice_free_fltr_list - free filter lists helper
1529 * @dev: pointer to the device struct
1530 * @h: pointer to the list head to be freed
1532 * Helper function to free filter lists previously created using
1533 * ice_add_mac_to_list
1535 void ice_free_fltr_list(struct device *dev, struct list_head *h)
1537 struct ice_fltr_list_entry *e, *tmp;
1539 list_for_each_entry_safe(e, tmp, h, list_entry) {
1540 list_del(&e->list_entry);
1546 * ice_vsi_add_vlan - Add VSI membership for given VLAN
1547 * @vsi: the VSI being configured
1548 * @vid: VLAN ID to be added
1550 int ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid)
1552 struct ice_fltr_list_entry *tmp;
1553 struct ice_pf *pf = vsi->back;
1554 LIST_HEAD(tmp_add_list);
1555 enum ice_status status;
1558 tmp = devm_kzalloc(&pf->pdev->dev, sizeof(*tmp), GFP_KERNEL);
1562 tmp->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
1563 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1564 tmp->fltr_info.flag = ICE_FLTR_TX;
1565 tmp->fltr_info.src_id = ICE_SRC_ID_VSI;
1566 tmp->fltr_info.vsi_handle = vsi->idx;
1567 tmp->fltr_info.l_data.vlan.vlan_id = vid;
1569 INIT_LIST_HEAD(&tmp->list_entry);
1570 list_add(&tmp->list_entry, &tmp_add_list);
1572 status = ice_add_vlan(&pf->hw, &tmp_add_list);
1575 dev_err(&pf->pdev->dev, "Failure Adding VLAN %d on VSI %i\n",
1579 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
1584 * ice_vsi_kill_vlan - Remove VSI membership for a given VLAN
1585 * @vsi: the VSI being configured
1586 * @vid: VLAN ID to be removed
1588 * Returns 0 on success and negative on failure
1590 int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid)
1592 struct ice_fltr_list_entry *list;
1593 struct ice_pf *pf = vsi->back;
1594 LIST_HEAD(tmp_add_list);
1595 enum ice_status status;
1598 list = devm_kzalloc(&pf->pdev->dev, sizeof(*list), GFP_KERNEL);
1602 list->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
1603 list->fltr_info.vsi_handle = vsi->idx;
1604 list->fltr_info.fltr_act = ICE_FWD_TO_VSI;
1605 list->fltr_info.l_data.vlan.vlan_id = vid;
1606 list->fltr_info.flag = ICE_FLTR_TX;
1607 list->fltr_info.src_id = ICE_SRC_ID_VSI;
1609 INIT_LIST_HEAD(&list->list_entry);
1610 list_add(&list->list_entry, &tmp_add_list);
1612 status = ice_remove_vlan(&pf->hw, &tmp_add_list);
1613 if (status == ICE_ERR_DOES_NOT_EXIST) {
1614 dev_dbg(&pf->pdev->dev,
1615 "Failed to remove VLAN %d on VSI %i, it does not exist, status: %d\n",
1616 vid, vsi->vsi_num, status);
1617 } else if (status) {
1618 dev_err(&pf->pdev->dev,
1619 "Error removing VLAN %d on vsi %i error: %d\n",
1620 vid, vsi->vsi_num, status);
1624 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
1629 * ice_vsi_cfg_rxqs - Configure the VSI for Rx
1630 * @vsi: the VSI being configured
1632 * Return 0 on success and a negative value on error
1633 * Configure the Rx VSI for operation.
1635 int ice_vsi_cfg_rxqs(struct ice_vsi *vsi)
1639 if (vsi->type == ICE_VSI_VF)
1642 if (vsi->netdev && vsi->netdev->mtu > ETH_DATA_LEN)
1643 vsi->max_frame = vsi->netdev->mtu +
1644 ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
1646 vsi->max_frame = ICE_RXBUF_2048;
1648 vsi->rx_buf_len = ICE_RXBUF_2048;
1650 /* set up individual rings */
1651 for (i = 0; i < vsi->num_rxq; i++) {
1654 err = ice_setup_rx_ctx(vsi->rx_rings[i]);
1656 dev_err(&vsi->back->pdev->dev,
1657 "ice_setup_rx_ctx failed for RxQ %d, err %d\n",
1667 * ice_vsi_cfg_txqs - Configure the VSI for Tx
1668 * @vsi: the VSI being configured
1669 * @rings: Tx ring array to be configured
1670 * @offset: offset within vsi->txq_map
1672 * Return 0 on success and a negative value on error
1673 * Configure the Tx VSI for operation.
1676 ice_vsi_cfg_txqs(struct ice_vsi *vsi, struct ice_ring **rings, int offset)
1678 struct ice_aqc_add_tx_qgrp *qg_buf;
1679 struct ice_aqc_add_txqs_perq *txq;
1680 struct ice_pf *pf = vsi->back;
1681 u8 num_q_grps, q_idx = 0;
1682 enum ice_status status;
1683 u16 buf_len, i, pf_q;
1686 buf_len = sizeof(*qg_buf);
1687 qg_buf = devm_kzalloc(&pf->pdev->dev, buf_len, GFP_KERNEL);
1691 qg_buf->num_txqs = 1;
1694 /* set up and configure the Tx queues for each enabled TC */
1695 ice_for_each_traffic_class(tc) {
1696 if (!(vsi->tc_cfg.ena_tc & BIT(tc)))
1699 for (i = 0; i < vsi->tc_cfg.tc_info[tc].qcount_tx; i++) {
1700 struct ice_tlan_ctx tlan_ctx = { 0 };
1702 pf_q = vsi->txq_map[q_idx + offset];
1703 ice_setup_tx_ctx(rings[q_idx], &tlan_ctx, pf_q);
1704 /* copy context contents into the qg_buf */
1705 qg_buf->txqs[0].txq_id = cpu_to_le16(pf_q);
1706 ice_set_ctx((u8 *)&tlan_ctx, qg_buf->txqs[0].txq_ctx,
1709 /* init queue specific tail reg. It is referred as
1710 * transmit comm scheduler queue doorbell.
1712 rings[q_idx]->tail =
1713 pf->hw.hw_addr + QTX_COMM_DBELL(pf_q);
1714 status = ice_ena_vsi_txq(vsi->port_info, vsi->idx, tc,
1715 i, num_q_grps, qg_buf,
1718 dev_err(&pf->pdev->dev,
1719 "Failed to set LAN Tx queue context, error: %d\n",
1725 /* Add Tx Queue TEID into the VSI Tx ring from the
1726 * response. This will complete configuring and
1727 * enabling the queue.
1729 txq = &qg_buf->txqs[0];
1730 if (pf_q == le16_to_cpu(txq->txq_id))
1731 rings[q_idx]->txq_teid =
1732 le32_to_cpu(txq->q_teid);
1738 devm_kfree(&pf->pdev->dev, qg_buf);
1743 * ice_vsi_cfg_lan_txqs - Configure the VSI for Tx
1744 * @vsi: the VSI being configured
1746 * Return 0 on success and a negative value on error
1747 * Configure the Tx VSI for operation.
1749 int ice_vsi_cfg_lan_txqs(struct ice_vsi *vsi)
1751 return ice_vsi_cfg_txqs(vsi, vsi->tx_rings, 0);
1755 * ice_intrl_usec_to_reg - convert interrupt rate limit to register value
1756 * @intrl: interrupt rate limit in usecs
1757 * @gran: interrupt rate limit granularity in usecs
1759 * This function converts a decimal interrupt rate limit in usecs to the format
1760 * expected by firmware.
1762 u32 ice_intrl_usec_to_reg(u8 intrl, u8 gran)
1764 u32 val = intrl / gran;
1767 return val | GLINT_RATE_INTRL_ENA_M;
1772 * ice_cfg_itr_gran - set the ITR granularity to 2 usecs if not already set
1773 * @hw: board specific structure
1775 static void ice_cfg_itr_gran(struct ice_hw *hw)
1777 u32 regval = rd32(hw, GLINT_CTL);
1779 /* no need to update global register if ITR gran is already set */
1780 if (!(regval & GLINT_CTL_DIS_AUTOMASK_M) &&
1781 (((regval & GLINT_CTL_ITR_GRAN_200_M) >>
1782 GLINT_CTL_ITR_GRAN_200_S) == ICE_ITR_GRAN_US) &&
1783 (((regval & GLINT_CTL_ITR_GRAN_100_M) >>
1784 GLINT_CTL_ITR_GRAN_100_S) == ICE_ITR_GRAN_US) &&
1785 (((regval & GLINT_CTL_ITR_GRAN_50_M) >>
1786 GLINT_CTL_ITR_GRAN_50_S) == ICE_ITR_GRAN_US) &&
1787 (((regval & GLINT_CTL_ITR_GRAN_25_M) >>
1788 GLINT_CTL_ITR_GRAN_25_S) == ICE_ITR_GRAN_US))
1791 regval = ((ICE_ITR_GRAN_US << GLINT_CTL_ITR_GRAN_200_S) &
1792 GLINT_CTL_ITR_GRAN_200_M) |
1793 ((ICE_ITR_GRAN_US << GLINT_CTL_ITR_GRAN_100_S) &
1794 GLINT_CTL_ITR_GRAN_100_M) |
1795 ((ICE_ITR_GRAN_US << GLINT_CTL_ITR_GRAN_50_S) &
1796 GLINT_CTL_ITR_GRAN_50_M) |
1797 ((ICE_ITR_GRAN_US << GLINT_CTL_ITR_GRAN_25_S) &
1798 GLINT_CTL_ITR_GRAN_25_M);
1799 wr32(hw, GLINT_CTL, regval);
1803 * ice_cfg_itr - configure the initial interrupt throttle values
1804 * @hw: pointer to the HW structure
1805 * @q_vector: interrupt vector that's being configured
1807 * Configure interrupt throttling values for the ring containers that are
1808 * associated with the interrupt vector passed in.
1811 ice_cfg_itr(struct ice_hw *hw, struct ice_q_vector *q_vector)
1813 ice_cfg_itr_gran(hw);
1815 if (q_vector->num_ring_rx) {
1816 struct ice_ring_container *rc = &q_vector->rx;
1818 /* if this value is set then don't overwrite with default */
1819 if (!rc->itr_setting)
1820 rc->itr_setting = ICE_DFLT_RX_ITR;
1822 rc->target_itr = ITR_TO_REG(rc->itr_setting);
1823 rc->next_update = jiffies + 1;
1824 rc->current_itr = rc->target_itr;
1825 wr32(hw, GLINT_ITR(rc->itr_idx, q_vector->reg_idx),
1826 ITR_REG_ALIGN(rc->current_itr) >> ICE_ITR_GRAN_S);
1829 if (q_vector->num_ring_tx) {
1830 struct ice_ring_container *rc = &q_vector->tx;
1832 /* if this value is set then don't overwrite with default */
1833 if (!rc->itr_setting)
1834 rc->itr_setting = ICE_DFLT_TX_ITR;
1836 rc->target_itr = ITR_TO_REG(rc->itr_setting);
1837 rc->next_update = jiffies + 1;
1838 rc->current_itr = rc->target_itr;
1839 wr32(hw, GLINT_ITR(rc->itr_idx, q_vector->reg_idx),
1840 ITR_REG_ALIGN(rc->current_itr) >> ICE_ITR_GRAN_S);
1845 * ice_vsi_cfg_msix - MSIX mode Interrupt Config in the HW
1846 * @vsi: the VSI being configured
1848 void ice_vsi_cfg_msix(struct ice_vsi *vsi)
1850 struct ice_pf *pf = vsi->back;
1851 struct ice_hw *hw = &pf->hw;
1852 u32 txq = 0, rxq = 0;
1855 for (i = 0; i < vsi->num_q_vectors; i++) {
1856 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1857 u16 reg_idx = q_vector->reg_idx;
1859 if (vsi->type != ICE_VSI_VF)
1860 ice_cfg_itr(hw, q_vector);
1862 wr32(hw, GLINT_RATE(reg_idx),
1863 ice_intrl_usec_to_reg(q_vector->intrl, hw->intrl_gran));
1865 /* Both Transmit Queue Interrupt Cause Control register
1866 * and Receive Queue Interrupt Cause control register
1867 * expects MSIX_INDX field to be the vector index
1868 * within the function space and not the absolute
1869 * vector index across PF or across device.
1870 * For SR-IOV VF VSIs queue vector index always starts
1871 * with 1 since first vector index(0) is used for OICR
1872 * in VF space. Since VMDq and other PF VSIs are within
1873 * the PF function space, use the vector index that is
1874 * tracked for this PF.
1876 for (q = 0; q < q_vector->num_ring_tx; q++) {
1877 int itr_idx = (q_vector->tx.itr_idx <<
1878 QINT_TQCTL_ITR_INDX_S) &
1879 QINT_TQCTL_ITR_INDX_M;
1882 if (vsi->type == ICE_VSI_VF)
1883 val = QINT_TQCTL_CAUSE_ENA_M | itr_idx |
1884 (((i + 1) << QINT_TQCTL_MSIX_INDX_S) &
1885 QINT_TQCTL_MSIX_INDX_M);
1887 val = QINT_TQCTL_CAUSE_ENA_M | itr_idx |
1888 ((reg_idx << QINT_TQCTL_MSIX_INDX_S) &
1889 QINT_TQCTL_MSIX_INDX_M);
1890 wr32(hw, QINT_TQCTL(vsi->txq_map[txq]), val);
1894 for (q = 0; q < q_vector->num_ring_rx; q++) {
1895 int itr_idx = (q_vector->rx.itr_idx <<
1896 QINT_RQCTL_ITR_INDX_S) &
1897 QINT_RQCTL_ITR_INDX_M;
1900 if (vsi->type == ICE_VSI_VF)
1901 val = QINT_RQCTL_CAUSE_ENA_M | itr_idx |
1902 (((i + 1) << QINT_RQCTL_MSIX_INDX_S) &
1903 QINT_RQCTL_MSIX_INDX_M);
1905 val = QINT_RQCTL_CAUSE_ENA_M | itr_idx |
1906 ((reg_idx << QINT_RQCTL_MSIX_INDX_S) &
1907 QINT_RQCTL_MSIX_INDX_M);
1908 wr32(hw, QINT_RQCTL(vsi->rxq_map[rxq]), val);
1917 * ice_vsi_manage_vlan_insertion - Manage VLAN insertion for the VSI for Tx
1918 * @vsi: the VSI being changed
1920 int ice_vsi_manage_vlan_insertion(struct ice_vsi *vsi)
1922 struct device *dev = &vsi->back->pdev->dev;
1923 struct ice_hw *hw = &vsi->back->hw;
1924 struct ice_vsi_ctx *ctxt;
1925 enum ice_status status;
1928 ctxt = devm_kzalloc(dev, sizeof(*ctxt), GFP_KERNEL);
1932 /* Here we are configuring the VSI to let the driver add VLAN tags by
1933 * setting vlan_flags to ICE_AQ_VSI_VLAN_MODE_ALL. The actual VLAN tag
1934 * insertion happens in the Tx hot path, in ice_tx_map.
1936 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_MODE_ALL;
1938 /* Preserve existing VLAN strip setting */
1939 ctxt->info.vlan_flags |= (vsi->info.vlan_flags &
1940 ICE_AQ_VSI_VLAN_EMOD_M);
1942 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
1944 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1946 dev_err(dev, "update VSI for VLAN insert failed, err %d aq_err %d\n",
1947 status, hw->adminq.sq_last_status);
1952 vsi->info.vlan_flags = ctxt->info.vlan_flags;
1954 devm_kfree(dev, ctxt);
1959 * ice_vsi_manage_vlan_stripping - Manage VLAN stripping for the VSI for Rx
1960 * @vsi: the VSI being changed
1961 * @ena: boolean value indicating if this is a enable or disable request
1963 int ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
1965 struct device *dev = &vsi->back->pdev->dev;
1966 struct ice_hw *hw = &vsi->back->hw;
1967 struct ice_vsi_ctx *ctxt;
1968 enum ice_status status;
1971 ctxt = devm_kzalloc(dev, sizeof(*ctxt), GFP_KERNEL);
1975 /* Here we are configuring what the VSI should do with the VLAN tag in
1976 * the Rx packet. We can either leave the tag in the packet or put it in
1977 * the Rx descriptor.
1980 /* Strip VLAN tag from Rx packet and put it in the desc */
1981 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_STR_BOTH;
1983 /* Disable stripping. Leave tag in packet */
1984 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_NOTHING;
1986 /* Allow all packets untagged/tagged */
1987 ctxt->info.vlan_flags |= ICE_AQ_VSI_VLAN_MODE_ALL;
1989 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
1991 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1993 dev_err(dev, "update VSI for VLAN strip failed, ena = %d err %d aq_err %d\n",
1994 ena, status, hw->adminq.sq_last_status);
1999 vsi->info.vlan_flags = ctxt->info.vlan_flags;
2001 devm_kfree(dev, ctxt);
2006 * ice_vsi_start_rx_rings - start VSI's Rx rings
2007 * @vsi: the VSI whose rings are to be started
2009 * Returns 0 on success and a negative value on error
2011 int ice_vsi_start_rx_rings(struct ice_vsi *vsi)
2013 return ice_vsi_ctrl_rx_rings(vsi, true);
2017 * ice_vsi_stop_rx_rings - stop VSI's Rx rings
2020 * Returns 0 on success and a negative value on error
2022 int ice_vsi_stop_rx_rings(struct ice_vsi *vsi)
2024 return ice_vsi_ctrl_rx_rings(vsi, false);
2028 * ice_vsi_stop_tx_rings - Disable Tx rings
2029 * @vsi: the VSI being configured
2030 * @rst_src: reset source
2031 * @rel_vmvf_num: Relative ID of VF/VM
2032 * @rings: Tx ring array to be stopped
2033 * @offset: offset within vsi->txq_map
2036 ice_vsi_stop_tx_rings(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
2037 u16 rel_vmvf_num, struct ice_ring **rings, int offset)
2039 struct ice_pf *pf = vsi->back;
2040 struct ice_hw *hw = &pf->hw;
2041 int tc, q_idx = 0, err = 0;
2042 u16 *q_ids, *q_handles, i;
2043 enum ice_status status;
2046 if (vsi->num_txq > ICE_LAN_TXQ_MAX_QDIS)
2049 q_teids = devm_kcalloc(&pf->pdev->dev, vsi->num_txq, sizeof(*q_teids),
2054 q_ids = devm_kcalloc(&pf->pdev->dev, vsi->num_txq, sizeof(*q_ids),
2058 goto err_alloc_q_ids;
2061 q_handles = devm_kcalloc(&pf->pdev->dev, vsi->num_txq,
2062 sizeof(*q_handles), GFP_KERNEL);
2065 goto err_alloc_q_handles;
2068 /* set up the Tx queue list to be disabled for each enabled TC */
2069 ice_for_each_traffic_class(tc) {
2070 if (!(vsi->tc_cfg.ena_tc & BIT(tc)))
2073 for (i = 0; i < vsi->tc_cfg.tc_info[tc].qcount_tx; i++) {
2074 if (!rings || !rings[q_idx] ||
2075 !rings[q_idx]->q_vector) {
2080 q_ids[i] = vsi->txq_map[q_idx + offset];
2081 q_teids[i] = rings[q_idx]->txq_teid;
2084 /* clear cause_ena bit for disabled queues */
2085 val = rd32(hw, QINT_TQCTL(rings[i]->reg_idx));
2086 val &= ~QINT_TQCTL_CAUSE_ENA_M;
2087 wr32(hw, QINT_TQCTL(rings[i]->reg_idx), val);
2089 /* software is expected to wait for 100 ns */
2092 /* trigger a software interrupt for the vector
2093 * associated to the queue to schedule NAPI handler
2095 wr32(hw, GLINT_DYN_CTL(rings[i]->q_vector->reg_idx),
2096 GLINT_DYN_CTL_SWINT_TRIG_M |
2097 GLINT_DYN_CTL_INTENA_MSK_M);
2100 status = ice_dis_vsi_txq(vsi->port_info, vsi->idx, tc,
2101 vsi->num_txq, q_handles, q_ids,
2102 q_teids, rst_src, rel_vmvf_num, NULL);
2104 /* if the disable queue command was exercised during an active
2105 * reset flow, ICE_ERR_RESET_ONGOING is returned. This is not
2106 * an error as the reset operation disables queues at the
2107 * hardware level anyway.
2109 if (status == ICE_ERR_RESET_ONGOING) {
2110 dev_dbg(&pf->pdev->dev,
2111 "Reset in progress. LAN Tx queues already disabled\n");
2112 } else if (status) {
2113 dev_err(&pf->pdev->dev,
2114 "Failed to disable LAN Tx queues, error: %d\n",
2121 devm_kfree(&pf->pdev->dev, q_handles);
2123 err_alloc_q_handles:
2124 devm_kfree(&pf->pdev->dev, q_ids);
2127 devm_kfree(&pf->pdev->dev, q_teids);
2133 * ice_vsi_stop_lan_tx_rings - Disable LAN Tx rings
2134 * @vsi: the VSI being configured
2135 * @rst_src: reset source
2136 * @rel_vmvf_num: Relative ID of VF/VM
2139 ice_vsi_stop_lan_tx_rings(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
2142 return ice_vsi_stop_tx_rings(vsi, rst_src, rel_vmvf_num, vsi->tx_rings,
2147 * ice_cfg_vlan_pruning - enable or disable VLAN pruning on the VSI
2148 * @vsi: VSI to enable or disable VLAN pruning on
2149 * @ena: set to true to enable VLAN pruning and false to disable it
2150 * @vlan_promisc: enable valid security flags if not in VLAN promiscuous mode
2152 * returns 0 if VSI is updated, negative otherwise
2154 int ice_cfg_vlan_pruning(struct ice_vsi *vsi, bool ena, bool vlan_promisc)
2156 struct ice_vsi_ctx *ctxt;
2165 dev = &pf->pdev->dev;
2166 ctxt = devm_kzalloc(dev, sizeof(*ctxt), GFP_KERNEL);
2170 ctxt->info = vsi->info;
2173 ctxt->info.sec_flags |=
2174 ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
2175 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S;
2176 ctxt->info.sw_flags2 |= ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
2178 ctxt->info.sec_flags &=
2179 ~(ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
2180 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S);
2181 ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
2185 ctxt->info.valid_sections =
2186 cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID |
2187 ICE_AQ_VSI_PROP_SW_VALID);
2189 status = ice_update_vsi(&pf->hw, vsi->idx, ctxt, NULL);
2191 netdev_err(vsi->netdev, "%sabling VLAN pruning on VSI handle: %d, VSI HW ID: %d failed, err = %d, aq_err = %d\n",
2192 ena ? "En" : "Dis", vsi->idx, vsi->vsi_num, status,
2193 pf->hw.adminq.sq_last_status);
2197 vsi->info.sec_flags = ctxt->info.sec_flags;
2198 vsi->info.sw_flags2 = ctxt->info.sw_flags2;
2200 devm_kfree(dev, ctxt);
2204 devm_kfree(dev, ctxt);
2208 static void ice_vsi_set_tc_cfg(struct ice_vsi *vsi)
2210 struct ice_dcbx_cfg *cfg = &vsi->port_info->local_dcbx_cfg;
2212 vsi->tc_cfg.ena_tc = ice_dcb_get_ena_tc(cfg);
2213 vsi->tc_cfg.numtc = ice_dcb_get_num_tc(cfg);
2217 * ice_vsi_set_q_vectors_reg_idx - set the HW register index for all q_vectors
2218 * @vsi: VSI to set the q_vectors register index on
2221 ice_vsi_set_q_vectors_reg_idx(struct ice_vsi *vsi)
2225 if (!vsi || !vsi->q_vectors)
2228 ice_for_each_q_vector(vsi, i) {
2229 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2232 dev_err(&vsi->back->pdev->dev,
2233 "Failed to set reg_idx on q_vector %d VSI %d\n",
2238 q_vector->reg_idx = q_vector->v_idx + vsi->hw_base_vector;
2244 ice_for_each_q_vector(vsi, i) {
2245 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2248 q_vector->reg_idx = 0;
2255 * ice_vsi_add_rem_eth_mac - Program VSI ethertype based filter with rule
2256 * @vsi: the VSI being configured
2257 * @add_rule: boolean value to add or remove ethertype filter rule
2260 ice_vsi_add_rem_eth_mac(struct ice_vsi *vsi, bool add_rule)
2262 struct ice_fltr_list_entry *list;
2263 struct ice_pf *pf = vsi->back;
2264 LIST_HEAD(tmp_add_list);
2265 enum ice_status status;
2267 list = devm_kzalloc(&pf->pdev->dev, sizeof(*list), GFP_KERNEL);
2271 list->fltr_info.lkup_type = ICE_SW_LKUP_ETHERTYPE;
2272 list->fltr_info.fltr_act = ICE_DROP_PACKET;
2273 list->fltr_info.flag = ICE_FLTR_TX;
2274 list->fltr_info.src_id = ICE_SRC_ID_VSI;
2275 list->fltr_info.vsi_handle = vsi->idx;
2276 list->fltr_info.l_data.ethertype_mac.ethertype = vsi->ethtype;
2278 INIT_LIST_HEAD(&list->list_entry);
2279 list_add(&list->list_entry, &tmp_add_list);
2282 status = ice_add_eth_mac(&pf->hw, &tmp_add_list);
2284 status = ice_remove_eth_mac(&pf->hw, &tmp_add_list);
2287 dev_err(&pf->pdev->dev,
2288 "Failure Adding or Removing Ethertype on VSI %i error: %d\n",
2289 vsi->vsi_num, status);
2291 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
2295 * ice_vsi_setup - Set up a VSI by a given type
2296 * @pf: board private structure
2297 * @pi: pointer to the port_info instance
2299 * @vf_id: defines VF ID to which this VSI connects. This field is meant to be
2300 * used only for ICE_VSI_VF VSI type. For other VSI types, should
2301 * fill-in ICE_INVAL_VFID as input.
2303 * This allocates the sw VSI structure and its queue resources.
2305 * Returns pointer to the successfully allocated and configured VSI sw struct on
2306 * success, NULL on failure.
2309 ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
2310 enum ice_vsi_type type, u16 vf_id)
2312 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2313 struct device *dev = &pf->pdev->dev;
2314 struct ice_vsi *vsi;
2317 if (type == ICE_VSI_VF)
2318 vsi = ice_vsi_alloc(pf, type, vf_id);
2320 vsi = ice_vsi_alloc(pf, type, ICE_INVAL_VFID);
2323 dev_err(dev, "could not allocate VSI\n");
2327 vsi->port_info = pi;
2328 vsi->vsw = pf->first_sw;
2329 if (vsi->type == ICE_VSI_PF)
2330 vsi->ethtype = ETH_P_PAUSE;
2332 if (vsi->type == ICE_VSI_VF)
2335 if (ice_vsi_get_qs(vsi)) {
2336 dev_err(dev, "Failed to allocate queues. vsi->idx = %d\n",
2341 /* set RSS capabilities */
2342 ice_vsi_set_rss_params(vsi);
2344 /* set TC configuration */
2345 ice_vsi_set_tc_cfg(vsi);
2347 /* create the VSI */
2348 ret = ice_vsi_init(vsi);
2352 switch (vsi->type) {
2354 ret = ice_vsi_alloc_q_vectors(vsi);
2356 goto unroll_vsi_init;
2358 ret = ice_vsi_setup_vector_base(vsi);
2360 goto unroll_alloc_q_vector;
2362 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2364 goto unroll_vector_base;
2366 ret = ice_vsi_alloc_rings(vsi);
2368 goto unroll_vector_base;
2370 ice_vsi_map_rings_to_vectors(vsi);
2372 /* Do not exit if configuring RSS had an issue, at least
2373 * receive traffic on first queue. Hence no need to capture
2376 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2377 ice_vsi_cfg_rss_lut_key(vsi);
2380 /* VF driver will take care of creating netdev for this type and
2381 * map queues to vectors through Virtchnl, PF driver only
2382 * creates a VSI and corresponding structures for bookkeeping
2385 ret = ice_vsi_alloc_q_vectors(vsi);
2387 goto unroll_vsi_init;
2389 ret = ice_vsi_alloc_rings(vsi);
2391 goto unroll_alloc_q_vector;
2393 /* Setup Vector base only during VF init phase or when VF asks
2394 * for more vectors than assigned number. In all other cases,
2395 * assign hw_base_vector to the value given earlier.
2397 if (test_bit(ICE_VF_STATE_CFG_INTR, pf->vf[vf_id].vf_states)) {
2398 ret = ice_vsi_setup_vector_base(vsi);
2400 goto unroll_vector_base;
2402 vsi->hw_base_vector = pf->vf[vf_id].first_vector_idx;
2404 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2406 goto unroll_vector_base;
2408 pf->q_left_tx -= vsi->alloc_txq;
2409 pf->q_left_rx -= vsi->alloc_rxq;
2412 /* clean up the resources and exit */
2413 goto unroll_vsi_init;
2416 /* configure VSI nodes based on number of queues and TC's */
2417 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2418 max_txqs[i] = pf->num_lan_tx;
2420 ret = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2423 dev_err(&pf->pdev->dev,
2424 "VSI %d failed lan queue config, error %d\n",
2426 goto unroll_vector_base;
2429 /* Add switch rule to drop all Tx Flow Control Frames, of look up
2430 * type ETHERTYPE from VSIs, and restrict malicious VF from sending
2431 * out PAUSE or PFC frames. If enabled, FW can still send FC frames.
2432 * The rule is added once for PF VSI in order to create appropriate
2433 * recipe, since VSI/VSI list is ignored with drop action...
2435 if (vsi->type == ICE_VSI_PF)
2436 ice_vsi_add_rem_eth_mac(vsi, true);
2441 /* reclaim SW interrupts back to the common pool */
2442 ice_free_res(pf->sw_irq_tracker, vsi->sw_base_vector, vsi->idx);
2443 pf->num_avail_sw_msix += vsi->num_q_vectors;
2444 /* reclaim HW interrupt back to the common pool */
2445 ice_free_res(pf->hw_irq_tracker, vsi->hw_base_vector, vsi->idx);
2446 pf->num_avail_hw_msix += vsi->num_q_vectors;
2447 unroll_alloc_q_vector:
2448 ice_vsi_free_q_vectors(vsi);
2450 ice_vsi_delete(vsi);
2452 ice_vsi_put_qs(vsi);
2453 pf->q_left_tx += vsi->alloc_txq;
2454 pf->q_left_rx += vsi->alloc_rxq;
2461 * ice_vsi_release_msix - Clear the queue to Interrupt mapping in HW
2462 * @vsi: the VSI being cleaned up
2464 static void ice_vsi_release_msix(struct ice_vsi *vsi)
2466 struct ice_pf *pf = vsi->back;
2467 u16 vector = vsi->hw_base_vector;
2468 struct ice_hw *hw = &pf->hw;
2473 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
2474 struct ice_q_vector *q_vector = vsi->q_vectors[i];
2476 wr32(hw, GLINT_ITR(ICE_IDX_ITR0, vector), 0);
2477 wr32(hw, GLINT_ITR(ICE_IDX_ITR1, vector), 0);
2478 for (q = 0; q < q_vector->num_ring_tx; q++) {
2479 wr32(hw, QINT_TQCTL(vsi->txq_map[txq]), 0);
2483 for (q = 0; q < q_vector->num_ring_rx; q++) {
2484 wr32(hw, QINT_RQCTL(vsi->rxq_map[rxq]), 0);
2493 * ice_vsi_free_irq - Free the IRQ association with the OS
2494 * @vsi: the VSI being configured
2496 void ice_vsi_free_irq(struct ice_vsi *vsi)
2498 struct ice_pf *pf = vsi->back;
2499 int base = vsi->sw_base_vector;
2501 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
2504 if (!vsi->q_vectors || !vsi->irqs_ready)
2507 ice_vsi_release_msix(vsi);
2508 if (vsi->type == ICE_VSI_VF)
2511 vsi->irqs_ready = false;
2512 ice_for_each_q_vector(vsi, i) {
2513 u16 vector = i + base;
2516 irq_num = pf->msix_entries[vector].vector;
2518 /* free only the irqs that were actually requested */
2519 if (!vsi->q_vectors[i] ||
2520 !(vsi->q_vectors[i]->num_ring_tx ||
2521 vsi->q_vectors[i]->num_ring_rx))
2524 /* clear the affinity notifier in the IRQ descriptor */
2525 irq_set_affinity_notifier(irq_num, NULL);
2527 /* clear the affinity_mask in the IRQ descriptor */
2528 irq_set_affinity_hint(irq_num, NULL);
2529 synchronize_irq(irq_num);
2530 devm_free_irq(&pf->pdev->dev, irq_num,
2537 * ice_vsi_free_tx_rings - Free Tx resources for VSI queues
2538 * @vsi: the VSI having resources freed
2540 void ice_vsi_free_tx_rings(struct ice_vsi *vsi)
2547 ice_for_each_txq(vsi, i)
2548 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
2549 ice_free_tx_ring(vsi->tx_rings[i]);
2553 * ice_vsi_free_rx_rings - Free Rx resources for VSI queues
2554 * @vsi: the VSI having resources freed
2556 void ice_vsi_free_rx_rings(struct ice_vsi *vsi)
2563 ice_for_each_rxq(vsi, i)
2564 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
2565 ice_free_rx_ring(vsi->rx_rings[i]);
2569 * ice_vsi_close - Shut down a VSI
2570 * @vsi: the VSI being shut down
2572 void ice_vsi_close(struct ice_vsi *vsi)
2574 if (!test_and_set_bit(__ICE_DOWN, vsi->state))
2577 ice_vsi_free_irq(vsi);
2578 ice_vsi_free_tx_rings(vsi);
2579 ice_vsi_free_rx_rings(vsi);
2583 * ice_free_res - free a block of resources
2584 * @res: pointer to the resource
2585 * @index: starting index previously returned by ice_get_res
2586 * @id: identifier to track owner
2588 * Returns number of resources freed
2590 int ice_free_res(struct ice_res_tracker *res, u16 index, u16 id)
2595 if (!res || index >= res->num_entries)
2598 id |= ICE_RES_VALID_BIT;
2599 for (i = index; i < res->num_entries && res->list[i] == id; i++) {
2608 * ice_search_res - Search the tracker for a block of resources
2609 * @res: pointer to the resource
2610 * @needed: size of the block needed
2611 * @id: identifier to track owner
2613 * Returns the base item index of the block, or -ENOMEM for error
2615 static int ice_search_res(struct ice_res_tracker *res, u16 needed, u16 id)
2617 int start = res->search_hint;
2620 if ((start + needed) > res->num_entries)
2623 id |= ICE_RES_VALID_BIT;
2626 /* skip already allocated entries */
2627 if (res->list[end++] & ICE_RES_VALID_BIT) {
2629 if ((start + needed) > res->num_entries)
2633 if (end == (start + needed)) {
2636 /* there was enough, so assign it to the requestor */
2638 res->list[i++] = id;
2640 if (end == res->num_entries)
2643 res->search_hint = end;
2652 * ice_get_res - get a block of resources
2653 * @pf: board private structure
2654 * @res: pointer to the resource
2655 * @needed: size of the block needed
2656 * @id: identifier to track owner
2658 * Returns the base item index of the block, or -ENOMEM for error
2659 * The search_hint trick and lack of advanced fit-finding only works
2660 * because we're highly likely to have all the same sized requests.
2661 * Linear search time and any fragmentation should be minimal.
2664 ice_get_res(struct ice_pf *pf, struct ice_res_tracker *res, u16 needed, u16 id)
2671 if (!needed || needed > res->num_entries || id >= ICE_RES_VALID_BIT) {
2672 dev_err(&pf->pdev->dev,
2673 "param err: needed=%d, num_entries = %d id=0x%04x\n",
2674 needed, res->num_entries, id);
2678 /* search based on search_hint */
2679 ret = ice_search_res(res, needed, id);
2682 /* previous search failed. Reset search hint and try again */
2683 res->search_hint = 0;
2684 ret = ice_search_res(res, needed, id);
2691 * ice_vsi_dis_irq - Mask off queue interrupt generation on the VSI
2692 * @vsi: the VSI being un-configured
2694 void ice_vsi_dis_irq(struct ice_vsi *vsi)
2696 int base = vsi->sw_base_vector;
2697 struct ice_pf *pf = vsi->back;
2698 struct ice_hw *hw = &pf->hw;
2702 /* disable interrupt causation from each queue */
2703 if (vsi->tx_rings) {
2704 ice_for_each_txq(vsi, i) {
2705 if (vsi->tx_rings[i]) {
2708 reg = vsi->tx_rings[i]->reg_idx;
2709 val = rd32(hw, QINT_TQCTL(reg));
2710 val &= ~QINT_TQCTL_CAUSE_ENA_M;
2711 wr32(hw, QINT_TQCTL(reg), val);
2716 if (vsi->rx_rings) {
2717 ice_for_each_rxq(vsi, i) {
2718 if (vsi->rx_rings[i]) {
2721 reg = vsi->rx_rings[i]->reg_idx;
2722 val = rd32(hw, QINT_RQCTL(reg));
2723 val &= ~QINT_RQCTL_CAUSE_ENA_M;
2724 wr32(hw, QINT_RQCTL(reg), val);
2729 /* disable each interrupt */
2730 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
2731 ice_for_each_q_vector(vsi, i)
2732 wr32(hw, GLINT_DYN_CTL(vsi->q_vectors[i]->reg_idx), 0);
2736 ice_for_each_q_vector(vsi, i)
2737 synchronize_irq(pf->msix_entries[i + base].vector);
2742 * ice_vsi_release - Delete a VSI and free its resources
2743 * @vsi: the VSI being removed
2745 * Returns 0 on success or < 0 on error
2747 int ice_vsi_release(struct ice_vsi *vsi)
2749 struct ice_vf *vf = NULL;
2756 if (vsi->type == ICE_VSI_VF)
2757 vf = &pf->vf[vsi->vf_id];
2758 /* do not unregister while driver is in the reset recovery pending
2759 * state. Since reset/rebuild happens through PF service task workqueue,
2760 * it's not a good idea to unregister netdev that is associated to the
2761 * PF that is running the work queue items currently. This is done to
2762 * avoid check_flush_dependency() warning on this wq
2764 if (vsi->netdev && !ice_is_reset_in_progress(pf->state))
2765 unregister_netdev(vsi->netdev);
2767 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2770 /* Disable VSI and free resources */
2771 ice_vsi_dis_irq(vsi);
2774 /* reclaim interrupt vectors back to PF */
2775 if (vsi->type != ICE_VSI_VF) {
2776 /* reclaim SW interrupts back to the common pool */
2777 ice_free_res(pf->sw_irq_tracker, vsi->sw_base_vector, vsi->idx);
2778 pf->num_avail_sw_msix += vsi->num_q_vectors;
2779 /* reclaim HW interrupts back to the common pool */
2780 ice_free_res(pf->hw_irq_tracker, vsi->hw_base_vector, vsi->idx);
2781 pf->num_avail_hw_msix += vsi->num_q_vectors;
2782 } else if (test_bit(ICE_VF_STATE_CFG_INTR, vf->vf_states)) {
2783 /* Reclaim VF resources back only while freeing all VFs or
2784 * vector reassignment is requested
2786 ice_free_res(pf->hw_irq_tracker, vf->first_vector_idx,
2788 pf->num_avail_hw_msix += pf->num_vf_msix;
2791 if (vsi->type == ICE_VSI_PF)
2792 ice_vsi_add_rem_eth_mac(vsi, false);
2794 ice_remove_vsi_fltr(&pf->hw, vsi->idx);
2795 ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx);
2796 ice_vsi_delete(vsi);
2797 ice_vsi_free_q_vectors(vsi);
2799 /* make sure unregister_netdev() was called by checking __ICE_DOWN */
2800 if (vsi->netdev && test_bit(__ICE_DOWN, vsi->state)) {
2801 free_netdev(vsi->netdev);
2805 ice_vsi_clear_rings(vsi);
2807 ice_vsi_put_qs(vsi);
2808 pf->q_left_tx += vsi->alloc_txq;
2809 pf->q_left_rx += vsi->alloc_rxq;
2811 /* retain SW VSI data structure since it is needed to unregister and
2812 * free VSI netdev when PF is not in reset recovery pending state,\
2813 * for ex: during rmmod.
2815 if (!ice_is_reset_in_progress(pf->state))
2822 * ice_vsi_rebuild - Rebuild VSI after reset
2823 * @vsi: VSI to be rebuild
2825 * Returns 0 on success and negative value on failure
2827 int ice_vsi_rebuild(struct ice_vsi *vsi)
2829 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2830 struct ice_vf *vf = NULL;
2838 if (vsi->type == ICE_VSI_VF)
2839 vf = &pf->vf[vsi->vf_id];
2841 ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx);
2842 ice_vsi_free_q_vectors(vsi);
2844 if (vsi->type != ICE_VSI_VF) {
2845 /* reclaim SW interrupts back to the common pool */
2846 ice_free_res(pf->sw_irq_tracker, vsi->sw_base_vector, vsi->idx);
2847 pf->num_avail_sw_msix += vsi->num_q_vectors;
2848 vsi->sw_base_vector = 0;
2849 /* reclaim HW interrupts back to the common pool */
2850 ice_free_res(pf->hw_irq_tracker, vsi->hw_base_vector,
2852 pf->num_avail_hw_msix += vsi->num_q_vectors;
2854 /* Reclaim VF resources back to the common pool for reset and
2855 * and rebuild, with vector reassignment
2857 ice_free_res(pf->hw_irq_tracker, vf->first_vector_idx,
2859 pf->num_avail_hw_msix += pf->num_vf_msix;
2861 vsi->hw_base_vector = 0;
2863 ice_vsi_clear_rings(vsi);
2864 ice_vsi_free_arrays(vsi);
2865 ice_dev_onetime_setup(&pf->hw);
2866 if (vsi->type == ICE_VSI_VF)
2867 ice_vsi_set_num_qs(vsi, vf->vf_id);
2869 ice_vsi_set_num_qs(vsi, ICE_INVAL_VFID);
2870 ice_vsi_set_tc_cfg(vsi);
2872 /* Initialize VSI struct elements and create VSI in FW */
2873 ret = ice_vsi_init(vsi);
2877 ret = ice_vsi_alloc_arrays(vsi);
2881 switch (vsi->type) {
2883 ret = ice_vsi_alloc_q_vectors(vsi);
2887 ret = ice_vsi_setup_vector_base(vsi);
2891 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2895 ret = ice_vsi_alloc_rings(vsi);
2899 ice_vsi_map_rings_to_vectors(vsi);
2900 /* Do not exit if configuring RSS had an issue, at least
2901 * receive traffic on first queue. Hence no need to capture
2904 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2905 ice_vsi_cfg_rss_lut_key(vsi);
2908 ret = ice_vsi_alloc_q_vectors(vsi);
2912 ret = ice_vsi_setup_vector_base(vsi);
2916 ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2920 ret = ice_vsi_alloc_rings(vsi);
2924 pf->q_left_tx -= vsi->alloc_txq;
2925 pf->q_left_rx -= vsi->alloc_rxq;
2931 /* configure VSI nodes based on number of queues and TC's */
2932 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2933 max_txqs[i] = pf->num_lan_tx;
2935 ret = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2938 dev_err(&pf->pdev->dev,
2939 "VSI %d failed lan queue config, error %d\n",
2946 ice_vsi_free_q_vectors(vsi);
2949 vsi->current_netdev_flags = 0;
2950 unregister_netdev(vsi->netdev);
2951 free_netdev(vsi->netdev);
2956 set_bit(__ICE_RESET_FAILED, pf->state);
2961 * ice_is_reset_in_progress - check for a reset in progress
2962 * @state: pf state field
2964 bool ice_is_reset_in_progress(unsigned long *state)
2966 return test_bit(__ICE_RESET_OICR_RECV, state) ||
2967 test_bit(__ICE_PFR_REQ, state) ||
2968 test_bit(__ICE_CORER_REQ, state) ||
2969 test_bit(__ICE_GLOBR_REQ, state);
2974 * ice_vsi_update_q_map - update our copy of the VSI info with new queue map
2975 * @vsi: VSI being configured
2976 * @ctx: the context buffer returned from AQ VSI update command
2978 static void ice_vsi_update_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctx)
2980 vsi->info.mapping_flags = ctx->info.mapping_flags;
2981 memcpy(&vsi->info.q_mapping, &ctx->info.q_mapping,
2982 sizeof(vsi->info.q_mapping));
2983 memcpy(&vsi->info.tc_mapping, ctx->info.tc_mapping,
2984 sizeof(vsi->info.tc_mapping));
2988 * ice_vsi_cfg_netdev_tc - Setup the netdev TC configuration
2989 * @vsi: the VSI being configured
2990 * @ena_tc: TC map to be enabled
2992 static void ice_vsi_cfg_netdev_tc(struct ice_vsi *vsi, u8 ena_tc)
2994 struct net_device *netdev = vsi->netdev;
2995 struct ice_pf *pf = vsi->back;
2996 struct ice_dcbx_cfg *dcbcfg;
3004 netdev_reset_tc(netdev);
3008 if (netdev_set_num_tc(netdev, vsi->tc_cfg.numtc))
3011 dcbcfg = &pf->hw.port_info->local_dcbx_cfg;
3013 ice_for_each_traffic_class(i)
3014 if (vsi->tc_cfg.ena_tc & BIT(i))
3015 netdev_set_tc_queue(netdev,
3016 vsi->tc_cfg.tc_info[i].netdev_tc,
3017 vsi->tc_cfg.tc_info[i].qcount_tx,
3018 vsi->tc_cfg.tc_info[i].qoffset);
3020 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
3021 u8 ets_tc = dcbcfg->etscfg.prio_table[i];
3023 /* Get the mapped netdev TC# for the UP */
3024 netdev_tc = vsi->tc_cfg.tc_info[ets_tc].netdev_tc;
3025 netdev_set_prio_tc_map(netdev, i, netdev_tc);
3030 * ice_vsi_cfg_tc - Configure VSI Tx Sched for given TC map
3031 * @vsi: VSI to be configured
3032 * @ena_tc: TC bitmap
3034 * VSI queues expected to be quiesced before calling this function
3036 int ice_vsi_cfg_tc(struct ice_vsi *vsi, u8 ena_tc)
3038 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
3039 struct ice_vsi_ctx *ctx;
3040 struct ice_pf *pf = vsi->back;
3041 enum ice_status status;
3045 ice_for_each_traffic_class(i) {
3046 /* build bitmap of enabled TCs */
3047 if (ena_tc & BIT(i))
3049 /* populate max_txqs per TC */
3050 max_txqs[i] = pf->num_lan_tx;
3053 vsi->tc_cfg.ena_tc = ena_tc;
3054 vsi->tc_cfg.numtc = num_tc;
3056 ctx = devm_kzalloc(&pf->pdev->dev, sizeof(*ctx), GFP_KERNEL);
3061 ctx->info = vsi->info;
3063 ice_vsi_setup_q_map(vsi, ctx);
3065 /* must to indicate which section of VSI context are being modified */
3066 ctx->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
3067 status = ice_update_vsi(&pf->hw, vsi->idx, ctx, NULL);
3069 dev_info(&pf->pdev->dev, "Failed VSI Update\n");
3074 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
3078 dev_err(&pf->pdev->dev,
3079 "VSI %d failed TC config, error %d\n",
3080 vsi->vsi_num, status);
3084 ice_vsi_update_q_map(vsi, ctx);
3085 vsi->info.valid_sections = 0;
3087 ice_vsi_cfg_netdev_tc(vsi, ena_tc);
3089 devm_kfree(&pf->pdev->dev, ctx);
3092 #endif /* CONFIG_DCB */