blob: 798f0dedf14fc49426a016946e304adf6f2f242d [file] [log] [blame]
Greg Rose5eae00c2013-12-21 06:12:45 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
Sravanthi Tangeda5b8eb172015-02-06 08:52:21 +00004 * Copyright(c) 2013 - 2015 Intel Corporation.
Greg Rose5eae00c2013-12-21 06:12:45 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Jesse Brandeburgb8316072014-04-05 07:46:11 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
Greg Rose5eae00c2013-12-21 06:12:45 +000018 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27#include "i40evf.h"
28#include "i40e_prototype.h"
29static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter);
30static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter);
31static int i40evf_close(struct net_device *netdev);
32
33char i40evf_driver_name[] = "i40evf";
34static const char i40evf_driver_string[] =
Mitch Williams0af56f42014-06-04 20:42:10 +000035 "Intel(R) XL710/X710 Virtual Function Network Driver";
Greg Rose5eae00c2013-12-21 06:12:45 +000036
Mitch Williams69ebe9552015-11-19 11:34:24 -080037#define DRV_KERN "-k"
38
39#define DRV_VERSION_MAJOR 1
40#define DRV_VERSION_MINOR 4
Catherine Sullivanc9c9f1b2015-11-19 11:34:25 -080041#define DRV_VERSION_BUILD 4
Mitch Williams69ebe9552015-11-19 11:34:24 -080042#define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
43 __stringify(DRV_VERSION_MINOR) "." \
44 __stringify(DRV_VERSION_BUILD) \
45 DRV_KERN
Greg Rose5eae00c2013-12-21 06:12:45 +000046const char i40evf_driver_version[] = DRV_VERSION;
47static const char i40evf_copyright[] =
Catherine Sullivanbf418462015-07-10 19:36:10 -040048 "Copyright (c) 2013 - 2015 Intel Corporation.";
Greg Rose5eae00c2013-12-21 06:12:45 +000049
50/* i40evf_pci_tbl - PCI Device ID Table
51 *
52 * Wildcard entries (PCI_ANY_ID) should come last
53 * Last entry must be all 0s
54 *
55 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
56 * Class, Class Mask, private data (not used) }
57 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020058static const struct pci_device_id i40evf_pci_tbl[] = {
Shannon Nelsonab600852014-01-17 15:36:39 -080059 {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0},
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040060 {PCI_VDEVICE(INTEL, I40E_DEV_ID_X722_VF), 0},
Greg Rose5eae00c2013-12-21 06:12:45 +000061 /* required last entry */
62 {0, }
63};
64
65MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl);
66
67MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
68MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
69MODULE_LICENSE("GPL");
70MODULE_VERSION(DRV_VERSION);
71
72/**
73 * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
74 * @hw: pointer to the HW structure
75 * @mem: ptr to mem struct to fill out
76 * @size: size of memory requested
77 * @alignment: what to align the allocation to
78 **/
79i40e_status i40evf_allocate_dma_mem_d(struct i40e_hw *hw,
80 struct i40e_dma_mem *mem,
81 u64 size, u32 alignment)
82{
83 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
84
85 if (!mem)
86 return I40E_ERR_PARAM;
87
88 mem->size = ALIGN(size, alignment);
89 mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size,
90 (dma_addr_t *)&mem->pa, GFP_KERNEL);
91 if (mem->va)
92 return 0;
93 else
94 return I40E_ERR_NO_MEMORY;
95}
96
97/**
98 * i40evf_free_dma_mem_d - OS specific memory free for shared code
99 * @hw: pointer to the HW structure
100 * @mem: ptr to mem struct to free
101 **/
102i40e_status i40evf_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
103{
104 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
105
106 if (!mem || !mem->va)
107 return I40E_ERR_PARAM;
108 dma_free_coherent(&adapter->pdev->dev, mem->size,
109 mem->va, (dma_addr_t)mem->pa);
110 return 0;
111}
112
113/**
114 * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
115 * @hw: pointer to the HW structure
116 * @mem: ptr to mem struct to fill out
117 * @size: size of memory requested
118 **/
119i40e_status i40evf_allocate_virt_mem_d(struct i40e_hw *hw,
120 struct i40e_virt_mem *mem, u32 size)
121{
122 if (!mem)
123 return I40E_ERR_PARAM;
124
125 mem->size = size;
126 mem->va = kzalloc(size, GFP_KERNEL);
127
128 if (mem->va)
129 return 0;
130 else
131 return I40E_ERR_NO_MEMORY;
132}
133
134/**
135 * i40evf_free_virt_mem_d - OS specific memory free for shared code
136 * @hw: pointer to the HW structure
137 * @mem: ptr to mem struct to free
138 **/
139i40e_status i40evf_free_virt_mem_d(struct i40e_hw *hw,
140 struct i40e_virt_mem *mem)
141{
142 if (!mem)
143 return I40E_ERR_PARAM;
144
145 /* it's ok to kfree a NULL pointer */
146 kfree(mem->va);
147
148 return 0;
149}
150
151/**
152 * i40evf_debug_d - OS dependent version of debug printing
153 * @hw: pointer to the HW structure
154 * @mask: debug level mask
155 * @fmt_str: printf-type format description
156 **/
157void i40evf_debug_d(void *hw, u32 mask, char *fmt_str, ...)
158{
159 char buf[512];
160 va_list argptr;
161
162 if (!(mask & ((struct i40e_hw *)hw)->debug_mask))
163 return;
164
165 va_start(argptr, fmt_str);
166 vsnprintf(buf, sizeof(buf), fmt_str, argptr);
167 va_end(argptr);
168
169 /* the debug string is already formatted with a newline */
170 pr_info("%s", buf);
171}
172
173/**
174 * i40evf_tx_timeout - Respond to a Tx Hang
175 * @netdev: network interface device structure
176 **/
177static void i40evf_tx_timeout(struct net_device *netdev)
178{
179 struct i40evf_adapter *adapter = netdev_priv(netdev);
180
181 adapter->tx_timeout_count++;
Mitch Williams67c818a2015-06-19 08:56:30 -0700182 if (!(adapter->flags & (I40EVF_FLAG_RESET_PENDING |
183 I40EVF_FLAG_RESET_NEEDED))) {
Mitch Williams3526d802014-03-06 08:59:56 +0000184 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
Mitch Williams625777e2014-02-20 19:29:05 -0800185 schedule_work(&adapter->reset_task);
186 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000187}
188
189/**
190 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
191 * @adapter: board private structure
192 **/
193static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter)
194{
195 struct i40e_hw *hw = &adapter->hw;
Mitch Williams75a64432014-11-11 20:02:42 +0000196
Greg Rose5eae00c2013-12-21 06:12:45 +0000197 wr32(hw, I40E_VFINT_DYN_CTL01, 0);
198
199 /* read flush */
200 rd32(hw, I40E_VFGEN_RSTAT);
201
202 synchronize_irq(adapter->msix_entries[0].vector);
203}
204
205/**
206 * i40evf_misc_irq_enable - Enable default interrupt generation settings
207 * @adapter: board private structure
208 **/
209static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter)
210{
211 struct i40e_hw *hw = &adapter->hw;
Mitch Williams75a64432014-11-11 20:02:42 +0000212
Greg Rose5eae00c2013-12-21 06:12:45 +0000213 wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK |
214 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400215 wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA1_ADMINQ_MASK);
Greg Rose5eae00c2013-12-21 06:12:45 +0000216
217 /* read flush */
218 rd32(hw, I40E_VFGEN_RSTAT);
219}
220
221/**
222 * i40evf_irq_disable - Mask off interrupt generation on the NIC
223 * @adapter: board private structure
224 **/
225static void i40evf_irq_disable(struct i40evf_adapter *adapter)
226{
227 int i;
228 struct i40e_hw *hw = &adapter->hw;
229
Mitch Williamsdbb01c82014-02-20 19:29:07 -0800230 if (!adapter->msix_entries)
231 return;
232
Greg Rose5eae00c2013-12-21 06:12:45 +0000233 for (i = 1; i < adapter->num_msix_vectors; i++) {
234 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0);
235 synchronize_irq(adapter->msix_entries[i].vector);
236 }
237 /* read flush */
238 rd32(hw, I40E_VFGEN_RSTAT);
Greg Rose5eae00c2013-12-21 06:12:45 +0000239}
240
241/**
242 * i40evf_irq_enable_queues - Enable interrupt for specified queues
243 * @adapter: board private structure
244 * @mask: bitmap of queues to enable
245 **/
246void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask)
247{
248 struct i40e_hw *hw = &adapter->hw;
249 int i;
250
251 for (i = 1; i < adapter->num_msix_vectors; i++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400252 if (mask & BIT(i - 1)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000253 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1),
254 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000255 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400256 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK);
Greg Rose5eae00c2013-12-21 06:12:45 +0000257 }
258 }
259}
260
261/**
262 * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
263 * @adapter: board private structure
264 * @mask: bitmap of vectors to trigger
265 **/
Mitch Williams75a64432014-11-11 20:02:42 +0000266static void i40evf_fire_sw_int(struct i40evf_adapter *adapter, u32 mask)
Greg Rose5eae00c2013-12-21 06:12:45 +0000267{
268 struct i40e_hw *hw = &adapter->hw;
269 int i;
Mitch Williamsd82acb32015-11-06 15:26:06 -0800270 u32 dyn_ctl;
Greg Rose5eae00c2013-12-21 06:12:45 +0000271
Mitch Williams164ec1b2014-06-04 08:45:19 +0000272 if (mask & 1) {
273 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTL01);
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400274 dyn_ctl |= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000275 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400276 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK;
Mitch Williams164ec1b2014-06-04 08:45:19 +0000277 wr32(hw, I40E_VFINT_DYN_CTL01, dyn_ctl);
278 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000279 for (i = 1; i < adapter->num_msix_vectors; i++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400280 if (mask & BIT(i)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000281 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1));
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400282 dyn_ctl |= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000283 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400284 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK;
Greg Rose5eae00c2013-12-21 06:12:45 +0000285 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl);
286 }
287 }
288}
289
290/**
291 * i40evf_irq_enable - Enable default interrupt generation settings
292 * @adapter: board private structure
Jean Sacren69c1d702015-10-13 01:06:27 -0600293 * @flush: boolean value whether to run rd32()
Greg Rose5eae00c2013-12-21 06:12:45 +0000294 **/
295void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush)
296{
297 struct i40e_hw *hw = &adapter->hw;
298
Mitch Williams164ec1b2014-06-04 08:45:19 +0000299 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +0000300 i40evf_irq_enable_queues(adapter, ~0);
301
302 if (flush)
303 rd32(hw, I40E_VFGEN_RSTAT);
304}
305
306/**
307 * i40evf_msix_aq - Interrupt handler for vector 0
308 * @irq: interrupt number
309 * @data: pointer to netdev
310 **/
311static irqreturn_t i40evf_msix_aq(int irq, void *data)
312{
313 struct net_device *netdev = data;
314 struct i40evf_adapter *adapter = netdev_priv(netdev);
315 struct i40e_hw *hw = &adapter->hw;
316 u32 val;
Greg Rose5eae00c2013-12-21 06:12:45 +0000317
Jesse Brandeburgcfbe4db2015-10-04 01:09:49 -0700318 /* handle non-queue interrupts, these reads clear the registers */
319 val = rd32(hw, I40E_VFINT_ICR01);
320 val = rd32(hw, I40E_VFINT_ICR0_ENA1);
Greg Rose5eae00c2013-12-21 06:12:45 +0000321
Jean Sacrened17f7e2015-10-13 01:06:30 -0600322 val = rd32(hw, I40E_VFINT_DYN_CTL01) |
323 I40E_VFINT_DYN_CTL01_CLEARPBA_MASK;
Greg Rose5eae00c2013-12-21 06:12:45 +0000324 wr32(hw, I40E_VFINT_DYN_CTL01, val);
325
Greg Rose5eae00c2013-12-21 06:12:45 +0000326 /* schedule work on the private workqueue */
327 schedule_work(&adapter->adminq_task);
328
329 return IRQ_HANDLED;
330}
331
332/**
333 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
334 * @irq: interrupt number
335 * @data: pointer to a q_vector
336 **/
337static irqreturn_t i40evf_msix_clean_rings(int irq, void *data)
338{
339 struct i40e_q_vector *q_vector = data;
340
341 if (!q_vector->tx.ring && !q_vector->rx.ring)
342 return IRQ_HANDLED;
343
Alexander Duyck5d3465a2015-09-29 15:19:50 -0700344 napi_schedule_irqoff(&q_vector->napi);
Greg Rose5eae00c2013-12-21 06:12:45 +0000345
346 return IRQ_HANDLED;
347}
348
349/**
350 * i40evf_map_vector_to_rxq - associate irqs with rx queues
351 * @adapter: board private structure
352 * @v_idx: interrupt number
353 * @r_idx: queue number
354 **/
355static void
356i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx)
357{
Mitch Williams7d96ba12015-10-26 19:44:39 -0400358 struct i40e_q_vector *q_vector = &adapter->q_vectors[v_idx];
Mitch Williams0dd438d2015-10-26 19:44:40 -0400359 struct i40e_ring *rx_ring = &adapter->rx_rings[r_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +0000360
361 rx_ring->q_vector = q_vector;
362 rx_ring->next = q_vector->rx.ring;
363 rx_ring->vsi = &adapter->vsi;
364 q_vector->rx.ring = rx_ring;
365 q_vector->rx.count++;
366 q_vector->rx.latency_range = I40E_LOW_LATENCY;
Jesse Brandeburgee2319c2015-09-28 14:16:54 -0400367 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Greg Rose5eae00c2013-12-21 06:12:45 +0000368}
369
370/**
371 * i40evf_map_vector_to_txq - associate irqs with tx queues
372 * @adapter: board private structure
373 * @v_idx: interrupt number
374 * @t_idx: queue number
375 **/
376static void
377i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx)
378{
Mitch Williams7d96ba12015-10-26 19:44:39 -0400379 struct i40e_q_vector *q_vector = &adapter->q_vectors[v_idx];
Mitch Williams0dd438d2015-10-26 19:44:40 -0400380 struct i40e_ring *tx_ring = &adapter->tx_rings[t_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +0000381
382 tx_ring->q_vector = q_vector;
383 tx_ring->next = q_vector->tx.ring;
384 tx_ring->vsi = &adapter->vsi;
385 q_vector->tx.ring = tx_ring;
386 q_vector->tx.count++;
387 q_vector->tx.latency_range = I40E_LOW_LATENCY;
Jesse Brandeburgee2319c2015-09-28 14:16:54 -0400388 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Greg Rose5eae00c2013-12-21 06:12:45 +0000389 q_vector->num_ringpairs++;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400390 q_vector->ring_mask |= BIT(t_idx);
Greg Rose5eae00c2013-12-21 06:12:45 +0000391}
392
393/**
394 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
395 * @adapter: board private structure to initialize
396 *
397 * This function maps descriptor rings to the queue-specific vectors
398 * we were allotted through the MSI-X enabling code. Ideally, we'd have
399 * one vector per ring/queue, but on a constrained vector budget, we
400 * group the rings as "efficiently" as possible. You would add new
401 * mapping configurations in here.
402 **/
403static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter)
404{
405 int q_vectors;
406 int v_start = 0;
407 int rxr_idx = 0, txr_idx = 0;
Mitch Williamscc052922014-10-25 03:24:34 +0000408 int rxr_remaining = adapter->num_active_queues;
409 int txr_remaining = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +0000410 int i, j;
411 int rqpv, tqpv;
412 int err = 0;
413
414 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
415
416 /* The ideal configuration...
417 * We have enough vectors to map one per queue.
418 */
Mitch Williams973371d2015-04-27 14:57:09 -0400419 if (q_vectors >= (rxr_remaining * 2)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000420 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
421 i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx);
422
423 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
424 i40evf_map_vector_to_txq(adapter, v_start, txr_idx);
425 goto out;
426 }
427
428 /* If we don't have enough vectors for a 1-to-1
429 * mapping, we'll have to group them so there are
430 * multiple queues per vector.
431 * Re-adjusting *qpv takes care of the remainder.
432 */
433 for (i = v_start; i < q_vectors; i++) {
434 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
435 for (j = 0; j < rqpv; j++) {
436 i40evf_map_vector_to_rxq(adapter, i, rxr_idx);
437 rxr_idx++;
438 rxr_remaining--;
439 }
440 }
441 for (i = v_start; i < q_vectors; i++) {
442 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
443 for (j = 0; j < tqpv; j++) {
444 i40evf_map_vector_to_txq(adapter, i, txr_idx);
445 txr_idx++;
446 txr_remaining--;
447 }
448 }
449
450out:
451 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
452
453 return err;
454}
455
Alexander Duyck7709b4c2015-09-24 09:04:38 -0700456#ifdef CONFIG_NET_POLL_CONTROLLER
457/**
458 * i40evf_netpoll - A Polling 'interrupt' handler
459 * @netdev: network interface device structure
460 *
461 * This is used by netconsole to send skbs without having to re-enable
462 * interrupts. It's not called while the normal interrupt routine is executing.
463 **/
464static void i40evf_netpoll(struct net_device *netdev)
465{
466 struct i40evf_adapter *adapter = netdev_priv(netdev);
467 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
468 int i;
469
470 /* if interface is down do nothing */
471 if (test_bit(__I40E_DOWN, &adapter->vsi.state))
472 return;
473
474 for (i = 0; i < q_vectors; i++)
Mitch Williams7d96ba12015-10-26 19:44:39 -0400475 i40evf_msix_clean_rings(0, &adapter->q_vectors[i]);
Alexander Duyck7709b4c2015-09-24 09:04:38 -0700476}
477
478#endif
Greg Rose5eae00c2013-12-21 06:12:45 +0000479/**
480 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
481 * @adapter: board private structure
482 *
483 * Allocates MSI-X vectors for tx and rx handling, and requests
484 * interrupts from the kernel.
485 **/
486static int
487i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename)
488{
489 int vector, err, q_vectors;
490 int rx_int_idx = 0, tx_int_idx = 0;
491
492 i40evf_irq_disable(adapter);
493 /* Decrement for Other and TCP Timer vectors */
494 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
495
496 for (vector = 0; vector < q_vectors; vector++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -0400497 struct i40e_q_vector *q_vector = &adapter->q_vectors[vector];
Greg Rose5eae00c2013-12-21 06:12:45 +0000498
499 if (q_vector->tx.ring && q_vector->rx.ring) {
500 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
501 "i40evf-%s-%s-%d", basename,
502 "TxRx", rx_int_idx++);
503 tx_int_idx++;
504 } else if (q_vector->rx.ring) {
505 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
506 "i40evf-%s-%s-%d", basename,
507 "rx", rx_int_idx++);
508 } else if (q_vector->tx.ring) {
509 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
510 "i40evf-%s-%s-%d", basename,
511 "tx", tx_int_idx++);
512 } else {
513 /* skip this unused q_vector */
514 continue;
515 }
516 err = request_irq(
517 adapter->msix_entries[vector + NONQ_VECS].vector,
518 i40evf_msix_clean_rings,
519 0,
520 q_vector->name,
521 q_vector);
522 if (err) {
523 dev_info(&adapter->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400524 "Request_irq failed, error: %d\n", err);
Greg Rose5eae00c2013-12-21 06:12:45 +0000525 goto free_queue_irqs;
526 }
527 /* assign the mask for this irq */
528 irq_set_affinity_hint(
529 adapter->msix_entries[vector + NONQ_VECS].vector,
530 q_vector->affinity_mask);
531 }
532
533 return 0;
534
535free_queue_irqs:
536 while (vector) {
537 vector--;
538 irq_set_affinity_hint(
539 adapter->msix_entries[vector + NONQ_VECS].vector,
540 NULL);
541 free_irq(adapter->msix_entries[vector + NONQ_VECS].vector,
Mitch Williams7d96ba12015-10-26 19:44:39 -0400542 &adapter->q_vectors[vector]);
Greg Rose5eae00c2013-12-21 06:12:45 +0000543 }
544 return err;
545}
546
547/**
548 * i40evf_request_misc_irq - Initialize MSI-X interrupts
549 * @adapter: board private structure
550 *
551 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
552 * vector is only for the admin queue, and stays active even when the netdev
553 * is closed.
554 **/
555static int i40evf_request_misc_irq(struct i40evf_adapter *adapter)
556{
557 struct net_device *netdev = adapter->netdev;
558 int err;
559
Jesse Brandeburgb39c1e22014-08-01 13:27:08 -0700560 snprintf(adapter->misc_vector_name,
Carolyn Wyborny9a21a002015-02-06 08:52:20 +0000561 sizeof(adapter->misc_vector_name) - 1, "i40evf-%s:mbx",
562 dev_name(&adapter->pdev->dev));
Greg Rose5eae00c2013-12-21 06:12:45 +0000563 err = request_irq(adapter->msix_entries[0].vector,
Mitch Williamse1dfee82014-02-13 03:48:51 -0800564 &i40evf_msix_aq, 0,
565 adapter->misc_vector_name, netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +0000566 if (err) {
567 dev_err(&adapter->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -0800568 "request_irq for %s failed: %d\n",
569 adapter->misc_vector_name, err);
Greg Rose5eae00c2013-12-21 06:12:45 +0000570 free_irq(adapter->msix_entries[0].vector, netdev);
571 }
572 return err;
573}
574
575/**
576 * i40evf_free_traffic_irqs - Free MSI-X interrupts
577 * @adapter: board private structure
578 *
579 * Frees all MSI-X vectors other than 0.
580 **/
581static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter)
582{
583 int i;
584 int q_vectors;
Mitch Williams75a64432014-11-11 20:02:42 +0000585
Greg Rose5eae00c2013-12-21 06:12:45 +0000586 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
587
588 for (i = 0; i < q_vectors; i++) {
589 irq_set_affinity_hint(adapter->msix_entries[i+1].vector,
590 NULL);
591 free_irq(adapter->msix_entries[i+1].vector,
Mitch Williams7d96ba12015-10-26 19:44:39 -0400592 &adapter->q_vectors[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +0000593 }
594}
595
596/**
597 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
598 * @adapter: board private structure
599 *
600 * Frees MSI-X vector 0.
601 **/
602static void i40evf_free_misc_irq(struct i40evf_adapter *adapter)
603{
604 struct net_device *netdev = adapter->netdev;
605
606 free_irq(adapter->msix_entries[0].vector, netdev);
607}
608
609/**
610 * i40evf_configure_tx - Configure Transmit Unit after Reset
611 * @adapter: board private structure
612 *
613 * Configure the Tx unit of the MAC after a reset.
614 **/
615static void i40evf_configure_tx(struct i40evf_adapter *adapter)
616{
617 struct i40e_hw *hw = &adapter->hw;
618 int i;
Mitch Williams75a64432014-11-11 20:02:42 +0000619
Mitch Williamscc052922014-10-25 03:24:34 +0000620 for (i = 0; i < adapter->num_active_queues; i++)
Mitch Williams0dd438d2015-10-26 19:44:40 -0400621 adapter->tx_rings[i].tail = hw->hw_addr + I40E_QTX_TAIL1(i);
Greg Rose5eae00c2013-12-21 06:12:45 +0000622}
623
624/**
625 * i40evf_configure_rx - Configure Receive Unit after Reset
626 * @adapter: board private structure
627 *
628 * Configure the Rx unit of the MAC after a reset.
629 **/
630static void i40evf_configure_rx(struct i40evf_adapter *adapter)
631{
632 struct i40e_hw *hw = &adapter->hw;
633 struct net_device *netdev = adapter->netdev;
634 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
635 int i;
636 int rx_buf_len;
637
638
639 adapter->flags &= ~I40EVF_FLAG_RX_PS_CAPABLE;
640 adapter->flags |= I40EVF_FLAG_RX_1BUF_CAPABLE;
641
642 /* Decide whether to use packet split mode or not */
643 if (netdev->mtu > ETH_DATA_LEN) {
644 if (adapter->flags & I40EVF_FLAG_RX_PS_CAPABLE)
645 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
646 else
647 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
648 } else {
649 if (adapter->flags & I40EVF_FLAG_RX_1BUF_CAPABLE)
650 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
651 else
652 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
653 }
654
655 /* Set the RX buffer length according to the mode */
656 if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) {
657 rx_buf_len = I40E_RX_HDR_SIZE;
658 } else {
659 if (netdev->mtu <= ETH_DATA_LEN)
660 rx_buf_len = I40EVF_RXBUFFER_2048;
661 else
662 rx_buf_len = ALIGN(max_frame, 1024);
663 }
664
Mitch Williamscc052922014-10-25 03:24:34 +0000665 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williams0dd438d2015-10-26 19:44:40 -0400666 adapter->rx_rings[i].tail = hw->hw_addr + I40E_QRX_TAIL1(i);
667 adapter->rx_rings[i].rx_buf_len = rx_buf_len;
Greg Rose5eae00c2013-12-21 06:12:45 +0000668 }
669}
670
671/**
672 * i40evf_find_vlan - Search filter list for specific vlan filter
673 * @adapter: board private structure
674 * @vlan: vlan tag
675 *
676 * Returns ptr to the filter object or NULL
677 **/
678static struct
679i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan)
680{
681 struct i40evf_vlan_filter *f;
682
683 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
684 if (vlan == f->vlan)
685 return f;
686 }
687 return NULL;
688}
689
690/**
691 * i40evf_add_vlan - Add a vlan filter to the list
692 * @adapter: board private structure
693 * @vlan: VLAN tag
694 *
695 * Returns ptr to the filter object or NULL when no memory available.
696 **/
697static struct
698i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan)
699{
Mitch Williams13acb542015-03-31 00:45:05 -0700700 struct i40evf_vlan_filter *f = NULL;
701 int count = 50;
702
703 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
704 &adapter->crit_section)) {
705 udelay(1);
706 if (--count == 0)
707 goto out;
708 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000709
710 f = i40evf_find_vlan(adapter, vlan);
Mitch Williams348d4992014-11-11 20:02:52 +0000711 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000712 f = kzalloc(sizeof(*f), GFP_ATOMIC);
Mitch Williams348d4992014-11-11 20:02:52 +0000713 if (!f)
Mitch Williams13acb542015-03-31 00:45:05 -0700714 goto clearout;
Mitch Williams249c8b82014-05-10 04:49:04 +0000715
Greg Rose5eae00c2013-12-21 06:12:45 +0000716 f->vlan = vlan;
717
718 INIT_LIST_HEAD(&f->list);
719 list_add(&f->list, &adapter->vlan_filter_list);
720 f->add = true;
721 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
722 }
723
Mitch Williams13acb542015-03-31 00:45:05 -0700724clearout:
725 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
726out:
Greg Rose5eae00c2013-12-21 06:12:45 +0000727 return f;
728}
729
730/**
731 * i40evf_del_vlan - Remove a vlan filter from the list
732 * @adapter: board private structure
733 * @vlan: VLAN tag
734 **/
735static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan)
736{
737 struct i40evf_vlan_filter *f;
Mitch Williams13acb542015-03-31 00:45:05 -0700738 int count = 50;
739
740 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
741 &adapter->crit_section)) {
742 udelay(1);
743 if (--count == 0)
744 return;
745 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000746
747 f = i40evf_find_vlan(adapter, vlan);
748 if (f) {
749 f->remove = true;
750 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
751 }
Mitch Williams13acb542015-03-31 00:45:05 -0700752 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Greg Rose5eae00c2013-12-21 06:12:45 +0000753}
754
755/**
756 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
757 * @netdev: network device struct
758 * @vid: VLAN tag
759 **/
760static int i40evf_vlan_rx_add_vid(struct net_device *netdev,
Mitch Williams75a64432014-11-11 20:02:42 +0000761 __always_unused __be16 proto, u16 vid)
Greg Rose5eae00c2013-12-21 06:12:45 +0000762{
763 struct i40evf_adapter *adapter = netdev_priv(netdev);
764
Mitch Williams8ed995f2015-08-28 17:55:57 -0400765 if (!VLAN_ALLOWED(adapter))
766 return -EIO;
Greg Rose5eae00c2013-12-21 06:12:45 +0000767 if (i40evf_add_vlan(adapter, vid) == NULL)
768 return -ENOMEM;
769 return 0;
770}
771
772/**
773 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
774 * @netdev: network device struct
775 * @vid: VLAN tag
776 **/
777static int i40evf_vlan_rx_kill_vid(struct net_device *netdev,
Mitch Williams75a64432014-11-11 20:02:42 +0000778 __always_unused __be16 proto, u16 vid)
Greg Rose5eae00c2013-12-21 06:12:45 +0000779{
780 struct i40evf_adapter *adapter = netdev_priv(netdev);
781
Mitch Williams8ed995f2015-08-28 17:55:57 -0400782 if (VLAN_ALLOWED(adapter)) {
783 i40evf_del_vlan(adapter, vid);
784 return 0;
785 }
786 return -EIO;
Greg Rose5eae00c2013-12-21 06:12:45 +0000787}
788
789/**
790 * i40evf_find_filter - Search filter list for specific mac filter
791 * @adapter: board private structure
792 * @macaddr: the MAC address
793 *
794 * Returns ptr to the filter object or NULL
795 **/
796static struct
797i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter,
798 u8 *macaddr)
799{
800 struct i40evf_mac_filter *f;
801
802 if (!macaddr)
803 return NULL;
804
805 list_for_each_entry(f, &adapter->mac_filter_list, list) {
806 if (ether_addr_equal(macaddr, f->macaddr))
807 return f;
808 }
809 return NULL;
810}
811
812/**
813 * i40e_add_filter - Add a mac filter to the filter list
814 * @adapter: board private structure
815 * @macaddr: the MAC address
816 *
817 * Returns ptr to the filter object or NULL when no memory available.
818 **/
819static struct
820i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter,
821 u8 *macaddr)
822{
823 struct i40evf_mac_filter *f;
Mitch Williams54e16f62015-01-29 07:17:20 +0000824 int count = 50;
Greg Rose5eae00c2013-12-21 06:12:45 +0000825
826 if (!macaddr)
827 return NULL;
828
829 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
Mitch Williams54e16f62015-01-29 07:17:20 +0000830 &adapter->crit_section)) {
Mitch Williamsb65476c2014-07-09 07:46:14 +0000831 udelay(1);
Mitch Williams54e16f62015-01-29 07:17:20 +0000832 if (--count == 0)
833 return NULL;
834 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000835
836 f = i40evf_find_filter(adapter, macaddr);
Mitch Williams348d4992014-11-11 20:02:52 +0000837 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000838 f = kzalloc(sizeof(*f), GFP_ATOMIC);
Mitch Williams348d4992014-11-11 20:02:52 +0000839 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000840 clear_bit(__I40EVF_IN_CRITICAL_TASK,
841 &adapter->crit_section);
842 return NULL;
843 }
844
Greg Rose9a173902014-05-22 06:32:02 +0000845 ether_addr_copy(f->macaddr, macaddr);
Greg Rose5eae00c2013-12-21 06:12:45 +0000846
847 list_add(&f->list, &adapter->mac_filter_list);
848 f->add = true;
849 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
850 }
851
852 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
853 return f;
854}
855
856/**
857 * i40evf_set_mac - NDO callback to set port mac address
858 * @netdev: network interface device structure
859 * @p: pointer to an address structure
860 *
861 * Returns 0 on success, negative on failure
862 **/
863static int i40evf_set_mac(struct net_device *netdev, void *p)
864{
865 struct i40evf_adapter *adapter = netdev_priv(netdev);
866 struct i40e_hw *hw = &adapter->hw;
867 struct i40evf_mac_filter *f;
868 struct sockaddr *addr = p;
869
870 if (!is_valid_ether_addr(addr->sa_data))
871 return -EADDRNOTAVAIL;
872
873 if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
874 return 0;
875
Mitch Williams14e52ee2015-08-31 19:54:44 -0400876 if (adapter->flags & I40EVF_FLAG_ADDR_SET_BY_PF)
877 return -EPERM;
878
879 f = i40evf_find_filter(adapter, hw->mac.addr);
880 if (f) {
881 f->remove = true;
882 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
883 }
884
Greg Rose5eae00c2013-12-21 06:12:45 +0000885 f = i40evf_add_filter(adapter, addr->sa_data);
886 if (f) {
Greg Rose9a173902014-05-22 06:32:02 +0000887 ether_addr_copy(hw->mac.addr, addr->sa_data);
888 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +0000889 }
890
891 return (f == NULL) ? -ENOMEM : 0;
892}
893
894/**
895 * i40evf_set_rx_mode - NDO callback to set the netdev filters
896 * @netdev: network interface device structure
897 **/
898static void i40evf_set_rx_mode(struct net_device *netdev)
899{
900 struct i40evf_adapter *adapter = netdev_priv(netdev);
901 struct i40evf_mac_filter *f, *ftmp;
902 struct netdev_hw_addr *uca;
903 struct netdev_hw_addr *mca;
Shannon Nelson2f41f332015-08-26 15:14:20 -0400904 struct netdev_hw_addr *ha;
Mitch Williams54e16f62015-01-29 07:17:20 +0000905 int count = 50;
Greg Rose5eae00c2013-12-21 06:12:45 +0000906
907 /* add addr if not already in the filter list */
908 netdev_for_each_uc_addr(uca, netdev) {
909 i40evf_add_filter(adapter, uca->addr);
910 }
911 netdev_for_each_mc_addr(mca, netdev) {
912 i40evf_add_filter(adapter, mca->addr);
913 }
914
915 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
Mitch Williams54e16f62015-01-29 07:17:20 +0000916 &adapter->crit_section)) {
Mitch Williamsb65476c2014-07-09 07:46:14 +0000917 udelay(1);
Mitch Williams54e16f62015-01-29 07:17:20 +0000918 if (--count == 0) {
919 dev_err(&adapter->pdev->dev,
920 "Failed to get lock in %s\n", __func__);
921 return;
922 }
923 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000924 /* remove filter if not in netdev list */
925 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
Shannon Nelson2f41f332015-08-26 15:14:20 -0400926 netdev_for_each_mc_addr(mca, netdev)
927 if (ether_addr_equal(mca->addr, f->macaddr))
928 goto bottom_of_search_loop;
Greg Rose5eae00c2013-12-21 06:12:45 +0000929
Shannon Nelson2f41f332015-08-26 15:14:20 -0400930 netdev_for_each_uc_addr(uca, netdev)
931 if (ether_addr_equal(uca->addr, f->macaddr))
932 goto bottom_of_search_loop;
933
934 for_each_dev_addr(netdev, ha)
935 if (ether_addr_equal(ha->addr, f->macaddr))
936 goto bottom_of_search_loop;
937
938 if (ether_addr_equal(f->macaddr, adapter->hw.mac.addr))
939 goto bottom_of_search_loop;
940
941 /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
942 f->remove = true;
943 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
944
945bottom_of_search_loop:
946 continue;
Greg Rose5eae00c2013-12-21 06:12:45 +0000947 }
948 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
949}
950
951/**
952 * i40evf_napi_enable_all - enable NAPI on all queue vectors
953 * @adapter: board private structure
954 **/
955static void i40evf_napi_enable_all(struct i40evf_adapter *adapter)
956{
957 int q_idx;
958 struct i40e_q_vector *q_vector;
959 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
960
961 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
962 struct napi_struct *napi;
Mitch Williams75a64432014-11-11 20:02:42 +0000963
Mitch Williams7d96ba12015-10-26 19:44:39 -0400964 q_vector = &adapter->q_vectors[q_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +0000965 napi = &q_vector->napi;
966 napi_enable(napi);
967 }
968}
969
970/**
971 * i40evf_napi_disable_all - disable NAPI on all queue vectors
972 * @adapter: board private structure
973 **/
974static void i40evf_napi_disable_all(struct i40evf_adapter *adapter)
975{
976 int q_idx;
977 struct i40e_q_vector *q_vector;
978 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
979
980 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -0400981 q_vector = &adapter->q_vectors[q_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +0000982 napi_disable(&q_vector->napi);
983 }
984}
985
986/**
987 * i40evf_configure - set up transmit and receive data structures
988 * @adapter: board private structure
989 **/
990static void i40evf_configure(struct i40evf_adapter *adapter)
991{
992 struct net_device *netdev = adapter->netdev;
993 int i;
994
995 i40evf_set_rx_mode(netdev);
996
997 i40evf_configure_tx(adapter);
998 i40evf_configure_rx(adapter);
999 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
1000
Mitch Williamscc052922014-10-25 03:24:34 +00001001 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williams0dd438d2015-10-26 19:44:40 -04001002 struct i40e_ring *ring = &adapter->rx_rings[i];
Mitch Williams75a64432014-11-11 20:02:42 +00001003
Mitch Williamsa132af22015-01-24 09:58:35 +00001004 i40evf_alloc_rx_buffers_1buf(ring, ring->count);
Greg Rose5eae00c2013-12-21 06:12:45 +00001005 ring->next_to_use = ring->count - 1;
1006 writel(ring->next_to_use, ring->tail);
1007 }
1008}
1009
1010/**
1011 * i40evf_up_complete - Finish the last steps of bringing up a connection
1012 * @adapter: board private structure
1013 **/
1014static int i40evf_up_complete(struct i40evf_adapter *adapter)
1015{
1016 adapter->state = __I40EVF_RUNNING;
1017 clear_bit(__I40E_DOWN, &adapter->vsi.state);
1018
1019 i40evf_napi_enable_all(adapter);
1020
1021 adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
1022 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
1023 return 0;
1024}
1025
1026/**
Greg Rose5eae00c2013-12-21 06:12:45 +00001027 * i40e_down - Shutdown the connection processing
1028 * @adapter: board private structure
1029 **/
1030void i40evf_down(struct i40evf_adapter *adapter)
1031{
1032 struct net_device *netdev = adapter->netdev;
1033 struct i40evf_mac_filter *f;
1034
Mitch Williams209dc4d2015-12-09 15:50:27 -08001035 if (adapter->state <= __I40EVF_DOWN_PENDING)
Mitch Williamsddf0b3a2014-05-22 06:31:46 +00001036 return;
1037
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001038 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1039 &adapter->crit_section))
1040 usleep_range(500, 1000);
1041
Mitch Williams63e18c22015-03-27 00:12:10 -07001042 netif_carrier_off(netdev);
1043 netif_tx_disable(netdev);
Mitch Williams748c4342015-01-29 07:17:18 +00001044 i40evf_napi_disable_all(adapter);
Mitch Williams63e18c22015-03-27 00:12:10 -07001045 i40evf_irq_disable(adapter);
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001046
Mitch Williamsef8693e2014-02-13 03:48:53 -08001047 /* remove all MAC filters */
Greg Rose5eae00c2013-12-21 06:12:45 +00001048 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1049 f->remove = true;
1050 }
Mitch Williamsed1f5b52014-02-20 19:29:06 -08001051 /* remove all VLAN filters */
1052 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
1053 f->remove = true;
1054 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001055 if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) &&
1056 adapter->state != __I40EVF_RESETTING) {
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001057 /* cancel any current operation */
1058 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001059 /* Schedule operations to close down the HW. Don't wait
1060 * here for this to complete. The watchdog is still running
1061 * and it will take care of this.
1062 */
1063 adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Mitch Williamsed1f5b52014-02-20 19:29:06 -08001064 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001065 adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001066 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001067
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001068 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Greg Rose5eae00c2013-12-21 06:12:45 +00001069}
1070
1071/**
1072 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1073 * @adapter: board private structure
1074 * @vectors: number of vectors to request
1075 *
1076 * Work with the OS to set up the MSIX vectors needed.
1077 *
1078 * Returns 0 on success, negative on failure
1079 **/
1080static int
1081i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors)
1082{
1083 int err, vector_threshold;
1084
1085 /* We'll want at least 3 (vector_threshold):
1086 * 0) Other (Admin Queue and link, mostly)
1087 * 1) TxQ[0] Cleanup
1088 * 2) RxQ[0] Cleanup
1089 */
1090 vector_threshold = MIN_MSIX_COUNT;
1091
1092 /* The more we get, the more we will assign to Tx/Rx Cleanup
1093 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1094 * Right now, we simply care about how many we'll get; we'll
1095 * set them up later while requesting irq's.
1096 */
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001097 err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
1098 vector_threshold, vectors);
1099 if (err < 0) {
Mitch Williams80e72892014-05-10 04:49:06 +00001100 dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001101 kfree(adapter->msix_entries);
1102 adapter->msix_entries = NULL;
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001103 return err;
Greg Rose5eae00c2013-12-21 06:12:45 +00001104 }
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001105
1106 /* Adjust for only the vectors we'll use, which is minimum
1107 * of max_msix_q_vectors + NONQ_VECS, or the number of
1108 * vectors we were allocated.
1109 */
1110 adapter->num_msix_vectors = err;
1111 return 0;
Greg Rose5eae00c2013-12-21 06:12:45 +00001112}
1113
1114/**
1115 * i40evf_free_queues - Free memory for all rings
1116 * @adapter: board private structure to initialize
1117 *
1118 * Free all of the memory associated with queue pairs.
1119 **/
1120static void i40evf_free_queues(struct i40evf_adapter *adapter)
1121{
Greg Rose5eae00c2013-12-21 06:12:45 +00001122 if (!adapter->vsi_res)
1123 return;
Mitch Williams0dd438d2015-10-26 19:44:40 -04001124 kfree(adapter->tx_rings);
Mitch Williams10311542015-12-09 15:50:30 -08001125 adapter->tx_rings = NULL;
Mitch Williams0dd438d2015-10-26 19:44:40 -04001126 kfree(adapter->rx_rings);
Mitch Williams10311542015-12-09 15:50:30 -08001127 adapter->rx_rings = NULL;
Greg Rose5eae00c2013-12-21 06:12:45 +00001128}
1129
1130/**
1131 * i40evf_alloc_queues - Allocate memory for all rings
1132 * @adapter: board private structure to initialize
1133 *
1134 * We allocate one ring per queue at run-time since we don't know the
1135 * number of queues at compile-time. The polling_netdev array is
1136 * intended for Multiqueue, but should work fine with a single queue.
1137 **/
1138static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
1139{
1140 int i;
1141
Mitch Williams0dd438d2015-10-26 19:44:40 -04001142 adapter->tx_rings = kcalloc(adapter->num_active_queues,
1143 sizeof(struct i40e_ring), GFP_KERNEL);
1144 if (!adapter->tx_rings)
1145 goto err_out;
1146 adapter->rx_rings = kcalloc(adapter->num_active_queues,
1147 sizeof(struct i40e_ring), GFP_KERNEL);
1148 if (!adapter->rx_rings)
1149 goto err_out;
1150
Mitch Williamscc052922014-10-25 03:24:34 +00001151 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001152 struct i40e_ring *tx_ring;
1153 struct i40e_ring *rx_ring;
1154
Mitch Williams0dd438d2015-10-26 19:44:40 -04001155 tx_ring = &adapter->tx_rings[i];
Greg Rose5eae00c2013-12-21 06:12:45 +00001156
1157 tx_ring->queue_index = i;
1158 tx_ring->netdev = adapter->netdev;
1159 tx_ring->dev = &adapter->pdev->dev;
Mitch Williamsd732a182014-04-24 06:41:37 +00001160 tx_ring->count = adapter->tx_desc_count;
Anjali Singhai Jain1f012272015-09-03 17:18:53 -04001161 if (adapter->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
1162 tx_ring->flags |= I40E_TXR_FLAGS_WB_ON_ITR;
Greg Rose5eae00c2013-12-21 06:12:45 +00001163
Mitch Williams0dd438d2015-10-26 19:44:40 -04001164 rx_ring = &adapter->rx_rings[i];
Greg Rose5eae00c2013-12-21 06:12:45 +00001165 rx_ring->queue_index = i;
1166 rx_ring->netdev = adapter->netdev;
1167 rx_ring->dev = &adapter->pdev->dev;
Mitch Williamsd732a182014-04-24 06:41:37 +00001168 rx_ring->count = adapter->rx_desc_count;
Greg Rose5eae00c2013-12-21 06:12:45 +00001169 }
1170
1171 return 0;
1172
1173err_out:
1174 i40evf_free_queues(adapter);
1175 return -ENOMEM;
1176}
1177
1178/**
1179 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1180 * @adapter: board private structure to initialize
1181 *
1182 * Attempt to configure the interrupts using the best available
1183 * capabilities of the hardware and the kernel.
1184 **/
1185static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter)
1186{
1187 int vector, v_budget;
1188 int pairs = 0;
1189 int err = 0;
1190
1191 if (!adapter->vsi_res) {
1192 err = -EIO;
1193 goto out;
1194 }
Mitch Williamscc052922014-10-25 03:24:34 +00001195 pairs = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +00001196
1197 /* It's easy to be greedy for MSI-X vectors, but it really
1198 * doesn't do us much good if we have a lot more vectors
1199 * than CPU's. So let's be conservative and only ask for
1200 * (roughly) twice the number of vectors as there are CPU's.
1201 */
Mitch Williams30a500e2014-02-11 08:27:52 +00001202 v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS;
1203 v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors);
Greg Rose5eae00c2013-12-21 06:12:45 +00001204
Greg Rose5eae00c2013-12-21 06:12:45 +00001205 adapter->msix_entries = kcalloc(v_budget,
1206 sizeof(struct msix_entry), GFP_KERNEL);
1207 if (!adapter->msix_entries) {
1208 err = -ENOMEM;
1209 goto out;
1210 }
1211
1212 for (vector = 0; vector < v_budget; vector++)
1213 adapter->msix_entries[vector].entry = vector;
1214
Mitch Williams313ed2d2015-08-27 11:42:31 -04001215 err = i40evf_acquire_msix_vectors(adapter, v_budget);
Greg Rose5eae00c2013-12-21 06:12:45 +00001216
1217out:
Mitch Williamse6c4cf62015-11-06 15:26:00 -08001218 netif_set_real_num_rx_queues(adapter->netdev, pairs);
1219 netif_set_real_num_tx_queues(adapter->netdev, pairs);
Greg Rose5eae00c2013-12-21 06:12:45 +00001220 return err;
1221}
1222
1223/**
Helin Zhang2c86ac32015-10-27 16:15:06 -04001224 * i40e_config_rss_aq - Prepare for RSS using AQ commands
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001225 * @vsi: vsi structure
1226 * @seed: RSS hash seed
Helin Zhang2c86ac32015-10-27 16:15:06 -04001227 * @lut: Lookup table
1228 * @lut_size: Lookup table size
1229 *
1230 * Return 0 on success, negative on failure
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001231 **/
Helin Zhang2c86ac32015-10-27 16:15:06 -04001232static int i40evf_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
1233 u8 *lut, u16 lut_size)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001234{
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001235 struct i40evf_adapter *adapter = vsi->back;
1236 struct i40e_hw *hw = &adapter->hw;
Helin Zhang2c86ac32015-10-27 16:15:06 -04001237 int ret = 0;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001238
1239 if (!vsi->id)
Helin Zhang2c86ac32015-10-27 16:15:06 -04001240 return -EINVAL;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001241
1242 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
1243 /* bail because we already have a command pending */
Masanari Iidae3d132d2015-10-16 21:14:29 +09001244 dev_err(&adapter->pdev->dev, "Cannot configure RSS, command %d pending\n",
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001245 adapter->current_op);
Helin Zhang2c86ac32015-10-27 16:15:06 -04001246 return -EBUSY;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001247 }
1248
Helin Zhang2c86ac32015-10-27 16:15:06 -04001249 if (seed) {
1250 struct i40e_aqc_get_set_rss_key_data *rss_key =
1251 (struct i40e_aqc_get_set_rss_key_data *)seed;
1252 ret = i40evf_aq_set_rss_key(hw, vsi->id, rss_key);
1253 if (ret) {
1254 dev_err(&adapter->pdev->dev, "Cannot set RSS key, err %s aq_err %s\n",
1255 i40evf_stat_str(hw, ret),
1256 i40evf_aq_str(hw, hw->aq.asq_last_status));
1257 return ret;
1258 }
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001259 }
1260
Helin Zhang2c86ac32015-10-27 16:15:06 -04001261 if (lut) {
1262 ret = i40evf_aq_set_rss_lut(hw, vsi->id, false, lut, lut_size);
1263 if (ret) {
1264 dev_err(&adapter->pdev->dev,
1265 "Cannot set RSS lut, err %s aq_err %s\n",
1266 i40evf_stat_str(hw, ret),
1267 i40evf_aq_str(hw, hw->aq.asq_last_status));
1268 return ret;
1269 }
1270 }
1271
1272 return ret;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001273}
1274
1275/**
Helin Zhang2c86ac32015-10-27 16:15:06 -04001276 * i40evf_config_rss_reg - Configure RSS keys and lut by writing registers
1277 * @vsi: Pointer to vsi structure
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001278 * @seed: RSS hash seed
Helin Zhang2c86ac32015-10-27 16:15:06 -04001279 * @lut: Lookup table
1280 * @lut_size: Lookup table size
1281 *
1282 * Returns 0 on success, negative on failure
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001283 **/
Helin Zhang2c86ac32015-10-27 16:15:06 -04001284static int i40evf_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
1285 const u8 *lut, u16 lut_size)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001286{
Helin Zhang2c86ac32015-10-27 16:15:06 -04001287 struct i40evf_adapter *adapter = vsi->back;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001288 struct i40e_hw *hw = &adapter->hw;
Helin Zhang2c86ac32015-10-27 16:15:06 -04001289 u16 i;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001290
Helin Zhang2c86ac32015-10-27 16:15:06 -04001291 if (seed) {
1292 u32 *seed_dw = (u32 *)seed;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001293
Helin Zhang2c86ac32015-10-27 16:15:06 -04001294 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1295 wr32(hw, I40E_VFQF_HKEY(i), seed_dw[i]);
1296 }
1297
1298 if (lut) {
1299 u32 *lut_dw = (u32 *)lut;
1300
1301 if (lut_size != I40EVF_HLUT_ARRAY_SIZE)
1302 return -EINVAL;
1303
1304 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
1305 wr32(hw, I40E_VFQF_HLUT(i), lut_dw[i]);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001306 }
1307 i40e_flush(hw);
Helin Zhang2c86ac32015-10-27 16:15:06 -04001308
1309 return 0;
1310}
1311
1312/**
Helin Zhang90b02b42015-10-26 19:44:33 -04001313 * * i40evf_get_rss_aq - Get RSS keys and lut by using AQ commands
1314 * @vsi: Pointer to vsi structure
1315 * @seed: RSS hash seed
1316 * @lut: Lookup table
1317 * @lut_size: Lookup table size
1318 *
1319 * Return 0 on success, negative on failure
1320 **/
1321static int i40evf_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
1322 u8 *lut, u16 lut_size)
1323{
1324 struct i40evf_adapter *adapter = vsi->back;
1325 struct i40e_hw *hw = &adapter->hw;
1326 int ret = 0;
1327
1328 if (seed) {
1329 ret = i40evf_aq_get_rss_key(hw, vsi->id,
1330 (struct i40e_aqc_get_set_rss_key_data *)seed);
1331 if (ret) {
1332 dev_err(&adapter->pdev->dev,
1333 "Cannot get RSS key, err %s aq_err %s\n",
1334 i40evf_stat_str(hw, ret),
1335 i40evf_aq_str(hw, hw->aq.asq_last_status));
1336 return ret;
1337 }
1338 }
1339
1340 if (lut) {
1341 ret = i40evf_aq_get_rss_lut(hw, vsi->id, seed, lut, lut_size);
1342 if (ret) {
1343 dev_err(&adapter->pdev->dev,
1344 "Cannot get RSS lut, err %s aq_err %s\n",
1345 i40evf_stat_str(hw, ret),
1346 i40evf_aq_str(hw, hw->aq.asq_last_status));
1347 return ret;
1348 }
1349 }
1350
1351 return ret;
1352}
1353
1354/**
1355 * * i40evf_get_rss_reg - Get RSS keys and lut by reading registers
1356 * @vsi: Pointer to vsi structure
1357 * @seed: RSS hash seed
1358 * @lut: Lookup table
1359 * @lut_size: Lookup table size
1360 *
1361 * Returns 0 on success, negative on failure
1362 **/
1363static int i40evf_get_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
1364 const u8 *lut, u16 lut_size)
1365{
1366 struct i40evf_adapter *adapter = vsi->back;
1367 struct i40e_hw *hw = &adapter->hw;
1368 u16 i;
1369
1370 if (seed) {
1371 u32 *seed_dw = (u32 *)seed;
1372
1373 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1374 seed_dw[i] = rd32(hw, I40E_VFQF_HKEY(i));
1375 }
1376
1377 if (lut) {
1378 u32 *lut_dw = (u32 *)lut;
1379
1380 if (lut_size != I40EVF_HLUT_ARRAY_SIZE)
1381 return -EINVAL;
1382
1383 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
1384 lut_dw[i] = rd32(hw, I40E_VFQF_HLUT(i));
1385 }
1386
1387 return 0;
1388}
1389
1390/**
Helin Zhang2c86ac32015-10-27 16:15:06 -04001391 * i40evf_config_rss - Configure RSS keys and lut
1392 * @vsi: Pointer to vsi structure
1393 * @seed: RSS hash seed
1394 * @lut: Lookup table
1395 * @lut_size: Lookup table size
1396 *
1397 * Returns 0 on success, negative on failure
1398 **/
1399int i40evf_config_rss(struct i40e_vsi *vsi, const u8 *seed,
1400 u8 *lut, u16 lut_size)
1401{
1402 struct i40evf_adapter *adapter = vsi->back;
1403
1404 if (RSS_AQ(adapter))
1405 return i40evf_config_rss_aq(vsi, seed, lut, lut_size);
1406 else
1407 return i40evf_config_rss_reg(vsi, seed, lut, lut_size);
1408}
1409
1410/**
Helin Zhang90b02b42015-10-26 19:44:33 -04001411 * i40evf_get_rss - Get RSS keys and lut
1412 * @vsi: Pointer to vsi structure
1413 * @seed: RSS hash seed
1414 * @lut: Lookup table
1415 * @lut_size: Lookup table size
1416 *
1417 * Returns 0 on success, negative on failure
1418 **/
1419int i40evf_get_rss(struct i40e_vsi *vsi, const u8 *seed, u8 *lut, u16 lut_size)
1420{
1421 struct i40evf_adapter *adapter = vsi->back;
1422
1423 if (RSS_AQ(adapter))
1424 return i40evf_get_rss_aq(vsi, seed, lut, lut_size);
1425 else
1426 return i40evf_get_rss_reg(vsi, seed, lut, lut_size);
1427}
1428
1429/**
Helin Zhang2c86ac32015-10-27 16:15:06 -04001430 * i40evf_fill_rss_lut - Fill the lut with default values
1431 * @lut: Lookup table to be filled with
1432 * @rss_table_size: Lookup table size
1433 * @rss_size: Range of queue number for hashing
1434 **/
1435static void i40evf_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
1436{
1437 u16 i;
1438
1439 for (i = 0; i < rss_table_size; i++)
1440 lut[i] = i % rss_size;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001441}
1442
1443/**
Helin Zhang96a81982015-10-26 19:44:31 -04001444 * i40evf_init_rss - Prepare for RSS
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001445 * @adapter: board private structure
Helin Zhang2c86ac32015-10-27 16:15:06 -04001446 *
1447 * Return 0 on success, negative on failure
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001448 **/
Helin Zhang2c86ac32015-10-27 16:15:06 -04001449static int i40evf_init_rss(struct i40evf_adapter *adapter)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001450{
Helin Zhang2c86ac32015-10-27 16:15:06 -04001451 struct i40e_vsi *vsi = &adapter->vsi;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001452 struct i40e_hw *hw = &adapter->hw;
1453 u8 seed[I40EVF_HKEY_ARRAY_SIZE];
1454 u64 hena;
Helin Zhang2c86ac32015-10-27 16:15:06 -04001455 u8 *lut;
1456 int ret;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001457
1458 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08001459 if (adapter->vf_res->vf_offload_flags &
1460 I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
1461 hena = I40E_DEFAULT_RSS_HENA_EXPANDED;
1462 else
1463 hena = I40E_DEFAULT_RSS_HENA;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001464 wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
1465 wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
1466
Helin Zhang2c86ac32015-10-27 16:15:06 -04001467 lut = kzalloc(I40EVF_HLUT_ARRAY_SIZE, GFP_KERNEL);
1468 if (!lut)
1469 return -ENOMEM;
Helin Zhang66f9af852015-10-26 19:44:34 -04001470
1471 /* Use user configured lut if there is one, otherwise use default */
1472 if (vsi->rss_lut_user)
1473 memcpy(lut, vsi->rss_lut_user, I40EVF_HLUT_ARRAY_SIZE);
1474 else
1475 i40evf_fill_rss_lut(lut, I40EVF_HLUT_ARRAY_SIZE,
1476 adapter->num_active_queues);
1477
1478 /* Use user configured hash key if there is one, otherwise
1479 * user default.
1480 */
1481 if (vsi->rss_hkey_user)
1482 memcpy(seed, vsi->rss_hkey_user, I40EVF_HKEY_ARRAY_SIZE);
1483 else
1484 netdev_rss_key_fill((void *)seed, I40EVF_HKEY_ARRAY_SIZE);
Helin Zhang2c86ac32015-10-27 16:15:06 -04001485 ret = i40evf_config_rss(vsi, seed, lut, I40EVF_HLUT_ARRAY_SIZE);
1486 kfree(lut);
1487
1488 return ret;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001489}
1490
1491/**
Greg Rose5eae00c2013-12-21 06:12:45 +00001492 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1493 * @adapter: board private structure to initialize
1494 *
1495 * We allocate one q_vector per queue interrupt. If allocation fails we
1496 * return -ENOMEM.
1497 **/
1498static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
1499{
Mitch Williams7d96ba12015-10-26 19:44:39 -04001500 int q_idx = 0, num_q_vectors;
Greg Rose5eae00c2013-12-21 06:12:45 +00001501 struct i40e_q_vector *q_vector;
1502
1503 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
Mitch Williams0dd438d2015-10-26 19:44:40 -04001504 adapter->q_vectors = kcalloc(num_q_vectors, sizeof(*q_vector),
Mitch Williams7d96ba12015-10-26 19:44:39 -04001505 GFP_KERNEL);
1506 if (!adapter->q_vectors)
1507 goto err_out;
Greg Rose5eae00c2013-12-21 06:12:45 +00001508
1509 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -04001510 q_vector = &adapter->q_vectors[q_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +00001511 q_vector->adapter = adapter;
1512 q_vector->vsi = &adapter->vsi;
1513 q_vector->v_idx = q_idx;
1514 netif_napi_add(adapter->netdev, &q_vector->napi,
Mitch Williams75a64432014-11-11 20:02:42 +00001515 i40evf_napi_poll, NAPI_POLL_WEIGHT);
Greg Rose5eae00c2013-12-21 06:12:45 +00001516 }
1517
1518 return 0;
1519
1520err_out:
1521 while (q_idx) {
1522 q_idx--;
Mitch Williams7d96ba12015-10-26 19:44:39 -04001523 q_vector = &adapter->q_vectors[q_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +00001524 netif_napi_del(&q_vector->napi);
Greg Rose5eae00c2013-12-21 06:12:45 +00001525 }
Mitch Williams7d96ba12015-10-26 19:44:39 -04001526 kfree(adapter->q_vectors);
Greg Rose5eae00c2013-12-21 06:12:45 +00001527 return -ENOMEM;
1528}
1529
1530/**
1531 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1532 * @adapter: board private structure to initialize
1533 *
1534 * This function frees the memory allocated to the q_vectors. In addition if
1535 * NAPI is enabled it will delete any references to the NAPI struct prior
1536 * to freeing the q_vector.
1537 **/
1538static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
1539{
1540 int q_idx, num_q_vectors;
1541 int napi_vectors;
1542
1543 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
Mitch Williamscc052922014-10-25 03:24:34 +00001544 napi_vectors = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +00001545
1546 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -04001547 struct i40e_q_vector *q_vector = &adapter->q_vectors[q_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +00001548 if (q_idx < napi_vectors)
1549 netif_napi_del(&q_vector->napi);
Greg Rose5eae00c2013-12-21 06:12:45 +00001550 }
Mitch Williams7d96ba12015-10-26 19:44:39 -04001551 kfree(adapter->q_vectors);
Greg Rose5eae00c2013-12-21 06:12:45 +00001552}
1553
1554/**
1555 * i40evf_reset_interrupt_capability - Reset MSIX setup
1556 * @adapter: board private structure
1557 *
1558 **/
1559void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
1560{
1561 pci_disable_msix(adapter->pdev);
1562 kfree(adapter->msix_entries);
1563 adapter->msix_entries = NULL;
Greg Rose5eae00c2013-12-21 06:12:45 +00001564}
1565
1566/**
1567 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1568 * @adapter: board private structure to initialize
1569 *
1570 **/
1571int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
1572{
1573 int err;
1574
1575 err = i40evf_set_interrupt_capability(adapter);
1576 if (err) {
1577 dev_err(&adapter->pdev->dev,
1578 "Unable to setup interrupt capabilities\n");
1579 goto err_set_interrupt;
1580 }
1581
1582 err = i40evf_alloc_q_vectors(adapter);
1583 if (err) {
1584 dev_err(&adapter->pdev->dev,
1585 "Unable to allocate memory for queue vectors\n");
1586 goto err_alloc_q_vectors;
1587 }
1588
1589 err = i40evf_alloc_queues(adapter);
1590 if (err) {
1591 dev_err(&adapter->pdev->dev,
1592 "Unable to allocate memory for queues\n");
1593 goto err_alloc_queues;
1594 }
1595
1596 dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
Mitch Williams75a64432014-11-11 20:02:42 +00001597 (adapter->num_active_queues > 1) ? "Enabled" : "Disabled",
1598 adapter->num_active_queues);
Greg Rose5eae00c2013-12-21 06:12:45 +00001599
1600 return 0;
1601err_alloc_queues:
1602 i40evf_free_q_vectors(adapter);
1603err_alloc_q_vectors:
1604 i40evf_reset_interrupt_capability(adapter);
1605err_set_interrupt:
1606 return err;
1607}
1608
1609/**
Helin Zhang66f9af852015-10-26 19:44:34 -04001610 * i40evf_clear_rss_config_user - Clear user configurations of RSS
1611 * @vsi: Pointer to VSI structure
1612 **/
1613static void i40evf_clear_rss_config_user(struct i40e_vsi *vsi)
1614{
1615 if (!vsi)
1616 return;
1617
1618 kfree(vsi->rss_hkey_user);
1619 vsi->rss_hkey_user = NULL;
1620
1621 kfree(vsi->rss_lut_user);
1622 vsi->rss_lut_user = NULL;
1623}
1624
1625/**
Greg Rose5eae00c2013-12-21 06:12:45 +00001626 * i40evf_watchdog_timer - Periodic call-back timer
1627 * @data: pointer to adapter disguised as unsigned long
1628 **/
1629static void i40evf_watchdog_timer(unsigned long data)
1630{
1631 struct i40evf_adapter *adapter = (struct i40evf_adapter *)data;
Mitch Williams75a64432014-11-11 20:02:42 +00001632
Greg Rose5eae00c2013-12-21 06:12:45 +00001633 schedule_work(&adapter->watchdog_task);
1634 /* timer will be rescheduled in watchdog task */
1635}
1636
1637/**
1638 * i40evf_watchdog_task - Periodic call-back task
1639 * @work: pointer to work_struct
1640 **/
1641static void i40evf_watchdog_task(struct work_struct *work)
1642{
1643 struct i40evf_adapter *adapter = container_of(work,
Mitch Williams75a64432014-11-11 20:02:42 +00001644 struct i40evf_adapter,
1645 watchdog_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00001646 struct i40e_hw *hw = &adapter->hw;
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001647 u32 reg_val;
Greg Rose5eae00c2013-12-21 06:12:45 +00001648
Greg Rose5eae00c2013-12-21 06:12:45 +00001649 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section))
Mitch Williamsef8693e2014-02-13 03:48:53 -08001650 goto restart_watchdog;
1651
1652 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001653 reg_val = rd32(hw, I40E_VFGEN_RSTAT) &
1654 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1655 if ((reg_val == I40E_VFR_VFACTIVE) ||
1656 (reg_val == I40E_VFR_COMPLETED)) {
Mitch Williamsef8693e2014-02-13 03:48:53 -08001657 /* A chance for redemption! */
1658 dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
1659 adapter->state = __I40EVF_STARTUP;
1660 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1661 schedule_delayed_work(&adapter->init_task, 10);
1662 clear_bit(__I40EVF_IN_CRITICAL_TASK,
1663 &adapter->crit_section);
1664 /* Don't reschedule the watchdog, since we've restarted
1665 * the init task. When init_task contacts the PF and
1666 * gets everything set up again, it'll restart the
1667 * watchdog for us. Down, boy. Sit. Stay. Woof.
1668 */
1669 return;
1670 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001671 adapter->aq_required = 0;
1672 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1673 goto watchdog_done;
1674 }
1675
1676 if ((adapter->state < __I40EVF_DOWN) ||
1677 (adapter->flags & I40EVF_FLAG_RESET_PENDING))
Greg Rose5eae00c2013-12-21 06:12:45 +00001678 goto watchdog_done;
1679
Mitch Williamsef8693e2014-02-13 03:48:53 -08001680 /* check for reset */
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001681 reg_val = rd32(hw, I40E_VF_ARQLEN1) & I40E_VF_ARQLEN1_ARQENABLE_MASK;
1682 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) && !reg_val) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001683 adapter->state = __I40EVF_RESETTING;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001684 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
Mitch Williams249c8b82014-05-10 04:49:04 +00001685 dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001686 schedule_work(&adapter->reset_task);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001687 adapter->aq_required = 0;
1688 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001689 goto watchdog_done;
1690 }
1691
1692 /* Process admin queue tasks. After init, everything gets done
1693 * here so we don't race on the admin queue.
1694 */
Mitch Williamsed636962015-04-07 19:45:32 -04001695 if (adapter->current_op) {
Mitch A Williams0758e7cb2014-12-09 08:53:08 +00001696 if (!i40evf_asq_done(hw)) {
1697 dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n");
1698 i40evf_send_api_ver(adapter);
1699 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001700 goto watchdog_done;
Mitch A Williams0758e7cb2014-12-09 08:53:08 +00001701 }
Mitch Williamse6d038d2015-06-04 16:23:58 -04001702 if (adapter->aq_required & I40EVF_FLAG_AQ_GET_CONFIG) {
1703 i40evf_send_vf_config_msg(adapter);
1704 goto watchdog_done;
1705 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001706
Mitch Williamse284fc82015-03-27 00:12:09 -07001707 if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) {
1708 i40evf_disable_queues(adapter);
1709 goto watchdog_done;
1710 }
1711
Greg Rose5eae00c2013-12-21 06:12:45 +00001712 if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) {
1713 i40evf_map_queues(adapter);
1714 goto watchdog_done;
1715 }
1716
1717 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) {
1718 i40evf_add_ether_addrs(adapter);
1719 goto watchdog_done;
1720 }
1721
1722 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) {
1723 i40evf_add_vlans(adapter);
1724 goto watchdog_done;
1725 }
1726
1727 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) {
1728 i40evf_del_ether_addrs(adapter);
1729 goto watchdog_done;
1730 }
1731
1732 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) {
1733 i40evf_del_vlans(adapter);
1734 goto watchdog_done;
1735 }
1736
Greg Rose5eae00c2013-12-21 06:12:45 +00001737 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) {
1738 i40evf_configure_queues(adapter);
1739 goto watchdog_done;
1740 }
1741
1742 if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) {
1743 i40evf_enable_queues(adapter);
1744 goto watchdog_done;
1745 }
1746
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001747 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_RSS) {
1748 /* This message goes straight to the firmware, not the
1749 * PF, so we don't have to set current_op as we will
1750 * not get a response through the ARQ.
1751 */
Helin Zhang96a81982015-10-26 19:44:31 -04001752 i40evf_init_rss(adapter);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001753 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_RSS;
1754 goto watchdog_done;
1755 }
1756
Greg Rose5eae00c2013-12-21 06:12:45 +00001757 if (adapter->state == __I40EVF_RUNNING)
1758 i40evf_request_stats(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001759watchdog_done:
Mitch A Williams4870e172014-12-09 08:53:06 +00001760 if (adapter->state == __I40EVF_RUNNING) {
1761 i40evf_irq_enable_queues(adapter, ~0);
1762 i40evf_fire_sw_int(adapter, 0xFF);
1763 } else {
1764 i40evf_fire_sw_int(adapter, 0x1);
1765 }
1766
Mitch Williamsef8693e2014-02-13 03:48:53 -08001767 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1768restart_watchdog:
Ashish Shahd3e2edb2014-08-01 13:27:12 -07001769 if (adapter->state == __I40EVF_REMOVE)
1770 return;
Greg Rose5eae00c2013-12-21 06:12:45 +00001771 if (adapter->aq_required)
1772 mod_timer(&adapter->watchdog_timer,
1773 jiffies + msecs_to_jiffies(20));
1774 else
1775 mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2));
Greg Rose5eae00c2013-12-21 06:12:45 +00001776 schedule_work(&adapter->adminq_task);
1777}
1778
Mitch Williams67c818a2015-06-19 08:56:30 -07001779#define I40EVF_RESET_WAIT_MS 10
1780#define I40EVF_RESET_WAIT_COUNT 500
Greg Rose5eae00c2013-12-21 06:12:45 +00001781/**
1782 * i40evf_reset_task - Call-back task to handle hardware reset
1783 * @work: pointer to work_struct
1784 *
1785 * During reset we need to shut down and reinitialize the admin queue
1786 * before we can use it to communicate with the PF again. We also clear
1787 * and reinit the rings because that context is lost as well.
1788 **/
1789static void i40evf_reset_task(struct work_struct *work)
1790{
Mitch Williamsef8693e2014-02-13 03:48:53 -08001791 struct i40evf_adapter *adapter = container_of(work,
1792 struct i40evf_adapter,
1793 reset_task);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001794 struct net_device *netdev = adapter->netdev;
Greg Rose5eae00c2013-12-21 06:12:45 +00001795 struct i40e_hw *hw = &adapter->hw;
Mitch Williams40d01362015-10-01 14:37:37 -04001796 struct i40evf_vlan_filter *vlf;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001797 struct i40evf_mac_filter *f;
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001798 u32 reg_val;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001799 int i = 0, err;
Greg Rose5eae00c2013-12-21 06:12:45 +00001800
1801 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1802 &adapter->crit_section))
Neerav Parikhf98a2002014-09-13 07:40:44 +00001803 usleep_range(500, 1000);
Mitch Williams3526d802014-03-06 08:59:56 +00001804
Mitch Williams67c818a2015-06-19 08:56:30 -07001805 i40evf_misc_irq_disable(adapter);
Mitch Williams3526d802014-03-06 08:59:56 +00001806 if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) {
Mitch Williams67c818a2015-06-19 08:56:30 -07001807 adapter->flags &= ~I40EVF_FLAG_RESET_NEEDED;
1808 /* Restart the AQ here. If we have been reset but didn't
1809 * detect it, or if the PF had to reinit, our AQ will be hosed.
1810 */
1811 i40evf_shutdown_adminq(hw);
1812 i40evf_init_adminq(hw);
Mitch Williams3526d802014-03-06 08:59:56 +00001813 i40evf_request_reset(adapter);
1814 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001815 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
Mitch Williams3526d802014-03-06 08:59:56 +00001816
Mitch Williamsef8693e2014-02-13 03:48:53 -08001817 /* poll until we see the reset actually happen */
1818 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001819 reg_val = rd32(hw, I40E_VF_ARQLEN1) &
1820 I40E_VF_ARQLEN1_ARQENABLE_MASK;
1821 if (!reg_val)
Greg Rose5eae00c2013-12-21 06:12:45 +00001822 break;
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001823 usleep_range(5000, 10000);
Greg Rose5eae00c2013-12-21 06:12:45 +00001824 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001825 if (i == I40EVF_RESET_WAIT_COUNT) {
Mitch Williams67c818a2015-06-19 08:56:30 -07001826 dev_info(&adapter->pdev->dev, "Never saw reset\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08001827 goto continue_reset; /* act like the reset happened */
1828 }
1829
1830 /* wait until the reset is complete and the PF is responding to us */
1831 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001832 reg_val = rd32(hw, I40E_VFGEN_RSTAT) &
1833 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1834 if (reg_val == I40E_VFR_VFACTIVE)
Mitch Williamsef8693e2014-02-13 03:48:53 -08001835 break;
Mitch Williamsc88e38c2014-11-11 20:03:13 +00001836 msleep(I40EVF_RESET_WAIT_MS);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001837 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001838 /* extra wait to make sure minimum wait is met */
1839 msleep(I40EVF_RESET_WAIT_MS);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001840 if (i == I40EVF_RESET_WAIT_COUNT) {
Shannon Nelson874d1a12015-09-03 17:18:57 -04001841 struct i40evf_mac_filter *ftmp;
Mitch Williams6ba36a22014-08-01 13:27:14 -07001842 struct i40evf_vlan_filter *fv, *fvtmp;
1843
Greg Rose5eae00c2013-12-21 06:12:45 +00001844 /* reset never finished */
Mitch Williams80e72892014-05-10 04:49:06 +00001845 dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n",
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001846 reg_val);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001847 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
1848
Mitch Williams169f4072014-04-01 07:11:50 +00001849 if (netif_running(adapter->netdev)) {
1850 set_bit(__I40E_DOWN, &adapter->vsi.state);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001851 netif_carrier_off(netdev);
Mitch Williams67c818a2015-06-19 08:56:30 -07001852 netif_tx_disable(netdev);
1853 i40evf_napi_disable_all(adapter);
1854 i40evf_irq_disable(adapter);
Mitch Williams169f4072014-04-01 07:11:50 +00001855 i40evf_free_traffic_irqs(adapter);
1856 i40evf_free_all_tx_resources(adapter);
1857 i40evf_free_all_rx_resources(adapter);
1858 }
Mitch Williams6ba36a22014-08-01 13:27:14 -07001859
1860 /* Delete all of the filters, both MAC and VLAN. */
1861 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list,
1862 list) {
1863 list_del(&f->list);
1864 kfree(f);
1865 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001866
Mitch Williams6ba36a22014-08-01 13:27:14 -07001867 list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list,
1868 list) {
1869 list_del(&fv->list);
1870 kfree(fv);
1871 }
1872
Mitch Williamsef8693e2014-02-13 03:48:53 -08001873 i40evf_free_misc_irq(adapter);
1874 i40evf_reset_interrupt_capability(adapter);
1875 i40evf_free_queues(adapter);
Mitch Williamsd31944d2014-08-01 13:27:13 -07001876 i40evf_free_q_vectors(adapter);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001877 kfree(adapter->vf_res);
1878 i40evf_shutdown_adminq(hw);
1879 adapter->netdev->flags &= ~IFF_UP;
1880 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Mitch Williams67c818a2015-06-19 08:56:30 -07001881 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1882 dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08001883 return; /* Do not attempt to reinit. It's dead, Jim. */
Greg Rose5eae00c2013-12-21 06:12:45 +00001884 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001885
1886continue_reset:
Mitch Williams67c818a2015-06-19 08:56:30 -07001887 if (netif_running(adapter->netdev)) {
1888 netif_carrier_off(netdev);
1889 netif_tx_stop_all_queues(netdev);
1890 i40evf_napi_disable_all(adapter);
1891 }
Mitch Williamsac833bb2015-01-29 07:17:19 +00001892 i40evf_irq_disable(adapter);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001893
Greg Rose5eae00c2013-12-21 06:12:45 +00001894 adapter->state = __I40EVF_RESETTING;
Mitch Williams67c818a2015-06-19 08:56:30 -07001895 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1896
1897 /* free the Tx/Rx rings and descriptors, might be better to just
1898 * re-use them sometime in the future
1899 */
1900 i40evf_free_all_rx_resources(adapter);
1901 i40evf_free_all_tx_resources(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001902
1903 /* kill and reinit the admin queue */
1904 if (i40evf_shutdown_adminq(hw))
Mitch Williamsac833bb2015-01-29 07:17:19 +00001905 dev_warn(&adapter->pdev->dev, "Failed to shut down adminq\n");
1906 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001907 err = i40evf_init_adminq(hw);
1908 if (err)
Mitch Williamsac833bb2015-01-29 07:17:19 +00001909 dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n",
1910 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00001911
Mitch Williamse6d038d2015-06-04 16:23:58 -04001912 adapter->aq_required = I40EVF_FLAG_AQ_GET_CONFIG;
1913 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001914
1915 /* re-add all MAC filters */
1916 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1917 f->add = true;
1918 }
1919 /* re-add all VLAN filters */
Mitch Williams40d01362015-10-01 14:37:37 -04001920 list_for_each_entry(vlf, &adapter->vlan_filter_list, list) {
1921 vlf->add = true;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001922 }
Mitch Williamse6d038d2015-06-04 16:23:58 -04001923 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001924 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
Greg Rose5eae00c2013-12-21 06:12:45 +00001925 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Mitch Williams67c818a2015-06-19 08:56:30 -07001926 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001927
1928 mod_timer(&adapter->watchdog_timer, jiffies + 2);
1929
1930 if (netif_running(adapter->netdev)) {
1931 /* allocate transmit descriptors */
1932 err = i40evf_setup_all_tx_resources(adapter);
1933 if (err)
1934 goto reset_err;
1935
1936 /* allocate receive descriptors */
1937 err = i40evf_setup_all_rx_resources(adapter);
1938 if (err)
1939 goto reset_err;
1940
1941 i40evf_configure(adapter);
1942
1943 err = i40evf_up_complete(adapter);
1944 if (err)
1945 goto reset_err;
1946
1947 i40evf_irq_enable(adapter, true);
Mitch Williams67c818a2015-06-19 08:56:30 -07001948 } else {
1949 adapter->state = __I40EVF_DOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001950 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001951
Greg Rose5eae00c2013-12-21 06:12:45 +00001952 return;
1953reset_err:
Mitch Williams80e72892014-05-10 04:49:06 +00001954 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001955 i40evf_close(adapter->netdev);
1956}
1957
1958/**
1959 * i40evf_adminq_task - worker thread to clean the admin queue
1960 * @work: pointer to work_struct containing our data
1961 **/
1962static void i40evf_adminq_task(struct work_struct *work)
1963{
1964 struct i40evf_adapter *adapter =
1965 container_of(work, struct i40evf_adapter, adminq_task);
1966 struct i40e_hw *hw = &adapter->hw;
1967 struct i40e_arq_event_info event;
1968 struct i40e_virtchnl_msg *v_msg;
1969 i40e_status ret;
Mitch Williams912257e2014-05-22 06:32:07 +00001970 u32 val, oldval;
Greg Rose5eae00c2013-12-21 06:12:45 +00001971 u16 pending;
1972
Mitch Williamsef8693e2014-02-13 03:48:53 -08001973 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
Mitch A Williams72354482014-12-09 08:53:07 +00001974 goto out;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001975
Mitch Williams1001dc32014-11-11 20:02:19 +00001976 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
1977 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +00001978 if (!event.msg_buf)
Mitch A Williams72354482014-12-09 08:53:07 +00001979 goto out;
Mitch Williams249c8b82014-05-10 04:49:04 +00001980
Greg Rose5eae00c2013-12-21 06:12:45 +00001981 v_msg = (struct i40e_virtchnl_msg *)&event.desc;
1982 do {
1983 ret = i40evf_clean_arq_element(hw, &event, &pending);
Mitch Williams8b011eb2015-01-09 11:18:17 +00001984 if (ret || !v_msg->v_opcode)
Greg Rose5eae00c2013-12-21 06:12:45 +00001985 break; /* No event to process or error cleaning ARQ */
1986
1987 i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
1988 v_msg->v_retval, event.msg_buf,
Mitch Williams1001dc32014-11-11 20:02:19 +00001989 event.msg_len);
Mitch Williams75a64432014-11-11 20:02:42 +00001990 if (pending != 0)
Greg Rose5eae00c2013-12-21 06:12:45 +00001991 memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
Greg Rose5eae00c2013-12-21 06:12:45 +00001992 } while (pending);
1993
Mitch Williams67c818a2015-06-19 08:56:30 -07001994 if ((adapter->flags &
1995 (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) ||
1996 adapter->state == __I40EVF_RESETTING)
1997 goto freedom;
1998
Mitch Williams912257e2014-05-22 06:32:07 +00001999 /* check for error indications */
2000 val = rd32(hw, hw->aq.arq.len);
2001 oldval = val;
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002002 if (val & I40E_VF_ARQLEN1_ARQVFE_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00002003 dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002004 val &= ~I40E_VF_ARQLEN1_ARQVFE_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00002005 }
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002006 if (val & I40E_VF_ARQLEN1_ARQOVFL_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00002007 dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002008 val &= ~I40E_VF_ARQLEN1_ARQOVFL_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00002009 }
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002010 if (val & I40E_VF_ARQLEN1_ARQCRIT_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00002011 dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002012 val &= ~I40E_VF_ARQLEN1_ARQCRIT_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00002013 }
2014 if (oldval != val)
2015 wr32(hw, hw->aq.arq.len, val);
2016
2017 val = rd32(hw, hw->aq.asq.len);
2018 oldval = val;
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002019 if (val & I40E_VF_ATQLEN1_ATQVFE_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00002020 dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002021 val &= ~I40E_VF_ATQLEN1_ATQVFE_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00002022 }
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002023 if (val & I40E_VF_ATQLEN1_ATQOVFL_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00002024 dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002025 val &= ~I40E_VF_ATQLEN1_ATQOVFL_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00002026 }
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002027 if (val & I40E_VF_ATQLEN1_ATQCRIT_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00002028 dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002029 val &= ~I40E_VF_ATQLEN1_ATQCRIT_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00002030 }
2031 if (oldval != val)
2032 wr32(hw, hw->aq.asq.len, val);
2033
Mitch Williams67c818a2015-06-19 08:56:30 -07002034freedom:
Mitch A Williams72354482014-12-09 08:53:07 +00002035 kfree(event.msg_buf);
2036out:
Greg Rose5eae00c2013-12-21 06:12:45 +00002037 /* re-enable Admin queue interrupt cause */
2038 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002039}
2040
2041/**
2042 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
2043 * @adapter: board private structure
2044 *
2045 * Free all transmit software resources
2046 **/
Mitch Williamse284fc82015-03-27 00:12:09 -07002047void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
Greg Rose5eae00c2013-12-21 06:12:45 +00002048{
2049 int i;
2050
Mitch Williamsfdb47ae2015-11-19 11:34:18 -08002051 if (!adapter->tx_rings)
2052 return;
2053
Mitch Williamscc052922014-10-25 03:24:34 +00002054 for (i = 0; i < adapter->num_active_queues; i++)
Mitch Williams0dd438d2015-10-26 19:44:40 -04002055 if (adapter->tx_rings[i].desc)
2056 i40evf_free_tx_resources(&adapter->tx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00002057}
2058
2059/**
2060 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
2061 * @adapter: board private structure
2062 *
2063 * If this function returns with an error, then it's possible one or
2064 * more of the rings is populated (while the rest are not). It is the
2065 * callers duty to clean those orphaned rings.
2066 *
2067 * Return 0 on success, negative on failure
2068 **/
2069static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
2070{
2071 int i, err = 0;
2072
Mitch Williamscc052922014-10-25 03:24:34 +00002073 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williams0dd438d2015-10-26 19:44:40 -04002074 adapter->tx_rings[i].count = adapter->tx_desc_count;
2075 err = i40evf_setup_tx_descriptors(&adapter->tx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00002076 if (!err)
2077 continue;
2078 dev_err(&adapter->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04002079 "Allocation for Tx Queue %u failed\n", i);
Greg Rose5eae00c2013-12-21 06:12:45 +00002080 break;
2081 }
2082
2083 return err;
2084}
2085
2086/**
2087 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
2088 * @adapter: board private structure
2089 *
2090 * If this function returns with an error, then it's possible one or
2091 * more of the rings is populated (while the rest are not). It is the
2092 * callers duty to clean those orphaned rings.
2093 *
2094 * Return 0 on success, negative on failure
2095 **/
2096static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
2097{
2098 int i, err = 0;
2099
Mitch Williamscc052922014-10-25 03:24:34 +00002100 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williams0dd438d2015-10-26 19:44:40 -04002101 adapter->rx_rings[i].count = adapter->rx_desc_count;
2102 err = i40evf_setup_rx_descriptors(&adapter->rx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00002103 if (!err)
2104 continue;
2105 dev_err(&adapter->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04002106 "Allocation for Rx Queue %u failed\n", i);
Greg Rose5eae00c2013-12-21 06:12:45 +00002107 break;
2108 }
2109 return err;
2110}
2111
2112/**
2113 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
2114 * @adapter: board private structure
2115 *
2116 * Free all receive software resources
2117 **/
Mitch Williamse284fc82015-03-27 00:12:09 -07002118void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
Greg Rose5eae00c2013-12-21 06:12:45 +00002119{
2120 int i;
2121
Mitch Williamsfdb47ae2015-11-19 11:34:18 -08002122 if (!adapter->rx_rings)
2123 return;
2124
Mitch Williamscc052922014-10-25 03:24:34 +00002125 for (i = 0; i < adapter->num_active_queues; i++)
Mitch Williams0dd438d2015-10-26 19:44:40 -04002126 if (adapter->rx_rings[i].desc)
2127 i40evf_free_rx_resources(&adapter->rx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00002128}
2129
2130/**
2131 * i40evf_open - Called when a network interface is made active
2132 * @netdev: network interface device structure
2133 *
2134 * Returns 0 on success, negative value on failure
2135 *
2136 * The open entry point is called when a network interface is made
2137 * active by the system (IFF_UP). At this point all resources needed
2138 * for transmit and receive operations are allocated, the interrupt
2139 * handler is registered with the OS, the watchdog timer is started,
2140 * and the stack is notified that the interface is ready.
2141 **/
2142static int i40evf_open(struct net_device *netdev)
2143{
2144 struct i40evf_adapter *adapter = netdev_priv(netdev);
2145 int err;
2146
Mitch Williamsef8693e2014-02-13 03:48:53 -08002147 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
2148 dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
2149 return -EIO;
2150 }
Mitch Williams209dc4d2015-12-09 15:50:27 -08002151
2152 if (adapter->state != __I40EVF_DOWN)
Greg Rose5eae00c2013-12-21 06:12:45 +00002153 return -EBUSY;
2154
2155 /* allocate transmit descriptors */
2156 err = i40evf_setup_all_tx_resources(adapter);
2157 if (err)
2158 goto err_setup_tx;
2159
2160 /* allocate receive descriptors */
2161 err = i40evf_setup_all_rx_resources(adapter);
2162 if (err)
2163 goto err_setup_rx;
2164
2165 /* clear any pending interrupts, may auto mask */
2166 err = i40evf_request_traffic_irqs(adapter, netdev->name);
2167 if (err)
2168 goto err_req_irq;
2169
Mitch Williams44151cd2015-04-27 14:57:17 -04002170 i40evf_add_filter(adapter, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002171 i40evf_configure(adapter);
2172
2173 err = i40evf_up_complete(adapter);
2174 if (err)
2175 goto err_req_irq;
2176
2177 i40evf_irq_enable(adapter, true);
2178
2179 return 0;
2180
2181err_req_irq:
2182 i40evf_down(adapter);
2183 i40evf_free_traffic_irqs(adapter);
2184err_setup_rx:
2185 i40evf_free_all_rx_resources(adapter);
2186err_setup_tx:
2187 i40evf_free_all_tx_resources(adapter);
2188
2189 return err;
2190}
2191
2192/**
2193 * i40evf_close - Disables a network interface
2194 * @netdev: network interface device structure
2195 *
2196 * Returns 0, this is not allowed to fail
2197 *
2198 * The close entry point is called when an interface is de-activated
2199 * by the OS. The hardware is still under the drivers control, but
2200 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
2201 * are freed, along with all transmit and receive resources.
2202 **/
2203static int i40evf_close(struct net_device *netdev)
2204{
2205 struct i40evf_adapter *adapter = netdev_priv(netdev);
2206
Mitch Williams209dc4d2015-12-09 15:50:27 -08002207 if (adapter->state <= __I40EVF_DOWN_PENDING)
Mitch Williamsef8693e2014-02-13 03:48:53 -08002208 return 0;
2209
Mitch Williamsef8693e2014-02-13 03:48:53 -08002210
Greg Rose5eae00c2013-12-21 06:12:45 +00002211 set_bit(__I40E_DOWN, &adapter->vsi.state);
2212
2213 i40evf_down(adapter);
Mitch Williams209dc4d2015-12-09 15:50:27 -08002214 adapter->state = __I40EVF_DOWN_PENDING;
Greg Rose5eae00c2013-12-21 06:12:45 +00002215 i40evf_free_traffic_irqs(adapter);
2216
Greg Rose5eae00c2013-12-21 06:12:45 +00002217 return 0;
2218}
2219
2220/**
2221 * i40evf_get_stats - Get System Network Statistics
2222 * @netdev: network interface device structure
2223 *
2224 * Returns the address of the device statistics structure.
2225 * The statistics are actually updated from the timer callback.
2226 **/
2227static struct net_device_stats *i40evf_get_stats(struct net_device *netdev)
2228{
2229 struct i40evf_adapter *adapter = netdev_priv(netdev);
2230
2231 /* only return the current stats */
2232 return &adapter->net_stats;
2233}
2234
2235/**
Greg Rose5eae00c2013-12-21 06:12:45 +00002236 * i40evf_change_mtu - Change the Maximum Transfer Unit
2237 * @netdev: network interface device structure
2238 * @new_mtu: new value for maximum frame size
2239 *
2240 * Returns 0 on success, negative on failure
2241 **/
2242static int i40evf_change_mtu(struct net_device *netdev, int new_mtu)
2243{
2244 struct i40evf_adapter *adapter = netdev_priv(netdev);
2245 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
2246
2247 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
2248 return -EINVAL;
2249
Greg Rose5eae00c2013-12-21 06:12:45 +00002250 netdev->mtu = new_mtu;
Mitch Williams67c818a2015-06-19 08:56:30 -07002251 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
2252 schedule_work(&adapter->reset_task);
2253
Greg Rose5eae00c2013-12-21 06:12:45 +00002254 return 0;
2255}
2256
2257static const struct net_device_ops i40evf_netdev_ops = {
2258 .ndo_open = i40evf_open,
2259 .ndo_stop = i40evf_close,
2260 .ndo_start_xmit = i40evf_xmit_frame,
2261 .ndo_get_stats = i40evf_get_stats,
2262 .ndo_set_rx_mode = i40evf_set_rx_mode,
2263 .ndo_validate_addr = eth_validate_addr,
2264 .ndo_set_mac_address = i40evf_set_mac,
2265 .ndo_change_mtu = i40evf_change_mtu,
2266 .ndo_tx_timeout = i40evf_tx_timeout,
2267 .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid,
2268 .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid,
Alexander Duyck7709b4c2015-09-24 09:04:38 -07002269#ifdef CONFIG_NET_POLL_CONTROLLER
2270 .ndo_poll_controller = i40evf_netpoll,
2271#endif
Greg Rose5eae00c2013-12-21 06:12:45 +00002272};
2273
2274/**
2275 * i40evf_check_reset_complete - check that VF reset is complete
2276 * @hw: pointer to hw struct
2277 *
2278 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
2279 **/
2280static int i40evf_check_reset_complete(struct i40e_hw *hw)
2281{
2282 u32 rstat;
2283 int i;
2284
2285 for (i = 0; i < 100; i++) {
Ashish Shahfd358862014-08-01 13:27:11 -07002286 rstat = rd32(hw, I40E_VFGEN_RSTAT) &
2287 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
2288 if ((rstat == I40E_VFR_VFACTIVE) ||
2289 (rstat == I40E_VFR_COMPLETED))
Greg Rose5eae00c2013-12-21 06:12:45 +00002290 return 0;
Neerav Parikhf98a2002014-09-13 07:40:44 +00002291 usleep_range(10, 20);
Greg Rose5eae00c2013-12-21 06:12:45 +00002292 }
2293 return -EBUSY;
2294}
2295
2296/**
Mitch Williamse6d038d2015-06-04 16:23:58 -04002297 * i40evf_process_config - Process the config information we got from the PF
2298 * @adapter: board private structure
2299 *
2300 * Verify that we have a valid config struct, and set up our netdev features
2301 * and our VSI struct.
2302 **/
2303int i40evf_process_config(struct i40evf_adapter *adapter)
2304{
2305 struct net_device *netdev = adapter->netdev;
2306 int i;
2307
2308 /* got VF config message back from PF, now we can parse it */
2309 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
2310 if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
2311 adapter->vsi_res = &adapter->vf_res->vsi_res[i];
2312 }
2313 if (!adapter->vsi_res) {
2314 dev_err(&adapter->pdev->dev, "No LAN VSI found\n");
2315 return -ENODEV;
2316 }
2317
2318 if (adapter->vf_res->vf_offload_flags
2319 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) {
Mitch Williamscc7e4062015-09-28 14:12:40 -04002320 netdev->vlan_features = netdev->features &
2321 ~(NETIF_F_HW_VLAN_CTAG_TX |
2322 NETIF_F_HW_VLAN_CTAG_RX |
2323 NETIF_F_HW_VLAN_CTAG_FILTER);
Mitch Williamse6d038d2015-06-04 16:23:58 -04002324 netdev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2325 NETIF_F_HW_VLAN_CTAG_RX |
2326 NETIF_F_HW_VLAN_CTAG_FILTER;
2327 }
2328 netdev->features |= NETIF_F_HIGHDMA |
2329 NETIF_F_SG |
2330 NETIF_F_IP_CSUM |
Tom Herbert53692b12015-12-14 11:19:41 -08002331 NETIF_F_SCTP_CRC |
Mitch Williamse6d038d2015-06-04 16:23:58 -04002332 NETIF_F_IPV6_CSUM |
2333 NETIF_F_TSO |
2334 NETIF_F_TSO6 |
2335 NETIF_F_RXCSUM |
2336 NETIF_F_GRO;
2337
2338 /* copy netdev features into list of user selectable features */
2339 netdev->hw_features |= netdev->features;
2340 netdev->hw_features &= ~NETIF_F_RXCSUM;
2341
2342 adapter->vsi.id = adapter->vsi_res->vsi_id;
2343
2344 adapter->vsi.back = adapter;
2345 adapter->vsi.base_vector = 1;
2346 adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK;
2347 adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC |
2348 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
2349 adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC |
2350 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
2351 adapter->vsi.netdev = adapter->netdev;
Mitch Williamsf578f5f2015-08-28 17:55:58 -04002352 adapter->vsi.qs_handle = adapter->vsi_res->qset_handle;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002353 return 0;
2354}
2355
2356/**
Greg Rose5eae00c2013-12-21 06:12:45 +00002357 * i40evf_init_task - worker thread to perform delayed initialization
2358 * @work: pointer to work_struct containing our data
2359 *
2360 * This task completes the work that was begun in probe. Due to the nature
2361 * of VF-PF communications, we may need to wait tens of milliseconds to get
Joe Perchesdbedd442015-03-06 20:49:12 -08002362 * responses back from the PF. Rather than busy-wait in probe and bog down the
Greg Rose5eae00c2013-12-21 06:12:45 +00002363 * whole system, we'll do it in a task so we can sleep.
2364 * This task only runs during driver init. Once we've established
2365 * communications with the PF driver and set up our netdev, the watchdog
2366 * takes over.
2367 **/
2368static void i40evf_init_task(struct work_struct *work)
2369{
2370 struct i40evf_adapter *adapter = container_of(work,
2371 struct i40evf_adapter,
2372 init_task.work);
2373 struct net_device *netdev = adapter->netdev;
Greg Rose5eae00c2013-12-21 06:12:45 +00002374 struct i40e_hw *hw = &adapter->hw;
2375 struct pci_dev *pdev = adapter->pdev;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002376 int err, bufsz;
Greg Rose5eae00c2013-12-21 06:12:45 +00002377
2378 switch (adapter->state) {
2379 case __I40EVF_STARTUP:
2380 /* driver loaded, probe complete */
Mitch Williamsef8693e2014-02-13 03:48:53 -08002381 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
2382 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
Greg Rose5eae00c2013-12-21 06:12:45 +00002383 err = i40e_set_mac_type(hw);
2384 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002385 dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
2386 err);
Mitch Williams2619ef42015-04-07 19:45:30 -04002387 goto err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002388 }
2389 err = i40evf_check_reset_complete(hw);
2390 if (err) {
Mitch Williams0d9c7ea2014-04-23 04:50:00 +00002391 dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n",
Mitch Williams75a64432014-11-11 20:02:42 +00002392 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002393 goto err;
2394 }
2395 hw->aq.num_arq_entries = I40EVF_AQ_LEN;
2396 hw->aq.num_asq_entries = I40EVF_AQ_LEN;
2397 hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2398 hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2399
2400 err = i40evf_init_adminq(hw);
2401 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002402 dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
2403 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002404 goto err;
2405 }
2406 err = i40evf_send_api_ver(adapter);
2407 if (err) {
Mitch Williams10bdd672014-03-06 08:59:53 +00002408 dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002409 i40evf_shutdown_adminq(hw);
2410 goto err;
2411 }
2412 adapter->state = __I40EVF_INIT_VERSION_CHECK;
2413 goto restart;
Greg Rose5eae00c2013-12-21 06:12:45 +00002414 case __I40EVF_INIT_VERSION_CHECK:
Mitch Williams10bdd672014-03-06 08:59:53 +00002415 if (!i40evf_asq_done(hw)) {
Mitch Williams80e72892014-05-10 04:49:06 +00002416 dev_err(&pdev->dev, "Admin queue command never completed\n");
Mitch Williams906a6932014-11-13 03:06:12 +00002417 i40evf_shutdown_adminq(hw);
2418 adapter->state = __I40EVF_STARTUP;
Greg Rose5eae00c2013-12-21 06:12:45 +00002419 goto err;
Mitch Williams10bdd672014-03-06 08:59:53 +00002420 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002421
2422 /* aq msg sent, awaiting reply */
2423 err = i40evf_verify_api_ver(adapter);
2424 if (err) {
Mitch A Williamsd4f82fd2014-12-09 08:53:03 +00002425 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
Mitch Williams56f99202014-06-04 04:22:41 +00002426 err = i40evf_send_api_ver(adapter);
Mitch Williamsee1693e2015-06-04 16:23:59 -04002427 else
2428 dev_err(&pdev->dev, "Unsupported PF API version %d.%d, expected %d.%d\n",
2429 adapter->pf_version.major,
2430 adapter->pf_version.minor,
2431 I40E_VIRTCHNL_VERSION_MAJOR,
2432 I40E_VIRTCHNL_VERSION_MINOR);
Greg Rose5eae00c2013-12-21 06:12:45 +00002433 goto err;
2434 }
2435 err = i40evf_send_vf_config_msg(adapter);
2436 if (err) {
Mitch Williams3f2ab172014-06-04 04:22:40 +00002437 dev_err(&pdev->dev, "Unable to send config request (%d)\n",
Greg Rose5eae00c2013-12-21 06:12:45 +00002438 err);
2439 goto err;
2440 }
2441 adapter->state = __I40EVF_INIT_GET_RESOURCES;
2442 goto restart;
Greg Rose5eae00c2013-12-21 06:12:45 +00002443 case __I40EVF_INIT_GET_RESOURCES:
2444 /* aq msg sent, awaiting reply */
2445 if (!adapter->vf_res) {
2446 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
2447 (I40E_MAX_VF_VSI *
2448 sizeof(struct i40e_virtchnl_vsi_resource));
2449 adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002450 if (!adapter->vf_res)
Greg Rose5eae00c2013-12-21 06:12:45 +00002451 goto err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002452 }
2453 err = i40evf_get_vf_config(adapter);
Mitch Williams906a6932014-11-13 03:06:12 +00002454 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
Mitch Williams906a6932014-11-13 03:06:12 +00002455 err = i40evf_send_vf_config_msg(adapter);
2456 goto err;
Mitch Williamse7430722015-10-26 19:44:38 -04002457 } else if (err == I40E_ERR_PARAM) {
2458 /* We only get ERR_PARAM if the device is in a very bad
2459 * state or if we've been disabled for previous bad
2460 * behavior. Either way, we're done now.
2461 */
2462 i40evf_shutdown_adminq(hw);
2463 dev_err(&pdev->dev, "Unable to get VF config due to PF error condition, not retrying\n");
2464 return;
Mitch Williams906a6932014-11-13 03:06:12 +00002465 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002466 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002467 dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
2468 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002469 goto err_alloc;
2470 }
2471 adapter->state = __I40EVF_INIT_SW;
2472 break;
2473 default:
2474 goto err_alloc;
2475 }
Mitch Williamse6d038d2015-06-04 16:23:58 -04002476 if (i40evf_process_config(adapter))
Greg Rose5eae00c2013-12-21 06:12:45 +00002477 goto err_alloc;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002478 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00002479
2480 adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED;
2481
Greg Rose5eae00c2013-12-21 06:12:45 +00002482 netdev->netdev_ops = &i40evf_netdev_ops;
2483 i40evf_set_ethtool_ops(netdev);
2484 netdev->watchdog_timeo = 5 * HZ;
Greg Rose3415e8c2014-01-30 12:40:27 +00002485
Greg Rose5eae00c2013-12-21 06:12:45 +00002486 if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
Mitch Williamsb34f90e2014-05-10 04:49:07 +00002487 dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002488 adapter->hw.mac.addr);
Mitch Williams14e52ee2015-08-31 19:54:44 -04002489 eth_hw_addr_random(netdev);
2490 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2491 } else {
2492 adapter->flags |= I40EVF_FLAG_ADDR_SET_BY_PF;
2493 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
2494 ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002495 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002496
Greg Rose5eae00c2013-12-21 06:12:45 +00002497 init_timer(&adapter->watchdog_timer);
2498 adapter->watchdog_timer.function = &i40evf_watchdog_timer;
2499 adapter->watchdog_timer.data = (unsigned long)adapter;
2500 mod_timer(&adapter->watchdog_timer, jiffies + 1);
2501
Mitch Williamscc052922014-10-25 03:24:34 +00002502 adapter->num_active_queues = min_t(int,
2503 adapter->vsi_res->num_queue_pairs,
2504 (int)(num_online_cpus()));
Mitch Williamsd732a182014-04-24 06:41:37 +00002505 adapter->tx_desc_count = I40EVF_DEFAULT_TXD;
2506 adapter->rx_desc_count = I40EVF_DEFAULT_RXD;
Greg Rose5eae00c2013-12-21 06:12:45 +00002507 err = i40evf_init_interrupt_scheme(adapter);
2508 if (err)
2509 goto err_sw_init;
2510 i40evf_map_rings_to_vectors(adapter);
Anjali Singhai Jain1f012272015-09-03 17:18:53 -04002511 if (adapter->vf_res->vf_offload_flags &
2512 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
2513 adapter->flags |= I40EVF_FLAG_WB_ON_ITR_CAPABLE;
Greg Rose5eae00c2013-12-21 06:12:45 +00002514 err = i40evf_request_misc_irq(adapter);
2515 if (err)
2516 goto err_sw_init;
2517
2518 netif_carrier_off(netdev);
2519
Mitch Williamsef8693e2014-02-13 03:48:53 -08002520 if (!adapter->netdev_registered) {
2521 err = register_netdev(netdev);
2522 if (err)
2523 goto err_register;
2524 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002525
2526 adapter->netdev_registered = true;
2527
2528 netif_tx_stop_all_queues(netdev);
2529
Mitch Williamsb34f90e2014-05-10 04:49:07 +00002530 dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002531 if (netdev->features & NETIF_F_GRO)
2532 dev_info(&pdev->dev, "GRO is enabled\n");
2533
Greg Rose5eae00c2013-12-21 06:12:45 +00002534 adapter->state = __I40EVF_DOWN;
2535 set_bit(__I40E_DOWN, &adapter->vsi.state);
2536 i40evf_misc_irq_enable(adapter);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04002537
2538 if (RSS_AQ(adapter)) {
2539 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_RSS;
2540 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
2541 } else {
Helin Zhang96a81982015-10-26 19:44:31 -04002542 i40evf_init_rss(adapter);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04002543 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002544 return;
2545restart:
Mitch Williams3f7e5c32015-09-28 14:12:42 -04002546 schedule_delayed_work(&adapter->init_task, msecs_to_jiffies(30));
Greg Rose5eae00c2013-12-21 06:12:45 +00002547 return;
2548
2549err_register:
2550 i40evf_free_misc_irq(adapter);
2551err_sw_init:
2552 i40evf_reset_interrupt_capability(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002553err_alloc:
2554 kfree(adapter->vf_res);
2555 adapter->vf_res = NULL;
2556err:
2557 /* Things went into the weeds, so try again later */
2558 if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
Mitch Williamsb9029e92015-09-28 14:16:50 -04002559 dev_err(&pdev->dev, "Failed to communicate with PF; waiting before retry\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08002560 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
Mitch Williamsb9029e92015-09-28 14:16:50 -04002561 i40evf_shutdown_adminq(hw);
2562 adapter->state = __I40EVF_STARTUP;
2563 schedule_delayed_work(&adapter->init_task, HZ * 5);
2564 return;
Greg Rose5eae00c2013-12-21 06:12:45 +00002565 }
Mitch Williams3f7e5c32015-09-28 14:12:42 -04002566 schedule_delayed_work(&adapter->init_task, HZ);
Greg Rose5eae00c2013-12-21 06:12:45 +00002567}
2568
2569/**
2570 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2571 * @pdev: pci device structure
2572 **/
2573static void i40evf_shutdown(struct pci_dev *pdev)
2574{
2575 struct net_device *netdev = pci_get_drvdata(pdev);
Mitch Williams00293fd2015-01-09 11:18:18 +00002576 struct i40evf_adapter *adapter = netdev_priv(netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +00002577
2578 netif_device_detach(netdev);
2579
2580 if (netif_running(netdev))
2581 i40evf_close(netdev);
2582
Mitch Williams00293fd2015-01-09 11:18:18 +00002583 /* Prevent the watchdog from running. */
2584 adapter->state = __I40EVF_REMOVE;
2585 adapter->aq_required = 0;
Mitch Williams00293fd2015-01-09 11:18:18 +00002586
Greg Rose5eae00c2013-12-21 06:12:45 +00002587#ifdef CONFIG_PM
2588 pci_save_state(pdev);
2589
2590#endif
2591 pci_disable_device(pdev);
2592}
2593
2594/**
2595 * i40evf_probe - Device Initialization Routine
2596 * @pdev: PCI device information struct
2597 * @ent: entry in i40evf_pci_tbl
2598 *
2599 * Returns 0 on success, negative on failure
2600 *
2601 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2602 * The OS initialization, configuring of the adapter private structure,
2603 * and a hardware reset occur.
2604 **/
2605static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2606{
2607 struct net_device *netdev;
2608 struct i40evf_adapter *adapter = NULL;
2609 struct i40e_hw *hw = NULL;
Mitch Williamsdbbd8112014-02-20 19:29:08 -08002610 int err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002611
2612 err = pci_enable_device(pdev);
2613 if (err)
2614 return err;
2615
Mitch Williams64942942014-02-11 08:26:33 +00002616 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +00002617 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +00002618 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2619 if (err) {
2620 dev_err(&pdev->dev,
2621 "DMA configuration failed: 0x%x\n", err);
2622 goto err_dma;
2623 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002624 }
2625
2626 err = pci_request_regions(pdev, i40evf_driver_name);
2627 if (err) {
2628 dev_err(&pdev->dev,
2629 "pci_request_regions failed 0x%x\n", err);
2630 goto err_pci_reg;
2631 }
2632
2633 pci_enable_pcie_error_reporting(pdev);
2634
2635 pci_set_master(pdev);
2636
Mitch Williams1255b7a2015-11-06 15:25:59 -08002637 netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter), MAX_QUEUES);
Greg Rose5eae00c2013-12-21 06:12:45 +00002638 if (!netdev) {
2639 err = -ENOMEM;
2640 goto err_alloc_etherdev;
2641 }
2642
2643 SET_NETDEV_DEV(netdev, &pdev->dev);
2644
2645 pci_set_drvdata(pdev, netdev);
2646 adapter = netdev_priv(netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +00002647
2648 adapter->netdev = netdev;
2649 adapter->pdev = pdev;
2650
2651 hw = &adapter->hw;
2652 hw->back = adapter;
2653
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002654 adapter->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
Greg Rose5eae00c2013-12-21 06:12:45 +00002655 adapter->state = __I40EVF_STARTUP;
2656
2657 /* Call save state here because it relies on the adapter struct. */
2658 pci_save_state(pdev);
2659
2660 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2661 pci_resource_len(pdev, 0));
2662 if (!hw->hw_addr) {
2663 err = -EIO;
2664 goto err_ioremap;
2665 }
2666 hw->vendor_id = pdev->vendor;
2667 hw->device_id = pdev->device;
2668 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2669 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2670 hw->subsystem_device_id = pdev->subsystem_device;
2671 hw->bus.device = PCI_SLOT(pdev->devfn);
2672 hw->bus.func = PCI_FUNC(pdev->devfn);
2673
Jesse Brandeburg8ddb3322015-11-18 15:47:06 -08002674 /* set up the locks for the AQ, do this only once in probe
2675 * and destroy them only once in remove
2676 */
2677 mutex_init(&hw->aq.asq_mutex);
2678 mutex_init(&hw->aq.arq_mutex);
2679
Serey Kong8bb1a542014-08-01 13:27:15 -07002680 INIT_LIST_HEAD(&adapter->mac_filter_list);
2681 INIT_LIST_HEAD(&adapter->vlan_filter_list);
2682
Greg Rose5eae00c2013-12-21 06:12:45 +00002683 INIT_WORK(&adapter->reset_task, i40evf_reset_task);
2684 INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
2685 INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
2686 INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
Mitch Williams9b32b0b2015-08-13 15:11:32 -07002687 schedule_delayed_work(&adapter->init_task,
2688 msecs_to_jiffies(5 * (pdev->devfn & 0x07)));
Greg Rose5eae00c2013-12-21 06:12:45 +00002689
2690 return 0;
2691
2692err_ioremap:
2693 free_netdev(netdev);
2694err_alloc_etherdev:
2695 pci_release_regions(pdev);
2696err_pci_reg:
2697err_dma:
2698 pci_disable_device(pdev);
2699 return err;
2700}
2701
2702#ifdef CONFIG_PM
2703/**
2704 * i40evf_suspend - Power management suspend routine
2705 * @pdev: PCI device information struct
2706 * @state: unused
2707 *
2708 * Called when the system (VM) is entering sleep/suspend.
2709 **/
2710static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
2711{
2712 struct net_device *netdev = pci_get_drvdata(pdev);
2713 struct i40evf_adapter *adapter = netdev_priv(netdev);
2714 int retval = 0;
2715
2716 netif_device_detach(netdev);
2717
2718 if (netif_running(netdev)) {
2719 rtnl_lock();
2720 i40evf_down(adapter);
2721 rtnl_unlock();
2722 }
2723 i40evf_free_misc_irq(adapter);
2724 i40evf_reset_interrupt_capability(adapter);
2725
2726 retval = pci_save_state(pdev);
2727 if (retval)
2728 return retval;
2729
2730 pci_disable_device(pdev);
2731
2732 return 0;
2733}
2734
2735/**
Joe Perchesdbedd442015-03-06 20:49:12 -08002736 * i40evf_resume - Power management resume routine
Greg Rose5eae00c2013-12-21 06:12:45 +00002737 * @pdev: PCI device information struct
2738 *
2739 * Called when the system (VM) is resumed from sleep/suspend.
2740 **/
2741static int i40evf_resume(struct pci_dev *pdev)
2742{
2743 struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
2744 struct net_device *netdev = adapter->netdev;
2745 u32 err;
2746
2747 pci_set_power_state(pdev, PCI_D0);
2748 pci_restore_state(pdev);
2749 /* pci_restore_state clears dev->state_saved so call
2750 * pci_save_state to restore it.
2751 */
2752 pci_save_state(pdev);
2753
2754 err = pci_enable_device_mem(pdev);
2755 if (err) {
2756 dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
2757 return err;
2758 }
2759 pci_set_master(pdev);
2760
2761 rtnl_lock();
2762 err = i40evf_set_interrupt_capability(adapter);
2763 if (err) {
Vasily Averinf2a1c362015-07-07 18:53:38 +03002764 rtnl_unlock();
Greg Rose5eae00c2013-12-21 06:12:45 +00002765 dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
2766 return err;
2767 }
2768 err = i40evf_request_misc_irq(adapter);
2769 rtnl_unlock();
2770 if (err) {
2771 dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
2772 return err;
2773 }
2774
2775 schedule_work(&adapter->reset_task);
2776
2777 netif_device_attach(netdev);
2778
2779 return err;
2780}
2781
2782#endif /* CONFIG_PM */
2783/**
2784 * i40evf_remove - Device Removal Routine
2785 * @pdev: PCI device information struct
2786 *
2787 * i40evf_remove is called by the PCI subsystem to alert the driver
2788 * that it should release a PCI device. The could be caused by a
2789 * Hot-Plug event, or because the driver is going to be removed from
2790 * memory.
2791 **/
2792static void i40evf_remove(struct pci_dev *pdev)
2793{
2794 struct net_device *netdev = pci_get_drvdata(pdev);
2795 struct i40evf_adapter *adapter = netdev_priv(netdev);
Mitch Williams6ba36a22014-08-01 13:27:14 -07002796 struct i40evf_mac_filter *f, *ftmp;
Greg Rose5eae00c2013-12-21 06:12:45 +00002797 struct i40e_hw *hw = &adapter->hw;
2798
2799 cancel_delayed_work_sync(&adapter->init_task);
Mitch Williamsef8693e2014-02-13 03:48:53 -08002800 cancel_work_sync(&adapter->reset_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00002801
2802 if (adapter->netdev_registered) {
2803 unregister_netdev(netdev);
2804 adapter->netdev_registered = false;
2805 }
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00002806
Mitch Williamsf4a71882015-01-09 11:18:16 +00002807 /* Shut down all the garbage mashers on the detention level */
Greg Rose5eae00c2013-12-21 06:12:45 +00002808 adapter->state = __I40EVF_REMOVE;
Mitch Williamsf4a71882015-01-09 11:18:16 +00002809 adapter->aq_required = 0;
Mitch Williamsf4a71882015-01-09 11:18:16 +00002810 i40evf_request_reset(adapter);
2811 msleep(20);
2812 /* If the FW isn't responding, kick it once, but only once. */
2813 if (!i40evf_asq_done(hw)) {
2814 i40evf_request_reset(adapter);
2815 msleep(20);
2816 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002817
Mitch Williamsdbb01c82014-02-20 19:29:07 -08002818 if (adapter->msix_entries) {
Greg Rose5eae00c2013-12-21 06:12:45 +00002819 i40evf_misc_irq_disable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002820 i40evf_free_misc_irq(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002821 i40evf_reset_interrupt_capability(adapter);
Mitch Williamsd31944d2014-08-01 13:27:13 -07002822 i40evf_free_q_vectors(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002823 }
2824
Mitch Williamse5d17c32014-06-04 04:22:38 +00002825 if (adapter->watchdog_timer.function)
2826 del_timer_sync(&adapter->watchdog_timer);
2827
Mitch Williamsdbb01c82014-02-20 19:29:07 -08002828 flush_scheduled_work();
2829
Helin Zhang66f9af852015-10-26 19:44:34 -04002830 /* Clear user configurations for RSS */
2831 i40evf_clear_rss_config_user(&adapter->vsi);
2832
Greg Rose5eae00c2013-12-21 06:12:45 +00002833 if (hw->aq.asq.count)
2834 i40evf_shutdown_adminq(hw);
2835
Jesse Brandeburg8ddb3322015-11-18 15:47:06 -08002836 /* destroy the locks only once, here */
2837 mutex_destroy(&hw->aq.arq_mutex);
2838 mutex_destroy(&hw->aq.asq_mutex);
2839
Greg Rose5eae00c2013-12-21 06:12:45 +00002840 iounmap(hw->hw_addr);
2841 pci_release_regions(pdev);
2842
Mitch Williamse284fc82015-03-27 00:12:09 -07002843 i40evf_free_all_tx_resources(adapter);
2844 i40evf_free_all_rx_resources(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002845 i40evf_free_queues(adapter);
2846 kfree(adapter->vf_res);
Mitch Williams6ba36a22014-08-01 13:27:14 -07002847 /* If we got removed before an up/down sequence, we've got a filter
2848 * hanging out there that we need to get rid of.
2849 */
2850 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
2851 list_del(&f->list);
2852 kfree(f);
2853 }
Mitch A Williams37dfdf32014-12-09 08:53:05 +00002854 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
2855 list_del(&f->list);
2856 kfree(f);
2857 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002858
2859 free_netdev(netdev);
2860
2861 pci_disable_pcie_error_reporting(pdev);
2862
2863 pci_disable_device(pdev);
2864}
2865
2866static struct pci_driver i40evf_driver = {
2867 .name = i40evf_driver_name,
2868 .id_table = i40evf_pci_tbl,
2869 .probe = i40evf_probe,
2870 .remove = i40evf_remove,
2871#ifdef CONFIG_PM
2872 .suspend = i40evf_suspend,
2873 .resume = i40evf_resume,
2874#endif
2875 .shutdown = i40evf_shutdown,
2876};
2877
2878/**
2879 * i40e_init_module - Driver Registration Routine
2880 *
2881 * i40e_init_module is the first routine called when the driver is
2882 * loaded. All it does is register with the PCI subsystem.
2883 **/
2884static int __init i40evf_init_module(void)
2885{
2886 int ret;
Mitch Williams75a64432014-11-11 20:02:42 +00002887
Greg Rose5eae00c2013-12-21 06:12:45 +00002888 pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
Mitch Williams75a64432014-11-11 20:02:42 +00002889 i40evf_driver_version);
Greg Rose5eae00c2013-12-21 06:12:45 +00002890
2891 pr_info("%s\n", i40evf_copyright);
2892
2893 ret = pci_register_driver(&i40evf_driver);
2894 return ret;
2895}
2896
2897module_init(i40evf_init_module);
2898
2899/**
2900 * i40e_exit_module - Driver Exit Cleanup Routine
2901 *
2902 * i40e_exit_module is called just before the driver is removed
2903 * from memory.
2904 **/
2905static void __exit i40evf_exit_module(void)
2906{
2907 pci_unregister_driver(&i40evf_driver);
2908}
2909
2910module_exit(i40evf_exit_module);
2911
2912/* i40evf_main.c */