]>
Commit | Line | Data |
---|---|---|
5eae00c5 GR |
1 | /******************************************************************************* |
2 | * | |
3 | * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver | |
5b8eb176 | 4 | * Copyright(c) 2013 - 2015 Intel Corporation. |
5eae00c5 GR |
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 | * | |
b831607d JB |
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/>. | |
17 | * | |
5eae00c5 GR |
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 | #include "i40evf.h" | |
28 | #include "i40e_prototype.h" | |
29 | static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter); | |
30 | static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter); | |
31 | static int i40evf_close(struct net_device *netdev); | |
32 | ||
33 | char i40evf_driver_name[] = "i40evf"; | |
34 | static const char i40evf_driver_string[] = | |
0af56f44 | 35 | "Intel(R) XL710/X710 Virtual Function Network Driver"; |
5eae00c5 | 36 | |
0e320516 | 37 | #define DRV_VERSION "1.3.33" |
5eae00c5 GR |
38 | const char i40evf_driver_version[] = DRV_VERSION; |
39 | static const char i40evf_copyright[] = | |
bf41846e | 40 | "Copyright (c) 2013 - 2015 Intel Corporation."; |
5eae00c5 GR |
41 | |
42 | /* i40evf_pci_tbl - PCI Device ID Table | |
43 | * | |
44 | * Wildcard entries (PCI_ANY_ID) should come last | |
45 | * Last entry must be all 0s | |
46 | * | |
47 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, | |
48 | * Class, Class Mask, private data (not used) } | |
49 | */ | |
9baa3c34 | 50 | static const struct pci_device_id i40evf_pci_tbl[] = { |
ab60085e | 51 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0}, |
87e6c1d7 | 52 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_X722_VF), 0}, |
5eae00c5 GR |
53 | /* required last entry */ |
54 | {0, } | |
55 | }; | |
56 | ||
57 | MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl); | |
58 | ||
59 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); | |
60 | MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver"); | |
61 | MODULE_LICENSE("GPL"); | |
62 | MODULE_VERSION(DRV_VERSION); | |
63 | ||
64 | /** | |
65 | * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code | |
66 | * @hw: pointer to the HW structure | |
67 | * @mem: ptr to mem struct to fill out | |
68 | * @size: size of memory requested | |
69 | * @alignment: what to align the allocation to | |
70 | **/ | |
71 | i40e_status i40evf_allocate_dma_mem_d(struct i40e_hw *hw, | |
72 | struct i40e_dma_mem *mem, | |
73 | u64 size, u32 alignment) | |
74 | { | |
75 | struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back; | |
76 | ||
77 | if (!mem) | |
78 | return I40E_ERR_PARAM; | |
79 | ||
80 | mem->size = ALIGN(size, alignment); | |
81 | mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size, | |
82 | (dma_addr_t *)&mem->pa, GFP_KERNEL); | |
83 | if (mem->va) | |
84 | return 0; | |
85 | else | |
86 | return I40E_ERR_NO_MEMORY; | |
87 | } | |
88 | ||
89 | /** | |
90 | * i40evf_free_dma_mem_d - OS specific memory free for shared code | |
91 | * @hw: pointer to the HW structure | |
92 | * @mem: ptr to mem struct to free | |
93 | **/ | |
94 | i40e_status i40evf_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) | |
95 | { | |
96 | struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back; | |
97 | ||
98 | if (!mem || !mem->va) | |
99 | return I40E_ERR_PARAM; | |
100 | dma_free_coherent(&adapter->pdev->dev, mem->size, | |
101 | mem->va, (dma_addr_t)mem->pa); | |
102 | return 0; | |
103 | } | |
104 | ||
105 | /** | |
106 | * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code | |
107 | * @hw: pointer to the HW structure | |
108 | * @mem: ptr to mem struct to fill out | |
109 | * @size: size of memory requested | |
110 | **/ | |
111 | i40e_status i40evf_allocate_virt_mem_d(struct i40e_hw *hw, | |
112 | struct i40e_virt_mem *mem, u32 size) | |
113 | { | |
114 | if (!mem) | |
115 | return I40E_ERR_PARAM; | |
116 | ||
117 | mem->size = size; | |
118 | mem->va = kzalloc(size, GFP_KERNEL); | |
119 | ||
120 | if (mem->va) | |
121 | return 0; | |
122 | else | |
123 | return I40E_ERR_NO_MEMORY; | |
124 | } | |
125 | ||
126 | /** | |
127 | * i40evf_free_virt_mem_d - OS specific memory free for shared code | |
128 | * @hw: pointer to the HW structure | |
129 | * @mem: ptr to mem struct to free | |
130 | **/ | |
131 | i40e_status i40evf_free_virt_mem_d(struct i40e_hw *hw, | |
132 | struct i40e_virt_mem *mem) | |
133 | { | |
134 | if (!mem) | |
135 | return I40E_ERR_PARAM; | |
136 | ||
137 | /* it's ok to kfree a NULL pointer */ | |
138 | kfree(mem->va); | |
139 | ||
140 | return 0; | |
141 | } | |
142 | ||
143 | /** | |
144 | * i40evf_debug_d - OS dependent version of debug printing | |
145 | * @hw: pointer to the HW structure | |
146 | * @mask: debug level mask | |
147 | * @fmt_str: printf-type format description | |
148 | **/ | |
149 | void i40evf_debug_d(void *hw, u32 mask, char *fmt_str, ...) | |
150 | { | |
151 | char buf[512]; | |
152 | va_list argptr; | |
153 | ||
154 | if (!(mask & ((struct i40e_hw *)hw)->debug_mask)) | |
155 | return; | |
156 | ||
157 | va_start(argptr, fmt_str); | |
158 | vsnprintf(buf, sizeof(buf), fmt_str, argptr); | |
159 | va_end(argptr); | |
160 | ||
161 | /* the debug string is already formatted with a newline */ | |
162 | pr_info("%s", buf); | |
163 | } | |
164 | ||
165 | /** | |
166 | * i40evf_tx_timeout - Respond to a Tx Hang | |
167 | * @netdev: network interface device structure | |
168 | **/ | |
169 | static void i40evf_tx_timeout(struct net_device *netdev) | |
170 | { | |
171 | struct i40evf_adapter *adapter = netdev_priv(netdev); | |
172 | ||
173 | adapter->tx_timeout_count++; | |
67c818a1 MW |
174 | if (!(adapter->flags & (I40EVF_FLAG_RESET_PENDING | |
175 | I40EVF_FLAG_RESET_NEEDED))) { | |
3526d800 | 176 | adapter->flags |= I40EVF_FLAG_RESET_NEEDED; |
625777e3 MW |
177 | schedule_work(&adapter->reset_task); |
178 | } | |
5eae00c5 GR |
179 | } |
180 | ||
181 | /** | |
182 | * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC | |
183 | * @adapter: board private structure | |
184 | **/ | |
185 | static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter) | |
186 | { | |
187 | struct i40e_hw *hw = &adapter->hw; | |
75a64435 | 188 | |
5eae00c5 GR |
189 | wr32(hw, I40E_VFINT_DYN_CTL01, 0); |
190 | ||
191 | /* read flush */ | |
192 | rd32(hw, I40E_VFGEN_RSTAT); | |
193 | ||
194 | synchronize_irq(adapter->msix_entries[0].vector); | |
195 | } | |
196 | ||
197 | /** | |
198 | * i40evf_misc_irq_enable - Enable default interrupt generation settings | |
199 | * @adapter: board private structure | |
200 | **/ | |
201 | static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter) | |
202 | { | |
203 | struct i40e_hw *hw = &adapter->hw; | |
75a64435 | 204 | |
5eae00c5 GR |
205 | wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK | |
206 | I40E_VFINT_DYN_CTL01_ITR_INDX_MASK); | |
b1f3366b | 207 | wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA1_ADMINQ_MASK); |
5eae00c5 GR |
208 | |
209 | /* read flush */ | |
210 | rd32(hw, I40E_VFGEN_RSTAT); | |
211 | } | |
212 | ||
213 | /** | |
214 | * i40evf_irq_disable - Mask off interrupt generation on the NIC | |
215 | * @adapter: board private structure | |
216 | **/ | |
217 | static void i40evf_irq_disable(struct i40evf_adapter *adapter) | |
218 | { | |
219 | int i; | |
220 | struct i40e_hw *hw = &adapter->hw; | |
221 | ||
dbb01c8a MW |
222 | if (!adapter->msix_entries) |
223 | return; | |
224 | ||
5eae00c5 GR |
225 | for (i = 1; i < adapter->num_msix_vectors; i++) { |
226 | wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0); | |
227 | synchronize_irq(adapter->msix_entries[i].vector); | |
228 | } | |
229 | /* read flush */ | |
230 | rd32(hw, I40E_VFGEN_RSTAT); | |
5eae00c5 GR |
231 | } |
232 | ||
233 | /** | |
234 | * i40evf_irq_enable_queues - Enable interrupt for specified queues | |
235 | * @adapter: board private structure | |
236 | * @mask: bitmap of queues to enable | |
237 | **/ | |
238 | void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask) | |
239 | { | |
240 | struct i40e_hw *hw = &adapter->hw; | |
241 | int i; | |
242 | ||
243 | for (i = 1; i < adapter->num_msix_vectors; i++) { | |
41a1d04b | 244 | if (mask & BIT(i - 1)) { |
5eae00c5 GR |
245 | wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), |
246 | I40E_VFINT_DYN_CTLN1_INTENA_MASK | | |
97bf75f1 | 247 | I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK | |
b1f3366b | 248 | I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK); |
5eae00c5 GR |
249 | } |
250 | } | |
251 | } | |
252 | ||
253 | /** | |
254 | * i40evf_fire_sw_int - Generate SW interrupt for specified vectors | |
255 | * @adapter: board private structure | |
256 | * @mask: bitmap of vectors to trigger | |
257 | **/ | |
75a64435 | 258 | static void i40evf_fire_sw_int(struct i40evf_adapter *adapter, u32 mask) |
5eae00c5 GR |
259 | { |
260 | struct i40e_hw *hw = &adapter->hw; | |
261 | int i; | |
262 | uint32_t dyn_ctl; | |
263 | ||
164ec1bf MW |
264 | if (mask & 1) { |
265 | dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTL01); | |
b1f3366b | 266 | dyn_ctl |= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK | |
97bf75f1 | 267 | I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK | |
b1f3366b | 268 | I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK; |
164ec1bf MW |
269 | wr32(hw, I40E_VFINT_DYN_CTL01, dyn_ctl); |
270 | } | |
5eae00c5 | 271 | for (i = 1; i < adapter->num_msix_vectors; i++) { |
41a1d04b | 272 | if (mask & BIT(i)) { |
5eae00c5 | 273 | dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1)); |
b1f3366b | 274 | dyn_ctl |= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK | |
97bf75f1 | 275 | I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK | |
b1f3366b | 276 | I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK; |
5eae00c5 GR |
277 | wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl); |
278 | } | |
279 | } | |
280 | } | |
281 | ||
282 | /** | |
283 | * i40evf_irq_enable - Enable default interrupt generation settings | |
284 | * @adapter: board private structure | |
69c1d70a | 285 | * @flush: boolean value whether to run rd32() |
5eae00c5 GR |
286 | **/ |
287 | void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush) | |
288 | { | |
289 | struct i40e_hw *hw = &adapter->hw; | |
290 | ||
164ec1bf | 291 | i40evf_misc_irq_enable(adapter); |
5eae00c5 GR |
292 | i40evf_irq_enable_queues(adapter, ~0); |
293 | ||
294 | if (flush) | |
295 | rd32(hw, I40E_VFGEN_RSTAT); | |
296 | } | |
297 | ||
298 | /** | |
299 | * i40evf_msix_aq - Interrupt handler for vector 0 | |
300 | * @irq: interrupt number | |
301 | * @data: pointer to netdev | |
302 | **/ | |
303 | static irqreturn_t i40evf_msix_aq(int irq, void *data) | |
304 | { | |
305 | struct net_device *netdev = data; | |
306 | struct i40evf_adapter *adapter = netdev_priv(netdev); | |
307 | struct i40e_hw *hw = &adapter->hw; | |
308 | u32 val; | |
5eae00c5 | 309 | |
cfbe4dba JB |
310 | /* handle non-queue interrupts, these reads clear the registers */ |
311 | val = rd32(hw, I40E_VFINT_ICR01); | |
312 | val = rd32(hw, I40E_VFINT_ICR0_ENA1); | |
5eae00c5 | 313 | |
ed17f7e5 JS |
314 | val = rd32(hw, I40E_VFINT_DYN_CTL01) | |
315 | I40E_VFINT_DYN_CTL01_CLEARPBA_MASK; | |
5eae00c5 GR |
316 | wr32(hw, I40E_VFINT_DYN_CTL01, val); |
317 | ||
5eae00c5 GR |
318 | /* schedule work on the private workqueue */ |
319 | schedule_work(&adapter->adminq_task); | |
320 | ||
321 | return IRQ_HANDLED; | |
322 | } | |
323 | ||
324 | /** | |
325 | * i40evf_msix_clean_rings - MSIX mode Interrupt Handler | |
326 | * @irq: interrupt number | |
327 | * @data: pointer to a q_vector | |
328 | **/ | |
329 | static irqreturn_t i40evf_msix_clean_rings(int irq, void *data) | |
330 | { | |
331 | struct i40e_q_vector *q_vector = data; | |
332 | ||
333 | if (!q_vector->tx.ring && !q_vector->rx.ring) | |
334 | return IRQ_HANDLED; | |
335 | ||
5d3465a1 | 336 | napi_schedule_irqoff(&q_vector->napi); |
5eae00c5 GR |
337 | |
338 | return IRQ_HANDLED; | |
339 | } | |
340 | ||
341 | /** | |
342 | * i40evf_map_vector_to_rxq - associate irqs with rx queues | |
343 | * @adapter: board private structure | |
344 | * @v_idx: interrupt number | |
345 | * @r_idx: queue number | |
346 | **/ | |
347 | static void | |
348 | i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx) | |
349 | { | |
350 | struct i40e_q_vector *q_vector = adapter->q_vector[v_idx]; | |
351 | struct i40e_ring *rx_ring = adapter->rx_rings[r_idx]; | |
352 | ||
353 | rx_ring->q_vector = q_vector; | |
354 | rx_ring->next = q_vector->rx.ring; | |
355 | rx_ring->vsi = &adapter->vsi; | |
356 | q_vector->rx.ring = rx_ring; | |
357 | q_vector->rx.count++; | |
358 | q_vector->rx.latency_range = I40E_LOW_LATENCY; | |
ee2319cf | 359 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
5eae00c5 GR |
360 | } |
361 | ||
362 | /** | |
363 | * i40evf_map_vector_to_txq - associate irqs with tx queues | |
364 | * @adapter: board private structure | |
365 | * @v_idx: interrupt number | |
366 | * @t_idx: queue number | |
367 | **/ | |
368 | static void | |
369 | i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx) | |
370 | { | |
371 | struct i40e_q_vector *q_vector = adapter->q_vector[v_idx]; | |
372 | struct i40e_ring *tx_ring = adapter->tx_rings[t_idx]; | |
373 | ||
374 | tx_ring->q_vector = q_vector; | |
375 | tx_ring->next = q_vector->tx.ring; | |
376 | tx_ring->vsi = &adapter->vsi; | |
377 | q_vector->tx.ring = tx_ring; | |
378 | q_vector->tx.count++; | |
379 | q_vector->tx.latency_range = I40E_LOW_LATENCY; | |
ee2319cf | 380 | q_vector->itr_countdown = ITR_COUNTDOWN_START; |
5eae00c5 | 381 | q_vector->num_ringpairs++; |
41a1d04b | 382 | q_vector->ring_mask |= BIT(t_idx); |
5eae00c5 GR |
383 | } |
384 | ||
385 | /** | |
386 | * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors | |
387 | * @adapter: board private structure to initialize | |
388 | * | |
389 | * This function maps descriptor rings to the queue-specific vectors | |
390 | * we were allotted through the MSI-X enabling code. Ideally, we'd have | |
391 | * one vector per ring/queue, but on a constrained vector budget, we | |
392 | * group the rings as "efficiently" as possible. You would add new | |
393 | * mapping configurations in here. | |
394 | **/ | |
395 | static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter) | |
396 | { | |
397 | int q_vectors; | |
398 | int v_start = 0; | |
399 | int rxr_idx = 0, txr_idx = 0; | |
cc052927 MW |
400 | int rxr_remaining = adapter->num_active_queues; |
401 | int txr_remaining = adapter->num_active_queues; | |
5eae00c5 GR |
402 | int i, j; |
403 | int rqpv, tqpv; | |
404 | int err = 0; | |
405 | ||
406 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; | |
407 | ||
408 | /* The ideal configuration... | |
409 | * We have enough vectors to map one per queue. | |
410 | */ | |
973371da | 411 | if (q_vectors >= (rxr_remaining * 2)) { |
5eae00c5 GR |
412 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
413 | i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx); | |
414 | ||
415 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) | |
416 | i40evf_map_vector_to_txq(adapter, v_start, txr_idx); | |
417 | goto out; | |
418 | } | |
419 | ||
420 | /* If we don't have enough vectors for a 1-to-1 | |
421 | * mapping, we'll have to group them so there are | |
422 | * multiple queues per vector. | |
423 | * Re-adjusting *qpv takes care of the remainder. | |
424 | */ | |
425 | for (i = v_start; i < q_vectors; i++) { | |
426 | rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i); | |
427 | for (j = 0; j < rqpv; j++) { | |
428 | i40evf_map_vector_to_rxq(adapter, i, rxr_idx); | |
429 | rxr_idx++; | |
430 | rxr_remaining--; | |
431 | } | |
432 | } | |
433 | for (i = v_start; i < q_vectors; i++) { | |
434 | tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i); | |
435 | for (j = 0; j < tqpv; j++) { | |
436 | i40evf_map_vector_to_txq(adapter, i, txr_idx); | |
437 | txr_idx++; | |
438 | txr_remaining--; | |
439 | } | |
440 | } | |
441 | ||
442 | out: | |
443 | adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS; | |
444 | ||
445 | return err; | |
446 | } | |
447 | ||
7709b4c1 AD |
448 | #ifdef CONFIG_NET_POLL_CONTROLLER |
449 | /** | |
450 | * i40evf_netpoll - A Polling 'interrupt' handler | |
451 | * @netdev: network interface device structure | |
452 | * | |
453 | * This is used by netconsole to send skbs without having to re-enable | |
454 | * interrupts. It's not called while the normal interrupt routine is executing. | |
455 | **/ | |
456 | static void i40evf_netpoll(struct net_device *netdev) | |
457 | { | |
458 | struct i40evf_adapter *adapter = netdev_priv(netdev); | |
459 | int q_vectors = adapter->num_msix_vectors - NONQ_VECS; | |
460 | int i; | |
461 | ||
462 | /* if interface is down do nothing */ | |
463 | if (test_bit(__I40E_DOWN, &adapter->vsi.state)) | |
464 | return; | |
465 | ||
466 | for (i = 0; i < q_vectors; i++) | |
467 | i40evf_msix_clean_rings(0, adapter->q_vector[i]); | |
468 | } | |
469 | ||
470 | #endif | |
5eae00c5 GR |
471 | /** |
472 | * i40evf_request_traffic_irqs - Initialize MSI-X interrupts | |
473 | * @adapter: board private structure | |
474 | * | |
475 | * Allocates MSI-X vectors for tx and rx handling, and requests | |
476 | * interrupts from the kernel. | |
477 | **/ | |
478 | static int | |
479 | i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename) | |
480 | { | |
481 | int vector, err, q_vectors; | |
482 | int rx_int_idx = 0, tx_int_idx = 0; | |
483 | ||
484 | i40evf_irq_disable(adapter); | |
485 | /* Decrement for Other and TCP Timer vectors */ | |
486 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; | |
487 | ||
488 | for (vector = 0; vector < q_vectors; vector++) { | |
489 | struct i40e_q_vector *q_vector = adapter->q_vector[vector]; | |
490 | ||
491 | if (q_vector->tx.ring && q_vector->rx.ring) { | |
492 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, | |
493 | "i40evf-%s-%s-%d", basename, | |
494 | "TxRx", rx_int_idx++); | |
495 | tx_int_idx++; | |
496 | } else if (q_vector->rx.ring) { | |
497 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, | |
498 | "i40evf-%s-%s-%d", basename, | |
499 | "rx", rx_int_idx++); | |
500 | } else if (q_vector->tx.ring) { | |
501 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, | |
502 | "i40evf-%s-%s-%d", basename, | |
503 | "tx", tx_int_idx++); | |
504 | } else { | |
505 | /* skip this unused q_vector */ | |
506 | continue; | |
507 | } | |
508 | err = request_irq( | |
509 | adapter->msix_entries[vector + NONQ_VECS].vector, | |
510 | i40evf_msix_clean_rings, | |
511 | 0, | |
512 | q_vector->name, | |
513 | q_vector); | |
514 | if (err) { | |
515 | dev_info(&adapter->pdev->dev, | |
fb43201f | 516 | "Request_irq failed, error: %d\n", err); |
5eae00c5 GR |
517 | goto free_queue_irqs; |
518 | } | |
519 | /* assign the mask for this irq */ | |
520 | irq_set_affinity_hint( | |
521 | adapter->msix_entries[vector + NONQ_VECS].vector, | |
522 | q_vector->affinity_mask); | |
523 | } | |
524 | ||
525 | return 0; | |
526 | ||
527 | free_queue_irqs: | |
528 | while (vector) { | |
529 | vector--; | |
530 | irq_set_affinity_hint( | |
531 | adapter->msix_entries[vector + NONQ_VECS].vector, | |
532 | NULL); | |
533 | free_irq(adapter->msix_entries[vector + NONQ_VECS].vector, | |
534 | adapter->q_vector[vector]); | |
535 | } | |
536 | return err; | |
537 | } | |
538 | ||
539 | /** | |
540 | * i40evf_request_misc_irq - Initialize MSI-X interrupts | |
541 | * @adapter: board private structure | |
542 | * | |
543 | * Allocates MSI-X vector 0 and requests interrupts from the kernel. This | |
544 | * vector is only for the admin queue, and stays active even when the netdev | |
545 | * is closed. | |
546 | **/ | |
547 | static int i40evf_request_misc_irq(struct i40evf_adapter *adapter) | |
548 | { | |
549 | struct net_device *netdev = adapter->netdev; | |
550 | int err; | |
551 | ||
b39c1e2c | 552 | snprintf(adapter->misc_vector_name, |
9a21a007 CW |
553 | sizeof(adapter->misc_vector_name) - 1, "i40evf-%s:mbx", |
554 | dev_name(&adapter->pdev->dev)); | |
5eae00c5 | 555 | err = request_irq(adapter->msix_entries[0].vector, |
e1dfee8e MW |
556 | &i40evf_msix_aq, 0, |
557 | adapter->misc_vector_name, netdev); | |
5eae00c5 GR |
558 | if (err) { |
559 | dev_err(&adapter->pdev->dev, | |
77fa28be CS |
560 | "request_irq for %s failed: %d\n", |
561 | adapter->misc_vector_name, err); | |
5eae00c5 GR |
562 | free_irq(adapter->msix_entries[0].vector, netdev); |
563 | } | |
564 | return err; | |
565 | } | |
566 | ||
567 | /** | |
568 | * i40evf_free_traffic_irqs - Free MSI-X interrupts | |
569 | * @adapter: board private structure | |
570 | * | |
571 | * Frees all MSI-X vectors other than 0. | |
572 | **/ | |
573 | static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter) | |
574 | { | |
575 | int i; | |
576 | int q_vectors; | |
75a64435 | 577 | |
5eae00c5 GR |
578 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
579 | ||
580 | for (i = 0; i < q_vectors; i++) { | |
581 | irq_set_affinity_hint(adapter->msix_entries[i+1].vector, | |
582 | NULL); | |
583 | free_irq(adapter->msix_entries[i+1].vector, | |
584 | adapter->q_vector[i]); | |
585 | } | |
586 | } | |
587 | ||
588 | /** | |
589 | * i40evf_free_misc_irq - Free MSI-X miscellaneous vector | |
590 | * @adapter: board private structure | |
591 | * | |
592 | * Frees MSI-X vector 0. | |
593 | **/ | |
594 | static void i40evf_free_misc_irq(struct i40evf_adapter *adapter) | |
595 | { | |
596 | struct net_device *netdev = adapter->netdev; | |
597 | ||
598 | free_irq(adapter->msix_entries[0].vector, netdev); | |
599 | } | |
600 | ||
601 | /** | |
602 | * i40evf_configure_tx - Configure Transmit Unit after Reset | |
603 | * @adapter: board private structure | |
604 | * | |
605 | * Configure the Tx unit of the MAC after a reset. | |
606 | **/ | |
607 | static void i40evf_configure_tx(struct i40evf_adapter *adapter) | |
608 | { | |
609 | struct i40e_hw *hw = &adapter->hw; | |
610 | int i; | |
75a64435 | 611 | |
cc052927 | 612 | for (i = 0; i < adapter->num_active_queues; i++) |
5eae00c5 GR |
613 | adapter->tx_rings[i]->tail = hw->hw_addr + I40E_QTX_TAIL1(i); |
614 | } | |
615 | ||
616 | /** | |
617 | * i40evf_configure_rx - Configure Receive Unit after Reset | |
618 | * @adapter: board private structure | |
619 | * | |
620 | * Configure the Rx unit of the MAC after a reset. | |
621 | **/ | |
622 | static void i40evf_configure_rx(struct i40evf_adapter *adapter) | |
623 | { | |
624 | struct i40e_hw *hw = &adapter->hw; | |
625 | struct net_device *netdev = adapter->netdev; | |
626 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; | |
627 | int i; | |
628 | int rx_buf_len; | |
629 | ||
630 | ||
631 | adapter->flags &= ~I40EVF_FLAG_RX_PS_CAPABLE; | |
632 | adapter->flags |= I40EVF_FLAG_RX_1BUF_CAPABLE; | |
633 | ||
634 | /* Decide whether to use packet split mode or not */ | |
635 | if (netdev->mtu > ETH_DATA_LEN) { | |
636 | if (adapter->flags & I40EVF_FLAG_RX_PS_CAPABLE) | |
637 | adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED; | |
638 | else | |
639 | adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED; | |
640 | } else { | |
641 | if (adapter->flags & I40EVF_FLAG_RX_1BUF_CAPABLE) | |
642 | adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED; | |
643 | else | |
644 | adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED; | |
645 | } | |
646 | ||
647 | /* Set the RX buffer length according to the mode */ | |
648 | if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) { | |
649 | rx_buf_len = I40E_RX_HDR_SIZE; | |
650 | } else { | |
651 | if (netdev->mtu <= ETH_DATA_LEN) | |
652 | rx_buf_len = I40EVF_RXBUFFER_2048; | |
653 | else | |
654 | rx_buf_len = ALIGN(max_frame, 1024); | |
655 | } | |
656 | ||
cc052927 | 657 | for (i = 0; i < adapter->num_active_queues; i++) { |
5eae00c5 GR |
658 | adapter->rx_rings[i]->tail = hw->hw_addr + I40E_QRX_TAIL1(i); |
659 | adapter->rx_rings[i]->rx_buf_len = rx_buf_len; | |
660 | } | |
661 | } | |
662 | ||
663 | /** | |
664 | * i40evf_find_vlan - Search filter list for specific vlan filter | |
665 | * @adapter: board private structure | |
666 | * @vlan: vlan tag | |
667 | * | |
668 | * Returns ptr to the filter object or NULL | |
669 | **/ | |
670 | static struct | |
671 | i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan) | |
672 | { | |
673 | struct i40evf_vlan_filter *f; | |
674 | ||
675 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { | |
676 | if (vlan == f->vlan) | |
677 | return f; | |
678 | } | |
679 | return NULL; | |
680 | } | |
681 | ||
682 | /** | |
683 | * i40evf_add_vlan - Add a vlan filter to the list | |
684 | * @adapter: board private structure | |
685 | * @vlan: VLAN tag | |
686 | * | |
687 | * Returns ptr to the filter object or NULL when no memory available. | |
688 | **/ | |
689 | static struct | |
690 | i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan) | |
691 | { | |
13acb546 MW |
692 | struct i40evf_vlan_filter *f = NULL; |
693 | int count = 50; | |
694 | ||
695 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, | |
696 | &adapter->crit_section)) { | |
697 | udelay(1); | |
698 | if (--count == 0) | |
699 | goto out; | |
700 | } | |
5eae00c5 GR |
701 | |
702 | f = i40evf_find_vlan(adapter, vlan); | |
348d4994 | 703 | if (!f) { |
5eae00c5 | 704 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
348d4994 | 705 | if (!f) |
13acb546 | 706 | goto clearout; |
249c8b8d | 707 | |
5eae00c5 GR |
708 | f->vlan = vlan; |
709 | ||
710 | INIT_LIST_HEAD(&f->list); | |
711 | list_add(&f->list, &adapter->vlan_filter_list); | |
712 | f->add = true; | |
713 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER; | |
714 | } | |
715 | ||
13acb546 MW |
716 | clearout: |
717 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); | |
718 | out: | |
5eae00c5 GR |
719 | return f; |
720 | } | |
721 | ||
722 | /** | |
723 | * i40evf_del_vlan - Remove a vlan filter from the list | |
724 | * @adapter: board private structure | |
725 | * @vlan: VLAN tag | |
726 | **/ | |
727 | static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan) | |
728 | { | |
729 | struct i40evf_vlan_filter *f; | |
13acb546 MW |
730 | int count = 50; |
731 | ||
732 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, | |
733 | &adapter->crit_section)) { | |
734 | udelay(1); | |
735 | if (--count == 0) | |
736 | return; | |
737 | } | |
5eae00c5 GR |
738 | |
739 | f = i40evf_find_vlan(adapter, vlan); | |
740 | if (f) { | |
741 | f->remove = true; | |
742 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER; | |
743 | } | |
13acb546 | 744 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
5eae00c5 GR |
745 | } |
746 | ||
747 | /** | |
748 | * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device | |
749 | * @netdev: network device struct | |
750 | * @vid: VLAN tag | |
751 | **/ | |
752 | static int i40evf_vlan_rx_add_vid(struct net_device *netdev, | |
75a64435 | 753 | __always_unused __be16 proto, u16 vid) |
5eae00c5 GR |
754 | { |
755 | struct i40evf_adapter *adapter = netdev_priv(netdev); | |
756 | ||
8ed995ff MW |
757 | if (!VLAN_ALLOWED(adapter)) |
758 | return -EIO; | |
5eae00c5 GR |
759 | if (i40evf_add_vlan(adapter, vid) == NULL) |
760 | return -ENOMEM; | |
761 | return 0; | |
762 | } | |
763 | ||
764 | /** | |
765 | * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device | |
766 | * @netdev: network device struct | |
767 | * @vid: VLAN tag | |
768 | **/ | |
769 | static int i40evf_vlan_rx_kill_vid(struct net_device *netdev, | |
75a64435 | 770 | __always_unused __be16 proto, u16 vid) |
5eae00c5 GR |
771 | { |
772 | struct i40evf_adapter *adapter = netdev_priv(netdev); | |
773 | ||
8ed995ff MW |
774 | if (VLAN_ALLOWED(adapter)) { |
775 | i40evf_del_vlan(adapter, vid); | |
776 | return 0; | |
777 | } | |
778 | return -EIO; | |
5eae00c5 GR |
779 | } |
780 | ||
781 | /** | |
782 | * i40evf_find_filter - Search filter list for specific mac filter | |
783 | * @adapter: board private structure | |
784 | * @macaddr: the MAC address | |
785 | * | |
786 | * Returns ptr to the filter object or NULL | |
787 | **/ | |
788 | static struct | |
789 | i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter, | |
790 | u8 *macaddr) | |
791 | { | |
792 | struct i40evf_mac_filter *f; | |
793 | ||
794 | if (!macaddr) | |
795 | return NULL; | |
796 | ||
797 | list_for_each_entry(f, &adapter->mac_filter_list, list) { | |
798 | if (ether_addr_equal(macaddr, f->macaddr)) | |
799 | return f; | |
800 | } | |
801 | return NULL; | |
802 | } | |
803 | ||
804 | /** | |
805 | * i40e_add_filter - Add a mac filter to the filter list | |
806 | * @adapter: board private structure | |
807 | * @macaddr: the MAC address | |
808 | * | |
809 | * Returns ptr to the filter object or NULL when no memory available. | |
810 | **/ | |
811 | static struct | |
812 | i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter, | |
813 | u8 *macaddr) | |
814 | { | |
815 | struct i40evf_mac_filter *f; | |
54e16f64 | 816 | int count = 50; |
5eae00c5 GR |
817 | |
818 | if (!macaddr) | |
819 | return NULL; | |
820 | ||
821 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, | |
54e16f64 | 822 | &adapter->crit_section)) { |
b65476cd | 823 | udelay(1); |
54e16f64 MW |
824 | if (--count == 0) |
825 | return NULL; | |
826 | } | |
5eae00c5 GR |
827 | |
828 | f = i40evf_find_filter(adapter, macaddr); | |
348d4994 | 829 | if (!f) { |
5eae00c5 | 830 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
348d4994 | 831 | if (!f) { |
5eae00c5 GR |
832 | clear_bit(__I40EVF_IN_CRITICAL_TASK, |
833 | &adapter->crit_section); | |
834 | return NULL; | |
835 | } | |
836 | ||
9a173901 | 837 | ether_addr_copy(f->macaddr, macaddr); |
5eae00c5 GR |
838 | |
839 | list_add(&f->list, &adapter->mac_filter_list); | |
840 | f->add = true; | |
841 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER; | |
842 | } | |
843 | ||
844 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); | |
845 | return f; | |
846 | } | |
847 | ||
848 | /** | |
849 | * i40evf_set_mac - NDO callback to set port mac address | |
850 | * @netdev: network interface device structure | |
851 | * @p: pointer to an address structure | |
852 | * | |
853 | * Returns 0 on success, negative on failure | |
854 | **/ | |
855 | static int i40evf_set_mac(struct net_device *netdev, void *p) | |
856 | { | |
857 | struct i40evf_adapter *adapter = netdev_priv(netdev); | |
858 | struct i40e_hw *hw = &adapter->hw; | |
859 | struct i40evf_mac_filter *f; | |
860 | struct sockaddr *addr = p; | |
861 | ||
862 | if (!is_valid_ether_addr(addr->sa_data)) | |
863 | return -EADDRNOTAVAIL; | |
864 | ||
865 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) | |
866 | return 0; | |
867 | ||
14e52ee2 MW |
868 | if (adapter->flags & I40EVF_FLAG_ADDR_SET_BY_PF) |
869 | return -EPERM; | |
870 | ||
871 | f = i40evf_find_filter(adapter, hw->mac.addr); | |
872 | if (f) { | |
873 | f->remove = true; | |
874 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER; | |
875 | } | |
876 | ||
5eae00c5 GR |
877 | f = i40evf_add_filter(adapter, addr->sa_data); |
878 | if (f) { | |
9a173901 GR |
879 | ether_addr_copy(hw->mac.addr, addr->sa_data); |
880 | ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr); | |
5eae00c5 GR |
881 | } |
882 | ||
883 | return (f == NULL) ? -ENOMEM : 0; | |
884 | } | |
885 | ||
886 | /** | |
887 | * i40evf_set_rx_mode - NDO callback to set the netdev filters | |
888 | * @netdev: network interface device structure | |
889 | **/ | |
890 | static void i40evf_set_rx_mode(struct net_device *netdev) | |
891 | { | |
892 | struct i40evf_adapter *adapter = netdev_priv(netdev); | |
893 | struct i40evf_mac_filter *f, *ftmp; | |
894 | struct netdev_hw_addr *uca; | |
895 | struct netdev_hw_addr *mca; | |
2f41f335 | 896 | struct netdev_hw_addr *ha; |
54e16f64 | 897 | int count = 50; |
5eae00c5 GR |
898 | |
899 | /* add addr if not already in the filter list */ | |
900 | netdev_for_each_uc_addr(uca, netdev) { | |
901 | i40evf_add_filter(adapter, uca->addr); | |
902 | } | |
903 | netdev_for_each_mc_addr(mca, netdev) { | |
904 | i40evf_add_filter(adapter, mca->addr); | |
905 | } | |
906 | ||
907 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, | |
54e16f64 | 908 | &adapter->crit_section)) { |
b65476cd | 909 | udelay(1); |
54e16f64 MW |
910 | if (--count == 0) { |
911 | dev_err(&adapter->pdev->dev, | |
912 | "Failed to get lock in %s\n", __func__); | |
913 | return; | |
914 | } | |
915 | } | |
5eae00c5 GR |
916 | /* remove filter if not in netdev list */ |
917 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { | |
2f41f335 SN |
918 | netdev_for_each_mc_addr(mca, netdev) |
919 | if (ether_addr_equal(mca->addr, f->macaddr)) | |
920 | goto bottom_of_search_loop; | |
921 | ||
922 | netdev_for_each_uc_addr(uca, netdev) | |
923 | if (ether_addr_equal(uca->addr, f->macaddr)) | |
924 | goto bottom_of_search_loop; | |
925 | ||
926 | for_each_dev_addr(netdev, ha) | |
927 | if (ether_addr_equal(ha->addr, f->macaddr)) | |
928 | goto bottom_of_search_loop; | |
929 | ||
930 | if (ether_addr_equal(f->macaddr, adapter->hw.mac.addr)) | |
931 | goto bottom_of_search_loop; | |
932 | ||
933 | /* f->macaddr wasn't found in uc, mc, or ha list so delete it */ | |
934 | f->remove = true; | |
935 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER; | |
936 | ||
937 | bottom_of_search_loop: | |
938 | continue; | |
5eae00c5 GR |
939 | } |
940 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); | |
941 | } | |
942 | ||
943 | /** | |
944 | * i40evf_napi_enable_all - enable NAPI on all queue vectors | |
945 | * @adapter: board private structure | |
946 | **/ | |
947 | static void i40evf_napi_enable_all(struct i40evf_adapter *adapter) | |
948 | { | |
949 | int q_idx; | |
950 | struct i40e_q_vector *q_vector; | |
951 | int q_vectors = adapter->num_msix_vectors - NONQ_VECS; | |
952 | ||
953 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { | |
954 | struct napi_struct *napi; | |
75a64435 | 955 | |
5eae00c5 GR |
956 | q_vector = adapter->q_vector[q_idx]; |
957 | napi = &q_vector->napi; | |
958 | napi_enable(napi); | |
959 | } | |
960 | } | |
961 | ||
962 | /** | |
963 | * i40evf_napi_disable_all - disable NAPI on all queue vectors | |
964 | * @adapter: board private structure | |
965 | **/ | |
966 | static void i40evf_napi_disable_all(struct i40evf_adapter *adapter) | |
967 | { | |
968 | int q_idx; | |
969 | struct i40e_q_vector *q_vector; | |
970 | int q_vectors = adapter->num_msix_vectors - NONQ_VECS; | |
971 | ||
972 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { | |
973 | q_vector = adapter->q_vector[q_idx]; | |
974 | napi_disable(&q_vector->napi); | |
975 | } | |
976 | } | |
977 | ||
978 | /** | |
979 | * i40evf_configure - set up transmit and receive data structures | |
980 | * @adapter: board private structure | |
981 | **/ | |
982 | static void i40evf_configure(struct i40evf_adapter *adapter) | |
983 | { | |
984 | struct net_device *netdev = adapter->netdev; | |
985 | int i; | |
986 | ||
987 | i40evf_set_rx_mode(netdev); | |
988 | ||
989 | i40evf_configure_tx(adapter); | |
990 | i40evf_configure_rx(adapter); | |
991 | adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES; | |
992 | ||
cc052927 | 993 | for (i = 0; i < adapter->num_active_queues; i++) { |
5eae00c5 | 994 | struct i40e_ring *ring = adapter->rx_rings[i]; |
75a64435 | 995 | |
a132af24 | 996 | i40evf_alloc_rx_buffers_1buf(ring, ring->count); |
5eae00c5 GR |
997 | ring->next_to_use = ring->count - 1; |
998 | writel(ring->next_to_use, ring->tail); | |
999 | } | |
1000 | } | |
1001 | ||
1002 | /** | |
1003 | * i40evf_up_complete - Finish the last steps of bringing up a connection | |
1004 | * @adapter: board private structure | |
1005 | **/ | |
1006 | static int i40evf_up_complete(struct i40evf_adapter *adapter) | |
1007 | { | |
1008 | adapter->state = __I40EVF_RUNNING; | |
1009 | clear_bit(__I40E_DOWN, &adapter->vsi.state); | |
1010 | ||
1011 | i40evf_napi_enable_all(adapter); | |
1012 | ||
1013 | adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES; | |
1014 | mod_timer_pending(&adapter->watchdog_timer, jiffies + 1); | |
1015 | return 0; | |
1016 | } | |
1017 | ||
5eae00c5 GR |
1018 | /** |
1019 | * i40e_down - Shutdown the connection processing | |
1020 | * @adapter: board private structure | |
1021 | **/ | |
1022 | void i40evf_down(struct i40evf_adapter *adapter) | |
1023 | { | |
1024 | struct net_device *netdev = adapter->netdev; | |
1025 | struct i40evf_mac_filter *f; | |
1026 | ||
ddf0b3a6 MW |
1027 | if (adapter->state == __I40EVF_DOWN) |
1028 | return; | |
1029 | ||
53d0b3ae MW |
1030 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, |
1031 | &adapter->crit_section)) | |
1032 | usleep_range(500, 1000); | |
1033 | ||
63e18c25 MW |
1034 | netif_carrier_off(netdev); |
1035 | netif_tx_disable(netdev); | |
748c434b | 1036 | i40evf_napi_disable_all(adapter); |
63e18c25 | 1037 | i40evf_irq_disable(adapter); |
53d0b3ae | 1038 | |
ef8693eb | 1039 | /* remove all MAC filters */ |
5eae00c5 GR |
1040 | list_for_each_entry(f, &adapter->mac_filter_list, list) { |
1041 | f->remove = true; | |
1042 | } | |
ed1f5b58 MW |
1043 | /* remove all VLAN filters */ |
1044 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { | |
1045 | f->remove = true; | |
1046 | } | |
ef8693eb MW |
1047 | if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) && |
1048 | adapter->state != __I40EVF_RESETTING) { | |
53d0b3ae MW |
1049 | /* cancel any current operation */ |
1050 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; | |
53d0b3ae MW |
1051 | /* Schedule operations to close down the HW. Don't wait |
1052 | * here for this to complete. The watchdog is still running | |
1053 | * and it will take care of this. | |
1054 | */ | |
1055 | adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER; | |
ed1f5b58 | 1056 | adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER; |
ef8693eb | 1057 | adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES; |
ef8693eb | 1058 | } |
5eae00c5 | 1059 | |
53d0b3ae | 1060 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
5eae00c5 GR |
1061 | } |
1062 | ||
1063 | /** | |
1064 | * i40evf_acquire_msix_vectors - Setup the MSIX capability | |
1065 | * @adapter: board private structure | |
1066 | * @vectors: number of vectors to request | |
1067 | * | |
1068 | * Work with the OS to set up the MSIX vectors needed. | |
1069 | * | |
1070 | * Returns 0 on success, negative on failure | |
1071 | **/ | |
1072 | static int | |
1073 | i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors) | |
1074 | { | |
1075 | int err, vector_threshold; | |
1076 | ||
1077 | /* We'll want at least 3 (vector_threshold): | |
1078 | * 0) Other (Admin Queue and link, mostly) | |
1079 | * 1) TxQ[0] Cleanup | |
1080 | * 2) RxQ[0] Cleanup | |
1081 | */ | |
1082 | vector_threshold = MIN_MSIX_COUNT; | |
1083 | ||
1084 | /* The more we get, the more we will assign to Tx/Rx Cleanup | |
1085 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. | |
1086 | * Right now, we simply care about how many we'll get; we'll | |
1087 | * set them up later while requesting irq's. | |
1088 | */ | |
fc2f2f5d AG |
1089 | err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries, |
1090 | vector_threshold, vectors); | |
1091 | if (err < 0) { | |
80e72893 | 1092 | dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n"); |
5eae00c5 GR |
1093 | kfree(adapter->msix_entries); |
1094 | adapter->msix_entries = NULL; | |
fc2f2f5d | 1095 | return err; |
5eae00c5 | 1096 | } |
fc2f2f5d AG |
1097 | |
1098 | /* Adjust for only the vectors we'll use, which is minimum | |
1099 | * of max_msix_q_vectors + NONQ_VECS, or the number of | |
1100 | * vectors we were allocated. | |
1101 | */ | |
1102 | adapter->num_msix_vectors = err; | |
1103 | return 0; | |
5eae00c5 GR |
1104 | } |
1105 | ||
1106 | /** | |
1107 | * i40evf_free_queues - Free memory for all rings | |
1108 | * @adapter: board private structure to initialize | |
1109 | * | |
1110 | * Free all of the memory associated with queue pairs. | |
1111 | **/ | |
1112 | static void i40evf_free_queues(struct i40evf_adapter *adapter) | |
1113 | { | |
1114 | int i; | |
1115 | ||
1116 | if (!adapter->vsi_res) | |
1117 | return; | |
cc052927 | 1118 | for (i = 0; i < adapter->num_active_queues; i++) { |
5eae00c5 GR |
1119 | if (adapter->tx_rings[i]) |
1120 | kfree_rcu(adapter->tx_rings[i], rcu); | |
1121 | adapter->tx_rings[i] = NULL; | |
1122 | adapter->rx_rings[i] = NULL; | |
1123 | } | |
1124 | } | |
1125 | ||
1126 | /** | |
1127 | * i40evf_alloc_queues - Allocate memory for all rings | |
1128 | * @adapter: board private structure to initialize | |
1129 | * | |
1130 | * We allocate one ring per queue at run-time since we don't know the | |
1131 | * number of queues at compile-time. The polling_netdev array is | |
1132 | * intended for Multiqueue, but should work fine with a single queue. | |
1133 | **/ | |
1134 | static int i40evf_alloc_queues(struct i40evf_adapter *adapter) | |
1135 | { | |
1136 | int i; | |
1137 | ||
cc052927 | 1138 | for (i = 0; i < adapter->num_active_queues; i++) { |
5eae00c5 GR |
1139 | struct i40e_ring *tx_ring; |
1140 | struct i40e_ring *rx_ring; | |
1141 | ||
75a64435 | 1142 | tx_ring = kzalloc(sizeof(*tx_ring) * 2, GFP_KERNEL); |
5eae00c5 GR |
1143 | if (!tx_ring) |
1144 | goto err_out; | |
1145 | ||
1146 | tx_ring->queue_index = i; | |
1147 | tx_ring->netdev = adapter->netdev; | |
1148 | tx_ring->dev = &adapter->pdev->dev; | |
d732a184 | 1149 | tx_ring->count = adapter->tx_desc_count; |
1f012279 ASJ |
1150 | if (adapter->flags & I40E_FLAG_WB_ON_ITR_CAPABLE) |
1151 | tx_ring->flags |= I40E_TXR_FLAGS_WB_ON_ITR; | |
5eae00c5 GR |
1152 | adapter->tx_rings[i] = tx_ring; |
1153 | ||
1154 | rx_ring = &tx_ring[1]; | |
1155 | rx_ring->queue_index = i; | |
1156 | rx_ring->netdev = adapter->netdev; | |
1157 | rx_ring->dev = &adapter->pdev->dev; | |
d732a184 | 1158 | rx_ring->count = adapter->rx_desc_count; |
5eae00c5 GR |
1159 | adapter->rx_rings[i] = rx_ring; |
1160 | } | |
1161 | ||
1162 | return 0; | |
1163 | ||
1164 | err_out: | |
1165 | i40evf_free_queues(adapter); | |
1166 | return -ENOMEM; | |
1167 | } | |
1168 | ||
1169 | /** | |
1170 | * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported | |
1171 | * @adapter: board private structure to initialize | |
1172 | * | |
1173 | * Attempt to configure the interrupts using the best available | |
1174 | * capabilities of the hardware and the kernel. | |
1175 | **/ | |
1176 | static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter) | |
1177 | { | |
1178 | int vector, v_budget; | |
1179 | int pairs = 0; | |
1180 | int err = 0; | |
1181 | ||
1182 | if (!adapter->vsi_res) { | |
1183 | err = -EIO; | |
1184 | goto out; | |
1185 | } | |
cc052927 | 1186 | pairs = adapter->num_active_queues; |
5eae00c5 GR |
1187 | |
1188 | /* It's easy to be greedy for MSI-X vectors, but it really | |
1189 | * doesn't do us much good if we have a lot more vectors | |
1190 | * than CPU's. So let's be conservative and only ask for | |
1191 | * (roughly) twice the number of vectors as there are CPU's. | |
1192 | */ | |
30a500e2 MW |
1193 | v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS; |
1194 | v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors); | |
5eae00c5 | 1195 | |
5eae00c5 GR |
1196 | adapter->msix_entries = kcalloc(v_budget, |
1197 | sizeof(struct msix_entry), GFP_KERNEL); | |
1198 | if (!adapter->msix_entries) { | |
1199 | err = -ENOMEM; | |
1200 | goto out; | |
1201 | } | |
1202 | ||
1203 | for (vector = 0; vector < v_budget; vector++) | |
1204 | adapter->msix_entries[vector].entry = vector; | |
1205 | ||
313ed2d5 | 1206 | err = i40evf_acquire_msix_vectors(adapter, v_budget); |
5eae00c5 GR |
1207 | |
1208 | out: | |
1209 | adapter->netdev->real_num_tx_queues = pairs; | |
1210 | return err; | |
1211 | } | |
1212 | ||
e25d00b8 | 1213 | /** |
2c86ac3c | 1214 | * i40e_config_rss_aq - Prepare for RSS using AQ commands |
e25d00b8 ASJ |
1215 | * @vsi: vsi structure |
1216 | * @seed: RSS hash seed | |
2c86ac3c HZ |
1217 | * @lut: Lookup table |
1218 | * @lut_size: Lookup table size | |
1219 | * | |
1220 | * Return 0 on success, negative on failure | |
e25d00b8 | 1221 | **/ |
2c86ac3c HZ |
1222 | static int i40evf_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed, |
1223 | u8 *lut, u16 lut_size) | |
e25d00b8 | 1224 | { |
e25d00b8 ASJ |
1225 | struct i40evf_adapter *adapter = vsi->back; |
1226 | struct i40e_hw *hw = &adapter->hw; | |
2c86ac3c | 1227 | int ret = 0; |
e25d00b8 ASJ |
1228 | |
1229 | if (!vsi->id) | |
2c86ac3c | 1230 | return -EINVAL; |
e25d00b8 ASJ |
1231 | |
1232 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { | |
1233 | /* bail because we already have a command pending */ | |
1234 | dev_err(&adapter->pdev->dev, "Cannot confiure RSS, command %d pending\n", | |
1235 | adapter->current_op); | |
2c86ac3c | 1236 | return -EBUSY; |
e25d00b8 ASJ |
1237 | } |
1238 | ||
2c86ac3c HZ |
1239 | if (seed) { |
1240 | struct i40e_aqc_get_set_rss_key_data *rss_key = | |
1241 | (struct i40e_aqc_get_set_rss_key_data *)seed; | |
1242 | ret = i40evf_aq_set_rss_key(hw, vsi->id, rss_key); | |
1243 | if (ret) { | |
1244 | dev_err(&adapter->pdev->dev, "Cannot set RSS key, err %s aq_err %s\n", | |
1245 | i40evf_stat_str(hw, ret), | |
1246 | i40evf_aq_str(hw, hw->aq.asq_last_status)); | |
1247 | return ret; | |
1248 | } | |
1249 | } | |
e25d00b8 | 1250 | |
2c86ac3c HZ |
1251 | if (lut) { |
1252 | ret = i40evf_aq_set_rss_lut(hw, vsi->id, false, lut, lut_size); | |
1253 | if (ret) { | |
1254 | dev_err(&adapter->pdev->dev, | |
1255 | "Cannot set RSS lut, err %s aq_err %s\n", | |
1256 | i40evf_stat_str(hw, ret), | |
1257 | i40evf_aq_str(hw, hw->aq.asq_last_status)); | |
1258 | return ret; | |
1259 | } | |
e25d00b8 ASJ |
1260 | } |
1261 | ||
2c86ac3c | 1262 | return ret; |
e25d00b8 ASJ |
1263 | } |
1264 | ||
1265 | /** | |
2c86ac3c HZ |
1266 | * i40evf_config_rss_reg - Configure RSS keys and lut by writing registers |
1267 | * @vsi: Pointer to vsi structure | |
e25d00b8 | 1268 | * @seed: RSS hash seed |
2c86ac3c HZ |
1269 | * @lut: Lookup table |
1270 | * @lut_size: Lookup table size | |
1271 | * | |
1272 | * Returns 0 on success, negative on failure | |
e25d00b8 | 1273 | **/ |
2c86ac3c HZ |
1274 | static int i40evf_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed, |
1275 | const u8 *lut, u16 lut_size) | |
e25d00b8 | 1276 | { |
2c86ac3c | 1277 | struct i40evf_adapter *adapter = vsi->back; |
e25d00b8 | 1278 | struct i40e_hw *hw = &adapter->hw; |
2c86ac3c | 1279 | u16 i; |
e25d00b8 | 1280 | |
2c86ac3c HZ |
1281 | if (seed) { |
1282 | u32 *seed_dw = (u32 *)seed; | |
1283 | ||
1284 | for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++) | |
1285 | wr32(hw, I40E_VFQF_HKEY(i), seed_dw[i]); | |
1286 | } | |
1287 | ||
1288 | if (lut) { | |
1289 | u32 *lut_dw = (u32 *)lut; | |
1290 | ||
1291 | if (lut_size != I40EVF_HLUT_ARRAY_SIZE) | |
1292 | return -EINVAL; | |
1293 | ||
1294 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) | |
1295 | wr32(hw, I40E_VFQF_HLUT(i), lut_dw[i]); | |
e25d00b8 ASJ |
1296 | } |
1297 | i40e_flush(hw); | |
2c86ac3c HZ |
1298 | |
1299 | return 0; | |
1300 | } | |
1301 | ||
90b02b43 HZ |
1302 | /** |
1303 | * * i40evf_get_rss_aq - Get RSS keys and lut by using AQ commands | |
1304 | * @vsi: Pointer to vsi structure | |
1305 | * @seed: RSS hash seed | |
1306 | * @lut: Lookup table | |
1307 | * @lut_size: Lookup table size | |
1308 | * | |
1309 | * Return 0 on success, negative on failure | |
1310 | **/ | |
1311 | static int i40evf_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed, | |
1312 | u8 *lut, u16 lut_size) | |
1313 | { | |
1314 | struct i40evf_adapter *adapter = vsi->back; | |
1315 | struct i40e_hw *hw = &adapter->hw; | |
1316 | int ret = 0; | |
1317 | ||
1318 | if (seed) { | |
1319 | ret = i40evf_aq_get_rss_key(hw, vsi->id, | |
1320 | (struct i40e_aqc_get_set_rss_key_data *)seed); | |
1321 | if (ret) { | |
1322 | dev_err(&adapter->pdev->dev, | |
1323 | "Cannot get RSS key, err %s aq_err %s\n", | |
1324 | i40evf_stat_str(hw, ret), | |
1325 | i40evf_aq_str(hw, hw->aq.asq_last_status)); | |
1326 | return ret; | |
1327 | } | |
1328 | } | |
1329 | ||
1330 | if (lut) { | |
1331 | ret = i40evf_aq_get_rss_lut(hw, vsi->id, seed, lut, lut_size); | |
1332 | if (ret) { | |
1333 | dev_err(&adapter->pdev->dev, | |
1334 | "Cannot get RSS lut, err %s aq_err %s\n", | |
1335 | i40evf_stat_str(hw, ret), | |
1336 | i40evf_aq_str(hw, hw->aq.asq_last_status)); | |
1337 | return ret; | |
1338 | } | |
1339 | } | |
1340 | ||
1341 | return ret; | |
1342 | } | |
1343 | ||
1344 | /** | |
1345 | * * i40evf_get_rss_reg - Get RSS keys and lut by reading registers | |
1346 | * @vsi: Pointer to vsi structure | |
1347 | * @seed: RSS hash seed | |
1348 | * @lut: Lookup table | |
1349 | * @lut_size: Lookup table size | |
1350 | * | |
1351 | * Returns 0 on success, negative on failure | |
1352 | **/ | |
1353 | static int i40evf_get_rss_reg(struct i40e_vsi *vsi, const u8 *seed, | |
1354 | const u8 *lut, u16 lut_size) | |
1355 | { | |
1356 | struct i40evf_adapter *adapter = vsi->back; | |
1357 | struct i40e_hw *hw = &adapter->hw; | |
1358 | u16 i; | |
1359 | ||
1360 | if (seed) { | |
1361 | u32 *seed_dw = (u32 *)seed; | |
1362 | ||
1363 | for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++) | |
1364 | seed_dw[i] = rd32(hw, I40E_VFQF_HKEY(i)); | |
1365 | } | |
1366 | ||
1367 | if (lut) { | |
1368 | u32 *lut_dw = (u32 *)lut; | |
1369 | ||
1370 | if (lut_size != I40EVF_HLUT_ARRAY_SIZE) | |
1371 | return -EINVAL; | |
1372 | ||
1373 | for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++) | |
1374 | lut_dw[i] = rd32(hw, I40E_VFQF_HLUT(i)); | |
1375 | } | |
1376 | ||
1377 | return 0; | |
1378 | } | |
1379 | ||
2c86ac3c HZ |
1380 | /** |
1381 | * i40evf_config_rss - Configure RSS keys and lut | |
1382 | * @vsi: Pointer to vsi structure | |
1383 | * @seed: RSS hash seed | |
1384 | * @lut: Lookup table | |
1385 | * @lut_size: Lookup table size | |
1386 | * | |
1387 | * Returns 0 on success, negative on failure | |
1388 | **/ | |
1389 | int i40evf_config_rss(struct i40e_vsi *vsi, const u8 *seed, | |
1390 | u8 *lut, u16 lut_size) | |
1391 | { | |
1392 | struct i40evf_adapter *adapter = vsi->back; | |
1393 | ||
1394 | if (RSS_AQ(adapter)) | |
1395 | return i40evf_config_rss_aq(vsi, seed, lut, lut_size); | |
1396 | else | |
1397 | return i40evf_config_rss_reg(vsi, seed, lut, lut_size); | |
1398 | } | |
1399 | ||
90b02b43 HZ |
1400 | /** |
1401 | * i40evf_get_rss - Get RSS keys and lut | |
1402 | * @vsi: Pointer to vsi structure | |
1403 | * @seed: RSS hash seed | |
1404 | * @lut: Lookup table | |
1405 | * @lut_size: Lookup table size | |
1406 | * | |
1407 | * Returns 0 on success, negative on failure | |
1408 | **/ | |
1409 | int i40evf_get_rss(struct i40e_vsi *vsi, const u8 *seed, u8 *lut, u16 lut_size) | |
1410 | { | |
1411 | struct i40evf_adapter *adapter = vsi->back; | |
1412 | ||
1413 | if (RSS_AQ(adapter)) | |
1414 | return i40evf_get_rss_aq(vsi, seed, lut, lut_size); | |
1415 | else | |
1416 | return i40evf_get_rss_reg(vsi, seed, lut, lut_size); | |
1417 | } | |
1418 | ||
2c86ac3c HZ |
1419 | /** |
1420 | * i40evf_fill_rss_lut - Fill the lut with default values | |
1421 | * @lut: Lookup table to be filled with | |
1422 | * @rss_table_size: Lookup table size | |
1423 | * @rss_size: Range of queue number for hashing | |
1424 | **/ | |
1425 | static void i40evf_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size) | |
1426 | { | |
1427 | u16 i; | |
1428 | ||
1429 | for (i = 0; i < rss_table_size; i++) | |
1430 | lut[i] = i % rss_size; | |
e25d00b8 ASJ |
1431 | } |
1432 | ||
1433 | /** | |
96a81986 | 1434 | * i40evf_init_rss - Prepare for RSS |
e25d00b8 | 1435 | * @adapter: board private structure |
2c86ac3c HZ |
1436 | * |
1437 | * Return 0 on success, negative on failure | |
e25d00b8 | 1438 | **/ |
2c86ac3c | 1439 | static int i40evf_init_rss(struct i40evf_adapter *adapter) |
e25d00b8 | 1440 | { |
2c86ac3c | 1441 | struct i40e_vsi *vsi = &adapter->vsi; |
e25d00b8 ASJ |
1442 | struct i40e_hw *hw = &adapter->hw; |
1443 | u8 seed[I40EVF_HKEY_ARRAY_SIZE]; | |
1444 | u64 hena; | |
2c86ac3c HZ |
1445 | u8 *lut; |
1446 | int ret; | |
e25d00b8 ASJ |
1447 | |
1448 | /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */ | |
1449 | hena = I40E_DEFAULT_RSS_HENA; | |
1450 | wr32(hw, I40E_VFQF_HENA(0), (u32)hena); | |
1451 | wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32)); | |
1452 | ||
2c86ac3c HZ |
1453 | lut = kzalloc(I40EVF_HLUT_ARRAY_SIZE, GFP_KERNEL); |
1454 | if (!lut) | |
1455 | return -ENOMEM; | |
66f9af85 HZ |
1456 | |
1457 | /* Use user configured lut if there is one, otherwise use default */ | |
1458 | if (vsi->rss_lut_user) | |
1459 | memcpy(lut, vsi->rss_lut_user, I40EVF_HLUT_ARRAY_SIZE); | |
1460 | else | |
1461 | i40evf_fill_rss_lut(lut, I40EVF_HLUT_ARRAY_SIZE, | |
1462 | adapter->num_active_queues); | |
1463 | ||
1464 | /* Use user configured hash key if there is one, otherwise | |
1465 | * user default. | |
1466 | */ | |
1467 | if (vsi->rss_hkey_user) | |
1468 | memcpy(seed, vsi->rss_hkey_user, I40EVF_HKEY_ARRAY_SIZE); | |
1469 | else | |
1470 | netdev_rss_key_fill((void *)seed, I40EVF_HKEY_ARRAY_SIZE); | |
2c86ac3c HZ |
1471 | ret = i40evf_config_rss(vsi, seed, lut, I40EVF_HLUT_ARRAY_SIZE); |
1472 | kfree(lut); | |
1473 | ||
1474 | return ret; | |
e25d00b8 ASJ |
1475 | } |
1476 | ||
5eae00c5 GR |
1477 | /** |
1478 | * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors | |
1479 | * @adapter: board private structure to initialize | |
1480 | * | |
1481 | * We allocate one q_vector per queue interrupt. If allocation fails we | |
1482 | * return -ENOMEM. | |
1483 | **/ | |
1484 | static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter) | |
1485 | { | |
1486 | int q_idx, num_q_vectors; | |
1487 | struct i40e_q_vector *q_vector; | |
1488 | ||
1489 | num_q_vectors = adapter->num_msix_vectors - NONQ_VECS; | |
1490 | ||
1491 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { | |
75a64435 | 1492 | q_vector = kzalloc(sizeof(*q_vector), GFP_KERNEL); |
5eae00c5 GR |
1493 | if (!q_vector) |
1494 | goto err_out; | |
1495 | q_vector->adapter = adapter; | |
1496 | q_vector->vsi = &adapter->vsi; | |
1497 | q_vector->v_idx = q_idx; | |
1498 | netif_napi_add(adapter->netdev, &q_vector->napi, | |
75a64435 | 1499 | i40evf_napi_poll, NAPI_POLL_WEIGHT); |
5eae00c5 GR |
1500 | adapter->q_vector[q_idx] = q_vector; |
1501 | } | |
1502 | ||
1503 | return 0; | |
1504 | ||
1505 | err_out: | |
1506 | while (q_idx) { | |
1507 | q_idx--; | |
1508 | q_vector = adapter->q_vector[q_idx]; | |
1509 | netif_napi_del(&q_vector->napi); | |
1510 | kfree(q_vector); | |
1511 | adapter->q_vector[q_idx] = NULL; | |
1512 | } | |
1513 | return -ENOMEM; | |
1514 | } | |
1515 | ||
1516 | /** | |
1517 | * i40evf_free_q_vectors - Free memory allocated for interrupt vectors | |
1518 | * @adapter: board private structure to initialize | |
1519 | * | |
1520 | * This function frees the memory allocated to the q_vectors. In addition if | |
1521 | * NAPI is enabled it will delete any references to the NAPI struct prior | |
1522 | * to freeing the q_vector. | |
1523 | **/ | |
1524 | static void i40evf_free_q_vectors(struct i40evf_adapter *adapter) | |
1525 | { | |
1526 | int q_idx, num_q_vectors; | |
1527 | int napi_vectors; | |
1528 | ||
1529 | num_q_vectors = adapter->num_msix_vectors - NONQ_VECS; | |
cc052927 | 1530 | napi_vectors = adapter->num_active_queues; |
5eae00c5 GR |
1531 | |
1532 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { | |
1533 | struct i40e_q_vector *q_vector = adapter->q_vector[q_idx]; | |
1534 | ||
1535 | adapter->q_vector[q_idx] = NULL; | |
1536 | if (q_idx < napi_vectors) | |
1537 | netif_napi_del(&q_vector->napi); | |
1538 | kfree(q_vector); | |
1539 | } | |
1540 | } | |
1541 | ||
1542 | /** | |
1543 | * i40evf_reset_interrupt_capability - Reset MSIX setup | |
1544 | * @adapter: board private structure | |
1545 | * | |
1546 | **/ | |
1547 | void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter) | |
1548 | { | |
1549 | pci_disable_msix(adapter->pdev); | |
1550 | kfree(adapter->msix_entries); | |
1551 | adapter->msix_entries = NULL; | |
5eae00c5 GR |
1552 | } |
1553 | ||
1554 | /** | |
1555 | * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init | |
1556 | * @adapter: board private structure to initialize | |
1557 | * | |
1558 | **/ | |
1559 | int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter) | |
1560 | { | |
1561 | int err; | |
1562 | ||
1563 | err = i40evf_set_interrupt_capability(adapter); | |
1564 | if (err) { | |
1565 | dev_err(&adapter->pdev->dev, | |
1566 | "Unable to setup interrupt capabilities\n"); | |
1567 | goto err_set_interrupt; | |
1568 | } | |
1569 | ||
1570 | err = i40evf_alloc_q_vectors(adapter); | |
1571 | if (err) { | |
1572 | dev_err(&adapter->pdev->dev, | |
1573 | "Unable to allocate memory for queue vectors\n"); | |
1574 | goto err_alloc_q_vectors; | |
1575 | } | |
1576 | ||
1577 | err = i40evf_alloc_queues(adapter); | |
1578 | if (err) { | |
1579 | dev_err(&adapter->pdev->dev, | |
1580 | "Unable to allocate memory for queues\n"); | |
1581 | goto err_alloc_queues; | |
1582 | } | |
1583 | ||
1584 | dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u", | |
75a64435 MW |
1585 | (adapter->num_active_queues > 1) ? "Enabled" : "Disabled", |
1586 | adapter->num_active_queues); | |
5eae00c5 GR |
1587 | |
1588 | return 0; | |
1589 | err_alloc_queues: | |
1590 | i40evf_free_q_vectors(adapter); | |
1591 | err_alloc_q_vectors: | |
1592 | i40evf_reset_interrupt_capability(adapter); | |
1593 | err_set_interrupt: | |
1594 | return err; | |
1595 | } | |
1596 | ||
66f9af85 HZ |
1597 | /** |
1598 | * i40evf_clear_rss_config_user - Clear user configurations of RSS | |
1599 | * @vsi: Pointer to VSI structure | |
1600 | **/ | |
1601 | static void i40evf_clear_rss_config_user(struct i40e_vsi *vsi) | |
1602 | { | |
1603 | if (!vsi) | |
1604 | return; | |
1605 | ||
1606 | kfree(vsi->rss_hkey_user); | |
1607 | vsi->rss_hkey_user = NULL; | |
1608 | ||
1609 | kfree(vsi->rss_lut_user); | |
1610 | vsi->rss_lut_user = NULL; | |
1611 | } | |
1612 | ||
5eae00c5 GR |
1613 | /** |
1614 | * i40evf_watchdog_timer - Periodic call-back timer | |
1615 | * @data: pointer to adapter disguised as unsigned long | |
1616 | **/ | |
1617 | static void i40evf_watchdog_timer(unsigned long data) | |
1618 | { | |
1619 | struct i40evf_adapter *adapter = (struct i40evf_adapter *)data; | |
75a64435 | 1620 | |
5eae00c5 GR |
1621 | schedule_work(&adapter->watchdog_task); |
1622 | /* timer will be rescheduled in watchdog task */ | |
1623 | } | |
1624 | ||
1625 | /** | |
1626 | * i40evf_watchdog_task - Periodic call-back task | |
1627 | * @work: pointer to work_struct | |
1628 | **/ | |
1629 | static void i40evf_watchdog_task(struct work_struct *work) | |
1630 | { | |
1631 | struct i40evf_adapter *adapter = container_of(work, | |
75a64435 MW |
1632 | struct i40evf_adapter, |
1633 | watchdog_task); | |
5eae00c5 | 1634 | struct i40e_hw *hw = &adapter->hw; |
ee5c1e92 | 1635 | u32 reg_val; |
5eae00c5 | 1636 | |
ef8693eb MW |
1637 | if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section)) |
1638 | goto restart_watchdog; | |
1639 | ||
1640 | if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) { | |
ee5c1e92 MW |
1641 | reg_val = rd32(hw, I40E_VFGEN_RSTAT) & |
1642 | I40E_VFGEN_RSTAT_VFR_STATE_MASK; | |
1643 | if ((reg_val == I40E_VFR_VFACTIVE) || | |
1644 | (reg_val == I40E_VFR_COMPLETED)) { | |
ef8693eb MW |
1645 | /* A chance for redemption! */ |
1646 | dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n"); | |
1647 | adapter->state = __I40EVF_STARTUP; | |
1648 | adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED; | |
1649 | schedule_delayed_work(&adapter->init_task, 10); | |
1650 | clear_bit(__I40EVF_IN_CRITICAL_TASK, | |
1651 | &adapter->crit_section); | |
1652 | /* Don't reschedule the watchdog, since we've restarted | |
1653 | * the init task. When init_task contacts the PF and | |
1654 | * gets everything set up again, it'll restart the | |
1655 | * watchdog for us. Down, boy. Sit. Stay. Woof. | |
1656 | */ | |
1657 | return; | |
1658 | } | |
ef8693eb MW |
1659 | adapter->aq_required = 0; |
1660 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; | |
5eae00c5 | 1661 | goto watchdog_done; |
ef8693eb | 1662 | } |
5eae00c5 | 1663 | |
ef8693eb MW |
1664 | if ((adapter->state < __I40EVF_DOWN) || |
1665 | (adapter->flags & I40EVF_FLAG_RESET_PENDING)) | |
5eae00c5 GR |
1666 | goto watchdog_done; |
1667 | ||
ef8693eb | 1668 | /* check for reset */ |
ee5c1e92 MW |
1669 | reg_val = rd32(hw, I40E_VF_ARQLEN1) & I40E_VF_ARQLEN1_ARQENABLE_MASK; |
1670 | if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) && !reg_val) { | |
5eae00c5 | 1671 | adapter->state = __I40EVF_RESETTING; |
ef8693eb | 1672 | adapter->flags |= I40EVF_FLAG_RESET_PENDING; |
249c8b8d | 1673 | dev_err(&adapter->pdev->dev, "Hardware reset detected\n"); |
5eae00c5 | 1674 | schedule_work(&adapter->reset_task); |
ef8693eb MW |
1675 | adapter->aq_required = 0; |
1676 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; | |
5eae00c5 GR |
1677 | goto watchdog_done; |
1678 | } | |
1679 | ||
1680 | /* Process admin queue tasks. After init, everything gets done | |
1681 | * here so we don't race on the admin queue. | |
1682 | */ | |
ed636960 | 1683 | if (adapter->current_op) { |
0758e7cb MW |
1684 | if (!i40evf_asq_done(hw)) { |
1685 | dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n"); | |
1686 | i40evf_send_api_ver(adapter); | |
1687 | } | |
5eae00c5 | 1688 | goto watchdog_done; |
0758e7cb | 1689 | } |
e6d038de MW |
1690 | if (adapter->aq_required & I40EVF_FLAG_AQ_GET_CONFIG) { |
1691 | i40evf_send_vf_config_msg(adapter); | |
1692 | goto watchdog_done; | |
1693 | } | |
5eae00c5 | 1694 | |
e284fc88 MW |
1695 | if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) { |
1696 | i40evf_disable_queues(adapter); | |
1697 | goto watchdog_done; | |
1698 | } | |
1699 | ||
5eae00c5 GR |
1700 | if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) { |
1701 | i40evf_map_queues(adapter); | |
1702 | goto watchdog_done; | |
1703 | } | |
1704 | ||
1705 | if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) { | |
1706 | i40evf_add_ether_addrs(adapter); | |
1707 | goto watchdog_done; | |
1708 | } | |
1709 | ||
1710 | if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) { | |
1711 | i40evf_add_vlans(adapter); | |
1712 | goto watchdog_done; | |
1713 | } | |
1714 | ||
1715 | if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) { | |
1716 | i40evf_del_ether_addrs(adapter); | |
1717 | goto watchdog_done; | |
1718 | } | |
1719 | ||
1720 | if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) { | |
1721 | i40evf_del_vlans(adapter); | |
1722 | goto watchdog_done; | |
1723 | } | |
1724 | ||
5eae00c5 GR |
1725 | if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) { |
1726 | i40evf_configure_queues(adapter); | |
1727 | goto watchdog_done; | |
1728 | } | |
1729 | ||
1730 | if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) { | |
1731 | i40evf_enable_queues(adapter); | |
1732 | goto watchdog_done; | |
1733 | } | |
1734 | ||
e25d00b8 ASJ |
1735 | if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_RSS) { |
1736 | /* This message goes straight to the firmware, not the | |
1737 | * PF, so we don't have to set current_op as we will | |
1738 | * not get a response through the ARQ. | |
1739 | */ | |
96a81986 | 1740 | i40evf_init_rss(adapter); |
e25d00b8 ASJ |
1741 | adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_RSS; |
1742 | goto watchdog_done; | |
1743 | } | |
1744 | ||
5eae00c5 GR |
1745 | if (adapter->state == __I40EVF_RUNNING) |
1746 | i40evf_request_stats(adapter); | |
5eae00c5 | 1747 | watchdog_done: |
4870e176 MW |
1748 | if (adapter->state == __I40EVF_RUNNING) { |
1749 | i40evf_irq_enable_queues(adapter, ~0); | |
1750 | i40evf_fire_sw_int(adapter, 0xFF); | |
1751 | } else { | |
1752 | i40evf_fire_sw_int(adapter, 0x1); | |
1753 | } | |
1754 | ||
ef8693eb MW |
1755 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
1756 | restart_watchdog: | |
d3e2edb7 AS |
1757 | if (adapter->state == __I40EVF_REMOVE) |
1758 | return; | |
5eae00c5 GR |
1759 | if (adapter->aq_required) |
1760 | mod_timer(&adapter->watchdog_timer, | |
1761 | jiffies + msecs_to_jiffies(20)); | |
1762 | else | |
1763 | mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2)); | |
5eae00c5 GR |
1764 | schedule_work(&adapter->adminq_task); |
1765 | } | |
1766 | ||
67c818a1 MW |
1767 | #define I40EVF_RESET_WAIT_MS 10 |
1768 | #define I40EVF_RESET_WAIT_COUNT 500 | |
5eae00c5 GR |
1769 | /** |
1770 | * i40evf_reset_task - Call-back task to handle hardware reset | |
1771 | * @work: pointer to work_struct | |
1772 | * | |
1773 | * During reset we need to shut down and reinitialize the admin queue | |
1774 | * before we can use it to communicate with the PF again. We also clear | |
1775 | * and reinit the rings because that context is lost as well. | |
1776 | **/ | |
1777 | static void i40evf_reset_task(struct work_struct *work) | |
1778 | { | |
ef8693eb MW |
1779 | struct i40evf_adapter *adapter = container_of(work, |
1780 | struct i40evf_adapter, | |
1781 | reset_task); | |
ac833bbf | 1782 | struct net_device *netdev = adapter->netdev; |
5eae00c5 | 1783 | struct i40e_hw *hw = &adapter->hw; |
40d01366 | 1784 | struct i40evf_vlan_filter *vlf; |
ac833bbf | 1785 | struct i40evf_mac_filter *f; |
ee5c1e92 | 1786 | u32 reg_val; |
ac833bbf | 1787 | int i = 0, err; |
5eae00c5 GR |
1788 | |
1789 | while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, | |
1790 | &adapter->crit_section)) | |
f98a2006 | 1791 | usleep_range(500, 1000); |
3526d800 | 1792 | |
67c818a1 | 1793 | i40evf_misc_irq_disable(adapter); |
3526d800 | 1794 | if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) { |
67c818a1 MW |
1795 | adapter->flags &= ~I40EVF_FLAG_RESET_NEEDED; |
1796 | /* Restart the AQ here. If we have been reset but didn't | |
1797 | * detect it, or if the PF had to reinit, our AQ will be hosed. | |
1798 | */ | |
1799 | i40evf_shutdown_adminq(hw); | |
1800 | i40evf_init_adminq(hw); | |
3526d800 MW |
1801 | i40evf_request_reset(adapter); |
1802 | } | |
67c818a1 | 1803 | adapter->flags |= I40EVF_FLAG_RESET_PENDING; |
3526d800 | 1804 | |
ef8693eb MW |
1805 | /* poll until we see the reset actually happen */ |
1806 | for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) { | |
ee5c1e92 MW |
1807 | reg_val = rd32(hw, I40E_VF_ARQLEN1) & |
1808 | I40E_VF_ARQLEN1_ARQENABLE_MASK; | |
1809 | if (!reg_val) | |
ef8693eb | 1810 | break; |
ee5c1e92 | 1811 | usleep_range(5000, 10000); |
ef8693eb MW |
1812 | } |
1813 | if (i == I40EVF_RESET_WAIT_COUNT) { | |
67c818a1 | 1814 | dev_info(&adapter->pdev->dev, "Never saw reset\n"); |
ef8693eb MW |
1815 | goto continue_reset; /* act like the reset happened */ |
1816 | } | |
5eae00c5 | 1817 | |
ef8693eb MW |
1818 | /* wait until the reset is complete and the PF is responding to us */ |
1819 | for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) { | |
ee5c1e92 MW |
1820 | reg_val = rd32(hw, I40E_VFGEN_RSTAT) & |
1821 | I40E_VFGEN_RSTAT_VFR_STATE_MASK; | |
1822 | if (reg_val == I40E_VFR_VFACTIVE) | |
5eae00c5 | 1823 | break; |
c88e38cc | 1824 | msleep(I40EVF_RESET_WAIT_MS); |
5eae00c5 | 1825 | } |
67c818a1 MW |
1826 | /* extra wait to make sure minimum wait is met */ |
1827 | msleep(I40EVF_RESET_WAIT_MS); | |
ef8693eb | 1828 | if (i == I40EVF_RESET_WAIT_COUNT) { |
874d1a10 | 1829 | struct i40evf_mac_filter *ftmp; |
6ba36a24 MW |
1830 | struct i40evf_vlan_filter *fv, *fvtmp; |
1831 | ||
5eae00c5 | 1832 | /* reset never finished */ |
80e72893 | 1833 | dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n", |
ee5c1e92 | 1834 | reg_val); |
ef8693eb MW |
1835 | adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED; |
1836 | ||
169f4076 MW |
1837 | if (netif_running(adapter->netdev)) { |
1838 | set_bit(__I40E_DOWN, &adapter->vsi.state); | |
ac833bbf | 1839 | netif_carrier_off(netdev); |
67c818a1 MW |
1840 | netif_tx_disable(netdev); |
1841 | i40evf_napi_disable_all(adapter); | |
1842 | i40evf_irq_disable(adapter); | |
169f4076 MW |
1843 | i40evf_free_traffic_irqs(adapter); |
1844 | i40evf_free_all_tx_resources(adapter); | |
1845 | i40evf_free_all_rx_resources(adapter); | |
1846 | } | |
6ba36a24 MW |
1847 | |
1848 | /* Delete all of the filters, both MAC and VLAN. */ | |
1849 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, | |
1850 | list) { | |
1851 | list_del(&f->list); | |
1852 | kfree(f); | |
1853 | } | |
67c818a1 | 1854 | |
6ba36a24 MW |
1855 | list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list, |
1856 | list) { | |
1857 | list_del(&fv->list); | |
1858 | kfree(fv); | |
1859 | } | |
1860 | ||
ef8693eb MW |
1861 | i40evf_free_misc_irq(adapter); |
1862 | i40evf_reset_interrupt_capability(adapter); | |
1863 | i40evf_free_queues(adapter); | |
d31944d6 | 1864 | i40evf_free_q_vectors(adapter); |
ef8693eb MW |
1865 | kfree(adapter->vf_res); |
1866 | i40evf_shutdown_adminq(hw); | |
1867 | adapter->netdev->flags &= ~IFF_UP; | |
1868 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); | |
67c818a1 MW |
1869 | adapter->flags &= ~I40EVF_FLAG_RESET_PENDING; |
1870 | dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n"); | |
ef8693eb | 1871 | return; /* Do not attempt to reinit. It's dead, Jim. */ |
5eae00c5 | 1872 | } |
ef8693eb MW |
1873 | |
1874 | continue_reset: | |
3c8e0b98 | 1875 | if (netif_running(adapter->netdev)) { |
3c8e0b98 | 1876 | netif_carrier_off(netdev); |
67c818a1 MW |
1877 | netif_tx_stop_all_queues(netdev); |
1878 | i40evf_napi_disable_all(adapter); | |
3c8e0b98 | 1879 | } |
67c818a1 | 1880 | i40evf_irq_disable(adapter); |
ac833bbf | 1881 | |
5eae00c5 | 1882 | adapter->state = __I40EVF_RESETTING; |
67c818a1 MW |
1883 | adapter->flags &= ~I40EVF_FLAG_RESET_PENDING; |
1884 | ||
1885 | /* free the Tx/Rx rings and descriptors, might be better to just | |
1886 | * re-use them sometime in the future | |
1887 | */ | |
1888 | i40evf_free_all_rx_resources(adapter); | |
1889 | i40evf_free_all_tx_resources(adapter); | |
5eae00c5 GR |
1890 | |
1891 | /* kill and reinit the admin queue */ | |
1892 | if (i40evf_shutdown_adminq(hw)) | |
ac833bbf MW |
1893 | dev_warn(&adapter->pdev->dev, "Failed to shut down adminq\n"); |
1894 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; | |
5eae00c5 GR |
1895 | err = i40evf_init_adminq(hw); |
1896 | if (err) | |
ac833bbf MW |
1897 | dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n", |
1898 | err); | |
5eae00c5 | 1899 | |
e6d038de MW |
1900 | adapter->aq_required = I40EVF_FLAG_AQ_GET_CONFIG; |
1901 | adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS; | |
ac833bbf MW |
1902 | |
1903 | /* re-add all MAC filters */ | |
1904 | list_for_each_entry(f, &adapter->mac_filter_list, list) { | |
1905 | f->add = true; | |
1906 | } | |
1907 | /* re-add all VLAN filters */ | |
40d01366 MW |
1908 | list_for_each_entry(vlf, &adapter->vlan_filter_list, list) { |
1909 | vlf->add = true; | |
ac833bbf | 1910 | } |
e6d038de | 1911 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER; |
ac833bbf | 1912 | adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER; |
5eae00c5 | 1913 | clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section); |
67c818a1 | 1914 | i40evf_misc_irq_enable(adapter); |
5eae00c5 GR |
1915 | |
1916 | mod_timer(&adapter->watchdog_timer, jiffies + 2); | |
1917 | ||
1918 | if (netif_running(adapter->netdev)) { | |
1919 | /* allocate transmit descriptors */ | |
1920 | err = i40evf_setup_all_tx_resources(adapter); | |
1921 | if (err) | |
1922 | goto reset_err; | |
1923 | ||
1924 | /* allocate receive descriptors */ | |
1925 | err = i40evf_setup_all_rx_resources(adapter); | |
1926 | if (err) | |
1927 | goto reset_err; | |
1928 | ||
1929 | i40evf_configure(adapter); | |
1930 | ||
1931 | err = i40evf_up_complete(adapter); | |
1932 | if (err) | |
1933 | goto reset_err; | |
1934 | ||
1935 | i40evf_irq_enable(adapter, true); | |
67c818a1 MW |
1936 | } else { |
1937 | adapter->state = __I40EVF_DOWN; | |
5eae00c5 | 1938 | } |
67c818a1 | 1939 | |
5eae00c5 GR |
1940 | return; |
1941 | reset_err: | |
80e72893 | 1942 | dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n"); |
5eae00c5 GR |
1943 | i40evf_close(adapter->netdev); |
1944 | } | |
1945 | ||
1946 | /** | |
1947 | * i40evf_adminq_task - worker thread to clean the admin queue | |
1948 | * @work: pointer to work_struct containing our data | |
1949 | **/ | |
1950 | static void i40evf_adminq_task(struct work_struct *work) | |
1951 | { | |
1952 | struct i40evf_adapter *adapter = | |
1953 | container_of(work, struct i40evf_adapter, adminq_task); | |
1954 | struct i40e_hw *hw = &adapter->hw; | |
1955 | struct i40e_arq_event_info event; | |
1956 | struct i40e_virtchnl_msg *v_msg; | |
1957 | i40e_status ret; | |
912257e5 | 1958 | u32 val, oldval; |
5eae00c5 GR |
1959 | u16 pending; |
1960 | ||
ef8693eb | 1961 | if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) |
7235448c | 1962 | goto out; |
ef8693eb | 1963 | |
1001dc37 MW |
1964 | event.buf_len = I40EVF_MAX_AQ_BUF_SIZE; |
1965 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); | |
249c8b8d | 1966 | if (!event.msg_buf) |
7235448c | 1967 | goto out; |
249c8b8d | 1968 | |
5eae00c5 GR |
1969 | v_msg = (struct i40e_virtchnl_msg *)&event.desc; |
1970 | do { | |
1971 | ret = i40evf_clean_arq_element(hw, &event, &pending); | |
8b011ebb | 1972 | if (ret || !v_msg->v_opcode) |
5eae00c5 GR |
1973 | break; /* No event to process or error cleaning ARQ */ |
1974 | ||
1975 | i40evf_virtchnl_completion(adapter, v_msg->v_opcode, | |
1976 | v_msg->v_retval, event.msg_buf, | |
1001dc37 | 1977 | event.msg_len); |
75a64435 | 1978 | if (pending != 0) |
5eae00c5 | 1979 | memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE); |
5eae00c5 GR |
1980 | } while (pending); |
1981 | ||
67c818a1 MW |
1982 | if ((adapter->flags & |
1983 | (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) || | |
1984 | adapter->state == __I40EVF_RESETTING) | |
1985 | goto freedom; | |
1986 | ||
912257e5 MW |
1987 | /* check for error indications */ |
1988 | val = rd32(hw, hw->aq.arq.len); | |
1989 | oldval = val; | |
b1f3366b | 1990 | if (val & I40E_VF_ARQLEN1_ARQVFE_MASK) { |
912257e5 | 1991 | dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n"); |
b1f3366b | 1992 | val &= ~I40E_VF_ARQLEN1_ARQVFE_MASK; |
912257e5 | 1993 | } |
b1f3366b | 1994 | if (val & I40E_VF_ARQLEN1_ARQOVFL_MASK) { |
912257e5 | 1995 | dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n"); |
b1f3366b | 1996 | val &= ~I40E_VF_ARQLEN1_ARQOVFL_MASK; |
912257e5 | 1997 | } |
b1f3366b | 1998 | if (val & I40E_VF_ARQLEN1_ARQCRIT_MASK) { |
912257e5 | 1999 | dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n"); |
b1f3366b | 2000 | val &= ~I40E_VF_ARQLEN1_ARQCRIT_MASK; |
912257e5 MW |
2001 | } |
2002 | if (oldval != val) | |
2003 | wr32(hw, hw->aq.arq.len, val); | |
2004 | ||
2005 | val = rd32(hw, hw->aq.asq.len); | |
2006 | oldval = val; | |
b1f3366b | 2007 | if (val & I40E_VF_ATQLEN1_ATQVFE_MASK) { |
912257e5 | 2008 | dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n"); |
b1f3366b | 2009 | val &= ~I40E_VF_ATQLEN1_ATQVFE_MASK; |
912257e5 | 2010 | } |
b1f3366b | 2011 | if (val & I40E_VF_ATQLEN1_ATQOVFL_MASK) { |
912257e5 | 2012 | dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n"); |
b1f3366b | 2013 | val &= ~I40E_VF_ATQLEN1_ATQOVFL_MASK; |
912257e5 | 2014 | } |
b1f3366b | 2015 | if (val & I40E_VF_ATQLEN1_ATQCRIT_MASK) { |
912257e5 | 2016 | dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n"); |
b1f3366b | 2017 | val &= ~I40E_VF_ATQLEN1_ATQCRIT_MASK; |
912257e5 MW |
2018 | } |
2019 | if (oldval != val) | |
2020 | wr32(hw, hw->aq.asq.len, val); | |
2021 | ||
67c818a1 | 2022 | freedom: |
7235448c MW |
2023 | kfree(event.msg_buf); |
2024 | out: | |
5eae00c5 GR |
2025 | /* re-enable Admin queue interrupt cause */ |
2026 | i40evf_misc_irq_enable(adapter); | |
5eae00c5 GR |
2027 | } |
2028 | ||
2029 | /** | |
2030 | * i40evf_free_all_tx_resources - Free Tx Resources for All Queues | |
2031 | * @adapter: board private structure | |
2032 | * | |
2033 | * Free all transmit software resources | |
2034 | **/ | |
e284fc88 | 2035 | void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter) |
5eae00c5 GR |
2036 | { |
2037 | int i; | |
2038 | ||
cc052927 | 2039 | for (i = 0; i < adapter->num_active_queues; i++) |
5eae00c5 GR |
2040 | if (adapter->tx_rings[i]->desc) |
2041 | i40evf_free_tx_resources(adapter->tx_rings[i]); | |
5eae00c5 GR |
2042 | } |
2043 | ||
2044 | /** | |
2045 | * i40evf_setup_all_tx_resources - allocate all queues Tx resources | |
2046 | * @adapter: board private structure | |
2047 | * | |
2048 | * If this function returns with an error, then it's possible one or | |
2049 | * more of the rings is populated (while the rest are not). It is the | |
2050 | * callers duty to clean those orphaned rings. | |
2051 | * | |
2052 | * Return 0 on success, negative on failure | |
2053 | **/ | |
2054 | static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter) | |
2055 | { | |
2056 | int i, err = 0; | |
2057 | ||
cc052927 | 2058 | for (i = 0; i < adapter->num_active_queues; i++) { |
d732a184 | 2059 | adapter->tx_rings[i]->count = adapter->tx_desc_count; |
5eae00c5 GR |
2060 | err = i40evf_setup_tx_descriptors(adapter->tx_rings[i]); |
2061 | if (!err) | |
2062 | continue; | |
2063 | dev_err(&adapter->pdev->dev, | |
fb43201f | 2064 | "Allocation for Tx Queue %u failed\n", i); |
5eae00c5 GR |
2065 | break; |
2066 | } | |
2067 | ||
2068 | return err; | |
2069 | } | |
2070 | ||
2071 | /** | |
2072 | * i40evf_setup_all_rx_resources - allocate all queues Rx resources | |
2073 | * @adapter: board private structure | |
2074 | * | |
2075 | * If this function returns with an error, then it's possible one or | |
2076 | * more of the rings is populated (while the rest are not). It is the | |
2077 | * callers duty to clean those orphaned rings. | |
2078 | * | |
2079 | * Return 0 on success, negative on failure | |
2080 | **/ | |
2081 | static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter) | |
2082 | { | |
2083 | int i, err = 0; | |
2084 | ||
cc052927 | 2085 | for (i = 0; i < adapter->num_active_queues; i++) { |
d732a184 | 2086 | adapter->rx_rings[i]->count = adapter->rx_desc_count; |
5eae00c5 GR |
2087 | err = i40evf_setup_rx_descriptors(adapter->rx_rings[i]); |
2088 | if (!err) | |
2089 | continue; | |
2090 | dev_err(&adapter->pdev->dev, | |
fb43201f | 2091 | "Allocation for Rx Queue %u failed\n", i); |
5eae00c5 GR |
2092 | break; |
2093 | } | |
2094 | return err; | |
2095 | } | |
2096 | ||
2097 | /** | |
2098 | * i40evf_free_all_rx_resources - Free Rx Resources for All Queues | |
2099 | * @adapter: board private structure | |
2100 | * | |
2101 | * Free all receive software resources | |
2102 | **/ | |
e284fc88 | 2103 | void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter) |
5eae00c5 GR |
2104 | { |
2105 | int i; | |
2106 | ||
cc052927 | 2107 | for (i = 0; i < adapter->num_active_queues; i++) |
5eae00c5 GR |
2108 | if (adapter->rx_rings[i]->desc) |
2109 | i40evf_free_rx_resources(adapter->rx_rings[i]); | |
2110 | } | |
2111 | ||
2112 | /** | |
2113 | * i40evf_open - Called when a network interface is made active | |
2114 | * @netdev: network interface device structure | |
2115 | * | |
2116 | * Returns 0 on success, negative value on failure | |
2117 | * | |
2118 | * The open entry point is called when a network interface is made | |
2119 | * active by the system (IFF_UP). At this point all resources needed | |
2120 | * for transmit and receive operations are allocated, the interrupt | |
2121 | * handler is registered with the OS, the watchdog timer is started, | |
2122 | * and the stack is notified that the interface is ready. | |
2123 | **/ | |
2124 | static int i40evf_open(struct net_device *netdev) | |
2125 | { | |
2126 | struct i40evf_adapter *adapter = netdev_priv(netdev); | |
2127 | int err; | |
2128 | ||
ef8693eb MW |
2129 | if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) { |
2130 | dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n"); | |
2131 | return -EIO; | |
2132 | } | |
e284fc88 | 2133 | if (adapter->state != __I40EVF_DOWN || adapter->aq_required) |
5eae00c5 GR |
2134 | return -EBUSY; |
2135 | ||
2136 | /* allocate transmit descriptors */ | |
2137 | err = i40evf_setup_all_tx_resources(adapter); | |
2138 | if (err) | |
2139 | goto err_setup_tx; | |
2140 | ||
2141 | /* allocate receive descriptors */ | |
2142 | err = i40evf_setup_all_rx_resources(adapter); | |
2143 | if (err) | |
2144 | goto err_setup_rx; | |
2145 | ||
2146 | /* clear any pending interrupts, may auto mask */ | |
2147 | err = i40evf_request_traffic_irqs(adapter, netdev->name); | |
2148 | if (err) | |
2149 | goto err_req_irq; | |
2150 | ||
44151cd3 | 2151 | i40evf_add_filter(adapter, adapter->hw.mac.addr); |
5eae00c5 GR |
2152 | i40evf_configure(adapter); |
2153 | ||
2154 | err = i40evf_up_complete(adapter); | |
2155 | if (err) | |
2156 | goto err_req_irq; | |
2157 | ||
2158 | i40evf_irq_enable(adapter, true); | |
2159 | ||
2160 | return 0; | |
2161 | ||
2162 | err_req_irq: | |
2163 | i40evf_down(adapter); | |
2164 | i40evf_free_traffic_irqs(adapter); | |
2165 | err_setup_rx: | |
2166 | i40evf_free_all_rx_resources(adapter); | |
2167 | err_setup_tx: | |
2168 | i40evf_free_all_tx_resources(adapter); | |
2169 | ||
2170 | return err; | |
2171 | } | |
2172 | ||
2173 | /** | |
2174 | * i40evf_close - Disables a network interface | |
2175 | * @netdev: network interface device structure | |
2176 | * | |
2177 | * Returns 0, this is not allowed to fail | |
2178 | * | |
2179 | * The close entry point is called when an interface is de-activated | |
2180 | * by the OS. The hardware is still under the drivers control, but | |
2181 | * needs to be disabled. All IRQs except vector 0 (reserved for admin queue) | |
2182 | * are freed, along with all transmit and receive resources. | |
2183 | **/ | |
2184 | static int i40evf_close(struct net_device *netdev) | |
2185 | { | |
2186 | struct i40evf_adapter *adapter = netdev_priv(netdev); | |
2187 | ||
ef8693eb MW |
2188 | if (adapter->state <= __I40EVF_DOWN) |
2189 | return 0; | |
2190 | ||
ef8693eb | 2191 | |
5eae00c5 GR |
2192 | set_bit(__I40E_DOWN, &adapter->vsi.state); |
2193 | ||
2194 | i40evf_down(adapter); | |
ddf0b3a6 | 2195 | adapter->state = __I40EVF_DOWN; |
5eae00c5 GR |
2196 | i40evf_free_traffic_irqs(adapter); |
2197 | ||
5eae00c5 GR |
2198 | return 0; |
2199 | } | |
2200 | ||
2201 | /** | |
2202 | * i40evf_get_stats - Get System Network Statistics | |
2203 | * @netdev: network interface device structure | |
2204 | * | |
2205 | * Returns the address of the device statistics structure. | |
2206 | * The statistics are actually updated from the timer callback. | |
2207 | **/ | |
2208 | static struct net_device_stats *i40evf_get_stats(struct net_device *netdev) | |
2209 | { | |
2210 | struct i40evf_adapter *adapter = netdev_priv(netdev); | |
2211 | ||
2212 | /* only return the current stats */ | |
2213 | return &adapter->net_stats; | |
2214 | } | |
2215 | ||
5eae00c5 GR |
2216 | /** |
2217 | * i40evf_change_mtu - Change the Maximum Transfer Unit | |
2218 | * @netdev: network interface device structure | |
2219 | * @new_mtu: new value for maximum frame size | |
2220 | * | |
2221 | * Returns 0 on success, negative on failure | |
2222 | **/ | |
2223 | static int i40evf_change_mtu(struct net_device *netdev, int new_mtu) | |
2224 | { | |
2225 | struct i40evf_adapter *adapter = netdev_priv(netdev); | |
2226 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; | |
2227 | ||
2228 | if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER)) | |
2229 | return -EINVAL; | |
2230 | ||
5eae00c5 | 2231 | netdev->mtu = new_mtu; |
67c818a1 MW |
2232 | adapter->flags |= I40EVF_FLAG_RESET_NEEDED; |
2233 | schedule_work(&adapter->reset_task); | |
2234 | ||
5eae00c5 GR |
2235 | return 0; |
2236 | } | |
2237 | ||
2238 | static const struct net_device_ops i40evf_netdev_ops = { | |
2239 | .ndo_open = i40evf_open, | |
2240 | .ndo_stop = i40evf_close, | |
2241 | .ndo_start_xmit = i40evf_xmit_frame, | |
2242 | .ndo_get_stats = i40evf_get_stats, | |
2243 | .ndo_set_rx_mode = i40evf_set_rx_mode, | |
2244 | .ndo_validate_addr = eth_validate_addr, | |
2245 | .ndo_set_mac_address = i40evf_set_mac, | |
2246 | .ndo_change_mtu = i40evf_change_mtu, | |
2247 | .ndo_tx_timeout = i40evf_tx_timeout, | |
2248 | .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid, | |
2249 | .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid, | |
7709b4c1 AD |
2250 | #ifdef CONFIG_NET_POLL_CONTROLLER |
2251 | .ndo_poll_controller = i40evf_netpoll, | |
2252 | #endif | |
5eae00c5 GR |
2253 | }; |
2254 | ||
2255 | /** | |
2256 | * i40evf_check_reset_complete - check that VF reset is complete | |
2257 | * @hw: pointer to hw struct | |
2258 | * | |
2259 | * Returns 0 if device is ready to use, or -EBUSY if it's in reset. | |
2260 | **/ | |
2261 | static int i40evf_check_reset_complete(struct i40e_hw *hw) | |
2262 | { | |
2263 | u32 rstat; | |
2264 | int i; | |
2265 | ||
2266 | for (i = 0; i < 100; i++) { | |
fd35886a AS |
2267 | rstat = rd32(hw, I40E_VFGEN_RSTAT) & |
2268 | I40E_VFGEN_RSTAT_VFR_STATE_MASK; | |
2269 | if ((rstat == I40E_VFR_VFACTIVE) || | |
2270 | (rstat == I40E_VFR_COMPLETED)) | |
5eae00c5 | 2271 | return 0; |
f98a2006 | 2272 | usleep_range(10, 20); |
5eae00c5 GR |
2273 | } |
2274 | return -EBUSY; | |
2275 | } | |
2276 | ||
e6d038de MW |
2277 | /** |
2278 | * i40evf_process_config - Process the config information we got from the PF | |
2279 | * @adapter: board private structure | |
2280 | * | |
2281 | * Verify that we have a valid config struct, and set up our netdev features | |
2282 | * and our VSI struct. | |
2283 | **/ | |
2284 | int i40evf_process_config(struct i40evf_adapter *adapter) | |
2285 | { | |
2286 | struct net_device *netdev = adapter->netdev; | |
2287 | int i; | |
2288 | ||
2289 | /* got VF config message back from PF, now we can parse it */ | |
2290 | for (i = 0; i < adapter->vf_res->num_vsis; i++) { | |
2291 | if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV) | |
2292 | adapter->vsi_res = &adapter->vf_res->vsi_res[i]; | |
2293 | } | |
2294 | if (!adapter->vsi_res) { | |
2295 | dev_err(&adapter->pdev->dev, "No LAN VSI found\n"); | |
2296 | return -ENODEV; | |
2297 | } | |
2298 | ||
2299 | if (adapter->vf_res->vf_offload_flags | |
2300 | & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) { | |
cc7e406c MW |
2301 | netdev->vlan_features = netdev->features & |
2302 | ~(NETIF_F_HW_VLAN_CTAG_TX | | |
2303 | NETIF_F_HW_VLAN_CTAG_RX | | |
2304 | NETIF_F_HW_VLAN_CTAG_FILTER); | |
e6d038de MW |
2305 | netdev->features |= NETIF_F_HW_VLAN_CTAG_TX | |
2306 | NETIF_F_HW_VLAN_CTAG_RX | | |
2307 | NETIF_F_HW_VLAN_CTAG_FILTER; | |
2308 | } | |
2309 | netdev->features |= NETIF_F_HIGHDMA | | |
2310 | NETIF_F_SG | | |
2311 | NETIF_F_IP_CSUM | | |
2312 | NETIF_F_SCTP_CSUM | | |
2313 | NETIF_F_IPV6_CSUM | | |
2314 | NETIF_F_TSO | | |
2315 | NETIF_F_TSO6 | | |
2316 | NETIF_F_RXCSUM | | |
2317 | NETIF_F_GRO; | |
2318 | ||
2319 | /* copy netdev features into list of user selectable features */ | |
2320 | netdev->hw_features |= netdev->features; | |
2321 | netdev->hw_features &= ~NETIF_F_RXCSUM; | |
2322 | ||
2323 | adapter->vsi.id = adapter->vsi_res->vsi_id; | |
2324 | ||
2325 | adapter->vsi.back = adapter; | |
2326 | adapter->vsi.base_vector = 1; | |
2327 | adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK; | |
2328 | adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC | | |
2329 | ITR_REG_TO_USEC(I40E_ITR_RX_DEF)); | |
2330 | adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC | | |
2331 | ITR_REG_TO_USEC(I40E_ITR_TX_DEF)); | |
2332 | adapter->vsi.netdev = adapter->netdev; | |
f578f5f4 | 2333 | adapter->vsi.qs_handle = adapter->vsi_res->qset_handle; |
e6d038de MW |
2334 | return 0; |
2335 | } | |
2336 | ||
5eae00c5 GR |
2337 | /** |
2338 | * i40evf_init_task - worker thread to perform delayed initialization | |
2339 | * @work: pointer to work_struct containing our data | |
2340 | * | |
2341 | * This task completes the work that was begun in probe. Due to the nature | |
2342 | * of VF-PF communications, we may need to wait tens of milliseconds to get | |
dbedd44e | 2343 | * responses back from the PF. Rather than busy-wait in probe and bog down the |
5eae00c5 GR |
2344 | * whole system, we'll do it in a task so we can sleep. |
2345 | * This task only runs during driver init. Once we've established | |
2346 | * communications with the PF driver and set up our netdev, the watchdog | |
2347 | * takes over. | |
2348 | **/ | |
2349 | static void i40evf_init_task(struct work_struct *work) | |
2350 | { | |
2351 | struct i40evf_adapter *adapter = container_of(work, | |
2352 | struct i40evf_adapter, | |
2353 | init_task.work); | |
2354 | struct net_device *netdev = adapter->netdev; | |
5eae00c5 GR |
2355 | struct i40e_hw *hw = &adapter->hw; |
2356 | struct pci_dev *pdev = adapter->pdev; | |
e6d038de | 2357 | int err, bufsz; |
5eae00c5 GR |
2358 | |
2359 | switch (adapter->state) { | |
2360 | case __I40EVF_STARTUP: | |
2361 | /* driver loaded, probe complete */ | |
ef8693eb MW |
2362 | adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED; |
2363 | adapter->flags &= ~I40EVF_FLAG_RESET_PENDING; | |
5eae00c5 GR |
2364 | err = i40e_set_mac_type(hw); |
2365 | if (err) { | |
c2a137cb MW |
2366 | dev_err(&pdev->dev, "Failed to set MAC type (%d)\n", |
2367 | err); | |
2619ef47 | 2368 | goto err; |
5eae00c5 GR |
2369 | } |
2370 | err = i40evf_check_reset_complete(hw); | |
2371 | if (err) { | |
0d9c7ea8 | 2372 | dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n", |
75a64435 | 2373 | err); |
5eae00c5 GR |
2374 | goto err; |
2375 | } | |
2376 | hw->aq.num_arq_entries = I40EVF_AQ_LEN; | |
2377 | hw->aq.num_asq_entries = I40EVF_AQ_LEN; | |
2378 | hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE; | |
2379 | hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE; | |
2380 | ||
2381 | err = i40evf_init_adminq(hw); | |
2382 | if (err) { | |
c2a137cb MW |
2383 | dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n", |
2384 | err); | |
5eae00c5 GR |
2385 | goto err; |
2386 | } | |
2387 | err = i40evf_send_api_ver(adapter); | |
2388 | if (err) { | |
10bdd67b | 2389 | dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err); |
5eae00c5 GR |
2390 | i40evf_shutdown_adminq(hw); |
2391 | goto err; | |
2392 | } | |
2393 | adapter->state = __I40EVF_INIT_VERSION_CHECK; | |
2394 | goto restart; | |
5eae00c5 | 2395 | case __I40EVF_INIT_VERSION_CHECK: |
10bdd67b | 2396 | if (!i40evf_asq_done(hw)) { |
80e72893 | 2397 | dev_err(&pdev->dev, "Admin queue command never completed\n"); |
906a6937 MW |
2398 | i40evf_shutdown_adminq(hw); |
2399 | adapter->state = __I40EVF_STARTUP; | |
5eae00c5 | 2400 | goto err; |
10bdd67b | 2401 | } |
5eae00c5 GR |
2402 | |
2403 | /* aq msg sent, awaiting reply */ | |
2404 | err = i40evf_verify_api_ver(adapter); | |
2405 | if (err) { | |
d4f82fd3 | 2406 | if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) |
56f9920a | 2407 | err = i40evf_send_api_ver(adapter); |
ee1693e5 MW |
2408 | else |
2409 | dev_err(&pdev->dev, "Unsupported PF API version %d.%d, expected %d.%d\n", | |
2410 | adapter->pf_version.major, | |
2411 | adapter->pf_version.minor, | |
2412 | I40E_VIRTCHNL_VERSION_MAJOR, | |
2413 | I40E_VIRTCHNL_VERSION_MINOR); | |
5eae00c5 GR |
2414 | goto err; |
2415 | } | |
2416 | err = i40evf_send_vf_config_msg(adapter); | |
2417 | if (err) { | |
3f2ab172 | 2418 | dev_err(&pdev->dev, "Unable to send config request (%d)\n", |
5eae00c5 GR |
2419 | err); |
2420 | goto err; | |
2421 | } | |
2422 | adapter->state = __I40EVF_INIT_GET_RESOURCES; | |
2423 | goto restart; | |
5eae00c5 GR |
2424 | case __I40EVF_INIT_GET_RESOURCES: |
2425 | /* aq msg sent, awaiting reply */ | |
2426 | if (!adapter->vf_res) { | |
2427 | bufsz = sizeof(struct i40e_virtchnl_vf_resource) + | |
2428 | (I40E_MAX_VF_VSI * | |
2429 | sizeof(struct i40e_virtchnl_vsi_resource)); | |
2430 | adapter->vf_res = kzalloc(bufsz, GFP_KERNEL); | |
c2a137cb | 2431 | if (!adapter->vf_res) |
5eae00c5 | 2432 | goto err; |
5eae00c5 GR |
2433 | } |
2434 | err = i40evf_get_vf_config(adapter); | |
906a6937 | 2435 | if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) { |
906a6937 MW |
2436 | err = i40evf_send_vf_config_msg(adapter); |
2437 | goto err; | |
2438 | } | |
5eae00c5 | 2439 | if (err) { |
c2a137cb MW |
2440 | dev_err(&pdev->dev, "Unable to get VF config (%d)\n", |
2441 | err); | |
5eae00c5 GR |
2442 | goto err_alloc; |
2443 | } | |
2444 | adapter->state = __I40EVF_INIT_SW; | |
2445 | break; | |
2446 | default: | |
2447 | goto err_alloc; | |
2448 | } | |
e6d038de | 2449 | if (i40evf_process_config(adapter)) |
5eae00c5 | 2450 | goto err_alloc; |
e6d038de | 2451 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; |
5eae00c5 GR |
2452 | |
2453 | adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED; | |
2454 | ||
5eae00c5 GR |
2455 | netdev->netdev_ops = &i40evf_netdev_ops; |
2456 | i40evf_set_ethtool_ops(netdev); | |
2457 | netdev->watchdog_timeo = 5 * HZ; | |
3415e8ce | 2458 | |
5eae00c5 | 2459 | if (!is_valid_ether_addr(adapter->hw.mac.addr)) { |
b34f90e7 | 2460 | dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n", |
c2a137cb | 2461 | adapter->hw.mac.addr); |
14e52ee2 MW |
2462 | eth_hw_addr_random(netdev); |
2463 | ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr); | |
2464 | } else { | |
2465 | adapter->flags |= I40EVF_FLAG_ADDR_SET_BY_PF; | |
2466 | ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr); | |
2467 | ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr); | |
5eae00c5 | 2468 | } |
5eae00c5 | 2469 | |
5eae00c5 GR |
2470 | init_timer(&adapter->watchdog_timer); |
2471 | adapter->watchdog_timer.function = &i40evf_watchdog_timer; | |
2472 | adapter->watchdog_timer.data = (unsigned long)adapter; | |
2473 | mod_timer(&adapter->watchdog_timer, jiffies + 1); | |
2474 | ||
cc052927 MW |
2475 | adapter->num_active_queues = min_t(int, |
2476 | adapter->vsi_res->num_queue_pairs, | |
2477 | (int)(num_online_cpus())); | |
d732a184 MW |
2478 | adapter->tx_desc_count = I40EVF_DEFAULT_TXD; |
2479 | adapter->rx_desc_count = I40EVF_DEFAULT_RXD; | |
5eae00c5 GR |
2480 | err = i40evf_init_interrupt_scheme(adapter); |
2481 | if (err) | |
2482 | goto err_sw_init; | |
2483 | i40evf_map_rings_to_vectors(adapter); | |
1f012279 ASJ |
2484 | if (adapter->vf_res->vf_offload_flags & |
2485 | I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) | |
2486 | adapter->flags |= I40EVF_FLAG_WB_ON_ITR_CAPABLE; | |
e25d00b8 | 2487 | if (!RSS_AQ(adapter)) |
96a81986 | 2488 | i40evf_init_rss(adapter); |
5eae00c5 GR |
2489 | err = i40evf_request_misc_irq(adapter); |
2490 | if (err) | |
2491 | goto err_sw_init; | |
2492 | ||
2493 | netif_carrier_off(netdev); | |
2494 | ||
ef8693eb MW |
2495 | if (!adapter->netdev_registered) { |
2496 | err = register_netdev(netdev); | |
2497 | if (err) | |
2498 | goto err_register; | |
2499 | } | |
5eae00c5 GR |
2500 | |
2501 | adapter->netdev_registered = true; | |
2502 | ||
2503 | netif_tx_stop_all_queues(netdev); | |
2504 | ||
b34f90e7 | 2505 | dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr); |
5eae00c5 GR |
2506 | if (netdev->features & NETIF_F_GRO) |
2507 | dev_info(&pdev->dev, "GRO is enabled\n"); | |
2508 | ||
2509 | dev_info(&pdev->dev, "%s\n", i40evf_driver_string); | |
2510 | adapter->state = __I40EVF_DOWN; | |
2511 | set_bit(__I40E_DOWN, &adapter->vsi.state); | |
2512 | i40evf_misc_irq_enable(adapter); | |
e25d00b8 ASJ |
2513 | |
2514 | if (RSS_AQ(adapter)) { | |
2515 | adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_RSS; | |
2516 | mod_timer_pending(&adapter->watchdog_timer, jiffies + 1); | |
2517 | } else { | |
96a81986 | 2518 | i40evf_init_rss(adapter); |
e25d00b8 | 2519 | } |
5eae00c5 GR |
2520 | return; |
2521 | restart: | |
3f7e5c33 | 2522 | schedule_delayed_work(&adapter->init_task, msecs_to_jiffies(30)); |
5eae00c5 GR |
2523 | return; |
2524 | ||
2525 | err_register: | |
2526 | i40evf_free_misc_irq(adapter); | |
2527 | err_sw_init: | |
2528 | i40evf_reset_interrupt_capability(adapter); | |
5eae00c5 GR |
2529 | err_alloc: |
2530 | kfree(adapter->vf_res); | |
2531 | adapter->vf_res = NULL; | |
2532 | err: | |
2533 | /* Things went into the weeds, so try again later */ | |
2534 | if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) { | |
b9029e94 | 2535 | dev_err(&pdev->dev, "Failed to communicate with PF; waiting before retry\n"); |
ef8693eb | 2536 | adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED; |
b9029e94 MW |
2537 | i40evf_shutdown_adminq(hw); |
2538 | adapter->state = __I40EVF_STARTUP; | |
2539 | schedule_delayed_work(&adapter->init_task, HZ * 5); | |
2540 | return; | |
5eae00c5 | 2541 | } |
3f7e5c33 | 2542 | schedule_delayed_work(&adapter->init_task, HZ); |
5eae00c5 GR |
2543 | } |
2544 | ||
2545 | /** | |
2546 | * i40evf_shutdown - Shutdown the device in preparation for a reboot | |
2547 | * @pdev: pci device structure | |
2548 | **/ | |
2549 | static void i40evf_shutdown(struct pci_dev *pdev) | |
2550 | { | |
2551 | struct net_device *netdev = pci_get_drvdata(pdev); | |
00293fdc | 2552 | struct i40evf_adapter *adapter = netdev_priv(netdev); |
5eae00c5 GR |
2553 | |
2554 | netif_device_detach(netdev); | |
2555 | ||
2556 | if (netif_running(netdev)) | |
2557 | i40evf_close(netdev); | |
2558 | ||
00293fdc MW |
2559 | /* Prevent the watchdog from running. */ |
2560 | adapter->state = __I40EVF_REMOVE; | |
2561 | adapter->aq_required = 0; | |
00293fdc | 2562 | |
5eae00c5 GR |
2563 | #ifdef CONFIG_PM |
2564 | pci_save_state(pdev); | |
2565 | ||
2566 | #endif | |
2567 | pci_disable_device(pdev); | |
2568 | } | |
2569 | ||
2570 | /** | |
2571 | * i40evf_probe - Device Initialization Routine | |
2572 | * @pdev: PCI device information struct | |
2573 | * @ent: entry in i40evf_pci_tbl | |
2574 | * | |
2575 | * Returns 0 on success, negative on failure | |
2576 | * | |
2577 | * i40evf_probe initializes an adapter identified by a pci_dev structure. | |
2578 | * The OS initialization, configuring of the adapter private structure, | |
2579 | * and a hardware reset occur. | |
2580 | **/ | |
2581 | static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |
2582 | { | |
2583 | struct net_device *netdev; | |
2584 | struct i40evf_adapter *adapter = NULL; | |
2585 | struct i40e_hw *hw = NULL; | |
dbbd8111 | 2586 | int err; |
5eae00c5 GR |
2587 | |
2588 | err = pci_enable_device(pdev); | |
2589 | if (err) | |
2590 | return err; | |
2591 | ||
6494294f | 2592 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
6494294f | 2593 | if (err) { |
e3e3bfdd JS |
2594 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
2595 | if (err) { | |
2596 | dev_err(&pdev->dev, | |
2597 | "DMA configuration failed: 0x%x\n", err); | |
2598 | goto err_dma; | |
2599 | } | |
5eae00c5 GR |
2600 | } |
2601 | ||
2602 | err = pci_request_regions(pdev, i40evf_driver_name); | |
2603 | if (err) { | |
2604 | dev_err(&pdev->dev, | |
2605 | "pci_request_regions failed 0x%x\n", err); | |
2606 | goto err_pci_reg; | |
2607 | } | |
2608 | ||
2609 | pci_enable_pcie_error_reporting(pdev); | |
2610 | ||
2611 | pci_set_master(pdev); | |
2612 | ||
2613 | netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter), | |
2614 | MAX_TX_QUEUES); | |
2615 | if (!netdev) { | |
2616 | err = -ENOMEM; | |
2617 | goto err_alloc_etherdev; | |
2618 | } | |
2619 | ||
2620 | SET_NETDEV_DEV(netdev, &pdev->dev); | |
2621 | ||
2622 | pci_set_drvdata(pdev, netdev); | |
2623 | adapter = netdev_priv(netdev); | |
5eae00c5 GR |
2624 | |
2625 | adapter->netdev = netdev; | |
2626 | adapter->pdev = pdev; | |
2627 | ||
2628 | hw = &adapter->hw; | |
2629 | hw->back = adapter; | |
2630 | ||
41a1d04b | 2631 | adapter->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
5eae00c5 GR |
2632 | adapter->state = __I40EVF_STARTUP; |
2633 | ||
2634 | /* Call save state here because it relies on the adapter struct. */ | |
2635 | pci_save_state(pdev); | |
2636 | ||
2637 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), | |
2638 | pci_resource_len(pdev, 0)); | |
2639 | if (!hw->hw_addr) { | |
2640 | err = -EIO; | |
2641 | goto err_ioremap; | |
2642 | } | |
2643 | hw->vendor_id = pdev->vendor; | |
2644 | hw->device_id = pdev->device; | |
2645 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); | |
2646 | hw->subsystem_vendor_id = pdev->subsystem_vendor; | |
2647 | hw->subsystem_device_id = pdev->subsystem_device; | |
2648 | hw->bus.device = PCI_SLOT(pdev->devfn); | |
2649 | hw->bus.func = PCI_FUNC(pdev->devfn); | |
2650 | ||
8bb1a540 SK |
2651 | INIT_LIST_HEAD(&adapter->mac_filter_list); |
2652 | INIT_LIST_HEAD(&adapter->vlan_filter_list); | |
2653 | ||
5eae00c5 GR |
2654 | INIT_WORK(&adapter->reset_task, i40evf_reset_task); |
2655 | INIT_WORK(&adapter->adminq_task, i40evf_adminq_task); | |
2656 | INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task); | |
2657 | INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task); | |
9b32b0b5 MW |
2658 | schedule_delayed_work(&adapter->init_task, |
2659 | msecs_to_jiffies(5 * (pdev->devfn & 0x07))); | |
5eae00c5 GR |
2660 | |
2661 | return 0; | |
2662 | ||
2663 | err_ioremap: | |
2664 | free_netdev(netdev); | |
2665 | err_alloc_etherdev: | |
2666 | pci_release_regions(pdev); | |
2667 | err_pci_reg: | |
2668 | err_dma: | |
2669 | pci_disable_device(pdev); | |
2670 | return err; | |
2671 | } | |
2672 | ||
2673 | #ifdef CONFIG_PM | |
2674 | /** | |
2675 | * i40evf_suspend - Power management suspend routine | |
2676 | * @pdev: PCI device information struct | |
2677 | * @state: unused | |
2678 | * | |
2679 | * Called when the system (VM) is entering sleep/suspend. | |
2680 | **/ | |
2681 | static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state) | |
2682 | { | |
2683 | struct net_device *netdev = pci_get_drvdata(pdev); | |
2684 | struct i40evf_adapter *adapter = netdev_priv(netdev); | |
2685 | int retval = 0; | |
2686 | ||
2687 | netif_device_detach(netdev); | |
2688 | ||
2689 | if (netif_running(netdev)) { | |
2690 | rtnl_lock(); | |
2691 | i40evf_down(adapter); | |
2692 | rtnl_unlock(); | |
2693 | } | |
2694 | i40evf_free_misc_irq(adapter); | |
2695 | i40evf_reset_interrupt_capability(adapter); | |
2696 | ||
2697 | retval = pci_save_state(pdev); | |
2698 | if (retval) | |
2699 | return retval; | |
2700 | ||
2701 | pci_disable_device(pdev); | |
2702 | ||
2703 | return 0; | |
2704 | } | |
2705 | ||
2706 | /** | |
dbedd44e | 2707 | * i40evf_resume - Power management resume routine |
5eae00c5 GR |
2708 | * @pdev: PCI device information struct |
2709 | * | |
2710 | * Called when the system (VM) is resumed from sleep/suspend. | |
2711 | **/ | |
2712 | static int i40evf_resume(struct pci_dev *pdev) | |
2713 | { | |
2714 | struct i40evf_adapter *adapter = pci_get_drvdata(pdev); | |
2715 | struct net_device *netdev = adapter->netdev; | |
2716 | u32 err; | |
2717 | ||
2718 | pci_set_power_state(pdev, PCI_D0); | |
2719 | pci_restore_state(pdev); | |
2720 | /* pci_restore_state clears dev->state_saved so call | |
2721 | * pci_save_state to restore it. | |
2722 | */ | |
2723 | pci_save_state(pdev); | |
2724 | ||
2725 | err = pci_enable_device_mem(pdev); | |
2726 | if (err) { | |
2727 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n"); | |
2728 | return err; | |
2729 | } | |
2730 | pci_set_master(pdev); | |
2731 | ||
2732 | rtnl_lock(); | |
2733 | err = i40evf_set_interrupt_capability(adapter); | |
2734 | if (err) { | |
f2a1c368 | 2735 | rtnl_unlock(); |
5eae00c5 GR |
2736 | dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n"); |
2737 | return err; | |
2738 | } | |
2739 | err = i40evf_request_misc_irq(adapter); | |
2740 | rtnl_unlock(); | |
2741 | if (err) { | |
2742 | dev_err(&pdev->dev, "Cannot get interrupt vector.\n"); | |
2743 | return err; | |
2744 | } | |
2745 | ||
2746 | schedule_work(&adapter->reset_task); | |
2747 | ||
2748 | netif_device_attach(netdev); | |
2749 | ||
2750 | return err; | |
2751 | } | |
2752 | ||
2753 | #endif /* CONFIG_PM */ | |
2754 | /** | |
2755 | * i40evf_remove - Device Removal Routine | |
2756 | * @pdev: PCI device information struct | |
2757 | * | |
2758 | * i40evf_remove is called by the PCI subsystem to alert the driver | |
2759 | * that it should release a PCI device. The could be caused by a | |
2760 | * Hot-Plug event, or because the driver is going to be removed from | |
2761 | * memory. | |
2762 | **/ | |
2763 | static void i40evf_remove(struct pci_dev *pdev) | |
2764 | { | |
2765 | struct net_device *netdev = pci_get_drvdata(pdev); | |
2766 | struct i40evf_adapter *adapter = netdev_priv(netdev); | |
6ba36a24 | 2767 | struct i40evf_mac_filter *f, *ftmp; |
5eae00c5 GR |
2768 | struct i40e_hw *hw = &adapter->hw; |
2769 | ||
2770 | cancel_delayed_work_sync(&adapter->init_task); | |
ef8693eb | 2771 | cancel_work_sync(&adapter->reset_task); |
5eae00c5 GR |
2772 | |
2773 | if (adapter->netdev_registered) { | |
2774 | unregister_netdev(netdev); | |
2775 | adapter->netdev_registered = false; | |
2776 | } | |
53d0b3ae | 2777 | |
f4a71881 | 2778 | /* Shut down all the garbage mashers on the detention level */ |
5eae00c5 | 2779 | adapter->state = __I40EVF_REMOVE; |
f4a71881 | 2780 | adapter->aq_required = 0; |
f4a71881 MW |
2781 | i40evf_request_reset(adapter); |
2782 | msleep(20); | |
2783 | /* If the FW isn't responding, kick it once, but only once. */ | |
2784 | if (!i40evf_asq_done(hw)) { | |
2785 | i40evf_request_reset(adapter); | |
2786 | msleep(20); | |
2787 | } | |
5eae00c5 | 2788 | |
dbb01c8a | 2789 | if (adapter->msix_entries) { |
5eae00c5 | 2790 | i40evf_misc_irq_disable(adapter); |
5eae00c5 | 2791 | i40evf_free_misc_irq(adapter); |
5eae00c5 | 2792 | i40evf_reset_interrupt_capability(adapter); |
d31944d6 | 2793 | i40evf_free_q_vectors(adapter); |
5eae00c5 GR |
2794 | } |
2795 | ||
e5d17c3e MW |
2796 | if (adapter->watchdog_timer.function) |
2797 | del_timer_sync(&adapter->watchdog_timer); | |
2798 | ||
dbb01c8a MW |
2799 | flush_scheduled_work(); |
2800 | ||
66f9af85 HZ |
2801 | /* Clear user configurations for RSS */ |
2802 | i40evf_clear_rss_config_user(&adapter->vsi); | |
2803 | ||
5eae00c5 GR |
2804 | if (hw->aq.asq.count) |
2805 | i40evf_shutdown_adminq(hw); | |
2806 | ||
2807 | iounmap(hw->hw_addr); | |
2808 | pci_release_regions(pdev); | |
2809 | ||
e284fc88 MW |
2810 | i40evf_free_all_tx_resources(adapter); |
2811 | i40evf_free_all_rx_resources(adapter); | |
5eae00c5 GR |
2812 | i40evf_free_queues(adapter); |
2813 | kfree(adapter->vf_res); | |
6ba36a24 MW |
2814 | /* If we got removed before an up/down sequence, we've got a filter |
2815 | * hanging out there that we need to get rid of. | |
2816 | */ | |
2817 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { | |
2818 | list_del(&f->list); | |
2819 | kfree(f); | |
2820 | } | |
37dfdf37 MW |
2821 | list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { |
2822 | list_del(&f->list); | |
2823 | kfree(f); | |
2824 | } | |
5eae00c5 GR |
2825 | |
2826 | free_netdev(netdev); | |
2827 | ||
2828 | pci_disable_pcie_error_reporting(pdev); | |
2829 | ||
2830 | pci_disable_device(pdev); | |
2831 | } | |
2832 | ||
2833 | static struct pci_driver i40evf_driver = { | |
2834 | .name = i40evf_driver_name, | |
2835 | .id_table = i40evf_pci_tbl, | |
2836 | .probe = i40evf_probe, | |
2837 | .remove = i40evf_remove, | |
2838 | #ifdef CONFIG_PM | |
2839 | .suspend = i40evf_suspend, | |
2840 | .resume = i40evf_resume, | |
2841 | #endif | |
2842 | .shutdown = i40evf_shutdown, | |
2843 | }; | |
2844 | ||
2845 | /** | |
2846 | * i40e_init_module - Driver Registration Routine | |
2847 | * | |
2848 | * i40e_init_module is the first routine called when the driver is | |
2849 | * loaded. All it does is register with the PCI subsystem. | |
2850 | **/ | |
2851 | static int __init i40evf_init_module(void) | |
2852 | { | |
2853 | int ret; | |
75a64435 | 2854 | |
5eae00c5 | 2855 | pr_info("i40evf: %s - version %s\n", i40evf_driver_string, |
75a64435 | 2856 | i40evf_driver_version); |
5eae00c5 GR |
2857 | |
2858 | pr_info("%s\n", i40evf_copyright); | |
2859 | ||
2860 | ret = pci_register_driver(&i40evf_driver); | |
2861 | return ret; | |
2862 | } | |
2863 | ||
2864 | module_init(i40evf_init_module); | |
2865 | ||
2866 | /** | |
2867 | * i40e_exit_module - Driver Exit Cleanup Routine | |
2868 | * | |
2869 | * i40e_exit_module is called just before the driver is removed | |
2870 | * from memory. | |
2871 | **/ | |
2872 | static void __exit i40evf_exit_module(void) | |
2873 | { | |
2874 | pci_unregister_driver(&i40evf_driver); | |
2875 | } | |
2876 | ||
2877 | module_exit(i40evf_exit_module); | |
2878 | ||
2879 | /* i40evf_main.c */ |