blob: 8af6420826d1e15ede6a5b34d7f46bbfe10fa24a [file] [log] [blame]
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Shannon Nelson4fc8c672017-06-07 05:43:08 -04004 * Copyright(c) 2013 - 2017 Intel Corporation.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +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 *
Greg Rosedc641b72013-12-18 13:45:51 +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/>.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000017 *
18 * 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
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050027#include <linux/etherdevice.h>
28#include <linux/of_net.h>
29#include <linux/pci.h>
Björn Töpel0c8493d2017-05-24 07:55:34 +020030#include <linux/bpf.h>
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050031
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000032/* Local includes */
33#include "i40e.h"
Shannon Nelson4eb3f762014-03-06 08:59:58 +000034#include "i40e_diag.h"
Alexander Duyck06a5f7f2016-06-16 12:22:06 -070035#include <net/udp_tunnel.h>
Scott Petersoned0980c2017-04-13 04:45:44 -040036/* All i40e tracepoints are defined by the include below, which
37 * must be included exactly once across the whole kernel with
38 * CREATE_TRACE_POINTS defined
39 */
40#define CREATE_TRACE_POINTS
41#include "i40e_trace.h"
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000042
43const char i40e_driver_name[] = "i40e";
44static const char i40e_driver_string[] =
45 "Intel(R) Ethernet Connection XL710 Network Driver";
46
47#define DRV_KERN "-k"
48
Bimmy Pujari15990832017-01-30 12:29:37 -080049#define DRV_VERSION_MAJOR 2
50#define DRV_VERSION_MINOR 1
Jacob Keller2318b402017-04-19 09:25:53 -040051#define DRV_VERSION_BUILD 14
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000052#define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
53 __stringify(DRV_VERSION_MINOR) "." \
54 __stringify(DRV_VERSION_BUILD) DRV_KERN
55const char i40e_driver_version_str[] = DRV_VERSION;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -080056static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000057
58/* a bit of forward declarations */
59static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
Maciej Sosin373149f2017-04-05 07:50:55 -040060static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000061static int i40e_add_vsi(struct i40e_vsi *vsi);
62static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000063static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000064static int i40e_setup_misc_vector(struct i40e_pf *pf);
65static void i40e_determine_queue_usage(struct i40e_pf *pf);
66static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
Maciej Sosin373149f2017-04-05 07:50:55 -040067static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired);
68static int i40e_reset(struct i40e_pf *pf);
69static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080070static void i40e_fdir_sb_setup(struct i40e_pf *pf);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080071static int i40e_veb_get_bw_info(struct i40e_veb *veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000072
73/* i40e_pci_tbl - PCI Device ID Table
74 *
75 * Last entry must be all 0s
76 *
77 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
78 * Class, Class Mask, private data (not used) }
79 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020080static const struct pci_device_id i40e_pci_tbl[] = {
Shannon Nelsonab600852014-01-17 15:36:39 -080081 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080082 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080083 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
84 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080085 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
86 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
87 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
Mitch Williams5960d332014-09-13 07:40:47 +000088 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
Shannon Nelsonbc5166b92015-08-26 15:14:10 -040089 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
Anjali Singhai Jain35dae512015-12-22 14:25:03 -080090 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0},
91 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0},
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040092 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
93 {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
94 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
Catherine Sullivand6bf58c2016-03-18 12:18:08 -070095 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0},
Shannon Nelson48a3b512015-07-23 16:54:39 -040096 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
97 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
Carolyn Wyborny31232372016-11-21 13:03:48 -080098 {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_B), 0},
99 {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_SFP28), 0},
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000100 /* required last entry */
101 {0, }
102};
103MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
104
105#define I40E_MAX_VF_COUNT 128
106static int debug = -1;
Alexander Duyck5d4ca232016-09-30 08:21:46 -0400107module_param(debug, uint, 0);
108MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000109
110MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
111MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
112MODULE_LICENSE("GPL");
113MODULE_VERSION(DRV_VERSION);
114
Jesse Brandeburg2803b162015-12-22 14:25:08 -0800115static struct workqueue_struct *i40e_wq;
116
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000117/**
118 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
119 * @hw: pointer to the HW structure
120 * @mem: ptr to mem struct to fill out
121 * @size: size of memory requested
122 * @alignment: what to align the allocation to
123 **/
124int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
125 u64 size, u32 alignment)
126{
127 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
128
129 mem->size = ALIGN(size, alignment);
130 mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
131 &mem->pa, GFP_KERNEL);
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000132 if (!mem->va)
133 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000134
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000135 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000136}
137
138/**
139 * i40e_free_dma_mem_d - OS specific memory free for shared code
140 * @hw: pointer to the HW structure
141 * @mem: ptr to mem struct to free
142 **/
143int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
144{
145 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
146
147 dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
148 mem->va = NULL;
149 mem->pa = 0;
150 mem->size = 0;
151
152 return 0;
153}
154
155/**
156 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
157 * @hw: pointer to the HW structure
158 * @mem: ptr to mem struct to fill out
159 * @size: size of memory requested
160 **/
161int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
162 u32 size)
163{
164 mem->size = size;
165 mem->va = kzalloc(size, GFP_KERNEL);
166
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000167 if (!mem->va)
168 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000169
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000170 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000171}
172
173/**
174 * i40e_free_virt_mem_d - OS specific memory free for shared code
175 * @hw: pointer to the HW structure
176 * @mem: ptr to mem struct to free
177 **/
178int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
179{
180 /* it's ok to kfree a NULL pointer */
181 kfree(mem->va);
182 mem->va = NULL;
183 mem->size = 0;
184
185 return 0;
186}
187
188/**
189 * i40e_get_lump - find a lump of free generic resource
190 * @pf: board private structure
191 * @pile: the pile of resource to search
192 * @needed: the number of items needed
193 * @id: an owner id to stick on the items assigned
194 *
195 * Returns the base item index of the lump, or negative for error
196 *
197 * The search_hint trick and lack of advanced fit-finding only work
198 * because we're highly likely to have all the same size lump requests.
199 * Linear search time and any fragmentation should be minimal.
200 **/
201static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
202 u16 needed, u16 id)
203{
204 int ret = -ENOMEM;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000205 int i, j;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000206
207 if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
208 dev_info(&pf->pdev->dev,
209 "param err: pile=%p needed=%d id=0x%04x\n",
210 pile, needed, id);
211 return -EINVAL;
212 }
213
214 /* start the linear search with an imperfect hint */
215 i = pile->search_hint;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000216 while (i < pile->num_entries) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000217 /* skip already allocated entries */
218 if (pile->list[i] & I40E_PILE_VALID_BIT) {
219 i++;
220 continue;
221 }
222
223 /* do we have enough in this lump? */
224 for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
225 if (pile->list[i+j] & I40E_PILE_VALID_BIT)
226 break;
227 }
228
229 if (j == needed) {
230 /* there was enough, so assign it to the requestor */
231 for (j = 0; j < needed; j++)
232 pile->list[i+j] = id | I40E_PILE_VALID_BIT;
233 ret = i;
234 pile->search_hint = i + j;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000235 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000236 }
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400237
238 /* not enough, so skip over it and continue looking */
239 i += j;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000240 }
241
242 return ret;
243}
244
245/**
246 * i40e_put_lump - return a lump of generic resource
247 * @pile: the pile of resource to search
248 * @index: the base item index
249 * @id: the owner id of the items assigned
250 *
251 * Returns the count of items in the lump
252 **/
253static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
254{
255 int valid_id = (id | I40E_PILE_VALID_BIT);
256 int count = 0;
257 int i;
258
259 if (!pile || index >= pile->num_entries)
260 return -EINVAL;
261
262 for (i = index;
263 i < pile->num_entries && pile->list[i] == valid_id;
264 i++) {
265 pile->list[i] = 0;
266 count++;
267 }
268
269 if (count && index < pile->search_hint)
270 pile->search_hint = index;
271
272 return count;
273}
274
275/**
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700276 * i40e_find_vsi_from_id - searches for the vsi with the given id
277 * @pf - the pf structure to search for the vsi
278 * @id - id of the vsi it is searching for
279 **/
280struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
281{
282 int i;
283
284 for (i = 0; i < pf->num_alloc_vsi; i++)
285 if (pf->vsi[i] && (pf->vsi[i]->id == id))
286 return pf->vsi[i];
287
288 return NULL;
289}
290
291/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000292 * i40e_service_event_schedule - Schedule the service task to wake up
293 * @pf: board private structure
294 *
295 * If not already scheduled, this puts the task into the work queue
296 **/
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600297void i40e_service_event_schedule(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000298{
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -0300299 if (!test_bit(__I40E_DOWN, pf->state) &&
Jacob Keller0da36b92017-04-19 09:25:55 -0400300 !test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
Jesse Brandeburg2803b162015-12-22 14:25:08 -0800301 queue_work(i40e_wq, &pf->service_task);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000302}
303
304/**
305 * i40e_tx_timeout - Respond to a Tx Hang
306 * @netdev: network interface device structure
307 *
308 * If any port has noticed a Tx timeout, it is likely that the whole
309 * device is munged, not just the one netdev port, so go for the full
310 * reset.
311 **/
312static void i40e_tx_timeout(struct net_device *netdev)
313{
314 struct i40e_netdev_priv *np = netdev_priv(netdev);
315 struct i40e_vsi *vsi = np->vsi;
316 struct i40e_pf *pf = vsi->back;
Kiran Patilb03a8c12015-09-24 18:13:15 -0400317 struct i40e_ring *tx_ring = NULL;
318 unsigned int i, hung_queue = 0;
319 u32 head, val;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000320
321 pf->tx_timeout_count++;
322
Kiran Patilb03a8c12015-09-24 18:13:15 -0400323 /* find the stopped queue the same way the stack does */
324 for (i = 0; i < netdev->num_tx_queues; i++) {
325 struct netdev_queue *q;
326 unsigned long trans_start;
327
328 q = netdev_get_tx_queue(netdev, i);
Florian Westphal9b366272016-05-03 16:33:14 +0200329 trans_start = q->trans_start;
Kiran Patilb03a8c12015-09-24 18:13:15 -0400330 if (netif_xmit_stopped(q) &&
331 time_after(jiffies,
332 (trans_start + netdev->watchdog_timeo))) {
333 hung_queue = i;
334 break;
335 }
336 }
337
338 if (i == netdev->num_tx_queues) {
339 netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
340 } else {
341 /* now that we have an index, find the tx_ring struct */
342 for (i = 0; i < vsi->num_queue_pairs; i++) {
343 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
344 if (hung_queue ==
345 vsi->tx_rings[i]->queue_index) {
346 tx_ring = vsi->tx_rings[i];
347 break;
348 }
349 }
350 }
351 }
352
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000353 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
Kiran Patilb03a8c12015-09-24 18:13:15 -0400354 pf->tx_timeout_recovery_level = 1; /* reset after some time */
355 else if (time_before(jiffies,
356 (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
357 return; /* don't do any new action before the next timeout */
358
359 if (tx_ring) {
360 head = i40e_get_head(tx_ring);
361 /* Read interrupt register */
362 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
363 val = rd32(&pf->hw,
364 I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
365 tx_ring->vsi->base_vector - 1));
366 else
367 val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
368
369 netdev_info(netdev, "tx_timeout: VSI_seid: %d, Q %d, NTC: 0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x, INT: 0x%x\n",
370 vsi->seid, hung_queue, tx_ring->next_to_clean,
371 head, tx_ring->next_to_use,
372 readl(tx_ring->tail), val);
373 }
374
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000375 pf->tx_timeout_last_recovery = jiffies;
Kiran Patilb03a8c12015-09-24 18:13:15 -0400376 netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
377 pf->tx_timeout_recovery_level, hung_queue);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000378
379 switch (pf->tx_timeout_recovery_level) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000380 case 1:
Jacob Keller0da36b92017-04-19 09:25:55 -0400381 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000382 break;
383 case 2:
Jacob Keller0da36b92017-04-19 09:25:55 -0400384 set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000385 break;
386 case 3:
Jacob Keller0da36b92017-04-19 09:25:55 -0400387 set_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000388 break;
389 default:
390 netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000391 break;
392 }
Kiran Patilb03a8c12015-09-24 18:13:15 -0400393
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000394 i40e_service_event_schedule(pf);
395 pf->tx_timeout_recovery_level++;
396}
397
398/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000399 * i40e_get_vsi_stats_struct - Get System Network Statistics
400 * @vsi: the VSI we care about
401 *
402 * Returns the address of the device statistics structure.
403 * The statistics are actually updated from the service task.
404 **/
405struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
406{
407 return &vsi->net_stats;
408}
409
410/**
Björn Töpel74608d12017-05-24 07:55:35 +0200411 * i40e_get_netdev_stats_struct_tx - populate stats from a Tx ring
412 * @ring: Tx ring to get statistics from
413 * @stats: statistics entry to be updated
414 **/
415static void i40e_get_netdev_stats_struct_tx(struct i40e_ring *ring,
416 struct rtnl_link_stats64 *stats)
417{
418 u64 bytes, packets;
419 unsigned int start;
420
421 do {
422 start = u64_stats_fetch_begin_irq(&ring->syncp);
423 packets = ring->stats.packets;
424 bytes = ring->stats.bytes;
425 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
426
427 stats->tx_packets += packets;
428 stats->tx_bytes += bytes;
429}
430
431/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000432 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
433 * @netdev: network interface device structure
434 *
435 * Returns the address of the device statistics structure.
436 * The statistics are actually updated from the service task.
437 **/
Alexander Duyck9eed69a2017-02-21 15:55:47 -0800438static void i40e_get_netdev_stats_struct(struct net_device *netdev,
stephen hemmingerbc1f4472017-01-06 19:12:52 -0800439 struct rtnl_link_stats64 *stats)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000440{
441 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000442 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000443 struct i40e_vsi *vsi = np->vsi;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000444 struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
445 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000446
Jacob Keller0da36b92017-04-19 09:25:55 -0400447 if (test_bit(__I40E_VSI_DOWN, vsi->state))
stephen hemmingerbc1f4472017-01-06 19:12:52 -0800448 return;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +0000449
Jesse Brandeburg3c325ce2013-12-14 03:26:45 -0800450 if (!vsi->tx_rings)
stephen hemmingerbc1f4472017-01-06 19:12:52 -0800451 return;
Jesse Brandeburg3c325ce2013-12-14 03:26:45 -0800452
Alexander Duyck980e9b12013-09-28 06:01:03 +0000453 rcu_read_lock();
454 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000455 u64 bytes, packets;
456 unsigned int start;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000457
Alexander Duyck980e9b12013-09-28 06:01:03 +0000458 tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
459 if (!tx_ring)
460 continue;
Björn Töpel74608d12017-05-24 07:55:35 +0200461 i40e_get_netdev_stats_struct_tx(tx_ring, stats);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000462
Alexander Duyck980e9b12013-09-28 06:01:03 +0000463 rx_ring = &tx_ring[1];
464
465 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700466 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000467 packets = rx_ring->stats.packets;
468 bytes = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700469 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000470
471 stats->rx_packets += packets;
472 stats->rx_bytes += bytes;
Björn Töpel74608d12017-05-24 07:55:35 +0200473
474 if (i40e_enabled_xdp_vsi(vsi))
475 i40e_get_netdev_stats_struct_tx(&rx_ring[1], stats);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000476 }
477 rcu_read_unlock();
478
Akeem G Abodunrina5282f42014-05-10 04:49:03 +0000479 /* following stats updated by i40e_watchdog_subtask() */
Alexander Duyck980e9b12013-09-28 06:01:03 +0000480 stats->multicast = vsi_stats->multicast;
481 stats->tx_errors = vsi_stats->tx_errors;
482 stats->tx_dropped = vsi_stats->tx_dropped;
483 stats->rx_errors = vsi_stats->rx_errors;
Jesse Brandeburgd8201e22015-07-23 16:54:35 -0400484 stats->rx_dropped = vsi_stats->rx_dropped;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000485 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
486 stats->rx_length_errors = vsi_stats->rx_length_errors;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000487}
488
489/**
490 * i40e_vsi_reset_stats - Resets all stats of the given vsi
491 * @vsi: the VSI to have its stats reset
492 **/
493void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
494{
495 struct rtnl_link_stats64 *ns;
496 int i;
497
498 if (!vsi)
499 return;
500
501 ns = i40e_get_vsi_stats_struct(vsi);
502 memset(ns, 0, sizeof(*ns));
503 memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
504 memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
505 memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
Greg Rose8e9dca52013-12-18 13:45:53 +0000506 if (vsi->rx_rings && vsi->rx_rings[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000507 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400508 memset(&vsi->rx_rings[i]->stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000509 sizeof(vsi->rx_rings[i]->stats));
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400510 memset(&vsi->rx_rings[i]->rx_stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000511 sizeof(vsi->rx_rings[i]->rx_stats));
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400512 memset(&vsi->tx_rings[i]->stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000513 sizeof(vsi->tx_rings[i]->stats));
514 memset(&vsi->tx_rings[i]->tx_stats, 0,
515 sizeof(vsi->tx_rings[i]->tx_stats));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000516 }
Greg Rose8e9dca52013-12-18 13:45:53 +0000517 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000518 vsi->stat_offsets_loaded = false;
519}
520
521/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +0000522 * i40e_pf_reset_stats - Reset all of the stats for the given PF
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000523 * @pf: the PF to be reset
524 **/
525void i40e_pf_reset_stats(struct i40e_pf *pf)
526{
Shannon Nelsone91fdf72014-06-03 23:50:18 +0000527 int i;
528
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000529 memset(&pf->stats, 0, sizeof(pf->stats));
530 memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
531 pf->stat_offsets_loaded = false;
Shannon Nelsone91fdf72014-06-03 23:50:18 +0000532
533 for (i = 0; i < I40E_MAX_VEB; i++) {
534 if (pf->veb[i]) {
535 memset(&pf->veb[i]->stats, 0,
536 sizeof(pf->veb[i]->stats));
537 memset(&pf->veb[i]->stats_offsets, 0,
538 sizeof(pf->veb[i]->stats_offsets));
539 pf->veb[i]->stat_offsets_loaded = false;
540 }
541 }
Catherine Sullivan42bce042016-07-27 12:02:32 -0700542 pf->hw_csum_rx_error = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000543}
544
545/**
546 * i40e_stat_update48 - read and update a 48 bit stat from the chip
547 * @hw: ptr to the hardware info
548 * @hireg: the high 32 bit reg to read
549 * @loreg: the low 32 bit reg to read
550 * @offset_loaded: has the initial offset been loaded yet
551 * @offset: ptr to current offset value
552 * @stat: ptr to the stat
553 *
554 * Since the device stats are not reset at PFReset, they likely will not
555 * be zeroed when the driver starts. We'll save the first values read
556 * and use them as offsets to be subtracted from the raw values in order
557 * to report stats that count from zero. In the process, we also manage
558 * the potential roll-over.
559 **/
560static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
561 bool offset_loaded, u64 *offset, u64 *stat)
562{
563 u64 new_data;
564
Shannon Nelsonab600852014-01-17 15:36:39 -0800565 if (hw->device_id == I40E_DEV_ID_QEMU) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000566 new_data = rd32(hw, loreg);
567 new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
568 } else {
569 new_data = rd64(hw, loreg);
570 }
571 if (!offset_loaded)
572 *offset = new_data;
573 if (likely(new_data >= *offset))
574 *stat = new_data - *offset;
575 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400576 *stat = (new_data + BIT_ULL(48)) - *offset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000577 *stat &= 0xFFFFFFFFFFFFULL;
578}
579
580/**
581 * i40e_stat_update32 - read and update a 32 bit stat from the chip
582 * @hw: ptr to the hardware info
583 * @reg: the hw reg to read
584 * @offset_loaded: has the initial offset been loaded yet
585 * @offset: ptr to current offset value
586 * @stat: ptr to the stat
587 **/
588static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
589 bool offset_loaded, u64 *offset, u64 *stat)
590{
591 u32 new_data;
592
593 new_data = rd32(hw, reg);
594 if (!offset_loaded)
595 *offset = new_data;
596 if (likely(new_data >= *offset))
597 *stat = (u32)(new_data - *offset);
598 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400599 *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000600}
601
602/**
603 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
604 * @vsi: the VSI to be updated
605 **/
606void i40e_update_eth_stats(struct i40e_vsi *vsi)
607{
608 int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
609 struct i40e_pf *pf = vsi->back;
610 struct i40e_hw *hw = &pf->hw;
611 struct i40e_eth_stats *oes;
612 struct i40e_eth_stats *es; /* device's eth stats */
613
614 es = &vsi->eth_stats;
615 oes = &vsi->eth_stats_offsets;
616
617 /* Gather up the stats that the hw collects */
618 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
619 vsi->stat_offsets_loaded,
620 &oes->tx_errors, &es->tx_errors);
621 i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
622 vsi->stat_offsets_loaded,
623 &oes->rx_discards, &es->rx_discards);
Shannon Nelson41a9e552014-04-23 04:50:20 +0000624 i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
625 vsi->stat_offsets_loaded,
626 &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
627 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
628 vsi->stat_offsets_loaded,
629 &oes->tx_errors, &es->tx_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000630
631 i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
632 I40E_GLV_GORCL(stat_idx),
633 vsi->stat_offsets_loaded,
634 &oes->rx_bytes, &es->rx_bytes);
635 i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
636 I40E_GLV_UPRCL(stat_idx),
637 vsi->stat_offsets_loaded,
638 &oes->rx_unicast, &es->rx_unicast);
639 i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
640 I40E_GLV_MPRCL(stat_idx),
641 vsi->stat_offsets_loaded,
642 &oes->rx_multicast, &es->rx_multicast);
643 i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
644 I40E_GLV_BPRCL(stat_idx),
645 vsi->stat_offsets_loaded,
646 &oes->rx_broadcast, &es->rx_broadcast);
647
648 i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
649 I40E_GLV_GOTCL(stat_idx),
650 vsi->stat_offsets_loaded,
651 &oes->tx_bytes, &es->tx_bytes);
652 i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
653 I40E_GLV_UPTCL(stat_idx),
654 vsi->stat_offsets_loaded,
655 &oes->tx_unicast, &es->tx_unicast);
656 i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
657 I40E_GLV_MPTCL(stat_idx),
658 vsi->stat_offsets_loaded,
659 &oes->tx_multicast, &es->tx_multicast);
660 i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
661 I40E_GLV_BPTCL(stat_idx),
662 vsi->stat_offsets_loaded,
663 &oes->tx_broadcast, &es->tx_broadcast);
664 vsi->stat_offsets_loaded = true;
665}
666
667/**
668 * i40e_update_veb_stats - Update Switch component statistics
669 * @veb: the VEB being updated
670 **/
671static void i40e_update_veb_stats(struct i40e_veb *veb)
672{
673 struct i40e_pf *pf = veb->pf;
674 struct i40e_hw *hw = &pf->hw;
675 struct i40e_eth_stats *oes;
676 struct i40e_eth_stats *es; /* device's eth stats */
Neerav Parikhfe860af2015-07-10 19:36:02 -0400677 struct i40e_veb_tc_stats *veb_oes;
678 struct i40e_veb_tc_stats *veb_es;
679 int i, idx = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000680
681 idx = veb->stats_idx;
682 es = &veb->stats;
683 oes = &veb->stats_offsets;
Neerav Parikhfe860af2015-07-10 19:36:02 -0400684 veb_es = &veb->tc_stats;
685 veb_oes = &veb->tc_stats_offsets;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000686
687 /* Gather up the stats that the hw collects */
688 i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
689 veb->stat_offsets_loaded,
690 &oes->tx_discards, &es->tx_discards);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000691 if (hw->revision_id > 0)
692 i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
693 veb->stat_offsets_loaded,
694 &oes->rx_unknown_protocol,
695 &es->rx_unknown_protocol);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000696 i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
697 veb->stat_offsets_loaded,
698 &oes->rx_bytes, &es->rx_bytes);
699 i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
700 veb->stat_offsets_loaded,
701 &oes->rx_unicast, &es->rx_unicast);
702 i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
703 veb->stat_offsets_loaded,
704 &oes->rx_multicast, &es->rx_multicast);
705 i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
706 veb->stat_offsets_loaded,
707 &oes->rx_broadcast, &es->rx_broadcast);
708
709 i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
710 veb->stat_offsets_loaded,
711 &oes->tx_bytes, &es->tx_bytes);
712 i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
713 veb->stat_offsets_loaded,
714 &oes->tx_unicast, &es->tx_unicast);
715 i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
716 veb->stat_offsets_loaded,
717 &oes->tx_multicast, &es->tx_multicast);
718 i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
719 veb->stat_offsets_loaded,
720 &oes->tx_broadcast, &es->tx_broadcast);
Neerav Parikhfe860af2015-07-10 19:36:02 -0400721 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
722 i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
723 I40E_GLVEBTC_RPCL(i, idx),
724 veb->stat_offsets_loaded,
725 &veb_oes->tc_rx_packets[i],
726 &veb_es->tc_rx_packets[i]);
727 i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
728 I40E_GLVEBTC_RBCL(i, idx),
729 veb->stat_offsets_loaded,
730 &veb_oes->tc_rx_bytes[i],
731 &veb_es->tc_rx_bytes[i]);
732 i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
733 I40E_GLVEBTC_TPCL(i, idx),
734 veb->stat_offsets_loaded,
735 &veb_oes->tc_tx_packets[i],
736 &veb_es->tc_tx_packets[i]);
737 i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
738 I40E_GLVEBTC_TBCL(i, idx),
739 veb->stat_offsets_loaded,
740 &veb_oes->tc_tx_bytes[i],
741 &veb_es->tc_tx_bytes[i]);
742 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000743 veb->stat_offsets_loaded = true;
744}
745
746/**
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000747 * i40e_update_vsi_stats - Update the vsi statistics counters.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000748 * @vsi: the VSI to be updated
749 *
750 * There are a few instances where we store the same stat in a
751 * couple of different structs. This is partly because we have
752 * the netdev stats that need to be filled out, which is slightly
753 * different from the "eth_stats" defined by the chip and used in
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000754 * VF communications. We sort it out here.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000755 **/
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000756static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000757{
758 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000759 struct rtnl_link_stats64 *ons;
760 struct rtnl_link_stats64 *ns; /* netdev stats */
761 struct i40e_eth_stats *oes;
762 struct i40e_eth_stats *es; /* device's eth stats */
763 u32 tx_restart, tx_busy;
Akeem G Abodunrinbf00b372014-10-17 03:14:39 +0000764 struct i40e_ring *p;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000765 u32 rx_page, rx_buf;
Akeem G Abodunrinbf00b372014-10-17 03:14:39 +0000766 u64 bytes, packets;
767 unsigned int start;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400768 u64 tx_linearize;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400769 u64 tx_force_wb;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000770 u64 rx_p, rx_b;
771 u64 tx_p, tx_b;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000772 u16 q;
773
Jacob Keller0da36b92017-04-19 09:25:55 -0400774 if (test_bit(__I40E_VSI_DOWN, vsi->state) ||
775 test_bit(__I40E_CONFIG_BUSY, pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000776 return;
777
778 ns = i40e_get_vsi_stats_struct(vsi);
779 ons = &vsi->net_stats_offsets;
780 es = &vsi->eth_stats;
781 oes = &vsi->eth_stats_offsets;
782
783 /* Gather up the netdev and vsi stats that the driver collects
784 * on the fly during packet processing
785 */
786 rx_b = rx_p = 0;
787 tx_b = tx_p = 0;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400788 tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000789 rx_page = 0;
790 rx_buf = 0;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000791 rcu_read_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000792 for (q = 0; q < vsi->num_queue_pairs; q++) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000793 /* locate Tx ring */
794 p = ACCESS_ONCE(vsi->tx_rings[q]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000795
Alexander Duyck980e9b12013-09-28 06:01:03 +0000796 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700797 start = u64_stats_fetch_begin_irq(&p->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000798 packets = p->stats.packets;
799 bytes = p->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700800 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000801 tx_b += bytes;
802 tx_p += packets;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000803 tx_restart += p->tx_stats.restart_queue;
804 tx_busy += p->tx_stats.tx_busy;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400805 tx_linearize += p->tx_stats.tx_linearize;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400806 tx_force_wb += p->tx_stats.tx_force_wb;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000807
808 /* Rx queue is part of the same block as Tx queue */
809 p = &p[1];
810 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700811 start = u64_stats_fetch_begin_irq(&p->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000812 packets = p->stats.packets;
813 bytes = p->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700814 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000815 rx_b += bytes;
816 rx_p += packets;
Mitch Williams420136c2013-12-18 13:45:59 +0000817 rx_buf += p->rx_stats.alloc_buff_failed;
818 rx_page += p->rx_stats.alloc_page_failed;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000819 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000820 rcu_read_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000821 vsi->tx_restart = tx_restart;
822 vsi->tx_busy = tx_busy;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400823 vsi->tx_linearize = tx_linearize;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400824 vsi->tx_force_wb = tx_force_wb;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000825 vsi->rx_page_failed = rx_page;
826 vsi->rx_buf_failed = rx_buf;
827
828 ns->rx_packets = rx_p;
829 ns->rx_bytes = rx_b;
830 ns->tx_packets = tx_p;
831 ns->tx_bytes = tx_b;
832
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000833 /* update netdev stats from eth stats */
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000834 i40e_update_eth_stats(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000835 ons->tx_errors = oes->tx_errors;
836 ns->tx_errors = es->tx_errors;
837 ons->multicast = oes->rx_multicast;
838 ns->multicast = es->rx_multicast;
Shannon Nelson41a9e552014-04-23 04:50:20 +0000839 ons->rx_dropped = oes->rx_discards;
840 ns->rx_dropped = es->rx_discards;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000841 ons->tx_dropped = oes->tx_discards;
842 ns->tx_dropped = es->tx_discards;
843
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000844 /* pull in a couple PF stats if this is the main vsi */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000845 if (vsi == pf->vsi[pf->lan_vsi]) {
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000846 ns->rx_crc_errors = pf->stats.crc_errors;
847 ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
848 ns->rx_length_errors = pf->stats.rx_length_errors;
849 }
850}
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000851
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000852/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +0000853 * i40e_update_pf_stats - Update the PF statistics counters.
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000854 * @pf: the PF to be updated
855 **/
856static void i40e_update_pf_stats(struct i40e_pf *pf)
857{
858 struct i40e_hw_port_stats *osd = &pf->stats_offsets;
859 struct i40e_hw_port_stats *nsd = &pf->stats;
860 struct i40e_hw *hw = &pf->hw;
861 u32 val;
862 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000863
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000864 i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
865 I40E_GLPRT_GORCL(hw->port),
866 pf->stat_offsets_loaded,
867 &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
868 i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
869 I40E_GLPRT_GOTCL(hw->port),
870 pf->stat_offsets_loaded,
871 &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
872 i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
873 pf->stat_offsets_loaded,
874 &osd->eth.rx_discards,
875 &nsd->eth.rx_discards);
Shannon Nelson532d2832014-04-23 04:50:09 +0000876 i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
877 I40E_GLPRT_UPRCL(hw->port),
878 pf->stat_offsets_loaded,
879 &osd->eth.rx_unicast,
880 &nsd->eth.rx_unicast);
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000881 i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
882 I40E_GLPRT_MPRCL(hw->port),
883 pf->stat_offsets_loaded,
884 &osd->eth.rx_multicast,
885 &nsd->eth.rx_multicast);
Shannon Nelson532d2832014-04-23 04:50:09 +0000886 i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
887 I40E_GLPRT_BPRCL(hw->port),
888 pf->stat_offsets_loaded,
889 &osd->eth.rx_broadcast,
890 &nsd->eth.rx_broadcast);
891 i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
892 I40E_GLPRT_UPTCL(hw->port),
893 pf->stat_offsets_loaded,
894 &osd->eth.tx_unicast,
895 &nsd->eth.tx_unicast);
896 i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
897 I40E_GLPRT_MPTCL(hw->port),
898 pf->stat_offsets_loaded,
899 &osd->eth.tx_multicast,
900 &nsd->eth.tx_multicast);
901 i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
902 I40E_GLPRT_BPTCL(hw->port),
903 pf->stat_offsets_loaded,
904 &osd->eth.tx_broadcast,
905 &nsd->eth.tx_broadcast);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000906
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000907 i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
908 pf->stat_offsets_loaded,
909 &osd->tx_dropped_link_down,
910 &nsd->tx_dropped_link_down);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000911
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000912 i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
913 pf->stat_offsets_loaded,
914 &osd->crc_errors, &nsd->crc_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000915
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000916 i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
917 pf->stat_offsets_loaded,
918 &osd->illegal_bytes, &nsd->illegal_bytes);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000919
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000920 i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
921 pf->stat_offsets_loaded,
922 &osd->mac_local_faults,
923 &nsd->mac_local_faults);
924 i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
925 pf->stat_offsets_loaded,
926 &osd->mac_remote_faults,
927 &nsd->mac_remote_faults);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000928
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000929 i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
930 pf->stat_offsets_loaded,
931 &osd->rx_length_errors,
932 &nsd->rx_length_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000933
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000934 i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
935 pf->stat_offsets_loaded,
936 &osd->link_xon_rx, &nsd->link_xon_rx);
937 i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
938 pf->stat_offsets_loaded,
939 &osd->link_xon_tx, &nsd->link_xon_tx);
Neerav Parikh95db2392015-11-06 15:26:09 -0800940 i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
941 pf->stat_offsets_loaded,
942 &osd->link_xoff_rx, &nsd->link_xoff_rx);
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000943 i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
944 pf->stat_offsets_loaded,
945 &osd->link_xoff_tx, &nsd->link_xoff_tx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000946
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000947 for (i = 0; i < 8; i++) {
Neerav Parikh95db2392015-11-06 15:26:09 -0800948 i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
949 pf->stat_offsets_loaded,
950 &osd->priority_xoff_rx[i],
951 &nsd->priority_xoff_rx[i]);
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000952 i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000953 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000954 &osd->priority_xon_rx[i],
955 &nsd->priority_xon_rx[i]);
956 i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000957 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000958 &osd->priority_xon_tx[i],
959 &nsd->priority_xon_tx[i]);
960 i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000961 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000962 &osd->priority_xoff_tx[i],
963 &nsd->priority_xoff_tx[i]);
964 i40e_stat_update32(hw,
965 I40E_GLPRT_RXON2OFFCNT(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000966 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000967 &osd->priority_xon_2_xoff[i],
968 &nsd->priority_xon_2_xoff[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000969 }
970
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000971 i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
972 I40E_GLPRT_PRC64L(hw->port),
973 pf->stat_offsets_loaded,
974 &osd->rx_size_64, &nsd->rx_size_64);
975 i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
976 I40E_GLPRT_PRC127L(hw->port),
977 pf->stat_offsets_loaded,
978 &osd->rx_size_127, &nsd->rx_size_127);
979 i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
980 I40E_GLPRT_PRC255L(hw->port),
981 pf->stat_offsets_loaded,
982 &osd->rx_size_255, &nsd->rx_size_255);
983 i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
984 I40E_GLPRT_PRC511L(hw->port),
985 pf->stat_offsets_loaded,
986 &osd->rx_size_511, &nsd->rx_size_511);
987 i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
988 I40E_GLPRT_PRC1023L(hw->port),
989 pf->stat_offsets_loaded,
990 &osd->rx_size_1023, &nsd->rx_size_1023);
991 i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
992 I40E_GLPRT_PRC1522L(hw->port),
993 pf->stat_offsets_loaded,
994 &osd->rx_size_1522, &nsd->rx_size_1522);
995 i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
996 I40E_GLPRT_PRC9522L(hw->port),
997 pf->stat_offsets_loaded,
998 &osd->rx_size_big, &nsd->rx_size_big);
999
1000 i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
1001 I40E_GLPRT_PTC64L(hw->port),
1002 pf->stat_offsets_loaded,
1003 &osd->tx_size_64, &nsd->tx_size_64);
1004 i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
1005 I40E_GLPRT_PTC127L(hw->port),
1006 pf->stat_offsets_loaded,
1007 &osd->tx_size_127, &nsd->tx_size_127);
1008 i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
1009 I40E_GLPRT_PTC255L(hw->port),
1010 pf->stat_offsets_loaded,
1011 &osd->tx_size_255, &nsd->tx_size_255);
1012 i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
1013 I40E_GLPRT_PTC511L(hw->port),
1014 pf->stat_offsets_loaded,
1015 &osd->tx_size_511, &nsd->tx_size_511);
1016 i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
1017 I40E_GLPRT_PTC1023L(hw->port),
1018 pf->stat_offsets_loaded,
1019 &osd->tx_size_1023, &nsd->tx_size_1023);
1020 i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
1021 I40E_GLPRT_PTC1522L(hw->port),
1022 pf->stat_offsets_loaded,
1023 &osd->tx_size_1522, &nsd->tx_size_1522);
1024 i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
1025 I40E_GLPRT_PTC9522L(hw->port),
1026 pf->stat_offsets_loaded,
1027 &osd->tx_size_big, &nsd->tx_size_big);
1028
1029 i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
1030 pf->stat_offsets_loaded,
1031 &osd->rx_undersize, &nsd->rx_undersize);
1032 i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
1033 pf->stat_offsets_loaded,
1034 &osd->rx_fragments, &nsd->rx_fragments);
1035 i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
1036 pf->stat_offsets_loaded,
1037 &osd->rx_oversize, &nsd->rx_oversize);
1038 i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
1039 pf->stat_offsets_loaded,
1040 &osd->rx_jabber, &nsd->rx_jabber);
1041
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001042 /* FDIR stats */
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04001043 i40e_stat_update32(hw,
1044 I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001045 pf->stat_offsets_loaded,
1046 &osd->fd_atr_match, &nsd->fd_atr_match);
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04001047 i40e_stat_update32(hw,
1048 I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001049 pf->stat_offsets_loaded,
1050 &osd->fd_sb_match, &nsd->fd_sb_match);
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -04001051 i40e_stat_update32(hw,
1052 I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)),
1053 pf->stat_offsets_loaded,
1054 &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match);
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001055
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001056 val = rd32(hw, I40E_PRTPM_EEE_STAT);
1057 nsd->tx_lpi_status =
1058 (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
1059 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
1060 nsd->rx_lpi_status =
1061 (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
1062 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
1063 i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
1064 pf->stat_offsets_loaded,
1065 &osd->tx_lpi_count, &nsd->tx_lpi_count);
1066 i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
1067 pf->stat_offsets_loaded,
1068 &osd->rx_lpi_count, &nsd->rx_lpi_count);
1069
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -04001070 if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
Jacob Keller47994c12017-04-19 09:25:57 -04001071 !(pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED))
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -04001072 nsd->fd_sb_status = true;
1073 else
1074 nsd->fd_sb_status = false;
1075
1076 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
Jacob Keller47994c12017-04-19 09:25:57 -04001077 !(pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED))
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -04001078 nsd->fd_atr_status = true;
1079 else
1080 nsd->fd_atr_status = false;
1081
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001082 pf->stat_offsets_loaded = true;
1083}
1084
1085/**
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001086 * i40e_update_stats - Update the various statistics counters.
1087 * @vsi: the VSI to be updated
1088 *
1089 * Update the various stats for this VSI and its related entities.
1090 **/
1091void i40e_update_stats(struct i40e_vsi *vsi)
1092{
1093 struct i40e_pf *pf = vsi->back;
1094
1095 if (vsi == pf->vsi[pf->lan_vsi])
1096 i40e_update_pf_stats(pf);
1097
1098 i40e_update_vsi_stats(vsi);
1099}
1100
1101/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001102 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1103 * @vsi: the VSI to be searched
1104 * @macaddr: the MAC address
1105 * @vlan: the vlan
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001106 *
1107 * Returns ptr to the filter object or NULL
1108 **/
1109static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
Jacob Keller6622f5c2016-10-05 09:30:32 -07001110 const u8 *macaddr, s16 vlan)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001111{
1112 struct i40e_mac_filter *f;
Jacob Keller278e7d02016-10-05 09:30:37 -07001113 u64 key;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001114
1115 if (!vsi || !macaddr)
1116 return NULL;
1117
Jacob Keller278e7d02016-10-05 09:30:37 -07001118 key = i40e_addr_to_hkey(macaddr);
1119 hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001120 if ((ether_addr_equal(macaddr, f->macaddr)) &&
Jacob Keller1bc87e82016-10-05 09:30:31 -07001121 (vlan == f->vlan))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001122 return f;
1123 }
1124 return NULL;
1125}
1126
1127/**
1128 * i40e_find_mac - Find a mac addr in the macvlan filters list
1129 * @vsi: the VSI to be searched
1130 * @macaddr: the MAC address we are searching for
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001131 *
1132 * Returns the first filter with the provided MAC address or NULL if
1133 * MAC address was not found
1134 **/
Jacob Keller6622f5c2016-10-05 09:30:32 -07001135struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001136{
1137 struct i40e_mac_filter *f;
Jacob Keller278e7d02016-10-05 09:30:37 -07001138 u64 key;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001139
1140 if (!vsi || !macaddr)
1141 return NULL;
1142
Jacob Keller278e7d02016-10-05 09:30:37 -07001143 key = i40e_addr_to_hkey(macaddr);
1144 hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
Jacob Keller1bc87e82016-10-05 09:30:31 -07001145 if ((ether_addr_equal(macaddr, f->macaddr)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001146 return f;
1147 }
1148 return NULL;
1149}
1150
1151/**
1152 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1153 * @vsi: the VSI to be searched
1154 *
1155 * Returns true if VSI is in vlan mode or false otherwise
1156 **/
1157bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
1158{
Jacob Kellercbebb852016-10-05 09:30:40 -07001159 /* If we have a PVID, always operate in VLAN mode */
1160 if (vsi->info.pvid)
1161 return true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001162
Jacob Kellercbebb852016-10-05 09:30:40 -07001163 /* We need to operate in VLAN mode whenever we have any filters with
1164 * a VLAN other than I40E_VLAN_ALL. We could check the table each
1165 * time, incurring search cost repeatedly. However, we can notice two
1166 * things:
1167 *
1168 * 1) the only place where we can gain a VLAN filter is in
1169 * i40e_add_filter.
1170 *
1171 * 2) the only place where filters are actually removed is in
Jacob Keller0b7c8b52016-10-25 16:08:52 -07001172 * i40e_sync_filters_subtask.
Jacob Kellercbebb852016-10-05 09:30:40 -07001173 *
1174 * Thus, we can simply use a boolean value, has_vlan_filters which we
1175 * will set to true when we add a VLAN filter in i40e_add_filter. Then
1176 * we have to perform the full search after deleting filters in
Jacob Keller0b7c8b52016-10-25 16:08:52 -07001177 * i40e_sync_filters_subtask, but we already have to search
Jacob Kellercbebb852016-10-05 09:30:40 -07001178 * filters here and can perform the check at the same time. This
1179 * results in avoiding embedding a loop for VLAN mode inside another
1180 * loop over all the filters, and should maintain correctness as noted
1181 * above.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001182 */
Jacob Kellercbebb852016-10-05 09:30:40 -07001183 return vsi->has_vlan_filter;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001184}
1185
1186/**
Jacob Keller489a3262016-11-11 12:39:31 -08001187 * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary
1188 * @vsi: the VSI to configure
1189 * @tmp_add_list: list of filters ready to be added
1190 * @tmp_del_list: list of filters ready to be deleted
1191 * @vlan_filters: the number of active VLAN filters
1192 *
1193 * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they
1194 * behave as expected. If we have any active VLAN filters remaining or about
1195 * to be added then we need to update non-VLAN filters to be marked as VLAN=0
1196 * so that they only match against untagged traffic. If we no longer have any
1197 * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1
1198 * so that they match against both tagged and untagged traffic. In this way,
1199 * we ensure that we correctly receive the desired traffic. This ensures that
1200 * when we have an active VLAN we will receive only untagged traffic and
1201 * traffic matching active VLANs. If we have no active VLANs then we will
1202 * operate in non-VLAN mode and receive all traffic, tagged or untagged.
1203 *
1204 * Finally, in a similar fashion, this function also corrects filters when
1205 * there is an active PVID assigned to this VSI.
1206 *
1207 * In case of memory allocation failure return -ENOMEM. Otherwise, return 0.
1208 *
1209 * This function is only expected to be called from within
1210 * i40e_sync_vsi_filters.
1211 *
1212 * NOTE: This function expects to be called while under the
1213 * mac_filter_hash_lock
1214 */
1215static int i40e_correct_mac_vlan_filters(struct i40e_vsi *vsi,
1216 struct hlist_head *tmp_add_list,
1217 struct hlist_head *tmp_del_list,
1218 int vlan_filters)
1219{
Jacob Keller5cb25902016-12-12 15:44:15 -08001220 s16 pvid = le16_to_cpu(vsi->info.pvid);
Jacob Keller489a3262016-11-11 12:39:31 -08001221 struct i40e_mac_filter *f, *add_head;
Jacob Keller671889e2016-12-02 12:33:00 -08001222 struct i40e_new_mac_filter *new;
Jacob Keller489a3262016-11-11 12:39:31 -08001223 struct hlist_node *h;
1224 int bkt, new_vlan;
1225
1226 /* To determine if a particular filter needs to be replaced we
1227 * have the three following conditions:
1228 *
1229 * a) if we have a PVID assigned, then all filters which are
1230 * not marked as VLAN=PVID must be replaced with filters that
1231 * are.
1232 * b) otherwise, if we have any active VLANS, all filters
1233 * which are marked as VLAN=-1 must be replaced with
1234 * filters marked as VLAN=0
1235 * c) finally, if we do not have any active VLANS, all filters
1236 * which are marked as VLAN=0 must be replaced with filters
1237 * marked as VLAN=-1
1238 */
1239
1240 /* Update the filters about to be added in place */
Jacob Keller671889e2016-12-02 12:33:00 -08001241 hlist_for_each_entry(new, tmp_add_list, hlist) {
Jacob Keller5cb25902016-12-12 15:44:15 -08001242 if (pvid && new->f->vlan != pvid)
1243 new->f->vlan = pvid;
Jacob Keller671889e2016-12-02 12:33:00 -08001244 else if (vlan_filters && new->f->vlan == I40E_VLAN_ANY)
1245 new->f->vlan = 0;
1246 else if (!vlan_filters && new->f->vlan == 0)
1247 new->f->vlan = I40E_VLAN_ANY;
Jacob Keller489a3262016-11-11 12:39:31 -08001248 }
1249
1250 /* Update the remaining active filters */
1251 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
1252 /* Combine the checks for whether a filter needs to be changed
1253 * and then determine the new VLAN inside the if block, in
1254 * order to avoid duplicating code for adding the new filter
1255 * then deleting the old filter.
1256 */
Jacob Keller5cb25902016-12-12 15:44:15 -08001257 if ((pvid && f->vlan != pvid) ||
Jacob Keller489a3262016-11-11 12:39:31 -08001258 (vlan_filters && f->vlan == I40E_VLAN_ANY) ||
1259 (!vlan_filters && f->vlan == 0)) {
1260 /* Determine the new vlan we will be adding */
Jacob Keller5cb25902016-12-12 15:44:15 -08001261 if (pvid)
1262 new_vlan = pvid;
Jacob Keller489a3262016-11-11 12:39:31 -08001263 else if (vlan_filters)
1264 new_vlan = 0;
1265 else
1266 new_vlan = I40E_VLAN_ANY;
1267
1268 /* Create the new filter */
1269 add_head = i40e_add_filter(vsi, f->macaddr, new_vlan);
1270 if (!add_head)
1271 return -ENOMEM;
1272
Jacob Keller671889e2016-12-02 12:33:00 -08001273 /* Create a temporary i40e_new_mac_filter */
1274 new = kzalloc(sizeof(*new), GFP_ATOMIC);
1275 if (!new)
1276 return -ENOMEM;
1277
1278 new->f = add_head;
1279 new->state = add_head->state;
1280
1281 /* Add the new filter to the tmp list */
1282 hlist_add_head(&new->hlist, tmp_add_list);
Jacob Keller489a3262016-11-11 12:39:31 -08001283
1284 /* Put the original filter into the delete list */
1285 f->state = I40E_FILTER_REMOVE;
1286 hash_del(&f->hlist);
1287 hlist_add_head(&f->hlist, tmp_del_list);
1288 }
1289 }
1290
1291 vsi->has_vlan_filter = !!vlan_filters;
1292
1293 return 0;
1294}
1295
1296/**
Jacob Keller1596b5d2016-11-08 13:05:15 -08001297 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1298 * @vsi: the PF Main VSI - inappropriate for any other VSI
1299 * @macaddr: the MAC address
1300 *
1301 * Remove whatever filter the firmware set up so the driver can manage
1302 * its own filtering intelligently.
1303 **/
1304static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
1305{
1306 struct i40e_aqc_remove_macvlan_element_data element;
1307 struct i40e_pf *pf = vsi->back;
1308
1309 /* Only appropriate for the PF main VSI */
1310 if (vsi->type != I40E_VSI_MAIN)
1311 return;
1312
1313 memset(&element, 0, sizeof(element));
1314 ether_addr_copy(element.mac_addr, macaddr);
1315 element.vlan_tag = 0;
1316 /* Ignore error returns, some firmware does it this way... */
1317 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
1318 i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1319
1320 memset(&element, 0, sizeof(element));
1321 ether_addr_copy(element.mac_addr, macaddr);
1322 element.vlan_tag = 0;
1323 /* ...and some firmware does it this way. */
1324 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
1325 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
1326 i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1327}
1328
1329/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001330 * i40e_add_filter - Add a mac/vlan filter to the VSI
1331 * @vsi: the VSI to be searched
1332 * @macaddr: the MAC address
1333 * @vlan: the vlan
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001334 *
1335 * Returns ptr to the filter object or NULL when no memory available.
Kiran Patil21659032015-09-30 14:09:03 -04001336 *
Jacob Keller278e7d02016-10-05 09:30:37 -07001337 * NOTE: This function is expected to be called with mac_filter_hash_lock
Kiran Patil21659032015-09-30 14:09:03 -04001338 * being held.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001339 **/
1340struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
Jacob Keller6622f5c2016-10-05 09:30:32 -07001341 const u8 *macaddr, s16 vlan)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001342{
1343 struct i40e_mac_filter *f;
Jacob Keller278e7d02016-10-05 09:30:37 -07001344 u64 key;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001345
1346 if (!vsi || !macaddr)
1347 return NULL;
1348
Jacob Keller1bc87e82016-10-05 09:30:31 -07001349 f = i40e_find_filter(vsi, macaddr, vlan);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001350 if (!f) {
1351 f = kzalloc(sizeof(*f), GFP_ATOMIC);
1352 if (!f)
Jacob Keller1bc87e82016-10-05 09:30:31 -07001353 return NULL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001354
Jacob Kellercbebb852016-10-05 09:30:40 -07001355 /* Update the boolean indicating if we need to function in
1356 * VLAN mode.
1357 */
1358 if (vlan >= 0)
1359 vsi->has_vlan_filter = true;
1360
Greg Rose9a173902014-05-22 06:32:02 +00001361 ether_addr_copy(f->macaddr, macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001362 f->vlan = vlan;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001363 /* If we're in overflow promisc mode, set the state directly
1364 * to failed, so we don't bother to try sending the filter
1365 * to the hardware.
1366 */
Jacob Keller0da36b92017-04-19 09:25:55 -04001367 if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state))
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001368 f->state = I40E_FILTER_FAILED;
1369 else
1370 f->state = I40E_FILTER_NEW;
Jacob Keller278e7d02016-10-05 09:30:37 -07001371 INIT_HLIST_NODE(&f->hlist);
1372
1373 key = i40e_addr_to_hkey(macaddr);
1374 hash_add(vsi->mac_filter_hash, &f->hlist, key);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001375
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001376 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1377 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1378 }
1379
Jacob Keller1bc87e82016-10-05 09:30:31 -07001380 /* If we're asked to add a filter that has been marked for removal, it
1381 * is safe to simply restore it to active state. __i40e_del_filter
1382 * will have simply deleted any filters which were previously marked
1383 * NEW or FAILED, so if it is currently marked REMOVE it must have
1384 * previously been ACTIVE. Since we haven't yet run the sync filters
1385 * task, just restore this filter to the ACTIVE state so that the
1386 * sync task leaves it in place
1387 */
1388 if (f->state == I40E_FILTER_REMOVE)
1389 f->state = I40E_FILTER_ACTIVE;
1390
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001391 return f;
1392}
1393
1394/**
Jacob Keller290d2552016-10-05 09:30:36 -07001395 * __i40e_del_filter - Remove a specific filter from the VSI
1396 * @vsi: VSI to remove from
1397 * @f: the filter to remove from the list
1398 *
1399 * This function should be called instead of i40e_del_filter only if you know
1400 * the exact filter you will remove already, such as via i40e_find_filter or
1401 * i40e_find_mac.
Kiran Patil21659032015-09-30 14:09:03 -04001402 *
Jacob Keller278e7d02016-10-05 09:30:37 -07001403 * NOTE: This function is expected to be called with mac_filter_hash_lock
Kiran Patil21659032015-09-30 14:09:03 -04001404 * being held.
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001405 * ANOTHER NOTE: This function MUST be called from within the context of
1406 * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
1407 * instead of list_for_each_entry().
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001408 **/
Jacob Keller148141b2016-11-11 12:39:36 -08001409void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001410{
Jacob Keller1bc87e82016-10-05 09:30:31 -07001411 if (!f)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001412 return;
1413
Alan Bradya410c822016-12-12 15:44:07 -08001414 /* If the filter was never added to firmware then we can just delete it
1415 * directly and we don't want to set the status to remove or else an
1416 * admin queue command will unnecessarily fire.
1417 */
Jacob Keller1bc87e82016-10-05 09:30:31 -07001418 if ((f->state == I40E_FILTER_FAILED) ||
1419 (f->state == I40E_FILTER_NEW)) {
Jacob Keller278e7d02016-10-05 09:30:37 -07001420 hash_del(&f->hlist);
Jacob Keller1bc87e82016-10-05 09:30:31 -07001421 kfree(f);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001422 } else {
Jacob Keller1bc87e82016-10-05 09:30:31 -07001423 f->state = I40E_FILTER_REMOVE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001424 }
Alan Bradya410c822016-12-12 15:44:07 -08001425
1426 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1427 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001428}
1429
1430/**
Jacob Keller290d2552016-10-05 09:30:36 -07001431 * i40e_del_filter - Remove a MAC/VLAN filter from the VSI
1432 * @vsi: the VSI to be searched
1433 * @macaddr: the MAC address
1434 * @vlan: the VLAN
1435 *
Jacob Keller278e7d02016-10-05 09:30:37 -07001436 * NOTE: This function is expected to be called with mac_filter_hash_lock
Jacob Keller290d2552016-10-05 09:30:36 -07001437 * being held.
1438 * ANOTHER NOTE: This function MUST be called from within the context of
1439 * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
1440 * instead of list_for_each_entry().
1441 **/
1442void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan)
1443{
1444 struct i40e_mac_filter *f;
1445
1446 if (!vsi || !macaddr)
1447 return;
1448
1449 f = i40e_find_filter(vsi, macaddr, vlan);
1450 __i40e_del_filter(vsi, f);
1451}
1452
1453/**
Jacob Kellerfeffdbe2016-11-11 12:39:35 -08001454 * i40e_add_mac_filter - Add a MAC filter for all active VLANs
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001455 * @vsi: the VSI to be searched
1456 * @macaddr: the mac address to be filtered
1457 *
Jacob Kellerfeffdbe2016-11-11 12:39:35 -08001458 * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise,
1459 * go through all the macvlan filters and add a macvlan filter for each
Jacob Keller5feb3d72016-10-05 09:30:34 -07001460 * unique vlan that already exists. If a PVID has been assigned, instead only
1461 * add the macaddr to that VLAN.
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001462 *
Jacob Keller5feb3d72016-10-05 09:30:34 -07001463 * Returns last filter added on success, else NULL
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001464 **/
Jacob Kellerfeffdbe2016-11-11 12:39:35 -08001465struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi,
1466 const u8 *macaddr)
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001467{
Jacob Keller5feb3d72016-10-05 09:30:34 -07001468 struct i40e_mac_filter *f, *add = NULL;
Jacob Keller278e7d02016-10-05 09:30:37 -07001469 struct hlist_node *h;
1470 int bkt;
Jacob Keller5feb3d72016-10-05 09:30:34 -07001471
1472 if (vsi->info.pvid)
1473 return i40e_add_filter(vsi, macaddr,
1474 le16_to_cpu(vsi->info.pvid));
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001475
Jacob Keller7aaf95362016-11-11 12:39:33 -08001476 if (!i40e_is_vsi_in_vlan(vsi))
1477 return i40e_add_filter(vsi, macaddr, I40E_VLAN_ANY);
1478
Jacob Keller278e7d02016-10-05 09:30:37 -07001479 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Jacob Keller57b341d2016-10-05 09:30:35 -07001480 if (f->state == I40E_FILTER_REMOVE)
1481 continue;
Jacob Keller5feb3d72016-10-05 09:30:34 -07001482 add = i40e_add_filter(vsi, macaddr, f->vlan);
1483 if (!add)
1484 return NULL;
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001485 }
1486
Jacob Keller5feb3d72016-10-05 09:30:34 -07001487 return add;
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001488}
1489
1490/**
Jacob Kellerfeffdbe2016-11-11 12:39:35 -08001491 * i40e_del_mac_filter - Remove a MAC filter from all VLANs
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001492 * @vsi: the VSI to be searched
1493 * @macaddr: the mac address to be removed
1494 *
Jacob Kellerfeffdbe2016-11-11 12:39:35 -08001495 * Removes a given MAC address from a VSI regardless of what VLAN it has been
1496 * associated with.
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001497 *
1498 * Returns 0 for success, or error
1499 **/
Jacob Kellerfeffdbe2016-11-11 12:39:35 -08001500int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr)
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001501{
Jacob Keller278e7d02016-10-05 09:30:37 -07001502 struct i40e_mac_filter *f;
1503 struct hlist_node *h;
Jacob Keller290d2552016-10-05 09:30:36 -07001504 bool found = false;
Jacob Keller278e7d02016-10-05 09:30:37 -07001505 int bkt;
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001506
Jacob Keller278e7d02016-10-05 09:30:37 -07001507 WARN(!spin_is_locked(&vsi->mac_filter_hash_lock),
1508 "Missing mac_filter_hash_lock\n");
1509 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Jacob Keller290d2552016-10-05 09:30:36 -07001510 if (ether_addr_equal(macaddr, f->macaddr)) {
1511 __i40e_del_filter(vsi, f);
1512 found = true;
1513 }
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001514 }
Jacob Keller290d2552016-10-05 09:30:36 -07001515
1516 if (found)
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001517 return 0;
Jacob Keller290d2552016-10-05 09:30:36 -07001518 else
1519 return -ENOENT;
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001520}
1521
1522/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001523 * i40e_set_mac - NDO callback to set mac address
1524 * @netdev: network interface device structure
1525 * @p: pointer to an address structure
1526 *
1527 * Returns 0 on success, negative on failure
1528 **/
1529static int i40e_set_mac(struct net_device *netdev, void *p)
1530{
1531 struct i40e_netdev_priv *np = netdev_priv(netdev);
1532 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson30650cc2014-07-29 04:01:50 +00001533 struct i40e_pf *pf = vsi->back;
1534 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001535 struct sockaddr *addr = p;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001536
1537 if (!is_valid_ether_addr(addr->sa_data))
1538 return -EADDRNOTAVAIL;
1539
Shannon Nelson30650cc2014-07-29 04:01:50 +00001540 if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
1541 netdev_info(netdev, "already using mac address %pM\n",
1542 addr->sa_data);
1543 return 0;
1544 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001545
Jacob Keller0da36b92017-04-19 09:25:55 -04001546 if (test_bit(__I40E_VSI_DOWN, vsi->back->state) ||
1547 test_bit(__I40E_RESET_RECOVERY_PENDING, vsi->back->state))
Anjali Singhai Jain80f64282013-11-28 06:39:47 +00001548 return -EADDRNOTAVAIL;
1549
Shannon Nelson30650cc2014-07-29 04:01:50 +00001550 if (ether_addr_equal(hw->mac.addr, addr->sa_data))
1551 netdev_info(netdev, "returning to hw mac address %pM\n",
1552 hw->mac.addr);
1553 else
1554 netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
1555
Jacob Keller278e7d02016-10-05 09:30:37 -07001556 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Kellerfeffdbe2016-11-11 12:39:35 -08001557 i40e_del_mac_filter(vsi, netdev->dev_addr);
1558 i40e_add_mac_filter(vsi, addr->sa_data);
Jacob Keller278e7d02016-10-05 09:30:37 -07001559 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001560 ether_addr_copy(netdev->dev_addr, addr->sa_data);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001561 if (vsi->type == I40E_VSI_MAIN) {
1562 i40e_status ret;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001563
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001564 ret = i40e_aq_mac_address_write(&vsi->back->hw,
Shannon Nelsoncc412222014-06-04 01:23:21 +00001565 I40E_AQC_WRITE_TYPE_LAA_WOL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001566 addr->sa_data, NULL);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001567 if (ret)
1568 netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
1569 i40e_stat_str(hw, ret),
1570 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001571 }
1572
Jesse Brandeburgc53934c2016-01-04 10:33:06 -08001573 /* schedule our worker thread which will take care of
1574 * applying the new filter changes
1575 */
1576 i40e_service_event_schedule(vsi->back);
1577 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001578}
1579
1580/**
1581 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1582 * @vsi: the VSI being setup
1583 * @ctxt: VSI context structure
1584 * @enabled_tc: Enabled TCs bitmap
1585 * @is_add: True if called before Add VSI
1586 *
1587 * Setup VSI queue mapping for enabled traffic classes.
1588 **/
1589static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1590 struct i40e_vsi_context *ctxt,
1591 u8 enabled_tc,
1592 bool is_add)
1593{
1594 struct i40e_pf *pf = vsi->back;
1595 u16 sections = 0;
1596 u8 netdev_tc = 0;
1597 u16 numtc = 0;
1598 u16 qcount;
1599 u8 offset;
1600 u16 qmap;
1601 int i;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001602 u16 num_tc_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001603
1604 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
1605 offset = 0;
1606
1607 if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
1608 /* Find numtc from enabled TC bitmap */
1609 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08001610 if (enabled_tc & BIT(i)) /* TC is enabled */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001611 numtc++;
1612 }
1613 if (!numtc) {
1614 dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
1615 numtc = 1;
1616 }
1617 } else {
1618 /* At least TC0 is enabled in case of non-DCB case */
1619 numtc = 1;
1620 }
1621
1622 vsi->tc_config.numtc = numtc;
1623 vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001624 /* Number of queues per enabled TC */
Catherine Sullivan7d644022016-05-16 10:26:41 -07001625 qcount = vsi->alloc_queue_pairs;
1626
Anjali Singhai7f9ff472015-02-21 06:43:19 +00001627 num_tc_qps = qcount / numtc;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001628 num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001629
1630 /* Setup queue offset/count for all TCs for given VSI */
1631 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1632 /* See if the given TC is enabled for the given VSI */
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08001633 if (vsi->tc_config.enabled_tc & BIT(i)) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001634 /* TC is enabled */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001635 int pow, num_qps;
1636
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001637 switch (vsi->type) {
1638 case I40E_VSI_MAIN:
Helin Zhangacd65442015-10-26 19:44:28 -04001639 qcount = min_t(int, pf->alloc_rss_size,
1640 num_tc_qps);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001641 break;
1642 case I40E_VSI_FDIR:
1643 case I40E_VSI_SRIOV:
1644 case I40E_VSI_VMDQ2:
1645 default:
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001646 qcount = num_tc_qps;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001647 WARN_ON(i != 0);
1648 break;
1649 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001650 vsi->tc_config.tc_info[i].qoffset = offset;
1651 vsi->tc_config.tc_info[i].qcount = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001652
Shannon Nelson1e200e42015-02-27 09:15:24 +00001653 /* find the next higher power-of-2 of num queue pairs */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001654 num_qps = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001655 pow = 0;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001656 while (num_qps && (BIT_ULL(pow) < qcount)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001657 pow++;
1658 num_qps >>= 1;
1659 }
1660
1661 vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
1662 qmap =
1663 (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
1664 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
1665
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001666 offset += qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001667 } else {
1668 /* TC is not enabled so set the offset to
1669 * default queue and allocate one queue
1670 * for the given TC.
1671 */
1672 vsi->tc_config.tc_info[i].qoffset = 0;
1673 vsi->tc_config.tc_info[i].qcount = 1;
1674 vsi->tc_config.tc_info[i].netdev_tc = 0;
1675
1676 qmap = 0;
1677 }
1678 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
1679 }
1680
1681 /* Set actual Tx/Rx queue pairs */
1682 vsi->num_queue_pairs = offset;
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00001683 if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
1684 if (vsi->req_queue_pairs > 0)
1685 vsi->num_queue_pairs = vsi->req_queue_pairs;
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04001686 else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00001687 vsi->num_queue_pairs = pf->num_lan_msix;
1688 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001689
1690 /* Scheduler section valid can only be set for ADD VSI */
1691 if (is_add) {
1692 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
1693
1694 ctxt->info.up_enable_bits = enabled_tc;
1695 }
1696 if (vsi->type == I40E_VSI_SRIOV) {
1697 ctxt->info.mapping_flags |=
1698 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
1699 for (i = 0; i < vsi->num_queue_pairs; i++)
1700 ctxt->info.queue_mapping[i] =
1701 cpu_to_le16(vsi->base_queue + i);
1702 } else {
1703 ctxt->info.mapping_flags |=
1704 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
1705 ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
1706 }
1707 ctxt->info.valid_sections |= cpu_to_le16(sections);
1708}
1709
1710/**
Jacob Keller6622f5c2016-10-05 09:30:32 -07001711 * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
1712 * @netdev: the netdevice
1713 * @addr: address to add
1714 *
1715 * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
1716 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
1717 */
1718static int i40e_addr_sync(struct net_device *netdev, const u8 *addr)
1719{
1720 struct i40e_netdev_priv *np = netdev_priv(netdev);
1721 struct i40e_vsi *vsi = np->vsi;
Jacob Keller6622f5c2016-10-05 09:30:32 -07001722
Jacob Kellerfeffdbe2016-11-11 12:39:35 -08001723 if (i40e_add_mac_filter(vsi, addr))
Jacob Keller6622f5c2016-10-05 09:30:32 -07001724 return 0;
1725 else
1726 return -ENOMEM;
1727}
1728
1729/**
1730 * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
1731 * @netdev: the netdevice
1732 * @addr: address to add
1733 *
1734 * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
1735 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
1736 */
1737static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr)
1738{
1739 struct i40e_netdev_priv *np = netdev_priv(netdev);
1740 struct i40e_vsi *vsi = np->vsi;
1741
Jacob Kellerfeffdbe2016-11-11 12:39:35 -08001742 i40e_del_mac_filter(vsi, addr);
Jacob Keller6622f5c2016-10-05 09:30:32 -07001743
1744 return 0;
1745}
1746
1747/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001748 * i40e_set_rx_mode - NDO callback to set the netdev filters
1749 * @netdev: network interface device structure
1750 **/
1751static void i40e_set_rx_mode(struct net_device *netdev)
1752{
1753 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001754 struct i40e_vsi *vsi = np->vsi;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001755
Jacob Keller278e7d02016-10-05 09:30:37 -07001756 spin_lock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -04001757
Jacob Keller6622f5c2016-10-05 09:30:32 -07001758 __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
1759 __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001760
Jacob Keller278e7d02016-10-05 09:30:37 -07001761 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001762
1763 /* check for other flag changes */
1764 if (vsi->current_netdev_flags != vsi->netdev->flags) {
1765 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1766 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1767 }
Jesse Brandeburgc53934c2016-01-04 10:33:06 -08001768
1769 /* schedule our worker thread which will take care of
1770 * applying the new filter changes
1771 */
1772 i40e_service_event_schedule(vsi->back);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001773}
1774
1775/**
Jacob Keller671889e2016-12-02 12:33:00 -08001776 * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
Jacob Keller4a2ce272016-10-05 09:30:38 -07001777 * @vsi: Pointer to VSI struct
Kiran Patil21659032015-09-30 14:09:03 -04001778 * @from: Pointer to list which contains MAC filter entries - changes to
1779 * those entries needs to be undone.
1780 *
Jacob Keller671889e2016-12-02 12:33:00 -08001781 * MAC filter entries from this list were slated for deletion.
Kiran Patil21659032015-09-30 14:09:03 -04001782 **/
Jacob Keller671889e2016-12-02 12:33:00 -08001783static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
1784 struct hlist_head *from)
Kiran Patil21659032015-09-30 14:09:03 -04001785{
Jacob Keller278e7d02016-10-05 09:30:37 -07001786 struct i40e_mac_filter *f;
1787 struct hlist_node *h;
Kiran Patil21659032015-09-30 14:09:03 -04001788
Jacob Keller278e7d02016-10-05 09:30:37 -07001789 hlist_for_each_entry_safe(f, h, from, hlist) {
1790 u64 key = i40e_addr_to_hkey(f->macaddr);
1791
Kiran Patil21659032015-09-30 14:09:03 -04001792 /* Move the element back into MAC filter list*/
Jacob Keller278e7d02016-10-05 09:30:37 -07001793 hlist_del(&f->hlist);
1794 hash_add(vsi->mac_filter_hash, &f->hlist, key);
Kiran Patil21659032015-09-30 14:09:03 -04001795 }
1796}
1797
1798/**
Jacob Keller671889e2016-12-02 12:33:00 -08001799 * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
1800 * @vsi: Pointer to vsi struct
1801 * @from: Pointer to list which contains MAC filter entries - changes to
1802 * those entries needs to be undone.
1803 *
1804 * MAC filter entries from this list were slated for addition.
1805 **/
1806static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi,
1807 struct hlist_head *from)
1808{
1809 struct i40e_new_mac_filter *new;
1810 struct hlist_node *h;
1811
1812 hlist_for_each_entry_safe(new, h, from, hlist) {
1813 /* We can simply free the wrapper structure */
1814 hlist_del(&new->hlist);
1815 kfree(new);
1816 }
1817}
1818
1819/**
Jacob Kellerd88d40b2016-12-02 12:32:59 -08001820 * i40e_next_entry - Get the next non-broadcast filter from a list
Jacob Keller671889e2016-12-02 12:33:00 -08001821 * @next: pointer to filter in list
Jacob Kellerd88d40b2016-12-02 12:32:59 -08001822 *
1823 * Returns the next non-broadcast filter in the list. Required so that we
1824 * ignore broadcast filters within the list, since these are not handled via
1825 * the normal firmware update path.
1826 */
Jacob Keller671889e2016-12-02 12:33:00 -08001827static
1828struct i40e_new_mac_filter *i40e_next_filter(struct i40e_new_mac_filter *next)
Jacob Kellerd88d40b2016-12-02 12:32:59 -08001829{
Jacob Keller584a8872017-03-07 15:17:52 -08001830 hlist_for_each_entry_continue(next, hlist) {
1831 if (!is_broadcast_ether_addr(next->f->macaddr))
1832 return next;
Jacob Kellerd88d40b2016-12-02 12:32:59 -08001833 }
1834
Jacob Keller584a8872017-03-07 15:17:52 -08001835 return NULL;
Jacob Kellerd88d40b2016-12-02 12:32:59 -08001836}
1837
1838/**
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001839 * i40e_update_filter_state - Update filter state based on return data
1840 * from firmware
1841 * @count: Number of filters added
1842 * @add_list: return data from fw
1843 * @head: pointer to first filter in current batch
Kiran Patil21659032015-09-30 14:09:03 -04001844 *
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001845 * MAC filter entries from list were slated to be added to device. Returns
1846 * number of successful filters. Note that 0 does NOT mean success!
Kiran Patil21659032015-09-30 14:09:03 -04001847 **/
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001848static int
1849i40e_update_filter_state(int count,
1850 struct i40e_aqc_add_macvlan_element_data *add_list,
Jacob Keller671889e2016-12-02 12:33:00 -08001851 struct i40e_new_mac_filter *add_head)
Kiran Patil21659032015-09-30 14:09:03 -04001852{
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001853 int retval = 0;
1854 int i;
Kiran Patil21659032015-09-30 14:09:03 -04001855
Jacob Kellerac9e2392016-11-11 12:39:27 -08001856 for (i = 0; i < count; i++) {
1857 /* Always check status of each filter. We don't need to check
1858 * the firmware return status because we pre-set the filter
1859 * status to I40E_AQC_MM_ERR_NO_RES when sending the filter
1860 * request to the adminq. Thus, if it no longer matches then
1861 * we know the filter is active.
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001862 */
Jacob Kellerac9e2392016-11-11 12:39:27 -08001863 if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001864 add_head->state = I40E_FILTER_FAILED;
Jacob Kellerac9e2392016-11-11 12:39:27 -08001865 } else {
1866 add_head->state = I40E_FILTER_ACTIVE;
1867 retval++;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001868 }
Jacob Kellerac9e2392016-11-11 12:39:27 -08001869
Jacob Kellerd88d40b2016-12-02 12:32:59 -08001870 add_head = i40e_next_filter(add_head);
1871 if (!add_head)
1872 break;
Kiran Patil21659032015-09-30 14:09:03 -04001873 }
Jacob Kellerac9e2392016-11-11 12:39:27 -08001874
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001875 return retval;
Kiran Patil21659032015-09-30 14:09:03 -04001876}
1877
1878/**
Jacob Keller00936312016-10-05 09:30:41 -07001879 * i40e_aqc_del_filters - Request firmware to delete a set of filters
1880 * @vsi: ptr to the VSI
1881 * @vsi_name: name to display in messages
1882 * @list: the list of filters to send to firmware
1883 * @num_del: the number of filters to delete
1884 * @retval: Set to -EIO on failure to delete
1885 *
1886 * Send a request to firmware via AdminQ to delete a set of filters. Uses
1887 * *retval instead of a return value so that success does not force ret_val to
1888 * be set to 0. This ensures that a sequence of calls to this function
1889 * preserve the previous value of *retval on successful delete.
1890 */
1891static
1892void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name,
1893 struct i40e_aqc_remove_macvlan_element_data *list,
1894 int num_del, int *retval)
1895{
1896 struct i40e_hw *hw = &vsi->back->hw;
1897 i40e_status aq_ret;
1898 int aq_err;
1899
1900 aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL);
1901 aq_err = hw->aq.asq_last_status;
1902
1903 /* Explicitly ignore and do not report when firmware returns ENOENT */
1904 if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
1905 *retval = -EIO;
1906 dev_info(&vsi->back->pdev->dev,
1907 "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
1908 vsi_name, i40e_stat_str(hw, aq_ret),
1909 i40e_aq_str(hw, aq_err));
1910 }
1911}
1912
1913/**
1914 * i40e_aqc_add_filters - Request firmware to add a set of filters
1915 * @vsi: ptr to the VSI
1916 * @vsi_name: name to display in messages
1917 * @list: the list of filters to send to firmware
1918 * @add_head: Position in the add hlist
1919 * @num_add: the number of filters to add
1920 * @promisc_change: set to true on exit if promiscuous mode was forced on
1921 *
1922 * Send a request to firmware via AdminQ to add a chunk of filters. Will set
1923 * promisc_changed to true if the firmware has run out of space for more
1924 * filters.
1925 */
1926static
1927void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
1928 struct i40e_aqc_add_macvlan_element_data *list,
Jacob Keller671889e2016-12-02 12:33:00 -08001929 struct i40e_new_mac_filter *add_head,
Jacob Keller00936312016-10-05 09:30:41 -07001930 int num_add, bool *promisc_changed)
1931{
1932 struct i40e_hw *hw = &vsi->back->hw;
Jacob Keller00936312016-10-05 09:30:41 -07001933 int aq_err, fcnt;
1934
Jacob Kellerac9e2392016-11-11 12:39:27 -08001935 i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL);
Jacob Keller00936312016-10-05 09:30:41 -07001936 aq_err = hw->aq.asq_last_status;
Jacob Kellerac9e2392016-11-11 12:39:27 -08001937 fcnt = i40e_update_filter_state(num_add, list, add_head);
Jacob Keller00936312016-10-05 09:30:41 -07001938
1939 if (fcnt != num_add) {
1940 *promisc_changed = true;
Jacob Keller0da36b92017-04-19 09:25:55 -04001941 set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
Jacob Keller00936312016-10-05 09:30:41 -07001942 dev_warn(&vsi->back->pdev->dev,
1943 "Error %s adding RX filters on %s, promiscuous mode forced on\n",
1944 i40e_aq_str(hw, aq_err),
1945 vsi_name);
1946 }
1947}
1948
1949/**
Jacob Keller435c0842016-11-08 13:05:10 -08001950 * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags
1951 * @vsi: pointer to the VSI
1952 * @f: filter data
1953 *
1954 * This function sets or clears the promiscuous broadcast flags for VLAN
1955 * filters in order to properly receive broadcast frames. Assumes that only
1956 * broadcast filters are passed.
Jacob Keller671889e2016-12-02 12:33:00 -08001957 *
1958 * Returns status indicating success or failure;
Jacob Keller435c0842016-11-08 13:05:10 -08001959 **/
Jacob Keller671889e2016-12-02 12:33:00 -08001960static i40e_status
1961i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name,
1962 struct i40e_mac_filter *f)
Jacob Keller435c0842016-11-08 13:05:10 -08001963{
1964 bool enable = f->state == I40E_FILTER_NEW;
1965 struct i40e_hw *hw = &vsi->back->hw;
1966 i40e_status aq_ret;
1967
1968 if (f->vlan == I40E_VLAN_ANY) {
1969 aq_ret = i40e_aq_set_vsi_broadcast(hw,
1970 vsi->seid,
1971 enable,
1972 NULL);
1973 } else {
1974 aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw,
1975 vsi->seid,
1976 enable,
1977 f->vlan,
1978 NULL);
1979 }
1980
Jacob Keller671889e2016-12-02 12:33:00 -08001981 if (aq_ret)
Jacob Keller435c0842016-11-08 13:05:10 -08001982 dev_warn(&vsi->back->pdev->dev,
1983 "Error %s setting broadcast promiscuous mode on %s\n",
1984 i40e_aq_str(hw, hw->aq.asq_last_status),
1985 vsi_name);
Jacob Keller671889e2016-12-02 12:33:00 -08001986
1987 return aq_ret;
Jacob Keller435c0842016-11-08 13:05:10 -08001988}
1989
1990/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001991 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1992 * @vsi: ptr to the VSI
1993 *
1994 * Push any outstanding VSI filter changes through the AdminQ.
1995 *
1996 * Returns 0 or error value
1997 **/
Jesse Brandeburg17652c62015-11-05 17:01:02 -08001998int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001999{
Jacob Keller278e7d02016-10-05 09:30:37 -07002000 struct hlist_head tmp_add_list, tmp_del_list;
Jacob Keller671889e2016-12-02 12:33:00 -08002001 struct i40e_mac_filter *f;
2002 struct i40e_new_mac_filter *new, *add_head = NULL;
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002003 struct i40e_hw *hw = &vsi->back->hw;
Jacob Keller38326212016-11-11 12:39:26 -08002004 unsigned int failed_filters = 0;
Alan Brady84f5ca62016-10-05 09:30:39 -07002005 unsigned int vlan_filters = 0;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002006 bool promisc_changed = false;
Shannon Nelson2d1de822016-05-16 10:26:44 -07002007 char vsi_name[16] = "PF";
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002008 int filter_list_len = 0;
Mitch Williamsea02e902015-11-09 15:35:50 -08002009 i40e_status aq_ret = 0;
Alan Brady84f5ca62016-10-05 09:30:39 -07002010 u32 changed_flags = 0;
Jacob Keller278e7d02016-10-05 09:30:37 -07002011 struct hlist_node *h;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002012 struct i40e_pf *pf;
2013 int num_add = 0;
2014 int num_del = 0;
Alan Brady84f5ca62016-10-05 09:30:39 -07002015 int retval = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002016 u16 cmd_flags;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002017 int list_size;
Jacob Keller278e7d02016-10-05 09:30:37 -07002018 int bkt;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002019
2020 /* empty array typed pointers, kcalloc later */
2021 struct i40e_aqc_add_macvlan_element_data *add_list;
2022 struct i40e_aqc_remove_macvlan_element_data *del_list;
2023
Jacob Keller0da36b92017-04-19 09:25:55 -04002024 while (test_and_set_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002025 usleep_range(1000, 2000);
2026 pf = vsi->back;
2027
2028 if (vsi->netdev) {
2029 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
2030 vsi->current_netdev_flags = vsi->netdev->flags;
2031 }
2032
Jacob Keller278e7d02016-10-05 09:30:37 -07002033 INIT_HLIST_HEAD(&tmp_add_list);
2034 INIT_HLIST_HEAD(&tmp_del_list);
Kiran Patil21659032015-09-30 14:09:03 -04002035
Shannon Nelson2d1de822016-05-16 10:26:44 -07002036 if (vsi->type == I40E_VSI_SRIOV)
2037 snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
2038 else if (vsi->type != I40E_VSI_MAIN)
2039 snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
2040
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002041 if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
2042 vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
2043
Jacob Keller278e7d02016-10-05 09:30:37 -07002044 spin_lock_bh(&vsi->mac_filter_hash_lock);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002045 /* Create a list of filters to delete. */
Jacob Keller278e7d02016-10-05 09:30:37 -07002046 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002047 if (f->state == I40E_FILTER_REMOVE) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002048 /* Move the element into temporary del_list */
Jacob Keller278e7d02016-10-05 09:30:37 -07002049 hash_del(&f->hlist);
2050 hlist_add_head(&f->hlist, &tmp_del_list);
Alan Brady84f5ca62016-10-05 09:30:39 -07002051
2052 /* Avoid counting removed filters */
2053 continue;
Kiran Patil21659032015-09-30 14:09:03 -04002054 }
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002055 if (f->state == I40E_FILTER_NEW) {
Jacob Keller671889e2016-12-02 12:33:00 -08002056 /* Create a temporary i40e_new_mac_filter */
2057 new = kzalloc(sizeof(*new), GFP_ATOMIC);
2058 if (!new)
2059 goto err_no_memory_locked;
2060
2061 /* Store pointer to the real filter */
2062 new->f = f;
2063 new->state = f->state;
2064
2065 /* Add it to the hash list */
2066 hlist_add_head(&new->hlist, &tmp_add_list);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002067 }
Alan Brady84f5ca62016-10-05 09:30:39 -07002068
Jacob Keller489a3262016-11-11 12:39:31 -08002069 /* Count the number of active (current and new) VLAN
2070 * filters we have now. Does not count filters which
2071 * are marked for deletion.
Alan Brady84f5ca62016-10-05 09:30:39 -07002072 */
2073 if (f->vlan > 0)
2074 vlan_filters++;
Alan Brady84f5ca62016-10-05 09:30:39 -07002075 }
2076
Jacob Keller489a3262016-11-11 12:39:31 -08002077 retval = i40e_correct_mac_vlan_filters(vsi,
2078 &tmp_add_list,
2079 &tmp_del_list,
2080 vlan_filters);
2081 if (retval)
2082 goto err_no_memory_locked;
Alan Brady84f5ca62016-10-05 09:30:39 -07002083
Jacob Keller278e7d02016-10-05 09:30:37 -07002084 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -04002085 }
2086
2087 /* Now process 'del_list' outside the lock */
Jacob Keller278e7d02016-10-05 09:30:37 -07002088 if (!hlist_empty(&tmp_del_list)) {
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002089 filter_list_len = hw->aq.asq_buf_size /
Kiran Patil21659032015-09-30 14:09:03 -04002090 sizeof(struct i40e_aqc_remove_macvlan_element_data);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002091 list_size = filter_list_len *
Shannon Nelsonf1199992015-11-19 11:34:23 -08002092 sizeof(struct i40e_aqc_remove_macvlan_element_data);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002093 del_list = kzalloc(list_size, GFP_ATOMIC);
Jacob Keller4a2ce272016-10-05 09:30:38 -07002094 if (!del_list)
2095 goto err_no_memory;
Kiran Patil21659032015-09-30 14:09:03 -04002096
Jacob Keller278e7d02016-10-05 09:30:37 -07002097 hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002098 cmd_flags = 0;
2099
Jacob Keller435c0842016-11-08 13:05:10 -08002100 /* handle broadcast filters by updating the broadcast
Jacob Kellerd88d40b2016-12-02 12:32:59 -08002101 * promiscuous flag and release filter list.
Jacob Keller435c0842016-11-08 13:05:10 -08002102 */
2103 if (is_broadcast_ether_addr(f->macaddr)) {
2104 i40e_aqc_broadcast_filter(vsi, vsi_name, f);
2105
2106 hlist_del(&f->hlist);
2107 kfree(f);
2108 continue;
2109 }
2110
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002111 /* add to delete list */
Greg Rose9a173902014-05-22 06:32:02 +00002112 ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002113 if (f->vlan == I40E_VLAN_ANY) {
2114 del_list[num_del].vlan_tag = 0;
Alan Bradya6cb9142016-09-06 18:05:07 -07002115 cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002116 } else {
2117 del_list[num_del].vlan_tag =
2118 cpu_to_le16((u16)(f->vlan));
2119 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002120
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002121 cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
2122 del_list[num_del].flags = cmd_flags;
2123 num_del++;
2124
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002125 /* flush a full buffer */
2126 if (num_del == filter_list_len) {
Jacob Keller00936312016-10-05 09:30:41 -07002127 i40e_aqc_del_filters(vsi, vsi_name, del_list,
2128 num_del, &retval);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002129 memset(del_list, 0, list_size);
Jacob Keller00936312016-10-05 09:30:41 -07002130 num_del = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002131 }
Kiran Patil21659032015-09-30 14:09:03 -04002132 /* Release memory for MAC filter entries which were
2133 * synced up with HW.
2134 */
Jacob Keller278e7d02016-10-05 09:30:37 -07002135 hlist_del(&f->hlist);
Kiran Patil21659032015-09-30 14:09:03 -04002136 kfree(f);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002137 }
Kiran Patil21659032015-09-30 14:09:03 -04002138
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002139 if (num_del) {
Jacob Keller00936312016-10-05 09:30:41 -07002140 i40e_aqc_del_filters(vsi, vsi_name, del_list,
2141 num_del, &retval);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002142 }
2143
2144 kfree(del_list);
2145 del_list = NULL;
Kiran Patil21659032015-09-30 14:09:03 -04002146 }
2147
Jacob Keller278e7d02016-10-05 09:30:37 -07002148 if (!hlist_empty(&tmp_add_list)) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002149 /* Do all the adds now. */
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002150 filter_list_len = hw->aq.asq_buf_size /
Shannon Nelsonf1199992015-11-19 11:34:23 -08002151 sizeof(struct i40e_aqc_add_macvlan_element_data);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002152 list_size = filter_list_len *
2153 sizeof(struct i40e_aqc_add_macvlan_element_data);
2154 add_list = kzalloc(list_size, GFP_ATOMIC);
Jacob Keller4a2ce272016-10-05 09:30:38 -07002155 if (!add_list)
2156 goto err_no_memory;
2157
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002158 num_add = 0;
Jacob Keller671889e2016-12-02 12:33:00 -08002159 hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
Jacob Kellerd19cb642017-04-21 13:38:05 -07002160 if (test_bit(__I40E_VSI_OVERFLOW_PROMISC,
Jacob Keller0da36b92017-04-19 09:25:55 -04002161 vsi->state)) {
Jacob Keller671889e2016-12-02 12:33:00 -08002162 new->state = I40E_FILTER_FAILED;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002163 continue;
2164 }
Jacob Keller435c0842016-11-08 13:05:10 -08002165
2166 /* handle broadcast filters by updating the broadcast
2167 * promiscuous flag instead of adding a MAC filter.
2168 */
Jacob Keller671889e2016-12-02 12:33:00 -08002169 if (is_broadcast_ether_addr(new->f->macaddr)) {
2170 if (i40e_aqc_broadcast_filter(vsi, vsi_name,
2171 new->f))
2172 new->state = I40E_FILTER_FAILED;
2173 else
2174 new->state = I40E_FILTER_ACTIVE;
Jacob Keller435c0842016-11-08 13:05:10 -08002175 continue;
2176 }
2177
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002178 /* add to add array */
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002179 if (num_add == 0)
Jacob Keller671889e2016-12-02 12:33:00 -08002180 add_head = new;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002181 cmd_flags = 0;
Jacob Keller671889e2016-12-02 12:33:00 -08002182 ether_addr_copy(add_list[num_add].mac_addr,
2183 new->f->macaddr);
2184 if (new->f->vlan == I40E_VLAN_ANY) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002185 add_list[num_add].vlan_tag = 0;
2186 cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
2187 } else {
2188 add_list[num_add].vlan_tag =
Jacob Keller671889e2016-12-02 12:33:00 -08002189 cpu_to_le16((u16)(new->f->vlan));
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002190 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002191 add_list[num_add].queue_number = 0;
Jacob Kellerac9e2392016-11-11 12:39:27 -08002192 /* set invalid match method for later detection */
Keller, Jacob E0266ac42016-12-09 13:39:21 -08002193 add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002194 cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002195 add_list[num_add].flags = cpu_to_le16(cmd_flags);
2196 num_add++;
2197
2198 /* flush a full buffer */
2199 if (num_add == filter_list_len) {
Jacob Keller00936312016-10-05 09:30:41 -07002200 i40e_aqc_add_filters(vsi, vsi_name, add_list,
2201 add_head, num_add,
2202 &promisc_changed);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002203 memset(add_list, 0, list_size);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002204 num_add = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002205 }
2206 }
2207 if (num_add) {
Jacob Keller00936312016-10-05 09:30:41 -07002208 i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head,
2209 num_add, &promisc_changed);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002210 }
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002211 /* Now move all of the filters from the temp add list back to
2212 * the VSI's list.
2213 */
Jacob Keller278e7d02016-10-05 09:30:37 -07002214 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller671889e2016-12-02 12:33:00 -08002215 hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
2216 /* Only update the state if we're still NEW */
2217 if (new->f->state == I40E_FILTER_NEW)
2218 new->f->state = new->state;
2219 hlist_del(&new->hlist);
2220 kfree(new);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002221 }
Jacob Keller278e7d02016-10-05 09:30:37 -07002222 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002223 kfree(add_list);
2224 add_list = NULL;
2225 }
2226
Jacob Keller38326212016-11-11 12:39:26 -08002227 /* Determine the number of active and failed filters. */
2228 spin_lock_bh(&vsi->mac_filter_hash_lock);
2229 vsi->active_filters = 0;
2230 hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
2231 if (f->state == I40E_FILTER_ACTIVE)
2232 vsi->active_filters++;
2233 else if (f->state == I40E_FILTER_FAILED)
2234 failed_filters++;
2235 }
2236 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2237
2238 /* If promiscuous mode has changed, we need to calculate a new
2239 * threshold for when we are safe to exit
2240 */
2241 if (promisc_changed)
2242 vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
2243
2244 /* Check if we are able to exit overflow promiscuous mode. We can
2245 * safely exit if we didn't just enter, we no longer have any failed
2246 * filters, and we have reduced filters below the threshold value.
2247 */
Jacob Keller0da36b92017-04-19 09:25:55 -04002248 if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state) &&
Jacob Keller38326212016-11-11 12:39:26 -08002249 !promisc_changed && !failed_filters &&
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002250 (vsi->active_filters < vsi->promisc_threshold)) {
Jacob Keller38326212016-11-11 12:39:26 -08002251 dev_info(&pf->pdev->dev,
2252 "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
2253 vsi_name);
Jacob Keller0da36b92017-04-19 09:25:55 -04002254 clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
Jacob Keller38326212016-11-11 12:39:26 -08002255 promisc_changed = true;
2256 vsi->promisc_threshold = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002257 }
2258
Anjali Singhai Jaina856b5c2016-04-13 03:08:23 -07002259 /* if the VF is not trusted do not do promisc */
2260 if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
Jacob Keller0da36b92017-04-19 09:25:55 -04002261 clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
Anjali Singhai Jaina856b5c2016-04-13 03:08:23 -07002262 goto out;
2263 }
2264
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002265 /* check for changes in promiscuous modes */
2266 if (changed_flags & IFF_ALLMULTI) {
2267 bool cur_multipromisc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002268
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002269 cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
Mitch Williamsea02e902015-11-09 15:35:50 -08002270 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
2271 vsi->seid,
2272 cur_multipromisc,
2273 NULL);
2274 if (aq_ret) {
2275 retval = i40e_aq_rc_to_posix(aq_ret,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002276 hw->aq.asq_last_status);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002277 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002278 "set multi promisc failed on %s, err %s aq_err %s\n",
2279 vsi_name,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002280 i40e_stat_str(hw, aq_ret),
2281 i40e_aq_str(hw, hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002282 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002283 }
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002284 if ((changed_flags & IFF_PROMISC) ||
2285 (promisc_changed &&
Jacob Keller0da36b92017-04-19 09:25:55 -04002286 test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state))) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002287 bool cur_promisc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002288
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002289 cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
Jacob Kellerd19cb642017-04-21 13:38:05 -07002290 test_bit(__I40E_VSI_OVERFLOW_PROMISC,
Jacob Keller0da36b92017-04-19 09:25:55 -04002291 vsi->state));
Anjali Singhai Jain6784ed52016-01-15 14:33:13 -08002292 if ((vsi->type == I40E_VSI_MAIN) &&
2293 (pf->lan_veb != I40E_NO_VEB) &&
2294 !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002295 /* set defport ON for Main VSI instead of true promisc
2296 * this way we will get all unicast/multicast and VLAN
2297 * promisc behavior but will not get VF or VMDq traffic
2298 * replicated on the Main VSI.
2299 */
2300 if (pf->cur_promisc != cur_promisc) {
2301 pf->cur_promisc = cur_promisc;
Mitch Williams5bc16032016-05-16 10:26:43 -07002302 if (cur_promisc)
2303 aq_ret =
2304 i40e_aq_set_default_vsi(hw,
2305 vsi->seid,
2306 NULL);
2307 else
2308 aq_ret =
2309 i40e_aq_clear_default_vsi(hw,
2310 vsi->seid,
2311 NULL);
2312 if (aq_ret) {
2313 retval = i40e_aq_rc_to_posix(aq_ret,
2314 hw->aq.asq_last_status);
2315 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002316 "Set default VSI failed on %s, err %s, aq_err %s\n",
2317 vsi_name,
Mitch Williams5bc16032016-05-16 10:26:43 -07002318 i40e_stat_str(hw, aq_ret),
2319 i40e_aq_str(hw,
2320 hw->aq.asq_last_status));
2321 }
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002322 }
2323 } else {
Mitch Williamsea02e902015-11-09 15:35:50 -08002324 aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002325 hw,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002326 vsi->seid,
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002327 cur_promisc, NULL,
2328 true);
Mitch Williamsea02e902015-11-09 15:35:50 -08002329 if (aq_ret) {
2330 retval =
2331 i40e_aq_rc_to_posix(aq_ret,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002332 hw->aq.asq_last_status);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002333 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002334 "set unicast promisc failed on %s, err %s, aq_err %s\n",
2335 vsi_name,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002336 i40e_stat_str(hw, aq_ret),
2337 i40e_aq_str(hw,
2338 hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002339 }
2340 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002341 hw,
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002342 vsi->seid,
2343 cur_promisc, NULL);
Mitch Williamsea02e902015-11-09 15:35:50 -08002344 if (aq_ret) {
2345 retval =
2346 i40e_aq_rc_to_posix(aq_ret,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002347 hw->aq.asq_last_status);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002348 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002349 "set multicast promisc failed on %s, err %s, aq_err %s\n",
2350 vsi_name,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002351 i40e_stat_str(hw, aq_ret),
2352 i40e_aq_str(hw,
2353 hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002354 }
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002355 }
Mitch Williamsea02e902015-11-09 15:35:50 -08002356 aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
2357 vsi->seid,
2358 cur_promisc, NULL);
2359 if (aq_ret) {
2360 retval = i40e_aq_rc_to_posix(aq_ret,
2361 pf->hw.aq.asq_last_status);
Greg Rose1a103702013-11-28 06:42:39 +00002362 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002363 "set brdcast promisc failed, err %s, aq_err %s\n",
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002364 i40e_stat_str(hw, aq_ret),
2365 i40e_aq_str(hw,
2366 hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002367 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002368 }
Mitch Williamsea02e902015-11-09 15:35:50 -08002369out:
Jesse Brandeburg2818ccd2016-01-13 16:51:38 -08002370 /* if something went wrong then set the changed flag so we try again */
2371 if (retval)
2372 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
2373
Jacob Keller0da36b92017-04-19 09:25:55 -04002374 clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
Mitch Williamsea02e902015-11-09 15:35:50 -08002375 return retval;
Jacob Keller4a2ce272016-10-05 09:30:38 -07002376
2377err_no_memory:
2378 /* Restore elements on the temporary add and delete lists */
2379 spin_lock_bh(&vsi->mac_filter_hash_lock);
Alan Brady84f5ca62016-10-05 09:30:39 -07002380err_no_memory_locked:
Jacob Keller671889e2016-12-02 12:33:00 -08002381 i40e_undo_del_filter_entries(vsi, &tmp_del_list);
2382 i40e_undo_add_filter_entries(vsi, &tmp_add_list);
Jacob Keller4a2ce272016-10-05 09:30:38 -07002383 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2384
2385 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
Jacob Keller0da36b92017-04-19 09:25:55 -04002386 clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
Jacob Keller4a2ce272016-10-05 09:30:38 -07002387 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002388}
2389
2390/**
2391 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2392 * @pf: board private structure
2393 **/
2394static void i40e_sync_filters_subtask(struct i40e_pf *pf)
2395{
2396 int v;
2397
2398 if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
2399 return;
2400 pf->flags &= ~I40E_FLAG_FILTER_SYNC;
2401
Mitch Williams505682c2014-05-20 08:01:37 +00002402 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002403 if (pf->vsi[v] &&
Jesse Brandeburg17652c62015-11-05 17:01:02 -08002404 (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
2405 int ret = i40e_sync_vsi_filters(pf->vsi[v]);
2406
2407 if (ret) {
2408 /* come back and try again later */
2409 pf->flags |= I40E_FLAG_FILTER_SYNC;
2410 break;
2411 }
2412 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002413 }
2414}
2415
2416/**
Björn Töpel0c8493d2017-05-24 07:55:34 +02002417 * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
2418 * @vsi: the vsi
2419 **/
2420static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi)
2421{
2422 if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
2423 return I40E_RXBUFFER_2048;
2424 else
2425 return I40E_RXBUFFER_3072;
2426}
2427
2428/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002429 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2430 * @netdev: network interface device structure
2431 * @new_mtu: new value for maximum frame size
2432 *
2433 * Returns 0 on success, negative on failure
2434 **/
2435static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
2436{
2437 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002438 struct i40e_vsi *vsi = np->vsi;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -08002439 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002440
Björn Töpel0c8493d2017-05-24 07:55:34 +02002441 if (i40e_enabled_xdp_vsi(vsi)) {
2442 int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
2443
2444 if (frame_size > i40e_max_xdp_frame_size(vsi))
2445 return -EINVAL;
2446 }
2447
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002448 netdev_info(netdev, "changing MTU from %d to %d\n",
2449 netdev->mtu, new_mtu);
2450 netdev->mtu = new_mtu;
2451 if (netif_running(netdev))
2452 i40e_vsi_reinit_locked(vsi);
Mitch Williams0ef2d5a2017-01-24 10:24:00 -08002453 pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED |
2454 I40E_FLAG_CLIENT_L2_CHANGE);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002455 return 0;
2456}
2457
2458/**
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002459 * i40e_ioctl - Access the hwtstamp interface
2460 * @netdev: network interface device structure
2461 * @ifr: interface request data
2462 * @cmd: ioctl command
2463 **/
2464int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2465{
2466 struct i40e_netdev_priv *np = netdev_priv(netdev);
2467 struct i40e_pf *pf = np->vsi->back;
2468
2469 switch (cmd) {
2470 case SIOCGHWTSTAMP:
2471 return i40e_ptp_get_ts_config(pf, ifr);
2472 case SIOCSHWTSTAMP:
2473 return i40e_ptp_set_ts_config(pf, ifr);
2474 default:
2475 return -EOPNOTSUPP;
2476 }
2477}
2478
2479/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002480 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2481 * @vsi: the vsi being adjusted
2482 **/
2483void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
2484{
2485 struct i40e_vsi_context ctxt;
2486 i40e_status ret;
2487
2488 if ((vsi->info.valid_sections &
2489 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2490 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
2491 return; /* already enabled */
2492
2493 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2494 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2495 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
2496
2497 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002498 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002499 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2500 if (ret) {
2501 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002502 "update vlan stripping failed, err %s aq_err %s\n",
2503 i40e_stat_str(&vsi->back->hw, ret),
2504 i40e_aq_str(&vsi->back->hw,
2505 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002506 }
2507}
2508
2509/**
2510 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2511 * @vsi: the vsi being adjusted
2512 **/
2513void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
2514{
2515 struct i40e_vsi_context ctxt;
2516 i40e_status ret;
2517
2518 if ((vsi->info.valid_sections &
2519 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2520 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
2521 I40E_AQ_VSI_PVLAN_EMOD_MASK))
2522 return; /* already disabled */
2523
2524 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2525 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2526 I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
2527
2528 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002529 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002530 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2531 if (ret) {
2532 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002533 "update vlan stripping failed, err %s aq_err %s\n",
2534 i40e_stat_str(&vsi->back->hw, ret),
2535 i40e_aq_str(&vsi->back->hw,
2536 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002537 }
2538}
2539
2540/**
2541 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2542 * @netdev: network interface to be adjusted
2543 * @features: netdev features to test if VLAN offload is enabled or not
2544 **/
2545static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
2546{
2547 struct i40e_netdev_priv *np = netdev_priv(netdev);
2548 struct i40e_vsi *vsi = np->vsi;
2549
2550 if (features & NETIF_F_HW_VLAN_CTAG_RX)
2551 i40e_vlan_stripping_enable(vsi);
2552 else
2553 i40e_vlan_stripping_disable(vsi);
2554}
2555
2556/**
Jacob Keller490a4ad2016-11-11 12:39:29 -08002557 * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002558 * @vsi: the vsi being configured
2559 * @vid: vlan id to be added (0 = untagged only , -1 = any)
Jacob Keller490a4ad2016-11-11 12:39:29 -08002560 *
2561 * This is a helper function for adding a new MAC/VLAN filter with the
2562 * specified VLAN for each existing MAC address already in the hash table.
2563 * This function does *not* perform any accounting to update filters based on
2564 * VLAN mode.
2565 *
2566 * NOTE: this function expects to be called while under the
2567 * mac_filter_hash_lock
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002568 **/
Jacob Keller9af52f62016-11-11 12:39:30 -08002569int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002570{
Jacob Keller490a4ad2016-11-11 12:39:29 -08002571 struct i40e_mac_filter *f, *add_f;
Jacob Keller278e7d02016-10-05 09:30:37 -07002572 struct hlist_node *h;
2573 int bkt;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002574
Jacob Keller278e7d02016-10-05 09:30:37 -07002575 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Jacob Keller57b341d2016-10-05 09:30:35 -07002576 if (f->state == I40E_FILTER_REMOVE)
2577 continue;
Jacob Keller1bc87e82016-10-05 09:30:31 -07002578 add_f = i40e_add_filter(vsi, f->macaddr, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002579 if (!add_f) {
2580 dev_info(&vsi->back->pdev->dev,
2581 "Could not add vlan filter %d for %pM\n",
2582 vid, f->macaddr);
2583 return -ENOMEM;
2584 }
2585 }
2586
Jacob Keller490a4ad2016-11-11 12:39:29 -08002587 return 0;
2588}
2589
2590/**
2591 * i40e_vsi_add_vlan - Add VSI membership for given VLAN
2592 * @vsi: the VSI being configured
Jacob Kellerf94484b2016-12-07 14:05:34 -08002593 * @vid: VLAN id to be added
Jacob Keller490a4ad2016-11-11 12:39:29 -08002594 **/
Jacob Kellerf94484b2016-12-07 14:05:34 -08002595int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid)
Jacob Keller490a4ad2016-11-11 12:39:29 -08002596{
Jacob Keller489a3262016-11-11 12:39:31 -08002597 int err;
Jacob Keller490a4ad2016-11-11 12:39:29 -08002598
Jacob Kellerf94484b2016-12-07 14:05:34 -08002599 if (!vid || vsi->info.pvid)
2600 return -EINVAL;
2601
Jacob Keller490a4ad2016-11-11 12:39:29 -08002602 /* Locked once because all functions invoked below iterates list*/
2603 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller490a4ad2016-11-11 12:39:29 -08002604 err = i40e_add_vlan_all_mac(vsi, vid);
Jacob Keller278e7d02016-10-05 09:30:37 -07002605 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller489a3262016-11-11 12:39:31 -08002606 if (err)
2607 return err;
Kiran Patil21659032015-09-30 14:09:03 -04002608
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002609 /* schedule our worker thread which will take care of
2610 * applying the new filter changes
2611 */
2612 i40e_service_event_schedule(vsi->back);
2613 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002614}
2615
2616/**
Jacob Keller490a4ad2016-11-11 12:39:29 -08002617 * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002618 * @vsi: the vsi being configured
2619 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
Jacob Keller490a4ad2016-11-11 12:39:29 -08002620 *
2621 * This function should be used to remove all VLAN filters which match the
2622 * given VID. It does not schedule the service event and does not take the
2623 * mac_filter_hash_lock so it may be combined with other operations under
2624 * a single invocation of the mac_filter_hash_lock.
2625 *
2626 * NOTE: this function expects to be called while under the
2627 * mac_filter_hash_lock
2628 */
Jacob Keller9af52f62016-11-11 12:39:30 -08002629void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002630{
Alan Brady84f5ca62016-10-05 09:30:39 -07002631 struct i40e_mac_filter *f;
Jacob Keller278e7d02016-10-05 09:30:37 -07002632 struct hlist_node *h;
Jacob Keller278e7d02016-10-05 09:30:37 -07002633 int bkt;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002634
Jacob Keller278e7d02016-10-05 09:30:37 -07002635 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Jacob Keller290d2552016-10-05 09:30:36 -07002636 if (f->vlan == vid)
2637 __i40e_del_filter(vsi, f);
2638 }
Jacob Keller490a4ad2016-11-11 12:39:29 -08002639}
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002640
Jacob Keller490a4ad2016-11-11 12:39:29 -08002641/**
2642 * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
2643 * @vsi: the VSI being configured
Jacob Kellerf94484b2016-12-07 14:05:34 -08002644 * @vid: VLAN id to be removed
Jacob Keller490a4ad2016-11-11 12:39:29 -08002645 **/
Jacob Kellerf94484b2016-12-07 14:05:34 -08002646void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid)
Jacob Keller490a4ad2016-11-11 12:39:29 -08002647{
Jacob Kellerf94484b2016-12-07 14:05:34 -08002648 if (!vid || vsi->info.pvid)
2649 return;
2650
Jacob Keller490a4ad2016-11-11 12:39:29 -08002651 spin_lock_bh(&vsi->mac_filter_hash_lock);
2652 i40e_rm_vlan_all_mac(vsi, vid);
Jacob Keller278e7d02016-10-05 09:30:37 -07002653 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -04002654
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002655 /* schedule our worker thread which will take care of
2656 * applying the new filter changes
2657 */
2658 i40e_service_event_schedule(vsi->back);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002659}
2660
2661/**
2662 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2663 * @netdev: network interface to be adjusted
2664 * @vid: vlan id to be added
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002665 *
2666 * net_device_ops implementation for adding vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002667 **/
2668static int i40e_vlan_rx_add_vid(struct net_device *netdev,
2669 __always_unused __be16 proto, u16 vid)
2670{
2671 struct i40e_netdev_priv *np = netdev_priv(netdev);
2672 struct i40e_vsi *vsi = np->vsi;
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002673 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002674
Jacob Keller6a1127852016-10-25 16:08:49 -07002675 if (vid >= VLAN_N_VID)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002676 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002677
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002678 /* If the network stack called us with vid = 0 then
2679 * it is asking to receive priority tagged packets with
2680 * vlan id 0. Our HW receives them by default when configured
2681 * to receive untagged packets so there is no need to add an
2682 * extra filter for vlan 0 tagged packets.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002683 */
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002684 if (vid)
2685 ret = i40e_vsi_add_vlan(vsi, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002686
Jacob Keller6a1127852016-10-25 16:08:49 -07002687 if (!ret)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002688 set_bit(vid, vsi->active_vlans);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002689
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002690 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002691}
2692
2693/**
2694 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2695 * @netdev: network interface to be adjusted
2696 * @vid: vlan id to be removed
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002697 *
Akeem G Abodunrinfdfd9432014-02-11 08:24:15 +00002698 * net_device_ops implementation for removing vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002699 **/
2700static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2701 __always_unused __be16 proto, u16 vid)
2702{
2703 struct i40e_netdev_priv *np = netdev_priv(netdev);
2704 struct i40e_vsi *vsi = np->vsi;
2705
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002706 /* return code is ignored as there is nothing a user
2707 * can do about failure to remove and a log message was
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002708 * already printed from the other function
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002709 */
2710 i40e_vsi_kill_vlan(vsi, vid);
2711
2712 clear_bit(vid, vsi->active_vlans);
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002713
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002714 return 0;
2715}
2716
2717/**
Tushar Daveb1b15df2016-07-01 10:11:20 -07002718 * i40e_macaddr_init - explicitly write the mac address filters
2719 *
2720 * @vsi: pointer to the vsi
2721 * @macaddr: the MAC address
2722 *
2723 * This is needed when the macaddr has been obtained by other
2724 * means than the default, e.g., from Open Firmware or IDPROM.
2725 * Returns 0 on success, negative on failure
2726 **/
2727static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr)
2728{
2729 int ret;
2730 struct i40e_aqc_add_macvlan_element_data element;
2731
2732 ret = i40e_aq_mac_address_write(&vsi->back->hw,
2733 I40E_AQC_WRITE_TYPE_LAA_WOL,
2734 macaddr, NULL);
2735 if (ret) {
2736 dev_info(&vsi->back->pdev->dev,
2737 "Addr change for VSI failed: %d\n", ret);
2738 return -EADDRNOTAVAIL;
2739 }
2740
2741 memset(&element, 0, sizeof(element));
2742 ether_addr_copy(element.mac_addr, macaddr);
2743 element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
2744 ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL);
2745 if (ret) {
2746 dev_info(&vsi->back->pdev->dev,
2747 "add filter failed err %s aq_err %s\n",
2748 i40e_stat_str(&vsi->back->hw, ret),
2749 i40e_aq_str(&vsi->back->hw,
2750 vsi->back->hw.aq.asq_last_status));
2751 }
2752 return ret;
2753}
2754
2755/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002756 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2757 * @vsi: the vsi being brought back up
2758 **/
2759static void i40e_restore_vlan(struct i40e_vsi *vsi)
2760{
2761 u16 vid;
2762
2763 if (!vsi->netdev)
2764 return;
2765
2766 i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
2767
2768 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
2769 i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
2770 vid);
2771}
2772
2773/**
2774 * i40e_vsi_add_pvid - Add pvid for the VSI
2775 * @vsi: the vsi being adjusted
2776 * @vid: the vlan id to set as a PVID
2777 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002778int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002779{
2780 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002781 i40e_status ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002782
2783 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2784 vsi->info.pvid = cpu_to_le16(vid);
Greg Rose6c12fcb2013-11-28 06:39:34 +00002785 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
2786 I40E_AQ_VSI_PVLAN_INSERT_PVID |
Greg Roseb774c7d2013-11-28 06:39:44 +00002787 I40E_AQ_VSI_PVLAN_EMOD_STR;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002788
2789 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002790 ctxt.info = vsi->info;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002791 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2792 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002793 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002794 "add pvid failed, err %s aq_err %s\n",
2795 i40e_stat_str(&vsi->back->hw, ret),
2796 i40e_aq_str(&vsi->back->hw,
2797 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002798 return -ENOENT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002799 }
2800
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002801 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002802}
2803
2804/**
2805 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2806 * @vsi: the vsi being adjusted
2807 *
2808 * Just use the vlan_rx_register() service to put it back to normal
2809 **/
2810void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
2811{
Greg Rose6c12fcb2013-11-28 06:39:34 +00002812 i40e_vlan_stripping_disable(vsi);
2813
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002814 vsi->info.pvid = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002815}
2816
2817/**
2818 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2819 * @vsi: ptr to the VSI
2820 *
2821 * If this function returns with an error, then it's possible one or
2822 * more of the rings is populated (while the rest are not). It is the
2823 * callers duty to clean those orphaned rings.
2824 *
2825 * Return 0 on success, negative on failure
2826 **/
2827static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
2828{
2829 int i, err = 0;
2830
2831 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002832 err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002833
Björn Töpel74608d12017-05-24 07:55:35 +02002834 if (!i40e_enabled_xdp_vsi(vsi))
2835 return err;
2836
2837 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
2838 err = i40e_setup_tx_descriptors(vsi->xdp_rings[i]);
2839
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002840 return err;
2841}
2842
2843/**
2844 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2845 * @vsi: ptr to the VSI
2846 *
2847 * Free VSI's transmit software resources
2848 **/
2849static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
2850{
2851 int i;
2852
Björn Töpel74608d12017-05-24 07:55:35 +02002853 if (vsi->tx_rings) {
2854 for (i = 0; i < vsi->num_queue_pairs; i++)
2855 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
2856 i40e_free_tx_resources(vsi->tx_rings[i]);
2857 }
Greg Rose8e9dca52013-12-18 13:45:53 +00002858
Björn Töpel74608d12017-05-24 07:55:35 +02002859 if (vsi->xdp_rings) {
2860 for (i = 0; i < vsi->num_queue_pairs; i++)
2861 if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
2862 i40e_free_tx_resources(vsi->xdp_rings[i]);
2863 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002864}
2865
2866/**
2867 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2868 * @vsi: ptr to the VSI
2869 *
2870 * If this function returns with an error, then it's possible one or
2871 * more of the rings is populated (while the rest are not). It is the
2872 * callers duty to clean those orphaned rings.
2873 *
2874 * Return 0 on success, negative on failure
2875 **/
2876static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
2877{
2878 int i, err = 0;
2879
2880 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002881 err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002882 return err;
2883}
2884
2885/**
2886 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2887 * @vsi: ptr to the VSI
2888 *
2889 * Free all receive software resources
2890 **/
2891static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
2892{
2893 int i;
2894
Greg Rose8e9dca52013-12-18 13:45:53 +00002895 if (!vsi->rx_rings)
2896 return;
2897
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002898 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002899 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002900 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002901}
2902
2903/**
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002904 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
2905 * @ring: The Tx ring to configure
2906 *
2907 * This enables/disables XPS for a given Tx descriptor ring
2908 * based on the TCs enabled for the VSI that ring belongs to.
2909 **/
2910static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
2911{
2912 struct i40e_vsi *vsi = ring->vsi;
2913 cpumask_var_t mask;
2914
Jesse Brandeburg9a660ee2015-02-26 16:13:22 +00002915 if (!ring->q_vector || !ring->netdev)
2916 return;
2917
2918 /* Single TC mode enable XPS */
2919 if (vsi->tc_config.numtc <= 1) {
2920 if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002921 netif_set_xps_queue(ring->netdev,
2922 &ring->q_vector->affinity_mask,
2923 ring->queue_index);
Jesse Brandeburg9a660ee2015-02-26 16:13:22 +00002924 } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) {
2925 /* Disable XPS to allow selection based on TC */
2926 bitmap_zero(cpumask_bits(mask), nr_cpumask_bits);
2927 netif_set_xps_queue(ring->netdev, mask, ring->queue_index);
2928 free_cpumask_var(mask);
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002929 }
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002930
2931 /* schedule our worker thread which will take care of
2932 * applying the new filter changes
2933 */
2934 i40e_service_event_schedule(vsi->back);
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002935}
2936
2937/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002938 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2939 * @ring: The Tx ring to configure
2940 *
2941 * Configure the Tx descriptor ring in the HMC context.
2942 **/
2943static int i40e_configure_tx_ring(struct i40e_ring *ring)
2944{
2945 struct i40e_vsi *vsi = ring->vsi;
2946 u16 pf_q = vsi->base_queue + ring->queue_index;
2947 struct i40e_hw *hw = &vsi->back->hw;
2948 struct i40e_hmc_obj_txq tx_ctx;
2949 i40e_status err = 0;
2950 u32 qtx_ctl = 0;
2951
2952 /* some ATR related tx ring init */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002953 if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002954 ring->atr_sample_rate = vsi->back->atr_sample_rate;
2955 ring->atr_count = 0;
2956 } else {
2957 ring->atr_sample_rate = 0;
2958 }
2959
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002960 /* configure XPS */
2961 i40e_config_xps_tx_ring(ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002962
2963 /* clear the context structure first */
2964 memset(&tx_ctx, 0, sizeof(tx_ctx));
2965
2966 tx_ctx.new_context = 1;
2967 tx_ctx.base = (ring->dma / 128);
2968 tx_ctx.qlen = ring->count;
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002969 tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
2970 I40E_FLAG_FD_ATR_ENABLED));
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002971 tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
Jesse Brandeburg1943d8b2014-02-14 02:14:40 +00002972 /* FDIR VSI tx ring can still use RS bit and writebacks */
2973 if (vsi->type != I40E_VSI_FDIR)
2974 tx_ctx.head_wb_ena = 1;
2975 tx_ctx.head_wb_addr = ring->dma +
2976 (ring->count * sizeof(struct i40e_tx_desc));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002977
2978 /* As part of VSI creation/update, FW allocates certain
2979 * Tx arbitration queue sets for each TC enabled for
2980 * the VSI. The FW returns the handles to these queue
2981 * sets as part of the response buffer to Add VSI,
2982 * Update VSI, etc. AQ commands. It is expected that
2983 * these queue set handles be associated with the Tx
2984 * queues by the driver as part of the TX queue context
2985 * initialization. This has to be done regardless of
2986 * DCB as by default everything is mapped to TC0.
2987 */
2988 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
2989 tx_ctx.rdylist_act = 0;
2990
2991 /* clear the context in the HMC */
2992 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2993 if (err) {
2994 dev_info(&vsi->back->pdev->dev,
2995 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2996 ring->queue_index, pf_q, err);
2997 return -ENOMEM;
2998 }
2999
3000 /* set the context in the HMC */
3001 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
3002 if (err) {
3003 dev_info(&vsi->back->pdev->dev,
3004 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
3005 ring->queue_index, pf_q, err);
3006 return -ENOMEM;
3007 }
3008
3009 /* Now associate this queue with this PCI function */
Mitch Williams7a28d882014-10-17 03:14:52 +00003010 if (vsi->type == I40E_VSI_VMDQ2) {
Shannon Nelson9d8bf542014-01-14 00:49:50 -08003011 qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
Mitch Williams7a28d882014-10-17 03:14:52 +00003012 qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
3013 I40E_QTX_CTL_VFVM_INDX_MASK;
3014 } else {
Shannon Nelson9d8bf542014-01-14 00:49:50 -08003015 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
Mitch Williams7a28d882014-10-17 03:14:52 +00003016 }
3017
Shannon Nelson13fd9772013-09-28 07:14:19 +00003018 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
3019 I40E_QTX_CTL_PF_INDX_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003020 wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
3021 i40e_flush(hw);
3022
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003023 /* cache tail off for easier writes later */
3024 ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
3025
3026 return 0;
3027}
3028
3029/**
3030 * i40e_configure_rx_ring - Configure a receive ring context
3031 * @ring: The Rx ring to configure
3032 *
3033 * Configure the Rx descriptor ring in the HMC context.
3034 **/
3035static int i40e_configure_rx_ring(struct i40e_ring *ring)
3036{
3037 struct i40e_vsi *vsi = ring->vsi;
3038 u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
3039 u16 pf_q = vsi->base_queue + ring->queue_index;
3040 struct i40e_hw *hw = &vsi->back->hw;
3041 struct i40e_hmc_obj_rxq rx_ctx;
3042 i40e_status err = 0;
3043
3044 ring->state = 0;
3045
3046 /* clear the context structure first */
3047 memset(&rx_ctx, 0, sizeof(rx_ctx));
3048
3049 ring->rx_buf_len = vsi->rx_buf_len;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003050
Alexander Duyckdab86af2017-03-14 10:15:27 -07003051 rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len,
3052 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003053
3054 rx_ctx.base = (ring->dma / 128);
3055 rx_ctx.qlen = ring->count;
3056
Jesse Brandeburgbec60fc2016-04-18 11:33:47 -07003057 /* use 32 byte descriptors */
3058 rx_ctx.dsize = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003059
Jesse Brandeburgbec60fc2016-04-18 11:33:47 -07003060 /* descriptor type is always zero
3061 * rx_ctx.dtype = 0;
3062 */
Jesse Brandeburgb32bfa172016-04-18 11:33:42 -07003063 rx_ctx.hsplit_0 = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003064
Jesse Brandeburgb32bfa172016-04-18 11:33:42 -07003065 rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003066 if (hw->revision_id == 0)
3067 rx_ctx.lrxqthresh = 0;
3068 else
3069 rx_ctx.lrxqthresh = 2;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003070 rx_ctx.crcstrip = 1;
3071 rx_ctx.l2tsel = 1;
Jesse Brandeburgc4bbac32015-09-28 11:21:48 -07003072 /* this controls whether VLAN is stripped from inner headers */
3073 rx_ctx.showiv = 0;
Catherine Sullivanacb36762014-03-06 09:02:30 +00003074 /* set the prefena field to 1 because the manual says to */
3075 rx_ctx.prefena = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003076
3077 /* clear the context in the HMC */
3078 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
3079 if (err) {
3080 dev_info(&vsi->back->pdev->dev,
3081 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3082 ring->queue_index, pf_q, err);
3083 return -ENOMEM;
3084 }
3085
3086 /* set the context in the HMC */
3087 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
3088 if (err) {
3089 dev_info(&vsi->back->pdev->dev,
3090 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3091 ring->queue_index, pf_q, err);
3092 return -ENOMEM;
3093 }
3094
Alexander Duyckca9ec082017-04-05 07:51:02 -04003095 /* configure Rx buffer alignment */
3096 if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
3097 clear_ring_build_skb_enabled(ring);
3098 else
3099 set_ring_build_skb_enabled(ring);
3100
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003101 /* cache tail for quicker writes, and clear the reg before use */
3102 ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
3103 writel(0, ring->tail);
3104
Jesse Brandeburg1a557afc2016-04-20 19:43:37 -07003105 i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003106
3107 return 0;
3108}
3109
3110/**
3111 * i40e_vsi_configure_tx - Configure the VSI for Tx
3112 * @vsi: VSI structure describing this set of rings and resources
3113 *
3114 * Configure the Tx VSI for operation.
3115 **/
3116static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
3117{
3118 int err = 0;
3119 u16 i;
3120
Alexander Duyck9f65e152013-09-28 06:00:58 +00003121 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
3122 err = i40e_configure_tx_ring(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003123
Björn Töpel74608d12017-05-24 07:55:35 +02003124 if (!i40e_enabled_xdp_vsi(vsi))
3125 return err;
3126
3127 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
3128 err = i40e_configure_tx_ring(vsi->xdp_rings[i]);
3129
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003130 return err;
3131}
3132
3133/**
3134 * i40e_vsi_configure_rx - Configure the VSI for Rx
3135 * @vsi: the VSI being configured
3136 *
3137 * Configure the Rx VSI for operation.
3138 **/
3139static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
3140{
3141 int err = 0;
3142 u16 i;
3143
Alexander Duyckdab86af2017-03-14 10:15:27 -07003144 if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) {
3145 vsi->max_frame = I40E_MAX_RXBUFFER;
3146 vsi->rx_buf_len = I40E_RXBUFFER_2048;
3147#if (PAGE_SIZE < 8192)
Alexander Duyckca9ec082017-04-05 07:51:02 -04003148 } else if (!I40E_2K_TOO_SMALL_WITH_PADDING &&
3149 (vsi->netdev->mtu <= ETH_DATA_LEN)) {
Alexander Duyckdab86af2017-03-14 10:15:27 -07003150 vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
3151 vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
3152#endif
3153 } else {
3154 vsi->max_frame = I40E_MAX_RXBUFFER;
Alexander Duyck98efd692017-04-05 07:51:01 -04003155 vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 :
3156 I40E_RXBUFFER_2048;
Alexander Duyckdab86af2017-03-14 10:15:27 -07003157 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003158
3159 /* set up individual rings */
3160 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00003161 err = i40e_configure_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003162
3163 return err;
3164}
3165
3166/**
3167 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
3168 * @vsi: ptr to the VSI
3169 **/
3170static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
3171{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00003172 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003173 u16 qoffset, qcount;
3174 int i, n;
3175
Parikh, Neeravcd238a32015-02-21 06:43:37 +00003176 if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
3177 /* Reset the TC information */
3178 for (i = 0; i < vsi->num_queue_pairs; i++) {
3179 rx_ring = vsi->rx_rings[i];
3180 tx_ring = vsi->tx_rings[i];
3181 rx_ring->dcb_tc = 0;
3182 tx_ring->dcb_tc = 0;
3183 }
3184 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003185
3186 for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04003187 if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003188 continue;
3189
3190 qoffset = vsi->tc_config.tc_info[n].qoffset;
3191 qcount = vsi->tc_config.tc_info[n].qcount;
3192 for (i = qoffset; i < (qoffset + qcount); i++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00003193 rx_ring = vsi->rx_rings[i];
3194 tx_ring = vsi->tx_rings[i];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003195 rx_ring->dcb_tc = n;
3196 tx_ring->dcb_tc = n;
3197 }
3198 }
3199}
3200
3201/**
3202 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
3203 * @vsi: ptr to the VSI
3204 **/
3205static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
3206{
Tushar Daveb1b15df2016-07-01 10:11:20 -07003207 struct i40e_pf *pf = vsi->back;
3208 int err;
3209
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003210 if (vsi->netdev)
3211 i40e_set_rx_mode(vsi->netdev);
Tushar Daveb1b15df2016-07-01 10:11:20 -07003212
3213 if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
3214 err = i40e_macaddr_init(vsi, pf->hw.mac.addr);
3215 if (err) {
3216 dev_warn(&pf->pdev->dev,
3217 "could not set up macaddr; err %d\n", err);
3218 }
3219 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003220}
3221
3222/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003223 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
3224 * @vsi: Pointer to the targeted VSI
3225 *
3226 * This function replays the hlist on the hw where all the SB Flow Director
3227 * filters were saved.
3228 **/
3229static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
3230{
3231 struct i40e_fdir_filter *filter;
3232 struct i40e_pf *pf = vsi->back;
3233 struct hlist_node *node;
3234
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003235 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3236 return;
3237
Jacob Keller6d069422017-02-06 14:38:44 -08003238 /* Reset FDir counters as we're replaying all existing filters */
Jacob Keller097dbf52017-02-06 14:38:46 -08003239 pf->fd_tcp4_filter_cnt = 0;
3240 pf->fd_udp4_filter_cnt = 0;
Jacob Kellerf223c872017-02-06 14:38:51 -08003241 pf->fd_sctp4_filter_cnt = 0;
Jacob Keller097dbf52017-02-06 14:38:46 -08003242 pf->fd_ip4_filter_cnt = 0;
Jacob Keller6d069422017-02-06 14:38:44 -08003243
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003244 hlist_for_each_entry_safe(filter, node,
3245 &pf->fdir_filter_list, fdir_node) {
3246 i40e_add_del_fdir(vsi, filter, true);
3247 }
3248}
3249
3250/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003251 * i40e_vsi_configure - Set up the VSI for action
3252 * @vsi: the VSI being configured
3253 **/
3254static int i40e_vsi_configure(struct i40e_vsi *vsi)
3255{
3256 int err;
3257
3258 i40e_set_vsi_rx_mode(vsi);
3259 i40e_restore_vlan(vsi);
3260 i40e_vsi_config_dcb_rings(vsi);
3261 err = i40e_vsi_configure_tx(vsi);
3262 if (!err)
3263 err = i40e_vsi_configure_rx(vsi);
3264
3265 return err;
3266}
3267
3268/**
3269 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3270 * @vsi: the VSI being configured
3271 **/
3272static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
3273{
Björn Töpel74608d12017-05-24 07:55:35 +02003274 bool has_xdp = i40e_enabled_xdp_vsi(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003275 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003276 struct i40e_hw *hw = &pf->hw;
3277 u16 vector;
3278 int i, q;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003279 u32 qp;
3280
3281 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3282 * and PFINT_LNKLSTn registers, e.g.:
3283 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3284 */
3285 qp = vsi->base_queue;
3286 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +00003287 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003288 struct i40e_q_vector *q_vector = vsi->q_vectors[i];
3289
Jesse Brandeburgee2319c2015-09-28 14:16:54 -04003290 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Kan Lianga75e8002016-02-19 09:24:04 -05003291 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003292 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3293 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
3294 q_vector->rx.itr);
Kan Lianga75e8002016-02-19 09:24:04 -05003295 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003296 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3297 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
3298 q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003299 wr32(hw, I40E_PFINT_RATEN(vector - 1),
Alan Brady1c0e6a32016-11-28 16:06:02 -08003300 i40e_intrl_usec_to_reg(vsi->int_rate_limit));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003301
3302 /* Linked list for the queuepairs assigned to this vector */
3303 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
3304 for (q = 0; q < q_vector->num_ringpairs; q++) {
Björn Töpel74608d12017-05-24 07:55:35 +02003305 u32 nextqp = has_xdp ? qp + vsi->alloc_queue_pairs : qp;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003306 u32 val;
3307
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003308 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
Björn Töpel74608d12017-05-24 07:55:35 +02003309 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3310 (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
3311 (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
3312 (I40E_QUEUE_TYPE_TX <<
3313 I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003314
3315 wr32(hw, I40E_QINT_RQCTL(qp), val);
3316
Björn Töpel74608d12017-05-24 07:55:35 +02003317 if (has_xdp) {
3318 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3319 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3320 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
3321 (qp << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
3322 (I40E_QUEUE_TYPE_TX <<
3323 I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3324
3325 wr32(hw, I40E_QINT_TQCTL(nextqp), val);
3326 }
3327
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003328 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
Björn Töpel74608d12017-05-24 07:55:35 +02003329 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3330 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
3331 ((qp + 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
3332 (I40E_QUEUE_TYPE_RX <<
3333 I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003334
3335 /* Terminate the linked list */
3336 if (q == (q_vector->num_ringpairs - 1))
Björn Töpel74608d12017-05-24 07:55:35 +02003337 val |= (I40E_QUEUE_END_OF_LIST <<
3338 I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003339
3340 wr32(hw, I40E_QINT_TQCTL(qp), val);
3341 qp++;
3342 }
3343 }
3344
3345 i40e_flush(hw);
3346}
3347
3348/**
3349 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3350 * @hw: ptr to the hardware info
3351 **/
Jacob Kellerab437b52014-12-14 01:55:08 +00003352static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003353{
Jacob Kellerab437b52014-12-14 01:55:08 +00003354 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003355 u32 val;
3356
3357 /* clear things first */
3358 wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
3359 rd32(hw, I40E_PFINT_ICR0); /* read to clear */
3360
3361 val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
3362 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
3363 I40E_PFINT_ICR0_ENA_GRST_MASK |
3364 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
3365 I40E_PFINT_ICR0_ENA_GPIO_MASK |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003366 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
3367 I40E_PFINT_ICR0_ENA_VFLR_MASK |
3368 I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3369
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003370 if (pf->flags & I40E_FLAG_IWARP_ENABLED)
3371 val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3372
Jacob Kellerab437b52014-12-14 01:55:08 +00003373 if (pf->flags & I40E_FLAG_PTP)
3374 val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
3375
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003376 wr32(hw, I40E_PFINT_ICR0_ENA, val);
3377
3378 /* SW_ITR_IDX = 0, but don't change INTENA */
Anjali Singhai Jain84ed40e2013-11-26 10:49:32 +00003379 wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
3380 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003381
3382 /* OTHER_ITR_IDX = 0 */
3383 wr32(hw, I40E_PFINT_STAT_CTL0, 0);
3384}
3385
3386/**
3387 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3388 * @vsi: the VSI being configured
3389 **/
3390static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
3391{
Björn Töpel74608d12017-05-24 07:55:35 +02003392 u32 nextqp = i40e_enabled_xdp_vsi(vsi) ? vsi->alloc_queue_pairs : 0;
Alexander Duyck493fb302013-09-28 07:01:44 +00003393 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003394 struct i40e_pf *pf = vsi->back;
3395 struct i40e_hw *hw = &pf->hw;
3396 u32 val;
3397
3398 /* set the ITR configuration */
Jesse Brandeburgee2319c2015-09-28 14:16:54 -04003399 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Kan Lianga75e8002016-02-19 09:24:04 -05003400 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003401 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3402 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
Kan Lianga75e8002016-02-19 09:24:04 -05003403 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003404 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3405 wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
3406
Jacob Kellerab437b52014-12-14 01:55:08 +00003407 i40e_enable_misc_int_causes(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003408
3409 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3410 wr32(hw, I40E_PFINT_LNKLST0, 0);
3411
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00003412 /* Associate the queue pair to the vector and enable the queue int */
Björn Töpel74608d12017-05-24 07:55:35 +02003413 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3414 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3415 (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003416 (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3417
3418 wr32(hw, I40E_QINT_RQCTL(0), val);
3419
Björn Töpel74608d12017-05-24 07:55:35 +02003420 if (i40e_enabled_xdp_vsi(vsi)) {
3421 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3422 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT)|
3423 (I40E_QUEUE_TYPE_TX
3424 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3425
3426 wr32(hw, I40E_QINT_TQCTL(nextqp), val);
3427 }
3428
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003429 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3430 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3431 (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3432
3433 wr32(hw, I40E_QINT_TQCTL(0), val);
3434 i40e_flush(hw);
3435}
3436
3437/**
Mitch Williams2ef28cf2013-11-28 06:39:32 +00003438 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3439 * @pf: board private structure
3440 **/
3441void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
3442{
3443 struct i40e_hw *hw = &pf->hw;
3444
3445 wr32(hw, I40E_PFINT_DYN_CTL0,
3446 I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
3447 i40e_flush(hw);
3448}
3449
3450/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003451 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3452 * @pf: board private structure
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003453 * @clearpba: true when all pending interrupt events should be cleared
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003454 **/
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003455void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003456{
3457 struct i40e_hw *hw = &pf->hw;
3458 u32 val;
3459
3460 val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003461 (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003462 (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
3463
3464 wr32(hw, I40E_PFINT_DYN_CTL0, val);
3465 i40e_flush(hw);
3466}
3467
3468/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003469 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3470 * @irq: interrupt number
3471 * @data: pointer to a q_vector
3472 **/
3473static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
3474{
3475 struct i40e_q_vector *q_vector = data;
3476
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003477 if (!q_vector->tx.ring && !q_vector->rx.ring)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003478 return IRQ_HANDLED;
3479
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003480 napi_schedule_irqoff(&q_vector->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003481
3482 return IRQ_HANDLED;
3483}
3484
3485/**
Alan Brady96db7762016-09-14 16:24:38 -07003486 * i40e_irq_affinity_notify - Callback for affinity changes
3487 * @notify: context as to what irq was changed
3488 * @mask: the new affinity mask
3489 *
3490 * This is a callback function used by the irq_set_affinity_notifier function
3491 * so that we may register to receive changes to the irq affinity masks.
3492 **/
3493static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
3494 const cpumask_t *mask)
3495{
3496 struct i40e_q_vector *q_vector =
3497 container_of(notify, struct i40e_q_vector, affinity_notify);
3498
3499 q_vector->affinity_mask = *mask;
3500}
3501
3502/**
3503 * i40e_irq_affinity_release - Callback for affinity notifier release
3504 * @ref: internal core kernel usage
3505 *
3506 * This is a callback function used by the irq_set_affinity_notifier function
3507 * to inform the current notification subscriber that they will no longer
3508 * receive notifications.
3509 **/
3510static void i40e_irq_affinity_release(struct kref *ref) {}
3511
3512/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003513 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3514 * @vsi: the VSI being configured
3515 * @basename: name for the vector
3516 *
3517 * Allocates MSI-X vectors and requests interrupts from the kernel.
3518 **/
3519static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
3520{
3521 int q_vectors = vsi->num_q_vectors;
3522 struct i40e_pf *pf = vsi->back;
3523 int base = vsi->base_vector;
3524 int rx_int_idx = 0;
3525 int tx_int_idx = 0;
3526 int vector, err;
Alan Brady96db7762016-09-14 16:24:38 -07003527 int irq_num;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003528
3529 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck493fb302013-09-28 07:01:44 +00003530 struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003531
Alan Brady96db7762016-09-14 16:24:38 -07003532 irq_num = pf->msix_entries[base + vector].vector;
3533
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003534 if (q_vector->tx.ring && q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003535 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3536 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
3537 tx_int_idx++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003538 } else if (q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003539 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3540 "%s-%s-%d", basename, "rx", rx_int_idx++);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003541 } else if (q_vector->tx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003542 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3543 "%s-%s-%d", basename, "tx", tx_int_idx++);
3544 } else {
3545 /* skip this unused q_vector */
3546 continue;
3547 }
Alan Brady96db7762016-09-14 16:24:38 -07003548 err = request_irq(irq_num,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003549 vsi->irq_handler,
3550 0,
3551 q_vector->name,
3552 q_vector);
3553 if (err) {
3554 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003555 "MSIX request_irq failed, error: %d\n", err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003556 goto free_queue_irqs;
3557 }
Alan Brady96db7762016-09-14 16:24:38 -07003558
3559 /* register for affinity change notifications */
3560 q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
3561 q_vector->affinity_notify.release = i40e_irq_affinity_release;
3562 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003563 /* assign the mask for this irq */
Alan Brady96db7762016-09-14 16:24:38 -07003564 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003565 }
3566
Shannon Nelson63741842014-04-23 04:50:16 +00003567 vsi->irqs_ready = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003568 return 0;
3569
3570free_queue_irqs:
3571 while (vector) {
3572 vector--;
Alan Brady96db7762016-09-14 16:24:38 -07003573 irq_num = pf->msix_entries[base + vector].vector;
3574 irq_set_affinity_notifier(irq_num, NULL);
3575 irq_set_affinity_hint(irq_num, NULL);
3576 free_irq(irq_num, &vsi->q_vectors[vector]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003577 }
3578 return err;
3579}
3580
3581/**
3582 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3583 * @vsi: the VSI being un-configured
3584 **/
3585static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
3586{
3587 struct i40e_pf *pf = vsi->back;
3588 struct i40e_hw *hw = &pf->hw;
3589 int base = vsi->base_vector;
3590 int i;
3591
3592 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00003593 wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
3594 wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
Björn Töpel74608d12017-05-24 07:55:35 +02003595 if (!i40e_enabled_xdp_vsi(vsi))
3596 continue;
3597 wr32(hw, I40E_QINT_TQCTL(vsi->xdp_rings[i]->reg_idx), 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003598 }
3599
3600 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3601 for (i = vsi->base_vector;
3602 i < (vsi->num_q_vectors + vsi->base_vector); i++)
3603 wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
3604
3605 i40e_flush(hw);
3606 for (i = 0; i < vsi->num_q_vectors; i++)
3607 synchronize_irq(pf->msix_entries[i + base].vector);
3608 } else {
3609 /* Legacy and MSI mode - this stops all interrupt handling */
3610 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
3611 wr32(hw, I40E_PFINT_DYN_CTL0, 0);
3612 i40e_flush(hw);
3613 synchronize_irq(pf->pdev->irq);
3614 }
3615}
3616
3617/**
3618 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3619 * @vsi: the VSI being configured
3620 **/
3621static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
3622{
3623 struct i40e_pf *pf = vsi->back;
3624 int i;
3625
3626 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
Jesse Brandeburg78455482015-07-23 16:54:41 -04003627 for (i = 0; i < vsi->num_q_vectors; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003628 i40e_irq_dynamic_enable(vsi, i);
3629 } else {
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003630 i40e_irq_dynamic_enable_icr0(pf, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003631 }
3632
Jesse Brandeburg1022cb62013-09-28 07:13:08 +00003633 i40e_flush(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003634 return 0;
3635}
3636
3637/**
3638 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3639 * @pf: board private structure
3640 **/
3641static void i40e_stop_misc_vector(struct i40e_pf *pf)
3642{
3643 /* Disable ICR 0 */
3644 wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
3645 i40e_flush(&pf->hw);
3646}
3647
3648/**
3649 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3650 * @irq: interrupt number
3651 * @data: pointer to a q_vector
3652 *
3653 * This is the handler used for all MSI/Legacy interrupts, and deals
3654 * with both queue and non-queue interrupts. This is also used in
3655 * MSIX mode to handle the non-queue interrupts.
3656 **/
3657static irqreturn_t i40e_intr(int irq, void *data)
3658{
3659 struct i40e_pf *pf = (struct i40e_pf *)data;
3660 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003661 irqreturn_t ret = IRQ_NONE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003662 u32 icr0, icr0_remaining;
3663 u32 val, ena_mask;
3664
3665 icr0 = rd32(hw, I40E_PFINT_ICR0);
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003666 ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003667
Shannon Nelson116a57d2013-09-28 07:13:59 +00003668 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3669 if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003670 goto enable_intr;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003671
Shannon Nelsoncd92e722013-11-16 10:00:44 +00003672 /* if interrupt but no bits showing, must be SWINT */
3673 if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
3674 (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
3675 pf->sw_int_count++;
3676
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003677 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
3678 (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
3679 ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3680 icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
Carolyn Wyborny23bb6dc2016-11-08 13:05:12 -08003681 dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n");
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003682 }
3683
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003684 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3685 if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003686 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
3687 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003688
Anjali Singhai Jaina16ae2d2016-01-15 14:33:16 -08003689 /* We do not have a way to disarm Queue causes while leaving
3690 * interrupt enabled for all other causes, ideally
3691 * interrupt should be disabled while we are in NAPI but
3692 * this is not a performance path and napi_schedule()
3693 * can deal with rescheduling.
3694 */
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -03003695 if (!test_bit(__I40E_DOWN, pf->state))
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003696 napi_schedule_irqoff(&q_vector->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003697 }
3698
3699 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
3700 ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
Jacob Keller0da36b92017-04-19 09:25:55 -04003701 set_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08003702 i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003703 }
3704
3705 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
3706 ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
Jacob Keller0da36b92017-04-19 09:25:55 -04003707 set_bit(__I40E_MDD_EVENT_PENDING, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003708 }
3709
3710 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
3711 ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
Jacob Keller0da36b92017-04-19 09:25:55 -04003712 set_bit(__I40E_VFLR_EVENT_PENDING, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003713 }
3714
3715 if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
Jacob Keller0da36b92017-04-19 09:25:55 -04003716 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
3717 set_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003718 ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
3719 val = rd32(hw, I40E_GLGEN_RSTAT);
3720 val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
3721 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003722 if (val == I40E_RESET_CORER) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003723 pf->corer_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003724 } else if (val == I40E_RESET_GLOBR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003725 pf->globr_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003726 } else if (val == I40E_RESET_EMPR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003727 pf->empr_count++;
Jacob Keller0da36b92017-04-19 09:25:55 -04003728 set_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003729 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003730 }
3731
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003732 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
3733 icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
3734 dev_info(&pf->pdev->dev, "HMC error interrupt\n");
Anjali Singhai Jain25fc0e62015-03-31 00:45:01 -07003735 dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
3736 rd32(hw, I40E_PFHMC_ERRORINFO),
3737 rd32(hw, I40E_PFHMC_ERRORDATA));
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003738 }
3739
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003740 if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
3741 u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
3742
3743 if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
Jacob Kellercafa1fc2014-04-24 18:05:03 -07003744 icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003745 i40e_ptp_tx_hwtstamp(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003746 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003747 }
3748
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003749 /* If a critical error is pending we have no choice but to reset the
3750 * device.
3751 * Report and mask out any remaining unexpected interrupts.
3752 */
3753 icr0_remaining = icr0 & ena_mask;
3754 if (icr0_remaining) {
3755 dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
3756 icr0_remaining);
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003757 if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003758 (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
Anjali Singhai Jainc0c28972014-02-12 01:45:34 +00003759 (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003760 dev_info(&pf->pdev->dev, "device will be reset\n");
Jacob Keller0da36b92017-04-19 09:25:55 -04003761 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003762 i40e_service_event_schedule(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003763 }
3764 ena_mask &= ~icr0_remaining;
3765 }
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003766 ret = IRQ_HANDLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003767
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003768enable_intr:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003769 /* re-enable interrupt causes */
3770 wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -03003771 if (!test_bit(__I40E_DOWN, pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003772 i40e_service_event_schedule(pf);
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003773 i40e_irq_dynamic_enable_icr0(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003774 }
3775
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003776 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003777}
3778
3779/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003780 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3781 * @tx_ring: tx ring to clean
3782 * @budget: how many cleans we're allowed
3783 *
3784 * Returns true if there's any budget left (e.g. the clean is finished)
3785 **/
3786static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
3787{
3788 struct i40e_vsi *vsi = tx_ring->vsi;
3789 u16 i = tx_ring->next_to_clean;
3790 struct i40e_tx_buffer *tx_buf;
3791 struct i40e_tx_desc *tx_desc;
3792
3793 tx_buf = &tx_ring->tx_bi[i];
3794 tx_desc = I40E_TX_DESC(tx_ring, i);
3795 i -= tx_ring->count;
3796
3797 do {
3798 struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
3799
3800 /* if next_to_watch is not set then there is no work pending */
3801 if (!eop_desc)
3802 break;
3803
3804 /* prevent any other reads prior to eop_desc */
3805 read_barrier_depends();
3806
3807 /* if the descriptor isn't done, no work yet to do */
3808 if (!(eop_desc->cmd_type_offset_bsz &
3809 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
3810 break;
3811
3812 /* clear next_to_watch to prevent false hangs */
3813 tx_buf->next_to_watch = NULL;
3814
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003815 tx_desc->buffer_addr = 0;
3816 tx_desc->cmd_type_offset_bsz = 0;
3817 /* move past filter desc */
3818 tx_buf++;
3819 tx_desc++;
3820 i++;
3821 if (unlikely(!i)) {
3822 i -= tx_ring->count;
3823 tx_buf = tx_ring->tx_bi;
3824 tx_desc = I40E_TX_DESC(tx_ring, 0);
3825 }
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003826 /* unmap skb header data */
3827 dma_unmap_single(tx_ring->dev,
3828 dma_unmap_addr(tx_buf, dma),
3829 dma_unmap_len(tx_buf, len),
3830 DMA_TO_DEVICE);
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003831 if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
3832 kfree(tx_buf->raw_buf);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003833
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003834 tx_buf->raw_buf = NULL;
3835 tx_buf->tx_flags = 0;
3836 tx_buf->next_to_watch = NULL;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003837 dma_unmap_len_set(tx_buf, len, 0);
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003838 tx_desc->buffer_addr = 0;
3839 tx_desc->cmd_type_offset_bsz = 0;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003840
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003841 /* move us past the eop_desc for start of next FD desc */
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003842 tx_buf++;
3843 tx_desc++;
3844 i++;
3845 if (unlikely(!i)) {
3846 i -= tx_ring->count;
3847 tx_buf = tx_ring->tx_bi;
3848 tx_desc = I40E_TX_DESC(tx_ring, 0);
3849 }
3850
3851 /* update budget accounting */
3852 budget--;
3853 } while (likely(budget));
3854
3855 i += tx_ring->count;
3856 tx_ring->next_to_clean = i;
3857
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003858 if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
Jesse Brandeburg78455482015-07-23 16:54:41 -04003859 i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003860
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003861 return budget > 0;
3862}
3863
3864/**
3865 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3866 * @irq: interrupt number
3867 * @data: pointer to a q_vector
3868 **/
3869static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
3870{
3871 struct i40e_q_vector *q_vector = data;
3872 struct i40e_vsi *vsi;
3873
3874 if (!q_vector->tx.ring)
3875 return IRQ_HANDLED;
3876
3877 vsi = q_vector->tx.ring->vsi;
3878 i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
3879
3880 return IRQ_HANDLED;
3881}
3882
3883/**
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003884 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003885 * @vsi: the VSI being configured
3886 * @v_idx: vector index
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003887 * @qp_idx: queue pair index
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003888 **/
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04003889static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003890{
Alexander Duyck493fb302013-09-28 07:01:44 +00003891 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyck9f65e152013-09-28 06:00:58 +00003892 struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
3893 struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003894
3895 tx_ring->q_vector = q_vector;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003896 tx_ring->next = q_vector->tx.ring;
3897 q_vector->tx.ring = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003898 q_vector->tx.count++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003899
Björn Töpel74608d12017-05-24 07:55:35 +02003900 /* Place XDP Tx ring in the same q_vector ring list as regular Tx */
3901 if (i40e_enabled_xdp_vsi(vsi)) {
3902 struct i40e_ring *xdp_ring = vsi->xdp_rings[qp_idx];
3903
3904 xdp_ring->q_vector = q_vector;
3905 xdp_ring->next = q_vector->tx.ring;
3906 q_vector->tx.ring = xdp_ring;
3907 q_vector->tx.count++;
3908 }
3909
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003910 rx_ring->q_vector = q_vector;
3911 rx_ring->next = q_vector->rx.ring;
3912 q_vector->rx.ring = rx_ring;
3913 q_vector->rx.count++;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003914}
3915
3916/**
3917 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3918 * @vsi: the VSI being configured
3919 *
3920 * This function maps descriptor rings to the queue-specific vectors
3921 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3922 * one vector per queue pair, but on a constrained vector budget, we
3923 * group the queue pairs as "efficiently" as possible.
3924 **/
3925static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
3926{
3927 int qp_remaining = vsi->num_queue_pairs;
3928 int q_vectors = vsi->num_q_vectors;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003929 int num_ringpairs;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003930 int v_start = 0;
3931 int qp_idx = 0;
3932
3933 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3934 * group them so there are multiple queues per vector.
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003935 * It is also important to go through all the vectors available to be
3936 * sure that if we don't use all the vectors, that the remaining vectors
3937 * are cleared. This is especially important when decreasing the
3938 * number of queues in use.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003939 */
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003940 for (; v_start < q_vectors; v_start++) {
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003941 struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
3942
3943 num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
3944
3945 q_vector->num_ringpairs = num_ringpairs;
3946
3947 q_vector->rx.count = 0;
3948 q_vector->tx.count = 0;
3949 q_vector->rx.ring = NULL;
3950 q_vector->tx.ring = NULL;
3951
3952 while (num_ringpairs--) {
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04003953 i40e_map_vector_to_qp(vsi, v_start, qp_idx);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003954 qp_idx++;
3955 qp_remaining--;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003956 }
3957 }
3958}
3959
3960/**
3961 * i40e_vsi_request_irq - Request IRQ from the OS
3962 * @vsi: the VSI being configured
3963 * @basename: name for the vector
3964 **/
3965static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
3966{
3967 struct i40e_pf *pf = vsi->back;
3968 int err;
3969
3970 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
3971 err = i40e_vsi_request_irq_msix(vsi, basename);
3972 else if (pf->flags & I40E_FLAG_MSI_ENABLED)
3973 err = request_irq(pf->pdev->irq, i40e_intr, 0,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00003974 pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003975 else
3976 err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00003977 pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003978
3979 if (err)
3980 dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
3981
3982 return err;
3983}
3984
3985#ifdef CONFIG_NET_POLL_CONTROLLER
3986/**
Jesse Brandeburgd89d9672016-01-04 10:33:02 -08003987 * i40e_netpoll - A Polling 'interrupt' handler
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003988 * @netdev: network interface device structure
3989 *
3990 * This is used by netconsole to send skbs without having to re-enable
3991 * interrupts. It's not called while the normal interrupt routine is executing.
3992 **/
3993static void i40e_netpoll(struct net_device *netdev)
3994{
3995 struct i40e_netdev_priv *np = netdev_priv(netdev);
3996 struct i40e_vsi *vsi = np->vsi;
3997 struct i40e_pf *pf = vsi->back;
3998 int i;
3999
4000 /* if interface is down do nothing */
Jacob Keller0da36b92017-04-19 09:25:55 -04004001 if (test_bit(__I40E_VSI_DOWN, vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004002 return;
4003
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004004 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4005 for (i = 0; i < vsi->num_q_vectors; i++)
Alexander Duyck493fb302013-09-28 07:01:44 +00004006 i40e_msix_clean_rings(0, vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004007 } else {
4008 i40e_intr(pf->pdev->irq, netdev);
4009 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004010}
4011#endif
4012
Jacob Kellerc768e492017-04-13 04:45:47 -04004013#define I40E_QTX_ENA_WAIT_COUNT 50
4014
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004015/**
Neerav Parikh23527302014-06-03 23:50:15 +00004016 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
4017 * @pf: the PF being configured
4018 * @pf_q: the PF queue
4019 * @enable: enable or disable state of the queue
4020 *
4021 * This routine will wait for the given Tx queue of the PF to reach the
4022 * enabled or disabled state.
4023 * Returns -ETIMEDOUT in case of failing to reach the requested state after
4024 * multiple retries; else will return 0 in case of success.
4025 **/
4026static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
4027{
4028 int i;
4029 u32 tx_reg;
4030
4031 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
4032 tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
4033 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
4034 break;
4035
Neerav Parikhf98a2002014-09-13 07:40:44 +00004036 usleep_range(10, 20);
Neerav Parikh23527302014-06-03 23:50:15 +00004037 }
4038 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
4039 return -ETIMEDOUT;
4040
4041 return 0;
4042}
4043
4044/**
Jacob Kellerc768e492017-04-13 04:45:47 -04004045 * i40e_control_tx_q - Start or stop a particular Tx queue
4046 * @pf: the PF structure
4047 * @pf_q: the PF queue to configure
4048 * @enable: start or stop the queue
4049 *
4050 * This function enables or disables a single queue. Note that any delay
4051 * required after the operation is expected to be handled by the caller of
4052 * this function.
4053 **/
4054static void i40e_control_tx_q(struct i40e_pf *pf, int pf_q, bool enable)
4055{
4056 struct i40e_hw *hw = &pf->hw;
4057 u32 tx_reg;
4058 int i;
4059
4060 /* warn the TX unit of coming changes */
4061 i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
4062 if (!enable)
4063 usleep_range(10, 20);
4064
4065 for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
4066 tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
4067 if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
4068 ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
4069 break;
4070 usleep_range(1000, 2000);
4071 }
4072
4073 /* Skip if the queue is already in the requested state */
4074 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
4075 return;
4076
4077 /* turn on/off the queue */
4078 if (enable) {
4079 wr32(hw, I40E_QTX_HEAD(pf_q), 0);
4080 tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
4081 } else {
4082 tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
4083 }
4084
4085 wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
4086}
4087
4088/**
Björn Töpel74608d12017-05-24 07:55:35 +02004089 * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion
4090 * @seid: VSI SEID
4091 * @pf: the PF structure
4092 * @pf_q: the PF queue to configure
4093 * @is_xdp: true if the queue is used for XDP
4094 * @enable: start or stop the queue
4095 **/
4096static int i40e_control_wait_tx_q(int seid, struct i40e_pf *pf, int pf_q,
4097 bool is_xdp, bool enable)
4098{
4099 int ret;
4100
4101 i40e_control_tx_q(pf, pf_q, enable);
4102
4103 /* wait for the change to finish */
4104 ret = i40e_pf_txq_wait(pf, pf_q, enable);
4105 if (ret) {
4106 dev_info(&pf->pdev->dev,
4107 "VSI seid %d %sTx ring %d %sable timeout\n",
4108 seid, (is_xdp ? "XDP " : ""), pf_q,
4109 (enable ? "en" : "dis"));
4110 }
4111
4112 return ret;
4113}
4114
4115/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004116 * i40e_vsi_control_tx - Start or stop a VSI's rings
4117 * @vsi: the VSI being configured
4118 * @enable: start or stop the rings
4119 **/
4120static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
4121{
4122 struct i40e_pf *pf = vsi->back;
Jacob Kellerc768e492017-04-13 04:45:47 -04004123 int i, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004124
4125 pf_q = vsi->base_queue;
4126 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Björn Töpel74608d12017-05-24 07:55:35 +02004127 ret = i40e_control_wait_tx_q(vsi->seid, pf,
4128 pf_q,
4129 false /*is xdp*/, enable);
4130 if (ret)
Neerav Parikh23527302014-06-03 23:50:15 +00004131 break;
Björn Töpel74608d12017-05-24 07:55:35 +02004132
4133 if (!i40e_enabled_xdp_vsi(vsi))
4134 continue;
4135
4136 ret = i40e_control_wait_tx_q(vsi->seid, pf,
4137 pf_q + vsi->alloc_queue_pairs,
4138 true /*is xdp*/, enable);
4139 if (ret)
4140 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004141 }
4142
Neerav Parikh23527302014-06-03 23:50:15 +00004143 return ret;
4144}
4145
4146/**
4147 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
4148 * @pf: the PF being configured
4149 * @pf_q: the PF queue
4150 * @enable: enable or disable state of the queue
4151 *
4152 * This routine will wait for the given Rx queue of the PF to reach the
4153 * enabled or disabled state.
4154 * Returns -ETIMEDOUT in case of failing to reach the requested state after
4155 * multiple retries; else will return 0 in case of success.
4156 **/
4157static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
4158{
4159 int i;
4160 u32 rx_reg;
4161
4162 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
4163 rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
4164 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
4165 break;
4166
Neerav Parikhf98a2002014-09-13 07:40:44 +00004167 usleep_range(10, 20);
Neerav Parikh23527302014-06-03 23:50:15 +00004168 }
4169 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
4170 return -ETIMEDOUT;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00004171
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004172 return 0;
4173}
4174
4175/**
Jacob Kellerc768e492017-04-13 04:45:47 -04004176 * i40e_control_rx_q - Start or stop a particular Rx queue
4177 * @pf: the PF structure
4178 * @pf_q: the PF queue to configure
4179 * @enable: start or stop the queue
4180 *
4181 * This function enables or disables a single queue. Note that any delay
4182 * required after the operation is expected to be handled by the caller of
4183 * this function.
4184 **/
4185static void i40e_control_rx_q(struct i40e_pf *pf, int pf_q, bool enable)
4186{
4187 struct i40e_hw *hw = &pf->hw;
4188 u32 rx_reg;
4189 int i;
4190
4191 for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
4192 rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
4193 if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
4194 ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
4195 break;
4196 usleep_range(1000, 2000);
4197 }
4198
4199 /* Skip if the queue is already in the requested state */
4200 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
4201 return;
4202
4203 /* turn on/off the queue */
4204 if (enable)
4205 rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
4206 else
4207 rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
4208
4209 wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
4210}
4211
4212/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004213 * i40e_vsi_control_rx - Start or stop a VSI's rings
4214 * @vsi: the VSI being configured
4215 * @enable: start or stop the rings
4216 **/
4217static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
4218{
4219 struct i40e_pf *pf = vsi->back;
Jacob Kellerc768e492017-04-13 04:45:47 -04004220 int i, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004221
4222 pf_q = vsi->base_queue;
4223 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Jacob Kellerc768e492017-04-13 04:45:47 -04004224 i40e_control_rx_q(pf, pf_q, enable);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004225
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004226 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00004227 ret = i40e_pf_rxq_wait(pf, pf_q, enable);
4228 if (ret) {
4229 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004230 "VSI seid %d Rx ring %d %sable timeout\n",
4231 vsi->seid, pf_q, (enable ? "en" : "dis"));
Neerav Parikh23527302014-06-03 23:50:15 +00004232 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004233 }
4234 }
4235
Wyborny, Carolynd08a9f62017-03-28 08:00:48 -07004236 /* Due to HW errata, on Rx disable only, the register can indicate done
4237 * before it really is. Needs 50ms to be sure
4238 */
4239 if (!enable)
4240 mdelay(50);
4241
Neerav Parikh23527302014-06-03 23:50:15 +00004242 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004243}
4244
4245/**
Filip Sadowski3aa7b742016-10-11 15:26:58 -07004246 * i40e_vsi_start_rings - Start a VSI's rings
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004247 * @vsi: the VSI being configured
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004248 **/
Filip Sadowski3aa7b742016-10-11 15:26:58 -07004249int i40e_vsi_start_rings(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004250{
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00004251 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004252
4253 /* do rx first for enable and last for disable */
Filip Sadowski3aa7b742016-10-11 15:26:58 -07004254 ret = i40e_vsi_control_rx(vsi, true);
4255 if (ret)
4256 return ret;
4257 ret = i40e_vsi_control_tx(vsi, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004258
4259 return ret;
4260}
4261
4262/**
Filip Sadowski3aa7b742016-10-11 15:26:58 -07004263 * i40e_vsi_stop_rings - Stop a VSI's rings
4264 * @vsi: the VSI being configured
4265 **/
4266void i40e_vsi_stop_rings(struct i40e_vsi *vsi)
4267{
Jacob Keller34807562017-04-13 04:45:53 -04004268 /* When port TX is suspended, don't wait */
Jacob Keller0da36b92017-04-19 09:25:55 -04004269 if (test_bit(__I40E_PORT_SUSPENDED, vsi->back->state))
Jacob Keller34807562017-04-13 04:45:53 -04004270 return i40e_vsi_stop_rings_no_wait(vsi);
4271
Filip Sadowski3aa7b742016-10-11 15:26:58 -07004272 /* do rx first for enable and last for disable
4273 * Ignore return value, we need to shutdown whatever we can
4274 */
4275 i40e_vsi_control_tx(vsi, false);
4276 i40e_vsi_control_rx(vsi, false);
4277}
4278
4279/**
Jacob Kellere4b433f2017-04-13 04:45:52 -04004280 * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay
4281 * @vsi: the VSI being shutdown
4282 *
4283 * This function stops all the rings for a VSI but does not delay to verify
4284 * that rings have been disabled. It is expected that the caller is shutting
4285 * down multiple VSIs at once and will delay together for all the VSIs after
4286 * initiating the shutdown. This is particularly useful for shutting down lots
4287 * of VFs together. Otherwise, a large delay can be incurred while configuring
4288 * each VSI in serial.
4289 **/
4290void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi)
4291{
4292 struct i40e_pf *pf = vsi->back;
4293 int i, pf_q;
4294
4295 pf_q = vsi->base_queue;
4296 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4297 i40e_control_tx_q(pf, pf_q, false);
4298 i40e_control_rx_q(pf, pf_q, false);
4299 }
4300}
4301
4302/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004303 * i40e_vsi_free_irq - Free the irq association with the OS
4304 * @vsi: the VSI being configured
4305 **/
4306static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
4307{
4308 struct i40e_pf *pf = vsi->back;
4309 struct i40e_hw *hw = &pf->hw;
4310 int base = vsi->base_vector;
4311 u32 val, qp;
4312 int i;
4313
4314 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4315 if (!vsi->q_vectors)
4316 return;
4317
Shannon Nelson63741842014-04-23 04:50:16 +00004318 if (!vsi->irqs_ready)
4319 return;
4320
4321 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004322 for (i = 0; i < vsi->num_q_vectors; i++) {
Alan Brady96db7762016-09-14 16:24:38 -07004323 int irq_num;
4324 u16 vector;
4325
4326 vector = i + base;
4327 irq_num = pf->msix_entries[vector].vector;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004328
4329 /* free only the irqs that were actually requested */
Shannon Nelson78681b12013-11-28 06:39:36 +00004330 if (!vsi->q_vectors[i] ||
4331 !vsi->q_vectors[i]->num_ringpairs)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004332 continue;
4333
Alan Brady96db7762016-09-14 16:24:38 -07004334 /* clear the affinity notifier in the IRQ descriptor */
4335 irq_set_affinity_notifier(irq_num, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004336 /* clear the affinity_mask in the IRQ descriptor */
Alan Brady96db7762016-09-14 16:24:38 -07004337 irq_set_affinity_hint(irq_num, NULL);
4338 synchronize_irq(irq_num);
4339 free_irq(irq_num, vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004340
4341 /* Tear down the interrupt queue link list
4342 *
4343 * We know that they come in pairs and always
4344 * the Rx first, then the Tx. To clear the
4345 * link list, stick the EOL value into the
4346 * next_q field of the registers.
4347 */
4348 val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
4349 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4350 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4351 val |= I40E_QUEUE_END_OF_LIST
4352 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4353 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
4354
4355 while (qp != I40E_QUEUE_END_OF_LIST) {
4356 u32 next;
4357
4358 val = rd32(hw, I40E_QINT_RQCTL(qp));
4359
4360 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4361 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4362 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4363 I40E_QINT_RQCTL_INTEVENT_MASK);
4364
4365 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4366 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4367
4368 wr32(hw, I40E_QINT_RQCTL(qp), val);
4369
4370 val = rd32(hw, I40E_QINT_TQCTL(qp));
4371
4372 next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
4373 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
4374
4375 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4376 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4377 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4378 I40E_QINT_TQCTL_INTEVENT_MASK);
4379
4380 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4381 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4382
4383 wr32(hw, I40E_QINT_TQCTL(qp), val);
4384 qp = next;
4385 }
4386 }
4387 } else {
4388 free_irq(pf->pdev->irq, pf);
4389
4390 val = rd32(hw, I40E_PFINT_LNKLST0);
4391 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4392 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4393 val |= I40E_QUEUE_END_OF_LIST
4394 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
4395 wr32(hw, I40E_PFINT_LNKLST0, val);
4396
4397 val = rd32(hw, I40E_QINT_RQCTL(qp));
4398 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4399 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4400 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4401 I40E_QINT_RQCTL_INTEVENT_MASK);
4402
4403 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4404 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4405
4406 wr32(hw, I40E_QINT_RQCTL(qp), val);
4407
4408 val = rd32(hw, I40E_QINT_TQCTL(qp));
4409
4410 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4411 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4412 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4413 I40E_QINT_TQCTL_INTEVENT_MASK);
4414
4415 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4416 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4417
4418 wr32(hw, I40E_QINT_TQCTL(qp), val);
4419 }
4420}
4421
4422/**
Alexander Duyck493fb302013-09-28 07:01:44 +00004423 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4424 * @vsi: the VSI being configured
4425 * @v_idx: Index of vector to be freed
4426 *
4427 * This function frees the memory allocated to the q_vector. In addition if
4428 * NAPI is enabled it will delete any references to the NAPI struct prior
4429 * to freeing the q_vector.
4430 **/
4431static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
4432{
4433 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00004434 struct i40e_ring *ring;
Alexander Duyck493fb302013-09-28 07:01:44 +00004435
4436 if (!q_vector)
4437 return;
4438
4439 /* disassociate q_vector from rings */
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00004440 i40e_for_each_ring(ring, q_vector->tx)
4441 ring->q_vector = NULL;
4442
4443 i40e_for_each_ring(ring, q_vector->rx)
4444 ring->q_vector = NULL;
Alexander Duyck493fb302013-09-28 07:01:44 +00004445
4446 /* only VSI w/ an associated netdev is set up w/ NAPI */
4447 if (vsi->netdev)
4448 netif_napi_del(&q_vector->napi);
4449
4450 vsi->q_vectors[v_idx] = NULL;
4451
4452 kfree_rcu(q_vector, rcu);
4453}
4454
4455/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004456 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4457 * @vsi: the VSI being un-configured
4458 *
4459 * This frees the memory allocated to the q_vectors and
4460 * deletes references to the NAPI struct.
4461 **/
4462static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
4463{
4464 int v_idx;
4465
Alexander Duyck493fb302013-09-28 07:01:44 +00004466 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
4467 i40e_free_q_vector(vsi, v_idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004468}
4469
4470/**
4471 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4472 * @pf: board private structure
4473 **/
4474static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
4475{
4476 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4477 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4478 pci_disable_msix(pf->pdev);
4479 kfree(pf->msix_entries);
4480 pf->msix_entries = NULL;
Shannon Nelson3b444392015-02-26 16:15:57 +00004481 kfree(pf->irq_pile);
4482 pf->irq_pile = NULL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004483 } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
4484 pci_disable_msi(pf->pdev);
4485 }
4486 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
4487}
4488
4489/**
4490 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4491 * @pf: board private structure
4492 *
4493 * We go through and clear interrupt specific resources and reset the structure
4494 * to pre-load conditions
4495 **/
4496static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
4497{
4498 int i;
4499
Shannon Nelsone1477582015-02-21 06:44:33 +00004500 i40e_stop_misc_vector(pf);
Shannon Nelson69278392016-03-10 14:59:43 -08004501 if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
Shannon Nelsone1477582015-02-21 06:44:33 +00004502 synchronize_irq(pf->msix_entries[0].vector);
4503 free_irq(pf->msix_entries[0].vector, pf);
4504 }
4505
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06004506 i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
4507 I40E_IWARP_IRQ_PILE_ID);
4508
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004509 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
Mitch Williams505682c2014-05-20 08:01:37 +00004510 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004511 if (pf->vsi[i])
4512 i40e_vsi_free_q_vectors(pf->vsi[i]);
4513 i40e_reset_interrupt_capability(pf);
4514}
4515
4516/**
4517 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4518 * @vsi: the VSI being configured
4519 **/
4520static void i40e_napi_enable_all(struct i40e_vsi *vsi)
4521{
4522 int q_idx;
4523
4524 if (!vsi->netdev)
4525 return;
4526
Alexander Duyck13a8cd12017-03-24 15:01:42 -07004527 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
4528 struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
4529
4530 if (q_vector->rx.ring || q_vector->tx.ring)
4531 napi_enable(&q_vector->napi);
4532 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004533}
4534
4535/**
4536 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4537 * @vsi: the VSI being configured
4538 **/
4539static void i40e_napi_disable_all(struct i40e_vsi *vsi)
4540{
4541 int q_idx;
4542
4543 if (!vsi->netdev)
4544 return;
4545
Alexander Duyck13a8cd12017-03-24 15:01:42 -07004546 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
4547 struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
4548
4549 if (q_vector->rx.ring || q_vector->tx.ring)
4550 napi_disable(&q_vector->napi);
4551 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004552}
4553
4554/**
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004555 * i40e_vsi_close - Shut down a VSI
4556 * @vsi: the vsi to be quelled
4557 **/
4558static void i40e_vsi_close(struct i40e_vsi *vsi)
4559{
Mitch Williams0ef2d5a2017-01-24 10:24:00 -08004560 struct i40e_pf *pf = vsi->back;
Jacob Keller0da36b92017-04-19 09:25:55 -04004561 if (!test_and_set_bit(__I40E_VSI_DOWN, vsi->state))
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004562 i40e_down(vsi);
4563 i40e_vsi_free_irq(vsi);
4564 i40e_vsi_free_tx_resources(vsi);
4565 i40e_vsi_free_rx_resources(vsi);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04004566 vsi->current_netdev_flags = 0;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -08004567 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
Jacob Keller0da36b92017-04-19 09:25:55 -04004568 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
Mitch Williams0ef2d5a2017-01-24 10:24:00 -08004569 pf->flags |= I40E_FLAG_CLIENT_RESET;
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004570}
4571
4572/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004573 * i40e_quiesce_vsi - Pause a given VSI
4574 * @vsi: the VSI being paused
4575 **/
4576static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
4577{
Jacob Keller0da36b92017-04-19 09:25:55 -04004578 if (test_bit(__I40E_VSI_DOWN, vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004579 return;
4580
Jacob Keller0da36b92017-04-19 09:25:55 -04004581 set_bit(__I40E_VSI_NEEDS_RESTART, vsi->state);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004582 if (vsi->netdev && netif_running(vsi->netdev))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004583 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004584 else
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004585 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004586}
4587
4588/**
4589 * i40e_unquiesce_vsi - Resume a given VSI
4590 * @vsi: the VSI being resumed
4591 **/
4592static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
4593{
Jacob Keller0da36b92017-04-19 09:25:55 -04004594 if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART, vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004595 return;
4596
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004597 if (vsi->netdev && netif_running(vsi->netdev))
4598 vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
4599 else
Shannon Nelson8276f752014-03-14 07:32:27 +00004600 i40e_vsi_open(vsi); /* this clears the DOWN bit */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004601}
4602
4603/**
4604 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4605 * @pf: the PF
4606 **/
4607static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
4608{
4609 int v;
4610
Mitch Williams505682c2014-05-20 08:01:37 +00004611 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004612 if (pf->vsi[v])
4613 i40e_quiesce_vsi(pf->vsi[v]);
4614 }
4615}
4616
4617/**
4618 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4619 * @pf: the PF
4620 **/
4621static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
4622{
4623 int v;
4624
Mitch Williams505682c2014-05-20 08:01:37 +00004625 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004626 if (pf->vsi[v])
4627 i40e_unquiesce_vsi(pf->vsi[v]);
4628 }
4629}
4630
Neerav Parikh69129dc2014-11-12 00:18:46 +00004631/**
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004632 * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
Neerav Parikh69129dc2014-11-12 00:18:46 +00004633 * @vsi: the VSI being configured
4634 *
Jacob Kelleraf26ce22017-04-05 07:50:58 -04004635 * Wait until all queues on a given VSI have been disabled.
Neerav Parikh69129dc2014-11-12 00:18:46 +00004636 **/
Jacob Kellere4b433f2017-04-13 04:45:52 -04004637int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
Neerav Parikh69129dc2014-11-12 00:18:46 +00004638{
4639 struct i40e_pf *pf = vsi->back;
4640 int i, pf_q, ret;
4641
4642 pf_q = vsi->base_queue;
4643 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Jacob Kelleraf26ce22017-04-05 07:50:58 -04004644 /* Check and wait for the Tx queue */
Neerav Parikh69129dc2014-11-12 00:18:46 +00004645 ret = i40e_pf_txq_wait(pf, pf_q, false);
4646 if (ret) {
4647 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004648 "VSI seid %d Tx ring %d disable timeout\n",
4649 vsi->seid, pf_q);
Neerav Parikh69129dc2014-11-12 00:18:46 +00004650 return ret;
4651 }
Björn Töpel74608d12017-05-24 07:55:35 +02004652
4653 if (!i40e_enabled_xdp_vsi(vsi))
4654 goto wait_rx;
4655
4656 /* Check and wait for the XDP Tx queue */
4657 ret = i40e_pf_txq_wait(pf, pf_q + vsi->alloc_queue_pairs,
4658 false);
4659 if (ret) {
4660 dev_info(&pf->pdev->dev,
4661 "VSI seid %d XDP Tx ring %d disable timeout\n",
4662 vsi->seid, pf_q);
4663 return ret;
4664 }
4665wait_rx:
4666 /* Check and wait for the Rx queue */
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004667 ret = i40e_pf_rxq_wait(pf, pf_q, false);
4668 if (ret) {
4669 dev_info(&pf->pdev->dev,
4670 "VSI seid %d Rx ring %d disable timeout\n",
4671 vsi->seid, pf_q);
4672 return ret;
4673 }
4674 }
4675
Neerav Parikh69129dc2014-11-12 00:18:46 +00004676 return 0;
4677}
4678
Jacob Kellere4b433f2017-04-13 04:45:52 -04004679#ifdef CONFIG_I40E_DCB
Neerav Parikh69129dc2014-11-12 00:18:46 +00004680/**
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004681 * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
Neerav Parikh69129dc2014-11-12 00:18:46 +00004682 * @pf: the PF
4683 *
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004684 * This function waits for the queues to be in disabled state for all the
Neerav Parikh69129dc2014-11-12 00:18:46 +00004685 * VSIs that are managed by this PF.
4686 **/
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004687static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
Neerav Parikh69129dc2014-11-12 00:18:46 +00004688{
4689 int v, ret = 0;
4690
4691 for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
Alexander Duyckc76cb6e2017-02-21 15:55:48 -08004692 if (pf->vsi[v]) {
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004693 ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
Neerav Parikh69129dc2014-11-12 00:18:46 +00004694 if (ret)
4695 break;
4696 }
4697 }
4698
4699 return ret;
4700}
4701
4702#endif
Kiran Patilb03a8c12015-09-24 18:13:15 -04004703
4704/**
4705 * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
4706 * @q_idx: TX queue number
4707 * @vsi: Pointer to VSI struct
4708 *
4709 * This function checks specified queue for given VSI. Detects hung condition.
Alan Brady17daabb2017-04-05 07:50:56 -04004710 * We proactively detect hung TX queues by checking if interrupts are disabled
4711 * but there are pending descriptors. If it appears hung, attempt to recover
4712 * by triggering a SW interrupt.
Kiran Patilb03a8c12015-09-24 18:13:15 -04004713 **/
4714static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
4715{
4716 struct i40e_ring *tx_ring = NULL;
4717 struct i40e_pf *pf;
Alan Brady17daabb2017-04-05 07:50:56 -04004718 u32 val, tx_pending;
Kiran Patilb03a8c12015-09-24 18:13:15 -04004719 int i;
4720
4721 pf = vsi->back;
4722
4723 /* now that we have an index, find the tx_ring struct */
4724 for (i = 0; i < vsi->num_queue_pairs; i++) {
4725 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
4726 if (q_idx == vsi->tx_rings[i]->queue_index) {
4727 tx_ring = vsi->tx_rings[i];
4728 break;
4729 }
4730 }
4731 }
4732
4733 if (!tx_ring)
4734 return;
4735
4736 /* Read interrupt register */
4737 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
4738 val = rd32(&pf->hw,
4739 I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
4740 tx_ring->vsi->base_vector - 1));
4741 else
4742 val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
4743
Alan Brady17daabb2017-04-05 07:50:56 -04004744 tx_pending = i40e_get_tx_pending(tx_ring);
Kiran Patilb03a8c12015-09-24 18:13:15 -04004745
Alan Brady17daabb2017-04-05 07:50:56 -04004746 /* Interrupts are disabled and TX pending is non-zero,
4747 * trigger the SW interrupt (don't wait). Worst case
4748 * there will be one extra interrupt which may result
4749 * into not cleaning any queues because queues are cleaned.
Kiran Patilb03a8c12015-09-24 18:13:15 -04004750 */
Alan Brady17daabb2017-04-05 07:50:56 -04004751 if (tx_pending && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK)))
4752 i40e_force_wb(vsi, tx_ring->q_vector);
Kiran Patilb03a8c12015-09-24 18:13:15 -04004753}
4754
4755/**
4756 * i40e_detect_recover_hung - Function to detect and recover hung_queues
4757 * @pf: pointer to PF struct
4758 *
4759 * LAN VSI has netdev and netdev has TX queues. This function is to check
4760 * each of those TX queues if they are hung, trigger recovery by issuing
4761 * SW interrupt.
4762 **/
4763static void i40e_detect_recover_hung(struct i40e_pf *pf)
4764{
4765 struct net_device *netdev;
4766 struct i40e_vsi *vsi;
4767 int i;
4768
4769 /* Only for LAN VSI */
4770 vsi = pf->vsi[pf->lan_vsi];
4771
4772 if (!vsi)
4773 return;
4774
4775 /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
Jacob Keller0da36b92017-04-19 09:25:55 -04004776 if (test_bit(__I40E_VSI_DOWN, vsi->back->state) ||
4777 test_bit(__I40E_RESET_RECOVERY_PENDING, vsi->back->state))
Kiran Patilb03a8c12015-09-24 18:13:15 -04004778 return;
4779
4780 /* Make sure type is MAIN VSI */
4781 if (vsi->type != I40E_VSI_MAIN)
4782 return;
4783
4784 netdev = vsi->netdev;
4785 if (!netdev)
4786 return;
4787
4788 /* Bail out if netif_carrier is not OK */
4789 if (!netif_carrier_ok(netdev))
4790 return;
4791
4792 /* Go thru' TX queues for netdev */
4793 for (i = 0; i < netdev->num_tx_queues; i++) {
4794 struct netdev_queue *q;
4795
4796 q = netdev_get_tx_queue(netdev, i);
4797 if (q)
4798 i40e_detect_recover_hung_queue(i, vsi);
4799 }
4800}
4801
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004802/**
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004803 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00004804 * @pf: pointer to PF
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004805 *
4806 * Get TC map for ISCSI PF type that will include iSCSI TC
4807 * and LAN TC.
4808 **/
4809static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
4810{
4811 struct i40e_dcb_app_priority_table app;
4812 struct i40e_hw *hw = &pf->hw;
4813 u8 enabled_tc = 1; /* TC0 is always enabled */
4814 u8 tc, i;
4815 /* Get the iSCSI APP TLV */
4816 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4817
4818 for (i = 0; i < dcbcfg->numapps; i++) {
4819 app = dcbcfg->app[i];
4820 if (app.selector == I40E_APP_SEL_TCPIP &&
4821 app.protocolid == I40E_APP_PROTOID_ISCSI) {
4822 tc = dcbcfg->etscfg.prioritytable[app.priority];
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004823 enabled_tc |= BIT(tc);
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004824 break;
4825 }
4826 }
4827
4828 return enabled_tc;
4829}
4830
4831/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004832 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4833 * @dcbcfg: the corresponding DCBx configuration structure
4834 *
4835 * Return the number of TCs from given DCBx configuration
4836 **/
4837static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
4838{
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004839 int i, tc_unused = 0;
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004840 u8 num_tc = 0;
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004841 u8 ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004842
4843 /* Scan the ETS Config Priority Table to find
4844 * traffic class enabled for a given priority
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004845 * and create a bitmask of enabled TCs
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004846 */
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004847 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
4848 num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
4849
4850 /* Now scan the bitmask to check for
4851 * contiguous TCs starting with TC0
4852 */
4853 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4854 if (num_tc & BIT(i)) {
4855 if (!tc_unused) {
4856 ret++;
4857 } else {
4858 pr_err("Non-contiguous TC - Disabling DCB\n");
4859 return 1;
4860 }
4861 } else {
4862 tc_unused = 1;
4863 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004864 }
4865
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004866 /* There is always at least TC0 */
4867 if (!ret)
4868 ret = 1;
4869
4870 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004871}
4872
4873/**
4874 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4875 * @dcbcfg: the corresponding DCBx configuration structure
4876 *
4877 * Query the current DCB configuration and return the number of
4878 * traffic classes enabled from the given DCBX config
4879 **/
4880static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
4881{
4882 u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
4883 u8 enabled_tc = 1;
4884 u8 i;
4885
4886 for (i = 0; i < num_tc; i++)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004887 enabled_tc |= BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004888
4889 return enabled_tc;
4890}
4891
4892/**
4893 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4894 * @pf: PF being queried
4895 *
4896 * Return number of traffic classes enabled for the given PF
4897 **/
4898static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
4899{
4900 struct i40e_hw *hw = &pf->hw;
Dave Ertman52a08ca2016-07-27 12:02:34 -07004901 u8 i, enabled_tc = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004902 u8 num_tc = 0;
4903 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4904
4905 /* If DCB is not enabled then always in single TC */
4906 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
4907 return 1;
4908
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004909 /* SFP mode will be enabled for all TCs on port */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004910 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4911 return i40e_dcb_get_num_tc(dcbcfg);
4912
4913 /* MFP mode return count of enabled TCs for this PF */
4914 if (pf->hw.func_caps.iscsi)
4915 enabled_tc = i40e_get_iscsi_tc_map(pf);
4916 else
Neerav Parikhfc51de92015-02-24 06:58:53 +00004917 return 1; /* Only TC0 */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004918
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004919 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004920 if (enabled_tc & BIT(i))
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004921 num_tc++;
4922 }
4923 return num_tc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004924}
4925
4926/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004927 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4928 * @pf: PF being queried
4929 *
4930 * Return a bitmap for enabled traffic classes for this PF.
4931 **/
4932static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
4933{
4934 /* If DCB is not enabled for this PF then just return default TC */
4935 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
David Ertmanea6acb72016-09-20 07:10:50 -07004936 return I40E_DEFAULT_TRAFFIC_CLASS;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004937
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004938 /* SFP mode we want PF to be enabled for all TCs */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004939 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4940 return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
4941
Neerav Parikhfc51de92015-02-24 06:58:53 +00004942 /* MFP enabled and iSCSI PF type */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004943 if (pf->hw.func_caps.iscsi)
4944 return i40e_get_iscsi_tc_map(pf);
4945 else
David Ertmanea6acb72016-09-20 07:10:50 -07004946 return I40E_DEFAULT_TRAFFIC_CLASS;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004947}
4948
4949/**
4950 * i40e_vsi_get_bw_info - Query VSI BW Information
4951 * @vsi: the VSI being queried
4952 *
4953 * Returns 0 on success, negative value on failure
4954 **/
4955static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
4956{
4957 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
4958 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
4959 struct i40e_pf *pf = vsi->back;
4960 struct i40e_hw *hw = &pf->hw;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004961 i40e_status ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004962 u32 tc_bw_max;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004963 int i;
4964
4965 /* Get the VSI level BW configuration */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004966 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
4967 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004968 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004969 "couldn't get PF vsi bw config, err %s aq_err %s\n",
4970 i40e_stat_str(&pf->hw, ret),
4971 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004972 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004973 }
4974
4975 /* Get the VSI level BW configuration per TC */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004976 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
4977 NULL);
4978 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004979 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004980 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
4981 i40e_stat_str(&pf->hw, ret),
4982 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004983 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004984 }
4985
4986 if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
4987 dev_info(&pf->pdev->dev,
4988 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4989 bw_config.tc_valid_bits,
4990 bw_ets_config.tc_valid_bits);
4991 /* Still continuing */
4992 }
4993
4994 vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
4995 vsi->bw_max_quanta = bw_config.max_bw;
4996 tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
4997 (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
4998 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4999 vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
5000 vsi->bw_ets_limit_credits[i] =
5001 le16_to_cpu(bw_ets_config.credits[i]);
5002 /* 3 bits out of 4 for each TC */
5003 vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
5004 }
Jesse Brandeburg078b5872013-09-25 23:41:14 +00005005
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00005006 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005007}
5008
5009/**
5010 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
5011 * @vsi: the VSI being configured
5012 * @enabled_tc: TC bitmap
5013 * @bw_credits: BW shared credits per TC
5014 *
5015 * Returns 0 on success, negative value on failure
5016 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00005017static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005018 u8 *bw_share)
5019{
5020 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005021 i40e_status ret;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00005022 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005023
5024 bw_data.tc_valid_bits = enabled_tc;
5025 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5026 bw_data.tc_bw_credits[i] = bw_share[i];
5027
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005028 ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
5029 NULL);
5030 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005031 dev_info(&vsi->back->pdev->dev,
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005032 "AQ command Config VSI BW allocation per TC failed = %d\n",
5033 vsi->back->hw.aq.asq_last_status);
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00005034 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005035 }
5036
5037 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5038 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
5039
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00005040 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005041}
5042
5043/**
5044 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
5045 * @vsi: the VSI being configured
5046 * @enabled_tc: TC map to be enabled
5047 *
5048 **/
5049static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
5050{
5051 struct net_device *netdev = vsi->netdev;
5052 struct i40e_pf *pf = vsi->back;
5053 struct i40e_hw *hw = &pf->hw;
5054 u8 netdev_tc = 0;
5055 int i;
5056 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
5057
5058 if (!netdev)
5059 return;
5060
5061 if (!enabled_tc) {
5062 netdev_reset_tc(netdev);
5063 return;
5064 }
5065
5066 /* Set up actual enabled TCs on the VSI */
5067 if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
5068 return;
5069
5070 /* set per TC queues for the VSI */
5071 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5072 /* Only set TC queues for enabled tcs
5073 *
5074 * e.g. For a VSI that has TC0 and TC3 enabled the
5075 * enabled_tc bitmap would be 0x00001001; the driver
5076 * will set the numtc for netdev as 2 that will be
5077 * referenced by the netdev layer as TC 0 and 1.
5078 */
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08005079 if (vsi->tc_config.enabled_tc & BIT(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005080 netdev_set_tc_queue(netdev,
5081 vsi->tc_config.tc_info[i].netdev_tc,
5082 vsi->tc_config.tc_info[i].qcount,
5083 vsi->tc_config.tc_info[i].qoffset);
5084 }
5085
5086 /* Assign UP2TC map for the VSI */
5087 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
5088 /* Get the actual TC# for the UP */
5089 u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
5090 /* Get the mapped netdev TC# for the UP */
5091 netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
5092 netdev_set_prio_tc_map(netdev, i, netdev_tc);
5093 }
5094}
5095
5096/**
5097 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
5098 * @vsi: the VSI being configured
5099 * @ctxt: the ctxt buffer returned from AQ VSI update param command
5100 **/
5101static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
5102 struct i40e_vsi_context *ctxt)
5103{
5104 /* copy just the sections touched not the entire info
5105 * since not all sections are valid as returned by
5106 * update vsi params
5107 */
5108 vsi->info.mapping_flags = ctxt->info.mapping_flags;
5109 memcpy(&vsi->info.queue_mapping,
5110 &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
5111 memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
5112 sizeof(vsi->info.tc_mapping));
5113}
5114
5115/**
5116 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
5117 * @vsi: VSI to be configured
5118 * @enabled_tc: TC bitmap
5119 *
5120 * This configures a particular VSI for TCs that are mapped to the
5121 * given TC bitmap. It uses default bandwidth share for TCs across
5122 * VSIs to configure TC for a particular VSI.
5123 *
5124 * NOTE:
5125 * It is expected that the VSI queues have been quisced before calling
5126 * this function.
5127 **/
5128static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
5129{
5130 u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
5131 struct i40e_vsi_context ctxt;
5132 int ret = 0;
5133 int i;
5134
5135 /* Check if enabled_tc is same as existing or new TCs */
5136 if (vsi->tc_config.enabled_tc == enabled_tc)
5137 return ret;
5138
5139 /* Enable ETS TCs with equal BW Share for now across all VSIs */
5140 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08005141 if (enabled_tc & BIT(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005142 bw_share[i] = 1;
5143 }
5144
5145 ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
5146 if (ret) {
5147 dev_info(&vsi->back->pdev->dev,
5148 "Failed configuring TC map %d for VSI %d\n",
5149 enabled_tc, vsi->seid);
5150 goto out;
5151 }
5152
5153 /* Update Queue Pairs Mapping for currently enabled UPs */
5154 ctxt.seid = vsi->seid;
5155 ctxt.pf_num = vsi->back->hw.pf_id;
5156 ctxt.vf_num = 0;
5157 ctxt.uplink_seid = vsi->uplink_seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07005158 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005159 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
5160
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06005161 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
5162 ctxt.info.valid_sections |=
5163 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
5164 ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
5165 }
5166
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005167 /* Update the VSI after updating the VSI queue-mapping information */
5168 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
5169 if (ret) {
5170 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005171 "Update vsi tc config failed, err %s aq_err %s\n",
5172 i40e_stat_str(&vsi->back->hw, ret),
5173 i40e_aq_str(&vsi->back->hw,
5174 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005175 goto out;
5176 }
5177 /* update the local VSI info with updated queue map */
5178 i40e_vsi_update_queue_map(vsi, &ctxt);
5179 vsi->info.valid_sections = 0;
5180
5181 /* Update current VSI BW information */
5182 ret = i40e_vsi_get_bw_info(vsi);
5183 if (ret) {
5184 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005185 "Failed updating vsi bw info, err %s aq_err %s\n",
5186 i40e_stat_str(&vsi->back->hw, ret),
5187 i40e_aq_str(&vsi->back->hw,
5188 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005189 goto out;
5190 }
5191
5192 /* Update the netdev TC setup */
5193 i40e_vsi_config_netdev_tc(vsi, enabled_tc);
5194out:
5195 return ret;
5196}
5197
5198/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005199 * i40e_veb_config_tc - Configure TCs for given VEB
5200 * @veb: given VEB
5201 * @enabled_tc: TC bitmap
5202 *
5203 * Configures given TC bitmap for VEB (switching) element
5204 **/
5205int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
5206{
5207 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
5208 struct i40e_pf *pf = veb->pf;
5209 int ret = 0;
5210 int i;
5211
5212 /* No TCs or already enabled TCs just return */
5213 if (!enabled_tc || veb->enabled_tc == enabled_tc)
5214 return ret;
5215
5216 bw_data.tc_valid_bits = enabled_tc;
5217 /* bw_data.absolute_credits is not set (relative) */
5218
5219 /* Enable ETS TCs with equal BW Share for now */
5220 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08005221 if (enabled_tc & BIT(i))
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005222 bw_data.tc_bw_share_credits[i] = 1;
5223 }
5224
5225 ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
5226 &bw_data, NULL);
5227 if (ret) {
5228 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005229 "VEB bw config failed, err %s aq_err %s\n",
5230 i40e_stat_str(&pf->hw, ret),
5231 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005232 goto out;
5233 }
5234
5235 /* Update the BW information */
5236 ret = i40e_veb_get_bw_info(veb);
5237 if (ret) {
5238 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005239 "Failed getting veb bw config, err %s aq_err %s\n",
5240 i40e_stat_str(&pf->hw, ret),
5241 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005242 }
5243
5244out:
5245 return ret;
5246}
5247
5248#ifdef CONFIG_I40E_DCB
5249/**
5250 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
5251 * @pf: PF struct
5252 *
5253 * Reconfigure VEB/VSIs on a given PF; it is assumed that
5254 * the caller would've quiesce all the VSIs before calling
5255 * this function
5256 **/
5257static void i40e_dcb_reconfigure(struct i40e_pf *pf)
5258{
5259 u8 tc_map = 0;
5260 int ret;
5261 u8 v;
5262
5263 /* Enable the TCs available on PF to all VEBs */
5264 tc_map = i40e_pf_get_tc_map(pf);
5265 for (v = 0; v < I40E_MAX_VEB; v++) {
5266 if (!pf->veb[v])
5267 continue;
5268 ret = i40e_veb_config_tc(pf->veb[v], tc_map);
5269 if (ret) {
5270 dev_info(&pf->pdev->dev,
5271 "Failed configuring TC for VEB seid=%d\n",
5272 pf->veb[v]->seid);
5273 /* Will try to configure as many components */
5274 }
5275 }
5276
5277 /* Update each VSI */
Mitch Williams505682c2014-05-20 08:01:37 +00005278 for (v = 0; v < pf->num_alloc_vsi; v++) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005279 if (!pf->vsi[v])
5280 continue;
5281
5282 /* - Enable all TCs for the LAN VSI
5283 * - For all others keep them at TC0 for now
5284 */
5285 if (v == pf->lan_vsi)
5286 tc_map = i40e_pf_get_tc_map(pf);
5287 else
David Ertmanea6acb72016-09-20 07:10:50 -07005288 tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005289
5290 ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
5291 if (ret) {
5292 dev_info(&pf->pdev->dev,
5293 "Failed configuring TC for VSI seid=%d\n",
5294 pf->vsi[v]->seid);
5295 /* Will try to configure as many components */
5296 } else {
Neerav Parikh0672a092014-04-01 07:11:47 +00005297 /* Re-configure VSI vectors based on updated TC map */
5298 i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005299 if (pf->vsi[v]->netdev)
5300 i40e_dcbnl_set_all(pf->vsi[v]);
5301 }
5302 }
5303}
5304
5305/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005306 * i40e_resume_port_tx - Resume port Tx
5307 * @pf: PF struct
5308 *
5309 * Resume a port's Tx and issue a PF reset in case of failure to
5310 * resume.
5311 **/
5312static int i40e_resume_port_tx(struct i40e_pf *pf)
5313{
5314 struct i40e_hw *hw = &pf->hw;
5315 int ret;
5316
5317 ret = i40e_aq_resume_port_tx(hw, NULL);
5318 if (ret) {
5319 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005320 "Resume Port Tx failed, err %s aq_err %s\n",
5321 i40e_stat_str(&pf->hw, ret),
5322 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005323 /* Schedule PF reset to recover */
Jacob Keller0da36b92017-04-19 09:25:55 -04005324 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005325 i40e_service_event_schedule(pf);
5326 }
5327
5328 return ret;
5329}
5330
5331/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005332 * i40e_init_pf_dcb - Initialize DCB configuration
5333 * @pf: PF being configured
5334 *
5335 * Query the current DCB configuration and cache it
5336 * in the hardware structure
5337 **/
5338static int i40e_init_pf_dcb(struct i40e_pf *pf)
5339{
5340 struct i40e_hw *hw = &pf->hw;
5341 int err = 0;
5342
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00005343 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
Neerav Parikhf1bbad32016-01-13 16:51:39 -08005344 if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT)
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00005345 goto out;
5346
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005347 /* Get the initial DCB configuration */
5348 err = i40e_init_dcb(hw);
5349 if (!err) {
5350 /* Device/Function is not DCBX capable */
5351 if ((!hw->func_caps.dcb) ||
5352 (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
5353 dev_info(&pf->pdev->dev,
5354 "DCBX offload is not supported or is disabled for this PF.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005355 } else {
5356 /* When status is not DISABLED then DCBX in FW */
5357 pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
5358 DCB_CAP_DCBX_VER_IEEE;
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005359
5360 pf->flags |= I40E_FLAG_DCB_CAPABLE;
Dave Ertmana0362442016-08-29 17:38:26 -07005361 /* Enable DCB tagging only when more than one TC
5362 * or explicitly disable if only one TC
5363 */
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005364 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
5365 pf->flags |= I40E_FLAG_DCB_ENABLED;
Dave Ertmana0362442016-08-29 17:38:26 -07005366 else
5367 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005368 dev_dbg(&pf->pdev->dev,
5369 "DCBX offload is supported for this PF.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005370 }
Neerav Parikh014269f2014-04-01 07:11:48 +00005371 } else {
Shannon Nelsonaebfc812014-12-11 07:06:38 +00005372 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005373 "Query for DCB configuration failed, err %s aq_err %s\n",
5374 i40e_stat_str(&pf->hw, err),
5375 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005376 }
5377
5378out:
5379 return err;
5380}
5381#endif /* CONFIG_I40E_DCB */
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005382#define SPEED_SIZE 14
5383#define FC_SIZE 8
5384/**
5385 * i40e_print_link_message - print link up or down
5386 * @vsi: the VSI for which link needs a message
5387 */
Matt Jaredc156f852015-08-27 11:42:39 -04005388void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005389{
Filip Sadowski7ec9ba12016-11-08 13:05:13 -08005390 enum i40e_aq_link_speed new_speed;
Shannon Nelsona9165492015-09-03 17:19:00 -04005391 char *speed = "Unknown";
5392 char *fc = "Unknown";
Henry Tieman3e03d7c2016-12-02 12:32:57 -08005393 char *fec = "";
5394 char *an = "";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005395
Filip Sadowski7ec9ba12016-11-08 13:05:13 -08005396 new_speed = vsi->back->hw.phy.link_info.link_speed;
5397
5398 if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed))
Matt Jaredc156f852015-08-27 11:42:39 -04005399 return;
5400 vsi->current_isup = isup;
Filip Sadowski7ec9ba12016-11-08 13:05:13 -08005401 vsi->current_speed = new_speed;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005402 if (!isup) {
5403 netdev_info(vsi->netdev, "NIC Link is Down\n");
5404 return;
5405 }
5406
Greg Rose148c2d82014-12-11 07:06:27 +00005407 /* Warn user if link speed on NPAR enabled partition is not at
5408 * least 10GB
5409 */
5410 if (vsi->back->hw.func_caps.npar_enable &&
5411 (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
5412 vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
5413 netdev_warn(vsi->netdev,
5414 "The partition detected link speed that is less than 10Gbps\n");
5415
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005416 switch (vsi->back->hw.phy.link_info.link_speed) {
5417 case I40E_LINK_SPEED_40GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005418 speed = "40 G";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005419 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -07005420 case I40E_LINK_SPEED_20GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005421 speed = "20 G";
Jesse Brandeburgae24b402015-03-27 00:12:09 -07005422 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -08005423 case I40E_LINK_SPEED_25GB:
5424 speed = "25 G";
5425 break;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005426 case I40E_LINK_SPEED_10GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005427 speed = "10 G";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005428 break;
5429 case I40E_LINK_SPEED_1GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005430 speed = "1000 M";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005431 break;
Mitch Williams5960d332014-09-13 07:40:47 +00005432 case I40E_LINK_SPEED_100MB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005433 speed = "100 M";
Mitch Williams5960d332014-09-13 07:40:47 +00005434 break;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005435 default:
5436 break;
5437 }
5438
5439 switch (vsi->back->hw.fc.current_mode) {
5440 case I40E_FC_FULL:
Shannon Nelsona9165492015-09-03 17:19:00 -04005441 fc = "RX/TX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005442 break;
5443 case I40E_FC_TX_PAUSE:
Shannon Nelsona9165492015-09-03 17:19:00 -04005444 fc = "TX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005445 break;
5446 case I40E_FC_RX_PAUSE:
Shannon Nelsona9165492015-09-03 17:19:00 -04005447 fc = "RX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005448 break;
5449 default:
Shannon Nelsona9165492015-09-03 17:19:00 -04005450 fc = "None";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005451 break;
5452 }
5453
Henry Tieman3e03d7c2016-12-02 12:32:57 -08005454 if (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) {
5455 fec = ", FEC: None";
5456 an = ", Autoneg: False";
5457
5458 if (vsi->back->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED)
5459 an = ", Autoneg: True";
5460
5461 if (vsi->back->hw.phy.link_info.fec_info &
5462 I40E_AQ_CONFIG_FEC_KR_ENA)
5463 fec = ", FEC: CL74 FC-FEC/BASE-R";
5464 else if (vsi->back->hw.phy.link_info.fec_info &
5465 I40E_AQ_CONFIG_FEC_RS_ENA)
5466 fec = ", FEC: CL108 RS-FEC";
5467 }
5468
5469 netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s, Flow Control: %s\n",
5470 speed, fec, an, fc);
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005471}
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005472
5473/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005474 * i40e_up_complete - Finish the last steps of bringing up a connection
5475 * @vsi: the VSI being configured
5476 **/
5477static int i40e_up_complete(struct i40e_vsi *vsi)
5478{
5479 struct i40e_pf *pf = vsi->back;
5480 int err;
5481
5482 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
5483 i40e_vsi_configure_msix(vsi);
5484 else
5485 i40e_configure_msi_and_legacy(vsi);
5486
5487 /* start rings */
Filip Sadowski3aa7b742016-10-11 15:26:58 -07005488 err = i40e_vsi_start_rings(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005489 if (err)
5490 return err;
5491
Jacob Keller0da36b92017-04-19 09:25:55 -04005492 clear_bit(__I40E_VSI_DOWN, vsi->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005493 i40e_napi_enable_all(vsi);
5494 i40e_vsi_enable_irq(vsi);
5495
5496 if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
5497 (vsi->netdev)) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005498 i40e_print_link_message(vsi, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005499 netif_tx_start_all_queues(vsi->netdev);
5500 netif_carrier_on(vsi->netdev);
Anjali Singhai6d779b42013-09-28 06:00:02 +00005501 } else if (vsi->netdev) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005502 i40e_print_link_message(vsi, false);
Carolyn Wyborny7b592f62014-07-10 07:58:19 +00005503 /* need to check for qualified module here*/
5504 if ((pf->hw.phy.link_info.link_info &
5505 I40E_AQ_MEDIA_AVAILABLE) &&
5506 (!(pf->hw.phy.link_info.an_info &
5507 I40E_AQ_QUALIFIED_MODULE)))
5508 netdev_err(vsi->netdev,
5509 "the driver failed to link because an unqualified module was detected.");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005510 }
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00005511
5512 /* replay FDIR SB filters */
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005513 if (vsi->type == I40E_VSI_FDIR) {
5514 /* reset fd counters */
Jacob Keller097dbf52017-02-06 14:38:46 -08005515 pf->fd_add_err = 0;
5516 pf->fd_atr_cnt = 0;
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00005517 i40e_fdir_filter_restore(vsi);
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005518 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06005519
5520 /* On the next run of the service_task, notify any clients of the new
5521 * opened netdev
5522 */
5523 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005524 i40e_service_event_schedule(pf);
5525
5526 return 0;
5527}
5528
5529/**
5530 * i40e_vsi_reinit_locked - Reset the VSI
5531 * @vsi: the VSI being configured
5532 *
5533 * Rebuild the ring structs after some configuration
5534 * has changed, e.g. MTU size.
5535 **/
5536static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
5537{
5538 struct i40e_pf *pf = vsi->back;
5539
5540 WARN_ON(in_interrupt());
Jacob Keller0da36b92017-04-19 09:25:55 -04005541 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005542 usleep_range(1000, 2000);
5543 i40e_down(vsi);
5544
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005545 i40e_up(vsi);
Jacob Keller0da36b92017-04-19 09:25:55 -04005546 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005547}
5548
5549/**
5550 * i40e_up - Bring the connection back up after being down
5551 * @vsi: the VSI being configured
5552 **/
5553int i40e_up(struct i40e_vsi *vsi)
5554{
5555 int err;
5556
5557 err = i40e_vsi_configure(vsi);
5558 if (!err)
5559 err = i40e_up_complete(vsi);
5560
5561 return err;
5562}
5563
5564/**
5565 * i40e_down - Shutdown the connection processing
5566 * @vsi: the VSI being stopped
5567 **/
5568void i40e_down(struct i40e_vsi *vsi)
5569{
5570 int i;
5571
5572 /* It is assumed that the caller of this function
Jacob Kellerd19cb642017-04-21 13:38:05 -07005573 * sets the vsi->state __I40E_VSI_DOWN bit.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005574 */
5575 if (vsi->netdev) {
5576 netif_carrier_off(vsi->netdev);
5577 netif_tx_disable(vsi->netdev);
5578 }
5579 i40e_vsi_disable_irq(vsi);
Filip Sadowski3aa7b742016-10-11 15:26:58 -07005580 i40e_vsi_stop_rings(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005581 i40e_napi_disable_all(vsi);
5582
5583 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00005584 i40e_clean_tx_ring(vsi->tx_rings[i]);
Björn Töpel74608d12017-05-24 07:55:35 +02005585 if (i40e_enabled_xdp_vsi(vsi))
5586 i40e_clean_tx_ring(vsi->xdp_rings[i]);
Alexander Duyck9f65e152013-09-28 06:00:58 +00005587 i40e_clean_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005588 }
Catherine Sullivanf980d442016-05-16 10:26:34 -07005589
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005590}
5591
5592/**
5593 * i40e_setup_tc - configure multiple traffic classes
5594 * @netdev: net device to configure
5595 * @tc: number of traffic classes to enable
5596 **/
5597static int i40e_setup_tc(struct net_device *netdev, u8 tc)
5598{
5599 struct i40e_netdev_priv *np = netdev_priv(netdev);
5600 struct i40e_vsi *vsi = np->vsi;
5601 struct i40e_pf *pf = vsi->back;
5602 u8 enabled_tc = 0;
5603 int ret = -EINVAL;
5604 int i;
5605
5606 /* Check if DCB enabled to continue */
5607 if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
5608 netdev_info(netdev, "DCB is not enabled for adapter\n");
5609 goto exit;
5610 }
5611
5612 /* Check if MFP enabled */
5613 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
5614 netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
5615 goto exit;
5616 }
5617
5618 /* Check whether tc count is within enabled limit */
5619 if (tc > i40e_pf_get_num_tc(pf)) {
5620 netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
5621 goto exit;
5622 }
5623
5624 /* Generate TC map for number of tc requested */
5625 for (i = 0; i < tc; i++)
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08005626 enabled_tc |= BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005627
5628 /* Requesting same TC configuration as already enabled */
5629 if (enabled_tc == vsi->tc_config.enabled_tc)
5630 return 0;
5631
5632 /* Quiesce VSI queues */
5633 i40e_quiesce_vsi(vsi);
5634
5635 /* Configure VSI for enabled TCs */
5636 ret = i40e_vsi_config_tc(vsi, enabled_tc);
5637 if (ret) {
5638 netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
5639 vsi->seid);
5640 goto exit;
5641 }
5642
5643 /* Unquiesce VSI */
5644 i40e_unquiesce_vsi(vsi);
5645
5646exit:
5647 return ret;
5648}
5649
Jiri Pirkoa5fcf8a2017-06-06 17:00:16 +02005650static int __i40e_setup_tc(struct net_device *netdev, u32 handle,
5651 u32 chain_index, __be16 proto,
John Fastabend16e5cc62016-02-16 21:16:43 -08005652 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -08005653{
Amritha Nambiar56f36ac2017-03-15 10:39:25 -07005654 if (tc->type != TC_SETUP_MQPRIO)
John Fastabende4c67342016-02-16 21:16:15 -08005655 return -EINVAL;
Amritha Nambiar56f36ac2017-03-15 10:39:25 -07005656
5657 tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
5658
5659 return i40e_setup_tc(netdev, tc->mqprio->num_tc);
John Fastabende4c67342016-02-16 21:16:15 -08005660}
5661
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005662/**
5663 * i40e_open - Called when a network interface is made active
5664 * @netdev: network interface device structure
5665 *
5666 * The open entry point is called when a network interface is made
5667 * active by the system (IFF_UP). At this point all resources needed
5668 * for transmit and receive operations are allocated, the interrupt
5669 * handler is registered with the OS, the netdev watchdog subtask is
5670 * enabled, and the stack is notified that the interface is ready.
5671 *
5672 * Returns 0 on success, negative value on failure
5673 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005674int i40e_open(struct net_device *netdev)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005675{
5676 struct i40e_netdev_priv *np = netdev_priv(netdev);
5677 struct i40e_vsi *vsi = np->vsi;
5678 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005679 int err;
5680
Shannon Nelson4eb3f762014-03-06 08:59:58 +00005681 /* disallow open during test or if eeprom is broken */
Jacob Keller0da36b92017-04-19 09:25:55 -04005682 if (test_bit(__I40E_TESTING, pf->state) ||
5683 test_bit(__I40E_BAD_EEPROM, pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005684 return -EBUSY;
5685
5686 netif_carrier_off(netdev);
5687
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005688 err = i40e_vsi_open(vsi);
5689 if (err)
5690 return err;
5691
Jesse Brandeburg059dab62014-04-01 09:07:20 +00005692 /* configure global TSO hardware offload settings */
5693 wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
5694 TCP_FLAG_FIN) >> 16);
5695 wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
5696 TCP_FLAG_FIN |
5697 TCP_FLAG_CWR) >> 16);
5698 wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
5699
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07005700 udp_tunnel_get_rx_info(netdev);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06005701
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005702 return 0;
5703}
5704
5705/**
5706 * i40e_vsi_open -
5707 * @vsi: the VSI to open
5708 *
5709 * Finish initialization of the VSI.
5710 *
5711 * Returns 0 on success, negative value on failure
Maciej Sosin373149f2017-04-05 07:50:55 -04005712 *
5713 * Note: expects to be called while under rtnl_lock()
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005714 **/
5715int i40e_vsi_open(struct i40e_vsi *vsi)
5716{
5717 struct i40e_pf *pf = vsi->back;
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00005718 char int_name[I40E_INT_NAME_STR_LEN];
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005719 int err;
5720
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005721 /* allocate descriptors */
5722 err = i40e_vsi_setup_tx_resources(vsi);
5723 if (err)
5724 goto err_setup_tx;
5725 err = i40e_vsi_setup_rx_resources(vsi);
5726 if (err)
5727 goto err_setup_rx;
5728
5729 err = i40e_vsi_configure(vsi);
5730 if (err)
5731 goto err_setup_rx;
5732
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00005733 if (vsi->netdev) {
5734 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
5735 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
5736 err = i40e_vsi_request_irq(vsi, int_name);
5737 if (err)
5738 goto err_setup_rx;
5739
5740 /* Notify the stack of the actual queue counts. */
5741 err = netif_set_real_num_tx_queues(vsi->netdev,
5742 vsi->num_queue_pairs);
5743 if (err)
5744 goto err_set_queues;
5745
5746 err = netif_set_real_num_rx_queues(vsi->netdev,
5747 vsi->num_queue_pairs);
5748 if (err)
5749 goto err_set_queues;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005750
5751 } else if (vsi->type == I40E_VSI_FDIR) {
Carolyn Wybornye240f672014-12-11 07:06:37 +00005752 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +00005753 dev_driver_string(&pf->pdev->dev),
5754 dev_name(&pf->pdev->dev));
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005755 err = i40e_vsi_request_irq(vsi, int_name);
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +00005756
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00005757 } else {
Jean Sacrence9ccb12014-05-01 14:31:18 +00005758 err = -EINVAL;
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005759 goto err_setup_rx;
5760 }
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00005761
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005762 err = i40e_up_complete(vsi);
5763 if (err)
5764 goto err_up_complete;
5765
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005766 return 0;
5767
5768err_up_complete:
5769 i40e_down(vsi);
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00005770err_set_queues:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005771 i40e_vsi_free_irq(vsi);
5772err_setup_rx:
5773 i40e_vsi_free_rx_resources(vsi);
5774err_setup_tx:
5775 i40e_vsi_free_tx_resources(vsi);
5776 if (vsi == pf->vsi[pf->lan_vsi])
Maciej Sosin373149f2017-04-05 07:50:55 -04005777 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005778
5779 return err;
5780}
5781
5782/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005783 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00005784 * @pf: Pointer to PF
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005785 *
5786 * This function destroys the hlist where all the Flow Director
5787 * filters were saved.
5788 **/
5789static void i40e_fdir_filter_exit(struct i40e_pf *pf)
5790{
5791 struct i40e_fdir_filter *filter;
Jacob Keller0e588de2017-02-06 14:38:50 -08005792 struct i40e_flex_pit *pit_entry, *tmp;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005793 struct hlist_node *node2;
5794
5795 hlist_for_each_entry_safe(filter, node2,
5796 &pf->fdir_filter_list, fdir_node) {
5797 hlist_del(&filter->fdir_node);
5798 kfree(filter);
5799 }
Jacob Keller097dbf52017-02-06 14:38:46 -08005800
Jacob Keller0e588de2017-02-06 14:38:50 -08005801 list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) {
5802 list_del(&pit_entry->list);
5803 kfree(pit_entry);
5804 }
5805 INIT_LIST_HEAD(&pf->l3_flex_pit_list);
5806
5807 list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) {
5808 list_del(&pit_entry->list);
5809 kfree(pit_entry);
5810 }
5811 INIT_LIST_HEAD(&pf->l4_flex_pit_list);
5812
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005813 pf->fdir_pf_active_filters = 0;
Jacob Keller097dbf52017-02-06 14:38:46 -08005814 pf->fd_tcp4_filter_cnt = 0;
5815 pf->fd_udp4_filter_cnt = 0;
Jacob Kellerf223c872017-02-06 14:38:51 -08005816 pf->fd_sctp4_filter_cnt = 0;
Jacob Keller097dbf52017-02-06 14:38:46 -08005817 pf->fd_ip4_filter_cnt = 0;
Jacob Keller3bcee1e2017-02-06 14:38:46 -08005818
5819 /* Reprogram the default input set for TCP/IPv4 */
5820 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
5821 I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
5822 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
5823
5824 /* Reprogram the default input set for UDP/IPv4 */
5825 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP,
5826 I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
5827 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
5828
5829 /* Reprogram the default input set for SCTP/IPv4 */
5830 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP,
5831 I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
5832 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
5833
5834 /* Reprogram the default input set for Other/IPv4 */
5835 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER,
5836 I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005837}
5838
5839/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005840 * i40e_close - Disables a network interface
5841 * @netdev: network interface device structure
5842 *
5843 * The close entry point is called when an interface is de-activated
5844 * by the OS. The hardware is still under the driver's control, but
5845 * this netdev interface is disabled.
5846 *
5847 * Returns 0, this is not allowed to fail
5848 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005849int i40e_close(struct net_device *netdev)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005850{
5851 struct i40e_netdev_priv *np = netdev_priv(netdev);
5852 struct i40e_vsi *vsi = np->vsi;
5853
Shannon Nelson90ef8d42014-03-14 07:32:26 +00005854 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005855
5856 return 0;
5857}
5858
5859/**
5860 * i40e_do_reset - Start a PF or Core Reset sequence
5861 * @pf: board private structure
5862 * @reset_flags: which reset is requested
Maciej Sosin373149f2017-04-05 07:50:55 -04005863 * @lock_acquired: indicates whether or not the lock has been acquired
5864 * before this function was called.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005865 *
5866 * The essential difference in resets is that the PF Reset
5867 * doesn't clear the packet buffers, doesn't reset the PE
5868 * firmware, and doesn't bother the other PFs on the chip.
5869 **/
Maciej Sosin373149f2017-04-05 07:50:55 -04005870void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005871{
5872 u32 val;
5873
5874 WARN_ON(in_interrupt());
5875
Mitch Williams263fc482014-04-23 04:50:11 +00005876
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005877 /* do the biggest reset indicated */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005878 if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005879
5880 /* Request a Global Reset
5881 *
5882 * This will start the chip's countdown to the actual full
5883 * chip reset event, and a warning interrupt to be sent
5884 * to all PFs, including the requestor. Our handler
5885 * for the warning interrupt will deal with the shutdown
5886 * and recovery of the switch setup.
5887 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005888 dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005889 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5890 val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
5891 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5892
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005893 } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005894
5895 /* Request a Core Reset
5896 *
5897 * Same as Global Reset, except does *not* include the MAC/PHY
5898 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005899 dev_dbg(&pf->pdev->dev, "CoreR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005900 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5901 val |= I40E_GLGEN_RTRIG_CORER_MASK;
5902 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5903 i40e_flush(&pf->hw);
5904
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005905 } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005906
5907 /* Request a PF Reset
5908 *
5909 * Resets only the PF-specific registers
5910 *
5911 * This goes directly to the tear-down and rebuild of
5912 * the switch, since we need to do all the recovery as
5913 * for the Core Reset.
5914 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005915 dev_dbg(&pf->pdev->dev, "PFR requested\n");
Maciej Sosin373149f2017-04-05 07:50:55 -04005916 i40e_handle_reset_warning(pf, lock_acquired);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005917
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005918 } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005919 int v;
5920
5921 /* Find the VSI(s) that requested a re-init */
5922 dev_info(&pf->pdev->dev,
5923 "VSI reinit requested\n");
Mitch Williams505682c2014-05-20 08:01:37 +00005924 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005925 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04005926
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005927 if (vsi != NULL &&
Jacob Kellerd19cb642017-04-21 13:38:05 -07005928 test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED,
Jacob Keller0da36b92017-04-19 09:25:55 -04005929 vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005930 i40e_vsi_reinit_locked(pf->vsi[v]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005931 }
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005932 } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005933 int v;
5934
5935 /* Find the VSI(s) that needs to be brought down */
5936 dev_info(&pf->pdev->dev, "VSI down requested\n");
5937 for (v = 0; v < pf->num_alloc_vsi; v++) {
5938 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04005939
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005940 if (vsi != NULL &&
Jacob Kellerd19cb642017-04-21 13:38:05 -07005941 test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED,
Jacob Keller0da36b92017-04-19 09:25:55 -04005942 vsi->state)) {
5943 set_bit(__I40E_VSI_DOWN, vsi->state);
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005944 i40e_down(vsi);
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005945 }
5946 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005947 } else {
5948 dev_info(&pf->pdev->dev,
5949 "bad reset request 0x%08x\n", reset_flags);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005950 }
5951}
5952
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005953#ifdef CONFIG_I40E_DCB
5954/**
5955 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
5956 * @pf: board private structure
5957 * @old_cfg: current DCB config
5958 * @new_cfg: new DCB config
5959 **/
5960bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
5961 struct i40e_dcbx_config *old_cfg,
5962 struct i40e_dcbx_config *new_cfg)
5963{
5964 bool need_reconfig = false;
5965
5966 /* Check if ETS configuration has changed */
5967 if (memcmp(&new_cfg->etscfg,
5968 &old_cfg->etscfg,
5969 sizeof(new_cfg->etscfg))) {
5970 /* If Priority Table has changed reconfig is needed */
5971 if (memcmp(&new_cfg->etscfg.prioritytable,
5972 &old_cfg->etscfg.prioritytable,
5973 sizeof(new_cfg->etscfg.prioritytable))) {
5974 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005975 dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005976 }
5977
5978 if (memcmp(&new_cfg->etscfg.tcbwtable,
5979 &old_cfg->etscfg.tcbwtable,
5980 sizeof(new_cfg->etscfg.tcbwtable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005981 dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005982
5983 if (memcmp(&new_cfg->etscfg.tsatable,
5984 &old_cfg->etscfg.tsatable,
5985 sizeof(new_cfg->etscfg.tsatable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005986 dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005987 }
5988
5989 /* Check if PFC configuration has changed */
5990 if (memcmp(&new_cfg->pfc,
5991 &old_cfg->pfc,
5992 sizeof(new_cfg->pfc))) {
5993 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005994 dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005995 }
5996
5997 /* Check if APP Table has changed */
5998 if (memcmp(&new_cfg->app,
5999 &old_cfg->app,
Dave Jones3d9667a2014-01-27 23:11:09 -05006000 sizeof(new_cfg->app))) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006001 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006002 dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
Dave Jones3d9667a2014-01-27 23:11:09 -05006003 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006004
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04006005 dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006006 return need_reconfig;
6007}
6008
6009/**
6010 * i40e_handle_lldp_event - Handle LLDP Change MIB event
6011 * @pf: board private structure
6012 * @e: event info posted on ARQ
6013 **/
6014static int i40e_handle_lldp_event(struct i40e_pf *pf,
6015 struct i40e_arq_event_info *e)
6016{
6017 struct i40e_aqc_lldp_get_mib *mib =
6018 (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
6019 struct i40e_hw *hw = &pf->hw;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006020 struct i40e_dcbx_config tmp_dcbx_cfg;
6021 bool need_reconfig = false;
6022 int ret = 0;
6023 u8 type;
6024
Neerav Parikh4d9b6042014-05-22 06:31:51 +00006025 /* Not DCB capable or capability disabled */
David Ertmanea6acb72016-09-20 07:10:50 -07006026 if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
Neerav Parikh4d9b6042014-05-22 06:31:51 +00006027 return ret;
6028
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006029 /* Ignore if event is not for Nearest Bridge */
6030 type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
6031 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04006032 dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006033 if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
6034 return ret;
6035
6036 /* Check MIB Type and return if event for Remote MIB update */
6037 type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00006038 dev_dbg(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04006039 "LLDP event mib type %s\n", type ? "remote" : "local");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006040 if (type == I40E_AQ_LLDP_MIB_REMOTE) {
6041 /* Update the remote cached instance and return */
6042 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
6043 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
6044 &hw->remote_dcbx_config);
6045 goto exit;
6046 }
6047
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00006048 /* Store the old configuration */
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07006049 tmp_dcbx_cfg = hw->local_dcbx_config;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00006050
Neerav Parikh750fcbc2015-02-24 06:58:47 +00006051 /* Reset the old DCBx configuration data */
6052 memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00006053 /* Get updated DCBX data from firmware */
6054 ret = i40e_get_dcb_config(&pf->hw);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006055 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006056 dev_info(&pf->pdev->dev,
6057 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
6058 i40e_stat_str(&pf->hw, ret),
6059 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006060 goto exit;
6061 }
6062
6063 /* No change detected in DCBX configs */
Neerav Parikh750fcbc2015-02-24 06:58:47 +00006064 if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
6065 sizeof(tmp_dcbx_cfg))) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006066 dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006067 goto exit;
6068 }
6069
Neerav Parikh750fcbc2015-02-24 06:58:47 +00006070 need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
6071 &hw->local_dcbx_config);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006072
Neerav Parikh750fcbc2015-02-24 06:58:47 +00006073 i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006074
6075 if (!need_reconfig)
6076 goto exit;
6077
Neerav Parikh4d9b6042014-05-22 06:31:51 +00006078 /* Enable DCB tagging only when more than one TC */
Neerav Parikh750fcbc2015-02-24 06:58:47 +00006079 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
Neerav Parikh4d9b6042014-05-22 06:31:51 +00006080 pf->flags |= I40E_FLAG_DCB_ENABLED;
6081 else
6082 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
6083
Jacob Keller0da36b92017-04-19 09:25:55 -04006084 set_bit(__I40E_PORT_SUSPENDED, pf->state);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006085 /* Reconfiguration needed quiesce all VSIs */
6086 i40e_pf_quiesce_all_vsi(pf);
6087
6088 /* Changes in configuration update VEB/VSI */
6089 i40e_dcb_reconfigure(pf);
6090
Neerav Parikh2fd75f32014-11-12 00:18:20 +00006091 ret = i40e_resume_port_tx(pf);
6092
Jacob Keller0da36b92017-04-19 09:25:55 -04006093 clear_bit(__I40E_PORT_SUSPENDED, pf->state);
Neerav Parikh2fd75f32014-11-12 00:18:20 +00006094 /* In case of error no point in resuming VSIs */
Neerav Parikh69129dc2014-11-12 00:18:46 +00006095 if (ret)
6096 goto exit;
6097
Neerav Parikh3fe06f42016-02-17 16:12:15 -08006098 /* Wait for the PF's queues to be disabled */
6099 ret = i40e_pf_wait_queues_disabled(pf);
Parikh, Neerav11e47702015-02-21 06:43:55 +00006100 if (ret) {
6101 /* Schedule PF reset to recover */
Jacob Keller0da36b92017-04-19 09:25:55 -04006102 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
Parikh, Neerav11e47702015-02-21 06:43:55 +00006103 i40e_service_event_schedule(pf);
6104 } else {
Neerav Parikh2fd75f32014-11-12 00:18:20 +00006105 i40e_pf_unquiesce_all_vsi(pf);
Mitch Williams0ef2d5a2017-01-24 10:24:00 -08006106 pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED |
6107 I40E_FLAG_CLIENT_L2_CHANGE);
Parikh, Neerav11e47702015-02-21 06:43:55 +00006108 }
6109
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006110exit:
6111 return ret;
6112}
6113#endif /* CONFIG_I40E_DCB */
6114
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006115/**
Anjali Singhai Jain233261862013-11-26 10:49:22 +00006116 * i40e_do_reset_safe - Protected reset path for userland calls.
6117 * @pf: board private structure
6118 * @reset_flags: which reset is requested
6119 *
6120 **/
6121void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
6122{
6123 rtnl_lock();
Maciej Sosin373149f2017-04-05 07:50:55 -04006124 i40e_do_reset(pf, reset_flags, true);
Anjali Singhai Jain233261862013-11-26 10:49:22 +00006125 rtnl_unlock();
6126}
6127
6128/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006129 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
6130 * @pf: board private structure
6131 * @e: event info posted on ARQ
6132 *
6133 * Handler for LAN Queue Overflow Event generated by the firmware for PF
6134 * and VF queues
6135 **/
6136static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
6137 struct i40e_arq_event_info *e)
6138{
6139 struct i40e_aqc_lan_overflow *data =
6140 (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
6141 u32 queue = le32_to_cpu(data->prtdcb_rupto);
6142 u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
6143 struct i40e_hw *hw = &pf->hw;
6144 struct i40e_vf *vf;
6145 u16 vf_id;
6146
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006147 dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
6148 queue, qtx_ctl);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006149
6150 /* Queue belongs to VF, find the VF and issue VF reset */
6151 if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
6152 >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
6153 vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
6154 >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
6155 vf_id -= hw->func_caps.vf_base_id;
6156 vf = &pf->vf[vf_id];
6157 i40e_vc_notify_vf_reset(vf);
6158 /* Allow VF to process pending reset notification */
6159 msleep(20);
6160 i40e_reset_vf(vf, false);
6161 }
6162}
6163
6164/**
Anjali Singhai Jain12957382014-06-04 04:22:47 +00006165 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
6166 * @pf: board private structure
6167 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006168u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
Anjali Singhai Jain12957382014-06-04 04:22:47 +00006169{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006170 u32 val, fcnt_prog;
Anjali Singhai Jain12957382014-06-04 04:22:47 +00006171
6172 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
6173 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
6174 return fcnt_prog;
6175}
6176
6177/**
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006178 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006179 * @pf: board private structure
6180 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006181u32 i40e_get_current_fd_count(struct i40e_pf *pf)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006182{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006183 u32 val, fcnt_prog;
6184
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006185 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
6186 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
6187 ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
6188 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
6189 return fcnt_prog;
6190}
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006191
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006192/**
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006193 * i40e_get_global_fd_count - Get total FD filters programmed on device
6194 * @pf: board private structure
6195 **/
6196u32 i40e_get_global_fd_count(struct i40e_pf *pf)
6197{
6198 u32 val, fcnt_prog;
6199
6200 val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
6201 fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
6202 ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
6203 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
6204 return fcnt_prog;
6205}
6206
6207/**
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006208 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
6209 * @pf: board private structure
6210 **/
6211void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
6212{
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04006213 struct i40e_fdir_filter *filter;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006214 u32 fcnt_prog, fcnt_avail;
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04006215 struct hlist_node *node;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006216
Jacob Keller0da36b92017-04-19 09:25:55 -04006217 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006218 return;
6219
Jacob Keller47994c12017-04-19 09:25:57 -04006220 /* Check if we have enough room to re-enable FDir SB capability. */
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006221 fcnt_prog = i40e_get_global_fd_count(pf);
Anjali Singhai Jain12957382014-06-04 04:22:47 +00006222 fcnt_avail = pf->fdir_pf_filter_count;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006223 if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
6224 (pf->fd_add_err == 0) ||
6225 (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
Jacob Keller47994c12017-04-19 09:25:57 -04006226 if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED) {
6227 pf->flags &= ~I40E_FLAG_FD_SB_AUTO_DISABLED;
6228 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
6229 (I40E_DEBUG_FD & pf->hw.debug_mask))
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04006230 dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006231 }
6232 }
Jacob Kellera3417d22016-09-06 18:05:10 -07006233
Jacob Keller47994c12017-04-19 09:25:57 -04006234 /* We should wait for even more space before re-enabling ATR.
6235 * Additionally, we cannot enable ATR as long as we still have TCP SB
6236 * rules active.
Jacob Kellera3417d22016-09-06 18:05:10 -07006237 */
Jacob Keller47994c12017-04-19 09:25:57 -04006238 if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) &&
6239 (pf->fd_tcp4_filter_cnt == 0)) {
6240 if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) {
6241 pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
6242 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
6243 (I40E_DEBUG_FD & pf->hw.debug_mask))
Jacob Kellera3417d22016-09-06 18:05:10 -07006244 dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006245 }
6246 }
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04006247
6248 /* if hw had a problem adding a filter, delete it */
6249 if (pf->fd_inv > 0) {
6250 hlist_for_each_entry_safe(filter, node,
6251 &pf->fdir_filter_list, fdir_node) {
6252 if (filter->fd_id == pf->fd_inv) {
6253 hlist_del(&filter->fdir_node);
6254 kfree(filter);
6255 pf->fdir_pf_active_filters--;
6256 }
6257 }
6258 }
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006259}
6260
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006261#define I40E_MIN_FD_FLUSH_INTERVAL 10
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006262#define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006263/**
6264 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
6265 * @pf: board private structure
6266 **/
6267static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
6268{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006269 unsigned long min_flush_time;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006270 int flush_wait_retry = 50;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006271 bool disable_atr = false;
6272 int fd_room;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006273 int reg;
6274
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006275 if (!time_after(jiffies, pf->fd_flush_timestamp +
6276 (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
6277 return;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006278
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006279 /* If the flush is happening too quick and we have mostly SB rules we
6280 * should not re-enable ATR for some time.
6281 */
6282 min_flush_time = pf->fd_flush_timestamp +
6283 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
6284 fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006285
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006286 if (!(time_after(jiffies, min_flush_time)) &&
6287 (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
6288 if (I40E_DEBUG_FD & pf->hw.debug_mask)
6289 dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
6290 disable_atr = true;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006291 }
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006292
6293 pf->fd_flush_timestamp = jiffies;
Jacob Keller47994c12017-04-19 09:25:57 -04006294 pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006295 /* flush all filters */
6296 wr32(&pf->hw, I40E_PFQF_CTL_1,
6297 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
6298 i40e_flush(&pf->hw);
6299 pf->fd_flush_cnt++;
6300 pf->fd_add_err = 0;
6301 do {
6302 /* Check FD flush status every 5-6msec */
6303 usleep_range(5000, 6000);
6304 reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
6305 if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
6306 break;
6307 } while (flush_wait_retry--);
6308 if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
6309 dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
6310 } else {
6311 /* replay sideband filters */
6312 i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
Jacob Keller097dbf52017-02-06 14:38:46 -08006313 if (!disable_atr && !pf->fd_tcp4_filter_cnt)
Jacob Keller47994c12017-04-19 09:25:57 -04006314 pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
Jacob Keller0da36b92017-04-19 09:25:55 -04006315 clear_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006316 if (I40E_DEBUG_FD & pf->hw.debug_mask)
6317 dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
6318 }
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006319}
6320
6321/**
6322 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
6323 * @pf: board private structure
6324 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006325u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006326{
6327 return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
6328}
6329
6330/* We can see up to 256 filter programming desc in transit if the filters are
6331 * being applied really fast; before we see the first
6332 * filter miss error on Rx queue 0. Accumulating enough error messages before
6333 * reacting will make sure we don't cause flush too often.
6334 */
6335#define I40E_MAX_FD_PROGRAM_ERROR 256
6336
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006337/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006338 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
6339 * @pf: board private structure
6340 **/
6341static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
6342{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006343
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006344 /* if interface is down do nothing */
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -03006345 if (test_bit(__I40E_DOWN, pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006346 return;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006347
Jacob Keller0da36b92017-04-19 09:25:55 -04006348 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006349 i40e_fdir_flush_and_replay(pf);
6350
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006351 i40e_fdir_check_and_reenable(pf);
6352
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006353}
6354
6355/**
6356 * i40e_vsi_link_event - notify VSI of a link event
6357 * @vsi: vsi to be notified
6358 * @link_up: link up or down
6359 **/
6360static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
6361{
Jacob Keller0da36b92017-04-19 09:25:55 -04006362 if (!vsi || test_bit(__I40E_VSI_DOWN, vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006363 return;
6364
6365 switch (vsi->type) {
6366 case I40E_VSI_MAIN:
6367 if (!vsi->netdev || !vsi->netdev_registered)
6368 break;
6369
6370 if (link_up) {
6371 netif_carrier_on(vsi->netdev);
6372 netif_tx_wake_all_queues(vsi->netdev);
6373 } else {
6374 netif_carrier_off(vsi->netdev);
6375 netif_tx_stop_all_queues(vsi->netdev);
6376 }
6377 break;
6378
6379 case I40E_VSI_SRIOV:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006380 case I40E_VSI_VMDQ2:
6381 case I40E_VSI_CTRL:
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06006382 case I40E_VSI_IWARP:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006383 case I40E_VSI_MIRROR:
6384 default:
6385 /* there is no notification for other VSIs */
6386 break;
6387 }
6388}
6389
6390/**
6391 * i40e_veb_link_event - notify elements on the veb of a link event
6392 * @veb: veb to be notified
6393 * @link_up: link up or down
6394 **/
6395static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
6396{
6397 struct i40e_pf *pf;
6398 int i;
6399
6400 if (!veb || !veb->pf)
6401 return;
6402 pf = veb->pf;
6403
6404 /* depth first... */
6405 for (i = 0; i < I40E_MAX_VEB; i++)
6406 if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
6407 i40e_veb_link_event(pf->veb[i], link_up);
6408
6409 /* ... now the local VSIs */
Mitch Williams505682c2014-05-20 08:01:37 +00006410 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006411 if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
6412 i40e_vsi_link_event(pf->vsi[i], link_up);
6413}
6414
6415/**
6416 * i40e_link_event - Update netif_carrier status
6417 * @pf: board private structure
6418 **/
6419static void i40e_link_event(struct i40e_pf *pf)
6420{
Mitch Williams320684c2014-10-17 03:14:43 +00006421 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006422 u8 new_link_speed, old_link_speed;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006423 i40e_status status;
6424 bool new_link, old_link;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006425
Catherine Sullivan1f9610e2015-10-21 19:47:09 -04006426 /* save off old link status information */
6427 pf->hw.phy.link_info_old = pf->hw.phy.link_info;
6428
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006429 /* set this to force the get_link_status call to refresh state */
6430 pf->hw.phy.get_link_info = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006431
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006432 old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006433
6434 status = i40e_get_link_status(&pf->hw, &new_link);
Harshitha Ramamurthyae136702016-12-12 15:44:16 -08006435
6436 /* On success, disable temp link polling */
6437 if (status == I40E_SUCCESS) {
6438 if (pf->flags & I40E_FLAG_TEMP_LINK_POLLING)
6439 pf->flags &= ~I40E_FLAG_TEMP_LINK_POLLING;
6440 } else {
6441 /* Enable link polling temporarily until i40e_get_link_status
6442 * returns I40E_SUCCESS
6443 */
6444 pf->flags |= I40E_FLAG_TEMP_LINK_POLLING;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006445 dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
6446 status);
6447 return;
6448 }
6449
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006450 old_link_speed = pf->hw.phy.link_info_old.link_speed;
6451 new_link_speed = pf->hw.phy.link_info.link_speed;
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006452
6453 if (new_link == old_link &&
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006454 new_link_speed == old_link_speed &&
Jacob Keller0da36b92017-04-19 09:25:55 -04006455 (test_bit(__I40E_VSI_DOWN, vsi->state) ||
Mitch Williams320684c2014-10-17 03:14:43 +00006456 new_link == netif_carrier_ok(vsi->netdev)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006457 return;
Mitch Williams320684c2014-10-17 03:14:43 +00006458
Jacob Keller0da36b92017-04-19 09:25:55 -04006459 if (!test_bit(__I40E_VSI_DOWN, vsi->state))
Mitch Williams320684c2014-10-17 03:14:43 +00006460 i40e_print_link_message(vsi, new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006461
6462 /* Notify the base of the switch tree connected to
6463 * the link. Floating VEBs are not notified.
6464 */
6465 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
6466 i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
6467 else
Mitch Williams320684c2014-10-17 03:14:43 +00006468 i40e_vsi_link_event(vsi, new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006469
6470 if (pf->vf)
6471 i40e_vc_notify_link_state(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00006472
6473 if (pf->flags & I40E_FLAG_PTP)
6474 i40e_ptp_set_increment(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006475}
6476
6477/**
Shannon Nelson21536712014-10-25 10:35:25 +00006478 * i40e_watchdog_subtask - periodic checks not using event driven response
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006479 * @pf: board private structure
6480 **/
6481static void i40e_watchdog_subtask(struct i40e_pf *pf)
6482{
6483 int i;
6484
6485 /* if interface is down do nothing */
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -03006486 if (test_bit(__I40E_DOWN, pf->state) ||
Jacob Keller0da36b92017-04-19 09:25:55 -04006487 test_bit(__I40E_CONFIG_BUSY, pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006488 return;
6489
Shannon Nelson21536712014-10-25 10:35:25 +00006490 /* make sure we don't do these things too often */
6491 if (time_before(jiffies, (pf->service_timer_previous +
6492 pf->service_timer_period)))
6493 return;
6494 pf->service_timer_previous = jiffies;
6495
Harshitha Ramamurthyae136702016-12-12 15:44:16 -08006496 if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) ||
6497 (pf->flags & I40E_FLAG_TEMP_LINK_POLLING))
Shannon Nelson9ac77262015-08-27 11:42:40 -04006498 i40e_link_event(pf);
Shannon Nelson21536712014-10-25 10:35:25 +00006499
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006500 /* Update the stats for active netdevs so the network stack
6501 * can look at updated numbers whenever it cares to
6502 */
Mitch Williams505682c2014-05-20 08:01:37 +00006503 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006504 if (pf->vsi[i] && pf->vsi[i]->netdev)
6505 i40e_update_stats(pf->vsi[i]);
6506
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04006507 if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
6508 /* Update the stats for the active switching components */
6509 for (i = 0; i < I40E_MAX_VEB; i++)
6510 if (pf->veb[i])
6511 i40e_update_veb_stats(pf->veb[i]);
6512 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00006513
Jacob Keller61189552017-05-03 10:29:01 -07006514 i40e_ptp_rx_hang(pf);
Jacob Keller0bc07062017-05-03 10:29:02 -07006515 i40e_ptp_tx_hang(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006516}
6517
6518/**
6519 * i40e_reset_subtask - Set up for resetting the device and driver
6520 * @pf: board private structure
6521 **/
6522static void i40e_reset_subtask(struct i40e_pf *pf)
6523{
6524 u32 reset_flags = 0;
6525
Jacob Keller0da36b92017-04-19 09:25:55 -04006526 if (test_bit(__I40E_REINIT_REQUESTED, pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006527 reset_flags |= BIT(__I40E_REINIT_REQUESTED);
Jacob Keller0da36b92017-04-19 09:25:55 -04006528 clear_bit(__I40E_REINIT_REQUESTED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006529 }
Jacob Keller0da36b92017-04-19 09:25:55 -04006530 if (test_bit(__I40E_PF_RESET_REQUESTED, pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006531 reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
Jacob Keller0da36b92017-04-19 09:25:55 -04006532 clear_bit(__I40E_PF_RESET_REQUESTED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006533 }
Jacob Keller0da36b92017-04-19 09:25:55 -04006534 if (test_bit(__I40E_CORE_RESET_REQUESTED, pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006535 reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
Jacob Keller0da36b92017-04-19 09:25:55 -04006536 clear_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006537 }
Jacob Keller0da36b92017-04-19 09:25:55 -04006538 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006539 reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
Jacob Keller0da36b92017-04-19 09:25:55 -04006540 clear_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006541 }
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -03006542 if (test_bit(__I40E_DOWN_REQUESTED, pf->state)) {
6543 reset_flags |= BIT(__I40E_DOWN_REQUESTED);
6544 clear_bit(__I40E_DOWN_REQUESTED, pf->state);
Neerav Parikhb5d06f02014-06-03 23:50:17 +00006545 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006546
6547 /* If there's a recovery already waiting, it takes
6548 * precedence before starting a new reset sequence.
6549 */
Jacob Keller0da36b92017-04-19 09:25:55 -04006550 if (test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) {
Maciej Sosin373149f2017-04-05 07:50:55 -04006551 i40e_prep_for_reset(pf, false);
6552 i40e_reset(pf);
6553 i40e_rebuild(pf, false, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006554 }
6555
6556 /* If we're already down or resetting, just bail */
6557 if (reset_flags &&
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -03006558 !test_bit(__I40E_DOWN, pf->state) &&
Jacob Keller0da36b92017-04-19 09:25:55 -04006559 !test_bit(__I40E_CONFIG_BUSY, pf->state)) {
Maciej Sosin373149f2017-04-05 07:50:55 -04006560 rtnl_lock();
6561 i40e_do_reset(pf, reset_flags, true);
6562 rtnl_unlock();
6563 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006564}
6565
6566/**
6567 * i40e_handle_link_event - Handle link event
6568 * @pf: board private structure
6569 * @e: event info posted on ARQ
6570 **/
6571static void i40e_handle_link_event(struct i40e_pf *pf,
6572 struct i40e_arq_event_info *e)
6573{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006574 struct i40e_aqc_get_link_status *status =
6575 (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006576
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006577 /* Do a new status request to re-enable LSE reporting
6578 * and load new status information into the hw struct
6579 * This completely ignores any state information
6580 * in the ARQ event info, instead choosing to always
6581 * issue the AQ update link status command.
6582 */
6583 i40e_link_event(pf);
6584
Carolyn Wyborny7b592f62014-07-10 07:58:19 +00006585 /* check for unqualified module, if link is down */
6586 if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
6587 (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
6588 (!(status->link_info & I40E_AQ_LINK_UP)))
6589 dev_err(&pf->pdev->dev,
6590 "The driver failed to link because an unqualified module was detected.\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006591}
6592
6593/**
6594 * i40e_clean_adminq_subtask - Clean the AdminQ rings
6595 * @pf: board private structure
6596 **/
6597static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
6598{
6599 struct i40e_arq_event_info event;
6600 struct i40e_hw *hw = &pf->hw;
6601 u16 pending, i = 0;
6602 i40e_status ret;
6603 u16 opcode;
Shannon Nelson86df2422014-05-20 08:01:35 +00006604 u32 oldval;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006605 u32 val;
6606
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006607 /* Do not run clean AQ when PF reset fails */
Jacob Keller0da36b92017-04-19 09:25:55 -04006608 if (test_bit(__I40E_RESET_FAILED, pf->state))
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006609 return;
6610
Shannon Nelson86df2422014-05-20 08:01:35 +00006611 /* check for error indications */
6612 val = rd32(&pf->hw, pf->hw.aq.arq.len);
6613 oldval = val;
6614 if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006615 if (hw->debug_mask & I40E_DEBUG_AQ)
6616 dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006617 val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
6618 }
6619 if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006620 if (hw->debug_mask & I40E_DEBUG_AQ)
6621 dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006622 val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
Mitch Williams1d0a4ad2015-12-23 12:05:48 -08006623 pf->arq_overflows++;
Shannon Nelson86df2422014-05-20 08:01:35 +00006624 }
6625 if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006626 if (hw->debug_mask & I40E_DEBUG_AQ)
6627 dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006628 val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
6629 }
6630 if (oldval != val)
6631 wr32(&pf->hw, pf->hw.aq.arq.len, val);
6632
6633 val = rd32(&pf->hw, pf->hw.aq.asq.len);
6634 oldval = val;
6635 if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006636 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6637 dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006638 val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
6639 }
6640 if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006641 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6642 dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006643 val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
6644 }
6645 if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006646 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6647 dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006648 val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
6649 }
6650 if (oldval != val)
6651 wr32(&pf->hw, pf->hw.aq.asq.len, val);
6652
Mitch Williams1001dc32014-11-11 20:02:19 +00006653 event.buf_len = I40E_MAX_AQ_BUF_SIZE;
6654 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006655 if (!event.msg_buf)
6656 return;
6657
6658 do {
6659 ret = i40e_clean_arq_element(hw, &event, &pending);
Mitch Williams56497972014-06-04 08:45:18 +00006660 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006661 break;
Mitch Williams56497972014-06-04 08:45:18 +00006662 else if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006663 dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
6664 break;
6665 }
6666
6667 opcode = le16_to_cpu(event.desc.opcode);
6668 switch (opcode) {
6669
6670 case i40e_aqc_opc_get_link_status:
6671 i40e_handle_link_event(pf, &event);
6672 break;
6673 case i40e_aqc_opc_send_msg_to_pf:
6674 ret = i40e_vc_process_vf_msg(pf,
6675 le16_to_cpu(event.desc.retval),
6676 le32_to_cpu(event.desc.cookie_high),
6677 le32_to_cpu(event.desc.cookie_low),
6678 event.msg_buf,
Mitch Williams1001dc32014-11-11 20:02:19 +00006679 event.msg_len);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006680 break;
6681 case i40e_aqc_opc_lldp_update_mib:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006682 dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006683#ifdef CONFIG_I40E_DCB
6684 rtnl_lock();
6685 ret = i40e_handle_lldp_event(pf, &event);
6686 rtnl_unlock();
6687#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006688 break;
6689 case i40e_aqc_opc_event_lan_overflow:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006690 dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006691 i40e_handle_lan_overflow_event(pf, &event);
6692 break;
Shannon Nelson0467bc92013-12-18 13:45:58 +00006693 case i40e_aqc_opc_send_msg_to_peer:
6694 dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
6695 break;
Shannon Nelson91a0f932015-03-19 14:32:01 -07006696 case i40e_aqc_opc_nvm_erase:
6697 case i40e_aqc_opc_nvm_update:
Michal Kosiarz00ada502015-11-19 11:34:20 -08006698 case i40e_aqc_opc_oem_post_update:
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08006699 i40e_debug(&pf->hw, I40E_DEBUG_NVM,
6700 "ARQ NVM operation 0x%04x completed\n",
6701 opcode);
Shannon Nelson91a0f932015-03-19 14:32:01 -07006702 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006703 default:
6704 dev_info(&pf->pdev->dev,
Shannon Nelson56e5ca62016-03-10 14:59:48 -08006705 "ARQ: Unknown event 0x%04x ignored\n",
Shannon Nelson0467bc92013-12-18 13:45:58 +00006706 opcode);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006707 break;
6708 }
Christopher N Bednarz1fca3262017-03-10 12:22:03 -08006709 } while (i++ < pf->adminq_work_limit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006710
Christopher N Bednarz1fca3262017-03-10 12:22:03 -08006711 if (i < pf->adminq_work_limit)
Jacob Keller0da36b92017-04-19 09:25:55 -04006712 clear_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
Christopher N Bednarz1fca3262017-03-10 12:22:03 -08006713
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006714 /* re-enable Admin queue interrupt cause */
6715 val = rd32(hw, I40E_PFINT_ICR0_ENA);
6716 val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
6717 wr32(hw, I40E_PFINT_ICR0_ENA, val);
6718 i40e_flush(hw);
6719
6720 kfree(event.msg_buf);
6721}
6722
6723/**
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006724 * i40e_verify_eeprom - make sure eeprom is good to use
6725 * @pf: board private structure
6726 **/
6727static void i40e_verify_eeprom(struct i40e_pf *pf)
6728{
6729 int err;
6730
6731 err = i40e_diag_eeprom_test(&pf->hw);
6732 if (err) {
6733 /* retry in case of garbage read */
6734 err = i40e_diag_eeprom_test(&pf->hw);
6735 if (err) {
6736 dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
6737 err);
Jacob Keller0da36b92017-04-19 09:25:55 -04006738 set_bit(__I40E_BAD_EEPROM, pf->state);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006739 }
6740 }
6741
Jacob Keller0da36b92017-04-19 09:25:55 -04006742 if (!err && test_bit(__I40E_BAD_EEPROM, pf->state)) {
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006743 dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
Jacob Keller0da36b92017-04-19 09:25:55 -04006744 clear_bit(__I40E_BAD_EEPROM, pf->state);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006745 }
6746}
6747
6748/**
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006749 * i40e_enable_pf_switch_lb
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006750 * @pf: pointer to the PF structure
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006751 *
6752 * enable switch loop back or die - no point in a return value
6753 **/
6754static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
6755{
6756 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6757 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006758 int ret;
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006759
6760 ctxt.seid = pf->main_vsi_seid;
6761 ctxt.pf_num = pf->hw.pf_id;
6762 ctxt.vf_num = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006763 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6764 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006765 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006766 "couldn't get PF vsi config, err %s aq_err %s\n",
6767 i40e_stat_str(&pf->hw, ret),
6768 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006769 return;
6770 }
6771 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6772 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6773 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6774
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006775 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6776 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006777 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006778 "update vsi switch failed, err %s aq_err %s\n",
6779 i40e_stat_str(&pf->hw, ret),
6780 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006781 }
6782}
6783
6784/**
6785 * i40e_disable_pf_switch_lb
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006786 * @pf: pointer to the PF structure
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006787 *
6788 * disable switch loop back or die - no point in a return value
6789 **/
6790static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
6791{
6792 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6793 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006794 int ret;
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006795
6796 ctxt.seid = pf->main_vsi_seid;
6797 ctxt.pf_num = pf->hw.pf_id;
6798 ctxt.vf_num = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006799 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6800 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006801 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006802 "couldn't get PF vsi config, err %s aq_err %s\n",
6803 i40e_stat_str(&pf->hw, ret),
6804 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006805 return;
6806 }
6807 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6808 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6809 ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6810
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006811 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6812 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006813 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006814 "update vsi switch failed, err %s aq_err %s\n",
6815 i40e_stat_str(&pf->hw, ret),
6816 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006817 }
6818}
6819
6820/**
Neerav Parikh51616012015-02-06 08:52:14 +00006821 * i40e_config_bridge_mode - Configure the HW bridge mode
6822 * @veb: pointer to the bridge instance
6823 *
6824 * Configure the loop back mode for the LAN VSI that is downlink to the
6825 * specified HW bridge instance. It is expected this function is called
6826 * when a new HW bridge is instantiated.
6827 **/
6828static void i40e_config_bridge_mode(struct i40e_veb *veb)
6829{
6830 struct i40e_pf *pf = veb->pf;
6831
Shannon Nelson6dec1012015-09-28 14:12:30 -04006832 if (pf->hw.debug_mask & I40E_DEBUG_LAN)
6833 dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
6834 veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
Neerav Parikh51616012015-02-06 08:52:14 +00006835 if (veb->bridge_mode & BRIDGE_MODE_VEPA)
6836 i40e_disable_pf_switch_lb(pf);
6837 else
6838 i40e_enable_pf_switch_lb(pf);
6839}
6840
6841/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006842 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
6843 * @veb: pointer to the VEB instance
6844 *
6845 * This is a recursive function that first builds the attached VSIs then
6846 * recurses in to build the next layer of VEB. We track the connections
6847 * through our own index numbers because the seid's from the HW could
6848 * change across the reset.
6849 **/
6850static int i40e_reconstitute_veb(struct i40e_veb *veb)
6851{
6852 struct i40e_vsi *ctl_vsi = NULL;
6853 struct i40e_pf *pf = veb->pf;
6854 int v, veb_idx;
6855 int ret;
6856
6857 /* build VSI that owns this VEB, temporarily attached to base VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00006858 for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006859 if (pf->vsi[v] &&
6860 pf->vsi[v]->veb_idx == veb->idx &&
6861 pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
6862 ctl_vsi = pf->vsi[v];
6863 break;
6864 }
6865 }
6866 if (!ctl_vsi) {
6867 dev_info(&pf->pdev->dev,
6868 "missing owner VSI for veb_idx %d\n", veb->idx);
6869 ret = -ENOENT;
6870 goto end_reconstitute;
6871 }
6872 if (ctl_vsi != pf->vsi[pf->lan_vsi])
6873 ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
6874 ret = i40e_add_vsi(ctl_vsi);
6875 if (ret) {
6876 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006877 "rebuild of veb_idx %d owner VSI failed: %d\n",
6878 veb->idx, ret);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006879 goto end_reconstitute;
6880 }
6881 i40e_vsi_reset_stats(ctl_vsi);
6882
6883 /* create the VEB in the switch and move the VSI onto the VEB */
6884 ret = i40e_add_veb(veb, ctl_vsi);
6885 if (ret)
6886 goto end_reconstitute;
6887
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07006888 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
6889 veb->bridge_mode = BRIDGE_MODE_VEB;
6890 else
6891 veb->bridge_mode = BRIDGE_MODE_VEPA;
Neerav Parikh51616012015-02-06 08:52:14 +00006892 i40e_config_bridge_mode(veb);
Anjali Singhai Jainb64ba082014-11-13 03:06:15 +00006893
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006894 /* create the remaining VSIs attached to this VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00006895 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006896 if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
6897 continue;
6898
6899 if (pf->vsi[v]->veb_idx == veb->idx) {
6900 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04006901
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006902 vsi->uplink_seid = veb->seid;
6903 ret = i40e_add_vsi(vsi);
6904 if (ret) {
6905 dev_info(&pf->pdev->dev,
6906 "rebuild of vsi_idx %d failed: %d\n",
6907 v, ret);
6908 goto end_reconstitute;
6909 }
6910 i40e_vsi_reset_stats(vsi);
6911 }
6912 }
6913
6914 /* create any VEBs attached to this VEB - RECURSION */
6915 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
6916 if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
6917 pf->veb[veb_idx]->uplink_seid = veb->seid;
6918 ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
6919 if (ret)
6920 break;
6921 }
6922 }
6923
6924end_reconstitute:
6925 return ret;
6926}
6927
6928/**
6929 * i40e_get_capabilities - get info about the HW
6930 * @pf: the PF struct
6931 **/
6932static int i40e_get_capabilities(struct i40e_pf *pf)
6933{
6934 struct i40e_aqc_list_capabilities_element_resp *cap_buf;
6935 u16 data_size;
6936 int buf_len;
6937 int err;
6938
6939 buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
6940 do {
6941 cap_buf = kzalloc(buf_len, GFP_KERNEL);
6942 if (!cap_buf)
6943 return -ENOMEM;
6944
6945 /* this loads the data into the hw struct for us */
6946 err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
6947 &data_size,
6948 i40e_aqc_opc_list_func_capabilities,
6949 NULL);
6950 /* data loaded, buffer no longer needed */
6951 kfree(cap_buf);
6952
6953 if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
6954 /* retry with a larger buffer */
6955 buf_len = data_size;
6956 } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
6957 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006958 "capability discovery failed, err %s aq_err %s\n",
6959 i40e_stat_str(&pf->hw, err),
6960 i40e_aq_str(&pf->hw,
6961 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006962 return -ENODEV;
6963 }
6964 } while (err);
6965
6966 if (pf->hw.debug_mask & I40E_DEBUG_USER)
6967 dev_info(&pf->pdev->dev,
6968 "pf=%d, num_vfs=%d, msix_pf=%d, msix_vf=%d, fd_g=%d, fd_b=%d, pf_max_q=%d num_vsi=%d\n",
6969 pf->hw.pf_id, pf->hw.func_caps.num_vfs,
6970 pf->hw.func_caps.num_msix_vectors,
6971 pf->hw.func_caps.num_msix_vectors_vf,
6972 pf->hw.func_caps.fd_filters_guaranteed,
6973 pf->hw.func_caps.fd_filters_best_effort,
6974 pf->hw.func_caps.num_tx_qp,
6975 pf->hw.func_caps.num_vsis);
6976
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00006977#define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
6978 + pf->hw.func_caps.num_vfs)
6979 if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
6980 dev_info(&pf->pdev->dev,
6981 "got num_vsis %d, setting num_vsis to %d\n",
6982 pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
6983 pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
6984 }
6985
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006986 return 0;
6987}
6988
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006989static int i40e_vsi_clear(struct i40e_vsi *vsi);
6990
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006991/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006992 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006993 * @pf: board private structure
6994 **/
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006995static void i40e_fdir_sb_setup(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006996{
6997 struct i40e_vsi *vsi;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006998
Jesse Brandeburg407e0632014-06-03 23:50:12 +00006999 /* quick workaround for an NVM issue that leaves a critical register
7000 * uninitialized
7001 */
7002 if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
7003 static const u32 hkey[] = {
7004 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
7005 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
7006 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
7007 0x95b3a76d};
Alexander Duyck4b816442016-10-11 15:26:53 -07007008 int i;
Jesse Brandeburg407e0632014-06-03 23:50:12 +00007009
7010 for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
7011 wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
7012 }
7013
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08007014 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007015 return;
7016
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08007017 /* find existing VSI and see if it needs configuring */
Alexander Duyck4b816442016-10-11 15:26:53 -07007018 vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08007019
7020 /* create a new VSI if none exists */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007021 if (!vsi) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08007022 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
7023 pf->vsi[pf->lan_vsi]->seid, 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007024 if (!vsi) {
7025 dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00007026 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
7027 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007028 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007029 }
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00007030
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08007031 i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007032}
7033
7034/**
7035 * i40e_fdir_teardown - release the Flow Director resources
7036 * @pf: board private structure
7037 **/
7038static void i40e_fdir_teardown(struct i40e_pf *pf)
7039{
Alexander Duyck4b816442016-10-11 15:26:53 -07007040 struct i40e_vsi *vsi;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007041
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00007042 i40e_fdir_filter_exit(pf);
Alexander Duyck4b816442016-10-11 15:26:53 -07007043 vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
7044 if (vsi)
7045 i40e_vsi_release(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007046}
7047
7048/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007049 * i40e_prep_for_reset - prep for the core to reset
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007050 * @pf: board private structure
Maciej Sosin373149f2017-04-05 07:50:55 -04007051 * @lock_acquired: indicates whether or not the lock has been acquired
7052 * before this function was called.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007053 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00007054 * Close up the VFs and other things in prep for PF Reset.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007055 **/
Maciej Sosin373149f2017-04-05 07:50:55 -04007056static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007057{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007058 struct i40e_hw *hw = &pf->hw;
Shannon Nelson60442de2014-04-23 04:50:13 +00007059 i40e_status ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007060 u32 v;
7061
Jacob Keller0da36b92017-04-19 09:25:55 -04007062 clear_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
7063 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
Shannon Nelson23cfbe02014-06-04 01:23:14 +00007064 return;
Mitch Williamsd3ce57342016-03-10 14:59:46 -08007065 if (i40e_check_asq_alive(&pf->hw))
7066 i40e_vc_notify_reset(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007067
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00007068 dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007069
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007070 /* quiesce the VSIs and their queues that are not already DOWN */
Maciej Sosin373149f2017-04-05 07:50:55 -04007071 /* pf_quiesce_all_vsi modifies netdev structures -rtnl_lock needed */
7072 if (!lock_acquired)
7073 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007074 i40e_pf_quiesce_all_vsi(pf);
Maciej Sosin373149f2017-04-05 07:50:55 -04007075 if (!lock_acquired)
7076 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007077
Mitch Williams505682c2014-05-20 08:01:37 +00007078 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007079 if (pf->vsi[v])
7080 pf->vsi[v]->seid = 0;
7081 }
7082
7083 i40e_shutdown_adminq(&pf->hw);
7084
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007085 /* call shutdown HMC */
Shannon Nelson60442de2014-04-23 04:50:13 +00007086 if (hw->hmc.hmc_obj) {
7087 ret = i40e_shutdown_lan_hmc(hw);
Shannon Nelson23cfbe02014-06-04 01:23:14 +00007088 if (ret)
Shannon Nelson60442de2014-04-23 04:50:13 +00007089 dev_warn(&pf->pdev->dev,
7090 "shutdown_lan_hmc failed: %d\n", ret);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007091 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007092}
7093
7094/**
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00007095 * i40e_send_version - update firmware with driver version
7096 * @pf: PF struct
7097 */
7098static void i40e_send_version(struct i40e_pf *pf)
7099{
7100 struct i40e_driver_version dv;
7101
7102 dv.major_version = DRV_VERSION_MAJOR;
7103 dv.minor_version = DRV_VERSION_MINOR;
7104 dv.build_version = DRV_VERSION_BUILD;
7105 dv.subbuild_version = 0;
Rickard Strandqvist35a7d802014-07-29 09:26:25 +00007106 strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00007107 i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
7108}
7109
7110/**
Filip Sadowski5bbb2e22017-06-07 05:43:09 -04007111 * i40e_get_oem_version - get OEM specific version information
7112 * @hw: pointer to the hardware structure
7113 **/
7114static void i40e_get_oem_version(struct i40e_hw *hw)
7115{
7116 u16 block_offset = 0xffff;
7117 u16 block_length = 0;
7118 u16 capabilities = 0;
7119 u16 gen_snap = 0;
7120 u16 release = 0;
7121
7122#define I40E_SR_NVM_OEM_VERSION_PTR 0x1B
7123#define I40E_NVM_OEM_LENGTH_OFFSET 0x00
7124#define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01
7125#define I40E_NVM_OEM_GEN_OFFSET 0x02
7126#define I40E_NVM_OEM_RELEASE_OFFSET 0x03
7127#define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F
7128#define I40E_NVM_OEM_LENGTH 3
7129
7130 /* Check if pointer to OEM version block is valid. */
7131 i40e_read_nvm_word(hw, I40E_SR_NVM_OEM_VERSION_PTR, &block_offset);
7132 if (block_offset == 0xffff)
7133 return;
7134
7135 /* Check if OEM version block has correct length. */
7136 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_LENGTH_OFFSET,
7137 &block_length);
7138 if (block_length < I40E_NVM_OEM_LENGTH)
7139 return;
7140
7141 /* Check if OEM version format is as expected. */
7142 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_CAPABILITIES_OFFSET,
7143 &capabilities);
7144 if ((capabilities & I40E_NVM_OEM_CAPABILITIES_MASK) != 0)
7145 return;
7146
7147 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_GEN_OFFSET,
7148 &gen_snap);
7149 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_RELEASE_OFFSET,
7150 &release);
7151 hw->nvm.oem_ver = (gen_snap << I40E_OEM_SNAP_SHIFT) | release;
7152 hw->nvm.eetrack = I40E_OEM_EETRACK_ID;
7153}
7154
7155/**
Maciej Sosin373149f2017-04-05 07:50:55 -04007156 * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen
7157 * @pf: board private structure
7158 **/
7159static int i40e_reset(struct i40e_pf *pf)
7160{
7161 struct i40e_hw *hw = &pf->hw;
7162 i40e_status ret;
7163
7164 ret = i40e_pf_reset(hw);
7165 if (ret) {
7166 dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
Jacob Keller0da36b92017-04-19 09:25:55 -04007167 set_bit(__I40E_RESET_FAILED, pf->state);
7168 clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04007169 } else {
7170 pf->pfr_count++;
7171 }
7172 return ret;
7173}
7174
7175/**
7176 * i40e_rebuild - rebuild using a saved config
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007177 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007178 * @reinit: if the Main VSI needs to re-initialized.
Maciej Sosin373149f2017-04-05 07:50:55 -04007179 * @lock_acquired: indicates whether or not the lock has been acquired
7180 * before this function was called.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007181 **/
Maciej Sosin373149f2017-04-05 07:50:55 -04007182static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007183{
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007184 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00007185 u8 set_fc_aq_fail = 0;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007186 i40e_status ret;
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -04007187 u32 val;
Maciej Sosin373149f2017-04-05 07:50:55 -04007188 int v;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007189
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -03007190 if (test_bit(__I40E_DOWN, pf->state))
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00007191 goto clear_recovery;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00007192 dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007193
7194 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
7195 ret = i40e_init_adminq(&pf->hw);
7196 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007197 dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
7198 i40e_stat_str(&pf->hw, ret),
7199 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00007200 goto clear_recovery;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007201 }
Filip Sadowski5bbb2e22017-06-07 05:43:09 -04007202 i40e_get_oem_version(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007203
Shannon Nelson4eb3f762014-03-06 08:59:58 +00007204 /* re-verify the eeprom if we just had an EMP reset */
Jacob Keller0da36b92017-04-19 09:25:55 -04007205 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson4eb3f762014-03-06 08:59:58 +00007206 i40e_verify_eeprom(pf);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00007207
Shannon Nelsone78ac4bf2014-05-10 04:49:09 +00007208 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007209 ret = i40e_get_capabilities(pf);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007210 if (ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007211 goto end_core_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007212
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007213 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
Alexander Duyckc76cb6e2017-02-21 15:55:48 -08007214 hw->func_caps.num_rx_qp, 0, 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007215 if (ret) {
7216 dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
7217 goto end_core_reset;
7218 }
7219 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
7220 if (ret) {
7221 dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
7222 goto end_core_reset;
7223 }
7224
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08007225#ifdef CONFIG_I40E_DCB
7226 ret = i40e_init_pf_dcb(pf);
7227 if (ret) {
Shannon Nelsonaebfc812014-12-11 07:06:38 +00007228 dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
7229 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
7230 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08007231 }
7232#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007233 /* do basic switch setup */
Maciej Sosin373149f2017-04-05 07:50:55 -04007234 if (!lock_acquired)
7235 rtnl_lock();
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007236 ret = i40e_setup_pf_switch(pf, reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007237 if (ret)
Maciej Sosin373149f2017-04-05 07:50:55 -04007238 goto end_unlock;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007239
Shannon Nelson2f0aff42016-01-04 10:33:08 -08007240 /* The driver only wants link up/down and module qualification
7241 * reports from firmware. Note the negative logic.
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00007242 */
7243 ret = i40e_aq_set_phy_int_mask(&pf->hw,
Shannon Nelson2f0aff42016-01-04 10:33:08 -08007244 ~(I40E_AQ_EVENT_LINK_UPDOWN |
Shannon Nelson867a79e2016-03-18 12:18:15 -07007245 I40E_AQ_EVENT_MEDIA_NA |
Shannon Nelson2f0aff42016-01-04 10:33:08 -08007246 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00007247 if (ret)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007248 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
7249 i40e_stat_str(&pf->hw, ret),
7250 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00007251
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00007252 /* make sure our flow control settings are restored */
7253 ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
7254 if (ret)
Neerav Parikh8279e492015-09-03 17:18:50 -04007255 dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
7256 i40e_stat_str(&pf->hw, ret),
7257 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00007258
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007259 /* Rebuild the VSIs and VEBs that existed before reset.
7260 * They are still in our local switch element arrays, so only
7261 * need to rebuild the switch model in the HW.
7262 *
7263 * If there were VEBs but the reconstitution failed, we'll try
7264 * try to recover minimal use by getting the basic PF VSI working.
7265 */
7266 if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00007267 dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007268 /* find the one VEB connected to the MAC, and find orphans */
7269 for (v = 0; v < I40E_MAX_VEB; v++) {
7270 if (!pf->veb[v])
7271 continue;
7272
7273 if (pf->veb[v]->uplink_seid == pf->mac_seid ||
7274 pf->veb[v]->uplink_seid == 0) {
7275 ret = i40e_reconstitute_veb(pf->veb[v]);
7276
7277 if (!ret)
7278 continue;
7279
7280 /* If Main VEB failed, we're in deep doodoo,
7281 * so give up rebuilding the switch and set up
7282 * for minimal rebuild of PF VSI.
7283 * If orphan failed, we'll report the error
7284 * but try to keep going.
7285 */
7286 if (pf->veb[v]->uplink_seid == pf->mac_seid) {
7287 dev_info(&pf->pdev->dev,
7288 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
7289 ret);
7290 pf->vsi[pf->lan_vsi]->uplink_seid
7291 = pf->mac_seid;
7292 break;
7293 } else if (pf->veb[v]->uplink_seid == 0) {
7294 dev_info(&pf->pdev->dev,
7295 "rebuild of orphan VEB failed: %d\n",
7296 ret);
7297 }
7298 }
7299 }
7300 }
7301
7302 if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
Shannon Nelsoncde4cbc2014-06-04 01:23:17 +00007303 dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007304 /* no VEB, so rebuild only the Main VSI */
7305 ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
7306 if (ret) {
7307 dev_info(&pf->pdev->dev,
7308 "rebuild of Main VSI failed: %d\n", ret);
Maciej Sosin373149f2017-04-05 07:50:55 -04007309 goto end_unlock;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007310 }
7311 }
7312
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -04007313 /* Reconfigure hardware for allowing smaller MSS in the case
7314 * of TSO, so that we avoid the MDD being fired and causing
7315 * a reset in the case of small MSS+TSO.
7316 */
7317#define I40E_REG_MSS 0x000E64DC
7318#define I40E_REG_MSS_MIN_MASK 0x3FF0000
7319#define I40E_64BYTE_MSS 0x400000
7320 val = rd32(hw, I40E_REG_MSS);
7321 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
7322 val &= ~I40E_REG_MSS_MIN_MASK;
7323 val |= I40E_64BYTE_MSS;
7324 wr32(hw, I40E_REG_MSS, val);
7325 }
7326
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08007327 if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00007328 msleep(75);
7329 ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
7330 if (ret)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007331 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
7332 i40e_stat_str(&pf->hw, ret),
7333 i40e_aq_str(&pf->hw,
7334 pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00007335 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007336 /* reinit the misc interrupt */
7337 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7338 ret = i40e_setup_misc_vector(pf);
7339
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04007340 /* Add a filter to drop all Flow control frames from any VSI from being
7341 * transmitted. By doing so we stop a malicious VF from sending out
7342 * PAUSE or PFC frames and potentially controlling traffic for other
7343 * PF/VF VSIs.
7344 * The FW can still send Flow control frames if enabled.
7345 */
7346 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
7347 pf->main_vsi_seid);
7348
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007349 /* restart the VSIs that were rebuilt and running before the reset */
7350 i40e_pf_unquiesce_all_vsi(pf);
7351
Jacob Keller024b05f2017-04-13 04:45:46 -04007352 /* Release the RTNL lock before we start resetting VFs */
7353 if (!lock_acquired)
7354 rtnl_unlock();
7355
Jacob Kellere4b433f2017-04-13 04:45:52 -04007356 i40e_reset_all_vfs(pf, true);
Mitch Williams69f64b22014-02-13 03:48:46 -08007357
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007358 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00007359 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007360
Jacob Keller024b05f2017-04-13 04:45:46 -04007361 /* We've already released the lock, so don't do it again */
7362 goto end_core_reset;
7363
Maciej Sosin373149f2017-04-05 07:50:55 -04007364end_unlock:
Jacob Keller024b05f2017-04-13 04:45:46 -04007365 if (!lock_acquired)
7366 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007367end_core_reset:
Jacob Keller0da36b92017-04-19 09:25:55 -04007368 clear_bit(__I40E_RESET_FAILED, pf->state);
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00007369clear_recovery:
Jacob Keller0da36b92017-04-19 09:25:55 -04007370 clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007371}
7372
7373/**
Maciej Sosin373149f2017-04-05 07:50:55 -04007374 * i40e_reset_and_rebuild - reset and rebuild using a saved config
7375 * @pf: board private structure
7376 * @reinit: if the Main VSI needs to re-initialized.
7377 * @lock_acquired: indicates whether or not the lock has been acquired
7378 * before this function was called.
7379 **/
7380static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit,
7381 bool lock_acquired)
7382{
7383 int ret;
7384 /* Now we wait for GRST to settle out.
7385 * We don't have to delete the VEBs or VSIs from the hw switch
7386 * because the reset will make them disappear.
7387 */
7388 ret = i40e_reset(pf);
7389 if (!ret)
7390 i40e_rebuild(pf, reinit, lock_acquired);
7391}
7392
7393/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00007394 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007395 * @pf: board private structure
7396 *
7397 * Close up the VFs and other things in prep for a Core Reset,
7398 * then get ready to rebuild the world.
Maciej Sosin373149f2017-04-05 07:50:55 -04007399 * @lock_acquired: indicates whether or not the lock has been acquired
7400 * before this function was called.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007401 **/
Maciej Sosin373149f2017-04-05 07:50:55 -04007402static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007403{
Maciej Sosin373149f2017-04-05 07:50:55 -04007404 i40e_prep_for_reset(pf, lock_acquired);
7405 i40e_reset_and_rebuild(pf, false, lock_acquired);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007406}
7407
7408/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007409 * i40e_handle_mdd_event
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00007410 * @pf: pointer to the PF structure
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007411 *
7412 * Called from the MDD irq handler to identify possibly malicious vfs
7413 **/
7414static void i40e_handle_mdd_event(struct i40e_pf *pf)
7415{
7416 struct i40e_hw *hw = &pf->hw;
7417 bool mdd_detected = false;
Neerav Parikhdf430b12014-06-04 01:23:15 +00007418 bool pf_mdd_detected = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007419 struct i40e_vf *vf;
7420 u32 reg;
7421 int i;
7422
Jacob Keller0da36b92017-04-19 09:25:55 -04007423 if (!test_bit(__I40E_MDD_EVENT_PENDING, pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007424 return;
7425
7426 /* find what triggered the MDD event */
7427 reg = rd32(hw, I40E_GL_MDET_TX);
7428 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007429 u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
7430 I40E_GL_MDET_TX_PF_NUM_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00007431 u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007432 I40E_GL_MDET_TX_VF_NUM_SHIFT;
Dan Carpenter013f6572014-10-22 20:06:29 -07007433 u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007434 I40E_GL_MDET_TX_EVENT_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00007435 u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
7436 I40E_GL_MDET_TX_QUEUE_SHIFT) -
7437 pf->hw.func_caps.base_queue;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007438 if (netif_msg_tx_err(pf))
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00007439 dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007440 event, queue, pf_num, vf_num);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007441 wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
7442 mdd_detected = true;
7443 }
7444 reg = rd32(hw, I40E_GL_MDET_RX);
7445 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007446 u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
7447 I40E_GL_MDET_RX_FUNCTION_SHIFT;
Dan Carpenter013f6572014-10-22 20:06:29 -07007448 u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007449 I40E_GL_MDET_RX_EVENT_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00007450 u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
7451 I40E_GL_MDET_RX_QUEUE_SHIFT) -
7452 pf->hw.func_caps.base_queue;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007453 if (netif_msg_rx_err(pf))
7454 dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
7455 event, queue, func);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007456 wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
7457 mdd_detected = true;
7458 }
7459
Neerav Parikhdf430b12014-06-04 01:23:15 +00007460 if (mdd_detected) {
7461 reg = rd32(hw, I40E_PF_MDET_TX);
7462 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
7463 wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007464 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
Neerav Parikhdf430b12014-06-04 01:23:15 +00007465 pf_mdd_detected = true;
7466 }
7467 reg = rd32(hw, I40E_PF_MDET_RX);
7468 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
7469 wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007470 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
Neerav Parikhdf430b12014-06-04 01:23:15 +00007471 pf_mdd_detected = true;
7472 }
7473 /* Queue belongs to the PF, initiate a reset */
7474 if (pf_mdd_detected) {
Jacob Keller0da36b92017-04-19 09:25:55 -04007475 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
Neerav Parikhdf430b12014-06-04 01:23:15 +00007476 i40e_service_event_schedule(pf);
7477 }
7478 }
7479
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007480 /* see if one of the VFs needs its hand slapped */
7481 for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
7482 vf = &(pf->vf[i]);
7483 reg = rd32(hw, I40E_VP_MDET_TX(i));
7484 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
7485 wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
7486 vf->num_mdd_events++;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007487 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
7488 i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007489 }
7490
7491 reg = rd32(hw, I40E_VP_MDET_RX(i));
7492 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
7493 wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
7494 vf->num_mdd_events++;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007495 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
7496 i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007497 }
7498
7499 if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
7500 dev_info(&pf->pdev->dev,
7501 "Too many MDD events on VF %d, disabled\n", i);
7502 dev_info(&pf->pdev->dev,
7503 "Use PF Control I/F to re-enable the VF\n");
Jacob Keller6322e632017-04-13 04:45:54 -04007504 set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007505 }
7506 }
7507
7508 /* re-enable mdd interrupt cause */
Jacob Keller0da36b92017-04-19 09:25:55 -04007509 clear_bit(__I40E_MDD_EVENT_PENDING, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007510 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
7511 reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
7512 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
7513 i40e_flush(hw);
7514}
7515
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007516/**
Alexander Duyck1f190d92017-04-19 09:25:51 -04007517 * i40e_sync_udp_filters - Trigger a sync event for existing UDP filters
7518 * @pf: board private structure
7519 **/
7520static void i40e_sync_udp_filters(struct i40e_pf *pf)
7521{
7522 int i;
7523
7524 /* loop through and set pending bit for all active UDP filters */
7525 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
7526 if (pf->udp_ports[i].port)
7527 pf->pending_udp_bitmap |= BIT_ULL(i);
7528 }
7529
7530 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
7531}
7532
7533/**
Singhai, Anjali6a899022015-12-14 12:21:18 -08007534 * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007535 * @pf: board private structure
7536 **/
Singhai, Anjali6a899022015-12-14 12:21:18 -08007537static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007538{
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007539 struct i40e_hw *hw = &pf->hw;
7540 i40e_status ret;
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08007541 u16 port;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007542 int i;
7543
Singhai, Anjali6a899022015-12-14 12:21:18 -08007544 if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC))
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007545 return;
7546
Singhai, Anjali6a899022015-12-14 12:21:18 -08007547 pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007548
7549 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
Singhai, Anjali6a899022015-12-14 12:21:18 -08007550 if (pf->pending_udp_bitmap & BIT_ULL(i)) {
7551 pf->pending_udp_bitmap &= ~BIT_ULL(i);
Jacob Keller27826fd2017-04-19 09:25:50 -04007552 port = pf->udp_ports[i].port;
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007553 if (port)
Carolyn Wybornyb3f5c7b2016-08-24 11:33:51 -07007554 ret = i40e_aq_add_udp_tunnel(hw, port,
7555 pf->udp_ports[i].type,
7556 NULL, NULL);
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007557 else
7558 ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007559
7560 if (ret) {
Carolyn Wyborny730a8f82016-02-17 16:12:16 -08007561 dev_dbg(&pf->pdev->dev,
7562 "%s %s port %d, index %d failed, err %s aq_err %s\n",
7563 pf->udp_ports[i].type ? "vxlan" : "geneve",
7564 port ? "add" : "delete",
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08007565 port, i,
Carolyn Wyborny730a8f82016-02-17 16:12:16 -08007566 i40e_stat_str(&pf->hw, ret),
7567 i40e_aq_str(&pf->hw,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007568 pf->hw.aq.asq_last_status));
Jacob Keller27826fd2017-04-19 09:25:50 -04007569 pf->udp_ports[i].port = 0;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007570 }
7571 }
7572 }
7573}
7574
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007575/**
7576 * i40e_service_task - Run the driver's async subtasks
7577 * @work: pointer to work_struct containing our data
7578 **/
7579static void i40e_service_task(struct work_struct *work)
7580{
7581 struct i40e_pf *pf = container_of(work,
7582 struct i40e_pf,
7583 service_task);
7584 unsigned long start_time = jiffies;
7585
Shannon Nelsone57a2fe2014-06-03 23:50:19 +00007586 /* don't bother with service tasks if a reset is in progress */
Jacob Keller0da36b92017-04-19 09:25:55 -04007587 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
Shannon Nelsone57a2fe2014-06-03 23:50:19 +00007588 return;
Shannon Nelsone57a2fe2014-06-03 23:50:19 +00007589
Jacob Keller0da36b92017-04-19 09:25:55 -04007590 if (test_and_set_bit(__I40E_SERVICE_SCHED, pf->state))
Mitch Williams91089032016-11-21 13:03:51 -08007591 return;
7592
Kiran Patilb03a8c12015-09-24 18:13:15 -04007593 i40e_detect_recover_hung(pf);
Jesse Brandeburg2818ccd2016-01-13 16:51:38 -08007594 i40e_sync_filters_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007595 i40e_reset_subtask(pf);
7596 i40e_handle_mdd_event(pf);
7597 i40e_vc_process_vflr_event(pf);
7598 i40e_watchdog_subtask(pf);
7599 i40e_fdir_reinit_subtask(pf);
Mitch Williams0ef2d5a2017-01-24 10:24:00 -08007600 if (pf->flags & I40E_FLAG_CLIENT_RESET) {
7601 /* Client subtask will reopen next time through. */
7602 i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], true);
7603 pf->flags &= ~I40E_FLAG_CLIENT_RESET;
7604 } else {
7605 i40e_client_subtask(pf);
7606 if (pf->flags & I40E_FLAG_CLIENT_L2_CHANGE) {
7607 i40e_notify_client_of_l2_param_changes(
7608 pf->vsi[pf->lan_vsi]);
7609 pf->flags &= ~I40E_FLAG_CLIENT_L2_CHANGE;
7610 }
7611 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007612 i40e_sync_filters_subtask(pf);
Singhai, Anjali6a899022015-12-14 12:21:18 -08007613 i40e_sync_udp_filters_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007614 i40e_clean_adminq_subtask(pf);
7615
Mitch Williams91089032016-11-21 13:03:51 -08007616 /* flush memory to make sure state is correct before next watchdog */
7617 smp_mb__before_atomic();
Jacob Keller0da36b92017-04-19 09:25:55 -04007618 clear_bit(__I40E_SERVICE_SCHED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007619
7620 /* If the tasks have taken longer than one timer cycle or there
7621 * is more work to be done, reschedule the service task now
7622 * rather than wait for the timer to tick again.
7623 */
7624 if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
Jacob Keller0da36b92017-04-19 09:25:55 -04007625 test_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state) ||
7626 test_bit(__I40E_MDD_EVENT_PENDING, pf->state) ||
7627 test_bit(__I40E_VFLR_EVENT_PENDING, pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007628 i40e_service_event_schedule(pf);
7629}
7630
7631/**
7632 * i40e_service_timer - timer callback
7633 * @data: pointer to PF struct
7634 **/
7635static void i40e_service_timer(unsigned long data)
7636{
7637 struct i40e_pf *pf = (struct i40e_pf *)data;
7638
7639 mod_timer(&pf->service_timer,
7640 round_jiffies(jiffies + pf->service_timer_period));
7641 i40e_service_event_schedule(pf);
7642}
7643
7644/**
7645 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
7646 * @vsi: the VSI being configured
7647 **/
7648static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
7649{
7650 struct i40e_pf *pf = vsi->back;
7651
7652 switch (vsi->type) {
7653 case I40E_VSI_MAIN:
7654 vsi->alloc_queue_pairs = pf->num_lan_qps;
7655 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7656 I40E_REQ_DESCRIPTOR_MULTIPLE);
7657 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7658 vsi->num_q_vectors = pf->num_lan_msix;
7659 else
7660 vsi->num_q_vectors = 1;
7661
7662 break;
7663
7664 case I40E_VSI_FDIR:
7665 vsi->alloc_queue_pairs = 1;
7666 vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
7667 I40E_REQ_DESCRIPTOR_MULTIPLE);
Tushar Davea70e4072016-05-16 12:40:53 -07007668 vsi->num_q_vectors = pf->num_fdsb_msix;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007669 break;
7670
7671 case I40E_VSI_VMDQ2:
7672 vsi->alloc_queue_pairs = pf->num_vmdq_qps;
7673 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7674 I40E_REQ_DESCRIPTOR_MULTIPLE);
7675 vsi->num_q_vectors = pf->num_vmdq_msix;
7676 break;
7677
7678 case I40E_VSI_SRIOV:
7679 vsi->alloc_queue_pairs = pf->num_vf_qps;
7680 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7681 I40E_REQ_DESCRIPTOR_MULTIPLE);
7682 break;
7683
7684 default:
7685 WARN_ON(1);
7686 return -ENODATA;
7687 }
7688
7689 return 0;
7690}
7691
7692/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007693 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
7694 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007695 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007696 *
7697 * On error: returns error code (negative)
7698 * On success: returns 0
7699 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007700static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007701{
Björn Töpel74608d12017-05-24 07:55:35 +02007702 struct i40e_ring **next_rings;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007703 int size;
7704 int ret = 0;
7705
Björn Töpel74608d12017-05-24 07:55:35 +02007706 /* allocate memory for both Tx, XDP Tx and Rx ring pointers */
7707 size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs *
7708 (i40e_enabled_xdp_vsi(vsi) ? 3 : 2);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007709 vsi->tx_rings = kzalloc(size, GFP_KERNEL);
7710 if (!vsi->tx_rings)
7711 return -ENOMEM;
Björn Töpel74608d12017-05-24 07:55:35 +02007712 next_rings = vsi->tx_rings + vsi->alloc_queue_pairs;
7713 if (i40e_enabled_xdp_vsi(vsi)) {
7714 vsi->xdp_rings = next_rings;
7715 next_rings += vsi->alloc_queue_pairs;
7716 }
7717 vsi->rx_rings = next_rings;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007718
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007719 if (alloc_qvectors) {
7720 /* allocate memory for q_vector pointers */
Julia Lawallf57e4fb2014-07-30 03:11:09 +00007721 size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007722 vsi->q_vectors = kzalloc(size, GFP_KERNEL);
7723 if (!vsi->q_vectors) {
7724 ret = -ENOMEM;
7725 goto err_vectors;
7726 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007727 }
7728 return ret;
7729
7730err_vectors:
7731 kfree(vsi->tx_rings);
7732 return ret;
7733}
7734
7735/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007736 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
7737 * @pf: board private structure
7738 * @type: type of VSI
7739 *
7740 * On error: returns error code (negative)
7741 * On success: returns vsi index in PF (positive)
7742 **/
7743static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
7744{
7745 int ret = -ENODEV;
7746 struct i40e_vsi *vsi;
7747 int vsi_idx;
7748 int i;
7749
7750 /* Need to protect the allocation of the VSIs at the PF level */
7751 mutex_lock(&pf->switch_mutex);
7752
7753 /* VSI list may be fragmented if VSI creation/destruction has
7754 * been happening. We can afford to do a quick scan to look
7755 * for any free VSIs in the list.
7756 *
7757 * find next empty vsi slot, looping back around if necessary
7758 */
7759 i = pf->next_vsi;
Mitch Williams505682c2014-05-20 08:01:37 +00007760 while (i < pf->num_alloc_vsi && pf->vsi[i])
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007761 i++;
Mitch Williams505682c2014-05-20 08:01:37 +00007762 if (i >= pf->num_alloc_vsi) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007763 i = 0;
7764 while (i < pf->next_vsi && pf->vsi[i])
7765 i++;
7766 }
7767
Mitch Williams505682c2014-05-20 08:01:37 +00007768 if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007769 vsi_idx = i; /* Found one! */
7770 } else {
7771 ret = -ENODEV;
Alexander Duyck493fb302013-09-28 07:01:44 +00007772 goto unlock_pf; /* out of VSI slots! */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007773 }
7774 pf->next_vsi = ++i;
7775
7776 vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
7777 if (!vsi) {
7778 ret = -ENOMEM;
Alexander Duyck493fb302013-09-28 07:01:44 +00007779 goto unlock_pf;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007780 }
7781 vsi->type = type;
7782 vsi->back = pf;
Jacob Keller0da36b92017-04-19 09:25:55 -04007783 set_bit(__I40E_VSI_DOWN, vsi->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007784 vsi->flags = 0;
7785 vsi->idx = vsi_idx;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04007786 vsi->int_rate_limit = 0;
Anjali Singhai Jain5db4cb52015-02-24 06:58:49 +00007787 vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
7788 pf->rss_table_size : 64;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007789 vsi->netdev_registered = false;
7790 vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
Jacob Keller278e7d02016-10-05 09:30:37 -07007791 hash_init(vsi->mac_filter_hash);
Shannon Nelson63741842014-04-23 04:50:16 +00007792 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007793
Alexander Duyck9f65e152013-09-28 06:00:58 +00007794 ret = i40e_set_num_rings_in_vsi(vsi);
7795 if (ret)
7796 goto err_rings;
7797
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007798 ret = i40e_vsi_alloc_arrays(vsi, true);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007799 if (ret)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007800 goto err_rings;
Alexander Duyck493fb302013-09-28 07:01:44 +00007801
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007802 /* Setup default MSIX irq handler for VSI */
7803 i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
7804
Kiran Patil21659032015-09-30 14:09:03 -04007805 /* Initialize VSI lock */
Jacob Keller278e7d02016-10-05 09:30:37 -07007806 spin_lock_init(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007807 pf->vsi[vsi_idx] = vsi;
7808 ret = vsi_idx;
Alexander Duyck493fb302013-09-28 07:01:44 +00007809 goto unlock_pf;
7810
Alexander Duyck9f65e152013-09-28 06:00:58 +00007811err_rings:
Alexander Duyck493fb302013-09-28 07:01:44 +00007812 pf->next_vsi = i - 1;
7813 kfree(vsi);
7814unlock_pf:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007815 mutex_unlock(&pf->switch_mutex);
7816 return ret;
7817}
7818
7819/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007820 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
7821 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007822 * @free_qvectors: a bool to specify if q_vectors need to be freed.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007823 *
7824 * On error: returns error code (negative)
7825 * On success: returns 0
7826 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007827static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007828{
7829 /* free the ring and vector containers */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007830 if (free_qvectors) {
7831 kfree(vsi->q_vectors);
7832 vsi->q_vectors = NULL;
7833 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007834 kfree(vsi->tx_rings);
7835 vsi->tx_rings = NULL;
7836 vsi->rx_rings = NULL;
Björn Töpel74608d12017-05-24 07:55:35 +02007837 vsi->xdp_rings = NULL;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007838}
7839
7840/**
Helin Zhang28c58692015-10-26 19:44:27 -04007841 * i40e_clear_rss_config_user - clear the user configured RSS hash keys
7842 * and lookup table
7843 * @vsi: Pointer to VSI structure
7844 */
7845static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
7846{
7847 if (!vsi)
7848 return;
7849
7850 kfree(vsi->rss_hkey_user);
7851 vsi->rss_hkey_user = NULL;
7852
7853 kfree(vsi->rss_lut_user);
7854 vsi->rss_lut_user = NULL;
7855}
7856
7857/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007858 * i40e_vsi_clear - Deallocate the VSI provided
7859 * @vsi: the VSI being un-configured
7860 **/
7861static int i40e_vsi_clear(struct i40e_vsi *vsi)
7862{
7863 struct i40e_pf *pf;
7864
7865 if (!vsi)
7866 return 0;
7867
7868 if (!vsi->back)
7869 goto free_vsi;
7870 pf = vsi->back;
7871
7872 mutex_lock(&pf->switch_mutex);
7873 if (!pf->vsi[vsi->idx]) {
7874 dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
7875 vsi->idx, vsi->idx, vsi, vsi->type);
7876 goto unlock_vsi;
7877 }
7878
7879 if (pf->vsi[vsi->idx] != vsi) {
7880 dev_err(&pf->pdev->dev,
7881 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
7882 pf->vsi[vsi->idx]->idx,
7883 pf->vsi[vsi->idx],
7884 pf->vsi[vsi->idx]->type,
7885 vsi->idx, vsi, vsi->type);
7886 goto unlock_vsi;
7887 }
7888
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00007889 /* updates the PF for this cleared vsi */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007890 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
7891 i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
7892
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007893 i40e_vsi_free_arrays(vsi, true);
Helin Zhang28c58692015-10-26 19:44:27 -04007894 i40e_clear_rss_config_user(vsi);
Alexander Duyck493fb302013-09-28 07:01:44 +00007895
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007896 pf->vsi[vsi->idx] = NULL;
7897 if (vsi->idx < pf->next_vsi)
7898 pf->next_vsi = vsi->idx;
7899
7900unlock_vsi:
7901 mutex_unlock(&pf->switch_mutex);
7902free_vsi:
7903 kfree(vsi);
7904
7905 return 0;
7906}
7907
7908/**
Alexander Duyck9f65e152013-09-28 06:00:58 +00007909 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
7910 * @vsi: the VSI being cleaned
7911 **/
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00007912static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007913{
7914 int i;
7915
Greg Rose8e9dca52013-12-18 13:45:53 +00007916 if (vsi->tx_rings && vsi->tx_rings[0]) {
Neerav Parikhd7397642013-11-28 06:39:37 +00007917 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Mitch Williams00403f02013-09-28 07:13:13 +00007918 kfree_rcu(vsi->tx_rings[i], rcu);
7919 vsi->tx_rings[i] = NULL;
7920 vsi->rx_rings[i] = NULL;
Björn Töpel74608d12017-05-24 07:55:35 +02007921 if (vsi->xdp_rings)
7922 vsi->xdp_rings[i] = NULL;
Mitch Williams00403f02013-09-28 07:13:13 +00007923 }
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00007924 }
Alexander Duyck9f65e152013-09-28 06:00:58 +00007925}
7926
7927/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007928 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
7929 * @vsi: the VSI being configured
7930 **/
7931static int i40e_alloc_rings(struct i40e_vsi *vsi)
7932{
Björn Töpel74608d12017-05-24 07:55:35 +02007933 int i, qpv = i40e_enabled_xdp_vsi(vsi) ? 3 : 2;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007934 struct i40e_pf *pf = vsi->back;
Björn Töpel74608d12017-05-24 07:55:35 +02007935 struct i40e_ring *ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007936
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007937 /* Set basic values in the rings to be used later during open() */
Neerav Parikhd7397642013-11-28 06:39:37 +00007938 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00007939 /* allocate space for both Tx and Rx in one shot */
Björn Töpel74608d12017-05-24 07:55:35 +02007940 ring = kcalloc(qpv, sizeof(struct i40e_ring), GFP_KERNEL);
7941 if (!ring)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007942 goto err_out;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007943
Björn Töpel74608d12017-05-24 07:55:35 +02007944 ring->queue_index = i;
7945 ring->reg_idx = vsi->base_queue + i;
7946 ring->ring_active = false;
7947 ring->vsi = vsi;
7948 ring->netdev = vsi->netdev;
7949 ring->dev = &pf->pdev->dev;
7950 ring->count = vsi->num_desc;
7951 ring->size = 0;
7952 ring->dcb_tc = 0;
Anjali Singhai Jain8e0764b2015-06-05 12:20:30 -04007953 if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
Björn Töpel74608d12017-05-24 07:55:35 +02007954 ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
7955 ring->tx_itr_setting = pf->tx_itr_default;
7956 vsi->tx_rings[i] = ring++;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007957
Björn Töpel74608d12017-05-24 07:55:35 +02007958 if (!i40e_enabled_xdp_vsi(vsi))
7959 goto setup_rx;
7960
7961 ring->queue_index = vsi->alloc_queue_pairs + i;
7962 ring->reg_idx = vsi->base_queue + ring->queue_index;
7963 ring->ring_active = false;
7964 ring->vsi = vsi;
7965 ring->netdev = NULL;
7966 ring->dev = &pf->pdev->dev;
7967 ring->count = vsi->num_desc;
7968 ring->size = 0;
7969 ring->dcb_tc = 0;
7970 if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
7971 ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
7972 set_ring_xdp(ring);
7973 ring->tx_itr_setting = pf->tx_itr_default;
7974 vsi->xdp_rings[i] = ring++;
7975
7976setup_rx:
7977 ring->queue_index = i;
7978 ring->reg_idx = vsi->base_queue + i;
7979 ring->ring_active = false;
7980 ring->vsi = vsi;
7981 ring->netdev = vsi->netdev;
7982 ring->dev = &pf->pdev->dev;
7983 ring->count = vsi->num_desc;
7984 ring->size = 0;
7985 ring->dcb_tc = 0;
7986 ring->rx_itr_setting = pf->rx_itr_default;
7987 vsi->rx_rings[i] = ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007988 }
7989
7990 return 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00007991
7992err_out:
7993 i40e_vsi_clear_rings(vsi);
7994 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007995}
7996
7997/**
7998 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
7999 * @pf: board private structure
8000 * @vectors: the number of MSI-X vectors to request
8001 *
8002 * Returns the number of vectors reserved, or error
8003 **/
8004static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
8005{
Alexander Gordeev7b37f372014-02-18 11:11:42 +01008006 vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
8007 I40E_MIN_MSIX, vectors);
8008 if (vectors < 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008009 dev_info(&pf->pdev->dev,
Alexander Gordeev7b37f372014-02-18 11:11:42 +01008010 "MSI-X vector reservation failed: %d\n", vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008011 vectors = 0;
8012 }
8013
8014 return vectors;
8015}
8016
8017/**
8018 * i40e_init_msix - Setup the MSIX capability
8019 * @pf: board private structure
8020 *
8021 * Work with the OS to set up the MSIX vectors needed.
8022 *
Shannon Nelson3b444392015-02-26 16:15:57 +00008023 * Returns the number of vectors reserved or negative on failure
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008024 **/
8025static int i40e_init_msix(struct i40e_pf *pf)
8026{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008027 struct i40e_hw *hw = &pf->hw;
Jacob Kellerc0cf70a2017-01-24 10:24:01 -08008028 int cpus, extra_vectors;
Shannon Nelson1e200e42015-02-27 09:15:24 +00008029 int vectors_left;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008030 int v_budget, i;
Shannon Nelson3b444392015-02-26 16:15:57 +00008031 int v_actual;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008032 int iwarp_requested = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008033
8034 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
8035 return -ENODEV;
8036
8037 /* The number of vectors we'll request will be comprised of:
8038 * - Add 1 for "other" cause for Admin Queue events, etc.
8039 * - The number of LAN queue pairs
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008040 * - Queues being used for RSS.
8041 * We don't need as many as max_rss_size vectors.
8042 * use rss_size instead in the calculation since that
8043 * is governed by number of cpus in the system.
8044 * - assumes symmetric Tx/Rx pairing
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008045 * - The number of VMDq pairs
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008046 * - The CPU count within the NUMA node if iWARP is enabled
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008047 * Once we count this up, try the request.
8048 *
8049 * If we can't get what we want, we'll simplify to nearly nothing
8050 * and try again. If that still fails, we punt.
8051 */
Shannon Nelson1e200e42015-02-27 09:15:24 +00008052 vectors_left = hw->func_caps.num_msix_vectors;
8053 v_budget = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008054
Shannon Nelson1e200e42015-02-27 09:15:24 +00008055 /* reserve one vector for miscellaneous handler */
8056 if (vectors_left) {
8057 v_budget++;
8058 vectors_left--;
8059 }
8060
Jacob Kellerc0cf70a2017-01-24 10:24:01 -08008061 /* reserve some vectors for the main PF traffic queues. Initially we
8062 * only reserve at most 50% of the available vectors, in the case that
8063 * the number of online CPUs is large. This ensures that we can enable
8064 * extra features as well. Once we've enabled the other features, we
8065 * will use any remaining vectors to reach as close as we can to the
8066 * number of online CPUs.
8067 */
8068 cpus = num_online_cpus();
8069 pf->num_lan_msix = min_t(int, cpus, vectors_left / 2);
Shannon Nelson1e200e42015-02-27 09:15:24 +00008070 vectors_left -= pf->num_lan_msix;
Shannon Nelson1e200e42015-02-27 09:15:24 +00008071
8072 /* reserve one vector for sideband flow director */
8073 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
8074 if (vectors_left) {
Tushar Davea70e4072016-05-16 12:40:53 -07008075 pf->num_fdsb_msix = 1;
Shannon Nelson1e200e42015-02-27 09:15:24 +00008076 v_budget++;
8077 vectors_left--;
8078 } else {
Tushar Davea70e4072016-05-16 12:40:53 -07008079 pf->num_fdsb_msix = 0;
Shannon Nelson1e200e42015-02-27 09:15:24 +00008080 }
8081 }
John W Linville83840e42015-01-14 03:06:28 +00008082
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008083 /* can we reserve enough for iWARP? */
8084 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02008085 iwarp_requested = pf->num_iwarp_msix;
8086
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008087 if (!vectors_left)
8088 pf->num_iwarp_msix = 0;
8089 else if (vectors_left < pf->num_iwarp_msix)
8090 pf->num_iwarp_msix = 1;
8091 v_budget += pf->num_iwarp_msix;
8092 vectors_left -= pf->num_iwarp_msix;
8093 }
8094
Shannon Nelson1e200e42015-02-27 09:15:24 +00008095 /* any vectors left over go for VMDq support */
8096 if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
8097 int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
8098 int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
8099
Stefan Assmann9ca57e92016-09-19 13:37:49 +02008100 if (!vectors_left) {
8101 pf->num_vmdq_msix = 0;
8102 pf->num_vmdq_qps = 0;
8103 } else {
8104 /* if we're short on vectors for what's desired, we limit
8105 * the queues per vmdq. If this is still more than are
8106 * available, the user will need to change the number of
8107 * queues/vectors used by the PF later with the ethtool
8108 * channels command
8109 */
8110 if (vmdq_vecs < vmdq_vecs_wanted)
8111 pf->num_vmdq_qps = 1;
8112 pf->num_vmdq_msix = pf->num_vmdq_qps;
Shannon Nelson1e200e42015-02-27 09:15:24 +00008113
Stefan Assmann9ca57e92016-09-19 13:37:49 +02008114 v_budget += vmdq_vecs;
8115 vectors_left -= vmdq_vecs;
8116 }
Shannon Nelson1e200e42015-02-27 09:15:24 +00008117 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008118
Jacob Kellerc0cf70a2017-01-24 10:24:01 -08008119 /* On systems with a large number of SMP cores, we previously limited
8120 * the number of vectors for num_lan_msix to be at most 50% of the
8121 * available vectors, to allow for other features. Now, we add back
8122 * the remaining vectors. However, we ensure that the total
8123 * num_lan_msix will not exceed num_online_cpus(). To do this, we
8124 * calculate the number of vectors we can add without going over the
8125 * cap of CPUs. For systems with a small number of CPUs this will be
8126 * zero.
8127 */
8128 extra_vectors = min_t(int, cpus - pf->num_lan_msix, vectors_left);
8129 pf->num_lan_msix += extra_vectors;
8130 vectors_left -= extra_vectors;
8131
8132 WARN(vectors_left < 0,
8133 "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n");
8134
8135 v_budget += pf->num_lan_msix;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008136 pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
8137 GFP_KERNEL);
8138 if (!pf->msix_entries)
8139 return -ENOMEM;
8140
8141 for (i = 0; i < v_budget; i++)
8142 pf->msix_entries[i].entry = i;
Shannon Nelson3b444392015-02-26 16:15:57 +00008143 v_actual = i40e_reserve_msix_vectors(pf, v_budget);
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00008144
Shannon Nelson3b444392015-02-26 16:15:57 +00008145 if (v_actual < I40E_MIN_MSIX) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008146 pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
8147 kfree(pf->msix_entries);
8148 pf->msix_entries = NULL;
Guilherme G Piccoli4c95aa52016-09-22 10:03:58 -03008149 pci_disable_msix(pf->pdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008150 return -ENODEV;
8151
Shannon Nelson3b444392015-02-26 16:15:57 +00008152 } else if (v_actual == I40E_MIN_MSIX) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008153 /* Adjust for minimal MSIX use */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008154 pf->num_vmdq_vsis = 0;
8155 pf->num_vmdq_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008156 pf->num_lan_qps = 1;
8157 pf->num_lan_msix = 1;
8158
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02008159 } else if (!vectors_left) {
8160 /* If we have limited resources, we will start with no vectors
8161 * for the special features and then allocate vectors to some
8162 * of these features based on the policy and at the end disable
8163 * the features that did not get any vectors.
8164 */
Shannon Nelson3b444392015-02-26 16:15:57 +00008165 int vec;
8166
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02008167 dev_info(&pf->pdev->dev,
8168 "MSI-X vector limit reached, attempting to redistribute vectors\n");
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00008169 /* reserve the misc vector */
Shannon Nelson3b444392015-02-26 16:15:57 +00008170 vec = v_actual - 1;
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00008171
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008172 /* Scale vector usage down */
8173 pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00008174 pf->num_vmdq_vsis = 1;
Shannon Nelson1e200e42015-02-27 09:15:24 +00008175 pf->num_vmdq_qps = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008176
8177 /* partition out the remaining vectors */
8178 switch (vec) {
8179 case 2:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008180 pf->num_lan_msix = 1;
8181 break;
8182 case 3:
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008183 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
8184 pf->num_lan_msix = 1;
8185 pf->num_iwarp_msix = 1;
8186 } else {
8187 pf->num_lan_msix = 2;
8188 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008189 break;
8190 default:
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008191 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
8192 pf->num_iwarp_msix = min_t(int, (vec / 3),
8193 iwarp_requested);
8194 pf->num_vmdq_vsis = min_t(int, (vec / 3),
8195 I40E_DEFAULT_NUM_VMDQ_VSI);
8196 } else {
8197 pf->num_vmdq_vsis = min_t(int, (vec / 2),
8198 I40E_DEFAULT_NUM_VMDQ_VSI);
8199 }
Stefan Assmannabd97a92016-09-19 13:37:51 +02008200 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
8201 pf->num_fdsb_msix = 1;
8202 vec--;
8203 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008204 pf->num_lan_msix = min_t(int,
8205 (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
8206 pf->num_lan_msix);
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02008207 pf->num_lan_qps = pf->num_lan_msix;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008208 break;
8209 }
8210 }
8211
Stefan Assmannabd97a92016-09-19 13:37:51 +02008212 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
8213 (pf->num_fdsb_msix == 0)) {
8214 dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
8215 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
8216 }
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00008217 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
8218 (pf->num_vmdq_msix == 0)) {
8219 dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
8220 pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
8221 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008222
8223 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
8224 (pf->num_iwarp_msix == 0)) {
8225 dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
8226 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
8227 }
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02008228 i40e_debug(&pf->hw, I40E_DEBUG_INIT,
8229 "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
8230 pf->num_lan_msix,
8231 pf->num_vmdq_msix * pf->num_vmdq_vsis,
8232 pf->num_fdsb_msix,
8233 pf->num_iwarp_msix);
8234
Shannon Nelson3b444392015-02-26 16:15:57 +00008235 return v_actual;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008236}
8237
8238/**
Greg Rose90e04072014-03-06 08:59:57 +00008239 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
Alexander Duyck493fb302013-09-28 07:01:44 +00008240 * @vsi: the VSI being configured
8241 * @v_idx: index of the vector in the vsi struct
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03008242 * @cpu: cpu to be used on affinity_mask
Alexander Duyck493fb302013-09-28 07:01:44 +00008243 *
8244 * We allocate one q_vector. If allocation fails we return -ENOMEM.
8245 **/
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03008246static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu)
Alexander Duyck493fb302013-09-28 07:01:44 +00008247{
8248 struct i40e_q_vector *q_vector;
8249
8250 /* allocate q_vector */
8251 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
8252 if (!q_vector)
8253 return -ENOMEM;
8254
8255 q_vector->vsi = vsi;
8256 q_vector->v_idx = v_idx;
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03008257 cpumask_set_cpu(cpu, &q_vector->affinity_mask);
8258
Alexander Duyck493fb302013-09-28 07:01:44 +00008259 if (vsi->netdev)
8260 netif_napi_add(vsi->netdev, &q_vector->napi,
Jesse Brandeburgeefeace2014-05-10 04:49:13 +00008261 i40e_napi_poll, NAPI_POLL_WEIGHT);
Alexander Duyck493fb302013-09-28 07:01:44 +00008262
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00008263 q_vector->rx.latency_range = I40E_LOW_LATENCY;
8264 q_vector->tx.latency_range = I40E_LOW_LATENCY;
8265
Alexander Duyck493fb302013-09-28 07:01:44 +00008266 /* tie q_vector and vsi together */
8267 vsi->q_vectors[v_idx] = q_vector;
8268
8269 return 0;
8270}
8271
8272/**
Greg Rose90e04072014-03-06 08:59:57 +00008273 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008274 * @vsi: the VSI being configured
8275 *
8276 * We allocate one q_vector per queue interrupt. If allocation fails we
8277 * return -ENOMEM.
8278 **/
Greg Rose90e04072014-03-06 08:59:57 +00008279static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008280{
8281 struct i40e_pf *pf = vsi->back;
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03008282 int err, v_idx, num_q_vectors, current_cpu;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008283
8284 /* if not MSIX, give the one vector only to the LAN VSI */
8285 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
8286 num_q_vectors = vsi->num_q_vectors;
8287 else if (vsi == pf->vsi[pf->lan_vsi])
8288 num_q_vectors = 1;
8289 else
8290 return -EINVAL;
8291
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03008292 current_cpu = cpumask_first(cpu_online_mask);
8293
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008294 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03008295 err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu);
Alexander Duyck493fb302013-09-28 07:01:44 +00008296 if (err)
8297 goto err_out;
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03008298 current_cpu = cpumask_next(current_cpu, cpu_online_mask);
8299 if (unlikely(current_cpu >= nr_cpu_ids))
8300 current_cpu = cpumask_first(cpu_online_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008301 }
8302
8303 return 0;
Alexander Duyck493fb302013-09-28 07:01:44 +00008304
8305err_out:
8306 while (v_idx--)
8307 i40e_free_q_vector(vsi, v_idx);
8308
8309 return err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008310}
8311
8312/**
8313 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
8314 * @pf: board private structure to initialize
8315 **/
Jesse Brandeburgc11472802015-04-07 19:45:39 -04008316static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008317{
Shannon Nelson3b444392015-02-26 16:15:57 +00008318 int vectors = 0;
8319 ssize_t size;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008320
8321 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
Shannon Nelson3b444392015-02-26 16:15:57 +00008322 vectors = i40e_init_msix(pf);
8323 if (vectors < 0) {
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08008324 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008325 I40E_FLAG_IWARP_ENABLED |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08008326 I40E_FLAG_RSS_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008327 I40E_FLAG_DCB_CAPABLE |
Dave Ertmana0362442016-08-29 17:38:26 -07008328 I40E_FLAG_DCB_ENABLED |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08008329 I40E_FLAG_SRIOV_ENABLED |
8330 I40E_FLAG_FD_SB_ENABLED |
8331 I40E_FLAG_FD_ATR_ENABLED |
8332 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008333
8334 /* rework the queue expectations without MSIX */
8335 i40e_determine_queue_usage(pf);
8336 }
8337 }
8338
8339 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
8340 (pf->flags & I40E_FLAG_MSI_ENABLED)) {
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08008341 dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
Shannon Nelson3b444392015-02-26 16:15:57 +00008342 vectors = pci_enable_msi(pf->pdev);
8343 if (vectors < 0) {
8344 dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
8345 vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008346 pf->flags &= ~I40E_FLAG_MSI_ENABLED;
8347 }
Shannon Nelson3b444392015-02-26 16:15:57 +00008348 vectors = 1; /* one MSI or Legacy vector */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008349 }
8350
Shannon Nelson958a3e32013-09-28 07:13:28 +00008351 if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08008352 dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
Shannon Nelson958a3e32013-09-28 07:13:28 +00008353
Shannon Nelson3b444392015-02-26 16:15:57 +00008354 /* set up vector assignment tracking */
8355 size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
8356 pf->irq_pile = kzalloc(size, GFP_KERNEL);
Jesse Brandeburgc11472802015-04-07 19:45:39 -04008357 if (!pf->irq_pile) {
8358 dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n");
8359 return -ENOMEM;
8360 }
Shannon Nelson3b444392015-02-26 16:15:57 +00008361 pf->irq_pile->num_entries = vectors;
8362 pf->irq_pile->search_hint = 0;
8363
Jesse Brandeburgc11472802015-04-07 19:45:39 -04008364 /* track first vector for misc interrupts, ignore return */
Shannon Nelson3b444392015-02-26 16:15:57 +00008365 (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
Jesse Brandeburgc11472802015-04-07 19:45:39 -04008366
8367 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008368}
8369
8370/**
8371 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
8372 * @pf: board private structure
8373 *
8374 * This sets up the handler for MSIX 0, which is used to manage the
8375 * non-queue interrupts, e.g. AdminQ and errors. This is not used
8376 * when in MSI or Legacy interrupt mode.
8377 **/
8378static int i40e_setup_misc_vector(struct i40e_pf *pf)
8379{
8380 struct i40e_hw *hw = &pf->hw;
8381 int err = 0;
8382
8383 /* Only request the irq if this is the first time through, and
8384 * not when we're rebuilding after a Reset
8385 */
Jacob Keller0da36b92017-04-19 09:25:55 -04008386 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008387 err = request_irq(pf->msix_entries[0].vector,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00008388 i40e_intr, 0, pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008389 if (err) {
8390 dev_info(&pf->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08008391 "request_irq for %s failed: %d\n",
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00008392 pf->int_name, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008393 return -EFAULT;
8394 }
8395 }
8396
Jacob Kellerab437b52014-12-14 01:55:08 +00008397 i40e_enable_misc_int_causes(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008398
8399 /* associate no queues to the misc vector */
8400 wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
8401 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
8402
8403 i40e_flush(hw);
8404
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08008405 i40e_irq_dynamic_enable_icr0(pf, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008406
8407 return err;
8408}
8409
8410/**
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008411 * i40e_config_rss_aq - Prepare for RSS using AQ commands
8412 * @vsi: vsi structure
8413 * @seed: RSS hash seed
8414 **/
Helin Zhange69ff812015-10-21 19:56:22 -04008415static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
8416 u8 *lut, u16 lut_size)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008417{
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008418 struct i40e_pf *pf = vsi->back;
8419 struct i40e_hw *hw = &pf->hw;
Jacob Keller776b2e12016-07-19 16:23:30 -07008420 int ret = 0;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008421
Jacob Keller776b2e12016-07-19 16:23:30 -07008422 if (seed) {
8423 struct i40e_aqc_get_set_rss_key_data *seed_dw =
8424 (struct i40e_aqc_get_set_rss_key_data *)seed;
8425 ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw);
8426 if (ret) {
8427 dev_info(&pf->pdev->dev,
8428 "Cannot set RSS key, err %s aq_err %s\n",
8429 i40e_stat_str(hw, ret),
8430 i40e_aq_str(hw, hw->aq.asq_last_status));
8431 return ret;
8432 }
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008433 }
Jacob Keller776b2e12016-07-19 16:23:30 -07008434 if (lut) {
8435 bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008436
Jacob Keller776b2e12016-07-19 16:23:30 -07008437 ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
8438 if (ret) {
8439 dev_info(&pf->pdev->dev,
8440 "Cannot set RSS lut, err %s aq_err %s\n",
8441 i40e_stat_str(hw, ret),
8442 i40e_aq_str(hw, hw->aq.asq_last_status));
8443 return ret;
8444 }
8445 }
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008446 return ret;
8447}
8448
8449/**
Anjali Singhai Jain95a73782015-12-22 14:25:04 -08008450 * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
8451 * @vsi: Pointer to vsi structure
8452 * @seed: Buffter to store the hash keys
8453 * @lut: Buffer to store the lookup table entries
8454 * @lut_size: Size of buffer to store the lookup table entries
8455 *
8456 * Return 0 on success, negative on failure
8457 */
8458static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
8459 u8 *lut, u16 lut_size)
8460{
8461 struct i40e_pf *pf = vsi->back;
8462 struct i40e_hw *hw = &pf->hw;
8463 int ret = 0;
8464
8465 if (seed) {
8466 ret = i40e_aq_get_rss_key(hw, vsi->id,
8467 (struct i40e_aqc_get_set_rss_key_data *)seed);
8468 if (ret) {
8469 dev_info(&pf->pdev->dev,
8470 "Cannot get RSS key, err %s aq_err %s\n",
8471 i40e_stat_str(&pf->hw, ret),
8472 i40e_aq_str(&pf->hw,
8473 pf->hw.aq.asq_last_status));
8474 return ret;
8475 }
8476 }
8477
8478 if (lut) {
8479 bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
8480
8481 ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
8482 if (ret) {
8483 dev_info(&pf->pdev->dev,
8484 "Cannot get RSS lut, err %s aq_err %s\n",
8485 i40e_stat_str(&pf->hw, ret),
8486 i40e_aq_str(&pf->hw,
8487 pf->hw.aq.asq_last_status));
8488 return ret;
8489 }
8490 }
8491
8492 return ret;
8493}
8494
8495/**
Jacob Keller0582b962016-07-19 16:23:29 -07008496 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
8497 * @vsi: VSI structure
8498 **/
8499static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
8500{
8501 u8 seed[I40E_HKEY_ARRAY_SIZE];
8502 struct i40e_pf *pf = vsi->back;
8503 u8 *lut;
8504 int ret;
8505
8506 if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE))
8507 return 0;
8508
Jacob Keller552b9962016-07-19 16:23:31 -07008509 if (!vsi->rss_size)
8510 vsi->rss_size = min_t(int, pf->alloc_rss_size,
8511 vsi->num_queue_pairs);
8512 if (!vsi->rss_size)
8513 return -EINVAL;
8514
Jacob Keller0582b962016-07-19 16:23:29 -07008515 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
8516 if (!lut)
8517 return -ENOMEM;
Jacob Keller552b9962016-07-19 16:23:31 -07008518 /* Use the user configured hash keys and lookup table if there is one,
8519 * otherwise use default
8520 */
8521 if (vsi->rss_lut_user)
8522 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
8523 else
8524 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
8525 if (vsi->rss_hkey_user)
8526 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
8527 else
8528 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
Jacob Keller0582b962016-07-19 16:23:29 -07008529 ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
8530 kfree(lut);
8531
8532 return ret;
8533}
8534
8535/**
Helin Zhang043dd652015-10-21 19:56:23 -04008536 * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
Helin Zhange69ff812015-10-21 19:56:22 -04008537 * @vsi: Pointer to vsi structure
8538 * @seed: RSS hash seed
8539 * @lut: Lookup table
8540 * @lut_size: Lookup table size
8541 *
8542 * Returns 0 on success, negative on failure
8543 **/
8544static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
8545 const u8 *lut, u16 lut_size)
8546{
8547 struct i40e_pf *pf = vsi->back;
8548 struct i40e_hw *hw = &pf->hw;
Mitch Williamsc4e18682016-04-12 08:30:40 -07008549 u16 vf_id = vsi->vf_id;
Helin Zhange69ff812015-10-21 19:56:22 -04008550 u8 i;
8551
8552 /* Fill out hash function seed */
8553 if (seed) {
8554 u32 *seed_dw = (u32 *)seed;
8555
Mitch Williamsc4e18682016-04-12 08:30:40 -07008556 if (vsi->type == I40E_VSI_MAIN) {
8557 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
Lihong Yang26f77e52017-01-30 12:29:33 -08008558 wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
Mitch Williamsc4e18682016-04-12 08:30:40 -07008559 } else if (vsi->type == I40E_VSI_SRIOV) {
8560 for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
Lihong Yang26f77e52017-01-30 12:29:33 -08008561 wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]);
Mitch Williamsc4e18682016-04-12 08:30:40 -07008562 } else {
8563 dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
8564 }
Helin Zhange69ff812015-10-21 19:56:22 -04008565 }
8566
8567 if (lut) {
8568 u32 *lut_dw = (u32 *)lut;
8569
Mitch Williamsc4e18682016-04-12 08:30:40 -07008570 if (vsi->type == I40E_VSI_MAIN) {
8571 if (lut_size != I40E_HLUT_ARRAY_SIZE)
8572 return -EINVAL;
8573 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8574 wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
8575 } else if (vsi->type == I40E_VSI_SRIOV) {
8576 if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
8577 return -EINVAL;
8578 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
Lihong Yang26f77e52017-01-30 12:29:33 -08008579 wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]);
Mitch Williamsc4e18682016-04-12 08:30:40 -07008580 } else {
8581 dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
8582 }
Helin Zhange69ff812015-10-21 19:56:22 -04008583 }
8584 i40e_flush(hw);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008585
8586 return 0;
8587}
8588
8589/**
Helin Zhang043dd652015-10-21 19:56:23 -04008590 * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
8591 * @vsi: Pointer to VSI structure
8592 * @seed: Buffer to store the keys
8593 * @lut: Buffer to store the lookup table entries
8594 * @lut_size: Size of buffer to store the lookup table entries
8595 *
8596 * Returns 0 on success, negative on failure
8597 */
8598static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
8599 u8 *lut, u16 lut_size)
8600{
8601 struct i40e_pf *pf = vsi->back;
8602 struct i40e_hw *hw = &pf->hw;
8603 u16 i;
8604
8605 if (seed) {
8606 u32 *seed_dw = (u32 *)seed;
8607
8608 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008609 seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
Helin Zhang043dd652015-10-21 19:56:23 -04008610 }
8611 if (lut) {
8612 u32 *lut_dw = (u32 *)lut;
8613
8614 if (lut_size != I40E_HLUT_ARRAY_SIZE)
8615 return -EINVAL;
8616 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8617 lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
8618 }
8619
8620 return 0;
8621}
8622
8623/**
8624 * i40e_config_rss - Configure RSS keys and lut
8625 * @vsi: Pointer to VSI structure
8626 * @seed: RSS hash seed
8627 * @lut: Lookup table
8628 * @lut_size: Lookup table size
8629 *
8630 * Returns 0 on success, negative on failure
8631 */
8632int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
8633{
8634 struct i40e_pf *pf = vsi->back;
8635
8636 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
8637 return i40e_config_rss_aq(vsi, seed, lut, lut_size);
8638 else
8639 return i40e_config_rss_reg(vsi, seed, lut, lut_size);
8640}
8641
8642/**
8643 * i40e_get_rss - Get RSS keys and lut
8644 * @vsi: Pointer to VSI structure
8645 * @seed: Buffer to store the keys
8646 * @lut: Buffer to store the lookup table entries
8647 * lut_size: Size of buffer to store the lookup table entries
8648 *
8649 * Returns 0 on success, negative on failure
8650 */
8651int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
8652{
Anjali Singhai Jain95a73782015-12-22 14:25:04 -08008653 struct i40e_pf *pf = vsi->back;
8654
8655 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
8656 return i40e_get_rss_aq(vsi, seed, lut, lut_size);
8657 else
8658 return i40e_get_rss_reg(vsi, seed, lut, lut_size);
Helin Zhang043dd652015-10-21 19:56:23 -04008659}
8660
8661/**
Helin Zhange69ff812015-10-21 19:56:22 -04008662 * i40e_fill_rss_lut - Fill the RSS lookup table with default values
8663 * @pf: Pointer to board private structure
8664 * @lut: Lookup table
8665 * @rss_table_size: Lookup table size
8666 * @rss_size: Range of queue number for hashing
8667 */
Alan Bradyf1582352016-08-24 11:33:46 -07008668void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
8669 u16 rss_table_size, u16 rss_size)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008670{
Helin Zhange69ff812015-10-21 19:56:22 -04008671 u16 i;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008672
Helin Zhange69ff812015-10-21 19:56:22 -04008673 for (i = 0; i < rss_table_size; i++)
8674 lut[i] = i % rss_size;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008675}
8676
8677/**
Helin Zhang043dd652015-10-21 19:56:23 -04008678 * i40e_pf_config_rss - Prepare for RSS if used
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008679 * @pf: board private structure
8680 **/
Helin Zhang043dd652015-10-21 19:56:23 -04008681static int i40e_pf_config_rss(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008682{
Anjali Singhai Jain66ddcff2015-02-24 06:58:50 +00008683 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008684 u8 seed[I40E_HKEY_ARRAY_SIZE];
Helin Zhange69ff812015-10-21 19:56:22 -04008685 u8 *lut;
Anjali Singhai Jain4617e8c2013-11-20 10:02:56 +00008686 struct i40e_hw *hw = &pf->hw;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00008687 u32 reg_val;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008688 u64 hena;
Helin Zhange69ff812015-10-21 19:56:22 -04008689 int ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008690
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008691 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008692 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
8693 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008694 hena |= i40e_pf_get_default_rss_hena(pf);
8695
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008696 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
8697 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008698
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008699 /* Determine the RSS table size based on the hardware capabilities */
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008700 reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008701 reg_val = (pf->rss_table_size == 512) ?
8702 (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
8703 (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008704 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
Carolyn Wybornye157ea32014-06-03 23:50:22 +00008705
Helin Zhang28c58692015-10-26 19:44:27 -04008706 /* Determine the RSS size of the VSI */
Harshitha Ramamurthyf25571b2017-02-21 15:55:40 -08008707 if (!vsi->rss_size) {
8708 u16 qcount;
8709
8710 qcount = vsi->num_queue_pairs / vsi->tc_config.numtc;
8711 vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
8712 }
Mitch Williamsa4fa59c2016-09-12 14:18:43 -07008713 if (!vsi->rss_size)
8714 return -EINVAL;
Helin Zhang28c58692015-10-26 19:44:27 -04008715
Helin Zhange69ff812015-10-21 19:56:22 -04008716 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
8717 if (!lut)
8718 return -ENOMEM;
8719
Helin Zhang28c58692015-10-26 19:44:27 -04008720 /* Use user configured lut if there is one, otherwise use default */
8721 if (vsi->rss_lut_user)
8722 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
8723 else
8724 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
Helin Zhange69ff812015-10-21 19:56:22 -04008725
Helin Zhang28c58692015-10-26 19:44:27 -04008726 /* Use user configured hash key if there is one, otherwise
8727 * use default.
8728 */
8729 if (vsi->rss_hkey_user)
8730 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
8731 else
8732 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
Helin Zhang043dd652015-10-21 19:56:23 -04008733 ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
Helin Zhange69ff812015-10-21 19:56:22 -04008734 kfree(lut);
8735
8736 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008737}
8738
8739/**
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008740 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
8741 * @pf: board private structure
8742 * @queue_count: the requested queue count for rss.
8743 *
8744 * returns 0 if rss is not enabled, if enabled returns the final rss queue
8745 * count which may be different from the requested queue count.
Maciej Sosin373149f2017-04-05 07:50:55 -04008746 * Note: expects to be called while under rtnl_lock()
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008747 **/
8748int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
8749{
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008750 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
8751 int new_rss_size;
8752
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008753 if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
8754 return 0;
8755
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008756 new_rss_size = min_t(int, queue_count, pf->rss_size_max);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008757
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008758 if (queue_count != vsi->num_queue_pairs) {
Harshitha Ramamurthyf25571b2017-02-21 15:55:40 -08008759 u16 qcount;
8760
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008761 vsi->req_queue_pairs = queue_count;
Maciej Sosin373149f2017-04-05 07:50:55 -04008762 i40e_prep_for_reset(pf, true);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008763
Helin Zhangacd65442015-10-26 19:44:28 -04008764 pf->alloc_rss_size = new_rss_size;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008765
Maciej Sosin373149f2017-04-05 07:50:55 -04008766 i40e_reset_and_rebuild(pf, true, true);
Helin Zhang28c58692015-10-26 19:44:27 -04008767
8768 /* Discard the user configured hash keys and lut, if less
8769 * queues are enabled.
8770 */
8771 if (queue_count < vsi->rss_size) {
8772 i40e_clear_rss_config_user(vsi);
8773 dev_dbg(&pf->pdev->dev,
8774 "discard user configured hash keys and lut\n");
8775 }
8776
8777 /* Reset vsi->rss_size, as number of enabled queues changed */
Harshitha Ramamurthyf25571b2017-02-21 15:55:40 -08008778 qcount = vsi->num_queue_pairs / vsi->tc_config.numtc;
8779 vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
Helin Zhang28c58692015-10-26 19:44:27 -04008780
Helin Zhang043dd652015-10-21 19:56:23 -04008781 i40e_pf_config_rss(pf);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008782 }
Lihong Yang12815052016-09-27 11:28:48 -07008783 dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n",
8784 vsi->req_queue_pairs, pf->rss_size_max);
Helin Zhangacd65442015-10-26 19:44:28 -04008785 return pf->alloc_rss_size;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008786}
8787
8788/**
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008789 * i40e_get_partition_bw_setting - Retrieve BW settings for this PF partition
Greg Rosef4492db2015-02-06 08:52:12 +00008790 * @pf: board private structure
8791 **/
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008792i40e_status i40e_get_partition_bw_setting(struct i40e_pf *pf)
Greg Rosef4492db2015-02-06 08:52:12 +00008793{
8794 i40e_status status;
8795 bool min_valid, max_valid;
8796 u32 max_bw, min_bw;
8797
8798 status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
8799 &min_valid, &max_valid);
8800
8801 if (!status) {
8802 if (min_valid)
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008803 pf->min_bw = min_bw;
Greg Rosef4492db2015-02-06 08:52:12 +00008804 if (max_valid)
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008805 pf->max_bw = max_bw;
Greg Rosef4492db2015-02-06 08:52:12 +00008806 }
8807
8808 return status;
8809}
8810
8811/**
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008812 * i40e_set_partition_bw_setting - Set BW settings for this PF partition
Greg Rosef4492db2015-02-06 08:52:12 +00008813 * @pf: board private structure
8814 **/
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008815i40e_status i40e_set_partition_bw_setting(struct i40e_pf *pf)
Greg Rosef4492db2015-02-06 08:52:12 +00008816{
8817 struct i40e_aqc_configure_partition_bw_data bw_data;
8818 i40e_status status;
8819
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00008820 /* Set the valid bit for this PF */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008821 bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008822 bw_data.max_bw[pf->hw.pf_id] = pf->max_bw & I40E_ALT_BW_VALUE_MASK;
8823 bw_data.min_bw[pf->hw.pf_id] = pf->min_bw & I40E_ALT_BW_VALUE_MASK;
Greg Rosef4492db2015-02-06 08:52:12 +00008824
8825 /* Set the new bandwidths */
8826 status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
8827
8828 return status;
8829}
8830
8831/**
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008832 * i40e_commit_partition_bw_setting - Commit BW settings for this PF partition
Greg Rosef4492db2015-02-06 08:52:12 +00008833 * @pf: board private structure
8834 **/
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008835i40e_status i40e_commit_partition_bw_setting(struct i40e_pf *pf)
Greg Rosef4492db2015-02-06 08:52:12 +00008836{
8837 /* Commit temporary BW setting to permanent NVM image */
8838 enum i40e_admin_queue_err last_aq_status;
8839 i40e_status ret;
8840 u16 nvm_word;
8841
8842 if (pf->hw.partition_id != 1) {
8843 dev_info(&pf->pdev->dev,
8844 "Commit BW only works on partition 1! This is partition %d",
8845 pf->hw.partition_id);
8846 ret = I40E_NOT_SUPPORTED;
8847 goto bw_commit_out;
8848 }
8849
8850 /* Acquire NVM for read access */
8851 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
8852 last_aq_status = pf->hw.aq.asq_last_status;
8853 if (ret) {
8854 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008855 "Cannot acquire NVM for read access, err %s aq_err %s\n",
8856 i40e_stat_str(&pf->hw, ret),
8857 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008858 goto bw_commit_out;
8859 }
8860
8861 /* Read word 0x10 of NVM - SW compatibility word 1 */
8862 ret = i40e_aq_read_nvm(&pf->hw,
8863 I40E_SR_NVM_CONTROL_WORD,
8864 0x10, sizeof(nvm_word), &nvm_word,
8865 false, NULL);
8866 /* Save off last admin queue command status before releasing
8867 * the NVM
8868 */
8869 last_aq_status = pf->hw.aq.asq_last_status;
8870 i40e_release_nvm(&pf->hw);
8871 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008872 dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
8873 i40e_stat_str(&pf->hw, ret),
8874 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008875 goto bw_commit_out;
8876 }
8877
8878 /* Wait a bit for NVM release to complete */
8879 msleep(50);
8880
8881 /* Acquire NVM for write access */
8882 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
8883 last_aq_status = pf->hw.aq.asq_last_status;
8884 if (ret) {
8885 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008886 "Cannot acquire NVM for write access, err %s aq_err %s\n",
8887 i40e_stat_str(&pf->hw, ret),
8888 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008889 goto bw_commit_out;
8890 }
8891 /* Write it back out unchanged to initiate update NVM,
8892 * which will force a write of the shadow (alt) RAM to
8893 * the NVM - thus storing the bandwidth values permanently.
8894 */
8895 ret = i40e_aq_update_nvm(&pf->hw,
8896 I40E_SR_NVM_CONTROL_WORD,
8897 0x10, sizeof(nvm_word),
8898 &nvm_word, true, NULL);
8899 /* Save off last admin queue command status before releasing
8900 * the NVM
8901 */
8902 last_aq_status = pf->hw.aq.asq_last_status;
8903 i40e_release_nvm(&pf->hw);
8904 if (ret)
8905 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008906 "BW settings NOT SAVED, err %s aq_err %s\n",
8907 i40e_stat_str(&pf->hw, ret),
8908 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008909bw_commit_out:
8910
8911 return ret;
8912}
8913
8914/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008915 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
8916 * @pf: board private structure to initialize
8917 *
8918 * i40e_sw_init initializes the Adapter private data structure.
8919 * Fields are initialized based on PCI device information and
8920 * OS network device settings (MTU size).
8921 **/
8922static int i40e_sw_init(struct i40e_pf *pf)
8923{
8924 int err = 0;
8925 int size;
8926
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008927 /* Set default capability flags */
8928 pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
8929 I40E_FLAG_MSI_ENABLED |
Mitch Williams2bc7ee82015-02-06 08:52:11 +00008930 I40E_FLAG_MSIX_ENABLED;
8931
Mitch Williamsca99eb92014-04-04 04:43:07 +00008932 /* Set default ITR */
8933 pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
8934 pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
8935
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008936 /* Depending on PF configurations, it is possible that the RSS
8937 * maximum might end up larger than the available queues
8938 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008939 pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
Helin Zhangacd65442015-10-26 19:44:28 -04008940 pf->alloc_rss_size = 1;
Anjali Singhai Jain5db4cb52015-02-24 06:58:49 +00008941 pf->rss_table_size = pf->hw.func_caps.rss_table_size;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008942 pf->rss_size_max = min_t(int, pf->rss_size_max,
8943 pf->hw.func_caps.num_tx_qp);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008944 if (pf->hw.func_caps.rss) {
8945 pf->flags |= I40E_FLAG_RSS_ENABLED;
Helin Zhangacd65442015-10-26 19:44:28 -04008946 pf->alloc_rss_size = min_t(int, pf->rss_size_max,
8947 num_online_cpus());
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008948 }
8949
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008950 /* MFP mode enabled */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04008951 if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008952 pf->flags |= I40E_FLAG_MFP_ENABLED;
8953 dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008954 if (i40e_get_partition_bw_setting(pf)) {
Greg Rosef4492db2015-02-06 08:52:12 +00008955 dev_warn(&pf->pdev->dev,
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008956 "Could not get partition bw settings\n");
8957 } else {
Greg Rosef4492db2015-02-06 08:52:12 +00008958 dev_info(&pf->pdev->dev,
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008959 "Partition BW Min = %8.8x, Max = %8.8x\n",
8960 pf->min_bw, pf->max_bw);
8961
8962 /* nudge the Tx scheduler */
8963 i40e_set_partition_bw_setting(pf);
8964 }
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008965 }
8966
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008967 if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
8968 (pf->hw.func_caps.fd_filters_best_effort > 0)) {
8969 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
8970 pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
Shannon Nelson6eae9c62015-09-03 17:18:55 -04008971 if (pf->flags & I40E_FLAG_MFP_ENABLED &&
8972 pf->hw.num_partitions > 1)
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008973 dev_info(&pf->pdev->dev,
Anjali Singhai Jain0b675842014-03-06 08:59:51 +00008974 "Flow Director Sideband mode Disabled in MFP mode\n");
Shannon Nelson6eae9c62015-09-03 17:18:55 -04008975 else
8976 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008977 pf->fdir_pf_filter_count =
8978 pf->hw.func_caps.fd_filters_guaranteed;
8979 pf->hw.fdir_shared_filter_count =
8980 pf->hw.func_caps.fd_filters_best_effort;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008981 }
8982
Bimmy Pujari6de432c2016-11-11 12:39:38 -08008983 if ((pf->hw.mac.type == I40E_MAC_XL710) &&
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08008984 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008985 (pf->hw.aq.fw_maj_ver < 4))) {
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08008986 pf->flags |= I40E_FLAG_RESTART_AUTONEG;
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008987 /* No DCB support for FW < v4.33 */
8988 pf->flags |= I40E_FLAG_NO_DCB_SUPPORT;
8989 }
8990
8991 /* Disable FW LLDP if FW < v4.3 */
Bimmy Pujari6de432c2016-11-11 12:39:38 -08008992 if ((pf->hw.mac.type == I40E_MAC_XL710) &&
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008993 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
8994 (pf->hw.aq.fw_maj_ver < 4)))
8995 pf->flags |= I40E_FLAG_STOP_FW_LLDP;
8996
8997 /* Use the FW Set LLDP MIB API if FW > v4.40 */
Bimmy Pujari6de432c2016-11-11 12:39:38 -08008998 if ((pf->hw.mac.type == I40E_MAC_XL710) &&
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008999 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
9000 (pf->hw.aq.fw_maj_ver >= 5)))
9001 pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB;
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08009002
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009003 if (pf->hw.func_caps.vmdq) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009004 pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04009005 pf->flags |= I40E_FLAG_VMDQ_ENABLED;
Jesse Brandeburge9e53662015-10-02 17:57:21 -07009006 pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009007 }
9008
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06009009 if (pf->hw.func_caps.iwarp) {
9010 pf->flags |= I40E_FLAG_IWARP_ENABLED;
9011 /* IWARP needs one extra vector for CQP just like MISC.*/
9012 pf->num_iwarp_msix = (int)num_online_cpus() + 1;
9013 }
9014
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009015#ifdef CONFIG_PCI_IOV
Shannon Nelsonba252f132014-12-11 07:06:34 +00009016 if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009017 pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
9018 pf->flags |= I40E_FLAG_SRIOV_ENABLED;
9019 pf->num_req_vfs = min_t(int,
9020 pf->hw.func_caps.num_vfs,
9021 I40E_MAX_VF_COUNT);
9022 }
9023#endif /* CONFIG_PCI_IOV */
Anjali Singhai Jaind502ce02015-06-05 12:20:26 -04009024 if (pf->hw.mac.type == I40E_MAC_X722) {
Joshua Hay1d680052016-12-12 15:44:08 -08009025 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE
9026 | I40E_FLAG_128_QP_RSS_CAPABLE
9027 | I40E_FLAG_HW_ATR_EVICT_CAPABLE
9028 | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE
9029 | I40E_FLAG_WB_ON_ITR_CAPABLE
9030 | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE
9031 | I40E_FLAG_NO_PCI_LINK_CHECK
9032 | I40E_FLAG_USE_SET_LLDP_MIB
9033 | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE
9034 | I40E_FLAG_PTP_L4_CAPABLE
9035 | I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE;
Anjali Singhaia340c782016-01-06 11:49:28 -08009036 } else if ((pf->hw.aq.api_maj_ver > 1) ||
9037 ((pf->hw.aq.api_maj_ver == 1) &&
9038 (pf->hw.aq.api_min_ver > 4))) {
9039 /* Supported in FW API version higher than 1.4 */
9040 pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
Anjali Singhai Jaind502ce02015-06-05 12:20:26 -04009041 }
Anjali Singhaia340c782016-01-06 11:49:28 -08009042
Jacob Keller6964e532017-06-12 15:38:36 -07009043 /* Enable HW ATR eviction if possible */
9044 if (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE)
9045 pf->flags |= I40E_FLAG_HW_ATR_EVICT_ENABLED;
9046
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009047 pf->eeprom_version = 0xDEAD;
9048 pf->lan_veb = I40E_NO_VEB;
9049 pf->lan_vsi = I40E_NO_VSI;
9050
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04009051 /* By default FW has this off for performance reasons */
9052 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
9053
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009054 /* set up queue assignment tracking */
9055 size = sizeof(struct i40e_lump_tracking)
9056 + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
9057 pf->qp_pile = kzalloc(size, GFP_KERNEL);
9058 if (!pf->qp_pile) {
9059 err = -ENOMEM;
9060 goto sw_init_done;
9061 }
9062 pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
9063 pf->qp_pile->search_hint = 0;
9064
Anjali Singhai Jain327fe042014-06-04 01:23:26 +00009065 pf->tx_timeout_recovery_level = 1;
9066
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009067 mutex_init(&pf->switch_mutex);
9068
9069sw_init_done:
9070 return err;
9071}
9072
9073/**
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00009074 * i40e_set_ntuple - set the ntuple feature flag and take action
9075 * @pf: board private structure to initialize
9076 * @features: the feature set that the stack is suggesting
9077 *
9078 * returns a bool to indicate if reset needs to happen
9079 **/
9080bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
9081{
9082 bool need_reset = false;
9083
9084 /* Check if Flow Director n-tuple support was enabled or disabled. If
9085 * the state changed, we need to reset.
9086 */
9087 if (features & NETIF_F_NTUPLE) {
9088 /* Enable filters and mark for reset */
9089 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
9090 need_reset = true;
Tushar Davea70e4072016-05-16 12:40:53 -07009091 /* enable FD_SB only if there is MSI-X vector */
9092 if (pf->num_fdsb_msix > 0)
9093 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00009094 } else {
9095 /* turn off filters, mark for reset and clear SW filter list */
9096 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
9097 need_reset = true;
9098 i40e_fdir_filter_exit(pf);
9099 }
Jacob Keller47994c12017-04-19 09:25:57 -04009100 pf->flags &= ~(I40E_FLAG_FD_SB_ENABLED |
9101 I40E_FLAG_FD_SB_AUTO_DISABLED);
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00009102 /* reset fd counters */
Jacob Keller097dbf52017-02-06 14:38:46 -08009103 pf->fd_add_err = 0;
9104 pf->fd_atr_cnt = 0;
Anjali Singhai Jain8a4f34f2014-06-04 08:45:20 +00009105 /* if ATR was auto disabled it can be re-enabled. */
Jacob Keller47994c12017-04-19 09:25:57 -04009106 if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) {
9107 pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
9108 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
9109 (I40E_DEBUG_FD & pf->hw.debug_mask))
Jacob Keller234dc4e2016-09-06 18:05:09 -07009110 dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
9111 }
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00009112 }
9113 return need_reset;
9114}
9115
9116/**
Alan Bradyd8ec9862016-07-27 12:02:38 -07009117 * i40e_clear_rss_lut - clear the rx hash lookup table
9118 * @vsi: the VSI being configured
9119 **/
9120static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
9121{
9122 struct i40e_pf *pf = vsi->back;
9123 struct i40e_hw *hw = &pf->hw;
9124 u16 vf_id = vsi->vf_id;
9125 u8 i;
9126
9127 if (vsi->type == I40E_VSI_MAIN) {
9128 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
9129 wr32(hw, I40E_PFQF_HLUT(i), 0);
9130 } else if (vsi->type == I40E_VSI_SRIOV) {
9131 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
9132 i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
9133 } else {
9134 dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
9135 }
9136}
9137
9138/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009139 * i40e_set_features - set the netdev feature flags
9140 * @netdev: ptr to the netdev being adjusted
9141 * @features: the feature set that the stack is suggesting
Maciej Sosin373149f2017-04-05 07:50:55 -04009142 * Note: expects to be called while under rtnl_lock()
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009143 **/
9144static int i40e_set_features(struct net_device *netdev,
9145 netdev_features_t features)
9146{
9147 struct i40e_netdev_priv *np = netdev_priv(netdev);
9148 struct i40e_vsi *vsi = np->vsi;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00009149 struct i40e_pf *pf = vsi->back;
9150 bool need_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009151
Alan Bradyd8ec9862016-07-27 12:02:38 -07009152 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
9153 i40e_pf_config_rss(pf);
9154 else if (!(features & NETIF_F_RXHASH) &&
9155 netdev->features & NETIF_F_RXHASH)
9156 i40e_clear_rss_lut(vsi);
9157
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009158 if (features & NETIF_F_HW_VLAN_CTAG_RX)
9159 i40e_vlan_stripping_enable(vsi);
9160 else
9161 i40e_vlan_stripping_disable(vsi);
9162
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00009163 need_reset = i40e_set_ntuple(pf, features);
9164
9165 if (need_reset)
Maciej Sosin373149f2017-04-05 07:50:55 -04009166 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED), true);
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00009167
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009168 return 0;
9169}
9170
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009171/**
Singhai, Anjali6a899022015-12-14 12:21:18 -08009172 * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009173 * @pf: board private structure
9174 * @port: The UDP port to look up
9175 *
9176 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
9177 **/
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08009178static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, u16 port)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009179{
9180 u8 i;
9181
9182 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
Jacob Keller27826fd2017-04-19 09:25:50 -04009183 if (pf->udp_ports[i].port == port)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009184 return i;
9185 }
9186
9187 return i;
9188}
9189
9190/**
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009191 * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009192 * @netdev: This physical port's netdev
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009193 * @ti: Tunnel endpoint information
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009194 **/
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009195static void i40e_udp_tunnel_add(struct net_device *netdev,
9196 struct udp_tunnel_info *ti)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009197{
9198 struct i40e_netdev_priv *np = netdev_priv(netdev);
9199 struct i40e_vsi *vsi = np->vsi;
9200 struct i40e_pf *pf = vsi->back;
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08009201 u16 port = ntohs(ti->port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009202 u8 next_idx;
9203 u8 idx;
9204
Singhai, Anjali6a899022015-12-14 12:21:18 -08009205 idx = i40e_get_udp_port_idx(pf, port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009206
9207 /* Check if port already exists */
9208 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08009209 netdev_info(netdev, "port %d already offloaded\n", port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009210 return;
9211 }
9212
9213 /* Now check if there is space to add the new port */
Singhai, Anjali6a899022015-12-14 12:21:18 -08009214 next_idx = i40e_get_udp_port_idx(pf, 0);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009215
9216 if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009217 netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08009218 port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009219 return;
9220 }
9221
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009222 switch (ti->type) {
9223 case UDP_TUNNEL_TYPE_VXLAN:
9224 pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
9225 break;
9226 case UDP_TUNNEL_TYPE_GENEVE:
9227 if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
9228 return;
9229 pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
9230 break;
9231 default:
9232 return;
9233 }
9234
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009235 /* New port: add it and mark its index in the bitmap */
Jacob Keller27826fd2017-04-19 09:25:50 -04009236 pf->udp_ports[next_idx].port = port;
Singhai, Anjali6a899022015-12-14 12:21:18 -08009237 pf->pending_udp_bitmap |= BIT_ULL(next_idx);
9238 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009239}
9240
9241/**
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009242 * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009243 * @netdev: This physical port's netdev
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009244 * @ti: Tunnel endpoint information
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009245 **/
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009246static void i40e_udp_tunnel_del(struct net_device *netdev,
9247 struct udp_tunnel_info *ti)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009248{
9249 struct i40e_netdev_priv *np = netdev_priv(netdev);
9250 struct i40e_vsi *vsi = np->vsi;
9251 struct i40e_pf *pf = vsi->back;
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08009252 u16 port = ntohs(ti->port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009253 u8 idx;
9254
Singhai, Anjali6a899022015-12-14 12:21:18 -08009255 idx = i40e_get_udp_port_idx(pf, port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009256
9257 /* Check if port already exists */
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009258 if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
9259 goto not_found;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009260
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009261 switch (ti->type) {
9262 case UDP_TUNNEL_TYPE_VXLAN:
9263 if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
9264 goto not_found;
9265 break;
9266 case UDP_TUNNEL_TYPE_GENEVE:
9267 if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
9268 goto not_found;
9269 break;
9270 default:
9271 goto not_found;
Singhai, Anjali6a899022015-12-14 12:21:18 -08009272 }
9273
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009274 /* if port exists, set it to 0 (mark for deletion)
9275 * and make it pending
9276 */
Jacob Keller27826fd2017-04-19 09:25:50 -04009277 pf->udp_ports[idx].port = 0;
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009278 pf->pending_udp_bitmap |= BIT_ULL(idx);
Singhai, Anjali6a899022015-12-14 12:21:18 -08009279 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
9280
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009281 return;
9282not_found:
9283 netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08009284 port);
Singhai, Anjali6a899022015-12-14 12:21:18 -08009285}
9286
Neerav Parikh1f224ad2014-02-12 01:45:31 +00009287static int i40e_get_phys_port_id(struct net_device *netdev,
Jiri Pirko02637fc2014-11-28 14:34:16 +01009288 struct netdev_phys_item_id *ppid)
Neerav Parikh1f224ad2014-02-12 01:45:31 +00009289{
9290 struct i40e_netdev_priv *np = netdev_priv(netdev);
9291 struct i40e_pf *pf = np->vsi->back;
9292 struct i40e_hw *hw = &pf->hw;
9293
9294 if (!(pf->flags & I40E_FLAG_PORT_ID_VALID))
9295 return -EOPNOTSUPP;
9296
9297 ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
9298 memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
9299
9300 return 0;
9301}
9302
Jesse Brandeburg2f90ade2014-11-20 16:30:02 -08009303/**
9304 * i40e_ndo_fdb_add - add an entry to the hardware database
9305 * @ndm: the input from the stack
9306 * @tb: pointer to array of nladdr (unused)
9307 * @dev: the net device pointer
9308 * @addr: the MAC address entry being added
9309 * @flags: instructions from stack about fdb operation
9310 */
Greg Rose4ba0dea2014-03-06 08:59:55 +00009311static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
9312 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01009313 const unsigned char *addr, u16 vid,
Greg Rose4ba0dea2014-03-06 08:59:55 +00009314 u16 flags)
Greg Rose4ba0dea2014-03-06 08:59:55 +00009315{
9316 struct i40e_netdev_priv *np = netdev_priv(dev);
9317 struct i40e_pf *pf = np->vsi->back;
9318 int err = 0;
9319
9320 if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
9321 return -EOPNOTSUPP;
9322
Or Gerlitz65891fe2014-12-14 18:19:05 +02009323 if (vid) {
9324 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
9325 return -EINVAL;
9326 }
9327
Greg Rose4ba0dea2014-03-06 08:59:55 +00009328 /* Hardware does not support aging addresses so if a
9329 * ndm_state is given only allow permanent addresses
9330 */
9331 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
9332 netdev_info(dev, "FDB only supports static addresses\n");
9333 return -EINVAL;
9334 }
9335
9336 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
9337 err = dev_uc_add_excl(dev, addr);
9338 else if (is_multicast_ether_addr(addr))
9339 err = dev_mc_add_excl(dev, addr);
9340 else
9341 err = -EINVAL;
9342
9343 /* Only return duplicate errors if NLM_F_EXCL is set */
9344 if (err == -EEXIST && !(flags & NLM_F_EXCL))
9345 err = 0;
9346
9347 return err;
9348}
9349
Neerav Parikh51616012015-02-06 08:52:14 +00009350/**
9351 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
9352 * @dev: the netdev being configured
9353 * @nlh: RTNL message
9354 *
9355 * Inserts a new hardware bridge if not already created and
9356 * enables the bridging mode requested (VEB or VEPA). If the
9357 * hardware bridge has already been inserted and the request
9358 * is to change the mode then that requires a PF reset to
9359 * allow rebuild of the components with required hardware
9360 * bridge mode enabled.
Maciej Sosin373149f2017-04-05 07:50:55 -04009361 *
9362 * Note: expects to be called while under rtnl_lock()
Neerav Parikh51616012015-02-06 08:52:14 +00009363 **/
9364static int i40e_ndo_bridge_setlink(struct net_device *dev,
Carolyn Wyborny9df70b62015-04-27 14:57:11 -04009365 struct nlmsghdr *nlh,
9366 u16 flags)
Neerav Parikh51616012015-02-06 08:52:14 +00009367{
9368 struct i40e_netdev_priv *np = netdev_priv(dev);
9369 struct i40e_vsi *vsi = np->vsi;
9370 struct i40e_pf *pf = vsi->back;
9371 struct i40e_veb *veb = NULL;
9372 struct nlattr *attr, *br_spec;
9373 int i, rem;
9374
9375 /* Only for PF VSI for now */
9376 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
9377 return -EOPNOTSUPP;
9378
9379 /* Find the HW bridge for PF VSI */
9380 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
9381 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
9382 veb = pf->veb[i];
9383 }
9384
9385 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
9386
9387 nla_for_each_nested(attr, br_spec, rem) {
9388 __u16 mode;
9389
9390 if (nla_type(attr) != IFLA_BRIDGE_MODE)
9391 continue;
9392
9393 mode = nla_get_u16(attr);
9394 if ((mode != BRIDGE_MODE_VEPA) &&
9395 (mode != BRIDGE_MODE_VEB))
9396 return -EINVAL;
9397
9398 /* Insert a new HW bridge */
9399 if (!veb) {
9400 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
9401 vsi->tc_config.enabled_tc);
9402 if (veb) {
9403 veb->bridge_mode = mode;
9404 i40e_config_bridge_mode(veb);
9405 } else {
9406 /* No Bridge HW offload available */
9407 return -ENOENT;
9408 }
9409 break;
9410 } else if (mode != veb->bridge_mode) {
9411 /* Existing HW bridge but different mode needs reset */
9412 veb->bridge_mode = mode;
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009413 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
9414 if (mode == BRIDGE_MODE_VEB)
9415 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
9416 else
9417 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
Maciej Sosin373149f2017-04-05 07:50:55 -04009418 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED),
9419 true);
Neerav Parikh51616012015-02-06 08:52:14 +00009420 break;
9421 }
9422 }
9423
9424 return 0;
9425}
9426
9427/**
9428 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
9429 * @skb: skb buff
9430 * @pid: process id
9431 * @seq: RTNL message seq #
9432 * @dev: the netdev being configured
9433 * @filter_mask: unused
Jesse Brandeburgd4b2f9f2015-09-03 17:18:48 -04009434 * @nlflags: netlink flags passed in
Neerav Parikh51616012015-02-06 08:52:14 +00009435 *
9436 * Return the mode in which the hardware bridge is operating in
9437 * i.e VEB or VEPA.
9438 **/
Neerav Parikh51616012015-02-06 08:52:14 +00009439static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
9440 struct net_device *dev,
Carolyn Wyborny9f4ffc42015-08-31 19:54:42 -04009441 u32 __always_unused filter_mask,
9442 int nlflags)
Neerav Parikh51616012015-02-06 08:52:14 +00009443{
9444 struct i40e_netdev_priv *np = netdev_priv(dev);
9445 struct i40e_vsi *vsi = np->vsi;
9446 struct i40e_pf *pf = vsi->back;
9447 struct i40e_veb *veb = NULL;
9448 int i;
9449
9450 /* Only for PF VSI for now */
9451 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
9452 return -EOPNOTSUPP;
9453
9454 /* Find the HW bridge for the PF VSI */
9455 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
9456 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
9457 veb = pf->veb[i];
9458 }
9459
9460 if (!veb)
9461 return 0;
9462
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02009463 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
Huaibin Wang599b0762016-09-26 09:51:18 +02009464 0, 0, nlflags, filter_mask, NULL);
Neerav Parikh51616012015-02-06 08:52:14 +00009465}
Neerav Parikh51616012015-02-06 08:52:14 +00009466
Joe Stringerf44a75e2015-04-14 17:09:14 -07009467/**
9468 * i40e_features_check - Validate encapsulated packet conforms to limits
9469 * @skb: skb buff
Jean Sacren2bc11c62015-09-19 05:08:43 -06009470 * @dev: This physical port's netdev
Joe Stringerf44a75e2015-04-14 17:09:14 -07009471 * @features: Offload features that the stack believes apply
9472 **/
9473static netdev_features_t i40e_features_check(struct sk_buff *skb,
9474 struct net_device *dev,
9475 netdev_features_t features)
9476{
Alexander Duyckf114dca2016-10-25 16:08:46 -07009477 size_t len;
9478
9479 /* No point in doing any of this if neither checksum nor GSO are
9480 * being requested for this frame. We can rule out both by just
9481 * checking for CHECKSUM_PARTIAL
9482 */
9483 if (skb->ip_summed != CHECKSUM_PARTIAL)
9484 return features;
9485
9486 /* We cannot support GSO if the MSS is going to be less than
9487 * 64 bytes. If it is then we need to drop support for GSO.
9488 */
9489 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
9490 features &= ~NETIF_F_GSO_MASK;
9491
9492 /* MACLEN can support at most 63 words */
9493 len = skb_network_header(skb) - skb->data;
9494 if (len & ~(63 * 2))
9495 goto out_err;
9496
9497 /* IPLEN and EIPLEN can support at most 127 dwords */
9498 len = skb_transport_header(skb) - skb_network_header(skb);
9499 if (len & ~(127 * 4))
9500 goto out_err;
9501
9502 if (skb->encapsulation) {
9503 /* L4TUNLEN can support 127 words */
9504 len = skb_inner_network_header(skb) - skb_transport_header(skb);
9505 if (len & ~(127 * 2))
9506 goto out_err;
9507
9508 /* IPLEN can support at most 127 dwords */
9509 len = skb_inner_transport_header(skb) -
9510 skb_inner_network_header(skb);
9511 if (len & ~(127 * 4))
9512 goto out_err;
9513 }
9514
9515 /* No need to validate L4LEN as TCP is the only protocol with a
9516 * a flexible value and we support all possible values supported
9517 * by TCP, which is at most 15 dwords
9518 */
Joe Stringerf44a75e2015-04-14 17:09:14 -07009519
9520 return features;
Alexander Duyckf114dca2016-10-25 16:08:46 -07009521out_err:
9522 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
Joe Stringerf44a75e2015-04-14 17:09:14 -07009523}
9524
Björn Töpel0c8493d2017-05-24 07:55:34 +02009525/**
9526 * i40e_xdp_setup - add/remove an XDP program
9527 * @vsi: VSI to changed
9528 * @prog: XDP program
9529 **/
9530static int i40e_xdp_setup(struct i40e_vsi *vsi,
9531 struct bpf_prog *prog)
9532{
9533 int frame_size = vsi->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
9534 struct i40e_pf *pf = vsi->back;
9535 struct bpf_prog *old_prog;
9536 bool need_reset;
9537 int i;
9538
9539 /* Don't allow frames that span over multiple buffers */
9540 if (frame_size > vsi->rx_buf_len)
9541 return -EINVAL;
9542
9543 if (!i40e_enabled_xdp_vsi(vsi) && !prog)
9544 return 0;
9545
9546 /* When turning XDP on->off/off->on we reset and rebuild the rings. */
9547 need_reset = (i40e_enabled_xdp_vsi(vsi) != !!prog);
9548
9549 if (need_reset)
9550 i40e_prep_for_reset(pf, true);
9551
9552 old_prog = xchg(&vsi->xdp_prog, prog);
9553
9554 if (need_reset)
9555 i40e_reset_and_rebuild(pf, true, true);
9556
9557 for (i = 0; i < vsi->num_queue_pairs; i++)
9558 WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
9559
9560 if (old_prog)
9561 bpf_prog_put(old_prog);
9562
9563 return 0;
9564}
9565
9566/**
9567 * i40e_xdp - implements ndo_xdp for i40e
9568 * @dev: netdevice
9569 * @xdp: XDP command
9570 **/
9571static int i40e_xdp(struct net_device *dev,
9572 struct netdev_xdp *xdp)
9573{
9574 struct i40e_netdev_priv *np = netdev_priv(dev);
9575 struct i40e_vsi *vsi = np->vsi;
9576
9577 if (vsi->type != I40E_VSI_MAIN)
9578 return -EINVAL;
9579
9580 switch (xdp->command) {
9581 case XDP_SETUP_PROG:
9582 return i40e_xdp_setup(vsi, xdp->prog);
9583 case XDP_QUERY_PROG:
9584 xdp->prog_attached = i40e_enabled_xdp_vsi(vsi);
9585 return 0;
9586 default:
9587 return -EINVAL;
9588 }
9589}
9590
Shannon Nelson37a29732015-02-27 09:15:19 +00009591static const struct net_device_ops i40e_netdev_ops = {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009592 .ndo_open = i40e_open,
9593 .ndo_stop = i40e_close,
9594 .ndo_start_xmit = i40e_lan_xmit_frame,
9595 .ndo_get_stats64 = i40e_get_netdev_stats_struct,
9596 .ndo_set_rx_mode = i40e_set_rx_mode,
9597 .ndo_validate_addr = eth_validate_addr,
9598 .ndo_set_mac_address = i40e_set_mac,
9599 .ndo_change_mtu = i40e_change_mtu,
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00009600 .ndo_do_ioctl = i40e_ioctl,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009601 .ndo_tx_timeout = i40e_tx_timeout,
9602 .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
9603 .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
9604#ifdef CONFIG_NET_POLL_CONTROLLER
9605 .ndo_poll_controller = i40e_netpoll,
9606#endif
John Fastabende4c67342016-02-16 21:16:15 -08009607 .ndo_setup_tc = __i40e_setup_tc,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009608 .ndo_set_features = i40e_set_features,
9609 .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
9610 .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04009611 .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009612 .ndo_get_vf_config = i40e_ndo_get_vf_config,
Mitch Williams588aefa2014-02-11 08:27:49 +00009613 .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
Serey Konge6d90042014-07-12 07:28:14 +00009614 .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
Anjali Singhai Jainc3bbbd22016-04-01 03:56:07 -07009615 .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009616 .ndo_udp_tunnel_add = i40e_udp_tunnel_add,
9617 .ndo_udp_tunnel_del = i40e_udp_tunnel_del,
Neerav Parikh1f224ad2014-02-12 01:45:31 +00009618 .ndo_get_phys_port_id = i40e_get_phys_port_id,
Greg Rose4ba0dea2014-03-06 08:59:55 +00009619 .ndo_fdb_add = i40e_ndo_fdb_add,
Joe Stringerf44a75e2015-04-14 17:09:14 -07009620 .ndo_features_check = i40e_features_check,
Neerav Parikh51616012015-02-06 08:52:14 +00009621 .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
9622 .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
Björn Töpel0c8493d2017-05-24 07:55:34 +02009623 .ndo_xdp = i40e_xdp,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009624};
9625
9626/**
9627 * i40e_config_netdev - Setup the netdev flags
9628 * @vsi: the VSI being configured
9629 *
9630 * Returns 0 on success, negative value on failure
9631 **/
9632static int i40e_config_netdev(struct i40e_vsi *vsi)
9633{
9634 struct i40e_pf *pf = vsi->back;
9635 struct i40e_hw *hw = &pf->hw;
9636 struct i40e_netdev_priv *np;
9637 struct net_device *netdev;
Jacob Keller435c0842016-11-08 13:05:10 -08009638 u8 broadcast[ETH_ALEN];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009639 u8 mac_addr[ETH_ALEN];
9640 int etherdev_size;
Preethi Banalabacd75c2017-03-27 14:43:18 -07009641 netdev_features_t hw_enc_features;
9642 netdev_features_t hw_features;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009643
9644 etherdev_size = sizeof(struct i40e_netdev_priv);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00009645 netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009646 if (!netdev)
9647 return -ENOMEM;
9648
9649 vsi->netdev = netdev;
9650 np = netdev_priv(netdev);
9651 np->vsi = vsi;
9652
Preethi Banalabacd75c2017-03-27 14:43:18 -07009653 hw_enc_features = NETIF_F_SG |
9654 NETIF_F_IP_CSUM |
9655 NETIF_F_IPV6_CSUM |
9656 NETIF_F_HIGHDMA |
9657 NETIF_F_SOFT_FEATURES |
9658 NETIF_F_TSO |
9659 NETIF_F_TSO_ECN |
9660 NETIF_F_TSO6 |
9661 NETIF_F_GSO_GRE |
9662 NETIF_F_GSO_GRE_CSUM |
9663 NETIF_F_GSO_PARTIAL |
9664 NETIF_F_GSO_UDP_TUNNEL |
9665 NETIF_F_GSO_UDP_TUNNEL_CSUM |
9666 NETIF_F_SCTP_CRC |
9667 NETIF_F_RXHASH |
9668 NETIF_F_RXCSUM |
9669 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009670
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009671 if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE))
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04009672 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
9673
9674 netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009675
Preethi Banalabacd75c2017-03-27 14:43:18 -07009676 netdev->hw_enc_features |= hw_enc_features;
9677
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009678 /* record features VLANs can make use of */
Preethi Banalabacd75c2017-03-27 14:43:18 -07009679 netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009680
Anjali Singhai Jain2e86a0b2014-04-01 07:11:53 +00009681 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009682 netdev->hw_features |= NETIF_F_NTUPLE;
Preethi Banalabacd75c2017-03-27 14:43:18 -07009683 hw_features = hw_enc_features |
9684 NETIF_F_HW_VLAN_CTAG_TX |
9685 NETIF_F_HW_VLAN_CTAG_RX;
Anjali Singhai Jain2e86a0b2014-04-01 07:11:53 +00009686
Preethi Banalabacd75c2017-03-27 14:43:18 -07009687 netdev->hw_features |= hw_features;
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009688
Preethi Banalabacd75c2017-03-27 14:43:18 -07009689 netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04009690 netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009691
9692 if (vsi->type == I40E_VSI_MAIN) {
9693 SET_NETDEV_DEV(netdev, &pf->pdev->dev);
Greg Rose9a173902014-05-22 06:32:02 +00009694 ether_addr_copy(mac_addr, hw->mac.perm_addr);
Jacob Keller41c4c2b2017-04-05 07:50:57 -04009695 /* The following steps are necessary for two reasons. First,
9696 * some older NVM configurations load a default MAC-VLAN
9697 * filter that will accept any tagged packet, and we want to
9698 * replace this with a normal filter. Additionally, it is
9699 * possible our MAC address was provided by the platform using
9700 * Open Firmware or similar.
9701 *
9702 * Thus, we need to remove the default filter and install one
9703 * specific to the MAC address.
Jacob Keller1596b5d2016-11-08 13:05:15 -08009704 */
9705 i40e_rm_default_mac_filter(vsi, mac_addr);
Jacob Keller278e7d02016-10-05 09:30:37 -07009706 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller9569a9a2016-11-11 12:39:37 -08009707 i40e_add_mac_filter(vsi, mac_addr);
Jacob Keller278e7d02016-10-05 09:30:37 -07009708 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009709 } else {
9710 /* relate the VSI_VMDQ name to the VSI_MAIN name */
9711 snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
9712 pf->vsi[pf->lan_vsi]->netdev->name);
9713 random_ether_addr(mac_addr);
Kiran Patil21659032015-09-30 14:09:03 -04009714
Jacob Keller278e7d02016-10-05 09:30:37 -07009715 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller9569a9a2016-11-11 12:39:37 -08009716 i40e_add_mac_filter(vsi, mac_addr);
Jacob Keller278e7d02016-10-05 09:30:37 -07009717 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009718 }
Kiran Patil21659032015-09-30 14:09:03 -04009719
Jacob Keller435c0842016-11-08 13:05:10 -08009720 /* Add the broadcast filter so that we initially will receive
9721 * broadcast packets. Note that when a new VLAN is first added the
9722 * driver will convert all filters marked I40E_VLAN_ANY into VLAN
9723 * specific filters as part of transitioning into "vlan" operation.
9724 * When more VLANs are added, the driver will copy each existing MAC
9725 * filter and add it for the new VLAN.
9726 *
9727 * Broadcast filters are handled specially by
9728 * i40e_sync_filters_subtask, as the driver must to set the broadcast
9729 * promiscuous bit instead of adding this directly as a MAC/VLAN
9730 * filter. The subtask will update the correct broadcast promiscuous
9731 * bits as VLANs become active or inactive.
9732 */
9733 eth_broadcast_addr(broadcast);
9734 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller9569a9a2016-11-11 12:39:37 -08009735 i40e_add_mac_filter(vsi, broadcast);
Jacob Keller435c0842016-11-08 13:05:10 -08009736 spin_unlock_bh(&vsi->mac_filter_hash_lock);
9737
Greg Rose9a173902014-05-22 06:32:02 +00009738 ether_addr_copy(netdev->dev_addr, mac_addr);
9739 ether_addr_copy(netdev->perm_addr, mac_addr);
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009740
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009741 netdev->priv_flags |= IFF_UNICAST_FLT;
9742 netdev->priv_flags |= IFF_SUPP_NOFCS;
9743 /* Setup netdev TC information */
9744 i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
9745
9746 netdev->netdev_ops = &i40e_netdev_ops;
9747 netdev->watchdog_timeo = 5 * HZ;
9748 i40e_set_ethtool_ops(netdev);
9749
Jarod Wilson91c527a2016-10-17 15:54:05 -04009750 /* MTU range: 68 - 9706 */
9751 netdev->min_mtu = ETH_MIN_MTU;
9752 netdev->max_mtu = I40E_MAX_RXBUFFER -
9753 (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
9754
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009755 return 0;
9756}
9757
9758/**
9759 * i40e_vsi_delete - Delete a VSI from the switch
9760 * @vsi: the VSI being removed
9761 *
9762 * Returns 0 on success, negative value on failure
9763 **/
9764static void i40e_vsi_delete(struct i40e_vsi *vsi)
9765{
9766 /* remove default VSI is not allowed */
9767 if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
9768 return;
9769
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009770 i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009771}
9772
9773/**
Neerav Parikh51616012015-02-06 08:52:14 +00009774 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
9775 * @vsi: the VSI being queried
9776 *
9777 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
9778 **/
9779int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
9780{
9781 struct i40e_veb *veb;
9782 struct i40e_pf *pf = vsi->back;
9783
9784 /* Uplink is not a bridge so default to VEB */
9785 if (vsi->veb_idx == I40E_NO_VEB)
9786 return 1;
9787
9788 veb = pf->veb[vsi->veb_idx];
Akeem G Abodunrin09603ea2015-10-01 14:37:36 -04009789 if (!veb) {
9790 dev_info(&pf->pdev->dev,
9791 "There is no veb associated with the bridge\n");
9792 return -ENOENT;
9793 }
Neerav Parikh51616012015-02-06 08:52:14 +00009794
Akeem G Abodunrin09603ea2015-10-01 14:37:36 -04009795 /* Uplink is a bridge in VEPA mode */
9796 if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
9797 return 0;
9798 } else {
9799 /* Uplink is a bridge in VEB mode */
9800 return 1;
9801 }
9802
9803 /* VEPA is now default bridge, so return 0 */
9804 return 0;
Neerav Parikh51616012015-02-06 08:52:14 +00009805}
9806
9807/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009808 * i40e_add_vsi - Add a VSI to the switch
9809 * @vsi: the VSI being configured
9810 *
9811 * This initializes a VSI context depending on the VSI type to be added and
9812 * passes it down to the add_vsi aq command.
9813 **/
9814static int i40e_add_vsi(struct i40e_vsi *vsi)
9815{
9816 int ret = -ENODEV;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009817 struct i40e_pf *pf = vsi->back;
9818 struct i40e_hw *hw = &pf->hw;
9819 struct i40e_vsi_context ctxt;
Jacob Keller278e7d02016-10-05 09:30:37 -07009820 struct i40e_mac_filter *f;
9821 struct hlist_node *h;
9822 int bkt;
Kiran Patil21659032015-09-30 14:09:03 -04009823
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009824 u8 enabled_tc = 0x1; /* TC0 enabled */
9825 int f_count = 0;
9826
9827 memset(&ctxt, 0, sizeof(ctxt));
9828 switch (vsi->type) {
9829 case I40E_VSI_MAIN:
9830 /* The PF's main VSI is already setup as part of the
9831 * device initialization, so we'll not bother with
9832 * the add_vsi call, but we will retrieve the current
9833 * VSI context.
9834 */
9835 ctxt.seid = pf->main_vsi_seid;
9836 ctxt.pf_num = pf->hw.pf_id;
9837 ctxt.vf_num = 0;
9838 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
9839 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
9840 if (ret) {
9841 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009842 "couldn't get PF vsi config, err %s aq_err %s\n",
9843 i40e_stat_str(&pf->hw, ret),
9844 i40e_aq_str(&pf->hw,
9845 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009846 return -ENOENT;
9847 }
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07009848 vsi->info = ctxt.info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009849 vsi->info.valid_sections = 0;
9850
9851 vsi->seid = ctxt.seid;
9852 vsi->id = ctxt.vsi_number;
9853
9854 enabled_tc = i40e_pf_get_tc_map(pf);
9855
9856 /* MFP mode setup queue map and update VSI */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00009857 if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
9858 !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009859 memset(&ctxt, 0, sizeof(ctxt));
9860 ctxt.seid = pf->main_vsi_seid;
9861 ctxt.pf_num = pf->hw.pf_id;
9862 ctxt.vf_num = 0;
9863 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
9864 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
9865 if (ret) {
9866 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009867 "update vsi failed, err %s aq_err %s\n",
9868 i40e_stat_str(&pf->hw, ret),
9869 i40e_aq_str(&pf->hw,
9870 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009871 ret = -ENOENT;
9872 goto err;
9873 }
9874 /* update the local VSI info queue map */
9875 i40e_vsi_update_queue_map(vsi, &ctxt);
9876 vsi->info.valid_sections = 0;
9877 } else {
9878 /* Default/Main VSI is only enabled for TC0
9879 * reconfigure it to enable all TCs that are
9880 * available on the port in SFP mode.
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00009881 * For MFP case the iSCSI PF would use this
9882 * flow to enable LAN+iSCSI TC.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009883 */
9884 ret = i40e_vsi_config_tc(vsi, enabled_tc);
9885 if (ret) {
9886 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009887 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
9888 enabled_tc,
9889 i40e_stat_str(&pf->hw, ret),
9890 i40e_aq_str(&pf->hw,
9891 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009892 ret = -ENOENT;
9893 }
9894 }
9895 break;
9896
9897 case I40E_VSI_FDIR:
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009898 ctxt.pf_num = hw->pf_id;
9899 ctxt.vf_num = 0;
9900 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009901 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009902 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009903 if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
9904 (i40e_is_vsi_uplink_mode_veb(vsi))) {
Neerav Parikh51616012015-02-06 08:52:14 +00009905 ctxt.info.valid_sections |=
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009906 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
Neerav Parikh51616012015-02-06 08:52:14 +00009907 ctxt.info.switch_id =
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009908 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
Neerav Parikh51616012015-02-06 08:52:14 +00009909 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009910 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009911 break;
9912
9913 case I40E_VSI_VMDQ2:
9914 ctxt.pf_num = hw->pf_id;
9915 ctxt.vf_num = 0;
9916 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009917 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009918 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
9919
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009920 /* This VSI is connected to VEB so the switch_id
9921 * should be set to zero by default.
9922 */
Neerav Parikh51616012015-02-06 08:52:14 +00009923 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
9924 ctxt.info.valid_sections |=
9925 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9926 ctxt.info.switch_id =
9927 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9928 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009929
9930 /* Setup the VSI tx/rx queue map for TC0 only for now */
9931 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9932 break;
9933
9934 case I40E_VSI_SRIOV:
9935 ctxt.pf_num = hw->pf_id;
9936 ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
9937 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009938 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009939 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
9940
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009941 /* This VSI is connected to VEB so the switch_id
9942 * should be set to zero by default.
9943 */
Neerav Parikh51616012015-02-06 08:52:14 +00009944 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
9945 ctxt.info.valid_sections |=
9946 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9947 ctxt.info.switch_id =
9948 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9949 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009950
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06009951 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
9952 ctxt.info.valid_sections |=
9953 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
9954 ctxt.info.queueing_opt_flags |=
Ashish Shah4b28cdb2016-05-03 15:13:17 -07009955 (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
9956 I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06009957 }
9958
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009959 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
9960 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
Mitch Williamsc674d122014-05-20 08:01:40 +00009961 if (pf->vf[vsi->vf_id].spoofchk) {
9962 ctxt.info.valid_sections |=
9963 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
9964 ctxt.info.sec_flags |=
9965 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
9966 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
9967 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009968 /* Setup the VSI tx/rx queue map for TC0 only for now */
9969 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9970 break;
9971
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06009972 case I40E_VSI_IWARP:
9973 /* send down message to iWARP */
9974 break;
9975
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009976 default:
9977 return -ENODEV;
9978 }
9979
9980 if (vsi->type != I40E_VSI_MAIN) {
9981 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
9982 if (ret) {
9983 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009984 "add vsi failed, err %s aq_err %s\n",
9985 i40e_stat_str(&pf->hw, ret),
9986 i40e_aq_str(&pf->hw,
9987 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009988 ret = -ENOENT;
9989 goto err;
9990 }
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07009991 vsi->info = ctxt.info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009992 vsi->info.valid_sections = 0;
9993 vsi->seid = ctxt.seid;
9994 vsi->id = ctxt.vsi_number;
9995 }
9996
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07009997 vsi->active_filters = 0;
Jacob Keller0da36b92017-04-19 09:25:55 -04009998 clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
Jacob Keller278e7d02016-10-05 09:30:37 -07009999 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010000 /* If macvlan filters already exist, force them to get loaded */
Jacob Keller278e7d02016-10-05 09:30:37 -070010001 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -070010002 f->state = I40E_FILTER_NEW;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010003 f_count++;
10004 }
Jacob Keller278e7d02016-10-05 09:30:37 -070010005 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -040010006
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010007 if (f_count) {
10008 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
10009 pf->flags |= I40E_FLAG_FILTER_SYNC;
10010 }
10011
10012 /* Update VSI BW information */
10013 ret = i40e_vsi_get_bw_info(vsi);
10014 if (ret) {
10015 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010016 "couldn't get vsi bw info, err %s aq_err %s\n",
10017 i40e_stat_str(&pf->hw, ret),
10018 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010019 /* VSI is already added so not tearing that up */
10020 ret = 0;
10021 }
10022
10023err:
10024 return ret;
10025}
10026
10027/**
10028 * i40e_vsi_release - Delete a VSI and free its resources
10029 * @vsi: the VSI being removed
10030 *
10031 * Returns 0 on success or < 0 on error
10032 **/
10033int i40e_vsi_release(struct i40e_vsi *vsi)
10034{
Jacob Keller278e7d02016-10-05 09:30:37 -070010035 struct i40e_mac_filter *f;
10036 struct hlist_node *h;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010037 struct i40e_veb *veb = NULL;
10038 struct i40e_pf *pf;
10039 u16 uplink_seid;
Jacob Keller278e7d02016-10-05 09:30:37 -070010040 int i, n, bkt;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010041
10042 pf = vsi->back;
10043
10044 /* release of a VEB-owner or last VSI is not allowed */
10045 if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
10046 dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
10047 vsi->seid, vsi->uplink_seid);
10048 return -ENODEV;
10049 }
10050 if (vsi == pf->vsi[pf->lan_vsi] &&
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030010051 !test_bit(__I40E_DOWN, pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010052 dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
10053 return -ENODEV;
10054 }
10055
10056 uplink_seid = vsi->uplink_seid;
10057 if (vsi->type != I40E_VSI_SRIOV) {
10058 if (vsi->netdev_registered) {
10059 vsi->netdev_registered = false;
10060 if (vsi->netdev) {
10061 /* results in a call to i40e_close() */
10062 unregister_netdev(vsi->netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010063 }
10064 } else {
Shannon Nelson90ef8d42014-03-14 07:32:26 +000010065 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010066 }
10067 i40e_vsi_disable_irq(vsi);
10068 }
10069
Jacob Keller278e7d02016-10-05 09:30:37 -070010070 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller6622f5c2016-10-05 09:30:32 -070010071
10072 /* clear the sync flag on all filters */
10073 if (vsi->netdev) {
10074 __dev_uc_unsync(vsi->netdev, NULL);
10075 __dev_mc_unsync(vsi->netdev, NULL);
10076 }
10077
10078 /* make sure any remaining filters are marked for deletion */
Jacob Keller278e7d02016-10-05 09:30:37 -070010079 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
Jacob Keller290d2552016-10-05 09:30:36 -070010080 __i40e_del_filter(vsi, f);
Jacob Keller6622f5c2016-10-05 09:30:32 -070010081
Jacob Keller278e7d02016-10-05 09:30:37 -070010082 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -040010083
Jesse Brandeburg17652c62015-11-05 17:01:02 -080010084 i40e_sync_vsi_filters(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010085
10086 i40e_vsi_delete(vsi);
10087 i40e_vsi_free_q_vectors(vsi);
Shannon Nelsona4866592014-02-11 08:24:07 +000010088 if (vsi->netdev) {
10089 free_netdev(vsi->netdev);
10090 vsi->netdev = NULL;
10091 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010092 i40e_vsi_clear_rings(vsi);
10093 i40e_vsi_clear(vsi);
10094
10095 /* If this was the last thing on the VEB, except for the
10096 * controlling VSI, remove the VEB, which puts the controlling
10097 * VSI onto the next level down in the switch.
10098 *
10099 * Well, okay, there's one more exception here: don't remove
10100 * the orphan VEBs yet. We'll wait for an explicit remove request
10101 * from up the network stack.
10102 */
Mitch Williams505682c2014-05-20 08:01:37 +000010103 for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010104 if (pf->vsi[i] &&
10105 pf->vsi[i]->uplink_seid == uplink_seid &&
10106 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
10107 n++; /* count the VSIs */
10108 }
10109 }
10110 for (i = 0; i < I40E_MAX_VEB; i++) {
10111 if (!pf->veb[i])
10112 continue;
10113 if (pf->veb[i]->uplink_seid == uplink_seid)
10114 n++; /* count the VEBs */
10115 if (pf->veb[i]->seid == uplink_seid)
10116 veb = pf->veb[i];
10117 }
10118 if (n == 0 && veb && veb->uplink_seid != 0)
10119 i40e_veb_release(veb);
10120
10121 return 0;
10122}
10123
10124/**
10125 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
10126 * @vsi: ptr to the VSI
10127 *
10128 * This should only be called after i40e_vsi_mem_alloc() which allocates the
10129 * corresponding SW VSI structure and initializes num_queue_pairs for the
10130 * newly allocated VSI.
10131 *
10132 * Returns 0 on success or negative on failure
10133 **/
10134static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
10135{
10136 int ret = -ENOENT;
10137 struct i40e_pf *pf = vsi->back;
10138
Alexander Duyck493fb302013-09-28 07:01:44 +000010139 if (vsi->q_vectors[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010140 dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
10141 vsi->seid);
10142 return -EEXIST;
10143 }
10144
10145 if (vsi->base_vector) {
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +000010146 dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010147 vsi->seid, vsi->base_vector);
10148 return -EEXIST;
10149 }
10150
Greg Rose90e04072014-03-06 08:59:57 +000010151 ret = i40e_vsi_alloc_q_vectors(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010152 if (ret) {
10153 dev_info(&pf->pdev->dev,
10154 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
10155 vsi->num_q_vectors, vsi->seid, ret);
10156 vsi->num_q_vectors = 0;
10157 goto vector_setup_out;
10158 }
10159
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -040010160 /* In Legacy mode, we do not have to get any other vector since we
10161 * piggyback on the misc/ICR0 for queue interrupts.
10162 */
10163 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
10164 return ret;
Shannon Nelson958a3e32013-09-28 07:13:28 +000010165 if (vsi->num_q_vectors)
10166 vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
10167 vsi->num_q_vectors, vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010168 if (vsi->base_vector < 0) {
10169 dev_info(&pf->pdev->dev,
Shannon Nelson049a2be2014-10-17 03:14:50 +000010170 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
10171 vsi->num_q_vectors, vsi->seid, vsi->base_vector);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010172 i40e_vsi_free_q_vectors(vsi);
10173 ret = -ENOENT;
10174 goto vector_setup_out;
10175 }
10176
10177vector_setup_out:
10178 return ret;
10179}
10180
10181/**
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010182 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
10183 * @vsi: pointer to the vsi.
10184 *
10185 * This re-allocates a vsi's queue resources.
10186 *
10187 * Returns pointer to the successfully allocated and configured VSI sw struct
10188 * on success, otherwise returns NULL on failure.
10189 **/
10190static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
10191{
Björn Töpel74608d12017-05-24 07:55:35 +020010192 u16 alloc_queue_pairs;
John Underwoodf5340392016-02-18 09:19:24 -080010193 struct i40e_pf *pf;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010194 u8 enabled_tc;
10195 int ret;
10196
John Underwoodf5340392016-02-18 09:19:24 -080010197 if (!vsi)
10198 return NULL;
10199
10200 pf = vsi->back;
10201
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010202 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
10203 i40e_vsi_clear_rings(vsi);
10204
10205 i40e_vsi_free_arrays(vsi, false);
10206 i40e_set_num_rings_in_vsi(vsi);
10207 ret = i40e_vsi_alloc_arrays(vsi, false);
10208 if (ret)
10209 goto err_vsi;
10210
Björn Töpel74608d12017-05-24 07:55:35 +020010211 alloc_queue_pairs = vsi->alloc_queue_pairs *
10212 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
10213
10214 ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010215 if (ret < 0) {
Shannon Nelson049a2be2014-10-17 03:14:50 +000010216 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010217 "failed to get tracking for %d queues for VSI %d err %d\n",
Björn Töpel74608d12017-05-24 07:55:35 +020010218 alloc_queue_pairs, vsi->seid, ret);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010219 goto err_vsi;
10220 }
10221 vsi->base_queue = ret;
10222
10223 /* Update the FW view of the VSI. Force a reset of TC and queue
10224 * layout configurations.
10225 */
10226 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
10227 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
10228 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
10229 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
Jacob Keller1596b5d2016-11-08 13:05:15 -080010230 if (vsi->type == I40E_VSI_MAIN)
10231 i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010232
10233 /* assign it some queues */
10234 ret = i40e_alloc_rings(vsi);
10235 if (ret)
10236 goto err_rings;
10237
10238 /* map all of the rings to the q_vectors */
10239 i40e_vsi_map_rings_to_vectors(vsi);
10240 return vsi;
10241
10242err_rings:
10243 i40e_vsi_free_q_vectors(vsi);
10244 if (vsi->netdev_registered) {
10245 vsi->netdev_registered = false;
10246 unregister_netdev(vsi->netdev);
10247 free_netdev(vsi->netdev);
10248 vsi->netdev = NULL;
10249 }
10250 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
10251err_vsi:
10252 i40e_vsi_clear(vsi);
10253 return NULL;
10254}
10255
10256/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010257 * i40e_vsi_setup - Set up a VSI by a given type
10258 * @pf: board private structure
10259 * @type: VSI type
10260 * @uplink_seid: the switch element to link to
10261 * @param1: usage depends upon VSI type. For VF types, indicates VF id
10262 *
10263 * This allocates the sw VSI structure and its queue resources, then add a VSI
10264 * to the identified VEB.
10265 *
10266 * Returns pointer to the successfully allocated and configure VSI sw struct on
10267 * success, otherwise returns NULL on failure.
10268 **/
10269struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
10270 u16 uplink_seid, u32 param1)
10271{
10272 struct i40e_vsi *vsi = NULL;
10273 struct i40e_veb *veb = NULL;
Björn Töpel74608d12017-05-24 07:55:35 +020010274 u16 alloc_queue_pairs;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010275 int ret, i;
10276 int v_idx;
10277
10278 /* The requested uplink_seid must be either
10279 * - the PF's port seid
10280 * no VEB is needed because this is the PF
10281 * or this is a Flow Director special case VSI
10282 * - seid of an existing VEB
10283 * - seid of a VSI that owns an existing VEB
10284 * - seid of a VSI that doesn't own a VEB
10285 * a new VEB is created and the VSI becomes the owner
10286 * - seid of the PF VSI, which is what creates the first VEB
10287 * this is a special case of the previous
10288 *
10289 * Find which uplink_seid we were given and create a new VEB if needed
10290 */
10291 for (i = 0; i < I40E_MAX_VEB; i++) {
10292 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
10293 veb = pf->veb[i];
10294 break;
10295 }
10296 }
10297
10298 if (!veb && uplink_seid != pf->mac_seid) {
10299
Mitch Williams505682c2014-05-20 08:01:37 +000010300 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010301 if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
10302 vsi = pf->vsi[i];
10303 break;
10304 }
10305 }
10306 if (!vsi) {
10307 dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
10308 uplink_seid);
10309 return NULL;
10310 }
10311
10312 if (vsi->uplink_seid == pf->mac_seid)
10313 veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
10314 vsi->tc_config.enabled_tc);
10315 else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
10316 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
10317 vsi->tc_config.enabled_tc);
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +000010318 if (veb) {
10319 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
10320 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040010321 "New VSI creation error, uplink seid of LAN VSI expected.\n");
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +000010322 return NULL;
10323 }
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -040010324 /* We come up by default in VEPA mode if SRIOV is not
10325 * already enabled, in which case we can't force VEPA
10326 * mode.
10327 */
10328 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
10329 veb->bridge_mode = BRIDGE_MODE_VEPA;
10330 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
10331 }
Neerav Parikh51616012015-02-06 08:52:14 +000010332 i40e_config_bridge_mode(veb);
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +000010333 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010334 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
10335 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
10336 veb = pf->veb[i];
10337 }
10338 if (!veb) {
10339 dev_info(&pf->pdev->dev, "couldn't add VEB\n");
10340 return NULL;
10341 }
10342
10343 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
10344 uplink_seid = veb->seid;
10345 }
10346
10347 /* get vsi sw struct */
10348 v_idx = i40e_vsi_mem_alloc(pf, type);
10349 if (v_idx < 0)
10350 goto err_alloc;
10351 vsi = pf->vsi[v_idx];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010352 if (!vsi)
10353 goto err_alloc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010354 vsi->type = type;
10355 vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
10356
10357 if (type == I40E_VSI_MAIN)
10358 pf->lan_vsi = v_idx;
10359 else if (type == I40E_VSI_SRIOV)
10360 vsi->vf_id = param1;
10361 /* assign it some queues */
Björn Töpel74608d12017-05-24 07:55:35 +020010362 alloc_queue_pairs = vsi->alloc_queue_pairs *
10363 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
10364
10365 ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010366 if (ret < 0) {
Shannon Nelson049a2be2014-10-17 03:14:50 +000010367 dev_info(&pf->pdev->dev,
10368 "failed to get tracking for %d queues for VSI %d err=%d\n",
Björn Töpel74608d12017-05-24 07:55:35 +020010369 alloc_queue_pairs, vsi->seid, ret);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010370 goto err_vsi;
10371 }
10372 vsi->base_queue = ret;
10373
10374 /* get a VSI from the hardware */
10375 vsi->uplink_seid = uplink_seid;
10376 ret = i40e_add_vsi(vsi);
10377 if (ret)
10378 goto err_vsi;
10379
10380 switch (vsi->type) {
10381 /* setup the netdev if needed */
10382 case I40E_VSI_MAIN:
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010383 /* Apply relevant filters if a platform-specific mac
10384 * address was selected.
10385 */
10386 if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
10387 ret = i40e_macaddr_init(vsi, pf->hw.mac.addr);
10388 if (ret) {
10389 dev_warn(&pf->pdev->dev,
10390 "could not set up macaddr; err %d\n",
10391 ret);
10392 }
10393 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010394 case I40E_VSI_VMDQ2:
10395 ret = i40e_config_netdev(vsi);
10396 if (ret)
10397 goto err_netdev;
10398 ret = register_netdev(vsi->netdev);
10399 if (ret)
10400 goto err_netdev;
10401 vsi->netdev_registered = true;
10402 netif_carrier_off(vsi->netdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080010403#ifdef CONFIG_I40E_DCB
10404 /* Setup DCB netlink interface */
10405 i40e_dcbnl_setup(vsi);
10406#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010407 /* fall through */
10408
10409 case I40E_VSI_FDIR:
10410 /* set up vectors and rings if needed */
10411 ret = i40e_vsi_setup_vectors(vsi);
10412 if (ret)
10413 goto err_msix;
10414
10415 ret = i40e_alloc_rings(vsi);
10416 if (ret)
10417 goto err_rings;
10418
10419 /* map all of the rings to the q_vectors */
10420 i40e_vsi_map_rings_to_vectors(vsi);
10421
10422 i40e_vsi_reset_stats(vsi);
10423 break;
10424
10425 default:
10426 /* no netdev or rings for the other VSI types */
10427 break;
10428 }
10429
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -040010430 if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
10431 (vsi->type == I40E_VSI_VMDQ2)) {
10432 ret = i40e_vsi_config_rss(vsi);
10433 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010434 return vsi;
10435
10436err_rings:
10437 i40e_vsi_free_q_vectors(vsi);
10438err_msix:
10439 if (vsi->netdev_registered) {
10440 vsi->netdev_registered = false;
10441 unregister_netdev(vsi->netdev);
10442 free_netdev(vsi->netdev);
10443 vsi->netdev = NULL;
10444 }
10445err_netdev:
10446 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
10447err_vsi:
10448 i40e_vsi_clear(vsi);
10449err_alloc:
10450 return NULL;
10451}
10452
10453/**
10454 * i40e_veb_get_bw_info - Query VEB BW information
10455 * @veb: the veb to query
10456 *
10457 * Query the Tx scheduler BW configuration data for given VEB
10458 **/
10459static int i40e_veb_get_bw_info(struct i40e_veb *veb)
10460{
10461 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
10462 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
10463 struct i40e_pf *pf = veb->pf;
10464 struct i40e_hw *hw = &pf->hw;
10465 u32 tc_bw_max;
10466 int ret = 0;
10467 int i;
10468
10469 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
10470 &bw_data, NULL);
10471 if (ret) {
10472 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010473 "query veb bw config failed, err %s aq_err %s\n",
10474 i40e_stat_str(&pf->hw, ret),
10475 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010476 goto out;
10477 }
10478
10479 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
10480 &ets_data, NULL);
10481 if (ret) {
10482 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010483 "query veb bw ets config failed, err %s aq_err %s\n",
10484 i40e_stat_str(&pf->hw, ret),
10485 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010486 goto out;
10487 }
10488
10489 veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
10490 veb->bw_max_quanta = ets_data.tc_bw_max;
10491 veb->is_abs_credits = bw_data.absolute_credits_enable;
Neerav Parikh23cd1f02014-11-12 00:18:41 +000010492 veb->enabled_tc = ets_data.tc_valid_bits;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010493 tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
10494 (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
10495 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10496 veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
10497 veb->bw_tc_limit_credits[i] =
10498 le16_to_cpu(bw_data.tc_bw_limits[i]);
10499 veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
10500 }
10501
10502out:
10503 return ret;
10504}
10505
10506/**
10507 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
10508 * @pf: board private structure
10509 *
10510 * On error: returns error code (negative)
10511 * On success: returns vsi index in PF (positive)
10512 **/
10513static int i40e_veb_mem_alloc(struct i40e_pf *pf)
10514{
10515 int ret = -ENOENT;
10516 struct i40e_veb *veb;
10517 int i;
10518
10519 /* Need to protect the allocation of switch elements at the PF level */
10520 mutex_lock(&pf->switch_mutex);
10521
10522 /* VEB list may be fragmented if VEB creation/destruction has
10523 * been happening. We can afford to do a quick scan to look
10524 * for any free slots in the list.
10525 *
10526 * find next empty veb slot, looping back around if necessary
10527 */
10528 i = 0;
10529 while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
10530 i++;
10531 if (i >= I40E_MAX_VEB) {
10532 ret = -ENOMEM;
10533 goto err_alloc_veb; /* out of VEB slots! */
10534 }
10535
10536 veb = kzalloc(sizeof(*veb), GFP_KERNEL);
10537 if (!veb) {
10538 ret = -ENOMEM;
10539 goto err_alloc_veb;
10540 }
10541 veb->pf = pf;
10542 veb->idx = i;
10543 veb->enabled_tc = 1;
10544
10545 pf->veb[i] = veb;
10546 ret = i;
10547err_alloc_veb:
10548 mutex_unlock(&pf->switch_mutex);
10549 return ret;
10550}
10551
10552/**
10553 * i40e_switch_branch_release - Delete a branch of the switch tree
10554 * @branch: where to start deleting
10555 *
10556 * This uses recursion to find the tips of the branch to be
10557 * removed, deleting until we get back to and can delete this VEB.
10558 **/
10559static void i40e_switch_branch_release(struct i40e_veb *branch)
10560{
10561 struct i40e_pf *pf = branch->pf;
10562 u16 branch_seid = branch->seid;
10563 u16 veb_idx = branch->idx;
10564 int i;
10565
10566 /* release any VEBs on this VEB - RECURSION */
10567 for (i = 0; i < I40E_MAX_VEB; i++) {
10568 if (!pf->veb[i])
10569 continue;
10570 if (pf->veb[i]->uplink_seid == branch->seid)
10571 i40e_switch_branch_release(pf->veb[i]);
10572 }
10573
10574 /* Release the VSIs on this VEB, but not the owner VSI.
10575 *
10576 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
10577 * the VEB itself, so don't use (*branch) after this loop.
10578 */
Mitch Williams505682c2014-05-20 08:01:37 +000010579 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010580 if (!pf->vsi[i])
10581 continue;
10582 if (pf->vsi[i]->uplink_seid == branch_seid &&
10583 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
10584 i40e_vsi_release(pf->vsi[i]);
10585 }
10586 }
10587
10588 /* There's one corner case where the VEB might not have been
10589 * removed, so double check it here and remove it if needed.
10590 * This case happens if the veb was created from the debugfs
10591 * commands and no VSIs were added to it.
10592 */
10593 if (pf->veb[veb_idx])
10594 i40e_veb_release(pf->veb[veb_idx]);
10595}
10596
10597/**
10598 * i40e_veb_clear - remove veb struct
10599 * @veb: the veb to remove
10600 **/
10601static void i40e_veb_clear(struct i40e_veb *veb)
10602{
10603 if (!veb)
10604 return;
10605
10606 if (veb->pf) {
10607 struct i40e_pf *pf = veb->pf;
10608
10609 mutex_lock(&pf->switch_mutex);
10610 if (pf->veb[veb->idx] == veb)
10611 pf->veb[veb->idx] = NULL;
10612 mutex_unlock(&pf->switch_mutex);
10613 }
10614
10615 kfree(veb);
10616}
10617
10618/**
10619 * i40e_veb_release - Delete a VEB and free its resources
10620 * @veb: the VEB being removed
10621 **/
10622void i40e_veb_release(struct i40e_veb *veb)
10623{
10624 struct i40e_vsi *vsi = NULL;
10625 struct i40e_pf *pf;
10626 int i, n = 0;
10627
10628 pf = veb->pf;
10629
10630 /* find the remaining VSI and check for extras */
Mitch Williams505682c2014-05-20 08:01:37 +000010631 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010632 if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
10633 n++;
10634 vsi = pf->vsi[i];
10635 }
10636 }
10637 if (n != 1) {
10638 dev_info(&pf->pdev->dev,
10639 "can't remove VEB %d with %d VSIs left\n",
10640 veb->seid, n);
10641 return;
10642 }
10643
10644 /* move the remaining VSI to uplink veb */
10645 vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
10646 if (veb->uplink_seid) {
10647 vsi->uplink_seid = veb->uplink_seid;
10648 if (veb->uplink_seid == pf->mac_seid)
10649 vsi->veb_idx = I40E_NO_VEB;
10650 else
10651 vsi->veb_idx = veb->veb_idx;
10652 } else {
10653 /* floating VEB */
10654 vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
10655 vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
10656 }
10657
10658 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
10659 i40e_veb_clear(veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010660}
10661
10662/**
10663 * i40e_add_veb - create the VEB in the switch
10664 * @veb: the VEB to be instantiated
10665 * @vsi: the controlling VSI
10666 **/
10667static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
10668{
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010669 struct i40e_pf *pf = veb->pf;
Shannon Nelson66fc3602016-01-13 16:51:42 -080010670 bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010671 int ret;
10672
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010673 ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
Mitch Williams5bc16032016-05-16 10:26:43 -070010674 veb->enabled_tc, false,
Shannon Nelson66fc3602016-01-13 16:51:42 -080010675 &veb->seid, enable_stats, NULL);
Mitch Williams5bc16032016-05-16 10:26:43 -070010676
10677 /* get a VEB from the hardware */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010678 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010679 dev_info(&pf->pdev->dev,
10680 "couldn't add VEB, err %s aq_err %s\n",
10681 i40e_stat_str(&pf->hw, ret),
10682 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010683 return -EPERM;
10684 }
10685
10686 /* get statistics counter */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010687 ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010688 &veb->stats_idx, NULL, NULL, NULL);
10689 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010690 dev_info(&pf->pdev->dev,
10691 "couldn't get VEB statistics idx, err %s aq_err %s\n",
10692 i40e_stat_str(&pf->hw, ret),
10693 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010694 return -EPERM;
10695 }
10696 ret = i40e_veb_get_bw_info(veb);
10697 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010698 dev_info(&pf->pdev->dev,
10699 "couldn't get VEB bw info, err %s aq_err %s\n",
10700 i40e_stat_str(&pf->hw, ret),
10701 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10702 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010703 return -ENOENT;
10704 }
10705
10706 vsi->uplink_seid = veb->seid;
10707 vsi->veb_idx = veb->idx;
10708 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
10709
10710 return 0;
10711}
10712
10713/**
10714 * i40e_veb_setup - Set up a VEB
10715 * @pf: board private structure
10716 * @flags: VEB setup flags
10717 * @uplink_seid: the switch element to link to
10718 * @vsi_seid: the initial VSI seid
10719 * @enabled_tc: Enabled TC bit-map
10720 *
10721 * This allocates the sw VEB structure and links it into the switch
10722 * It is possible and legal for this to be a duplicate of an already
10723 * existing VEB. It is also possible for both uplink and vsi seids
10724 * to be zero, in order to create a floating VEB.
10725 *
10726 * Returns pointer to the successfully allocated VEB sw struct on
10727 * success, otherwise returns NULL on failure.
10728 **/
10729struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
10730 u16 uplink_seid, u16 vsi_seid,
10731 u8 enabled_tc)
10732{
10733 struct i40e_veb *veb, *uplink_veb = NULL;
10734 int vsi_idx, veb_idx;
10735 int ret;
10736
10737 /* if one seid is 0, the other must be 0 to create a floating relay */
10738 if ((uplink_seid == 0 || vsi_seid == 0) &&
10739 (uplink_seid + vsi_seid != 0)) {
10740 dev_info(&pf->pdev->dev,
10741 "one, not both seid's are 0: uplink=%d vsi=%d\n",
10742 uplink_seid, vsi_seid);
10743 return NULL;
10744 }
10745
10746 /* make sure there is such a vsi and uplink */
Mitch Williams505682c2014-05-20 08:01:37 +000010747 for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010748 if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
10749 break;
Mitch Williams505682c2014-05-20 08:01:37 +000010750 if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010751 dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
10752 vsi_seid);
10753 return NULL;
10754 }
10755
10756 if (uplink_seid && uplink_seid != pf->mac_seid) {
10757 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
10758 if (pf->veb[veb_idx] &&
10759 pf->veb[veb_idx]->seid == uplink_seid) {
10760 uplink_veb = pf->veb[veb_idx];
10761 break;
10762 }
10763 }
10764 if (!uplink_veb) {
10765 dev_info(&pf->pdev->dev,
10766 "uplink seid %d not found\n", uplink_seid);
10767 return NULL;
10768 }
10769 }
10770
10771 /* get veb sw struct */
10772 veb_idx = i40e_veb_mem_alloc(pf);
10773 if (veb_idx < 0)
10774 goto err_alloc;
10775 veb = pf->veb[veb_idx];
10776 veb->flags = flags;
10777 veb->uplink_seid = uplink_seid;
10778 veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
10779 veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
10780
10781 /* create the VEB in the switch */
10782 ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
10783 if (ret)
10784 goto err_veb;
Shannon Nelson1bb8b932014-04-23 04:49:54 +000010785 if (vsi_idx == pf->lan_vsi)
10786 pf->lan_veb = veb->idx;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010787
10788 return veb;
10789
10790err_veb:
10791 i40e_veb_clear(veb);
10792err_alloc:
10793 return NULL;
10794}
10795
10796/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000010797 * i40e_setup_pf_switch_element - set PF vars based on switch type
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010798 * @pf: board private structure
10799 * @ele: element we are building info from
10800 * @num_reported: total number of elements
10801 * @printconfig: should we print the contents
10802 *
10803 * helper function to assist in extracting a few useful SEID values.
10804 **/
10805static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
10806 struct i40e_aqc_switch_config_element_resp *ele,
10807 u16 num_reported, bool printconfig)
10808{
10809 u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
10810 u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
10811 u8 element_type = ele->element_type;
10812 u16 seid = le16_to_cpu(ele->seid);
10813
10814 if (printconfig)
10815 dev_info(&pf->pdev->dev,
10816 "type=%d seid=%d uplink=%d downlink=%d\n",
10817 element_type, seid, uplink_seid, downlink_seid);
10818
10819 switch (element_type) {
10820 case I40E_SWITCH_ELEMENT_TYPE_MAC:
10821 pf->mac_seid = seid;
10822 break;
10823 case I40E_SWITCH_ELEMENT_TYPE_VEB:
10824 /* Main VEB? */
10825 if (uplink_seid != pf->mac_seid)
10826 break;
10827 if (pf->lan_veb == I40E_NO_VEB) {
10828 int v;
10829
10830 /* find existing or else empty VEB */
10831 for (v = 0; v < I40E_MAX_VEB; v++) {
10832 if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
10833 pf->lan_veb = v;
10834 break;
10835 }
10836 }
10837 if (pf->lan_veb == I40E_NO_VEB) {
10838 v = i40e_veb_mem_alloc(pf);
10839 if (v < 0)
10840 break;
10841 pf->lan_veb = v;
10842 }
10843 }
10844
10845 pf->veb[pf->lan_veb]->seid = seid;
10846 pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
10847 pf->veb[pf->lan_veb]->pf = pf;
10848 pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
10849 break;
10850 case I40E_SWITCH_ELEMENT_TYPE_VSI:
10851 if (num_reported != 1)
10852 break;
10853 /* This is immediately after a reset so we can assume this is
10854 * the PF's VSI
10855 */
10856 pf->mac_seid = uplink_seid;
10857 pf->pf_seid = downlink_seid;
10858 pf->main_vsi_seid = seid;
10859 if (printconfig)
10860 dev_info(&pf->pdev->dev,
10861 "pf_seid=%d main_vsi_seid=%d\n",
10862 pf->pf_seid, pf->main_vsi_seid);
10863 break;
10864 case I40E_SWITCH_ELEMENT_TYPE_PF:
10865 case I40E_SWITCH_ELEMENT_TYPE_VF:
10866 case I40E_SWITCH_ELEMENT_TYPE_EMP:
10867 case I40E_SWITCH_ELEMENT_TYPE_BMC:
10868 case I40E_SWITCH_ELEMENT_TYPE_PE:
10869 case I40E_SWITCH_ELEMENT_TYPE_PA:
10870 /* ignore these for now */
10871 break;
10872 default:
10873 dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
10874 element_type, seid);
10875 break;
10876 }
10877}
10878
10879/**
10880 * i40e_fetch_switch_configuration - Get switch config from firmware
10881 * @pf: board private structure
10882 * @printconfig: should we print the contents
10883 *
10884 * Get the current switch configuration from the device and
10885 * extract a few useful SEID values.
10886 **/
10887int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
10888{
10889 struct i40e_aqc_get_switch_config_resp *sw_config;
10890 u16 next_seid = 0;
10891 int ret = 0;
10892 u8 *aq_buf;
10893 int i;
10894
10895 aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
10896 if (!aq_buf)
10897 return -ENOMEM;
10898
10899 sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
10900 do {
10901 u16 num_reported, num_total;
10902
10903 ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
10904 I40E_AQ_LARGE_BUF,
10905 &next_seid, NULL);
10906 if (ret) {
10907 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010908 "get switch config failed err %s aq_err %s\n",
10909 i40e_stat_str(&pf->hw, ret),
10910 i40e_aq_str(&pf->hw,
10911 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010912 kfree(aq_buf);
10913 return -ENOENT;
10914 }
10915
10916 num_reported = le16_to_cpu(sw_config->header.num_reported);
10917 num_total = le16_to_cpu(sw_config->header.num_total);
10918
10919 if (printconfig)
10920 dev_info(&pf->pdev->dev,
10921 "header: %d reported %d total\n",
10922 num_reported, num_total);
10923
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010924 for (i = 0; i < num_reported; i++) {
10925 struct i40e_aqc_switch_config_element_resp *ele =
10926 &sw_config->element[i];
10927
10928 i40e_setup_pf_switch_element(pf, ele, num_reported,
10929 printconfig);
10930 }
10931 } while (next_seid != 0);
10932
10933 kfree(aq_buf);
10934 return ret;
10935}
10936
10937/**
10938 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
10939 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010940 * @reinit: if the Main VSI needs to re-initialized.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010941 *
10942 * Returns 0 on success, negative value on failure
10943 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010944static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010945{
Anjali Singhai Jainb5569892016-05-03 15:13:12 -070010946 u16 flags = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010947 int ret;
10948
10949 /* find out what's out there already */
10950 ret = i40e_fetch_switch_configuration(pf, false);
10951 if (ret) {
10952 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010953 "couldn't fetch switch config, err %s aq_err %s\n",
10954 i40e_stat_str(&pf->hw, ret),
10955 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010956 return ret;
10957 }
10958 i40e_pf_reset_stats(pf);
10959
Anjali Singhai Jainb5569892016-05-03 15:13:12 -070010960 /* set the switch config bit for the whole device to
10961 * support limited promisc or true promisc
10962 * when user requests promisc. The default is limited
10963 * promisc.
10964 */
10965
10966 if ((pf->hw.pf_id == 0) &&
10967 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
10968 flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
10969
10970 if (pf->hw.pf_id == 0) {
10971 u16 valid_flags;
10972
10973 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
10974 ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags,
10975 NULL);
10976 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
10977 dev_info(&pf->pdev->dev,
10978 "couldn't set switch config bits, err %s aq_err %s\n",
10979 i40e_stat_str(&pf->hw, ret),
10980 i40e_aq_str(&pf->hw,
10981 pf->hw.aq.asq_last_status));
10982 /* not a fatal problem, just keep going */
10983 }
10984 }
10985
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010986 /* first time setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010987 if (pf->lan_vsi == I40E_NO_VSI || reinit) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010988 struct i40e_vsi *vsi = NULL;
10989 u16 uplink_seid;
10990
10991 /* Set up the PF VSI associated with the PF's main VSI
10992 * that is already in the HW switch
10993 */
10994 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
10995 uplink_seid = pf->veb[pf->lan_veb]->seid;
10996 else
10997 uplink_seid = pf->mac_seid;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010998 if (pf->lan_vsi == I40E_NO_VSI)
10999 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
11000 else if (reinit)
11001 vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011002 if (!vsi) {
11003 dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
11004 i40e_fdir_teardown(pf);
11005 return -EAGAIN;
11006 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011007 } else {
11008 /* force a reset of TC and queue layout configurations */
11009 u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -040011010
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011011 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
11012 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
11013 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
11014 }
11015 i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
11016
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080011017 i40e_fdir_sb_setup(pf);
11018
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011019 /* Setup static PF queue filter control settings */
11020 ret = i40e_setup_pf_filter_control(pf);
11021 if (ret) {
11022 dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
11023 ret);
11024 /* Failure here should not stop continuing other steps */
11025 }
11026
11027 /* enable RSS in the HW, even for only one queue, as the stack can use
11028 * the hash
11029 */
11030 if ((pf->flags & I40E_FLAG_RSS_ENABLED))
Helin Zhang043dd652015-10-21 19:56:23 -040011031 i40e_pf_config_rss(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011032
11033 /* fill in link information and enable LSE reporting */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011034 i40e_link_event(pf);
11035
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000011036 /* Initialize user-specific link properties */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011037 pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
11038 I40E_AQ_AN_COMPLETED) ? true : false);
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000011039
Jacob Kellerbeb0dff2014-01-11 05:43:19 +000011040 i40e_ptp_init(pf);
11041
Alexander Duyck1f190d92017-04-19 09:25:51 -040011042 /* repopulate tunnel port filters */
11043 i40e_sync_udp_filters(pf);
11044
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011045 return ret;
11046}
11047
11048/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011049 * i40e_determine_queue_usage - Work out queue distribution
11050 * @pf: board private structure
11051 **/
11052static void i40e_determine_queue_usage(struct i40e_pf *pf)
11053{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011054 int queues_left;
11055
11056 pf->num_lan_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011057
11058 /* Find the max queues to be put into basic use. We'll always be
11059 * using TC0, whether or not DCB is running, and TC0 will get the
11060 * big RSS set.
11061 */
11062 queues_left = pf->hw.func_caps.num_tx_qp;
11063
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080011064 if ((queues_left == 1) ||
Frank Zhang9aa7e932014-05-20 08:01:42 +000011065 !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011066 /* one qp for PF, no queues for anything else */
11067 queues_left = 0;
Helin Zhangacd65442015-10-26 19:44:28 -040011068 pf->alloc_rss_size = pf->num_lan_qps = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011069
11070 /* make sure all the fancies are disabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080011071 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011072 I40E_FLAG_IWARP_ENABLED |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080011073 I40E_FLAG_FD_SB_ENABLED |
11074 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +000011075 I40E_FLAG_DCB_CAPABLE |
Dave Ertmana0362442016-08-29 17:38:26 -070011076 I40E_FLAG_DCB_ENABLED |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080011077 I40E_FLAG_SRIOV_ENABLED |
11078 I40E_FLAG_VMDQ_ENABLED);
Frank Zhang9aa7e932014-05-20 08:01:42 +000011079 } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
11080 I40E_FLAG_FD_SB_ENABLED |
Anjali Singhai Jainbbe7d0e2014-05-20 08:01:44 +000011081 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +000011082 I40E_FLAG_DCB_CAPABLE))) {
Frank Zhang9aa7e932014-05-20 08:01:42 +000011083 /* one qp for PF */
Helin Zhangacd65442015-10-26 19:44:28 -040011084 pf->alloc_rss_size = pf->num_lan_qps = 1;
Frank Zhang9aa7e932014-05-20 08:01:42 +000011085 queues_left -= pf->num_lan_qps;
11086
11087 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011088 I40E_FLAG_IWARP_ENABLED |
Frank Zhang9aa7e932014-05-20 08:01:42 +000011089 I40E_FLAG_FD_SB_ENABLED |
11090 I40E_FLAG_FD_ATR_ENABLED |
11091 I40E_FLAG_DCB_ENABLED |
11092 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011093 } else {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080011094 /* Not enough queues for all TCs */
Neerav Parikh4d9b6042014-05-22 06:31:51 +000011095 if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080011096 (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
Dave Ertmana0362442016-08-29 17:38:26 -070011097 pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
11098 I40E_FLAG_DCB_ENABLED);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080011099 dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
11100 }
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +000011101 pf->num_lan_qps = max_t(int, pf->rss_size_max,
11102 num_online_cpus());
11103 pf->num_lan_qps = min_t(int, pf->num_lan_qps,
11104 pf->hw.func_caps.num_tx_qp);
11105
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080011106 queues_left -= pf->num_lan_qps;
11107 }
11108
11109 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
11110 if (queues_left > 1) {
11111 queues_left -= 1; /* save 1 queue for FD */
11112 } else {
11113 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
11114 dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
11115 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011116 }
11117
11118 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
11119 pf->num_vf_qps && pf->num_req_vfs && queues_left) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080011120 pf->num_req_vfs = min_t(int, pf->num_req_vfs,
11121 (queues_left / pf->num_vf_qps));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011122 queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
11123 }
11124
11125 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
11126 pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
11127 pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
11128 (queues_left / pf->num_vmdq_qps));
11129 queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
11130 }
11131
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +000011132 pf->queues_left = queues_left;
Neerav Parikh8279e492015-09-03 17:18:50 -040011133 dev_dbg(&pf->pdev->dev,
11134 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
11135 pf->hw.func_caps.num_tx_qp,
11136 !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
Helin Zhangacd65442015-10-26 19:44:28 -040011137 pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
11138 pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
11139 queues_left);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011140}
11141
11142/**
11143 * i40e_setup_pf_filter_control - Setup PF static filter control
11144 * @pf: PF to be setup
11145 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000011146 * i40e_setup_pf_filter_control sets up a PF's initial filter control
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011147 * settings. If PE/FCoE are enabled then it will also set the per PF
11148 * based filter sizes required for them. It also enables Flow director,
11149 * ethertype and macvlan type filter settings for the pf.
11150 *
11151 * Returns 0 on success, negative on failure
11152 **/
11153static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
11154{
11155 struct i40e_filter_control_settings *settings = &pf->filter_settings;
11156
11157 settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
11158
11159 /* Flow Director is enabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080011160 if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011161 settings->enable_fdir = true;
11162
11163 /* Ethtype and MACVLAN filters enabled for PF */
11164 settings->enable_ethtype = true;
11165 settings->enable_macvlan = true;
11166
11167 if (i40e_set_filter_control(&pf->hw, settings))
11168 return -ENOENT;
11169
11170 return 0;
11171}
11172
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011173#define INFO_STRING_LEN 255
Shannon Nelson7fd89542015-10-21 19:47:04 -040011174#define REMAIN(__x) (INFO_STRING_LEN - (__x))
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011175static void i40e_print_features(struct i40e_pf *pf)
11176{
11177 struct i40e_hw *hw = &pf->hw;
Joe Perches3b195842015-12-03 04:20:57 -080011178 char *buf;
11179 int i;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011180
Joe Perches3b195842015-12-03 04:20:57 -080011181 buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
11182 if (!buf)
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011183 return;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011184
Joe Perches3b195842015-12-03 04:20:57 -080011185 i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011186#ifdef CONFIG_PCI_IOV
Joe Perches3b195842015-12-03 04:20:57 -080011187 i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011188#endif
Jesse Brandeburg1a557afc2016-04-20 19:43:37 -070011189 i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
Shannon Nelson7fd89542015-10-21 19:47:04 -040011190 pf->hw.func_caps.num_vsis,
Jesse Brandeburg1a557afc2016-04-20 19:43:37 -070011191 pf->vsi[pf->lan_vsi]->num_queue_pairs);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011192 if (pf->flags & I40E_FLAG_RSS_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080011193 i += snprintf(&buf[i], REMAIN(i), " RSS");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011194 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080011195 i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +000011196 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
Joe Perches3b195842015-12-03 04:20:57 -080011197 i += snprintf(&buf[i], REMAIN(i), " FD_SB");
11198 i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +000011199 }
Neerav Parikh4d9b6042014-05-22 06:31:51 +000011200 if (pf->flags & I40E_FLAG_DCB_CAPABLE)
Joe Perches3b195842015-12-03 04:20:57 -080011201 i += snprintf(&buf[i], REMAIN(i), " DCB");
Joe Perches3b195842015-12-03 04:20:57 -080011202 i += snprintf(&buf[i], REMAIN(i), " VxLAN");
Singhai, Anjali6a899022015-12-14 12:21:18 -080011203 i += snprintf(&buf[i], REMAIN(i), " Geneve");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011204 if (pf->flags & I40E_FLAG_PTP)
Joe Perches3b195842015-12-03 04:20:57 -080011205 i += snprintf(&buf[i], REMAIN(i), " PTP");
Shannon Nelson6dec1012015-09-28 14:12:30 -040011206 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080011207 i += snprintf(&buf[i], REMAIN(i), " VEB");
Shannon Nelson6dec1012015-09-28 14:12:30 -040011208 else
Joe Perches3b195842015-12-03 04:20:57 -080011209 i += snprintf(&buf[i], REMAIN(i), " VEPA");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011210
Joe Perches3b195842015-12-03 04:20:57 -080011211 dev_info(&pf->pdev->dev, "%s\n", buf);
11212 kfree(buf);
Shannon Nelson7fd89542015-10-21 19:47:04 -040011213 WARN_ON(i > INFO_STRING_LEN);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011214}
11215
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011216/**
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050011217 * i40e_get_platform_mac_addr - get platform-specific MAC address
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050011218 * @pdev: PCI device information struct
11219 * @pf: board private structure
11220 *
Jacob Keller41c4c2b2017-04-05 07:50:57 -040011221 * Look up the MAC address for the device. First we'll try
11222 * eth_platform_get_mac_address, which will check Open Firmware, or arch
11223 * specific fallback. Otherwise, we'll default to the stored value in
11224 * firmware.
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050011225 **/
11226static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
11227{
Jacob Keller41c4c2b2017-04-05 07:50:57 -040011228 if (eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
11229 i40e_get_mac_addr(&pf->hw, pf->hw.mac.addr);
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050011230}
11231
11232/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011233 * i40e_probe - Device initialization routine
11234 * @pdev: PCI device information struct
11235 * @ent: entry in i40e_pci_tbl
11236 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000011237 * i40e_probe initializes a PF identified by a pci_dev structure.
11238 * The OS initialization, configuring of the PF private structure,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011239 * and a hardware reset occur.
11240 *
11241 * Returns 0 on success, negative on failure
11242 **/
11243static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
11244{
Catherine Sullivane8278452015-02-06 08:52:08 +000011245 struct i40e_aq_get_phy_abilities_resp abilities;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011246 struct i40e_pf *pf;
11247 struct i40e_hw *hw;
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000011248 static u16 pfs_found;
Shannon Nelson1d5109d2015-08-26 15:14:08 -040011249 u16 wol_nvm_bits;
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011250 u16 link_status;
Jean Sacren6f66a482015-09-19 05:08:45 -060011251 int err;
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -040011252 u32 val;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000011253 u32 i;
Helin Zhang58fc3262015-10-01 14:37:38 -040011254 u8 set_fc_aq_fail;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011255
11256 err = pci_enable_device_mem(pdev);
11257 if (err)
11258 return err;
11259
11260 /* set up for high or low dma */
Mitch Williams64942942014-02-11 08:26:33 +000011261 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +000011262 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +000011263 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
11264 if (err) {
11265 dev_err(&pdev->dev,
11266 "DMA configuration failed: 0x%x\n", err);
11267 goto err_dma;
11268 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011269 }
11270
11271 /* set up pci connections */
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020011272 err = pci_request_mem_regions(pdev, i40e_driver_name);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011273 if (err) {
11274 dev_info(&pdev->dev,
11275 "pci_request_selected_regions failed %d\n", err);
11276 goto err_pci_reg;
11277 }
11278
11279 pci_enable_pcie_error_reporting(pdev);
11280 pci_set_master(pdev);
11281
11282 /* Now that we have a PCI connection, we need to do the
11283 * low level device setup. This is primarily setting up
11284 * the Admin Queue structures and then querying for the
11285 * device's current profile information.
11286 */
11287 pf = kzalloc(sizeof(*pf), GFP_KERNEL);
11288 if (!pf) {
11289 err = -ENOMEM;
11290 goto err_pf_alloc;
11291 }
11292 pf->next_vsi = 0;
11293 pf->pdev = pdev;
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030011294 set_bit(__I40E_DOWN, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011295
11296 hw = &pf->hw;
11297 hw->back = pf;
Anjali Singhai232f4702015-02-26 16:15:39 +000011298
Shannon Nelson2ac8b672015-07-23 16:54:37 -040011299 pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
11300 I40E_MAX_CSR_SPACE);
Anjali Singhai232f4702015-02-26 16:15:39 +000011301
Shannon Nelson2ac8b672015-07-23 16:54:37 -040011302 hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011303 if (!hw->hw_addr) {
11304 err = -EIO;
11305 dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
11306 (unsigned int)pci_resource_start(pdev, 0),
Shannon Nelson2ac8b672015-07-23 16:54:37 -040011307 pf->ioremap_len, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011308 goto err_ioremap;
11309 }
11310 hw->vendor_id = pdev->vendor;
11311 hw->device_id = pdev->device;
11312 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
11313 hw->subsystem_vendor_id = pdev->subsystem_vendor;
11314 hw->subsystem_device_id = pdev->subsystem_device;
11315 hw->bus.device = PCI_SLOT(pdev->devfn);
11316 hw->bus.func = PCI_FUNC(pdev->devfn);
Sudheer Mogilappagarib3f028f2017-02-09 23:58:22 -080011317 hw->bus.bus_id = pdev->bus->number;
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000011318 pf->instance = pfs_found;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011319
Jacob Keller0e588de2017-02-06 14:38:50 -080011320 INIT_LIST_HEAD(&pf->l3_flex_pit_list);
11321 INIT_LIST_HEAD(&pf->l4_flex_pit_list);
11322
Shannon Nelsonde03d2b2016-03-10 14:59:44 -080011323 /* set up the locks for the AQ, do this only once in probe
11324 * and destroy them only once in remove
11325 */
11326 mutex_init(&hw->aq.asq_mutex);
11327 mutex_init(&hw->aq.arq_mutex);
11328
Alexander Duyck5d4ca232016-09-30 08:21:46 -040011329 pf->msg_enable = netif_msg_init(debug,
11330 NETIF_MSG_DRV |
11331 NETIF_MSG_PROBE |
11332 NETIF_MSG_LINK);
11333 if (debug < -1)
11334 pf->hw.debug_mask = debug;
Shannon Nelson5b5faa42014-10-17 03:14:51 +000011335
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +000011336 /* do a special CORER for clearing PXE mode once at init */
11337 if (hw->revision_id == 0 &&
11338 (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
11339 wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
11340 i40e_flush(hw);
11341 msleep(200);
11342 pf->corer_count++;
11343
11344 i40e_clear_pxe_mode(hw);
11345 }
11346
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011347 /* Reset here to make sure all is clean and to define PF 'n' */
Shannon Nelson838d41d2014-06-04 20:41:27 +000011348 i40e_clear_hw(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011349 err = i40e_pf_reset(hw);
11350 if (err) {
11351 dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
11352 goto err_pf_reset;
11353 }
11354 pf->pfr_count++;
11355
11356 hw->aq.num_arq_entries = I40E_AQ_LEN;
11357 hw->aq.num_asq_entries = I40E_AQ_LEN;
11358 hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
11359 hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
11360 pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +000011361
Carolyn Wybornyb294ac72014-12-11 07:06:39 +000011362 snprintf(pf->int_name, sizeof(pf->int_name) - 1,
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +000011363 "%s-%s:misc",
11364 dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011365
11366 err = i40e_init_shared_code(hw);
11367 if (err) {
Anjali Singhai Jainb2a75c52015-04-27 14:57:20 -040011368 dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
11369 err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011370 goto err_pf_reset;
11371 }
11372
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000011373 /* set up a default setting for link flow control */
11374 pf->hw.fc.requested_mode = I40E_FC_NONE;
11375
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011376 err = i40e_init_adminq(hw);
Carolyn Wyborny2b2426a762015-10-26 19:44:35 -040011377 if (err) {
11378 if (err == I40E_ERR_FIRMWARE_API_VERSION)
11379 dev_info(&pdev->dev,
11380 "The driver for the device stopped because the NVM image is newer than expected. You must install the most recent version of the network driver.\n");
11381 else
11382 dev_info(&pdev->dev,
11383 "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
11384
11385 goto err_pf_reset;
11386 }
Filip Sadowski5bbb2e22017-06-07 05:43:09 -040011387 i40e_get_oem_version(hw);
Carolyn Wybornyf0b44442015-08-31 19:54:49 -040011388
Shannon Nelson6dec1012015-09-28 14:12:30 -040011389 /* provide nvm, fw, api versions */
11390 dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
11391 hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
11392 hw->aq.api_maj_ver, hw->aq.api_min_ver,
11393 i40e_nvm_version_str(hw));
Carolyn Wybornyf0b44442015-08-31 19:54:49 -040011394
Catherine Sullivan7aa67612014-07-09 07:46:17 +000011395 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
11396 hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
Shannon Nelson278b6f62014-06-04 01:41:03 +000011397 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000011398 "The driver for the device detected a newer version of the NVM image than expected. Please install the most recent version of the network driver.\n");
11399 else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
11400 hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
Shannon Nelson278b6f62014-06-04 01:41:03 +000011401 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000011402 "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
Shannon Nelson278b6f62014-06-04 01:41:03 +000011403
Shannon Nelson4eb3f762014-03-06 08:59:58 +000011404 i40e_verify_eeprom(pf);
11405
Jesse Brandeburg2c5fe332014-04-23 04:49:57 +000011406 /* Rev 0 hardware was never productized */
11407 if (hw->revision_id < 1)
11408 dev_warn(&pdev->dev, "This device is a pre-production adapter/LOM. Please be aware there may be issues with your hardware. If you are experiencing problems please contact your Intel or hardware representative who provided you with this hardware.\n");
11409
Shannon Nelson6ff4ef82013-12-21 05:44:49 +000011410 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011411 err = i40e_get_capabilities(pf);
11412 if (err)
11413 goto err_adminq_setup;
11414
11415 err = i40e_sw_init(pf);
11416 if (err) {
11417 dev_info(&pdev->dev, "sw_init failed: %d\n", err);
11418 goto err_sw_init;
11419 }
11420
11421 err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
Alexander Duyckc76cb6e2017-02-21 15:55:48 -080011422 hw->func_caps.num_rx_qp, 0, 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011423 if (err) {
11424 dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
11425 goto err_init_lan_hmc;
11426 }
11427
11428 err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
11429 if (err) {
11430 dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
11431 err = -ENOENT;
11432 goto err_configure_lan_hmc;
11433 }
11434
Neerav Parikhb686ece2014-12-14 01:55:11 +000011435 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
11436 * Ignore error return codes because if it was already disabled via
11437 * hardware settings this will fail
11438 */
Neerav Parikhf1bbad32016-01-13 16:51:39 -080011439 if (pf->flags & I40E_FLAG_STOP_FW_LLDP) {
Neerav Parikhb686ece2014-12-14 01:55:11 +000011440 dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
11441 i40e_aq_stop_lldp(hw, true, NULL);
11442 }
11443
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050011444 /* allow a platform config to override the HW addr */
11445 i40e_get_platform_mac_addr(pdev, pf);
Jacob Keller41c4c2b2017-04-05 07:50:57 -040011446
Jesse Brandeburgf62b5062013-11-28 06:39:27 +000011447 if (!is_valid_ether_addr(hw->mac.addr)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011448 dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
11449 err = -EIO;
11450 goto err_mac_addr;
11451 }
11452 dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
Greg Rose9a173902014-05-22 06:32:02 +000011453 ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
Neerav Parikh1f224ad2014-02-12 01:45:31 +000011454 i40e_get_port_mac_addr(hw, hw->mac.port_addr);
11455 if (is_valid_ether_addr(hw->mac.port_addr))
11456 pf->flags |= I40E_FLAG_PORT_ID_VALID;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011457
11458 pci_set_drvdata(pdev, pf);
11459 pci_save_state(pdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080011460#ifdef CONFIG_I40E_DCB
11461 err = i40e_init_pf_dcb(pf);
11462 if (err) {
Shannon Nelsonaebfc812014-12-11 07:06:38 +000011463 dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
David Ertmanc17ef432016-09-30 01:36:21 -070011464 pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED);
Neerav Parikh014269f2014-04-01 07:11:48 +000011465 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080011466 }
11467#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011468
11469 /* set up periodic task facility */
11470 setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
11471 pf->service_timer_period = HZ;
11472
11473 INIT_WORK(&pf->service_task, i40e_service_task);
Jacob Keller0da36b92017-04-19 09:25:55 -040011474 clear_bit(__I40E_SERVICE_SCHED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011475
Shannon Nelson1d5109d2015-08-26 15:14:08 -040011476 /* NVM bit on means WoL disabled for the port */
11477 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -080011478 if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
Shannon Nelson1d5109d2015-08-26 15:14:08 -040011479 pf->wol_en = false;
11480 else
11481 pf->wol_en = true;
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011482 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
11483
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011484 /* set up the main switch operations */
11485 i40e_determine_queue_usage(pf);
Jesse Brandeburgc11472802015-04-07 19:45:39 -040011486 err = i40e_init_interrupt_scheme(pf);
11487 if (err)
11488 goto err_switch_setup;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011489
Mitch Williams505682c2014-05-20 08:01:37 +000011490 /* The number of VSIs reported by the FW is the minimum guaranteed
11491 * to us; HW supports far more and we share the remaining pool with
11492 * the other PFs. We allocate space for more than the guarantee with
11493 * the understanding that we might not get them all later.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011494 */
Mitch Williams505682c2014-05-20 08:01:37 +000011495 if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
11496 pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
11497 else
11498 pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
11499
11500 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
Jesse Brandeburgd17038d2015-12-23 12:05:55 -080011501 pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
11502 GFP_KERNEL);
Wei Yongjuned87ac02013-09-24 05:17:25 +000011503 if (!pf->vsi) {
11504 err = -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011505 goto err_switch_setup;
Wei Yongjuned87ac02013-09-24 05:17:25 +000011506 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011507
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -040011508#ifdef CONFIG_PCI_IOV
11509 /* prep for VF support */
11510 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
11511 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
Jacob Keller0da36b92017-04-19 09:25:55 -040011512 !test_bit(__I40E_BAD_EEPROM, pf->state)) {
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -040011513 if (pci_num_vf(pdev))
11514 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
11515 }
11516#endif
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000011517 err = i40e_setup_pf_switch(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011518 if (err) {
11519 dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
11520 goto err_vsis;
11521 }
Helin Zhang58fc3262015-10-01 14:37:38 -040011522
11523 /* Make sure flow control is set according to current settings */
11524 err = i40e_set_fc(hw, &set_fc_aq_fail, true);
11525 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
11526 dev_dbg(&pf->pdev->dev,
11527 "Set fc with err %s aq_err %s on get_phy_cap\n",
11528 i40e_stat_str(hw, err),
11529 i40e_aq_str(hw, hw->aq.asq_last_status));
11530 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
11531 dev_dbg(&pf->pdev->dev,
11532 "Set fc with err %s aq_err %s on set_phy_config\n",
11533 i40e_stat_str(hw, err),
11534 i40e_aq_str(hw, hw->aq.asq_last_status));
11535 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
11536 dev_dbg(&pf->pdev->dev,
11537 "Set fc with err %s aq_err %s on get_link_info\n",
11538 i40e_stat_str(hw, err),
11539 i40e_aq_str(hw, hw->aq.asq_last_status));
11540
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000011541 /* if FDIR VSI was set up, start it now */
Mitch Williams505682c2014-05-20 08:01:37 +000011542 for (i = 0; i < pf->num_alloc_vsi; i++) {
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000011543 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
11544 i40e_vsi_open(pf->vsi[i]);
11545 break;
11546 }
11547 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011548
Shannon Nelson2f0aff42016-01-04 10:33:08 -080011549 /* The driver only wants link up/down and module qualification
11550 * reports from firmware. Note the negative logic.
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000011551 */
11552 err = i40e_aq_set_phy_int_mask(&pf->hw,
Shannon Nelson2f0aff42016-01-04 10:33:08 -080011553 ~(I40E_AQ_EVENT_LINK_UPDOWN |
Shannon Nelson867a79e2016-03-18 12:18:15 -070011554 I40E_AQ_EVENT_MEDIA_NA |
Shannon Nelson2f0aff42016-01-04 10:33:08 -080011555 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000011556 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040011557 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
11558 i40e_stat_str(&pf->hw, err),
11559 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000011560
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -040011561 /* Reconfigure hardware for allowing smaller MSS in the case
11562 * of TSO, so that we avoid the MDD being fired and causing
11563 * a reset in the case of small MSS+TSO.
11564 */
11565 val = rd32(hw, I40E_REG_MSS);
11566 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
11567 val &= ~I40E_REG_MSS_MIN_MASK;
11568 val |= I40E_64BYTE_MSS;
11569 wr32(hw, I40E_REG_MSS, val);
11570 }
11571
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -080011572 if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +000011573 msleep(75);
11574 err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
11575 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040011576 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
11577 i40e_stat_str(&pf->hw, err),
11578 i40e_aq_str(&pf->hw,
11579 pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +000011580 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011581 /* The main driver is (mostly) up and happy. We need to set this state
11582 * before setting up the misc vector or we get a race and the vector
11583 * ends up disabled forever.
11584 */
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030011585 clear_bit(__I40E_DOWN, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011586
11587 /* In case of MSIX we are going to setup the misc vector right here
11588 * to handle admin queue events etc. In case of legacy and MSI
11589 * the misc functionality and queue processing is combined in
11590 * the same vector and that gets setup at open.
11591 */
11592 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
11593 err = i40e_setup_misc_vector(pf);
11594 if (err) {
11595 dev_info(&pdev->dev,
11596 "setup of misc vector failed: %d\n", err);
11597 goto err_vsis;
11598 }
11599 }
11600
Greg Rosedf805f62014-04-04 04:43:16 +000011601#ifdef CONFIG_PCI_IOV
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011602 /* prep for VF support */
11603 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
Shannon Nelson4eb3f762014-03-06 08:59:58 +000011604 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
Jacob Keller0da36b92017-04-19 09:25:55 -040011605 !test_bit(__I40E_BAD_EEPROM, pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011606 /* disable link interrupts for VFs */
11607 val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
11608 val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
11609 wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
11610 i40e_flush(hw);
Mitch Williams4aeec012014-02-13 03:48:47 -080011611
11612 if (pci_num_vf(pdev)) {
11613 dev_info(&pdev->dev,
11614 "Active VFs found, allocating resources.\n");
11615 err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
11616 if (err)
11617 dev_info(&pdev->dev,
11618 "Error %d allocating resources for existing VFs\n",
11619 err);
11620 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011621 }
Greg Rosedf805f62014-04-04 04:43:16 +000011622#endif /* CONFIG_PCI_IOV */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011623
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011624 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11625 pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
11626 pf->num_iwarp_msix,
11627 I40E_IWARP_IRQ_PILE_ID);
11628 if (pf->iwarp_base_vector < 0) {
11629 dev_info(&pdev->dev,
11630 "failed to get tracking for %d vectors for IWARP err=%d\n",
11631 pf->num_iwarp_msix, pf->iwarp_base_vector);
11632 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
11633 }
11634 }
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000011635
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011636 i40e_dbg_pf_init(pf);
11637
11638 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +000011639 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011640
11641 /* since everything's happy, start the service_task timer */
11642 mod_timer(&pf->service_timer,
11643 round_jiffies(jiffies + pf->service_timer_period));
11644
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011645 /* add this PF to client device list and launch a client service task */
Mitch Williams004eb612017-04-04 12:40:16 -070011646 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11647 err = i40e_lan_add_device(pf);
11648 if (err)
11649 dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
11650 err);
11651 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011652
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011653#define PCI_SPEED_SIZE 8
11654#define PCI_WIDTH_SIZE 8
11655 /* Devices on the IOSF bus do not have this information
11656 * and will report PCI Gen 1 x 1 by default so don't bother
11657 * checking them.
11658 */
11659 if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) {
11660 char speed[PCI_SPEED_SIZE] = "Unknown";
11661 char width[PCI_WIDTH_SIZE] = "Unknown";
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011662
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011663 /* Get the negotiated link width and speed from PCI config
11664 * space
11665 */
11666 pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
11667 &link_status);
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011668
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011669 i40e_set_pci_config_data(hw, link_status);
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011670
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011671 switch (hw->bus.speed) {
11672 case i40e_bus_speed_8000:
11673 strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
11674 case i40e_bus_speed_5000:
11675 strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
11676 case i40e_bus_speed_2500:
11677 strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
11678 default:
11679 break;
11680 }
11681 switch (hw->bus.width) {
11682 case i40e_bus_width_pcie_x8:
11683 strncpy(width, "8", PCI_WIDTH_SIZE); break;
11684 case i40e_bus_width_pcie_x4:
11685 strncpy(width, "4", PCI_WIDTH_SIZE); break;
11686 case i40e_bus_width_pcie_x2:
11687 strncpy(width, "2", PCI_WIDTH_SIZE); break;
11688 case i40e_bus_width_pcie_x1:
11689 strncpy(width, "1", PCI_WIDTH_SIZE); break;
11690 default:
11691 break;
11692 }
11693
11694 dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
11695 speed, width);
11696
11697 if (hw->bus.width < i40e_bus_width_pcie_x8 ||
11698 hw->bus.speed < i40e_bus_speed_8000) {
11699 dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
11700 dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
11701 }
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011702 }
11703
Catherine Sullivane8278452015-02-06 08:52:08 +000011704 /* get the requested speeds from the fw */
11705 err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
11706 if (err)
Neerav Parikh8279e492015-09-03 17:18:50 -040011707 dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
11708 i40e_stat_str(&pf->hw, err),
11709 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Catherine Sullivane8278452015-02-06 08:52:08 +000011710 pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
11711
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -040011712 /* get the supported phy types from the fw */
11713 err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
11714 if (err)
11715 dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
11716 i40e_stat_str(&pf->hw, err),
11717 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -040011718
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -040011719 /* Add a filter to drop all Flow control frames from any VSI from being
11720 * transmitted. By doing so we stop a malicious VF from sending out
11721 * PAUSE or PFC frames and potentially controlling traffic for other
11722 * PF/VF VSIs.
11723 * The FW can still send Flow control frames if enabled.
11724 */
11725 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
11726 pf->main_vsi_seid);
11727
Carolyn Wyborny31b606d2016-02-17 16:12:12 -080011728 if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
Henry Tieman4f9b4302016-11-08 13:05:18 -080011729 (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
11730 pf->flags |= I40E_FLAG_PHY_CONTROLS_LEDS;
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -080011731 if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722)
11732 pf->flags |= I40E_FLAG_HAVE_CRT_RETIMER;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011733 /* print a string summarizing features */
11734 i40e_print_features(pf);
11735
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011736 return 0;
11737
11738 /* Unwind what we've done if something failed in the setup */
11739err_vsis:
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030011740 set_bit(__I40E_DOWN, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011741 i40e_clear_interrupt_scheme(pf);
11742 kfree(pf->vsi);
Shannon Nelson04b03012013-11-28 06:39:34 +000011743err_switch_setup:
11744 i40e_reset_interrupt_capability(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011745 del_timer_sync(&pf->service_timer);
11746err_mac_addr:
11747err_configure_lan_hmc:
11748 (void)i40e_shutdown_lan_hmc(hw);
11749err_init_lan_hmc:
11750 kfree(pf->qp_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011751err_sw_init:
11752err_adminq_setup:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011753err_pf_reset:
11754 iounmap(hw->hw_addr);
11755err_ioremap:
11756 kfree(pf);
11757err_pf_alloc:
11758 pci_disable_pcie_error_reporting(pdev);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020011759 pci_release_mem_regions(pdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011760err_pci_reg:
11761err_dma:
11762 pci_disable_device(pdev);
11763 return err;
11764}
11765
11766/**
11767 * i40e_remove - Device removal routine
11768 * @pdev: PCI device information struct
11769 *
11770 * i40e_remove is called by the PCI subsystem to alert the driver
11771 * that is should release a PCI device. This could be caused by a
11772 * Hot-Plug event, or because the driver is going to be removed from
11773 * memory.
11774 **/
11775static void i40e_remove(struct pci_dev *pdev)
11776{
11777 struct i40e_pf *pf = pci_get_drvdata(pdev);
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011778 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011779 i40e_status ret_code;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011780 int i;
11781
11782 i40e_dbg_pf_exit(pf);
11783
Jacob Kellerbeb0dff2014-01-11 05:43:19 +000011784 i40e_ptp_stop(pf);
11785
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011786 /* Disable RSS in hw */
Shannon Nelson272cdaf22016-02-17 16:12:21 -080011787 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
11788 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011789
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011790 /* no more scheduling of any task */
Jacob Keller0da36b92017-04-19 09:25:55 -040011791 set_bit(__I40E_SUSPENDED, pf->state);
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030011792 set_bit(__I40E_DOWN, pf->state);
Shannon Nelsonc99abb42016-03-10 14:59:45 -080011793 if (pf->service_timer.data)
11794 del_timer_sync(&pf->service_timer);
11795 if (pf->service_task.func)
11796 cancel_work_sync(&pf->service_task);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011797
Mitch Williams921c4672017-03-30 00:46:08 -070011798 /* Client close must be called explicitly here because the timer
11799 * has been stopped.
11800 */
11801 i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
11802
Mitch Williamseb2d80b2014-02-13 03:48:48 -080011803 if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
11804 i40e_free_vfs(pf);
11805 pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
11806 }
11807
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011808 i40e_fdir_teardown(pf);
11809
11810 /* If there is a switch structure or any orphans, remove them.
11811 * This will leave only the PF's VSI remaining.
11812 */
11813 for (i = 0; i < I40E_MAX_VEB; i++) {
11814 if (!pf->veb[i])
11815 continue;
11816
11817 if (pf->veb[i]->uplink_seid == pf->mac_seid ||
11818 pf->veb[i]->uplink_seid == 0)
11819 i40e_switch_branch_release(pf->veb[i]);
11820 }
11821
11822 /* Now we can shutdown the PF's VSI, just before we kill
11823 * adminq and hmc.
11824 */
11825 if (pf->vsi[pf->lan_vsi])
11826 i40e_vsi_release(pf->vsi[pf->lan_vsi]);
11827
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011828 /* remove attached clients */
Mitch Williams004eb612017-04-04 12:40:16 -070011829 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11830 ret_code = i40e_lan_del_device(pf);
11831 if (ret_code)
11832 dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
11833 ret_code);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011834 }
11835
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011836 /* shutdown and destroy the HMC */
Jesse Brandeburgf734dff2016-01-15 14:33:11 -080011837 if (hw->hmc.hmc_obj) {
11838 ret_code = i40e_shutdown_lan_hmc(hw);
Shannon Nelson60442de2014-04-23 04:50:13 +000011839 if (ret_code)
11840 dev_warn(&pdev->dev,
11841 "Failed to destroy the HMC resources: %d\n",
11842 ret_code);
11843 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011844
11845 /* shutdown the adminq */
Henry Tiemanac9c5c62016-09-06 18:05:11 -070011846 i40e_shutdown_adminq(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011847
Jesse Brandeburg8ddb3322015-11-18 15:47:06 -080011848 /* destroy the locks only once, here */
11849 mutex_destroy(&hw->aq.arq_mutex);
11850 mutex_destroy(&hw->aq.asq_mutex);
11851
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011852 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
11853 i40e_clear_interrupt_scheme(pf);
Mitch Williams505682c2014-05-20 08:01:37 +000011854 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011855 if (pf->vsi[i]) {
11856 i40e_vsi_clear_rings(pf->vsi[i]);
11857 i40e_vsi_clear(pf->vsi[i]);
11858 pf->vsi[i] = NULL;
11859 }
11860 }
11861
11862 for (i = 0; i < I40E_MAX_VEB; i++) {
11863 kfree(pf->veb[i]);
11864 pf->veb[i] = NULL;
11865 }
11866
11867 kfree(pf->qp_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011868 kfree(pf->vsi);
11869
Jesse Brandeburgf734dff2016-01-15 14:33:11 -080011870 iounmap(hw->hw_addr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011871 kfree(pf);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020011872 pci_release_mem_regions(pdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011873
11874 pci_disable_pcie_error_reporting(pdev);
11875 pci_disable_device(pdev);
11876}
11877
11878/**
11879 * i40e_pci_error_detected - warning that something funky happened in PCI land
11880 * @pdev: PCI device information struct
11881 *
11882 * Called to warn that something happened and the error handling steps
11883 * are in progress. Allows the driver to quiesce things, be ready for
11884 * remediation.
11885 **/
11886static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
11887 enum pci_channel_state error)
11888{
11889 struct i40e_pf *pf = pci_get_drvdata(pdev);
11890
11891 dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
11892
Guilherme G Piccoliedfc23ee2016-10-03 00:31:12 -070011893 if (!pf) {
11894 dev_info(&pdev->dev,
11895 "Cannot recover - error happened during device probe\n");
11896 return PCI_ERS_RESULT_DISCONNECT;
11897 }
11898
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011899 /* shutdown all operations */
Jacob Keller0da36b92017-04-19 09:25:55 -040011900 if (!test_bit(__I40E_SUSPENDED, pf->state)) {
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011901 rtnl_lock();
Maciej Sosin373149f2017-04-05 07:50:55 -040011902 i40e_prep_for_reset(pf, true);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011903 rtnl_unlock();
11904 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011905
11906 /* Request a slot reset */
11907 return PCI_ERS_RESULT_NEED_RESET;
11908}
11909
11910/**
11911 * i40e_pci_error_slot_reset - a PCI slot reset just happened
11912 * @pdev: PCI device information struct
11913 *
11914 * Called to find if the driver can work with the device now that
11915 * the pci slot has been reset. If a basic connection seems good
11916 * (registers are readable and have sane content) then return a
11917 * happy little PCI_ERS_RESULT_xxx.
11918 **/
11919static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
11920{
11921 struct i40e_pf *pf = pci_get_drvdata(pdev);
11922 pci_ers_result_t result;
11923 int err;
11924 u32 reg;
11925
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011926 dev_dbg(&pdev->dev, "%s\n", __func__);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011927 if (pci_enable_device_mem(pdev)) {
11928 dev_info(&pdev->dev,
11929 "Cannot re-enable PCI device after reset.\n");
11930 result = PCI_ERS_RESULT_DISCONNECT;
11931 } else {
11932 pci_set_master(pdev);
11933 pci_restore_state(pdev);
11934 pci_save_state(pdev);
11935 pci_wake_from_d3(pdev, false);
11936
11937 reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
11938 if (reg == 0)
11939 result = PCI_ERS_RESULT_RECOVERED;
11940 else
11941 result = PCI_ERS_RESULT_DISCONNECT;
11942 }
11943
11944 err = pci_cleanup_aer_uncorrect_error_status(pdev);
11945 if (err) {
11946 dev_info(&pdev->dev,
11947 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
11948 err);
11949 /* non-fatal, continue */
11950 }
11951
11952 return result;
11953}
11954
11955/**
11956 * i40e_pci_error_resume - restart operations after PCI error recovery
11957 * @pdev: PCI device information struct
11958 *
11959 * Called to allow the driver to bring things back up after PCI error
11960 * and/or reset recovery has finished.
11961 **/
11962static void i40e_pci_error_resume(struct pci_dev *pdev)
11963{
11964 struct i40e_pf *pf = pci_get_drvdata(pdev);
11965
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011966 dev_dbg(&pdev->dev, "%s\n", __func__);
Jacob Keller0da36b92017-04-19 09:25:55 -040011967 if (test_bit(__I40E_SUSPENDED, pf->state))
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011968 return;
11969
11970 rtnl_lock();
Maciej Sosin373149f2017-04-05 07:50:55 -040011971 i40e_handle_reset_warning(pf, true);
Vasily Averin4c4935a2015-07-08 15:04:26 +030011972 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011973}
11974
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011975/**
Joshua Hay1d680052016-12-12 15:44:08 -080011976 * i40e_enable_mc_magic_wake - enable multicast magic packet wake up
11977 * using the mac_address_write admin q function
11978 * @pf: pointer to i40e_pf struct
11979 **/
11980static void i40e_enable_mc_magic_wake(struct i40e_pf *pf)
11981{
11982 struct i40e_hw *hw = &pf->hw;
11983 i40e_status ret;
11984 u8 mac_addr[6];
11985 u16 flags = 0;
11986
11987 /* Get current MAC address in case it's an LAA */
11988 if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) {
11989 ether_addr_copy(mac_addr,
11990 pf->vsi[pf->lan_vsi]->netdev->dev_addr);
11991 } else {
11992 dev_err(&pf->pdev->dev,
11993 "Failed to retrieve MAC address; using default\n");
11994 ether_addr_copy(mac_addr, hw->mac.addr);
11995 }
11996
11997 /* The FW expects the mac address write cmd to first be called with
11998 * one of these flags before calling it again with the multicast
11999 * enable flags.
12000 */
12001 flags = I40E_AQC_WRITE_TYPE_LAA_WOL;
12002
12003 if (hw->func_caps.flex10_enable && hw->partition_id != 1)
12004 flags = I40E_AQC_WRITE_TYPE_LAA_ONLY;
12005
12006 ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
12007 if (ret) {
12008 dev_err(&pf->pdev->dev,
12009 "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up");
12010 return;
12011 }
12012
12013 flags = I40E_AQC_MC_MAG_EN
12014 | I40E_AQC_WOL_PRESERVE_ON_PFR
12015 | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG;
12016 ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
12017 if (ret)
12018 dev_err(&pf->pdev->dev,
12019 "Failed to enable Multicast Magic Packet wake up\n");
12020}
12021
12022/**
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012023 * i40e_shutdown - PCI callback for shutting down
12024 * @pdev: PCI device information struct
12025 **/
12026static void i40e_shutdown(struct pci_dev *pdev)
12027{
12028 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +000012029 struct i40e_hw *hw = &pf->hw;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012030
Jacob Keller0da36b92017-04-19 09:25:55 -040012031 set_bit(__I40E_SUSPENDED, pf->state);
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030012032 set_bit(__I40E_DOWN, pf->state);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012033 rtnl_lock();
Maciej Sosin373149f2017-04-05 07:50:55 -040012034 i40e_prep_for_reset(pf, true);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012035 rtnl_unlock();
12036
Shannon Nelson8e2773a2013-11-28 06:39:22 +000012037 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
12038 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
12039
Catherine Sullivan02b42492015-07-10 19:35:59 -040012040 del_timer_sync(&pf->service_timer);
12041 cancel_work_sync(&pf->service_task);
12042 i40e_fdir_teardown(pf);
12043
Mitch Williams921c4672017-03-30 00:46:08 -070012044 /* Client close must be called explicitly here because the timer
12045 * has been stopped.
12046 */
12047 i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
12048
Joshua Hay1d680052016-12-12 15:44:08 -080012049 if (pf->wol_en && (pf->flags & I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE))
12050 i40e_enable_mc_magic_wake(pf);
12051
Catherine Sullivan02b42492015-07-10 19:35:59 -040012052 rtnl_lock();
Maciej Sosin373149f2017-04-05 07:50:55 -040012053 i40e_prep_for_reset(pf, true);
Catherine Sullivan02b42492015-07-10 19:35:59 -040012054 rtnl_unlock();
12055
12056 wr32(hw, I40E_PFPM_APM,
12057 (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
12058 wr32(hw, I40E_PFPM_WUFC,
12059 (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
12060
Shannon Nelsone1477582015-02-21 06:44:33 +000012061 i40e_clear_interrupt_scheme(pf);
12062
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012063 if (system_state == SYSTEM_POWER_OFF) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +000012064 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012065 pci_set_power_state(pdev, PCI_D3hot);
12066 }
12067}
12068
12069#ifdef CONFIG_PM
12070/**
12071 * i40e_suspend - PCI callback for moving to D3
12072 * @pdev: PCI device information struct
12073 **/
12074static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
12075{
12076 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +000012077 struct i40e_hw *hw = &pf->hw;
Greg Rose059ff692016-05-16 10:26:38 -070012078 int retval = 0;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012079
Jacob Keller0da36b92017-04-19 09:25:55 -040012080 set_bit(__I40E_SUSPENDED, pf->state);
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030012081 set_bit(__I40E_DOWN, pf->state);
Mitch Williams3932dbf2015-03-31 00:45:04 -070012082
Joshua Hay1d680052016-12-12 15:44:08 -080012083 if (pf->wol_en && (pf->flags & I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE))
12084 i40e_enable_mc_magic_wake(pf);
12085
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012086 rtnl_lock();
Maciej Sosin373149f2017-04-05 07:50:55 -040012087 i40e_prep_for_reset(pf, true);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012088 rtnl_unlock();
12089
Shannon Nelson8e2773a2013-11-28 06:39:22 +000012090 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
12091 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
12092
Greg Roseb33d3b72016-05-16 10:26:37 -070012093 i40e_stop_misc_vector(pf);
12094
Greg Rose059ff692016-05-16 10:26:38 -070012095 retval = pci_save_state(pdev);
12096 if (retval)
12097 return retval;
12098
Shannon Nelson8e2773a2013-11-28 06:39:22 +000012099 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012100 pci_set_power_state(pdev, PCI_D3hot);
12101
Greg Rose059ff692016-05-16 10:26:38 -070012102 return retval;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012103}
12104
12105/**
12106 * i40e_resume - PCI callback for waking up from D3
12107 * @pdev: PCI device information struct
12108 **/
12109static int i40e_resume(struct pci_dev *pdev)
12110{
12111 struct i40e_pf *pf = pci_get_drvdata(pdev);
12112 u32 err;
12113
12114 pci_set_power_state(pdev, PCI_D0);
12115 pci_restore_state(pdev);
12116 /* pci_restore_state() clears dev->state_saves, so
12117 * call pci_save_state() again to restore it.
12118 */
12119 pci_save_state(pdev);
12120
12121 err = pci_enable_device_mem(pdev);
12122 if (err) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040012123 dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012124 return err;
12125 }
12126 pci_set_master(pdev);
12127
12128 /* no wakeup events while running */
12129 pci_wake_from_d3(pdev, false);
12130
12131 /* handling the reset will rebuild the device state */
Jacob Keller0da36b92017-04-19 09:25:55 -040012132 if (test_and_clear_bit(__I40E_SUSPENDED, pf->state)) {
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030012133 clear_bit(__I40E_DOWN, pf->state);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012134 rtnl_lock();
Maciej Sosin373149f2017-04-05 07:50:55 -040012135 i40e_reset_and_rebuild(pf, false, true);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012136 rtnl_unlock();
12137 }
12138
12139 return 0;
12140}
12141
12142#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000012143static const struct pci_error_handlers i40e_err_handler = {
12144 .error_detected = i40e_pci_error_detected,
12145 .slot_reset = i40e_pci_error_slot_reset,
12146 .resume = i40e_pci_error_resume,
12147};
12148
12149static struct pci_driver i40e_driver = {
12150 .name = i40e_driver_name,
12151 .id_table = i40e_pci_tbl,
12152 .probe = i40e_probe,
12153 .remove = i40e_remove,
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012154#ifdef CONFIG_PM
12155 .suspend = i40e_suspend,
12156 .resume = i40e_resume,
12157#endif
12158 .shutdown = i40e_shutdown,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000012159 .err_handler = &i40e_err_handler,
12160 .sriov_configure = i40e_pci_sriov_configure,
12161};
12162
12163/**
12164 * i40e_init_module - Driver registration routine
12165 *
12166 * i40e_init_module is the first routine called when the driver is
12167 * loaded. All it does is register with the PCI subsystem.
12168 **/
12169static int __init i40e_init_module(void)
12170{
12171 pr_info("%s: %s - version %s\n", i40e_driver_name,
12172 i40e_driver_string, i40e_driver_version_str);
12173 pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
Greg Rose96664482015-02-06 08:52:13 +000012174
Jesse Brandeburg2803b162015-12-22 14:25:08 -080012175 /* we will see if single thread per module is enough for now,
12176 * it can't be any worse than using the system workqueue which
12177 * was already single threaded
12178 */
Jacob Keller6992a6c2016-08-04 11:37:01 -070012179 i40e_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1,
12180 i40e_driver_name);
Jesse Brandeburg2803b162015-12-22 14:25:08 -080012181 if (!i40e_wq) {
12182 pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
12183 return -ENOMEM;
12184 }
12185
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000012186 i40e_dbg_init();
12187 return pci_register_driver(&i40e_driver);
12188}
12189module_init(i40e_init_module);
12190
12191/**
12192 * i40e_exit_module - Driver exit cleanup routine
12193 *
12194 * i40e_exit_module is called just before the driver is removed
12195 * from memory.
12196 **/
12197static void __exit i40e_exit_module(void)
12198{
12199 pci_unregister_driver(&i40e_driver);
Jesse Brandeburg2803b162015-12-22 14:25:08 -080012200 destroy_workqueue(i40e_wq);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000012201 i40e_dbg_exit();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000012202}
12203module_exit(i40e_exit_module);