]>
Commit | Line | Data |
---|---|---|
ae06c70b | 1 | // SPDX-License-Identifier: GPL-2.0 |
51dce24b | 2 | /* Copyright(c) 2013 - 2018 Intel Corporation. */ |
5eae00c5 | 3 | |
5ec8b7d1 | 4 | #include "iavf.h" |
66bc8e0f | 5 | #include "iavf_prototype.h" |
5ec8b7d1 | 6 | #include "iavf_client.h" |
129cf89e | 7 | /* All iavf tracepoints are defined by the include below, which must |
ed0980c4 SP |
8 | * be included exactly once across the whole kernel with |
9 | * CREATE_TRACE_POINTS defined | |
10 | */ | |
11 | #define CREATE_TRACE_POINTS | |
ad64ed8b | 12 | #include "iavf_trace.h" |
ed0980c4 | 13 | |
129cf89e JB |
14 | static int iavf_setup_all_tx_resources(struct iavf_adapter *adapter); |
15 | static int iavf_setup_all_rx_resources(struct iavf_adapter *adapter); | |
16 | static int iavf_close(struct net_device *netdev); | |
b66c7bc1 JP |
17 | static int iavf_init_get_resources(struct iavf_adapter *adapter); |
18 | static int iavf_check_reset_complete(struct iavf_hw *hw); | |
5eae00c5 | 19 | |
129cf89e JB |
20 | char iavf_driver_name[] = "iavf"; |
21 | static const char iavf_driver_string[] = | |
8062b226 | 22 | "Intel(R) Ethernet Adaptive Virtual Function Network Driver"; |
5eae00c5 | 23 | |
129cf89e | 24 | static const char iavf_copyright[] = |
8062b226 | 25 | "Copyright (c) 2013 - 2018 Intel Corporation."; |
5eae00c5 | 26 | |
129cf89e | 27 | /* iavf_pci_tbl - PCI Device ID Table |
5eae00c5 GR |
28 | * |
29 | * Wildcard entries (PCI_ANY_ID) should come last | |
30 | * Last entry must be all 0s | |
31 | * | |
32 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, | |
33 | * Class, Class Mask, private data (not used) } | |
34 | */ | |
129cf89e | 35 | static const struct pci_device_id iavf_pci_tbl[] = { |
4dbc76e0 JB |
36 | {PCI_VDEVICE(INTEL, IAVF_DEV_ID_VF), 0}, |
37 | {PCI_VDEVICE(INTEL, IAVF_DEV_ID_VF_HV), 0}, | |
38 | {PCI_VDEVICE(INTEL, IAVF_DEV_ID_X722_VF), 0}, | |
39 | {PCI_VDEVICE(INTEL, IAVF_DEV_ID_ADAPTIVE_VF), 0}, | |
5eae00c5 GR |
40 | /* required last entry */ |
41 | {0, } | |
42 | }; | |
43 | ||
129cf89e | 44 | MODULE_DEVICE_TABLE(pci, iavf_pci_tbl); |
5eae00c5 | 45 | |
8062b226 | 46 | MODULE_ALIAS("i40evf"); |
5eae00c5 | 47 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
98674ebe JB |
48 | MODULE_DESCRIPTION("Intel(R) Ethernet Adaptive Virtual Function Network Driver"); |
49 | MODULE_LICENSE("GPL v2"); | |
5eae00c5 | 50 | |
b66c7bc1 | 51 | static const struct net_device_ops iavf_netdev_ops; |
fdd4044f | 52 | struct workqueue_struct *iavf_wq; |
2803b16c | 53 | |
5eae00c5 | 54 | /** |
129cf89e | 55 | * iavf_allocate_dma_mem_d - OS specific memory alloc for shared code |
5eae00c5 GR |
56 | * @hw: pointer to the HW structure |
57 | * @mem: ptr to mem struct to fill out | |
58 | * @size: size of memory requested | |
59 | * @alignment: what to align the allocation to | |
60 | **/ | |
80754bbc SN |
61 | enum iavf_status iavf_allocate_dma_mem_d(struct iavf_hw *hw, |
62 | struct iavf_dma_mem *mem, | |
63 | u64 size, u32 alignment) | |
5eae00c5 | 64 | { |
129cf89e | 65 | struct iavf_adapter *adapter = (struct iavf_adapter *)hw->back; |
5eae00c5 GR |
66 | |
67 | if (!mem) | |
8821b3fa | 68 | return IAVF_ERR_PARAM; |
5eae00c5 GR |
69 | |
70 | mem->size = ALIGN(size, alignment); | |
71 | mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size, | |
72 | (dma_addr_t *)&mem->pa, GFP_KERNEL); | |
73 | if (mem->va) | |
74 | return 0; | |
75 | else | |
8821b3fa | 76 | return IAVF_ERR_NO_MEMORY; |
5eae00c5 GR |
77 | } |
78 | ||
79 | /** | |
129cf89e | 80 | * iavf_free_dma_mem_d - OS specific memory free for shared code |
5eae00c5 GR |
81 | * @hw: pointer to the HW structure |
82 | * @mem: ptr to mem struct to free | |
83 | **/ | |
80754bbc SN |
84 | enum iavf_status iavf_free_dma_mem_d(struct iavf_hw *hw, |
85 | struct iavf_dma_mem *mem) | |
5eae00c5 | 86 | { |
129cf89e | 87 | struct iavf_adapter *adapter = (struct iavf_adapter *)hw->back; |
5eae00c5 GR |
88 | |
89 | if (!mem || !mem->va) | |
8821b3fa | 90 | return IAVF_ERR_PARAM; |
5eae00c5 GR |
91 | dma_free_coherent(&adapter->pdev->dev, mem->size, |
92 | mem->va, (dma_addr_t)mem->pa); | |
93 | return 0; | |
94 | } | |
95 | ||
96 | /** | |
129cf89e | 97 | * iavf_allocate_virt_mem_d - OS specific memory alloc for shared code |
5eae00c5 GR |
98 | * @hw: pointer to the HW structure |
99 | * @mem: ptr to mem struct to fill out | |
100 | * @size: size of memory requested | |
101 | **/ | |
80754bbc SN |
102 | enum iavf_status iavf_allocate_virt_mem_d(struct iavf_hw *hw, |
103 | struct iavf_virt_mem *mem, u32 size) | |
5eae00c5 GR |
104 | { |
105 | if (!mem) | |
8821b3fa | 106 | return IAVF_ERR_PARAM; |
5eae00c5 GR |
107 | |
108 | mem->size = size; | |
109 | mem->va = kzalloc(size, GFP_KERNEL); | |
110 | ||
111 | if (mem->va) | |
112 | return 0; | |
113 | else | |
8821b3fa | 114 | return IAVF_ERR_NO_MEMORY; |
5eae00c5 GR |
115 | } |
116 | ||
117 | /** | |
129cf89e | 118 | * iavf_free_virt_mem_d - OS specific memory free for shared code |
5eae00c5 GR |
119 | * @hw: pointer to the HW structure |
120 | * @mem: ptr to mem struct to free | |
121 | **/ | |
80754bbc SN |
122 | enum iavf_status iavf_free_virt_mem_d(struct iavf_hw *hw, |
123 | struct iavf_virt_mem *mem) | |
5eae00c5 GR |
124 | { |
125 | if (!mem) | |
8821b3fa | 126 | return IAVF_ERR_PARAM; |
5eae00c5 GR |
127 | |
128 | /* it's ok to kfree a NULL pointer */ | |
129 | kfree(mem->va); | |
130 | ||
131 | return 0; | |
132 | } | |
133 | ||
226d5285 | 134 | /** |
5ac49f3c SA |
135 | * iavf_lock_timeout - try to lock mutex but give up after timeout |
136 | * @lock: mutex that should be locked | |
226d5285 SA |
137 | * @msecs: timeout in msecs |
138 | * | |
139 | * Returns 0 on success, negative on failure | |
140 | **/ | |
5ac49f3c | 141 | static int iavf_lock_timeout(struct mutex *lock, unsigned int msecs) |
226d5285 SA |
142 | { |
143 | unsigned int wait, delay = 10; | |
144 | ||
145 | for (wait = 0; wait < msecs; wait += delay) { | |
5ac49f3c | 146 | if (mutex_trylock(lock)) |
226d5285 SA |
147 | return 0; |
148 | ||
149 | msleep(delay); | |
150 | } | |
151 | ||
152 | return -1; | |
153 | } | |
154 | ||
00e5ec4b | 155 | /** |
129cf89e | 156 | * iavf_schedule_reset - Set the flags and schedule a reset event |
00e5ec4b MW |
157 | * @adapter: board private structure |
158 | **/ | |
129cf89e | 159 | void iavf_schedule_reset(struct iavf_adapter *adapter) |
00e5ec4b MW |
160 | { |
161 | if (!(adapter->flags & | |
129cf89e JB |
162 | (IAVF_FLAG_RESET_PENDING | IAVF_FLAG_RESET_NEEDED))) { |
163 | adapter->flags |= IAVF_FLAG_RESET_NEEDED; | |
fdd4044f | 164 | queue_work(iavf_wq, &adapter->reset_task); |
00e5ec4b MW |
165 | } |
166 | } | |
167 | ||
6a8621b9 JJ |
168 | /** |
169 | * iavf_schedule_request_stats - Set the flags and schedule statistics request | |
170 | * @adapter: board private structure | |
171 | * | |
172 | * Sets IAVF_FLAG_AQ_REQUEST_STATS flag so iavf_watchdog_task() will explicitly | |
173 | * request and refresh ethtool stats | |
174 | **/ | |
175 | void iavf_schedule_request_stats(struct iavf_adapter *adapter) | |
176 | { | |
177 | adapter->aq_required |= IAVF_FLAG_AQ_REQUEST_STATS; | |
178 | mod_delayed_work(iavf_wq, &adapter->watchdog_task, 0); | |
179 | } | |
180 | ||
5eae00c5 | 181 | /** |
129cf89e | 182 | * iavf_tx_timeout - Respond to a Tx Hang |
5eae00c5 | 183 | * @netdev: network interface device structure |
b50f7bca | 184 | * @txqueue: queue number that is timing out |
5eae00c5 | 185 | **/ |
0290bd29 | 186 | static void iavf_tx_timeout(struct net_device *netdev, unsigned int txqueue) |
5eae00c5 | 187 | { |
129cf89e | 188 | struct iavf_adapter *adapter = netdev_priv(netdev); |
5eae00c5 GR |
189 | |
190 | adapter->tx_timeout_count++; | |
129cf89e | 191 | iavf_schedule_reset(adapter); |
5eae00c5 GR |
192 | } |
193 | ||
194 | /** | |
129cf89e | 195 | * iavf_misc_irq_disable - Mask off interrupt generation on the NIC |
5eae00c5 GR |
196 | * @adapter: board private structure |
197 | **/ | |
129cf89e | 198 | static void iavf_misc_irq_disable(struct iavf_adapter *adapter) |
5eae00c5 | 199 | { |
f349daa5 | 200 | struct iavf_hw *hw = &adapter->hw; |
75a64435 | 201 | |
ef4603e8 JK |
202 | if (!adapter->msix_entries) |
203 | return; | |
204 | ||
f1cad2ce | 205 | wr32(hw, IAVF_VFINT_DYN_CTL01, 0); |
5eae00c5 | 206 | |
f1cad2ce | 207 | iavf_flush(hw); |
5eae00c5 GR |
208 | |
209 | synchronize_irq(adapter->msix_entries[0].vector); | |
210 | } | |
211 | ||
212 | /** | |
129cf89e | 213 | * iavf_misc_irq_enable - Enable default interrupt generation settings |
5eae00c5 GR |
214 | * @adapter: board private structure |
215 | **/ | |
129cf89e | 216 | static void iavf_misc_irq_enable(struct iavf_adapter *adapter) |
5eae00c5 | 217 | { |
f349daa5 | 218 | struct iavf_hw *hw = &adapter->hw; |
75a64435 | 219 | |
f1cad2ce JB |
220 | wr32(hw, IAVF_VFINT_DYN_CTL01, IAVF_VFINT_DYN_CTL01_INTENA_MASK | |
221 | IAVF_VFINT_DYN_CTL01_ITR_INDX_MASK); | |
222 | wr32(hw, IAVF_VFINT_ICR0_ENA1, IAVF_VFINT_ICR0_ENA1_ADMINQ_MASK); | |
5eae00c5 | 223 | |
f1cad2ce | 224 | iavf_flush(hw); |
5eae00c5 GR |
225 | } |
226 | ||
227 | /** | |
129cf89e | 228 | * iavf_irq_disable - Mask off interrupt generation on the NIC |
5eae00c5 GR |
229 | * @adapter: board private structure |
230 | **/ | |
129cf89e | 231 | static void iavf_irq_disable(struct iavf_adapter *adapter) |
5eae00c5 GR |
232 | { |
233 | int i; | |
f349daa5 | 234 | struct iavf_hw *hw = &adapter->hw; |
5eae00c5 | 235 | |
dbb01c8a MW |
236 | if (!adapter->msix_entries) |
237 | return; | |
238 | ||
5eae00c5 | 239 | for (i = 1; i < adapter->num_msix_vectors; i++) { |
f1cad2ce | 240 | wr32(hw, IAVF_VFINT_DYN_CTLN1(i - 1), 0); |
5eae00c5 GR |
241 | synchronize_irq(adapter->msix_entries[i].vector); |
242 | } | |
f1cad2ce | 243 | iavf_flush(hw); |
5eae00c5 GR |
244 | } |
245 | ||
246 | /** | |
129cf89e | 247 | * iavf_irq_enable_queues - Enable interrupt for specified queues |
5eae00c5 GR |
248 | * @adapter: board private structure |
249 | * @mask: bitmap of queues to enable | |
250 | **/ | |
129cf89e | 251 | void iavf_irq_enable_queues(struct iavf_adapter *adapter, u32 mask) |
5eae00c5 | 252 | { |
f349daa5 | 253 | struct iavf_hw *hw = &adapter->hw; |
5eae00c5 GR |
254 | int i; |
255 | ||
256 | for (i = 1; i < adapter->num_msix_vectors; i++) { | |
41a1d04b | 257 | if (mask & BIT(i - 1)) { |
f1cad2ce JB |
258 | wr32(hw, IAVF_VFINT_DYN_CTLN1(i - 1), |
259 | IAVF_VFINT_DYN_CTLN1_INTENA_MASK | | |
260 | IAVF_VFINT_DYN_CTLN1_ITR_INDX_MASK); | |
5eae00c5 GR |
261 | } |
262 | } | |
263 | } | |
264 | ||
5eae00c5 | 265 | /** |
129cf89e | 266 | * iavf_irq_enable - Enable default interrupt generation settings |
5eae00c5 | 267 | * @adapter: board private structure |
69c1d70a | 268 | * @flush: boolean value whether to run rd32() |
5eae00c5 | 269 | **/ |
129cf89e | 270 | void iavf_irq_enable(struct iavf_adapter *adapter, bool flush) |
5eae00c5 | 271 | { |
f349daa5 | 272 | struct iavf_hw *hw = &adapter->hw; |
5eae00c5 | 273 | |
129cf89e JB |
274 | iavf_misc_irq_enable(adapter); |
275 | iavf_irq_enable_queues(adapter, ~0); | |
5eae00c5 GR |
276 | |
277 | if (flush) | |
f1cad2ce | 278 | iavf_flush(hw); |
5eae00c5 GR |
279 | } |
280 | ||
281 | /** | |
129cf89e | 282 | * iavf_msix_aq - Interrupt handler for vector 0 |
5eae00c5 GR |
283 | * @irq: interrupt number |
284 | * @data: pointer to netdev | |
285 | **/ | |
129cf89e | 286 | static irqreturn_t iavf_msix_aq(int irq, void *data) |
5eae00c5 GR |
287 | { |
288 | struct net_device *netdev = data; | |
129cf89e | 289 | struct iavf_adapter *adapter = netdev_priv(netdev); |
f349daa5 | 290 | struct iavf_hw *hw = &adapter->hw; |
5eae00c5 | 291 | |
cfbe4dba | 292 | /* handle non-queue interrupts, these reads clear the registers */ |
f1cad2ce JB |
293 | rd32(hw, IAVF_VFINT_ICR01); |
294 | rd32(hw, IAVF_VFINT_ICR0_ENA1); | |
5eae00c5 | 295 | |
5eae00c5 | 296 | /* schedule work on the private workqueue */ |
fdd4044f | 297 | queue_work(iavf_wq, &adapter->adminq_task); |
5eae00c5 GR |
298 | |
299 | return IRQ_HANDLED; | |
300 | } | |
301 | ||
302 | /** | |
129cf89e | 303 | * iavf_msix_clean_rings - MSIX mode Interrupt Handler |
5eae00c5 GR |
304 | * @irq: interrupt number |
305 | * @data: pointer to a q_vector | |
306 | **/ | |
129cf89e | 307 | static irqreturn_t iavf_msix_clean_rings(int irq, void *data) |
5eae00c5 | 308 | { |
56184e01 | 309 | struct iavf_q_vector *q_vector = data; |
5eae00c5 GR |
310 | |
311 | if (!q_vector->tx.ring && !q_vector->rx.ring) | |
312 | return IRQ_HANDLED; | |
313 | ||
5d3465a1 | 314 | napi_schedule_irqoff(&q_vector->napi); |
5eae00c5 GR |
315 | |
316 | return IRQ_HANDLED; | |
317 | } | |
318 | ||
319 | /** | |
129cf89e | 320 | * iavf_map_vector_to_rxq - associate irqs with rx queues |
5eae00c5 GR |
321 | * @adapter: board private structure |
322 | * @v_idx: interrupt number | |
323 | * @r_idx: queue number | |
324 | **/ | |
325 | static void | |
129cf89e | 326 | iavf_map_vector_to_rxq(struct iavf_adapter *adapter, int v_idx, int r_idx) |
5eae00c5 | 327 | { |
56184e01 JB |
328 | struct iavf_q_vector *q_vector = &adapter->q_vectors[v_idx]; |
329 | struct iavf_ring *rx_ring = &adapter->rx_rings[r_idx]; | |
f349daa5 | 330 | struct iavf_hw *hw = &adapter->hw; |
5eae00c5 GR |
331 | |
332 | rx_ring->q_vector = q_vector; | |
333 | rx_ring->next = q_vector->rx.ring; | |
334 | rx_ring->vsi = &adapter->vsi; | |
335 | q_vector->rx.ring = rx_ring; | |
336 | q_vector->rx.count++; | |
a0073a4b | 337 | q_vector->rx.next_update = jiffies + 1; |
556fdfd6 | 338 | q_vector->rx.target_itr = ITR_TO_REG(rx_ring->itr_setting); |
f19a973f | 339 | q_vector->ring_mask |= BIT(r_idx); |
56184e01 | 340 | wr32(hw, IAVF_VFINT_ITRN1(IAVF_RX_ITR, q_vector->reg_idx), |
4eda4e00 | 341 | q_vector->rx.current_itr >> 1); |
556fdfd6 | 342 | q_vector->rx.current_itr = q_vector->rx.target_itr; |
5eae00c5 GR |
343 | } |
344 | ||
345 | /** | |
129cf89e | 346 | * iavf_map_vector_to_txq - associate irqs with tx queues |
5eae00c5 GR |
347 | * @adapter: board private structure |
348 | * @v_idx: interrupt number | |
349 | * @t_idx: queue number | |
350 | **/ | |
351 | static void | |
129cf89e | 352 | iavf_map_vector_to_txq(struct iavf_adapter *adapter, int v_idx, int t_idx) |
5eae00c5 | 353 | { |
56184e01 JB |
354 | struct iavf_q_vector *q_vector = &adapter->q_vectors[v_idx]; |
355 | struct iavf_ring *tx_ring = &adapter->tx_rings[t_idx]; | |
f349daa5 | 356 | struct iavf_hw *hw = &adapter->hw; |
5eae00c5 GR |
357 | |
358 | tx_ring->q_vector = q_vector; | |
359 | tx_ring->next = q_vector->tx.ring; | |
360 | tx_ring->vsi = &adapter->vsi; | |
361 | q_vector->tx.ring = tx_ring; | |
362 | q_vector->tx.count++; | |
a0073a4b | 363 | q_vector->tx.next_update = jiffies + 1; |
556fdfd6 | 364 | q_vector->tx.target_itr = ITR_TO_REG(tx_ring->itr_setting); |
5eae00c5 | 365 | q_vector->num_ringpairs++; |
56184e01 | 366 | wr32(hw, IAVF_VFINT_ITRN1(IAVF_TX_ITR, q_vector->reg_idx), |
4eda4e00 | 367 | q_vector->tx.target_itr >> 1); |
556fdfd6 | 368 | q_vector->tx.current_itr = q_vector->tx.target_itr; |
5eae00c5 GR |
369 | } |
370 | ||
371 | /** | |
129cf89e | 372 | * iavf_map_rings_to_vectors - Maps descriptor rings to vectors |
5eae00c5 GR |
373 | * @adapter: board private structure to initialize |
374 | * | |
375 | * This function maps descriptor rings to the queue-specific vectors | |
376 | * we were allotted through the MSI-X enabling code. Ideally, we'd have | |
377 | * one vector per ring/queue, but on a constrained vector budget, we | |
378 | * group the rings as "efficiently" as possible. You would add new | |
379 | * mapping configurations in here. | |
380 | **/ | |
129cf89e | 381 | static void iavf_map_rings_to_vectors(struct iavf_adapter *adapter) |
5eae00c5 | 382 | { |
c97fc9b6 AB |
383 | int rings_remaining = adapter->num_active_queues; |
384 | int ridx = 0, vidx = 0; | |
5eae00c5 | 385 | int q_vectors; |
5eae00c5 GR |
386 | |
387 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; | |
388 | ||
c97fc9b6 | 389 | for (; ridx < rings_remaining; ridx++) { |
129cf89e JB |
390 | iavf_map_vector_to_rxq(adapter, vidx, ridx); |
391 | iavf_map_vector_to_txq(adapter, vidx, ridx); | |
5eae00c5 | 392 | |
c97fc9b6 AB |
393 | /* In the case where we have more queues than vectors, continue |
394 | * round-robin on vectors until all queues are mapped. | |
395 | */ | |
396 | if (++vidx >= q_vectors) | |
397 | vidx = 0; | |
5eae00c5 GR |
398 | } |
399 | ||
129cf89e | 400 | adapter->aq_required |= IAVF_FLAG_AQ_MAP_VECTORS; |
5eae00c5 GR |
401 | } |
402 | ||
96db776a | 403 | /** |
129cf89e | 404 | * iavf_irq_affinity_notify - Callback for affinity changes |
96db776a AB |
405 | * @notify: context as to what irq was changed |
406 | * @mask: the new affinity mask | |
407 | * | |
408 | * This is a callback function used by the irq_set_affinity_notifier function | |
409 | * so that we may register to receive changes to the irq affinity masks. | |
410 | **/ | |
129cf89e JB |
411 | static void iavf_irq_affinity_notify(struct irq_affinity_notify *notify, |
412 | const cpumask_t *mask) | |
96db776a | 413 | { |
56184e01 JB |
414 | struct iavf_q_vector *q_vector = |
415 | container_of(notify, struct iavf_q_vector, affinity_notify); | |
96db776a | 416 | |
7e4d01e7 | 417 | cpumask_copy(&q_vector->affinity_mask, mask); |
96db776a AB |
418 | } |
419 | ||
420 | /** | |
129cf89e | 421 | * iavf_irq_affinity_release - Callback for affinity notifier release |
96db776a AB |
422 | * @ref: internal core kernel usage |
423 | * | |
424 | * This is a callback function used by the irq_set_affinity_notifier function | |
425 | * to inform the current notification subscriber that they will no longer | |
426 | * receive notifications. | |
427 | **/ | |
129cf89e | 428 | static void iavf_irq_affinity_release(struct kref *ref) {} |
96db776a | 429 | |
5eae00c5 | 430 | /** |
129cf89e | 431 | * iavf_request_traffic_irqs - Initialize MSI-X interrupts |
5eae00c5 | 432 | * @adapter: board private structure |
f5254429 | 433 | * @basename: device basename |
5eae00c5 GR |
434 | * |
435 | * Allocates MSI-X vectors for tx and rx handling, and requests | |
436 | * interrupts from the kernel. | |
437 | **/ | |
438 | static int | |
129cf89e | 439 | iavf_request_traffic_irqs(struct iavf_adapter *adapter, char *basename) |
5eae00c5 | 440 | { |
696ac80a JK |
441 | unsigned int vector, q_vectors; |
442 | unsigned int rx_int_idx = 0, tx_int_idx = 0; | |
443 | int irq_num, err; | |
be664cbe | 444 | int cpu; |
5eae00c5 | 445 | |
129cf89e | 446 | iavf_irq_disable(adapter); |
5eae00c5 GR |
447 | /* Decrement for Other and TCP Timer vectors */ |
448 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; | |
449 | ||
450 | for (vector = 0; vector < q_vectors; vector++) { | |
56184e01 | 451 | struct iavf_q_vector *q_vector = &adapter->q_vectors[vector]; |
0b6591e6 | 452 | |
96db776a | 453 | irq_num = adapter->msix_entries[vector + NONQ_VECS].vector; |
5eae00c5 GR |
454 | |
455 | if (q_vector->tx.ring && q_vector->rx.ring) { | |
696ac80a | 456 | snprintf(q_vector->name, sizeof(q_vector->name), |
129cf89e | 457 | "iavf-%s-TxRx-%d", basename, rx_int_idx++); |
5eae00c5 GR |
458 | tx_int_idx++; |
459 | } else if (q_vector->rx.ring) { | |
696ac80a | 460 | snprintf(q_vector->name, sizeof(q_vector->name), |
129cf89e | 461 | "iavf-%s-rx-%d", basename, rx_int_idx++); |
5eae00c5 | 462 | } else if (q_vector->tx.ring) { |
696ac80a | 463 | snprintf(q_vector->name, sizeof(q_vector->name), |
129cf89e | 464 | "iavf-%s-tx-%d", basename, tx_int_idx++); |
5eae00c5 GR |
465 | } else { |
466 | /* skip this unused q_vector */ | |
467 | continue; | |
468 | } | |
96db776a | 469 | err = request_irq(irq_num, |
129cf89e | 470 | iavf_msix_clean_rings, |
96db776a AB |
471 | 0, |
472 | q_vector->name, | |
473 | q_vector); | |
5eae00c5 GR |
474 | if (err) { |
475 | dev_info(&adapter->pdev->dev, | |
fb43201f | 476 | "Request_irq failed, error: %d\n", err); |
5eae00c5 GR |
477 | goto free_queue_irqs; |
478 | } | |
96db776a | 479 | /* register for affinity change notifications */ |
129cf89e | 480 | q_vector->affinity_notify.notify = iavf_irq_affinity_notify; |
96db776a | 481 | q_vector->affinity_notify.release = |
129cf89e | 482 | iavf_irq_affinity_release; |
96db776a | 483 | irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify); |
be664cbe JK |
484 | /* Spread the IRQ affinity hints across online CPUs. Note that |
485 | * get_cpu_mask returns a mask with a permanent lifetime so | |
486 | * it's safe to use as a hint for irq_set_affinity_hint. | |
759dc4a7 | 487 | */ |
be664cbe JK |
488 | cpu = cpumask_local_spread(q_vector->v_idx, -1); |
489 | irq_set_affinity_hint(irq_num, get_cpu_mask(cpu)); | |
5eae00c5 GR |
490 | } |
491 | ||
492 | return 0; | |
493 | ||
494 | free_queue_irqs: | |
495 | while (vector) { | |
496 | vector--; | |
96db776a AB |
497 | irq_num = adapter->msix_entries[vector + NONQ_VECS].vector; |
498 | irq_set_affinity_notifier(irq_num, NULL); | |
499 | irq_set_affinity_hint(irq_num, NULL); | |
500 | free_irq(irq_num, &adapter->q_vectors[vector]); | |
5eae00c5 GR |
501 | } |
502 | return err; | |
503 | } | |
504 | ||
505 | /** | |
129cf89e | 506 | * iavf_request_misc_irq - Initialize MSI-X interrupts |
5eae00c5 GR |
507 | * @adapter: board private structure |
508 | * | |
509 | * Allocates MSI-X vector 0 and requests interrupts from the kernel. This | |
510 | * vector is only for the admin queue, and stays active even when the netdev | |
511 | * is closed. | |
512 | **/ | |
129cf89e | 513 | static int iavf_request_misc_irq(struct iavf_adapter *adapter) |
5eae00c5 GR |
514 | { |
515 | struct net_device *netdev = adapter->netdev; | |
516 | int err; | |
517 | ||
b39c1e2c | 518 | snprintf(adapter->misc_vector_name, |
129cf89e | 519 | sizeof(adapter->misc_vector_name) - 1, "iavf-%s:mbx", |
9a21a007 | 520 | dev_name(&adapter->pdev->dev)); |
5eae00c5 | 521 | err = request_irq(adapter->msix_entries[0].vector, |
129cf89e | 522 | &iavf_msix_aq, 0, |
e1dfee8e | 523 | adapter->misc_vector_name, netdev); |
5eae00c5 GR |
524 | if (err) { |
525 | dev_err(&adapter->pdev->dev, | |
77fa28be CS |
526 | "request_irq for %s failed: %d\n", |
527 | adapter->misc_vector_name, err); | |
5eae00c5 GR |
528 | free_irq(adapter->msix_entries[0].vector, netdev); |
529 | } | |
530 | return err; | |
531 | } | |
532 | ||
533 | /** | |
129cf89e | 534 | * iavf_free_traffic_irqs - Free MSI-X interrupts |
5eae00c5 GR |
535 | * @adapter: board private structure |
536 | * | |
537 | * Frees all MSI-X vectors other than 0. | |
538 | **/ | |
129cf89e | 539 | static void iavf_free_traffic_irqs(struct iavf_adapter *adapter) |
5eae00c5 | 540 | { |
96db776a | 541 | int vector, irq_num, q_vectors; |
75a64435 | 542 | |
47d2a5d8 AB |
543 | if (!adapter->msix_entries) |
544 | return; | |
545 | ||
5eae00c5 GR |
546 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
547 | ||
96db776a AB |
548 | for (vector = 0; vector < q_vectors; vector++) { |
549 | irq_num = adapter->msix_entries[vector + NONQ_VECS].vector; | |
550 | irq_set_affinity_notifier(irq_num, NULL); | |
551 | irq_set_affinity_hint(irq_num, NULL); | |
552 | free_irq(irq_num, &adapter->q_vectors[vector]); | |
5eae00c5 GR |
553 | } |
554 | } | |
555 | ||
556 | /** | |
129cf89e | 557 | * iavf_free_misc_irq - Free MSI-X miscellaneous vector |
5eae00c5 GR |
558 | * @adapter: board private structure |
559 | * | |
560 | * Frees MSI-X vector 0. | |
561 | **/ | |
129cf89e | 562 | static void iavf_free_misc_irq(struct iavf_adapter *adapter) |
5eae00c5 GR |
563 | { |
564 | struct net_device *netdev = adapter->netdev; | |
565 | ||
ef4603e8 JK |
566 | if (!adapter->msix_entries) |
567 | return; | |
568 | ||
5eae00c5 GR |
569 | free_irq(adapter->msix_entries[0].vector, netdev); |
570 | } | |
571 | ||
572 | /** | |
129cf89e | 573 | * iavf_configure_tx - Configure Transmit Unit after Reset |
5eae00c5 GR |
574 | * @adapter: board private structure |
575 | * | |
576 | * Configure the Tx unit of the MAC after a reset. | |
577 | **/ | |
129cf89e | 578 | static void iavf_configure_tx(struct iavf_adapter *adapter) |
5eae00c5 | 579 | { |
f349daa5 | 580 | struct iavf_hw *hw = &adapter->hw; |
5eae00c5 | 581 | int i; |
75a64435 | 582 | |
cc052927 | 583 | for (i = 0; i < adapter->num_active_queues; i++) |
f1cad2ce | 584 | adapter->tx_rings[i].tail = hw->hw_addr + IAVF_QTX_TAIL1(i); |
5eae00c5 GR |
585 | } |
586 | ||
587 | /** | |
129cf89e | 588 | * iavf_configure_rx - Configure Receive Unit after Reset |
5eae00c5 GR |
589 | * @adapter: board private structure |
590 | * | |
591 | * Configure the Rx unit of the MAC after a reset. | |
592 | **/ | |
129cf89e | 593 | static void iavf_configure_rx(struct iavf_adapter *adapter) |
5eae00c5 | 594 | { |
56184e01 | 595 | unsigned int rx_buf_len = IAVF_RXBUFFER_2048; |
f349daa5 | 596 | struct iavf_hw *hw = &adapter->hw; |
5eae00c5 | 597 | int i; |
5eae00c5 | 598 | |
dab86afd AD |
599 | /* Legacy Rx will always default to a 2048 buffer size. */ |
600 | #if (PAGE_SIZE < 8192) | |
129cf89e | 601 | if (!(adapter->flags & IAVF_FLAG_LEGACY_RX)) { |
3dfc3eb5 AB |
602 | struct net_device *netdev = adapter->netdev; |
603 | ||
98efd694 AD |
604 | /* For jumbo frames on systems with 4K pages we have to use |
605 | * an order 1 page, so we might as well increase the size | |
606 | * of our Rx buffer to make better use of the available space | |
607 | */ | |
56184e01 | 608 | rx_buf_len = IAVF_RXBUFFER_3072; |
98efd694 | 609 | |
dab86afd AD |
610 | /* We use a 1536 buffer size for configurations with |
611 | * standard Ethernet mtu. On x86 this gives us enough room | |
612 | * for shared info and 192 bytes of padding. | |
613 | */ | |
56184e01 | 614 | if (!IAVF_2K_TOO_SMALL_WITH_PADDING && |
ca9ec088 | 615 | (netdev->mtu <= ETH_DATA_LEN)) |
56184e01 | 616 | rx_buf_len = IAVF_RXBUFFER_1536 - NET_IP_ALIGN; |
dab86afd AD |
617 | } |
618 | #endif | |
619 | ||
cc052927 | 620 | for (i = 0; i < adapter->num_active_queues; i++) { |
f1cad2ce | 621 | adapter->rx_rings[i].tail = hw->hw_addr + IAVF_QRX_TAIL1(i); |
dab86afd | 622 | adapter->rx_rings[i].rx_buf_len = rx_buf_len; |
ca9ec088 | 623 | |
129cf89e | 624 | if (adapter->flags & IAVF_FLAG_LEGACY_RX) |
ca9ec088 AD |
625 | clear_ring_build_skb_enabled(&adapter->rx_rings[i]); |
626 | else | |
627 | set_ring_build_skb_enabled(&adapter->rx_rings[i]); | |
5eae00c5 GR |
628 | } |
629 | } | |
630 | ||
631 | /** | |
129cf89e | 632 | * iavf_find_vlan - Search filter list for specific vlan filter |
5eae00c5 GR |
633 | * @adapter: board private structure |
634 | * @vlan: vlan tag | |
635 | * | |
504398f0 JK |
636 | * Returns ptr to the filter object or NULL. Must be called while holding the |
637 | * mac_vlan_list_lock. | |
5eae00c5 GR |
638 | **/ |
639 | static struct | |
129cf89e | 640 | iavf_vlan_filter *iavf_find_vlan(struct iavf_adapter *adapter, u16 vlan) |
5eae00c5 | 641 | { |
129cf89e | 642 | struct iavf_vlan_filter *f; |
5eae00c5 GR |
643 | |
644 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { | |
645 | if (vlan == f->vlan) | |
646 | return f; | |
647 | } | |
648 | return NULL; | |
649 | } | |
650 | ||
651 | /** | |
129cf89e | 652 | * iavf_add_vlan - Add a vlan filter to the list |
5eae00c5 GR |
653 | * @adapter: board private structure |
654 | * @vlan: VLAN tag | |
655 | * | |
656 | * Returns ptr to the filter object or NULL when no memory available. | |
657 | **/ | |
658 | static struct | |
129cf89e | 659 | iavf_vlan_filter *iavf_add_vlan(struct iavf_adapter *adapter, u16 vlan) |
5eae00c5 | 660 | { |
129cf89e | 661 | struct iavf_vlan_filter *f = NULL; |
13acb546 | 662 | |
504398f0 | 663 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
5eae00c5 | 664 | |
129cf89e | 665 | f = iavf_find_vlan(adapter, vlan); |
348d4994 | 666 | if (!f) { |
f0a48fb4 | 667 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
348d4994 | 668 | if (!f) |
13acb546 | 669 | goto clearout; |
249c8b8d | 670 | |
5eae00c5 GR |
671 | f->vlan = vlan; |
672 | ||
c2417a7b | 673 | list_add_tail(&f->list, &adapter->vlan_filter_list); |
5eae00c5 | 674 | f->add = true; |
129cf89e | 675 | adapter->aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER; |
5eae00c5 GR |
676 | } |
677 | ||
13acb546 | 678 | clearout: |
504398f0 | 679 | spin_unlock_bh(&adapter->mac_vlan_list_lock); |
5eae00c5 GR |
680 | return f; |
681 | } | |
682 | ||
683 | /** | |
129cf89e | 684 | * iavf_del_vlan - Remove a vlan filter from the list |
5eae00c5 GR |
685 | * @adapter: board private structure |
686 | * @vlan: VLAN tag | |
687 | **/ | |
129cf89e | 688 | static void iavf_del_vlan(struct iavf_adapter *adapter, u16 vlan) |
5eae00c5 | 689 | { |
129cf89e | 690 | struct iavf_vlan_filter *f; |
13acb546 | 691 | |
504398f0 | 692 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
5eae00c5 | 693 | |
129cf89e | 694 | f = iavf_find_vlan(adapter, vlan); |
5eae00c5 GR |
695 | if (f) { |
696 | f->remove = true; | |
129cf89e | 697 | adapter->aq_required |= IAVF_FLAG_AQ_DEL_VLAN_FILTER; |
5eae00c5 | 698 | } |
504398f0 JK |
699 | |
700 | spin_unlock_bh(&adapter->mac_vlan_list_lock); | |
5eae00c5 GR |
701 | } |
702 | ||
1f36185d AA |
703 | /** |
704 | * iavf_restore_filters | |
705 | * @adapter: board private structure | |
706 | * | |
707 | * Restore existing non MAC filters when VF netdev comes back up | |
708 | **/ | |
709 | static void iavf_restore_filters(struct iavf_adapter *adapter) | |
710 | { | |
711 | /* re-add all VLAN filters */ | |
712 | if (VLAN_ALLOWED(adapter)) { | |
713 | u16 vid; | |
714 | ||
715 | for_each_set_bit(vid, adapter->vsi.active_vlans, VLAN_N_VID) | |
716 | iavf_add_vlan(adapter, vid); | |
717 | } | |
718 | } | |
719 | ||
5eae00c5 | 720 | /** |
129cf89e | 721 | * iavf_vlan_rx_add_vid - Add a VLAN filter to a device |
5eae00c5 | 722 | * @netdev: network device struct |
f5254429 | 723 | * @proto: unused protocol data |
5eae00c5 GR |
724 | * @vid: VLAN tag |
725 | **/ | |
129cf89e JB |
726 | static int iavf_vlan_rx_add_vid(struct net_device *netdev, |
727 | __always_unused __be16 proto, u16 vid) | |
5eae00c5 | 728 | { |
129cf89e | 729 | struct iavf_adapter *adapter = netdev_priv(netdev); |
5eae00c5 | 730 | |
8ed995ff MW |
731 | if (!VLAN_ALLOWED(adapter)) |
732 | return -EIO; | |
1f36185d | 733 | |
129cf89e | 734 | if (iavf_add_vlan(adapter, vid) == NULL) |
5eae00c5 | 735 | return -ENOMEM; |
1f36185d AA |
736 | |
737 | set_bit(vid, adapter->vsi.active_vlans); | |
5eae00c5 GR |
738 | return 0; |
739 | } | |
740 | ||
741 | /** | |
129cf89e | 742 | * iavf_vlan_rx_kill_vid - Remove a VLAN filter from a device |
5eae00c5 | 743 | * @netdev: network device struct |
f5254429 | 744 | * @proto: unused protocol data |
5eae00c5 GR |
745 | * @vid: VLAN tag |
746 | **/ | |
129cf89e JB |
747 | static int iavf_vlan_rx_kill_vid(struct net_device *netdev, |
748 | __always_unused __be16 proto, u16 vid) | |
5eae00c5 | 749 | { |
129cf89e | 750 | struct iavf_adapter *adapter = netdev_priv(netdev); |
5eae00c5 | 751 | |
1f36185d AA |
752 | if (!VLAN_ALLOWED(adapter)) |
753 | return -EIO; | |
754 | ||
755 | iavf_del_vlan(adapter, vid); | |
756 | clear_bit(vid, adapter->vsi.active_vlans); | |
757 | ||
758 | return 0; | |
5eae00c5 GR |
759 | } |
760 | ||
761 | /** | |
129cf89e | 762 | * iavf_find_filter - Search filter list for specific mac filter |
5eae00c5 GR |
763 | * @adapter: board private structure |
764 | * @macaddr: the MAC address | |
765 | * | |
504398f0 JK |
766 | * Returns ptr to the filter object or NULL. Must be called while holding the |
767 | * mac_vlan_list_lock. | |
5eae00c5 GR |
768 | **/ |
769 | static struct | |
129cf89e JB |
770 | iavf_mac_filter *iavf_find_filter(struct iavf_adapter *adapter, |
771 | const u8 *macaddr) | |
5eae00c5 | 772 | { |
129cf89e | 773 | struct iavf_mac_filter *f; |
5eae00c5 GR |
774 | |
775 | if (!macaddr) | |
776 | return NULL; | |
777 | ||
778 | list_for_each_entry(f, &adapter->mac_filter_list, list) { | |
779 | if (ether_addr_equal(macaddr, f->macaddr)) | |
780 | return f; | |
781 | } | |
782 | return NULL; | |
783 | } | |
784 | ||
785 | /** | |
56184e01 | 786 | * iavf_add_filter - Add a mac filter to the filter list |
5eae00c5 GR |
787 | * @adapter: board private structure |
788 | * @macaddr: the MAC address | |
789 | * | |
790 | * Returns ptr to the filter object or NULL when no memory available. | |
791 | **/ | |
9e052291 SA |
792 | struct iavf_mac_filter *iavf_add_filter(struct iavf_adapter *adapter, |
793 | const u8 *macaddr) | |
5eae00c5 | 794 | { |
129cf89e | 795 | struct iavf_mac_filter *f; |
5eae00c5 GR |
796 | |
797 | if (!macaddr) | |
798 | return NULL; | |
799 | ||
129cf89e | 800 | f = iavf_find_filter(adapter, macaddr); |
348d4994 | 801 | if (!f) { |
5eae00c5 | 802 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
504398f0 | 803 | if (!f) |
8cd5fe62 | 804 | return f; |
5eae00c5 | 805 | |
9a173901 | 806 | ether_addr_copy(f->macaddr, macaddr); |
5eae00c5 | 807 | |
63590b61 | 808 | list_add_tail(&f->list, &adapter->mac_filter_list); |
5eae00c5 | 809 | f->add = true; |
8da80c9d | 810 | f->is_new_mac = true; |
129cf89e | 811 | adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER; |
c766b9af AB |
812 | } else { |
813 | f->remove = false; | |
5eae00c5 GR |
814 | } |
815 | ||
5eae00c5 GR |
816 | return f; |
817 | } | |
818 | ||
819 | /** | |
129cf89e | 820 | * iavf_set_mac - NDO callback to set port mac address |
5eae00c5 GR |
821 | * @netdev: network interface device structure |
822 | * @p: pointer to an address structure | |
823 | * | |
824 | * Returns 0 on success, negative on failure | |
825 | **/ | |
129cf89e | 826 | static int iavf_set_mac(struct net_device *netdev, void *p) |
5eae00c5 | 827 | { |
129cf89e | 828 | struct iavf_adapter *adapter = netdev_priv(netdev); |
f349daa5 | 829 | struct iavf_hw *hw = &adapter->hw; |
129cf89e | 830 | struct iavf_mac_filter *f; |
5eae00c5 GR |
831 | struct sockaddr *addr = p; |
832 | ||
833 | if (!is_valid_ether_addr(addr->sa_data)) | |
834 | return -EADDRNOTAVAIL; | |
835 | ||
836 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) | |
837 | return 0; | |
838 | ||
504398f0 JK |
839 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
840 | ||
129cf89e | 841 | f = iavf_find_filter(adapter, hw->mac.addr); |
14e52ee2 MW |
842 | if (f) { |
843 | f->remove = true; | |
129cf89e | 844 | adapter->aq_required |= IAVF_FLAG_AQ_DEL_MAC_FILTER; |
14e52ee2 MW |
845 | } |
846 | ||
129cf89e | 847 | f = iavf_add_filter(adapter, addr->sa_data); |
8cd5fe62 | 848 | |
504398f0 JK |
849 | spin_unlock_bh(&adapter->mac_vlan_list_lock); |
850 | ||
5eae00c5 | 851 | if (f) { |
9a173901 | 852 | ether_addr_copy(hw->mac.addr, addr->sa_data); |
5eae00c5 GR |
853 | } |
854 | ||
855 | return (f == NULL) ? -ENOMEM : 0; | |
856 | } | |
857 | ||
858 | /** | |
129cf89e | 859 | * iavf_addr_sync - Callback for dev_(mc|uc)_sync to add address |
8946b563 JK |
860 | * @netdev: the netdevice |
861 | * @addr: address to add | |
862 | * | |
863 | * Called by __dev_(mc|uc)_sync when an address needs to be added. We call | |
864 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. | |
865 | */ | |
129cf89e | 866 | static int iavf_addr_sync(struct net_device *netdev, const u8 *addr) |
5eae00c5 | 867 | { |
129cf89e | 868 | struct iavf_adapter *adapter = netdev_priv(netdev); |
2f41f335 | 869 | |
129cf89e | 870 | if (iavf_add_filter(adapter, addr)) |
8946b563 JK |
871 | return 0; |
872 | else | |
873 | return -ENOMEM; | |
874 | } | |
2f41f335 | 875 | |
8946b563 | 876 | /** |
129cf89e | 877 | * iavf_addr_unsync - Callback for dev_(mc|uc)_sync to remove address |
8946b563 JK |
878 | * @netdev: the netdevice |
879 | * @addr: address to add | |
880 | * | |
881 | * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call | |
882 | * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock. | |
883 | */ | |
129cf89e | 884 | static int iavf_addr_unsync(struct net_device *netdev, const u8 *addr) |
8946b563 | 885 | { |
129cf89e JB |
886 | struct iavf_adapter *adapter = netdev_priv(netdev); |
887 | struct iavf_mac_filter *f; | |
2f41f335 | 888 | |
8946b563 JK |
889 | /* Under some circumstances, we might receive a request to delete |
890 | * our own device address from our uc list. Because we store the | |
891 | * device address in the VSI's MAC/VLAN filter list, we need to ignore | |
892 | * such requests and not delete our device address from this list. | |
893 | */ | |
894 | if (ether_addr_equal(addr, netdev->dev_addr)) | |
895 | return 0; | |
2f41f335 | 896 | |
129cf89e | 897 | f = iavf_find_filter(adapter, addr); |
8946b563 | 898 | if (f) { |
2f41f335 | 899 | f->remove = true; |
129cf89e | 900 | adapter->aq_required |= IAVF_FLAG_AQ_DEL_MAC_FILTER; |
5eae00c5 | 901 | } |
8946b563 JK |
902 | return 0; |
903 | } | |
904 | ||
905 | /** | |
129cf89e | 906 | * iavf_set_rx_mode - NDO callback to set the netdev filters |
8946b563 JK |
907 | * @netdev: network interface device structure |
908 | **/ | |
129cf89e | 909 | static void iavf_set_rx_mode(struct net_device *netdev) |
8946b563 | 910 | { |
129cf89e | 911 | struct iavf_adapter *adapter = netdev_priv(netdev); |
8946b563 JK |
912 | |
913 | spin_lock_bh(&adapter->mac_vlan_list_lock); | |
129cf89e JB |
914 | __dev_uc_sync(netdev, iavf_addr_sync, iavf_addr_unsync); |
915 | __dev_mc_sync(netdev, iavf_addr_sync, iavf_addr_unsync); | |
8946b563 | 916 | spin_unlock_bh(&adapter->mac_vlan_list_lock); |
47d34839 ASJ |
917 | |
918 | if (netdev->flags & IFF_PROMISC && | |
129cf89e JB |
919 | !(adapter->flags & IAVF_FLAG_PROMISC_ON)) |
920 | adapter->aq_required |= IAVF_FLAG_AQ_REQUEST_PROMISC; | |
47d34839 | 921 | else if (!(netdev->flags & IFF_PROMISC) && |
129cf89e JB |
922 | adapter->flags & IAVF_FLAG_PROMISC_ON) |
923 | adapter->aq_required |= IAVF_FLAG_AQ_RELEASE_PROMISC; | |
47d34839 | 924 | |
f42a5c74 | 925 | if (netdev->flags & IFF_ALLMULTI && |
129cf89e JB |
926 | !(adapter->flags & IAVF_FLAG_ALLMULTI_ON)) |
927 | adapter->aq_required |= IAVF_FLAG_AQ_REQUEST_ALLMULTI; | |
f42a5c74 | 928 | else if (!(netdev->flags & IFF_ALLMULTI) && |
129cf89e JB |
929 | adapter->flags & IAVF_FLAG_ALLMULTI_ON) |
930 | adapter->aq_required |= IAVF_FLAG_AQ_RELEASE_ALLMULTI; | |
5eae00c5 GR |
931 | } |
932 | ||
933 | /** | |
129cf89e | 934 | * iavf_napi_enable_all - enable NAPI on all queue vectors |
5eae00c5 GR |
935 | * @adapter: board private structure |
936 | **/ | |
129cf89e | 937 | static void iavf_napi_enable_all(struct iavf_adapter *adapter) |
5eae00c5 GR |
938 | { |
939 | int q_idx; | |
56184e01 | 940 | struct iavf_q_vector *q_vector; |
5eae00c5 GR |
941 | int q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
942 | ||
943 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { | |
944 | struct napi_struct *napi; | |
75a64435 | 945 | |
7d96ba1a | 946 | q_vector = &adapter->q_vectors[q_idx]; |
5eae00c5 GR |
947 | napi = &q_vector->napi; |
948 | napi_enable(napi); | |
949 | } | |
950 | } | |
951 | ||
952 | /** | |
129cf89e | 953 | * iavf_napi_disable_all - disable NAPI on all queue vectors |
5eae00c5 GR |
954 | * @adapter: board private structure |
955 | **/ | |
129cf89e | 956 | static void iavf_napi_disable_all(struct iavf_adapter *adapter) |
5eae00c5 GR |
957 | { |
958 | int q_idx; | |
56184e01 | 959 | struct iavf_q_vector *q_vector; |
5eae00c5 GR |
960 | int q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
961 | ||
962 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { | |
7d96ba1a | 963 | q_vector = &adapter->q_vectors[q_idx]; |
5eae00c5 GR |
964 | napi_disable(&q_vector->napi); |
965 | } | |
966 | } | |
967 | ||
968 | /** | |
129cf89e | 969 | * iavf_configure - set up transmit and receive data structures |
5eae00c5 GR |
970 | * @adapter: board private structure |
971 | **/ | |
129cf89e | 972 | static void iavf_configure(struct iavf_adapter *adapter) |
5eae00c5 GR |
973 | { |
974 | struct net_device *netdev = adapter->netdev; | |
975 | int i; | |
976 | ||
129cf89e | 977 | iavf_set_rx_mode(netdev); |
5eae00c5 | 978 | |
129cf89e JB |
979 | iavf_configure_tx(adapter); |
980 | iavf_configure_rx(adapter); | |
981 | adapter->aq_required |= IAVF_FLAG_AQ_CONFIGURE_QUEUES; | |
5eae00c5 | 982 | |
cc052927 | 983 | for (i = 0; i < adapter->num_active_queues; i++) { |
56184e01 | 984 | struct iavf_ring *ring = &adapter->rx_rings[i]; |
75a64435 | 985 | |
56184e01 | 986 | iavf_alloc_rx_buffers(ring, IAVF_DESC_UNUSED(ring)); |
5eae00c5 GR |
987 | } |
988 | } | |
989 | ||
990 | /** | |
129cf89e | 991 | * iavf_up_complete - Finish the last steps of bringing up a connection |
5eae00c5 | 992 | * @adapter: board private structure |
9b2aef12 | 993 | * |
129cf89e | 994 | * Expects to be called while holding the __IAVF_IN_CRITICAL_TASK bit lock. |
5eae00c5 | 995 | **/ |
129cf89e | 996 | static void iavf_up_complete(struct iavf_adapter *adapter) |
5eae00c5 | 997 | { |
129cf89e | 998 | adapter->state = __IAVF_RUNNING; |
56184e01 | 999 | clear_bit(__IAVF_VSI_DOWN, adapter->vsi.state); |
5eae00c5 | 1000 | |
129cf89e | 1001 | iavf_napi_enable_all(adapter); |
5eae00c5 | 1002 | |
129cf89e | 1003 | adapter->aq_required |= IAVF_FLAG_AQ_ENABLE_QUEUES; |
ed0e894d | 1004 | if (CLIENT_ENABLED(adapter)) |
129cf89e | 1005 | adapter->flags |= IAVF_FLAG_CLIENT_NEEDS_OPEN; |
fdd4044f | 1006 | mod_delayed_work(iavf_wq, &adapter->watchdog_task, 0); |
5eae00c5 GR |
1007 | } |
1008 | ||
5eae00c5 | 1009 | /** |
56184e01 | 1010 | * iavf_down - Shutdown the connection processing |
5eae00c5 | 1011 | * @adapter: board private structure |
9b2aef12 | 1012 | * |
129cf89e | 1013 | * Expects to be called while holding the __IAVF_IN_CRITICAL_TASK bit lock. |
5eae00c5 | 1014 | **/ |
129cf89e | 1015 | void iavf_down(struct iavf_adapter *adapter) |
5eae00c5 GR |
1016 | { |
1017 | struct net_device *netdev = adapter->netdev; | |
129cf89e | 1018 | struct iavf_vlan_filter *vlf; |
129cf89e | 1019 | struct iavf_cloud_filter *cf; |
0dbfbabb HW |
1020 | struct iavf_fdir_fltr *fdir; |
1021 | struct iavf_mac_filter *f; | |
0aaeb4fb | 1022 | struct iavf_adv_rss *rss; |
5eae00c5 | 1023 | |
129cf89e | 1024 | if (adapter->state <= __IAVF_DOWN_PENDING) |
ddf0b3a6 MW |
1025 | return; |
1026 | ||
63e18c25 MW |
1027 | netif_carrier_off(netdev); |
1028 | netif_tx_disable(netdev); | |
3f341acc | 1029 | adapter->link_up = false; |
129cf89e JB |
1030 | iavf_napi_disable_all(adapter); |
1031 | iavf_irq_disable(adapter); | |
53d0b3ae | 1032 | |
504398f0 JK |
1033 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
1034 | ||
8946b563 JK |
1035 | /* clear the sync flag on all filters */ |
1036 | __dev_uc_unsync(adapter->netdev, NULL); | |
1037 | __dev_mc_unsync(adapter->netdev, NULL); | |
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 | } | |
8946b563 | 1043 | |
ed1f5b58 | 1044 | /* remove all VLAN filters */ |
fbd5eb54 | 1045 | list_for_each_entry(vlf, &adapter->vlan_filter_list, list) { |
0075fa0f | 1046 | vlf->remove = true; |
ed1f5b58 | 1047 | } |
504398f0 JK |
1048 | |
1049 | spin_unlock_bh(&adapter->mac_vlan_list_lock); | |
1050 | ||
0075fa0f HR |
1051 | /* remove all cloud filters */ |
1052 | spin_lock_bh(&adapter->cloud_filter_list_lock); | |
1053 | list_for_each_entry(cf, &adapter->cloud_filter_list, list) { | |
1054 | cf->del = true; | |
1055 | } | |
1056 | spin_unlock_bh(&adapter->cloud_filter_list_lock); | |
1057 | ||
0dbfbabb HW |
1058 | /* remove all Flow Director filters */ |
1059 | spin_lock_bh(&adapter->fdir_fltr_lock); | |
1060 | list_for_each_entry(fdir, &adapter->fdir_list_head, list) { | |
1061 | fdir->state = IAVF_FDIR_FLTR_DEL_REQUEST; | |
1062 | } | |
1063 | spin_unlock_bh(&adapter->fdir_fltr_lock); | |
1064 | ||
0aaeb4fb HW |
1065 | /* remove all advance RSS configuration */ |
1066 | spin_lock_bh(&adapter->adv_rss_lock); | |
1067 | list_for_each_entry(rss, &adapter->adv_rss_list_head, list) | |
1068 | rss->state = IAVF_ADV_RSS_DEL_REQUEST; | |
1069 | spin_unlock_bh(&adapter->adv_rss_lock); | |
1070 | ||
129cf89e JB |
1071 | if (!(adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) && |
1072 | adapter->state != __IAVF_RESETTING) { | |
53d0b3ae | 1073 | /* cancel any current operation */ |
310a2ad9 | 1074 | adapter->current_op = VIRTCHNL_OP_UNKNOWN; |
53d0b3ae MW |
1075 | /* Schedule operations to close down the HW. Don't wait |
1076 | * here for this to complete. The watchdog is still running | |
1077 | * and it will take care of this. | |
1078 | */ | |
129cf89e JB |
1079 | adapter->aq_required = IAVF_FLAG_AQ_DEL_MAC_FILTER; |
1080 | adapter->aq_required |= IAVF_FLAG_AQ_DEL_VLAN_FILTER; | |
1081 | adapter->aq_required |= IAVF_FLAG_AQ_DEL_CLOUD_FILTER; | |
0dbfbabb | 1082 | adapter->aq_required |= IAVF_FLAG_AQ_DEL_FDIR_FILTER; |
0aaeb4fb | 1083 | adapter->aq_required |= IAVF_FLAG_AQ_DEL_ADV_RSS_CFG; |
129cf89e | 1084 | adapter->aq_required |= IAVF_FLAG_AQ_DISABLE_QUEUES; |
ef8693eb | 1085 | } |
5eae00c5 | 1086 | |
fdd4044f | 1087 | mod_delayed_work(iavf_wq, &adapter->watchdog_task, 0); |
5eae00c5 GR |
1088 | } |
1089 | ||
1090 | /** | |
129cf89e | 1091 | * iavf_acquire_msix_vectors - Setup the MSIX capability |
5eae00c5 GR |
1092 | * @adapter: board private structure |
1093 | * @vectors: number of vectors to request | |
1094 | * | |
1095 | * Work with the OS to set up the MSIX vectors needed. | |
1096 | * | |
1097 | * Returns 0 on success, negative on failure | |
1098 | **/ | |
1099 | static int | |
129cf89e | 1100 | iavf_acquire_msix_vectors(struct iavf_adapter *adapter, int vectors) |
5eae00c5 GR |
1101 | { |
1102 | int err, vector_threshold; | |
1103 | ||
1104 | /* We'll want at least 3 (vector_threshold): | |
1105 | * 0) Other (Admin Queue and link, mostly) | |
1106 | * 1) TxQ[0] Cleanup | |
1107 | * 2) RxQ[0] Cleanup | |
1108 | */ | |
1109 | vector_threshold = MIN_MSIX_COUNT; | |
1110 | ||
1111 | /* The more we get, the more we will assign to Tx/Rx Cleanup | |
1112 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. | |
1113 | * Right now, we simply care about how many we'll get; we'll | |
1114 | * set them up later while requesting irq's. | |
1115 | */ | |
fc2f2f5d AG |
1116 | err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries, |
1117 | vector_threshold, vectors); | |
1118 | if (err < 0) { | |
80e72893 | 1119 | dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n"); |
5eae00c5 GR |
1120 | kfree(adapter->msix_entries); |
1121 | adapter->msix_entries = NULL; | |
fc2f2f5d | 1122 | return err; |
5eae00c5 | 1123 | } |
fc2f2f5d AG |
1124 | |
1125 | /* Adjust for only the vectors we'll use, which is minimum | |
1126 | * of max_msix_q_vectors + NONQ_VECS, or the number of | |
1127 | * vectors we were allocated. | |
1128 | */ | |
1129 | adapter->num_msix_vectors = err; | |
1130 | return 0; | |
5eae00c5 GR |
1131 | } |
1132 | ||
1133 | /** | |
129cf89e | 1134 | * iavf_free_queues - Free memory for all rings |
5eae00c5 GR |
1135 | * @adapter: board private structure to initialize |
1136 | * | |
1137 | * Free all of the memory associated with queue pairs. | |
1138 | **/ | |
129cf89e | 1139 | static void iavf_free_queues(struct iavf_adapter *adapter) |
5eae00c5 | 1140 | { |
5eae00c5 GR |
1141 | if (!adapter->vsi_res) |
1142 | return; | |
65c7006f | 1143 | adapter->num_active_queues = 0; |
0dd438d8 | 1144 | kfree(adapter->tx_rings); |
10311540 | 1145 | adapter->tx_rings = NULL; |
0dd438d8 | 1146 | kfree(adapter->rx_rings); |
10311540 | 1147 | adapter->rx_rings = NULL; |
5eae00c5 GR |
1148 | } |
1149 | ||
1150 | /** | |
129cf89e | 1151 | * iavf_alloc_queues - Allocate memory for all rings |
5eae00c5 GR |
1152 | * @adapter: board private structure to initialize |
1153 | * | |
1154 | * We allocate one ring per queue at run-time since we don't know the | |
1155 | * number of queues at compile-time. The polling_netdev array is | |
1156 | * intended for Multiqueue, but should work fine with a single queue. | |
1157 | **/ | |
129cf89e | 1158 | static int iavf_alloc_queues(struct iavf_adapter *adapter) |
5eae00c5 | 1159 | { |
65c7006f JK |
1160 | int i, num_active_queues; |
1161 | ||
5b36e8d0 AB |
1162 | /* If we're in reset reallocating queues we don't actually know yet for |
1163 | * certain the PF gave us the number of queues we asked for but we'll | |
1164 | * assume it did. Once basic reset is finished we'll confirm once we | |
1165 | * start negotiating config with PF. | |
1166 | */ | |
1167 | if (adapter->num_req_queues) | |
1168 | num_active_queues = adapter->num_req_queues; | |
5e97ce63 AD |
1169 | else if ((adapter->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADQ) && |
1170 | adapter->num_tc) | |
1171 | num_active_queues = adapter->ch_config.total_qps; | |
5b36e8d0 AB |
1172 | else |
1173 | num_active_queues = min_t(int, | |
1174 | adapter->vsi_res->num_queue_pairs, | |
1175 | (int)(num_online_cpus())); | |
1176 | ||
5eae00c5 | 1177 | |
65c7006f | 1178 | adapter->tx_rings = kcalloc(num_active_queues, |
56184e01 | 1179 | sizeof(struct iavf_ring), GFP_KERNEL); |
0dd438d8 MW |
1180 | if (!adapter->tx_rings) |
1181 | goto err_out; | |
65c7006f | 1182 | adapter->rx_rings = kcalloc(num_active_queues, |
56184e01 | 1183 | sizeof(struct iavf_ring), GFP_KERNEL); |
0dd438d8 MW |
1184 | if (!adapter->rx_rings) |
1185 | goto err_out; | |
1186 | ||
65c7006f | 1187 | for (i = 0; i < num_active_queues; i++) { |
56184e01 JB |
1188 | struct iavf_ring *tx_ring; |
1189 | struct iavf_ring *rx_ring; | |
5eae00c5 | 1190 | |
0dd438d8 | 1191 | tx_ring = &adapter->tx_rings[i]; |
5eae00c5 GR |
1192 | |
1193 | tx_ring->queue_index = i; | |
1194 | tx_ring->netdev = adapter->netdev; | |
1195 | tx_ring->dev = &adapter->pdev->dev; | |
d732a184 | 1196 | tx_ring->count = adapter->tx_desc_count; |
56184e01 | 1197 | tx_ring->itr_setting = IAVF_ITR_TX_DEF; |
129cf89e | 1198 | if (adapter->flags & IAVF_FLAG_WB_ON_ITR_CAPABLE) |
56184e01 | 1199 | tx_ring->flags |= IAVF_TXR_FLAGS_WB_ON_ITR; |
5eae00c5 | 1200 | |
0dd438d8 | 1201 | rx_ring = &adapter->rx_rings[i]; |
5eae00c5 GR |
1202 | rx_ring->queue_index = i; |
1203 | rx_ring->netdev = adapter->netdev; | |
1204 | rx_ring->dev = &adapter->pdev->dev; | |
d732a184 | 1205 | rx_ring->count = adapter->rx_desc_count; |
56184e01 | 1206 | rx_ring->itr_setting = IAVF_ITR_RX_DEF; |
5eae00c5 GR |
1207 | } |
1208 | ||
65c7006f JK |
1209 | adapter->num_active_queues = num_active_queues; |
1210 | ||
5eae00c5 GR |
1211 | return 0; |
1212 | ||
1213 | err_out: | |
129cf89e | 1214 | iavf_free_queues(adapter); |
5eae00c5 GR |
1215 | return -ENOMEM; |
1216 | } | |
1217 | ||
1218 | /** | |
129cf89e | 1219 | * iavf_set_interrupt_capability - set MSI-X or FAIL if not supported |
5eae00c5 GR |
1220 | * @adapter: board private structure to initialize |
1221 | * | |
1222 | * Attempt to configure the interrupts using the best available | |
1223 | * capabilities of the hardware and the kernel. | |
1224 | **/ | |
129cf89e | 1225 | static int iavf_set_interrupt_capability(struct iavf_adapter *adapter) |
5eae00c5 GR |
1226 | { |
1227 | int vector, v_budget; | |
1228 | int pairs = 0; | |
1229 | int err = 0; | |
1230 | ||
1231 | if (!adapter->vsi_res) { | |
1232 | err = -EIO; | |
1233 | goto out; | |
1234 | } | |
cc052927 | 1235 | pairs = adapter->num_active_queues; |
5eae00c5 | 1236 | |
789f38ca JK |
1237 | /* It's easy to be greedy for MSI-X vectors, but it really doesn't do |
1238 | * us much good if we have more vectors than CPUs. However, we already | |
1239 | * limit the total number of queues by the number of CPUs so we do not | |
1240 | * need any further limiting here. | |
5eae00c5 | 1241 | */ |
789f38ca JK |
1242 | v_budget = min_t(int, pairs + NONQ_VECS, |
1243 | (int)adapter->vf_res->max_vectors); | |
5eae00c5 | 1244 | |
5eae00c5 GR |
1245 | adapter->msix_entries = kcalloc(v_budget, |
1246 | sizeof(struct msix_entry), GFP_KERNEL); | |
1247 | if (!adapter->msix_entries) { | |
1248 | err = -ENOMEM; | |
1249 | goto out; | |
1250 | } | |
1251 | ||
1252 | for (vector = 0; vector < v_budget; vector++) | |
1253 | adapter->msix_entries[vector].entry = vector; | |
1254 | ||
129cf89e | 1255 | err = iavf_acquire_msix_vectors(adapter, v_budget); |
5eae00c5 GR |
1256 | |
1257 | out: | |
e6c4cf6f MW |
1258 | netif_set_real_num_rx_queues(adapter->netdev, pairs); |
1259 | netif_set_real_num_tx_queues(adapter->netdev, pairs); | |
5eae00c5 GR |
1260 | return err; |
1261 | } | |
1262 | ||
e25d00b8 | 1263 | /** |
56184e01 | 1264 | * iavf_config_rss_aq - Configure RSS keys and lut by using AQ commands |
43a3d9ba | 1265 | * @adapter: board private structure |
2c86ac3c HZ |
1266 | * |
1267 | * Return 0 on success, negative on failure | |
e25d00b8 | 1268 | **/ |
129cf89e | 1269 | static int iavf_config_rss_aq(struct iavf_adapter *adapter) |
e25d00b8 | 1270 | { |
7af36e32 AM |
1271 | struct iavf_aqc_get_set_rss_key_data *rss_key = |
1272 | (struct iavf_aqc_get_set_rss_key_data *)adapter->rss_key; | |
f349daa5 | 1273 | struct iavf_hw *hw = &adapter->hw; |
2c86ac3c | 1274 | int ret = 0; |
e25d00b8 | 1275 | |
310a2ad9 | 1276 | if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) { |
e25d00b8 | 1277 | /* bail because we already have a command pending */ |
e3d132d1 | 1278 | dev_err(&adapter->pdev->dev, "Cannot configure RSS, command %d pending\n", |
e25d00b8 | 1279 | adapter->current_op); |
2c86ac3c | 1280 | return -EBUSY; |
e25d00b8 ASJ |
1281 | } |
1282 | ||
129cf89e | 1283 | ret = iavf_aq_set_rss_key(hw, adapter->vsi.id, rss_key); |
43a3d9ba MW |
1284 | if (ret) { |
1285 | dev_err(&adapter->pdev->dev, "Cannot set RSS key, err %s aq_err %s\n", | |
129cf89e JB |
1286 | iavf_stat_str(hw, ret), |
1287 | iavf_aq_str(hw, hw->aq.asq_last_status)); | |
43a3d9ba MW |
1288 | return ret; |
1289 | ||
2c86ac3c | 1290 | } |
e25d00b8 | 1291 | |
129cf89e JB |
1292 | ret = iavf_aq_set_rss_lut(hw, adapter->vsi.id, false, |
1293 | adapter->rss_lut, adapter->rss_lut_size); | |
43a3d9ba MW |
1294 | if (ret) { |
1295 | dev_err(&adapter->pdev->dev, "Cannot set RSS lut, err %s aq_err %s\n", | |
129cf89e JB |
1296 | iavf_stat_str(hw, ret), |
1297 | iavf_aq_str(hw, hw->aq.asq_last_status)); | |
e25d00b8 ASJ |
1298 | } |
1299 | ||
2c86ac3c | 1300 | return ret; |
43a3d9ba | 1301 | |
e25d00b8 ASJ |
1302 | } |
1303 | ||
1304 | /** | |
129cf89e | 1305 | * iavf_config_rss_reg - Configure RSS keys and lut by writing registers |
43a3d9ba | 1306 | * @adapter: board private structure |
2c86ac3c HZ |
1307 | * |
1308 | * Returns 0 on success, negative on failure | |
e25d00b8 | 1309 | **/ |
129cf89e | 1310 | static int iavf_config_rss_reg(struct iavf_adapter *adapter) |
e25d00b8 | 1311 | { |
f349daa5 | 1312 | struct iavf_hw *hw = &adapter->hw; |
43a3d9ba | 1313 | u32 *dw; |
2c86ac3c | 1314 | u16 i; |
e25d00b8 | 1315 | |
43a3d9ba MW |
1316 | dw = (u32 *)adapter->rss_key; |
1317 | for (i = 0; i <= adapter->rss_key_size / 4; i++) | |
f1cad2ce | 1318 | wr32(hw, IAVF_VFQF_HKEY(i), dw[i]); |
2c86ac3c | 1319 | |
43a3d9ba MW |
1320 | dw = (u32 *)adapter->rss_lut; |
1321 | for (i = 0; i <= adapter->rss_lut_size / 4; i++) | |
f1cad2ce | 1322 | wr32(hw, IAVF_VFQF_HLUT(i), dw[i]); |
2c86ac3c | 1323 | |
f1cad2ce | 1324 | iavf_flush(hw); |
2c86ac3c HZ |
1325 | |
1326 | return 0; | |
1327 | } | |
1328 | ||
1329 | /** | |
129cf89e | 1330 | * iavf_config_rss - Configure RSS keys and lut |
43a3d9ba | 1331 | * @adapter: board private structure |
90b02b43 HZ |
1332 | * |
1333 | * Returns 0 on success, negative on failure | |
1334 | **/ | |
129cf89e | 1335 | int iavf_config_rss(struct iavf_adapter *adapter) |
90b02b43 | 1336 | { |
90b02b43 | 1337 | |
43a3d9ba | 1338 | if (RSS_PF(adapter)) { |
129cf89e JB |
1339 | adapter->aq_required |= IAVF_FLAG_AQ_SET_RSS_LUT | |
1340 | IAVF_FLAG_AQ_SET_RSS_KEY; | |
43a3d9ba MW |
1341 | return 0; |
1342 | } else if (RSS_AQ(adapter)) { | |
129cf89e | 1343 | return iavf_config_rss_aq(adapter); |
43a3d9ba | 1344 | } else { |
129cf89e | 1345 | return iavf_config_rss_reg(adapter); |
43a3d9ba | 1346 | } |
90b02b43 HZ |
1347 | } |
1348 | ||
2c86ac3c | 1349 | /** |
129cf89e | 1350 | * iavf_fill_rss_lut - Fill the lut with default values |
43a3d9ba | 1351 | * @adapter: board private structure |
2c86ac3c | 1352 | **/ |
129cf89e | 1353 | static void iavf_fill_rss_lut(struct iavf_adapter *adapter) |
2c86ac3c HZ |
1354 | { |
1355 | u16 i; | |
1356 | ||
43a3d9ba MW |
1357 | for (i = 0; i < adapter->rss_lut_size; i++) |
1358 | adapter->rss_lut[i] = i % adapter->num_active_queues; | |
e25d00b8 ASJ |
1359 | } |
1360 | ||
1361 | /** | |
129cf89e | 1362 | * iavf_init_rss - Prepare for RSS |
e25d00b8 | 1363 | * @adapter: board private structure |
2c86ac3c HZ |
1364 | * |
1365 | * Return 0 on success, negative on failure | |
e25d00b8 | 1366 | **/ |
129cf89e | 1367 | static int iavf_init_rss(struct iavf_adapter *adapter) |
e25d00b8 | 1368 | { |
f349daa5 | 1369 | struct iavf_hw *hw = &adapter->hw; |
2c86ac3c | 1370 | int ret; |
e25d00b8 | 1371 | |
43a3d9ba MW |
1372 | if (!RSS_PF(adapter)) { |
1373 | /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */ | |
fbb113f7 | 1374 | if (adapter->vf_res->vf_cap_flags & |
310a2ad9 | 1375 | VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2) |
56184e01 | 1376 | adapter->hena = IAVF_DEFAULT_RSS_HENA_EXPANDED; |
43a3d9ba | 1377 | else |
56184e01 | 1378 | adapter->hena = IAVF_DEFAULT_RSS_HENA; |
e25d00b8 | 1379 | |
f1cad2ce JB |
1380 | wr32(hw, IAVF_VFQF_HENA(0), (u32)adapter->hena); |
1381 | wr32(hw, IAVF_VFQF_HENA(1), (u32)(adapter->hena >> 32)); | |
43a3d9ba | 1382 | } |
66f9af85 | 1383 | |
129cf89e | 1384 | iavf_fill_rss_lut(adapter); |
43a3d9ba | 1385 | netdev_rss_key_fill((void *)adapter->rss_key, adapter->rss_key_size); |
129cf89e | 1386 | ret = iavf_config_rss(adapter); |
2c86ac3c HZ |
1387 | |
1388 | return ret; | |
e25d00b8 ASJ |
1389 | } |
1390 | ||
5eae00c5 | 1391 | /** |
129cf89e | 1392 | * iavf_alloc_q_vectors - Allocate memory for interrupt vectors |
5eae00c5 GR |
1393 | * @adapter: board private structure to initialize |
1394 | * | |
1395 | * We allocate one q_vector per queue interrupt. If allocation fails we | |
1396 | * return -ENOMEM. | |
1397 | **/ | |
129cf89e | 1398 | static int iavf_alloc_q_vectors(struct iavf_adapter *adapter) |
5eae00c5 | 1399 | { |
7d96ba1a | 1400 | int q_idx = 0, num_q_vectors; |
56184e01 | 1401 | struct iavf_q_vector *q_vector; |
5eae00c5 GR |
1402 | |
1403 | num_q_vectors = adapter->num_msix_vectors - NONQ_VECS; | |
0dd438d8 | 1404 | adapter->q_vectors = kcalloc(num_q_vectors, sizeof(*q_vector), |
7d96ba1a MW |
1405 | GFP_KERNEL); |
1406 | if (!adapter->q_vectors) | |
311f23e9 | 1407 | return -ENOMEM; |
5eae00c5 GR |
1408 | |
1409 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { | |
7d96ba1a | 1410 | q_vector = &adapter->q_vectors[q_idx]; |
5eae00c5 GR |
1411 | q_vector->adapter = adapter; |
1412 | q_vector->vsi = &adapter->vsi; | |
1413 | q_vector->v_idx = q_idx; | |
a3f9fb5e | 1414 | q_vector->reg_idx = q_idx; |
759dc4a7 | 1415 | cpumask_copy(&q_vector->affinity_mask, cpu_possible_mask); |
5eae00c5 | 1416 | netif_napi_add(adapter->netdev, &q_vector->napi, |
129cf89e | 1417 | iavf_napi_poll, NAPI_POLL_WEIGHT); |
5eae00c5 GR |
1418 | } |
1419 | ||
1420 | return 0; | |
5eae00c5 GR |
1421 | } |
1422 | ||
1423 | /** | |
129cf89e | 1424 | * iavf_free_q_vectors - Free memory allocated for interrupt vectors |
5eae00c5 GR |
1425 | * @adapter: board private structure to initialize |
1426 | * | |
1427 | * This function frees the memory allocated to the q_vectors. In addition if | |
1428 | * NAPI is enabled it will delete any references to the NAPI struct prior | |
1429 | * to freeing the q_vector. | |
1430 | **/ | |
129cf89e | 1431 | static void iavf_free_q_vectors(struct iavf_adapter *adapter) |
5eae00c5 GR |
1432 | { |
1433 | int q_idx, num_q_vectors; | |
1434 | int napi_vectors; | |
1435 | ||
ef4603e8 JK |
1436 | if (!adapter->q_vectors) |
1437 | return; | |
1438 | ||
5eae00c5 | 1439 | num_q_vectors = adapter->num_msix_vectors - NONQ_VECS; |
cc052927 | 1440 | napi_vectors = adapter->num_active_queues; |
5eae00c5 GR |
1441 | |
1442 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { | |
56184e01 | 1443 | struct iavf_q_vector *q_vector = &adapter->q_vectors[q_idx]; |
0b6591e6 | 1444 | |
5eae00c5 GR |
1445 | if (q_idx < napi_vectors) |
1446 | netif_napi_del(&q_vector->napi); | |
5eae00c5 | 1447 | } |
7d96ba1a | 1448 | kfree(adapter->q_vectors); |
ef4603e8 | 1449 | adapter->q_vectors = NULL; |
5eae00c5 GR |
1450 | } |
1451 | ||
1452 | /** | |
129cf89e | 1453 | * iavf_reset_interrupt_capability - Reset MSIX setup |
5eae00c5 GR |
1454 | * @adapter: board private structure |
1455 | * | |
1456 | **/ | |
129cf89e | 1457 | void iavf_reset_interrupt_capability(struct iavf_adapter *adapter) |
5eae00c5 | 1458 | { |
47d2a5d8 AB |
1459 | if (!adapter->msix_entries) |
1460 | return; | |
1461 | ||
5eae00c5 GR |
1462 | pci_disable_msix(adapter->pdev); |
1463 | kfree(adapter->msix_entries); | |
1464 | adapter->msix_entries = NULL; | |
5eae00c5 GR |
1465 | } |
1466 | ||
1467 | /** | |
129cf89e | 1468 | * iavf_init_interrupt_scheme - Determine if MSIX is supported and init |
5eae00c5 GR |
1469 | * @adapter: board private structure to initialize |
1470 | * | |
1471 | **/ | |
129cf89e | 1472 | int iavf_init_interrupt_scheme(struct iavf_adapter *adapter) |
5eae00c5 GR |
1473 | { |
1474 | int err; | |
1475 | ||
129cf89e | 1476 | err = iavf_alloc_queues(adapter); |
283aeafe JK |
1477 | if (err) { |
1478 | dev_err(&adapter->pdev->dev, | |
1479 | "Unable to allocate memory for queues\n"); | |
1480 | goto err_alloc_queues; | |
1481 | } | |
1482 | ||
62fe2a86 | 1483 | rtnl_lock(); |
129cf89e | 1484 | err = iavf_set_interrupt_capability(adapter); |
62fe2a86 | 1485 | rtnl_unlock(); |
5eae00c5 GR |
1486 | if (err) { |
1487 | dev_err(&adapter->pdev->dev, | |
1488 | "Unable to setup interrupt capabilities\n"); | |
1489 | goto err_set_interrupt; | |
1490 | } | |
1491 | ||
129cf89e | 1492 | err = iavf_alloc_q_vectors(adapter); |
5eae00c5 GR |
1493 | if (err) { |
1494 | dev_err(&adapter->pdev->dev, | |
1495 | "Unable to allocate memory for queue vectors\n"); | |
1496 | goto err_alloc_q_vectors; | |
1497 | } | |
1498 | ||
5e97ce63 AD |
1499 | /* If we've made it so far while ADq flag being ON, then we haven't |
1500 | * bailed out anywhere in middle. And ADq isn't just enabled but actual | |
1501 | * resources have been allocated in the reset path. | |
1502 | * Now we can truly claim that ADq is enabled. | |
1503 | */ | |
1504 | if ((adapter->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADQ) && | |
1505 | adapter->num_tc) | |
1506 | dev_info(&adapter->pdev->dev, "ADq Enabled, %u TCs created", | |
1507 | adapter->num_tc); | |
1508 | ||
5eae00c5 | 1509 | dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u", |
75a64435 MW |
1510 | (adapter->num_active_queues > 1) ? "Enabled" : "Disabled", |
1511 | adapter->num_active_queues); | |
5eae00c5 GR |
1512 | |
1513 | return 0; | |
5eae00c5 | 1514 | err_alloc_q_vectors: |
129cf89e | 1515 | iavf_reset_interrupt_capability(adapter); |
5eae00c5 | 1516 | err_set_interrupt: |
129cf89e | 1517 | iavf_free_queues(adapter); |
283aeafe | 1518 | err_alloc_queues: |
5eae00c5 GR |
1519 | return err; |
1520 | } | |
1521 | ||
66f9af85 | 1522 | /** |
129cf89e | 1523 | * iavf_free_rss - Free memory used by RSS structs |
43a3d9ba | 1524 | * @adapter: board private structure |
66f9af85 | 1525 | **/ |
129cf89e | 1526 | static void iavf_free_rss(struct iavf_adapter *adapter) |
66f9af85 | 1527 | { |
43a3d9ba MW |
1528 | kfree(adapter->rss_key); |
1529 | adapter->rss_key = NULL; | |
66f9af85 | 1530 | |
43a3d9ba MW |
1531 | kfree(adapter->rss_lut); |
1532 | adapter->rss_lut = NULL; | |
66f9af85 HZ |
1533 | } |
1534 | ||
5b36e8d0 | 1535 | /** |
129cf89e | 1536 | * iavf_reinit_interrupt_scheme - Reallocate queues and vectors |
5b36e8d0 AB |
1537 | * @adapter: board private structure |
1538 | * | |
1539 | * Returns 0 on success, negative on failure | |
1540 | **/ | |
129cf89e | 1541 | static int iavf_reinit_interrupt_scheme(struct iavf_adapter *adapter) |
5b36e8d0 AB |
1542 | { |
1543 | struct net_device *netdev = adapter->netdev; | |
1544 | int err; | |
1545 | ||
1546 | if (netif_running(netdev)) | |
129cf89e JB |
1547 | iavf_free_traffic_irqs(adapter); |
1548 | iavf_free_misc_irq(adapter); | |
1549 | iavf_reset_interrupt_capability(adapter); | |
1550 | iavf_free_q_vectors(adapter); | |
1551 | iavf_free_queues(adapter); | |
5b36e8d0 | 1552 | |
129cf89e | 1553 | err = iavf_init_interrupt_scheme(adapter); |
5b36e8d0 AB |
1554 | if (err) |
1555 | goto err; | |
1556 | ||
1557 | netif_tx_stop_all_queues(netdev); | |
1558 | ||
129cf89e | 1559 | err = iavf_request_misc_irq(adapter); |
5b36e8d0 AB |
1560 | if (err) |
1561 | goto err; | |
1562 | ||
56184e01 | 1563 | set_bit(__IAVF_VSI_DOWN, adapter->vsi.state); |
5b36e8d0 | 1564 | |
129cf89e | 1565 | iavf_map_rings_to_vectors(adapter); |
5b36e8d0 AB |
1566 | err: |
1567 | return err; | |
1568 | } | |
1569 | ||
5eae00c5 | 1570 | /** |
b476b003 JP |
1571 | * iavf_process_aq_command - process aq_required flags |
1572 | * and sends aq command | |
1573 | * @adapter: pointer to iavf adapter structure | |
1574 | * | |
1575 | * Returns 0 on success | |
1576 | * Returns error code if no command was sent | |
1577 | * or error code if the command failed. | |
5eae00c5 | 1578 | **/ |
b476b003 | 1579 | static int iavf_process_aq_command(struct iavf_adapter *adapter) |
5eae00c5 | 1580 | { |
b476b003 JP |
1581 | if (adapter->aq_required & IAVF_FLAG_AQ_GET_CONFIG) |
1582 | return iavf_send_vf_config_msg(adapter); | |
129cf89e JB |
1583 | if (adapter->aq_required & IAVF_FLAG_AQ_DISABLE_QUEUES) { |
1584 | iavf_disable_queues(adapter); | |
b476b003 | 1585 | return 0; |
e284fc88 MW |
1586 | } |
1587 | ||
129cf89e JB |
1588 | if (adapter->aq_required & IAVF_FLAG_AQ_MAP_VECTORS) { |
1589 | iavf_map_queues(adapter); | |
b476b003 | 1590 | return 0; |
5eae00c5 GR |
1591 | } |
1592 | ||
129cf89e JB |
1593 | if (adapter->aq_required & IAVF_FLAG_AQ_ADD_MAC_FILTER) { |
1594 | iavf_add_ether_addrs(adapter); | |
b476b003 | 1595 | return 0; |
5eae00c5 GR |
1596 | } |
1597 | ||
129cf89e JB |
1598 | if (adapter->aq_required & IAVF_FLAG_AQ_ADD_VLAN_FILTER) { |
1599 | iavf_add_vlans(adapter); | |
b476b003 | 1600 | return 0; |
5eae00c5 GR |
1601 | } |
1602 | ||
129cf89e JB |
1603 | if (adapter->aq_required & IAVF_FLAG_AQ_DEL_MAC_FILTER) { |
1604 | iavf_del_ether_addrs(adapter); | |
b476b003 | 1605 | return 0; |
5eae00c5 GR |
1606 | } |
1607 | ||
129cf89e JB |
1608 | if (adapter->aq_required & IAVF_FLAG_AQ_DEL_VLAN_FILTER) { |
1609 | iavf_del_vlans(adapter); | |
b476b003 | 1610 | return 0; |
5eae00c5 GR |
1611 | } |
1612 | ||
129cf89e JB |
1613 | if (adapter->aq_required & IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING) { |
1614 | iavf_enable_vlan_stripping(adapter); | |
b476b003 | 1615 | return 0; |
8774370d MS |
1616 | } |
1617 | ||
129cf89e JB |
1618 | if (adapter->aq_required & IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING) { |
1619 | iavf_disable_vlan_stripping(adapter); | |
b476b003 | 1620 | return 0; |
8774370d MS |
1621 | } |
1622 | ||
129cf89e JB |
1623 | if (adapter->aq_required & IAVF_FLAG_AQ_CONFIGURE_QUEUES) { |
1624 | iavf_configure_queues(adapter); | |
b476b003 | 1625 | return 0; |
5eae00c5 GR |
1626 | } |
1627 | ||
129cf89e JB |
1628 | if (adapter->aq_required & IAVF_FLAG_AQ_ENABLE_QUEUES) { |
1629 | iavf_enable_queues(adapter); | |
b476b003 | 1630 | return 0; |
5eae00c5 GR |
1631 | } |
1632 | ||
129cf89e | 1633 | if (adapter->aq_required & IAVF_FLAG_AQ_CONFIGURE_RSS) { |
e25d00b8 ASJ |
1634 | /* This message goes straight to the firmware, not the |
1635 | * PF, so we don't have to set current_op as we will | |
1636 | * not get a response through the ARQ. | |
1637 | */ | |
129cf89e | 1638 | adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_RSS; |
b476b003 | 1639 | return 0; |
e25d00b8 | 1640 | } |
129cf89e JB |
1641 | if (adapter->aq_required & IAVF_FLAG_AQ_GET_HENA) { |
1642 | iavf_get_hena(adapter); | |
b476b003 | 1643 | return 0; |
43a3d9ba | 1644 | } |
129cf89e JB |
1645 | if (adapter->aq_required & IAVF_FLAG_AQ_SET_HENA) { |
1646 | iavf_set_hena(adapter); | |
b476b003 | 1647 | return 0; |
43a3d9ba | 1648 | } |
129cf89e JB |
1649 | if (adapter->aq_required & IAVF_FLAG_AQ_SET_RSS_KEY) { |
1650 | iavf_set_rss_key(adapter); | |
b476b003 | 1651 | return 0; |
43a3d9ba | 1652 | } |
129cf89e JB |
1653 | if (adapter->aq_required & IAVF_FLAG_AQ_SET_RSS_LUT) { |
1654 | iavf_set_rss_lut(adapter); | |
b476b003 | 1655 | return 0; |
43a3d9ba | 1656 | } |
e25d00b8 | 1657 | |
129cf89e JB |
1658 | if (adapter->aq_required & IAVF_FLAG_AQ_REQUEST_PROMISC) { |
1659 | iavf_set_promiscuous(adapter, FLAG_VF_UNICAST_PROMISC | | |
ff3f4cc2 | 1660 | FLAG_VF_MULTICAST_PROMISC); |
b476b003 | 1661 | return 0; |
47d34839 ASJ |
1662 | } |
1663 | ||
129cf89e JB |
1664 | if (adapter->aq_required & IAVF_FLAG_AQ_REQUEST_ALLMULTI) { |
1665 | iavf_set_promiscuous(adapter, FLAG_VF_MULTICAST_PROMISC); | |
b476b003 | 1666 | return 0; |
f42a5c74 | 1667 | } |
084a4685 | 1668 | if ((adapter->aq_required & IAVF_FLAG_AQ_RELEASE_PROMISC) || |
129cf89e JB |
1669 | (adapter->aq_required & IAVF_FLAG_AQ_RELEASE_ALLMULTI)) { |
1670 | iavf_set_promiscuous(adapter, 0); | |
b476b003 | 1671 | return 0; |
47d34839 | 1672 | } |
d5b33d02 | 1673 | |
129cf89e JB |
1674 | if (adapter->aq_required & IAVF_FLAG_AQ_ENABLE_CHANNELS) { |
1675 | iavf_enable_channels(adapter); | |
b476b003 | 1676 | return 0; |
d5b33d02 HR |
1677 | } |
1678 | ||
129cf89e JB |
1679 | if (adapter->aq_required & IAVF_FLAG_AQ_DISABLE_CHANNELS) { |
1680 | iavf_disable_channels(adapter); | |
b476b003 | 1681 | return 0; |
d5b33d02 | 1682 | } |
129cf89e JB |
1683 | if (adapter->aq_required & IAVF_FLAG_AQ_ADD_CLOUD_FILTER) { |
1684 | iavf_add_cloud_filter(adapter); | |
b476b003 | 1685 | return 0; |
0075fa0f HR |
1686 | } |
1687 | ||
129cf89e JB |
1688 | if (adapter->aq_required & IAVF_FLAG_AQ_DEL_CLOUD_FILTER) { |
1689 | iavf_del_cloud_filter(adapter); | |
b476b003 JP |
1690 | return 0; |
1691 | } | |
68dfe634 PG |
1692 | if (adapter->aq_required & IAVF_FLAG_AQ_DEL_CLOUD_FILTER) { |
1693 | iavf_del_cloud_filter(adapter); | |
1694 | return 0; | |
1695 | } | |
1696 | if (adapter->aq_required & IAVF_FLAG_AQ_ADD_CLOUD_FILTER) { | |
1697 | iavf_add_cloud_filter(adapter); | |
1698 | return 0; | |
1699 | } | |
0dbfbabb HW |
1700 | if (adapter->aq_required & IAVF_FLAG_AQ_ADD_FDIR_FILTER) { |
1701 | iavf_add_fdir_filter(adapter); | |
1702 | return IAVF_SUCCESS; | |
1703 | } | |
1704 | if (adapter->aq_required & IAVF_FLAG_AQ_DEL_FDIR_FILTER) { | |
1705 | iavf_del_fdir_filter(adapter); | |
1706 | return IAVF_SUCCESS; | |
1707 | } | |
0aaeb4fb HW |
1708 | if (adapter->aq_required & IAVF_FLAG_AQ_ADD_ADV_RSS_CFG) { |
1709 | iavf_add_adv_rss_cfg(adapter); | |
1710 | return 0; | |
1711 | } | |
1712 | if (adapter->aq_required & IAVF_FLAG_AQ_DEL_ADV_RSS_CFG) { | |
1713 | iavf_del_adv_rss_cfg(adapter); | |
1714 | return 0; | |
1715 | } | |
6a8621b9 JJ |
1716 | if (adapter->aq_required & IAVF_FLAG_AQ_REQUEST_STATS) { |
1717 | iavf_request_stats(adapter); | |
1718 | return 0; | |
1719 | } | |
1720 | ||
b476b003 JP |
1721 | return -EAGAIN; |
1722 | } | |
1723 | ||
b66c7bc1 JP |
1724 | /** |
1725 | * iavf_startup - first step of driver startup | |
1726 | * @adapter: board private structure | |
1727 | * | |
1728 | * Function process __IAVF_STARTUP driver state. | |
1729 | * When success the state is changed to __IAVF_INIT_VERSION_CHECK | |
1730 | * when fails it returns -EAGAIN | |
1731 | **/ | |
1732 | static int iavf_startup(struct iavf_adapter *adapter) | |
1733 | { | |
1734 | struct pci_dev *pdev = adapter->pdev; | |
1735 | struct iavf_hw *hw = &adapter->hw; | |
1736 | int err; | |
1737 | ||
1738 | WARN_ON(adapter->state != __IAVF_STARTUP); | |
1739 | ||
1740 | /* driver loaded, probe complete */ | |
1741 | adapter->flags &= ~IAVF_FLAG_PF_COMMS_FAILED; | |
1742 | adapter->flags &= ~IAVF_FLAG_RESET_PENDING; | |
1743 | err = iavf_set_mac_type(hw); | |
1744 | if (err) { | |
1745 | dev_err(&pdev->dev, "Failed to set MAC type (%d)\n", err); | |
1746 | goto err; | |
1747 | } | |
1748 | ||
1749 | err = iavf_check_reset_complete(hw); | |
1750 | if (err) { | |
1751 | dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n", | |
1752 | err); | |
1753 | goto err; | |
1754 | } | |
1755 | hw->aq.num_arq_entries = IAVF_AQ_LEN; | |
1756 | hw->aq.num_asq_entries = IAVF_AQ_LEN; | |
1757 | hw->aq.arq_buf_size = IAVF_MAX_AQ_BUF_SIZE; | |
1758 | hw->aq.asq_buf_size = IAVF_MAX_AQ_BUF_SIZE; | |
1759 | ||
1760 | err = iavf_init_adminq(hw); | |
1761 | if (err) { | |
1762 | dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n", err); | |
1763 | goto err; | |
1764 | } | |
1765 | err = iavf_send_api_ver(adapter); | |
1766 | if (err) { | |
1767 | dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err); | |
1768 | iavf_shutdown_adminq(hw); | |
1769 | goto err; | |
1770 | } | |
1771 | adapter->state = __IAVF_INIT_VERSION_CHECK; | |
1772 | err: | |
1773 | return err; | |
1774 | } | |
1775 | ||
1776 | /** | |
1777 | * iavf_init_version_check - second step of driver startup | |
1778 | * @adapter: board private structure | |
1779 | * | |
1780 | * Function process __IAVF_INIT_VERSION_CHECK driver state. | |
1781 | * When success the state is changed to __IAVF_INIT_GET_RESOURCES | |
1782 | * when fails it returns -EAGAIN | |
1783 | **/ | |
1784 | static int iavf_init_version_check(struct iavf_adapter *adapter) | |
1785 | { | |
1786 | struct pci_dev *pdev = adapter->pdev; | |
1787 | struct iavf_hw *hw = &adapter->hw; | |
1788 | int err = -EAGAIN; | |
1789 | ||
1790 | WARN_ON(adapter->state != __IAVF_INIT_VERSION_CHECK); | |
1791 | ||
1792 | if (!iavf_asq_done(hw)) { | |
1793 | dev_err(&pdev->dev, "Admin queue command never completed\n"); | |
1794 | iavf_shutdown_adminq(hw); | |
1795 | adapter->state = __IAVF_STARTUP; | |
1796 | goto err; | |
1797 | } | |
1798 | ||
1799 | /* aq msg sent, awaiting reply */ | |
1800 | err = iavf_verify_api_ver(adapter); | |
1801 | if (err) { | |
1802 | if (err == IAVF_ERR_ADMIN_QUEUE_NO_WORK) | |
1803 | err = iavf_send_api_ver(adapter); | |
1804 | else | |
1805 | dev_err(&pdev->dev, "Unsupported PF API version %d.%d, expected %d.%d\n", | |
1806 | adapter->pf_version.major, | |
1807 | adapter->pf_version.minor, | |
1808 | VIRTCHNL_VERSION_MAJOR, | |
1809 | VIRTCHNL_VERSION_MINOR); | |
1810 | goto err; | |
1811 | } | |
1812 | err = iavf_send_vf_config_msg(adapter); | |
1813 | if (err) { | |
1814 | dev_err(&pdev->dev, "Unable to send config request (%d)\n", | |
1815 | err); | |
1816 | goto err; | |
1817 | } | |
1818 | adapter->state = __IAVF_INIT_GET_RESOURCES; | |
1819 | ||
1820 | err: | |
1821 | return err; | |
1822 | } | |
1823 | ||
1824 | /** | |
1825 | * iavf_init_get_resources - third step of driver startup | |
1826 | * @adapter: board private structure | |
1827 | * | |
1828 | * Function process __IAVF_INIT_GET_RESOURCES driver state and | |
1829 | * finishes driver initialization procedure. | |
1830 | * When success the state is changed to __IAVF_DOWN | |
1831 | * when fails it returns -EAGAIN | |
1832 | **/ | |
1833 | static int iavf_init_get_resources(struct iavf_adapter *adapter) | |
1834 | { | |
1835 | struct net_device *netdev = adapter->netdev; | |
1836 | struct pci_dev *pdev = adapter->pdev; | |
1837 | struct iavf_hw *hw = &adapter->hw; | |
e0ef26fb | 1838 | int err; |
b66c7bc1 JP |
1839 | |
1840 | WARN_ON(adapter->state != __IAVF_INIT_GET_RESOURCES); | |
1841 | /* aq msg sent, awaiting reply */ | |
1842 | if (!adapter->vf_res) { | |
e0ef26fb BC |
1843 | adapter->vf_res = kzalloc(IAVF_VIRTCHNL_VF_RESOURCE_SIZE, |
1844 | GFP_KERNEL); | |
1845 | if (!adapter->vf_res) { | |
1846 | err = -ENOMEM; | |
b66c7bc1 | 1847 | goto err; |
e0ef26fb | 1848 | } |
b66c7bc1 JP |
1849 | } |
1850 | err = iavf_get_vf_config(adapter); | |
1851 | if (err == IAVF_ERR_ADMIN_QUEUE_NO_WORK) { | |
1852 | err = iavf_send_vf_config_msg(adapter); | |
1853 | goto err; | |
1854 | } else if (err == IAVF_ERR_PARAM) { | |
1855 | /* We only get ERR_PARAM if the device is in a very bad | |
1856 | * state or if we've been disabled for previous bad | |
1857 | * behavior. Either way, we're done now. | |
1858 | */ | |
1859 | iavf_shutdown_adminq(hw); | |
1860 | dev_err(&pdev->dev, "Unable to get VF config due to PF error condition, not retrying\n"); | |
1861 | return 0; | |
1862 | } | |
1863 | if (err) { | |
1864 | dev_err(&pdev->dev, "Unable to get VF config (%d)\n", err); | |
1865 | goto err_alloc; | |
1866 | } | |
1867 | ||
6650d31f JJB |
1868 | err = iavf_process_config(adapter); |
1869 | if (err) | |
b66c7bc1 JP |
1870 | goto err_alloc; |
1871 | adapter->current_op = VIRTCHNL_OP_UNKNOWN; | |
1872 | ||
1873 | adapter->flags |= IAVF_FLAG_RX_CSUM_ENABLED; | |
1874 | ||
1875 | netdev->netdev_ops = &iavf_netdev_ops; | |
1876 | iavf_set_ethtool_ops(netdev); | |
1877 | netdev->watchdog_timeo = 5 * HZ; | |
1878 | ||
1879 | /* MTU range: 68 - 9710 */ | |
1880 | netdev->min_mtu = ETH_MIN_MTU; | |
1881 | netdev->max_mtu = IAVF_MAX_RXBUFFER - IAVF_PACKET_HDR_PAD; | |
1882 | ||
1883 | if (!is_valid_ether_addr(adapter->hw.mac.addr)) { | |
1884 | dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n", | |
1885 | adapter->hw.mac.addr); | |
1886 | eth_hw_addr_random(netdev); | |
1887 | ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr); | |
1888 | } else { | |
b66c7bc1 JP |
1889 | ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr); |
1890 | ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr); | |
1891 | } | |
1892 | ||
1893 | adapter->tx_desc_count = IAVF_DEFAULT_TXD; | |
1894 | adapter->rx_desc_count = IAVF_DEFAULT_RXD; | |
1895 | err = iavf_init_interrupt_scheme(adapter); | |
1896 | if (err) | |
1897 | goto err_sw_init; | |
1898 | iavf_map_rings_to_vectors(adapter); | |
1899 | if (adapter->vf_res->vf_cap_flags & | |
1900 | VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) | |
1901 | adapter->flags |= IAVF_FLAG_WB_ON_ITR_CAPABLE; | |
1902 | ||
1903 | err = iavf_request_misc_irq(adapter); | |
1904 | if (err) | |
1905 | goto err_sw_init; | |
1906 | ||
1907 | netif_carrier_off(netdev); | |
1908 | adapter->link_up = false; | |
1909 | ||
1910 | /* set the semaphore to prevent any callbacks after device registration | |
1911 | * up to time when state of driver will be set to __IAVF_DOWN | |
1912 | */ | |
1913 | rtnl_lock(); | |
1914 | if (!adapter->netdev_registered) { | |
1915 | err = register_netdevice(netdev); | |
1916 | if (err) { | |
1917 | rtnl_unlock(); | |
1918 | goto err_register; | |
1919 | } | |
1920 | } | |
1921 | ||
1922 | adapter->netdev_registered = true; | |
1923 | ||
1924 | netif_tx_stop_all_queues(netdev); | |
1925 | if (CLIENT_ALLOWED(adapter)) { | |
1926 | err = iavf_lan_add_device(adapter); | |
f1340265 | 1927 | if (err) |
b66c7bc1 JP |
1928 | dev_info(&pdev->dev, "Failed to add VF to client API service list: %d\n", |
1929 | err); | |
b66c7bc1 JP |
1930 | } |
1931 | dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr); | |
1932 | if (netdev->features & NETIF_F_GRO) | |
1933 | dev_info(&pdev->dev, "GRO is enabled\n"); | |
1934 | ||
1935 | adapter->state = __IAVF_DOWN; | |
1936 | set_bit(__IAVF_VSI_DOWN, adapter->vsi.state); | |
1937 | rtnl_unlock(); | |
1938 | ||
1939 | iavf_misc_irq_enable(adapter); | |
1940 | wake_up(&adapter->down_waitqueue); | |
1941 | ||
1942 | adapter->rss_key = kzalloc(adapter->rss_key_size, GFP_KERNEL); | |
1943 | adapter->rss_lut = kzalloc(adapter->rss_lut_size, GFP_KERNEL); | |
753f3884 WY |
1944 | if (!adapter->rss_key || !adapter->rss_lut) { |
1945 | err = -ENOMEM; | |
b66c7bc1 | 1946 | goto err_mem; |
753f3884 | 1947 | } |
b66c7bc1 JP |
1948 | if (RSS_AQ(adapter)) |
1949 | adapter->aq_required |= IAVF_FLAG_AQ_CONFIGURE_RSS; | |
1950 | else | |
1951 | iavf_init_rss(adapter); | |
1952 | ||
1953 | return err; | |
1954 | err_mem: | |
1955 | iavf_free_rss(adapter); | |
1956 | err_register: | |
1957 | iavf_free_misc_irq(adapter); | |
1958 | err_sw_init: | |
1959 | iavf_reset_interrupt_capability(adapter); | |
1960 | err_alloc: | |
1961 | kfree(adapter->vf_res); | |
1962 | adapter->vf_res = NULL; | |
1963 | err: | |
1964 | return err; | |
1965 | } | |
1966 | ||
b476b003 JP |
1967 | /** |
1968 | * iavf_watchdog_task - Periodic call-back task | |
1969 | * @work: pointer to work_struct | |
1970 | **/ | |
1971 | static void iavf_watchdog_task(struct work_struct *work) | |
1972 | { | |
1973 | struct iavf_adapter *adapter = container_of(work, | |
1974 | struct iavf_adapter, | |
fdd4044f | 1975 | watchdog_task.work); |
b476b003 JP |
1976 | struct iavf_hw *hw = &adapter->hw; |
1977 | u32 reg_val; | |
1978 | ||
5ac49f3c | 1979 | if (!mutex_trylock(&adapter->crit_lock)) |
b476b003 JP |
1980 | goto restart_watchdog; |
1981 | ||
bac84861 JS |
1982 | if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) |
1983 | adapter->state = __IAVF_COMM_FAILED; | |
1984 | ||
1985 | switch (adapter->state) { | |
1986 | case __IAVF_COMM_FAILED: | |
b476b003 JP |
1987 | reg_val = rd32(hw, IAVF_VFGEN_RSTAT) & |
1988 | IAVF_VFGEN_RSTAT_VFR_STATE_MASK; | |
1989 | if (reg_val == VIRTCHNL_VFR_VFACTIVE || | |
1990 | reg_val == VIRTCHNL_VFR_COMPLETED) { | |
1991 | /* A chance for redemption! */ | |
bac84861 JS |
1992 | dev_err(&adapter->pdev->dev, |
1993 | "Hardware came out of reset. Attempting reinit.\n"); | |
b476b003 JP |
1994 | adapter->state = __IAVF_STARTUP; |
1995 | adapter->flags &= ~IAVF_FLAG_PF_COMMS_FAILED; | |
fdd4044f | 1996 | queue_delayed_work(iavf_wq, &adapter->init_task, 10); |
5ac49f3c | 1997 | mutex_unlock(&adapter->crit_lock); |
b476b003 JP |
1998 | /* Don't reschedule the watchdog, since we've restarted |
1999 | * the init task. When init_task contacts the PF and | |
2000 | * gets everything set up again, it'll restart the | |
2001 | * watchdog for us. Down, boy. Sit. Stay. Woof. | |
2002 | */ | |
2003 | return; | |
2004 | } | |
2005 | adapter->aq_required = 0; | |
2006 | adapter->current_op = VIRTCHNL_OP_UNKNOWN; | |
bac84861 JS |
2007 | queue_delayed_work(iavf_wq, |
2008 | &adapter->watchdog_task, | |
2009 | msecs_to_jiffies(10)); | |
0075fa0f | 2010 | goto watchdog_done; |
bac84861 | 2011 | case __IAVF_RESETTING: |
5ac49f3c | 2012 | mutex_unlock(&adapter->crit_lock); |
bac84861 JS |
2013 | queue_delayed_work(iavf_wq, &adapter->watchdog_task, HZ * 2); |
2014 | return; | |
2015 | case __IAVF_DOWN: | |
2016 | case __IAVF_DOWN_PENDING: | |
2017 | case __IAVF_TESTING: | |
2018 | case __IAVF_RUNNING: | |
2019 | if (adapter->current_op) { | |
2020 | if (!iavf_asq_done(hw)) { | |
2021 | dev_dbg(&adapter->pdev->dev, | |
2022 | "Admin queue timeout\n"); | |
2023 | iavf_send_api_ver(adapter); | |
2024 | } | |
2025 | } else { | |
93580766 TN |
2026 | /* An error will be returned if no commands were |
2027 | * processed; use this opportunity to update stats | |
2028 | */ | |
2029 | if (iavf_process_aq_command(adapter) && | |
bac84861 JS |
2030 | adapter->state == __IAVF_RUNNING) |
2031 | iavf_request_stats(adapter); | |
2032 | } | |
2033 | break; | |
2034 | case __IAVF_REMOVE: | |
5ac49f3c | 2035 | mutex_unlock(&adapter->crit_lock); |
bac84861 JS |
2036 | return; |
2037 | default: | |
2038 | goto restart_watchdog; | |
0075fa0f HR |
2039 | } |
2040 | ||
bac84861 | 2041 | /* check for hw reset */ |
b476b003 | 2042 | reg_val = rd32(hw, IAVF_VF_ARQLEN1) & IAVF_VF_ARQLEN1_ARQENABLE_MASK; |
bac84861 | 2043 | if (!reg_val) { |
b476b003 | 2044 | adapter->flags |= IAVF_FLAG_RESET_PENDING; |
b476b003 JP |
2045 | adapter->aq_required = 0; |
2046 | adapter->current_op = VIRTCHNL_OP_UNKNOWN; | |
bac84861 JS |
2047 | dev_err(&adapter->pdev->dev, "Hardware reset detected\n"); |
2048 | queue_work(iavf_wq, &adapter->reset_task); | |
b476b003 JP |
2049 | goto watchdog_done; |
2050 | } | |
2051 | ||
b476b003 | 2052 | schedule_delayed_work(&adapter->client_task, msecs_to_jiffies(5)); |
5eae00c5 | 2053 | watchdog_done: |
bac84861 JS |
2054 | if (adapter->state == __IAVF_RUNNING || |
2055 | adapter->state == __IAVF_COMM_FAILED) | |
129cf89e | 2056 | iavf_detect_recover_hung(&adapter->vsi); |
5ac49f3c | 2057 | mutex_unlock(&adapter->crit_lock); |
ef8693eb | 2058 | restart_watchdog: |
5eae00c5 | 2059 | if (adapter->aq_required) |
fdd4044f JP |
2060 | queue_delayed_work(iavf_wq, &adapter->watchdog_task, |
2061 | msecs_to_jiffies(20)); | |
5eae00c5 | 2062 | else |
fdd4044f JP |
2063 | queue_delayed_work(iavf_wq, &adapter->watchdog_task, HZ * 2); |
2064 | queue_work(iavf_wq, &adapter->adminq_task); | |
5eae00c5 GR |
2065 | } |
2066 | ||
129cf89e | 2067 | static void iavf_disable_vf(struct iavf_adapter *adapter) |
dedecb6d | 2068 | { |
129cf89e JB |
2069 | struct iavf_mac_filter *f, *ftmp; |
2070 | struct iavf_vlan_filter *fv, *fvtmp; | |
2071 | struct iavf_cloud_filter *cf, *cftmp; | |
dedecb6d | 2072 | |
129cf89e | 2073 | adapter->flags |= IAVF_FLAG_PF_COMMS_FAILED; |
dedecb6d | 2074 | |
44b034b4 JK |
2075 | /* We don't use netif_running() because it may be true prior to |
2076 | * ndo_open() returning, so we can't assume it means all our open | |
2077 | * tasks have finished, since we're not holding the rtnl_lock here. | |
2078 | */ | |
129cf89e | 2079 | if (adapter->state == __IAVF_RUNNING) { |
56184e01 | 2080 | set_bit(__IAVF_VSI_DOWN, adapter->vsi.state); |
dedecb6d JP |
2081 | netif_carrier_off(adapter->netdev); |
2082 | netif_tx_disable(adapter->netdev); | |
2083 | adapter->link_up = false; | |
129cf89e JB |
2084 | iavf_napi_disable_all(adapter); |
2085 | iavf_irq_disable(adapter); | |
2086 | iavf_free_traffic_irqs(adapter); | |
2087 | iavf_free_all_tx_resources(adapter); | |
2088 | iavf_free_all_rx_resources(adapter); | |
dedecb6d JP |
2089 | } |
2090 | ||
504398f0 JK |
2091 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
2092 | ||
0075fa0f | 2093 | /* Delete all of the filters */ |
dedecb6d JP |
2094 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { |
2095 | list_del(&f->list); | |
2096 | kfree(f); | |
2097 | } | |
2098 | ||
2099 | list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list, list) { | |
2100 | list_del(&fv->list); | |
2101 | kfree(fv); | |
2102 | } | |
2103 | ||
504398f0 JK |
2104 | spin_unlock_bh(&adapter->mac_vlan_list_lock); |
2105 | ||
0075fa0f HR |
2106 | spin_lock_bh(&adapter->cloud_filter_list_lock); |
2107 | list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) { | |
2108 | list_del(&cf->list); | |
2109 | kfree(cf); | |
2110 | adapter->num_cloud_filters--; | |
2111 | } | |
2112 | spin_unlock_bh(&adapter->cloud_filter_list_lock); | |
2113 | ||
129cf89e JB |
2114 | iavf_free_misc_irq(adapter); |
2115 | iavf_reset_interrupt_capability(adapter); | |
129cf89e | 2116 | iavf_free_q_vectors(adapter); |
f0d8f344 | 2117 | iavf_free_queues(adapter); |
e0ef26fb | 2118 | memset(adapter->vf_res, 0, IAVF_VIRTCHNL_VF_RESOURCE_SIZE); |
129cf89e | 2119 | iavf_shutdown_adminq(&adapter->hw); |
dedecb6d | 2120 | adapter->netdev->flags &= ~IFF_UP; |
5ac49f3c | 2121 | mutex_unlock(&adapter->crit_lock); |
129cf89e JB |
2122 | adapter->flags &= ~IAVF_FLAG_RESET_PENDING; |
2123 | adapter->state = __IAVF_DOWN; | |
fe2647ab | 2124 | wake_up(&adapter->down_waitqueue); |
dedecb6d JP |
2125 | dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n"); |
2126 | } | |
2127 | ||
5eae00c5 | 2128 | /** |
129cf89e | 2129 | * iavf_reset_task - Call-back task to handle hardware reset |
5eae00c5 GR |
2130 | * @work: pointer to work_struct |
2131 | * | |
2132 | * During reset we need to shut down and reinitialize the admin queue | |
2133 | * before we can use it to communicate with the PF again. We also clear | |
2134 | * and reinit the rings because that context is lost as well. | |
2135 | **/ | |
129cf89e | 2136 | static void iavf_reset_task(struct work_struct *work) |
5eae00c5 | 2137 | { |
129cf89e JB |
2138 | struct iavf_adapter *adapter = container_of(work, |
2139 | struct iavf_adapter, | |
ef8693eb | 2140 | reset_task); |
0075fa0f | 2141 | struct virtchnl_vf_resource *vfres = adapter->vf_res; |
ac833bbf | 2142 | struct net_device *netdev = adapter->netdev; |
f349daa5 | 2143 | struct iavf_hw *hw = &adapter->hw; |
9e052291 | 2144 | struct iavf_mac_filter *f, *ftmp; |
129cf89e JB |
2145 | struct iavf_vlan_filter *vlf; |
2146 | struct iavf_cloud_filter *cf; | |
ee5c1e92 | 2147 | u32 reg_val; |
ac833bbf | 2148 | int i = 0, err; |
44b034b4 | 2149 | bool running; |
5eae00c5 | 2150 | |
06aa040f AD |
2151 | /* When device is being removed it doesn't make sense to run the reset |
2152 | * task, just return in such a case. | |
2153 | */ | |
5ac49f3c | 2154 | if (mutex_is_locked(&adapter->remove_lock)) |
06aa040f AD |
2155 | return; |
2156 | ||
5ac49f3c | 2157 | if (iavf_lock_timeout(&adapter->crit_lock, 200)) { |
226d5285 SA |
2158 | schedule_work(&adapter->reset_task); |
2159 | return; | |
2160 | } | |
5ac49f3c | 2161 | while (!mutex_trylock(&adapter->client_lock)) |
f98a2006 | 2162 | usleep_range(500, 1000); |
ed0e894d | 2163 | if (CLIENT_ENABLED(adapter)) { |
129cf89e JB |
2164 | adapter->flags &= ~(IAVF_FLAG_CLIENT_NEEDS_OPEN | |
2165 | IAVF_FLAG_CLIENT_NEEDS_CLOSE | | |
2166 | IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS | | |
2167 | IAVF_FLAG_SERVICE_CLIENT_REQUESTED); | |
ed0e894d | 2168 | cancel_delayed_work_sync(&adapter->client_task); |
129cf89e | 2169 | iavf_notify_client_close(&adapter->vsi, true); |
ed0e894d | 2170 | } |
129cf89e JB |
2171 | iavf_misc_irq_disable(adapter); |
2172 | if (adapter->flags & IAVF_FLAG_RESET_NEEDED) { | |
2173 | adapter->flags &= ~IAVF_FLAG_RESET_NEEDED; | |
67c818a1 MW |
2174 | /* Restart the AQ here. If we have been reset but didn't |
2175 | * detect it, or if the PF had to reinit, our AQ will be hosed. | |
2176 | */ | |
129cf89e JB |
2177 | iavf_shutdown_adminq(hw); |
2178 | iavf_init_adminq(hw); | |
2179 | iavf_request_reset(adapter); | |
3526d800 | 2180 | } |
129cf89e | 2181 | adapter->flags |= IAVF_FLAG_RESET_PENDING; |
3526d800 | 2182 | |
ef8693eb | 2183 | /* poll until we see the reset actually happen */ |
8e3e4b9d | 2184 | for (i = 0; i < IAVF_RESET_WAIT_DETECTED_COUNT; i++) { |
f1cad2ce JB |
2185 | reg_val = rd32(hw, IAVF_VF_ARQLEN1) & |
2186 | IAVF_VF_ARQLEN1_ARQENABLE_MASK; | |
ee5c1e92 | 2187 | if (!reg_val) |
ef8693eb | 2188 | break; |
ee5c1e92 | 2189 | usleep_range(5000, 10000); |
ef8693eb | 2190 | } |
8e3e4b9d | 2191 | if (i == IAVF_RESET_WAIT_DETECTED_COUNT) { |
67c818a1 | 2192 | dev_info(&adapter->pdev->dev, "Never saw reset\n"); |
ef8693eb MW |
2193 | goto continue_reset; /* act like the reset happened */ |
2194 | } | |
5eae00c5 | 2195 | |
ef8693eb | 2196 | /* wait until the reset is complete and the PF is responding to us */ |
8e3e4b9d | 2197 | for (i = 0; i < IAVF_RESET_WAIT_COMPLETE_COUNT; i++) { |
7d3f04af | 2198 | /* sleep first to make sure a minimum wait time is met */ |
129cf89e | 2199 | msleep(IAVF_RESET_WAIT_MS); |
7d3f04af | 2200 | |
f1cad2ce JB |
2201 | reg_val = rd32(hw, IAVF_VFGEN_RSTAT) & |
2202 | IAVF_VFGEN_RSTAT_VFR_STATE_MASK; | |
310a2ad9 | 2203 | if (reg_val == VIRTCHNL_VFR_VFACTIVE) |
5eae00c5 | 2204 | break; |
5eae00c5 | 2205 | } |
7d3f04af | 2206 | |
509a447a | 2207 | pci_set_master(adapter->pdev); |
7d3f04af | 2208 | |
8e3e4b9d | 2209 | if (i == IAVF_RESET_WAIT_COMPLETE_COUNT) { |
80e72893 | 2210 | dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n", |
ee5c1e92 | 2211 | reg_val); |
129cf89e | 2212 | iavf_disable_vf(adapter); |
5ac49f3c | 2213 | mutex_unlock(&adapter->client_lock); |
ef8693eb | 2214 | return; /* Do not attempt to reinit. It's dead, Jim. */ |
5eae00c5 | 2215 | } |
ef8693eb MW |
2216 | |
2217 | continue_reset: | |
44b034b4 JK |
2218 | /* We don't use netif_running() because it may be true prior to |
2219 | * ndo_open() returning, so we can't assume it means all our open | |
2220 | * tasks have finished, since we're not holding the rtnl_lock here. | |
2221 | */ | |
129cf89e JB |
2222 | running = ((adapter->state == __IAVF_RUNNING) || |
2223 | (adapter->state == __IAVF_RESETTING)); | |
44b034b4 JK |
2224 | |
2225 | if (running) { | |
3c8e0b98 | 2226 | netif_carrier_off(netdev); |
67c818a1 | 2227 | netif_tx_stop_all_queues(netdev); |
3f341acc | 2228 | adapter->link_up = false; |
129cf89e | 2229 | iavf_napi_disable_all(adapter); |
3c8e0b98 | 2230 | } |
129cf89e | 2231 | iavf_irq_disable(adapter); |
ac833bbf | 2232 | |
129cf89e JB |
2233 | adapter->state = __IAVF_RESETTING; |
2234 | adapter->flags &= ~IAVF_FLAG_RESET_PENDING; | |
67c818a1 MW |
2235 | |
2236 | /* free the Tx/Rx rings and descriptors, might be better to just | |
2237 | * re-use them sometime in the future | |
2238 | */ | |
129cf89e JB |
2239 | iavf_free_all_rx_resources(adapter); |
2240 | iavf_free_all_tx_resources(adapter); | |
5eae00c5 | 2241 | |
129cf89e | 2242 | adapter->flags |= IAVF_FLAG_QUEUES_DISABLED; |
5eae00c5 | 2243 | /* kill and reinit the admin queue */ |
129cf89e | 2244 | iavf_shutdown_adminq(hw); |
310a2ad9 | 2245 | adapter->current_op = VIRTCHNL_OP_UNKNOWN; |
129cf89e | 2246 | err = iavf_init_adminq(hw); |
5eae00c5 | 2247 | if (err) |
ac833bbf MW |
2248 | dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n", |
2249 | err); | |
5b36e8d0 AB |
2250 | adapter->aq_required = 0; |
2251 | ||
129cf89e JB |
2252 | if (adapter->flags & IAVF_FLAG_REINIT_ITR_NEEDED) { |
2253 | err = iavf_reinit_interrupt_scheme(adapter); | |
5b36e8d0 AB |
2254 | if (err) |
2255 | goto reset_err; | |
2256 | } | |
5eae00c5 | 2257 | |
a7550f8b MFIP |
2258 | if (RSS_AQ(adapter)) { |
2259 | adapter->aq_required |= IAVF_FLAG_AQ_CONFIGURE_RSS; | |
2260 | } else { | |
2261 | err = iavf_init_rss(adapter); | |
2262 | if (err) | |
2263 | goto reset_err; | |
2264 | } | |
2265 | ||
129cf89e JB |
2266 | adapter->aq_required |= IAVF_FLAG_AQ_GET_CONFIG; |
2267 | adapter->aq_required |= IAVF_FLAG_AQ_MAP_VECTORS; | |
ac833bbf | 2268 | |
504398f0 JK |
2269 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
2270 | ||
9e052291 SA |
2271 | /* Delete filter for the current MAC address, it could have |
2272 | * been changed by the PF via administratively set MAC. | |
2273 | * Will be re-added via VIRTCHNL_OP_GET_VF_RESOURCES. | |
2274 | */ | |
2275 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { | |
2276 | if (ether_addr_equal(f->macaddr, adapter->hw.mac.addr)) { | |
2277 | list_del(&f->list); | |
2278 | kfree(f); | |
2279 | } | |
2280 | } | |
ac833bbf MW |
2281 | /* re-add all MAC filters */ |
2282 | list_for_each_entry(f, &adapter->mac_filter_list, list) { | |
2283 | f->add = true; | |
2284 | } | |
2285 | /* re-add all VLAN filters */ | |
40d01366 MW |
2286 | list_for_each_entry(vlf, &adapter->vlan_filter_list, list) { |
2287 | vlf->add = true; | |
ac833bbf | 2288 | } |
504398f0 JK |
2289 | |
2290 | spin_unlock_bh(&adapter->mac_vlan_list_lock); | |
2291 | ||
0075fa0f HR |
2292 | /* check if TCs are running and re-add all cloud filters */ |
2293 | spin_lock_bh(&adapter->cloud_filter_list_lock); | |
2294 | if ((vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADQ) && | |
2295 | adapter->num_tc) { | |
2296 | list_for_each_entry(cf, &adapter->cloud_filter_list, list) { | |
2297 | cf->add = true; | |
2298 | } | |
2299 | } | |
2300 | spin_unlock_bh(&adapter->cloud_filter_list_lock); | |
2301 | ||
129cf89e JB |
2302 | adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER; |
2303 | adapter->aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER; | |
2304 | adapter->aq_required |= IAVF_FLAG_AQ_ADD_CLOUD_FILTER; | |
2305 | iavf_misc_irq_enable(adapter); | |
5eae00c5 | 2306 | |
fdd4044f | 2307 | mod_delayed_work(iavf_wq, &adapter->watchdog_task, 2); |
5eae00c5 | 2308 | |
44b034b4 JK |
2309 | /* We were running when the reset started, so we need to restore some |
2310 | * state here. | |
2311 | */ | |
2312 | if (running) { | |
5eae00c5 | 2313 | /* allocate transmit descriptors */ |
129cf89e | 2314 | err = iavf_setup_all_tx_resources(adapter); |
5eae00c5 GR |
2315 | if (err) |
2316 | goto reset_err; | |
2317 | ||
2318 | /* allocate receive descriptors */ | |
129cf89e | 2319 | err = iavf_setup_all_rx_resources(adapter); |
5eae00c5 GR |
2320 | if (err) |
2321 | goto reset_err; | |
2322 | ||
129cf89e JB |
2323 | if (adapter->flags & IAVF_FLAG_REINIT_ITR_NEEDED) { |
2324 | err = iavf_request_traffic_irqs(adapter, netdev->name); | |
5b36e8d0 AB |
2325 | if (err) |
2326 | goto reset_err; | |
2327 | ||
129cf89e | 2328 | adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED; |
5b36e8d0 AB |
2329 | } |
2330 | ||
129cf89e | 2331 | iavf_configure(adapter); |
5eae00c5 | 2332 | |
129cf89e | 2333 | iavf_up_complete(adapter); |
5eae00c5 | 2334 | |
129cf89e | 2335 | iavf_irq_enable(adapter, true); |
67c818a1 | 2336 | } else { |
129cf89e | 2337 | adapter->state = __IAVF_DOWN; |
fe2647ab | 2338 | wake_up(&adapter->down_waitqueue); |
5eae00c5 | 2339 | } |
5ac49f3c SA |
2340 | mutex_unlock(&adapter->client_lock); |
2341 | mutex_unlock(&adapter->crit_lock); | |
67c818a1 | 2342 | |
5eae00c5 GR |
2343 | return; |
2344 | reset_err: | |
5ac49f3c SA |
2345 | mutex_unlock(&adapter->client_lock); |
2346 | mutex_unlock(&adapter->crit_lock); | |
80e72893 | 2347 | dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n"); |
129cf89e | 2348 | iavf_close(netdev); |
5eae00c5 GR |
2349 | } |
2350 | ||
2351 | /** | |
129cf89e | 2352 | * iavf_adminq_task - worker thread to clean the admin queue |
5eae00c5 GR |
2353 | * @work: pointer to work_struct containing our data |
2354 | **/ | |
129cf89e | 2355 | static void iavf_adminq_task(struct work_struct *work) |
5eae00c5 | 2356 | { |
129cf89e JB |
2357 | struct iavf_adapter *adapter = |
2358 | container_of(work, struct iavf_adapter, adminq_task); | |
f349daa5 | 2359 | struct iavf_hw *hw = &adapter->hw; |
7af36e32 | 2360 | struct iavf_arq_event_info event; |
c969ef4e | 2361 | enum virtchnl_ops v_op; |
80754bbc | 2362 | enum iavf_status ret, v_ret; |
912257e5 | 2363 | u32 val, oldval; |
5eae00c5 GR |
2364 | u16 pending; |
2365 | ||
129cf89e | 2366 | if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) |
7235448c | 2367 | goto out; |
ef8693eb | 2368 | |
129cf89e | 2369 | event.buf_len = IAVF_MAX_AQ_BUF_SIZE; |
1001dc37 | 2370 | event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
249c8b8d | 2371 | if (!event.msg_buf) |
7235448c | 2372 | goto out; |
249c8b8d | 2373 | |
5ac49f3c | 2374 | if (iavf_lock_timeout(&adapter->crit_lock, 200)) |
226d5285 | 2375 | goto freedom; |
5eae00c5 | 2376 | do { |
129cf89e | 2377 | ret = iavf_clean_arq_element(hw, &event, &pending); |
c969ef4e | 2378 | v_op = (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high); |
80754bbc | 2379 | v_ret = (enum iavf_status)le32_to_cpu(event.desc.cookie_low); |
c969ef4e TD |
2380 | |
2381 | if (ret || !v_op) | |
5eae00c5 GR |
2382 | break; /* No event to process or error cleaning ARQ */ |
2383 | ||
129cf89e JB |
2384 | iavf_virtchnl_completion(adapter, v_op, v_ret, event.msg_buf, |
2385 | event.msg_len); | |
75a64435 | 2386 | if (pending != 0) |
129cf89e | 2387 | memset(event.msg_buf, 0, IAVF_MAX_AQ_BUF_SIZE); |
5eae00c5 | 2388 | } while (pending); |
5ac49f3c | 2389 | mutex_unlock(&adapter->crit_lock); |
5eae00c5 | 2390 | |
67c818a1 | 2391 | if ((adapter->flags & |
129cf89e JB |
2392 | (IAVF_FLAG_RESET_PENDING | IAVF_FLAG_RESET_NEEDED)) || |
2393 | adapter->state == __IAVF_RESETTING) | |
67c818a1 MW |
2394 | goto freedom; |
2395 | ||
912257e5 MW |
2396 | /* check for error indications */ |
2397 | val = rd32(hw, hw->aq.arq.len); | |
2b3fd880 | 2398 | if (val == 0xdeadbeef || val == 0xffffffff) /* device in reset */ |
19b73d8e | 2399 | goto freedom; |
912257e5 | 2400 | oldval = val; |
f1cad2ce | 2401 | if (val & IAVF_VF_ARQLEN1_ARQVFE_MASK) { |
912257e5 | 2402 | dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n"); |
f1cad2ce | 2403 | val &= ~IAVF_VF_ARQLEN1_ARQVFE_MASK; |
912257e5 | 2404 | } |
f1cad2ce | 2405 | if (val & IAVF_VF_ARQLEN1_ARQOVFL_MASK) { |
912257e5 | 2406 | dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n"); |
f1cad2ce | 2407 | val &= ~IAVF_VF_ARQLEN1_ARQOVFL_MASK; |
912257e5 | 2408 | } |
f1cad2ce | 2409 | if (val & IAVF_VF_ARQLEN1_ARQCRIT_MASK) { |
912257e5 | 2410 | dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n"); |
f1cad2ce | 2411 | val &= ~IAVF_VF_ARQLEN1_ARQCRIT_MASK; |
912257e5 MW |
2412 | } |
2413 | if (oldval != val) | |
2414 | wr32(hw, hw->aq.arq.len, val); | |
2415 | ||
2416 | val = rd32(hw, hw->aq.asq.len); | |
2417 | oldval = val; | |
f1cad2ce | 2418 | if (val & IAVF_VF_ATQLEN1_ATQVFE_MASK) { |
912257e5 | 2419 | dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n"); |
f1cad2ce | 2420 | val &= ~IAVF_VF_ATQLEN1_ATQVFE_MASK; |
912257e5 | 2421 | } |
f1cad2ce | 2422 | if (val & IAVF_VF_ATQLEN1_ATQOVFL_MASK) { |
912257e5 | 2423 | dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n"); |
f1cad2ce | 2424 | val &= ~IAVF_VF_ATQLEN1_ATQOVFL_MASK; |
912257e5 | 2425 | } |
f1cad2ce | 2426 | if (val & IAVF_VF_ATQLEN1_ATQCRIT_MASK) { |
912257e5 | 2427 | dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n"); |
f1cad2ce | 2428 | val &= ~IAVF_VF_ATQLEN1_ATQCRIT_MASK; |
912257e5 MW |
2429 | } |
2430 | if (oldval != val) | |
2431 | wr32(hw, hw->aq.asq.len, val); | |
2432 | ||
67c818a1 | 2433 | freedom: |
7235448c MW |
2434 | kfree(event.msg_buf); |
2435 | out: | |
5eae00c5 | 2436 | /* re-enable Admin queue interrupt cause */ |
129cf89e | 2437 | iavf_misc_irq_enable(adapter); |
5eae00c5 GR |
2438 | } |
2439 | ||
ed0e894d | 2440 | /** |
129cf89e | 2441 | * iavf_client_task - worker thread to perform client work |
ed0e894d MW |
2442 | * @work: pointer to work_struct containing our data |
2443 | * | |
2444 | * This task handles client interactions. Because client calls can be | |
2445 | * reentrant, we can't handle them in the watchdog. | |
2446 | **/ | |
129cf89e | 2447 | static void iavf_client_task(struct work_struct *work) |
ed0e894d | 2448 | { |
129cf89e JB |
2449 | struct iavf_adapter *adapter = |
2450 | container_of(work, struct iavf_adapter, client_task.work); | |
ed0e894d MW |
2451 | |
2452 | /* If we can't get the client bit, just give up. We'll be rescheduled | |
2453 | * later. | |
2454 | */ | |
2455 | ||
5ac49f3c | 2456 | if (!mutex_trylock(&adapter->client_lock)) |
ed0e894d MW |
2457 | return; |
2458 | ||
129cf89e JB |
2459 | if (adapter->flags & IAVF_FLAG_SERVICE_CLIENT_REQUESTED) { |
2460 | iavf_client_subtask(adapter); | |
2461 | adapter->flags &= ~IAVF_FLAG_SERVICE_CLIENT_REQUESTED; | |
ed0e894d MW |
2462 | goto out; |
2463 | } | |
129cf89e JB |
2464 | if (adapter->flags & IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS) { |
2465 | iavf_notify_client_l2_params(&adapter->vsi); | |
2466 | adapter->flags &= ~IAVF_FLAG_CLIENT_NEEDS_L2_PARAMS; | |
01acc73f AB |
2467 | goto out; |
2468 | } | |
129cf89e JB |
2469 | if (adapter->flags & IAVF_FLAG_CLIENT_NEEDS_CLOSE) { |
2470 | iavf_notify_client_close(&adapter->vsi, false); | |
2471 | adapter->flags &= ~IAVF_FLAG_CLIENT_NEEDS_CLOSE; | |
ed0e894d MW |
2472 | goto out; |
2473 | } | |
129cf89e JB |
2474 | if (adapter->flags & IAVF_FLAG_CLIENT_NEEDS_OPEN) { |
2475 | iavf_notify_client_open(&adapter->vsi); | |
2476 | adapter->flags &= ~IAVF_FLAG_CLIENT_NEEDS_OPEN; | |
ed0e894d MW |
2477 | } |
2478 | out: | |
5ac49f3c | 2479 | mutex_unlock(&adapter->client_lock); |
ed0e894d MW |
2480 | } |
2481 | ||
5eae00c5 | 2482 | /** |
129cf89e | 2483 | * iavf_free_all_tx_resources - Free Tx Resources for All Queues |
5eae00c5 GR |
2484 | * @adapter: board private structure |
2485 | * | |
2486 | * Free all transmit software resources | |
2487 | **/ | |
129cf89e | 2488 | void iavf_free_all_tx_resources(struct iavf_adapter *adapter) |
5eae00c5 GR |
2489 | { |
2490 | int i; | |
2491 | ||
fdb47ae8 MW |
2492 | if (!adapter->tx_rings) |
2493 | return; | |
2494 | ||
cc052927 | 2495 | for (i = 0; i < adapter->num_active_queues; i++) |
0dd438d8 | 2496 | if (adapter->tx_rings[i].desc) |
129cf89e | 2497 | iavf_free_tx_resources(&adapter->tx_rings[i]); |
5eae00c5 GR |
2498 | } |
2499 | ||
2500 | /** | |
129cf89e | 2501 | * iavf_setup_all_tx_resources - allocate all queues Tx resources |
5eae00c5 GR |
2502 | * @adapter: board private structure |
2503 | * | |
2504 | * If this function returns with an error, then it's possible one or | |
2505 | * more of the rings is populated (while the rest are not). It is the | |
2506 | * callers duty to clean those orphaned rings. | |
2507 | * | |
2508 | * Return 0 on success, negative on failure | |
2509 | **/ | |
129cf89e | 2510 | static int iavf_setup_all_tx_resources(struct iavf_adapter *adapter) |
5eae00c5 GR |
2511 | { |
2512 | int i, err = 0; | |
2513 | ||
cc052927 | 2514 | for (i = 0; i < adapter->num_active_queues; i++) { |
0dd438d8 | 2515 | adapter->tx_rings[i].count = adapter->tx_desc_count; |
129cf89e | 2516 | err = iavf_setup_tx_descriptors(&adapter->tx_rings[i]); |
5eae00c5 GR |
2517 | if (!err) |
2518 | continue; | |
2519 | dev_err(&adapter->pdev->dev, | |
fb43201f | 2520 | "Allocation for Tx Queue %u failed\n", i); |
5eae00c5 GR |
2521 | break; |
2522 | } | |
2523 | ||
2524 | return err; | |
2525 | } | |
2526 | ||
2527 | /** | |
129cf89e | 2528 | * iavf_setup_all_rx_resources - allocate all queues Rx resources |
5eae00c5 GR |
2529 | * @adapter: board private structure |
2530 | * | |
2531 | * If this function returns with an error, then it's possible one or | |
2532 | * more of the rings is populated (while the rest are not). It is the | |
2533 | * callers duty to clean those orphaned rings. | |
2534 | * | |
2535 | * Return 0 on success, negative on failure | |
2536 | **/ | |
129cf89e | 2537 | static int iavf_setup_all_rx_resources(struct iavf_adapter *adapter) |
5eae00c5 GR |
2538 | { |
2539 | int i, err = 0; | |
2540 | ||
cc052927 | 2541 | for (i = 0; i < adapter->num_active_queues; i++) { |
0dd438d8 | 2542 | adapter->rx_rings[i].count = adapter->rx_desc_count; |
129cf89e | 2543 | err = iavf_setup_rx_descriptors(&adapter->rx_rings[i]); |
5eae00c5 GR |
2544 | if (!err) |
2545 | continue; | |
2546 | dev_err(&adapter->pdev->dev, | |
fb43201f | 2547 | "Allocation for Rx Queue %u failed\n", i); |
5eae00c5 GR |
2548 | break; |
2549 | } | |
2550 | return err; | |
2551 | } | |
2552 | ||
2553 | /** | |
129cf89e | 2554 | * iavf_free_all_rx_resources - Free Rx Resources for All Queues |
5eae00c5 GR |
2555 | * @adapter: board private structure |
2556 | * | |
2557 | * Free all receive software resources | |
2558 | **/ | |
129cf89e | 2559 | void iavf_free_all_rx_resources(struct iavf_adapter *adapter) |
5eae00c5 GR |
2560 | { |
2561 | int i; | |
2562 | ||
fdb47ae8 MW |
2563 | if (!adapter->rx_rings) |
2564 | return; | |
2565 | ||
cc052927 | 2566 | for (i = 0; i < adapter->num_active_queues; i++) |
0dd438d8 | 2567 | if (adapter->rx_rings[i].desc) |
129cf89e | 2568 | iavf_free_rx_resources(&adapter->rx_rings[i]); |
5eae00c5 GR |
2569 | } |
2570 | ||
591532d6 | 2571 | /** |
129cf89e | 2572 | * iavf_validate_tx_bandwidth - validate the max Tx bandwidth |
591532d6 HR |
2573 | * @adapter: board private structure |
2574 | * @max_tx_rate: max Tx bw for a tc | |
2575 | **/ | |
129cf89e JB |
2576 | static int iavf_validate_tx_bandwidth(struct iavf_adapter *adapter, |
2577 | u64 max_tx_rate) | |
591532d6 HR |
2578 | { |
2579 | int speed = 0, ret = 0; | |
2580 | ||
e0ef26fb BC |
2581 | if (ADV_LINK_SUPPORT(adapter)) { |
2582 | if (adapter->link_speed_mbps < U32_MAX) { | |
2583 | speed = adapter->link_speed_mbps; | |
2584 | goto validate_bw; | |
2585 | } else { | |
2586 | dev_err(&adapter->pdev->dev, "Unknown link speed\n"); | |
2587 | return -EINVAL; | |
2588 | } | |
2589 | } | |
2590 | ||
591532d6 | 2591 | switch (adapter->link_speed) { |
5071bda2 | 2592 | case VIRTCHNL_LINK_SPEED_40GB: |
18c012d9 | 2593 | speed = SPEED_40000; |
591532d6 | 2594 | break; |
5071bda2 | 2595 | case VIRTCHNL_LINK_SPEED_25GB: |
18c012d9 | 2596 | speed = SPEED_25000; |
591532d6 | 2597 | break; |
5071bda2 | 2598 | case VIRTCHNL_LINK_SPEED_20GB: |
18c012d9 | 2599 | speed = SPEED_20000; |
591532d6 | 2600 | break; |
5071bda2 | 2601 | case VIRTCHNL_LINK_SPEED_10GB: |
18c012d9 BC |
2602 | speed = SPEED_10000; |
2603 | break; | |
2604 | case VIRTCHNL_LINK_SPEED_5GB: | |
2605 | speed = SPEED_5000; | |
2606 | break; | |
2607 | case VIRTCHNL_LINK_SPEED_2_5GB: | |
2608 | speed = SPEED_2500; | |
591532d6 | 2609 | break; |
5071bda2 | 2610 | case VIRTCHNL_LINK_SPEED_1GB: |
18c012d9 | 2611 | speed = SPEED_1000; |
591532d6 | 2612 | break; |
5071bda2 | 2613 | case VIRTCHNL_LINK_SPEED_100MB: |
18c012d9 | 2614 | speed = SPEED_100; |
591532d6 HR |
2615 | break; |
2616 | default: | |
2617 | break; | |
2618 | } | |
2619 | ||
e0ef26fb | 2620 | validate_bw: |
591532d6 HR |
2621 | if (max_tx_rate > speed) { |
2622 | dev_err(&adapter->pdev->dev, | |
2623 | "Invalid tx rate specified\n"); | |
2624 | ret = -EINVAL; | |
2625 | } | |
2626 | ||
2627 | return ret; | |
2628 | } | |
2629 | ||
d5b33d02 | 2630 | /** |
262de08f | 2631 | * iavf_validate_ch_config - validate queue mapping info |
d5b33d02 HR |
2632 | * @adapter: board private structure |
2633 | * @mqprio_qopt: queue parameters | |
2634 | * | |
2635 | * This function validates if the config provided by the user to | |
2636 | * configure queue channels is valid or not. Returns 0 on a valid | |
2637 | * config. | |
2638 | **/ | |
129cf89e JB |
2639 | static int iavf_validate_ch_config(struct iavf_adapter *adapter, |
2640 | struct tc_mqprio_qopt_offload *mqprio_qopt) | |
d5b33d02 | 2641 | { |
591532d6 | 2642 | u64 total_max_rate = 0; |
d5b33d02 | 2643 | int i, num_qps = 0; |
591532d6 HR |
2644 | u64 tx_rate = 0; |
2645 | int ret = 0; | |
d5b33d02 | 2646 | |
129cf89e | 2647 | if (mqprio_qopt->qopt.num_tc > IAVF_MAX_TRAFFIC_CLASS || |
d5b33d02 HR |
2648 | mqprio_qopt->qopt.num_tc < 1) |
2649 | return -EINVAL; | |
2650 | ||
2651 | for (i = 0; i <= mqprio_qopt->qopt.num_tc - 1; i++) { | |
2652 | if (!mqprio_qopt->qopt.count[i] || | |
d5b33d02 HR |
2653 | mqprio_qopt->qopt.offset[i] != num_qps) |
2654 | return -EINVAL; | |
591532d6 HR |
2655 | if (mqprio_qopt->min_rate[i]) { |
2656 | dev_err(&adapter->pdev->dev, | |
2657 | "Invalid min tx rate (greater than 0) specified\n"); | |
2658 | return -EINVAL; | |
2659 | } | |
2660 | /*convert to Mbps */ | |
2661 | tx_rate = div_u64(mqprio_qopt->max_rate[i], | |
129cf89e | 2662 | IAVF_MBPS_DIVISOR); |
591532d6 | 2663 | total_max_rate += tx_rate; |
d5b33d02 HR |
2664 | num_qps += mqprio_qopt->qopt.count[i]; |
2665 | } | |
129cf89e | 2666 | if (num_qps > IAVF_MAX_REQ_QUEUES) |
d5b33d02 HR |
2667 | return -EINVAL; |
2668 | ||
129cf89e | 2669 | ret = iavf_validate_tx_bandwidth(adapter, total_max_rate); |
591532d6 | 2670 | return ret; |
d5b33d02 HR |
2671 | } |
2672 | ||
0075fa0f | 2673 | /** |
b50f7bca JB |
2674 | * iavf_del_all_cloud_filters - delete all cloud filters on the traffic classes |
2675 | * @adapter: board private structure | |
0075fa0f | 2676 | **/ |
129cf89e | 2677 | static void iavf_del_all_cloud_filters(struct iavf_adapter *adapter) |
0075fa0f | 2678 | { |
129cf89e | 2679 | struct iavf_cloud_filter *cf, *cftmp; |
0075fa0f HR |
2680 | |
2681 | spin_lock_bh(&adapter->cloud_filter_list_lock); | |
2682 | list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, | |
2683 | list) { | |
2684 | list_del(&cf->list); | |
2685 | kfree(cf); | |
2686 | adapter->num_cloud_filters--; | |
2687 | } | |
2688 | spin_unlock_bh(&adapter->cloud_filter_list_lock); | |
2689 | } | |
2690 | ||
d5b33d02 | 2691 | /** |
129cf89e | 2692 | * __iavf_setup_tc - configure multiple traffic classes |
d5b33d02 | 2693 | * @netdev: network interface device structure |
b50f7bca | 2694 | * @type_data: tc offload data |
d5b33d02 HR |
2695 | * |
2696 | * This function processes the config information provided by the | |
2697 | * user to configure traffic classes/queue channels and packages the | |
2698 | * information to request the PF to setup traffic classes. | |
2699 | * | |
2700 | * Returns 0 on success. | |
2701 | **/ | |
129cf89e | 2702 | static int __iavf_setup_tc(struct net_device *netdev, void *type_data) |
d5b33d02 HR |
2703 | { |
2704 | struct tc_mqprio_qopt_offload *mqprio_qopt = type_data; | |
129cf89e | 2705 | struct iavf_adapter *adapter = netdev_priv(netdev); |
d5b33d02 HR |
2706 | struct virtchnl_vf_resource *vfres = adapter->vf_res; |
2707 | u8 num_tc = 0, total_qps = 0; | |
2708 | int ret = 0, netdev_tc = 0; | |
591532d6 | 2709 | u64 max_tx_rate; |
d5b33d02 HR |
2710 | u16 mode; |
2711 | int i; | |
2712 | ||
2713 | num_tc = mqprio_qopt->qopt.num_tc; | |
2714 | mode = mqprio_qopt->mode; | |
2715 | ||
2716 | /* delete queue_channel */ | |
2717 | if (!mqprio_qopt->qopt.hw) { | |
129cf89e | 2718 | if (adapter->ch_config.state == __IAVF_TC_RUNNING) { |
d5b33d02 HR |
2719 | /* reset the tc configuration */ |
2720 | netdev_reset_tc(netdev); | |
2721 | adapter->num_tc = 0; | |
2722 | netif_tx_stop_all_queues(netdev); | |
2723 | netif_tx_disable(netdev); | |
129cf89e JB |
2724 | iavf_del_all_cloud_filters(adapter); |
2725 | adapter->aq_required = IAVF_FLAG_AQ_DISABLE_CHANNELS; | |
d5b33d02 HR |
2726 | goto exit; |
2727 | } else { | |
2728 | return -EINVAL; | |
2729 | } | |
2730 | } | |
2731 | ||
2732 | /* add queue channel */ | |
2733 | if (mode == TC_MQPRIO_MODE_CHANNEL) { | |
2734 | if (!(vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADQ)) { | |
2735 | dev_err(&adapter->pdev->dev, "ADq not supported\n"); | |
2736 | return -EOPNOTSUPP; | |
2737 | } | |
129cf89e | 2738 | if (adapter->ch_config.state != __IAVF_TC_INVALID) { |
d5b33d02 HR |
2739 | dev_err(&adapter->pdev->dev, "TC configuration already exists\n"); |
2740 | return -EINVAL; | |
2741 | } | |
2742 | ||
129cf89e | 2743 | ret = iavf_validate_ch_config(adapter, mqprio_qopt); |
d5b33d02 HR |
2744 | if (ret) |
2745 | return ret; | |
2746 | /* Return if same TC config is requested */ | |
2747 | if (adapter->num_tc == num_tc) | |
2748 | return 0; | |
2749 | adapter->num_tc = num_tc; | |
2750 | ||
129cf89e | 2751 | for (i = 0; i < IAVF_MAX_TRAFFIC_CLASS; i++) { |
d5b33d02 HR |
2752 | if (i < num_tc) { |
2753 | adapter->ch_config.ch_info[i].count = | |
2754 | mqprio_qopt->qopt.count[i]; | |
2755 | adapter->ch_config.ch_info[i].offset = | |
2756 | mqprio_qopt->qopt.offset[i]; | |
2757 | total_qps += mqprio_qopt->qopt.count[i]; | |
591532d6 HR |
2758 | max_tx_rate = mqprio_qopt->max_rate[i]; |
2759 | /* convert to Mbps */ | |
2760 | max_tx_rate = div_u64(max_tx_rate, | |
129cf89e | 2761 | IAVF_MBPS_DIVISOR); |
591532d6 HR |
2762 | adapter->ch_config.ch_info[i].max_tx_rate = |
2763 | max_tx_rate; | |
d5b33d02 HR |
2764 | } else { |
2765 | adapter->ch_config.ch_info[i].count = 1; | |
2766 | adapter->ch_config.ch_info[i].offset = 0; | |
2767 | } | |
2768 | } | |
2769 | adapter->ch_config.total_qps = total_qps; | |
2770 | netif_tx_stop_all_queues(netdev); | |
2771 | netif_tx_disable(netdev); | |
129cf89e | 2772 | adapter->aq_required |= IAVF_FLAG_AQ_ENABLE_CHANNELS; |
d5b33d02 HR |
2773 | netdev_reset_tc(netdev); |
2774 | /* Report the tc mapping up the stack */ | |
2775 | netdev_set_num_tc(adapter->netdev, num_tc); | |
129cf89e | 2776 | for (i = 0; i < IAVF_MAX_TRAFFIC_CLASS; i++) { |
d5b33d02 HR |
2777 | u16 qcount = mqprio_qopt->qopt.count[i]; |
2778 | u16 qoffset = mqprio_qopt->qopt.offset[i]; | |
2779 | ||
2780 | if (i < num_tc) | |
2781 | netdev_set_tc_queue(netdev, netdev_tc++, qcount, | |
2782 | qoffset); | |
2783 | } | |
2784 | } | |
2785 | exit: | |
2786 | return ret; | |
2787 | } | |
2788 | ||
0075fa0f | 2789 | /** |
129cf89e | 2790 | * iavf_parse_cls_flower - Parse tc flower filters provided by kernel |
0075fa0f | 2791 | * @adapter: board private structure |
b50f7bca | 2792 | * @f: pointer to struct flow_cls_offload |
0075fa0f HR |
2793 | * @filter: pointer to cloud filter structure |
2794 | */ | |
129cf89e | 2795 | static int iavf_parse_cls_flower(struct iavf_adapter *adapter, |
f9e30088 | 2796 | struct flow_cls_offload *f, |
129cf89e | 2797 | struct iavf_cloud_filter *filter) |
0075fa0f | 2798 | { |
f9e30088 | 2799 | struct flow_rule *rule = flow_cls_offload_flow_rule(f); |
8f256622 | 2800 | struct flow_dissector *dissector = rule->match.dissector; |
0075fa0f HR |
2801 | u16 n_proto_mask = 0; |
2802 | u16 n_proto_key = 0; | |
2803 | u8 field_flags = 0; | |
2804 | u16 addr_type = 0; | |
2805 | u16 n_proto = 0; | |
2806 | int i = 0; | |
deb9a9ad | 2807 | struct virtchnl_filter *vf = &filter->f; |
0075fa0f | 2808 | |
8f256622 | 2809 | if (dissector->used_keys & |
0075fa0f HR |
2810 | ~(BIT(FLOW_DISSECTOR_KEY_CONTROL) | |
2811 | BIT(FLOW_DISSECTOR_KEY_BASIC) | | |
2812 | BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) | | |
2813 | BIT(FLOW_DISSECTOR_KEY_VLAN) | | |
2814 | BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) | | |
2815 | BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) | | |
2816 | BIT(FLOW_DISSECTOR_KEY_PORTS) | | |
2817 | BIT(FLOW_DISSECTOR_KEY_ENC_KEYID))) { | |
2818 | dev_err(&adapter->pdev->dev, "Unsupported key used: 0x%x\n", | |
8f256622 | 2819 | dissector->used_keys); |
0075fa0f HR |
2820 | return -EOPNOTSUPP; |
2821 | } | |
2822 | ||
8f256622 PNA |
2823 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_KEYID)) { |
2824 | struct flow_match_enc_keyid match; | |
0075fa0f | 2825 | |
8f256622 PNA |
2826 | flow_rule_match_enc_keyid(rule, &match); |
2827 | if (match.mask->keyid != 0) | |
129cf89e | 2828 | field_flags |= IAVF_CLOUD_FIELD_TEN_ID; |
0075fa0f HR |
2829 | } |
2830 | ||
8f256622 PNA |
2831 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) { |
2832 | struct flow_match_basic match; | |
0075fa0f | 2833 | |
8f256622 PNA |
2834 | flow_rule_match_basic(rule, &match); |
2835 | n_proto_key = ntohs(match.key->n_proto); | |
2836 | n_proto_mask = ntohs(match.mask->n_proto); | |
0075fa0f HR |
2837 | |
2838 | if (n_proto_key == ETH_P_ALL) { | |
2839 | n_proto_key = 0; | |
2840 | n_proto_mask = 0; | |
2841 | } | |
2842 | n_proto = n_proto_key & n_proto_mask; | |
2843 | if (n_proto != ETH_P_IP && n_proto != ETH_P_IPV6) | |
2844 | return -EINVAL; | |
2845 | if (n_proto == ETH_P_IPV6) { | |
2846 | /* specify flow type as TCP IPv6 */ | |
deb9a9ad | 2847 | vf->flow_type = VIRTCHNL_TCP_V6_FLOW; |
0075fa0f HR |
2848 | } |
2849 | ||
8f256622 | 2850 | if (match.key->ip_proto != IPPROTO_TCP) { |
0075fa0f HR |
2851 | dev_info(&adapter->pdev->dev, "Only TCP transport is supported\n"); |
2852 | return -EINVAL; | |
2853 | } | |
2854 | } | |
2855 | ||
8f256622 PNA |
2856 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) { |
2857 | struct flow_match_eth_addrs match; | |
2858 | ||
2859 | flow_rule_match_eth_addrs(rule, &match); | |
0075fa0f | 2860 | |
0075fa0f | 2861 | /* use is_broadcast and is_zero to check for all 0xf or 0 */ |
8f256622 PNA |
2862 | if (!is_zero_ether_addr(match.mask->dst)) { |
2863 | if (is_broadcast_ether_addr(match.mask->dst)) { | |
129cf89e | 2864 | field_flags |= IAVF_CLOUD_FIELD_OMAC; |
0075fa0f HR |
2865 | } else { |
2866 | dev_err(&adapter->pdev->dev, "Bad ether dest mask %pM\n", | |
8f256622 | 2867 | match.mask->dst); |
8821b3fa | 2868 | return IAVF_ERR_CONFIG; |
0075fa0f HR |
2869 | } |
2870 | } | |
2871 | ||
8f256622 PNA |
2872 | if (!is_zero_ether_addr(match.mask->src)) { |
2873 | if (is_broadcast_ether_addr(match.mask->src)) { | |
129cf89e | 2874 | field_flags |= IAVF_CLOUD_FIELD_IMAC; |
0075fa0f HR |
2875 | } else { |
2876 | dev_err(&adapter->pdev->dev, "Bad ether src mask %pM\n", | |
8f256622 | 2877 | match.mask->src); |
8821b3fa | 2878 | return IAVF_ERR_CONFIG; |
0075fa0f HR |
2879 | } |
2880 | } | |
2881 | ||
8f256622 PNA |
2882 | if (!is_zero_ether_addr(match.key->dst)) |
2883 | if (is_valid_ether_addr(match.key->dst) || | |
2884 | is_multicast_ether_addr(match.key->dst)) { | |
0075fa0f HR |
2885 | /* set the mask if a valid dst_mac address */ |
2886 | for (i = 0; i < ETH_ALEN; i++) | |
deb9a9ad CIK |
2887 | vf->mask.tcp_spec.dst_mac[i] |= 0xff; |
2888 | ether_addr_copy(vf->data.tcp_spec.dst_mac, | |
8f256622 | 2889 | match.key->dst); |
0075fa0f HR |
2890 | } |
2891 | ||
8f256622 PNA |
2892 | if (!is_zero_ether_addr(match.key->src)) |
2893 | if (is_valid_ether_addr(match.key->src) || | |
2894 | is_multicast_ether_addr(match.key->src)) { | |
0075fa0f HR |
2895 | /* set the mask if a valid dst_mac address */ |
2896 | for (i = 0; i < ETH_ALEN; i++) | |
deb9a9ad CIK |
2897 | vf->mask.tcp_spec.src_mac[i] |= 0xff; |
2898 | ether_addr_copy(vf->data.tcp_spec.src_mac, | |
8f256622 | 2899 | match.key->src); |
0075fa0f HR |
2900 | } |
2901 | } | |
2902 | ||
8f256622 PNA |
2903 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_VLAN)) { |
2904 | struct flow_match_vlan match; | |
0075fa0f | 2905 | |
8f256622 PNA |
2906 | flow_rule_match_vlan(rule, &match); |
2907 | if (match.mask->vlan_id) { | |
2908 | if (match.mask->vlan_id == VLAN_VID_MASK) { | |
129cf89e | 2909 | field_flags |= IAVF_CLOUD_FIELD_IVLAN; |
0075fa0f HR |
2910 | } else { |
2911 | dev_err(&adapter->pdev->dev, "Bad vlan mask %u\n", | |
8f256622 | 2912 | match.mask->vlan_id); |
8821b3fa | 2913 | return IAVF_ERR_CONFIG; |
0075fa0f HR |
2914 | } |
2915 | } | |
deb9a9ad | 2916 | vf->mask.tcp_spec.vlan_id |= cpu_to_be16(0xffff); |
8f256622 | 2917 | vf->data.tcp_spec.vlan_id = cpu_to_be16(match.key->vlan_id); |
0075fa0f HR |
2918 | } |
2919 | ||
8f256622 PNA |
2920 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) { |
2921 | struct flow_match_control match; | |
0075fa0f | 2922 | |
8f256622 PNA |
2923 | flow_rule_match_control(rule, &match); |
2924 | addr_type = match.key->addr_type; | |
0075fa0f HR |
2925 | } |
2926 | ||
2927 | if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) { | |
8f256622 PNA |
2928 | struct flow_match_ipv4_addrs match; |
2929 | ||
2930 | flow_rule_match_ipv4_addrs(rule, &match); | |
2931 | if (match.mask->dst) { | |
2932 | if (match.mask->dst == cpu_to_be32(0xffffffff)) { | |
129cf89e | 2933 | field_flags |= IAVF_CLOUD_FIELD_IIP; |
0075fa0f HR |
2934 | } else { |
2935 | dev_err(&adapter->pdev->dev, "Bad ip dst mask 0x%08x\n", | |
8f256622 | 2936 | be32_to_cpu(match.mask->dst)); |
8821b3fa | 2937 | return IAVF_ERR_CONFIG; |
0075fa0f HR |
2938 | } |
2939 | } | |
2940 | ||
8f256622 PNA |
2941 | if (match.mask->src) { |
2942 | if (match.mask->src == cpu_to_be32(0xffffffff)) { | |
129cf89e | 2943 | field_flags |= IAVF_CLOUD_FIELD_IIP; |
0075fa0f HR |
2944 | } else { |
2945 | dev_err(&adapter->pdev->dev, "Bad ip src mask 0x%08x\n", | |
8f256622 | 2946 | be32_to_cpu(match.mask->dst)); |
8821b3fa | 2947 | return IAVF_ERR_CONFIG; |
0075fa0f HR |
2948 | } |
2949 | } | |
2950 | ||
129cf89e | 2951 | if (field_flags & IAVF_CLOUD_FIELD_TEN_ID) { |
0075fa0f | 2952 | dev_info(&adapter->pdev->dev, "Tenant id not allowed for ip filter\n"); |
8821b3fa | 2953 | return IAVF_ERR_CONFIG; |
0075fa0f | 2954 | } |
8f256622 | 2955 | if (match.key->dst) { |
deb9a9ad | 2956 | vf->mask.tcp_spec.dst_ip[0] |= cpu_to_be32(0xffffffff); |
8f256622 | 2957 | vf->data.tcp_spec.dst_ip[0] = match.key->dst; |
0075fa0f | 2958 | } |
8f256622 | 2959 | if (match.key->src) { |
deb9a9ad | 2960 | vf->mask.tcp_spec.src_ip[0] |= cpu_to_be32(0xffffffff); |
8f256622 | 2961 | vf->data.tcp_spec.src_ip[0] = match.key->src; |
0075fa0f HR |
2962 | } |
2963 | } | |
2964 | ||
2965 | if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) { | |
8f256622 PNA |
2966 | struct flow_match_ipv6_addrs match; |
2967 | ||
2968 | flow_rule_match_ipv6_addrs(rule, &match); | |
0075fa0f HR |
2969 | |
2970 | /* validate mask, make sure it is not IPV6_ADDR_ANY */ | |
8f256622 | 2971 | if (ipv6_addr_any(&match.mask->dst)) { |
0075fa0f HR |
2972 | dev_err(&adapter->pdev->dev, "Bad ipv6 dst mask 0x%02x\n", |
2973 | IPV6_ADDR_ANY); | |
8821b3fa | 2974 | return IAVF_ERR_CONFIG; |
0075fa0f HR |
2975 | } |
2976 | ||
2977 | /* src and dest IPv6 address should not be LOOPBACK | |
2978 | * (0:0:0:0:0:0:0:1) which can be represented as ::1 | |
2979 | */ | |
8f256622 PNA |
2980 | if (ipv6_addr_loopback(&match.key->dst) || |
2981 | ipv6_addr_loopback(&match.key->src)) { | |
0075fa0f HR |
2982 | dev_err(&adapter->pdev->dev, |
2983 | "ipv6 addr should not be loopback\n"); | |
8821b3fa | 2984 | return IAVF_ERR_CONFIG; |
0075fa0f | 2985 | } |
8f256622 PNA |
2986 | if (!ipv6_addr_any(&match.mask->dst) || |
2987 | !ipv6_addr_any(&match.mask->src)) | |
129cf89e | 2988 | field_flags |= IAVF_CLOUD_FIELD_IIP; |
0075fa0f | 2989 | |
deb9a9ad CIK |
2990 | for (i = 0; i < 4; i++) |
2991 | vf->mask.tcp_spec.dst_ip[i] |= cpu_to_be32(0xffffffff); | |
8f256622 | 2992 | memcpy(&vf->data.tcp_spec.dst_ip, &match.key->dst.s6_addr32, |
deb9a9ad CIK |
2993 | sizeof(vf->data.tcp_spec.dst_ip)); |
2994 | for (i = 0; i < 4; i++) | |
2995 | vf->mask.tcp_spec.src_ip[i] |= cpu_to_be32(0xffffffff); | |
8f256622 | 2996 | memcpy(&vf->data.tcp_spec.src_ip, &match.key->src.s6_addr32, |
deb9a9ad | 2997 | sizeof(vf->data.tcp_spec.src_ip)); |
0075fa0f | 2998 | } |
8f256622 PNA |
2999 | if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS)) { |
3000 | struct flow_match_ports match; | |
3001 | ||
3002 | flow_rule_match_ports(rule, &match); | |
3003 | if (match.mask->src) { | |
3004 | if (match.mask->src == cpu_to_be16(0xffff)) { | |
129cf89e | 3005 | field_flags |= IAVF_CLOUD_FIELD_IIP; |
0075fa0f HR |
3006 | } else { |
3007 | dev_err(&adapter->pdev->dev, "Bad src port mask %u\n", | |
8f256622 | 3008 | be16_to_cpu(match.mask->src)); |
8821b3fa | 3009 | return IAVF_ERR_CONFIG; |
0075fa0f HR |
3010 | } |
3011 | } | |
3012 | ||
8f256622 PNA |
3013 | if (match.mask->dst) { |
3014 | if (match.mask->dst == cpu_to_be16(0xffff)) { | |
129cf89e | 3015 | field_flags |= IAVF_CLOUD_FIELD_IIP; |
0075fa0f HR |
3016 | } else { |
3017 | dev_err(&adapter->pdev->dev, "Bad dst port mask %u\n", | |
8f256622 | 3018 | be16_to_cpu(match.mask->dst)); |
8821b3fa | 3019 | return IAVF_ERR_CONFIG; |
0075fa0f HR |
3020 | } |
3021 | } | |
8f256622 | 3022 | if (match.key->dst) { |
deb9a9ad | 3023 | vf->mask.tcp_spec.dst_port |= cpu_to_be16(0xffff); |
8f256622 | 3024 | vf->data.tcp_spec.dst_port = match.key->dst; |
0075fa0f HR |
3025 | } |
3026 | ||
8f256622 | 3027 | if (match.key->src) { |
deb9a9ad | 3028 | vf->mask.tcp_spec.src_port |= cpu_to_be16(0xffff); |
8f256622 | 3029 | vf->data.tcp_spec.src_port = match.key->src; |
0075fa0f HR |
3030 | } |
3031 | } | |
deb9a9ad | 3032 | vf->field_flags = field_flags; |
0075fa0f HR |
3033 | |
3034 | return 0; | |
3035 | } | |
3036 | ||
3037 | /** | |
129cf89e | 3038 | * iavf_handle_tclass - Forward to a traffic class on the device |
0075fa0f HR |
3039 | * @adapter: board private structure |
3040 | * @tc: traffic class index on the device | |
3041 | * @filter: pointer to cloud filter structure | |
3042 | */ | |
129cf89e JB |
3043 | static int iavf_handle_tclass(struct iavf_adapter *adapter, u32 tc, |
3044 | struct iavf_cloud_filter *filter) | |
0075fa0f HR |
3045 | { |
3046 | if (tc == 0) | |
3047 | return 0; | |
3048 | if (tc < adapter->num_tc) { | |
3049 | if (!filter->f.data.tcp_spec.dst_port) { | |
3050 | dev_err(&adapter->pdev->dev, | |
3051 | "Specify destination port to redirect to traffic class other than TC0\n"); | |
3052 | return -EINVAL; | |
3053 | } | |
3054 | } | |
3055 | /* redirect to a traffic class on the same device */ | |
3056 | filter->f.action = VIRTCHNL_ACTION_TC_REDIRECT; | |
3057 | filter->f.action_meta = tc; | |
3058 | return 0; | |
3059 | } | |
3060 | ||
3061 | /** | |
129cf89e | 3062 | * iavf_configure_clsflower - Add tc flower filters |
0075fa0f | 3063 | * @adapter: board private structure |
f9e30088 | 3064 | * @cls_flower: Pointer to struct flow_cls_offload |
0075fa0f | 3065 | */ |
129cf89e | 3066 | static int iavf_configure_clsflower(struct iavf_adapter *adapter, |
f9e30088 | 3067 | struct flow_cls_offload *cls_flower) |
0075fa0f HR |
3068 | { |
3069 | int tc = tc_classid_to_hwtc(adapter->netdev, cls_flower->classid); | |
129cf89e | 3070 | struct iavf_cloud_filter *filter = NULL; |
640a8af5 | 3071 | int err = -EINVAL, count = 50; |
0075fa0f HR |
3072 | |
3073 | if (tc < 0) { | |
3074 | dev_err(&adapter->pdev->dev, "Invalid traffic class\n"); | |
3075 | return -EINVAL; | |
3076 | } | |
3077 | ||
3078 | filter = kzalloc(sizeof(*filter), GFP_KERNEL); | |
640a8af5 AD |
3079 | if (!filter) |
3080 | return -ENOMEM; | |
3081 | ||
5ac49f3c | 3082 | while (!mutex_trylock(&adapter->crit_lock)) { |
3e269413 NN |
3083 | if (--count == 0) { |
3084 | kfree(filter); | |
3085 | return err; | |
3086 | } | |
640a8af5 | 3087 | udelay(1); |
0075fa0f | 3088 | } |
640a8af5 | 3089 | |
0075fa0f HR |
3090 | filter->cookie = cls_flower->cookie; |
3091 | ||
3092 | /* set the mask to all zeroes to begin with */ | |
3093 | memset(&filter->f.mask.tcp_spec, 0, sizeof(struct virtchnl_l4_spec)); | |
3094 | /* start out with flow type and eth type IPv4 to begin with */ | |
3095 | filter->f.flow_type = VIRTCHNL_TCP_V4_FLOW; | |
129cf89e | 3096 | err = iavf_parse_cls_flower(adapter, cls_flower, filter); |
b267ce84 | 3097 | if (err) |
0075fa0f HR |
3098 | goto err; |
3099 | ||
129cf89e | 3100 | err = iavf_handle_tclass(adapter, tc, filter); |
b267ce84 | 3101 | if (err) |
0075fa0f HR |
3102 | goto err; |
3103 | ||
3104 | /* add filter to the list */ | |
3105 | spin_lock_bh(&adapter->cloud_filter_list_lock); | |
3106 | list_add_tail(&filter->list, &adapter->cloud_filter_list); | |
3107 | adapter->num_cloud_filters++; | |
3108 | filter->add = true; | |
129cf89e | 3109 | adapter->aq_required |= IAVF_FLAG_AQ_ADD_CLOUD_FILTER; |
0075fa0f HR |
3110 | spin_unlock_bh(&adapter->cloud_filter_list_lock); |
3111 | err: | |
3112 | if (err) | |
3113 | kfree(filter); | |
640a8af5 | 3114 | |
5ac49f3c | 3115 | mutex_unlock(&adapter->crit_lock); |
0075fa0f HR |
3116 | return err; |
3117 | } | |
3118 | ||
129cf89e | 3119 | /* iavf_find_cf - Find the cloud filter in the list |
0075fa0f HR |
3120 | * @adapter: Board private structure |
3121 | * @cookie: filter specific cookie | |
3122 | * | |
3123 | * Returns ptr to the filter object or NULL. Must be called while holding the | |
3124 | * cloud_filter_list_lock. | |
3125 | */ | |
129cf89e JB |
3126 | static struct iavf_cloud_filter *iavf_find_cf(struct iavf_adapter *adapter, |
3127 | unsigned long *cookie) | |
0075fa0f | 3128 | { |
129cf89e | 3129 | struct iavf_cloud_filter *filter = NULL; |
0075fa0f HR |
3130 | |
3131 | if (!cookie) | |
3132 | return NULL; | |
3133 | ||
3134 | list_for_each_entry(filter, &adapter->cloud_filter_list, list) { | |
3135 | if (!memcmp(cookie, &filter->cookie, sizeof(filter->cookie))) | |
3136 | return filter; | |
3137 | } | |
3138 | return NULL; | |
3139 | } | |
3140 | ||
3141 | /** | |
129cf89e | 3142 | * iavf_delete_clsflower - Remove tc flower filters |
0075fa0f | 3143 | * @adapter: board private structure |
f9e30088 | 3144 | * @cls_flower: Pointer to struct flow_cls_offload |
0075fa0f | 3145 | */ |
129cf89e | 3146 | static int iavf_delete_clsflower(struct iavf_adapter *adapter, |
f9e30088 | 3147 | struct flow_cls_offload *cls_flower) |
0075fa0f | 3148 | { |
129cf89e | 3149 | struct iavf_cloud_filter *filter = NULL; |
0075fa0f HR |
3150 | int err = 0; |
3151 | ||
3152 | spin_lock_bh(&adapter->cloud_filter_list_lock); | |
129cf89e | 3153 | filter = iavf_find_cf(adapter, &cls_flower->cookie); |
0075fa0f HR |
3154 | if (filter) { |
3155 | filter->del = true; | |
129cf89e | 3156 | adapter->aq_required |= IAVF_FLAG_AQ_DEL_CLOUD_FILTER; |
0075fa0f HR |
3157 | } else { |
3158 | err = -EINVAL; | |
3159 | } | |
3160 | spin_unlock_bh(&adapter->cloud_filter_list_lock); | |
3161 | ||
3162 | return err; | |
3163 | } | |
3164 | ||
3165 | /** | |
129cf89e | 3166 | * iavf_setup_tc_cls_flower - flower classifier offloads |
b50f7bca JB |
3167 | * @adapter: board private structure |
3168 | * @cls_flower: pointer to flow_cls_offload struct with flow info | |
0075fa0f | 3169 | */ |
129cf89e | 3170 | static int iavf_setup_tc_cls_flower(struct iavf_adapter *adapter, |
f9e30088 | 3171 | struct flow_cls_offload *cls_flower) |
0075fa0f | 3172 | { |
0075fa0f | 3173 | switch (cls_flower->command) { |
f9e30088 | 3174 | case FLOW_CLS_REPLACE: |
129cf89e | 3175 | return iavf_configure_clsflower(adapter, cls_flower); |
f9e30088 | 3176 | case FLOW_CLS_DESTROY: |
129cf89e | 3177 | return iavf_delete_clsflower(adapter, cls_flower); |
f9e30088 | 3178 | case FLOW_CLS_STATS: |
0075fa0f HR |
3179 | return -EOPNOTSUPP; |
3180 | default: | |
246ab6f0 | 3181 | return -EOPNOTSUPP; |
0075fa0f HR |
3182 | } |
3183 | } | |
3184 | ||
3185 | /** | |
129cf89e | 3186 | * iavf_setup_tc_block_cb - block callback for tc |
0075fa0f HR |
3187 | * @type: type of offload |
3188 | * @type_data: offload data | |
3189 | * @cb_priv: | |
3190 | * | |
3191 | * This function is the block callback for traffic classes | |
3192 | **/ | |
129cf89e JB |
3193 | static int iavf_setup_tc_block_cb(enum tc_setup_type type, void *type_data, |
3194 | void *cb_priv) | |
0075fa0f | 3195 | { |
bb0858d8 JP |
3196 | struct iavf_adapter *adapter = cb_priv; |
3197 | ||
3198 | if (!tc_cls_can_offload_and_chain0(adapter->netdev, type_data)) | |
3199 | return -EOPNOTSUPP; | |
3200 | ||
0075fa0f HR |
3201 | switch (type) { |
3202 | case TC_SETUP_CLSFLOWER: | |
129cf89e | 3203 | return iavf_setup_tc_cls_flower(cb_priv, type_data); |
0075fa0f HR |
3204 | default: |
3205 | return -EOPNOTSUPP; | |
3206 | } | |
3207 | } | |
3208 | ||
955bcb6e PNA |
3209 | static LIST_HEAD(iavf_block_cb_list); |
3210 | ||
d5b33d02 | 3211 | /** |
129cf89e | 3212 | * iavf_setup_tc - configure multiple traffic classes |
d5b33d02 HR |
3213 | * @netdev: network interface device structure |
3214 | * @type: type of offload | |
b50f7bca | 3215 | * @type_data: tc offload data |
d5b33d02 HR |
3216 | * |
3217 | * This function is the callback to ndo_setup_tc in the | |
3218 | * netdev_ops. | |
3219 | * | |
3220 | * Returns 0 on success | |
3221 | **/ | |
129cf89e JB |
3222 | static int iavf_setup_tc(struct net_device *netdev, enum tc_setup_type type, |
3223 | void *type_data) | |
d5b33d02 | 3224 | { |
4e95bc26 PNA |
3225 | struct iavf_adapter *adapter = netdev_priv(netdev); |
3226 | ||
0075fa0f HR |
3227 | switch (type) { |
3228 | case TC_SETUP_QDISC_MQPRIO: | |
129cf89e | 3229 | return __iavf_setup_tc(netdev, type_data); |
0075fa0f | 3230 | case TC_SETUP_BLOCK: |
955bcb6e PNA |
3231 | return flow_block_cb_setup_simple(type_data, |
3232 | &iavf_block_cb_list, | |
4e95bc26 PNA |
3233 | iavf_setup_tc_block_cb, |
3234 | adapter, adapter, true); | |
0075fa0f | 3235 | default: |
d5b33d02 | 3236 | return -EOPNOTSUPP; |
0075fa0f | 3237 | } |
d5b33d02 HR |
3238 | } |
3239 | ||
5eae00c5 | 3240 | /** |
129cf89e | 3241 | * iavf_open - Called when a network interface is made active |
5eae00c5 GR |
3242 | * @netdev: network interface device structure |
3243 | * | |
3244 | * Returns 0 on success, negative value on failure | |
3245 | * | |
3246 | * The open entry point is called when a network interface is made | |
3247 | * active by the system (IFF_UP). At this point all resources needed | |
3248 | * for transmit and receive operations are allocated, the interrupt | |
fdd4044f | 3249 | * handler is registered with the OS, the watchdog is started, |
5eae00c5 GR |
3250 | * and the stack is notified that the interface is ready. |
3251 | **/ | |
129cf89e | 3252 | static int iavf_open(struct net_device *netdev) |
5eae00c5 | 3253 | { |
129cf89e | 3254 | struct iavf_adapter *adapter = netdev_priv(netdev); |
5eae00c5 GR |
3255 | int err; |
3256 | ||
129cf89e | 3257 | if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED) { |
ef8693eb MW |
3258 | dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n"); |
3259 | return -EIO; | |
3260 | } | |
209dc4da | 3261 | |
5ac49f3c | 3262 | while (!mutex_trylock(&adapter->crit_lock)) |
9b2aef12 JK |
3263 | usleep_range(500, 1000); |
3264 | ||
129cf89e | 3265 | if (adapter->state != __IAVF_DOWN) { |
9b2aef12 JK |
3266 | err = -EBUSY; |
3267 | goto err_unlock; | |
3268 | } | |
5eae00c5 GR |
3269 | |
3270 | /* allocate transmit descriptors */ | |
129cf89e | 3271 | err = iavf_setup_all_tx_resources(adapter); |
5eae00c5 GR |
3272 | if (err) |
3273 | goto err_setup_tx; | |
3274 | ||
3275 | /* allocate receive descriptors */ | |
129cf89e | 3276 | err = iavf_setup_all_rx_resources(adapter); |
5eae00c5 GR |
3277 | if (err) |
3278 | goto err_setup_rx; | |
3279 | ||
3280 | /* clear any pending interrupts, may auto mask */ | |
129cf89e | 3281 | err = iavf_request_traffic_irqs(adapter, netdev->name); |
5eae00c5 GR |
3282 | if (err) |
3283 | goto err_req_irq; | |
3284 | ||
8cd5fe62 PJ |
3285 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
3286 | ||
129cf89e | 3287 | iavf_add_filter(adapter, adapter->hw.mac.addr); |
8cd5fe62 PJ |
3288 | |
3289 | spin_unlock_bh(&adapter->mac_vlan_list_lock); | |
3290 | ||
1f36185d AA |
3291 | /* Restore VLAN filters that were removed with IFF_DOWN */ |
3292 | iavf_restore_filters(adapter); | |
3293 | ||
129cf89e | 3294 | iavf_configure(adapter); |
5eae00c5 | 3295 | |
129cf89e | 3296 | iavf_up_complete(adapter); |
5eae00c5 | 3297 | |
129cf89e | 3298 | iavf_irq_enable(adapter, true); |
5eae00c5 | 3299 | |
5ac49f3c | 3300 | mutex_unlock(&adapter->crit_lock); |
9b2aef12 | 3301 | |
5eae00c5 GR |
3302 | return 0; |
3303 | ||
3304 | err_req_irq: | |
129cf89e JB |
3305 | iavf_down(adapter); |
3306 | iavf_free_traffic_irqs(adapter); | |
5eae00c5 | 3307 | err_setup_rx: |
129cf89e | 3308 | iavf_free_all_rx_resources(adapter); |
5eae00c5 | 3309 | err_setup_tx: |
129cf89e | 3310 | iavf_free_all_tx_resources(adapter); |
9b2aef12 | 3311 | err_unlock: |
5ac49f3c | 3312 | mutex_unlock(&adapter->crit_lock); |
5eae00c5 GR |
3313 | |
3314 | return err; | |
3315 | } | |
3316 | ||
3317 | /** | |
129cf89e | 3318 | * iavf_close - Disables a network interface |
5eae00c5 GR |
3319 | * @netdev: network interface device structure |
3320 | * | |
3321 | * Returns 0, this is not allowed to fail | |
3322 | * | |
3323 | * The close entry point is called when an interface is de-activated | |
3324 | * by the OS. The hardware is still under the drivers control, but | |
3325 | * needs to be disabled. All IRQs except vector 0 (reserved for admin queue) | |
3326 | * are freed, along with all transmit and receive resources. | |
3327 | **/ | |
129cf89e | 3328 | static int iavf_close(struct net_device *netdev) |
5eae00c5 | 3329 | { |
129cf89e | 3330 | struct iavf_adapter *adapter = netdev_priv(netdev); |
fe2647ab | 3331 | int status; |
5eae00c5 | 3332 | |
129cf89e | 3333 | if (adapter->state <= __IAVF_DOWN_PENDING) |
ef8693eb MW |
3334 | return 0; |
3335 | ||
5ac49f3c | 3336 | while (!mutex_trylock(&adapter->crit_lock)) |
9b2aef12 | 3337 | usleep_range(500, 1000); |
ef8693eb | 3338 | |
56184e01 | 3339 | set_bit(__IAVF_VSI_DOWN, adapter->vsi.state); |
ed0e894d | 3340 | if (CLIENT_ENABLED(adapter)) |
129cf89e | 3341 | adapter->flags |= IAVF_FLAG_CLIENT_NEEDS_CLOSE; |
5eae00c5 | 3342 | |
129cf89e JB |
3343 | iavf_down(adapter); |
3344 | adapter->state = __IAVF_DOWN_PENDING; | |
3345 | iavf_free_traffic_irqs(adapter); | |
5eae00c5 | 3346 | |
5ac49f3c | 3347 | mutex_unlock(&adapter->crit_lock); |
9b2aef12 | 3348 | |
51f38262 MW |
3349 | /* We explicitly don't free resources here because the hardware is |
3350 | * still active and can DMA into memory. Resources are cleared in | |
129cf89e | 3351 | * iavf_virtchnl_completion() after we get confirmation from the PF |
51f38262 | 3352 | * driver that the rings have been stopped. |
fe2647ab | 3353 | * |
129cf89e JB |
3354 | * Also, we wait for state to transition to __IAVF_DOWN before |
3355 | * returning. State change occurs in iavf_virtchnl_completion() after | |
fe2647ab SM |
3356 | * VF resources are released (which occurs after PF driver processes and |
3357 | * responds to admin queue commands). | |
51f38262 | 3358 | */ |
fe2647ab SM |
3359 | |
3360 | status = wait_event_timeout(adapter->down_waitqueue, | |
129cf89e | 3361 | adapter->state == __IAVF_DOWN, |
88ec7308 | 3362 | msecs_to_jiffies(500)); |
fe2647ab SM |
3363 | if (!status) |
3364 | netdev_warn(netdev, "Device resources not yet released\n"); | |
5eae00c5 GR |
3365 | return 0; |
3366 | } | |
3367 | ||
5eae00c5 | 3368 | /** |
129cf89e | 3369 | * iavf_change_mtu - Change the Maximum Transfer Unit |
5eae00c5 GR |
3370 | * @netdev: network interface device structure |
3371 | * @new_mtu: new value for maximum frame size | |
3372 | * | |
3373 | * Returns 0 on success, negative on failure | |
3374 | **/ | |
129cf89e | 3375 | static int iavf_change_mtu(struct net_device *netdev, int new_mtu) |
5eae00c5 | 3376 | { |
129cf89e | 3377 | struct iavf_adapter *adapter = netdev_priv(netdev); |
5eae00c5 | 3378 | |
5eae00c5 | 3379 | netdev->mtu = new_mtu; |
ed0e894d | 3380 | if (CLIENT_ENABLED(adapter)) { |
129cf89e JB |
3381 | iavf_notify_client_l2_params(&adapter->vsi); |
3382 | adapter->flags |= IAVF_FLAG_SERVICE_CLIENT_REQUESTED; | |
ed0e894d | 3383 | } |
129cf89e | 3384 | adapter->flags |= IAVF_FLAG_RESET_NEEDED; |
fdd4044f | 3385 | queue_work(iavf_wq, &adapter->reset_task); |
67c818a1 | 3386 | |
5eae00c5 GR |
3387 | return 0; |
3388 | } | |
3389 | ||
8774370d | 3390 | /** |
56184e01 | 3391 | * iavf_set_features - set the netdev feature flags |
8774370d MS |
3392 | * @netdev: ptr to the netdev being adjusted |
3393 | * @features: the feature set that the stack is suggesting | |
3394 | * Note: expects to be called while under rtnl_lock() | |
3395 | **/ | |
129cf89e JB |
3396 | static int iavf_set_features(struct net_device *netdev, |
3397 | netdev_features_t features) | |
8774370d | 3398 | { |
129cf89e | 3399 | struct iavf_adapter *adapter = netdev_priv(netdev); |
8774370d | 3400 | |
3bd77e2a PM |
3401 | /* Don't allow changing VLAN_RX flag when adapter is not capable |
3402 | * of VLAN offload | |
e0f60a81 | 3403 | */ |
3bd77e2a PM |
3404 | if (!VLAN_ALLOWED(adapter)) { |
3405 | if ((netdev->features ^ features) & NETIF_F_HW_VLAN_CTAG_RX) | |
3406 | return -EINVAL; | |
3407 | } else if ((netdev->features ^ features) & NETIF_F_HW_VLAN_CTAG_RX) { | |
e0f60a81 PJ |
3408 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
3409 | adapter->aq_required |= | |
129cf89e | 3410 | IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING; |
e0f60a81 PJ |
3411 | else |
3412 | adapter->aq_required |= | |
129cf89e | 3413 | IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING; |
e0f60a81 | 3414 | } |
8774370d MS |
3415 | |
3416 | return 0; | |
3417 | } | |
3418 | ||
06fc016c | 3419 | /** |
129cf89e | 3420 | * iavf_features_check - Validate encapsulated packet conforms to limits |
06fc016c | 3421 | * @skb: skb buff |
f5254429 | 3422 | * @dev: This physical port's netdev |
06fc016c AD |
3423 | * @features: Offload features that the stack believes apply |
3424 | **/ | |
129cf89e JB |
3425 | static netdev_features_t iavf_features_check(struct sk_buff *skb, |
3426 | struct net_device *dev, | |
3427 | netdev_features_t features) | |
06fc016c AD |
3428 | { |
3429 | size_t len; | |
3430 | ||
3431 | /* No point in doing any of this if neither checksum nor GSO are | |
3432 | * being requested for this frame. We can rule out both by just | |
3433 | * checking for CHECKSUM_PARTIAL | |
3434 | */ | |
3435 | if (skb->ip_summed != CHECKSUM_PARTIAL) | |
3436 | return features; | |
3437 | ||
3438 | /* We cannot support GSO if the MSS is going to be less than | |
3439 | * 64 bytes. If it is then we need to drop support for GSO. | |
3440 | */ | |
3441 | if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64)) | |
3442 | features &= ~NETIF_F_GSO_MASK; | |
3443 | ||
3444 | /* MACLEN can support at most 63 words */ | |
3445 | len = skb_network_header(skb) - skb->data; | |
3446 | if (len & ~(63 * 2)) | |
3447 | goto out_err; | |
3448 | ||
3449 | /* IPLEN and EIPLEN can support at most 127 dwords */ | |
3450 | len = skb_transport_header(skb) - skb_network_header(skb); | |
3451 | if (len & ~(127 * 4)) | |
3452 | goto out_err; | |
3453 | ||
3454 | if (skb->encapsulation) { | |
3455 | /* L4TUNLEN can support 127 words */ | |
3456 | len = skb_inner_network_header(skb) - skb_transport_header(skb); | |
3457 | if (len & ~(127 * 2)) | |
3458 | goto out_err; | |
3459 | ||
3460 | /* IPLEN can support at most 127 dwords */ | |
3461 | len = skb_inner_transport_header(skb) - | |
3462 | skb_inner_network_header(skb); | |
3463 | if (len & ~(127 * 4)) | |
3464 | goto out_err; | |
3465 | } | |
3466 | ||
3467 | /* No need to validate L4LEN as TCP is the only protocol with a | |
3468 | * a flexible value and we support all possible values supported | |
3469 | * by TCP, which is at most 15 dwords | |
3470 | */ | |
3471 | ||
3472 | return features; | |
3473 | out_err: | |
3474 | return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); | |
3475 | } | |
3476 | ||
c4445aed | 3477 | /** |
129cf89e | 3478 | * iavf_fix_features - fix up the netdev feature bits |
c4445aed MW |
3479 | * @netdev: our net device |
3480 | * @features: desired feature bits | |
3481 | * | |
3482 | * Returns fixed-up features bits | |
3483 | **/ | |
129cf89e JB |
3484 | static netdev_features_t iavf_fix_features(struct net_device *netdev, |
3485 | netdev_features_t features) | |
c4445aed | 3486 | { |
129cf89e | 3487 | struct iavf_adapter *adapter = netdev_priv(netdev); |
c4445aed | 3488 | |
cba429c6 NN |
3489 | if (adapter->vf_res && |
3490 | !(adapter->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN)) | |
0a3b4f70 JK |
3491 | features &= ~(NETIF_F_HW_VLAN_CTAG_TX | |
3492 | NETIF_F_HW_VLAN_CTAG_RX | | |
3493 | NETIF_F_HW_VLAN_CTAG_FILTER); | |
3494 | ||
c4445aed MW |
3495 | return features; |
3496 | } | |
3497 | ||
129cf89e JB |
3498 | static const struct net_device_ops iavf_netdev_ops = { |
3499 | .ndo_open = iavf_open, | |
3500 | .ndo_stop = iavf_close, | |
3501 | .ndo_start_xmit = iavf_xmit_frame, | |
3502 | .ndo_set_rx_mode = iavf_set_rx_mode, | |
5eae00c5 | 3503 | .ndo_validate_addr = eth_validate_addr, |
129cf89e JB |
3504 | .ndo_set_mac_address = iavf_set_mac, |
3505 | .ndo_change_mtu = iavf_change_mtu, | |
3506 | .ndo_tx_timeout = iavf_tx_timeout, | |
3507 | .ndo_vlan_rx_add_vid = iavf_vlan_rx_add_vid, | |
3508 | .ndo_vlan_rx_kill_vid = iavf_vlan_rx_kill_vid, | |
3509 | .ndo_features_check = iavf_features_check, | |
3510 | .ndo_fix_features = iavf_fix_features, | |
3511 | .ndo_set_features = iavf_set_features, | |
129cf89e | 3512 | .ndo_setup_tc = iavf_setup_tc, |
5eae00c5 GR |
3513 | }; |
3514 | ||
3515 | /** | |
129cf89e | 3516 | * iavf_check_reset_complete - check that VF reset is complete |
5eae00c5 GR |
3517 | * @hw: pointer to hw struct |
3518 | * | |
3519 | * Returns 0 if device is ready to use, or -EBUSY if it's in reset. | |
3520 | **/ | |
f349daa5 | 3521 | static int iavf_check_reset_complete(struct iavf_hw *hw) |
5eae00c5 GR |
3522 | { |
3523 | u32 rstat; | |
3524 | int i; | |
3525 | ||
8e3e4b9d | 3526 | for (i = 0; i < IAVF_RESET_WAIT_COMPLETE_COUNT; i++) { |
f1cad2ce JB |
3527 | rstat = rd32(hw, IAVF_VFGEN_RSTAT) & |
3528 | IAVF_VFGEN_RSTAT_VFR_STATE_MASK; | |
310a2ad9 JB |
3529 | if ((rstat == VIRTCHNL_VFR_VFACTIVE) || |
3530 | (rstat == VIRTCHNL_VFR_COMPLETED)) | |
5eae00c5 | 3531 | return 0; |
f98a2006 | 3532 | usleep_range(10, 20); |
5eae00c5 GR |
3533 | } |
3534 | return -EBUSY; | |
3535 | } | |
3536 | ||
e6d038de | 3537 | /** |
129cf89e | 3538 | * iavf_process_config - Process the config information we got from the PF |
e6d038de MW |
3539 | * @adapter: board private structure |
3540 | * | |
3541 | * Verify that we have a valid config struct, and set up our netdev features | |
3542 | * and our VSI struct. | |
3543 | **/ | |
129cf89e | 3544 | int iavf_process_config(struct iavf_adapter *adapter) |
e6d038de | 3545 | { |
310a2ad9 | 3546 | struct virtchnl_vf_resource *vfres = adapter->vf_res; |
5b36e8d0 | 3547 | int i, num_req_queues = adapter->num_req_queues; |
e6d038de | 3548 | struct net_device *netdev = adapter->netdev; |
56184e01 | 3549 | struct iavf_vsi *vsi = &adapter->vsi; |
bacd75cf PB |
3550 | netdev_features_t hw_enc_features; |
3551 | netdev_features_t hw_features; | |
e6d038de MW |
3552 | |
3553 | /* got VF config message back from PF, now we can parse it */ | |
ba6cc7f6 | 3554 | for (i = 0; i < vfres->num_vsis; i++) { |
ff3f4cc2 | 3555 | if (vfres->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV) |
ba6cc7f6 | 3556 | adapter->vsi_res = &vfres->vsi_res[i]; |
e6d038de MW |
3557 | } |
3558 | if (!adapter->vsi_res) { | |
3559 | dev_err(&adapter->pdev->dev, "No LAN VSI found\n"); | |
3560 | return -ENODEV; | |
3561 | } | |
3562 | ||
5b36e8d0 | 3563 | if (num_req_queues && |
5520deb1 | 3564 | num_req_queues > adapter->vsi_res->num_queue_pairs) { |
5b36e8d0 AB |
3565 | /* Problem. The PF gave us fewer queues than what we had |
3566 | * negotiated in our request. Need a reset to see if we can't | |
3567 | * get back to a working state. | |
3568 | */ | |
3569 | dev_err(&adapter->pdev->dev, | |
3570 | "Requested %d queues, but PF only gave us %d.\n", | |
3571 | num_req_queues, | |
3572 | adapter->vsi_res->num_queue_pairs); | |
129cf89e | 3573 | adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED; |
5b36e8d0 | 3574 | adapter->num_req_queues = adapter->vsi_res->num_queue_pairs; |
129cf89e | 3575 | iavf_schedule_reset(adapter); |
5b36e8d0 AB |
3576 | return -ENODEV; |
3577 | } | |
3578 | adapter->num_req_queues = 0; | |
3579 | ||
bacd75cf PB |
3580 | hw_enc_features = NETIF_F_SG | |
3581 | NETIF_F_IP_CSUM | | |
3582 | NETIF_F_IPV6_CSUM | | |
3583 | NETIF_F_HIGHDMA | | |
3584 | NETIF_F_SOFT_FEATURES | | |
3585 | NETIF_F_TSO | | |
3586 | NETIF_F_TSO_ECN | | |
3587 | NETIF_F_TSO6 | | |
3588 | NETIF_F_SCTP_CRC | | |
3589 | NETIF_F_RXHASH | | |
3590 | NETIF_F_RXCSUM | | |
3591 | 0; | |
3592 | ||
3593 | /* advertise to stack only if offloads for encapsulated packets is | |
3594 | * supported | |
3595 | */ | |
fbb113f7 | 3596 | if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ENCAP) { |
bacd75cf | 3597 | hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL | |
b0fe3306 | 3598 | NETIF_F_GSO_GRE | |
1c7b4a23 | 3599 | NETIF_F_GSO_GRE_CSUM | |
7e13318d | 3600 | NETIF_F_GSO_IPXIP4 | |
bf2d1df3 | 3601 | NETIF_F_GSO_IPXIP6 | |
b0fe3306 | 3602 | NETIF_F_GSO_UDP_TUNNEL_CSUM | |
1c7b4a23 | 3603 | NETIF_F_GSO_PARTIAL | |
b0fe3306 AD |
3604 | 0; |
3605 | ||
fbb113f7 | 3606 | if (!(vfres->vf_cap_flags & |
310a2ad9 | 3607 | VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM)) |
bacd75cf PB |
3608 | netdev->gso_partial_features |= |
3609 | NETIF_F_GSO_UDP_TUNNEL_CSUM; | |
b0fe3306 | 3610 | |
bacd75cf PB |
3611 | netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM; |
3612 | netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID; | |
3613 | netdev->hw_enc_features |= hw_enc_features; | |
3614 | } | |
b0fe3306 | 3615 | /* record features VLANs can make use of */ |
bacd75cf | 3616 | netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID; |
b0fe3306 AD |
3617 | |
3618 | /* Write features and hw_features separately to avoid polluting | |
bacd75cf | 3619 | * with, or dropping, features that are set when we registered. |
b0fe3306 | 3620 | */ |
bacd75cf | 3621 | hw_features = hw_enc_features; |
b0fe3306 | 3622 | |
0a3b4f70 JK |
3623 | /* Enable VLAN features if supported */ |
3624 | if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN) | |
3625 | hw_features |= (NETIF_F_HW_VLAN_CTAG_TX | | |
3626 | NETIF_F_HW_VLAN_CTAG_RX); | |
0075fa0f HR |
3627 | /* Enable cloud filter if ADQ is supported */ |
3628 | if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADQ) | |
3629 | hw_features |= NETIF_F_HW_TC; | |
c91a4f9f BC |
3630 | if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_USO) |
3631 | hw_features |= NETIF_F_GSO_UDP_L4; | |
0a3b4f70 | 3632 | |
bacd75cf | 3633 | netdev->hw_features |= hw_features; |
b0fe3306 | 3634 | |
0a3b4f70 JK |
3635 | netdev->features |= hw_features; |
3636 | ||
3637 | if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN) | |
3638 | netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; | |
e6d038de | 3639 | |
e65aae08 LY |
3640 | netdev->priv_flags |= IFF_UNICAST_FLT; |
3641 | ||
e4062894 PJ |
3642 | /* Do not turn on offloads when they are requested to be turned off. |
3643 | * TSO needs minimum 576 bytes to work correctly. | |
3644 | */ | |
3645 | if (netdev->wanted_features) { | |
3646 | if (!(netdev->wanted_features & NETIF_F_TSO) || | |
3647 | netdev->mtu < 576) | |
3648 | netdev->features &= ~NETIF_F_TSO; | |
3649 | if (!(netdev->wanted_features & NETIF_F_TSO6) || | |
3650 | netdev->mtu < 576) | |
3651 | netdev->features &= ~NETIF_F_TSO6; | |
3652 | if (!(netdev->wanted_features & NETIF_F_TSO_ECN)) | |
3653 | netdev->features &= ~NETIF_F_TSO_ECN; | |
3654 | if (!(netdev->wanted_features & NETIF_F_GRO)) | |
3655 | netdev->features &= ~NETIF_F_GRO; | |
3656 | if (!(netdev->wanted_features & NETIF_F_GSO)) | |
3657 | netdev->features &= ~NETIF_F_GSO; | |
3658 | } | |
3659 | ||
e6d038de MW |
3660 | adapter->vsi.id = adapter->vsi_res->vsi_id; |
3661 | ||
3662 | adapter->vsi.back = adapter; | |
3663 | adapter->vsi.base_vector = 1; | |
56184e01 | 3664 | adapter->vsi.work_limit = IAVF_DEFAULT_IRQ_WORK; |
43a3d9ba MW |
3665 | vsi->netdev = adapter->netdev; |
3666 | vsi->qs_handle = adapter->vsi_res->qset_handle; | |
fbb113f7 | 3667 | if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) { |
43a3d9ba MW |
3668 | adapter->rss_key_size = vfres->rss_key_size; |
3669 | adapter->rss_lut_size = vfres->rss_lut_size; | |
3670 | } else { | |
129cf89e JB |
3671 | adapter->rss_key_size = IAVF_HKEY_ARRAY_SIZE; |
3672 | adapter->rss_lut_size = IAVF_HLUT_ARRAY_SIZE; | |
43a3d9ba MW |
3673 | } |
3674 | ||
e6d038de MW |
3675 | return 0; |
3676 | } | |
3677 | ||
5eae00c5 | 3678 | /** |
129cf89e | 3679 | * iavf_init_task - worker thread to perform delayed initialization |
5eae00c5 GR |
3680 | * @work: pointer to work_struct containing our data |
3681 | * | |
3682 | * This task completes the work that was begun in probe. Due to the nature | |
3683 | * of VF-PF communications, we may need to wait tens of milliseconds to get | |
dbedd44e | 3684 | * responses back from the PF. Rather than busy-wait in probe and bog down the |
5eae00c5 GR |
3685 | * whole system, we'll do it in a task so we can sleep. |
3686 | * This task only runs during driver init. Once we've established | |
3687 | * communications with the PF driver and set up our netdev, the watchdog | |
3688 | * takes over. | |
3689 | **/ | |
129cf89e | 3690 | static void iavf_init_task(struct work_struct *work) |
5eae00c5 | 3691 | { |
129cf89e | 3692 | struct iavf_adapter *adapter = container_of(work, |
b66c7bc1 JP |
3693 | struct iavf_adapter, |
3694 | init_task.work); | |
f349daa5 | 3695 | struct iavf_hw *hw = &adapter->hw; |
5eae00c5 | 3696 | |
5ac49f3c SA |
3697 | if (iavf_lock_timeout(&adapter->crit_lock, 5000)) { |
3698 | dev_warn(&adapter->pdev->dev, "failed to acquire crit_lock in %s\n", __FUNCTION__); | |
226d5285 SA |
3699 | return; |
3700 | } | |
5eae00c5 | 3701 | switch (adapter->state) { |
129cf89e | 3702 | case __IAVF_STARTUP: |
b66c7bc1 JP |
3703 | if (iavf_startup(adapter) < 0) |
3704 | goto init_failed; | |
3705 | break; | |
129cf89e | 3706 | case __IAVF_INIT_VERSION_CHECK: |
b66c7bc1 JP |
3707 | if (iavf_init_version_check(adapter) < 0) |
3708 | goto init_failed; | |
5eae00c5 | 3709 | break; |
b66c7bc1 JP |
3710 | case __IAVF_INIT_GET_RESOURCES: |
3711 | if (iavf_init_get_resources(adapter) < 0) | |
3712 | goto init_failed; | |
226d5285 | 3713 | goto out; |
5eae00c5 | 3714 | default: |
b66c7bc1 | 3715 | goto init_failed; |
ef8693eb | 3716 | } |
5eae00c5 | 3717 | |
fdd4044f JP |
3718 | queue_delayed_work(iavf_wq, &adapter->init_task, |
3719 | msecs_to_jiffies(30)); | |
226d5285 | 3720 | goto out; |
b66c7bc1 | 3721 | init_failed: |
129cf89e | 3722 | if (++adapter->aq_wait_count > IAVF_AQ_MAX_ERR) { |
b66c7bc1 JP |
3723 | dev_err(&adapter->pdev->dev, |
3724 | "Failed to communicate with PF; waiting before retry\n"); | |
129cf89e JB |
3725 | adapter->flags |= IAVF_FLAG_PF_COMMS_FAILED; |
3726 | iavf_shutdown_adminq(hw); | |
3727 | adapter->state = __IAVF_STARTUP; | |
fdd4044f | 3728 | queue_delayed_work(iavf_wq, &adapter->init_task, HZ * 5); |
226d5285 | 3729 | goto out; |
5eae00c5 | 3730 | } |
fdd4044f | 3731 | queue_delayed_work(iavf_wq, &adapter->init_task, HZ); |
226d5285 | 3732 | out: |
5ac49f3c | 3733 | mutex_unlock(&adapter->crit_lock); |
5eae00c5 GR |
3734 | } |
3735 | ||
3736 | /** | |
129cf89e | 3737 | * iavf_shutdown - Shutdown the device in preparation for a reboot |
5eae00c5 GR |
3738 | * @pdev: pci device structure |
3739 | **/ | |
129cf89e | 3740 | static void iavf_shutdown(struct pci_dev *pdev) |
5eae00c5 GR |
3741 | { |
3742 | struct net_device *netdev = pci_get_drvdata(pdev); | |
129cf89e | 3743 | struct iavf_adapter *adapter = netdev_priv(netdev); |
5eae00c5 GR |
3744 | |
3745 | netif_device_detach(netdev); | |
3746 | ||
3747 | if (netif_running(netdev)) | |
129cf89e | 3748 | iavf_close(netdev); |
5eae00c5 | 3749 | |
5ac49f3c SA |
3750 | if (iavf_lock_timeout(&adapter->crit_lock, 5000)) |
3751 | dev_warn(&adapter->pdev->dev, "failed to acquire crit_lock in %s\n", __FUNCTION__); | |
00293fdc | 3752 | /* Prevent the watchdog from running. */ |
129cf89e | 3753 | adapter->state = __IAVF_REMOVE; |
00293fdc | 3754 | adapter->aq_required = 0; |
5ac49f3c | 3755 | mutex_unlock(&adapter->crit_lock); |
00293fdc | 3756 | |
5eae00c5 GR |
3757 | #ifdef CONFIG_PM |
3758 | pci_save_state(pdev); | |
3759 | ||
3760 | #endif | |
3761 | pci_disable_device(pdev); | |
3762 | } | |
3763 | ||
3764 | /** | |
129cf89e | 3765 | * iavf_probe - Device Initialization Routine |
5eae00c5 | 3766 | * @pdev: PCI device information struct |
129cf89e | 3767 | * @ent: entry in iavf_pci_tbl |
5eae00c5 GR |
3768 | * |
3769 | * Returns 0 on success, negative on failure | |
3770 | * | |
129cf89e | 3771 | * iavf_probe initializes an adapter identified by a pci_dev structure. |
5eae00c5 GR |
3772 | * The OS initialization, configuring of the adapter private structure, |
3773 | * and a hardware reset occur. | |
3774 | **/ | |
129cf89e | 3775 | static int iavf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
5eae00c5 GR |
3776 | { |
3777 | struct net_device *netdev; | |
129cf89e | 3778 | struct iavf_adapter *adapter = NULL; |
f349daa5 | 3779 | struct iavf_hw *hw = NULL; |
dbbd8111 | 3780 | int err; |
5eae00c5 GR |
3781 | |
3782 | err = pci_enable_device(pdev); | |
3783 | if (err) | |
3784 | return err; | |
3785 | ||
6494294f | 3786 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
6494294f | 3787 | if (err) { |
e3e3bfdd JS |
3788 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
3789 | if (err) { | |
3790 | dev_err(&pdev->dev, | |
3791 | "DMA configuration failed: 0x%x\n", err); | |
3792 | goto err_dma; | |
3793 | } | |
5eae00c5 GR |
3794 | } |
3795 | ||
129cf89e | 3796 | err = pci_request_regions(pdev, iavf_driver_name); |
5eae00c5 GR |
3797 | if (err) { |
3798 | dev_err(&pdev->dev, | |
3799 | "pci_request_regions failed 0x%x\n", err); | |
3800 | goto err_pci_reg; | |
3801 | } | |
3802 | ||
3803 | pci_enable_pcie_error_reporting(pdev); | |
3804 | ||
3805 | pci_set_master(pdev); | |
3806 | ||
129cf89e JB |
3807 | netdev = alloc_etherdev_mq(sizeof(struct iavf_adapter), |
3808 | IAVF_MAX_REQ_QUEUES); | |
5eae00c5 GR |
3809 | if (!netdev) { |
3810 | err = -ENOMEM; | |
3811 | goto err_alloc_etherdev; | |
3812 | } | |
3813 | ||
3814 | SET_NETDEV_DEV(netdev, &pdev->dev); | |
3815 | ||
3816 | pci_set_drvdata(pdev, netdev); | |
3817 | adapter = netdev_priv(netdev); | |
5eae00c5 GR |
3818 | |
3819 | adapter->netdev = netdev; | |
3820 | adapter->pdev = pdev; | |
3821 | ||
3822 | hw = &adapter->hw; | |
3823 | hw->back = adapter; | |
3824 | ||
41a1d04b | 3825 | adapter->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
129cf89e | 3826 | adapter->state = __IAVF_STARTUP; |
5eae00c5 GR |
3827 | |
3828 | /* Call save state here because it relies on the adapter struct. */ | |
3829 | pci_save_state(pdev); | |
3830 | ||
3831 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), | |
3832 | pci_resource_len(pdev, 0)); | |
3833 | if (!hw->hw_addr) { | |
3834 | err = -EIO; | |
3835 | goto err_ioremap; | |
3836 | } | |
3837 | hw->vendor_id = pdev->vendor; | |
3838 | hw->device_id = pdev->device; | |
3839 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); | |
3840 | hw->subsystem_vendor_id = pdev->subsystem_vendor; | |
3841 | hw->subsystem_device_id = pdev->subsystem_device; | |
3842 | hw->bus.device = PCI_SLOT(pdev->devfn); | |
3843 | hw->bus.func = PCI_FUNC(pdev->devfn); | |
b3f028fc | 3844 | hw->bus.bus_id = pdev->bus->number; |
5eae00c5 | 3845 | |
8ddb3326 JB |
3846 | /* set up the locks for the AQ, do this only once in probe |
3847 | * and destroy them only once in remove | |
3848 | */ | |
5ac49f3c SA |
3849 | mutex_init(&adapter->crit_lock); |
3850 | mutex_init(&adapter->client_lock); | |
3851 | mutex_init(&adapter->remove_lock); | |
8ddb3326 JB |
3852 | mutex_init(&hw->aq.asq_mutex); |
3853 | mutex_init(&hw->aq.arq_mutex); | |
3854 | ||
504398f0 | 3855 | spin_lock_init(&adapter->mac_vlan_list_lock); |
0075fa0f | 3856 | spin_lock_init(&adapter->cloud_filter_list_lock); |
0dbfbabb | 3857 | spin_lock_init(&adapter->fdir_fltr_lock); |
0aaeb4fb | 3858 | spin_lock_init(&adapter->adv_rss_lock); |
504398f0 | 3859 | |
8bb1a540 SK |
3860 | INIT_LIST_HEAD(&adapter->mac_filter_list); |
3861 | INIT_LIST_HEAD(&adapter->vlan_filter_list); | |
0075fa0f | 3862 | INIT_LIST_HEAD(&adapter->cloud_filter_list); |
0dbfbabb | 3863 | INIT_LIST_HEAD(&adapter->fdir_list_head); |
0aaeb4fb | 3864 | INIT_LIST_HEAD(&adapter->adv_rss_list_head); |
8bb1a540 | 3865 | |
129cf89e JB |
3866 | INIT_WORK(&adapter->reset_task, iavf_reset_task); |
3867 | INIT_WORK(&adapter->adminq_task, iavf_adminq_task); | |
fdd4044f | 3868 | INIT_DELAYED_WORK(&adapter->watchdog_task, iavf_watchdog_task); |
129cf89e JB |
3869 | INIT_DELAYED_WORK(&adapter->client_task, iavf_client_task); |
3870 | INIT_DELAYED_WORK(&adapter->init_task, iavf_init_task); | |
fdd4044f JP |
3871 | queue_delayed_work(iavf_wq, &adapter->init_task, |
3872 | msecs_to_jiffies(5 * (pdev->devfn & 0x07))); | |
5eae00c5 | 3873 | |
fe2647ab SM |
3874 | /* Setup the wait queue for indicating transition to down status */ |
3875 | init_waitqueue_head(&adapter->down_waitqueue); | |
3876 | ||
5eae00c5 GR |
3877 | return 0; |
3878 | ||
3879 | err_ioremap: | |
3880 | free_netdev(netdev); | |
3881 | err_alloc_etherdev: | |
af30cbd2 | 3882 | pci_disable_pcie_error_reporting(pdev); |
5eae00c5 GR |
3883 | pci_release_regions(pdev); |
3884 | err_pci_reg: | |
3885 | err_dma: | |
3886 | pci_disable_device(pdev); | |
3887 | return err; | |
3888 | } | |
3889 | ||
5eae00c5 | 3890 | /** |
129cf89e | 3891 | * iavf_suspend - Power management suspend routine |
b50f7bca | 3892 | * @dev_d: device info pointer |
5eae00c5 GR |
3893 | * |
3894 | * Called when the system (VM) is entering sleep/suspend. | |
3895 | **/ | |
bc5cbd73 | 3896 | static int __maybe_unused iavf_suspend(struct device *dev_d) |
5eae00c5 | 3897 | { |
bc5cbd73 | 3898 | struct net_device *netdev = dev_get_drvdata(dev_d); |
129cf89e | 3899 | struct iavf_adapter *adapter = netdev_priv(netdev); |
5eae00c5 GR |
3900 | |
3901 | netif_device_detach(netdev); | |
3902 | ||
5ac49f3c | 3903 | while (!mutex_trylock(&adapter->crit_lock)) |
9b2aef12 JK |
3904 | usleep_range(500, 1000); |
3905 | ||
5eae00c5 GR |
3906 | if (netif_running(netdev)) { |
3907 | rtnl_lock(); | |
129cf89e | 3908 | iavf_down(adapter); |
5eae00c5 GR |
3909 | rtnl_unlock(); |
3910 | } | |
129cf89e JB |
3911 | iavf_free_misc_irq(adapter); |
3912 | iavf_reset_interrupt_capability(adapter); | |
5eae00c5 | 3913 | |
5ac49f3c | 3914 | mutex_unlock(&adapter->crit_lock); |
9b2aef12 | 3915 | |
5eae00c5 GR |
3916 | return 0; |
3917 | } | |
3918 | ||
3919 | /** | |
129cf89e | 3920 | * iavf_resume - Power management resume routine |
b50f7bca | 3921 | * @dev_d: device info pointer |
5eae00c5 GR |
3922 | * |
3923 | * Called when the system (VM) is resumed from sleep/suspend. | |
3924 | **/ | |
bc5cbd73 | 3925 | static int __maybe_unused iavf_resume(struct device *dev_d) |
5eae00c5 | 3926 | { |
bc5cbd73 | 3927 | struct pci_dev *pdev = to_pci_dev(dev_d); |
75598a8f SD |
3928 | struct net_device *netdev = pci_get_drvdata(pdev); |
3929 | struct iavf_adapter *adapter = netdev_priv(netdev); | |
5eae00c5 GR |
3930 | u32 err; |
3931 | ||
5eae00c5 GR |
3932 | pci_set_master(pdev); |
3933 | ||
3934 | rtnl_lock(); | |
129cf89e | 3935 | err = iavf_set_interrupt_capability(adapter); |
5eae00c5 | 3936 | if (err) { |
f2a1c368 | 3937 | rtnl_unlock(); |
5eae00c5 GR |
3938 | dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n"); |
3939 | return err; | |
3940 | } | |
129cf89e | 3941 | err = iavf_request_misc_irq(adapter); |
5eae00c5 GR |
3942 | rtnl_unlock(); |
3943 | if (err) { | |
3944 | dev_err(&pdev->dev, "Cannot get interrupt vector.\n"); | |
3945 | return err; | |
3946 | } | |
3947 | ||
fdd4044f | 3948 | queue_work(iavf_wq, &adapter->reset_task); |
5eae00c5 GR |
3949 | |
3950 | netif_device_attach(netdev); | |
3951 | ||
3952 | return err; | |
3953 | } | |
3954 | ||
5eae00c5 | 3955 | /** |
129cf89e | 3956 | * iavf_remove - Device Removal Routine |
5eae00c5 GR |
3957 | * @pdev: PCI device information struct |
3958 | * | |
129cf89e | 3959 | * iavf_remove is called by the PCI subsystem to alert the driver |
5eae00c5 GR |
3960 | * that it should release a PCI device. The could be caused by a |
3961 | * Hot-Plug event, or because the driver is going to be removed from | |
3962 | * memory. | |
3963 | **/ | |
129cf89e | 3964 | static void iavf_remove(struct pci_dev *pdev) |
5eae00c5 GR |
3965 | { |
3966 | struct net_device *netdev = pci_get_drvdata(pdev); | |
129cf89e | 3967 | struct iavf_adapter *adapter = netdev_priv(netdev); |
0dbfbabb | 3968 | struct iavf_fdir_fltr *fdir, *fdirtmp; |
129cf89e | 3969 | struct iavf_vlan_filter *vlf, *vlftmp; |
0aaeb4fb | 3970 | struct iavf_adv_rss *rss, *rsstmp; |
129cf89e JB |
3971 | struct iavf_mac_filter *f, *ftmp; |
3972 | struct iavf_cloud_filter *cf, *cftmp; | |
f349daa5 | 3973 | struct iavf_hw *hw = &adapter->hw; |
ed0e894d | 3974 | int err; |
06aa040f | 3975 | /* Indicate we are in remove and not to run reset_task */ |
5ac49f3c | 3976 | mutex_lock(&adapter->remove_lock); |
5eae00c5 | 3977 | cancel_delayed_work_sync(&adapter->init_task); |
ef8693eb | 3978 | cancel_work_sync(&adapter->reset_task); |
ed0e894d | 3979 | cancel_delayed_work_sync(&adapter->client_task); |
5eae00c5 GR |
3980 | if (adapter->netdev_registered) { |
3981 | unregister_netdev(netdev); | |
3982 | adapter->netdev_registered = false; | |
3983 | } | |
ed0e894d | 3984 | if (CLIENT_ALLOWED(adapter)) { |
129cf89e | 3985 | err = iavf_lan_del_device(adapter); |
ed0e894d MW |
3986 | if (err) |
3987 | dev_warn(&pdev->dev, "Failed to delete client device: %d\n", | |
3988 | err); | |
3989 | } | |
53d0b3ae | 3990 | |
129cf89e | 3991 | iavf_request_reset(adapter); |
22ead37f | 3992 | msleep(50); |
f4a71881 | 3993 | /* If the FW isn't responding, kick it once, but only once. */ |
129cf89e JB |
3994 | if (!iavf_asq_done(hw)) { |
3995 | iavf_request_reset(adapter); | |
22ead37f | 3996 | msleep(50); |
f4a71881 | 3997 | } |
5ac49f3c SA |
3998 | if (iavf_lock_timeout(&adapter->crit_lock, 5000)) |
3999 | dev_warn(&adapter->pdev->dev, "failed to acquire crit_lock in %s\n", __FUNCTION__); | |
226d5285 SA |
4000 | |
4001 | /* Shut down all the garbage mashers on the detention level */ | |
4002 | adapter->state = __IAVF_REMOVE; | |
4003 | adapter->aq_required = 0; | |
4004 | adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED; | |
129cf89e JB |
4005 | iavf_free_all_tx_resources(adapter); |
4006 | iavf_free_all_rx_resources(adapter); | |
4007 | iavf_misc_irq_disable(adapter); | |
4008 | iavf_free_misc_irq(adapter); | |
4009 | iavf_reset_interrupt_capability(adapter); | |
4010 | iavf_free_q_vectors(adapter); | |
5eae00c5 | 4011 | |
fdd4044f | 4012 | cancel_delayed_work_sync(&adapter->watchdog_task); |
e5d17c3e | 4013 | |
babbcc60 LY |
4014 | cancel_work_sync(&adapter->adminq_task); |
4015 | ||
129cf89e | 4016 | iavf_free_rss(adapter); |
66f9af85 | 4017 | |
5eae00c5 | 4018 | if (hw->aq.asq.count) |
129cf89e | 4019 | iavf_shutdown_adminq(hw); |
5eae00c5 | 4020 | |
8ddb3326 JB |
4021 | /* destroy the locks only once, here */ |
4022 | mutex_destroy(&hw->aq.arq_mutex); | |
4023 | mutex_destroy(&hw->aq.asq_mutex); | |
5ac49f3c SA |
4024 | mutex_destroy(&adapter->client_lock); |
4025 | mutex_unlock(&adapter->crit_lock); | |
4026 | mutex_destroy(&adapter->crit_lock); | |
4027 | mutex_unlock(&adapter->remove_lock); | |
4028 | mutex_destroy(&adapter->remove_lock); | |
8ddb3326 | 4029 | |
5eae00c5 GR |
4030 | iounmap(hw->hw_addr); |
4031 | pci_release_regions(pdev); | |
129cf89e | 4032 | iavf_free_queues(adapter); |
5eae00c5 | 4033 | kfree(adapter->vf_res); |
504398f0 | 4034 | spin_lock_bh(&adapter->mac_vlan_list_lock); |
6ba36a24 MW |
4035 | /* If we got removed before an up/down sequence, we've got a filter |
4036 | * hanging out there that we need to get rid of. | |
4037 | */ | |
4038 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { | |
4039 | list_del(&f->list); | |
4040 | kfree(f); | |
4041 | } | |
fbd5eb54 HR |
4042 | list_for_each_entry_safe(vlf, vlftmp, &adapter->vlan_filter_list, |
4043 | list) { | |
4044 | list_del(&vlf->list); | |
4045 | kfree(vlf); | |
37dfdf37 | 4046 | } |
5eae00c5 | 4047 | |
504398f0 JK |
4048 | spin_unlock_bh(&adapter->mac_vlan_list_lock); |
4049 | ||
0075fa0f HR |
4050 | spin_lock_bh(&adapter->cloud_filter_list_lock); |
4051 | list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) { | |
4052 | list_del(&cf->list); | |
4053 | kfree(cf); | |
4054 | } | |
4055 | spin_unlock_bh(&adapter->cloud_filter_list_lock); | |
4056 | ||
0dbfbabb HW |
4057 | spin_lock_bh(&adapter->fdir_fltr_lock); |
4058 | list_for_each_entry_safe(fdir, fdirtmp, &adapter->fdir_list_head, list) { | |
4059 | list_del(&fdir->list); | |
4060 | kfree(fdir); | |
4061 | } | |
4062 | spin_unlock_bh(&adapter->fdir_fltr_lock); | |
4063 | ||
0aaeb4fb HW |
4064 | spin_lock_bh(&adapter->adv_rss_lock); |
4065 | list_for_each_entry_safe(rss, rsstmp, &adapter->adv_rss_list_head, | |
4066 | list) { | |
4067 | list_del(&rss->list); | |
4068 | kfree(rss); | |
4069 | } | |
4070 | spin_unlock_bh(&adapter->adv_rss_lock); | |
4071 | ||
5eae00c5 GR |
4072 | free_netdev(netdev); |
4073 | ||
4074 | pci_disable_pcie_error_reporting(pdev); | |
4075 | ||
4076 | pci_disable_device(pdev); | |
4077 | } | |
4078 | ||
bc5cbd73 VG |
4079 | static SIMPLE_DEV_PM_OPS(iavf_pm_ops, iavf_suspend, iavf_resume); |
4080 | ||
129cf89e | 4081 | static struct pci_driver iavf_driver = { |
bc5cbd73 VG |
4082 | .name = iavf_driver_name, |
4083 | .id_table = iavf_pci_tbl, | |
4084 | .probe = iavf_probe, | |
4085 | .remove = iavf_remove, | |
4086 | .driver.pm = &iavf_pm_ops, | |
4087 | .shutdown = iavf_shutdown, | |
5eae00c5 GR |
4088 | }; |
4089 | ||
4090 | /** | |
56184e01 | 4091 | * iavf_init_module - Driver Registration Routine |
5eae00c5 | 4092 | * |
56184e01 | 4093 | * iavf_init_module is the first routine called when the driver is |
5eae00c5 GR |
4094 | * loaded. All it does is register with the PCI subsystem. |
4095 | **/ | |
129cf89e | 4096 | static int __init iavf_init_module(void) |
5eae00c5 GR |
4097 | { |
4098 | int ret; | |
75a64435 | 4099 | |
34a2a3b8 | 4100 | pr_info("iavf: %s\n", iavf_driver_string); |
5eae00c5 | 4101 | |
129cf89e | 4102 | pr_info("%s\n", iavf_copyright); |
5eae00c5 | 4103 | |
129cf89e JB |
4104 | iavf_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1, |
4105 | iavf_driver_name); | |
4106 | if (!iavf_wq) { | |
4107 | pr_err("%s: Failed to create workqueue\n", iavf_driver_name); | |
2803b16c JB |
4108 | return -ENOMEM; |
4109 | } | |
129cf89e | 4110 | ret = pci_register_driver(&iavf_driver); |
5eae00c5 GR |
4111 | return ret; |
4112 | } | |
4113 | ||
129cf89e | 4114 | module_init(iavf_init_module); |
5eae00c5 GR |
4115 | |
4116 | /** | |
56184e01 | 4117 | * iavf_exit_module - Driver Exit Cleanup Routine |
5eae00c5 | 4118 | * |
56184e01 | 4119 | * iavf_exit_module is called just before the driver is removed |
5eae00c5 GR |
4120 | * from memory. |
4121 | **/ | |
129cf89e | 4122 | static void __exit iavf_exit_module(void) |
5eae00c5 | 4123 | { |
129cf89e JB |
4124 | pci_unregister_driver(&iavf_driver); |
4125 | destroy_workqueue(iavf_wq); | |
5eae00c5 GR |
4126 | } |
4127 | ||
129cf89e | 4128 | module_exit(iavf_exit_module); |
5eae00c5 | 4129 | |
129cf89e | 4130 | /* iavf_main.c */ |