blob: 5915273c372f8d7f435f897fe68650239925084d [file] [log] [blame]
Greg Rose5eae00c2013-12-21 06:12:45 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
Catherine Sullivaneaab59e2016-01-13 16:51:44 -08004 * Copyright(c) 2013 - 2016 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"
Mitch Williamsed0e8942017-01-24 10:23:59 -080029#include "i40evf_client.h"
Scott Petersoned0980c2017-04-13 04:45:44 -040030/* All i40evf tracepoints are defined by the include below, which must
31 * be included exactly once across the whole kernel with
32 * CREATE_TRACE_POINTS defined
33 */
34#define CREATE_TRACE_POINTS
35#include "i40e_trace.h"
36
Greg Rose5eae00c2013-12-21 06:12:45 +000037static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter);
38static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter);
39static int i40evf_close(struct net_device *netdev);
40
41char i40evf_driver_name[] = "i40evf";
42static const char i40evf_driver_string[] =
Catherine Sullivaneaab59e2016-01-13 16:51:44 -080043 "Intel(R) 40-10 Gigabit Virtual Function Network Driver";
Greg Rose5eae00c2013-12-21 06:12:45 +000044
Mitch Williams69ebe9552015-11-19 11:34:24 -080045#define DRV_KERN "-k"
46
Bimmy Pujari15990832017-01-30 12:29:37 -080047#define DRV_VERSION_MAJOR 2
48#define DRV_VERSION_MINOR 1
49#define DRV_VERSION_BUILD 7
Mitch Williams69ebe9552015-11-19 11:34:24 -080050#define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
51 __stringify(DRV_VERSION_MINOR) "." \
52 __stringify(DRV_VERSION_BUILD) \
53 DRV_KERN
Greg Rose5eae00c2013-12-21 06:12:45 +000054const char i40evf_driver_version[] = DRV_VERSION;
55static const char i40evf_copyright[] =
Catherine Sullivanbf418462015-07-10 19:36:10 -040056 "Copyright (c) 2013 - 2015 Intel Corporation.";
Greg Rose5eae00c2013-12-21 06:12:45 +000057
58/* i40evf_pci_tbl - PCI Device ID Table
59 *
60 * Wildcard entries (PCI_ANY_ID) should come last
61 * Last entry must be all 0s
62 *
63 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
64 * Class, Class Mask, private data (not used) }
65 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020066static const struct pci_device_id i40evf_pci_tbl[] = {
Shannon Nelsonab600852014-01-17 15:36:39 -080067 {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF), 0},
Joshua Hay92871412016-06-20 09:10:37 -070068 {PCI_VDEVICE(INTEL, I40E_DEV_ID_VF_HV), 0},
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040069 {PCI_VDEVICE(INTEL, I40E_DEV_ID_X722_VF), 0},
Greg Rose5eae00c2013-12-21 06:12:45 +000070 /* required last entry */
71 {0, }
72};
73
74MODULE_DEVICE_TABLE(pci, i40evf_pci_tbl);
75
76MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
77MODULE_DESCRIPTION("Intel(R) XL710 X710 Virtual Function Network Driver");
78MODULE_LICENSE("GPL");
79MODULE_VERSION(DRV_VERSION);
80
Jesse Brandeburg2803b162015-12-22 14:25:08 -080081static struct workqueue_struct *i40evf_wq;
82
Greg Rose5eae00c2013-12-21 06:12:45 +000083/**
84 * i40evf_allocate_dma_mem_d - OS specific memory alloc for shared code
85 * @hw: pointer to the HW structure
86 * @mem: ptr to mem struct to fill out
87 * @size: size of memory requested
88 * @alignment: what to align the allocation to
89 **/
90i40e_status i40evf_allocate_dma_mem_d(struct i40e_hw *hw,
91 struct i40e_dma_mem *mem,
92 u64 size, u32 alignment)
93{
94 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
95
96 if (!mem)
97 return I40E_ERR_PARAM;
98
99 mem->size = ALIGN(size, alignment);
100 mem->va = dma_alloc_coherent(&adapter->pdev->dev, mem->size,
101 (dma_addr_t *)&mem->pa, GFP_KERNEL);
102 if (mem->va)
103 return 0;
104 else
105 return I40E_ERR_NO_MEMORY;
106}
107
108/**
109 * i40evf_free_dma_mem_d - OS specific memory free for shared code
110 * @hw: pointer to the HW structure
111 * @mem: ptr to mem struct to free
112 **/
113i40e_status i40evf_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
114{
115 struct i40evf_adapter *adapter = (struct i40evf_adapter *)hw->back;
116
117 if (!mem || !mem->va)
118 return I40E_ERR_PARAM;
119 dma_free_coherent(&adapter->pdev->dev, mem->size,
120 mem->va, (dma_addr_t)mem->pa);
121 return 0;
122}
123
124/**
125 * i40evf_allocate_virt_mem_d - OS specific memory alloc for shared code
126 * @hw: pointer to the HW structure
127 * @mem: ptr to mem struct to fill out
128 * @size: size of memory requested
129 **/
130i40e_status i40evf_allocate_virt_mem_d(struct i40e_hw *hw,
131 struct i40e_virt_mem *mem, u32 size)
132{
133 if (!mem)
134 return I40E_ERR_PARAM;
135
136 mem->size = size;
137 mem->va = kzalloc(size, GFP_KERNEL);
138
139 if (mem->va)
140 return 0;
141 else
142 return I40E_ERR_NO_MEMORY;
143}
144
145/**
146 * i40evf_free_virt_mem_d - OS specific memory free for shared code
147 * @hw: pointer to the HW structure
148 * @mem: ptr to mem struct to free
149 **/
150i40e_status i40evf_free_virt_mem_d(struct i40e_hw *hw,
151 struct i40e_virt_mem *mem)
152{
153 if (!mem)
154 return I40E_ERR_PARAM;
155
156 /* it's ok to kfree a NULL pointer */
157 kfree(mem->va);
158
159 return 0;
160}
161
162/**
163 * i40evf_debug_d - OS dependent version of debug printing
164 * @hw: pointer to the HW structure
165 * @mask: debug level mask
166 * @fmt_str: printf-type format description
167 **/
168void i40evf_debug_d(void *hw, u32 mask, char *fmt_str, ...)
169{
170 char buf[512];
171 va_list argptr;
172
173 if (!(mask & ((struct i40e_hw *)hw)->debug_mask))
174 return;
175
176 va_start(argptr, fmt_str);
177 vsnprintf(buf, sizeof(buf), fmt_str, argptr);
178 va_end(argptr);
179
180 /* the debug string is already formatted with a newline */
181 pr_info("%s", buf);
182}
183
184/**
Mitch Williams00e5ec42016-01-15 14:33:10 -0800185 * i40evf_schedule_reset - Set the flags and schedule a reset event
186 * @adapter: board private structure
187 **/
188void i40evf_schedule_reset(struct i40evf_adapter *adapter)
189{
190 if (!(adapter->flags &
191 (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED))) {
192 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
193 schedule_work(&adapter->reset_task);
194 }
195}
196
197/**
Greg Rose5eae00c2013-12-21 06:12:45 +0000198 * i40evf_tx_timeout - Respond to a Tx Hang
199 * @netdev: network interface device structure
200 **/
201static void i40evf_tx_timeout(struct net_device *netdev)
202{
203 struct i40evf_adapter *adapter = netdev_priv(netdev);
204
205 adapter->tx_timeout_count++;
Mitch Williams00e5ec42016-01-15 14:33:10 -0800206 i40evf_schedule_reset(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +0000207}
208
209/**
210 * i40evf_misc_irq_disable - Mask off interrupt generation on the NIC
211 * @adapter: board private structure
212 **/
213static void i40evf_misc_irq_disable(struct i40evf_adapter *adapter)
214{
215 struct i40e_hw *hw = &adapter->hw;
Mitch Williams75a64432014-11-11 20:02:42 +0000216
Jacob Kelleref4603e2016-11-08 13:05:08 -0800217 if (!adapter->msix_entries)
218 return;
219
Greg Rose5eae00c2013-12-21 06:12:45 +0000220 wr32(hw, I40E_VFINT_DYN_CTL01, 0);
221
222 /* read flush */
223 rd32(hw, I40E_VFGEN_RSTAT);
224
225 synchronize_irq(adapter->msix_entries[0].vector);
226}
227
228/**
229 * i40evf_misc_irq_enable - Enable default interrupt generation settings
230 * @adapter: board private structure
231 **/
232static void i40evf_misc_irq_enable(struct i40evf_adapter *adapter)
233{
234 struct i40e_hw *hw = &adapter->hw;
Mitch Williams75a64432014-11-11 20:02:42 +0000235
Greg Rose5eae00c2013-12-21 06:12:45 +0000236 wr32(hw, I40E_VFINT_DYN_CTL01, I40E_VFINT_DYN_CTL01_INTENA_MASK |
237 I40E_VFINT_DYN_CTL01_ITR_INDX_MASK);
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400238 wr32(hw, I40E_VFINT_ICR0_ENA1, I40E_VFINT_ICR0_ENA1_ADMINQ_MASK);
Greg Rose5eae00c2013-12-21 06:12:45 +0000239
240 /* read flush */
241 rd32(hw, I40E_VFGEN_RSTAT);
242}
243
244/**
245 * i40evf_irq_disable - Mask off interrupt generation on the NIC
246 * @adapter: board private structure
247 **/
248static void i40evf_irq_disable(struct i40evf_adapter *adapter)
249{
250 int i;
251 struct i40e_hw *hw = &adapter->hw;
252
Mitch Williamsdbb01c82014-02-20 19:29:07 -0800253 if (!adapter->msix_entries)
254 return;
255
Greg Rose5eae00c2013-12-21 06:12:45 +0000256 for (i = 1; i < adapter->num_msix_vectors; i++) {
257 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), 0);
258 synchronize_irq(adapter->msix_entries[i].vector);
259 }
260 /* read flush */
261 rd32(hw, I40E_VFGEN_RSTAT);
Greg Rose5eae00c2013-12-21 06:12:45 +0000262}
263
264/**
265 * i40evf_irq_enable_queues - Enable interrupt for specified queues
266 * @adapter: board private structure
267 * @mask: bitmap of queues to enable
268 **/
269void i40evf_irq_enable_queues(struct i40evf_adapter *adapter, u32 mask)
270{
271 struct i40e_hw *hw = &adapter->hw;
272 int i;
273
274 for (i = 1; i < adapter->num_msix_vectors; i++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400275 if (mask & BIT(i - 1)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000276 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1),
277 I40E_VFINT_DYN_CTLN1_INTENA_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000278 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400279 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK);
Greg Rose5eae00c2013-12-21 06:12:45 +0000280 }
281 }
282}
283
284/**
285 * i40evf_fire_sw_int - Generate SW interrupt for specified vectors
286 * @adapter: board private structure
287 * @mask: bitmap of vectors to trigger
288 **/
Mitch Williams75a64432014-11-11 20:02:42 +0000289static void i40evf_fire_sw_int(struct i40evf_adapter *adapter, u32 mask)
Greg Rose5eae00c2013-12-21 06:12:45 +0000290{
291 struct i40e_hw *hw = &adapter->hw;
292 int i;
Mitch Williamsd82acb32015-11-06 15:26:06 -0800293 u32 dyn_ctl;
Greg Rose5eae00c2013-12-21 06:12:45 +0000294
Mitch Williams164ec1b2014-06-04 08:45:19 +0000295 if (mask & 1) {
296 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTL01);
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400297 dyn_ctl |= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000298 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400299 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK;
Mitch Williams164ec1b2014-06-04 08:45:19 +0000300 wr32(hw, I40E_VFINT_DYN_CTL01, dyn_ctl);
301 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000302 for (i = 1; i < adapter->num_msix_vectors; i++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400303 if (mask & BIT(i)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000304 dyn_ctl = rd32(hw, I40E_VFINT_DYN_CTLN1(i - 1));
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400305 dyn_ctl |= I40E_VFINT_DYN_CTLN1_SWINT_TRIG_MASK |
Jesse Brandeburg97bf75f2015-02-27 09:18:32 +0000306 I40E_VFINT_DYN_CTLN1_ITR_INDX_MASK |
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -0400307 I40E_VFINT_DYN_CTLN1_CLEARPBA_MASK;
Greg Rose5eae00c2013-12-21 06:12:45 +0000308 wr32(hw, I40E_VFINT_DYN_CTLN1(i - 1), dyn_ctl);
309 }
310 }
311}
312
313/**
314 * i40evf_irq_enable - Enable default interrupt generation settings
315 * @adapter: board private structure
Jean Sacren69c1d702015-10-13 01:06:27 -0600316 * @flush: boolean value whether to run rd32()
Greg Rose5eae00c2013-12-21 06:12:45 +0000317 **/
318void i40evf_irq_enable(struct i40evf_adapter *adapter, bool flush)
319{
320 struct i40e_hw *hw = &adapter->hw;
321
Mitch Williams164ec1b2014-06-04 08:45:19 +0000322 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +0000323 i40evf_irq_enable_queues(adapter, ~0);
324
325 if (flush)
326 rd32(hw, I40E_VFGEN_RSTAT);
327}
328
329/**
330 * i40evf_msix_aq - Interrupt handler for vector 0
331 * @irq: interrupt number
332 * @data: pointer to netdev
333 **/
334static irqreturn_t i40evf_msix_aq(int irq, void *data)
335{
336 struct net_device *netdev = data;
337 struct i40evf_adapter *adapter = netdev_priv(netdev);
338 struct i40e_hw *hw = &adapter->hw;
339 u32 val;
Greg Rose5eae00c2013-12-21 06:12:45 +0000340
Jesse Brandeburgcfbe4db2015-10-04 01:09:49 -0700341 /* handle non-queue interrupts, these reads clear the registers */
342 val = rd32(hw, I40E_VFINT_ICR01);
343 val = rd32(hw, I40E_VFINT_ICR0_ENA1);
Greg Rose5eae00c2013-12-21 06:12:45 +0000344
Jean Sacrened17f7e2015-10-13 01:06:30 -0600345 val = rd32(hw, I40E_VFINT_DYN_CTL01) |
346 I40E_VFINT_DYN_CTL01_CLEARPBA_MASK;
Greg Rose5eae00c2013-12-21 06:12:45 +0000347 wr32(hw, I40E_VFINT_DYN_CTL01, val);
348
Greg Rose5eae00c2013-12-21 06:12:45 +0000349 /* schedule work on the private workqueue */
350 schedule_work(&adapter->adminq_task);
351
352 return IRQ_HANDLED;
353}
354
355/**
356 * i40evf_msix_clean_rings - MSIX mode Interrupt Handler
357 * @irq: interrupt number
358 * @data: pointer to a q_vector
359 **/
360static irqreturn_t i40evf_msix_clean_rings(int irq, void *data)
361{
362 struct i40e_q_vector *q_vector = data;
363
364 if (!q_vector->tx.ring && !q_vector->rx.ring)
365 return IRQ_HANDLED;
366
Alexander Duyck5d3465a2015-09-29 15:19:50 -0700367 napi_schedule_irqoff(&q_vector->napi);
Greg Rose5eae00c2013-12-21 06:12:45 +0000368
369 return IRQ_HANDLED;
370}
371
372/**
373 * i40evf_map_vector_to_rxq - associate irqs with rx queues
374 * @adapter: board private structure
375 * @v_idx: interrupt number
376 * @r_idx: queue number
377 **/
378static void
379i40evf_map_vector_to_rxq(struct i40evf_adapter *adapter, int v_idx, int r_idx)
380{
Mitch Williams7d96ba12015-10-26 19:44:39 -0400381 struct i40e_q_vector *q_vector = &adapter->q_vectors[v_idx];
Mitch Williams0dd438d2015-10-26 19:44:40 -0400382 struct i40e_ring *rx_ring = &adapter->rx_rings[r_idx];
Mitch Williamsf19a9732016-09-12 14:18:38 -0700383 struct i40e_hw *hw = &adapter->hw;
Greg Rose5eae00c2013-12-21 06:12:45 +0000384
385 rx_ring->q_vector = q_vector;
386 rx_ring->next = q_vector->rx.ring;
387 rx_ring->vsi = &adapter->vsi;
388 q_vector->rx.ring = rx_ring;
389 q_vector->rx.count++;
390 q_vector->rx.latency_range = I40E_LOW_LATENCY;
Jacob Keller65e87c02016-09-12 14:18:44 -0700391 q_vector->rx.itr = ITR_TO_REG(rx_ring->rx_itr_setting);
Mitch Williamsf19a9732016-09-12 14:18:38 -0700392 q_vector->ring_mask |= BIT(r_idx);
Jesse Brandeburgee2319c2015-09-28 14:16:54 -0400393 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Mitch Williamsf19a9732016-09-12 14:18:38 -0700394 wr32(hw, I40E_VFINT_ITRN1(I40E_RX_ITR, v_idx - 1), q_vector->rx.itr);
Greg Rose5eae00c2013-12-21 06:12:45 +0000395}
396
397/**
398 * i40evf_map_vector_to_txq - associate irqs with tx queues
399 * @adapter: board private structure
400 * @v_idx: interrupt number
401 * @t_idx: queue number
402 **/
403static void
404i40evf_map_vector_to_txq(struct i40evf_adapter *adapter, int v_idx, int t_idx)
405{
Mitch Williams7d96ba12015-10-26 19:44:39 -0400406 struct i40e_q_vector *q_vector = &adapter->q_vectors[v_idx];
Mitch Williams0dd438d2015-10-26 19:44:40 -0400407 struct i40e_ring *tx_ring = &adapter->tx_rings[t_idx];
Mitch Williamsf19a9732016-09-12 14:18:38 -0700408 struct i40e_hw *hw = &adapter->hw;
Greg Rose5eae00c2013-12-21 06:12:45 +0000409
410 tx_ring->q_vector = q_vector;
411 tx_ring->next = q_vector->tx.ring;
412 tx_ring->vsi = &adapter->vsi;
413 q_vector->tx.ring = tx_ring;
414 q_vector->tx.count++;
415 q_vector->tx.latency_range = I40E_LOW_LATENCY;
Jacob Keller65e87c02016-09-12 14:18:44 -0700416 q_vector->tx.itr = ITR_TO_REG(tx_ring->tx_itr_setting);
Jesse Brandeburgee2319c2015-09-28 14:16:54 -0400417 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Greg Rose5eae00c2013-12-21 06:12:45 +0000418 q_vector->num_ringpairs++;
Mitch Williamsf19a9732016-09-12 14:18:38 -0700419 wr32(hw, I40E_VFINT_ITRN1(I40E_TX_ITR, v_idx - 1), q_vector->tx.itr);
Greg Rose5eae00c2013-12-21 06:12:45 +0000420}
421
422/**
423 * i40evf_map_rings_to_vectors - Maps descriptor rings to vectors
424 * @adapter: board private structure to initialize
425 *
426 * This function maps descriptor rings to the queue-specific vectors
427 * we were allotted through the MSI-X enabling code. Ideally, we'd have
428 * one vector per ring/queue, but on a constrained vector budget, we
429 * group the rings as "efficiently" as possible. You would add new
430 * mapping configurations in here.
431 **/
432static int i40evf_map_rings_to_vectors(struct i40evf_adapter *adapter)
433{
434 int q_vectors;
435 int v_start = 0;
436 int rxr_idx = 0, txr_idx = 0;
Mitch Williamscc052922014-10-25 03:24:34 +0000437 int rxr_remaining = adapter->num_active_queues;
438 int txr_remaining = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +0000439 int i, j;
440 int rqpv, tqpv;
441 int err = 0;
442
443 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
444
445 /* The ideal configuration...
446 * We have enough vectors to map one per queue.
447 */
Mitch Williams973371d2015-04-27 14:57:09 -0400448 if (q_vectors >= (rxr_remaining * 2)) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000449 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
450 i40evf_map_vector_to_rxq(adapter, v_start, rxr_idx);
451
452 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
453 i40evf_map_vector_to_txq(adapter, v_start, txr_idx);
454 goto out;
455 }
456
457 /* If we don't have enough vectors for a 1-to-1
458 * mapping, we'll have to group them so there are
459 * multiple queues per vector.
460 * Re-adjusting *qpv takes care of the remainder.
461 */
462 for (i = v_start; i < q_vectors; i++) {
463 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
464 for (j = 0; j < rqpv; j++) {
465 i40evf_map_vector_to_rxq(adapter, i, rxr_idx);
466 rxr_idx++;
467 rxr_remaining--;
468 }
469 }
470 for (i = v_start; i < q_vectors; i++) {
471 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
472 for (j = 0; j < tqpv; j++) {
473 i40evf_map_vector_to_txq(adapter, i, txr_idx);
474 txr_idx++;
475 txr_remaining--;
476 }
477 }
478
479out:
480 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
481
482 return err;
483}
484
Alexander Duyck7709b4c2015-09-24 09:04:38 -0700485#ifdef CONFIG_NET_POLL_CONTROLLER
486/**
487 * i40evf_netpoll - A Polling 'interrupt' handler
488 * @netdev: network interface device structure
489 *
490 * This is used by netconsole to send skbs without having to re-enable
491 * interrupts. It's not called while the normal interrupt routine is executing.
492 **/
493static void i40evf_netpoll(struct net_device *netdev)
494{
495 struct i40evf_adapter *adapter = netdev_priv(netdev);
496 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
497 int i;
498
499 /* if interface is down do nothing */
500 if (test_bit(__I40E_DOWN, &adapter->vsi.state))
501 return;
502
503 for (i = 0; i < q_vectors; i++)
Mitch Williams7d96ba12015-10-26 19:44:39 -0400504 i40evf_msix_clean_rings(0, &adapter->q_vectors[i]);
Alexander Duyck7709b4c2015-09-24 09:04:38 -0700505}
506
507#endif
Greg Rose5eae00c2013-12-21 06:12:45 +0000508/**
Alan Brady96db7762016-09-14 16:24:38 -0700509 * i40evf_irq_affinity_notify - Callback for affinity changes
510 * @notify: context as to what irq was changed
511 * @mask: the new affinity mask
512 *
513 * This is a callback function used by the irq_set_affinity_notifier function
514 * so that we may register to receive changes to the irq affinity masks.
515 **/
516static void i40evf_irq_affinity_notify(struct irq_affinity_notify *notify,
517 const cpumask_t *mask)
518{
519 struct i40e_q_vector *q_vector =
520 container_of(notify, struct i40e_q_vector, affinity_notify);
521
522 q_vector->affinity_mask = *mask;
523}
524
525/**
526 * i40evf_irq_affinity_release - Callback for affinity notifier release
527 * @ref: internal core kernel usage
528 *
529 * This is a callback function used by the irq_set_affinity_notifier function
530 * to inform the current notification subscriber that they will no longer
531 * receive notifications.
532 **/
533static void i40evf_irq_affinity_release(struct kref *ref) {}
534
535/**
Greg Rose5eae00c2013-12-21 06:12:45 +0000536 * i40evf_request_traffic_irqs - Initialize MSI-X interrupts
537 * @adapter: board private structure
538 *
539 * Allocates MSI-X vectors for tx and rx handling, and requests
540 * interrupts from the kernel.
541 **/
542static int
543i40evf_request_traffic_irqs(struct i40evf_adapter *adapter, char *basename)
544{
545 int vector, err, q_vectors;
546 int rx_int_idx = 0, tx_int_idx = 0;
Alan Brady96db7762016-09-14 16:24:38 -0700547 int irq_num;
Greg Rose5eae00c2013-12-21 06:12:45 +0000548
549 i40evf_irq_disable(adapter);
550 /* Decrement for Other and TCP Timer vectors */
551 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
552
553 for (vector = 0; vector < q_vectors; vector++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -0400554 struct i40e_q_vector *q_vector = &adapter->q_vectors[vector];
Alan Brady96db7762016-09-14 16:24:38 -0700555 irq_num = adapter->msix_entries[vector + NONQ_VECS].vector;
Greg Rose5eae00c2013-12-21 06:12:45 +0000556
557 if (q_vector->tx.ring && q_vector->rx.ring) {
558 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
559 "i40evf-%s-%s-%d", basename,
560 "TxRx", rx_int_idx++);
561 tx_int_idx++;
562 } else if (q_vector->rx.ring) {
563 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
564 "i40evf-%s-%s-%d", basename,
565 "rx", rx_int_idx++);
566 } else if (q_vector->tx.ring) {
567 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
568 "i40evf-%s-%s-%d", basename,
569 "tx", tx_int_idx++);
570 } else {
571 /* skip this unused q_vector */
572 continue;
573 }
Alan Brady96db7762016-09-14 16:24:38 -0700574 err = request_irq(irq_num,
575 i40evf_msix_clean_rings,
576 0,
577 q_vector->name,
578 q_vector);
Greg Rose5eae00c2013-12-21 06:12:45 +0000579 if (err) {
580 dev_info(&adapter->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400581 "Request_irq failed, error: %d\n", err);
Greg Rose5eae00c2013-12-21 06:12:45 +0000582 goto free_queue_irqs;
583 }
Alan Brady96db7762016-09-14 16:24:38 -0700584 /* register for affinity change notifications */
585 q_vector->affinity_notify.notify = i40evf_irq_affinity_notify;
586 q_vector->affinity_notify.release =
587 i40evf_irq_affinity_release;
588 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
Greg Rose5eae00c2013-12-21 06:12:45 +0000589 /* assign the mask for this irq */
Alan Brady96db7762016-09-14 16:24:38 -0700590 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
Greg Rose5eae00c2013-12-21 06:12:45 +0000591 }
592
593 return 0;
594
595free_queue_irqs:
596 while (vector) {
597 vector--;
Alan Brady96db7762016-09-14 16:24:38 -0700598 irq_num = adapter->msix_entries[vector + NONQ_VECS].vector;
599 irq_set_affinity_notifier(irq_num, NULL);
600 irq_set_affinity_hint(irq_num, NULL);
601 free_irq(irq_num, &adapter->q_vectors[vector]);
Greg Rose5eae00c2013-12-21 06:12:45 +0000602 }
603 return err;
604}
605
606/**
607 * i40evf_request_misc_irq - Initialize MSI-X interrupts
608 * @adapter: board private structure
609 *
610 * Allocates MSI-X vector 0 and requests interrupts from the kernel. This
611 * vector is only for the admin queue, and stays active even when the netdev
612 * is closed.
613 **/
614static int i40evf_request_misc_irq(struct i40evf_adapter *adapter)
615{
616 struct net_device *netdev = adapter->netdev;
617 int err;
618
Jesse Brandeburgb39c1e22014-08-01 13:27:08 -0700619 snprintf(adapter->misc_vector_name,
Carolyn Wyborny9a21a002015-02-06 08:52:20 +0000620 sizeof(adapter->misc_vector_name) - 1, "i40evf-%s:mbx",
621 dev_name(&adapter->pdev->dev));
Greg Rose5eae00c2013-12-21 06:12:45 +0000622 err = request_irq(adapter->msix_entries[0].vector,
Mitch Williamse1dfee82014-02-13 03:48:51 -0800623 &i40evf_msix_aq, 0,
624 adapter->misc_vector_name, netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +0000625 if (err) {
626 dev_err(&adapter->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -0800627 "request_irq for %s failed: %d\n",
628 adapter->misc_vector_name, err);
Greg Rose5eae00c2013-12-21 06:12:45 +0000629 free_irq(adapter->msix_entries[0].vector, netdev);
630 }
631 return err;
632}
633
634/**
635 * i40evf_free_traffic_irqs - Free MSI-X interrupts
636 * @adapter: board private structure
637 *
638 * Frees all MSI-X vectors other than 0.
639 **/
640static void i40evf_free_traffic_irqs(struct i40evf_adapter *adapter)
641{
Alan Brady96db7762016-09-14 16:24:38 -0700642 int vector, irq_num, q_vectors;
Mitch Williams75a64432014-11-11 20:02:42 +0000643
Alan Brady47d2a5d2016-11-08 13:05:05 -0800644 if (!adapter->msix_entries)
645 return;
646
Greg Rose5eae00c2013-12-21 06:12:45 +0000647 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
648
Alan Brady96db7762016-09-14 16:24:38 -0700649 for (vector = 0; vector < q_vectors; vector++) {
650 irq_num = adapter->msix_entries[vector + NONQ_VECS].vector;
651 irq_set_affinity_notifier(irq_num, NULL);
652 irq_set_affinity_hint(irq_num, NULL);
653 free_irq(irq_num, &adapter->q_vectors[vector]);
Greg Rose5eae00c2013-12-21 06:12:45 +0000654 }
655}
656
657/**
658 * i40evf_free_misc_irq - Free MSI-X miscellaneous vector
659 * @adapter: board private structure
660 *
661 * Frees MSI-X vector 0.
662 **/
663static void i40evf_free_misc_irq(struct i40evf_adapter *adapter)
664{
665 struct net_device *netdev = adapter->netdev;
666
Jacob Kelleref4603e2016-11-08 13:05:08 -0800667 if (!adapter->msix_entries)
668 return;
669
Greg Rose5eae00c2013-12-21 06:12:45 +0000670 free_irq(adapter->msix_entries[0].vector, netdev);
671}
672
673/**
674 * i40evf_configure_tx - Configure Transmit Unit after Reset
675 * @adapter: board private structure
676 *
677 * Configure the Tx unit of the MAC after a reset.
678 **/
679static void i40evf_configure_tx(struct i40evf_adapter *adapter)
680{
681 struct i40e_hw *hw = &adapter->hw;
682 int i;
Mitch Williams75a64432014-11-11 20:02:42 +0000683
Mitch Williamscc052922014-10-25 03:24:34 +0000684 for (i = 0; i < adapter->num_active_queues; i++)
Mitch Williams0dd438d2015-10-26 19:44:40 -0400685 adapter->tx_rings[i].tail = hw->hw_addr + I40E_QTX_TAIL1(i);
Greg Rose5eae00c2013-12-21 06:12:45 +0000686}
687
688/**
689 * i40evf_configure_rx - Configure Receive Unit after Reset
690 * @adapter: board private structure
691 *
692 * Configure the Rx unit of the MAC after a reset.
693 **/
694static void i40evf_configure_rx(struct i40evf_adapter *adapter)
695{
Alexander Duyckdab86af2017-03-14 10:15:27 -0700696 unsigned int rx_buf_len = I40E_RXBUFFER_2048;
697 struct net_device *netdev = adapter->netdev;
Greg Rose5eae00c2013-12-21 06:12:45 +0000698 struct i40e_hw *hw = &adapter->hw;
Greg Rose5eae00c2013-12-21 06:12:45 +0000699 int i;
Greg Rose5eae00c2013-12-21 06:12:45 +0000700
Alexander Duyckdab86af2017-03-14 10:15:27 -0700701 /* Legacy Rx will always default to a 2048 buffer size. */
702#if (PAGE_SIZE < 8192)
703 if (!(adapter->flags & I40EVF_FLAG_LEGACY_RX)) {
Alexander Duyck98efd692017-04-05 07:51:01 -0400704 /* For jumbo frames on systems with 4K pages we have to use
705 * an order 1 page, so we might as well increase the size
706 * of our Rx buffer to make better use of the available space
707 */
708 rx_buf_len = I40E_RXBUFFER_3072;
709
Alexander Duyckdab86af2017-03-14 10:15:27 -0700710 /* We use a 1536 buffer size for configurations with
711 * standard Ethernet mtu. On x86 this gives us enough room
712 * for shared info and 192 bytes of padding.
713 */
Alexander Duyckca9ec082017-04-05 07:51:02 -0400714 if (!I40E_2K_TOO_SMALL_WITH_PADDING &&
715 (netdev->mtu <= ETH_DATA_LEN))
Alexander Duyckdab86af2017-03-14 10:15:27 -0700716 rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
717 }
718#endif
719
Mitch Williamscc052922014-10-25 03:24:34 +0000720 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williams0dd438d2015-10-26 19:44:40 -0400721 adapter->rx_rings[i].tail = hw->hw_addr + I40E_QRX_TAIL1(i);
Alexander Duyckdab86af2017-03-14 10:15:27 -0700722 adapter->rx_rings[i].rx_buf_len = rx_buf_len;
Alexander Duyckca9ec082017-04-05 07:51:02 -0400723
724 if (adapter->flags & I40EVF_FLAG_LEGACY_RX)
725 clear_ring_build_skb_enabled(&adapter->rx_rings[i]);
726 else
727 set_ring_build_skb_enabled(&adapter->rx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +0000728 }
729}
730
731/**
732 * i40evf_find_vlan - Search filter list for specific vlan filter
733 * @adapter: board private structure
734 * @vlan: vlan tag
735 *
736 * Returns ptr to the filter object or NULL
737 **/
738static struct
739i40evf_vlan_filter *i40evf_find_vlan(struct i40evf_adapter *adapter, u16 vlan)
740{
741 struct i40evf_vlan_filter *f;
742
743 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
744 if (vlan == f->vlan)
745 return f;
746 }
747 return NULL;
748}
749
750/**
751 * i40evf_add_vlan - Add a vlan filter to the list
752 * @adapter: board private structure
753 * @vlan: VLAN tag
754 *
755 * Returns ptr to the filter object or NULL when no memory available.
756 **/
757static struct
758i40evf_vlan_filter *i40evf_add_vlan(struct i40evf_adapter *adapter, u16 vlan)
759{
Mitch Williams13acb542015-03-31 00:45:05 -0700760 struct i40evf_vlan_filter *f = NULL;
761 int count = 50;
762
763 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
764 &adapter->crit_section)) {
765 udelay(1);
766 if (--count == 0)
767 goto out;
768 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000769
770 f = i40evf_find_vlan(adapter, vlan);
Mitch Williams348d4992014-11-11 20:02:52 +0000771 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000772 f = kzalloc(sizeof(*f), GFP_ATOMIC);
Mitch Williams348d4992014-11-11 20:02:52 +0000773 if (!f)
Mitch Williams13acb542015-03-31 00:45:05 -0700774 goto clearout;
Mitch Williams249c8b82014-05-10 04:49:04 +0000775
Greg Rose5eae00c2013-12-21 06:12:45 +0000776 f->vlan = vlan;
777
778 INIT_LIST_HEAD(&f->list);
779 list_add(&f->list, &adapter->vlan_filter_list);
780 f->add = true;
781 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
782 }
783
Mitch Williams13acb542015-03-31 00:45:05 -0700784clearout:
785 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
786out:
Greg Rose5eae00c2013-12-21 06:12:45 +0000787 return f;
788}
789
790/**
791 * i40evf_del_vlan - Remove a vlan filter from the list
792 * @adapter: board private structure
793 * @vlan: VLAN tag
794 **/
795static void i40evf_del_vlan(struct i40evf_adapter *adapter, u16 vlan)
796{
797 struct i40evf_vlan_filter *f;
Mitch Williams13acb542015-03-31 00:45:05 -0700798 int count = 50;
799
800 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
801 &adapter->crit_section)) {
802 udelay(1);
803 if (--count == 0)
804 return;
805 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000806
807 f = i40evf_find_vlan(adapter, vlan);
808 if (f) {
809 f->remove = true;
810 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
811 }
Mitch Williams13acb542015-03-31 00:45:05 -0700812 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Greg Rose5eae00c2013-12-21 06:12:45 +0000813}
814
815/**
816 * i40evf_vlan_rx_add_vid - Add a VLAN filter to a device
817 * @netdev: network device struct
818 * @vid: VLAN tag
819 **/
820static int i40evf_vlan_rx_add_vid(struct net_device *netdev,
Mitch Williams75a64432014-11-11 20:02:42 +0000821 __always_unused __be16 proto, u16 vid)
Greg Rose5eae00c2013-12-21 06:12:45 +0000822{
823 struct i40evf_adapter *adapter = netdev_priv(netdev);
824
Mitch Williams8ed995f2015-08-28 17:55:57 -0400825 if (!VLAN_ALLOWED(adapter))
826 return -EIO;
Greg Rose5eae00c2013-12-21 06:12:45 +0000827 if (i40evf_add_vlan(adapter, vid) == NULL)
828 return -ENOMEM;
829 return 0;
830}
831
832/**
833 * i40evf_vlan_rx_kill_vid - Remove a VLAN filter from a device
834 * @netdev: network device struct
835 * @vid: VLAN tag
836 **/
837static int i40evf_vlan_rx_kill_vid(struct net_device *netdev,
Mitch Williams75a64432014-11-11 20:02:42 +0000838 __always_unused __be16 proto, u16 vid)
Greg Rose5eae00c2013-12-21 06:12:45 +0000839{
840 struct i40evf_adapter *adapter = netdev_priv(netdev);
841
Mitch Williams8ed995f2015-08-28 17:55:57 -0400842 if (VLAN_ALLOWED(adapter)) {
843 i40evf_del_vlan(adapter, vid);
844 return 0;
845 }
846 return -EIO;
Greg Rose5eae00c2013-12-21 06:12:45 +0000847}
848
849/**
850 * i40evf_find_filter - Search filter list for specific mac filter
851 * @adapter: board private structure
852 * @macaddr: the MAC address
853 *
854 * Returns ptr to the filter object or NULL
855 **/
856static struct
857i40evf_mac_filter *i40evf_find_filter(struct i40evf_adapter *adapter,
858 u8 *macaddr)
859{
860 struct i40evf_mac_filter *f;
861
862 if (!macaddr)
863 return NULL;
864
865 list_for_each_entry(f, &adapter->mac_filter_list, list) {
866 if (ether_addr_equal(macaddr, f->macaddr))
867 return f;
868 }
869 return NULL;
870}
871
872/**
873 * i40e_add_filter - Add a mac filter to the filter list
874 * @adapter: board private structure
875 * @macaddr: the MAC address
876 *
877 * Returns ptr to the filter object or NULL when no memory available.
878 **/
879static struct
880i40evf_mac_filter *i40evf_add_filter(struct i40evf_adapter *adapter,
881 u8 *macaddr)
882{
883 struct i40evf_mac_filter *f;
Mitch Williams54e16f62015-01-29 07:17:20 +0000884 int count = 50;
Greg Rose5eae00c2013-12-21 06:12:45 +0000885
886 if (!macaddr)
887 return NULL;
888
889 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
Mitch Williams54e16f62015-01-29 07:17:20 +0000890 &adapter->crit_section)) {
Mitch Williamsb65476c2014-07-09 07:46:14 +0000891 udelay(1);
Mitch Williams54e16f62015-01-29 07:17:20 +0000892 if (--count == 0)
893 return NULL;
894 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000895
896 f = i40evf_find_filter(adapter, macaddr);
Mitch Williams348d4992014-11-11 20:02:52 +0000897 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000898 f = kzalloc(sizeof(*f), GFP_ATOMIC);
Mitch Williams348d4992014-11-11 20:02:52 +0000899 if (!f) {
Greg Rose5eae00c2013-12-21 06:12:45 +0000900 clear_bit(__I40EVF_IN_CRITICAL_TASK,
901 &adapter->crit_section);
902 return NULL;
903 }
904
Greg Rose9a173902014-05-22 06:32:02 +0000905 ether_addr_copy(f->macaddr, macaddr);
Greg Rose5eae00c2013-12-21 06:12:45 +0000906
Mitch Williams63590b62016-05-16 10:26:42 -0700907 list_add_tail(&f->list, &adapter->mac_filter_list);
Greg Rose5eae00c2013-12-21 06:12:45 +0000908 f->add = true;
909 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
910 }
911
912 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
913 return f;
914}
915
916/**
917 * i40evf_set_mac - NDO callback to set port mac address
918 * @netdev: network interface device structure
919 * @p: pointer to an address structure
920 *
921 * Returns 0 on success, negative on failure
922 **/
923static int i40evf_set_mac(struct net_device *netdev, void *p)
924{
925 struct i40evf_adapter *adapter = netdev_priv(netdev);
926 struct i40e_hw *hw = &adapter->hw;
927 struct i40evf_mac_filter *f;
928 struct sockaddr *addr = p;
929
930 if (!is_valid_ether_addr(addr->sa_data))
931 return -EADDRNOTAVAIL;
932
933 if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
934 return 0;
935
Mitch Williams14e52ee2015-08-31 19:54:44 -0400936 if (adapter->flags & I40EVF_FLAG_ADDR_SET_BY_PF)
937 return -EPERM;
938
939 f = i40evf_find_filter(adapter, hw->mac.addr);
940 if (f) {
941 f->remove = true;
942 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
943 }
944
Greg Rose5eae00c2013-12-21 06:12:45 +0000945 f = i40evf_add_filter(adapter, addr->sa_data);
946 if (f) {
Greg Rose9a173902014-05-22 06:32:02 +0000947 ether_addr_copy(hw->mac.addr, addr->sa_data);
948 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +0000949 }
950
951 return (f == NULL) ? -ENOMEM : 0;
952}
953
954/**
955 * i40evf_set_rx_mode - NDO callback to set the netdev filters
956 * @netdev: network interface device structure
957 **/
958static void i40evf_set_rx_mode(struct net_device *netdev)
959{
960 struct i40evf_adapter *adapter = netdev_priv(netdev);
961 struct i40evf_mac_filter *f, *ftmp;
962 struct netdev_hw_addr *uca;
963 struct netdev_hw_addr *mca;
Shannon Nelson2f41f332015-08-26 15:14:20 -0400964 struct netdev_hw_addr *ha;
Mitch Williams54e16f62015-01-29 07:17:20 +0000965 int count = 50;
Greg Rose5eae00c2013-12-21 06:12:45 +0000966
967 /* add addr if not already in the filter list */
968 netdev_for_each_uc_addr(uca, netdev) {
969 i40evf_add_filter(adapter, uca->addr);
970 }
971 netdev_for_each_mc_addr(mca, netdev) {
972 i40evf_add_filter(adapter, mca->addr);
973 }
974
975 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
Mitch Williams54e16f62015-01-29 07:17:20 +0000976 &adapter->crit_section)) {
Mitch Williamsb65476c2014-07-09 07:46:14 +0000977 udelay(1);
Mitch Williams54e16f62015-01-29 07:17:20 +0000978 if (--count == 0) {
979 dev_err(&adapter->pdev->dev,
980 "Failed to get lock in %s\n", __func__);
981 return;
982 }
983 }
Greg Rose5eae00c2013-12-21 06:12:45 +0000984 /* remove filter if not in netdev list */
985 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
Shannon Nelson2f41f332015-08-26 15:14:20 -0400986 netdev_for_each_mc_addr(mca, netdev)
987 if (ether_addr_equal(mca->addr, f->macaddr))
988 goto bottom_of_search_loop;
Greg Rose5eae00c2013-12-21 06:12:45 +0000989
Shannon Nelson2f41f332015-08-26 15:14:20 -0400990 netdev_for_each_uc_addr(uca, netdev)
991 if (ether_addr_equal(uca->addr, f->macaddr))
992 goto bottom_of_search_loop;
993
994 for_each_dev_addr(netdev, ha)
995 if (ether_addr_equal(ha->addr, f->macaddr))
996 goto bottom_of_search_loop;
997
998 if (ether_addr_equal(f->macaddr, adapter->hw.mac.addr))
999 goto bottom_of_search_loop;
1000
1001 /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
1002 f->remove = true;
1003 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
1004
1005bottom_of_search_loop:
1006 continue;
Greg Rose5eae00c2013-12-21 06:12:45 +00001007 }
Anjali Singhai Jain47d34832016-04-12 08:30:52 -07001008
1009 if (netdev->flags & IFF_PROMISC &&
1010 !(adapter->flags & I40EVF_FLAG_PROMISC_ON))
1011 adapter->aq_required |= I40EVF_FLAG_AQ_REQUEST_PROMISC;
1012 else if (!(netdev->flags & IFF_PROMISC) &&
1013 adapter->flags & I40EVF_FLAG_PROMISC_ON)
1014 adapter->aq_required |= I40EVF_FLAG_AQ_RELEASE_PROMISC;
1015
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -07001016 if (netdev->flags & IFF_ALLMULTI &&
1017 !(adapter->flags & I40EVF_FLAG_ALLMULTI_ON))
1018 adapter->aq_required |= I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
1019 else if (!(netdev->flags & IFF_ALLMULTI) &&
1020 adapter->flags & I40EVF_FLAG_ALLMULTI_ON)
1021 adapter->aq_required |= I40EVF_FLAG_AQ_RELEASE_ALLMULTI;
1022
Greg Rose5eae00c2013-12-21 06:12:45 +00001023 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1024}
1025
1026/**
1027 * i40evf_napi_enable_all - enable NAPI on all queue vectors
1028 * @adapter: board private structure
1029 **/
1030static void i40evf_napi_enable_all(struct i40evf_adapter *adapter)
1031{
1032 int q_idx;
1033 struct i40e_q_vector *q_vector;
1034 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1035
1036 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1037 struct napi_struct *napi;
Mitch Williams75a64432014-11-11 20:02:42 +00001038
Mitch Williams7d96ba12015-10-26 19:44:39 -04001039 q_vector = &adapter->q_vectors[q_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +00001040 napi = &q_vector->napi;
1041 napi_enable(napi);
1042 }
1043}
1044
1045/**
1046 * i40evf_napi_disable_all - disable NAPI on all queue vectors
1047 * @adapter: board private structure
1048 **/
1049static void i40evf_napi_disable_all(struct i40evf_adapter *adapter)
1050{
1051 int q_idx;
1052 struct i40e_q_vector *q_vector;
1053 int q_vectors = adapter->num_msix_vectors - NONQ_VECS;
1054
1055 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -04001056 q_vector = &adapter->q_vectors[q_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +00001057 napi_disable(&q_vector->napi);
1058 }
1059}
1060
1061/**
1062 * i40evf_configure - set up transmit and receive data structures
1063 * @adapter: board private structure
1064 **/
1065static void i40evf_configure(struct i40evf_adapter *adapter)
1066{
1067 struct net_device *netdev = adapter->netdev;
1068 int i;
1069
1070 i40evf_set_rx_mode(netdev);
1071
1072 i40evf_configure_tx(adapter);
1073 i40evf_configure_rx(adapter);
1074 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
1075
Mitch Williamscc052922014-10-25 03:24:34 +00001076 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williams0dd438d2015-10-26 19:44:40 -04001077 struct i40e_ring *ring = &adapter->rx_rings[i];
Mitch Williams75a64432014-11-11 20:02:42 +00001078
Mitch Williamsb1630982016-04-18 11:33:48 -07001079 i40evf_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
Greg Rose5eae00c2013-12-21 06:12:45 +00001080 }
1081}
1082
1083/**
1084 * i40evf_up_complete - Finish the last steps of bringing up a connection
1085 * @adapter: board private structure
1086 **/
Bimmy Pujaricb130a02016-09-06 18:05:03 -07001087static void i40evf_up_complete(struct i40evf_adapter *adapter)
Greg Rose5eae00c2013-12-21 06:12:45 +00001088{
1089 adapter->state = __I40EVF_RUNNING;
1090 clear_bit(__I40E_DOWN, &adapter->vsi.state);
1091
1092 i40evf_napi_enable_all(adapter);
1093
1094 adapter->aq_required |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
Mitch Williamsed0e8942017-01-24 10:23:59 -08001095 if (CLIENT_ENABLED(adapter))
1096 adapter->flags |= I40EVF_FLAG_CLIENT_NEEDS_OPEN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001097 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
Greg Rose5eae00c2013-12-21 06:12:45 +00001098}
1099
1100/**
Greg Rose5eae00c2013-12-21 06:12:45 +00001101 * i40e_down - Shutdown the connection processing
1102 * @adapter: board private structure
1103 **/
1104void i40evf_down(struct i40evf_adapter *adapter)
1105{
1106 struct net_device *netdev = adapter->netdev;
1107 struct i40evf_mac_filter *f;
1108
Mitch Williams209dc4d2015-12-09 15:50:27 -08001109 if (adapter->state <= __I40EVF_DOWN_PENDING)
Mitch Williamsddf0b3a2014-05-22 06:31:46 +00001110 return;
1111
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001112 while (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK,
1113 &adapter->crit_section))
1114 usleep_range(500, 1000);
1115
Mitch Williams63e18c22015-03-27 00:12:10 -07001116 netif_carrier_off(netdev);
1117 netif_tx_disable(netdev);
Sridhar Samudrala3f341ac2016-09-01 22:27:27 +02001118 adapter->link_up = false;
Mitch Williams748c4342015-01-29 07:17:18 +00001119 i40evf_napi_disable_all(adapter);
Mitch Williams63e18c22015-03-27 00:12:10 -07001120 i40evf_irq_disable(adapter);
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001121
Mitch Williamsef8693e2014-02-13 03:48:53 -08001122 /* remove all MAC filters */
Greg Rose5eae00c2013-12-21 06:12:45 +00001123 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1124 f->remove = true;
1125 }
Mitch Williamsed1f5b52014-02-20 19:29:06 -08001126 /* remove all VLAN filters */
1127 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
1128 f->remove = true;
1129 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001130 if (!(adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) &&
1131 adapter->state != __I40EVF_RESETTING) {
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001132 /* cancel any current operation */
1133 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001134 /* Schedule operations to close down the HW. Don't wait
1135 * here for this to complete. The watchdog is still running
1136 * and it will take care of this.
1137 */
1138 adapter->aq_required = I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Mitch Williamsed1f5b52014-02-20 19:29:06 -08001139 adapter->aq_required |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001140 adapter->aq_required |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001141 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001142
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00001143 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Greg Rose5eae00c2013-12-21 06:12:45 +00001144}
1145
1146/**
1147 * i40evf_acquire_msix_vectors - Setup the MSIX capability
1148 * @adapter: board private structure
1149 * @vectors: number of vectors to request
1150 *
1151 * Work with the OS to set up the MSIX vectors needed.
1152 *
1153 * Returns 0 on success, negative on failure
1154 **/
1155static int
1156i40evf_acquire_msix_vectors(struct i40evf_adapter *adapter, int vectors)
1157{
1158 int err, vector_threshold;
1159
1160 /* We'll want at least 3 (vector_threshold):
1161 * 0) Other (Admin Queue and link, mostly)
1162 * 1) TxQ[0] Cleanup
1163 * 2) RxQ[0] Cleanup
1164 */
1165 vector_threshold = MIN_MSIX_COUNT;
1166
1167 /* The more we get, the more we will assign to Tx/Rx Cleanup
1168 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
1169 * Right now, we simply care about how many we'll get; we'll
1170 * set them up later while requesting irq's.
1171 */
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001172 err = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
1173 vector_threshold, vectors);
1174 if (err < 0) {
Mitch Williams80e72892014-05-10 04:49:06 +00001175 dev_err(&adapter->pdev->dev, "Unable to allocate MSI-X interrupts\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001176 kfree(adapter->msix_entries);
1177 adapter->msix_entries = NULL;
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001178 return err;
Greg Rose5eae00c2013-12-21 06:12:45 +00001179 }
Alexander Gordeevfc2f2f52014-04-28 17:53:16 +00001180
1181 /* Adjust for only the vectors we'll use, which is minimum
1182 * of max_msix_q_vectors + NONQ_VECS, or the number of
1183 * vectors we were allocated.
1184 */
1185 adapter->num_msix_vectors = err;
1186 return 0;
Greg Rose5eae00c2013-12-21 06:12:45 +00001187}
1188
1189/**
1190 * i40evf_free_queues - Free memory for all rings
1191 * @adapter: board private structure to initialize
1192 *
1193 * Free all of the memory associated with queue pairs.
1194 **/
1195static void i40evf_free_queues(struct i40evf_adapter *adapter)
1196{
Greg Rose5eae00c2013-12-21 06:12:45 +00001197 if (!adapter->vsi_res)
1198 return;
Mitch Williams0dd438d2015-10-26 19:44:40 -04001199 kfree(adapter->tx_rings);
Mitch Williams10311542015-12-09 15:50:30 -08001200 adapter->tx_rings = NULL;
Mitch Williams0dd438d2015-10-26 19:44:40 -04001201 kfree(adapter->rx_rings);
Mitch Williams10311542015-12-09 15:50:30 -08001202 adapter->rx_rings = NULL;
Greg Rose5eae00c2013-12-21 06:12:45 +00001203}
1204
1205/**
1206 * i40evf_alloc_queues - Allocate memory for all rings
1207 * @adapter: board private structure to initialize
1208 *
1209 * We allocate one ring per queue at run-time since we don't know the
1210 * number of queues at compile-time. The polling_netdev array is
1211 * intended for Multiqueue, but should work fine with a single queue.
1212 **/
1213static int i40evf_alloc_queues(struct i40evf_adapter *adapter)
1214{
1215 int i;
1216
Mitch Williams0dd438d2015-10-26 19:44:40 -04001217 adapter->tx_rings = kcalloc(adapter->num_active_queues,
1218 sizeof(struct i40e_ring), GFP_KERNEL);
1219 if (!adapter->tx_rings)
1220 goto err_out;
1221 adapter->rx_rings = kcalloc(adapter->num_active_queues,
1222 sizeof(struct i40e_ring), GFP_KERNEL);
1223 if (!adapter->rx_rings)
1224 goto err_out;
1225
Mitch Williamscc052922014-10-25 03:24:34 +00001226 for (i = 0; i < adapter->num_active_queues; i++) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001227 struct i40e_ring *tx_ring;
1228 struct i40e_ring *rx_ring;
1229
Mitch Williams0dd438d2015-10-26 19:44:40 -04001230 tx_ring = &adapter->tx_rings[i];
Greg Rose5eae00c2013-12-21 06:12:45 +00001231
1232 tx_ring->queue_index = i;
1233 tx_ring->netdev = adapter->netdev;
1234 tx_ring->dev = &adapter->pdev->dev;
Mitch Williamsd732a182014-04-24 06:41:37 +00001235 tx_ring->count = adapter->tx_desc_count;
Jacob Keller65e87c02016-09-12 14:18:44 -07001236 tx_ring->tx_itr_setting = (I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF);
Anjali Singhai Jain1f012272015-09-03 17:18:53 -04001237 if (adapter->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
1238 tx_ring->flags |= I40E_TXR_FLAGS_WB_ON_ITR;
Greg Rose5eae00c2013-12-21 06:12:45 +00001239
Mitch Williams0dd438d2015-10-26 19:44:40 -04001240 rx_ring = &adapter->rx_rings[i];
Greg Rose5eae00c2013-12-21 06:12:45 +00001241 rx_ring->queue_index = i;
1242 rx_ring->netdev = adapter->netdev;
1243 rx_ring->dev = &adapter->pdev->dev;
Mitch Williamsd732a182014-04-24 06:41:37 +00001244 rx_ring->count = adapter->rx_desc_count;
Jacob Keller65e87c02016-09-12 14:18:44 -07001245 rx_ring->rx_itr_setting = (I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF);
Greg Rose5eae00c2013-12-21 06:12:45 +00001246 }
1247
1248 return 0;
1249
1250err_out:
1251 i40evf_free_queues(adapter);
1252 return -ENOMEM;
1253}
1254
1255/**
1256 * i40evf_set_interrupt_capability - set MSI-X or FAIL if not supported
1257 * @adapter: board private structure to initialize
1258 *
1259 * Attempt to configure the interrupts using the best available
1260 * capabilities of the hardware and the kernel.
1261 **/
1262static int i40evf_set_interrupt_capability(struct i40evf_adapter *adapter)
1263{
1264 int vector, v_budget;
1265 int pairs = 0;
1266 int err = 0;
1267
1268 if (!adapter->vsi_res) {
1269 err = -EIO;
1270 goto out;
1271 }
Mitch Williamscc052922014-10-25 03:24:34 +00001272 pairs = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +00001273
1274 /* It's easy to be greedy for MSI-X vectors, but it really
1275 * doesn't do us much good if we have a lot more vectors
1276 * than CPU's. So let's be conservative and only ask for
1277 * (roughly) twice the number of vectors as there are CPU's.
1278 */
Mitch Williams30a500e2014-02-11 08:27:52 +00001279 v_budget = min_t(int, pairs, (int)(num_online_cpus() * 2)) + NONQ_VECS;
1280 v_budget = min_t(int, v_budget, (int)adapter->vf_res->max_vectors);
Greg Rose5eae00c2013-12-21 06:12:45 +00001281
Greg Rose5eae00c2013-12-21 06:12:45 +00001282 adapter->msix_entries = kcalloc(v_budget,
1283 sizeof(struct msix_entry), GFP_KERNEL);
1284 if (!adapter->msix_entries) {
1285 err = -ENOMEM;
1286 goto out;
1287 }
1288
1289 for (vector = 0; vector < v_budget; vector++)
1290 adapter->msix_entries[vector].entry = vector;
1291
Mitch Williams313ed2d2015-08-27 11:42:31 -04001292 err = i40evf_acquire_msix_vectors(adapter, v_budget);
Greg Rose5eae00c2013-12-21 06:12:45 +00001293
1294out:
Mitch Williamse6c4cf62015-11-06 15:26:00 -08001295 netif_set_real_num_rx_queues(adapter->netdev, pairs);
1296 netif_set_real_num_tx_queues(adapter->netdev, pairs);
Greg Rose5eae00c2013-12-21 06:12:45 +00001297 return err;
1298}
1299
1300/**
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001301 * i40e_config_rss_aq - Configure RSS keys and lut by using AQ commands
1302 * @adapter: board private structure
Helin Zhang2c86ac32015-10-27 16:15:06 -04001303 *
1304 * Return 0 on success, negative on failure
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001305 **/
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001306static int i40evf_config_rss_aq(struct i40evf_adapter *adapter)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001307{
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001308 struct i40e_aqc_get_set_rss_key_data *rss_key =
1309 (struct i40e_aqc_get_set_rss_key_data *)adapter->rss_key;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001310 struct i40e_hw *hw = &adapter->hw;
Helin Zhang2c86ac32015-10-27 16:15:06 -04001311 int ret = 0;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001312
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001313 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
1314 /* bail because we already have a command pending */
Masanari Iidae3d132d2015-10-16 21:14:29 +09001315 dev_err(&adapter->pdev->dev, "Cannot configure RSS, command %d pending\n",
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001316 adapter->current_op);
Helin Zhang2c86ac32015-10-27 16:15:06 -04001317 return -EBUSY;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001318 }
1319
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001320 ret = i40evf_aq_set_rss_key(hw, adapter->vsi.id, rss_key);
1321 if (ret) {
1322 dev_err(&adapter->pdev->dev, "Cannot set RSS key, err %s aq_err %s\n",
1323 i40evf_stat_str(hw, ret),
1324 i40evf_aq_str(hw, hw->aq.asq_last_status));
1325 return ret;
1326
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001327 }
1328
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001329 ret = i40evf_aq_set_rss_lut(hw, adapter->vsi.id, false,
1330 adapter->rss_lut, adapter->rss_lut_size);
1331 if (ret) {
1332 dev_err(&adapter->pdev->dev, "Cannot set RSS lut, err %s aq_err %s\n",
1333 i40evf_stat_str(hw, ret),
1334 i40evf_aq_str(hw, hw->aq.asq_last_status));
Helin Zhang2c86ac32015-10-27 16:15:06 -04001335 }
1336
1337 return ret;
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001338
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001339}
1340
1341/**
Helin Zhang2c86ac32015-10-27 16:15:06 -04001342 * i40evf_config_rss_reg - Configure RSS keys and lut by writing registers
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001343 * @adapter: board private structure
Helin Zhang2c86ac32015-10-27 16:15:06 -04001344 *
1345 * Returns 0 on success, negative on failure
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001346 **/
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001347static int i40evf_config_rss_reg(struct i40evf_adapter *adapter)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001348{
1349 struct i40e_hw *hw = &adapter->hw;
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001350 u32 *dw;
Helin Zhang2c86ac32015-10-27 16:15:06 -04001351 u16 i;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001352
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001353 dw = (u32 *)adapter->rss_key;
1354 for (i = 0; i <= adapter->rss_key_size / 4; i++)
1355 wr32(hw, I40E_VFQF_HKEY(i), dw[i]);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001356
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001357 dw = (u32 *)adapter->rss_lut;
1358 for (i = 0; i <= adapter->rss_lut_size / 4; i++)
1359 wr32(hw, I40E_VFQF_HLUT(i), dw[i]);
Helin Zhang2c86ac32015-10-27 16:15:06 -04001360
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001361 i40e_flush(hw);
Helin Zhang2c86ac32015-10-27 16:15:06 -04001362
1363 return 0;
1364}
1365
1366/**
1367 * i40evf_config_rss - Configure RSS keys and lut
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001368 * @adapter: board private structure
Helin Zhang2c86ac32015-10-27 16:15:06 -04001369 *
1370 * Returns 0 on success, negative on failure
1371 **/
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001372int i40evf_config_rss(struct i40evf_adapter *adapter)
Helin Zhang2c86ac32015-10-27 16:15:06 -04001373{
Helin Zhang2c86ac32015-10-27 16:15:06 -04001374
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001375 if (RSS_PF(adapter)) {
1376 adapter->aq_required |= I40EVF_FLAG_AQ_SET_RSS_LUT |
1377 I40EVF_FLAG_AQ_SET_RSS_KEY;
1378 return 0;
1379 } else if (RSS_AQ(adapter)) {
1380 return i40evf_config_rss_aq(adapter);
1381 } else {
1382 return i40evf_config_rss_reg(adapter);
1383 }
Helin Zhang90b02b42015-10-26 19:44:33 -04001384}
1385
1386/**
Helin Zhang2c86ac32015-10-27 16:15:06 -04001387 * i40evf_fill_rss_lut - Fill the lut with default values
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001388 * @adapter: board private structure
Helin Zhang2c86ac32015-10-27 16:15:06 -04001389 **/
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001390static void i40evf_fill_rss_lut(struct i40evf_adapter *adapter)
Helin Zhang2c86ac32015-10-27 16:15:06 -04001391{
1392 u16 i;
1393
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001394 for (i = 0; i < adapter->rss_lut_size; i++)
1395 adapter->rss_lut[i] = i % adapter->num_active_queues;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001396}
1397
1398/**
Helin Zhang96a81982015-10-26 19:44:31 -04001399 * i40evf_init_rss - Prepare for RSS
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001400 * @adapter: board private structure
Helin Zhang2c86ac32015-10-27 16:15:06 -04001401 *
1402 * Return 0 on success, negative on failure
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001403 **/
Helin Zhang2c86ac32015-10-27 16:15:06 -04001404static int i40evf_init_rss(struct i40evf_adapter *adapter)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001405{
1406 struct i40e_hw *hw = &adapter->hw;
Helin Zhang2c86ac32015-10-27 16:15:06 -04001407 int ret;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001408
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001409 if (!RSS_PF(adapter)) {
1410 /* Enable PCTYPES for RSS, TCP/UDP with IPv4/IPv6 */
1411 if (adapter->vf_res->vf_offload_flags &
1412 I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
1413 adapter->hena = I40E_DEFAULT_RSS_HENA_EXPANDED;
1414 else
1415 adapter->hena = I40E_DEFAULT_RSS_HENA;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001416
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001417 wr32(hw, I40E_VFQF_HENA(0), (u32)adapter->hena);
1418 wr32(hw, I40E_VFQF_HENA(1), (u32)(adapter->hena >> 32));
1419 }
Helin Zhang66f9af852015-10-26 19:44:34 -04001420
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001421 i40evf_fill_rss_lut(adapter);
Helin Zhang66f9af852015-10-26 19:44:34 -04001422
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001423 netdev_rss_key_fill((void *)adapter->rss_key, adapter->rss_key_size);
1424 ret = i40evf_config_rss(adapter);
Helin Zhang2c86ac32015-10-27 16:15:06 -04001425
1426 return ret;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001427}
1428
1429/**
Greg Rose5eae00c2013-12-21 06:12:45 +00001430 * i40evf_alloc_q_vectors - Allocate memory for interrupt vectors
1431 * @adapter: board private structure to initialize
1432 *
1433 * We allocate one q_vector per queue interrupt. If allocation fails we
1434 * return -ENOMEM.
1435 **/
1436static int i40evf_alloc_q_vectors(struct i40evf_adapter *adapter)
1437{
Mitch Williams7d96ba12015-10-26 19:44:39 -04001438 int q_idx = 0, num_q_vectors;
Greg Rose5eae00c2013-12-21 06:12:45 +00001439 struct i40e_q_vector *q_vector;
1440
1441 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
Mitch Williams0dd438d2015-10-26 19:44:40 -04001442 adapter->q_vectors = kcalloc(num_q_vectors, sizeof(*q_vector),
Mitch Williams7d96ba12015-10-26 19:44:39 -04001443 GFP_KERNEL);
1444 if (!adapter->q_vectors)
Alan Cox311f23e2016-03-01 16:02:15 -08001445 return -ENOMEM;
Greg Rose5eae00c2013-12-21 06:12:45 +00001446
1447 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -04001448 q_vector = &adapter->q_vectors[q_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +00001449 q_vector->adapter = adapter;
1450 q_vector->vsi = &adapter->vsi;
1451 q_vector->v_idx = q_idx;
1452 netif_napi_add(adapter->netdev, &q_vector->napi,
Mitch Williams75a64432014-11-11 20:02:42 +00001453 i40evf_napi_poll, NAPI_POLL_WEIGHT);
Greg Rose5eae00c2013-12-21 06:12:45 +00001454 }
1455
1456 return 0;
Greg Rose5eae00c2013-12-21 06:12:45 +00001457}
1458
1459/**
1460 * i40evf_free_q_vectors - Free memory allocated for interrupt vectors
1461 * @adapter: board private structure to initialize
1462 *
1463 * This function frees the memory allocated to the q_vectors. In addition if
1464 * NAPI is enabled it will delete any references to the NAPI struct prior
1465 * to freeing the q_vector.
1466 **/
1467static void i40evf_free_q_vectors(struct i40evf_adapter *adapter)
1468{
1469 int q_idx, num_q_vectors;
1470 int napi_vectors;
1471
Jacob Kelleref4603e2016-11-08 13:05:08 -08001472 if (!adapter->q_vectors)
1473 return;
1474
Greg Rose5eae00c2013-12-21 06:12:45 +00001475 num_q_vectors = adapter->num_msix_vectors - NONQ_VECS;
Mitch Williamscc052922014-10-25 03:24:34 +00001476 napi_vectors = adapter->num_active_queues;
Greg Rose5eae00c2013-12-21 06:12:45 +00001477
1478 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -04001479 struct i40e_q_vector *q_vector = &adapter->q_vectors[q_idx];
Greg Rose5eae00c2013-12-21 06:12:45 +00001480 if (q_idx < napi_vectors)
1481 netif_napi_del(&q_vector->napi);
Greg Rose5eae00c2013-12-21 06:12:45 +00001482 }
Mitch Williams7d96ba12015-10-26 19:44:39 -04001483 kfree(adapter->q_vectors);
Jacob Kelleref4603e2016-11-08 13:05:08 -08001484 adapter->q_vectors = NULL;
Greg Rose5eae00c2013-12-21 06:12:45 +00001485}
1486
1487/**
1488 * i40evf_reset_interrupt_capability - Reset MSIX setup
1489 * @adapter: board private structure
1490 *
1491 **/
1492void i40evf_reset_interrupt_capability(struct i40evf_adapter *adapter)
1493{
Alan Brady47d2a5d2016-11-08 13:05:05 -08001494 if (!adapter->msix_entries)
1495 return;
1496
Greg Rose5eae00c2013-12-21 06:12:45 +00001497 pci_disable_msix(adapter->pdev);
1498 kfree(adapter->msix_entries);
1499 adapter->msix_entries = NULL;
Greg Rose5eae00c2013-12-21 06:12:45 +00001500}
1501
1502/**
1503 * i40evf_init_interrupt_scheme - Determine if MSIX is supported and init
1504 * @adapter: board private structure to initialize
1505 *
1506 **/
1507int i40evf_init_interrupt_scheme(struct i40evf_adapter *adapter)
1508{
1509 int err;
1510
Jacob Keller62fe2a82016-07-27 12:02:33 -07001511 rtnl_lock();
Greg Rose5eae00c2013-12-21 06:12:45 +00001512 err = i40evf_set_interrupt_capability(adapter);
Jacob Keller62fe2a82016-07-27 12:02:33 -07001513 rtnl_unlock();
Greg Rose5eae00c2013-12-21 06:12:45 +00001514 if (err) {
1515 dev_err(&adapter->pdev->dev,
1516 "Unable to setup interrupt capabilities\n");
1517 goto err_set_interrupt;
1518 }
1519
1520 err = i40evf_alloc_q_vectors(adapter);
1521 if (err) {
1522 dev_err(&adapter->pdev->dev,
1523 "Unable to allocate memory for queue vectors\n");
1524 goto err_alloc_q_vectors;
1525 }
1526
1527 err = i40evf_alloc_queues(adapter);
1528 if (err) {
1529 dev_err(&adapter->pdev->dev,
1530 "Unable to allocate memory for queues\n");
1531 goto err_alloc_queues;
1532 }
1533
1534 dev_info(&adapter->pdev->dev, "Multiqueue %s: Queue pair count = %u",
Mitch Williams75a64432014-11-11 20:02:42 +00001535 (adapter->num_active_queues > 1) ? "Enabled" : "Disabled",
1536 adapter->num_active_queues);
Greg Rose5eae00c2013-12-21 06:12:45 +00001537
1538 return 0;
1539err_alloc_queues:
1540 i40evf_free_q_vectors(adapter);
1541err_alloc_q_vectors:
1542 i40evf_reset_interrupt_capability(adapter);
1543err_set_interrupt:
1544 return err;
1545}
1546
1547/**
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001548 * i40evf_free_rss - Free memory used by RSS structs
1549 * @adapter: board private structure
Helin Zhang66f9af852015-10-26 19:44:34 -04001550 **/
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001551static void i40evf_free_rss(struct i40evf_adapter *adapter)
Helin Zhang66f9af852015-10-26 19:44:34 -04001552{
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001553 kfree(adapter->rss_key);
1554 adapter->rss_key = NULL;
Helin Zhang66f9af852015-10-26 19:44:34 -04001555
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001556 kfree(adapter->rss_lut);
1557 adapter->rss_lut = NULL;
Helin Zhang66f9af852015-10-26 19:44:34 -04001558}
1559
1560/**
Greg Rose5eae00c2013-12-21 06:12:45 +00001561 * i40evf_watchdog_timer - Periodic call-back timer
1562 * @data: pointer to adapter disguised as unsigned long
1563 **/
1564static void i40evf_watchdog_timer(unsigned long data)
1565{
1566 struct i40evf_adapter *adapter = (struct i40evf_adapter *)data;
Mitch Williams75a64432014-11-11 20:02:42 +00001567
Greg Rose5eae00c2013-12-21 06:12:45 +00001568 schedule_work(&adapter->watchdog_task);
1569 /* timer will be rescheduled in watchdog task */
1570}
1571
1572/**
1573 * i40evf_watchdog_task - Periodic call-back task
1574 * @work: pointer to work_struct
1575 **/
1576static void i40evf_watchdog_task(struct work_struct *work)
1577{
1578 struct i40evf_adapter *adapter = container_of(work,
Mitch Williams75a64432014-11-11 20:02:42 +00001579 struct i40evf_adapter,
1580 watchdog_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00001581 struct i40e_hw *hw = &adapter->hw;
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001582 u32 reg_val;
Greg Rose5eae00c2013-12-21 06:12:45 +00001583
Greg Rose5eae00c2013-12-21 06:12:45 +00001584 if (test_and_set_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section))
Mitch Williamsef8693e2014-02-13 03:48:53 -08001585 goto restart_watchdog;
1586
1587 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001588 reg_val = rd32(hw, I40E_VFGEN_RSTAT) &
1589 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1590 if ((reg_val == I40E_VFR_VFACTIVE) ||
1591 (reg_val == I40E_VFR_COMPLETED)) {
Mitch Williamsef8693e2014-02-13 03:48:53 -08001592 /* A chance for redemption! */
1593 dev_err(&adapter->pdev->dev, "Hardware came out of reset. Attempting reinit.\n");
1594 adapter->state = __I40EVF_STARTUP;
1595 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
1596 schedule_delayed_work(&adapter->init_task, 10);
1597 clear_bit(__I40EVF_IN_CRITICAL_TASK,
1598 &adapter->crit_section);
1599 /* Don't reschedule the watchdog, since we've restarted
1600 * the init task. When init_task contacts the PF and
1601 * gets everything set up again, it'll restart the
1602 * watchdog for us. Down, boy. Sit. Stay. Woof.
1603 */
1604 return;
1605 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001606 adapter->aq_required = 0;
1607 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1608 goto watchdog_done;
1609 }
1610
1611 if ((adapter->state < __I40EVF_DOWN) ||
1612 (adapter->flags & I40EVF_FLAG_RESET_PENDING))
Greg Rose5eae00c2013-12-21 06:12:45 +00001613 goto watchdog_done;
1614
Mitch Williamsef8693e2014-02-13 03:48:53 -08001615 /* check for reset */
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001616 reg_val = rd32(hw, I40E_VF_ARQLEN1) & I40E_VF_ARQLEN1_ARQENABLE_MASK;
1617 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING) && !reg_val) {
Greg Rose5eae00c2013-12-21 06:12:45 +00001618 adapter->state = __I40EVF_RESETTING;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001619 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
Mitch Williams249c8b82014-05-10 04:49:04 +00001620 dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001621 schedule_work(&adapter->reset_task);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001622 adapter->aq_required = 0;
1623 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001624 goto watchdog_done;
1625 }
1626
1627 /* Process admin queue tasks. After init, everything gets done
1628 * here so we don't race on the admin queue.
1629 */
Mitch Williamsed636962015-04-07 19:45:32 -04001630 if (adapter->current_op) {
Mitch A Williams0758e7cb2014-12-09 08:53:08 +00001631 if (!i40evf_asq_done(hw)) {
1632 dev_dbg(&adapter->pdev->dev, "Admin queue timeout\n");
1633 i40evf_send_api_ver(adapter);
1634 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001635 goto watchdog_done;
Mitch A Williams0758e7cb2014-12-09 08:53:08 +00001636 }
Mitch Williamse6d038d2015-06-04 16:23:58 -04001637 if (adapter->aq_required & I40EVF_FLAG_AQ_GET_CONFIG) {
1638 i40evf_send_vf_config_msg(adapter);
1639 goto watchdog_done;
1640 }
Greg Rose5eae00c2013-12-21 06:12:45 +00001641
Mitch Williamse284fc82015-03-27 00:12:09 -07001642 if (adapter->aq_required & I40EVF_FLAG_AQ_DISABLE_QUEUES) {
1643 i40evf_disable_queues(adapter);
1644 goto watchdog_done;
1645 }
1646
Greg Rose5eae00c2013-12-21 06:12:45 +00001647 if (adapter->aq_required & I40EVF_FLAG_AQ_MAP_VECTORS) {
1648 i40evf_map_queues(adapter);
1649 goto watchdog_done;
1650 }
1651
1652 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_MAC_FILTER) {
1653 i40evf_add_ether_addrs(adapter);
1654 goto watchdog_done;
1655 }
1656
1657 if (adapter->aq_required & I40EVF_FLAG_AQ_ADD_VLAN_FILTER) {
1658 i40evf_add_vlans(adapter);
1659 goto watchdog_done;
1660 }
1661
1662 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_MAC_FILTER) {
1663 i40evf_del_ether_addrs(adapter);
1664 goto watchdog_done;
1665 }
1666
1667 if (adapter->aq_required & I40EVF_FLAG_AQ_DEL_VLAN_FILTER) {
1668 i40evf_del_vlans(adapter);
1669 goto watchdog_done;
1670 }
1671
Greg Rose5eae00c2013-12-21 06:12:45 +00001672 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_QUEUES) {
1673 i40evf_configure_queues(adapter);
1674 goto watchdog_done;
1675 }
1676
1677 if (adapter->aq_required & I40EVF_FLAG_AQ_ENABLE_QUEUES) {
1678 i40evf_enable_queues(adapter);
1679 goto watchdog_done;
1680 }
1681
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001682 if (adapter->aq_required & I40EVF_FLAG_AQ_CONFIGURE_RSS) {
1683 /* This message goes straight to the firmware, not the
1684 * PF, so we don't have to set current_op as we will
1685 * not get a response through the ARQ.
1686 */
Helin Zhang96a81982015-10-26 19:44:31 -04001687 i40evf_init_rss(adapter);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001688 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_RSS;
1689 goto watchdog_done;
1690 }
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001691 if (adapter->aq_required & I40EVF_FLAG_AQ_GET_HENA) {
1692 i40evf_get_hena(adapter);
1693 goto watchdog_done;
1694 }
1695 if (adapter->aq_required & I40EVF_FLAG_AQ_SET_HENA) {
1696 i40evf_set_hena(adapter);
1697 goto watchdog_done;
1698 }
1699 if (adapter->aq_required & I40EVF_FLAG_AQ_SET_RSS_KEY) {
1700 i40evf_set_rss_key(adapter);
1701 goto watchdog_done;
1702 }
1703 if (adapter->aq_required & I40EVF_FLAG_AQ_SET_RSS_LUT) {
1704 i40evf_set_rss_lut(adapter);
1705 goto watchdog_done;
1706 }
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001707
Anjali Singhai Jain47d34832016-04-12 08:30:52 -07001708 if (adapter->aq_required & I40EVF_FLAG_AQ_REQUEST_PROMISC) {
1709 i40evf_set_promiscuous(adapter, I40E_FLAG_VF_UNICAST_PROMISC |
1710 I40E_FLAG_VF_MULTICAST_PROMISC);
1711 goto watchdog_done;
1712 }
1713
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -07001714 if (adapter->aq_required & I40EVF_FLAG_AQ_REQUEST_ALLMULTI) {
1715 i40evf_set_promiscuous(adapter, I40E_FLAG_VF_MULTICAST_PROMISC);
1716 goto watchdog_done;
1717 }
1718
1719 if ((adapter->aq_required & I40EVF_FLAG_AQ_RELEASE_PROMISC) &&
1720 (adapter->aq_required & I40EVF_FLAG_AQ_RELEASE_ALLMULTI)) {
Anjali Singhai Jain47d34832016-04-12 08:30:52 -07001721 i40evf_set_promiscuous(adapter, 0);
1722 goto watchdog_done;
1723 }
Mitch Williamsed0e8942017-01-24 10:23:59 -08001724 schedule_delayed_work(&adapter->client_task, msecs_to_jiffies(5));
Anjali Singhai Jain47d34832016-04-12 08:30:52 -07001725
Greg Rose5eae00c2013-12-21 06:12:45 +00001726 if (adapter->state == __I40EVF_RUNNING)
1727 i40evf_request_stats(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001728watchdog_done:
Mitch A Williams4870e172014-12-09 08:53:06 +00001729 if (adapter->state == __I40EVF_RUNNING) {
1730 i40evf_irq_enable_queues(adapter, ~0);
1731 i40evf_fire_sw_int(adapter, 0xFF);
1732 } else {
1733 i40evf_fire_sw_int(adapter, 0x1);
1734 }
1735
Mitch Williamsef8693e2014-02-13 03:48:53 -08001736 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1737restart_watchdog:
Ashish Shahd3e2edb2014-08-01 13:27:12 -07001738 if (adapter->state == __I40EVF_REMOVE)
1739 return;
Greg Rose5eae00c2013-12-21 06:12:45 +00001740 if (adapter->aq_required)
1741 mod_timer(&adapter->watchdog_timer,
1742 jiffies + msecs_to_jiffies(20));
1743 else
1744 mod_timer(&adapter->watchdog_timer, jiffies + (HZ * 2));
Greg Rose5eae00c2013-12-21 06:12:45 +00001745 schedule_work(&adapter->adminq_task);
1746}
1747
Joe Perchesdedecb62016-11-01 15:35:14 -07001748static void i40evf_disable_vf(struct i40evf_adapter *adapter)
1749{
1750 struct i40evf_mac_filter *f, *ftmp;
1751 struct i40evf_vlan_filter *fv, *fvtmp;
1752
1753 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
1754
1755 if (netif_running(adapter->netdev)) {
1756 set_bit(__I40E_DOWN, &adapter->vsi.state);
1757 netif_carrier_off(adapter->netdev);
1758 netif_tx_disable(adapter->netdev);
1759 adapter->link_up = false;
1760 i40evf_napi_disable_all(adapter);
1761 i40evf_irq_disable(adapter);
1762 i40evf_free_traffic_irqs(adapter);
1763 i40evf_free_all_tx_resources(adapter);
1764 i40evf_free_all_rx_resources(adapter);
1765 }
1766
1767 /* Delete all of the filters, both MAC and VLAN. */
1768 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
1769 list_del(&f->list);
1770 kfree(f);
1771 }
1772
1773 list_for_each_entry_safe(fv, fvtmp, &adapter->vlan_filter_list, list) {
1774 list_del(&fv->list);
1775 kfree(fv);
1776 }
1777
1778 i40evf_free_misc_irq(adapter);
1779 i40evf_reset_interrupt_capability(adapter);
1780 i40evf_free_queues(adapter);
1781 i40evf_free_q_vectors(adapter);
1782 kfree(adapter->vf_res);
1783 i40evf_shutdown_adminq(&adapter->hw);
1784 adapter->netdev->flags &= ~IFF_UP;
1785 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
1786 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1787 adapter->state = __I40EVF_DOWN;
1788 dev_info(&adapter->pdev->dev, "Reset task did not complete, VF disabled\n");
1789}
1790
Mitch Williams67c818a2015-06-19 08:56:30 -07001791#define I40EVF_RESET_WAIT_MS 10
1792#define I40EVF_RESET_WAIT_COUNT 500
Greg Rose5eae00c2013-12-21 06:12:45 +00001793/**
1794 * i40evf_reset_task - Call-back task to handle hardware reset
1795 * @work: pointer to work_struct
1796 *
1797 * During reset we need to shut down and reinitialize the admin queue
1798 * before we can use it to communicate with the PF again. We also clear
1799 * and reinit the rings because that context is lost as well.
1800 **/
1801static void i40evf_reset_task(struct work_struct *work)
1802{
Mitch Williamsef8693e2014-02-13 03:48:53 -08001803 struct i40evf_adapter *adapter = container_of(work,
1804 struct i40evf_adapter,
1805 reset_task);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001806 struct net_device *netdev = adapter->netdev;
Greg Rose5eae00c2013-12-21 06:12:45 +00001807 struct i40e_hw *hw = &adapter->hw;
Mitch Williams40d01362015-10-01 14:37:37 -04001808 struct i40evf_vlan_filter *vlf;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001809 struct i40evf_mac_filter *f;
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001810 u32 reg_val;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001811 int i = 0, err;
Greg Rose5eae00c2013-12-21 06:12:45 +00001812
Mitch Williamsed0e8942017-01-24 10:23:59 -08001813 while (test_and_set_bit(__I40EVF_IN_CLIENT_TASK,
Greg Rose5eae00c2013-12-21 06:12:45 +00001814 &adapter->crit_section))
Neerav Parikhf98a2002014-09-13 07:40:44 +00001815 usleep_range(500, 1000);
Mitch Williamsed0e8942017-01-24 10:23:59 -08001816 if (CLIENT_ENABLED(adapter)) {
1817 adapter->flags &= ~(I40EVF_FLAG_CLIENT_NEEDS_OPEN |
1818 I40EVF_FLAG_CLIENT_NEEDS_CLOSE |
1819 I40EVF_FLAG_CLIENT_NEEDS_L2_PARAMS |
1820 I40EVF_FLAG_SERVICE_CLIENT_REQUESTED);
1821 cancel_delayed_work_sync(&adapter->client_task);
1822 i40evf_notify_client_close(&adapter->vsi, true);
1823 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001824 i40evf_misc_irq_disable(adapter);
Mitch Williams3526d802014-03-06 08:59:56 +00001825 if (adapter->flags & I40EVF_FLAG_RESET_NEEDED) {
Mitch Williams67c818a2015-06-19 08:56:30 -07001826 adapter->flags &= ~I40EVF_FLAG_RESET_NEEDED;
1827 /* Restart the AQ here. If we have been reset but didn't
1828 * detect it, or if the PF had to reinit, our AQ will be hosed.
1829 */
1830 i40evf_shutdown_adminq(hw);
1831 i40evf_init_adminq(hw);
Mitch Williams3526d802014-03-06 08:59:56 +00001832 i40evf_request_reset(adapter);
1833 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001834 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
Mitch Williams3526d802014-03-06 08:59:56 +00001835
Mitch Williamsef8693e2014-02-13 03:48:53 -08001836 /* poll until we see the reset actually happen */
1837 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001838 reg_val = rd32(hw, I40E_VF_ARQLEN1) &
1839 I40E_VF_ARQLEN1_ARQENABLE_MASK;
1840 if (!reg_val)
Greg Rose5eae00c2013-12-21 06:12:45 +00001841 break;
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001842 usleep_range(5000, 10000);
Greg Rose5eae00c2013-12-21 06:12:45 +00001843 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001844 if (i == I40EVF_RESET_WAIT_COUNT) {
Mitch Williams67c818a2015-06-19 08:56:30 -07001845 dev_info(&adapter->pdev->dev, "Never saw reset\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08001846 goto continue_reset; /* act like the reset happened */
1847 }
1848
1849 /* wait until the reset is complete and the PF is responding to us */
1850 for (i = 0; i < I40EVF_RESET_WAIT_COUNT; i++) {
Jacob Keller7d3f04a2016-10-05 09:30:45 -07001851 /* sleep first to make sure a minimum wait time is met */
1852 msleep(I40EVF_RESET_WAIT_MS);
1853
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001854 reg_val = rd32(hw, I40E_VFGEN_RSTAT) &
1855 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
1856 if (reg_val == I40E_VFR_VFACTIVE)
Mitch Williamsef8693e2014-02-13 03:48:53 -08001857 break;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001858 }
Jacob Keller7d3f04a2016-10-05 09:30:45 -07001859
Mitch Williams509a4472015-12-23 12:05:52 -08001860 pci_set_master(adapter->pdev);
Jacob Keller7d3f04a2016-10-05 09:30:45 -07001861
Mitch Williamsef8693e2014-02-13 03:48:53 -08001862 if (i == I40EVF_RESET_WAIT_COUNT) {
Mitch Williams80e72892014-05-10 04:49:06 +00001863 dev_err(&adapter->pdev->dev, "Reset never finished (%x)\n",
Mitch Williamsee5c1e92015-08-28 17:55:53 -04001864 reg_val);
Joe Perchesdedecb62016-11-01 15:35:14 -07001865 i40evf_disable_vf(adapter);
Mitch Williamsed0e8942017-01-24 10:23:59 -08001866 clear_bit(__I40EVF_IN_CLIENT_TASK, &adapter->crit_section);
Mitch Williamsef8693e2014-02-13 03:48:53 -08001867 return; /* Do not attempt to reinit. It's dead, Jim. */
Greg Rose5eae00c2013-12-21 06:12:45 +00001868 }
Mitch Williamsef8693e2014-02-13 03:48:53 -08001869
1870continue_reset:
Mitch Williams67c818a2015-06-19 08:56:30 -07001871 if (netif_running(adapter->netdev)) {
1872 netif_carrier_off(netdev);
1873 netif_tx_stop_all_queues(netdev);
Sridhar Samudrala3f341ac2016-09-01 22:27:27 +02001874 adapter->link_up = false;
Mitch Williams67c818a2015-06-19 08:56:30 -07001875 i40evf_napi_disable_all(adapter);
1876 }
Mitch Williamsac833bb2015-01-29 07:17:19 +00001877 i40evf_irq_disable(adapter);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001878
Greg Rose5eae00c2013-12-21 06:12:45 +00001879 adapter->state = __I40EVF_RESETTING;
Mitch Williams67c818a2015-06-19 08:56:30 -07001880 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
1881
1882 /* free the Tx/Rx rings and descriptors, might be better to just
1883 * re-use them sometime in the future
1884 */
1885 i40evf_free_all_rx_resources(adapter);
1886 i40evf_free_all_tx_resources(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001887
1888 /* kill and reinit the admin queue */
Lihong Yang903e6832016-09-06 18:05:05 -07001889 i40evf_shutdown_adminq(hw);
Mitch Williamsac833bb2015-01-29 07:17:19 +00001890 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001891 err = i40evf_init_adminq(hw);
1892 if (err)
Mitch Williamsac833bb2015-01-29 07:17:19 +00001893 dev_info(&adapter->pdev->dev, "Failed to init adminq: %d\n",
1894 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00001895
Mitch Williamse6d038d2015-06-04 16:23:58 -04001896 adapter->aq_required = I40EVF_FLAG_AQ_GET_CONFIG;
1897 adapter->aq_required |= I40EVF_FLAG_AQ_MAP_VECTORS;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001898
1899 /* re-add all MAC filters */
1900 list_for_each_entry(f, &adapter->mac_filter_list, list) {
1901 f->add = true;
1902 }
1903 /* re-add all VLAN filters */
Mitch Williams40d01362015-10-01 14:37:37 -04001904 list_for_each_entry(vlf, &adapter->vlan_filter_list, list) {
1905 vlf->add = true;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001906 }
Mitch Williamse6d038d2015-06-04 16:23:58 -04001907 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
Mitch Williamsac833bb2015-01-29 07:17:19 +00001908 adapter->aq_required |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
Greg Rose5eae00c2013-12-21 06:12:45 +00001909 clear_bit(__I40EVF_IN_CRITICAL_TASK, &adapter->crit_section);
Mitch Williamsed0e8942017-01-24 10:23:59 -08001910 clear_bit(__I40EVF_IN_CLIENT_TASK, &adapter->crit_section);
Mitch Williams67c818a2015-06-19 08:56:30 -07001911 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001912
1913 mod_timer(&adapter->watchdog_timer, jiffies + 2);
1914
1915 if (netif_running(adapter->netdev)) {
1916 /* allocate transmit descriptors */
1917 err = i40evf_setup_all_tx_resources(adapter);
1918 if (err)
1919 goto reset_err;
1920
1921 /* allocate receive descriptors */
1922 err = i40evf_setup_all_rx_resources(adapter);
1923 if (err)
1924 goto reset_err;
1925
1926 i40evf_configure(adapter);
1927
Bimmy Pujaricb130a02016-09-06 18:05:03 -07001928 i40evf_up_complete(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00001929
1930 i40evf_irq_enable(adapter, true);
Mitch Williams67c818a2015-06-19 08:56:30 -07001931 } else {
1932 adapter->state = __I40EVF_DOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00001933 }
Mitch Williams67c818a2015-06-19 08:56:30 -07001934
Greg Rose5eae00c2013-12-21 06:12:45 +00001935 return;
1936reset_err:
Mitch Williams80e72892014-05-10 04:49:06 +00001937 dev_err(&adapter->pdev->dev, "failed to allocate resources during reinit\n");
Greg Rose5eae00c2013-12-21 06:12:45 +00001938 i40evf_close(adapter->netdev);
1939}
1940
1941/**
1942 * i40evf_adminq_task - worker thread to clean the admin queue
1943 * @work: pointer to work_struct containing our data
1944 **/
1945static void i40evf_adminq_task(struct work_struct *work)
1946{
1947 struct i40evf_adapter *adapter =
1948 container_of(work, struct i40evf_adapter, adminq_task);
1949 struct i40e_hw *hw = &adapter->hw;
1950 struct i40e_arq_event_info event;
1951 struct i40e_virtchnl_msg *v_msg;
1952 i40e_status ret;
Mitch Williams912257e2014-05-22 06:32:07 +00001953 u32 val, oldval;
Greg Rose5eae00c2013-12-21 06:12:45 +00001954 u16 pending;
1955
Mitch Williamsef8693e2014-02-13 03:48:53 -08001956 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
Mitch A Williams72354482014-12-09 08:53:07 +00001957 goto out;
Mitch Williamsef8693e2014-02-13 03:48:53 -08001958
Mitch Williams1001dc32014-11-11 20:02:19 +00001959 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
1960 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +00001961 if (!event.msg_buf)
Mitch A Williams72354482014-12-09 08:53:07 +00001962 goto out;
Mitch Williams249c8b82014-05-10 04:49:04 +00001963
Greg Rose5eae00c2013-12-21 06:12:45 +00001964 v_msg = (struct i40e_virtchnl_msg *)&event.desc;
1965 do {
1966 ret = i40evf_clean_arq_element(hw, &event, &pending);
Mitch Williams8b011eb2015-01-09 11:18:17 +00001967 if (ret || !v_msg->v_opcode)
Greg Rose5eae00c2013-12-21 06:12:45 +00001968 break; /* No event to process or error cleaning ARQ */
1969
1970 i40evf_virtchnl_completion(adapter, v_msg->v_opcode,
1971 v_msg->v_retval, event.msg_buf,
Mitch Williams1001dc32014-11-11 20:02:19 +00001972 event.msg_len);
Mitch Williams75a64432014-11-11 20:02:42 +00001973 if (pending != 0)
Greg Rose5eae00c2013-12-21 06:12:45 +00001974 memset(event.msg_buf, 0, I40EVF_MAX_AQ_BUF_SIZE);
Greg Rose5eae00c2013-12-21 06:12:45 +00001975 } while (pending);
1976
Mitch Williams67c818a2015-06-19 08:56:30 -07001977 if ((adapter->flags &
1978 (I40EVF_FLAG_RESET_PENDING | I40EVF_FLAG_RESET_NEEDED)) ||
1979 adapter->state == __I40EVF_RESETTING)
1980 goto freedom;
1981
Mitch Williams912257e2014-05-22 06:32:07 +00001982 /* check for error indications */
1983 val = rd32(hw, hw->aq.arq.len);
Mitch Williams19b73d82016-03-10 14:59:49 -08001984 if (val == 0xdeadbeef) /* indicates device in reset */
1985 goto freedom;
Mitch Williams912257e2014-05-22 06:32:07 +00001986 oldval = val;
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04001987 if (val & I40E_VF_ARQLEN1_ARQVFE_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00001988 dev_info(&adapter->pdev->dev, "ARQ VF Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04001989 val &= ~I40E_VF_ARQLEN1_ARQVFE_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00001990 }
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04001991 if (val & I40E_VF_ARQLEN1_ARQOVFL_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00001992 dev_info(&adapter->pdev->dev, "ARQ Overflow Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04001993 val &= ~I40E_VF_ARQLEN1_ARQOVFL_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00001994 }
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04001995 if (val & I40E_VF_ARQLEN1_ARQCRIT_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00001996 dev_info(&adapter->pdev->dev, "ARQ Critical Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04001997 val &= ~I40E_VF_ARQLEN1_ARQCRIT_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00001998 }
1999 if (oldval != val)
2000 wr32(hw, hw->aq.arq.len, val);
2001
2002 val = rd32(hw, hw->aq.asq.len);
2003 oldval = val;
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002004 if (val & I40E_VF_ATQLEN1_ATQVFE_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00002005 dev_info(&adapter->pdev->dev, "ASQ VF Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002006 val &= ~I40E_VF_ATQLEN1_ATQVFE_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00002007 }
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002008 if (val & I40E_VF_ATQLEN1_ATQOVFL_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00002009 dev_info(&adapter->pdev->dev, "ASQ Overflow Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002010 val &= ~I40E_VF_ATQLEN1_ATQOVFL_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00002011 }
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002012 if (val & I40E_VF_ATQLEN1_ATQCRIT_MASK) {
Mitch Williams912257e2014-05-22 06:32:07 +00002013 dev_info(&adapter->pdev->dev, "ASQ Critical Error detected\n");
Anjali Singhai Jainb1f33662015-07-10 19:36:05 -04002014 val &= ~I40E_VF_ATQLEN1_ATQCRIT_MASK;
Mitch Williams912257e2014-05-22 06:32:07 +00002015 }
2016 if (oldval != val)
2017 wr32(hw, hw->aq.asq.len, val);
2018
Mitch Williams67c818a2015-06-19 08:56:30 -07002019freedom:
Mitch A Williams72354482014-12-09 08:53:07 +00002020 kfree(event.msg_buf);
2021out:
Greg Rose5eae00c2013-12-21 06:12:45 +00002022 /* re-enable Admin queue interrupt cause */
2023 i40evf_misc_irq_enable(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002024}
2025
2026/**
Mitch Williamsed0e8942017-01-24 10:23:59 -08002027 * i40evf_client_task - worker thread to perform client work
2028 * @work: pointer to work_struct containing our data
2029 *
2030 * This task handles client interactions. Because client calls can be
2031 * reentrant, we can't handle them in the watchdog.
2032 **/
2033static void i40evf_client_task(struct work_struct *work)
2034{
2035 struct i40evf_adapter *adapter =
2036 container_of(work, struct i40evf_adapter, client_task.work);
2037
2038 /* If we can't get the client bit, just give up. We'll be rescheduled
2039 * later.
2040 */
2041
2042 if (test_and_set_bit(__I40EVF_IN_CLIENT_TASK, &adapter->crit_section))
2043 return;
2044
2045 if (adapter->flags & I40EVF_FLAG_SERVICE_CLIENT_REQUESTED) {
2046 i40evf_client_subtask(adapter);
2047 adapter->flags &= ~I40EVF_FLAG_SERVICE_CLIENT_REQUESTED;
2048 goto out;
2049 }
2050 if (adapter->flags & I40EVF_FLAG_CLIENT_NEEDS_CLOSE) {
2051 i40evf_notify_client_close(&adapter->vsi, false);
2052 adapter->flags &= ~I40EVF_FLAG_CLIENT_NEEDS_CLOSE;
2053 goto out;
2054 }
2055 if (adapter->flags & I40EVF_FLAG_CLIENT_NEEDS_OPEN) {
2056 i40evf_notify_client_open(&adapter->vsi);
2057 adapter->flags &= ~I40EVF_FLAG_CLIENT_NEEDS_OPEN;
2058 goto out;
2059 }
2060 if (adapter->flags & I40EVF_FLAG_CLIENT_NEEDS_L2_PARAMS) {
2061 i40evf_notify_client_l2_params(&adapter->vsi);
2062 adapter->flags &= ~I40EVF_FLAG_CLIENT_NEEDS_L2_PARAMS;
2063 }
2064out:
2065 clear_bit(__I40EVF_IN_CLIENT_TASK, &adapter->crit_section);
2066}
2067
2068/**
Greg Rose5eae00c2013-12-21 06:12:45 +00002069 * i40evf_free_all_tx_resources - Free Tx Resources for All Queues
2070 * @adapter: board private structure
2071 *
2072 * Free all transmit software resources
2073 **/
Mitch Williamse284fc82015-03-27 00:12:09 -07002074void i40evf_free_all_tx_resources(struct i40evf_adapter *adapter)
Greg Rose5eae00c2013-12-21 06:12:45 +00002075{
2076 int i;
2077
Mitch Williamsfdb47ae2015-11-19 11:34:18 -08002078 if (!adapter->tx_rings)
2079 return;
2080
Mitch Williamscc052922014-10-25 03:24:34 +00002081 for (i = 0; i < adapter->num_active_queues; i++)
Mitch Williams0dd438d2015-10-26 19:44:40 -04002082 if (adapter->tx_rings[i].desc)
2083 i40evf_free_tx_resources(&adapter->tx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00002084}
2085
2086/**
2087 * i40evf_setup_all_tx_resources - allocate all queues Tx resources
2088 * @adapter: board private structure
2089 *
2090 * If this function returns with an error, then it's possible one or
2091 * more of the rings is populated (while the rest are not). It is the
2092 * callers duty to clean those orphaned rings.
2093 *
2094 * Return 0 on success, negative on failure
2095 **/
2096static int i40evf_setup_all_tx_resources(struct i40evf_adapter *adapter)
2097{
2098 int i, err = 0;
2099
Mitch Williamscc052922014-10-25 03:24:34 +00002100 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williams0dd438d2015-10-26 19:44:40 -04002101 adapter->tx_rings[i].count = adapter->tx_desc_count;
2102 err = i40evf_setup_tx_descriptors(&adapter->tx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00002103 if (!err)
2104 continue;
2105 dev_err(&adapter->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04002106 "Allocation for Tx Queue %u failed\n", i);
Greg Rose5eae00c2013-12-21 06:12:45 +00002107 break;
2108 }
2109
2110 return err;
2111}
2112
2113/**
2114 * i40evf_setup_all_rx_resources - allocate all queues Rx resources
2115 * @adapter: board private structure
2116 *
2117 * If this function returns with an error, then it's possible one or
2118 * more of the rings is populated (while the rest are not). It is the
2119 * callers duty to clean those orphaned rings.
2120 *
2121 * Return 0 on success, negative on failure
2122 **/
2123static int i40evf_setup_all_rx_resources(struct i40evf_adapter *adapter)
2124{
2125 int i, err = 0;
2126
Mitch Williamscc052922014-10-25 03:24:34 +00002127 for (i = 0; i < adapter->num_active_queues; i++) {
Mitch Williams0dd438d2015-10-26 19:44:40 -04002128 adapter->rx_rings[i].count = adapter->rx_desc_count;
2129 err = i40evf_setup_rx_descriptors(&adapter->rx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00002130 if (!err)
2131 continue;
2132 dev_err(&adapter->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04002133 "Allocation for Rx Queue %u failed\n", i);
Greg Rose5eae00c2013-12-21 06:12:45 +00002134 break;
2135 }
2136 return err;
2137}
2138
2139/**
2140 * i40evf_free_all_rx_resources - Free Rx Resources for All Queues
2141 * @adapter: board private structure
2142 *
2143 * Free all receive software resources
2144 **/
Mitch Williamse284fc82015-03-27 00:12:09 -07002145void i40evf_free_all_rx_resources(struct i40evf_adapter *adapter)
Greg Rose5eae00c2013-12-21 06:12:45 +00002146{
2147 int i;
2148
Mitch Williamsfdb47ae2015-11-19 11:34:18 -08002149 if (!adapter->rx_rings)
2150 return;
2151
Mitch Williamscc052922014-10-25 03:24:34 +00002152 for (i = 0; i < adapter->num_active_queues; i++)
Mitch Williams0dd438d2015-10-26 19:44:40 -04002153 if (adapter->rx_rings[i].desc)
2154 i40evf_free_rx_resources(&adapter->rx_rings[i]);
Greg Rose5eae00c2013-12-21 06:12:45 +00002155}
2156
2157/**
2158 * i40evf_open - Called when a network interface is made active
2159 * @netdev: network interface device structure
2160 *
2161 * Returns 0 on success, negative value on failure
2162 *
2163 * The open entry point is called when a network interface is made
2164 * active by the system (IFF_UP). At this point all resources needed
2165 * for transmit and receive operations are allocated, the interrupt
2166 * handler is registered with the OS, the watchdog timer is started,
2167 * and the stack is notified that the interface is ready.
2168 **/
2169static int i40evf_open(struct net_device *netdev)
2170{
2171 struct i40evf_adapter *adapter = netdev_priv(netdev);
2172 int err;
2173
Mitch Williamsef8693e2014-02-13 03:48:53 -08002174 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) {
2175 dev_err(&adapter->pdev->dev, "Unable to open device due to PF driver failure.\n");
2176 return -EIO;
2177 }
Mitch Williams209dc4d2015-12-09 15:50:27 -08002178
2179 if (adapter->state != __I40EVF_DOWN)
Greg Rose5eae00c2013-12-21 06:12:45 +00002180 return -EBUSY;
2181
2182 /* allocate transmit descriptors */
2183 err = i40evf_setup_all_tx_resources(adapter);
2184 if (err)
2185 goto err_setup_tx;
2186
2187 /* allocate receive descriptors */
2188 err = i40evf_setup_all_rx_resources(adapter);
2189 if (err)
2190 goto err_setup_rx;
2191
2192 /* clear any pending interrupts, may auto mask */
2193 err = i40evf_request_traffic_irqs(adapter, netdev->name);
2194 if (err)
2195 goto err_req_irq;
2196
Mitch Williams44151cd2015-04-27 14:57:17 -04002197 i40evf_add_filter(adapter, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002198 i40evf_configure(adapter);
2199
Bimmy Pujaricb130a02016-09-06 18:05:03 -07002200 i40evf_up_complete(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002201
2202 i40evf_irq_enable(adapter, true);
2203
2204 return 0;
2205
2206err_req_irq:
2207 i40evf_down(adapter);
2208 i40evf_free_traffic_irqs(adapter);
2209err_setup_rx:
2210 i40evf_free_all_rx_resources(adapter);
2211err_setup_tx:
2212 i40evf_free_all_tx_resources(adapter);
2213
2214 return err;
2215}
2216
2217/**
2218 * i40evf_close - Disables a network interface
2219 * @netdev: network interface device structure
2220 *
2221 * Returns 0, this is not allowed to fail
2222 *
2223 * The close entry point is called when an interface is de-activated
2224 * by the OS. The hardware is still under the drivers control, but
2225 * needs to be disabled. All IRQs except vector 0 (reserved for admin queue)
2226 * are freed, along with all transmit and receive resources.
2227 **/
2228static int i40evf_close(struct net_device *netdev)
2229{
2230 struct i40evf_adapter *adapter = netdev_priv(netdev);
2231
Mitch Williams209dc4d2015-12-09 15:50:27 -08002232 if (adapter->state <= __I40EVF_DOWN_PENDING)
Mitch Williamsef8693e2014-02-13 03:48:53 -08002233 return 0;
2234
Mitch Williamsef8693e2014-02-13 03:48:53 -08002235
Greg Rose5eae00c2013-12-21 06:12:45 +00002236 set_bit(__I40E_DOWN, &adapter->vsi.state);
Mitch Williamsed0e8942017-01-24 10:23:59 -08002237 if (CLIENT_ENABLED(adapter))
2238 adapter->flags |= I40EVF_FLAG_CLIENT_NEEDS_CLOSE;
Greg Rose5eae00c2013-12-21 06:12:45 +00002239
2240 i40evf_down(adapter);
Mitch Williams209dc4d2015-12-09 15:50:27 -08002241 adapter->state = __I40EVF_DOWN_PENDING;
Greg Rose5eae00c2013-12-21 06:12:45 +00002242 i40evf_free_traffic_irqs(adapter);
2243
Mitch Williams51f38262016-12-12 15:44:11 -08002244 /* We explicitly don't free resources here because the hardware is
2245 * still active and can DMA into memory. Resources are cleared in
2246 * i40evf_virtchnl_completion() after we get confirmation from the PF
2247 * driver that the rings have been stopped.
2248 */
Greg Rose5eae00c2013-12-21 06:12:45 +00002249 return 0;
2250}
2251
2252/**
Greg Rose5eae00c2013-12-21 06:12:45 +00002253 * i40evf_change_mtu - Change the Maximum Transfer Unit
2254 * @netdev: network interface device structure
2255 * @new_mtu: new value for maximum frame size
2256 *
2257 * Returns 0 on success, negative on failure
2258 **/
2259static int i40evf_change_mtu(struct net_device *netdev, int new_mtu)
2260{
2261 struct i40evf_adapter *adapter = netdev_priv(netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +00002262
Greg Rose5eae00c2013-12-21 06:12:45 +00002263 netdev->mtu = new_mtu;
Mitch Williamsed0e8942017-01-24 10:23:59 -08002264 if (CLIENT_ENABLED(adapter)) {
2265 i40evf_notify_client_l2_params(&adapter->vsi);
2266 adapter->flags |= I40EVF_FLAG_SERVICE_CLIENT_REQUESTED;
2267 }
Mitch Williams67c818a2015-06-19 08:56:30 -07002268 adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
2269 schedule_work(&adapter->reset_task);
2270
Greg Rose5eae00c2013-12-21 06:12:45 +00002271 return 0;
2272}
2273
Alexander Duyck06fc0162016-10-25 16:08:47 -07002274/**
2275 * i40evf_features_check - Validate encapsulated packet conforms to limits
2276 * @skb: skb buff
2277 * @netdev: This physical port's netdev
2278 * @features: Offload features that the stack believes apply
2279 **/
2280static netdev_features_t i40evf_features_check(struct sk_buff *skb,
2281 struct net_device *dev,
2282 netdev_features_t features)
2283{
2284 size_t len;
2285
2286 /* No point in doing any of this if neither checksum nor GSO are
2287 * being requested for this frame. We can rule out both by just
2288 * checking for CHECKSUM_PARTIAL
2289 */
2290 if (skb->ip_summed != CHECKSUM_PARTIAL)
2291 return features;
2292
2293 /* We cannot support GSO if the MSS is going to be less than
2294 * 64 bytes. If it is then we need to drop support for GSO.
2295 */
2296 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
2297 features &= ~NETIF_F_GSO_MASK;
2298
2299 /* MACLEN can support at most 63 words */
2300 len = skb_network_header(skb) - skb->data;
2301 if (len & ~(63 * 2))
2302 goto out_err;
2303
2304 /* IPLEN and EIPLEN can support at most 127 dwords */
2305 len = skb_transport_header(skb) - skb_network_header(skb);
2306 if (len & ~(127 * 4))
2307 goto out_err;
2308
2309 if (skb->encapsulation) {
2310 /* L4TUNLEN can support 127 words */
2311 len = skb_inner_network_header(skb) - skb_transport_header(skb);
2312 if (len & ~(127 * 2))
2313 goto out_err;
2314
2315 /* IPLEN can support at most 127 dwords */
2316 len = skb_inner_transport_header(skb) -
2317 skb_inner_network_header(skb);
2318 if (len & ~(127 * 4))
2319 goto out_err;
2320 }
2321
2322 /* No need to validate L4LEN as TCP is the only protocol with a
2323 * a flexible value and we support all possible values supported
2324 * by TCP, which is at most 15 dwords
2325 */
2326
2327 return features;
2328out_err:
2329 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
2330}
2331
Mitch Williamsc4445ae2016-03-18 12:18:07 -07002332#define I40EVF_VLAN_FEATURES (NETIF_F_HW_VLAN_CTAG_TX |\
2333 NETIF_F_HW_VLAN_CTAG_RX |\
2334 NETIF_F_HW_VLAN_CTAG_FILTER)
2335
2336/**
2337 * i40evf_fix_features - fix up the netdev feature bits
2338 * @netdev: our net device
2339 * @features: desired feature bits
2340 *
2341 * Returns fixed-up features bits
2342 **/
2343static netdev_features_t i40evf_fix_features(struct net_device *netdev,
2344 netdev_features_t features)
2345{
2346 struct i40evf_adapter *adapter = netdev_priv(netdev);
2347
2348 features &= ~I40EVF_VLAN_FEATURES;
2349 if (adapter->vf_res->vf_offload_flags & I40E_VIRTCHNL_VF_OFFLOAD_VLAN)
2350 features |= I40EVF_VLAN_FEATURES;
2351 return features;
2352}
2353
Greg Rose5eae00c2013-12-21 06:12:45 +00002354static const struct net_device_ops i40evf_netdev_ops = {
2355 .ndo_open = i40evf_open,
2356 .ndo_stop = i40evf_close,
2357 .ndo_start_xmit = i40evf_xmit_frame,
Greg Rose5eae00c2013-12-21 06:12:45 +00002358 .ndo_set_rx_mode = i40evf_set_rx_mode,
2359 .ndo_validate_addr = eth_validate_addr,
2360 .ndo_set_mac_address = i40evf_set_mac,
2361 .ndo_change_mtu = i40evf_change_mtu,
2362 .ndo_tx_timeout = i40evf_tx_timeout,
2363 .ndo_vlan_rx_add_vid = i40evf_vlan_rx_add_vid,
2364 .ndo_vlan_rx_kill_vid = i40evf_vlan_rx_kill_vid,
Alexander Duyck06fc0162016-10-25 16:08:47 -07002365 .ndo_features_check = i40evf_features_check,
Mitch Williamsc4445ae2016-03-18 12:18:07 -07002366 .ndo_fix_features = i40evf_fix_features,
Alexander Duyck7709b4c2015-09-24 09:04:38 -07002367#ifdef CONFIG_NET_POLL_CONTROLLER
2368 .ndo_poll_controller = i40evf_netpoll,
2369#endif
Greg Rose5eae00c2013-12-21 06:12:45 +00002370};
2371
2372/**
2373 * i40evf_check_reset_complete - check that VF reset is complete
2374 * @hw: pointer to hw struct
2375 *
2376 * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
2377 **/
2378static int i40evf_check_reset_complete(struct i40e_hw *hw)
2379{
2380 u32 rstat;
2381 int i;
2382
2383 for (i = 0; i < 100; i++) {
Ashish Shahfd358862014-08-01 13:27:11 -07002384 rstat = rd32(hw, I40E_VFGEN_RSTAT) &
2385 I40E_VFGEN_RSTAT_VFR_STATE_MASK;
2386 if ((rstat == I40E_VFR_VFACTIVE) ||
2387 (rstat == I40E_VFR_COMPLETED))
Greg Rose5eae00c2013-12-21 06:12:45 +00002388 return 0;
Neerav Parikhf98a2002014-09-13 07:40:44 +00002389 usleep_range(10, 20);
Greg Rose5eae00c2013-12-21 06:12:45 +00002390 }
2391 return -EBUSY;
2392}
2393
2394/**
Mitch Williamse6d038d2015-06-04 16:23:58 -04002395 * i40evf_process_config - Process the config information we got from the PF
2396 * @adapter: board private structure
2397 *
2398 * Verify that we have a valid config struct, and set up our netdev features
2399 * and our VSI struct.
2400 **/
2401int i40evf_process_config(struct i40evf_adapter *adapter)
2402{
Mitch Williamsba6cc7f2016-04-01 13:34:31 -07002403 struct i40e_virtchnl_vf_resource *vfres = adapter->vf_res;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002404 struct net_device *netdev = adapter->netdev;
Mitch Williams43a3d9b2016-04-12 08:30:44 -07002405 struct i40e_vsi *vsi = &adapter->vsi;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002406 int i;
Preethi Banalabacd75c2017-03-27 14:43:18 -07002407 netdev_features_t hw_enc_features;
2408 netdev_features_t hw_features;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002409
2410 /* got VF config message back from PF, now we can parse it */
Mitch Williamsba6cc7f2016-04-01 13:34:31 -07002411 for (i = 0; i < vfres->num_vsis; i++) {
2412 if (vfres->vsi_res[i].vsi_type == I40E_VSI_SRIOV)
2413 adapter->vsi_res = &vfres->vsi_res[i];
Mitch Williamse6d038d2015-06-04 16:23:58 -04002414 }
2415 if (!adapter->vsi_res) {
2416 dev_err(&adapter->pdev->dev, "No LAN VSI found\n");
2417 return -ENODEV;
2418 }
2419
Preethi Banalabacd75c2017-03-27 14:43:18 -07002420 hw_enc_features = NETIF_F_SG |
2421 NETIF_F_IP_CSUM |
2422 NETIF_F_IPV6_CSUM |
2423 NETIF_F_HIGHDMA |
2424 NETIF_F_SOFT_FEATURES |
2425 NETIF_F_TSO |
2426 NETIF_F_TSO_ECN |
2427 NETIF_F_TSO6 |
2428 NETIF_F_SCTP_CRC |
2429 NETIF_F_RXHASH |
2430 NETIF_F_RXCSUM |
2431 0;
2432
2433 /* advertise to stack only if offloads for encapsulated packets is
2434 * supported
2435 */
2436 if (vfres->vf_offload_flags & I40E_VIRTCHNL_VF_OFFLOAD_ENCAP) {
2437 hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL |
Alexander Duyckb0fe3302016-04-02 00:05:14 -07002438 NETIF_F_GSO_GRE |
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04002439 NETIF_F_GSO_GRE_CSUM |
Tom Herbert7e133182016-05-18 09:06:10 -07002440 NETIF_F_GSO_IPXIP4 |
Alexander Duyckbf2d1df2016-05-18 10:44:53 -07002441 NETIF_F_GSO_IPXIP6 |
Alexander Duyckb0fe3302016-04-02 00:05:14 -07002442 NETIF_F_GSO_UDP_TUNNEL_CSUM |
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04002443 NETIF_F_GSO_PARTIAL |
Alexander Duyckb0fe3302016-04-02 00:05:14 -07002444 0;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002445
Preethi Banalabacd75c2017-03-27 14:43:18 -07002446 if (!(vfres->vf_offload_flags &
2447 I40E_VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM))
2448 netdev->gso_partial_features |=
2449 NETIF_F_GSO_UDP_TUNNEL_CSUM;
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04002450
Preethi Banalabacd75c2017-03-27 14:43:18 -07002451 netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
2452 netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
2453 netdev->hw_enc_features |= hw_enc_features;
2454 }
Alexander Duyckb0fe3302016-04-02 00:05:14 -07002455 /* record features VLANs can make use of */
Preethi Banalabacd75c2017-03-27 14:43:18 -07002456 netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID;
Alexander Duyckf608e6a2016-01-24 21:17:57 -08002457
Alexander Duyckb0fe3302016-04-02 00:05:14 -07002458 /* Write features and hw_features separately to avoid polluting
Preethi Banalabacd75c2017-03-27 14:43:18 -07002459 * with, or dropping, features that are set when we registered.
Alexander Duyckb0fe3302016-04-02 00:05:14 -07002460 */
Preethi Banalabacd75c2017-03-27 14:43:18 -07002461 hw_features = hw_enc_features;
Mitch Williamsba6cc7f2016-04-01 13:34:31 -07002462
Preethi Banalabacd75c2017-03-27 14:43:18 -07002463 netdev->hw_features |= hw_features;
Alexander Duyckb0fe3302016-04-02 00:05:14 -07002464
Preethi Banalabacd75c2017-03-27 14:43:18 -07002465 netdev->features |= hw_features | I40EVF_VLAN_FEATURES;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002466
2467 adapter->vsi.id = adapter->vsi_res->vsi_id;
2468
2469 adapter->vsi.back = adapter;
2470 adapter->vsi.base_vector = 1;
2471 adapter->vsi.work_limit = I40E_DEFAULT_IRQ_WORK;
Mitch Williams43a3d9b2016-04-12 08:30:44 -07002472 vsi->netdev = adapter->netdev;
2473 vsi->qs_handle = adapter->vsi_res->qset_handle;
2474 if (vfres->vf_offload_flags & I40E_VIRTCHNL_VF_OFFLOAD_RSS_PF) {
2475 adapter->rss_key_size = vfres->rss_key_size;
2476 adapter->rss_lut_size = vfres->rss_lut_size;
2477 } else {
2478 adapter->rss_key_size = I40EVF_HKEY_ARRAY_SIZE;
2479 adapter->rss_lut_size = I40EVF_HLUT_ARRAY_SIZE;
2480 }
2481
Mitch Williamse6d038d2015-06-04 16:23:58 -04002482 return 0;
2483}
2484
2485/**
Greg Rose5eae00c2013-12-21 06:12:45 +00002486 * i40evf_init_task - worker thread to perform delayed initialization
2487 * @work: pointer to work_struct containing our data
2488 *
2489 * This task completes the work that was begun in probe. Due to the nature
2490 * of VF-PF communications, we may need to wait tens of milliseconds to get
Joe Perchesdbedd442015-03-06 20:49:12 -08002491 * responses back from the PF. Rather than busy-wait in probe and bog down the
Greg Rose5eae00c2013-12-21 06:12:45 +00002492 * whole system, we'll do it in a task so we can sleep.
2493 * This task only runs during driver init. Once we've established
2494 * communications with the PF driver and set up our netdev, the watchdog
2495 * takes over.
2496 **/
2497static void i40evf_init_task(struct work_struct *work)
2498{
2499 struct i40evf_adapter *adapter = container_of(work,
2500 struct i40evf_adapter,
2501 init_task.work);
2502 struct net_device *netdev = adapter->netdev;
Greg Rose5eae00c2013-12-21 06:12:45 +00002503 struct i40e_hw *hw = &adapter->hw;
2504 struct pci_dev *pdev = adapter->pdev;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002505 int err, bufsz;
Greg Rose5eae00c2013-12-21 06:12:45 +00002506
2507 switch (adapter->state) {
2508 case __I40EVF_STARTUP:
2509 /* driver loaded, probe complete */
Mitch Williamsef8693e2014-02-13 03:48:53 -08002510 adapter->flags &= ~I40EVF_FLAG_PF_COMMS_FAILED;
2511 adapter->flags &= ~I40EVF_FLAG_RESET_PENDING;
Greg Rose5eae00c2013-12-21 06:12:45 +00002512 err = i40e_set_mac_type(hw);
2513 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002514 dev_err(&pdev->dev, "Failed to set MAC type (%d)\n",
2515 err);
Mitch Williams2619ef42015-04-07 19:45:30 -04002516 goto err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002517 }
2518 err = i40evf_check_reset_complete(hw);
2519 if (err) {
Mitch Williams0d9c7ea2014-04-23 04:50:00 +00002520 dev_info(&pdev->dev, "Device is still in reset (%d), retrying\n",
Mitch Williams75a64432014-11-11 20:02:42 +00002521 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002522 goto err;
2523 }
2524 hw->aq.num_arq_entries = I40EVF_AQ_LEN;
2525 hw->aq.num_asq_entries = I40EVF_AQ_LEN;
2526 hw->aq.arq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2527 hw->aq.asq_buf_size = I40EVF_MAX_AQ_BUF_SIZE;
2528
2529 err = i40evf_init_adminq(hw);
2530 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002531 dev_err(&pdev->dev, "Failed to init Admin Queue (%d)\n",
2532 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002533 goto err;
2534 }
2535 err = i40evf_send_api_ver(adapter);
2536 if (err) {
Mitch Williams10bdd672014-03-06 08:59:53 +00002537 dev_err(&pdev->dev, "Unable to send to PF (%d)\n", err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002538 i40evf_shutdown_adminq(hw);
2539 goto err;
2540 }
2541 adapter->state = __I40EVF_INIT_VERSION_CHECK;
2542 goto restart;
Greg Rose5eae00c2013-12-21 06:12:45 +00002543 case __I40EVF_INIT_VERSION_CHECK:
Mitch Williams10bdd672014-03-06 08:59:53 +00002544 if (!i40evf_asq_done(hw)) {
Mitch Williams80e72892014-05-10 04:49:06 +00002545 dev_err(&pdev->dev, "Admin queue command never completed\n");
Mitch Williams906a6932014-11-13 03:06:12 +00002546 i40evf_shutdown_adminq(hw);
2547 adapter->state = __I40EVF_STARTUP;
Greg Rose5eae00c2013-12-21 06:12:45 +00002548 goto err;
Mitch Williams10bdd672014-03-06 08:59:53 +00002549 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002550
2551 /* aq msg sent, awaiting reply */
2552 err = i40evf_verify_api_ver(adapter);
2553 if (err) {
Mitch A Williamsd4f82fd2014-12-09 08:53:03 +00002554 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
Mitch Williams56f99202014-06-04 04:22:41 +00002555 err = i40evf_send_api_ver(adapter);
Mitch Williamsee1693e2015-06-04 16:23:59 -04002556 else
2557 dev_err(&pdev->dev, "Unsupported PF API version %d.%d, expected %d.%d\n",
2558 adapter->pf_version.major,
2559 adapter->pf_version.minor,
2560 I40E_VIRTCHNL_VERSION_MAJOR,
2561 I40E_VIRTCHNL_VERSION_MINOR);
Greg Rose5eae00c2013-12-21 06:12:45 +00002562 goto err;
2563 }
2564 err = i40evf_send_vf_config_msg(adapter);
2565 if (err) {
Mitch Williams3f2ab172014-06-04 04:22:40 +00002566 dev_err(&pdev->dev, "Unable to send config request (%d)\n",
Greg Rose5eae00c2013-12-21 06:12:45 +00002567 err);
2568 goto err;
2569 }
2570 adapter->state = __I40EVF_INIT_GET_RESOURCES;
2571 goto restart;
Greg Rose5eae00c2013-12-21 06:12:45 +00002572 case __I40EVF_INIT_GET_RESOURCES:
2573 /* aq msg sent, awaiting reply */
2574 if (!adapter->vf_res) {
2575 bufsz = sizeof(struct i40e_virtchnl_vf_resource) +
2576 (I40E_MAX_VF_VSI *
2577 sizeof(struct i40e_virtchnl_vsi_resource));
2578 adapter->vf_res = kzalloc(bufsz, GFP_KERNEL);
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002579 if (!adapter->vf_res)
Greg Rose5eae00c2013-12-21 06:12:45 +00002580 goto err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002581 }
2582 err = i40evf_get_vf_config(adapter);
Mitch Williams906a6932014-11-13 03:06:12 +00002583 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
Mitch Williams906a6932014-11-13 03:06:12 +00002584 err = i40evf_send_vf_config_msg(adapter);
2585 goto err;
Mitch Williamse7430722015-10-26 19:44:38 -04002586 } else if (err == I40E_ERR_PARAM) {
2587 /* We only get ERR_PARAM if the device is in a very bad
2588 * state or if we've been disabled for previous bad
2589 * behavior. Either way, we're done now.
2590 */
2591 i40evf_shutdown_adminq(hw);
2592 dev_err(&pdev->dev, "Unable to get VF config due to PF error condition, not retrying\n");
2593 return;
Mitch Williams906a6932014-11-13 03:06:12 +00002594 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002595 if (err) {
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002596 dev_err(&pdev->dev, "Unable to get VF config (%d)\n",
2597 err);
Greg Rose5eae00c2013-12-21 06:12:45 +00002598 goto err_alloc;
2599 }
2600 adapter->state = __I40EVF_INIT_SW;
2601 break;
2602 default:
2603 goto err_alloc;
2604 }
Alexander Duyckf608e6a2016-01-24 21:17:57 -08002605
Mitch Williamse6d038d2015-06-04 16:23:58 -04002606 if (i40evf_process_config(adapter))
Greg Rose5eae00c2013-12-21 06:12:45 +00002607 goto err_alloc;
Mitch Williamse6d038d2015-06-04 16:23:58 -04002608 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
Greg Rose5eae00c2013-12-21 06:12:45 +00002609
2610 adapter->flags |= I40EVF_FLAG_RX_CSUM_ENABLED;
2611
Greg Rose5eae00c2013-12-21 06:12:45 +00002612 netdev->netdev_ops = &i40evf_netdev_ops;
2613 i40evf_set_ethtool_ops(netdev);
2614 netdev->watchdog_timeo = 5 * HZ;
Greg Rose3415e8c2014-01-30 12:40:27 +00002615
Jarod Wilson91c527a2016-10-17 15:54:05 -04002616 /* MTU range: 68 - 9710 */
2617 netdev->min_mtu = ETH_MIN_MTU;
2618 netdev->max_mtu = I40E_MAX_RXBUFFER - (ETH_HLEN + ETH_FCS_LEN);
2619
Greg Rose5eae00c2013-12-21 06:12:45 +00002620 if (!is_valid_ether_addr(adapter->hw.mac.addr)) {
Mitch Williamsb34f90e2014-05-10 04:49:07 +00002621 dev_info(&pdev->dev, "Invalid MAC address %pM, using random\n",
Mitch Williamsc2a137c2014-02-20 19:29:09 -08002622 adapter->hw.mac.addr);
Mitch Williams14e52ee2015-08-31 19:54:44 -04002623 eth_hw_addr_random(netdev);
2624 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2625 } else {
2626 adapter->flags |= I40EVF_FLAG_ADDR_SET_BY_PF;
2627 ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
2628 ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002629 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002630
Greg Rose5eae00c2013-12-21 06:12:45 +00002631 init_timer(&adapter->watchdog_timer);
2632 adapter->watchdog_timer.function = &i40evf_watchdog_timer;
2633 adapter->watchdog_timer.data = (unsigned long)adapter;
2634 mod_timer(&adapter->watchdog_timer, jiffies + 1);
2635
Mitch Williamscc052922014-10-25 03:24:34 +00002636 adapter->num_active_queues = min_t(int,
2637 adapter->vsi_res->num_queue_pairs,
2638 (int)(num_online_cpus()));
Mitch Williamsd732a182014-04-24 06:41:37 +00002639 adapter->tx_desc_count = I40EVF_DEFAULT_TXD;
2640 adapter->rx_desc_count = I40EVF_DEFAULT_RXD;
Greg Rose5eae00c2013-12-21 06:12:45 +00002641 err = i40evf_init_interrupt_scheme(adapter);
2642 if (err)
2643 goto err_sw_init;
2644 i40evf_map_rings_to_vectors(adapter);
Anjali Singhai Jain1f012272015-09-03 17:18:53 -04002645 if (adapter->vf_res->vf_offload_flags &
Anjali Singhai Jainf6d83d12015-12-22 14:25:07 -08002646 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
2647 adapter->flags |= I40EVF_FLAG_WB_ON_ITR_CAPABLE;
2648
Greg Rose5eae00c2013-12-21 06:12:45 +00002649 err = i40evf_request_misc_irq(adapter);
2650 if (err)
2651 goto err_sw_init;
2652
2653 netif_carrier_off(netdev);
Sridhar Samudrala3f341ac2016-09-01 22:27:27 +02002654 adapter->link_up = false;
Greg Rose5eae00c2013-12-21 06:12:45 +00002655
Mitch Williamsef8693e2014-02-13 03:48:53 -08002656 if (!adapter->netdev_registered) {
2657 err = register_netdev(netdev);
2658 if (err)
2659 goto err_register;
2660 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002661
2662 adapter->netdev_registered = true;
2663
2664 netif_tx_stop_all_queues(netdev);
Mitch Williamsed0e8942017-01-24 10:23:59 -08002665 if (CLIENT_ALLOWED(adapter)) {
2666 err = i40evf_lan_add_device(adapter);
2667 if (err)
2668 dev_info(&pdev->dev, "Failed to add VF to client API service list: %d\n",
2669 err);
2670 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002671
Mitch Williamsb34f90e2014-05-10 04:49:07 +00002672 dev_info(&pdev->dev, "MAC address: %pM\n", adapter->hw.mac.addr);
Greg Rose5eae00c2013-12-21 06:12:45 +00002673 if (netdev->features & NETIF_F_GRO)
2674 dev_info(&pdev->dev, "GRO is enabled\n");
2675
Greg Rose5eae00c2013-12-21 06:12:45 +00002676 adapter->state = __I40EVF_DOWN;
2677 set_bit(__I40E_DOWN, &adapter->vsi.state);
2678 i40evf_misc_irq_enable(adapter);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04002679
Mitch Williams43a3d9b2016-04-12 08:30:44 -07002680 adapter->rss_key = kzalloc(adapter->rss_key_size, GFP_KERNEL);
2681 adapter->rss_lut = kzalloc(adapter->rss_lut_size, GFP_KERNEL);
2682 if (!adapter->rss_key || !adapter->rss_lut)
2683 goto err_mem;
2684
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04002685 if (RSS_AQ(adapter)) {
2686 adapter->aq_required |= I40EVF_FLAG_AQ_CONFIGURE_RSS;
2687 mod_timer_pending(&adapter->watchdog_timer, jiffies + 1);
2688 } else {
Helin Zhang96a81982015-10-26 19:44:31 -04002689 i40evf_init_rss(adapter);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04002690 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002691 return;
2692restart:
Mitch Williams3f7e5c32015-09-28 14:12:42 -04002693 schedule_delayed_work(&adapter->init_task, msecs_to_jiffies(30));
Greg Rose5eae00c2013-12-21 06:12:45 +00002694 return;
Mitch Williams43a3d9b2016-04-12 08:30:44 -07002695err_mem:
2696 i40evf_free_rss(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002697err_register:
2698 i40evf_free_misc_irq(adapter);
2699err_sw_init:
2700 i40evf_reset_interrupt_capability(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002701err_alloc:
2702 kfree(adapter->vf_res);
2703 adapter->vf_res = NULL;
2704err:
2705 /* Things went into the weeds, so try again later */
2706 if (++adapter->aq_wait_count > I40EVF_AQ_MAX_ERR) {
Mitch Williamsb9029e92015-09-28 14:16:50 -04002707 dev_err(&pdev->dev, "Failed to communicate with PF; waiting before retry\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08002708 adapter->flags |= I40EVF_FLAG_PF_COMMS_FAILED;
Mitch Williamsb9029e92015-09-28 14:16:50 -04002709 i40evf_shutdown_adminq(hw);
2710 adapter->state = __I40EVF_STARTUP;
2711 schedule_delayed_work(&adapter->init_task, HZ * 5);
2712 return;
Greg Rose5eae00c2013-12-21 06:12:45 +00002713 }
Mitch Williams3f7e5c32015-09-28 14:12:42 -04002714 schedule_delayed_work(&adapter->init_task, HZ);
Greg Rose5eae00c2013-12-21 06:12:45 +00002715}
2716
2717/**
2718 * i40evf_shutdown - Shutdown the device in preparation for a reboot
2719 * @pdev: pci device structure
2720 **/
2721static void i40evf_shutdown(struct pci_dev *pdev)
2722{
2723 struct net_device *netdev = pci_get_drvdata(pdev);
Mitch Williams00293fd2015-01-09 11:18:18 +00002724 struct i40evf_adapter *adapter = netdev_priv(netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +00002725
2726 netif_device_detach(netdev);
2727
2728 if (netif_running(netdev))
2729 i40evf_close(netdev);
2730
Mitch Williams00293fd2015-01-09 11:18:18 +00002731 /* Prevent the watchdog from running. */
2732 adapter->state = __I40EVF_REMOVE;
2733 adapter->aq_required = 0;
Mitch Williams00293fd2015-01-09 11:18:18 +00002734
Greg Rose5eae00c2013-12-21 06:12:45 +00002735#ifdef CONFIG_PM
2736 pci_save_state(pdev);
2737
2738#endif
2739 pci_disable_device(pdev);
2740}
2741
2742/**
2743 * i40evf_probe - Device Initialization Routine
2744 * @pdev: PCI device information struct
2745 * @ent: entry in i40evf_pci_tbl
2746 *
2747 * Returns 0 on success, negative on failure
2748 *
2749 * i40evf_probe initializes an adapter identified by a pci_dev structure.
2750 * The OS initialization, configuring of the adapter private structure,
2751 * and a hardware reset occur.
2752 **/
2753static int i40evf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2754{
2755 struct net_device *netdev;
2756 struct i40evf_adapter *adapter = NULL;
2757 struct i40e_hw *hw = NULL;
Mitch Williamsdbbd8112014-02-20 19:29:08 -08002758 int err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002759
2760 err = pci_enable_device(pdev);
2761 if (err)
2762 return err;
2763
Mitch Williams64942942014-02-11 08:26:33 +00002764 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +00002765 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +00002766 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2767 if (err) {
2768 dev_err(&pdev->dev,
2769 "DMA configuration failed: 0x%x\n", err);
2770 goto err_dma;
2771 }
Greg Rose5eae00c2013-12-21 06:12:45 +00002772 }
2773
2774 err = pci_request_regions(pdev, i40evf_driver_name);
2775 if (err) {
2776 dev_err(&pdev->dev,
2777 "pci_request_regions failed 0x%x\n", err);
2778 goto err_pci_reg;
2779 }
2780
2781 pci_enable_pcie_error_reporting(pdev);
2782
2783 pci_set_master(pdev);
2784
Mitch Williams1255b7a2015-11-06 15:25:59 -08002785 netdev = alloc_etherdev_mq(sizeof(struct i40evf_adapter), MAX_QUEUES);
Greg Rose5eae00c2013-12-21 06:12:45 +00002786 if (!netdev) {
2787 err = -ENOMEM;
2788 goto err_alloc_etherdev;
2789 }
2790
2791 SET_NETDEV_DEV(netdev, &pdev->dev);
2792
2793 pci_set_drvdata(pdev, netdev);
2794 adapter = netdev_priv(netdev);
Greg Rose5eae00c2013-12-21 06:12:45 +00002795
2796 adapter->netdev = netdev;
2797 adapter->pdev = pdev;
2798
2799 hw = &adapter->hw;
2800 hw->back = adapter;
2801
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002802 adapter->msg_enable = BIT(DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
Greg Rose5eae00c2013-12-21 06:12:45 +00002803 adapter->state = __I40EVF_STARTUP;
2804
2805 /* Call save state here because it relies on the adapter struct. */
2806 pci_save_state(pdev);
2807
2808 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2809 pci_resource_len(pdev, 0));
2810 if (!hw->hw_addr) {
2811 err = -EIO;
2812 goto err_ioremap;
2813 }
2814 hw->vendor_id = pdev->vendor;
2815 hw->device_id = pdev->device;
2816 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2817 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2818 hw->subsystem_device_id = pdev->subsystem_device;
2819 hw->bus.device = PCI_SLOT(pdev->devfn);
2820 hw->bus.func = PCI_FUNC(pdev->devfn);
Sudheer Mogilappagarib3f028f2017-02-09 23:58:22 -08002821 hw->bus.bus_id = pdev->bus->number;
Greg Rose5eae00c2013-12-21 06:12:45 +00002822
Jesse Brandeburg8ddb3322015-11-18 15:47:06 -08002823 /* set up the locks for the AQ, do this only once in probe
2824 * and destroy them only once in remove
2825 */
2826 mutex_init(&hw->aq.asq_mutex);
2827 mutex_init(&hw->aq.arq_mutex);
2828
Serey Kong8bb1a542014-08-01 13:27:15 -07002829 INIT_LIST_HEAD(&adapter->mac_filter_list);
2830 INIT_LIST_HEAD(&adapter->vlan_filter_list);
2831
Greg Rose5eae00c2013-12-21 06:12:45 +00002832 INIT_WORK(&adapter->reset_task, i40evf_reset_task);
2833 INIT_WORK(&adapter->adminq_task, i40evf_adminq_task);
2834 INIT_WORK(&adapter->watchdog_task, i40evf_watchdog_task);
Mitch Williamsed0e8942017-01-24 10:23:59 -08002835 INIT_DELAYED_WORK(&adapter->client_task, i40evf_client_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00002836 INIT_DELAYED_WORK(&adapter->init_task, i40evf_init_task);
Mitch Williams9b32b0b2015-08-13 15:11:32 -07002837 schedule_delayed_work(&adapter->init_task,
2838 msecs_to_jiffies(5 * (pdev->devfn & 0x07)));
Greg Rose5eae00c2013-12-21 06:12:45 +00002839
2840 return 0;
2841
2842err_ioremap:
2843 free_netdev(netdev);
2844err_alloc_etherdev:
2845 pci_release_regions(pdev);
2846err_pci_reg:
2847err_dma:
2848 pci_disable_device(pdev);
2849 return err;
2850}
2851
2852#ifdef CONFIG_PM
2853/**
2854 * i40evf_suspend - Power management suspend routine
2855 * @pdev: PCI device information struct
2856 * @state: unused
2857 *
2858 * Called when the system (VM) is entering sleep/suspend.
2859 **/
2860static int i40evf_suspend(struct pci_dev *pdev, pm_message_t state)
2861{
2862 struct net_device *netdev = pci_get_drvdata(pdev);
2863 struct i40evf_adapter *adapter = netdev_priv(netdev);
2864 int retval = 0;
2865
2866 netif_device_detach(netdev);
2867
2868 if (netif_running(netdev)) {
2869 rtnl_lock();
2870 i40evf_down(adapter);
2871 rtnl_unlock();
2872 }
2873 i40evf_free_misc_irq(adapter);
2874 i40evf_reset_interrupt_capability(adapter);
2875
2876 retval = pci_save_state(pdev);
2877 if (retval)
2878 return retval;
2879
2880 pci_disable_device(pdev);
2881
2882 return 0;
2883}
2884
2885/**
Joe Perchesdbedd442015-03-06 20:49:12 -08002886 * i40evf_resume - Power management resume routine
Greg Rose5eae00c2013-12-21 06:12:45 +00002887 * @pdev: PCI device information struct
2888 *
2889 * Called when the system (VM) is resumed from sleep/suspend.
2890 **/
2891static int i40evf_resume(struct pci_dev *pdev)
2892{
2893 struct i40evf_adapter *adapter = pci_get_drvdata(pdev);
2894 struct net_device *netdev = adapter->netdev;
2895 u32 err;
2896
2897 pci_set_power_state(pdev, PCI_D0);
2898 pci_restore_state(pdev);
2899 /* pci_restore_state clears dev->state_saved so call
2900 * pci_save_state to restore it.
2901 */
2902 pci_save_state(pdev);
2903
2904 err = pci_enable_device_mem(pdev);
2905 if (err) {
2906 dev_err(&pdev->dev, "Cannot enable PCI device from suspend.\n");
2907 return err;
2908 }
2909 pci_set_master(pdev);
2910
2911 rtnl_lock();
2912 err = i40evf_set_interrupt_capability(adapter);
2913 if (err) {
Vasily Averinf2a1c362015-07-07 18:53:38 +03002914 rtnl_unlock();
Greg Rose5eae00c2013-12-21 06:12:45 +00002915 dev_err(&pdev->dev, "Cannot enable MSI-X interrupts.\n");
2916 return err;
2917 }
2918 err = i40evf_request_misc_irq(adapter);
2919 rtnl_unlock();
2920 if (err) {
2921 dev_err(&pdev->dev, "Cannot get interrupt vector.\n");
2922 return err;
2923 }
2924
2925 schedule_work(&adapter->reset_task);
2926
2927 netif_device_attach(netdev);
2928
2929 return err;
2930}
2931
2932#endif /* CONFIG_PM */
2933/**
2934 * i40evf_remove - Device Removal Routine
2935 * @pdev: PCI device information struct
2936 *
2937 * i40evf_remove is called by the PCI subsystem to alert the driver
2938 * that it should release a PCI device. The could be caused by a
2939 * Hot-Plug event, or because the driver is going to be removed from
2940 * memory.
2941 **/
2942static void i40evf_remove(struct pci_dev *pdev)
2943{
2944 struct net_device *netdev = pci_get_drvdata(pdev);
2945 struct i40evf_adapter *adapter = netdev_priv(netdev);
Mitch Williams6ba36a22014-08-01 13:27:14 -07002946 struct i40evf_mac_filter *f, *ftmp;
Greg Rose5eae00c2013-12-21 06:12:45 +00002947 struct i40e_hw *hw = &adapter->hw;
Mitch Williamsed0e8942017-01-24 10:23:59 -08002948 int err;
Greg Rose5eae00c2013-12-21 06:12:45 +00002949
2950 cancel_delayed_work_sync(&adapter->init_task);
Mitch Williamsef8693e2014-02-13 03:48:53 -08002951 cancel_work_sync(&adapter->reset_task);
Mitch Williamsed0e8942017-01-24 10:23:59 -08002952 cancel_delayed_work_sync(&adapter->client_task);
Greg Rose5eae00c2013-12-21 06:12:45 +00002953 if (adapter->netdev_registered) {
2954 unregister_netdev(netdev);
2955 adapter->netdev_registered = false;
2956 }
Mitch Williamsed0e8942017-01-24 10:23:59 -08002957 if (CLIENT_ALLOWED(adapter)) {
2958 err = i40evf_lan_del_device(adapter);
2959 if (err)
2960 dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
2961 err);
2962 }
Mitch A Williams53d0b3a2014-12-09 08:53:04 +00002963
Mitch Williamsf4a71882015-01-09 11:18:16 +00002964 /* Shut down all the garbage mashers on the detention level */
Greg Rose5eae00c2013-12-21 06:12:45 +00002965 adapter->state = __I40EVF_REMOVE;
Mitch Williamsf4a71882015-01-09 11:18:16 +00002966 adapter->aq_required = 0;
Mitch Williamsf4a71882015-01-09 11:18:16 +00002967 i40evf_request_reset(adapter);
Mitch Williams22ead372016-03-18 12:18:10 -07002968 msleep(50);
Mitch Williamsf4a71882015-01-09 11:18:16 +00002969 /* If the FW isn't responding, kick it once, but only once. */
2970 if (!i40evf_asq_done(hw)) {
2971 i40evf_request_reset(adapter);
Mitch Williams22ead372016-03-18 12:18:10 -07002972 msleep(50);
Mitch Williamsf4a71882015-01-09 11:18:16 +00002973 }
Mitch Williams8a68bad2016-12-12 15:44:10 -08002974 i40evf_free_all_tx_resources(adapter);
2975 i40evf_free_all_rx_resources(adapter);
Jacob Kelleref4603e2016-11-08 13:05:08 -08002976 i40evf_misc_irq_disable(adapter);
2977 i40evf_free_misc_irq(adapter);
2978 i40evf_reset_interrupt_capability(adapter);
2979 i40evf_free_q_vectors(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002980
Mitch Williamse5d17c32014-06-04 04:22:38 +00002981 if (adapter->watchdog_timer.function)
2982 del_timer_sync(&adapter->watchdog_timer);
2983
Mitch Williamsdbb01c82014-02-20 19:29:07 -08002984 flush_scheduled_work();
2985
Mitch Williams43a3d9b2016-04-12 08:30:44 -07002986 i40evf_free_rss(adapter);
Helin Zhang66f9af852015-10-26 19:44:34 -04002987
Greg Rose5eae00c2013-12-21 06:12:45 +00002988 if (hw->aq.asq.count)
2989 i40evf_shutdown_adminq(hw);
2990
Jesse Brandeburg8ddb3322015-11-18 15:47:06 -08002991 /* destroy the locks only once, here */
2992 mutex_destroy(&hw->aq.arq_mutex);
2993 mutex_destroy(&hw->aq.asq_mutex);
2994
Greg Rose5eae00c2013-12-21 06:12:45 +00002995 iounmap(hw->hw_addr);
2996 pci_release_regions(pdev);
Mitch Williamse284fc82015-03-27 00:12:09 -07002997 i40evf_free_all_tx_resources(adapter);
2998 i40evf_free_all_rx_resources(adapter);
Greg Rose5eae00c2013-12-21 06:12:45 +00002999 i40evf_free_queues(adapter);
3000 kfree(adapter->vf_res);
Mitch Williams6ba36a22014-08-01 13:27:14 -07003001 /* If we got removed before an up/down sequence, we've got a filter
3002 * hanging out there that we need to get rid of.
3003 */
3004 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
3005 list_del(&f->list);
3006 kfree(f);
3007 }
Mitch A Williams37dfdf32014-12-09 08:53:05 +00003008 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
3009 list_del(&f->list);
3010 kfree(f);
3011 }
Greg Rose5eae00c2013-12-21 06:12:45 +00003012
3013 free_netdev(netdev);
3014
3015 pci_disable_pcie_error_reporting(pdev);
3016
3017 pci_disable_device(pdev);
3018}
3019
3020static struct pci_driver i40evf_driver = {
3021 .name = i40evf_driver_name,
3022 .id_table = i40evf_pci_tbl,
3023 .probe = i40evf_probe,
3024 .remove = i40evf_remove,
3025#ifdef CONFIG_PM
3026 .suspend = i40evf_suspend,
3027 .resume = i40evf_resume,
3028#endif
3029 .shutdown = i40evf_shutdown,
3030};
3031
3032/**
3033 * i40e_init_module - Driver Registration Routine
3034 *
3035 * i40e_init_module is the first routine called when the driver is
3036 * loaded. All it does is register with the PCI subsystem.
3037 **/
3038static int __init i40evf_init_module(void)
3039{
3040 int ret;
Mitch Williams75a64432014-11-11 20:02:42 +00003041
Greg Rose5eae00c2013-12-21 06:12:45 +00003042 pr_info("i40evf: %s - version %s\n", i40evf_driver_string,
Mitch Williams75a64432014-11-11 20:02:42 +00003043 i40evf_driver_version);
Greg Rose5eae00c2013-12-21 06:12:45 +00003044
3045 pr_info("%s\n", i40evf_copyright);
3046
Jacob Keller6992a6c2016-08-04 11:37:01 -07003047 i40evf_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1,
3048 i40evf_driver_name);
Jesse Brandeburg2803b162015-12-22 14:25:08 -08003049 if (!i40evf_wq) {
3050 pr_err("%s: Failed to create workqueue\n", i40evf_driver_name);
3051 return -ENOMEM;
3052 }
Greg Rose5eae00c2013-12-21 06:12:45 +00003053 ret = pci_register_driver(&i40evf_driver);
3054 return ret;
3055}
3056
3057module_init(i40evf_init_module);
3058
3059/**
3060 * i40e_exit_module - Driver Exit Cleanup Routine
3061 *
3062 * i40e_exit_module is called just before the driver is removed
3063 * from memory.
3064 **/
3065static void __exit i40evf_exit_module(void)
3066{
3067 pci_unregister_driver(&i40evf_driver);
Jesse Brandeburg2803b162015-12-22 14:25:08 -08003068 destroy_workqueue(i40evf_wq);
Greg Rose5eae00c2013-12-21 06:12:45 +00003069}
3070
3071module_exit(i40evf_exit_module);
3072
3073/* i40evf_main.c */