]>
Commit | Line | Data |
---|---|---|
41c445ff JB |
1 | /******************************************************************************* |
2 | * | |
3 | * Intel Ethernet Controller XL710 Family Linux Driver | |
2818ccd9 | 4 | * Copyright(c) 2013 - 2016 Intel Corporation. |
41c445ff JB |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms and conditions of the GNU General Public License, | |
8 | * version 2, as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
dc641b73 GR |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program. If not, see <http://www.gnu.org/licenses/>. | |
41c445ff JB |
17 | * |
18 | * The full GNU General Public License is included in this distribution in | |
19 | * the file called "COPYING". | |
20 | * | |
21 | * Contact Information: | |
22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | |
23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
24 | * | |
25 | ******************************************************************************/ | |
26 | ||
b499ffb0 SV |
27 | #include <linux/etherdevice.h> |
28 | #include <linux/of_net.h> | |
29 | #include <linux/pci.h> | |
30 | ||
41c445ff JB |
31 | /* Local includes */ |
32 | #include "i40e.h" | |
4eb3f768 | 33 | #include "i40e_diag.h" |
06a5f7f1 | 34 | #include <net/udp_tunnel.h> |
ed0980c4 SP |
35 | /* All i40e tracepoints are defined by the include below, which |
36 | * must be included exactly once across the whole kernel with | |
37 | * CREATE_TRACE_POINTS defined | |
38 | */ | |
39 | #define CREATE_TRACE_POINTS | |
40 | #include "i40e_trace.h" | |
41c445ff JB |
41 | |
42 | const char i40e_driver_name[] = "i40e"; | |
43 | static const char i40e_driver_string[] = | |
44 | "Intel(R) Ethernet Connection XL710 Network Driver"; | |
45 | ||
46 | #define DRV_KERN "-k" | |
47 | ||
15990832 BP |
48 | #define DRV_VERSION_MAJOR 2 |
49 | #define DRV_VERSION_MINOR 1 | |
50 | #define DRV_VERSION_BUILD 7 | |
41c445ff JB |
51 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
52 | __stringify(DRV_VERSION_MINOR) "." \ | |
53 | __stringify(DRV_VERSION_BUILD) DRV_KERN | |
54 | const char i40e_driver_version_str[] = DRV_VERSION; | |
8fb905b3 | 55 | static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation."; |
41c445ff JB |
56 | |
57 | /* a bit of forward declarations */ | |
58 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); | |
373149fc | 59 | static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired); |
41c445ff JB |
60 | static int i40e_add_vsi(struct i40e_vsi *vsi); |
61 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi); | |
bc7d338f | 62 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); |
41c445ff JB |
63 | static int i40e_setup_misc_vector(struct i40e_pf *pf); |
64 | static void i40e_determine_queue_usage(struct i40e_pf *pf); | |
65 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); | |
373149fc MS |
66 | static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired); |
67 | static int i40e_reset(struct i40e_pf *pf); | |
68 | static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired); | |
cbf61325 | 69 | static void i40e_fdir_sb_setup(struct i40e_pf *pf); |
4e3b35b0 | 70 | static int i40e_veb_get_bw_info(struct i40e_veb *veb); |
41c445ff JB |
71 | |
72 | /* i40e_pci_tbl - PCI Device ID Table | |
73 | * | |
74 | * Last entry must be all 0s | |
75 | * | |
76 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, | |
77 | * Class, Class Mask, private data (not used) } | |
78 | */ | |
9baa3c34 | 79 | static const struct pci_device_id i40e_pci_tbl[] = { |
ab60085e | 80 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0}, |
ab60085e | 81 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0}, |
ab60085e SN |
82 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0}, |
83 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0}, | |
ab60085e SN |
84 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0}, |
85 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0}, | |
86 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0}, | |
5960d33f | 87 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0}, |
bc5166b9 | 88 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0}, |
35dae51d ASJ |
89 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0}, |
90 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0}, | |
87e6c1d7 ASJ |
91 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0}, |
92 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0}, | |
93 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0}, | |
d6bf58c2 | 94 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0}, |
48a3b512 SN |
95 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0}, |
96 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0}, | |
3123237a CW |
97 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_B), 0}, |
98 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_SFP28), 0}, | |
41c445ff JB |
99 | /* required last entry */ |
100 | {0, } | |
101 | }; | |
102 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); | |
103 | ||
104 | #define I40E_MAX_VF_COUNT 128 | |
105 | static int debug = -1; | |
5d4ca23e AD |
106 | module_param(debug, uint, 0); |
107 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)"); | |
41c445ff JB |
108 | |
109 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); | |
110 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); | |
111 | MODULE_LICENSE("GPL"); | |
112 | MODULE_VERSION(DRV_VERSION); | |
113 | ||
2803b16c JB |
114 | static struct workqueue_struct *i40e_wq; |
115 | ||
41c445ff JB |
116 | /** |
117 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code | |
118 | * @hw: pointer to the HW structure | |
119 | * @mem: ptr to mem struct to fill out | |
120 | * @size: size of memory requested | |
121 | * @alignment: what to align the allocation to | |
122 | **/ | |
123 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, | |
124 | u64 size, u32 alignment) | |
125 | { | |
126 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; | |
127 | ||
128 | mem->size = ALIGN(size, alignment); | |
129 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, | |
130 | &mem->pa, GFP_KERNEL); | |
93bc73b8 JB |
131 | if (!mem->va) |
132 | return -ENOMEM; | |
41c445ff | 133 | |
93bc73b8 | 134 | return 0; |
41c445ff JB |
135 | } |
136 | ||
137 | /** | |
138 | * i40e_free_dma_mem_d - OS specific memory free for shared code | |
139 | * @hw: pointer to the HW structure | |
140 | * @mem: ptr to mem struct to free | |
141 | **/ | |
142 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) | |
143 | { | |
144 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; | |
145 | ||
146 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); | |
147 | mem->va = NULL; | |
148 | mem->pa = 0; | |
149 | mem->size = 0; | |
150 | ||
151 | return 0; | |
152 | } | |
153 | ||
154 | /** | |
155 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code | |
156 | * @hw: pointer to the HW structure | |
157 | * @mem: ptr to mem struct to fill out | |
158 | * @size: size of memory requested | |
159 | **/ | |
160 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, | |
161 | u32 size) | |
162 | { | |
163 | mem->size = size; | |
164 | mem->va = kzalloc(size, GFP_KERNEL); | |
165 | ||
93bc73b8 JB |
166 | if (!mem->va) |
167 | return -ENOMEM; | |
41c445ff | 168 | |
93bc73b8 | 169 | return 0; |
41c445ff JB |
170 | } |
171 | ||
172 | /** | |
173 | * i40e_free_virt_mem_d - OS specific memory free for shared code | |
174 | * @hw: pointer to the HW structure | |
175 | * @mem: ptr to mem struct to free | |
176 | **/ | |
177 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) | |
178 | { | |
179 | /* it's ok to kfree a NULL pointer */ | |
180 | kfree(mem->va); | |
181 | mem->va = NULL; | |
182 | mem->size = 0; | |
183 | ||
184 | return 0; | |
185 | } | |
186 | ||
187 | /** | |
188 | * i40e_get_lump - find a lump of free generic resource | |
189 | * @pf: board private structure | |
190 | * @pile: the pile of resource to search | |
191 | * @needed: the number of items needed | |
192 | * @id: an owner id to stick on the items assigned | |
193 | * | |
194 | * Returns the base item index of the lump, or negative for error | |
195 | * | |
196 | * The search_hint trick and lack of advanced fit-finding only work | |
197 | * because we're highly likely to have all the same size lump requests. | |
198 | * Linear search time and any fragmentation should be minimal. | |
199 | **/ | |
200 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, | |
201 | u16 needed, u16 id) | |
202 | { | |
203 | int ret = -ENOMEM; | |
ddf434ac | 204 | int i, j; |
41c445ff JB |
205 | |
206 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { | |
207 | dev_info(&pf->pdev->dev, | |
208 | "param err: pile=%p needed=%d id=0x%04x\n", | |
209 | pile, needed, id); | |
210 | return -EINVAL; | |
211 | } | |
212 | ||
213 | /* start the linear search with an imperfect hint */ | |
214 | i = pile->search_hint; | |
ddf434ac | 215 | while (i < pile->num_entries) { |
41c445ff JB |
216 | /* skip already allocated entries */ |
217 | if (pile->list[i] & I40E_PILE_VALID_BIT) { | |
218 | i++; | |
219 | continue; | |
220 | } | |
221 | ||
222 | /* do we have enough in this lump? */ | |
223 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { | |
224 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) | |
225 | break; | |
226 | } | |
227 | ||
228 | if (j == needed) { | |
229 | /* there was enough, so assign it to the requestor */ | |
230 | for (j = 0; j < needed; j++) | |
231 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; | |
232 | ret = i; | |
233 | pile->search_hint = i + j; | |
ddf434ac | 234 | break; |
41c445ff | 235 | } |
6995b36c JB |
236 | |
237 | /* not enough, so skip over it and continue looking */ | |
238 | i += j; | |
41c445ff JB |
239 | } |
240 | ||
241 | return ret; | |
242 | } | |
243 | ||
244 | /** | |
245 | * i40e_put_lump - return a lump of generic resource | |
246 | * @pile: the pile of resource to search | |
247 | * @index: the base item index | |
248 | * @id: the owner id of the items assigned | |
249 | * | |
250 | * Returns the count of items in the lump | |
251 | **/ | |
252 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) | |
253 | { | |
254 | int valid_id = (id | I40E_PILE_VALID_BIT); | |
255 | int count = 0; | |
256 | int i; | |
257 | ||
258 | if (!pile || index >= pile->num_entries) | |
259 | return -EINVAL; | |
260 | ||
261 | for (i = index; | |
262 | i < pile->num_entries && pile->list[i] == valid_id; | |
263 | i++) { | |
264 | pile->list[i] = 0; | |
265 | count++; | |
266 | } | |
267 | ||
268 | if (count && index < pile->search_hint) | |
269 | pile->search_hint = index; | |
270 | ||
271 | return count; | |
272 | } | |
273 | ||
fdf0e0bf ASJ |
274 | /** |
275 | * i40e_find_vsi_from_id - searches for the vsi with the given id | |
276 | * @pf - the pf structure to search for the vsi | |
277 | * @id - id of the vsi it is searching for | |
278 | **/ | |
279 | struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id) | |
280 | { | |
281 | int i; | |
282 | ||
283 | for (i = 0; i < pf->num_alloc_vsi; i++) | |
284 | if (pf->vsi[i] && (pf->vsi[i]->id == id)) | |
285 | return pf->vsi[i]; | |
286 | ||
287 | return NULL; | |
288 | } | |
289 | ||
41c445ff JB |
290 | /** |
291 | * i40e_service_event_schedule - Schedule the service task to wake up | |
292 | * @pf: board private structure | |
293 | * | |
294 | * If not already scheduled, this puts the task into the work queue | |
295 | **/ | |
e3219ce6 | 296 | void i40e_service_event_schedule(struct i40e_pf *pf) |
41c445ff JB |
297 | { |
298 | if (!test_bit(__I40E_DOWN, &pf->state) && | |
91089033 | 299 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
2803b16c | 300 | queue_work(i40e_wq, &pf->service_task); |
41c445ff JB |
301 | } |
302 | ||
303 | /** | |
304 | * i40e_tx_timeout - Respond to a Tx Hang | |
305 | * @netdev: network interface device structure | |
306 | * | |
307 | * If any port has noticed a Tx timeout, it is likely that the whole | |
308 | * device is munged, not just the one netdev port, so go for the full | |
309 | * reset. | |
310 | **/ | |
311 | static void i40e_tx_timeout(struct net_device *netdev) | |
312 | { | |
313 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
314 | struct i40e_vsi *vsi = np->vsi; | |
315 | struct i40e_pf *pf = vsi->back; | |
b03a8c1f KP |
316 | struct i40e_ring *tx_ring = NULL; |
317 | unsigned int i, hung_queue = 0; | |
318 | u32 head, val; | |
41c445ff JB |
319 | |
320 | pf->tx_timeout_count++; | |
321 | ||
b03a8c1f KP |
322 | /* find the stopped queue the same way the stack does */ |
323 | for (i = 0; i < netdev->num_tx_queues; i++) { | |
324 | struct netdev_queue *q; | |
325 | unsigned long trans_start; | |
326 | ||
327 | q = netdev_get_tx_queue(netdev, i); | |
9b36627a | 328 | trans_start = q->trans_start; |
b03a8c1f KP |
329 | if (netif_xmit_stopped(q) && |
330 | time_after(jiffies, | |
331 | (trans_start + netdev->watchdog_timeo))) { | |
332 | hung_queue = i; | |
333 | break; | |
334 | } | |
335 | } | |
336 | ||
337 | if (i == netdev->num_tx_queues) { | |
338 | netdev_info(netdev, "tx_timeout: no netdev hung queue found\n"); | |
339 | } else { | |
340 | /* now that we have an index, find the tx_ring struct */ | |
341 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
342 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { | |
343 | if (hung_queue == | |
344 | vsi->tx_rings[i]->queue_index) { | |
345 | tx_ring = vsi->tx_rings[i]; | |
346 | break; | |
347 | } | |
348 | } | |
349 | } | |
350 | } | |
351 | ||
41c445ff | 352 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
b03a8c1f KP |
353 | pf->tx_timeout_recovery_level = 1; /* reset after some time */ |
354 | else if (time_before(jiffies, | |
355 | (pf->tx_timeout_last_recovery + netdev->watchdog_timeo))) | |
356 | return; /* don't do any new action before the next timeout */ | |
357 | ||
358 | if (tx_ring) { | |
359 | head = i40e_get_head(tx_ring); | |
360 | /* Read interrupt register */ | |
361 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) | |
362 | val = rd32(&pf->hw, | |
363 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + | |
364 | tx_ring->vsi->base_vector - 1)); | |
365 | else | |
366 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); | |
367 | ||
368 | netdev_info(netdev, "tx_timeout: VSI_seid: %d, Q %d, NTC: 0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x, INT: 0x%x\n", | |
369 | vsi->seid, hung_queue, tx_ring->next_to_clean, | |
370 | head, tx_ring->next_to_use, | |
371 | readl(tx_ring->tail), val); | |
372 | } | |
373 | ||
41c445ff | 374 | pf->tx_timeout_last_recovery = jiffies; |
b03a8c1f KP |
375 | netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n", |
376 | pf->tx_timeout_recovery_level, hung_queue); | |
41c445ff JB |
377 | |
378 | switch (pf->tx_timeout_recovery_level) { | |
41c445ff JB |
379 | case 1: |
380 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); | |
381 | break; | |
382 | case 2: | |
383 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); | |
384 | break; | |
385 | case 3: | |
386 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); | |
387 | break; | |
388 | default: | |
389 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); | |
41c445ff JB |
390 | break; |
391 | } | |
b03a8c1f | 392 | |
41c445ff JB |
393 | i40e_service_event_schedule(pf); |
394 | pf->tx_timeout_recovery_level++; | |
395 | } | |
396 | ||
41c445ff JB |
397 | /** |
398 | * i40e_get_vsi_stats_struct - Get System Network Statistics | |
399 | * @vsi: the VSI we care about | |
400 | * | |
401 | * Returns the address of the device statistics structure. | |
402 | * The statistics are actually updated from the service task. | |
403 | **/ | |
404 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) | |
405 | { | |
406 | return &vsi->net_stats; | |
407 | } | |
408 | ||
409 | /** | |
410 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface | |
411 | * @netdev: network interface device structure | |
412 | * | |
413 | * Returns the address of the device statistics structure. | |
414 | * The statistics are actually updated from the service task. | |
415 | **/ | |
9eed69a9 | 416 | static void i40e_get_netdev_stats_struct(struct net_device *netdev, |
bc1f4470 | 417 | struct rtnl_link_stats64 *stats) |
41c445ff JB |
418 | { |
419 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
e7046ee1 | 420 | struct i40e_ring *tx_ring, *rx_ring; |
41c445ff | 421 | struct i40e_vsi *vsi = np->vsi; |
980e9b11 AD |
422 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
423 | int i; | |
424 | ||
bc7d338f | 425 | if (test_bit(__I40E_DOWN, &vsi->state)) |
bc1f4470 | 426 | return; |
bc7d338f | 427 | |
3c325ced | 428 | if (!vsi->tx_rings) |
bc1f4470 | 429 | return; |
3c325ced | 430 | |
980e9b11 AD |
431 | rcu_read_lock(); |
432 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
980e9b11 AD |
433 | u64 bytes, packets; |
434 | unsigned int start; | |
435 | ||
436 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); | |
437 | if (!tx_ring) | |
438 | continue; | |
439 | ||
440 | do { | |
57a7744e | 441 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
980e9b11 AD |
442 | packets = tx_ring->stats.packets; |
443 | bytes = tx_ring->stats.bytes; | |
57a7744e | 444 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
980e9b11 AD |
445 | |
446 | stats->tx_packets += packets; | |
447 | stats->tx_bytes += bytes; | |
448 | rx_ring = &tx_ring[1]; | |
449 | ||
450 | do { | |
57a7744e | 451 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
980e9b11 AD |
452 | packets = rx_ring->stats.packets; |
453 | bytes = rx_ring->stats.bytes; | |
57a7744e | 454 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
41c445ff | 455 | |
980e9b11 AD |
456 | stats->rx_packets += packets; |
457 | stats->rx_bytes += bytes; | |
458 | } | |
459 | rcu_read_unlock(); | |
460 | ||
a5282f44 | 461 | /* following stats updated by i40e_watchdog_subtask() */ |
980e9b11 AD |
462 | stats->multicast = vsi_stats->multicast; |
463 | stats->tx_errors = vsi_stats->tx_errors; | |
464 | stats->tx_dropped = vsi_stats->tx_dropped; | |
465 | stats->rx_errors = vsi_stats->rx_errors; | |
d8201e20 | 466 | stats->rx_dropped = vsi_stats->rx_dropped; |
980e9b11 AD |
467 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
468 | stats->rx_length_errors = vsi_stats->rx_length_errors; | |
41c445ff JB |
469 | } |
470 | ||
471 | /** | |
472 | * i40e_vsi_reset_stats - Resets all stats of the given vsi | |
473 | * @vsi: the VSI to have its stats reset | |
474 | **/ | |
475 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) | |
476 | { | |
477 | struct rtnl_link_stats64 *ns; | |
478 | int i; | |
479 | ||
480 | if (!vsi) | |
481 | return; | |
482 | ||
483 | ns = i40e_get_vsi_stats_struct(vsi); | |
484 | memset(ns, 0, sizeof(*ns)); | |
485 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); | |
486 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); | |
487 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); | |
8e9dca53 | 488 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
41c445ff | 489 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
6995b36c | 490 | memset(&vsi->rx_rings[i]->stats, 0, |
9f65e15b | 491 | sizeof(vsi->rx_rings[i]->stats)); |
6995b36c | 492 | memset(&vsi->rx_rings[i]->rx_stats, 0, |
9f65e15b | 493 | sizeof(vsi->rx_rings[i]->rx_stats)); |
6995b36c | 494 | memset(&vsi->tx_rings[i]->stats, 0, |
9f65e15b AD |
495 | sizeof(vsi->tx_rings[i]->stats)); |
496 | memset(&vsi->tx_rings[i]->tx_stats, 0, | |
497 | sizeof(vsi->tx_rings[i]->tx_stats)); | |
41c445ff | 498 | } |
8e9dca53 | 499 | } |
41c445ff JB |
500 | vsi->stat_offsets_loaded = false; |
501 | } | |
502 | ||
503 | /** | |
b40c82e6 | 504 | * i40e_pf_reset_stats - Reset all of the stats for the given PF |
41c445ff JB |
505 | * @pf: the PF to be reset |
506 | **/ | |
507 | void i40e_pf_reset_stats(struct i40e_pf *pf) | |
508 | { | |
e91fdf76 SN |
509 | int i; |
510 | ||
41c445ff JB |
511 | memset(&pf->stats, 0, sizeof(pf->stats)); |
512 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); | |
513 | pf->stat_offsets_loaded = false; | |
e91fdf76 SN |
514 | |
515 | for (i = 0; i < I40E_MAX_VEB; i++) { | |
516 | if (pf->veb[i]) { | |
517 | memset(&pf->veb[i]->stats, 0, | |
518 | sizeof(pf->veb[i]->stats)); | |
519 | memset(&pf->veb[i]->stats_offsets, 0, | |
520 | sizeof(pf->veb[i]->stats_offsets)); | |
521 | pf->veb[i]->stat_offsets_loaded = false; | |
522 | } | |
523 | } | |
42bce04e | 524 | pf->hw_csum_rx_error = 0; |
41c445ff JB |
525 | } |
526 | ||
527 | /** | |
528 | * i40e_stat_update48 - read and update a 48 bit stat from the chip | |
529 | * @hw: ptr to the hardware info | |
530 | * @hireg: the high 32 bit reg to read | |
531 | * @loreg: the low 32 bit reg to read | |
532 | * @offset_loaded: has the initial offset been loaded yet | |
533 | * @offset: ptr to current offset value | |
534 | * @stat: ptr to the stat | |
535 | * | |
536 | * Since the device stats are not reset at PFReset, they likely will not | |
537 | * be zeroed when the driver starts. We'll save the first values read | |
538 | * and use them as offsets to be subtracted from the raw values in order | |
539 | * to report stats that count from zero. In the process, we also manage | |
540 | * the potential roll-over. | |
541 | **/ | |
542 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, | |
543 | bool offset_loaded, u64 *offset, u64 *stat) | |
544 | { | |
545 | u64 new_data; | |
546 | ||
ab60085e | 547 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
41c445ff JB |
548 | new_data = rd32(hw, loreg); |
549 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; | |
550 | } else { | |
551 | new_data = rd64(hw, loreg); | |
552 | } | |
553 | if (!offset_loaded) | |
554 | *offset = new_data; | |
555 | if (likely(new_data >= *offset)) | |
556 | *stat = new_data - *offset; | |
557 | else | |
41a1d04b | 558 | *stat = (new_data + BIT_ULL(48)) - *offset; |
41c445ff JB |
559 | *stat &= 0xFFFFFFFFFFFFULL; |
560 | } | |
561 | ||
562 | /** | |
563 | * i40e_stat_update32 - read and update a 32 bit stat from the chip | |
564 | * @hw: ptr to the hardware info | |
565 | * @reg: the hw reg to read | |
566 | * @offset_loaded: has the initial offset been loaded yet | |
567 | * @offset: ptr to current offset value | |
568 | * @stat: ptr to the stat | |
569 | **/ | |
570 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, | |
571 | bool offset_loaded, u64 *offset, u64 *stat) | |
572 | { | |
573 | u32 new_data; | |
574 | ||
575 | new_data = rd32(hw, reg); | |
576 | if (!offset_loaded) | |
577 | *offset = new_data; | |
578 | if (likely(new_data >= *offset)) | |
579 | *stat = (u32)(new_data - *offset); | |
580 | else | |
41a1d04b | 581 | *stat = (u32)((new_data + BIT_ULL(32)) - *offset); |
41c445ff JB |
582 | } |
583 | ||
584 | /** | |
585 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. | |
586 | * @vsi: the VSI to be updated | |
587 | **/ | |
588 | void i40e_update_eth_stats(struct i40e_vsi *vsi) | |
589 | { | |
590 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); | |
591 | struct i40e_pf *pf = vsi->back; | |
592 | struct i40e_hw *hw = &pf->hw; | |
593 | struct i40e_eth_stats *oes; | |
594 | struct i40e_eth_stats *es; /* device's eth stats */ | |
595 | ||
596 | es = &vsi->eth_stats; | |
597 | oes = &vsi->eth_stats_offsets; | |
598 | ||
599 | /* Gather up the stats that the hw collects */ | |
600 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), | |
601 | vsi->stat_offsets_loaded, | |
602 | &oes->tx_errors, &es->tx_errors); | |
603 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), | |
604 | vsi->stat_offsets_loaded, | |
605 | &oes->rx_discards, &es->rx_discards); | |
41a9e55c SN |
606 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
607 | vsi->stat_offsets_loaded, | |
608 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); | |
609 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), | |
610 | vsi->stat_offsets_loaded, | |
611 | &oes->tx_errors, &es->tx_errors); | |
41c445ff JB |
612 | |
613 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), | |
614 | I40E_GLV_GORCL(stat_idx), | |
615 | vsi->stat_offsets_loaded, | |
616 | &oes->rx_bytes, &es->rx_bytes); | |
617 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), | |
618 | I40E_GLV_UPRCL(stat_idx), | |
619 | vsi->stat_offsets_loaded, | |
620 | &oes->rx_unicast, &es->rx_unicast); | |
621 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), | |
622 | I40E_GLV_MPRCL(stat_idx), | |
623 | vsi->stat_offsets_loaded, | |
624 | &oes->rx_multicast, &es->rx_multicast); | |
625 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), | |
626 | I40E_GLV_BPRCL(stat_idx), | |
627 | vsi->stat_offsets_loaded, | |
628 | &oes->rx_broadcast, &es->rx_broadcast); | |
629 | ||
630 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), | |
631 | I40E_GLV_GOTCL(stat_idx), | |
632 | vsi->stat_offsets_loaded, | |
633 | &oes->tx_bytes, &es->tx_bytes); | |
634 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), | |
635 | I40E_GLV_UPTCL(stat_idx), | |
636 | vsi->stat_offsets_loaded, | |
637 | &oes->tx_unicast, &es->tx_unicast); | |
638 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), | |
639 | I40E_GLV_MPTCL(stat_idx), | |
640 | vsi->stat_offsets_loaded, | |
641 | &oes->tx_multicast, &es->tx_multicast); | |
642 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), | |
643 | I40E_GLV_BPTCL(stat_idx), | |
644 | vsi->stat_offsets_loaded, | |
645 | &oes->tx_broadcast, &es->tx_broadcast); | |
646 | vsi->stat_offsets_loaded = true; | |
647 | } | |
648 | ||
649 | /** | |
650 | * i40e_update_veb_stats - Update Switch component statistics | |
651 | * @veb: the VEB being updated | |
652 | **/ | |
653 | static void i40e_update_veb_stats(struct i40e_veb *veb) | |
654 | { | |
655 | struct i40e_pf *pf = veb->pf; | |
656 | struct i40e_hw *hw = &pf->hw; | |
657 | struct i40e_eth_stats *oes; | |
658 | struct i40e_eth_stats *es; /* device's eth stats */ | |
fe860afb NP |
659 | struct i40e_veb_tc_stats *veb_oes; |
660 | struct i40e_veb_tc_stats *veb_es; | |
661 | int i, idx = 0; | |
41c445ff JB |
662 | |
663 | idx = veb->stats_idx; | |
664 | es = &veb->stats; | |
665 | oes = &veb->stats_offsets; | |
fe860afb NP |
666 | veb_es = &veb->tc_stats; |
667 | veb_oes = &veb->tc_stats_offsets; | |
41c445ff JB |
668 | |
669 | /* Gather up the stats that the hw collects */ | |
670 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), | |
671 | veb->stat_offsets_loaded, | |
672 | &oes->tx_discards, &es->tx_discards); | |
7134f9ce JB |
673 | if (hw->revision_id > 0) |
674 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), | |
675 | veb->stat_offsets_loaded, | |
676 | &oes->rx_unknown_protocol, | |
677 | &es->rx_unknown_protocol); | |
41c445ff JB |
678 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
679 | veb->stat_offsets_loaded, | |
680 | &oes->rx_bytes, &es->rx_bytes); | |
681 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), | |
682 | veb->stat_offsets_loaded, | |
683 | &oes->rx_unicast, &es->rx_unicast); | |
684 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), | |
685 | veb->stat_offsets_loaded, | |
686 | &oes->rx_multicast, &es->rx_multicast); | |
687 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), | |
688 | veb->stat_offsets_loaded, | |
689 | &oes->rx_broadcast, &es->rx_broadcast); | |
690 | ||
691 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), | |
692 | veb->stat_offsets_loaded, | |
693 | &oes->tx_bytes, &es->tx_bytes); | |
694 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), | |
695 | veb->stat_offsets_loaded, | |
696 | &oes->tx_unicast, &es->tx_unicast); | |
697 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), | |
698 | veb->stat_offsets_loaded, | |
699 | &oes->tx_multicast, &es->tx_multicast); | |
700 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), | |
701 | veb->stat_offsets_loaded, | |
702 | &oes->tx_broadcast, &es->tx_broadcast); | |
fe860afb NP |
703 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
704 | i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx), | |
705 | I40E_GLVEBTC_RPCL(i, idx), | |
706 | veb->stat_offsets_loaded, | |
707 | &veb_oes->tc_rx_packets[i], | |
708 | &veb_es->tc_rx_packets[i]); | |
709 | i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx), | |
710 | I40E_GLVEBTC_RBCL(i, idx), | |
711 | veb->stat_offsets_loaded, | |
712 | &veb_oes->tc_rx_bytes[i], | |
713 | &veb_es->tc_rx_bytes[i]); | |
714 | i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx), | |
715 | I40E_GLVEBTC_TPCL(i, idx), | |
716 | veb->stat_offsets_loaded, | |
717 | &veb_oes->tc_tx_packets[i], | |
718 | &veb_es->tc_tx_packets[i]); | |
719 | i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx), | |
720 | I40E_GLVEBTC_TBCL(i, idx), | |
721 | veb->stat_offsets_loaded, | |
722 | &veb_oes->tc_tx_bytes[i], | |
723 | &veb_es->tc_tx_bytes[i]); | |
724 | } | |
41c445ff JB |
725 | veb->stat_offsets_loaded = true; |
726 | } | |
727 | ||
41c445ff | 728 | /** |
7812fddc | 729 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
41c445ff JB |
730 | * @vsi: the VSI to be updated |
731 | * | |
732 | * There are a few instances where we store the same stat in a | |
733 | * couple of different structs. This is partly because we have | |
734 | * the netdev stats that need to be filled out, which is slightly | |
735 | * different from the "eth_stats" defined by the chip and used in | |
7812fddc | 736 | * VF communications. We sort it out here. |
41c445ff | 737 | **/ |
7812fddc | 738 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
41c445ff JB |
739 | { |
740 | struct i40e_pf *pf = vsi->back; | |
41c445ff JB |
741 | struct rtnl_link_stats64 *ons; |
742 | struct rtnl_link_stats64 *ns; /* netdev stats */ | |
743 | struct i40e_eth_stats *oes; | |
744 | struct i40e_eth_stats *es; /* device's eth stats */ | |
745 | u32 tx_restart, tx_busy; | |
bf00b376 | 746 | struct i40e_ring *p; |
41c445ff | 747 | u32 rx_page, rx_buf; |
bf00b376 AA |
748 | u64 bytes, packets; |
749 | unsigned int start; | |
2fc3d715 | 750 | u64 tx_linearize; |
164c9f54 | 751 | u64 tx_force_wb; |
41c445ff JB |
752 | u64 rx_p, rx_b; |
753 | u64 tx_p, tx_b; | |
41c445ff JB |
754 | u16 q; |
755 | ||
756 | if (test_bit(__I40E_DOWN, &vsi->state) || | |
757 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) | |
758 | return; | |
759 | ||
760 | ns = i40e_get_vsi_stats_struct(vsi); | |
761 | ons = &vsi->net_stats_offsets; | |
762 | es = &vsi->eth_stats; | |
763 | oes = &vsi->eth_stats_offsets; | |
764 | ||
765 | /* Gather up the netdev and vsi stats that the driver collects | |
766 | * on the fly during packet processing | |
767 | */ | |
768 | rx_b = rx_p = 0; | |
769 | tx_b = tx_p = 0; | |
164c9f54 | 770 | tx_restart = tx_busy = tx_linearize = tx_force_wb = 0; |
41c445ff JB |
771 | rx_page = 0; |
772 | rx_buf = 0; | |
980e9b11 | 773 | rcu_read_lock(); |
41c445ff | 774 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
980e9b11 AD |
775 | /* locate Tx ring */ |
776 | p = ACCESS_ONCE(vsi->tx_rings[q]); | |
777 | ||
778 | do { | |
57a7744e | 779 | start = u64_stats_fetch_begin_irq(&p->syncp); |
980e9b11 AD |
780 | packets = p->stats.packets; |
781 | bytes = p->stats.bytes; | |
57a7744e | 782 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
980e9b11 AD |
783 | tx_b += bytes; |
784 | tx_p += packets; | |
785 | tx_restart += p->tx_stats.restart_queue; | |
786 | tx_busy += p->tx_stats.tx_busy; | |
2fc3d715 | 787 | tx_linearize += p->tx_stats.tx_linearize; |
164c9f54 | 788 | tx_force_wb += p->tx_stats.tx_force_wb; |
41c445ff | 789 | |
980e9b11 AD |
790 | /* Rx queue is part of the same block as Tx queue */ |
791 | p = &p[1]; | |
792 | do { | |
57a7744e | 793 | start = u64_stats_fetch_begin_irq(&p->syncp); |
980e9b11 AD |
794 | packets = p->stats.packets; |
795 | bytes = p->stats.bytes; | |
57a7744e | 796 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
980e9b11 AD |
797 | rx_b += bytes; |
798 | rx_p += packets; | |
420136cc MW |
799 | rx_buf += p->rx_stats.alloc_buff_failed; |
800 | rx_page += p->rx_stats.alloc_page_failed; | |
41c445ff | 801 | } |
980e9b11 | 802 | rcu_read_unlock(); |
41c445ff JB |
803 | vsi->tx_restart = tx_restart; |
804 | vsi->tx_busy = tx_busy; | |
2fc3d715 | 805 | vsi->tx_linearize = tx_linearize; |
164c9f54 | 806 | vsi->tx_force_wb = tx_force_wb; |
41c445ff JB |
807 | vsi->rx_page_failed = rx_page; |
808 | vsi->rx_buf_failed = rx_buf; | |
809 | ||
810 | ns->rx_packets = rx_p; | |
811 | ns->rx_bytes = rx_b; | |
812 | ns->tx_packets = tx_p; | |
813 | ns->tx_bytes = tx_b; | |
814 | ||
41c445ff | 815 | /* update netdev stats from eth stats */ |
7812fddc | 816 | i40e_update_eth_stats(vsi); |
41c445ff JB |
817 | ons->tx_errors = oes->tx_errors; |
818 | ns->tx_errors = es->tx_errors; | |
819 | ons->multicast = oes->rx_multicast; | |
820 | ns->multicast = es->rx_multicast; | |
41a9e55c SN |
821 | ons->rx_dropped = oes->rx_discards; |
822 | ns->rx_dropped = es->rx_discards; | |
41c445ff JB |
823 | ons->tx_dropped = oes->tx_discards; |
824 | ns->tx_dropped = es->tx_discards; | |
825 | ||
7812fddc | 826 | /* pull in a couple PF stats if this is the main vsi */ |
41c445ff | 827 | if (vsi == pf->vsi[pf->lan_vsi]) { |
7812fddc SN |
828 | ns->rx_crc_errors = pf->stats.crc_errors; |
829 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; | |
830 | ns->rx_length_errors = pf->stats.rx_length_errors; | |
831 | } | |
832 | } | |
41c445ff | 833 | |
7812fddc | 834 | /** |
b40c82e6 | 835 | * i40e_update_pf_stats - Update the PF statistics counters. |
7812fddc SN |
836 | * @pf: the PF to be updated |
837 | **/ | |
838 | static void i40e_update_pf_stats(struct i40e_pf *pf) | |
839 | { | |
840 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; | |
841 | struct i40e_hw_port_stats *nsd = &pf->stats; | |
842 | struct i40e_hw *hw = &pf->hw; | |
843 | u32 val; | |
844 | int i; | |
41c445ff | 845 | |
7812fddc SN |
846 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
847 | I40E_GLPRT_GORCL(hw->port), | |
848 | pf->stat_offsets_loaded, | |
849 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); | |
850 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), | |
851 | I40E_GLPRT_GOTCL(hw->port), | |
852 | pf->stat_offsets_loaded, | |
853 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); | |
854 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), | |
855 | pf->stat_offsets_loaded, | |
856 | &osd->eth.rx_discards, | |
857 | &nsd->eth.rx_discards); | |
532d283d SN |
858 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
859 | I40E_GLPRT_UPRCL(hw->port), | |
860 | pf->stat_offsets_loaded, | |
861 | &osd->eth.rx_unicast, | |
862 | &nsd->eth.rx_unicast); | |
7812fddc SN |
863 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
864 | I40E_GLPRT_MPRCL(hw->port), | |
865 | pf->stat_offsets_loaded, | |
866 | &osd->eth.rx_multicast, | |
867 | &nsd->eth.rx_multicast); | |
532d283d SN |
868 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
869 | I40E_GLPRT_BPRCL(hw->port), | |
870 | pf->stat_offsets_loaded, | |
871 | &osd->eth.rx_broadcast, | |
872 | &nsd->eth.rx_broadcast); | |
873 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), | |
874 | I40E_GLPRT_UPTCL(hw->port), | |
875 | pf->stat_offsets_loaded, | |
876 | &osd->eth.tx_unicast, | |
877 | &nsd->eth.tx_unicast); | |
878 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), | |
879 | I40E_GLPRT_MPTCL(hw->port), | |
880 | pf->stat_offsets_loaded, | |
881 | &osd->eth.tx_multicast, | |
882 | &nsd->eth.tx_multicast); | |
883 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), | |
884 | I40E_GLPRT_BPTCL(hw->port), | |
885 | pf->stat_offsets_loaded, | |
886 | &osd->eth.tx_broadcast, | |
887 | &nsd->eth.tx_broadcast); | |
41c445ff | 888 | |
7812fddc SN |
889 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
890 | pf->stat_offsets_loaded, | |
891 | &osd->tx_dropped_link_down, | |
892 | &nsd->tx_dropped_link_down); | |
41c445ff | 893 | |
7812fddc SN |
894 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
895 | pf->stat_offsets_loaded, | |
896 | &osd->crc_errors, &nsd->crc_errors); | |
41c445ff | 897 | |
7812fddc SN |
898 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
899 | pf->stat_offsets_loaded, | |
900 | &osd->illegal_bytes, &nsd->illegal_bytes); | |
41c445ff | 901 | |
7812fddc SN |
902 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
903 | pf->stat_offsets_loaded, | |
904 | &osd->mac_local_faults, | |
905 | &nsd->mac_local_faults); | |
906 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), | |
907 | pf->stat_offsets_loaded, | |
908 | &osd->mac_remote_faults, | |
909 | &nsd->mac_remote_faults); | |
41c445ff | 910 | |
7812fddc SN |
911 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
912 | pf->stat_offsets_loaded, | |
913 | &osd->rx_length_errors, | |
914 | &nsd->rx_length_errors); | |
41c445ff | 915 | |
7812fddc SN |
916 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
917 | pf->stat_offsets_loaded, | |
918 | &osd->link_xon_rx, &nsd->link_xon_rx); | |
919 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), | |
920 | pf->stat_offsets_loaded, | |
921 | &osd->link_xon_tx, &nsd->link_xon_tx); | |
95db239f NP |
922 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
923 | pf->stat_offsets_loaded, | |
924 | &osd->link_xoff_rx, &nsd->link_xoff_rx); | |
7812fddc SN |
925 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
926 | pf->stat_offsets_loaded, | |
927 | &osd->link_xoff_tx, &nsd->link_xoff_tx); | |
41c445ff | 928 | |
7812fddc | 929 | for (i = 0; i < 8; i++) { |
95db239f NP |
930 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
931 | pf->stat_offsets_loaded, | |
932 | &osd->priority_xoff_rx[i], | |
933 | &nsd->priority_xoff_rx[i]); | |
7812fddc | 934 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
41c445ff | 935 | pf->stat_offsets_loaded, |
7812fddc SN |
936 | &osd->priority_xon_rx[i], |
937 | &nsd->priority_xon_rx[i]); | |
938 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), | |
41c445ff | 939 | pf->stat_offsets_loaded, |
7812fddc SN |
940 | &osd->priority_xon_tx[i], |
941 | &nsd->priority_xon_tx[i]); | |
942 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), | |
41c445ff | 943 | pf->stat_offsets_loaded, |
7812fddc SN |
944 | &osd->priority_xoff_tx[i], |
945 | &nsd->priority_xoff_tx[i]); | |
946 | i40e_stat_update32(hw, | |
947 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), | |
bee5af7e | 948 | pf->stat_offsets_loaded, |
7812fddc SN |
949 | &osd->priority_xon_2_xoff[i], |
950 | &nsd->priority_xon_2_xoff[i]); | |
41c445ff JB |
951 | } |
952 | ||
7812fddc SN |
953 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
954 | I40E_GLPRT_PRC64L(hw->port), | |
955 | pf->stat_offsets_loaded, | |
956 | &osd->rx_size_64, &nsd->rx_size_64); | |
957 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), | |
958 | I40E_GLPRT_PRC127L(hw->port), | |
959 | pf->stat_offsets_loaded, | |
960 | &osd->rx_size_127, &nsd->rx_size_127); | |
961 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), | |
962 | I40E_GLPRT_PRC255L(hw->port), | |
963 | pf->stat_offsets_loaded, | |
964 | &osd->rx_size_255, &nsd->rx_size_255); | |
965 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), | |
966 | I40E_GLPRT_PRC511L(hw->port), | |
967 | pf->stat_offsets_loaded, | |
968 | &osd->rx_size_511, &nsd->rx_size_511); | |
969 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), | |
970 | I40E_GLPRT_PRC1023L(hw->port), | |
971 | pf->stat_offsets_loaded, | |
972 | &osd->rx_size_1023, &nsd->rx_size_1023); | |
973 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), | |
974 | I40E_GLPRT_PRC1522L(hw->port), | |
975 | pf->stat_offsets_loaded, | |
976 | &osd->rx_size_1522, &nsd->rx_size_1522); | |
977 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), | |
978 | I40E_GLPRT_PRC9522L(hw->port), | |
979 | pf->stat_offsets_loaded, | |
980 | &osd->rx_size_big, &nsd->rx_size_big); | |
981 | ||
982 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), | |
983 | I40E_GLPRT_PTC64L(hw->port), | |
984 | pf->stat_offsets_loaded, | |
985 | &osd->tx_size_64, &nsd->tx_size_64); | |
986 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), | |
987 | I40E_GLPRT_PTC127L(hw->port), | |
988 | pf->stat_offsets_loaded, | |
989 | &osd->tx_size_127, &nsd->tx_size_127); | |
990 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), | |
991 | I40E_GLPRT_PTC255L(hw->port), | |
992 | pf->stat_offsets_loaded, | |
993 | &osd->tx_size_255, &nsd->tx_size_255); | |
994 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), | |
995 | I40E_GLPRT_PTC511L(hw->port), | |
996 | pf->stat_offsets_loaded, | |
997 | &osd->tx_size_511, &nsd->tx_size_511); | |
998 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), | |
999 | I40E_GLPRT_PTC1023L(hw->port), | |
1000 | pf->stat_offsets_loaded, | |
1001 | &osd->tx_size_1023, &nsd->tx_size_1023); | |
1002 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), | |
1003 | I40E_GLPRT_PTC1522L(hw->port), | |
1004 | pf->stat_offsets_loaded, | |
1005 | &osd->tx_size_1522, &nsd->tx_size_1522); | |
1006 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), | |
1007 | I40E_GLPRT_PTC9522L(hw->port), | |
1008 | pf->stat_offsets_loaded, | |
1009 | &osd->tx_size_big, &nsd->tx_size_big); | |
1010 | ||
1011 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), | |
1012 | pf->stat_offsets_loaded, | |
1013 | &osd->rx_undersize, &nsd->rx_undersize); | |
1014 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), | |
1015 | pf->stat_offsets_loaded, | |
1016 | &osd->rx_fragments, &nsd->rx_fragments); | |
1017 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), | |
1018 | pf->stat_offsets_loaded, | |
1019 | &osd->rx_oversize, &nsd->rx_oversize); | |
1020 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), | |
1021 | pf->stat_offsets_loaded, | |
1022 | &osd->rx_jabber, &nsd->rx_jabber); | |
1023 | ||
433c47de | 1024 | /* FDIR stats */ |
0bf4b1b0 ASJ |
1025 | i40e_stat_update32(hw, |
1026 | I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)), | |
433c47de ASJ |
1027 | pf->stat_offsets_loaded, |
1028 | &osd->fd_atr_match, &nsd->fd_atr_match); | |
0bf4b1b0 ASJ |
1029 | i40e_stat_update32(hw, |
1030 | I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)), | |
433c47de ASJ |
1031 | pf->stat_offsets_loaded, |
1032 | &osd->fd_sb_match, &nsd->fd_sb_match); | |
60ccd45c ASJ |
1033 | i40e_stat_update32(hw, |
1034 | I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)), | |
1035 | pf->stat_offsets_loaded, | |
1036 | &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match); | |
433c47de | 1037 | |
7812fddc SN |
1038 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
1039 | nsd->tx_lpi_status = | |
1040 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> | |
1041 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; | |
1042 | nsd->rx_lpi_status = | |
1043 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> | |
1044 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; | |
1045 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, | |
1046 | pf->stat_offsets_loaded, | |
1047 | &osd->tx_lpi_count, &nsd->tx_lpi_count); | |
1048 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, | |
1049 | pf->stat_offsets_loaded, | |
1050 | &osd->rx_lpi_count, &nsd->rx_lpi_count); | |
1051 | ||
d0389e51 | 1052 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED && |
b77ac975 | 1053 | !(pf->hw_disabled_flags & I40E_FLAG_FD_SB_ENABLED)) |
d0389e51 ASJ |
1054 | nsd->fd_sb_status = true; |
1055 | else | |
1056 | nsd->fd_sb_status = false; | |
1057 | ||
1058 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED && | |
b77ac975 | 1059 | !(pf->hw_disabled_flags & I40E_FLAG_FD_ATR_ENABLED)) |
d0389e51 ASJ |
1060 | nsd->fd_atr_status = true; |
1061 | else | |
1062 | nsd->fd_atr_status = false; | |
1063 | ||
41c445ff JB |
1064 | pf->stat_offsets_loaded = true; |
1065 | } | |
1066 | ||
7812fddc SN |
1067 | /** |
1068 | * i40e_update_stats - Update the various statistics counters. | |
1069 | * @vsi: the VSI to be updated | |
1070 | * | |
1071 | * Update the various stats for this VSI and its related entities. | |
1072 | **/ | |
1073 | void i40e_update_stats(struct i40e_vsi *vsi) | |
1074 | { | |
1075 | struct i40e_pf *pf = vsi->back; | |
1076 | ||
1077 | if (vsi == pf->vsi[pf->lan_vsi]) | |
1078 | i40e_update_pf_stats(pf); | |
1079 | ||
1080 | i40e_update_vsi_stats(vsi); | |
1081 | } | |
1082 | ||
41c445ff JB |
1083 | /** |
1084 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter | |
1085 | * @vsi: the VSI to be searched | |
1086 | * @macaddr: the MAC address | |
1087 | * @vlan: the vlan | |
41c445ff JB |
1088 | * |
1089 | * Returns ptr to the filter object or NULL | |
1090 | **/ | |
1091 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, | |
6622f5cd | 1092 | const u8 *macaddr, s16 vlan) |
41c445ff JB |
1093 | { |
1094 | struct i40e_mac_filter *f; | |
278e7d0b | 1095 | u64 key; |
41c445ff JB |
1096 | |
1097 | if (!vsi || !macaddr) | |
1098 | return NULL; | |
1099 | ||
278e7d0b JK |
1100 | key = i40e_addr_to_hkey(macaddr); |
1101 | hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) { | |
41c445ff | 1102 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
1bc87e80 | 1103 | (vlan == f->vlan)) |
41c445ff JB |
1104 | return f; |
1105 | } | |
1106 | return NULL; | |
1107 | } | |
1108 | ||
1109 | /** | |
1110 | * i40e_find_mac - Find a mac addr in the macvlan filters list | |
1111 | * @vsi: the VSI to be searched | |
1112 | * @macaddr: the MAC address we are searching for | |
41c445ff JB |
1113 | * |
1114 | * Returns the first filter with the provided MAC address or NULL if | |
1115 | * MAC address was not found | |
1116 | **/ | |
6622f5cd | 1117 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr) |
41c445ff JB |
1118 | { |
1119 | struct i40e_mac_filter *f; | |
278e7d0b | 1120 | u64 key; |
41c445ff JB |
1121 | |
1122 | if (!vsi || !macaddr) | |
1123 | return NULL; | |
1124 | ||
278e7d0b JK |
1125 | key = i40e_addr_to_hkey(macaddr); |
1126 | hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) { | |
1bc87e80 | 1127 | if ((ether_addr_equal(macaddr, f->macaddr))) |
41c445ff JB |
1128 | return f; |
1129 | } | |
1130 | return NULL; | |
1131 | } | |
1132 | ||
1133 | /** | |
1134 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode | |
1135 | * @vsi: the VSI to be searched | |
1136 | * | |
1137 | * Returns true if VSI is in vlan mode or false otherwise | |
1138 | **/ | |
1139 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) | |
1140 | { | |
cbebb85f JK |
1141 | /* If we have a PVID, always operate in VLAN mode */ |
1142 | if (vsi->info.pvid) | |
1143 | return true; | |
1144 | ||
1145 | /* We need to operate in VLAN mode whenever we have any filters with | |
1146 | * a VLAN other than I40E_VLAN_ALL. We could check the table each | |
1147 | * time, incurring search cost repeatedly. However, we can notice two | |
1148 | * things: | |
1149 | * | |
1150 | * 1) the only place where we can gain a VLAN filter is in | |
1151 | * i40e_add_filter. | |
1152 | * | |
1153 | * 2) the only place where filters are actually removed is in | |
0b7c8b5d | 1154 | * i40e_sync_filters_subtask. |
cbebb85f JK |
1155 | * |
1156 | * Thus, we can simply use a boolean value, has_vlan_filters which we | |
1157 | * will set to true when we add a VLAN filter in i40e_add_filter. Then | |
1158 | * we have to perform the full search after deleting filters in | |
0b7c8b5d | 1159 | * i40e_sync_filters_subtask, but we already have to search |
cbebb85f JK |
1160 | * filters here and can perform the check at the same time. This |
1161 | * results in avoiding embedding a loop for VLAN mode inside another | |
1162 | * loop over all the filters, and should maintain correctness as noted | |
1163 | * above. | |
41c445ff | 1164 | */ |
cbebb85f | 1165 | return vsi->has_vlan_filter; |
41c445ff JB |
1166 | } |
1167 | ||
489a3265 JK |
1168 | /** |
1169 | * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary | |
1170 | * @vsi: the VSI to configure | |
1171 | * @tmp_add_list: list of filters ready to be added | |
1172 | * @tmp_del_list: list of filters ready to be deleted | |
1173 | * @vlan_filters: the number of active VLAN filters | |
1174 | * | |
1175 | * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they | |
1176 | * behave as expected. If we have any active VLAN filters remaining or about | |
1177 | * to be added then we need to update non-VLAN filters to be marked as VLAN=0 | |
1178 | * so that they only match against untagged traffic. If we no longer have any | |
1179 | * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1 | |
1180 | * so that they match against both tagged and untagged traffic. In this way, | |
1181 | * we ensure that we correctly receive the desired traffic. This ensures that | |
1182 | * when we have an active VLAN we will receive only untagged traffic and | |
1183 | * traffic matching active VLANs. If we have no active VLANs then we will | |
1184 | * operate in non-VLAN mode and receive all traffic, tagged or untagged. | |
1185 | * | |
1186 | * Finally, in a similar fashion, this function also corrects filters when | |
1187 | * there is an active PVID assigned to this VSI. | |
1188 | * | |
1189 | * In case of memory allocation failure return -ENOMEM. Otherwise, return 0. | |
1190 | * | |
1191 | * This function is only expected to be called from within | |
1192 | * i40e_sync_vsi_filters. | |
1193 | * | |
1194 | * NOTE: This function expects to be called while under the | |
1195 | * mac_filter_hash_lock | |
1196 | */ | |
1197 | static int i40e_correct_mac_vlan_filters(struct i40e_vsi *vsi, | |
1198 | struct hlist_head *tmp_add_list, | |
1199 | struct hlist_head *tmp_del_list, | |
1200 | int vlan_filters) | |
1201 | { | |
5cb25901 | 1202 | s16 pvid = le16_to_cpu(vsi->info.pvid); |
489a3265 | 1203 | struct i40e_mac_filter *f, *add_head; |
671889e6 | 1204 | struct i40e_new_mac_filter *new; |
489a3265 JK |
1205 | struct hlist_node *h; |
1206 | int bkt, new_vlan; | |
1207 | ||
1208 | /* To determine if a particular filter needs to be replaced we | |
1209 | * have the three following conditions: | |
1210 | * | |
1211 | * a) if we have a PVID assigned, then all filters which are | |
1212 | * not marked as VLAN=PVID must be replaced with filters that | |
1213 | * are. | |
1214 | * b) otherwise, if we have any active VLANS, all filters | |
1215 | * which are marked as VLAN=-1 must be replaced with | |
1216 | * filters marked as VLAN=0 | |
1217 | * c) finally, if we do not have any active VLANS, all filters | |
1218 | * which are marked as VLAN=0 must be replaced with filters | |
1219 | * marked as VLAN=-1 | |
1220 | */ | |
1221 | ||
1222 | /* Update the filters about to be added in place */ | |
671889e6 | 1223 | hlist_for_each_entry(new, tmp_add_list, hlist) { |
5cb25901 JK |
1224 | if (pvid && new->f->vlan != pvid) |
1225 | new->f->vlan = pvid; | |
671889e6 JK |
1226 | else if (vlan_filters && new->f->vlan == I40E_VLAN_ANY) |
1227 | new->f->vlan = 0; | |
1228 | else if (!vlan_filters && new->f->vlan == 0) | |
1229 | new->f->vlan = I40E_VLAN_ANY; | |
489a3265 JK |
1230 | } |
1231 | ||
1232 | /* Update the remaining active filters */ | |
1233 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { | |
1234 | /* Combine the checks for whether a filter needs to be changed | |
1235 | * and then determine the new VLAN inside the if block, in | |
1236 | * order to avoid duplicating code for adding the new filter | |
1237 | * then deleting the old filter. | |
1238 | */ | |
5cb25901 | 1239 | if ((pvid && f->vlan != pvid) || |
489a3265 JK |
1240 | (vlan_filters && f->vlan == I40E_VLAN_ANY) || |
1241 | (!vlan_filters && f->vlan == 0)) { | |
1242 | /* Determine the new vlan we will be adding */ | |
5cb25901 JK |
1243 | if (pvid) |
1244 | new_vlan = pvid; | |
489a3265 JK |
1245 | else if (vlan_filters) |
1246 | new_vlan = 0; | |
1247 | else | |
1248 | new_vlan = I40E_VLAN_ANY; | |
1249 | ||
1250 | /* Create the new filter */ | |
1251 | add_head = i40e_add_filter(vsi, f->macaddr, new_vlan); | |
1252 | if (!add_head) | |
1253 | return -ENOMEM; | |
1254 | ||
671889e6 JK |
1255 | /* Create a temporary i40e_new_mac_filter */ |
1256 | new = kzalloc(sizeof(*new), GFP_ATOMIC); | |
1257 | if (!new) | |
1258 | return -ENOMEM; | |
1259 | ||
1260 | new->f = add_head; | |
1261 | new->state = add_head->state; | |
1262 | ||
1263 | /* Add the new filter to the tmp list */ | |
1264 | hlist_add_head(&new->hlist, tmp_add_list); | |
489a3265 JK |
1265 | |
1266 | /* Put the original filter into the delete list */ | |
1267 | f->state = I40E_FILTER_REMOVE; | |
1268 | hash_del(&f->hlist); | |
1269 | hlist_add_head(&f->hlist, tmp_del_list); | |
1270 | } | |
1271 | } | |
1272 | ||
1273 | vsi->has_vlan_filter = !!vlan_filters; | |
1274 | ||
1275 | return 0; | |
1276 | } | |
1277 | ||
1596b5dd JK |
1278 | /** |
1279 | * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM | |
1280 | * @vsi: the PF Main VSI - inappropriate for any other VSI | |
1281 | * @macaddr: the MAC address | |
1282 | * | |
1283 | * Remove whatever filter the firmware set up so the driver can manage | |
1284 | * its own filtering intelligently. | |
1285 | **/ | |
1286 | static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr) | |
1287 | { | |
1288 | struct i40e_aqc_remove_macvlan_element_data element; | |
1289 | struct i40e_pf *pf = vsi->back; | |
1290 | ||
1291 | /* Only appropriate for the PF main VSI */ | |
1292 | if (vsi->type != I40E_VSI_MAIN) | |
1293 | return; | |
1294 | ||
1295 | memset(&element, 0, sizeof(element)); | |
1296 | ether_addr_copy(element.mac_addr, macaddr); | |
1297 | element.vlan_tag = 0; | |
1298 | /* Ignore error returns, some firmware does it this way... */ | |
1299 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; | |
1300 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); | |
1301 | ||
1302 | memset(&element, 0, sizeof(element)); | |
1303 | ether_addr_copy(element.mac_addr, macaddr); | |
1304 | element.vlan_tag = 0; | |
1305 | /* ...and some firmware does it this way. */ | |
1306 | element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH | | |
1307 | I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; | |
1308 | i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL); | |
1309 | } | |
1310 | ||
41c445ff JB |
1311 | /** |
1312 | * i40e_add_filter - Add a mac/vlan filter to the VSI | |
1313 | * @vsi: the VSI to be searched | |
1314 | * @macaddr: the MAC address | |
1315 | * @vlan: the vlan | |
41c445ff JB |
1316 | * |
1317 | * Returns ptr to the filter object or NULL when no memory available. | |
21659035 | 1318 | * |
278e7d0b | 1319 | * NOTE: This function is expected to be called with mac_filter_hash_lock |
21659035 | 1320 | * being held. |
41c445ff JB |
1321 | **/ |
1322 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, | |
6622f5cd | 1323 | const u8 *macaddr, s16 vlan) |
41c445ff JB |
1324 | { |
1325 | struct i40e_mac_filter *f; | |
278e7d0b | 1326 | u64 key; |
41c445ff JB |
1327 | |
1328 | if (!vsi || !macaddr) | |
1329 | return NULL; | |
1330 | ||
1bc87e80 | 1331 | f = i40e_find_filter(vsi, macaddr, vlan); |
41c445ff JB |
1332 | if (!f) { |
1333 | f = kzalloc(sizeof(*f), GFP_ATOMIC); | |
1334 | if (!f) | |
1bc87e80 | 1335 | return NULL; |
41c445ff | 1336 | |
cbebb85f JK |
1337 | /* Update the boolean indicating if we need to function in |
1338 | * VLAN mode. | |
1339 | */ | |
1340 | if (vlan >= 0) | |
1341 | vsi->has_vlan_filter = true; | |
1342 | ||
9a173901 | 1343 | ether_addr_copy(f->macaddr, macaddr); |
41c445ff | 1344 | f->vlan = vlan; |
c3c7ea27 MW |
1345 | /* If we're in overflow promisc mode, set the state directly |
1346 | * to failed, so we don't bother to try sending the filter | |
1347 | * to the hardware. | |
1348 | */ | |
1349 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state)) | |
1350 | f->state = I40E_FILTER_FAILED; | |
1351 | else | |
1352 | f->state = I40E_FILTER_NEW; | |
278e7d0b JK |
1353 | INIT_HLIST_NODE(&f->hlist); |
1354 | ||
1355 | key = i40e_addr_to_hkey(macaddr); | |
1356 | hash_add(vsi->mac_filter_hash, &f->hlist, key); | |
41c445ff | 1357 | |
41c445ff JB |
1358 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
1359 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; | |
1360 | } | |
1361 | ||
1bc87e80 JK |
1362 | /* If we're asked to add a filter that has been marked for removal, it |
1363 | * is safe to simply restore it to active state. __i40e_del_filter | |
1364 | * will have simply deleted any filters which were previously marked | |
1365 | * NEW or FAILED, so if it is currently marked REMOVE it must have | |
1366 | * previously been ACTIVE. Since we haven't yet run the sync filters | |
1367 | * task, just restore this filter to the ACTIVE state so that the | |
1368 | * sync task leaves it in place | |
1369 | */ | |
1370 | if (f->state == I40E_FILTER_REMOVE) | |
1371 | f->state = I40E_FILTER_ACTIVE; | |
1372 | ||
41c445ff JB |
1373 | return f; |
1374 | } | |
1375 | ||
1376 | /** | |
290d2557 JK |
1377 | * __i40e_del_filter - Remove a specific filter from the VSI |
1378 | * @vsi: VSI to remove from | |
1379 | * @f: the filter to remove from the list | |
1380 | * | |
1381 | * This function should be called instead of i40e_del_filter only if you know | |
1382 | * the exact filter you will remove already, such as via i40e_find_filter or | |
1383 | * i40e_find_mac. | |
21659035 | 1384 | * |
278e7d0b | 1385 | * NOTE: This function is expected to be called with mac_filter_hash_lock |
21659035 | 1386 | * being held. |
c3c7ea27 MW |
1387 | * ANOTHER NOTE: This function MUST be called from within the context of |
1388 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() | |
1389 | * instead of list_for_each_entry(). | |
41c445ff | 1390 | **/ |
148141bb | 1391 | void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f) |
41c445ff | 1392 | { |
1bc87e80 | 1393 | if (!f) |
41c445ff JB |
1394 | return; |
1395 | ||
a410c821 AB |
1396 | /* If the filter was never added to firmware then we can just delete it |
1397 | * directly and we don't want to set the status to remove or else an | |
1398 | * admin queue command will unnecessarily fire. | |
1399 | */ | |
1bc87e80 JK |
1400 | if ((f->state == I40E_FILTER_FAILED) || |
1401 | (f->state == I40E_FILTER_NEW)) { | |
278e7d0b | 1402 | hash_del(&f->hlist); |
1bc87e80 | 1403 | kfree(f); |
41c445ff | 1404 | } else { |
1bc87e80 | 1405 | f->state = I40E_FILTER_REMOVE; |
41c445ff | 1406 | } |
a410c821 AB |
1407 | |
1408 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; | |
1409 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; | |
41c445ff JB |
1410 | } |
1411 | ||
290d2557 JK |
1412 | /** |
1413 | * i40e_del_filter - Remove a MAC/VLAN filter from the VSI | |
1414 | * @vsi: the VSI to be searched | |
1415 | * @macaddr: the MAC address | |
1416 | * @vlan: the VLAN | |
1417 | * | |
278e7d0b | 1418 | * NOTE: This function is expected to be called with mac_filter_hash_lock |
290d2557 JK |
1419 | * being held. |
1420 | * ANOTHER NOTE: This function MUST be called from within the context of | |
1421 | * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe() | |
1422 | * instead of list_for_each_entry(). | |
1423 | **/ | |
1424 | void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan) | |
1425 | { | |
1426 | struct i40e_mac_filter *f; | |
1427 | ||
1428 | if (!vsi || !macaddr) | |
1429 | return; | |
1430 | ||
1431 | f = i40e_find_filter(vsi, macaddr, vlan); | |
1432 | __i40e_del_filter(vsi, f); | |
1433 | } | |
1434 | ||
35ec2ff3 | 1435 | /** |
feffdbe4 | 1436 | * i40e_add_mac_filter - Add a MAC filter for all active VLANs |
35ec2ff3 JK |
1437 | * @vsi: the VSI to be searched |
1438 | * @macaddr: the mac address to be filtered | |
1439 | * | |
feffdbe4 JK |
1440 | * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise, |
1441 | * go through all the macvlan filters and add a macvlan filter for each | |
5feb3d7b JK |
1442 | * unique vlan that already exists. If a PVID has been assigned, instead only |
1443 | * add the macaddr to that VLAN. | |
35ec2ff3 | 1444 | * |
5feb3d7b | 1445 | * Returns last filter added on success, else NULL |
35ec2ff3 | 1446 | **/ |
feffdbe4 JK |
1447 | struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi, |
1448 | const u8 *macaddr) | |
35ec2ff3 | 1449 | { |
5feb3d7b | 1450 | struct i40e_mac_filter *f, *add = NULL; |
278e7d0b JK |
1451 | struct hlist_node *h; |
1452 | int bkt; | |
5feb3d7b JK |
1453 | |
1454 | if (vsi->info.pvid) | |
1455 | return i40e_add_filter(vsi, macaddr, | |
1456 | le16_to_cpu(vsi->info.pvid)); | |
35ec2ff3 | 1457 | |
7aaf9536 JK |
1458 | if (!i40e_is_vsi_in_vlan(vsi)) |
1459 | return i40e_add_filter(vsi, macaddr, I40E_VLAN_ANY); | |
1460 | ||
278e7d0b | 1461 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
57b341d6 JK |
1462 | if (f->state == I40E_FILTER_REMOVE) |
1463 | continue; | |
5feb3d7b JK |
1464 | add = i40e_add_filter(vsi, macaddr, f->vlan); |
1465 | if (!add) | |
1466 | return NULL; | |
35ec2ff3 JK |
1467 | } |
1468 | ||
5feb3d7b | 1469 | return add; |
35ec2ff3 JK |
1470 | } |
1471 | ||
1472 | /** | |
feffdbe4 | 1473 | * i40e_del_mac_filter - Remove a MAC filter from all VLANs |
35ec2ff3 JK |
1474 | * @vsi: the VSI to be searched |
1475 | * @macaddr: the mac address to be removed | |
1476 | * | |
feffdbe4 JK |
1477 | * Removes a given MAC address from a VSI regardless of what VLAN it has been |
1478 | * associated with. | |
35ec2ff3 JK |
1479 | * |
1480 | * Returns 0 for success, or error | |
1481 | **/ | |
feffdbe4 | 1482 | int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr) |
35ec2ff3 | 1483 | { |
278e7d0b JK |
1484 | struct i40e_mac_filter *f; |
1485 | struct hlist_node *h; | |
290d2557 | 1486 | bool found = false; |
278e7d0b | 1487 | int bkt; |
35ec2ff3 | 1488 | |
278e7d0b JK |
1489 | WARN(!spin_is_locked(&vsi->mac_filter_hash_lock), |
1490 | "Missing mac_filter_hash_lock\n"); | |
1491 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { | |
290d2557 JK |
1492 | if (ether_addr_equal(macaddr, f->macaddr)) { |
1493 | __i40e_del_filter(vsi, f); | |
1494 | found = true; | |
1495 | } | |
35ec2ff3 | 1496 | } |
290d2557 JK |
1497 | |
1498 | if (found) | |
35ec2ff3 | 1499 | return 0; |
290d2557 JK |
1500 | else |
1501 | return -ENOENT; | |
35ec2ff3 JK |
1502 | } |
1503 | ||
41c445ff JB |
1504 | /** |
1505 | * i40e_set_mac - NDO callback to set mac address | |
1506 | * @netdev: network interface device structure | |
1507 | * @p: pointer to an address structure | |
1508 | * | |
1509 | * Returns 0 on success, negative on failure | |
1510 | **/ | |
1511 | static int i40e_set_mac(struct net_device *netdev, void *p) | |
1512 | { | |
1513 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1514 | struct i40e_vsi *vsi = np->vsi; | |
30650cc5 SN |
1515 | struct i40e_pf *pf = vsi->back; |
1516 | struct i40e_hw *hw = &pf->hw; | |
41c445ff | 1517 | struct sockaddr *addr = p; |
41c445ff JB |
1518 | |
1519 | if (!is_valid_ether_addr(addr->sa_data)) | |
1520 | return -EADDRNOTAVAIL; | |
1521 | ||
30650cc5 SN |
1522 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) { |
1523 | netdev_info(netdev, "already using mac address %pM\n", | |
1524 | addr->sa_data); | |
1525 | return 0; | |
1526 | } | |
41c445ff | 1527 | |
80f6428f ASJ |
1528 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
1529 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) | |
1530 | return -EADDRNOTAVAIL; | |
1531 | ||
30650cc5 SN |
1532 | if (ether_addr_equal(hw->mac.addr, addr->sa_data)) |
1533 | netdev_info(netdev, "returning to hw mac address %pM\n", | |
1534 | hw->mac.addr); | |
1535 | else | |
1536 | netdev_info(netdev, "set new mac address %pM\n", addr->sa_data); | |
1537 | ||
278e7d0b | 1538 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
feffdbe4 JK |
1539 | i40e_del_mac_filter(vsi, netdev->dev_addr); |
1540 | i40e_add_mac_filter(vsi, addr->sa_data); | |
278e7d0b | 1541 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
c3c7ea27 | 1542 | ether_addr_copy(netdev->dev_addr, addr->sa_data); |
41c445ff JB |
1543 | if (vsi->type == I40E_VSI_MAIN) { |
1544 | i40e_status ret; | |
6995b36c | 1545 | |
41c445ff | 1546 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
cc41222c | 1547 | I40E_AQC_WRITE_TYPE_LAA_WOL, |
41c445ff | 1548 | addr->sa_data, NULL); |
c3c7ea27 MW |
1549 | if (ret) |
1550 | netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n", | |
1551 | i40e_stat_str(hw, ret), | |
1552 | i40e_aq_str(hw, hw->aq.asq_last_status)); | |
30650cc5 SN |
1553 | } |
1554 | ||
c53934c6 JB |
1555 | /* schedule our worker thread which will take care of |
1556 | * applying the new filter changes | |
1557 | */ | |
1558 | i40e_service_event_schedule(vsi->back); | |
1559 | return 0; | |
41c445ff JB |
1560 | } |
1561 | ||
1562 | /** | |
1563 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc | |
1564 | * @vsi: the VSI being setup | |
1565 | * @ctxt: VSI context structure | |
1566 | * @enabled_tc: Enabled TCs bitmap | |
1567 | * @is_add: True if called before Add VSI | |
1568 | * | |
1569 | * Setup VSI queue mapping for enabled traffic classes. | |
1570 | **/ | |
1571 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, | |
1572 | struct i40e_vsi_context *ctxt, | |
1573 | u8 enabled_tc, | |
1574 | bool is_add) | |
1575 | { | |
1576 | struct i40e_pf *pf = vsi->back; | |
1577 | u16 sections = 0; | |
1578 | u8 netdev_tc = 0; | |
1579 | u16 numtc = 0; | |
1580 | u16 qcount; | |
1581 | u8 offset; | |
1582 | u16 qmap; | |
1583 | int i; | |
4e3b35b0 | 1584 | u16 num_tc_qps = 0; |
41c445ff JB |
1585 | |
1586 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; | |
1587 | offset = 0; | |
1588 | ||
1589 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { | |
1590 | /* Find numtc from enabled TC bitmap */ | |
1591 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
75f5cea9 | 1592 | if (enabled_tc & BIT(i)) /* TC is enabled */ |
41c445ff JB |
1593 | numtc++; |
1594 | } | |
1595 | if (!numtc) { | |
1596 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); | |
1597 | numtc = 1; | |
1598 | } | |
1599 | } else { | |
1600 | /* At least TC0 is enabled in case of non-DCB case */ | |
1601 | numtc = 1; | |
1602 | } | |
1603 | ||
1604 | vsi->tc_config.numtc = numtc; | |
1605 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; | |
4e3b35b0 | 1606 | /* Number of queues per enabled TC */ |
7d64402f CS |
1607 | qcount = vsi->alloc_queue_pairs; |
1608 | ||
7f9ff476 | 1609 | num_tc_qps = qcount / numtc; |
e25d00b8 | 1610 | num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf)); |
41c445ff JB |
1611 | |
1612 | /* Setup queue offset/count for all TCs for given VSI */ | |
1613 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
1614 | /* See if the given TC is enabled for the given VSI */ | |
75f5cea9 | 1615 | if (vsi->tc_config.enabled_tc & BIT(i)) { |
41a1d04b | 1616 | /* TC is enabled */ |
41c445ff JB |
1617 | int pow, num_qps; |
1618 | ||
41c445ff JB |
1619 | switch (vsi->type) { |
1620 | case I40E_VSI_MAIN: | |
acd65448 HZ |
1621 | qcount = min_t(int, pf->alloc_rss_size, |
1622 | num_tc_qps); | |
41c445ff JB |
1623 | break; |
1624 | case I40E_VSI_FDIR: | |
1625 | case I40E_VSI_SRIOV: | |
1626 | case I40E_VSI_VMDQ2: | |
1627 | default: | |
4e3b35b0 | 1628 | qcount = num_tc_qps; |
41c445ff JB |
1629 | WARN_ON(i != 0); |
1630 | break; | |
1631 | } | |
4e3b35b0 NP |
1632 | vsi->tc_config.tc_info[i].qoffset = offset; |
1633 | vsi->tc_config.tc_info[i].qcount = qcount; | |
41c445ff | 1634 | |
1e200e4a | 1635 | /* find the next higher power-of-2 of num queue pairs */ |
4e3b35b0 | 1636 | num_qps = qcount; |
41c445ff | 1637 | pow = 0; |
41a1d04b | 1638 | while (num_qps && (BIT_ULL(pow) < qcount)) { |
41c445ff JB |
1639 | pow++; |
1640 | num_qps >>= 1; | |
1641 | } | |
1642 | ||
1643 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; | |
1644 | qmap = | |
1645 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | | |
1646 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); | |
1647 | ||
4e3b35b0 | 1648 | offset += qcount; |
41c445ff JB |
1649 | } else { |
1650 | /* TC is not enabled so set the offset to | |
1651 | * default queue and allocate one queue | |
1652 | * for the given TC. | |
1653 | */ | |
1654 | vsi->tc_config.tc_info[i].qoffset = 0; | |
1655 | vsi->tc_config.tc_info[i].qcount = 1; | |
1656 | vsi->tc_config.tc_info[i].netdev_tc = 0; | |
1657 | ||
1658 | qmap = 0; | |
1659 | } | |
1660 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); | |
1661 | } | |
1662 | ||
1663 | /* Set actual Tx/Rx queue pairs */ | |
1664 | vsi->num_queue_pairs = offset; | |
9a3bd2f1 ASJ |
1665 | if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) { |
1666 | if (vsi->req_queue_pairs > 0) | |
1667 | vsi->num_queue_pairs = vsi->req_queue_pairs; | |
26cdc443 | 1668 | else if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
9a3bd2f1 ASJ |
1669 | vsi->num_queue_pairs = pf->num_lan_msix; |
1670 | } | |
41c445ff JB |
1671 | |
1672 | /* Scheduler section valid can only be set for ADD VSI */ | |
1673 | if (is_add) { | |
1674 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; | |
1675 | ||
1676 | ctxt->info.up_enable_bits = enabled_tc; | |
1677 | } | |
1678 | if (vsi->type == I40E_VSI_SRIOV) { | |
1679 | ctxt->info.mapping_flags |= | |
1680 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); | |
1681 | for (i = 0; i < vsi->num_queue_pairs; i++) | |
1682 | ctxt->info.queue_mapping[i] = | |
1683 | cpu_to_le16(vsi->base_queue + i); | |
1684 | } else { | |
1685 | ctxt->info.mapping_flags |= | |
1686 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); | |
1687 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); | |
1688 | } | |
1689 | ctxt->info.valid_sections |= cpu_to_le16(sections); | |
1690 | } | |
1691 | ||
6622f5cd JK |
1692 | /** |
1693 | * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address | |
1694 | * @netdev: the netdevice | |
1695 | * @addr: address to add | |
1696 | * | |
1697 | * Called by __dev_(mc|uc)_sync when an address needs to be added. We call | |
1698 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. | |
1699 | */ | |
1700 | static int i40e_addr_sync(struct net_device *netdev, const u8 *addr) | |
1701 | { | |
1702 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1703 | struct i40e_vsi *vsi = np->vsi; | |
6622f5cd | 1704 | |
feffdbe4 | 1705 | if (i40e_add_mac_filter(vsi, addr)) |
6622f5cd JK |
1706 | return 0; |
1707 | else | |
1708 | return -ENOMEM; | |
1709 | } | |
1710 | ||
1711 | /** | |
1712 | * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address | |
1713 | * @netdev: the netdevice | |
1714 | * @addr: address to add | |
1715 | * | |
1716 | * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call | |
1717 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. | |
1718 | */ | |
1719 | static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr) | |
1720 | { | |
1721 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1722 | struct i40e_vsi *vsi = np->vsi; | |
1723 | ||
feffdbe4 | 1724 | i40e_del_mac_filter(vsi, addr); |
6622f5cd JK |
1725 | |
1726 | return 0; | |
1727 | } | |
1728 | ||
41c445ff JB |
1729 | /** |
1730 | * i40e_set_rx_mode - NDO callback to set the netdev filters | |
1731 | * @netdev: network interface device structure | |
1732 | **/ | |
1733 | static void i40e_set_rx_mode(struct net_device *netdev) | |
1734 | { | |
1735 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
41c445ff | 1736 | struct i40e_vsi *vsi = np->vsi; |
41c445ff | 1737 | |
278e7d0b | 1738 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
21659035 | 1739 | |
6622f5cd JK |
1740 | __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); |
1741 | __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync); | |
41c445ff | 1742 | |
278e7d0b | 1743 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
41c445ff JB |
1744 | |
1745 | /* check for other flag changes */ | |
1746 | if (vsi->current_netdev_flags != vsi->netdev->flags) { | |
1747 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; | |
1748 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; | |
1749 | } | |
c53934c6 JB |
1750 | |
1751 | /* schedule our worker thread which will take care of | |
1752 | * applying the new filter changes | |
1753 | */ | |
1754 | i40e_service_event_schedule(vsi->back); | |
41c445ff JB |
1755 | } |
1756 | ||
21659035 | 1757 | /** |
671889e6 | 1758 | * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries |
4a2ce27b | 1759 | * @vsi: Pointer to VSI struct |
21659035 KP |
1760 | * @from: Pointer to list which contains MAC filter entries - changes to |
1761 | * those entries needs to be undone. | |
1762 | * | |
671889e6 | 1763 | * MAC filter entries from this list were slated for deletion. |
21659035 | 1764 | **/ |
671889e6 JK |
1765 | static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi, |
1766 | struct hlist_head *from) | |
21659035 | 1767 | { |
278e7d0b JK |
1768 | struct i40e_mac_filter *f; |
1769 | struct hlist_node *h; | |
1770 | ||
1771 | hlist_for_each_entry_safe(f, h, from, hlist) { | |
1772 | u64 key = i40e_addr_to_hkey(f->macaddr); | |
21659035 | 1773 | |
21659035 | 1774 | /* Move the element back into MAC filter list*/ |
278e7d0b JK |
1775 | hlist_del(&f->hlist); |
1776 | hash_add(vsi->mac_filter_hash, &f->hlist, key); | |
21659035 KP |
1777 | } |
1778 | } | |
1779 | ||
671889e6 JK |
1780 | /** |
1781 | * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries | |
1782 | * @vsi: Pointer to vsi struct | |
1783 | * @from: Pointer to list which contains MAC filter entries - changes to | |
1784 | * those entries needs to be undone. | |
1785 | * | |
1786 | * MAC filter entries from this list were slated for addition. | |
1787 | **/ | |
1788 | static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi, | |
1789 | struct hlist_head *from) | |
1790 | { | |
1791 | struct i40e_new_mac_filter *new; | |
1792 | struct hlist_node *h; | |
1793 | ||
1794 | hlist_for_each_entry_safe(new, h, from, hlist) { | |
1795 | /* We can simply free the wrapper structure */ | |
1796 | hlist_del(&new->hlist); | |
1797 | kfree(new); | |
1798 | } | |
1799 | } | |
1800 | ||
d88d40b0 JK |
1801 | /** |
1802 | * i40e_next_entry - Get the next non-broadcast filter from a list | |
671889e6 | 1803 | * @next: pointer to filter in list |
d88d40b0 JK |
1804 | * |
1805 | * Returns the next non-broadcast filter in the list. Required so that we | |
1806 | * ignore broadcast filters within the list, since these are not handled via | |
1807 | * the normal firmware update path. | |
1808 | */ | |
671889e6 JK |
1809 | static |
1810 | struct i40e_new_mac_filter *i40e_next_filter(struct i40e_new_mac_filter *next) | |
d88d40b0 | 1811 | { |
584a8870 JK |
1812 | hlist_for_each_entry_continue(next, hlist) { |
1813 | if (!is_broadcast_ether_addr(next->f->macaddr)) | |
1814 | return next; | |
d88d40b0 JK |
1815 | } |
1816 | ||
584a8870 | 1817 | return NULL; |
d88d40b0 JK |
1818 | } |
1819 | ||
21659035 | 1820 | /** |
c3c7ea27 MW |
1821 | * i40e_update_filter_state - Update filter state based on return data |
1822 | * from firmware | |
1823 | * @count: Number of filters added | |
1824 | * @add_list: return data from fw | |
1825 | * @head: pointer to first filter in current batch | |
21659035 | 1826 | * |
c3c7ea27 MW |
1827 | * MAC filter entries from list were slated to be added to device. Returns |
1828 | * number of successful filters. Note that 0 does NOT mean success! | |
21659035 | 1829 | **/ |
c3c7ea27 MW |
1830 | static int |
1831 | i40e_update_filter_state(int count, | |
1832 | struct i40e_aqc_add_macvlan_element_data *add_list, | |
671889e6 | 1833 | struct i40e_new_mac_filter *add_head) |
21659035 | 1834 | { |
c3c7ea27 MW |
1835 | int retval = 0; |
1836 | int i; | |
21659035 | 1837 | |
ac9e2390 JK |
1838 | for (i = 0; i < count; i++) { |
1839 | /* Always check status of each filter. We don't need to check | |
1840 | * the firmware return status because we pre-set the filter | |
1841 | * status to I40E_AQC_MM_ERR_NO_RES when sending the filter | |
1842 | * request to the adminq. Thus, if it no longer matches then | |
1843 | * we know the filter is active. | |
c3c7ea27 | 1844 | */ |
ac9e2390 | 1845 | if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) { |
c3c7ea27 | 1846 | add_head->state = I40E_FILTER_FAILED; |
ac9e2390 JK |
1847 | } else { |
1848 | add_head->state = I40E_FILTER_ACTIVE; | |
1849 | retval++; | |
c3c7ea27 | 1850 | } |
ac9e2390 | 1851 | |
d88d40b0 JK |
1852 | add_head = i40e_next_filter(add_head); |
1853 | if (!add_head) | |
1854 | break; | |
21659035 | 1855 | } |
ac9e2390 | 1856 | |
c3c7ea27 | 1857 | return retval; |
21659035 KP |
1858 | } |
1859 | ||
00936319 JK |
1860 | /** |
1861 | * i40e_aqc_del_filters - Request firmware to delete a set of filters | |
1862 | * @vsi: ptr to the VSI | |
1863 | * @vsi_name: name to display in messages | |
1864 | * @list: the list of filters to send to firmware | |
1865 | * @num_del: the number of filters to delete | |
1866 | * @retval: Set to -EIO on failure to delete | |
1867 | * | |
1868 | * Send a request to firmware via AdminQ to delete a set of filters. Uses | |
1869 | * *retval instead of a return value so that success does not force ret_val to | |
1870 | * be set to 0. This ensures that a sequence of calls to this function | |
1871 | * preserve the previous value of *retval on successful delete. | |
1872 | */ | |
1873 | static | |
1874 | void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name, | |
1875 | struct i40e_aqc_remove_macvlan_element_data *list, | |
1876 | int num_del, int *retval) | |
1877 | { | |
1878 | struct i40e_hw *hw = &vsi->back->hw; | |
1879 | i40e_status aq_ret; | |
1880 | int aq_err; | |
1881 | ||
1882 | aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL); | |
1883 | aq_err = hw->aq.asq_last_status; | |
1884 | ||
1885 | /* Explicitly ignore and do not report when firmware returns ENOENT */ | |
1886 | if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) { | |
1887 | *retval = -EIO; | |
1888 | dev_info(&vsi->back->pdev->dev, | |
1889 | "ignoring delete macvlan error on %s, err %s, aq_err %s\n", | |
1890 | vsi_name, i40e_stat_str(hw, aq_ret), | |
1891 | i40e_aq_str(hw, aq_err)); | |
1892 | } | |
1893 | } | |
1894 | ||
1895 | /** | |
1896 | * i40e_aqc_add_filters - Request firmware to add a set of filters | |
1897 | * @vsi: ptr to the VSI | |
1898 | * @vsi_name: name to display in messages | |
1899 | * @list: the list of filters to send to firmware | |
1900 | * @add_head: Position in the add hlist | |
1901 | * @num_add: the number of filters to add | |
1902 | * @promisc_change: set to true on exit if promiscuous mode was forced on | |
1903 | * | |
1904 | * Send a request to firmware via AdminQ to add a chunk of filters. Will set | |
1905 | * promisc_changed to true if the firmware has run out of space for more | |
1906 | * filters. | |
1907 | */ | |
1908 | static | |
1909 | void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name, | |
1910 | struct i40e_aqc_add_macvlan_element_data *list, | |
671889e6 | 1911 | struct i40e_new_mac_filter *add_head, |
00936319 JK |
1912 | int num_add, bool *promisc_changed) |
1913 | { | |
1914 | struct i40e_hw *hw = &vsi->back->hw; | |
00936319 JK |
1915 | int aq_err, fcnt; |
1916 | ||
ac9e2390 | 1917 | i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL); |
00936319 | 1918 | aq_err = hw->aq.asq_last_status; |
ac9e2390 | 1919 | fcnt = i40e_update_filter_state(num_add, list, add_head); |
00936319 JK |
1920 | |
1921 | if (fcnt != num_add) { | |
1922 | *promisc_changed = true; | |
1923 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); | |
00936319 JK |
1924 | dev_warn(&vsi->back->pdev->dev, |
1925 | "Error %s adding RX filters on %s, promiscuous mode forced on\n", | |
1926 | i40e_aq_str(hw, aq_err), | |
1927 | vsi_name); | |
1928 | } | |
1929 | } | |
1930 | ||
435c084a JK |
1931 | /** |
1932 | * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags | |
1933 | * @vsi: pointer to the VSI | |
1934 | * @f: filter data | |
1935 | * | |
1936 | * This function sets or clears the promiscuous broadcast flags for VLAN | |
1937 | * filters in order to properly receive broadcast frames. Assumes that only | |
1938 | * broadcast filters are passed. | |
671889e6 JK |
1939 | * |
1940 | * Returns status indicating success or failure; | |
435c084a | 1941 | **/ |
671889e6 JK |
1942 | static i40e_status |
1943 | i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name, | |
1944 | struct i40e_mac_filter *f) | |
435c084a JK |
1945 | { |
1946 | bool enable = f->state == I40E_FILTER_NEW; | |
1947 | struct i40e_hw *hw = &vsi->back->hw; | |
1948 | i40e_status aq_ret; | |
1949 | ||
1950 | if (f->vlan == I40E_VLAN_ANY) { | |
1951 | aq_ret = i40e_aq_set_vsi_broadcast(hw, | |
1952 | vsi->seid, | |
1953 | enable, | |
1954 | NULL); | |
1955 | } else { | |
1956 | aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw, | |
1957 | vsi->seid, | |
1958 | enable, | |
1959 | f->vlan, | |
1960 | NULL); | |
1961 | } | |
1962 | ||
671889e6 | 1963 | if (aq_ret) |
435c084a JK |
1964 | dev_warn(&vsi->back->pdev->dev, |
1965 | "Error %s setting broadcast promiscuous mode on %s\n", | |
1966 | i40e_aq_str(hw, hw->aq.asq_last_status), | |
1967 | vsi_name); | |
671889e6 JK |
1968 | |
1969 | return aq_ret; | |
435c084a JK |
1970 | } |
1971 | ||
41c445ff JB |
1972 | /** |
1973 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW | |
1974 | * @vsi: ptr to the VSI | |
1975 | * | |
1976 | * Push any outstanding VSI filter changes through the AdminQ. | |
1977 | * | |
1978 | * Returns 0 or error value | |
1979 | **/ | |
17652c63 | 1980 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
41c445ff | 1981 | { |
278e7d0b | 1982 | struct hlist_head tmp_add_list, tmp_del_list; |
671889e6 JK |
1983 | struct i40e_mac_filter *f; |
1984 | struct i40e_new_mac_filter *new, *add_head = NULL; | |
3e25a8f3 | 1985 | struct i40e_hw *hw = &vsi->back->hw; |
38326218 | 1986 | unsigned int failed_filters = 0; |
84f5ca6c | 1987 | unsigned int vlan_filters = 0; |
c3c7ea27 | 1988 | bool promisc_changed = false; |
2d1de828 | 1989 | char vsi_name[16] = "PF"; |
41c445ff | 1990 | int filter_list_len = 0; |
ea02e90b | 1991 | i40e_status aq_ret = 0; |
84f5ca6c | 1992 | u32 changed_flags = 0; |
278e7d0b | 1993 | struct hlist_node *h; |
41c445ff JB |
1994 | struct i40e_pf *pf; |
1995 | int num_add = 0; | |
1996 | int num_del = 0; | |
84f5ca6c | 1997 | int retval = 0; |
41c445ff | 1998 | u16 cmd_flags; |
c3c7ea27 | 1999 | int list_size; |
278e7d0b | 2000 | int bkt; |
41c445ff JB |
2001 | |
2002 | /* empty array typed pointers, kcalloc later */ | |
2003 | struct i40e_aqc_add_macvlan_element_data *add_list; | |
2004 | struct i40e_aqc_remove_macvlan_element_data *del_list; | |
2005 | ||
2006 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) | |
2007 | usleep_range(1000, 2000); | |
2008 | pf = vsi->back; | |
2009 | ||
2010 | if (vsi->netdev) { | |
2011 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; | |
2012 | vsi->current_netdev_flags = vsi->netdev->flags; | |
2013 | } | |
2014 | ||
278e7d0b JK |
2015 | INIT_HLIST_HEAD(&tmp_add_list); |
2016 | INIT_HLIST_HEAD(&tmp_del_list); | |
21659035 | 2017 | |
2d1de828 SN |
2018 | if (vsi->type == I40E_VSI_SRIOV) |
2019 | snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id); | |
2020 | else if (vsi->type != I40E_VSI_MAIN) | |
2021 | snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid); | |
2022 | ||
41c445ff JB |
2023 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
2024 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; | |
2025 | ||
278e7d0b | 2026 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
c3c7ea27 | 2027 | /* Create a list of filters to delete. */ |
278e7d0b | 2028 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
c3c7ea27 | 2029 | if (f->state == I40E_FILTER_REMOVE) { |
c3c7ea27 | 2030 | /* Move the element into temporary del_list */ |
278e7d0b JK |
2031 | hash_del(&f->hlist); |
2032 | hlist_add_head(&f->hlist, &tmp_del_list); | |
84f5ca6c AB |
2033 | |
2034 | /* Avoid counting removed filters */ | |
2035 | continue; | |
c3c7ea27 MW |
2036 | } |
2037 | if (f->state == I40E_FILTER_NEW) { | |
671889e6 JK |
2038 | /* Create a temporary i40e_new_mac_filter */ |
2039 | new = kzalloc(sizeof(*new), GFP_ATOMIC); | |
2040 | if (!new) | |
2041 | goto err_no_memory_locked; | |
2042 | ||
2043 | /* Store pointer to the real filter */ | |
2044 | new->f = f; | |
2045 | new->state = f->state; | |
2046 | ||
2047 | /* Add it to the hash list */ | |
2048 | hlist_add_head(&new->hlist, &tmp_add_list); | |
21659035 | 2049 | } |
84f5ca6c | 2050 | |
489a3265 JK |
2051 | /* Count the number of active (current and new) VLAN |
2052 | * filters we have now. Does not count filters which | |
2053 | * are marked for deletion. | |
84f5ca6c AB |
2054 | */ |
2055 | if (f->vlan > 0) | |
2056 | vlan_filters++; | |
84f5ca6c AB |
2057 | } |
2058 | ||
489a3265 JK |
2059 | retval = i40e_correct_mac_vlan_filters(vsi, |
2060 | &tmp_add_list, | |
2061 | &tmp_del_list, | |
2062 | vlan_filters); | |
2063 | if (retval) | |
2064 | goto err_no_memory_locked; | |
84f5ca6c | 2065 | |
278e7d0b | 2066 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
21659035 KP |
2067 | } |
2068 | ||
2069 | /* Now process 'del_list' outside the lock */ | |
278e7d0b | 2070 | if (!hlist_empty(&tmp_del_list)) { |
3e25a8f3 | 2071 | filter_list_len = hw->aq.asq_buf_size / |
21659035 | 2072 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
c3c7ea27 | 2073 | list_size = filter_list_len * |
f1199998 | 2074 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
c3c7ea27 | 2075 | del_list = kzalloc(list_size, GFP_ATOMIC); |
4a2ce27b JK |
2076 | if (!del_list) |
2077 | goto err_no_memory; | |
21659035 | 2078 | |
278e7d0b | 2079 | hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) { |
41c445ff JB |
2080 | cmd_flags = 0; |
2081 | ||
435c084a | 2082 | /* handle broadcast filters by updating the broadcast |
d88d40b0 | 2083 | * promiscuous flag and release filter list. |
435c084a JK |
2084 | */ |
2085 | if (is_broadcast_ether_addr(f->macaddr)) { | |
2086 | i40e_aqc_broadcast_filter(vsi, vsi_name, f); | |
2087 | ||
2088 | hlist_del(&f->hlist); | |
2089 | kfree(f); | |
2090 | continue; | |
2091 | } | |
2092 | ||
41c445ff | 2093 | /* add to delete list */ |
9a173901 | 2094 | ether_addr_copy(del_list[num_del].mac_addr, f->macaddr); |
c3c7ea27 MW |
2095 | if (f->vlan == I40E_VLAN_ANY) { |
2096 | del_list[num_del].vlan_tag = 0; | |
a6cb9146 | 2097 | cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN; |
c3c7ea27 MW |
2098 | } else { |
2099 | del_list[num_del].vlan_tag = | |
2100 | cpu_to_le16((u16)(f->vlan)); | |
2101 | } | |
41c445ff | 2102 | |
41c445ff JB |
2103 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
2104 | del_list[num_del].flags = cmd_flags; | |
2105 | num_del++; | |
2106 | ||
41c445ff JB |
2107 | /* flush a full buffer */ |
2108 | if (num_del == filter_list_len) { | |
00936319 JK |
2109 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
2110 | num_del, &retval); | |
c3c7ea27 | 2111 | memset(del_list, 0, list_size); |
00936319 | 2112 | num_del = 0; |
41c445ff | 2113 | } |
21659035 KP |
2114 | /* Release memory for MAC filter entries which were |
2115 | * synced up with HW. | |
2116 | */ | |
278e7d0b | 2117 | hlist_del(&f->hlist); |
21659035 | 2118 | kfree(f); |
41c445ff | 2119 | } |
21659035 | 2120 | |
41c445ff | 2121 | if (num_del) { |
00936319 JK |
2122 | i40e_aqc_del_filters(vsi, vsi_name, del_list, |
2123 | num_del, &retval); | |
41c445ff JB |
2124 | } |
2125 | ||
2126 | kfree(del_list); | |
2127 | del_list = NULL; | |
21659035 KP |
2128 | } |
2129 | ||
278e7d0b | 2130 | if (!hlist_empty(&tmp_add_list)) { |
c3c7ea27 | 2131 | /* Do all the adds now. */ |
3e25a8f3 | 2132 | filter_list_len = hw->aq.asq_buf_size / |
f1199998 | 2133 | sizeof(struct i40e_aqc_add_macvlan_element_data); |
c3c7ea27 MW |
2134 | list_size = filter_list_len * |
2135 | sizeof(struct i40e_aqc_add_macvlan_element_data); | |
2136 | add_list = kzalloc(list_size, GFP_ATOMIC); | |
4a2ce27b JK |
2137 | if (!add_list) |
2138 | goto err_no_memory; | |
2139 | ||
c3c7ea27 | 2140 | num_add = 0; |
671889e6 | 2141 | hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) { |
c3c7ea27 MW |
2142 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
2143 | &vsi->state)) { | |
671889e6 | 2144 | new->state = I40E_FILTER_FAILED; |
c3c7ea27 MW |
2145 | continue; |
2146 | } | |
435c084a JK |
2147 | |
2148 | /* handle broadcast filters by updating the broadcast | |
2149 | * promiscuous flag instead of adding a MAC filter. | |
2150 | */ | |
671889e6 JK |
2151 | if (is_broadcast_ether_addr(new->f->macaddr)) { |
2152 | if (i40e_aqc_broadcast_filter(vsi, vsi_name, | |
2153 | new->f)) | |
2154 | new->state = I40E_FILTER_FAILED; | |
2155 | else | |
2156 | new->state = I40E_FILTER_ACTIVE; | |
435c084a JK |
2157 | continue; |
2158 | } | |
2159 | ||
41c445ff | 2160 | /* add to add array */ |
c3c7ea27 | 2161 | if (num_add == 0) |
671889e6 | 2162 | add_head = new; |
c3c7ea27 | 2163 | cmd_flags = 0; |
671889e6 JK |
2164 | ether_addr_copy(add_list[num_add].mac_addr, |
2165 | new->f->macaddr); | |
2166 | if (new->f->vlan == I40E_VLAN_ANY) { | |
c3c7ea27 MW |
2167 | add_list[num_add].vlan_tag = 0; |
2168 | cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN; | |
2169 | } else { | |
2170 | add_list[num_add].vlan_tag = | |
671889e6 | 2171 | cpu_to_le16((u16)(new->f->vlan)); |
c3c7ea27 | 2172 | } |
41c445ff | 2173 | add_list[num_add].queue_number = 0; |
ac9e2390 | 2174 | /* set invalid match method for later detection */ |
0266ac45 | 2175 | add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES; |
41c445ff | 2176 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
41c445ff JB |
2177 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
2178 | num_add++; | |
2179 | ||
2180 | /* flush a full buffer */ | |
2181 | if (num_add == filter_list_len) { | |
00936319 JK |
2182 | i40e_aqc_add_filters(vsi, vsi_name, add_list, |
2183 | add_head, num_add, | |
2184 | &promisc_changed); | |
c3c7ea27 | 2185 | memset(add_list, 0, list_size); |
41c445ff | 2186 | num_add = 0; |
41c445ff JB |
2187 | } |
2188 | } | |
2189 | if (num_add) { | |
00936319 JK |
2190 | i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head, |
2191 | num_add, &promisc_changed); | |
41c445ff | 2192 | } |
c3c7ea27 MW |
2193 | /* Now move all of the filters from the temp add list back to |
2194 | * the VSI's list. | |
2195 | */ | |
278e7d0b | 2196 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
671889e6 JK |
2197 | hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) { |
2198 | /* Only update the state if we're still NEW */ | |
2199 | if (new->f->state == I40E_FILTER_NEW) | |
2200 | new->f->state = new->state; | |
2201 | hlist_del(&new->hlist); | |
2202 | kfree(new); | |
c3c7ea27 | 2203 | } |
278e7d0b | 2204 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
41c445ff JB |
2205 | kfree(add_list); |
2206 | add_list = NULL; | |
c3c7ea27 | 2207 | } |
41c445ff | 2208 | |
38326218 JK |
2209 | /* Determine the number of active and failed filters. */ |
2210 | spin_lock_bh(&vsi->mac_filter_hash_lock); | |
2211 | vsi->active_filters = 0; | |
2212 | hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) { | |
2213 | if (f->state == I40E_FILTER_ACTIVE) | |
2214 | vsi->active_filters++; | |
2215 | else if (f->state == I40E_FILTER_FAILED) | |
2216 | failed_filters++; | |
2217 | } | |
2218 | spin_unlock_bh(&vsi->mac_filter_hash_lock); | |
2219 | ||
2220 | /* If promiscuous mode has changed, we need to calculate a new | |
2221 | * threshold for when we are safe to exit | |
2222 | */ | |
2223 | if (promisc_changed) | |
2224 | vsi->promisc_threshold = (vsi->active_filters * 3) / 4; | |
2225 | ||
2226 | /* Check if we are able to exit overflow promiscuous mode. We can | |
2227 | * safely exit if we didn't just enter, we no longer have any failed | |
2228 | * filters, and we have reduced filters below the threshold value. | |
2229 | */ | |
c3c7ea27 | 2230 | if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state) && |
38326218 | 2231 | !promisc_changed && !failed_filters && |
c3c7ea27 | 2232 | (vsi->active_filters < vsi->promisc_threshold)) { |
38326218 JK |
2233 | dev_info(&pf->pdev->dev, |
2234 | "filter logjam cleared on %s, leaving overflow promiscuous mode\n", | |
2235 | vsi_name); | |
2236 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); | |
2237 | promisc_changed = true; | |
2238 | vsi->promisc_threshold = 0; | |
41c445ff JB |
2239 | } |
2240 | ||
a856b5cb ASJ |
2241 | /* if the VF is not trusted do not do promisc */ |
2242 | if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) { | |
2243 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); | |
2244 | goto out; | |
2245 | } | |
2246 | ||
41c445ff JB |
2247 | /* check for changes in promiscuous modes */ |
2248 | if (changed_flags & IFF_ALLMULTI) { | |
2249 | bool cur_multipromisc; | |
6995b36c | 2250 | |
41c445ff | 2251 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
ea02e90b MW |
2252 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
2253 | vsi->seid, | |
2254 | cur_multipromisc, | |
2255 | NULL); | |
2256 | if (aq_ret) { | |
2257 | retval = i40e_aq_rc_to_posix(aq_ret, | |
3e25a8f3 | 2258 | hw->aq.asq_last_status); |
41c445ff | 2259 | dev_info(&pf->pdev->dev, |
2d1de828 SN |
2260 | "set multi promisc failed on %s, err %s aq_err %s\n", |
2261 | vsi_name, | |
3e25a8f3 MW |
2262 | i40e_stat_str(hw, aq_ret), |
2263 | i40e_aq_str(hw, hw->aq.asq_last_status)); | |
ea02e90b | 2264 | } |
41c445ff | 2265 | } |
c3c7ea27 MW |
2266 | if ((changed_flags & IFF_PROMISC) || |
2267 | (promisc_changed && | |
2268 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))) { | |
41c445ff | 2269 | bool cur_promisc; |
6995b36c | 2270 | |
41c445ff JB |
2271 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
2272 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, | |
2273 | &vsi->state)); | |
6784ed5a ASJ |
2274 | if ((vsi->type == I40E_VSI_MAIN) && |
2275 | (pf->lan_veb != I40E_NO_VEB) && | |
2276 | !(pf->flags & I40E_FLAG_MFP_ENABLED)) { | |
92faef85 ASJ |
2277 | /* set defport ON for Main VSI instead of true promisc |
2278 | * this way we will get all unicast/multicast and VLAN | |
2279 | * promisc behavior but will not get VF or VMDq traffic | |
2280 | * replicated on the Main VSI. | |
2281 | */ | |
2282 | if (pf->cur_promisc != cur_promisc) { | |
2283 | pf->cur_promisc = cur_promisc; | |
5bc16031 MW |
2284 | if (cur_promisc) |
2285 | aq_ret = | |
2286 | i40e_aq_set_default_vsi(hw, | |
2287 | vsi->seid, | |
2288 | NULL); | |
2289 | else | |
2290 | aq_ret = | |
2291 | i40e_aq_clear_default_vsi(hw, | |
2292 | vsi->seid, | |
2293 | NULL); | |
2294 | if (aq_ret) { | |
2295 | retval = i40e_aq_rc_to_posix(aq_ret, | |
2296 | hw->aq.asq_last_status); | |
2297 | dev_info(&pf->pdev->dev, | |
2d1de828 SN |
2298 | "Set default VSI failed on %s, err %s, aq_err %s\n", |
2299 | vsi_name, | |
5bc16031 MW |
2300 | i40e_stat_str(hw, aq_ret), |
2301 | i40e_aq_str(hw, | |
2302 | hw->aq.asq_last_status)); | |
2303 | } | |
92faef85 ASJ |
2304 | } |
2305 | } else { | |
ea02e90b | 2306 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous( |
3e25a8f3 | 2307 | hw, |
f1c7e72e | 2308 | vsi->seid, |
b5569892 ASJ |
2309 | cur_promisc, NULL, |
2310 | true); | |
ea02e90b MW |
2311 | if (aq_ret) { |
2312 | retval = | |
2313 | i40e_aq_rc_to_posix(aq_ret, | |
3e25a8f3 | 2314 | hw->aq.asq_last_status); |
92faef85 | 2315 | dev_info(&pf->pdev->dev, |
2d1de828 SN |
2316 | "set unicast promisc failed on %s, err %s, aq_err %s\n", |
2317 | vsi_name, | |
3e25a8f3 MW |
2318 | i40e_stat_str(hw, aq_ret), |
2319 | i40e_aq_str(hw, | |
2320 | hw->aq.asq_last_status)); | |
ea02e90b MW |
2321 | } |
2322 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous( | |
3e25a8f3 | 2323 | hw, |
92faef85 ASJ |
2324 | vsi->seid, |
2325 | cur_promisc, NULL); | |
ea02e90b MW |
2326 | if (aq_ret) { |
2327 | retval = | |
2328 | i40e_aq_rc_to_posix(aq_ret, | |
3e25a8f3 | 2329 | hw->aq.asq_last_status); |
92faef85 | 2330 | dev_info(&pf->pdev->dev, |
2d1de828 SN |
2331 | "set multicast promisc failed on %s, err %s, aq_err %s\n", |
2332 | vsi_name, | |
3e25a8f3 MW |
2333 | i40e_stat_str(hw, aq_ret), |
2334 | i40e_aq_str(hw, | |
2335 | hw->aq.asq_last_status)); | |
ea02e90b | 2336 | } |
92faef85 | 2337 | } |
ea02e90b MW |
2338 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
2339 | vsi->seid, | |
2340 | cur_promisc, NULL); | |
2341 | if (aq_ret) { | |
2342 | retval = i40e_aq_rc_to_posix(aq_ret, | |
2343 | pf->hw.aq.asq_last_status); | |
1a10370a | 2344 | dev_info(&pf->pdev->dev, |
f1c7e72e | 2345 | "set brdcast promisc failed, err %s, aq_err %s\n", |
3e25a8f3 MW |
2346 | i40e_stat_str(hw, aq_ret), |
2347 | i40e_aq_str(hw, | |
2348 | hw->aq.asq_last_status)); | |
ea02e90b | 2349 | } |
41c445ff | 2350 | } |
ea02e90b | 2351 | out: |
2818ccd9 JB |
2352 | /* if something went wrong then set the changed flag so we try again */ |
2353 | if (retval) | |
2354 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; | |
2355 | ||
41c445ff | 2356 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
ea02e90b | 2357 | return retval; |
4a2ce27b JK |
2358 | |
2359 | err_no_memory: | |
2360 | /* Restore elements on the temporary add and delete lists */ | |
2361 | spin_lock_bh(&vsi->mac_filter_hash_lock); | |
84f5ca6c | 2362 | err_no_memory_locked: |
671889e6 JK |
2363 | i40e_undo_del_filter_entries(vsi, &tmp_del_list); |
2364 | i40e_undo_add_filter_entries(vsi, &tmp_add_list); | |
4a2ce27b JK |
2365 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
2366 | ||
2367 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; | |
2368 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); | |
2369 | return -ENOMEM; | |
41c445ff JB |
2370 | } |
2371 | ||
2372 | /** | |
2373 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW | |
2374 | * @pf: board private structure | |
2375 | **/ | |
2376 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) | |
2377 | { | |
2378 | int v; | |
2379 | ||
2380 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) | |
2381 | return; | |
2382 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; | |
2383 | ||
505682cd | 2384 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
41c445ff | 2385 | if (pf->vsi[v] && |
17652c63 JB |
2386 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) { |
2387 | int ret = i40e_sync_vsi_filters(pf->vsi[v]); | |
2388 | ||
2389 | if (ret) { | |
2390 | /* come back and try again later */ | |
2391 | pf->flags |= I40E_FLAG_FILTER_SYNC; | |
2392 | break; | |
2393 | } | |
2394 | } | |
41c445ff JB |
2395 | } |
2396 | } | |
2397 | ||
2398 | /** | |
2399 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit | |
2400 | * @netdev: network interface device structure | |
2401 | * @new_mtu: new value for maximum frame size | |
2402 | * | |
2403 | * Returns 0 on success, negative on failure | |
2404 | **/ | |
2405 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) | |
2406 | { | |
2407 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
41c445ff | 2408 | struct i40e_vsi *vsi = np->vsi; |
0ef2d5af | 2409 | struct i40e_pf *pf = vsi->back; |
41c445ff | 2410 | |
41c445ff JB |
2411 | netdev_info(netdev, "changing MTU from %d to %d\n", |
2412 | netdev->mtu, new_mtu); | |
2413 | netdev->mtu = new_mtu; | |
2414 | if (netif_running(netdev)) | |
2415 | i40e_vsi_reinit_locked(vsi); | |
0ef2d5af MW |
2416 | pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED | |
2417 | I40E_FLAG_CLIENT_L2_CHANGE); | |
41c445ff JB |
2418 | return 0; |
2419 | } | |
2420 | ||
beb0dff1 JK |
2421 | /** |
2422 | * i40e_ioctl - Access the hwtstamp interface | |
2423 | * @netdev: network interface device structure | |
2424 | * @ifr: interface request data | |
2425 | * @cmd: ioctl command | |
2426 | **/ | |
2427 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) | |
2428 | { | |
2429 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
2430 | struct i40e_pf *pf = np->vsi->back; | |
2431 | ||
2432 | switch (cmd) { | |
2433 | case SIOCGHWTSTAMP: | |
2434 | return i40e_ptp_get_ts_config(pf, ifr); | |
2435 | case SIOCSHWTSTAMP: | |
2436 | return i40e_ptp_set_ts_config(pf, ifr); | |
2437 | default: | |
2438 | return -EOPNOTSUPP; | |
2439 | } | |
2440 | } | |
2441 | ||
41c445ff JB |
2442 | /** |
2443 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI | |
2444 | * @vsi: the vsi being adjusted | |
2445 | **/ | |
2446 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) | |
2447 | { | |
2448 | struct i40e_vsi_context ctxt; | |
2449 | i40e_status ret; | |
2450 | ||
2451 | if ((vsi->info.valid_sections & | |
2452 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && | |
2453 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) | |
2454 | return; /* already enabled */ | |
2455 | ||
2456 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); | |
2457 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | | |
2458 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; | |
2459 | ||
2460 | ctxt.seid = vsi->seid; | |
1a2f6248 | 2461 | ctxt.info = vsi->info; |
41c445ff JB |
2462 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
2463 | if (ret) { | |
2464 | dev_info(&vsi->back->pdev->dev, | |
f1c7e72e SN |
2465 | "update vlan stripping failed, err %s aq_err %s\n", |
2466 | i40e_stat_str(&vsi->back->hw, ret), | |
2467 | i40e_aq_str(&vsi->back->hw, | |
2468 | vsi->back->hw.aq.asq_last_status)); | |
41c445ff JB |
2469 | } |
2470 | } | |
2471 | ||
2472 | /** | |
2473 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI | |
2474 | * @vsi: the vsi being adjusted | |
2475 | **/ | |
2476 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) | |
2477 | { | |
2478 | struct i40e_vsi_context ctxt; | |
2479 | i40e_status ret; | |
2480 | ||
2481 | if ((vsi->info.valid_sections & | |
2482 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && | |
2483 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == | |
2484 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) | |
2485 | return; /* already disabled */ | |
2486 | ||
2487 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); | |
2488 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | | |
2489 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; | |
2490 | ||
2491 | ctxt.seid = vsi->seid; | |
1a2f6248 | 2492 | ctxt.info = vsi->info; |
41c445ff JB |
2493 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
2494 | if (ret) { | |
2495 | dev_info(&vsi->back->pdev->dev, | |
f1c7e72e SN |
2496 | "update vlan stripping failed, err %s aq_err %s\n", |
2497 | i40e_stat_str(&vsi->back->hw, ret), | |
2498 | i40e_aq_str(&vsi->back->hw, | |
2499 | vsi->back->hw.aq.asq_last_status)); | |
41c445ff JB |
2500 | } |
2501 | } | |
2502 | ||
2503 | /** | |
2504 | * i40e_vlan_rx_register - Setup or shutdown vlan offload | |
2505 | * @netdev: network interface to be adjusted | |
2506 | * @features: netdev features to test if VLAN offload is enabled or not | |
2507 | **/ | |
2508 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) | |
2509 | { | |
2510 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
2511 | struct i40e_vsi *vsi = np->vsi; | |
2512 | ||
2513 | if (features & NETIF_F_HW_VLAN_CTAG_RX) | |
2514 | i40e_vlan_stripping_enable(vsi); | |
2515 | else | |
2516 | i40e_vlan_stripping_disable(vsi); | |
2517 | } | |
2518 | ||
2519 | /** | |
490a4ad3 | 2520 | * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address |
41c445ff JB |
2521 | * @vsi: the vsi being configured |
2522 | * @vid: vlan id to be added (0 = untagged only , -1 = any) | |
490a4ad3 JK |
2523 | * |
2524 | * This is a helper function for adding a new MAC/VLAN filter with the | |
2525 | * specified VLAN for each existing MAC address already in the hash table. | |
2526 | * This function does *not* perform any accounting to update filters based on | |
2527 | * VLAN mode. | |
2528 | * | |
2529 | * NOTE: this function expects to be called while under the | |
2530 | * mac_filter_hash_lock | |
41c445ff | 2531 | **/ |
9af52f60 | 2532 | int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid) |
41c445ff | 2533 | { |
490a4ad3 | 2534 | struct i40e_mac_filter *f, *add_f; |
278e7d0b JK |
2535 | struct hlist_node *h; |
2536 | int bkt; | |
41c445ff | 2537 | |
278e7d0b | 2538 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
57b341d6 JK |
2539 | if (f->state == I40E_FILTER_REMOVE) |
2540 | continue; | |
1bc87e80 | 2541 | add_f = i40e_add_filter(vsi, f->macaddr, vid); |
41c445ff JB |
2542 | if (!add_f) { |
2543 | dev_info(&vsi->back->pdev->dev, | |
2544 | "Could not add vlan filter %d for %pM\n", | |
2545 | vid, f->macaddr); | |
2546 | return -ENOMEM; | |
2547 | } | |
2548 | } | |
2549 | ||
490a4ad3 JK |
2550 | return 0; |
2551 | } | |
2552 | ||
2553 | /** | |
2554 | * i40e_vsi_add_vlan - Add VSI membership for given VLAN | |
2555 | * @vsi: the VSI being configured | |
f94484b7 | 2556 | * @vid: VLAN id to be added |
490a4ad3 | 2557 | **/ |
f94484b7 | 2558 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid) |
490a4ad3 | 2559 | { |
489a3265 | 2560 | int err; |
490a4ad3 | 2561 | |
f94484b7 JK |
2562 | if (!vid || vsi->info.pvid) |
2563 | return -EINVAL; | |
2564 | ||
490a4ad3 JK |
2565 | /* Locked once because all functions invoked below iterates list*/ |
2566 | spin_lock_bh(&vsi->mac_filter_hash_lock); | |
490a4ad3 | 2567 | err = i40e_add_vlan_all_mac(vsi, vid); |
278e7d0b | 2568 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
489a3265 JK |
2569 | if (err) |
2570 | return err; | |
21659035 | 2571 | |
0e4425ed JB |
2572 | /* schedule our worker thread which will take care of |
2573 | * applying the new filter changes | |
2574 | */ | |
2575 | i40e_service_event_schedule(vsi->back); | |
2576 | return 0; | |
41c445ff JB |
2577 | } |
2578 | ||
2579 | /** | |
490a4ad3 | 2580 | * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN |
41c445ff JB |
2581 | * @vsi: the vsi being configured |
2582 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) | |
490a4ad3 JK |
2583 | * |
2584 | * This function should be used to remove all VLAN filters which match the | |
2585 | * given VID. It does not schedule the service event and does not take the | |
2586 | * mac_filter_hash_lock so it may be combined with other operations under | |
2587 | * a single invocation of the mac_filter_hash_lock. | |
2588 | * | |
2589 | * NOTE: this function expects to be called while under the | |
2590 | * mac_filter_hash_lock | |
2591 | */ | |
9af52f60 | 2592 | void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid) |
41c445ff | 2593 | { |
84f5ca6c | 2594 | struct i40e_mac_filter *f; |
278e7d0b | 2595 | struct hlist_node *h; |
278e7d0b | 2596 | int bkt; |
41c445ff | 2597 | |
278e7d0b | 2598 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
290d2557 JK |
2599 | if (f->vlan == vid) |
2600 | __i40e_del_filter(vsi, f); | |
2601 | } | |
490a4ad3 | 2602 | } |
41c445ff | 2603 | |
490a4ad3 JK |
2604 | /** |
2605 | * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN | |
2606 | * @vsi: the VSI being configured | |
f94484b7 | 2607 | * @vid: VLAN id to be removed |
490a4ad3 | 2608 | **/ |
f94484b7 | 2609 | void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid) |
490a4ad3 | 2610 | { |
f94484b7 JK |
2611 | if (!vid || vsi->info.pvid) |
2612 | return; | |
2613 | ||
490a4ad3 JK |
2614 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
2615 | i40e_rm_vlan_all_mac(vsi, vid); | |
278e7d0b | 2616 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
21659035 | 2617 | |
0e4425ed JB |
2618 | /* schedule our worker thread which will take care of |
2619 | * applying the new filter changes | |
2620 | */ | |
2621 | i40e_service_event_schedule(vsi->back); | |
41c445ff JB |
2622 | } |
2623 | ||
2624 | /** | |
2625 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload | |
2626 | * @netdev: network interface to be adjusted | |
2627 | * @vid: vlan id to be added | |
078b5876 JB |
2628 | * |
2629 | * net_device_ops implementation for adding vlan ids | |
41c445ff JB |
2630 | **/ |
2631 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, | |
2632 | __always_unused __be16 proto, u16 vid) | |
2633 | { | |
2634 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
2635 | struct i40e_vsi *vsi = np->vsi; | |
078b5876 | 2636 | int ret = 0; |
41c445ff | 2637 | |
6a112785 | 2638 | if (vid >= VLAN_N_VID) |
078b5876 JB |
2639 | return -EINVAL; |
2640 | ||
6982d429 ASJ |
2641 | /* If the network stack called us with vid = 0 then |
2642 | * it is asking to receive priority tagged packets with | |
2643 | * vlan id 0. Our HW receives them by default when configured | |
2644 | * to receive untagged packets so there is no need to add an | |
2645 | * extra filter for vlan 0 tagged packets. | |
41c445ff | 2646 | */ |
6982d429 ASJ |
2647 | if (vid) |
2648 | ret = i40e_vsi_add_vlan(vsi, vid); | |
41c445ff | 2649 | |
6a112785 | 2650 | if (!ret) |
078b5876 | 2651 | set_bit(vid, vsi->active_vlans); |
41c445ff | 2652 | |
078b5876 | 2653 | return ret; |
41c445ff JB |
2654 | } |
2655 | ||
2656 | /** | |
2657 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload | |
2658 | * @netdev: network interface to be adjusted | |
2659 | * @vid: vlan id to be removed | |
078b5876 | 2660 | * |
fdfd943e | 2661 | * net_device_ops implementation for removing vlan ids |
41c445ff JB |
2662 | **/ |
2663 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, | |
2664 | __always_unused __be16 proto, u16 vid) | |
2665 | { | |
2666 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
2667 | struct i40e_vsi *vsi = np->vsi; | |
2668 | ||
41c445ff JB |
2669 | /* return code is ignored as there is nothing a user |
2670 | * can do about failure to remove and a log message was | |
078b5876 | 2671 | * already printed from the other function |
41c445ff JB |
2672 | */ |
2673 | i40e_vsi_kill_vlan(vsi, vid); | |
2674 | ||
2675 | clear_bit(vid, vsi->active_vlans); | |
078b5876 | 2676 | |
41c445ff JB |
2677 | return 0; |
2678 | } | |
2679 | ||
b1b15df5 TD |
2680 | /** |
2681 | * i40e_macaddr_init - explicitly write the mac address filters | |
2682 | * | |
2683 | * @vsi: pointer to the vsi | |
2684 | * @macaddr: the MAC address | |
2685 | * | |
2686 | * This is needed when the macaddr has been obtained by other | |
2687 | * means than the default, e.g., from Open Firmware or IDPROM. | |
2688 | * Returns 0 on success, negative on failure | |
2689 | **/ | |
2690 | static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) | |
2691 | { | |
2692 | int ret; | |
2693 | struct i40e_aqc_add_macvlan_element_data element; | |
2694 | ||
2695 | ret = i40e_aq_mac_address_write(&vsi->back->hw, | |
2696 | I40E_AQC_WRITE_TYPE_LAA_WOL, | |
2697 | macaddr, NULL); | |
2698 | if (ret) { | |
2699 | dev_info(&vsi->back->pdev->dev, | |
2700 | "Addr change for VSI failed: %d\n", ret); | |
2701 | return -EADDRNOTAVAIL; | |
2702 | } | |
2703 | ||
2704 | memset(&element, 0, sizeof(element)); | |
2705 | ether_addr_copy(element.mac_addr, macaddr); | |
2706 | element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); | |
2707 | ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); | |
2708 | if (ret) { | |
2709 | dev_info(&vsi->back->pdev->dev, | |
2710 | "add filter failed err %s aq_err %s\n", | |
2711 | i40e_stat_str(&vsi->back->hw, ret), | |
2712 | i40e_aq_str(&vsi->back->hw, | |
2713 | vsi->back->hw.aq.asq_last_status)); | |
2714 | } | |
2715 | return ret; | |
2716 | } | |
2717 | ||
41c445ff JB |
2718 | /** |
2719 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up | |
2720 | * @vsi: the vsi being brought back up | |
2721 | **/ | |
2722 | static void i40e_restore_vlan(struct i40e_vsi *vsi) | |
2723 | { | |
2724 | u16 vid; | |
2725 | ||
2726 | if (!vsi->netdev) | |
2727 | return; | |
2728 | ||
2729 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); | |
2730 | ||
2731 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) | |
2732 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), | |
2733 | vid); | |
2734 | } | |
2735 | ||
2736 | /** | |
2737 | * i40e_vsi_add_pvid - Add pvid for the VSI | |
2738 | * @vsi: the vsi being adjusted | |
2739 | * @vid: the vlan id to set as a PVID | |
2740 | **/ | |
dcae29be | 2741 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
41c445ff JB |
2742 | { |
2743 | struct i40e_vsi_context ctxt; | |
f1c7e72e | 2744 | i40e_status ret; |
41c445ff JB |
2745 | |
2746 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); | |
2747 | vsi->info.pvid = cpu_to_le16(vid); | |
6c12fcbf GR |
2748 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
2749 | I40E_AQ_VSI_PVLAN_INSERT_PVID | | |
b774c7dd | 2750 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
41c445ff JB |
2751 | |
2752 | ctxt.seid = vsi->seid; | |
1a2f6248 | 2753 | ctxt.info = vsi->info; |
f1c7e72e SN |
2754 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
2755 | if (ret) { | |
41c445ff | 2756 | dev_info(&vsi->back->pdev->dev, |
f1c7e72e SN |
2757 | "add pvid failed, err %s aq_err %s\n", |
2758 | i40e_stat_str(&vsi->back->hw, ret), | |
2759 | i40e_aq_str(&vsi->back->hw, | |
2760 | vsi->back->hw.aq.asq_last_status)); | |
dcae29be | 2761 | return -ENOENT; |
41c445ff JB |
2762 | } |
2763 | ||
dcae29be | 2764 | return 0; |
41c445ff JB |
2765 | } |
2766 | ||
2767 | /** | |
2768 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI | |
2769 | * @vsi: the vsi being adjusted | |
2770 | * | |
2771 | * Just use the vlan_rx_register() service to put it back to normal | |
2772 | **/ | |
2773 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) | |
2774 | { | |
6c12fcbf GR |
2775 | i40e_vlan_stripping_disable(vsi); |
2776 | ||
41c445ff | 2777 | vsi->info.pvid = 0; |
41c445ff JB |
2778 | } |
2779 | ||
2780 | /** | |
2781 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources | |
2782 | * @vsi: ptr to the VSI | |
2783 | * | |
2784 | * If this function returns with an error, then it's possible one or | |
2785 | * more of the rings is populated (while the rest are not). It is the | |
2786 | * callers duty to clean those orphaned rings. | |
2787 | * | |
2788 | * Return 0 on success, negative on failure | |
2789 | **/ | |
2790 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) | |
2791 | { | |
2792 | int i, err = 0; | |
2793 | ||
2794 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) | |
9f65e15b | 2795 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
41c445ff JB |
2796 | |
2797 | return err; | |
2798 | } | |
2799 | ||
2800 | /** | |
2801 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues | |
2802 | * @vsi: ptr to the VSI | |
2803 | * | |
2804 | * Free VSI's transmit software resources | |
2805 | **/ | |
2806 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) | |
2807 | { | |
2808 | int i; | |
2809 | ||
8e9dca53 GR |
2810 | if (!vsi->tx_rings) |
2811 | return; | |
2812 | ||
41c445ff | 2813 | for (i = 0; i < vsi->num_queue_pairs; i++) |
8e9dca53 | 2814 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
9f65e15b | 2815 | i40e_free_tx_resources(vsi->tx_rings[i]); |
41c445ff JB |
2816 | } |
2817 | ||
2818 | /** | |
2819 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources | |
2820 | * @vsi: ptr to the VSI | |
2821 | * | |
2822 | * If this function returns with an error, then it's possible one or | |
2823 | * more of the rings is populated (while the rest are not). It is the | |
2824 | * callers duty to clean those orphaned rings. | |
2825 | * | |
2826 | * Return 0 on success, negative on failure | |
2827 | **/ | |
2828 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) | |
2829 | { | |
2830 | int i, err = 0; | |
2831 | ||
2832 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) | |
9f65e15b | 2833 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
41c445ff JB |
2834 | return err; |
2835 | } | |
2836 | ||
2837 | /** | |
2838 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues | |
2839 | * @vsi: ptr to the VSI | |
2840 | * | |
2841 | * Free all receive software resources | |
2842 | **/ | |
2843 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) | |
2844 | { | |
2845 | int i; | |
2846 | ||
8e9dca53 GR |
2847 | if (!vsi->rx_rings) |
2848 | return; | |
2849 | ||
41c445ff | 2850 | for (i = 0; i < vsi->num_queue_pairs; i++) |
8e9dca53 | 2851 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
9f65e15b | 2852 | i40e_free_rx_resources(vsi->rx_rings[i]); |
41c445ff JB |
2853 | } |
2854 | ||
3ffa037d NP |
2855 | /** |
2856 | * i40e_config_xps_tx_ring - Configure XPS for a Tx ring | |
2857 | * @ring: The Tx ring to configure | |
2858 | * | |
2859 | * This enables/disables XPS for a given Tx descriptor ring | |
2860 | * based on the TCs enabled for the VSI that ring belongs to. | |
2861 | **/ | |
2862 | static void i40e_config_xps_tx_ring(struct i40e_ring *ring) | |
2863 | { | |
2864 | struct i40e_vsi *vsi = ring->vsi; | |
2865 | cpumask_var_t mask; | |
2866 | ||
9a660eea JB |
2867 | if (!ring->q_vector || !ring->netdev) |
2868 | return; | |
2869 | ||
2870 | /* Single TC mode enable XPS */ | |
2871 | if (vsi->tc_config.numtc <= 1) { | |
2872 | if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) | |
3ffa037d NP |
2873 | netif_set_xps_queue(ring->netdev, |
2874 | &ring->q_vector->affinity_mask, | |
2875 | ring->queue_index); | |
9a660eea JB |
2876 | } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) { |
2877 | /* Disable XPS to allow selection based on TC */ | |
2878 | bitmap_zero(cpumask_bits(mask), nr_cpumask_bits); | |
2879 | netif_set_xps_queue(ring->netdev, mask, ring->queue_index); | |
2880 | free_cpumask_var(mask); | |
3ffa037d | 2881 | } |
0e4425ed JB |
2882 | |
2883 | /* schedule our worker thread which will take care of | |
2884 | * applying the new filter changes | |
2885 | */ | |
2886 | i40e_service_event_schedule(vsi->back); | |
3ffa037d NP |
2887 | } |
2888 | ||
41c445ff JB |
2889 | /** |
2890 | * i40e_configure_tx_ring - Configure a transmit ring context and rest | |
2891 | * @ring: The Tx ring to configure | |
2892 | * | |
2893 | * Configure the Tx descriptor ring in the HMC context. | |
2894 | **/ | |
2895 | static int i40e_configure_tx_ring(struct i40e_ring *ring) | |
2896 | { | |
2897 | struct i40e_vsi *vsi = ring->vsi; | |
2898 | u16 pf_q = vsi->base_queue + ring->queue_index; | |
2899 | struct i40e_hw *hw = &vsi->back->hw; | |
2900 | struct i40e_hmc_obj_txq tx_ctx; | |
2901 | i40e_status err = 0; | |
2902 | u32 qtx_ctl = 0; | |
2903 | ||
2904 | /* some ATR related tx ring init */ | |
60ea5f83 | 2905 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
41c445ff JB |
2906 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
2907 | ring->atr_count = 0; | |
2908 | } else { | |
2909 | ring->atr_sample_rate = 0; | |
2910 | } | |
2911 | ||
3ffa037d NP |
2912 | /* configure XPS */ |
2913 | i40e_config_xps_tx_ring(ring); | |
41c445ff JB |
2914 | |
2915 | /* clear the context structure first */ | |
2916 | memset(&tx_ctx, 0, sizeof(tx_ctx)); | |
2917 | ||
2918 | tx_ctx.new_context = 1; | |
2919 | tx_ctx.base = (ring->dma / 128); | |
2920 | tx_ctx.qlen = ring->count; | |
60ea5f83 JB |
2921 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
2922 | I40E_FLAG_FD_ATR_ENABLED)); | |
beb0dff1 | 2923 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
1943d8ba JB |
2924 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
2925 | if (vsi->type != I40E_VSI_FDIR) | |
2926 | tx_ctx.head_wb_ena = 1; | |
2927 | tx_ctx.head_wb_addr = ring->dma + | |
2928 | (ring->count * sizeof(struct i40e_tx_desc)); | |
41c445ff JB |
2929 | |
2930 | /* As part of VSI creation/update, FW allocates certain | |
2931 | * Tx arbitration queue sets for each TC enabled for | |
2932 | * the VSI. The FW returns the handles to these queue | |
2933 | * sets as part of the response buffer to Add VSI, | |
2934 | * Update VSI, etc. AQ commands. It is expected that | |
2935 | * these queue set handles be associated with the Tx | |
2936 | * queues by the driver as part of the TX queue context | |
2937 | * initialization. This has to be done regardless of | |
2938 | * DCB as by default everything is mapped to TC0. | |
2939 | */ | |
2940 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); | |
2941 | tx_ctx.rdylist_act = 0; | |
2942 | ||
2943 | /* clear the context in the HMC */ | |
2944 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); | |
2945 | if (err) { | |
2946 | dev_info(&vsi->back->pdev->dev, | |
2947 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", | |
2948 | ring->queue_index, pf_q, err); | |
2949 | return -ENOMEM; | |
2950 | } | |
2951 | ||
2952 | /* set the context in the HMC */ | |
2953 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); | |
2954 | if (err) { | |
2955 | dev_info(&vsi->back->pdev->dev, | |
2956 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", | |
2957 | ring->queue_index, pf_q, err); | |
2958 | return -ENOMEM; | |
2959 | } | |
2960 | ||
2961 | /* Now associate this queue with this PCI function */ | |
7a28d885 | 2962 | if (vsi->type == I40E_VSI_VMDQ2) { |
9d8bf547 | 2963 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
7a28d885 MW |
2964 | qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) & |
2965 | I40E_QTX_CTL_VFVM_INDX_MASK; | |
2966 | } else { | |
9d8bf547 | 2967 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
7a28d885 MW |
2968 | } |
2969 | ||
13fd9774 SN |
2970 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
2971 | I40E_QTX_CTL_PF_INDX_MASK); | |
41c445ff JB |
2972 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
2973 | i40e_flush(hw); | |
2974 | ||
41c445ff JB |
2975 | /* cache tail off for easier writes later */ |
2976 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); | |
2977 | ||
2978 | return 0; | |
2979 | } | |
2980 | ||
2981 | /** | |
2982 | * i40e_configure_rx_ring - Configure a receive ring context | |
2983 | * @ring: The Rx ring to configure | |
2984 | * | |
2985 | * Configure the Rx descriptor ring in the HMC context. | |
2986 | **/ | |
2987 | static int i40e_configure_rx_ring(struct i40e_ring *ring) | |
2988 | { | |
2989 | struct i40e_vsi *vsi = ring->vsi; | |
2990 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; | |
2991 | u16 pf_q = vsi->base_queue + ring->queue_index; | |
2992 | struct i40e_hw *hw = &vsi->back->hw; | |
2993 | struct i40e_hmc_obj_rxq rx_ctx; | |
2994 | i40e_status err = 0; | |
2995 | ||
2996 | ring->state = 0; | |
2997 | ||
2998 | /* clear the context structure first */ | |
2999 | memset(&rx_ctx, 0, sizeof(rx_ctx)); | |
3000 | ||
3001 | ring->rx_buf_len = vsi->rx_buf_len; | |
41c445ff | 3002 | |
dab86afd AD |
3003 | rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len, |
3004 | BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT)); | |
41c445ff JB |
3005 | |
3006 | rx_ctx.base = (ring->dma / 128); | |
3007 | rx_ctx.qlen = ring->count; | |
3008 | ||
bec60fc4 JB |
3009 | /* use 32 byte descriptors */ |
3010 | rx_ctx.dsize = 1; | |
41c445ff | 3011 | |
bec60fc4 JB |
3012 | /* descriptor type is always zero |
3013 | * rx_ctx.dtype = 0; | |
3014 | */ | |
b32bfa17 | 3015 | rx_ctx.hsplit_0 = 0; |
41c445ff | 3016 | |
b32bfa17 | 3017 | rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len); |
7134f9ce JB |
3018 | if (hw->revision_id == 0) |
3019 | rx_ctx.lrxqthresh = 0; | |
3020 | else | |
3021 | rx_ctx.lrxqthresh = 2; | |
41c445ff JB |
3022 | rx_ctx.crcstrip = 1; |
3023 | rx_ctx.l2tsel = 1; | |
c4bbac39 JB |
3024 | /* this controls whether VLAN is stripped from inner headers */ |
3025 | rx_ctx.showiv = 0; | |
acb3676b CS |
3026 | /* set the prefena field to 1 because the manual says to */ |
3027 | rx_ctx.prefena = 1; | |
41c445ff JB |
3028 | |
3029 | /* clear the context in the HMC */ | |
3030 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); | |
3031 | if (err) { | |
3032 | dev_info(&vsi->back->pdev->dev, | |
3033 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", | |
3034 | ring->queue_index, pf_q, err); | |
3035 | return -ENOMEM; | |
3036 | } | |
3037 | ||
3038 | /* set the context in the HMC */ | |
3039 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); | |
3040 | if (err) { | |
3041 | dev_info(&vsi->back->pdev->dev, | |
3042 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", | |
3043 | ring->queue_index, pf_q, err); | |
3044 | return -ENOMEM; | |
3045 | } | |
3046 | ||
ca9ec088 AD |
3047 | /* configure Rx buffer alignment */ |
3048 | if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) | |
3049 | clear_ring_build_skb_enabled(ring); | |
3050 | else | |
3051 | set_ring_build_skb_enabled(ring); | |
3052 | ||
41c445ff JB |
3053 | /* cache tail for quicker writes, and clear the reg before use */ |
3054 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); | |
3055 | writel(0, ring->tail); | |
3056 | ||
1a557afc | 3057 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
41c445ff JB |
3058 | |
3059 | return 0; | |
3060 | } | |
3061 | ||
3062 | /** | |
3063 | * i40e_vsi_configure_tx - Configure the VSI for Tx | |
3064 | * @vsi: VSI structure describing this set of rings and resources | |
3065 | * | |
3066 | * Configure the Tx VSI for operation. | |
3067 | **/ | |
3068 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) | |
3069 | { | |
3070 | int err = 0; | |
3071 | u16 i; | |
3072 | ||
9f65e15b AD |
3073 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
3074 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); | |
41c445ff JB |
3075 | |
3076 | return err; | |
3077 | } | |
3078 | ||
3079 | /** | |
3080 | * i40e_vsi_configure_rx - Configure the VSI for Rx | |
3081 | * @vsi: the VSI being configured | |
3082 | * | |
3083 | * Configure the Rx VSI for operation. | |
3084 | **/ | |
3085 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) | |
3086 | { | |
3087 | int err = 0; | |
3088 | u16 i; | |
3089 | ||
dab86afd AD |
3090 | if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) { |
3091 | vsi->max_frame = I40E_MAX_RXBUFFER; | |
3092 | vsi->rx_buf_len = I40E_RXBUFFER_2048; | |
3093 | #if (PAGE_SIZE < 8192) | |
ca9ec088 AD |
3094 | } else if (!I40E_2K_TOO_SMALL_WITH_PADDING && |
3095 | (vsi->netdev->mtu <= ETH_DATA_LEN)) { | |
dab86afd AD |
3096 | vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN; |
3097 | vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN; | |
3098 | #endif | |
3099 | } else { | |
3100 | vsi->max_frame = I40E_MAX_RXBUFFER; | |
98efd694 AD |
3101 | vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 : |
3102 | I40E_RXBUFFER_2048; | |
dab86afd | 3103 | } |
41c445ff JB |
3104 | |
3105 | /* set up individual rings */ | |
3106 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) | |
9f65e15b | 3107 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
41c445ff JB |
3108 | |
3109 | return err; | |
3110 | } | |
3111 | ||
3112 | /** | |
3113 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC | |
3114 | * @vsi: ptr to the VSI | |
3115 | **/ | |
3116 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) | |
3117 | { | |
e7046ee1 | 3118 | struct i40e_ring *tx_ring, *rx_ring; |
41c445ff JB |
3119 | u16 qoffset, qcount; |
3120 | int i, n; | |
3121 | ||
cd238a3e PN |
3122 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
3123 | /* Reset the TC information */ | |
3124 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
3125 | rx_ring = vsi->rx_rings[i]; | |
3126 | tx_ring = vsi->tx_rings[i]; | |
3127 | rx_ring->dcb_tc = 0; | |
3128 | tx_ring->dcb_tc = 0; | |
3129 | } | |
3130 | } | |
41c445ff JB |
3131 | |
3132 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { | |
41a1d04b | 3133 | if (!(vsi->tc_config.enabled_tc & BIT_ULL(n))) |
41c445ff JB |
3134 | continue; |
3135 | ||
3136 | qoffset = vsi->tc_config.tc_info[n].qoffset; | |
3137 | qcount = vsi->tc_config.tc_info[n].qcount; | |
3138 | for (i = qoffset; i < (qoffset + qcount); i++) { | |
e7046ee1 AA |
3139 | rx_ring = vsi->rx_rings[i]; |
3140 | tx_ring = vsi->tx_rings[i]; | |
41c445ff JB |
3141 | rx_ring->dcb_tc = n; |
3142 | tx_ring->dcb_tc = n; | |
3143 | } | |
3144 | } | |
3145 | } | |
3146 | ||
3147 | /** | |
3148 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI | |
3149 | * @vsi: ptr to the VSI | |
3150 | **/ | |
3151 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) | |
3152 | { | |
b1b15df5 TD |
3153 | struct i40e_pf *pf = vsi->back; |
3154 | int err; | |
3155 | ||
41c445ff JB |
3156 | if (vsi->netdev) |
3157 | i40e_set_rx_mode(vsi->netdev); | |
b1b15df5 TD |
3158 | |
3159 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { | |
3160 | err = i40e_macaddr_init(vsi, pf->hw.mac.addr); | |
3161 | if (err) { | |
3162 | dev_warn(&pf->pdev->dev, | |
3163 | "could not set up macaddr; err %d\n", err); | |
3164 | } | |
3165 | } | |
41c445ff JB |
3166 | } |
3167 | ||
17a73f6b JG |
3168 | /** |
3169 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters | |
3170 | * @vsi: Pointer to the targeted VSI | |
3171 | * | |
3172 | * This function replays the hlist on the hw where all the SB Flow Director | |
3173 | * filters were saved. | |
3174 | **/ | |
3175 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) | |
3176 | { | |
3177 | struct i40e_fdir_filter *filter; | |
3178 | struct i40e_pf *pf = vsi->back; | |
3179 | struct hlist_node *node; | |
3180 | ||
55a5e60b ASJ |
3181 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
3182 | return; | |
3183 | ||
6d069425 | 3184 | /* Reset FDir counters as we're replaying all existing filters */ |
097dbf52 JK |
3185 | pf->fd_tcp4_filter_cnt = 0; |
3186 | pf->fd_udp4_filter_cnt = 0; | |
f223c875 | 3187 | pf->fd_sctp4_filter_cnt = 0; |
097dbf52 | 3188 | pf->fd_ip4_filter_cnt = 0; |
6d069425 | 3189 | |
17a73f6b JG |
3190 | hlist_for_each_entry_safe(filter, node, |
3191 | &pf->fdir_filter_list, fdir_node) { | |
3192 | i40e_add_del_fdir(vsi, filter, true); | |
3193 | } | |
3194 | } | |
3195 | ||
41c445ff JB |
3196 | /** |
3197 | * i40e_vsi_configure - Set up the VSI for action | |
3198 | * @vsi: the VSI being configured | |
3199 | **/ | |
3200 | static int i40e_vsi_configure(struct i40e_vsi *vsi) | |
3201 | { | |
3202 | int err; | |
3203 | ||
3204 | i40e_set_vsi_rx_mode(vsi); | |
3205 | i40e_restore_vlan(vsi); | |
3206 | i40e_vsi_config_dcb_rings(vsi); | |
3207 | err = i40e_vsi_configure_tx(vsi); | |
3208 | if (!err) | |
3209 | err = i40e_vsi_configure_rx(vsi); | |
3210 | ||
3211 | return err; | |
3212 | } | |
3213 | ||
3214 | /** | |
3215 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW | |
3216 | * @vsi: the VSI being configured | |
3217 | **/ | |
3218 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) | |
3219 | { | |
3220 | struct i40e_pf *pf = vsi->back; | |
41c445ff JB |
3221 | struct i40e_hw *hw = &pf->hw; |
3222 | u16 vector; | |
3223 | int i, q; | |
41c445ff JB |
3224 | u32 qp; |
3225 | ||
3226 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn | |
3227 | * and PFINT_LNKLSTn registers, e.g.: | |
3228 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) | |
3229 | */ | |
3230 | qp = vsi->base_queue; | |
3231 | vector = vsi->base_vector; | |
493fb300 | 3232 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
ac26fc13 JB |
3233 | struct i40e_q_vector *q_vector = vsi->q_vectors[i]; |
3234 | ||
ee2319cf | 3235 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
a75e8005 | 3236 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting); |
41c445ff JB |
3237 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
3238 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), | |
3239 | q_vector->rx.itr); | |
a75e8005 | 3240 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting); |
41c445ff JB |
3241 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
3242 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), | |
3243 | q_vector->tx.itr); | |
ac26fc13 | 3244 | wr32(hw, I40E_PFINT_RATEN(vector - 1), |
1c0e6a36 | 3245 | i40e_intrl_usec_to_reg(vsi->int_rate_limit)); |
41c445ff JB |
3246 | |
3247 | /* Linked list for the queuepairs assigned to this vector */ | |
3248 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); | |
3249 | for (q = 0; q < q_vector->num_ringpairs; q++) { | |
ac26fc13 JB |
3250 | u32 val; |
3251 | ||
41c445ff JB |
3252 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
3253 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | | |
3254 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | | |
3255 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| | |
3256 | (I40E_QUEUE_TYPE_TX | |
3257 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); | |
3258 | ||
3259 | wr32(hw, I40E_QINT_RQCTL(qp), val); | |
3260 | ||
3261 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | | |
3262 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | | |
3263 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | | |
3264 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| | |
3265 | (I40E_QUEUE_TYPE_RX | |
3266 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); | |
3267 | ||
3268 | /* Terminate the linked list */ | |
3269 | if (q == (q_vector->num_ringpairs - 1)) | |
3270 | val |= (I40E_QUEUE_END_OF_LIST | |
3271 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); | |
3272 | ||
3273 | wr32(hw, I40E_QINT_TQCTL(qp), val); | |
3274 | qp++; | |
3275 | } | |
3276 | } | |
3277 | ||
3278 | i40e_flush(hw); | |
3279 | } | |
3280 | ||
3281 | /** | |
3282 | * i40e_enable_misc_int_causes - enable the non-queue interrupts | |
3283 | * @hw: ptr to the hardware info | |
3284 | **/ | |
ab437b5a | 3285 | static void i40e_enable_misc_int_causes(struct i40e_pf *pf) |
41c445ff | 3286 | { |
ab437b5a | 3287 | struct i40e_hw *hw = &pf->hw; |
41c445ff JB |
3288 | u32 val; |
3289 | ||
3290 | /* clear things first */ | |
3291 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ | |
3292 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ | |
3293 | ||
3294 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | | |
3295 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | | |
3296 | I40E_PFINT_ICR0_ENA_GRST_MASK | | |
3297 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | | |
3298 | I40E_PFINT_ICR0_ENA_GPIO_MASK | | |
41c445ff JB |
3299 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
3300 | I40E_PFINT_ICR0_ENA_VFLR_MASK | | |
3301 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; | |
3302 | ||
0d8e1439 ASJ |
3303 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) |
3304 | val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; | |
3305 | ||
ab437b5a JK |
3306 | if (pf->flags & I40E_FLAG_PTP) |
3307 | val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; | |
3308 | ||
41c445ff JB |
3309 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
3310 | ||
3311 | /* SW_ITR_IDX = 0, but don't change INTENA */ | |
84ed40e7 ASJ |
3312 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
3313 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); | |
41c445ff JB |
3314 | |
3315 | /* OTHER_ITR_IDX = 0 */ | |
3316 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); | |
3317 | } | |
3318 | ||
3319 | /** | |
3320 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW | |
3321 | * @vsi: the VSI being configured | |
3322 | **/ | |
3323 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) | |
3324 | { | |
493fb300 | 3325 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
41c445ff JB |
3326 | struct i40e_pf *pf = vsi->back; |
3327 | struct i40e_hw *hw = &pf->hw; | |
3328 | u32 val; | |
3329 | ||
3330 | /* set the ITR configuration */ | |
ee2319cf | 3331 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
a75e8005 | 3332 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting); |
41c445ff JB |
3333 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
3334 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); | |
a75e8005 | 3335 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting); |
41c445ff JB |
3336 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
3337 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); | |
3338 | ||
ab437b5a | 3339 | i40e_enable_misc_int_causes(pf); |
41c445ff JB |
3340 | |
3341 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ | |
3342 | wr32(hw, I40E_PFINT_LNKLST0, 0); | |
3343 | ||
f29eaa3d | 3344 | /* Associate the queue pair to the vector and enable the queue int */ |
41c445ff JB |
3345 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
3346 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | | |
3347 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); | |
3348 | ||
3349 | wr32(hw, I40E_QINT_RQCTL(0), val); | |
3350 | ||
3351 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | | |
3352 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | | |
3353 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); | |
3354 | ||
3355 | wr32(hw, I40E_QINT_TQCTL(0), val); | |
3356 | i40e_flush(hw); | |
3357 | } | |
3358 | ||
2ef28cfb MW |
3359 | /** |
3360 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 | |
3361 | * @pf: board private structure | |
3362 | **/ | |
3363 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) | |
3364 | { | |
3365 | struct i40e_hw *hw = &pf->hw; | |
3366 | ||
3367 | wr32(hw, I40E_PFINT_DYN_CTL0, | |
3368 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); | |
3369 | i40e_flush(hw); | |
3370 | } | |
3371 | ||
41c445ff JB |
3372 | /** |
3373 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 | |
3374 | * @pf: board private structure | |
40d72a50 | 3375 | * @clearpba: true when all pending interrupt events should be cleared |
41c445ff | 3376 | **/ |
40d72a50 | 3377 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba) |
41c445ff JB |
3378 | { |
3379 | struct i40e_hw *hw = &pf->hw; | |
3380 | u32 val; | |
3381 | ||
3382 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | | |
40d72a50 | 3383 | (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) | |
41c445ff JB |
3384 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
3385 | ||
3386 | wr32(hw, I40E_PFINT_DYN_CTL0, val); | |
3387 | i40e_flush(hw); | |
3388 | } | |
3389 | ||
41c445ff JB |
3390 | /** |
3391 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler | |
3392 | * @irq: interrupt number | |
3393 | * @data: pointer to a q_vector | |
3394 | **/ | |
3395 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) | |
3396 | { | |
3397 | struct i40e_q_vector *q_vector = data; | |
3398 | ||
cd0b6fa6 | 3399 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
41c445ff JB |
3400 | return IRQ_HANDLED; |
3401 | ||
5d3465a1 | 3402 | napi_schedule_irqoff(&q_vector->napi); |
41c445ff JB |
3403 | |
3404 | return IRQ_HANDLED; | |
3405 | } | |
3406 | ||
96db776a AB |
3407 | /** |
3408 | * i40e_irq_affinity_notify - Callback for affinity changes | |
3409 | * @notify: context as to what irq was changed | |
3410 | * @mask: the new affinity mask | |
3411 | * | |
3412 | * This is a callback function used by the irq_set_affinity_notifier function | |
3413 | * so that we may register to receive changes to the irq affinity masks. | |
3414 | **/ | |
3415 | static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify, | |
3416 | const cpumask_t *mask) | |
3417 | { | |
3418 | struct i40e_q_vector *q_vector = | |
3419 | container_of(notify, struct i40e_q_vector, affinity_notify); | |
3420 | ||
3421 | q_vector->affinity_mask = *mask; | |
3422 | } | |
3423 | ||
3424 | /** | |
3425 | * i40e_irq_affinity_release - Callback for affinity notifier release | |
3426 | * @ref: internal core kernel usage | |
3427 | * | |
3428 | * This is a callback function used by the irq_set_affinity_notifier function | |
3429 | * to inform the current notification subscriber that they will no longer | |
3430 | * receive notifications. | |
3431 | **/ | |
3432 | static void i40e_irq_affinity_release(struct kref *ref) {} | |
3433 | ||
41c445ff JB |
3434 | /** |
3435 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts | |
3436 | * @vsi: the VSI being configured | |
3437 | * @basename: name for the vector | |
3438 | * | |
3439 | * Allocates MSI-X vectors and requests interrupts from the kernel. | |
3440 | **/ | |
3441 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) | |
3442 | { | |
3443 | int q_vectors = vsi->num_q_vectors; | |
3444 | struct i40e_pf *pf = vsi->back; | |
3445 | int base = vsi->base_vector; | |
3446 | int rx_int_idx = 0; | |
3447 | int tx_int_idx = 0; | |
3448 | int vector, err; | |
96db776a | 3449 | int irq_num; |
41c445ff JB |
3450 | |
3451 | for (vector = 0; vector < q_vectors; vector++) { | |
493fb300 | 3452 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
41c445ff | 3453 | |
96db776a AB |
3454 | irq_num = pf->msix_entries[base + vector].vector; |
3455 | ||
cd0b6fa6 | 3456 | if (q_vector->tx.ring && q_vector->rx.ring) { |
41c445ff JB |
3457 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
3458 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); | |
3459 | tx_int_idx++; | |
cd0b6fa6 | 3460 | } else if (q_vector->rx.ring) { |
41c445ff JB |
3461 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
3462 | "%s-%s-%d", basename, "rx", rx_int_idx++); | |
cd0b6fa6 | 3463 | } else if (q_vector->tx.ring) { |
41c445ff JB |
3464 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
3465 | "%s-%s-%d", basename, "tx", tx_int_idx++); | |
3466 | } else { | |
3467 | /* skip this unused q_vector */ | |
3468 | continue; | |
3469 | } | |
96db776a | 3470 | err = request_irq(irq_num, |
41c445ff JB |
3471 | vsi->irq_handler, |
3472 | 0, | |
3473 | q_vector->name, | |
3474 | q_vector); | |
3475 | if (err) { | |
3476 | dev_info(&pf->pdev->dev, | |
fb43201f | 3477 | "MSIX request_irq failed, error: %d\n", err); |
41c445ff JB |
3478 | goto free_queue_irqs; |
3479 | } | |
96db776a AB |
3480 | |
3481 | /* register for affinity change notifications */ | |
3482 | q_vector->affinity_notify.notify = i40e_irq_affinity_notify; | |
3483 | q_vector->affinity_notify.release = i40e_irq_affinity_release; | |
3484 | irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify); | |
41c445ff | 3485 | /* assign the mask for this irq */ |
96db776a | 3486 | irq_set_affinity_hint(irq_num, &q_vector->affinity_mask); |
41c445ff JB |
3487 | } |
3488 | ||
63741846 | 3489 | vsi->irqs_ready = true; |
41c445ff JB |
3490 | return 0; |
3491 | ||
3492 | free_queue_irqs: | |
3493 | while (vector) { | |
3494 | vector--; | |
96db776a AB |
3495 | irq_num = pf->msix_entries[base + vector].vector; |
3496 | irq_set_affinity_notifier(irq_num, NULL); | |
3497 | irq_set_affinity_hint(irq_num, NULL); | |
3498 | free_irq(irq_num, &vsi->q_vectors[vector]); | |
41c445ff JB |
3499 | } |
3500 | return err; | |
3501 | } | |
3502 | ||
3503 | /** | |
3504 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI | |
3505 | * @vsi: the VSI being un-configured | |
3506 | **/ | |
3507 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) | |
3508 | { | |
3509 | struct i40e_pf *pf = vsi->back; | |
3510 | struct i40e_hw *hw = &pf->hw; | |
3511 | int base = vsi->base_vector; | |
3512 | int i; | |
3513 | ||
3514 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
9f65e15b AD |
3515 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
3516 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); | |
41c445ff JB |
3517 | } |
3518 | ||
3519 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | |
3520 | for (i = vsi->base_vector; | |
3521 | i < (vsi->num_q_vectors + vsi->base_vector); i++) | |
3522 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); | |
3523 | ||
3524 | i40e_flush(hw); | |
3525 | for (i = 0; i < vsi->num_q_vectors; i++) | |
3526 | synchronize_irq(pf->msix_entries[i + base].vector); | |
3527 | } else { | |
3528 | /* Legacy and MSI mode - this stops all interrupt handling */ | |
3529 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); | |
3530 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); | |
3531 | i40e_flush(hw); | |
3532 | synchronize_irq(pf->pdev->irq); | |
3533 | } | |
3534 | } | |
3535 | ||
3536 | /** | |
3537 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI | |
3538 | * @vsi: the VSI being configured | |
3539 | **/ | |
3540 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) | |
3541 | { | |
3542 | struct i40e_pf *pf = vsi->back; | |
3543 | int i; | |
3544 | ||
3545 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | |
7845548d | 3546 | for (i = 0; i < vsi->num_q_vectors; i++) |
41c445ff JB |
3547 | i40e_irq_dynamic_enable(vsi, i); |
3548 | } else { | |
40d72a50 | 3549 | i40e_irq_dynamic_enable_icr0(pf, true); |
41c445ff JB |
3550 | } |
3551 | ||
1022cb6c | 3552 | i40e_flush(&pf->hw); |
41c445ff JB |
3553 | return 0; |
3554 | } | |
3555 | ||
3556 | /** | |
3557 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events | |
3558 | * @pf: board private structure | |
3559 | **/ | |
3560 | static void i40e_stop_misc_vector(struct i40e_pf *pf) | |
3561 | { | |
3562 | /* Disable ICR 0 */ | |
3563 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); | |
3564 | i40e_flush(&pf->hw); | |
3565 | } | |
3566 | ||
3567 | /** | |
3568 | * i40e_intr - MSI/Legacy and non-queue interrupt handler | |
3569 | * @irq: interrupt number | |
3570 | * @data: pointer to a q_vector | |
3571 | * | |
3572 | * This is the handler used for all MSI/Legacy interrupts, and deals | |
3573 | * with both queue and non-queue interrupts. This is also used in | |
3574 | * MSIX mode to handle the non-queue interrupts. | |
3575 | **/ | |
3576 | static irqreturn_t i40e_intr(int irq, void *data) | |
3577 | { | |
3578 | struct i40e_pf *pf = (struct i40e_pf *)data; | |
3579 | struct i40e_hw *hw = &pf->hw; | |
5e823066 | 3580 | irqreturn_t ret = IRQ_NONE; |
41c445ff JB |
3581 | u32 icr0, icr0_remaining; |
3582 | u32 val, ena_mask; | |
3583 | ||
3584 | icr0 = rd32(hw, I40E_PFINT_ICR0); | |
5e823066 | 3585 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
41c445ff | 3586 | |
116a57d4 SN |
3587 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
3588 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) | |
5e823066 | 3589 | goto enable_intr; |
41c445ff | 3590 | |
cd92e72f SN |
3591 | /* if interrupt but no bits showing, must be SWINT */ |
3592 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || | |
3593 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) | |
3594 | pf->sw_int_count++; | |
3595 | ||
0d8e1439 ASJ |
3596 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && |
3597 | (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) { | |
3598 | ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; | |
3599 | icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK; | |
23bb6dc3 | 3600 | dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n"); |
0d8e1439 ASJ |
3601 | } |
3602 | ||
41c445ff JB |
3603 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
3604 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { | |
5d3465a1 AD |
3605 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
3606 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; | |
41c445ff | 3607 | |
a16ae2d5 ASJ |
3608 | /* We do not have a way to disarm Queue causes while leaving |
3609 | * interrupt enabled for all other causes, ideally | |
3610 | * interrupt should be disabled while we are in NAPI but | |
3611 | * this is not a performance path and napi_schedule() | |
3612 | * can deal with rescheduling. | |
3613 | */ | |
41c445ff | 3614 | if (!test_bit(__I40E_DOWN, &pf->state)) |
5d3465a1 | 3615 | napi_schedule_irqoff(&q_vector->napi); |
41c445ff JB |
3616 | } |
3617 | ||
3618 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { | |
3619 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; | |
3620 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); | |
6e93d0c9 | 3621 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n"); |
41c445ff JB |
3622 | } |
3623 | ||
3624 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { | |
3625 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; | |
3626 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); | |
3627 | } | |
3628 | ||
3629 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { | |
3630 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; | |
3631 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); | |
3632 | } | |
3633 | ||
3634 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { | |
3635 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) | |
3636 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); | |
3637 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; | |
3638 | val = rd32(hw, I40E_GLGEN_RSTAT); | |
3639 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) | |
3640 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; | |
4eb3f768 | 3641 | if (val == I40E_RESET_CORER) { |
41c445ff | 3642 | pf->corer_count++; |
4eb3f768 | 3643 | } else if (val == I40E_RESET_GLOBR) { |
41c445ff | 3644 | pf->globr_count++; |
4eb3f768 | 3645 | } else if (val == I40E_RESET_EMPR) { |
41c445ff | 3646 | pf->empr_count++; |
9df42d1a | 3647 | set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state); |
4eb3f768 | 3648 | } |
41c445ff JB |
3649 | } |
3650 | ||
9c010ee0 ASJ |
3651 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
3652 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; | |
3653 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); | |
25fc0e65 ASJ |
3654 | dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n", |
3655 | rd32(hw, I40E_PFHMC_ERRORINFO), | |
3656 | rd32(hw, I40E_PFHMC_ERRORDATA)); | |
9c010ee0 ASJ |
3657 | } |
3658 | ||
beb0dff1 JK |
3659 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
3660 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); | |
3661 | ||
3662 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { | |
cafa1fca | 3663 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
beb0dff1 | 3664 | i40e_ptp_tx_hwtstamp(pf); |
beb0dff1 | 3665 | } |
beb0dff1 JK |
3666 | } |
3667 | ||
41c445ff JB |
3668 | /* If a critical error is pending we have no choice but to reset the |
3669 | * device. | |
3670 | * Report and mask out any remaining unexpected interrupts. | |
3671 | */ | |
3672 | icr0_remaining = icr0 & ena_mask; | |
3673 | if (icr0_remaining) { | |
3674 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", | |
3675 | icr0_remaining); | |
9c010ee0 | 3676 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
41c445ff | 3677 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
c0c28975 | 3678 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
9c010ee0 ASJ |
3679 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
3680 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); | |
3681 | i40e_service_event_schedule(pf); | |
41c445ff JB |
3682 | } |
3683 | ena_mask &= ~icr0_remaining; | |
3684 | } | |
5e823066 | 3685 | ret = IRQ_HANDLED; |
41c445ff | 3686 | |
5e823066 | 3687 | enable_intr: |
41c445ff JB |
3688 | /* re-enable interrupt causes */ |
3689 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); | |
41c445ff JB |
3690 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
3691 | i40e_service_event_schedule(pf); | |
40d72a50 | 3692 | i40e_irq_dynamic_enable_icr0(pf, false); |
41c445ff JB |
3693 | } |
3694 | ||
5e823066 | 3695 | return ret; |
41c445ff JB |
3696 | } |
3697 | ||
cbf61325 ASJ |
3698 | /** |
3699 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes | |
3700 | * @tx_ring: tx ring to clean | |
3701 | * @budget: how many cleans we're allowed | |
3702 | * | |
3703 | * Returns true if there's any budget left (e.g. the clean is finished) | |
3704 | **/ | |
3705 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) | |
3706 | { | |
3707 | struct i40e_vsi *vsi = tx_ring->vsi; | |
3708 | u16 i = tx_ring->next_to_clean; | |
3709 | struct i40e_tx_buffer *tx_buf; | |
3710 | struct i40e_tx_desc *tx_desc; | |
3711 | ||
3712 | tx_buf = &tx_ring->tx_bi[i]; | |
3713 | tx_desc = I40E_TX_DESC(tx_ring, i); | |
3714 | i -= tx_ring->count; | |
3715 | ||
3716 | do { | |
3717 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; | |
3718 | ||
3719 | /* if next_to_watch is not set then there is no work pending */ | |
3720 | if (!eop_desc) | |
3721 | break; | |
3722 | ||
3723 | /* prevent any other reads prior to eop_desc */ | |
3724 | read_barrier_depends(); | |
3725 | ||
3726 | /* if the descriptor isn't done, no work yet to do */ | |
3727 | if (!(eop_desc->cmd_type_offset_bsz & | |
3728 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) | |
3729 | break; | |
3730 | ||
3731 | /* clear next_to_watch to prevent false hangs */ | |
3732 | tx_buf->next_to_watch = NULL; | |
3733 | ||
49d7d933 ASJ |
3734 | tx_desc->buffer_addr = 0; |
3735 | tx_desc->cmd_type_offset_bsz = 0; | |
3736 | /* move past filter desc */ | |
3737 | tx_buf++; | |
3738 | tx_desc++; | |
3739 | i++; | |
3740 | if (unlikely(!i)) { | |
3741 | i -= tx_ring->count; | |
3742 | tx_buf = tx_ring->tx_bi; | |
3743 | tx_desc = I40E_TX_DESC(tx_ring, 0); | |
3744 | } | |
cbf61325 ASJ |
3745 | /* unmap skb header data */ |
3746 | dma_unmap_single(tx_ring->dev, | |
3747 | dma_unmap_addr(tx_buf, dma), | |
3748 | dma_unmap_len(tx_buf, len), | |
3749 | DMA_TO_DEVICE); | |
49d7d933 ASJ |
3750 | if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB) |
3751 | kfree(tx_buf->raw_buf); | |
cbf61325 | 3752 | |
49d7d933 ASJ |
3753 | tx_buf->raw_buf = NULL; |
3754 | tx_buf->tx_flags = 0; | |
3755 | tx_buf->next_to_watch = NULL; | |
cbf61325 | 3756 | dma_unmap_len_set(tx_buf, len, 0); |
49d7d933 ASJ |
3757 | tx_desc->buffer_addr = 0; |
3758 | tx_desc->cmd_type_offset_bsz = 0; | |
cbf61325 | 3759 | |
49d7d933 | 3760 | /* move us past the eop_desc for start of next FD desc */ |
cbf61325 ASJ |
3761 | tx_buf++; |
3762 | tx_desc++; | |
3763 | i++; | |
3764 | if (unlikely(!i)) { | |
3765 | i -= tx_ring->count; | |
3766 | tx_buf = tx_ring->tx_bi; | |
3767 | tx_desc = I40E_TX_DESC(tx_ring, 0); | |
3768 | } | |
3769 | ||
3770 | /* update budget accounting */ | |
3771 | budget--; | |
3772 | } while (likely(budget)); | |
3773 | ||
3774 | i += tx_ring->count; | |
3775 | tx_ring->next_to_clean = i; | |
3776 | ||
6995b36c | 3777 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) |
7845548d | 3778 | i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx); |
6995b36c | 3779 | |
cbf61325 ASJ |
3780 | return budget > 0; |
3781 | } | |
3782 | ||
3783 | /** | |
3784 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring | |
3785 | * @irq: interrupt number | |
3786 | * @data: pointer to a q_vector | |
3787 | **/ | |
3788 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) | |
3789 | { | |
3790 | struct i40e_q_vector *q_vector = data; | |
3791 | struct i40e_vsi *vsi; | |
3792 | ||
3793 | if (!q_vector->tx.ring) | |
3794 | return IRQ_HANDLED; | |
3795 | ||
3796 | vsi = q_vector->tx.ring->vsi; | |
3797 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); | |
3798 | ||
3799 | return IRQ_HANDLED; | |
3800 | } | |
3801 | ||
41c445ff | 3802 | /** |
cd0b6fa6 | 3803 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
41c445ff JB |
3804 | * @vsi: the VSI being configured |
3805 | * @v_idx: vector index | |
cd0b6fa6 | 3806 | * @qp_idx: queue pair index |
41c445ff | 3807 | **/ |
26cdc443 | 3808 | static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx) |
41c445ff | 3809 | { |
493fb300 | 3810 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
9f65e15b AD |
3811 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
3812 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; | |
41c445ff JB |
3813 | |
3814 | tx_ring->q_vector = q_vector; | |
cd0b6fa6 AD |
3815 | tx_ring->next = q_vector->tx.ring; |
3816 | q_vector->tx.ring = tx_ring; | |
41c445ff | 3817 | q_vector->tx.count++; |
cd0b6fa6 AD |
3818 | |
3819 | rx_ring->q_vector = q_vector; | |
3820 | rx_ring->next = q_vector->rx.ring; | |
3821 | q_vector->rx.ring = rx_ring; | |
3822 | q_vector->rx.count++; | |
41c445ff JB |
3823 | } |
3824 | ||
3825 | /** | |
3826 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors | |
3827 | * @vsi: the VSI being configured | |
3828 | * | |
3829 | * This function maps descriptor rings to the queue-specific vectors | |
3830 | * we were allotted through the MSI-X enabling code. Ideally, we'd have | |
3831 | * one vector per queue pair, but on a constrained vector budget, we | |
3832 | * group the queue pairs as "efficiently" as possible. | |
3833 | **/ | |
3834 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) | |
3835 | { | |
3836 | int qp_remaining = vsi->num_queue_pairs; | |
3837 | int q_vectors = vsi->num_q_vectors; | |
cd0b6fa6 | 3838 | int num_ringpairs; |
41c445ff JB |
3839 | int v_start = 0; |
3840 | int qp_idx = 0; | |
3841 | ||
3842 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to | |
3843 | * group them so there are multiple queues per vector. | |
70114ec4 ASJ |
3844 | * It is also important to go through all the vectors available to be |
3845 | * sure that if we don't use all the vectors, that the remaining vectors | |
3846 | * are cleared. This is especially important when decreasing the | |
3847 | * number of queues in use. | |
41c445ff | 3848 | */ |
70114ec4 | 3849 | for (; v_start < q_vectors; v_start++) { |
cd0b6fa6 AD |
3850 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
3851 | ||
3852 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); | |
3853 | ||
3854 | q_vector->num_ringpairs = num_ringpairs; | |
3855 | ||
3856 | q_vector->rx.count = 0; | |
3857 | q_vector->tx.count = 0; | |
3858 | q_vector->rx.ring = NULL; | |
3859 | q_vector->tx.ring = NULL; | |
3860 | ||
3861 | while (num_ringpairs--) { | |
26cdc443 | 3862 | i40e_map_vector_to_qp(vsi, v_start, qp_idx); |
cd0b6fa6 AD |
3863 | qp_idx++; |
3864 | qp_remaining--; | |
41c445ff JB |
3865 | } |
3866 | } | |
3867 | } | |
3868 | ||
3869 | /** | |
3870 | * i40e_vsi_request_irq - Request IRQ from the OS | |
3871 | * @vsi: the VSI being configured | |
3872 | * @basename: name for the vector | |
3873 | **/ | |
3874 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) | |
3875 | { | |
3876 | struct i40e_pf *pf = vsi->back; | |
3877 | int err; | |
3878 | ||
3879 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) | |
3880 | err = i40e_vsi_request_irq_msix(vsi, basename); | |
3881 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) | |
3882 | err = request_irq(pf->pdev->irq, i40e_intr, 0, | |
b294ac70 | 3883 | pf->int_name, pf); |
41c445ff JB |
3884 | else |
3885 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, | |
b294ac70 | 3886 | pf->int_name, pf); |
41c445ff JB |
3887 | |
3888 | if (err) | |
3889 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); | |
3890 | ||
3891 | return err; | |
3892 | } | |
3893 | ||
3894 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
3895 | /** | |
d89d967f | 3896 | * i40e_netpoll - A Polling 'interrupt' handler |
41c445ff JB |
3897 | * @netdev: network interface device structure |
3898 | * | |
3899 | * This is used by netconsole to send skbs without having to re-enable | |
3900 | * interrupts. It's not called while the normal interrupt routine is executing. | |
3901 | **/ | |
3902 | static void i40e_netpoll(struct net_device *netdev) | |
3903 | { | |
3904 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
3905 | struct i40e_vsi *vsi = np->vsi; | |
3906 | struct i40e_pf *pf = vsi->back; | |
3907 | int i; | |
3908 | ||
3909 | /* if interface is down do nothing */ | |
3910 | if (test_bit(__I40E_DOWN, &vsi->state)) | |
3911 | return; | |
3912 | ||
41c445ff JB |
3913 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
3914 | for (i = 0; i < vsi->num_q_vectors; i++) | |
493fb300 | 3915 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
41c445ff JB |
3916 | } else { |
3917 | i40e_intr(pf->pdev->irq, netdev); | |
3918 | } | |
41c445ff JB |
3919 | } |
3920 | #endif | |
3921 | ||
c768e490 JK |
3922 | #define I40E_QTX_ENA_WAIT_COUNT 50 |
3923 | ||
23527308 NP |
3924 | /** |
3925 | * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled | |
3926 | * @pf: the PF being configured | |
3927 | * @pf_q: the PF queue | |
3928 | * @enable: enable or disable state of the queue | |
3929 | * | |
3930 | * This routine will wait for the given Tx queue of the PF to reach the | |
3931 | * enabled or disabled state. | |
3932 | * Returns -ETIMEDOUT in case of failing to reach the requested state after | |
3933 | * multiple retries; else will return 0 in case of success. | |
3934 | **/ | |
3935 | static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable) | |
3936 | { | |
3937 | int i; | |
3938 | u32 tx_reg; | |
3939 | ||
3940 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { | |
3941 | tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q)); | |
3942 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) | |
3943 | break; | |
3944 | ||
f98a2006 | 3945 | usleep_range(10, 20); |
23527308 NP |
3946 | } |
3947 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) | |
3948 | return -ETIMEDOUT; | |
3949 | ||
3950 | return 0; | |
3951 | } | |
3952 | ||
c768e490 JK |
3953 | /** |
3954 | * i40e_control_tx_q - Start or stop a particular Tx queue | |
3955 | * @pf: the PF structure | |
3956 | * @pf_q: the PF queue to configure | |
3957 | * @enable: start or stop the queue | |
3958 | * | |
3959 | * This function enables or disables a single queue. Note that any delay | |
3960 | * required after the operation is expected to be handled by the caller of | |
3961 | * this function. | |
3962 | **/ | |
3963 | static void i40e_control_tx_q(struct i40e_pf *pf, int pf_q, bool enable) | |
3964 | { | |
3965 | struct i40e_hw *hw = &pf->hw; | |
3966 | u32 tx_reg; | |
3967 | int i; | |
3968 | ||
3969 | /* warn the TX unit of coming changes */ | |
3970 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); | |
3971 | if (!enable) | |
3972 | usleep_range(10, 20); | |
3973 | ||
3974 | for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) { | |
3975 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); | |
3976 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == | |
3977 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) | |
3978 | break; | |
3979 | usleep_range(1000, 2000); | |
3980 | } | |
3981 | ||
3982 | /* Skip if the queue is already in the requested state */ | |
3983 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) | |
3984 | return; | |
3985 | ||
3986 | /* turn on/off the queue */ | |
3987 | if (enable) { | |
3988 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); | |
3989 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; | |
3990 | } else { | |
3991 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; | |
3992 | } | |
3993 | ||
3994 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); | |
3995 | } | |
3996 | ||
41c445ff JB |
3997 | /** |
3998 | * i40e_vsi_control_tx - Start or stop a VSI's rings | |
3999 | * @vsi: the VSI being configured | |
4000 | * @enable: start or stop the rings | |
4001 | **/ | |
4002 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) | |
4003 | { | |
4004 | struct i40e_pf *pf = vsi->back; | |
c768e490 | 4005 | int i, pf_q, ret = 0; |
41c445ff JB |
4006 | |
4007 | pf_q = vsi->base_queue; | |
4008 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { | |
c768e490 | 4009 | i40e_control_tx_q(pf, pf_q, enable); |
351499ab | 4010 | |
c768e490 | 4011 | /* Don't wait to disable when port Tx is suspended */ |
69129dc3 NP |
4012 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
4013 | continue; | |
41c445ff JB |
4014 | |
4015 | /* wait for the change to finish */ | |
23527308 NP |
4016 | ret = i40e_pf_txq_wait(pf, pf_q, enable); |
4017 | if (ret) { | |
4018 | dev_info(&pf->pdev->dev, | |
fb43201f SN |
4019 | "VSI seid %d Tx ring %d %sable timeout\n", |
4020 | vsi->seid, pf_q, (enable ? "en" : "dis")); | |
23527308 | 4021 | break; |
41c445ff JB |
4022 | } |
4023 | } | |
4024 | ||
23527308 NP |
4025 | return ret; |
4026 | } | |
4027 | ||
4028 | /** | |
4029 | * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled | |
4030 | * @pf: the PF being configured | |
4031 | * @pf_q: the PF queue | |
4032 | * @enable: enable or disable state of the queue | |
4033 | * | |
4034 | * This routine will wait for the given Rx queue of the PF to reach the | |
4035 | * enabled or disabled state. | |
4036 | * Returns -ETIMEDOUT in case of failing to reach the requested state after | |
4037 | * multiple retries; else will return 0 in case of success. | |
4038 | **/ | |
4039 | static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable) | |
4040 | { | |
4041 | int i; | |
4042 | u32 rx_reg; | |
4043 | ||
4044 | for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) { | |
4045 | rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q)); | |
4046 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) | |
4047 | break; | |
4048 | ||
f98a2006 | 4049 | usleep_range(10, 20); |
23527308 NP |
4050 | } |
4051 | if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT) | |
4052 | return -ETIMEDOUT; | |
7134f9ce | 4053 | |
41c445ff JB |
4054 | return 0; |
4055 | } | |
4056 | ||
c768e490 JK |
4057 | /** |
4058 | * i40e_control_rx_q - Start or stop a particular Rx queue | |
4059 | * @pf: the PF structure | |
4060 | * @pf_q: the PF queue to configure | |
4061 | * @enable: start or stop the queue | |
4062 | * | |
4063 | * This function enables or disables a single queue. Note that any delay | |
4064 | * required after the operation is expected to be handled by the caller of | |
4065 | * this function. | |
4066 | **/ | |
4067 | static void i40e_control_rx_q(struct i40e_pf *pf, int pf_q, bool enable) | |
4068 | { | |
4069 | struct i40e_hw *hw = &pf->hw; | |
4070 | u32 rx_reg; | |
4071 | int i; | |
4072 | ||
4073 | for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) { | |
4074 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); | |
4075 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == | |
4076 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) | |
4077 | break; | |
4078 | usleep_range(1000, 2000); | |
4079 | } | |
4080 | ||
4081 | /* Skip if the queue is already in the requested state */ | |
4082 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) | |
4083 | return; | |
4084 | ||
4085 | /* turn on/off the queue */ | |
4086 | if (enable) | |
4087 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; | |
4088 | else | |
4089 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; | |
4090 | ||
4091 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); | |
4092 | } | |
4093 | ||
41c445ff JB |
4094 | /** |
4095 | * i40e_vsi_control_rx - Start or stop a VSI's rings | |
4096 | * @vsi: the VSI being configured | |
4097 | * @enable: start or stop the rings | |
4098 | **/ | |
4099 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) | |
4100 | { | |
4101 | struct i40e_pf *pf = vsi->back; | |
c768e490 | 4102 | int i, pf_q, ret = 0; |
41c445ff JB |
4103 | |
4104 | pf_q = vsi->base_queue; | |
4105 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { | |
c768e490 | 4106 | i40e_control_rx_q(pf, pf_q, enable); |
41c445ff | 4107 | |
c768e490 | 4108 | /* Don't wait to disable when port Tx is suspended */ |
3fe06f41 NP |
4109 | if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state)) |
4110 | continue; | |
41c445ff JB |
4111 | |
4112 | /* wait for the change to finish */ | |
23527308 NP |
4113 | ret = i40e_pf_rxq_wait(pf, pf_q, enable); |
4114 | if (ret) { | |
4115 | dev_info(&pf->pdev->dev, | |
fb43201f SN |
4116 | "VSI seid %d Rx ring %d %sable timeout\n", |
4117 | vsi->seid, pf_q, (enable ? "en" : "dis")); | |
23527308 | 4118 | break; |
41c445ff JB |
4119 | } |
4120 | } | |
4121 | ||
d08a9f6c WC |
4122 | /* Due to HW errata, on Rx disable only, the register can indicate done |
4123 | * before it really is. Needs 50ms to be sure | |
4124 | */ | |
4125 | if (!enable) | |
4126 | mdelay(50); | |
4127 | ||
23527308 | 4128 | return ret; |
41c445ff JB |
4129 | } |
4130 | ||
4131 | /** | |
3aa7b74d | 4132 | * i40e_vsi_start_rings - Start a VSI's rings |
41c445ff | 4133 | * @vsi: the VSI being configured |
41c445ff | 4134 | **/ |
3aa7b74d | 4135 | int i40e_vsi_start_rings(struct i40e_vsi *vsi) |
41c445ff | 4136 | { |
3b867b28 | 4137 | int ret = 0; |
41c445ff JB |
4138 | |
4139 | /* do rx first for enable and last for disable */ | |
3aa7b74d FS |
4140 | ret = i40e_vsi_control_rx(vsi, true); |
4141 | if (ret) | |
4142 | return ret; | |
4143 | ret = i40e_vsi_control_tx(vsi, true); | |
41c445ff JB |
4144 | |
4145 | return ret; | |
4146 | } | |
4147 | ||
3aa7b74d FS |
4148 | /** |
4149 | * i40e_vsi_stop_rings - Stop a VSI's rings | |
4150 | * @vsi: the VSI being configured | |
4151 | **/ | |
4152 | void i40e_vsi_stop_rings(struct i40e_vsi *vsi) | |
4153 | { | |
4154 | /* do rx first for enable and last for disable | |
4155 | * Ignore return value, we need to shutdown whatever we can | |
4156 | */ | |
4157 | i40e_vsi_control_tx(vsi, false); | |
4158 | i40e_vsi_control_rx(vsi, false); | |
4159 | } | |
4160 | ||
41c445ff JB |
4161 | /** |
4162 | * i40e_vsi_free_irq - Free the irq association with the OS | |
4163 | * @vsi: the VSI being configured | |
4164 | **/ | |
4165 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) | |
4166 | { | |
4167 | struct i40e_pf *pf = vsi->back; | |
4168 | struct i40e_hw *hw = &pf->hw; | |
4169 | int base = vsi->base_vector; | |
4170 | u32 val, qp; | |
4171 | int i; | |
4172 | ||
4173 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | |
4174 | if (!vsi->q_vectors) | |
4175 | return; | |
4176 | ||
63741846 SN |
4177 | if (!vsi->irqs_ready) |
4178 | return; | |
4179 | ||
4180 | vsi->irqs_ready = false; | |
41c445ff | 4181 | for (i = 0; i < vsi->num_q_vectors; i++) { |
96db776a AB |
4182 | int irq_num; |
4183 | u16 vector; | |
4184 | ||
4185 | vector = i + base; | |
4186 | irq_num = pf->msix_entries[vector].vector; | |
41c445ff JB |
4187 | |
4188 | /* free only the irqs that were actually requested */ | |
78681b1f SN |
4189 | if (!vsi->q_vectors[i] || |
4190 | !vsi->q_vectors[i]->num_ringpairs) | |
41c445ff JB |
4191 | continue; |
4192 | ||
96db776a AB |
4193 | /* clear the affinity notifier in the IRQ descriptor */ |
4194 | irq_set_affinity_notifier(irq_num, NULL); | |
41c445ff | 4195 | /* clear the affinity_mask in the IRQ descriptor */ |
96db776a AB |
4196 | irq_set_affinity_hint(irq_num, NULL); |
4197 | synchronize_irq(irq_num); | |
4198 | free_irq(irq_num, vsi->q_vectors[i]); | |
41c445ff JB |
4199 | |
4200 | /* Tear down the interrupt queue link list | |
4201 | * | |
4202 | * We know that they come in pairs and always | |
4203 | * the Rx first, then the Tx. To clear the | |
4204 | * link list, stick the EOL value into the | |
4205 | * next_q field of the registers. | |
4206 | */ | |
4207 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); | |
4208 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) | |
4209 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; | |
4210 | val |= I40E_QUEUE_END_OF_LIST | |
4211 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; | |
4212 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); | |
4213 | ||
4214 | while (qp != I40E_QUEUE_END_OF_LIST) { | |
4215 | u32 next; | |
4216 | ||
4217 | val = rd32(hw, I40E_QINT_RQCTL(qp)); | |
4218 | ||
4219 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | | |
4220 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | | |
4221 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | | |
4222 | I40E_QINT_RQCTL_INTEVENT_MASK); | |
4223 | ||
4224 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | | |
4225 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); | |
4226 | ||
4227 | wr32(hw, I40E_QINT_RQCTL(qp), val); | |
4228 | ||
4229 | val = rd32(hw, I40E_QINT_TQCTL(qp)); | |
4230 | ||
4231 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) | |
4232 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; | |
4233 | ||
4234 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | | |
4235 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | | |
4236 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | | |
4237 | I40E_QINT_TQCTL_INTEVENT_MASK); | |
4238 | ||
4239 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | | |
4240 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); | |
4241 | ||
4242 | wr32(hw, I40E_QINT_TQCTL(qp), val); | |
4243 | qp = next; | |
4244 | } | |
4245 | } | |
4246 | } else { | |
4247 | free_irq(pf->pdev->irq, pf); | |
4248 | ||
4249 | val = rd32(hw, I40E_PFINT_LNKLST0); | |
4250 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) | |
4251 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; | |
4252 | val |= I40E_QUEUE_END_OF_LIST | |
4253 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; | |
4254 | wr32(hw, I40E_PFINT_LNKLST0, val); | |
4255 | ||
4256 | val = rd32(hw, I40E_QINT_RQCTL(qp)); | |
4257 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | | |
4258 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | | |
4259 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | | |
4260 | I40E_QINT_RQCTL_INTEVENT_MASK); | |
4261 | ||
4262 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | | |
4263 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); | |
4264 | ||
4265 | wr32(hw, I40E_QINT_RQCTL(qp), val); | |
4266 | ||
4267 | val = rd32(hw, I40E_QINT_TQCTL(qp)); | |
4268 | ||
4269 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | | |
4270 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | | |
4271 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | | |
4272 | I40E_QINT_TQCTL_INTEVENT_MASK); | |
4273 | ||
4274 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | | |
4275 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); | |
4276 | ||
4277 | wr32(hw, I40E_QINT_TQCTL(qp), val); | |
4278 | } | |
4279 | } | |
4280 | ||
493fb300 AD |
4281 | /** |
4282 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector | |
4283 | * @vsi: the VSI being configured | |
4284 | * @v_idx: Index of vector to be freed | |
4285 | * | |
4286 | * This function frees the memory allocated to the q_vector. In addition if | |
4287 | * NAPI is enabled it will delete any references to the NAPI struct prior | |
4288 | * to freeing the q_vector. | |
4289 | **/ | |
4290 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) | |
4291 | { | |
4292 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; | |
cd0b6fa6 | 4293 | struct i40e_ring *ring; |
493fb300 AD |
4294 | |
4295 | if (!q_vector) | |
4296 | return; | |
4297 | ||
4298 | /* disassociate q_vector from rings */ | |
cd0b6fa6 AD |
4299 | i40e_for_each_ring(ring, q_vector->tx) |
4300 | ring->q_vector = NULL; | |
4301 | ||
4302 | i40e_for_each_ring(ring, q_vector->rx) | |
4303 | ring->q_vector = NULL; | |
493fb300 AD |
4304 | |
4305 | /* only VSI w/ an associated netdev is set up w/ NAPI */ | |
4306 | if (vsi->netdev) | |
4307 | netif_napi_del(&q_vector->napi); | |
4308 | ||
4309 | vsi->q_vectors[v_idx] = NULL; | |
4310 | ||
4311 | kfree_rcu(q_vector, rcu); | |
4312 | } | |
4313 | ||
41c445ff JB |
4314 | /** |
4315 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors | |
4316 | * @vsi: the VSI being un-configured | |
4317 | * | |
4318 | * This frees the memory allocated to the q_vectors and | |
4319 | * deletes references to the NAPI struct. | |
4320 | **/ | |
4321 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) | |
4322 | { | |
4323 | int v_idx; | |
4324 | ||
493fb300 AD |
4325 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
4326 | i40e_free_q_vector(vsi, v_idx); | |
41c445ff JB |
4327 | } |
4328 | ||
4329 | /** | |
4330 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS | |
4331 | * @pf: board private structure | |
4332 | **/ | |
4333 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) | |
4334 | { | |
4335 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ | |
4336 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | |
4337 | pci_disable_msix(pf->pdev); | |
4338 | kfree(pf->msix_entries); | |
4339 | pf->msix_entries = NULL; | |
3b444399 SN |
4340 | kfree(pf->irq_pile); |
4341 | pf->irq_pile = NULL; | |
41c445ff JB |
4342 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
4343 | pci_disable_msi(pf->pdev); | |
4344 | } | |
4345 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); | |
4346 | } | |
4347 | ||
4348 | /** | |
4349 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings | |
4350 | * @pf: board private structure | |
4351 | * | |
4352 | * We go through and clear interrupt specific resources and reset the structure | |
4353 | * to pre-load conditions | |
4354 | **/ | |
4355 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) | |
4356 | { | |
4357 | int i; | |
4358 | ||
e147758d | 4359 | i40e_stop_misc_vector(pf); |
69278398 | 4360 | if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) { |
e147758d SN |
4361 | synchronize_irq(pf->msix_entries[0].vector); |
4362 | free_irq(pf->msix_entries[0].vector, pf); | |
4363 | } | |
4364 | ||
e3219ce6 ASJ |
4365 | i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector, |
4366 | I40E_IWARP_IRQ_PILE_ID); | |
4367 | ||
41c445ff | 4368 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
505682cd | 4369 | for (i = 0; i < pf->num_alloc_vsi; i++) |
41c445ff JB |
4370 | if (pf->vsi[i]) |
4371 | i40e_vsi_free_q_vectors(pf->vsi[i]); | |
4372 | i40e_reset_interrupt_capability(pf); | |
4373 | } | |
4374 | ||
4375 | /** | |
4376 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI | |
4377 | * @vsi: the VSI being configured | |
4378 | **/ | |
4379 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) | |
4380 | { | |
4381 | int q_idx; | |
4382 | ||
4383 | if (!vsi->netdev) | |
4384 | return; | |
4385 | ||
13a8cd19 AD |
4386 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) { |
4387 | struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx]; | |
4388 | ||
4389 | if (q_vector->rx.ring || q_vector->tx.ring) | |
4390 | napi_enable(&q_vector->napi); | |
4391 | } | |
41c445ff JB |
4392 | } |
4393 | ||
4394 | /** | |
4395 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI | |
4396 | * @vsi: the VSI being configured | |
4397 | **/ | |
4398 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) | |
4399 | { | |
4400 | int q_idx; | |
4401 | ||
4402 | if (!vsi->netdev) | |
4403 | return; | |
4404 | ||
13a8cd19 AD |
4405 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) { |
4406 | struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx]; | |
4407 | ||
4408 | if (q_vector->rx.ring || q_vector->tx.ring) | |
4409 | napi_disable(&q_vector->napi); | |
4410 | } | |
41c445ff JB |
4411 | } |
4412 | ||
90ef8d47 SN |
4413 | /** |
4414 | * i40e_vsi_close - Shut down a VSI | |
4415 | * @vsi: the vsi to be quelled | |
4416 | **/ | |
4417 | static void i40e_vsi_close(struct i40e_vsi *vsi) | |
4418 | { | |
0ef2d5af | 4419 | struct i40e_pf *pf = vsi->back; |
90ef8d47 SN |
4420 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
4421 | i40e_down(vsi); | |
4422 | i40e_vsi_free_irq(vsi); | |
4423 | i40e_vsi_free_tx_resources(vsi); | |
4424 | i40e_vsi_free_rx_resources(vsi); | |
92faef85 | 4425 | vsi->current_netdev_flags = 0; |
0ef2d5af MW |
4426 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; |
4427 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) | |
4428 | pf->flags |= I40E_FLAG_CLIENT_RESET; | |
90ef8d47 SN |
4429 | } |
4430 | ||
41c445ff JB |
4431 | /** |
4432 | * i40e_quiesce_vsi - Pause a given VSI | |
4433 | * @vsi: the VSI being paused | |
4434 | **/ | |
4435 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) | |
4436 | { | |
4437 | if (test_bit(__I40E_DOWN, &vsi->state)) | |
4438 | return; | |
4439 | ||
4440 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); | |
6995b36c | 4441 | if (vsi->netdev && netif_running(vsi->netdev)) |
41c445ff | 4442 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
6995b36c | 4443 | else |
90ef8d47 | 4444 | i40e_vsi_close(vsi); |
41c445ff JB |
4445 | } |
4446 | ||
4447 | /** | |
4448 | * i40e_unquiesce_vsi - Resume a given VSI | |
4449 | * @vsi: the VSI being resumed | |
4450 | **/ | |
4451 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) | |
4452 | { | |
4453 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) | |
4454 | return; | |
4455 | ||
4456 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); | |
4457 | if (vsi->netdev && netif_running(vsi->netdev)) | |
4458 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); | |
4459 | else | |
8276f757 | 4460 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
41c445ff JB |
4461 | } |
4462 | ||
4463 | /** | |
4464 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF | |
4465 | * @pf: the PF | |
4466 | **/ | |
4467 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) | |
4468 | { | |
4469 | int v; | |
4470 | ||
505682cd | 4471 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
41c445ff JB |
4472 | if (pf->vsi[v]) |
4473 | i40e_quiesce_vsi(pf->vsi[v]); | |
4474 | } | |
4475 | } | |
4476 | ||
4477 | /** | |
4478 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF | |
4479 | * @pf: the PF | |
4480 | **/ | |
4481 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) | |
4482 | { | |
4483 | int v; | |
4484 | ||
505682cd | 4485 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
41c445ff JB |
4486 | if (pf->vsi[v]) |
4487 | i40e_unquiesce_vsi(pf->vsi[v]); | |
4488 | } | |
4489 | } | |
4490 | ||
69129dc3 NP |
4491 | #ifdef CONFIG_I40E_DCB |
4492 | /** | |
3fe06f41 | 4493 | * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled |
69129dc3 NP |
4494 | * @vsi: the VSI being configured |
4495 | * | |
af26ce2d | 4496 | * Wait until all queues on a given VSI have been disabled. |
69129dc3 | 4497 | **/ |
3fe06f41 | 4498 | static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi) |
69129dc3 NP |
4499 | { |
4500 | struct i40e_pf *pf = vsi->back; | |
4501 | int i, pf_q, ret; | |
4502 | ||
4503 | pf_q = vsi->base_queue; | |
4504 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { | |
af26ce2d | 4505 | /* Check and wait for the Tx queue */ |
69129dc3 NP |
4506 | ret = i40e_pf_txq_wait(pf, pf_q, false); |
4507 | if (ret) { | |
4508 | dev_info(&pf->pdev->dev, | |
fb43201f SN |
4509 | "VSI seid %d Tx ring %d disable timeout\n", |
4510 | vsi->seid, pf_q); | |
69129dc3 NP |
4511 | return ret; |
4512 | } | |
af26ce2d | 4513 | /* Check and wait for the Tx queue */ |
3fe06f41 NP |
4514 | ret = i40e_pf_rxq_wait(pf, pf_q, false); |
4515 | if (ret) { | |
4516 | dev_info(&pf->pdev->dev, | |
4517 | "VSI seid %d Rx ring %d disable timeout\n", | |
4518 | vsi->seid, pf_q); | |
4519 | return ret; | |
4520 | } | |
4521 | } | |
4522 | ||
69129dc3 NP |
4523 | return 0; |
4524 | } | |
4525 | ||
4526 | /** | |
3fe06f41 | 4527 | * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled |
69129dc3 NP |
4528 | * @pf: the PF |
4529 | * | |
3fe06f41 | 4530 | * This function waits for the queues to be in disabled state for all the |
69129dc3 NP |
4531 | * VSIs that are managed by this PF. |
4532 | **/ | |
3fe06f41 | 4533 | static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf) |
69129dc3 NP |
4534 | { |
4535 | int v, ret = 0; | |
4536 | ||
4537 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | |
c76cb6ed | 4538 | if (pf->vsi[v]) { |
3fe06f41 | 4539 | ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]); |
69129dc3 NP |
4540 | if (ret) |
4541 | break; | |
4542 | } | |
4543 | } | |
4544 | ||
4545 | return ret; | |
4546 | } | |
4547 | ||
4548 | #endif | |
b03a8c1f KP |
4549 | |
4550 | /** | |
4551 | * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue | |
4552 | * @q_idx: TX queue number | |
4553 | * @vsi: Pointer to VSI struct | |
4554 | * | |
4555 | * This function checks specified queue for given VSI. Detects hung condition. | |
17daabb5 AB |
4556 | * We proactively detect hung TX queues by checking if interrupts are disabled |
4557 | * but there are pending descriptors. If it appears hung, attempt to recover | |
4558 | * by triggering a SW interrupt. | |
b03a8c1f KP |
4559 | **/ |
4560 | static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi) | |
4561 | { | |
4562 | struct i40e_ring *tx_ring = NULL; | |
4563 | struct i40e_pf *pf; | |
17daabb5 | 4564 | u32 val, tx_pending; |
b03a8c1f KP |
4565 | int i; |
4566 | ||
4567 | pf = vsi->back; | |
4568 | ||
4569 | /* now that we have an index, find the tx_ring struct */ | |
4570 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
4571 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) { | |
4572 | if (q_idx == vsi->tx_rings[i]->queue_index) { | |
4573 | tx_ring = vsi->tx_rings[i]; | |
4574 | break; | |
4575 | } | |
4576 | } | |
4577 | } | |
4578 | ||
4579 | if (!tx_ring) | |
4580 | return; | |
4581 | ||
4582 | /* Read interrupt register */ | |
4583 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) | |
4584 | val = rd32(&pf->hw, | |
4585 | I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx + | |
4586 | tx_ring->vsi->base_vector - 1)); | |
4587 | else | |
4588 | val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0); | |
4589 | ||
17daabb5 | 4590 | tx_pending = i40e_get_tx_pending(tx_ring); |
b03a8c1f | 4591 | |
17daabb5 AB |
4592 | /* Interrupts are disabled and TX pending is non-zero, |
4593 | * trigger the SW interrupt (don't wait). Worst case | |
4594 | * there will be one extra interrupt which may result | |
4595 | * into not cleaning any queues because queues are cleaned. | |
b03a8c1f | 4596 | */ |
17daabb5 AB |
4597 | if (tx_pending && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) |
4598 | i40e_force_wb(vsi, tx_ring->q_vector); | |
b03a8c1f KP |
4599 | } |
4600 | ||
4601 | /** | |
4602 | * i40e_detect_recover_hung - Function to detect and recover hung_queues | |
4603 | * @pf: pointer to PF struct | |
4604 | * | |
4605 | * LAN VSI has netdev and netdev has TX queues. This function is to check | |
4606 | * each of those TX queues if they are hung, trigger recovery by issuing | |
4607 | * SW interrupt. | |
4608 | **/ | |
4609 | static void i40e_detect_recover_hung(struct i40e_pf *pf) | |
4610 | { | |
4611 | struct net_device *netdev; | |
4612 | struct i40e_vsi *vsi; | |
4613 | int i; | |
4614 | ||
4615 | /* Only for LAN VSI */ | |
4616 | vsi = pf->vsi[pf->lan_vsi]; | |
4617 | ||
4618 | if (!vsi) | |
4619 | return; | |
4620 | ||
4621 | /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */ | |
4622 | if (test_bit(__I40E_DOWN, &vsi->back->state) || | |
4623 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) | |
4624 | return; | |
4625 | ||
4626 | /* Make sure type is MAIN VSI */ | |
4627 | if (vsi->type != I40E_VSI_MAIN) | |
4628 | return; | |
4629 | ||
4630 | netdev = vsi->netdev; | |
4631 | if (!netdev) | |
4632 | return; | |
4633 | ||
4634 | /* Bail out if netif_carrier is not OK */ | |
4635 | if (!netif_carrier_ok(netdev)) | |
4636 | return; | |
4637 | ||
4638 | /* Go thru' TX queues for netdev */ | |
4639 | for (i = 0; i < netdev->num_tx_queues; i++) { | |
4640 | struct netdev_queue *q; | |
4641 | ||
4642 | q = netdev_get_tx_queue(netdev, i); | |
4643 | if (q) | |
4644 | i40e_detect_recover_hung_queue(i, vsi); | |
4645 | } | |
4646 | } | |
4647 | ||
63d7e5a4 NP |
4648 | /** |
4649 | * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP | |
b40c82e6 | 4650 | * @pf: pointer to PF |
63d7e5a4 NP |
4651 | * |
4652 | * Get TC map for ISCSI PF type that will include iSCSI TC | |
4653 | * and LAN TC. | |
4654 | **/ | |
4655 | static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf) | |
4656 | { | |
4657 | struct i40e_dcb_app_priority_table app; | |
4658 | struct i40e_hw *hw = &pf->hw; | |
4659 | u8 enabled_tc = 1; /* TC0 is always enabled */ | |
4660 | u8 tc, i; | |
4661 | /* Get the iSCSI APP TLV */ | |
4662 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; | |
4663 | ||
4664 | for (i = 0; i < dcbcfg->numapps; i++) { | |
4665 | app = dcbcfg->app[i]; | |
4666 | if (app.selector == I40E_APP_SEL_TCPIP && | |
4667 | app.protocolid == I40E_APP_PROTOID_ISCSI) { | |
4668 | tc = dcbcfg->etscfg.prioritytable[app.priority]; | |
75f5cea9 | 4669 | enabled_tc |= BIT(tc); |
63d7e5a4 NP |
4670 | break; |
4671 | } | |
4672 | } | |
4673 | ||
4674 | return enabled_tc; | |
4675 | } | |
4676 | ||
41c445ff JB |
4677 | /** |
4678 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config | |
4679 | * @dcbcfg: the corresponding DCBx configuration structure | |
4680 | * | |
4681 | * Return the number of TCs from given DCBx configuration | |
4682 | **/ | |
4683 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) | |
4684 | { | |
fbfe12c6 | 4685 | int i, tc_unused = 0; |
078b5876 | 4686 | u8 num_tc = 0; |
fbfe12c6 | 4687 | u8 ret = 0; |
41c445ff JB |
4688 | |
4689 | /* Scan the ETS Config Priority Table to find | |
4690 | * traffic class enabled for a given priority | |
fbfe12c6 | 4691 | * and create a bitmask of enabled TCs |
41c445ff | 4692 | */ |
fbfe12c6 DE |
4693 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) |
4694 | num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]); | |
41c445ff | 4695 | |
fbfe12c6 DE |
4696 | /* Now scan the bitmask to check for |
4697 | * contiguous TCs starting with TC0 | |
41c445ff | 4698 | */ |
fbfe12c6 DE |
4699 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
4700 | if (num_tc & BIT(i)) { | |
4701 | if (!tc_unused) { | |
4702 | ret++; | |
4703 | } else { | |
4704 | pr_err("Non-contiguous TC - Disabling DCB\n"); | |
4705 | return 1; | |
4706 | } | |
4707 | } else { | |
4708 | tc_unused = 1; | |
4709 | } | |
4710 | } | |
4711 | ||
4712 | /* There is always at least TC0 */ | |
4713 | if (!ret) | |
4714 | ret = 1; | |
4715 | ||
4716 | return ret; | |
41c445ff JB |
4717 | } |
4718 | ||
4719 | /** | |
4720 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes | |
4721 | * @dcbcfg: the corresponding DCBx configuration structure | |
4722 | * | |
4723 | * Query the current DCB configuration and return the number of | |
4724 | * traffic classes enabled from the given DCBX config | |
4725 | **/ | |
4726 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) | |
4727 | { | |
4728 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); | |
4729 | u8 enabled_tc = 1; | |
4730 | u8 i; | |
4731 | ||
4732 | for (i = 0; i < num_tc; i++) | |
41a1d04b | 4733 | enabled_tc |= BIT(i); |
41c445ff JB |
4734 | |
4735 | return enabled_tc; | |
4736 | } | |
4737 | ||
4738 | /** | |
4739 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF | |
4740 | * @pf: PF being queried | |
4741 | * | |
4742 | * Return number of traffic classes enabled for the given PF | |
4743 | **/ | |
4744 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) | |
4745 | { | |
4746 | struct i40e_hw *hw = &pf->hw; | |
52a08caa | 4747 | u8 i, enabled_tc = 1; |
41c445ff JB |
4748 | u8 num_tc = 0; |
4749 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; | |
4750 | ||
4751 | /* If DCB is not enabled then always in single TC */ | |
4752 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) | |
4753 | return 1; | |
4754 | ||
63d7e5a4 NP |
4755 | /* SFP mode will be enabled for all TCs on port */ |
4756 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) | |
4757 | return i40e_dcb_get_num_tc(dcbcfg); | |
4758 | ||
41c445ff | 4759 | /* MFP mode return count of enabled TCs for this PF */ |
63d7e5a4 NP |
4760 | if (pf->hw.func_caps.iscsi) |
4761 | enabled_tc = i40e_get_iscsi_tc_map(pf); | |
4762 | else | |
fc51de96 | 4763 | return 1; /* Only TC0 */ |
41c445ff | 4764 | |
63d7e5a4 | 4765 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
75f5cea9 | 4766 | if (enabled_tc & BIT(i)) |
63d7e5a4 NP |
4767 | num_tc++; |
4768 | } | |
4769 | return num_tc; | |
41c445ff JB |
4770 | } |
4771 | ||
41c445ff JB |
4772 | /** |
4773 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes | |
4774 | * @pf: PF being queried | |
4775 | * | |
4776 | * Return a bitmap for enabled traffic classes for this PF. | |
4777 | **/ | |
4778 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) | |
4779 | { | |
4780 | /* If DCB is not enabled for this PF then just return default TC */ | |
4781 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) | |
ea6acb7e | 4782 | return I40E_DEFAULT_TRAFFIC_CLASS; |
41c445ff | 4783 | |
41c445ff | 4784 | /* SFP mode we want PF to be enabled for all TCs */ |
63d7e5a4 NP |
4785 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
4786 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); | |
4787 | ||
fc51de96 | 4788 | /* MFP enabled and iSCSI PF type */ |
63d7e5a4 NP |
4789 | if (pf->hw.func_caps.iscsi) |
4790 | return i40e_get_iscsi_tc_map(pf); | |
4791 | else | |
ea6acb7e | 4792 | return I40E_DEFAULT_TRAFFIC_CLASS; |
41c445ff JB |
4793 | } |
4794 | ||
4795 | /** | |
4796 | * i40e_vsi_get_bw_info - Query VSI BW Information | |
4797 | * @vsi: the VSI being queried | |
4798 | * | |
4799 | * Returns 0 on success, negative value on failure | |
4800 | **/ | |
4801 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) | |
4802 | { | |
4803 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; | |
4804 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; | |
4805 | struct i40e_pf *pf = vsi->back; | |
4806 | struct i40e_hw *hw = &pf->hw; | |
f1c7e72e | 4807 | i40e_status ret; |
41c445ff | 4808 | u32 tc_bw_max; |
41c445ff JB |
4809 | int i; |
4810 | ||
4811 | /* Get the VSI level BW configuration */ | |
f1c7e72e SN |
4812 | ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
4813 | if (ret) { | |
41c445ff | 4814 | dev_info(&pf->pdev->dev, |
f1c7e72e SN |
4815 | "couldn't get PF vsi bw config, err %s aq_err %s\n", |
4816 | i40e_stat_str(&pf->hw, ret), | |
4817 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
dcae29be | 4818 | return -EINVAL; |
41c445ff JB |
4819 | } |
4820 | ||
4821 | /* Get the VSI level BW configuration per TC */ | |
f1c7e72e SN |
4822 | ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
4823 | NULL); | |
4824 | if (ret) { | |
41c445ff | 4825 | dev_info(&pf->pdev->dev, |
f1c7e72e SN |
4826 | "couldn't get PF vsi ets bw config, err %s aq_err %s\n", |
4827 | i40e_stat_str(&pf->hw, ret), | |
4828 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
dcae29be | 4829 | return -EINVAL; |
41c445ff JB |
4830 | } |
4831 | ||
4832 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { | |
4833 | dev_info(&pf->pdev->dev, | |
4834 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", | |
4835 | bw_config.tc_valid_bits, | |
4836 | bw_ets_config.tc_valid_bits); | |
4837 | /* Still continuing */ | |
4838 | } | |
4839 | ||
4840 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); | |
4841 | vsi->bw_max_quanta = bw_config.max_bw; | |
4842 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | | |
4843 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); | |
4844 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
4845 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; | |
4846 | vsi->bw_ets_limit_credits[i] = | |
4847 | le16_to_cpu(bw_ets_config.credits[i]); | |
4848 | /* 3 bits out of 4 for each TC */ | |
4849 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); | |
4850 | } | |
078b5876 | 4851 | |
dcae29be | 4852 | return 0; |
41c445ff JB |
4853 | } |
4854 | ||
4855 | /** | |
4856 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC | |
4857 | * @vsi: the VSI being configured | |
4858 | * @enabled_tc: TC bitmap | |
4859 | * @bw_credits: BW shared credits per TC | |
4860 | * | |
4861 | * Returns 0 on success, negative value on failure | |
4862 | **/ | |
dcae29be | 4863 | static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc, |
41c445ff JB |
4864 | u8 *bw_share) |
4865 | { | |
4866 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; | |
f1c7e72e | 4867 | i40e_status ret; |
dcae29be | 4868 | int i; |
41c445ff JB |
4869 | |
4870 | bw_data.tc_valid_bits = enabled_tc; | |
4871 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) | |
4872 | bw_data.tc_bw_credits[i] = bw_share[i]; | |
4873 | ||
f1c7e72e SN |
4874 | ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
4875 | NULL); | |
4876 | if (ret) { | |
41c445ff | 4877 | dev_info(&vsi->back->pdev->dev, |
69bfb110 JB |
4878 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
4879 | vsi->back->hw.aq.asq_last_status); | |
dcae29be | 4880 | return -EINVAL; |
41c445ff JB |
4881 | } |
4882 | ||
4883 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) | |
4884 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; | |
4885 | ||
dcae29be | 4886 | return 0; |
41c445ff JB |
4887 | } |
4888 | ||
4889 | /** | |
4890 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration | |
4891 | * @vsi: the VSI being configured | |
4892 | * @enabled_tc: TC map to be enabled | |
4893 | * | |
4894 | **/ | |
4895 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) | |
4896 | { | |
4897 | struct net_device *netdev = vsi->netdev; | |
4898 | struct i40e_pf *pf = vsi->back; | |
4899 | struct i40e_hw *hw = &pf->hw; | |
4900 | u8 netdev_tc = 0; | |
4901 | int i; | |
4902 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; | |
4903 | ||
4904 | if (!netdev) | |
4905 | return; | |
4906 | ||
4907 | if (!enabled_tc) { | |
4908 | netdev_reset_tc(netdev); | |
4909 | return; | |
4910 | } | |
4911 | ||
4912 | /* Set up actual enabled TCs on the VSI */ | |
4913 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) | |
4914 | return; | |
4915 | ||
4916 | /* set per TC queues for the VSI */ | |
4917 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
4918 | /* Only set TC queues for enabled tcs | |
4919 | * | |
4920 | * e.g. For a VSI that has TC0 and TC3 enabled the | |
4921 | * enabled_tc bitmap would be 0x00001001; the driver | |
4922 | * will set the numtc for netdev as 2 that will be | |
4923 | * referenced by the netdev layer as TC 0 and 1. | |
4924 | */ | |
75f5cea9 | 4925 | if (vsi->tc_config.enabled_tc & BIT(i)) |
41c445ff JB |
4926 | netdev_set_tc_queue(netdev, |
4927 | vsi->tc_config.tc_info[i].netdev_tc, | |
4928 | vsi->tc_config.tc_info[i].qcount, | |
4929 | vsi->tc_config.tc_info[i].qoffset); | |
4930 | } | |
4931 | ||
4932 | /* Assign UP2TC map for the VSI */ | |
4933 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { | |
4934 | /* Get the actual TC# for the UP */ | |
4935 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; | |
4936 | /* Get the mapped netdev TC# for the UP */ | |
4937 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; | |
4938 | netdev_set_prio_tc_map(netdev, i, netdev_tc); | |
4939 | } | |
4940 | } | |
4941 | ||
4942 | /** | |
4943 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map | |
4944 | * @vsi: the VSI being configured | |
4945 | * @ctxt: the ctxt buffer returned from AQ VSI update param command | |
4946 | **/ | |
4947 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, | |
4948 | struct i40e_vsi_context *ctxt) | |
4949 | { | |
4950 | /* copy just the sections touched not the entire info | |
4951 | * since not all sections are valid as returned by | |
4952 | * update vsi params | |
4953 | */ | |
4954 | vsi->info.mapping_flags = ctxt->info.mapping_flags; | |
4955 | memcpy(&vsi->info.queue_mapping, | |
4956 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); | |
4957 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, | |
4958 | sizeof(vsi->info.tc_mapping)); | |
4959 | } | |
4960 | ||
4961 | /** | |
4962 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map | |
4963 | * @vsi: VSI to be configured | |
4964 | * @enabled_tc: TC bitmap | |
4965 | * | |
4966 | * This configures a particular VSI for TCs that are mapped to the | |
4967 | * given TC bitmap. It uses default bandwidth share for TCs across | |
4968 | * VSIs to configure TC for a particular VSI. | |
4969 | * | |
4970 | * NOTE: | |
4971 | * It is expected that the VSI queues have been quisced before calling | |
4972 | * this function. | |
4973 | **/ | |
4974 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) | |
4975 | { | |
4976 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; | |
4977 | struct i40e_vsi_context ctxt; | |
4978 | int ret = 0; | |
4979 | int i; | |
4980 | ||
4981 | /* Check if enabled_tc is same as existing or new TCs */ | |
4982 | if (vsi->tc_config.enabled_tc == enabled_tc) | |
4983 | return ret; | |
4984 | ||
4985 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ | |
4986 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
75f5cea9 | 4987 | if (enabled_tc & BIT(i)) |
41c445ff JB |
4988 | bw_share[i] = 1; |
4989 | } | |
4990 | ||
4991 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); | |
4992 | if (ret) { | |
4993 | dev_info(&vsi->back->pdev->dev, | |
4994 | "Failed configuring TC map %d for VSI %d\n", | |
4995 | enabled_tc, vsi->seid); | |
4996 | goto out; | |
4997 | } | |
4998 | ||
4999 | /* Update Queue Pairs Mapping for currently enabled UPs */ | |
5000 | ctxt.seid = vsi->seid; | |
5001 | ctxt.pf_num = vsi->back->hw.pf_id; | |
5002 | ctxt.vf_num = 0; | |
5003 | ctxt.uplink_seid = vsi->uplink_seid; | |
1a2f6248 | 5004 | ctxt.info = vsi->info; |
41c445ff JB |
5005 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
5006 | ||
e3219ce6 ASJ |
5007 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
5008 | ctxt.info.valid_sections |= | |
5009 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); | |
5010 | ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA; | |
5011 | } | |
5012 | ||
41c445ff JB |
5013 | /* Update the VSI after updating the VSI queue-mapping information */ |
5014 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); | |
5015 | if (ret) { | |
5016 | dev_info(&vsi->back->pdev->dev, | |
f1c7e72e SN |
5017 | "Update vsi tc config failed, err %s aq_err %s\n", |
5018 | i40e_stat_str(&vsi->back->hw, ret), | |
5019 | i40e_aq_str(&vsi->back->hw, | |
5020 | vsi->back->hw.aq.asq_last_status)); | |
41c445ff JB |
5021 | goto out; |
5022 | } | |
5023 | /* update the local VSI info with updated queue map */ | |
5024 | i40e_vsi_update_queue_map(vsi, &ctxt); | |
5025 | vsi->info.valid_sections = 0; | |
5026 | ||
5027 | /* Update current VSI BW information */ | |
5028 | ret = i40e_vsi_get_bw_info(vsi); | |
5029 | if (ret) { | |
5030 | dev_info(&vsi->back->pdev->dev, | |
f1c7e72e SN |
5031 | "Failed updating vsi bw info, err %s aq_err %s\n", |
5032 | i40e_stat_str(&vsi->back->hw, ret), | |
5033 | i40e_aq_str(&vsi->back->hw, | |
5034 | vsi->back->hw.aq.asq_last_status)); | |
41c445ff JB |
5035 | goto out; |
5036 | } | |
5037 | ||
5038 | /* Update the netdev TC setup */ | |
5039 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); | |
5040 | out: | |
5041 | return ret; | |
5042 | } | |
5043 | ||
4e3b35b0 NP |
5044 | /** |
5045 | * i40e_veb_config_tc - Configure TCs for given VEB | |
5046 | * @veb: given VEB | |
5047 | * @enabled_tc: TC bitmap | |
5048 | * | |
5049 | * Configures given TC bitmap for VEB (switching) element | |
5050 | **/ | |
5051 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) | |
5052 | { | |
5053 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; | |
5054 | struct i40e_pf *pf = veb->pf; | |
5055 | int ret = 0; | |
5056 | int i; | |
5057 | ||
5058 | /* No TCs or already enabled TCs just return */ | |
5059 | if (!enabled_tc || veb->enabled_tc == enabled_tc) | |
5060 | return ret; | |
5061 | ||
5062 | bw_data.tc_valid_bits = enabled_tc; | |
5063 | /* bw_data.absolute_credits is not set (relative) */ | |
5064 | ||
5065 | /* Enable ETS TCs with equal BW Share for now */ | |
5066 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
75f5cea9 | 5067 | if (enabled_tc & BIT(i)) |
4e3b35b0 NP |
5068 | bw_data.tc_bw_share_credits[i] = 1; |
5069 | } | |
5070 | ||
5071 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, | |
5072 | &bw_data, NULL); | |
5073 | if (ret) { | |
5074 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
5075 | "VEB bw config failed, err %s aq_err %s\n", |
5076 | i40e_stat_str(&pf->hw, ret), | |
5077 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
4e3b35b0 NP |
5078 | goto out; |
5079 | } | |
5080 | ||
5081 | /* Update the BW information */ | |
5082 | ret = i40e_veb_get_bw_info(veb); | |
5083 | if (ret) { | |
5084 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
5085 | "Failed getting veb bw config, err %s aq_err %s\n", |
5086 | i40e_stat_str(&pf->hw, ret), | |
5087 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
4e3b35b0 NP |
5088 | } |
5089 | ||
5090 | out: | |
5091 | return ret; | |
5092 | } | |
5093 | ||
5094 | #ifdef CONFIG_I40E_DCB | |
5095 | /** | |
5096 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs | |
5097 | * @pf: PF struct | |
5098 | * | |
5099 | * Reconfigure VEB/VSIs on a given PF; it is assumed that | |
5100 | * the caller would've quiesce all the VSIs before calling | |
5101 | * this function | |
5102 | **/ | |
5103 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) | |
5104 | { | |
5105 | u8 tc_map = 0; | |
5106 | int ret; | |
5107 | u8 v; | |
5108 | ||
5109 | /* Enable the TCs available on PF to all VEBs */ | |
5110 | tc_map = i40e_pf_get_tc_map(pf); | |
5111 | for (v = 0; v < I40E_MAX_VEB; v++) { | |
5112 | if (!pf->veb[v]) | |
5113 | continue; | |
5114 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); | |
5115 | if (ret) { | |
5116 | dev_info(&pf->pdev->dev, | |
5117 | "Failed configuring TC for VEB seid=%d\n", | |
5118 | pf->veb[v]->seid); | |
5119 | /* Will try to configure as many components */ | |
5120 | } | |
5121 | } | |
5122 | ||
5123 | /* Update each VSI */ | |
505682cd | 5124 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
4e3b35b0 NP |
5125 | if (!pf->vsi[v]) |
5126 | continue; | |
5127 | ||
5128 | /* - Enable all TCs for the LAN VSI | |
5129 | * - For all others keep them at TC0 for now | |
5130 | */ | |
5131 | if (v == pf->lan_vsi) | |
5132 | tc_map = i40e_pf_get_tc_map(pf); | |
5133 | else | |
ea6acb7e | 5134 | tc_map = I40E_DEFAULT_TRAFFIC_CLASS; |
4e3b35b0 NP |
5135 | |
5136 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); | |
5137 | if (ret) { | |
5138 | dev_info(&pf->pdev->dev, | |
5139 | "Failed configuring TC for VSI seid=%d\n", | |
5140 | pf->vsi[v]->seid); | |
5141 | /* Will try to configure as many components */ | |
5142 | } else { | |
0672a091 NP |
5143 | /* Re-configure VSI vectors based on updated TC map */ |
5144 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); | |
4e3b35b0 NP |
5145 | if (pf->vsi[v]->netdev) |
5146 | i40e_dcbnl_set_all(pf->vsi[v]); | |
5147 | } | |
5148 | } | |
5149 | } | |
5150 | ||
2fd75f31 NP |
5151 | /** |
5152 | * i40e_resume_port_tx - Resume port Tx | |
5153 | * @pf: PF struct | |
5154 | * | |
5155 | * Resume a port's Tx and issue a PF reset in case of failure to | |
5156 | * resume. | |
5157 | **/ | |
5158 | static int i40e_resume_port_tx(struct i40e_pf *pf) | |
5159 | { | |
5160 | struct i40e_hw *hw = &pf->hw; | |
5161 | int ret; | |
5162 | ||
5163 | ret = i40e_aq_resume_port_tx(hw, NULL); | |
5164 | if (ret) { | |
5165 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
5166 | "Resume Port Tx failed, err %s aq_err %s\n", |
5167 | i40e_stat_str(&pf->hw, ret), | |
5168 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
2fd75f31 NP |
5169 | /* Schedule PF reset to recover */ |
5170 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); | |
5171 | i40e_service_event_schedule(pf); | |
5172 | } | |
5173 | ||
5174 | return ret; | |
5175 | } | |
5176 | ||
4e3b35b0 NP |
5177 | /** |
5178 | * i40e_init_pf_dcb - Initialize DCB configuration | |
5179 | * @pf: PF being configured | |
5180 | * | |
5181 | * Query the current DCB configuration and cache it | |
5182 | * in the hardware structure | |
5183 | **/ | |
5184 | static int i40e_init_pf_dcb(struct i40e_pf *pf) | |
5185 | { | |
5186 | struct i40e_hw *hw = &pf->hw; | |
5187 | int err = 0; | |
5188 | ||
025b4a54 | 5189 | /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */ |
f1bbad33 | 5190 | if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT) |
025b4a54 ASJ |
5191 | goto out; |
5192 | ||
4e3b35b0 NP |
5193 | /* Get the initial DCB configuration */ |
5194 | err = i40e_init_dcb(hw); | |
5195 | if (!err) { | |
5196 | /* Device/Function is not DCBX capable */ | |
5197 | if ((!hw->func_caps.dcb) || | |
5198 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { | |
5199 | dev_info(&pf->pdev->dev, | |
5200 | "DCBX offload is not supported or is disabled for this PF.\n"); | |
4e3b35b0 NP |
5201 | } else { |
5202 | /* When status is not DISABLED then DCBX in FW */ | |
5203 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | | |
5204 | DCB_CAP_DCBX_VER_IEEE; | |
4d9b6043 NP |
5205 | |
5206 | pf->flags |= I40E_FLAG_DCB_CAPABLE; | |
a036244c DE |
5207 | /* Enable DCB tagging only when more than one TC |
5208 | * or explicitly disable if only one TC | |
5209 | */ | |
4d9b6043 NP |
5210 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
5211 | pf->flags |= I40E_FLAG_DCB_ENABLED; | |
a036244c DE |
5212 | else |
5213 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; | |
9fa61dd2 NP |
5214 | dev_dbg(&pf->pdev->dev, |
5215 | "DCBX offload is supported for this PF.\n"); | |
4e3b35b0 | 5216 | } |
014269ff | 5217 | } else { |
aebfc816 | 5218 | dev_info(&pf->pdev->dev, |
f1c7e72e SN |
5219 | "Query for DCB configuration failed, err %s aq_err %s\n", |
5220 | i40e_stat_str(&pf->hw, err), | |
5221 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
4e3b35b0 NP |
5222 | } |
5223 | ||
5224 | out: | |
5225 | return err; | |
5226 | } | |
5227 | #endif /* CONFIG_I40E_DCB */ | |
cf05ed08 JB |
5228 | #define SPEED_SIZE 14 |
5229 | #define FC_SIZE 8 | |
5230 | /** | |
5231 | * i40e_print_link_message - print link up or down | |
5232 | * @vsi: the VSI for which link needs a message | |
5233 | */ | |
c156f856 | 5234 | void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
cf05ed08 | 5235 | { |
7ec9ba11 | 5236 | enum i40e_aq_link_speed new_speed; |
a9165490 SN |
5237 | char *speed = "Unknown"; |
5238 | char *fc = "Unknown"; | |
3e03d7cc HT |
5239 | char *fec = ""; |
5240 | char *an = ""; | |
cf05ed08 | 5241 | |
7ec9ba11 FS |
5242 | new_speed = vsi->back->hw.phy.link_info.link_speed; |
5243 | ||
5244 | if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed)) | |
c156f856 MJ |
5245 | return; |
5246 | vsi->current_isup = isup; | |
7ec9ba11 | 5247 | vsi->current_speed = new_speed; |
cf05ed08 JB |
5248 | if (!isup) { |
5249 | netdev_info(vsi->netdev, "NIC Link is Down\n"); | |
5250 | return; | |
5251 | } | |
5252 | ||
148c2d80 GR |
5253 | /* Warn user if link speed on NPAR enabled partition is not at |
5254 | * least 10GB | |
5255 | */ | |
5256 | if (vsi->back->hw.func_caps.npar_enable && | |
5257 | (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB || | |
5258 | vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB)) | |
5259 | netdev_warn(vsi->netdev, | |
5260 | "The partition detected link speed that is less than 10Gbps\n"); | |
5261 | ||
cf05ed08 JB |
5262 | switch (vsi->back->hw.phy.link_info.link_speed) { |
5263 | case I40E_LINK_SPEED_40GB: | |
a9165490 | 5264 | speed = "40 G"; |
cf05ed08 | 5265 | break; |
ae24b409 | 5266 | case I40E_LINK_SPEED_20GB: |
a9165490 | 5267 | speed = "20 G"; |
ae24b409 | 5268 | break; |
3123237a CW |
5269 | case I40E_LINK_SPEED_25GB: |
5270 | speed = "25 G"; | |
5271 | break; | |
cf05ed08 | 5272 | case I40E_LINK_SPEED_10GB: |
a9165490 | 5273 | speed = "10 G"; |
cf05ed08 JB |
5274 | break; |
5275 | case I40E_LINK_SPEED_1GB: | |
a9165490 | 5276 | speed = "1000 M"; |
cf05ed08 | 5277 | break; |
5960d33f | 5278 | case I40E_LINK_SPEED_100MB: |
a9165490 | 5279 | speed = "100 M"; |
5960d33f | 5280 | break; |
cf05ed08 JB |
5281 | default: |
5282 | break; | |
5283 | } | |
5284 | ||
5285 | switch (vsi->back->hw.fc.current_mode) { | |
5286 | case I40E_FC_FULL: | |
a9165490 | 5287 | fc = "RX/TX"; |
cf05ed08 JB |
5288 | break; |
5289 | case I40E_FC_TX_PAUSE: | |
a9165490 | 5290 | fc = "TX"; |
cf05ed08 JB |
5291 | break; |
5292 | case I40E_FC_RX_PAUSE: | |
a9165490 | 5293 | fc = "RX"; |
cf05ed08 JB |
5294 | break; |
5295 | default: | |
a9165490 | 5296 | fc = "None"; |
cf05ed08 JB |
5297 | break; |
5298 | } | |
5299 | ||
3e03d7cc HT |
5300 | if (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) { |
5301 | fec = ", FEC: None"; | |
5302 | an = ", Autoneg: False"; | |
5303 | ||
5304 | if (vsi->back->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED) | |
5305 | an = ", Autoneg: True"; | |
5306 | ||
5307 | if (vsi->back->hw.phy.link_info.fec_info & | |
5308 | I40E_AQ_CONFIG_FEC_KR_ENA) | |
5309 | fec = ", FEC: CL74 FC-FEC/BASE-R"; | |
5310 | else if (vsi->back->hw.phy.link_info.fec_info & | |
5311 | I40E_AQ_CONFIG_FEC_RS_ENA) | |
5312 | fec = ", FEC: CL108 RS-FEC"; | |
5313 | } | |
5314 | ||
5315 | netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s, Flow Control: %s\n", | |
5316 | speed, fec, an, fc); | |
cf05ed08 | 5317 | } |
4e3b35b0 | 5318 | |
41c445ff JB |
5319 | /** |
5320 | * i40e_up_complete - Finish the last steps of bringing up a connection | |
5321 | * @vsi: the VSI being configured | |
5322 | **/ | |
5323 | static int i40e_up_complete(struct i40e_vsi *vsi) | |
5324 | { | |
5325 | struct i40e_pf *pf = vsi->back; | |
5326 | int err; | |
5327 | ||
5328 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) | |
5329 | i40e_vsi_configure_msix(vsi); | |
5330 | else | |
5331 | i40e_configure_msi_and_legacy(vsi); | |
5332 | ||
5333 | /* start rings */ | |
3aa7b74d | 5334 | err = i40e_vsi_start_rings(vsi); |
41c445ff JB |
5335 | if (err) |
5336 | return err; | |
5337 | ||
5338 | clear_bit(__I40E_DOWN, &vsi->state); | |
5339 | i40e_napi_enable_all(vsi); | |
5340 | i40e_vsi_enable_irq(vsi); | |
5341 | ||
5342 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && | |
5343 | (vsi->netdev)) { | |
cf05ed08 | 5344 | i40e_print_link_message(vsi, true); |
41c445ff JB |
5345 | netif_tx_start_all_queues(vsi->netdev); |
5346 | netif_carrier_on(vsi->netdev); | |
6d779b41 | 5347 | } else if (vsi->netdev) { |
cf05ed08 | 5348 | i40e_print_link_message(vsi, false); |
7b592f61 CW |
5349 | /* need to check for qualified module here*/ |
5350 | if ((pf->hw.phy.link_info.link_info & | |
5351 | I40E_AQ_MEDIA_AVAILABLE) && | |
5352 | (!(pf->hw.phy.link_info.an_info & | |
5353 | I40E_AQ_QUALIFIED_MODULE))) | |
5354 | netdev_err(vsi->netdev, | |
5355 | "the driver failed to link because an unqualified module was detected."); | |
41c445ff | 5356 | } |
ca64fa4e ASJ |
5357 | |
5358 | /* replay FDIR SB filters */ | |
1e1be8f6 ASJ |
5359 | if (vsi->type == I40E_VSI_FDIR) { |
5360 | /* reset fd counters */ | |
097dbf52 JK |
5361 | pf->fd_add_err = 0; |
5362 | pf->fd_atr_cnt = 0; | |
ca64fa4e | 5363 | i40e_fdir_filter_restore(vsi); |
1e1be8f6 | 5364 | } |
e3219ce6 ASJ |
5365 | |
5366 | /* On the next run of the service_task, notify any clients of the new | |
5367 | * opened netdev | |
5368 | */ | |
5369 | pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED; | |
41c445ff JB |
5370 | i40e_service_event_schedule(pf); |
5371 | ||
5372 | return 0; | |
5373 | } | |
5374 | ||
5375 | /** | |
5376 | * i40e_vsi_reinit_locked - Reset the VSI | |
5377 | * @vsi: the VSI being configured | |
5378 | * | |
5379 | * Rebuild the ring structs after some configuration | |
5380 | * has changed, e.g. MTU size. | |
5381 | **/ | |
5382 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) | |
5383 | { | |
5384 | struct i40e_pf *pf = vsi->back; | |
5385 | ||
5386 | WARN_ON(in_interrupt()); | |
5387 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) | |
5388 | usleep_range(1000, 2000); | |
5389 | i40e_down(vsi); | |
5390 | ||
41c445ff JB |
5391 | i40e_up(vsi); |
5392 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); | |
5393 | } | |
5394 | ||
5395 | /** | |
5396 | * i40e_up - Bring the connection back up after being down | |
5397 | * @vsi: the VSI being configured | |
5398 | **/ | |
5399 | int i40e_up(struct i40e_vsi *vsi) | |
5400 | { | |
5401 | int err; | |
5402 | ||
5403 | err = i40e_vsi_configure(vsi); | |
5404 | if (!err) | |
5405 | err = i40e_up_complete(vsi); | |
5406 | ||
5407 | return err; | |
5408 | } | |
5409 | ||
5410 | /** | |
5411 | * i40e_down - Shutdown the connection processing | |
5412 | * @vsi: the VSI being stopped | |
5413 | **/ | |
5414 | void i40e_down(struct i40e_vsi *vsi) | |
5415 | { | |
5416 | int i; | |
5417 | ||
5418 | /* It is assumed that the caller of this function | |
5419 | * sets the vsi->state __I40E_DOWN bit. | |
5420 | */ | |
5421 | if (vsi->netdev) { | |
5422 | netif_carrier_off(vsi->netdev); | |
5423 | netif_tx_disable(vsi->netdev); | |
5424 | } | |
5425 | i40e_vsi_disable_irq(vsi); | |
3aa7b74d | 5426 | i40e_vsi_stop_rings(vsi); |
41c445ff JB |
5427 | i40e_napi_disable_all(vsi); |
5428 | ||
5429 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
9f65e15b AD |
5430 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
5431 | i40e_clean_rx_ring(vsi->rx_rings[i]); | |
41c445ff | 5432 | } |
f980d445 | 5433 | |
41c445ff JB |
5434 | } |
5435 | ||
5436 | /** | |
5437 | * i40e_setup_tc - configure multiple traffic classes | |
5438 | * @netdev: net device to configure | |
5439 | * @tc: number of traffic classes to enable | |
5440 | **/ | |
5441 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) | |
5442 | { | |
5443 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
5444 | struct i40e_vsi *vsi = np->vsi; | |
5445 | struct i40e_pf *pf = vsi->back; | |
5446 | u8 enabled_tc = 0; | |
5447 | int ret = -EINVAL; | |
5448 | int i; | |
5449 | ||
5450 | /* Check if DCB enabled to continue */ | |
5451 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { | |
5452 | netdev_info(netdev, "DCB is not enabled for adapter\n"); | |
5453 | goto exit; | |
5454 | } | |
5455 | ||
5456 | /* Check if MFP enabled */ | |
5457 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { | |
5458 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); | |
5459 | goto exit; | |
5460 | } | |
5461 | ||
5462 | /* Check whether tc count is within enabled limit */ | |
5463 | if (tc > i40e_pf_get_num_tc(pf)) { | |
5464 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); | |
5465 | goto exit; | |
5466 | } | |
5467 | ||
5468 | /* Generate TC map for number of tc requested */ | |
5469 | for (i = 0; i < tc; i++) | |
75f5cea9 | 5470 | enabled_tc |= BIT(i); |
41c445ff JB |
5471 | |
5472 | /* Requesting same TC configuration as already enabled */ | |
5473 | if (enabled_tc == vsi->tc_config.enabled_tc) | |
5474 | return 0; | |
5475 | ||
5476 | /* Quiesce VSI queues */ | |
5477 | i40e_quiesce_vsi(vsi); | |
5478 | ||
5479 | /* Configure VSI for enabled TCs */ | |
5480 | ret = i40e_vsi_config_tc(vsi, enabled_tc); | |
5481 | if (ret) { | |
5482 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", | |
5483 | vsi->seid); | |
5484 | goto exit; | |
5485 | } | |
5486 | ||
5487 | /* Unquiesce VSI */ | |
5488 | i40e_unquiesce_vsi(vsi); | |
5489 | ||
5490 | exit: | |
5491 | return ret; | |
5492 | } | |
5493 | ||
16e5cc64 JF |
5494 | static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto, |
5495 | struct tc_to_netdev *tc) | |
e4c6734e | 5496 | { |
56f36acd | 5497 | if (tc->type != TC_SETUP_MQPRIO) |
e4c6734e | 5498 | return -EINVAL; |
56f36acd AN |
5499 | |
5500 | tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS; | |
5501 | ||
5502 | return i40e_setup_tc(netdev, tc->mqprio->num_tc); | |
e4c6734e JF |
5503 | } |
5504 | ||
41c445ff JB |
5505 | /** |
5506 | * i40e_open - Called when a network interface is made active | |
5507 | * @netdev: network interface device structure | |
5508 | * | |
5509 | * The open entry point is called when a network interface is made | |
5510 | * active by the system (IFF_UP). At this point all resources needed | |
5511 | * for transmit and receive operations are allocated, the interrupt | |
5512 | * handler is registered with the OS, the netdev watchdog subtask is | |
5513 | * enabled, and the stack is notified that the interface is ready. | |
5514 | * | |
5515 | * Returns 0 on success, negative value on failure | |
5516 | **/ | |
38e00438 | 5517 | int i40e_open(struct net_device *netdev) |
41c445ff JB |
5518 | { |
5519 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
5520 | struct i40e_vsi *vsi = np->vsi; | |
5521 | struct i40e_pf *pf = vsi->back; | |
41c445ff JB |
5522 | int err; |
5523 | ||
4eb3f768 SN |
5524 | /* disallow open during test or if eeprom is broken */ |
5525 | if (test_bit(__I40E_TESTING, &pf->state) || | |
5526 | test_bit(__I40E_BAD_EEPROM, &pf->state)) | |
41c445ff JB |
5527 | return -EBUSY; |
5528 | ||
5529 | netif_carrier_off(netdev); | |
5530 | ||
6c167f58 EK |
5531 | err = i40e_vsi_open(vsi); |
5532 | if (err) | |
5533 | return err; | |
5534 | ||
059dab69 JB |
5535 | /* configure global TSO hardware offload settings */ |
5536 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | | |
5537 | TCP_FLAG_FIN) >> 16); | |
5538 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | | |
5539 | TCP_FLAG_FIN | | |
5540 | TCP_FLAG_CWR) >> 16); | |
5541 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); | |
5542 | ||
06a5f7f1 | 5543 | udp_tunnel_get_rx_info(netdev); |
e3219ce6 | 5544 | |
6c167f58 EK |
5545 | return 0; |
5546 | } | |
5547 | ||
5548 | /** | |
5549 | * i40e_vsi_open - | |
5550 | * @vsi: the VSI to open | |
5551 | * | |
5552 | * Finish initialization of the VSI. | |
5553 | * | |
5554 | * Returns 0 on success, negative value on failure | |
373149fc MS |
5555 | * |
5556 | * Note: expects to be called while under rtnl_lock() | |
6c167f58 EK |
5557 | **/ |
5558 | int i40e_vsi_open(struct i40e_vsi *vsi) | |
5559 | { | |
5560 | struct i40e_pf *pf = vsi->back; | |
b294ac70 | 5561 | char int_name[I40E_INT_NAME_STR_LEN]; |
6c167f58 EK |
5562 | int err; |
5563 | ||
41c445ff JB |
5564 | /* allocate descriptors */ |
5565 | err = i40e_vsi_setup_tx_resources(vsi); | |
5566 | if (err) | |
5567 | goto err_setup_tx; | |
5568 | err = i40e_vsi_setup_rx_resources(vsi); | |
5569 | if (err) | |
5570 | goto err_setup_rx; | |
5571 | ||
5572 | err = i40e_vsi_configure(vsi); | |
5573 | if (err) | |
5574 | goto err_setup_rx; | |
5575 | ||
c22e3c6c SN |
5576 | if (vsi->netdev) { |
5577 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", | |
5578 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); | |
5579 | err = i40e_vsi_request_irq(vsi, int_name); | |
5580 | if (err) | |
5581 | goto err_setup_rx; | |
41c445ff | 5582 | |
c22e3c6c SN |
5583 | /* Notify the stack of the actual queue counts. */ |
5584 | err = netif_set_real_num_tx_queues(vsi->netdev, | |
5585 | vsi->num_queue_pairs); | |
5586 | if (err) | |
5587 | goto err_set_queues; | |
25946ddb | 5588 | |
c22e3c6c SN |
5589 | err = netif_set_real_num_rx_queues(vsi->netdev, |
5590 | vsi->num_queue_pairs); | |
5591 | if (err) | |
5592 | goto err_set_queues; | |
8a9eb7d3 SN |
5593 | |
5594 | } else if (vsi->type == I40E_VSI_FDIR) { | |
e240f674 | 5595 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir", |
b2008cbf CW |
5596 | dev_driver_string(&pf->pdev->dev), |
5597 | dev_name(&pf->pdev->dev)); | |
8a9eb7d3 | 5598 | err = i40e_vsi_request_irq(vsi, int_name); |
b2008cbf | 5599 | |
c22e3c6c | 5600 | } else { |
ce9ccb17 | 5601 | err = -EINVAL; |
6c167f58 EK |
5602 | goto err_setup_rx; |
5603 | } | |
25946ddb | 5604 | |
41c445ff JB |
5605 | err = i40e_up_complete(vsi); |
5606 | if (err) | |
5607 | goto err_up_complete; | |
5608 | ||
41c445ff JB |
5609 | return 0; |
5610 | ||
5611 | err_up_complete: | |
5612 | i40e_down(vsi); | |
25946ddb | 5613 | err_set_queues: |
41c445ff JB |
5614 | i40e_vsi_free_irq(vsi); |
5615 | err_setup_rx: | |
5616 | i40e_vsi_free_rx_resources(vsi); | |
5617 | err_setup_tx: | |
5618 | i40e_vsi_free_tx_resources(vsi); | |
5619 | if (vsi == pf->vsi[pf->lan_vsi]) | |
373149fc | 5620 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED), true); |
41c445ff JB |
5621 | |
5622 | return err; | |
5623 | } | |
5624 | ||
17a73f6b JG |
5625 | /** |
5626 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting | |
b40c82e6 | 5627 | * @pf: Pointer to PF |
17a73f6b JG |
5628 | * |
5629 | * This function destroys the hlist where all the Flow Director | |
5630 | * filters were saved. | |
5631 | **/ | |
5632 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) | |
5633 | { | |
5634 | struct i40e_fdir_filter *filter; | |
0e588de1 | 5635 | struct i40e_flex_pit *pit_entry, *tmp; |
17a73f6b JG |
5636 | struct hlist_node *node2; |
5637 | ||
5638 | hlist_for_each_entry_safe(filter, node2, | |
5639 | &pf->fdir_filter_list, fdir_node) { | |
5640 | hlist_del(&filter->fdir_node); | |
5641 | kfree(filter); | |
5642 | } | |
097dbf52 | 5643 | |
0e588de1 JK |
5644 | list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) { |
5645 | list_del(&pit_entry->list); | |
5646 | kfree(pit_entry); | |
5647 | } | |
5648 | INIT_LIST_HEAD(&pf->l3_flex_pit_list); | |
5649 | ||
5650 | list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) { | |
5651 | list_del(&pit_entry->list); | |
5652 | kfree(pit_entry); | |
5653 | } | |
5654 | INIT_LIST_HEAD(&pf->l4_flex_pit_list); | |
5655 | ||
17a73f6b | 5656 | pf->fdir_pf_active_filters = 0; |
097dbf52 JK |
5657 | pf->fd_tcp4_filter_cnt = 0; |
5658 | pf->fd_udp4_filter_cnt = 0; | |
f223c875 | 5659 | pf->fd_sctp4_filter_cnt = 0; |
097dbf52 | 5660 | pf->fd_ip4_filter_cnt = 0; |
3bcee1e6 JK |
5661 | |
5662 | /* Reprogram the default input set for TCP/IPv4 */ | |
5663 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP, | |
5664 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | | |
5665 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); | |
5666 | ||
5667 | /* Reprogram the default input set for UDP/IPv4 */ | |
5668 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP, | |
5669 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | | |
5670 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); | |
5671 | ||
5672 | /* Reprogram the default input set for SCTP/IPv4 */ | |
5673 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP, | |
5674 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK | | |
5675 | I40E_L4_SRC_MASK | I40E_L4_DST_MASK); | |
5676 | ||
5677 | /* Reprogram the default input set for Other/IPv4 */ | |
5678 | i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER, | |
5679 | I40E_L3_SRC_MASK | I40E_L3_DST_MASK); | |
17a73f6b JG |
5680 | } |
5681 | ||
41c445ff JB |
5682 | /** |
5683 | * i40e_close - Disables a network interface | |
5684 | * @netdev: network interface device structure | |
5685 | * | |
5686 | * The close entry point is called when an interface is de-activated | |
5687 | * by the OS. The hardware is still under the driver's control, but | |
5688 | * this netdev interface is disabled. | |
5689 | * | |
5690 | * Returns 0, this is not allowed to fail | |
5691 | **/ | |
38e00438 | 5692 | int i40e_close(struct net_device *netdev) |
41c445ff JB |
5693 | { |
5694 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
5695 | struct i40e_vsi *vsi = np->vsi; | |
5696 | ||
90ef8d47 | 5697 | i40e_vsi_close(vsi); |
41c445ff JB |
5698 | |
5699 | return 0; | |
5700 | } | |
5701 | ||
5702 | /** | |
5703 | * i40e_do_reset - Start a PF or Core Reset sequence | |
5704 | * @pf: board private structure | |
5705 | * @reset_flags: which reset is requested | |
373149fc MS |
5706 | * @lock_acquired: indicates whether or not the lock has been acquired |
5707 | * before this function was called. | |
41c445ff JB |
5708 | * |
5709 | * The essential difference in resets is that the PF Reset | |
5710 | * doesn't clear the packet buffers, doesn't reset the PE | |
5711 | * firmware, and doesn't bother the other PFs on the chip. | |
5712 | **/ | |
373149fc | 5713 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired) |
41c445ff JB |
5714 | { |
5715 | u32 val; | |
5716 | ||
5717 | WARN_ON(in_interrupt()); | |
5718 | ||
263fc48f | 5719 | |
41c445ff | 5720 | /* do the biggest reset indicated */ |
41a1d04b | 5721 | if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) { |
41c445ff JB |
5722 | |
5723 | /* Request a Global Reset | |
5724 | * | |
5725 | * This will start the chip's countdown to the actual full | |
5726 | * chip reset event, and a warning interrupt to be sent | |
5727 | * to all PFs, including the requestor. Our handler | |
5728 | * for the warning interrupt will deal with the shutdown | |
5729 | * and recovery of the switch setup. | |
5730 | */ | |
69bfb110 | 5731 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
41c445ff JB |
5732 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
5733 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; | |
5734 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); | |
5735 | ||
41a1d04b | 5736 | } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) { |
41c445ff JB |
5737 | |
5738 | /* Request a Core Reset | |
5739 | * | |
5740 | * Same as Global Reset, except does *not* include the MAC/PHY | |
5741 | */ | |
69bfb110 | 5742 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
41c445ff JB |
5743 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
5744 | val |= I40E_GLGEN_RTRIG_CORER_MASK; | |
5745 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); | |
5746 | i40e_flush(&pf->hw); | |
5747 | ||
41a1d04b | 5748 | } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) { |
41c445ff JB |
5749 | |
5750 | /* Request a PF Reset | |
5751 | * | |
5752 | * Resets only the PF-specific registers | |
5753 | * | |
5754 | * This goes directly to the tear-down and rebuild of | |
5755 | * the switch, since we need to do all the recovery as | |
5756 | * for the Core Reset. | |
5757 | */ | |
69bfb110 | 5758 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
373149fc | 5759 | i40e_handle_reset_warning(pf, lock_acquired); |
41c445ff | 5760 | |
41a1d04b | 5761 | } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) { |
41c445ff JB |
5762 | int v; |
5763 | ||
5764 | /* Find the VSI(s) that requested a re-init */ | |
5765 | dev_info(&pf->pdev->dev, | |
5766 | "VSI reinit requested\n"); | |
505682cd | 5767 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
41c445ff | 5768 | struct i40e_vsi *vsi = pf->vsi[v]; |
6995b36c | 5769 | |
41c445ff JB |
5770 | if (vsi != NULL && |
5771 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { | |
5772 | i40e_vsi_reinit_locked(pf->vsi[v]); | |
5773 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); | |
5774 | } | |
5775 | } | |
41a1d04b | 5776 | } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) { |
b5d06f05 NP |
5777 | int v; |
5778 | ||
5779 | /* Find the VSI(s) that needs to be brought down */ | |
5780 | dev_info(&pf->pdev->dev, "VSI down requested\n"); | |
5781 | for (v = 0; v < pf->num_alloc_vsi; v++) { | |
5782 | struct i40e_vsi *vsi = pf->vsi[v]; | |
6995b36c | 5783 | |
b5d06f05 NP |
5784 | if (vsi != NULL && |
5785 | test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) { | |
5786 | set_bit(__I40E_DOWN, &vsi->state); | |
5787 | i40e_down(vsi); | |
5788 | clear_bit(__I40E_DOWN_REQUESTED, &vsi->state); | |
5789 | } | |
5790 | } | |
41c445ff JB |
5791 | } else { |
5792 | dev_info(&pf->pdev->dev, | |
5793 | "bad reset request 0x%08x\n", reset_flags); | |
41c445ff JB |
5794 | } |
5795 | } | |
5796 | ||
4e3b35b0 NP |
5797 | #ifdef CONFIG_I40E_DCB |
5798 | /** | |
5799 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig | |
5800 | * @pf: board private structure | |
5801 | * @old_cfg: current DCB config | |
5802 | * @new_cfg: new DCB config | |
5803 | **/ | |
5804 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, | |
5805 | struct i40e_dcbx_config *old_cfg, | |
5806 | struct i40e_dcbx_config *new_cfg) | |
5807 | { | |
5808 | bool need_reconfig = false; | |
5809 | ||
5810 | /* Check if ETS configuration has changed */ | |
5811 | if (memcmp(&new_cfg->etscfg, | |
5812 | &old_cfg->etscfg, | |
5813 | sizeof(new_cfg->etscfg))) { | |
5814 | /* If Priority Table has changed reconfig is needed */ | |
5815 | if (memcmp(&new_cfg->etscfg.prioritytable, | |
5816 | &old_cfg->etscfg.prioritytable, | |
5817 | sizeof(new_cfg->etscfg.prioritytable))) { | |
5818 | need_reconfig = true; | |
69bfb110 | 5819 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
4e3b35b0 NP |
5820 | } |
5821 | ||
5822 | if (memcmp(&new_cfg->etscfg.tcbwtable, | |
5823 | &old_cfg->etscfg.tcbwtable, | |
5824 | sizeof(new_cfg->etscfg.tcbwtable))) | |
69bfb110 | 5825 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
4e3b35b0 NP |
5826 | |
5827 | if (memcmp(&new_cfg->etscfg.tsatable, | |
5828 | &old_cfg->etscfg.tsatable, | |
5829 | sizeof(new_cfg->etscfg.tsatable))) | |
69bfb110 | 5830 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
4e3b35b0 NP |
5831 | } |
5832 | ||
5833 | /* Check if PFC configuration has changed */ | |
5834 | if (memcmp(&new_cfg->pfc, | |
5835 | &old_cfg->pfc, | |
5836 | sizeof(new_cfg->pfc))) { | |
5837 | need_reconfig = true; | |
69bfb110 | 5838 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
4e3b35b0 NP |
5839 | } |
5840 | ||
5841 | /* Check if APP Table has changed */ | |
5842 | if (memcmp(&new_cfg->app, | |
5843 | &old_cfg->app, | |
3d9667a9 | 5844 | sizeof(new_cfg->app))) { |
4e3b35b0 | 5845 | need_reconfig = true; |
69bfb110 | 5846 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
3d9667a9 | 5847 | } |
4e3b35b0 | 5848 | |
fb43201f | 5849 | dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig); |
4e3b35b0 NP |
5850 | return need_reconfig; |
5851 | } | |
5852 | ||
5853 | /** | |
5854 | * i40e_handle_lldp_event - Handle LLDP Change MIB event | |
5855 | * @pf: board private structure | |
5856 | * @e: event info posted on ARQ | |
5857 | **/ | |
5858 | static int i40e_handle_lldp_event(struct i40e_pf *pf, | |
5859 | struct i40e_arq_event_info *e) | |
5860 | { | |
5861 | struct i40e_aqc_lldp_get_mib *mib = | |
5862 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; | |
5863 | struct i40e_hw *hw = &pf->hw; | |
4e3b35b0 NP |
5864 | struct i40e_dcbx_config tmp_dcbx_cfg; |
5865 | bool need_reconfig = false; | |
5866 | int ret = 0; | |
5867 | u8 type; | |
5868 | ||
4d9b6043 | 5869 | /* Not DCB capable or capability disabled */ |
ea6acb7e | 5870 | if (!(pf->flags & I40E_FLAG_DCB_CAPABLE)) |
4d9b6043 NP |
5871 | return ret; |
5872 | ||
4e3b35b0 NP |
5873 | /* Ignore if event is not for Nearest Bridge */ |
5874 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) | |
5875 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); | |
fb43201f | 5876 | dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type); |
4e3b35b0 NP |
5877 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
5878 | return ret; | |
5879 | ||
5880 | /* Check MIB Type and return if event for Remote MIB update */ | |
5881 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; | |
9fa61dd2 | 5882 | dev_dbg(&pf->pdev->dev, |
fb43201f | 5883 | "LLDP event mib type %s\n", type ? "remote" : "local"); |
4e3b35b0 NP |
5884 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
5885 | /* Update the remote cached instance and return */ | |
5886 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, | |
5887 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, | |
5888 | &hw->remote_dcbx_config); | |
5889 | goto exit; | |
5890 | } | |
5891 | ||
9fa61dd2 | 5892 | /* Store the old configuration */ |
1a2f6248 | 5893 | tmp_dcbx_cfg = hw->local_dcbx_config; |
9fa61dd2 | 5894 | |
750fcbcf NP |
5895 | /* Reset the old DCBx configuration data */ |
5896 | memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config)); | |
9fa61dd2 NP |
5897 | /* Get updated DCBX data from firmware */ |
5898 | ret = i40e_get_dcb_config(&pf->hw); | |
4e3b35b0 | 5899 | if (ret) { |
f1c7e72e SN |
5900 | dev_info(&pf->pdev->dev, |
5901 | "Failed querying DCB configuration data from firmware, err %s aq_err %s\n", | |
5902 | i40e_stat_str(&pf->hw, ret), | |
5903 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
4e3b35b0 NP |
5904 | goto exit; |
5905 | } | |
5906 | ||
5907 | /* No change detected in DCBX configs */ | |
750fcbcf NP |
5908 | if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config, |
5909 | sizeof(tmp_dcbx_cfg))) { | |
69bfb110 | 5910 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
4e3b35b0 NP |
5911 | goto exit; |
5912 | } | |
5913 | ||
750fcbcf NP |
5914 | need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg, |
5915 | &hw->local_dcbx_config); | |
4e3b35b0 | 5916 | |
750fcbcf | 5917 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config); |
4e3b35b0 NP |
5918 | |
5919 | if (!need_reconfig) | |
5920 | goto exit; | |
5921 | ||
4d9b6043 | 5922 | /* Enable DCB tagging only when more than one TC */ |
750fcbcf | 5923 | if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1) |
4d9b6043 NP |
5924 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
5925 | else | |
5926 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; | |
5927 | ||
69129dc3 | 5928 | set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
4e3b35b0 NP |
5929 | /* Reconfiguration needed quiesce all VSIs */ |
5930 | i40e_pf_quiesce_all_vsi(pf); | |
5931 | ||
5932 | /* Changes in configuration update VEB/VSI */ | |
5933 | i40e_dcb_reconfigure(pf); | |
5934 | ||
2fd75f31 NP |
5935 | ret = i40e_resume_port_tx(pf); |
5936 | ||
69129dc3 | 5937 | clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state); |
2fd75f31 | 5938 | /* In case of error no point in resuming VSIs */ |
69129dc3 NP |
5939 | if (ret) |
5940 | goto exit; | |
5941 | ||
3fe06f41 NP |
5942 | /* Wait for the PF's queues to be disabled */ |
5943 | ret = i40e_pf_wait_queues_disabled(pf); | |
11e47708 PN |
5944 | if (ret) { |
5945 | /* Schedule PF reset to recover */ | |
5946 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); | |
5947 | i40e_service_event_schedule(pf); | |
5948 | } else { | |
2fd75f31 | 5949 | i40e_pf_unquiesce_all_vsi(pf); |
0ef2d5af MW |
5950 | pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED | |
5951 | I40E_FLAG_CLIENT_L2_CHANGE); | |
11e47708 PN |
5952 | } |
5953 | ||
4e3b35b0 NP |
5954 | exit: |
5955 | return ret; | |
5956 | } | |
5957 | #endif /* CONFIG_I40E_DCB */ | |
5958 | ||
23326186 ASJ |
5959 | /** |
5960 | * i40e_do_reset_safe - Protected reset path for userland calls. | |
5961 | * @pf: board private structure | |
5962 | * @reset_flags: which reset is requested | |
5963 | * | |
5964 | **/ | |
5965 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) | |
5966 | { | |
5967 | rtnl_lock(); | |
373149fc | 5968 | i40e_do_reset(pf, reset_flags, true); |
23326186 ASJ |
5969 | rtnl_unlock(); |
5970 | } | |
5971 | ||
41c445ff JB |
5972 | /** |
5973 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event | |
5974 | * @pf: board private structure | |
5975 | * @e: event info posted on ARQ | |
5976 | * | |
5977 | * Handler for LAN Queue Overflow Event generated by the firmware for PF | |
5978 | * and VF queues | |
5979 | **/ | |
5980 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, | |
5981 | struct i40e_arq_event_info *e) | |
5982 | { | |
5983 | struct i40e_aqc_lan_overflow *data = | |
5984 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; | |
5985 | u32 queue = le32_to_cpu(data->prtdcb_rupto); | |
5986 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); | |
5987 | struct i40e_hw *hw = &pf->hw; | |
5988 | struct i40e_vf *vf; | |
5989 | u16 vf_id; | |
5990 | ||
69bfb110 JB |
5991 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
5992 | queue, qtx_ctl); | |
41c445ff JB |
5993 | |
5994 | /* Queue belongs to VF, find the VF and issue VF reset */ | |
5995 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) | |
5996 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { | |
5997 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) | |
5998 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); | |
5999 | vf_id -= hw->func_caps.vf_base_id; | |
6000 | vf = &pf->vf[vf_id]; | |
6001 | i40e_vc_notify_vf_reset(vf); | |
6002 | /* Allow VF to process pending reset notification */ | |
6003 | msleep(20); | |
6004 | i40e_reset_vf(vf, false); | |
6005 | } | |
6006 | } | |
6007 | ||
55a5e60b | 6008 | /** |
12957388 ASJ |
6009 | * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters |
6010 | * @pf: board private structure | |
6011 | **/ | |
04294e38 | 6012 | u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf) |
12957388 | 6013 | { |
04294e38 | 6014 | u32 val, fcnt_prog; |
12957388 ASJ |
6015 | |
6016 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); | |
6017 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK); | |
6018 | return fcnt_prog; | |
6019 | } | |
6020 | ||
6021 | /** | |
04294e38 | 6022 | * i40e_get_current_fd_count - Get total FD filters programmed for this PF |
55a5e60b ASJ |
6023 | * @pf: board private structure |
6024 | **/ | |
04294e38 | 6025 | u32 i40e_get_current_fd_count(struct i40e_pf *pf) |
55a5e60b | 6026 | { |
04294e38 ASJ |
6027 | u32 val, fcnt_prog; |
6028 | ||
55a5e60b ASJ |
6029 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
6030 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + | |
6031 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> | |
6032 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); | |
6033 | return fcnt_prog; | |
6034 | } | |
1e1be8f6 | 6035 | |
04294e38 ASJ |
6036 | /** |
6037 | * i40e_get_global_fd_count - Get total FD filters programmed on device | |
6038 | * @pf: board private structure | |
6039 | **/ | |
6040 | u32 i40e_get_global_fd_count(struct i40e_pf *pf) | |
6041 | { | |
6042 | u32 val, fcnt_prog; | |
6043 | ||
6044 | val = rd32(&pf->hw, I40E_GLQF_FDCNT_0); | |
6045 | fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) + | |
6046 | ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >> | |
6047 | I40E_GLQF_FDCNT_0_BESTCNT_SHIFT); | |
6048 | return fcnt_prog; | |
6049 | } | |
6050 | ||
55a5e60b ASJ |
6051 | /** |
6052 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled | |
6053 | * @pf: board private structure | |
6054 | **/ | |
6055 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) | |
6056 | { | |
3487b6c3 | 6057 | struct i40e_fdir_filter *filter; |
55a5e60b | 6058 | u32 fcnt_prog, fcnt_avail; |
3487b6c3 | 6059 | struct hlist_node *node; |
55a5e60b | 6060 | |
1e1be8f6 ASJ |
6061 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
6062 | return; | |
6063 | ||
55a5e60b ASJ |
6064 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
6065 | * to re-enable | |
6066 | */ | |
04294e38 | 6067 | fcnt_prog = i40e_get_global_fd_count(pf); |
12957388 | 6068 | fcnt_avail = pf->fdir_pf_filter_count; |
1e1be8f6 ASJ |
6069 | if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) || |
6070 | (pf->fd_add_err == 0) || | |
6071 | (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) { | |
55a5e60b | 6072 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
b77ac975 HR |
6073 | (pf->hw_disabled_flags & I40E_FLAG_FD_SB_ENABLED)) { |
6074 | pf->hw_disabled_flags &= ~I40E_FLAG_FD_SB_ENABLED; | |
2e4875e3 ASJ |
6075 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
6076 | dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n"); | |
55a5e60b ASJ |
6077 | } |
6078 | } | |
a3417d28 JK |
6079 | |
6080 | /* Wait for some more space to be available to turn on ATR. We also | |
6081 | * must check that no existing ntuple rules for TCP are in effect | |
6082 | */ | |
55a5e60b ASJ |
6083 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
6084 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && | |
b77ac975 | 6085 | (pf->hw_disabled_flags & I40E_FLAG_FD_ATR_ENABLED) && |
097dbf52 | 6086 | (pf->fd_tcp4_filter_cnt == 0)) { |
b77ac975 | 6087 | pf->hw_disabled_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
2e4875e3 | 6088 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
a3417d28 | 6089 | dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n"); |
55a5e60b ASJ |
6090 | } |
6091 | } | |
3487b6c3 CW |
6092 | |
6093 | /* if hw had a problem adding a filter, delete it */ | |
6094 | if (pf->fd_inv > 0) { | |
6095 | hlist_for_each_entry_safe(filter, node, | |
6096 | &pf->fdir_filter_list, fdir_node) { | |
6097 | if (filter->fd_id == pf->fd_inv) { | |
6098 | hlist_del(&filter->fdir_node); | |
6099 | kfree(filter); | |
6100 | pf->fdir_pf_active_filters--; | |
6101 | } | |
6102 | } | |
6103 | } | |
55a5e60b ASJ |
6104 | } |
6105 | ||
1e1be8f6 | 6106 | #define I40E_MIN_FD_FLUSH_INTERVAL 10 |
04294e38 | 6107 | #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30 |
1e1be8f6 ASJ |
6108 | /** |
6109 | * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB | |
6110 | * @pf: board private structure | |
6111 | **/ | |
6112 | static void i40e_fdir_flush_and_replay(struct i40e_pf *pf) | |
6113 | { | |
04294e38 | 6114 | unsigned long min_flush_time; |
1e1be8f6 | 6115 | int flush_wait_retry = 50; |
04294e38 ASJ |
6116 | bool disable_atr = false; |
6117 | int fd_room; | |
1e1be8f6 ASJ |
6118 | int reg; |
6119 | ||
a5fdaf34 JB |
6120 | if (!time_after(jiffies, pf->fd_flush_timestamp + |
6121 | (I40E_MIN_FD_FLUSH_INTERVAL * HZ))) | |
6122 | return; | |
04294e38 | 6123 | |
a5fdaf34 JB |
6124 | /* If the flush is happening too quick and we have mostly SB rules we |
6125 | * should not re-enable ATR for some time. | |
6126 | */ | |
6127 | min_flush_time = pf->fd_flush_timestamp + | |
6128 | (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ); | |
6129 | fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters; | |
6130 | ||
6131 | if (!(time_after(jiffies, min_flush_time)) && | |
6132 | (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) { | |
6133 | if (I40E_DEBUG_FD & pf->hw.debug_mask) | |
6134 | dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n"); | |
6135 | disable_atr = true; | |
6136 | } | |
6137 | ||
6138 | pf->fd_flush_timestamp = jiffies; | |
b77ac975 | 6139 | pf->hw_disabled_flags |= I40E_FLAG_FD_ATR_ENABLED; |
a5fdaf34 JB |
6140 | /* flush all filters */ |
6141 | wr32(&pf->hw, I40E_PFQF_CTL_1, | |
6142 | I40E_PFQF_CTL_1_CLEARFDTABLE_MASK); | |
6143 | i40e_flush(&pf->hw); | |
6144 | pf->fd_flush_cnt++; | |
6145 | pf->fd_add_err = 0; | |
6146 | do { | |
6147 | /* Check FD flush status every 5-6msec */ | |
6148 | usleep_range(5000, 6000); | |
6149 | reg = rd32(&pf->hw, I40E_PFQF_CTL_1); | |
6150 | if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK)) | |
6151 | break; | |
6152 | } while (flush_wait_retry--); | |
6153 | if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) { | |
6154 | dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n"); | |
6155 | } else { | |
6156 | /* replay sideband filters */ | |
6157 | i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]); | |
097dbf52 | 6158 | if (!disable_atr && !pf->fd_tcp4_filter_cnt) |
b77ac975 | 6159 | pf->hw_disabled_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
a5fdaf34 JB |
6160 | clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
6161 | if (I40E_DEBUG_FD & pf->hw.debug_mask) | |
6162 | dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n"); | |
1e1be8f6 ASJ |
6163 | } |
6164 | } | |
6165 | ||
6166 | /** | |
6167 | * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed | |
6168 | * @pf: board private structure | |
6169 | **/ | |
04294e38 | 6170 | u32 i40e_get_current_atr_cnt(struct i40e_pf *pf) |
1e1be8f6 ASJ |
6171 | { |
6172 | return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters; | |
6173 | } | |
6174 | ||
6175 | /* We can see up to 256 filter programming desc in transit if the filters are | |
6176 | * being applied really fast; before we see the first | |
6177 | * filter miss error on Rx queue 0. Accumulating enough error messages before | |
6178 | * reacting will make sure we don't cause flush too often. | |
6179 | */ | |
6180 | #define I40E_MAX_FD_PROGRAM_ERROR 256 | |
6181 | ||
41c445ff JB |
6182 | /** |
6183 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table | |
6184 | * @pf: board private structure | |
6185 | **/ | |
6186 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) | |
6187 | { | |
41c445ff | 6188 | |
41c445ff JB |
6189 | /* if interface is down do nothing */ |
6190 | if (test_bit(__I40E_DOWN, &pf->state)) | |
6191 | return; | |
1e1be8f6 | 6192 | |
04294e38 | 6193 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
1e1be8f6 ASJ |
6194 | i40e_fdir_flush_and_replay(pf); |
6195 | ||
55a5e60b ASJ |
6196 | i40e_fdir_check_and_reenable(pf); |
6197 | ||
41c445ff JB |
6198 | } |
6199 | ||
6200 | /** | |
6201 | * i40e_vsi_link_event - notify VSI of a link event | |
6202 | * @vsi: vsi to be notified | |
6203 | * @link_up: link up or down | |
6204 | **/ | |
6205 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) | |
6206 | { | |
32b5b811 | 6207 | if (!vsi || test_bit(__I40E_DOWN, &vsi->state)) |
41c445ff JB |
6208 | return; |
6209 | ||
6210 | switch (vsi->type) { | |
6211 | case I40E_VSI_MAIN: | |
6212 | if (!vsi->netdev || !vsi->netdev_registered) | |
6213 | break; | |
6214 | ||
6215 | if (link_up) { | |
6216 | netif_carrier_on(vsi->netdev); | |
6217 | netif_tx_wake_all_queues(vsi->netdev); | |
6218 | } else { | |
6219 | netif_carrier_off(vsi->netdev); | |
6220 | netif_tx_stop_all_queues(vsi->netdev); | |
6221 | } | |
6222 | break; | |
6223 | ||
6224 | case I40E_VSI_SRIOV: | |
41c445ff JB |
6225 | case I40E_VSI_VMDQ2: |
6226 | case I40E_VSI_CTRL: | |
e3219ce6 | 6227 | case I40E_VSI_IWARP: |
41c445ff JB |
6228 | case I40E_VSI_MIRROR: |
6229 | default: | |
6230 | /* there is no notification for other VSIs */ | |
6231 | break; | |
6232 | } | |
6233 | } | |
6234 | ||
6235 | /** | |
6236 | * i40e_veb_link_event - notify elements on the veb of a link event | |
6237 | * @veb: veb to be notified | |
6238 | * @link_up: link up or down | |
6239 | **/ | |
6240 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) | |
6241 | { | |
6242 | struct i40e_pf *pf; | |
6243 | int i; | |
6244 | ||
6245 | if (!veb || !veb->pf) | |
6246 | return; | |
6247 | pf = veb->pf; | |
6248 | ||
6249 | /* depth first... */ | |
6250 | for (i = 0; i < I40E_MAX_VEB; i++) | |
6251 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) | |
6252 | i40e_veb_link_event(pf->veb[i], link_up); | |
6253 | ||
6254 | /* ... now the local VSIs */ | |
505682cd | 6255 | for (i = 0; i < pf->num_alloc_vsi; i++) |
41c445ff JB |
6256 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
6257 | i40e_vsi_link_event(pf->vsi[i], link_up); | |
6258 | } | |
6259 | ||
6260 | /** | |
6261 | * i40e_link_event - Update netif_carrier status | |
6262 | * @pf: board private structure | |
6263 | **/ | |
6264 | static void i40e_link_event(struct i40e_pf *pf) | |
6265 | { | |
320684cd | 6266 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
fef59ddf | 6267 | u8 new_link_speed, old_link_speed; |
a72a5abc JB |
6268 | i40e_status status; |
6269 | bool new_link, old_link; | |
41c445ff | 6270 | |
1f9610e4 CS |
6271 | /* save off old link status information */ |
6272 | pf->hw.phy.link_info_old = pf->hw.phy.link_info; | |
6273 | ||
1e701e09 JB |
6274 | /* set this to force the get_link_status call to refresh state */ |
6275 | pf->hw.phy.get_link_info = true; | |
6276 | ||
41c445ff | 6277 | old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP); |
a72a5abc JB |
6278 | |
6279 | status = i40e_get_link_status(&pf->hw, &new_link); | |
ae136708 HR |
6280 | |
6281 | /* On success, disable temp link polling */ | |
6282 | if (status == I40E_SUCCESS) { | |
6283 | if (pf->flags & I40E_FLAG_TEMP_LINK_POLLING) | |
6284 | pf->flags &= ~I40E_FLAG_TEMP_LINK_POLLING; | |
6285 | } else { | |
6286 | /* Enable link polling temporarily until i40e_get_link_status | |
6287 | * returns I40E_SUCCESS | |
6288 | */ | |
6289 | pf->flags |= I40E_FLAG_TEMP_LINK_POLLING; | |
a72a5abc JB |
6290 | dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n", |
6291 | status); | |
6292 | return; | |
6293 | } | |
6294 | ||
fef59ddf CS |
6295 | old_link_speed = pf->hw.phy.link_info_old.link_speed; |
6296 | new_link_speed = pf->hw.phy.link_info.link_speed; | |
41c445ff | 6297 | |
1e701e09 | 6298 | if (new_link == old_link && |
fef59ddf | 6299 | new_link_speed == old_link_speed && |
320684cd MW |
6300 | (test_bit(__I40E_DOWN, &vsi->state) || |
6301 | new_link == netif_carrier_ok(vsi->netdev))) | |
41c445ff | 6302 | return; |
320684cd MW |
6303 | |
6304 | if (!test_bit(__I40E_DOWN, &vsi->state)) | |
6305 | i40e_print_link_message(vsi, new_link); | |
41c445ff JB |
6306 | |
6307 | /* Notify the base of the switch tree connected to | |
6308 | * the link. Floating VEBs are not notified. | |
6309 | */ | |
6310 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) | |
6311 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); | |
6312 | else | |
320684cd | 6313 | i40e_vsi_link_event(vsi, new_link); |
41c445ff JB |
6314 | |
6315 | if (pf->vf) | |
6316 | i40e_vc_notify_link_state(pf); | |
beb0dff1 JK |
6317 | |
6318 | if (pf->flags & I40E_FLAG_PTP) | |
6319 | i40e_ptp_set_increment(pf); | |
41c445ff JB |
6320 | } |
6321 | ||
41c445ff | 6322 | /** |
21536717 | 6323 | * i40e_watchdog_subtask - periodic checks not using event driven response |
41c445ff JB |
6324 | * @pf: board private structure |
6325 | **/ | |
6326 | static void i40e_watchdog_subtask(struct i40e_pf *pf) | |
6327 | { | |
6328 | int i; | |
6329 | ||
6330 | /* if interface is down do nothing */ | |
6331 | if (test_bit(__I40E_DOWN, &pf->state) || | |
6332 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) | |
6333 | return; | |
6334 | ||
21536717 SN |
6335 | /* make sure we don't do these things too often */ |
6336 | if (time_before(jiffies, (pf->service_timer_previous + | |
6337 | pf->service_timer_period))) | |
6338 | return; | |
6339 | pf->service_timer_previous = jiffies; | |
6340 | ||
ae136708 HR |
6341 | if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) || |
6342 | (pf->flags & I40E_FLAG_TEMP_LINK_POLLING)) | |
9ac77266 | 6343 | i40e_link_event(pf); |
21536717 | 6344 | |
41c445ff JB |
6345 | /* Update the stats for active netdevs so the network stack |
6346 | * can look at updated numbers whenever it cares to | |
6347 | */ | |
505682cd | 6348 | for (i = 0; i < pf->num_alloc_vsi; i++) |
41c445ff JB |
6349 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
6350 | i40e_update_stats(pf->vsi[i]); | |
6351 | ||
d1a8d275 ASJ |
6352 | if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) { |
6353 | /* Update the stats for the active switching components */ | |
6354 | for (i = 0; i < I40E_MAX_VEB; i++) | |
6355 | if (pf->veb[i]) | |
6356 | i40e_update_veb_stats(pf->veb[i]); | |
6357 | } | |
beb0dff1 JK |
6358 | |
6359 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); | |
41c445ff JB |
6360 | } |
6361 | ||
6362 | /** | |
6363 | * i40e_reset_subtask - Set up for resetting the device and driver | |
6364 | * @pf: board private structure | |
6365 | **/ | |
6366 | static void i40e_reset_subtask(struct i40e_pf *pf) | |
6367 | { | |
6368 | u32 reset_flags = 0; | |
6369 | ||
6370 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { | |
75f5cea9 | 6371 | reset_flags |= BIT(__I40E_REINIT_REQUESTED); |
41c445ff JB |
6372 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
6373 | } | |
6374 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { | |
75f5cea9 | 6375 | reset_flags |= BIT(__I40E_PF_RESET_REQUESTED); |
41c445ff JB |
6376 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
6377 | } | |
6378 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { | |
75f5cea9 | 6379 | reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED); |
41c445ff JB |
6380 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
6381 | } | |
6382 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { | |
75f5cea9 | 6383 | reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED); |
41c445ff JB |
6384 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
6385 | } | |
b5d06f05 | 6386 | if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) { |
75f5cea9 | 6387 | reset_flags |= BIT(__I40E_DOWN_REQUESTED); |
b5d06f05 NP |
6388 | clear_bit(__I40E_DOWN_REQUESTED, &pf->state); |
6389 | } | |
41c445ff JB |
6390 | |
6391 | /* If there's a recovery already waiting, it takes | |
6392 | * precedence before starting a new reset sequence. | |
6393 | */ | |
6394 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { | |
373149fc MS |
6395 | i40e_prep_for_reset(pf, false); |
6396 | i40e_reset(pf); | |
6397 | i40e_rebuild(pf, false, false); | |
41c445ff JB |
6398 | } |
6399 | ||
6400 | /* If we're already down or resetting, just bail */ | |
6401 | if (reset_flags && | |
6402 | !test_bit(__I40E_DOWN, &pf->state) && | |
373149fc MS |
6403 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) { |
6404 | rtnl_lock(); | |
6405 | i40e_do_reset(pf, reset_flags, true); | |
6406 | rtnl_unlock(); | |
6407 | } | |
41c445ff JB |
6408 | } |
6409 | ||
6410 | /** | |
6411 | * i40e_handle_link_event - Handle link event | |
6412 | * @pf: board private structure | |
6413 | * @e: event info posted on ARQ | |
6414 | **/ | |
6415 | static void i40e_handle_link_event(struct i40e_pf *pf, | |
6416 | struct i40e_arq_event_info *e) | |
6417 | { | |
41c445ff JB |
6418 | struct i40e_aqc_get_link_status *status = |
6419 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; | |
41c445ff | 6420 | |
1e701e09 JB |
6421 | /* Do a new status request to re-enable LSE reporting |
6422 | * and load new status information into the hw struct | |
6423 | * This completely ignores any state information | |
6424 | * in the ARQ event info, instead choosing to always | |
6425 | * issue the AQ update link status command. | |
6426 | */ | |
6427 | i40e_link_event(pf); | |
6428 | ||
7b592f61 CW |
6429 | /* check for unqualified module, if link is down */ |
6430 | if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) && | |
6431 | (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) && | |
6432 | (!(status->link_info & I40E_AQ_LINK_UP))) | |
6433 | dev_err(&pf->pdev->dev, | |
6434 | "The driver failed to link because an unqualified module was detected.\n"); | |
41c445ff JB |
6435 | } |
6436 | ||
6437 | /** | |
6438 | * i40e_clean_adminq_subtask - Clean the AdminQ rings | |
6439 | * @pf: board private structure | |
6440 | **/ | |
6441 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) | |
6442 | { | |
6443 | struct i40e_arq_event_info event; | |
6444 | struct i40e_hw *hw = &pf->hw; | |
6445 | u16 pending, i = 0; | |
6446 | i40e_status ret; | |
6447 | u16 opcode; | |
86df242b | 6448 | u32 oldval; |
41c445ff JB |
6449 | u32 val; |
6450 | ||
a316f651 ASJ |
6451 | /* Do not run clean AQ when PF reset fails */ |
6452 | if (test_bit(__I40E_RESET_FAILED, &pf->state)) | |
6453 | return; | |
6454 | ||
86df242b SN |
6455 | /* check for error indications */ |
6456 | val = rd32(&pf->hw, pf->hw.aq.arq.len); | |
6457 | oldval = val; | |
6458 | if (val & I40E_PF_ARQLEN_ARQVFE_MASK) { | |
75eb73c1 MW |
6459 | if (hw->debug_mask & I40E_DEBUG_AQ) |
6460 | dev_info(&pf->pdev->dev, "ARQ VF Error detected\n"); | |
86df242b SN |
6461 | val &= ~I40E_PF_ARQLEN_ARQVFE_MASK; |
6462 | } | |
6463 | if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) { | |
75eb73c1 MW |
6464 | if (hw->debug_mask & I40E_DEBUG_AQ) |
6465 | dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n"); | |
86df242b | 6466 | val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK; |
1d0a4ada | 6467 | pf->arq_overflows++; |
86df242b SN |
6468 | } |
6469 | if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) { | |
75eb73c1 MW |
6470 | if (hw->debug_mask & I40E_DEBUG_AQ) |
6471 | dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n"); | |
86df242b SN |
6472 | val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK; |
6473 | } | |
6474 | if (oldval != val) | |
6475 | wr32(&pf->hw, pf->hw.aq.arq.len, val); | |
6476 | ||
6477 | val = rd32(&pf->hw, pf->hw.aq.asq.len); | |
6478 | oldval = val; | |
6479 | if (val & I40E_PF_ATQLEN_ATQVFE_MASK) { | |
75eb73c1 MW |
6480 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
6481 | dev_info(&pf->pdev->dev, "ASQ VF Error detected\n"); | |
86df242b SN |
6482 | val &= ~I40E_PF_ATQLEN_ATQVFE_MASK; |
6483 | } | |
6484 | if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) { | |
75eb73c1 MW |
6485 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
6486 | dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n"); | |
86df242b SN |
6487 | val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK; |
6488 | } | |
6489 | if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) { | |
75eb73c1 MW |
6490 | if (pf->hw.debug_mask & I40E_DEBUG_AQ) |
6491 | dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n"); | |
86df242b SN |
6492 | val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK; |
6493 | } | |
6494 | if (oldval != val) | |
6495 | wr32(&pf->hw, pf->hw.aq.asq.len, val); | |
6496 | ||
1001dc37 MW |
6497 | event.buf_len = I40E_MAX_AQ_BUF_SIZE; |
6498 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); | |
41c445ff JB |
6499 | if (!event.msg_buf) |
6500 | return; | |
6501 | ||
6502 | do { | |
6503 | ret = i40e_clean_arq_element(hw, &event, &pending); | |
56497978 | 6504 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
41c445ff | 6505 | break; |
56497978 | 6506 | else if (ret) { |
41c445ff JB |
6507 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
6508 | break; | |
6509 | } | |
6510 | ||
6511 | opcode = le16_to_cpu(event.desc.opcode); | |
6512 | switch (opcode) { | |
6513 | ||
6514 | case i40e_aqc_opc_get_link_status: | |
6515 | i40e_handle_link_event(pf, &event); | |
6516 | break; | |
6517 | case i40e_aqc_opc_send_msg_to_pf: | |
6518 | ret = i40e_vc_process_vf_msg(pf, | |
6519 | le16_to_cpu(event.desc.retval), | |
6520 | le32_to_cpu(event.desc.cookie_high), | |
6521 | le32_to_cpu(event.desc.cookie_low), | |
6522 | event.msg_buf, | |
1001dc37 | 6523 | event.msg_len); |
41c445ff JB |
6524 | break; |
6525 | case i40e_aqc_opc_lldp_update_mib: | |
69bfb110 | 6526 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
4e3b35b0 NP |
6527 | #ifdef CONFIG_I40E_DCB |
6528 | rtnl_lock(); | |
6529 | ret = i40e_handle_lldp_event(pf, &event); | |
6530 | rtnl_unlock(); | |
6531 | #endif /* CONFIG_I40E_DCB */ | |
41c445ff JB |
6532 | break; |
6533 | case i40e_aqc_opc_event_lan_overflow: | |
69bfb110 | 6534 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
41c445ff JB |
6535 | i40e_handle_lan_overflow_event(pf, &event); |
6536 | break; | |
0467bc91 SN |
6537 | case i40e_aqc_opc_send_msg_to_peer: |
6538 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); | |
6539 | break; | |
91a0f930 SN |
6540 | case i40e_aqc_opc_nvm_erase: |
6541 | case i40e_aqc_opc_nvm_update: | |
00ada50d | 6542 | case i40e_aqc_opc_oem_post_update: |
6e93d0c9 SN |
6543 | i40e_debug(&pf->hw, I40E_DEBUG_NVM, |
6544 | "ARQ NVM operation 0x%04x completed\n", | |
6545 | opcode); | |
91a0f930 | 6546 | break; |
41c445ff JB |
6547 | default: |
6548 | dev_info(&pf->pdev->dev, | |
56e5ca68 | 6549 | "ARQ: Unknown event 0x%04x ignored\n", |
0467bc91 | 6550 | opcode); |
41c445ff JB |
6551 | break; |
6552 | } | |
1fca3265 CB |
6553 | } while (i++ < pf->adminq_work_limit); |
6554 | ||
6555 | if (i < pf->adminq_work_limit) | |
6556 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); | |
41c445ff | 6557 | |
41c445ff JB |
6558 | /* re-enable Admin queue interrupt cause */ |
6559 | val = rd32(hw, I40E_PFINT_ICR0_ENA); | |
6560 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; | |
6561 | wr32(hw, I40E_PFINT_ICR0_ENA, val); | |
6562 | i40e_flush(hw); | |
6563 | ||
6564 | kfree(event.msg_buf); | |
6565 | } | |
6566 | ||
4eb3f768 SN |
6567 | /** |
6568 | * i40e_verify_eeprom - make sure eeprom is good to use | |
6569 | * @pf: board private structure | |
6570 | **/ | |
6571 | static void i40e_verify_eeprom(struct i40e_pf *pf) | |
6572 | { | |
6573 | int err; | |
6574 | ||
6575 | err = i40e_diag_eeprom_test(&pf->hw); | |
6576 | if (err) { | |
6577 | /* retry in case of garbage read */ | |
6578 | err = i40e_diag_eeprom_test(&pf->hw); | |
6579 | if (err) { | |
6580 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", | |
6581 | err); | |
6582 | set_bit(__I40E_BAD_EEPROM, &pf->state); | |
6583 | } | |
6584 | } | |
6585 | ||
6586 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { | |
6587 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); | |
6588 | clear_bit(__I40E_BAD_EEPROM, &pf->state); | |
6589 | } | |
6590 | } | |
6591 | ||
386a0afa AA |
6592 | /** |
6593 | * i40e_enable_pf_switch_lb | |
b40c82e6 | 6594 | * @pf: pointer to the PF structure |
386a0afa AA |
6595 | * |
6596 | * enable switch loop back or die - no point in a return value | |
6597 | **/ | |
6598 | static void i40e_enable_pf_switch_lb(struct i40e_pf *pf) | |
6599 | { | |
6600 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; | |
6601 | struct i40e_vsi_context ctxt; | |
f1c7e72e | 6602 | int ret; |
386a0afa AA |
6603 | |
6604 | ctxt.seid = pf->main_vsi_seid; | |
6605 | ctxt.pf_num = pf->hw.pf_id; | |
6606 | ctxt.vf_num = 0; | |
f1c7e72e SN |
6607 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
6608 | if (ret) { | |
386a0afa | 6609 | dev_info(&pf->pdev->dev, |
f1c7e72e SN |
6610 | "couldn't get PF vsi config, err %s aq_err %s\n", |
6611 | i40e_stat_str(&pf->hw, ret), | |
6612 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
386a0afa AA |
6613 | return; |
6614 | } | |
6615 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; | |
6616 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); | |
6617 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); | |
6618 | ||
f1c7e72e SN |
6619 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
6620 | if (ret) { | |
386a0afa | 6621 | dev_info(&pf->pdev->dev, |
f1c7e72e SN |
6622 | "update vsi switch failed, err %s aq_err %s\n", |
6623 | i40e_stat_str(&pf->hw, ret), | |
6624 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
386a0afa AA |
6625 | } |
6626 | } | |
6627 | ||
6628 | /** | |
6629 | * i40e_disable_pf_switch_lb | |
b40c82e6 | 6630 | * @pf: pointer to the PF structure |
386a0afa AA |
6631 | * |
6632 | * disable switch loop back or die - no point in a return value | |
6633 | **/ | |
6634 | static void i40e_disable_pf_switch_lb(struct i40e_pf *pf) | |
6635 | { | |
6636 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; | |
6637 | struct i40e_vsi_context ctxt; | |
f1c7e72e | 6638 | int ret; |
386a0afa AA |
6639 | |
6640 | ctxt.seid = pf->main_vsi_seid; | |
6641 | ctxt.pf_num = pf->hw.pf_id; | |
6642 | ctxt.vf_num = 0; | |
f1c7e72e SN |
6643 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
6644 | if (ret) { | |
386a0afa | 6645 | dev_info(&pf->pdev->dev, |
f1c7e72e SN |
6646 | "couldn't get PF vsi config, err %s aq_err %s\n", |
6647 | i40e_stat_str(&pf->hw, ret), | |
6648 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
386a0afa AA |
6649 | return; |
6650 | } | |
6651 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; | |
6652 | ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); | |
6653 | ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); | |
6654 | ||
f1c7e72e SN |
6655 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
6656 | if (ret) { | |
386a0afa | 6657 | dev_info(&pf->pdev->dev, |
f1c7e72e SN |
6658 | "update vsi switch failed, err %s aq_err %s\n", |
6659 | i40e_stat_str(&pf->hw, ret), | |
6660 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
386a0afa AA |
6661 | } |
6662 | } | |
6663 | ||
51616018 NP |
6664 | /** |
6665 | * i40e_config_bridge_mode - Configure the HW bridge mode | |
6666 | * @veb: pointer to the bridge instance | |
6667 | * | |
6668 | * Configure the loop back mode for the LAN VSI that is downlink to the | |
6669 | * specified HW bridge instance. It is expected this function is called | |
6670 | * when a new HW bridge is instantiated. | |
6671 | **/ | |
6672 | static void i40e_config_bridge_mode(struct i40e_veb *veb) | |
6673 | { | |
6674 | struct i40e_pf *pf = veb->pf; | |
6675 | ||
6dec1017 SN |
6676 | if (pf->hw.debug_mask & I40E_DEBUG_LAN) |
6677 | dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n", | |
6678 | veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); | |
51616018 NP |
6679 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) |
6680 | i40e_disable_pf_switch_lb(pf); | |
6681 | else | |
6682 | i40e_enable_pf_switch_lb(pf); | |
6683 | } | |
6684 | ||
41c445ff JB |
6685 | /** |
6686 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it | |
6687 | * @veb: pointer to the VEB instance | |
6688 | * | |
6689 | * This is a recursive function that first builds the attached VSIs then | |
6690 | * recurses in to build the next layer of VEB. We track the connections | |
6691 | * through our own index numbers because the seid's from the HW could | |
6692 | * change across the reset. | |
6693 | **/ | |
6694 | static int i40e_reconstitute_veb(struct i40e_veb *veb) | |
6695 | { | |
6696 | struct i40e_vsi *ctl_vsi = NULL; | |
6697 | struct i40e_pf *pf = veb->pf; | |
6698 | int v, veb_idx; | |
6699 | int ret; | |
6700 | ||
6701 | /* build VSI that owns this VEB, temporarily attached to base VEB */ | |
505682cd | 6702 | for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) { |
41c445ff JB |
6703 | if (pf->vsi[v] && |
6704 | pf->vsi[v]->veb_idx == veb->idx && | |
6705 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { | |
6706 | ctl_vsi = pf->vsi[v]; | |
6707 | break; | |
6708 | } | |
6709 | } | |
6710 | if (!ctl_vsi) { | |
6711 | dev_info(&pf->pdev->dev, | |
6712 | "missing owner VSI for veb_idx %d\n", veb->idx); | |
6713 | ret = -ENOENT; | |
6714 | goto end_reconstitute; | |
6715 | } | |
6716 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) | |
6717 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; | |
6718 | ret = i40e_add_vsi(ctl_vsi); | |
6719 | if (ret) { | |
6720 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
6721 | "rebuild of veb_idx %d owner VSI failed: %d\n", |
6722 | veb->idx, ret); | |
41c445ff JB |
6723 | goto end_reconstitute; |
6724 | } | |
6725 | i40e_vsi_reset_stats(ctl_vsi); | |
6726 | ||
6727 | /* create the VEB in the switch and move the VSI onto the VEB */ | |
6728 | ret = i40e_add_veb(veb, ctl_vsi); | |
6729 | if (ret) | |
6730 | goto end_reconstitute; | |
6731 | ||
fc60861e ASJ |
6732 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
6733 | veb->bridge_mode = BRIDGE_MODE_VEB; | |
6734 | else | |
6735 | veb->bridge_mode = BRIDGE_MODE_VEPA; | |
51616018 | 6736 | i40e_config_bridge_mode(veb); |
b64ba084 | 6737 | |
41c445ff | 6738 | /* create the remaining VSIs attached to this VEB */ |
505682cd | 6739 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
41c445ff JB |
6740 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
6741 | continue; | |
6742 | ||
6743 | if (pf->vsi[v]->veb_idx == veb->idx) { | |
6744 | struct i40e_vsi *vsi = pf->vsi[v]; | |
6995b36c | 6745 | |
41c445ff JB |
6746 | vsi->uplink_seid = veb->seid; |
6747 | ret = i40e_add_vsi(vsi); | |
6748 | if (ret) { | |
6749 | dev_info(&pf->pdev->dev, | |
6750 | "rebuild of vsi_idx %d failed: %d\n", | |
6751 | v, ret); | |
6752 | goto end_reconstitute; | |
6753 | } | |
6754 | i40e_vsi_reset_stats(vsi); | |
6755 | } | |
6756 | } | |
6757 | ||
6758 | /* create any VEBs attached to this VEB - RECURSION */ | |
6759 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { | |
6760 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { | |
6761 | pf->veb[veb_idx]->uplink_seid = veb->seid; | |
6762 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); | |
6763 | if (ret) | |
6764 | break; | |
6765 | } | |
6766 | } | |
6767 | ||
6768 | end_reconstitute: | |
6769 | return ret; | |
6770 | } | |
6771 | ||
6772 | /** | |
6773 | * i40e_get_capabilities - get info about the HW | |
6774 | * @pf: the PF struct | |
6775 | **/ | |
6776 | static int i40e_get_capabilities(struct i40e_pf *pf) | |
6777 | { | |
6778 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; | |
6779 | u16 data_size; | |
6780 | int buf_len; | |
6781 | int err; | |
6782 | ||
6783 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); | |
6784 | do { | |
6785 | cap_buf = kzalloc(buf_len, GFP_KERNEL); | |
6786 | if (!cap_buf) | |
6787 | return -ENOMEM; | |
6788 | ||
6789 | /* this loads the data into the hw struct for us */ | |
6790 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, | |
6791 | &data_size, | |
6792 | i40e_aqc_opc_list_func_capabilities, | |
6793 | NULL); | |
6794 | /* data loaded, buffer no longer needed */ | |
6795 | kfree(cap_buf); | |
6796 | ||
6797 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { | |
6798 | /* retry with a larger buffer */ | |
6799 | buf_len = data_size; | |
6800 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { | |
6801 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
6802 | "capability discovery failed, err %s aq_err %s\n", |
6803 | i40e_stat_str(&pf->hw, err), | |
6804 | i40e_aq_str(&pf->hw, | |
6805 | pf->hw.aq.asq_last_status)); | |
41c445ff JB |
6806 | return -ENODEV; |
6807 | } | |
6808 | } while (err); | |
6809 | ||
6810 | if (pf->hw.debug_mask & I40E_DEBUG_USER) | |
6811 | dev_info(&pf->pdev->dev, | |
6812 | "pf=%d, num_vfs=%d, msix_pf=%d, msix_vf=%d, fd_g=%d, fd_b=%d, pf_max_q=%d num_vsi=%d\n", | |
6813 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, | |
6814 | pf->hw.func_caps.num_msix_vectors, | |
6815 | pf->hw.func_caps.num_msix_vectors_vf, | |
6816 | pf->hw.func_caps.fd_filters_guaranteed, | |
6817 | pf->hw.func_caps.fd_filters_best_effort, | |
6818 | pf->hw.func_caps.num_tx_qp, | |
6819 | pf->hw.func_caps.num_vsis); | |
6820 | ||
7134f9ce JB |
6821 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
6822 | + pf->hw.func_caps.num_vfs) | |
6823 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { | |
6824 | dev_info(&pf->pdev->dev, | |
6825 | "got num_vsis %d, setting num_vsis to %d\n", | |
6826 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); | |
6827 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; | |
6828 | } | |
6829 | ||
41c445ff JB |
6830 | return 0; |
6831 | } | |
6832 | ||
cbf61325 ASJ |
6833 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
6834 | ||
41c445ff | 6835 | /** |
cbf61325 | 6836 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
41c445ff JB |
6837 | * @pf: board private structure |
6838 | **/ | |
cbf61325 | 6839 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
41c445ff JB |
6840 | { |
6841 | struct i40e_vsi *vsi; | |
41c445ff | 6842 | |
407e063c JB |
6843 | /* quick workaround for an NVM issue that leaves a critical register |
6844 | * uninitialized | |
6845 | */ | |
6846 | if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) { | |
6847 | static const u32 hkey[] = { | |
6848 | 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36, | |
6849 | 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb, | |
6850 | 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21, | |
6851 | 0x95b3a76d}; | |
4b816446 | 6852 | int i; |
407e063c JB |
6853 | |
6854 | for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++) | |
6855 | wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]); | |
6856 | } | |
6857 | ||
cbf61325 | 6858 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
41c445ff JB |
6859 | return; |
6860 | ||
cbf61325 | 6861 | /* find existing VSI and see if it needs configuring */ |
4b816446 | 6862 | vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); |
cbf61325 ASJ |
6863 | |
6864 | /* create a new VSI if none exists */ | |
41c445ff | 6865 | if (!vsi) { |
cbf61325 ASJ |
6866 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
6867 | pf->vsi[pf->lan_vsi]->seid, 0); | |
41c445ff JB |
6868 | if (!vsi) { |
6869 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); | |
8a9eb7d3 SN |
6870 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
6871 | return; | |
41c445ff | 6872 | } |
cbf61325 | 6873 | } |
41c445ff | 6874 | |
8a9eb7d3 | 6875 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
41c445ff JB |
6876 | } |
6877 | ||
6878 | /** | |
6879 | * i40e_fdir_teardown - release the Flow Director resources | |
6880 | * @pf: board private structure | |
6881 | **/ | |
6882 | static void i40e_fdir_teardown(struct i40e_pf *pf) | |
6883 | { | |
4b816446 | 6884 | struct i40e_vsi *vsi; |
41c445ff | 6885 | |
17a73f6b | 6886 | i40e_fdir_filter_exit(pf); |
4b816446 AD |
6887 | vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR); |
6888 | if (vsi) | |
6889 | i40e_vsi_release(vsi); | |
41c445ff JB |
6890 | } |
6891 | ||
6892 | /** | |
f650a38b | 6893 | * i40e_prep_for_reset - prep for the core to reset |
41c445ff | 6894 | * @pf: board private structure |
373149fc MS |
6895 | * @lock_acquired: indicates whether or not the lock has been acquired |
6896 | * before this function was called. | |
41c445ff | 6897 | * |
b40c82e6 | 6898 | * Close up the VFs and other things in prep for PF Reset. |
f650a38b | 6899 | **/ |
373149fc | 6900 | static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired) |
41c445ff | 6901 | { |
41c445ff | 6902 | struct i40e_hw *hw = &pf->hw; |
60442dea | 6903 | i40e_status ret = 0; |
41c445ff JB |
6904 | u32 v; |
6905 | ||
6906 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); | |
6907 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) | |
23cfbe07 | 6908 | return; |
d3ce5734 MW |
6909 | if (i40e_check_asq_alive(&pf->hw)) |
6910 | i40e_vc_notify_reset(pf); | |
41c445ff | 6911 | |
69bfb110 | 6912 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
41c445ff | 6913 | |
41c445ff | 6914 | /* quiesce the VSIs and their queues that are not already DOWN */ |
373149fc MS |
6915 | /* pf_quiesce_all_vsi modifies netdev structures -rtnl_lock needed */ |
6916 | if (!lock_acquired) | |
6917 | rtnl_lock(); | |
41c445ff | 6918 | i40e_pf_quiesce_all_vsi(pf); |
373149fc MS |
6919 | if (!lock_acquired) |
6920 | rtnl_unlock(); | |
41c445ff | 6921 | |
505682cd | 6922 | for (v = 0; v < pf->num_alloc_vsi; v++) { |
41c445ff JB |
6923 | if (pf->vsi[v]) |
6924 | pf->vsi[v]->seid = 0; | |
6925 | } | |
6926 | ||
6927 | i40e_shutdown_adminq(&pf->hw); | |
6928 | ||
f650a38b | 6929 | /* call shutdown HMC */ |
60442dea SN |
6930 | if (hw->hmc.hmc_obj) { |
6931 | ret = i40e_shutdown_lan_hmc(hw); | |
23cfbe07 | 6932 | if (ret) |
60442dea SN |
6933 | dev_warn(&pf->pdev->dev, |
6934 | "shutdown_lan_hmc failed: %d\n", ret); | |
f650a38b | 6935 | } |
f650a38b ASJ |
6936 | } |
6937 | ||
44033fac JB |
6938 | /** |
6939 | * i40e_send_version - update firmware with driver version | |
6940 | * @pf: PF struct | |
6941 | */ | |
6942 | static void i40e_send_version(struct i40e_pf *pf) | |
6943 | { | |
6944 | struct i40e_driver_version dv; | |
6945 | ||
6946 | dv.major_version = DRV_VERSION_MAJOR; | |
6947 | dv.minor_version = DRV_VERSION_MINOR; | |
6948 | dv.build_version = DRV_VERSION_BUILD; | |
6949 | dv.subbuild_version = 0; | |
35a7d804 | 6950 | strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
44033fac JB |
6951 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
6952 | } | |
6953 | ||
f650a38b | 6954 | /** |
373149fc | 6955 | * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen |
f650a38b ASJ |
6956 | * @pf: board private structure |
6957 | **/ | |
373149fc | 6958 | static int i40e_reset(struct i40e_pf *pf) |
f650a38b | 6959 | { |
f650a38b ASJ |
6960 | struct i40e_hw *hw = &pf->hw; |
6961 | i40e_status ret; | |
f650a38b | 6962 | |
41c445ff | 6963 | ret = i40e_pf_reset(hw); |
b5565400 | 6964 | if (ret) { |
41c445ff | 6965 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
a316f651 | 6966 | set_bit(__I40E_RESET_FAILED, &pf->state); |
373149fc MS |
6967 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
6968 | } else { | |
6969 | pf->pfr_count++; | |
b5565400 | 6970 | } |
373149fc MS |
6971 | return ret; |
6972 | } | |
6973 | ||
6974 | /** | |
6975 | * i40e_rebuild - rebuild using a saved config | |
6976 | * @pf: board private structure | |
6977 | * @reinit: if the Main VSI needs to re-initialized. | |
6978 | * @lock_acquired: indicates whether or not the lock has been acquired | |
6979 | * before this function was called. | |
6980 | **/ | |
6981 | static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired) | |
6982 | { | |
6983 | struct i40e_hw *hw = &pf->hw; | |
6984 | u8 set_fc_aq_fail = 0; | |
6985 | i40e_status ret; | |
6986 | u32 val; | |
6987 | int v; | |
41c445ff JB |
6988 | |
6989 | if (test_bit(__I40E_DOWN, &pf->state)) | |
a316f651 | 6990 | goto clear_recovery; |
69bfb110 | 6991 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
41c445ff JB |
6992 | |
6993 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ | |
6994 | ret = i40e_init_adminq(&pf->hw); | |
6995 | if (ret) { | |
f1c7e72e SN |
6996 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n", |
6997 | i40e_stat_str(&pf->hw, ret), | |
6998 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
a316f651 | 6999 | goto clear_recovery; |
41c445ff JB |
7000 | } |
7001 | ||
4eb3f768 | 7002 | /* re-verify the eeprom if we just had an EMP reset */ |
9df42d1a | 7003 | if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state)) |
4eb3f768 | 7004 | i40e_verify_eeprom(pf); |
4eb3f768 | 7005 | |
e78ac4bf | 7006 | i40e_clear_pxe_mode(hw); |
41c445ff | 7007 | ret = i40e_get_capabilities(pf); |
f1c7e72e | 7008 | if (ret) |
41c445ff | 7009 | goto end_core_reset; |
41c445ff | 7010 | |
41c445ff | 7011 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
c76cb6ed | 7012 | hw->func_caps.num_rx_qp, 0, 0); |
41c445ff JB |
7013 | if (ret) { |
7014 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); | |
7015 | goto end_core_reset; | |
7016 | } | |
7017 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); | |
7018 | if (ret) { | |
7019 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); | |
7020 | goto end_core_reset; | |
7021 | } | |
7022 | ||
4e3b35b0 NP |
7023 | #ifdef CONFIG_I40E_DCB |
7024 | ret = i40e_init_pf_dcb(pf); | |
7025 | if (ret) { | |
aebfc816 SN |
7026 | dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret); |
7027 | pf->flags &= ~I40E_FLAG_DCB_CAPABLE; | |
7028 | /* Continue without DCB enabled */ | |
4e3b35b0 NP |
7029 | } |
7030 | #endif /* CONFIG_I40E_DCB */ | |
41c445ff | 7031 | /* do basic switch setup */ |
373149fc MS |
7032 | if (!lock_acquired) |
7033 | rtnl_lock(); | |
bc7d338f | 7034 | ret = i40e_setup_pf_switch(pf, reinit); |
41c445ff | 7035 | if (ret) |
373149fc | 7036 | goto end_unlock; |
41c445ff | 7037 | |
2f0aff41 SN |
7038 | /* The driver only wants link up/down and module qualification |
7039 | * reports from firmware. Note the negative logic. | |
7e2453fe JB |
7040 | */ |
7041 | ret = i40e_aq_set_phy_int_mask(&pf->hw, | |
2f0aff41 | 7042 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
867a79e3 | 7043 | I40E_AQ_EVENT_MEDIA_NA | |
2f0aff41 | 7044 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
7e2453fe | 7045 | if (ret) |
f1c7e72e SN |
7046 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
7047 | i40e_stat_str(&pf->hw, ret), | |
7048 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
7e2453fe | 7049 | |
cafa2ee6 ASJ |
7050 | /* make sure our flow control settings are restored */ |
7051 | ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true); | |
7052 | if (ret) | |
8279e495 NP |
7053 | dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n", |
7054 | i40e_stat_str(&pf->hw, ret), | |
7055 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
cafa2ee6 | 7056 | |
41c445ff JB |
7057 | /* Rebuild the VSIs and VEBs that existed before reset. |
7058 | * They are still in our local switch element arrays, so only | |
7059 | * need to rebuild the switch model in the HW. | |
7060 | * | |
7061 | * If there were VEBs but the reconstitution failed, we'll try | |
7062 | * try to recover minimal use by getting the basic PF VSI working. | |
7063 | */ | |
7064 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { | |
69bfb110 | 7065 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
41c445ff JB |
7066 | /* find the one VEB connected to the MAC, and find orphans */ |
7067 | for (v = 0; v < I40E_MAX_VEB; v++) { | |
7068 | if (!pf->veb[v]) | |
7069 | continue; | |
7070 | ||
7071 | if (pf->veb[v]->uplink_seid == pf->mac_seid || | |
7072 | pf->veb[v]->uplink_seid == 0) { | |
7073 | ret = i40e_reconstitute_veb(pf->veb[v]); | |
7074 | ||
7075 | if (!ret) | |
7076 | continue; | |
7077 | ||
7078 | /* If Main VEB failed, we're in deep doodoo, | |
7079 | * so give up rebuilding the switch and set up | |
7080 | * for minimal rebuild of PF VSI. | |
7081 | * If orphan failed, we'll report the error | |
7082 | * but try to keep going. | |
7083 | */ | |
7084 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { | |
7085 | dev_info(&pf->pdev->dev, | |
7086 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", | |
7087 | ret); | |
7088 | pf->vsi[pf->lan_vsi]->uplink_seid | |
7089 | = pf->mac_seid; | |
7090 | break; | |
7091 | } else if (pf->veb[v]->uplink_seid == 0) { | |
7092 | dev_info(&pf->pdev->dev, | |
7093 | "rebuild of orphan VEB failed: %d\n", | |
7094 | ret); | |
7095 | } | |
7096 | } | |
7097 | } | |
7098 | } | |
7099 | ||
7100 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { | |
cde4cbc7 | 7101 | dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
41c445ff JB |
7102 | /* no VEB, so rebuild only the Main VSI */ |
7103 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); | |
7104 | if (ret) { | |
7105 | dev_info(&pf->pdev->dev, | |
7106 | "rebuild of Main VSI failed: %d\n", ret); | |
373149fc | 7107 | goto end_unlock; |
41c445ff JB |
7108 | } |
7109 | } | |
7110 | ||
4f2f017c ASJ |
7111 | /* Reconfigure hardware for allowing smaller MSS in the case |
7112 | * of TSO, so that we avoid the MDD being fired and causing | |
7113 | * a reset in the case of small MSS+TSO. | |
7114 | */ | |
7115 | #define I40E_REG_MSS 0x000E64DC | |
7116 | #define I40E_REG_MSS_MIN_MASK 0x3FF0000 | |
7117 | #define I40E_64BYTE_MSS 0x400000 | |
7118 | val = rd32(hw, I40E_REG_MSS); | |
7119 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { | |
7120 | val &= ~I40E_REG_MSS_MIN_MASK; | |
7121 | val |= I40E_64BYTE_MSS; | |
7122 | wr32(hw, I40E_REG_MSS, val); | |
7123 | } | |
7124 | ||
8eed76fa | 7125 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
025b4a54 ASJ |
7126 | msleep(75); |
7127 | ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); | |
7128 | if (ret) | |
f1c7e72e SN |
7129 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
7130 | i40e_stat_str(&pf->hw, ret), | |
7131 | i40e_aq_str(&pf->hw, | |
7132 | pf->hw.aq.asq_last_status)); | |
cafa2ee6 | 7133 | } |
41c445ff JB |
7134 | /* reinit the misc interrupt */ |
7135 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) | |
7136 | ret = i40e_setup_misc_vector(pf); | |
7137 | ||
e7358f54 ASJ |
7138 | /* Add a filter to drop all Flow control frames from any VSI from being |
7139 | * transmitted. By doing so we stop a malicious VF from sending out | |
7140 | * PAUSE or PFC frames and potentially controlling traffic for other | |
7141 | * PF/VF VSIs. | |
7142 | * The FW can still send Flow control frames if enabled. | |
7143 | */ | |
7144 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, | |
7145 | pf->main_vsi_seid); | |
7146 | ||
41c445ff JB |
7147 | /* restart the VSIs that were rebuilt and running before the reset */ |
7148 | i40e_pf_unquiesce_all_vsi(pf); | |
7149 | ||
024b05f4 JK |
7150 | /* Release the RTNL lock before we start resetting VFs */ |
7151 | if (!lock_acquired) | |
7152 | rtnl_unlock(); | |
7153 | ||
69f64b2b MW |
7154 | if (pf->num_alloc_vfs) { |
7155 | for (v = 0; v < pf->num_alloc_vfs; v++) | |
7156 | i40e_reset_vf(&pf->vf[v], true); | |
7157 | } | |
7158 | ||
41c445ff | 7159 | /* tell the firmware that we're starting */ |
44033fac | 7160 | i40e_send_version(pf); |
41c445ff | 7161 | |
024b05f4 JK |
7162 | /* We've already released the lock, so don't do it again */ |
7163 | goto end_core_reset; | |
7164 | ||
373149fc | 7165 | end_unlock: |
024b05f4 JK |
7166 | if (!lock_acquired) |
7167 | rtnl_unlock(); | |
41c445ff | 7168 | end_core_reset: |
a316f651 ASJ |
7169 | clear_bit(__I40E_RESET_FAILED, &pf->state); |
7170 | clear_recovery: | |
41c445ff JB |
7171 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
7172 | } | |
7173 | ||
373149fc MS |
7174 | /** |
7175 | * i40e_reset_and_rebuild - reset and rebuild using a saved config | |
7176 | * @pf: board private structure | |
7177 | * @reinit: if the Main VSI needs to re-initialized. | |
7178 | * @lock_acquired: indicates whether or not the lock has been acquired | |
7179 | * before this function was called. | |
7180 | **/ | |
7181 | static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit, | |
7182 | bool lock_acquired) | |
7183 | { | |
7184 | int ret; | |
7185 | /* Now we wait for GRST to settle out. | |
7186 | * We don't have to delete the VEBs or VSIs from the hw switch | |
7187 | * because the reset will make them disappear. | |
7188 | */ | |
7189 | ret = i40e_reset(pf); | |
7190 | if (!ret) | |
7191 | i40e_rebuild(pf, reinit, lock_acquired); | |
7192 | } | |
7193 | ||
f650a38b | 7194 | /** |
b40c82e6 | 7195 | * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild |
f650a38b ASJ |
7196 | * @pf: board private structure |
7197 | * | |
7198 | * Close up the VFs and other things in prep for a Core Reset, | |
7199 | * then get ready to rebuild the world. | |
373149fc MS |
7200 | * @lock_acquired: indicates whether or not the lock has been acquired |
7201 | * before this function was called. | |
f650a38b | 7202 | **/ |
373149fc | 7203 | static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired) |
f650a38b | 7204 | { |
373149fc MS |
7205 | i40e_prep_for_reset(pf, lock_acquired); |
7206 | i40e_reset_and_rebuild(pf, false, lock_acquired); | |
f650a38b ASJ |
7207 | } |
7208 | ||
41c445ff JB |
7209 | /** |
7210 | * i40e_handle_mdd_event | |
b40c82e6 | 7211 | * @pf: pointer to the PF structure |
41c445ff JB |
7212 | * |
7213 | * Called from the MDD irq handler to identify possibly malicious vfs | |
7214 | **/ | |
7215 | static void i40e_handle_mdd_event(struct i40e_pf *pf) | |
7216 | { | |
7217 | struct i40e_hw *hw = &pf->hw; | |
7218 | bool mdd_detected = false; | |
df430b12 | 7219 | bool pf_mdd_detected = false; |
41c445ff JB |
7220 | struct i40e_vf *vf; |
7221 | u32 reg; | |
7222 | int i; | |
7223 | ||
7224 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) | |
7225 | return; | |
7226 | ||
7227 | /* find what triggered the MDD event */ | |
7228 | reg = rd32(hw, I40E_GL_MDET_TX); | |
7229 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { | |
4c33f83a ASJ |
7230 | u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >> |
7231 | I40E_GL_MDET_TX_PF_NUM_SHIFT; | |
2089ad03 | 7232 | u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >> |
4c33f83a | 7233 | I40E_GL_MDET_TX_VF_NUM_SHIFT; |
013f6579 | 7234 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >> |
4c33f83a | 7235 | I40E_GL_MDET_TX_EVENT_SHIFT; |
2089ad03 MW |
7236 | u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >> |
7237 | I40E_GL_MDET_TX_QUEUE_SHIFT) - | |
7238 | pf->hw.func_caps.base_queue; | |
faf32978 | 7239 | if (netif_msg_tx_err(pf)) |
b40c82e6 | 7240 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n", |
faf32978 | 7241 | event, queue, pf_num, vf_num); |
41c445ff JB |
7242 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
7243 | mdd_detected = true; | |
7244 | } | |
7245 | reg = rd32(hw, I40E_GL_MDET_RX); | |
7246 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { | |
4c33f83a ASJ |
7247 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >> |
7248 | I40E_GL_MDET_RX_FUNCTION_SHIFT; | |
013f6579 | 7249 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >> |
4c33f83a | 7250 | I40E_GL_MDET_RX_EVENT_SHIFT; |
2089ad03 MW |
7251 | u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >> |
7252 | I40E_GL_MDET_RX_QUEUE_SHIFT) - | |
7253 | pf->hw.func_caps.base_queue; | |
faf32978 JB |
7254 | if (netif_msg_rx_err(pf)) |
7255 | dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", | |
7256 | event, queue, func); | |
41c445ff JB |
7257 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
7258 | mdd_detected = true; | |
7259 | } | |
7260 | ||
df430b12 NP |
7261 | if (mdd_detected) { |
7262 | reg = rd32(hw, I40E_PF_MDET_TX); | |
7263 | if (reg & I40E_PF_MDET_TX_VALID_MASK) { | |
7264 | wr32(hw, I40E_PF_MDET_TX, 0xFFFF); | |
faf32978 | 7265 | dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n"); |
df430b12 NP |
7266 | pf_mdd_detected = true; |
7267 | } | |
7268 | reg = rd32(hw, I40E_PF_MDET_RX); | |
7269 | if (reg & I40E_PF_MDET_RX_VALID_MASK) { | |
7270 | wr32(hw, I40E_PF_MDET_RX, 0xFFFF); | |
faf32978 | 7271 | dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n"); |
df430b12 NP |
7272 | pf_mdd_detected = true; |
7273 | } | |
7274 | /* Queue belongs to the PF, initiate a reset */ | |
7275 | if (pf_mdd_detected) { | |
7276 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); | |
7277 | i40e_service_event_schedule(pf); | |
7278 | } | |
7279 | } | |
7280 | ||
41c445ff JB |
7281 | /* see if one of the VFs needs its hand slapped */ |
7282 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { | |
7283 | vf = &(pf->vf[i]); | |
7284 | reg = rd32(hw, I40E_VP_MDET_TX(i)); | |
7285 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { | |
7286 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); | |
7287 | vf->num_mdd_events++; | |
faf32978 JB |
7288 | dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n", |
7289 | i); | |
41c445ff JB |
7290 | } |
7291 | ||
7292 | reg = rd32(hw, I40E_VP_MDET_RX(i)); | |
7293 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { | |
7294 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); | |
7295 | vf->num_mdd_events++; | |
faf32978 JB |
7296 | dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n", |
7297 | i); | |
41c445ff JB |
7298 | } |
7299 | ||
7300 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { | |
7301 | dev_info(&pf->pdev->dev, | |
7302 | "Too many MDD events on VF %d, disabled\n", i); | |
7303 | dev_info(&pf->pdev->dev, | |
7304 | "Use PF Control I/F to re-enable the VF\n"); | |
7305 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); | |
7306 | } | |
7307 | } | |
7308 | ||
7309 | /* re-enable mdd interrupt cause */ | |
7310 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); | |
7311 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); | |
7312 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; | |
7313 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); | |
7314 | i40e_flush(hw); | |
7315 | } | |
7316 | ||
a1c9a9d9 | 7317 | /** |
6a899024 | 7318 | * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW |
a1c9a9d9 JK |
7319 | * @pf: board private structure |
7320 | **/ | |
6a899024 | 7321 | static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf) |
a1c9a9d9 | 7322 | { |
a1c9a9d9 JK |
7323 | struct i40e_hw *hw = &pf->hw; |
7324 | i40e_status ret; | |
fe0b0cd9 | 7325 | u16 port; |
a1c9a9d9 JK |
7326 | int i; |
7327 | ||
6a899024 | 7328 | if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC)) |
a1c9a9d9 JK |
7329 | return; |
7330 | ||
6a899024 | 7331 | pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC; |
a1c9a9d9 JK |
7332 | |
7333 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { | |
6a899024 SA |
7334 | if (pf->pending_udp_bitmap & BIT_ULL(i)) { |
7335 | pf->pending_udp_bitmap &= ~BIT_ULL(i); | |
7336 | port = pf->udp_ports[i].index; | |
c22c06c8 | 7337 | if (port) |
b3f5c7bc CW |
7338 | ret = i40e_aq_add_udp_tunnel(hw, port, |
7339 | pf->udp_ports[i].type, | |
7340 | NULL, NULL); | |
c22c06c8 SN |
7341 | else |
7342 | ret = i40e_aq_del_udp_tunnel(hw, i, NULL); | |
a1c9a9d9 JK |
7343 | |
7344 | if (ret) { | |
730a8f87 CW |
7345 | dev_dbg(&pf->pdev->dev, |
7346 | "%s %s port %d, index %d failed, err %s aq_err %s\n", | |
7347 | pf->udp_ports[i].type ? "vxlan" : "geneve", | |
7348 | port ? "add" : "delete", | |
fe0b0cd9 | 7349 | port, i, |
730a8f87 CW |
7350 | i40e_stat_str(&pf->hw, ret), |
7351 | i40e_aq_str(&pf->hw, | |
f1c7e72e | 7352 | pf->hw.aq.asq_last_status)); |
6a899024 | 7353 | pf->udp_ports[i].index = 0; |
a1c9a9d9 JK |
7354 | } |
7355 | } | |
7356 | } | |
7357 | } | |
7358 | ||
41c445ff JB |
7359 | /** |
7360 | * i40e_service_task - Run the driver's async subtasks | |
7361 | * @work: pointer to work_struct containing our data | |
7362 | **/ | |
7363 | static void i40e_service_task(struct work_struct *work) | |
7364 | { | |
7365 | struct i40e_pf *pf = container_of(work, | |
7366 | struct i40e_pf, | |
7367 | service_task); | |
7368 | unsigned long start_time = jiffies; | |
7369 | ||
e57a2fea SN |
7370 | /* don't bother with service tasks if a reset is in progress */ |
7371 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { | |
e57a2fea SN |
7372 | return; |
7373 | } | |
7374 | ||
91089033 MW |
7375 | if (test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
7376 | return; | |
7377 | ||
b03a8c1f | 7378 | i40e_detect_recover_hung(pf); |
2818ccd9 | 7379 | i40e_sync_filters_subtask(pf); |
41c445ff JB |
7380 | i40e_reset_subtask(pf); |
7381 | i40e_handle_mdd_event(pf); | |
7382 | i40e_vc_process_vflr_event(pf); | |
7383 | i40e_watchdog_subtask(pf); | |
7384 | i40e_fdir_reinit_subtask(pf); | |
0ef2d5af MW |
7385 | if (pf->flags & I40E_FLAG_CLIENT_RESET) { |
7386 | /* Client subtask will reopen next time through. */ | |
7387 | i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], true); | |
7388 | pf->flags &= ~I40E_FLAG_CLIENT_RESET; | |
7389 | } else { | |
7390 | i40e_client_subtask(pf); | |
7391 | if (pf->flags & I40E_FLAG_CLIENT_L2_CHANGE) { | |
7392 | i40e_notify_client_of_l2_param_changes( | |
7393 | pf->vsi[pf->lan_vsi]); | |
7394 | pf->flags &= ~I40E_FLAG_CLIENT_L2_CHANGE; | |
7395 | } | |
7396 | } | |
41c445ff | 7397 | i40e_sync_filters_subtask(pf); |
6a899024 | 7398 | i40e_sync_udp_filters_subtask(pf); |
41c445ff JB |
7399 | i40e_clean_adminq_subtask(pf); |
7400 | ||
91089033 MW |
7401 | /* flush memory to make sure state is correct before next watchdog */ |
7402 | smp_mb__before_atomic(); | |
7403 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); | |
41c445ff JB |
7404 | |
7405 | /* If the tasks have taken longer than one timer cycle or there | |
7406 | * is more work to be done, reschedule the service task now | |
7407 | * rather than wait for the timer to tick again. | |
7408 | */ | |
7409 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || | |
7410 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || | |
7411 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || | |
7412 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) | |
7413 | i40e_service_event_schedule(pf); | |
7414 | } | |
7415 | ||
7416 | /** | |
7417 | * i40e_service_timer - timer callback | |
7418 | * @data: pointer to PF struct | |
7419 | **/ | |
7420 | static void i40e_service_timer(unsigned long data) | |
7421 | { | |
7422 | struct i40e_pf *pf = (struct i40e_pf *)data; | |
7423 | ||
7424 | mod_timer(&pf->service_timer, | |
7425 | round_jiffies(jiffies + pf->service_timer_period)); | |
7426 | i40e_service_event_schedule(pf); | |
7427 | } | |
7428 | ||
7429 | /** | |
7430 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI | |
7431 | * @vsi: the VSI being configured | |
7432 | **/ | |
7433 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) | |
7434 | { | |
7435 | struct i40e_pf *pf = vsi->back; | |
7436 | ||
7437 | switch (vsi->type) { | |
7438 | case I40E_VSI_MAIN: | |
7439 | vsi->alloc_queue_pairs = pf->num_lan_qps; | |
7440 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, | |
7441 | I40E_REQ_DESCRIPTOR_MULTIPLE); | |
7442 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) | |
7443 | vsi->num_q_vectors = pf->num_lan_msix; | |
7444 | else | |
7445 | vsi->num_q_vectors = 1; | |
7446 | ||
7447 | break; | |
7448 | ||
7449 | case I40E_VSI_FDIR: | |
7450 | vsi->alloc_queue_pairs = 1; | |
7451 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, | |
7452 | I40E_REQ_DESCRIPTOR_MULTIPLE); | |
a70e407f | 7453 | vsi->num_q_vectors = pf->num_fdsb_msix; |
41c445ff JB |
7454 | break; |
7455 | ||
7456 | case I40E_VSI_VMDQ2: | |
7457 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; | |
7458 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, | |
7459 | I40E_REQ_DESCRIPTOR_MULTIPLE); | |
7460 | vsi->num_q_vectors = pf->num_vmdq_msix; | |
7461 | break; | |
7462 | ||
7463 | case I40E_VSI_SRIOV: | |
7464 | vsi->alloc_queue_pairs = pf->num_vf_qps; | |
7465 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, | |
7466 | I40E_REQ_DESCRIPTOR_MULTIPLE); | |
7467 | break; | |
7468 | ||
7469 | default: | |
7470 | WARN_ON(1); | |
7471 | return -ENODATA; | |
7472 | } | |
7473 | ||
7474 | return 0; | |
7475 | } | |
7476 | ||
f650a38b ASJ |
7477 | /** |
7478 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi | |
7479 | * @type: VSI pointer | |
bc7d338f | 7480 | * @alloc_qvectors: a bool to specify if q_vectors need to be allocated. |
f650a38b ASJ |
7481 | * |
7482 | * On error: returns error code (negative) | |
7483 | * On success: returns 0 | |
7484 | **/ | |
bc7d338f | 7485 | static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors) |
f650a38b ASJ |
7486 | { |
7487 | int size; | |
7488 | int ret = 0; | |
7489 | ||
ac6c5e3d | 7490 | /* allocate memory for both Tx and Rx ring pointers */ |
f650a38b ASJ |
7491 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
7492 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); | |
7493 | if (!vsi->tx_rings) | |
7494 | return -ENOMEM; | |
f650a38b ASJ |
7495 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
7496 | ||
bc7d338f ASJ |
7497 | if (alloc_qvectors) { |
7498 | /* allocate memory for q_vector pointers */ | |
f57e4fbd | 7499 | size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors; |
bc7d338f ASJ |
7500 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
7501 | if (!vsi->q_vectors) { | |
7502 | ret = -ENOMEM; | |
7503 | goto err_vectors; | |
7504 | } | |
f650a38b ASJ |
7505 | } |
7506 | return ret; | |
7507 | ||
7508 | err_vectors: | |
7509 | kfree(vsi->tx_rings); | |
7510 | return ret; | |
7511 | } | |
7512 | ||
41c445ff JB |
7513 | /** |
7514 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF | |
7515 | * @pf: board private structure | |
7516 | * @type: type of VSI | |
7517 | * | |
7518 | * On error: returns error code (negative) | |
7519 | * On success: returns vsi index in PF (positive) | |
7520 | **/ | |
7521 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) | |
7522 | { | |
7523 | int ret = -ENODEV; | |
7524 | struct i40e_vsi *vsi; | |
7525 | int vsi_idx; | |
7526 | int i; | |
7527 | ||
7528 | /* Need to protect the allocation of the VSIs at the PF level */ | |
7529 | mutex_lock(&pf->switch_mutex); | |
7530 | ||
7531 | /* VSI list may be fragmented if VSI creation/destruction has | |
7532 | * been happening. We can afford to do a quick scan to look | |
7533 | * for any free VSIs in the list. | |
7534 | * | |
7535 | * find next empty vsi slot, looping back around if necessary | |
7536 | */ | |
7537 | i = pf->next_vsi; | |
505682cd | 7538 | while (i < pf->num_alloc_vsi && pf->vsi[i]) |
41c445ff | 7539 | i++; |
505682cd | 7540 | if (i >= pf->num_alloc_vsi) { |
41c445ff JB |
7541 | i = 0; |
7542 | while (i < pf->next_vsi && pf->vsi[i]) | |
7543 | i++; | |
7544 | } | |
7545 | ||
505682cd | 7546 | if (i < pf->num_alloc_vsi && !pf->vsi[i]) { |
41c445ff JB |
7547 | vsi_idx = i; /* Found one! */ |
7548 | } else { | |
7549 | ret = -ENODEV; | |
493fb300 | 7550 | goto unlock_pf; /* out of VSI slots! */ |
41c445ff JB |
7551 | } |
7552 | pf->next_vsi = ++i; | |
7553 | ||
7554 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); | |
7555 | if (!vsi) { | |
7556 | ret = -ENOMEM; | |
493fb300 | 7557 | goto unlock_pf; |
41c445ff JB |
7558 | } |
7559 | vsi->type = type; | |
7560 | vsi->back = pf; | |
7561 | set_bit(__I40E_DOWN, &vsi->state); | |
7562 | vsi->flags = 0; | |
7563 | vsi->idx = vsi_idx; | |
ac26fc13 | 7564 | vsi->int_rate_limit = 0; |
5db4cb59 ASJ |
7565 | vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ? |
7566 | pf->rss_table_size : 64; | |
41c445ff JB |
7567 | vsi->netdev_registered = false; |
7568 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; | |
278e7d0b | 7569 | hash_init(vsi->mac_filter_hash); |
63741846 | 7570 | vsi->irqs_ready = false; |
41c445ff | 7571 | |
9f65e15b AD |
7572 | ret = i40e_set_num_rings_in_vsi(vsi); |
7573 | if (ret) | |
7574 | goto err_rings; | |
7575 | ||
bc7d338f | 7576 | ret = i40e_vsi_alloc_arrays(vsi, true); |
f650a38b | 7577 | if (ret) |
9f65e15b | 7578 | goto err_rings; |
493fb300 | 7579 | |
41c445ff JB |
7580 | /* Setup default MSIX irq handler for VSI */ |
7581 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); | |
7582 | ||
21659035 | 7583 | /* Initialize VSI lock */ |
278e7d0b | 7584 | spin_lock_init(&vsi->mac_filter_hash_lock); |
41c445ff JB |
7585 | pf->vsi[vsi_idx] = vsi; |
7586 | ret = vsi_idx; | |
493fb300 AD |
7587 | goto unlock_pf; |
7588 | ||
9f65e15b | 7589 | err_rings: |
493fb300 AD |
7590 | pf->next_vsi = i - 1; |
7591 | kfree(vsi); | |
7592 | unlock_pf: | |
41c445ff JB |
7593 | mutex_unlock(&pf->switch_mutex); |
7594 | return ret; | |
7595 | } | |
7596 | ||
f650a38b ASJ |
7597 | /** |
7598 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI | |
7599 | * @type: VSI pointer | |
bc7d338f | 7600 | * @free_qvectors: a bool to specify if q_vectors need to be freed. |
f650a38b ASJ |
7601 | * |
7602 | * On error: returns error code (negative) | |
7603 | * On success: returns 0 | |
7604 | **/ | |
bc7d338f | 7605 | static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors) |
f650a38b ASJ |
7606 | { |
7607 | /* free the ring and vector containers */ | |
bc7d338f ASJ |
7608 | if (free_qvectors) { |
7609 | kfree(vsi->q_vectors); | |
7610 | vsi->q_vectors = NULL; | |
7611 | } | |
f650a38b ASJ |
7612 | kfree(vsi->tx_rings); |
7613 | vsi->tx_rings = NULL; | |
7614 | vsi->rx_rings = NULL; | |
7615 | } | |
7616 | ||
28c5869f HZ |
7617 | /** |
7618 | * i40e_clear_rss_config_user - clear the user configured RSS hash keys | |
7619 | * and lookup table | |
7620 | * @vsi: Pointer to VSI structure | |
7621 | */ | |
7622 | static void i40e_clear_rss_config_user(struct i40e_vsi *vsi) | |
7623 | { | |
7624 | if (!vsi) | |
7625 | return; | |
7626 | ||
7627 | kfree(vsi->rss_hkey_user); | |
7628 | vsi->rss_hkey_user = NULL; | |
7629 | ||
7630 | kfree(vsi->rss_lut_user); | |
7631 | vsi->rss_lut_user = NULL; | |
7632 | } | |
7633 | ||
41c445ff JB |
7634 | /** |
7635 | * i40e_vsi_clear - Deallocate the VSI provided | |
7636 | * @vsi: the VSI being un-configured | |
7637 | **/ | |
7638 | static int i40e_vsi_clear(struct i40e_vsi *vsi) | |
7639 | { | |
7640 | struct i40e_pf *pf; | |
7641 | ||
7642 | if (!vsi) | |
7643 | return 0; | |
7644 | ||
7645 | if (!vsi->back) | |
7646 | goto free_vsi; | |
7647 | pf = vsi->back; | |
7648 | ||
7649 | mutex_lock(&pf->switch_mutex); | |
7650 | if (!pf->vsi[vsi->idx]) { | |
7651 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", | |
7652 | vsi->idx, vsi->idx, vsi, vsi->type); | |
7653 | goto unlock_vsi; | |
7654 | } | |
7655 | ||
7656 | if (pf->vsi[vsi->idx] != vsi) { | |
7657 | dev_err(&pf->pdev->dev, | |
7658 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", | |
7659 | pf->vsi[vsi->idx]->idx, | |
7660 | pf->vsi[vsi->idx], | |
7661 | pf->vsi[vsi->idx]->type, | |
7662 | vsi->idx, vsi, vsi->type); | |
7663 | goto unlock_vsi; | |
7664 | } | |
7665 | ||
b40c82e6 | 7666 | /* updates the PF for this cleared vsi */ |
41c445ff JB |
7667 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
7668 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); | |
7669 | ||
bc7d338f | 7670 | i40e_vsi_free_arrays(vsi, true); |
28c5869f | 7671 | i40e_clear_rss_config_user(vsi); |
493fb300 | 7672 | |
41c445ff JB |
7673 | pf->vsi[vsi->idx] = NULL; |
7674 | if (vsi->idx < pf->next_vsi) | |
7675 | pf->next_vsi = vsi->idx; | |
7676 | ||
7677 | unlock_vsi: | |
7678 | mutex_unlock(&pf->switch_mutex); | |
7679 | free_vsi: | |
7680 | kfree(vsi); | |
7681 | ||
7682 | return 0; | |
7683 | } | |
7684 | ||
9f65e15b AD |
7685 | /** |
7686 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI | |
7687 | * @vsi: the VSI being cleaned | |
7688 | **/ | |
be1d5eea | 7689 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
9f65e15b AD |
7690 | { |
7691 | int i; | |
7692 | ||
8e9dca53 | 7693 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
d7397644 | 7694 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
00403f04 MW |
7695 | kfree_rcu(vsi->tx_rings[i], rcu); |
7696 | vsi->tx_rings[i] = NULL; | |
7697 | vsi->rx_rings[i] = NULL; | |
7698 | } | |
be1d5eea | 7699 | } |
9f65e15b AD |
7700 | } |
7701 | ||
41c445ff JB |
7702 | /** |
7703 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI | |
7704 | * @vsi: the VSI being configured | |
7705 | **/ | |
7706 | static int i40e_alloc_rings(struct i40e_vsi *vsi) | |
7707 | { | |
e7046ee1 | 7708 | struct i40e_ring *tx_ring, *rx_ring; |
41c445ff | 7709 | struct i40e_pf *pf = vsi->back; |
41c445ff JB |
7710 | int i; |
7711 | ||
41c445ff | 7712 | /* Set basic values in the rings to be used later during open() */ |
d7397644 | 7713 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
ac6c5e3d | 7714 | /* allocate space for both Tx and Rx in one shot */ |
9f65e15b AD |
7715 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
7716 | if (!tx_ring) | |
7717 | goto err_out; | |
41c445ff JB |
7718 | |
7719 | tx_ring->queue_index = i; | |
7720 | tx_ring->reg_idx = vsi->base_queue + i; | |
7721 | tx_ring->ring_active = false; | |
7722 | tx_ring->vsi = vsi; | |
7723 | tx_ring->netdev = vsi->netdev; | |
7724 | tx_ring->dev = &pf->pdev->dev; | |
7725 | tx_ring->count = vsi->num_desc; | |
7726 | tx_ring->size = 0; | |
7727 | tx_ring->dcb_tc = 0; | |
8e0764b4 ASJ |
7728 | if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
7729 | tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR; | |
a75e8005 | 7730 | tx_ring->tx_itr_setting = pf->tx_itr_default; |
9f65e15b | 7731 | vsi->tx_rings[i] = tx_ring; |
41c445ff | 7732 | |
9f65e15b | 7733 | rx_ring = &tx_ring[1]; |
41c445ff JB |
7734 | rx_ring->queue_index = i; |
7735 | rx_ring->reg_idx = vsi->base_queue + i; | |
7736 | rx_ring->ring_active = false; | |
7737 | rx_ring->vsi = vsi; | |
7738 | rx_ring->netdev = vsi->netdev; | |
7739 | rx_ring->dev = &pf->pdev->dev; | |
7740 | rx_ring->count = vsi->num_desc; | |
7741 | rx_ring->size = 0; | |
7742 | rx_ring->dcb_tc = 0; | |
a75e8005 | 7743 | rx_ring->rx_itr_setting = pf->rx_itr_default; |
9f65e15b | 7744 | vsi->rx_rings[i] = rx_ring; |
41c445ff JB |
7745 | } |
7746 | ||
7747 | return 0; | |
9f65e15b AD |
7748 | |
7749 | err_out: | |
7750 | i40e_vsi_clear_rings(vsi); | |
7751 | return -ENOMEM; | |
41c445ff JB |
7752 | } |
7753 | ||
7754 | /** | |
7755 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel | |
7756 | * @pf: board private structure | |
7757 | * @vectors: the number of MSI-X vectors to request | |
7758 | * | |
7759 | * Returns the number of vectors reserved, or error | |
7760 | **/ | |
7761 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) | |
7762 | { | |
7b37f376 AG |
7763 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
7764 | I40E_MIN_MSIX, vectors); | |
7765 | if (vectors < 0) { | |
41c445ff | 7766 | dev_info(&pf->pdev->dev, |
7b37f376 | 7767 | "MSI-X vector reservation failed: %d\n", vectors); |
41c445ff JB |
7768 | vectors = 0; |
7769 | } | |
7770 | ||
7771 | return vectors; | |
7772 | } | |
7773 | ||
7774 | /** | |
7775 | * i40e_init_msix - Setup the MSIX capability | |
7776 | * @pf: board private structure | |
7777 | * | |
7778 | * Work with the OS to set up the MSIX vectors needed. | |
7779 | * | |
3b444399 | 7780 | * Returns the number of vectors reserved or negative on failure |
41c445ff JB |
7781 | **/ |
7782 | static int i40e_init_msix(struct i40e_pf *pf) | |
7783 | { | |
41c445ff | 7784 | struct i40e_hw *hw = &pf->hw; |
c0cf70a6 | 7785 | int cpus, extra_vectors; |
1e200e4a | 7786 | int vectors_left; |
41c445ff | 7787 | int v_budget, i; |
3b444399 | 7788 | int v_actual; |
e3219ce6 | 7789 | int iwarp_requested = 0; |
41c445ff JB |
7790 | |
7791 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) | |
7792 | return -ENODEV; | |
7793 | ||
7794 | /* The number of vectors we'll request will be comprised of: | |
7795 | * - Add 1 for "other" cause for Admin Queue events, etc. | |
7796 | * - The number of LAN queue pairs | |
f8ff1464 ASJ |
7797 | * - Queues being used for RSS. |
7798 | * We don't need as many as max_rss_size vectors. | |
7799 | * use rss_size instead in the calculation since that | |
7800 | * is governed by number of cpus in the system. | |
7801 | * - assumes symmetric Tx/Rx pairing | |
41c445ff | 7802 | * - The number of VMDq pairs |
e3219ce6 | 7803 | * - The CPU count within the NUMA node if iWARP is enabled |
41c445ff JB |
7804 | * Once we count this up, try the request. |
7805 | * | |
7806 | * If we can't get what we want, we'll simplify to nearly nothing | |
7807 | * and try again. If that still fails, we punt. | |
7808 | */ | |
1e200e4a SN |
7809 | vectors_left = hw->func_caps.num_msix_vectors; |
7810 | v_budget = 0; | |
7811 | ||
7812 | /* reserve one vector for miscellaneous handler */ | |
7813 | if (vectors_left) { | |
7814 | v_budget++; | |
7815 | vectors_left--; | |
7816 | } | |
7817 | ||
c0cf70a6 JK |
7818 | /* reserve some vectors for the main PF traffic queues. Initially we |
7819 | * only reserve at most 50% of the available vectors, in the case that | |
7820 | * the number of online CPUs is large. This ensures that we can enable | |
7821 | * extra features as well. Once we've enabled the other features, we | |
7822 | * will use any remaining vectors to reach as close as we can to the | |
7823 | * number of online CPUs. | |
7824 | */ | |
7825 | cpus = num_online_cpus(); | |
7826 | pf->num_lan_msix = min_t(int, cpus, vectors_left / 2); | |
1e200e4a | 7827 | vectors_left -= pf->num_lan_msix; |
1e200e4a SN |
7828 | |
7829 | /* reserve one vector for sideband flow director */ | |
7830 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { | |
7831 | if (vectors_left) { | |
a70e407f | 7832 | pf->num_fdsb_msix = 1; |
1e200e4a SN |
7833 | v_budget++; |
7834 | vectors_left--; | |
7835 | } else { | |
a70e407f | 7836 | pf->num_fdsb_msix = 0; |
1e200e4a SN |
7837 | } |
7838 | } | |
83840e4b | 7839 | |
e3219ce6 ASJ |
7840 | /* can we reserve enough for iWARP? */ |
7841 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { | |
4ce20abc SA |
7842 | iwarp_requested = pf->num_iwarp_msix; |
7843 | ||
e3219ce6 ASJ |
7844 | if (!vectors_left) |
7845 | pf->num_iwarp_msix = 0; | |
7846 | else if (vectors_left < pf->num_iwarp_msix) | |
7847 | pf->num_iwarp_msix = 1; | |
7848 | v_budget += pf->num_iwarp_msix; | |
7849 | vectors_left -= pf->num_iwarp_msix; | |
7850 | } | |
7851 | ||
1e200e4a SN |
7852 | /* any vectors left over go for VMDq support */ |
7853 | if (pf->flags & I40E_FLAG_VMDQ_ENABLED) { | |
7854 | int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps; | |
7855 | int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted); | |
7856 | ||
9ca57e97 SA |
7857 | if (!vectors_left) { |
7858 | pf->num_vmdq_msix = 0; | |
7859 | pf->num_vmdq_qps = 0; | |
7860 | } else { | |
7861 | /* if we're short on vectors for what's desired, we limit | |
7862 | * the queues per vmdq. If this is still more than are | |
7863 | * available, the user will need to change the number of | |
7864 | * queues/vectors used by the PF later with the ethtool | |
7865 | * channels command | |
7866 | */ | |
7867 | if (vmdq_vecs < vmdq_vecs_wanted) | |
7868 | pf->num_vmdq_qps = 1; | |
7869 | pf->num_vmdq_msix = pf->num_vmdq_qps; | |
1e200e4a | 7870 | |
9ca57e97 SA |
7871 | v_budget += vmdq_vecs; |
7872 | vectors_left -= vmdq_vecs; | |
7873 | } | |
1e200e4a | 7874 | } |
41c445ff | 7875 | |
c0cf70a6 JK |
7876 | /* On systems with a large number of SMP cores, we previously limited |
7877 | * the number of vectors for num_lan_msix to be at most 50% of the | |
7878 | * available vectors, to allow for other features. Now, we add back | |
7879 | * the remaining vectors. However, we ensure that the total | |
7880 | * num_lan_msix will not exceed num_online_cpus(). To do this, we | |
7881 | * calculate the number of vectors we can add without going over the | |
7882 | * cap of CPUs. For systems with a small number of CPUs this will be | |
7883 | * zero. | |
7884 | */ | |
7885 | extra_vectors = min_t(int, cpus - pf->num_lan_msix, vectors_left); | |
7886 | pf->num_lan_msix += extra_vectors; | |
7887 | vectors_left -= extra_vectors; | |
7888 | ||
7889 | WARN(vectors_left < 0, | |
7890 | "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n"); | |
7891 | ||
7892 | v_budget += pf->num_lan_msix; | |
41c445ff JB |
7893 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
7894 | GFP_KERNEL); | |
7895 | if (!pf->msix_entries) | |
7896 | return -ENOMEM; | |
7897 | ||
7898 | for (i = 0; i < v_budget; i++) | |
7899 | pf->msix_entries[i].entry = i; | |
3b444399 | 7900 | v_actual = i40e_reserve_msix_vectors(pf, v_budget); |
a34977ba | 7901 | |
3b444399 | 7902 | if (v_actual < I40E_MIN_MSIX) { |
41c445ff JB |
7903 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
7904 | kfree(pf->msix_entries); | |
7905 | pf->msix_entries = NULL; | |
4c95aa5d | 7906 | pci_disable_msix(pf->pdev); |
41c445ff JB |
7907 | return -ENODEV; |
7908 | ||
3b444399 | 7909 | } else if (v_actual == I40E_MIN_MSIX) { |
41c445ff | 7910 | /* Adjust for minimal MSIX use */ |
41c445ff JB |
7911 | pf->num_vmdq_vsis = 0; |
7912 | pf->num_vmdq_qps = 0; | |
41c445ff JB |
7913 | pf->num_lan_qps = 1; |
7914 | pf->num_lan_msix = 1; | |
7915 | ||
4ce20abc SA |
7916 | } else if (!vectors_left) { |
7917 | /* If we have limited resources, we will start with no vectors | |
7918 | * for the special features and then allocate vectors to some | |
7919 | * of these features based on the policy and at the end disable | |
7920 | * the features that did not get any vectors. | |
7921 | */ | |
3b444399 SN |
7922 | int vec; |
7923 | ||
4ce20abc SA |
7924 | dev_info(&pf->pdev->dev, |
7925 | "MSI-X vector limit reached, attempting to redistribute vectors\n"); | |
a34977ba | 7926 | /* reserve the misc vector */ |
3b444399 | 7927 | vec = v_actual - 1; |
a34977ba | 7928 | |
41c445ff JB |
7929 | /* Scale vector usage down */ |
7930 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ | |
a34977ba | 7931 | pf->num_vmdq_vsis = 1; |
1e200e4a | 7932 | pf->num_vmdq_qps = 1; |
41c445ff JB |
7933 | |
7934 | /* partition out the remaining vectors */ | |
7935 | switch (vec) { | |
7936 | case 2: | |
41c445ff JB |
7937 | pf->num_lan_msix = 1; |
7938 | break; | |
7939 | case 3: | |
e3219ce6 ASJ |
7940 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
7941 | pf->num_lan_msix = 1; | |
7942 | pf->num_iwarp_msix = 1; | |
7943 | } else { | |
7944 | pf->num_lan_msix = 2; | |
7945 | } | |
41c445ff JB |
7946 | break; |
7947 | default: | |
e3219ce6 ASJ |
7948 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
7949 | pf->num_iwarp_msix = min_t(int, (vec / 3), | |
7950 | iwarp_requested); | |
7951 | pf->num_vmdq_vsis = min_t(int, (vec / 3), | |
7952 | I40E_DEFAULT_NUM_VMDQ_VSI); | |
7953 | } else { | |
7954 | pf->num_vmdq_vsis = min_t(int, (vec / 2), | |
7955 | I40E_DEFAULT_NUM_VMDQ_VSI); | |
7956 | } | |
abd97a94 SA |
7957 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
7958 | pf->num_fdsb_msix = 1; | |
7959 | vec--; | |
7960 | } | |
e3219ce6 ASJ |
7961 | pf->num_lan_msix = min_t(int, |
7962 | (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)), | |
7963 | pf->num_lan_msix); | |
4ce20abc | 7964 | pf->num_lan_qps = pf->num_lan_msix; |
41c445ff JB |
7965 | break; |
7966 | } | |
7967 | } | |
7968 | ||
abd97a94 SA |
7969 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
7970 | (pf->num_fdsb_msix == 0)) { | |
7971 | dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n"); | |
7972 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; | |
7973 | } | |
a34977ba ASJ |
7974 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
7975 | (pf->num_vmdq_msix == 0)) { | |
7976 | dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n"); | |
7977 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; | |
7978 | } | |
e3219ce6 ASJ |
7979 | |
7980 | if ((pf->flags & I40E_FLAG_IWARP_ENABLED) && | |
7981 | (pf->num_iwarp_msix == 0)) { | |
7982 | dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n"); | |
7983 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; | |
7984 | } | |
4ce20abc SA |
7985 | i40e_debug(&pf->hw, I40E_DEBUG_INIT, |
7986 | "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n", | |
7987 | pf->num_lan_msix, | |
7988 | pf->num_vmdq_msix * pf->num_vmdq_vsis, | |
7989 | pf->num_fdsb_msix, | |
7990 | pf->num_iwarp_msix); | |
7991 | ||
3b444399 | 7992 | return v_actual; |
41c445ff JB |
7993 | } |
7994 | ||
493fb300 | 7995 | /** |
90e04070 | 7996 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
493fb300 AD |
7997 | * @vsi: the VSI being configured |
7998 | * @v_idx: index of the vector in the vsi struct | |
7f6c5539 | 7999 | * @cpu: cpu to be used on affinity_mask |
493fb300 AD |
8000 | * |
8001 | * We allocate one q_vector. If allocation fails we return -ENOMEM. | |
8002 | **/ | |
7f6c5539 | 8003 | static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu) |
493fb300 AD |
8004 | { |
8005 | struct i40e_q_vector *q_vector; | |
8006 | ||
8007 | /* allocate q_vector */ | |
8008 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); | |
8009 | if (!q_vector) | |
8010 | return -ENOMEM; | |
8011 | ||
8012 | q_vector->vsi = vsi; | |
8013 | q_vector->v_idx = v_idx; | |
7f6c5539 GP |
8014 | cpumask_set_cpu(cpu, &q_vector->affinity_mask); |
8015 | ||
493fb300 AD |
8016 | if (vsi->netdev) |
8017 | netif_napi_add(vsi->netdev, &q_vector->napi, | |
eefeacee | 8018 | i40e_napi_poll, NAPI_POLL_WEIGHT); |
493fb300 | 8019 | |
cd0b6fa6 AD |
8020 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
8021 | q_vector->tx.latency_range = I40E_LOW_LATENCY; | |
8022 | ||
493fb300 AD |
8023 | /* tie q_vector and vsi together */ |
8024 | vsi->q_vectors[v_idx] = q_vector; | |
8025 | ||
8026 | return 0; | |
8027 | } | |
8028 | ||
41c445ff | 8029 | /** |
90e04070 | 8030 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
41c445ff JB |
8031 | * @vsi: the VSI being configured |
8032 | * | |
8033 | * We allocate one q_vector per queue interrupt. If allocation fails we | |
8034 | * return -ENOMEM. | |
8035 | **/ | |
90e04070 | 8036 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
41c445ff JB |
8037 | { |
8038 | struct i40e_pf *pf = vsi->back; | |
7f6c5539 | 8039 | int err, v_idx, num_q_vectors, current_cpu; |
41c445ff JB |
8040 | |
8041 | /* if not MSIX, give the one vector only to the LAN VSI */ | |
8042 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) | |
8043 | num_q_vectors = vsi->num_q_vectors; | |
8044 | else if (vsi == pf->vsi[pf->lan_vsi]) | |
8045 | num_q_vectors = 1; | |
8046 | else | |
8047 | return -EINVAL; | |
8048 | ||
7f6c5539 GP |
8049 | current_cpu = cpumask_first(cpu_online_mask); |
8050 | ||
41c445ff | 8051 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
7f6c5539 | 8052 | err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu); |
493fb300 AD |
8053 | if (err) |
8054 | goto err_out; | |
7f6c5539 GP |
8055 | current_cpu = cpumask_next(current_cpu, cpu_online_mask); |
8056 | if (unlikely(current_cpu >= nr_cpu_ids)) | |
8057 | current_cpu = cpumask_first(cpu_online_mask); | |
41c445ff JB |
8058 | } |
8059 | ||
8060 | return 0; | |
493fb300 AD |
8061 | |
8062 | err_out: | |
8063 | while (v_idx--) | |
8064 | i40e_free_q_vector(vsi, v_idx); | |
8065 | ||
8066 | return err; | |
41c445ff JB |
8067 | } |
8068 | ||
8069 | /** | |
8070 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme | |
8071 | * @pf: board private structure to initialize | |
8072 | **/ | |
c1147280 | 8073 | static int i40e_init_interrupt_scheme(struct i40e_pf *pf) |
41c445ff | 8074 | { |
3b444399 SN |
8075 | int vectors = 0; |
8076 | ssize_t size; | |
41c445ff JB |
8077 | |
8078 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | |
3b444399 SN |
8079 | vectors = i40e_init_msix(pf); |
8080 | if (vectors < 0) { | |
60ea5f83 | 8081 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
e3219ce6 | 8082 | I40E_FLAG_IWARP_ENABLED | |
60ea5f83 | 8083 | I40E_FLAG_RSS_ENABLED | |
4d9b6043 | 8084 | I40E_FLAG_DCB_CAPABLE | |
a036244c | 8085 | I40E_FLAG_DCB_ENABLED | |
60ea5f83 JB |
8086 | I40E_FLAG_SRIOV_ENABLED | |
8087 | I40E_FLAG_FD_SB_ENABLED | | |
8088 | I40E_FLAG_FD_ATR_ENABLED | | |
8089 | I40E_FLAG_VMDQ_ENABLED); | |
41c445ff JB |
8090 | |
8091 | /* rework the queue expectations without MSIX */ | |
8092 | i40e_determine_queue_usage(pf); | |
8093 | } | |
8094 | } | |
8095 | ||
8096 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && | |
8097 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { | |
77fa28be | 8098 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
3b444399 SN |
8099 | vectors = pci_enable_msi(pf->pdev); |
8100 | if (vectors < 0) { | |
8101 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", | |
8102 | vectors); | |
41c445ff JB |
8103 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
8104 | } | |
3b444399 | 8105 | vectors = 1; /* one MSI or Legacy vector */ |
41c445ff JB |
8106 | } |
8107 | ||
958a3e3b | 8108 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
77fa28be | 8109 | dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n"); |
958a3e3b | 8110 | |
3b444399 SN |
8111 | /* set up vector assignment tracking */ |
8112 | size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors); | |
8113 | pf->irq_pile = kzalloc(size, GFP_KERNEL); | |
c1147280 JB |
8114 | if (!pf->irq_pile) { |
8115 | dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n"); | |
8116 | return -ENOMEM; | |
8117 | } | |
3b444399 SN |
8118 | pf->irq_pile->num_entries = vectors; |
8119 | pf->irq_pile->search_hint = 0; | |
8120 | ||
c1147280 | 8121 | /* track first vector for misc interrupts, ignore return */ |
3b444399 | 8122 | (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1); |
c1147280 JB |
8123 | |
8124 | return 0; | |
41c445ff JB |
8125 | } |
8126 | ||
8127 | /** | |
8128 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events | |
8129 | * @pf: board private structure | |
8130 | * | |
8131 | * This sets up the handler for MSIX 0, which is used to manage the | |
8132 | * non-queue interrupts, e.g. AdminQ and errors. This is not used | |
8133 | * when in MSI or Legacy interrupt mode. | |
8134 | **/ | |
8135 | static int i40e_setup_misc_vector(struct i40e_pf *pf) | |
8136 | { | |
8137 | struct i40e_hw *hw = &pf->hw; | |
8138 | int err = 0; | |
8139 | ||
8140 | /* Only request the irq if this is the first time through, and | |
8141 | * not when we're rebuilding after a Reset | |
8142 | */ | |
8143 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { | |
8144 | err = request_irq(pf->msix_entries[0].vector, | |
b294ac70 | 8145 | i40e_intr, 0, pf->int_name, pf); |
41c445ff JB |
8146 | if (err) { |
8147 | dev_info(&pf->pdev->dev, | |
77fa28be | 8148 | "request_irq for %s failed: %d\n", |
b294ac70 | 8149 | pf->int_name, err); |
41c445ff JB |
8150 | return -EFAULT; |
8151 | } | |
8152 | } | |
8153 | ||
ab437b5a | 8154 | i40e_enable_misc_int_causes(pf); |
41c445ff JB |
8155 | |
8156 | /* associate no queues to the misc vector */ | |
8157 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); | |
8158 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); | |
8159 | ||
8160 | i40e_flush(hw); | |
8161 | ||
40d72a50 | 8162 | i40e_irq_dynamic_enable_icr0(pf, true); |
41c445ff JB |
8163 | |
8164 | return err; | |
8165 | } | |
8166 | ||
8167 | /** | |
e25d00b8 ASJ |
8168 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
8169 | * @vsi: vsi structure | |
8170 | * @seed: RSS hash seed | |
8171 | **/ | |
e69ff813 HZ |
8172 | static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
8173 | u8 *lut, u16 lut_size) | |
e25d00b8 | 8174 | { |
e25d00b8 ASJ |
8175 | struct i40e_pf *pf = vsi->back; |
8176 | struct i40e_hw *hw = &pf->hw; | |
776b2e15 | 8177 | int ret = 0; |
e25d00b8 | 8178 | |
776b2e15 JK |
8179 | if (seed) { |
8180 | struct i40e_aqc_get_set_rss_key_data *seed_dw = | |
8181 | (struct i40e_aqc_get_set_rss_key_data *)seed; | |
8182 | ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw); | |
8183 | if (ret) { | |
8184 | dev_info(&pf->pdev->dev, | |
8185 | "Cannot set RSS key, err %s aq_err %s\n", | |
8186 | i40e_stat_str(hw, ret), | |
8187 | i40e_aq_str(hw, hw->aq.asq_last_status)); | |
8188 | return ret; | |
8189 | } | |
e25d00b8 | 8190 | } |
776b2e15 JK |
8191 | if (lut) { |
8192 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; | |
e25d00b8 | 8193 | |
776b2e15 JK |
8194 | ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); |
8195 | if (ret) { | |
8196 | dev_info(&pf->pdev->dev, | |
8197 | "Cannot set RSS lut, err %s aq_err %s\n", | |
8198 | i40e_stat_str(hw, ret), | |
8199 | i40e_aq_str(hw, hw->aq.asq_last_status)); | |
8200 | return ret; | |
8201 | } | |
8202 | } | |
e25d00b8 ASJ |
8203 | return ret; |
8204 | } | |
8205 | ||
95a73780 ASJ |
8206 | /** |
8207 | * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands | |
8208 | * @vsi: Pointer to vsi structure | |
8209 | * @seed: Buffter to store the hash keys | |
8210 | * @lut: Buffer to store the lookup table entries | |
8211 | * @lut_size: Size of buffer to store the lookup table entries | |
8212 | * | |
8213 | * Return 0 on success, negative on failure | |
8214 | */ | |
8215 | static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, | |
8216 | u8 *lut, u16 lut_size) | |
8217 | { | |
8218 | struct i40e_pf *pf = vsi->back; | |
8219 | struct i40e_hw *hw = &pf->hw; | |
8220 | int ret = 0; | |
8221 | ||
8222 | if (seed) { | |
8223 | ret = i40e_aq_get_rss_key(hw, vsi->id, | |
8224 | (struct i40e_aqc_get_set_rss_key_data *)seed); | |
8225 | if (ret) { | |
8226 | dev_info(&pf->pdev->dev, | |
8227 | "Cannot get RSS key, err %s aq_err %s\n", | |
8228 | i40e_stat_str(&pf->hw, ret), | |
8229 | i40e_aq_str(&pf->hw, | |
8230 | pf->hw.aq.asq_last_status)); | |
8231 | return ret; | |
8232 | } | |
8233 | } | |
8234 | ||
8235 | if (lut) { | |
8236 | bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false; | |
8237 | ||
8238 | ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size); | |
8239 | if (ret) { | |
8240 | dev_info(&pf->pdev->dev, | |
8241 | "Cannot get RSS lut, err %s aq_err %s\n", | |
8242 | i40e_stat_str(&pf->hw, ret), | |
8243 | i40e_aq_str(&pf->hw, | |
8244 | pf->hw.aq.asq_last_status)); | |
8245 | return ret; | |
8246 | } | |
8247 | } | |
8248 | ||
8249 | return ret; | |
8250 | } | |
8251 | ||
0582b964 JK |
8252 | /** |
8253 | * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used | |
8254 | * @vsi: VSI structure | |
8255 | **/ | |
8256 | static int i40e_vsi_config_rss(struct i40e_vsi *vsi) | |
8257 | { | |
8258 | u8 seed[I40E_HKEY_ARRAY_SIZE]; | |
8259 | struct i40e_pf *pf = vsi->back; | |
8260 | u8 *lut; | |
8261 | int ret; | |
8262 | ||
8263 | if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)) | |
8264 | return 0; | |
8265 | ||
552b9962 JK |
8266 | if (!vsi->rss_size) |
8267 | vsi->rss_size = min_t(int, pf->alloc_rss_size, | |
8268 | vsi->num_queue_pairs); | |
8269 | if (!vsi->rss_size) | |
8270 | return -EINVAL; | |
8271 | ||
0582b964 JK |
8272 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
8273 | if (!lut) | |
8274 | return -ENOMEM; | |
552b9962 JK |
8275 | /* Use the user configured hash keys and lookup table if there is one, |
8276 | * otherwise use default | |
8277 | */ | |
8278 | if (vsi->rss_lut_user) | |
8279 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); | |
8280 | else | |
8281 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); | |
8282 | if (vsi->rss_hkey_user) | |
8283 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); | |
8284 | else | |
8285 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); | |
0582b964 JK |
8286 | ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size); |
8287 | kfree(lut); | |
8288 | ||
8289 | return ret; | |
8290 | } | |
8291 | ||
e25d00b8 | 8292 | /** |
043dd650 | 8293 | * i40e_config_rss_reg - Configure RSS keys and lut by writing registers |
e69ff813 | 8294 | * @vsi: Pointer to vsi structure |
e25d00b8 | 8295 | * @seed: RSS hash seed |
e69ff813 HZ |
8296 | * @lut: Lookup table |
8297 | * @lut_size: Lookup table size | |
8298 | * | |
8299 | * Returns 0 on success, negative on failure | |
41c445ff | 8300 | **/ |
e69ff813 HZ |
8301 | static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
8302 | const u8 *lut, u16 lut_size) | |
41c445ff | 8303 | { |
e69ff813 | 8304 | struct i40e_pf *pf = vsi->back; |
4617e8c0 | 8305 | struct i40e_hw *hw = &pf->hw; |
c4e1868c | 8306 | u16 vf_id = vsi->vf_id; |
e69ff813 | 8307 | u8 i; |
41c445ff | 8308 | |
e25d00b8 | 8309 | /* Fill out hash function seed */ |
e69ff813 HZ |
8310 | if (seed) { |
8311 | u32 *seed_dw = (u32 *)seed; | |
8312 | ||
c4e1868c MW |
8313 | if (vsi->type == I40E_VSI_MAIN) { |
8314 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) | |
26f77e53 | 8315 | wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]); |
c4e1868c MW |
8316 | } else if (vsi->type == I40E_VSI_SRIOV) { |
8317 | for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++) | |
26f77e53 | 8318 | wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]); |
c4e1868c MW |
8319 | } else { |
8320 | dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n"); | |
8321 | } | |
e69ff813 HZ |
8322 | } |
8323 | ||
8324 | if (lut) { | |
8325 | u32 *lut_dw = (u32 *)lut; | |
8326 | ||
c4e1868c MW |
8327 | if (vsi->type == I40E_VSI_MAIN) { |
8328 | if (lut_size != I40E_HLUT_ARRAY_SIZE) | |
8329 | return -EINVAL; | |
8330 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) | |
8331 | wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]); | |
8332 | } else if (vsi->type == I40E_VSI_SRIOV) { | |
8333 | if (lut_size != I40E_VF_HLUT_ARRAY_SIZE) | |
8334 | return -EINVAL; | |
8335 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) | |
26f77e53 | 8336 | wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]); |
c4e1868c MW |
8337 | } else { |
8338 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); | |
8339 | } | |
e25d00b8 ASJ |
8340 | } |
8341 | i40e_flush(hw); | |
8342 | ||
8343 | return 0; | |
8344 | } | |
8345 | ||
043dd650 HZ |
8346 | /** |
8347 | * i40e_get_rss_reg - Get the RSS keys and lut by reading registers | |
8348 | * @vsi: Pointer to VSI structure | |
8349 | * @seed: Buffer to store the keys | |
8350 | * @lut: Buffer to store the lookup table entries | |
8351 | * @lut_size: Size of buffer to store the lookup table entries | |
8352 | * | |
8353 | * Returns 0 on success, negative on failure | |
8354 | */ | |
8355 | static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed, | |
8356 | u8 *lut, u16 lut_size) | |
8357 | { | |
8358 | struct i40e_pf *pf = vsi->back; | |
8359 | struct i40e_hw *hw = &pf->hw; | |
8360 | u16 i; | |
8361 | ||
8362 | if (seed) { | |
8363 | u32 *seed_dw = (u32 *)seed; | |
8364 | ||
8365 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) | |
272cdaf2 | 8366 | seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i)); |
043dd650 HZ |
8367 | } |
8368 | if (lut) { | |
8369 | u32 *lut_dw = (u32 *)lut; | |
8370 | ||
8371 | if (lut_size != I40E_HLUT_ARRAY_SIZE) | |
8372 | return -EINVAL; | |
8373 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) | |
8374 | lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i)); | |
8375 | } | |
8376 | ||
8377 | return 0; | |
8378 | } | |
8379 | ||
8380 | /** | |
8381 | * i40e_config_rss - Configure RSS keys and lut | |
8382 | * @vsi: Pointer to VSI structure | |
8383 | * @seed: RSS hash seed | |
8384 | * @lut: Lookup table | |
8385 | * @lut_size: Lookup table size | |
8386 | * | |
8387 | * Returns 0 on success, negative on failure | |
8388 | */ | |
8389 | int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) | |
8390 | { | |
8391 | struct i40e_pf *pf = vsi->back; | |
8392 | ||
8393 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) | |
8394 | return i40e_config_rss_aq(vsi, seed, lut, lut_size); | |
8395 | else | |
8396 | return i40e_config_rss_reg(vsi, seed, lut, lut_size); | |
8397 | } | |
8398 | ||
8399 | /** | |
8400 | * i40e_get_rss - Get RSS keys and lut | |
8401 | * @vsi: Pointer to VSI structure | |
8402 | * @seed: Buffer to store the keys | |
8403 | * @lut: Buffer to store the lookup table entries | |
8404 | * lut_size: Size of buffer to store the lookup table entries | |
8405 | * | |
8406 | * Returns 0 on success, negative on failure | |
8407 | */ | |
8408 | int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) | |
8409 | { | |
95a73780 ASJ |
8410 | struct i40e_pf *pf = vsi->back; |
8411 | ||
8412 | if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) | |
8413 | return i40e_get_rss_aq(vsi, seed, lut, lut_size); | |
8414 | else | |
8415 | return i40e_get_rss_reg(vsi, seed, lut, lut_size); | |
043dd650 HZ |
8416 | } |
8417 | ||
e69ff813 HZ |
8418 | /** |
8419 | * i40e_fill_rss_lut - Fill the RSS lookup table with default values | |
8420 | * @pf: Pointer to board private structure | |
8421 | * @lut: Lookup table | |
8422 | * @rss_table_size: Lookup table size | |
8423 | * @rss_size: Range of queue number for hashing | |
8424 | */ | |
f1582351 AB |
8425 | void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut, |
8426 | u16 rss_table_size, u16 rss_size) | |
e69ff813 HZ |
8427 | { |
8428 | u16 i; | |
8429 | ||
8430 | for (i = 0; i < rss_table_size; i++) | |
8431 | lut[i] = i % rss_size; | |
8432 | } | |
8433 | ||
e25d00b8 | 8434 | /** |
043dd650 | 8435 | * i40e_pf_config_rss - Prepare for RSS if used |
e25d00b8 ASJ |
8436 | * @pf: board private structure |
8437 | **/ | |
043dd650 | 8438 | static int i40e_pf_config_rss(struct i40e_pf *pf) |
e25d00b8 ASJ |
8439 | { |
8440 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; | |
8441 | u8 seed[I40E_HKEY_ARRAY_SIZE]; | |
e69ff813 | 8442 | u8 *lut; |
e25d00b8 ASJ |
8443 | struct i40e_hw *hw = &pf->hw; |
8444 | u32 reg_val; | |
8445 | u64 hena; | |
e69ff813 | 8446 | int ret; |
e25d00b8 | 8447 | |
41c445ff | 8448 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
272cdaf2 SN |
8449 | hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
8450 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); | |
e25d00b8 ASJ |
8451 | hena |= i40e_pf_get_default_rss_hena(pf); |
8452 | ||
272cdaf2 SN |
8453 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
8454 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); | |
41c445ff | 8455 | |
e25d00b8 | 8456 | /* Determine the RSS table size based on the hardware capabilities */ |
272cdaf2 | 8457 | reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0); |
e25d00b8 ASJ |
8458 | reg_val = (pf->rss_table_size == 512) ? |
8459 | (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) : | |
8460 | (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512); | |
272cdaf2 | 8461 | i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val); |
e157ea30 | 8462 | |
28c5869f | 8463 | /* Determine the RSS size of the VSI */ |
f25571b5 HR |
8464 | if (!vsi->rss_size) { |
8465 | u16 qcount; | |
8466 | ||
8467 | qcount = vsi->num_queue_pairs / vsi->tc_config.numtc; | |
8468 | vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount); | |
8469 | } | |
a4fa59cc MW |
8470 | if (!vsi->rss_size) |
8471 | return -EINVAL; | |
28c5869f | 8472 | |
e69ff813 HZ |
8473 | lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); |
8474 | if (!lut) | |
8475 | return -ENOMEM; | |
8476 | ||
28c5869f HZ |
8477 | /* Use user configured lut if there is one, otherwise use default */ |
8478 | if (vsi->rss_lut_user) | |
8479 | memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); | |
8480 | else | |
8481 | i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size); | |
e69ff813 | 8482 | |
28c5869f HZ |
8483 | /* Use user configured hash key if there is one, otherwise |
8484 | * use default. | |
8485 | */ | |
8486 | if (vsi->rss_hkey_user) | |
8487 | memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE); | |
8488 | else | |
8489 | netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE); | |
043dd650 | 8490 | ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size); |
e69ff813 HZ |
8491 | kfree(lut); |
8492 | ||
8493 | return ret; | |
41c445ff JB |
8494 | } |
8495 | ||
f8ff1464 ASJ |
8496 | /** |
8497 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild | |
8498 | * @pf: board private structure | |
8499 | * @queue_count: the requested queue count for rss. | |
8500 | * | |
8501 | * returns 0 if rss is not enabled, if enabled returns the final rss queue | |
8502 | * count which may be different from the requested queue count. | |
373149fc | 8503 | * Note: expects to be called while under rtnl_lock() |
f8ff1464 ASJ |
8504 | **/ |
8505 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) | |
8506 | { | |
9a3bd2f1 ASJ |
8507 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
8508 | int new_rss_size; | |
8509 | ||
f8ff1464 ASJ |
8510 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
8511 | return 0; | |
8512 | ||
9a3bd2f1 | 8513 | new_rss_size = min_t(int, queue_count, pf->rss_size_max); |
f8ff1464 | 8514 | |
9a3bd2f1 | 8515 | if (queue_count != vsi->num_queue_pairs) { |
f25571b5 HR |
8516 | u16 qcount; |
8517 | ||
9a3bd2f1 | 8518 | vsi->req_queue_pairs = queue_count; |
373149fc | 8519 | i40e_prep_for_reset(pf, true); |
f8ff1464 | 8520 | |
acd65448 | 8521 | pf->alloc_rss_size = new_rss_size; |
f8ff1464 | 8522 | |
373149fc | 8523 | i40e_reset_and_rebuild(pf, true, true); |
28c5869f HZ |
8524 | |
8525 | /* Discard the user configured hash keys and lut, if less | |
8526 | * queues are enabled. | |
8527 | */ | |
8528 | if (queue_count < vsi->rss_size) { | |
8529 | i40e_clear_rss_config_user(vsi); | |
8530 | dev_dbg(&pf->pdev->dev, | |
8531 | "discard user configured hash keys and lut\n"); | |
8532 | } | |
8533 | ||
8534 | /* Reset vsi->rss_size, as number of enabled queues changed */ | |
f25571b5 HR |
8535 | qcount = vsi->num_queue_pairs / vsi->tc_config.numtc; |
8536 | vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount); | |
28c5869f | 8537 | |
043dd650 | 8538 | i40e_pf_config_rss(pf); |
f8ff1464 | 8539 | } |
12815057 LY |
8540 | dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n", |
8541 | vsi->req_queue_pairs, pf->rss_size_max); | |
acd65448 | 8542 | return pf->alloc_rss_size; |
f8ff1464 ASJ |
8543 | } |
8544 | ||
f4492db1 GR |
8545 | /** |
8546 | * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition | |
8547 | * @pf: board private structure | |
8548 | **/ | |
8549 | i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf) | |
8550 | { | |
8551 | i40e_status status; | |
8552 | bool min_valid, max_valid; | |
8553 | u32 max_bw, min_bw; | |
8554 | ||
8555 | status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw, | |
8556 | &min_valid, &max_valid); | |
8557 | ||
8558 | if (!status) { | |
8559 | if (min_valid) | |
8560 | pf->npar_min_bw = min_bw; | |
8561 | if (max_valid) | |
8562 | pf->npar_max_bw = max_bw; | |
8563 | } | |
8564 | ||
8565 | return status; | |
8566 | } | |
8567 | ||
8568 | /** | |
8569 | * i40e_set_npar_bw_setting - Set BW settings for this PF partition | |
8570 | * @pf: board private structure | |
8571 | **/ | |
8572 | i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf) | |
8573 | { | |
8574 | struct i40e_aqc_configure_partition_bw_data bw_data; | |
8575 | i40e_status status; | |
8576 | ||
b40c82e6 | 8577 | /* Set the valid bit for this PF */ |
41a1d04b | 8578 | bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id)); |
f4492db1 GR |
8579 | bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK; |
8580 | bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK; | |
8581 | ||
8582 | /* Set the new bandwidths */ | |
8583 | status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL); | |
8584 | ||
8585 | return status; | |
8586 | } | |
8587 | ||
8588 | /** | |
8589 | * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition | |
8590 | * @pf: board private structure | |
8591 | **/ | |
8592 | i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf) | |
8593 | { | |
8594 | /* Commit temporary BW setting to permanent NVM image */ | |
8595 | enum i40e_admin_queue_err last_aq_status; | |
8596 | i40e_status ret; | |
8597 | u16 nvm_word; | |
8598 | ||
8599 | if (pf->hw.partition_id != 1) { | |
8600 | dev_info(&pf->pdev->dev, | |
8601 | "Commit BW only works on partition 1! This is partition %d", | |
8602 | pf->hw.partition_id); | |
8603 | ret = I40E_NOT_SUPPORTED; | |
8604 | goto bw_commit_out; | |
8605 | } | |
8606 | ||
8607 | /* Acquire NVM for read access */ | |
8608 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ); | |
8609 | last_aq_status = pf->hw.aq.asq_last_status; | |
8610 | if (ret) { | |
8611 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
8612 | "Cannot acquire NVM for read access, err %s aq_err %s\n", |
8613 | i40e_stat_str(&pf->hw, ret), | |
8614 | i40e_aq_str(&pf->hw, last_aq_status)); | |
f4492db1 GR |
8615 | goto bw_commit_out; |
8616 | } | |
8617 | ||
8618 | /* Read word 0x10 of NVM - SW compatibility word 1 */ | |
8619 | ret = i40e_aq_read_nvm(&pf->hw, | |
8620 | I40E_SR_NVM_CONTROL_WORD, | |
8621 | 0x10, sizeof(nvm_word), &nvm_word, | |
8622 | false, NULL); | |
8623 | /* Save off last admin queue command status before releasing | |
8624 | * the NVM | |
8625 | */ | |
8626 | last_aq_status = pf->hw.aq.asq_last_status; | |
8627 | i40e_release_nvm(&pf->hw); | |
8628 | if (ret) { | |
f1c7e72e SN |
8629 | dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n", |
8630 | i40e_stat_str(&pf->hw, ret), | |
8631 | i40e_aq_str(&pf->hw, last_aq_status)); | |
f4492db1 GR |
8632 | goto bw_commit_out; |
8633 | } | |
8634 | ||
8635 | /* Wait a bit for NVM release to complete */ | |
8636 | msleep(50); | |
8637 | ||
8638 | /* Acquire NVM for write access */ | |
8639 | ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE); | |
8640 | last_aq_status = pf->hw.aq.asq_last_status; | |
8641 | if (ret) { | |
8642 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
8643 | "Cannot acquire NVM for write access, err %s aq_err %s\n", |
8644 | i40e_stat_str(&pf->hw, ret), | |
8645 | i40e_aq_str(&pf->hw, last_aq_status)); | |
f4492db1 GR |
8646 | goto bw_commit_out; |
8647 | } | |
8648 | /* Write it back out unchanged to initiate update NVM, | |
8649 | * which will force a write of the shadow (alt) RAM to | |
8650 | * the NVM - thus storing the bandwidth values permanently. | |
8651 | */ | |
8652 | ret = i40e_aq_update_nvm(&pf->hw, | |
8653 | I40E_SR_NVM_CONTROL_WORD, | |
8654 | 0x10, sizeof(nvm_word), | |
8655 | &nvm_word, true, NULL); | |
8656 | /* Save off last admin queue command status before releasing | |
8657 | * the NVM | |
8658 | */ | |
8659 | last_aq_status = pf->hw.aq.asq_last_status; | |
8660 | i40e_release_nvm(&pf->hw); | |
8661 | if (ret) | |
8662 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
8663 | "BW settings NOT SAVED, err %s aq_err %s\n", |
8664 | i40e_stat_str(&pf->hw, ret), | |
8665 | i40e_aq_str(&pf->hw, last_aq_status)); | |
f4492db1 GR |
8666 | bw_commit_out: |
8667 | ||
8668 | return ret; | |
8669 | } | |
8670 | ||
41c445ff JB |
8671 | /** |
8672 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) | |
8673 | * @pf: board private structure to initialize | |
8674 | * | |
8675 | * i40e_sw_init initializes the Adapter private data structure. | |
8676 | * Fields are initialized based on PCI device information and | |
8677 | * OS network device settings (MTU size). | |
8678 | **/ | |
8679 | static int i40e_sw_init(struct i40e_pf *pf) | |
8680 | { | |
8681 | int err = 0; | |
8682 | int size; | |
8683 | ||
41c445ff JB |
8684 | /* Set default capability flags */ |
8685 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | | |
8686 | I40E_FLAG_MSI_ENABLED | | |
2bc7ee8a MW |
8687 | I40E_FLAG_MSIX_ENABLED; |
8688 | ||
ca99eb99 MW |
8689 | /* Set default ITR */ |
8690 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; | |
8691 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; | |
8692 | ||
7134f9ce JB |
8693 | /* Depending on PF configurations, it is possible that the RSS |
8694 | * maximum might end up larger than the available queues | |
8695 | */ | |
41a1d04b | 8696 | pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width); |
acd65448 | 8697 | pf->alloc_rss_size = 1; |
5db4cb59 | 8698 | pf->rss_table_size = pf->hw.func_caps.rss_table_size; |
7134f9ce JB |
8699 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
8700 | pf->hw.func_caps.num_tx_qp); | |
41c445ff JB |
8701 | if (pf->hw.func_caps.rss) { |
8702 | pf->flags |= I40E_FLAG_RSS_ENABLED; | |
acd65448 HZ |
8703 | pf->alloc_rss_size = min_t(int, pf->rss_size_max, |
8704 | num_online_cpus()); | |
41c445ff JB |
8705 | } |
8706 | ||
2050bc65 | 8707 | /* MFP mode enabled */ |
c78b953e | 8708 | if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) { |
2050bc65 CS |
8709 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
8710 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); | |
f4492db1 GR |
8711 | if (i40e_get_npar_bw_setting(pf)) |
8712 | dev_warn(&pf->pdev->dev, | |
8713 | "Could not get NPAR bw settings\n"); | |
8714 | else | |
8715 | dev_info(&pf->pdev->dev, | |
8716 | "Min BW = %8.8x, Max BW = %8.8x\n", | |
8717 | pf->npar_min_bw, pf->npar_max_bw); | |
2050bc65 CS |
8718 | } |
8719 | ||
cbf61325 ASJ |
8720 | /* FW/NVM is not yet fixed in this regard */ |
8721 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || | |
8722 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { | |
8723 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; | |
8724 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; | |
6eae9c6a SN |
8725 | if (pf->flags & I40E_FLAG_MFP_ENABLED && |
8726 | pf->hw.num_partitions > 1) | |
cbf61325 | 8727 | dev_info(&pf->pdev->dev, |
0b67584f | 8728 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
6eae9c6a SN |
8729 | else |
8730 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; | |
cbf61325 ASJ |
8731 | pf->fdir_pf_filter_count = |
8732 | pf->hw.func_caps.fd_filters_guaranteed; | |
8733 | pf->hw.fdir_shared_filter_count = | |
8734 | pf->hw.func_caps.fd_filters_best_effort; | |
41c445ff JB |
8735 | } |
8736 | ||
6de432c5 | 8737 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
8eed76fa | 8738 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) || |
f1bbad33 | 8739 | (pf->hw.aq.fw_maj_ver < 4))) { |
8eed76fa | 8740 | pf->flags |= I40E_FLAG_RESTART_AUTONEG; |
f1bbad33 NP |
8741 | /* No DCB support for FW < v4.33 */ |
8742 | pf->flags |= I40E_FLAG_NO_DCB_SUPPORT; | |
8743 | } | |
8744 | ||
8745 | /* Disable FW LLDP if FW < v4.3 */ | |
6de432c5 | 8746 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
f1bbad33 NP |
8747 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) || |
8748 | (pf->hw.aq.fw_maj_ver < 4))) | |
8749 | pf->flags |= I40E_FLAG_STOP_FW_LLDP; | |
8750 | ||
8751 | /* Use the FW Set LLDP MIB API if FW > v4.40 */ | |
6de432c5 | 8752 | if ((pf->hw.mac.type == I40E_MAC_XL710) && |
f1bbad33 NP |
8753 | (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) || |
8754 | (pf->hw.aq.fw_maj_ver >= 5))) | |
8755 | pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB; | |
8eed76fa | 8756 | |
41c445ff | 8757 | if (pf->hw.func_caps.vmdq) { |
41c445ff | 8758 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
e25d00b8 | 8759 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
e9e53662 | 8760 | pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf); |
41c445ff JB |
8761 | } |
8762 | ||
e3219ce6 ASJ |
8763 | if (pf->hw.func_caps.iwarp) { |
8764 | pf->flags |= I40E_FLAG_IWARP_ENABLED; | |
8765 | /* IWARP needs one extra vector for CQP just like MISC.*/ | |
8766 | pf->num_iwarp_msix = (int)num_online_cpus() + 1; | |
8767 | } | |
8768 | ||
41c445ff | 8769 | #ifdef CONFIG_PCI_IOV |
ba252f13 | 8770 | if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) { |
41c445ff JB |
8771 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
8772 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; | |
8773 | pf->num_req_vfs = min_t(int, | |
8774 | pf->hw.func_caps.num_vfs, | |
8775 | I40E_MAX_VF_COUNT); | |
8776 | } | |
8777 | #endif /* CONFIG_PCI_IOV */ | |
d502ce01 | 8778 | if (pf->hw.mac.type == I40E_MAC_X722) { |
1d68005d JH |
8779 | pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE |
8780 | | I40E_FLAG_128_QP_RSS_CAPABLE | |
8781 | | I40E_FLAG_HW_ATR_EVICT_CAPABLE | |
8782 | | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE | |
8783 | | I40E_FLAG_WB_ON_ITR_CAPABLE | |
8784 | | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE | |
8785 | | I40E_FLAG_NO_PCI_LINK_CHECK | |
8786 | | I40E_FLAG_USE_SET_LLDP_MIB | |
8787 | | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE | |
8788 | | I40E_FLAG_PTP_L4_CAPABLE | |
8789 | | I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE; | |
a340c789 AS |
8790 | } else if ((pf->hw.aq.api_maj_ver > 1) || |
8791 | ((pf->hw.aq.api_maj_ver == 1) && | |
8792 | (pf->hw.aq.api_min_ver > 4))) { | |
8793 | /* Supported in FW API version higher than 1.4 */ | |
8794 | pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE; | |
b77ac975 | 8795 | pf->hw_disabled_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
72b74869 | 8796 | } else { |
b77ac975 | 8797 | pf->hw_disabled_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
d502ce01 | 8798 | } |
a340c789 | 8799 | |
41c445ff JB |
8800 | pf->eeprom_version = 0xDEAD; |
8801 | pf->lan_veb = I40E_NO_VEB; | |
8802 | pf->lan_vsi = I40E_NO_VSI; | |
8803 | ||
d1a8d275 ASJ |
8804 | /* By default FW has this off for performance reasons */ |
8805 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; | |
8806 | ||
41c445ff JB |
8807 | /* set up queue assignment tracking */ |
8808 | size = sizeof(struct i40e_lump_tracking) | |
8809 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); | |
8810 | pf->qp_pile = kzalloc(size, GFP_KERNEL); | |
8811 | if (!pf->qp_pile) { | |
8812 | err = -ENOMEM; | |
8813 | goto sw_init_done; | |
8814 | } | |
8815 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; | |
8816 | pf->qp_pile->search_hint = 0; | |
8817 | ||
327fe04b ASJ |
8818 | pf->tx_timeout_recovery_level = 1; |
8819 | ||
41c445ff JB |
8820 | mutex_init(&pf->switch_mutex); |
8821 | ||
c668a12c GR |
8822 | /* If NPAR is enabled nudge the Tx scheduler */ |
8823 | if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf))) | |
8824 | i40e_set_npar_bw_setting(pf); | |
8825 | ||
41c445ff JB |
8826 | sw_init_done: |
8827 | return err; | |
8828 | } | |
8829 | ||
7c3c288b ASJ |
8830 | /** |
8831 | * i40e_set_ntuple - set the ntuple feature flag and take action | |
8832 | * @pf: board private structure to initialize | |
8833 | * @features: the feature set that the stack is suggesting | |
8834 | * | |
8835 | * returns a bool to indicate if reset needs to happen | |
8836 | **/ | |
8837 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) | |
8838 | { | |
8839 | bool need_reset = false; | |
8840 | ||
8841 | /* Check if Flow Director n-tuple support was enabled or disabled. If | |
8842 | * the state changed, we need to reset. | |
8843 | */ | |
8844 | if (features & NETIF_F_NTUPLE) { | |
8845 | /* Enable filters and mark for reset */ | |
8846 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) | |
8847 | need_reset = true; | |
a70e407f TD |
8848 | /* enable FD_SB only if there is MSI-X vector */ |
8849 | if (pf->num_fdsb_msix > 0) | |
8850 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; | |
7c3c288b ASJ |
8851 | } else { |
8852 | /* turn off filters, mark for reset and clear SW filter list */ | |
8853 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { | |
8854 | need_reset = true; | |
8855 | i40e_fdir_filter_exit(pf); | |
8856 | } | |
8857 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; | |
b77ac975 | 8858 | pf->hw_disabled_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
1e1be8f6 | 8859 | /* reset fd counters */ |
097dbf52 JK |
8860 | pf->fd_add_err = 0; |
8861 | pf->fd_atr_cnt = 0; | |
8a4f34fb ASJ |
8862 | /* if ATR was auto disabled it can be re-enabled. */ |
8863 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && | |
b77ac975 HR |
8864 | (pf->hw_disabled_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
8865 | pf->hw_disabled_flags &= ~I40E_FLAG_FD_ATR_ENABLED; | |
234dc4e6 JK |
8866 | if (I40E_DEBUG_FD & pf->hw.debug_mask) |
8867 | dev_info(&pf->pdev->dev, "ATR re-enabled.\n"); | |
8868 | } | |
7c3c288b ASJ |
8869 | } |
8870 | return need_reset; | |
8871 | } | |
8872 | ||
d8ec9864 AB |
8873 | /** |
8874 | * i40e_clear_rss_lut - clear the rx hash lookup table | |
8875 | * @vsi: the VSI being configured | |
8876 | **/ | |
8877 | static void i40e_clear_rss_lut(struct i40e_vsi *vsi) | |
8878 | { | |
8879 | struct i40e_pf *pf = vsi->back; | |
8880 | struct i40e_hw *hw = &pf->hw; | |
8881 | u16 vf_id = vsi->vf_id; | |
8882 | u8 i; | |
8883 | ||
8884 | if (vsi->type == I40E_VSI_MAIN) { | |
8885 | for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) | |
8886 | wr32(hw, I40E_PFQF_HLUT(i), 0); | |
8887 | } else if (vsi->type == I40E_VSI_SRIOV) { | |
8888 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) | |
8889 | i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0); | |
8890 | } else { | |
8891 | dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n"); | |
8892 | } | |
8893 | } | |
8894 | ||
41c445ff JB |
8895 | /** |
8896 | * i40e_set_features - set the netdev feature flags | |
8897 | * @netdev: ptr to the netdev being adjusted | |
8898 | * @features: the feature set that the stack is suggesting | |
373149fc | 8899 | * Note: expects to be called while under rtnl_lock() |
41c445ff JB |
8900 | **/ |
8901 | static int i40e_set_features(struct net_device *netdev, | |
8902 | netdev_features_t features) | |
8903 | { | |
8904 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
8905 | struct i40e_vsi *vsi = np->vsi; | |
7c3c288b ASJ |
8906 | struct i40e_pf *pf = vsi->back; |
8907 | bool need_reset; | |
41c445ff | 8908 | |
d8ec9864 AB |
8909 | if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH)) |
8910 | i40e_pf_config_rss(pf); | |
8911 | else if (!(features & NETIF_F_RXHASH) && | |
8912 | netdev->features & NETIF_F_RXHASH) | |
8913 | i40e_clear_rss_lut(vsi); | |
8914 | ||
41c445ff JB |
8915 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
8916 | i40e_vlan_stripping_enable(vsi); | |
8917 | else | |
8918 | i40e_vlan_stripping_disable(vsi); | |
8919 | ||
7c3c288b ASJ |
8920 | need_reset = i40e_set_ntuple(pf, features); |
8921 | ||
8922 | if (need_reset) | |
373149fc | 8923 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED), true); |
7c3c288b | 8924 | |
41c445ff JB |
8925 | return 0; |
8926 | } | |
8927 | ||
a1c9a9d9 | 8928 | /** |
6a899024 | 8929 | * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port |
a1c9a9d9 JK |
8930 | * @pf: board private structure |
8931 | * @port: The UDP port to look up | |
8932 | * | |
8933 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found | |
8934 | **/ | |
fe0b0cd9 | 8935 | static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, u16 port) |
a1c9a9d9 JK |
8936 | { |
8937 | u8 i; | |
8938 | ||
8939 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { | |
6a899024 | 8940 | if (pf->udp_ports[i].index == port) |
a1c9a9d9 JK |
8941 | return i; |
8942 | } | |
8943 | ||
8944 | return i; | |
8945 | } | |
8946 | ||
8947 | /** | |
06a5f7f1 | 8948 | * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up |
a1c9a9d9 | 8949 | * @netdev: This physical port's netdev |
06a5f7f1 | 8950 | * @ti: Tunnel endpoint information |
a1c9a9d9 | 8951 | **/ |
06a5f7f1 AD |
8952 | static void i40e_udp_tunnel_add(struct net_device *netdev, |
8953 | struct udp_tunnel_info *ti) | |
a1c9a9d9 JK |
8954 | { |
8955 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
8956 | struct i40e_vsi *vsi = np->vsi; | |
8957 | struct i40e_pf *pf = vsi->back; | |
fe0b0cd9 | 8958 | u16 port = ntohs(ti->port); |
a1c9a9d9 JK |
8959 | u8 next_idx; |
8960 | u8 idx; | |
8961 | ||
6a899024 | 8962 | idx = i40e_get_udp_port_idx(pf, port); |
a1c9a9d9 JK |
8963 | |
8964 | /* Check if port already exists */ | |
8965 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { | |
fe0b0cd9 | 8966 | netdev_info(netdev, "port %d already offloaded\n", port); |
a1c9a9d9 JK |
8967 | return; |
8968 | } | |
8969 | ||
8970 | /* Now check if there is space to add the new port */ | |
6a899024 | 8971 | next_idx = i40e_get_udp_port_idx(pf, 0); |
a1c9a9d9 JK |
8972 | |
8973 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { | |
06a5f7f1 | 8974 | netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n", |
fe0b0cd9 | 8975 | port); |
6a899024 SA |
8976 | return; |
8977 | } | |
8978 | ||
06a5f7f1 AD |
8979 | switch (ti->type) { |
8980 | case UDP_TUNNEL_TYPE_VXLAN: | |
8981 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN; | |
8982 | break; | |
8983 | case UDP_TUNNEL_TYPE_GENEVE: | |
8984 | if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)) | |
8985 | return; | |
8986 | pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE; | |
8987 | break; | |
8988 | default: | |
6a899024 SA |
8989 | return; |
8990 | } | |
8991 | ||
8992 | /* New port: add it and mark its index in the bitmap */ | |
8993 | pf->udp_ports[next_idx].index = port; | |
6a899024 SA |
8994 | pf->pending_udp_bitmap |= BIT_ULL(next_idx); |
8995 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; | |
a1c9a9d9 JK |
8996 | } |
8997 | ||
6a899024 | 8998 | /** |
06a5f7f1 | 8999 | * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away |
6a899024 | 9000 | * @netdev: This physical port's netdev |
06a5f7f1 | 9001 | * @ti: Tunnel endpoint information |
6a899024 | 9002 | **/ |
06a5f7f1 AD |
9003 | static void i40e_udp_tunnel_del(struct net_device *netdev, |
9004 | struct udp_tunnel_info *ti) | |
6a899024 | 9005 | { |
6a899024 SA |
9006 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
9007 | struct i40e_vsi *vsi = np->vsi; | |
9008 | struct i40e_pf *pf = vsi->back; | |
fe0b0cd9 | 9009 | u16 port = ntohs(ti->port); |
6a899024 SA |
9010 | u8 idx; |
9011 | ||
6a899024 SA |
9012 | idx = i40e_get_udp_port_idx(pf, port); |
9013 | ||
9014 | /* Check if port already exists */ | |
06a5f7f1 AD |
9015 | if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS) |
9016 | goto not_found; | |
6a899024 | 9017 | |
06a5f7f1 AD |
9018 | switch (ti->type) { |
9019 | case UDP_TUNNEL_TYPE_VXLAN: | |
9020 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN) | |
9021 | goto not_found; | |
9022 | break; | |
9023 | case UDP_TUNNEL_TYPE_GENEVE: | |
9024 | if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE) | |
9025 | goto not_found; | |
9026 | break; | |
9027 | default: | |
9028 | goto not_found; | |
6a899024 | 9029 | } |
06a5f7f1 AD |
9030 | |
9031 | /* if port exists, set it to 0 (mark for deletion) | |
9032 | * and make it pending | |
9033 | */ | |
9034 | pf->udp_ports[idx].index = 0; | |
9035 | pf->pending_udp_bitmap |= BIT_ULL(idx); | |
9036 | pf->flags |= I40E_FLAG_UDP_FILTER_SYNC; | |
9037 | ||
9038 | return; | |
9039 | not_found: | |
9040 | netdev_warn(netdev, "UDP port %d was not found, not deleting\n", | |
fe0b0cd9 | 9041 | port); |
6a899024 SA |
9042 | } |
9043 | ||
1f224ad2 | 9044 | static int i40e_get_phys_port_id(struct net_device *netdev, |
02637fce | 9045 | struct netdev_phys_item_id *ppid) |
1f224ad2 NP |
9046 | { |
9047 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
9048 | struct i40e_pf *pf = np->vsi->back; | |
9049 | struct i40e_hw *hw = &pf->hw; | |
9050 | ||
9051 | if (!(pf->flags & I40E_FLAG_PORT_ID_VALID)) | |
9052 | return -EOPNOTSUPP; | |
9053 | ||
9054 | ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id)); | |
9055 | memcpy(ppid->id, hw->mac.port_addr, ppid->id_len); | |
9056 | ||
9057 | return 0; | |
9058 | } | |
9059 | ||
2f90ade6 JB |
9060 | /** |
9061 | * i40e_ndo_fdb_add - add an entry to the hardware database | |
9062 | * @ndm: the input from the stack | |
9063 | * @tb: pointer to array of nladdr (unused) | |
9064 | * @dev: the net device pointer | |
9065 | * @addr: the MAC address entry being added | |
9066 | * @flags: instructions from stack about fdb operation | |
9067 | */ | |
4ba0dea5 GR |
9068 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
9069 | struct net_device *dev, | |
f6f6424b | 9070 | const unsigned char *addr, u16 vid, |
4ba0dea5 | 9071 | u16 flags) |
4ba0dea5 GR |
9072 | { |
9073 | struct i40e_netdev_priv *np = netdev_priv(dev); | |
9074 | struct i40e_pf *pf = np->vsi->back; | |
9075 | int err = 0; | |
9076 | ||
9077 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) | |
9078 | return -EOPNOTSUPP; | |
9079 | ||
65891fea OG |
9080 | if (vid) { |
9081 | pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name); | |
9082 | return -EINVAL; | |
9083 | } | |
9084 | ||
4ba0dea5 GR |
9085 | /* Hardware does not support aging addresses so if a |
9086 | * ndm_state is given only allow permanent addresses | |
9087 | */ | |
9088 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { | |
9089 | netdev_info(dev, "FDB only supports static addresses\n"); | |
9090 | return -EINVAL; | |
9091 | } | |
9092 | ||
9093 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) | |
9094 | err = dev_uc_add_excl(dev, addr); | |
9095 | else if (is_multicast_ether_addr(addr)) | |
9096 | err = dev_mc_add_excl(dev, addr); | |
9097 | else | |
9098 | err = -EINVAL; | |
9099 | ||
9100 | /* Only return duplicate errors if NLM_F_EXCL is set */ | |
9101 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) | |
9102 | err = 0; | |
9103 | ||
9104 | return err; | |
9105 | } | |
9106 | ||
51616018 NP |
9107 | /** |
9108 | * i40e_ndo_bridge_setlink - Set the hardware bridge mode | |
9109 | * @dev: the netdev being configured | |
9110 | * @nlh: RTNL message | |
9111 | * | |
9112 | * Inserts a new hardware bridge if not already created and | |
9113 | * enables the bridging mode requested (VEB or VEPA). If the | |
9114 | * hardware bridge has already been inserted and the request | |
9115 | * is to change the mode then that requires a PF reset to | |
9116 | * allow rebuild of the components with required hardware | |
9117 | * bridge mode enabled. | |
373149fc MS |
9118 | * |
9119 | * Note: expects to be called while under rtnl_lock() | |
51616018 NP |
9120 | **/ |
9121 | static int i40e_ndo_bridge_setlink(struct net_device *dev, | |
9df70b66 CW |
9122 | struct nlmsghdr *nlh, |
9123 | u16 flags) | |
51616018 NP |
9124 | { |
9125 | struct i40e_netdev_priv *np = netdev_priv(dev); | |
9126 | struct i40e_vsi *vsi = np->vsi; | |
9127 | struct i40e_pf *pf = vsi->back; | |
9128 | struct i40e_veb *veb = NULL; | |
9129 | struct nlattr *attr, *br_spec; | |
9130 | int i, rem; | |
9131 | ||
9132 | /* Only for PF VSI for now */ | |
9133 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) | |
9134 | return -EOPNOTSUPP; | |
9135 | ||
9136 | /* Find the HW bridge for PF VSI */ | |
9137 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { | |
9138 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) | |
9139 | veb = pf->veb[i]; | |
9140 | } | |
9141 | ||
9142 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); | |
9143 | ||
9144 | nla_for_each_nested(attr, br_spec, rem) { | |
9145 | __u16 mode; | |
9146 | ||
9147 | if (nla_type(attr) != IFLA_BRIDGE_MODE) | |
9148 | continue; | |
9149 | ||
9150 | mode = nla_get_u16(attr); | |
9151 | if ((mode != BRIDGE_MODE_VEPA) && | |
9152 | (mode != BRIDGE_MODE_VEB)) | |
9153 | return -EINVAL; | |
9154 | ||
9155 | /* Insert a new HW bridge */ | |
9156 | if (!veb) { | |
9157 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, | |
9158 | vsi->tc_config.enabled_tc); | |
9159 | if (veb) { | |
9160 | veb->bridge_mode = mode; | |
9161 | i40e_config_bridge_mode(veb); | |
9162 | } else { | |
9163 | /* No Bridge HW offload available */ | |
9164 | return -ENOENT; | |
9165 | } | |
9166 | break; | |
9167 | } else if (mode != veb->bridge_mode) { | |
9168 | /* Existing HW bridge but different mode needs reset */ | |
9169 | veb->bridge_mode = mode; | |
fc60861e ASJ |
9170 | /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */ |
9171 | if (mode == BRIDGE_MODE_VEB) | |
9172 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; | |
9173 | else | |
9174 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; | |
373149fc MS |
9175 | i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED), |
9176 | true); | |
51616018 NP |
9177 | break; |
9178 | } | |
9179 | } | |
9180 | ||
9181 | return 0; | |
9182 | } | |
9183 | ||
9184 | /** | |
9185 | * i40e_ndo_bridge_getlink - Get the hardware bridge mode | |
9186 | * @skb: skb buff | |
9187 | * @pid: process id | |
9188 | * @seq: RTNL message seq # | |
9189 | * @dev: the netdev being configured | |
9190 | * @filter_mask: unused | |
d4b2f9fe | 9191 | * @nlflags: netlink flags passed in |
51616018 NP |
9192 | * |
9193 | * Return the mode in which the hardware bridge is operating in | |
9194 | * i.e VEB or VEPA. | |
9195 | **/ | |
51616018 NP |
9196 | static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
9197 | struct net_device *dev, | |
9f4ffc44 CW |
9198 | u32 __always_unused filter_mask, |
9199 | int nlflags) | |
51616018 NP |
9200 | { |
9201 | struct i40e_netdev_priv *np = netdev_priv(dev); | |
9202 | struct i40e_vsi *vsi = np->vsi; | |
9203 | struct i40e_pf *pf = vsi->back; | |
9204 | struct i40e_veb *veb = NULL; | |
9205 | int i; | |
9206 | ||
9207 | /* Only for PF VSI for now */ | |
9208 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) | |
9209 | return -EOPNOTSUPP; | |
9210 | ||
9211 | /* Find the HW bridge for the PF VSI */ | |
9212 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { | |
9213 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) | |
9214 | veb = pf->veb[i]; | |
9215 | } | |
9216 | ||
9217 | if (!veb) | |
9218 | return 0; | |
9219 | ||
46c264da | 9220 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, |
599b076d | 9221 | 0, 0, nlflags, filter_mask, NULL); |
51616018 | 9222 | } |
51616018 | 9223 | |
f44a75e2 JS |
9224 | /** |
9225 | * i40e_features_check - Validate encapsulated packet conforms to limits | |
9226 | * @skb: skb buff | |
2bc11c63 | 9227 | * @dev: This physical port's netdev |
f44a75e2 JS |
9228 | * @features: Offload features that the stack believes apply |
9229 | **/ | |
9230 | static netdev_features_t i40e_features_check(struct sk_buff *skb, | |
9231 | struct net_device *dev, | |
9232 | netdev_features_t features) | |
9233 | { | |
f114dca2 AD |
9234 | size_t len; |
9235 | ||
9236 | /* No point in doing any of this if neither checksum nor GSO are | |
9237 | * being requested for this frame. We can rule out both by just | |
9238 | * checking for CHECKSUM_PARTIAL | |
9239 | */ | |
9240 | if (skb->ip_summed != CHECKSUM_PARTIAL) | |
9241 | return features; | |
9242 | ||
9243 | /* We cannot support GSO if the MSS is going to be less than | |
9244 | * 64 bytes. If it is then we need to drop support for GSO. | |
9245 | */ | |
9246 | if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64)) | |
9247 | features &= ~NETIF_F_GSO_MASK; | |
9248 | ||
9249 | /* MACLEN can support at most 63 words */ | |
9250 | len = skb_network_header(skb) - skb->data; | |
9251 | if (len & ~(63 * 2)) | |
9252 | goto out_err; | |
9253 | ||
9254 | /* IPLEN and EIPLEN can support at most 127 dwords */ | |
9255 | len = skb_transport_header(skb) - skb_network_header(skb); | |
9256 | if (len & ~(127 * 4)) | |
9257 | goto out_err; | |
9258 | ||
9259 | if (skb->encapsulation) { | |
9260 | /* L4TUNLEN can support 127 words */ | |
9261 | len = skb_inner_network_header(skb) - skb_transport_header(skb); | |
9262 | if (len & ~(127 * 2)) | |
9263 | goto out_err; | |
9264 | ||
9265 | /* IPLEN can support at most 127 dwords */ | |
9266 | len = skb_inner_transport_header(skb) - | |
9267 | skb_inner_network_header(skb); | |
9268 | if (len & ~(127 * 4)) | |
9269 | goto out_err; | |
9270 | } | |
9271 | ||
9272 | /* No need to validate L4LEN as TCP is the only protocol with a | |
9273 | * a flexible value and we support all possible values supported | |
9274 | * by TCP, which is at most 15 dwords | |
9275 | */ | |
f44a75e2 JS |
9276 | |
9277 | return features; | |
f114dca2 AD |
9278 | out_err: |
9279 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); | |
f44a75e2 JS |
9280 | } |
9281 | ||
37a2973a | 9282 | static const struct net_device_ops i40e_netdev_ops = { |
41c445ff JB |
9283 | .ndo_open = i40e_open, |
9284 | .ndo_stop = i40e_close, | |
9285 | .ndo_start_xmit = i40e_lan_xmit_frame, | |
9286 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, | |
9287 | .ndo_set_rx_mode = i40e_set_rx_mode, | |
9288 | .ndo_validate_addr = eth_validate_addr, | |
9289 | .ndo_set_mac_address = i40e_set_mac, | |
9290 | .ndo_change_mtu = i40e_change_mtu, | |
beb0dff1 | 9291 | .ndo_do_ioctl = i40e_ioctl, |
41c445ff JB |
9292 | .ndo_tx_timeout = i40e_tx_timeout, |
9293 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, | |
9294 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, | |
9295 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
9296 | .ndo_poll_controller = i40e_netpoll, | |
9297 | #endif | |
e4c6734e | 9298 | .ndo_setup_tc = __i40e_setup_tc, |
41c445ff JB |
9299 | .ndo_set_features = i40e_set_features, |
9300 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, | |
9301 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, | |
ed616689 | 9302 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
41c445ff | 9303 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
588aefa0 | 9304 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
e6d9004d | 9305 | .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk, |
c3bbbd20 | 9306 | .ndo_set_vf_trust = i40e_ndo_set_vf_trust, |
06a5f7f1 AD |
9307 | .ndo_udp_tunnel_add = i40e_udp_tunnel_add, |
9308 | .ndo_udp_tunnel_del = i40e_udp_tunnel_del, | |
1f224ad2 | 9309 | .ndo_get_phys_port_id = i40e_get_phys_port_id, |
4ba0dea5 | 9310 | .ndo_fdb_add = i40e_ndo_fdb_add, |
f44a75e2 | 9311 | .ndo_features_check = i40e_features_check, |
51616018 NP |
9312 | .ndo_bridge_getlink = i40e_ndo_bridge_getlink, |
9313 | .ndo_bridge_setlink = i40e_ndo_bridge_setlink, | |
41c445ff JB |
9314 | }; |
9315 | ||
9316 | /** | |
9317 | * i40e_config_netdev - Setup the netdev flags | |
9318 | * @vsi: the VSI being configured | |
9319 | * | |
9320 | * Returns 0 on success, negative value on failure | |
9321 | **/ | |
9322 | static int i40e_config_netdev(struct i40e_vsi *vsi) | |
9323 | { | |
9324 | struct i40e_pf *pf = vsi->back; | |
9325 | struct i40e_hw *hw = &pf->hw; | |
9326 | struct i40e_netdev_priv *np; | |
9327 | struct net_device *netdev; | |
435c084a | 9328 | u8 broadcast[ETH_ALEN]; |
41c445ff JB |
9329 | u8 mac_addr[ETH_ALEN]; |
9330 | int etherdev_size; | |
bacd75cf PB |
9331 | netdev_features_t hw_enc_features; |
9332 | netdev_features_t hw_features; | |
41c445ff JB |
9333 | |
9334 | etherdev_size = sizeof(struct i40e_netdev_priv); | |
f8ff1464 | 9335 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
41c445ff JB |
9336 | if (!netdev) |
9337 | return -ENOMEM; | |
9338 | ||
9339 | vsi->netdev = netdev; | |
9340 | np = netdev_priv(netdev); | |
9341 | np->vsi = vsi; | |
9342 | ||
bacd75cf PB |
9343 | hw_enc_features = NETIF_F_SG | |
9344 | NETIF_F_IP_CSUM | | |
9345 | NETIF_F_IPV6_CSUM | | |
9346 | NETIF_F_HIGHDMA | | |
9347 | NETIF_F_SOFT_FEATURES | | |
9348 | NETIF_F_TSO | | |
9349 | NETIF_F_TSO_ECN | | |
9350 | NETIF_F_TSO6 | | |
9351 | NETIF_F_GSO_GRE | | |
9352 | NETIF_F_GSO_GRE_CSUM | | |
9353 | NETIF_F_GSO_PARTIAL | | |
9354 | NETIF_F_GSO_UDP_TUNNEL | | |
9355 | NETIF_F_GSO_UDP_TUNNEL_CSUM | | |
9356 | NETIF_F_SCTP_CRC | | |
9357 | NETIF_F_RXHASH | | |
9358 | NETIF_F_RXCSUM | | |
9359 | 0; | |
41c445ff | 9360 | |
b0fe3306 | 9361 | if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE)) |
1c7b4a23 AD |
9362 | netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM; |
9363 | ||
9364 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; | |
b0fe3306 | 9365 | |
bacd75cf PB |
9366 | netdev->hw_enc_features |= hw_enc_features; |
9367 | ||
b0fe3306 | 9368 | /* record features VLANs can make use of */ |
bacd75cf | 9369 | netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID; |
41c445ff | 9370 | |
2e86a0b6 | 9371 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
b0fe3306 | 9372 | netdev->hw_features |= NETIF_F_NTUPLE; |
bacd75cf PB |
9373 | hw_features = hw_enc_features | |
9374 | NETIF_F_HW_VLAN_CTAG_TX | | |
9375 | NETIF_F_HW_VLAN_CTAG_RX; | |
b0fe3306 | 9376 | |
bacd75cf | 9377 | netdev->hw_features |= hw_features; |
2e86a0b6 | 9378 | |
bacd75cf | 9379 | netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; |
1c7b4a23 | 9380 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; |
41c445ff JB |
9381 | |
9382 | if (vsi->type == I40E_VSI_MAIN) { | |
9383 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); | |
9a173901 | 9384 | ether_addr_copy(mac_addr, hw->mac.perm_addr); |
41c4c2b5 JK |
9385 | /* The following steps are necessary for two reasons. First, |
9386 | * some older NVM configurations load a default MAC-VLAN | |
9387 | * filter that will accept any tagged packet, and we want to | |
9388 | * replace this with a normal filter. Additionally, it is | |
9389 | * possible our MAC address was provided by the platform using | |
9390 | * Open Firmware or similar. | |
9391 | * | |
9392 | * Thus, we need to remove the default filter and install one | |
9393 | * specific to the MAC address. | |
1596b5dd JK |
9394 | */ |
9395 | i40e_rm_default_mac_filter(vsi, mac_addr); | |
278e7d0b | 9396 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
9569a9a4 | 9397 | i40e_add_mac_filter(vsi, mac_addr); |
278e7d0b | 9398 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
41c445ff JB |
9399 | } else { |
9400 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ | |
9401 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", | |
9402 | pf->vsi[pf->lan_vsi]->netdev->name); | |
9403 | random_ether_addr(mac_addr); | |
21659035 | 9404 | |
278e7d0b | 9405 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
9569a9a4 | 9406 | i40e_add_mac_filter(vsi, mac_addr); |
278e7d0b | 9407 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
41c445ff | 9408 | } |
21659035 | 9409 | |
435c084a JK |
9410 | /* Add the broadcast filter so that we initially will receive |
9411 | * broadcast packets. Note that when a new VLAN is first added the | |
9412 | * driver will convert all filters marked I40E_VLAN_ANY into VLAN | |
9413 | * specific filters as part of transitioning into "vlan" operation. | |
9414 | * When more VLANs are added, the driver will copy each existing MAC | |
9415 | * filter and add it for the new VLAN. | |
9416 | * | |
9417 | * Broadcast filters are handled specially by | |
9418 | * i40e_sync_filters_subtask, as the driver must to set the broadcast | |
9419 | * promiscuous bit instead of adding this directly as a MAC/VLAN | |
9420 | * filter. The subtask will update the correct broadcast promiscuous | |
9421 | * bits as VLANs become active or inactive. | |
9422 | */ | |
9423 | eth_broadcast_addr(broadcast); | |
9424 | spin_lock_bh(&vsi->mac_filter_hash_lock); | |
9569a9a4 | 9425 | i40e_add_mac_filter(vsi, broadcast); |
435c084a JK |
9426 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
9427 | ||
9a173901 GR |
9428 | ether_addr_copy(netdev->dev_addr, mac_addr); |
9429 | ether_addr_copy(netdev->perm_addr, mac_addr); | |
b0fe3306 | 9430 | |
41c445ff JB |
9431 | netdev->priv_flags |= IFF_UNICAST_FLT; |
9432 | netdev->priv_flags |= IFF_SUPP_NOFCS; | |
9433 | /* Setup netdev TC information */ | |
9434 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); | |
9435 | ||
9436 | netdev->netdev_ops = &i40e_netdev_ops; | |
9437 | netdev->watchdog_timeo = 5 * HZ; | |
9438 | i40e_set_ethtool_ops(netdev); | |
9439 | ||
91c527a5 JW |
9440 | /* MTU range: 68 - 9706 */ |
9441 | netdev->min_mtu = ETH_MIN_MTU; | |
9442 | netdev->max_mtu = I40E_MAX_RXBUFFER - | |
9443 | (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); | |
9444 | ||
41c445ff JB |
9445 | return 0; |
9446 | } | |
9447 | ||
9448 | /** | |
9449 | * i40e_vsi_delete - Delete a VSI from the switch | |
9450 | * @vsi: the VSI being removed | |
9451 | * | |
9452 | * Returns 0 on success, negative value on failure | |
9453 | **/ | |
9454 | static void i40e_vsi_delete(struct i40e_vsi *vsi) | |
9455 | { | |
9456 | /* remove default VSI is not allowed */ | |
9457 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) | |
9458 | return; | |
9459 | ||
41c445ff | 9460 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
41c445ff JB |
9461 | } |
9462 | ||
51616018 NP |
9463 | /** |
9464 | * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB | |
9465 | * @vsi: the VSI being queried | |
9466 | * | |
9467 | * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode | |
9468 | **/ | |
9469 | int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi) | |
9470 | { | |
9471 | struct i40e_veb *veb; | |
9472 | struct i40e_pf *pf = vsi->back; | |
9473 | ||
9474 | /* Uplink is not a bridge so default to VEB */ | |
9475 | if (vsi->veb_idx == I40E_NO_VEB) | |
9476 | return 1; | |
9477 | ||
9478 | veb = pf->veb[vsi->veb_idx]; | |
09603eaa AA |
9479 | if (!veb) { |
9480 | dev_info(&pf->pdev->dev, | |
9481 | "There is no veb associated with the bridge\n"); | |
9482 | return -ENOENT; | |
9483 | } | |
9484 | ||
51616018 | 9485 | /* Uplink is a bridge in VEPA mode */ |
09603eaa | 9486 | if (veb->bridge_mode & BRIDGE_MODE_VEPA) { |
51616018 | 9487 | return 0; |
09603eaa AA |
9488 | } else { |
9489 | /* Uplink is a bridge in VEB mode */ | |
9490 | return 1; | |
9491 | } | |
51616018 | 9492 | |
09603eaa AA |
9493 | /* VEPA is now default bridge, so return 0 */ |
9494 | return 0; | |
51616018 NP |
9495 | } |
9496 | ||
41c445ff JB |
9497 | /** |
9498 | * i40e_add_vsi - Add a VSI to the switch | |
9499 | * @vsi: the VSI being configured | |
9500 | * | |
9501 | * This initializes a VSI context depending on the VSI type to be added and | |
9502 | * passes it down to the add_vsi aq command. | |
9503 | **/ | |
9504 | static int i40e_add_vsi(struct i40e_vsi *vsi) | |
9505 | { | |
9506 | int ret = -ENODEV; | |
41c445ff JB |
9507 | struct i40e_pf *pf = vsi->back; |
9508 | struct i40e_hw *hw = &pf->hw; | |
9509 | struct i40e_vsi_context ctxt; | |
278e7d0b JK |
9510 | struct i40e_mac_filter *f; |
9511 | struct hlist_node *h; | |
9512 | int bkt; | |
21659035 | 9513 | |
41c445ff JB |
9514 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
9515 | int f_count = 0; | |
9516 | ||
9517 | memset(&ctxt, 0, sizeof(ctxt)); | |
9518 | switch (vsi->type) { | |
9519 | case I40E_VSI_MAIN: | |
9520 | /* The PF's main VSI is already setup as part of the | |
9521 | * device initialization, so we'll not bother with | |
9522 | * the add_vsi call, but we will retrieve the current | |
9523 | * VSI context. | |
9524 | */ | |
9525 | ctxt.seid = pf->main_vsi_seid; | |
9526 | ctxt.pf_num = pf->hw.pf_id; | |
9527 | ctxt.vf_num = 0; | |
9528 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); | |
9529 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; | |
9530 | if (ret) { | |
9531 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
9532 | "couldn't get PF vsi config, err %s aq_err %s\n", |
9533 | i40e_stat_str(&pf->hw, ret), | |
9534 | i40e_aq_str(&pf->hw, | |
9535 | pf->hw.aq.asq_last_status)); | |
41c445ff JB |
9536 | return -ENOENT; |
9537 | } | |
1a2f6248 | 9538 | vsi->info = ctxt.info; |
41c445ff JB |
9539 | vsi->info.valid_sections = 0; |
9540 | ||
9541 | vsi->seid = ctxt.seid; | |
9542 | vsi->id = ctxt.vsi_number; | |
9543 | ||
9544 | enabled_tc = i40e_pf_get_tc_map(pf); | |
9545 | ||
9546 | /* MFP mode setup queue map and update VSI */ | |
63d7e5a4 NP |
9547 | if ((pf->flags & I40E_FLAG_MFP_ENABLED) && |
9548 | !(pf->hw.func_caps.iscsi)) { /* NIC type PF */ | |
41c445ff JB |
9549 | memset(&ctxt, 0, sizeof(ctxt)); |
9550 | ctxt.seid = pf->main_vsi_seid; | |
9551 | ctxt.pf_num = pf->hw.pf_id; | |
9552 | ctxt.vf_num = 0; | |
9553 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); | |
9554 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); | |
9555 | if (ret) { | |
9556 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
9557 | "update vsi failed, err %s aq_err %s\n", |
9558 | i40e_stat_str(&pf->hw, ret), | |
9559 | i40e_aq_str(&pf->hw, | |
9560 | pf->hw.aq.asq_last_status)); | |
41c445ff JB |
9561 | ret = -ENOENT; |
9562 | goto err; | |
9563 | } | |
9564 | /* update the local VSI info queue map */ | |
9565 | i40e_vsi_update_queue_map(vsi, &ctxt); | |
9566 | vsi->info.valid_sections = 0; | |
9567 | } else { | |
9568 | /* Default/Main VSI is only enabled for TC0 | |
9569 | * reconfigure it to enable all TCs that are | |
9570 | * available on the port in SFP mode. | |
63d7e5a4 NP |
9571 | * For MFP case the iSCSI PF would use this |
9572 | * flow to enable LAN+iSCSI TC. | |
41c445ff JB |
9573 | */ |
9574 | ret = i40e_vsi_config_tc(vsi, enabled_tc); | |
9575 | if (ret) { | |
9576 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
9577 | "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n", |
9578 | enabled_tc, | |
9579 | i40e_stat_str(&pf->hw, ret), | |
9580 | i40e_aq_str(&pf->hw, | |
9581 | pf->hw.aq.asq_last_status)); | |
41c445ff JB |
9582 | ret = -ENOENT; |
9583 | } | |
9584 | } | |
9585 | break; | |
9586 | ||
9587 | case I40E_VSI_FDIR: | |
cbf61325 ASJ |
9588 | ctxt.pf_num = hw->pf_id; |
9589 | ctxt.vf_num = 0; | |
9590 | ctxt.uplink_seid = vsi->uplink_seid; | |
2b18e591 | 9591 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
cbf61325 | 9592 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
fc60861e ASJ |
9593 | if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) && |
9594 | (i40e_is_vsi_uplink_mode_veb(vsi))) { | |
51616018 | 9595 | ctxt.info.valid_sections |= |
fc60861e | 9596 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
51616018 | 9597 | ctxt.info.switch_id = |
fc60861e | 9598 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
51616018 | 9599 | } |
41c445ff | 9600 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
41c445ff JB |
9601 | break; |
9602 | ||
9603 | case I40E_VSI_VMDQ2: | |
9604 | ctxt.pf_num = hw->pf_id; | |
9605 | ctxt.vf_num = 0; | |
9606 | ctxt.uplink_seid = vsi->uplink_seid; | |
2b18e591 | 9607 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
41c445ff JB |
9608 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
9609 | ||
41c445ff JB |
9610 | /* This VSI is connected to VEB so the switch_id |
9611 | * should be set to zero by default. | |
9612 | */ | |
51616018 NP |
9613 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
9614 | ctxt.info.valid_sections |= | |
9615 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); | |
9616 | ctxt.info.switch_id = | |
9617 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); | |
9618 | } | |
41c445ff JB |
9619 | |
9620 | /* Setup the VSI tx/rx queue map for TC0 only for now */ | |
9621 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); | |
9622 | break; | |
9623 | ||
9624 | case I40E_VSI_SRIOV: | |
9625 | ctxt.pf_num = hw->pf_id; | |
9626 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; | |
9627 | ctxt.uplink_seid = vsi->uplink_seid; | |
2b18e591 | 9628 | ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL; |
41c445ff JB |
9629 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
9630 | ||
41c445ff JB |
9631 | /* This VSI is connected to VEB so the switch_id |
9632 | * should be set to zero by default. | |
9633 | */ | |
51616018 NP |
9634 | if (i40e_is_vsi_uplink_mode_veb(vsi)) { |
9635 | ctxt.info.valid_sections |= | |
9636 | cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); | |
9637 | ctxt.info.switch_id = | |
9638 | cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); | |
9639 | } | |
41c445ff | 9640 | |
e3219ce6 ASJ |
9641 | if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) { |
9642 | ctxt.info.valid_sections |= | |
9643 | cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID); | |
9644 | ctxt.info.queueing_opt_flags |= | |
4b28cdba AS |
9645 | (I40E_AQ_VSI_QUE_OPT_TCP_ENA | |
9646 | I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI); | |
e3219ce6 ASJ |
9647 | } |
9648 | ||
41c445ff JB |
9649 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
9650 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; | |
c674d125 MW |
9651 | if (pf->vf[vsi->vf_id].spoofchk) { |
9652 | ctxt.info.valid_sections |= | |
9653 | cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); | |
9654 | ctxt.info.sec_flags |= | |
9655 | (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK | | |
9656 | I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK); | |
9657 | } | |
41c445ff JB |
9658 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
9659 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); | |
9660 | break; | |
9661 | ||
e3219ce6 ASJ |
9662 | case I40E_VSI_IWARP: |
9663 | /* send down message to iWARP */ | |
9664 | break; | |
9665 | ||
41c445ff JB |
9666 | default: |
9667 | return -ENODEV; | |
9668 | } | |
9669 | ||
9670 | if (vsi->type != I40E_VSI_MAIN) { | |
9671 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); | |
9672 | if (ret) { | |
9673 | dev_info(&vsi->back->pdev->dev, | |
f1c7e72e SN |
9674 | "add vsi failed, err %s aq_err %s\n", |
9675 | i40e_stat_str(&pf->hw, ret), | |
9676 | i40e_aq_str(&pf->hw, | |
9677 | pf->hw.aq.asq_last_status)); | |
41c445ff JB |
9678 | ret = -ENOENT; |
9679 | goto err; | |
9680 | } | |
1a2f6248 | 9681 | vsi->info = ctxt.info; |
41c445ff JB |
9682 | vsi->info.valid_sections = 0; |
9683 | vsi->seid = ctxt.seid; | |
9684 | vsi->id = ctxt.vsi_number; | |
9685 | } | |
9686 | ||
c3c7ea27 MW |
9687 | vsi->active_filters = 0; |
9688 | clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state); | |
278e7d0b | 9689 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
41c445ff | 9690 | /* If macvlan filters already exist, force them to get loaded */ |
278e7d0b | 9691 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { |
c3c7ea27 | 9692 | f->state = I40E_FILTER_NEW; |
41c445ff | 9693 | f_count++; |
21659035 | 9694 | } |
278e7d0b | 9695 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
30650cc5 | 9696 | |
41c445ff JB |
9697 | if (f_count) { |
9698 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; | |
9699 | pf->flags |= I40E_FLAG_FILTER_SYNC; | |
9700 | } | |
9701 | ||
9702 | /* Update VSI BW information */ | |
9703 | ret = i40e_vsi_get_bw_info(vsi); | |
9704 | if (ret) { | |
9705 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
9706 | "couldn't get vsi bw info, err %s aq_err %s\n", |
9707 | i40e_stat_str(&pf->hw, ret), | |
9708 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
41c445ff JB |
9709 | /* VSI is already added so not tearing that up */ |
9710 | ret = 0; | |
9711 | } | |
9712 | ||
9713 | err: | |
9714 | return ret; | |
9715 | } | |
9716 | ||
9717 | /** | |
9718 | * i40e_vsi_release - Delete a VSI and free its resources | |
9719 | * @vsi: the VSI being removed | |
9720 | * | |
9721 | * Returns 0 on success or < 0 on error | |
9722 | **/ | |
9723 | int i40e_vsi_release(struct i40e_vsi *vsi) | |
9724 | { | |
278e7d0b JK |
9725 | struct i40e_mac_filter *f; |
9726 | struct hlist_node *h; | |
41c445ff JB |
9727 | struct i40e_veb *veb = NULL; |
9728 | struct i40e_pf *pf; | |
9729 | u16 uplink_seid; | |
278e7d0b | 9730 | int i, n, bkt; |
41c445ff JB |
9731 | |
9732 | pf = vsi->back; | |
9733 | ||
9734 | /* release of a VEB-owner or last VSI is not allowed */ | |
9735 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { | |
9736 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", | |
9737 | vsi->seid, vsi->uplink_seid); | |
9738 | return -ENODEV; | |
9739 | } | |
9740 | if (vsi == pf->vsi[pf->lan_vsi] && | |
9741 | !test_bit(__I40E_DOWN, &pf->state)) { | |
9742 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); | |
9743 | return -ENODEV; | |
9744 | } | |
9745 | ||
9746 | uplink_seid = vsi->uplink_seid; | |
9747 | if (vsi->type != I40E_VSI_SRIOV) { | |
9748 | if (vsi->netdev_registered) { | |
9749 | vsi->netdev_registered = false; | |
9750 | if (vsi->netdev) { | |
9751 | /* results in a call to i40e_close() */ | |
9752 | unregister_netdev(vsi->netdev); | |
41c445ff JB |
9753 | } |
9754 | } else { | |
90ef8d47 | 9755 | i40e_vsi_close(vsi); |
41c445ff JB |
9756 | } |
9757 | i40e_vsi_disable_irq(vsi); | |
9758 | } | |
9759 | ||
278e7d0b | 9760 | spin_lock_bh(&vsi->mac_filter_hash_lock); |
6622f5cd JK |
9761 | |
9762 | /* clear the sync flag on all filters */ | |
9763 | if (vsi->netdev) { | |
9764 | __dev_uc_unsync(vsi->netdev, NULL); | |
9765 | __dev_mc_unsync(vsi->netdev, NULL); | |
9766 | } | |
9767 | ||
9768 | /* make sure any remaining filters are marked for deletion */ | |
278e7d0b | 9769 | hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) |
290d2557 | 9770 | __i40e_del_filter(vsi, f); |
6622f5cd | 9771 | |
278e7d0b | 9772 | spin_unlock_bh(&vsi->mac_filter_hash_lock); |
21659035 | 9773 | |
17652c63 | 9774 | i40e_sync_vsi_filters(vsi); |
41c445ff JB |
9775 | |
9776 | i40e_vsi_delete(vsi); | |
9777 | i40e_vsi_free_q_vectors(vsi); | |
a4866597 SN |
9778 | if (vsi->netdev) { |
9779 | free_netdev(vsi->netdev); | |
9780 | vsi->netdev = NULL; | |
9781 | } | |
41c445ff JB |
9782 | i40e_vsi_clear_rings(vsi); |
9783 | i40e_vsi_clear(vsi); | |
9784 | ||
9785 | /* If this was the last thing on the VEB, except for the | |
9786 | * controlling VSI, remove the VEB, which puts the controlling | |
9787 | * VSI onto the next level down in the switch. | |
9788 | * | |
9789 | * Well, okay, there's one more exception here: don't remove | |
9790 | * the orphan VEBs yet. We'll wait for an explicit remove request | |
9791 | * from up the network stack. | |
9792 | */ | |
505682cd | 9793 | for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) { |
41c445ff JB |
9794 | if (pf->vsi[i] && |
9795 | pf->vsi[i]->uplink_seid == uplink_seid && | |
9796 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { | |
9797 | n++; /* count the VSIs */ | |
9798 | } | |
9799 | } | |
9800 | for (i = 0; i < I40E_MAX_VEB; i++) { | |
9801 | if (!pf->veb[i]) | |
9802 | continue; | |
9803 | if (pf->veb[i]->uplink_seid == uplink_seid) | |
9804 | n++; /* count the VEBs */ | |
9805 | if (pf->veb[i]->seid == uplink_seid) | |
9806 | veb = pf->veb[i]; | |
9807 | } | |
9808 | if (n == 0 && veb && veb->uplink_seid != 0) | |
9809 | i40e_veb_release(veb); | |
9810 | ||
9811 | return 0; | |
9812 | } | |
9813 | ||
9814 | /** | |
9815 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI | |
9816 | * @vsi: ptr to the VSI | |
9817 | * | |
9818 | * This should only be called after i40e_vsi_mem_alloc() which allocates the | |
9819 | * corresponding SW VSI structure and initializes num_queue_pairs for the | |
9820 | * newly allocated VSI. | |
9821 | * | |
9822 | * Returns 0 on success or negative on failure | |
9823 | **/ | |
9824 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) | |
9825 | { | |
9826 | int ret = -ENOENT; | |
9827 | struct i40e_pf *pf = vsi->back; | |
9828 | ||
493fb300 | 9829 | if (vsi->q_vectors[0]) { |
41c445ff JB |
9830 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
9831 | vsi->seid); | |
9832 | return -EEXIST; | |
9833 | } | |
9834 | ||
9835 | if (vsi->base_vector) { | |
f29eaa3d | 9836 | dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n", |
41c445ff JB |
9837 | vsi->seid, vsi->base_vector); |
9838 | return -EEXIST; | |
9839 | } | |
9840 | ||
90e04070 | 9841 | ret = i40e_vsi_alloc_q_vectors(vsi); |
41c445ff JB |
9842 | if (ret) { |
9843 | dev_info(&pf->pdev->dev, | |
9844 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", | |
9845 | vsi->num_q_vectors, vsi->seid, ret); | |
9846 | vsi->num_q_vectors = 0; | |
9847 | goto vector_setup_out; | |
9848 | } | |
9849 | ||
26cdc443 ASJ |
9850 | /* In Legacy mode, we do not have to get any other vector since we |
9851 | * piggyback on the misc/ICR0 for queue interrupts. | |
9852 | */ | |
9853 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) | |
9854 | return ret; | |
958a3e3b SN |
9855 | if (vsi->num_q_vectors) |
9856 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, | |
9857 | vsi->num_q_vectors, vsi->idx); | |
41c445ff JB |
9858 | if (vsi->base_vector < 0) { |
9859 | dev_info(&pf->pdev->dev, | |
049a2be8 SN |
9860 | "failed to get tracking for %d vectors for VSI %d, err=%d\n", |
9861 | vsi->num_q_vectors, vsi->seid, vsi->base_vector); | |
41c445ff JB |
9862 | i40e_vsi_free_q_vectors(vsi); |
9863 | ret = -ENOENT; | |
9864 | goto vector_setup_out; | |
9865 | } | |
9866 | ||
9867 | vector_setup_out: | |
9868 | return ret; | |
9869 | } | |
9870 | ||
bc7d338f ASJ |
9871 | /** |
9872 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI | |
9873 | * @vsi: pointer to the vsi. | |
9874 | * | |
9875 | * This re-allocates a vsi's queue resources. | |
9876 | * | |
9877 | * Returns pointer to the successfully allocated and configured VSI sw struct | |
9878 | * on success, otherwise returns NULL on failure. | |
9879 | **/ | |
9880 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) | |
9881 | { | |
f534039d | 9882 | struct i40e_pf *pf; |
bc7d338f ASJ |
9883 | u8 enabled_tc; |
9884 | int ret; | |
9885 | ||
f534039d JU |
9886 | if (!vsi) |
9887 | return NULL; | |
9888 | ||
9889 | pf = vsi->back; | |
9890 | ||
bc7d338f ASJ |
9891 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
9892 | i40e_vsi_clear_rings(vsi); | |
9893 | ||
9894 | i40e_vsi_free_arrays(vsi, false); | |
9895 | i40e_set_num_rings_in_vsi(vsi); | |
9896 | ret = i40e_vsi_alloc_arrays(vsi, false); | |
9897 | if (ret) | |
9898 | goto err_vsi; | |
9899 | ||
9900 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); | |
9901 | if (ret < 0) { | |
049a2be8 | 9902 | dev_info(&pf->pdev->dev, |
f1c7e72e | 9903 | "failed to get tracking for %d queues for VSI %d err %d\n", |
049a2be8 | 9904 | vsi->alloc_queue_pairs, vsi->seid, ret); |
bc7d338f ASJ |
9905 | goto err_vsi; |
9906 | } | |
9907 | vsi->base_queue = ret; | |
9908 | ||
9909 | /* Update the FW view of the VSI. Force a reset of TC and queue | |
9910 | * layout configurations. | |
9911 | */ | |
9912 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; | |
9913 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; | |
9914 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; | |
9915 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); | |
1596b5dd JK |
9916 | if (vsi->type == I40E_VSI_MAIN) |
9917 | i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr); | |
bc7d338f ASJ |
9918 | |
9919 | /* assign it some queues */ | |
9920 | ret = i40e_alloc_rings(vsi); | |
9921 | if (ret) | |
9922 | goto err_rings; | |
9923 | ||
9924 | /* map all of the rings to the q_vectors */ | |
9925 | i40e_vsi_map_rings_to_vectors(vsi); | |
9926 | return vsi; | |
9927 | ||
9928 | err_rings: | |
9929 | i40e_vsi_free_q_vectors(vsi); | |
9930 | if (vsi->netdev_registered) { | |
9931 | vsi->netdev_registered = false; | |
9932 | unregister_netdev(vsi->netdev); | |
9933 | free_netdev(vsi->netdev); | |
9934 | vsi->netdev = NULL; | |
9935 | } | |
9936 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); | |
9937 | err_vsi: | |
9938 | i40e_vsi_clear(vsi); | |
9939 | return NULL; | |
9940 | } | |
9941 | ||
41c445ff JB |
9942 | /** |
9943 | * i40e_vsi_setup - Set up a VSI by a given type | |
9944 | * @pf: board private structure | |
9945 | * @type: VSI type | |
9946 | * @uplink_seid: the switch element to link to | |
9947 | * @param1: usage depends upon VSI type. For VF types, indicates VF id | |
9948 | * | |
9949 | * This allocates the sw VSI structure and its queue resources, then add a VSI | |
9950 | * to the identified VEB. | |
9951 | * | |
9952 | * Returns pointer to the successfully allocated and configure VSI sw struct on | |
9953 | * success, otherwise returns NULL on failure. | |
9954 | **/ | |
9955 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, | |
9956 | u16 uplink_seid, u32 param1) | |
9957 | { | |
9958 | struct i40e_vsi *vsi = NULL; | |
9959 | struct i40e_veb *veb = NULL; | |
9960 | int ret, i; | |
9961 | int v_idx; | |
9962 | ||
9963 | /* The requested uplink_seid must be either | |
9964 | * - the PF's port seid | |
9965 | * no VEB is needed because this is the PF | |
9966 | * or this is a Flow Director special case VSI | |
9967 | * - seid of an existing VEB | |
9968 | * - seid of a VSI that owns an existing VEB | |
9969 | * - seid of a VSI that doesn't own a VEB | |
9970 | * a new VEB is created and the VSI becomes the owner | |
9971 | * - seid of the PF VSI, which is what creates the first VEB | |
9972 | * this is a special case of the previous | |
9973 | * | |
9974 | * Find which uplink_seid we were given and create a new VEB if needed | |
9975 | */ | |
9976 | for (i = 0; i < I40E_MAX_VEB; i++) { | |
9977 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { | |
9978 | veb = pf->veb[i]; | |
9979 | break; | |
9980 | } | |
9981 | } | |
9982 | ||
9983 | if (!veb && uplink_seid != pf->mac_seid) { | |
9984 | ||
505682cd | 9985 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
41c445ff JB |
9986 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
9987 | vsi = pf->vsi[i]; | |
9988 | break; | |
9989 | } | |
9990 | } | |
9991 | if (!vsi) { | |
9992 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", | |
9993 | uplink_seid); | |
9994 | return NULL; | |
9995 | } | |
9996 | ||
9997 | if (vsi->uplink_seid == pf->mac_seid) | |
9998 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, | |
9999 | vsi->tc_config.enabled_tc); | |
10000 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) | |
10001 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, | |
10002 | vsi->tc_config.enabled_tc); | |
79c21a82 ASJ |
10003 | if (veb) { |
10004 | if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) { | |
10005 | dev_info(&vsi->back->pdev->dev, | |
fb43201f | 10006 | "New VSI creation error, uplink seid of LAN VSI expected.\n"); |
79c21a82 ASJ |
10007 | return NULL; |
10008 | } | |
fa11cb3d ASJ |
10009 | /* We come up by default in VEPA mode if SRIOV is not |
10010 | * already enabled, in which case we can't force VEPA | |
10011 | * mode. | |
10012 | */ | |
10013 | if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) { | |
10014 | veb->bridge_mode = BRIDGE_MODE_VEPA; | |
10015 | pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED; | |
10016 | } | |
51616018 | 10017 | i40e_config_bridge_mode(veb); |
79c21a82 | 10018 | } |
41c445ff JB |
10019 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
10020 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) | |
10021 | veb = pf->veb[i]; | |
10022 | } | |
10023 | if (!veb) { | |
10024 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); | |
10025 | return NULL; | |
10026 | } | |
10027 | ||
10028 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; | |
10029 | uplink_seid = veb->seid; | |
10030 | } | |
10031 | ||
10032 | /* get vsi sw struct */ | |
10033 | v_idx = i40e_vsi_mem_alloc(pf, type); | |
10034 | if (v_idx < 0) | |
10035 | goto err_alloc; | |
10036 | vsi = pf->vsi[v_idx]; | |
cbf61325 ASJ |
10037 | if (!vsi) |
10038 | goto err_alloc; | |
41c445ff JB |
10039 | vsi->type = type; |
10040 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); | |
10041 | ||
10042 | if (type == I40E_VSI_MAIN) | |
10043 | pf->lan_vsi = v_idx; | |
10044 | else if (type == I40E_VSI_SRIOV) | |
10045 | vsi->vf_id = param1; | |
10046 | /* assign it some queues */ | |
cbf61325 ASJ |
10047 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
10048 | vsi->idx); | |
41c445ff | 10049 | if (ret < 0) { |
049a2be8 SN |
10050 | dev_info(&pf->pdev->dev, |
10051 | "failed to get tracking for %d queues for VSI %d err=%d\n", | |
10052 | vsi->alloc_queue_pairs, vsi->seid, ret); | |
41c445ff JB |
10053 | goto err_vsi; |
10054 | } | |
10055 | vsi->base_queue = ret; | |
10056 | ||
10057 | /* get a VSI from the hardware */ | |
10058 | vsi->uplink_seid = uplink_seid; | |
10059 | ret = i40e_add_vsi(vsi); | |
10060 | if (ret) | |
10061 | goto err_vsi; | |
10062 | ||
10063 | switch (vsi->type) { | |
10064 | /* setup the netdev if needed */ | |
10065 | case I40E_VSI_MAIN: | |
b499ffb0 SV |
10066 | /* Apply relevant filters if a platform-specific mac |
10067 | * address was selected. | |
10068 | */ | |
10069 | if (!!(pf->flags & I40E_FLAG_PF_MAC)) { | |
10070 | ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); | |
10071 | if (ret) { | |
10072 | dev_warn(&pf->pdev->dev, | |
10073 | "could not set up macaddr; err %d\n", | |
10074 | ret); | |
10075 | } | |
10076 | } | |
41c445ff JB |
10077 | case I40E_VSI_VMDQ2: |
10078 | ret = i40e_config_netdev(vsi); | |
10079 | if (ret) | |
10080 | goto err_netdev; | |
10081 | ret = register_netdev(vsi->netdev); | |
10082 | if (ret) | |
10083 | goto err_netdev; | |
10084 | vsi->netdev_registered = true; | |
10085 | netif_carrier_off(vsi->netdev); | |
4e3b35b0 NP |
10086 | #ifdef CONFIG_I40E_DCB |
10087 | /* Setup DCB netlink interface */ | |
10088 | i40e_dcbnl_setup(vsi); | |
10089 | #endif /* CONFIG_I40E_DCB */ | |
41c445ff JB |
10090 | /* fall through */ |
10091 | ||
10092 | case I40E_VSI_FDIR: | |
10093 | /* set up vectors and rings if needed */ | |
10094 | ret = i40e_vsi_setup_vectors(vsi); | |
10095 | if (ret) | |
10096 | goto err_msix; | |
10097 | ||
10098 | ret = i40e_alloc_rings(vsi); | |
10099 | if (ret) | |
10100 | goto err_rings; | |
10101 | ||
10102 | /* map all of the rings to the q_vectors */ | |
10103 | i40e_vsi_map_rings_to_vectors(vsi); | |
10104 | ||
10105 | i40e_vsi_reset_stats(vsi); | |
10106 | break; | |
10107 | ||
10108 | default: | |
10109 | /* no netdev or rings for the other VSI types */ | |
10110 | break; | |
10111 | } | |
10112 | ||
e25d00b8 ASJ |
10113 | if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) && |
10114 | (vsi->type == I40E_VSI_VMDQ2)) { | |
10115 | ret = i40e_vsi_config_rss(vsi); | |
10116 | } | |
41c445ff JB |
10117 | return vsi; |
10118 | ||
10119 | err_rings: | |
10120 | i40e_vsi_free_q_vectors(vsi); | |
10121 | err_msix: | |
10122 | if (vsi->netdev_registered) { | |
10123 | vsi->netdev_registered = false; | |
10124 | unregister_netdev(vsi->netdev); | |
10125 | free_netdev(vsi->netdev); | |
10126 | vsi->netdev = NULL; | |
10127 | } | |
10128 | err_netdev: | |
10129 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); | |
10130 | err_vsi: | |
10131 | i40e_vsi_clear(vsi); | |
10132 | err_alloc: | |
10133 | return NULL; | |
10134 | } | |
10135 | ||
10136 | /** | |
10137 | * i40e_veb_get_bw_info - Query VEB BW information | |
10138 | * @veb: the veb to query | |
10139 | * | |
10140 | * Query the Tx scheduler BW configuration data for given VEB | |
10141 | **/ | |
10142 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) | |
10143 | { | |
10144 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; | |
10145 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; | |
10146 | struct i40e_pf *pf = veb->pf; | |
10147 | struct i40e_hw *hw = &pf->hw; | |
10148 | u32 tc_bw_max; | |
10149 | int ret = 0; | |
10150 | int i; | |
10151 | ||
10152 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, | |
10153 | &bw_data, NULL); | |
10154 | if (ret) { | |
10155 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
10156 | "query veb bw config failed, err %s aq_err %s\n", |
10157 | i40e_stat_str(&pf->hw, ret), | |
10158 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); | |
41c445ff JB |
10159 | goto out; |
10160 | } | |
10161 | ||
10162 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, | |
10163 | &ets_data, NULL); | |
10164 | if (ret) { | |
10165 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
10166 | "query veb bw ets config failed, err %s aq_err %s\n", |
10167 | i40e_stat_str(&pf->hw, ret), | |
10168 | i40e_aq_str(&pf->hw, hw->aq.asq_last_status)); | |
41c445ff JB |
10169 | goto out; |
10170 | } | |
10171 | ||
10172 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); | |
10173 | veb->bw_max_quanta = ets_data.tc_bw_max; | |
10174 | veb->is_abs_credits = bw_data.absolute_credits_enable; | |
23cd1f09 | 10175 | veb->enabled_tc = ets_data.tc_valid_bits; |
41c445ff JB |
10176 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
10177 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); | |
10178 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
10179 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; | |
10180 | veb->bw_tc_limit_credits[i] = | |
10181 | le16_to_cpu(bw_data.tc_bw_limits[i]); | |
10182 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); | |
10183 | } | |
10184 | ||
10185 | out: | |
10186 | return ret; | |
10187 | } | |
10188 | ||
10189 | /** | |
10190 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF | |
10191 | * @pf: board private structure | |
10192 | * | |
10193 | * On error: returns error code (negative) | |
10194 | * On success: returns vsi index in PF (positive) | |
10195 | **/ | |
10196 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) | |
10197 | { | |
10198 | int ret = -ENOENT; | |
10199 | struct i40e_veb *veb; | |
10200 | int i; | |
10201 | ||
10202 | /* Need to protect the allocation of switch elements at the PF level */ | |
10203 | mutex_lock(&pf->switch_mutex); | |
10204 | ||
10205 | /* VEB list may be fragmented if VEB creation/destruction has | |
10206 | * been happening. We can afford to do a quick scan to look | |
10207 | * for any free slots in the list. | |
10208 | * | |
10209 | * find next empty veb slot, looping back around if necessary | |
10210 | */ | |
10211 | i = 0; | |
10212 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) | |
10213 | i++; | |
10214 | if (i >= I40E_MAX_VEB) { | |
10215 | ret = -ENOMEM; | |
10216 | goto err_alloc_veb; /* out of VEB slots! */ | |
10217 | } | |
10218 | ||
10219 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); | |
10220 | if (!veb) { | |
10221 | ret = -ENOMEM; | |
10222 | goto err_alloc_veb; | |
10223 | } | |
10224 | veb->pf = pf; | |
10225 | veb->idx = i; | |
10226 | veb->enabled_tc = 1; | |
10227 | ||
10228 | pf->veb[i] = veb; | |
10229 | ret = i; | |
10230 | err_alloc_veb: | |
10231 | mutex_unlock(&pf->switch_mutex); | |
10232 | return ret; | |
10233 | } | |
10234 | ||
10235 | /** | |
10236 | * i40e_switch_branch_release - Delete a branch of the switch tree | |
10237 | * @branch: where to start deleting | |
10238 | * | |
10239 | * This uses recursion to find the tips of the branch to be | |
10240 | * removed, deleting until we get back to and can delete this VEB. | |
10241 | **/ | |
10242 | static void i40e_switch_branch_release(struct i40e_veb *branch) | |
10243 | { | |
10244 | struct i40e_pf *pf = branch->pf; | |
10245 | u16 branch_seid = branch->seid; | |
10246 | u16 veb_idx = branch->idx; | |
10247 | int i; | |
10248 | ||
10249 | /* release any VEBs on this VEB - RECURSION */ | |
10250 | for (i = 0; i < I40E_MAX_VEB; i++) { | |
10251 | if (!pf->veb[i]) | |
10252 | continue; | |
10253 | if (pf->veb[i]->uplink_seid == branch->seid) | |
10254 | i40e_switch_branch_release(pf->veb[i]); | |
10255 | } | |
10256 | ||
10257 | /* Release the VSIs on this VEB, but not the owner VSI. | |
10258 | * | |
10259 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing | |
10260 | * the VEB itself, so don't use (*branch) after this loop. | |
10261 | */ | |
505682cd | 10262 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
41c445ff JB |
10263 | if (!pf->vsi[i]) |
10264 | continue; | |
10265 | if (pf->vsi[i]->uplink_seid == branch_seid && | |
10266 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { | |
10267 | i40e_vsi_release(pf->vsi[i]); | |
10268 | } | |
10269 | } | |
10270 | ||
10271 | /* There's one corner case where the VEB might not have been | |
10272 | * removed, so double check it here and remove it if needed. | |
10273 | * This case happens if the veb was created from the debugfs | |
10274 | * commands and no VSIs were added to it. | |
10275 | */ | |
10276 | if (pf->veb[veb_idx]) | |
10277 | i40e_veb_release(pf->veb[veb_idx]); | |
10278 | } | |
10279 | ||
10280 | /** | |
10281 | * i40e_veb_clear - remove veb struct | |
10282 | * @veb: the veb to remove | |
10283 | **/ | |
10284 | static void i40e_veb_clear(struct i40e_veb *veb) | |
10285 | { | |
10286 | if (!veb) | |
10287 | return; | |
10288 | ||
10289 | if (veb->pf) { | |
10290 | struct i40e_pf *pf = veb->pf; | |
10291 | ||
10292 | mutex_lock(&pf->switch_mutex); | |
10293 | if (pf->veb[veb->idx] == veb) | |
10294 | pf->veb[veb->idx] = NULL; | |
10295 | mutex_unlock(&pf->switch_mutex); | |
10296 | } | |
10297 | ||
10298 | kfree(veb); | |
10299 | } | |
10300 | ||
10301 | /** | |
10302 | * i40e_veb_release - Delete a VEB and free its resources | |
10303 | * @veb: the VEB being removed | |
10304 | **/ | |
10305 | void i40e_veb_release(struct i40e_veb *veb) | |
10306 | { | |
10307 | struct i40e_vsi *vsi = NULL; | |
10308 | struct i40e_pf *pf; | |
10309 | int i, n = 0; | |
10310 | ||
10311 | pf = veb->pf; | |
10312 | ||
10313 | /* find the remaining VSI and check for extras */ | |
505682cd | 10314 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
41c445ff JB |
10315 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
10316 | n++; | |
10317 | vsi = pf->vsi[i]; | |
10318 | } | |
10319 | } | |
10320 | if (n != 1) { | |
10321 | dev_info(&pf->pdev->dev, | |
10322 | "can't remove VEB %d with %d VSIs left\n", | |
10323 | veb->seid, n); | |
10324 | return; | |
10325 | } | |
10326 | ||
10327 | /* move the remaining VSI to uplink veb */ | |
10328 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; | |
10329 | if (veb->uplink_seid) { | |
10330 | vsi->uplink_seid = veb->uplink_seid; | |
10331 | if (veb->uplink_seid == pf->mac_seid) | |
10332 | vsi->veb_idx = I40E_NO_VEB; | |
10333 | else | |
10334 | vsi->veb_idx = veb->veb_idx; | |
10335 | } else { | |
10336 | /* floating VEB */ | |
10337 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; | |
10338 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; | |
10339 | } | |
10340 | ||
10341 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); | |
10342 | i40e_veb_clear(veb); | |
41c445ff JB |
10343 | } |
10344 | ||
10345 | /** | |
10346 | * i40e_add_veb - create the VEB in the switch | |
10347 | * @veb: the VEB to be instantiated | |
10348 | * @vsi: the controlling VSI | |
10349 | **/ | |
10350 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) | |
10351 | { | |
f1c7e72e | 10352 | struct i40e_pf *pf = veb->pf; |
66fc360a | 10353 | bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED); |
41c445ff JB |
10354 | int ret; |
10355 | ||
f1c7e72e | 10356 | ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid, |
5bc16031 | 10357 | veb->enabled_tc, false, |
66fc360a | 10358 | &veb->seid, enable_stats, NULL); |
5bc16031 MW |
10359 | |
10360 | /* get a VEB from the hardware */ | |
41c445ff | 10361 | if (ret) { |
f1c7e72e SN |
10362 | dev_info(&pf->pdev->dev, |
10363 | "couldn't add VEB, err %s aq_err %s\n", | |
10364 | i40e_stat_str(&pf->hw, ret), | |
10365 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
41c445ff JB |
10366 | return -EPERM; |
10367 | } | |
10368 | ||
10369 | /* get statistics counter */ | |
f1c7e72e | 10370 | ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL, |
41c445ff JB |
10371 | &veb->stats_idx, NULL, NULL, NULL); |
10372 | if (ret) { | |
f1c7e72e SN |
10373 | dev_info(&pf->pdev->dev, |
10374 | "couldn't get VEB statistics idx, err %s aq_err %s\n", | |
10375 | i40e_stat_str(&pf->hw, ret), | |
10376 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
41c445ff JB |
10377 | return -EPERM; |
10378 | } | |
10379 | ret = i40e_veb_get_bw_info(veb); | |
10380 | if (ret) { | |
f1c7e72e SN |
10381 | dev_info(&pf->pdev->dev, |
10382 | "couldn't get VEB bw info, err %s aq_err %s\n", | |
10383 | i40e_stat_str(&pf->hw, ret), | |
10384 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
10385 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); | |
41c445ff JB |
10386 | return -ENOENT; |
10387 | } | |
10388 | ||
10389 | vsi->uplink_seid = veb->seid; | |
10390 | vsi->veb_idx = veb->idx; | |
10391 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; | |
10392 | ||
10393 | return 0; | |
10394 | } | |
10395 | ||
10396 | /** | |
10397 | * i40e_veb_setup - Set up a VEB | |
10398 | * @pf: board private structure | |
10399 | * @flags: VEB setup flags | |
10400 | * @uplink_seid: the switch element to link to | |
10401 | * @vsi_seid: the initial VSI seid | |
10402 | * @enabled_tc: Enabled TC bit-map | |
10403 | * | |
10404 | * This allocates the sw VEB structure and links it into the switch | |
10405 | * It is possible and legal for this to be a duplicate of an already | |
10406 | * existing VEB. It is also possible for both uplink and vsi seids | |
10407 | * to be zero, in order to create a floating VEB. | |
10408 | * | |
10409 | * Returns pointer to the successfully allocated VEB sw struct on | |
10410 | * success, otherwise returns NULL on failure. | |
10411 | **/ | |
10412 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, | |
10413 | u16 uplink_seid, u16 vsi_seid, | |
10414 | u8 enabled_tc) | |
10415 | { | |
10416 | struct i40e_veb *veb, *uplink_veb = NULL; | |
10417 | int vsi_idx, veb_idx; | |
10418 | int ret; | |
10419 | ||
10420 | /* if one seid is 0, the other must be 0 to create a floating relay */ | |
10421 | if ((uplink_seid == 0 || vsi_seid == 0) && | |
10422 | (uplink_seid + vsi_seid != 0)) { | |
10423 | dev_info(&pf->pdev->dev, | |
10424 | "one, not both seid's are 0: uplink=%d vsi=%d\n", | |
10425 | uplink_seid, vsi_seid); | |
10426 | return NULL; | |
10427 | } | |
10428 | ||
10429 | /* make sure there is such a vsi and uplink */ | |
505682cd | 10430 | for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++) |
41c445ff JB |
10431 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
10432 | break; | |
505682cd | 10433 | if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) { |
41c445ff JB |
10434 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
10435 | vsi_seid); | |
10436 | return NULL; | |
10437 | } | |
10438 | ||
10439 | if (uplink_seid && uplink_seid != pf->mac_seid) { | |
10440 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { | |
10441 | if (pf->veb[veb_idx] && | |
10442 | pf->veb[veb_idx]->seid == uplink_seid) { | |
10443 | uplink_veb = pf->veb[veb_idx]; | |
10444 | break; | |
10445 | } | |
10446 | } | |
10447 | if (!uplink_veb) { | |
10448 | dev_info(&pf->pdev->dev, | |
10449 | "uplink seid %d not found\n", uplink_seid); | |
10450 | return NULL; | |
10451 | } | |
10452 | } | |
10453 | ||
10454 | /* get veb sw struct */ | |
10455 | veb_idx = i40e_veb_mem_alloc(pf); | |
10456 | if (veb_idx < 0) | |
10457 | goto err_alloc; | |
10458 | veb = pf->veb[veb_idx]; | |
10459 | veb->flags = flags; | |
10460 | veb->uplink_seid = uplink_seid; | |
10461 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); | |
10462 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); | |
10463 | ||
10464 | /* create the VEB in the switch */ | |
10465 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); | |
10466 | if (ret) | |
10467 | goto err_veb; | |
1bb8b935 SN |
10468 | if (vsi_idx == pf->lan_vsi) |
10469 | pf->lan_veb = veb->idx; | |
41c445ff JB |
10470 | |
10471 | return veb; | |
10472 | ||
10473 | err_veb: | |
10474 | i40e_veb_clear(veb); | |
10475 | err_alloc: | |
10476 | return NULL; | |
10477 | } | |
10478 | ||
10479 | /** | |
b40c82e6 | 10480 | * i40e_setup_pf_switch_element - set PF vars based on switch type |
41c445ff JB |
10481 | * @pf: board private structure |
10482 | * @ele: element we are building info from | |
10483 | * @num_reported: total number of elements | |
10484 | * @printconfig: should we print the contents | |
10485 | * | |
10486 | * helper function to assist in extracting a few useful SEID values. | |
10487 | **/ | |
10488 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, | |
10489 | struct i40e_aqc_switch_config_element_resp *ele, | |
10490 | u16 num_reported, bool printconfig) | |
10491 | { | |
10492 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); | |
10493 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); | |
10494 | u8 element_type = ele->element_type; | |
10495 | u16 seid = le16_to_cpu(ele->seid); | |
10496 | ||
10497 | if (printconfig) | |
10498 | dev_info(&pf->pdev->dev, | |
10499 | "type=%d seid=%d uplink=%d downlink=%d\n", | |
10500 | element_type, seid, uplink_seid, downlink_seid); | |
10501 | ||
10502 | switch (element_type) { | |
10503 | case I40E_SWITCH_ELEMENT_TYPE_MAC: | |
10504 | pf->mac_seid = seid; | |
10505 | break; | |
10506 | case I40E_SWITCH_ELEMENT_TYPE_VEB: | |
10507 | /* Main VEB? */ | |
10508 | if (uplink_seid != pf->mac_seid) | |
10509 | break; | |
10510 | if (pf->lan_veb == I40E_NO_VEB) { | |
10511 | int v; | |
10512 | ||
10513 | /* find existing or else empty VEB */ | |
10514 | for (v = 0; v < I40E_MAX_VEB; v++) { | |
10515 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { | |
10516 | pf->lan_veb = v; | |
10517 | break; | |
10518 | } | |
10519 | } | |
10520 | if (pf->lan_veb == I40E_NO_VEB) { | |
10521 | v = i40e_veb_mem_alloc(pf); | |
10522 | if (v < 0) | |
10523 | break; | |
10524 | pf->lan_veb = v; | |
10525 | } | |
10526 | } | |
10527 | ||
10528 | pf->veb[pf->lan_veb]->seid = seid; | |
10529 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; | |
10530 | pf->veb[pf->lan_veb]->pf = pf; | |
10531 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; | |
10532 | break; | |
10533 | case I40E_SWITCH_ELEMENT_TYPE_VSI: | |
10534 | if (num_reported != 1) | |
10535 | break; | |
10536 | /* This is immediately after a reset so we can assume this is | |
10537 | * the PF's VSI | |
10538 | */ | |
10539 | pf->mac_seid = uplink_seid; | |
10540 | pf->pf_seid = downlink_seid; | |
10541 | pf->main_vsi_seid = seid; | |
10542 | if (printconfig) | |
10543 | dev_info(&pf->pdev->dev, | |
10544 | "pf_seid=%d main_vsi_seid=%d\n", | |
10545 | pf->pf_seid, pf->main_vsi_seid); | |
10546 | break; | |
10547 | case I40E_SWITCH_ELEMENT_TYPE_PF: | |
10548 | case I40E_SWITCH_ELEMENT_TYPE_VF: | |
10549 | case I40E_SWITCH_ELEMENT_TYPE_EMP: | |
10550 | case I40E_SWITCH_ELEMENT_TYPE_BMC: | |
10551 | case I40E_SWITCH_ELEMENT_TYPE_PE: | |
10552 | case I40E_SWITCH_ELEMENT_TYPE_PA: | |
10553 | /* ignore these for now */ | |
10554 | break; | |
10555 | default: | |
10556 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", | |
10557 | element_type, seid); | |
10558 | break; | |
10559 | } | |
10560 | } | |
10561 | ||
10562 | /** | |
10563 | * i40e_fetch_switch_configuration - Get switch config from firmware | |
10564 | * @pf: board private structure | |
10565 | * @printconfig: should we print the contents | |
10566 | * | |
10567 | * Get the current switch configuration from the device and | |
10568 | * extract a few useful SEID values. | |
10569 | **/ | |
10570 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) | |
10571 | { | |
10572 | struct i40e_aqc_get_switch_config_resp *sw_config; | |
10573 | u16 next_seid = 0; | |
10574 | int ret = 0; | |
10575 | u8 *aq_buf; | |
10576 | int i; | |
10577 | ||
10578 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); | |
10579 | if (!aq_buf) | |
10580 | return -ENOMEM; | |
10581 | ||
10582 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; | |
10583 | do { | |
10584 | u16 num_reported, num_total; | |
10585 | ||
10586 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, | |
10587 | I40E_AQ_LARGE_BUF, | |
10588 | &next_seid, NULL); | |
10589 | if (ret) { | |
10590 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
10591 | "get switch config failed err %s aq_err %s\n", |
10592 | i40e_stat_str(&pf->hw, ret), | |
10593 | i40e_aq_str(&pf->hw, | |
10594 | pf->hw.aq.asq_last_status)); | |
41c445ff JB |
10595 | kfree(aq_buf); |
10596 | return -ENOENT; | |
10597 | } | |
10598 | ||
10599 | num_reported = le16_to_cpu(sw_config->header.num_reported); | |
10600 | num_total = le16_to_cpu(sw_config->header.num_total); | |
10601 | ||
10602 | if (printconfig) | |
10603 | dev_info(&pf->pdev->dev, | |
10604 | "header: %d reported %d total\n", | |
10605 | num_reported, num_total); | |
10606 | ||
41c445ff JB |
10607 | for (i = 0; i < num_reported; i++) { |
10608 | struct i40e_aqc_switch_config_element_resp *ele = | |
10609 | &sw_config->element[i]; | |
10610 | ||
10611 | i40e_setup_pf_switch_element(pf, ele, num_reported, | |
10612 | printconfig); | |
10613 | } | |
10614 | } while (next_seid != 0); | |
10615 | ||
10616 | kfree(aq_buf); | |
10617 | return ret; | |
10618 | } | |
10619 | ||
10620 | /** | |
10621 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset | |
10622 | * @pf: board private structure | |
bc7d338f | 10623 | * @reinit: if the Main VSI needs to re-initialized. |
41c445ff JB |
10624 | * |
10625 | * Returns 0 on success, negative value on failure | |
10626 | **/ | |
bc7d338f | 10627 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
41c445ff | 10628 | { |
b5569892 | 10629 | u16 flags = 0; |
41c445ff JB |
10630 | int ret; |
10631 | ||
10632 | /* find out what's out there already */ | |
10633 | ret = i40e_fetch_switch_configuration(pf, false); | |
10634 | if (ret) { | |
10635 | dev_info(&pf->pdev->dev, | |
f1c7e72e SN |
10636 | "couldn't fetch switch config, err %s aq_err %s\n", |
10637 | i40e_stat_str(&pf->hw, ret), | |
10638 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
41c445ff JB |
10639 | return ret; |
10640 | } | |
10641 | i40e_pf_reset_stats(pf); | |
10642 | ||
b5569892 ASJ |
10643 | /* set the switch config bit for the whole device to |
10644 | * support limited promisc or true promisc | |
10645 | * when user requests promisc. The default is limited | |
10646 | * promisc. | |
10647 | */ | |
10648 | ||
10649 | if ((pf->hw.pf_id == 0) && | |
10650 | !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) | |
10651 | flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; | |
10652 | ||
10653 | if (pf->hw.pf_id == 0) { | |
10654 | u16 valid_flags; | |
10655 | ||
10656 | valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; | |
10657 | ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, | |
10658 | NULL); | |
10659 | if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { | |
10660 | dev_info(&pf->pdev->dev, | |
10661 | "couldn't set switch config bits, err %s aq_err %s\n", | |
10662 | i40e_stat_str(&pf->hw, ret), | |
10663 | i40e_aq_str(&pf->hw, | |
10664 | pf->hw.aq.asq_last_status)); | |
10665 | /* not a fatal problem, just keep going */ | |
10666 | } | |
10667 | } | |
10668 | ||
41c445ff | 10669 | /* first time setup */ |
bc7d338f | 10670 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
41c445ff JB |
10671 | struct i40e_vsi *vsi = NULL; |
10672 | u16 uplink_seid; | |
10673 | ||
10674 | /* Set up the PF VSI associated with the PF's main VSI | |
10675 | * that is already in the HW switch | |
10676 | */ | |
10677 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) | |
10678 | uplink_seid = pf->veb[pf->lan_veb]->seid; | |
10679 | else | |
10680 | uplink_seid = pf->mac_seid; | |
bc7d338f ASJ |
10681 | if (pf->lan_vsi == I40E_NO_VSI) |
10682 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); | |
10683 | else if (reinit) | |
10684 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); | |
41c445ff JB |
10685 | if (!vsi) { |
10686 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); | |
10687 | i40e_fdir_teardown(pf); | |
10688 | return -EAGAIN; | |
10689 | } | |
41c445ff JB |
10690 | } else { |
10691 | /* force a reset of TC and queue layout configurations */ | |
10692 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; | |
6995b36c | 10693 | |
41c445ff JB |
10694 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
10695 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; | |
10696 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); | |
10697 | } | |
10698 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); | |
10699 | ||
cbf61325 ASJ |
10700 | i40e_fdir_sb_setup(pf); |
10701 | ||
41c445ff JB |
10702 | /* Setup static PF queue filter control settings */ |
10703 | ret = i40e_setup_pf_filter_control(pf); | |
10704 | if (ret) { | |
10705 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", | |
10706 | ret); | |
10707 | /* Failure here should not stop continuing other steps */ | |
10708 | } | |
10709 | ||
10710 | /* enable RSS in the HW, even for only one queue, as the stack can use | |
10711 | * the hash | |
10712 | */ | |
10713 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) | |
043dd650 | 10714 | i40e_pf_config_rss(pf); |
41c445ff JB |
10715 | |
10716 | /* fill in link information and enable LSE reporting */ | |
a34a6711 MW |
10717 | i40e_link_event(pf); |
10718 | ||
d52c20b7 | 10719 | /* Initialize user-specific link properties */ |
41c445ff JB |
10720 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
10721 | I40E_AQ_AN_COMPLETED) ? true : false); | |
d52c20b7 | 10722 | |
beb0dff1 JK |
10723 | i40e_ptp_init(pf); |
10724 | ||
41c445ff JB |
10725 | return ret; |
10726 | } | |
10727 | ||
41c445ff JB |
10728 | /** |
10729 | * i40e_determine_queue_usage - Work out queue distribution | |
10730 | * @pf: board private structure | |
10731 | **/ | |
10732 | static void i40e_determine_queue_usage(struct i40e_pf *pf) | |
10733 | { | |
41c445ff JB |
10734 | int queues_left; |
10735 | ||
10736 | pf->num_lan_qps = 0; | |
41c445ff JB |
10737 | |
10738 | /* Find the max queues to be put into basic use. We'll always be | |
10739 | * using TC0, whether or not DCB is running, and TC0 will get the | |
10740 | * big RSS set. | |
10741 | */ | |
10742 | queues_left = pf->hw.func_caps.num_tx_qp; | |
10743 | ||
cbf61325 | 10744 | if ((queues_left == 1) || |
9aa7e935 | 10745 | !(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
41c445ff JB |
10746 | /* one qp for PF, no queues for anything else */ |
10747 | queues_left = 0; | |
acd65448 | 10748 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
41c445ff JB |
10749 | |
10750 | /* make sure all the fancies are disabled */ | |
60ea5f83 | 10751 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
e3219ce6 | 10752 | I40E_FLAG_IWARP_ENABLED | |
60ea5f83 JB |
10753 | I40E_FLAG_FD_SB_ENABLED | |
10754 | I40E_FLAG_FD_ATR_ENABLED | | |
4d9b6043 | 10755 | I40E_FLAG_DCB_CAPABLE | |
a036244c | 10756 | I40E_FLAG_DCB_ENABLED | |
60ea5f83 JB |
10757 | I40E_FLAG_SRIOV_ENABLED | |
10758 | I40E_FLAG_VMDQ_ENABLED); | |
9aa7e935 FZ |
10759 | } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED | |
10760 | I40E_FLAG_FD_SB_ENABLED | | |
bbe7d0e0 | 10761 | I40E_FLAG_FD_ATR_ENABLED | |
4d9b6043 | 10762 | I40E_FLAG_DCB_CAPABLE))) { |
9aa7e935 | 10763 | /* one qp for PF */ |
acd65448 | 10764 | pf->alloc_rss_size = pf->num_lan_qps = 1; |
9aa7e935 FZ |
10765 | queues_left -= pf->num_lan_qps; |
10766 | ||
10767 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | | |
e3219ce6 | 10768 | I40E_FLAG_IWARP_ENABLED | |
9aa7e935 FZ |
10769 | I40E_FLAG_FD_SB_ENABLED | |
10770 | I40E_FLAG_FD_ATR_ENABLED | | |
10771 | I40E_FLAG_DCB_ENABLED | | |
10772 | I40E_FLAG_VMDQ_ENABLED); | |
41c445ff | 10773 | } else { |
cbf61325 | 10774 | /* Not enough queues for all TCs */ |
4d9b6043 | 10775 | if ((pf->flags & I40E_FLAG_DCB_CAPABLE) && |
cbf61325 | 10776 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
a036244c DE |
10777 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | |
10778 | I40E_FLAG_DCB_ENABLED); | |
cbf61325 ASJ |
10779 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
10780 | } | |
9a3bd2f1 ASJ |
10781 | pf->num_lan_qps = max_t(int, pf->rss_size_max, |
10782 | num_online_cpus()); | |
10783 | pf->num_lan_qps = min_t(int, pf->num_lan_qps, | |
10784 | pf->hw.func_caps.num_tx_qp); | |
10785 | ||
cbf61325 ASJ |
10786 | queues_left -= pf->num_lan_qps; |
10787 | } | |
10788 | ||
10789 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { | |
10790 | if (queues_left > 1) { | |
10791 | queues_left -= 1; /* save 1 queue for FD */ | |
10792 | } else { | |
10793 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; | |
10794 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); | |
10795 | } | |
41c445ff JB |
10796 | } |
10797 | ||
10798 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && | |
10799 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { | |
cbf61325 ASJ |
10800 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
10801 | (queues_left / pf->num_vf_qps)); | |
41c445ff JB |
10802 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
10803 | } | |
10804 | ||
10805 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && | |
10806 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { | |
10807 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, | |
10808 | (queues_left / pf->num_vmdq_qps)); | |
10809 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); | |
10810 | } | |
10811 | ||
f8ff1464 | 10812 | pf->queues_left = queues_left; |
8279e495 NP |
10813 | dev_dbg(&pf->pdev->dev, |
10814 | "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n", | |
10815 | pf->hw.func_caps.num_tx_qp, | |
10816 | !!(pf->flags & I40E_FLAG_FD_SB_ENABLED), | |
acd65448 HZ |
10817 | pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs, |
10818 | pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps, | |
10819 | queues_left); | |
41c445ff JB |
10820 | } |
10821 | ||
10822 | /** | |
10823 | * i40e_setup_pf_filter_control - Setup PF static filter control | |
10824 | * @pf: PF to be setup | |
10825 | * | |
b40c82e6 | 10826 | * i40e_setup_pf_filter_control sets up a PF's initial filter control |
41c445ff JB |
10827 | * settings. If PE/FCoE are enabled then it will also set the per PF |
10828 | * based filter sizes required for them. It also enables Flow director, | |
10829 | * ethertype and macvlan type filter settings for the pf. | |
10830 | * | |
10831 | * Returns 0 on success, negative on failure | |
10832 | **/ | |
10833 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) | |
10834 | { | |
10835 | struct i40e_filter_control_settings *settings = &pf->filter_settings; | |
10836 | ||
10837 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; | |
10838 | ||
10839 | /* Flow Director is enabled */ | |
60ea5f83 | 10840 | if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED)) |
41c445ff JB |
10841 | settings->enable_fdir = true; |
10842 | ||
10843 | /* Ethtype and MACVLAN filters enabled for PF */ | |
10844 | settings->enable_ethtype = true; | |
10845 | settings->enable_macvlan = true; | |
10846 | ||
10847 | if (i40e_set_filter_control(&pf->hw, settings)) | |
10848 | return -ENOENT; | |
10849 | ||
10850 | return 0; | |
10851 | } | |
10852 | ||
0c22b3dd | 10853 | #define INFO_STRING_LEN 255 |
7fd89545 | 10854 | #define REMAIN(__x) (INFO_STRING_LEN - (__x)) |
0c22b3dd JB |
10855 | static void i40e_print_features(struct i40e_pf *pf) |
10856 | { | |
10857 | struct i40e_hw *hw = &pf->hw; | |
3b195843 JP |
10858 | char *buf; |
10859 | int i; | |
0c22b3dd | 10860 | |
3b195843 JP |
10861 | buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL); |
10862 | if (!buf) | |
0c22b3dd | 10863 | return; |
0c22b3dd | 10864 | |
3b195843 | 10865 | i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id); |
0c22b3dd | 10866 | #ifdef CONFIG_PCI_IOV |
3b195843 | 10867 | i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs); |
0c22b3dd | 10868 | #endif |
1a557afc | 10869 | i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d", |
7fd89545 | 10870 | pf->hw.func_caps.num_vsis, |
1a557afc | 10871 | pf->vsi[pf->lan_vsi]->num_queue_pairs); |
0c22b3dd | 10872 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
3b195843 | 10873 | i += snprintf(&buf[i], REMAIN(i), " RSS"); |
0c22b3dd | 10874 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
3b195843 | 10875 | i += snprintf(&buf[i], REMAIN(i), " FD_ATR"); |
c6423ff1 | 10876 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
3b195843 JP |
10877 | i += snprintf(&buf[i], REMAIN(i), " FD_SB"); |
10878 | i += snprintf(&buf[i], REMAIN(i), " NTUPLE"); | |
c6423ff1 | 10879 | } |
4d9b6043 | 10880 | if (pf->flags & I40E_FLAG_DCB_CAPABLE) |
3b195843 | 10881 | i += snprintf(&buf[i], REMAIN(i), " DCB"); |
3b195843 | 10882 | i += snprintf(&buf[i], REMAIN(i), " VxLAN"); |
6a899024 | 10883 | i += snprintf(&buf[i], REMAIN(i), " Geneve"); |
0c22b3dd | 10884 | if (pf->flags & I40E_FLAG_PTP) |
3b195843 | 10885 | i += snprintf(&buf[i], REMAIN(i), " PTP"); |
6dec1017 | 10886 | if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) |
3b195843 | 10887 | i += snprintf(&buf[i], REMAIN(i), " VEB"); |
6dec1017 | 10888 | else |
3b195843 | 10889 | i += snprintf(&buf[i], REMAIN(i), " VEPA"); |
0c22b3dd | 10890 | |
3b195843 JP |
10891 | dev_info(&pf->pdev->dev, "%s\n", buf); |
10892 | kfree(buf); | |
7fd89545 | 10893 | WARN_ON(i > INFO_STRING_LEN); |
0c22b3dd JB |
10894 | } |
10895 | ||
b499ffb0 SV |
10896 | /** |
10897 | * i40e_get_platform_mac_addr - get platform-specific MAC address | |
b499ffb0 SV |
10898 | * @pdev: PCI device information struct |
10899 | * @pf: board private structure | |
10900 | * | |
41c4c2b5 JK |
10901 | * Look up the MAC address for the device. First we'll try |
10902 | * eth_platform_get_mac_address, which will check Open Firmware, or arch | |
10903 | * specific fallback. Otherwise, we'll default to the stored value in | |
10904 | * firmware. | |
b499ffb0 SV |
10905 | **/ |
10906 | static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf) | |
10907 | { | |
41c4c2b5 JK |
10908 | if (eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr)) |
10909 | i40e_get_mac_addr(&pf->hw, pf->hw.mac.addr); | |
b499ffb0 SV |
10910 | } |
10911 | ||
41c445ff JB |
10912 | /** |
10913 | * i40e_probe - Device initialization routine | |
10914 | * @pdev: PCI device information struct | |
10915 | * @ent: entry in i40e_pci_tbl | |
10916 | * | |
b40c82e6 JK |
10917 | * i40e_probe initializes a PF identified by a pci_dev structure. |
10918 | * The OS initialization, configuring of the PF private structure, | |
41c445ff JB |
10919 | * and a hardware reset occur. |
10920 | * | |
10921 | * Returns 0 on success, negative on failure | |
10922 | **/ | |
10923 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |
10924 | { | |
e827845c | 10925 | struct i40e_aq_get_phy_abilities_resp abilities; |
41c445ff JB |
10926 | struct i40e_pf *pf; |
10927 | struct i40e_hw *hw; | |
93cd765b | 10928 | static u16 pfs_found; |
1d5109d1 | 10929 | u16 wol_nvm_bits; |
d4dfb81a | 10930 | u16 link_status; |
6f66a484 | 10931 | int err; |
4f2f017c | 10932 | u32 val; |
8a9eb7d3 | 10933 | u32 i; |
58fc3267 | 10934 | u8 set_fc_aq_fail; |
41c445ff JB |
10935 | |
10936 | err = pci_enable_device_mem(pdev); | |
10937 | if (err) | |
10938 | return err; | |
10939 | ||
10940 | /* set up for high or low dma */ | |
6494294f | 10941 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
6494294f | 10942 | if (err) { |
e3e3bfdd JS |
10943 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
10944 | if (err) { | |
10945 | dev_err(&pdev->dev, | |
10946 | "DMA configuration failed: 0x%x\n", err); | |
10947 | goto err_dma; | |
10948 | } | |
41c445ff JB |
10949 | } |
10950 | ||
10951 | /* set up pci connections */ | |
56d766d6 | 10952 | err = pci_request_mem_regions(pdev, i40e_driver_name); |
41c445ff JB |
10953 | if (err) { |
10954 | dev_info(&pdev->dev, | |
10955 | "pci_request_selected_regions failed %d\n", err); | |
10956 | goto err_pci_reg; | |
10957 | } | |
10958 | ||
10959 | pci_enable_pcie_error_reporting(pdev); | |
10960 | pci_set_master(pdev); | |
10961 | ||
10962 | /* Now that we have a PCI connection, we need to do the | |
10963 | * low level device setup. This is primarily setting up | |
10964 | * the Admin Queue structures and then querying for the | |
10965 | * device's current profile information. | |
10966 | */ | |
10967 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); | |
10968 | if (!pf) { | |
10969 | err = -ENOMEM; | |
10970 | goto err_pf_alloc; | |
10971 | } | |
10972 | pf->next_vsi = 0; | |
10973 | pf->pdev = pdev; | |
10974 | set_bit(__I40E_DOWN, &pf->state); | |
10975 | ||
10976 | hw = &pf->hw; | |
10977 | hw->back = pf; | |
232f4706 | 10978 | |
2ac8b675 SN |
10979 | pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0), |
10980 | I40E_MAX_CSR_SPACE); | |
232f4706 | 10981 | |
2ac8b675 | 10982 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len); |
41c445ff JB |
10983 | if (!hw->hw_addr) { |
10984 | err = -EIO; | |
10985 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", | |
10986 | (unsigned int)pci_resource_start(pdev, 0), | |
2ac8b675 | 10987 | pf->ioremap_len, err); |
41c445ff JB |
10988 | goto err_ioremap; |
10989 | } | |
10990 | hw->vendor_id = pdev->vendor; | |
10991 | hw->device_id = pdev->device; | |
10992 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); | |
10993 | hw->subsystem_vendor_id = pdev->subsystem_vendor; | |
10994 | hw->subsystem_device_id = pdev->subsystem_device; | |
10995 | hw->bus.device = PCI_SLOT(pdev->devfn); | |
10996 | hw->bus.func = PCI_FUNC(pdev->devfn); | |
b3f028fc | 10997 | hw->bus.bus_id = pdev->bus->number; |
93cd765b | 10998 | pf->instance = pfs_found; |
41c445ff | 10999 | |
0e588de1 JK |
11000 | INIT_LIST_HEAD(&pf->l3_flex_pit_list); |
11001 | INIT_LIST_HEAD(&pf->l4_flex_pit_list); | |
11002 | ||
de03d2b0 SN |
11003 | /* set up the locks for the AQ, do this only once in probe |
11004 | * and destroy them only once in remove | |
11005 | */ | |
11006 | mutex_init(&hw->aq.asq_mutex); | |
11007 | mutex_init(&hw->aq.arq_mutex); | |
11008 | ||
5d4ca23e AD |
11009 | pf->msg_enable = netif_msg_init(debug, |
11010 | NETIF_MSG_DRV | | |
11011 | NETIF_MSG_PROBE | | |
11012 | NETIF_MSG_LINK); | |
11013 | if (debug < -1) | |
11014 | pf->hw.debug_mask = debug; | |
5b5faa43 | 11015 | |
7134f9ce JB |
11016 | /* do a special CORER for clearing PXE mode once at init */ |
11017 | if (hw->revision_id == 0 && | |
11018 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { | |
11019 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); | |
11020 | i40e_flush(hw); | |
11021 | msleep(200); | |
11022 | pf->corer_count++; | |
11023 | ||
11024 | i40e_clear_pxe_mode(hw); | |
11025 | } | |
11026 | ||
41c445ff | 11027 | /* Reset here to make sure all is clean and to define PF 'n' */ |
838d41d9 | 11028 | i40e_clear_hw(hw); |
41c445ff JB |
11029 | err = i40e_pf_reset(hw); |
11030 | if (err) { | |
11031 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); | |
11032 | goto err_pf_reset; | |
11033 | } | |
11034 | pf->pfr_count++; | |
11035 | ||
11036 | hw->aq.num_arq_entries = I40E_AQ_LEN; | |
11037 | hw->aq.num_asq_entries = I40E_AQ_LEN; | |
11038 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; | |
11039 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; | |
11040 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; | |
b2008cbf | 11041 | |
b294ac70 | 11042 | snprintf(pf->int_name, sizeof(pf->int_name) - 1, |
b2008cbf CW |
11043 | "%s-%s:misc", |
11044 | dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev)); | |
41c445ff JB |
11045 | |
11046 | err = i40e_init_shared_code(hw); | |
11047 | if (err) { | |
b2a75c58 ASJ |
11048 | dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n", |
11049 | err); | |
41c445ff JB |
11050 | goto err_pf_reset; |
11051 | } | |
11052 | ||
d52c20b7 JB |
11053 | /* set up a default setting for link flow control */ |
11054 | pf->hw.fc.requested_mode = I40E_FC_NONE; | |
11055 | ||
41c445ff | 11056 | err = i40e_init_adminq(hw); |
2b2426a7 CW |
11057 | if (err) { |
11058 | if (err == I40E_ERR_FIRMWARE_API_VERSION) | |
11059 | dev_info(&pdev->dev, | |
11060 | "The driver for the device stopped because the NVM image is newer than expected. You must install the most recent version of the network driver.\n"); | |
11061 | else | |
11062 | dev_info(&pdev->dev, | |
11063 | "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n"); | |
11064 | ||
11065 | goto err_pf_reset; | |
11066 | } | |
f0b44440 | 11067 | |
6dec1017 SN |
11068 | /* provide nvm, fw, api versions */ |
11069 | dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n", | |
11070 | hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build, | |
11071 | hw->aq.api_maj_ver, hw->aq.api_min_ver, | |
11072 | i40e_nvm_version_str(hw)); | |
f0b44440 | 11073 | |
7aa67613 CS |
11074 | if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR && |
11075 | hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR) | |
278b6f62 | 11076 | dev_info(&pdev->dev, |
7aa67613 CS |
11077 | "The driver for the device detected a newer version of the NVM image than expected. Please install the most recent version of the network driver.\n"); |
11078 | else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR || | |
11079 | hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1)) | |
278b6f62 | 11080 | dev_info(&pdev->dev, |
7aa67613 | 11081 | "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n"); |
278b6f62 | 11082 | |
4eb3f768 SN |
11083 | i40e_verify_eeprom(pf); |
11084 | ||
2c5fe33b JB |
11085 | /* Rev 0 hardware was never productized */ |
11086 | if (hw->revision_id < 1) | |
11087 | dev_warn(&pdev->dev, "This device is a pre-production adapter/LOM. Please be aware there may be issues with your hardware. If you are experiencing problems please contact your Intel or hardware representative who provided you with this hardware.\n"); | |
11088 | ||
6ff4ef86 | 11089 | i40e_clear_pxe_mode(hw); |
41c445ff JB |
11090 | err = i40e_get_capabilities(pf); |
11091 | if (err) | |
11092 | goto err_adminq_setup; | |
11093 | ||
11094 | err = i40e_sw_init(pf); | |
11095 | if (err) { | |
11096 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); | |
11097 | goto err_sw_init; | |
11098 | } | |
11099 | ||
11100 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, | |
c76cb6ed | 11101 | hw->func_caps.num_rx_qp, 0, 0); |
41c445ff JB |
11102 | if (err) { |
11103 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); | |
11104 | goto err_init_lan_hmc; | |
11105 | } | |
11106 | ||
11107 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); | |
11108 | if (err) { | |
11109 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); | |
11110 | err = -ENOENT; | |
11111 | goto err_configure_lan_hmc; | |
11112 | } | |
11113 | ||
b686ece5 NP |
11114 | /* Disable LLDP for NICs that have firmware versions lower than v4.3. |
11115 | * Ignore error return codes because if it was already disabled via | |
11116 | * hardware settings this will fail | |
11117 | */ | |
f1bbad33 | 11118 | if (pf->flags & I40E_FLAG_STOP_FW_LLDP) { |
b686ece5 NP |
11119 | dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n"); |
11120 | i40e_aq_stop_lldp(hw, true, NULL); | |
11121 | } | |
11122 | ||
b499ffb0 SV |
11123 | /* allow a platform config to override the HW addr */ |
11124 | i40e_get_platform_mac_addr(pdev, pf); | |
41c4c2b5 | 11125 | |
f62b5060 | 11126 | if (!is_valid_ether_addr(hw->mac.addr)) { |
41c445ff JB |
11127 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
11128 | err = -EIO; | |
11129 | goto err_mac_addr; | |
11130 | } | |
11131 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); | |
9a173901 | 11132 | ether_addr_copy(hw->mac.perm_addr, hw->mac.addr); |
1f224ad2 NP |
11133 | i40e_get_port_mac_addr(hw, hw->mac.port_addr); |
11134 | if (is_valid_ether_addr(hw->mac.port_addr)) | |
11135 | pf->flags |= I40E_FLAG_PORT_ID_VALID; | |
41c445ff JB |
11136 | |
11137 | pci_set_drvdata(pdev, pf); | |
11138 | pci_save_state(pdev); | |
4e3b35b0 NP |
11139 | #ifdef CONFIG_I40E_DCB |
11140 | err = i40e_init_pf_dcb(pf); | |
11141 | if (err) { | |
aebfc816 | 11142 | dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err); |
c17ef430 | 11143 | pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED); |
014269ff | 11144 | /* Continue without DCB enabled */ |
4e3b35b0 NP |
11145 | } |
11146 | #endif /* CONFIG_I40E_DCB */ | |
41c445ff JB |
11147 | |
11148 | /* set up periodic task facility */ | |
11149 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); | |
11150 | pf->service_timer_period = HZ; | |
11151 | ||
11152 | INIT_WORK(&pf->service_task, i40e_service_task); | |
11153 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); | |
41c445ff | 11154 | |
1d5109d1 SN |
11155 | /* NVM bit on means WoL disabled for the port */ |
11156 | i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits); | |
75f5cea9 | 11157 | if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1) |
1d5109d1 SN |
11158 | pf->wol_en = false; |
11159 | else | |
11160 | pf->wol_en = true; | |
8e2773ae SN |
11161 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
11162 | ||
41c445ff JB |
11163 | /* set up the main switch operations */ |
11164 | i40e_determine_queue_usage(pf); | |
c1147280 JB |
11165 | err = i40e_init_interrupt_scheme(pf); |
11166 | if (err) | |
11167 | goto err_switch_setup; | |
41c445ff | 11168 | |
505682cd MW |
11169 | /* The number of VSIs reported by the FW is the minimum guaranteed |
11170 | * to us; HW supports far more and we share the remaining pool with | |
11171 | * the other PFs. We allocate space for more than the guarantee with | |
11172 | * the understanding that we might not get them all later. | |
41c445ff | 11173 | */ |
505682cd MW |
11174 | if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC) |
11175 | pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC; | |
11176 | else | |
11177 | pf->num_alloc_vsi = pf->hw.func_caps.num_vsis; | |
11178 | ||
11179 | /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */ | |
d17038d6 JB |
11180 | pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *), |
11181 | GFP_KERNEL); | |
ed87ac09 WY |
11182 | if (!pf->vsi) { |
11183 | err = -ENOMEM; | |
41c445ff | 11184 | goto err_switch_setup; |
ed87ac09 | 11185 | } |
41c445ff | 11186 | |
fa11cb3d ASJ |
11187 | #ifdef CONFIG_PCI_IOV |
11188 | /* prep for VF support */ | |
11189 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && | |
11190 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && | |
11191 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { | |
11192 | if (pci_num_vf(pdev)) | |
11193 | pf->flags |= I40E_FLAG_VEB_MODE_ENABLED; | |
11194 | } | |
11195 | #endif | |
bc7d338f | 11196 | err = i40e_setup_pf_switch(pf, false); |
41c445ff JB |
11197 | if (err) { |
11198 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); | |
11199 | goto err_vsis; | |
11200 | } | |
58fc3267 HZ |
11201 | |
11202 | /* Make sure flow control is set according to current settings */ | |
11203 | err = i40e_set_fc(hw, &set_fc_aq_fail, true); | |
11204 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET) | |
11205 | dev_dbg(&pf->pdev->dev, | |
11206 | "Set fc with err %s aq_err %s on get_phy_cap\n", | |
11207 | i40e_stat_str(hw, err), | |
11208 | i40e_aq_str(hw, hw->aq.asq_last_status)); | |
11209 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET) | |
11210 | dev_dbg(&pf->pdev->dev, | |
11211 | "Set fc with err %s aq_err %s on set_phy_config\n", | |
11212 | i40e_stat_str(hw, err), | |
11213 | i40e_aq_str(hw, hw->aq.asq_last_status)); | |
11214 | if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE) | |
11215 | dev_dbg(&pf->pdev->dev, | |
11216 | "Set fc with err %s aq_err %s on get_link_info\n", | |
11217 | i40e_stat_str(hw, err), | |
11218 | i40e_aq_str(hw, hw->aq.asq_last_status)); | |
11219 | ||
8a9eb7d3 | 11220 | /* if FDIR VSI was set up, start it now */ |
505682cd | 11221 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
8a9eb7d3 SN |
11222 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
11223 | i40e_vsi_open(pf->vsi[i]); | |
11224 | break; | |
11225 | } | |
11226 | } | |
41c445ff | 11227 | |
2f0aff41 SN |
11228 | /* The driver only wants link up/down and module qualification |
11229 | * reports from firmware. Note the negative logic. | |
7e2453fe JB |
11230 | */ |
11231 | err = i40e_aq_set_phy_int_mask(&pf->hw, | |
2f0aff41 | 11232 | ~(I40E_AQ_EVENT_LINK_UPDOWN | |
867a79e3 | 11233 | I40E_AQ_EVENT_MEDIA_NA | |
2f0aff41 | 11234 | I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL); |
7e2453fe | 11235 | if (err) |
f1c7e72e SN |
11236 | dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n", |
11237 | i40e_stat_str(&pf->hw, err), | |
11238 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
7e2453fe | 11239 | |
4f2f017c ASJ |
11240 | /* Reconfigure hardware for allowing smaller MSS in the case |
11241 | * of TSO, so that we avoid the MDD being fired and causing | |
11242 | * a reset in the case of small MSS+TSO. | |
11243 | */ | |
11244 | val = rd32(hw, I40E_REG_MSS); | |
11245 | if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) { | |
11246 | val &= ~I40E_REG_MSS_MIN_MASK; | |
11247 | val |= I40E_64BYTE_MSS; | |
11248 | wr32(hw, I40E_REG_MSS, val); | |
11249 | } | |
11250 | ||
8eed76fa | 11251 | if (pf->flags & I40E_FLAG_RESTART_AUTONEG) { |
025b4a54 ASJ |
11252 | msleep(75); |
11253 | err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL); | |
11254 | if (err) | |
f1c7e72e SN |
11255 | dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n", |
11256 | i40e_stat_str(&pf->hw, err), | |
11257 | i40e_aq_str(&pf->hw, | |
11258 | pf->hw.aq.asq_last_status)); | |
cafa2ee6 | 11259 | } |
41c445ff JB |
11260 | /* The main driver is (mostly) up and happy. We need to set this state |
11261 | * before setting up the misc vector or we get a race and the vector | |
11262 | * ends up disabled forever. | |
11263 | */ | |
11264 | clear_bit(__I40E_DOWN, &pf->state); | |
11265 | ||
11266 | /* In case of MSIX we are going to setup the misc vector right here | |
11267 | * to handle admin queue events etc. In case of legacy and MSI | |
11268 | * the misc functionality and queue processing is combined in | |
11269 | * the same vector and that gets setup at open. | |
11270 | */ | |
11271 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | |
11272 | err = i40e_setup_misc_vector(pf); | |
11273 | if (err) { | |
11274 | dev_info(&pdev->dev, | |
11275 | "setup of misc vector failed: %d\n", err); | |
11276 | goto err_vsis; | |
11277 | } | |
11278 | } | |
11279 | ||
df805f62 | 11280 | #ifdef CONFIG_PCI_IOV |
41c445ff JB |
11281 | /* prep for VF support */ |
11282 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && | |
4eb3f768 SN |
11283 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
11284 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { | |
41c445ff JB |
11285 | /* disable link interrupts for VFs */ |
11286 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); | |
11287 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; | |
11288 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); | |
11289 | i40e_flush(hw); | |
4aeec010 MW |
11290 | |
11291 | if (pci_num_vf(pdev)) { | |
11292 | dev_info(&pdev->dev, | |
11293 | "Active VFs found, allocating resources.\n"); | |
11294 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); | |
11295 | if (err) | |
11296 | dev_info(&pdev->dev, | |
11297 | "Error %d allocating resources for existing VFs\n", | |
11298 | err); | |
11299 | } | |
41c445ff | 11300 | } |
df805f62 | 11301 | #endif /* CONFIG_PCI_IOV */ |
41c445ff | 11302 | |
e3219ce6 ASJ |
11303 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
11304 | pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile, | |
11305 | pf->num_iwarp_msix, | |
11306 | I40E_IWARP_IRQ_PILE_ID); | |
11307 | if (pf->iwarp_base_vector < 0) { | |
11308 | dev_info(&pdev->dev, | |
11309 | "failed to get tracking for %d vectors for IWARP err=%d\n", | |
11310 | pf->num_iwarp_msix, pf->iwarp_base_vector); | |
11311 | pf->flags &= ~I40E_FLAG_IWARP_ENABLED; | |
11312 | } | |
11313 | } | |
93cd765b | 11314 | |
41c445ff JB |
11315 | i40e_dbg_pf_init(pf); |
11316 | ||
11317 | /* tell the firmware that we're starting */ | |
44033fac | 11318 | i40e_send_version(pf); |
41c445ff JB |
11319 | |
11320 | /* since everything's happy, start the service_task timer */ | |
11321 | mod_timer(&pf->service_timer, | |
11322 | round_jiffies(jiffies + pf->service_timer_period)); | |
11323 | ||
e3219ce6 | 11324 | /* add this PF to client device list and launch a client service task */ |
004eb614 MW |
11325 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
11326 | err = i40e_lan_add_device(pf); | |
11327 | if (err) | |
11328 | dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n", | |
11329 | err); | |
11330 | } | |
e3219ce6 | 11331 | |
3fced535 ASJ |
11332 | #define PCI_SPEED_SIZE 8 |
11333 | #define PCI_WIDTH_SIZE 8 | |
11334 | /* Devices on the IOSF bus do not have this information | |
11335 | * and will report PCI Gen 1 x 1 by default so don't bother | |
11336 | * checking them. | |
11337 | */ | |
11338 | if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) { | |
11339 | char speed[PCI_SPEED_SIZE] = "Unknown"; | |
11340 | char width[PCI_WIDTH_SIZE] = "Unknown"; | |
11341 | ||
11342 | /* Get the negotiated link width and speed from PCI config | |
11343 | * space | |
11344 | */ | |
11345 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, | |
11346 | &link_status); | |
11347 | ||
11348 | i40e_set_pci_config_data(hw, link_status); | |
11349 | ||
11350 | switch (hw->bus.speed) { | |
11351 | case i40e_bus_speed_8000: | |
11352 | strncpy(speed, "8.0", PCI_SPEED_SIZE); break; | |
11353 | case i40e_bus_speed_5000: | |
11354 | strncpy(speed, "5.0", PCI_SPEED_SIZE); break; | |
11355 | case i40e_bus_speed_2500: | |
11356 | strncpy(speed, "2.5", PCI_SPEED_SIZE); break; | |
11357 | default: | |
11358 | break; | |
11359 | } | |
11360 | switch (hw->bus.width) { | |
11361 | case i40e_bus_width_pcie_x8: | |
11362 | strncpy(width, "8", PCI_WIDTH_SIZE); break; | |
11363 | case i40e_bus_width_pcie_x4: | |
11364 | strncpy(width, "4", PCI_WIDTH_SIZE); break; | |
11365 | case i40e_bus_width_pcie_x2: | |
11366 | strncpy(width, "2", PCI_WIDTH_SIZE); break; | |
11367 | case i40e_bus_width_pcie_x1: | |
11368 | strncpy(width, "1", PCI_WIDTH_SIZE); break; | |
11369 | default: | |
11370 | break; | |
11371 | } | |
11372 | ||
11373 | dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n", | |
11374 | speed, width); | |
11375 | ||
11376 | if (hw->bus.width < i40e_bus_width_pcie_x8 || | |
11377 | hw->bus.speed < i40e_bus_speed_8000) { | |
11378 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); | |
11379 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); | |
11380 | } | |
d4dfb81a CS |
11381 | } |
11382 | ||
e827845c CS |
11383 | /* get the requested speeds from the fw */ |
11384 | err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL); | |
11385 | if (err) | |
8279e495 NP |
11386 | dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n", |
11387 | i40e_stat_str(&pf->hw, err), | |
11388 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
e827845c CS |
11389 | pf->hw.phy.link_info.requested_speeds = abilities.link_speed; |
11390 | ||
fc72dbce CS |
11391 | /* get the supported phy types from the fw */ |
11392 | err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL); | |
11393 | if (err) | |
11394 | dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n", | |
11395 | i40e_stat_str(&pf->hw, err), | |
11396 | i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); | |
fc72dbce | 11397 | |
e7358f54 ASJ |
11398 | /* Add a filter to drop all Flow control frames from any VSI from being |
11399 | * transmitted. By doing so we stop a malicious VF from sending out | |
11400 | * PAUSE or PFC frames and potentially controlling traffic for other | |
11401 | * PF/VF VSIs. | |
11402 | * The FW can still send Flow control frames if enabled. | |
11403 | */ | |
11404 | i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw, | |
11405 | pf->main_vsi_seid); | |
11406 | ||
31b606d0 | 11407 | if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) || |
4f9b4307 HT |
11408 | (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4)) |
11409 | pf->flags |= I40E_FLAG_PHY_CONTROLS_LEDS; | |
4ad9f4f9 HR |
11410 | if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722) |
11411 | pf->flags |= I40E_FLAG_HAVE_CRT_RETIMER; | |
0c22b3dd JB |
11412 | /* print a string summarizing features */ |
11413 | i40e_print_features(pf); | |
11414 | ||
41c445ff JB |
11415 | return 0; |
11416 | ||
11417 | /* Unwind what we've done if something failed in the setup */ | |
11418 | err_vsis: | |
11419 | set_bit(__I40E_DOWN, &pf->state); | |
41c445ff JB |
11420 | i40e_clear_interrupt_scheme(pf); |
11421 | kfree(pf->vsi); | |
04b03013 SN |
11422 | err_switch_setup: |
11423 | i40e_reset_interrupt_capability(pf); | |
41c445ff JB |
11424 | del_timer_sync(&pf->service_timer); |
11425 | err_mac_addr: | |
11426 | err_configure_lan_hmc: | |
11427 | (void)i40e_shutdown_lan_hmc(hw); | |
11428 | err_init_lan_hmc: | |
11429 | kfree(pf->qp_pile); | |
41c445ff JB |
11430 | err_sw_init: |
11431 | err_adminq_setup: | |
41c445ff JB |
11432 | err_pf_reset: |
11433 | iounmap(hw->hw_addr); | |
11434 | err_ioremap: | |
11435 | kfree(pf); | |
11436 | err_pf_alloc: | |
11437 | pci_disable_pcie_error_reporting(pdev); | |
56d766d6 | 11438 | pci_release_mem_regions(pdev); |
41c445ff JB |
11439 | err_pci_reg: |
11440 | err_dma: | |
11441 | pci_disable_device(pdev); | |
11442 | return err; | |
11443 | } | |
11444 | ||
11445 | /** | |
11446 | * i40e_remove - Device removal routine | |
11447 | * @pdev: PCI device information struct | |
11448 | * | |
11449 | * i40e_remove is called by the PCI subsystem to alert the driver | |
11450 | * that is should release a PCI device. This could be caused by a | |
11451 | * Hot-Plug event, or because the driver is going to be removed from | |
11452 | * memory. | |
11453 | **/ | |
11454 | static void i40e_remove(struct pci_dev *pdev) | |
11455 | { | |
11456 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
bcab2db9 | 11457 | struct i40e_hw *hw = &pf->hw; |
41c445ff | 11458 | i40e_status ret_code; |
41c445ff JB |
11459 | int i; |
11460 | ||
11461 | i40e_dbg_pf_exit(pf); | |
11462 | ||
beb0dff1 JK |
11463 | i40e_ptp_stop(pf); |
11464 | ||
bcab2db9 | 11465 | /* Disable RSS in hw */ |
272cdaf2 SN |
11466 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0); |
11467 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0); | |
bcab2db9 | 11468 | |
41c445ff | 11469 | /* no more scheduling of any task */ |
a4618ec8 | 11470 | set_bit(__I40E_SUSPENDED, &pf->state); |
41c445ff | 11471 | set_bit(__I40E_DOWN, &pf->state); |
c99abb4c SN |
11472 | if (pf->service_timer.data) |
11473 | del_timer_sync(&pf->service_timer); | |
11474 | if (pf->service_task.func) | |
11475 | cancel_work_sync(&pf->service_task); | |
41c445ff | 11476 | |
921c467c MW |
11477 | /* Client close must be called explicitly here because the timer |
11478 | * has been stopped. | |
11479 | */ | |
11480 | i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false); | |
11481 | ||
eb2d80bc MW |
11482 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
11483 | i40e_free_vfs(pf); | |
11484 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; | |
11485 | } | |
11486 | ||
41c445ff JB |
11487 | i40e_fdir_teardown(pf); |
11488 | ||
11489 | /* If there is a switch structure or any orphans, remove them. | |
11490 | * This will leave only the PF's VSI remaining. | |
11491 | */ | |
11492 | for (i = 0; i < I40E_MAX_VEB; i++) { | |
11493 | if (!pf->veb[i]) | |
11494 | continue; | |
11495 | ||
11496 | if (pf->veb[i]->uplink_seid == pf->mac_seid || | |
11497 | pf->veb[i]->uplink_seid == 0) | |
11498 | i40e_switch_branch_release(pf->veb[i]); | |
11499 | } | |
11500 | ||
11501 | /* Now we can shutdown the PF's VSI, just before we kill | |
11502 | * adminq and hmc. | |
11503 | */ | |
11504 | if (pf->vsi[pf->lan_vsi]) | |
11505 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); | |
11506 | ||
e3219ce6 | 11507 | /* remove attached clients */ |
004eb614 MW |
11508 | if (pf->flags & I40E_FLAG_IWARP_ENABLED) { |
11509 | ret_code = i40e_lan_del_device(pf); | |
11510 | if (ret_code) | |
11511 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", | |
11512 | ret_code); | |
e3219ce6 ASJ |
11513 | } |
11514 | ||
41c445ff | 11515 | /* shutdown and destroy the HMC */ |
f734dfff JB |
11516 | if (hw->hmc.hmc_obj) { |
11517 | ret_code = i40e_shutdown_lan_hmc(hw); | |
60442dea SN |
11518 | if (ret_code) |
11519 | dev_warn(&pdev->dev, | |
11520 | "Failed to destroy the HMC resources: %d\n", | |
11521 | ret_code); | |
11522 | } | |
41c445ff JB |
11523 | |
11524 | /* shutdown the adminq */ | |
ac9c5c6d | 11525 | i40e_shutdown_adminq(hw); |
41c445ff | 11526 | |
8ddb3326 JB |
11527 | /* destroy the locks only once, here */ |
11528 | mutex_destroy(&hw->aq.arq_mutex); | |
11529 | mutex_destroy(&hw->aq.asq_mutex); | |
11530 | ||
41c445ff JB |
11531 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
11532 | i40e_clear_interrupt_scheme(pf); | |
505682cd | 11533 | for (i = 0; i < pf->num_alloc_vsi; i++) { |
41c445ff JB |
11534 | if (pf->vsi[i]) { |
11535 | i40e_vsi_clear_rings(pf->vsi[i]); | |
11536 | i40e_vsi_clear(pf->vsi[i]); | |
11537 | pf->vsi[i] = NULL; | |
11538 | } | |
11539 | } | |
11540 | ||
11541 | for (i = 0; i < I40E_MAX_VEB; i++) { | |
11542 | kfree(pf->veb[i]); | |
11543 | pf->veb[i] = NULL; | |
11544 | } | |
11545 | ||
11546 | kfree(pf->qp_pile); | |
41c445ff JB |
11547 | kfree(pf->vsi); |
11548 | ||
f734dfff | 11549 | iounmap(hw->hw_addr); |
41c445ff | 11550 | kfree(pf); |
56d766d6 | 11551 | pci_release_mem_regions(pdev); |
41c445ff JB |
11552 | |
11553 | pci_disable_pcie_error_reporting(pdev); | |
11554 | pci_disable_device(pdev); | |
11555 | } | |
11556 | ||
11557 | /** | |
11558 | * i40e_pci_error_detected - warning that something funky happened in PCI land | |
11559 | * @pdev: PCI device information struct | |
11560 | * | |
11561 | * Called to warn that something happened and the error handling steps | |
11562 | * are in progress. Allows the driver to quiesce things, be ready for | |
11563 | * remediation. | |
11564 | **/ | |
11565 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, | |
11566 | enum pci_channel_state error) | |
11567 | { | |
11568 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
11569 | ||
11570 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); | |
11571 | ||
edfc23ee GP |
11572 | if (!pf) { |
11573 | dev_info(&pdev->dev, | |
11574 | "Cannot recover - error happened during device probe\n"); | |
11575 | return PCI_ERS_RESULT_DISCONNECT; | |
11576 | } | |
11577 | ||
41c445ff | 11578 | /* shutdown all operations */ |
9007bccd SN |
11579 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
11580 | rtnl_lock(); | |
373149fc | 11581 | i40e_prep_for_reset(pf, true); |
9007bccd SN |
11582 | rtnl_unlock(); |
11583 | } | |
41c445ff JB |
11584 | |
11585 | /* Request a slot reset */ | |
11586 | return PCI_ERS_RESULT_NEED_RESET; | |
11587 | } | |
11588 | ||
11589 | /** | |
11590 | * i40e_pci_error_slot_reset - a PCI slot reset just happened | |
11591 | * @pdev: PCI device information struct | |
11592 | * | |
11593 | * Called to find if the driver can work with the device now that | |
11594 | * the pci slot has been reset. If a basic connection seems good | |
11595 | * (registers are readable and have sane content) then return a | |
11596 | * happy little PCI_ERS_RESULT_xxx. | |
11597 | **/ | |
11598 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) | |
11599 | { | |
11600 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
11601 | pci_ers_result_t result; | |
11602 | int err; | |
11603 | u32 reg; | |
11604 | ||
fb43201f | 11605 | dev_dbg(&pdev->dev, "%s\n", __func__); |
41c445ff JB |
11606 | if (pci_enable_device_mem(pdev)) { |
11607 | dev_info(&pdev->dev, | |
11608 | "Cannot re-enable PCI device after reset.\n"); | |
11609 | result = PCI_ERS_RESULT_DISCONNECT; | |
11610 | } else { | |
11611 | pci_set_master(pdev); | |
11612 | pci_restore_state(pdev); | |
11613 | pci_save_state(pdev); | |
11614 | pci_wake_from_d3(pdev, false); | |
11615 | ||
11616 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); | |
11617 | if (reg == 0) | |
11618 | result = PCI_ERS_RESULT_RECOVERED; | |
11619 | else | |
11620 | result = PCI_ERS_RESULT_DISCONNECT; | |
11621 | } | |
11622 | ||
11623 | err = pci_cleanup_aer_uncorrect_error_status(pdev); | |
11624 | if (err) { | |
11625 | dev_info(&pdev->dev, | |
11626 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", | |
11627 | err); | |
11628 | /* non-fatal, continue */ | |
11629 | } | |
11630 | ||
11631 | return result; | |
11632 | } | |
11633 | ||
11634 | /** | |
11635 | * i40e_pci_error_resume - restart operations after PCI error recovery | |
11636 | * @pdev: PCI device information struct | |
11637 | * | |
11638 | * Called to allow the driver to bring things back up after PCI error | |
11639 | * and/or reset recovery has finished. | |
11640 | **/ | |
11641 | static void i40e_pci_error_resume(struct pci_dev *pdev) | |
11642 | { | |
11643 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
11644 | ||
fb43201f | 11645 | dev_dbg(&pdev->dev, "%s\n", __func__); |
9007bccd SN |
11646 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
11647 | return; | |
11648 | ||
11649 | rtnl_lock(); | |
373149fc | 11650 | i40e_handle_reset_warning(pf, true); |
4c4935a9 | 11651 | rtnl_unlock(); |
9007bccd SN |
11652 | } |
11653 | ||
1d68005d JH |
11654 | /** |
11655 | * i40e_enable_mc_magic_wake - enable multicast magic packet wake up | |
11656 | * using the mac_address_write admin q function | |
11657 | * @pf: pointer to i40e_pf struct | |
11658 | **/ | |
11659 | static void i40e_enable_mc_magic_wake(struct i40e_pf *pf) | |
11660 | { | |
11661 | struct i40e_hw *hw = &pf->hw; | |
11662 | i40e_status ret; | |
11663 | u8 mac_addr[6]; | |
11664 | u16 flags = 0; | |
11665 | ||
11666 | /* Get current MAC address in case it's an LAA */ | |
11667 | if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) { | |
11668 | ether_addr_copy(mac_addr, | |
11669 | pf->vsi[pf->lan_vsi]->netdev->dev_addr); | |
11670 | } else { | |
11671 | dev_err(&pf->pdev->dev, | |
11672 | "Failed to retrieve MAC address; using default\n"); | |
11673 | ether_addr_copy(mac_addr, hw->mac.addr); | |
11674 | } | |
11675 | ||
11676 | /* The FW expects the mac address write cmd to first be called with | |
11677 | * one of these flags before calling it again with the multicast | |
11678 | * enable flags. | |
11679 | */ | |
11680 | flags = I40E_AQC_WRITE_TYPE_LAA_WOL; | |
11681 | ||
11682 | if (hw->func_caps.flex10_enable && hw->partition_id != 1) | |
11683 | flags = I40E_AQC_WRITE_TYPE_LAA_ONLY; | |
11684 | ||
11685 | ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL); | |
11686 | if (ret) { | |
11687 | dev_err(&pf->pdev->dev, | |
11688 | "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up"); | |
11689 | return; | |
11690 | } | |
11691 | ||
11692 | flags = I40E_AQC_MC_MAG_EN | |
11693 | | I40E_AQC_WOL_PRESERVE_ON_PFR | |
11694 | | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG; | |
11695 | ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL); | |
11696 | if (ret) | |
11697 | dev_err(&pf->pdev->dev, | |
11698 | "Failed to enable Multicast Magic Packet wake up\n"); | |
11699 | } | |
11700 | ||
9007bccd SN |
11701 | /** |
11702 | * i40e_shutdown - PCI callback for shutting down | |
11703 | * @pdev: PCI device information struct | |
11704 | **/ | |
11705 | static void i40e_shutdown(struct pci_dev *pdev) | |
11706 | { | |
11707 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
8e2773ae | 11708 | struct i40e_hw *hw = &pf->hw; |
9007bccd SN |
11709 | |
11710 | set_bit(__I40E_SUSPENDED, &pf->state); | |
11711 | set_bit(__I40E_DOWN, &pf->state); | |
11712 | rtnl_lock(); | |
373149fc | 11713 | i40e_prep_for_reset(pf, true); |
9007bccd SN |
11714 | rtnl_unlock(); |
11715 | ||
8e2773ae SN |
11716 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
11717 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); | |
11718 | ||
02b42498 CS |
11719 | del_timer_sync(&pf->service_timer); |
11720 | cancel_work_sync(&pf->service_task); | |
11721 | i40e_fdir_teardown(pf); | |
11722 | ||
921c467c MW |
11723 | /* Client close must be called explicitly here because the timer |
11724 | * has been stopped. | |
11725 | */ | |
11726 | i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false); | |
11727 | ||
1d68005d JH |
11728 | if (pf->wol_en && (pf->flags & I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE)) |
11729 | i40e_enable_mc_magic_wake(pf); | |
11730 | ||
02b42498 | 11731 | rtnl_lock(); |
373149fc | 11732 | i40e_prep_for_reset(pf, true); |
02b42498 CS |
11733 | rtnl_unlock(); |
11734 | ||
11735 | wr32(hw, I40E_PFPM_APM, | |
11736 | (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); | |
11737 | wr32(hw, I40E_PFPM_WUFC, | |
11738 | (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); | |
11739 | ||
e147758d SN |
11740 | i40e_clear_interrupt_scheme(pf); |
11741 | ||
9007bccd | 11742 | if (system_state == SYSTEM_POWER_OFF) { |
8e2773ae | 11743 | pci_wake_from_d3(pdev, pf->wol_en); |
9007bccd SN |
11744 | pci_set_power_state(pdev, PCI_D3hot); |
11745 | } | |
11746 | } | |
11747 | ||
11748 | #ifdef CONFIG_PM | |
11749 | /** | |
11750 | * i40e_suspend - PCI callback for moving to D3 | |
11751 | * @pdev: PCI device information struct | |
11752 | **/ | |
11753 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) | |
11754 | { | |
11755 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
8e2773ae | 11756 | struct i40e_hw *hw = &pf->hw; |
059ff69b | 11757 | int retval = 0; |
9007bccd SN |
11758 | |
11759 | set_bit(__I40E_SUSPENDED, &pf->state); | |
11760 | set_bit(__I40E_DOWN, &pf->state); | |
3932dbfe | 11761 | |
1d68005d JH |
11762 | if (pf->wol_en && (pf->flags & I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE)) |
11763 | i40e_enable_mc_magic_wake(pf); | |
11764 | ||
9007bccd | 11765 | rtnl_lock(); |
373149fc | 11766 | i40e_prep_for_reset(pf, true); |
9007bccd SN |
11767 | rtnl_unlock(); |
11768 | ||
8e2773ae SN |
11769 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
11770 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); | |
11771 | ||
b33d3b73 GR |
11772 | i40e_stop_misc_vector(pf); |
11773 | ||
059ff69b GR |
11774 | retval = pci_save_state(pdev); |
11775 | if (retval) | |
11776 | return retval; | |
11777 | ||
8e2773ae | 11778 | pci_wake_from_d3(pdev, pf->wol_en); |
9007bccd SN |
11779 | pci_set_power_state(pdev, PCI_D3hot); |
11780 | ||
059ff69b | 11781 | return retval; |
41c445ff JB |
11782 | } |
11783 | ||
9007bccd SN |
11784 | /** |
11785 | * i40e_resume - PCI callback for waking up from D3 | |
11786 | * @pdev: PCI device information struct | |
11787 | **/ | |
11788 | static int i40e_resume(struct pci_dev *pdev) | |
11789 | { | |
11790 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
11791 | u32 err; | |
11792 | ||
11793 | pci_set_power_state(pdev, PCI_D0); | |
11794 | pci_restore_state(pdev); | |
11795 | /* pci_restore_state() clears dev->state_saves, so | |
11796 | * call pci_save_state() again to restore it. | |
11797 | */ | |
11798 | pci_save_state(pdev); | |
11799 | ||
11800 | err = pci_enable_device_mem(pdev); | |
11801 | if (err) { | |
fb43201f | 11802 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
9007bccd SN |
11803 | return err; |
11804 | } | |
11805 | pci_set_master(pdev); | |
11806 | ||
11807 | /* no wakeup events while running */ | |
11808 | pci_wake_from_d3(pdev, false); | |
11809 | ||
11810 | /* handling the reset will rebuild the device state */ | |
11811 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { | |
11812 | clear_bit(__I40E_DOWN, &pf->state); | |
11813 | rtnl_lock(); | |
373149fc | 11814 | i40e_reset_and_rebuild(pf, false, true); |
9007bccd SN |
11815 | rtnl_unlock(); |
11816 | } | |
11817 | ||
11818 | return 0; | |
11819 | } | |
11820 | ||
11821 | #endif | |
41c445ff JB |
11822 | static const struct pci_error_handlers i40e_err_handler = { |
11823 | .error_detected = i40e_pci_error_detected, | |
11824 | .slot_reset = i40e_pci_error_slot_reset, | |
11825 | .resume = i40e_pci_error_resume, | |
11826 | }; | |
11827 | ||
11828 | static struct pci_driver i40e_driver = { | |
11829 | .name = i40e_driver_name, | |
11830 | .id_table = i40e_pci_tbl, | |
11831 | .probe = i40e_probe, | |
11832 | .remove = i40e_remove, | |
9007bccd SN |
11833 | #ifdef CONFIG_PM |
11834 | .suspend = i40e_suspend, | |
11835 | .resume = i40e_resume, | |
11836 | #endif | |
11837 | .shutdown = i40e_shutdown, | |
41c445ff JB |
11838 | .err_handler = &i40e_err_handler, |
11839 | .sriov_configure = i40e_pci_sriov_configure, | |
11840 | }; | |
11841 | ||
11842 | /** | |
11843 | * i40e_init_module - Driver registration routine | |
11844 | * | |
11845 | * i40e_init_module is the first routine called when the driver is | |
11846 | * loaded. All it does is register with the PCI subsystem. | |
11847 | **/ | |
11848 | static int __init i40e_init_module(void) | |
11849 | { | |
11850 | pr_info("%s: %s - version %s\n", i40e_driver_name, | |
11851 | i40e_driver_string, i40e_driver_version_str); | |
11852 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); | |
96664483 | 11853 | |
2803b16c JB |
11854 | /* we will see if single thread per module is enough for now, |
11855 | * it can't be any worse than using the system workqueue which | |
11856 | * was already single threaded | |
11857 | */ | |
6992a6c9 JK |
11858 | i40e_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1, |
11859 | i40e_driver_name); | |
2803b16c JB |
11860 | if (!i40e_wq) { |
11861 | pr_err("%s: Failed to create workqueue\n", i40e_driver_name); | |
11862 | return -ENOMEM; | |
11863 | } | |
11864 | ||
41c445ff JB |
11865 | i40e_dbg_init(); |
11866 | return pci_register_driver(&i40e_driver); | |
11867 | } | |
11868 | module_init(i40e_init_module); | |
11869 | ||
11870 | /** | |
11871 | * i40e_exit_module - Driver exit cleanup routine | |
11872 | * | |
11873 | * i40e_exit_module is called just before the driver is removed | |
11874 | * from memory. | |
11875 | **/ | |
11876 | static void __exit i40e_exit_module(void) | |
11877 | { | |
11878 | pci_unregister_driver(&i40e_driver); | |
2803b16c | 11879 | destroy_workqueue(i40e_wq); |
41c445ff JB |
11880 | i40e_dbg_exit(); |
11881 | } | |
11882 | module_exit(i40e_exit_module); |