Commit | Line | Data |
---|---|---|
41c445ff JB |
1 | /******************************************************************************* |
2 | * | |
3 | * Intel Ethernet Controller XL710 Family Linux Driver | |
dc641b73 | 4 | * Copyright(c) 2013 - 2014 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 | ||
27 | /* Local includes */ | |
28 | #include "i40e.h" | |
a1c9a9d9 JK |
29 | #ifdef CONFIG_I40E_VXLAN |
30 | #include <net/vxlan.h> | |
31 | #endif | |
41c445ff JB |
32 | |
33 | const char i40e_driver_name[] = "i40e"; | |
34 | static const char i40e_driver_string[] = | |
35 | "Intel(R) Ethernet Connection XL710 Network Driver"; | |
36 | ||
37 | #define DRV_KERN "-k" | |
38 | ||
39 | #define DRV_VERSION_MAJOR 0 | |
40 | #define DRV_VERSION_MINOR 3 | |
2062862a | 41 | #define DRV_VERSION_BUILD 34 |
41c445ff JB |
42 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
43 | __stringify(DRV_VERSION_MINOR) "." \ | |
44 | __stringify(DRV_VERSION_BUILD) DRV_KERN | |
45 | const char i40e_driver_version_str[] = DRV_VERSION; | |
8fb905b3 | 46 | static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation."; |
41c445ff JB |
47 | |
48 | /* a bit of forward declarations */ | |
49 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); | |
50 | static void i40e_handle_reset_warning(struct i40e_pf *pf); | |
51 | static int i40e_add_vsi(struct i40e_vsi *vsi); | |
52 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi); | |
bc7d338f | 53 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); |
41c445ff JB |
54 | static int i40e_setup_misc_vector(struct i40e_pf *pf); |
55 | static void i40e_determine_queue_usage(struct i40e_pf *pf); | |
56 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); | |
cbf61325 | 57 | static void i40e_fdir_sb_setup(struct i40e_pf *pf); |
4e3b35b0 | 58 | static int i40e_veb_get_bw_info(struct i40e_veb *veb); |
41c445ff JB |
59 | |
60 | /* i40e_pci_tbl - PCI Device ID Table | |
61 | * | |
62 | * Last entry must be all 0s | |
63 | * | |
64 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, | |
65 | * Class, Class Mask, private data (not used) } | |
66 | */ | |
67 | static DEFINE_PCI_DEVICE_TABLE(i40e_pci_tbl) = { | |
ab60085e SN |
68 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0}, |
69 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X710), 0}, | |
70 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0}, | |
71 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_A), 0}, | |
72 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0}, | |
73 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0}, | |
74 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_D), 0}, | |
75 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0}, | |
76 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0}, | |
77 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0}, | |
41c445ff JB |
78 | /* required last entry */ |
79 | {0, } | |
80 | }; | |
81 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); | |
82 | ||
83 | #define I40E_MAX_VF_COUNT 128 | |
84 | static int debug = -1; | |
85 | module_param(debug, int, 0); | |
86 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); | |
87 | ||
88 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); | |
89 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); | |
90 | MODULE_LICENSE("GPL"); | |
91 | MODULE_VERSION(DRV_VERSION); | |
92 | ||
93 | /** | |
94 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code | |
95 | * @hw: pointer to the HW structure | |
96 | * @mem: ptr to mem struct to fill out | |
97 | * @size: size of memory requested | |
98 | * @alignment: what to align the allocation to | |
99 | **/ | |
100 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, | |
101 | u64 size, u32 alignment) | |
102 | { | |
103 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; | |
104 | ||
105 | mem->size = ALIGN(size, alignment); | |
106 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, | |
107 | &mem->pa, GFP_KERNEL); | |
93bc73b8 JB |
108 | if (!mem->va) |
109 | return -ENOMEM; | |
41c445ff | 110 | |
93bc73b8 | 111 | return 0; |
41c445ff JB |
112 | } |
113 | ||
114 | /** | |
115 | * i40e_free_dma_mem_d - OS specific memory free for shared code | |
116 | * @hw: pointer to the HW structure | |
117 | * @mem: ptr to mem struct to free | |
118 | **/ | |
119 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) | |
120 | { | |
121 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; | |
122 | ||
123 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); | |
124 | mem->va = NULL; | |
125 | mem->pa = 0; | |
126 | mem->size = 0; | |
127 | ||
128 | return 0; | |
129 | } | |
130 | ||
131 | /** | |
132 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code | |
133 | * @hw: pointer to the HW structure | |
134 | * @mem: ptr to mem struct to fill out | |
135 | * @size: size of memory requested | |
136 | **/ | |
137 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, | |
138 | u32 size) | |
139 | { | |
140 | mem->size = size; | |
141 | mem->va = kzalloc(size, GFP_KERNEL); | |
142 | ||
93bc73b8 JB |
143 | if (!mem->va) |
144 | return -ENOMEM; | |
41c445ff | 145 | |
93bc73b8 | 146 | return 0; |
41c445ff JB |
147 | } |
148 | ||
149 | /** | |
150 | * i40e_free_virt_mem_d - OS specific memory free for shared code | |
151 | * @hw: pointer to the HW structure | |
152 | * @mem: ptr to mem struct to free | |
153 | **/ | |
154 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) | |
155 | { | |
156 | /* it's ok to kfree a NULL pointer */ | |
157 | kfree(mem->va); | |
158 | mem->va = NULL; | |
159 | mem->size = 0; | |
160 | ||
161 | return 0; | |
162 | } | |
163 | ||
164 | /** | |
165 | * i40e_get_lump - find a lump of free generic resource | |
166 | * @pf: board private structure | |
167 | * @pile: the pile of resource to search | |
168 | * @needed: the number of items needed | |
169 | * @id: an owner id to stick on the items assigned | |
170 | * | |
171 | * Returns the base item index of the lump, or negative for error | |
172 | * | |
173 | * The search_hint trick and lack of advanced fit-finding only work | |
174 | * because we're highly likely to have all the same size lump requests. | |
175 | * Linear search time and any fragmentation should be minimal. | |
176 | **/ | |
177 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, | |
178 | u16 needed, u16 id) | |
179 | { | |
180 | int ret = -ENOMEM; | |
ddf434ac | 181 | int i, j; |
41c445ff JB |
182 | |
183 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { | |
184 | dev_info(&pf->pdev->dev, | |
185 | "param err: pile=%p needed=%d id=0x%04x\n", | |
186 | pile, needed, id); | |
187 | return -EINVAL; | |
188 | } | |
189 | ||
190 | /* start the linear search with an imperfect hint */ | |
191 | i = pile->search_hint; | |
ddf434ac | 192 | while (i < pile->num_entries) { |
41c445ff JB |
193 | /* skip already allocated entries */ |
194 | if (pile->list[i] & I40E_PILE_VALID_BIT) { | |
195 | i++; | |
196 | continue; | |
197 | } | |
198 | ||
199 | /* do we have enough in this lump? */ | |
200 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { | |
201 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) | |
202 | break; | |
203 | } | |
204 | ||
205 | if (j == needed) { | |
206 | /* there was enough, so assign it to the requestor */ | |
207 | for (j = 0; j < needed; j++) | |
208 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; | |
209 | ret = i; | |
210 | pile->search_hint = i + j; | |
ddf434ac | 211 | break; |
41c445ff JB |
212 | } else { |
213 | /* not enough, so skip over it and continue looking */ | |
214 | i += j; | |
215 | } | |
216 | } | |
217 | ||
218 | return ret; | |
219 | } | |
220 | ||
221 | /** | |
222 | * i40e_put_lump - return a lump of generic resource | |
223 | * @pile: the pile of resource to search | |
224 | * @index: the base item index | |
225 | * @id: the owner id of the items assigned | |
226 | * | |
227 | * Returns the count of items in the lump | |
228 | **/ | |
229 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) | |
230 | { | |
231 | int valid_id = (id | I40E_PILE_VALID_BIT); | |
232 | int count = 0; | |
233 | int i; | |
234 | ||
235 | if (!pile || index >= pile->num_entries) | |
236 | return -EINVAL; | |
237 | ||
238 | for (i = index; | |
239 | i < pile->num_entries && pile->list[i] == valid_id; | |
240 | i++) { | |
241 | pile->list[i] = 0; | |
242 | count++; | |
243 | } | |
244 | ||
245 | if (count && index < pile->search_hint) | |
246 | pile->search_hint = index; | |
247 | ||
248 | return count; | |
249 | } | |
250 | ||
251 | /** | |
252 | * i40e_service_event_schedule - Schedule the service task to wake up | |
253 | * @pf: board private structure | |
254 | * | |
255 | * If not already scheduled, this puts the task into the work queue | |
256 | **/ | |
257 | static void i40e_service_event_schedule(struct i40e_pf *pf) | |
258 | { | |
259 | if (!test_bit(__I40E_DOWN, &pf->state) && | |
260 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && | |
261 | !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) | |
262 | schedule_work(&pf->service_task); | |
263 | } | |
264 | ||
265 | /** | |
266 | * i40e_tx_timeout - Respond to a Tx Hang | |
267 | * @netdev: network interface device structure | |
268 | * | |
269 | * If any port has noticed a Tx timeout, it is likely that the whole | |
270 | * device is munged, not just the one netdev port, so go for the full | |
271 | * reset. | |
272 | **/ | |
273 | static void i40e_tx_timeout(struct net_device *netdev) | |
274 | { | |
275 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
276 | struct i40e_vsi *vsi = np->vsi; | |
277 | struct i40e_pf *pf = vsi->back; | |
278 | ||
279 | pf->tx_timeout_count++; | |
280 | ||
281 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) | |
282 | pf->tx_timeout_recovery_level = 0; | |
283 | pf->tx_timeout_last_recovery = jiffies; | |
284 | netdev_info(netdev, "tx_timeout recovery level %d\n", | |
285 | pf->tx_timeout_recovery_level); | |
286 | ||
287 | switch (pf->tx_timeout_recovery_level) { | |
288 | case 0: | |
289 | /* disable and re-enable queues for the VSI */ | |
290 | if (in_interrupt()) { | |
291 | set_bit(__I40E_REINIT_REQUESTED, &pf->state); | |
292 | set_bit(__I40E_REINIT_REQUESTED, &vsi->state); | |
293 | } else { | |
294 | i40e_vsi_reinit_locked(vsi); | |
295 | } | |
296 | break; | |
297 | case 1: | |
298 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); | |
299 | break; | |
300 | case 2: | |
301 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); | |
302 | break; | |
303 | case 3: | |
304 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); | |
305 | break; | |
306 | default: | |
307 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); | |
e108b0e3 | 308 | set_bit(__I40E_DOWN, &vsi->state); |
41c445ff JB |
309 | i40e_down(vsi); |
310 | break; | |
311 | } | |
312 | i40e_service_event_schedule(pf); | |
313 | pf->tx_timeout_recovery_level++; | |
314 | } | |
315 | ||
316 | /** | |
317 | * i40e_release_rx_desc - Store the new tail and head values | |
318 | * @rx_ring: ring to bump | |
319 | * @val: new head index | |
320 | **/ | |
321 | static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val) | |
322 | { | |
323 | rx_ring->next_to_use = val; | |
324 | ||
325 | /* Force memory writes to complete before letting h/w | |
326 | * know there are new descriptors to fetch. (Only | |
327 | * applicable for weak-ordered memory model archs, | |
328 | * such as IA-64). | |
329 | */ | |
330 | wmb(); | |
331 | writel(val, rx_ring->tail); | |
332 | } | |
333 | ||
334 | /** | |
335 | * i40e_get_vsi_stats_struct - Get System Network Statistics | |
336 | * @vsi: the VSI we care about | |
337 | * | |
338 | * Returns the address of the device statistics structure. | |
339 | * The statistics are actually updated from the service task. | |
340 | **/ | |
341 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) | |
342 | { | |
343 | return &vsi->net_stats; | |
344 | } | |
345 | ||
346 | /** | |
347 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface | |
348 | * @netdev: network interface device structure | |
349 | * | |
350 | * Returns the address of the device statistics structure. | |
351 | * The statistics are actually updated from the service task. | |
352 | **/ | |
353 | static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( | |
354 | struct net_device *netdev, | |
980e9b11 | 355 | struct rtnl_link_stats64 *stats) |
41c445ff JB |
356 | { |
357 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
358 | struct i40e_vsi *vsi = np->vsi; | |
980e9b11 AD |
359 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
360 | int i; | |
361 | ||
bc7d338f ASJ |
362 | if (test_bit(__I40E_DOWN, &vsi->state)) |
363 | return stats; | |
364 | ||
3c325ced JB |
365 | if (!vsi->tx_rings) |
366 | return stats; | |
367 | ||
980e9b11 AD |
368 | rcu_read_lock(); |
369 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
370 | struct i40e_ring *tx_ring, *rx_ring; | |
371 | u64 bytes, packets; | |
372 | unsigned int start; | |
373 | ||
374 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); | |
375 | if (!tx_ring) | |
376 | continue; | |
377 | ||
378 | do { | |
57a7744e | 379 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
980e9b11 AD |
380 | packets = tx_ring->stats.packets; |
381 | bytes = tx_ring->stats.bytes; | |
57a7744e | 382 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
980e9b11 AD |
383 | |
384 | stats->tx_packets += packets; | |
385 | stats->tx_bytes += bytes; | |
386 | rx_ring = &tx_ring[1]; | |
387 | ||
388 | do { | |
57a7744e | 389 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
980e9b11 AD |
390 | packets = rx_ring->stats.packets; |
391 | bytes = rx_ring->stats.bytes; | |
57a7744e | 392 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
41c445ff | 393 | |
980e9b11 AD |
394 | stats->rx_packets += packets; |
395 | stats->rx_bytes += bytes; | |
396 | } | |
397 | rcu_read_unlock(); | |
398 | ||
399 | /* following stats updated by ixgbe_watchdog_task() */ | |
400 | stats->multicast = vsi_stats->multicast; | |
401 | stats->tx_errors = vsi_stats->tx_errors; | |
402 | stats->tx_dropped = vsi_stats->tx_dropped; | |
403 | stats->rx_errors = vsi_stats->rx_errors; | |
404 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; | |
405 | stats->rx_length_errors = vsi_stats->rx_length_errors; | |
41c445ff | 406 | |
980e9b11 | 407 | return stats; |
41c445ff JB |
408 | } |
409 | ||
410 | /** | |
411 | * i40e_vsi_reset_stats - Resets all stats of the given vsi | |
412 | * @vsi: the VSI to have its stats reset | |
413 | **/ | |
414 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) | |
415 | { | |
416 | struct rtnl_link_stats64 *ns; | |
417 | int i; | |
418 | ||
419 | if (!vsi) | |
420 | return; | |
421 | ||
422 | ns = i40e_get_vsi_stats_struct(vsi); | |
423 | memset(ns, 0, sizeof(*ns)); | |
424 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); | |
425 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); | |
426 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); | |
8e9dca53 | 427 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
41c445ff | 428 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
9f65e15b AD |
429 | memset(&vsi->rx_rings[i]->stats, 0 , |
430 | sizeof(vsi->rx_rings[i]->stats)); | |
431 | memset(&vsi->rx_rings[i]->rx_stats, 0 , | |
432 | sizeof(vsi->rx_rings[i]->rx_stats)); | |
433 | memset(&vsi->tx_rings[i]->stats, 0 , | |
434 | sizeof(vsi->tx_rings[i]->stats)); | |
435 | memset(&vsi->tx_rings[i]->tx_stats, 0, | |
436 | sizeof(vsi->tx_rings[i]->tx_stats)); | |
41c445ff | 437 | } |
8e9dca53 | 438 | } |
41c445ff JB |
439 | vsi->stat_offsets_loaded = false; |
440 | } | |
441 | ||
442 | /** | |
443 | * i40e_pf_reset_stats - Reset all of the stats for the given pf | |
444 | * @pf: the PF to be reset | |
445 | **/ | |
446 | void i40e_pf_reset_stats(struct i40e_pf *pf) | |
447 | { | |
448 | memset(&pf->stats, 0, sizeof(pf->stats)); | |
449 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); | |
450 | pf->stat_offsets_loaded = false; | |
451 | } | |
452 | ||
453 | /** | |
454 | * i40e_stat_update48 - read and update a 48 bit stat from the chip | |
455 | * @hw: ptr to the hardware info | |
456 | * @hireg: the high 32 bit reg to read | |
457 | * @loreg: the low 32 bit reg to read | |
458 | * @offset_loaded: has the initial offset been loaded yet | |
459 | * @offset: ptr to current offset value | |
460 | * @stat: ptr to the stat | |
461 | * | |
462 | * Since the device stats are not reset at PFReset, they likely will not | |
463 | * be zeroed when the driver starts. We'll save the first values read | |
464 | * and use them as offsets to be subtracted from the raw values in order | |
465 | * to report stats that count from zero. In the process, we also manage | |
466 | * the potential roll-over. | |
467 | **/ | |
468 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, | |
469 | bool offset_loaded, u64 *offset, u64 *stat) | |
470 | { | |
471 | u64 new_data; | |
472 | ||
ab60085e | 473 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
41c445ff JB |
474 | new_data = rd32(hw, loreg); |
475 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; | |
476 | } else { | |
477 | new_data = rd64(hw, loreg); | |
478 | } | |
479 | if (!offset_loaded) | |
480 | *offset = new_data; | |
481 | if (likely(new_data >= *offset)) | |
482 | *stat = new_data - *offset; | |
483 | else | |
484 | *stat = (new_data + ((u64)1 << 48)) - *offset; | |
485 | *stat &= 0xFFFFFFFFFFFFULL; | |
486 | } | |
487 | ||
488 | /** | |
489 | * i40e_stat_update32 - read and update a 32 bit stat from the chip | |
490 | * @hw: ptr to the hardware info | |
491 | * @reg: the hw reg to read | |
492 | * @offset_loaded: has the initial offset been loaded yet | |
493 | * @offset: ptr to current offset value | |
494 | * @stat: ptr to the stat | |
495 | **/ | |
496 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, | |
497 | bool offset_loaded, u64 *offset, u64 *stat) | |
498 | { | |
499 | u32 new_data; | |
500 | ||
501 | new_data = rd32(hw, reg); | |
502 | if (!offset_loaded) | |
503 | *offset = new_data; | |
504 | if (likely(new_data >= *offset)) | |
505 | *stat = (u32)(new_data - *offset); | |
506 | else | |
507 | *stat = (u32)((new_data + ((u64)1 << 32)) - *offset); | |
508 | } | |
509 | ||
510 | /** | |
511 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. | |
512 | * @vsi: the VSI to be updated | |
513 | **/ | |
514 | void i40e_update_eth_stats(struct i40e_vsi *vsi) | |
515 | { | |
516 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); | |
517 | struct i40e_pf *pf = vsi->back; | |
518 | struct i40e_hw *hw = &pf->hw; | |
519 | struct i40e_eth_stats *oes; | |
520 | struct i40e_eth_stats *es; /* device's eth stats */ | |
521 | ||
522 | es = &vsi->eth_stats; | |
523 | oes = &vsi->eth_stats_offsets; | |
524 | ||
525 | /* Gather up the stats that the hw collects */ | |
526 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), | |
527 | vsi->stat_offsets_loaded, | |
528 | &oes->tx_errors, &es->tx_errors); | |
529 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), | |
530 | vsi->stat_offsets_loaded, | |
531 | &oes->rx_discards, &es->rx_discards); | |
532 | ||
533 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), | |
534 | I40E_GLV_GORCL(stat_idx), | |
535 | vsi->stat_offsets_loaded, | |
536 | &oes->rx_bytes, &es->rx_bytes); | |
537 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), | |
538 | I40E_GLV_UPRCL(stat_idx), | |
539 | vsi->stat_offsets_loaded, | |
540 | &oes->rx_unicast, &es->rx_unicast); | |
541 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), | |
542 | I40E_GLV_MPRCL(stat_idx), | |
543 | vsi->stat_offsets_loaded, | |
544 | &oes->rx_multicast, &es->rx_multicast); | |
545 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), | |
546 | I40E_GLV_BPRCL(stat_idx), | |
547 | vsi->stat_offsets_loaded, | |
548 | &oes->rx_broadcast, &es->rx_broadcast); | |
549 | ||
550 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), | |
551 | I40E_GLV_GOTCL(stat_idx), | |
552 | vsi->stat_offsets_loaded, | |
553 | &oes->tx_bytes, &es->tx_bytes); | |
554 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), | |
555 | I40E_GLV_UPTCL(stat_idx), | |
556 | vsi->stat_offsets_loaded, | |
557 | &oes->tx_unicast, &es->tx_unicast); | |
558 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), | |
559 | I40E_GLV_MPTCL(stat_idx), | |
560 | vsi->stat_offsets_loaded, | |
561 | &oes->tx_multicast, &es->tx_multicast); | |
562 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), | |
563 | I40E_GLV_BPTCL(stat_idx), | |
564 | vsi->stat_offsets_loaded, | |
565 | &oes->tx_broadcast, &es->tx_broadcast); | |
566 | vsi->stat_offsets_loaded = true; | |
567 | } | |
568 | ||
569 | /** | |
570 | * i40e_update_veb_stats - Update Switch component statistics | |
571 | * @veb: the VEB being updated | |
572 | **/ | |
573 | static void i40e_update_veb_stats(struct i40e_veb *veb) | |
574 | { | |
575 | struct i40e_pf *pf = veb->pf; | |
576 | struct i40e_hw *hw = &pf->hw; | |
577 | struct i40e_eth_stats *oes; | |
578 | struct i40e_eth_stats *es; /* device's eth stats */ | |
579 | int idx = 0; | |
580 | ||
581 | idx = veb->stats_idx; | |
582 | es = &veb->stats; | |
583 | oes = &veb->stats_offsets; | |
584 | ||
585 | /* Gather up the stats that the hw collects */ | |
586 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), | |
587 | veb->stat_offsets_loaded, | |
588 | &oes->tx_discards, &es->tx_discards); | |
7134f9ce JB |
589 | if (hw->revision_id > 0) |
590 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), | |
591 | veb->stat_offsets_loaded, | |
592 | &oes->rx_unknown_protocol, | |
593 | &es->rx_unknown_protocol); | |
41c445ff JB |
594 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
595 | veb->stat_offsets_loaded, | |
596 | &oes->rx_bytes, &es->rx_bytes); | |
597 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), | |
598 | veb->stat_offsets_loaded, | |
599 | &oes->rx_unicast, &es->rx_unicast); | |
600 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), | |
601 | veb->stat_offsets_loaded, | |
602 | &oes->rx_multicast, &es->rx_multicast); | |
603 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), | |
604 | veb->stat_offsets_loaded, | |
605 | &oes->rx_broadcast, &es->rx_broadcast); | |
606 | ||
607 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), | |
608 | veb->stat_offsets_loaded, | |
609 | &oes->tx_bytes, &es->tx_bytes); | |
610 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), | |
611 | veb->stat_offsets_loaded, | |
612 | &oes->tx_unicast, &es->tx_unicast); | |
613 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), | |
614 | veb->stat_offsets_loaded, | |
615 | &oes->tx_multicast, &es->tx_multicast); | |
616 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), | |
617 | veb->stat_offsets_loaded, | |
618 | &oes->tx_broadcast, &es->tx_broadcast); | |
619 | veb->stat_offsets_loaded = true; | |
620 | } | |
621 | ||
622 | /** | |
623 | * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode | |
624 | * @pf: the corresponding PF | |
625 | * | |
626 | * Update the Rx XOFF counter (PAUSE frames) in link flow control mode | |
627 | **/ | |
628 | static void i40e_update_link_xoff_rx(struct i40e_pf *pf) | |
629 | { | |
630 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; | |
631 | struct i40e_hw_port_stats *nsd = &pf->stats; | |
632 | struct i40e_hw *hw = &pf->hw; | |
633 | u64 xoff = 0; | |
634 | u16 i, v; | |
635 | ||
636 | if ((hw->fc.current_mode != I40E_FC_FULL) && | |
637 | (hw->fc.current_mode != I40E_FC_RX_PAUSE)) | |
638 | return; | |
639 | ||
640 | xoff = nsd->link_xoff_rx; | |
641 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), | |
642 | pf->stat_offsets_loaded, | |
643 | &osd->link_xoff_rx, &nsd->link_xoff_rx); | |
644 | ||
645 | /* No new LFC xoff rx */ | |
646 | if (!(nsd->link_xoff_rx - xoff)) | |
647 | return; | |
648 | ||
649 | /* Clear the __I40E_HANG_CHECK_ARMED bit for all Tx rings */ | |
650 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | |
651 | struct i40e_vsi *vsi = pf->vsi[v]; | |
652 | ||
653 | if (!vsi) | |
654 | continue; | |
655 | ||
656 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
9f65e15b | 657 | struct i40e_ring *ring = vsi->tx_rings[i]; |
41c445ff JB |
658 | clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state); |
659 | } | |
660 | } | |
661 | } | |
662 | ||
663 | /** | |
664 | * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode | |
665 | * @pf: the corresponding PF | |
666 | * | |
667 | * Update the Rx XOFF counter (PAUSE frames) in PFC mode | |
668 | **/ | |
669 | static void i40e_update_prio_xoff_rx(struct i40e_pf *pf) | |
670 | { | |
671 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; | |
672 | struct i40e_hw_port_stats *nsd = &pf->stats; | |
673 | bool xoff[I40E_MAX_TRAFFIC_CLASS] = {false}; | |
674 | struct i40e_dcbx_config *dcb_cfg; | |
675 | struct i40e_hw *hw = &pf->hw; | |
676 | u16 i, v; | |
677 | u8 tc; | |
678 | ||
679 | dcb_cfg = &hw->local_dcbx_config; | |
680 | ||
681 | /* See if DCB enabled with PFC TC */ | |
682 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED) || | |
683 | !(dcb_cfg->pfc.pfcenable)) { | |
684 | i40e_update_link_xoff_rx(pf); | |
685 | return; | |
686 | } | |
687 | ||
688 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { | |
689 | u64 prio_xoff = nsd->priority_xoff_rx[i]; | |
690 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), | |
691 | pf->stat_offsets_loaded, | |
692 | &osd->priority_xoff_rx[i], | |
693 | &nsd->priority_xoff_rx[i]); | |
694 | ||
695 | /* No new PFC xoff rx */ | |
696 | if (!(nsd->priority_xoff_rx[i] - prio_xoff)) | |
697 | continue; | |
698 | /* Get the TC for given priority */ | |
699 | tc = dcb_cfg->etscfg.prioritytable[i]; | |
700 | xoff[tc] = true; | |
701 | } | |
702 | ||
703 | /* Clear the __I40E_HANG_CHECK_ARMED bit for Tx rings */ | |
704 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | |
705 | struct i40e_vsi *vsi = pf->vsi[v]; | |
706 | ||
707 | if (!vsi) | |
708 | continue; | |
709 | ||
710 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
9f65e15b | 711 | struct i40e_ring *ring = vsi->tx_rings[i]; |
41c445ff JB |
712 | |
713 | tc = ring->dcb_tc; | |
714 | if (xoff[tc]) | |
715 | clear_bit(__I40E_HANG_CHECK_ARMED, | |
716 | &ring->state); | |
717 | } | |
718 | } | |
719 | } | |
720 | ||
721 | /** | |
722 | * i40e_update_stats - Update the board statistics counters. | |
723 | * @vsi: the VSI to be updated | |
724 | * | |
725 | * There are a few instances where we store the same stat in a | |
726 | * couple of different structs. This is partly because we have | |
727 | * the netdev stats that need to be filled out, which is slightly | |
728 | * different from the "eth_stats" defined by the chip and used in | |
729 | * VF communications. We sort it all out here in a central place. | |
730 | **/ | |
731 | void i40e_update_stats(struct i40e_vsi *vsi) | |
732 | { | |
733 | struct i40e_pf *pf = vsi->back; | |
734 | struct i40e_hw *hw = &pf->hw; | |
735 | struct rtnl_link_stats64 *ons; | |
736 | struct rtnl_link_stats64 *ns; /* netdev stats */ | |
737 | struct i40e_eth_stats *oes; | |
738 | struct i40e_eth_stats *es; /* device's eth stats */ | |
739 | u32 tx_restart, tx_busy; | |
740 | u32 rx_page, rx_buf; | |
741 | u64 rx_p, rx_b; | |
742 | u64 tx_p, tx_b; | |
743 | int i; | |
744 | u16 q; | |
745 | ||
746 | if (test_bit(__I40E_DOWN, &vsi->state) || | |
747 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) | |
748 | return; | |
749 | ||
750 | ns = i40e_get_vsi_stats_struct(vsi); | |
751 | ons = &vsi->net_stats_offsets; | |
752 | es = &vsi->eth_stats; | |
753 | oes = &vsi->eth_stats_offsets; | |
754 | ||
755 | /* Gather up the netdev and vsi stats that the driver collects | |
756 | * on the fly during packet processing | |
757 | */ | |
758 | rx_b = rx_p = 0; | |
759 | tx_b = tx_p = 0; | |
760 | tx_restart = tx_busy = 0; | |
761 | rx_page = 0; | |
762 | rx_buf = 0; | |
980e9b11 | 763 | rcu_read_lock(); |
41c445ff JB |
764 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
765 | struct i40e_ring *p; | |
980e9b11 AD |
766 | u64 bytes, packets; |
767 | unsigned int start; | |
768 | ||
769 | /* locate Tx ring */ | |
770 | p = ACCESS_ONCE(vsi->tx_rings[q]); | |
771 | ||
772 | do { | |
57a7744e | 773 | start = u64_stats_fetch_begin_irq(&p->syncp); |
980e9b11 AD |
774 | packets = p->stats.packets; |
775 | bytes = p->stats.bytes; | |
57a7744e | 776 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
980e9b11 AD |
777 | tx_b += bytes; |
778 | tx_p += packets; | |
779 | tx_restart += p->tx_stats.restart_queue; | |
780 | tx_busy += p->tx_stats.tx_busy; | |
41c445ff | 781 | |
980e9b11 AD |
782 | /* Rx queue is part of the same block as Tx queue */ |
783 | p = &p[1]; | |
784 | do { | |
57a7744e | 785 | start = u64_stats_fetch_begin_irq(&p->syncp); |
980e9b11 AD |
786 | packets = p->stats.packets; |
787 | bytes = p->stats.bytes; | |
57a7744e | 788 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
980e9b11 AD |
789 | rx_b += bytes; |
790 | rx_p += packets; | |
420136cc MW |
791 | rx_buf += p->rx_stats.alloc_buff_failed; |
792 | rx_page += p->rx_stats.alloc_page_failed; | |
41c445ff | 793 | } |
980e9b11 | 794 | rcu_read_unlock(); |
41c445ff JB |
795 | vsi->tx_restart = tx_restart; |
796 | vsi->tx_busy = tx_busy; | |
797 | vsi->rx_page_failed = rx_page; | |
798 | vsi->rx_buf_failed = rx_buf; | |
799 | ||
800 | ns->rx_packets = rx_p; | |
801 | ns->rx_bytes = rx_b; | |
802 | ns->tx_packets = tx_p; | |
803 | ns->tx_bytes = tx_b; | |
804 | ||
805 | i40e_update_eth_stats(vsi); | |
806 | /* update netdev stats from eth stats */ | |
807 | ons->rx_errors = oes->rx_errors; | |
808 | ns->rx_errors = es->rx_errors; | |
809 | ons->tx_errors = oes->tx_errors; | |
810 | ns->tx_errors = es->tx_errors; | |
811 | ons->multicast = oes->rx_multicast; | |
812 | ns->multicast = es->rx_multicast; | |
813 | ons->tx_dropped = oes->tx_discards; | |
814 | ns->tx_dropped = es->tx_discards; | |
815 | ||
816 | /* Get the port data only if this is the main PF VSI */ | |
817 | if (vsi == pf->vsi[pf->lan_vsi]) { | |
818 | struct i40e_hw_port_stats *nsd = &pf->stats; | |
819 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; | |
820 | ||
821 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), | |
822 | I40E_GLPRT_GORCL(hw->port), | |
823 | pf->stat_offsets_loaded, | |
824 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); | |
825 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), | |
826 | I40E_GLPRT_GOTCL(hw->port), | |
827 | pf->stat_offsets_loaded, | |
828 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); | |
829 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), | |
830 | pf->stat_offsets_loaded, | |
831 | &osd->eth.rx_discards, | |
832 | &nsd->eth.rx_discards); | |
833 | i40e_stat_update32(hw, I40E_GLPRT_TDPC(hw->port), | |
834 | pf->stat_offsets_loaded, | |
835 | &osd->eth.tx_discards, | |
836 | &nsd->eth.tx_discards); | |
837 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), | |
838 | I40E_GLPRT_MPRCL(hw->port), | |
839 | pf->stat_offsets_loaded, | |
840 | &osd->eth.rx_multicast, | |
841 | &nsd->eth.rx_multicast); | |
842 | ||
843 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), | |
844 | pf->stat_offsets_loaded, | |
845 | &osd->tx_dropped_link_down, | |
846 | &nsd->tx_dropped_link_down); | |
847 | ||
848 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), | |
849 | pf->stat_offsets_loaded, | |
850 | &osd->crc_errors, &nsd->crc_errors); | |
851 | ns->rx_crc_errors = nsd->crc_errors; | |
852 | ||
853 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), | |
854 | pf->stat_offsets_loaded, | |
855 | &osd->illegal_bytes, &nsd->illegal_bytes); | |
856 | ns->rx_errors = nsd->crc_errors | |
857 | + nsd->illegal_bytes; | |
858 | ||
859 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), | |
860 | pf->stat_offsets_loaded, | |
861 | &osd->mac_local_faults, | |
862 | &nsd->mac_local_faults); | |
863 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), | |
864 | pf->stat_offsets_loaded, | |
865 | &osd->mac_remote_faults, | |
866 | &nsd->mac_remote_faults); | |
867 | ||
868 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), | |
869 | pf->stat_offsets_loaded, | |
870 | &osd->rx_length_errors, | |
871 | &nsd->rx_length_errors); | |
872 | ns->rx_length_errors = nsd->rx_length_errors; | |
873 | ||
874 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), | |
875 | pf->stat_offsets_loaded, | |
876 | &osd->link_xon_rx, &nsd->link_xon_rx); | |
877 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), | |
878 | pf->stat_offsets_loaded, | |
879 | &osd->link_xon_tx, &nsd->link_xon_tx); | |
880 | i40e_update_prio_xoff_rx(pf); /* handles I40E_GLPRT_LXOFFRXC */ | |
881 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), | |
882 | pf->stat_offsets_loaded, | |
883 | &osd->link_xoff_tx, &nsd->link_xoff_tx); | |
884 | ||
885 | for (i = 0; i < 8; i++) { | |
886 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), | |
887 | pf->stat_offsets_loaded, | |
888 | &osd->priority_xon_rx[i], | |
889 | &nsd->priority_xon_rx[i]); | |
890 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), | |
891 | pf->stat_offsets_loaded, | |
892 | &osd->priority_xon_tx[i], | |
893 | &nsd->priority_xon_tx[i]); | |
894 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), | |
895 | pf->stat_offsets_loaded, | |
896 | &osd->priority_xoff_tx[i], | |
897 | &nsd->priority_xoff_tx[i]); | |
898 | i40e_stat_update32(hw, | |
899 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), | |
900 | pf->stat_offsets_loaded, | |
901 | &osd->priority_xon_2_xoff[i], | |
902 | &nsd->priority_xon_2_xoff[i]); | |
903 | } | |
904 | ||
905 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), | |
906 | I40E_GLPRT_PRC64L(hw->port), | |
907 | pf->stat_offsets_loaded, | |
908 | &osd->rx_size_64, &nsd->rx_size_64); | |
909 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), | |
910 | I40E_GLPRT_PRC127L(hw->port), | |
911 | pf->stat_offsets_loaded, | |
912 | &osd->rx_size_127, &nsd->rx_size_127); | |
913 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), | |
914 | I40E_GLPRT_PRC255L(hw->port), | |
915 | pf->stat_offsets_loaded, | |
916 | &osd->rx_size_255, &nsd->rx_size_255); | |
917 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), | |
918 | I40E_GLPRT_PRC511L(hw->port), | |
919 | pf->stat_offsets_loaded, | |
920 | &osd->rx_size_511, &nsd->rx_size_511); | |
921 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), | |
922 | I40E_GLPRT_PRC1023L(hw->port), | |
923 | pf->stat_offsets_loaded, | |
924 | &osd->rx_size_1023, &nsd->rx_size_1023); | |
925 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), | |
926 | I40E_GLPRT_PRC1522L(hw->port), | |
927 | pf->stat_offsets_loaded, | |
928 | &osd->rx_size_1522, &nsd->rx_size_1522); | |
929 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), | |
930 | I40E_GLPRT_PRC9522L(hw->port), | |
931 | pf->stat_offsets_loaded, | |
932 | &osd->rx_size_big, &nsd->rx_size_big); | |
933 | ||
934 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), | |
935 | I40E_GLPRT_PTC64L(hw->port), | |
936 | pf->stat_offsets_loaded, | |
937 | &osd->tx_size_64, &nsd->tx_size_64); | |
938 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), | |
939 | I40E_GLPRT_PTC127L(hw->port), | |
940 | pf->stat_offsets_loaded, | |
941 | &osd->tx_size_127, &nsd->tx_size_127); | |
942 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), | |
943 | I40E_GLPRT_PTC255L(hw->port), | |
944 | pf->stat_offsets_loaded, | |
945 | &osd->tx_size_255, &nsd->tx_size_255); | |
946 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), | |
947 | I40E_GLPRT_PTC511L(hw->port), | |
948 | pf->stat_offsets_loaded, | |
949 | &osd->tx_size_511, &nsd->tx_size_511); | |
950 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), | |
951 | I40E_GLPRT_PTC1023L(hw->port), | |
952 | pf->stat_offsets_loaded, | |
953 | &osd->tx_size_1023, &nsd->tx_size_1023); | |
954 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), | |
955 | I40E_GLPRT_PTC1522L(hw->port), | |
956 | pf->stat_offsets_loaded, | |
957 | &osd->tx_size_1522, &nsd->tx_size_1522); | |
958 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), | |
959 | I40E_GLPRT_PTC9522L(hw->port), | |
960 | pf->stat_offsets_loaded, | |
961 | &osd->tx_size_big, &nsd->tx_size_big); | |
962 | ||
963 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), | |
964 | pf->stat_offsets_loaded, | |
965 | &osd->rx_undersize, &nsd->rx_undersize); | |
966 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), | |
967 | pf->stat_offsets_loaded, | |
968 | &osd->rx_fragments, &nsd->rx_fragments); | |
969 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), | |
970 | pf->stat_offsets_loaded, | |
971 | &osd->rx_oversize, &nsd->rx_oversize); | |
972 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), | |
973 | pf->stat_offsets_loaded, | |
974 | &osd->rx_jabber, &nsd->rx_jabber); | |
975 | } | |
976 | ||
977 | pf->stat_offsets_loaded = true; | |
978 | } | |
979 | ||
980 | /** | |
981 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter | |
982 | * @vsi: the VSI to be searched | |
983 | * @macaddr: the MAC address | |
984 | * @vlan: the vlan | |
985 | * @is_vf: make sure its a vf filter, else doesn't matter | |
986 | * @is_netdev: make sure its a netdev filter, else doesn't matter | |
987 | * | |
988 | * Returns ptr to the filter object or NULL | |
989 | **/ | |
990 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, | |
991 | u8 *macaddr, s16 vlan, | |
992 | bool is_vf, bool is_netdev) | |
993 | { | |
994 | struct i40e_mac_filter *f; | |
995 | ||
996 | if (!vsi || !macaddr) | |
997 | return NULL; | |
998 | ||
999 | list_for_each_entry(f, &vsi->mac_filter_list, list) { | |
1000 | if ((ether_addr_equal(macaddr, f->macaddr)) && | |
1001 | (vlan == f->vlan) && | |
1002 | (!is_vf || f->is_vf) && | |
1003 | (!is_netdev || f->is_netdev)) | |
1004 | return f; | |
1005 | } | |
1006 | return NULL; | |
1007 | } | |
1008 | ||
1009 | /** | |
1010 | * i40e_find_mac - Find a mac addr in the macvlan filters list | |
1011 | * @vsi: the VSI to be searched | |
1012 | * @macaddr: the MAC address we are searching for | |
1013 | * @is_vf: make sure its a vf filter, else doesn't matter | |
1014 | * @is_netdev: make sure its a netdev filter, else doesn't matter | |
1015 | * | |
1016 | * Returns the first filter with the provided MAC address or NULL if | |
1017 | * MAC address was not found | |
1018 | **/ | |
1019 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr, | |
1020 | bool is_vf, bool is_netdev) | |
1021 | { | |
1022 | struct i40e_mac_filter *f; | |
1023 | ||
1024 | if (!vsi || !macaddr) | |
1025 | return NULL; | |
1026 | ||
1027 | list_for_each_entry(f, &vsi->mac_filter_list, list) { | |
1028 | if ((ether_addr_equal(macaddr, f->macaddr)) && | |
1029 | (!is_vf || f->is_vf) && | |
1030 | (!is_netdev || f->is_netdev)) | |
1031 | return f; | |
1032 | } | |
1033 | return NULL; | |
1034 | } | |
1035 | ||
1036 | /** | |
1037 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode | |
1038 | * @vsi: the VSI to be searched | |
1039 | * | |
1040 | * Returns true if VSI is in vlan mode or false otherwise | |
1041 | **/ | |
1042 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) | |
1043 | { | |
1044 | struct i40e_mac_filter *f; | |
1045 | ||
1046 | /* Only -1 for all the filters denotes not in vlan mode | |
1047 | * so we have to go through all the list in order to make sure | |
1048 | */ | |
1049 | list_for_each_entry(f, &vsi->mac_filter_list, list) { | |
1050 | if (f->vlan >= 0) | |
1051 | return true; | |
1052 | } | |
1053 | ||
1054 | return false; | |
1055 | } | |
1056 | ||
1057 | /** | |
1058 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans | |
1059 | * @vsi: the VSI to be searched | |
1060 | * @macaddr: the mac address to be filtered | |
1061 | * @is_vf: true if it is a vf | |
1062 | * @is_netdev: true if it is a netdev | |
1063 | * | |
1064 | * Goes through all the macvlan filters and adds a | |
1065 | * macvlan filter for each unique vlan that already exists | |
1066 | * | |
1067 | * Returns first filter found on success, else NULL | |
1068 | **/ | |
1069 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr, | |
1070 | bool is_vf, bool is_netdev) | |
1071 | { | |
1072 | struct i40e_mac_filter *f; | |
1073 | ||
1074 | list_for_each_entry(f, &vsi->mac_filter_list, list) { | |
1075 | if (!i40e_find_filter(vsi, macaddr, f->vlan, | |
1076 | is_vf, is_netdev)) { | |
1077 | if (!i40e_add_filter(vsi, macaddr, f->vlan, | |
8fb905b3 | 1078 | is_vf, is_netdev)) |
41c445ff JB |
1079 | return NULL; |
1080 | } | |
1081 | } | |
1082 | ||
1083 | return list_first_entry_or_null(&vsi->mac_filter_list, | |
1084 | struct i40e_mac_filter, list); | |
1085 | } | |
1086 | ||
1087 | /** | |
1088 | * i40e_add_filter - Add a mac/vlan filter to the VSI | |
1089 | * @vsi: the VSI to be searched | |
1090 | * @macaddr: the MAC address | |
1091 | * @vlan: the vlan | |
1092 | * @is_vf: make sure its a vf filter, else doesn't matter | |
1093 | * @is_netdev: make sure its a netdev filter, else doesn't matter | |
1094 | * | |
1095 | * Returns ptr to the filter object or NULL when no memory available. | |
1096 | **/ | |
1097 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, | |
1098 | u8 *macaddr, s16 vlan, | |
1099 | bool is_vf, bool is_netdev) | |
1100 | { | |
1101 | struct i40e_mac_filter *f; | |
1102 | ||
1103 | if (!vsi || !macaddr) | |
1104 | return NULL; | |
1105 | ||
1106 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); | |
1107 | if (!f) { | |
1108 | f = kzalloc(sizeof(*f), GFP_ATOMIC); | |
1109 | if (!f) | |
1110 | goto add_filter_out; | |
1111 | ||
1112 | memcpy(f->macaddr, macaddr, ETH_ALEN); | |
1113 | f->vlan = vlan; | |
1114 | f->changed = true; | |
1115 | ||
1116 | INIT_LIST_HEAD(&f->list); | |
1117 | list_add(&f->list, &vsi->mac_filter_list); | |
1118 | } | |
1119 | ||
1120 | /* increment counter and add a new flag if needed */ | |
1121 | if (is_vf) { | |
1122 | if (!f->is_vf) { | |
1123 | f->is_vf = true; | |
1124 | f->counter++; | |
1125 | } | |
1126 | } else if (is_netdev) { | |
1127 | if (!f->is_netdev) { | |
1128 | f->is_netdev = true; | |
1129 | f->counter++; | |
1130 | } | |
1131 | } else { | |
1132 | f->counter++; | |
1133 | } | |
1134 | ||
1135 | /* changed tells sync_filters_subtask to | |
1136 | * push the filter down to the firmware | |
1137 | */ | |
1138 | if (f->changed) { | |
1139 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; | |
1140 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; | |
1141 | } | |
1142 | ||
1143 | add_filter_out: | |
1144 | return f; | |
1145 | } | |
1146 | ||
1147 | /** | |
1148 | * i40e_del_filter - Remove a mac/vlan filter from the VSI | |
1149 | * @vsi: the VSI to be searched | |
1150 | * @macaddr: the MAC address | |
1151 | * @vlan: the vlan | |
1152 | * @is_vf: make sure it's a vf filter, else doesn't matter | |
1153 | * @is_netdev: make sure it's a netdev filter, else doesn't matter | |
1154 | **/ | |
1155 | void i40e_del_filter(struct i40e_vsi *vsi, | |
1156 | u8 *macaddr, s16 vlan, | |
1157 | bool is_vf, bool is_netdev) | |
1158 | { | |
1159 | struct i40e_mac_filter *f; | |
1160 | ||
1161 | if (!vsi || !macaddr) | |
1162 | return; | |
1163 | ||
1164 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); | |
1165 | if (!f || f->counter == 0) | |
1166 | return; | |
1167 | ||
1168 | if (is_vf) { | |
1169 | if (f->is_vf) { | |
1170 | f->is_vf = false; | |
1171 | f->counter--; | |
1172 | } | |
1173 | } else if (is_netdev) { | |
1174 | if (f->is_netdev) { | |
1175 | f->is_netdev = false; | |
1176 | f->counter--; | |
1177 | } | |
1178 | } else { | |
1179 | /* make sure we don't remove a filter in use by vf or netdev */ | |
1180 | int min_f = 0; | |
1181 | min_f += (f->is_vf ? 1 : 0); | |
1182 | min_f += (f->is_netdev ? 1 : 0); | |
1183 | ||
1184 | if (f->counter > min_f) | |
1185 | f->counter--; | |
1186 | } | |
1187 | ||
1188 | /* counter == 0 tells sync_filters_subtask to | |
1189 | * remove the filter from the firmware's list | |
1190 | */ | |
1191 | if (f->counter == 0) { | |
1192 | f->changed = true; | |
1193 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; | |
1194 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; | |
1195 | } | |
1196 | } | |
1197 | ||
1198 | /** | |
1199 | * i40e_set_mac - NDO callback to set mac address | |
1200 | * @netdev: network interface device structure | |
1201 | * @p: pointer to an address structure | |
1202 | * | |
1203 | * Returns 0 on success, negative on failure | |
1204 | **/ | |
1205 | static int i40e_set_mac(struct net_device *netdev, void *p) | |
1206 | { | |
1207 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1208 | struct i40e_vsi *vsi = np->vsi; | |
1209 | struct sockaddr *addr = p; | |
1210 | struct i40e_mac_filter *f; | |
1211 | ||
1212 | if (!is_valid_ether_addr(addr->sa_data)) | |
1213 | return -EADDRNOTAVAIL; | |
1214 | ||
1215 | netdev_info(netdev, "set mac address=%pM\n", addr->sa_data); | |
1216 | ||
1217 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) | |
1218 | return 0; | |
1219 | ||
80f6428f ASJ |
1220 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
1221 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) | |
1222 | return -EADDRNOTAVAIL; | |
1223 | ||
41c445ff JB |
1224 | if (vsi->type == I40E_VSI_MAIN) { |
1225 | i40e_status ret; | |
1226 | ret = i40e_aq_mac_address_write(&vsi->back->hw, | |
1227 | I40E_AQC_WRITE_TYPE_LAA_ONLY, | |
1228 | addr->sa_data, NULL); | |
1229 | if (ret) { | |
1230 | netdev_info(netdev, | |
1231 | "Addr change for Main VSI failed: %d\n", | |
1232 | ret); | |
1233 | return -EADDRNOTAVAIL; | |
1234 | } | |
1235 | ||
1236 | memcpy(vsi->back->hw.mac.addr, addr->sa_data, netdev->addr_len); | |
1237 | } | |
1238 | ||
1239 | /* In order to be sure to not drop any packets, add the new address | |
1240 | * then delete the old one. | |
1241 | */ | |
1242 | f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, false, false); | |
1243 | if (!f) | |
1244 | return -ENOMEM; | |
1245 | ||
1246 | i40e_sync_vsi_filters(vsi); | |
1247 | i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, false, false); | |
1248 | i40e_sync_vsi_filters(vsi); | |
1249 | ||
1250 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); | |
1251 | ||
1252 | return 0; | |
1253 | } | |
1254 | ||
1255 | /** | |
1256 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc | |
1257 | * @vsi: the VSI being setup | |
1258 | * @ctxt: VSI context structure | |
1259 | * @enabled_tc: Enabled TCs bitmap | |
1260 | * @is_add: True if called before Add VSI | |
1261 | * | |
1262 | * Setup VSI queue mapping for enabled traffic classes. | |
1263 | **/ | |
1264 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, | |
1265 | struct i40e_vsi_context *ctxt, | |
1266 | u8 enabled_tc, | |
1267 | bool is_add) | |
1268 | { | |
1269 | struct i40e_pf *pf = vsi->back; | |
1270 | u16 sections = 0; | |
1271 | u8 netdev_tc = 0; | |
1272 | u16 numtc = 0; | |
1273 | u16 qcount; | |
1274 | u8 offset; | |
1275 | u16 qmap; | |
1276 | int i; | |
4e3b35b0 | 1277 | u16 num_tc_qps = 0; |
41c445ff JB |
1278 | |
1279 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; | |
1280 | offset = 0; | |
1281 | ||
1282 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { | |
1283 | /* Find numtc from enabled TC bitmap */ | |
1284 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
1285 | if (enabled_tc & (1 << i)) /* TC is enabled */ | |
1286 | numtc++; | |
1287 | } | |
1288 | if (!numtc) { | |
1289 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); | |
1290 | numtc = 1; | |
1291 | } | |
1292 | } else { | |
1293 | /* At least TC0 is enabled in case of non-DCB case */ | |
1294 | numtc = 1; | |
1295 | } | |
1296 | ||
1297 | vsi->tc_config.numtc = numtc; | |
1298 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; | |
4e3b35b0 NP |
1299 | /* Number of queues per enabled TC */ |
1300 | num_tc_qps = rounddown_pow_of_two(vsi->alloc_queue_pairs/numtc); | |
1301 | num_tc_qps = min_t(int, num_tc_qps, I40E_MAX_QUEUES_PER_TC); | |
41c445ff JB |
1302 | |
1303 | /* Setup queue offset/count for all TCs for given VSI */ | |
1304 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
1305 | /* See if the given TC is enabled for the given VSI */ | |
1306 | if (vsi->tc_config.enabled_tc & (1 << i)) { /* TC is enabled */ | |
1307 | int pow, num_qps; | |
1308 | ||
41c445ff JB |
1309 | switch (vsi->type) { |
1310 | case I40E_VSI_MAIN: | |
4e3b35b0 | 1311 | qcount = min_t(int, pf->rss_size, num_tc_qps); |
41c445ff JB |
1312 | break; |
1313 | case I40E_VSI_FDIR: | |
1314 | case I40E_VSI_SRIOV: | |
1315 | case I40E_VSI_VMDQ2: | |
1316 | default: | |
4e3b35b0 | 1317 | qcount = num_tc_qps; |
41c445ff JB |
1318 | WARN_ON(i != 0); |
1319 | break; | |
1320 | } | |
4e3b35b0 NP |
1321 | vsi->tc_config.tc_info[i].qoffset = offset; |
1322 | vsi->tc_config.tc_info[i].qcount = qcount; | |
41c445ff JB |
1323 | |
1324 | /* find the power-of-2 of the number of queue pairs */ | |
4e3b35b0 | 1325 | num_qps = qcount; |
41c445ff | 1326 | pow = 0; |
4e3b35b0 | 1327 | while (num_qps && ((1 << pow) < qcount)) { |
41c445ff JB |
1328 | pow++; |
1329 | num_qps >>= 1; | |
1330 | } | |
1331 | ||
1332 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; | |
1333 | qmap = | |
1334 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | | |
1335 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); | |
1336 | ||
4e3b35b0 | 1337 | offset += qcount; |
41c445ff JB |
1338 | } else { |
1339 | /* TC is not enabled so set the offset to | |
1340 | * default queue and allocate one queue | |
1341 | * for the given TC. | |
1342 | */ | |
1343 | vsi->tc_config.tc_info[i].qoffset = 0; | |
1344 | vsi->tc_config.tc_info[i].qcount = 1; | |
1345 | vsi->tc_config.tc_info[i].netdev_tc = 0; | |
1346 | ||
1347 | qmap = 0; | |
1348 | } | |
1349 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); | |
1350 | } | |
1351 | ||
1352 | /* Set actual Tx/Rx queue pairs */ | |
1353 | vsi->num_queue_pairs = offset; | |
1354 | ||
1355 | /* Scheduler section valid can only be set for ADD VSI */ | |
1356 | if (is_add) { | |
1357 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; | |
1358 | ||
1359 | ctxt->info.up_enable_bits = enabled_tc; | |
1360 | } | |
1361 | if (vsi->type == I40E_VSI_SRIOV) { | |
1362 | ctxt->info.mapping_flags |= | |
1363 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); | |
1364 | for (i = 0; i < vsi->num_queue_pairs; i++) | |
1365 | ctxt->info.queue_mapping[i] = | |
1366 | cpu_to_le16(vsi->base_queue + i); | |
1367 | } else { | |
1368 | ctxt->info.mapping_flags |= | |
1369 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); | |
1370 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); | |
1371 | } | |
1372 | ctxt->info.valid_sections |= cpu_to_le16(sections); | |
1373 | } | |
1374 | ||
1375 | /** | |
1376 | * i40e_set_rx_mode - NDO callback to set the netdev filters | |
1377 | * @netdev: network interface device structure | |
1378 | **/ | |
1379 | static void i40e_set_rx_mode(struct net_device *netdev) | |
1380 | { | |
1381 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1382 | struct i40e_mac_filter *f, *ftmp; | |
1383 | struct i40e_vsi *vsi = np->vsi; | |
1384 | struct netdev_hw_addr *uca; | |
1385 | struct netdev_hw_addr *mca; | |
1386 | struct netdev_hw_addr *ha; | |
1387 | ||
1388 | /* add addr if not already in the filter list */ | |
1389 | netdev_for_each_uc_addr(uca, netdev) { | |
1390 | if (!i40e_find_mac(vsi, uca->addr, false, true)) { | |
1391 | if (i40e_is_vsi_in_vlan(vsi)) | |
1392 | i40e_put_mac_in_vlan(vsi, uca->addr, | |
1393 | false, true); | |
1394 | else | |
1395 | i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY, | |
1396 | false, true); | |
1397 | } | |
1398 | } | |
1399 | ||
1400 | netdev_for_each_mc_addr(mca, netdev) { | |
1401 | if (!i40e_find_mac(vsi, mca->addr, false, true)) { | |
1402 | if (i40e_is_vsi_in_vlan(vsi)) | |
1403 | i40e_put_mac_in_vlan(vsi, mca->addr, | |
1404 | false, true); | |
1405 | else | |
1406 | i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY, | |
1407 | false, true); | |
1408 | } | |
1409 | } | |
1410 | ||
1411 | /* remove filter if not in netdev list */ | |
1412 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { | |
1413 | bool found = false; | |
1414 | ||
1415 | if (!f->is_netdev) | |
1416 | continue; | |
1417 | ||
1418 | if (is_multicast_ether_addr(f->macaddr)) { | |
1419 | netdev_for_each_mc_addr(mca, netdev) { | |
1420 | if (ether_addr_equal(mca->addr, f->macaddr)) { | |
1421 | found = true; | |
1422 | break; | |
1423 | } | |
1424 | } | |
1425 | } else { | |
1426 | netdev_for_each_uc_addr(uca, netdev) { | |
1427 | if (ether_addr_equal(uca->addr, f->macaddr)) { | |
1428 | found = true; | |
1429 | break; | |
1430 | } | |
1431 | } | |
1432 | ||
1433 | for_each_dev_addr(netdev, ha) { | |
1434 | if (ether_addr_equal(ha->addr, f->macaddr)) { | |
1435 | found = true; | |
1436 | break; | |
1437 | } | |
1438 | } | |
1439 | } | |
1440 | if (!found) | |
1441 | i40e_del_filter( | |
1442 | vsi, f->macaddr, I40E_VLAN_ANY, false, true); | |
1443 | } | |
1444 | ||
1445 | /* check for other flag changes */ | |
1446 | if (vsi->current_netdev_flags != vsi->netdev->flags) { | |
1447 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; | |
1448 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; | |
1449 | } | |
1450 | } | |
1451 | ||
1452 | /** | |
1453 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW | |
1454 | * @vsi: ptr to the VSI | |
1455 | * | |
1456 | * Push any outstanding VSI filter changes through the AdminQ. | |
1457 | * | |
1458 | * Returns 0 or error value | |
1459 | **/ | |
1460 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) | |
1461 | { | |
1462 | struct i40e_mac_filter *f, *ftmp; | |
1463 | bool promisc_forced_on = false; | |
1464 | bool add_happened = false; | |
1465 | int filter_list_len = 0; | |
1466 | u32 changed_flags = 0; | |
dcae29be | 1467 | i40e_status aq_ret = 0; |
41c445ff JB |
1468 | struct i40e_pf *pf; |
1469 | int num_add = 0; | |
1470 | int num_del = 0; | |
1471 | u16 cmd_flags; | |
1472 | ||
1473 | /* empty array typed pointers, kcalloc later */ | |
1474 | struct i40e_aqc_add_macvlan_element_data *add_list; | |
1475 | struct i40e_aqc_remove_macvlan_element_data *del_list; | |
1476 | ||
1477 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) | |
1478 | usleep_range(1000, 2000); | |
1479 | pf = vsi->back; | |
1480 | ||
1481 | if (vsi->netdev) { | |
1482 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; | |
1483 | vsi->current_netdev_flags = vsi->netdev->flags; | |
1484 | } | |
1485 | ||
1486 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { | |
1487 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; | |
1488 | ||
1489 | filter_list_len = pf->hw.aq.asq_buf_size / | |
1490 | sizeof(struct i40e_aqc_remove_macvlan_element_data); | |
1491 | del_list = kcalloc(filter_list_len, | |
1492 | sizeof(struct i40e_aqc_remove_macvlan_element_data), | |
1493 | GFP_KERNEL); | |
1494 | if (!del_list) | |
1495 | return -ENOMEM; | |
1496 | ||
1497 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { | |
1498 | if (!f->changed) | |
1499 | continue; | |
1500 | ||
1501 | if (f->counter != 0) | |
1502 | continue; | |
1503 | f->changed = false; | |
1504 | cmd_flags = 0; | |
1505 | ||
1506 | /* add to delete list */ | |
1507 | memcpy(del_list[num_del].mac_addr, | |
1508 | f->macaddr, ETH_ALEN); | |
1509 | del_list[num_del].vlan_tag = | |
1510 | cpu_to_le16((u16)(f->vlan == | |
1511 | I40E_VLAN_ANY ? 0 : f->vlan)); | |
1512 | ||
41c445ff JB |
1513 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
1514 | del_list[num_del].flags = cmd_flags; | |
1515 | num_del++; | |
1516 | ||
1517 | /* unlink from filter list */ | |
1518 | list_del(&f->list); | |
1519 | kfree(f); | |
1520 | ||
1521 | /* flush a full buffer */ | |
1522 | if (num_del == filter_list_len) { | |
dcae29be | 1523 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, |
41c445ff JB |
1524 | vsi->seid, del_list, num_del, |
1525 | NULL); | |
1526 | num_del = 0; | |
1527 | memset(del_list, 0, sizeof(*del_list)); | |
1528 | ||
dcae29be | 1529 | if (aq_ret) |
41c445ff JB |
1530 | dev_info(&pf->pdev->dev, |
1531 | "ignoring delete macvlan error, err %d, aq_err %d while flushing a full buffer\n", | |
dcae29be | 1532 | aq_ret, |
41c445ff JB |
1533 | pf->hw.aq.asq_last_status); |
1534 | } | |
1535 | } | |
1536 | if (num_del) { | |
dcae29be | 1537 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, |
41c445ff JB |
1538 | del_list, num_del, NULL); |
1539 | num_del = 0; | |
1540 | ||
dcae29be | 1541 | if (aq_ret) |
41c445ff JB |
1542 | dev_info(&pf->pdev->dev, |
1543 | "ignoring delete macvlan error, err %d, aq_err %d\n", | |
dcae29be | 1544 | aq_ret, pf->hw.aq.asq_last_status); |
41c445ff JB |
1545 | } |
1546 | ||
1547 | kfree(del_list); | |
1548 | del_list = NULL; | |
1549 | ||
1550 | /* do all the adds now */ | |
1551 | filter_list_len = pf->hw.aq.asq_buf_size / | |
1552 | sizeof(struct i40e_aqc_add_macvlan_element_data), | |
1553 | add_list = kcalloc(filter_list_len, | |
1554 | sizeof(struct i40e_aqc_add_macvlan_element_data), | |
1555 | GFP_KERNEL); | |
1556 | if (!add_list) | |
1557 | return -ENOMEM; | |
1558 | ||
1559 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { | |
1560 | if (!f->changed) | |
1561 | continue; | |
1562 | ||
1563 | if (f->counter == 0) | |
1564 | continue; | |
1565 | f->changed = false; | |
1566 | add_happened = true; | |
1567 | cmd_flags = 0; | |
1568 | ||
1569 | /* add to add array */ | |
1570 | memcpy(add_list[num_add].mac_addr, | |
1571 | f->macaddr, ETH_ALEN); | |
1572 | add_list[num_add].vlan_tag = | |
1573 | cpu_to_le16( | |
1574 | (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan)); | |
1575 | add_list[num_add].queue_number = 0; | |
1576 | ||
1577 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; | |
41c445ff JB |
1578 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
1579 | num_add++; | |
1580 | ||
1581 | /* flush a full buffer */ | |
1582 | if (num_add == filter_list_len) { | |
dcae29be JB |
1583 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
1584 | add_list, num_add, | |
1585 | NULL); | |
41c445ff JB |
1586 | num_add = 0; |
1587 | ||
dcae29be | 1588 | if (aq_ret) |
41c445ff JB |
1589 | break; |
1590 | memset(add_list, 0, sizeof(*add_list)); | |
1591 | } | |
1592 | } | |
1593 | if (num_add) { | |
dcae29be JB |
1594 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
1595 | add_list, num_add, NULL); | |
41c445ff JB |
1596 | num_add = 0; |
1597 | } | |
1598 | kfree(add_list); | |
1599 | add_list = NULL; | |
1600 | ||
dcae29be | 1601 | if (add_happened && (!aq_ret)) { |
41c445ff | 1602 | /* do nothing */; |
dcae29be | 1603 | } else if (add_happened && (aq_ret)) { |
41c445ff JB |
1604 | dev_info(&pf->pdev->dev, |
1605 | "add filter failed, err %d, aq_err %d\n", | |
dcae29be | 1606 | aq_ret, pf->hw.aq.asq_last_status); |
41c445ff JB |
1607 | if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) && |
1608 | !test_bit(__I40E_FILTER_OVERFLOW_PROMISC, | |
1609 | &vsi->state)) { | |
1610 | promisc_forced_on = true; | |
1611 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, | |
1612 | &vsi->state); | |
1613 | dev_info(&pf->pdev->dev, "promiscuous mode forced on\n"); | |
1614 | } | |
1615 | } | |
1616 | } | |
1617 | ||
1618 | /* check for changes in promiscuous modes */ | |
1619 | if (changed_flags & IFF_ALLMULTI) { | |
1620 | bool cur_multipromisc; | |
1621 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); | |
dcae29be JB |
1622 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
1623 | vsi->seid, | |
1624 | cur_multipromisc, | |
1625 | NULL); | |
1626 | if (aq_ret) | |
41c445ff JB |
1627 | dev_info(&pf->pdev->dev, |
1628 | "set multi promisc failed, err %d, aq_err %d\n", | |
dcae29be | 1629 | aq_ret, pf->hw.aq.asq_last_status); |
41c445ff JB |
1630 | } |
1631 | if ((changed_flags & IFF_PROMISC) || promisc_forced_on) { | |
1632 | bool cur_promisc; | |
1633 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || | |
1634 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, | |
1635 | &vsi->state)); | |
dcae29be JB |
1636 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous(&vsi->back->hw, |
1637 | vsi->seid, | |
1638 | cur_promisc, NULL); | |
1639 | if (aq_ret) | |
41c445ff JB |
1640 | dev_info(&pf->pdev->dev, |
1641 | "set uni promisc failed, err %d, aq_err %d\n", | |
dcae29be | 1642 | aq_ret, pf->hw.aq.asq_last_status); |
1a10370a GR |
1643 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
1644 | vsi->seid, | |
1645 | cur_promisc, NULL); | |
1646 | if (aq_ret) | |
1647 | dev_info(&pf->pdev->dev, | |
1648 | "set brdcast promisc failed, err %d, aq_err %d\n", | |
1649 | aq_ret, pf->hw.aq.asq_last_status); | |
41c445ff JB |
1650 | } |
1651 | ||
1652 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); | |
1653 | return 0; | |
1654 | } | |
1655 | ||
1656 | /** | |
1657 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW | |
1658 | * @pf: board private structure | |
1659 | **/ | |
1660 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) | |
1661 | { | |
1662 | int v; | |
1663 | ||
1664 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) | |
1665 | return; | |
1666 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; | |
1667 | ||
1668 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | |
1669 | if (pf->vsi[v] && | |
1670 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) | |
1671 | i40e_sync_vsi_filters(pf->vsi[v]); | |
1672 | } | |
1673 | } | |
1674 | ||
1675 | /** | |
1676 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit | |
1677 | * @netdev: network interface device structure | |
1678 | * @new_mtu: new value for maximum frame size | |
1679 | * | |
1680 | * Returns 0 on success, negative on failure | |
1681 | **/ | |
1682 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) | |
1683 | { | |
1684 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1685 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; | |
1686 | struct i40e_vsi *vsi = np->vsi; | |
1687 | ||
1688 | /* MTU < 68 is an error and causes problems on some kernels */ | |
1689 | if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER)) | |
1690 | return -EINVAL; | |
1691 | ||
1692 | netdev_info(netdev, "changing MTU from %d to %d\n", | |
1693 | netdev->mtu, new_mtu); | |
1694 | netdev->mtu = new_mtu; | |
1695 | if (netif_running(netdev)) | |
1696 | i40e_vsi_reinit_locked(vsi); | |
1697 | ||
1698 | return 0; | |
1699 | } | |
1700 | ||
beb0dff1 JK |
1701 | /** |
1702 | * i40e_ioctl - Access the hwtstamp interface | |
1703 | * @netdev: network interface device structure | |
1704 | * @ifr: interface request data | |
1705 | * @cmd: ioctl command | |
1706 | **/ | |
1707 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) | |
1708 | { | |
1709 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1710 | struct i40e_pf *pf = np->vsi->back; | |
1711 | ||
1712 | switch (cmd) { | |
1713 | case SIOCGHWTSTAMP: | |
1714 | return i40e_ptp_get_ts_config(pf, ifr); | |
1715 | case SIOCSHWTSTAMP: | |
1716 | return i40e_ptp_set_ts_config(pf, ifr); | |
1717 | default: | |
1718 | return -EOPNOTSUPP; | |
1719 | } | |
1720 | } | |
1721 | ||
41c445ff JB |
1722 | /** |
1723 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI | |
1724 | * @vsi: the vsi being adjusted | |
1725 | **/ | |
1726 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) | |
1727 | { | |
1728 | struct i40e_vsi_context ctxt; | |
1729 | i40e_status ret; | |
1730 | ||
1731 | if ((vsi->info.valid_sections & | |
1732 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && | |
1733 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) | |
1734 | return; /* already enabled */ | |
1735 | ||
1736 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); | |
1737 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | | |
1738 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; | |
1739 | ||
1740 | ctxt.seid = vsi->seid; | |
1741 | memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); | |
1742 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); | |
1743 | if (ret) { | |
1744 | dev_info(&vsi->back->pdev->dev, | |
1745 | "%s: update vsi failed, aq_err=%d\n", | |
1746 | __func__, vsi->back->hw.aq.asq_last_status); | |
1747 | } | |
1748 | } | |
1749 | ||
1750 | /** | |
1751 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI | |
1752 | * @vsi: the vsi being adjusted | |
1753 | **/ | |
1754 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) | |
1755 | { | |
1756 | struct i40e_vsi_context ctxt; | |
1757 | i40e_status ret; | |
1758 | ||
1759 | if ((vsi->info.valid_sections & | |
1760 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && | |
1761 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == | |
1762 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) | |
1763 | return; /* already disabled */ | |
1764 | ||
1765 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); | |
1766 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | | |
1767 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; | |
1768 | ||
1769 | ctxt.seid = vsi->seid; | |
1770 | memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); | |
1771 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); | |
1772 | if (ret) { | |
1773 | dev_info(&vsi->back->pdev->dev, | |
1774 | "%s: update vsi failed, aq_err=%d\n", | |
1775 | __func__, vsi->back->hw.aq.asq_last_status); | |
1776 | } | |
1777 | } | |
1778 | ||
1779 | /** | |
1780 | * i40e_vlan_rx_register - Setup or shutdown vlan offload | |
1781 | * @netdev: network interface to be adjusted | |
1782 | * @features: netdev features to test if VLAN offload is enabled or not | |
1783 | **/ | |
1784 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) | |
1785 | { | |
1786 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1787 | struct i40e_vsi *vsi = np->vsi; | |
1788 | ||
1789 | if (features & NETIF_F_HW_VLAN_CTAG_RX) | |
1790 | i40e_vlan_stripping_enable(vsi); | |
1791 | else | |
1792 | i40e_vlan_stripping_disable(vsi); | |
1793 | } | |
1794 | ||
1795 | /** | |
1796 | * i40e_vsi_add_vlan - Add vsi membership for given vlan | |
1797 | * @vsi: the vsi being configured | |
1798 | * @vid: vlan id to be added (0 = untagged only , -1 = any) | |
1799 | **/ | |
1800 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) | |
1801 | { | |
1802 | struct i40e_mac_filter *f, *add_f; | |
1803 | bool is_netdev, is_vf; | |
41c445ff JB |
1804 | |
1805 | is_vf = (vsi->type == I40E_VSI_SRIOV); | |
1806 | is_netdev = !!(vsi->netdev); | |
1807 | ||
1808 | if (is_netdev) { | |
1809 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid, | |
1810 | is_vf, is_netdev); | |
1811 | if (!add_f) { | |
1812 | dev_info(&vsi->back->pdev->dev, | |
1813 | "Could not add vlan filter %d for %pM\n", | |
1814 | vid, vsi->netdev->dev_addr); | |
1815 | return -ENOMEM; | |
1816 | } | |
1817 | } | |
1818 | ||
1819 | list_for_each_entry(f, &vsi->mac_filter_list, list) { | |
1820 | add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev); | |
1821 | if (!add_f) { | |
1822 | dev_info(&vsi->back->pdev->dev, | |
1823 | "Could not add vlan filter %d for %pM\n", | |
1824 | vid, f->macaddr); | |
1825 | return -ENOMEM; | |
1826 | } | |
1827 | } | |
1828 | ||
41c445ff JB |
1829 | /* Now if we add a vlan tag, make sure to check if it is the first |
1830 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" | |
1831 | * with 0, so we now accept untagged and specified tagged traffic | |
1832 | * (and not any taged and untagged) | |
1833 | */ | |
1834 | if (vid > 0) { | |
1835 | if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr, | |
1836 | I40E_VLAN_ANY, | |
1837 | is_vf, is_netdev)) { | |
1838 | i40e_del_filter(vsi, vsi->netdev->dev_addr, | |
1839 | I40E_VLAN_ANY, is_vf, is_netdev); | |
1840 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0, | |
1841 | is_vf, is_netdev); | |
1842 | if (!add_f) { | |
1843 | dev_info(&vsi->back->pdev->dev, | |
1844 | "Could not add filter 0 for %pM\n", | |
1845 | vsi->netdev->dev_addr); | |
1846 | return -ENOMEM; | |
1847 | } | |
1848 | } | |
8d82a7c5 | 1849 | } |
41c445ff | 1850 | |
8d82a7c5 GR |
1851 | /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */ |
1852 | if (vid > 0 && !vsi->info.pvid) { | |
41c445ff JB |
1853 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
1854 | if (i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY, | |
1855 | is_vf, is_netdev)) { | |
1856 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, | |
1857 | is_vf, is_netdev); | |
1858 | add_f = i40e_add_filter(vsi, f->macaddr, | |
1859 | 0, is_vf, is_netdev); | |
1860 | if (!add_f) { | |
1861 | dev_info(&vsi->back->pdev->dev, | |
1862 | "Could not add filter 0 for %pM\n", | |
1863 | f->macaddr); | |
1864 | return -ENOMEM; | |
1865 | } | |
1866 | } | |
1867 | } | |
41c445ff JB |
1868 | } |
1869 | ||
80f6428f ASJ |
1870 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
1871 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) | |
1872 | return 0; | |
1873 | ||
1874 | return i40e_sync_vsi_filters(vsi); | |
41c445ff JB |
1875 | } |
1876 | ||
1877 | /** | |
1878 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan | |
1879 | * @vsi: the vsi being configured | |
1880 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) | |
078b5876 JB |
1881 | * |
1882 | * Return: 0 on success or negative otherwise | |
41c445ff JB |
1883 | **/ |
1884 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) | |
1885 | { | |
1886 | struct net_device *netdev = vsi->netdev; | |
1887 | struct i40e_mac_filter *f, *add_f; | |
1888 | bool is_vf, is_netdev; | |
1889 | int filter_count = 0; | |
41c445ff JB |
1890 | |
1891 | is_vf = (vsi->type == I40E_VSI_SRIOV); | |
1892 | is_netdev = !!(netdev); | |
1893 | ||
1894 | if (is_netdev) | |
1895 | i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev); | |
1896 | ||
1897 | list_for_each_entry(f, &vsi->mac_filter_list, list) | |
1898 | i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev); | |
1899 | ||
41c445ff JB |
1900 | /* go through all the filters for this VSI and if there is only |
1901 | * vid == 0 it means there are no other filters, so vid 0 must | |
1902 | * be replaced with -1. This signifies that we should from now | |
1903 | * on accept any traffic (with any tag present, or untagged) | |
1904 | */ | |
1905 | list_for_each_entry(f, &vsi->mac_filter_list, list) { | |
1906 | if (is_netdev) { | |
1907 | if (f->vlan && | |
1908 | ether_addr_equal(netdev->dev_addr, f->macaddr)) | |
1909 | filter_count++; | |
1910 | } | |
1911 | ||
1912 | if (f->vlan) | |
1913 | filter_count++; | |
1914 | } | |
1915 | ||
1916 | if (!filter_count && is_netdev) { | |
1917 | i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev); | |
1918 | f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, | |
1919 | is_vf, is_netdev); | |
1920 | if (!f) { | |
1921 | dev_info(&vsi->back->pdev->dev, | |
1922 | "Could not add filter %d for %pM\n", | |
1923 | I40E_VLAN_ANY, netdev->dev_addr); | |
1924 | return -ENOMEM; | |
1925 | } | |
1926 | } | |
1927 | ||
1928 | if (!filter_count) { | |
1929 | list_for_each_entry(f, &vsi->mac_filter_list, list) { | |
1930 | i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev); | |
1931 | add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY, | |
1932 | is_vf, is_netdev); | |
1933 | if (!add_f) { | |
1934 | dev_info(&vsi->back->pdev->dev, | |
1935 | "Could not add filter %d for %pM\n", | |
1936 | I40E_VLAN_ANY, f->macaddr); | |
1937 | return -ENOMEM; | |
1938 | } | |
1939 | } | |
1940 | } | |
1941 | ||
80f6428f ASJ |
1942 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
1943 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) | |
1944 | return 0; | |
1945 | ||
41c445ff JB |
1946 | return i40e_sync_vsi_filters(vsi); |
1947 | } | |
1948 | ||
1949 | /** | |
1950 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload | |
1951 | * @netdev: network interface to be adjusted | |
1952 | * @vid: vlan id to be added | |
078b5876 JB |
1953 | * |
1954 | * net_device_ops implementation for adding vlan ids | |
41c445ff JB |
1955 | **/ |
1956 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, | |
1957 | __always_unused __be16 proto, u16 vid) | |
1958 | { | |
1959 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1960 | struct i40e_vsi *vsi = np->vsi; | |
078b5876 | 1961 | int ret = 0; |
41c445ff JB |
1962 | |
1963 | if (vid > 4095) | |
078b5876 JB |
1964 | return -EINVAL; |
1965 | ||
1966 | netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid); | |
41c445ff | 1967 | |
6982d429 ASJ |
1968 | /* If the network stack called us with vid = 0 then |
1969 | * it is asking to receive priority tagged packets with | |
1970 | * vlan id 0. Our HW receives them by default when configured | |
1971 | * to receive untagged packets so there is no need to add an | |
1972 | * extra filter for vlan 0 tagged packets. | |
41c445ff | 1973 | */ |
6982d429 ASJ |
1974 | if (vid) |
1975 | ret = i40e_vsi_add_vlan(vsi, vid); | |
41c445ff | 1976 | |
078b5876 JB |
1977 | if (!ret && (vid < VLAN_N_VID)) |
1978 | set_bit(vid, vsi->active_vlans); | |
41c445ff | 1979 | |
078b5876 | 1980 | return ret; |
41c445ff JB |
1981 | } |
1982 | ||
1983 | /** | |
1984 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload | |
1985 | * @netdev: network interface to be adjusted | |
1986 | * @vid: vlan id to be removed | |
078b5876 | 1987 | * |
fdfd943e | 1988 | * net_device_ops implementation for removing vlan ids |
41c445ff JB |
1989 | **/ |
1990 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, | |
1991 | __always_unused __be16 proto, u16 vid) | |
1992 | { | |
1993 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1994 | struct i40e_vsi *vsi = np->vsi; | |
1995 | ||
078b5876 JB |
1996 | netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid); |
1997 | ||
41c445ff JB |
1998 | /* return code is ignored as there is nothing a user |
1999 | * can do about failure to remove and a log message was | |
078b5876 | 2000 | * already printed from the other function |
41c445ff JB |
2001 | */ |
2002 | i40e_vsi_kill_vlan(vsi, vid); | |
2003 | ||
2004 | clear_bit(vid, vsi->active_vlans); | |
078b5876 | 2005 | |
41c445ff JB |
2006 | return 0; |
2007 | } | |
2008 | ||
2009 | /** | |
2010 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up | |
2011 | * @vsi: the vsi being brought back up | |
2012 | **/ | |
2013 | static void i40e_restore_vlan(struct i40e_vsi *vsi) | |
2014 | { | |
2015 | u16 vid; | |
2016 | ||
2017 | if (!vsi->netdev) | |
2018 | return; | |
2019 | ||
2020 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); | |
2021 | ||
2022 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) | |
2023 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), | |
2024 | vid); | |
2025 | } | |
2026 | ||
2027 | /** | |
2028 | * i40e_vsi_add_pvid - Add pvid for the VSI | |
2029 | * @vsi: the vsi being adjusted | |
2030 | * @vid: the vlan id to set as a PVID | |
2031 | **/ | |
dcae29be | 2032 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
41c445ff JB |
2033 | { |
2034 | struct i40e_vsi_context ctxt; | |
dcae29be | 2035 | i40e_status aq_ret; |
41c445ff JB |
2036 | |
2037 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); | |
2038 | vsi->info.pvid = cpu_to_le16(vid); | |
6c12fcbf GR |
2039 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
2040 | I40E_AQ_VSI_PVLAN_INSERT_PVID | | |
b774c7dd | 2041 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
41c445ff JB |
2042 | |
2043 | ctxt.seid = vsi->seid; | |
2044 | memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); | |
dcae29be JB |
2045 | aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
2046 | if (aq_ret) { | |
41c445ff JB |
2047 | dev_info(&vsi->back->pdev->dev, |
2048 | "%s: update vsi failed, aq_err=%d\n", | |
2049 | __func__, vsi->back->hw.aq.asq_last_status); | |
dcae29be | 2050 | return -ENOENT; |
41c445ff JB |
2051 | } |
2052 | ||
dcae29be | 2053 | return 0; |
41c445ff JB |
2054 | } |
2055 | ||
2056 | /** | |
2057 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI | |
2058 | * @vsi: the vsi being adjusted | |
2059 | * | |
2060 | * Just use the vlan_rx_register() service to put it back to normal | |
2061 | **/ | |
2062 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) | |
2063 | { | |
6c12fcbf GR |
2064 | i40e_vlan_stripping_disable(vsi); |
2065 | ||
41c445ff | 2066 | vsi->info.pvid = 0; |
41c445ff JB |
2067 | } |
2068 | ||
2069 | /** | |
2070 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources | |
2071 | * @vsi: ptr to the VSI | |
2072 | * | |
2073 | * If this function returns with an error, then it's possible one or | |
2074 | * more of the rings is populated (while the rest are not). It is the | |
2075 | * callers duty to clean those orphaned rings. | |
2076 | * | |
2077 | * Return 0 on success, negative on failure | |
2078 | **/ | |
2079 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) | |
2080 | { | |
2081 | int i, err = 0; | |
2082 | ||
2083 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) | |
9f65e15b | 2084 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
41c445ff JB |
2085 | |
2086 | return err; | |
2087 | } | |
2088 | ||
2089 | /** | |
2090 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues | |
2091 | * @vsi: ptr to the VSI | |
2092 | * | |
2093 | * Free VSI's transmit software resources | |
2094 | **/ | |
2095 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) | |
2096 | { | |
2097 | int i; | |
2098 | ||
8e9dca53 GR |
2099 | if (!vsi->tx_rings) |
2100 | return; | |
2101 | ||
41c445ff | 2102 | for (i = 0; i < vsi->num_queue_pairs; i++) |
8e9dca53 | 2103 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
9f65e15b | 2104 | i40e_free_tx_resources(vsi->tx_rings[i]); |
41c445ff JB |
2105 | } |
2106 | ||
2107 | /** | |
2108 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources | |
2109 | * @vsi: ptr to the VSI | |
2110 | * | |
2111 | * If this function returns with an error, then it's possible one or | |
2112 | * more of the rings is populated (while the rest are not). It is the | |
2113 | * callers duty to clean those orphaned rings. | |
2114 | * | |
2115 | * Return 0 on success, negative on failure | |
2116 | **/ | |
2117 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) | |
2118 | { | |
2119 | int i, err = 0; | |
2120 | ||
2121 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) | |
9f65e15b | 2122 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
41c445ff JB |
2123 | return err; |
2124 | } | |
2125 | ||
2126 | /** | |
2127 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues | |
2128 | * @vsi: ptr to the VSI | |
2129 | * | |
2130 | * Free all receive software resources | |
2131 | **/ | |
2132 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) | |
2133 | { | |
2134 | int i; | |
2135 | ||
8e9dca53 GR |
2136 | if (!vsi->rx_rings) |
2137 | return; | |
2138 | ||
41c445ff | 2139 | for (i = 0; i < vsi->num_queue_pairs; i++) |
8e9dca53 | 2140 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
9f65e15b | 2141 | i40e_free_rx_resources(vsi->rx_rings[i]); |
41c445ff JB |
2142 | } |
2143 | ||
2144 | /** | |
2145 | * i40e_configure_tx_ring - Configure a transmit ring context and rest | |
2146 | * @ring: The Tx ring to configure | |
2147 | * | |
2148 | * Configure the Tx descriptor ring in the HMC context. | |
2149 | **/ | |
2150 | static int i40e_configure_tx_ring(struct i40e_ring *ring) | |
2151 | { | |
2152 | struct i40e_vsi *vsi = ring->vsi; | |
2153 | u16 pf_q = vsi->base_queue + ring->queue_index; | |
2154 | struct i40e_hw *hw = &vsi->back->hw; | |
2155 | struct i40e_hmc_obj_txq tx_ctx; | |
2156 | i40e_status err = 0; | |
2157 | u32 qtx_ctl = 0; | |
2158 | ||
2159 | /* some ATR related tx ring init */ | |
60ea5f83 | 2160 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
41c445ff JB |
2161 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
2162 | ring->atr_count = 0; | |
2163 | } else { | |
2164 | ring->atr_sample_rate = 0; | |
2165 | } | |
2166 | ||
2167 | /* initialize XPS */ | |
2168 | if (ring->q_vector && ring->netdev && | |
4e3b35b0 | 2169 | vsi->tc_config.numtc <= 1 && |
41c445ff JB |
2170 | !test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
2171 | netif_set_xps_queue(ring->netdev, | |
2172 | &ring->q_vector->affinity_mask, | |
2173 | ring->queue_index); | |
2174 | ||
2175 | /* clear the context structure first */ | |
2176 | memset(&tx_ctx, 0, sizeof(tx_ctx)); | |
2177 | ||
2178 | tx_ctx.new_context = 1; | |
2179 | tx_ctx.base = (ring->dma / 128); | |
2180 | tx_ctx.qlen = ring->count; | |
60ea5f83 JB |
2181 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
2182 | I40E_FLAG_FD_ATR_ENABLED)); | |
beb0dff1 | 2183 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
41c445ff JB |
2184 | |
2185 | /* As part of VSI creation/update, FW allocates certain | |
2186 | * Tx arbitration queue sets for each TC enabled for | |
2187 | * the VSI. The FW returns the handles to these queue | |
2188 | * sets as part of the response buffer to Add VSI, | |
2189 | * Update VSI, etc. AQ commands. It is expected that | |
2190 | * these queue set handles be associated with the Tx | |
2191 | * queues by the driver as part of the TX queue context | |
2192 | * initialization. This has to be done regardless of | |
2193 | * DCB as by default everything is mapped to TC0. | |
2194 | */ | |
2195 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); | |
2196 | tx_ctx.rdylist_act = 0; | |
2197 | ||
2198 | /* clear the context in the HMC */ | |
2199 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); | |
2200 | if (err) { | |
2201 | dev_info(&vsi->back->pdev->dev, | |
2202 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", | |
2203 | ring->queue_index, pf_q, err); | |
2204 | return -ENOMEM; | |
2205 | } | |
2206 | ||
2207 | /* set the context in the HMC */ | |
2208 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); | |
2209 | if (err) { | |
2210 | dev_info(&vsi->back->pdev->dev, | |
2211 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", | |
2212 | ring->queue_index, pf_q, err); | |
2213 | return -ENOMEM; | |
2214 | } | |
2215 | ||
2216 | /* Now associate this queue with this PCI function */ | |
9d8bf547 SN |
2217 | if (vsi->type == I40E_VSI_VMDQ2) |
2218 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; | |
2219 | else | |
2220 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; | |
13fd9774 SN |
2221 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
2222 | I40E_QTX_CTL_PF_INDX_MASK); | |
41c445ff JB |
2223 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
2224 | i40e_flush(hw); | |
2225 | ||
2226 | clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state); | |
2227 | ||
2228 | /* cache tail off for easier writes later */ | |
2229 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); | |
2230 | ||
2231 | return 0; | |
2232 | } | |
2233 | ||
2234 | /** | |
2235 | * i40e_configure_rx_ring - Configure a receive ring context | |
2236 | * @ring: The Rx ring to configure | |
2237 | * | |
2238 | * Configure the Rx descriptor ring in the HMC context. | |
2239 | **/ | |
2240 | static int i40e_configure_rx_ring(struct i40e_ring *ring) | |
2241 | { | |
2242 | struct i40e_vsi *vsi = ring->vsi; | |
2243 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; | |
2244 | u16 pf_q = vsi->base_queue + ring->queue_index; | |
2245 | struct i40e_hw *hw = &vsi->back->hw; | |
2246 | struct i40e_hmc_obj_rxq rx_ctx; | |
2247 | i40e_status err = 0; | |
2248 | ||
2249 | ring->state = 0; | |
2250 | ||
2251 | /* clear the context structure first */ | |
2252 | memset(&rx_ctx, 0, sizeof(rx_ctx)); | |
2253 | ||
2254 | ring->rx_buf_len = vsi->rx_buf_len; | |
2255 | ring->rx_hdr_len = vsi->rx_hdr_len; | |
2256 | ||
2257 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; | |
2258 | rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT; | |
2259 | ||
2260 | rx_ctx.base = (ring->dma / 128); | |
2261 | rx_ctx.qlen = ring->count; | |
2262 | ||
2263 | if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) { | |
2264 | set_ring_16byte_desc_enabled(ring); | |
2265 | rx_ctx.dsize = 0; | |
2266 | } else { | |
2267 | rx_ctx.dsize = 1; | |
2268 | } | |
2269 | ||
2270 | rx_ctx.dtype = vsi->dtype; | |
2271 | if (vsi->dtype) { | |
2272 | set_ring_ps_enabled(ring); | |
2273 | rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 | | |
2274 | I40E_RX_SPLIT_IP | | |
2275 | I40E_RX_SPLIT_TCP_UDP | | |
2276 | I40E_RX_SPLIT_SCTP; | |
2277 | } else { | |
2278 | rx_ctx.hsplit_0 = 0; | |
2279 | } | |
2280 | ||
2281 | rx_ctx.rxmax = min_t(u16, vsi->max_frame, | |
2282 | (chain_len * ring->rx_buf_len)); | |
2283 | rx_ctx.tphrdesc_ena = 1; | |
2284 | rx_ctx.tphwdesc_ena = 1; | |
2285 | rx_ctx.tphdata_ena = 1; | |
2286 | rx_ctx.tphhead_ena = 1; | |
7134f9ce JB |
2287 | if (hw->revision_id == 0) |
2288 | rx_ctx.lrxqthresh = 0; | |
2289 | else | |
2290 | rx_ctx.lrxqthresh = 2; | |
41c445ff JB |
2291 | rx_ctx.crcstrip = 1; |
2292 | rx_ctx.l2tsel = 1; | |
2293 | rx_ctx.showiv = 1; | |
2294 | ||
2295 | /* clear the context in the HMC */ | |
2296 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); | |
2297 | if (err) { | |
2298 | dev_info(&vsi->back->pdev->dev, | |
2299 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", | |
2300 | ring->queue_index, pf_q, err); | |
2301 | return -ENOMEM; | |
2302 | } | |
2303 | ||
2304 | /* set the context in the HMC */ | |
2305 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); | |
2306 | if (err) { | |
2307 | dev_info(&vsi->back->pdev->dev, | |
2308 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", | |
2309 | ring->queue_index, pf_q, err); | |
2310 | return -ENOMEM; | |
2311 | } | |
2312 | ||
2313 | /* cache tail for quicker writes, and clear the reg before use */ | |
2314 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); | |
2315 | writel(0, ring->tail); | |
2316 | ||
2317 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); | |
2318 | ||
2319 | return 0; | |
2320 | } | |
2321 | ||
2322 | /** | |
2323 | * i40e_vsi_configure_tx - Configure the VSI for Tx | |
2324 | * @vsi: VSI structure describing this set of rings and resources | |
2325 | * | |
2326 | * Configure the Tx VSI for operation. | |
2327 | **/ | |
2328 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) | |
2329 | { | |
2330 | int err = 0; | |
2331 | u16 i; | |
2332 | ||
9f65e15b AD |
2333 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
2334 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); | |
41c445ff JB |
2335 | |
2336 | return err; | |
2337 | } | |
2338 | ||
2339 | /** | |
2340 | * i40e_vsi_configure_rx - Configure the VSI for Rx | |
2341 | * @vsi: the VSI being configured | |
2342 | * | |
2343 | * Configure the Rx VSI for operation. | |
2344 | **/ | |
2345 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) | |
2346 | { | |
2347 | int err = 0; | |
2348 | u16 i; | |
2349 | ||
2350 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) | |
2351 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN | |
2352 | + ETH_FCS_LEN + VLAN_HLEN; | |
2353 | else | |
2354 | vsi->max_frame = I40E_RXBUFFER_2048; | |
2355 | ||
2356 | /* figure out correct receive buffer length */ | |
2357 | switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED | | |
2358 | I40E_FLAG_RX_PS_ENABLED)) { | |
2359 | case I40E_FLAG_RX_1BUF_ENABLED: | |
2360 | vsi->rx_hdr_len = 0; | |
2361 | vsi->rx_buf_len = vsi->max_frame; | |
2362 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; | |
2363 | break; | |
2364 | case I40E_FLAG_RX_PS_ENABLED: | |
2365 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; | |
2366 | vsi->rx_buf_len = I40E_RXBUFFER_2048; | |
2367 | vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT; | |
2368 | break; | |
2369 | default: | |
2370 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; | |
2371 | vsi->rx_buf_len = I40E_RXBUFFER_2048; | |
2372 | vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS; | |
2373 | break; | |
2374 | } | |
2375 | ||
2376 | /* round up for the chip's needs */ | |
2377 | vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len, | |
2378 | (1 << I40E_RXQ_CTX_HBUFF_SHIFT)); | |
2379 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, | |
2380 | (1 << I40E_RXQ_CTX_DBUFF_SHIFT)); | |
2381 | ||
2382 | /* set up individual rings */ | |
2383 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) | |
9f65e15b | 2384 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
41c445ff JB |
2385 | |
2386 | return err; | |
2387 | } | |
2388 | ||
2389 | /** | |
2390 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC | |
2391 | * @vsi: ptr to the VSI | |
2392 | **/ | |
2393 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) | |
2394 | { | |
2395 | u16 qoffset, qcount; | |
2396 | int i, n; | |
2397 | ||
2398 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) | |
2399 | return; | |
2400 | ||
2401 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { | |
2402 | if (!(vsi->tc_config.enabled_tc & (1 << n))) | |
2403 | continue; | |
2404 | ||
2405 | qoffset = vsi->tc_config.tc_info[n].qoffset; | |
2406 | qcount = vsi->tc_config.tc_info[n].qcount; | |
2407 | for (i = qoffset; i < (qoffset + qcount); i++) { | |
9f65e15b AD |
2408 | struct i40e_ring *rx_ring = vsi->rx_rings[i]; |
2409 | struct i40e_ring *tx_ring = vsi->tx_rings[i]; | |
41c445ff JB |
2410 | rx_ring->dcb_tc = n; |
2411 | tx_ring->dcb_tc = n; | |
2412 | } | |
2413 | } | |
2414 | } | |
2415 | ||
2416 | /** | |
2417 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI | |
2418 | * @vsi: ptr to the VSI | |
2419 | **/ | |
2420 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) | |
2421 | { | |
2422 | if (vsi->netdev) | |
2423 | i40e_set_rx_mode(vsi->netdev); | |
2424 | } | |
2425 | ||
17a73f6b JG |
2426 | /** |
2427 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters | |
2428 | * @vsi: Pointer to the targeted VSI | |
2429 | * | |
2430 | * This function replays the hlist on the hw where all the SB Flow Director | |
2431 | * filters were saved. | |
2432 | **/ | |
2433 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) | |
2434 | { | |
2435 | struct i40e_fdir_filter *filter; | |
2436 | struct i40e_pf *pf = vsi->back; | |
2437 | struct hlist_node *node; | |
2438 | ||
55a5e60b ASJ |
2439 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
2440 | return; | |
2441 | ||
17a73f6b JG |
2442 | hlist_for_each_entry_safe(filter, node, |
2443 | &pf->fdir_filter_list, fdir_node) { | |
2444 | i40e_add_del_fdir(vsi, filter, true); | |
2445 | } | |
2446 | } | |
2447 | ||
41c445ff JB |
2448 | /** |
2449 | * i40e_vsi_configure - Set up the VSI for action | |
2450 | * @vsi: the VSI being configured | |
2451 | **/ | |
2452 | static int i40e_vsi_configure(struct i40e_vsi *vsi) | |
2453 | { | |
2454 | int err; | |
2455 | ||
2456 | i40e_set_vsi_rx_mode(vsi); | |
2457 | i40e_restore_vlan(vsi); | |
2458 | i40e_vsi_config_dcb_rings(vsi); | |
2459 | err = i40e_vsi_configure_tx(vsi); | |
2460 | if (!err) | |
2461 | err = i40e_vsi_configure_rx(vsi); | |
2462 | ||
2463 | return err; | |
2464 | } | |
2465 | ||
2466 | /** | |
2467 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW | |
2468 | * @vsi: the VSI being configured | |
2469 | **/ | |
2470 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) | |
2471 | { | |
2472 | struct i40e_pf *pf = vsi->back; | |
2473 | struct i40e_q_vector *q_vector; | |
2474 | struct i40e_hw *hw = &pf->hw; | |
2475 | u16 vector; | |
2476 | int i, q; | |
2477 | u32 val; | |
2478 | u32 qp; | |
2479 | ||
2480 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn | |
2481 | * and PFINT_LNKLSTn registers, e.g.: | |
2482 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) | |
2483 | */ | |
2484 | qp = vsi->base_queue; | |
2485 | vector = vsi->base_vector; | |
493fb300 AD |
2486 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
2487 | q_vector = vsi->q_vectors[i]; | |
41c445ff JB |
2488 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
2489 | q_vector->rx.latency_range = I40E_LOW_LATENCY; | |
2490 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), | |
2491 | q_vector->rx.itr); | |
2492 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); | |
2493 | q_vector->tx.latency_range = I40E_LOW_LATENCY; | |
2494 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), | |
2495 | q_vector->tx.itr); | |
2496 | ||
2497 | /* Linked list for the queuepairs assigned to this vector */ | |
2498 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); | |
2499 | for (q = 0; q < q_vector->num_ringpairs; q++) { | |
2500 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | | |
2501 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | | |
2502 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | | |
2503 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| | |
2504 | (I40E_QUEUE_TYPE_TX | |
2505 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); | |
2506 | ||
2507 | wr32(hw, I40E_QINT_RQCTL(qp), val); | |
2508 | ||
2509 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | | |
2510 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | | |
2511 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | | |
2512 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| | |
2513 | (I40E_QUEUE_TYPE_RX | |
2514 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); | |
2515 | ||
2516 | /* Terminate the linked list */ | |
2517 | if (q == (q_vector->num_ringpairs - 1)) | |
2518 | val |= (I40E_QUEUE_END_OF_LIST | |
2519 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); | |
2520 | ||
2521 | wr32(hw, I40E_QINT_TQCTL(qp), val); | |
2522 | qp++; | |
2523 | } | |
2524 | } | |
2525 | ||
2526 | i40e_flush(hw); | |
2527 | } | |
2528 | ||
2529 | /** | |
2530 | * i40e_enable_misc_int_causes - enable the non-queue interrupts | |
2531 | * @hw: ptr to the hardware info | |
2532 | **/ | |
2533 | static void i40e_enable_misc_int_causes(struct i40e_hw *hw) | |
2534 | { | |
2535 | u32 val; | |
2536 | ||
2537 | /* clear things first */ | |
2538 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ | |
2539 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ | |
2540 | ||
2541 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | | |
2542 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | | |
2543 | I40E_PFINT_ICR0_ENA_GRST_MASK | | |
2544 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | | |
2545 | I40E_PFINT_ICR0_ENA_GPIO_MASK | | |
beb0dff1 | 2546 | I40E_PFINT_ICR0_ENA_TIMESYNC_MASK | |
41c445ff JB |
2547 | I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK | |
2548 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | | |
2549 | I40E_PFINT_ICR0_ENA_VFLR_MASK | | |
2550 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; | |
2551 | ||
2552 | wr32(hw, I40E_PFINT_ICR0_ENA, val); | |
2553 | ||
2554 | /* SW_ITR_IDX = 0, but don't change INTENA */ | |
84ed40e7 ASJ |
2555 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
2556 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); | |
41c445ff JB |
2557 | |
2558 | /* OTHER_ITR_IDX = 0 */ | |
2559 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); | |
2560 | } | |
2561 | ||
2562 | /** | |
2563 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW | |
2564 | * @vsi: the VSI being configured | |
2565 | **/ | |
2566 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) | |
2567 | { | |
493fb300 | 2568 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
41c445ff JB |
2569 | struct i40e_pf *pf = vsi->back; |
2570 | struct i40e_hw *hw = &pf->hw; | |
2571 | u32 val; | |
2572 | ||
2573 | /* set the ITR configuration */ | |
2574 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); | |
2575 | q_vector->rx.latency_range = I40E_LOW_LATENCY; | |
2576 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); | |
2577 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); | |
2578 | q_vector->tx.latency_range = I40E_LOW_LATENCY; | |
2579 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); | |
2580 | ||
2581 | i40e_enable_misc_int_causes(hw); | |
2582 | ||
2583 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ | |
2584 | wr32(hw, I40E_PFINT_LNKLST0, 0); | |
2585 | ||
f29eaa3d | 2586 | /* Associate the queue pair to the vector and enable the queue int */ |
41c445ff JB |
2587 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
2588 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | | |
2589 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); | |
2590 | ||
2591 | wr32(hw, I40E_QINT_RQCTL(0), val); | |
2592 | ||
2593 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | | |
2594 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | | |
2595 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); | |
2596 | ||
2597 | wr32(hw, I40E_QINT_TQCTL(0), val); | |
2598 | i40e_flush(hw); | |
2599 | } | |
2600 | ||
2ef28cfb MW |
2601 | /** |
2602 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 | |
2603 | * @pf: board private structure | |
2604 | **/ | |
2605 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) | |
2606 | { | |
2607 | struct i40e_hw *hw = &pf->hw; | |
2608 | ||
2609 | wr32(hw, I40E_PFINT_DYN_CTL0, | |
2610 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); | |
2611 | i40e_flush(hw); | |
2612 | } | |
2613 | ||
41c445ff JB |
2614 | /** |
2615 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 | |
2616 | * @pf: board private structure | |
2617 | **/ | |
116a57d4 | 2618 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf) |
41c445ff JB |
2619 | { |
2620 | struct i40e_hw *hw = &pf->hw; | |
2621 | u32 val; | |
2622 | ||
2623 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | | |
2624 | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK | | |
2625 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); | |
2626 | ||
2627 | wr32(hw, I40E_PFINT_DYN_CTL0, val); | |
2628 | i40e_flush(hw); | |
2629 | } | |
2630 | ||
2631 | /** | |
2632 | * i40e_irq_dynamic_enable - Enable default interrupt generation settings | |
2633 | * @vsi: pointer to a vsi | |
2634 | * @vector: enable a particular Hw Interrupt vector | |
2635 | **/ | |
2636 | void i40e_irq_dynamic_enable(struct i40e_vsi *vsi, int vector) | |
2637 | { | |
2638 | struct i40e_pf *pf = vsi->back; | |
2639 | struct i40e_hw *hw = &pf->hw; | |
2640 | u32 val; | |
2641 | ||
2642 | val = I40E_PFINT_DYN_CTLN_INTENA_MASK | | |
2643 | I40E_PFINT_DYN_CTLN_CLEARPBA_MASK | | |
2644 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); | |
2645 | wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val); | |
1022cb6c | 2646 | /* skip the flush */ |
41c445ff JB |
2647 | } |
2648 | ||
2649 | /** | |
2650 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler | |
2651 | * @irq: interrupt number | |
2652 | * @data: pointer to a q_vector | |
2653 | **/ | |
2654 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) | |
2655 | { | |
2656 | struct i40e_q_vector *q_vector = data; | |
2657 | ||
cd0b6fa6 | 2658 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
41c445ff JB |
2659 | return IRQ_HANDLED; |
2660 | ||
2661 | napi_schedule(&q_vector->napi); | |
2662 | ||
2663 | return IRQ_HANDLED; | |
2664 | } | |
2665 | ||
41c445ff JB |
2666 | /** |
2667 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts | |
2668 | * @vsi: the VSI being configured | |
2669 | * @basename: name for the vector | |
2670 | * | |
2671 | * Allocates MSI-X vectors and requests interrupts from the kernel. | |
2672 | **/ | |
2673 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) | |
2674 | { | |
2675 | int q_vectors = vsi->num_q_vectors; | |
2676 | struct i40e_pf *pf = vsi->back; | |
2677 | int base = vsi->base_vector; | |
2678 | int rx_int_idx = 0; | |
2679 | int tx_int_idx = 0; | |
2680 | int vector, err; | |
2681 | ||
2682 | for (vector = 0; vector < q_vectors; vector++) { | |
493fb300 | 2683 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
41c445ff | 2684 | |
cd0b6fa6 | 2685 | if (q_vector->tx.ring && q_vector->rx.ring) { |
41c445ff JB |
2686 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
2687 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); | |
2688 | tx_int_idx++; | |
cd0b6fa6 | 2689 | } else if (q_vector->rx.ring) { |
41c445ff JB |
2690 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
2691 | "%s-%s-%d", basename, "rx", rx_int_idx++); | |
cd0b6fa6 | 2692 | } else if (q_vector->tx.ring) { |
41c445ff JB |
2693 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
2694 | "%s-%s-%d", basename, "tx", tx_int_idx++); | |
2695 | } else { | |
2696 | /* skip this unused q_vector */ | |
2697 | continue; | |
2698 | } | |
2699 | err = request_irq(pf->msix_entries[base + vector].vector, | |
2700 | vsi->irq_handler, | |
2701 | 0, | |
2702 | q_vector->name, | |
2703 | q_vector); | |
2704 | if (err) { | |
2705 | dev_info(&pf->pdev->dev, | |
2706 | "%s: request_irq failed, error: %d\n", | |
2707 | __func__, err); | |
2708 | goto free_queue_irqs; | |
2709 | } | |
2710 | /* assign the mask for this irq */ | |
2711 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, | |
2712 | &q_vector->affinity_mask); | |
2713 | } | |
2714 | ||
2715 | return 0; | |
2716 | ||
2717 | free_queue_irqs: | |
2718 | while (vector) { | |
2719 | vector--; | |
2720 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, | |
2721 | NULL); | |
2722 | free_irq(pf->msix_entries[base + vector].vector, | |
2723 | &(vsi->q_vectors[vector])); | |
2724 | } | |
2725 | return err; | |
2726 | } | |
2727 | ||
2728 | /** | |
2729 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI | |
2730 | * @vsi: the VSI being un-configured | |
2731 | **/ | |
2732 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) | |
2733 | { | |
2734 | struct i40e_pf *pf = vsi->back; | |
2735 | struct i40e_hw *hw = &pf->hw; | |
2736 | int base = vsi->base_vector; | |
2737 | int i; | |
2738 | ||
2739 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
9f65e15b AD |
2740 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
2741 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); | |
41c445ff JB |
2742 | } |
2743 | ||
2744 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | |
2745 | for (i = vsi->base_vector; | |
2746 | i < (vsi->num_q_vectors + vsi->base_vector); i++) | |
2747 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); | |
2748 | ||
2749 | i40e_flush(hw); | |
2750 | for (i = 0; i < vsi->num_q_vectors; i++) | |
2751 | synchronize_irq(pf->msix_entries[i + base].vector); | |
2752 | } else { | |
2753 | /* Legacy and MSI mode - this stops all interrupt handling */ | |
2754 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); | |
2755 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); | |
2756 | i40e_flush(hw); | |
2757 | synchronize_irq(pf->pdev->irq); | |
2758 | } | |
2759 | } | |
2760 | ||
2761 | /** | |
2762 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI | |
2763 | * @vsi: the VSI being configured | |
2764 | **/ | |
2765 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) | |
2766 | { | |
2767 | struct i40e_pf *pf = vsi->back; | |
2768 | int i; | |
2769 | ||
2770 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | |
2771 | for (i = vsi->base_vector; | |
2772 | i < (vsi->num_q_vectors + vsi->base_vector); i++) | |
2773 | i40e_irq_dynamic_enable(vsi, i); | |
2774 | } else { | |
2775 | i40e_irq_dynamic_enable_icr0(pf); | |
2776 | } | |
2777 | ||
1022cb6c | 2778 | i40e_flush(&pf->hw); |
41c445ff JB |
2779 | return 0; |
2780 | } | |
2781 | ||
2782 | /** | |
2783 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events | |
2784 | * @pf: board private structure | |
2785 | **/ | |
2786 | static void i40e_stop_misc_vector(struct i40e_pf *pf) | |
2787 | { | |
2788 | /* Disable ICR 0 */ | |
2789 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); | |
2790 | i40e_flush(&pf->hw); | |
2791 | } | |
2792 | ||
2793 | /** | |
2794 | * i40e_intr - MSI/Legacy and non-queue interrupt handler | |
2795 | * @irq: interrupt number | |
2796 | * @data: pointer to a q_vector | |
2797 | * | |
2798 | * This is the handler used for all MSI/Legacy interrupts, and deals | |
2799 | * with both queue and non-queue interrupts. This is also used in | |
2800 | * MSIX mode to handle the non-queue interrupts. | |
2801 | **/ | |
2802 | static irqreturn_t i40e_intr(int irq, void *data) | |
2803 | { | |
2804 | struct i40e_pf *pf = (struct i40e_pf *)data; | |
2805 | struct i40e_hw *hw = &pf->hw; | |
5e823066 | 2806 | irqreturn_t ret = IRQ_NONE; |
41c445ff JB |
2807 | u32 icr0, icr0_remaining; |
2808 | u32 val, ena_mask; | |
2809 | ||
2810 | icr0 = rd32(hw, I40E_PFINT_ICR0); | |
5e823066 | 2811 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
41c445ff | 2812 | |
116a57d4 SN |
2813 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
2814 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) | |
5e823066 | 2815 | goto enable_intr; |
41c445ff | 2816 | |
cd92e72f SN |
2817 | /* if interrupt but no bits showing, must be SWINT */ |
2818 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || | |
2819 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) | |
2820 | pf->sw_int_count++; | |
2821 | ||
41c445ff JB |
2822 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
2823 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { | |
2824 | ||
2825 | /* temporarily disable queue cause for NAPI processing */ | |
2826 | u32 qval = rd32(hw, I40E_QINT_RQCTL(0)); | |
2827 | qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK; | |
2828 | wr32(hw, I40E_QINT_RQCTL(0), qval); | |
2829 | ||
2830 | qval = rd32(hw, I40E_QINT_TQCTL(0)); | |
2831 | qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK; | |
2832 | wr32(hw, I40E_QINT_TQCTL(0), qval); | |
41c445ff JB |
2833 | |
2834 | if (!test_bit(__I40E_DOWN, &pf->state)) | |
493fb300 | 2835 | napi_schedule(&pf->vsi[pf->lan_vsi]->q_vectors[0]->napi); |
41c445ff JB |
2836 | } |
2837 | ||
2838 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { | |
2839 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; | |
2840 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); | |
2841 | } | |
2842 | ||
2843 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { | |
2844 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; | |
2845 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); | |
2846 | } | |
2847 | ||
2848 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { | |
2849 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; | |
2850 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); | |
2851 | } | |
2852 | ||
2853 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { | |
2854 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) | |
2855 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); | |
2856 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; | |
2857 | val = rd32(hw, I40E_GLGEN_RSTAT); | |
2858 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) | |
2859 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; | |
d52cf0a9 | 2860 | if (val == I40E_RESET_CORER) |
41c445ff | 2861 | pf->corer_count++; |
d52cf0a9 | 2862 | else if (val == I40E_RESET_GLOBR) |
41c445ff | 2863 | pf->globr_count++; |
d52cf0a9 | 2864 | else if (val == I40E_RESET_EMPR) |
41c445ff JB |
2865 | pf->empr_count++; |
2866 | } | |
2867 | ||
9c010ee0 ASJ |
2868 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
2869 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; | |
2870 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); | |
2871 | } | |
2872 | ||
beb0dff1 JK |
2873 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
2874 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); | |
2875 | ||
2876 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { | |
2877 | ena_mask &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; | |
2878 | i40e_ptp_tx_hwtstamp(pf); | |
2879 | prttsyn_stat &= ~I40E_PRTTSYN_STAT_0_TXTIME_MASK; | |
2880 | } | |
2881 | ||
2882 | wr32(hw, I40E_PRTTSYN_STAT_0, prttsyn_stat); | |
2883 | } | |
2884 | ||
41c445ff JB |
2885 | /* If a critical error is pending we have no choice but to reset the |
2886 | * device. | |
2887 | * Report and mask out any remaining unexpected interrupts. | |
2888 | */ | |
2889 | icr0_remaining = icr0 & ena_mask; | |
2890 | if (icr0_remaining) { | |
2891 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", | |
2892 | icr0_remaining); | |
9c010ee0 | 2893 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
41c445ff | 2894 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
c0c28975 | 2895 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
9c010ee0 ASJ |
2896 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
2897 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); | |
2898 | i40e_service_event_schedule(pf); | |
41c445ff JB |
2899 | } |
2900 | ena_mask &= ~icr0_remaining; | |
2901 | } | |
5e823066 | 2902 | ret = IRQ_HANDLED; |
41c445ff | 2903 | |
5e823066 | 2904 | enable_intr: |
41c445ff JB |
2905 | /* re-enable interrupt causes */ |
2906 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); | |
41c445ff JB |
2907 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
2908 | i40e_service_event_schedule(pf); | |
2909 | i40e_irq_dynamic_enable_icr0(pf); | |
2910 | } | |
2911 | ||
5e823066 | 2912 | return ret; |
41c445ff JB |
2913 | } |
2914 | ||
cbf61325 ASJ |
2915 | /** |
2916 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes | |
2917 | * @tx_ring: tx ring to clean | |
2918 | * @budget: how many cleans we're allowed | |
2919 | * | |
2920 | * Returns true if there's any budget left (e.g. the clean is finished) | |
2921 | **/ | |
2922 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) | |
2923 | { | |
2924 | struct i40e_vsi *vsi = tx_ring->vsi; | |
2925 | u16 i = tx_ring->next_to_clean; | |
2926 | struct i40e_tx_buffer *tx_buf; | |
2927 | struct i40e_tx_desc *tx_desc; | |
2928 | ||
2929 | tx_buf = &tx_ring->tx_bi[i]; | |
2930 | tx_desc = I40E_TX_DESC(tx_ring, i); | |
2931 | i -= tx_ring->count; | |
2932 | ||
2933 | do { | |
2934 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; | |
2935 | ||
2936 | /* if next_to_watch is not set then there is no work pending */ | |
2937 | if (!eop_desc) | |
2938 | break; | |
2939 | ||
2940 | /* prevent any other reads prior to eop_desc */ | |
2941 | read_barrier_depends(); | |
2942 | ||
2943 | /* if the descriptor isn't done, no work yet to do */ | |
2944 | if (!(eop_desc->cmd_type_offset_bsz & | |
2945 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) | |
2946 | break; | |
2947 | ||
2948 | /* clear next_to_watch to prevent false hangs */ | |
2949 | tx_buf->next_to_watch = NULL; | |
2950 | ||
2951 | /* unmap skb header data */ | |
2952 | dma_unmap_single(tx_ring->dev, | |
2953 | dma_unmap_addr(tx_buf, dma), | |
2954 | dma_unmap_len(tx_buf, len), | |
2955 | DMA_TO_DEVICE); | |
2956 | ||
2957 | dma_unmap_len_set(tx_buf, len, 0); | |
2958 | ||
2959 | ||
2960 | /* move to the next desc and buffer to clean */ | |
2961 | tx_buf++; | |
2962 | tx_desc++; | |
2963 | i++; | |
2964 | if (unlikely(!i)) { | |
2965 | i -= tx_ring->count; | |
2966 | tx_buf = tx_ring->tx_bi; | |
2967 | tx_desc = I40E_TX_DESC(tx_ring, 0); | |
2968 | } | |
2969 | ||
2970 | /* update budget accounting */ | |
2971 | budget--; | |
2972 | } while (likely(budget)); | |
2973 | ||
2974 | i += tx_ring->count; | |
2975 | tx_ring->next_to_clean = i; | |
2976 | ||
2977 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) { | |
2978 | i40e_irq_dynamic_enable(vsi, | |
2979 | tx_ring->q_vector->v_idx + vsi->base_vector); | |
2980 | } | |
2981 | return budget > 0; | |
2982 | } | |
2983 | ||
2984 | /** | |
2985 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring | |
2986 | * @irq: interrupt number | |
2987 | * @data: pointer to a q_vector | |
2988 | **/ | |
2989 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) | |
2990 | { | |
2991 | struct i40e_q_vector *q_vector = data; | |
2992 | struct i40e_vsi *vsi; | |
2993 | ||
2994 | if (!q_vector->tx.ring) | |
2995 | return IRQ_HANDLED; | |
2996 | ||
2997 | vsi = q_vector->tx.ring->vsi; | |
2998 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); | |
2999 | ||
3000 | return IRQ_HANDLED; | |
3001 | } | |
3002 | ||
41c445ff | 3003 | /** |
cd0b6fa6 | 3004 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
41c445ff JB |
3005 | * @vsi: the VSI being configured |
3006 | * @v_idx: vector index | |
cd0b6fa6 | 3007 | * @qp_idx: queue pair index |
41c445ff | 3008 | **/ |
cd0b6fa6 | 3009 | static void map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx) |
41c445ff | 3010 | { |
493fb300 | 3011 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
9f65e15b AD |
3012 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
3013 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; | |
41c445ff JB |
3014 | |
3015 | tx_ring->q_vector = q_vector; | |
cd0b6fa6 AD |
3016 | tx_ring->next = q_vector->tx.ring; |
3017 | q_vector->tx.ring = tx_ring; | |
41c445ff | 3018 | q_vector->tx.count++; |
cd0b6fa6 AD |
3019 | |
3020 | rx_ring->q_vector = q_vector; | |
3021 | rx_ring->next = q_vector->rx.ring; | |
3022 | q_vector->rx.ring = rx_ring; | |
3023 | q_vector->rx.count++; | |
41c445ff JB |
3024 | } |
3025 | ||
3026 | /** | |
3027 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors | |
3028 | * @vsi: the VSI being configured | |
3029 | * | |
3030 | * This function maps descriptor rings to the queue-specific vectors | |
3031 | * we were allotted through the MSI-X enabling code. Ideally, we'd have | |
3032 | * one vector per queue pair, but on a constrained vector budget, we | |
3033 | * group the queue pairs as "efficiently" as possible. | |
3034 | **/ | |
3035 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) | |
3036 | { | |
3037 | int qp_remaining = vsi->num_queue_pairs; | |
3038 | int q_vectors = vsi->num_q_vectors; | |
cd0b6fa6 | 3039 | int num_ringpairs; |
41c445ff JB |
3040 | int v_start = 0; |
3041 | int qp_idx = 0; | |
3042 | ||
3043 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to | |
3044 | * group them so there are multiple queues per vector. | |
3045 | */ | |
3046 | for (; v_start < q_vectors && qp_remaining; v_start++) { | |
cd0b6fa6 AD |
3047 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
3048 | ||
3049 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); | |
3050 | ||
3051 | q_vector->num_ringpairs = num_ringpairs; | |
3052 | ||
3053 | q_vector->rx.count = 0; | |
3054 | q_vector->tx.count = 0; | |
3055 | q_vector->rx.ring = NULL; | |
3056 | q_vector->tx.ring = NULL; | |
3057 | ||
3058 | while (num_ringpairs--) { | |
3059 | map_vector_to_qp(vsi, v_start, qp_idx); | |
3060 | qp_idx++; | |
3061 | qp_remaining--; | |
41c445ff JB |
3062 | } |
3063 | } | |
3064 | } | |
3065 | ||
3066 | /** | |
3067 | * i40e_vsi_request_irq - Request IRQ from the OS | |
3068 | * @vsi: the VSI being configured | |
3069 | * @basename: name for the vector | |
3070 | **/ | |
3071 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) | |
3072 | { | |
3073 | struct i40e_pf *pf = vsi->back; | |
3074 | int err; | |
3075 | ||
3076 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) | |
3077 | err = i40e_vsi_request_irq_msix(vsi, basename); | |
3078 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) | |
3079 | err = request_irq(pf->pdev->irq, i40e_intr, 0, | |
3080 | pf->misc_int_name, pf); | |
3081 | else | |
3082 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, | |
3083 | pf->misc_int_name, pf); | |
3084 | ||
3085 | if (err) | |
3086 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); | |
3087 | ||
3088 | return err; | |
3089 | } | |
3090 | ||
3091 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
3092 | /** | |
3093 | * i40e_netpoll - A Polling 'interrupt'handler | |
3094 | * @netdev: network interface device structure | |
3095 | * | |
3096 | * This is used by netconsole to send skbs without having to re-enable | |
3097 | * interrupts. It's not called while the normal interrupt routine is executing. | |
3098 | **/ | |
3099 | static void i40e_netpoll(struct net_device *netdev) | |
3100 | { | |
3101 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
3102 | struct i40e_vsi *vsi = np->vsi; | |
3103 | struct i40e_pf *pf = vsi->back; | |
3104 | int i; | |
3105 | ||
3106 | /* if interface is down do nothing */ | |
3107 | if (test_bit(__I40E_DOWN, &vsi->state)) | |
3108 | return; | |
3109 | ||
3110 | pf->flags |= I40E_FLAG_IN_NETPOLL; | |
3111 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | |
3112 | for (i = 0; i < vsi->num_q_vectors; i++) | |
493fb300 | 3113 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
41c445ff JB |
3114 | } else { |
3115 | i40e_intr(pf->pdev->irq, netdev); | |
3116 | } | |
3117 | pf->flags &= ~I40E_FLAG_IN_NETPOLL; | |
3118 | } | |
3119 | #endif | |
3120 | ||
3121 | /** | |
3122 | * i40e_vsi_control_tx - Start or stop a VSI's rings | |
3123 | * @vsi: the VSI being configured | |
3124 | * @enable: start or stop the rings | |
3125 | **/ | |
3126 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) | |
3127 | { | |
3128 | struct i40e_pf *pf = vsi->back; | |
3129 | struct i40e_hw *hw = &pf->hw; | |
3130 | int i, j, pf_q; | |
3131 | u32 tx_reg; | |
3132 | ||
3133 | pf_q = vsi->base_queue; | |
3134 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { | |
6c5ef620 | 3135 | for (j = 0; j < 50; j++) { |
41c445ff | 3136 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
6c5ef620 MW |
3137 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
3138 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) | |
3139 | break; | |
3140 | usleep_range(1000, 2000); | |
3141 | } | |
fda972f6 MW |
3142 | /* Skip if the queue is already in the requested state */ |
3143 | if (enable && (tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) | |
3144 | continue; | |
3145 | if (!enable && !(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) | |
3146 | continue; | |
41c445ff JB |
3147 | |
3148 | /* turn on/off the queue */ | |
c5c9eb9e SN |
3149 | if (enable) { |
3150 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); | |
6c5ef620 | 3151 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
c5c9eb9e | 3152 | } else { |
41c445ff | 3153 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
c5c9eb9e | 3154 | } |
41c445ff JB |
3155 | |
3156 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); | |
3157 | ||
3158 | /* wait for the change to finish */ | |
3159 | for (j = 0; j < 10; j++) { | |
3160 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); | |
3161 | if (enable) { | |
3162 | if ((tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) | |
3163 | break; | |
3164 | } else { | |
3165 | if (!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) | |
3166 | break; | |
3167 | } | |
3168 | ||
3169 | udelay(10); | |
3170 | } | |
3171 | if (j >= 10) { | |
3172 | dev_info(&pf->pdev->dev, "Tx ring %d %sable timeout\n", | |
3173 | pf_q, (enable ? "en" : "dis")); | |
3174 | return -ETIMEDOUT; | |
3175 | } | |
3176 | } | |
3177 | ||
7134f9ce JB |
3178 | if (hw->revision_id == 0) |
3179 | mdelay(50); | |
3180 | ||
41c445ff JB |
3181 | return 0; |
3182 | } | |
3183 | ||
3184 | /** | |
3185 | * i40e_vsi_control_rx - Start or stop a VSI's rings | |
3186 | * @vsi: the VSI being configured | |
3187 | * @enable: start or stop the rings | |
3188 | **/ | |
3189 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) | |
3190 | { | |
3191 | struct i40e_pf *pf = vsi->back; | |
3192 | struct i40e_hw *hw = &pf->hw; | |
3193 | int i, j, pf_q; | |
3194 | u32 rx_reg; | |
3195 | ||
3196 | pf_q = vsi->base_queue; | |
3197 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { | |
6c5ef620 | 3198 | for (j = 0; j < 50; j++) { |
41c445ff | 3199 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
6c5ef620 MW |
3200 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
3201 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) | |
3202 | break; | |
3203 | usleep_range(1000, 2000); | |
3204 | } | |
41c445ff JB |
3205 | |
3206 | if (enable) { | |
3207 | /* is STAT set ? */ | |
3208 | if ((rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) | |
3209 | continue; | |
3210 | } else { | |
3211 | /* is !STAT set ? */ | |
3212 | if (!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) | |
3213 | continue; | |
3214 | } | |
3215 | ||
3216 | /* turn on/off the queue */ | |
3217 | if (enable) | |
6c5ef620 | 3218 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
41c445ff | 3219 | else |
6c5ef620 | 3220 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
41c445ff JB |
3221 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
3222 | ||
3223 | /* wait for the change to finish */ | |
3224 | for (j = 0; j < 10; j++) { | |
3225 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); | |
3226 | ||
3227 | if (enable) { | |
3228 | if ((rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) | |
3229 | break; | |
3230 | } else { | |
3231 | if (!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) | |
3232 | break; | |
3233 | } | |
3234 | ||
3235 | udelay(10); | |
3236 | } | |
3237 | if (j >= 10) { | |
3238 | dev_info(&pf->pdev->dev, "Rx ring %d %sable timeout\n", | |
3239 | pf_q, (enable ? "en" : "dis")); | |
3240 | return -ETIMEDOUT; | |
3241 | } | |
3242 | } | |
3243 | ||
3244 | return 0; | |
3245 | } | |
3246 | ||
3247 | /** | |
3248 | * i40e_vsi_control_rings - Start or stop a VSI's rings | |
3249 | * @vsi: the VSI being configured | |
3250 | * @enable: start or stop the rings | |
3251 | **/ | |
fc18eaa0 | 3252 | int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) |
41c445ff | 3253 | { |
3b867b28 | 3254 | int ret = 0; |
41c445ff JB |
3255 | |
3256 | /* do rx first for enable and last for disable */ | |
3257 | if (request) { | |
3258 | ret = i40e_vsi_control_rx(vsi, request); | |
3259 | if (ret) | |
3260 | return ret; | |
3261 | ret = i40e_vsi_control_tx(vsi, request); | |
3262 | } else { | |
3b867b28 ASJ |
3263 | /* Ignore return value, we need to shutdown whatever we can */ |
3264 | i40e_vsi_control_tx(vsi, request); | |
3265 | i40e_vsi_control_rx(vsi, request); | |
41c445ff JB |
3266 | } |
3267 | ||
3268 | return ret; | |
3269 | } | |
3270 | ||
3271 | /** | |
3272 | * i40e_vsi_free_irq - Free the irq association with the OS | |
3273 | * @vsi: the VSI being configured | |
3274 | **/ | |
3275 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) | |
3276 | { | |
3277 | struct i40e_pf *pf = vsi->back; | |
3278 | struct i40e_hw *hw = &pf->hw; | |
3279 | int base = vsi->base_vector; | |
3280 | u32 val, qp; | |
3281 | int i; | |
3282 | ||
3283 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | |
3284 | if (!vsi->q_vectors) | |
3285 | return; | |
3286 | ||
3287 | for (i = 0; i < vsi->num_q_vectors; i++) { | |
3288 | u16 vector = i + base; | |
3289 | ||
3290 | /* free only the irqs that were actually requested */ | |
78681b1f SN |
3291 | if (!vsi->q_vectors[i] || |
3292 | !vsi->q_vectors[i]->num_ringpairs) | |
41c445ff JB |
3293 | continue; |
3294 | ||
3295 | /* clear the affinity_mask in the IRQ descriptor */ | |
3296 | irq_set_affinity_hint(pf->msix_entries[vector].vector, | |
3297 | NULL); | |
3298 | free_irq(pf->msix_entries[vector].vector, | |
493fb300 | 3299 | vsi->q_vectors[i]); |
41c445ff JB |
3300 | |
3301 | /* Tear down the interrupt queue link list | |
3302 | * | |
3303 | * We know that they come in pairs and always | |
3304 | * the Rx first, then the Tx. To clear the | |
3305 | * link list, stick the EOL value into the | |
3306 | * next_q field of the registers. | |
3307 | */ | |
3308 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); | |
3309 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) | |
3310 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; | |
3311 | val |= I40E_QUEUE_END_OF_LIST | |
3312 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; | |
3313 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); | |
3314 | ||
3315 | while (qp != I40E_QUEUE_END_OF_LIST) { | |
3316 | u32 next; | |
3317 | ||
3318 | val = rd32(hw, I40E_QINT_RQCTL(qp)); | |
3319 | ||
3320 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | | |
3321 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | | |
3322 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | | |
3323 | I40E_QINT_RQCTL_INTEVENT_MASK); | |
3324 | ||
3325 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | | |
3326 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); | |
3327 | ||
3328 | wr32(hw, I40E_QINT_RQCTL(qp), val); | |
3329 | ||
3330 | val = rd32(hw, I40E_QINT_TQCTL(qp)); | |
3331 | ||
3332 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) | |
3333 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; | |
3334 | ||
3335 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | | |
3336 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | | |
3337 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | | |
3338 | I40E_QINT_TQCTL_INTEVENT_MASK); | |
3339 | ||
3340 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | | |
3341 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); | |
3342 | ||
3343 | wr32(hw, I40E_QINT_TQCTL(qp), val); | |
3344 | qp = next; | |
3345 | } | |
3346 | } | |
3347 | } else { | |
3348 | free_irq(pf->pdev->irq, pf); | |
3349 | ||
3350 | val = rd32(hw, I40E_PFINT_LNKLST0); | |
3351 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) | |
3352 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; | |
3353 | val |= I40E_QUEUE_END_OF_LIST | |
3354 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; | |
3355 | wr32(hw, I40E_PFINT_LNKLST0, val); | |
3356 | ||
3357 | val = rd32(hw, I40E_QINT_RQCTL(qp)); | |
3358 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | | |
3359 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | | |
3360 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | | |
3361 | I40E_QINT_RQCTL_INTEVENT_MASK); | |
3362 | ||
3363 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | | |
3364 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); | |
3365 | ||
3366 | wr32(hw, I40E_QINT_RQCTL(qp), val); | |
3367 | ||
3368 | val = rd32(hw, I40E_QINT_TQCTL(qp)); | |
3369 | ||
3370 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | | |
3371 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | | |
3372 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | | |
3373 | I40E_QINT_TQCTL_INTEVENT_MASK); | |
3374 | ||
3375 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | | |
3376 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); | |
3377 | ||
3378 | wr32(hw, I40E_QINT_TQCTL(qp), val); | |
3379 | } | |
3380 | } | |
3381 | ||
493fb300 AD |
3382 | /** |
3383 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector | |
3384 | * @vsi: the VSI being configured | |
3385 | * @v_idx: Index of vector to be freed | |
3386 | * | |
3387 | * This function frees the memory allocated to the q_vector. In addition if | |
3388 | * NAPI is enabled it will delete any references to the NAPI struct prior | |
3389 | * to freeing the q_vector. | |
3390 | **/ | |
3391 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) | |
3392 | { | |
3393 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; | |
cd0b6fa6 | 3394 | struct i40e_ring *ring; |
493fb300 AD |
3395 | |
3396 | if (!q_vector) | |
3397 | return; | |
3398 | ||
3399 | /* disassociate q_vector from rings */ | |
cd0b6fa6 AD |
3400 | i40e_for_each_ring(ring, q_vector->tx) |
3401 | ring->q_vector = NULL; | |
3402 | ||
3403 | i40e_for_each_ring(ring, q_vector->rx) | |
3404 | ring->q_vector = NULL; | |
493fb300 AD |
3405 | |
3406 | /* only VSI w/ an associated netdev is set up w/ NAPI */ | |
3407 | if (vsi->netdev) | |
3408 | netif_napi_del(&q_vector->napi); | |
3409 | ||
3410 | vsi->q_vectors[v_idx] = NULL; | |
3411 | ||
3412 | kfree_rcu(q_vector, rcu); | |
3413 | } | |
3414 | ||
41c445ff JB |
3415 | /** |
3416 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors | |
3417 | * @vsi: the VSI being un-configured | |
3418 | * | |
3419 | * This frees the memory allocated to the q_vectors and | |
3420 | * deletes references to the NAPI struct. | |
3421 | **/ | |
3422 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) | |
3423 | { | |
3424 | int v_idx; | |
3425 | ||
493fb300 AD |
3426 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
3427 | i40e_free_q_vector(vsi, v_idx); | |
41c445ff JB |
3428 | } |
3429 | ||
3430 | /** | |
3431 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS | |
3432 | * @pf: board private structure | |
3433 | **/ | |
3434 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) | |
3435 | { | |
3436 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ | |
3437 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | |
3438 | pci_disable_msix(pf->pdev); | |
3439 | kfree(pf->msix_entries); | |
3440 | pf->msix_entries = NULL; | |
3441 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { | |
3442 | pci_disable_msi(pf->pdev); | |
3443 | } | |
3444 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); | |
3445 | } | |
3446 | ||
3447 | /** | |
3448 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings | |
3449 | * @pf: board private structure | |
3450 | * | |
3451 | * We go through and clear interrupt specific resources and reset the structure | |
3452 | * to pre-load conditions | |
3453 | **/ | |
3454 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) | |
3455 | { | |
3456 | int i; | |
3457 | ||
3458 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); | |
3459 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) | |
3460 | if (pf->vsi[i]) | |
3461 | i40e_vsi_free_q_vectors(pf->vsi[i]); | |
3462 | i40e_reset_interrupt_capability(pf); | |
3463 | } | |
3464 | ||
3465 | /** | |
3466 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI | |
3467 | * @vsi: the VSI being configured | |
3468 | **/ | |
3469 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) | |
3470 | { | |
3471 | int q_idx; | |
3472 | ||
3473 | if (!vsi->netdev) | |
3474 | return; | |
3475 | ||
3476 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) | |
493fb300 | 3477 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
41c445ff JB |
3478 | } |
3479 | ||
3480 | /** | |
3481 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI | |
3482 | * @vsi: the VSI being configured | |
3483 | **/ | |
3484 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) | |
3485 | { | |
3486 | int q_idx; | |
3487 | ||
3488 | if (!vsi->netdev) | |
3489 | return; | |
3490 | ||
3491 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) | |
493fb300 | 3492 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
41c445ff JB |
3493 | } |
3494 | ||
3495 | /** | |
3496 | * i40e_quiesce_vsi - Pause a given VSI | |
3497 | * @vsi: the VSI being paused | |
3498 | **/ | |
3499 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) | |
3500 | { | |
3501 | if (test_bit(__I40E_DOWN, &vsi->state)) | |
3502 | return; | |
3503 | ||
3504 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); | |
3505 | if (vsi->netdev && netif_running(vsi->netdev)) { | |
3506 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); | |
3507 | } else { | |
3508 | set_bit(__I40E_DOWN, &vsi->state); | |
3509 | i40e_down(vsi); | |
3510 | } | |
3511 | } | |
3512 | ||
3513 | /** | |
3514 | * i40e_unquiesce_vsi - Resume a given VSI | |
3515 | * @vsi: the VSI being resumed | |
3516 | **/ | |
3517 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) | |
3518 | { | |
3519 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) | |
3520 | return; | |
3521 | ||
3522 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); | |
3523 | if (vsi->netdev && netif_running(vsi->netdev)) | |
3524 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); | |
3525 | else | |
3526 | i40e_up(vsi); /* this clears the DOWN bit */ | |
3527 | } | |
3528 | ||
3529 | /** | |
3530 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF | |
3531 | * @pf: the PF | |
3532 | **/ | |
3533 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) | |
3534 | { | |
3535 | int v; | |
3536 | ||
3537 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | |
3538 | if (pf->vsi[v]) | |
3539 | i40e_quiesce_vsi(pf->vsi[v]); | |
3540 | } | |
3541 | } | |
3542 | ||
3543 | /** | |
3544 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF | |
3545 | * @pf: the PF | |
3546 | **/ | |
3547 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) | |
3548 | { | |
3549 | int v; | |
3550 | ||
3551 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | |
3552 | if (pf->vsi[v]) | |
3553 | i40e_unquiesce_vsi(pf->vsi[v]); | |
3554 | } | |
3555 | } | |
3556 | ||
3557 | /** | |
3558 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config | |
3559 | * @dcbcfg: the corresponding DCBx configuration structure | |
3560 | * | |
3561 | * Return the number of TCs from given DCBx configuration | |
3562 | **/ | |
3563 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) | |
3564 | { | |
078b5876 JB |
3565 | u8 num_tc = 0; |
3566 | int i; | |
41c445ff JB |
3567 | |
3568 | /* Scan the ETS Config Priority Table to find | |
3569 | * traffic class enabled for a given priority | |
3570 | * and use the traffic class index to get the | |
3571 | * number of traffic classes enabled | |
3572 | */ | |
3573 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { | |
3574 | if (dcbcfg->etscfg.prioritytable[i] > num_tc) | |
3575 | num_tc = dcbcfg->etscfg.prioritytable[i]; | |
3576 | } | |
3577 | ||
3578 | /* Traffic class index starts from zero so | |
3579 | * increment to return the actual count | |
3580 | */ | |
078b5876 | 3581 | return num_tc + 1; |
41c445ff JB |
3582 | } |
3583 | ||
3584 | /** | |
3585 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes | |
3586 | * @dcbcfg: the corresponding DCBx configuration structure | |
3587 | * | |
3588 | * Query the current DCB configuration and return the number of | |
3589 | * traffic classes enabled from the given DCBX config | |
3590 | **/ | |
3591 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) | |
3592 | { | |
3593 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); | |
3594 | u8 enabled_tc = 1; | |
3595 | u8 i; | |
3596 | ||
3597 | for (i = 0; i < num_tc; i++) | |
3598 | enabled_tc |= 1 << i; | |
3599 | ||
3600 | return enabled_tc; | |
3601 | } | |
3602 | ||
3603 | /** | |
3604 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF | |
3605 | * @pf: PF being queried | |
3606 | * | |
3607 | * Return number of traffic classes enabled for the given PF | |
3608 | **/ | |
3609 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) | |
3610 | { | |
3611 | struct i40e_hw *hw = &pf->hw; | |
3612 | u8 i, enabled_tc; | |
3613 | u8 num_tc = 0; | |
3614 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; | |
3615 | ||
3616 | /* If DCB is not enabled then always in single TC */ | |
3617 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) | |
3618 | return 1; | |
3619 | ||
3620 | /* MFP mode return count of enabled TCs for this PF */ | |
3621 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { | |
3622 | enabled_tc = pf->hw.func_caps.enabled_tcmap; | |
3623 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
3624 | if (enabled_tc & (1 << i)) | |
3625 | num_tc++; | |
3626 | } | |
3627 | return num_tc; | |
3628 | } | |
3629 | ||
3630 | /* SFP mode will be enabled for all TCs on port */ | |
3631 | return i40e_dcb_get_num_tc(dcbcfg); | |
3632 | } | |
3633 | ||
3634 | /** | |
3635 | * i40e_pf_get_default_tc - Get bitmap for first enabled TC | |
3636 | * @pf: PF being queried | |
3637 | * | |
3638 | * Return a bitmap for first enabled traffic class for this PF. | |
3639 | **/ | |
3640 | static u8 i40e_pf_get_default_tc(struct i40e_pf *pf) | |
3641 | { | |
3642 | u8 enabled_tc = pf->hw.func_caps.enabled_tcmap; | |
3643 | u8 i = 0; | |
3644 | ||
3645 | if (!enabled_tc) | |
3646 | return 0x1; /* TC0 */ | |
3647 | ||
3648 | /* Find the first enabled TC */ | |
3649 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
3650 | if (enabled_tc & (1 << i)) | |
3651 | break; | |
3652 | } | |
3653 | ||
3654 | return 1 << i; | |
3655 | } | |
3656 | ||
3657 | /** | |
3658 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes | |
3659 | * @pf: PF being queried | |
3660 | * | |
3661 | * Return a bitmap for enabled traffic classes for this PF. | |
3662 | **/ | |
3663 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) | |
3664 | { | |
3665 | /* If DCB is not enabled for this PF then just return default TC */ | |
3666 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) | |
3667 | return i40e_pf_get_default_tc(pf); | |
3668 | ||
3669 | /* MFP mode will have enabled TCs set by FW */ | |
3670 | if (pf->flags & I40E_FLAG_MFP_ENABLED) | |
3671 | return pf->hw.func_caps.enabled_tcmap; | |
3672 | ||
3673 | /* SFP mode we want PF to be enabled for all TCs */ | |
3674 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); | |
3675 | } | |
3676 | ||
3677 | /** | |
3678 | * i40e_vsi_get_bw_info - Query VSI BW Information | |
3679 | * @vsi: the VSI being queried | |
3680 | * | |
3681 | * Returns 0 on success, negative value on failure | |
3682 | **/ | |
3683 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) | |
3684 | { | |
3685 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; | |
3686 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; | |
3687 | struct i40e_pf *pf = vsi->back; | |
3688 | struct i40e_hw *hw = &pf->hw; | |
dcae29be | 3689 | i40e_status aq_ret; |
41c445ff | 3690 | u32 tc_bw_max; |
41c445ff JB |
3691 | int i; |
3692 | ||
3693 | /* Get the VSI level BW configuration */ | |
dcae29be JB |
3694 | aq_ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
3695 | if (aq_ret) { | |
41c445ff JB |
3696 | dev_info(&pf->pdev->dev, |
3697 | "couldn't get pf vsi bw config, err %d, aq_err %d\n", | |
dcae29be JB |
3698 | aq_ret, pf->hw.aq.asq_last_status); |
3699 | return -EINVAL; | |
41c445ff JB |
3700 | } |
3701 | ||
3702 | /* Get the VSI level BW configuration per TC */ | |
dcae29be | 3703 | aq_ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
6838b535 | 3704 | NULL); |
dcae29be | 3705 | if (aq_ret) { |
41c445ff JB |
3706 | dev_info(&pf->pdev->dev, |
3707 | "couldn't get pf vsi ets bw config, err %d, aq_err %d\n", | |
dcae29be JB |
3708 | aq_ret, pf->hw.aq.asq_last_status); |
3709 | return -EINVAL; | |
41c445ff JB |
3710 | } |
3711 | ||
3712 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { | |
3713 | dev_info(&pf->pdev->dev, | |
3714 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", | |
3715 | bw_config.tc_valid_bits, | |
3716 | bw_ets_config.tc_valid_bits); | |
3717 | /* Still continuing */ | |
3718 | } | |
3719 | ||
3720 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); | |
3721 | vsi->bw_max_quanta = bw_config.max_bw; | |
3722 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | | |
3723 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); | |
3724 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
3725 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; | |
3726 | vsi->bw_ets_limit_credits[i] = | |
3727 | le16_to_cpu(bw_ets_config.credits[i]); | |
3728 | /* 3 bits out of 4 for each TC */ | |
3729 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); | |
3730 | } | |
078b5876 | 3731 | |
dcae29be | 3732 | return 0; |
41c445ff JB |
3733 | } |
3734 | ||
3735 | /** | |
3736 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC | |
3737 | * @vsi: the VSI being configured | |
3738 | * @enabled_tc: TC bitmap | |
3739 | * @bw_credits: BW shared credits per TC | |
3740 | * | |
3741 | * Returns 0 on success, negative value on failure | |
3742 | **/ | |
dcae29be | 3743 | static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc, |
41c445ff JB |
3744 | u8 *bw_share) |
3745 | { | |
3746 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; | |
dcae29be JB |
3747 | i40e_status aq_ret; |
3748 | int i; | |
41c445ff JB |
3749 | |
3750 | bw_data.tc_valid_bits = enabled_tc; | |
3751 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) | |
3752 | bw_data.tc_bw_credits[i] = bw_share[i]; | |
3753 | ||
dcae29be JB |
3754 | aq_ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
3755 | NULL); | |
3756 | if (aq_ret) { | |
41c445ff | 3757 | dev_info(&vsi->back->pdev->dev, |
69bfb110 JB |
3758 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
3759 | vsi->back->hw.aq.asq_last_status); | |
dcae29be | 3760 | return -EINVAL; |
41c445ff JB |
3761 | } |
3762 | ||
3763 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) | |
3764 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; | |
3765 | ||
dcae29be | 3766 | return 0; |
41c445ff JB |
3767 | } |
3768 | ||
3769 | /** | |
3770 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration | |
3771 | * @vsi: the VSI being configured | |
3772 | * @enabled_tc: TC map to be enabled | |
3773 | * | |
3774 | **/ | |
3775 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) | |
3776 | { | |
3777 | struct net_device *netdev = vsi->netdev; | |
3778 | struct i40e_pf *pf = vsi->back; | |
3779 | struct i40e_hw *hw = &pf->hw; | |
3780 | u8 netdev_tc = 0; | |
3781 | int i; | |
3782 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; | |
3783 | ||
3784 | if (!netdev) | |
3785 | return; | |
3786 | ||
3787 | if (!enabled_tc) { | |
3788 | netdev_reset_tc(netdev); | |
3789 | return; | |
3790 | } | |
3791 | ||
3792 | /* Set up actual enabled TCs on the VSI */ | |
3793 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) | |
3794 | return; | |
3795 | ||
3796 | /* set per TC queues for the VSI */ | |
3797 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
3798 | /* Only set TC queues for enabled tcs | |
3799 | * | |
3800 | * e.g. For a VSI that has TC0 and TC3 enabled the | |
3801 | * enabled_tc bitmap would be 0x00001001; the driver | |
3802 | * will set the numtc for netdev as 2 that will be | |
3803 | * referenced by the netdev layer as TC 0 and 1. | |
3804 | */ | |
3805 | if (vsi->tc_config.enabled_tc & (1 << i)) | |
3806 | netdev_set_tc_queue(netdev, | |
3807 | vsi->tc_config.tc_info[i].netdev_tc, | |
3808 | vsi->tc_config.tc_info[i].qcount, | |
3809 | vsi->tc_config.tc_info[i].qoffset); | |
3810 | } | |
3811 | ||
3812 | /* Assign UP2TC map for the VSI */ | |
3813 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { | |
3814 | /* Get the actual TC# for the UP */ | |
3815 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; | |
3816 | /* Get the mapped netdev TC# for the UP */ | |
3817 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; | |
3818 | netdev_set_prio_tc_map(netdev, i, netdev_tc); | |
3819 | } | |
3820 | } | |
3821 | ||
3822 | /** | |
3823 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map | |
3824 | * @vsi: the VSI being configured | |
3825 | * @ctxt: the ctxt buffer returned from AQ VSI update param command | |
3826 | **/ | |
3827 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, | |
3828 | struct i40e_vsi_context *ctxt) | |
3829 | { | |
3830 | /* copy just the sections touched not the entire info | |
3831 | * since not all sections are valid as returned by | |
3832 | * update vsi params | |
3833 | */ | |
3834 | vsi->info.mapping_flags = ctxt->info.mapping_flags; | |
3835 | memcpy(&vsi->info.queue_mapping, | |
3836 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); | |
3837 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, | |
3838 | sizeof(vsi->info.tc_mapping)); | |
3839 | } | |
3840 | ||
3841 | /** | |
3842 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map | |
3843 | * @vsi: VSI to be configured | |
3844 | * @enabled_tc: TC bitmap | |
3845 | * | |
3846 | * This configures a particular VSI for TCs that are mapped to the | |
3847 | * given TC bitmap. It uses default bandwidth share for TCs across | |
3848 | * VSIs to configure TC for a particular VSI. | |
3849 | * | |
3850 | * NOTE: | |
3851 | * It is expected that the VSI queues have been quisced before calling | |
3852 | * this function. | |
3853 | **/ | |
3854 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) | |
3855 | { | |
3856 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; | |
3857 | struct i40e_vsi_context ctxt; | |
3858 | int ret = 0; | |
3859 | int i; | |
3860 | ||
3861 | /* Check if enabled_tc is same as existing or new TCs */ | |
3862 | if (vsi->tc_config.enabled_tc == enabled_tc) | |
3863 | return ret; | |
3864 | ||
3865 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ | |
3866 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
3867 | if (enabled_tc & (1 << i)) | |
3868 | bw_share[i] = 1; | |
3869 | } | |
3870 | ||
3871 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); | |
3872 | if (ret) { | |
3873 | dev_info(&vsi->back->pdev->dev, | |
3874 | "Failed configuring TC map %d for VSI %d\n", | |
3875 | enabled_tc, vsi->seid); | |
3876 | goto out; | |
3877 | } | |
3878 | ||
3879 | /* Update Queue Pairs Mapping for currently enabled UPs */ | |
3880 | ctxt.seid = vsi->seid; | |
3881 | ctxt.pf_num = vsi->back->hw.pf_id; | |
3882 | ctxt.vf_num = 0; | |
3883 | ctxt.uplink_seid = vsi->uplink_seid; | |
3884 | memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); | |
3885 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); | |
3886 | ||
3887 | /* Update the VSI after updating the VSI queue-mapping information */ | |
3888 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); | |
3889 | if (ret) { | |
3890 | dev_info(&vsi->back->pdev->dev, | |
3891 | "update vsi failed, aq_err=%d\n", | |
3892 | vsi->back->hw.aq.asq_last_status); | |
3893 | goto out; | |
3894 | } | |
3895 | /* update the local VSI info with updated queue map */ | |
3896 | i40e_vsi_update_queue_map(vsi, &ctxt); | |
3897 | vsi->info.valid_sections = 0; | |
3898 | ||
3899 | /* Update current VSI BW information */ | |
3900 | ret = i40e_vsi_get_bw_info(vsi); | |
3901 | if (ret) { | |
3902 | dev_info(&vsi->back->pdev->dev, | |
3903 | "Failed updating vsi bw info, aq_err=%d\n", | |
3904 | vsi->back->hw.aq.asq_last_status); | |
3905 | goto out; | |
3906 | } | |
3907 | ||
3908 | /* Update the netdev TC setup */ | |
3909 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); | |
3910 | out: | |
3911 | return ret; | |
3912 | } | |
3913 | ||
4e3b35b0 NP |
3914 | /** |
3915 | * i40e_veb_config_tc - Configure TCs for given VEB | |
3916 | * @veb: given VEB | |
3917 | * @enabled_tc: TC bitmap | |
3918 | * | |
3919 | * Configures given TC bitmap for VEB (switching) element | |
3920 | **/ | |
3921 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) | |
3922 | { | |
3923 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; | |
3924 | struct i40e_pf *pf = veb->pf; | |
3925 | int ret = 0; | |
3926 | int i; | |
3927 | ||
3928 | /* No TCs or already enabled TCs just return */ | |
3929 | if (!enabled_tc || veb->enabled_tc == enabled_tc) | |
3930 | return ret; | |
3931 | ||
3932 | bw_data.tc_valid_bits = enabled_tc; | |
3933 | /* bw_data.absolute_credits is not set (relative) */ | |
3934 | ||
3935 | /* Enable ETS TCs with equal BW Share for now */ | |
3936 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
3937 | if (enabled_tc & (1 << i)) | |
3938 | bw_data.tc_bw_share_credits[i] = 1; | |
3939 | } | |
3940 | ||
3941 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, | |
3942 | &bw_data, NULL); | |
3943 | if (ret) { | |
3944 | dev_info(&pf->pdev->dev, | |
3945 | "veb bw config failed, aq_err=%d\n", | |
3946 | pf->hw.aq.asq_last_status); | |
3947 | goto out; | |
3948 | } | |
3949 | ||
3950 | /* Update the BW information */ | |
3951 | ret = i40e_veb_get_bw_info(veb); | |
3952 | if (ret) { | |
3953 | dev_info(&pf->pdev->dev, | |
3954 | "Failed getting veb bw config, aq_err=%d\n", | |
3955 | pf->hw.aq.asq_last_status); | |
3956 | } | |
3957 | ||
3958 | out: | |
3959 | return ret; | |
3960 | } | |
3961 | ||
3962 | #ifdef CONFIG_I40E_DCB | |
3963 | /** | |
3964 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs | |
3965 | * @pf: PF struct | |
3966 | * | |
3967 | * Reconfigure VEB/VSIs on a given PF; it is assumed that | |
3968 | * the caller would've quiesce all the VSIs before calling | |
3969 | * this function | |
3970 | **/ | |
3971 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) | |
3972 | { | |
3973 | u8 tc_map = 0; | |
3974 | int ret; | |
3975 | u8 v; | |
3976 | ||
3977 | /* Enable the TCs available on PF to all VEBs */ | |
3978 | tc_map = i40e_pf_get_tc_map(pf); | |
3979 | for (v = 0; v < I40E_MAX_VEB; v++) { | |
3980 | if (!pf->veb[v]) | |
3981 | continue; | |
3982 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); | |
3983 | if (ret) { | |
3984 | dev_info(&pf->pdev->dev, | |
3985 | "Failed configuring TC for VEB seid=%d\n", | |
3986 | pf->veb[v]->seid); | |
3987 | /* Will try to configure as many components */ | |
3988 | } | |
3989 | } | |
3990 | ||
3991 | /* Update each VSI */ | |
3992 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | |
3993 | if (!pf->vsi[v]) | |
3994 | continue; | |
3995 | ||
3996 | /* - Enable all TCs for the LAN VSI | |
3997 | * - For all others keep them at TC0 for now | |
3998 | */ | |
3999 | if (v == pf->lan_vsi) | |
4000 | tc_map = i40e_pf_get_tc_map(pf); | |
4001 | else | |
4002 | tc_map = i40e_pf_get_default_tc(pf); | |
4003 | ||
4004 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); | |
4005 | if (ret) { | |
4006 | dev_info(&pf->pdev->dev, | |
4007 | "Failed configuring TC for VSI seid=%d\n", | |
4008 | pf->vsi[v]->seid); | |
4009 | /* Will try to configure as many components */ | |
4010 | } else { | |
4011 | if (pf->vsi[v]->netdev) | |
4012 | i40e_dcbnl_set_all(pf->vsi[v]); | |
4013 | } | |
4014 | } | |
4015 | } | |
4016 | ||
4017 | /** | |
4018 | * i40e_init_pf_dcb - Initialize DCB configuration | |
4019 | * @pf: PF being configured | |
4020 | * | |
4021 | * Query the current DCB configuration and cache it | |
4022 | * in the hardware structure | |
4023 | **/ | |
4024 | static int i40e_init_pf_dcb(struct i40e_pf *pf) | |
4025 | { | |
4026 | struct i40e_hw *hw = &pf->hw; | |
4027 | int err = 0; | |
4028 | ||
4029 | if (pf->hw.func_caps.npar_enable) | |
4030 | goto out; | |
4031 | ||
4032 | /* Get the initial DCB configuration */ | |
4033 | err = i40e_init_dcb(hw); | |
4034 | if (!err) { | |
4035 | /* Device/Function is not DCBX capable */ | |
4036 | if ((!hw->func_caps.dcb) || | |
4037 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { | |
4038 | dev_info(&pf->pdev->dev, | |
4039 | "DCBX offload is not supported or is disabled for this PF.\n"); | |
4040 | ||
4041 | if (pf->flags & I40E_FLAG_MFP_ENABLED) | |
4042 | goto out; | |
4043 | ||
4044 | } else { | |
4045 | /* When status is not DISABLED then DCBX in FW */ | |
4046 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | | |
4047 | DCB_CAP_DCBX_VER_IEEE; | |
4048 | pf->flags |= I40E_FLAG_DCB_ENABLED; | |
4049 | } | |
4050 | } | |
4051 | ||
4052 | out: | |
4053 | return err; | |
4054 | } | |
4055 | #endif /* CONFIG_I40E_DCB */ | |
4056 | ||
41c445ff JB |
4057 | /** |
4058 | * i40e_up_complete - Finish the last steps of bringing up a connection | |
4059 | * @vsi: the VSI being configured | |
4060 | **/ | |
4061 | static int i40e_up_complete(struct i40e_vsi *vsi) | |
4062 | { | |
4063 | struct i40e_pf *pf = vsi->back; | |
4064 | int err; | |
4065 | ||
4066 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) | |
4067 | i40e_vsi_configure_msix(vsi); | |
4068 | else | |
4069 | i40e_configure_msi_and_legacy(vsi); | |
4070 | ||
4071 | /* start rings */ | |
4072 | err = i40e_vsi_control_rings(vsi, true); | |
4073 | if (err) | |
4074 | return err; | |
4075 | ||
4076 | clear_bit(__I40E_DOWN, &vsi->state); | |
4077 | i40e_napi_enable_all(vsi); | |
4078 | i40e_vsi_enable_irq(vsi); | |
4079 | ||
4080 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && | |
4081 | (vsi->netdev)) { | |
6d779b41 | 4082 | netdev_info(vsi->netdev, "NIC Link is Up\n"); |
41c445ff JB |
4083 | netif_tx_start_all_queues(vsi->netdev); |
4084 | netif_carrier_on(vsi->netdev); | |
6d779b41 AS |
4085 | } else if (vsi->netdev) { |
4086 | netdev_info(vsi->netdev, "NIC Link is Down\n"); | |
41c445ff | 4087 | } |
ca64fa4e ASJ |
4088 | |
4089 | /* replay FDIR SB filters */ | |
4090 | if (vsi->type == I40E_VSI_FDIR) | |
4091 | i40e_fdir_filter_restore(vsi); | |
41c445ff JB |
4092 | i40e_service_event_schedule(pf); |
4093 | ||
4094 | return 0; | |
4095 | } | |
4096 | ||
4097 | /** | |
4098 | * i40e_vsi_reinit_locked - Reset the VSI | |
4099 | * @vsi: the VSI being configured | |
4100 | * | |
4101 | * Rebuild the ring structs after some configuration | |
4102 | * has changed, e.g. MTU size. | |
4103 | **/ | |
4104 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) | |
4105 | { | |
4106 | struct i40e_pf *pf = vsi->back; | |
4107 | ||
4108 | WARN_ON(in_interrupt()); | |
4109 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) | |
4110 | usleep_range(1000, 2000); | |
4111 | i40e_down(vsi); | |
4112 | ||
4113 | /* Give a VF some time to respond to the reset. The | |
4114 | * two second wait is based upon the watchdog cycle in | |
4115 | * the VF driver. | |
4116 | */ | |
4117 | if (vsi->type == I40E_VSI_SRIOV) | |
4118 | msleep(2000); | |
4119 | i40e_up(vsi); | |
4120 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); | |
4121 | } | |
4122 | ||
4123 | /** | |
4124 | * i40e_up - Bring the connection back up after being down | |
4125 | * @vsi: the VSI being configured | |
4126 | **/ | |
4127 | int i40e_up(struct i40e_vsi *vsi) | |
4128 | { | |
4129 | int err; | |
4130 | ||
4131 | err = i40e_vsi_configure(vsi); | |
4132 | if (!err) | |
4133 | err = i40e_up_complete(vsi); | |
4134 | ||
4135 | return err; | |
4136 | } | |
4137 | ||
4138 | /** | |
4139 | * i40e_down - Shutdown the connection processing | |
4140 | * @vsi: the VSI being stopped | |
4141 | **/ | |
4142 | void i40e_down(struct i40e_vsi *vsi) | |
4143 | { | |
4144 | int i; | |
4145 | ||
4146 | /* It is assumed that the caller of this function | |
4147 | * sets the vsi->state __I40E_DOWN bit. | |
4148 | */ | |
4149 | if (vsi->netdev) { | |
4150 | netif_carrier_off(vsi->netdev); | |
4151 | netif_tx_disable(vsi->netdev); | |
4152 | } | |
4153 | i40e_vsi_disable_irq(vsi); | |
4154 | i40e_vsi_control_rings(vsi, false); | |
4155 | i40e_napi_disable_all(vsi); | |
4156 | ||
4157 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
9f65e15b AD |
4158 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
4159 | i40e_clean_rx_ring(vsi->rx_rings[i]); | |
41c445ff JB |
4160 | } |
4161 | } | |
4162 | ||
4163 | /** | |
4164 | * i40e_setup_tc - configure multiple traffic classes | |
4165 | * @netdev: net device to configure | |
4166 | * @tc: number of traffic classes to enable | |
4167 | **/ | |
4168 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) | |
4169 | { | |
4170 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
4171 | struct i40e_vsi *vsi = np->vsi; | |
4172 | struct i40e_pf *pf = vsi->back; | |
4173 | u8 enabled_tc = 0; | |
4174 | int ret = -EINVAL; | |
4175 | int i; | |
4176 | ||
4177 | /* Check if DCB enabled to continue */ | |
4178 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { | |
4179 | netdev_info(netdev, "DCB is not enabled for adapter\n"); | |
4180 | goto exit; | |
4181 | } | |
4182 | ||
4183 | /* Check if MFP enabled */ | |
4184 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { | |
4185 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); | |
4186 | goto exit; | |
4187 | } | |
4188 | ||
4189 | /* Check whether tc count is within enabled limit */ | |
4190 | if (tc > i40e_pf_get_num_tc(pf)) { | |
4191 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); | |
4192 | goto exit; | |
4193 | } | |
4194 | ||
4195 | /* Generate TC map for number of tc requested */ | |
4196 | for (i = 0; i < tc; i++) | |
4197 | enabled_tc |= (1 << i); | |
4198 | ||
4199 | /* Requesting same TC configuration as already enabled */ | |
4200 | if (enabled_tc == vsi->tc_config.enabled_tc) | |
4201 | return 0; | |
4202 | ||
4203 | /* Quiesce VSI queues */ | |
4204 | i40e_quiesce_vsi(vsi); | |
4205 | ||
4206 | /* Configure VSI for enabled TCs */ | |
4207 | ret = i40e_vsi_config_tc(vsi, enabled_tc); | |
4208 | if (ret) { | |
4209 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", | |
4210 | vsi->seid); | |
4211 | goto exit; | |
4212 | } | |
4213 | ||
4214 | /* Unquiesce VSI */ | |
4215 | i40e_unquiesce_vsi(vsi); | |
4216 | ||
4217 | exit: | |
4218 | return ret; | |
4219 | } | |
4220 | ||
4221 | /** | |
4222 | * i40e_open - Called when a network interface is made active | |
4223 | * @netdev: network interface device structure | |
4224 | * | |
4225 | * The open entry point is called when a network interface is made | |
4226 | * active by the system (IFF_UP). At this point all resources needed | |
4227 | * for transmit and receive operations are allocated, the interrupt | |
4228 | * handler is registered with the OS, the netdev watchdog subtask is | |
4229 | * enabled, and the stack is notified that the interface is ready. | |
4230 | * | |
4231 | * Returns 0 on success, negative value on failure | |
4232 | **/ | |
4233 | static int i40e_open(struct net_device *netdev) | |
4234 | { | |
4235 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
4236 | struct i40e_vsi *vsi = np->vsi; | |
4237 | struct i40e_pf *pf = vsi->back; | |
4238 | char int_name[IFNAMSIZ]; | |
4239 | int err; | |
4240 | ||
4241 | /* disallow open during test */ | |
4242 | if (test_bit(__I40E_TESTING, &pf->state)) | |
4243 | return -EBUSY; | |
4244 | ||
4245 | netif_carrier_off(netdev); | |
4246 | ||
4247 | /* allocate descriptors */ | |
4248 | err = i40e_vsi_setup_tx_resources(vsi); | |
4249 | if (err) | |
4250 | goto err_setup_tx; | |
4251 | err = i40e_vsi_setup_rx_resources(vsi); | |
4252 | if (err) | |
4253 | goto err_setup_rx; | |
4254 | ||
4255 | err = i40e_vsi_configure(vsi); | |
4256 | if (err) | |
4257 | goto err_setup_rx; | |
4258 | ||
4259 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", | |
4260 | dev_driver_string(&pf->pdev->dev), netdev->name); | |
4261 | err = i40e_vsi_request_irq(vsi, int_name); | |
4262 | if (err) | |
4263 | goto err_setup_rx; | |
4264 | ||
25946ddb | 4265 | /* Notify the stack of the actual queue counts. */ |
d7397644 | 4266 | err = netif_set_real_num_tx_queues(netdev, vsi->num_queue_pairs); |
25946ddb ASJ |
4267 | if (err) |
4268 | goto err_set_queues; | |
4269 | ||
d7397644 | 4270 | err = netif_set_real_num_rx_queues(netdev, vsi->num_queue_pairs); |
25946ddb ASJ |
4271 | if (err) |
4272 | goto err_set_queues; | |
4273 | ||
41c445ff JB |
4274 | err = i40e_up_complete(vsi); |
4275 | if (err) | |
4276 | goto err_up_complete; | |
4277 | ||
a1c9a9d9 JK |
4278 | #ifdef CONFIG_I40E_VXLAN |
4279 | vxlan_get_rx_port(netdev); | |
4280 | #endif | |
41c445ff JB |
4281 | |
4282 | return 0; | |
4283 | ||
4284 | err_up_complete: | |
4285 | i40e_down(vsi); | |
25946ddb | 4286 | err_set_queues: |
41c445ff JB |
4287 | i40e_vsi_free_irq(vsi); |
4288 | err_setup_rx: | |
4289 | i40e_vsi_free_rx_resources(vsi); | |
4290 | err_setup_tx: | |
4291 | i40e_vsi_free_tx_resources(vsi); | |
4292 | if (vsi == pf->vsi[pf->lan_vsi]) | |
4293 | i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED)); | |
4294 | ||
4295 | return err; | |
4296 | } | |
4297 | ||
17a73f6b JG |
4298 | /** |
4299 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting | |
4300 | * @pf: Pointer to pf | |
4301 | * | |
4302 | * This function destroys the hlist where all the Flow Director | |
4303 | * filters were saved. | |
4304 | **/ | |
4305 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) | |
4306 | { | |
4307 | struct i40e_fdir_filter *filter; | |
4308 | struct hlist_node *node2; | |
4309 | ||
4310 | hlist_for_each_entry_safe(filter, node2, | |
4311 | &pf->fdir_filter_list, fdir_node) { | |
4312 | hlist_del(&filter->fdir_node); | |
4313 | kfree(filter); | |
4314 | } | |
4315 | pf->fdir_pf_active_filters = 0; | |
4316 | } | |
4317 | ||
41c445ff JB |
4318 | /** |
4319 | * i40e_close - Disables a network interface | |
4320 | * @netdev: network interface device structure | |
4321 | * | |
4322 | * The close entry point is called when an interface is de-activated | |
4323 | * by the OS. The hardware is still under the driver's control, but | |
4324 | * this netdev interface is disabled. | |
4325 | * | |
4326 | * Returns 0, this is not allowed to fail | |
4327 | **/ | |
4328 | static int i40e_close(struct net_device *netdev) | |
4329 | { | |
4330 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
4331 | struct i40e_vsi *vsi = np->vsi; | |
4332 | ||
4333 | if (test_and_set_bit(__I40E_DOWN, &vsi->state)) | |
4334 | return 0; | |
4335 | ||
4336 | i40e_down(vsi); | |
4337 | i40e_vsi_free_irq(vsi); | |
4338 | ||
4339 | i40e_vsi_free_tx_resources(vsi); | |
4340 | i40e_vsi_free_rx_resources(vsi); | |
4341 | ||
4342 | return 0; | |
4343 | } | |
4344 | ||
4345 | /** | |
4346 | * i40e_do_reset - Start a PF or Core Reset sequence | |
4347 | * @pf: board private structure | |
4348 | * @reset_flags: which reset is requested | |
4349 | * | |
4350 | * The essential difference in resets is that the PF Reset | |
4351 | * doesn't clear the packet buffers, doesn't reset the PE | |
4352 | * firmware, and doesn't bother the other PFs on the chip. | |
4353 | **/ | |
4354 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) | |
4355 | { | |
4356 | u32 val; | |
4357 | ||
4358 | WARN_ON(in_interrupt()); | |
4359 | ||
4360 | /* do the biggest reset indicated */ | |
4361 | if (reset_flags & (1 << __I40E_GLOBAL_RESET_REQUESTED)) { | |
4362 | ||
4363 | /* Request a Global Reset | |
4364 | * | |
4365 | * This will start the chip's countdown to the actual full | |
4366 | * chip reset event, and a warning interrupt to be sent | |
4367 | * to all PFs, including the requestor. Our handler | |
4368 | * for the warning interrupt will deal with the shutdown | |
4369 | * and recovery of the switch setup. | |
4370 | */ | |
69bfb110 | 4371 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
41c445ff JB |
4372 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
4373 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; | |
4374 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); | |
4375 | ||
4376 | } else if (reset_flags & (1 << __I40E_CORE_RESET_REQUESTED)) { | |
4377 | ||
4378 | /* Request a Core Reset | |
4379 | * | |
4380 | * Same as Global Reset, except does *not* include the MAC/PHY | |
4381 | */ | |
69bfb110 | 4382 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
41c445ff JB |
4383 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
4384 | val |= I40E_GLGEN_RTRIG_CORER_MASK; | |
4385 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); | |
4386 | i40e_flush(&pf->hw); | |
4387 | ||
7823fe34 SN |
4388 | } else if (reset_flags & (1 << __I40E_EMP_RESET_REQUESTED)) { |
4389 | ||
4390 | /* Request a Firmware Reset | |
4391 | * | |
4392 | * Same as Global reset, plus restarting the | |
4393 | * embedded firmware engine. | |
4394 | */ | |
4395 | /* enable EMP Reset */ | |
4396 | val = rd32(&pf->hw, I40E_GLGEN_RSTENA_EMP); | |
4397 | val |= I40E_GLGEN_RSTENA_EMP_EMP_RST_ENA_MASK; | |
4398 | wr32(&pf->hw, I40E_GLGEN_RSTENA_EMP, val); | |
4399 | ||
4400 | /* force the reset */ | |
4401 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); | |
4402 | val |= I40E_GLGEN_RTRIG_EMPFWR_MASK; | |
4403 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); | |
4404 | i40e_flush(&pf->hw); | |
4405 | ||
41c445ff JB |
4406 | } else if (reset_flags & (1 << __I40E_PF_RESET_REQUESTED)) { |
4407 | ||
4408 | /* Request a PF Reset | |
4409 | * | |
4410 | * Resets only the PF-specific registers | |
4411 | * | |
4412 | * This goes directly to the tear-down and rebuild of | |
4413 | * the switch, since we need to do all the recovery as | |
4414 | * for the Core Reset. | |
4415 | */ | |
69bfb110 | 4416 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
41c445ff JB |
4417 | i40e_handle_reset_warning(pf); |
4418 | ||
4419 | } else if (reset_flags & (1 << __I40E_REINIT_REQUESTED)) { | |
4420 | int v; | |
4421 | ||
4422 | /* Find the VSI(s) that requested a re-init */ | |
4423 | dev_info(&pf->pdev->dev, | |
4424 | "VSI reinit requested\n"); | |
4425 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | |
4426 | struct i40e_vsi *vsi = pf->vsi[v]; | |
4427 | if (vsi != NULL && | |
4428 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { | |
4429 | i40e_vsi_reinit_locked(pf->vsi[v]); | |
4430 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); | |
4431 | } | |
4432 | } | |
4433 | ||
4434 | /* no further action needed, so return now */ | |
4435 | return; | |
4436 | } else { | |
4437 | dev_info(&pf->pdev->dev, | |
4438 | "bad reset request 0x%08x\n", reset_flags); | |
4439 | return; | |
4440 | } | |
4441 | } | |
4442 | ||
4e3b35b0 NP |
4443 | #ifdef CONFIG_I40E_DCB |
4444 | /** | |
4445 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig | |
4446 | * @pf: board private structure | |
4447 | * @old_cfg: current DCB config | |
4448 | * @new_cfg: new DCB config | |
4449 | **/ | |
4450 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, | |
4451 | struct i40e_dcbx_config *old_cfg, | |
4452 | struct i40e_dcbx_config *new_cfg) | |
4453 | { | |
4454 | bool need_reconfig = false; | |
4455 | ||
4456 | /* Check if ETS configuration has changed */ | |
4457 | if (memcmp(&new_cfg->etscfg, | |
4458 | &old_cfg->etscfg, | |
4459 | sizeof(new_cfg->etscfg))) { | |
4460 | /* If Priority Table has changed reconfig is needed */ | |
4461 | if (memcmp(&new_cfg->etscfg.prioritytable, | |
4462 | &old_cfg->etscfg.prioritytable, | |
4463 | sizeof(new_cfg->etscfg.prioritytable))) { | |
4464 | need_reconfig = true; | |
69bfb110 | 4465 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
4e3b35b0 NP |
4466 | } |
4467 | ||
4468 | if (memcmp(&new_cfg->etscfg.tcbwtable, | |
4469 | &old_cfg->etscfg.tcbwtable, | |
4470 | sizeof(new_cfg->etscfg.tcbwtable))) | |
69bfb110 | 4471 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
4e3b35b0 NP |
4472 | |
4473 | if (memcmp(&new_cfg->etscfg.tsatable, | |
4474 | &old_cfg->etscfg.tsatable, | |
4475 | sizeof(new_cfg->etscfg.tsatable))) | |
69bfb110 | 4476 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
4e3b35b0 NP |
4477 | } |
4478 | ||
4479 | /* Check if PFC configuration has changed */ | |
4480 | if (memcmp(&new_cfg->pfc, | |
4481 | &old_cfg->pfc, | |
4482 | sizeof(new_cfg->pfc))) { | |
4483 | need_reconfig = true; | |
69bfb110 | 4484 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
4e3b35b0 NP |
4485 | } |
4486 | ||
4487 | /* Check if APP Table has changed */ | |
4488 | if (memcmp(&new_cfg->app, | |
4489 | &old_cfg->app, | |
3d9667a9 | 4490 | sizeof(new_cfg->app))) { |
4e3b35b0 | 4491 | need_reconfig = true; |
69bfb110 | 4492 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
3d9667a9 | 4493 | } |
4e3b35b0 NP |
4494 | |
4495 | return need_reconfig; | |
4496 | } | |
4497 | ||
4498 | /** | |
4499 | * i40e_handle_lldp_event - Handle LLDP Change MIB event | |
4500 | * @pf: board private structure | |
4501 | * @e: event info posted on ARQ | |
4502 | **/ | |
4503 | static int i40e_handle_lldp_event(struct i40e_pf *pf, | |
4504 | struct i40e_arq_event_info *e) | |
4505 | { | |
4506 | struct i40e_aqc_lldp_get_mib *mib = | |
4507 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; | |
4508 | struct i40e_hw *hw = &pf->hw; | |
4509 | struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config; | |
4510 | struct i40e_dcbx_config tmp_dcbx_cfg; | |
4511 | bool need_reconfig = false; | |
4512 | int ret = 0; | |
4513 | u8 type; | |
4514 | ||
4515 | /* Ignore if event is not for Nearest Bridge */ | |
4516 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) | |
4517 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); | |
4518 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) | |
4519 | return ret; | |
4520 | ||
4521 | /* Check MIB Type and return if event for Remote MIB update */ | |
4522 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; | |
4523 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { | |
4524 | /* Update the remote cached instance and return */ | |
4525 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, | |
4526 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, | |
4527 | &hw->remote_dcbx_config); | |
4528 | goto exit; | |
4529 | } | |
4530 | ||
4531 | /* Convert/store the DCBX data from LLDPDU temporarily */ | |
4532 | memset(&tmp_dcbx_cfg, 0, sizeof(tmp_dcbx_cfg)); | |
4533 | ret = i40e_lldp_to_dcb_config(e->msg_buf, &tmp_dcbx_cfg); | |
4534 | if (ret) { | |
4535 | /* Error in LLDPDU parsing return */ | |
4536 | dev_info(&pf->pdev->dev, "Failed parsing LLDPDU from event buffer\n"); | |
4537 | goto exit; | |
4538 | } | |
4539 | ||
4540 | /* No change detected in DCBX configs */ | |
4541 | if (!memcmp(&tmp_dcbx_cfg, dcbx_cfg, sizeof(tmp_dcbx_cfg))) { | |
69bfb110 | 4542 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
4e3b35b0 NP |
4543 | goto exit; |
4544 | } | |
4545 | ||
4546 | need_reconfig = i40e_dcb_need_reconfig(pf, dcbx_cfg, &tmp_dcbx_cfg); | |
4547 | ||
4548 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg); | |
4549 | ||
4550 | /* Overwrite the new configuration */ | |
4551 | *dcbx_cfg = tmp_dcbx_cfg; | |
4552 | ||
4553 | if (!need_reconfig) | |
4554 | goto exit; | |
4555 | ||
4556 | /* Reconfiguration needed quiesce all VSIs */ | |
4557 | i40e_pf_quiesce_all_vsi(pf); | |
4558 | ||
4559 | /* Changes in configuration update VEB/VSI */ | |
4560 | i40e_dcb_reconfigure(pf); | |
4561 | ||
4562 | i40e_pf_unquiesce_all_vsi(pf); | |
4563 | exit: | |
4564 | return ret; | |
4565 | } | |
4566 | #endif /* CONFIG_I40E_DCB */ | |
4567 | ||
23326186 ASJ |
4568 | /** |
4569 | * i40e_do_reset_safe - Protected reset path for userland calls. | |
4570 | * @pf: board private structure | |
4571 | * @reset_flags: which reset is requested | |
4572 | * | |
4573 | **/ | |
4574 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) | |
4575 | { | |
4576 | rtnl_lock(); | |
4577 | i40e_do_reset(pf, reset_flags); | |
4578 | rtnl_unlock(); | |
4579 | } | |
4580 | ||
41c445ff JB |
4581 | /** |
4582 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event | |
4583 | * @pf: board private structure | |
4584 | * @e: event info posted on ARQ | |
4585 | * | |
4586 | * Handler for LAN Queue Overflow Event generated by the firmware for PF | |
4587 | * and VF queues | |
4588 | **/ | |
4589 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, | |
4590 | struct i40e_arq_event_info *e) | |
4591 | { | |
4592 | struct i40e_aqc_lan_overflow *data = | |
4593 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; | |
4594 | u32 queue = le32_to_cpu(data->prtdcb_rupto); | |
4595 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); | |
4596 | struct i40e_hw *hw = &pf->hw; | |
4597 | struct i40e_vf *vf; | |
4598 | u16 vf_id; | |
4599 | ||
69bfb110 JB |
4600 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
4601 | queue, qtx_ctl); | |
41c445ff JB |
4602 | |
4603 | /* Queue belongs to VF, find the VF and issue VF reset */ | |
4604 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) | |
4605 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { | |
4606 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) | |
4607 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); | |
4608 | vf_id -= hw->func_caps.vf_base_id; | |
4609 | vf = &pf->vf[vf_id]; | |
4610 | i40e_vc_notify_vf_reset(vf); | |
4611 | /* Allow VF to process pending reset notification */ | |
4612 | msleep(20); | |
4613 | i40e_reset_vf(vf, false); | |
4614 | } | |
4615 | } | |
4616 | ||
4617 | /** | |
4618 | * i40e_service_event_complete - Finish up the service event | |
4619 | * @pf: board private structure | |
4620 | **/ | |
4621 | static void i40e_service_event_complete(struct i40e_pf *pf) | |
4622 | { | |
4623 | BUG_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); | |
4624 | ||
4625 | /* flush memory to make sure state is correct before next watchog */ | |
4626 | smp_mb__before_clear_bit(); | |
4627 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); | |
4628 | } | |
4629 | ||
55a5e60b ASJ |
4630 | /** |
4631 | * i40e_get_current_fd_count - Get the count of FD filters programmed in the HW | |
4632 | * @pf: board private structure | |
4633 | **/ | |
4634 | int i40e_get_current_fd_count(struct i40e_pf *pf) | |
4635 | { | |
4636 | int val, fcnt_prog; | |
4637 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); | |
4638 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + | |
4639 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> | |
4640 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); | |
4641 | return fcnt_prog; | |
4642 | } | |
4643 | ||
4644 | /** | |
4645 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled | |
4646 | * @pf: board private structure | |
4647 | **/ | |
4648 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) | |
4649 | { | |
4650 | u32 fcnt_prog, fcnt_avail; | |
4651 | ||
4652 | /* Check if, FD SB or ATR was auto disabled and if there is enough room | |
4653 | * to re-enable | |
4654 | */ | |
4655 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && | |
4656 | (pf->flags & I40E_FLAG_FD_SB_ENABLED)) | |
4657 | return; | |
4658 | fcnt_prog = i40e_get_current_fd_count(pf); | |
4659 | fcnt_avail = pf->hw.fdir_shared_filter_count + | |
4660 | pf->fdir_pf_filter_count; | |
4661 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) { | |
4662 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && | |
4663 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { | |
4664 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; | |
4665 | dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n"); | |
4666 | } | |
4667 | } | |
4668 | /* Wait for some more space to be available to turn on ATR */ | |
4669 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { | |
4670 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && | |
4671 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { | |
4672 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; | |
4673 | dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table now\n"); | |
4674 | } | |
4675 | } | |
4676 | } | |
4677 | ||
41c445ff JB |
4678 | /** |
4679 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table | |
4680 | * @pf: board private structure | |
4681 | **/ | |
4682 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) | |
4683 | { | |
4684 | if (!(pf->flags & I40E_FLAG_FDIR_REQUIRES_REINIT)) | |
4685 | return; | |
4686 | ||
41c445ff JB |
4687 | /* if interface is down do nothing */ |
4688 | if (test_bit(__I40E_DOWN, &pf->state)) | |
4689 | return; | |
55a5e60b ASJ |
4690 | i40e_fdir_check_and_reenable(pf); |
4691 | ||
4692 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && | |
4693 | (pf->flags & I40E_FLAG_FD_SB_ENABLED)) | |
4694 | pf->flags &= ~I40E_FLAG_FDIR_REQUIRES_REINIT; | |
41c445ff JB |
4695 | } |
4696 | ||
4697 | /** | |
4698 | * i40e_vsi_link_event - notify VSI of a link event | |
4699 | * @vsi: vsi to be notified | |
4700 | * @link_up: link up or down | |
4701 | **/ | |
4702 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) | |
4703 | { | |
4704 | if (!vsi) | |
4705 | return; | |
4706 | ||
4707 | switch (vsi->type) { | |
4708 | case I40E_VSI_MAIN: | |
4709 | if (!vsi->netdev || !vsi->netdev_registered) | |
4710 | break; | |
4711 | ||
4712 | if (link_up) { | |
4713 | netif_carrier_on(vsi->netdev); | |
4714 | netif_tx_wake_all_queues(vsi->netdev); | |
4715 | } else { | |
4716 | netif_carrier_off(vsi->netdev); | |
4717 | netif_tx_stop_all_queues(vsi->netdev); | |
4718 | } | |
4719 | break; | |
4720 | ||
4721 | case I40E_VSI_SRIOV: | |
4722 | break; | |
4723 | ||
4724 | case I40E_VSI_VMDQ2: | |
4725 | case I40E_VSI_CTRL: | |
4726 | case I40E_VSI_MIRROR: | |
4727 | default: | |
4728 | /* there is no notification for other VSIs */ | |
4729 | break; | |
4730 | } | |
4731 | } | |
4732 | ||
4733 | /** | |
4734 | * i40e_veb_link_event - notify elements on the veb of a link event | |
4735 | * @veb: veb to be notified | |
4736 | * @link_up: link up or down | |
4737 | **/ | |
4738 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) | |
4739 | { | |
4740 | struct i40e_pf *pf; | |
4741 | int i; | |
4742 | ||
4743 | if (!veb || !veb->pf) | |
4744 | return; | |
4745 | pf = veb->pf; | |
4746 | ||
4747 | /* depth first... */ | |
4748 | for (i = 0; i < I40E_MAX_VEB; i++) | |
4749 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) | |
4750 | i40e_veb_link_event(pf->veb[i], link_up); | |
4751 | ||
4752 | /* ... now the local VSIs */ | |
4753 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) | |
4754 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) | |
4755 | i40e_vsi_link_event(pf->vsi[i], link_up); | |
4756 | } | |
4757 | ||
4758 | /** | |
4759 | * i40e_link_event - Update netif_carrier status | |
4760 | * @pf: board private structure | |
4761 | **/ | |
4762 | static void i40e_link_event(struct i40e_pf *pf) | |
4763 | { | |
4764 | bool new_link, old_link; | |
4765 | ||
4766 | new_link = (pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP); | |
4767 | old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP); | |
4768 | ||
4769 | if (new_link == old_link) | |
4770 | return; | |
4771 | ||
6d779b41 AS |
4772 | if (!test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state)) |
4773 | netdev_info(pf->vsi[pf->lan_vsi]->netdev, | |
4774 | "NIC Link is %s\n", (new_link ? "Up" : "Down")); | |
41c445ff JB |
4775 | |
4776 | /* Notify the base of the switch tree connected to | |
4777 | * the link. Floating VEBs are not notified. | |
4778 | */ | |
4779 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) | |
4780 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); | |
4781 | else | |
4782 | i40e_vsi_link_event(pf->vsi[pf->lan_vsi], new_link); | |
4783 | ||
4784 | if (pf->vf) | |
4785 | i40e_vc_notify_link_state(pf); | |
beb0dff1 JK |
4786 | |
4787 | if (pf->flags & I40E_FLAG_PTP) | |
4788 | i40e_ptp_set_increment(pf); | |
41c445ff JB |
4789 | } |
4790 | ||
4791 | /** | |
4792 | * i40e_check_hang_subtask - Check for hung queues and dropped interrupts | |
4793 | * @pf: board private structure | |
4794 | * | |
4795 | * Set the per-queue flags to request a check for stuck queues in the irq | |
4796 | * clean functions, then force interrupts to be sure the irq clean is called. | |
4797 | **/ | |
4798 | static void i40e_check_hang_subtask(struct i40e_pf *pf) | |
4799 | { | |
4800 | int i, v; | |
4801 | ||
4802 | /* If we're down or resetting, just bail */ | |
4803 | if (test_bit(__I40E_CONFIG_BUSY, &pf->state)) | |
4804 | return; | |
4805 | ||
4806 | /* for each VSI/netdev | |
4807 | * for each Tx queue | |
4808 | * set the check flag | |
4809 | * for each q_vector | |
4810 | * force an interrupt | |
4811 | */ | |
4812 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | |
4813 | struct i40e_vsi *vsi = pf->vsi[v]; | |
4814 | int armed = 0; | |
4815 | ||
4816 | if (!pf->vsi[v] || | |
4817 | test_bit(__I40E_DOWN, &vsi->state) || | |
4818 | (vsi->netdev && !netif_carrier_ok(vsi->netdev))) | |
4819 | continue; | |
4820 | ||
4821 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
9f65e15b | 4822 | set_check_for_tx_hang(vsi->tx_rings[i]); |
41c445ff | 4823 | if (test_bit(__I40E_HANG_CHECK_ARMED, |
9f65e15b | 4824 | &vsi->tx_rings[i]->state)) |
41c445ff JB |
4825 | armed++; |
4826 | } | |
4827 | ||
4828 | if (armed) { | |
4829 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) { | |
4830 | wr32(&vsi->back->hw, I40E_PFINT_DYN_CTL0, | |
4831 | (I40E_PFINT_DYN_CTL0_INTENA_MASK | | |
4832 | I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK)); | |
4833 | } else { | |
4834 | u16 vec = vsi->base_vector - 1; | |
4835 | u32 val = (I40E_PFINT_DYN_CTLN_INTENA_MASK | | |
4836 | I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK); | |
4837 | for (i = 0; i < vsi->num_q_vectors; i++, vec++) | |
4838 | wr32(&vsi->back->hw, | |
4839 | I40E_PFINT_DYN_CTLN(vec), val); | |
4840 | } | |
4841 | i40e_flush(&vsi->back->hw); | |
4842 | } | |
4843 | } | |
4844 | } | |
4845 | ||
4846 | /** | |
4847 | * i40e_watchdog_subtask - Check and bring link up | |
4848 | * @pf: board private structure | |
4849 | **/ | |
4850 | static void i40e_watchdog_subtask(struct i40e_pf *pf) | |
4851 | { | |
4852 | int i; | |
4853 | ||
4854 | /* if interface is down do nothing */ | |
4855 | if (test_bit(__I40E_DOWN, &pf->state) || | |
4856 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) | |
4857 | return; | |
4858 | ||
4859 | /* Update the stats for active netdevs so the network stack | |
4860 | * can look at updated numbers whenever it cares to | |
4861 | */ | |
4862 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) | |
4863 | if (pf->vsi[i] && pf->vsi[i]->netdev) | |
4864 | i40e_update_stats(pf->vsi[i]); | |
4865 | ||
4866 | /* Update the stats for the active switching components */ | |
4867 | for (i = 0; i < I40E_MAX_VEB; i++) | |
4868 | if (pf->veb[i]) | |
4869 | i40e_update_veb_stats(pf->veb[i]); | |
beb0dff1 JK |
4870 | |
4871 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); | |
41c445ff JB |
4872 | } |
4873 | ||
4874 | /** | |
4875 | * i40e_reset_subtask - Set up for resetting the device and driver | |
4876 | * @pf: board private structure | |
4877 | **/ | |
4878 | static void i40e_reset_subtask(struct i40e_pf *pf) | |
4879 | { | |
4880 | u32 reset_flags = 0; | |
4881 | ||
23326186 | 4882 | rtnl_lock(); |
41c445ff JB |
4883 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
4884 | reset_flags |= (1 << __I40E_REINIT_REQUESTED); | |
4885 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); | |
4886 | } | |
4887 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { | |
4888 | reset_flags |= (1 << __I40E_PF_RESET_REQUESTED); | |
4889 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); | |
4890 | } | |
4891 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { | |
4892 | reset_flags |= (1 << __I40E_CORE_RESET_REQUESTED); | |
4893 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); | |
4894 | } | |
4895 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { | |
4896 | reset_flags |= (1 << __I40E_GLOBAL_RESET_REQUESTED); | |
4897 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); | |
4898 | } | |
4899 | ||
4900 | /* If there's a recovery already waiting, it takes | |
4901 | * precedence before starting a new reset sequence. | |
4902 | */ | |
4903 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { | |
4904 | i40e_handle_reset_warning(pf); | |
23326186 | 4905 | goto unlock; |
41c445ff JB |
4906 | } |
4907 | ||
4908 | /* If we're already down or resetting, just bail */ | |
4909 | if (reset_flags && | |
4910 | !test_bit(__I40E_DOWN, &pf->state) && | |
4911 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) | |
4912 | i40e_do_reset(pf, reset_flags); | |
23326186 ASJ |
4913 | |
4914 | unlock: | |
4915 | rtnl_unlock(); | |
41c445ff JB |
4916 | } |
4917 | ||
4918 | /** | |
4919 | * i40e_handle_link_event - Handle link event | |
4920 | * @pf: board private structure | |
4921 | * @e: event info posted on ARQ | |
4922 | **/ | |
4923 | static void i40e_handle_link_event(struct i40e_pf *pf, | |
4924 | struct i40e_arq_event_info *e) | |
4925 | { | |
4926 | struct i40e_hw *hw = &pf->hw; | |
4927 | struct i40e_aqc_get_link_status *status = | |
4928 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; | |
4929 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; | |
4930 | ||
4931 | /* save off old link status information */ | |
4932 | memcpy(&pf->hw.phy.link_info_old, hw_link_info, | |
4933 | sizeof(pf->hw.phy.link_info_old)); | |
4934 | ||
4935 | /* update link status */ | |
4936 | hw_link_info->phy_type = (enum i40e_aq_phy_type)status->phy_type; | |
4937 | hw_link_info->link_speed = (enum i40e_aq_link_speed)status->link_speed; | |
4938 | hw_link_info->link_info = status->link_info; | |
4939 | hw_link_info->an_info = status->an_info; | |
4940 | hw_link_info->ext_info = status->ext_info; | |
4941 | hw_link_info->lse_enable = | |
4942 | le16_to_cpu(status->command_flags) & | |
4943 | I40E_AQ_LSE_ENABLE; | |
4944 | ||
4945 | /* process the event */ | |
4946 | i40e_link_event(pf); | |
4947 | ||
4948 | /* Do a new status request to re-enable LSE reporting | |
4949 | * and load new status information into the hw struct, | |
4950 | * then see if the status changed while processing the | |
4951 | * initial event. | |
4952 | */ | |
4953 | i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); | |
4954 | i40e_link_event(pf); | |
4955 | } | |
4956 | ||
4957 | /** | |
4958 | * i40e_clean_adminq_subtask - Clean the AdminQ rings | |
4959 | * @pf: board private structure | |
4960 | **/ | |
4961 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) | |
4962 | { | |
4963 | struct i40e_arq_event_info event; | |
4964 | struct i40e_hw *hw = &pf->hw; | |
4965 | u16 pending, i = 0; | |
4966 | i40e_status ret; | |
4967 | u16 opcode; | |
4968 | u32 val; | |
4969 | ||
4970 | if (!test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state)) | |
4971 | return; | |
4972 | ||
3197ce22 | 4973 | event.msg_size = I40E_MAX_AQ_BUF_SIZE; |
41c445ff JB |
4974 | event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL); |
4975 | if (!event.msg_buf) | |
4976 | return; | |
4977 | ||
4978 | do { | |
2f019123 | 4979 | event.msg_size = I40E_MAX_AQ_BUF_SIZE; /* reinit each time */ |
41c445ff JB |
4980 | ret = i40e_clean_arq_element(hw, &event, &pending); |
4981 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) { | |
4982 | dev_info(&pf->pdev->dev, "No ARQ event found\n"); | |
4983 | break; | |
4984 | } else if (ret) { | |
4985 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); | |
4986 | break; | |
4987 | } | |
4988 | ||
4989 | opcode = le16_to_cpu(event.desc.opcode); | |
4990 | switch (opcode) { | |
4991 | ||
4992 | case i40e_aqc_opc_get_link_status: | |
4993 | i40e_handle_link_event(pf, &event); | |
4994 | break; | |
4995 | case i40e_aqc_opc_send_msg_to_pf: | |
4996 | ret = i40e_vc_process_vf_msg(pf, | |
4997 | le16_to_cpu(event.desc.retval), | |
4998 | le32_to_cpu(event.desc.cookie_high), | |
4999 | le32_to_cpu(event.desc.cookie_low), | |
5000 | event.msg_buf, | |
5001 | event.msg_size); | |
5002 | break; | |
5003 | case i40e_aqc_opc_lldp_update_mib: | |
69bfb110 | 5004 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
4e3b35b0 NP |
5005 | #ifdef CONFIG_I40E_DCB |
5006 | rtnl_lock(); | |
5007 | ret = i40e_handle_lldp_event(pf, &event); | |
5008 | rtnl_unlock(); | |
5009 | #endif /* CONFIG_I40E_DCB */ | |
41c445ff JB |
5010 | break; |
5011 | case i40e_aqc_opc_event_lan_overflow: | |
69bfb110 | 5012 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
41c445ff JB |
5013 | i40e_handle_lan_overflow_event(pf, &event); |
5014 | break; | |
0467bc91 SN |
5015 | case i40e_aqc_opc_send_msg_to_peer: |
5016 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); | |
5017 | break; | |
41c445ff JB |
5018 | default: |
5019 | dev_info(&pf->pdev->dev, | |
0467bc91 SN |
5020 | "ARQ Error: Unknown event 0x%04x received\n", |
5021 | opcode); | |
41c445ff JB |
5022 | break; |
5023 | } | |
5024 | } while (pending && (i++ < pf->adminq_work_limit)); | |
5025 | ||
5026 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); | |
5027 | /* re-enable Admin queue interrupt cause */ | |
5028 | val = rd32(hw, I40E_PFINT_ICR0_ENA); | |
5029 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; | |
5030 | wr32(hw, I40E_PFINT_ICR0_ENA, val); | |
5031 | i40e_flush(hw); | |
5032 | ||
5033 | kfree(event.msg_buf); | |
5034 | } | |
5035 | ||
5036 | /** | |
5037 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it | |
5038 | * @veb: pointer to the VEB instance | |
5039 | * | |
5040 | * This is a recursive function that first builds the attached VSIs then | |
5041 | * recurses in to build the next layer of VEB. We track the connections | |
5042 | * through our own index numbers because the seid's from the HW could | |
5043 | * change across the reset. | |
5044 | **/ | |
5045 | static int i40e_reconstitute_veb(struct i40e_veb *veb) | |
5046 | { | |
5047 | struct i40e_vsi *ctl_vsi = NULL; | |
5048 | struct i40e_pf *pf = veb->pf; | |
5049 | int v, veb_idx; | |
5050 | int ret; | |
5051 | ||
5052 | /* build VSI that owns this VEB, temporarily attached to base VEB */ | |
5053 | for (v = 0; v < pf->hw.func_caps.num_vsis && !ctl_vsi; v++) { | |
5054 | if (pf->vsi[v] && | |
5055 | pf->vsi[v]->veb_idx == veb->idx && | |
5056 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { | |
5057 | ctl_vsi = pf->vsi[v]; | |
5058 | break; | |
5059 | } | |
5060 | } | |
5061 | if (!ctl_vsi) { | |
5062 | dev_info(&pf->pdev->dev, | |
5063 | "missing owner VSI for veb_idx %d\n", veb->idx); | |
5064 | ret = -ENOENT; | |
5065 | goto end_reconstitute; | |
5066 | } | |
5067 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) | |
5068 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; | |
5069 | ret = i40e_add_vsi(ctl_vsi); | |
5070 | if (ret) { | |
5071 | dev_info(&pf->pdev->dev, | |
5072 | "rebuild of owner VSI failed: %d\n", ret); | |
5073 | goto end_reconstitute; | |
5074 | } | |
5075 | i40e_vsi_reset_stats(ctl_vsi); | |
5076 | ||
5077 | /* create the VEB in the switch and move the VSI onto the VEB */ | |
5078 | ret = i40e_add_veb(veb, ctl_vsi); | |
5079 | if (ret) | |
5080 | goto end_reconstitute; | |
5081 | ||
5082 | /* create the remaining VSIs attached to this VEB */ | |
5083 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | |
5084 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) | |
5085 | continue; | |
5086 | ||
5087 | if (pf->vsi[v]->veb_idx == veb->idx) { | |
5088 | struct i40e_vsi *vsi = pf->vsi[v]; | |
5089 | vsi->uplink_seid = veb->seid; | |
5090 | ret = i40e_add_vsi(vsi); | |
5091 | if (ret) { | |
5092 | dev_info(&pf->pdev->dev, | |
5093 | "rebuild of vsi_idx %d failed: %d\n", | |
5094 | v, ret); | |
5095 | goto end_reconstitute; | |
5096 | } | |
5097 | i40e_vsi_reset_stats(vsi); | |
5098 | } | |
5099 | } | |
5100 | ||
5101 | /* create any VEBs attached to this VEB - RECURSION */ | |
5102 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { | |
5103 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { | |
5104 | pf->veb[veb_idx]->uplink_seid = veb->seid; | |
5105 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); | |
5106 | if (ret) | |
5107 | break; | |
5108 | } | |
5109 | } | |
5110 | ||
5111 | end_reconstitute: | |
5112 | return ret; | |
5113 | } | |
5114 | ||
5115 | /** | |
5116 | * i40e_get_capabilities - get info about the HW | |
5117 | * @pf: the PF struct | |
5118 | **/ | |
5119 | static int i40e_get_capabilities(struct i40e_pf *pf) | |
5120 | { | |
5121 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; | |
5122 | u16 data_size; | |
5123 | int buf_len; | |
5124 | int err; | |
5125 | ||
5126 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); | |
5127 | do { | |
5128 | cap_buf = kzalloc(buf_len, GFP_KERNEL); | |
5129 | if (!cap_buf) | |
5130 | return -ENOMEM; | |
5131 | ||
5132 | /* this loads the data into the hw struct for us */ | |
5133 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, | |
5134 | &data_size, | |
5135 | i40e_aqc_opc_list_func_capabilities, | |
5136 | NULL); | |
5137 | /* data loaded, buffer no longer needed */ | |
5138 | kfree(cap_buf); | |
5139 | ||
5140 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { | |
5141 | /* retry with a larger buffer */ | |
5142 | buf_len = data_size; | |
5143 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { | |
5144 | dev_info(&pf->pdev->dev, | |
5145 | "capability discovery failed: aq=%d\n", | |
5146 | pf->hw.aq.asq_last_status); | |
5147 | return -ENODEV; | |
5148 | } | |
5149 | } while (err); | |
5150 | ||
d0b10249 JB |
5151 | /* increment MSI-X count because current FW skips one */ |
5152 | pf->hw.func_caps.num_msix_vectors++; | |
7134f9ce | 5153 | |
ac71b7ba ASJ |
5154 | if (((pf->hw.aq.fw_maj_ver == 2) && (pf->hw.aq.fw_min_ver < 22)) || |
5155 | (pf->hw.aq.fw_maj_ver < 2)) { | |
5156 | pf->hw.func_caps.num_msix_vectors++; | |
5157 | pf->hw.func_caps.num_msix_vectors_vf++; | |
5158 | } | |
5159 | ||
41c445ff JB |
5160 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
5161 | dev_info(&pf->pdev->dev, | |
5162 | "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", | |
5163 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, | |
5164 | pf->hw.func_caps.num_msix_vectors, | |
5165 | pf->hw.func_caps.num_msix_vectors_vf, | |
5166 | pf->hw.func_caps.fd_filters_guaranteed, | |
5167 | pf->hw.func_caps.fd_filters_best_effort, | |
5168 | pf->hw.func_caps.num_tx_qp, | |
5169 | pf->hw.func_caps.num_vsis); | |
5170 | ||
7134f9ce JB |
5171 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
5172 | + pf->hw.func_caps.num_vfs) | |
5173 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { | |
5174 | dev_info(&pf->pdev->dev, | |
5175 | "got num_vsis %d, setting num_vsis to %d\n", | |
5176 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); | |
5177 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; | |
5178 | } | |
5179 | ||
41c445ff JB |
5180 | return 0; |
5181 | } | |
5182 | ||
cbf61325 ASJ |
5183 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
5184 | ||
41c445ff | 5185 | /** |
cbf61325 | 5186 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
41c445ff JB |
5187 | * @pf: board private structure |
5188 | **/ | |
cbf61325 | 5189 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
41c445ff JB |
5190 | { |
5191 | struct i40e_vsi *vsi; | |
5192 | bool new_vsi = false; | |
5193 | int err, i; | |
5194 | ||
cbf61325 | 5195 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
41c445ff JB |
5196 | return; |
5197 | ||
cbf61325 | 5198 | /* find existing VSI and see if it needs configuring */ |
41c445ff | 5199 | vsi = NULL; |
cbf61325 ASJ |
5200 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
5201 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { | |
41c445ff | 5202 | vsi = pf->vsi[i]; |
cbf61325 ASJ |
5203 | break; |
5204 | } | |
5205 | } | |
5206 | ||
5207 | /* create a new VSI if none exists */ | |
41c445ff | 5208 | if (!vsi) { |
cbf61325 ASJ |
5209 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
5210 | pf->vsi[pf->lan_vsi]->seid, 0); | |
41c445ff JB |
5211 | if (!vsi) { |
5212 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); | |
cbf61325 | 5213 | goto err_vsi; |
41c445ff JB |
5214 | } |
5215 | new_vsi = true; | |
5216 | } | |
cbf61325 | 5217 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
41c445ff JB |
5218 | |
5219 | err = i40e_vsi_setup_tx_resources(vsi); | |
cbf61325 ASJ |
5220 | if (err) |
5221 | goto err_setup_tx; | |
5222 | err = i40e_vsi_setup_rx_resources(vsi); | |
5223 | if (err) | |
5224 | goto err_setup_rx; | |
5225 | ||
5226 | if (new_vsi) { | |
41c445ff | 5227 | char int_name[IFNAMSIZ + 9]; |
cbf61325 ASJ |
5228 | err = i40e_vsi_configure(vsi); |
5229 | if (err) | |
5230 | goto err_setup_rx; | |
41c445ff JB |
5231 | snprintf(int_name, sizeof(int_name) - 1, "%s-fdir", |
5232 | dev_driver_string(&pf->pdev->dev)); | |
5233 | err = i40e_vsi_request_irq(vsi, int_name); | |
cbf61325 ASJ |
5234 | if (err) |
5235 | goto err_setup_rx; | |
41c445ff | 5236 | err = i40e_up_complete(vsi); |
cbf61325 ASJ |
5237 | if (err) |
5238 | goto err_up_complete; | |
17a73f6b | 5239 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
cbf61325 | 5240 | } |
41c445ff | 5241 | |
cbf61325 ASJ |
5242 | return; |
5243 | ||
5244 | err_up_complete: | |
5245 | i40e_down(vsi); | |
5246 | i40e_vsi_free_irq(vsi); | |
5247 | err_setup_rx: | |
5248 | i40e_vsi_free_rx_resources(vsi); | |
5249 | err_setup_tx: | |
5250 | i40e_vsi_free_tx_resources(vsi); | |
5251 | err_vsi: | |
5252 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; | |
5253 | i40e_vsi_clear(vsi); | |
41c445ff JB |
5254 | } |
5255 | ||
5256 | /** | |
5257 | * i40e_fdir_teardown - release the Flow Director resources | |
5258 | * @pf: board private structure | |
5259 | **/ | |
5260 | static void i40e_fdir_teardown(struct i40e_pf *pf) | |
5261 | { | |
5262 | int i; | |
5263 | ||
17a73f6b | 5264 | i40e_fdir_filter_exit(pf); |
41c445ff JB |
5265 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
5266 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { | |
5267 | i40e_vsi_release(pf->vsi[i]); | |
5268 | break; | |
5269 | } | |
5270 | } | |
5271 | } | |
5272 | ||
5273 | /** | |
f650a38b | 5274 | * i40e_prep_for_reset - prep for the core to reset |
41c445ff JB |
5275 | * @pf: board private structure |
5276 | * | |
f650a38b ASJ |
5277 | * Close up the VFs and other things in prep for pf Reset. |
5278 | **/ | |
5279 | static int i40e_prep_for_reset(struct i40e_pf *pf) | |
41c445ff | 5280 | { |
41c445ff JB |
5281 | struct i40e_hw *hw = &pf->hw; |
5282 | i40e_status ret; | |
5283 | u32 v; | |
5284 | ||
5285 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); | |
5286 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) | |
f650a38b | 5287 | return 0; |
41c445ff | 5288 | |
69bfb110 | 5289 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
41c445ff | 5290 | |
37f0be6d ASJ |
5291 | if (i40e_check_asq_alive(hw)) |
5292 | i40e_vc_notify_reset(pf); | |
41c445ff JB |
5293 | |
5294 | /* quiesce the VSIs and their queues that are not already DOWN */ | |
5295 | i40e_pf_quiesce_all_vsi(pf); | |
5296 | ||
5297 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | |
5298 | if (pf->vsi[v]) | |
5299 | pf->vsi[v]->seid = 0; | |
5300 | } | |
5301 | ||
5302 | i40e_shutdown_adminq(&pf->hw); | |
5303 | ||
f650a38b ASJ |
5304 | /* call shutdown HMC */ |
5305 | ret = i40e_shutdown_lan_hmc(hw); | |
5306 | if (ret) { | |
5307 | dev_info(&pf->pdev->dev, "shutdown_lan_hmc failed: %d\n", ret); | |
5308 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); | |
5309 | } | |
5310 | return ret; | |
5311 | } | |
5312 | ||
5313 | /** | |
4dda12e6 | 5314 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
f650a38b | 5315 | * @pf: board private structure |
bc7d338f | 5316 | * @reinit: if the Main VSI needs to re-initialized. |
f650a38b | 5317 | **/ |
bc7d338f | 5318 | static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit) |
f650a38b ASJ |
5319 | { |
5320 | struct i40e_driver_version dv; | |
5321 | struct i40e_hw *hw = &pf->hw; | |
5322 | i40e_status ret; | |
5323 | u32 v; | |
5324 | ||
41c445ff JB |
5325 | /* Now we wait for GRST to settle out. |
5326 | * We don't have to delete the VEBs or VSIs from the hw switch | |
5327 | * because the reset will make them disappear. | |
5328 | */ | |
5329 | ret = i40e_pf_reset(hw); | |
5330 | if (ret) | |
5331 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); | |
5332 | pf->pfr_count++; | |
5333 | ||
5334 | if (test_bit(__I40E_DOWN, &pf->state)) | |
5335 | goto end_core_reset; | |
69bfb110 | 5336 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
41c445ff JB |
5337 | |
5338 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ | |
5339 | ret = i40e_init_adminq(&pf->hw); | |
5340 | if (ret) { | |
5341 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, %d\n", ret); | |
5342 | goto end_core_reset; | |
5343 | } | |
5344 | ||
5345 | ret = i40e_get_capabilities(pf); | |
5346 | if (ret) { | |
5347 | dev_info(&pf->pdev->dev, "i40e_get_capabilities failed, %d\n", | |
5348 | ret); | |
5349 | goto end_core_reset; | |
5350 | } | |
5351 | ||
41c445ff JB |
5352 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
5353 | hw->func_caps.num_rx_qp, | |
5354 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); | |
5355 | if (ret) { | |
5356 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); | |
5357 | goto end_core_reset; | |
5358 | } | |
5359 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); | |
5360 | if (ret) { | |
5361 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); | |
5362 | goto end_core_reset; | |
5363 | } | |
5364 | ||
4e3b35b0 NP |
5365 | #ifdef CONFIG_I40E_DCB |
5366 | ret = i40e_init_pf_dcb(pf); | |
5367 | if (ret) { | |
5368 | dev_info(&pf->pdev->dev, "init_pf_dcb failed: %d\n", ret); | |
5369 | goto end_core_reset; | |
5370 | } | |
5371 | #endif /* CONFIG_I40E_DCB */ | |
5372 | ||
41c445ff | 5373 | /* do basic switch setup */ |
bc7d338f | 5374 | ret = i40e_setup_pf_switch(pf, reinit); |
41c445ff JB |
5375 | if (ret) |
5376 | goto end_core_reset; | |
5377 | ||
5378 | /* Rebuild the VSIs and VEBs that existed before reset. | |
5379 | * They are still in our local switch element arrays, so only | |
5380 | * need to rebuild the switch model in the HW. | |
5381 | * | |
5382 | * If there were VEBs but the reconstitution failed, we'll try | |
5383 | * try to recover minimal use by getting the basic PF VSI working. | |
5384 | */ | |
5385 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { | |
69bfb110 | 5386 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
41c445ff JB |
5387 | /* find the one VEB connected to the MAC, and find orphans */ |
5388 | for (v = 0; v < I40E_MAX_VEB; v++) { | |
5389 | if (!pf->veb[v]) | |
5390 | continue; | |
5391 | ||
5392 | if (pf->veb[v]->uplink_seid == pf->mac_seid || | |
5393 | pf->veb[v]->uplink_seid == 0) { | |
5394 | ret = i40e_reconstitute_veb(pf->veb[v]); | |
5395 | ||
5396 | if (!ret) | |
5397 | continue; | |
5398 | ||
5399 | /* If Main VEB failed, we're in deep doodoo, | |
5400 | * so give up rebuilding the switch and set up | |
5401 | * for minimal rebuild of PF VSI. | |
5402 | * If orphan failed, we'll report the error | |
5403 | * but try to keep going. | |
5404 | */ | |
5405 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { | |
5406 | dev_info(&pf->pdev->dev, | |
5407 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", | |
5408 | ret); | |
5409 | pf->vsi[pf->lan_vsi]->uplink_seid | |
5410 | = pf->mac_seid; | |
5411 | break; | |
5412 | } else if (pf->veb[v]->uplink_seid == 0) { | |
5413 | dev_info(&pf->pdev->dev, | |
5414 | "rebuild of orphan VEB failed: %d\n", | |
5415 | ret); | |
5416 | } | |
5417 | } | |
5418 | } | |
5419 | } | |
5420 | ||
5421 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { | |
5422 | dev_info(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); | |
5423 | /* no VEB, so rebuild only the Main VSI */ | |
5424 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); | |
5425 | if (ret) { | |
5426 | dev_info(&pf->pdev->dev, | |
5427 | "rebuild of Main VSI failed: %d\n", ret); | |
5428 | goto end_core_reset; | |
5429 | } | |
5430 | } | |
5431 | ||
5432 | /* reinit the misc interrupt */ | |
5433 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) | |
5434 | ret = i40e_setup_misc_vector(pf); | |
5435 | ||
5436 | /* restart the VSIs that were rebuilt and running before the reset */ | |
5437 | i40e_pf_unquiesce_all_vsi(pf); | |
5438 | ||
69f64b2b MW |
5439 | if (pf->num_alloc_vfs) { |
5440 | for (v = 0; v < pf->num_alloc_vfs; v++) | |
5441 | i40e_reset_vf(&pf->vf[v], true); | |
5442 | } | |
5443 | ||
41c445ff JB |
5444 | /* tell the firmware that we're starting */ |
5445 | dv.major_version = DRV_VERSION_MAJOR; | |
5446 | dv.minor_version = DRV_VERSION_MINOR; | |
5447 | dv.build_version = DRV_VERSION_BUILD; | |
5448 | dv.subbuild_version = 0; | |
5449 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); | |
5450 | ||
69bfb110 | 5451 | dev_info(&pf->pdev->dev, "reset complete\n"); |
41c445ff JB |
5452 | |
5453 | end_core_reset: | |
5454 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); | |
5455 | } | |
5456 | ||
f650a38b ASJ |
5457 | /** |
5458 | * i40e_handle_reset_warning - prep for the pf to reset, reset and rebuild | |
5459 | * @pf: board private structure | |
5460 | * | |
5461 | * Close up the VFs and other things in prep for a Core Reset, | |
5462 | * then get ready to rebuild the world. | |
5463 | **/ | |
5464 | static void i40e_handle_reset_warning(struct i40e_pf *pf) | |
5465 | { | |
5466 | i40e_status ret; | |
5467 | ||
5468 | ret = i40e_prep_for_reset(pf); | |
5469 | if (!ret) | |
bc7d338f | 5470 | i40e_reset_and_rebuild(pf, false); |
f650a38b ASJ |
5471 | } |
5472 | ||
41c445ff JB |
5473 | /** |
5474 | * i40e_handle_mdd_event | |
5475 | * @pf: pointer to the pf structure | |
5476 | * | |
5477 | * Called from the MDD irq handler to identify possibly malicious vfs | |
5478 | **/ | |
5479 | static void i40e_handle_mdd_event(struct i40e_pf *pf) | |
5480 | { | |
5481 | struct i40e_hw *hw = &pf->hw; | |
5482 | bool mdd_detected = false; | |
5483 | struct i40e_vf *vf; | |
5484 | u32 reg; | |
5485 | int i; | |
5486 | ||
5487 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) | |
5488 | return; | |
5489 | ||
5490 | /* find what triggered the MDD event */ | |
5491 | reg = rd32(hw, I40E_GL_MDET_TX); | |
5492 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { | |
5493 | u8 func = (reg & I40E_GL_MDET_TX_FUNCTION_MASK) | |
5494 | >> I40E_GL_MDET_TX_FUNCTION_SHIFT; | |
5495 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_SHIFT) | |
5496 | >> I40E_GL_MDET_TX_EVENT_SHIFT; | |
5497 | u8 queue = (reg & I40E_GL_MDET_TX_QUEUE_MASK) | |
5498 | >> I40E_GL_MDET_TX_QUEUE_SHIFT; | |
5499 | dev_info(&pf->pdev->dev, | |
f29eaa3d | 5500 | "Malicious Driver Detection event 0x%02x on TX queue %d of function 0x%02x\n", |
41c445ff JB |
5501 | event, queue, func); |
5502 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); | |
5503 | mdd_detected = true; | |
5504 | } | |
5505 | reg = rd32(hw, I40E_GL_MDET_RX); | |
5506 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { | |
5507 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) | |
5508 | >> I40E_GL_MDET_RX_FUNCTION_SHIFT; | |
5509 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_SHIFT) | |
5510 | >> I40E_GL_MDET_RX_EVENT_SHIFT; | |
5511 | u8 queue = (reg & I40E_GL_MDET_RX_QUEUE_MASK) | |
5512 | >> I40E_GL_MDET_RX_QUEUE_SHIFT; | |
5513 | dev_info(&pf->pdev->dev, | |
f29eaa3d | 5514 | "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
41c445ff JB |
5515 | event, queue, func); |
5516 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); | |
5517 | mdd_detected = true; | |
5518 | } | |
5519 | ||
5520 | /* see if one of the VFs needs its hand slapped */ | |
5521 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { | |
5522 | vf = &(pf->vf[i]); | |
5523 | reg = rd32(hw, I40E_VP_MDET_TX(i)); | |
5524 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { | |
5525 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); | |
5526 | vf->num_mdd_events++; | |
5527 | dev_info(&pf->pdev->dev, "MDD TX event on VF %d\n", i); | |
5528 | } | |
5529 | ||
5530 | reg = rd32(hw, I40E_VP_MDET_RX(i)); | |
5531 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { | |
5532 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); | |
5533 | vf->num_mdd_events++; | |
5534 | dev_info(&pf->pdev->dev, "MDD RX event on VF %d\n", i); | |
5535 | } | |
5536 | ||
5537 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { | |
5538 | dev_info(&pf->pdev->dev, | |
5539 | "Too many MDD events on VF %d, disabled\n", i); | |
5540 | dev_info(&pf->pdev->dev, | |
5541 | "Use PF Control I/F to re-enable the VF\n"); | |
5542 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); | |
5543 | } | |
5544 | } | |
5545 | ||
5546 | /* re-enable mdd interrupt cause */ | |
5547 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); | |
5548 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); | |
5549 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; | |
5550 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); | |
5551 | i40e_flush(hw); | |
5552 | } | |
5553 | ||
a1c9a9d9 JK |
5554 | #ifdef CONFIG_I40E_VXLAN |
5555 | /** | |
5556 | * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW | |
5557 | * @pf: board private structure | |
5558 | **/ | |
5559 | static void i40e_sync_vxlan_filters_subtask(struct i40e_pf *pf) | |
5560 | { | |
5561 | const int vxlan_hdr_qwords = 4; | |
5562 | struct i40e_hw *hw = &pf->hw; | |
5563 | i40e_status ret; | |
5564 | u8 filter_index; | |
5565 | __be16 port; | |
5566 | int i; | |
5567 | ||
5568 | if (!(pf->flags & I40E_FLAG_VXLAN_FILTER_SYNC)) | |
5569 | return; | |
5570 | ||
5571 | pf->flags &= ~I40E_FLAG_VXLAN_FILTER_SYNC; | |
5572 | ||
5573 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { | |
5574 | if (pf->pending_vxlan_bitmap & (1 << i)) { | |
5575 | pf->pending_vxlan_bitmap &= ~(1 << i); | |
5576 | port = pf->vxlan_ports[i]; | |
5577 | ret = port ? | |
5578 | i40e_aq_add_udp_tunnel(hw, ntohs(port), | |
5579 | vxlan_hdr_qwords, | |
5580 | I40E_AQC_TUNNEL_TYPE_VXLAN, | |
5581 | &filter_index, NULL) | |
5582 | : i40e_aq_del_udp_tunnel(hw, i, NULL); | |
5583 | ||
5584 | if (ret) { | |
5585 | dev_info(&pf->pdev->dev, "Failed to execute AQ command for %s port %d with index %d\n", | |
5586 | port ? "adding" : "deleting", | |
5587 | ntohs(port), port ? i : i); | |
5588 | ||
5589 | pf->vxlan_ports[i] = 0; | |
5590 | } else { | |
5591 | dev_info(&pf->pdev->dev, "%s port %d with AQ command with index %d\n", | |
5592 | port ? "Added" : "Deleted", | |
5593 | ntohs(port), port ? i : filter_index); | |
5594 | } | |
5595 | } | |
5596 | } | |
5597 | } | |
5598 | ||
5599 | #endif | |
41c445ff JB |
5600 | /** |
5601 | * i40e_service_task - Run the driver's async subtasks | |
5602 | * @work: pointer to work_struct containing our data | |
5603 | **/ | |
5604 | static void i40e_service_task(struct work_struct *work) | |
5605 | { | |
5606 | struct i40e_pf *pf = container_of(work, | |
5607 | struct i40e_pf, | |
5608 | service_task); | |
5609 | unsigned long start_time = jiffies; | |
5610 | ||
5611 | i40e_reset_subtask(pf); | |
5612 | i40e_handle_mdd_event(pf); | |
5613 | i40e_vc_process_vflr_event(pf); | |
5614 | i40e_watchdog_subtask(pf); | |
5615 | i40e_fdir_reinit_subtask(pf); | |
5616 | i40e_check_hang_subtask(pf); | |
5617 | i40e_sync_filters_subtask(pf); | |
a1c9a9d9 JK |
5618 | #ifdef CONFIG_I40E_VXLAN |
5619 | i40e_sync_vxlan_filters_subtask(pf); | |
5620 | #endif | |
41c445ff JB |
5621 | i40e_clean_adminq_subtask(pf); |
5622 | ||
5623 | i40e_service_event_complete(pf); | |
5624 | ||
5625 | /* If the tasks have taken longer than one timer cycle or there | |
5626 | * is more work to be done, reschedule the service task now | |
5627 | * rather than wait for the timer to tick again. | |
5628 | */ | |
5629 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || | |
5630 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || | |
5631 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || | |
5632 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) | |
5633 | i40e_service_event_schedule(pf); | |
5634 | } | |
5635 | ||
5636 | /** | |
5637 | * i40e_service_timer - timer callback | |
5638 | * @data: pointer to PF struct | |
5639 | **/ | |
5640 | static void i40e_service_timer(unsigned long data) | |
5641 | { | |
5642 | struct i40e_pf *pf = (struct i40e_pf *)data; | |
5643 | ||
5644 | mod_timer(&pf->service_timer, | |
5645 | round_jiffies(jiffies + pf->service_timer_period)); | |
5646 | i40e_service_event_schedule(pf); | |
5647 | } | |
5648 | ||
5649 | /** | |
5650 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI | |
5651 | * @vsi: the VSI being configured | |
5652 | **/ | |
5653 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) | |
5654 | { | |
5655 | struct i40e_pf *pf = vsi->back; | |
5656 | ||
5657 | switch (vsi->type) { | |
5658 | case I40E_VSI_MAIN: | |
5659 | vsi->alloc_queue_pairs = pf->num_lan_qps; | |
5660 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, | |
5661 | I40E_REQ_DESCRIPTOR_MULTIPLE); | |
5662 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) | |
5663 | vsi->num_q_vectors = pf->num_lan_msix; | |
5664 | else | |
5665 | vsi->num_q_vectors = 1; | |
5666 | ||
5667 | break; | |
5668 | ||
5669 | case I40E_VSI_FDIR: | |
5670 | vsi->alloc_queue_pairs = 1; | |
5671 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, | |
5672 | I40E_REQ_DESCRIPTOR_MULTIPLE); | |
5673 | vsi->num_q_vectors = 1; | |
5674 | break; | |
5675 | ||
5676 | case I40E_VSI_VMDQ2: | |
5677 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; | |
5678 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, | |
5679 | I40E_REQ_DESCRIPTOR_MULTIPLE); | |
5680 | vsi->num_q_vectors = pf->num_vmdq_msix; | |
5681 | break; | |
5682 | ||
5683 | case I40E_VSI_SRIOV: | |
5684 | vsi->alloc_queue_pairs = pf->num_vf_qps; | |
5685 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, | |
5686 | I40E_REQ_DESCRIPTOR_MULTIPLE); | |
5687 | break; | |
5688 | ||
5689 | default: | |
5690 | WARN_ON(1); | |
5691 | return -ENODATA; | |
5692 | } | |
5693 | ||
5694 | return 0; | |
5695 | } | |
5696 | ||
f650a38b ASJ |
5697 | /** |
5698 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi | |
5699 | * @type: VSI pointer | |
bc7d338f | 5700 | * @alloc_qvectors: a bool to specify if q_vectors need to be allocated. |
f650a38b ASJ |
5701 | * |
5702 | * On error: returns error code (negative) | |
5703 | * On success: returns 0 | |
5704 | **/ | |
bc7d338f | 5705 | static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors) |
f650a38b ASJ |
5706 | { |
5707 | int size; | |
5708 | int ret = 0; | |
5709 | ||
ac6c5e3d | 5710 | /* allocate memory for both Tx and Rx ring pointers */ |
f650a38b ASJ |
5711 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
5712 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); | |
5713 | if (!vsi->tx_rings) | |
5714 | return -ENOMEM; | |
f650a38b ASJ |
5715 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
5716 | ||
bc7d338f ASJ |
5717 | if (alloc_qvectors) { |
5718 | /* allocate memory for q_vector pointers */ | |
5719 | size = sizeof(struct i40e_q_vectors *) * vsi->num_q_vectors; | |
5720 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); | |
5721 | if (!vsi->q_vectors) { | |
5722 | ret = -ENOMEM; | |
5723 | goto err_vectors; | |
5724 | } | |
f650a38b ASJ |
5725 | } |
5726 | return ret; | |
5727 | ||
5728 | err_vectors: | |
5729 | kfree(vsi->tx_rings); | |
5730 | return ret; | |
5731 | } | |
5732 | ||
41c445ff JB |
5733 | /** |
5734 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF | |
5735 | * @pf: board private structure | |
5736 | * @type: type of VSI | |
5737 | * | |
5738 | * On error: returns error code (negative) | |
5739 | * On success: returns vsi index in PF (positive) | |
5740 | **/ | |
5741 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) | |
5742 | { | |
5743 | int ret = -ENODEV; | |
5744 | struct i40e_vsi *vsi; | |
5745 | int vsi_idx; | |
5746 | int i; | |
5747 | ||
5748 | /* Need to protect the allocation of the VSIs at the PF level */ | |
5749 | mutex_lock(&pf->switch_mutex); | |
5750 | ||
5751 | /* VSI list may be fragmented if VSI creation/destruction has | |
5752 | * been happening. We can afford to do a quick scan to look | |
5753 | * for any free VSIs in the list. | |
5754 | * | |
5755 | * find next empty vsi slot, looping back around if necessary | |
5756 | */ | |
5757 | i = pf->next_vsi; | |
5758 | while (i < pf->hw.func_caps.num_vsis && pf->vsi[i]) | |
5759 | i++; | |
5760 | if (i >= pf->hw.func_caps.num_vsis) { | |
5761 | i = 0; | |
5762 | while (i < pf->next_vsi && pf->vsi[i]) | |
5763 | i++; | |
5764 | } | |
5765 | ||
5766 | if (i < pf->hw.func_caps.num_vsis && !pf->vsi[i]) { | |
5767 | vsi_idx = i; /* Found one! */ | |
5768 | } else { | |
5769 | ret = -ENODEV; | |
493fb300 | 5770 | goto unlock_pf; /* out of VSI slots! */ |
41c445ff JB |
5771 | } |
5772 | pf->next_vsi = ++i; | |
5773 | ||
5774 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); | |
5775 | if (!vsi) { | |
5776 | ret = -ENOMEM; | |
493fb300 | 5777 | goto unlock_pf; |
41c445ff JB |
5778 | } |
5779 | vsi->type = type; | |
5780 | vsi->back = pf; | |
5781 | set_bit(__I40E_DOWN, &vsi->state); | |
5782 | vsi->flags = 0; | |
5783 | vsi->idx = vsi_idx; | |
5784 | vsi->rx_itr_setting = pf->rx_itr_default; | |
5785 | vsi->tx_itr_setting = pf->tx_itr_default; | |
5786 | vsi->netdev_registered = false; | |
5787 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; | |
5788 | INIT_LIST_HEAD(&vsi->mac_filter_list); | |
5789 | ||
9f65e15b AD |
5790 | ret = i40e_set_num_rings_in_vsi(vsi); |
5791 | if (ret) | |
5792 | goto err_rings; | |
5793 | ||
bc7d338f | 5794 | ret = i40e_vsi_alloc_arrays(vsi, true); |
f650a38b | 5795 | if (ret) |
9f65e15b | 5796 | goto err_rings; |
493fb300 | 5797 | |
41c445ff JB |
5798 | /* Setup default MSIX irq handler for VSI */ |
5799 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); | |
5800 | ||
5801 | pf->vsi[vsi_idx] = vsi; | |
5802 | ret = vsi_idx; | |
493fb300 AD |
5803 | goto unlock_pf; |
5804 | ||
9f65e15b | 5805 | err_rings: |
493fb300 AD |
5806 | pf->next_vsi = i - 1; |
5807 | kfree(vsi); | |
5808 | unlock_pf: | |
41c445ff JB |
5809 | mutex_unlock(&pf->switch_mutex); |
5810 | return ret; | |
5811 | } | |
5812 | ||
f650a38b ASJ |
5813 | /** |
5814 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI | |
5815 | * @type: VSI pointer | |
bc7d338f | 5816 | * @free_qvectors: a bool to specify if q_vectors need to be freed. |
f650a38b ASJ |
5817 | * |
5818 | * On error: returns error code (negative) | |
5819 | * On success: returns 0 | |
5820 | **/ | |
bc7d338f | 5821 | static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors) |
f650a38b ASJ |
5822 | { |
5823 | /* free the ring and vector containers */ | |
bc7d338f ASJ |
5824 | if (free_qvectors) { |
5825 | kfree(vsi->q_vectors); | |
5826 | vsi->q_vectors = NULL; | |
5827 | } | |
f650a38b ASJ |
5828 | kfree(vsi->tx_rings); |
5829 | vsi->tx_rings = NULL; | |
5830 | vsi->rx_rings = NULL; | |
5831 | } | |
5832 | ||
41c445ff JB |
5833 | /** |
5834 | * i40e_vsi_clear - Deallocate the VSI provided | |
5835 | * @vsi: the VSI being un-configured | |
5836 | **/ | |
5837 | static int i40e_vsi_clear(struct i40e_vsi *vsi) | |
5838 | { | |
5839 | struct i40e_pf *pf; | |
5840 | ||
5841 | if (!vsi) | |
5842 | return 0; | |
5843 | ||
5844 | if (!vsi->back) | |
5845 | goto free_vsi; | |
5846 | pf = vsi->back; | |
5847 | ||
5848 | mutex_lock(&pf->switch_mutex); | |
5849 | if (!pf->vsi[vsi->idx]) { | |
5850 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", | |
5851 | vsi->idx, vsi->idx, vsi, vsi->type); | |
5852 | goto unlock_vsi; | |
5853 | } | |
5854 | ||
5855 | if (pf->vsi[vsi->idx] != vsi) { | |
5856 | dev_err(&pf->pdev->dev, | |
5857 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", | |
5858 | pf->vsi[vsi->idx]->idx, | |
5859 | pf->vsi[vsi->idx], | |
5860 | pf->vsi[vsi->idx]->type, | |
5861 | vsi->idx, vsi, vsi->type); | |
5862 | goto unlock_vsi; | |
5863 | } | |
5864 | ||
5865 | /* updates the pf for this cleared vsi */ | |
5866 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); | |
5867 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); | |
5868 | ||
bc7d338f | 5869 | i40e_vsi_free_arrays(vsi, true); |
493fb300 | 5870 | |
41c445ff JB |
5871 | pf->vsi[vsi->idx] = NULL; |
5872 | if (vsi->idx < pf->next_vsi) | |
5873 | pf->next_vsi = vsi->idx; | |
5874 | ||
5875 | unlock_vsi: | |
5876 | mutex_unlock(&pf->switch_mutex); | |
5877 | free_vsi: | |
5878 | kfree(vsi); | |
5879 | ||
5880 | return 0; | |
5881 | } | |
5882 | ||
9f65e15b AD |
5883 | /** |
5884 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI | |
5885 | * @vsi: the VSI being cleaned | |
5886 | **/ | |
be1d5eea | 5887 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
9f65e15b AD |
5888 | { |
5889 | int i; | |
5890 | ||
8e9dca53 | 5891 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
d7397644 | 5892 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
00403f04 MW |
5893 | kfree_rcu(vsi->tx_rings[i], rcu); |
5894 | vsi->tx_rings[i] = NULL; | |
5895 | vsi->rx_rings[i] = NULL; | |
5896 | } | |
be1d5eea | 5897 | } |
9f65e15b AD |
5898 | } |
5899 | ||
41c445ff JB |
5900 | /** |
5901 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI | |
5902 | * @vsi: the VSI being configured | |
5903 | **/ | |
5904 | static int i40e_alloc_rings(struct i40e_vsi *vsi) | |
5905 | { | |
5906 | struct i40e_pf *pf = vsi->back; | |
41c445ff JB |
5907 | int i; |
5908 | ||
41c445ff | 5909 | /* Set basic values in the rings to be used later during open() */ |
d7397644 | 5910 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
9f65e15b AD |
5911 | struct i40e_ring *tx_ring; |
5912 | struct i40e_ring *rx_ring; | |
5913 | ||
ac6c5e3d | 5914 | /* allocate space for both Tx and Rx in one shot */ |
9f65e15b AD |
5915 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
5916 | if (!tx_ring) | |
5917 | goto err_out; | |
41c445ff JB |
5918 | |
5919 | tx_ring->queue_index = i; | |
5920 | tx_ring->reg_idx = vsi->base_queue + i; | |
5921 | tx_ring->ring_active = false; | |
5922 | tx_ring->vsi = vsi; | |
5923 | tx_ring->netdev = vsi->netdev; | |
5924 | tx_ring->dev = &pf->pdev->dev; | |
5925 | tx_ring->count = vsi->num_desc; | |
5926 | tx_ring->size = 0; | |
5927 | tx_ring->dcb_tc = 0; | |
9f65e15b | 5928 | vsi->tx_rings[i] = tx_ring; |
41c445ff | 5929 | |
9f65e15b | 5930 | rx_ring = &tx_ring[1]; |
41c445ff JB |
5931 | rx_ring->queue_index = i; |
5932 | rx_ring->reg_idx = vsi->base_queue + i; | |
5933 | rx_ring->ring_active = false; | |
5934 | rx_ring->vsi = vsi; | |
5935 | rx_ring->netdev = vsi->netdev; | |
5936 | rx_ring->dev = &pf->pdev->dev; | |
5937 | rx_ring->count = vsi->num_desc; | |
5938 | rx_ring->size = 0; | |
5939 | rx_ring->dcb_tc = 0; | |
5940 | if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) | |
5941 | set_ring_16byte_desc_enabled(rx_ring); | |
5942 | else | |
5943 | clear_ring_16byte_desc_enabled(rx_ring); | |
9f65e15b | 5944 | vsi->rx_rings[i] = rx_ring; |
41c445ff JB |
5945 | } |
5946 | ||
5947 | return 0; | |
9f65e15b AD |
5948 | |
5949 | err_out: | |
5950 | i40e_vsi_clear_rings(vsi); | |
5951 | return -ENOMEM; | |
41c445ff JB |
5952 | } |
5953 | ||
5954 | /** | |
5955 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel | |
5956 | * @pf: board private structure | |
5957 | * @vectors: the number of MSI-X vectors to request | |
5958 | * | |
5959 | * Returns the number of vectors reserved, or error | |
5960 | **/ | |
5961 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) | |
5962 | { | |
7b37f376 AG |
5963 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
5964 | I40E_MIN_MSIX, vectors); | |
5965 | if (vectors < 0) { | |
41c445ff | 5966 | dev_info(&pf->pdev->dev, |
7b37f376 | 5967 | "MSI-X vector reservation failed: %d\n", vectors); |
41c445ff JB |
5968 | vectors = 0; |
5969 | } | |
5970 | ||
7b37f376 AG |
5971 | pf->num_msix_entries = vectors; |
5972 | ||
41c445ff JB |
5973 | return vectors; |
5974 | } | |
5975 | ||
5976 | /** | |
5977 | * i40e_init_msix - Setup the MSIX capability | |
5978 | * @pf: board private structure | |
5979 | * | |
5980 | * Work with the OS to set up the MSIX vectors needed. | |
5981 | * | |
5982 | * Returns 0 on success, negative on failure | |
5983 | **/ | |
5984 | static int i40e_init_msix(struct i40e_pf *pf) | |
5985 | { | |
5986 | i40e_status err = 0; | |
5987 | struct i40e_hw *hw = &pf->hw; | |
5988 | int v_budget, i; | |
5989 | int vec; | |
5990 | ||
5991 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) | |
5992 | return -ENODEV; | |
5993 | ||
5994 | /* The number of vectors we'll request will be comprised of: | |
5995 | * - Add 1 for "other" cause for Admin Queue events, etc. | |
5996 | * - The number of LAN queue pairs | |
f8ff1464 ASJ |
5997 | * - Queues being used for RSS. |
5998 | * We don't need as many as max_rss_size vectors. | |
5999 | * use rss_size instead in the calculation since that | |
6000 | * is governed by number of cpus in the system. | |
6001 | * - assumes symmetric Tx/Rx pairing | |
41c445ff JB |
6002 | * - The number of VMDq pairs |
6003 | * Once we count this up, try the request. | |
6004 | * | |
6005 | * If we can't get what we want, we'll simplify to nearly nothing | |
6006 | * and try again. If that still fails, we punt. | |
6007 | */ | |
f8ff1464 | 6008 | pf->num_lan_msix = pf->num_lan_qps - (pf->rss_size_max - pf->rss_size); |
41c445ff JB |
6009 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
6010 | v_budget = 1 + pf->num_lan_msix; | |
6011 | v_budget += (pf->num_vmdq_vsis * pf->num_vmdq_msix); | |
60ea5f83 | 6012 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) |
41c445ff JB |
6013 | v_budget++; |
6014 | ||
6015 | /* Scale down if necessary, and the rings will share vectors */ | |
6016 | v_budget = min_t(int, v_budget, hw->func_caps.num_msix_vectors); | |
6017 | ||
6018 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), | |
6019 | GFP_KERNEL); | |
6020 | if (!pf->msix_entries) | |
6021 | return -ENOMEM; | |
6022 | ||
6023 | for (i = 0; i < v_budget; i++) | |
6024 | pf->msix_entries[i].entry = i; | |
6025 | vec = i40e_reserve_msix_vectors(pf, v_budget); | |
6026 | if (vec < I40E_MIN_MSIX) { | |
6027 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; | |
6028 | kfree(pf->msix_entries); | |
6029 | pf->msix_entries = NULL; | |
6030 | return -ENODEV; | |
6031 | ||
6032 | } else if (vec == I40E_MIN_MSIX) { | |
6033 | /* Adjust for minimal MSIX use */ | |
77fa28be | 6034 | dev_info(&pf->pdev->dev, "Features disabled, not enough MSI-X vectors\n"); |
41c445ff JB |
6035 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
6036 | pf->num_vmdq_vsis = 0; | |
6037 | pf->num_vmdq_qps = 0; | |
6038 | pf->num_vmdq_msix = 0; | |
6039 | pf->num_lan_qps = 1; | |
6040 | pf->num_lan_msix = 1; | |
6041 | ||
6042 | } else if (vec != v_budget) { | |
6043 | /* Scale vector usage down */ | |
6044 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ | |
6045 | vec--; /* reserve the misc vector */ | |
6046 | ||
6047 | /* partition out the remaining vectors */ | |
6048 | switch (vec) { | |
6049 | case 2: | |
6050 | pf->num_vmdq_vsis = 1; | |
6051 | pf->num_lan_msix = 1; | |
6052 | break; | |
6053 | case 3: | |
6054 | pf->num_vmdq_vsis = 1; | |
6055 | pf->num_lan_msix = 2; | |
6056 | break; | |
6057 | default: | |
6058 | pf->num_lan_msix = min_t(int, (vec / 2), | |
6059 | pf->num_lan_qps); | |
6060 | pf->num_vmdq_vsis = min_t(int, (vec - pf->num_lan_msix), | |
6061 | I40E_DEFAULT_NUM_VMDQ_VSI); | |
6062 | break; | |
6063 | } | |
6064 | } | |
6065 | ||
6066 | return err; | |
6067 | } | |
6068 | ||
493fb300 AD |
6069 | /** |
6070 | * i40e_alloc_q_vector - Allocate memory for a single interrupt vector | |
6071 | * @vsi: the VSI being configured | |
6072 | * @v_idx: index of the vector in the vsi struct | |
6073 | * | |
6074 | * We allocate one q_vector. If allocation fails we return -ENOMEM. | |
6075 | **/ | |
6076 | static int i40e_alloc_q_vector(struct i40e_vsi *vsi, int v_idx) | |
6077 | { | |
6078 | struct i40e_q_vector *q_vector; | |
6079 | ||
6080 | /* allocate q_vector */ | |
6081 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); | |
6082 | if (!q_vector) | |
6083 | return -ENOMEM; | |
6084 | ||
6085 | q_vector->vsi = vsi; | |
6086 | q_vector->v_idx = v_idx; | |
6087 | cpumask_set_cpu(v_idx, &q_vector->affinity_mask); | |
6088 | if (vsi->netdev) | |
6089 | netif_napi_add(vsi->netdev, &q_vector->napi, | |
6090 | i40e_napi_poll, vsi->work_limit); | |
6091 | ||
cd0b6fa6 AD |
6092 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
6093 | q_vector->tx.latency_range = I40E_LOW_LATENCY; | |
6094 | ||
493fb300 AD |
6095 | /* tie q_vector and vsi together */ |
6096 | vsi->q_vectors[v_idx] = q_vector; | |
6097 | ||
6098 | return 0; | |
6099 | } | |
6100 | ||
41c445ff JB |
6101 | /** |
6102 | * i40e_alloc_q_vectors - Allocate memory for interrupt vectors | |
6103 | * @vsi: the VSI being configured | |
6104 | * | |
6105 | * We allocate one q_vector per queue interrupt. If allocation fails we | |
6106 | * return -ENOMEM. | |
6107 | **/ | |
6108 | static int i40e_alloc_q_vectors(struct i40e_vsi *vsi) | |
6109 | { | |
6110 | struct i40e_pf *pf = vsi->back; | |
6111 | int v_idx, num_q_vectors; | |
493fb300 | 6112 | int err; |
41c445ff JB |
6113 | |
6114 | /* if not MSIX, give the one vector only to the LAN VSI */ | |
6115 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) | |
6116 | num_q_vectors = vsi->num_q_vectors; | |
6117 | else if (vsi == pf->vsi[pf->lan_vsi]) | |
6118 | num_q_vectors = 1; | |
6119 | else | |
6120 | return -EINVAL; | |
6121 | ||
41c445ff | 6122 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
493fb300 AD |
6123 | err = i40e_alloc_q_vector(vsi, v_idx); |
6124 | if (err) | |
6125 | goto err_out; | |
41c445ff JB |
6126 | } |
6127 | ||
6128 | return 0; | |
493fb300 AD |
6129 | |
6130 | err_out: | |
6131 | while (v_idx--) | |
6132 | i40e_free_q_vector(vsi, v_idx); | |
6133 | ||
6134 | return err; | |
41c445ff JB |
6135 | } |
6136 | ||
6137 | /** | |
6138 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme | |
6139 | * @pf: board private structure to initialize | |
6140 | **/ | |
6141 | static void i40e_init_interrupt_scheme(struct i40e_pf *pf) | |
6142 | { | |
6143 | int err = 0; | |
6144 | ||
6145 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | |
6146 | err = i40e_init_msix(pf); | |
6147 | if (err) { | |
60ea5f83 JB |
6148 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
6149 | I40E_FLAG_RSS_ENABLED | | |
6150 | I40E_FLAG_DCB_ENABLED | | |
6151 | I40E_FLAG_SRIOV_ENABLED | | |
6152 | I40E_FLAG_FD_SB_ENABLED | | |
6153 | I40E_FLAG_FD_ATR_ENABLED | | |
6154 | I40E_FLAG_VMDQ_ENABLED); | |
41c445ff JB |
6155 | |
6156 | /* rework the queue expectations without MSIX */ | |
6157 | i40e_determine_queue_usage(pf); | |
6158 | } | |
6159 | } | |
6160 | ||
6161 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && | |
6162 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { | |
77fa28be | 6163 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
41c445ff JB |
6164 | err = pci_enable_msi(pf->pdev); |
6165 | if (err) { | |
958a3e3b | 6166 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", err); |
41c445ff JB |
6167 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
6168 | } | |
6169 | } | |
6170 | ||
958a3e3b | 6171 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
77fa28be | 6172 | dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n"); |
958a3e3b | 6173 | |
41c445ff JB |
6174 | /* track first vector for misc interrupts */ |
6175 | err = i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT-1); | |
6176 | } | |
6177 | ||
6178 | /** | |
6179 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events | |
6180 | * @pf: board private structure | |
6181 | * | |
6182 | * This sets up the handler for MSIX 0, which is used to manage the | |
6183 | * non-queue interrupts, e.g. AdminQ and errors. This is not used | |
6184 | * when in MSI or Legacy interrupt mode. | |
6185 | **/ | |
6186 | static int i40e_setup_misc_vector(struct i40e_pf *pf) | |
6187 | { | |
6188 | struct i40e_hw *hw = &pf->hw; | |
6189 | int err = 0; | |
6190 | ||
6191 | /* Only request the irq if this is the first time through, and | |
6192 | * not when we're rebuilding after a Reset | |
6193 | */ | |
6194 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { | |
6195 | err = request_irq(pf->msix_entries[0].vector, | |
6196 | i40e_intr, 0, pf->misc_int_name, pf); | |
6197 | if (err) { | |
6198 | dev_info(&pf->pdev->dev, | |
77fa28be CS |
6199 | "request_irq for %s failed: %d\n", |
6200 | pf->misc_int_name, err); | |
41c445ff JB |
6201 | return -EFAULT; |
6202 | } | |
6203 | } | |
6204 | ||
6205 | i40e_enable_misc_int_causes(hw); | |
6206 | ||
6207 | /* associate no queues to the misc vector */ | |
6208 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); | |
6209 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); | |
6210 | ||
6211 | i40e_flush(hw); | |
6212 | ||
6213 | i40e_irq_dynamic_enable_icr0(pf); | |
6214 | ||
6215 | return err; | |
6216 | } | |
6217 | ||
6218 | /** | |
6219 | * i40e_config_rss - Prepare for RSS if used | |
6220 | * @pf: board private structure | |
6221 | **/ | |
6222 | static int i40e_config_rss(struct i40e_pf *pf) | |
6223 | { | |
41c445ff JB |
6224 | /* Set of random keys generated using kernel random number generator */ |
6225 | static const u32 seed[I40E_PFQF_HKEY_MAX_INDEX + 1] = {0x41b01687, | |
6226 | 0x183cfd8c, 0xce880440, 0x580cbc3c, 0x35897377, | |
6227 | 0x328b25e1, 0x4fa98922, 0xb7d90c14, 0xd5bad70d, | |
6228 | 0xcd15a2c1, 0xe8580225, 0x4a1e9d11, 0xfe5731be}; | |
4617e8c0 ASJ |
6229 | struct i40e_hw *hw = &pf->hw; |
6230 | u32 lut = 0; | |
6231 | int i, j; | |
6232 | u64 hena; | |
41c445ff JB |
6233 | |
6234 | /* Fill out hash function seed */ | |
6235 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) | |
6236 | wr32(hw, I40E_PFQF_HKEY(i), seed[i]); | |
6237 | ||
6238 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ | |
6239 | hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) | | |
6240 | ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32); | |
12dc4fe3 | 6241 | hena |= I40E_DEFAULT_RSS_HENA; |
41c445ff JB |
6242 | wr32(hw, I40E_PFQF_HENA(0), (u32)hena); |
6243 | wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); | |
6244 | ||
6245 | /* Populate the LUT with max no. of queues in round robin fashion */ | |
6246 | for (i = 0, j = 0; i < pf->hw.func_caps.rss_table_size; i++, j++) { | |
6247 | ||
6248 | /* The assumption is that lan qp count will be the highest | |
6249 | * qp count for any PF VSI that needs RSS. | |
6250 | * If multiple VSIs need RSS support, all the qp counts | |
6251 | * for those VSIs should be a power of 2 for RSS to work. | |
6252 | * If LAN VSI is the only consumer for RSS then this requirement | |
6253 | * is not necessary. | |
6254 | */ | |
6255 | if (j == pf->rss_size) | |
6256 | j = 0; | |
6257 | /* lut = 4-byte sliding window of 4 lut entries */ | |
6258 | lut = (lut << 8) | (j & | |
6259 | ((0x1 << pf->hw.func_caps.rss_table_entry_width) - 1)); | |
6260 | /* On i = 3, we have 4 entries in lut; write to the register */ | |
6261 | if ((i & 3) == 3) | |
6262 | wr32(hw, I40E_PFQF_HLUT(i >> 2), lut); | |
6263 | } | |
6264 | i40e_flush(hw); | |
6265 | ||
6266 | return 0; | |
6267 | } | |
6268 | ||
f8ff1464 ASJ |
6269 | /** |
6270 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild | |
6271 | * @pf: board private structure | |
6272 | * @queue_count: the requested queue count for rss. | |
6273 | * | |
6274 | * returns 0 if rss is not enabled, if enabled returns the final rss queue | |
6275 | * count which may be different from the requested queue count. | |
6276 | **/ | |
6277 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) | |
6278 | { | |
6279 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) | |
6280 | return 0; | |
6281 | ||
6282 | queue_count = min_t(int, queue_count, pf->rss_size_max); | |
6283 | queue_count = rounddown_pow_of_two(queue_count); | |
6284 | ||
6285 | if (queue_count != pf->rss_size) { | |
f8ff1464 ASJ |
6286 | i40e_prep_for_reset(pf); |
6287 | ||
f8ff1464 ASJ |
6288 | pf->rss_size = queue_count; |
6289 | ||
6290 | i40e_reset_and_rebuild(pf, true); | |
6291 | i40e_config_rss(pf); | |
6292 | } | |
6293 | dev_info(&pf->pdev->dev, "RSS count: %d\n", pf->rss_size); | |
6294 | return pf->rss_size; | |
6295 | } | |
6296 | ||
41c445ff JB |
6297 | /** |
6298 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) | |
6299 | * @pf: board private structure to initialize | |
6300 | * | |
6301 | * i40e_sw_init initializes the Adapter private data structure. | |
6302 | * Fields are initialized based on PCI device information and | |
6303 | * OS network device settings (MTU size). | |
6304 | **/ | |
6305 | static int i40e_sw_init(struct i40e_pf *pf) | |
6306 | { | |
6307 | int err = 0; | |
6308 | int size; | |
6309 | ||
6310 | pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE, | |
6311 | (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)); | |
2759997b | 6312 | pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG; |
41c445ff JB |
6313 | if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) { |
6314 | if (I40E_DEBUG_USER & debug) | |
6315 | pf->hw.debug_mask = debug; | |
6316 | pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER), | |
6317 | I40E_DEFAULT_MSG_ENABLE); | |
6318 | } | |
6319 | ||
6320 | /* Set default capability flags */ | |
6321 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | | |
6322 | I40E_FLAG_MSI_ENABLED | | |
6323 | I40E_FLAG_MSIX_ENABLED | | |
41c445ff JB |
6324 | I40E_FLAG_RX_1BUF_ENABLED; |
6325 | ||
7134f9ce JB |
6326 | /* Depending on PF configurations, it is possible that the RSS |
6327 | * maximum might end up larger than the available queues | |
6328 | */ | |
41c445ff | 6329 | pf->rss_size_max = 0x1 << pf->hw.func_caps.rss_table_entry_width; |
7134f9ce JB |
6330 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
6331 | pf->hw.func_caps.num_tx_qp); | |
41c445ff JB |
6332 | if (pf->hw.func_caps.rss) { |
6333 | pf->flags |= I40E_FLAG_RSS_ENABLED; | |
bf051a3b | 6334 | pf->rss_size = min_t(int, pf->rss_size_max, num_online_cpus()); |
cbf61325 | 6335 | pf->rss_size = rounddown_pow_of_two(pf->rss_size); |
41c445ff JB |
6336 | } else { |
6337 | pf->rss_size = 1; | |
6338 | } | |
6339 | ||
2050bc65 CS |
6340 | /* MFP mode enabled */ |
6341 | if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.mfp_mode_1) { | |
6342 | pf->flags |= I40E_FLAG_MFP_ENABLED; | |
6343 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); | |
6344 | } | |
6345 | ||
cbf61325 ASJ |
6346 | /* FW/NVM is not yet fixed in this regard */ |
6347 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || | |
6348 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { | |
6349 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; | |
6350 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; | |
cbf61325 | 6351 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
60ea5f83 | 6352 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
cbf61325 ASJ |
6353 | } else { |
6354 | dev_info(&pf->pdev->dev, | |
6355 | "Flow Director Side Band mode Disabled in MFP mode\n"); | |
41c445ff | 6356 | } |
cbf61325 ASJ |
6357 | pf->fdir_pf_filter_count = |
6358 | pf->hw.func_caps.fd_filters_guaranteed; | |
6359 | pf->hw.fdir_shared_filter_count = | |
6360 | pf->hw.func_caps.fd_filters_best_effort; | |
41c445ff JB |
6361 | } |
6362 | ||
6363 | if (pf->hw.func_caps.vmdq) { | |
6364 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; | |
6365 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; | |
6366 | pf->num_vmdq_qps = I40E_DEFAULT_QUEUES_PER_VMDQ; | |
6367 | } | |
6368 | ||
41c445ff JB |
6369 | #ifdef CONFIG_PCI_IOV |
6370 | if (pf->hw.func_caps.num_vfs) { | |
6371 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; | |
6372 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; | |
6373 | pf->num_req_vfs = min_t(int, | |
6374 | pf->hw.func_caps.num_vfs, | |
6375 | I40E_MAX_VF_COUNT); | |
6376 | } | |
6377 | #endif /* CONFIG_PCI_IOV */ | |
6378 | pf->eeprom_version = 0xDEAD; | |
6379 | pf->lan_veb = I40E_NO_VEB; | |
6380 | pf->lan_vsi = I40E_NO_VSI; | |
6381 | ||
6382 | /* set up queue assignment tracking */ | |
6383 | size = sizeof(struct i40e_lump_tracking) | |
6384 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); | |
6385 | pf->qp_pile = kzalloc(size, GFP_KERNEL); | |
6386 | if (!pf->qp_pile) { | |
6387 | err = -ENOMEM; | |
6388 | goto sw_init_done; | |
6389 | } | |
6390 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; | |
6391 | pf->qp_pile->search_hint = 0; | |
6392 | ||
6393 | /* set up vector assignment tracking */ | |
6394 | size = sizeof(struct i40e_lump_tracking) | |
6395 | + (sizeof(u16) * pf->hw.func_caps.num_msix_vectors); | |
6396 | pf->irq_pile = kzalloc(size, GFP_KERNEL); | |
6397 | if (!pf->irq_pile) { | |
6398 | kfree(pf->qp_pile); | |
6399 | err = -ENOMEM; | |
6400 | goto sw_init_done; | |
6401 | } | |
6402 | pf->irq_pile->num_entries = pf->hw.func_caps.num_msix_vectors; | |
6403 | pf->irq_pile->search_hint = 0; | |
6404 | ||
6405 | mutex_init(&pf->switch_mutex); | |
6406 | ||
6407 | sw_init_done: | |
6408 | return err; | |
6409 | } | |
6410 | ||
6411 | /** | |
6412 | * i40e_set_features - set the netdev feature flags | |
6413 | * @netdev: ptr to the netdev being adjusted | |
6414 | * @features: the feature set that the stack is suggesting | |
6415 | **/ | |
6416 | static int i40e_set_features(struct net_device *netdev, | |
6417 | netdev_features_t features) | |
6418 | { | |
6419 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
6420 | struct i40e_vsi *vsi = np->vsi; | |
6421 | ||
6422 | if (features & NETIF_F_HW_VLAN_CTAG_RX) | |
6423 | i40e_vlan_stripping_enable(vsi); | |
6424 | else | |
6425 | i40e_vlan_stripping_disable(vsi); | |
6426 | ||
6427 | return 0; | |
6428 | } | |
6429 | ||
a1c9a9d9 JK |
6430 | #ifdef CONFIG_I40E_VXLAN |
6431 | /** | |
6432 | * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port | |
6433 | * @pf: board private structure | |
6434 | * @port: The UDP port to look up | |
6435 | * | |
6436 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found | |
6437 | **/ | |
6438 | static u8 i40e_get_vxlan_port_idx(struct i40e_pf *pf, __be16 port) | |
6439 | { | |
6440 | u8 i; | |
6441 | ||
6442 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { | |
6443 | if (pf->vxlan_ports[i] == port) | |
6444 | return i; | |
6445 | } | |
6446 | ||
6447 | return i; | |
6448 | } | |
6449 | ||
6450 | /** | |
6451 | * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up | |
6452 | * @netdev: This physical port's netdev | |
6453 | * @sa_family: Socket Family that VXLAN is notifying us about | |
6454 | * @port: New UDP port number that VXLAN started listening to | |
6455 | **/ | |
6456 | static void i40e_add_vxlan_port(struct net_device *netdev, | |
6457 | sa_family_t sa_family, __be16 port) | |
6458 | { | |
6459 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
6460 | struct i40e_vsi *vsi = np->vsi; | |
6461 | struct i40e_pf *pf = vsi->back; | |
6462 | u8 next_idx; | |
6463 | u8 idx; | |
6464 | ||
6465 | if (sa_family == AF_INET6) | |
6466 | return; | |
6467 | ||
6468 | idx = i40e_get_vxlan_port_idx(pf, port); | |
6469 | ||
6470 | /* Check if port already exists */ | |
6471 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { | |
6472 | netdev_info(netdev, "Port %d already offloaded\n", ntohs(port)); | |
6473 | return; | |
6474 | } | |
6475 | ||
6476 | /* Now check if there is space to add the new port */ | |
6477 | next_idx = i40e_get_vxlan_port_idx(pf, 0); | |
6478 | ||
6479 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { | |
6480 | netdev_info(netdev, "Maximum number of UDP ports reached, not adding port %d\n", | |
6481 | ntohs(port)); | |
6482 | return; | |
6483 | } | |
6484 | ||
6485 | /* New port: add it and mark its index in the bitmap */ | |
6486 | pf->vxlan_ports[next_idx] = port; | |
6487 | pf->pending_vxlan_bitmap |= (1 << next_idx); | |
6488 | ||
6489 | pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC; | |
6490 | } | |
6491 | ||
6492 | /** | |
6493 | * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away | |
6494 | * @netdev: This physical port's netdev | |
6495 | * @sa_family: Socket Family that VXLAN is notifying us about | |
6496 | * @port: UDP port number that VXLAN stopped listening to | |
6497 | **/ | |
6498 | static void i40e_del_vxlan_port(struct net_device *netdev, | |
6499 | sa_family_t sa_family, __be16 port) | |
6500 | { | |
6501 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
6502 | struct i40e_vsi *vsi = np->vsi; | |
6503 | struct i40e_pf *pf = vsi->back; | |
6504 | u8 idx; | |
6505 | ||
6506 | if (sa_family == AF_INET6) | |
6507 | return; | |
6508 | ||
6509 | idx = i40e_get_vxlan_port_idx(pf, port); | |
6510 | ||
6511 | /* Check if port already exists */ | |
6512 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { | |
6513 | /* if port exists, set it to 0 (mark for deletion) | |
6514 | * and make it pending | |
6515 | */ | |
6516 | pf->vxlan_ports[idx] = 0; | |
6517 | ||
6518 | pf->pending_vxlan_bitmap |= (1 << idx); | |
6519 | ||
6520 | pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC; | |
6521 | } else { | |
6522 | netdev_warn(netdev, "Port %d was not found, not deleting\n", | |
6523 | ntohs(port)); | |
6524 | } | |
6525 | } | |
6526 | ||
6527 | #endif | |
41c445ff JB |
6528 | static const struct net_device_ops i40e_netdev_ops = { |
6529 | .ndo_open = i40e_open, | |
6530 | .ndo_stop = i40e_close, | |
6531 | .ndo_start_xmit = i40e_lan_xmit_frame, | |
6532 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, | |
6533 | .ndo_set_rx_mode = i40e_set_rx_mode, | |
6534 | .ndo_validate_addr = eth_validate_addr, | |
6535 | .ndo_set_mac_address = i40e_set_mac, | |
6536 | .ndo_change_mtu = i40e_change_mtu, | |
beb0dff1 | 6537 | .ndo_do_ioctl = i40e_ioctl, |
41c445ff JB |
6538 | .ndo_tx_timeout = i40e_tx_timeout, |
6539 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, | |
6540 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, | |
6541 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
6542 | .ndo_poll_controller = i40e_netpoll, | |
6543 | #endif | |
6544 | .ndo_setup_tc = i40e_setup_tc, | |
6545 | .ndo_set_features = i40e_set_features, | |
6546 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, | |
6547 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, | |
6548 | .ndo_set_vf_tx_rate = i40e_ndo_set_vf_bw, | |
6549 | .ndo_get_vf_config = i40e_ndo_get_vf_config, | |
588aefa0 | 6550 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
a1c9a9d9 JK |
6551 | #ifdef CONFIG_I40E_VXLAN |
6552 | .ndo_add_vxlan_port = i40e_add_vxlan_port, | |
6553 | .ndo_del_vxlan_port = i40e_del_vxlan_port, | |
6554 | #endif | |
41c445ff JB |
6555 | }; |
6556 | ||
6557 | /** | |
6558 | * i40e_config_netdev - Setup the netdev flags | |
6559 | * @vsi: the VSI being configured | |
6560 | * | |
6561 | * Returns 0 on success, negative value on failure | |
6562 | **/ | |
6563 | static int i40e_config_netdev(struct i40e_vsi *vsi) | |
6564 | { | |
1a10370a | 6565 | u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
41c445ff JB |
6566 | struct i40e_pf *pf = vsi->back; |
6567 | struct i40e_hw *hw = &pf->hw; | |
6568 | struct i40e_netdev_priv *np; | |
6569 | struct net_device *netdev; | |
6570 | u8 mac_addr[ETH_ALEN]; | |
6571 | int etherdev_size; | |
6572 | ||
6573 | etherdev_size = sizeof(struct i40e_netdev_priv); | |
f8ff1464 | 6574 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
41c445ff JB |
6575 | if (!netdev) |
6576 | return -ENOMEM; | |
6577 | ||
6578 | vsi->netdev = netdev; | |
6579 | np = netdev_priv(netdev); | |
6580 | np->vsi = vsi; | |
6581 | ||
d70e941b | 6582 | netdev->hw_enc_features |= NETIF_F_IP_CSUM | |
41c445ff | 6583 | NETIF_F_GSO_UDP_TUNNEL | |
d70e941b | 6584 | NETIF_F_TSO; |
41c445ff JB |
6585 | |
6586 | netdev->features = NETIF_F_SG | | |
6587 | NETIF_F_IP_CSUM | | |
6588 | NETIF_F_SCTP_CSUM | | |
6589 | NETIF_F_HIGHDMA | | |
6590 | NETIF_F_GSO_UDP_TUNNEL | | |
6591 | NETIF_F_HW_VLAN_CTAG_TX | | |
6592 | NETIF_F_HW_VLAN_CTAG_RX | | |
6593 | NETIF_F_HW_VLAN_CTAG_FILTER | | |
6594 | NETIF_F_IPV6_CSUM | | |
6595 | NETIF_F_TSO | | |
6596 | NETIF_F_TSO6 | | |
6597 | NETIF_F_RXCSUM | | |
6598 | NETIF_F_RXHASH | | |
6599 | 0; | |
6600 | ||
6601 | /* copy netdev features into list of user selectable features */ | |
6602 | netdev->hw_features |= netdev->features; | |
6603 | ||
6604 | if (vsi->type == I40E_VSI_MAIN) { | |
6605 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); | |
6606 | memcpy(mac_addr, hw->mac.perm_addr, ETH_ALEN); | |
6607 | } else { | |
6608 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ | |
6609 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", | |
6610 | pf->vsi[pf->lan_vsi]->netdev->name); | |
6611 | random_ether_addr(mac_addr); | |
6612 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false); | |
6613 | } | |
1a10370a | 6614 | i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false); |
41c445ff JB |
6615 | |
6616 | memcpy(netdev->dev_addr, mac_addr, ETH_ALEN); | |
6617 | memcpy(netdev->perm_addr, mac_addr, ETH_ALEN); | |
6618 | /* vlan gets same features (except vlan offload) | |
6619 | * after any tweaks for specific VSI types | |
6620 | */ | |
6621 | netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX | | |
6622 | NETIF_F_HW_VLAN_CTAG_RX | | |
6623 | NETIF_F_HW_VLAN_CTAG_FILTER); | |
6624 | netdev->priv_flags |= IFF_UNICAST_FLT; | |
6625 | netdev->priv_flags |= IFF_SUPP_NOFCS; | |
6626 | /* Setup netdev TC information */ | |
6627 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); | |
6628 | ||
6629 | netdev->netdev_ops = &i40e_netdev_ops; | |
6630 | netdev->watchdog_timeo = 5 * HZ; | |
6631 | i40e_set_ethtool_ops(netdev); | |
6632 | ||
6633 | return 0; | |
6634 | } | |
6635 | ||
6636 | /** | |
6637 | * i40e_vsi_delete - Delete a VSI from the switch | |
6638 | * @vsi: the VSI being removed | |
6639 | * | |
6640 | * Returns 0 on success, negative value on failure | |
6641 | **/ | |
6642 | static void i40e_vsi_delete(struct i40e_vsi *vsi) | |
6643 | { | |
6644 | /* remove default VSI is not allowed */ | |
6645 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) | |
6646 | return; | |
6647 | ||
41c445ff JB |
6648 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
6649 | return; | |
6650 | } | |
6651 | ||
6652 | /** | |
6653 | * i40e_add_vsi - Add a VSI to the switch | |
6654 | * @vsi: the VSI being configured | |
6655 | * | |
6656 | * This initializes a VSI context depending on the VSI type to be added and | |
6657 | * passes it down to the add_vsi aq command. | |
6658 | **/ | |
6659 | static int i40e_add_vsi(struct i40e_vsi *vsi) | |
6660 | { | |
6661 | int ret = -ENODEV; | |
6662 | struct i40e_mac_filter *f, *ftmp; | |
6663 | struct i40e_pf *pf = vsi->back; | |
6664 | struct i40e_hw *hw = &pf->hw; | |
6665 | struct i40e_vsi_context ctxt; | |
6666 | u8 enabled_tc = 0x1; /* TC0 enabled */ | |
6667 | int f_count = 0; | |
6668 | ||
6669 | memset(&ctxt, 0, sizeof(ctxt)); | |
6670 | switch (vsi->type) { | |
6671 | case I40E_VSI_MAIN: | |
6672 | /* The PF's main VSI is already setup as part of the | |
6673 | * device initialization, so we'll not bother with | |
6674 | * the add_vsi call, but we will retrieve the current | |
6675 | * VSI context. | |
6676 | */ | |
6677 | ctxt.seid = pf->main_vsi_seid; | |
6678 | ctxt.pf_num = pf->hw.pf_id; | |
6679 | ctxt.vf_num = 0; | |
6680 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); | |
6681 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; | |
6682 | if (ret) { | |
6683 | dev_info(&pf->pdev->dev, | |
6684 | "couldn't get pf vsi config, err %d, aq_err %d\n", | |
6685 | ret, pf->hw.aq.asq_last_status); | |
6686 | return -ENOENT; | |
6687 | } | |
6688 | memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info)); | |
6689 | vsi->info.valid_sections = 0; | |
6690 | ||
6691 | vsi->seid = ctxt.seid; | |
6692 | vsi->id = ctxt.vsi_number; | |
6693 | ||
6694 | enabled_tc = i40e_pf_get_tc_map(pf); | |
6695 | ||
6696 | /* MFP mode setup queue map and update VSI */ | |
6697 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { | |
6698 | memset(&ctxt, 0, sizeof(ctxt)); | |
6699 | ctxt.seid = pf->main_vsi_seid; | |
6700 | ctxt.pf_num = pf->hw.pf_id; | |
6701 | ctxt.vf_num = 0; | |
6702 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); | |
6703 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); | |
6704 | if (ret) { | |
6705 | dev_info(&pf->pdev->dev, | |
6706 | "update vsi failed, aq_err=%d\n", | |
6707 | pf->hw.aq.asq_last_status); | |
6708 | ret = -ENOENT; | |
6709 | goto err; | |
6710 | } | |
6711 | /* update the local VSI info queue map */ | |
6712 | i40e_vsi_update_queue_map(vsi, &ctxt); | |
6713 | vsi->info.valid_sections = 0; | |
6714 | } else { | |
6715 | /* Default/Main VSI is only enabled for TC0 | |
6716 | * reconfigure it to enable all TCs that are | |
6717 | * available on the port in SFP mode. | |
6718 | */ | |
6719 | ret = i40e_vsi_config_tc(vsi, enabled_tc); | |
6720 | if (ret) { | |
6721 | dev_info(&pf->pdev->dev, | |
6722 | "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n", | |
6723 | enabled_tc, ret, | |
6724 | pf->hw.aq.asq_last_status); | |
6725 | ret = -ENOENT; | |
6726 | } | |
6727 | } | |
6728 | break; | |
6729 | ||
6730 | case I40E_VSI_FDIR: | |
cbf61325 ASJ |
6731 | ctxt.pf_num = hw->pf_id; |
6732 | ctxt.vf_num = 0; | |
6733 | ctxt.uplink_seid = vsi->uplink_seid; | |
6734 | ctxt.connection_type = 0x1; /* regular data port */ | |
6735 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; | |
41c445ff | 6736 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
41c445ff JB |
6737 | break; |
6738 | ||
6739 | case I40E_VSI_VMDQ2: | |
6740 | ctxt.pf_num = hw->pf_id; | |
6741 | ctxt.vf_num = 0; | |
6742 | ctxt.uplink_seid = vsi->uplink_seid; | |
6743 | ctxt.connection_type = 0x1; /* regular data port */ | |
6744 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; | |
6745 | ||
6746 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); | |
6747 | ||
6748 | /* This VSI is connected to VEB so the switch_id | |
6749 | * should be set to zero by default. | |
6750 | */ | |
6751 | ctxt.info.switch_id = 0; | |
6752 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB); | |
6753 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); | |
6754 | ||
6755 | /* Setup the VSI tx/rx queue map for TC0 only for now */ | |
6756 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); | |
6757 | break; | |
6758 | ||
6759 | case I40E_VSI_SRIOV: | |
6760 | ctxt.pf_num = hw->pf_id; | |
6761 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; | |
6762 | ctxt.uplink_seid = vsi->uplink_seid; | |
6763 | ctxt.connection_type = 0x1; /* regular data port */ | |
6764 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; | |
6765 | ||
6766 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); | |
6767 | ||
6768 | /* This VSI is connected to VEB so the switch_id | |
6769 | * should be set to zero by default. | |
6770 | */ | |
6771 | ctxt.info.switch_id = cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); | |
6772 | ||
6773 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); | |
6774 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; | |
6775 | /* Setup the VSI tx/rx queue map for TC0 only for now */ | |
6776 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); | |
6777 | break; | |
6778 | ||
6779 | default: | |
6780 | return -ENODEV; | |
6781 | } | |
6782 | ||
6783 | if (vsi->type != I40E_VSI_MAIN) { | |
6784 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); | |
6785 | if (ret) { | |
6786 | dev_info(&vsi->back->pdev->dev, | |
6787 | "add vsi failed, aq_err=%d\n", | |
6788 | vsi->back->hw.aq.asq_last_status); | |
6789 | ret = -ENOENT; | |
6790 | goto err; | |
6791 | } | |
6792 | memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info)); | |
6793 | vsi->info.valid_sections = 0; | |
6794 | vsi->seid = ctxt.seid; | |
6795 | vsi->id = ctxt.vsi_number; | |
6796 | } | |
6797 | ||
6798 | /* If macvlan filters already exist, force them to get loaded */ | |
6799 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { | |
6800 | f->changed = true; | |
6801 | f_count++; | |
6802 | } | |
6803 | if (f_count) { | |
6804 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; | |
6805 | pf->flags |= I40E_FLAG_FILTER_SYNC; | |
6806 | } | |
6807 | ||
6808 | /* Update VSI BW information */ | |
6809 | ret = i40e_vsi_get_bw_info(vsi); | |
6810 | if (ret) { | |
6811 | dev_info(&pf->pdev->dev, | |
6812 | "couldn't get vsi bw info, err %d, aq_err %d\n", | |
6813 | ret, pf->hw.aq.asq_last_status); | |
6814 | /* VSI is already added so not tearing that up */ | |
6815 | ret = 0; | |
6816 | } | |
6817 | ||
6818 | err: | |
6819 | return ret; | |
6820 | } | |
6821 | ||
6822 | /** | |
6823 | * i40e_vsi_release - Delete a VSI and free its resources | |
6824 | * @vsi: the VSI being removed | |
6825 | * | |
6826 | * Returns 0 on success or < 0 on error | |
6827 | **/ | |
6828 | int i40e_vsi_release(struct i40e_vsi *vsi) | |
6829 | { | |
6830 | struct i40e_mac_filter *f, *ftmp; | |
6831 | struct i40e_veb *veb = NULL; | |
6832 | struct i40e_pf *pf; | |
6833 | u16 uplink_seid; | |
6834 | int i, n; | |
6835 | ||
6836 | pf = vsi->back; | |
6837 | ||
6838 | /* release of a VEB-owner or last VSI is not allowed */ | |
6839 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { | |
6840 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", | |
6841 | vsi->seid, vsi->uplink_seid); | |
6842 | return -ENODEV; | |
6843 | } | |
6844 | if (vsi == pf->vsi[pf->lan_vsi] && | |
6845 | !test_bit(__I40E_DOWN, &pf->state)) { | |
6846 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); | |
6847 | return -ENODEV; | |
6848 | } | |
6849 | ||
6850 | uplink_seid = vsi->uplink_seid; | |
6851 | if (vsi->type != I40E_VSI_SRIOV) { | |
6852 | if (vsi->netdev_registered) { | |
6853 | vsi->netdev_registered = false; | |
6854 | if (vsi->netdev) { | |
6855 | /* results in a call to i40e_close() */ | |
6856 | unregister_netdev(vsi->netdev); | |
41c445ff JB |
6857 | } |
6858 | } else { | |
6859 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) | |
6860 | i40e_down(vsi); | |
6861 | i40e_vsi_free_irq(vsi); | |
6862 | i40e_vsi_free_tx_resources(vsi); | |
6863 | i40e_vsi_free_rx_resources(vsi); | |
6864 | } | |
6865 | i40e_vsi_disable_irq(vsi); | |
6866 | } | |
6867 | ||
6868 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) | |
6869 | i40e_del_filter(vsi, f->macaddr, f->vlan, | |
6870 | f->is_vf, f->is_netdev); | |
6871 | i40e_sync_vsi_filters(vsi); | |
6872 | ||
6873 | i40e_vsi_delete(vsi); | |
6874 | i40e_vsi_free_q_vectors(vsi); | |
a4866597 SN |
6875 | if (vsi->netdev) { |
6876 | free_netdev(vsi->netdev); | |
6877 | vsi->netdev = NULL; | |
6878 | } | |
41c445ff JB |
6879 | i40e_vsi_clear_rings(vsi); |
6880 | i40e_vsi_clear(vsi); | |
6881 | ||
6882 | /* If this was the last thing on the VEB, except for the | |
6883 | * controlling VSI, remove the VEB, which puts the controlling | |
6884 | * VSI onto the next level down in the switch. | |
6885 | * | |
6886 | * Well, okay, there's one more exception here: don't remove | |
6887 | * the orphan VEBs yet. We'll wait for an explicit remove request | |
6888 | * from up the network stack. | |
6889 | */ | |
6890 | for (n = 0, i = 0; i < pf->hw.func_caps.num_vsis; i++) { | |
6891 | if (pf->vsi[i] && | |
6892 | pf->vsi[i]->uplink_seid == uplink_seid && | |
6893 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { | |
6894 | n++; /* count the VSIs */ | |
6895 | } | |
6896 | } | |
6897 | for (i = 0; i < I40E_MAX_VEB; i++) { | |
6898 | if (!pf->veb[i]) | |
6899 | continue; | |
6900 | if (pf->veb[i]->uplink_seid == uplink_seid) | |
6901 | n++; /* count the VEBs */ | |
6902 | if (pf->veb[i]->seid == uplink_seid) | |
6903 | veb = pf->veb[i]; | |
6904 | } | |
6905 | if (n == 0 && veb && veb->uplink_seid != 0) | |
6906 | i40e_veb_release(veb); | |
6907 | ||
6908 | return 0; | |
6909 | } | |
6910 | ||
6911 | /** | |
6912 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI | |
6913 | * @vsi: ptr to the VSI | |
6914 | * | |
6915 | * This should only be called after i40e_vsi_mem_alloc() which allocates the | |
6916 | * corresponding SW VSI structure and initializes num_queue_pairs for the | |
6917 | * newly allocated VSI. | |
6918 | * | |
6919 | * Returns 0 on success or negative on failure | |
6920 | **/ | |
6921 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) | |
6922 | { | |
6923 | int ret = -ENOENT; | |
6924 | struct i40e_pf *pf = vsi->back; | |
6925 | ||
493fb300 | 6926 | if (vsi->q_vectors[0]) { |
41c445ff JB |
6927 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
6928 | vsi->seid); | |
6929 | return -EEXIST; | |
6930 | } | |
6931 | ||
6932 | if (vsi->base_vector) { | |
f29eaa3d | 6933 | dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n", |
41c445ff JB |
6934 | vsi->seid, vsi->base_vector); |
6935 | return -EEXIST; | |
6936 | } | |
6937 | ||
6938 | ret = i40e_alloc_q_vectors(vsi); | |
6939 | if (ret) { | |
6940 | dev_info(&pf->pdev->dev, | |
6941 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", | |
6942 | vsi->num_q_vectors, vsi->seid, ret); | |
6943 | vsi->num_q_vectors = 0; | |
6944 | goto vector_setup_out; | |
6945 | } | |
6946 | ||
958a3e3b SN |
6947 | if (vsi->num_q_vectors) |
6948 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, | |
6949 | vsi->num_q_vectors, vsi->idx); | |
41c445ff JB |
6950 | if (vsi->base_vector < 0) { |
6951 | dev_info(&pf->pdev->dev, | |
f29eaa3d | 6952 | "failed to get queue tracking for VSI %d, err=%d\n", |
41c445ff JB |
6953 | vsi->seid, vsi->base_vector); |
6954 | i40e_vsi_free_q_vectors(vsi); | |
6955 | ret = -ENOENT; | |
6956 | goto vector_setup_out; | |
6957 | } | |
6958 | ||
6959 | vector_setup_out: | |
6960 | return ret; | |
6961 | } | |
6962 | ||
bc7d338f ASJ |
6963 | /** |
6964 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI | |
6965 | * @vsi: pointer to the vsi. | |
6966 | * | |
6967 | * This re-allocates a vsi's queue resources. | |
6968 | * | |
6969 | * Returns pointer to the successfully allocated and configured VSI sw struct | |
6970 | * on success, otherwise returns NULL on failure. | |
6971 | **/ | |
6972 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) | |
6973 | { | |
6974 | struct i40e_pf *pf = vsi->back; | |
6975 | u8 enabled_tc; | |
6976 | int ret; | |
6977 | ||
6978 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); | |
6979 | i40e_vsi_clear_rings(vsi); | |
6980 | ||
6981 | i40e_vsi_free_arrays(vsi, false); | |
6982 | i40e_set_num_rings_in_vsi(vsi); | |
6983 | ret = i40e_vsi_alloc_arrays(vsi, false); | |
6984 | if (ret) | |
6985 | goto err_vsi; | |
6986 | ||
6987 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); | |
6988 | if (ret < 0) { | |
6989 | dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n", | |
6990 | vsi->seid, ret); | |
6991 | goto err_vsi; | |
6992 | } | |
6993 | vsi->base_queue = ret; | |
6994 | ||
6995 | /* Update the FW view of the VSI. Force a reset of TC and queue | |
6996 | * layout configurations. | |
6997 | */ | |
6998 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; | |
6999 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; | |
7000 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; | |
7001 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); | |
7002 | ||
7003 | /* assign it some queues */ | |
7004 | ret = i40e_alloc_rings(vsi); | |
7005 | if (ret) | |
7006 | goto err_rings; | |
7007 | ||
7008 | /* map all of the rings to the q_vectors */ | |
7009 | i40e_vsi_map_rings_to_vectors(vsi); | |
7010 | return vsi; | |
7011 | ||
7012 | err_rings: | |
7013 | i40e_vsi_free_q_vectors(vsi); | |
7014 | if (vsi->netdev_registered) { | |
7015 | vsi->netdev_registered = false; | |
7016 | unregister_netdev(vsi->netdev); | |
7017 | free_netdev(vsi->netdev); | |
7018 | vsi->netdev = NULL; | |
7019 | } | |
7020 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); | |
7021 | err_vsi: | |
7022 | i40e_vsi_clear(vsi); | |
7023 | return NULL; | |
7024 | } | |
7025 | ||
41c445ff JB |
7026 | /** |
7027 | * i40e_vsi_setup - Set up a VSI by a given type | |
7028 | * @pf: board private structure | |
7029 | * @type: VSI type | |
7030 | * @uplink_seid: the switch element to link to | |
7031 | * @param1: usage depends upon VSI type. For VF types, indicates VF id | |
7032 | * | |
7033 | * This allocates the sw VSI structure and its queue resources, then add a VSI | |
7034 | * to the identified VEB. | |
7035 | * | |
7036 | * Returns pointer to the successfully allocated and configure VSI sw struct on | |
7037 | * success, otherwise returns NULL on failure. | |
7038 | **/ | |
7039 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, | |
7040 | u16 uplink_seid, u32 param1) | |
7041 | { | |
7042 | struct i40e_vsi *vsi = NULL; | |
7043 | struct i40e_veb *veb = NULL; | |
7044 | int ret, i; | |
7045 | int v_idx; | |
7046 | ||
7047 | /* The requested uplink_seid must be either | |
7048 | * - the PF's port seid | |
7049 | * no VEB is needed because this is the PF | |
7050 | * or this is a Flow Director special case VSI | |
7051 | * - seid of an existing VEB | |
7052 | * - seid of a VSI that owns an existing VEB | |
7053 | * - seid of a VSI that doesn't own a VEB | |
7054 | * a new VEB is created and the VSI becomes the owner | |
7055 | * - seid of the PF VSI, which is what creates the first VEB | |
7056 | * this is a special case of the previous | |
7057 | * | |
7058 | * Find which uplink_seid we were given and create a new VEB if needed | |
7059 | */ | |
7060 | for (i = 0; i < I40E_MAX_VEB; i++) { | |
7061 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { | |
7062 | veb = pf->veb[i]; | |
7063 | break; | |
7064 | } | |
7065 | } | |
7066 | ||
7067 | if (!veb && uplink_seid != pf->mac_seid) { | |
7068 | ||
7069 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { | |
7070 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { | |
7071 | vsi = pf->vsi[i]; | |
7072 | break; | |
7073 | } | |
7074 | } | |
7075 | if (!vsi) { | |
7076 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", | |
7077 | uplink_seid); | |
7078 | return NULL; | |
7079 | } | |
7080 | ||
7081 | if (vsi->uplink_seid == pf->mac_seid) | |
7082 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, | |
7083 | vsi->tc_config.enabled_tc); | |
7084 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) | |
7085 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, | |
7086 | vsi->tc_config.enabled_tc); | |
7087 | ||
7088 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { | |
7089 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) | |
7090 | veb = pf->veb[i]; | |
7091 | } | |
7092 | if (!veb) { | |
7093 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); | |
7094 | return NULL; | |
7095 | } | |
7096 | ||
7097 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; | |
7098 | uplink_seid = veb->seid; | |
7099 | } | |
7100 | ||
7101 | /* get vsi sw struct */ | |
7102 | v_idx = i40e_vsi_mem_alloc(pf, type); | |
7103 | if (v_idx < 0) | |
7104 | goto err_alloc; | |
7105 | vsi = pf->vsi[v_idx]; | |
cbf61325 ASJ |
7106 | if (!vsi) |
7107 | goto err_alloc; | |
41c445ff JB |
7108 | vsi->type = type; |
7109 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); | |
7110 | ||
7111 | if (type == I40E_VSI_MAIN) | |
7112 | pf->lan_vsi = v_idx; | |
7113 | else if (type == I40E_VSI_SRIOV) | |
7114 | vsi->vf_id = param1; | |
7115 | /* assign it some queues */ | |
cbf61325 ASJ |
7116 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
7117 | vsi->idx); | |
41c445ff JB |
7118 | if (ret < 0) { |
7119 | dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n", | |
7120 | vsi->seid, ret); | |
7121 | goto err_vsi; | |
7122 | } | |
7123 | vsi->base_queue = ret; | |
7124 | ||
7125 | /* get a VSI from the hardware */ | |
7126 | vsi->uplink_seid = uplink_seid; | |
7127 | ret = i40e_add_vsi(vsi); | |
7128 | if (ret) | |
7129 | goto err_vsi; | |
7130 | ||
7131 | switch (vsi->type) { | |
7132 | /* setup the netdev if needed */ | |
7133 | case I40E_VSI_MAIN: | |
7134 | case I40E_VSI_VMDQ2: | |
7135 | ret = i40e_config_netdev(vsi); | |
7136 | if (ret) | |
7137 | goto err_netdev; | |
7138 | ret = register_netdev(vsi->netdev); | |
7139 | if (ret) | |
7140 | goto err_netdev; | |
7141 | vsi->netdev_registered = true; | |
7142 | netif_carrier_off(vsi->netdev); | |
4e3b35b0 NP |
7143 | #ifdef CONFIG_I40E_DCB |
7144 | /* Setup DCB netlink interface */ | |
7145 | i40e_dcbnl_setup(vsi); | |
7146 | #endif /* CONFIG_I40E_DCB */ | |
41c445ff JB |
7147 | /* fall through */ |
7148 | ||
7149 | case I40E_VSI_FDIR: | |
7150 | /* set up vectors and rings if needed */ | |
7151 | ret = i40e_vsi_setup_vectors(vsi); | |
7152 | if (ret) | |
7153 | goto err_msix; | |
7154 | ||
7155 | ret = i40e_alloc_rings(vsi); | |
7156 | if (ret) | |
7157 | goto err_rings; | |
7158 | ||
7159 | /* map all of the rings to the q_vectors */ | |
7160 | i40e_vsi_map_rings_to_vectors(vsi); | |
7161 | ||
7162 | i40e_vsi_reset_stats(vsi); | |
7163 | break; | |
7164 | ||
7165 | default: | |
7166 | /* no netdev or rings for the other VSI types */ | |
7167 | break; | |
7168 | } | |
7169 | ||
7170 | return vsi; | |
7171 | ||
7172 | err_rings: | |
7173 | i40e_vsi_free_q_vectors(vsi); | |
7174 | err_msix: | |
7175 | if (vsi->netdev_registered) { | |
7176 | vsi->netdev_registered = false; | |
7177 | unregister_netdev(vsi->netdev); | |
7178 | free_netdev(vsi->netdev); | |
7179 | vsi->netdev = NULL; | |
7180 | } | |
7181 | err_netdev: | |
7182 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); | |
7183 | err_vsi: | |
7184 | i40e_vsi_clear(vsi); | |
7185 | err_alloc: | |
7186 | return NULL; | |
7187 | } | |
7188 | ||
7189 | /** | |
7190 | * i40e_veb_get_bw_info - Query VEB BW information | |
7191 | * @veb: the veb to query | |
7192 | * | |
7193 | * Query the Tx scheduler BW configuration data for given VEB | |
7194 | **/ | |
7195 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) | |
7196 | { | |
7197 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; | |
7198 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; | |
7199 | struct i40e_pf *pf = veb->pf; | |
7200 | struct i40e_hw *hw = &pf->hw; | |
7201 | u32 tc_bw_max; | |
7202 | int ret = 0; | |
7203 | int i; | |
7204 | ||
7205 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, | |
7206 | &bw_data, NULL); | |
7207 | if (ret) { | |
7208 | dev_info(&pf->pdev->dev, | |
7209 | "query veb bw config failed, aq_err=%d\n", | |
7210 | hw->aq.asq_last_status); | |
7211 | goto out; | |
7212 | } | |
7213 | ||
7214 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, | |
7215 | &ets_data, NULL); | |
7216 | if (ret) { | |
7217 | dev_info(&pf->pdev->dev, | |
7218 | "query veb bw ets config failed, aq_err=%d\n", | |
7219 | hw->aq.asq_last_status); | |
7220 | goto out; | |
7221 | } | |
7222 | ||
7223 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); | |
7224 | veb->bw_max_quanta = ets_data.tc_bw_max; | |
7225 | veb->is_abs_credits = bw_data.absolute_credits_enable; | |
7226 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | | |
7227 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); | |
7228 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | |
7229 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; | |
7230 | veb->bw_tc_limit_credits[i] = | |
7231 | le16_to_cpu(bw_data.tc_bw_limits[i]); | |
7232 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); | |
7233 | } | |
7234 | ||
7235 | out: | |
7236 | return ret; | |
7237 | } | |
7238 | ||
7239 | /** | |
7240 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF | |
7241 | * @pf: board private structure | |
7242 | * | |
7243 | * On error: returns error code (negative) | |
7244 | * On success: returns vsi index in PF (positive) | |
7245 | **/ | |
7246 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) | |
7247 | { | |
7248 | int ret = -ENOENT; | |
7249 | struct i40e_veb *veb; | |
7250 | int i; | |
7251 | ||
7252 | /* Need to protect the allocation of switch elements at the PF level */ | |
7253 | mutex_lock(&pf->switch_mutex); | |
7254 | ||
7255 | /* VEB list may be fragmented if VEB creation/destruction has | |
7256 | * been happening. We can afford to do a quick scan to look | |
7257 | * for any free slots in the list. | |
7258 | * | |
7259 | * find next empty veb slot, looping back around if necessary | |
7260 | */ | |
7261 | i = 0; | |
7262 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) | |
7263 | i++; | |
7264 | if (i >= I40E_MAX_VEB) { | |
7265 | ret = -ENOMEM; | |
7266 | goto err_alloc_veb; /* out of VEB slots! */ | |
7267 | } | |
7268 | ||
7269 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); | |
7270 | if (!veb) { | |
7271 | ret = -ENOMEM; | |
7272 | goto err_alloc_veb; | |
7273 | } | |
7274 | veb->pf = pf; | |
7275 | veb->idx = i; | |
7276 | veb->enabled_tc = 1; | |
7277 | ||
7278 | pf->veb[i] = veb; | |
7279 | ret = i; | |
7280 | err_alloc_veb: | |
7281 | mutex_unlock(&pf->switch_mutex); | |
7282 | return ret; | |
7283 | } | |
7284 | ||
7285 | /** | |
7286 | * i40e_switch_branch_release - Delete a branch of the switch tree | |
7287 | * @branch: where to start deleting | |
7288 | * | |
7289 | * This uses recursion to find the tips of the branch to be | |
7290 | * removed, deleting until we get back to and can delete this VEB. | |
7291 | **/ | |
7292 | static void i40e_switch_branch_release(struct i40e_veb *branch) | |
7293 | { | |
7294 | struct i40e_pf *pf = branch->pf; | |
7295 | u16 branch_seid = branch->seid; | |
7296 | u16 veb_idx = branch->idx; | |
7297 | int i; | |
7298 | ||
7299 | /* release any VEBs on this VEB - RECURSION */ | |
7300 | for (i = 0; i < I40E_MAX_VEB; i++) { | |
7301 | if (!pf->veb[i]) | |
7302 | continue; | |
7303 | if (pf->veb[i]->uplink_seid == branch->seid) | |
7304 | i40e_switch_branch_release(pf->veb[i]); | |
7305 | } | |
7306 | ||
7307 | /* Release the VSIs on this VEB, but not the owner VSI. | |
7308 | * | |
7309 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing | |
7310 | * the VEB itself, so don't use (*branch) after this loop. | |
7311 | */ | |
7312 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { | |
7313 | if (!pf->vsi[i]) | |
7314 | continue; | |
7315 | if (pf->vsi[i]->uplink_seid == branch_seid && | |
7316 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { | |
7317 | i40e_vsi_release(pf->vsi[i]); | |
7318 | } | |
7319 | } | |
7320 | ||
7321 | /* There's one corner case where the VEB might not have been | |
7322 | * removed, so double check it here and remove it if needed. | |
7323 | * This case happens if the veb was created from the debugfs | |
7324 | * commands and no VSIs were added to it. | |
7325 | */ | |
7326 | if (pf->veb[veb_idx]) | |
7327 | i40e_veb_release(pf->veb[veb_idx]); | |
7328 | } | |
7329 | ||
7330 | /** | |
7331 | * i40e_veb_clear - remove veb struct | |
7332 | * @veb: the veb to remove | |
7333 | **/ | |
7334 | static void i40e_veb_clear(struct i40e_veb *veb) | |
7335 | { | |
7336 | if (!veb) | |
7337 | return; | |
7338 | ||
7339 | if (veb->pf) { | |
7340 | struct i40e_pf *pf = veb->pf; | |
7341 | ||
7342 | mutex_lock(&pf->switch_mutex); | |
7343 | if (pf->veb[veb->idx] == veb) | |
7344 | pf->veb[veb->idx] = NULL; | |
7345 | mutex_unlock(&pf->switch_mutex); | |
7346 | } | |
7347 | ||
7348 | kfree(veb); | |
7349 | } | |
7350 | ||
7351 | /** | |
7352 | * i40e_veb_release - Delete a VEB and free its resources | |
7353 | * @veb: the VEB being removed | |
7354 | **/ | |
7355 | void i40e_veb_release(struct i40e_veb *veb) | |
7356 | { | |
7357 | struct i40e_vsi *vsi = NULL; | |
7358 | struct i40e_pf *pf; | |
7359 | int i, n = 0; | |
7360 | ||
7361 | pf = veb->pf; | |
7362 | ||
7363 | /* find the remaining VSI and check for extras */ | |
7364 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { | |
7365 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { | |
7366 | n++; | |
7367 | vsi = pf->vsi[i]; | |
7368 | } | |
7369 | } | |
7370 | if (n != 1) { | |
7371 | dev_info(&pf->pdev->dev, | |
7372 | "can't remove VEB %d with %d VSIs left\n", | |
7373 | veb->seid, n); | |
7374 | return; | |
7375 | } | |
7376 | ||
7377 | /* move the remaining VSI to uplink veb */ | |
7378 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; | |
7379 | if (veb->uplink_seid) { | |
7380 | vsi->uplink_seid = veb->uplink_seid; | |
7381 | if (veb->uplink_seid == pf->mac_seid) | |
7382 | vsi->veb_idx = I40E_NO_VEB; | |
7383 | else | |
7384 | vsi->veb_idx = veb->veb_idx; | |
7385 | } else { | |
7386 | /* floating VEB */ | |
7387 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; | |
7388 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; | |
7389 | } | |
7390 | ||
7391 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); | |
7392 | i40e_veb_clear(veb); | |
7393 | ||
7394 | return; | |
7395 | } | |
7396 | ||
7397 | /** | |
7398 | * i40e_add_veb - create the VEB in the switch | |
7399 | * @veb: the VEB to be instantiated | |
7400 | * @vsi: the controlling VSI | |
7401 | **/ | |
7402 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) | |
7403 | { | |
56747264 | 7404 | bool is_default = false; |
e1c51b95 | 7405 | bool is_cloud = false; |
41c445ff JB |
7406 | int ret; |
7407 | ||
7408 | /* get a VEB from the hardware */ | |
7409 | ret = i40e_aq_add_veb(&veb->pf->hw, veb->uplink_seid, vsi->seid, | |
e1c51b95 KS |
7410 | veb->enabled_tc, is_default, |
7411 | is_cloud, &veb->seid, NULL); | |
41c445ff JB |
7412 | if (ret) { |
7413 | dev_info(&veb->pf->pdev->dev, | |
7414 | "couldn't add VEB, err %d, aq_err %d\n", | |
7415 | ret, veb->pf->hw.aq.asq_last_status); | |
7416 | return -EPERM; | |
7417 | } | |
7418 | ||
7419 | /* get statistics counter */ | |
7420 | ret = i40e_aq_get_veb_parameters(&veb->pf->hw, veb->seid, NULL, NULL, | |
7421 | &veb->stats_idx, NULL, NULL, NULL); | |
7422 | if (ret) { | |
7423 | dev_info(&veb->pf->pdev->dev, | |
7424 | "couldn't get VEB statistics idx, err %d, aq_err %d\n", | |
7425 | ret, veb->pf->hw.aq.asq_last_status); | |
7426 | return -EPERM; | |
7427 | } | |
7428 | ret = i40e_veb_get_bw_info(veb); | |
7429 | if (ret) { | |
7430 | dev_info(&veb->pf->pdev->dev, | |
7431 | "couldn't get VEB bw info, err %d, aq_err %d\n", | |
7432 | ret, veb->pf->hw.aq.asq_last_status); | |
7433 | i40e_aq_delete_element(&veb->pf->hw, veb->seid, NULL); | |
7434 | return -ENOENT; | |
7435 | } | |
7436 | ||
7437 | vsi->uplink_seid = veb->seid; | |
7438 | vsi->veb_idx = veb->idx; | |
7439 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; | |
7440 | ||
7441 | return 0; | |
7442 | } | |
7443 | ||
7444 | /** | |
7445 | * i40e_veb_setup - Set up a VEB | |
7446 | * @pf: board private structure | |
7447 | * @flags: VEB setup flags | |
7448 | * @uplink_seid: the switch element to link to | |
7449 | * @vsi_seid: the initial VSI seid | |
7450 | * @enabled_tc: Enabled TC bit-map | |
7451 | * | |
7452 | * This allocates the sw VEB structure and links it into the switch | |
7453 | * It is possible and legal for this to be a duplicate of an already | |
7454 | * existing VEB. It is also possible for both uplink and vsi seids | |
7455 | * to be zero, in order to create a floating VEB. | |
7456 | * | |
7457 | * Returns pointer to the successfully allocated VEB sw struct on | |
7458 | * success, otherwise returns NULL on failure. | |
7459 | **/ | |
7460 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, | |
7461 | u16 uplink_seid, u16 vsi_seid, | |
7462 | u8 enabled_tc) | |
7463 | { | |
7464 | struct i40e_veb *veb, *uplink_veb = NULL; | |
7465 | int vsi_idx, veb_idx; | |
7466 | int ret; | |
7467 | ||
7468 | /* if one seid is 0, the other must be 0 to create a floating relay */ | |
7469 | if ((uplink_seid == 0 || vsi_seid == 0) && | |
7470 | (uplink_seid + vsi_seid != 0)) { | |
7471 | dev_info(&pf->pdev->dev, | |
7472 | "one, not both seid's are 0: uplink=%d vsi=%d\n", | |
7473 | uplink_seid, vsi_seid); | |
7474 | return NULL; | |
7475 | } | |
7476 | ||
7477 | /* make sure there is such a vsi and uplink */ | |
7478 | for (vsi_idx = 0; vsi_idx < pf->hw.func_caps.num_vsis; vsi_idx++) | |
7479 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) | |
7480 | break; | |
7481 | if (vsi_idx >= pf->hw.func_caps.num_vsis && vsi_seid != 0) { | |
7482 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", | |
7483 | vsi_seid); | |
7484 | return NULL; | |
7485 | } | |
7486 | ||
7487 | if (uplink_seid && uplink_seid != pf->mac_seid) { | |
7488 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { | |
7489 | if (pf->veb[veb_idx] && | |
7490 | pf->veb[veb_idx]->seid == uplink_seid) { | |
7491 | uplink_veb = pf->veb[veb_idx]; | |
7492 | break; | |
7493 | } | |
7494 | } | |
7495 | if (!uplink_veb) { | |
7496 | dev_info(&pf->pdev->dev, | |
7497 | "uplink seid %d not found\n", uplink_seid); | |
7498 | return NULL; | |
7499 | } | |
7500 | } | |
7501 | ||
7502 | /* get veb sw struct */ | |
7503 | veb_idx = i40e_veb_mem_alloc(pf); | |
7504 | if (veb_idx < 0) | |
7505 | goto err_alloc; | |
7506 | veb = pf->veb[veb_idx]; | |
7507 | veb->flags = flags; | |
7508 | veb->uplink_seid = uplink_seid; | |
7509 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); | |
7510 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); | |
7511 | ||
7512 | /* create the VEB in the switch */ | |
7513 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); | |
7514 | if (ret) | |
7515 | goto err_veb; | |
7516 | ||
7517 | return veb; | |
7518 | ||
7519 | err_veb: | |
7520 | i40e_veb_clear(veb); | |
7521 | err_alloc: | |
7522 | return NULL; | |
7523 | } | |
7524 | ||
7525 | /** | |
7526 | * i40e_setup_pf_switch_element - set pf vars based on switch type | |
7527 | * @pf: board private structure | |
7528 | * @ele: element we are building info from | |
7529 | * @num_reported: total number of elements | |
7530 | * @printconfig: should we print the contents | |
7531 | * | |
7532 | * helper function to assist in extracting a few useful SEID values. | |
7533 | **/ | |
7534 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, | |
7535 | struct i40e_aqc_switch_config_element_resp *ele, | |
7536 | u16 num_reported, bool printconfig) | |
7537 | { | |
7538 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); | |
7539 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); | |
7540 | u8 element_type = ele->element_type; | |
7541 | u16 seid = le16_to_cpu(ele->seid); | |
7542 | ||
7543 | if (printconfig) | |
7544 | dev_info(&pf->pdev->dev, | |
7545 | "type=%d seid=%d uplink=%d downlink=%d\n", | |
7546 | element_type, seid, uplink_seid, downlink_seid); | |
7547 | ||
7548 | switch (element_type) { | |
7549 | case I40E_SWITCH_ELEMENT_TYPE_MAC: | |
7550 | pf->mac_seid = seid; | |
7551 | break; | |
7552 | case I40E_SWITCH_ELEMENT_TYPE_VEB: | |
7553 | /* Main VEB? */ | |
7554 | if (uplink_seid != pf->mac_seid) | |
7555 | break; | |
7556 | if (pf->lan_veb == I40E_NO_VEB) { | |
7557 | int v; | |
7558 | ||
7559 | /* find existing or else empty VEB */ | |
7560 | for (v = 0; v < I40E_MAX_VEB; v++) { | |
7561 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { | |
7562 | pf->lan_veb = v; | |
7563 | break; | |
7564 | } | |
7565 | } | |
7566 | if (pf->lan_veb == I40E_NO_VEB) { | |
7567 | v = i40e_veb_mem_alloc(pf); | |
7568 | if (v < 0) | |
7569 | break; | |
7570 | pf->lan_veb = v; | |
7571 | } | |
7572 | } | |
7573 | ||
7574 | pf->veb[pf->lan_veb]->seid = seid; | |
7575 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; | |
7576 | pf->veb[pf->lan_veb]->pf = pf; | |
7577 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; | |
7578 | break; | |
7579 | case I40E_SWITCH_ELEMENT_TYPE_VSI: | |
7580 | if (num_reported != 1) | |
7581 | break; | |
7582 | /* This is immediately after a reset so we can assume this is | |
7583 | * the PF's VSI | |
7584 | */ | |
7585 | pf->mac_seid = uplink_seid; | |
7586 | pf->pf_seid = downlink_seid; | |
7587 | pf->main_vsi_seid = seid; | |
7588 | if (printconfig) | |
7589 | dev_info(&pf->pdev->dev, | |
7590 | "pf_seid=%d main_vsi_seid=%d\n", | |
7591 | pf->pf_seid, pf->main_vsi_seid); | |
7592 | break; | |
7593 | case I40E_SWITCH_ELEMENT_TYPE_PF: | |
7594 | case I40E_SWITCH_ELEMENT_TYPE_VF: | |
7595 | case I40E_SWITCH_ELEMENT_TYPE_EMP: | |
7596 | case I40E_SWITCH_ELEMENT_TYPE_BMC: | |
7597 | case I40E_SWITCH_ELEMENT_TYPE_PE: | |
7598 | case I40E_SWITCH_ELEMENT_TYPE_PA: | |
7599 | /* ignore these for now */ | |
7600 | break; | |
7601 | default: | |
7602 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", | |
7603 | element_type, seid); | |
7604 | break; | |
7605 | } | |
7606 | } | |
7607 | ||
7608 | /** | |
7609 | * i40e_fetch_switch_configuration - Get switch config from firmware | |
7610 | * @pf: board private structure | |
7611 | * @printconfig: should we print the contents | |
7612 | * | |
7613 | * Get the current switch configuration from the device and | |
7614 | * extract a few useful SEID values. | |
7615 | **/ | |
7616 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) | |
7617 | { | |
7618 | struct i40e_aqc_get_switch_config_resp *sw_config; | |
7619 | u16 next_seid = 0; | |
7620 | int ret = 0; | |
7621 | u8 *aq_buf; | |
7622 | int i; | |
7623 | ||
7624 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); | |
7625 | if (!aq_buf) | |
7626 | return -ENOMEM; | |
7627 | ||
7628 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; | |
7629 | do { | |
7630 | u16 num_reported, num_total; | |
7631 | ||
7632 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, | |
7633 | I40E_AQ_LARGE_BUF, | |
7634 | &next_seid, NULL); | |
7635 | if (ret) { | |
7636 | dev_info(&pf->pdev->dev, | |
7637 | "get switch config failed %d aq_err=%x\n", | |
7638 | ret, pf->hw.aq.asq_last_status); | |
7639 | kfree(aq_buf); | |
7640 | return -ENOENT; | |
7641 | } | |
7642 | ||
7643 | num_reported = le16_to_cpu(sw_config->header.num_reported); | |
7644 | num_total = le16_to_cpu(sw_config->header.num_total); | |
7645 | ||
7646 | if (printconfig) | |
7647 | dev_info(&pf->pdev->dev, | |
7648 | "header: %d reported %d total\n", | |
7649 | num_reported, num_total); | |
7650 | ||
7651 | if (num_reported) { | |
7652 | int sz = sizeof(*sw_config) * num_reported; | |
7653 | ||
7654 | kfree(pf->sw_config); | |
7655 | pf->sw_config = kzalloc(sz, GFP_KERNEL); | |
7656 | if (pf->sw_config) | |
7657 | memcpy(pf->sw_config, sw_config, sz); | |
7658 | } | |
7659 | ||
7660 | for (i = 0; i < num_reported; i++) { | |
7661 | struct i40e_aqc_switch_config_element_resp *ele = | |
7662 | &sw_config->element[i]; | |
7663 | ||
7664 | i40e_setup_pf_switch_element(pf, ele, num_reported, | |
7665 | printconfig); | |
7666 | } | |
7667 | } while (next_seid != 0); | |
7668 | ||
7669 | kfree(aq_buf); | |
7670 | return ret; | |
7671 | } | |
7672 | ||
7673 | /** | |
7674 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset | |
7675 | * @pf: board private structure | |
bc7d338f | 7676 | * @reinit: if the Main VSI needs to re-initialized. |
41c445ff JB |
7677 | * |
7678 | * Returns 0 on success, negative value on failure | |
7679 | **/ | |
bc7d338f | 7680 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
41c445ff | 7681 | { |
895106a5 | 7682 | u32 rxfc = 0, txfc = 0, rxfc_reg; |
41c445ff JB |
7683 | int ret; |
7684 | ||
7685 | /* find out what's out there already */ | |
7686 | ret = i40e_fetch_switch_configuration(pf, false); | |
7687 | if (ret) { | |
7688 | dev_info(&pf->pdev->dev, | |
7689 | "couldn't fetch switch config, err %d, aq_err %d\n", | |
7690 | ret, pf->hw.aq.asq_last_status); | |
7691 | return ret; | |
7692 | } | |
7693 | i40e_pf_reset_stats(pf); | |
7694 | ||
41c445ff | 7695 | /* first time setup */ |
bc7d338f | 7696 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
41c445ff JB |
7697 | struct i40e_vsi *vsi = NULL; |
7698 | u16 uplink_seid; | |
7699 | ||
7700 | /* Set up the PF VSI associated with the PF's main VSI | |
7701 | * that is already in the HW switch | |
7702 | */ | |
7703 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) | |
7704 | uplink_seid = pf->veb[pf->lan_veb]->seid; | |
7705 | else | |
7706 | uplink_seid = pf->mac_seid; | |
bc7d338f ASJ |
7707 | if (pf->lan_vsi == I40E_NO_VSI) |
7708 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); | |
7709 | else if (reinit) | |
7710 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); | |
41c445ff JB |
7711 | if (!vsi) { |
7712 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); | |
7713 | i40e_fdir_teardown(pf); | |
7714 | return -EAGAIN; | |
7715 | } | |
41c445ff JB |
7716 | } else { |
7717 | /* force a reset of TC and queue layout configurations */ | |
7718 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; | |
7719 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; | |
7720 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; | |
7721 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); | |
7722 | } | |
7723 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); | |
7724 | ||
cbf61325 ASJ |
7725 | i40e_fdir_sb_setup(pf); |
7726 | ||
41c445ff JB |
7727 | /* Setup static PF queue filter control settings */ |
7728 | ret = i40e_setup_pf_filter_control(pf); | |
7729 | if (ret) { | |
7730 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", | |
7731 | ret); | |
7732 | /* Failure here should not stop continuing other steps */ | |
7733 | } | |
7734 | ||
7735 | /* enable RSS in the HW, even for only one queue, as the stack can use | |
7736 | * the hash | |
7737 | */ | |
7738 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) | |
7739 | i40e_config_rss(pf); | |
7740 | ||
7741 | /* fill in link information and enable LSE reporting */ | |
7742 | i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); | |
7743 | i40e_link_event(pf); | |
7744 | ||
d52c20b7 | 7745 | /* Initialize user-specific link properties */ |
41c445ff JB |
7746 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
7747 | I40E_AQ_AN_COMPLETED) ? true : false); | |
d52c20b7 JB |
7748 | /* requested_mode is set in probe or by ethtool */ |
7749 | if (!pf->fc_autoneg_status) | |
7750 | goto no_autoneg; | |
7751 | ||
7752 | if ((pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) && | |
7753 | (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX)) | |
41c445ff JB |
7754 | pf->hw.fc.current_mode = I40E_FC_FULL; |
7755 | else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) | |
7756 | pf->hw.fc.current_mode = I40E_FC_TX_PAUSE; | |
7757 | else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX) | |
7758 | pf->hw.fc.current_mode = I40E_FC_RX_PAUSE; | |
7759 | else | |
d52c20b7 JB |
7760 | pf->hw.fc.current_mode = I40E_FC_NONE; |
7761 | ||
7762 | /* sync the flow control settings with the auto-neg values */ | |
7763 | switch (pf->hw.fc.current_mode) { | |
7764 | case I40E_FC_FULL: | |
7765 | txfc = 1; | |
7766 | rxfc = 1; | |
7767 | break; | |
7768 | case I40E_FC_TX_PAUSE: | |
7769 | txfc = 1; | |
7770 | rxfc = 0; | |
7771 | break; | |
7772 | case I40E_FC_RX_PAUSE: | |
7773 | txfc = 0; | |
7774 | rxfc = 1; | |
7775 | break; | |
7776 | case I40E_FC_NONE: | |
7777 | case I40E_FC_DEFAULT: | |
7778 | txfc = 0; | |
7779 | rxfc = 0; | |
7780 | break; | |
7781 | case I40E_FC_PFC: | |
7782 | /* TBD */ | |
7783 | break; | |
7784 | /* no default case, we have to handle all possibilities here */ | |
7785 | } | |
7786 | ||
7787 | wr32(&pf->hw, I40E_PRTDCB_FCCFG, txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT); | |
7788 | ||
7789 | rxfc_reg = rd32(&pf->hw, I40E_PRTDCB_MFLCN) & | |
7790 | ~I40E_PRTDCB_MFLCN_RFCE_MASK; | |
7791 | rxfc_reg |= (rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT); | |
7792 | ||
7793 | wr32(&pf->hw, I40E_PRTDCB_MFLCN, rxfc_reg); | |
41c445ff | 7794 | |
d52c20b7 JB |
7795 | goto fc_complete; |
7796 | ||
7797 | no_autoneg: | |
7798 | /* disable L2 flow control, user can turn it on if they wish */ | |
7799 | wr32(&pf->hw, I40E_PRTDCB_FCCFG, 0); | |
7800 | wr32(&pf->hw, I40E_PRTDCB_MFLCN, rd32(&pf->hw, I40E_PRTDCB_MFLCN) & | |
7801 | ~I40E_PRTDCB_MFLCN_RFCE_MASK); | |
7802 | ||
7803 | fc_complete: | |
beb0dff1 JK |
7804 | i40e_ptp_init(pf); |
7805 | ||
41c445ff JB |
7806 | return ret; |
7807 | } | |
7808 | ||
41c445ff JB |
7809 | /** |
7810 | * i40e_determine_queue_usage - Work out queue distribution | |
7811 | * @pf: board private structure | |
7812 | **/ | |
7813 | static void i40e_determine_queue_usage(struct i40e_pf *pf) | |
7814 | { | |
41c445ff JB |
7815 | int queues_left; |
7816 | ||
7817 | pf->num_lan_qps = 0; | |
41c445ff JB |
7818 | |
7819 | /* Find the max queues to be put into basic use. We'll always be | |
7820 | * using TC0, whether or not DCB is running, and TC0 will get the | |
7821 | * big RSS set. | |
7822 | */ | |
7823 | queues_left = pf->hw.func_caps.num_tx_qp; | |
7824 | ||
cbf61325 ASJ |
7825 | if ((queues_left == 1) || |
7826 | !(pf->flags & I40E_FLAG_MSIX_ENABLED) || | |
7827 | !(pf->flags & (I40E_FLAG_RSS_ENABLED | I40E_FLAG_FD_SB_ENABLED | | |
7828 | I40E_FLAG_DCB_ENABLED))) { | |
41c445ff JB |
7829 | /* one qp for PF, no queues for anything else */ |
7830 | queues_left = 0; | |
7831 | pf->rss_size = pf->num_lan_qps = 1; | |
7832 | ||
7833 | /* make sure all the fancies are disabled */ | |
60ea5f83 JB |
7834 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
7835 | I40E_FLAG_FD_SB_ENABLED | | |
7836 | I40E_FLAG_FD_ATR_ENABLED | | |
7837 | I40E_FLAG_DCB_ENABLED | | |
7838 | I40E_FLAG_SRIOV_ENABLED | | |
7839 | I40E_FLAG_VMDQ_ENABLED); | |
41c445ff | 7840 | } else { |
cbf61325 ASJ |
7841 | /* Not enough queues for all TCs */ |
7842 | if ((pf->flags & I40E_FLAG_DCB_ENABLED) && | |
7843 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { | |
7844 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; | |
7845 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); | |
7846 | } | |
7847 | pf->num_lan_qps = pf->rss_size_max; | |
7848 | queues_left -= pf->num_lan_qps; | |
7849 | } | |
7850 | ||
7851 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { | |
7852 | if (queues_left > 1) { | |
7853 | queues_left -= 1; /* save 1 queue for FD */ | |
7854 | } else { | |
7855 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; | |
7856 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); | |
7857 | } | |
41c445ff JB |
7858 | } |
7859 | ||
7860 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && | |
7861 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { | |
cbf61325 ASJ |
7862 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
7863 | (queues_left / pf->num_vf_qps)); | |
41c445ff JB |
7864 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
7865 | } | |
7866 | ||
7867 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && | |
7868 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { | |
7869 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, | |
7870 | (queues_left / pf->num_vmdq_qps)); | |
7871 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); | |
7872 | } | |
7873 | ||
f8ff1464 | 7874 | pf->queues_left = queues_left; |
41c445ff JB |
7875 | return; |
7876 | } | |
7877 | ||
7878 | /** | |
7879 | * i40e_setup_pf_filter_control - Setup PF static filter control | |
7880 | * @pf: PF to be setup | |
7881 | * | |
7882 | * i40e_setup_pf_filter_control sets up a pf's initial filter control | |
7883 | * settings. If PE/FCoE are enabled then it will also set the per PF | |
7884 | * based filter sizes required for them. It also enables Flow director, | |
7885 | * ethertype and macvlan type filter settings for the pf. | |
7886 | * | |
7887 | * Returns 0 on success, negative on failure | |
7888 | **/ | |
7889 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) | |
7890 | { | |
7891 | struct i40e_filter_control_settings *settings = &pf->filter_settings; | |
7892 | ||
7893 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; | |
7894 | ||
7895 | /* Flow Director is enabled */ | |
60ea5f83 | 7896 | if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED)) |
41c445ff JB |
7897 | settings->enable_fdir = true; |
7898 | ||
7899 | /* Ethtype and MACVLAN filters enabled for PF */ | |
7900 | settings->enable_ethtype = true; | |
7901 | settings->enable_macvlan = true; | |
7902 | ||
7903 | if (i40e_set_filter_control(&pf->hw, settings)) | |
7904 | return -ENOENT; | |
7905 | ||
7906 | return 0; | |
7907 | } | |
7908 | ||
0c22b3dd JB |
7909 | #define INFO_STRING_LEN 255 |
7910 | static void i40e_print_features(struct i40e_pf *pf) | |
7911 | { | |
7912 | struct i40e_hw *hw = &pf->hw; | |
7913 | char *buf, *string; | |
7914 | ||
7915 | string = kzalloc(INFO_STRING_LEN, GFP_KERNEL); | |
7916 | if (!string) { | |
7917 | dev_err(&pf->pdev->dev, "Features string allocation failed\n"); | |
7918 | return; | |
7919 | } | |
7920 | ||
7921 | buf = string; | |
7922 | ||
7923 | buf += sprintf(string, "Features: PF-id[%d] ", hw->pf_id); | |
7924 | #ifdef CONFIG_PCI_IOV | |
7925 | buf += sprintf(buf, "VFs: %d ", pf->num_req_vfs); | |
7926 | #endif | |
7927 | buf += sprintf(buf, "VSIs: %d QP: %d ", pf->hw.func_caps.num_vsis, | |
7928 | pf->vsi[pf->lan_vsi]->num_queue_pairs); | |
7929 | ||
7930 | if (pf->flags & I40E_FLAG_RSS_ENABLED) | |
7931 | buf += sprintf(buf, "RSS "); | |
7932 | buf += sprintf(buf, "FDir "); | |
7933 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) | |
7934 | buf += sprintf(buf, "ATR "); | |
7935 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) | |
7936 | buf += sprintf(buf, "NTUPLE "); | |
7937 | if (pf->flags & I40E_FLAG_DCB_ENABLED) | |
7938 | buf += sprintf(buf, "DCB "); | |
7939 | if (pf->flags & I40E_FLAG_PTP) | |
7940 | buf += sprintf(buf, "PTP "); | |
7941 | ||
7942 | BUG_ON(buf > (string + INFO_STRING_LEN)); | |
7943 | dev_info(&pf->pdev->dev, "%s\n", string); | |
7944 | kfree(string); | |
7945 | } | |
7946 | ||
41c445ff JB |
7947 | /** |
7948 | * i40e_probe - Device initialization routine | |
7949 | * @pdev: PCI device information struct | |
7950 | * @ent: entry in i40e_pci_tbl | |
7951 | * | |
7952 | * i40e_probe initializes a pf identified by a pci_dev structure. | |
7953 | * The OS initialization, configuring of the pf private structure, | |
7954 | * and a hardware reset occur. | |
7955 | * | |
7956 | * Returns 0 on success, negative on failure | |
7957 | **/ | |
7958 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |
7959 | { | |
7960 | struct i40e_driver_version dv; | |
7961 | struct i40e_pf *pf; | |
7962 | struct i40e_hw *hw; | |
93cd765b | 7963 | static u16 pfs_found; |
d4dfb81a | 7964 | u16 link_status; |
41c445ff JB |
7965 | int err = 0; |
7966 | u32 len; | |
7967 | ||
7968 | err = pci_enable_device_mem(pdev); | |
7969 | if (err) | |
7970 | return err; | |
7971 | ||
7972 | /* set up for high or low dma */ | |
6494294f MW |
7973 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
7974 | if (err) | |
7975 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); | |
7976 | if (err) { | |
7977 | dev_err(&pdev->dev, | |
7978 | "DMA configuration failed: 0x%x\n", err); | |
41c445ff JB |
7979 | goto err_dma; |
7980 | } | |
7981 | ||
7982 | /* set up pci connections */ | |
7983 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, | |
7984 | IORESOURCE_MEM), i40e_driver_name); | |
7985 | if (err) { | |
7986 | dev_info(&pdev->dev, | |
7987 | "pci_request_selected_regions failed %d\n", err); | |
7988 | goto err_pci_reg; | |
7989 | } | |
7990 | ||
7991 | pci_enable_pcie_error_reporting(pdev); | |
7992 | pci_set_master(pdev); | |
7993 | ||
7994 | /* Now that we have a PCI connection, we need to do the | |
7995 | * low level device setup. This is primarily setting up | |
7996 | * the Admin Queue structures and then querying for the | |
7997 | * device's current profile information. | |
7998 | */ | |
7999 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); | |
8000 | if (!pf) { | |
8001 | err = -ENOMEM; | |
8002 | goto err_pf_alloc; | |
8003 | } | |
8004 | pf->next_vsi = 0; | |
8005 | pf->pdev = pdev; | |
8006 | set_bit(__I40E_DOWN, &pf->state); | |
8007 | ||
8008 | hw = &pf->hw; | |
8009 | hw->back = pf; | |
8010 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), | |
8011 | pci_resource_len(pdev, 0)); | |
8012 | if (!hw->hw_addr) { | |
8013 | err = -EIO; | |
8014 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", | |
8015 | (unsigned int)pci_resource_start(pdev, 0), | |
8016 | (unsigned int)pci_resource_len(pdev, 0), err); | |
8017 | goto err_ioremap; | |
8018 | } | |
8019 | hw->vendor_id = pdev->vendor; | |
8020 | hw->device_id = pdev->device; | |
8021 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); | |
8022 | hw->subsystem_vendor_id = pdev->subsystem_vendor; | |
8023 | hw->subsystem_device_id = pdev->subsystem_device; | |
8024 | hw->bus.device = PCI_SLOT(pdev->devfn); | |
8025 | hw->bus.func = PCI_FUNC(pdev->devfn); | |
93cd765b | 8026 | pf->instance = pfs_found; |
41c445ff | 8027 | |
7134f9ce JB |
8028 | /* do a special CORER for clearing PXE mode once at init */ |
8029 | if (hw->revision_id == 0 && | |
8030 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { | |
8031 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); | |
8032 | i40e_flush(hw); | |
8033 | msleep(200); | |
8034 | pf->corer_count++; | |
8035 | ||
8036 | i40e_clear_pxe_mode(hw); | |
8037 | } | |
8038 | ||
41c445ff JB |
8039 | /* Reset here to make sure all is clean and to define PF 'n' */ |
8040 | err = i40e_pf_reset(hw); | |
8041 | if (err) { | |
8042 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); | |
8043 | goto err_pf_reset; | |
8044 | } | |
8045 | pf->pfr_count++; | |
8046 | ||
8047 | hw->aq.num_arq_entries = I40E_AQ_LEN; | |
8048 | hw->aq.num_asq_entries = I40E_AQ_LEN; | |
8049 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; | |
8050 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; | |
8051 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; | |
8052 | snprintf(pf->misc_int_name, sizeof(pf->misc_int_name) - 1, | |
8053 | "%s-pf%d:misc", | |
8054 | dev_driver_string(&pf->pdev->dev), pf->hw.pf_id); | |
8055 | ||
8056 | err = i40e_init_shared_code(hw); | |
8057 | if (err) { | |
8058 | dev_info(&pdev->dev, "init_shared_code failed: %d\n", err); | |
8059 | goto err_pf_reset; | |
8060 | } | |
8061 | ||
d52c20b7 JB |
8062 | /* set up a default setting for link flow control */ |
8063 | pf->hw.fc.requested_mode = I40E_FC_NONE; | |
8064 | ||
41c445ff JB |
8065 | err = i40e_init_adminq(hw); |
8066 | dev_info(&pdev->dev, "%s\n", i40e_fw_version_str(hw)); | |
8067 | if (err) { | |
8068 | dev_info(&pdev->dev, | |
8069 | "init_adminq failed: %d expecting API %02x.%02x\n", | |
8070 | err, | |
8071 | I40E_FW_API_VERSION_MAJOR, I40E_FW_API_VERSION_MINOR); | |
8072 | goto err_pf_reset; | |
8073 | } | |
8074 | ||
6ff4ef86 | 8075 | i40e_clear_pxe_mode(hw); |
41c445ff JB |
8076 | err = i40e_get_capabilities(pf); |
8077 | if (err) | |
8078 | goto err_adminq_setup; | |
8079 | ||
8080 | err = i40e_sw_init(pf); | |
8081 | if (err) { | |
8082 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); | |
8083 | goto err_sw_init; | |
8084 | } | |
8085 | ||
8086 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, | |
8087 | hw->func_caps.num_rx_qp, | |
8088 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); | |
8089 | if (err) { | |
8090 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); | |
8091 | goto err_init_lan_hmc; | |
8092 | } | |
8093 | ||
8094 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); | |
8095 | if (err) { | |
8096 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); | |
8097 | err = -ENOENT; | |
8098 | goto err_configure_lan_hmc; | |
8099 | } | |
8100 | ||
8101 | i40e_get_mac_addr(hw, hw->mac.addr); | |
f62b5060 | 8102 | if (!is_valid_ether_addr(hw->mac.addr)) { |
41c445ff JB |
8103 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
8104 | err = -EIO; | |
8105 | goto err_mac_addr; | |
8106 | } | |
8107 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); | |
8108 | memcpy(hw->mac.perm_addr, hw->mac.addr, ETH_ALEN); | |
8109 | ||
8110 | pci_set_drvdata(pdev, pf); | |
8111 | pci_save_state(pdev); | |
4e3b35b0 NP |
8112 | #ifdef CONFIG_I40E_DCB |
8113 | err = i40e_init_pf_dcb(pf); | |
8114 | if (err) { | |
8115 | dev_info(&pdev->dev, "init_pf_dcb failed: %d\n", err); | |
8116 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; | |
8117 | goto err_init_dcb; | |
8118 | } | |
8119 | #endif /* CONFIG_I40E_DCB */ | |
41c445ff JB |
8120 | |
8121 | /* set up periodic task facility */ | |
8122 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); | |
8123 | pf->service_timer_period = HZ; | |
8124 | ||
8125 | INIT_WORK(&pf->service_task, i40e_service_task); | |
8126 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); | |
8127 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; | |
8128 | pf->link_check_timeout = jiffies; | |
8129 | ||
8e2773ae SN |
8130 | /* WoL defaults to disabled */ |
8131 | pf->wol_en = false; | |
8132 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); | |
8133 | ||
41c445ff JB |
8134 | /* set up the main switch operations */ |
8135 | i40e_determine_queue_usage(pf); | |
8136 | i40e_init_interrupt_scheme(pf); | |
8137 | ||
8138 | /* Set up the *vsi struct based on the number of VSIs in the HW, | |
8139 | * and set up our local tracking of the MAIN PF vsi. | |
8140 | */ | |
8141 | len = sizeof(struct i40e_vsi *) * pf->hw.func_caps.num_vsis; | |
8142 | pf->vsi = kzalloc(len, GFP_KERNEL); | |
ed87ac09 WY |
8143 | if (!pf->vsi) { |
8144 | err = -ENOMEM; | |
41c445ff | 8145 | goto err_switch_setup; |
ed87ac09 | 8146 | } |
41c445ff | 8147 | |
bc7d338f | 8148 | err = i40e_setup_pf_switch(pf, false); |
41c445ff JB |
8149 | if (err) { |
8150 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); | |
8151 | goto err_vsis; | |
8152 | } | |
8153 | ||
8154 | /* The main driver is (mostly) up and happy. We need to set this state | |
8155 | * before setting up the misc vector or we get a race and the vector | |
8156 | * ends up disabled forever. | |
8157 | */ | |
8158 | clear_bit(__I40E_DOWN, &pf->state); | |
8159 | ||
8160 | /* In case of MSIX we are going to setup the misc vector right here | |
8161 | * to handle admin queue events etc. In case of legacy and MSI | |
8162 | * the misc functionality and queue processing is combined in | |
8163 | * the same vector and that gets setup at open. | |
8164 | */ | |
8165 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | |
8166 | err = i40e_setup_misc_vector(pf); | |
8167 | if (err) { | |
8168 | dev_info(&pdev->dev, | |
8169 | "setup of misc vector failed: %d\n", err); | |
8170 | goto err_vsis; | |
8171 | } | |
8172 | } | |
8173 | ||
8174 | /* prep for VF support */ | |
8175 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && | |
8176 | (pf->flags & I40E_FLAG_MSIX_ENABLED)) { | |
8177 | u32 val; | |
8178 | ||
8179 | /* disable link interrupts for VFs */ | |
8180 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); | |
8181 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; | |
8182 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); | |
8183 | i40e_flush(hw); | |
4aeec010 MW |
8184 | |
8185 | if (pci_num_vf(pdev)) { | |
8186 | dev_info(&pdev->dev, | |
8187 | "Active VFs found, allocating resources.\n"); | |
8188 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); | |
8189 | if (err) | |
8190 | dev_info(&pdev->dev, | |
8191 | "Error %d allocating resources for existing VFs\n", | |
8192 | err); | |
8193 | } | |
41c445ff JB |
8194 | } |
8195 | ||
93cd765b ASJ |
8196 | pfs_found++; |
8197 | ||
41c445ff JB |
8198 | i40e_dbg_pf_init(pf); |
8199 | ||
8200 | /* tell the firmware that we're starting */ | |
8201 | dv.major_version = DRV_VERSION_MAJOR; | |
8202 | dv.minor_version = DRV_VERSION_MINOR; | |
8203 | dv.build_version = DRV_VERSION_BUILD; | |
8204 | dv.subbuild_version = 0; | |
8205 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); | |
8206 | ||
8207 | /* since everything's happy, start the service_task timer */ | |
8208 | mod_timer(&pf->service_timer, | |
8209 | round_jiffies(jiffies + pf->service_timer_period)); | |
8210 | ||
d4dfb81a CS |
8211 | /* Get the negotiated link width and speed from PCI config space */ |
8212 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, &link_status); | |
8213 | ||
8214 | i40e_set_pci_config_data(hw, link_status); | |
8215 | ||
69bfb110 | 8216 | dev_info(&pdev->dev, "PCI-Express: %s %s\n", |
d4dfb81a CS |
8217 | (hw->bus.speed == i40e_bus_speed_8000 ? "Speed 8.0GT/s" : |
8218 | hw->bus.speed == i40e_bus_speed_5000 ? "Speed 5.0GT/s" : | |
8219 | hw->bus.speed == i40e_bus_speed_2500 ? "Speed 2.5GT/s" : | |
8220 | "Unknown"), | |
8221 | (hw->bus.width == i40e_bus_width_pcie_x8 ? "Width x8" : | |
8222 | hw->bus.width == i40e_bus_width_pcie_x4 ? "Width x4" : | |
8223 | hw->bus.width == i40e_bus_width_pcie_x2 ? "Width x2" : | |
8224 | hw->bus.width == i40e_bus_width_pcie_x1 ? "Width x1" : | |
8225 | "Unknown")); | |
8226 | ||
8227 | if (hw->bus.width < i40e_bus_width_pcie_x8 || | |
8228 | hw->bus.speed < i40e_bus_speed_8000) { | |
8229 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); | |
8230 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); | |
8231 | } | |
8232 | ||
0c22b3dd JB |
8233 | /* print a string summarizing features */ |
8234 | i40e_print_features(pf); | |
8235 | ||
41c445ff JB |
8236 | return 0; |
8237 | ||
8238 | /* Unwind what we've done if something failed in the setup */ | |
8239 | err_vsis: | |
8240 | set_bit(__I40E_DOWN, &pf->state); | |
41c445ff JB |
8241 | i40e_clear_interrupt_scheme(pf); |
8242 | kfree(pf->vsi); | |
04b03013 SN |
8243 | err_switch_setup: |
8244 | i40e_reset_interrupt_capability(pf); | |
41c445ff | 8245 | del_timer_sync(&pf->service_timer); |
4e3b35b0 NP |
8246 | #ifdef CONFIG_I40E_DCB |
8247 | err_init_dcb: | |
8248 | #endif /* CONFIG_I40E_DCB */ | |
41c445ff JB |
8249 | err_mac_addr: |
8250 | err_configure_lan_hmc: | |
8251 | (void)i40e_shutdown_lan_hmc(hw); | |
8252 | err_init_lan_hmc: | |
8253 | kfree(pf->qp_pile); | |
8254 | kfree(pf->irq_pile); | |
8255 | err_sw_init: | |
8256 | err_adminq_setup: | |
8257 | (void)i40e_shutdown_adminq(hw); | |
8258 | err_pf_reset: | |
8259 | iounmap(hw->hw_addr); | |
8260 | err_ioremap: | |
8261 | kfree(pf); | |
8262 | err_pf_alloc: | |
8263 | pci_disable_pcie_error_reporting(pdev); | |
8264 | pci_release_selected_regions(pdev, | |
8265 | pci_select_bars(pdev, IORESOURCE_MEM)); | |
8266 | err_pci_reg: | |
8267 | err_dma: | |
8268 | pci_disable_device(pdev); | |
8269 | return err; | |
8270 | } | |
8271 | ||
8272 | /** | |
8273 | * i40e_remove - Device removal routine | |
8274 | * @pdev: PCI device information struct | |
8275 | * | |
8276 | * i40e_remove is called by the PCI subsystem to alert the driver | |
8277 | * that is should release a PCI device. This could be caused by a | |
8278 | * Hot-Plug event, or because the driver is going to be removed from | |
8279 | * memory. | |
8280 | **/ | |
8281 | static void i40e_remove(struct pci_dev *pdev) | |
8282 | { | |
8283 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
8284 | i40e_status ret_code; | |
8285 | u32 reg; | |
8286 | int i; | |
8287 | ||
8288 | i40e_dbg_pf_exit(pf); | |
8289 | ||
beb0dff1 JK |
8290 | i40e_ptp_stop(pf); |
8291 | ||
41c445ff JB |
8292 | /* no more scheduling of any task */ |
8293 | set_bit(__I40E_DOWN, &pf->state); | |
8294 | del_timer_sync(&pf->service_timer); | |
8295 | cancel_work_sync(&pf->service_task); | |
8296 | ||
eb2d80bc MW |
8297 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
8298 | i40e_free_vfs(pf); | |
8299 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; | |
8300 | } | |
8301 | ||
41c445ff JB |
8302 | i40e_fdir_teardown(pf); |
8303 | ||
8304 | /* If there is a switch structure or any orphans, remove them. | |
8305 | * This will leave only the PF's VSI remaining. | |
8306 | */ | |
8307 | for (i = 0; i < I40E_MAX_VEB; i++) { | |
8308 | if (!pf->veb[i]) | |
8309 | continue; | |
8310 | ||
8311 | if (pf->veb[i]->uplink_seid == pf->mac_seid || | |
8312 | pf->veb[i]->uplink_seid == 0) | |
8313 | i40e_switch_branch_release(pf->veb[i]); | |
8314 | } | |
8315 | ||
8316 | /* Now we can shutdown the PF's VSI, just before we kill | |
8317 | * adminq and hmc. | |
8318 | */ | |
8319 | if (pf->vsi[pf->lan_vsi]) | |
8320 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); | |
8321 | ||
8322 | i40e_stop_misc_vector(pf); | |
8323 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | |
8324 | synchronize_irq(pf->msix_entries[0].vector); | |
8325 | free_irq(pf->msix_entries[0].vector, pf); | |
8326 | } | |
8327 | ||
8328 | /* shutdown and destroy the HMC */ | |
8329 | ret_code = i40e_shutdown_lan_hmc(&pf->hw); | |
8330 | if (ret_code) | |
8331 | dev_warn(&pdev->dev, | |
8332 | "Failed to destroy the HMC resources: %d\n", ret_code); | |
8333 | ||
8334 | /* shutdown the adminq */ | |
41c445ff JB |
8335 | ret_code = i40e_shutdown_adminq(&pf->hw); |
8336 | if (ret_code) | |
8337 | dev_warn(&pdev->dev, | |
8338 | "Failed to destroy the Admin Queue resources: %d\n", | |
8339 | ret_code); | |
8340 | ||
8341 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ | |
8342 | i40e_clear_interrupt_scheme(pf); | |
8343 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { | |
8344 | if (pf->vsi[i]) { | |
8345 | i40e_vsi_clear_rings(pf->vsi[i]); | |
8346 | i40e_vsi_clear(pf->vsi[i]); | |
8347 | pf->vsi[i] = NULL; | |
8348 | } | |
8349 | } | |
8350 | ||
8351 | for (i = 0; i < I40E_MAX_VEB; i++) { | |
8352 | kfree(pf->veb[i]); | |
8353 | pf->veb[i] = NULL; | |
8354 | } | |
8355 | ||
8356 | kfree(pf->qp_pile); | |
8357 | kfree(pf->irq_pile); | |
8358 | kfree(pf->sw_config); | |
8359 | kfree(pf->vsi); | |
8360 | ||
8361 | /* force a PF reset to clean anything leftover */ | |
8362 | reg = rd32(&pf->hw, I40E_PFGEN_CTRL); | |
8363 | wr32(&pf->hw, I40E_PFGEN_CTRL, (reg | I40E_PFGEN_CTRL_PFSWR_MASK)); | |
8364 | i40e_flush(&pf->hw); | |
8365 | ||
8366 | iounmap(pf->hw.hw_addr); | |
8367 | kfree(pf); | |
8368 | pci_release_selected_regions(pdev, | |
8369 | pci_select_bars(pdev, IORESOURCE_MEM)); | |
8370 | ||
8371 | pci_disable_pcie_error_reporting(pdev); | |
8372 | pci_disable_device(pdev); | |
8373 | } | |
8374 | ||
8375 | /** | |
8376 | * i40e_pci_error_detected - warning that something funky happened in PCI land | |
8377 | * @pdev: PCI device information struct | |
8378 | * | |
8379 | * Called to warn that something happened and the error handling steps | |
8380 | * are in progress. Allows the driver to quiesce things, be ready for | |
8381 | * remediation. | |
8382 | **/ | |
8383 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, | |
8384 | enum pci_channel_state error) | |
8385 | { | |
8386 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
8387 | ||
8388 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); | |
8389 | ||
8390 | /* shutdown all operations */ | |
9007bccd SN |
8391 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
8392 | rtnl_lock(); | |
8393 | i40e_prep_for_reset(pf); | |
8394 | rtnl_unlock(); | |
8395 | } | |
41c445ff JB |
8396 | |
8397 | /* Request a slot reset */ | |
8398 | return PCI_ERS_RESULT_NEED_RESET; | |
8399 | } | |
8400 | ||
8401 | /** | |
8402 | * i40e_pci_error_slot_reset - a PCI slot reset just happened | |
8403 | * @pdev: PCI device information struct | |
8404 | * | |
8405 | * Called to find if the driver can work with the device now that | |
8406 | * the pci slot has been reset. If a basic connection seems good | |
8407 | * (registers are readable and have sane content) then return a | |
8408 | * happy little PCI_ERS_RESULT_xxx. | |
8409 | **/ | |
8410 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) | |
8411 | { | |
8412 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
8413 | pci_ers_result_t result; | |
8414 | int err; | |
8415 | u32 reg; | |
8416 | ||
8417 | dev_info(&pdev->dev, "%s\n", __func__); | |
8418 | if (pci_enable_device_mem(pdev)) { | |
8419 | dev_info(&pdev->dev, | |
8420 | "Cannot re-enable PCI device after reset.\n"); | |
8421 | result = PCI_ERS_RESULT_DISCONNECT; | |
8422 | } else { | |
8423 | pci_set_master(pdev); | |
8424 | pci_restore_state(pdev); | |
8425 | pci_save_state(pdev); | |
8426 | pci_wake_from_d3(pdev, false); | |
8427 | ||
8428 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); | |
8429 | if (reg == 0) | |
8430 | result = PCI_ERS_RESULT_RECOVERED; | |
8431 | else | |
8432 | result = PCI_ERS_RESULT_DISCONNECT; | |
8433 | } | |
8434 | ||
8435 | err = pci_cleanup_aer_uncorrect_error_status(pdev); | |
8436 | if (err) { | |
8437 | dev_info(&pdev->dev, | |
8438 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", | |
8439 | err); | |
8440 | /* non-fatal, continue */ | |
8441 | } | |
8442 | ||
8443 | return result; | |
8444 | } | |
8445 | ||
8446 | /** | |
8447 | * i40e_pci_error_resume - restart operations after PCI error recovery | |
8448 | * @pdev: PCI device information struct | |
8449 | * | |
8450 | * Called to allow the driver to bring things back up after PCI error | |
8451 | * and/or reset recovery has finished. | |
8452 | **/ | |
8453 | static void i40e_pci_error_resume(struct pci_dev *pdev) | |
8454 | { | |
8455 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
8456 | ||
8457 | dev_info(&pdev->dev, "%s\n", __func__); | |
9007bccd SN |
8458 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
8459 | return; | |
8460 | ||
8461 | rtnl_lock(); | |
41c445ff | 8462 | i40e_handle_reset_warning(pf); |
9007bccd SN |
8463 | rtnl_lock(); |
8464 | } | |
8465 | ||
8466 | /** | |
8467 | * i40e_shutdown - PCI callback for shutting down | |
8468 | * @pdev: PCI device information struct | |
8469 | **/ | |
8470 | static void i40e_shutdown(struct pci_dev *pdev) | |
8471 | { | |
8472 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
8e2773ae | 8473 | struct i40e_hw *hw = &pf->hw; |
9007bccd SN |
8474 | |
8475 | set_bit(__I40E_SUSPENDED, &pf->state); | |
8476 | set_bit(__I40E_DOWN, &pf->state); | |
8477 | rtnl_lock(); | |
8478 | i40e_prep_for_reset(pf); | |
8479 | rtnl_unlock(); | |
8480 | ||
8e2773ae SN |
8481 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
8482 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); | |
8483 | ||
9007bccd | 8484 | if (system_state == SYSTEM_POWER_OFF) { |
8e2773ae | 8485 | pci_wake_from_d3(pdev, pf->wol_en); |
9007bccd SN |
8486 | pci_set_power_state(pdev, PCI_D3hot); |
8487 | } | |
8488 | } | |
8489 | ||
8490 | #ifdef CONFIG_PM | |
8491 | /** | |
8492 | * i40e_suspend - PCI callback for moving to D3 | |
8493 | * @pdev: PCI device information struct | |
8494 | **/ | |
8495 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) | |
8496 | { | |
8497 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
8e2773ae | 8498 | struct i40e_hw *hw = &pf->hw; |
9007bccd SN |
8499 | |
8500 | set_bit(__I40E_SUSPENDED, &pf->state); | |
8501 | set_bit(__I40E_DOWN, &pf->state); | |
8502 | rtnl_lock(); | |
8503 | i40e_prep_for_reset(pf); | |
8504 | rtnl_unlock(); | |
8505 | ||
8e2773ae SN |
8506 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
8507 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); | |
8508 | ||
8509 | pci_wake_from_d3(pdev, pf->wol_en); | |
9007bccd SN |
8510 | pci_set_power_state(pdev, PCI_D3hot); |
8511 | ||
8512 | return 0; | |
41c445ff JB |
8513 | } |
8514 | ||
9007bccd SN |
8515 | /** |
8516 | * i40e_resume - PCI callback for waking up from D3 | |
8517 | * @pdev: PCI device information struct | |
8518 | **/ | |
8519 | static int i40e_resume(struct pci_dev *pdev) | |
8520 | { | |
8521 | struct i40e_pf *pf = pci_get_drvdata(pdev); | |
8522 | u32 err; | |
8523 | ||
8524 | pci_set_power_state(pdev, PCI_D0); | |
8525 | pci_restore_state(pdev); | |
8526 | /* pci_restore_state() clears dev->state_saves, so | |
8527 | * call pci_save_state() again to restore it. | |
8528 | */ | |
8529 | pci_save_state(pdev); | |
8530 | ||
8531 | err = pci_enable_device_mem(pdev); | |
8532 | if (err) { | |
8533 | dev_err(&pdev->dev, | |
8534 | "%s: Cannot enable PCI device from suspend\n", | |
8535 | __func__); | |
8536 | return err; | |
8537 | } | |
8538 | pci_set_master(pdev); | |
8539 | ||
8540 | /* no wakeup events while running */ | |
8541 | pci_wake_from_d3(pdev, false); | |
8542 | ||
8543 | /* handling the reset will rebuild the device state */ | |
8544 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { | |
8545 | clear_bit(__I40E_DOWN, &pf->state); | |
8546 | rtnl_lock(); | |
8547 | i40e_reset_and_rebuild(pf, false); | |
8548 | rtnl_unlock(); | |
8549 | } | |
8550 | ||
8551 | return 0; | |
8552 | } | |
8553 | ||
8554 | #endif | |
41c445ff JB |
8555 | static const struct pci_error_handlers i40e_err_handler = { |
8556 | .error_detected = i40e_pci_error_detected, | |
8557 | .slot_reset = i40e_pci_error_slot_reset, | |
8558 | .resume = i40e_pci_error_resume, | |
8559 | }; | |
8560 | ||
8561 | static struct pci_driver i40e_driver = { | |
8562 | .name = i40e_driver_name, | |
8563 | .id_table = i40e_pci_tbl, | |
8564 | .probe = i40e_probe, | |
8565 | .remove = i40e_remove, | |
9007bccd SN |
8566 | #ifdef CONFIG_PM |
8567 | .suspend = i40e_suspend, | |
8568 | .resume = i40e_resume, | |
8569 | #endif | |
8570 | .shutdown = i40e_shutdown, | |
41c445ff JB |
8571 | .err_handler = &i40e_err_handler, |
8572 | .sriov_configure = i40e_pci_sriov_configure, | |
8573 | }; | |
8574 | ||
8575 | /** | |
8576 | * i40e_init_module - Driver registration routine | |
8577 | * | |
8578 | * i40e_init_module is the first routine called when the driver is | |
8579 | * loaded. All it does is register with the PCI subsystem. | |
8580 | **/ | |
8581 | static int __init i40e_init_module(void) | |
8582 | { | |
8583 | pr_info("%s: %s - version %s\n", i40e_driver_name, | |
8584 | i40e_driver_string, i40e_driver_version_str); | |
8585 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); | |
8586 | i40e_dbg_init(); | |
8587 | return pci_register_driver(&i40e_driver); | |
8588 | } | |
8589 | module_init(i40e_init_module); | |
8590 | ||
8591 | /** | |
8592 | * i40e_exit_module - Driver exit cleanup routine | |
8593 | * | |
8594 | * i40e_exit_module is called just before the driver is removed | |
8595 | * from memory. | |
8596 | **/ | |
8597 | static void __exit i40e_exit_module(void) | |
8598 | { | |
8599 | pci_unregister_driver(&i40e_driver); | |
8600 | i40e_dbg_exit(); | |
8601 | } | |
8602 | module_exit(i40e_exit_module); |