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
235 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
237 * On error: returns error code (negative)
238 * On success: returns 0
240 static int ice_vsi_alloc_arrays(struct ice_vsi
*vsi
, bool alloc_qvectors
)
242 struct ice_pf
*pf
= vsi
->back
;
244 /* allocate memory for both Tx and Rx ring pointers */
245 vsi
->tx_rings
= devm_kcalloc(&pf
->pdev
->dev
, vsi
->alloc_txq
,
246 sizeof(*vsi
->tx_rings
), GFP_KERNEL
);
250 vsi
->rx_rings
= devm_kcalloc(&pf
->pdev
->dev
, vsi
->alloc_rxq
,
251 sizeof(*vsi
->rx_rings
), GFP_KERNEL
);
255 if (alloc_qvectors
) {
256 /* allocate memory for q_vector pointers */
257 vsi
->q_vectors
= devm_kcalloc(&pf
->pdev
->dev
,
259 sizeof(*vsi
->q_vectors
),
268 devm_kfree(&pf
->pdev
->dev
, vsi
->rx_rings
);
270 devm_kfree(&pf
->pdev
->dev
, vsi
->tx_rings
);
276 * ice_vsi_set_num_desc - Set number of descriptors for queues on this VSI
277 * @vsi: the VSI being configured
279 static void ice_vsi_set_num_desc(struct ice_vsi
*vsi
)
283 vsi
->num_rx_desc
= ICE_DFLT_NUM_RX_DESC
;
284 vsi
->num_tx_desc
= ICE_DFLT_NUM_TX_DESC
;
287 dev_dbg(&vsi
->back
->pdev
->dev
,
288 "Not setting number of Tx/Rx descriptors for VSI type %d\n",
295 * ice_vsi_set_num_qs - Set number of queues, descriptors and vectors for a VSI
296 * @vsi: the VSI being configured
297 * @vf_id: ID of the VF being configured
299 * Return 0 on success and a negative value on error
301 static void ice_vsi_set_num_qs(struct ice_vsi
*vsi
, u16 vf_id
)
303 struct ice_pf
*pf
= vsi
->back
;
304 struct ice_vf
*vf
= NULL
;
306 if (vsi
->type
== ICE_VSI_VF
)
311 vsi
->alloc_txq
= pf
->num_lan_tx
;
312 vsi
->alloc_rxq
= pf
->num_lan_rx
;
313 vsi
->num_q_vectors
= max_t(int, pf
->num_lan_rx
, pf
->num_lan_tx
);
316 vf
= &pf
->vf
[vsi
->vf_id
];
317 vsi
->alloc_txq
= vf
->num_vf_qs
;
318 vsi
->alloc_rxq
= vf
->num_vf_qs
;
319 /* pf->num_vf_msix includes (VF miscellaneous vector +
320 * data queue interrupts). Since vsi->num_q_vectors is number
321 * of queues vectors, subtract 1 from the original vector
324 vsi
->num_q_vectors
= pf
->num_vf_msix
- 1;
327 dev_warn(&pf
->pdev
->dev
, "Unknown VSI type %d\n", vsi
->type
);
331 ice_vsi_set_num_desc(vsi
);
335 * ice_get_free_slot - get the next non-NULL location index in array
336 * @array: array to search
337 * @size: size of the array
338 * @curr: last known occupied index to be used as a search hint
340 * void * is being used to keep the functionality generic. This lets us use this
341 * function on any array of pointers.
343 static int ice_get_free_slot(void *array
, int size
, int curr
)
345 int **tmp_array
= (int **)array
;
348 if (curr
< (size
- 1) && !tmp_array
[curr
+ 1]) {
353 while ((i
< size
) && (tmp_array
[i
]))
364 * ice_vsi_delete - delete a VSI from the switch
365 * @vsi: pointer to VSI being removed
367 void ice_vsi_delete(struct ice_vsi
*vsi
)
369 struct ice_pf
*pf
= vsi
->back
;
370 struct ice_vsi_ctx
*ctxt
;
371 enum ice_status status
;
373 ctxt
= devm_kzalloc(&pf
->pdev
->dev
, sizeof(*ctxt
), GFP_KERNEL
);
377 if (vsi
->type
== ICE_VSI_VF
)
378 ctxt
->vf_num
= vsi
->vf_id
;
379 ctxt
->vsi_num
= vsi
->vsi_num
;
381 memcpy(&ctxt
->info
, &vsi
->info
, sizeof(ctxt
->info
));
383 status
= ice_free_vsi(&pf
->hw
, vsi
->idx
, ctxt
, false, NULL
);
385 dev_err(&pf
->pdev
->dev
, "Failed to delete VSI %i in FW\n",
388 devm_kfree(&pf
->pdev
->dev
, ctxt
);
392 * ice_vsi_free_arrays - clean up VSI resources
393 * @vsi: pointer to VSI being cleared
394 * @free_qvectors: bool to specify if q_vectors should be deallocated
396 static void ice_vsi_free_arrays(struct ice_vsi
*vsi
, bool free_qvectors
)
398 struct ice_pf
*pf
= vsi
->back
;
400 /* free the ring and vector containers */
401 if (free_qvectors
&& vsi
->q_vectors
) {
402 devm_kfree(&pf
->pdev
->dev
, vsi
->q_vectors
);
403 vsi
->q_vectors
= NULL
;
406 devm_kfree(&pf
->pdev
->dev
, vsi
->tx_rings
);
407 vsi
->tx_rings
= NULL
;
410 devm_kfree(&pf
->pdev
->dev
, vsi
->rx_rings
);
411 vsi
->rx_rings
= NULL
;
416 * ice_vsi_clear - clean up and deallocate the provided VSI
417 * @vsi: pointer to VSI being cleared
419 * This deallocates the VSI's queue resources, removes it from the PF's
420 * VSI array if necessary, and deallocates the VSI
422 * Returns 0 on success, negative on failure
424 int ice_vsi_clear(struct ice_vsi
*vsi
)
426 struct ice_pf
*pf
= NULL
;
436 if (!pf
->vsi
[vsi
->idx
] || pf
->vsi
[vsi
->idx
] != vsi
) {
437 dev_dbg(&pf
->pdev
->dev
, "vsi does not exist at pf->vsi[%d]\n",
442 mutex_lock(&pf
->sw_mutex
);
443 /* updates the PF for this cleared VSI */
445 pf
->vsi
[vsi
->idx
] = NULL
;
446 if (vsi
->idx
< pf
->next_vsi
)
447 pf
->next_vsi
= vsi
->idx
;
449 ice_vsi_free_arrays(vsi
, true);
450 mutex_unlock(&pf
->sw_mutex
);
451 devm_kfree(&pf
->pdev
->dev
, vsi
);
457 * ice_msix_clean_rings - MSIX mode Interrupt Handler
458 * @irq: interrupt number
459 * @data: pointer to a q_vector
461 static irqreturn_t
ice_msix_clean_rings(int __always_unused irq
, void *data
)
463 struct ice_q_vector
*q_vector
= (struct ice_q_vector
*)data
;
465 if (!q_vector
->tx
.ring
&& !q_vector
->rx
.ring
)
468 napi_schedule(&q_vector
->napi
);
474 * ice_vsi_alloc - Allocates the next available struct VSI in the PF
475 * @pf: board private structure
477 * @vf_id: ID of the VF being configured
479 * returns a pointer to a VSI on success, NULL on failure.
481 static struct ice_vsi
*
482 ice_vsi_alloc(struct ice_pf
*pf
, enum ice_vsi_type type
, u16 vf_id
)
484 struct ice_vsi
*vsi
= NULL
;
486 /* Need to protect the allocation of the VSIs at the PF level */
487 mutex_lock(&pf
->sw_mutex
);
489 /* If we have already allocated our maximum number of VSIs,
490 * pf->next_vsi will be ICE_NO_VSI. If not, pf->next_vsi index
491 * is available to be populated
493 if (pf
->next_vsi
== ICE_NO_VSI
) {
494 dev_dbg(&pf
->pdev
->dev
, "out of VSI slots!\n");
498 vsi
= devm_kzalloc(&pf
->pdev
->dev
, sizeof(*vsi
), GFP_KERNEL
);
504 set_bit(__ICE_DOWN
, vsi
->state
);
505 vsi
->idx
= pf
->next_vsi
;
506 vsi
->work_lmt
= ICE_DFLT_IRQ_WORK
;
508 if (type
== ICE_VSI_VF
)
509 ice_vsi_set_num_qs(vsi
, vf_id
);
511 ice_vsi_set_num_qs(vsi
, ICE_INVAL_VFID
);
515 if (ice_vsi_alloc_arrays(vsi
, true))
518 /* Setup default MSIX irq handler for VSI */
519 vsi
->irq_handler
= ice_msix_clean_rings
;
522 if (ice_vsi_alloc_arrays(vsi
, true))
526 dev_warn(&pf
->pdev
->dev
, "Unknown VSI type %d\n", vsi
->type
);
530 /* fill VSI slot in the PF struct */
531 pf
->vsi
[pf
->next_vsi
] = vsi
;
533 /* prepare pf->next_vsi for next use */
534 pf
->next_vsi
= ice_get_free_slot(pf
->vsi
, pf
->num_alloc_vsi
,
539 devm_kfree(&pf
->pdev
->dev
, vsi
);
542 mutex_unlock(&pf
->sw_mutex
);
547 * __ice_vsi_get_qs_contig - Assign a contiguous chunk of queues to VSI
548 * @qs_cfg: gathered variables needed for PF->VSI queues assignment
550 * Return 0 on success and -ENOMEM in case of no left space in PF queue bitmap
552 static int __ice_vsi_get_qs_contig(struct ice_qs_cfg
*qs_cfg
)
556 mutex_lock(qs_cfg
->qs_mutex
);
557 offset
= bitmap_find_next_zero_area(qs_cfg
->pf_map
, qs_cfg
->pf_map_size
,
558 0, qs_cfg
->q_count
, 0);
559 if (offset
>= qs_cfg
->pf_map_size
) {
560 mutex_unlock(qs_cfg
->qs_mutex
);
564 bitmap_set(qs_cfg
->pf_map
, offset
, qs_cfg
->q_count
);
565 for (i
= 0; i
< qs_cfg
->q_count
; i
++)
566 qs_cfg
->vsi_map
[i
+ qs_cfg
->vsi_map_offset
] = i
+ offset
;
567 mutex_unlock(qs_cfg
->qs_mutex
);
573 * __ice_vsi_get_qs_sc - Assign a scattered queues from PF to VSI
574 * @qs_cfg: gathered variables needed for pf->vsi queues assignment
576 * Return 0 on success and -ENOMEM in case of no left space in PF queue bitmap
578 static int __ice_vsi_get_qs_sc(struct ice_qs_cfg
*qs_cfg
)
582 mutex_lock(qs_cfg
->qs_mutex
);
583 for (i
= 0; i
< qs_cfg
->q_count
; i
++) {
584 index
= find_next_zero_bit(qs_cfg
->pf_map
,
585 qs_cfg
->pf_map_size
, index
);
586 if (index
>= qs_cfg
->pf_map_size
)
588 set_bit(index
, qs_cfg
->pf_map
);
589 qs_cfg
->vsi_map
[i
+ qs_cfg
->vsi_map_offset
] = index
;
591 mutex_unlock(qs_cfg
->qs_mutex
);
595 for (index
= 0; index
< i
; index
++) {
596 clear_bit(qs_cfg
->vsi_map
[index
], qs_cfg
->pf_map
);
597 qs_cfg
->vsi_map
[index
+ qs_cfg
->vsi_map_offset
] = 0;
599 mutex_unlock(qs_cfg
->qs_mutex
);
605 * __ice_vsi_get_qs - helper function for assigning queues from PF to VSI
606 * @qs_cfg: gathered variables needed for pf->vsi queues assignment
608 * This function first tries to find contiguous space. If it is not successful,
609 * it tries with the scatter approach.
611 * Return 0 on success and -ENOMEM in case of no left space in PF queue bitmap
613 static int __ice_vsi_get_qs(struct ice_qs_cfg
*qs_cfg
)
617 ret
= __ice_vsi_get_qs_contig(qs_cfg
);
619 /* contig failed, so try with scatter approach */
620 qs_cfg
->mapping_mode
= ICE_VSI_MAP_SCATTER
;
621 qs_cfg
->q_count
= min_t(u16
, qs_cfg
->q_count
,
622 qs_cfg
->scatter_count
);
623 ret
= __ice_vsi_get_qs_sc(qs_cfg
);
629 * ice_vsi_get_qs - Assign queues from PF to VSI
630 * @vsi: the VSI to assign queues to
632 * Returns 0 on success and a negative value on error
634 static int ice_vsi_get_qs(struct ice_vsi
*vsi
)
636 struct ice_pf
*pf
= vsi
->back
;
637 struct ice_qs_cfg tx_qs_cfg
= {
638 .qs_mutex
= &pf
->avail_q_mutex
,
639 .pf_map
= pf
->avail_txqs
,
640 .pf_map_size
= ICE_MAX_TXQS
,
641 .q_count
= vsi
->alloc_txq
,
642 .scatter_count
= ICE_MAX_SCATTER_TXQS
,
643 .vsi_map
= vsi
->txq_map
,
645 .mapping_mode
= vsi
->tx_mapping_mode
647 struct ice_qs_cfg rx_qs_cfg
= {
648 .qs_mutex
= &pf
->avail_q_mutex
,
649 .pf_map
= pf
->avail_rxqs
,
650 .pf_map_size
= ICE_MAX_RXQS
,
651 .q_count
= vsi
->alloc_rxq
,
652 .scatter_count
= ICE_MAX_SCATTER_RXQS
,
653 .vsi_map
= vsi
->rxq_map
,
655 .mapping_mode
= vsi
->rx_mapping_mode
659 vsi
->tx_mapping_mode
= ICE_VSI_MAP_CONTIG
;
660 vsi
->rx_mapping_mode
= ICE_VSI_MAP_CONTIG
;
662 ret
= __ice_vsi_get_qs(&tx_qs_cfg
);
664 ret
= __ice_vsi_get_qs(&rx_qs_cfg
);
670 * ice_vsi_put_qs - Release queues from VSI to PF
671 * @vsi: the VSI that is going to release queues
673 void ice_vsi_put_qs(struct ice_vsi
*vsi
)
675 struct ice_pf
*pf
= vsi
->back
;
678 mutex_lock(&pf
->avail_q_mutex
);
680 for (i
= 0; i
< vsi
->alloc_txq
; i
++) {
681 clear_bit(vsi
->txq_map
[i
], pf
->avail_txqs
);
682 vsi
->txq_map
[i
] = ICE_INVAL_Q_INDEX
;
685 for (i
= 0; i
< vsi
->alloc_rxq
; i
++) {
686 clear_bit(vsi
->rxq_map
[i
], pf
->avail_rxqs
);
687 vsi
->rxq_map
[i
] = ICE_INVAL_Q_INDEX
;
690 mutex_unlock(&pf
->avail_q_mutex
);
694 * ice_rss_clean - Delete RSS related VSI structures that hold user inputs
695 * @vsi: the VSI being removed
697 static void ice_rss_clean(struct ice_vsi
*vsi
)
703 if (vsi
->rss_hkey_user
)
704 devm_kfree(&pf
->pdev
->dev
, vsi
->rss_hkey_user
);
705 if (vsi
->rss_lut_user
)
706 devm_kfree(&pf
->pdev
->dev
, vsi
->rss_lut_user
);
710 * ice_vsi_set_rss_params - Setup RSS capabilities per VSI type
711 * @vsi: the VSI being configured
713 static void ice_vsi_set_rss_params(struct ice_vsi
*vsi
)
715 struct ice_hw_common_caps
*cap
;
716 struct ice_pf
*pf
= vsi
->back
;
718 if (!test_bit(ICE_FLAG_RSS_ENA
, pf
->flags
)) {
723 cap
= &pf
->hw
.func_caps
.common_cap
;
726 /* PF VSI will inherit RSS instance of PF */
727 vsi
->rss_table_size
= cap
->rss_table_size
;
728 vsi
->rss_size
= min_t(int, num_online_cpus(),
729 BIT(cap
->rss_table_entry_width
));
730 vsi
->rss_lut_type
= ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF
;
733 /* VF VSI will gets a small RSS table
734 * For VSI_LUT, LUT size should be set to 64 bytes
736 vsi
->rss_table_size
= ICE_VSIQF_HLUT_ARRAY_SIZE
;
737 vsi
->rss_size
= min_t(int, num_online_cpus(),
738 BIT(cap
->rss_table_entry_width
));
739 vsi
->rss_lut_type
= ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_VSI
;
742 dev_warn(&pf
->pdev
->dev
, "Unknown VSI type %d\n",
749 * ice_set_dflt_vsi_ctx - Set default VSI context before adding a VSI
750 * @ctxt: the VSI context being set
752 * This initializes a default VSI context for all sections except the Queues.
754 static void ice_set_dflt_vsi_ctx(struct ice_vsi_ctx
*ctxt
)
758 memset(&ctxt
->info
, 0, sizeof(ctxt
->info
));
759 /* VSI's should be allocated from shared pool */
760 ctxt
->alloc_from_pool
= true;
761 /* Src pruning enabled by default */
762 ctxt
->info
.sw_flags
= ICE_AQ_VSI_SW_FLAG_SRC_PRUNE
;
763 /* Traffic from VSI can be sent to LAN */
764 ctxt
->info
.sw_flags2
= ICE_AQ_VSI_SW_FLAG_LAN_ENA
;
765 /* By default bits 3 and 4 in vlan_flags are 0's which results in legacy
766 * behavior (show VLAN, DEI, and UP) in descriptor. Also, allow all
767 * packets untagged/tagged.
769 ctxt
->info
.vlan_flags
= ((ICE_AQ_VSI_VLAN_MODE_ALL
&
770 ICE_AQ_VSI_VLAN_MODE_M
) >>
771 ICE_AQ_VSI_VLAN_MODE_S
);
772 /* Have 1:1 UP mapping for both ingress/egress tables */
773 table
|= ICE_UP_TABLE_TRANSLATE(0, 0);
774 table
|= ICE_UP_TABLE_TRANSLATE(1, 1);
775 table
|= ICE_UP_TABLE_TRANSLATE(2, 2);
776 table
|= ICE_UP_TABLE_TRANSLATE(3, 3);
777 table
|= ICE_UP_TABLE_TRANSLATE(4, 4);
778 table
|= ICE_UP_TABLE_TRANSLATE(5, 5);
779 table
|= ICE_UP_TABLE_TRANSLATE(6, 6);
780 table
|= ICE_UP_TABLE_TRANSLATE(7, 7);
781 ctxt
->info
.ingress_table
= cpu_to_le32(table
);
782 ctxt
->info
.egress_table
= cpu_to_le32(table
);
783 /* Have 1:1 UP mapping for outer to inner UP table */
784 ctxt
->info
.outer_up_table
= cpu_to_le32(table
);
785 /* No Outer tag support outer_tag_flags remains to zero */
789 * ice_vsi_setup_q_map - Setup a VSI queue map
790 * @vsi: the VSI being configured
791 * @ctxt: VSI context structure
793 static void ice_vsi_setup_q_map(struct ice_vsi
*vsi
, struct ice_vsi_ctx
*ctxt
)
795 u16 offset
= 0, qmap
= 0, tx_count
= 0;
796 u16 qcount_tx
= vsi
->alloc_txq
;
797 u16 qcount_rx
= vsi
->alloc_rxq
;
798 u16 tx_numq_tc
, rx_numq_tc
;
799 u16 pow
= 0, max_rss
= 0;
800 bool ena_tc0
= false;
804 /* at least TC0 should be enabled by default */
805 if (vsi
->tc_cfg
.numtc
) {
806 if (!(vsi
->tc_cfg
.ena_tc
& BIT(0)))
814 vsi
->tc_cfg
.ena_tc
|= 1;
817 rx_numq_tc
= qcount_rx
/ vsi
->tc_cfg
.numtc
;
820 tx_numq_tc
= qcount_tx
/ vsi
->tc_cfg
.numtc
;
824 /* TC mapping is a function of the number of Rx queues assigned to the
825 * VSI for each traffic class and the offset of these queues.
826 * The first 10 bits are for queue offset for TC0, next 4 bits for no:of
827 * queues allocated to TC0. No:of queues is a power-of-2.
829 * If TC is not enabled, the queue offset is set to 0, and allocate one
830 * queue, this way, traffic for the given TC will be sent to the default
833 * Setup number and offset of Rx queues for all TCs for the VSI
836 qcount_rx
= rx_numq_tc
;
838 /* qcount will change if RSS is enabled */
839 if (test_bit(ICE_FLAG_RSS_ENA
, vsi
->back
->flags
)) {
840 if (vsi
->type
== ICE_VSI_PF
|| vsi
->type
== ICE_VSI_VF
) {
841 if (vsi
->type
== ICE_VSI_PF
)
842 max_rss
= ICE_MAX_LG_RSS_QS
;
844 max_rss
= ICE_MAX_SMALL_RSS_QS
;
845 qcount_rx
= min_t(int, rx_numq_tc
, max_rss
);
846 qcount_rx
= min_t(int, qcount_rx
, vsi
->rss_size
);
850 /* find the (rounded up) power-of-2 of qcount */
851 pow
= order_base_2(qcount_rx
);
853 ice_for_each_traffic_class(i
) {
854 if (!(vsi
->tc_cfg
.ena_tc
& BIT(i
))) {
855 /* TC is not enabled */
856 vsi
->tc_cfg
.tc_info
[i
].qoffset
= 0;
857 vsi
->tc_cfg
.tc_info
[i
].qcount_rx
= 1;
858 vsi
->tc_cfg
.tc_info
[i
].qcount_tx
= 1;
859 vsi
->tc_cfg
.tc_info
[i
].netdev_tc
= 0;
860 ctxt
->info
.tc_mapping
[i
] = 0;
865 vsi
->tc_cfg
.tc_info
[i
].qoffset
= offset
;
866 vsi
->tc_cfg
.tc_info
[i
].qcount_rx
= qcount_rx
;
867 vsi
->tc_cfg
.tc_info
[i
].qcount_tx
= tx_numq_tc
;
868 vsi
->tc_cfg
.tc_info
[i
].netdev_tc
= netdev_tc
++;
870 qmap
= ((offset
<< ICE_AQ_VSI_TC_Q_OFFSET_S
) &
871 ICE_AQ_VSI_TC_Q_OFFSET_M
) |
872 ((pow
<< ICE_AQ_VSI_TC_Q_NUM_S
) &
873 ICE_AQ_VSI_TC_Q_NUM_M
);
875 tx_count
+= tx_numq_tc
;
876 ctxt
->info
.tc_mapping
[i
] = cpu_to_le16(qmap
);
879 /* if offset is non-zero, means it is calculated correctly based on
880 * enabled TCs for a given VSI otherwise qcount_rx will always
881 * be correct and non-zero because it is based off - VSI's
882 * allocated Rx queues which is at least 1 (hence qcount_tx will be
886 vsi
->num_rxq
= offset
;
888 vsi
->num_rxq
= qcount_rx
;
890 vsi
->num_txq
= tx_count
;
892 if (vsi
->type
== ICE_VSI_VF
&& vsi
->num_txq
!= vsi
->num_rxq
) {
893 dev_dbg(&vsi
->back
->pdev
->dev
, "VF VSI should have same number of Tx and Rx queues. Hence making them equal\n");
894 /* since there is a chance that num_rxq could have been changed
895 * in the above for loop, make num_txq equal to num_rxq.
897 vsi
->num_txq
= vsi
->num_rxq
;
900 /* Rx queue mapping */
901 ctxt
->info
.mapping_flags
|= cpu_to_le16(ICE_AQ_VSI_Q_MAP_CONTIG
);
902 /* q_mapping buffer holds the info for the first queue allocated for
903 * this VSI in the PF space and also the number of queues associated
906 ctxt
->info
.q_mapping
[0] = cpu_to_le16(vsi
->rxq_map
[0]);
907 ctxt
->info
.q_mapping
[1] = cpu_to_le16(vsi
->num_rxq
);
911 * ice_set_rss_vsi_ctx - Set RSS VSI context before adding a VSI
912 * @ctxt: the VSI context being set
913 * @vsi: the VSI being configured
915 static void ice_set_rss_vsi_ctx(struct ice_vsi_ctx
*ctxt
, struct ice_vsi
*vsi
)
917 u8 lut_type
, hash_type
;
924 /* PF VSI will inherit RSS instance of PF */
925 lut_type
= ICE_AQ_VSI_Q_OPT_RSS_LUT_PF
;
926 hash_type
= ICE_AQ_VSI_Q_OPT_RSS_TPLZ
;
929 /* VF VSI will gets a small RSS table which is a VSI LUT type */
930 lut_type
= ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI
;
931 hash_type
= ICE_AQ_VSI_Q_OPT_RSS_TPLZ
;
934 dev_warn(&pf
->pdev
->dev
, "Unknown VSI type %d\n", vsi
->type
);
938 ctxt
->info
.q_opt_rss
= ((lut_type
<< ICE_AQ_VSI_Q_OPT_RSS_LUT_S
) &
939 ICE_AQ_VSI_Q_OPT_RSS_LUT_M
) |
940 ((hash_type
<< ICE_AQ_VSI_Q_OPT_RSS_HASH_S
) &
941 ICE_AQ_VSI_Q_OPT_RSS_HASH_M
);
945 * ice_vsi_init - Create and initialize a VSI
946 * @vsi: the VSI being configured
948 * This initializes a VSI context depending on the VSI type to be added and
949 * passes it down to the add_vsi aq command to create a new VSI.
951 static int ice_vsi_init(struct ice_vsi
*vsi
)
953 struct ice_pf
*pf
= vsi
->back
;
954 struct ice_hw
*hw
= &pf
->hw
;
955 struct ice_vsi_ctx
*ctxt
;
958 ctxt
= devm_kzalloc(&pf
->pdev
->dev
, sizeof(*ctxt
), GFP_KERNEL
);
962 ctxt
->info
= vsi
->info
;
965 ctxt
->flags
= ICE_AQ_VSI_TYPE_PF
;
968 ctxt
->flags
= ICE_AQ_VSI_TYPE_VF
;
969 /* VF number here is the absolute VF number (0-255) */
970 ctxt
->vf_num
= vsi
->vf_id
+ hw
->func_caps
.vf_base_id
;
976 ice_set_dflt_vsi_ctx(ctxt
);
977 /* if the switch is in VEB mode, allow VSI loopback */
978 if (vsi
->vsw
->bridge_mode
== BRIDGE_MODE_VEB
)
979 ctxt
->info
.sw_flags
|= ICE_AQ_VSI_SW_FLAG_ALLOW_LB
;
981 /* Set LUT type and HASH type if RSS is enabled */
982 if (test_bit(ICE_FLAG_RSS_ENA
, pf
->flags
))
983 ice_set_rss_vsi_ctx(ctxt
, vsi
);
985 ctxt
->info
.sw_id
= vsi
->port_info
->sw_id
;
986 ice_vsi_setup_q_map(vsi
, ctxt
);
988 /* Enable MAC Antispoof with new VSI being initialized or updated */
989 if (vsi
->type
== ICE_VSI_VF
&& pf
->vf
[vsi
->vf_id
].spoofchk
) {
990 ctxt
->info
.valid_sections
|=
991 cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID
);
992 ctxt
->info
.sec_flags
|=
993 ICE_AQ_VSI_SEC_FLAG_ENA_MAC_ANTI_SPOOF
;
996 ret
= ice_add_vsi(hw
, vsi
->idx
, ctxt
, NULL
);
998 dev_err(&pf
->pdev
->dev
,
999 "Add VSI failed, err %d\n", ret
);
1003 /* keep context for update VSI operations */
1004 vsi
->info
= ctxt
->info
;
1006 /* record VSI number returned */
1007 vsi
->vsi_num
= ctxt
->vsi_num
;
1009 devm_kfree(&pf
->pdev
->dev
, ctxt
);
1014 * ice_free_q_vector - Free memory allocated for a specific interrupt vector
1015 * @vsi: VSI having the memory freed
1016 * @v_idx: index of the vector to be freed
1018 static void ice_free_q_vector(struct ice_vsi
*vsi
, int v_idx
)
1020 struct ice_q_vector
*q_vector
;
1021 struct ice_pf
*pf
= vsi
->back
;
1022 struct ice_ring
*ring
;
1024 if (!vsi
->q_vectors
[v_idx
]) {
1025 dev_dbg(&pf
->pdev
->dev
, "Queue vector at index %d not found\n",
1029 q_vector
= vsi
->q_vectors
[v_idx
];
1031 ice_for_each_ring(ring
, q_vector
->tx
)
1032 ring
->q_vector
= NULL
;
1033 ice_for_each_ring(ring
, q_vector
->rx
)
1034 ring
->q_vector
= NULL
;
1036 /* only VSI with an associated netdev is set up with NAPI */
1038 netif_napi_del(&q_vector
->napi
);
1040 devm_kfree(&pf
->pdev
->dev
, q_vector
);
1041 vsi
->q_vectors
[v_idx
] = NULL
;
1045 * ice_vsi_free_q_vectors - Free memory allocated for interrupt vectors
1046 * @vsi: the VSI having memory freed
1048 void ice_vsi_free_q_vectors(struct ice_vsi
*vsi
)
1052 ice_for_each_q_vector(vsi
, v_idx
)
1053 ice_free_q_vector(vsi
, v_idx
);
1057 * ice_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
1058 * @vsi: the VSI being configured
1059 * @v_idx: index of the vector in the VSI struct
1061 * We allocate one q_vector. If allocation fails we return -ENOMEM.
1063 static int ice_vsi_alloc_q_vector(struct ice_vsi
*vsi
, int v_idx
)
1065 struct ice_pf
*pf
= vsi
->back
;
1066 struct ice_q_vector
*q_vector
;
1068 /* allocate q_vector */
1069 q_vector
= devm_kzalloc(&pf
->pdev
->dev
, sizeof(*q_vector
), GFP_KERNEL
);
1073 q_vector
->vsi
= vsi
;
1074 q_vector
->v_idx
= v_idx
;
1075 if (vsi
->type
== ICE_VSI_VF
)
1077 /* only set affinity_mask if the CPU is online */
1078 if (cpu_online(v_idx
))
1079 cpumask_set_cpu(v_idx
, &q_vector
->affinity_mask
);
1081 /* This will not be called in the driver load path because the netdev
1082 * will not be created yet. All other cases with register the NAPI
1083 * handler here (i.e. resume, reset/rebuild, etc.)
1086 netif_napi_add(vsi
->netdev
, &q_vector
->napi
, ice_napi_poll
,
1090 /* tie q_vector and VSI together */
1091 vsi
->q_vectors
[v_idx
] = q_vector
;
1097 * ice_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
1098 * @vsi: the VSI being configured
1100 * We allocate one q_vector per queue interrupt. If allocation fails we
1103 static int ice_vsi_alloc_q_vectors(struct ice_vsi
*vsi
)
1105 struct ice_pf
*pf
= vsi
->back
;
1106 int v_idx
= 0, num_q_vectors
;
1109 if (vsi
->q_vectors
[0]) {
1110 dev_dbg(&pf
->pdev
->dev
, "VSI %d has existing q_vectors\n",
1115 if (test_bit(ICE_FLAG_MSIX_ENA
, pf
->flags
)) {
1116 num_q_vectors
= vsi
->num_q_vectors
;
1122 for (v_idx
= 0; v_idx
< num_q_vectors
; v_idx
++) {
1123 err
= ice_vsi_alloc_q_vector(vsi
, v_idx
);
1132 ice_free_q_vector(vsi
, v_idx
);
1134 dev_err(&pf
->pdev
->dev
,
1135 "Failed to allocate %d q_vector for VSI %d, ret=%d\n",
1136 vsi
->num_q_vectors
, vsi
->vsi_num
, err
);
1137 vsi
->num_q_vectors
= 0;
1142 * ice_vsi_setup_vector_base - Set up the base vector for the given VSI
1143 * @vsi: ptr to the VSI
1145 * This should only be called after ice_vsi_alloc() which allocates the
1146 * corresponding SW VSI structure and initializes num_queue_pairs for the
1147 * newly allocated VSI.
1149 * Returns 0 on success or negative on failure
1151 static int ice_vsi_setup_vector_base(struct ice_vsi
*vsi
)
1153 struct ice_pf
*pf
= vsi
->back
;
1154 int num_q_vectors
= 0;
1156 if (vsi
->sw_base_vector
|| vsi
->hw_base_vector
) {
1157 dev_dbg(&pf
->pdev
->dev
, "VSI %d has non-zero HW base vector %d or SW base vector %d\n",
1158 vsi
->vsi_num
, vsi
->hw_base_vector
, vsi
->sw_base_vector
);
1162 if (!test_bit(ICE_FLAG_MSIX_ENA
, pf
->flags
))
1165 switch (vsi
->type
) {
1167 num_q_vectors
= vsi
->num_q_vectors
;
1168 /* reserve slots from OS requested IRQs */
1169 vsi
->sw_base_vector
= ice_get_res(pf
, pf
->sw_irq_tracker
,
1170 num_q_vectors
, vsi
->idx
);
1171 if (vsi
->sw_base_vector
< 0) {
1172 dev_err(&pf
->pdev
->dev
,
1173 "Failed to get tracking for %d SW vectors for VSI %d, err=%d\n",
1174 num_q_vectors
, vsi
->vsi_num
,
1175 vsi
->sw_base_vector
);
1178 pf
->num_avail_sw_msix
-= num_q_vectors
;
1180 /* reserve slots from HW interrupts */
1181 vsi
->hw_base_vector
= ice_get_res(pf
, pf
->hw_irq_tracker
,
1182 num_q_vectors
, vsi
->idx
);
1185 /* take VF misc vector and data vectors into account */
1186 num_q_vectors
= pf
->num_vf_msix
;
1187 /* For VF VSI, reserve slots only from HW interrupts */
1188 vsi
->hw_base_vector
= ice_get_res(pf
, pf
->hw_irq_tracker
,
1189 num_q_vectors
, vsi
->idx
);
1192 dev_warn(&pf
->pdev
->dev
, "Unknown VSI type %d\n", vsi
->type
);
1196 if (vsi
->hw_base_vector
< 0) {
1197 dev_err(&pf
->pdev
->dev
,
1198 "Failed to get tracking for %d HW vectors for VSI %d, err=%d\n",
1199 num_q_vectors
, vsi
->vsi_num
, vsi
->hw_base_vector
);
1200 if (vsi
->type
!= ICE_VSI_VF
) {
1201 ice_free_res(pf
->sw_irq_tracker
,
1202 vsi
->sw_base_vector
, vsi
->idx
);
1203 pf
->num_avail_sw_msix
+= num_q_vectors
;
1208 pf
->num_avail_hw_msix
-= num_q_vectors
;
1214 * ice_vsi_clear_rings - Deallocates the Tx and Rx rings for VSI
1215 * @vsi: the VSI having rings deallocated
1217 static void ice_vsi_clear_rings(struct ice_vsi
*vsi
)
1221 if (vsi
->tx_rings
) {
1222 for (i
= 0; i
< vsi
->alloc_txq
; i
++) {
1223 if (vsi
->tx_rings
[i
]) {
1224 kfree_rcu(vsi
->tx_rings
[i
], rcu
);
1225 vsi
->tx_rings
[i
] = NULL
;
1229 if (vsi
->rx_rings
) {
1230 for (i
= 0; i
< vsi
->alloc_rxq
; i
++) {
1231 if (vsi
->rx_rings
[i
]) {
1232 kfree_rcu(vsi
->rx_rings
[i
], rcu
);
1233 vsi
->rx_rings
[i
] = NULL
;
1240 * ice_vsi_alloc_rings - Allocates Tx and Rx rings for the VSI
1241 * @vsi: VSI which is having rings allocated
1243 static int ice_vsi_alloc_rings(struct ice_vsi
*vsi
)
1245 struct ice_pf
*pf
= vsi
->back
;
1248 /* Allocate Tx rings */
1249 for (i
= 0; i
< vsi
->alloc_txq
; i
++) {
1250 struct ice_ring
*ring
;
1252 /* allocate with kzalloc(), free with kfree_rcu() */
1253 ring
= kzalloc(sizeof(*ring
), GFP_KERNEL
);
1259 ring
->reg_idx
= vsi
->txq_map
[i
];
1260 ring
->ring_active
= false;
1262 ring
->dev
= &pf
->pdev
->dev
;
1263 ring
->count
= vsi
->num_tx_desc
;
1264 vsi
->tx_rings
[i
] = ring
;
1267 /* Allocate Rx rings */
1268 for (i
= 0; i
< vsi
->alloc_rxq
; i
++) {
1269 struct ice_ring
*ring
;
1271 /* allocate with kzalloc(), free with kfree_rcu() */
1272 ring
= kzalloc(sizeof(*ring
), GFP_KERNEL
);
1277 ring
->reg_idx
= vsi
->rxq_map
[i
];
1278 ring
->ring_active
= false;
1280 ring
->netdev
= vsi
->netdev
;
1281 ring
->dev
= &pf
->pdev
->dev
;
1282 ring
->count
= vsi
->num_rx_desc
;
1283 vsi
->rx_rings
[i
] = ring
;
1289 ice_vsi_clear_rings(vsi
);
1294 * ice_vsi_map_rings_to_vectors - Map VSI rings to interrupt vectors
1295 * @vsi: the VSI being configured
1297 * This function maps descriptor rings to the queue-specific vectors allotted
1298 * through the MSI-X enabling code. On a constrained vector budget, we map Tx
1299 * and Rx rings to the vector as "efficiently" as possible.
1302 void ice_vsi_map_rings_to_vectors(struct ice_vsi
*vsi
)
1304 static void ice_vsi_map_rings_to_vectors(struct ice_vsi
*vsi
)
1305 #endif /* CONFIG_DCB */
1307 int q_vectors
= vsi
->num_q_vectors
;
1308 int tx_rings_rem
, rx_rings_rem
;
1311 /* initially assigning remaining rings count to VSIs num queue value */
1312 tx_rings_rem
= vsi
->num_txq
;
1313 rx_rings_rem
= vsi
->num_rxq
;
1315 for (v_id
= 0; v_id
< q_vectors
; v_id
++) {
1316 struct ice_q_vector
*q_vector
= vsi
->q_vectors
[v_id
];
1317 int tx_rings_per_v
, rx_rings_per_v
, q_id
, q_base
;
1319 /* Tx rings mapping to vector */
1320 tx_rings_per_v
= DIV_ROUND_UP(tx_rings_rem
, q_vectors
- v_id
);
1321 q_vector
->num_ring_tx
= tx_rings_per_v
;
1322 q_vector
->tx
.ring
= NULL
;
1323 q_vector
->tx
.itr_idx
= ICE_TX_ITR
;
1324 q_base
= vsi
->num_txq
- tx_rings_rem
;
1326 for (q_id
= q_base
; q_id
< (q_base
+ tx_rings_per_v
); q_id
++) {
1327 struct ice_ring
*tx_ring
= vsi
->tx_rings
[q_id
];
1329 tx_ring
->q_vector
= q_vector
;
1330 tx_ring
->next
= q_vector
->tx
.ring
;
1331 q_vector
->tx
.ring
= tx_ring
;
1333 tx_rings_rem
-= tx_rings_per_v
;
1335 /* Rx rings mapping to vector */
1336 rx_rings_per_v
= DIV_ROUND_UP(rx_rings_rem
, q_vectors
- v_id
);
1337 q_vector
->num_ring_rx
= rx_rings_per_v
;
1338 q_vector
->rx
.ring
= NULL
;
1339 q_vector
->rx
.itr_idx
= ICE_RX_ITR
;
1340 q_base
= vsi
->num_rxq
- rx_rings_rem
;
1342 for (q_id
= q_base
; q_id
< (q_base
+ rx_rings_per_v
); q_id
++) {
1343 struct ice_ring
*rx_ring
= vsi
->rx_rings
[q_id
];
1345 rx_ring
->q_vector
= q_vector
;
1346 rx_ring
->next
= q_vector
->rx
.ring
;
1347 q_vector
->rx
.ring
= rx_ring
;
1349 rx_rings_rem
-= rx_rings_per_v
;
1354 * ice_vsi_manage_rss_lut - disable/enable RSS
1355 * @vsi: the VSI being changed
1356 * @ena: boolean value indicating if this is an enable or disable request
1358 * In the event of disable request for RSS, this function will zero out RSS
1359 * LUT, while in the event of enable request for RSS, it will reconfigure RSS
1362 int ice_vsi_manage_rss_lut(struct ice_vsi
*vsi
, bool ena
)
1367 lut
= devm_kzalloc(&vsi
->back
->pdev
->dev
, vsi
->rss_table_size
,
1373 if (vsi
->rss_lut_user
)
1374 memcpy(lut
, vsi
->rss_lut_user
, vsi
->rss_table_size
);
1376 ice_fill_rss_lut(lut
, vsi
->rss_table_size
,
1380 err
= ice_set_rss(vsi
, NULL
, lut
, vsi
->rss_table_size
);
1381 devm_kfree(&vsi
->back
->pdev
->dev
, lut
);
1386 * ice_vsi_cfg_rss_lut_key - Configure RSS params for a VSI
1387 * @vsi: VSI to be configured
1389 static int ice_vsi_cfg_rss_lut_key(struct ice_vsi
*vsi
)
1391 struct ice_aqc_get_set_rss_keys
*key
;
1392 struct ice_pf
*pf
= vsi
->back
;
1393 enum ice_status status
;
1397 vsi
->rss_size
= min_t(int, vsi
->rss_size
, vsi
->num_rxq
);
1399 lut
= devm_kzalloc(&pf
->pdev
->dev
, vsi
->rss_table_size
, GFP_KERNEL
);
1403 if (vsi
->rss_lut_user
)
1404 memcpy(lut
, vsi
->rss_lut_user
, vsi
->rss_table_size
);
1406 ice_fill_rss_lut(lut
, vsi
->rss_table_size
, vsi
->rss_size
);
1408 status
= ice_aq_set_rss_lut(&pf
->hw
, vsi
->idx
, vsi
->rss_lut_type
, lut
,
1409 vsi
->rss_table_size
);
1412 dev_err(&pf
->pdev
->dev
,
1413 "set_rss_lut failed, error %d\n", status
);
1415 goto ice_vsi_cfg_rss_exit
;
1418 key
= devm_kzalloc(&pf
->pdev
->dev
, sizeof(*key
), GFP_KERNEL
);
1421 goto ice_vsi_cfg_rss_exit
;
1424 if (vsi
->rss_hkey_user
)
1426 (struct ice_aqc_get_set_rss_keys
*)vsi
->rss_hkey_user
,
1427 ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE
);
1429 netdev_rss_key_fill((void *)key
,
1430 ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE
);
1432 status
= ice_aq_set_rss_key(&pf
->hw
, vsi
->idx
, key
);
1435 dev_err(&pf
->pdev
->dev
, "set_rss_key failed, error %d\n",
1440 devm_kfree(&pf
->pdev
->dev
, key
);
1441 ice_vsi_cfg_rss_exit
:
1442 devm_kfree(&pf
->pdev
->dev
, lut
);
1447 * ice_add_mac_to_list - Add a MAC address filter entry to the list
1448 * @vsi: the VSI to be forwarded to
1449 * @add_list: pointer to the list which contains MAC filter entries
1450 * @macaddr: the MAC address to be added.
1452 * Adds MAC address filter entry to the temp list
1454 * Returns 0 on success or ENOMEM on failure.
1456 int ice_add_mac_to_list(struct ice_vsi
*vsi
, struct list_head
*add_list
,
1459 struct ice_fltr_list_entry
*tmp
;
1460 struct ice_pf
*pf
= vsi
->back
;
1462 tmp
= devm_kzalloc(&pf
->pdev
->dev
, sizeof(*tmp
), GFP_ATOMIC
);
1466 tmp
->fltr_info
.flag
= ICE_FLTR_TX
;
1467 tmp
->fltr_info
.src_id
= ICE_SRC_ID_VSI
;
1468 tmp
->fltr_info
.lkup_type
= ICE_SW_LKUP_MAC
;
1469 tmp
->fltr_info
.fltr_act
= ICE_FWD_TO_VSI
;
1470 tmp
->fltr_info
.vsi_handle
= vsi
->idx
;
1471 ether_addr_copy(tmp
->fltr_info
.l_data
.mac
.mac_addr
, macaddr
);
1473 INIT_LIST_HEAD(&tmp
->list_entry
);
1474 list_add(&tmp
->list_entry
, add_list
);
1480 * ice_update_eth_stats - Update VSI-specific ethernet statistics counters
1481 * @vsi: the VSI to be updated
1483 void ice_update_eth_stats(struct ice_vsi
*vsi
)
1485 struct ice_eth_stats
*prev_es
, *cur_es
;
1486 struct ice_hw
*hw
= &vsi
->back
->hw
;
1487 u16 vsi_num
= vsi
->vsi_num
; /* HW absolute index of a VSI */
1489 prev_es
= &vsi
->eth_stats_prev
;
1490 cur_es
= &vsi
->eth_stats
;
1492 ice_stat_update40(hw
, GLV_GORCH(vsi_num
), GLV_GORCL(vsi_num
),
1493 vsi
->stat_offsets_loaded
, &prev_es
->rx_bytes
,
1496 ice_stat_update40(hw
, GLV_UPRCH(vsi_num
), GLV_UPRCL(vsi_num
),
1497 vsi
->stat_offsets_loaded
, &prev_es
->rx_unicast
,
1498 &cur_es
->rx_unicast
);
1500 ice_stat_update40(hw
, GLV_MPRCH(vsi_num
), GLV_MPRCL(vsi_num
),
1501 vsi
->stat_offsets_loaded
, &prev_es
->rx_multicast
,
1502 &cur_es
->rx_multicast
);
1504 ice_stat_update40(hw
, GLV_BPRCH(vsi_num
), GLV_BPRCL(vsi_num
),
1505 vsi
->stat_offsets_loaded
, &prev_es
->rx_broadcast
,
1506 &cur_es
->rx_broadcast
);
1508 ice_stat_update32(hw
, GLV_RDPC(vsi_num
), vsi
->stat_offsets_loaded
,
1509 &prev_es
->rx_discards
, &cur_es
->rx_discards
);
1511 ice_stat_update40(hw
, GLV_GOTCH(vsi_num
), GLV_GOTCL(vsi_num
),
1512 vsi
->stat_offsets_loaded
, &prev_es
->tx_bytes
,
1515 ice_stat_update40(hw
, GLV_UPTCH(vsi_num
), GLV_UPTCL(vsi_num
),
1516 vsi
->stat_offsets_loaded
, &prev_es
->tx_unicast
,
1517 &cur_es
->tx_unicast
);
1519 ice_stat_update40(hw
, GLV_MPTCH(vsi_num
), GLV_MPTCL(vsi_num
),
1520 vsi
->stat_offsets_loaded
, &prev_es
->tx_multicast
,
1521 &cur_es
->tx_multicast
);
1523 ice_stat_update40(hw
, GLV_BPTCH(vsi_num
), GLV_BPTCL(vsi_num
),
1524 vsi
->stat_offsets_loaded
, &prev_es
->tx_broadcast
,
1525 &cur_es
->tx_broadcast
);
1527 ice_stat_update32(hw
, GLV_TEPC(vsi_num
), vsi
->stat_offsets_loaded
,
1528 &prev_es
->tx_errors
, &cur_es
->tx_errors
);
1530 vsi
->stat_offsets_loaded
= true;
1534 * ice_free_fltr_list - free filter lists helper
1535 * @dev: pointer to the device struct
1536 * @h: pointer to the list head to be freed
1538 * Helper function to free filter lists previously created using
1539 * ice_add_mac_to_list
1541 void ice_free_fltr_list(struct device
*dev
, struct list_head
*h
)
1543 struct ice_fltr_list_entry
*e
, *tmp
;
1545 list_for_each_entry_safe(e
, tmp
, h
, list_entry
) {
1546 list_del(&e
->list_entry
);
1552 * ice_vsi_add_vlan - Add VSI membership for given VLAN
1553 * @vsi: the VSI being configured
1554 * @vid: VLAN ID to be added
1556 int ice_vsi_add_vlan(struct ice_vsi
*vsi
, u16 vid
)
1558 struct ice_fltr_list_entry
*tmp
;
1559 struct ice_pf
*pf
= vsi
->back
;
1560 LIST_HEAD(tmp_add_list
);
1561 enum ice_status status
;
1564 tmp
= devm_kzalloc(&pf
->pdev
->dev
, sizeof(*tmp
), GFP_KERNEL
);
1568 tmp
->fltr_info
.lkup_type
= ICE_SW_LKUP_VLAN
;
1569 tmp
->fltr_info
.fltr_act
= ICE_FWD_TO_VSI
;
1570 tmp
->fltr_info
.flag
= ICE_FLTR_TX
;
1571 tmp
->fltr_info
.src_id
= ICE_SRC_ID_VSI
;
1572 tmp
->fltr_info
.vsi_handle
= vsi
->idx
;
1573 tmp
->fltr_info
.l_data
.vlan
.vlan_id
= vid
;
1575 INIT_LIST_HEAD(&tmp
->list_entry
);
1576 list_add(&tmp
->list_entry
, &tmp_add_list
);
1578 status
= ice_add_vlan(&pf
->hw
, &tmp_add_list
);
1581 dev_err(&pf
->pdev
->dev
, "Failure Adding VLAN %d on VSI %i\n",
1585 ice_free_fltr_list(&pf
->pdev
->dev
, &tmp_add_list
);
1590 * ice_vsi_kill_vlan - Remove VSI membership for a given VLAN
1591 * @vsi: the VSI being configured
1592 * @vid: VLAN ID to be removed
1594 * Returns 0 on success and negative on failure
1596 int ice_vsi_kill_vlan(struct ice_vsi
*vsi
, u16 vid
)
1598 struct ice_fltr_list_entry
*list
;
1599 struct ice_pf
*pf
= vsi
->back
;
1600 LIST_HEAD(tmp_add_list
);
1601 enum ice_status status
;
1604 list
= devm_kzalloc(&pf
->pdev
->dev
, sizeof(*list
), GFP_KERNEL
);
1608 list
->fltr_info
.lkup_type
= ICE_SW_LKUP_VLAN
;
1609 list
->fltr_info
.vsi_handle
= vsi
->idx
;
1610 list
->fltr_info
.fltr_act
= ICE_FWD_TO_VSI
;
1611 list
->fltr_info
.l_data
.vlan
.vlan_id
= vid
;
1612 list
->fltr_info
.flag
= ICE_FLTR_TX
;
1613 list
->fltr_info
.src_id
= ICE_SRC_ID_VSI
;
1615 INIT_LIST_HEAD(&list
->list_entry
);
1616 list_add(&list
->list_entry
, &tmp_add_list
);
1618 status
= ice_remove_vlan(&pf
->hw
, &tmp_add_list
);
1619 if (status
== ICE_ERR_DOES_NOT_EXIST
) {
1620 dev_dbg(&pf
->pdev
->dev
,
1621 "Failed to remove VLAN %d on VSI %i, it does not exist, status: %d\n",
1622 vid
, vsi
->vsi_num
, status
);
1623 } else if (status
) {
1624 dev_err(&pf
->pdev
->dev
,
1625 "Error removing VLAN %d on vsi %i error: %d\n",
1626 vid
, vsi
->vsi_num
, status
);
1630 ice_free_fltr_list(&pf
->pdev
->dev
, &tmp_add_list
);
1635 * ice_vsi_cfg_rxqs - Configure the VSI for Rx
1636 * @vsi: the VSI being configured
1638 * Return 0 on success and a negative value on error
1639 * Configure the Rx VSI for operation.
1641 int ice_vsi_cfg_rxqs(struct ice_vsi
*vsi
)
1645 if (vsi
->type
== ICE_VSI_VF
)
1648 if (vsi
->netdev
&& vsi
->netdev
->mtu
> ETH_DATA_LEN
)
1649 vsi
->max_frame
= vsi
->netdev
->mtu
+
1650 ETH_HLEN
+ ETH_FCS_LEN
+ VLAN_HLEN
;
1652 vsi
->max_frame
= ICE_RXBUF_2048
;
1654 vsi
->rx_buf_len
= ICE_RXBUF_2048
;
1656 /* set up individual rings */
1657 for (i
= 0; i
< vsi
->num_rxq
; i
++) {
1660 err
= ice_setup_rx_ctx(vsi
->rx_rings
[i
]);
1662 dev_err(&vsi
->back
->pdev
->dev
,
1663 "ice_setup_rx_ctx failed for RxQ %d, err %d\n",
1673 * ice_vsi_cfg_txqs - Configure the VSI for Tx
1674 * @vsi: the VSI being configured
1675 * @rings: Tx ring array to be configured
1676 * @offset: offset within vsi->txq_map
1678 * Return 0 on success and a negative value on error
1679 * Configure the Tx VSI for operation.
1682 ice_vsi_cfg_txqs(struct ice_vsi
*vsi
, struct ice_ring
**rings
, int offset
)
1684 struct ice_aqc_add_tx_qgrp
*qg_buf
;
1685 struct ice_aqc_add_txqs_perq
*txq
;
1686 struct ice_pf
*pf
= vsi
->back
;
1687 u8 num_q_grps
, q_idx
= 0;
1688 enum ice_status status
;
1689 u16 buf_len
, i
, pf_q
;
1692 buf_len
= sizeof(*qg_buf
);
1693 qg_buf
= devm_kzalloc(&pf
->pdev
->dev
, buf_len
, GFP_KERNEL
);
1697 qg_buf
->num_txqs
= 1;
1700 /* set up and configure the Tx queues for each enabled TC */
1701 ice_for_each_traffic_class(tc
) {
1702 if (!(vsi
->tc_cfg
.ena_tc
& BIT(tc
)))
1705 for (i
= 0; i
< vsi
->tc_cfg
.tc_info
[tc
].qcount_tx
; i
++) {
1706 struct ice_tlan_ctx tlan_ctx
= { 0 };
1708 pf_q
= vsi
->txq_map
[q_idx
+ offset
];
1709 ice_setup_tx_ctx(rings
[q_idx
], &tlan_ctx
, pf_q
);
1710 /* copy context contents into the qg_buf */
1711 qg_buf
->txqs
[0].txq_id
= cpu_to_le16(pf_q
);
1712 ice_set_ctx((u8
*)&tlan_ctx
, qg_buf
->txqs
[0].txq_ctx
,
1715 /* init queue specific tail reg. It is referred as
1716 * transmit comm scheduler queue doorbell.
1718 rings
[q_idx
]->tail
=
1719 pf
->hw
.hw_addr
+ QTX_COMM_DBELL(pf_q
);
1720 status
= ice_ena_vsi_txq(vsi
->port_info
, vsi
->idx
, tc
,
1721 i
, num_q_grps
, qg_buf
,
1724 dev_err(&pf
->pdev
->dev
,
1725 "Failed to set LAN Tx queue context, error: %d\n",
1731 /* Add Tx Queue TEID into the VSI Tx ring from the
1732 * response. This will complete configuring and
1733 * enabling the queue.
1735 txq
= &qg_buf
->txqs
[0];
1736 if (pf_q
== le16_to_cpu(txq
->txq_id
))
1737 rings
[q_idx
]->txq_teid
=
1738 le32_to_cpu(txq
->q_teid
);
1744 devm_kfree(&pf
->pdev
->dev
, qg_buf
);
1749 * ice_vsi_cfg_lan_txqs - Configure the VSI for Tx
1750 * @vsi: the VSI being configured
1752 * Return 0 on success and a negative value on error
1753 * Configure the Tx VSI for operation.
1755 int ice_vsi_cfg_lan_txqs(struct ice_vsi
*vsi
)
1757 return ice_vsi_cfg_txqs(vsi
, vsi
->tx_rings
, 0);
1761 * ice_intrl_usec_to_reg - convert interrupt rate limit to register value
1762 * @intrl: interrupt rate limit in usecs
1763 * @gran: interrupt rate limit granularity in usecs
1765 * This function converts a decimal interrupt rate limit in usecs to the format
1766 * expected by firmware.
1768 u32
ice_intrl_usec_to_reg(u8 intrl
, u8 gran
)
1770 u32 val
= intrl
/ gran
;
1773 return val
| GLINT_RATE_INTRL_ENA_M
;
1778 * ice_cfg_itr_gran - set the ITR granularity to 2 usecs if not already set
1779 * @hw: board specific structure
1781 static void ice_cfg_itr_gran(struct ice_hw
*hw
)
1783 u32 regval
= rd32(hw
, GLINT_CTL
);
1785 /* no need to update global register if ITR gran is already set */
1786 if (!(regval
& GLINT_CTL_DIS_AUTOMASK_M
) &&
1787 (((regval
& GLINT_CTL_ITR_GRAN_200_M
) >>
1788 GLINT_CTL_ITR_GRAN_200_S
) == ICE_ITR_GRAN_US
) &&
1789 (((regval
& GLINT_CTL_ITR_GRAN_100_M
) >>
1790 GLINT_CTL_ITR_GRAN_100_S
) == ICE_ITR_GRAN_US
) &&
1791 (((regval
& GLINT_CTL_ITR_GRAN_50_M
) >>
1792 GLINT_CTL_ITR_GRAN_50_S
) == ICE_ITR_GRAN_US
) &&
1793 (((regval
& GLINT_CTL_ITR_GRAN_25_M
) >>
1794 GLINT_CTL_ITR_GRAN_25_S
) == ICE_ITR_GRAN_US
))
1797 regval
= ((ICE_ITR_GRAN_US
<< GLINT_CTL_ITR_GRAN_200_S
) &
1798 GLINT_CTL_ITR_GRAN_200_M
) |
1799 ((ICE_ITR_GRAN_US
<< GLINT_CTL_ITR_GRAN_100_S
) &
1800 GLINT_CTL_ITR_GRAN_100_M
) |
1801 ((ICE_ITR_GRAN_US
<< GLINT_CTL_ITR_GRAN_50_S
) &
1802 GLINT_CTL_ITR_GRAN_50_M
) |
1803 ((ICE_ITR_GRAN_US
<< GLINT_CTL_ITR_GRAN_25_S
) &
1804 GLINT_CTL_ITR_GRAN_25_M
);
1805 wr32(hw
, GLINT_CTL
, regval
);
1809 * ice_cfg_itr - configure the initial interrupt throttle values
1810 * @hw: pointer to the HW structure
1811 * @q_vector: interrupt vector that's being configured
1813 * Configure interrupt throttling values for the ring containers that are
1814 * associated with the interrupt vector passed in.
1817 ice_cfg_itr(struct ice_hw
*hw
, struct ice_q_vector
*q_vector
)
1819 ice_cfg_itr_gran(hw
);
1821 if (q_vector
->num_ring_rx
) {
1822 struct ice_ring_container
*rc
= &q_vector
->rx
;
1824 /* if this value is set then don't overwrite with default */
1825 if (!rc
->itr_setting
)
1826 rc
->itr_setting
= ICE_DFLT_RX_ITR
;
1828 rc
->target_itr
= ITR_TO_REG(rc
->itr_setting
);
1829 rc
->next_update
= jiffies
+ 1;
1830 rc
->current_itr
= rc
->target_itr
;
1831 wr32(hw
, GLINT_ITR(rc
->itr_idx
, q_vector
->reg_idx
),
1832 ITR_REG_ALIGN(rc
->current_itr
) >> ICE_ITR_GRAN_S
);
1835 if (q_vector
->num_ring_tx
) {
1836 struct ice_ring_container
*rc
= &q_vector
->tx
;
1838 /* if this value is set then don't overwrite with default */
1839 if (!rc
->itr_setting
)
1840 rc
->itr_setting
= ICE_DFLT_TX_ITR
;
1842 rc
->target_itr
= ITR_TO_REG(rc
->itr_setting
);
1843 rc
->next_update
= jiffies
+ 1;
1844 rc
->current_itr
= rc
->target_itr
;
1845 wr32(hw
, GLINT_ITR(rc
->itr_idx
, q_vector
->reg_idx
),
1846 ITR_REG_ALIGN(rc
->current_itr
) >> ICE_ITR_GRAN_S
);
1851 * ice_vsi_cfg_msix - MSIX mode Interrupt Config in the HW
1852 * @vsi: the VSI being configured
1854 void ice_vsi_cfg_msix(struct ice_vsi
*vsi
)
1856 struct ice_pf
*pf
= vsi
->back
;
1857 struct ice_hw
*hw
= &pf
->hw
;
1858 u32 txq
= 0, rxq
= 0;
1861 for (i
= 0; i
< vsi
->num_q_vectors
; i
++) {
1862 struct ice_q_vector
*q_vector
= vsi
->q_vectors
[i
];
1863 u16 reg_idx
= q_vector
->reg_idx
;
1865 ice_cfg_itr(hw
, q_vector
);
1867 wr32(hw
, GLINT_RATE(reg_idx
),
1868 ice_intrl_usec_to_reg(q_vector
->intrl
, hw
->intrl_gran
));
1870 /* Both Transmit Queue Interrupt Cause Control register
1871 * and Receive Queue Interrupt Cause control register
1872 * expects MSIX_INDX field to be the vector index
1873 * within the function space and not the absolute
1874 * vector index across PF or across device.
1875 * For SR-IOV VF VSIs queue vector index always starts
1876 * with 1 since first vector index(0) is used for OICR
1877 * in VF space. Since VMDq and other PF VSIs are within
1878 * the PF function space, use the vector index that is
1879 * tracked for this PF.
1881 for (q
= 0; q
< q_vector
->num_ring_tx
; q
++) {
1882 int itr_idx
= (q_vector
->tx
.itr_idx
<<
1883 QINT_TQCTL_ITR_INDX_S
) &
1884 QINT_TQCTL_ITR_INDX_M
;
1887 if (vsi
->type
== ICE_VSI_VF
)
1888 val
= QINT_TQCTL_CAUSE_ENA_M
| itr_idx
|
1889 (((i
+ 1) << QINT_TQCTL_MSIX_INDX_S
) &
1890 QINT_TQCTL_MSIX_INDX_M
);
1892 val
= QINT_TQCTL_CAUSE_ENA_M
| itr_idx
|
1893 ((reg_idx
<< QINT_TQCTL_MSIX_INDX_S
) &
1894 QINT_TQCTL_MSIX_INDX_M
);
1895 wr32(hw
, QINT_TQCTL(vsi
->txq_map
[txq
]), val
);
1899 for (q
= 0; q
< q_vector
->num_ring_rx
; q
++) {
1900 int itr_idx
= (q_vector
->rx
.itr_idx
<<
1901 QINT_RQCTL_ITR_INDX_S
) &
1902 QINT_RQCTL_ITR_INDX_M
;
1905 if (vsi
->type
== ICE_VSI_VF
)
1906 val
= QINT_RQCTL_CAUSE_ENA_M
| itr_idx
|
1907 (((i
+ 1) << QINT_RQCTL_MSIX_INDX_S
) &
1908 QINT_RQCTL_MSIX_INDX_M
);
1910 val
= QINT_RQCTL_CAUSE_ENA_M
| itr_idx
|
1911 ((reg_idx
<< QINT_RQCTL_MSIX_INDX_S
) &
1912 QINT_RQCTL_MSIX_INDX_M
);
1913 wr32(hw
, QINT_RQCTL(vsi
->rxq_map
[rxq
]), val
);
1922 * ice_vsi_manage_vlan_insertion - Manage VLAN insertion for the VSI for Tx
1923 * @vsi: the VSI being changed
1925 int ice_vsi_manage_vlan_insertion(struct ice_vsi
*vsi
)
1927 struct device
*dev
= &vsi
->back
->pdev
->dev
;
1928 struct ice_hw
*hw
= &vsi
->back
->hw
;
1929 struct ice_vsi_ctx
*ctxt
;
1930 enum ice_status status
;
1933 ctxt
= devm_kzalloc(dev
, sizeof(*ctxt
), GFP_KERNEL
);
1937 /* Here we are configuring the VSI to let the driver add VLAN tags by
1938 * setting vlan_flags to ICE_AQ_VSI_VLAN_MODE_ALL. The actual VLAN tag
1939 * insertion happens in the Tx hot path, in ice_tx_map.
1941 ctxt
->info
.vlan_flags
= ICE_AQ_VSI_VLAN_MODE_ALL
;
1943 /* Preserve existing VLAN strip setting */
1944 ctxt
->info
.vlan_flags
|= (vsi
->info
.vlan_flags
&
1945 ICE_AQ_VSI_VLAN_EMOD_M
);
1947 ctxt
->info
.valid_sections
= cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID
);
1949 status
= ice_update_vsi(hw
, vsi
->idx
, ctxt
, NULL
);
1951 dev_err(dev
, "update VSI for VLAN insert failed, err %d aq_err %d\n",
1952 status
, hw
->adminq
.sq_last_status
);
1957 vsi
->info
.vlan_flags
= ctxt
->info
.vlan_flags
;
1959 devm_kfree(dev
, ctxt
);
1964 * ice_vsi_manage_vlan_stripping - Manage VLAN stripping for the VSI for Rx
1965 * @vsi: the VSI being changed
1966 * @ena: boolean value indicating if this is a enable or disable request
1968 int ice_vsi_manage_vlan_stripping(struct ice_vsi
*vsi
, bool ena
)
1970 struct device
*dev
= &vsi
->back
->pdev
->dev
;
1971 struct ice_hw
*hw
= &vsi
->back
->hw
;
1972 struct ice_vsi_ctx
*ctxt
;
1973 enum ice_status status
;
1976 ctxt
= devm_kzalloc(dev
, sizeof(*ctxt
), GFP_KERNEL
);
1980 /* Here we are configuring what the VSI should do with the VLAN tag in
1981 * the Rx packet. We can either leave the tag in the packet or put it in
1982 * the Rx descriptor.
1985 /* Strip VLAN tag from Rx packet and put it in the desc */
1986 ctxt
->info
.vlan_flags
= ICE_AQ_VSI_VLAN_EMOD_STR_BOTH
;
1988 /* Disable stripping. Leave tag in packet */
1989 ctxt
->info
.vlan_flags
= ICE_AQ_VSI_VLAN_EMOD_NOTHING
;
1991 /* Allow all packets untagged/tagged */
1992 ctxt
->info
.vlan_flags
|= ICE_AQ_VSI_VLAN_MODE_ALL
;
1994 ctxt
->info
.valid_sections
= cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID
);
1996 status
= ice_update_vsi(hw
, vsi
->idx
, ctxt
, NULL
);
1998 dev_err(dev
, "update VSI for VLAN strip failed, ena = %d err %d aq_err %d\n",
1999 ena
, status
, hw
->adminq
.sq_last_status
);
2004 vsi
->info
.vlan_flags
= ctxt
->info
.vlan_flags
;
2006 devm_kfree(dev
, ctxt
);
2011 * ice_vsi_start_rx_rings - start VSI's Rx rings
2012 * @vsi: the VSI whose rings are to be started
2014 * Returns 0 on success and a negative value on error
2016 int ice_vsi_start_rx_rings(struct ice_vsi
*vsi
)
2018 return ice_vsi_ctrl_rx_rings(vsi
, true);
2022 * ice_vsi_stop_rx_rings - stop VSI's Rx rings
2025 * Returns 0 on success and a negative value on error
2027 int ice_vsi_stop_rx_rings(struct ice_vsi
*vsi
)
2029 return ice_vsi_ctrl_rx_rings(vsi
, false);
2033 * ice_vsi_stop_tx_rings - Disable Tx rings
2034 * @vsi: the VSI being configured
2035 * @rst_src: reset source
2036 * @rel_vmvf_num: Relative ID of VF/VM
2037 * @rings: Tx ring array to be stopped
2038 * @offset: offset within vsi->txq_map
2041 ice_vsi_stop_tx_rings(struct ice_vsi
*vsi
, enum ice_disq_rst_src rst_src
,
2042 u16 rel_vmvf_num
, struct ice_ring
**rings
, int offset
)
2044 struct ice_pf
*pf
= vsi
->back
;
2045 struct ice_hw
*hw
= &pf
->hw
;
2046 int tc
, q_idx
= 0, err
= 0;
2047 u16
*q_ids
, *q_handles
, i
;
2048 enum ice_status status
;
2051 if (vsi
->num_txq
> ICE_LAN_TXQ_MAX_QDIS
)
2054 q_teids
= devm_kcalloc(&pf
->pdev
->dev
, vsi
->num_txq
, sizeof(*q_teids
),
2059 q_ids
= devm_kcalloc(&pf
->pdev
->dev
, vsi
->num_txq
, sizeof(*q_ids
),
2063 goto err_alloc_q_ids
;
2066 q_handles
= devm_kcalloc(&pf
->pdev
->dev
, vsi
->num_txq
,
2067 sizeof(*q_handles
), GFP_KERNEL
);
2070 goto err_alloc_q_handles
;
2073 /* set up the Tx queue list to be disabled for each enabled TC */
2074 ice_for_each_traffic_class(tc
) {
2075 if (!(vsi
->tc_cfg
.ena_tc
& BIT(tc
)))
2078 for (i
= 0; i
< vsi
->tc_cfg
.tc_info
[tc
].qcount_tx
; i
++) {
2079 if (!rings
|| !rings
[q_idx
] ||
2080 !rings
[q_idx
]->q_vector
) {
2085 q_ids
[i
] = vsi
->txq_map
[q_idx
+ offset
];
2086 q_teids
[i
] = rings
[q_idx
]->txq_teid
;
2089 /* clear cause_ena bit for disabled queues */
2090 val
= rd32(hw
, QINT_TQCTL(rings
[i
]->reg_idx
));
2091 val
&= ~QINT_TQCTL_CAUSE_ENA_M
;
2092 wr32(hw
, QINT_TQCTL(rings
[i
]->reg_idx
), val
);
2094 /* software is expected to wait for 100 ns */
2097 /* trigger a software interrupt for the vector
2098 * associated to the queue to schedule NAPI handler
2100 wr32(hw
, GLINT_DYN_CTL(rings
[i
]->q_vector
->reg_idx
),
2101 GLINT_DYN_CTL_SWINT_TRIG_M
|
2102 GLINT_DYN_CTL_INTENA_MSK_M
);
2105 status
= ice_dis_vsi_txq(vsi
->port_info
, vsi
->idx
, tc
,
2106 vsi
->num_txq
, q_handles
, q_ids
,
2107 q_teids
, rst_src
, rel_vmvf_num
, NULL
);
2109 /* if the disable queue command was exercised during an active
2110 * reset flow, ICE_ERR_RESET_ONGOING is returned. This is not
2111 * an error as the reset operation disables queues at the
2112 * hardware level anyway.
2114 if (status
== ICE_ERR_RESET_ONGOING
) {
2115 dev_dbg(&pf
->pdev
->dev
,
2116 "Reset in progress. LAN Tx queues already disabled\n");
2117 } else if (status
) {
2118 dev_err(&pf
->pdev
->dev
,
2119 "Failed to disable LAN Tx queues, error: %d\n",
2126 devm_kfree(&pf
->pdev
->dev
, q_handles
);
2128 err_alloc_q_handles
:
2129 devm_kfree(&pf
->pdev
->dev
, q_ids
);
2132 devm_kfree(&pf
->pdev
->dev
, q_teids
);
2138 * ice_vsi_stop_lan_tx_rings - Disable LAN Tx rings
2139 * @vsi: the VSI being configured
2140 * @rst_src: reset source
2141 * @rel_vmvf_num: Relative ID of VF/VM
2144 ice_vsi_stop_lan_tx_rings(struct ice_vsi
*vsi
, enum ice_disq_rst_src rst_src
,
2147 return ice_vsi_stop_tx_rings(vsi
, rst_src
, rel_vmvf_num
, vsi
->tx_rings
,
2152 * ice_cfg_vlan_pruning - enable or disable VLAN pruning on the VSI
2153 * @vsi: VSI to enable or disable VLAN pruning on
2154 * @ena: set to true to enable VLAN pruning and false to disable it
2155 * @vlan_promisc: enable valid security flags if not in VLAN promiscuous mode
2157 * returns 0 if VSI is updated, negative otherwise
2159 int ice_cfg_vlan_pruning(struct ice_vsi
*vsi
, bool ena
, bool vlan_promisc
)
2161 struct ice_vsi_ctx
*ctxt
;
2170 dev
= &pf
->pdev
->dev
;
2171 ctxt
= devm_kzalloc(dev
, sizeof(*ctxt
), GFP_KERNEL
);
2175 ctxt
->info
= vsi
->info
;
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
;
2183 ctxt
->info
.sec_flags
&=
2184 ~(ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA
<<
2185 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S
);
2186 ctxt
->info
.sw_flags2
&= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA
;
2190 ctxt
->info
.valid_sections
=
2191 cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID
|
2192 ICE_AQ_VSI_PROP_SW_VALID
);
2194 status
= ice_update_vsi(&pf
->hw
, vsi
->idx
, ctxt
, NULL
);
2196 netdev_err(vsi
->netdev
, "%sabling VLAN pruning on VSI handle: %d, VSI HW ID: %d failed, err = %d, aq_err = %d\n",
2197 ena
? "En" : "Dis", vsi
->idx
, vsi
->vsi_num
, status
,
2198 pf
->hw
.adminq
.sq_last_status
);
2202 vsi
->info
.sec_flags
= ctxt
->info
.sec_flags
;
2203 vsi
->info
.sw_flags2
= ctxt
->info
.sw_flags2
;
2205 devm_kfree(dev
, ctxt
);
2209 devm_kfree(dev
, ctxt
);
2213 static void ice_vsi_set_tc_cfg(struct ice_vsi
*vsi
)
2215 struct ice_dcbx_cfg
*cfg
= &vsi
->port_info
->local_dcbx_cfg
;
2217 vsi
->tc_cfg
.ena_tc
= ice_dcb_get_ena_tc(cfg
);
2218 vsi
->tc_cfg
.numtc
= ice_dcb_get_num_tc(cfg
);
2222 * ice_vsi_set_q_vectors_reg_idx - set the HW register index for all q_vectors
2223 * @vsi: VSI to set the q_vectors register index on
2226 ice_vsi_set_q_vectors_reg_idx(struct ice_vsi
*vsi
)
2230 if (!vsi
|| !vsi
->q_vectors
)
2233 ice_for_each_q_vector(vsi
, i
) {
2234 struct ice_q_vector
*q_vector
= vsi
->q_vectors
[i
];
2237 dev_err(&vsi
->back
->pdev
->dev
,
2238 "Failed to set reg_idx on q_vector %d VSI %d\n",
2243 q_vector
->reg_idx
= q_vector
->v_idx
+ vsi
->hw_base_vector
;
2249 ice_for_each_q_vector(vsi
, i
) {
2250 struct ice_q_vector
*q_vector
= vsi
->q_vectors
[i
];
2253 q_vector
->reg_idx
= 0;
2260 * ice_vsi_setup - Set up a VSI by a given type
2261 * @pf: board private structure
2262 * @pi: pointer to the port_info instance
2264 * @vf_id: defines VF ID to which this VSI connects. This field is meant to be
2265 * used only for ICE_VSI_VF VSI type. For other VSI types, should
2266 * fill-in ICE_INVAL_VFID as input.
2268 * This allocates the sw VSI structure and its queue resources.
2270 * Returns pointer to the successfully allocated and configured VSI sw struct on
2271 * success, NULL on failure.
2274 ice_vsi_setup(struct ice_pf
*pf
, struct ice_port_info
*pi
,
2275 enum ice_vsi_type type
, u16 vf_id
)
2277 u16 max_txqs
[ICE_MAX_TRAFFIC_CLASS
] = { 0 };
2278 struct device
*dev
= &pf
->pdev
->dev
;
2279 struct ice_vsi
*vsi
;
2282 if (type
== ICE_VSI_VF
)
2283 vsi
= ice_vsi_alloc(pf
, type
, vf_id
);
2285 vsi
= ice_vsi_alloc(pf
, type
, ICE_INVAL_VFID
);
2288 dev_err(dev
, "could not allocate VSI\n");
2292 vsi
->port_info
= pi
;
2293 vsi
->vsw
= pf
->first_sw
;
2294 if (vsi
->type
== ICE_VSI_VF
)
2297 if (ice_vsi_get_qs(vsi
)) {
2298 dev_err(dev
, "Failed to allocate queues. vsi->idx = %d\n",
2303 /* set RSS capabilities */
2304 ice_vsi_set_rss_params(vsi
);
2306 /* set TC configuration */
2307 ice_vsi_set_tc_cfg(vsi
);
2309 /* create the VSI */
2310 ret
= ice_vsi_init(vsi
);
2314 switch (vsi
->type
) {
2316 ret
= ice_vsi_alloc_q_vectors(vsi
);
2318 goto unroll_vsi_init
;
2320 ret
= ice_vsi_setup_vector_base(vsi
);
2322 goto unroll_alloc_q_vector
;
2324 ret
= ice_vsi_set_q_vectors_reg_idx(vsi
);
2326 goto unroll_vector_base
;
2328 ret
= ice_vsi_alloc_rings(vsi
);
2330 goto unroll_vector_base
;
2332 ice_vsi_map_rings_to_vectors(vsi
);
2334 /* Do not exit if configuring RSS had an issue, at least
2335 * receive traffic on first queue. Hence no need to capture
2338 if (test_bit(ICE_FLAG_RSS_ENA
, pf
->flags
))
2339 ice_vsi_cfg_rss_lut_key(vsi
);
2342 /* VF driver will take care of creating netdev for this type and
2343 * map queues to vectors through Virtchnl, PF driver only
2344 * creates a VSI and corresponding structures for bookkeeping
2347 ret
= ice_vsi_alloc_q_vectors(vsi
);
2349 goto unroll_vsi_init
;
2351 ret
= ice_vsi_alloc_rings(vsi
);
2353 goto unroll_alloc_q_vector
;
2355 /* Setup Vector base only during VF init phase or when VF asks
2356 * for more vectors than assigned number. In all other cases,
2357 * assign hw_base_vector to the value given earlier.
2359 if (test_bit(ICE_VF_STATE_CFG_INTR
, pf
->vf
[vf_id
].vf_states
)) {
2360 ret
= ice_vsi_setup_vector_base(vsi
);
2362 goto unroll_vector_base
;
2364 vsi
->hw_base_vector
= pf
->vf
[vf_id
].first_vector_idx
;
2366 ret
= ice_vsi_set_q_vectors_reg_idx(vsi
);
2368 goto unroll_vector_base
;
2370 pf
->q_left_tx
-= vsi
->alloc_txq
;
2371 pf
->q_left_rx
-= vsi
->alloc_rxq
;
2374 /* clean up the resources and exit */
2375 goto unroll_vsi_init
;
2378 /* configure VSI nodes based on number of queues and TC's */
2379 for (i
= 0; i
< vsi
->tc_cfg
.numtc
; i
++)
2380 max_txqs
[i
] = pf
->num_lan_tx
;
2382 ret
= ice_cfg_vsi_lan(vsi
->port_info
, vsi
->idx
, vsi
->tc_cfg
.ena_tc
,
2385 dev_err(&pf
->pdev
->dev
,
2386 "VSI %d failed lan queue config, error %d\n",
2388 goto unroll_vector_base
;
2394 /* reclaim SW interrupts back to the common pool */
2395 ice_free_res(pf
->sw_irq_tracker
, vsi
->sw_base_vector
, vsi
->idx
);
2396 pf
->num_avail_sw_msix
+= vsi
->num_q_vectors
;
2397 /* reclaim HW interrupt back to the common pool */
2398 ice_free_res(pf
->hw_irq_tracker
, vsi
->hw_base_vector
, vsi
->idx
);
2399 pf
->num_avail_hw_msix
+= vsi
->num_q_vectors
;
2400 unroll_alloc_q_vector
:
2401 ice_vsi_free_q_vectors(vsi
);
2403 ice_vsi_delete(vsi
);
2405 ice_vsi_put_qs(vsi
);
2406 pf
->q_left_tx
+= vsi
->alloc_txq
;
2407 pf
->q_left_rx
+= vsi
->alloc_rxq
;
2414 * ice_vsi_release_msix - Clear the queue to Interrupt mapping in HW
2415 * @vsi: the VSI being cleaned up
2417 static void ice_vsi_release_msix(struct ice_vsi
*vsi
)
2419 struct ice_pf
*pf
= vsi
->back
;
2420 u16 vector
= vsi
->hw_base_vector
;
2421 struct ice_hw
*hw
= &pf
->hw
;
2426 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
2427 struct ice_q_vector
*q_vector
= vsi
->q_vectors
[i
];
2429 wr32(hw
, GLINT_ITR(ICE_IDX_ITR0
, vector
), 0);
2430 wr32(hw
, GLINT_ITR(ICE_IDX_ITR1
, vector
), 0);
2431 for (q
= 0; q
< q_vector
->num_ring_tx
; q
++) {
2432 wr32(hw
, QINT_TQCTL(vsi
->txq_map
[txq
]), 0);
2436 for (q
= 0; q
< q_vector
->num_ring_rx
; q
++) {
2437 wr32(hw
, QINT_RQCTL(vsi
->rxq_map
[rxq
]), 0);
2446 * ice_vsi_free_irq - Free the IRQ association with the OS
2447 * @vsi: the VSI being configured
2449 void ice_vsi_free_irq(struct ice_vsi
*vsi
)
2451 struct ice_pf
*pf
= vsi
->back
;
2452 int base
= vsi
->sw_base_vector
;
2454 if (test_bit(ICE_FLAG_MSIX_ENA
, pf
->flags
)) {
2457 if (!vsi
->q_vectors
|| !vsi
->irqs_ready
)
2460 ice_vsi_release_msix(vsi
);
2461 if (vsi
->type
== ICE_VSI_VF
)
2464 vsi
->irqs_ready
= false;
2465 ice_for_each_q_vector(vsi
, i
) {
2466 u16 vector
= i
+ base
;
2469 irq_num
= pf
->msix_entries
[vector
].vector
;
2471 /* free only the irqs that were actually requested */
2472 if (!vsi
->q_vectors
[i
] ||
2473 !(vsi
->q_vectors
[i
]->num_ring_tx
||
2474 vsi
->q_vectors
[i
]->num_ring_rx
))
2477 /* clear the affinity notifier in the IRQ descriptor */
2478 irq_set_affinity_notifier(irq_num
, NULL
);
2480 /* clear the affinity_mask in the IRQ descriptor */
2481 irq_set_affinity_hint(irq_num
, NULL
);
2482 synchronize_irq(irq_num
);
2483 devm_free_irq(&pf
->pdev
->dev
, irq_num
,
2490 * ice_vsi_free_tx_rings - Free Tx resources for VSI queues
2491 * @vsi: the VSI having resources freed
2493 void ice_vsi_free_tx_rings(struct ice_vsi
*vsi
)
2500 ice_for_each_txq(vsi
, i
)
2501 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
)
2502 ice_free_tx_ring(vsi
->tx_rings
[i
]);
2506 * ice_vsi_free_rx_rings - Free Rx resources for VSI queues
2507 * @vsi: the VSI having resources freed
2509 void ice_vsi_free_rx_rings(struct ice_vsi
*vsi
)
2516 ice_for_each_rxq(vsi
, i
)
2517 if (vsi
->rx_rings
[i
] && vsi
->rx_rings
[i
]->desc
)
2518 ice_free_rx_ring(vsi
->rx_rings
[i
]);
2522 * ice_vsi_close - Shut down a VSI
2523 * @vsi: the VSI being shut down
2525 void ice_vsi_close(struct ice_vsi
*vsi
)
2527 if (!test_and_set_bit(__ICE_DOWN
, vsi
->state
))
2530 ice_vsi_free_irq(vsi
);
2531 ice_vsi_free_tx_rings(vsi
);
2532 ice_vsi_free_rx_rings(vsi
);
2536 * ice_free_res - free a block of resources
2537 * @res: pointer to the resource
2538 * @index: starting index previously returned by ice_get_res
2539 * @id: identifier to track owner
2541 * Returns number of resources freed
2543 int ice_free_res(struct ice_res_tracker
*res
, u16 index
, u16 id
)
2548 if (!res
|| index
>= res
->num_entries
)
2551 id
|= ICE_RES_VALID_BIT
;
2552 for (i
= index
; i
< res
->num_entries
&& res
->list
[i
] == id
; i
++) {
2561 * ice_search_res - Search the tracker for a block of resources
2562 * @res: pointer to the resource
2563 * @needed: size of the block needed
2564 * @id: identifier to track owner
2566 * Returns the base item index of the block, or -ENOMEM for error
2568 static int ice_search_res(struct ice_res_tracker
*res
, u16 needed
, u16 id
)
2570 int start
= res
->search_hint
;
2573 if ((start
+ needed
) > res
->num_entries
)
2576 id
|= ICE_RES_VALID_BIT
;
2579 /* skip already allocated entries */
2580 if (res
->list
[end
++] & ICE_RES_VALID_BIT
) {
2582 if ((start
+ needed
) > res
->num_entries
)
2586 if (end
== (start
+ needed
)) {
2589 /* there was enough, so assign it to the requestor */
2591 res
->list
[i
++] = id
;
2593 if (end
== res
->num_entries
)
2596 res
->search_hint
= end
;
2605 * ice_get_res - get a block of resources
2606 * @pf: board private structure
2607 * @res: pointer to the resource
2608 * @needed: size of the block needed
2609 * @id: identifier to track owner
2611 * Returns the base item index of the block, or -ENOMEM for error
2612 * The search_hint trick and lack of advanced fit-finding only works
2613 * because we're highly likely to have all the same sized requests.
2614 * Linear search time and any fragmentation should be minimal.
2617 ice_get_res(struct ice_pf
*pf
, struct ice_res_tracker
*res
, u16 needed
, u16 id
)
2624 if (!needed
|| needed
> res
->num_entries
|| id
>= ICE_RES_VALID_BIT
) {
2625 dev_err(&pf
->pdev
->dev
,
2626 "param err: needed=%d, num_entries = %d id=0x%04x\n",
2627 needed
, res
->num_entries
, id
);
2631 /* search based on search_hint */
2632 ret
= ice_search_res(res
, needed
, id
);
2635 /* previous search failed. Reset search hint and try again */
2636 res
->search_hint
= 0;
2637 ret
= ice_search_res(res
, needed
, id
);
2644 * ice_vsi_dis_irq - Mask off queue interrupt generation on the VSI
2645 * @vsi: the VSI being un-configured
2647 void ice_vsi_dis_irq(struct ice_vsi
*vsi
)
2649 int base
= vsi
->sw_base_vector
;
2650 struct ice_pf
*pf
= vsi
->back
;
2651 struct ice_hw
*hw
= &pf
->hw
;
2655 /* disable interrupt causation from each queue */
2656 if (vsi
->tx_rings
) {
2657 ice_for_each_txq(vsi
, i
) {
2658 if (vsi
->tx_rings
[i
]) {
2661 reg
= vsi
->tx_rings
[i
]->reg_idx
;
2662 val
= rd32(hw
, QINT_TQCTL(reg
));
2663 val
&= ~QINT_TQCTL_CAUSE_ENA_M
;
2664 wr32(hw
, QINT_TQCTL(reg
), val
);
2669 if (vsi
->rx_rings
) {
2670 ice_for_each_rxq(vsi
, i
) {
2671 if (vsi
->rx_rings
[i
]) {
2674 reg
= vsi
->rx_rings
[i
]->reg_idx
;
2675 val
= rd32(hw
, QINT_RQCTL(reg
));
2676 val
&= ~QINT_RQCTL_CAUSE_ENA_M
;
2677 wr32(hw
, QINT_RQCTL(reg
), val
);
2682 /* disable each interrupt */
2683 if (test_bit(ICE_FLAG_MSIX_ENA
, pf
->flags
)) {
2684 ice_for_each_q_vector(vsi
, i
)
2685 wr32(hw
, GLINT_DYN_CTL(vsi
->q_vectors
[i
]->reg_idx
), 0);
2689 ice_for_each_q_vector(vsi
, i
)
2690 synchronize_irq(pf
->msix_entries
[i
+ base
].vector
);
2695 * ice_vsi_release - Delete a VSI and free its resources
2696 * @vsi: the VSI being removed
2698 * Returns 0 on success or < 0 on error
2700 int ice_vsi_release(struct ice_vsi
*vsi
)
2702 struct ice_vf
*vf
= NULL
;
2709 if (vsi
->type
== ICE_VSI_VF
)
2710 vf
= &pf
->vf
[vsi
->vf_id
];
2711 /* do not unregister and free netdevs while driver is in the reset
2712 * recovery pending state. Since reset/rebuild happens through PF
2713 * service task workqueue, its not a good idea to unregister netdev
2714 * that is associated to the PF that is running the work queue items
2715 * currently. This is done to avoid check_flush_dependency() warning
2718 if (vsi
->netdev
&& !ice_is_reset_in_progress(pf
->state
)) {
2720 unregister_netdev(vsi
->netdev
);
2721 free_netdev(vsi
->netdev
);
2725 if (test_bit(ICE_FLAG_RSS_ENA
, pf
->flags
))
2728 /* Disable VSI and free resources */
2729 ice_vsi_dis_irq(vsi
);
2732 /* reclaim interrupt vectors back to PF */
2733 if (vsi
->type
!= ICE_VSI_VF
) {
2734 /* reclaim SW interrupts back to the common pool */
2735 ice_free_res(pf
->sw_irq_tracker
, vsi
->sw_base_vector
, vsi
->idx
);
2736 pf
->num_avail_sw_msix
+= vsi
->num_q_vectors
;
2737 /* reclaim HW interrupts back to the common pool */
2738 ice_free_res(pf
->hw_irq_tracker
, vsi
->hw_base_vector
, vsi
->idx
);
2739 pf
->num_avail_hw_msix
+= vsi
->num_q_vectors
;
2740 } else if (test_bit(ICE_VF_STATE_CFG_INTR
, vf
->vf_states
)) {
2741 /* Reclaim VF resources back only while freeing all VFs or
2742 * vector reassignment is requested
2744 ice_free_res(pf
->hw_irq_tracker
, vf
->first_vector_idx
,
2746 pf
->num_avail_hw_msix
+= pf
->num_vf_msix
;
2749 ice_remove_vsi_fltr(&pf
->hw
, vsi
->idx
);
2750 ice_rm_vsi_lan_cfg(vsi
->port_info
, vsi
->idx
);
2751 ice_vsi_delete(vsi
);
2752 ice_vsi_free_q_vectors(vsi
);
2753 ice_vsi_clear_rings(vsi
);
2755 ice_vsi_put_qs(vsi
);
2756 pf
->q_left_tx
+= vsi
->alloc_txq
;
2757 pf
->q_left_rx
+= vsi
->alloc_rxq
;
2759 /* retain SW VSI data structure since it is needed to unregister and
2760 * free VSI netdev when PF is not in reset recovery pending state,\
2761 * for ex: during rmmod.
2763 if (!ice_is_reset_in_progress(pf
->state
))
2770 * ice_vsi_rebuild - Rebuild VSI after reset
2771 * @vsi: VSI to be rebuild
2773 * Returns 0 on success and negative value on failure
2775 int ice_vsi_rebuild(struct ice_vsi
*vsi
)
2777 u16 max_txqs
[ICE_MAX_TRAFFIC_CLASS
] = { 0 };
2778 struct ice_vf
*vf
= NULL
;
2786 if (vsi
->type
== ICE_VSI_VF
)
2787 vf
= &pf
->vf
[vsi
->vf_id
];
2789 ice_rm_vsi_lan_cfg(vsi
->port_info
, vsi
->idx
);
2790 ice_vsi_free_q_vectors(vsi
);
2792 if (vsi
->type
!= ICE_VSI_VF
) {
2793 /* reclaim SW interrupts back to the common pool */
2794 ice_free_res(pf
->sw_irq_tracker
, vsi
->sw_base_vector
, vsi
->idx
);
2795 pf
->num_avail_sw_msix
+= vsi
->num_q_vectors
;
2796 vsi
->sw_base_vector
= 0;
2797 /* reclaim HW interrupts back to the common pool */
2798 ice_free_res(pf
->hw_irq_tracker
, vsi
->hw_base_vector
,
2800 pf
->num_avail_hw_msix
+= vsi
->num_q_vectors
;
2802 /* Reclaim VF resources back to the common pool for reset and
2803 * and rebuild, with vector reassignment
2805 ice_free_res(pf
->hw_irq_tracker
, vf
->first_vector_idx
,
2807 pf
->num_avail_hw_msix
+= pf
->num_vf_msix
;
2809 vsi
->hw_base_vector
= 0;
2811 ice_vsi_clear_rings(vsi
);
2812 ice_vsi_free_arrays(vsi
, false);
2813 ice_dev_onetime_setup(&pf
->hw
);
2814 if (vsi
->type
== ICE_VSI_VF
)
2815 ice_vsi_set_num_qs(vsi
, vf
->vf_id
);
2817 ice_vsi_set_num_qs(vsi
, ICE_INVAL_VFID
);
2818 ice_vsi_set_tc_cfg(vsi
);
2820 /* Initialize VSI struct elements and create VSI in FW */
2821 ret
= ice_vsi_init(vsi
);
2825 ret
= ice_vsi_alloc_arrays(vsi
, false);
2829 switch (vsi
->type
) {
2831 ret
= ice_vsi_alloc_q_vectors(vsi
);
2835 ret
= ice_vsi_setup_vector_base(vsi
);
2839 ret
= ice_vsi_set_q_vectors_reg_idx(vsi
);
2843 ret
= ice_vsi_alloc_rings(vsi
);
2847 ice_vsi_map_rings_to_vectors(vsi
);
2848 /* Do not exit if configuring RSS had an issue, at least
2849 * receive traffic on first queue. Hence no need to capture
2852 if (test_bit(ICE_FLAG_RSS_ENA
, pf
->flags
))
2853 ice_vsi_cfg_rss_lut_key(vsi
);
2856 ret
= ice_vsi_alloc_q_vectors(vsi
);
2860 ret
= ice_vsi_setup_vector_base(vsi
);
2864 ret
= ice_vsi_set_q_vectors_reg_idx(vsi
);
2868 ret
= ice_vsi_alloc_rings(vsi
);
2872 pf
->q_left_tx
-= vsi
->alloc_txq
;
2873 pf
->q_left_rx
-= vsi
->alloc_rxq
;
2879 /* configure VSI nodes based on number of queues and TC's */
2880 for (i
= 0; i
< vsi
->tc_cfg
.numtc
; i
++)
2881 max_txqs
[i
] = pf
->num_lan_tx
;
2883 ret
= ice_cfg_vsi_lan(vsi
->port_info
, vsi
->idx
, vsi
->tc_cfg
.ena_tc
,
2886 dev_err(&pf
->pdev
->dev
,
2887 "VSI %d failed lan queue config, error %d\n",
2894 ice_vsi_free_q_vectors(vsi
);
2897 vsi
->current_netdev_flags
= 0;
2898 unregister_netdev(vsi
->netdev
);
2899 free_netdev(vsi
->netdev
);
2904 set_bit(__ICE_RESET_FAILED
, pf
->state
);
2909 * ice_is_reset_in_progress - check for a reset in progress
2910 * @state: pf state field
2912 bool ice_is_reset_in_progress(unsigned long *state
)
2914 return test_bit(__ICE_RESET_OICR_RECV
, state
) ||
2915 test_bit(__ICE_PFR_REQ
, state
) ||
2916 test_bit(__ICE_CORER_REQ
, state
) ||
2917 test_bit(__ICE_GLOBR_REQ
, state
);
2922 * ice_vsi_update_q_map - update our copy of the VSI info with new queue map
2923 * @vsi: VSI being configured
2924 * @ctx: the context buffer returned from AQ VSI update command
2926 static void ice_vsi_update_q_map(struct ice_vsi
*vsi
, struct ice_vsi_ctx
*ctx
)
2928 vsi
->info
.mapping_flags
= ctx
->info
.mapping_flags
;
2929 memcpy(&vsi
->info
.q_mapping
, &ctx
->info
.q_mapping
,
2930 sizeof(vsi
->info
.q_mapping
));
2931 memcpy(&vsi
->info
.tc_mapping
, ctx
->info
.tc_mapping
,
2932 sizeof(vsi
->info
.tc_mapping
));
2936 * ice_vsi_cfg_netdev_tc - Setup the netdev TC configuration
2937 * @vsi: the VSI being configured
2938 * @ena_tc: TC map to be enabled
2940 static void ice_vsi_cfg_netdev_tc(struct ice_vsi
*vsi
, u8 ena_tc
)
2942 struct net_device
*netdev
= vsi
->netdev
;
2943 struct ice_pf
*pf
= vsi
->back
;
2944 struct ice_dcbx_cfg
*dcbcfg
;
2952 netdev_reset_tc(netdev
);
2956 if (netdev_set_num_tc(netdev
, vsi
->tc_cfg
.numtc
))
2959 dcbcfg
= &pf
->hw
.port_info
->local_dcbx_cfg
;
2961 ice_for_each_traffic_class(i
)
2962 if (vsi
->tc_cfg
.ena_tc
& BIT(i
))
2963 netdev_set_tc_queue(netdev
,
2964 vsi
->tc_cfg
.tc_info
[i
].netdev_tc
,
2965 vsi
->tc_cfg
.tc_info
[i
].qcount_tx
,
2966 vsi
->tc_cfg
.tc_info
[i
].qoffset
);
2968 for (i
= 0; i
< ICE_MAX_USER_PRIORITY
; i
++) {
2969 u8 ets_tc
= dcbcfg
->etscfg
.prio_table
[i
];
2971 /* Get the mapped netdev TC# for the UP */
2972 netdev_tc
= vsi
->tc_cfg
.tc_info
[ets_tc
].netdev_tc
;
2973 netdev_set_prio_tc_map(netdev
, i
, netdev_tc
);
2978 * ice_vsi_cfg_tc - Configure VSI Tx Sched for given TC map
2979 * @vsi: VSI to be configured
2980 * @ena_tc: TC bitmap
2982 * VSI queues expected to be quiesced before calling this function
2984 int ice_vsi_cfg_tc(struct ice_vsi
*vsi
, u8 ena_tc
)
2986 u16 max_txqs
[ICE_MAX_TRAFFIC_CLASS
] = { 0 };
2987 struct ice_vsi_ctx
*ctx
;
2988 struct ice_pf
*pf
= vsi
->back
;
2989 enum ice_status status
;
2993 ice_for_each_traffic_class(i
) {
2994 /* build bitmap of enabled TCs */
2995 if (ena_tc
& BIT(i
))
2997 /* populate max_txqs per TC */
2998 max_txqs
[i
] = pf
->num_lan_tx
;
3001 vsi
->tc_cfg
.ena_tc
= ena_tc
;
3002 vsi
->tc_cfg
.numtc
= num_tc
;
3004 ctx
= devm_kzalloc(&pf
->pdev
->dev
, sizeof(*ctx
), GFP_KERNEL
);
3009 ctx
->info
= vsi
->info
;
3011 ice_vsi_setup_q_map(vsi
, ctx
);
3013 /* must to indicate which section of VSI context are being modified */
3014 ctx
->info
.valid_sections
= cpu_to_le16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID
);
3015 status
= ice_update_vsi(&pf
->hw
, vsi
->idx
, ctx
, NULL
);
3017 dev_info(&pf
->pdev
->dev
, "Failed VSI Update\n");
3022 status
= ice_cfg_vsi_lan(vsi
->port_info
, vsi
->idx
, vsi
->tc_cfg
.ena_tc
,
3026 dev_err(&pf
->pdev
->dev
,
3027 "VSI %d failed TC config, error %d\n",
3028 vsi
->vsi_num
, status
);
3032 ice_vsi_update_q_map(vsi
, ctx
);
3033 vsi
->info
.valid_sections
= 0;
3035 ice_vsi_cfg_netdev_tc(vsi
, ena_tc
);
3037 devm_kfree(&pf
->pdev
->dev
, ctx
);
3040 #endif /* CONFIG_DCB */