1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /* Copyright (c) 2018, Intel Corporation. */
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun #include "ice.h"
5*4882a593Smuzhiyun #include "ice_base.h"
6*4882a593Smuzhiyun #include "ice_flow.h"
7*4882a593Smuzhiyun #include "ice_lib.h"
8*4882a593Smuzhiyun #include "ice_fltr.h"
9*4882a593Smuzhiyun #include "ice_dcb_lib.h"
10*4882a593Smuzhiyun #include "ice_devlink.h"
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun /**
13*4882a593Smuzhiyun * ice_vsi_type_str - maps VSI type enum to string equivalents
14*4882a593Smuzhiyun * @vsi_type: VSI type enum
15*4882a593Smuzhiyun */
ice_vsi_type_str(enum ice_vsi_type vsi_type)16*4882a593Smuzhiyun const char *ice_vsi_type_str(enum ice_vsi_type vsi_type)
17*4882a593Smuzhiyun {
18*4882a593Smuzhiyun switch (vsi_type) {
19*4882a593Smuzhiyun case ICE_VSI_PF:
20*4882a593Smuzhiyun return "ICE_VSI_PF";
21*4882a593Smuzhiyun case ICE_VSI_VF:
22*4882a593Smuzhiyun return "ICE_VSI_VF";
23*4882a593Smuzhiyun case ICE_VSI_CTRL:
24*4882a593Smuzhiyun return "ICE_VSI_CTRL";
25*4882a593Smuzhiyun case ICE_VSI_LB:
26*4882a593Smuzhiyun return "ICE_VSI_LB";
27*4882a593Smuzhiyun default:
28*4882a593Smuzhiyun return "unknown";
29*4882a593Smuzhiyun }
30*4882a593Smuzhiyun }
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun /**
33*4882a593Smuzhiyun * ice_vsi_ctrl_all_rx_rings - Start or stop a VSI's Rx rings
34*4882a593Smuzhiyun * @vsi: the VSI being configured
35*4882a593Smuzhiyun * @ena: start or stop the Rx rings
36*4882a593Smuzhiyun *
37*4882a593Smuzhiyun * First enable/disable all of the Rx rings, flush any remaining writes, and
38*4882a593Smuzhiyun * then verify that they have all been enabled/disabled successfully. This will
39*4882a593Smuzhiyun * let all of the register writes complete when enabling/disabling the Rx rings
40*4882a593Smuzhiyun * before waiting for the change in hardware to complete.
41*4882a593Smuzhiyun */
ice_vsi_ctrl_all_rx_rings(struct ice_vsi * vsi,bool ena)42*4882a593Smuzhiyun static int ice_vsi_ctrl_all_rx_rings(struct ice_vsi *vsi, bool ena)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun int ret = 0;
45*4882a593Smuzhiyun u16 i;
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun for (i = 0; i < vsi->num_rxq; i++)
48*4882a593Smuzhiyun ice_vsi_ctrl_one_rx_ring(vsi, ena, i, false);
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun ice_flush(&vsi->back->hw);
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun for (i = 0; i < vsi->num_rxq; i++) {
53*4882a593Smuzhiyun ret = ice_vsi_wait_one_rx_ring(vsi, ena, i);
54*4882a593Smuzhiyun if (ret)
55*4882a593Smuzhiyun break;
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun return ret;
59*4882a593Smuzhiyun }
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun /**
62*4882a593Smuzhiyun * ice_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the VSI
63*4882a593Smuzhiyun * @vsi: VSI pointer
64*4882a593Smuzhiyun *
65*4882a593Smuzhiyun * On error: returns error code (negative)
66*4882a593Smuzhiyun * On success: returns 0
67*4882a593Smuzhiyun */
ice_vsi_alloc_arrays(struct ice_vsi * vsi)68*4882a593Smuzhiyun static int ice_vsi_alloc_arrays(struct ice_vsi *vsi)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
71*4882a593Smuzhiyun struct device *dev;
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun /* allocate memory for both Tx and Rx ring pointers */
76*4882a593Smuzhiyun vsi->tx_rings = devm_kcalloc(dev, vsi->alloc_txq,
77*4882a593Smuzhiyun sizeof(*vsi->tx_rings), GFP_KERNEL);
78*4882a593Smuzhiyun if (!vsi->tx_rings)
79*4882a593Smuzhiyun return -ENOMEM;
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun vsi->rx_rings = devm_kcalloc(dev, vsi->alloc_rxq,
82*4882a593Smuzhiyun sizeof(*vsi->rx_rings), GFP_KERNEL);
83*4882a593Smuzhiyun if (!vsi->rx_rings)
84*4882a593Smuzhiyun goto err_rings;
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun /* txq_map needs to have enough space to track both Tx (stack) rings
87*4882a593Smuzhiyun * and XDP rings; at this point vsi->num_xdp_txq might not be set,
88*4882a593Smuzhiyun * so use num_possible_cpus() as we want to always provide XDP ring
89*4882a593Smuzhiyun * per CPU, regardless of queue count settings from user that might
90*4882a593Smuzhiyun * have come from ethtool's set_channels() callback;
91*4882a593Smuzhiyun */
92*4882a593Smuzhiyun vsi->txq_map = devm_kcalloc(dev, (vsi->alloc_txq + num_possible_cpus()),
93*4882a593Smuzhiyun sizeof(*vsi->txq_map), GFP_KERNEL);
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun if (!vsi->txq_map)
96*4882a593Smuzhiyun goto err_txq_map;
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun vsi->rxq_map = devm_kcalloc(dev, vsi->alloc_rxq,
99*4882a593Smuzhiyun sizeof(*vsi->rxq_map), GFP_KERNEL);
100*4882a593Smuzhiyun if (!vsi->rxq_map)
101*4882a593Smuzhiyun goto err_rxq_map;
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun /* There is no need to allocate q_vectors for a loopback VSI. */
104*4882a593Smuzhiyun if (vsi->type == ICE_VSI_LB)
105*4882a593Smuzhiyun return 0;
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun /* allocate memory for q_vector pointers */
108*4882a593Smuzhiyun vsi->q_vectors = devm_kcalloc(dev, vsi->num_q_vectors,
109*4882a593Smuzhiyun sizeof(*vsi->q_vectors), GFP_KERNEL);
110*4882a593Smuzhiyun if (!vsi->q_vectors)
111*4882a593Smuzhiyun goto err_vectors;
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun return 0;
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun err_vectors:
116*4882a593Smuzhiyun devm_kfree(dev, vsi->rxq_map);
117*4882a593Smuzhiyun err_rxq_map:
118*4882a593Smuzhiyun devm_kfree(dev, vsi->txq_map);
119*4882a593Smuzhiyun err_txq_map:
120*4882a593Smuzhiyun devm_kfree(dev, vsi->rx_rings);
121*4882a593Smuzhiyun err_rings:
122*4882a593Smuzhiyun devm_kfree(dev, vsi->tx_rings);
123*4882a593Smuzhiyun return -ENOMEM;
124*4882a593Smuzhiyun }
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun /**
127*4882a593Smuzhiyun * ice_vsi_set_num_desc - Set number of descriptors for queues on this VSI
128*4882a593Smuzhiyun * @vsi: the VSI being configured
129*4882a593Smuzhiyun */
ice_vsi_set_num_desc(struct ice_vsi * vsi)130*4882a593Smuzhiyun static void ice_vsi_set_num_desc(struct ice_vsi *vsi)
131*4882a593Smuzhiyun {
132*4882a593Smuzhiyun switch (vsi->type) {
133*4882a593Smuzhiyun case ICE_VSI_PF:
134*4882a593Smuzhiyun case ICE_VSI_CTRL:
135*4882a593Smuzhiyun case ICE_VSI_LB:
136*4882a593Smuzhiyun /* a user could change the values of num_[tr]x_desc using
137*4882a593Smuzhiyun * ethtool -G so we should keep those values instead of
138*4882a593Smuzhiyun * overwriting them with the defaults.
139*4882a593Smuzhiyun */
140*4882a593Smuzhiyun if (!vsi->num_rx_desc)
141*4882a593Smuzhiyun vsi->num_rx_desc = ICE_DFLT_NUM_RX_DESC;
142*4882a593Smuzhiyun if (!vsi->num_tx_desc)
143*4882a593Smuzhiyun vsi->num_tx_desc = ICE_DFLT_NUM_TX_DESC;
144*4882a593Smuzhiyun break;
145*4882a593Smuzhiyun default:
146*4882a593Smuzhiyun dev_dbg(ice_pf_to_dev(vsi->back), "Not setting number of Tx/Rx descriptors for VSI type %d\n",
147*4882a593Smuzhiyun vsi->type);
148*4882a593Smuzhiyun break;
149*4882a593Smuzhiyun }
150*4882a593Smuzhiyun }
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun /**
153*4882a593Smuzhiyun * ice_vsi_set_num_qs - Set number of queues, descriptors and vectors for a VSI
154*4882a593Smuzhiyun * @vsi: the VSI being configured
155*4882a593Smuzhiyun * @vf_id: ID of the VF being configured
156*4882a593Smuzhiyun *
157*4882a593Smuzhiyun * Return 0 on success and a negative value on error
158*4882a593Smuzhiyun */
ice_vsi_set_num_qs(struct ice_vsi * vsi,u16 vf_id)159*4882a593Smuzhiyun static void ice_vsi_set_num_qs(struct ice_vsi *vsi, u16 vf_id)
160*4882a593Smuzhiyun {
161*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
162*4882a593Smuzhiyun struct ice_vf *vf = NULL;
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun if (vsi->type == ICE_VSI_VF)
165*4882a593Smuzhiyun vsi->vf_id = vf_id;
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun switch (vsi->type) {
168*4882a593Smuzhiyun case ICE_VSI_PF:
169*4882a593Smuzhiyun vsi->alloc_txq = min3(pf->num_lan_msix,
170*4882a593Smuzhiyun ice_get_avail_txq_count(pf),
171*4882a593Smuzhiyun (u16)num_online_cpus());
172*4882a593Smuzhiyun if (vsi->req_txq) {
173*4882a593Smuzhiyun vsi->alloc_txq = vsi->req_txq;
174*4882a593Smuzhiyun vsi->num_txq = vsi->req_txq;
175*4882a593Smuzhiyun }
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun pf->num_lan_tx = vsi->alloc_txq;
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun /* only 1 Rx queue unless RSS is enabled */
180*4882a593Smuzhiyun if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
181*4882a593Smuzhiyun vsi->alloc_rxq = 1;
182*4882a593Smuzhiyun } else {
183*4882a593Smuzhiyun vsi->alloc_rxq = min3(pf->num_lan_msix,
184*4882a593Smuzhiyun ice_get_avail_rxq_count(pf),
185*4882a593Smuzhiyun (u16)num_online_cpus());
186*4882a593Smuzhiyun if (vsi->req_rxq) {
187*4882a593Smuzhiyun vsi->alloc_rxq = vsi->req_rxq;
188*4882a593Smuzhiyun vsi->num_rxq = vsi->req_rxq;
189*4882a593Smuzhiyun }
190*4882a593Smuzhiyun }
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun pf->num_lan_rx = vsi->alloc_rxq;
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun vsi->num_q_vectors = min_t(int, pf->num_lan_msix,
195*4882a593Smuzhiyun max_t(int, vsi->alloc_rxq,
196*4882a593Smuzhiyun vsi->alloc_txq));
197*4882a593Smuzhiyun break;
198*4882a593Smuzhiyun case ICE_VSI_VF:
199*4882a593Smuzhiyun vf = &pf->vf[vsi->vf_id];
200*4882a593Smuzhiyun if (vf->num_req_qs)
201*4882a593Smuzhiyun vf->num_vf_qs = vf->num_req_qs;
202*4882a593Smuzhiyun vsi->alloc_txq = vf->num_vf_qs;
203*4882a593Smuzhiyun vsi->alloc_rxq = vf->num_vf_qs;
204*4882a593Smuzhiyun /* pf->num_msix_per_vf includes (VF miscellaneous vector +
205*4882a593Smuzhiyun * data queue interrupts). Since vsi->num_q_vectors is number
206*4882a593Smuzhiyun * of queues vectors, subtract 1 (ICE_NONQ_VECS_VF) from the
207*4882a593Smuzhiyun * original vector count
208*4882a593Smuzhiyun */
209*4882a593Smuzhiyun vsi->num_q_vectors = pf->num_msix_per_vf - ICE_NONQ_VECS_VF;
210*4882a593Smuzhiyun break;
211*4882a593Smuzhiyun case ICE_VSI_CTRL:
212*4882a593Smuzhiyun vsi->alloc_txq = 1;
213*4882a593Smuzhiyun vsi->alloc_rxq = 1;
214*4882a593Smuzhiyun vsi->num_q_vectors = 1;
215*4882a593Smuzhiyun break;
216*4882a593Smuzhiyun case ICE_VSI_LB:
217*4882a593Smuzhiyun vsi->alloc_txq = 1;
218*4882a593Smuzhiyun vsi->alloc_rxq = 1;
219*4882a593Smuzhiyun break;
220*4882a593Smuzhiyun default:
221*4882a593Smuzhiyun dev_warn(ice_pf_to_dev(pf), "Unknown VSI type %d\n", vsi->type);
222*4882a593Smuzhiyun break;
223*4882a593Smuzhiyun }
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun ice_vsi_set_num_desc(vsi);
226*4882a593Smuzhiyun }
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun /**
229*4882a593Smuzhiyun * ice_get_free_slot - get the next non-NULL location index in array
230*4882a593Smuzhiyun * @array: array to search
231*4882a593Smuzhiyun * @size: size of the array
232*4882a593Smuzhiyun * @curr: last known occupied index to be used as a search hint
233*4882a593Smuzhiyun *
234*4882a593Smuzhiyun * void * is being used to keep the functionality generic. This lets us use this
235*4882a593Smuzhiyun * function on any array of pointers.
236*4882a593Smuzhiyun */
ice_get_free_slot(void * array,int size,int curr)237*4882a593Smuzhiyun static int ice_get_free_slot(void *array, int size, int curr)
238*4882a593Smuzhiyun {
239*4882a593Smuzhiyun int **tmp_array = (int **)array;
240*4882a593Smuzhiyun int next;
241*4882a593Smuzhiyun
242*4882a593Smuzhiyun if (curr < (size - 1) && !tmp_array[curr + 1]) {
243*4882a593Smuzhiyun next = curr + 1;
244*4882a593Smuzhiyun } else {
245*4882a593Smuzhiyun int i = 0;
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun while ((i < size) && (tmp_array[i]))
248*4882a593Smuzhiyun i++;
249*4882a593Smuzhiyun if (i == size)
250*4882a593Smuzhiyun next = ICE_NO_VSI;
251*4882a593Smuzhiyun else
252*4882a593Smuzhiyun next = i;
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun return next;
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun /**
258*4882a593Smuzhiyun * ice_vsi_delete - delete a VSI from the switch
259*4882a593Smuzhiyun * @vsi: pointer to VSI being removed
260*4882a593Smuzhiyun */
ice_vsi_delete(struct ice_vsi * vsi)261*4882a593Smuzhiyun static void ice_vsi_delete(struct ice_vsi *vsi)
262*4882a593Smuzhiyun {
263*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
264*4882a593Smuzhiyun struct ice_vsi_ctx *ctxt;
265*4882a593Smuzhiyun enum ice_status status;
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
268*4882a593Smuzhiyun if (!ctxt)
269*4882a593Smuzhiyun return;
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun if (vsi->type == ICE_VSI_VF)
272*4882a593Smuzhiyun ctxt->vf_num = vsi->vf_id;
273*4882a593Smuzhiyun ctxt->vsi_num = vsi->vsi_num;
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun memcpy(&ctxt->info, &vsi->info, sizeof(ctxt->info));
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun status = ice_free_vsi(&pf->hw, vsi->idx, ctxt, false, NULL);
278*4882a593Smuzhiyun if (status)
279*4882a593Smuzhiyun dev_err(ice_pf_to_dev(pf), "Failed to delete VSI %i in FW - error: %s\n",
280*4882a593Smuzhiyun vsi->vsi_num, ice_stat_str(status));
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun kfree(ctxt);
283*4882a593Smuzhiyun }
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun /**
286*4882a593Smuzhiyun * ice_vsi_free_arrays - De-allocate queue and vector pointer arrays for the VSI
287*4882a593Smuzhiyun * @vsi: pointer to VSI being cleared
288*4882a593Smuzhiyun */
ice_vsi_free_arrays(struct ice_vsi * vsi)289*4882a593Smuzhiyun static void ice_vsi_free_arrays(struct ice_vsi *vsi)
290*4882a593Smuzhiyun {
291*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
292*4882a593Smuzhiyun struct device *dev;
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun /* free the ring and vector containers */
297*4882a593Smuzhiyun if (vsi->q_vectors) {
298*4882a593Smuzhiyun devm_kfree(dev, vsi->q_vectors);
299*4882a593Smuzhiyun vsi->q_vectors = NULL;
300*4882a593Smuzhiyun }
301*4882a593Smuzhiyun if (vsi->tx_rings) {
302*4882a593Smuzhiyun devm_kfree(dev, vsi->tx_rings);
303*4882a593Smuzhiyun vsi->tx_rings = NULL;
304*4882a593Smuzhiyun }
305*4882a593Smuzhiyun if (vsi->rx_rings) {
306*4882a593Smuzhiyun devm_kfree(dev, vsi->rx_rings);
307*4882a593Smuzhiyun vsi->rx_rings = NULL;
308*4882a593Smuzhiyun }
309*4882a593Smuzhiyun if (vsi->txq_map) {
310*4882a593Smuzhiyun devm_kfree(dev, vsi->txq_map);
311*4882a593Smuzhiyun vsi->txq_map = NULL;
312*4882a593Smuzhiyun }
313*4882a593Smuzhiyun if (vsi->rxq_map) {
314*4882a593Smuzhiyun devm_kfree(dev, vsi->rxq_map);
315*4882a593Smuzhiyun vsi->rxq_map = NULL;
316*4882a593Smuzhiyun }
317*4882a593Smuzhiyun }
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun /**
320*4882a593Smuzhiyun * ice_vsi_clear - clean up and deallocate the provided VSI
321*4882a593Smuzhiyun * @vsi: pointer to VSI being cleared
322*4882a593Smuzhiyun *
323*4882a593Smuzhiyun * This deallocates the VSI's queue resources, removes it from the PF's
324*4882a593Smuzhiyun * VSI array if necessary, and deallocates the VSI
325*4882a593Smuzhiyun *
326*4882a593Smuzhiyun * Returns 0 on success, negative on failure
327*4882a593Smuzhiyun */
ice_vsi_clear(struct ice_vsi * vsi)328*4882a593Smuzhiyun static int ice_vsi_clear(struct ice_vsi *vsi)
329*4882a593Smuzhiyun {
330*4882a593Smuzhiyun struct ice_pf *pf = NULL;
331*4882a593Smuzhiyun struct device *dev;
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun if (!vsi)
334*4882a593Smuzhiyun return 0;
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun if (!vsi->back)
337*4882a593Smuzhiyun return -EINVAL;
338*4882a593Smuzhiyun
339*4882a593Smuzhiyun pf = vsi->back;
340*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun if (!pf->vsi[vsi->idx] || pf->vsi[vsi->idx] != vsi) {
343*4882a593Smuzhiyun dev_dbg(dev, "vsi does not exist at pf->vsi[%d]\n", vsi->idx);
344*4882a593Smuzhiyun return -EINVAL;
345*4882a593Smuzhiyun }
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun mutex_lock(&pf->sw_mutex);
348*4882a593Smuzhiyun /* updates the PF for this cleared VSI */
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun pf->vsi[vsi->idx] = NULL;
351*4882a593Smuzhiyun if (vsi->idx < pf->next_vsi && vsi->type != ICE_VSI_CTRL)
352*4882a593Smuzhiyun pf->next_vsi = vsi->idx;
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun ice_vsi_free_arrays(vsi);
355*4882a593Smuzhiyun mutex_unlock(&pf->sw_mutex);
356*4882a593Smuzhiyun devm_kfree(dev, vsi);
357*4882a593Smuzhiyun
358*4882a593Smuzhiyun return 0;
359*4882a593Smuzhiyun }
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun /**
362*4882a593Smuzhiyun * ice_msix_clean_ctrl_vsi - MSIX mode interrupt handler for ctrl VSI
363*4882a593Smuzhiyun * @irq: interrupt number
364*4882a593Smuzhiyun * @data: pointer to a q_vector
365*4882a593Smuzhiyun */
ice_msix_clean_ctrl_vsi(int __always_unused irq,void * data)366*4882a593Smuzhiyun static irqreturn_t ice_msix_clean_ctrl_vsi(int __always_unused irq, void *data)
367*4882a593Smuzhiyun {
368*4882a593Smuzhiyun struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun if (!q_vector->tx.ring)
371*4882a593Smuzhiyun return IRQ_HANDLED;
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun #define FDIR_RX_DESC_CLEAN_BUDGET 64
374*4882a593Smuzhiyun ice_clean_rx_irq(q_vector->rx.ring, FDIR_RX_DESC_CLEAN_BUDGET);
375*4882a593Smuzhiyun ice_clean_ctrl_tx_irq(q_vector->tx.ring);
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun return IRQ_HANDLED;
378*4882a593Smuzhiyun }
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun /**
381*4882a593Smuzhiyun * ice_msix_clean_rings - MSIX mode Interrupt Handler
382*4882a593Smuzhiyun * @irq: interrupt number
383*4882a593Smuzhiyun * @data: pointer to a q_vector
384*4882a593Smuzhiyun */
ice_msix_clean_rings(int __always_unused irq,void * data)385*4882a593Smuzhiyun static irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data)
386*4882a593Smuzhiyun {
387*4882a593Smuzhiyun struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun if (!q_vector->tx.ring && !q_vector->rx.ring)
390*4882a593Smuzhiyun return IRQ_HANDLED;
391*4882a593Smuzhiyun
392*4882a593Smuzhiyun napi_schedule(&q_vector->napi);
393*4882a593Smuzhiyun
394*4882a593Smuzhiyun return IRQ_HANDLED;
395*4882a593Smuzhiyun }
396*4882a593Smuzhiyun
397*4882a593Smuzhiyun /**
398*4882a593Smuzhiyun * ice_vsi_alloc - Allocates the next available struct VSI in the PF
399*4882a593Smuzhiyun * @pf: board private structure
400*4882a593Smuzhiyun * @vsi_type: type of VSI
401*4882a593Smuzhiyun * @vf_id: ID of the VF being configured
402*4882a593Smuzhiyun *
403*4882a593Smuzhiyun * returns a pointer to a VSI on success, NULL on failure.
404*4882a593Smuzhiyun */
405*4882a593Smuzhiyun static struct ice_vsi *
ice_vsi_alloc(struct ice_pf * pf,enum ice_vsi_type vsi_type,u16 vf_id)406*4882a593Smuzhiyun ice_vsi_alloc(struct ice_pf *pf, enum ice_vsi_type vsi_type, u16 vf_id)
407*4882a593Smuzhiyun {
408*4882a593Smuzhiyun struct device *dev = ice_pf_to_dev(pf);
409*4882a593Smuzhiyun struct ice_vsi *vsi = NULL;
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun /* Need to protect the allocation of the VSIs at the PF level */
412*4882a593Smuzhiyun mutex_lock(&pf->sw_mutex);
413*4882a593Smuzhiyun
414*4882a593Smuzhiyun /* If we have already allocated our maximum number of VSIs,
415*4882a593Smuzhiyun * pf->next_vsi will be ICE_NO_VSI. If not, pf->next_vsi index
416*4882a593Smuzhiyun * is available to be populated
417*4882a593Smuzhiyun */
418*4882a593Smuzhiyun if (pf->next_vsi == ICE_NO_VSI) {
419*4882a593Smuzhiyun dev_dbg(dev, "out of VSI slots!\n");
420*4882a593Smuzhiyun goto unlock_pf;
421*4882a593Smuzhiyun }
422*4882a593Smuzhiyun
423*4882a593Smuzhiyun vsi = devm_kzalloc(dev, sizeof(*vsi), GFP_KERNEL);
424*4882a593Smuzhiyun if (!vsi)
425*4882a593Smuzhiyun goto unlock_pf;
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun vsi->type = vsi_type;
428*4882a593Smuzhiyun vsi->back = pf;
429*4882a593Smuzhiyun set_bit(__ICE_DOWN, vsi->state);
430*4882a593Smuzhiyun
431*4882a593Smuzhiyun if (vsi_type == ICE_VSI_VF)
432*4882a593Smuzhiyun ice_vsi_set_num_qs(vsi, vf_id);
433*4882a593Smuzhiyun else
434*4882a593Smuzhiyun ice_vsi_set_num_qs(vsi, ICE_INVAL_VFID);
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun switch (vsi->type) {
437*4882a593Smuzhiyun case ICE_VSI_PF:
438*4882a593Smuzhiyun if (ice_vsi_alloc_arrays(vsi))
439*4882a593Smuzhiyun goto err_rings;
440*4882a593Smuzhiyun
441*4882a593Smuzhiyun /* Setup default MSIX irq handler for VSI */
442*4882a593Smuzhiyun vsi->irq_handler = ice_msix_clean_rings;
443*4882a593Smuzhiyun break;
444*4882a593Smuzhiyun case ICE_VSI_CTRL:
445*4882a593Smuzhiyun if (ice_vsi_alloc_arrays(vsi))
446*4882a593Smuzhiyun goto err_rings;
447*4882a593Smuzhiyun
448*4882a593Smuzhiyun /* Setup ctrl VSI MSIX irq handler */
449*4882a593Smuzhiyun vsi->irq_handler = ice_msix_clean_ctrl_vsi;
450*4882a593Smuzhiyun break;
451*4882a593Smuzhiyun case ICE_VSI_VF:
452*4882a593Smuzhiyun if (ice_vsi_alloc_arrays(vsi))
453*4882a593Smuzhiyun goto err_rings;
454*4882a593Smuzhiyun break;
455*4882a593Smuzhiyun case ICE_VSI_LB:
456*4882a593Smuzhiyun if (ice_vsi_alloc_arrays(vsi))
457*4882a593Smuzhiyun goto err_rings;
458*4882a593Smuzhiyun break;
459*4882a593Smuzhiyun default:
460*4882a593Smuzhiyun dev_warn(dev, "Unknown VSI type %d\n", vsi->type);
461*4882a593Smuzhiyun goto unlock_pf;
462*4882a593Smuzhiyun }
463*4882a593Smuzhiyun
464*4882a593Smuzhiyun if (vsi->type == ICE_VSI_CTRL) {
465*4882a593Smuzhiyun /* Use the last VSI slot as the index for the control VSI */
466*4882a593Smuzhiyun vsi->idx = pf->num_alloc_vsi - 1;
467*4882a593Smuzhiyun pf->ctrl_vsi_idx = vsi->idx;
468*4882a593Smuzhiyun pf->vsi[vsi->idx] = vsi;
469*4882a593Smuzhiyun } else {
470*4882a593Smuzhiyun /* fill slot and make note of the index */
471*4882a593Smuzhiyun vsi->idx = pf->next_vsi;
472*4882a593Smuzhiyun pf->vsi[pf->next_vsi] = vsi;
473*4882a593Smuzhiyun
474*4882a593Smuzhiyun /* prepare pf->next_vsi for next use */
475*4882a593Smuzhiyun pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi,
476*4882a593Smuzhiyun pf->next_vsi);
477*4882a593Smuzhiyun }
478*4882a593Smuzhiyun goto unlock_pf;
479*4882a593Smuzhiyun
480*4882a593Smuzhiyun err_rings:
481*4882a593Smuzhiyun devm_kfree(dev, vsi);
482*4882a593Smuzhiyun vsi = NULL;
483*4882a593Smuzhiyun unlock_pf:
484*4882a593Smuzhiyun mutex_unlock(&pf->sw_mutex);
485*4882a593Smuzhiyun return vsi;
486*4882a593Smuzhiyun }
487*4882a593Smuzhiyun
488*4882a593Smuzhiyun /**
489*4882a593Smuzhiyun * ice_alloc_fd_res - Allocate FD resource for a VSI
490*4882a593Smuzhiyun * @vsi: pointer to the ice_vsi
491*4882a593Smuzhiyun *
492*4882a593Smuzhiyun * This allocates the FD resources
493*4882a593Smuzhiyun *
494*4882a593Smuzhiyun * Returns 0 on success, -EPERM on no-op or -EIO on failure
495*4882a593Smuzhiyun */
ice_alloc_fd_res(struct ice_vsi * vsi)496*4882a593Smuzhiyun static int ice_alloc_fd_res(struct ice_vsi *vsi)
497*4882a593Smuzhiyun {
498*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
499*4882a593Smuzhiyun u32 g_val, b_val;
500*4882a593Smuzhiyun
501*4882a593Smuzhiyun /* Flow Director filters are only allocated/assigned to the PF VSI which
502*4882a593Smuzhiyun * passes the traffic. The CTRL VSI is only used to add/delete filters
503*4882a593Smuzhiyun * so we don't allocate resources to it
504*4882a593Smuzhiyun */
505*4882a593Smuzhiyun
506*4882a593Smuzhiyun /* FD filters from guaranteed pool per VSI */
507*4882a593Smuzhiyun g_val = pf->hw.func_caps.fd_fltr_guar;
508*4882a593Smuzhiyun if (!g_val)
509*4882a593Smuzhiyun return -EPERM;
510*4882a593Smuzhiyun
511*4882a593Smuzhiyun /* FD filters from best effort pool */
512*4882a593Smuzhiyun b_val = pf->hw.func_caps.fd_fltr_best_effort;
513*4882a593Smuzhiyun if (!b_val)
514*4882a593Smuzhiyun return -EPERM;
515*4882a593Smuzhiyun
516*4882a593Smuzhiyun if (vsi->type != ICE_VSI_PF)
517*4882a593Smuzhiyun return -EPERM;
518*4882a593Smuzhiyun
519*4882a593Smuzhiyun if (!test_bit(ICE_FLAG_FD_ENA, pf->flags))
520*4882a593Smuzhiyun return -EPERM;
521*4882a593Smuzhiyun
522*4882a593Smuzhiyun vsi->num_gfltr = g_val / pf->num_alloc_vsi;
523*4882a593Smuzhiyun
524*4882a593Smuzhiyun /* each VSI gets same "best_effort" quota */
525*4882a593Smuzhiyun vsi->num_bfltr = b_val;
526*4882a593Smuzhiyun
527*4882a593Smuzhiyun return 0;
528*4882a593Smuzhiyun }
529*4882a593Smuzhiyun
530*4882a593Smuzhiyun /**
531*4882a593Smuzhiyun * ice_vsi_get_qs - Assign queues from PF to VSI
532*4882a593Smuzhiyun * @vsi: the VSI to assign queues to
533*4882a593Smuzhiyun *
534*4882a593Smuzhiyun * Returns 0 on success and a negative value on error
535*4882a593Smuzhiyun */
ice_vsi_get_qs(struct ice_vsi * vsi)536*4882a593Smuzhiyun static int ice_vsi_get_qs(struct ice_vsi *vsi)
537*4882a593Smuzhiyun {
538*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
539*4882a593Smuzhiyun struct ice_qs_cfg tx_qs_cfg = {
540*4882a593Smuzhiyun .qs_mutex = &pf->avail_q_mutex,
541*4882a593Smuzhiyun .pf_map = pf->avail_txqs,
542*4882a593Smuzhiyun .pf_map_size = pf->max_pf_txqs,
543*4882a593Smuzhiyun .q_count = vsi->alloc_txq,
544*4882a593Smuzhiyun .scatter_count = ICE_MAX_SCATTER_TXQS,
545*4882a593Smuzhiyun .vsi_map = vsi->txq_map,
546*4882a593Smuzhiyun .vsi_map_offset = 0,
547*4882a593Smuzhiyun .mapping_mode = ICE_VSI_MAP_CONTIG
548*4882a593Smuzhiyun };
549*4882a593Smuzhiyun struct ice_qs_cfg rx_qs_cfg = {
550*4882a593Smuzhiyun .qs_mutex = &pf->avail_q_mutex,
551*4882a593Smuzhiyun .pf_map = pf->avail_rxqs,
552*4882a593Smuzhiyun .pf_map_size = pf->max_pf_rxqs,
553*4882a593Smuzhiyun .q_count = vsi->alloc_rxq,
554*4882a593Smuzhiyun .scatter_count = ICE_MAX_SCATTER_RXQS,
555*4882a593Smuzhiyun .vsi_map = vsi->rxq_map,
556*4882a593Smuzhiyun .vsi_map_offset = 0,
557*4882a593Smuzhiyun .mapping_mode = ICE_VSI_MAP_CONTIG
558*4882a593Smuzhiyun };
559*4882a593Smuzhiyun int ret;
560*4882a593Smuzhiyun
561*4882a593Smuzhiyun ret = __ice_vsi_get_qs(&tx_qs_cfg);
562*4882a593Smuzhiyun if (ret)
563*4882a593Smuzhiyun return ret;
564*4882a593Smuzhiyun vsi->tx_mapping_mode = tx_qs_cfg.mapping_mode;
565*4882a593Smuzhiyun
566*4882a593Smuzhiyun ret = __ice_vsi_get_qs(&rx_qs_cfg);
567*4882a593Smuzhiyun if (ret)
568*4882a593Smuzhiyun return ret;
569*4882a593Smuzhiyun vsi->rx_mapping_mode = rx_qs_cfg.mapping_mode;
570*4882a593Smuzhiyun
571*4882a593Smuzhiyun return 0;
572*4882a593Smuzhiyun }
573*4882a593Smuzhiyun
574*4882a593Smuzhiyun /**
575*4882a593Smuzhiyun * ice_vsi_put_qs - Release queues from VSI to PF
576*4882a593Smuzhiyun * @vsi: the VSI that is going to release queues
577*4882a593Smuzhiyun */
ice_vsi_put_qs(struct ice_vsi * vsi)578*4882a593Smuzhiyun static void ice_vsi_put_qs(struct ice_vsi *vsi)
579*4882a593Smuzhiyun {
580*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
581*4882a593Smuzhiyun int i;
582*4882a593Smuzhiyun
583*4882a593Smuzhiyun mutex_lock(&pf->avail_q_mutex);
584*4882a593Smuzhiyun
585*4882a593Smuzhiyun for (i = 0; i < vsi->alloc_txq; i++) {
586*4882a593Smuzhiyun clear_bit(vsi->txq_map[i], pf->avail_txqs);
587*4882a593Smuzhiyun vsi->txq_map[i] = ICE_INVAL_Q_INDEX;
588*4882a593Smuzhiyun }
589*4882a593Smuzhiyun
590*4882a593Smuzhiyun for (i = 0; i < vsi->alloc_rxq; i++) {
591*4882a593Smuzhiyun clear_bit(vsi->rxq_map[i], pf->avail_rxqs);
592*4882a593Smuzhiyun vsi->rxq_map[i] = ICE_INVAL_Q_INDEX;
593*4882a593Smuzhiyun }
594*4882a593Smuzhiyun
595*4882a593Smuzhiyun mutex_unlock(&pf->avail_q_mutex);
596*4882a593Smuzhiyun }
597*4882a593Smuzhiyun
598*4882a593Smuzhiyun /**
599*4882a593Smuzhiyun * ice_is_safe_mode
600*4882a593Smuzhiyun * @pf: pointer to the PF struct
601*4882a593Smuzhiyun *
602*4882a593Smuzhiyun * returns true if driver is in safe mode, false otherwise
603*4882a593Smuzhiyun */
ice_is_safe_mode(struct ice_pf * pf)604*4882a593Smuzhiyun bool ice_is_safe_mode(struct ice_pf *pf)
605*4882a593Smuzhiyun {
606*4882a593Smuzhiyun return !test_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
607*4882a593Smuzhiyun }
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun /**
610*4882a593Smuzhiyun * ice_vsi_clean_rss_flow_fld - Delete RSS configuration
611*4882a593Smuzhiyun * @vsi: the VSI being cleaned up
612*4882a593Smuzhiyun *
613*4882a593Smuzhiyun * This function deletes RSS input set for all flows that were configured
614*4882a593Smuzhiyun * for this VSI
615*4882a593Smuzhiyun */
ice_vsi_clean_rss_flow_fld(struct ice_vsi * vsi)616*4882a593Smuzhiyun static void ice_vsi_clean_rss_flow_fld(struct ice_vsi *vsi)
617*4882a593Smuzhiyun {
618*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
619*4882a593Smuzhiyun enum ice_status status;
620*4882a593Smuzhiyun
621*4882a593Smuzhiyun if (ice_is_safe_mode(pf))
622*4882a593Smuzhiyun return;
623*4882a593Smuzhiyun
624*4882a593Smuzhiyun status = ice_rem_vsi_rss_cfg(&pf->hw, vsi->idx);
625*4882a593Smuzhiyun if (status)
626*4882a593Smuzhiyun dev_dbg(ice_pf_to_dev(pf), "ice_rem_vsi_rss_cfg failed for vsi = %d, error = %s\n",
627*4882a593Smuzhiyun vsi->vsi_num, ice_stat_str(status));
628*4882a593Smuzhiyun }
629*4882a593Smuzhiyun
630*4882a593Smuzhiyun /**
631*4882a593Smuzhiyun * ice_rss_clean - Delete RSS related VSI structures and configuration
632*4882a593Smuzhiyun * @vsi: the VSI being removed
633*4882a593Smuzhiyun */
ice_rss_clean(struct ice_vsi * vsi)634*4882a593Smuzhiyun static void ice_rss_clean(struct ice_vsi *vsi)
635*4882a593Smuzhiyun {
636*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
637*4882a593Smuzhiyun struct device *dev;
638*4882a593Smuzhiyun
639*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
640*4882a593Smuzhiyun
641*4882a593Smuzhiyun if (vsi->rss_hkey_user)
642*4882a593Smuzhiyun devm_kfree(dev, vsi->rss_hkey_user);
643*4882a593Smuzhiyun if (vsi->rss_lut_user)
644*4882a593Smuzhiyun devm_kfree(dev, vsi->rss_lut_user);
645*4882a593Smuzhiyun
646*4882a593Smuzhiyun ice_vsi_clean_rss_flow_fld(vsi);
647*4882a593Smuzhiyun /* remove RSS replay list */
648*4882a593Smuzhiyun if (!ice_is_safe_mode(pf))
649*4882a593Smuzhiyun ice_rem_vsi_rss_list(&pf->hw, vsi->idx);
650*4882a593Smuzhiyun }
651*4882a593Smuzhiyun
652*4882a593Smuzhiyun /**
653*4882a593Smuzhiyun * ice_vsi_set_rss_params - Setup RSS capabilities per VSI type
654*4882a593Smuzhiyun * @vsi: the VSI being configured
655*4882a593Smuzhiyun */
ice_vsi_set_rss_params(struct ice_vsi * vsi)656*4882a593Smuzhiyun static void ice_vsi_set_rss_params(struct ice_vsi *vsi)
657*4882a593Smuzhiyun {
658*4882a593Smuzhiyun struct ice_hw_common_caps *cap;
659*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
660*4882a593Smuzhiyun
661*4882a593Smuzhiyun if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
662*4882a593Smuzhiyun vsi->rss_size = 1;
663*4882a593Smuzhiyun return;
664*4882a593Smuzhiyun }
665*4882a593Smuzhiyun
666*4882a593Smuzhiyun cap = &pf->hw.func_caps.common_cap;
667*4882a593Smuzhiyun switch (vsi->type) {
668*4882a593Smuzhiyun case ICE_VSI_PF:
669*4882a593Smuzhiyun /* PF VSI will inherit RSS instance of PF */
670*4882a593Smuzhiyun vsi->rss_table_size = (u16)cap->rss_table_size;
671*4882a593Smuzhiyun vsi->rss_size = min_t(u16, num_online_cpus(),
672*4882a593Smuzhiyun BIT(cap->rss_table_entry_width));
673*4882a593Smuzhiyun vsi->rss_lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
674*4882a593Smuzhiyun break;
675*4882a593Smuzhiyun case ICE_VSI_VF:
676*4882a593Smuzhiyun /* VF VSI will get a small RSS table.
677*4882a593Smuzhiyun * For VSI_LUT, LUT size should be set to 64 bytes.
678*4882a593Smuzhiyun */
679*4882a593Smuzhiyun vsi->rss_table_size = ICE_VSIQF_HLUT_ARRAY_SIZE;
680*4882a593Smuzhiyun vsi->rss_size = ICE_MAX_RSS_QS_PER_VF;
681*4882a593Smuzhiyun vsi->rss_lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_VSI;
682*4882a593Smuzhiyun break;
683*4882a593Smuzhiyun case ICE_VSI_LB:
684*4882a593Smuzhiyun break;
685*4882a593Smuzhiyun default:
686*4882a593Smuzhiyun dev_dbg(ice_pf_to_dev(pf), "Unsupported VSI type %s\n",
687*4882a593Smuzhiyun ice_vsi_type_str(vsi->type));
688*4882a593Smuzhiyun break;
689*4882a593Smuzhiyun }
690*4882a593Smuzhiyun }
691*4882a593Smuzhiyun
692*4882a593Smuzhiyun /**
693*4882a593Smuzhiyun * ice_set_dflt_vsi_ctx - Set default VSI context before adding a VSI
694*4882a593Smuzhiyun * @ctxt: the VSI context being set
695*4882a593Smuzhiyun *
696*4882a593Smuzhiyun * This initializes a default VSI context for all sections except the Queues.
697*4882a593Smuzhiyun */
ice_set_dflt_vsi_ctx(struct ice_vsi_ctx * ctxt)698*4882a593Smuzhiyun static void ice_set_dflt_vsi_ctx(struct ice_vsi_ctx *ctxt)
699*4882a593Smuzhiyun {
700*4882a593Smuzhiyun u32 table = 0;
701*4882a593Smuzhiyun
702*4882a593Smuzhiyun memset(&ctxt->info, 0, sizeof(ctxt->info));
703*4882a593Smuzhiyun /* VSI's should be allocated from shared pool */
704*4882a593Smuzhiyun ctxt->alloc_from_pool = true;
705*4882a593Smuzhiyun /* Src pruning enabled by default */
706*4882a593Smuzhiyun ctxt->info.sw_flags = ICE_AQ_VSI_SW_FLAG_SRC_PRUNE;
707*4882a593Smuzhiyun /* Traffic from VSI can be sent to LAN */
708*4882a593Smuzhiyun ctxt->info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
709*4882a593Smuzhiyun /* By default bits 3 and 4 in vlan_flags are 0's which results in legacy
710*4882a593Smuzhiyun * behavior (show VLAN, DEI, and UP) in descriptor. Also, allow all
711*4882a593Smuzhiyun * packets untagged/tagged.
712*4882a593Smuzhiyun */
713*4882a593Smuzhiyun ctxt->info.vlan_flags = ((ICE_AQ_VSI_VLAN_MODE_ALL &
714*4882a593Smuzhiyun ICE_AQ_VSI_VLAN_MODE_M) >>
715*4882a593Smuzhiyun ICE_AQ_VSI_VLAN_MODE_S);
716*4882a593Smuzhiyun /* Have 1:1 UP mapping for both ingress/egress tables */
717*4882a593Smuzhiyun table |= ICE_UP_TABLE_TRANSLATE(0, 0);
718*4882a593Smuzhiyun table |= ICE_UP_TABLE_TRANSLATE(1, 1);
719*4882a593Smuzhiyun table |= ICE_UP_TABLE_TRANSLATE(2, 2);
720*4882a593Smuzhiyun table |= ICE_UP_TABLE_TRANSLATE(3, 3);
721*4882a593Smuzhiyun table |= ICE_UP_TABLE_TRANSLATE(4, 4);
722*4882a593Smuzhiyun table |= ICE_UP_TABLE_TRANSLATE(5, 5);
723*4882a593Smuzhiyun table |= ICE_UP_TABLE_TRANSLATE(6, 6);
724*4882a593Smuzhiyun table |= ICE_UP_TABLE_TRANSLATE(7, 7);
725*4882a593Smuzhiyun ctxt->info.ingress_table = cpu_to_le32(table);
726*4882a593Smuzhiyun ctxt->info.egress_table = cpu_to_le32(table);
727*4882a593Smuzhiyun /* Have 1:1 UP mapping for outer to inner UP table */
728*4882a593Smuzhiyun ctxt->info.outer_up_table = cpu_to_le32(table);
729*4882a593Smuzhiyun /* No Outer tag support outer_tag_flags remains to zero */
730*4882a593Smuzhiyun }
731*4882a593Smuzhiyun
732*4882a593Smuzhiyun /**
733*4882a593Smuzhiyun * ice_vsi_setup_q_map - Setup a VSI queue map
734*4882a593Smuzhiyun * @vsi: the VSI being configured
735*4882a593Smuzhiyun * @ctxt: VSI context structure
736*4882a593Smuzhiyun */
ice_vsi_setup_q_map(struct ice_vsi * vsi,struct ice_vsi_ctx * ctxt)737*4882a593Smuzhiyun static void ice_vsi_setup_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctxt)
738*4882a593Smuzhiyun {
739*4882a593Smuzhiyun u16 offset = 0, qmap = 0, tx_count = 0;
740*4882a593Smuzhiyun u16 qcount_tx = vsi->alloc_txq;
741*4882a593Smuzhiyun u16 qcount_rx = vsi->alloc_rxq;
742*4882a593Smuzhiyun u16 tx_numq_tc, rx_numq_tc;
743*4882a593Smuzhiyun u16 pow = 0, max_rss = 0;
744*4882a593Smuzhiyun bool ena_tc0 = false;
745*4882a593Smuzhiyun u8 netdev_tc = 0;
746*4882a593Smuzhiyun int i;
747*4882a593Smuzhiyun
748*4882a593Smuzhiyun /* at least TC0 should be enabled by default */
749*4882a593Smuzhiyun if (vsi->tc_cfg.numtc) {
750*4882a593Smuzhiyun if (!(vsi->tc_cfg.ena_tc & BIT(0)))
751*4882a593Smuzhiyun ena_tc0 = true;
752*4882a593Smuzhiyun } else {
753*4882a593Smuzhiyun ena_tc0 = true;
754*4882a593Smuzhiyun }
755*4882a593Smuzhiyun
756*4882a593Smuzhiyun if (ena_tc0) {
757*4882a593Smuzhiyun vsi->tc_cfg.numtc++;
758*4882a593Smuzhiyun vsi->tc_cfg.ena_tc |= 1;
759*4882a593Smuzhiyun }
760*4882a593Smuzhiyun
761*4882a593Smuzhiyun rx_numq_tc = qcount_rx / vsi->tc_cfg.numtc;
762*4882a593Smuzhiyun if (!rx_numq_tc)
763*4882a593Smuzhiyun rx_numq_tc = 1;
764*4882a593Smuzhiyun tx_numq_tc = qcount_tx / vsi->tc_cfg.numtc;
765*4882a593Smuzhiyun if (!tx_numq_tc)
766*4882a593Smuzhiyun tx_numq_tc = 1;
767*4882a593Smuzhiyun
768*4882a593Smuzhiyun /* TC mapping is a function of the number of Rx queues assigned to the
769*4882a593Smuzhiyun * VSI for each traffic class and the offset of these queues.
770*4882a593Smuzhiyun * The first 10 bits are for queue offset for TC0, next 4 bits for no:of
771*4882a593Smuzhiyun * queues allocated to TC0. No:of queues is a power-of-2.
772*4882a593Smuzhiyun *
773*4882a593Smuzhiyun * If TC is not enabled, the queue offset is set to 0, and allocate one
774*4882a593Smuzhiyun * queue, this way, traffic for the given TC will be sent to the default
775*4882a593Smuzhiyun * queue.
776*4882a593Smuzhiyun *
777*4882a593Smuzhiyun * Setup number and offset of Rx queues for all TCs for the VSI
778*4882a593Smuzhiyun */
779*4882a593Smuzhiyun
780*4882a593Smuzhiyun qcount_rx = rx_numq_tc;
781*4882a593Smuzhiyun
782*4882a593Smuzhiyun /* qcount will change if RSS is enabled */
783*4882a593Smuzhiyun if (test_bit(ICE_FLAG_RSS_ENA, vsi->back->flags)) {
784*4882a593Smuzhiyun if (vsi->type == ICE_VSI_PF || vsi->type == ICE_VSI_VF) {
785*4882a593Smuzhiyun if (vsi->type == ICE_VSI_PF)
786*4882a593Smuzhiyun max_rss = ICE_MAX_LG_RSS_QS;
787*4882a593Smuzhiyun else
788*4882a593Smuzhiyun max_rss = ICE_MAX_RSS_QS_PER_VF;
789*4882a593Smuzhiyun qcount_rx = min_t(u16, rx_numq_tc, max_rss);
790*4882a593Smuzhiyun if (!vsi->req_rxq)
791*4882a593Smuzhiyun qcount_rx = min_t(u16, qcount_rx,
792*4882a593Smuzhiyun vsi->rss_size);
793*4882a593Smuzhiyun }
794*4882a593Smuzhiyun }
795*4882a593Smuzhiyun
796*4882a593Smuzhiyun /* find the (rounded up) power-of-2 of qcount */
797*4882a593Smuzhiyun pow = (u16)order_base_2(qcount_rx);
798*4882a593Smuzhiyun
799*4882a593Smuzhiyun ice_for_each_traffic_class(i) {
800*4882a593Smuzhiyun if (!(vsi->tc_cfg.ena_tc & BIT(i))) {
801*4882a593Smuzhiyun /* TC is not enabled */
802*4882a593Smuzhiyun vsi->tc_cfg.tc_info[i].qoffset = 0;
803*4882a593Smuzhiyun vsi->tc_cfg.tc_info[i].qcount_rx = 1;
804*4882a593Smuzhiyun vsi->tc_cfg.tc_info[i].qcount_tx = 1;
805*4882a593Smuzhiyun vsi->tc_cfg.tc_info[i].netdev_tc = 0;
806*4882a593Smuzhiyun ctxt->info.tc_mapping[i] = 0;
807*4882a593Smuzhiyun continue;
808*4882a593Smuzhiyun }
809*4882a593Smuzhiyun
810*4882a593Smuzhiyun /* TC is enabled */
811*4882a593Smuzhiyun vsi->tc_cfg.tc_info[i].qoffset = offset;
812*4882a593Smuzhiyun vsi->tc_cfg.tc_info[i].qcount_rx = qcount_rx;
813*4882a593Smuzhiyun vsi->tc_cfg.tc_info[i].qcount_tx = tx_numq_tc;
814*4882a593Smuzhiyun vsi->tc_cfg.tc_info[i].netdev_tc = netdev_tc++;
815*4882a593Smuzhiyun
816*4882a593Smuzhiyun qmap = ((offset << ICE_AQ_VSI_TC_Q_OFFSET_S) &
817*4882a593Smuzhiyun ICE_AQ_VSI_TC_Q_OFFSET_M) |
818*4882a593Smuzhiyun ((pow << ICE_AQ_VSI_TC_Q_NUM_S) &
819*4882a593Smuzhiyun ICE_AQ_VSI_TC_Q_NUM_M);
820*4882a593Smuzhiyun offset += qcount_rx;
821*4882a593Smuzhiyun tx_count += tx_numq_tc;
822*4882a593Smuzhiyun ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
823*4882a593Smuzhiyun }
824*4882a593Smuzhiyun
825*4882a593Smuzhiyun /* if offset is non-zero, means it is calculated correctly based on
826*4882a593Smuzhiyun * enabled TCs for a given VSI otherwise qcount_rx will always
827*4882a593Smuzhiyun * be correct and non-zero because it is based off - VSI's
828*4882a593Smuzhiyun * allocated Rx queues which is at least 1 (hence qcount_tx will be
829*4882a593Smuzhiyun * at least 1)
830*4882a593Smuzhiyun */
831*4882a593Smuzhiyun if (offset)
832*4882a593Smuzhiyun vsi->num_rxq = offset;
833*4882a593Smuzhiyun else
834*4882a593Smuzhiyun vsi->num_rxq = qcount_rx;
835*4882a593Smuzhiyun
836*4882a593Smuzhiyun vsi->num_txq = tx_count;
837*4882a593Smuzhiyun
838*4882a593Smuzhiyun if (vsi->type == ICE_VSI_VF && vsi->num_txq != vsi->num_rxq) {
839*4882a593Smuzhiyun dev_dbg(ice_pf_to_dev(vsi->back), "VF VSI should have same number of Tx and Rx queues. Hence making them equal\n");
840*4882a593Smuzhiyun /* since there is a chance that num_rxq could have been changed
841*4882a593Smuzhiyun * in the above for loop, make num_txq equal to num_rxq.
842*4882a593Smuzhiyun */
843*4882a593Smuzhiyun vsi->num_txq = vsi->num_rxq;
844*4882a593Smuzhiyun }
845*4882a593Smuzhiyun
846*4882a593Smuzhiyun /* Rx queue mapping */
847*4882a593Smuzhiyun ctxt->info.mapping_flags |= cpu_to_le16(ICE_AQ_VSI_Q_MAP_CONTIG);
848*4882a593Smuzhiyun /* q_mapping buffer holds the info for the first queue allocated for
849*4882a593Smuzhiyun * this VSI in the PF space and also the number of queues associated
850*4882a593Smuzhiyun * with this VSI.
851*4882a593Smuzhiyun */
852*4882a593Smuzhiyun ctxt->info.q_mapping[0] = cpu_to_le16(vsi->rxq_map[0]);
853*4882a593Smuzhiyun ctxt->info.q_mapping[1] = cpu_to_le16(vsi->num_rxq);
854*4882a593Smuzhiyun }
855*4882a593Smuzhiyun
856*4882a593Smuzhiyun /**
857*4882a593Smuzhiyun * ice_set_fd_vsi_ctx - Set FD VSI context before adding a VSI
858*4882a593Smuzhiyun * @ctxt: the VSI context being set
859*4882a593Smuzhiyun * @vsi: the VSI being configured
860*4882a593Smuzhiyun */
ice_set_fd_vsi_ctx(struct ice_vsi_ctx * ctxt,struct ice_vsi * vsi)861*4882a593Smuzhiyun static void ice_set_fd_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
862*4882a593Smuzhiyun {
863*4882a593Smuzhiyun u8 dflt_q_group, dflt_q_prio;
864*4882a593Smuzhiyun u16 dflt_q, report_q, val;
865*4882a593Smuzhiyun
866*4882a593Smuzhiyun if (vsi->type != ICE_VSI_PF && vsi->type != ICE_VSI_CTRL)
867*4882a593Smuzhiyun return;
868*4882a593Smuzhiyun
869*4882a593Smuzhiyun val = ICE_AQ_VSI_PROP_FLOW_DIR_VALID;
870*4882a593Smuzhiyun ctxt->info.valid_sections |= cpu_to_le16(val);
871*4882a593Smuzhiyun dflt_q = 0;
872*4882a593Smuzhiyun dflt_q_group = 0;
873*4882a593Smuzhiyun report_q = 0;
874*4882a593Smuzhiyun dflt_q_prio = 0;
875*4882a593Smuzhiyun
876*4882a593Smuzhiyun /* enable flow director filtering/programming */
877*4882a593Smuzhiyun val = ICE_AQ_VSI_FD_ENABLE | ICE_AQ_VSI_FD_PROG_ENABLE;
878*4882a593Smuzhiyun ctxt->info.fd_options = cpu_to_le16(val);
879*4882a593Smuzhiyun /* max of allocated flow director filters */
880*4882a593Smuzhiyun ctxt->info.max_fd_fltr_dedicated =
881*4882a593Smuzhiyun cpu_to_le16(vsi->num_gfltr);
882*4882a593Smuzhiyun /* max of shared flow director filters any VSI may program */
883*4882a593Smuzhiyun ctxt->info.max_fd_fltr_shared =
884*4882a593Smuzhiyun cpu_to_le16(vsi->num_bfltr);
885*4882a593Smuzhiyun /* default queue index within the VSI of the default FD */
886*4882a593Smuzhiyun val = ((dflt_q << ICE_AQ_VSI_FD_DEF_Q_S) &
887*4882a593Smuzhiyun ICE_AQ_VSI_FD_DEF_Q_M);
888*4882a593Smuzhiyun /* target queue or queue group to the FD filter */
889*4882a593Smuzhiyun val |= ((dflt_q_group << ICE_AQ_VSI_FD_DEF_GRP_S) &
890*4882a593Smuzhiyun ICE_AQ_VSI_FD_DEF_GRP_M);
891*4882a593Smuzhiyun ctxt->info.fd_def_q = cpu_to_le16(val);
892*4882a593Smuzhiyun /* queue index on which FD filter completion is reported */
893*4882a593Smuzhiyun val = ((report_q << ICE_AQ_VSI_FD_REPORT_Q_S) &
894*4882a593Smuzhiyun ICE_AQ_VSI_FD_REPORT_Q_M);
895*4882a593Smuzhiyun /* priority of the default qindex action */
896*4882a593Smuzhiyun val |= ((dflt_q_prio << ICE_AQ_VSI_FD_DEF_PRIORITY_S) &
897*4882a593Smuzhiyun ICE_AQ_VSI_FD_DEF_PRIORITY_M);
898*4882a593Smuzhiyun ctxt->info.fd_report_opt = cpu_to_le16(val);
899*4882a593Smuzhiyun }
900*4882a593Smuzhiyun
901*4882a593Smuzhiyun /**
902*4882a593Smuzhiyun * ice_set_rss_vsi_ctx - Set RSS VSI context before adding a VSI
903*4882a593Smuzhiyun * @ctxt: the VSI context being set
904*4882a593Smuzhiyun * @vsi: the VSI being configured
905*4882a593Smuzhiyun */
ice_set_rss_vsi_ctx(struct ice_vsi_ctx * ctxt,struct ice_vsi * vsi)906*4882a593Smuzhiyun static void ice_set_rss_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
907*4882a593Smuzhiyun {
908*4882a593Smuzhiyun u8 lut_type, hash_type;
909*4882a593Smuzhiyun struct device *dev;
910*4882a593Smuzhiyun struct ice_pf *pf;
911*4882a593Smuzhiyun
912*4882a593Smuzhiyun pf = vsi->back;
913*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
914*4882a593Smuzhiyun
915*4882a593Smuzhiyun switch (vsi->type) {
916*4882a593Smuzhiyun case ICE_VSI_PF:
917*4882a593Smuzhiyun /* PF VSI will inherit RSS instance of PF */
918*4882a593Smuzhiyun lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_PF;
919*4882a593Smuzhiyun hash_type = ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
920*4882a593Smuzhiyun break;
921*4882a593Smuzhiyun case ICE_VSI_VF:
922*4882a593Smuzhiyun /* VF VSI will gets a small RSS table which is a VSI LUT type */
923*4882a593Smuzhiyun lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI;
924*4882a593Smuzhiyun hash_type = ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
925*4882a593Smuzhiyun break;
926*4882a593Smuzhiyun default:
927*4882a593Smuzhiyun dev_dbg(dev, "Unsupported VSI type %s\n",
928*4882a593Smuzhiyun ice_vsi_type_str(vsi->type));
929*4882a593Smuzhiyun return;
930*4882a593Smuzhiyun }
931*4882a593Smuzhiyun
932*4882a593Smuzhiyun ctxt->info.q_opt_rss = ((lut_type << ICE_AQ_VSI_Q_OPT_RSS_LUT_S) &
933*4882a593Smuzhiyun ICE_AQ_VSI_Q_OPT_RSS_LUT_M) |
934*4882a593Smuzhiyun ((hash_type << ICE_AQ_VSI_Q_OPT_RSS_HASH_S) &
935*4882a593Smuzhiyun ICE_AQ_VSI_Q_OPT_RSS_HASH_M);
936*4882a593Smuzhiyun }
937*4882a593Smuzhiyun
938*4882a593Smuzhiyun /**
939*4882a593Smuzhiyun * ice_vsi_init - Create and initialize a VSI
940*4882a593Smuzhiyun * @vsi: the VSI being configured
941*4882a593Smuzhiyun * @init_vsi: is this call creating a VSI
942*4882a593Smuzhiyun *
943*4882a593Smuzhiyun * This initializes a VSI context depending on the VSI type to be added and
944*4882a593Smuzhiyun * passes it down to the add_vsi aq command to create a new VSI.
945*4882a593Smuzhiyun */
ice_vsi_init(struct ice_vsi * vsi,bool init_vsi)946*4882a593Smuzhiyun static int ice_vsi_init(struct ice_vsi *vsi, bool init_vsi)
947*4882a593Smuzhiyun {
948*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
949*4882a593Smuzhiyun struct ice_hw *hw = &pf->hw;
950*4882a593Smuzhiyun struct ice_vsi_ctx *ctxt;
951*4882a593Smuzhiyun struct device *dev;
952*4882a593Smuzhiyun int ret = 0;
953*4882a593Smuzhiyun
954*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
955*4882a593Smuzhiyun ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
956*4882a593Smuzhiyun if (!ctxt)
957*4882a593Smuzhiyun return -ENOMEM;
958*4882a593Smuzhiyun
959*4882a593Smuzhiyun switch (vsi->type) {
960*4882a593Smuzhiyun case ICE_VSI_CTRL:
961*4882a593Smuzhiyun case ICE_VSI_LB:
962*4882a593Smuzhiyun case ICE_VSI_PF:
963*4882a593Smuzhiyun ctxt->flags = ICE_AQ_VSI_TYPE_PF;
964*4882a593Smuzhiyun break;
965*4882a593Smuzhiyun case ICE_VSI_VF:
966*4882a593Smuzhiyun ctxt->flags = ICE_AQ_VSI_TYPE_VF;
967*4882a593Smuzhiyun /* VF number here is the absolute VF number (0-255) */
968*4882a593Smuzhiyun ctxt->vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
969*4882a593Smuzhiyun break;
970*4882a593Smuzhiyun default:
971*4882a593Smuzhiyun ret = -ENODEV;
972*4882a593Smuzhiyun goto out;
973*4882a593Smuzhiyun }
974*4882a593Smuzhiyun
975*4882a593Smuzhiyun ice_set_dflt_vsi_ctx(ctxt);
976*4882a593Smuzhiyun if (test_bit(ICE_FLAG_FD_ENA, pf->flags))
977*4882a593Smuzhiyun ice_set_fd_vsi_ctx(ctxt, vsi);
978*4882a593Smuzhiyun /* if the switch is in VEB mode, allow VSI loopback */
979*4882a593Smuzhiyun if (vsi->vsw->bridge_mode == BRIDGE_MODE_VEB)
980*4882a593Smuzhiyun ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
981*4882a593Smuzhiyun
982*4882a593Smuzhiyun /* Set LUT type and HASH type if RSS is enabled */
983*4882a593Smuzhiyun if (test_bit(ICE_FLAG_RSS_ENA, pf->flags) &&
984*4882a593Smuzhiyun vsi->type != ICE_VSI_CTRL) {
985*4882a593Smuzhiyun ice_set_rss_vsi_ctx(ctxt, vsi);
986*4882a593Smuzhiyun /* if updating VSI context, make sure to set valid_section:
987*4882a593Smuzhiyun * to indicate which section of VSI context being updated
988*4882a593Smuzhiyun */
989*4882a593Smuzhiyun if (!init_vsi)
990*4882a593Smuzhiyun ctxt->info.valid_sections |=
991*4882a593Smuzhiyun cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
992*4882a593Smuzhiyun }
993*4882a593Smuzhiyun
994*4882a593Smuzhiyun ctxt->info.sw_id = vsi->port_info->sw_id;
995*4882a593Smuzhiyun ice_vsi_setup_q_map(vsi, ctxt);
996*4882a593Smuzhiyun if (!init_vsi) /* means VSI being updated */
997*4882a593Smuzhiyun /* must to indicate which section of VSI context are
998*4882a593Smuzhiyun * being modified
999*4882a593Smuzhiyun */
1000*4882a593Smuzhiyun ctxt->info.valid_sections |=
1001*4882a593Smuzhiyun cpu_to_le16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
1002*4882a593Smuzhiyun
1003*4882a593Smuzhiyun /* enable/disable MAC and VLAN anti-spoof when spoofchk is on/off
1004*4882a593Smuzhiyun * respectively
1005*4882a593Smuzhiyun */
1006*4882a593Smuzhiyun if (vsi->type == ICE_VSI_VF) {
1007*4882a593Smuzhiyun ctxt->info.valid_sections |=
1008*4882a593Smuzhiyun cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID);
1009*4882a593Smuzhiyun if (pf->vf[vsi->vf_id].spoofchk) {
1010*4882a593Smuzhiyun ctxt->info.sec_flags |=
1011*4882a593Smuzhiyun ICE_AQ_VSI_SEC_FLAG_ENA_MAC_ANTI_SPOOF |
1012*4882a593Smuzhiyun (ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
1013*4882a593Smuzhiyun ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S);
1014*4882a593Smuzhiyun } else {
1015*4882a593Smuzhiyun ctxt->info.sec_flags &=
1016*4882a593Smuzhiyun ~(ICE_AQ_VSI_SEC_FLAG_ENA_MAC_ANTI_SPOOF |
1017*4882a593Smuzhiyun (ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
1018*4882a593Smuzhiyun ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S));
1019*4882a593Smuzhiyun }
1020*4882a593Smuzhiyun }
1021*4882a593Smuzhiyun
1022*4882a593Smuzhiyun /* Allow control frames out of main VSI */
1023*4882a593Smuzhiyun if (vsi->type == ICE_VSI_PF) {
1024*4882a593Smuzhiyun ctxt->info.sec_flags |= ICE_AQ_VSI_SEC_FLAG_ALLOW_DEST_OVRD;
1025*4882a593Smuzhiyun ctxt->info.valid_sections |=
1026*4882a593Smuzhiyun cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID);
1027*4882a593Smuzhiyun }
1028*4882a593Smuzhiyun
1029*4882a593Smuzhiyun if (init_vsi) {
1030*4882a593Smuzhiyun ret = ice_add_vsi(hw, vsi->idx, ctxt, NULL);
1031*4882a593Smuzhiyun if (ret) {
1032*4882a593Smuzhiyun dev_err(dev, "Add VSI failed, err %d\n", ret);
1033*4882a593Smuzhiyun ret = -EIO;
1034*4882a593Smuzhiyun goto out;
1035*4882a593Smuzhiyun }
1036*4882a593Smuzhiyun } else {
1037*4882a593Smuzhiyun ret = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1038*4882a593Smuzhiyun if (ret) {
1039*4882a593Smuzhiyun dev_err(dev, "Update VSI failed, err %d\n", ret);
1040*4882a593Smuzhiyun ret = -EIO;
1041*4882a593Smuzhiyun goto out;
1042*4882a593Smuzhiyun }
1043*4882a593Smuzhiyun }
1044*4882a593Smuzhiyun
1045*4882a593Smuzhiyun /* keep context for update VSI operations */
1046*4882a593Smuzhiyun vsi->info = ctxt->info;
1047*4882a593Smuzhiyun
1048*4882a593Smuzhiyun /* record VSI number returned */
1049*4882a593Smuzhiyun vsi->vsi_num = ctxt->vsi_num;
1050*4882a593Smuzhiyun
1051*4882a593Smuzhiyun out:
1052*4882a593Smuzhiyun kfree(ctxt);
1053*4882a593Smuzhiyun return ret;
1054*4882a593Smuzhiyun }
1055*4882a593Smuzhiyun
1056*4882a593Smuzhiyun /**
1057*4882a593Smuzhiyun * ice_free_res - free a block of resources
1058*4882a593Smuzhiyun * @res: pointer to the resource
1059*4882a593Smuzhiyun * @index: starting index previously returned by ice_get_res
1060*4882a593Smuzhiyun * @id: identifier to track owner
1061*4882a593Smuzhiyun *
1062*4882a593Smuzhiyun * Returns number of resources freed
1063*4882a593Smuzhiyun */
ice_free_res(struct ice_res_tracker * res,u16 index,u16 id)1064*4882a593Smuzhiyun int ice_free_res(struct ice_res_tracker *res, u16 index, u16 id)
1065*4882a593Smuzhiyun {
1066*4882a593Smuzhiyun int count = 0;
1067*4882a593Smuzhiyun int i;
1068*4882a593Smuzhiyun
1069*4882a593Smuzhiyun if (!res || index >= res->end)
1070*4882a593Smuzhiyun return -EINVAL;
1071*4882a593Smuzhiyun
1072*4882a593Smuzhiyun id |= ICE_RES_VALID_BIT;
1073*4882a593Smuzhiyun for (i = index; i < res->end && res->list[i] == id; i++) {
1074*4882a593Smuzhiyun res->list[i] = 0;
1075*4882a593Smuzhiyun count++;
1076*4882a593Smuzhiyun }
1077*4882a593Smuzhiyun
1078*4882a593Smuzhiyun return count;
1079*4882a593Smuzhiyun }
1080*4882a593Smuzhiyun
1081*4882a593Smuzhiyun /**
1082*4882a593Smuzhiyun * ice_search_res - Search the tracker for a block of resources
1083*4882a593Smuzhiyun * @res: pointer to the resource
1084*4882a593Smuzhiyun * @needed: size of the block needed
1085*4882a593Smuzhiyun * @id: identifier to track owner
1086*4882a593Smuzhiyun *
1087*4882a593Smuzhiyun * Returns the base item index of the block, or -ENOMEM for error
1088*4882a593Smuzhiyun */
ice_search_res(struct ice_res_tracker * res,u16 needed,u16 id)1089*4882a593Smuzhiyun static int ice_search_res(struct ice_res_tracker *res, u16 needed, u16 id)
1090*4882a593Smuzhiyun {
1091*4882a593Smuzhiyun u16 start = 0, end = 0;
1092*4882a593Smuzhiyun
1093*4882a593Smuzhiyun if (needed > res->end)
1094*4882a593Smuzhiyun return -ENOMEM;
1095*4882a593Smuzhiyun
1096*4882a593Smuzhiyun id |= ICE_RES_VALID_BIT;
1097*4882a593Smuzhiyun
1098*4882a593Smuzhiyun do {
1099*4882a593Smuzhiyun /* skip already allocated entries */
1100*4882a593Smuzhiyun if (res->list[end++] & ICE_RES_VALID_BIT) {
1101*4882a593Smuzhiyun start = end;
1102*4882a593Smuzhiyun if ((start + needed) > res->end)
1103*4882a593Smuzhiyun break;
1104*4882a593Smuzhiyun }
1105*4882a593Smuzhiyun
1106*4882a593Smuzhiyun if (end == (start + needed)) {
1107*4882a593Smuzhiyun int i = start;
1108*4882a593Smuzhiyun
1109*4882a593Smuzhiyun /* there was enough, so assign it to the requestor */
1110*4882a593Smuzhiyun while (i != end)
1111*4882a593Smuzhiyun res->list[i++] = id;
1112*4882a593Smuzhiyun
1113*4882a593Smuzhiyun return start;
1114*4882a593Smuzhiyun }
1115*4882a593Smuzhiyun } while (end < res->end);
1116*4882a593Smuzhiyun
1117*4882a593Smuzhiyun return -ENOMEM;
1118*4882a593Smuzhiyun }
1119*4882a593Smuzhiyun
1120*4882a593Smuzhiyun /**
1121*4882a593Smuzhiyun * ice_get_free_res_count - Get free count from a resource tracker
1122*4882a593Smuzhiyun * @res: Resource tracker instance
1123*4882a593Smuzhiyun */
ice_get_free_res_count(struct ice_res_tracker * res)1124*4882a593Smuzhiyun static u16 ice_get_free_res_count(struct ice_res_tracker *res)
1125*4882a593Smuzhiyun {
1126*4882a593Smuzhiyun u16 i, count = 0;
1127*4882a593Smuzhiyun
1128*4882a593Smuzhiyun for (i = 0; i < res->end; i++)
1129*4882a593Smuzhiyun if (!(res->list[i] & ICE_RES_VALID_BIT))
1130*4882a593Smuzhiyun count++;
1131*4882a593Smuzhiyun
1132*4882a593Smuzhiyun return count;
1133*4882a593Smuzhiyun }
1134*4882a593Smuzhiyun
1135*4882a593Smuzhiyun /**
1136*4882a593Smuzhiyun * ice_get_res - get a block of resources
1137*4882a593Smuzhiyun * @pf: board private structure
1138*4882a593Smuzhiyun * @res: pointer to the resource
1139*4882a593Smuzhiyun * @needed: size of the block needed
1140*4882a593Smuzhiyun * @id: identifier to track owner
1141*4882a593Smuzhiyun *
1142*4882a593Smuzhiyun * Returns the base item index of the block, or negative for error
1143*4882a593Smuzhiyun */
1144*4882a593Smuzhiyun int
ice_get_res(struct ice_pf * pf,struct ice_res_tracker * res,u16 needed,u16 id)1145*4882a593Smuzhiyun ice_get_res(struct ice_pf *pf, struct ice_res_tracker *res, u16 needed, u16 id)
1146*4882a593Smuzhiyun {
1147*4882a593Smuzhiyun if (!res || !pf)
1148*4882a593Smuzhiyun return -EINVAL;
1149*4882a593Smuzhiyun
1150*4882a593Smuzhiyun if (!needed || needed > res->num_entries || id >= ICE_RES_VALID_BIT) {
1151*4882a593Smuzhiyun dev_err(ice_pf_to_dev(pf), "param err: needed=%d, num_entries = %d id=0x%04x\n",
1152*4882a593Smuzhiyun needed, res->num_entries, id);
1153*4882a593Smuzhiyun return -EINVAL;
1154*4882a593Smuzhiyun }
1155*4882a593Smuzhiyun
1156*4882a593Smuzhiyun return ice_search_res(res, needed, id);
1157*4882a593Smuzhiyun }
1158*4882a593Smuzhiyun
1159*4882a593Smuzhiyun /**
1160*4882a593Smuzhiyun * ice_vsi_setup_vector_base - Set up the base vector for the given VSI
1161*4882a593Smuzhiyun * @vsi: ptr to the VSI
1162*4882a593Smuzhiyun *
1163*4882a593Smuzhiyun * This should only be called after ice_vsi_alloc() which allocates the
1164*4882a593Smuzhiyun * corresponding SW VSI structure and initializes num_queue_pairs for the
1165*4882a593Smuzhiyun * newly allocated VSI.
1166*4882a593Smuzhiyun *
1167*4882a593Smuzhiyun * Returns 0 on success or negative on failure
1168*4882a593Smuzhiyun */
ice_vsi_setup_vector_base(struct ice_vsi * vsi)1169*4882a593Smuzhiyun static int ice_vsi_setup_vector_base(struct ice_vsi *vsi)
1170*4882a593Smuzhiyun {
1171*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
1172*4882a593Smuzhiyun struct device *dev;
1173*4882a593Smuzhiyun u16 num_q_vectors;
1174*4882a593Smuzhiyun int base;
1175*4882a593Smuzhiyun
1176*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
1177*4882a593Smuzhiyun /* SRIOV doesn't grab irq_tracker entries for each VSI */
1178*4882a593Smuzhiyun if (vsi->type == ICE_VSI_VF)
1179*4882a593Smuzhiyun return 0;
1180*4882a593Smuzhiyun
1181*4882a593Smuzhiyun if (vsi->base_vector) {
1182*4882a593Smuzhiyun dev_dbg(dev, "VSI %d has non-zero base vector %d\n",
1183*4882a593Smuzhiyun vsi->vsi_num, vsi->base_vector);
1184*4882a593Smuzhiyun return -EEXIST;
1185*4882a593Smuzhiyun }
1186*4882a593Smuzhiyun
1187*4882a593Smuzhiyun num_q_vectors = vsi->num_q_vectors;
1188*4882a593Smuzhiyun /* reserve slots from OS requested IRQs */
1189*4882a593Smuzhiyun base = ice_get_res(pf, pf->irq_tracker, num_q_vectors, vsi->idx);
1190*4882a593Smuzhiyun
1191*4882a593Smuzhiyun if (base < 0) {
1192*4882a593Smuzhiyun dev_err(dev, "%d MSI-X interrupts available. %s %d failed to get %d MSI-X vectors\n",
1193*4882a593Smuzhiyun ice_get_free_res_count(pf->irq_tracker),
1194*4882a593Smuzhiyun ice_vsi_type_str(vsi->type), vsi->idx, num_q_vectors);
1195*4882a593Smuzhiyun return -ENOENT;
1196*4882a593Smuzhiyun }
1197*4882a593Smuzhiyun vsi->base_vector = (u16)base;
1198*4882a593Smuzhiyun pf->num_avail_sw_msix -= num_q_vectors;
1199*4882a593Smuzhiyun
1200*4882a593Smuzhiyun return 0;
1201*4882a593Smuzhiyun }
1202*4882a593Smuzhiyun
1203*4882a593Smuzhiyun /**
1204*4882a593Smuzhiyun * ice_vsi_clear_rings - Deallocates the Tx and Rx rings for VSI
1205*4882a593Smuzhiyun * @vsi: the VSI having rings deallocated
1206*4882a593Smuzhiyun */
ice_vsi_clear_rings(struct ice_vsi * vsi)1207*4882a593Smuzhiyun static void ice_vsi_clear_rings(struct ice_vsi *vsi)
1208*4882a593Smuzhiyun {
1209*4882a593Smuzhiyun int i;
1210*4882a593Smuzhiyun
1211*4882a593Smuzhiyun /* Avoid stale references by clearing map from vector to ring */
1212*4882a593Smuzhiyun if (vsi->q_vectors) {
1213*4882a593Smuzhiyun ice_for_each_q_vector(vsi, i) {
1214*4882a593Smuzhiyun struct ice_q_vector *q_vector = vsi->q_vectors[i];
1215*4882a593Smuzhiyun
1216*4882a593Smuzhiyun if (q_vector) {
1217*4882a593Smuzhiyun q_vector->tx.ring = NULL;
1218*4882a593Smuzhiyun q_vector->rx.ring = NULL;
1219*4882a593Smuzhiyun }
1220*4882a593Smuzhiyun }
1221*4882a593Smuzhiyun }
1222*4882a593Smuzhiyun
1223*4882a593Smuzhiyun if (vsi->tx_rings) {
1224*4882a593Smuzhiyun for (i = 0; i < vsi->alloc_txq; i++) {
1225*4882a593Smuzhiyun if (vsi->tx_rings[i]) {
1226*4882a593Smuzhiyun kfree_rcu(vsi->tx_rings[i], rcu);
1227*4882a593Smuzhiyun WRITE_ONCE(vsi->tx_rings[i], NULL);
1228*4882a593Smuzhiyun }
1229*4882a593Smuzhiyun }
1230*4882a593Smuzhiyun }
1231*4882a593Smuzhiyun if (vsi->rx_rings) {
1232*4882a593Smuzhiyun for (i = 0; i < vsi->alloc_rxq; i++) {
1233*4882a593Smuzhiyun if (vsi->rx_rings[i]) {
1234*4882a593Smuzhiyun kfree_rcu(vsi->rx_rings[i], rcu);
1235*4882a593Smuzhiyun WRITE_ONCE(vsi->rx_rings[i], NULL);
1236*4882a593Smuzhiyun }
1237*4882a593Smuzhiyun }
1238*4882a593Smuzhiyun }
1239*4882a593Smuzhiyun }
1240*4882a593Smuzhiyun
1241*4882a593Smuzhiyun /**
1242*4882a593Smuzhiyun * ice_vsi_alloc_rings - Allocates Tx and Rx rings for the VSI
1243*4882a593Smuzhiyun * @vsi: VSI which is having rings allocated
1244*4882a593Smuzhiyun */
ice_vsi_alloc_rings(struct ice_vsi * vsi)1245*4882a593Smuzhiyun static int ice_vsi_alloc_rings(struct ice_vsi *vsi)
1246*4882a593Smuzhiyun {
1247*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
1248*4882a593Smuzhiyun struct device *dev;
1249*4882a593Smuzhiyun u16 i;
1250*4882a593Smuzhiyun
1251*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
1252*4882a593Smuzhiyun /* Allocate Tx rings */
1253*4882a593Smuzhiyun for (i = 0; i < vsi->alloc_txq; i++) {
1254*4882a593Smuzhiyun struct ice_ring *ring;
1255*4882a593Smuzhiyun
1256*4882a593Smuzhiyun /* allocate with kzalloc(), free with kfree_rcu() */
1257*4882a593Smuzhiyun ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1258*4882a593Smuzhiyun
1259*4882a593Smuzhiyun if (!ring)
1260*4882a593Smuzhiyun goto err_out;
1261*4882a593Smuzhiyun
1262*4882a593Smuzhiyun ring->q_index = i;
1263*4882a593Smuzhiyun ring->reg_idx = vsi->txq_map[i];
1264*4882a593Smuzhiyun ring->ring_active = false;
1265*4882a593Smuzhiyun ring->vsi = vsi;
1266*4882a593Smuzhiyun ring->dev = dev;
1267*4882a593Smuzhiyun ring->count = vsi->num_tx_desc;
1268*4882a593Smuzhiyun ring->txq_teid = ICE_INVAL_TEID;
1269*4882a593Smuzhiyun WRITE_ONCE(vsi->tx_rings[i], ring);
1270*4882a593Smuzhiyun }
1271*4882a593Smuzhiyun
1272*4882a593Smuzhiyun /* Allocate Rx rings */
1273*4882a593Smuzhiyun for (i = 0; i < vsi->alloc_rxq; i++) {
1274*4882a593Smuzhiyun struct ice_ring *ring;
1275*4882a593Smuzhiyun
1276*4882a593Smuzhiyun /* allocate with kzalloc(), free with kfree_rcu() */
1277*4882a593Smuzhiyun ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1278*4882a593Smuzhiyun if (!ring)
1279*4882a593Smuzhiyun goto err_out;
1280*4882a593Smuzhiyun
1281*4882a593Smuzhiyun ring->q_index = i;
1282*4882a593Smuzhiyun ring->reg_idx = vsi->rxq_map[i];
1283*4882a593Smuzhiyun ring->ring_active = false;
1284*4882a593Smuzhiyun ring->vsi = vsi;
1285*4882a593Smuzhiyun ring->netdev = vsi->netdev;
1286*4882a593Smuzhiyun ring->dev = dev;
1287*4882a593Smuzhiyun ring->count = vsi->num_rx_desc;
1288*4882a593Smuzhiyun WRITE_ONCE(vsi->rx_rings[i], ring);
1289*4882a593Smuzhiyun }
1290*4882a593Smuzhiyun
1291*4882a593Smuzhiyun return 0;
1292*4882a593Smuzhiyun
1293*4882a593Smuzhiyun err_out:
1294*4882a593Smuzhiyun ice_vsi_clear_rings(vsi);
1295*4882a593Smuzhiyun return -ENOMEM;
1296*4882a593Smuzhiyun }
1297*4882a593Smuzhiyun
1298*4882a593Smuzhiyun /**
1299*4882a593Smuzhiyun * ice_vsi_manage_rss_lut - disable/enable RSS
1300*4882a593Smuzhiyun * @vsi: the VSI being changed
1301*4882a593Smuzhiyun * @ena: boolean value indicating if this is an enable or disable request
1302*4882a593Smuzhiyun *
1303*4882a593Smuzhiyun * In the event of disable request for RSS, this function will zero out RSS
1304*4882a593Smuzhiyun * LUT, while in the event of enable request for RSS, it will reconfigure RSS
1305*4882a593Smuzhiyun * LUT.
1306*4882a593Smuzhiyun */
ice_vsi_manage_rss_lut(struct ice_vsi * vsi,bool ena)1307*4882a593Smuzhiyun int ice_vsi_manage_rss_lut(struct ice_vsi *vsi, bool ena)
1308*4882a593Smuzhiyun {
1309*4882a593Smuzhiyun int err = 0;
1310*4882a593Smuzhiyun u8 *lut;
1311*4882a593Smuzhiyun
1312*4882a593Smuzhiyun lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
1313*4882a593Smuzhiyun if (!lut)
1314*4882a593Smuzhiyun return -ENOMEM;
1315*4882a593Smuzhiyun
1316*4882a593Smuzhiyun if (ena) {
1317*4882a593Smuzhiyun if (vsi->rss_lut_user)
1318*4882a593Smuzhiyun memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1319*4882a593Smuzhiyun else
1320*4882a593Smuzhiyun ice_fill_rss_lut(lut, vsi->rss_table_size,
1321*4882a593Smuzhiyun vsi->rss_size);
1322*4882a593Smuzhiyun }
1323*4882a593Smuzhiyun
1324*4882a593Smuzhiyun err = ice_set_rss(vsi, NULL, lut, vsi->rss_table_size);
1325*4882a593Smuzhiyun kfree(lut);
1326*4882a593Smuzhiyun return err;
1327*4882a593Smuzhiyun }
1328*4882a593Smuzhiyun
1329*4882a593Smuzhiyun /**
1330*4882a593Smuzhiyun * ice_vsi_cfg_rss_lut_key - Configure RSS params for a VSI
1331*4882a593Smuzhiyun * @vsi: VSI to be configured
1332*4882a593Smuzhiyun */
ice_vsi_cfg_rss_lut_key(struct ice_vsi * vsi)1333*4882a593Smuzhiyun static int ice_vsi_cfg_rss_lut_key(struct ice_vsi *vsi)
1334*4882a593Smuzhiyun {
1335*4882a593Smuzhiyun struct ice_aqc_get_set_rss_keys *key;
1336*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
1337*4882a593Smuzhiyun enum ice_status status;
1338*4882a593Smuzhiyun struct device *dev;
1339*4882a593Smuzhiyun int err = 0;
1340*4882a593Smuzhiyun u8 *lut;
1341*4882a593Smuzhiyun
1342*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
1343*4882a593Smuzhiyun vsi->rss_size = min_t(u16, vsi->rss_size, vsi->num_rxq);
1344*4882a593Smuzhiyun
1345*4882a593Smuzhiyun lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
1346*4882a593Smuzhiyun if (!lut)
1347*4882a593Smuzhiyun return -ENOMEM;
1348*4882a593Smuzhiyun
1349*4882a593Smuzhiyun if (vsi->rss_lut_user)
1350*4882a593Smuzhiyun memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
1351*4882a593Smuzhiyun else
1352*4882a593Smuzhiyun ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
1353*4882a593Smuzhiyun
1354*4882a593Smuzhiyun status = ice_aq_set_rss_lut(&pf->hw, vsi->idx, vsi->rss_lut_type, lut,
1355*4882a593Smuzhiyun vsi->rss_table_size);
1356*4882a593Smuzhiyun
1357*4882a593Smuzhiyun if (status) {
1358*4882a593Smuzhiyun dev_err(dev, "set_rss_lut failed, error %s\n",
1359*4882a593Smuzhiyun ice_stat_str(status));
1360*4882a593Smuzhiyun err = -EIO;
1361*4882a593Smuzhiyun goto ice_vsi_cfg_rss_exit;
1362*4882a593Smuzhiyun }
1363*4882a593Smuzhiyun
1364*4882a593Smuzhiyun key = kzalloc(sizeof(*key), GFP_KERNEL);
1365*4882a593Smuzhiyun if (!key) {
1366*4882a593Smuzhiyun err = -ENOMEM;
1367*4882a593Smuzhiyun goto ice_vsi_cfg_rss_exit;
1368*4882a593Smuzhiyun }
1369*4882a593Smuzhiyun
1370*4882a593Smuzhiyun if (vsi->rss_hkey_user)
1371*4882a593Smuzhiyun memcpy(key,
1372*4882a593Smuzhiyun (struct ice_aqc_get_set_rss_keys *)vsi->rss_hkey_user,
1373*4882a593Smuzhiyun ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE);
1374*4882a593Smuzhiyun else
1375*4882a593Smuzhiyun netdev_rss_key_fill((void *)key,
1376*4882a593Smuzhiyun ICE_GET_SET_RSS_KEY_EXTEND_KEY_SIZE);
1377*4882a593Smuzhiyun
1378*4882a593Smuzhiyun status = ice_aq_set_rss_key(&pf->hw, vsi->idx, key);
1379*4882a593Smuzhiyun
1380*4882a593Smuzhiyun if (status) {
1381*4882a593Smuzhiyun dev_err(dev, "set_rss_key failed, error %s\n",
1382*4882a593Smuzhiyun ice_stat_str(status));
1383*4882a593Smuzhiyun err = -EIO;
1384*4882a593Smuzhiyun }
1385*4882a593Smuzhiyun
1386*4882a593Smuzhiyun kfree(key);
1387*4882a593Smuzhiyun ice_vsi_cfg_rss_exit:
1388*4882a593Smuzhiyun kfree(lut);
1389*4882a593Smuzhiyun return err;
1390*4882a593Smuzhiyun }
1391*4882a593Smuzhiyun
1392*4882a593Smuzhiyun /**
1393*4882a593Smuzhiyun * ice_vsi_set_vf_rss_flow_fld - Sets VF VSI RSS input set for different flows
1394*4882a593Smuzhiyun * @vsi: VSI to be configured
1395*4882a593Smuzhiyun *
1396*4882a593Smuzhiyun * This function will only be called during the VF VSI setup. Upon successful
1397*4882a593Smuzhiyun * completion of package download, this function will configure default RSS
1398*4882a593Smuzhiyun * input sets for VF VSI.
1399*4882a593Smuzhiyun */
ice_vsi_set_vf_rss_flow_fld(struct ice_vsi * vsi)1400*4882a593Smuzhiyun static void ice_vsi_set_vf_rss_flow_fld(struct ice_vsi *vsi)
1401*4882a593Smuzhiyun {
1402*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
1403*4882a593Smuzhiyun enum ice_status status;
1404*4882a593Smuzhiyun struct device *dev;
1405*4882a593Smuzhiyun
1406*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
1407*4882a593Smuzhiyun if (ice_is_safe_mode(pf)) {
1408*4882a593Smuzhiyun dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
1409*4882a593Smuzhiyun vsi->vsi_num);
1410*4882a593Smuzhiyun return;
1411*4882a593Smuzhiyun }
1412*4882a593Smuzhiyun
1413*4882a593Smuzhiyun status = ice_add_avf_rss_cfg(&pf->hw, vsi->idx, ICE_DEFAULT_RSS_HENA);
1414*4882a593Smuzhiyun if (status)
1415*4882a593Smuzhiyun dev_dbg(dev, "ice_add_avf_rss_cfg failed for vsi = %d, error = %s\n",
1416*4882a593Smuzhiyun vsi->vsi_num, ice_stat_str(status));
1417*4882a593Smuzhiyun }
1418*4882a593Smuzhiyun
1419*4882a593Smuzhiyun /**
1420*4882a593Smuzhiyun * ice_vsi_set_rss_flow_fld - Sets RSS input set for different flows
1421*4882a593Smuzhiyun * @vsi: VSI to be configured
1422*4882a593Smuzhiyun *
1423*4882a593Smuzhiyun * This function will only be called after successful download package call
1424*4882a593Smuzhiyun * during initialization of PF. Since the downloaded package will erase the
1425*4882a593Smuzhiyun * RSS section, this function will configure RSS input sets for different
1426*4882a593Smuzhiyun * flow types. The last profile added has the highest priority, therefore 2
1427*4882a593Smuzhiyun * tuple profiles (i.e. IPv4 src/dst) are added before 4 tuple profiles
1428*4882a593Smuzhiyun * (i.e. IPv4 src/dst TCP src/dst port).
1429*4882a593Smuzhiyun */
ice_vsi_set_rss_flow_fld(struct ice_vsi * vsi)1430*4882a593Smuzhiyun static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi)
1431*4882a593Smuzhiyun {
1432*4882a593Smuzhiyun u16 vsi_handle = vsi->idx, vsi_num = vsi->vsi_num;
1433*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
1434*4882a593Smuzhiyun struct ice_hw *hw = &pf->hw;
1435*4882a593Smuzhiyun enum ice_status status;
1436*4882a593Smuzhiyun struct device *dev;
1437*4882a593Smuzhiyun
1438*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
1439*4882a593Smuzhiyun if (ice_is_safe_mode(pf)) {
1440*4882a593Smuzhiyun dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
1441*4882a593Smuzhiyun vsi_num);
1442*4882a593Smuzhiyun return;
1443*4882a593Smuzhiyun }
1444*4882a593Smuzhiyun /* configure RSS for IPv4 with input set IP src/dst */
1445*4882a593Smuzhiyun status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV4,
1446*4882a593Smuzhiyun ICE_FLOW_SEG_HDR_IPV4);
1447*4882a593Smuzhiyun if (status)
1448*4882a593Smuzhiyun dev_dbg(dev, "ice_add_rss_cfg failed for ipv4 flow, vsi = %d, error = %s\n",
1449*4882a593Smuzhiyun vsi_num, ice_stat_str(status));
1450*4882a593Smuzhiyun
1451*4882a593Smuzhiyun /* configure RSS for IPv6 with input set IPv6 src/dst */
1452*4882a593Smuzhiyun status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV6,
1453*4882a593Smuzhiyun ICE_FLOW_SEG_HDR_IPV6);
1454*4882a593Smuzhiyun if (status)
1455*4882a593Smuzhiyun dev_dbg(dev, "ice_add_rss_cfg failed for ipv6 flow, vsi = %d, error = %s\n",
1456*4882a593Smuzhiyun vsi_num, ice_stat_str(status));
1457*4882a593Smuzhiyun
1458*4882a593Smuzhiyun /* configure RSS for tcp4 with input set IP src/dst, TCP src/dst */
1459*4882a593Smuzhiyun status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_TCP_IPV4,
1460*4882a593Smuzhiyun ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4);
1461*4882a593Smuzhiyun if (status)
1462*4882a593Smuzhiyun dev_dbg(dev, "ice_add_rss_cfg failed for tcp4 flow, vsi = %d, error = %s\n",
1463*4882a593Smuzhiyun vsi_num, ice_stat_str(status));
1464*4882a593Smuzhiyun
1465*4882a593Smuzhiyun /* configure RSS for udp4 with input set IP src/dst, UDP src/dst */
1466*4882a593Smuzhiyun status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_UDP_IPV4,
1467*4882a593Smuzhiyun ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4);
1468*4882a593Smuzhiyun if (status)
1469*4882a593Smuzhiyun dev_dbg(dev, "ice_add_rss_cfg failed for udp4 flow, vsi = %d, error = %s\n",
1470*4882a593Smuzhiyun vsi_num, ice_stat_str(status));
1471*4882a593Smuzhiyun
1472*4882a593Smuzhiyun /* configure RSS for sctp4 with input set IP src/dst */
1473*4882a593Smuzhiyun status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV4,
1474*4882a593Smuzhiyun ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4);
1475*4882a593Smuzhiyun if (status)
1476*4882a593Smuzhiyun dev_dbg(dev, "ice_add_rss_cfg failed for sctp4 flow, vsi = %d, error = %s\n",
1477*4882a593Smuzhiyun vsi_num, ice_stat_str(status));
1478*4882a593Smuzhiyun
1479*4882a593Smuzhiyun /* configure RSS for tcp6 with input set IPv6 src/dst, TCP src/dst */
1480*4882a593Smuzhiyun status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_TCP_IPV6,
1481*4882a593Smuzhiyun ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6);
1482*4882a593Smuzhiyun if (status)
1483*4882a593Smuzhiyun dev_dbg(dev, "ice_add_rss_cfg failed for tcp6 flow, vsi = %d, error = %s\n",
1484*4882a593Smuzhiyun vsi_num, ice_stat_str(status));
1485*4882a593Smuzhiyun
1486*4882a593Smuzhiyun /* configure RSS for udp6 with input set IPv6 src/dst, UDP src/dst */
1487*4882a593Smuzhiyun status = ice_add_rss_cfg(hw, vsi_handle, ICE_HASH_UDP_IPV6,
1488*4882a593Smuzhiyun ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6);
1489*4882a593Smuzhiyun if (status)
1490*4882a593Smuzhiyun dev_dbg(dev, "ice_add_rss_cfg failed for udp6 flow, vsi = %d, error = %s\n",
1491*4882a593Smuzhiyun vsi_num, ice_stat_str(status));
1492*4882a593Smuzhiyun
1493*4882a593Smuzhiyun /* configure RSS for sctp6 with input set IPv6 src/dst */
1494*4882a593Smuzhiyun status = ice_add_rss_cfg(hw, vsi_handle, ICE_FLOW_HASH_IPV6,
1495*4882a593Smuzhiyun ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6);
1496*4882a593Smuzhiyun if (status)
1497*4882a593Smuzhiyun dev_dbg(dev, "ice_add_rss_cfg failed for sctp6 flow, vsi = %d, error = %s\n",
1498*4882a593Smuzhiyun vsi_num, ice_stat_str(status));
1499*4882a593Smuzhiyun }
1500*4882a593Smuzhiyun
1501*4882a593Smuzhiyun /**
1502*4882a593Smuzhiyun * ice_pf_state_is_nominal - checks the PF for nominal state
1503*4882a593Smuzhiyun * @pf: pointer to PF to check
1504*4882a593Smuzhiyun *
1505*4882a593Smuzhiyun * Check the PF's state for a collection of bits that would indicate
1506*4882a593Smuzhiyun * the PF is in a state that would inhibit normal operation for
1507*4882a593Smuzhiyun * driver functionality.
1508*4882a593Smuzhiyun *
1509*4882a593Smuzhiyun * Returns true if PF is in a nominal state, false otherwise
1510*4882a593Smuzhiyun */
ice_pf_state_is_nominal(struct ice_pf * pf)1511*4882a593Smuzhiyun bool ice_pf_state_is_nominal(struct ice_pf *pf)
1512*4882a593Smuzhiyun {
1513*4882a593Smuzhiyun DECLARE_BITMAP(check_bits, __ICE_STATE_NBITS) = { 0 };
1514*4882a593Smuzhiyun
1515*4882a593Smuzhiyun if (!pf)
1516*4882a593Smuzhiyun return false;
1517*4882a593Smuzhiyun
1518*4882a593Smuzhiyun bitmap_set(check_bits, 0, __ICE_STATE_NOMINAL_CHECK_BITS);
1519*4882a593Smuzhiyun if (bitmap_intersects(pf->state, check_bits, __ICE_STATE_NBITS))
1520*4882a593Smuzhiyun return false;
1521*4882a593Smuzhiyun
1522*4882a593Smuzhiyun return true;
1523*4882a593Smuzhiyun }
1524*4882a593Smuzhiyun
1525*4882a593Smuzhiyun /**
1526*4882a593Smuzhiyun * ice_update_eth_stats - Update VSI-specific ethernet statistics counters
1527*4882a593Smuzhiyun * @vsi: the VSI to be updated
1528*4882a593Smuzhiyun */
ice_update_eth_stats(struct ice_vsi * vsi)1529*4882a593Smuzhiyun void ice_update_eth_stats(struct ice_vsi *vsi)
1530*4882a593Smuzhiyun {
1531*4882a593Smuzhiyun struct ice_eth_stats *prev_es, *cur_es;
1532*4882a593Smuzhiyun struct ice_hw *hw = &vsi->back->hw;
1533*4882a593Smuzhiyun u16 vsi_num = vsi->vsi_num; /* HW absolute index of a VSI */
1534*4882a593Smuzhiyun
1535*4882a593Smuzhiyun prev_es = &vsi->eth_stats_prev;
1536*4882a593Smuzhiyun cur_es = &vsi->eth_stats;
1537*4882a593Smuzhiyun
1538*4882a593Smuzhiyun ice_stat_update40(hw, GLV_GORCL(vsi_num), vsi->stat_offsets_loaded,
1539*4882a593Smuzhiyun &prev_es->rx_bytes, &cur_es->rx_bytes);
1540*4882a593Smuzhiyun
1541*4882a593Smuzhiyun ice_stat_update40(hw, GLV_UPRCL(vsi_num), vsi->stat_offsets_loaded,
1542*4882a593Smuzhiyun &prev_es->rx_unicast, &cur_es->rx_unicast);
1543*4882a593Smuzhiyun
1544*4882a593Smuzhiyun ice_stat_update40(hw, GLV_MPRCL(vsi_num), vsi->stat_offsets_loaded,
1545*4882a593Smuzhiyun &prev_es->rx_multicast, &cur_es->rx_multicast);
1546*4882a593Smuzhiyun
1547*4882a593Smuzhiyun ice_stat_update40(hw, GLV_BPRCL(vsi_num), vsi->stat_offsets_loaded,
1548*4882a593Smuzhiyun &prev_es->rx_broadcast, &cur_es->rx_broadcast);
1549*4882a593Smuzhiyun
1550*4882a593Smuzhiyun ice_stat_update32(hw, GLV_RDPC(vsi_num), vsi->stat_offsets_loaded,
1551*4882a593Smuzhiyun &prev_es->rx_discards, &cur_es->rx_discards);
1552*4882a593Smuzhiyun
1553*4882a593Smuzhiyun ice_stat_update40(hw, GLV_GOTCL(vsi_num), vsi->stat_offsets_loaded,
1554*4882a593Smuzhiyun &prev_es->tx_bytes, &cur_es->tx_bytes);
1555*4882a593Smuzhiyun
1556*4882a593Smuzhiyun ice_stat_update40(hw, GLV_UPTCL(vsi_num), vsi->stat_offsets_loaded,
1557*4882a593Smuzhiyun &prev_es->tx_unicast, &cur_es->tx_unicast);
1558*4882a593Smuzhiyun
1559*4882a593Smuzhiyun ice_stat_update40(hw, GLV_MPTCL(vsi_num), vsi->stat_offsets_loaded,
1560*4882a593Smuzhiyun &prev_es->tx_multicast, &cur_es->tx_multicast);
1561*4882a593Smuzhiyun
1562*4882a593Smuzhiyun ice_stat_update40(hw, GLV_BPTCL(vsi_num), vsi->stat_offsets_loaded,
1563*4882a593Smuzhiyun &prev_es->tx_broadcast, &cur_es->tx_broadcast);
1564*4882a593Smuzhiyun
1565*4882a593Smuzhiyun ice_stat_update32(hw, GLV_TEPC(vsi_num), vsi->stat_offsets_loaded,
1566*4882a593Smuzhiyun &prev_es->tx_errors, &cur_es->tx_errors);
1567*4882a593Smuzhiyun
1568*4882a593Smuzhiyun vsi->stat_offsets_loaded = true;
1569*4882a593Smuzhiyun }
1570*4882a593Smuzhiyun
1571*4882a593Smuzhiyun /**
1572*4882a593Smuzhiyun * ice_vsi_add_vlan - Add VSI membership for given VLAN
1573*4882a593Smuzhiyun * @vsi: the VSI being configured
1574*4882a593Smuzhiyun * @vid: VLAN ID to be added
1575*4882a593Smuzhiyun * @action: filter action to be performed on match
1576*4882a593Smuzhiyun */
1577*4882a593Smuzhiyun int
ice_vsi_add_vlan(struct ice_vsi * vsi,u16 vid,enum ice_sw_fwd_act_type action)1578*4882a593Smuzhiyun ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid, enum ice_sw_fwd_act_type action)
1579*4882a593Smuzhiyun {
1580*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
1581*4882a593Smuzhiyun struct device *dev;
1582*4882a593Smuzhiyun int err = 0;
1583*4882a593Smuzhiyun
1584*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
1585*4882a593Smuzhiyun
1586*4882a593Smuzhiyun if (!ice_fltr_add_vlan(vsi, vid, action)) {
1587*4882a593Smuzhiyun vsi->num_vlan++;
1588*4882a593Smuzhiyun } else {
1589*4882a593Smuzhiyun err = -ENODEV;
1590*4882a593Smuzhiyun dev_err(dev, "Failure Adding VLAN %d on VSI %i\n", vid,
1591*4882a593Smuzhiyun vsi->vsi_num);
1592*4882a593Smuzhiyun }
1593*4882a593Smuzhiyun
1594*4882a593Smuzhiyun return err;
1595*4882a593Smuzhiyun }
1596*4882a593Smuzhiyun
1597*4882a593Smuzhiyun /**
1598*4882a593Smuzhiyun * ice_vsi_kill_vlan - Remove VSI membership for a given VLAN
1599*4882a593Smuzhiyun * @vsi: the VSI being configured
1600*4882a593Smuzhiyun * @vid: VLAN ID to be removed
1601*4882a593Smuzhiyun *
1602*4882a593Smuzhiyun * Returns 0 on success and negative on failure
1603*4882a593Smuzhiyun */
ice_vsi_kill_vlan(struct ice_vsi * vsi,u16 vid)1604*4882a593Smuzhiyun int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid)
1605*4882a593Smuzhiyun {
1606*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
1607*4882a593Smuzhiyun enum ice_status status;
1608*4882a593Smuzhiyun struct device *dev;
1609*4882a593Smuzhiyun int err = 0;
1610*4882a593Smuzhiyun
1611*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
1612*4882a593Smuzhiyun
1613*4882a593Smuzhiyun status = ice_fltr_remove_vlan(vsi, vid, ICE_FWD_TO_VSI);
1614*4882a593Smuzhiyun if (!status) {
1615*4882a593Smuzhiyun vsi->num_vlan--;
1616*4882a593Smuzhiyun } else if (status == ICE_ERR_DOES_NOT_EXIST) {
1617*4882a593Smuzhiyun dev_dbg(dev, "Failed to remove VLAN %d on VSI %i, it does not exist, status: %s\n",
1618*4882a593Smuzhiyun vid, vsi->vsi_num, ice_stat_str(status));
1619*4882a593Smuzhiyun } else {
1620*4882a593Smuzhiyun dev_err(dev, "Error removing VLAN %d on vsi %i error: %s\n",
1621*4882a593Smuzhiyun vid, vsi->vsi_num, ice_stat_str(status));
1622*4882a593Smuzhiyun err = -EIO;
1623*4882a593Smuzhiyun }
1624*4882a593Smuzhiyun
1625*4882a593Smuzhiyun return err;
1626*4882a593Smuzhiyun }
1627*4882a593Smuzhiyun
1628*4882a593Smuzhiyun /**
1629*4882a593Smuzhiyun * ice_vsi_cfg_frame_size - setup max frame size and Rx buffer length
1630*4882a593Smuzhiyun * @vsi: VSI
1631*4882a593Smuzhiyun */
ice_vsi_cfg_frame_size(struct ice_vsi * vsi)1632*4882a593Smuzhiyun void ice_vsi_cfg_frame_size(struct ice_vsi *vsi)
1633*4882a593Smuzhiyun {
1634*4882a593Smuzhiyun if (!vsi->netdev || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags)) {
1635*4882a593Smuzhiyun vsi->max_frame = ICE_AQ_SET_MAC_FRAME_SIZE_MAX;
1636*4882a593Smuzhiyun vsi->rx_buf_len = ICE_RXBUF_2048;
1637*4882a593Smuzhiyun #if (PAGE_SIZE < 8192)
1638*4882a593Smuzhiyun } else if (!ICE_2K_TOO_SMALL_WITH_PADDING &&
1639*4882a593Smuzhiyun (vsi->netdev->mtu <= ETH_DATA_LEN)) {
1640*4882a593Smuzhiyun vsi->max_frame = ICE_RXBUF_1536 - NET_IP_ALIGN;
1641*4882a593Smuzhiyun vsi->rx_buf_len = ICE_RXBUF_1536 - NET_IP_ALIGN;
1642*4882a593Smuzhiyun #endif
1643*4882a593Smuzhiyun } else {
1644*4882a593Smuzhiyun vsi->max_frame = ICE_AQ_SET_MAC_FRAME_SIZE_MAX;
1645*4882a593Smuzhiyun #if (PAGE_SIZE < 8192)
1646*4882a593Smuzhiyun vsi->rx_buf_len = ICE_RXBUF_3072;
1647*4882a593Smuzhiyun #else
1648*4882a593Smuzhiyun vsi->rx_buf_len = ICE_RXBUF_2048;
1649*4882a593Smuzhiyun #endif
1650*4882a593Smuzhiyun }
1651*4882a593Smuzhiyun }
1652*4882a593Smuzhiyun
1653*4882a593Smuzhiyun /**
1654*4882a593Smuzhiyun * ice_write_qrxflxp_cntxt - write/configure QRXFLXP_CNTXT register
1655*4882a593Smuzhiyun * @hw: HW pointer
1656*4882a593Smuzhiyun * @pf_q: index of the Rx queue in the PF's queue space
1657*4882a593Smuzhiyun * @rxdid: flexible descriptor RXDID
1658*4882a593Smuzhiyun * @prio: priority for the RXDID for this queue
1659*4882a593Smuzhiyun */
1660*4882a593Smuzhiyun void
ice_write_qrxflxp_cntxt(struct ice_hw * hw,u16 pf_q,u32 rxdid,u32 prio)1661*4882a593Smuzhiyun ice_write_qrxflxp_cntxt(struct ice_hw *hw, u16 pf_q, u32 rxdid, u32 prio)
1662*4882a593Smuzhiyun {
1663*4882a593Smuzhiyun int regval = rd32(hw, QRXFLXP_CNTXT(pf_q));
1664*4882a593Smuzhiyun
1665*4882a593Smuzhiyun /* clear any previous values */
1666*4882a593Smuzhiyun regval &= ~(QRXFLXP_CNTXT_RXDID_IDX_M |
1667*4882a593Smuzhiyun QRXFLXP_CNTXT_RXDID_PRIO_M |
1668*4882a593Smuzhiyun QRXFLXP_CNTXT_TS_M);
1669*4882a593Smuzhiyun
1670*4882a593Smuzhiyun regval |= (rxdid << QRXFLXP_CNTXT_RXDID_IDX_S) &
1671*4882a593Smuzhiyun QRXFLXP_CNTXT_RXDID_IDX_M;
1672*4882a593Smuzhiyun
1673*4882a593Smuzhiyun regval |= (prio << QRXFLXP_CNTXT_RXDID_PRIO_S) &
1674*4882a593Smuzhiyun QRXFLXP_CNTXT_RXDID_PRIO_M;
1675*4882a593Smuzhiyun
1676*4882a593Smuzhiyun wr32(hw, QRXFLXP_CNTXT(pf_q), regval);
1677*4882a593Smuzhiyun }
1678*4882a593Smuzhiyun
1679*4882a593Smuzhiyun /**
1680*4882a593Smuzhiyun * ice_vsi_cfg_rxqs - Configure the VSI for Rx
1681*4882a593Smuzhiyun * @vsi: the VSI being configured
1682*4882a593Smuzhiyun *
1683*4882a593Smuzhiyun * Return 0 on success and a negative value on error
1684*4882a593Smuzhiyun * Configure the Rx VSI for operation.
1685*4882a593Smuzhiyun */
ice_vsi_cfg_rxqs(struct ice_vsi * vsi)1686*4882a593Smuzhiyun int ice_vsi_cfg_rxqs(struct ice_vsi *vsi)
1687*4882a593Smuzhiyun {
1688*4882a593Smuzhiyun u16 i;
1689*4882a593Smuzhiyun
1690*4882a593Smuzhiyun if (vsi->type == ICE_VSI_VF)
1691*4882a593Smuzhiyun goto setup_rings;
1692*4882a593Smuzhiyun
1693*4882a593Smuzhiyun ice_vsi_cfg_frame_size(vsi);
1694*4882a593Smuzhiyun setup_rings:
1695*4882a593Smuzhiyun /* set up individual rings */
1696*4882a593Smuzhiyun for (i = 0; i < vsi->num_rxq; i++) {
1697*4882a593Smuzhiyun int err;
1698*4882a593Smuzhiyun
1699*4882a593Smuzhiyun err = ice_setup_rx_ctx(vsi->rx_rings[i]);
1700*4882a593Smuzhiyun if (err) {
1701*4882a593Smuzhiyun dev_err(ice_pf_to_dev(vsi->back), "ice_setup_rx_ctx failed for RxQ %d, err %d\n",
1702*4882a593Smuzhiyun i, err);
1703*4882a593Smuzhiyun return err;
1704*4882a593Smuzhiyun }
1705*4882a593Smuzhiyun }
1706*4882a593Smuzhiyun
1707*4882a593Smuzhiyun return 0;
1708*4882a593Smuzhiyun }
1709*4882a593Smuzhiyun
1710*4882a593Smuzhiyun /**
1711*4882a593Smuzhiyun * ice_vsi_cfg_txqs - Configure the VSI for Tx
1712*4882a593Smuzhiyun * @vsi: the VSI being configured
1713*4882a593Smuzhiyun * @rings: Tx ring array to be configured
1714*4882a593Smuzhiyun * @count: number of Tx ring array elements
1715*4882a593Smuzhiyun *
1716*4882a593Smuzhiyun * Return 0 on success and a negative value on error
1717*4882a593Smuzhiyun * Configure the Tx VSI for operation.
1718*4882a593Smuzhiyun */
1719*4882a593Smuzhiyun static int
ice_vsi_cfg_txqs(struct ice_vsi * vsi,struct ice_ring ** rings,u16 count)1720*4882a593Smuzhiyun ice_vsi_cfg_txqs(struct ice_vsi *vsi, struct ice_ring **rings, u16 count)
1721*4882a593Smuzhiyun {
1722*4882a593Smuzhiyun struct ice_aqc_add_tx_qgrp *qg_buf;
1723*4882a593Smuzhiyun u16 q_idx = 0;
1724*4882a593Smuzhiyun int err = 0;
1725*4882a593Smuzhiyun
1726*4882a593Smuzhiyun qg_buf = kzalloc(struct_size(qg_buf, txqs, 1), GFP_KERNEL);
1727*4882a593Smuzhiyun if (!qg_buf)
1728*4882a593Smuzhiyun return -ENOMEM;
1729*4882a593Smuzhiyun
1730*4882a593Smuzhiyun qg_buf->num_txqs = 1;
1731*4882a593Smuzhiyun
1732*4882a593Smuzhiyun for (q_idx = 0; q_idx < count; q_idx++) {
1733*4882a593Smuzhiyun err = ice_vsi_cfg_txq(vsi, rings[q_idx], qg_buf);
1734*4882a593Smuzhiyun if (err)
1735*4882a593Smuzhiyun goto err_cfg_txqs;
1736*4882a593Smuzhiyun }
1737*4882a593Smuzhiyun
1738*4882a593Smuzhiyun err_cfg_txqs:
1739*4882a593Smuzhiyun kfree(qg_buf);
1740*4882a593Smuzhiyun return err;
1741*4882a593Smuzhiyun }
1742*4882a593Smuzhiyun
1743*4882a593Smuzhiyun /**
1744*4882a593Smuzhiyun * ice_vsi_cfg_lan_txqs - Configure the VSI for Tx
1745*4882a593Smuzhiyun * @vsi: the VSI being configured
1746*4882a593Smuzhiyun *
1747*4882a593Smuzhiyun * Return 0 on success and a negative value on error
1748*4882a593Smuzhiyun * Configure the Tx VSI for operation.
1749*4882a593Smuzhiyun */
ice_vsi_cfg_lan_txqs(struct ice_vsi * vsi)1750*4882a593Smuzhiyun int ice_vsi_cfg_lan_txqs(struct ice_vsi *vsi)
1751*4882a593Smuzhiyun {
1752*4882a593Smuzhiyun return ice_vsi_cfg_txqs(vsi, vsi->tx_rings, vsi->num_txq);
1753*4882a593Smuzhiyun }
1754*4882a593Smuzhiyun
1755*4882a593Smuzhiyun /**
1756*4882a593Smuzhiyun * ice_vsi_cfg_xdp_txqs - Configure Tx queues dedicated for XDP in given VSI
1757*4882a593Smuzhiyun * @vsi: the VSI being configured
1758*4882a593Smuzhiyun *
1759*4882a593Smuzhiyun * Return 0 on success and a negative value on error
1760*4882a593Smuzhiyun * Configure the Tx queues dedicated for XDP in given VSI for operation.
1761*4882a593Smuzhiyun */
ice_vsi_cfg_xdp_txqs(struct ice_vsi * vsi)1762*4882a593Smuzhiyun int ice_vsi_cfg_xdp_txqs(struct ice_vsi *vsi)
1763*4882a593Smuzhiyun {
1764*4882a593Smuzhiyun int ret;
1765*4882a593Smuzhiyun int i;
1766*4882a593Smuzhiyun
1767*4882a593Smuzhiyun ret = ice_vsi_cfg_txqs(vsi, vsi->xdp_rings, vsi->num_xdp_txq);
1768*4882a593Smuzhiyun if (ret)
1769*4882a593Smuzhiyun return ret;
1770*4882a593Smuzhiyun
1771*4882a593Smuzhiyun for (i = 0; i < vsi->num_xdp_txq; i++)
1772*4882a593Smuzhiyun vsi->xdp_rings[i]->xsk_pool = ice_xsk_pool(vsi->xdp_rings[i]);
1773*4882a593Smuzhiyun
1774*4882a593Smuzhiyun return ret;
1775*4882a593Smuzhiyun }
1776*4882a593Smuzhiyun
1777*4882a593Smuzhiyun /**
1778*4882a593Smuzhiyun * ice_intrl_usec_to_reg - convert interrupt rate limit to register value
1779*4882a593Smuzhiyun * @intrl: interrupt rate limit in usecs
1780*4882a593Smuzhiyun * @gran: interrupt rate limit granularity in usecs
1781*4882a593Smuzhiyun *
1782*4882a593Smuzhiyun * This function converts a decimal interrupt rate limit in usecs to the format
1783*4882a593Smuzhiyun * expected by firmware.
1784*4882a593Smuzhiyun */
ice_intrl_usec_to_reg(u8 intrl,u8 gran)1785*4882a593Smuzhiyun u32 ice_intrl_usec_to_reg(u8 intrl, u8 gran)
1786*4882a593Smuzhiyun {
1787*4882a593Smuzhiyun u32 val = intrl / gran;
1788*4882a593Smuzhiyun
1789*4882a593Smuzhiyun if (val)
1790*4882a593Smuzhiyun return val | GLINT_RATE_INTRL_ENA_M;
1791*4882a593Smuzhiyun return 0;
1792*4882a593Smuzhiyun }
1793*4882a593Smuzhiyun
1794*4882a593Smuzhiyun /**
1795*4882a593Smuzhiyun * ice_vsi_cfg_msix - MSIX mode Interrupt Config in the HW
1796*4882a593Smuzhiyun * @vsi: the VSI being configured
1797*4882a593Smuzhiyun *
1798*4882a593Smuzhiyun * This configures MSIX mode interrupts for the PF VSI, and should not be used
1799*4882a593Smuzhiyun * for the VF VSI.
1800*4882a593Smuzhiyun */
ice_vsi_cfg_msix(struct ice_vsi * vsi)1801*4882a593Smuzhiyun void ice_vsi_cfg_msix(struct ice_vsi *vsi)
1802*4882a593Smuzhiyun {
1803*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
1804*4882a593Smuzhiyun struct ice_hw *hw = &pf->hw;
1805*4882a593Smuzhiyun u16 txq = 0, rxq = 0;
1806*4882a593Smuzhiyun int i, q;
1807*4882a593Smuzhiyun
1808*4882a593Smuzhiyun for (i = 0; i < vsi->num_q_vectors; i++) {
1809*4882a593Smuzhiyun struct ice_q_vector *q_vector = vsi->q_vectors[i];
1810*4882a593Smuzhiyun u16 reg_idx = q_vector->reg_idx;
1811*4882a593Smuzhiyun
1812*4882a593Smuzhiyun ice_cfg_itr(hw, q_vector);
1813*4882a593Smuzhiyun
1814*4882a593Smuzhiyun wr32(hw, GLINT_RATE(reg_idx),
1815*4882a593Smuzhiyun ice_intrl_usec_to_reg(q_vector->intrl, hw->intrl_gran));
1816*4882a593Smuzhiyun
1817*4882a593Smuzhiyun /* Both Transmit Queue Interrupt Cause Control register
1818*4882a593Smuzhiyun * and Receive Queue Interrupt Cause control register
1819*4882a593Smuzhiyun * expects MSIX_INDX field to be the vector index
1820*4882a593Smuzhiyun * within the function space and not the absolute
1821*4882a593Smuzhiyun * vector index across PF or across device.
1822*4882a593Smuzhiyun * For SR-IOV VF VSIs queue vector index always starts
1823*4882a593Smuzhiyun * with 1 since first vector index(0) is used for OICR
1824*4882a593Smuzhiyun * in VF space. Since VMDq and other PF VSIs are within
1825*4882a593Smuzhiyun * the PF function space, use the vector index that is
1826*4882a593Smuzhiyun * tracked for this PF.
1827*4882a593Smuzhiyun */
1828*4882a593Smuzhiyun for (q = 0; q < q_vector->num_ring_tx; q++) {
1829*4882a593Smuzhiyun ice_cfg_txq_interrupt(vsi, txq, reg_idx,
1830*4882a593Smuzhiyun q_vector->tx.itr_idx);
1831*4882a593Smuzhiyun txq++;
1832*4882a593Smuzhiyun }
1833*4882a593Smuzhiyun
1834*4882a593Smuzhiyun for (q = 0; q < q_vector->num_ring_rx; q++) {
1835*4882a593Smuzhiyun ice_cfg_rxq_interrupt(vsi, rxq, reg_idx,
1836*4882a593Smuzhiyun q_vector->rx.itr_idx);
1837*4882a593Smuzhiyun rxq++;
1838*4882a593Smuzhiyun }
1839*4882a593Smuzhiyun }
1840*4882a593Smuzhiyun }
1841*4882a593Smuzhiyun
1842*4882a593Smuzhiyun /**
1843*4882a593Smuzhiyun * ice_vsi_manage_vlan_insertion - Manage VLAN insertion for the VSI for Tx
1844*4882a593Smuzhiyun * @vsi: the VSI being changed
1845*4882a593Smuzhiyun */
ice_vsi_manage_vlan_insertion(struct ice_vsi * vsi)1846*4882a593Smuzhiyun int ice_vsi_manage_vlan_insertion(struct ice_vsi *vsi)
1847*4882a593Smuzhiyun {
1848*4882a593Smuzhiyun struct ice_hw *hw = &vsi->back->hw;
1849*4882a593Smuzhiyun struct ice_vsi_ctx *ctxt;
1850*4882a593Smuzhiyun enum ice_status status;
1851*4882a593Smuzhiyun int ret = 0;
1852*4882a593Smuzhiyun
1853*4882a593Smuzhiyun ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
1854*4882a593Smuzhiyun if (!ctxt)
1855*4882a593Smuzhiyun return -ENOMEM;
1856*4882a593Smuzhiyun
1857*4882a593Smuzhiyun /* Here we are configuring the VSI to let the driver add VLAN tags by
1858*4882a593Smuzhiyun * setting vlan_flags to ICE_AQ_VSI_VLAN_MODE_ALL. The actual VLAN tag
1859*4882a593Smuzhiyun * insertion happens in the Tx hot path, in ice_tx_map.
1860*4882a593Smuzhiyun */
1861*4882a593Smuzhiyun ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_MODE_ALL;
1862*4882a593Smuzhiyun
1863*4882a593Smuzhiyun /* Preserve existing VLAN strip setting */
1864*4882a593Smuzhiyun ctxt->info.vlan_flags |= (vsi->info.vlan_flags &
1865*4882a593Smuzhiyun ICE_AQ_VSI_VLAN_EMOD_M);
1866*4882a593Smuzhiyun
1867*4882a593Smuzhiyun ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
1868*4882a593Smuzhiyun
1869*4882a593Smuzhiyun status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1870*4882a593Smuzhiyun if (status) {
1871*4882a593Smuzhiyun dev_err(ice_pf_to_dev(vsi->back), "update VSI for VLAN insert failed, err %s aq_err %s\n",
1872*4882a593Smuzhiyun ice_stat_str(status),
1873*4882a593Smuzhiyun ice_aq_str(hw->adminq.sq_last_status));
1874*4882a593Smuzhiyun ret = -EIO;
1875*4882a593Smuzhiyun goto out;
1876*4882a593Smuzhiyun }
1877*4882a593Smuzhiyun
1878*4882a593Smuzhiyun vsi->info.vlan_flags = ctxt->info.vlan_flags;
1879*4882a593Smuzhiyun out:
1880*4882a593Smuzhiyun kfree(ctxt);
1881*4882a593Smuzhiyun return ret;
1882*4882a593Smuzhiyun }
1883*4882a593Smuzhiyun
1884*4882a593Smuzhiyun /**
1885*4882a593Smuzhiyun * ice_vsi_manage_vlan_stripping - Manage VLAN stripping for the VSI for Rx
1886*4882a593Smuzhiyun * @vsi: the VSI being changed
1887*4882a593Smuzhiyun * @ena: boolean value indicating if this is a enable or disable request
1888*4882a593Smuzhiyun */
ice_vsi_manage_vlan_stripping(struct ice_vsi * vsi,bool ena)1889*4882a593Smuzhiyun int ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
1890*4882a593Smuzhiyun {
1891*4882a593Smuzhiyun struct ice_hw *hw = &vsi->back->hw;
1892*4882a593Smuzhiyun struct ice_vsi_ctx *ctxt;
1893*4882a593Smuzhiyun enum ice_status status;
1894*4882a593Smuzhiyun int ret = 0;
1895*4882a593Smuzhiyun
1896*4882a593Smuzhiyun /* do not allow modifying VLAN stripping when a port VLAN is configured
1897*4882a593Smuzhiyun * on this VSI
1898*4882a593Smuzhiyun */
1899*4882a593Smuzhiyun if (vsi->info.pvid)
1900*4882a593Smuzhiyun return 0;
1901*4882a593Smuzhiyun
1902*4882a593Smuzhiyun ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
1903*4882a593Smuzhiyun if (!ctxt)
1904*4882a593Smuzhiyun return -ENOMEM;
1905*4882a593Smuzhiyun
1906*4882a593Smuzhiyun /* Here we are configuring what the VSI should do with the VLAN tag in
1907*4882a593Smuzhiyun * the Rx packet. We can either leave the tag in the packet or put it in
1908*4882a593Smuzhiyun * the Rx descriptor.
1909*4882a593Smuzhiyun */
1910*4882a593Smuzhiyun if (ena)
1911*4882a593Smuzhiyun /* Strip VLAN tag from Rx packet and put it in the desc */
1912*4882a593Smuzhiyun ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_STR_BOTH;
1913*4882a593Smuzhiyun else
1914*4882a593Smuzhiyun /* Disable stripping. Leave tag in packet */
1915*4882a593Smuzhiyun ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_NOTHING;
1916*4882a593Smuzhiyun
1917*4882a593Smuzhiyun /* Allow all packets untagged/tagged */
1918*4882a593Smuzhiyun ctxt->info.vlan_flags |= ICE_AQ_VSI_VLAN_MODE_ALL;
1919*4882a593Smuzhiyun
1920*4882a593Smuzhiyun ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
1921*4882a593Smuzhiyun
1922*4882a593Smuzhiyun status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
1923*4882a593Smuzhiyun if (status) {
1924*4882a593Smuzhiyun dev_err(ice_pf_to_dev(vsi->back), "update VSI for VLAN strip failed, ena = %d err %s aq_err %s\n",
1925*4882a593Smuzhiyun ena, ice_stat_str(status),
1926*4882a593Smuzhiyun ice_aq_str(hw->adminq.sq_last_status));
1927*4882a593Smuzhiyun ret = -EIO;
1928*4882a593Smuzhiyun goto out;
1929*4882a593Smuzhiyun }
1930*4882a593Smuzhiyun
1931*4882a593Smuzhiyun vsi->info.vlan_flags = ctxt->info.vlan_flags;
1932*4882a593Smuzhiyun out:
1933*4882a593Smuzhiyun kfree(ctxt);
1934*4882a593Smuzhiyun return ret;
1935*4882a593Smuzhiyun }
1936*4882a593Smuzhiyun
1937*4882a593Smuzhiyun /**
1938*4882a593Smuzhiyun * ice_vsi_start_all_rx_rings - start/enable all of a VSI's Rx rings
1939*4882a593Smuzhiyun * @vsi: the VSI whose rings are to be enabled
1940*4882a593Smuzhiyun *
1941*4882a593Smuzhiyun * Returns 0 on success and a negative value on error
1942*4882a593Smuzhiyun */
ice_vsi_start_all_rx_rings(struct ice_vsi * vsi)1943*4882a593Smuzhiyun int ice_vsi_start_all_rx_rings(struct ice_vsi *vsi)
1944*4882a593Smuzhiyun {
1945*4882a593Smuzhiyun return ice_vsi_ctrl_all_rx_rings(vsi, true);
1946*4882a593Smuzhiyun }
1947*4882a593Smuzhiyun
1948*4882a593Smuzhiyun /**
1949*4882a593Smuzhiyun * ice_vsi_stop_all_rx_rings - stop/disable all of a VSI's Rx rings
1950*4882a593Smuzhiyun * @vsi: the VSI whose rings are to be disabled
1951*4882a593Smuzhiyun *
1952*4882a593Smuzhiyun * Returns 0 on success and a negative value on error
1953*4882a593Smuzhiyun */
ice_vsi_stop_all_rx_rings(struct ice_vsi * vsi)1954*4882a593Smuzhiyun int ice_vsi_stop_all_rx_rings(struct ice_vsi *vsi)
1955*4882a593Smuzhiyun {
1956*4882a593Smuzhiyun return ice_vsi_ctrl_all_rx_rings(vsi, false);
1957*4882a593Smuzhiyun }
1958*4882a593Smuzhiyun
1959*4882a593Smuzhiyun /**
1960*4882a593Smuzhiyun * ice_vsi_stop_tx_rings - Disable Tx rings
1961*4882a593Smuzhiyun * @vsi: the VSI being configured
1962*4882a593Smuzhiyun * @rst_src: reset source
1963*4882a593Smuzhiyun * @rel_vmvf_num: Relative ID of VF/VM
1964*4882a593Smuzhiyun * @rings: Tx ring array to be stopped
1965*4882a593Smuzhiyun * @count: number of Tx ring array elements
1966*4882a593Smuzhiyun */
1967*4882a593Smuzhiyun static int
ice_vsi_stop_tx_rings(struct ice_vsi * vsi,enum ice_disq_rst_src rst_src,u16 rel_vmvf_num,struct ice_ring ** rings,u16 count)1968*4882a593Smuzhiyun ice_vsi_stop_tx_rings(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
1969*4882a593Smuzhiyun u16 rel_vmvf_num, struct ice_ring **rings, u16 count)
1970*4882a593Smuzhiyun {
1971*4882a593Smuzhiyun u16 q_idx;
1972*4882a593Smuzhiyun
1973*4882a593Smuzhiyun if (vsi->num_txq > ICE_LAN_TXQ_MAX_QDIS)
1974*4882a593Smuzhiyun return -EINVAL;
1975*4882a593Smuzhiyun
1976*4882a593Smuzhiyun for (q_idx = 0; q_idx < count; q_idx++) {
1977*4882a593Smuzhiyun struct ice_txq_meta txq_meta = { };
1978*4882a593Smuzhiyun int status;
1979*4882a593Smuzhiyun
1980*4882a593Smuzhiyun if (!rings || !rings[q_idx])
1981*4882a593Smuzhiyun return -EINVAL;
1982*4882a593Smuzhiyun
1983*4882a593Smuzhiyun ice_fill_txq_meta(vsi, rings[q_idx], &txq_meta);
1984*4882a593Smuzhiyun status = ice_vsi_stop_tx_ring(vsi, rst_src, rel_vmvf_num,
1985*4882a593Smuzhiyun rings[q_idx], &txq_meta);
1986*4882a593Smuzhiyun
1987*4882a593Smuzhiyun if (status)
1988*4882a593Smuzhiyun return status;
1989*4882a593Smuzhiyun }
1990*4882a593Smuzhiyun
1991*4882a593Smuzhiyun return 0;
1992*4882a593Smuzhiyun }
1993*4882a593Smuzhiyun
1994*4882a593Smuzhiyun /**
1995*4882a593Smuzhiyun * ice_vsi_stop_lan_tx_rings - Disable LAN Tx rings
1996*4882a593Smuzhiyun * @vsi: the VSI being configured
1997*4882a593Smuzhiyun * @rst_src: reset source
1998*4882a593Smuzhiyun * @rel_vmvf_num: Relative ID of VF/VM
1999*4882a593Smuzhiyun */
2000*4882a593Smuzhiyun int
ice_vsi_stop_lan_tx_rings(struct ice_vsi * vsi,enum ice_disq_rst_src rst_src,u16 rel_vmvf_num)2001*4882a593Smuzhiyun ice_vsi_stop_lan_tx_rings(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
2002*4882a593Smuzhiyun u16 rel_vmvf_num)
2003*4882a593Smuzhiyun {
2004*4882a593Smuzhiyun return ice_vsi_stop_tx_rings(vsi, rst_src, rel_vmvf_num, vsi->tx_rings, vsi->num_txq);
2005*4882a593Smuzhiyun }
2006*4882a593Smuzhiyun
2007*4882a593Smuzhiyun /**
2008*4882a593Smuzhiyun * ice_vsi_stop_xdp_tx_rings - Disable XDP Tx rings
2009*4882a593Smuzhiyun * @vsi: the VSI being configured
2010*4882a593Smuzhiyun */
ice_vsi_stop_xdp_tx_rings(struct ice_vsi * vsi)2011*4882a593Smuzhiyun int ice_vsi_stop_xdp_tx_rings(struct ice_vsi *vsi)
2012*4882a593Smuzhiyun {
2013*4882a593Smuzhiyun return ice_vsi_stop_tx_rings(vsi, ICE_NO_RESET, 0, vsi->xdp_rings, vsi->num_xdp_txq);
2014*4882a593Smuzhiyun }
2015*4882a593Smuzhiyun
2016*4882a593Smuzhiyun /**
2017*4882a593Smuzhiyun * ice_vsi_is_vlan_pruning_ena - check if VLAN pruning is enabled or not
2018*4882a593Smuzhiyun * @vsi: VSI to check whether or not VLAN pruning is enabled.
2019*4882a593Smuzhiyun *
2020*4882a593Smuzhiyun * returns true if Rx VLAN pruning is enabled and false otherwise.
2021*4882a593Smuzhiyun */
ice_vsi_is_vlan_pruning_ena(struct ice_vsi * vsi)2022*4882a593Smuzhiyun bool ice_vsi_is_vlan_pruning_ena(struct ice_vsi *vsi)
2023*4882a593Smuzhiyun {
2024*4882a593Smuzhiyun if (!vsi)
2025*4882a593Smuzhiyun return false;
2026*4882a593Smuzhiyun
2027*4882a593Smuzhiyun return (vsi->info.sw_flags2 & ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA);
2028*4882a593Smuzhiyun }
2029*4882a593Smuzhiyun
2030*4882a593Smuzhiyun /**
2031*4882a593Smuzhiyun * ice_cfg_vlan_pruning - enable or disable VLAN pruning on the VSI
2032*4882a593Smuzhiyun * @vsi: VSI to enable or disable VLAN pruning on
2033*4882a593Smuzhiyun * @ena: set to true to enable VLAN pruning and false to disable it
2034*4882a593Smuzhiyun * @vlan_promisc: enable valid security flags if not in VLAN promiscuous mode
2035*4882a593Smuzhiyun *
2036*4882a593Smuzhiyun * returns 0 if VSI is updated, negative otherwise
2037*4882a593Smuzhiyun */
ice_cfg_vlan_pruning(struct ice_vsi * vsi,bool ena,bool vlan_promisc)2038*4882a593Smuzhiyun int ice_cfg_vlan_pruning(struct ice_vsi *vsi, bool ena, bool vlan_promisc)
2039*4882a593Smuzhiyun {
2040*4882a593Smuzhiyun struct ice_vsi_ctx *ctxt;
2041*4882a593Smuzhiyun struct ice_pf *pf;
2042*4882a593Smuzhiyun int status;
2043*4882a593Smuzhiyun
2044*4882a593Smuzhiyun if (!vsi)
2045*4882a593Smuzhiyun return -EINVAL;
2046*4882a593Smuzhiyun
2047*4882a593Smuzhiyun /* Don't enable VLAN pruning if the netdev is currently in promiscuous
2048*4882a593Smuzhiyun * mode. VLAN pruning will be enabled when the interface exits
2049*4882a593Smuzhiyun * promiscuous mode if any VLAN filters are active.
2050*4882a593Smuzhiyun */
2051*4882a593Smuzhiyun if (vsi->netdev && vsi->netdev->flags & IFF_PROMISC && ena)
2052*4882a593Smuzhiyun return 0;
2053*4882a593Smuzhiyun
2054*4882a593Smuzhiyun pf = vsi->back;
2055*4882a593Smuzhiyun ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
2056*4882a593Smuzhiyun if (!ctxt)
2057*4882a593Smuzhiyun return -ENOMEM;
2058*4882a593Smuzhiyun
2059*4882a593Smuzhiyun ctxt->info = vsi->info;
2060*4882a593Smuzhiyun
2061*4882a593Smuzhiyun if (ena)
2062*4882a593Smuzhiyun ctxt->info.sw_flags2 |= ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
2063*4882a593Smuzhiyun else
2064*4882a593Smuzhiyun ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
2065*4882a593Smuzhiyun
2066*4882a593Smuzhiyun if (!vlan_promisc)
2067*4882a593Smuzhiyun ctxt->info.valid_sections =
2068*4882a593Smuzhiyun cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
2069*4882a593Smuzhiyun
2070*4882a593Smuzhiyun status = ice_update_vsi(&pf->hw, vsi->idx, ctxt, NULL);
2071*4882a593Smuzhiyun if (status) {
2072*4882a593Smuzhiyun netdev_err(vsi->netdev, "%sabling VLAN pruning on VSI handle: %d, VSI HW ID: %d failed, err = %s, aq_err = %s\n",
2073*4882a593Smuzhiyun ena ? "En" : "Dis", vsi->idx, vsi->vsi_num,
2074*4882a593Smuzhiyun ice_stat_str(status),
2075*4882a593Smuzhiyun ice_aq_str(pf->hw.adminq.sq_last_status));
2076*4882a593Smuzhiyun goto err_out;
2077*4882a593Smuzhiyun }
2078*4882a593Smuzhiyun
2079*4882a593Smuzhiyun vsi->info.sw_flags2 = ctxt->info.sw_flags2;
2080*4882a593Smuzhiyun
2081*4882a593Smuzhiyun kfree(ctxt);
2082*4882a593Smuzhiyun return 0;
2083*4882a593Smuzhiyun
2084*4882a593Smuzhiyun err_out:
2085*4882a593Smuzhiyun kfree(ctxt);
2086*4882a593Smuzhiyun return -EIO;
2087*4882a593Smuzhiyun }
2088*4882a593Smuzhiyun
ice_vsi_set_tc_cfg(struct ice_vsi * vsi)2089*4882a593Smuzhiyun static void ice_vsi_set_tc_cfg(struct ice_vsi *vsi)
2090*4882a593Smuzhiyun {
2091*4882a593Smuzhiyun struct ice_dcbx_cfg *cfg = &vsi->port_info->qos_cfg.local_dcbx_cfg;
2092*4882a593Smuzhiyun
2093*4882a593Smuzhiyun vsi->tc_cfg.ena_tc = ice_dcb_get_ena_tc(cfg);
2094*4882a593Smuzhiyun vsi->tc_cfg.numtc = ice_dcb_get_num_tc(cfg);
2095*4882a593Smuzhiyun }
2096*4882a593Smuzhiyun
2097*4882a593Smuzhiyun /**
2098*4882a593Smuzhiyun * ice_vsi_set_q_vectors_reg_idx - set the HW register index for all q_vectors
2099*4882a593Smuzhiyun * @vsi: VSI to set the q_vectors register index on
2100*4882a593Smuzhiyun */
2101*4882a593Smuzhiyun static int
ice_vsi_set_q_vectors_reg_idx(struct ice_vsi * vsi)2102*4882a593Smuzhiyun ice_vsi_set_q_vectors_reg_idx(struct ice_vsi *vsi)
2103*4882a593Smuzhiyun {
2104*4882a593Smuzhiyun u16 i;
2105*4882a593Smuzhiyun
2106*4882a593Smuzhiyun if (!vsi || !vsi->q_vectors)
2107*4882a593Smuzhiyun return -EINVAL;
2108*4882a593Smuzhiyun
2109*4882a593Smuzhiyun ice_for_each_q_vector(vsi, i) {
2110*4882a593Smuzhiyun struct ice_q_vector *q_vector = vsi->q_vectors[i];
2111*4882a593Smuzhiyun
2112*4882a593Smuzhiyun if (!q_vector) {
2113*4882a593Smuzhiyun dev_err(ice_pf_to_dev(vsi->back), "Failed to set reg_idx on q_vector %d VSI %d\n",
2114*4882a593Smuzhiyun i, vsi->vsi_num);
2115*4882a593Smuzhiyun goto clear_reg_idx;
2116*4882a593Smuzhiyun }
2117*4882a593Smuzhiyun
2118*4882a593Smuzhiyun if (vsi->type == ICE_VSI_VF) {
2119*4882a593Smuzhiyun struct ice_vf *vf = &vsi->back->vf[vsi->vf_id];
2120*4882a593Smuzhiyun
2121*4882a593Smuzhiyun q_vector->reg_idx = ice_calc_vf_reg_idx(vf, q_vector);
2122*4882a593Smuzhiyun } else {
2123*4882a593Smuzhiyun q_vector->reg_idx =
2124*4882a593Smuzhiyun q_vector->v_idx + vsi->base_vector;
2125*4882a593Smuzhiyun }
2126*4882a593Smuzhiyun }
2127*4882a593Smuzhiyun
2128*4882a593Smuzhiyun return 0;
2129*4882a593Smuzhiyun
2130*4882a593Smuzhiyun clear_reg_idx:
2131*4882a593Smuzhiyun ice_for_each_q_vector(vsi, i) {
2132*4882a593Smuzhiyun struct ice_q_vector *q_vector = vsi->q_vectors[i];
2133*4882a593Smuzhiyun
2134*4882a593Smuzhiyun if (q_vector)
2135*4882a593Smuzhiyun q_vector->reg_idx = 0;
2136*4882a593Smuzhiyun }
2137*4882a593Smuzhiyun
2138*4882a593Smuzhiyun return -EINVAL;
2139*4882a593Smuzhiyun }
2140*4882a593Smuzhiyun
2141*4882a593Smuzhiyun /**
2142*4882a593Smuzhiyun * ice_cfg_sw_lldp - Config switch rules for LLDP packet handling
2143*4882a593Smuzhiyun * @vsi: the VSI being configured
2144*4882a593Smuzhiyun * @tx: bool to determine Tx or Rx rule
2145*4882a593Smuzhiyun * @create: bool to determine create or remove Rule
2146*4882a593Smuzhiyun */
ice_cfg_sw_lldp(struct ice_vsi * vsi,bool tx,bool create)2147*4882a593Smuzhiyun void ice_cfg_sw_lldp(struct ice_vsi *vsi, bool tx, bool create)
2148*4882a593Smuzhiyun {
2149*4882a593Smuzhiyun enum ice_status (*eth_fltr)(struct ice_vsi *v, u16 type, u16 flag,
2150*4882a593Smuzhiyun enum ice_sw_fwd_act_type act);
2151*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
2152*4882a593Smuzhiyun enum ice_status status;
2153*4882a593Smuzhiyun struct device *dev;
2154*4882a593Smuzhiyun
2155*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
2156*4882a593Smuzhiyun eth_fltr = create ? ice_fltr_add_eth : ice_fltr_remove_eth;
2157*4882a593Smuzhiyun
2158*4882a593Smuzhiyun if (tx)
2159*4882a593Smuzhiyun status = eth_fltr(vsi, ETH_P_LLDP, ICE_FLTR_TX,
2160*4882a593Smuzhiyun ICE_DROP_PACKET);
2161*4882a593Smuzhiyun else
2162*4882a593Smuzhiyun status = eth_fltr(vsi, ETH_P_LLDP, ICE_FLTR_RX, ICE_FWD_TO_VSI);
2163*4882a593Smuzhiyun
2164*4882a593Smuzhiyun if (status)
2165*4882a593Smuzhiyun dev_err(dev, "Fail %s %s LLDP rule on VSI %i error: %s\n",
2166*4882a593Smuzhiyun create ? "adding" : "removing", tx ? "TX" : "RX",
2167*4882a593Smuzhiyun vsi->vsi_num, ice_stat_str(status));
2168*4882a593Smuzhiyun }
2169*4882a593Smuzhiyun
2170*4882a593Smuzhiyun /**
2171*4882a593Smuzhiyun * ice_vsi_setup - Set up a VSI by a given type
2172*4882a593Smuzhiyun * @pf: board private structure
2173*4882a593Smuzhiyun * @pi: pointer to the port_info instance
2174*4882a593Smuzhiyun * @vsi_type: VSI type
2175*4882a593Smuzhiyun * @vf_id: defines VF ID to which this VSI connects. This field is meant to be
2176*4882a593Smuzhiyun * used only for ICE_VSI_VF VSI type. For other VSI types, should
2177*4882a593Smuzhiyun * fill-in ICE_INVAL_VFID as input.
2178*4882a593Smuzhiyun *
2179*4882a593Smuzhiyun * This allocates the sw VSI structure and its queue resources.
2180*4882a593Smuzhiyun *
2181*4882a593Smuzhiyun * Returns pointer to the successfully allocated and configured VSI sw struct on
2182*4882a593Smuzhiyun * success, NULL on failure.
2183*4882a593Smuzhiyun */
2184*4882a593Smuzhiyun struct ice_vsi *
ice_vsi_setup(struct ice_pf * pf,struct ice_port_info * pi,enum ice_vsi_type vsi_type,u16 vf_id)2185*4882a593Smuzhiyun ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
2186*4882a593Smuzhiyun enum ice_vsi_type vsi_type, u16 vf_id)
2187*4882a593Smuzhiyun {
2188*4882a593Smuzhiyun u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2189*4882a593Smuzhiyun struct device *dev = ice_pf_to_dev(pf);
2190*4882a593Smuzhiyun enum ice_status status;
2191*4882a593Smuzhiyun struct ice_vsi *vsi;
2192*4882a593Smuzhiyun int ret, i;
2193*4882a593Smuzhiyun
2194*4882a593Smuzhiyun if (vsi_type == ICE_VSI_VF)
2195*4882a593Smuzhiyun vsi = ice_vsi_alloc(pf, vsi_type, vf_id);
2196*4882a593Smuzhiyun else
2197*4882a593Smuzhiyun vsi = ice_vsi_alloc(pf, vsi_type, ICE_INVAL_VFID);
2198*4882a593Smuzhiyun
2199*4882a593Smuzhiyun if (!vsi) {
2200*4882a593Smuzhiyun dev_err(dev, "could not allocate VSI\n");
2201*4882a593Smuzhiyun return NULL;
2202*4882a593Smuzhiyun }
2203*4882a593Smuzhiyun
2204*4882a593Smuzhiyun vsi->port_info = pi;
2205*4882a593Smuzhiyun vsi->vsw = pf->first_sw;
2206*4882a593Smuzhiyun if (vsi->type == ICE_VSI_PF)
2207*4882a593Smuzhiyun vsi->ethtype = ETH_P_PAUSE;
2208*4882a593Smuzhiyun
2209*4882a593Smuzhiyun if (vsi->type == ICE_VSI_VF)
2210*4882a593Smuzhiyun vsi->vf_id = vf_id;
2211*4882a593Smuzhiyun
2212*4882a593Smuzhiyun ice_alloc_fd_res(vsi);
2213*4882a593Smuzhiyun
2214*4882a593Smuzhiyun if (ice_vsi_get_qs(vsi)) {
2215*4882a593Smuzhiyun dev_err(dev, "Failed to allocate queues. vsi->idx = %d\n",
2216*4882a593Smuzhiyun vsi->idx);
2217*4882a593Smuzhiyun goto unroll_vsi_alloc;
2218*4882a593Smuzhiyun }
2219*4882a593Smuzhiyun
2220*4882a593Smuzhiyun /* set RSS capabilities */
2221*4882a593Smuzhiyun ice_vsi_set_rss_params(vsi);
2222*4882a593Smuzhiyun
2223*4882a593Smuzhiyun /* set TC configuration */
2224*4882a593Smuzhiyun ice_vsi_set_tc_cfg(vsi);
2225*4882a593Smuzhiyun
2226*4882a593Smuzhiyun /* create the VSI */
2227*4882a593Smuzhiyun ret = ice_vsi_init(vsi, true);
2228*4882a593Smuzhiyun if (ret)
2229*4882a593Smuzhiyun goto unroll_get_qs;
2230*4882a593Smuzhiyun
2231*4882a593Smuzhiyun switch (vsi->type) {
2232*4882a593Smuzhiyun case ICE_VSI_CTRL:
2233*4882a593Smuzhiyun case ICE_VSI_PF:
2234*4882a593Smuzhiyun ret = ice_vsi_alloc_q_vectors(vsi);
2235*4882a593Smuzhiyun if (ret)
2236*4882a593Smuzhiyun goto unroll_vsi_init;
2237*4882a593Smuzhiyun
2238*4882a593Smuzhiyun ret = ice_vsi_setup_vector_base(vsi);
2239*4882a593Smuzhiyun if (ret)
2240*4882a593Smuzhiyun goto unroll_alloc_q_vector;
2241*4882a593Smuzhiyun
2242*4882a593Smuzhiyun ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2243*4882a593Smuzhiyun if (ret)
2244*4882a593Smuzhiyun goto unroll_vector_base;
2245*4882a593Smuzhiyun
2246*4882a593Smuzhiyun ret = ice_vsi_alloc_rings(vsi);
2247*4882a593Smuzhiyun if (ret)
2248*4882a593Smuzhiyun goto unroll_vector_base;
2249*4882a593Smuzhiyun
2250*4882a593Smuzhiyun /* Always add VLAN ID 0 switch rule by default. This is needed
2251*4882a593Smuzhiyun * in order to allow all untagged and 0 tagged priority traffic
2252*4882a593Smuzhiyun * if Rx VLAN pruning is enabled. Also there are cases where we
2253*4882a593Smuzhiyun * don't get the call to add VLAN 0 via ice_vlan_rx_add_vid()
2254*4882a593Smuzhiyun * so this handles those cases (i.e. adding the PF to a bridge
2255*4882a593Smuzhiyun * without the 8021q module loaded).
2256*4882a593Smuzhiyun */
2257*4882a593Smuzhiyun ret = ice_vsi_add_vlan(vsi, 0, ICE_FWD_TO_VSI);
2258*4882a593Smuzhiyun if (ret)
2259*4882a593Smuzhiyun goto unroll_clear_rings;
2260*4882a593Smuzhiyun
2261*4882a593Smuzhiyun ice_vsi_map_rings_to_vectors(vsi);
2262*4882a593Smuzhiyun
2263*4882a593Smuzhiyun /* ICE_VSI_CTRL does not need RSS so skip RSS processing */
2264*4882a593Smuzhiyun if (vsi->type != ICE_VSI_CTRL)
2265*4882a593Smuzhiyun /* Do not exit if configuring RSS had an issue, at
2266*4882a593Smuzhiyun * least receive traffic on first queue. Hence no
2267*4882a593Smuzhiyun * need to capture return value
2268*4882a593Smuzhiyun */
2269*4882a593Smuzhiyun if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
2270*4882a593Smuzhiyun ice_vsi_cfg_rss_lut_key(vsi);
2271*4882a593Smuzhiyun ice_vsi_set_rss_flow_fld(vsi);
2272*4882a593Smuzhiyun }
2273*4882a593Smuzhiyun ice_init_arfs(vsi);
2274*4882a593Smuzhiyun break;
2275*4882a593Smuzhiyun case ICE_VSI_VF:
2276*4882a593Smuzhiyun /* VF driver will take care of creating netdev for this type and
2277*4882a593Smuzhiyun * map queues to vectors through Virtchnl, PF driver only
2278*4882a593Smuzhiyun * creates a VSI and corresponding structures for bookkeeping
2279*4882a593Smuzhiyun * purpose
2280*4882a593Smuzhiyun */
2281*4882a593Smuzhiyun ret = ice_vsi_alloc_q_vectors(vsi);
2282*4882a593Smuzhiyun if (ret)
2283*4882a593Smuzhiyun goto unroll_vsi_init;
2284*4882a593Smuzhiyun
2285*4882a593Smuzhiyun ret = ice_vsi_alloc_rings(vsi);
2286*4882a593Smuzhiyun if (ret)
2287*4882a593Smuzhiyun goto unroll_alloc_q_vector;
2288*4882a593Smuzhiyun
2289*4882a593Smuzhiyun ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2290*4882a593Smuzhiyun if (ret)
2291*4882a593Smuzhiyun goto unroll_vector_base;
2292*4882a593Smuzhiyun
2293*4882a593Smuzhiyun /* Do not exit if configuring RSS had an issue, at least
2294*4882a593Smuzhiyun * receive traffic on first queue. Hence no need to capture
2295*4882a593Smuzhiyun * return value
2296*4882a593Smuzhiyun */
2297*4882a593Smuzhiyun if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
2298*4882a593Smuzhiyun ice_vsi_cfg_rss_lut_key(vsi);
2299*4882a593Smuzhiyun ice_vsi_set_vf_rss_flow_fld(vsi);
2300*4882a593Smuzhiyun }
2301*4882a593Smuzhiyun break;
2302*4882a593Smuzhiyun case ICE_VSI_LB:
2303*4882a593Smuzhiyun ret = ice_vsi_alloc_rings(vsi);
2304*4882a593Smuzhiyun if (ret)
2305*4882a593Smuzhiyun goto unroll_vsi_init;
2306*4882a593Smuzhiyun break;
2307*4882a593Smuzhiyun default:
2308*4882a593Smuzhiyun /* clean up the resources and exit */
2309*4882a593Smuzhiyun goto unroll_vsi_init;
2310*4882a593Smuzhiyun }
2311*4882a593Smuzhiyun
2312*4882a593Smuzhiyun /* configure VSI nodes based on number of queues and TC's */
2313*4882a593Smuzhiyun for (i = 0; i < vsi->tc_cfg.numtc; i++)
2314*4882a593Smuzhiyun max_txqs[i] = vsi->alloc_txq;
2315*4882a593Smuzhiyun
2316*4882a593Smuzhiyun status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2317*4882a593Smuzhiyun max_txqs);
2318*4882a593Smuzhiyun if (status) {
2319*4882a593Smuzhiyun dev_err(dev, "VSI %d failed lan queue config, error %s\n",
2320*4882a593Smuzhiyun vsi->vsi_num, ice_stat_str(status));
2321*4882a593Smuzhiyun goto unroll_clear_rings;
2322*4882a593Smuzhiyun }
2323*4882a593Smuzhiyun
2324*4882a593Smuzhiyun /* Add switch rule to drop all Tx Flow Control Frames, of look up
2325*4882a593Smuzhiyun * type ETHERTYPE from VSIs, and restrict malicious VF from sending
2326*4882a593Smuzhiyun * out PAUSE or PFC frames. If enabled, FW can still send FC frames.
2327*4882a593Smuzhiyun * The rule is added once for PF VSI in order to create appropriate
2328*4882a593Smuzhiyun * recipe, since VSI/VSI list is ignored with drop action...
2329*4882a593Smuzhiyun * Also add rules to handle LLDP Tx packets. Tx LLDP packets need to
2330*4882a593Smuzhiyun * be dropped so that VFs cannot send LLDP packets to reconfig DCB
2331*4882a593Smuzhiyun * settings in the HW.
2332*4882a593Smuzhiyun */
2333*4882a593Smuzhiyun if (!ice_is_safe_mode(pf))
2334*4882a593Smuzhiyun if (vsi->type == ICE_VSI_PF) {
2335*4882a593Smuzhiyun ice_fltr_add_eth(vsi, ETH_P_PAUSE, ICE_FLTR_TX,
2336*4882a593Smuzhiyun ICE_DROP_PACKET);
2337*4882a593Smuzhiyun ice_cfg_sw_lldp(vsi, true, true);
2338*4882a593Smuzhiyun }
2339*4882a593Smuzhiyun
2340*4882a593Smuzhiyun return vsi;
2341*4882a593Smuzhiyun
2342*4882a593Smuzhiyun unroll_clear_rings:
2343*4882a593Smuzhiyun ice_vsi_clear_rings(vsi);
2344*4882a593Smuzhiyun unroll_vector_base:
2345*4882a593Smuzhiyun /* reclaim SW interrupts back to the common pool */
2346*4882a593Smuzhiyun ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
2347*4882a593Smuzhiyun pf->num_avail_sw_msix += vsi->num_q_vectors;
2348*4882a593Smuzhiyun unroll_alloc_q_vector:
2349*4882a593Smuzhiyun ice_vsi_free_q_vectors(vsi);
2350*4882a593Smuzhiyun unroll_vsi_init:
2351*4882a593Smuzhiyun ice_vsi_delete(vsi);
2352*4882a593Smuzhiyun unroll_get_qs:
2353*4882a593Smuzhiyun ice_vsi_put_qs(vsi);
2354*4882a593Smuzhiyun unroll_vsi_alloc:
2355*4882a593Smuzhiyun ice_vsi_clear(vsi);
2356*4882a593Smuzhiyun
2357*4882a593Smuzhiyun return NULL;
2358*4882a593Smuzhiyun }
2359*4882a593Smuzhiyun
2360*4882a593Smuzhiyun /**
2361*4882a593Smuzhiyun * ice_vsi_release_msix - Clear the queue to Interrupt mapping in HW
2362*4882a593Smuzhiyun * @vsi: the VSI being cleaned up
2363*4882a593Smuzhiyun */
ice_vsi_release_msix(struct ice_vsi * vsi)2364*4882a593Smuzhiyun static void ice_vsi_release_msix(struct ice_vsi *vsi)
2365*4882a593Smuzhiyun {
2366*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
2367*4882a593Smuzhiyun struct ice_hw *hw = &pf->hw;
2368*4882a593Smuzhiyun u32 txq = 0;
2369*4882a593Smuzhiyun u32 rxq = 0;
2370*4882a593Smuzhiyun int i, q;
2371*4882a593Smuzhiyun
2372*4882a593Smuzhiyun for (i = 0; i < vsi->num_q_vectors; i++) {
2373*4882a593Smuzhiyun struct ice_q_vector *q_vector = vsi->q_vectors[i];
2374*4882a593Smuzhiyun u16 reg_idx = q_vector->reg_idx;
2375*4882a593Smuzhiyun
2376*4882a593Smuzhiyun wr32(hw, GLINT_ITR(ICE_IDX_ITR0, reg_idx), 0);
2377*4882a593Smuzhiyun wr32(hw, GLINT_ITR(ICE_IDX_ITR1, reg_idx), 0);
2378*4882a593Smuzhiyun for (q = 0; q < q_vector->num_ring_tx; q++) {
2379*4882a593Smuzhiyun wr32(hw, QINT_TQCTL(vsi->txq_map[txq]), 0);
2380*4882a593Smuzhiyun if (ice_is_xdp_ena_vsi(vsi)) {
2381*4882a593Smuzhiyun u32 xdp_txq = txq + vsi->num_xdp_txq;
2382*4882a593Smuzhiyun
2383*4882a593Smuzhiyun wr32(hw, QINT_TQCTL(vsi->txq_map[xdp_txq]), 0);
2384*4882a593Smuzhiyun }
2385*4882a593Smuzhiyun txq++;
2386*4882a593Smuzhiyun }
2387*4882a593Smuzhiyun
2388*4882a593Smuzhiyun for (q = 0; q < q_vector->num_ring_rx; q++) {
2389*4882a593Smuzhiyun wr32(hw, QINT_RQCTL(vsi->rxq_map[rxq]), 0);
2390*4882a593Smuzhiyun rxq++;
2391*4882a593Smuzhiyun }
2392*4882a593Smuzhiyun }
2393*4882a593Smuzhiyun
2394*4882a593Smuzhiyun ice_flush(hw);
2395*4882a593Smuzhiyun }
2396*4882a593Smuzhiyun
2397*4882a593Smuzhiyun /**
2398*4882a593Smuzhiyun * ice_vsi_free_irq - Free the IRQ association with the OS
2399*4882a593Smuzhiyun * @vsi: the VSI being configured
2400*4882a593Smuzhiyun */
ice_vsi_free_irq(struct ice_vsi * vsi)2401*4882a593Smuzhiyun void ice_vsi_free_irq(struct ice_vsi *vsi)
2402*4882a593Smuzhiyun {
2403*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
2404*4882a593Smuzhiyun int base = vsi->base_vector;
2405*4882a593Smuzhiyun int i;
2406*4882a593Smuzhiyun
2407*4882a593Smuzhiyun if (!vsi->q_vectors || !vsi->irqs_ready)
2408*4882a593Smuzhiyun return;
2409*4882a593Smuzhiyun
2410*4882a593Smuzhiyun ice_vsi_release_msix(vsi);
2411*4882a593Smuzhiyun if (vsi->type == ICE_VSI_VF)
2412*4882a593Smuzhiyun return;
2413*4882a593Smuzhiyun
2414*4882a593Smuzhiyun vsi->irqs_ready = false;
2415*4882a593Smuzhiyun ice_for_each_q_vector(vsi, i) {
2416*4882a593Smuzhiyun u16 vector = i + base;
2417*4882a593Smuzhiyun int irq_num;
2418*4882a593Smuzhiyun
2419*4882a593Smuzhiyun irq_num = pf->msix_entries[vector].vector;
2420*4882a593Smuzhiyun
2421*4882a593Smuzhiyun /* free only the irqs that were actually requested */
2422*4882a593Smuzhiyun if (!vsi->q_vectors[i] ||
2423*4882a593Smuzhiyun !(vsi->q_vectors[i]->num_ring_tx ||
2424*4882a593Smuzhiyun vsi->q_vectors[i]->num_ring_rx))
2425*4882a593Smuzhiyun continue;
2426*4882a593Smuzhiyun
2427*4882a593Smuzhiyun /* clear the affinity notifier in the IRQ descriptor */
2428*4882a593Smuzhiyun irq_set_affinity_notifier(irq_num, NULL);
2429*4882a593Smuzhiyun
2430*4882a593Smuzhiyun /* clear the affinity_mask in the IRQ descriptor */
2431*4882a593Smuzhiyun irq_set_affinity_hint(irq_num, NULL);
2432*4882a593Smuzhiyun synchronize_irq(irq_num);
2433*4882a593Smuzhiyun devm_free_irq(ice_pf_to_dev(pf), irq_num, vsi->q_vectors[i]);
2434*4882a593Smuzhiyun }
2435*4882a593Smuzhiyun }
2436*4882a593Smuzhiyun
2437*4882a593Smuzhiyun /**
2438*4882a593Smuzhiyun * ice_vsi_free_tx_rings - Free Tx resources for VSI queues
2439*4882a593Smuzhiyun * @vsi: the VSI having resources freed
2440*4882a593Smuzhiyun */
ice_vsi_free_tx_rings(struct ice_vsi * vsi)2441*4882a593Smuzhiyun void ice_vsi_free_tx_rings(struct ice_vsi *vsi)
2442*4882a593Smuzhiyun {
2443*4882a593Smuzhiyun int i;
2444*4882a593Smuzhiyun
2445*4882a593Smuzhiyun if (!vsi->tx_rings)
2446*4882a593Smuzhiyun return;
2447*4882a593Smuzhiyun
2448*4882a593Smuzhiyun ice_for_each_txq(vsi, i)
2449*4882a593Smuzhiyun if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
2450*4882a593Smuzhiyun ice_free_tx_ring(vsi->tx_rings[i]);
2451*4882a593Smuzhiyun }
2452*4882a593Smuzhiyun
2453*4882a593Smuzhiyun /**
2454*4882a593Smuzhiyun * ice_vsi_free_rx_rings - Free Rx resources for VSI queues
2455*4882a593Smuzhiyun * @vsi: the VSI having resources freed
2456*4882a593Smuzhiyun */
ice_vsi_free_rx_rings(struct ice_vsi * vsi)2457*4882a593Smuzhiyun void ice_vsi_free_rx_rings(struct ice_vsi *vsi)
2458*4882a593Smuzhiyun {
2459*4882a593Smuzhiyun int i;
2460*4882a593Smuzhiyun
2461*4882a593Smuzhiyun if (!vsi->rx_rings)
2462*4882a593Smuzhiyun return;
2463*4882a593Smuzhiyun
2464*4882a593Smuzhiyun ice_for_each_rxq(vsi, i)
2465*4882a593Smuzhiyun if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
2466*4882a593Smuzhiyun ice_free_rx_ring(vsi->rx_rings[i]);
2467*4882a593Smuzhiyun }
2468*4882a593Smuzhiyun
2469*4882a593Smuzhiyun /**
2470*4882a593Smuzhiyun * ice_vsi_close - Shut down a VSI
2471*4882a593Smuzhiyun * @vsi: the VSI being shut down
2472*4882a593Smuzhiyun */
ice_vsi_close(struct ice_vsi * vsi)2473*4882a593Smuzhiyun void ice_vsi_close(struct ice_vsi *vsi)
2474*4882a593Smuzhiyun {
2475*4882a593Smuzhiyun if (!test_and_set_bit(__ICE_DOWN, vsi->state))
2476*4882a593Smuzhiyun ice_down(vsi);
2477*4882a593Smuzhiyun
2478*4882a593Smuzhiyun ice_vsi_free_irq(vsi);
2479*4882a593Smuzhiyun ice_vsi_free_tx_rings(vsi);
2480*4882a593Smuzhiyun ice_vsi_free_rx_rings(vsi);
2481*4882a593Smuzhiyun }
2482*4882a593Smuzhiyun
2483*4882a593Smuzhiyun /**
2484*4882a593Smuzhiyun * ice_ena_vsi - resume a VSI
2485*4882a593Smuzhiyun * @vsi: the VSI being resume
2486*4882a593Smuzhiyun * @locked: is the rtnl_lock already held
2487*4882a593Smuzhiyun */
ice_ena_vsi(struct ice_vsi * vsi,bool locked)2488*4882a593Smuzhiyun int ice_ena_vsi(struct ice_vsi *vsi, bool locked)
2489*4882a593Smuzhiyun {
2490*4882a593Smuzhiyun int err = 0;
2491*4882a593Smuzhiyun
2492*4882a593Smuzhiyun if (!test_bit(__ICE_NEEDS_RESTART, vsi->state))
2493*4882a593Smuzhiyun return 0;
2494*4882a593Smuzhiyun
2495*4882a593Smuzhiyun clear_bit(__ICE_NEEDS_RESTART, vsi->state);
2496*4882a593Smuzhiyun
2497*4882a593Smuzhiyun if (vsi->netdev && vsi->type == ICE_VSI_PF) {
2498*4882a593Smuzhiyun if (netif_running(vsi->netdev)) {
2499*4882a593Smuzhiyun if (!locked)
2500*4882a593Smuzhiyun rtnl_lock();
2501*4882a593Smuzhiyun
2502*4882a593Smuzhiyun err = ice_open_internal(vsi->netdev);
2503*4882a593Smuzhiyun
2504*4882a593Smuzhiyun if (!locked)
2505*4882a593Smuzhiyun rtnl_unlock();
2506*4882a593Smuzhiyun }
2507*4882a593Smuzhiyun } else if (vsi->type == ICE_VSI_CTRL) {
2508*4882a593Smuzhiyun err = ice_vsi_open_ctrl(vsi);
2509*4882a593Smuzhiyun }
2510*4882a593Smuzhiyun
2511*4882a593Smuzhiyun return err;
2512*4882a593Smuzhiyun }
2513*4882a593Smuzhiyun
2514*4882a593Smuzhiyun /**
2515*4882a593Smuzhiyun * ice_dis_vsi - pause a VSI
2516*4882a593Smuzhiyun * @vsi: the VSI being paused
2517*4882a593Smuzhiyun * @locked: is the rtnl_lock already held
2518*4882a593Smuzhiyun */
ice_dis_vsi(struct ice_vsi * vsi,bool locked)2519*4882a593Smuzhiyun void ice_dis_vsi(struct ice_vsi *vsi, bool locked)
2520*4882a593Smuzhiyun {
2521*4882a593Smuzhiyun if (test_bit(__ICE_DOWN, vsi->state))
2522*4882a593Smuzhiyun return;
2523*4882a593Smuzhiyun
2524*4882a593Smuzhiyun set_bit(__ICE_NEEDS_RESTART, vsi->state);
2525*4882a593Smuzhiyun
2526*4882a593Smuzhiyun if (vsi->type == ICE_VSI_PF && vsi->netdev) {
2527*4882a593Smuzhiyun if (netif_running(vsi->netdev)) {
2528*4882a593Smuzhiyun if (!locked)
2529*4882a593Smuzhiyun rtnl_lock();
2530*4882a593Smuzhiyun
2531*4882a593Smuzhiyun ice_vsi_close(vsi);
2532*4882a593Smuzhiyun
2533*4882a593Smuzhiyun if (!locked)
2534*4882a593Smuzhiyun rtnl_unlock();
2535*4882a593Smuzhiyun } else {
2536*4882a593Smuzhiyun ice_vsi_close(vsi);
2537*4882a593Smuzhiyun }
2538*4882a593Smuzhiyun } else if (vsi->type == ICE_VSI_CTRL) {
2539*4882a593Smuzhiyun ice_vsi_close(vsi);
2540*4882a593Smuzhiyun }
2541*4882a593Smuzhiyun }
2542*4882a593Smuzhiyun
2543*4882a593Smuzhiyun /**
2544*4882a593Smuzhiyun * ice_vsi_dis_irq - Mask off queue interrupt generation on the VSI
2545*4882a593Smuzhiyun * @vsi: the VSI being un-configured
2546*4882a593Smuzhiyun */
ice_vsi_dis_irq(struct ice_vsi * vsi)2547*4882a593Smuzhiyun void ice_vsi_dis_irq(struct ice_vsi *vsi)
2548*4882a593Smuzhiyun {
2549*4882a593Smuzhiyun int base = vsi->base_vector;
2550*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
2551*4882a593Smuzhiyun struct ice_hw *hw = &pf->hw;
2552*4882a593Smuzhiyun u32 val;
2553*4882a593Smuzhiyun int i;
2554*4882a593Smuzhiyun
2555*4882a593Smuzhiyun /* disable interrupt causation from each queue */
2556*4882a593Smuzhiyun if (vsi->tx_rings) {
2557*4882a593Smuzhiyun ice_for_each_txq(vsi, i) {
2558*4882a593Smuzhiyun if (vsi->tx_rings[i]) {
2559*4882a593Smuzhiyun u16 reg;
2560*4882a593Smuzhiyun
2561*4882a593Smuzhiyun reg = vsi->tx_rings[i]->reg_idx;
2562*4882a593Smuzhiyun val = rd32(hw, QINT_TQCTL(reg));
2563*4882a593Smuzhiyun val &= ~QINT_TQCTL_CAUSE_ENA_M;
2564*4882a593Smuzhiyun wr32(hw, QINT_TQCTL(reg), val);
2565*4882a593Smuzhiyun }
2566*4882a593Smuzhiyun }
2567*4882a593Smuzhiyun }
2568*4882a593Smuzhiyun
2569*4882a593Smuzhiyun if (vsi->rx_rings) {
2570*4882a593Smuzhiyun ice_for_each_rxq(vsi, i) {
2571*4882a593Smuzhiyun if (vsi->rx_rings[i]) {
2572*4882a593Smuzhiyun u16 reg;
2573*4882a593Smuzhiyun
2574*4882a593Smuzhiyun reg = vsi->rx_rings[i]->reg_idx;
2575*4882a593Smuzhiyun val = rd32(hw, QINT_RQCTL(reg));
2576*4882a593Smuzhiyun val &= ~QINT_RQCTL_CAUSE_ENA_M;
2577*4882a593Smuzhiyun wr32(hw, QINT_RQCTL(reg), val);
2578*4882a593Smuzhiyun }
2579*4882a593Smuzhiyun }
2580*4882a593Smuzhiyun }
2581*4882a593Smuzhiyun
2582*4882a593Smuzhiyun /* disable each interrupt */
2583*4882a593Smuzhiyun ice_for_each_q_vector(vsi, i) {
2584*4882a593Smuzhiyun if (!vsi->q_vectors[i])
2585*4882a593Smuzhiyun continue;
2586*4882a593Smuzhiyun wr32(hw, GLINT_DYN_CTL(vsi->q_vectors[i]->reg_idx), 0);
2587*4882a593Smuzhiyun }
2588*4882a593Smuzhiyun
2589*4882a593Smuzhiyun ice_flush(hw);
2590*4882a593Smuzhiyun
2591*4882a593Smuzhiyun /* don't call synchronize_irq() for VF's from the host */
2592*4882a593Smuzhiyun if (vsi->type == ICE_VSI_VF)
2593*4882a593Smuzhiyun return;
2594*4882a593Smuzhiyun
2595*4882a593Smuzhiyun ice_for_each_q_vector(vsi, i)
2596*4882a593Smuzhiyun synchronize_irq(pf->msix_entries[i + base].vector);
2597*4882a593Smuzhiyun }
2598*4882a593Smuzhiyun
2599*4882a593Smuzhiyun /**
2600*4882a593Smuzhiyun * ice_napi_del - Remove NAPI handler for the VSI
2601*4882a593Smuzhiyun * @vsi: VSI for which NAPI handler is to be removed
2602*4882a593Smuzhiyun */
ice_napi_del(struct ice_vsi * vsi)2603*4882a593Smuzhiyun void ice_napi_del(struct ice_vsi *vsi)
2604*4882a593Smuzhiyun {
2605*4882a593Smuzhiyun int v_idx;
2606*4882a593Smuzhiyun
2607*4882a593Smuzhiyun if (!vsi->netdev)
2608*4882a593Smuzhiyun return;
2609*4882a593Smuzhiyun
2610*4882a593Smuzhiyun ice_for_each_q_vector(vsi, v_idx)
2611*4882a593Smuzhiyun netif_napi_del(&vsi->q_vectors[v_idx]->napi);
2612*4882a593Smuzhiyun }
2613*4882a593Smuzhiyun
2614*4882a593Smuzhiyun /**
2615*4882a593Smuzhiyun * ice_vsi_release - Delete a VSI and free its resources
2616*4882a593Smuzhiyun * @vsi: the VSI being removed
2617*4882a593Smuzhiyun *
2618*4882a593Smuzhiyun * Returns 0 on success or < 0 on error
2619*4882a593Smuzhiyun */
ice_vsi_release(struct ice_vsi * vsi)2620*4882a593Smuzhiyun int ice_vsi_release(struct ice_vsi *vsi)
2621*4882a593Smuzhiyun {
2622*4882a593Smuzhiyun struct ice_pf *pf;
2623*4882a593Smuzhiyun
2624*4882a593Smuzhiyun if (!vsi->back)
2625*4882a593Smuzhiyun return -ENODEV;
2626*4882a593Smuzhiyun pf = vsi->back;
2627*4882a593Smuzhiyun
2628*4882a593Smuzhiyun /* do not unregister while driver is in the reset recovery pending
2629*4882a593Smuzhiyun * state. Since reset/rebuild happens through PF service task workqueue,
2630*4882a593Smuzhiyun * it's not a good idea to unregister netdev that is associated to the
2631*4882a593Smuzhiyun * PF that is running the work queue items currently. This is done to
2632*4882a593Smuzhiyun * avoid check_flush_dependency() warning on this wq
2633*4882a593Smuzhiyun */
2634*4882a593Smuzhiyun if (vsi->netdev && !ice_is_reset_in_progress(pf->state)) {
2635*4882a593Smuzhiyun unregister_netdev(vsi->netdev);
2636*4882a593Smuzhiyun ice_devlink_destroy_port(vsi);
2637*4882a593Smuzhiyun }
2638*4882a593Smuzhiyun
2639*4882a593Smuzhiyun if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2640*4882a593Smuzhiyun ice_rss_clean(vsi);
2641*4882a593Smuzhiyun
2642*4882a593Smuzhiyun /* Disable VSI and free resources */
2643*4882a593Smuzhiyun if (vsi->type != ICE_VSI_LB)
2644*4882a593Smuzhiyun ice_vsi_dis_irq(vsi);
2645*4882a593Smuzhiyun ice_vsi_close(vsi);
2646*4882a593Smuzhiyun
2647*4882a593Smuzhiyun /* SR-IOV determines needed MSIX resources all at once instead of per
2648*4882a593Smuzhiyun * VSI since when VFs are spawned we know how many VFs there are and how
2649*4882a593Smuzhiyun * many interrupts each VF needs. SR-IOV MSIX resources are also
2650*4882a593Smuzhiyun * cleared in the same manner.
2651*4882a593Smuzhiyun */
2652*4882a593Smuzhiyun if (vsi->type != ICE_VSI_VF) {
2653*4882a593Smuzhiyun /* reclaim SW interrupts back to the common pool */
2654*4882a593Smuzhiyun ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
2655*4882a593Smuzhiyun pf->num_avail_sw_msix += vsi->num_q_vectors;
2656*4882a593Smuzhiyun }
2657*4882a593Smuzhiyun
2658*4882a593Smuzhiyun if (!ice_is_safe_mode(pf)) {
2659*4882a593Smuzhiyun if (vsi->type == ICE_VSI_PF) {
2660*4882a593Smuzhiyun ice_fltr_remove_eth(vsi, ETH_P_PAUSE, ICE_FLTR_TX,
2661*4882a593Smuzhiyun ICE_DROP_PACKET);
2662*4882a593Smuzhiyun ice_cfg_sw_lldp(vsi, true, false);
2663*4882a593Smuzhiyun /* The Rx rule will only exist to remove if the LLDP FW
2664*4882a593Smuzhiyun * engine is currently stopped
2665*4882a593Smuzhiyun */
2666*4882a593Smuzhiyun if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags))
2667*4882a593Smuzhiyun ice_cfg_sw_lldp(vsi, false, false);
2668*4882a593Smuzhiyun }
2669*4882a593Smuzhiyun }
2670*4882a593Smuzhiyun
2671*4882a593Smuzhiyun if (ice_is_vsi_dflt_vsi(pf->first_sw, vsi))
2672*4882a593Smuzhiyun ice_clear_dflt_vsi(pf->first_sw);
2673*4882a593Smuzhiyun ice_fltr_remove_all(vsi);
2674*4882a593Smuzhiyun ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx);
2675*4882a593Smuzhiyun ice_vsi_delete(vsi);
2676*4882a593Smuzhiyun ice_vsi_free_q_vectors(vsi);
2677*4882a593Smuzhiyun
2678*4882a593Smuzhiyun /* make sure unregister_netdev() was called by checking __ICE_DOWN */
2679*4882a593Smuzhiyun if (vsi->netdev && test_bit(__ICE_DOWN, vsi->state)) {
2680*4882a593Smuzhiyun free_netdev(vsi->netdev);
2681*4882a593Smuzhiyun vsi->netdev = NULL;
2682*4882a593Smuzhiyun }
2683*4882a593Smuzhiyun
2684*4882a593Smuzhiyun ice_vsi_clear_rings(vsi);
2685*4882a593Smuzhiyun
2686*4882a593Smuzhiyun ice_vsi_put_qs(vsi);
2687*4882a593Smuzhiyun
2688*4882a593Smuzhiyun /* retain SW VSI data structure since it is needed to unregister and
2689*4882a593Smuzhiyun * free VSI netdev when PF is not in reset recovery pending state,\
2690*4882a593Smuzhiyun * for ex: during rmmod.
2691*4882a593Smuzhiyun */
2692*4882a593Smuzhiyun if (!ice_is_reset_in_progress(pf->state))
2693*4882a593Smuzhiyun ice_vsi_clear(vsi);
2694*4882a593Smuzhiyun
2695*4882a593Smuzhiyun return 0;
2696*4882a593Smuzhiyun }
2697*4882a593Smuzhiyun
2698*4882a593Smuzhiyun /**
2699*4882a593Smuzhiyun * ice_vsi_rebuild_update_coalesce_intrl - set interrupt rate limit for a q_vector
2700*4882a593Smuzhiyun * @q_vector: pointer to q_vector which is being updated
2701*4882a593Smuzhiyun * @stored_intrl_setting: original INTRL setting
2702*4882a593Smuzhiyun *
2703*4882a593Smuzhiyun * Set coalesce param in q_vector and update these parameters in HW.
2704*4882a593Smuzhiyun */
2705*4882a593Smuzhiyun static void
ice_vsi_rebuild_update_coalesce_intrl(struct ice_q_vector * q_vector,u16 stored_intrl_setting)2706*4882a593Smuzhiyun ice_vsi_rebuild_update_coalesce_intrl(struct ice_q_vector *q_vector,
2707*4882a593Smuzhiyun u16 stored_intrl_setting)
2708*4882a593Smuzhiyun {
2709*4882a593Smuzhiyun struct ice_hw *hw = &q_vector->vsi->back->hw;
2710*4882a593Smuzhiyun
2711*4882a593Smuzhiyun q_vector->intrl = stored_intrl_setting;
2712*4882a593Smuzhiyun wr32(hw, GLINT_RATE(q_vector->reg_idx),
2713*4882a593Smuzhiyun ice_intrl_usec_to_reg(q_vector->intrl, hw->intrl_gran));
2714*4882a593Smuzhiyun }
2715*4882a593Smuzhiyun
2716*4882a593Smuzhiyun /**
2717*4882a593Smuzhiyun * ice_vsi_rebuild_update_coalesce_itr - set coalesce for a q_vector
2718*4882a593Smuzhiyun * @q_vector: pointer to q_vector which is being updated
2719*4882a593Smuzhiyun * @rc: pointer to ring container
2720*4882a593Smuzhiyun * @stored_itr_setting: original ITR setting
2721*4882a593Smuzhiyun *
2722*4882a593Smuzhiyun * Set coalesce param in q_vector and update these parameters in HW.
2723*4882a593Smuzhiyun */
2724*4882a593Smuzhiyun static void
ice_vsi_rebuild_update_coalesce_itr(struct ice_q_vector * q_vector,struct ice_ring_container * rc,u16 stored_itr_setting)2725*4882a593Smuzhiyun ice_vsi_rebuild_update_coalesce_itr(struct ice_q_vector *q_vector,
2726*4882a593Smuzhiyun struct ice_ring_container *rc,
2727*4882a593Smuzhiyun u16 stored_itr_setting)
2728*4882a593Smuzhiyun {
2729*4882a593Smuzhiyun struct ice_hw *hw = &q_vector->vsi->back->hw;
2730*4882a593Smuzhiyun
2731*4882a593Smuzhiyun rc->itr_setting = stored_itr_setting;
2732*4882a593Smuzhiyun
2733*4882a593Smuzhiyun /* dynamic ITR values will be updated during Tx/Rx */
2734*4882a593Smuzhiyun if (!ITR_IS_DYNAMIC(rc->itr_setting))
2735*4882a593Smuzhiyun wr32(hw, GLINT_ITR(rc->itr_idx, q_vector->reg_idx),
2736*4882a593Smuzhiyun ITR_REG_ALIGN(rc->itr_setting) >> ICE_ITR_GRAN_S);
2737*4882a593Smuzhiyun }
2738*4882a593Smuzhiyun
2739*4882a593Smuzhiyun /**
2740*4882a593Smuzhiyun * ice_vsi_rebuild_get_coalesce - get coalesce from all q_vectors
2741*4882a593Smuzhiyun * @vsi: VSI connected with q_vectors
2742*4882a593Smuzhiyun * @coalesce: array of struct with stored coalesce
2743*4882a593Smuzhiyun *
2744*4882a593Smuzhiyun * Returns array size.
2745*4882a593Smuzhiyun */
2746*4882a593Smuzhiyun static int
ice_vsi_rebuild_get_coalesce(struct ice_vsi * vsi,struct ice_coalesce_stored * coalesce)2747*4882a593Smuzhiyun ice_vsi_rebuild_get_coalesce(struct ice_vsi *vsi,
2748*4882a593Smuzhiyun struct ice_coalesce_stored *coalesce)
2749*4882a593Smuzhiyun {
2750*4882a593Smuzhiyun int i;
2751*4882a593Smuzhiyun
2752*4882a593Smuzhiyun ice_for_each_q_vector(vsi, i) {
2753*4882a593Smuzhiyun struct ice_q_vector *q_vector = vsi->q_vectors[i];
2754*4882a593Smuzhiyun
2755*4882a593Smuzhiyun coalesce[i].itr_tx = q_vector->tx.itr_setting;
2756*4882a593Smuzhiyun coalesce[i].itr_rx = q_vector->rx.itr_setting;
2757*4882a593Smuzhiyun coalesce[i].intrl = q_vector->intrl;
2758*4882a593Smuzhiyun
2759*4882a593Smuzhiyun if (i < vsi->num_txq)
2760*4882a593Smuzhiyun coalesce[i].tx_valid = true;
2761*4882a593Smuzhiyun if (i < vsi->num_rxq)
2762*4882a593Smuzhiyun coalesce[i].rx_valid = true;
2763*4882a593Smuzhiyun }
2764*4882a593Smuzhiyun
2765*4882a593Smuzhiyun return vsi->num_q_vectors;
2766*4882a593Smuzhiyun }
2767*4882a593Smuzhiyun
2768*4882a593Smuzhiyun /**
2769*4882a593Smuzhiyun * ice_vsi_rebuild_set_coalesce - set coalesce from earlier saved arrays
2770*4882a593Smuzhiyun * @vsi: VSI connected with q_vectors
2771*4882a593Smuzhiyun * @coalesce: pointer to array of struct with stored coalesce
2772*4882a593Smuzhiyun * @size: size of coalesce array
2773*4882a593Smuzhiyun *
2774*4882a593Smuzhiyun * Before this function, ice_vsi_rebuild_get_coalesce should be called to save
2775*4882a593Smuzhiyun * ITR params in arrays. If size is 0 or coalesce wasn't stored set coalesce
2776*4882a593Smuzhiyun * to default value.
2777*4882a593Smuzhiyun */
2778*4882a593Smuzhiyun static void
ice_vsi_rebuild_set_coalesce(struct ice_vsi * vsi,struct ice_coalesce_stored * coalesce,int size)2779*4882a593Smuzhiyun ice_vsi_rebuild_set_coalesce(struct ice_vsi *vsi,
2780*4882a593Smuzhiyun struct ice_coalesce_stored *coalesce, int size)
2781*4882a593Smuzhiyun {
2782*4882a593Smuzhiyun int i;
2783*4882a593Smuzhiyun
2784*4882a593Smuzhiyun if ((size && !coalesce) || !vsi)
2785*4882a593Smuzhiyun return;
2786*4882a593Smuzhiyun
2787*4882a593Smuzhiyun /* There are a couple of cases that have to be handled here:
2788*4882a593Smuzhiyun * 1. The case where the number of queue vectors stays the same, but
2789*4882a593Smuzhiyun * the number of Tx or Rx rings changes (the first for loop)
2790*4882a593Smuzhiyun * 2. The case where the number of queue vectors increased (the
2791*4882a593Smuzhiyun * second for loop)
2792*4882a593Smuzhiyun */
2793*4882a593Smuzhiyun for (i = 0; i < size && i < vsi->num_q_vectors; i++) {
2794*4882a593Smuzhiyun /* There are 2 cases to handle here and they are the same for
2795*4882a593Smuzhiyun * both Tx and Rx:
2796*4882a593Smuzhiyun * if the entry was valid previously (coalesce[i].[tr]x_valid
2797*4882a593Smuzhiyun * and the loop variable is less than the number of rings
2798*4882a593Smuzhiyun * allocated, then write the previous values
2799*4882a593Smuzhiyun *
2800*4882a593Smuzhiyun * if the entry was not valid previously, but the number of
2801*4882a593Smuzhiyun * rings is less than are allocated (this means the number of
2802*4882a593Smuzhiyun * rings increased from previously), then write out the
2803*4882a593Smuzhiyun * values in the first element
2804*4882a593Smuzhiyun */
2805*4882a593Smuzhiyun if (i < vsi->alloc_rxq && coalesce[i].rx_valid)
2806*4882a593Smuzhiyun ice_vsi_rebuild_update_coalesce_itr(vsi->q_vectors[i],
2807*4882a593Smuzhiyun &vsi->q_vectors[i]->rx,
2808*4882a593Smuzhiyun coalesce[i].itr_rx);
2809*4882a593Smuzhiyun else if (i < vsi->alloc_rxq)
2810*4882a593Smuzhiyun ice_vsi_rebuild_update_coalesce_itr(vsi->q_vectors[i],
2811*4882a593Smuzhiyun &vsi->q_vectors[i]->rx,
2812*4882a593Smuzhiyun coalesce[0].itr_rx);
2813*4882a593Smuzhiyun
2814*4882a593Smuzhiyun if (i < vsi->alloc_txq && coalesce[i].tx_valid)
2815*4882a593Smuzhiyun ice_vsi_rebuild_update_coalesce_itr(vsi->q_vectors[i],
2816*4882a593Smuzhiyun &vsi->q_vectors[i]->tx,
2817*4882a593Smuzhiyun coalesce[i].itr_tx);
2818*4882a593Smuzhiyun else if (i < vsi->alloc_txq)
2819*4882a593Smuzhiyun ice_vsi_rebuild_update_coalesce_itr(vsi->q_vectors[i],
2820*4882a593Smuzhiyun &vsi->q_vectors[i]->tx,
2821*4882a593Smuzhiyun coalesce[0].itr_tx);
2822*4882a593Smuzhiyun
2823*4882a593Smuzhiyun ice_vsi_rebuild_update_coalesce_intrl(vsi->q_vectors[i],
2824*4882a593Smuzhiyun coalesce[i].intrl);
2825*4882a593Smuzhiyun }
2826*4882a593Smuzhiyun
2827*4882a593Smuzhiyun /* the number of queue vectors increased so write whatever is in
2828*4882a593Smuzhiyun * the first element
2829*4882a593Smuzhiyun */
2830*4882a593Smuzhiyun for (; i < vsi->num_q_vectors; i++) {
2831*4882a593Smuzhiyun ice_vsi_rebuild_update_coalesce_itr(vsi->q_vectors[i],
2832*4882a593Smuzhiyun &vsi->q_vectors[i]->tx,
2833*4882a593Smuzhiyun coalesce[0].itr_tx);
2834*4882a593Smuzhiyun ice_vsi_rebuild_update_coalesce_itr(vsi->q_vectors[i],
2835*4882a593Smuzhiyun &vsi->q_vectors[i]->rx,
2836*4882a593Smuzhiyun coalesce[0].itr_rx);
2837*4882a593Smuzhiyun ice_vsi_rebuild_update_coalesce_intrl(vsi->q_vectors[i],
2838*4882a593Smuzhiyun coalesce[0].intrl);
2839*4882a593Smuzhiyun }
2840*4882a593Smuzhiyun }
2841*4882a593Smuzhiyun
2842*4882a593Smuzhiyun /**
2843*4882a593Smuzhiyun * ice_vsi_rebuild - Rebuild VSI after reset
2844*4882a593Smuzhiyun * @vsi: VSI to be rebuild
2845*4882a593Smuzhiyun * @init_vsi: is this an initialization or a reconfigure of the VSI
2846*4882a593Smuzhiyun *
2847*4882a593Smuzhiyun * Returns 0 on success and negative value on failure
2848*4882a593Smuzhiyun */
ice_vsi_rebuild(struct ice_vsi * vsi,bool init_vsi)2849*4882a593Smuzhiyun int ice_vsi_rebuild(struct ice_vsi *vsi, bool init_vsi)
2850*4882a593Smuzhiyun {
2851*4882a593Smuzhiyun u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2852*4882a593Smuzhiyun struct ice_coalesce_stored *coalesce;
2853*4882a593Smuzhiyun int prev_num_q_vectors = 0;
2854*4882a593Smuzhiyun struct ice_vf *vf = NULL;
2855*4882a593Smuzhiyun enum ice_status status;
2856*4882a593Smuzhiyun struct ice_pf *pf;
2857*4882a593Smuzhiyun int ret, i;
2858*4882a593Smuzhiyun
2859*4882a593Smuzhiyun if (!vsi)
2860*4882a593Smuzhiyun return -EINVAL;
2861*4882a593Smuzhiyun
2862*4882a593Smuzhiyun pf = vsi->back;
2863*4882a593Smuzhiyun if (vsi->type == ICE_VSI_VF)
2864*4882a593Smuzhiyun vf = &pf->vf[vsi->vf_id];
2865*4882a593Smuzhiyun
2866*4882a593Smuzhiyun coalesce = kcalloc(vsi->num_q_vectors,
2867*4882a593Smuzhiyun sizeof(struct ice_coalesce_stored), GFP_KERNEL);
2868*4882a593Smuzhiyun if (!coalesce)
2869*4882a593Smuzhiyun return -ENOMEM;
2870*4882a593Smuzhiyun
2871*4882a593Smuzhiyun prev_num_q_vectors = ice_vsi_rebuild_get_coalesce(vsi, coalesce);
2872*4882a593Smuzhiyun
2873*4882a593Smuzhiyun ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx);
2874*4882a593Smuzhiyun ice_vsi_free_q_vectors(vsi);
2875*4882a593Smuzhiyun
2876*4882a593Smuzhiyun /* SR-IOV determines needed MSIX resources all at once instead of per
2877*4882a593Smuzhiyun * VSI since when VFs are spawned we know how many VFs there are and how
2878*4882a593Smuzhiyun * many interrupts each VF needs. SR-IOV MSIX resources are also
2879*4882a593Smuzhiyun * cleared in the same manner.
2880*4882a593Smuzhiyun */
2881*4882a593Smuzhiyun if (vsi->type != ICE_VSI_VF) {
2882*4882a593Smuzhiyun /* reclaim SW interrupts back to the common pool */
2883*4882a593Smuzhiyun ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx);
2884*4882a593Smuzhiyun pf->num_avail_sw_msix += vsi->num_q_vectors;
2885*4882a593Smuzhiyun vsi->base_vector = 0;
2886*4882a593Smuzhiyun }
2887*4882a593Smuzhiyun
2888*4882a593Smuzhiyun if (ice_is_xdp_ena_vsi(vsi))
2889*4882a593Smuzhiyun /* return value check can be skipped here, it always returns
2890*4882a593Smuzhiyun * 0 if reset is in progress
2891*4882a593Smuzhiyun */
2892*4882a593Smuzhiyun ice_destroy_xdp_rings(vsi);
2893*4882a593Smuzhiyun ice_vsi_put_qs(vsi);
2894*4882a593Smuzhiyun ice_vsi_clear_rings(vsi);
2895*4882a593Smuzhiyun ice_vsi_free_arrays(vsi);
2896*4882a593Smuzhiyun if (vsi->type == ICE_VSI_VF)
2897*4882a593Smuzhiyun ice_vsi_set_num_qs(vsi, vf->vf_id);
2898*4882a593Smuzhiyun else
2899*4882a593Smuzhiyun ice_vsi_set_num_qs(vsi, ICE_INVAL_VFID);
2900*4882a593Smuzhiyun
2901*4882a593Smuzhiyun ret = ice_vsi_alloc_arrays(vsi);
2902*4882a593Smuzhiyun if (ret < 0)
2903*4882a593Smuzhiyun goto err_vsi;
2904*4882a593Smuzhiyun
2905*4882a593Smuzhiyun ice_vsi_get_qs(vsi);
2906*4882a593Smuzhiyun
2907*4882a593Smuzhiyun ice_alloc_fd_res(vsi);
2908*4882a593Smuzhiyun ice_vsi_set_tc_cfg(vsi);
2909*4882a593Smuzhiyun
2910*4882a593Smuzhiyun /* Initialize VSI struct elements and create VSI in FW */
2911*4882a593Smuzhiyun ret = ice_vsi_init(vsi, init_vsi);
2912*4882a593Smuzhiyun if (ret < 0)
2913*4882a593Smuzhiyun goto err_vsi;
2914*4882a593Smuzhiyun
2915*4882a593Smuzhiyun switch (vsi->type) {
2916*4882a593Smuzhiyun case ICE_VSI_CTRL:
2917*4882a593Smuzhiyun case ICE_VSI_PF:
2918*4882a593Smuzhiyun ret = ice_vsi_alloc_q_vectors(vsi);
2919*4882a593Smuzhiyun if (ret)
2920*4882a593Smuzhiyun goto err_rings;
2921*4882a593Smuzhiyun
2922*4882a593Smuzhiyun ret = ice_vsi_setup_vector_base(vsi);
2923*4882a593Smuzhiyun if (ret)
2924*4882a593Smuzhiyun goto err_vectors;
2925*4882a593Smuzhiyun
2926*4882a593Smuzhiyun ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2927*4882a593Smuzhiyun if (ret)
2928*4882a593Smuzhiyun goto err_vectors;
2929*4882a593Smuzhiyun
2930*4882a593Smuzhiyun ret = ice_vsi_alloc_rings(vsi);
2931*4882a593Smuzhiyun if (ret)
2932*4882a593Smuzhiyun goto err_vectors;
2933*4882a593Smuzhiyun
2934*4882a593Smuzhiyun ice_vsi_map_rings_to_vectors(vsi);
2935*4882a593Smuzhiyun if (ice_is_xdp_ena_vsi(vsi)) {
2936*4882a593Smuzhiyun vsi->num_xdp_txq = vsi->alloc_rxq;
2937*4882a593Smuzhiyun ret = ice_prepare_xdp_rings(vsi, vsi->xdp_prog);
2938*4882a593Smuzhiyun if (ret)
2939*4882a593Smuzhiyun goto err_vectors;
2940*4882a593Smuzhiyun }
2941*4882a593Smuzhiyun /* ICE_VSI_CTRL does not need RSS so skip RSS processing */
2942*4882a593Smuzhiyun if (vsi->type != ICE_VSI_CTRL)
2943*4882a593Smuzhiyun /* Do not exit if configuring RSS had an issue, at
2944*4882a593Smuzhiyun * least receive traffic on first queue. Hence no
2945*4882a593Smuzhiyun * need to capture return value
2946*4882a593Smuzhiyun */
2947*4882a593Smuzhiyun if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2948*4882a593Smuzhiyun ice_vsi_cfg_rss_lut_key(vsi);
2949*4882a593Smuzhiyun break;
2950*4882a593Smuzhiyun case ICE_VSI_VF:
2951*4882a593Smuzhiyun ret = ice_vsi_alloc_q_vectors(vsi);
2952*4882a593Smuzhiyun if (ret)
2953*4882a593Smuzhiyun goto err_rings;
2954*4882a593Smuzhiyun
2955*4882a593Smuzhiyun ret = ice_vsi_set_q_vectors_reg_idx(vsi);
2956*4882a593Smuzhiyun if (ret)
2957*4882a593Smuzhiyun goto err_vectors;
2958*4882a593Smuzhiyun
2959*4882a593Smuzhiyun ret = ice_vsi_alloc_rings(vsi);
2960*4882a593Smuzhiyun if (ret)
2961*4882a593Smuzhiyun goto err_vectors;
2962*4882a593Smuzhiyun
2963*4882a593Smuzhiyun break;
2964*4882a593Smuzhiyun default:
2965*4882a593Smuzhiyun break;
2966*4882a593Smuzhiyun }
2967*4882a593Smuzhiyun
2968*4882a593Smuzhiyun /* configure VSI nodes based on number of queues and TC's */
2969*4882a593Smuzhiyun for (i = 0; i < vsi->tc_cfg.numtc; i++) {
2970*4882a593Smuzhiyun max_txqs[i] = vsi->alloc_txq;
2971*4882a593Smuzhiyun
2972*4882a593Smuzhiyun if (ice_is_xdp_ena_vsi(vsi))
2973*4882a593Smuzhiyun max_txqs[i] += vsi->num_xdp_txq;
2974*4882a593Smuzhiyun }
2975*4882a593Smuzhiyun
2976*4882a593Smuzhiyun status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2977*4882a593Smuzhiyun max_txqs);
2978*4882a593Smuzhiyun if (status) {
2979*4882a593Smuzhiyun dev_err(ice_pf_to_dev(pf), "VSI %d failed lan queue config, error %s\n",
2980*4882a593Smuzhiyun vsi->vsi_num, ice_stat_str(status));
2981*4882a593Smuzhiyun if (init_vsi) {
2982*4882a593Smuzhiyun ret = -EIO;
2983*4882a593Smuzhiyun goto err_vectors;
2984*4882a593Smuzhiyun } else {
2985*4882a593Smuzhiyun return ice_schedule_reset(pf, ICE_RESET_PFR);
2986*4882a593Smuzhiyun }
2987*4882a593Smuzhiyun }
2988*4882a593Smuzhiyun ice_vsi_rebuild_set_coalesce(vsi, coalesce, prev_num_q_vectors);
2989*4882a593Smuzhiyun kfree(coalesce);
2990*4882a593Smuzhiyun
2991*4882a593Smuzhiyun return 0;
2992*4882a593Smuzhiyun
2993*4882a593Smuzhiyun err_vectors:
2994*4882a593Smuzhiyun ice_vsi_free_q_vectors(vsi);
2995*4882a593Smuzhiyun err_rings:
2996*4882a593Smuzhiyun if (vsi->netdev) {
2997*4882a593Smuzhiyun vsi->current_netdev_flags = 0;
2998*4882a593Smuzhiyun unregister_netdev(vsi->netdev);
2999*4882a593Smuzhiyun free_netdev(vsi->netdev);
3000*4882a593Smuzhiyun vsi->netdev = NULL;
3001*4882a593Smuzhiyun }
3002*4882a593Smuzhiyun err_vsi:
3003*4882a593Smuzhiyun ice_vsi_clear(vsi);
3004*4882a593Smuzhiyun set_bit(__ICE_RESET_FAILED, pf->state);
3005*4882a593Smuzhiyun kfree(coalesce);
3006*4882a593Smuzhiyun return ret;
3007*4882a593Smuzhiyun }
3008*4882a593Smuzhiyun
3009*4882a593Smuzhiyun /**
3010*4882a593Smuzhiyun * ice_is_reset_in_progress - check for a reset in progress
3011*4882a593Smuzhiyun * @state: PF state field
3012*4882a593Smuzhiyun */
ice_is_reset_in_progress(unsigned long * state)3013*4882a593Smuzhiyun bool ice_is_reset_in_progress(unsigned long *state)
3014*4882a593Smuzhiyun {
3015*4882a593Smuzhiyun return test_bit(__ICE_RESET_OICR_RECV, state) ||
3016*4882a593Smuzhiyun test_bit(__ICE_PFR_REQ, state) ||
3017*4882a593Smuzhiyun test_bit(__ICE_CORER_REQ, state) ||
3018*4882a593Smuzhiyun test_bit(__ICE_GLOBR_REQ, state);
3019*4882a593Smuzhiyun }
3020*4882a593Smuzhiyun
3021*4882a593Smuzhiyun #ifdef CONFIG_DCB
3022*4882a593Smuzhiyun /**
3023*4882a593Smuzhiyun * ice_vsi_update_q_map - update our copy of the VSI info with new queue map
3024*4882a593Smuzhiyun * @vsi: VSI being configured
3025*4882a593Smuzhiyun * @ctx: the context buffer returned from AQ VSI update command
3026*4882a593Smuzhiyun */
ice_vsi_update_q_map(struct ice_vsi * vsi,struct ice_vsi_ctx * ctx)3027*4882a593Smuzhiyun static void ice_vsi_update_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctx)
3028*4882a593Smuzhiyun {
3029*4882a593Smuzhiyun vsi->info.mapping_flags = ctx->info.mapping_flags;
3030*4882a593Smuzhiyun memcpy(&vsi->info.q_mapping, &ctx->info.q_mapping,
3031*4882a593Smuzhiyun sizeof(vsi->info.q_mapping));
3032*4882a593Smuzhiyun memcpy(&vsi->info.tc_mapping, ctx->info.tc_mapping,
3033*4882a593Smuzhiyun sizeof(vsi->info.tc_mapping));
3034*4882a593Smuzhiyun }
3035*4882a593Smuzhiyun
3036*4882a593Smuzhiyun /**
3037*4882a593Smuzhiyun * ice_vsi_cfg_tc - Configure VSI Tx Sched for given TC map
3038*4882a593Smuzhiyun * @vsi: VSI to be configured
3039*4882a593Smuzhiyun * @ena_tc: TC bitmap
3040*4882a593Smuzhiyun *
3041*4882a593Smuzhiyun * VSI queues expected to be quiesced before calling this function
3042*4882a593Smuzhiyun */
ice_vsi_cfg_tc(struct ice_vsi * vsi,u8 ena_tc)3043*4882a593Smuzhiyun int ice_vsi_cfg_tc(struct ice_vsi *vsi, u8 ena_tc)
3044*4882a593Smuzhiyun {
3045*4882a593Smuzhiyun u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
3046*4882a593Smuzhiyun struct ice_pf *pf = vsi->back;
3047*4882a593Smuzhiyun struct ice_vsi_ctx *ctx;
3048*4882a593Smuzhiyun enum ice_status status;
3049*4882a593Smuzhiyun struct device *dev;
3050*4882a593Smuzhiyun int i, ret = 0;
3051*4882a593Smuzhiyun u8 num_tc = 0;
3052*4882a593Smuzhiyun
3053*4882a593Smuzhiyun dev = ice_pf_to_dev(pf);
3054*4882a593Smuzhiyun
3055*4882a593Smuzhiyun ice_for_each_traffic_class(i) {
3056*4882a593Smuzhiyun /* build bitmap of enabled TCs */
3057*4882a593Smuzhiyun if (ena_tc & BIT(i))
3058*4882a593Smuzhiyun num_tc++;
3059*4882a593Smuzhiyun /* populate max_txqs per TC */
3060*4882a593Smuzhiyun max_txqs[i] = vsi->alloc_txq;
3061*4882a593Smuzhiyun }
3062*4882a593Smuzhiyun
3063*4882a593Smuzhiyun vsi->tc_cfg.ena_tc = ena_tc;
3064*4882a593Smuzhiyun vsi->tc_cfg.numtc = num_tc;
3065*4882a593Smuzhiyun
3066*4882a593Smuzhiyun ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
3067*4882a593Smuzhiyun if (!ctx)
3068*4882a593Smuzhiyun return -ENOMEM;
3069*4882a593Smuzhiyun
3070*4882a593Smuzhiyun ctx->vf_num = 0;
3071*4882a593Smuzhiyun ctx->info = vsi->info;
3072*4882a593Smuzhiyun
3073*4882a593Smuzhiyun ice_vsi_setup_q_map(vsi, ctx);
3074*4882a593Smuzhiyun
3075*4882a593Smuzhiyun /* must to indicate which section of VSI context are being modified */
3076*4882a593Smuzhiyun ctx->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_RXQ_MAP_VALID);
3077*4882a593Smuzhiyun status = ice_update_vsi(&pf->hw, vsi->idx, ctx, NULL);
3078*4882a593Smuzhiyun if (status) {
3079*4882a593Smuzhiyun dev_info(dev, "Failed VSI Update\n");
3080*4882a593Smuzhiyun ret = -EIO;
3081*4882a593Smuzhiyun goto out;
3082*4882a593Smuzhiyun }
3083*4882a593Smuzhiyun
3084*4882a593Smuzhiyun status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
3085*4882a593Smuzhiyun max_txqs);
3086*4882a593Smuzhiyun
3087*4882a593Smuzhiyun if (status) {
3088*4882a593Smuzhiyun dev_err(dev, "VSI %d failed TC config, error %s\n",
3089*4882a593Smuzhiyun vsi->vsi_num, ice_stat_str(status));
3090*4882a593Smuzhiyun ret = -EIO;
3091*4882a593Smuzhiyun goto out;
3092*4882a593Smuzhiyun }
3093*4882a593Smuzhiyun ice_vsi_update_q_map(vsi, ctx);
3094*4882a593Smuzhiyun vsi->info.valid_sections = 0;
3095*4882a593Smuzhiyun
3096*4882a593Smuzhiyun ice_vsi_cfg_netdev_tc(vsi, ena_tc);
3097*4882a593Smuzhiyun out:
3098*4882a593Smuzhiyun kfree(ctx);
3099*4882a593Smuzhiyun return ret;
3100*4882a593Smuzhiyun }
3101*4882a593Smuzhiyun #endif /* CONFIG_DCB */
3102*4882a593Smuzhiyun
3103*4882a593Smuzhiyun /**
3104*4882a593Smuzhiyun * ice_update_ring_stats - Update ring statistics
3105*4882a593Smuzhiyun * @ring: ring to update
3106*4882a593Smuzhiyun * @cont: used to increment per-vector counters
3107*4882a593Smuzhiyun * @pkts: number of processed packets
3108*4882a593Smuzhiyun * @bytes: number of processed bytes
3109*4882a593Smuzhiyun *
3110*4882a593Smuzhiyun * This function assumes that caller has acquired a u64_stats_sync lock.
3111*4882a593Smuzhiyun */
3112*4882a593Smuzhiyun static void
ice_update_ring_stats(struct ice_ring * ring,struct ice_ring_container * cont,u64 pkts,u64 bytes)3113*4882a593Smuzhiyun ice_update_ring_stats(struct ice_ring *ring, struct ice_ring_container *cont,
3114*4882a593Smuzhiyun u64 pkts, u64 bytes)
3115*4882a593Smuzhiyun {
3116*4882a593Smuzhiyun ring->stats.bytes += bytes;
3117*4882a593Smuzhiyun ring->stats.pkts += pkts;
3118*4882a593Smuzhiyun cont->total_bytes += bytes;
3119*4882a593Smuzhiyun cont->total_pkts += pkts;
3120*4882a593Smuzhiyun }
3121*4882a593Smuzhiyun
3122*4882a593Smuzhiyun /**
3123*4882a593Smuzhiyun * ice_update_tx_ring_stats - Update Tx ring specific counters
3124*4882a593Smuzhiyun * @tx_ring: ring to update
3125*4882a593Smuzhiyun * @pkts: number of processed packets
3126*4882a593Smuzhiyun * @bytes: number of processed bytes
3127*4882a593Smuzhiyun */
ice_update_tx_ring_stats(struct ice_ring * tx_ring,u64 pkts,u64 bytes)3128*4882a593Smuzhiyun void ice_update_tx_ring_stats(struct ice_ring *tx_ring, u64 pkts, u64 bytes)
3129*4882a593Smuzhiyun {
3130*4882a593Smuzhiyun u64_stats_update_begin(&tx_ring->syncp);
3131*4882a593Smuzhiyun ice_update_ring_stats(tx_ring, &tx_ring->q_vector->tx, pkts, bytes);
3132*4882a593Smuzhiyun u64_stats_update_end(&tx_ring->syncp);
3133*4882a593Smuzhiyun }
3134*4882a593Smuzhiyun
3135*4882a593Smuzhiyun /**
3136*4882a593Smuzhiyun * ice_update_rx_ring_stats - Update Rx ring specific counters
3137*4882a593Smuzhiyun * @rx_ring: ring to update
3138*4882a593Smuzhiyun * @pkts: number of processed packets
3139*4882a593Smuzhiyun * @bytes: number of processed bytes
3140*4882a593Smuzhiyun */
ice_update_rx_ring_stats(struct ice_ring * rx_ring,u64 pkts,u64 bytes)3141*4882a593Smuzhiyun void ice_update_rx_ring_stats(struct ice_ring *rx_ring, u64 pkts, u64 bytes)
3142*4882a593Smuzhiyun {
3143*4882a593Smuzhiyun u64_stats_update_begin(&rx_ring->syncp);
3144*4882a593Smuzhiyun ice_update_ring_stats(rx_ring, &rx_ring->q_vector->rx, pkts, bytes);
3145*4882a593Smuzhiyun u64_stats_update_end(&rx_ring->syncp);
3146*4882a593Smuzhiyun }
3147*4882a593Smuzhiyun
3148*4882a593Smuzhiyun /**
3149*4882a593Smuzhiyun * ice_status_to_errno - convert from enum ice_status to Linux errno
3150*4882a593Smuzhiyun * @err: ice_status value to convert
3151*4882a593Smuzhiyun */
ice_status_to_errno(enum ice_status err)3152*4882a593Smuzhiyun int ice_status_to_errno(enum ice_status err)
3153*4882a593Smuzhiyun {
3154*4882a593Smuzhiyun switch (err) {
3155*4882a593Smuzhiyun case ICE_SUCCESS:
3156*4882a593Smuzhiyun return 0;
3157*4882a593Smuzhiyun case ICE_ERR_DOES_NOT_EXIST:
3158*4882a593Smuzhiyun return -ENOENT;
3159*4882a593Smuzhiyun case ICE_ERR_OUT_OF_RANGE:
3160*4882a593Smuzhiyun return -ENOTTY;
3161*4882a593Smuzhiyun case ICE_ERR_PARAM:
3162*4882a593Smuzhiyun return -EINVAL;
3163*4882a593Smuzhiyun case ICE_ERR_NO_MEMORY:
3164*4882a593Smuzhiyun return -ENOMEM;
3165*4882a593Smuzhiyun case ICE_ERR_MAX_LIMIT:
3166*4882a593Smuzhiyun return -EAGAIN;
3167*4882a593Smuzhiyun default:
3168*4882a593Smuzhiyun return -EINVAL;
3169*4882a593Smuzhiyun }
3170*4882a593Smuzhiyun }
3171*4882a593Smuzhiyun
3172*4882a593Smuzhiyun /**
3173*4882a593Smuzhiyun * ice_is_dflt_vsi_in_use - check if the default forwarding VSI is being used
3174*4882a593Smuzhiyun * @sw: switch to check if its default forwarding VSI is free
3175*4882a593Smuzhiyun *
3176*4882a593Smuzhiyun * Return true if the default forwarding VSI is already being used, else returns
3177*4882a593Smuzhiyun * false signalling that it's available to use.
3178*4882a593Smuzhiyun */
ice_is_dflt_vsi_in_use(struct ice_sw * sw)3179*4882a593Smuzhiyun bool ice_is_dflt_vsi_in_use(struct ice_sw *sw)
3180*4882a593Smuzhiyun {
3181*4882a593Smuzhiyun return (sw->dflt_vsi && sw->dflt_vsi_ena);
3182*4882a593Smuzhiyun }
3183*4882a593Smuzhiyun
3184*4882a593Smuzhiyun /**
3185*4882a593Smuzhiyun * ice_is_vsi_dflt_vsi - check if the VSI passed in is the default VSI
3186*4882a593Smuzhiyun * @sw: switch for the default forwarding VSI to compare against
3187*4882a593Smuzhiyun * @vsi: VSI to compare against default forwarding VSI
3188*4882a593Smuzhiyun *
3189*4882a593Smuzhiyun * If this VSI passed in is the default forwarding VSI then return true, else
3190*4882a593Smuzhiyun * return false
3191*4882a593Smuzhiyun */
ice_is_vsi_dflt_vsi(struct ice_sw * sw,struct ice_vsi * vsi)3192*4882a593Smuzhiyun bool ice_is_vsi_dflt_vsi(struct ice_sw *sw, struct ice_vsi *vsi)
3193*4882a593Smuzhiyun {
3194*4882a593Smuzhiyun return (sw->dflt_vsi == vsi && sw->dflt_vsi_ena);
3195*4882a593Smuzhiyun }
3196*4882a593Smuzhiyun
3197*4882a593Smuzhiyun /**
3198*4882a593Smuzhiyun * ice_set_dflt_vsi - set the default forwarding VSI
3199*4882a593Smuzhiyun * @sw: switch used to assign the default forwarding VSI
3200*4882a593Smuzhiyun * @vsi: VSI getting set as the default forwarding VSI on the switch
3201*4882a593Smuzhiyun *
3202*4882a593Smuzhiyun * If the VSI passed in is already the default VSI and it's enabled just return
3203*4882a593Smuzhiyun * success.
3204*4882a593Smuzhiyun *
3205*4882a593Smuzhiyun * If there is already a default VSI on the switch and it's enabled then return
3206*4882a593Smuzhiyun * -EEXIST since there can only be one default VSI per switch.
3207*4882a593Smuzhiyun *
3208*4882a593Smuzhiyun * Otherwise try to set the VSI passed in as the switch's default VSI and
3209*4882a593Smuzhiyun * return the result.
3210*4882a593Smuzhiyun */
ice_set_dflt_vsi(struct ice_sw * sw,struct ice_vsi * vsi)3211*4882a593Smuzhiyun int ice_set_dflt_vsi(struct ice_sw *sw, struct ice_vsi *vsi)
3212*4882a593Smuzhiyun {
3213*4882a593Smuzhiyun enum ice_status status;
3214*4882a593Smuzhiyun struct device *dev;
3215*4882a593Smuzhiyun
3216*4882a593Smuzhiyun if (!sw || !vsi)
3217*4882a593Smuzhiyun return -EINVAL;
3218*4882a593Smuzhiyun
3219*4882a593Smuzhiyun dev = ice_pf_to_dev(vsi->back);
3220*4882a593Smuzhiyun
3221*4882a593Smuzhiyun /* the VSI passed in is already the default VSI */
3222*4882a593Smuzhiyun if (ice_is_vsi_dflt_vsi(sw, vsi)) {
3223*4882a593Smuzhiyun dev_dbg(dev, "VSI %d passed in is already the default forwarding VSI, nothing to do\n",
3224*4882a593Smuzhiyun vsi->vsi_num);
3225*4882a593Smuzhiyun return 0;
3226*4882a593Smuzhiyun }
3227*4882a593Smuzhiyun
3228*4882a593Smuzhiyun /* another VSI is already the default VSI for this switch */
3229*4882a593Smuzhiyun if (ice_is_dflt_vsi_in_use(sw)) {
3230*4882a593Smuzhiyun dev_err(dev, "Default forwarding VSI %d already in use, disable it and try again\n",
3231*4882a593Smuzhiyun sw->dflt_vsi->vsi_num);
3232*4882a593Smuzhiyun return -EEXIST;
3233*4882a593Smuzhiyun }
3234*4882a593Smuzhiyun
3235*4882a593Smuzhiyun status = ice_cfg_dflt_vsi(&vsi->back->hw, vsi->idx, true, ICE_FLTR_RX);
3236*4882a593Smuzhiyun if (status) {
3237*4882a593Smuzhiyun dev_err(dev, "Failed to set VSI %d as the default forwarding VSI, error %s\n",
3238*4882a593Smuzhiyun vsi->vsi_num, ice_stat_str(status));
3239*4882a593Smuzhiyun return -EIO;
3240*4882a593Smuzhiyun }
3241*4882a593Smuzhiyun
3242*4882a593Smuzhiyun sw->dflt_vsi = vsi;
3243*4882a593Smuzhiyun sw->dflt_vsi_ena = true;
3244*4882a593Smuzhiyun
3245*4882a593Smuzhiyun return 0;
3246*4882a593Smuzhiyun }
3247*4882a593Smuzhiyun
3248*4882a593Smuzhiyun /**
3249*4882a593Smuzhiyun * ice_clear_dflt_vsi - clear the default forwarding VSI
3250*4882a593Smuzhiyun * @sw: switch used to clear the default VSI
3251*4882a593Smuzhiyun *
3252*4882a593Smuzhiyun * If the switch has no default VSI or it's not enabled then return error.
3253*4882a593Smuzhiyun *
3254*4882a593Smuzhiyun * Otherwise try to clear the default VSI and return the result.
3255*4882a593Smuzhiyun */
ice_clear_dflt_vsi(struct ice_sw * sw)3256*4882a593Smuzhiyun int ice_clear_dflt_vsi(struct ice_sw *sw)
3257*4882a593Smuzhiyun {
3258*4882a593Smuzhiyun struct ice_vsi *dflt_vsi;
3259*4882a593Smuzhiyun enum ice_status status;
3260*4882a593Smuzhiyun struct device *dev;
3261*4882a593Smuzhiyun
3262*4882a593Smuzhiyun if (!sw)
3263*4882a593Smuzhiyun return -EINVAL;
3264*4882a593Smuzhiyun
3265*4882a593Smuzhiyun dev = ice_pf_to_dev(sw->pf);
3266*4882a593Smuzhiyun
3267*4882a593Smuzhiyun dflt_vsi = sw->dflt_vsi;
3268*4882a593Smuzhiyun
3269*4882a593Smuzhiyun /* there is no default VSI configured */
3270*4882a593Smuzhiyun if (!ice_is_dflt_vsi_in_use(sw))
3271*4882a593Smuzhiyun return -ENODEV;
3272*4882a593Smuzhiyun
3273*4882a593Smuzhiyun status = ice_cfg_dflt_vsi(&dflt_vsi->back->hw, dflt_vsi->idx, false,
3274*4882a593Smuzhiyun ICE_FLTR_RX);
3275*4882a593Smuzhiyun if (status) {
3276*4882a593Smuzhiyun dev_err(dev, "Failed to clear the default forwarding VSI %d, error %s\n",
3277*4882a593Smuzhiyun dflt_vsi->vsi_num, ice_stat_str(status));
3278*4882a593Smuzhiyun return -EIO;
3279*4882a593Smuzhiyun }
3280*4882a593Smuzhiyun
3281*4882a593Smuzhiyun sw->dflt_vsi = NULL;
3282*4882a593Smuzhiyun sw->dflt_vsi_ena = false;
3283*4882a593Smuzhiyun
3284*4882a593Smuzhiyun return 0;
3285*4882a593Smuzhiyun }
3286