blob: 98091b4ccc533ed365c8d6fa131be30360faa970 [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
Catherine Sullivan1e590662015-11-06 15:26:12 -080037#define DRV_VERSION "1.4.3"
Greg Rose5eae00c2013-12-21 06:12:45 +000038const char i40evf_driver_version[] = DRV_VERSION;
39static const char i40evf_copyright[] =
Catherine Sullivanbf418462015-07-10 19:36:10 -040040 "Copyright (c) 2013 - 2015 Intel Corporation.";
Greg Rose5eae00c2013-12-21 06:12:45 +000041
42/* i40evf_pci_tbl - PCI Device ID Table
43 *
44 * Wildcard entries (PCI_ANY_ID) should come last
45 * Last entry must be all 0s
46 *
47 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
48 * Class, Class Mask, private data (not used) }
49 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020050static const struct pci_device_id i40evf_pci_tbl[] = {
Shannon Nelsonab600852014-01-17 15:36:39 -080051 {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0},
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040052 {PCI_VDEVICE(INTEL, I40E_DEV_ID_X722_VF), 0},
Greg Rose5eae00c2013-12-21 06:12:45 +000053 /* required last entry */
54 {0, }
55};
56
57MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl);
58
59MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
60MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
61MODULE_LICENSE("GPL");
62MODULE_VERSION(DRV_VERSION);
63
64/**
65 * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
66 * @hw: pointer to the HW structure
67 * @mem: ptr to mem struct to fill out
68 * @size: size of memory requested
69 * @alignment: what to align the allocation to
70 **/
71i40e_status i40evf_allocate_dma_mem_d(struct i40e_hw *hw,
72 struct i40e_dma_mem *mem,
73 u64 size, u32 alignment)
74{
75 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
76
77 if (!mem)
78 return I40E_ERR_PARAM;
79
80 mem->size = ALIGN(size, alignment);
81 mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size,
82 (dma_addr_t *)&mem->pa, GFP_KERNEL);
83 if (mem->va)
84 return 0;
85 else
86 return I40E_ERR_NO_MEMORY;
87}
88
89/**
90 * i40evf_free_dma_mem_d - OS specific memory free for shared code
91 * @hw: pointer to the HW structure
92 * @mem: ptr to mem struct to free
93 **/
94i40e_status i40evf_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
95{
96 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
97
98 if (!mem || !mem->va)
99 return I40E_ERR_PARAM;
100 dma_free_coherent(&adapter->pdev->dev, mem->size,
101 mem->va, (dma_addr_t)mem->pa);
102 return 0;
103}
104
105/**
106 * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
107 * @hw: pointer to the HW structure
108 * @mem: ptr to mem struct to fill out
109 * @size: size of memory requested
110 **/
111i40e_status i40evf_allocate_virt_mem_d(struct i40e_hw *hw,
112 struct i40e_virt_mem *mem, u32 size)
113{
114 if (!mem)
115 return I40E_ERR_PARAM;
116
117 mem->size = size;
118 mem->va = kzalloc(size, GFP_KERNEL);
119
120 if (mem->va)
121 return 0;
122 else
123 return I40E_ERR_NO_MEMORY;
124}
125
126/**
127 * i40evf_free_virt_mem_d - OS specific memory free for shared code
128 * @hw: pointer to the HW structure
129 * @mem: ptr to mem struct to free
130 **/
131i40e_status i40evf_free_virt_mem_d(struct i40e_hw *hw,
132 struct i40e_virt_mem *mem)
133{
134 if (!mem)
135 return I40E_ERR_PARAM;
136
137 /* it's ok to kfree a NULL pointer */
138 kfree(mem->va);
139
140 return 0;
141}
142
143/**
144 * i40evf_debug_d - OS dependent version of debug printing
145 * @hw: pointer to the HW structure
146 * @mask: debug level mask
147 * @fmt_str: printf-type format description
148 **/
149void i40evf_debug_d(void *hw, u32 mask, char *fmt_str, ...)
150{
151 char buf[512];
152 va_list argptr;
153
154 if (!(mask & ((struct i40e_hw *)hw)->debug_mask))
155 return;
156
157 va_start(argptr, fmt_str);
158 vsnprintf(buf, sizeof(buf), fmt_str, argptr);
159 va_end(argptr);
160
161 /* the debug string is already formatted with a newline */
162 pr_info("%s", buf);
163}
164
165/**
166 * i40evf_tx_timeout - Respond to a Tx Hang
167 * @netdev: network interface device structure
168 **/
169static void i40evf_tx_timeout(struct net_device *netdev)
170{
171 struct i40evf_adapter *adapter = netdev_priv(netdev);
172
173 adapter->tx_timeout_count++;
Mitch Williams67c818a2015-06-19 08:56:30 -0700174 if (!(adapter->flags & (I40EVF_FLAG_RESET_PENDING |
175 I40EVF_FLAG_RESET_NEEDED))) {
Mitch Williams3526d802014-03-06 08:59:56 +0000176 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
Mitch Williams625777e2014-02-20 19:29:05 -0800177 schedule_work(&adapter->reset_task);
178 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000179}
180
181/**
182 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
183 * @adapter: board private structure
184 **/
185static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter)
186{
187 struct i40e_hw *hw = &adapter->hw;
Mitch Williams75a64432014-11-11 20:02:42 +0000188
Greg Rose5eae00c2013-12-21 06:12:45 +0000189 wr32(hw, I40E_VFINT_DYN_CTL01, 0);
190
191 /* read flush */
192 rd32(hw, I40E_VFGEN_RSTAT);
193
194 synchronize_irq(adapter->msix_entries[0].vector);
195}
196
197/**
198 * i40evf_misc_irq_enable - Enable default interrupt generation settings
199 * @adapter: board private structure
200 **/
201static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter)
202{
203 struct i40e_hw *hw = &adapter->hw;
Mitch Williams75a64432014-11-11 20:02:42 +0000204
Greg Rose5eae00c2013-12-21 06:12:45 +0000205 wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK |
206 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400207 wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA1_ADMINQ_MASK);
Greg Rose5eae00c2013-12-21 06:12:45 +0000208
209 /* read flush */
210 rd32(hw, I40E_VFGEN_RSTAT);
211}
212
213/**
214 * i40evf_irq_disable - Mask off interrupt generation on the NIC
215 * @adapter: board private structure
216 **/
217static void i40evf_irq_disable(struct i40evf_adapter *adapter)
218{
219 int i;
220 struct i40e_hw *hw = &adapter->hw;
221
Mitch Williamsdbb01c82014-02-20 19:29:07 -0800222 if (!adapter->msix_entries)
223 return;
224
Greg Rose5eae00c2013-12-21 06:12:45 +0000225 for (i = 1; i < adapter->num_msix_vectors; i++) {
226 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0);
227 synchronize_irq(adapter->msix_entries[i].vector);
228 }
229 /* read flush */
230 rd32(hw, I40E_VFGEN_RSTAT);
Greg Rose5eae00c2013-12-21 06:12:45 +0000231}
232
233/**
234 * i40evf_irq_enable_queues - Enable interrupt for specified queues
235 * @adapter: board private structure
236 * @mask: bitmap of queues to enable
237 **/
238void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask)
239{
240 struct i40e_hw *hw = &adapter->hw;
241 int i;
242
243 for (i = 1; i < adapter->num_msix_vectors; i++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400244 if (mask & BIT(i - 1)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000245 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1),
246 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000247 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400248 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK);
Greg Rose5eae00c2013-12-21 06:12:45 +0000249 }
250 }
251}
252
253/**
254 * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
255 * @adapter: board private structure
256 * @mask: bitmap of vectors to trigger
257 **/
Mitch Williams75a64432014-11-11 20:02:42 +0000258static void i40evf_fire_sw_int(struct i40evf_adapter *adapter, u32 mask)
Greg Rose5eae00c2013-12-21 06:12:45 +0000259{
260 struct i40e_hw *hw = &adapter->hw;
261 int i;
Mitch Williamsd82acb32015-11-06 15:26:06 -0800262 u32 dyn_ctl;
Greg Rose5eae00c2013-12-21 06:12:45 +0000263
Mitch Williams164ec1b2014-06-04 08:45:19 +0000264 if (mask & 1) {
265 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTL01);
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400266 dyn_ctl |= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000267 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400268 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK;
Mitch Williams164ec1b2014-06-04 08:45:19 +0000269 wr32(hw, I40E_VFINT_DYN_CTL01, dyn_ctl);
270 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000271 for (i = 1; i < adapter->num_msix_vectors; i++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400272 if (mask & BIT(i)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000273 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1));
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;
Greg Rose5eae00c2013-12-21 06:12:45 +0000277 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl);
278 }
279 }
280}
281
282/**
283 * i40evf_irq_enable - Enable default interrupt generation settings
284 * @adapter: board private structure
Jean Sacren69c1d702015-10-13 01:06:27 -0600285 * @flush: boolean value whether to run rd32()
Greg Rose5eae00c2013-12-21 06:12:45 +0000286 **/
287void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush)
288{
289 struct i40e_hw *hw = &adapter->hw;
290
Mitch Williams164ec1b2014-06-04 08:45:19 +0000291 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +0000292 i40evf_irq_enable_queues(adapter, ~0);
293
294 if (flush)
295 rd32(hw, I40E_VFGEN_RSTAT);
296}
297
298/**
299 * i40evf_msix_aq - Interrupt handler for vector 0
300 * @irq: interrupt number
301 * @data: pointer to netdev
302 **/
303static irqreturn_t i40evf_msix_aq(int irq, void *data)
304{
305 struct net_device *netdev = data;
306 struct i40evf_adapter *adapter = netdev_priv(netdev);
307 struct i40e_hw *hw = &adapter->hw;
308 u32 val;
Greg Rose5eae00c2013-12-21 06:12:45 +0000309
Jesse Brandeburgcfbe4db2015-10-04 01:09:49 -0700310 /* handle non-queue interrupts, these reads clear the registers */
311 val = rd32(hw, I40E_VFINT_ICR01);
312 val = rd32(hw, I40E_VFINT_ICR0_ENA1);
Greg Rose5eae00c2013-12-21 06:12:45 +0000313
Jean Sacrened17f7e2015-10-13 01:06:30 -0600314 val = rd32(hw, I40E_VFINT_DYN_CTL01) |
315 I40E_VFINT_DYN_CTL01_CLEARPBA_MASK;
Greg Rose5eae00c2013-12-21 06:12:45 +0000316 wr32(hw, I40E_VFINT_DYN_CTL01, val);
317
Greg Rose5eae00c2013-12-21 06:12:45 +0000318 /* schedule work on the private workqueue */
319 schedule_work(&adapter->adminq_task);
320
321 return IRQ_HANDLED;
322}
323
324/**
325 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
326 * @irq: interrupt number
327 * @data: pointer to a q_vector
328 **/
329static irqreturn_t i40evf_msix_clean_rings(int irq, void *data)
330{
331 struct i40e_q_vector *q_vector = data;
332
333 if (!q_vector->tx.ring && !q_vector->rx.ring)
334 return IRQ_HANDLED;
335
Alexander Duyck5d3465a2015-09-29 15:19:50 -0700336 napi_schedule_irqoff(&q_vector->napi);
Greg Rose5eae00c2013-12-21 06:12:45 +0000337
338 return IRQ_HANDLED;
339}
340
341/**
342 * i40evf_map_vector_to_rxq - associate irqs with rx queues
343 * @adapter: board private structure
344 * @v_idx: interrupt number
345 * @r_idx: queue number
346 **/
347static void
348i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx)
349{
Mitch Williams7d96ba12015-10-26 19:44:39 -0400350 struct i40e_q_vector *q_vector = &adapter->q_vectors[v_idx];
Mitch Williams0dd438d2015-10-26 19:44:40 -0400351 struct i40e_ring *rx_ring = &adapter->rx_rings[r_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +0000352
353 rx_ring->q_vector = q_vector;
354 rx_ring->next = q_vector->rx.ring;
355 rx_ring->vsi = &adapter->vsi;
356 q_vector->rx.ring = rx_ring;
357 q_vector->rx.count++;
358 q_vector->rx.latency_range = I40E_LOW_LATENCY;
Jesse Brandeburgee2319c2015-09-28 14:16:54 -0400359 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Greg Rose5eae00c2013-12-21 06:12:45 +0000360}
361
362/**
363 * i40evf_map_vector_to_txq - associate irqs with tx queues
364 * @adapter: board private structure
365 * @v_idx: interrupt number
366 * @t_idx: queue number
367 **/
368static void
369i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx)
370{
Mitch Williams7d96ba12015-10-26 19:44:39 -0400371 struct i40e_q_vector *q_vector = &adapter->q_vectors[v_idx];
Mitch Williams0dd438d2015-10-26 19:44:40 -0400372 struct i40e_ring *tx_ring = &adapter->tx_rings[t_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +0000373
374 tx_ring->q_vector = q_vector;
375 tx_ring->next = q_vector->tx.ring;
376 tx_ring->vsi = &adapter->vsi;
377 q_vector->tx.ring = tx_ring;
378 q_vector->tx.count++;
379 q_vector->tx.latency_range = I40E_LOW_LATENCY;
Jesse Brandeburgee2319c2015-09-28 14:16:54 -0400380 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Greg Rose5eae00c2013-12-21 06:12:45 +0000381 q_vector->num_ringpairs++;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400382 q_vector->ring_mask |= BIT(t_idx);
Greg Rose5eae00c2013-12-21 06:12:45 +0000383}
384
385/**
386 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
387 * @adapter: board private structure to initialize
388 *
389 * This function maps descriptor rings to the queue-specific vectors
390 * we were allotted through the MSI-X enabling code. Ideally, we'd have
391 * one vector per ring/queue, but on a constrained vector budget, we
392 * group the rings as "efficiently" as possible. You would add new
393 * mapping configurations in here.
394 **/
395static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter)
396{
397 int q_vectors;
398 int v_start = 0;
399 int rxr_idx = 0, txr_idx = 0;
Mitch Williamscc052922014-10-25 03:24:34 +0000400 int rxr_remaining = adapter->num_active_queues;
401 int txr_remaining = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +0000402 int i, j;
403 int rqpv, tqpv;
404 int err = 0;
405
406 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
407
408 /* The ideal configuration...
409 * We have enough vectors to map one per queue.
410 */
Mitch Williams973371d2015-04-27 14:57:09 -0400411 if (q_vectors >= (rxr_remaining * 2)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000412 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
413 i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx);
414
415 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
416 i40evf_map_vector_to_txq(adapter, v_start, txr_idx);
417 goto out;
418 }
419
420 /* If we don't have enough vectors for a 1-to-1
421 * mapping, we'll have to group them so there are
422 * multiple queues per vector.
423 * Re-adjusting *qpv takes care of the remainder.
424 */
425 for (i = v_start; i < q_vectors; i++) {
426 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
427 for (j = 0; j < rqpv; j++) {
428 i40evf_map_vector_to_rxq(adapter, i, rxr_idx);
429 rxr_idx++;
430 rxr_remaining--;
431 }
432 }
433 for (i = v_start; i < q_vectors; i++) {
434 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
435 for (j = 0; j < tqpv; j++) {
436 i40evf_map_vector_to_txq(adapter, i, txr_idx);
437 txr_idx++;
438 txr_remaining--;
439 }
440 }
441
442out:
443 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
444
445 return err;
446}
447
Alexander Duyck7709b4c2015-09-24 09:04:38 -0700448#ifdef CONFIG_NET_POLL_CONTROLLER
449/**
450 * i40evf_netpoll - A Polling 'interrupt' handler
451 * @netdev: network interface device structure
452 *
453 * This is used by netconsole to send skbs without having to re-enable
454 * interrupts. It's not called while the normal interrupt routine is executing.
455 **/
456static void i40evf_netpoll(struct net_device *netdev)
457{
458 struct i40evf_adapter *adapter = netdev_priv(netdev);
459 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
460 int i;
461
462 /* if interface is down do nothing */
463 if (test_bit(__I40E_DOWN, &adapter->vsi.state))
464 return;
465
466 for (i = 0; i < q_vectors; i++)
Mitch Williams7d96ba12015-10-26 19:44:39 -0400467 i40evf_msix_clean_rings(0, &adapter->q_vectors[i]);
Alexander Duyck7709b4c2015-09-24 09:04:38 -0700468}
469
470#endif
Greg Rose5eae00c2013-12-21 06:12:45 +0000471/**
472 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
473 * @adapter: board private structure
474 *
475 * Allocates MSI-X vectors for tx and rx handling, and requests
476 * interrupts from the kernel.
477 **/
478static int
479i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename)
480{
481 int vector, err, q_vectors;
482 int rx_int_idx = 0, tx_int_idx = 0;
483
484 i40evf_irq_disable(adapter);
485 /* Decrement for Other and TCP Timer vectors */
486 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
487
488 for (vector = 0; vector < q_vectors; vector++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -0400489 struct i40e_q_vector *q_vector = &adapter->q_vectors[vector];
Greg Rose5eae00c2013-12-21 06:12:45 +0000490
491 if (q_vector->tx.ring && q_vector->rx.ring) {
492 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
493 "i40evf-%s-%s-%d", basename,
494 "TxRx", rx_int_idx++);
495 tx_int_idx++;
496 } else if (q_vector->rx.ring) {
497 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
498 "i40evf-%s-%s-%d", basename,
499 "rx", rx_int_idx++);
500 } else if (q_vector->tx.ring) {
501 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
502 "i40evf-%s-%s-%d", basename,
503 "tx", tx_int_idx++);
504 } else {
505 /* skip this unused q_vector */
506 continue;
507 }
508 err = request_irq(
509 adapter->msix_entries[vector + NONQ_VECS].vector,
510 i40evf_msix_clean_rings,
511 0,
512 q_vector->name,
513 q_vector);
514 if (err) {
515 dev_info(&adapter->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400516 "Request_irq failed, error: %d\n", err);
Greg Rose5eae00c2013-12-21 06:12:45 +0000517 goto free_queue_irqs;
518 }
519 /* assign the mask for this irq */
520 irq_set_affinity_hint(
521 adapter->msix_entries[vector + NONQ_VECS].vector,
522 q_vector->affinity_mask);
523 }
524
525 return 0;
526
527free_queue_irqs:
528 while (vector) {
529 vector--;
530 irq_set_affinity_hint(
531 adapter->msix_entries[vector + NONQ_VECS].vector,
532 NULL);
533 free_irq(adapter->msix_entries[vector + NONQ_VECS].vector,
Mitch Williams7d96ba12015-10-26 19:44:39 -0400534 &adapter->q_vectors[vector]);
Greg Rose5eae00c2013-12-21 06:12:45 +0000535 }
536 return err;
537}
538
539/**
540 * i40evf_request_misc_irq - Initialize MSI-X interrupts
541 * @adapter: board private structure
542 *
543 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
544 * vector is only for the admin queue, and stays active even when the netdev
545 * is closed.
546 **/
547static int i40evf_request_misc_irq(struct i40evf_adapter *adapter)
548{
549 struct net_device *netdev = adapter->netdev;
550 int err;
551
Jesse Brandeburgb39c1e22014-08-01 13:27:08 -0700552 snprintf(adapter->misc_vector_name,
Carolyn Wyborny9a21a002015-02-06 08:52:20 +0000553 sizeof(adapter->misc_vector_name) - 1, "i40evf-%s:mbx",
554 dev_name(&adapter->pdev->dev));
Greg Rose5eae00c2013-12-21 06:12:45 +0000555 err = request_irq(adapter->msix_entries[0].vector,
Mitch Williamse1dfee82014-02-13 03:48:51 -0800556 &i40evf_msix_aq, 0,
557 adapter->misc_vector_name, netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +0000558 if (err) {
559 dev_err(&adapter->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -0800560 "request_irq for %s failed: %d\n",
561 adapter->misc_vector_name, err);
Greg Rose5eae00c2013-12-21 06:12:45 +0000562 free_irq(adapter->msix_entries[0].vector, netdev);
563 }
564 return err;
565}
566
567/**
568 * i40evf_free_traffic_irqs - Free MSI-X interrupts
569 * @adapter: board private structure
570 *
571 * Frees all MSI-X vectors other than 0.
572 **/
573static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter)
574{
575 int i;
576 int q_vectors;
Mitch Williams75a64432014-11-11 20:02:42 +0000577
Greg Rose5eae00c2013-12-21 06:12:45 +0000578 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
579
580 for (i = 0; i < q_vectors; i++) {
581 irq_set_affinity_hint(adapter->msix_entries[i+1].vector,
582 NULL);
583 free_irq(adapter->msix_entries[i+1].vector,
Mitch Williams7d96ba12015-10-26 19:44:39 -0400584 &adapter->q_vectors[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +0000585 }
586}
587
588/**
589 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
590 * @adapter: board private structure
591 *
592 * Frees MSI-X vector 0.
593 **/
594static void i40evf_free_misc_irq(struct i40evf_adapter *adapter)
595{
596 struct net_device *netdev = adapter->netdev;
597
598 free_irq(adapter->msix_entries[0].vector, netdev);
599}
600
601/**
602 * i40evf_configure_tx - Configure Transmit Unit after Reset
603 * @adapter: board private structure
604 *
605 * Configure the Tx unit of the MAC after a reset.
606 **/
607static void i40evf_configure_tx(struct i40evf_adapter *adapter)
608{
609 struct i40e_hw *hw = &adapter->hw;
610 int i;
Mitch Williams75a64432014-11-11 20:02:42 +0000611
Mitch Williamscc052922014-10-25 03:24:34 +0000612 for (i = 0; i < adapter->num_active_queues; i++)
Mitch Williams0dd438d2015-10-26 19:44:40 -0400613 adapter->tx_rings[i].tail = hw->hw_addr + I40E_QTX_TAIL1(i);
Greg Rose5eae00c2013-12-21 06:12:45 +0000614}
615
616/**
617 * i40evf_configure_rx - Configure Receive Unit after Reset
618 * @adapter: board private structure
619 *
620 * Configure the Rx unit of the MAC after a reset.
621 **/
622static void i40evf_configure_rx(struct i40evf_adapter *adapter)
623{
624 struct i40e_hw *hw = &adapter->hw;
625 struct net_device *netdev = adapter->netdev;
626 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
627 int i;
628 int rx_buf_len;
629
630
631 adapter->flags &= ~I40EVF_FLAG_RX_PS_CAPABLE;
632 adapter->flags |= I40EVF_FLAG_RX_1BUF_CAPABLE;
633
634 /* Decide whether to use packet split mode or not */
635 if (netdev->mtu > ETH_DATA_LEN) {
636 if (adapter->flags & I40EVF_FLAG_RX_PS_CAPABLE)
637 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
638 else
639 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
640 } else {
641 if (adapter->flags & I40EVF_FLAG_RX_1BUF_CAPABLE)
642 adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
643 else
644 adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
645 }
646
647 /* Set the RX buffer length according to the mode */
648 if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) {
649 rx_buf_len = I40E_RX_HDR_SIZE;
650 } else {
651 if (netdev->mtu <= ETH_DATA_LEN)
652 rx_buf_len = I40EVF_RXBUFFER_2048;
653 else
654 rx_buf_len = ALIGN(max_frame, 1024);
655 }
656
Mitch Williamscc052922014-10-25 03:24:34 +0000657 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williams0dd438d2015-10-26 19:44:40 -0400658 adapter->rx_rings[i].tail = hw->hw_addr + I40E_QRX_TAIL1(i);
659 adapter->rx_rings[i].rx_buf_len = rx_buf_len;
Greg Rose5eae00c2013-12-21 06:12:45 +0000660 }
661}
662
663/**
664 * i40evf_find_vlan - Search filter list for specific vlan filter
665 * @adapter: board private structure
666 * @vlan: vlan tag
667 *
668 * Returns ptr to the filter object or NULL
669 **/
670static struct
671i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan)
672{
673 struct i40evf_vlan_filter *f;
674
675 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
676 if (vlan == f->vlan)
677 return f;
678 }
679 return NULL;
680}
681
682/**
683 * i40evf_add_vlan - Add a vlan filter to the list
684 * @adapter: board private structure
685 * @vlan: VLAN tag
686 *
687 * Returns ptr to the filter object or NULL when no memory available.
688 **/
689static struct
690i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan)
691{
Mitch Williams13acb542015-03-31 00:45:05 -0700692 struct i40evf_vlan_filter *f = NULL;
693 int count = 50;
694
695 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
696 &adapter->crit_section)) {
697 udelay(1);
698 if (--count == 0)
699 goto out;
700 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000701
702 f = i40evf_find_vlan(adapter, vlan);
Mitch Williams348d4992014-11-11 20:02:52 +0000703 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000704 f = kzalloc(sizeof(*f), GFP_ATOMIC);
Mitch Williams348d4992014-11-11 20:02:52 +0000705 if (!f)
Mitch Williams13acb542015-03-31 00:45:05 -0700706 goto clearout;
Mitch Williams249c8b82014-05-10 04:49:04 +0000707
Greg Rose5eae00c2013-12-21 06:12:45 +0000708 f->vlan = vlan;
709
710 INIT_LIST_HEAD(&f->list);
711 list_add(&f->list, &adapter->vlan_filter_list);
712 f->add = true;
713 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
714 }
715
Mitch Williams13acb542015-03-31 00:45:05 -0700716clearout:
717 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
718out:
Greg Rose5eae00c2013-12-21 06:12:45 +0000719 return f;
720}
721
722/**
723 * i40evf_del_vlan - Remove a vlan filter from the list
724 * @adapter: board private structure
725 * @vlan: VLAN tag
726 **/
727static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan)
728{
729 struct i40evf_vlan_filter *f;
Mitch Williams13acb542015-03-31 00:45:05 -0700730 int count = 50;
731
732 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
733 &adapter->crit_section)) {
734 udelay(1);
735 if (--count == 0)
736 return;
737 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000738
739 f = i40evf_find_vlan(adapter, vlan);
740 if (f) {
741 f->remove = true;
742 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
743 }
Mitch Williams13acb542015-03-31 00:45:05 -0700744 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Greg Rose5eae00c2013-12-21 06:12:45 +0000745}
746
747/**
748 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
749 * @netdev: network device struct
750 * @vid: VLAN tag
751 **/
752static int i40evf_vlan_rx_add_vid(struct net_device *netdev,
Mitch Williams75a64432014-11-11 20:02:42 +0000753 __always_unused __be16 proto, u16 vid)
Greg Rose5eae00c2013-12-21 06:12:45 +0000754{
755 struct i40evf_adapter *adapter = netdev_priv(netdev);
756
Mitch Williams8ed995f2015-08-28 17:55:57 -0400757 if (!VLAN_ALLOWED(adapter))
758 return -EIO;
Greg Rose5eae00c2013-12-21 06:12:45 +0000759 if (i40evf_add_vlan(adapter, vid) == NULL)
760 return -ENOMEM;
761 return 0;
762}
763
764/**
765 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
766 * @netdev: network device struct
767 * @vid: VLAN tag
768 **/
769static int i40evf_vlan_rx_kill_vid(struct net_device *netdev,
Mitch Williams75a64432014-11-11 20:02:42 +0000770 __always_unused __be16 proto, u16 vid)
Greg Rose5eae00c2013-12-21 06:12:45 +0000771{
772 struct i40evf_adapter *adapter = netdev_priv(netdev);
773
Mitch Williams8ed995f2015-08-28 17:55:57 -0400774 if (VLAN_ALLOWED(adapter)) {
775 i40evf_del_vlan(adapter, vid);
776 return 0;
777 }
778 return -EIO;
Greg Rose5eae00c2013-12-21 06:12:45 +0000779}
780
781/**
782 * i40evf_find_filter - Search filter list for specific mac filter
783 * @adapter: board private structure
784 * @macaddr: the MAC address
785 *
786 * Returns ptr to the filter object or NULL
787 **/
788static struct
789i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter,
790 u8 *macaddr)
791{
792 struct i40evf_mac_filter *f;
793
794 if (!macaddr)
795 return NULL;
796
797 list_for_each_entry(f, &adapter->mac_filter_list, list) {
798 if (ether_addr_equal(macaddr, f->macaddr))
799 return f;
800 }
801 return NULL;
802}
803
804/**
805 * i40e_add_filter - Add a mac filter to the filter list
806 * @adapter: board private structure
807 * @macaddr: the MAC address
808 *
809 * Returns ptr to the filter object or NULL when no memory available.
810 **/
811static struct
812i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter,
813 u8 *macaddr)
814{
815 struct i40evf_mac_filter *f;
Mitch Williams54e16f62015-01-29 07:17:20 +0000816 int count = 50;
Greg Rose5eae00c2013-12-21 06:12:45 +0000817
818 if (!macaddr)
819 return NULL;
820
821 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
Mitch Williams54e16f62015-01-29 07:17:20 +0000822 &adapter->crit_section)) {
Mitch Williamsb65476c2014-07-09 07:46:14 +0000823 udelay(1);
Mitch Williams54e16f62015-01-29 07:17:20 +0000824 if (--count == 0)
825 return NULL;
826 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000827
828 f = i40evf_find_filter(adapter, macaddr);
Mitch Williams348d4992014-11-11 20:02:52 +0000829 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000830 f = kzalloc(sizeof(*f), GFP_ATOMIC);
Mitch Williams348d4992014-11-11 20:02:52 +0000831 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000832 clear_bit(__I40EVF_IN_CRITICAL_TASK,
833 &adapter->crit_section);
834 return NULL;
835 }
836
Greg Rose9a173902014-05-22 06:32:02 +0000837 ether_addr_copy(f->macaddr, macaddr);
Greg Rose5eae00c2013-12-21 06:12:45 +0000838
839 list_add(&f->list, &adapter->mac_filter_list);
840 f->add = true;
841 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
842 }
843
844 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
845 return f;
846}
847
848/**
849 * i40evf_set_mac - NDO callback to set port mac address
850 * @netdev: network interface device structure
851 * @p: pointer to an address structure
852 *
853 * Returns 0 on success, negative on failure
854 **/
855static int i40evf_set_mac(struct net_device *netdev, void *p)
856{
857 struct i40evf_adapter *adapter = netdev_priv(netdev);
858 struct i40e_hw *hw = &adapter->hw;
859 struct i40evf_mac_filter *f;
860 struct sockaddr *addr = p;
861
862 if (!is_valid_ether_addr(addr->sa_data))
863 return -EADDRNOTAVAIL;
864
865 if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
866 return 0;
867
Mitch Williams14e52ee2015-08-31 19:54:44 -0400868 if (adapter->flags & I40EVF_FLAG_ADDR_SET_BY_PF)
869 return -EPERM;
870
871 f = i40evf_find_filter(adapter, hw->mac.addr);
872 if (f) {
873 f->remove = true;
874 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
875 }
876
Greg Rose5eae00c2013-12-21 06:12:45 +0000877 f = i40evf_add_filter(adapter, addr->sa_data);
878 if (f) {
Greg Rose9a173902014-05-22 06:32:02 +0000879 ether_addr_copy(hw->mac.addr, addr->sa_data);
880 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +0000881 }
882
883 return (f == NULL) ? -ENOMEM : 0;
884}
885
886/**
887 * i40evf_set_rx_mode - NDO callback to set the netdev filters
888 * @netdev: network interface device structure
889 **/
890static void i40evf_set_rx_mode(struct net_device *netdev)
891{
892 struct i40evf_adapter *adapter = netdev_priv(netdev);
893 struct i40evf_mac_filter *f, *ftmp;
894 struct netdev_hw_addr *uca;
895 struct netdev_hw_addr *mca;
Shannon Nelson2f41f332015-08-26 15:14:20 -0400896 struct netdev_hw_addr *ha;
Mitch Williams54e16f62015-01-29 07:17:20 +0000897 int count = 50;
Greg Rose5eae00c2013-12-21 06:12:45 +0000898
899 /* add addr if not already in the filter list */
900 netdev_for_each_uc_addr(uca, netdev) {
901 i40evf_add_filter(adapter, uca->addr);
902 }
903 netdev_for_each_mc_addr(mca, netdev) {
904 i40evf_add_filter(adapter, mca->addr);
905 }
906
907 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
Mitch Williams54e16f62015-01-29 07:17:20 +0000908 &adapter->crit_section)) {
Mitch Williamsb65476c2014-07-09 07:46:14 +0000909 udelay(1);
Mitch Williams54e16f62015-01-29 07:17:20 +0000910 if (--count == 0) {
911 dev_err(&adapter->pdev->dev,
912 "Failed to get lock in %s\n", __func__);
913 return;
914 }
915 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000916 /* remove filter if not in netdev list */
917 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
Shannon Nelson2f41f332015-08-26 15:14:20 -0400918 netdev_for_each_mc_addr(mca, netdev)
919 if (ether_addr_equal(mca->addr, f->macaddr))
920 goto bottom_of_search_loop;
Greg Rose5eae00c2013-12-21 06:12:45 +0000921
Shannon Nelson2f41f332015-08-26 15:14:20 -0400922 netdev_for_each_uc_addr(uca, netdev)
923 if (ether_addr_equal(uca->addr, f->macaddr))
924 goto bottom_of_search_loop;
925
926 for_each_dev_addr(netdev, ha)
927 if (ether_addr_equal(ha->addr, f->macaddr))
928 goto bottom_of_search_loop;
929
930 if (ether_addr_equal(f->macaddr, adapter->hw.mac.addr))
931 goto bottom_of_search_loop;
932
933 /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
934 f->remove = true;
935 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
936
937bottom_of_search_loop:
938 continue;
Greg Rose5eae00c2013-12-21 06:12:45 +0000939 }
940 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
941}
942
943/**
944 * i40evf_napi_enable_all - enable NAPI on all queue vectors
945 * @adapter: board private structure
946 **/
947static void i40evf_napi_enable_all(struct i40evf_adapter *adapter)
948{
949 int q_idx;
950 struct i40e_q_vector *q_vector;
951 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
952
953 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
954 struct napi_struct *napi;
Mitch Williams75a64432014-11-11 20:02:42 +0000955
Mitch Williams7d96ba12015-10-26 19:44:39 -0400956 q_vector = &adapter->q_vectors[q_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +0000957 napi = &q_vector->napi;
958 napi_enable(napi);
959 }
960}
961
962/**
963 * i40evf_napi_disable_all - disable NAPI on all queue vectors
964 * @adapter: board private structure
965 **/
966static void i40evf_napi_disable_all(struct i40evf_adapter *adapter)
967{
968 int q_idx;
969 struct i40e_q_vector *q_vector;
970 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
971
972 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -0400973 q_vector = &adapter->q_vectors[q_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +0000974 napi_disable(&q_vector->napi);
975 }
976}
977
978/**
979 * i40evf_configure - set up transmit and receive data structures
980 * @adapter: board private structure
981 **/
982static void i40evf_configure(struct i40evf_adapter *adapter)
983{
984 struct net_device *netdev = adapter->netdev;
985 int i;
986
987 i40evf_set_rx_mode(netdev);
988
989 i40evf_configure_tx(adapter);
990 i40evf_configure_rx(adapter);
991 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
992
Mitch Williamscc052922014-10-25 03:24:34 +0000993 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williams0dd438d2015-10-26 19:44:40 -0400994 struct i40e_ring *ring = &adapter->rx_rings[i];
Mitch Williams75a64432014-11-11 20:02:42 +0000995
Mitch Williamsa132af22015-01-24 09:58:35 +0000996 i40evf_alloc_rx_buffers_1buf(ring, ring->count);
Greg Rose5eae00c2013-12-21 06:12:45 +0000997 ring->next_to_use = ring->count - 1;
998 writel(ring->next_to_use, ring->tail);
999 }
1000}
1001
1002/**
1003 * i40evf_up_complete - Finish the last steps of bringing up a connection
1004 * @adapter: board private structure
1005 **/
1006static int i40evf_up_complete(struct i40evf_adapter *adapter)
1007{
1008 adapter->state = __I40EVF_RUNNING;
1009 clear_bit(__I40E_DOWN, &adapter->vsi.state);
1010
1011 i40evf_napi_enable_all(adapter);
1012
1013 adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
1014 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
1015 return 0;
1016}
1017
1018/**
Greg Rose5eae00c2013-12-21 06:12:45 +00001019 * i40e_down - Shutdown the connection processing
1020 * @adapter: board private structure
1021 **/
1022void i40evf_down(struct i40evf_adapter *adapter)
1023{
1024 struct net_device *netdev = adapter->netdev;
1025 struct i40evf_mac_filter *f;
1026
Mitch Williamsddf0b3a2014-05-22 06:31:46 +00001027 if (adapter->state == __I40EVF_DOWN)
1028 return;
1029
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001030 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1031 &adapter->crit_section))
1032 usleep_range(500, 1000);
1033
Mitch Williams63e18c22015-03-27 00:12:10 -07001034 netif_carrier_off(netdev);
1035 netif_tx_disable(netdev);
Mitch Williams748c4342015-01-29 07:17:18 +00001036 i40evf_napi_disable_all(adapter);
Mitch Williams63e18c22015-03-27 00:12:10 -07001037 i40evf_irq_disable(adapter);
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001038
Mitch Williamsef8693e2014-02-13 03:48:53 -08001039 /* remove all MAC filters */
Greg Rose5eae00c2013-12-21 06:12:45 +00001040 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1041 f->remove = true;
1042 }
Mitch Williamsed1f5b52014-02-20 19:29:06 -08001043 /* remove all VLAN filters */
1044 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
1045 f->remove = true;
1046 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001047 if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) &&
1048 adapter->state != __I40EVF_RESETTING) {
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001049 /* cancel any current operation */
1050 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001051 /* Schedule operations to close down the HW. Don't wait
1052 * here for this to complete. The watchdog is still running
1053 * and it will take care of this.
1054 */
1055 adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Mitch Williamsed1f5b52014-02-20 19:29:06 -08001056 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001057 adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001058 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001059
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001060 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Greg Rose5eae00c2013-12-21 06:12:45 +00001061}
1062
1063/**
1064 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1065 * @adapter: board private structure
1066 * @vectors: number of vectors to request
1067 *
1068 * Work with the OS to set up the MSIX vectors needed.
1069 *
1070 * Returns 0 on success, negative on failure
1071 **/
1072static int
1073i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors)
1074{
1075 int err, vector_threshold;
1076
1077 /* We'll want at least 3 (vector_threshold):
1078 * 0) Other (Admin Queue and link, mostly)
1079 * 1) TxQ[0] Cleanup
1080 * 2) RxQ[0] Cleanup
1081 */
1082 vector_threshold = MIN_MSIX_COUNT;
1083
1084 /* The more we get, the more we will assign to Tx/Rx Cleanup
1085 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1086 * Right now, we simply care about how many we'll get; we'll
1087 * set them up later while requesting irq's.
1088 */
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001089 err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
1090 vector_threshold, vectors);
1091 if (err < 0) {
Mitch Williams80e72892014-05-10 04:49:06 +00001092 dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001093 kfree(adapter->msix_entries);
1094 adapter->msix_entries = NULL;
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001095 return err;
Greg Rose5eae00c2013-12-21 06:12:45 +00001096 }
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001097
1098 /* Adjust for only the vectors we'll use, which is minimum
1099 * of max_msix_q_vectors + NONQ_VECS, or the number of
1100 * vectors we were allocated.
1101 */
1102 adapter->num_msix_vectors = err;
1103 return 0;
Greg Rose5eae00c2013-12-21 06:12:45 +00001104}
1105
1106/**
1107 * i40evf_free_queues - Free memory for all rings
1108 * @adapter: board private structure to initialize
1109 *
1110 * Free all of the memory associated with queue pairs.
1111 **/
1112static void i40evf_free_queues(struct i40evf_adapter *adapter)
1113{
Greg Rose5eae00c2013-12-21 06:12:45 +00001114 if (!adapter->vsi_res)
1115 return;
Mitch Williams0dd438d2015-10-26 19:44:40 -04001116 kfree(adapter->tx_rings);
1117 kfree(adapter->rx_rings);
Greg Rose5eae00c2013-12-21 06:12:45 +00001118}
1119
1120/**
1121 * i40evf_alloc_queues - Allocate memory for all rings
1122 * @adapter: board private structure to initialize
1123 *
1124 * We allocate one ring per queue at run-time since we don't know the
1125 * number of queues at compile-time. The polling_netdev array is
1126 * intended for Multiqueue, but should work fine with a single queue.
1127 **/
1128static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
1129{
1130 int i;
1131
Mitch Williams0dd438d2015-10-26 19:44:40 -04001132 adapter->tx_rings = kcalloc(adapter->num_active_queues,
1133 sizeof(struct i40e_ring), GFP_KERNEL);
1134 if (!adapter->tx_rings)
1135 goto err_out;
1136 adapter->rx_rings = kcalloc(adapter->num_active_queues,
1137 sizeof(struct i40e_ring), GFP_KERNEL);
1138 if (!adapter->rx_rings)
1139 goto err_out;
1140
Mitch Williamscc052922014-10-25 03:24:34 +00001141 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001142 struct i40e_ring *tx_ring;
1143 struct i40e_ring *rx_ring;
1144
Mitch Williams0dd438d2015-10-26 19:44:40 -04001145 tx_ring = &adapter->tx_rings[i];
Greg Rose5eae00c2013-12-21 06:12:45 +00001146
1147 tx_ring->queue_index = i;
1148 tx_ring->netdev = adapter->netdev;
1149 tx_ring->dev = &adapter->pdev->dev;
Mitch Williamsd732a182014-04-24 06:41:37 +00001150 tx_ring->count = adapter->tx_desc_count;
Anjali Singhai Jain1f012272015-09-03 17:18:53 -04001151 if (adapter->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
1152 tx_ring->flags |= I40E_TXR_FLAGS_WB_ON_ITR;
Greg Rose5eae00c2013-12-21 06:12:45 +00001153
Mitch Williams0dd438d2015-10-26 19:44:40 -04001154 rx_ring = &adapter->rx_rings[i];
Greg Rose5eae00c2013-12-21 06:12:45 +00001155 rx_ring->queue_index = i;
1156 rx_ring->netdev = adapter->netdev;
1157 rx_ring->dev = &adapter->pdev->dev;
Mitch Williamsd732a182014-04-24 06:41:37 +00001158 rx_ring->count = adapter->rx_desc_count;
Greg Rose5eae00c2013-12-21 06:12:45 +00001159 }
1160
1161 return 0;
1162
1163err_out:
1164 i40evf_free_queues(adapter);
1165 return -ENOMEM;
1166}
1167
1168/**
1169 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1170 * @adapter: board private structure to initialize
1171 *
1172 * Attempt to configure the interrupts using the best available
1173 * capabilities of the hardware and the kernel.
1174 **/
1175static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter)
1176{
1177 int vector, v_budget;
1178 int pairs = 0;
1179 int err = 0;
1180
1181 if (!adapter->vsi_res) {
1182 err = -EIO;
1183 goto out;
1184 }
Mitch Williamscc052922014-10-25 03:24:34 +00001185 pairs = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +00001186
1187 /* It's easy to be greedy for MSI-X vectors, but it really
1188 * doesn't do us much good if we have a lot more vectors
1189 * than CPU's. So let's be conservative and only ask for
1190 * (roughly) twice the number of vectors as there are CPU's.
1191 */
Mitch Williams30a500e2014-02-11 08:27:52 +00001192 v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS;
1193 v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors);
Greg Rose5eae00c2013-12-21 06:12:45 +00001194
Greg Rose5eae00c2013-12-21 06:12:45 +00001195 adapter->msix_entries = kcalloc(v_budget,
1196 sizeof(struct msix_entry), GFP_KERNEL);
1197 if (!adapter->msix_entries) {
1198 err = -ENOMEM;
1199 goto out;
1200 }
1201
1202 for (vector = 0; vector < v_budget; vector++)
1203 adapter->msix_entries[vector].entry = vector;
1204
Mitch Williams313ed2d2015-08-27 11:42:31 -04001205 err = i40evf_acquire_msix_vectors(adapter, v_budget);
Greg Rose5eae00c2013-12-21 06:12:45 +00001206
1207out:
Mitch Williamse6c4cf62015-11-06 15:26:00 -08001208 netif_set_real_num_rx_queues(adapter->netdev, pairs);
1209 netif_set_real_num_tx_queues(adapter->netdev, pairs);
Greg Rose5eae00c2013-12-21 06:12:45 +00001210 return err;
1211}
1212
1213/**
Helin Zhang2c86ac32015-10-27 16:15:06 -04001214 * i40e_config_rss_aq - Prepare for RSS using AQ commands
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001215 * @vsi: vsi structure
1216 * @seed: RSS hash seed
Helin Zhang2c86ac32015-10-27 16:15:06 -04001217 * @lut: Lookup table
1218 * @lut_size: Lookup table size
1219 *
1220 * Return 0 on success, negative on failure
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001221 **/
Helin Zhang2c86ac32015-10-27 16:15:06 -04001222static int i40evf_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
1223 u8 *lut, u16 lut_size)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001224{
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001225 struct i40evf_adapter *adapter = vsi->back;
1226 struct i40e_hw *hw = &adapter->hw;
Helin Zhang2c86ac32015-10-27 16:15:06 -04001227 int ret = 0;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001228
1229 if (!vsi->id)
Helin Zhang2c86ac32015-10-27 16:15:06 -04001230 return -EINVAL;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001231
1232 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
1233 /* bail because we already have a command pending */
1234 dev_err(&adapter->pdev->dev, "Cannot confiure RSS, command %d pending\n",
1235 adapter->current_op);
Helin Zhang2c86ac32015-10-27 16:15:06 -04001236 return -EBUSY;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001237 }
1238
Helin Zhang2c86ac32015-10-27 16:15:06 -04001239 if (seed) {
1240 struct i40e_aqc_get_set_rss_key_data *rss_key =
1241 (struct i40e_aqc_get_set_rss_key_data *)seed;
1242 ret = i40evf_aq_set_rss_key(hw, vsi->id, rss_key);
1243 if (ret) {
1244 dev_err(&adapter->pdev->dev, "Cannot set RSS key, err %s aq_err %s\n",
1245 i40evf_stat_str(hw, ret),
1246 i40evf_aq_str(hw, hw->aq.asq_last_status));
1247 return ret;
1248 }
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001249 }
1250
Helin Zhang2c86ac32015-10-27 16:15:06 -04001251 if (lut) {
1252 ret = i40evf_aq_set_rss_lut(hw, vsi->id, false, lut, lut_size);
1253 if (ret) {
1254 dev_err(&adapter->pdev->dev,
1255 "Cannot set RSS lut, err %s aq_err %s\n",
1256 i40evf_stat_str(hw, ret),
1257 i40evf_aq_str(hw, hw->aq.asq_last_status));
1258 return ret;
1259 }
1260 }
1261
1262 return ret;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001263}
1264
1265/**
Helin Zhang2c86ac32015-10-27 16:15:06 -04001266 * i40evf_config_rss_reg - Configure RSS keys and lut by writing registers
1267 * @vsi: Pointer to vsi structure
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001268 * @seed: RSS hash seed
Helin Zhang2c86ac32015-10-27 16:15:06 -04001269 * @lut: Lookup table
1270 * @lut_size: Lookup table size
1271 *
1272 * Returns 0 on success, negative on failure
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001273 **/
Helin Zhang2c86ac32015-10-27 16:15:06 -04001274static int i40evf_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
1275 const u8 *lut, u16 lut_size)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001276{
Helin Zhang2c86ac32015-10-27 16:15:06 -04001277 struct i40evf_adapter *adapter = vsi->back;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001278 struct i40e_hw *hw = &adapter->hw;
Helin Zhang2c86ac32015-10-27 16:15:06 -04001279 u16 i;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001280
Helin Zhang2c86ac32015-10-27 16:15:06 -04001281 if (seed) {
1282 u32 *seed_dw = (u32 *)seed;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001283
Helin Zhang2c86ac32015-10-27 16:15:06 -04001284 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1285 wr32(hw, I40E_VFQF_HKEY(i), seed_dw[i]);
1286 }
1287
1288 if (lut) {
1289 u32 *lut_dw = (u32 *)lut;
1290
1291 if (lut_size != I40EVF_HLUT_ARRAY_SIZE)
1292 return -EINVAL;
1293
1294 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
1295 wr32(hw, I40E_VFQF_HLUT(i), lut_dw[i]);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001296 }
1297 i40e_flush(hw);
Helin Zhang2c86ac32015-10-27 16:15:06 -04001298
1299 return 0;
1300}
1301
1302/**
Helin Zhang90b02b42015-10-26 19:44:33 -04001303 * * i40evf_get_rss_aq - Get RSS keys and lut by using AQ commands
1304 * @vsi: Pointer to vsi structure
1305 * @seed: RSS hash seed
1306 * @lut: Lookup table
1307 * @lut_size: Lookup table size
1308 *
1309 * Return 0 on success, negative on failure
1310 **/
1311static int i40evf_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
1312 u8 *lut, u16 lut_size)
1313{
1314 struct i40evf_adapter *adapter = vsi->back;
1315 struct i40e_hw *hw = &adapter->hw;
1316 int ret = 0;
1317
1318 if (seed) {
1319 ret = i40evf_aq_get_rss_key(hw, vsi->id,
1320 (struct i40e_aqc_get_set_rss_key_data *)seed);
1321 if (ret) {
1322 dev_err(&adapter->pdev->dev,
1323 "Cannot get RSS key, err %s aq_err %s\n",
1324 i40evf_stat_str(hw, ret),
1325 i40evf_aq_str(hw, hw->aq.asq_last_status));
1326 return ret;
1327 }
1328 }
1329
1330 if (lut) {
1331 ret = i40evf_aq_get_rss_lut(hw, vsi->id, seed, lut, lut_size);
1332 if (ret) {
1333 dev_err(&adapter->pdev->dev,
1334 "Cannot get RSS lut, err %s aq_err %s\n",
1335 i40evf_stat_str(hw, ret),
1336 i40evf_aq_str(hw, hw->aq.asq_last_status));
1337 return ret;
1338 }
1339 }
1340
1341 return ret;
1342}
1343
1344/**
1345 * * i40evf_get_rss_reg - Get RSS keys and lut by reading registers
1346 * @vsi: Pointer to vsi structure
1347 * @seed: RSS hash seed
1348 * @lut: Lookup table
1349 * @lut_size: Lookup table size
1350 *
1351 * Returns 0 on success, negative on failure
1352 **/
1353static int i40evf_get_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
1354 const u8 *lut, u16 lut_size)
1355{
1356 struct i40evf_adapter *adapter = vsi->back;
1357 struct i40e_hw *hw = &adapter->hw;
1358 u16 i;
1359
1360 if (seed) {
1361 u32 *seed_dw = (u32 *)seed;
1362
1363 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
1364 seed_dw[i] = rd32(hw, I40E_VFQF_HKEY(i));
1365 }
1366
1367 if (lut) {
1368 u32 *lut_dw = (u32 *)lut;
1369
1370 if (lut_size != I40EVF_HLUT_ARRAY_SIZE)
1371 return -EINVAL;
1372
1373 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
1374 lut_dw[i] = rd32(hw, I40E_VFQF_HLUT(i));
1375 }
1376
1377 return 0;
1378}
1379
1380/**
Helin Zhang2c86ac32015-10-27 16:15:06 -04001381 * i40evf_config_rss - Configure RSS keys and lut
1382 * @vsi: Pointer to vsi structure
1383 * @seed: RSS hash seed
1384 * @lut: Lookup table
1385 * @lut_size: Lookup table size
1386 *
1387 * Returns 0 on success, negative on failure
1388 **/
1389int i40evf_config_rss(struct i40e_vsi *vsi, const u8 *seed,
1390 u8 *lut, u16 lut_size)
1391{
1392 struct i40evf_adapter *adapter = vsi->back;
1393
1394 if (RSS_AQ(adapter))
1395 return i40evf_config_rss_aq(vsi, seed, lut, lut_size);
1396 else
1397 return i40evf_config_rss_reg(vsi, seed, lut, lut_size);
1398}
1399
1400/**
Helin Zhang90b02b42015-10-26 19:44:33 -04001401 * i40evf_get_rss - Get RSS keys and lut
1402 * @vsi: Pointer to vsi structure
1403 * @seed: RSS hash seed
1404 * @lut: Lookup table
1405 * @lut_size: Lookup table size
1406 *
1407 * Returns 0 on success, negative on failure
1408 **/
1409int i40evf_get_rss(struct i40e_vsi *vsi, const u8 *seed, u8 *lut, u16 lut_size)
1410{
1411 struct i40evf_adapter *adapter = vsi->back;
1412
1413 if (RSS_AQ(adapter))
1414 return i40evf_get_rss_aq(vsi, seed, lut, lut_size);
1415 else
1416 return i40evf_get_rss_reg(vsi, seed, lut, lut_size);
1417}
1418
1419/**
Helin Zhang2c86ac32015-10-27 16:15:06 -04001420 * i40evf_fill_rss_lut - Fill the lut with default values
1421 * @lut: Lookup table to be filled with
1422 * @rss_table_size: Lookup table size
1423 * @rss_size: Range of queue number for hashing
1424 **/
1425static void i40evf_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
1426{
1427 u16 i;
1428
1429 for (i = 0; i < rss_table_size; i++)
1430 lut[i] = i % rss_size;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001431}
1432
1433/**
Helin Zhang96a81982015-10-26 19:44:31 -04001434 * i40evf_init_rss - Prepare for RSS
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001435 * @adapter: board private structure
Helin Zhang2c86ac32015-10-27 16:15:06 -04001436 *
1437 * Return 0 on success, negative on failure
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001438 **/
Helin Zhang2c86ac32015-10-27 16:15:06 -04001439static int i40evf_init_rss(struct i40evf_adapter *adapter)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001440{
Helin Zhang2c86ac32015-10-27 16:15:06 -04001441 struct i40e_vsi *vsi = &adapter->vsi;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001442 struct i40e_hw *hw = &adapter->hw;
1443 u8 seed[I40EVF_HKEY_ARRAY_SIZE];
1444 u64 hena;
Helin Zhang2c86ac32015-10-27 16:15:06 -04001445 u8 *lut;
1446 int ret;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001447
1448 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1449 hena = I40E_DEFAULT_RSS_HENA;
1450 wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
1451 wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
1452
Helin Zhang2c86ac32015-10-27 16:15:06 -04001453 lut = kzalloc(I40EVF_HLUT_ARRAY_SIZE, GFP_KERNEL);
1454 if (!lut)
1455 return -ENOMEM;
Helin Zhang66f9af852015-10-26 19:44:34 -04001456
1457 /* Use user configured lut if there is one, otherwise use default */
1458 if (vsi->rss_lut_user)
1459 memcpy(lut, vsi->rss_lut_user, I40EVF_HLUT_ARRAY_SIZE);
1460 else
1461 i40evf_fill_rss_lut(lut, I40EVF_HLUT_ARRAY_SIZE,
1462 adapter->num_active_queues);
1463
1464 /* Use user configured hash key if there is one, otherwise
1465 * user default.
1466 */
1467 if (vsi->rss_hkey_user)
1468 memcpy(seed, vsi->rss_hkey_user, I40EVF_HKEY_ARRAY_SIZE);
1469 else
1470 netdev_rss_key_fill((void *)seed, I40EVF_HKEY_ARRAY_SIZE);
Helin Zhang2c86ac32015-10-27 16:15:06 -04001471 ret = i40evf_config_rss(vsi, seed, lut, I40EVF_HLUT_ARRAY_SIZE);
1472 kfree(lut);
1473
1474 return ret;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001475}
1476
1477/**
Greg Rose5eae00c2013-12-21 06:12:45 +00001478 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1479 * @adapter: board private structure to initialize
1480 *
1481 * We allocate one q_vector per queue interrupt. If allocation fails we
1482 * return -ENOMEM.
1483 **/
1484static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
1485{
Mitch Williams7d96ba12015-10-26 19:44:39 -04001486 int q_idx = 0, num_q_vectors;
Greg Rose5eae00c2013-12-21 06:12:45 +00001487 struct i40e_q_vector *q_vector;
1488
1489 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
Mitch Williams0dd438d2015-10-26 19:44:40 -04001490 adapter->q_vectors = kcalloc(num_q_vectors, sizeof(*q_vector),
Mitch Williams7d96ba12015-10-26 19:44:39 -04001491 GFP_KERNEL);
1492 if (!adapter->q_vectors)
1493 goto err_out;
Greg Rose5eae00c2013-12-21 06:12:45 +00001494
1495 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -04001496 q_vector = &adapter->q_vectors[q_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +00001497 q_vector->adapter = adapter;
1498 q_vector->vsi = &adapter->vsi;
1499 q_vector->v_idx = q_idx;
1500 netif_napi_add(adapter->netdev, &q_vector->napi,
Mitch Williams75a64432014-11-11 20:02:42 +00001501 i40evf_napi_poll, NAPI_POLL_WEIGHT);
Greg Rose5eae00c2013-12-21 06:12:45 +00001502 }
1503
1504 return 0;
1505
1506err_out:
1507 while (q_idx) {
1508 q_idx--;
Mitch Williams7d96ba12015-10-26 19:44:39 -04001509 q_vector = &adapter->q_vectors[q_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +00001510 netif_napi_del(&q_vector->napi);
Greg Rose5eae00c2013-12-21 06:12:45 +00001511 }
Mitch Williams7d96ba12015-10-26 19:44:39 -04001512 kfree(adapter->q_vectors);
Greg Rose5eae00c2013-12-21 06:12:45 +00001513 return -ENOMEM;
1514}
1515
1516/**
1517 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1518 * @adapter: board private structure to initialize
1519 *
1520 * This function frees the memory allocated to the q_vectors. In addition if
1521 * NAPI is enabled it will delete any references to the NAPI struct prior
1522 * to freeing the q_vector.
1523 **/
1524static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
1525{
1526 int q_idx, num_q_vectors;
1527 int napi_vectors;
1528
1529 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
Mitch Williamscc052922014-10-25 03:24:34 +00001530 napi_vectors = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +00001531
1532 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -04001533 struct i40e_q_vector *q_vector = &adapter->q_vectors[q_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +00001534 if (q_idx < napi_vectors)
1535 netif_napi_del(&q_vector->napi);
Greg Rose5eae00c2013-12-21 06:12:45 +00001536 }
Mitch Williams7d96ba12015-10-26 19:44:39 -04001537 kfree(adapter->q_vectors);
Greg Rose5eae00c2013-12-21 06:12:45 +00001538}
1539
1540/**
1541 * i40evf_reset_interrupt_capability - Reset MSIX setup
1542 * @adapter: board private structure
1543 *
1544 **/
1545void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
1546{
1547 pci_disable_msix(adapter->pdev);
1548 kfree(adapter->msix_entries);
1549 adapter->msix_entries = NULL;
Greg Rose5eae00c2013-12-21 06:12:45 +00001550}
1551
1552/**
1553 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1554 * @adapter: board private structure to initialize
1555 *
1556 **/
1557int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
1558{
1559 int err;
1560
1561 err = i40evf_set_interrupt_capability(adapter);
1562 if (err) {
1563 dev_err(&adapter->pdev->dev,
1564 "Unable to setup interrupt capabilities\n");
1565 goto err_set_interrupt;
1566 }
1567
1568 err = i40evf_alloc_q_vectors(adapter);
1569 if (err) {
1570 dev_err(&adapter->pdev->dev,
1571 "Unable to allocate memory for queue vectors\n");
1572 goto err_alloc_q_vectors;
1573 }
1574
1575 err = i40evf_alloc_queues(adapter);
1576 if (err) {
1577 dev_err(&adapter->pdev->dev,
1578 "Unable to allocate memory for queues\n");
1579 goto err_alloc_queues;
1580 }
1581
1582 dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
Mitch Williams75a64432014-11-11 20:02:42 +00001583 (adapter->num_active_queues > 1) ? "Enabled" : "Disabled",
1584 adapter->num_active_queues);
Greg Rose5eae00c2013-12-21 06:12:45 +00001585
1586 return 0;
1587err_alloc_queues:
1588 i40evf_free_q_vectors(adapter);
1589err_alloc_q_vectors:
1590 i40evf_reset_interrupt_capability(adapter);
1591err_set_interrupt:
1592 return err;
1593}
1594
1595/**
Helin Zhang66f9af852015-10-26 19:44:34 -04001596 * i40evf_clear_rss_config_user - Clear user configurations of RSS
1597 * @vsi: Pointer to VSI structure
1598 **/
1599static void i40evf_clear_rss_config_user(struct i40e_vsi *vsi)
1600{
1601 if (!vsi)
1602 return;
1603
1604 kfree(vsi->rss_hkey_user);
1605 vsi->rss_hkey_user = NULL;
1606
1607 kfree(vsi->rss_lut_user);
1608 vsi->rss_lut_user = NULL;
1609}
1610
1611/**
Greg Rose5eae00c2013-12-21 06:12:45 +00001612 * i40evf_watchdog_timer - Periodic call-back timer
1613 * @data: pointer to adapter disguised as unsigned long
1614 **/
1615static void i40evf_watchdog_timer(unsigned long data)
1616{
1617 struct i40evf_adapter *adapter = (struct i40evf_adapter *)data;
Mitch Williams75a64432014-11-11 20:02:42 +00001618
Greg Rose5eae00c2013-12-21 06:12:45 +00001619 schedule_work(&adapter->watchdog_task);
1620 /* timer will be rescheduled in watchdog task */
1621}
1622
1623/**
1624 * i40evf_watchdog_task - Periodic call-back task
1625 * @work: pointer to work_struct
1626 **/
1627static void i40evf_watchdog_task(struct work_struct *work)
1628{
1629 struct i40evf_adapter *adapter = container_of(work,
Mitch Williams75a64432014-11-11 20:02:42 +00001630 struct i40evf_adapter,
1631 watchdog_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00001632 struct i40e_hw *hw = &adapter->hw;
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001633 u32 reg_val;
Greg Rose5eae00c2013-12-21 06:12:45 +00001634
Greg Rose5eae00c2013-12-21 06:12:45 +00001635 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section))
Mitch Williamsef8693e2014-02-13 03:48:53 -08001636 goto restart_watchdog;
1637
1638 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001639 reg_val = rd32(hw, I40E_VFGEN_RSTAT) &
1640 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1641 if ((reg_val == I40E_VFR_VFACTIVE) ||
1642 (reg_val == I40E_VFR_COMPLETED)) {
Mitch Williamsef8693e2014-02-13 03:48:53 -08001643 /* A chance for redemption! */
1644 dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
1645 adapter->state = __I40EVF_STARTUP;
1646 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1647 schedule_delayed_work(&adapter->init_task, 10);
1648 clear_bit(__I40EVF_IN_CRITICAL_TASK,
1649 &adapter->crit_section);
1650 /* Don't reschedule the watchdog, since we've restarted
1651 * the init task. When init_task contacts the PF and
1652 * gets everything set up again, it'll restart the
1653 * watchdog for us. Down, boy. Sit. Stay. Woof.
1654 */
1655 return;
1656 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001657 adapter->aq_required = 0;
1658 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1659 goto watchdog_done;
1660 }
1661
1662 if ((adapter->state < __I40EVF_DOWN) ||
1663 (adapter->flags & I40EVF_FLAG_RESET_PENDING))
Greg Rose5eae00c2013-12-21 06:12:45 +00001664 goto watchdog_done;
1665
Mitch Williamsef8693e2014-02-13 03:48:53 -08001666 /* check for reset */
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001667 reg_val = rd32(hw, I40E_VF_ARQLEN1) & I40E_VF_ARQLEN1_ARQENABLE_MASK;
1668 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) && !reg_val) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001669 adapter->state = __I40EVF_RESETTING;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001670 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
Mitch Williams249c8b82014-05-10 04:49:04 +00001671 dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001672 schedule_work(&adapter->reset_task);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001673 adapter->aq_required = 0;
1674 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001675 goto watchdog_done;
1676 }
1677
1678 /* Process admin queue tasks. After init, everything gets done
1679 * here so we don't race on the admin queue.
1680 */
Mitch Williamsed636962015-04-07 19:45:32 -04001681 if (adapter->current_op) {
Mitch A Williams0758e7cb2014-12-09 08:53:08 +00001682 if (!i40evf_asq_done(hw)) {
1683 dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n");
1684 i40evf_send_api_ver(adapter);
1685 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001686 goto watchdog_done;
Mitch A Williams0758e7cb2014-12-09 08:53:08 +00001687 }
Mitch Williamse6d038d2015-06-04 16:23:58 -04001688 if (adapter->aq_required & I40EVF_FLAG_AQ_GET_CONFIG) {
1689 i40evf_send_vf_config_msg(adapter);
1690 goto watchdog_done;
1691 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001692
Mitch Williamse284fc82015-03-27 00:12:09 -07001693 if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) {
1694 i40evf_disable_queues(adapter);
1695 goto watchdog_done;
1696 }
1697
Greg Rose5eae00c2013-12-21 06:12:45 +00001698 if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) {
1699 i40evf_map_queues(adapter);
1700 goto watchdog_done;
1701 }
1702
1703 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) {
1704 i40evf_add_ether_addrs(adapter);
1705 goto watchdog_done;
1706 }
1707
1708 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) {
1709 i40evf_add_vlans(adapter);
1710 goto watchdog_done;
1711 }
1712
1713 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) {
1714 i40evf_del_ether_addrs(adapter);
1715 goto watchdog_done;
1716 }
1717
1718 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) {
1719 i40evf_del_vlans(adapter);
1720 goto watchdog_done;
1721 }
1722
Greg Rose5eae00c2013-12-21 06:12:45 +00001723 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) {
1724 i40evf_configure_queues(adapter);
1725 goto watchdog_done;
1726 }
1727
1728 if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) {
1729 i40evf_enable_queues(adapter);
1730 goto watchdog_done;
1731 }
1732
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001733 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_RSS) {
1734 /* This message goes straight to the firmware, not the
1735 * PF, so we don't have to set current_op as we will
1736 * not get a response through the ARQ.
1737 */
Helin Zhang96a81982015-10-26 19:44:31 -04001738 i40evf_init_rss(adapter);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001739 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_RSS;
1740 goto watchdog_done;
1741 }
1742
Greg Rose5eae00c2013-12-21 06:12:45 +00001743 if (adapter->state == __I40EVF_RUNNING)
1744 i40evf_request_stats(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001745watchdog_done:
Mitch A Williams4870e172014-12-09 08:53:06 +00001746 if (adapter->state == __I40EVF_RUNNING) {
1747 i40evf_irq_enable_queues(adapter, ~0);
1748 i40evf_fire_sw_int(adapter, 0xFF);
1749 } else {
1750 i40evf_fire_sw_int(adapter, 0x1);
1751 }
1752
Mitch Williamsef8693e2014-02-13 03:48:53 -08001753 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1754restart_watchdog:
Ashish Shahd3e2edb2014-08-01 13:27:12 -07001755 if (adapter->state == __I40EVF_REMOVE)
1756 return;
Greg Rose5eae00c2013-12-21 06:12:45 +00001757 if (adapter->aq_required)
1758 mod_timer(&adapter->watchdog_timer,
1759 jiffies + msecs_to_jiffies(20));
1760 else
1761 mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2));
Greg Rose5eae00c2013-12-21 06:12:45 +00001762 schedule_work(&adapter->adminq_task);
1763}
1764
Mitch Williams67c818a2015-06-19 08:56:30 -07001765#define I40EVF_RESET_WAIT_MS 10
1766#define I40EVF_RESET_WAIT_COUNT 500
Greg Rose5eae00c2013-12-21 06:12:45 +00001767/**
1768 * i40evf_reset_task - Call-back task to handle hardware reset
1769 * @work: pointer to work_struct
1770 *
1771 * During reset we need to shut down and reinitialize the admin queue
1772 * before we can use it to communicate with the PF again. We also clear
1773 * and reinit the rings because that context is lost as well.
1774 **/
1775static void i40evf_reset_task(struct work_struct *work)
1776{
Mitch Williamsef8693e2014-02-13 03:48:53 -08001777 struct i40evf_adapter *adapter = container_of(work,
1778 struct i40evf_adapter,
1779 reset_task);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001780 struct net_device *netdev = adapter->netdev;
Greg Rose5eae00c2013-12-21 06:12:45 +00001781 struct i40e_hw *hw = &adapter->hw;
Mitch Williams40d01362015-10-01 14:37:37 -04001782 struct i40evf_vlan_filter *vlf;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001783 struct i40evf_mac_filter *f;
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001784 u32 reg_val;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001785 int i = 0, err;
Greg Rose5eae00c2013-12-21 06:12:45 +00001786
1787 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1788 &adapter->crit_section))
Neerav Parikhf98a2002014-09-13 07:40:44 +00001789 usleep_range(500, 1000);
Mitch Williams3526d802014-03-06 08:59:56 +00001790
Mitch Williams67c818a2015-06-19 08:56:30 -07001791 i40evf_misc_irq_disable(adapter);
Mitch Williams3526d802014-03-06 08:59:56 +00001792 if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) {
Mitch Williams67c818a2015-06-19 08:56:30 -07001793 adapter->flags &= ~I40EVF_FLAG_RESET_NEEDED;
1794 /* Restart the AQ here. If we have been reset but didn't
1795 * detect it, or if the PF had to reinit, our AQ will be hosed.
1796 */
1797 i40evf_shutdown_adminq(hw);
1798 i40evf_init_adminq(hw);
Mitch Williams3526d802014-03-06 08:59:56 +00001799 i40evf_request_reset(adapter);
1800 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001801 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
Mitch Williams3526d802014-03-06 08:59:56 +00001802
Mitch Williamsef8693e2014-02-13 03:48:53 -08001803 /* poll until we see the reset actually happen */
1804 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001805 reg_val = rd32(hw, I40E_VF_ARQLEN1) &
1806 I40E_VF_ARQLEN1_ARQENABLE_MASK;
1807 if (!reg_val)
Greg Rose5eae00c2013-12-21 06:12:45 +00001808 break;
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001809 usleep_range(5000, 10000);
Greg Rose5eae00c2013-12-21 06:12:45 +00001810 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001811 if (i == I40EVF_RESET_WAIT_COUNT) {
Mitch Williams67c818a2015-06-19 08:56:30 -07001812 dev_info(&adapter->pdev->dev, "Never saw reset\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08001813 goto continue_reset; /* act like the reset happened */
1814 }
1815
1816 /* wait until the reset is complete and the PF is responding to us */
1817 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001818 reg_val = rd32(hw, I40E_VFGEN_RSTAT) &
1819 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1820 if (reg_val == I40E_VFR_VFACTIVE)
Mitch Williamsef8693e2014-02-13 03:48:53 -08001821 break;
Mitch Williamsc88e38c2014-11-11 20:03:13 +00001822 msleep(I40EVF_RESET_WAIT_MS);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001823 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001824 /* extra wait to make sure minimum wait is met */
1825 msleep(I40EVF_RESET_WAIT_MS);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001826 if (i == I40EVF_RESET_WAIT_COUNT) {
Shannon Nelson874d1a12015-09-03 17:18:57 -04001827 struct i40evf_mac_filter *ftmp;
Mitch Williams6ba36a22014-08-01 13:27:14 -07001828 struct i40evf_vlan_filter *fv, *fvtmp;
1829
Greg Rose5eae00c2013-12-21 06:12:45 +00001830 /* reset never finished */
Mitch Williams80e72892014-05-10 04:49:06 +00001831 dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n",
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001832 reg_val);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001833 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
1834
Mitch Williams169f4072014-04-01 07:11:50 +00001835 if (netif_running(adapter->netdev)) {
1836 set_bit(__I40E_DOWN, &adapter->vsi.state);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001837 netif_carrier_off(netdev);
Mitch Williams67c818a2015-06-19 08:56:30 -07001838 netif_tx_disable(netdev);
1839 i40evf_napi_disable_all(adapter);
1840 i40evf_irq_disable(adapter);
Mitch Williams169f4072014-04-01 07:11:50 +00001841 i40evf_free_traffic_irqs(adapter);
1842 i40evf_free_all_tx_resources(adapter);
1843 i40evf_free_all_rx_resources(adapter);
1844 }
Mitch Williams6ba36a22014-08-01 13:27:14 -07001845
1846 /* Delete all of the filters, both MAC and VLAN. */
1847 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list,
1848 list) {
1849 list_del(&f->list);
1850 kfree(f);
1851 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001852
Mitch Williams6ba36a22014-08-01 13:27:14 -07001853 list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list,
1854 list) {
1855 list_del(&fv->list);
1856 kfree(fv);
1857 }
1858
Mitch Williamsef8693e2014-02-13 03:48:53 -08001859 i40evf_free_misc_irq(adapter);
1860 i40evf_reset_interrupt_capability(adapter);
1861 i40evf_free_queues(adapter);
Mitch Williamsd31944d2014-08-01 13:27:13 -07001862 i40evf_free_q_vectors(adapter);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001863 kfree(adapter->vf_res);
1864 i40evf_shutdown_adminq(hw);
1865 adapter->netdev->flags &= ~IFF_UP;
1866 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Mitch Williams67c818a2015-06-19 08:56:30 -07001867 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1868 dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08001869 return; /* Do not attempt to reinit. It's dead, Jim. */
Greg Rose5eae00c2013-12-21 06:12:45 +00001870 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001871
1872continue_reset:
Mitch Williams67c818a2015-06-19 08:56:30 -07001873 if (netif_running(adapter->netdev)) {
1874 netif_carrier_off(netdev);
1875 netif_tx_stop_all_queues(netdev);
1876 i40evf_napi_disable_all(adapter);
1877 }
Mitch Williamsac833bb2015-01-29 07:17:19 +00001878 i40evf_irq_disable(adapter);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001879
Greg Rose5eae00c2013-12-21 06:12:45 +00001880 adapter->state = __I40EVF_RESETTING;
Mitch Williams67c818a2015-06-19 08:56:30 -07001881 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1882
1883 /* free the Tx/Rx rings and descriptors, might be better to just
1884 * re-use them sometime in the future
1885 */
1886 i40evf_free_all_rx_resources(adapter);
1887 i40evf_free_all_tx_resources(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001888
1889 /* kill and reinit the admin queue */
1890 if (i40evf_shutdown_adminq(hw))
Mitch Williamsac833bb2015-01-29 07:17:19 +00001891 dev_warn(&adapter->pdev->dev, "Failed to shut down adminq\n");
1892 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001893 err = i40evf_init_adminq(hw);
1894 if (err)
Mitch Williamsac833bb2015-01-29 07:17:19 +00001895 dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n",
1896 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00001897
Mitch Williamse6d038d2015-06-04 16:23:58 -04001898 adapter->aq_required = I40EVF_FLAG_AQ_GET_CONFIG;
1899 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001900
1901 /* re-add all MAC filters */
1902 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1903 f->add = true;
1904 }
1905 /* re-add all VLAN filters */
Mitch Williams40d01362015-10-01 14:37:37 -04001906 list_for_each_entry(vlf, &adapter->vlan_filter_list, list) {
1907 vlf->add = true;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001908 }
Mitch Williamse6d038d2015-06-04 16:23:58 -04001909 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001910 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
Greg Rose5eae00c2013-12-21 06:12:45 +00001911 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Mitch Williams67c818a2015-06-19 08:56:30 -07001912 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001913
1914 mod_timer(&adapter->watchdog_timer, jiffies + 2);
1915
1916 if (netif_running(adapter->netdev)) {
1917 /* allocate transmit descriptors */
1918 err = i40evf_setup_all_tx_resources(adapter);
1919 if (err)
1920 goto reset_err;
1921
1922 /* allocate receive descriptors */
1923 err = i40evf_setup_all_rx_resources(adapter);
1924 if (err)
1925 goto reset_err;
1926
1927 i40evf_configure(adapter);
1928
1929 err = i40evf_up_complete(adapter);
1930 if (err)
1931 goto reset_err;
1932
1933 i40evf_irq_enable(adapter, true);
Mitch Williams67c818a2015-06-19 08:56:30 -07001934 } else {
1935 adapter->state = __I40EVF_DOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001936 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001937
Greg Rose5eae00c2013-12-21 06:12:45 +00001938 return;
1939reset_err:
Mitch Williams80e72892014-05-10 04:49:06 +00001940 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001941 i40evf_close(adapter->netdev);
1942}
1943
1944/**
1945 * i40evf_adminq_task - worker thread to clean the admin queue
1946 * @work: pointer to work_struct containing our data
1947 **/
1948static void i40evf_adminq_task(struct work_struct *work)
1949{
1950 struct i40evf_adapter *adapter =
1951 container_of(work, struct i40evf_adapter, adminq_task);
1952 struct i40e_hw *hw = &adapter->hw;
1953 struct i40e_arq_event_info event;
1954 struct i40e_virtchnl_msg *v_msg;
1955 i40e_status ret;
Mitch Williams912257e2014-05-22 06:32:07 +00001956 u32 val, oldval;
Greg Rose5eae00c2013-12-21 06:12:45 +00001957 u16 pending;
1958
Mitch Williamsef8693e2014-02-13 03:48:53 -08001959 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
Mitch A Williams72354482014-12-09 08:53:07 +00001960 goto out;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001961
Mitch Williams1001dc32014-11-11 20:02:19 +00001962 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
1963 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +00001964 if (!event.msg_buf)
Mitch A Williams72354482014-12-09 08:53:07 +00001965 goto out;
Mitch Williams249c8b82014-05-10 04:49:04 +00001966
Greg Rose5eae00c2013-12-21 06:12:45 +00001967 v_msg = (struct i40e_virtchnl_msg *)&event.desc;
1968 do {
1969 ret = i40evf_clean_arq_element(hw, &event, &pending);
Mitch Williams8b011eb2015-01-09 11:18:17 +00001970 if (ret || !v_msg->v_opcode)
Greg Rose5eae00c2013-12-21 06:12:45 +00001971 break; /* No event to process or error cleaning ARQ */
1972
1973 i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
1974 v_msg->v_retval, event.msg_buf,
Mitch Williams1001dc32014-11-11 20:02:19 +00001975 event.msg_len);
Mitch Williams75a64432014-11-11 20:02:42 +00001976 if (pending != 0)
Greg Rose5eae00c2013-12-21 06:12:45 +00001977 memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
Greg Rose5eae00c2013-12-21 06:12:45 +00001978 } while (pending);
1979
Mitch Williams67c818a2015-06-19 08:56:30 -07001980 if ((adapter->flags &
1981 (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) ||
1982 adapter->state == __I40EVF_RESETTING)
1983 goto freedom;
1984
Mitch Williams912257e2014-05-22 06:32:07 +00001985 /* check for error indications */
1986 val = rd32(hw, hw->aq.arq.len);
1987 oldval = val;
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04001988 if (val & I40E_VF_ARQLEN1_ARQVFE_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00001989 dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04001990 val &= ~I40E_VF_ARQLEN1_ARQVFE_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00001991 }
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04001992 if (val & I40E_VF_ARQLEN1_ARQOVFL_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00001993 dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04001994 val &= ~I40E_VF_ARQLEN1_ARQOVFL_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00001995 }
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04001996 if (val & I40E_VF_ARQLEN1_ARQCRIT_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00001997 dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04001998 val &= ~I40E_VF_ARQLEN1_ARQCRIT_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00001999 }
2000 if (oldval != val)
2001 wr32(hw, hw->aq.arq.len, val);
2002
2003 val = rd32(hw, hw->aq.asq.len);
2004 oldval = val;
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002005 if (val & I40E_VF_ATQLEN1_ATQVFE_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00002006 dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002007 val &= ~I40E_VF_ATQLEN1_ATQVFE_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00002008 }
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002009 if (val & I40E_VF_ATQLEN1_ATQOVFL_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00002010 dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002011 val &= ~I40E_VF_ATQLEN1_ATQOVFL_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00002012 }
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002013 if (val & I40E_VF_ATQLEN1_ATQCRIT_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00002014 dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002015 val &= ~I40E_VF_ATQLEN1_ATQCRIT_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00002016 }
2017 if (oldval != val)
2018 wr32(hw, hw->aq.asq.len, val);
2019
Mitch Williams67c818a2015-06-19 08:56:30 -07002020freedom:
Mitch A Williams72354482014-12-09 08:53:07 +00002021 kfree(event.msg_buf);
2022out:
Greg Rose5eae00c2013-12-21 06:12:45 +00002023 /* re-enable Admin queue interrupt cause */
2024 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002025}
2026
2027/**
2028 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
2029 * @adapter: board private structure
2030 *
2031 * Free all transmit software resources
2032 **/
Mitch Williamse284fc82015-03-27 00:12:09 -07002033void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
Greg Rose5eae00c2013-12-21 06:12:45 +00002034{
2035 int i;
2036
Mitch Williamsfdb47ae2015-11-19 11:34:18 -08002037 if (!adapter->tx_rings)
2038 return;
2039
Mitch Williamscc052922014-10-25 03:24:34 +00002040 for (i = 0; i < adapter->num_active_queues; i++)
Mitch Williams0dd438d2015-10-26 19:44:40 -04002041 if (adapter->tx_rings[i].desc)
2042 i40evf_free_tx_resources(&adapter->tx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00002043}
2044
2045/**
2046 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
2047 * @adapter: board private structure
2048 *
2049 * If this function returns with an error, then it's possible one or
2050 * more of the rings is populated (while the rest are not). It is the
2051 * callers duty to clean those orphaned rings.
2052 *
2053 * Return 0 on success, negative on failure
2054 **/
2055static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
2056{
2057 int i, err = 0;
2058
Mitch Williamscc052922014-10-25 03:24:34 +00002059 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williams0dd438d2015-10-26 19:44:40 -04002060 adapter->tx_rings[i].count = adapter->tx_desc_count;
2061 err = i40evf_setup_tx_descriptors(&adapter->tx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00002062 if (!err)
2063 continue;
2064 dev_err(&adapter->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04002065 "Allocation for Tx Queue %u failed\n", i);
Greg Rose5eae00c2013-12-21 06:12:45 +00002066 break;
2067 }
2068
2069 return err;
2070}
2071
2072/**
2073 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
2074 * @adapter: board private structure
2075 *
2076 * If this function returns with an error, then it's possible one or
2077 * more of the rings is populated (while the rest are not). It is the
2078 * callers duty to clean those orphaned rings.
2079 *
2080 * Return 0 on success, negative on failure
2081 **/
2082static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
2083{
2084 int i, err = 0;
2085
Mitch Williamscc052922014-10-25 03:24:34 +00002086 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williams0dd438d2015-10-26 19:44:40 -04002087 adapter->rx_rings[i].count = adapter->rx_desc_count;
2088 err = i40evf_setup_rx_descriptors(&adapter->rx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00002089 if (!err)
2090 continue;
2091 dev_err(&adapter->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04002092 "Allocation for Rx Queue %u failed\n", i);
Greg Rose5eae00c2013-12-21 06:12:45 +00002093 break;
2094 }
2095 return err;
2096}
2097
2098/**
2099 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
2100 * @adapter: board private structure
2101 *
2102 * Free all receive software resources
2103 **/
Mitch Williamse284fc82015-03-27 00:12:09 -07002104void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
Greg Rose5eae00c2013-12-21 06:12:45 +00002105{
2106 int i;
2107
Mitch Williamsfdb47ae2015-11-19 11:34:18 -08002108 if (!adapter->rx_rings)
2109 return;
2110
Mitch Williamscc052922014-10-25 03:24:34 +00002111 for (i = 0; i < adapter->num_active_queues; i++)
Mitch Williams0dd438d2015-10-26 19:44:40 -04002112 if (adapter->rx_rings[i].desc)
2113 i40evf_free_rx_resources(&adapter->rx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00002114}
2115
2116/**
2117 * i40evf_open - Called when a network interface is made active
2118 * @netdev: network interface device structure
2119 *
2120 * Returns 0 on success, negative value on failure
2121 *
2122 * The open entry point is called when a network interface is made
2123 * active by the system (IFF_UP). At this point all resources needed
2124 * for transmit and receive operations are allocated, the interrupt
2125 * handler is registered with the OS, the watchdog timer is started,
2126 * and the stack is notified that the interface is ready.
2127 **/
2128static int i40evf_open(struct net_device *netdev)
2129{
2130 struct i40evf_adapter *adapter = netdev_priv(netdev);
2131 int err;
2132
Mitch Williamsef8693e2014-02-13 03:48:53 -08002133 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
2134 dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
2135 return -EIO;
2136 }
Mitch Williamse284fc82015-03-27 00:12:09 -07002137 if (adapter->state != __I40EVF_DOWN || adapter->aq_required)
Greg Rose5eae00c2013-12-21 06:12:45 +00002138 return -EBUSY;
2139
2140 /* allocate transmit descriptors */
2141 err = i40evf_setup_all_tx_resources(adapter);
2142 if (err)
2143 goto err_setup_tx;
2144
2145 /* allocate receive descriptors */
2146 err = i40evf_setup_all_rx_resources(adapter);
2147 if (err)
2148 goto err_setup_rx;
2149
2150 /* clear any pending interrupts, may auto mask */
2151 err = i40evf_request_traffic_irqs(adapter, netdev->name);
2152 if (err)
2153 goto err_req_irq;
2154
Mitch Williams44151cd2015-04-27 14:57:17 -04002155 i40evf_add_filter(adapter, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002156 i40evf_configure(adapter);
2157
2158 err = i40evf_up_complete(adapter);
2159 if (err)
2160 goto err_req_irq;
2161
2162 i40evf_irq_enable(adapter, true);
2163
2164 return 0;
2165
2166err_req_irq:
2167 i40evf_down(adapter);
2168 i40evf_free_traffic_irqs(adapter);
2169err_setup_rx:
2170 i40evf_free_all_rx_resources(adapter);
2171err_setup_tx:
2172 i40evf_free_all_tx_resources(adapter);
2173
2174 return err;
2175}
2176
2177/**
2178 * i40evf_close - Disables a network interface
2179 * @netdev: network interface device structure
2180 *
2181 * Returns 0, this is not allowed to fail
2182 *
2183 * The close entry point is called when an interface is de-activated
2184 * by the OS. The hardware is still under the drivers control, but
2185 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
2186 * are freed, along with all transmit and receive resources.
2187 **/
2188static int i40evf_close(struct net_device *netdev)
2189{
2190 struct i40evf_adapter *adapter = netdev_priv(netdev);
2191
Mitch Williamsef8693e2014-02-13 03:48:53 -08002192 if (adapter->state <= __I40EVF_DOWN)
2193 return 0;
2194
Mitch Williamsef8693e2014-02-13 03:48:53 -08002195
Greg Rose5eae00c2013-12-21 06:12:45 +00002196 set_bit(__I40E_DOWN, &adapter->vsi.state);
2197
2198 i40evf_down(adapter);
Mitch Williamsddf0b3a2014-05-22 06:31:46 +00002199 adapter->state = __I40EVF_DOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00002200 i40evf_free_traffic_irqs(adapter);
2201
Greg Rose5eae00c2013-12-21 06:12:45 +00002202 return 0;
2203}
2204
2205/**
2206 * i40evf_get_stats - Get System Network Statistics
2207 * @netdev: network interface device structure
2208 *
2209 * Returns the address of the device statistics structure.
2210 * The statistics are actually updated from the timer callback.
2211 **/
2212static struct net_device_stats *i40evf_get_stats(struct net_device *netdev)
2213{
2214 struct i40evf_adapter *adapter = netdev_priv(netdev);
2215
2216 /* only return the current stats */
2217 return &adapter->net_stats;
2218}
2219
2220/**
Greg Rose5eae00c2013-12-21 06:12:45 +00002221 * i40evf_change_mtu - Change the Maximum Transfer Unit
2222 * @netdev: network interface device structure
2223 * @new_mtu: new value for maximum frame size
2224 *
2225 * Returns 0 on success, negative on failure
2226 **/
2227static int i40evf_change_mtu(struct net_device *netdev, int new_mtu)
2228{
2229 struct i40evf_adapter *adapter = netdev_priv(netdev);
2230 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
2231
2232 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
2233 return -EINVAL;
2234
Greg Rose5eae00c2013-12-21 06:12:45 +00002235 netdev->mtu = new_mtu;
Mitch Williams67c818a2015-06-19 08:56:30 -07002236 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
2237 schedule_work(&adapter->reset_task);
2238
Greg Rose5eae00c2013-12-21 06:12:45 +00002239 return 0;
2240}
2241
2242static const struct net_device_ops i40evf_netdev_ops = {
2243 .ndo_open = i40evf_open,
2244 .ndo_stop = i40evf_close,
2245 .ndo_start_xmit = i40evf_xmit_frame,
2246 .ndo_get_stats = i40evf_get_stats,
2247 .ndo_set_rx_mode = i40evf_set_rx_mode,
2248 .ndo_validate_addr = eth_validate_addr,
2249 .ndo_set_mac_address = i40evf_set_mac,
2250 .ndo_change_mtu = i40evf_change_mtu,
2251 .ndo_tx_timeout = i40evf_tx_timeout,
2252 .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid,
2253 .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid,
Alexander Duyck7709b4c2015-09-24 09:04:38 -07002254#ifdef CONFIG_NET_POLL_CONTROLLER
2255 .ndo_poll_controller = i40evf_netpoll,
2256#endif
Greg Rose5eae00c2013-12-21 06:12:45 +00002257};
2258
2259/**
2260 * i40evf_check_reset_complete - check that VF reset is complete
2261 * @hw: pointer to hw struct
2262 *
2263 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
2264 **/
2265static int i40evf_check_reset_complete(struct i40e_hw *hw)
2266{
2267 u32 rstat;
2268 int i;
2269
2270 for (i = 0; i < 100; i++) {
Ashish Shahfd358862014-08-01 13:27:11 -07002271 rstat = rd32(hw, I40E_VFGEN_RSTAT) &
2272 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
2273 if ((rstat == I40E_VFR_VFACTIVE) ||
2274 (rstat == I40E_VFR_COMPLETED))
Greg Rose5eae00c2013-12-21 06:12:45 +00002275 return 0;
Neerav Parikhf98a2002014-09-13 07:40:44 +00002276 usleep_range(10, 20);
Greg Rose5eae00c2013-12-21 06:12:45 +00002277 }
2278 return -EBUSY;
2279}
2280
2281/**
Mitch Williamse6d038d2015-06-04 16:23:58 -04002282 * i40evf_process_config - Process the config information we got from the PF
2283 * @adapter: board private structure
2284 *
2285 * Verify that we have a valid config struct, and set up our netdev features
2286 * and our VSI struct.
2287 **/
2288int i40evf_process_config(struct i40evf_adapter *adapter)
2289{
2290 struct net_device *netdev = adapter->netdev;
2291 int i;
2292
2293 /* got VF config message back from PF, now we can parse it */
2294 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
2295 if (adapter->vf_res->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
2296 adapter->vsi_res = &adapter->vf_res->vsi_res[i];
2297 }
2298 if (!adapter->vsi_res) {
2299 dev_err(&adapter->pdev->dev, "No LAN VSI found\n");
2300 return -ENODEV;
2301 }
2302
2303 if (adapter->vf_res->vf_offload_flags
2304 & I40E_VIRTCHNL_VF_OFFLOAD_VLAN) {
Mitch Williamscc7e4062015-09-28 14:12:40 -04002305 netdev->vlan_features = netdev->features &
2306 ~(NETIF_F_HW_VLAN_CTAG_TX |
2307 NETIF_F_HW_VLAN_CTAG_RX |
2308 NETIF_F_HW_VLAN_CTAG_FILTER);
Mitch Williamse6d038d2015-06-04 16:23:58 -04002309 netdev->features |= NETIF_F_HW_VLAN_CTAG_TX |
2310 NETIF_F_HW_VLAN_CTAG_RX |
2311 NETIF_F_HW_VLAN_CTAG_FILTER;
2312 }
2313 netdev->features |= NETIF_F_HIGHDMA |
2314 NETIF_F_SG |
2315 NETIF_F_IP_CSUM |
2316 NETIF_F_SCTP_CSUM |
2317 NETIF_F_IPV6_CSUM |
2318 NETIF_F_TSO |
2319 NETIF_F_TSO6 |
2320 NETIF_F_RXCSUM |
2321 NETIF_F_GRO;
2322
2323 /* copy netdev features into list of user selectable features */
2324 netdev->hw_features |= netdev->features;
2325 netdev->hw_features &= ~NETIF_F_RXCSUM;
2326
2327 adapter->vsi.id = adapter->vsi_res->vsi_id;
2328
2329 adapter->vsi.back = adapter;
2330 adapter->vsi.base_vector = 1;
2331 adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK;
2332 adapter->vsi.rx_itr_setting = (I40E_ITR_DYNAMIC |
2333 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
2334 adapter->vsi.tx_itr_setting = (I40E_ITR_DYNAMIC |
2335 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
2336 adapter->vsi.netdev = adapter->netdev;
Mitch Williamsf578f5f2015-08-28 17:55:58 -04002337 adapter->vsi.qs_handle = adapter->vsi_res->qset_handle;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002338 return 0;
2339}
2340
2341/**
Greg Rose5eae00c2013-12-21 06:12:45 +00002342 * i40evf_init_task - worker thread to perform delayed initialization
2343 * @work: pointer to work_struct containing our data
2344 *
2345 * This task completes the work that was begun in probe. Due to the nature
2346 * of VF-PF communications, we may need to wait tens of milliseconds to get
Joe Perchesdbedd442015-03-06 20:49:12 -08002347 * responses back from the PF. Rather than busy-wait in probe and bog down the
Greg Rose5eae00c2013-12-21 06:12:45 +00002348 * whole system, we'll do it in a task so we can sleep.
2349 * This task only runs during driver init. Once we've established
2350 * communications with the PF driver and set up our netdev, the watchdog
2351 * takes over.
2352 **/
2353static void i40evf_init_task(struct work_struct *work)
2354{
2355 struct i40evf_adapter *adapter = container_of(work,
2356 struct i40evf_adapter,
2357 init_task.work);
2358 struct net_device *netdev = adapter->netdev;
Greg Rose5eae00c2013-12-21 06:12:45 +00002359 struct i40e_hw *hw = &adapter->hw;
2360 struct pci_dev *pdev = adapter->pdev;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002361 int err, bufsz;
Greg Rose5eae00c2013-12-21 06:12:45 +00002362
2363 switch (adapter->state) {
2364 case __I40EVF_STARTUP:
2365 /* driver loaded, probe complete */
Mitch Williamsef8693e2014-02-13 03:48:53 -08002366 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
2367 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
Greg Rose5eae00c2013-12-21 06:12:45 +00002368 err = i40e_set_mac_type(hw);
2369 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002370 dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
2371 err);
Mitch Williams2619ef42015-04-07 19:45:30 -04002372 goto err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002373 }
2374 err = i40evf_check_reset_complete(hw);
2375 if (err) {
Mitch Williams0d9c7ea2014-04-23 04:50:00 +00002376 dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n",
Mitch Williams75a64432014-11-11 20:02:42 +00002377 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002378 goto err;
2379 }
2380 hw->aq.num_arq_entries = I40EVF_AQ_LEN;
2381 hw->aq.num_asq_entries = I40EVF_AQ_LEN;
2382 hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2383 hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2384
2385 err = i40evf_init_adminq(hw);
2386 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002387 dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
2388 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002389 goto err;
2390 }
2391 err = i40evf_send_api_ver(adapter);
2392 if (err) {
Mitch Williams10bdd672014-03-06 08:59:53 +00002393 dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002394 i40evf_shutdown_adminq(hw);
2395 goto err;
2396 }
2397 adapter->state = __I40EVF_INIT_VERSION_CHECK;
2398 goto restart;
Greg Rose5eae00c2013-12-21 06:12:45 +00002399 case __I40EVF_INIT_VERSION_CHECK:
Mitch Williams10bdd672014-03-06 08:59:53 +00002400 if (!i40evf_asq_done(hw)) {
Mitch Williams80e72892014-05-10 04:49:06 +00002401 dev_err(&pdev->dev, "Admin queue command never completed\n");
Mitch Williams906a6932014-11-13 03:06:12 +00002402 i40evf_shutdown_adminq(hw);
2403 adapter->state = __I40EVF_STARTUP;
Greg Rose5eae00c2013-12-21 06:12:45 +00002404 goto err;
Mitch Williams10bdd672014-03-06 08:59:53 +00002405 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002406
2407 /* aq msg sent, awaiting reply */
2408 err = i40evf_verify_api_ver(adapter);
2409 if (err) {
Mitch A Williamsd4f82fd2014-12-09 08:53:03 +00002410 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
Mitch Williams56f99202014-06-04 04:22:41 +00002411 err = i40evf_send_api_ver(adapter);
Mitch Williamsee1693e2015-06-04 16:23:59 -04002412 else
2413 dev_err(&pdev->dev, "Unsupported PF API version %d.%d, expected %d.%d\n",
2414 adapter->pf_version.major,
2415 adapter->pf_version.minor,
2416 I40E_VIRTCHNL_VERSION_MAJOR,
2417 I40E_VIRTCHNL_VERSION_MINOR);
Greg Rose5eae00c2013-12-21 06:12:45 +00002418 goto err;
2419 }
2420 err = i40evf_send_vf_config_msg(adapter);
2421 if (err) {
Mitch Williams3f2ab172014-06-04 04:22:40 +00002422 dev_err(&pdev->dev, "Unable to send config request (%d)\n",
Greg Rose5eae00c2013-12-21 06:12:45 +00002423 err);
2424 goto err;
2425 }
2426 adapter->state = __I40EVF_INIT_GET_RESOURCES;
2427 goto restart;
Greg Rose5eae00c2013-12-21 06:12:45 +00002428 case __I40EVF_INIT_GET_RESOURCES:
2429 /* aq msg sent, awaiting reply */
2430 if (!adapter->vf_res) {
2431 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
2432 (I40E_MAX_VF_VSI *
2433 sizeof(struct i40e_virtchnl_vsi_resource));
2434 adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002435 if (!adapter->vf_res)
Greg Rose5eae00c2013-12-21 06:12:45 +00002436 goto err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002437 }
2438 err = i40evf_get_vf_config(adapter);
Mitch Williams906a6932014-11-13 03:06:12 +00002439 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
Mitch Williams906a6932014-11-13 03:06:12 +00002440 err = i40evf_send_vf_config_msg(adapter);
2441 goto err;
Mitch Williamse7430722015-10-26 19:44:38 -04002442 } else if (err == I40E_ERR_PARAM) {
2443 /* We only get ERR_PARAM if the device is in a very bad
2444 * state or if we've been disabled for previous bad
2445 * behavior. Either way, we're done now.
2446 */
2447 i40evf_shutdown_adminq(hw);
2448 dev_err(&pdev->dev, "Unable to get VF config due to PF error condition, not retrying\n");
2449 return;
Mitch Williams906a6932014-11-13 03:06:12 +00002450 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002451 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002452 dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
2453 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002454 goto err_alloc;
2455 }
2456 adapter->state = __I40EVF_INIT_SW;
2457 break;
2458 default:
2459 goto err_alloc;
2460 }
Mitch Williamse6d038d2015-06-04 16:23:58 -04002461 if (i40evf_process_config(adapter))
Greg Rose5eae00c2013-12-21 06:12:45 +00002462 goto err_alloc;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002463 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00002464
2465 adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED;
2466
Greg Rose5eae00c2013-12-21 06:12:45 +00002467 netdev->netdev_ops = &i40evf_netdev_ops;
2468 i40evf_set_ethtool_ops(netdev);
2469 netdev->watchdog_timeo = 5 * HZ;
Greg Rose3415e8c2014-01-30 12:40:27 +00002470
Greg Rose5eae00c2013-12-21 06:12:45 +00002471 if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
Mitch Williamsb34f90e2014-05-10 04:49:07 +00002472 dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002473 adapter->hw.mac.addr);
Mitch Williams14e52ee2015-08-31 19:54:44 -04002474 eth_hw_addr_random(netdev);
2475 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2476 } else {
2477 adapter->flags |= I40EVF_FLAG_ADDR_SET_BY_PF;
2478 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
2479 ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002480 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002481
Greg Rose5eae00c2013-12-21 06:12:45 +00002482 init_timer(&adapter->watchdog_timer);
2483 adapter->watchdog_timer.function = &i40evf_watchdog_timer;
2484 adapter->watchdog_timer.data = (unsigned long)adapter;
2485 mod_timer(&adapter->watchdog_timer, jiffies + 1);
2486
Mitch Williamscc052922014-10-25 03:24:34 +00002487 adapter->num_active_queues = min_t(int,
2488 adapter->vsi_res->num_queue_pairs,
2489 (int)(num_online_cpus()));
Mitch Williamsd732a182014-04-24 06:41:37 +00002490 adapter->tx_desc_count = I40EVF_DEFAULT_TXD;
2491 adapter->rx_desc_count = I40EVF_DEFAULT_RXD;
Greg Rose5eae00c2013-12-21 06:12:45 +00002492 err = i40evf_init_interrupt_scheme(adapter);
2493 if (err)
2494 goto err_sw_init;
2495 i40evf_map_rings_to_vectors(adapter);
Anjali Singhai Jain1f012272015-09-03 17:18:53 -04002496 if (adapter->vf_res->vf_offload_flags &
2497 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
2498 adapter->flags |= I40EVF_FLAG_WB_ON_ITR_CAPABLE;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04002499 if (!RSS_AQ(adapter))
Helin Zhang96a81982015-10-26 19:44:31 -04002500 i40evf_init_rss(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002501 err = i40evf_request_misc_irq(adapter);
2502 if (err)
2503 goto err_sw_init;
2504
2505 netif_carrier_off(netdev);
2506
Mitch Williamsef8693e2014-02-13 03:48:53 -08002507 if (!adapter->netdev_registered) {
2508 err = register_netdev(netdev);
2509 if (err)
2510 goto err_register;
2511 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002512
2513 adapter->netdev_registered = true;
2514
2515 netif_tx_stop_all_queues(netdev);
2516
Mitch Williamsb34f90e2014-05-10 04:49:07 +00002517 dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002518 if (netdev->features & NETIF_F_GRO)
2519 dev_info(&pdev->dev, "GRO is enabled\n");
2520
Greg Rose5eae00c2013-12-21 06:12:45 +00002521 adapter->state = __I40EVF_DOWN;
2522 set_bit(__I40E_DOWN, &adapter->vsi.state);
2523 i40evf_misc_irq_enable(adapter);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04002524
2525 if (RSS_AQ(adapter)) {
2526 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_RSS;
2527 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
2528 } else {
Helin Zhang96a81982015-10-26 19:44:31 -04002529 i40evf_init_rss(adapter);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04002530 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002531 return;
2532restart:
Mitch Williams3f7e5c32015-09-28 14:12:42 -04002533 schedule_delayed_work(&adapter->init_task, msecs_to_jiffies(30));
Greg Rose5eae00c2013-12-21 06:12:45 +00002534 return;
2535
2536err_register:
2537 i40evf_free_misc_irq(adapter);
2538err_sw_init:
2539 i40evf_reset_interrupt_capability(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002540err_alloc:
2541 kfree(adapter->vf_res);
2542 adapter->vf_res = NULL;
2543err:
2544 /* Things went into the weeds, so try again later */
2545 if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
Mitch Williamsb9029e92015-09-28 14:16:50 -04002546 dev_err(&pdev->dev, "Failed to communicate with PF; waiting before retry\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08002547 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
Mitch Williamsb9029e92015-09-28 14:16:50 -04002548 i40evf_shutdown_adminq(hw);
2549 adapter->state = __I40EVF_STARTUP;
2550 schedule_delayed_work(&adapter->init_task, HZ * 5);
2551 return;
Greg Rose5eae00c2013-12-21 06:12:45 +00002552 }
Mitch Williams3f7e5c32015-09-28 14:12:42 -04002553 schedule_delayed_work(&adapter->init_task, HZ);
Greg Rose5eae00c2013-12-21 06:12:45 +00002554}
2555
2556/**
2557 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2558 * @pdev: pci device structure
2559 **/
2560static void i40evf_shutdown(struct pci_dev *pdev)
2561{
2562 struct net_device *netdev = pci_get_drvdata(pdev);
Mitch Williams00293fd2015-01-09 11:18:18 +00002563 struct i40evf_adapter *adapter = netdev_priv(netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +00002564
2565 netif_device_detach(netdev);
2566
2567 if (netif_running(netdev))
2568 i40evf_close(netdev);
2569
Mitch Williams00293fd2015-01-09 11:18:18 +00002570 /* Prevent the watchdog from running. */
2571 adapter->state = __I40EVF_REMOVE;
2572 adapter->aq_required = 0;
Mitch Williams00293fd2015-01-09 11:18:18 +00002573
Greg Rose5eae00c2013-12-21 06:12:45 +00002574#ifdef CONFIG_PM
2575 pci_save_state(pdev);
2576
2577#endif
2578 pci_disable_device(pdev);
2579}
2580
2581/**
2582 * i40evf_probe - Device Initialization Routine
2583 * @pdev: PCI device information struct
2584 * @ent: entry in i40evf_pci_tbl
2585 *
2586 * Returns 0 on success, negative on failure
2587 *
2588 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2589 * The OS initialization, configuring of the adapter private structure,
2590 * and a hardware reset occur.
2591 **/
2592static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2593{
2594 struct net_device *netdev;
2595 struct i40evf_adapter *adapter = NULL;
2596 struct i40e_hw *hw = NULL;
Mitch Williamsdbbd8112014-02-20 19:29:08 -08002597 int err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002598
2599 err = pci_enable_device(pdev);
2600 if (err)
2601 return err;
2602
Mitch Williams64942942014-02-11 08:26:33 +00002603 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +00002604 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +00002605 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2606 if (err) {
2607 dev_err(&pdev->dev,
2608 "DMA configuration failed: 0x%x\n", err);
2609 goto err_dma;
2610 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002611 }
2612
2613 err = pci_request_regions(pdev, i40evf_driver_name);
2614 if (err) {
2615 dev_err(&pdev->dev,
2616 "pci_request_regions failed 0x%x\n", err);
2617 goto err_pci_reg;
2618 }
2619
2620 pci_enable_pcie_error_reporting(pdev);
2621
2622 pci_set_master(pdev);
2623
Mitch Williams1255b7a2015-11-06 15:25:59 -08002624 netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter), MAX_QUEUES);
Greg Rose5eae00c2013-12-21 06:12:45 +00002625 if (!netdev) {
2626 err = -ENOMEM;
2627 goto err_alloc_etherdev;
2628 }
2629
2630 SET_NETDEV_DEV(netdev, &pdev->dev);
2631
2632 pci_set_drvdata(pdev, netdev);
2633 adapter = netdev_priv(netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +00002634
2635 adapter->netdev = netdev;
2636 adapter->pdev = pdev;
2637
2638 hw = &adapter->hw;
2639 hw->back = adapter;
2640
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002641 adapter->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
Greg Rose5eae00c2013-12-21 06:12:45 +00002642 adapter->state = __I40EVF_STARTUP;
2643
2644 /* Call save state here because it relies on the adapter struct. */
2645 pci_save_state(pdev);
2646
2647 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2648 pci_resource_len(pdev, 0));
2649 if (!hw->hw_addr) {
2650 err = -EIO;
2651 goto err_ioremap;
2652 }
2653 hw->vendor_id = pdev->vendor;
2654 hw->device_id = pdev->device;
2655 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2656 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2657 hw->subsystem_device_id = pdev->subsystem_device;
2658 hw->bus.device = PCI_SLOT(pdev->devfn);
2659 hw->bus.func = PCI_FUNC(pdev->devfn);
2660
Serey Kong8bb1a542014-08-01 13:27:15 -07002661 INIT_LIST_HEAD(&adapter->mac_filter_list);
2662 INIT_LIST_HEAD(&adapter->vlan_filter_list);
2663
Greg Rose5eae00c2013-12-21 06:12:45 +00002664 INIT_WORK(&adapter->reset_task, i40evf_reset_task);
2665 INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
2666 INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
2667 INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
Mitch Williams9b32b0b2015-08-13 15:11:32 -07002668 schedule_delayed_work(&adapter->init_task,
2669 msecs_to_jiffies(5 * (pdev->devfn & 0x07)));
Greg Rose5eae00c2013-12-21 06:12:45 +00002670
2671 return 0;
2672
2673err_ioremap:
2674 free_netdev(netdev);
2675err_alloc_etherdev:
2676 pci_release_regions(pdev);
2677err_pci_reg:
2678err_dma:
2679 pci_disable_device(pdev);
2680 return err;
2681}
2682
2683#ifdef CONFIG_PM
2684/**
2685 * i40evf_suspend - Power management suspend routine
2686 * @pdev: PCI device information struct
2687 * @state: unused
2688 *
2689 * Called when the system (VM) is entering sleep/suspend.
2690 **/
2691static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
2692{
2693 struct net_device *netdev = pci_get_drvdata(pdev);
2694 struct i40evf_adapter *adapter = netdev_priv(netdev);
2695 int retval = 0;
2696
2697 netif_device_detach(netdev);
2698
2699 if (netif_running(netdev)) {
2700 rtnl_lock();
2701 i40evf_down(adapter);
2702 rtnl_unlock();
2703 }
2704 i40evf_free_misc_irq(adapter);
2705 i40evf_reset_interrupt_capability(adapter);
2706
2707 retval = pci_save_state(pdev);
2708 if (retval)
2709 return retval;
2710
2711 pci_disable_device(pdev);
2712
2713 return 0;
2714}
2715
2716/**
Joe Perchesdbedd442015-03-06 20:49:12 -08002717 * i40evf_resume - Power management resume routine
Greg Rose5eae00c2013-12-21 06:12:45 +00002718 * @pdev: PCI device information struct
2719 *
2720 * Called when the system (VM) is resumed from sleep/suspend.
2721 **/
2722static int i40evf_resume(struct pci_dev *pdev)
2723{
2724 struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
2725 struct net_device *netdev = adapter->netdev;
2726 u32 err;
2727
2728 pci_set_power_state(pdev, PCI_D0);
2729 pci_restore_state(pdev);
2730 /* pci_restore_state clears dev->state_saved so call
2731 * pci_save_state to restore it.
2732 */
2733 pci_save_state(pdev);
2734
2735 err = pci_enable_device_mem(pdev);
2736 if (err) {
2737 dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
2738 return err;
2739 }
2740 pci_set_master(pdev);
2741
2742 rtnl_lock();
2743 err = i40evf_set_interrupt_capability(adapter);
2744 if (err) {
Vasily Averinf2a1c362015-07-07 18:53:38 +03002745 rtnl_unlock();
Greg Rose5eae00c2013-12-21 06:12:45 +00002746 dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
2747 return err;
2748 }
2749 err = i40evf_request_misc_irq(adapter);
2750 rtnl_unlock();
2751 if (err) {
2752 dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
2753 return err;
2754 }
2755
2756 schedule_work(&adapter->reset_task);
2757
2758 netif_device_attach(netdev);
2759
2760 return err;
2761}
2762
2763#endif /* CONFIG_PM */
2764/**
2765 * i40evf_remove - Device Removal Routine
2766 * @pdev: PCI device information struct
2767 *
2768 * i40evf_remove is called by the PCI subsystem to alert the driver
2769 * that it should release a PCI device. The could be caused by a
2770 * Hot-Plug event, or because the driver is going to be removed from
2771 * memory.
2772 **/
2773static void i40evf_remove(struct pci_dev *pdev)
2774{
2775 struct net_device *netdev = pci_get_drvdata(pdev);
2776 struct i40evf_adapter *adapter = netdev_priv(netdev);
Mitch Williams6ba36a22014-08-01 13:27:14 -07002777 struct i40evf_mac_filter *f, *ftmp;
Greg Rose5eae00c2013-12-21 06:12:45 +00002778 struct i40e_hw *hw = &adapter->hw;
2779
2780 cancel_delayed_work_sync(&adapter->init_task);
Mitch Williamsef8693e2014-02-13 03:48:53 -08002781 cancel_work_sync(&adapter->reset_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00002782
2783 if (adapter->netdev_registered) {
2784 unregister_netdev(netdev);
2785 adapter->netdev_registered = false;
2786 }
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00002787
Mitch Williamsf4a71882015-01-09 11:18:16 +00002788 /* Shut down all the garbage mashers on the detention level */
Greg Rose5eae00c2013-12-21 06:12:45 +00002789 adapter->state = __I40EVF_REMOVE;
Mitch Williamsf4a71882015-01-09 11:18:16 +00002790 adapter->aq_required = 0;
Mitch Williamsf4a71882015-01-09 11:18:16 +00002791 i40evf_request_reset(adapter);
2792 msleep(20);
2793 /* If the FW isn't responding, kick it once, but only once. */
2794 if (!i40evf_asq_done(hw)) {
2795 i40evf_request_reset(adapter);
2796 msleep(20);
2797 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002798
Mitch Williamsdbb01c82014-02-20 19:29:07 -08002799 if (adapter->msix_entries) {
Greg Rose5eae00c2013-12-21 06:12:45 +00002800 i40evf_misc_irq_disable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002801 i40evf_free_misc_irq(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002802 i40evf_reset_interrupt_capability(adapter);
Mitch Williamsd31944d2014-08-01 13:27:13 -07002803 i40evf_free_q_vectors(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002804 }
2805
Mitch Williamse5d17c32014-06-04 04:22:38 +00002806 if (adapter->watchdog_timer.function)
2807 del_timer_sync(&adapter->watchdog_timer);
2808
Mitch Williamsdbb01c82014-02-20 19:29:07 -08002809 flush_scheduled_work();
2810
Helin Zhang66f9af852015-10-26 19:44:34 -04002811 /* Clear user configurations for RSS */
2812 i40evf_clear_rss_config_user(&adapter->vsi);
2813
Greg Rose5eae00c2013-12-21 06:12:45 +00002814 if (hw->aq.asq.count)
2815 i40evf_shutdown_adminq(hw);
2816
2817 iounmap(hw->hw_addr);
2818 pci_release_regions(pdev);
2819
Mitch Williamse284fc82015-03-27 00:12:09 -07002820 i40evf_free_all_tx_resources(adapter);
2821 i40evf_free_all_rx_resources(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002822 i40evf_free_queues(adapter);
2823 kfree(adapter->vf_res);
Mitch Williams6ba36a22014-08-01 13:27:14 -07002824 /* If we got removed before an up/down sequence, we've got a filter
2825 * hanging out there that we need to get rid of.
2826 */
2827 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
2828 list_del(&f->list);
2829 kfree(f);
2830 }
Mitch A Williams37dfdf32014-12-09 08:53:05 +00002831 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
2832 list_del(&f->list);
2833 kfree(f);
2834 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002835
2836 free_netdev(netdev);
2837
2838 pci_disable_pcie_error_reporting(pdev);
2839
2840 pci_disable_device(pdev);
2841}
2842
2843static struct pci_driver i40evf_driver = {
2844 .name = i40evf_driver_name,
2845 .id_table = i40evf_pci_tbl,
2846 .probe = i40evf_probe,
2847 .remove = i40evf_remove,
2848#ifdef CONFIG_PM
2849 .suspend = i40evf_suspend,
2850 .resume = i40evf_resume,
2851#endif
2852 .shutdown = i40evf_shutdown,
2853};
2854
2855/**
2856 * i40e_init_module - Driver Registration Routine
2857 *
2858 * i40e_init_module is the first routine called when the driver is
2859 * loaded. All it does is register with the PCI subsystem.
2860 **/
2861static int __init i40evf_init_module(void)
2862{
2863 int ret;
Mitch Williams75a64432014-11-11 20:02:42 +00002864
Greg Rose5eae00c2013-12-21 06:12:45 +00002865 pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
Mitch Williams75a64432014-11-11 20:02:42 +00002866 i40evf_driver_version);
Greg Rose5eae00c2013-12-21 06:12:45 +00002867
2868 pr_info("%s\n", i40evf_copyright);
2869
2870 ret = pci_register_driver(&i40evf_driver);
2871 return ret;
2872}
2873
2874module_init(i40evf_init_module);
2875
2876/**
2877 * i40e_exit_module - Driver Exit Cleanup Routine
2878 *
2879 * i40e_exit_module is called just before the driver is removed
2880 * from memory.
2881 **/
2882static void __exit i40evf_exit_module(void)
2883{
2884 pci_unregister_driver(&i40evf_driver);
2885}
2886
2887module_exit(i40evf_exit_module);
2888
2889/* i40evf_main.c */