1eff380aaSAnirudh Venkataramanan // SPDX-License-Identifier: GPL-2.0
2eff380aaSAnirudh Venkataramanan /* Copyright (c) 2019, Intel Corporation. */
3eff380aaSAnirudh Venkataramanan
4175fc430SBjörn Töpel #include <net/xdp_sock_drv.h>
5eff380aaSAnirudh Venkataramanan #include "ice_base.h"
6401ce33bSBrett Creeley #include "ice_lib.h"
7eff380aaSAnirudh Venkataramanan #include "ice_dcb_lib.h"
80deb0bf7SJacob Keller #include "ice_sriov.h"
9eff380aaSAnirudh Venkataramanan
10eff380aaSAnirudh Venkataramanan /**
11eff380aaSAnirudh Venkataramanan * __ice_vsi_get_qs_contig - Assign a contiguous chunk of queues to VSI
12eff380aaSAnirudh Venkataramanan * @qs_cfg: gathered variables needed for PF->VSI queues assignment
13eff380aaSAnirudh Venkataramanan *
14eff380aaSAnirudh Venkataramanan * Return 0 on success and -ENOMEM in case of no left space in PF queue bitmap
15eff380aaSAnirudh Venkataramanan */
__ice_vsi_get_qs_contig(struct ice_qs_cfg * qs_cfg)16eff380aaSAnirudh Venkataramanan static int __ice_vsi_get_qs_contig(struct ice_qs_cfg *qs_cfg)
17eff380aaSAnirudh Venkataramanan {
1822bef5e7SJesse Brandeburg unsigned int offset, i;
19eff380aaSAnirudh Venkataramanan
20eff380aaSAnirudh Venkataramanan mutex_lock(qs_cfg->qs_mutex);
21eff380aaSAnirudh Venkataramanan offset = bitmap_find_next_zero_area(qs_cfg->pf_map, qs_cfg->pf_map_size,
22eff380aaSAnirudh Venkataramanan 0, qs_cfg->q_count, 0);
23eff380aaSAnirudh Venkataramanan if (offset >= qs_cfg->pf_map_size) {
24eff380aaSAnirudh Venkataramanan mutex_unlock(qs_cfg->qs_mutex);
25eff380aaSAnirudh Venkataramanan return -ENOMEM;
26eff380aaSAnirudh Venkataramanan }
27eff380aaSAnirudh Venkataramanan
28eff380aaSAnirudh Venkataramanan bitmap_set(qs_cfg->pf_map, offset, qs_cfg->q_count);
29eff380aaSAnirudh Venkataramanan for (i = 0; i < qs_cfg->q_count; i++)
3088865fc4SKarol Kolacinski qs_cfg->vsi_map[i + qs_cfg->vsi_map_offset] = (u16)(i + offset);
31eff380aaSAnirudh Venkataramanan mutex_unlock(qs_cfg->qs_mutex);
32eff380aaSAnirudh Venkataramanan
33eff380aaSAnirudh Venkataramanan return 0;
34eff380aaSAnirudh Venkataramanan }
35eff380aaSAnirudh Venkataramanan
36eff380aaSAnirudh Venkataramanan /**
37eff380aaSAnirudh Venkataramanan * __ice_vsi_get_qs_sc - Assign a scattered queues from PF to VSI
38eff380aaSAnirudh Venkataramanan * @qs_cfg: gathered variables needed for pf->vsi queues assignment
39eff380aaSAnirudh Venkataramanan *
40eff380aaSAnirudh Venkataramanan * Return 0 on success and -ENOMEM in case of no left space in PF queue bitmap
41eff380aaSAnirudh Venkataramanan */
__ice_vsi_get_qs_sc(struct ice_qs_cfg * qs_cfg)42eff380aaSAnirudh Venkataramanan static int __ice_vsi_get_qs_sc(struct ice_qs_cfg *qs_cfg)
43eff380aaSAnirudh Venkataramanan {
4422bef5e7SJesse Brandeburg unsigned int i, index = 0;
45eff380aaSAnirudh Venkataramanan
46eff380aaSAnirudh Venkataramanan mutex_lock(qs_cfg->qs_mutex);
47eff380aaSAnirudh Venkataramanan for (i = 0; i < qs_cfg->q_count; i++) {
48eff380aaSAnirudh Venkataramanan index = find_next_zero_bit(qs_cfg->pf_map,
49eff380aaSAnirudh Venkataramanan qs_cfg->pf_map_size, index);
50eff380aaSAnirudh Venkataramanan if (index >= qs_cfg->pf_map_size)
51eff380aaSAnirudh Venkataramanan goto err_scatter;
52eff380aaSAnirudh Venkataramanan set_bit(index, qs_cfg->pf_map);
5388865fc4SKarol Kolacinski qs_cfg->vsi_map[i + qs_cfg->vsi_map_offset] = (u16)index;
54eff380aaSAnirudh Venkataramanan }
55eff380aaSAnirudh Venkataramanan mutex_unlock(qs_cfg->qs_mutex);
56eff380aaSAnirudh Venkataramanan
57eff380aaSAnirudh Venkataramanan return 0;
58eff380aaSAnirudh Venkataramanan err_scatter:
59eff380aaSAnirudh Venkataramanan for (index = 0; index < i; index++) {
60eff380aaSAnirudh Venkataramanan clear_bit(qs_cfg->vsi_map[index], qs_cfg->pf_map);
61eff380aaSAnirudh Venkataramanan qs_cfg->vsi_map[index + qs_cfg->vsi_map_offset] = 0;
62eff380aaSAnirudh Venkataramanan }
63eff380aaSAnirudh Venkataramanan mutex_unlock(qs_cfg->qs_mutex);
64eff380aaSAnirudh Venkataramanan
65eff380aaSAnirudh Venkataramanan return -ENOMEM;
66eff380aaSAnirudh Venkataramanan }
67eff380aaSAnirudh Venkataramanan
68eff380aaSAnirudh Venkataramanan /**
69eff380aaSAnirudh Venkataramanan * ice_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
70eff380aaSAnirudh Venkataramanan * @pf: the PF being configured
71eff380aaSAnirudh Venkataramanan * @pf_q: the PF queue
72eff380aaSAnirudh Venkataramanan * @ena: enable or disable state of the queue
73eff380aaSAnirudh Venkataramanan *
74eff380aaSAnirudh Venkataramanan * This routine will wait for the given Rx queue of the PF to reach the
75eff380aaSAnirudh Venkataramanan * enabled or disabled state.
76eff380aaSAnirudh Venkataramanan * Returns -ETIMEDOUT in case of failing to reach the requested state after
77eff380aaSAnirudh Venkataramanan * multiple retries; else will return 0 in case of success.
78eff380aaSAnirudh Venkataramanan */
ice_pf_rxq_wait(struct ice_pf * pf,int pf_q,bool ena)79eff380aaSAnirudh Venkataramanan static int ice_pf_rxq_wait(struct ice_pf *pf, int pf_q, bool ena)
80eff380aaSAnirudh Venkataramanan {
81eff380aaSAnirudh Venkataramanan int i;
82eff380aaSAnirudh Venkataramanan
83eff380aaSAnirudh Venkataramanan for (i = 0; i < ICE_Q_WAIT_MAX_RETRY; i++) {
84eff380aaSAnirudh Venkataramanan if (ena == !!(rd32(&pf->hw, QRX_CTRL(pf_q)) &
85eff380aaSAnirudh Venkataramanan QRX_CTRL_QENA_STAT_M))
86eff380aaSAnirudh Venkataramanan return 0;
87eff380aaSAnirudh Venkataramanan
88eff380aaSAnirudh Venkataramanan usleep_range(20, 40);
89eff380aaSAnirudh Venkataramanan }
90eff380aaSAnirudh Venkataramanan
91eff380aaSAnirudh Venkataramanan return -ETIMEDOUT;
92eff380aaSAnirudh Venkataramanan }
93eff380aaSAnirudh Venkataramanan
94eff380aaSAnirudh Venkataramanan /**
95eff380aaSAnirudh Venkataramanan * ice_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
96eff380aaSAnirudh Venkataramanan * @vsi: the VSI being configured
97eff380aaSAnirudh Venkataramanan * @v_idx: index of the vector in the VSI struct
98eff380aaSAnirudh Venkataramanan *
99118e0e10SMichal Swiatkowski * We allocate one q_vector and set default value for ITR setting associated
100118e0e10SMichal Swiatkowski * with this q_vector. If allocation fails we return -ENOMEM.
101eff380aaSAnirudh Venkataramanan */
ice_vsi_alloc_q_vector(struct ice_vsi * vsi,u16 v_idx)10288865fc4SKarol Kolacinski static int ice_vsi_alloc_q_vector(struct ice_vsi *vsi, u16 v_idx)
103eff380aaSAnirudh Venkataramanan {
104eff380aaSAnirudh Venkataramanan struct ice_pf *pf = vsi->back;
105eff380aaSAnirudh Venkataramanan struct ice_q_vector *q_vector;
1064aad5335SPiotr Raczynski int err;
107eff380aaSAnirudh Venkataramanan
108eff380aaSAnirudh Venkataramanan /* allocate q_vector */
1094aad5335SPiotr Raczynski q_vector = kzalloc(sizeof(*q_vector), GFP_KERNEL);
110eff380aaSAnirudh Venkataramanan if (!q_vector)
111eff380aaSAnirudh Venkataramanan return -ENOMEM;
112eff380aaSAnirudh Venkataramanan
113eff380aaSAnirudh Venkataramanan q_vector->vsi = vsi;
114eff380aaSAnirudh Venkataramanan q_vector->v_idx = v_idx;
115118e0e10SMichal Swiatkowski q_vector->tx.itr_setting = ICE_DFLT_TX_ITR;
116118e0e10SMichal Swiatkowski q_vector->rx.itr_setting = ICE_DFLT_RX_ITR;
117d59684a0SJesse Brandeburg q_vector->tx.itr_mode = ITR_DYNAMIC;
118d59684a0SJesse Brandeburg q_vector->rx.itr_mode = ITR_DYNAMIC;
119dc23715cSMaciej Fijalkowski q_vector->tx.type = ICE_TX_CONTAINER;
120dc23715cSMaciej Fijalkowski q_vector->rx.type = ICE_RX_CONTAINER;
1214aad5335SPiotr Raczynski q_vector->irq.index = -ENOENT;
122d59684a0SJesse Brandeburg
1234aad5335SPiotr Raczynski if (vsi->type == ICE_VSI_VF) {
1244aad5335SPiotr Raczynski q_vector->reg_idx = ice_calc_vf_reg_idx(vsi->vf, q_vector);
125eff380aaSAnirudh Venkataramanan goto out;
1264aad5335SPiotr Raczynski } else if (vsi->type == ICE_VSI_CTRL && vsi->vf) {
1274aad5335SPiotr Raczynski struct ice_vsi *ctrl_vsi = ice_get_vf_ctrl_vsi(pf, vsi);
1284aad5335SPiotr Raczynski
1294aad5335SPiotr Raczynski if (ctrl_vsi) {
1304aad5335SPiotr Raczynski if (unlikely(!ctrl_vsi->q_vectors)) {
1314aad5335SPiotr Raczynski err = -ENOENT;
1324aad5335SPiotr Raczynski goto err_free_q_vector;
1334aad5335SPiotr Raczynski }
1344aad5335SPiotr Raczynski
1354aad5335SPiotr Raczynski q_vector->irq = ctrl_vsi->q_vectors[0]->irq;
1364aad5335SPiotr Raczynski goto skip_alloc;
1374aad5335SPiotr Raczynski }
1384aad5335SPiotr Raczynski }
1394aad5335SPiotr Raczynski
140011670ccSPiotr Raczynski q_vector->irq = ice_alloc_irq(pf, vsi->irq_dyn_alloc);
1414aad5335SPiotr Raczynski if (q_vector->irq.index < 0) {
1424aad5335SPiotr Raczynski err = -ENOMEM;
1434aad5335SPiotr Raczynski goto err_free_q_vector;
1444aad5335SPiotr Raczynski }
1454aad5335SPiotr Raczynski
1464aad5335SPiotr Raczynski skip_alloc:
1474aad5335SPiotr Raczynski q_vector->reg_idx = q_vector->irq.index;
1484aad5335SPiotr Raczynski
149eff380aaSAnirudh Venkataramanan /* only set affinity_mask if the CPU is online */
150eff380aaSAnirudh Venkataramanan if (cpu_online(v_idx))
151eff380aaSAnirudh Venkataramanan cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
152eff380aaSAnirudh Venkataramanan
153eff380aaSAnirudh Venkataramanan /* This will not be called in the driver load path because the netdev
154eff380aaSAnirudh Venkataramanan * will not be created yet. All other cases with register the NAPI
155eff380aaSAnirudh Venkataramanan * handler here (i.e. resume, reset/rebuild, etc.)
156eff380aaSAnirudh Venkataramanan */
157eff380aaSAnirudh Venkataramanan if (vsi->netdev)
158b48b89f9SJakub Kicinski netif_napi_add(vsi->netdev, &q_vector->napi, ice_napi_poll);
159eff380aaSAnirudh Venkataramanan
160eff380aaSAnirudh Venkataramanan out:
161eff380aaSAnirudh Venkataramanan /* tie q_vector and VSI together */
162eff380aaSAnirudh Venkataramanan vsi->q_vectors[v_idx] = q_vector;
163eff380aaSAnirudh Venkataramanan
164eff380aaSAnirudh Venkataramanan return 0;
1654aad5335SPiotr Raczynski
1664aad5335SPiotr Raczynski err_free_q_vector:
1674aad5335SPiotr Raczynski kfree(q_vector);
1684aad5335SPiotr Raczynski
1694aad5335SPiotr Raczynski return err;
170eff380aaSAnirudh Venkataramanan }
171eff380aaSAnirudh Venkataramanan
172eff380aaSAnirudh Venkataramanan /**
173eff380aaSAnirudh Venkataramanan * ice_free_q_vector - Free memory allocated for a specific interrupt vector
174eff380aaSAnirudh Venkataramanan * @vsi: VSI having the memory freed
175eff380aaSAnirudh Venkataramanan * @v_idx: index of the vector to be freed
176eff380aaSAnirudh Venkataramanan */
ice_free_q_vector(struct ice_vsi * vsi,int v_idx)177eff380aaSAnirudh Venkataramanan static void ice_free_q_vector(struct ice_vsi *vsi, int v_idx)
178eff380aaSAnirudh Venkataramanan {
179eff380aaSAnirudh Venkataramanan struct ice_q_vector *q_vector;
180eff380aaSAnirudh Venkataramanan struct ice_pf *pf = vsi->back;
181e72bba21SMaciej Fijalkowski struct ice_tx_ring *tx_ring;
182e72bba21SMaciej Fijalkowski struct ice_rx_ring *rx_ring;
1834015d11eSBrett Creeley struct device *dev;
184eff380aaSAnirudh Venkataramanan
1854015d11eSBrett Creeley dev = ice_pf_to_dev(pf);
186eff380aaSAnirudh Venkataramanan if (!vsi->q_vectors[v_idx]) {
1874015d11eSBrett Creeley dev_dbg(dev, "Queue vector at index %d not found\n", v_idx);
188eff380aaSAnirudh Venkataramanan return;
189eff380aaSAnirudh Venkataramanan }
190eff380aaSAnirudh Venkataramanan q_vector = vsi->q_vectors[v_idx];
191eff380aaSAnirudh Venkataramanan
192e72bba21SMaciej Fijalkowski ice_for_each_tx_ring(tx_ring, q_vector->tx)
193e72bba21SMaciej Fijalkowski tx_ring->q_vector = NULL;
194e72bba21SMaciej Fijalkowski ice_for_each_rx_ring(rx_ring, q_vector->rx)
195e72bba21SMaciej Fijalkowski rx_ring->q_vector = NULL;
196eff380aaSAnirudh Venkataramanan
197eff380aaSAnirudh Venkataramanan /* only VSI with an associated netdev is set up with NAPI */
198eff380aaSAnirudh Venkataramanan if (vsi->netdev)
199eff380aaSAnirudh Venkataramanan netif_napi_del(&q_vector->napi);
200eff380aaSAnirudh Venkataramanan
2014aad5335SPiotr Raczynski /* release MSIX interrupt if q_vector had interrupt allocated */
2024aad5335SPiotr Raczynski if (q_vector->irq.index < 0)
2034aad5335SPiotr Raczynski goto free_q_vector;
2044aad5335SPiotr Raczynski
2054aad5335SPiotr Raczynski /* only free last VF ctrl vsi interrupt */
2064aad5335SPiotr Raczynski if (vsi->type == ICE_VSI_CTRL && vsi->vf &&
2074aad5335SPiotr Raczynski ice_get_vf_ctrl_vsi(pf, vsi))
2084aad5335SPiotr Raczynski goto free_q_vector;
2094aad5335SPiotr Raczynski
2104aad5335SPiotr Raczynski ice_free_irq(pf, q_vector->irq);
2114aad5335SPiotr Raczynski
2124aad5335SPiotr Raczynski free_q_vector:
2134aad5335SPiotr Raczynski kfree(q_vector);
214eff380aaSAnirudh Venkataramanan vsi->q_vectors[v_idx] = NULL;
215eff380aaSAnirudh Venkataramanan }
216eff380aaSAnirudh Venkataramanan
217eff380aaSAnirudh Venkataramanan /**
218eff380aaSAnirudh Venkataramanan * ice_cfg_itr_gran - set the ITR granularity to 2 usecs if not already set
219eff380aaSAnirudh Venkataramanan * @hw: board specific structure
220eff380aaSAnirudh Venkataramanan */
ice_cfg_itr_gran(struct ice_hw * hw)221eff380aaSAnirudh Venkataramanan static void ice_cfg_itr_gran(struct ice_hw *hw)
222eff380aaSAnirudh Venkataramanan {
223eff380aaSAnirudh Venkataramanan u32 regval = rd32(hw, GLINT_CTL);
224eff380aaSAnirudh Venkataramanan
225eff380aaSAnirudh Venkataramanan /* no need to update global register if ITR gran is already set */
226eff380aaSAnirudh Venkataramanan if (!(regval & GLINT_CTL_DIS_AUTOMASK_M) &&
227eff380aaSAnirudh Venkataramanan (((regval & GLINT_CTL_ITR_GRAN_200_M) >>
228eff380aaSAnirudh Venkataramanan GLINT_CTL_ITR_GRAN_200_S) == ICE_ITR_GRAN_US) &&
229eff380aaSAnirudh Venkataramanan (((regval & GLINT_CTL_ITR_GRAN_100_M) >>
230eff380aaSAnirudh Venkataramanan GLINT_CTL_ITR_GRAN_100_S) == ICE_ITR_GRAN_US) &&
231eff380aaSAnirudh Venkataramanan (((regval & GLINT_CTL_ITR_GRAN_50_M) >>
232eff380aaSAnirudh Venkataramanan GLINT_CTL_ITR_GRAN_50_S) == ICE_ITR_GRAN_US) &&
233eff380aaSAnirudh Venkataramanan (((regval & GLINT_CTL_ITR_GRAN_25_M) >>
234eff380aaSAnirudh Venkataramanan GLINT_CTL_ITR_GRAN_25_S) == ICE_ITR_GRAN_US))
235eff380aaSAnirudh Venkataramanan return;
236eff380aaSAnirudh Venkataramanan
237eff380aaSAnirudh Venkataramanan regval = ((ICE_ITR_GRAN_US << GLINT_CTL_ITR_GRAN_200_S) &
238eff380aaSAnirudh Venkataramanan GLINT_CTL_ITR_GRAN_200_M) |
239eff380aaSAnirudh Venkataramanan ((ICE_ITR_GRAN_US << GLINT_CTL_ITR_GRAN_100_S) &
240eff380aaSAnirudh Venkataramanan GLINT_CTL_ITR_GRAN_100_M) |
241eff380aaSAnirudh Venkataramanan ((ICE_ITR_GRAN_US << GLINT_CTL_ITR_GRAN_50_S) &
242eff380aaSAnirudh Venkataramanan GLINT_CTL_ITR_GRAN_50_M) |
243eff380aaSAnirudh Venkataramanan ((ICE_ITR_GRAN_US << GLINT_CTL_ITR_GRAN_25_S) &
244eff380aaSAnirudh Venkataramanan GLINT_CTL_ITR_GRAN_25_M);
245eff380aaSAnirudh Venkataramanan wr32(hw, GLINT_CTL, regval);
246eff380aaSAnirudh Venkataramanan }
247eff380aaSAnirudh Venkataramanan
248eff380aaSAnirudh Venkataramanan /**
249e72bba21SMaciej Fijalkowski * ice_calc_txq_handle - calculate the queue handle
250e75d1b2cSMaciej Fijalkowski * @vsi: VSI that ring belongs to
251e75d1b2cSMaciej Fijalkowski * @ring: ring to get the absolute queue index
252e75d1b2cSMaciej Fijalkowski * @tc: traffic class number
253e75d1b2cSMaciej Fijalkowski */
ice_calc_txq_handle(struct ice_vsi * vsi,struct ice_tx_ring * ring,u8 tc)254e72bba21SMaciej Fijalkowski static u16 ice_calc_txq_handle(struct ice_vsi *vsi, struct ice_tx_ring *ring, u8 tc)
255e75d1b2cSMaciej Fijalkowski {
256af23635aSJesse Brandeburg WARN_ONCE(ice_ring_is_xdp(ring) && tc, "XDP ring can't belong to TC other than 0\n");
257efc2214bSMaciej Fijalkowski
2580754d65bSKiran Patil if (ring->ch)
2590754d65bSKiran Patil return ring->q_index - ring->ch->base_q;
2600754d65bSKiran Patil
261e75d1b2cSMaciej Fijalkowski /* Idea here for calculation is that we subtract the number of queue
262e75d1b2cSMaciej Fijalkowski * count from TC that ring belongs to from it's absolute queue index
263e75d1b2cSMaciej Fijalkowski * and as a result we get the queue's index within TC.
264e75d1b2cSMaciej Fijalkowski */
265e75d1b2cSMaciej Fijalkowski return ring->q_index - vsi->tc_cfg.tc_info[tc].qoffset;
266e75d1b2cSMaciej Fijalkowski }
267e75d1b2cSMaciej Fijalkowski
268e75d1b2cSMaciej Fijalkowski /**
269e72bba21SMaciej Fijalkowski * ice_eswitch_calc_txq_handle
270f66756e0SGrzegorz Nitka * @ring: pointer to ring which unique index is needed
271f66756e0SGrzegorz Nitka *
272f66756e0SGrzegorz Nitka * To correctly work with many netdevs ring->q_index of Tx rings on switchdev
273f66756e0SGrzegorz Nitka * VSI can repeat. Hardware ring setup requires unique q_index. Calculate it
274f66756e0SGrzegorz Nitka * here by finding index in vsi->tx_rings of this ring.
275f66756e0SGrzegorz Nitka *
276f66756e0SGrzegorz Nitka * Return ICE_INVAL_Q_INDEX when index wasn't found. Should never happen,
277f66756e0SGrzegorz Nitka * because VSI is get from ring->vsi, so it has to be present in this VSI.
278f66756e0SGrzegorz Nitka */
ice_eswitch_calc_txq_handle(struct ice_tx_ring * ring)279e72bba21SMaciej Fijalkowski static u16 ice_eswitch_calc_txq_handle(struct ice_tx_ring *ring)
280f66756e0SGrzegorz Nitka {
281f66756e0SGrzegorz Nitka struct ice_vsi *vsi = ring->vsi;
282f66756e0SGrzegorz Nitka int i;
283f66756e0SGrzegorz Nitka
284f66756e0SGrzegorz Nitka ice_for_each_txq(vsi, i) {
285f66756e0SGrzegorz Nitka if (vsi->tx_rings[i] == ring)
286f66756e0SGrzegorz Nitka return i;
287f66756e0SGrzegorz Nitka }
288f66756e0SGrzegorz Nitka
289f66756e0SGrzegorz Nitka return ICE_INVAL_Q_INDEX;
290f66756e0SGrzegorz Nitka }
291f66756e0SGrzegorz Nitka
292f66756e0SGrzegorz Nitka /**
293634da4c1SBenita Bose * ice_cfg_xps_tx_ring - Configure XPS for a Tx ring
294634da4c1SBenita Bose * @ring: The Tx ring to configure
295634da4c1SBenita Bose *
296634da4c1SBenita Bose * This enables/disables XPS for a given Tx descriptor ring
297634da4c1SBenita Bose * based on the TCs enabled for the VSI that ring belongs to.
298634da4c1SBenita Bose */
ice_cfg_xps_tx_ring(struct ice_tx_ring * ring)299e72bba21SMaciej Fijalkowski static void ice_cfg_xps_tx_ring(struct ice_tx_ring *ring)
300634da4c1SBenita Bose {
301634da4c1SBenita Bose if (!ring->q_vector || !ring->netdev)
302634da4c1SBenita Bose return;
303634da4c1SBenita Bose
304634da4c1SBenita Bose /* We only initialize XPS once, so as not to overwrite user settings */
305634da4c1SBenita Bose if (test_and_set_bit(ICE_TX_XPS_INIT_DONE, ring->xps_state))
306634da4c1SBenita Bose return;
307634da4c1SBenita Bose
308634da4c1SBenita Bose netif_set_xps_queue(ring->netdev, &ring->q_vector->affinity_mask,
309634da4c1SBenita Bose ring->q_index);
310634da4c1SBenita Bose }
311634da4c1SBenita Bose
312634da4c1SBenita Bose /**
313eff380aaSAnirudh Venkataramanan * ice_setup_tx_ctx - setup a struct ice_tlan_ctx instance
314eff380aaSAnirudh Venkataramanan * @ring: The Tx ring to configure
315eff380aaSAnirudh Venkataramanan * @tlan_ctx: Pointer to the Tx LAN queue context structure to be initialized
316eff380aaSAnirudh Venkataramanan * @pf_q: queue index in the PF space
317eff380aaSAnirudh Venkataramanan *
318eff380aaSAnirudh Venkataramanan * Configure the Tx descriptor ring in TLAN context.
319eff380aaSAnirudh Venkataramanan */
320eff380aaSAnirudh Venkataramanan static void
ice_setup_tx_ctx(struct ice_tx_ring * ring,struct ice_tlan_ctx * tlan_ctx,u16 pf_q)321e72bba21SMaciej Fijalkowski ice_setup_tx_ctx(struct ice_tx_ring *ring, struct ice_tlan_ctx *tlan_ctx, u16 pf_q)
322eff380aaSAnirudh Venkataramanan {
323eff380aaSAnirudh Venkataramanan struct ice_vsi *vsi = ring->vsi;
324eff380aaSAnirudh Venkataramanan struct ice_hw *hw = &vsi->back->hw;
325eff380aaSAnirudh Venkataramanan
326eff380aaSAnirudh Venkataramanan tlan_ctx->base = ring->dma >> ICE_TLAN_CTX_BASE_S;
327eff380aaSAnirudh Venkataramanan
328eff380aaSAnirudh Venkataramanan tlan_ctx->port_num = vsi->port_info->lport;
329eff380aaSAnirudh Venkataramanan
330eff380aaSAnirudh Venkataramanan /* Transmit Queue Length */
331eff380aaSAnirudh Venkataramanan tlan_ctx->qlen = ring->count;
332eff380aaSAnirudh Venkataramanan
333e72bba21SMaciej Fijalkowski ice_set_cgd_num(tlan_ctx, ring->dcb_tc);
334eff380aaSAnirudh Venkataramanan
335eff380aaSAnirudh Venkataramanan /* PF number */
336eff380aaSAnirudh Venkataramanan tlan_ctx->pf_num = hw->pf_id;
337eff380aaSAnirudh Venkataramanan
338eff380aaSAnirudh Venkataramanan /* queue belongs to a specific VSI type
339eff380aaSAnirudh Venkataramanan * VF / VM index should be programmed per vmvf_type setting:
340eff380aaSAnirudh Venkataramanan * for vmvf_type = VF, it is VF number between 0-256
341eff380aaSAnirudh Venkataramanan * for vmvf_type = VM, it is VM number between 0-767
342eff380aaSAnirudh Venkataramanan * for PF or EMP this field should be set to zero
343eff380aaSAnirudh Venkataramanan */
344eff380aaSAnirudh Venkataramanan switch (vsi->type) {
345eff380aaSAnirudh Venkataramanan case ICE_VSI_LB:
346148beb61SHenry Tieman case ICE_VSI_CTRL:
347eff380aaSAnirudh Venkataramanan case ICE_VSI_PF:
3480754d65bSKiran Patil if (ring->ch)
3490754d65bSKiran Patil tlan_ctx->vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_VMQ;
3500754d65bSKiran Patil else
351eff380aaSAnirudh Venkataramanan tlan_ctx->vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_PF;
352eff380aaSAnirudh Venkataramanan break;
353eff380aaSAnirudh Venkataramanan case ICE_VSI_VF:
354eff380aaSAnirudh Venkataramanan /* Firmware expects vmvf_num to be absolute VF ID */
355b03d519dSJacob Keller tlan_ctx->vmvf_num = hw->func_caps.vf_base_id + vsi->vf->vf_id;
356eff380aaSAnirudh Venkataramanan tlan_ctx->vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_VF;
357eff380aaSAnirudh Venkataramanan break;
358f66756e0SGrzegorz Nitka case ICE_VSI_SWITCHDEV_CTRL:
359f66756e0SGrzegorz Nitka tlan_ctx->vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_VMQ;
360f66756e0SGrzegorz Nitka break;
361eff380aaSAnirudh Venkataramanan default:
362eff380aaSAnirudh Venkataramanan return;
363eff380aaSAnirudh Venkataramanan }
364eff380aaSAnirudh Venkataramanan
365eff380aaSAnirudh Venkataramanan /* make sure the context is associated with the right VSI */
3660754d65bSKiran Patil if (ring->ch)
3670754d65bSKiran Patil tlan_ctx->src_vsi = ring->ch->vsi_num;
3680754d65bSKiran Patil else
369eff380aaSAnirudh Venkataramanan tlan_ctx->src_vsi = ice_get_hw_vsi_num(hw, vsi->idx);
370eff380aaSAnirudh Venkataramanan
371ea9b847cSJacob Keller /* Restrict Tx timestamps to the PF VSI */
372ea9b847cSJacob Keller switch (vsi->type) {
373ea9b847cSJacob Keller case ICE_VSI_PF:
374ea9b847cSJacob Keller tlan_ctx->tsyn_ena = 1;
375ea9b847cSJacob Keller break;
376ea9b847cSJacob Keller default:
377ea9b847cSJacob Keller break;
378ea9b847cSJacob Keller }
379ea9b847cSJacob Keller
380eff380aaSAnirudh Venkataramanan tlan_ctx->tso_ena = ICE_TX_LEGACY;
381eff380aaSAnirudh Venkataramanan tlan_ctx->tso_qnum = pf_q;
382eff380aaSAnirudh Venkataramanan
383eff380aaSAnirudh Venkataramanan /* Legacy or Advanced Host Interface:
384eff380aaSAnirudh Venkataramanan * 0: Advanced Host Interface
385eff380aaSAnirudh Venkataramanan * 1: Legacy Host Interface
386eff380aaSAnirudh Venkataramanan */
387eff380aaSAnirudh Venkataramanan tlan_ctx->legacy_int = ICE_TX_LEGACY;
388eff380aaSAnirudh Venkataramanan }
389eff380aaSAnirudh Venkataramanan
390eff380aaSAnirudh Venkataramanan /**
39189861c48SMaciej Fijalkowski * ice_rx_offset - Return expected offset into page to access data
39289861c48SMaciej Fijalkowski * @rx_ring: Ring we are requesting offset of
39389861c48SMaciej Fijalkowski *
39489861c48SMaciej Fijalkowski * Returns the offset value for ring into the data buffer.
39589861c48SMaciej Fijalkowski */
ice_rx_offset(struct ice_rx_ring * rx_ring)396e72bba21SMaciej Fijalkowski static unsigned int ice_rx_offset(struct ice_rx_ring *rx_ring)
39789861c48SMaciej Fijalkowski {
39889861c48SMaciej Fijalkowski if (ice_ring_uses_build_skb(rx_ring))
39989861c48SMaciej Fijalkowski return ICE_SKB_PAD;
40089861c48SMaciej Fijalkowski return 0;
40189861c48SMaciej Fijalkowski }
40289861c48SMaciej Fijalkowski
40389861c48SMaciej Fijalkowski /**
404eff380aaSAnirudh Venkataramanan * ice_setup_rx_ctx - Configure a receive ring context
405eff380aaSAnirudh Venkataramanan * @ring: The Rx ring to configure
406eff380aaSAnirudh Venkataramanan *
407eff380aaSAnirudh Venkataramanan * Configure the Rx descriptor ring in RLAN context.
408eff380aaSAnirudh Venkataramanan */
ice_setup_rx_ctx(struct ice_rx_ring * ring)409e72bba21SMaciej Fijalkowski static int ice_setup_rx_ctx(struct ice_rx_ring *ring)
410eff380aaSAnirudh Venkataramanan {
411eff380aaSAnirudh Venkataramanan struct ice_vsi *vsi = ring->vsi;
412eff380aaSAnirudh Venkataramanan u32 rxdid = ICE_RXDID_FLEX_NIC;
413eff380aaSAnirudh Venkataramanan struct ice_rlan_ctx rlan_ctx;
4142d4238f5SKrzysztof Kazimierczak struct ice_hw *hw;
415eff380aaSAnirudh Venkataramanan u16 pf_q;
416eff380aaSAnirudh Venkataramanan int err;
417eff380aaSAnirudh Venkataramanan
4182d4238f5SKrzysztof Kazimierczak hw = &vsi->back->hw;
4192d4238f5SKrzysztof Kazimierczak
420eff380aaSAnirudh Venkataramanan /* what is Rx queue number in global space of 2K Rx queues */
421eff380aaSAnirudh Venkataramanan pf_q = vsi->rxq_map[ring->q_index];
422eff380aaSAnirudh Venkataramanan
423eff380aaSAnirudh Venkataramanan /* clear the context structure first */
424eff380aaSAnirudh Venkataramanan memset(&rlan_ctx, 0, sizeof(rlan_ctx));
425eff380aaSAnirudh Venkataramanan
426efc2214bSMaciej Fijalkowski /* Receive Queue Base Address.
427efc2214bSMaciej Fijalkowski * Indicates the starting address of the descriptor queue defined in
428efc2214bSMaciej Fijalkowski * 128 Byte units.
429efc2214bSMaciej Fijalkowski */
43060aeca6dSAnatolii Gerasymenko rlan_ctx.base = ring->dma >> ICE_RLAN_BASE_S;
431eff380aaSAnirudh Venkataramanan
432eff380aaSAnirudh Venkataramanan rlan_ctx.qlen = ring->count;
433eff380aaSAnirudh Venkataramanan
434eff380aaSAnirudh Venkataramanan /* Receive Packet Data Buffer Size.
435eff380aaSAnirudh Venkataramanan * The Packet Data Buffer Size is defined in 128 byte units.
436eff380aaSAnirudh Venkataramanan */
43710083aefSJesse Brandeburg rlan_ctx.dbuf = DIV_ROUND_UP(ring->rx_buf_len,
43810083aefSJesse Brandeburg BIT_ULL(ICE_RLAN_CTX_DBUF_S));
439eff380aaSAnirudh Venkataramanan
440eff380aaSAnirudh Venkataramanan /* use 32 byte descriptors */
441eff380aaSAnirudh Venkataramanan rlan_ctx.dsize = 1;
442eff380aaSAnirudh Venkataramanan
443eff380aaSAnirudh Venkataramanan /* Strip the Ethernet CRC bytes before the packet is posted to host
444eff380aaSAnirudh Venkataramanan * memory.
445eff380aaSAnirudh Venkataramanan */
446dddd406dSJesse Brandeburg rlan_ctx.crcstrip = !(ring->flags & ICE_RX_FLAGS_CRC_STRIP_DIS);
447eff380aaSAnirudh Venkataramanan
4480d54d8f7SBrett Creeley /* L2TSEL flag defines the reported L2 Tags in the receive descriptor
4490d54d8f7SBrett Creeley * and it needs to remain 1 for non-DVM capable configurations to not
4500d54d8f7SBrett Creeley * break backward compatibility for VF drivers. Setting this field to 0
4510d54d8f7SBrett Creeley * will cause the single/outer VLAN tag to be stripped to the L2TAG2_2ND
4520d54d8f7SBrett Creeley * field in the Rx descriptor. Setting it to 1 allows the VLAN tag to
4530d54d8f7SBrett Creeley * be stripped in L2TAG1 of the Rx descriptor, which is where VFs will
4540d54d8f7SBrett Creeley * check for the tag
4550d54d8f7SBrett Creeley */
4560d54d8f7SBrett Creeley if (ice_is_dvm_ena(hw))
4570d54d8f7SBrett Creeley if (vsi->type == ICE_VSI_VF &&
458b03d519dSJacob Keller ice_vf_is_port_vlan_ena(vsi->vf))
4590d54d8f7SBrett Creeley rlan_ctx.l2tsel = 1;
4600d54d8f7SBrett Creeley else
4610d54d8f7SBrett Creeley rlan_ctx.l2tsel = 0;
4620d54d8f7SBrett Creeley else
463eff380aaSAnirudh Venkataramanan rlan_ctx.l2tsel = 1;
464eff380aaSAnirudh Venkataramanan
465eff380aaSAnirudh Venkataramanan rlan_ctx.dtype = ICE_RX_DTYPE_NO_SPLIT;
466eff380aaSAnirudh Venkataramanan rlan_ctx.hsplit_0 = ICE_RLAN_RX_HSPLIT_0_NO_SPLIT;
467eff380aaSAnirudh Venkataramanan rlan_ctx.hsplit_1 = ICE_RLAN_RX_HSPLIT_1_NO_SPLIT;
468eff380aaSAnirudh Venkataramanan
469eff380aaSAnirudh Venkataramanan /* This controls whether VLAN is stripped from inner headers
470eff380aaSAnirudh Venkataramanan * The VLAN in the inner L2 header is stripped to the receive
471eff380aaSAnirudh Venkataramanan * descriptor if enabled by this flag.
472eff380aaSAnirudh Venkataramanan */
473eff380aaSAnirudh Venkataramanan rlan_ctx.showiv = 0;
474eff380aaSAnirudh Venkataramanan
475eff380aaSAnirudh Venkataramanan /* Max packet size for this queue - must not be set to a larger value
476eff380aaSAnirudh Venkataramanan * than 5 x DBUF
477eff380aaSAnirudh Venkataramanan */
47888865fc4SKarol Kolacinski rlan_ctx.rxmax = min_t(u32, vsi->max_frame,
4791bbc04deSMaciej Fijalkowski ICE_MAX_CHAINED_RX_BUFS * ring->rx_buf_len);
480eff380aaSAnirudh Venkataramanan
481eff380aaSAnirudh Venkataramanan /* Rx queue threshold in units of 64 */
482eff380aaSAnirudh Venkataramanan rlan_ctx.lrxqthresh = 1;
483eff380aaSAnirudh Venkataramanan
484eff380aaSAnirudh Venkataramanan /* Enable Flexible Descriptors in the queue context which
485eff380aaSAnirudh Venkataramanan * allows this driver to select a specific receive descriptor format
486401ce33bSBrett Creeley * increasing context priority to pick up profile ID; default is 0x01;
487401ce33bSBrett Creeley * setting to 0x03 to ensure profile is programming if prev context is
488401ce33bSBrett Creeley * of same priority
489eff380aaSAnirudh Venkataramanan */
490401ce33bSBrett Creeley if (vsi->type != ICE_VSI_VF)
49177a78115SJacob Keller ice_write_qrxflxp_cntxt(hw, pf_q, rxdid, 0x3, true);
492401ce33bSBrett Creeley else
49377a78115SJacob Keller ice_write_qrxflxp_cntxt(hw, pf_q, ICE_RXDID_LEGACY_1, 0x3,
49477a78115SJacob Keller false);
495eff380aaSAnirudh Venkataramanan
496eff380aaSAnirudh Venkataramanan /* Absolute queue number out of 2K needs to be passed */
497eff380aaSAnirudh Venkataramanan err = ice_write_rxq_ctx(hw, &rlan_ctx, pf_q);
498eff380aaSAnirudh Venkataramanan if (err) {
49943c7f919SKrzysztof Kazimierczak dev_err(ice_pf_to_dev(vsi->back), "Failed to set LAN Rx queue context for absolute Rx queue %d error: %d\n",
500eff380aaSAnirudh Venkataramanan pf_q, err);
501eff380aaSAnirudh Venkataramanan return -EIO;
502eff380aaSAnirudh Venkataramanan }
503eff380aaSAnirudh Venkataramanan
504eff380aaSAnirudh Venkataramanan if (vsi->type == ICE_VSI_VF)
505eff380aaSAnirudh Venkataramanan return 0;
506eff380aaSAnirudh Venkataramanan
50759bb0808SMaciej Fijalkowski /* configure Rx buffer alignment */
50859bb0808SMaciej Fijalkowski if (!vsi->netdev || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags))
50959bb0808SMaciej Fijalkowski ice_clear_ring_build_skb_ena(ring);
51059bb0808SMaciej Fijalkowski else
51159bb0808SMaciej Fijalkowski ice_set_ring_build_skb_ena(ring);
51259bb0808SMaciej Fijalkowski
51389861c48SMaciej Fijalkowski ring->rx_offset = ice_rx_offset(ring);
51489861c48SMaciej Fijalkowski
515eff380aaSAnirudh Venkataramanan /* init queue specific tail register */
516eff380aaSAnirudh Venkataramanan ring->tail = hw->hw_addr + QRX_TAIL(pf_q);
517eff380aaSAnirudh Venkataramanan writel(0, ring->tail);
5182d4238f5SKrzysztof Kazimierczak
51943c7f919SKrzysztof Kazimierczak return 0;
52043c7f919SKrzysztof Kazimierczak }
52143c7f919SKrzysztof Kazimierczak
52243c7f919SKrzysztof Kazimierczak /**
523*c864bf01SMaciej Fijalkowski * ice_get_frame_sz - calculate xdp_buff::frame_sz
524*c864bf01SMaciej Fijalkowski * @rx_ring: the ring being configured
525*c864bf01SMaciej Fijalkowski *
526*c864bf01SMaciej Fijalkowski * Return frame size based on underlying PAGE_SIZE
527*c864bf01SMaciej Fijalkowski */
ice_get_frame_sz(struct ice_rx_ring * rx_ring)528*c864bf01SMaciej Fijalkowski static unsigned int ice_get_frame_sz(struct ice_rx_ring *rx_ring)
529*c864bf01SMaciej Fijalkowski {
530*c864bf01SMaciej Fijalkowski unsigned int frame_sz;
531*c864bf01SMaciej Fijalkowski
532*c864bf01SMaciej Fijalkowski #if (PAGE_SIZE >= 8192)
533*c864bf01SMaciej Fijalkowski frame_sz = rx_ring->rx_buf_len;
534*c864bf01SMaciej Fijalkowski #else
535*c864bf01SMaciej Fijalkowski frame_sz = ice_rx_pg_size(rx_ring) / 2;
536*c864bf01SMaciej Fijalkowski #endif
537*c864bf01SMaciej Fijalkowski
538*c864bf01SMaciej Fijalkowski return frame_sz;
539*c864bf01SMaciej Fijalkowski }
540*c864bf01SMaciej Fijalkowski
541*c864bf01SMaciej Fijalkowski /**
54243c7f919SKrzysztof Kazimierczak * ice_vsi_cfg_rxq - Configure an Rx queue
54343c7f919SKrzysztof Kazimierczak * @ring: the ring being configured
54443c7f919SKrzysztof Kazimierczak *
54543c7f919SKrzysztof Kazimierczak * Return 0 on success and a negative value on error.
54643c7f919SKrzysztof Kazimierczak */
ice_vsi_cfg_rxq(struct ice_rx_ring * ring)547e72bba21SMaciej Fijalkowski int ice_vsi_cfg_rxq(struct ice_rx_ring *ring)
54843c7f919SKrzysztof Kazimierczak {
54943c7f919SKrzysztof Kazimierczak struct device *dev = ice_pf_to_dev(ring->vsi->back);
5502fba7dc5SMaciej Fijalkowski u32 num_bufs = ICE_RX_DESC_UNUSED(ring);
55143c7f919SKrzysztof Kazimierczak int err;
55243c7f919SKrzysztof Kazimierczak
55343c7f919SKrzysztof Kazimierczak ring->rx_buf_len = ring->vsi->rx_buf_len;
55443c7f919SKrzysztof Kazimierczak
55543c7f919SKrzysztof Kazimierczak if (ring->vsi->type == ICE_VSI_PF) {
556c61f2bf8SMaciej Fijalkowski if (!xdp_rxq_info_is_reg(&ring->xdp_rxq)) {
557c61f2bf8SMaciej Fijalkowski err = __xdp_rxq_info_reg(&ring->xdp_rxq, ring->netdev,
5582fba7dc5SMaciej Fijalkowski ring->q_index,
5592fba7dc5SMaciej Fijalkowski ring->q_vector->napi.napi_id,
560c61f2bf8SMaciej Fijalkowski ring->rx_buf_len);
561c61f2bf8SMaciej Fijalkowski if (err)
562c61f2bf8SMaciej Fijalkowski return err;
563c61f2bf8SMaciej Fijalkowski }
56443c7f919SKrzysztof Kazimierczak
56543c7f919SKrzysztof Kazimierczak ring->xsk_pool = ice_xsk_pool(ring);
56643c7f919SKrzysztof Kazimierczak if (ring->xsk_pool) {
567c61f2bf8SMaciej Fijalkowski xdp_rxq_info_unreg(&ring->xdp_rxq);
56843c7f919SKrzysztof Kazimierczak
56943c7f919SKrzysztof Kazimierczak ring->rx_buf_len =
57043c7f919SKrzysztof Kazimierczak xsk_pool_get_rx_frame_size(ring->xsk_pool);
571c61f2bf8SMaciej Fijalkowski err = __xdp_rxq_info_reg(&ring->xdp_rxq, ring->netdev,
572c61f2bf8SMaciej Fijalkowski ring->q_index,
573c61f2bf8SMaciej Fijalkowski ring->q_vector->napi.napi_id,
574c61f2bf8SMaciej Fijalkowski ring->rx_buf_len);
575c61f2bf8SMaciej Fijalkowski if (err)
576c61f2bf8SMaciej Fijalkowski return err;
57743c7f919SKrzysztof Kazimierczak err = xdp_rxq_info_reg_mem_model(&ring->xdp_rxq,
57843c7f919SKrzysztof Kazimierczak MEM_TYPE_XSK_BUFF_POOL,
57943c7f919SKrzysztof Kazimierczak NULL);
58043c7f919SKrzysztof Kazimierczak if (err)
58143c7f919SKrzysztof Kazimierczak return err;
58243c7f919SKrzysztof Kazimierczak xsk_pool_set_rxq_info(ring->xsk_pool, &ring->xdp_rxq);
58343c7f919SKrzysztof Kazimierczak
58443c7f919SKrzysztof Kazimierczak dev_info(dev, "Registered XDP mem model MEM_TYPE_XSK_BUFF_POOL on Rx ring %d\n",
58543c7f919SKrzysztof Kazimierczak ring->q_index);
58643c7f919SKrzysztof Kazimierczak } else {
587c61f2bf8SMaciej Fijalkowski if (!xdp_rxq_info_is_reg(&ring->xdp_rxq)) {
588c61f2bf8SMaciej Fijalkowski err = __xdp_rxq_info_reg(&ring->xdp_rxq, ring->netdev,
5892fba7dc5SMaciej Fijalkowski ring->q_index,
5902fba7dc5SMaciej Fijalkowski ring->q_vector->napi.napi_id,
591c61f2bf8SMaciej Fijalkowski ring->rx_buf_len);
592c61f2bf8SMaciej Fijalkowski if (err)
593c61f2bf8SMaciej Fijalkowski return err;
594c61f2bf8SMaciej Fijalkowski }
59543c7f919SKrzysztof Kazimierczak
59643c7f919SKrzysztof Kazimierczak err = xdp_rxq_info_reg_mem_model(&ring->xdp_rxq,
59743c7f919SKrzysztof Kazimierczak MEM_TYPE_PAGE_SHARED,
59843c7f919SKrzysztof Kazimierczak NULL);
59943c7f919SKrzysztof Kazimierczak if (err)
60043c7f919SKrzysztof Kazimierczak return err;
60143c7f919SKrzysztof Kazimierczak }
60243c7f919SKrzysztof Kazimierczak }
60343c7f919SKrzysztof Kazimierczak
604*c864bf01SMaciej Fijalkowski xdp_init_buff(&ring->xdp, ice_get_frame_sz(ring), &ring->xdp_rxq);
6052fba7dc5SMaciej Fijalkowski ring->xdp.data = NULL;
60643c7f919SKrzysztof Kazimierczak err = ice_setup_rx_ctx(ring);
60743c7f919SKrzysztof Kazimierczak if (err) {
60843c7f919SKrzysztof Kazimierczak dev_err(dev, "ice_setup_rx_ctx failed for RxQ %d, err %d\n",
60943c7f919SKrzysztof Kazimierczak ring->q_index, err);
61043c7f919SKrzysztof Kazimierczak return err;
61143c7f919SKrzysztof Kazimierczak }
61243c7f919SKrzysztof Kazimierczak
6131742b3d5SMagnus Karlsson if (ring->xsk_pool) {
614ed0907e3SMagnus Karlsson bool ok;
615ed0907e3SMagnus Karlsson
616c4655761SMagnus Karlsson if (!xsk_buff_can_alloc(ring->xsk_pool, num_bufs)) {
6171742b3d5SMagnus Karlsson dev_warn(dev, "XSK buffer pool does not provide enough addresses to fill %d buffers on Rx ring %d\n",
6183f0d97cdSKrzysztof Kazimierczak num_bufs, ring->q_index);
6193f0d97cdSKrzysztof Kazimierczak dev_warn(dev, "Change Rx ring/fill queue size to avoid performance issues\n");
6203f0d97cdSKrzysztof Kazimierczak
6213f0d97cdSKrzysztof Kazimierczak return 0;
6223f0d97cdSKrzysztof Kazimierczak }
6233f0d97cdSKrzysztof Kazimierczak
624ed0907e3SMagnus Karlsson ok = ice_alloc_rx_bufs_zc(ring, num_bufs);
62543c7f919SKrzysztof Kazimierczak if (!ok) {
62643c7f919SKrzysztof Kazimierczak u16 pf_q = ring->vsi->rxq_map[ring->q_index];
62743c7f919SKrzysztof Kazimierczak
6281742b3d5SMagnus Karlsson dev_info(dev, "Failed to allocate some buffers on XSK buffer pool enabled Rx ring %d (pf_q %d)\n",
6292d4238f5SKrzysztof Kazimierczak ring->q_index, pf_q);
63043c7f919SKrzysztof Kazimierczak }
63143c7f919SKrzysztof Kazimierczak
6323f0d97cdSKrzysztof Kazimierczak return 0;
6333f0d97cdSKrzysztof Kazimierczak }
6343f0d97cdSKrzysztof Kazimierczak
6353f0d97cdSKrzysztof Kazimierczak ice_alloc_rx_bufs(ring, num_bufs);
636eff380aaSAnirudh Venkataramanan
637eff380aaSAnirudh Venkataramanan return 0;
638eff380aaSAnirudh Venkataramanan }
639eff380aaSAnirudh Venkataramanan
640eff380aaSAnirudh Venkataramanan /**
641eff380aaSAnirudh Venkataramanan * __ice_vsi_get_qs - helper function for assigning queues from PF to VSI
642eff380aaSAnirudh Venkataramanan * @qs_cfg: gathered variables needed for pf->vsi queues assignment
643eff380aaSAnirudh Venkataramanan *
644eff380aaSAnirudh Venkataramanan * This function first tries to find contiguous space. If it is not successful,
645eff380aaSAnirudh Venkataramanan * it tries with the scatter approach.
646eff380aaSAnirudh Venkataramanan *
647eff380aaSAnirudh Venkataramanan * Return 0 on success and -ENOMEM in case of no left space in PF queue bitmap
648eff380aaSAnirudh Venkataramanan */
__ice_vsi_get_qs(struct ice_qs_cfg * qs_cfg)649eff380aaSAnirudh Venkataramanan int __ice_vsi_get_qs(struct ice_qs_cfg *qs_cfg)
650eff380aaSAnirudh Venkataramanan {
651eff380aaSAnirudh Venkataramanan int ret = 0;
652eff380aaSAnirudh Venkataramanan
653eff380aaSAnirudh Venkataramanan ret = __ice_vsi_get_qs_contig(qs_cfg);
654eff380aaSAnirudh Venkataramanan if (ret) {
655eff380aaSAnirudh Venkataramanan /* contig failed, so try with scatter approach */
656eff380aaSAnirudh Venkataramanan qs_cfg->mapping_mode = ICE_VSI_MAP_SCATTER;
65788865fc4SKarol Kolacinski qs_cfg->q_count = min_t(unsigned int, qs_cfg->q_count,
658eff380aaSAnirudh Venkataramanan qs_cfg->scatter_count);
659eff380aaSAnirudh Venkataramanan ret = __ice_vsi_get_qs_sc(qs_cfg);
660eff380aaSAnirudh Venkataramanan }
661eff380aaSAnirudh Venkataramanan return ret;
662eff380aaSAnirudh Venkataramanan }
663eff380aaSAnirudh Venkataramanan
664eff380aaSAnirudh Venkataramanan /**
66513a6233bSBrett Creeley * ice_vsi_ctrl_one_rx_ring - start/stop VSI's Rx ring with no busy wait
666eff380aaSAnirudh Venkataramanan * @vsi: the VSI being configured
66713a6233bSBrett Creeley * @ena: start or stop the Rx ring
66813a6233bSBrett Creeley * @rxq_idx: 0-based Rx queue index for the VSI passed in
66913a6233bSBrett Creeley * @wait: wait or don't wait for configuration to finish in hardware
67013a6233bSBrett Creeley *
67113a6233bSBrett Creeley * Return 0 on success and negative on error.
672eff380aaSAnirudh Venkataramanan */
67313a6233bSBrett Creeley int
ice_vsi_ctrl_one_rx_ring(struct ice_vsi * vsi,bool ena,u16 rxq_idx,bool wait)67413a6233bSBrett Creeley ice_vsi_ctrl_one_rx_ring(struct ice_vsi *vsi, bool ena, u16 rxq_idx, bool wait)
675eff380aaSAnirudh Venkataramanan {
676eff380aaSAnirudh Venkataramanan int pf_q = vsi->rxq_map[rxq_idx];
677eff380aaSAnirudh Venkataramanan struct ice_pf *pf = vsi->back;
678eff380aaSAnirudh Venkataramanan struct ice_hw *hw = &pf->hw;
679eff380aaSAnirudh Venkataramanan u32 rx_reg;
680eff380aaSAnirudh Venkataramanan
681eff380aaSAnirudh Venkataramanan rx_reg = rd32(hw, QRX_CTRL(pf_q));
682eff380aaSAnirudh Venkataramanan
683eff380aaSAnirudh Venkataramanan /* Skip if the queue is already in the requested state */
684eff380aaSAnirudh Venkataramanan if (ena == !!(rx_reg & QRX_CTRL_QENA_STAT_M))
685eff380aaSAnirudh Venkataramanan return 0;
686eff380aaSAnirudh Venkataramanan
687eff380aaSAnirudh Venkataramanan /* turn on/off the queue */
688eff380aaSAnirudh Venkataramanan if (ena)
689eff380aaSAnirudh Venkataramanan rx_reg |= QRX_CTRL_QENA_REQ_M;
690eff380aaSAnirudh Venkataramanan else
691eff380aaSAnirudh Venkataramanan rx_reg &= ~QRX_CTRL_QENA_REQ_M;
692eff380aaSAnirudh Venkataramanan wr32(hw, QRX_CTRL(pf_q), rx_reg);
693eff380aaSAnirudh Venkataramanan
69413a6233bSBrett Creeley if (!wait)
69513a6233bSBrett Creeley return 0;
696eff380aaSAnirudh Venkataramanan
69713a6233bSBrett Creeley ice_flush(hw);
69813a6233bSBrett Creeley return ice_pf_rxq_wait(pf, pf_q, ena);
69913a6233bSBrett Creeley }
70013a6233bSBrett Creeley
70113a6233bSBrett Creeley /**
70213a6233bSBrett Creeley * ice_vsi_wait_one_rx_ring - wait for a VSI's Rx ring to be stopped/started
70313a6233bSBrett Creeley * @vsi: the VSI being configured
70413a6233bSBrett Creeley * @ena: true/false to verify Rx ring has been enabled/disabled respectively
70513a6233bSBrett Creeley * @rxq_idx: 0-based Rx queue index for the VSI passed in
70613a6233bSBrett Creeley *
70713a6233bSBrett Creeley * This routine will wait for the given Rx queue of the VSI to reach the
70813a6233bSBrett Creeley * enabled or disabled state. Returns -ETIMEDOUT in case of failing to reach
70913a6233bSBrett Creeley * the requested state after multiple retries; else will return 0 in case of
71013a6233bSBrett Creeley * success.
71113a6233bSBrett Creeley */
ice_vsi_wait_one_rx_ring(struct ice_vsi * vsi,bool ena,u16 rxq_idx)71213a6233bSBrett Creeley int ice_vsi_wait_one_rx_ring(struct ice_vsi *vsi, bool ena, u16 rxq_idx)
71313a6233bSBrett Creeley {
71413a6233bSBrett Creeley int pf_q = vsi->rxq_map[rxq_idx];
71513a6233bSBrett Creeley struct ice_pf *pf = vsi->back;
71613a6233bSBrett Creeley
71713a6233bSBrett Creeley return ice_pf_rxq_wait(pf, pf_q, ena);
718eff380aaSAnirudh Venkataramanan }
719eff380aaSAnirudh Venkataramanan
720eff380aaSAnirudh Venkataramanan /**
721eff380aaSAnirudh Venkataramanan * ice_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
722eff380aaSAnirudh Venkataramanan * @vsi: the VSI being configured
723eff380aaSAnirudh Venkataramanan *
724eff380aaSAnirudh Venkataramanan * We allocate one q_vector per queue interrupt. If allocation fails we
725eff380aaSAnirudh Venkataramanan * return -ENOMEM.
726eff380aaSAnirudh Venkataramanan */
ice_vsi_alloc_q_vectors(struct ice_vsi * vsi)727eff380aaSAnirudh Venkataramanan int ice_vsi_alloc_q_vectors(struct ice_vsi *vsi)
728eff380aaSAnirudh Venkataramanan {
7293306f79fSAnirudh Venkataramanan struct device *dev = ice_pf_to_dev(vsi->back);
73088865fc4SKarol Kolacinski u16 v_idx;
73188865fc4SKarol Kolacinski int err;
732eff380aaSAnirudh Venkataramanan
733eff380aaSAnirudh Venkataramanan if (vsi->q_vectors[0]) {
7344015d11eSBrett Creeley dev_dbg(dev, "VSI %d has existing q_vectors\n", vsi->vsi_num);
735eff380aaSAnirudh Venkataramanan return -EEXIST;
736eff380aaSAnirudh Venkataramanan }
737eff380aaSAnirudh Venkataramanan
7383306f79fSAnirudh Venkataramanan for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) {
739eff380aaSAnirudh Venkataramanan err = ice_vsi_alloc_q_vector(vsi, v_idx);
740eff380aaSAnirudh Venkataramanan if (err)
741eff380aaSAnirudh Venkataramanan goto err_out;
742eff380aaSAnirudh Venkataramanan }
743eff380aaSAnirudh Venkataramanan
744eff380aaSAnirudh Venkataramanan return 0;
745eff380aaSAnirudh Venkataramanan
746eff380aaSAnirudh Venkataramanan err_out:
747eff380aaSAnirudh Venkataramanan while (v_idx--)
748eff380aaSAnirudh Venkataramanan ice_free_q_vector(vsi, v_idx);
749eff380aaSAnirudh Venkataramanan
7504015d11eSBrett Creeley dev_err(dev, "Failed to allocate %d q_vector for VSI %d, ret=%d\n",
751eff380aaSAnirudh Venkataramanan vsi->num_q_vectors, vsi->vsi_num, err);
752eff380aaSAnirudh Venkataramanan vsi->num_q_vectors = 0;
753eff380aaSAnirudh Venkataramanan return err;
754eff380aaSAnirudh Venkataramanan }
755eff380aaSAnirudh Venkataramanan
756eff380aaSAnirudh Venkataramanan /**
757eff380aaSAnirudh Venkataramanan * ice_vsi_map_rings_to_vectors - Map VSI rings to interrupt vectors
758eff380aaSAnirudh Venkataramanan * @vsi: the VSI being configured
759eff380aaSAnirudh Venkataramanan *
760eff380aaSAnirudh Venkataramanan * This function maps descriptor rings to the queue-specific vectors allotted
761eff380aaSAnirudh Venkataramanan * through the MSI-X enabling code. On a constrained vector budget, we map Tx
762eff380aaSAnirudh Venkataramanan * and Rx rings to the vector as "efficiently" as possible.
763eff380aaSAnirudh Venkataramanan */
ice_vsi_map_rings_to_vectors(struct ice_vsi * vsi)764eff380aaSAnirudh Venkataramanan void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi)
765eff380aaSAnirudh Venkataramanan {
766eff380aaSAnirudh Venkataramanan int q_vectors = vsi->num_q_vectors;
76788865fc4SKarol Kolacinski u16 tx_rings_rem, rx_rings_rem;
768eff380aaSAnirudh Venkataramanan int v_id;
769eff380aaSAnirudh Venkataramanan
770eff380aaSAnirudh Venkataramanan /* initially assigning remaining rings count to VSIs num queue value */
771eff380aaSAnirudh Venkataramanan tx_rings_rem = vsi->num_txq;
772eff380aaSAnirudh Venkataramanan rx_rings_rem = vsi->num_rxq;
773eff380aaSAnirudh Venkataramanan
774eff380aaSAnirudh Venkataramanan for (v_id = 0; v_id < q_vectors; v_id++) {
775eff380aaSAnirudh Venkataramanan struct ice_q_vector *q_vector = vsi->q_vectors[v_id];
77688865fc4SKarol Kolacinski u8 tx_rings_per_v, rx_rings_per_v;
77788865fc4SKarol Kolacinski u16 q_id, q_base;
778eff380aaSAnirudh Venkataramanan
779eff380aaSAnirudh Venkataramanan /* Tx rings mapping to vector */
78088865fc4SKarol Kolacinski tx_rings_per_v = (u8)DIV_ROUND_UP(tx_rings_rem,
78188865fc4SKarol Kolacinski q_vectors - v_id);
782eff380aaSAnirudh Venkataramanan q_vector->num_ring_tx = tx_rings_per_v;
783e72bba21SMaciej Fijalkowski q_vector->tx.tx_ring = NULL;
784eff380aaSAnirudh Venkataramanan q_vector->tx.itr_idx = ICE_TX_ITR;
785eff380aaSAnirudh Venkataramanan q_base = vsi->num_txq - tx_rings_rem;
786eff380aaSAnirudh Venkataramanan
787eff380aaSAnirudh Venkataramanan for (q_id = q_base; q_id < (q_base + tx_rings_per_v); q_id++) {
788e72bba21SMaciej Fijalkowski struct ice_tx_ring *tx_ring = vsi->tx_rings[q_id];
789eff380aaSAnirudh Venkataramanan
790eff380aaSAnirudh Venkataramanan tx_ring->q_vector = q_vector;
791e72bba21SMaciej Fijalkowski tx_ring->next = q_vector->tx.tx_ring;
792e72bba21SMaciej Fijalkowski q_vector->tx.tx_ring = tx_ring;
793eff380aaSAnirudh Venkataramanan }
794eff380aaSAnirudh Venkataramanan tx_rings_rem -= tx_rings_per_v;
795eff380aaSAnirudh Venkataramanan
796eff380aaSAnirudh Venkataramanan /* Rx rings mapping to vector */
79788865fc4SKarol Kolacinski rx_rings_per_v = (u8)DIV_ROUND_UP(rx_rings_rem,
79888865fc4SKarol Kolacinski q_vectors - v_id);
799eff380aaSAnirudh Venkataramanan q_vector->num_ring_rx = rx_rings_per_v;
800e72bba21SMaciej Fijalkowski q_vector->rx.rx_ring = NULL;
801eff380aaSAnirudh Venkataramanan q_vector->rx.itr_idx = ICE_RX_ITR;
802eff380aaSAnirudh Venkataramanan q_base = vsi->num_rxq - rx_rings_rem;
803eff380aaSAnirudh Venkataramanan
804eff380aaSAnirudh Venkataramanan for (q_id = q_base; q_id < (q_base + rx_rings_per_v); q_id++) {
805e72bba21SMaciej Fijalkowski struct ice_rx_ring *rx_ring = vsi->rx_rings[q_id];
806eff380aaSAnirudh Venkataramanan
807eff380aaSAnirudh Venkataramanan rx_ring->q_vector = q_vector;
808e72bba21SMaciej Fijalkowski rx_ring->next = q_vector->rx.rx_ring;
809e72bba21SMaciej Fijalkowski q_vector->rx.rx_ring = rx_ring;
810eff380aaSAnirudh Venkataramanan }
811eff380aaSAnirudh Venkataramanan rx_rings_rem -= rx_rings_per_v;
812eff380aaSAnirudh Venkataramanan }
813eff380aaSAnirudh Venkataramanan }
814eff380aaSAnirudh Venkataramanan
815eff380aaSAnirudh Venkataramanan /**
816eff380aaSAnirudh Venkataramanan * ice_vsi_free_q_vectors - Free memory allocated for interrupt vectors
817eff380aaSAnirudh Venkataramanan * @vsi: the VSI having memory freed
818eff380aaSAnirudh Venkataramanan */
ice_vsi_free_q_vectors(struct ice_vsi * vsi)819eff380aaSAnirudh Venkataramanan void ice_vsi_free_q_vectors(struct ice_vsi *vsi)
820eff380aaSAnirudh Venkataramanan {
821eff380aaSAnirudh Venkataramanan int v_idx;
822eff380aaSAnirudh Venkataramanan
823eff380aaSAnirudh Venkataramanan ice_for_each_q_vector(vsi, v_idx)
824eff380aaSAnirudh Venkataramanan ice_free_q_vector(vsi, v_idx);
825b3e7b3a6SMichal Swiatkowski
826b3e7b3a6SMichal Swiatkowski vsi->num_q_vectors = 0;
827eff380aaSAnirudh Venkataramanan }
828eff380aaSAnirudh Venkataramanan
829eff380aaSAnirudh Venkataramanan /**
830eff380aaSAnirudh Venkataramanan * ice_vsi_cfg_txq - Configure single Tx queue
831eff380aaSAnirudh Venkataramanan * @vsi: the VSI that queue belongs to
832eff380aaSAnirudh Venkataramanan * @ring: Tx ring to be configured
833eff380aaSAnirudh Venkataramanan * @qg_buf: queue group buffer
834eff380aaSAnirudh Venkataramanan */
835eff380aaSAnirudh Venkataramanan int
ice_vsi_cfg_txq(struct ice_vsi * vsi,struct ice_tx_ring * ring,struct ice_aqc_add_tx_qgrp * qg_buf)836e72bba21SMaciej Fijalkowski ice_vsi_cfg_txq(struct ice_vsi *vsi, struct ice_tx_ring *ring,
837e75d1b2cSMaciej Fijalkowski struct ice_aqc_add_tx_qgrp *qg_buf)
838eff380aaSAnirudh Venkataramanan {
83966486d89SBruce Allan u8 buf_len = struct_size(qg_buf, txqs, 1);
840eff380aaSAnirudh Venkataramanan struct ice_tlan_ctx tlan_ctx = { 0 };
841eff380aaSAnirudh Venkataramanan struct ice_aqc_add_txqs_perq *txq;
8420754d65bSKiran Patil struct ice_channel *ch = ring->ch;
843eff380aaSAnirudh Venkataramanan struct ice_pf *pf = vsi->back;
8447e34786aSBruce Allan struct ice_hw *hw = &pf->hw;
8455e24d598STony Nguyen int status;
846eff380aaSAnirudh Venkataramanan u16 pf_q;
847e75d1b2cSMaciej Fijalkowski u8 tc;
848eff380aaSAnirudh Venkataramanan
849634da4c1SBenita Bose /* Configure XPS */
850634da4c1SBenita Bose ice_cfg_xps_tx_ring(ring);
851634da4c1SBenita Bose
852eff380aaSAnirudh Venkataramanan pf_q = ring->reg_idx;
853eff380aaSAnirudh Venkataramanan ice_setup_tx_ctx(ring, &tlan_ctx, pf_q);
854eff380aaSAnirudh Venkataramanan /* copy context contents into the qg_buf */
855eff380aaSAnirudh Venkataramanan qg_buf->txqs[0].txq_id = cpu_to_le16(pf_q);
8567e34786aSBruce Allan ice_set_ctx(hw, (u8 *)&tlan_ctx, qg_buf->txqs[0].txq_ctx,
857eff380aaSAnirudh Venkataramanan ice_tlan_ctx_info);
858eff380aaSAnirudh Venkataramanan
859eff380aaSAnirudh Venkataramanan /* init queue specific tail reg. It is referred as
860eff380aaSAnirudh Venkataramanan * transmit comm scheduler queue doorbell.
861eff380aaSAnirudh Venkataramanan */
8627e34786aSBruce Allan ring->tail = hw->hw_addr + QTX_COMM_DBELL(pf_q);
863eff380aaSAnirudh Venkataramanan
864e75d1b2cSMaciej Fijalkowski if (IS_ENABLED(CONFIG_DCB))
865e75d1b2cSMaciej Fijalkowski tc = ring->dcb_tc;
866e75d1b2cSMaciej Fijalkowski else
867e75d1b2cSMaciej Fijalkowski tc = 0;
868e75d1b2cSMaciej Fijalkowski
869eff380aaSAnirudh Venkataramanan /* Add unique software queue handle of the Tx queue per
870eff380aaSAnirudh Venkataramanan * TC into the VSI Tx ring
871eff380aaSAnirudh Venkataramanan */
872f66756e0SGrzegorz Nitka if (vsi->type == ICE_VSI_SWITCHDEV_CTRL) {
873e72bba21SMaciej Fijalkowski ring->q_handle = ice_eswitch_calc_txq_handle(ring);
874f66756e0SGrzegorz Nitka
875f66756e0SGrzegorz Nitka if (ring->q_handle == ICE_INVAL_Q_INDEX)
876f66756e0SGrzegorz Nitka return -ENODEV;
877f66756e0SGrzegorz Nitka } else {
878e72bba21SMaciej Fijalkowski ring->q_handle = ice_calc_txq_handle(vsi, ring, tc);
879f66756e0SGrzegorz Nitka }
880eff380aaSAnirudh Venkataramanan
8810754d65bSKiran Patil if (ch)
8820754d65bSKiran Patil status = ice_ena_vsi_txq(vsi->port_info, ch->ch_vsi->idx, 0,
8830754d65bSKiran Patil ring->q_handle, 1, qg_buf, buf_len,
8840754d65bSKiran Patil NULL);
8850754d65bSKiran Patil else
8860754d65bSKiran Patil status = ice_ena_vsi_txq(vsi->port_info, vsi->idx, tc,
8870754d65bSKiran Patil ring->q_handle, 1, qg_buf, buf_len,
8880754d65bSKiran Patil NULL);
889eff380aaSAnirudh Venkataramanan if (status) {
8905f87ec48STony Nguyen dev_err(ice_pf_to_dev(pf), "Failed to set LAN Tx queue context, error: %d\n",
8915f87ec48STony Nguyen status);
892c1484691STony Nguyen return status;
893eff380aaSAnirudh Venkataramanan }
894eff380aaSAnirudh Venkataramanan
895eff380aaSAnirudh Venkataramanan /* Add Tx Queue TEID into the VSI Tx ring from the
896eff380aaSAnirudh Venkataramanan * response. This will complete configuring and
897eff380aaSAnirudh Venkataramanan * enabling the queue.
898eff380aaSAnirudh Venkataramanan */
899eff380aaSAnirudh Venkataramanan txq = &qg_buf->txqs[0];
900eff380aaSAnirudh Venkataramanan if (pf_q == le16_to_cpu(txq->txq_id))
901eff380aaSAnirudh Venkataramanan ring->txq_teid = le32_to_cpu(txq->q_teid);
902eff380aaSAnirudh Venkataramanan
903eff380aaSAnirudh Venkataramanan return 0;
904eff380aaSAnirudh Venkataramanan }
905eff380aaSAnirudh Venkataramanan
906eff380aaSAnirudh Venkataramanan /**
907eff380aaSAnirudh Venkataramanan * ice_cfg_itr - configure the initial interrupt throttle values
908eff380aaSAnirudh Venkataramanan * @hw: pointer to the HW structure
909eff380aaSAnirudh Venkataramanan * @q_vector: interrupt vector that's being configured
910eff380aaSAnirudh Venkataramanan *
911eff380aaSAnirudh Venkataramanan * Configure interrupt throttling values for the ring containers that are
912eff380aaSAnirudh Venkataramanan * associated with the interrupt vector passed in.
913eff380aaSAnirudh Venkataramanan */
ice_cfg_itr(struct ice_hw * hw,struct ice_q_vector * q_vector)914eff380aaSAnirudh Venkataramanan void ice_cfg_itr(struct ice_hw *hw, struct ice_q_vector *q_vector)
915eff380aaSAnirudh Venkataramanan {
916eff380aaSAnirudh Venkataramanan ice_cfg_itr_gran(hw);
917eff380aaSAnirudh Venkataramanan
918b8b47723SJesse Brandeburg if (q_vector->num_ring_rx)
919b8b47723SJesse Brandeburg ice_write_itr(&q_vector->rx, q_vector->rx.itr_setting);
920eff380aaSAnirudh Venkataramanan
921b8b47723SJesse Brandeburg if (q_vector->num_ring_tx)
922b8b47723SJesse Brandeburg ice_write_itr(&q_vector->tx, q_vector->tx.itr_setting);
923eff380aaSAnirudh Venkataramanan
924b8b47723SJesse Brandeburg ice_write_intrl(q_vector, q_vector->intrl);
925eff380aaSAnirudh Venkataramanan }
926eff380aaSAnirudh Venkataramanan
927eff380aaSAnirudh Venkataramanan /**
928eff380aaSAnirudh Venkataramanan * ice_cfg_txq_interrupt - configure interrupt on Tx queue
929eff380aaSAnirudh Venkataramanan * @vsi: the VSI being configured
930eff380aaSAnirudh Venkataramanan * @txq: Tx queue being mapped to MSI-X vector
931eff380aaSAnirudh Venkataramanan * @msix_idx: MSI-X vector index within the function
932eff380aaSAnirudh Venkataramanan * @itr_idx: ITR index of the interrupt cause
933eff380aaSAnirudh Venkataramanan *
934eff380aaSAnirudh Venkataramanan * Configure interrupt on Tx queue by associating Tx queue to MSI-X vector
935eff380aaSAnirudh Venkataramanan * within the function space.
936eff380aaSAnirudh Venkataramanan */
937eff380aaSAnirudh Venkataramanan void
ice_cfg_txq_interrupt(struct ice_vsi * vsi,u16 txq,u16 msix_idx,u16 itr_idx)938eff380aaSAnirudh Venkataramanan ice_cfg_txq_interrupt(struct ice_vsi *vsi, u16 txq, u16 msix_idx, u16 itr_idx)
939eff380aaSAnirudh Venkataramanan {
940eff380aaSAnirudh Venkataramanan struct ice_pf *pf = vsi->back;
941eff380aaSAnirudh Venkataramanan struct ice_hw *hw = &pf->hw;
942eff380aaSAnirudh Venkataramanan u32 val;
943eff380aaSAnirudh Venkataramanan
944eff380aaSAnirudh Venkataramanan itr_idx = (itr_idx << QINT_TQCTL_ITR_INDX_S) & QINT_TQCTL_ITR_INDX_M;
945eff380aaSAnirudh Venkataramanan
946eff380aaSAnirudh Venkataramanan val = QINT_TQCTL_CAUSE_ENA_M | itr_idx |
947eff380aaSAnirudh Venkataramanan ((msix_idx << QINT_TQCTL_MSIX_INDX_S) & QINT_TQCTL_MSIX_INDX_M);
948eff380aaSAnirudh Venkataramanan
949eff380aaSAnirudh Venkataramanan wr32(hw, QINT_TQCTL(vsi->txq_map[txq]), val);
950efc2214bSMaciej Fijalkowski if (ice_is_xdp_ena_vsi(vsi)) {
951efc2214bSMaciej Fijalkowski u32 xdp_txq = txq + vsi->num_xdp_txq;
952efc2214bSMaciej Fijalkowski
953efc2214bSMaciej Fijalkowski wr32(hw, QINT_TQCTL(vsi->txq_map[xdp_txq]),
954efc2214bSMaciej Fijalkowski val);
955efc2214bSMaciej Fijalkowski }
956efc2214bSMaciej Fijalkowski ice_flush(hw);
957eff380aaSAnirudh Venkataramanan }
958eff380aaSAnirudh Venkataramanan
959eff380aaSAnirudh Venkataramanan /**
960eff380aaSAnirudh Venkataramanan * ice_cfg_rxq_interrupt - configure interrupt on Rx queue
961eff380aaSAnirudh Venkataramanan * @vsi: the VSI being configured
962eff380aaSAnirudh Venkataramanan * @rxq: Rx queue being mapped to MSI-X vector
963eff380aaSAnirudh Venkataramanan * @msix_idx: MSI-X vector index within the function
964eff380aaSAnirudh Venkataramanan * @itr_idx: ITR index of the interrupt cause
965eff380aaSAnirudh Venkataramanan *
966eff380aaSAnirudh Venkataramanan * Configure interrupt on Rx queue by associating Rx queue to MSI-X vector
967eff380aaSAnirudh Venkataramanan * within the function space.
968eff380aaSAnirudh Venkataramanan */
969eff380aaSAnirudh Venkataramanan void
ice_cfg_rxq_interrupt(struct ice_vsi * vsi,u16 rxq,u16 msix_idx,u16 itr_idx)970eff380aaSAnirudh Venkataramanan ice_cfg_rxq_interrupt(struct ice_vsi *vsi, u16 rxq, u16 msix_idx, u16 itr_idx)
971eff380aaSAnirudh Venkataramanan {
972eff380aaSAnirudh Venkataramanan struct ice_pf *pf = vsi->back;
973eff380aaSAnirudh Venkataramanan struct ice_hw *hw = &pf->hw;
974eff380aaSAnirudh Venkataramanan u32 val;
975eff380aaSAnirudh Venkataramanan
976eff380aaSAnirudh Venkataramanan itr_idx = (itr_idx << QINT_RQCTL_ITR_INDX_S) & QINT_RQCTL_ITR_INDX_M;
977eff380aaSAnirudh Venkataramanan
978eff380aaSAnirudh Venkataramanan val = QINT_RQCTL_CAUSE_ENA_M | itr_idx |
979eff380aaSAnirudh Venkataramanan ((msix_idx << QINT_RQCTL_MSIX_INDX_S) & QINT_RQCTL_MSIX_INDX_M);
980eff380aaSAnirudh Venkataramanan
981eff380aaSAnirudh Venkataramanan wr32(hw, QINT_RQCTL(vsi->rxq_map[rxq]), val);
982eff380aaSAnirudh Venkataramanan
983eff380aaSAnirudh Venkataramanan ice_flush(hw);
984eff380aaSAnirudh Venkataramanan }
985eff380aaSAnirudh Venkataramanan
986eff380aaSAnirudh Venkataramanan /**
987eff380aaSAnirudh Venkataramanan * ice_trigger_sw_intr - trigger a software interrupt
988eff380aaSAnirudh Venkataramanan * @hw: pointer to the HW structure
989eff380aaSAnirudh Venkataramanan * @q_vector: interrupt vector to trigger the software interrupt for
990eff380aaSAnirudh Venkataramanan */
ice_trigger_sw_intr(struct ice_hw * hw,struct ice_q_vector * q_vector)991eff380aaSAnirudh Venkataramanan void ice_trigger_sw_intr(struct ice_hw *hw, struct ice_q_vector *q_vector)
992eff380aaSAnirudh Venkataramanan {
993eff380aaSAnirudh Venkataramanan wr32(hw, GLINT_DYN_CTL(q_vector->reg_idx),
994eff380aaSAnirudh Venkataramanan (ICE_ITR_NONE << GLINT_DYN_CTL_ITR_INDX_S) |
995eff380aaSAnirudh Venkataramanan GLINT_DYN_CTL_SWINT_TRIG_M |
996eff380aaSAnirudh Venkataramanan GLINT_DYN_CTL_INTENA_M);
997eff380aaSAnirudh Venkataramanan }
998eff380aaSAnirudh Venkataramanan
999eff380aaSAnirudh Venkataramanan /**
1000eff380aaSAnirudh Venkataramanan * ice_vsi_stop_tx_ring - Disable single Tx ring
1001eff380aaSAnirudh Venkataramanan * @vsi: the VSI being configured
1002eff380aaSAnirudh Venkataramanan * @rst_src: reset source
1003eff380aaSAnirudh Venkataramanan * @rel_vmvf_num: Relative ID of VF/VM
1004eff380aaSAnirudh Venkataramanan * @ring: Tx ring to be stopped
1005eff380aaSAnirudh Venkataramanan * @txq_meta: Meta data of Tx ring to be stopped
1006eff380aaSAnirudh Venkataramanan */
1007eff380aaSAnirudh Venkataramanan int
ice_vsi_stop_tx_ring(struct ice_vsi * vsi,enum ice_disq_rst_src rst_src,u16 rel_vmvf_num,struct ice_tx_ring * ring,struct ice_txq_meta * txq_meta)1008eff380aaSAnirudh Venkataramanan ice_vsi_stop_tx_ring(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
1009e72bba21SMaciej Fijalkowski u16 rel_vmvf_num, struct ice_tx_ring *ring,
1010eff380aaSAnirudh Venkataramanan struct ice_txq_meta *txq_meta)
1011eff380aaSAnirudh Venkataramanan {
1012eff380aaSAnirudh Venkataramanan struct ice_pf *pf = vsi->back;
1013eff380aaSAnirudh Venkataramanan struct ice_q_vector *q_vector;
1014eff380aaSAnirudh Venkataramanan struct ice_hw *hw = &pf->hw;
10155e24d598STony Nguyen int status;
1016eff380aaSAnirudh Venkataramanan u32 val;
1017eff380aaSAnirudh Venkataramanan
1018eff380aaSAnirudh Venkataramanan /* clear cause_ena bit for disabled queues */
1019eff380aaSAnirudh Venkataramanan val = rd32(hw, QINT_TQCTL(ring->reg_idx));
1020eff380aaSAnirudh Venkataramanan val &= ~QINT_TQCTL_CAUSE_ENA_M;
1021eff380aaSAnirudh Venkataramanan wr32(hw, QINT_TQCTL(ring->reg_idx), val);
1022eff380aaSAnirudh Venkataramanan
1023eff380aaSAnirudh Venkataramanan /* software is expected to wait for 100 ns */
1024eff380aaSAnirudh Venkataramanan ndelay(100);
1025eff380aaSAnirudh Venkataramanan
1026eff380aaSAnirudh Venkataramanan /* trigger a software interrupt for the vector
1027eff380aaSAnirudh Venkataramanan * associated to the queue to schedule NAPI handler
1028eff380aaSAnirudh Venkataramanan */
1029eff380aaSAnirudh Venkataramanan q_vector = ring->q_vector;
1030f23df522SNorbert Zulinski if (q_vector && !(vsi->vf && ice_is_vf_disabled(vsi->vf)))
1031eff380aaSAnirudh Venkataramanan ice_trigger_sw_intr(hw, q_vector);
1032eff380aaSAnirudh Venkataramanan
1033eff380aaSAnirudh Venkataramanan status = ice_dis_vsi_txq(vsi->port_info, txq_meta->vsi_idx,
1034eff380aaSAnirudh Venkataramanan txq_meta->tc, 1, &txq_meta->q_handle,
1035eff380aaSAnirudh Venkataramanan &txq_meta->q_id, &txq_meta->q_teid, rst_src,
1036eff380aaSAnirudh Venkataramanan rel_vmvf_num, NULL);
1037eff380aaSAnirudh Venkataramanan
1038eff380aaSAnirudh Venkataramanan /* if the disable queue command was exercised during an
1039d54699e2STony Nguyen * active reset flow, -EBUSY is returned.
1040eff380aaSAnirudh Venkataramanan * This is not an error as the reset operation disables
1041eff380aaSAnirudh Venkataramanan * queues at the hardware level anyway.
1042eff380aaSAnirudh Venkataramanan */
1043d54699e2STony Nguyen if (status == -EBUSY) {
104419cce2c6SAnirudh Venkataramanan dev_dbg(ice_pf_to_dev(vsi->back), "Reset in progress. LAN Tx queues already disabled\n");
1045d54699e2STony Nguyen } else if (status == -ENOENT) {
104619cce2c6SAnirudh Venkataramanan dev_dbg(ice_pf_to_dev(vsi->back), "LAN Tx queues do not exist, nothing to disable\n");
1047eff380aaSAnirudh Venkataramanan } else if (status) {
10485f87ec48STony Nguyen dev_dbg(ice_pf_to_dev(vsi->back), "Failed to disable LAN Tx queues, error: %d\n",
10495f87ec48STony Nguyen status);
1050c1484691STony Nguyen return status;
1051eff380aaSAnirudh Venkataramanan }
1052eff380aaSAnirudh Venkataramanan
1053eff380aaSAnirudh Venkataramanan return 0;
1054eff380aaSAnirudh Venkataramanan }
1055eff380aaSAnirudh Venkataramanan
1056eff380aaSAnirudh Venkataramanan /**
1057eff380aaSAnirudh Venkataramanan * ice_fill_txq_meta - Prepare the Tx queue's meta data
1058eff380aaSAnirudh Venkataramanan * @vsi: VSI that ring belongs to
1059eff380aaSAnirudh Venkataramanan * @ring: ring that txq_meta will be based on
1060eff380aaSAnirudh Venkataramanan * @txq_meta: a helper struct that wraps Tx queue's information
1061eff380aaSAnirudh Venkataramanan *
1062eff380aaSAnirudh Venkataramanan * Set up a helper struct that will contain all the necessary fields that
1063eff380aaSAnirudh Venkataramanan * are needed for stopping Tx queue
1064eff380aaSAnirudh Venkataramanan */
1065eff380aaSAnirudh Venkataramanan void
ice_fill_txq_meta(struct ice_vsi * vsi,struct ice_tx_ring * ring,struct ice_txq_meta * txq_meta)1066e72bba21SMaciej Fijalkowski ice_fill_txq_meta(struct ice_vsi *vsi, struct ice_tx_ring *ring,
1067eff380aaSAnirudh Venkataramanan struct ice_txq_meta *txq_meta)
1068eff380aaSAnirudh Venkataramanan {
10690754d65bSKiran Patil struct ice_channel *ch = ring->ch;
1070eff380aaSAnirudh Venkataramanan u8 tc;
1071eff380aaSAnirudh Venkataramanan
1072eff380aaSAnirudh Venkataramanan if (IS_ENABLED(CONFIG_DCB))
1073eff380aaSAnirudh Venkataramanan tc = ring->dcb_tc;
1074eff380aaSAnirudh Venkataramanan else
1075eff380aaSAnirudh Venkataramanan tc = 0;
1076eff380aaSAnirudh Venkataramanan
1077eff380aaSAnirudh Venkataramanan txq_meta->q_id = ring->reg_idx;
1078eff380aaSAnirudh Venkataramanan txq_meta->q_teid = ring->txq_teid;
1079eff380aaSAnirudh Venkataramanan txq_meta->q_handle = ring->q_handle;
10800754d65bSKiran Patil if (ch) {
10810754d65bSKiran Patil txq_meta->vsi_idx = ch->ch_vsi->idx;
10820754d65bSKiran Patil txq_meta->tc = 0;
10830754d65bSKiran Patil } else {
1084eff380aaSAnirudh Venkataramanan txq_meta->vsi_idx = vsi->idx;
1085eff380aaSAnirudh Venkataramanan txq_meta->tc = tc;
1086eff380aaSAnirudh Venkataramanan }
10870754d65bSKiran Patil }
1088