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