blob: 4d1eb0c19028beaea679e486108a795508141394 [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 }
Alan Bradye5887232017-06-07 05:43:10 -04002284
2285 if ((changed_flags & IFF_PROMISC) || promisc_changed) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002286 bool cur_promisc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002287
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002288 cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
Jacob Kellerd19cb642017-04-21 13:38:05 -07002289 test_bit(__I40E_VSI_OVERFLOW_PROMISC,
Jacob Keller0da36b92017-04-19 09:25:55 -04002290 vsi->state));
Anjali Singhai Jain6784ed52016-01-15 14:33:13 -08002291 if ((vsi->type == I40E_VSI_MAIN) &&
2292 (pf->lan_veb != I40E_NO_VEB) &&
2293 !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002294 /* set defport ON for Main VSI instead of true promisc
2295 * this way we will get all unicast/multicast and VLAN
2296 * promisc behavior but will not get VF or VMDq traffic
2297 * replicated on the Main VSI.
2298 */
2299 if (pf->cur_promisc != cur_promisc) {
2300 pf->cur_promisc = cur_promisc;
Mitch Williams5bc16032016-05-16 10:26:43 -07002301 if (cur_promisc)
2302 aq_ret =
2303 i40e_aq_set_default_vsi(hw,
2304 vsi->seid,
2305 NULL);
2306 else
2307 aq_ret =
2308 i40e_aq_clear_default_vsi(hw,
2309 vsi->seid,
2310 NULL);
2311 if (aq_ret) {
2312 retval = i40e_aq_rc_to_posix(aq_ret,
2313 hw->aq.asq_last_status);
2314 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002315 "Set default VSI failed on %s, err %s, aq_err %s\n",
2316 vsi_name,
Mitch Williams5bc16032016-05-16 10:26:43 -07002317 i40e_stat_str(hw, aq_ret),
2318 i40e_aq_str(hw,
2319 hw->aq.asq_last_status));
2320 }
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002321 }
2322 } else {
Mitch Williamsea02e902015-11-09 15:35:50 -08002323 aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002324 hw,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002325 vsi->seid,
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002326 cur_promisc, NULL,
2327 true);
Mitch Williamsea02e902015-11-09 15:35:50 -08002328 if (aq_ret) {
2329 retval =
2330 i40e_aq_rc_to_posix(aq_ret,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002331 hw->aq.asq_last_status);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002332 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002333 "set unicast promisc failed on %s, err %s, aq_err %s\n",
2334 vsi_name,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002335 i40e_stat_str(hw, aq_ret),
2336 i40e_aq_str(hw,
2337 hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002338 }
2339 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002340 hw,
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002341 vsi->seid,
2342 cur_promisc, NULL);
Mitch Williamsea02e902015-11-09 15:35:50 -08002343 if (aq_ret) {
2344 retval =
2345 i40e_aq_rc_to_posix(aq_ret,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002346 hw->aq.asq_last_status);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002347 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002348 "set multicast promisc failed on %s, err %s, aq_err %s\n",
2349 vsi_name,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002350 i40e_stat_str(hw, aq_ret),
2351 i40e_aq_str(hw,
2352 hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002353 }
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002354 }
Mitch Williamsea02e902015-11-09 15:35:50 -08002355 aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
2356 vsi->seid,
2357 cur_promisc, NULL);
2358 if (aq_ret) {
2359 retval = i40e_aq_rc_to_posix(aq_ret,
2360 pf->hw.aq.asq_last_status);
Greg Rose1a103702013-11-28 06:42:39 +00002361 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002362 "set brdcast promisc failed, err %s, aq_err %s\n",
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002363 i40e_stat_str(hw, aq_ret),
2364 i40e_aq_str(hw,
2365 hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002366 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002367 }
Mitch Williamsea02e902015-11-09 15:35:50 -08002368out:
Jesse Brandeburg2818ccd2016-01-13 16:51:38 -08002369 /* if something went wrong then set the changed flag so we try again */
2370 if (retval)
2371 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
2372
Jacob Keller0da36b92017-04-19 09:25:55 -04002373 clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
Mitch Williamsea02e902015-11-09 15:35:50 -08002374 return retval;
Jacob Keller4a2ce272016-10-05 09:30:38 -07002375
2376err_no_memory:
2377 /* Restore elements on the temporary add and delete lists */
2378 spin_lock_bh(&vsi->mac_filter_hash_lock);
Alan Brady84f5ca62016-10-05 09:30:39 -07002379err_no_memory_locked:
Jacob Keller671889e2016-12-02 12:33:00 -08002380 i40e_undo_del_filter_entries(vsi, &tmp_del_list);
2381 i40e_undo_add_filter_entries(vsi, &tmp_add_list);
Jacob Keller4a2ce272016-10-05 09:30:38 -07002382 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2383
2384 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
Jacob Keller0da36b92017-04-19 09:25:55 -04002385 clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
Jacob Keller4a2ce272016-10-05 09:30:38 -07002386 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002387}
2388
2389/**
2390 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2391 * @pf: board private structure
2392 **/
2393static void i40e_sync_filters_subtask(struct i40e_pf *pf)
2394{
2395 int v;
2396
2397 if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
2398 return;
2399 pf->flags &= ~I40E_FLAG_FILTER_SYNC;
2400
Mitch Williams505682c2014-05-20 08:01:37 +00002401 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002402 if (pf->vsi[v] &&
Jesse Brandeburg17652c62015-11-05 17:01:02 -08002403 (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
2404 int ret = i40e_sync_vsi_filters(pf->vsi[v]);
2405
2406 if (ret) {
2407 /* come back and try again later */
2408 pf->flags |= I40E_FLAG_FILTER_SYNC;
2409 break;
2410 }
2411 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002412 }
2413}
2414
2415/**
Björn Töpel0c8493d2017-05-24 07:55:34 +02002416 * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
2417 * @vsi: the vsi
2418 **/
2419static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi)
2420{
2421 if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
2422 return I40E_RXBUFFER_2048;
2423 else
2424 return I40E_RXBUFFER_3072;
2425}
2426
2427/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002428 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2429 * @netdev: network interface device structure
2430 * @new_mtu: new value for maximum frame size
2431 *
2432 * Returns 0 on success, negative on failure
2433 **/
2434static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
2435{
2436 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002437 struct i40e_vsi *vsi = np->vsi;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -08002438 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002439
Björn Töpel0c8493d2017-05-24 07:55:34 +02002440 if (i40e_enabled_xdp_vsi(vsi)) {
2441 int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
2442
2443 if (frame_size > i40e_max_xdp_frame_size(vsi))
2444 return -EINVAL;
2445 }
2446
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002447 netdev_info(netdev, "changing MTU from %d to %d\n",
2448 netdev->mtu, new_mtu);
2449 netdev->mtu = new_mtu;
2450 if (netif_running(netdev))
2451 i40e_vsi_reinit_locked(vsi);
Mitch Williams0ef2d5a2017-01-24 10:24:00 -08002452 pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED |
2453 I40E_FLAG_CLIENT_L2_CHANGE);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002454 return 0;
2455}
2456
2457/**
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002458 * i40e_ioctl - Access the hwtstamp interface
2459 * @netdev: network interface device structure
2460 * @ifr: interface request data
2461 * @cmd: ioctl command
2462 **/
2463int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2464{
2465 struct i40e_netdev_priv *np = netdev_priv(netdev);
2466 struct i40e_pf *pf = np->vsi->back;
2467
2468 switch (cmd) {
2469 case SIOCGHWTSTAMP:
2470 return i40e_ptp_get_ts_config(pf, ifr);
2471 case SIOCSHWTSTAMP:
2472 return i40e_ptp_set_ts_config(pf, ifr);
2473 default:
2474 return -EOPNOTSUPP;
2475 }
2476}
2477
2478/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002479 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2480 * @vsi: the vsi being adjusted
2481 **/
2482void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
2483{
2484 struct i40e_vsi_context ctxt;
2485 i40e_status ret;
2486
2487 if ((vsi->info.valid_sections &
2488 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2489 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
2490 return; /* already enabled */
2491
2492 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2493 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2494 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
2495
2496 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002497 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002498 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2499 if (ret) {
2500 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002501 "update vlan stripping failed, err %s aq_err %s\n",
2502 i40e_stat_str(&vsi->back->hw, ret),
2503 i40e_aq_str(&vsi->back->hw,
2504 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002505 }
2506}
2507
2508/**
2509 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2510 * @vsi: the vsi being adjusted
2511 **/
2512void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
2513{
2514 struct i40e_vsi_context ctxt;
2515 i40e_status ret;
2516
2517 if ((vsi->info.valid_sections &
2518 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2519 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
2520 I40E_AQ_VSI_PVLAN_EMOD_MASK))
2521 return; /* already disabled */
2522
2523 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2524 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2525 I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
2526
2527 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002528 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002529 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2530 if (ret) {
2531 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002532 "update vlan stripping failed, err %s aq_err %s\n",
2533 i40e_stat_str(&vsi->back->hw, ret),
2534 i40e_aq_str(&vsi->back->hw,
2535 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002536 }
2537}
2538
2539/**
2540 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2541 * @netdev: network interface to be adjusted
2542 * @features: netdev features to test if VLAN offload is enabled or not
2543 **/
2544static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
2545{
2546 struct i40e_netdev_priv *np = netdev_priv(netdev);
2547 struct i40e_vsi *vsi = np->vsi;
2548
2549 if (features & NETIF_F_HW_VLAN_CTAG_RX)
2550 i40e_vlan_stripping_enable(vsi);
2551 else
2552 i40e_vlan_stripping_disable(vsi);
2553}
2554
2555/**
Jacob Keller490a4ad2016-11-11 12:39:29 -08002556 * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002557 * @vsi: the vsi being configured
2558 * @vid: vlan id to be added (0 = untagged only , -1 = any)
Jacob Keller490a4ad2016-11-11 12:39:29 -08002559 *
2560 * This is a helper function for adding a new MAC/VLAN filter with the
2561 * specified VLAN for each existing MAC address already in the hash table.
2562 * This function does *not* perform any accounting to update filters based on
2563 * VLAN mode.
2564 *
2565 * NOTE: this function expects to be called while under the
2566 * mac_filter_hash_lock
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002567 **/
Jacob Keller9af52f62016-11-11 12:39:30 -08002568int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002569{
Jacob Keller490a4ad2016-11-11 12:39:29 -08002570 struct i40e_mac_filter *f, *add_f;
Jacob Keller278e7d02016-10-05 09:30:37 -07002571 struct hlist_node *h;
2572 int bkt;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002573
Jacob Keller278e7d02016-10-05 09:30:37 -07002574 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Jacob Keller57b341d2016-10-05 09:30:35 -07002575 if (f->state == I40E_FILTER_REMOVE)
2576 continue;
Jacob Keller1bc87e82016-10-05 09:30:31 -07002577 add_f = i40e_add_filter(vsi, f->macaddr, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002578 if (!add_f) {
2579 dev_info(&vsi->back->pdev->dev,
2580 "Could not add vlan filter %d for %pM\n",
2581 vid, f->macaddr);
2582 return -ENOMEM;
2583 }
2584 }
2585
Jacob Keller490a4ad2016-11-11 12:39:29 -08002586 return 0;
2587}
2588
2589/**
2590 * i40e_vsi_add_vlan - Add VSI membership for given VLAN
2591 * @vsi: the VSI being configured
Jacob Kellerf94484b2016-12-07 14:05:34 -08002592 * @vid: VLAN id to be added
Jacob Keller490a4ad2016-11-11 12:39:29 -08002593 **/
Jacob Kellerf94484b2016-12-07 14:05:34 -08002594int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid)
Jacob Keller490a4ad2016-11-11 12:39:29 -08002595{
Jacob Keller489a3262016-11-11 12:39:31 -08002596 int err;
Jacob Keller490a4ad2016-11-11 12:39:29 -08002597
Jacob Kellerf94484b2016-12-07 14:05:34 -08002598 if (!vid || vsi->info.pvid)
2599 return -EINVAL;
2600
Jacob Keller490a4ad2016-11-11 12:39:29 -08002601 /* Locked once because all functions invoked below iterates list*/
2602 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller490a4ad2016-11-11 12:39:29 -08002603 err = i40e_add_vlan_all_mac(vsi, vid);
Jacob Keller278e7d02016-10-05 09:30:37 -07002604 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller489a3262016-11-11 12:39:31 -08002605 if (err)
2606 return err;
Kiran Patil21659032015-09-30 14:09:03 -04002607
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002608 /* schedule our worker thread which will take care of
2609 * applying the new filter changes
2610 */
2611 i40e_service_event_schedule(vsi->back);
2612 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002613}
2614
2615/**
Jacob Keller490a4ad2016-11-11 12:39:29 -08002616 * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002617 * @vsi: the vsi being configured
2618 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
Jacob Keller490a4ad2016-11-11 12:39:29 -08002619 *
2620 * This function should be used to remove all VLAN filters which match the
2621 * given VID. It does not schedule the service event and does not take the
2622 * mac_filter_hash_lock so it may be combined with other operations under
2623 * a single invocation of the mac_filter_hash_lock.
2624 *
2625 * NOTE: this function expects to be called while under the
2626 * mac_filter_hash_lock
2627 */
Jacob Keller9af52f62016-11-11 12:39:30 -08002628void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002629{
Alan Brady84f5ca62016-10-05 09:30:39 -07002630 struct i40e_mac_filter *f;
Jacob Keller278e7d02016-10-05 09:30:37 -07002631 struct hlist_node *h;
Jacob Keller278e7d02016-10-05 09:30:37 -07002632 int bkt;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002633
Jacob Keller278e7d02016-10-05 09:30:37 -07002634 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Jacob Keller290d2552016-10-05 09:30:36 -07002635 if (f->vlan == vid)
2636 __i40e_del_filter(vsi, f);
2637 }
Jacob Keller490a4ad2016-11-11 12:39:29 -08002638}
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002639
Jacob Keller490a4ad2016-11-11 12:39:29 -08002640/**
2641 * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
2642 * @vsi: the VSI being configured
Jacob Kellerf94484b2016-12-07 14:05:34 -08002643 * @vid: VLAN id to be removed
Jacob Keller490a4ad2016-11-11 12:39:29 -08002644 **/
Jacob Kellerf94484b2016-12-07 14:05:34 -08002645void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid)
Jacob Keller490a4ad2016-11-11 12:39:29 -08002646{
Jacob Kellerf94484b2016-12-07 14:05:34 -08002647 if (!vid || vsi->info.pvid)
2648 return;
2649
Jacob Keller490a4ad2016-11-11 12:39:29 -08002650 spin_lock_bh(&vsi->mac_filter_hash_lock);
2651 i40e_rm_vlan_all_mac(vsi, vid);
Jacob Keller278e7d02016-10-05 09:30:37 -07002652 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -04002653
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002654 /* schedule our worker thread which will take care of
2655 * applying the new filter changes
2656 */
2657 i40e_service_event_schedule(vsi->back);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002658}
2659
2660/**
2661 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2662 * @netdev: network interface to be adjusted
2663 * @vid: vlan id to be added
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002664 *
2665 * net_device_ops implementation for adding vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002666 **/
2667static int i40e_vlan_rx_add_vid(struct net_device *netdev,
2668 __always_unused __be16 proto, u16 vid)
2669{
2670 struct i40e_netdev_priv *np = netdev_priv(netdev);
2671 struct i40e_vsi *vsi = np->vsi;
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002672 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002673
Jacob Keller6a1127852016-10-25 16:08:49 -07002674 if (vid >= VLAN_N_VID)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002675 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002676
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002677 /* If the network stack called us with vid = 0 then
2678 * it is asking to receive priority tagged packets with
2679 * vlan id 0. Our HW receives them by default when configured
2680 * to receive untagged packets so there is no need to add an
2681 * extra filter for vlan 0 tagged packets.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002682 */
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002683 if (vid)
2684 ret = i40e_vsi_add_vlan(vsi, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002685
Jacob Keller6a1127852016-10-25 16:08:49 -07002686 if (!ret)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002687 set_bit(vid, vsi->active_vlans);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002688
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002689 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002690}
2691
2692/**
2693 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2694 * @netdev: network interface to be adjusted
2695 * @vid: vlan id to be removed
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002696 *
Akeem G Abodunrinfdfd9432014-02-11 08:24:15 +00002697 * net_device_ops implementation for removing vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002698 **/
2699static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2700 __always_unused __be16 proto, u16 vid)
2701{
2702 struct i40e_netdev_priv *np = netdev_priv(netdev);
2703 struct i40e_vsi *vsi = np->vsi;
2704
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002705 /* return code is ignored as there is nothing a user
2706 * can do about failure to remove and a log message was
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002707 * already printed from the other function
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002708 */
2709 i40e_vsi_kill_vlan(vsi, vid);
2710
2711 clear_bit(vid, vsi->active_vlans);
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002712
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002713 return 0;
2714}
2715
2716/**
2717 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2718 * @vsi: the vsi being brought back up
2719 **/
2720static void i40e_restore_vlan(struct i40e_vsi *vsi)
2721{
2722 u16 vid;
2723
2724 if (!vsi->netdev)
2725 return;
2726
2727 i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
2728
2729 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
2730 i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
2731 vid);
2732}
2733
2734/**
2735 * i40e_vsi_add_pvid - Add pvid for the VSI
2736 * @vsi: the vsi being adjusted
2737 * @vid: the vlan id to set as a PVID
2738 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002739int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002740{
2741 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002742 i40e_status ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002743
2744 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2745 vsi->info.pvid = cpu_to_le16(vid);
Greg Rose6c12fcb2013-11-28 06:39:34 +00002746 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
2747 I40E_AQ_VSI_PVLAN_INSERT_PVID |
Greg Roseb774c7d2013-11-28 06:39:44 +00002748 I40E_AQ_VSI_PVLAN_EMOD_STR;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002749
2750 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002751 ctxt.info = vsi->info;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002752 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2753 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002754 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002755 "add pvid failed, err %s aq_err %s\n",
2756 i40e_stat_str(&vsi->back->hw, ret),
2757 i40e_aq_str(&vsi->back->hw,
2758 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002759 return -ENOENT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002760 }
2761
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002762 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002763}
2764
2765/**
2766 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2767 * @vsi: the vsi being adjusted
2768 *
2769 * Just use the vlan_rx_register() service to put it back to normal
2770 **/
2771void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
2772{
Greg Rose6c12fcb2013-11-28 06:39:34 +00002773 i40e_vlan_stripping_disable(vsi);
2774
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002775 vsi->info.pvid = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002776}
2777
2778/**
2779 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2780 * @vsi: ptr to the VSI
2781 *
2782 * If this function returns with an error, then it's possible one or
2783 * more of the rings is populated (while the rest are not). It is the
2784 * callers duty to clean those orphaned rings.
2785 *
2786 * Return 0 on success, negative on failure
2787 **/
2788static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
2789{
2790 int i, err = 0;
2791
2792 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002793 err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002794
Björn Töpel74608d12017-05-24 07:55:35 +02002795 if (!i40e_enabled_xdp_vsi(vsi))
2796 return err;
2797
2798 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
2799 err = i40e_setup_tx_descriptors(vsi->xdp_rings[i]);
2800
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002801 return err;
2802}
2803
2804/**
2805 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2806 * @vsi: ptr to the VSI
2807 *
2808 * Free VSI's transmit software resources
2809 **/
2810static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
2811{
2812 int i;
2813
Björn Töpel74608d12017-05-24 07:55:35 +02002814 if (vsi->tx_rings) {
2815 for (i = 0; i < vsi->num_queue_pairs; i++)
2816 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
2817 i40e_free_tx_resources(vsi->tx_rings[i]);
2818 }
Greg Rose8e9dca52013-12-18 13:45:53 +00002819
Björn Töpel74608d12017-05-24 07:55:35 +02002820 if (vsi->xdp_rings) {
2821 for (i = 0; i < vsi->num_queue_pairs; i++)
2822 if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
2823 i40e_free_tx_resources(vsi->xdp_rings[i]);
2824 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002825}
2826
2827/**
2828 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2829 * @vsi: ptr to the VSI
2830 *
2831 * If this function returns with an error, then it's possible one or
2832 * more of the rings is populated (while the rest are not). It is the
2833 * callers duty to clean those orphaned rings.
2834 *
2835 * Return 0 on success, negative on failure
2836 **/
2837static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
2838{
2839 int i, err = 0;
2840
2841 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002842 err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002843 return err;
2844}
2845
2846/**
2847 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2848 * @vsi: ptr to the VSI
2849 *
2850 * Free all receive software resources
2851 **/
2852static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
2853{
2854 int i;
2855
Greg Rose8e9dca52013-12-18 13:45:53 +00002856 if (!vsi->rx_rings)
2857 return;
2858
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002859 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002860 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002861 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002862}
2863
2864/**
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002865 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
2866 * @ring: The Tx ring to configure
2867 *
2868 * This enables/disables XPS for a given Tx descriptor ring
2869 * based on the TCs enabled for the VSI that ring belongs to.
2870 **/
2871static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
2872{
2873 struct i40e_vsi *vsi = ring->vsi;
2874 cpumask_var_t mask;
2875
Jesse Brandeburg9a660ee2015-02-26 16:13:22 +00002876 if (!ring->q_vector || !ring->netdev)
2877 return;
2878
2879 /* Single TC mode enable XPS */
2880 if (vsi->tc_config.numtc <= 1) {
2881 if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002882 netif_set_xps_queue(ring->netdev,
2883 &ring->q_vector->affinity_mask,
2884 ring->queue_index);
Jesse Brandeburg9a660ee2015-02-26 16:13:22 +00002885 } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) {
2886 /* Disable XPS to allow selection based on TC */
2887 bitmap_zero(cpumask_bits(mask), nr_cpumask_bits);
2888 netif_set_xps_queue(ring->netdev, mask, ring->queue_index);
2889 free_cpumask_var(mask);
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002890 }
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002891
2892 /* schedule our worker thread which will take care of
2893 * applying the new filter changes
2894 */
2895 i40e_service_event_schedule(vsi->back);
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002896}
2897
2898/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002899 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2900 * @ring: The Tx ring to configure
2901 *
2902 * Configure the Tx descriptor ring in the HMC context.
2903 **/
2904static int i40e_configure_tx_ring(struct i40e_ring *ring)
2905{
2906 struct i40e_vsi *vsi = ring->vsi;
2907 u16 pf_q = vsi->base_queue + ring->queue_index;
2908 struct i40e_hw *hw = &vsi->back->hw;
2909 struct i40e_hmc_obj_txq tx_ctx;
2910 i40e_status err = 0;
2911 u32 qtx_ctl = 0;
2912
2913 /* some ATR related tx ring init */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002914 if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002915 ring->atr_sample_rate = vsi->back->atr_sample_rate;
2916 ring->atr_count = 0;
2917 } else {
2918 ring->atr_sample_rate = 0;
2919 }
2920
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002921 /* configure XPS */
2922 i40e_config_xps_tx_ring(ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002923
2924 /* clear the context structure first */
2925 memset(&tx_ctx, 0, sizeof(tx_ctx));
2926
2927 tx_ctx.new_context = 1;
2928 tx_ctx.base = (ring->dma / 128);
2929 tx_ctx.qlen = ring->count;
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002930 tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
2931 I40E_FLAG_FD_ATR_ENABLED));
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002932 tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
Jesse Brandeburg1943d8b2014-02-14 02:14:40 +00002933 /* FDIR VSI tx ring can still use RS bit and writebacks */
2934 if (vsi->type != I40E_VSI_FDIR)
2935 tx_ctx.head_wb_ena = 1;
2936 tx_ctx.head_wb_addr = ring->dma +
2937 (ring->count * sizeof(struct i40e_tx_desc));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002938
2939 /* As part of VSI creation/update, FW allocates certain
2940 * Tx arbitration queue sets for each TC enabled for
2941 * the VSI. The FW returns the handles to these queue
2942 * sets as part of the response buffer to Add VSI,
2943 * Update VSI, etc. AQ commands. It is expected that
2944 * these queue set handles be associated with the Tx
2945 * queues by the driver as part of the TX queue context
2946 * initialization. This has to be done regardless of
2947 * DCB as by default everything is mapped to TC0.
2948 */
2949 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
2950 tx_ctx.rdylist_act = 0;
2951
2952 /* clear the context in the HMC */
2953 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2954 if (err) {
2955 dev_info(&vsi->back->pdev->dev,
2956 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2957 ring->queue_index, pf_q, err);
2958 return -ENOMEM;
2959 }
2960
2961 /* set the context in the HMC */
2962 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
2963 if (err) {
2964 dev_info(&vsi->back->pdev->dev,
2965 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2966 ring->queue_index, pf_q, err);
2967 return -ENOMEM;
2968 }
2969
2970 /* Now associate this queue with this PCI function */
Mitch Williams7a28d882014-10-17 03:14:52 +00002971 if (vsi->type == I40E_VSI_VMDQ2) {
Shannon Nelson9d8bf542014-01-14 00:49:50 -08002972 qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
Mitch Williams7a28d882014-10-17 03:14:52 +00002973 qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
2974 I40E_QTX_CTL_VFVM_INDX_MASK;
2975 } else {
Shannon Nelson9d8bf542014-01-14 00:49:50 -08002976 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
Mitch Williams7a28d882014-10-17 03:14:52 +00002977 }
2978
Shannon Nelson13fd9772013-09-28 07:14:19 +00002979 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
2980 I40E_QTX_CTL_PF_INDX_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002981 wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
2982 i40e_flush(hw);
2983
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002984 /* cache tail off for easier writes later */
2985 ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2986
2987 return 0;
2988}
2989
2990/**
2991 * i40e_configure_rx_ring - Configure a receive ring context
2992 * @ring: The Rx ring to configure
2993 *
2994 * Configure the Rx descriptor ring in the HMC context.
2995 **/
2996static int i40e_configure_rx_ring(struct i40e_ring *ring)
2997{
2998 struct i40e_vsi *vsi = ring->vsi;
2999 u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
3000 u16 pf_q = vsi->base_queue + ring->queue_index;
3001 struct i40e_hw *hw = &vsi->back->hw;
3002 struct i40e_hmc_obj_rxq rx_ctx;
3003 i40e_status err = 0;
3004
3005 ring->state = 0;
3006
3007 /* clear the context structure first */
3008 memset(&rx_ctx, 0, sizeof(rx_ctx));
3009
3010 ring->rx_buf_len = vsi->rx_buf_len;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003011
Alexander Duyckdab86af2017-03-14 10:15:27 -07003012 rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len,
3013 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003014
3015 rx_ctx.base = (ring->dma / 128);
3016 rx_ctx.qlen = ring->count;
3017
Jesse Brandeburgbec60fc2016-04-18 11:33:47 -07003018 /* use 32 byte descriptors */
3019 rx_ctx.dsize = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003020
Jesse Brandeburgbec60fc2016-04-18 11:33:47 -07003021 /* descriptor type is always zero
3022 * rx_ctx.dtype = 0;
3023 */
Jesse Brandeburgb32bfa172016-04-18 11:33:42 -07003024 rx_ctx.hsplit_0 = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003025
Jesse Brandeburgb32bfa172016-04-18 11:33:42 -07003026 rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003027 if (hw->revision_id == 0)
3028 rx_ctx.lrxqthresh = 0;
3029 else
3030 rx_ctx.lrxqthresh = 2;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003031 rx_ctx.crcstrip = 1;
3032 rx_ctx.l2tsel = 1;
Jesse Brandeburgc4bbac32015-09-28 11:21:48 -07003033 /* this controls whether VLAN is stripped from inner headers */
3034 rx_ctx.showiv = 0;
Catherine Sullivanacb36762014-03-06 09:02:30 +00003035 /* set the prefena field to 1 because the manual says to */
3036 rx_ctx.prefena = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003037
3038 /* clear the context in the HMC */
3039 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
3040 if (err) {
3041 dev_info(&vsi->back->pdev->dev,
3042 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3043 ring->queue_index, pf_q, err);
3044 return -ENOMEM;
3045 }
3046
3047 /* set the context in the HMC */
3048 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
3049 if (err) {
3050 dev_info(&vsi->back->pdev->dev,
3051 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3052 ring->queue_index, pf_q, err);
3053 return -ENOMEM;
3054 }
3055
Alexander Duyckca9ec082017-04-05 07:51:02 -04003056 /* configure Rx buffer alignment */
3057 if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
3058 clear_ring_build_skb_enabled(ring);
3059 else
3060 set_ring_build_skb_enabled(ring);
3061
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003062 /* cache tail for quicker writes, and clear the reg before use */
3063 ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
3064 writel(0, ring->tail);
3065
Jesse Brandeburg1a557afc2016-04-20 19:43:37 -07003066 i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003067
3068 return 0;
3069}
3070
3071/**
3072 * i40e_vsi_configure_tx - Configure the VSI for Tx
3073 * @vsi: VSI structure describing this set of rings and resources
3074 *
3075 * Configure the Tx VSI for operation.
3076 **/
3077static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
3078{
3079 int err = 0;
3080 u16 i;
3081
Alexander Duyck9f65e152013-09-28 06:00:58 +00003082 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
3083 err = i40e_configure_tx_ring(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003084
Björn Töpel74608d12017-05-24 07:55:35 +02003085 if (!i40e_enabled_xdp_vsi(vsi))
3086 return err;
3087
3088 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
3089 err = i40e_configure_tx_ring(vsi->xdp_rings[i]);
3090
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003091 return err;
3092}
3093
3094/**
3095 * i40e_vsi_configure_rx - Configure the VSI for Rx
3096 * @vsi: the VSI being configured
3097 *
3098 * Configure the Rx VSI for operation.
3099 **/
3100static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
3101{
3102 int err = 0;
3103 u16 i;
3104
Alexander Duyckdab86af2017-03-14 10:15:27 -07003105 if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) {
3106 vsi->max_frame = I40E_MAX_RXBUFFER;
3107 vsi->rx_buf_len = I40E_RXBUFFER_2048;
3108#if (PAGE_SIZE < 8192)
Alexander Duyckca9ec082017-04-05 07:51:02 -04003109 } else if (!I40E_2K_TOO_SMALL_WITH_PADDING &&
3110 (vsi->netdev->mtu <= ETH_DATA_LEN)) {
Alexander Duyckdab86af2017-03-14 10:15:27 -07003111 vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
3112 vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
3113#endif
3114 } else {
3115 vsi->max_frame = I40E_MAX_RXBUFFER;
Alexander Duyck98efd692017-04-05 07:51:01 -04003116 vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 :
3117 I40E_RXBUFFER_2048;
Alexander Duyckdab86af2017-03-14 10:15:27 -07003118 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003119
3120 /* set up individual rings */
3121 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00003122 err = i40e_configure_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003123
3124 return err;
3125}
3126
3127/**
3128 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
3129 * @vsi: ptr to the VSI
3130 **/
3131static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
3132{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00003133 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003134 u16 qoffset, qcount;
3135 int i, n;
3136
Parikh, Neeravcd238a32015-02-21 06:43:37 +00003137 if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
3138 /* Reset the TC information */
3139 for (i = 0; i < vsi->num_queue_pairs; i++) {
3140 rx_ring = vsi->rx_rings[i];
3141 tx_ring = vsi->tx_rings[i];
3142 rx_ring->dcb_tc = 0;
3143 tx_ring->dcb_tc = 0;
3144 }
3145 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003146
3147 for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04003148 if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003149 continue;
3150
3151 qoffset = vsi->tc_config.tc_info[n].qoffset;
3152 qcount = vsi->tc_config.tc_info[n].qcount;
3153 for (i = qoffset; i < (qoffset + qcount); i++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00003154 rx_ring = vsi->rx_rings[i];
3155 tx_ring = vsi->tx_rings[i];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003156 rx_ring->dcb_tc = n;
3157 tx_ring->dcb_tc = n;
3158 }
3159 }
3160}
3161
3162/**
3163 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
3164 * @vsi: ptr to the VSI
3165 **/
3166static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
3167{
3168 if (vsi->netdev)
3169 i40e_set_rx_mode(vsi->netdev);
3170}
3171
3172/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003173 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
3174 * @vsi: Pointer to the targeted VSI
3175 *
3176 * This function replays the hlist on the hw where all the SB Flow Director
3177 * filters were saved.
3178 **/
3179static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
3180{
3181 struct i40e_fdir_filter *filter;
3182 struct i40e_pf *pf = vsi->back;
3183 struct hlist_node *node;
3184
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003185 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3186 return;
3187
Jacob Keller6d069422017-02-06 14:38:44 -08003188 /* Reset FDir counters as we're replaying all existing filters */
Jacob Keller097dbf52017-02-06 14:38:46 -08003189 pf->fd_tcp4_filter_cnt = 0;
3190 pf->fd_udp4_filter_cnt = 0;
Jacob Kellerf223c872017-02-06 14:38:51 -08003191 pf->fd_sctp4_filter_cnt = 0;
Jacob Keller097dbf52017-02-06 14:38:46 -08003192 pf->fd_ip4_filter_cnt = 0;
Jacob Keller6d069422017-02-06 14:38:44 -08003193
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003194 hlist_for_each_entry_safe(filter, node,
3195 &pf->fdir_filter_list, fdir_node) {
3196 i40e_add_del_fdir(vsi, filter, true);
3197 }
3198}
3199
3200/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003201 * i40e_vsi_configure - Set up the VSI for action
3202 * @vsi: the VSI being configured
3203 **/
3204static int i40e_vsi_configure(struct i40e_vsi *vsi)
3205{
3206 int err;
3207
3208 i40e_set_vsi_rx_mode(vsi);
3209 i40e_restore_vlan(vsi);
3210 i40e_vsi_config_dcb_rings(vsi);
3211 err = i40e_vsi_configure_tx(vsi);
3212 if (!err)
3213 err = i40e_vsi_configure_rx(vsi);
3214
3215 return err;
3216}
3217
3218/**
3219 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3220 * @vsi: the VSI being configured
3221 **/
3222static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
3223{
Björn Töpel74608d12017-05-24 07:55:35 +02003224 bool has_xdp = i40e_enabled_xdp_vsi(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003225 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003226 struct i40e_hw *hw = &pf->hw;
3227 u16 vector;
3228 int i, q;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003229 u32 qp;
3230
3231 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3232 * and PFINT_LNKLSTn registers, e.g.:
3233 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3234 */
3235 qp = vsi->base_queue;
3236 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +00003237 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003238 struct i40e_q_vector *q_vector = vsi->q_vectors[i];
3239
Jesse Brandeburgee2319c2015-09-28 14:16:54 -04003240 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Kan Lianga75e8002016-02-19 09:24:04 -05003241 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003242 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3243 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
3244 q_vector->rx.itr);
Kan Lianga75e8002016-02-19 09:24:04 -05003245 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003246 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3247 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
3248 q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003249 wr32(hw, I40E_PFINT_RATEN(vector - 1),
Alan Brady1c0e6a32016-11-28 16:06:02 -08003250 i40e_intrl_usec_to_reg(vsi->int_rate_limit));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003251
3252 /* Linked list for the queuepairs assigned to this vector */
3253 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
3254 for (q = 0; q < q_vector->num_ringpairs; q++) {
Björn Töpel74608d12017-05-24 07:55:35 +02003255 u32 nextqp = has_xdp ? qp + vsi->alloc_queue_pairs : qp;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003256 u32 val;
3257
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003258 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
Björn Töpel74608d12017-05-24 07:55:35 +02003259 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3260 (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
3261 (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
3262 (I40E_QUEUE_TYPE_TX <<
3263 I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003264
3265 wr32(hw, I40E_QINT_RQCTL(qp), val);
3266
Björn Töpel74608d12017-05-24 07:55:35 +02003267 if (has_xdp) {
3268 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3269 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3270 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
3271 (qp << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
3272 (I40E_QUEUE_TYPE_TX <<
3273 I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3274
3275 wr32(hw, I40E_QINT_TQCTL(nextqp), val);
3276 }
3277
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003278 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
Björn Töpel74608d12017-05-24 07:55:35 +02003279 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3280 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
3281 ((qp + 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
3282 (I40E_QUEUE_TYPE_RX <<
3283 I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003284
3285 /* Terminate the linked list */
3286 if (q == (q_vector->num_ringpairs - 1))
Björn Töpel74608d12017-05-24 07:55:35 +02003287 val |= (I40E_QUEUE_END_OF_LIST <<
3288 I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003289
3290 wr32(hw, I40E_QINT_TQCTL(qp), val);
3291 qp++;
3292 }
3293 }
3294
3295 i40e_flush(hw);
3296}
3297
3298/**
3299 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3300 * @hw: ptr to the hardware info
3301 **/
Jacob Kellerab437b52014-12-14 01:55:08 +00003302static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003303{
Jacob Kellerab437b52014-12-14 01:55:08 +00003304 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003305 u32 val;
3306
3307 /* clear things first */
3308 wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
3309 rd32(hw, I40E_PFINT_ICR0); /* read to clear */
3310
3311 val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
3312 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
3313 I40E_PFINT_ICR0_ENA_GRST_MASK |
3314 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
3315 I40E_PFINT_ICR0_ENA_GPIO_MASK |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003316 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
3317 I40E_PFINT_ICR0_ENA_VFLR_MASK |
3318 I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3319
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003320 if (pf->flags & I40E_FLAG_IWARP_ENABLED)
3321 val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3322
Jacob Kellerab437b52014-12-14 01:55:08 +00003323 if (pf->flags & I40E_FLAG_PTP)
3324 val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
3325
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003326 wr32(hw, I40E_PFINT_ICR0_ENA, val);
3327
3328 /* SW_ITR_IDX = 0, but don't change INTENA */
Anjali Singhai Jain84ed40e2013-11-26 10:49:32 +00003329 wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
3330 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003331
3332 /* OTHER_ITR_IDX = 0 */
3333 wr32(hw, I40E_PFINT_STAT_CTL0, 0);
3334}
3335
3336/**
3337 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3338 * @vsi: the VSI being configured
3339 **/
3340static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
3341{
Björn Töpel74608d12017-05-24 07:55:35 +02003342 u32 nextqp = i40e_enabled_xdp_vsi(vsi) ? vsi->alloc_queue_pairs : 0;
Alexander Duyck493fb302013-09-28 07:01:44 +00003343 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003344 struct i40e_pf *pf = vsi->back;
3345 struct i40e_hw *hw = &pf->hw;
3346 u32 val;
3347
3348 /* set the ITR configuration */
Jesse Brandeburgee2319c2015-09-28 14:16:54 -04003349 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Kan Lianga75e8002016-02-19 09:24:04 -05003350 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003351 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3352 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
Kan Lianga75e8002016-02-19 09:24:04 -05003353 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003354 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3355 wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
3356
Jacob Kellerab437b52014-12-14 01:55:08 +00003357 i40e_enable_misc_int_causes(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003358
3359 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3360 wr32(hw, I40E_PFINT_LNKLST0, 0);
3361
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00003362 /* Associate the queue pair to the vector and enable the queue int */
Björn Töpel74608d12017-05-24 07:55:35 +02003363 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3364 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3365 (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003366 (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3367
3368 wr32(hw, I40E_QINT_RQCTL(0), val);
3369
Björn Töpel74608d12017-05-24 07:55:35 +02003370 if (i40e_enabled_xdp_vsi(vsi)) {
3371 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3372 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT)|
3373 (I40E_QUEUE_TYPE_TX
3374 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3375
3376 wr32(hw, I40E_QINT_TQCTL(nextqp), val);
3377 }
3378
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003379 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3380 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3381 (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3382
3383 wr32(hw, I40E_QINT_TQCTL(0), val);
3384 i40e_flush(hw);
3385}
3386
3387/**
Mitch Williams2ef28cf2013-11-28 06:39:32 +00003388 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3389 * @pf: board private structure
3390 **/
3391void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
3392{
3393 struct i40e_hw *hw = &pf->hw;
3394
3395 wr32(hw, I40E_PFINT_DYN_CTL0,
3396 I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
3397 i40e_flush(hw);
3398}
3399
3400/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003401 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3402 * @pf: board private structure
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003403 * @clearpba: true when all pending interrupt events should be cleared
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003404 **/
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003405void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003406{
3407 struct i40e_hw *hw = &pf->hw;
3408 u32 val;
3409
3410 val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003411 (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003412 (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
3413
3414 wr32(hw, I40E_PFINT_DYN_CTL0, val);
3415 i40e_flush(hw);
3416}
3417
3418/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003419 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3420 * @irq: interrupt number
3421 * @data: pointer to a q_vector
3422 **/
3423static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
3424{
3425 struct i40e_q_vector *q_vector = data;
3426
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003427 if (!q_vector->tx.ring && !q_vector->rx.ring)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003428 return IRQ_HANDLED;
3429
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003430 napi_schedule_irqoff(&q_vector->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003431
3432 return IRQ_HANDLED;
3433}
3434
3435/**
Alan Brady96db7762016-09-14 16:24:38 -07003436 * i40e_irq_affinity_notify - Callback for affinity changes
3437 * @notify: context as to what irq was changed
3438 * @mask: the new affinity mask
3439 *
3440 * This is a callback function used by the irq_set_affinity_notifier function
3441 * so that we may register to receive changes to the irq affinity masks.
3442 **/
3443static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
3444 const cpumask_t *mask)
3445{
3446 struct i40e_q_vector *q_vector =
3447 container_of(notify, struct i40e_q_vector, affinity_notify);
3448
3449 q_vector->affinity_mask = *mask;
3450}
3451
3452/**
3453 * i40e_irq_affinity_release - Callback for affinity notifier release
3454 * @ref: internal core kernel usage
3455 *
3456 * This is a callback function used by the irq_set_affinity_notifier function
3457 * to inform the current notification subscriber that they will no longer
3458 * receive notifications.
3459 **/
3460static void i40e_irq_affinity_release(struct kref *ref) {}
3461
3462/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003463 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3464 * @vsi: the VSI being configured
3465 * @basename: name for the vector
3466 *
3467 * Allocates MSI-X vectors and requests interrupts from the kernel.
3468 **/
3469static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
3470{
3471 int q_vectors = vsi->num_q_vectors;
3472 struct i40e_pf *pf = vsi->back;
3473 int base = vsi->base_vector;
3474 int rx_int_idx = 0;
3475 int tx_int_idx = 0;
3476 int vector, err;
Alan Brady96db7762016-09-14 16:24:38 -07003477 int irq_num;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003478
3479 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck493fb302013-09-28 07:01:44 +00003480 struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003481
Alan Brady96db7762016-09-14 16:24:38 -07003482 irq_num = pf->msix_entries[base + vector].vector;
3483
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003484 if (q_vector->tx.ring && q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003485 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3486 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
3487 tx_int_idx++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003488 } else if (q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003489 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3490 "%s-%s-%d", basename, "rx", rx_int_idx++);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003491 } else if (q_vector->tx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003492 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3493 "%s-%s-%d", basename, "tx", tx_int_idx++);
3494 } else {
3495 /* skip this unused q_vector */
3496 continue;
3497 }
Alan Brady96db7762016-09-14 16:24:38 -07003498 err = request_irq(irq_num,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003499 vsi->irq_handler,
3500 0,
3501 q_vector->name,
3502 q_vector);
3503 if (err) {
3504 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003505 "MSIX request_irq failed, error: %d\n", err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003506 goto free_queue_irqs;
3507 }
Alan Brady96db7762016-09-14 16:24:38 -07003508
3509 /* register for affinity change notifications */
3510 q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
3511 q_vector->affinity_notify.release = i40e_irq_affinity_release;
3512 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003513 /* assign the mask for this irq */
Alan Brady96db7762016-09-14 16:24:38 -07003514 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003515 }
3516
Shannon Nelson63741842014-04-23 04:50:16 +00003517 vsi->irqs_ready = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003518 return 0;
3519
3520free_queue_irqs:
3521 while (vector) {
3522 vector--;
Alan Brady96db7762016-09-14 16:24:38 -07003523 irq_num = pf->msix_entries[base + vector].vector;
3524 irq_set_affinity_notifier(irq_num, NULL);
3525 irq_set_affinity_hint(irq_num, NULL);
3526 free_irq(irq_num, &vsi->q_vectors[vector]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003527 }
3528 return err;
3529}
3530
3531/**
3532 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3533 * @vsi: the VSI being un-configured
3534 **/
3535static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
3536{
3537 struct i40e_pf *pf = vsi->back;
3538 struct i40e_hw *hw = &pf->hw;
3539 int base = vsi->base_vector;
3540 int i;
3541
Shannon Nelson2e5c26ea2017-06-07 05:43:11 -04003542 /* disable interrupt causation from each queue */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003543 for (i = 0; i < vsi->num_queue_pairs; i++) {
Shannon Nelson2e5c26ea2017-06-07 05:43:11 -04003544 u32 val;
3545
3546 val = rd32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx));
3547 val &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
3548 wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), val);
3549
3550 val = rd32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx));
3551 val &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
3552 wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), val);
3553
Björn Töpel74608d12017-05-24 07:55:35 +02003554 if (!i40e_enabled_xdp_vsi(vsi))
3555 continue;
3556 wr32(hw, I40E_QINT_TQCTL(vsi->xdp_rings[i]->reg_idx), 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003557 }
3558
Shannon Nelson2e5c26ea2017-06-07 05:43:11 -04003559 /* disable each interrupt */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003560 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3561 for (i = vsi->base_vector;
3562 i < (vsi->num_q_vectors + vsi->base_vector); i++)
3563 wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
3564
3565 i40e_flush(hw);
3566 for (i = 0; i < vsi->num_q_vectors; i++)
3567 synchronize_irq(pf->msix_entries[i + base].vector);
3568 } else {
3569 /* Legacy and MSI mode - this stops all interrupt handling */
3570 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
3571 wr32(hw, I40E_PFINT_DYN_CTL0, 0);
3572 i40e_flush(hw);
3573 synchronize_irq(pf->pdev->irq);
3574 }
3575}
3576
3577/**
3578 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3579 * @vsi: the VSI being configured
3580 **/
3581static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
3582{
3583 struct i40e_pf *pf = vsi->back;
3584 int i;
3585
3586 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
Jesse Brandeburg78455482015-07-23 16:54:41 -04003587 for (i = 0; i < vsi->num_q_vectors; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003588 i40e_irq_dynamic_enable(vsi, i);
3589 } else {
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003590 i40e_irq_dynamic_enable_icr0(pf, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003591 }
3592
Jesse Brandeburg1022cb62013-09-28 07:13:08 +00003593 i40e_flush(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003594 return 0;
3595}
3596
3597/**
3598 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3599 * @pf: board private structure
3600 **/
3601static void i40e_stop_misc_vector(struct i40e_pf *pf)
3602{
3603 /* Disable ICR 0 */
3604 wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
3605 i40e_flush(&pf->hw);
3606}
3607
3608/**
3609 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3610 * @irq: interrupt number
3611 * @data: pointer to a q_vector
3612 *
3613 * This is the handler used for all MSI/Legacy interrupts, and deals
3614 * with both queue and non-queue interrupts. This is also used in
3615 * MSIX mode to handle the non-queue interrupts.
3616 **/
3617static irqreturn_t i40e_intr(int irq, void *data)
3618{
3619 struct i40e_pf *pf = (struct i40e_pf *)data;
3620 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003621 irqreturn_t ret = IRQ_NONE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003622 u32 icr0, icr0_remaining;
3623 u32 val, ena_mask;
3624
3625 icr0 = rd32(hw, I40E_PFINT_ICR0);
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003626 ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003627
Shannon Nelson116a57d2013-09-28 07:13:59 +00003628 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3629 if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003630 goto enable_intr;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003631
Shannon Nelsoncd92e722013-11-16 10:00:44 +00003632 /* if interrupt but no bits showing, must be SWINT */
3633 if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
3634 (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
3635 pf->sw_int_count++;
3636
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003637 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
Catherine Sullivan76429842017-06-07 05:43:12 -04003638 (icr0 & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003639 ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
Carolyn Wyborny23bb6dc2016-11-08 13:05:12 -08003640 dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n");
Catherine Sullivan76429842017-06-07 05:43:12 -04003641 set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003642 }
3643
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003644 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3645 if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003646 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
3647 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003648
Anjali Singhai Jaina16ae2d2016-01-15 14:33:16 -08003649 /* We do not have a way to disarm Queue causes while leaving
3650 * interrupt enabled for all other causes, ideally
3651 * interrupt should be disabled while we are in NAPI but
3652 * this is not a performance path and napi_schedule()
3653 * can deal with rescheduling.
3654 */
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -03003655 if (!test_bit(__I40E_DOWN, pf->state))
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003656 napi_schedule_irqoff(&q_vector->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003657 }
3658
3659 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
3660 ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
Jacob Keller0da36b92017-04-19 09:25:55 -04003661 set_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08003662 i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003663 }
3664
3665 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
3666 ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
Jacob Keller0da36b92017-04-19 09:25:55 -04003667 set_bit(__I40E_MDD_EVENT_PENDING, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003668 }
3669
3670 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
3671 ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
Jacob Keller0da36b92017-04-19 09:25:55 -04003672 set_bit(__I40E_VFLR_EVENT_PENDING, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003673 }
3674
3675 if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
Jacob Keller0da36b92017-04-19 09:25:55 -04003676 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
3677 set_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003678 ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
3679 val = rd32(hw, I40E_GLGEN_RSTAT);
3680 val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
3681 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003682 if (val == I40E_RESET_CORER) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003683 pf->corer_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003684 } else if (val == I40E_RESET_GLOBR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003685 pf->globr_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003686 } else if (val == I40E_RESET_EMPR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003687 pf->empr_count++;
Jacob Keller0da36b92017-04-19 09:25:55 -04003688 set_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003689 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003690 }
3691
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003692 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
3693 icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
3694 dev_info(&pf->pdev->dev, "HMC error interrupt\n");
Anjali Singhai Jain25fc0e62015-03-31 00:45:01 -07003695 dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
3696 rd32(hw, I40E_PFHMC_ERRORINFO),
3697 rd32(hw, I40E_PFHMC_ERRORDATA));
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003698 }
3699
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003700 if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
3701 u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
3702
3703 if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
Jacob Kellercafa1fc2014-04-24 18:05:03 -07003704 icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003705 i40e_ptp_tx_hwtstamp(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003706 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003707 }
3708
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003709 /* If a critical error is pending we have no choice but to reset the
3710 * device.
3711 * Report and mask out any remaining unexpected interrupts.
3712 */
3713 icr0_remaining = icr0 & ena_mask;
3714 if (icr0_remaining) {
3715 dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
3716 icr0_remaining);
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003717 if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003718 (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
Anjali Singhai Jainc0c28972014-02-12 01:45:34 +00003719 (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003720 dev_info(&pf->pdev->dev, "device will be reset\n");
Jacob Keller0da36b92017-04-19 09:25:55 -04003721 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003722 i40e_service_event_schedule(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003723 }
3724 ena_mask &= ~icr0_remaining;
3725 }
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003726 ret = IRQ_HANDLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003727
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003728enable_intr:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003729 /* re-enable interrupt causes */
3730 wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -03003731 if (!test_bit(__I40E_DOWN, pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003732 i40e_service_event_schedule(pf);
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003733 i40e_irq_dynamic_enable_icr0(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003734 }
3735
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003736 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003737}
3738
3739/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003740 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3741 * @tx_ring: tx ring to clean
3742 * @budget: how many cleans we're allowed
3743 *
3744 * Returns true if there's any budget left (e.g. the clean is finished)
3745 **/
3746static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
3747{
3748 struct i40e_vsi *vsi = tx_ring->vsi;
3749 u16 i = tx_ring->next_to_clean;
3750 struct i40e_tx_buffer *tx_buf;
3751 struct i40e_tx_desc *tx_desc;
3752
3753 tx_buf = &tx_ring->tx_bi[i];
3754 tx_desc = I40E_TX_DESC(tx_ring, i);
3755 i -= tx_ring->count;
3756
3757 do {
3758 struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
3759
3760 /* if next_to_watch is not set then there is no work pending */
3761 if (!eop_desc)
3762 break;
3763
3764 /* prevent any other reads prior to eop_desc */
3765 read_barrier_depends();
3766
3767 /* if the descriptor isn't done, no work yet to do */
3768 if (!(eop_desc->cmd_type_offset_bsz &
3769 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
3770 break;
3771
3772 /* clear next_to_watch to prevent false hangs */
3773 tx_buf->next_to_watch = NULL;
3774
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003775 tx_desc->buffer_addr = 0;
3776 tx_desc->cmd_type_offset_bsz = 0;
3777 /* move past filter desc */
3778 tx_buf++;
3779 tx_desc++;
3780 i++;
3781 if (unlikely(!i)) {
3782 i -= tx_ring->count;
3783 tx_buf = tx_ring->tx_bi;
3784 tx_desc = I40E_TX_DESC(tx_ring, 0);
3785 }
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003786 /* unmap skb header data */
3787 dma_unmap_single(tx_ring->dev,
3788 dma_unmap_addr(tx_buf, dma),
3789 dma_unmap_len(tx_buf, len),
3790 DMA_TO_DEVICE);
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003791 if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
3792 kfree(tx_buf->raw_buf);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003793
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003794 tx_buf->raw_buf = NULL;
3795 tx_buf->tx_flags = 0;
3796 tx_buf->next_to_watch = NULL;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003797 dma_unmap_len_set(tx_buf, len, 0);
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003798 tx_desc->buffer_addr = 0;
3799 tx_desc->cmd_type_offset_bsz = 0;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003800
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003801 /* move us past the eop_desc for start of next FD desc */
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003802 tx_buf++;
3803 tx_desc++;
3804 i++;
3805 if (unlikely(!i)) {
3806 i -= tx_ring->count;
3807 tx_buf = tx_ring->tx_bi;
3808 tx_desc = I40E_TX_DESC(tx_ring, 0);
3809 }
3810
3811 /* update budget accounting */
3812 budget--;
3813 } while (likely(budget));
3814
3815 i += tx_ring->count;
3816 tx_ring->next_to_clean = i;
3817
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003818 if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
Jesse Brandeburg78455482015-07-23 16:54:41 -04003819 i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003820
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003821 return budget > 0;
3822}
3823
3824/**
3825 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3826 * @irq: interrupt number
3827 * @data: pointer to a q_vector
3828 **/
3829static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
3830{
3831 struct i40e_q_vector *q_vector = data;
3832 struct i40e_vsi *vsi;
3833
3834 if (!q_vector->tx.ring)
3835 return IRQ_HANDLED;
3836
3837 vsi = q_vector->tx.ring->vsi;
3838 i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
3839
3840 return IRQ_HANDLED;
3841}
3842
3843/**
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003844 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003845 * @vsi: the VSI being configured
3846 * @v_idx: vector index
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003847 * @qp_idx: queue pair index
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003848 **/
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04003849static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003850{
Alexander Duyck493fb302013-09-28 07:01:44 +00003851 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyck9f65e152013-09-28 06:00:58 +00003852 struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
3853 struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003854
3855 tx_ring->q_vector = q_vector;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003856 tx_ring->next = q_vector->tx.ring;
3857 q_vector->tx.ring = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003858 q_vector->tx.count++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003859
Björn Töpel74608d12017-05-24 07:55:35 +02003860 /* Place XDP Tx ring in the same q_vector ring list as regular Tx */
3861 if (i40e_enabled_xdp_vsi(vsi)) {
3862 struct i40e_ring *xdp_ring = vsi->xdp_rings[qp_idx];
3863
3864 xdp_ring->q_vector = q_vector;
3865 xdp_ring->next = q_vector->tx.ring;
3866 q_vector->tx.ring = xdp_ring;
3867 q_vector->tx.count++;
3868 }
3869
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003870 rx_ring->q_vector = q_vector;
3871 rx_ring->next = q_vector->rx.ring;
3872 q_vector->rx.ring = rx_ring;
3873 q_vector->rx.count++;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003874}
3875
3876/**
3877 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3878 * @vsi: the VSI being configured
3879 *
3880 * This function maps descriptor rings to the queue-specific vectors
3881 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3882 * one vector per queue pair, but on a constrained vector budget, we
3883 * group the queue pairs as "efficiently" as possible.
3884 **/
3885static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
3886{
3887 int qp_remaining = vsi->num_queue_pairs;
3888 int q_vectors = vsi->num_q_vectors;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003889 int num_ringpairs;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003890 int v_start = 0;
3891 int qp_idx = 0;
3892
3893 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3894 * group them so there are multiple queues per vector.
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003895 * It is also important to go through all the vectors available to be
3896 * sure that if we don't use all the vectors, that the remaining vectors
3897 * are cleared. This is especially important when decreasing the
3898 * number of queues in use.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003899 */
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003900 for (; v_start < q_vectors; v_start++) {
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003901 struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
3902
3903 num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
3904
3905 q_vector->num_ringpairs = num_ringpairs;
3906
3907 q_vector->rx.count = 0;
3908 q_vector->tx.count = 0;
3909 q_vector->rx.ring = NULL;
3910 q_vector->tx.ring = NULL;
3911
3912 while (num_ringpairs--) {
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04003913 i40e_map_vector_to_qp(vsi, v_start, qp_idx);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003914 qp_idx++;
3915 qp_remaining--;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003916 }
3917 }
3918}
3919
3920/**
3921 * i40e_vsi_request_irq - Request IRQ from the OS
3922 * @vsi: the VSI being configured
3923 * @basename: name for the vector
3924 **/
3925static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
3926{
3927 struct i40e_pf *pf = vsi->back;
3928 int err;
3929
3930 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
3931 err = i40e_vsi_request_irq_msix(vsi, basename);
3932 else if (pf->flags & I40E_FLAG_MSI_ENABLED)
3933 err = request_irq(pf->pdev->irq, i40e_intr, 0,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00003934 pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003935 else
3936 err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00003937 pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003938
3939 if (err)
3940 dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
3941
3942 return err;
3943}
3944
3945#ifdef CONFIG_NET_POLL_CONTROLLER
3946/**
Jesse Brandeburgd89d9672016-01-04 10:33:02 -08003947 * i40e_netpoll - A Polling 'interrupt' handler
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003948 * @netdev: network interface device structure
3949 *
3950 * This is used by netconsole to send skbs without having to re-enable
3951 * interrupts. It's not called while the normal interrupt routine is executing.
3952 **/
3953static void i40e_netpoll(struct net_device *netdev)
3954{
3955 struct i40e_netdev_priv *np = netdev_priv(netdev);
3956 struct i40e_vsi *vsi = np->vsi;
3957 struct i40e_pf *pf = vsi->back;
3958 int i;
3959
3960 /* if interface is down do nothing */
Jacob Keller0da36b92017-04-19 09:25:55 -04003961 if (test_bit(__I40E_VSI_DOWN, vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003962 return;
3963
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003964 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3965 for (i = 0; i < vsi->num_q_vectors; i++)
Alexander Duyck493fb302013-09-28 07:01:44 +00003966 i40e_msix_clean_rings(0, vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003967 } else {
3968 i40e_intr(pf->pdev->irq, netdev);
3969 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003970}
3971#endif
3972
Jacob Kellerc768e492017-04-13 04:45:47 -04003973#define I40E_QTX_ENA_WAIT_COUNT 50
3974
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003975/**
Neerav Parikh23527302014-06-03 23:50:15 +00003976 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3977 * @pf: the PF being configured
3978 * @pf_q: the PF queue
3979 * @enable: enable or disable state of the queue
3980 *
3981 * This routine will wait for the given Tx queue of the PF to reach the
3982 * enabled or disabled state.
3983 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3984 * multiple retries; else will return 0 in case of success.
3985 **/
3986static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3987{
3988 int i;
3989 u32 tx_reg;
3990
3991 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3992 tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
3993 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
3994 break;
3995
Neerav Parikhf98a2002014-09-13 07:40:44 +00003996 usleep_range(10, 20);
Neerav Parikh23527302014-06-03 23:50:15 +00003997 }
3998 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3999 return -ETIMEDOUT;
4000
4001 return 0;
4002}
4003
4004/**
Jacob Kellerc768e492017-04-13 04:45:47 -04004005 * i40e_control_tx_q - Start or stop a particular Tx queue
4006 * @pf: the PF structure
4007 * @pf_q: the PF queue to configure
4008 * @enable: start or stop the queue
4009 *
4010 * This function enables or disables a single queue. Note that any delay
4011 * required after the operation is expected to be handled by the caller of
4012 * this function.
4013 **/
4014static void i40e_control_tx_q(struct i40e_pf *pf, int pf_q, bool enable)
4015{
4016 struct i40e_hw *hw = &pf->hw;
4017 u32 tx_reg;
4018 int i;
4019
4020 /* warn the TX unit of coming changes */
4021 i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
4022 if (!enable)
4023 usleep_range(10, 20);
4024
4025 for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
4026 tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
4027 if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
4028 ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
4029 break;
4030 usleep_range(1000, 2000);
4031 }
4032
4033 /* Skip if the queue is already in the requested state */
4034 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
4035 return;
4036
4037 /* turn on/off the queue */
4038 if (enable) {
4039 wr32(hw, I40E_QTX_HEAD(pf_q), 0);
4040 tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
4041 } else {
4042 tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
4043 }
4044
4045 wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
4046}
4047
4048/**
Björn Töpel74608d12017-05-24 07:55:35 +02004049 * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion
4050 * @seid: VSI SEID
4051 * @pf: the PF structure
4052 * @pf_q: the PF queue to configure
4053 * @is_xdp: true if the queue is used for XDP
4054 * @enable: start or stop the queue
4055 **/
4056static int i40e_control_wait_tx_q(int seid, struct i40e_pf *pf, int pf_q,
4057 bool is_xdp, bool enable)
4058{
4059 int ret;
4060
4061 i40e_control_tx_q(pf, pf_q, enable);
4062
4063 /* wait for the change to finish */
4064 ret = i40e_pf_txq_wait(pf, pf_q, enable);
4065 if (ret) {
4066 dev_info(&pf->pdev->dev,
4067 "VSI seid %d %sTx ring %d %sable timeout\n",
4068 seid, (is_xdp ? "XDP " : ""), pf_q,
4069 (enable ? "en" : "dis"));
4070 }
4071
4072 return ret;
4073}
4074
4075/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004076 * i40e_vsi_control_tx - Start or stop a VSI's rings
4077 * @vsi: the VSI being configured
4078 * @enable: start or stop the rings
4079 **/
4080static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
4081{
4082 struct i40e_pf *pf = vsi->back;
Jacob Kellerc768e492017-04-13 04:45:47 -04004083 int i, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004084
4085 pf_q = vsi->base_queue;
4086 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Björn Töpel74608d12017-05-24 07:55:35 +02004087 ret = i40e_control_wait_tx_q(vsi->seid, pf,
4088 pf_q,
4089 false /*is xdp*/, enable);
4090 if (ret)
Neerav Parikh23527302014-06-03 23:50:15 +00004091 break;
Björn Töpel74608d12017-05-24 07:55:35 +02004092
4093 if (!i40e_enabled_xdp_vsi(vsi))
4094 continue;
4095
4096 ret = i40e_control_wait_tx_q(vsi->seid, pf,
4097 pf_q + vsi->alloc_queue_pairs,
4098 true /*is xdp*/, enable);
4099 if (ret)
4100 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004101 }
4102
Neerav Parikh23527302014-06-03 23:50:15 +00004103 return ret;
4104}
4105
4106/**
4107 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
4108 * @pf: the PF being configured
4109 * @pf_q: the PF queue
4110 * @enable: enable or disable state of the queue
4111 *
4112 * This routine will wait for the given Rx queue of the PF to reach the
4113 * enabled or disabled state.
4114 * Returns -ETIMEDOUT in case of failing to reach the requested state after
4115 * multiple retries; else will return 0 in case of success.
4116 **/
4117static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
4118{
4119 int i;
4120 u32 rx_reg;
4121
4122 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
4123 rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
4124 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
4125 break;
4126
Neerav Parikhf98a2002014-09-13 07:40:44 +00004127 usleep_range(10, 20);
Neerav Parikh23527302014-06-03 23:50:15 +00004128 }
4129 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
4130 return -ETIMEDOUT;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00004131
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004132 return 0;
4133}
4134
4135/**
Jacob Kellerc768e492017-04-13 04:45:47 -04004136 * i40e_control_rx_q - Start or stop a particular Rx queue
4137 * @pf: the PF structure
4138 * @pf_q: the PF queue to configure
4139 * @enable: start or stop the queue
4140 *
4141 * This function enables or disables a single queue. Note that any delay
4142 * required after the operation is expected to be handled by the caller of
4143 * this function.
4144 **/
4145static void i40e_control_rx_q(struct i40e_pf *pf, int pf_q, bool enable)
4146{
4147 struct i40e_hw *hw = &pf->hw;
4148 u32 rx_reg;
4149 int i;
4150
4151 for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
4152 rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
4153 if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
4154 ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
4155 break;
4156 usleep_range(1000, 2000);
4157 }
4158
4159 /* Skip if the queue is already in the requested state */
4160 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
4161 return;
4162
4163 /* turn on/off the queue */
4164 if (enable)
4165 rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
4166 else
4167 rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
4168
4169 wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
4170}
4171
4172/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004173 * i40e_vsi_control_rx - Start or stop a VSI's rings
4174 * @vsi: the VSI being configured
4175 * @enable: start or stop the rings
4176 **/
4177static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
4178{
4179 struct i40e_pf *pf = vsi->back;
Jacob Kellerc768e492017-04-13 04:45:47 -04004180 int i, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004181
4182 pf_q = vsi->base_queue;
4183 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Jacob Kellerc768e492017-04-13 04:45:47 -04004184 i40e_control_rx_q(pf, pf_q, enable);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004185
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004186 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00004187 ret = i40e_pf_rxq_wait(pf, pf_q, enable);
4188 if (ret) {
4189 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004190 "VSI seid %d Rx ring %d %sable timeout\n",
4191 vsi->seid, pf_q, (enable ? "en" : "dis"));
Neerav Parikh23527302014-06-03 23:50:15 +00004192 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004193 }
4194 }
4195
Wyborny, Carolynd08a9f62017-03-28 08:00:48 -07004196 /* Due to HW errata, on Rx disable only, the register can indicate done
4197 * before it really is. Needs 50ms to be sure
4198 */
4199 if (!enable)
4200 mdelay(50);
4201
Neerav Parikh23527302014-06-03 23:50:15 +00004202 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004203}
4204
4205/**
Filip Sadowski3aa7b742016-10-11 15:26:58 -07004206 * i40e_vsi_start_rings - Start a VSI's rings
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004207 * @vsi: the VSI being configured
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004208 **/
Filip Sadowski3aa7b742016-10-11 15:26:58 -07004209int i40e_vsi_start_rings(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004210{
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00004211 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004212
4213 /* do rx first for enable and last for disable */
Filip Sadowski3aa7b742016-10-11 15:26:58 -07004214 ret = i40e_vsi_control_rx(vsi, true);
4215 if (ret)
4216 return ret;
4217 ret = i40e_vsi_control_tx(vsi, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004218
4219 return ret;
4220}
4221
4222/**
Filip Sadowski3aa7b742016-10-11 15:26:58 -07004223 * i40e_vsi_stop_rings - Stop a VSI's rings
4224 * @vsi: the VSI being configured
4225 **/
4226void i40e_vsi_stop_rings(struct i40e_vsi *vsi)
4227{
Jacob Keller34807562017-04-13 04:45:53 -04004228 /* When port TX is suspended, don't wait */
Jacob Keller0da36b92017-04-19 09:25:55 -04004229 if (test_bit(__I40E_PORT_SUSPENDED, vsi->back->state))
Jacob Keller34807562017-04-13 04:45:53 -04004230 return i40e_vsi_stop_rings_no_wait(vsi);
4231
Filip Sadowski3aa7b742016-10-11 15:26:58 -07004232 /* do rx first for enable and last for disable
4233 * Ignore return value, we need to shutdown whatever we can
4234 */
4235 i40e_vsi_control_tx(vsi, false);
4236 i40e_vsi_control_rx(vsi, false);
4237}
4238
4239/**
Jacob Kellere4b433f2017-04-13 04:45:52 -04004240 * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay
4241 * @vsi: the VSI being shutdown
4242 *
4243 * This function stops all the rings for a VSI but does not delay to verify
4244 * that rings have been disabled. It is expected that the caller is shutting
4245 * down multiple VSIs at once and will delay together for all the VSIs after
4246 * initiating the shutdown. This is particularly useful for shutting down lots
4247 * of VFs together. Otherwise, a large delay can be incurred while configuring
4248 * each VSI in serial.
4249 **/
4250void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi)
4251{
4252 struct i40e_pf *pf = vsi->back;
4253 int i, pf_q;
4254
4255 pf_q = vsi->base_queue;
4256 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4257 i40e_control_tx_q(pf, pf_q, false);
4258 i40e_control_rx_q(pf, pf_q, false);
4259 }
4260}
4261
4262/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004263 * i40e_vsi_free_irq - Free the irq association with the OS
4264 * @vsi: the VSI being configured
4265 **/
4266static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
4267{
4268 struct i40e_pf *pf = vsi->back;
4269 struct i40e_hw *hw = &pf->hw;
4270 int base = vsi->base_vector;
4271 u32 val, qp;
4272 int i;
4273
4274 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4275 if (!vsi->q_vectors)
4276 return;
4277
Shannon Nelson63741842014-04-23 04:50:16 +00004278 if (!vsi->irqs_ready)
4279 return;
4280
4281 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004282 for (i = 0; i < vsi->num_q_vectors; i++) {
Alan Brady96db7762016-09-14 16:24:38 -07004283 int irq_num;
4284 u16 vector;
4285
4286 vector = i + base;
4287 irq_num = pf->msix_entries[vector].vector;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004288
4289 /* free only the irqs that were actually requested */
Shannon Nelson78681b12013-11-28 06:39:36 +00004290 if (!vsi->q_vectors[i] ||
4291 !vsi->q_vectors[i]->num_ringpairs)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004292 continue;
4293
Alan Brady96db7762016-09-14 16:24:38 -07004294 /* clear the affinity notifier in the IRQ descriptor */
4295 irq_set_affinity_notifier(irq_num, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004296 /* clear the affinity_mask in the IRQ descriptor */
Alan Brady96db7762016-09-14 16:24:38 -07004297 irq_set_affinity_hint(irq_num, NULL);
4298 synchronize_irq(irq_num);
4299 free_irq(irq_num, vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004300
4301 /* Tear down the interrupt queue link list
4302 *
4303 * We know that they come in pairs and always
4304 * the Rx first, then the Tx. To clear the
4305 * link list, stick the EOL value into the
4306 * next_q field of the registers.
4307 */
4308 val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
4309 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4310 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4311 val |= I40E_QUEUE_END_OF_LIST
4312 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4313 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
4314
4315 while (qp != I40E_QUEUE_END_OF_LIST) {
4316 u32 next;
4317
4318 val = rd32(hw, I40E_QINT_RQCTL(qp));
4319
4320 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4321 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4322 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4323 I40E_QINT_RQCTL_INTEVENT_MASK);
4324
4325 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4326 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4327
4328 wr32(hw, I40E_QINT_RQCTL(qp), val);
4329
4330 val = rd32(hw, I40E_QINT_TQCTL(qp));
4331
4332 next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
4333 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
4334
4335 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4336 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4337 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4338 I40E_QINT_TQCTL_INTEVENT_MASK);
4339
4340 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4341 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4342
4343 wr32(hw, I40E_QINT_TQCTL(qp), val);
4344 qp = next;
4345 }
4346 }
4347 } else {
4348 free_irq(pf->pdev->irq, pf);
4349
4350 val = rd32(hw, I40E_PFINT_LNKLST0);
4351 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4352 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4353 val |= I40E_QUEUE_END_OF_LIST
4354 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
4355 wr32(hw, I40E_PFINT_LNKLST0, val);
4356
4357 val = rd32(hw, I40E_QINT_RQCTL(qp));
4358 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4359 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4360 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4361 I40E_QINT_RQCTL_INTEVENT_MASK);
4362
4363 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4364 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4365
4366 wr32(hw, I40E_QINT_RQCTL(qp), val);
4367
4368 val = rd32(hw, I40E_QINT_TQCTL(qp));
4369
4370 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4371 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4372 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4373 I40E_QINT_TQCTL_INTEVENT_MASK);
4374
4375 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4376 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4377
4378 wr32(hw, I40E_QINT_TQCTL(qp), val);
4379 }
4380}
4381
4382/**
Alexander Duyck493fb302013-09-28 07:01:44 +00004383 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4384 * @vsi: the VSI being configured
4385 * @v_idx: Index of vector to be freed
4386 *
4387 * This function frees the memory allocated to the q_vector. In addition if
4388 * NAPI is enabled it will delete any references to the NAPI struct prior
4389 * to freeing the q_vector.
4390 **/
4391static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
4392{
4393 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00004394 struct i40e_ring *ring;
Alexander Duyck493fb302013-09-28 07:01:44 +00004395
4396 if (!q_vector)
4397 return;
4398
4399 /* disassociate q_vector from rings */
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00004400 i40e_for_each_ring(ring, q_vector->tx)
4401 ring->q_vector = NULL;
4402
4403 i40e_for_each_ring(ring, q_vector->rx)
4404 ring->q_vector = NULL;
Alexander Duyck493fb302013-09-28 07:01:44 +00004405
4406 /* only VSI w/ an associated netdev is set up w/ NAPI */
4407 if (vsi->netdev)
4408 netif_napi_del(&q_vector->napi);
4409
4410 vsi->q_vectors[v_idx] = NULL;
4411
4412 kfree_rcu(q_vector, rcu);
4413}
4414
4415/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004416 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4417 * @vsi: the VSI being un-configured
4418 *
4419 * This frees the memory allocated to the q_vectors and
4420 * deletes references to the NAPI struct.
4421 **/
4422static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
4423{
4424 int v_idx;
4425
Alexander Duyck493fb302013-09-28 07:01:44 +00004426 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
4427 i40e_free_q_vector(vsi, v_idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004428}
4429
4430/**
4431 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4432 * @pf: board private structure
4433 **/
4434static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
4435{
4436 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4437 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4438 pci_disable_msix(pf->pdev);
4439 kfree(pf->msix_entries);
4440 pf->msix_entries = NULL;
Shannon Nelson3b444392015-02-26 16:15:57 +00004441 kfree(pf->irq_pile);
4442 pf->irq_pile = NULL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004443 } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
4444 pci_disable_msi(pf->pdev);
4445 }
4446 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
4447}
4448
4449/**
4450 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4451 * @pf: board private structure
4452 *
4453 * We go through and clear interrupt specific resources and reset the structure
4454 * to pre-load conditions
4455 **/
4456static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
4457{
4458 int i;
4459
Shannon Nelsone1477582015-02-21 06:44:33 +00004460 i40e_stop_misc_vector(pf);
Shannon Nelson69278392016-03-10 14:59:43 -08004461 if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
Shannon Nelsone1477582015-02-21 06:44:33 +00004462 synchronize_irq(pf->msix_entries[0].vector);
4463 free_irq(pf->msix_entries[0].vector, pf);
4464 }
4465
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06004466 i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
4467 I40E_IWARP_IRQ_PILE_ID);
4468
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004469 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
Mitch Williams505682c2014-05-20 08:01:37 +00004470 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004471 if (pf->vsi[i])
4472 i40e_vsi_free_q_vectors(pf->vsi[i]);
4473 i40e_reset_interrupt_capability(pf);
4474}
4475
4476/**
4477 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4478 * @vsi: the VSI being configured
4479 **/
4480static void i40e_napi_enable_all(struct i40e_vsi *vsi)
4481{
4482 int q_idx;
4483
4484 if (!vsi->netdev)
4485 return;
4486
Alexander Duyck13a8cd12017-03-24 15:01:42 -07004487 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
4488 struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
4489
4490 if (q_vector->rx.ring || q_vector->tx.ring)
4491 napi_enable(&q_vector->napi);
4492 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004493}
4494
4495/**
4496 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4497 * @vsi: the VSI being configured
4498 **/
4499static void i40e_napi_disable_all(struct i40e_vsi *vsi)
4500{
4501 int q_idx;
4502
4503 if (!vsi->netdev)
4504 return;
4505
Alexander Duyck13a8cd12017-03-24 15:01:42 -07004506 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
4507 struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
4508
4509 if (q_vector->rx.ring || q_vector->tx.ring)
4510 napi_disable(&q_vector->napi);
4511 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004512}
4513
4514/**
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004515 * i40e_vsi_close - Shut down a VSI
4516 * @vsi: the vsi to be quelled
4517 **/
4518static void i40e_vsi_close(struct i40e_vsi *vsi)
4519{
Mitch Williams0ef2d5a2017-01-24 10:24:00 -08004520 struct i40e_pf *pf = vsi->back;
Jacob Keller0da36b92017-04-19 09:25:55 -04004521 if (!test_and_set_bit(__I40E_VSI_DOWN, vsi->state))
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004522 i40e_down(vsi);
4523 i40e_vsi_free_irq(vsi);
4524 i40e_vsi_free_tx_resources(vsi);
4525 i40e_vsi_free_rx_resources(vsi);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04004526 vsi->current_netdev_flags = 0;
Mitch Williams0ef2d5a2017-01-24 10:24:00 -08004527 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
Jacob Keller0da36b92017-04-19 09:25:55 -04004528 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
Mitch Williams0ef2d5a2017-01-24 10:24:00 -08004529 pf->flags |= I40E_FLAG_CLIENT_RESET;
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004530}
4531
4532/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004533 * i40e_quiesce_vsi - Pause a given VSI
4534 * @vsi: the VSI being paused
4535 **/
4536static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
4537{
Jacob Keller0da36b92017-04-19 09:25:55 -04004538 if (test_bit(__I40E_VSI_DOWN, vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004539 return;
4540
Jacob Keller0da36b92017-04-19 09:25:55 -04004541 set_bit(__I40E_VSI_NEEDS_RESTART, vsi->state);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004542 if (vsi->netdev && netif_running(vsi->netdev))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004543 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004544 else
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004545 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004546}
4547
4548/**
4549 * i40e_unquiesce_vsi - Resume a given VSI
4550 * @vsi: the VSI being resumed
4551 **/
4552static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
4553{
Jacob Keller0da36b92017-04-19 09:25:55 -04004554 if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART, vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004555 return;
4556
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004557 if (vsi->netdev && netif_running(vsi->netdev))
4558 vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
4559 else
Shannon Nelson8276f752014-03-14 07:32:27 +00004560 i40e_vsi_open(vsi); /* this clears the DOWN bit */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004561}
4562
4563/**
4564 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4565 * @pf: the PF
4566 **/
4567static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
4568{
4569 int v;
4570
Mitch Williams505682c2014-05-20 08:01:37 +00004571 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004572 if (pf->vsi[v])
4573 i40e_quiesce_vsi(pf->vsi[v]);
4574 }
4575}
4576
4577/**
4578 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4579 * @pf: the PF
4580 **/
4581static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
4582{
4583 int v;
4584
Mitch Williams505682c2014-05-20 08:01:37 +00004585 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004586 if (pf->vsi[v])
4587 i40e_unquiesce_vsi(pf->vsi[v]);
4588 }
4589}
4590
Neerav Parikh69129dc2014-11-12 00:18:46 +00004591/**
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004592 * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
Neerav Parikh69129dc2014-11-12 00:18:46 +00004593 * @vsi: the VSI being configured
4594 *
Jacob Kelleraf26ce22017-04-05 07:50:58 -04004595 * Wait until all queues on a given VSI have been disabled.
Neerav Parikh69129dc2014-11-12 00:18:46 +00004596 **/
Jacob Kellere4b433f2017-04-13 04:45:52 -04004597int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
Neerav Parikh69129dc2014-11-12 00:18:46 +00004598{
4599 struct i40e_pf *pf = vsi->back;
4600 int i, pf_q, ret;
4601
4602 pf_q = vsi->base_queue;
4603 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Jacob Kelleraf26ce22017-04-05 07:50:58 -04004604 /* Check and wait for the Tx queue */
Neerav Parikh69129dc2014-11-12 00:18:46 +00004605 ret = i40e_pf_txq_wait(pf, pf_q, false);
4606 if (ret) {
4607 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004608 "VSI seid %d Tx ring %d disable timeout\n",
4609 vsi->seid, pf_q);
Neerav Parikh69129dc2014-11-12 00:18:46 +00004610 return ret;
4611 }
Björn Töpel74608d12017-05-24 07:55:35 +02004612
4613 if (!i40e_enabled_xdp_vsi(vsi))
4614 goto wait_rx;
4615
4616 /* Check and wait for the XDP Tx queue */
4617 ret = i40e_pf_txq_wait(pf, pf_q + vsi->alloc_queue_pairs,
4618 false);
4619 if (ret) {
4620 dev_info(&pf->pdev->dev,
4621 "VSI seid %d XDP Tx ring %d disable timeout\n",
4622 vsi->seid, pf_q);
4623 return ret;
4624 }
4625wait_rx:
4626 /* Check and wait for the Rx queue */
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004627 ret = i40e_pf_rxq_wait(pf, pf_q, false);
4628 if (ret) {
4629 dev_info(&pf->pdev->dev,
4630 "VSI seid %d Rx ring %d disable timeout\n",
4631 vsi->seid, pf_q);
4632 return ret;
4633 }
4634 }
4635
Neerav Parikh69129dc2014-11-12 00:18:46 +00004636 return 0;
4637}
4638
Jacob Kellere4b433f2017-04-13 04:45:52 -04004639#ifdef CONFIG_I40E_DCB
Neerav Parikh69129dc2014-11-12 00:18:46 +00004640/**
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004641 * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
Neerav Parikh69129dc2014-11-12 00:18:46 +00004642 * @pf: the PF
4643 *
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004644 * This function waits for the queues to be in disabled state for all the
Neerav Parikh69129dc2014-11-12 00:18:46 +00004645 * VSIs that are managed by this PF.
4646 **/
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004647static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
Neerav Parikh69129dc2014-11-12 00:18:46 +00004648{
4649 int v, ret = 0;
4650
4651 for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
Alexander Duyckc76cb6e2017-02-21 15:55:48 -08004652 if (pf->vsi[v]) {
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004653 ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
Neerav Parikh69129dc2014-11-12 00:18:46 +00004654 if (ret)
4655 break;
4656 }
4657 }
4658
4659 return ret;
4660}
4661
4662#endif
Kiran Patilb03a8c12015-09-24 18:13:15 -04004663
4664/**
4665 * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
4666 * @q_idx: TX queue number
4667 * @vsi: Pointer to VSI struct
4668 *
4669 * This function checks specified queue for given VSI. Detects hung condition.
Alan Brady17daabb2017-04-05 07:50:56 -04004670 * We proactively detect hung TX queues by checking if interrupts are disabled
4671 * but there are pending descriptors. If it appears hung, attempt to recover
4672 * by triggering a SW interrupt.
Kiran Patilb03a8c12015-09-24 18:13:15 -04004673 **/
4674static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
4675{
4676 struct i40e_ring *tx_ring = NULL;
4677 struct i40e_pf *pf;
Alan Brady17daabb2017-04-05 07:50:56 -04004678 u32 val, tx_pending;
Kiran Patilb03a8c12015-09-24 18:13:15 -04004679 int i;
4680
4681 pf = vsi->back;
4682
4683 /* now that we have an index, find the tx_ring struct */
4684 for (i = 0; i < vsi->num_queue_pairs; i++) {
4685 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
4686 if (q_idx == vsi->tx_rings[i]->queue_index) {
4687 tx_ring = vsi->tx_rings[i];
4688 break;
4689 }
4690 }
4691 }
4692
4693 if (!tx_ring)
4694 return;
4695
4696 /* Read interrupt register */
4697 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
4698 val = rd32(&pf->hw,
4699 I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
4700 tx_ring->vsi->base_vector - 1));
4701 else
4702 val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
4703
Alan Brady17daabb2017-04-05 07:50:56 -04004704 tx_pending = i40e_get_tx_pending(tx_ring);
Kiran Patilb03a8c12015-09-24 18:13:15 -04004705
Alan Brady17daabb2017-04-05 07:50:56 -04004706 /* Interrupts are disabled and TX pending is non-zero,
4707 * trigger the SW interrupt (don't wait). Worst case
4708 * there will be one extra interrupt which may result
4709 * into not cleaning any queues because queues are cleaned.
Kiran Patilb03a8c12015-09-24 18:13:15 -04004710 */
Alan Brady17daabb2017-04-05 07:50:56 -04004711 if (tx_pending && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK)))
4712 i40e_force_wb(vsi, tx_ring->q_vector);
Kiran Patilb03a8c12015-09-24 18:13:15 -04004713}
4714
4715/**
4716 * i40e_detect_recover_hung - Function to detect and recover hung_queues
4717 * @pf: pointer to PF struct
4718 *
4719 * LAN VSI has netdev and netdev has TX queues. This function is to check
4720 * each of those TX queues if they are hung, trigger recovery by issuing
4721 * SW interrupt.
4722 **/
4723static void i40e_detect_recover_hung(struct i40e_pf *pf)
4724{
4725 struct net_device *netdev;
4726 struct i40e_vsi *vsi;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07004727 unsigned int i;
Kiran Patilb03a8c12015-09-24 18:13:15 -04004728
4729 /* Only for LAN VSI */
4730 vsi = pf->vsi[pf->lan_vsi];
4731
4732 if (!vsi)
4733 return;
4734
4735 /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
Jacob Keller0da36b92017-04-19 09:25:55 -04004736 if (test_bit(__I40E_VSI_DOWN, vsi->back->state) ||
4737 test_bit(__I40E_RESET_RECOVERY_PENDING, vsi->back->state))
Kiran Patilb03a8c12015-09-24 18:13:15 -04004738 return;
4739
4740 /* Make sure type is MAIN VSI */
4741 if (vsi->type != I40E_VSI_MAIN)
4742 return;
4743
4744 netdev = vsi->netdev;
4745 if (!netdev)
4746 return;
4747
4748 /* Bail out if netif_carrier is not OK */
4749 if (!netif_carrier_ok(netdev))
4750 return;
4751
4752 /* Go thru' TX queues for netdev */
4753 for (i = 0; i < netdev->num_tx_queues; i++) {
4754 struct netdev_queue *q;
4755
4756 q = netdev_get_tx_queue(netdev, i);
4757 if (q)
4758 i40e_detect_recover_hung_queue(i, vsi);
4759 }
4760}
4761
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004762/**
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004763 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00004764 * @pf: pointer to PF
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004765 *
4766 * Get TC map for ISCSI PF type that will include iSCSI TC
4767 * and LAN TC.
4768 **/
4769static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
4770{
4771 struct i40e_dcb_app_priority_table app;
4772 struct i40e_hw *hw = &pf->hw;
4773 u8 enabled_tc = 1; /* TC0 is always enabled */
4774 u8 tc, i;
4775 /* Get the iSCSI APP TLV */
4776 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4777
4778 for (i = 0; i < dcbcfg->numapps; i++) {
4779 app = dcbcfg->app[i];
4780 if (app.selector == I40E_APP_SEL_TCPIP &&
4781 app.protocolid == I40E_APP_PROTOID_ISCSI) {
4782 tc = dcbcfg->etscfg.prioritytable[app.priority];
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004783 enabled_tc |= BIT(tc);
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004784 break;
4785 }
4786 }
4787
4788 return enabled_tc;
4789}
4790
4791/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004792 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4793 * @dcbcfg: the corresponding DCBx configuration structure
4794 *
4795 * Return the number of TCs from given DCBx configuration
4796 **/
4797static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
4798{
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004799 int i, tc_unused = 0;
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004800 u8 num_tc = 0;
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004801 u8 ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004802
4803 /* Scan the ETS Config Priority Table to find
4804 * traffic class enabled for a given priority
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004805 * and create a bitmask of enabled TCs
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004806 */
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004807 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
4808 num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
4809
4810 /* Now scan the bitmask to check for
4811 * contiguous TCs starting with TC0
4812 */
4813 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4814 if (num_tc & BIT(i)) {
4815 if (!tc_unused) {
4816 ret++;
4817 } else {
4818 pr_err("Non-contiguous TC - Disabling DCB\n");
4819 return 1;
4820 }
4821 } else {
4822 tc_unused = 1;
4823 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004824 }
4825
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004826 /* There is always at least TC0 */
4827 if (!ret)
4828 ret = 1;
4829
4830 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004831}
4832
4833/**
4834 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4835 * @dcbcfg: the corresponding DCBx configuration structure
4836 *
4837 * Query the current DCB configuration and return the number of
4838 * traffic classes enabled from the given DCBX config
4839 **/
4840static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
4841{
4842 u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
4843 u8 enabled_tc = 1;
4844 u8 i;
4845
4846 for (i = 0; i < num_tc; i++)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004847 enabled_tc |= BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004848
4849 return enabled_tc;
4850}
4851
4852/**
4853 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4854 * @pf: PF being queried
4855 *
4856 * Return number of traffic classes enabled for the given PF
4857 **/
4858static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
4859{
4860 struct i40e_hw *hw = &pf->hw;
Dave Ertman52a08ca2016-07-27 12:02:34 -07004861 u8 i, enabled_tc = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004862 u8 num_tc = 0;
4863 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4864
4865 /* If DCB is not enabled then always in single TC */
4866 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
4867 return 1;
4868
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004869 /* SFP mode will be enabled for all TCs on port */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004870 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4871 return i40e_dcb_get_num_tc(dcbcfg);
4872
4873 /* MFP mode return count of enabled TCs for this PF */
4874 if (pf->hw.func_caps.iscsi)
4875 enabled_tc = i40e_get_iscsi_tc_map(pf);
4876 else
Neerav Parikhfc51de92015-02-24 06:58:53 +00004877 return 1; /* Only TC0 */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004878
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004879 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004880 if (enabled_tc & BIT(i))
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004881 num_tc++;
4882 }
4883 return num_tc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004884}
4885
4886/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004887 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4888 * @pf: PF being queried
4889 *
4890 * Return a bitmap for enabled traffic classes for this PF.
4891 **/
4892static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
4893{
4894 /* If DCB is not enabled for this PF then just return default TC */
4895 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
David Ertmanea6acb72016-09-20 07:10:50 -07004896 return I40E_DEFAULT_TRAFFIC_CLASS;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004897
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004898 /* SFP mode we want PF to be enabled for all TCs */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004899 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4900 return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
4901
Neerav Parikhfc51de92015-02-24 06:58:53 +00004902 /* MFP enabled and iSCSI PF type */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004903 if (pf->hw.func_caps.iscsi)
4904 return i40e_get_iscsi_tc_map(pf);
4905 else
David Ertmanea6acb72016-09-20 07:10:50 -07004906 return I40E_DEFAULT_TRAFFIC_CLASS;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004907}
4908
4909/**
4910 * i40e_vsi_get_bw_info - Query VSI BW Information
4911 * @vsi: the VSI being queried
4912 *
4913 * Returns 0 on success, negative value on failure
4914 **/
4915static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
4916{
4917 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
4918 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
4919 struct i40e_pf *pf = vsi->back;
4920 struct i40e_hw *hw = &pf->hw;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004921 i40e_status ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004922 u32 tc_bw_max;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004923 int i;
4924
4925 /* Get the VSI level BW configuration */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004926 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
4927 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004928 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004929 "couldn't get PF vsi bw config, err %s aq_err %s\n",
4930 i40e_stat_str(&pf->hw, ret),
4931 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004932 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004933 }
4934
4935 /* Get the VSI level BW configuration per TC */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004936 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
4937 NULL);
4938 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004939 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004940 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
4941 i40e_stat_str(&pf->hw, ret),
4942 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004943 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004944 }
4945
4946 if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
4947 dev_info(&pf->pdev->dev,
4948 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4949 bw_config.tc_valid_bits,
4950 bw_ets_config.tc_valid_bits);
4951 /* Still continuing */
4952 }
4953
4954 vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
4955 vsi->bw_max_quanta = bw_config.max_bw;
4956 tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
4957 (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
4958 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4959 vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
4960 vsi->bw_ets_limit_credits[i] =
4961 le16_to_cpu(bw_ets_config.credits[i]);
4962 /* 3 bits out of 4 for each TC */
4963 vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
4964 }
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004965
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004966 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004967}
4968
4969/**
4970 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
4971 * @vsi: the VSI being configured
4972 * @enabled_tc: TC bitmap
4973 * @bw_credits: BW shared credits per TC
4974 *
4975 * Returns 0 on success, negative value on failure
4976 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004977static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004978 u8 *bw_share)
4979{
4980 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004981 i40e_status ret;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004982 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004983
4984 bw_data.tc_valid_bits = enabled_tc;
4985 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4986 bw_data.tc_bw_credits[i] = bw_share[i];
4987
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004988 ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
4989 NULL);
4990 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004991 dev_info(&vsi->back->pdev->dev,
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004992 "AQ command Config VSI BW allocation per TC failed = %d\n",
4993 vsi->back->hw.aq.asq_last_status);
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004994 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004995 }
4996
4997 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4998 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
4999
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00005000 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005001}
5002
5003/**
5004 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
5005 * @vsi: the VSI being configured
5006 * @enabled_tc: TC map to be enabled
5007 *
5008 **/
5009static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
5010{
5011 struct net_device *netdev = vsi->netdev;
5012 struct i40e_pf *pf = vsi->back;
5013 struct i40e_hw *hw = &pf->hw;
5014 u8 netdev_tc = 0;
5015 int i;
5016 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
5017
5018 if (!netdev)
5019 return;
5020
5021 if (!enabled_tc) {
5022 netdev_reset_tc(netdev);
5023 return;
5024 }
5025
5026 /* Set up actual enabled TCs on the VSI */
5027 if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
5028 return;
5029
5030 /* set per TC queues for the VSI */
5031 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5032 /* Only set TC queues for enabled tcs
5033 *
5034 * e.g. For a VSI that has TC0 and TC3 enabled the
5035 * enabled_tc bitmap would be 0x00001001; the driver
5036 * will set the numtc for netdev as 2 that will be
5037 * referenced by the netdev layer as TC 0 and 1.
5038 */
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08005039 if (vsi->tc_config.enabled_tc & BIT(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005040 netdev_set_tc_queue(netdev,
5041 vsi->tc_config.tc_info[i].netdev_tc,
5042 vsi->tc_config.tc_info[i].qcount,
5043 vsi->tc_config.tc_info[i].qoffset);
5044 }
5045
5046 /* Assign UP2TC map for the VSI */
5047 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
5048 /* Get the actual TC# for the UP */
5049 u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
5050 /* Get the mapped netdev TC# for the UP */
5051 netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
5052 netdev_set_prio_tc_map(netdev, i, netdev_tc);
5053 }
5054}
5055
5056/**
5057 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
5058 * @vsi: the VSI being configured
5059 * @ctxt: the ctxt buffer returned from AQ VSI update param command
5060 **/
5061static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
5062 struct i40e_vsi_context *ctxt)
5063{
5064 /* copy just the sections touched not the entire info
5065 * since not all sections are valid as returned by
5066 * update vsi params
5067 */
5068 vsi->info.mapping_flags = ctxt->info.mapping_flags;
5069 memcpy(&vsi->info.queue_mapping,
5070 &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
5071 memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
5072 sizeof(vsi->info.tc_mapping));
5073}
5074
5075/**
5076 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
5077 * @vsi: VSI to be configured
5078 * @enabled_tc: TC bitmap
5079 *
5080 * This configures a particular VSI for TCs that are mapped to the
5081 * given TC bitmap. It uses default bandwidth share for TCs across
5082 * VSIs to configure TC for a particular VSI.
5083 *
5084 * NOTE:
5085 * It is expected that the VSI queues have been quisced before calling
5086 * this function.
5087 **/
5088static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
5089{
5090 u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
5091 struct i40e_vsi_context ctxt;
5092 int ret = 0;
5093 int i;
5094
5095 /* Check if enabled_tc is same as existing or new TCs */
5096 if (vsi->tc_config.enabled_tc == enabled_tc)
5097 return ret;
5098
5099 /* Enable ETS TCs with equal BW Share for now across all VSIs */
5100 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08005101 if (enabled_tc & BIT(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005102 bw_share[i] = 1;
5103 }
5104
5105 ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
5106 if (ret) {
5107 dev_info(&vsi->back->pdev->dev,
5108 "Failed configuring TC map %d for VSI %d\n",
5109 enabled_tc, vsi->seid);
5110 goto out;
5111 }
5112
5113 /* Update Queue Pairs Mapping for currently enabled UPs */
5114 ctxt.seid = vsi->seid;
5115 ctxt.pf_num = vsi->back->hw.pf_id;
5116 ctxt.vf_num = 0;
5117 ctxt.uplink_seid = vsi->uplink_seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07005118 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005119 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
5120
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06005121 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
5122 ctxt.info.valid_sections |=
5123 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
5124 ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
5125 }
5126
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005127 /* Update the VSI after updating the VSI queue-mapping information */
5128 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
5129 if (ret) {
5130 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005131 "Update vsi tc config failed, err %s aq_err %s\n",
5132 i40e_stat_str(&vsi->back->hw, ret),
5133 i40e_aq_str(&vsi->back->hw,
5134 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005135 goto out;
5136 }
5137 /* update the local VSI info with updated queue map */
5138 i40e_vsi_update_queue_map(vsi, &ctxt);
5139 vsi->info.valid_sections = 0;
5140
5141 /* Update current VSI BW information */
5142 ret = i40e_vsi_get_bw_info(vsi);
5143 if (ret) {
5144 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005145 "Failed updating vsi bw info, err %s aq_err %s\n",
5146 i40e_stat_str(&vsi->back->hw, ret),
5147 i40e_aq_str(&vsi->back->hw,
5148 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005149 goto out;
5150 }
5151
5152 /* Update the netdev TC setup */
5153 i40e_vsi_config_netdev_tc(vsi, enabled_tc);
5154out:
5155 return ret;
5156}
5157
5158/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005159 * i40e_veb_config_tc - Configure TCs for given VEB
5160 * @veb: given VEB
5161 * @enabled_tc: TC bitmap
5162 *
5163 * Configures given TC bitmap for VEB (switching) element
5164 **/
5165int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
5166{
5167 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
5168 struct i40e_pf *pf = veb->pf;
5169 int ret = 0;
5170 int i;
5171
5172 /* No TCs or already enabled TCs just return */
5173 if (!enabled_tc || veb->enabled_tc == enabled_tc)
5174 return ret;
5175
5176 bw_data.tc_valid_bits = enabled_tc;
5177 /* bw_data.absolute_credits is not set (relative) */
5178
5179 /* Enable ETS TCs with equal BW Share for now */
5180 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08005181 if (enabled_tc & BIT(i))
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005182 bw_data.tc_bw_share_credits[i] = 1;
5183 }
5184
5185 ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
5186 &bw_data, NULL);
5187 if (ret) {
5188 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005189 "VEB bw config failed, err %s aq_err %s\n",
5190 i40e_stat_str(&pf->hw, ret),
5191 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005192 goto out;
5193 }
5194
5195 /* Update the BW information */
5196 ret = i40e_veb_get_bw_info(veb);
5197 if (ret) {
5198 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005199 "Failed getting veb bw config, err %s aq_err %s\n",
5200 i40e_stat_str(&pf->hw, ret),
5201 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005202 }
5203
5204out:
5205 return ret;
5206}
5207
5208#ifdef CONFIG_I40E_DCB
5209/**
5210 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
5211 * @pf: PF struct
5212 *
5213 * Reconfigure VEB/VSIs on a given PF; it is assumed that
5214 * the caller would've quiesce all the VSIs before calling
5215 * this function
5216 **/
5217static void i40e_dcb_reconfigure(struct i40e_pf *pf)
5218{
5219 u8 tc_map = 0;
5220 int ret;
5221 u8 v;
5222
5223 /* Enable the TCs available on PF to all VEBs */
5224 tc_map = i40e_pf_get_tc_map(pf);
5225 for (v = 0; v < I40E_MAX_VEB; v++) {
5226 if (!pf->veb[v])
5227 continue;
5228 ret = i40e_veb_config_tc(pf->veb[v], tc_map);
5229 if (ret) {
5230 dev_info(&pf->pdev->dev,
5231 "Failed configuring TC for VEB seid=%d\n",
5232 pf->veb[v]->seid);
5233 /* Will try to configure as many components */
5234 }
5235 }
5236
5237 /* Update each VSI */
Mitch Williams505682c2014-05-20 08:01:37 +00005238 for (v = 0; v < pf->num_alloc_vsi; v++) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005239 if (!pf->vsi[v])
5240 continue;
5241
5242 /* - Enable all TCs for the LAN VSI
5243 * - For all others keep them at TC0 for now
5244 */
5245 if (v == pf->lan_vsi)
5246 tc_map = i40e_pf_get_tc_map(pf);
5247 else
David Ertmanea6acb72016-09-20 07:10:50 -07005248 tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005249
5250 ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
5251 if (ret) {
5252 dev_info(&pf->pdev->dev,
5253 "Failed configuring TC for VSI seid=%d\n",
5254 pf->vsi[v]->seid);
5255 /* Will try to configure as many components */
5256 } else {
Neerav Parikh0672a092014-04-01 07:11:47 +00005257 /* Re-configure VSI vectors based on updated TC map */
5258 i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005259 if (pf->vsi[v]->netdev)
5260 i40e_dcbnl_set_all(pf->vsi[v]);
5261 }
5262 }
5263}
5264
5265/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005266 * i40e_resume_port_tx - Resume port Tx
5267 * @pf: PF struct
5268 *
5269 * Resume a port's Tx and issue a PF reset in case of failure to
5270 * resume.
5271 **/
5272static int i40e_resume_port_tx(struct i40e_pf *pf)
5273{
5274 struct i40e_hw *hw = &pf->hw;
5275 int ret;
5276
5277 ret = i40e_aq_resume_port_tx(hw, NULL);
5278 if (ret) {
5279 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005280 "Resume Port Tx failed, err %s aq_err %s\n",
5281 i40e_stat_str(&pf->hw, ret),
5282 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005283 /* Schedule PF reset to recover */
Jacob Keller0da36b92017-04-19 09:25:55 -04005284 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005285 i40e_service_event_schedule(pf);
5286 }
5287
5288 return ret;
5289}
5290
5291/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005292 * i40e_init_pf_dcb - Initialize DCB configuration
5293 * @pf: PF being configured
5294 *
5295 * Query the current DCB configuration and cache it
5296 * in the hardware structure
5297 **/
5298static int i40e_init_pf_dcb(struct i40e_pf *pf)
5299{
5300 struct i40e_hw *hw = &pf->hw;
5301 int err = 0;
5302
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00005303 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
Jacob Kellerd36e41d2017-06-23 04:24:46 -04005304 if (pf->hw_features & I40E_HW_NO_DCB_SUPPORT)
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00005305 goto out;
5306
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005307 /* Get the initial DCB configuration */
5308 err = i40e_init_dcb(hw);
5309 if (!err) {
5310 /* Device/Function is not DCBX capable */
5311 if ((!hw->func_caps.dcb) ||
5312 (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
5313 dev_info(&pf->pdev->dev,
5314 "DCBX offload is not supported or is disabled for this PF.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005315 } else {
5316 /* When status is not DISABLED then DCBX in FW */
5317 pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
5318 DCB_CAP_DCBX_VER_IEEE;
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005319
5320 pf->flags |= I40E_FLAG_DCB_CAPABLE;
Dave Ertmana0362442016-08-29 17:38:26 -07005321 /* Enable DCB tagging only when more than one TC
5322 * or explicitly disable if only one TC
5323 */
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005324 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
5325 pf->flags |= I40E_FLAG_DCB_ENABLED;
Dave Ertmana0362442016-08-29 17:38:26 -07005326 else
5327 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005328 dev_dbg(&pf->pdev->dev,
5329 "DCBX offload is supported for this PF.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005330 }
Neerav Parikh014269f2014-04-01 07:11:48 +00005331 } else {
Shannon Nelsonaebfc812014-12-11 07:06:38 +00005332 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005333 "Query for DCB configuration failed, err %s aq_err %s\n",
5334 i40e_stat_str(&pf->hw, err),
5335 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005336 }
5337
5338out:
5339 return err;
5340}
5341#endif /* CONFIG_I40E_DCB */
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005342#define SPEED_SIZE 14
5343#define FC_SIZE 8
5344/**
5345 * i40e_print_link_message - print link up or down
5346 * @vsi: the VSI for which link needs a message
5347 */
Matt Jaredc156f852015-08-27 11:42:39 -04005348void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005349{
Filip Sadowski7ec9ba12016-11-08 13:05:13 -08005350 enum i40e_aq_link_speed new_speed;
Shannon Nelsona9165492015-09-03 17:19:00 -04005351 char *speed = "Unknown";
5352 char *fc = "Unknown";
Henry Tieman3e03d7c2016-12-02 12:32:57 -08005353 char *fec = "";
5354 char *an = "";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005355
Filip Sadowski7ec9ba12016-11-08 13:05:13 -08005356 new_speed = vsi->back->hw.phy.link_info.link_speed;
5357
5358 if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed))
Matt Jaredc156f852015-08-27 11:42:39 -04005359 return;
5360 vsi->current_isup = isup;
Filip Sadowski7ec9ba12016-11-08 13:05:13 -08005361 vsi->current_speed = new_speed;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005362 if (!isup) {
5363 netdev_info(vsi->netdev, "NIC Link is Down\n");
5364 return;
5365 }
5366
Greg Rose148c2d82014-12-11 07:06:27 +00005367 /* Warn user if link speed on NPAR enabled partition is not at
5368 * least 10GB
5369 */
5370 if (vsi->back->hw.func_caps.npar_enable &&
5371 (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
5372 vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
5373 netdev_warn(vsi->netdev,
5374 "The partition detected link speed that is less than 10Gbps\n");
5375
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005376 switch (vsi->back->hw.phy.link_info.link_speed) {
5377 case I40E_LINK_SPEED_40GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005378 speed = "40 G";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005379 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -07005380 case I40E_LINK_SPEED_20GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005381 speed = "20 G";
Jesse Brandeburgae24b402015-03-27 00:12:09 -07005382 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -08005383 case I40E_LINK_SPEED_25GB:
5384 speed = "25 G";
5385 break;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005386 case I40E_LINK_SPEED_10GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005387 speed = "10 G";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005388 break;
5389 case I40E_LINK_SPEED_1GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005390 speed = "1000 M";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005391 break;
Mitch Williams5960d332014-09-13 07:40:47 +00005392 case I40E_LINK_SPEED_100MB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005393 speed = "100 M";
Mitch Williams5960d332014-09-13 07:40:47 +00005394 break;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005395 default:
5396 break;
5397 }
5398
5399 switch (vsi->back->hw.fc.current_mode) {
5400 case I40E_FC_FULL:
Shannon Nelsona9165492015-09-03 17:19:00 -04005401 fc = "RX/TX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005402 break;
5403 case I40E_FC_TX_PAUSE:
Shannon Nelsona9165492015-09-03 17:19:00 -04005404 fc = "TX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005405 break;
5406 case I40E_FC_RX_PAUSE:
Shannon Nelsona9165492015-09-03 17:19:00 -04005407 fc = "RX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005408 break;
5409 default:
Shannon Nelsona9165492015-09-03 17:19:00 -04005410 fc = "None";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005411 break;
5412 }
5413
Henry Tieman3e03d7c2016-12-02 12:32:57 -08005414 if (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) {
5415 fec = ", FEC: None";
5416 an = ", Autoneg: False";
5417
5418 if (vsi->back->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED)
5419 an = ", Autoneg: True";
5420
5421 if (vsi->back->hw.phy.link_info.fec_info &
5422 I40E_AQ_CONFIG_FEC_KR_ENA)
5423 fec = ", FEC: CL74 FC-FEC/BASE-R";
5424 else if (vsi->back->hw.phy.link_info.fec_info &
5425 I40E_AQ_CONFIG_FEC_RS_ENA)
5426 fec = ", FEC: CL108 RS-FEC";
5427 }
5428
5429 netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s, Flow Control: %s\n",
5430 speed, fec, an, fc);
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005431}
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005432
5433/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005434 * i40e_up_complete - Finish the last steps of bringing up a connection
5435 * @vsi: the VSI being configured
5436 **/
5437static int i40e_up_complete(struct i40e_vsi *vsi)
5438{
5439 struct i40e_pf *pf = vsi->back;
5440 int err;
5441
5442 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
5443 i40e_vsi_configure_msix(vsi);
5444 else
5445 i40e_configure_msi_and_legacy(vsi);
5446
5447 /* start rings */
Filip Sadowski3aa7b742016-10-11 15:26:58 -07005448 err = i40e_vsi_start_rings(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005449 if (err)
5450 return err;
5451
Jacob Keller0da36b92017-04-19 09:25:55 -04005452 clear_bit(__I40E_VSI_DOWN, vsi->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005453 i40e_napi_enable_all(vsi);
5454 i40e_vsi_enable_irq(vsi);
5455
5456 if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
5457 (vsi->netdev)) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005458 i40e_print_link_message(vsi, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005459 netif_tx_start_all_queues(vsi->netdev);
5460 netif_carrier_on(vsi->netdev);
Anjali Singhai6d779b42013-09-28 06:00:02 +00005461 } else if (vsi->netdev) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005462 i40e_print_link_message(vsi, false);
Carolyn Wyborny7b592f62014-07-10 07:58:19 +00005463 /* need to check for qualified module here*/
5464 if ((pf->hw.phy.link_info.link_info &
5465 I40E_AQ_MEDIA_AVAILABLE) &&
5466 (!(pf->hw.phy.link_info.an_info &
5467 I40E_AQ_QUALIFIED_MODULE)))
5468 netdev_err(vsi->netdev,
5469 "the driver failed to link because an unqualified module was detected.");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005470 }
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00005471
5472 /* replay FDIR SB filters */
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005473 if (vsi->type == I40E_VSI_FDIR) {
5474 /* reset fd counters */
Jacob Keller097dbf52017-02-06 14:38:46 -08005475 pf->fd_add_err = 0;
5476 pf->fd_atr_cnt = 0;
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00005477 i40e_fdir_filter_restore(vsi);
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005478 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06005479
5480 /* On the next run of the service_task, notify any clients of the new
5481 * opened netdev
5482 */
5483 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005484 i40e_service_event_schedule(pf);
5485
5486 return 0;
5487}
5488
5489/**
5490 * i40e_vsi_reinit_locked - Reset the VSI
5491 * @vsi: the VSI being configured
5492 *
5493 * Rebuild the ring structs after some configuration
5494 * has changed, e.g. MTU size.
5495 **/
5496static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
5497{
5498 struct i40e_pf *pf = vsi->back;
5499
5500 WARN_ON(in_interrupt());
Jacob Keller0da36b92017-04-19 09:25:55 -04005501 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005502 usleep_range(1000, 2000);
5503 i40e_down(vsi);
5504
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005505 i40e_up(vsi);
Jacob Keller0da36b92017-04-19 09:25:55 -04005506 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005507}
5508
5509/**
5510 * i40e_up - Bring the connection back up after being down
5511 * @vsi: the VSI being configured
5512 **/
5513int i40e_up(struct i40e_vsi *vsi)
5514{
5515 int err;
5516
5517 err = i40e_vsi_configure(vsi);
5518 if (!err)
5519 err = i40e_up_complete(vsi);
5520
5521 return err;
5522}
5523
5524/**
5525 * i40e_down - Shutdown the connection processing
5526 * @vsi: the VSI being stopped
5527 **/
5528void i40e_down(struct i40e_vsi *vsi)
5529{
5530 int i;
5531
5532 /* It is assumed that the caller of this function
Jacob Kellerd19cb642017-04-21 13:38:05 -07005533 * sets the vsi->state __I40E_VSI_DOWN bit.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005534 */
5535 if (vsi->netdev) {
5536 netif_carrier_off(vsi->netdev);
5537 netif_tx_disable(vsi->netdev);
5538 }
5539 i40e_vsi_disable_irq(vsi);
Filip Sadowski3aa7b742016-10-11 15:26:58 -07005540 i40e_vsi_stop_rings(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005541 i40e_napi_disable_all(vsi);
5542
5543 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00005544 i40e_clean_tx_ring(vsi->tx_rings[i]);
Björn Töpel74608d12017-05-24 07:55:35 +02005545 if (i40e_enabled_xdp_vsi(vsi))
5546 i40e_clean_tx_ring(vsi->xdp_rings[i]);
Alexander Duyck9f65e152013-09-28 06:00:58 +00005547 i40e_clean_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005548 }
Catherine Sullivanf980d442016-05-16 10:26:34 -07005549
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005550}
5551
5552/**
5553 * i40e_setup_tc - configure multiple traffic classes
5554 * @netdev: net device to configure
5555 * @tc: number of traffic classes to enable
5556 **/
5557static int i40e_setup_tc(struct net_device *netdev, u8 tc)
5558{
5559 struct i40e_netdev_priv *np = netdev_priv(netdev);
5560 struct i40e_vsi *vsi = np->vsi;
5561 struct i40e_pf *pf = vsi->back;
5562 u8 enabled_tc = 0;
5563 int ret = -EINVAL;
5564 int i;
5565
5566 /* Check if DCB enabled to continue */
5567 if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
5568 netdev_info(netdev, "DCB is not enabled for adapter\n");
5569 goto exit;
5570 }
5571
5572 /* Check if MFP enabled */
5573 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
5574 netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
5575 goto exit;
5576 }
5577
5578 /* Check whether tc count is within enabled limit */
5579 if (tc > i40e_pf_get_num_tc(pf)) {
5580 netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
5581 goto exit;
5582 }
5583
5584 /* Generate TC map for number of tc requested */
5585 for (i = 0; i < tc; i++)
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08005586 enabled_tc |= BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005587
5588 /* Requesting same TC configuration as already enabled */
5589 if (enabled_tc == vsi->tc_config.enabled_tc)
5590 return 0;
5591
5592 /* Quiesce VSI queues */
5593 i40e_quiesce_vsi(vsi);
5594
5595 /* Configure VSI for enabled TCs */
5596 ret = i40e_vsi_config_tc(vsi, enabled_tc);
5597 if (ret) {
5598 netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
5599 vsi->seid);
5600 goto exit;
5601 }
5602
5603 /* Unquiesce VSI */
5604 i40e_unquiesce_vsi(vsi);
5605
5606exit:
5607 return ret;
5608}
5609
Jiri Pirko2572ac52017-08-07 10:15:17 +02005610static int __i40e_setup_tc(struct net_device *netdev, enum tc_setup_type type,
Jiri Pirkode4784c2017-08-07 10:15:32 +02005611 void *type_data)
John Fastabende4c67342016-02-16 21:16:15 -08005612{
Jiri Pirkode4784c2017-08-07 10:15:32 +02005613 struct tc_mqprio_qopt *mqprio = type_data;
5614
Jiri Pirko2572ac52017-08-07 10:15:17 +02005615 if (type != TC_SETUP_MQPRIO)
Jiri Pirko38cf0422017-08-07 10:15:31 +02005616 return -EOPNOTSUPP;
Amritha Nambiar56f36ac2017-03-15 10:39:25 -07005617
Jiri Pirkode4784c2017-08-07 10:15:32 +02005618 mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
Amritha Nambiar56f36ac2017-03-15 10:39:25 -07005619
Jiri Pirkode4784c2017-08-07 10:15:32 +02005620 return i40e_setup_tc(netdev, mqprio->num_tc);
John Fastabende4c67342016-02-16 21:16:15 -08005621}
5622
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005623/**
5624 * i40e_open - Called when a network interface is made active
5625 * @netdev: network interface device structure
5626 *
5627 * The open entry point is called when a network interface is made
5628 * active by the system (IFF_UP). At this point all resources needed
5629 * for transmit and receive operations are allocated, the interrupt
5630 * handler is registered with the OS, the netdev watchdog subtask is
5631 * enabled, and the stack is notified that the interface is ready.
5632 *
5633 * Returns 0 on success, negative value on failure
5634 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005635int i40e_open(struct net_device *netdev)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005636{
5637 struct i40e_netdev_priv *np = netdev_priv(netdev);
5638 struct i40e_vsi *vsi = np->vsi;
5639 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005640 int err;
5641
Shannon Nelson4eb3f762014-03-06 08:59:58 +00005642 /* disallow open during test or if eeprom is broken */
Jacob Keller0da36b92017-04-19 09:25:55 -04005643 if (test_bit(__I40E_TESTING, pf->state) ||
5644 test_bit(__I40E_BAD_EEPROM, pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005645 return -EBUSY;
5646
5647 netif_carrier_off(netdev);
5648
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005649 err = i40e_vsi_open(vsi);
5650 if (err)
5651 return err;
5652
Jesse Brandeburg059dab62014-04-01 09:07:20 +00005653 /* configure global TSO hardware offload settings */
5654 wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
5655 TCP_FLAG_FIN) >> 16);
5656 wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
5657 TCP_FLAG_FIN |
5658 TCP_FLAG_CWR) >> 16);
5659 wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
5660
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07005661 udp_tunnel_get_rx_info(netdev);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06005662
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005663 return 0;
5664}
5665
5666/**
5667 * i40e_vsi_open -
5668 * @vsi: the VSI to open
5669 *
5670 * Finish initialization of the VSI.
5671 *
5672 * Returns 0 on success, negative value on failure
Maciej Sosin373149f2017-04-05 07:50:55 -04005673 *
5674 * Note: expects to be called while under rtnl_lock()
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005675 **/
5676int i40e_vsi_open(struct i40e_vsi *vsi)
5677{
5678 struct i40e_pf *pf = vsi->back;
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00005679 char int_name[I40E_INT_NAME_STR_LEN];
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005680 int err;
5681
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005682 /* allocate descriptors */
5683 err = i40e_vsi_setup_tx_resources(vsi);
5684 if (err)
5685 goto err_setup_tx;
5686 err = i40e_vsi_setup_rx_resources(vsi);
5687 if (err)
5688 goto err_setup_rx;
5689
5690 err = i40e_vsi_configure(vsi);
5691 if (err)
5692 goto err_setup_rx;
5693
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00005694 if (vsi->netdev) {
5695 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
5696 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
5697 err = i40e_vsi_request_irq(vsi, int_name);
5698 if (err)
5699 goto err_setup_rx;
5700
5701 /* Notify the stack of the actual queue counts. */
5702 err = netif_set_real_num_tx_queues(vsi->netdev,
5703 vsi->num_queue_pairs);
5704 if (err)
5705 goto err_set_queues;
5706
5707 err = netif_set_real_num_rx_queues(vsi->netdev,
5708 vsi->num_queue_pairs);
5709 if (err)
5710 goto err_set_queues;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005711
5712 } else if (vsi->type == I40E_VSI_FDIR) {
Carolyn Wybornye240f672014-12-11 07:06:37 +00005713 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +00005714 dev_driver_string(&pf->pdev->dev),
5715 dev_name(&pf->pdev->dev));
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005716 err = i40e_vsi_request_irq(vsi, int_name);
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +00005717
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00005718 } else {
Jean Sacrence9ccb12014-05-01 14:31:18 +00005719 err = -EINVAL;
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005720 goto err_setup_rx;
5721 }
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00005722
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005723 err = i40e_up_complete(vsi);
5724 if (err)
5725 goto err_up_complete;
5726
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005727 return 0;
5728
5729err_up_complete:
5730 i40e_down(vsi);
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00005731err_set_queues:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005732 i40e_vsi_free_irq(vsi);
5733err_setup_rx:
5734 i40e_vsi_free_rx_resources(vsi);
5735err_setup_tx:
5736 i40e_vsi_free_tx_resources(vsi);
5737 if (vsi == pf->vsi[pf->lan_vsi])
Maciej Sosin373149f2017-04-05 07:50:55 -04005738 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005739
5740 return err;
5741}
5742
5743/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005744 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00005745 * @pf: Pointer to PF
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005746 *
5747 * This function destroys the hlist where all the Flow Director
5748 * filters were saved.
5749 **/
5750static void i40e_fdir_filter_exit(struct i40e_pf *pf)
5751{
5752 struct i40e_fdir_filter *filter;
Jacob Keller0e588de2017-02-06 14:38:50 -08005753 struct i40e_flex_pit *pit_entry, *tmp;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005754 struct hlist_node *node2;
5755
5756 hlist_for_each_entry_safe(filter, node2,
5757 &pf->fdir_filter_list, fdir_node) {
5758 hlist_del(&filter->fdir_node);
5759 kfree(filter);
5760 }
Jacob Keller097dbf52017-02-06 14:38:46 -08005761
Jacob Keller0e588de2017-02-06 14:38:50 -08005762 list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) {
5763 list_del(&pit_entry->list);
5764 kfree(pit_entry);
5765 }
5766 INIT_LIST_HEAD(&pf->l3_flex_pit_list);
5767
5768 list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) {
5769 list_del(&pit_entry->list);
5770 kfree(pit_entry);
5771 }
5772 INIT_LIST_HEAD(&pf->l4_flex_pit_list);
5773
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005774 pf->fdir_pf_active_filters = 0;
Jacob Keller097dbf52017-02-06 14:38:46 -08005775 pf->fd_tcp4_filter_cnt = 0;
5776 pf->fd_udp4_filter_cnt = 0;
Jacob Kellerf223c872017-02-06 14:38:51 -08005777 pf->fd_sctp4_filter_cnt = 0;
Jacob Keller097dbf52017-02-06 14:38:46 -08005778 pf->fd_ip4_filter_cnt = 0;
Jacob Keller3bcee1e2017-02-06 14:38:46 -08005779
5780 /* Reprogram the default input set for TCP/IPv4 */
5781 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
5782 I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
5783 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
5784
5785 /* Reprogram the default input set for UDP/IPv4 */
5786 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP,
5787 I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
5788 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
5789
5790 /* Reprogram the default input set for SCTP/IPv4 */
5791 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP,
5792 I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
5793 I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
5794
5795 /* Reprogram the default input set for Other/IPv4 */
5796 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER,
5797 I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005798}
5799
5800/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005801 * i40e_close - Disables a network interface
5802 * @netdev: network interface device structure
5803 *
5804 * The close entry point is called when an interface is de-activated
5805 * by the OS. The hardware is still under the driver's control, but
5806 * this netdev interface is disabled.
5807 *
5808 * Returns 0, this is not allowed to fail
5809 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005810int i40e_close(struct net_device *netdev)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005811{
5812 struct i40e_netdev_priv *np = netdev_priv(netdev);
5813 struct i40e_vsi *vsi = np->vsi;
5814
Shannon Nelson90ef8d42014-03-14 07:32:26 +00005815 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005816
5817 return 0;
5818}
5819
5820/**
5821 * i40e_do_reset - Start a PF or Core Reset sequence
5822 * @pf: board private structure
5823 * @reset_flags: which reset is requested
Maciej Sosin373149f2017-04-05 07:50:55 -04005824 * @lock_acquired: indicates whether or not the lock has been acquired
5825 * before this function was called.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005826 *
5827 * The essential difference in resets is that the PF Reset
5828 * doesn't clear the packet buffers, doesn't reset the PE
5829 * firmware, and doesn't bother the other PFs on the chip.
5830 **/
Maciej Sosin373149f2017-04-05 07:50:55 -04005831void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005832{
5833 u32 val;
5834
5835 WARN_ON(in_interrupt());
5836
Mitch Williams263fc482014-04-23 04:50:11 +00005837
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005838 /* do the biggest reset indicated */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005839 if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005840
5841 /* Request a Global Reset
5842 *
5843 * This will start the chip's countdown to the actual full
5844 * chip reset event, and a warning interrupt to be sent
5845 * to all PFs, including the requestor. Our handler
5846 * for the warning interrupt will deal with the shutdown
5847 * and recovery of the switch setup.
5848 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005849 dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005850 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5851 val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
5852 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5853
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005854 } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005855
5856 /* Request a Core Reset
5857 *
5858 * Same as Global Reset, except does *not* include the MAC/PHY
5859 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005860 dev_dbg(&pf->pdev->dev, "CoreR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005861 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5862 val |= I40E_GLGEN_RTRIG_CORER_MASK;
5863 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5864 i40e_flush(&pf->hw);
5865
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005866 } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005867
5868 /* Request a PF Reset
5869 *
5870 * Resets only the PF-specific registers
5871 *
5872 * This goes directly to the tear-down and rebuild of
5873 * the switch, since we need to do all the recovery as
5874 * for the Core Reset.
5875 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005876 dev_dbg(&pf->pdev->dev, "PFR requested\n");
Maciej Sosin373149f2017-04-05 07:50:55 -04005877 i40e_handle_reset_warning(pf, lock_acquired);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005878
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005879 } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005880 int v;
5881
5882 /* Find the VSI(s) that requested a re-init */
5883 dev_info(&pf->pdev->dev,
5884 "VSI reinit requested\n");
Mitch Williams505682c2014-05-20 08:01:37 +00005885 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005886 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04005887
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005888 if (vsi != NULL &&
Jacob Kellerd19cb642017-04-21 13:38:05 -07005889 test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED,
Jacob Keller0da36b92017-04-19 09:25:55 -04005890 vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005891 i40e_vsi_reinit_locked(pf->vsi[v]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005892 }
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005893 } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005894 int v;
5895
5896 /* Find the VSI(s) that needs to be brought down */
5897 dev_info(&pf->pdev->dev, "VSI down requested\n");
5898 for (v = 0; v < pf->num_alloc_vsi; v++) {
5899 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04005900
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005901 if (vsi != NULL &&
Jacob Kellerd19cb642017-04-21 13:38:05 -07005902 test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED,
Jacob Keller0da36b92017-04-19 09:25:55 -04005903 vsi->state)) {
5904 set_bit(__I40E_VSI_DOWN, vsi->state);
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005905 i40e_down(vsi);
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005906 }
5907 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005908 } else {
5909 dev_info(&pf->pdev->dev,
5910 "bad reset request 0x%08x\n", reset_flags);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005911 }
5912}
5913
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005914#ifdef CONFIG_I40E_DCB
5915/**
5916 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
5917 * @pf: board private structure
5918 * @old_cfg: current DCB config
5919 * @new_cfg: new DCB config
5920 **/
5921bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
5922 struct i40e_dcbx_config *old_cfg,
5923 struct i40e_dcbx_config *new_cfg)
5924{
5925 bool need_reconfig = false;
5926
5927 /* Check if ETS configuration has changed */
5928 if (memcmp(&new_cfg->etscfg,
5929 &old_cfg->etscfg,
5930 sizeof(new_cfg->etscfg))) {
5931 /* If Priority Table has changed reconfig is needed */
5932 if (memcmp(&new_cfg->etscfg.prioritytable,
5933 &old_cfg->etscfg.prioritytable,
5934 sizeof(new_cfg->etscfg.prioritytable))) {
5935 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005936 dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005937 }
5938
5939 if (memcmp(&new_cfg->etscfg.tcbwtable,
5940 &old_cfg->etscfg.tcbwtable,
5941 sizeof(new_cfg->etscfg.tcbwtable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005942 dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005943
5944 if (memcmp(&new_cfg->etscfg.tsatable,
5945 &old_cfg->etscfg.tsatable,
5946 sizeof(new_cfg->etscfg.tsatable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005947 dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005948 }
5949
5950 /* Check if PFC configuration has changed */
5951 if (memcmp(&new_cfg->pfc,
5952 &old_cfg->pfc,
5953 sizeof(new_cfg->pfc))) {
5954 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005955 dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005956 }
5957
5958 /* Check if APP Table has changed */
5959 if (memcmp(&new_cfg->app,
5960 &old_cfg->app,
Dave Jones3d9667a2014-01-27 23:11:09 -05005961 sizeof(new_cfg->app))) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005962 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005963 dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
Dave Jones3d9667a2014-01-27 23:11:09 -05005964 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005965
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005966 dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005967 return need_reconfig;
5968}
5969
5970/**
5971 * i40e_handle_lldp_event - Handle LLDP Change MIB event
5972 * @pf: board private structure
5973 * @e: event info posted on ARQ
5974 **/
5975static int i40e_handle_lldp_event(struct i40e_pf *pf,
5976 struct i40e_arq_event_info *e)
5977{
5978 struct i40e_aqc_lldp_get_mib *mib =
5979 (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
5980 struct i40e_hw *hw = &pf->hw;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005981 struct i40e_dcbx_config tmp_dcbx_cfg;
5982 bool need_reconfig = false;
5983 int ret = 0;
5984 u8 type;
5985
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005986 /* Not DCB capable or capability disabled */
David Ertmanea6acb72016-09-20 07:10:50 -07005987 if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005988 return ret;
5989
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005990 /* Ignore if event is not for Nearest Bridge */
5991 type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
5992 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005993 dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005994 if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
5995 return ret;
5996
5997 /* Check MIB Type and return if event for Remote MIB update */
5998 type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005999 dev_dbg(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04006000 "LLDP event mib type %s\n", type ? "remote" : "local");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006001 if (type == I40E_AQ_LLDP_MIB_REMOTE) {
6002 /* Update the remote cached instance and return */
6003 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
6004 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
6005 &hw->remote_dcbx_config);
6006 goto exit;
6007 }
6008
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00006009 /* Store the old configuration */
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07006010 tmp_dcbx_cfg = hw->local_dcbx_config;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00006011
Neerav Parikh750fcbc2015-02-24 06:58:47 +00006012 /* Reset the old DCBx configuration data */
6013 memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00006014 /* Get updated DCBX data from firmware */
6015 ret = i40e_get_dcb_config(&pf->hw);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006016 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006017 dev_info(&pf->pdev->dev,
6018 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
6019 i40e_stat_str(&pf->hw, ret),
6020 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006021 goto exit;
6022 }
6023
6024 /* No change detected in DCBX configs */
Neerav Parikh750fcbc2015-02-24 06:58:47 +00006025 if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
6026 sizeof(tmp_dcbx_cfg))) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006027 dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006028 goto exit;
6029 }
6030
Neerav Parikh750fcbc2015-02-24 06:58:47 +00006031 need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
6032 &hw->local_dcbx_config);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006033
Neerav Parikh750fcbc2015-02-24 06:58:47 +00006034 i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006035
6036 if (!need_reconfig)
6037 goto exit;
6038
Neerav Parikh4d9b6042014-05-22 06:31:51 +00006039 /* Enable DCB tagging only when more than one TC */
Neerav Parikh750fcbc2015-02-24 06:58:47 +00006040 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
Neerav Parikh4d9b6042014-05-22 06:31:51 +00006041 pf->flags |= I40E_FLAG_DCB_ENABLED;
6042 else
6043 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
6044
Jacob Keller0da36b92017-04-19 09:25:55 -04006045 set_bit(__I40E_PORT_SUSPENDED, pf->state);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006046 /* Reconfiguration needed quiesce all VSIs */
6047 i40e_pf_quiesce_all_vsi(pf);
6048
6049 /* Changes in configuration update VEB/VSI */
6050 i40e_dcb_reconfigure(pf);
6051
Neerav Parikh2fd75f32014-11-12 00:18:20 +00006052 ret = i40e_resume_port_tx(pf);
6053
Jacob Keller0da36b92017-04-19 09:25:55 -04006054 clear_bit(__I40E_PORT_SUSPENDED, pf->state);
Neerav Parikh2fd75f32014-11-12 00:18:20 +00006055 /* In case of error no point in resuming VSIs */
Neerav Parikh69129dc2014-11-12 00:18:46 +00006056 if (ret)
6057 goto exit;
6058
Neerav Parikh3fe06f42016-02-17 16:12:15 -08006059 /* Wait for the PF's queues to be disabled */
6060 ret = i40e_pf_wait_queues_disabled(pf);
Parikh, Neerav11e47702015-02-21 06:43:55 +00006061 if (ret) {
6062 /* Schedule PF reset to recover */
Jacob Keller0da36b92017-04-19 09:25:55 -04006063 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
Parikh, Neerav11e47702015-02-21 06:43:55 +00006064 i40e_service_event_schedule(pf);
6065 } else {
Neerav Parikh2fd75f32014-11-12 00:18:20 +00006066 i40e_pf_unquiesce_all_vsi(pf);
Mitch Williams0ef2d5a2017-01-24 10:24:00 -08006067 pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED |
6068 I40E_FLAG_CLIENT_L2_CHANGE);
Parikh, Neerav11e47702015-02-21 06:43:55 +00006069 }
6070
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006071exit:
6072 return ret;
6073}
6074#endif /* CONFIG_I40E_DCB */
6075
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006076/**
Anjali Singhai Jain233261862013-11-26 10:49:22 +00006077 * i40e_do_reset_safe - Protected reset path for userland calls.
6078 * @pf: board private structure
6079 * @reset_flags: which reset is requested
6080 *
6081 **/
6082void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
6083{
6084 rtnl_lock();
Maciej Sosin373149f2017-04-05 07:50:55 -04006085 i40e_do_reset(pf, reset_flags, true);
Anjali Singhai Jain233261862013-11-26 10:49:22 +00006086 rtnl_unlock();
6087}
6088
6089/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006090 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
6091 * @pf: board private structure
6092 * @e: event info posted on ARQ
6093 *
6094 * Handler for LAN Queue Overflow Event generated by the firmware for PF
6095 * and VF queues
6096 **/
6097static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
6098 struct i40e_arq_event_info *e)
6099{
6100 struct i40e_aqc_lan_overflow *data =
6101 (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
6102 u32 queue = le32_to_cpu(data->prtdcb_rupto);
6103 u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
6104 struct i40e_hw *hw = &pf->hw;
6105 struct i40e_vf *vf;
6106 u16 vf_id;
6107
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006108 dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
6109 queue, qtx_ctl);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006110
6111 /* Queue belongs to VF, find the VF and issue VF reset */
6112 if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
6113 >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
6114 vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
6115 >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
6116 vf_id -= hw->func_caps.vf_base_id;
6117 vf = &pf->vf[vf_id];
6118 i40e_vc_notify_vf_reset(vf);
6119 /* Allow VF to process pending reset notification */
6120 msleep(20);
6121 i40e_reset_vf(vf, false);
6122 }
6123}
6124
6125/**
Anjali Singhai Jain12957382014-06-04 04:22:47 +00006126 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
6127 * @pf: board private structure
6128 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006129u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
Anjali Singhai Jain12957382014-06-04 04:22:47 +00006130{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006131 u32 val, fcnt_prog;
Anjali Singhai Jain12957382014-06-04 04:22:47 +00006132
6133 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
6134 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
6135 return fcnt_prog;
6136}
6137
6138/**
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006139 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006140 * @pf: board private structure
6141 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006142u32 i40e_get_current_fd_count(struct i40e_pf *pf)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006143{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006144 u32 val, fcnt_prog;
6145
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006146 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
6147 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
6148 ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
6149 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
6150 return fcnt_prog;
6151}
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006152
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006153/**
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006154 * i40e_get_global_fd_count - Get total FD filters programmed on device
6155 * @pf: board private structure
6156 **/
6157u32 i40e_get_global_fd_count(struct i40e_pf *pf)
6158{
6159 u32 val, fcnt_prog;
6160
6161 val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
6162 fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
6163 ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
6164 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
6165 return fcnt_prog;
6166}
6167
6168/**
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006169 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
6170 * @pf: board private structure
6171 **/
6172void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
6173{
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04006174 struct i40e_fdir_filter *filter;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006175 u32 fcnt_prog, fcnt_avail;
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04006176 struct hlist_node *node;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006177
Jacob Keller0da36b92017-04-19 09:25:55 -04006178 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006179 return;
6180
Jacob Keller47994c12017-04-19 09:25:57 -04006181 /* Check if we have enough room to re-enable FDir SB capability. */
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006182 fcnt_prog = i40e_get_global_fd_count(pf);
Anjali Singhai Jain12957382014-06-04 04:22:47 +00006183 fcnt_avail = pf->fdir_pf_filter_count;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006184 if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
6185 (pf->fd_add_err == 0) ||
6186 (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
Jacob Keller47994c12017-04-19 09:25:57 -04006187 if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED) {
6188 pf->flags &= ~I40E_FLAG_FD_SB_AUTO_DISABLED;
6189 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
6190 (I40E_DEBUG_FD & pf->hw.debug_mask))
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04006191 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 +00006192 }
6193 }
Jacob Kellera3417d22016-09-06 18:05:10 -07006194
Jacob Keller47994c12017-04-19 09:25:57 -04006195 /* We should wait for even more space before re-enabling ATR.
6196 * Additionally, we cannot enable ATR as long as we still have TCP SB
6197 * rules active.
Jacob Kellera3417d22016-09-06 18:05:10 -07006198 */
Jacob Keller47994c12017-04-19 09:25:57 -04006199 if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) &&
6200 (pf->fd_tcp4_filter_cnt == 0)) {
6201 if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) {
6202 pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
6203 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
6204 (I40E_DEBUG_FD & pf->hw.debug_mask))
Jacob Kellera3417d22016-09-06 18:05:10 -07006205 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 +00006206 }
6207 }
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04006208
6209 /* if hw had a problem adding a filter, delete it */
6210 if (pf->fd_inv > 0) {
6211 hlist_for_each_entry_safe(filter, node,
6212 &pf->fdir_filter_list, fdir_node) {
6213 if (filter->fd_id == pf->fd_inv) {
6214 hlist_del(&filter->fdir_node);
6215 kfree(filter);
6216 pf->fdir_pf_active_filters--;
6217 }
6218 }
6219 }
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006220}
6221
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006222#define I40E_MIN_FD_FLUSH_INTERVAL 10
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006223#define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006224/**
6225 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
6226 * @pf: board private structure
6227 **/
6228static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
6229{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006230 unsigned long min_flush_time;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006231 int flush_wait_retry = 50;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006232 bool disable_atr = false;
6233 int fd_room;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006234 int reg;
6235
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006236 if (!time_after(jiffies, pf->fd_flush_timestamp +
6237 (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
6238 return;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006239
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006240 /* If the flush is happening too quick and we have mostly SB rules we
6241 * should not re-enable ATR for some time.
6242 */
6243 min_flush_time = pf->fd_flush_timestamp +
6244 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
6245 fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006246
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006247 if (!(time_after(jiffies, min_flush_time)) &&
6248 (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
6249 if (I40E_DEBUG_FD & pf->hw.debug_mask)
6250 dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
6251 disable_atr = true;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006252 }
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006253
6254 pf->fd_flush_timestamp = jiffies;
Jacob Keller47994c12017-04-19 09:25:57 -04006255 pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006256 /* flush all filters */
6257 wr32(&pf->hw, I40E_PFQF_CTL_1,
6258 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
6259 i40e_flush(&pf->hw);
6260 pf->fd_flush_cnt++;
6261 pf->fd_add_err = 0;
6262 do {
6263 /* Check FD flush status every 5-6msec */
6264 usleep_range(5000, 6000);
6265 reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
6266 if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
6267 break;
6268 } while (flush_wait_retry--);
6269 if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
6270 dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
6271 } else {
6272 /* replay sideband filters */
6273 i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
Jacob Keller097dbf52017-02-06 14:38:46 -08006274 if (!disable_atr && !pf->fd_tcp4_filter_cnt)
Jacob Keller47994c12017-04-19 09:25:57 -04006275 pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
Jacob Keller0da36b92017-04-19 09:25:55 -04006276 clear_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006277 if (I40E_DEBUG_FD & pf->hw.debug_mask)
6278 dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
6279 }
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006280}
6281
6282/**
6283 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
6284 * @pf: board private structure
6285 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006286u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006287{
6288 return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
6289}
6290
6291/* We can see up to 256 filter programming desc in transit if the filters are
6292 * being applied really fast; before we see the first
6293 * filter miss error on Rx queue 0. Accumulating enough error messages before
6294 * reacting will make sure we don't cause flush too often.
6295 */
6296#define I40E_MAX_FD_PROGRAM_ERROR 256
6297
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006298/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006299 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
6300 * @pf: board private structure
6301 **/
6302static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
6303{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006304
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006305 /* if interface is down do nothing */
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -03006306 if (test_bit(__I40E_DOWN, pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006307 return;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006308
Jacob Keller0da36b92017-04-19 09:25:55 -04006309 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006310 i40e_fdir_flush_and_replay(pf);
6311
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006312 i40e_fdir_check_and_reenable(pf);
6313
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006314}
6315
6316/**
6317 * i40e_vsi_link_event - notify VSI of a link event
6318 * @vsi: vsi to be notified
6319 * @link_up: link up or down
6320 **/
6321static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
6322{
Jacob Keller0da36b92017-04-19 09:25:55 -04006323 if (!vsi || test_bit(__I40E_VSI_DOWN, vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006324 return;
6325
6326 switch (vsi->type) {
6327 case I40E_VSI_MAIN:
6328 if (!vsi->netdev || !vsi->netdev_registered)
6329 break;
6330
6331 if (link_up) {
6332 netif_carrier_on(vsi->netdev);
6333 netif_tx_wake_all_queues(vsi->netdev);
6334 } else {
6335 netif_carrier_off(vsi->netdev);
6336 netif_tx_stop_all_queues(vsi->netdev);
6337 }
6338 break;
6339
6340 case I40E_VSI_SRIOV:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006341 case I40E_VSI_VMDQ2:
6342 case I40E_VSI_CTRL:
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06006343 case I40E_VSI_IWARP:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006344 case I40E_VSI_MIRROR:
6345 default:
6346 /* there is no notification for other VSIs */
6347 break;
6348 }
6349}
6350
6351/**
6352 * i40e_veb_link_event - notify elements on the veb of a link event
6353 * @veb: veb to be notified
6354 * @link_up: link up or down
6355 **/
6356static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
6357{
6358 struct i40e_pf *pf;
6359 int i;
6360
6361 if (!veb || !veb->pf)
6362 return;
6363 pf = veb->pf;
6364
6365 /* depth first... */
6366 for (i = 0; i < I40E_MAX_VEB; i++)
6367 if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
6368 i40e_veb_link_event(pf->veb[i], link_up);
6369
6370 /* ... now the local VSIs */
Mitch Williams505682c2014-05-20 08:01:37 +00006371 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006372 if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
6373 i40e_vsi_link_event(pf->vsi[i], link_up);
6374}
6375
6376/**
6377 * i40e_link_event - Update netif_carrier status
6378 * @pf: board private structure
6379 **/
6380static void i40e_link_event(struct i40e_pf *pf)
6381{
Mitch Williams320684c2014-10-17 03:14:43 +00006382 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006383 u8 new_link_speed, old_link_speed;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006384 i40e_status status;
6385 bool new_link, old_link;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006386
Catherine Sullivan1f9610e2015-10-21 19:47:09 -04006387 /* save off old link status information */
6388 pf->hw.phy.link_info_old = pf->hw.phy.link_info;
6389
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006390 /* set this to force the get_link_status call to refresh state */
6391 pf->hw.phy.get_link_info = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006392
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006393 old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006394
6395 status = i40e_get_link_status(&pf->hw, &new_link);
Harshitha Ramamurthyae136702016-12-12 15:44:16 -08006396
6397 /* On success, disable temp link polling */
6398 if (status == I40E_SUCCESS) {
6399 if (pf->flags & I40E_FLAG_TEMP_LINK_POLLING)
6400 pf->flags &= ~I40E_FLAG_TEMP_LINK_POLLING;
6401 } else {
6402 /* Enable link polling temporarily until i40e_get_link_status
6403 * returns I40E_SUCCESS
6404 */
6405 pf->flags |= I40E_FLAG_TEMP_LINK_POLLING;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006406 dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
6407 status);
6408 return;
6409 }
6410
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006411 old_link_speed = pf->hw.phy.link_info_old.link_speed;
6412 new_link_speed = pf->hw.phy.link_info.link_speed;
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006413
6414 if (new_link == old_link &&
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006415 new_link_speed == old_link_speed &&
Jacob Keller0da36b92017-04-19 09:25:55 -04006416 (test_bit(__I40E_VSI_DOWN, vsi->state) ||
Mitch Williams320684c2014-10-17 03:14:43 +00006417 new_link == netif_carrier_ok(vsi->netdev)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006418 return;
Mitch Williams320684c2014-10-17 03:14:43 +00006419
Jacob Keller0da36b92017-04-19 09:25:55 -04006420 if (!test_bit(__I40E_VSI_DOWN, vsi->state))
Mitch Williams320684c2014-10-17 03:14:43 +00006421 i40e_print_link_message(vsi, new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006422
6423 /* Notify the base of the switch tree connected to
6424 * the link. Floating VEBs are not notified.
6425 */
6426 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
6427 i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
6428 else
Mitch Williams320684c2014-10-17 03:14:43 +00006429 i40e_vsi_link_event(vsi, new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006430
6431 if (pf->vf)
6432 i40e_vc_notify_link_state(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00006433
6434 if (pf->flags & I40E_FLAG_PTP)
6435 i40e_ptp_set_increment(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006436}
6437
6438/**
Shannon Nelson21536712014-10-25 10:35:25 +00006439 * i40e_watchdog_subtask - periodic checks not using event driven response
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006440 * @pf: board private structure
6441 **/
6442static void i40e_watchdog_subtask(struct i40e_pf *pf)
6443{
6444 int i;
6445
6446 /* if interface is down do nothing */
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -03006447 if (test_bit(__I40E_DOWN, pf->state) ||
Jacob Keller0da36b92017-04-19 09:25:55 -04006448 test_bit(__I40E_CONFIG_BUSY, pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006449 return;
6450
Shannon Nelson21536712014-10-25 10:35:25 +00006451 /* make sure we don't do these things too often */
6452 if (time_before(jiffies, (pf->service_timer_previous +
6453 pf->service_timer_period)))
6454 return;
6455 pf->service_timer_previous = jiffies;
6456
Harshitha Ramamurthyae136702016-12-12 15:44:16 -08006457 if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) ||
6458 (pf->flags & I40E_FLAG_TEMP_LINK_POLLING))
Shannon Nelson9ac77262015-08-27 11:42:40 -04006459 i40e_link_event(pf);
Shannon Nelson21536712014-10-25 10:35:25 +00006460
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006461 /* Update the stats for active netdevs so the network stack
6462 * can look at updated numbers whenever it cares to
6463 */
Mitch Williams505682c2014-05-20 08:01:37 +00006464 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006465 if (pf->vsi[i] && pf->vsi[i]->netdev)
6466 i40e_update_stats(pf->vsi[i]);
6467
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04006468 if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
6469 /* Update the stats for the active switching components */
6470 for (i = 0; i < I40E_MAX_VEB; i++)
6471 if (pf->veb[i])
6472 i40e_update_veb_stats(pf->veb[i]);
6473 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00006474
Jacob Keller61189552017-05-03 10:29:01 -07006475 i40e_ptp_rx_hang(pf);
Jacob Keller0bc07062017-05-03 10:29:02 -07006476 i40e_ptp_tx_hang(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006477}
6478
6479/**
6480 * i40e_reset_subtask - Set up for resetting the device and driver
6481 * @pf: board private structure
6482 **/
6483static void i40e_reset_subtask(struct i40e_pf *pf)
6484{
6485 u32 reset_flags = 0;
6486
Jacob Keller0da36b92017-04-19 09:25:55 -04006487 if (test_bit(__I40E_REINIT_REQUESTED, pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006488 reset_flags |= BIT(__I40E_REINIT_REQUESTED);
Jacob Keller0da36b92017-04-19 09:25:55 -04006489 clear_bit(__I40E_REINIT_REQUESTED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006490 }
Jacob Keller0da36b92017-04-19 09:25:55 -04006491 if (test_bit(__I40E_PF_RESET_REQUESTED, pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006492 reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
Jacob Keller0da36b92017-04-19 09:25:55 -04006493 clear_bit(__I40E_PF_RESET_REQUESTED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006494 }
Jacob Keller0da36b92017-04-19 09:25:55 -04006495 if (test_bit(__I40E_CORE_RESET_REQUESTED, pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006496 reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
Jacob Keller0da36b92017-04-19 09:25:55 -04006497 clear_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006498 }
Jacob Keller0da36b92017-04-19 09:25:55 -04006499 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006500 reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
Jacob Keller0da36b92017-04-19 09:25:55 -04006501 clear_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006502 }
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -03006503 if (test_bit(__I40E_DOWN_REQUESTED, pf->state)) {
6504 reset_flags |= BIT(__I40E_DOWN_REQUESTED);
6505 clear_bit(__I40E_DOWN_REQUESTED, pf->state);
Neerav Parikhb5d06f02014-06-03 23:50:17 +00006506 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006507
6508 /* If there's a recovery already waiting, it takes
6509 * precedence before starting a new reset sequence.
6510 */
Jacob Keller0da36b92017-04-19 09:25:55 -04006511 if (test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) {
Maciej Sosin373149f2017-04-05 07:50:55 -04006512 i40e_prep_for_reset(pf, false);
6513 i40e_reset(pf);
6514 i40e_rebuild(pf, false, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006515 }
6516
6517 /* If we're already down or resetting, just bail */
6518 if (reset_flags &&
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -03006519 !test_bit(__I40E_DOWN, pf->state) &&
Jacob Keller0da36b92017-04-19 09:25:55 -04006520 !test_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellerdfc4ff62017-06-07 05:43:13 -04006521 i40e_do_reset(pf, reset_flags, false);
Maciej Sosin373149f2017-04-05 07:50:55 -04006522 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006523}
6524
6525/**
6526 * i40e_handle_link_event - Handle link event
6527 * @pf: board private structure
6528 * @e: event info posted on ARQ
6529 **/
6530static void i40e_handle_link_event(struct i40e_pf *pf,
6531 struct i40e_arq_event_info *e)
6532{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006533 struct i40e_aqc_get_link_status *status =
6534 (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006535
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006536 /* Do a new status request to re-enable LSE reporting
6537 * and load new status information into the hw struct
6538 * This completely ignores any state information
6539 * in the ARQ event info, instead choosing to always
6540 * issue the AQ update link status command.
6541 */
6542 i40e_link_event(pf);
6543
Carolyn Wyborny7b592f62014-07-10 07:58:19 +00006544 /* check for unqualified module, if link is down */
6545 if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
6546 (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
6547 (!(status->link_info & I40E_AQ_LINK_UP)))
6548 dev_err(&pf->pdev->dev,
6549 "The driver failed to link because an unqualified module was detected.\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006550}
6551
6552/**
6553 * i40e_clean_adminq_subtask - Clean the AdminQ rings
6554 * @pf: board private structure
6555 **/
6556static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
6557{
6558 struct i40e_arq_event_info event;
6559 struct i40e_hw *hw = &pf->hw;
6560 u16 pending, i = 0;
6561 i40e_status ret;
6562 u16 opcode;
Shannon Nelson86df2422014-05-20 08:01:35 +00006563 u32 oldval;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006564 u32 val;
6565
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006566 /* Do not run clean AQ when PF reset fails */
Jacob Keller0da36b92017-04-19 09:25:55 -04006567 if (test_bit(__I40E_RESET_FAILED, pf->state))
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006568 return;
6569
Shannon Nelson86df2422014-05-20 08:01:35 +00006570 /* check for error indications */
6571 val = rd32(&pf->hw, pf->hw.aq.arq.len);
6572 oldval = val;
6573 if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006574 if (hw->debug_mask & I40E_DEBUG_AQ)
6575 dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006576 val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
6577 }
6578 if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006579 if (hw->debug_mask & I40E_DEBUG_AQ)
6580 dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006581 val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
Mitch Williams1d0a4ad2015-12-23 12:05:48 -08006582 pf->arq_overflows++;
Shannon Nelson86df2422014-05-20 08:01:35 +00006583 }
6584 if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006585 if (hw->debug_mask & I40E_DEBUG_AQ)
6586 dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006587 val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
6588 }
6589 if (oldval != val)
6590 wr32(&pf->hw, pf->hw.aq.arq.len, val);
6591
6592 val = rd32(&pf->hw, pf->hw.aq.asq.len);
6593 oldval = val;
6594 if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006595 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6596 dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006597 val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
6598 }
6599 if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006600 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6601 dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006602 val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
6603 }
6604 if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006605 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6606 dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006607 val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
6608 }
6609 if (oldval != val)
6610 wr32(&pf->hw, pf->hw.aq.asq.len, val);
6611
Mitch Williams1001dc32014-11-11 20:02:19 +00006612 event.buf_len = I40E_MAX_AQ_BUF_SIZE;
6613 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006614 if (!event.msg_buf)
6615 return;
6616
6617 do {
6618 ret = i40e_clean_arq_element(hw, &event, &pending);
Mitch Williams56497972014-06-04 08:45:18 +00006619 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006620 break;
Mitch Williams56497972014-06-04 08:45:18 +00006621 else if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006622 dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
6623 break;
6624 }
6625
6626 opcode = le16_to_cpu(event.desc.opcode);
6627 switch (opcode) {
6628
6629 case i40e_aqc_opc_get_link_status:
6630 i40e_handle_link_event(pf, &event);
6631 break;
6632 case i40e_aqc_opc_send_msg_to_pf:
6633 ret = i40e_vc_process_vf_msg(pf,
6634 le16_to_cpu(event.desc.retval),
6635 le32_to_cpu(event.desc.cookie_high),
6636 le32_to_cpu(event.desc.cookie_low),
6637 event.msg_buf,
Mitch Williams1001dc32014-11-11 20:02:19 +00006638 event.msg_len);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006639 break;
6640 case i40e_aqc_opc_lldp_update_mib:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006641 dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006642#ifdef CONFIG_I40E_DCB
6643 rtnl_lock();
6644 ret = i40e_handle_lldp_event(pf, &event);
6645 rtnl_unlock();
6646#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006647 break;
6648 case i40e_aqc_opc_event_lan_overflow:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006649 dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006650 i40e_handle_lan_overflow_event(pf, &event);
6651 break;
Shannon Nelson0467bc92013-12-18 13:45:58 +00006652 case i40e_aqc_opc_send_msg_to_peer:
6653 dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
6654 break;
Shannon Nelson91a0f932015-03-19 14:32:01 -07006655 case i40e_aqc_opc_nvm_erase:
6656 case i40e_aqc_opc_nvm_update:
Michal Kosiarz00ada502015-11-19 11:34:20 -08006657 case i40e_aqc_opc_oem_post_update:
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08006658 i40e_debug(&pf->hw, I40E_DEBUG_NVM,
6659 "ARQ NVM operation 0x%04x completed\n",
6660 opcode);
Shannon Nelson91a0f932015-03-19 14:32:01 -07006661 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006662 default:
6663 dev_info(&pf->pdev->dev,
Shannon Nelson56e5ca62016-03-10 14:59:48 -08006664 "ARQ: Unknown event 0x%04x ignored\n",
Shannon Nelson0467bc92013-12-18 13:45:58 +00006665 opcode);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006666 break;
6667 }
Christopher N Bednarz1fca3262017-03-10 12:22:03 -08006668 } while (i++ < pf->adminq_work_limit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006669
Christopher N Bednarz1fca3262017-03-10 12:22:03 -08006670 if (i < pf->adminq_work_limit)
Jacob Keller0da36b92017-04-19 09:25:55 -04006671 clear_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
Christopher N Bednarz1fca3262017-03-10 12:22:03 -08006672
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006673 /* re-enable Admin queue interrupt cause */
6674 val = rd32(hw, I40E_PFINT_ICR0_ENA);
6675 val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
6676 wr32(hw, I40E_PFINT_ICR0_ENA, val);
6677 i40e_flush(hw);
6678
6679 kfree(event.msg_buf);
6680}
6681
6682/**
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006683 * i40e_verify_eeprom - make sure eeprom is good to use
6684 * @pf: board private structure
6685 **/
6686static void i40e_verify_eeprom(struct i40e_pf *pf)
6687{
6688 int err;
6689
6690 err = i40e_diag_eeprom_test(&pf->hw);
6691 if (err) {
6692 /* retry in case of garbage read */
6693 err = i40e_diag_eeprom_test(&pf->hw);
6694 if (err) {
6695 dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
6696 err);
Jacob Keller0da36b92017-04-19 09:25:55 -04006697 set_bit(__I40E_BAD_EEPROM, pf->state);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006698 }
6699 }
6700
Jacob Keller0da36b92017-04-19 09:25:55 -04006701 if (!err && test_bit(__I40E_BAD_EEPROM, pf->state)) {
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006702 dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
Jacob Keller0da36b92017-04-19 09:25:55 -04006703 clear_bit(__I40E_BAD_EEPROM, pf->state);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006704 }
6705}
6706
6707/**
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006708 * i40e_enable_pf_switch_lb
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006709 * @pf: pointer to the PF structure
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006710 *
6711 * enable switch loop back or die - no point in a return value
6712 **/
6713static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
6714{
6715 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6716 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006717 int ret;
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006718
6719 ctxt.seid = pf->main_vsi_seid;
6720 ctxt.pf_num = pf->hw.pf_id;
6721 ctxt.vf_num = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006722 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6723 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006724 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006725 "couldn't get PF vsi config, err %s aq_err %s\n",
6726 i40e_stat_str(&pf->hw, ret),
6727 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006728 return;
6729 }
6730 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6731 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6732 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6733
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006734 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6735 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006736 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006737 "update vsi switch failed, err %s aq_err %s\n",
6738 i40e_stat_str(&pf->hw, ret),
6739 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006740 }
6741}
6742
6743/**
6744 * i40e_disable_pf_switch_lb
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006745 * @pf: pointer to the PF structure
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006746 *
6747 * disable switch loop back or die - no point in a return value
6748 **/
6749static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
6750{
6751 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6752 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006753 int ret;
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006754
6755 ctxt.seid = pf->main_vsi_seid;
6756 ctxt.pf_num = pf->hw.pf_id;
6757 ctxt.vf_num = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006758 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6759 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006760 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006761 "couldn't get PF vsi config, err %s aq_err %s\n",
6762 i40e_stat_str(&pf->hw, ret),
6763 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006764 return;
6765 }
6766 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6767 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6768 ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6769
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006770 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6771 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006772 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006773 "update vsi switch failed, err %s aq_err %s\n",
6774 i40e_stat_str(&pf->hw, ret),
6775 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006776 }
6777}
6778
6779/**
Neerav Parikh51616012015-02-06 08:52:14 +00006780 * i40e_config_bridge_mode - Configure the HW bridge mode
6781 * @veb: pointer to the bridge instance
6782 *
6783 * Configure the loop back mode for the LAN VSI that is downlink to the
6784 * specified HW bridge instance. It is expected this function is called
6785 * when a new HW bridge is instantiated.
6786 **/
6787static void i40e_config_bridge_mode(struct i40e_veb *veb)
6788{
6789 struct i40e_pf *pf = veb->pf;
6790
Shannon Nelson6dec1012015-09-28 14:12:30 -04006791 if (pf->hw.debug_mask & I40E_DEBUG_LAN)
6792 dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
6793 veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
Neerav Parikh51616012015-02-06 08:52:14 +00006794 if (veb->bridge_mode & BRIDGE_MODE_VEPA)
6795 i40e_disable_pf_switch_lb(pf);
6796 else
6797 i40e_enable_pf_switch_lb(pf);
6798}
6799
6800/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006801 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
6802 * @veb: pointer to the VEB instance
6803 *
6804 * This is a recursive function that first builds the attached VSIs then
6805 * recurses in to build the next layer of VEB. We track the connections
6806 * through our own index numbers because the seid's from the HW could
6807 * change across the reset.
6808 **/
6809static int i40e_reconstitute_veb(struct i40e_veb *veb)
6810{
6811 struct i40e_vsi *ctl_vsi = NULL;
6812 struct i40e_pf *pf = veb->pf;
6813 int v, veb_idx;
6814 int ret;
6815
6816 /* build VSI that owns this VEB, temporarily attached to base VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00006817 for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006818 if (pf->vsi[v] &&
6819 pf->vsi[v]->veb_idx == veb->idx &&
6820 pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
6821 ctl_vsi = pf->vsi[v];
6822 break;
6823 }
6824 }
6825 if (!ctl_vsi) {
6826 dev_info(&pf->pdev->dev,
6827 "missing owner VSI for veb_idx %d\n", veb->idx);
6828 ret = -ENOENT;
6829 goto end_reconstitute;
6830 }
6831 if (ctl_vsi != pf->vsi[pf->lan_vsi])
6832 ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
6833 ret = i40e_add_vsi(ctl_vsi);
6834 if (ret) {
6835 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006836 "rebuild of veb_idx %d owner VSI failed: %d\n",
6837 veb->idx, ret);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006838 goto end_reconstitute;
6839 }
6840 i40e_vsi_reset_stats(ctl_vsi);
6841
6842 /* create the VEB in the switch and move the VSI onto the VEB */
6843 ret = i40e_add_veb(veb, ctl_vsi);
6844 if (ret)
6845 goto end_reconstitute;
6846
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07006847 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
6848 veb->bridge_mode = BRIDGE_MODE_VEB;
6849 else
6850 veb->bridge_mode = BRIDGE_MODE_VEPA;
Neerav Parikh51616012015-02-06 08:52:14 +00006851 i40e_config_bridge_mode(veb);
Anjali Singhai Jainb64ba082014-11-13 03:06:15 +00006852
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006853 /* create the remaining VSIs attached to this VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00006854 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006855 if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
6856 continue;
6857
6858 if (pf->vsi[v]->veb_idx == veb->idx) {
6859 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04006860
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006861 vsi->uplink_seid = veb->seid;
6862 ret = i40e_add_vsi(vsi);
6863 if (ret) {
6864 dev_info(&pf->pdev->dev,
6865 "rebuild of vsi_idx %d failed: %d\n",
6866 v, ret);
6867 goto end_reconstitute;
6868 }
6869 i40e_vsi_reset_stats(vsi);
6870 }
6871 }
6872
6873 /* create any VEBs attached to this VEB - RECURSION */
6874 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
6875 if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
6876 pf->veb[veb_idx]->uplink_seid = veb->seid;
6877 ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
6878 if (ret)
6879 break;
6880 }
6881 }
6882
6883end_reconstitute:
6884 return ret;
6885}
6886
6887/**
6888 * i40e_get_capabilities - get info about the HW
6889 * @pf: the PF struct
6890 **/
6891static int i40e_get_capabilities(struct i40e_pf *pf)
6892{
6893 struct i40e_aqc_list_capabilities_element_resp *cap_buf;
6894 u16 data_size;
6895 int buf_len;
6896 int err;
6897
6898 buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
6899 do {
6900 cap_buf = kzalloc(buf_len, GFP_KERNEL);
6901 if (!cap_buf)
6902 return -ENOMEM;
6903
6904 /* this loads the data into the hw struct for us */
6905 err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
6906 &data_size,
6907 i40e_aqc_opc_list_func_capabilities,
6908 NULL);
6909 /* data loaded, buffer no longer needed */
6910 kfree(cap_buf);
6911
6912 if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
6913 /* retry with a larger buffer */
6914 buf_len = data_size;
6915 } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
6916 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006917 "capability discovery failed, err %s aq_err %s\n",
6918 i40e_stat_str(&pf->hw, err),
6919 i40e_aq_str(&pf->hw,
6920 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006921 return -ENODEV;
6922 }
6923 } while (err);
6924
6925 if (pf->hw.debug_mask & I40E_DEBUG_USER)
6926 dev_info(&pf->pdev->dev,
6927 "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",
6928 pf->hw.pf_id, pf->hw.func_caps.num_vfs,
6929 pf->hw.func_caps.num_msix_vectors,
6930 pf->hw.func_caps.num_msix_vectors_vf,
6931 pf->hw.func_caps.fd_filters_guaranteed,
6932 pf->hw.func_caps.fd_filters_best_effort,
6933 pf->hw.func_caps.num_tx_qp,
6934 pf->hw.func_caps.num_vsis);
6935
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00006936#define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
6937 + pf->hw.func_caps.num_vfs)
6938 if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
6939 dev_info(&pf->pdev->dev,
6940 "got num_vsis %d, setting num_vsis to %d\n",
6941 pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
6942 pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
6943 }
6944
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006945 return 0;
6946}
6947
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006948static int i40e_vsi_clear(struct i40e_vsi *vsi);
6949
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006950/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006951 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006952 * @pf: board private structure
6953 **/
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006954static void i40e_fdir_sb_setup(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006955{
6956 struct i40e_vsi *vsi;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006957
Jesse Brandeburg407e0632014-06-03 23:50:12 +00006958 /* quick workaround for an NVM issue that leaves a critical register
6959 * uninitialized
6960 */
6961 if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
6962 static const u32 hkey[] = {
6963 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
6964 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
6965 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
6966 0x95b3a76d};
Alexander Duyck4b816442016-10-11 15:26:53 -07006967 int i;
Jesse Brandeburg407e0632014-06-03 23:50:12 +00006968
6969 for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
6970 wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
6971 }
6972
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006973 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006974 return;
6975
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006976 /* find existing VSI and see if it needs configuring */
Alexander Duyck4b816442016-10-11 15:26:53 -07006977 vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006978
6979 /* create a new VSI if none exists */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006980 if (!vsi) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006981 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
6982 pf->vsi[pf->lan_vsi]->seid, 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006983 if (!vsi) {
6984 dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006985 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
6986 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006987 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006988 }
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006989
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006990 i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006991}
6992
6993/**
6994 * i40e_fdir_teardown - release the Flow Director resources
6995 * @pf: board private structure
6996 **/
6997static void i40e_fdir_teardown(struct i40e_pf *pf)
6998{
Alexander Duyck4b816442016-10-11 15:26:53 -07006999 struct i40e_vsi *vsi;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007000
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00007001 i40e_fdir_filter_exit(pf);
Alexander Duyck4b816442016-10-11 15:26:53 -07007002 vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
7003 if (vsi)
7004 i40e_vsi_release(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007005}
7006
7007/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007008 * i40e_prep_for_reset - prep for the core to reset
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007009 * @pf: board private structure
Maciej Sosin373149f2017-04-05 07:50:55 -04007010 * @lock_acquired: indicates whether or not the lock has been acquired
7011 * before this function was called.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007012 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00007013 * Close up the VFs and other things in prep for PF Reset.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007014 **/
Maciej Sosin373149f2017-04-05 07:50:55 -04007015static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007016{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007017 struct i40e_hw *hw = &pf->hw;
Shannon Nelson60442de2014-04-23 04:50:13 +00007018 i40e_status ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007019 u32 v;
7020
Jacob Keller0da36b92017-04-19 09:25:55 -04007021 clear_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
7022 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
Shannon Nelson23cfbe02014-06-04 01:23:14 +00007023 return;
Mitch Williamsd3ce57342016-03-10 14:59:46 -08007024 if (i40e_check_asq_alive(&pf->hw))
7025 i40e_vc_notify_reset(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007026
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00007027 dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007028
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007029 /* quiesce the VSIs and their queues that are not already DOWN */
Maciej Sosin373149f2017-04-05 07:50:55 -04007030 /* pf_quiesce_all_vsi modifies netdev structures -rtnl_lock needed */
7031 if (!lock_acquired)
7032 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007033 i40e_pf_quiesce_all_vsi(pf);
Maciej Sosin373149f2017-04-05 07:50:55 -04007034 if (!lock_acquired)
7035 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007036
Mitch Williams505682c2014-05-20 08:01:37 +00007037 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007038 if (pf->vsi[v])
7039 pf->vsi[v]->seid = 0;
7040 }
7041
7042 i40e_shutdown_adminq(&pf->hw);
7043
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007044 /* call shutdown HMC */
Shannon Nelson60442de2014-04-23 04:50:13 +00007045 if (hw->hmc.hmc_obj) {
7046 ret = i40e_shutdown_lan_hmc(hw);
Shannon Nelson23cfbe02014-06-04 01:23:14 +00007047 if (ret)
Shannon Nelson60442de2014-04-23 04:50:13 +00007048 dev_warn(&pf->pdev->dev,
7049 "shutdown_lan_hmc failed: %d\n", ret);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007050 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007051}
7052
7053/**
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00007054 * i40e_send_version - update firmware with driver version
7055 * @pf: PF struct
7056 */
7057static void i40e_send_version(struct i40e_pf *pf)
7058{
7059 struct i40e_driver_version dv;
7060
7061 dv.major_version = DRV_VERSION_MAJOR;
7062 dv.minor_version = DRV_VERSION_MINOR;
7063 dv.build_version = DRV_VERSION_BUILD;
7064 dv.subbuild_version = 0;
Rickard Strandqvist35a7d802014-07-29 09:26:25 +00007065 strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00007066 i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
7067}
7068
7069/**
Filip Sadowski5bbb2e22017-06-07 05:43:09 -04007070 * i40e_get_oem_version - get OEM specific version information
7071 * @hw: pointer to the hardware structure
7072 **/
7073static void i40e_get_oem_version(struct i40e_hw *hw)
7074{
7075 u16 block_offset = 0xffff;
7076 u16 block_length = 0;
7077 u16 capabilities = 0;
7078 u16 gen_snap = 0;
7079 u16 release = 0;
7080
7081#define I40E_SR_NVM_OEM_VERSION_PTR 0x1B
7082#define I40E_NVM_OEM_LENGTH_OFFSET 0x00
7083#define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01
7084#define I40E_NVM_OEM_GEN_OFFSET 0x02
7085#define I40E_NVM_OEM_RELEASE_OFFSET 0x03
7086#define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F
7087#define I40E_NVM_OEM_LENGTH 3
7088
7089 /* Check if pointer to OEM version block is valid. */
7090 i40e_read_nvm_word(hw, I40E_SR_NVM_OEM_VERSION_PTR, &block_offset);
7091 if (block_offset == 0xffff)
7092 return;
7093
7094 /* Check if OEM version block has correct length. */
7095 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_LENGTH_OFFSET,
7096 &block_length);
7097 if (block_length < I40E_NVM_OEM_LENGTH)
7098 return;
7099
7100 /* Check if OEM version format is as expected. */
7101 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_CAPABILITIES_OFFSET,
7102 &capabilities);
7103 if ((capabilities & I40E_NVM_OEM_CAPABILITIES_MASK) != 0)
7104 return;
7105
7106 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_GEN_OFFSET,
7107 &gen_snap);
7108 i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_RELEASE_OFFSET,
7109 &release);
7110 hw->nvm.oem_ver = (gen_snap << I40E_OEM_SNAP_SHIFT) | release;
7111 hw->nvm.eetrack = I40E_OEM_EETRACK_ID;
7112}
7113
7114/**
Maciej Sosin373149f2017-04-05 07:50:55 -04007115 * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen
7116 * @pf: board private structure
7117 **/
7118static int i40e_reset(struct i40e_pf *pf)
7119{
7120 struct i40e_hw *hw = &pf->hw;
7121 i40e_status ret;
7122
7123 ret = i40e_pf_reset(hw);
7124 if (ret) {
7125 dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
Jacob Keller0da36b92017-04-19 09:25:55 -04007126 set_bit(__I40E_RESET_FAILED, pf->state);
7127 clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04007128 } else {
7129 pf->pfr_count++;
7130 }
7131 return ret;
7132}
7133
7134/**
7135 * i40e_rebuild - rebuild using a saved config
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007136 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007137 * @reinit: if the Main VSI needs to re-initialized.
Maciej Sosin373149f2017-04-05 07:50:55 -04007138 * @lock_acquired: indicates whether or not the lock has been acquired
7139 * before this function was called.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007140 **/
Maciej Sosin373149f2017-04-05 07:50:55 -04007141static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007142{
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007143 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00007144 u8 set_fc_aq_fail = 0;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007145 i40e_status ret;
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -04007146 u32 val;
Maciej Sosin373149f2017-04-05 07:50:55 -04007147 int v;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007148
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -03007149 if (test_bit(__I40E_DOWN, pf->state))
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00007150 goto clear_recovery;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00007151 dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007152
7153 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
7154 ret = i40e_init_adminq(&pf->hw);
7155 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007156 dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
7157 i40e_stat_str(&pf->hw, ret),
7158 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00007159 goto clear_recovery;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007160 }
Filip Sadowski5bbb2e22017-06-07 05:43:09 -04007161 i40e_get_oem_version(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007162
Shannon Nelson4eb3f762014-03-06 08:59:58 +00007163 /* re-verify the eeprom if we just had an EMP reset */
Jacob Keller0da36b92017-04-19 09:25:55 -04007164 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson4eb3f762014-03-06 08:59:58 +00007165 i40e_verify_eeprom(pf);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00007166
Shannon Nelsone78ac4bf2014-05-10 04:49:09 +00007167 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007168 ret = i40e_get_capabilities(pf);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007169 if (ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007170 goto end_core_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007171
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007172 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
Alexander Duyckc76cb6e2017-02-21 15:55:48 -08007173 hw->func_caps.num_rx_qp, 0, 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007174 if (ret) {
7175 dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
7176 goto end_core_reset;
7177 }
7178 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
7179 if (ret) {
7180 dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
7181 goto end_core_reset;
7182 }
7183
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08007184#ifdef CONFIG_I40E_DCB
7185 ret = i40e_init_pf_dcb(pf);
7186 if (ret) {
Shannon Nelsonaebfc812014-12-11 07:06:38 +00007187 dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
7188 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
7189 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08007190 }
7191#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007192 /* do basic switch setup */
Maciej Sosin373149f2017-04-05 07:50:55 -04007193 if (!lock_acquired)
7194 rtnl_lock();
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007195 ret = i40e_setup_pf_switch(pf, reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007196 if (ret)
Maciej Sosin373149f2017-04-05 07:50:55 -04007197 goto end_unlock;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007198
Shannon Nelson2f0aff42016-01-04 10:33:08 -08007199 /* The driver only wants link up/down and module qualification
7200 * reports from firmware. Note the negative logic.
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00007201 */
7202 ret = i40e_aq_set_phy_int_mask(&pf->hw,
Shannon Nelson2f0aff42016-01-04 10:33:08 -08007203 ~(I40E_AQ_EVENT_LINK_UPDOWN |
Shannon Nelson867a79e2016-03-18 12:18:15 -07007204 I40E_AQ_EVENT_MEDIA_NA |
Shannon Nelson2f0aff42016-01-04 10:33:08 -08007205 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00007206 if (ret)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007207 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
7208 i40e_stat_str(&pf->hw, ret),
7209 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00007210
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00007211 /* make sure our flow control settings are restored */
7212 ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
7213 if (ret)
Neerav Parikh8279e492015-09-03 17:18:50 -04007214 dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
7215 i40e_stat_str(&pf->hw, ret),
7216 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00007217
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007218 /* Rebuild the VSIs and VEBs that existed before reset.
7219 * They are still in our local switch element arrays, so only
7220 * need to rebuild the switch model in the HW.
7221 *
7222 * If there were VEBs but the reconstitution failed, we'll try
7223 * try to recover minimal use by getting the basic PF VSI working.
7224 */
7225 if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00007226 dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007227 /* find the one VEB connected to the MAC, and find orphans */
7228 for (v = 0; v < I40E_MAX_VEB; v++) {
7229 if (!pf->veb[v])
7230 continue;
7231
7232 if (pf->veb[v]->uplink_seid == pf->mac_seid ||
7233 pf->veb[v]->uplink_seid == 0) {
7234 ret = i40e_reconstitute_veb(pf->veb[v]);
7235
7236 if (!ret)
7237 continue;
7238
7239 /* If Main VEB failed, we're in deep doodoo,
7240 * so give up rebuilding the switch and set up
7241 * for minimal rebuild of PF VSI.
7242 * If orphan failed, we'll report the error
7243 * but try to keep going.
7244 */
7245 if (pf->veb[v]->uplink_seid == pf->mac_seid) {
7246 dev_info(&pf->pdev->dev,
7247 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
7248 ret);
7249 pf->vsi[pf->lan_vsi]->uplink_seid
7250 = pf->mac_seid;
7251 break;
7252 } else if (pf->veb[v]->uplink_seid == 0) {
7253 dev_info(&pf->pdev->dev,
7254 "rebuild of orphan VEB failed: %d\n",
7255 ret);
7256 }
7257 }
7258 }
7259 }
7260
7261 if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
Shannon Nelsoncde4cbc2014-06-04 01:23:17 +00007262 dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007263 /* no VEB, so rebuild only the Main VSI */
7264 ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
7265 if (ret) {
7266 dev_info(&pf->pdev->dev,
7267 "rebuild of Main VSI failed: %d\n", ret);
Maciej Sosin373149f2017-04-05 07:50:55 -04007268 goto end_unlock;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007269 }
7270 }
7271
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -04007272 /* Reconfigure hardware for allowing smaller MSS in the case
7273 * of TSO, so that we avoid the MDD being fired and causing
7274 * a reset in the case of small MSS+TSO.
7275 */
7276#define I40E_REG_MSS 0x000E64DC
7277#define I40E_REG_MSS_MIN_MASK 0x3FF0000
7278#define I40E_64BYTE_MSS 0x400000
7279 val = rd32(hw, I40E_REG_MSS);
7280 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
7281 val &= ~I40E_REG_MSS_MIN_MASK;
7282 val |= I40E_64BYTE_MSS;
7283 wr32(hw, I40E_REG_MSS, val);
7284 }
7285
Jacob Kellerd36e41d2017-06-23 04:24:46 -04007286 if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00007287 msleep(75);
7288 ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
7289 if (ret)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007290 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
7291 i40e_stat_str(&pf->hw, ret),
7292 i40e_aq_str(&pf->hw,
7293 pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00007294 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007295 /* reinit the misc interrupt */
7296 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7297 ret = i40e_setup_misc_vector(pf);
7298
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04007299 /* Add a filter to drop all Flow control frames from any VSI from being
7300 * transmitted. By doing so we stop a malicious VF from sending out
7301 * PAUSE or PFC frames and potentially controlling traffic for other
7302 * PF/VF VSIs.
7303 * The FW can still send Flow control frames if enabled.
7304 */
7305 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
7306 pf->main_vsi_seid);
7307
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007308 /* restart the VSIs that were rebuilt and running before the reset */
7309 i40e_pf_unquiesce_all_vsi(pf);
7310
Jacob Keller024b05f2017-04-13 04:45:46 -04007311 /* Release the RTNL lock before we start resetting VFs */
7312 if (!lock_acquired)
7313 rtnl_unlock();
7314
Jacob Kellere4b433f2017-04-13 04:45:52 -04007315 i40e_reset_all_vfs(pf, true);
Mitch Williams69f64b22014-02-13 03:48:46 -08007316
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007317 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00007318 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007319
Jacob Keller024b05f2017-04-13 04:45:46 -04007320 /* We've already released the lock, so don't do it again */
7321 goto end_core_reset;
7322
Maciej Sosin373149f2017-04-05 07:50:55 -04007323end_unlock:
Jacob Keller024b05f2017-04-13 04:45:46 -04007324 if (!lock_acquired)
7325 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007326end_core_reset:
Jacob Keller0da36b92017-04-19 09:25:55 -04007327 clear_bit(__I40E_RESET_FAILED, pf->state);
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00007328clear_recovery:
Jacob Keller0da36b92017-04-19 09:25:55 -04007329 clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007330}
7331
7332/**
Maciej Sosin373149f2017-04-05 07:50:55 -04007333 * i40e_reset_and_rebuild - reset and rebuild using a saved config
7334 * @pf: board private structure
7335 * @reinit: if the Main VSI needs to re-initialized.
7336 * @lock_acquired: indicates whether or not the lock has been acquired
7337 * before this function was called.
7338 **/
7339static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit,
7340 bool lock_acquired)
7341{
7342 int ret;
7343 /* Now we wait for GRST to settle out.
7344 * We don't have to delete the VEBs or VSIs from the hw switch
7345 * because the reset will make them disappear.
7346 */
7347 ret = i40e_reset(pf);
7348 if (!ret)
7349 i40e_rebuild(pf, reinit, lock_acquired);
7350}
7351
7352/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00007353 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007354 * @pf: board private structure
7355 *
7356 * Close up the VFs and other things in prep for a Core Reset,
7357 * then get ready to rebuild the world.
Maciej Sosin373149f2017-04-05 07:50:55 -04007358 * @lock_acquired: indicates whether or not the lock has been acquired
7359 * before this function was called.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007360 **/
Maciej Sosin373149f2017-04-05 07:50:55 -04007361static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007362{
Maciej Sosin373149f2017-04-05 07:50:55 -04007363 i40e_prep_for_reset(pf, lock_acquired);
7364 i40e_reset_and_rebuild(pf, false, lock_acquired);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007365}
7366
7367/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007368 * i40e_handle_mdd_event
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00007369 * @pf: pointer to the PF structure
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007370 *
7371 * Called from the MDD irq handler to identify possibly malicious vfs
7372 **/
7373static void i40e_handle_mdd_event(struct i40e_pf *pf)
7374{
7375 struct i40e_hw *hw = &pf->hw;
7376 bool mdd_detected = false;
Neerav Parikhdf430b12014-06-04 01:23:15 +00007377 bool pf_mdd_detected = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007378 struct i40e_vf *vf;
7379 u32 reg;
7380 int i;
7381
Jacob Keller0da36b92017-04-19 09:25:55 -04007382 if (!test_bit(__I40E_MDD_EVENT_PENDING, pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007383 return;
7384
7385 /* find what triggered the MDD event */
7386 reg = rd32(hw, I40E_GL_MDET_TX);
7387 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007388 u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
7389 I40E_GL_MDET_TX_PF_NUM_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00007390 u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007391 I40E_GL_MDET_TX_VF_NUM_SHIFT;
Dan Carpenter013f6572014-10-22 20:06:29 -07007392 u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007393 I40E_GL_MDET_TX_EVENT_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00007394 u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
7395 I40E_GL_MDET_TX_QUEUE_SHIFT) -
7396 pf->hw.func_caps.base_queue;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007397 if (netif_msg_tx_err(pf))
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00007398 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 +00007399 event, queue, pf_num, vf_num);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007400 wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
7401 mdd_detected = true;
7402 }
7403 reg = rd32(hw, I40E_GL_MDET_RX);
7404 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007405 u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
7406 I40E_GL_MDET_RX_FUNCTION_SHIFT;
Dan Carpenter013f6572014-10-22 20:06:29 -07007407 u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007408 I40E_GL_MDET_RX_EVENT_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00007409 u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
7410 I40E_GL_MDET_RX_QUEUE_SHIFT) -
7411 pf->hw.func_caps.base_queue;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007412 if (netif_msg_rx_err(pf))
7413 dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
7414 event, queue, func);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007415 wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
7416 mdd_detected = true;
7417 }
7418
Neerav Parikhdf430b12014-06-04 01:23:15 +00007419 if (mdd_detected) {
7420 reg = rd32(hw, I40E_PF_MDET_TX);
7421 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
7422 wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007423 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
Neerav Parikhdf430b12014-06-04 01:23:15 +00007424 pf_mdd_detected = true;
7425 }
7426 reg = rd32(hw, I40E_PF_MDET_RX);
7427 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
7428 wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007429 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
Neerav Parikhdf430b12014-06-04 01:23:15 +00007430 pf_mdd_detected = true;
7431 }
7432 /* Queue belongs to the PF, initiate a reset */
7433 if (pf_mdd_detected) {
Jacob Keller0da36b92017-04-19 09:25:55 -04007434 set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
Neerav Parikhdf430b12014-06-04 01:23:15 +00007435 i40e_service_event_schedule(pf);
7436 }
7437 }
7438
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007439 /* see if one of the VFs needs its hand slapped */
7440 for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
7441 vf = &(pf->vf[i]);
7442 reg = rd32(hw, I40E_VP_MDET_TX(i));
7443 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
7444 wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
7445 vf->num_mdd_events++;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007446 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
7447 i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007448 }
7449
7450 reg = rd32(hw, I40E_VP_MDET_RX(i));
7451 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
7452 wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
7453 vf->num_mdd_events++;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007454 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
7455 i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007456 }
7457
7458 if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
7459 dev_info(&pf->pdev->dev,
7460 "Too many MDD events on VF %d, disabled\n", i);
7461 dev_info(&pf->pdev->dev,
7462 "Use PF Control I/F to re-enable the VF\n");
Jacob Keller6322e632017-04-13 04:45:54 -04007463 set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007464 }
7465 }
7466
7467 /* re-enable mdd interrupt cause */
Jacob Keller0da36b92017-04-19 09:25:55 -04007468 clear_bit(__I40E_MDD_EVENT_PENDING, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007469 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
7470 reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
7471 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
7472 i40e_flush(hw);
7473}
7474
Jacob Kellerd8b2c702017-06-20 15:17:00 -07007475static const char *i40e_tunnel_name(struct i40e_udp_port_config *port)
7476{
7477 switch (port->type) {
7478 case UDP_TUNNEL_TYPE_VXLAN:
7479 return "vxlan";
7480 case UDP_TUNNEL_TYPE_GENEVE:
7481 return "geneve";
7482 default:
7483 return "unknown";
7484 }
7485}
7486
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007487/**
Alexander Duyck1f190d92017-04-19 09:25:51 -04007488 * i40e_sync_udp_filters - Trigger a sync event for existing UDP filters
7489 * @pf: board private structure
7490 **/
7491static void i40e_sync_udp_filters(struct i40e_pf *pf)
7492{
7493 int i;
7494
7495 /* loop through and set pending bit for all active UDP filters */
7496 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
7497 if (pf->udp_ports[i].port)
7498 pf->pending_udp_bitmap |= BIT_ULL(i);
7499 }
7500
7501 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
7502}
7503
7504/**
Singhai, Anjali6a899022015-12-14 12:21:18 -08007505 * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007506 * @pf: board private structure
7507 **/
Singhai, Anjali6a899022015-12-14 12:21:18 -08007508static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007509{
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007510 struct i40e_hw *hw = &pf->hw;
7511 i40e_status ret;
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08007512 u16 port;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007513 int i;
7514
Singhai, Anjali6a899022015-12-14 12:21:18 -08007515 if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC))
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007516 return;
7517
Singhai, Anjali6a899022015-12-14 12:21:18 -08007518 pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007519
7520 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
Singhai, Anjali6a899022015-12-14 12:21:18 -08007521 if (pf->pending_udp_bitmap & BIT_ULL(i)) {
7522 pf->pending_udp_bitmap &= ~BIT_ULL(i);
Jacob Keller27826fd2017-04-19 09:25:50 -04007523 port = pf->udp_ports[i].port;
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007524 if (port)
Carolyn Wybornyb3f5c7b2016-08-24 11:33:51 -07007525 ret = i40e_aq_add_udp_tunnel(hw, port,
7526 pf->udp_ports[i].type,
7527 NULL, NULL);
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007528 else
7529 ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007530
7531 if (ret) {
Jacob Kellerd8b2c702017-06-20 15:17:00 -07007532 dev_info(&pf->pdev->dev,
7533 "%s %s port %d, index %d failed, err %s aq_err %s\n",
7534 i40e_tunnel_name(&pf->udp_ports[i]),
7535 port ? "add" : "delete",
7536 port, i,
7537 i40e_stat_str(&pf->hw, ret),
7538 i40e_aq_str(&pf->hw,
7539 pf->hw.aq.asq_last_status));
Jacob Keller27826fd2017-04-19 09:25:50 -04007540 pf->udp_ports[i].port = 0;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007541 }
7542 }
7543 }
7544}
7545
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007546/**
7547 * i40e_service_task - Run the driver's async subtasks
7548 * @work: pointer to work_struct containing our data
7549 **/
7550static void i40e_service_task(struct work_struct *work)
7551{
7552 struct i40e_pf *pf = container_of(work,
7553 struct i40e_pf,
7554 service_task);
7555 unsigned long start_time = jiffies;
7556
Shannon Nelsone57a2fe2014-06-03 23:50:19 +00007557 /* don't bother with service tasks if a reset is in progress */
Jacob Keller0da36b92017-04-19 09:25:55 -04007558 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
Shannon Nelsone57a2fe2014-06-03 23:50:19 +00007559 return;
Shannon Nelsone57a2fe2014-06-03 23:50:19 +00007560
Jacob Keller0da36b92017-04-19 09:25:55 -04007561 if (test_and_set_bit(__I40E_SERVICE_SCHED, pf->state))
Mitch Williams91089032016-11-21 13:03:51 -08007562 return;
7563
Kiran Patilb03a8c12015-09-24 18:13:15 -04007564 i40e_detect_recover_hung(pf);
Jesse Brandeburg2818ccd2016-01-13 16:51:38 -08007565 i40e_sync_filters_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007566 i40e_reset_subtask(pf);
7567 i40e_handle_mdd_event(pf);
7568 i40e_vc_process_vflr_event(pf);
7569 i40e_watchdog_subtask(pf);
7570 i40e_fdir_reinit_subtask(pf);
Mitch Williams0ef2d5a2017-01-24 10:24:00 -08007571 if (pf->flags & I40E_FLAG_CLIENT_RESET) {
7572 /* Client subtask will reopen next time through. */
7573 i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], true);
7574 pf->flags &= ~I40E_FLAG_CLIENT_RESET;
7575 } else {
7576 i40e_client_subtask(pf);
7577 if (pf->flags & I40E_FLAG_CLIENT_L2_CHANGE) {
7578 i40e_notify_client_of_l2_param_changes(
7579 pf->vsi[pf->lan_vsi]);
7580 pf->flags &= ~I40E_FLAG_CLIENT_L2_CHANGE;
7581 }
7582 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007583 i40e_sync_filters_subtask(pf);
Singhai, Anjali6a899022015-12-14 12:21:18 -08007584 i40e_sync_udp_filters_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007585 i40e_clean_adminq_subtask(pf);
7586
Mitch Williams91089032016-11-21 13:03:51 -08007587 /* flush memory to make sure state is correct before next watchdog */
7588 smp_mb__before_atomic();
Jacob Keller0da36b92017-04-19 09:25:55 -04007589 clear_bit(__I40E_SERVICE_SCHED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007590
7591 /* If the tasks have taken longer than one timer cycle or there
7592 * is more work to be done, reschedule the service task now
7593 * rather than wait for the timer to tick again.
7594 */
7595 if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
Jacob Keller0da36b92017-04-19 09:25:55 -04007596 test_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state) ||
7597 test_bit(__I40E_MDD_EVENT_PENDING, pf->state) ||
7598 test_bit(__I40E_VFLR_EVENT_PENDING, pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007599 i40e_service_event_schedule(pf);
7600}
7601
7602/**
7603 * i40e_service_timer - timer callback
7604 * @data: pointer to PF struct
7605 **/
7606static void i40e_service_timer(unsigned long data)
7607{
7608 struct i40e_pf *pf = (struct i40e_pf *)data;
7609
7610 mod_timer(&pf->service_timer,
7611 round_jiffies(jiffies + pf->service_timer_period));
7612 i40e_service_event_schedule(pf);
7613}
7614
7615/**
7616 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
7617 * @vsi: the VSI being configured
7618 **/
7619static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
7620{
7621 struct i40e_pf *pf = vsi->back;
7622
7623 switch (vsi->type) {
7624 case I40E_VSI_MAIN:
7625 vsi->alloc_queue_pairs = pf->num_lan_qps;
7626 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7627 I40E_REQ_DESCRIPTOR_MULTIPLE);
7628 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7629 vsi->num_q_vectors = pf->num_lan_msix;
7630 else
7631 vsi->num_q_vectors = 1;
7632
7633 break;
7634
7635 case I40E_VSI_FDIR:
7636 vsi->alloc_queue_pairs = 1;
7637 vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
7638 I40E_REQ_DESCRIPTOR_MULTIPLE);
Tushar Davea70e4072016-05-16 12:40:53 -07007639 vsi->num_q_vectors = pf->num_fdsb_msix;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007640 break;
7641
7642 case I40E_VSI_VMDQ2:
7643 vsi->alloc_queue_pairs = pf->num_vmdq_qps;
7644 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7645 I40E_REQ_DESCRIPTOR_MULTIPLE);
7646 vsi->num_q_vectors = pf->num_vmdq_msix;
7647 break;
7648
7649 case I40E_VSI_SRIOV:
7650 vsi->alloc_queue_pairs = pf->num_vf_qps;
7651 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7652 I40E_REQ_DESCRIPTOR_MULTIPLE);
7653 break;
7654
7655 default:
7656 WARN_ON(1);
7657 return -ENODATA;
7658 }
7659
7660 return 0;
7661}
7662
7663/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007664 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
7665 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007666 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007667 *
7668 * On error: returns error code (negative)
7669 * On success: returns 0
7670 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007671static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007672{
Björn Töpel74608d12017-05-24 07:55:35 +02007673 struct i40e_ring **next_rings;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007674 int size;
7675 int ret = 0;
7676
Björn Töpel74608d12017-05-24 07:55:35 +02007677 /* allocate memory for both Tx, XDP Tx and Rx ring pointers */
7678 size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs *
7679 (i40e_enabled_xdp_vsi(vsi) ? 3 : 2);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007680 vsi->tx_rings = kzalloc(size, GFP_KERNEL);
7681 if (!vsi->tx_rings)
7682 return -ENOMEM;
Björn Töpel74608d12017-05-24 07:55:35 +02007683 next_rings = vsi->tx_rings + vsi->alloc_queue_pairs;
7684 if (i40e_enabled_xdp_vsi(vsi)) {
7685 vsi->xdp_rings = next_rings;
7686 next_rings += vsi->alloc_queue_pairs;
7687 }
7688 vsi->rx_rings = next_rings;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007689
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007690 if (alloc_qvectors) {
7691 /* allocate memory for q_vector pointers */
Julia Lawallf57e4fb2014-07-30 03:11:09 +00007692 size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007693 vsi->q_vectors = kzalloc(size, GFP_KERNEL);
7694 if (!vsi->q_vectors) {
7695 ret = -ENOMEM;
7696 goto err_vectors;
7697 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007698 }
7699 return ret;
7700
7701err_vectors:
7702 kfree(vsi->tx_rings);
7703 return ret;
7704}
7705
7706/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007707 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
7708 * @pf: board private structure
7709 * @type: type of VSI
7710 *
7711 * On error: returns error code (negative)
7712 * On success: returns vsi index in PF (positive)
7713 **/
7714static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
7715{
7716 int ret = -ENODEV;
7717 struct i40e_vsi *vsi;
7718 int vsi_idx;
7719 int i;
7720
7721 /* Need to protect the allocation of the VSIs at the PF level */
7722 mutex_lock(&pf->switch_mutex);
7723
7724 /* VSI list may be fragmented if VSI creation/destruction has
7725 * been happening. We can afford to do a quick scan to look
7726 * for any free VSIs in the list.
7727 *
7728 * find next empty vsi slot, looping back around if necessary
7729 */
7730 i = pf->next_vsi;
Mitch Williams505682c2014-05-20 08:01:37 +00007731 while (i < pf->num_alloc_vsi && pf->vsi[i])
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007732 i++;
Mitch Williams505682c2014-05-20 08:01:37 +00007733 if (i >= pf->num_alloc_vsi) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007734 i = 0;
7735 while (i < pf->next_vsi && pf->vsi[i])
7736 i++;
7737 }
7738
Mitch Williams505682c2014-05-20 08:01:37 +00007739 if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007740 vsi_idx = i; /* Found one! */
7741 } else {
7742 ret = -ENODEV;
Alexander Duyck493fb302013-09-28 07:01:44 +00007743 goto unlock_pf; /* out of VSI slots! */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007744 }
7745 pf->next_vsi = ++i;
7746
7747 vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
7748 if (!vsi) {
7749 ret = -ENOMEM;
Alexander Duyck493fb302013-09-28 07:01:44 +00007750 goto unlock_pf;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007751 }
7752 vsi->type = type;
7753 vsi->back = pf;
Jacob Keller0da36b92017-04-19 09:25:55 -04007754 set_bit(__I40E_VSI_DOWN, vsi->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007755 vsi->flags = 0;
7756 vsi->idx = vsi_idx;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04007757 vsi->int_rate_limit = 0;
Anjali Singhai Jain5db4cb52015-02-24 06:58:49 +00007758 vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
7759 pf->rss_table_size : 64;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007760 vsi->netdev_registered = false;
7761 vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
Jacob Keller278e7d02016-10-05 09:30:37 -07007762 hash_init(vsi->mac_filter_hash);
Shannon Nelson63741842014-04-23 04:50:16 +00007763 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007764
Alexander Duyck9f65e152013-09-28 06:00:58 +00007765 ret = i40e_set_num_rings_in_vsi(vsi);
7766 if (ret)
7767 goto err_rings;
7768
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007769 ret = i40e_vsi_alloc_arrays(vsi, true);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007770 if (ret)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007771 goto err_rings;
Alexander Duyck493fb302013-09-28 07:01:44 +00007772
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007773 /* Setup default MSIX irq handler for VSI */
7774 i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
7775
Kiran Patil21659032015-09-30 14:09:03 -04007776 /* Initialize VSI lock */
Jacob Keller278e7d02016-10-05 09:30:37 -07007777 spin_lock_init(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007778 pf->vsi[vsi_idx] = vsi;
7779 ret = vsi_idx;
Alexander Duyck493fb302013-09-28 07:01:44 +00007780 goto unlock_pf;
7781
Alexander Duyck9f65e152013-09-28 06:00:58 +00007782err_rings:
Alexander Duyck493fb302013-09-28 07:01:44 +00007783 pf->next_vsi = i - 1;
7784 kfree(vsi);
7785unlock_pf:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007786 mutex_unlock(&pf->switch_mutex);
7787 return ret;
7788}
7789
7790/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007791 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
7792 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007793 * @free_qvectors: a bool to specify if q_vectors need to be freed.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007794 *
7795 * On error: returns error code (negative)
7796 * On success: returns 0
7797 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007798static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007799{
7800 /* free the ring and vector containers */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007801 if (free_qvectors) {
7802 kfree(vsi->q_vectors);
7803 vsi->q_vectors = NULL;
7804 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007805 kfree(vsi->tx_rings);
7806 vsi->tx_rings = NULL;
7807 vsi->rx_rings = NULL;
Björn Töpel74608d12017-05-24 07:55:35 +02007808 vsi->xdp_rings = NULL;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007809}
7810
7811/**
Helin Zhang28c58692015-10-26 19:44:27 -04007812 * i40e_clear_rss_config_user - clear the user configured RSS hash keys
7813 * and lookup table
7814 * @vsi: Pointer to VSI structure
7815 */
7816static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
7817{
7818 if (!vsi)
7819 return;
7820
7821 kfree(vsi->rss_hkey_user);
7822 vsi->rss_hkey_user = NULL;
7823
7824 kfree(vsi->rss_lut_user);
7825 vsi->rss_lut_user = NULL;
7826}
7827
7828/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007829 * i40e_vsi_clear - Deallocate the VSI provided
7830 * @vsi: the VSI being un-configured
7831 **/
7832static int i40e_vsi_clear(struct i40e_vsi *vsi)
7833{
7834 struct i40e_pf *pf;
7835
7836 if (!vsi)
7837 return 0;
7838
7839 if (!vsi->back)
7840 goto free_vsi;
7841 pf = vsi->back;
7842
7843 mutex_lock(&pf->switch_mutex);
7844 if (!pf->vsi[vsi->idx]) {
7845 dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
7846 vsi->idx, vsi->idx, vsi, vsi->type);
7847 goto unlock_vsi;
7848 }
7849
7850 if (pf->vsi[vsi->idx] != vsi) {
7851 dev_err(&pf->pdev->dev,
7852 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
7853 pf->vsi[vsi->idx]->idx,
7854 pf->vsi[vsi->idx],
7855 pf->vsi[vsi->idx]->type,
7856 vsi->idx, vsi, vsi->type);
7857 goto unlock_vsi;
7858 }
7859
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00007860 /* updates the PF for this cleared vsi */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007861 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
7862 i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
7863
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007864 i40e_vsi_free_arrays(vsi, true);
Helin Zhang28c58692015-10-26 19:44:27 -04007865 i40e_clear_rss_config_user(vsi);
Alexander Duyck493fb302013-09-28 07:01:44 +00007866
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007867 pf->vsi[vsi->idx] = NULL;
7868 if (vsi->idx < pf->next_vsi)
7869 pf->next_vsi = vsi->idx;
7870
7871unlock_vsi:
7872 mutex_unlock(&pf->switch_mutex);
7873free_vsi:
7874 kfree(vsi);
7875
7876 return 0;
7877}
7878
7879/**
Alexander Duyck9f65e152013-09-28 06:00:58 +00007880 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
7881 * @vsi: the VSI being cleaned
7882 **/
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00007883static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007884{
7885 int i;
7886
Greg Rose8e9dca52013-12-18 13:45:53 +00007887 if (vsi->tx_rings && vsi->tx_rings[0]) {
Neerav Parikhd7397642013-11-28 06:39:37 +00007888 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Mitch Williams00403f02013-09-28 07:13:13 +00007889 kfree_rcu(vsi->tx_rings[i], rcu);
7890 vsi->tx_rings[i] = NULL;
7891 vsi->rx_rings[i] = NULL;
Björn Töpel74608d12017-05-24 07:55:35 +02007892 if (vsi->xdp_rings)
7893 vsi->xdp_rings[i] = NULL;
Mitch Williams00403f02013-09-28 07:13:13 +00007894 }
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00007895 }
Alexander Duyck9f65e152013-09-28 06:00:58 +00007896}
7897
7898/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007899 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
7900 * @vsi: the VSI being configured
7901 **/
7902static int i40e_alloc_rings(struct i40e_vsi *vsi)
7903{
Björn Töpel74608d12017-05-24 07:55:35 +02007904 int i, qpv = i40e_enabled_xdp_vsi(vsi) ? 3 : 2;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007905 struct i40e_pf *pf = vsi->back;
Björn Töpel74608d12017-05-24 07:55:35 +02007906 struct i40e_ring *ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007907
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007908 /* Set basic values in the rings to be used later during open() */
Neerav Parikhd7397642013-11-28 06:39:37 +00007909 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00007910 /* allocate space for both Tx and Rx in one shot */
Björn Töpel74608d12017-05-24 07:55:35 +02007911 ring = kcalloc(qpv, sizeof(struct i40e_ring), GFP_KERNEL);
7912 if (!ring)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007913 goto err_out;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007914
Björn Töpel74608d12017-05-24 07:55:35 +02007915 ring->queue_index = i;
7916 ring->reg_idx = vsi->base_queue + i;
7917 ring->ring_active = false;
7918 ring->vsi = vsi;
7919 ring->netdev = vsi->netdev;
7920 ring->dev = &pf->pdev->dev;
7921 ring->count = vsi->num_desc;
7922 ring->size = 0;
7923 ring->dcb_tc = 0;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04007924 if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
Björn Töpel74608d12017-05-24 07:55:35 +02007925 ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
7926 ring->tx_itr_setting = pf->tx_itr_default;
7927 vsi->tx_rings[i] = ring++;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007928
Björn Töpel74608d12017-05-24 07:55:35 +02007929 if (!i40e_enabled_xdp_vsi(vsi))
7930 goto setup_rx;
7931
7932 ring->queue_index = vsi->alloc_queue_pairs + i;
7933 ring->reg_idx = vsi->base_queue + ring->queue_index;
7934 ring->ring_active = false;
7935 ring->vsi = vsi;
7936 ring->netdev = NULL;
7937 ring->dev = &pf->pdev->dev;
7938 ring->count = vsi->num_desc;
7939 ring->size = 0;
7940 ring->dcb_tc = 0;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04007941 if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
Björn Töpel74608d12017-05-24 07:55:35 +02007942 ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
7943 set_ring_xdp(ring);
7944 ring->tx_itr_setting = pf->tx_itr_default;
7945 vsi->xdp_rings[i] = ring++;
7946
7947setup_rx:
7948 ring->queue_index = i;
7949 ring->reg_idx = vsi->base_queue + i;
7950 ring->ring_active = false;
7951 ring->vsi = vsi;
7952 ring->netdev = vsi->netdev;
7953 ring->dev = &pf->pdev->dev;
7954 ring->count = vsi->num_desc;
7955 ring->size = 0;
7956 ring->dcb_tc = 0;
7957 ring->rx_itr_setting = pf->rx_itr_default;
7958 vsi->rx_rings[i] = ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007959 }
7960
7961 return 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00007962
7963err_out:
7964 i40e_vsi_clear_rings(vsi);
7965 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007966}
7967
7968/**
7969 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
7970 * @pf: board private structure
7971 * @vectors: the number of MSI-X vectors to request
7972 *
7973 * Returns the number of vectors reserved, or error
7974 **/
7975static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
7976{
Alexander Gordeev7b37f372014-02-18 11:11:42 +01007977 vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
7978 I40E_MIN_MSIX, vectors);
7979 if (vectors < 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007980 dev_info(&pf->pdev->dev,
Alexander Gordeev7b37f372014-02-18 11:11:42 +01007981 "MSI-X vector reservation failed: %d\n", vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007982 vectors = 0;
7983 }
7984
7985 return vectors;
7986}
7987
7988/**
7989 * i40e_init_msix - Setup the MSIX capability
7990 * @pf: board private structure
7991 *
7992 * Work with the OS to set up the MSIX vectors needed.
7993 *
Shannon Nelson3b444392015-02-26 16:15:57 +00007994 * Returns the number of vectors reserved or negative on failure
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007995 **/
7996static int i40e_init_msix(struct i40e_pf *pf)
7997{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007998 struct i40e_hw *hw = &pf->hw;
Jacob Kellerc0cf70a2017-01-24 10:24:01 -08007999 int cpus, extra_vectors;
Shannon Nelson1e200e42015-02-27 09:15:24 +00008000 int vectors_left;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008001 int v_budget, i;
Shannon Nelson3b444392015-02-26 16:15:57 +00008002 int v_actual;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008003 int iwarp_requested = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008004
8005 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
8006 return -ENODEV;
8007
8008 /* The number of vectors we'll request will be comprised of:
8009 * - Add 1 for "other" cause for Admin Queue events, etc.
8010 * - The number of LAN queue pairs
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008011 * - Queues being used for RSS.
8012 * We don't need as many as max_rss_size vectors.
8013 * use rss_size instead in the calculation since that
8014 * is governed by number of cpus in the system.
8015 * - assumes symmetric Tx/Rx pairing
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008016 * - The number of VMDq pairs
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008017 * - The CPU count within the NUMA node if iWARP is enabled
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008018 * Once we count this up, try the request.
8019 *
8020 * If we can't get what we want, we'll simplify to nearly nothing
8021 * and try again. If that still fails, we punt.
8022 */
Shannon Nelson1e200e42015-02-27 09:15:24 +00008023 vectors_left = hw->func_caps.num_msix_vectors;
8024 v_budget = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008025
Shannon Nelson1e200e42015-02-27 09:15:24 +00008026 /* reserve one vector for miscellaneous handler */
8027 if (vectors_left) {
8028 v_budget++;
8029 vectors_left--;
8030 }
8031
Jacob Kellerc0cf70a2017-01-24 10:24:01 -08008032 /* reserve some vectors for the main PF traffic queues. Initially we
8033 * only reserve at most 50% of the available vectors, in the case that
8034 * the number of online CPUs is large. This ensures that we can enable
8035 * extra features as well. Once we've enabled the other features, we
8036 * will use any remaining vectors to reach as close as we can to the
8037 * number of online CPUs.
8038 */
8039 cpus = num_online_cpus();
8040 pf->num_lan_msix = min_t(int, cpus, vectors_left / 2);
Shannon Nelson1e200e42015-02-27 09:15:24 +00008041 vectors_left -= pf->num_lan_msix;
Shannon Nelson1e200e42015-02-27 09:15:24 +00008042
8043 /* reserve one vector for sideband flow director */
8044 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
8045 if (vectors_left) {
Tushar Davea70e4072016-05-16 12:40:53 -07008046 pf->num_fdsb_msix = 1;
Shannon Nelson1e200e42015-02-27 09:15:24 +00008047 v_budget++;
8048 vectors_left--;
8049 } else {
Tushar Davea70e4072016-05-16 12:40:53 -07008050 pf->num_fdsb_msix = 0;
Shannon Nelson1e200e42015-02-27 09:15:24 +00008051 }
8052 }
John W Linville83840e42015-01-14 03:06:28 +00008053
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008054 /* can we reserve enough for iWARP? */
8055 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02008056 iwarp_requested = pf->num_iwarp_msix;
8057
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008058 if (!vectors_left)
8059 pf->num_iwarp_msix = 0;
8060 else if (vectors_left < pf->num_iwarp_msix)
8061 pf->num_iwarp_msix = 1;
8062 v_budget += pf->num_iwarp_msix;
8063 vectors_left -= pf->num_iwarp_msix;
8064 }
8065
Shannon Nelson1e200e42015-02-27 09:15:24 +00008066 /* any vectors left over go for VMDq support */
8067 if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
8068 int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
8069 int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
8070
Stefan Assmann9ca57e92016-09-19 13:37:49 +02008071 if (!vectors_left) {
8072 pf->num_vmdq_msix = 0;
8073 pf->num_vmdq_qps = 0;
8074 } else {
8075 /* if we're short on vectors for what's desired, we limit
8076 * the queues per vmdq. If this is still more than are
8077 * available, the user will need to change the number of
8078 * queues/vectors used by the PF later with the ethtool
8079 * channels command
8080 */
8081 if (vmdq_vecs < vmdq_vecs_wanted)
8082 pf->num_vmdq_qps = 1;
8083 pf->num_vmdq_msix = pf->num_vmdq_qps;
Shannon Nelson1e200e42015-02-27 09:15:24 +00008084
Stefan Assmann9ca57e92016-09-19 13:37:49 +02008085 v_budget += vmdq_vecs;
8086 vectors_left -= vmdq_vecs;
8087 }
Shannon Nelson1e200e42015-02-27 09:15:24 +00008088 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008089
Jacob Kellerc0cf70a2017-01-24 10:24:01 -08008090 /* On systems with a large number of SMP cores, we previously limited
8091 * the number of vectors for num_lan_msix to be at most 50% of the
8092 * available vectors, to allow for other features. Now, we add back
8093 * the remaining vectors. However, we ensure that the total
8094 * num_lan_msix will not exceed num_online_cpus(). To do this, we
8095 * calculate the number of vectors we can add without going over the
8096 * cap of CPUs. For systems with a small number of CPUs this will be
8097 * zero.
8098 */
8099 extra_vectors = min_t(int, cpus - pf->num_lan_msix, vectors_left);
8100 pf->num_lan_msix += extra_vectors;
8101 vectors_left -= extra_vectors;
8102
8103 WARN(vectors_left < 0,
8104 "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n");
8105
8106 v_budget += pf->num_lan_msix;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008107 pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
8108 GFP_KERNEL);
8109 if (!pf->msix_entries)
8110 return -ENOMEM;
8111
8112 for (i = 0; i < v_budget; i++)
8113 pf->msix_entries[i].entry = i;
Shannon Nelson3b444392015-02-26 16:15:57 +00008114 v_actual = i40e_reserve_msix_vectors(pf, v_budget);
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00008115
Shannon Nelson3b444392015-02-26 16:15:57 +00008116 if (v_actual < I40E_MIN_MSIX) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008117 pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
8118 kfree(pf->msix_entries);
8119 pf->msix_entries = NULL;
Guilherme G Piccoli4c95aa52016-09-22 10:03:58 -03008120 pci_disable_msix(pf->pdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008121 return -ENODEV;
8122
Shannon Nelson3b444392015-02-26 16:15:57 +00008123 } else if (v_actual == I40E_MIN_MSIX) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008124 /* Adjust for minimal MSIX use */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008125 pf->num_vmdq_vsis = 0;
8126 pf->num_vmdq_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008127 pf->num_lan_qps = 1;
8128 pf->num_lan_msix = 1;
8129
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02008130 } else if (!vectors_left) {
8131 /* If we have limited resources, we will start with no vectors
8132 * for the special features and then allocate vectors to some
8133 * of these features based on the policy and at the end disable
8134 * the features that did not get any vectors.
8135 */
Shannon Nelson3b444392015-02-26 16:15:57 +00008136 int vec;
8137
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02008138 dev_info(&pf->pdev->dev,
8139 "MSI-X vector limit reached, attempting to redistribute vectors\n");
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00008140 /* reserve the misc vector */
Shannon Nelson3b444392015-02-26 16:15:57 +00008141 vec = v_actual - 1;
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00008142
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008143 /* Scale vector usage down */
8144 pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00008145 pf->num_vmdq_vsis = 1;
Shannon Nelson1e200e42015-02-27 09:15:24 +00008146 pf->num_vmdq_qps = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008147
8148 /* partition out the remaining vectors */
8149 switch (vec) {
8150 case 2:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008151 pf->num_lan_msix = 1;
8152 break;
8153 case 3:
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008154 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
8155 pf->num_lan_msix = 1;
8156 pf->num_iwarp_msix = 1;
8157 } else {
8158 pf->num_lan_msix = 2;
8159 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008160 break;
8161 default:
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008162 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
8163 pf->num_iwarp_msix = min_t(int, (vec / 3),
8164 iwarp_requested);
8165 pf->num_vmdq_vsis = min_t(int, (vec / 3),
8166 I40E_DEFAULT_NUM_VMDQ_VSI);
8167 } else {
8168 pf->num_vmdq_vsis = min_t(int, (vec / 2),
8169 I40E_DEFAULT_NUM_VMDQ_VSI);
8170 }
Stefan Assmannabd97a92016-09-19 13:37:51 +02008171 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
8172 pf->num_fdsb_msix = 1;
8173 vec--;
8174 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008175 pf->num_lan_msix = min_t(int,
8176 (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
8177 pf->num_lan_msix);
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02008178 pf->num_lan_qps = pf->num_lan_msix;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008179 break;
8180 }
8181 }
8182
Stefan Assmannabd97a92016-09-19 13:37:51 +02008183 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
8184 (pf->num_fdsb_msix == 0)) {
8185 dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
8186 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
8187 }
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00008188 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
8189 (pf->num_vmdq_msix == 0)) {
8190 dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
8191 pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
8192 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008193
8194 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
8195 (pf->num_iwarp_msix == 0)) {
8196 dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
8197 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
8198 }
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02008199 i40e_debug(&pf->hw, I40E_DEBUG_INIT,
8200 "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
8201 pf->num_lan_msix,
8202 pf->num_vmdq_msix * pf->num_vmdq_vsis,
8203 pf->num_fdsb_msix,
8204 pf->num_iwarp_msix);
8205
Shannon Nelson3b444392015-02-26 16:15:57 +00008206 return v_actual;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008207}
8208
8209/**
Greg Rose90e04072014-03-06 08:59:57 +00008210 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
Alexander Duyck493fb302013-09-28 07:01:44 +00008211 * @vsi: the VSI being configured
8212 * @v_idx: index of the vector in the vsi struct
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03008213 * @cpu: cpu to be used on affinity_mask
Alexander Duyck493fb302013-09-28 07:01:44 +00008214 *
8215 * We allocate one q_vector. If allocation fails we return -ENOMEM.
8216 **/
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03008217static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu)
Alexander Duyck493fb302013-09-28 07:01:44 +00008218{
8219 struct i40e_q_vector *q_vector;
8220
8221 /* allocate q_vector */
8222 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
8223 if (!q_vector)
8224 return -ENOMEM;
8225
8226 q_vector->vsi = vsi;
8227 q_vector->v_idx = v_idx;
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03008228 cpumask_set_cpu(cpu, &q_vector->affinity_mask);
8229
Alexander Duyck493fb302013-09-28 07:01:44 +00008230 if (vsi->netdev)
8231 netif_napi_add(vsi->netdev, &q_vector->napi,
Jesse Brandeburgeefeace2014-05-10 04:49:13 +00008232 i40e_napi_poll, NAPI_POLL_WEIGHT);
Alexander Duyck493fb302013-09-28 07:01:44 +00008233
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00008234 q_vector->rx.latency_range = I40E_LOW_LATENCY;
8235 q_vector->tx.latency_range = I40E_LOW_LATENCY;
8236
Alexander Duyck493fb302013-09-28 07:01:44 +00008237 /* tie q_vector and vsi together */
8238 vsi->q_vectors[v_idx] = q_vector;
8239
8240 return 0;
8241}
8242
8243/**
Greg Rose90e04072014-03-06 08:59:57 +00008244 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008245 * @vsi: the VSI being configured
8246 *
8247 * We allocate one q_vector per queue interrupt. If allocation fails we
8248 * return -ENOMEM.
8249 **/
Greg Rose90e04072014-03-06 08:59:57 +00008250static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008251{
8252 struct i40e_pf *pf = vsi->back;
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03008253 int err, v_idx, num_q_vectors, current_cpu;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008254
8255 /* if not MSIX, give the one vector only to the LAN VSI */
8256 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
8257 num_q_vectors = vsi->num_q_vectors;
8258 else if (vsi == pf->vsi[pf->lan_vsi])
8259 num_q_vectors = 1;
8260 else
8261 return -EINVAL;
8262
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03008263 current_cpu = cpumask_first(cpu_online_mask);
8264
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008265 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03008266 err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu);
Alexander Duyck493fb302013-09-28 07:01:44 +00008267 if (err)
8268 goto err_out;
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03008269 current_cpu = cpumask_next(current_cpu, cpu_online_mask);
8270 if (unlikely(current_cpu >= nr_cpu_ids))
8271 current_cpu = cpumask_first(cpu_online_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008272 }
8273
8274 return 0;
Alexander Duyck493fb302013-09-28 07:01:44 +00008275
8276err_out:
8277 while (v_idx--)
8278 i40e_free_q_vector(vsi, v_idx);
8279
8280 return err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008281}
8282
8283/**
8284 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
8285 * @pf: board private structure to initialize
8286 **/
Jesse Brandeburgc11472802015-04-07 19:45:39 -04008287static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008288{
Shannon Nelson3b444392015-02-26 16:15:57 +00008289 int vectors = 0;
8290 ssize_t size;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008291
8292 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
Shannon Nelson3b444392015-02-26 16:15:57 +00008293 vectors = i40e_init_msix(pf);
8294 if (vectors < 0) {
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08008295 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008296 I40E_FLAG_IWARP_ENABLED |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08008297 I40E_FLAG_RSS_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008298 I40E_FLAG_DCB_CAPABLE |
Dave Ertmana0362442016-08-29 17:38:26 -07008299 I40E_FLAG_DCB_ENABLED |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08008300 I40E_FLAG_SRIOV_ENABLED |
8301 I40E_FLAG_FD_SB_ENABLED |
8302 I40E_FLAG_FD_ATR_ENABLED |
8303 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008304
8305 /* rework the queue expectations without MSIX */
8306 i40e_determine_queue_usage(pf);
8307 }
8308 }
8309
8310 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
8311 (pf->flags & I40E_FLAG_MSI_ENABLED)) {
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08008312 dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
Shannon Nelson3b444392015-02-26 16:15:57 +00008313 vectors = pci_enable_msi(pf->pdev);
8314 if (vectors < 0) {
8315 dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
8316 vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008317 pf->flags &= ~I40E_FLAG_MSI_ENABLED;
8318 }
Shannon Nelson3b444392015-02-26 16:15:57 +00008319 vectors = 1; /* one MSI or Legacy vector */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008320 }
8321
Shannon Nelson958a3e32013-09-28 07:13:28 +00008322 if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08008323 dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
Shannon Nelson958a3e32013-09-28 07:13:28 +00008324
Shannon Nelson3b444392015-02-26 16:15:57 +00008325 /* set up vector assignment tracking */
8326 size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
8327 pf->irq_pile = kzalloc(size, GFP_KERNEL);
Jesse Brandeburgc11472802015-04-07 19:45:39 -04008328 if (!pf->irq_pile) {
8329 dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n");
8330 return -ENOMEM;
8331 }
Shannon Nelson3b444392015-02-26 16:15:57 +00008332 pf->irq_pile->num_entries = vectors;
8333 pf->irq_pile->search_hint = 0;
8334
Jesse Brandeburgc11472802015-04-07 19:45:39 -04008335 /* track first vector for misc interrupts, ignore return */
Shannon Nelson3b444392015-02-26 16:15:57 +00008336 (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
Jesse Brandeburgc11472802015-04-07 19:45:39 -04008337
8338 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008339}
8340
8341/**
8342 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
8343 * @pf: board private structure
8344 *
8345 * This sets up the handler for MSIX 0, which is used to manage the
8346 * non-queue interrupts, e.g. AdminQ and errors. This is not used
8347 * when in MSI or Legacy interrupt mode.
8348 **/
8349static int i40e_setup_misc_vector(struct i40e_pf *pf)
8350{
8351 struct i40e_hw *hw = &pf->hw;
8352 int err = 0;
8353
8354 /* Only request the irq if this is the first time through, and
8355 * not when we're rebuilding after a Reset
8356 */
Jacob Keller0da36b92017-04-19 09:25:55 -04008357 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008358 err = request_irq(pf->msix_entries[0].vector,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00008359 i40e_intr, 0, pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008360 if (err) {
8361 dev_info(&pf->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08008362 "request_irq for %s failed: %d\n",
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00008363 pf->int_name, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008364 return -EFAULT;
8365 }
8366 }
8367
Jacob Kellerab437b52014-12-14 01:55:08 +00008368 i40e_enable_misc_int_causes(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008369
8370 /* associate no queues to the misc vector */
8371 wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
8372 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
8373
8374 i40e_flush(hw);
8375
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08008376 i40e_irq_dynamic_enable_icr0(pf, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008377
8378 return err;
8379}
8380
8381/**
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008382 * i40e_config_rss_aq - Prepare for RSS using AQ commands
8383 * @vsi: vsi structure
8384 * @seed: RSS hash seed
8385 **/
Helin Zhange69ff812015-10-21 19:56:22 -04008386static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
8387 u8 *lut, u16 lut_size)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008388{
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008389 struct i40e_pf *pf = vsi->back;
8390 struct i40e_hw *hw = &pf->hw;
Jacob Keller776b2e12016-07-19 16:23:30 -07008391 int ret = 0;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008392
Jacob Keller776b2e12016-07-19 16:23:30 -07008393 if (seed) {
8394 struct i40e_aqc_get_set_rss_key_data *seed_dw =
8395 (struct i40e_aqc_get_set_rss_key_data *)seed;
8396 ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw);
8397 if (ret) {
8398 dev_info(&pf->pdev->dev,
8399 "Cannot set RSS key, err %s aq_err %s\n",
8400 i40e_stat_str(hw, ret),
8401 i40e_aq_str(hw, hw->aq.asq_last_status));
8402 return ret;
8403 }
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008404 }
Jacob Keller776b2e12016-07-19 16:23:30 -07008405 if (lut) {
8406 bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008407
Jacob Keller776b2e12016-07-19 16:23:30 -07008408 ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
8409 if (ret) {
8410 dev_info(&pf->pdev->dev,
8411 "Cannot set RSS lut, err %s aq_err %s\n",
8412 i40e_stat_str(hw, ret),
8413 i40e_aq_str(hw, hw->aq.asq_last_status));
8414 return ret;
8415 }
8416 }
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008417 return ret;
8418}
8419
8420/**
Anjali Singhai Jain95a73782015-12-22 14:25:04 -08008421 * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
8422 * @vsi: Pointer to vsi structure
8423 * @seed: Buffter to store the hash keys
8424 * @lut: Buffer to store the lookup table entries
8425 * @lut_size: Size of buffer to store the lookup table entries
8426 *
8427 * Return 0 on success, negative on failure
8428 */
8429static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
8430 u8 *lut, u16 lut_size)
8431{
8432 struct i40e_pf *pf = vsi->back;
8433 struct i40e_hw *hw = &pf->hw;
8434 int ret = 0;
8435
8436 if (seed) {
8437 ret = i40e_aq_get_rss_key(hw, vsi->id,
8438 (struct i40e_aqc_get_set_rss_key_data *)seed);
8439 if (ret) {
8440 dev_info(&pf->pdev->dev,
8441 "Cannot get RSS key, err %s aq_err %s\n",
8442 i40e_stat_str(&pf->hw, ret),
8443 i40e_aq_str(&pf->hw,
8444 pf->hw.aq.asq_last_status));
8445 return ret;
8446 }
8447 }
8448
8449 if (lut) {
8450 bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
8451
8452 ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
8453 if (ret) {
8454 dev_info(&pf->pdev->dev,
8455 "Cannot get RSS lut, err %s aq_err %s\n",
8456 i40e_stat_str(&pf->hw, ret),
8457 i40e_aq_str(&pf->hw,
8458 pf->hw.aq.asq_last_status));
8459 return ret;
8460 }
8461 }
8462
8463 return ret;
8464}
8465
8466/**
Jacob Keller0582b962016-07-19 16:23:29 -07008467 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
8468 * @vsi: VSI structure
8469 **/
8470static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
8471{
8472 u8 seed[I40E_HKEY_ARRAY_SIZE];
8473 struct i40e_pf *pf = vsi->back;
8474 u8 *lut;
8475 int ret;
8476
Jacob Kellerd36e41d2017-06-23 04:24:46 -04008477 if (!(pf->hw_features & I40E_HW_RSS_AQ_CAPABLE))
Jacob Keller0582b962016-07-19 16:23:29 -07008478 return 0;
8479
Jacob Keller552b9962016-07-19 16:23:31 -07008480 if (!vsi->rss_size)
8481 vsi->rss_size = min_t(int, pf->alloc_rss_size,
8482 vsi->num_queue_pairs);
8483 if (!vsi->rss_size)
8484 return -EINVAL;
8485
Jacob Keller0582b962016-07-19 16:23:29 -07008486 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
8487 if (!lut)
8488 return -ENOMEM;
Jacob Keller552b9962016-07-19 16:23:31 -07008489 /* Use the user configured hash keys and lookup table if there is one,
8490 * otherwise use default
8491 */
8492 if (vsi->rss_lut_user)
8493 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
8494 else
8495 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
8496 if (vsi->rss_hkey_user)
8497 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
8498 else
8499 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
Jacob Keller0582b962016-07-19 16:23:29 -07008500 ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
8501 kfree(lut);
8502
8503 return ret;
8504}
8505
8506/**
Helin Zhang043dd652015-10-21 19:56:23 -04008507 * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
Helin Zhange69ff812015-10-21 19:56:22 -04008508 * @vsi: Pointer to vsi structure
8509 * @seed: RSS hash seed
8510 * @lut: Lookup table
8511 * @lut_size: Lookup table size
8512 *
8513 * Returns 0 on success, negative on failure
8514 **/
8515static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
8516 const u8 *lut, u16 lut_size)
8517{
8518 struct i40e_pf *pf = vsi->back;
8519 struct i40e_hw *hw = &pf->hw;
Mitch Williamsc4e18682016-04-12 08:30:40 -07008520 u16 vf_id = vsi->vf_id;
Helin Zhange69ff812015-10-21 19:56:22 -04008521 u8 i;
8522
8523 /* Fill out hash function seed */
8524 if (seed) {
8525 u32 *seed_dw = (u32 *)seed;
8526
Mitch Williamsc4e18682016-04-12 08:30:40 -07008527 if (vsi->type == I40E_VSI_MAIN) {
8528 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
Lihong Yang26f77e52017-01-30 12:29:33 -08008529 wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
Mitch Williamsc4e18682016-04-12 08:30:40 -07008530 } else if (vsi->type == I40E_VSI_SRIOV) {
8531 for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
Lihong Yang26f77e52017-01-30 12:29:33 -08008532 wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]);
Mitch Williamsc4e18682016-04-12 08:30:40 -07008533 } else {
8534 dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
8535 }
Helin Zhange69ff812015-10-21 19:56:22 -04008536 }
8537
8538 if (lut) {
8539 u32 *lut_dw = (u32 *)lut;
8540
Mitch Williamsc4e18682016-04-12 08:30:40 -07008541 if (vsi->type == I40E_VSI_MAIN) {
8542 if (lut_size != I40E_HLUT_ARRAY_SIZE)
8543 return -EINVAL;
8544 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8545 wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
8546 } else if (vsi->type == I40E_VSI_SRIOV) {
8547 if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
8548 return -EINVAL;
8549 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
Lihong Yang26f77e52017-01-30 12:29:33 -08008550 wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]);
Mitch Williamsc4e18682016-04-12 08:30:40 -07008551 } else {
8552 dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
8553 }
Helin Zhange69ff812015-10-21 19:56:22 -04008554 }
8555 i40e_flush(hw);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008556
8557 return 0;
8558}
8559
8560/**
Helin Zhang043dd652015-10-21 19:56:23 -04008561 * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
8562 * @vsi: Pointer to VSI structure
8563 * @seed: Buffer to store the keys
8564 * @lut: Buffer to store the lookup table entries
8565 * @lut_size: Size of buffer to store the lookup table entries
8566 *
8567 * Returns 0 on success, negative on failure
8568 */
8569static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
8570 u8 *lut, u16 lut_size)
8571{
8572 struct i40e_pf *pf = vsi->back;
8573 struct i40e_hw *hw = &pf->hw;
8574 u16 i;
8575
8576 if (seed) {
8577 u32 *seed_dw = (u32 *)seed;
8578
8579 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008580 seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
Helin Zhang043dd652015-10-21 19:56:23 -04008581 }
8582 if (lut) {
8583 u32 *lut_dw = (u32 *)lut;
8584
8585 if (lut_size != I40E_HLUT_ARRAY_SIZE)
8586 return -EINVAL;
8587 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8588 lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
8589 }
8590
8591 return 0;
8592}
8593
8594/**
8595 * i40e_config_rss - Configure RSS keys and lut
8596 * @vsi: Pointer to VSI structure
8597 * @seed: RSS hash seed
8598 * @lut: Lookup table
8599 * @lut_size: Lookup table size
8600 *
8601 * Returns 0 on success, negative on failure
8602 */
8603int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
8604{
8605 struct i40e_pf *pf = vsi->back;
8606
Jacob Kellerd36e41d2017-06-23 04:24:46 -04008607 if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
Helin Zhang043dd652015-10-21 19:56:23 -04008608 return i40e_config_rss_aq(vsi, seed, lut, lut_size);
8609 else
8610 return i40e_config_rss_reg(vsi, seed, lut, lut_size);
8611}
8612
8613/**
8614 * i40e_get_rss - Get RSS keys and lut
8615 * @vsi: Pointer to VSI structure
8616 * @seed: Buffer to store the keys
8617 * @lut: Buffer to store the lookup table entries
8618 * lut_size: Size of buffer to store the lookup table entries
8619 *
8620 * Returns 0 on success, negative on failure
8621 */
8622int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
8623{
Anjali Singhai Jain95a73782015-12-22 14:25:04 -08008624 struct i40e_pf *pf = vsi->back;
8625
Jacob Kellerd36e41d2017-06-23 04:24:46 -04008626 if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
Anjali Singhai Jain95a73782015-12-22 14:25:04 -08008627 return i40e_get_rss_aq(vsi, seed, lut, lut_size);
8628 else
8629 return i40e_get_rss_reg(vsi, seed, lut, lut_size);
Helin Zhang043dd652015-10-21 19:56:23 -04008630}
8631
8632/**
Helin Zhange69ff812015-10-21 19:56:22 -04008633 * i40e_fill_rss_lut - Fill the RSS lookup table with default values
8634 * @pf: Pointer to board private structure
8635 * @lut: Lookup table
8636 * @rss_table_size: Lookup table size
8637 * @rss_size: Range of queue number for hashing
8638 */
Alan Bradyf1582352016-08-24 11:33:46 -07008639void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
8640 u16 rss_table_size, u16 rss_size)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008641{
Helin Zhange69ff812015-10-21 19:56:22 -04008642 u16 i;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008643
Helin Zhange69ff812015-10-21 19:56:22 -04008644 for (i = 0; i < rss_table_size; i++)
8645 lut[i] = i % rss_size;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008646}
8647
8648/**
Helin Zhang043dd652015-10-21 19:56:23 -04008649 * i40e_pf_config_rss - Prepare for RSS if used
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008650 * @pf: board private structure
8651 **/
Helin Zhang043dd652015-10-21 19:56:23 -04008652static int i40e_pf_config_rss(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008653{
Anjali Singhai Jain66ddcff2015-02-24 06:58:50 +00008654 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008655 u8 seed[I40E_HKEY_ARRAY_SIZE];
Helin Zhange69ff812015-10-21 19:56:22 -04008656 u8 *lut;
Anjali Singhai Jain4617e8c2013-11-20 10:02:56 +00008657 struct i40e_hw *hw = &pf->hw;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00008658 u32 reg_val;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008659 u64 hena;
Helin Zhange69ff812015-10-21 19:56:22 -04008660 int ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008661
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008662 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008663 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
8664 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008665 hena |= i40e_pf_get_default_rss_hena(pf);
8666
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008667 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
8668 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008669
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008670 /* Determine the RSS table size based on the hardware capabilities */
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008671 reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008672 reg_val = (pf->rss_table_size == 512) ?
8673 (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
8674 (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008675 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
Carolyn Wybornye157ea32014-06-03 23:50:22 +00008676
Helin Zhang28c58692015-10-26 19:44:27 -04008677 /* Determine the RSS size of the VSI */
Harshitha Ramamurthyf25571b2017-02-21 15:55:40 -08008678 if (!vsi->rss_size) {
8679 u16 qcount;
8680
8681 qcount = vsi->num_queue_pairs / vsi->tc_config.numtc;
8682 vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
8683 }
Mitch Williamsa4fa59c2016-09-12 14:18:43 -07008684 if (!vsi->rss_size)
8685 return -EINVAL;
Helin Zhang28c58692015-10-26 19:44:27 -04008686
Helin Zhange69ff812015-10-21 19:56:22 -04008687 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
8688 if (!lut)
8689 return -ENOMEM;
8690
Helin Zhang28c58692015-10-26 19:44:27 -04008691 /* Use user configured lut if there is one, otherwise use default */
8692 if (vsi->rss_lut_user)
8693 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
8694 else
8695 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
Helin Zhange69ff812015-10-21 19:56:22 -04008696
Helin Zhang28c58692015-10-26 19:44:27 -04008697 /* Use user configured hash key if there is one, otherwise
8698 * use default.
8699 */
8700 if (vsi->rss_hkey_user)
8701 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
8702 else
8703 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
Helin Zhang043dd652015-10-21 19:56:23 -04008704 ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
Helin Zhange69ff812015-10-21 19:56:22 -04008705 kfree(lut);
8706
8707 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008708}
8709
8710/**
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008711 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
8712 * @pf: board private structure
8713 * @queue_count: the requested queue count for rss.
8714 *
8715 * returns 0 if rss is not enabled, if enabled returns the final rss queue
8716 * count which may be different from the requested queue count.
Maciej Sosin373149f2017-04-05 07:50:55 -04008717 * Note: expects to be called while under rtnl_lock()
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008718 **/
8719int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
8720{
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008721 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
8722 int new_rss_size;
8723
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008724 if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
8725 return 0;
8726
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008727 new_rss_size = min_t(int, queue_count, pf->rss_size_max);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008728
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008729 if (queue_count != vsi->num_queue_pairs) {
Harshitha Ramamurthyf25571b2017-02-21 15:55:40 -08008730 u16 qcount;
8731
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008732 vsi->req_queue_pairs = queue_count;
Maciej Sosin373149f2017-04-05 07:50:55 -04008733 i40e_prep_for_reset(pf, true);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008734
Helin Zhangacd65442015-10-26 19:44:28 -04008735 pf->alloc_rss_size = new_rss_size;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008736
Maciej Sosin373149f2017-04-05 07:50:55 -04008737 i40e_reset_and_rebuild(pf, true, true);
Helin Zhang28c58692015-10-26 19:44:27 -04008738
8739 /* Discard the user configured hash keys and lut, if less
8740 * queues are enabled.
8741 */
8742 if (queue_count < vsi->rss_size) {
8743 i40e_clear_rss_config_user(vsi);
8744 dev_dbg(&pf->pdev->dev,
8745 "discard user configured hash keys and lut\n");
8746 }
8747
8748 /* Reset vsi->rss_size, as number of enabled queues changed */
Harshitha Ramamurthyf25571b2017-02-21 15:55:40 -08008749 qcount = vsi->num_queue_pairs / vsi->tc_config.numtc;
8750 vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
Helin Zhang28c58692015-10-26 19:44:27 -04008751
Helin Zhang043dd652015-10-21 19:56:23 -04008752 i40e_pf_config_rss(pf);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008753 }
Lihong Yang12815052016-09-27 11:28:48 -07008754 dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n",
8755 vsi->req_queue_pairs, pf->rss_size_max);
Helin Zhangacd65442015-10-26 19:44:28 -04008756 return pf->alloc_rss_size;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008757}
8758
8759/**
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008760 * i40e_get_partition_bw_setting - Retrieve BW settings for this PF partition
Greg Rosef4492db2015-02-06 08:52:12 +00008761 * @pf: board private structure
8762 **/
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008763i40e_status i40e_get_partition_bw_setting(struct i40e_pf *pf)
Greg Rosef4492db2015-02-06 08:52:12 +00008764{
8765 i40e_status status;
8766 bool min_valid, max_valid;
8767 u32 max_bw, min_bw;
8768
8769 status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
8770 &min_valid, &max_valid);
8771
8772 if (!status) {
8773 if (min_valid)
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008774 pf->min_bw = min_bw;
Greg Rosef4492db2015-02-06 08:52:12 +00008775 if (max_valid)
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008776 pf->max_bw = max_bw;
Greg Rosef4492db2015-02-06 08:52:12 +00008777 }
8778
8779 return status;
8780}
8781
8782/**
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008783 * i40e_set_partition_bw_setting - Set BW settings for this PF partition
Greg Rosef4492db2015-02-06 08:52:12 +00008784 * @pf: board private structure
8785 **/
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008786i40e_status i40e_set_partition_bw_setting(struct i40e_pf *pf)
Greg Rosef4492db2015-02-06 08:52:12 +00008787{
8788 struct i40e_aqc_configure_partition_bw_data bw_data;
8789 i40e_status status;
8790
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00008791 /* Set the valid bit for this PF */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008792 bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008793 bw_data.max_bw[pf->hw.pf_id] = pf->max_bw & I40E_ALT_BW_VALUE_MASK;
8794 bw_data.min_bw[pf->hw.pf_id] = pf->min_bw & I40E_ALT_BW_VALUE_MASK;
Greg Rosef4492db2015-02-06 08:52:12 +00008795
8796 /* Set the new bandwidths */
8797 status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
8798
8799 return status;
8800}
8801
8802/**
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008803 * i40e_commit_partition_bw_setting - Commit BW settings for this PF partition
Greg Rosef4492db2015-02-06 08:52:12 +00008804 * @pf: board private structure
8805 **/
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008806i40e_status i40e_commit_partition_bw_setting(struct i40e_pf *pf)
Greg Rosef4492db2015-02-06 08:52:12 +00008807{
8808 /* Commit temporary BW setting to permanent NVM image */
8809 enum i40e_admin_queue_err last_aq_status;
8810 i40e_status ret;
8811 u16 nvm_word;
8812
8813 if (pf->hw.partition_id != 1) {
8814 dev_info(&pf->pdev->dev,
8815 "Commit BW only works on partition 1! This is partition %d",
8816 pf->hw.partition_id);
8817 ret = I40E_NOT_SUPPORTED;
8818 goto bw_commit_out;
8819 }
8820
8821 /* Acquire NVM for read access */
8822 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
8823 last_aq_status = pf->hw.aq.asq_last_status;
8824 if (ret) {
8825 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008826 "Cannot acquire NVM for read access, err %s aq_err %s\n",
8827 i40e_stat_str(&pf->hw, ret),
8828 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008829 goto bw_commit_out;
8830 }
8831
8832 /* Read word 0x10 of NVM - SW compatibility word 1 */
8833 ret = i40e_aq_read_nvm(&pf->hw,
8834 I40E_SR_NVM_CONTROL_WORD,
8835 0x10, sizeof(nvm_word), &nvm_word,
8836 false, NULL);
8837 /* Save off last admin queue command status before releasing
8838 * the NVM
8839 */
8840 last_aq_status = pf->hw.aq.asq_last_status;
8841 i40e_release_nvm(&pf->hw);
8842 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008843 dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
8844 i40e_stat_str(&pf->hw, ret),
8845 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008846 goto bw_commit_out;
8847 }
8848
8849 /* Wait a bit for NVM release to complete */
8850 msleep(50);
8851
8852 /* Acquire NVM for write access */
8853 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
8854 last_aq_status = pf->hw.aq.asq_last_status;
8855 if (ret) {
8856 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008857 "Cannot acquire NVM for write access, err %s aq_err %s\n",
8858 i40e_stat_str(&pf->hw, ret),
8859 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008860 goto bw_commit_out;
8861 }
8862 /* Write it back out unchanged to initiate update NVM,
8863 * which will force a write of the shadow (alt) RAM to
8864 * the NVM - thus storing the bandwidth values permanently.
8865 */
8866 ret = i40e_aq_update_nvm(&pf->hw,
8867 I40E_SR_NVM_CONTROL_WORD,
8868 0x10, sizeof(nvm_word),
8869 &nvm_word, true, NULL);
8870 /* Save off last admin queue command status before releasing
8871 * the NVM
8872 */
8873 last_aq_status = pf->hw.aq.asq_last_status;
8874 i40e_release_nvm(&pf->hw);
8875 if (ret)
8876 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008877 "BW settings NOT SAVED, err %s aq_err %s\n",
8878 i40e_stat_str(&pf->hw, ret),
8879 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008880bw_commit_out:
8881
8882 return ret;
8883}
8884
8885/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008886 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
8887 * @pf: board private structure to initialize
8888 *
8889 * i40e_sw_init initializes the Adapter private data structure.
8890 * Fields are initialized based on PCI device information and
8891 * OS network device settings (MTU size).
8892 **/
8893static int i40e_sw_init(struct i40e_pf *pf)
8894{
8895 int err = 0;
8896 int size;
8897
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008898 /* Set default capability flags */
8899 pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
8900 I40E_FLAG_MSI_ENABLED |
Mitch Williams2bc7ee82015-02-06 08:52:11 +00008901 I40E_FLAG_MSIX_ENABLED;
8902
Mitch Williamsca99eb92014-04-04 04:43:07 +00008903 /* Set default ITR */
8904 pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
8905 pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
8906
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008907 /* Depending on PF configurations, it is possible that the RSS
8908 * maximum might end up larger than the available queues
8909 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008910 pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
Helin Zhangacd65442015-10-26 19:44:28 -04008911 pf->alloc_rss_size = 1;
Anjali Singhai Jain5db4cb52015-02-24 06:58:49 +00008912 pf->rss_table_size = pf->hw.func_caps.rss_table_size;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008913 pf->rss_size_max = min_t(int, pf->rss_size_max,
8914 pf->hw.func_caps.num_tx_qp);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008915 if (pf->hw.func_caps.rss) {
8916 pf->flags |= I40E_FLAG_RSS_ENABLED;
Helin Zhangacd65442015-10-26 19:44:28 -04008917 pf->alloc_rss_size = min_t(int, pf->rss_size_max,
8918 num_online_cpus());
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008919 }
8920
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008921 /* MFP mode enabled */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04008922 if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008923 pf->flags |= I40E_FLAG_MFP_ENABLED;
8924 dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008925 if (i40e_get_partition_bw_setting(pf)) {
Greg Rosef4492db2015-02-06 08:52:12 +00008926 dev_warn(&pf->pdev->dev,
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008927 "Could not get partition bw settings\n");
8928 } else {
Greg Rosef4492db2015-02-06 08:52:12 +00008929 dev_info(&pf->pdev->dev,
Shannon Nelson4fc8c672017-06-07 05:43:08 -04008930 "Partition BW Min = %8.8x, Max = %8.8x\n",
8931 pf->min_bw, pf->max_bw);
8932
8933 /* nudge the Tx scheduler */
8934 i40e_set_partition_bw_setting(pf);
8935 }
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008936 }
8937
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008938 if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
8939 (pf->hw.func_caps.fd_filters_best_effort > 0)) {
8940 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
8941 pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
Shannon Nelson6eae9c62015-09-03 17:18:55 -04008942 if (pf->flags & I40E_FLAG_MFP_ENABLED &&
8943 pf->hw.num_partitions > 1)
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008944 dev_info(&pf->pdev->dev,
Anjali Singhai Jain0b675842014-03-06 08:59:51 +00008945 "Flow Director Sideband mode Disabled in MFP mode\n");
Shannon Nelson6eae9c62015-09-03 17:18:55 -04008946 else
8947 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008948 pf->fdir_pf_filter_count =
8949 pf->hw.func_caps.fd_filters_guaranteed;
8950 pf->hw.fdir_shared_filter_count =
8951 pf->hw.func_caps.fd_filters_best_effort;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008952 }
8953
Anjali Singhai Jain5a433192017-06-23 04:24:45 -04008954 if (pf->hw.mac.type == I40E_MAC_X722) {
Jacob Kellerd36e41d2017-06-23 04:24:46 -04008955 pf->hw_features |= (I40E_HW_RSS_AQ_CAPABLE |
8956 I40E_HW_128_QP_RSS_CAPABLE |
8957 I40E_HW_ATR_EVICT_CAPABLE |
8958 I40E_HW_WB_ON_ITR_CAPABLE |
8959 I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE |
8960 I40E_HW_NO_PCI_LINK_CHECK |
8961 I40E_HW_USE_SET_LLDP_MIB |
8962 I40E_HW_GENEVE_OFFLOAD_CAPABLE |
8963 I40E_HW_PTP_L4_CAPABLE |
8964 I40E_HW_WOL_MC_MAGIC_PKT_WAKE |
8965 I40E_HW_OUTER_UDP_CSUM_CAPABLE);
Anjali Singhai Jain5a433192017-06-23 04:24:45 -04008966 } else if ((pf->hw.aq.api_maj_ver > 1) ||
8967 ((pf->hw.aq.api_maj_ver == 1) &&
8968 (pf->hw.aq.api_min_ver > 4))) {
8969 /* Supported in FW API version higher than 1.4 */
Jacob Kellerd36e41d2017-06-23 04:24:46 -04008970 pf->hw_features |= I40E_HW_GENEVE_OFFLOAD_CAPABLE;
Anjali Singhai Jain5a433192017-06-23 04:24:45 -04008971 }
8972
8973 /* Enable HW ATR eviction if possible */
Jacob Kellerd36e41d2017-06-23 04:24:46 -04008974 if (pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE)
Anjali Singhai Jain5a433192017-06-23 04:24:45 -04008975 pf->flags |= I40E_FLAG_HW_ATR_EVICT_ENABLED;
8976
Bimmy Pujari6de432c2016-11-11 12:39:38 -08008977 if ((pf->hw.mac.type == I40E_MAC_XL710) &&
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08008978 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008979 (pf->hw.aq.fw_maj_ver < 4))) {
Jacob Kellerd36e41d2017-06-23 04:24:46 -04008980 pf->hw_features |= I40E_HW_RESTART_AUTONEG;
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008981 /* No DCB support for FW < v4.33 */
Jacob Kellerd36e41d2017-06-23 04:24:46 -04008982 pf->hw_features |= I40E_HW_NO_DCB_SUPPORT;
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008983 }
8984
8985 /* Disable FW LLDP if FW < v4.3 */
Bimmy Pujari6de432c2016-11-11 12:39:38 -08008986 if ((pf->hw.mac.type == I40E_MAC_XL710) &&
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008987 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
8988 (pf->hw.aq.fw_maj_ver < 4)))
Jacob Kellerd36e41d2017-06-23 04:24:46 -04008989 pf->hw_features |= I40E_HW_STOP_FW_LLDP;
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008990
8991 /* Use the FW Set LLDP MIB API if FW > v4.40 */
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 >= 40)) ||
8994 (pf->hw.aq.fw_maj_ver >= 5)))
Jacob Kellerd36e41d2017-06-23 04:24:46 -04008995 pf->hw_features |= I40E_HW_USE_SET_LLDP_MIB;
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08008996
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008997 if (pf->hw.func_caps.vmdq) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008998 pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008999 pf->flags |= I40E_FLAG_VMDQ_ENABLED;
Jesse Brandeburge9e53662015-10-02 17:57:21 -07009000 pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009001 }
9002
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06009003 if (pf->hw.func_caps.iwarp) {
9004 pf->flags |= I40E_FLAG_IWARP_ENABLED;
9005 /* IWARP needs one extra vector for CQP just like MISC.*/
9006 pf->num_iwarp_msix = (int)num_online_cpus() + 1;
9007 }
9008
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009009#ifdef CONFIG_PCI_IOV
Shannon Nelsonba252f132014-12-11 07:06:34 +00009010 if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009011 pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
9012 pf->flags |= I40E_FLAG_SRIOV_ENABLED;
9013 pf->num_req_vfs = min_t(int,
9014 pf->hw.func_caps.num_vfs,
9015 I40E_MAX_VF_COUNT);
9016 }
9017#endif /* CONFIG_PCI_IOV */
9018 pf->eeprom_version = 0xDEAD;
9019 pf->lan_veb = I40E_NO_VEB;
9020 pf->lan_vsi = I40E_NO_VSI;
9021
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04009022 /* By default FW has this off for performance reasons */
9023 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
9024
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009025 /* set up queue assignment tracking */
9026 size = sizeof(struct i40e_lump_tracking)
9027 + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
9028 pf->qp_pile = kzalloc(size, GFP_KERNEL);
9029 if (!pf->qp_pile) {
9030 err = -ENOMEM;
9031 goto sw_init_done;
9032 }
9033 pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
9034 pf->qp_pile->search_hint = 0;
9035
Anjali Singhai Jain327fe042014-06-04 01:23:26 +00009036 pf->tx_timeout_recovery_level = 1;
9037
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009038 mutex_init(&pf->switch_mutex);
9039
9040sw_init_done:
9041 return err;
9042}
9043
9044/**
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00009045 * i40e_set_ntuple - set the ntuple feature flag and take action
9046 * @pf: board private structure to initialize
9047 * @features: the feature set that the stack is suggesting
9048 *
9049 * returns a bool to indicate if reset needs to happen
9050 **/
9051bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
9052{
9053 bool need_reset = false;
9054
9055 /* Check if Flow Director n-tuple support was enabled or disabled. If
9056 * the state changed, we need to reset.
9057 */
9058 if (features & NETIF_F_NTUPLE) {
9059 /* Enable filters and mark for reset */
9060 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
9061 need_reset = true;
Tushar Davea70e4072016-05-16 12:40:53 -07009062 /* enable FD_SB only if there is MSI-X vector */
9063 if (pf->num_fdsb_msix > 0)
9064 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00009065 } else {
9066 /* turn off filters, mark for reset and clear SW filter list */
9067 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
9068 need_reset = true;
9069 i40e_fdir_filter_exit(pf);
9070 }
Jacob Keller47994c12017-04-19 09:25:57 -04009071 pf->flags &= ~(I40E_FLAG_FD_SB_ENABLED |
9072 I40E_FLAG_FD_SB_AUTO_DISABLED);
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00009073 /* reset fd counters */
Jacob Keller097dbf52017-02-06 14:38:46 -08009074 pf->fd_add_err = 0;
9075 pf->fd_atr_cnt = 0;
Anjali Singhai Jain8a4f34f2014-06-04 08:45:20 +00009076 /* if ATR was auto disabled it can be re-enabled. */
Jacob Keller47994c12017-04-19 09:25:57 -04009077 if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) {
9078 pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
9079 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
9080 (I40E_DEBUG_FD & pf->hw.debug_mask))
Jacob Keller234dc4e2016-09-06 18:05:09 -07009081 dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
9082 }
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00009083 }
9084 return need_reset;
9085}
9086
9087/**
Alan Bradyd8ec9862016-07-27 12:02:38 -07009088 * i40e_clear_rss_lut - clear the rx hash lookup table
9089 * @vsi: the VSI being configured
9090 **/
9091static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
9092{
9093 struct i40e_pf *pf = vsi->back;
9094 struct i40e_hw *hw = &pf->hw;
9095 u16 vf_id = vsi->vf_id;
9096 u8 i;
9097
9098 if (vsi->type == I40E_VSI_MAIN) {
9099 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
9100 wr32(hw, I40E_PFQF_HLUT(i), 0);
9101 } else if (vsi->type == I40E_VSI_SRIOV) {
9102 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
9103 i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
9104 } else {
9105 dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
9106 }
9107}
9108
9109/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009110 * i40e_set_features - set the netdev feature flags
9111 * @netdev: ptr to the netdev being adjusted
9112 * @features: the feature set that the stack is suggesting
Maciej Sosin373149f2017-04-05 07:50:55 -04009113 * Note: expects to be called while under rtnl_lock()
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009114 **/
9115static int i40e_set_features(struct net_device *netdev,
9116 netdev_features_t features)
9117{
9118 struct i40e_netdev_priv *np = netdev_priv(netdev);
9119 struct i40e_vsi *vsi = np->vsi;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00009120 struct i40e_pf *pf = vsi->back;
9121 bool need_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009122
Alan Bradyd8ec9862016-07-27 12:02:38 -07009123 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
9124 i40e_pf_config_rss(pf);
9125 else if (!(features & NETIF_F_RXHASH) &&
9126 netdev->features & NETIF_F_RXHASH)
9127 i40e_clear_rss_lut(vsi);
9128
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009129 if (features & NETIF_F_HW_VLAN_CTAG_RX)
9130 i40e_vlan_stripping_enable(vsi);
9131 else
9132 i40e_vlan_stripping_disable(vsi);
9133
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00009134 need_reset = i40e_set_ntuple(pf, features);
9135
9136 if (need_reset)
Maciej Sosin373149f2017-04-05 07:50:55 -04009137 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED), true);
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00009138
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009139 return 0;
9140}
9141
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009142/**
Singhai, Anjali6a899022015-12-14 12:21:18 -08009143 * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009144 * @pf: board private structure
9145 * @port: The UDP port to look up
9146 *
9147 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
9148 **/
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08009149static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, u16 port)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009150{
9151 u8 i;
9152
9153 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
Jacob Keller27826fd2017-04-19 09:25:50 -04009154 if (pf->udp_ports[i].port == port)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009155 return i;
9156 }
9157
9158 return i;
9159}
9160
9161/**
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009162 * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009163 * @netdev: This physical port's netdev
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009164 * @ti: Tunnel endpoint information
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009165 **/
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009166static void i40e_udp_tunnel_add(struct net_device *netdev,
9167 struct udp_tunnel_info *ti)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009168{
9169 struct i40e_netdev_priv *np = netdev_priv(netdev);
9170 struct i40e_vsi *vsi = np->vsi;
9171 struct i40e_pf *pf = vsi->back;
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08009172 u16 port = ntohs(ti->port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009173 u8 next_idx;
9174 u8 idx;
9175
Singhai, Anjali6a899022015-12-14 12:21:18 -08009176 idx = i40e_get_udp_port_idx(pf, port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009177
9178 /* Check if port already exists */
9179 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08009180 netdev_info(netdev, "port %d already offloaded\n", port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009181 return;
9182 }
9183
9184 /* Now check if there is space to add the new port */
Singhai, Anjali6a899022015-12-14 12:21:18 -08009185 next_idx = i40e_get_udp_port_idx(pf, 0);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009186
9187 if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009188 netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08009189 port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009190 return;
9191 }
9192
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009193 switch (ti->type) {
9194 case UDP_TUNNEL_TYPE_VXLAN:
9195 pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
9196 break;
9197 case UDP_TUNNEL_TYPE_GENEVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04009198 if (!(pf->hw_features & I40E_HW_GENEVE_OFFLOAD_CAPABLE))
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009199 return;
9200 pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
9201 break;
9202 default:
9203 return;
9204 }
9205
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009206 /* New port: add it and mark its index in the bitmap */
Jacob Keller27826fd2017-04-19 09:25:50 -04009207 pf->udp_ports[next_idx].port = port;
Singhai, Anjali6a899022015-12-14 12:21:18 -08009208 pf->pending_udp_bitmap |= BIT_ULL(next_idx);
9209 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009210}
9211
9212/**
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009213 * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009214 * @netdev: This physical port's netdev
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009215 * @ti: Tunnel endpoint information
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009216 **/
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009217static void i40e_udp_tunnel_del(struct net_device *netdev,
9218 struct udp_tunnel_info *ti)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009219{
9220 struct i40e_netdev_priv *np = netdev_priv(netdev);
9221 struct i40e_vsi *vsi = np->vsi;
9222 struct i40e_pf *pf = vsi->back;
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08009223 u16 port = ntohs(ti->port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009224 u8 idx;
9225
Singhai, Anjali6a899022015-12-14 12:21:18 -08009226 idx = i40e_get_udp_port_idx(pf, port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009227
9228 /* Check if port already exists */
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009229 if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
9230 goto not_found;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009231
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009232 switch (ti->type) {
9233 case UDP_TUNNEL_TYPE_VXLAN:
9234 if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
9235 goto not_found;
9236 break;
9237 case UDP_TUNNEL_TYPE_GENEVE:
9238 if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
9239 goto not_found;
9240 break;
9241 default:
9242 goto not_found;
Singhai, Anjali6a899022015-12-14 12:21:18 -08009243 }
9244
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009245 /* if port exists, set it to 0 (mark for deletion)
9246 * and make it pending
9247 */
Jacob Keller27826fd2017-04-19 09:25:50 -04009248 pf->udp_ports[idx].port = 0;
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009249 pf->pending_udp_bitmap |= BIT_ULL(idx);
Singhai, Anjali6a899022015-12-14 12:21:18 -08009250 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
9251
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009252 return;
9253not_found:
9254 netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
Jacob Kellerfe0b0cd2017-02-06 14:38:38 -08009255 port);
Singhai, Anjali6a899022015-12-14 12:21:18 -08009256}
9257
Neerav Parikh1f224ad2014-02-12 01:45:31 +00009258static int i40e_get_phys_port_id(struct net_device *netdev,
Jiri Pirko02637fc2014-11-28 14:34:16 +01009259 struct netdev_phys_item_id *ppid)
Neerav Parikh1f224ad2014-02-12 01:45:31 +00009260{
9261 struct i40e_netdev_priv *np = netdev_priv(netdev);
9262 struct i40e_pf *pf = np->vsi->back;
9263 struct i40e_hw *hw = &pf->hw;
9264
Jacob Kellerd36e41d2017-06-23 04:24:46 -04009265 if (!(pf->hw_features & I40E_HW_PORT_ID_VALID))
Neerav Parikh1f224ad2014-02-12 01:45:31 +00009266 return -EOPNOTSUPP;
9267
9268 ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
9269 memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
9270
9271 return 0;
9272}
9273
Jesse Brandeburg2f90ade2014-11-20 16:30:02 -08009274/**
9275 * i40e_ndo_fdb_add - add an entry to the hardware database
9276 * @ndm: the input from the stack
9277 * @tb: pointer to array of nladdr (unused)
9278 * @dev: the net device pointer
9279 * @addr: the MAC address entry being added
9280 * @flags: instructions from stack about fdb operation
9281 */
Greg Rose4ba0dea2014-03-06 08:59:55 +00009282static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
9283 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01009284 const unsigned char *addr, u16 vid,
Greg Rose4ba0dea2014-03-06 08:59:55 +00009285 u16 flags)
Greg Rose4ba0dea2014-03-06 08:59:55 +00009286{
9287 struct i40e_netdev_priv *np = netdev_priv(dev);
9288 struct i40e_pf *pf = np->vsi->back;
9289 int err = 0;
9290
9291 if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
9292 return -EOPNOTSUPP;
9293
Or Gerlitz65891fe2014-12-14 18:19:05 +02009294 if (vid) {
9295 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
9296 return -EINVAL;
9297 }
9298
Greg Rose4ba0dea2014-03-06 08:59:55 +00009299 /* Hardware does not support aging addresses so if a
9300 * ndm_state is given only allow permanent addresses
9301 */
9302 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
9303 netdev_info(dev, "FDB only supports static addresses\n");
9304 return -EINVAL;
9305 }
9306
9307 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
9308 err = dev_uc_add_excl(dev, addr);
9309 else if (is_multicast_ether_addr(addr))
9310 err = dev_mc_add_excl(dev, addr);
9311 else
9312 err = -EINVAL;
9313
9314 /* Only return duplicate errors if NLM_F_EXCL is set */
9315 if (err == -EEXIST && !(flags & NLM_F_EXCL))
9316 err = 0;
9317
9318 return err;
9319}
9320
Neerav Parikh51616012015-02-06 08:52:14 +00009321/**
9322 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
9323 * @dev: the netdev being configured
9324 * @nlh: RTNL message
9325 *
9326 * Inserts a new hardware bridge if not already created and
9327 * enables the bridging mode requested (VEB or VEPA). If the
9328 * hardware bridge has already been inserted and the request
9329 * is to change the mode then that requires a PF reset to
9330 * allow rebuild of the components with required hardware
9331 * bridge mode enabled.
Maciej Sosin373149f2017-04-05 07:50:55 -04009332 *
9333 * Note: expects to be called while under rtnl_lock()
Neerav Parikh51616012015-02-06 08:52:14 +00009334 **/
9335static int i40e_ndo_bridge_setlink(struct net_device *dev,
Carolyn Wyborny9df70b62015-04-27 14:57:11 -04009336 struct nlmsghdr *nlh,
9337 u16 flags)
Neerav Parikh51616012015-02-06 08:52:14 +00009338{
9339 struct i40e_netdev_priv *np = netdev_priv(dev);
9340 struct i40e_vsi *vsi = np->vsi;
9341 struct i40e_pf *pf = vsi->back;
9342 struct i40e_veb *veb = NULL;
9343 struct nlattr *attr, *br_spec;
9344 int i, rem;
9345
9346 /* Only for PF VSI for now */
9347 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
9348 return -EOPNOTSUPP;
9349
9350 /* Find the HW bridge for PF VSI */
9351 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
9352 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
9353 veb = pf->veb[i];
9354 }
9355
9356 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
9357
9358 nla_for_each_nested(attr, br_spec, rem) {
9359 __u16 mode;
9360
9361 if (nla_type(attr) != IFLA_BRIDGE_MODE)
9362 continue;
9363
9364 mode = nla_get_u16(attr);
9365 if ((mode != BRIDGE_MODE_VEPA) &&
9366 (mode != BRIDGE_MODE_VEB))
9367 return -EINVAL;
9368
9369 /* Insert a new HW bridge */
9370 if (!veb) {
9371 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
9372 vsi->tc_config.enabled_tc);
9373 if (veb) {
9374 veb->bridge_mode = mode;
9375 i40e_config_bridge_mode(veb);
9376 } else {
9377 /* No Bridge HW offload available */
9378 return -ENOENT;
9379 }
9380 break;
9381 } else if (mode != veb->bridge_mode) {
9382 /* Existing HW bridge but different mode needs reset */
9383 veb->bridge_mode = mode;
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009384 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
9385 if (mode == BRIDGE_MODE_VEB)
9386 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
9387 else
9388 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
Maciej Sosin373149f2017-04-05 07:50:55 -04009389 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED),
9390 true);
Neerav Parikh51616012015-02-06 08:52:14 +00009391 break;
9392 }
9393 }
9394
9395 return 0;
9396}
9397
9398/**
9399 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
9400 * @skb: skb buff
9401 * @pid: process id
9402 * @seq: RTNL message seq #
9403 * @dev: the netdev being configured
9404 * @filter_mask: unused
Jesse Brandeburgd4b2f9f2015-09-03 17:18:48 -04009405 * @nlflags: netlink flags passed in
Neerav Parikh51616012015-02-06 08:52:14 +00009406 *
9407 * Return the mode in which the hardware bridge is operating in
9408 * i.e VEB or VEPA.
9409 **/
Neerav Parikh51616012015-02-06 08:52:14 +00009410static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
9411 struct net_device *dev,
Carolyn Wyborny9f4ffc42015-08-31 19:54:42 -04009412 u32 __always_unused filter_mask,
9413 int nlflags)
Neerav Parikh51616012015-02-06 08:52:14 +00009414{
9415 struct i40e_netdev_priv *np = netdev_priv(dev);
9416 struct i40e_vsi *vsi = np->vsi;
9417 struct i40e_pf *pf = vsi->back;
9418 struct i40e_veb *veb = NULL;
9419 int i;
9420
9421 /* Only for PF VSI for now */
9422 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
9423 return -EOPNOTSUPP;
9424
9425 /* Find the HW bridge for the PF VSI */
9426 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
9427 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
9428 veb = pf->veb[i];
9429 }
9430
9431 if (!veb)
9432 return 0;
9433
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02009434 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
Huaibin Wang599b0762016-09-26 09:51:18 +02009435 0, 0, nlflags, filter_mask, NULL);
Neerav Parikh51616012015-02-06 08:52:14 +00009436}
Neerav Parikh51616012015-02-06 08:52:14 +00009437
Joe Stringerf44a75e2015-04-14 17:09:14 -07009438/**
9439 * i40e_features_check - Validate encapsulated packet conforms to limits
9440 * @skb: skb buff
Jean Sacren2bc11c62015-09-19 05:08:43 -06009441 * @dev: This physical port's netdev
Joe Stringerf44a75e2015-04-14 17:09:14 -07009442 * @features: Offload features that the stack believes apply
9443 **/
9444static netdev_features_t i40e_features_check(struct sk_buff *skb,
9445 struct net_device *dev,
9446 netdev_features_t features)
9447{
Alexander Duyckf114dca2016-10-25 16:08:46 -07009448 size_t len;
9449
9450 /* No point in doing any of this if neither checksum nor GSO are
9451 * being requested for this frame. We can rule out both by just
9452 * checking for CHECKSUM_PARTIAL
9453 */
9454 if (skb->ip_summed != CHECKSUM_PARTIAL)
9455 return features;
9456
9457 /* We cannot support GSO if the MSS is going to be less than
9458 * 64 bytes. If it is then we need to drop support for GSO.
9459 */
9460 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
9461 features &= ~NETIF_F_GSO_MASK;
9462
9463 /* MACLEN can support at most 63 words */
9464 len = skb_network_header(skb) - skb->data;
9465 if (len & ~(63 * 2))
9466 goto out_err;
9467
9468 /* IPLEN and EIPLEN can support at most 127 dwords */
9469 len = skb_transport_header(skb) - skb_network_header(skb);
9470 if (len & ~(127 * 4))
9471 goto out_err;
9472
9473 if (skb->encapsulation) {
9474 /* L4TUNLEN can support 127 words */
9475 len = skb_inner_network_header(skb) - skb_transport_header(skb);
9476 if (len & ~(127 * 2))
9477 goto out_err;
9478
9479 /* IPLEN can support at most 127 dwords */
9480 len = skb_inner_transport_header(skb) -
9481 skb_inner_network_header(skb);
9482 if (len & ~(127 * 4))
9483 goto out_err;
9484 }
9485
9486 /* No need to validate L4LEN as TCP is the only protocol with a
9487 * a flexible value and we support all possible values supported
9488 * by TCP, which is at most 15 dwords
9489 */
Joe Stringerf44a75e2015-04-14 17:09:14 -07009490
9491 return features;
Alexander Duyckf114dca2016-10-25 16:08:46 -07009492out_err:
9493 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
Joe Stringerf44a75e2015-04-14 17:09:14 -07009494}
9495
Björn Töpel0c8493d2017-05-24 07:55:34 +02009496/**
9497 * i40e_xdp_setup - add/remove an XDP program
9498 * @vsi: VSI to changed
9499 * @prog: XDP program
9500 **/
9501static int i40e_xdp_setup(struct i40e_vsi *vsi,
9502 struct bpf_prog *prog)
9503{
9504 int frame_size = vsi->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
9505 struct i40e_pf *pf = vsi->back;
9506 struct bpf_prog *old_prog;
9507 bool need_reset;
9508 int i;
9509
9510 /* Don't allow frames that span over multiple buffers */
9511 if (frame_size > vsi->rx_buf_len)
9512 return -EINVAL;
9513
9514 if (!i40e_enabled_xdp_vsi(vsi) && !prog)
9515 return 0;
9516
9517 /* When turning XDP on->off/off->on we reset and rebuild the rings. */
9518 need_reset = (i40e_enabled_xdp_vsi(vsi) != !!prog);
9519
9520 if (need_reset)
9521 i40e_prep_for_reset(pf, true);
9522
9523 old_prog = xchg(&vsi->xdp_prog, prog);
9524
9525 if (need_reset)
9526 i40e_reset_and_rebuild(pf, true, true);
9527
9528 for (i = 0; i < vsi->num_queue_pairs; i++)
9529 WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
9530
9531 if (old_prog)
9532 bpf_prog_put(old_prog);
9533
9534 return 0;
9535}
9536
9537/**
9538 * i40e_xdp - implements ndo_xdp for i40e
9539 * @dev: netdevice
9540 * @xdp: XDP command
9541 **/
9542static int i40e_xdp(struct net_device *dev,
9543 struct netdev_xdp *xdp)
9544{
9545 struct i40e_netdev_priv *np = netdev_priv(dev);
9546 struct i40e_vsi *vsi = np->vsi;
9547
9548 if (vsi->type != I40E_VSI_MAIN)
9549 return -EINVAL;
9550
9551 switch (xdp->command) {
9552 case XDP_SETUP_PROG:
9553 return i40e_xdp_setup(vsi, xdp->prog);
9554 case XDP_QUERY_PROG:
9555 xdp->prog_attached = i40e_enabled_xdp_vsi(vsi);
Daniel Borkmanneb230392017-06-24 21:13:52 +02009556 xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id : 0;
Björn Töpel0c8493d2017-05-24 07:55:34 +02009557 return 0;
9558 default:
9559 return -EINVAL;
9560 }
9561}
9562
Shannon Nelson37a29732015-02-27 09:15:19 +00009563static const struct net_device_ops i40e_netdev_ops = {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009564 .ndo_open = i40e_open,
9565 .ndo_stop = i40e_close,
9566 .ndo_start_xmit = i40e_lan_xmit_frame,
9567 .ndo_get_stats64 = i40e_get_netdev_stats_struct,
9568 .ndo_set_rx_mode = i40e_set_rx_mode,
9569 .ndo_validate_addr = eth_validate_addr,
9570 .ndo_set_mac_address = i40e_set_mac,
9571 .ndo_change_mtu = i40e_change_mtu,
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00009572 .ndo_do_ioctl = i40e_ioctl,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009573 .ndo_tx_timeout = i40e_tx_timeout,
9574 .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
9575 .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
9576#ifdef CONFIG_NET_POLL_CONTROLLER
9577 .ndo_poll_controller = i40e_netpoll,
9578#endif
John Fastabende4c67342016-02-16 21:16:15 -08009579 .ndo_setup_tc = __i40e_setup_tc,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009580 .ndo_set_features = i40e_set_features,
9581 .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
9582 .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04009583 .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009584 .ndo_get_vf_config = i40e_ndo_get_vf_config,
Mitch Williams588aefa2014-02-11 08:27:49 +00009585 .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
Serey Konge6d90042014-07-12 07:28:14 +00009586 .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
Anjali Singhai Jainc3bbbd22016-04-01 03:56:07 -07009587 .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009588 .ndo_udp_tunnel_add = i40e_udp_tunnel_add,
9589 .ndo_udp_tunnel_del = i40e_udp_tunnel_del,
Neerav Parikh1f224ad2014-02-12 01:45:31 +00009590 .ndo_get_phys_port_id = i40e_get_phys_port_id,
Greg Rose4ba0dea2014-03-06 08:59:55 +00009591 .ndo_fdb_add = i40e_ndo_fdb_add,
Joe Stringerf44a75e2015-04-14 17:09:14 -07009592 .ndo_features_check = i40e_features_check,
Neerav Parikh51616012015-02-06 08:52:14 +00009593 .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
9594 .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
Björn Töpel0c8493d2017-05-24 07:55:34 +02009595 .ndo_xdp = i40e_xdp,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009596};
9597
9598/**
9599 * i40e_config_netdev - Setup the netdev flags
9600 * @vsi: the VSI being configured
9601 *
9602 * Returns 0 on success, negative value on failure
9603 **/
9604static int i40e_config_netdev(struct i40e_vsi *vsi)
9605{
9606 struct i40e_pf *pf = vsi->back;
9607 struct i40e_hw *hw = &pf->hw;
9608 struct i40e_netdev_priv *np;
9609 struct net_device *netdev;
Jacob Keller435c0842016-11-08 13:05:10 -08009610 u8 broadcast[ETH_ALEN];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009611 u8 mac_addr[ETH_ALEN];
9612 int etherdev_size;
Preethi Banalabacd75c2017-03-27 14:43:18 -07009613 netdev_features_t hw_enc_features;
9614 netdev_features_t hw_features;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009615
9616 etherdev_size = sizeof(struct i40e_netdev_priv);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00009617 netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009618 if (!netdev)
9619 return -ENOMEM;
9620
9621 vsi->netdev = netdev;
9622 np = netdev_priv(netdev);
9623 np->vsi = vsi;
9624
Preethi Banalabacd75c2017-03-27 14:43:18 -07009625 hw_enc_features = NETIF_F_SG |
9626 NETIF_F_IP_CSUM |
9627 NETIF_F_IPV6_CSUM |
9628 NETIF_F_HIGHDMA |
9629 NETIF_F_SOFT_FEATURES |
9630 NETIF_F_TSO |
9631 NETIF_F_TSO_ECN |
9632 NETIF_F_TSO6 |
9633 NETIF_F_GSO_GRE |
9634 NETIF_F_GSO_GRE_CSUM |
9635 NETIF_F_GSO_PARTIAL |
9636 NETIF_F_GSO_UDP_TUNNEL |
9637 NETIF_F_GSO_UDP_TUNNEL_CSUM |
9638 NETIF_F_SCTP_CRC |
9639 NETIF_F_RXHASH |
9640 NETIF_F_RXCSUM |
9641 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009642
Jacob Kellerd36e41d2017-06-23 04:24:46 -04009643 if (!(pf->hw_features & I40E_HW_OUTER_UDP_CSUM_CAPABLE))
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04009644 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
9645
9646 netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009647
Preethi Banalabacd75c2017-03-27 14:43:18 -07009648 netdev->hw_enc_features |= hw_enc_features;
9649
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009650 /* record features VLANs can make use of */
Preethi Banalabacd75c2017-03-27 14:43:18 -07009651 netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009652
Anjali Singhai Jain2e86a0b2014-04-01 07:11:53 +00009653 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009654 netdev->hw_features |= NETIF_F_NTUPLE;
Preethi Banalabacd75c2017-03-27 14:43:18 -07009655 hw_features = hw_enc_features |
9656 NETIF_F_HW_VLAN_CTAG_TX |
9657 NETIF_F_HW_VLAN_CTAG_RX;
Anjali Singhai Jain2e86a0b2014-04-01 07:11:53 +00009658
Preethi Banalabacd75c2017-03-27 14:43:18 -07009659 netdev->hw_features |= hw_features;
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009660
Preethi Banalabacd75c2017-03-27 14:43:18 -07009661 netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04009662 netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009663
9664 if (vsi->type == I40E_VSI_MAIN) {
9665 SET_NETDEV_DEV(netdev, &pf->pdev->dev);
Greg Rose9a173902014-05-22 06:32:02 +00009666 ether_addr_copy(mac_addr, hw->mac.perm_addr);
Jacob Keller41c4c2b2017-04-05 07:50:57 -04009667 /* The following steps are necessary for two reasons. First,
9668 * some older NVM configurations load a default MAC-VLAN
9669 * filter that will accept any tagged packet, and we want to
9670 * replace this with a normal filter. Additionally, it is
9671 * possible our MAC address was provided by the platform using
9672 * Open Firmware or similar.
9673 *
9674 * Thus, we need to remove the default filter and install one
9675 * specific to the MAC address.
Jacob Keller1596b5d2016-11-08 13:05:15 -08009676 */
9677 i40e_rm_default_mac_filter(vsi, mac_addr);
Jacob Keller278e7d02016-10-05 09:30:37 -07009678 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller9569a9a2016-11-11 12:39:37 -08009679 i40e_add_mac_filter(vsi, mac_addr);
Jacob Keller278e7d02016-10-05 09:30:37 -07009680 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009681 } else {
9682 /* relate the VSI_VMDQ name to the VSI_MAIN name */
9683 snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
9684 pf->vsi[pf->lan_vsi]->netdev->name);
9685 random_ether_addr(mac_addr);
Kiran Patil21659032015-09-30 14:09:03 -04009686
Jacob Keller278e7d02016-10-05 09:30:37 -07009687 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller9569a9a2016-11-11 12:39:37 -08009688 i40e_add_mac_filter(vsi, mac_addr);
Jacob Keller278e7d02016-10-05 09:30:37 -07009689 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009690 }
Kiran Patil21659032015-09-30 14:09:03 -04009691
Jacob Keller435c0842016-11-08 13:05:10 -08009692 /* Add the broadcast filter so that we initially will receive
9693 * broadcast packets. Note that when a new VLAN is first added the
9694 * driver will convert all filters marked I40E_VLAN_ANY into VLAN
9695 * specific filters as part of transitioning into "vlan" operation.
9696 * When more VLANs are added, the driver will copy each existing MAC
9697 * filter and add it for the new VLAN.
9698 *
9699 * Broadcast filters are handled specially by
9700 * i40e_sync_filters_subtask, as the driver must to set the broadcast
9701 * promiscuous bit instead of adding this directly as a MAC/VLAN
9702 * filter. The subtask will update the correct broadcast promiscuous
9703 * bits as VLANs become active or inactive.
9704 */
9705 eth_broadcast_addr(broadcast);
9706 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller9569a9a2016-11-11 12:39:37 -08009707 i40e_add_mac_filter(vsi, broadcast);
Jacob Keller435c0842016-11-08 13:05:10 -08009708 spin_unlock_bh(&vsi->mac_filter_hash_lock);
9709
Greg Rose9a173902014-05-22 06:32:02 +00009710 ether_addr_copy(netdev->dev_addr, mac_addr);
9711 ether_addr_copy(netdev->perm_addr, mac_addr);
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009712
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009713 netdev->priv_flags |= IFF_UNICAST_FLT;
9714 netdev->priv_flags |= IFF_SUPP_NOFCS;
9715 /* Setup netdev TC information */
9716 i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
9717
9718 netdev->netdev_ops = &i40e_netdev_ops;
9719 netdev->watchdog_timeo = 5 * HZ;
9720 i40e_set_ethtool_ops(netdev);
9721
Jarod Wilson91c527a2016-10-17 15:54:05 -04009722 /* MTU range: 68 - 9706 */
9723 netdev->min_mtu = ETH_MIN_MTU;
Mitch Williams1e3a5fd2017-06-23 04:24:43 -04009724 netdev->max_mtu = I40E_MAX_RXBUFFER - I40E_PACKET_HDR_PAD;
Jarod Wilson91c527a2016-10-17 15:54:05 -04009725
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009726 return 0;
9727}
9728
9729/**
9730 * i40e_vsi_delete - Delete a VSI from the switch
9731 * @vsi: the VSI being removed
9732 *
9733 * Returns 0 on success, negative value on failure
9734 **/
9735static void i40e_vsi_delete(struct i40e_vsi *vsi)
9736{
9737 /* remove default VSI is not allowed */
9738 if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
9739 return;
9740
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009741 i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009742}
9743
9744/**
Neerav Parikh51616012015-02-06 08:52:14 +00009745 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
9746 * @vsi: the VSI being queried
9747 *
9748 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
9749 **/
9750int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
9751{
9752 struct i40e_veb *veb;
9753 struct i40e_pf *pf = vsi->back;
9754
9755 /* Uplink is not a bridge so default to VEB */
9756 if (vsi->veb_idx == I40E_NO_VEB)
9757 return 1;
9758
9759 veb = pf->veb[vsi->veb_idx];
Akeem G Abodunrin09603ea2015-10-01 14:37:36 -04009760 if (!veb) {
9761 dev_info(&pf->pdev->dev,
9762 "There is no veb associated with the bridge\n");
9763 return -ENOENT;
9764 }
Neerav Parikh51616012015-02-06 08:52:14 +00009765
Akeem G Abodunrin09603ea2015-10-01 14:37:36 -04009766 /* Uplink is a bridge in VEPA mode */
9767 if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
9768 return 0;
9769 } else {
9770 /* Uplink is a bridge in VEB mode */
9771 return 1;
9772 }
9773
9774 /* VEPA is now default bridge, so return 0 */
9775 return 0;
Neerav Parikh51616012015-02-06 08:52:14 +00009776}
9777
9778/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009779 * i40e_add_vsi - Add a VSI to the switch
9780 * @vsi: the VSI being configured
9781 *
9782 * This initializes a VSI context depending on the VSI type to be added and
9783 * passes it down to the add_vsi aq command.
9784 **/
9785static int i40e_add_vsi(struct i40e_vsi *vsi)
9786{
9787 int ret = -ENODEV;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009788 struct i40e_pf *pf = vsi->back;
9789 struct i40e_hw *hw = &pf->hw;
9790 struct i40e_vsi_context ctxt;
Jacob Keller278e7d02016-10-05 09:30:37 -07009791 struct i40e_mac_filter *f;
9792 struct hlist_node *h;
9793 int bkt;
Kiran Patil21659032015-09-30 14:09:03 -04009794
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009795 u8 enabled_tc = 0x1; /* TC0 enabled */
9796 int f_count = 0;
9797
9798 memset(&ctxt, 0, sizeof(ctxt));
9799 switch (vsi->type) {
9800 case I40E_VSI_MAIN:
9801 /* The PF's main VSI is already setup as part of the
9802 * device initialization, so we'll not bother with
9803 * the add_vsi call, but we will retrieve the current
9804 * VSI context.
9805 */
9806 ctxt.seid = pf->main_vsi_seid;
9807 ctxt.pf_num = pf->hw.pf_id;
9808 ctxt.vf_num = 0;
9809 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
9810 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
9811 if (ret) {
9812 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009813 "couldn't get PF vsi config, err %s aq_err %s\n",
9814 i40e_stat_str(&pf->hw, ret),
9815 i40e_aq_str(&pf->hw,
9816 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009817 return -ENOENT;
9818 }
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07009819 vsi->info = ctxt.info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009820 vsi->info.valid_sections = 0;
9821
9822 vsi->seid = ctxt.seid;
9823 vsi->id = ctxt.vsi_number;
9824
9825 enabled_tc = i40e_pf_get_tc_map(pf);
9826
9827 /* MFP mode setup queue map and update VSI */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00009828 if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
9829 !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009830 memset(&ctxt, 0, sizeof(ctxt));
9831 ctxt.seid = pf->main_vsi_seid;
9832 ctxt.pf_num = pf->hw.pf_id;
9833 ctxt.vf_num = 0;
9834 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
9835 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
9836 if (ret) {
9837 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009838 "update vsi failed, err %s aq_err %s\n",
9839 i40e_stat_str(&pf->hw, ret),
9840 i40e_aq_str(&pf->hw,
9841 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009842 ret = -ENOENT;
9843 goto err;
9844 }
9845 /* update the local VSI info queue map */
9846 i40e_vsi_update_queue_map(vsi, &ctxt);
9847 vsi->info.valid_sections = 0;
9848 } else {
9849 /* Default/Main VSI is only enabled for TC0
9850 * reconfigure it to enable all TCs that are
9851 * available on the port in SFP mode.
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00009852 * For MFP case the iSCSI PF would use this
9853 * flow to enable LAN+iSCSI TC.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009854 */
9855 ret = i40e_vsi_config_tc(vsi, enabled_tc);
9856 if (ret) {
9857 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009858 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
9859 enabled_tc,
9860 i40e_stat_str(&pf->hw, ret),
9861 i40e_aq_str(&pf->hw,
9862 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009863 ret = -ENOENT;
9864 }
9865 }
9866 break;
9867
9868 case I40E_VSI_FDIR:
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009869 ctxt.pf_num = hw->pf_id;
9870 ctxt.vf_num = 0;
9871 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009872 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009873 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009874 if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
9875 (i40e_is_vsi_uplink_mode_veb(vsi))) {
Neerav Parikh51616012015-02-06 08:52:14 +00009876 ctxt.info.valid_sections |=
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009877 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
Neerav Parikh51616012015-02-06 08:52:14 +00009878 ctxt.info.switch_id =
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009879 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
Neerav Parikh51616012015-02-06 08:52:14 +00009880 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009881 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009882 break;
9883
9884 case I40E_VSI_VMDQ2:
9885 ctxt.pf_num = hw->pf_id;
9886 ctxt.vf_num = 0;
9887 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009888 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009889 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
9890
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009891 /* This VSI is connected to VEB so the switch_id
9892 * should be set to zero by default.
9893 */
Neerav Parikh51616012015-02-06 08:52:14 +00009894 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
9895 ctxt.info.valid_sections |=
9896 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9897 ctxt.info.switch_id =
9898 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9899 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009900
9901 /* Setup the VSI tx/rx queue map for TC0 only for now */
9902 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9903 break;
9904
9905 case I40E_VSI_SRIOV:
9906 ctxt.pf_num = hw->pf_id;
9907 ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
9908 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009909 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009910 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
9911
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009912 /* This VSI is connected to VEB so the switch_id
9913 * should be set to zero by default.
9914 */
Neerav Parikh51616012015-02-06 08:52:14 +00009915 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
9916 ctxt.info.valid_sections |=
9917 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9918 ctxt.info.switch_id =
9919 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9920 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009921
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06009922 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
9923 ctxt.info.valid_sections |=
9924 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
9925 ctxt.info.queueing_opt_flags |=
Ashish Shah4b28cdb2016-05-03 15:13:17 -07009926 (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
9927 I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06009928 }
9929
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009930 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
9931 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
Mitch Williamsc674d122014-05-20 08:01:40 +00009932 if (pf->vf[vsi->vf_id].spoofchk) {
9933 ctxt.info.valid_sections |=
9934 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
9935 ctxt.info.sec_flags |=
9936 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
9937 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
9938 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009939 /* Setup the VSI tx/rx queue map for TC0 only for now */
9940 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9941 break;
9942
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06009943 case I40E_VSI_IWARP:
9944 /* send down message to iWARP */
9945 break;
9946
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009947 default:
9948 return -ENODEV;
9949 }
9950
9951 if (vsi->type != I40E_VSI_MAIN) {
9952 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
9953 if (ret) {
9954 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009955 "add vsi failed, err %s aq_err %s\n",
9956 i40e_stat_str(&pf->hw, ret),
9957 i40e_aq_str(&pf->hw,
9958 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009959 ret = -ENOENT;
9960 goto err;
9961 }
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07009962 vsi->info = ctxt.info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009963 vsi->info.valid_sections = 0;
9964 vsi->seid = ctxt.seid;
9965 vsi->id = ctxt.vsi_number;
9966 }
9967
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07009968 vsi->active_filters = 0;
Jacob Keller0da36b92017-04-19 09:25:55 -04009969 clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
Jacob Keller278e7d02016-10-05 09:30:37 -07009970 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009971 /* If macvlan filters already exist, force them to get loaded */
Jacob Keller278e7d02016-10-05 09:30:37 -07009972 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07009973 f->state = I40E_FILTER_NEW;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009974 f_count++;
9975 }
Jacob Keller278e7d02016-10-05 09:30:37 -07009976 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -04009977
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009978 if (f_count) {
9979 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
9980 pf->flags |= I40E_FLAG_FILTER_SYNC;
9981 }
9982
9983 /* Update VSI BW information */
9984 ret = i40e_vsi_get_bw_info(vsi);
9985 if (ret) {
9986 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009987 "couldn't get vsi bw info, err %s aq_err %s\n",
9988 i40e_stat_str(&pf->hw, ret),
9989 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009990 /* VSI is already added so not tearing that up */
9991 ret = 0;
9992 }
9993
9994err:
9995 return ret;
9996}
9997
9998/**
9999 * i40e_vsi_release - Delete a VSI and free its resources
10000 * @vsi: the VSI being removed
10001 *
10002 * Returns 0 on success or < 0 on error
10003 **/
10004int i40e_vsi_release(struct i40e_vsi *vsi)
10005{
Jacob Keller278e7d02016-10-05 09:30:37 -070010006 struct i40e_mac_filter *f;
10007 struct hlist_node *h;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010008 struct i40e_veb *veb = NULL;
10009 struct i40e_pf *pf;
10010 u16 uplink_seid;
Jacob Keller278e7d02016-10-05 09:30:37 -070010011 int i, n, bkt;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010012
10013 pf = vsi->back;
10014
10015 /* release of a VEB-owner or last VSI is not allowed */
10016 if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
10017 dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
10018 vsi->seid, vsi->uplink_seid);
10019 return -ENODEV;
10020 }
10021 if (vsi == pf->vsi[pf->lan_vsi] &&
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030010022 !test_bit(__I40E_DOWN, pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010023 dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
10024 return -ENODEV;
10025 }
10026
10027 uplink_seid = vsi->uplink_seid;
10028 if (vsi->type != I40E_VSI_SRIOV) {
10029 if (vsi->netdev_registered) {
10030 vsi->netdev_registered = false;
10031 if (vsi->netdev) {
10032 /* results in a call to i40e_close() */
10033 unregister_netdev(vsi->netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010034 }
10035 } else {
Shannon Nelson90ef8d42014-03-14 07:32:26 +000010036 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010037 }
10038 i40e_vsi_disable_irq(vsi);
10039 }
10040
Jacob Keller278e7d02016-10-05 09:30:37 -070010041 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller6622f5c2016-10-05 09:30:32 -070010042
10043 /* clear the sync flag on all filters */
10044 if (vsi->netdev) {
10045 __dev_uc_unsync(vsi->netdev, NULL);
10046 __dev_mc_unsync(vsi->netdev, NULL);
10047 }
10048
10049 /* make sure any remaining filters are marked for deletion */
Jacob Keller278e7d02016-10-05 09:30:37 -070010050 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
Jacob Keller290d2552016-10-05 09:30:36 -070010051 __i40e_del_filter(vsi, f);
Jacob Keller6622f5c2016-10-05 09:30:32 -070010052
Jacob Keller278e7d02016-10-05 09:30:37 -070010053 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -040010054
Jesse Brandeburg17652c62015-11-05 17:01:02 -080010055 i40e_sync_vsi_filters(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010056
10057 i40e_vsi_delete(vsi);
10058 i40e_vsi_free_q_vectors(vsi);
Shannon Nelsona4866592014-02-11 08:24:07 +000010059 if (vsi->netdev) {
10060 free_netdev(vsi->netdev);
10061 vsi->netdev = NULL;
10062 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010063 i40e_vsi_clear_rings(vsi);
10064 i40e_vsi_clear(vsi);
10065
10066 /* If this was the last thing on the VEB, except for the
10067 * controlling VSI, remove the VEB, which puts the controlling
10068 * VSI onto the next level down in the switch.
10069 *
10070 * Well, okay, there's one more exception here: don't remove
10071 * the orphan VEBs yet. We'll wait for an explicit remove request
10072 * from up the network stack.
10073 */
Mitch Williams505682c2014-05-20 08:01:37 +000010074 for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010075 if (pf->vsi[i] &&
10076 pf->vsi[i]->uplink_seid == uplink_seid &&
10077 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
10078 n++; /* count the VSIs */
10079 }
10080 }
10081 for (i = 0; i < I40E_MAX_VEB; i++) {
10082 if (!pf->veb[i])
10083 continue;
10084 if (pf->veb[i]->uplink_seid == uplink_seid)
10085 n++; /* count the VEBs */
10086 if (pf->veb[i]->seid == uplink_seid)
10087 veb = pf->veb[i];
10088 }
10089 if (n == 0 && veb && veb->uplink_seid != 0)
10090 i40e_veb_release(veb);
10091
10092 return 0;
10093}
10094
10095/**
10096 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
10097 * @vsi: ptr to the VSI
10098 *
10099 * This should only be called after i40e_vsi_mem_alloc() which allocates the
10100 * corresponding SW VSI structure and initializes num_queue_pairs for the
10101 * newly allocated VSI.
10102 *
10103 * Returns 0 on success or negative on failure
10104 **/
10105static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
10106{
10107 int ret = -ENOENT;
10108 struct i40e_pf *pf = vsi->back;
10109
Alexander Duyck493fb302013-09-28 07:01:44 +000010110 if (vsi->q_vectors[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010111 dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
10112 vsi->seid);
10113 return -EEXIST;
10114 }
10115
10116 if (vsi->base_vector) {
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +000010117 dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010118 vsi->seid, vsi->base_vector);
10119 return -EEXIST;
10120 }
10121
Greg Rose90e04072014-03-06 08:59:57 +000010122 ret = i40e_vsi_alloc_q_vectors(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010123 if (ret) {
10124 dev_info(&pf->pdev->dev,
10125 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
10126 vsi->num_q_vectors, vsi->seid, ret);
10127 vsi->num_q_vectors = 0;
10128 goto vector_setup_out;
10129 }
10130
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -040010131 /* In Legacy mode, we do not have to get any other vector since we
10132 * piggyback on the misc/ICR0 for queue interrupts.
10133 */
10134 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
10135 return ret;
Shannon Nelson958a3e32013-09-28 07:13:28 +000010136 if (vsi->num_q_vectors)
10137 vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
10138 vsi->num_q_vectors, vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010139 if (vsi->base_vector < 0) {
10140 dev_info(&pf->pdev->dev,
Shannon Nelson049a2be2014-10-17 03:14:50 +000010141 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
10142 vsi->num_q_vectors, vsi->seid, vsi->base_vector);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010143 i40e_vsi_free_q_vectors(vsi);
10144 ret = -ENOENT;
10145 goto vector_setup_out;
10146 }
10147
10148vector_setup_out:
10149 return ret;
10150}
10151
10152/**
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010153 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
10154 * @vsi: pointer to the vsi.
10155 *
10156 * This re-allocates a vsi's queue resources.
10157 *
10158 * Returns pointer to the successfully allocated and configured VSI sw struct
10159 * on success, otherwise returns NULL on failure.
10160 **/
10161static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
10162{
Björn Töpel74608d12017-05-24 07:55:35 +020010163 u16 alloc_queue_pairs;
John Underwoodf5340392016-02-18 09:19:24 -080010164 struct i40e_pf *pf;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010165 u8 enabled_tc;
10166 int ret;
10167
John Underwoodf5340392016-02-18 09:19:24 -080010168 if (!vsi)
10169 return NULL;
10170
10171 pf = vsi->back;
10172
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010173 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
10174 i40e_vsi_clear_rings(vsi);
10175
10176 i40e_vsi_free_arrays(vsi, false);
10177 i40e_set_num_rings_in_vsi(vsi);
10178 ret = i40e_vsi_alloc_arrays(vsi, false);
10179 if (ret)
10180 goto err_vsi;
10181
Björn Töpel74608d12017-05-24 07:55:35 +020010182 alloc_queue_pairs = vsi->alloc_queue_pairs *
10183 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
10184
10185 ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010186 if (ret < 0) {
Shannon Nelson049a2be2014-10-17 03:14:50 +000010187 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010188 "failed to get tracking for %d queues for VSI %d err %d\n",
Björn Töpel74608d12017-05-24 07:55:35 +020010189 alloc_queue_pairs, vsi->seid, ret);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010190 goto err_vsi;
10191 }
10192 vsi->base_queue = ret;
10193
10194 /* Update the FW view of the VSI. Force a reset of TC and queue
10195 * layout configurations.
10196 */
10197 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
10198 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
10199 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
10200 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
Jacob Keller1596b5d2016-11-08 13:05:15 -080010201 if (vsi->type == I40E_VSI_MAIN)
10202 i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010203
10204 /* assign it some queues */
10205 ret = i40e_alloc_rings(vsi);
10206 if (ret)
10207 goto err_rings;
10208
10209 /* map all of the rings to the q_vectors */
10210 i40e_vsi_map_rings_to_vectors(vsi);
10211 return vsi;
10212
10213err_rings:
10214 i40e_vsi_free_q_vectors(vsi);
10215 if (vsi->netdev_registered) {
10216 vsi->netdev_registered = false;
10217 unregister_netdev(vsi->netdev);
10218 free_netdev(vsi->netdev);
10219 vsi->netdev = NULL;
10220 }
10221 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
10222err_vsi:
10223 i40e_vsi_clear(vsi);
10224 return NULL;
10225}
10226
10227/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010228 * i40e_vsi_setup - Set up a VSI by a given type
10229 * @pf: board private structure
10230 * @type: VSI type
10231 * @uplink_seid: the switch element to link to
10232 * @param1: usage depends upon VSI type. For VF types, indicates VF id
10233 *
10234 * This allocates the sw VSI structure and its queue resources, then add a VSI
10235 * to the identified VEB.
10236 *
10237 * Returns pointer to the successfully allocated and configure VSI sw struct on
10238 * success, otherwise returns NULL on failure.
10239 **/
10240struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
10241 u16 uplink_seid, u32 param1)
10242{
10243 struct i40e_vsi *vsi = NULL;
10244 struct i40e_veb *veb = NULL;
Björn Töpel74608d12017-05-24 07:55:35 +020010245 u16 alloc_queue_pairs;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010246 int ret, i;
10247 int v_idx;
10248
10249 /* The requested uplink_seid must be either
10250 * - the PF's port seid
10251 * no VEB is needed because this is the PF
10252 * or this is a Flow Director special case VSI
10253 * - seid of an existing VEB
10254 * - seid of a VSI that owns an existing VEB
10255 * - seid of a VSI that doesn't own a VEB
10256 * a new VEB is created and the VSI becomes the owner
10257 * - seid of the PF VSI, which is what creates the first VEB
10258 * this is a special case of the previous
10259 *
10260 * Find which uplink_seid we were given and create a new VEB if needed
10261 */
10262 for (i = 0; i < I40E_MAX_VEB; i++) {
10263 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
10264 veb = pf->veb[i];
10265 break;
10266 }
10267 }
10268
10269 if (!veb && uplink_seid != pf->mac_seid) {
10270
Mitch Williams505682c2014-05-20 08:01:37 +000010271 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010272 if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
10273 vsi = pf->vsi[i];
10274 break;
10275 }
10276 }
10277 if (!vsi) {
10278 dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
10279 uplink_seid);
10280 return NULL;
10281 }
10282
10283 if (vsi->uplink_seid == pf->mac_seid)
10284 veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
10285 vsi->tc_config.enabled_tc);
10286 else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
10287 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
10288 vsi->tc_config.enabled_tc);
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +000010289 if (veb) {
10290 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
10291 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040010292 "New VSI creation error, uplink seid of LAN VSI expected.\n");
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +000010293 return NULL;
10294 }
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -040010295 /* We come up by default in VEPA mode if SRIOV is not
10296 * already enabled, in which case we can't force VEPA
10297 * mode.
10298 */
10299 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
10300 veb->bridge_mode = BRIDGE_MODE_VEPA;
10301 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
10302 }
Neerav Parikh51616012015-02-06 08:52:14 +000010303 i40e_config_bridge_mode(veb);
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +000010304 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010305 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
10306 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
10307 veb = pf->veb[i];
10308 }
10309 if (!veb) {
10310 dev_info(&pf->pdev->dev, "couldn't add VEB\n");
10311 return NULL;
10312 }
10313
10314 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
10315 uplink_seid = veb->seid;
10316 }
10317
10318 /* get vsi sw struct */
10319 v_idx = i40e_vsi_mem_alloc(pf, type);
10320 if (v_idx < 0)
10321 goto err_alloc;
10322 vsi = pf->vsi[v_idx];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010323 if (!vsi)
10324 goto err_alloc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010325 vsi->type = type;
10326 vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
10327
10328 if (type == I40E_VSI_MAIN)
10329 pf->lan_vsi = v_idx;
10330 else if (type == I40E_VSI_SRIOV)
10331 vsi->vf_id = param1;
10332 /* assign it some queues */
Björn Töpel74608d12017-05-24 07:55:35 +020010333 alloc_queue_pairs = vsi->alloc_queue_pairs *
10334 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
10335
10336 ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010337 if (ret < 0) {
Shannon Nelson049a2be2014-10-17 03:14:50 +000010338 dev_info(&pf->pdev->dev,
10339 "failed to get tracking for %d queues for VSI %d err=%d\n",
Björn Töpel74608d12017-05-24 07:55:35 +020010340 alloc_queue_pairs, vsi->seid, ret);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010341 goto err_vsi;
10342 }
10343 vsi->base_queue = ret;
10344
10345 /* get a VSI from the hardware */
10346 vsi->uplink_seid = uplink_seid;
10347 ret = i40e_add_vsi(vsi);
10348 if (ret)
10349 goto err_vsi;
10350
10351 switch (vsi->type) {
10352 /* setup the netdev if needed */
10353 case I40E_VSI_MAIN:
10354 case I40E_VSI_VMDQ2:
10355 ret = i40e_config_netdev(vsi);
10356 if (ret)
10357 goto err_netdev;
10358 ret = register_netdev(vsi->netdev);
10359 if (ret)
10360 goto err_netdev;
10361 vsi->netdev_registered = true;
10362 netif_carrier_off(vsi->netdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080010363#ifdef CONFIG_I40E_DCB
10364 /* Setup DCB netlink interface */
10365 i40e_dcbnl_setup(vsi);
10366#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010367 /* fall through */
10368
10369 case I40E_VSI_FDIR:
10370 /* set up vectors and rings if needed */
10371 ret = i40e_vsi_setup_vectors(vsi);
10372 if (ret)
10373 goto err_msix;
10374
10375 ret = i40e_alloc_rings(vsi);
10376 if (ret)
10377 goto err_rings;
10378
10379 /* map all of the rings to the q_vectors */
10380 i40e_vsi_map_rings_to_vectors(vsi);
10381
10382 i40e_vsi_reset_stats(vsi);
10383 break;
10384
10385 default:
10386 /* no netdev or rings for the other VSI types */
10387 break;
10388 }
10389
Jacob Kellerd36e41d2017-06-23 04:24:46 -040010390 if ((pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) &&
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -040010391 (vsi->type == I40E_VSI_VMDQ2)) {
10392 ret = i40e_vsi_config_rss(vsi);
10393 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010394 return vsi;
10395
10396err_rings:
10397 i40e_vsi_free_q_vectors(vsi);
10398err_msix:
10399 if (vsi->netdev_registered) {
10400 vsi->netdev_registered = false;
10401 unregister_netdev(vsi->netdev);
10402 free_netdev(vsi->netdev);
10403 vsi->netdev = NULL;
10404 }
10405err_netdev:
10406 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
10407err_vsi:
10408 i40e_vsi_clear(vsi);
10409err_alloc:
10410 return NULL;
10411}
10412
10413/**
10414 * i40e_veb_get_bw_info - Query VEB BW information
10415 * @veb: the veb to query
10416 *
10417 * Query the Tx scheduler BW configuration data for given VEB
10418 **/
10419static int i40e_veb_get_bw_info(struct i40e_veb *veb)
10420{
10421 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
10422 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
10423 struct i40e_pf *pf = veb->pf;
10424 struct i40e_hw *hw = &pf->hw;
10425 u32 tc_bw_max;
10426 int ret = 0;
10427 int i;
10428
10429 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
10430 &bw_data, NULL);
10431 if (ret) {
10432 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010433 "query veb bw config failed, err %s aq_err %s\n",
10434 i40e_stat_str(&pf->hw, ret),
10435 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010436 goto out;
10437 }
10438
10439 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
10440 &ets_data, NULL);
10441 if (ret) {
10442 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010443 "query veb bw ets config failed, err %s aq_err %s\n",
10444 i40e_stat_str(&pf->hw, ret),
10445 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010446 goto out;
10447 }
10448
10449 veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
10450 veb->bw_max_quanta = ets_data.tc_bw_max;
10451 veb->is_abs_credits = bw_data.absolute_credits_enable;
Neerav Parikh23cd1f02014-11-12 00:18:41 +000010452 veb->enabled_tc = ets_data.tc_valid_bits;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010453 tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
10454 (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
10455 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10456 veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
10457 veb->bw_tc_limit_credits[i] =
10458 le16_to_cpu(bw_data.tc_bw_limits[i]);
10459 veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
10460 }
10461
10462out:
10463 return ret;
10464}
10465
10466/**
10467 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
10468 * @pf: board private structure
10469 *
10470 * On error: returns error code (negative)
10471 * On success: returns vsi index in PF (positive)
10472 **/
10473static int i40e_veb_mem_alloc(struct i40e_pf *pf)
10474{
10475 int ret = -ENOENT;
10476 struct i40e_veb *veb;
10477 int i;
10478
10479 /* Need to protect the allocation of switch elements at the PF level */
10480 mutex_lock(&pf->switch_mutex);
10481
10482 /* VEB list may be fragmented if VEB creation/destruction has
10483 * been happening. We can afford to do a quick scan to look
10484 * for any free slots in the list.
10485 *
10486 * find next empty veb slot, looping back around if necessary
10487 */
10488 i = 0;
10489 while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
10490 i++;
10491 if (i >= I40E_MAX_VEB) {
10492 ret = -ENOMEM;
10493 goto err_alloc_veb; /* out of VEB slots! */
10494 }
10495
10496 veb = kzalloc(sizeof(*veb), GFP_KERNEL);
10497 if (!veb) {
10498 ret = -ENOMEM;
10499 goto err_alloc_veb;
10500 }
10501 veb->pf = pf;
10502 veb->idx = i;
10503 veb->enabled_tc = 1;
10504
10505 pf->veb[i] = veb;
10506 ret = i;
10507err_alloc_veb:
10508 mutex_unlock(&pf->switch_mutex);
10509 return ret;
10510}
10511
10512/**
10513 * i40e_switch_branch_release - Delete a branch of the switch tree
10514 * @branch: where to start deleting
10515 *
10516 * This uses recursion to find the tips of the branch to be
10517 * removed, deleting until we get back to and can delete this VEB.
10518 **/
10519static void i40e_switch_branch_release(struct i40e_veb *branch)
10520{
10521 struct i40e_pf *pf = branch->pf;
10522 u16 branch_seid = branch->seid;
10523 u16 veb_idx = branch->idx;
10524 int i;
10525
10526 /* release any VEBs on this VEB - RECURSION */
10527 for (i = 0; i < I40E_MAX_VEB; i++) {
10528 if (!pf->veb[i])
10529 continue;
10530 if (pf->veb[i]->uplink_seid == branch->seid)
10531 i40e_switch_branch_release(pf->veb[i]);
10532 }
10533
10534 /* Release the VSIs on this VEB, but not the owner VSI.
10535 *
10536 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
10537 * the VEB itself, so don't use (*branch) after this loop.
10538 */
Mitch Williams505682c2014-05-20 08:01:37 +000010539 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010540 if (!pf->vsi[i])
10541 continue;
10542 if (pf->vsi[i]->uplink_seid == branch_seid &&
10543 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
10544 i40e_vsi_release(pf->vsi[i]);
10545 }
10546 }
10547
10548 /* There's one corner case where the VEB might not have been
10549 * removed, so double check it here and remove it if needed.
10550 * This case happens if the veb was created from the debugfs
10551 * commands and no VSIs were added to it.
10552 */
10553 if (pf->veb[veb_idx])
10554 i40e_veb_release(pf->veb[veb_idx]);
10555}
10556
10557/**
10558 * i40e_veb_clear - remove veb struct
10559 * @veb: the veb to remove
10560 **/
10561static void i40e_veb_clear(struct i40e_veb *veb)
10562{
10563 if (!veb)
10564 return;
10565
10566 if (veb->pf) {
10567 struct i40e_pf *pf = veb->pf;
10568
10569 mutex_lock(&pf->switch_mutex);
10570 if (pf->veb[veb->idx] == veb)
10571 pf->veb[veb->idx] = NULL;
10572 mutex_unlock(&pf->switch_mutex);
10573 }
10574
10575 kfree(veb);
10576}
10577
10578/**
10579 * i40e_veb_release - Delete a VEB and free its resources
10580 * @veb: the VEB being removed
10581 **/
10582void i40e_veb_release(struct i40e_veb *veb)
10583{
10584 struct i40e_vsi *vsi = NULL;
10585 struct i40e_pf *pf;
10586 int i, n = 0;
10587
10588 pf = veb->pf;
10589
10590 /* find the remaining VSI and check for extras */
Mitch Williams505682c2014-05-20 08:01:37 +000010591 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010592 if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
10593 n++;
10594 vsi = pf->vsi[i];
10595 }
10596 }
10597 if (n != 1) {
10598 dev_info(&pf->pdev->dev,
10599 "can't remove VEB %d with %d VSIs left\n",
10600 veb->seid, n);
10601 return;
10602 }
10603
10604 /* move the remaining VSI to uplink veb */
10605 vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
10606 if (veb->uplink_seid) {
10607 vsi->uplink_seid = veb->uplink_seid;
10608 if (veb->uplink_seid == pf->mac_seid)
10609 vsi->veb_idx = I40E_NO_VEB;
10610 else
10611 vsi->veb_idx = veb->veb_idx;
10612 } else {
10613 /* floating VEB */
10614 vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
10615 vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
10616 }
10617
10618 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
10619 i40e_veb_clear(veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010620}
10621
10622/**
10623 * i40e_add_veb - create the VEB in the switch
10624 * @veb: the VEB to be instantiated
10625 * @vsi: the controlling VSI
10626 **/
10627static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
10628{
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010629 struct i40e_pf *pf = veb->pf;
Shannon Nelson66fc3602016-01-13 16:51:42 -080010630 bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010631 int ret;
10632
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010633 ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
Mitch Williams5bc16032016-05-16 10:26:43 -070010634 veb->enabled_tc, false,
Shannon Nelson66fc3602016-01-13 16:51:42 -080010635 &veb->seid, enable_stats, NULL);
Mitch Williams5bc16032016-05-16 10:26:43 -070010636
10637 /* get a VEB from the hardware */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010638 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010639 dev_info(&pf->pdev->dev,
10640 "couldn't add VEB, err %s aq_err %s\n",
10641 i40e_stat_str(&pf->hw, ret),
10642 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010643 return -EPERM;
10644 }
10645
10646 /* get statistics counter */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010647 ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010648 &veb->stats_idx, NULL, NULL, NULL);
10649 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010650 dev_info(&pf->pdev->dev,
10651 "couldn't get VEB statistics idx, err %s aq_err %s\n",
10652 i40e_stat_str(&pf->hw, ret),
10653 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010654 return -EPERM;
10655 }
10656 ret = i40e_veb_get_bw_info(veb);
10657 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010658 dev_info(&pf->pdev->dev,
10659 "couldn't get VEB bw info, err %s aq_err %s\n",
10660 i40e_stat_str(&pf->hw, ret),
10661 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10662 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010663 return -ENOENT;
10664 }
10665
10666 vsi->uplink_seid = veb->seid;
10667 vsi->veb_idx = veb->idx;
10668 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
10669
10670 return 0;
10671}
10672
10673/**
10674 * i40e_veb_setup - Set up a VEB
10675 * @pf: board private structure
10676 * @flags: VEB setup flags
10677 * @uplink_seid: the switch element to link to
10678 * @vsi_seid: the initial VSI seid
10679 * @enabled_tc: Enabled TC bit-map
10680 *
10681 * This allocates the sw VEB structure and links it into the switch
10682 * It is possible and legal for this to be a duplicate of an already
10683 * existing VEB. It is also possible for both uplink and vsi seids
10684 * to be zero, in order to create a floating VEB.
10685 *
10686 * Returns pointer to the successfully allocated VEB sw struct on
10687 * success, otherwise returns NULL on failure.
10688 **/
10689struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
10690 u16 uplink_seid, u16 vsi_seid,
10691 u8 enabled_tc)
10692{
10693 struct i40e_veb *veb, *uplink_veb = NULL;
10694 int vsi_idx, veb_idx;
10695 int ret;
10696
10697 /* if one seid is 0, the other must be 0 to create a floating relay */
10698 if ((uplink_seid == 0 || vsi_seid == 0) &&
10699 (uplink_seid + vsi_seid != 0)) {
10700 dev_info(&pf->pdev->dev,
10701 "one, not both seid's are 0: uplink=%d vsi=%d\n",
10702 uplink_seid, vsi_seid);
10703 return NULL;
10704 }
10705
10706 /* make sure there is such a vsi and uplink */
Mitch Williams505682c2014-05-20 08:01:37 +000010707 for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010708 if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
10709 break;
Mitch Williams505682c2014-05-20 08:01:37 +000010710 if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010711 dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
10712 vsi_seid);
10713 return NULL;
10714 }
10715
10716 if (uplink_seid && uplink_seid != pf->mac_seid) {
10717 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
10718 if (pf->veb[veb_idx] &&
10719 pf->veb[veb_idx]->seid == uplink_seid) {
10720 uplink_veb = pf->veb[veb_idx];
10721 break;
10722 }
10723 }
10724 if (!uplink_veb) {
10725 dev_info(&pf->pdev->dev,
10726 "uplink seid %d not found\n", uplink_seid);
10727 return NULL;
10728 }
10729 }
10730
10731 /* get veb sw struct */
10732 veb_idx = i40e_veb_mem_alloc(pf);
10733 if (veb_idx < 0)
10734 goto err_alloc;
10735 veb = pf->veb[veb_idx];
10736 veb->flags = flags;
10737 veb->uplink_seid = uplink_seid;
10738 veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
10739 veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
10740
10741 /* create the VEB in the switch */
10742 ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
10743 if (ret)
10744 goto err_veb;
Shannon Nelson1bb8b932014-04-23 04:49:54 +000010745 if (vsi_idx == pf->lan_vsi)
10746 pf->lan_veb = veb->idx;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010747
10748 return veb;
10749
10750err_veb:
10751 i40e_veb_clear(veb);
10752err_alloc:
10753 return NULL;
10754}
10755
10756/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000010757 * i40e_setup_pf_switch_element - set PF vars based on switch type
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010758 * @pf: board private structure
10759 * @ele: element we are building info from
10760 * @num_reported: total number of elements
10761 * @printconfig: should we print the contents
10762 *
10763 * helper function to assist in extracting a few useful SEID values.
10764 **/
10765static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
10766 struct i40e_aqc_switch_config_element_resp *ele,
10767 u16 num_reported, bool printconfig)
10768{
10769 u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
10770 u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
10771 u8 element_type = ele->element_type;
10772 u16 seid = le16_to_cpu(ele->seid);
10773
10774 if (printconfig)
10775 dev_info(&pf->pdev->dev,
10776 "type=%d seid=%d uplink=%d downlink=%d\n",
10777 element_type, seid, uplink_seid, downlink_seid);
10778
10779 switch (element_type) {
10780 case I40E_SWITCH_ELEMENT_TYPE_MAC:
10781 pf->mac_seid = seid;
10782 break;
10783 case I40E_SWITCH_ELEMENT_TYPE_VEB:
10784 /* Main VEB? */
10785 if (uplink_seid != pf->mac_seid)
10786 break;
10787 if (pf->lan_veb == I40E_NO_VEB) {
10788 int v;
10789
10790 /* find existing or else empty VEB */
10791 for (v = 0; v < I40E_MAX_VEB; v++) {
10792 if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
10793 pf->lan_veb = v;
10794 break;
10795 }
10796 }
10797 if (pf->lan_veb == I40E_NO_VEB) {
10798 v = i40e_veb_mem_alloc(pf);
10799 if (v < 0)
10800 break;
10801 pf->lan_veb = v;
10802 }
10803 }
10804
10805 pf->veb[pf->lan_veb]->seid = seid;
10806 pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
10807 pf->veb[pf->lan_veb]->pf = pf;
10808 pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
10809 break;
10810 case I40E_SWITCH_ELEMENT_TYPE_VSI:
10811 if (num_reported != 1)
10812 break;
10813 /* This is immediately after a reset so we can assume this is
10814 * the PF's VSI
10815 */
10816 pf->mac_seid = uplink_seid;
10817 pf->pf_seid = downlink_seid;
10818 pf->main_vsi_seid = seid;
10819 if (printconfig)
10820 dev_info(&pf->pdev->dev,
10821 "pf_seid=%d main_vsi_seid=%d\n",
10822 pf->pf_seid, pf->main_vsi_seid);
10823 break;
10824 case I40E_SWITCH_ELEMENT_TYPE_PF:
10825 case I40E_SWITCH_ELEMENT_TYPE_VF:
10826 case I40E_SWITCH_ELEMENT_TYPE_EMP:
10827 case I40E_SWITCH_ELEMENT_TYPE_BMC:
10828 case I40E_SWITCH_ELEMENT_TYPE_PE:
10829 case I40E_SWITCH_ELEMENT_TYPE_PA:
10830 /* ignore these for now */
10831 break;
10832 default:
10833 dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
10834 element_type, seid);
10835 break;
10836 }
10837}
10838
10839/**
10840 * i40e_fetch_switch_configuration - Get switch config from firmware
10841 * @pf: board private structure
10842 * @printconfig: should we print the contents
10843 *
10844 * Get the current switch configuration from the device and
10845 * extract a few useful SEID values.
10846 **/
10847int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
10848{
10849 struct i40e_aqc_get_switch_config_resp *sw_config;
10850 u16 next_seid = 0;
10851 int ret = 0;
10852 u8 *aq_buf;
10853 int i;
10854
10855 aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
10856 if (!aq_buf)
10857 return -ENOMEM;
10858
10859 sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
10860 do {
10861 u16 num_reported, num_total;
10862
10863 ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
10864 I40E_AQ_LARGE_BUF,
10865 &next_seid, NULL);
10866 if (ret) {
10867 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010868 "get switch config failed err %s aq_err %s\n",
10869 i40e_stat_str(&pf->hw, ret),
10870 i40e_aq_str(&pf->hw,
10871 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010872 kfree(aq_buf);
10873 return -ENOENT;
10874 }
10875
10876 num_reported = le16_to_cpu(sw_config->header.num_reported);
10877 num_total = le16_to_cpu(sw_config->header.num_total);
10878
10879 if (printconfig)
10880 dev_info(&pf->pdev->dev,
10881 "header: %d reported %d total\n",
10882 num_reported, num_total);
10883
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010884 for (i = 0; i < num_reported; i++) {
10885 struct i40e_aqc_switch_config_element_resp *ele =
10886 &sw_config->element[i];
10887
10888 i40e_setup_pf_switch_element(pf, ele, num_reported,
10889 printconfig);
10890 }
10891 } while (next_seid != 0);
10892
10893 kfree(aq_buf);
10894 return ret;
10895}
10896
10897/**
10898 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
10899 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010900 * @reinit: if the Main VSI needs to re-initialized.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010901 *
10902 * Returns 0 on success, negative value on failure
10903 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010904static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010905{
Anjali Singhai Jainb5569892016-05-03 15:13:12 -070010906 u16 flags = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010907 int ret;
10908
10909 /* find out what's out there already */
10910 ret = i40e_fetch_switch_configuration(pf, false);
10911 if (ret) {
10912 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010913 "couldn't fetch switch config, err %s aq_err %s\n",
10914 i40e_stat_str(&pf->hw, ret),
10915 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010916 return ret;
10917 }
10918 i40e_pf_reset_stats(pf);
10919
Anjali Singhai Jainb5569892016-05-03 15:13:12 -070010920 /* set the switch config bit for the whole device to
10921 * support limited promisc or true promisc
10922 * when user requests promisc. The default is limited
10923 * promisc.
10924 */
10925
10926 if ((pf->hw.pf_id == 0) &&
10927 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
10928 flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
10929
10930 if (pf->hw.pf_id == 0) {
10931 u16 valid_flags;
10932
10933 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
10934 ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags,
10935 NULL);
10936 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
10937 dev_info(&pf->pdev->dev,
10938 "couldn't set switch config bits, err %s aq_err %s\n",
10939 i40e_stat_str(&pf->hw, ret),
10940 i40e_aq_str(&pf->hw,
10941 pf->hw.aq.asq_last_status));
10942 /* not a fatal problem, just keep going */
10943 }
10944 }
10945
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010946 /* first time setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010947 if (pf->lan_vsi == I40E_NO_VSI || reinit) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010948 struct i40e_vsi *vsi = NULL;
10949 u16 uplink_seid;
10950
10951 /* Set up the PF VSI associated with the PF's main VSI
10952 * that is already in the HW switch
10953 */
10954 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
10955 uplink_seid = pf->veb[pf->lan_veb]->seid;
10956 else
10957 uplink_seid = pf->mac_seid;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010958 if (pf->lan_vsi == I40E_NO_VSI)
10959 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
10960 else if (reinit)
10961 vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010962 if (!vsi) {
10963 dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
10964 i40e_fdir_teardown(pf);
10965 return -EAGAIN;
10966 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010967 } else {
10968 /* force a reset of TC and queue layout configurations */
10969 u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -040010970
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010971 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
10972 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
10973 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
10974 }
10975 i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
10976
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010977 i40e_fdir_sb_setup(pf);
10978
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010979 /* Setup static PF queue filter control settings */
10980 ret = i40e_setup_pf_filter_control(pf);
10981 if (ret) {
10982 dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
10983 ret);
10984 /* Failure here should not stop continuing other steps */
10985 }
10986
10987 /* enable RSS in the HW, even for only one queue, as the stack can use
10988 * the hash
10989 */
10990 if ((pf->flags & I40E_FLAG_RSS_ENABLED))
Helin Zhang043dd652015-10-21 19:56:23 -040010991 i40e_pf_config_rss(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010992
10993 /* fill in link information and enable LSE reporting */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010994 i40e_link_event(pf);
10995
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000010996 /* Initialize user-specific link properties */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010997 pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
10998 I40E_AQ_AN_COMPLETED) ? true : false);
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000010999
Jacob Kellerbeb0dff2014-01-11 05:43:19 +000011000 i40e_ptp_init(pf);
11001
Alexander Duyck1f190d92017-04-19 09:25:51 -040011002 /* repopulate tunnel port filters */
11003 i40e_sync_udp_filters(pf);
11004
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011005 return ret;
11006}
11007
11008/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011009 * i40e_determine_queue_usage - Work out queue distribution
11010 * @pf: board private structure
11011 **/
11012static void i40e_determine_queue_usage(struct i40e_pf *pf)
11013{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011014 int queues_left;
11015
11016 pf->num_lan_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011017
11018 /* Find the max queues to be put into basic use. We'll always be
11019 * using TC0, whether or not DCB is running, and TC0 will get the
11020 * big RSS set.
11021 */
11022 queues_left = pf->hw.func_caps.num_tx_qp;
11023
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080011024 if ((queues_left == 1) ||
Frank Zhang9aa7e932014-05-20 08:01:42 +000011025 !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011026 /* one qp for PF, no queues for anything else */
11027 queues_left = 0;
Helin Zhangacd65442015-10-26 19:44:28 -040011028 pf->alloc_rss_size = pf->num_lan_qps = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011029
11030 /* make sure all the fancies are disabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080011031 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011032 I40E_FLAG_IWARP_ENABLED |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080011033 I40E_FLAG_FD_SB_ENABLED |
11034 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +000011035 I40E_FLAG_DCB_CAPABLE |
Dave Ertmana0362442016-08-29 17:38:26 -070011036 I40E_FLAG_DCB_ENABLED |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080011037 I40E_FLAG_SRIOV_ENABLED |
11038 I40E_FLAG_VMDQ_ENABLED);
Frank Zhang9aa7e932014-05-20 08:01:42 +000011039 } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
11040 I40E_FLAG_FD_SB_ENABLED |
Anjali Singhai Jainbbe7d0e2014-05-20 08:01:44 +000011041 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +000011042 I40E_FLAG_DCB_CAPABLE))) {
Frank Zhang9aa7e932014-05-20 08:01:42 +000011043 /* one qp for PF */
Helin Zhangacd65442015-10-26 19:44:28 -040011044 pf->alloc_rss_size = pf->num_lan_qps = 1;
Frank Zhang9aa7e932014-05-20 08:01:42 +000011045 queues_left -= pf->num_lan_qps;
11046
11047 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011048 I40E_FLAG_IWARP_ENABLED |
Frank Zhang9aa7e932014-05-20 08:01:42 +000011049 I40E_FLAG_FD_SB_ENABLED |
11050 I40E_FLAG_FD_ATR_ENABLED |
11051 I40E_FLAG_DCB_ENABLED |
11052 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011053 } else {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080011054 /* Not enough queues for all TCs */
Neerav Parikh4d9b6042014-05-22 06:31:51 +000011055 if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080011056 (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
Dave Ertmana0362442016-08-29 17:38:26 -070011057 pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
11058 I40E_FLAG_DCB_ENABLED);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080011059 dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
11060 }
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +000011061 pf->num_lan_qps = max_t(int, pf->rss_size_max,
11062 num_online_cpus());
11063 pf->num_lan_qps = min_t(int, pf->num_lan_qps,
11064 pf->hw.func_caps.num_tx_qp);
11065
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080011066 queues_left -= pf->num_lan_qps;
11067 }
11068
11069 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
11070 if (queues_left > 1) {
11071 queues_left -= 1; /* save 1 queue for FD */
11072 } else {
11073 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
11074 dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
11075 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011076 }
11077
11078 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
11079 pf->num_vf_qps && pf->num_req_vfs && queues_left) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080011080 pf->num_req_vfs = min_t(int, pf->num_req_vfs,
11081 (queues_left / pf->num_vf_qps));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011082 queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
11083 }
11084
11085 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
11086 pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
11087 pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
11088 (queues_left / pf->num_vmdq_qps));
11089 queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
11090 }
11091
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +000011092 pf->queues_left = queues_left;
Neerav Parikh8279e492015-09-03 17:18:50 -040011093 dev_dbg(&pf->pdev->dev,
11094 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
11095 pf->hw.func_caps.num_tx_qp,
11096 !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
Helin Zhangacd65442015-10-26 19:44:28 -040011097 pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
11098 pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
11099 queues_left);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011100}
11101
11102/**
11103 * i40e_setup_pf_filter_control - Setup PF static filter control
11104 * @pf: PF to be setup
11105 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000011106 * i40e_setup_pf_filter_control sets up a PF's initial filter control
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011107 * settings. If PE/FCoE are enabled then it will also set the per PF
11108 * based filter sizes required for them. It also enables Flow director,
11109 * ethertype and macvlan type filter settings for the pf.
11110 *
11111 * Returns 0 on success, negative on failure
11112 **/
11113static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
11114{
11115 struct i40e_filter_control_settings *settings = &pf->filter_settings;
11116
11117 settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
11118
11119 /* Flow Director is enabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080011120 if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011121 settings->enable_fdir = true;
11122
11123 /* Ethtype and MACVLAN filters enabled for PF */
11124 settings->enable_ethtype = true;
11125 settings->enable_macvlan = true;
11126
11127 if (i40e_set_filter_control(&pf->hw, settings))
11128 return -ENOENT;
11129
11130 return 0;
11131}
11132
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011133#define INFO_STRING_LEN 255
Shannon Nelson7fd89542015-10-21 19:47:04 -040011134#define REMAIN(__x) (INFO_STRING_LEN - (__x))
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011135static void i40e_print_features(struct i40e_pf *pf)
11136{
11137 struct i40e_hw *hw = &pf->hw;
Joe Perches3b195842015-12-03 04:20:57 -080011138 char *buf;
11139 int i;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011140
Joe Perches3b195842015-12-03 04:20:57 -080011141 buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
11142 if (!buf)
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011143 return;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011144
Joe Perches3b195842015-12-03 04:20:57 -080011145 i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011146#ifdef CONFIG_PCI_IOV
Joe Perches3b195842015-12-03 04:20:57 -080011147 i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011148#endif
Jesse Brandeburg1a557afc2016-04-20 19:43:37 -070011149 i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
Shannon Nelson7fd89542015-10-21 19:47:04 -040011150 pf->hw.func_caps.num_vsis,
Jesse Brandeburg1a557afc2016-04-20 19:43:37 -070011151 pf->vsi[pf->lan_vsi]->num_queue_pairs);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011152 if (pf->flags & I40E_FLAG_RSS_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080011153 i += snprintf(&buf[i], REMAIN(i), " RSS");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011154 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080011155 i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +000011156 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
Joe Perches3b195842015-12-03 04:20:57 -080011157 i += snprintf(&buf[i], REMAIN(i), " FD_SB");
11158 i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +000011159 }
Neerav Parikh4d9b6042014-05-22 06:31:51 +000011160 if (pf->flags & I40E_FLAG_DCB_CAPABLE)
Joe Perches3b195842015-12-03 04:20:57 -080011161 i += snprintf(&buf[i], REMAIN(i), " DCB");
Joe Perches3b195842015-12-03 04:20:57 -080011162 i += snprintf(&buf[i], REMAIN(i), " VxLAN");
Singhai, Anjali6a899022015-12-14 12:21:18 -080011163 i += snprintf(&buf[i], REMAIN(i), " Geneve");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011164 if (pf->flags & I40E_FLAG_PTP)
Joe Perches3b195842015-12-03 04:20:57 -080011165 i += snprintf(&buf[i], REMAIN(i), " PTP");
Shannon Nelson6dec1012015-09-28 14:12:30 -040011166 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080011167 i += snprintf(&buf[i], REMAIN(i), " VEB");
Shannon Nelson6dec1012015-09-28 14:12:30 -040011168 else
Joe Perches3b195842015-12-03 04:20:57 -080011169 i += snprintf(&buf[i], REMAIN(i), " VEPA");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011170
Joe Perches3b195842015-12-03 04:20:57 -080011171 dev_info(&pf->pdev->dev, "%s\n", buf);
11172 kfree(buf);
Shannon Nelson7fd89542015-10-21 19:47:04 -040011173 WARN_ON(i > INFO_STRING_LEN);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011174}
11175
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011176/**
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050011177 * i40e_get_platform_mac_addr - get platform-specific MAC address
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050011178 * @pdev: PCI device information struct
11179 * @pf: board private structure
11180 *
Jacob Keller41c4c2b2017-04-05 07:50:57 -040011181 * Look up the MAC address for the device. First we'll try
11182 * eth_platform_get_mac_address, which will check Open Firmware, or arch
11183 * specific fallback. Otherwise, we'll default to the stored value in
11184 * firmware.
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050011185 **/
11186static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
11187{
Jacob Keller41c4c2b2017-04-05 07:50:57 -040011188 if (eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
11189 i40e_get_mac_addr(&pf->hw, pf->hw.mac.addr);
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050011190}
11191
11192/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011193 * i40e_probe - Device initialization routine
11194 * @pdev: PCI device information struct
11195 * @ent: entry in i40e_pci_tbl
11196 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000011197 * i40e_probe initializes a PF identified by a pci_dev structure.
11198 * The OS initialization, configuring of the PF private structure,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011199 * and a hardware reset occur.
11200 *
11201 * Returns 0 on success, negative on failure
11202 **/
11203static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
11204{
Catherine Sullivane8278452015-02-06 08:52:08 +000011205 struct i40e_aq_get_phy_abilities_resp abilities;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011206 struct i40e_pf *pf;
11207 struct i40e_hw *hw;
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000011208 static u16 pfs_found;
Shannon Nelson1d5109d2015-08-26 15:14:08 -040011209 u16 wol_nvm_bits;
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011210 u16 link_status;
Jean Sacren6f66a482015-09-19 05:08:45 -060011211 int err;
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -040011212 u32 val;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000011213 u32 i;
Helin Zhang58fc3262015-10-01 14:37:38 -040011214 u8 set_fc_aq_fail;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011215
11216 err = pci_enable_device_mem(pdev);
11217 if (err)
11218 return err;
11219
11220 /* set up for high or low dma */
Mitch Williams64942942014-02-11 08:26:33 +000011221 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +000011222 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +000011223 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
11224 if (err) {
11225 dev_err(&pdev->dev,
11226 "DMA configuration failed: 0x%x\n", err);
11227 goto err_dma;
11228 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011229 }
11230
11231 /* set up pci connections */
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020011232 err = pci_request_mem_regions(pdev, i40e_driver_name);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011233 if (err) {
11234 dev_info(&pdev->dev,
11235 "pci_request_selected_regions failed %d\n", err);
11236 goto err_pci_reg;
11237 }
11238
11239 pci_enable_pcie_error_reporting(pdev);
11240 pci_set_master(pdev);
11241
11242 /* Now that we have a PCI connection, we need to do the
11243 * low level device setup. This is primarily setting up
11244 * the Admin Queue structures and then querying for the
11245 * device's current profile information.
11246 */
11247 pf = kzalloc(sizeof(*pf), GFP_KERNEL);
11248 if (!pf) {
11249 err = -ENOMEM;
11250 goto err_pf_alloc;
11251 }
11252 pf->next_vsi = 0;
11253 pf->pdev = pdev;
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030011254 set_bit(__I40E_DOWN, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011255
11256 hw = &pf->hw;
11257 hw->back = pf;
Anjali Singhai232f4702015-02-26 16:15:39 +000011258
Shannon Nelson2ac8b672015-07-23 16:54:37 -040011259 pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
11260 I40E_MAX_CSR_SPACE);
Anjali Singhai232f4702015-02-26 16:15:39 +000011261
Shannon Nelson2ac8b672015-07-23 16:54:37 -040011262 hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011263 if (!hw->hw_addr) {
11264 err = -EIO;
11265 dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
11266 (unsigned int)pci_resource_start(pdev, 0),
Shannon Nelson2ac8b672015-07-23 16:54:37 -040011267 pf->ioremap_len, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011268 goto err_ioremap;
11269 }
11270 hw->vendor_id = pdev->vendor;
11271 hw->device_id = pdev->device;
11272 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
11273 hw->subsystem_vendor_id = pdev->subsystem_vendor;
11274 hw->subsystem_device_id = pdev->subsystem_device;
11275 hw->bus.device = PCI_SLOT(pdev->devfn);
11276 hw->bus.func = PCI_FUNC(pdev->devfn);
Sudheer Mogilappagarib3f028f2017-02-09 23:58:22 -080011277 hw->bus.bus_id = pdev->bus->number;
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000011278 pf->instance = pfs_found;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011279
Jacob Keller0e588de2017-02-06 14:38:50 -080011280 INIT_LIST_HEAD(&pf->l3_flex_pit_list);
11281 INIT_LIST_HEAD(&pf->l4_flex_pit_list);
11282
Shannon Nelsonde03d2b2016-03-10 14:59:44 -080011283 /* set up the locks for the AQ, do this only once in probe
11284 * and destroy them only once in remove
11285 */
11286 mutex_init(&hw->aq.asq_mutex);
11287 mutex_init(&hw->aq.arq_mutex);
11288
Alexander Duyck5d4ca232016-09-30 08:21:46 -040011289 pf->msg_enable = netif_msg_init(debug,
11290 NETIF_MSG_DRV |
11291 NETIF_MSG_PROBE |
11292 NETIF_MSG_LINK);
11293 if (debug < -1)
11294 pf->hw.debug_mask = debug;
Shannon Nelson5b5faa42014-10-17 03:14:51 +000011295
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +000011296 /* do a special CORER for clearing PXE mode once at init */
11297 if (hw->revision_id == 0 &&
11298 (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
11299 wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
11300 i40e_flush(hw);
11301 msleep(200);
11302 pf->corer_count++;
11303
11304 i40e_clear_pxe_mode(hw);
11305 }
11306
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011307 /* Reset here to make sure all is clean and to define PF 'n' */
Shannon Nelson838d41d2014-06-04 20:41:27 +000011308 i40e_clear_hw(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011309 err = i40e_pf_reset(hw);
11310 if (err) {
11311 dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
11312 goto err_pf_reset;
11313 }
11314 pf->pfr_count++;
11315
11316 hw->aq.num_arq_entries = I40E_AQ_LEN;
11317 hw->aq.num_asq_entries = I40E_AQ_LEN;
11318 hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
11319 hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
11320 pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +000011321
Carolyn Wybornyb294ac72014-12-11 07:06:39 +000011322 snprintf(pf->int_name, sizeof(pf->int_name) - 1,
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +000011323 "%s-%s:misc",
11324 dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011325
11326 err = i40e_init_shared_code(hw);
11327 if (err) {
Anjali Singhai Jainb2a75c52015-04-27 14:57:20 -040011328 dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
11329 err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011330 goto err_pf_reset;
11331 }
11332
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000011333 /* set up a default setting for link flow control */
11334 pf->hw.fc.requested_mode = I40E_FC_NONE;
11335
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011336 err = i40e_init_adminq(hw);
Carolyn Wyborny2b2426a762015-10-26 19:44:35 -040011337 if (err) {
11338 if (err == I40E_ERR_FIRMWARE_API_VERSION)
11339 dev_info(&pdev->dev,
11340 "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");
11341 else
11342 dev_info(&pdev->dev,
11343 "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
11344
11345 goto err_pf_reset;
11346 }
Filip Sadowski5bbb2e22017-06-07 05:43:09 -040011347 i40e_get_oem_version(hw);
Carolyn Wybornyf0b44442015-08-31 19:54:49 -040011348
Shannon Nelson6dec1012015-09-28 14:12:30 -040011349 /* provide nvm, fw, api versions */
11350 dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
11351 hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
11352 hw->aq.api_maj_ver, hw->aq.api_min_ver,
11353 i40e_nvm_version_str(hw));
Carolyn Wybornyf0b44442015-08-31 19:54:49 -040011354
Catherine Sullivan7aa67612014-07-09 07:46:17 +000011355 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
11356 hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
Shannon Nelson278b6f62014-06-04 01:41:03 +000011357 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000011358 "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");
11359 else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
11360 hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
Shannon Nelson278b6f62014-06-04 01:41:03 +000011361 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000011362 "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 +000011363
Shannon Nelson4eb3f762014-03-06 08:59:58 +000011364 i40e_verify_eeprom(pf);
11365
Jesse Brandeburg2c5fe332014-04-23 04:49:57 +000011366 /* Rev 0 hardware was never productized */
11367 if (hw->revision_id < 1)
11368 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");
11369
Shannon Nelson6ff4ef82013-12-21 05:44:49 +000011370 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011371 err = i40e_get_capabilities(pf);
11372 if (err)
11373 goto err_adminq_setup;
11374
11375 err = i40e_sw_init(pf);
11376 if (err) {
11377 dev_info(&pdev->dev, "sw_init failed: %d\n", err);
11378 goto err_sw_init;
11379 }
11380
11381 err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
Alexander Duyckc76cb6e2017-02-21 15:55:48 -080011382 hw->func_caps.num_rx_qp, 0, 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011383 if (err) {
11384 dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
11385 goto err_init_lan_hmc;
11386 }
11387
11388 err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
11389 if (err) {
11390 dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
11391 err = -ENOENT;
11392 goto err_configure_lan_hmc;
11393 }
11394
Neerav Parikhb686ece2014-12-14 01:55:11 +000011395 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
11396 * Ignore error return codes because if it was already disabled via
11397 * hardware settings this will fail
11398 */
Jacob Kellerd36e41d2017-06-23 04:24:46 -040011399 if (pf->hw_features & I40E_HW_STOP_FW_LLDP) {
Neerav Parikhb686ece2014-12-14 01:55:11 +000011400 dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
11401 i40e_aq_stop_lldp(hw, true, NULL);
11402 }
11403
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050011404 /* allow a platform config to override the HW addr */
11405 i40e_get_platform_mac_addr(pdev, pf);
Jacob Keller41c4c2b2017-04-05 07:50:57 -040011406
Jesse Brandeburgf62b5062013-11-28 06:39:27 +000011407 if (!is_valid_ether_addr(hw->mac.addr)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011408 dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
11409 err = -EIO;
11410 goto err_mac_addr;
11411 }
11412 dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
Greg Rose9a173902014-05-22 06:32:02 +000011413 ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
Neerav Parikh1f224ad2014-02-12 01:45:31 +000011414 i40e_get_port_mac_addr(hw, hw->mac.port_addr);
11415 if (is_valid_ether_addr(hw->mac.port_addr))
Jacob Kellerd36e41d2017-06-23 04:24:46 -040011416 pf->hw_features |= I40E_HW_PORT_ID_VALID;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011417
11418 pci_set_drvdata(pdev, pf);
11419 pci_save_state(pdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080011420#ifdef CONFIG_I40E_DCB
11421 err = i40e_init_pf_dcb(pf);
11422 if (err) {
Shannon Nelsonaebfc812014-12-11 07:06:38 +000011423 dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
David Ertmanc17ef432016-09-30 01:36:21 -070011424 pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED);
Neerav Parikh014269f2014-04-01 07:11:48 +000011425 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080011426 }
11427#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011428
11429 /* set up periodic task facility */
11430 setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
11431 pf->service_timer_period = HZ;
11432
11433 INIT_WORK(&pf->service_task, i40e_service_task);
Jacob Keller0da36b92017-04-19 09:25:55 -040011434 clear_bit(__I40E_SERVICE_SCHED, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011435
Shannon Nelson1d5109d2015-08-26 15:14:08 -040011436 /* NVM bit on means WoL disabled for the port */
11437 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -080011438 if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
Shannon Nelson1d5109d2015-08-26 15:14:08 -040011439 pf->wol_en = false;
11440 else
11441 pf->wol_en = true;
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011442 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
11443
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011444 /* set up the main switch operations */
11445 i40e_determine_queue_usage(pf);
Jesse Brandeburgc11472802015-04-07 19:45:39 -040011446 err = i40e_init_interrupt_scheme(pf);
11447 if (err)
11448 goto err_switch_setup;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011449
Mitch Williams505682c2014-05-20 08:01:37 +000011450 /* The number of VSIs reported by the FW is the minimum guaranteed
11451 * to us; HW supports far more and we share the remaining pool with
11452 * the other PFs. We allocate space for more than the guarantee with
11453 * the understanding that we might not get them all later.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011454 */
Mitch Williams505682c2014-05-20 08:01:37 +000011455 if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
11456 pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
11457 else
11458 pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
11459
11460 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
Jesse Brandeburgd17038d2015-12-23 12:05:55 -080011461 pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
11462 GFP_KERNEL);
Wei Yongjuned87ac02013-09-24 05:17:25 +000011463 if (!pf->vsi) {
11464 err = -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011465 goto err_switch_setup;
Wei Yongjuned87ac02013-09-24 05:17:25 +000011466 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011467
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -040011468#ifdef CONFIG_PCI_IOV
11469 /* prep for VF support */
11470 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
11471 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
Jacob Keller0da36b92017-04-19 09:25:55 -040011472 !test_bit(__I40E_BAD_EEPROM, pf->state)) {
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -040011473 if (pci_num_vf(pdev))
11474 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
11475 }
11476#endif
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000011477 err = i40e_setup_pf_switch(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011478 if (err) {
11479 dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
11480 goto err_vsis;
11481 }
Helin Zhang58fc3262015-10-01 14:37:38 -040011482
11483 /* Make sure flow control is set according to current settings */
11484 err = i40e_set_fc(hw, &set_fc_aq_fail, true);
11485 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
11486 dev_dbg(&pf->pdev->dev,
11487 "Set fc with err %s aq_err %s on get_phy_cap\n",
11488 i40e_stat_str(hw, err),
11489 i40e_aq_str(hw, hw->aq.asq_last_status));
11490 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
11491 dev_dbg(&pf->pdev->dev,
11492 "Set fc with err %s aq_err %s on set_phy_config\n",
11493 i40e_stat_str(hw, err),
11494 i40e_aq_str(hw, hw->aq.asq_last_status));
11495 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
11496 dev_dbg(&pf->pdev->dev,
11497 "Set fc with err %s aq_err %s on get_link_info\n",
11498 i40e_stat_str(hw, err),
11499 i40e_aq_str(hw, hw->aq.asq_last_status));
11500
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000011501 /* if FDIR VSI was set up, start it now */
Mitch Williams505682c2014-05-20 08:01:37 +000011502 for (i = 0; i < pf->num_alloc_vsi; i++) {
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000011503 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
11504 i40e_vsi_open(pf->vsi[i]);
11505 break;
11506 }
11507 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011508
Shannon Nelson2f0aff42016-01-04 10:33:08 -080011509 /* The driver only wants link up/down and module qualification
11510 * reports from firmware. Note the negative logic.
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000011511 */
11512 err = i40e_aq_set_phy_int_mask(&pf->hw,
Shannon Nelson2f0aff42016-01-04 10:33:08 -080011513 ~(I40E_AQ_EVENT_LINK_UPDOWN |
Shannon Nelson867a79e2016-03-18 12:18:15 -070011514 I40E_AQ_EVENT_MEDIA_NA |
Shannon Nelson2f0aff42016-01-04 10:33:08 -080011515 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000011516 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040011517 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
11518 i40e_stat_str(&pf->hw, err),
11519 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000011520
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -040011521 /* Reconfigure hardware for allowing smaller MSS in the case
11522 * of TSO, so that we avoid the MDD being fired and causing
11523 * a reset in the case of small MSS+TSO.
11524 */
11525 val = rd32(hw, I40E_REG_MSS);
11526 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
11527 val &= ~I40E_REG_MSS_MIN_MASK;
11528 val |= I40E_64BYTE_MSS;
11529 wr32(hw, I40E_REG_MSS, val);
11530 }
11531
Jacob Kellerd36e41d2017-06-23 04:24:46 -040011532 if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +000011533 msleep(75);
11534 err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
11535 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040011536 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
11537 i40e_stat_str(&pf->hw, err),
11538 i40e_aq_str(&pf->hw,
11539 pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +000011540 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011541 /* The main driver is (mostly) up and happy. We need to set this state
11542 * before setting up the misc vector or we get a race and the vector
11543 * ends up disabled forever.
11544 */
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030011545 clear_bit(__I40E_DOWN, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011546
11547 /* In case of MSIX we are going to setup the misc vector right here
11548 * to handle admin queue events etc. In case of legacy and MSI
11549 * the misc functionality and queue processing is combined in
11550 * the same vector and that gets setup at open.
11551 */
11552 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
11553 err = i40e_setup_misc_vector(pf);
11554 if (err) {
11555 dev_info(&pdev->dev,
11556 "setup of misc vector failed: %d\n", err);
11557 goto err_vsis;
11558 }
11559 }
11560
Greg Rosedf805f62014-04-04 04:43:16 +000011561#ifdef CONFIG_PCI_IOV
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011562 /* prep for VF support */
11563 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
Shannon Nelson4eb3f762014-03-06 08:59:58 +000011564 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
Jacob Keller0da36b92017-04-19 09:25:55 -040011565 !test_bit(__I40E_BAD_EEPROM, pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011566 /* disable link interrupts for VFs */
11567 val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
11568 val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
11569 wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
11570 i40e_flush(hw);
Mitch Williams4aeec012014-02-13 03:48:47 -080011571
11572 if (pci_num_vf(pdev)) {
11573 dev_info(&pdev->dev,
11574 "Active VFs found, allocating resources.\n");
11575 err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
11576 if (err)
11577 dev_info(&pdev->dev,
11578 "Error %d allocating resources for existing VFs\n",
11579 err);
11580 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011581 }
Greg Rosedf805f62014-04-04 04:43:16 +000011582#endif /* CONFIG_PCI_IOV */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011583
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011584 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11585 pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
11586 pf->num_iwarp_msix,
11587 I40E_IWARP_IRQ_PILE_ID);
11588 if (pf->iwarp_base_vector < 0) {
11589 dev_info(&pdev->dev,
11590 "failed to get tracking for %d vectors for IWARP err=%d\n",
11591 pf->num_iwarp_msix, pf->iwarp_base_vector);
11592 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
11593 }
11594 }
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000011595
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011596 i40e_dbg_pf_init(pf);
11597
11598 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +000011599 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011600
11601 /* since everything's happy, start the service_task timer */
11602 mod_timer(&pf->service_timer,
11603 round_jiffies(jiffies + pf->service_timer_period));
11604
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011605 /* add this PF to client device list and launch a client service task */
Mitch Williams004eb612017-04-04 12:40:16 -070011606 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11607 err = i40e_lan_add_device(pf);
11608 if (err)
11609 dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
11610 err);
11611 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011612
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011613#define PCI_SPEED_SIZE 8
11614#define PCI_WIDTH_SIZE 8
11615 /* Devices on the IOSF bus do not have this information
11616 * and will report PCI Gen 1 x 1 by default so don't bother
11617 * checking them.
11618 */
Jacob Kellerd36e41d2017-06-23 04:24:46 -040011619 if (!(pf->hw_features & I40E_HW_NO_PCI_LINK_CHECK)) {
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011620 char speed[PCI_SPEED_SIZE] = "Unknown";
11621 char width[PCI_WIDTH_SIZE] = "Unknown";
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011622
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011623 /* Get the negotiated link width and speed from PCI config
11624 * space
11625 */
11626 pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
11627 &link_status);
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011628
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011629 i40e_set_pci_config_data(hw, link_status);
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011630
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011631 switch (hw->bus.speed) {
11632 case i40e_bus_speed_8000:
11633 strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
11634 case i40e_bus_speed_5000:
11635 strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
11636 case i40e_bus_speed_2500:
11637 strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
11638 default:
11639 break;
11640 }
11641 switch (hw->bus.width) {
11642 case i40e_bus_width_pcie_x8:
11643 strncpy(width, "8", PCI_WIDTH_SIZE); break;
11644 case i40e_bus_width_pcie_x4:
11645 strncpy(width, "4", PCI_WIDTH_SIZE); break;
11646 case i40e_bus_width_pcie_x2:
11647 strncpy(width, "2", PCI_WIDTH_SIZE); break;
11648 case i40e_bus_width_pcie_x1:
11649 strncpy(width, "1", PCI_WIDTH_SIZE); break;
11650 default:
11651 break;
11652 }
11653
11654 dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
11655 speed, width);
11656
11657 if (hw->bus.width < i40e_bus_width_pcie_x8 ||
11658 hw->bus.speed < i40e_bus_speed_8000) {
11659 dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
11660 dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
11661 }
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011662 }
11663
Catherine Sullivane8278452015-02-06 08:52:08 +000011664 /* get the requested speeds from the fw */
11665 err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
11666 if (err)
Neerav Parikh8279e492015-09-03 17:18:50 -040011667 dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
11668 i40e_stat_str(&pf->hw, err),
11669 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Catherine Sullivane8278452015-02-06 08:52:08 +000011670 pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
11671
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -040011672 /* get the supported phy types from the fw */
11673 err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
11674 if (err)
11675 dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
11676 i40e_stat_str(&pf->hw, err),
11677 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -040011678
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -040011679 /* Add a filter to drop all Flow control frames from any VSI from being
11680 * transmitted. By doing so we stop a malicious VF from sending out
11681 * PAUSE or PFC frames and potentially controlling traffic for other
11682 * PF/VF VSIs.
11683 * The FW can still send Flow control frames if enabled.
11684 */
11685 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
11686 pf->main_vsi_seid);
11687
Carolyn Wyborny31b606d2016-02-17 16:12:12 -080011688 if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
Henry Tieman4f9b4302016-11-08 13:05:18 -080011689 (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
Jacob Kellerd36e41d2017-06-23 04:24:46 -040011690 pf->hw_features |= I40E_HW_PHY_CONTROLS_LEDS;
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -080011691 if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722)
Jacob Kellerd36e41d2017-06-23 04:24:46 -040011692 pf->hw_features |= I40E_HW_HAVE_CRT_RETIMER;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011693 /* print a string summarizing features */
11694 i40e_print_features(pf);
11695
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011696 return 0;
11697
11698 /* Unwind what we've done if something failed in the setup */
11699err_vsis:
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030011700 set_bit(__I40E_DOWN, pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011701 i40e_clear_interrupt_scheme(pf);
11702 kfree(pf->vsi);
Shannon Nelson04b03012013-11-28 06:39:34 +000011703err_switch_setup:
11704 i40e_reset_interrupt_capability(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011705 del_timer_sync(&pf->service_timer);
11706err_mac_addr:
11707err_configure_lan_hmc:
11708 (void)i40e_shutdown_lan_hmc(hw);
11709err_init_lan_hmc:
11710 kfree(pf->qp_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011711err_sw_init:
11712err_adminq_setup:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011713err_pf_reset:
11714 iounmap(hw->hw_addr);
11715err_ioremap:
11716 kfree(pf);
11717err_pf_alloc:
11718 pci_disable_pcie_error_reporting(pdev);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020011719 pci_release_mem_regions(pdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011720err_pci_reg:
11721err_dma:
11722 pci_disable_device(pdev);
11723 return err;
11724}
11725
11726/**
11727 * i40e_remove - Device removal routine
11728 * @pdev: PCI device information struct
11729 *
11730 * i40e_remove is called by the PCI subsystem to alert the driver
11731 * that is should release a PCI device. This could be caused by a
11732 * Hot-Plug event, or because the driver is going to be removed from
11733 * memory.
11734 **/
11735static void i40e_remove(struct pci_dev *pdev)
11736{
11737 struct i40e_pf *pf = pci_get_drvdata(pdev);
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011738 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011739 i40e_status ret_code;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011740 int i;
11741
11742 i40e_dbg_pf_exit(pf);
11743
Jacob Kellerbeb0dff2014-01-11 05:43:19 +000011744 i40e_ptp_stop(pf);
11745
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011746 /* Disable RSS in hw */
Shannon Nelson272cdaf22016-02-17 16:12:21 -080011747 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
11748 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011749
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011750 /* no more scheduling of any task */
Jacob Keller0da36b92017-04-19 09:25:55 -040011751 set_bit(__I40E_SUSPENDED, pf->state);
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030011752 set_bit(__I40E_DOWN, pf->state);
Shannon Nelsonc99abb42016-03-10 14:59:45 -080011753 if (pf->service_timer.data)
11754 del_timer_sync(&pf->service_timer);
11755 if (pf->service_task.func)
11756 cancel_work_sync(&pf->service_task);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011757
Mitch Williams921c4672017-03-30 00:46:08 -070011758 /* Client close must be called explicitly here because the timer
11759 * has been stopped.
11760 */
11761 i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
11762
Mitch Williamseb2d80b2014-02-13 03:48:48 -080011763 if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
11764 i40e_free_vfs(pf);
11765 pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
11766 }
11767
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011768 i40e_fdir_teardown(pf);
11769
11770 /* If there is a switch structure or any orphans, remove them.
11771 * This will leave only the PF's VSI remaining.
11772 */
11773 for (i = 0; i < I40E_MAX_VEB; i++) {
11774 if (!pf->veb[i])
11775 continue;
11776
11777 if (pf->veb[i]->uplink_seid == pf->mac_seid ||
11778 pf->veb[i]->uplink_seid == 0)
11779 i40e_switch_branch_release(pf->veb[i]);
11780 }
11781
11782 /* Now we can shutdown the PF's VSI, just before we kill
11783 * adminq and hmc.
11784 */
11785 if (pf->vsi[pf->lan_vsi])
11786 i40e_vsi_release(pf->vsi[pf->lan_vsi]);
11787
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011788 /* remove attached clients */
Mitch Williams004eb612017-04-04 12:40:16 -070011789 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11790 ret_code = i40e_lan_del_device(pf);
11791 if (ret_code)
11792 dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
11793 ret_code);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011794 }
11795
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011796 /* shutdown and destroy the HMC */
Jesse Brandeburgf734dff2016-01-15 14:33:11 -080011797 if (hw->hmc.hmc_obj) {
11798 ret_code = i40e_shutdown_lan_hmc(hw);
Shannon Nelson60442de2014-04-23 04:50:13 +000011799 if (ret_code)
11800 dev_warn(&pdev->dev,
11801 "Failed to destroy the HMC resources: %d\n",
11802 ret_code);
11803 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011804
11805 /* shutdown the adminq */
Henry Tiemanac9c5c62016-09-06 18:05:11 -070011806 i40e_shutdown_adminq(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011807
Jesse Brandeburg8ddb3322015-11-18 15:47:06 -080011808 /* destroy the locks only once, here */
11809 mutex_destroy(&hw->aq.arq_mutex);
11810 mutex_destroy(&hw->aq.asq_mutex);
11811
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011812 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
11813 i40e_clear_interrupt_scheme(pf);
Mitch Williams505682c2014-05-20 08:01:37 +000011814 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011815 if (pf->vsi[i]) {
11816 i40e_vsi_clear_rings(pf->vsi[i]);
11817 i40e_vsi_clear(pf->vsi[i]);
11818 pf->vsi[i] = NULL;
11819 }
11820 }
11821
11822 for (i = 0; i < I40E_MAX_VEB; i++) {
11823 kfree(pf->veb[i]);
11824 pf->veb[i] = NULL;
11825 }
11826
11827 kfree(pf->qp_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011828 kfree(pf->vsi);
11829
Jesse Brandeburgf734dff2016-01-15 14:33:11 -080011830 iounmap(hw->hw_addr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011831 kfree(pf);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020011832 pci_release_mem_regions(pdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011833
11834 pci_disable_pcie_error_reporting(pdev);
11835 pci_disable_device(pdev);
11836}
11837
11838/**
11839 * i40e_pci_error_detected - warning that something funky happened in PCI land
11840 * @pdev: PCI device information struct
11841 *
11842 * Called to warn that something happened and the error handling steps
11843 * are in progress. Allows the driver to quiesce things, be ready for
11844 * remediation.
11845 **/
11846static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
11847 enum pci_channel_state error)
11848{
11849 struct i40e_pf *pf = pci_get_drvdata(pdev);
11850
11851 dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
11852
Guilherme G Piccoliedfc23ee2016-10-03 00:31:12 -070011853 if (!pf) {
11854 dev_info(&pdev->dev,
11855 "Cannot recover - error happened during device probe\n");
11856 return PCI_ERS_RESULT_DISCONNECT;
11857 }
11858
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011859 /* shutdown all operations */
Jacob Kellerdfc4ff62017-06-07 05:43:13 -040011860 if (!test_bit(__I40E_SUSPENDED, pf->state))
11861 i40e_prep_for_reset(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011862
11863 /* Request a slot reset */
11864 return PCI_ERS_RESULT_NEED_RESET;
11865}
11866
11867/**
11868 * i40e_pci_error_slot_reset - a PCI slot reset just happened
11869 * @pdev: PCI device information struct
11870 *
11871 * Called to find if the driver can work with the device now that
11872 * the pci slot has been reset. If a basic connection seems good
11873 * (registers are readable and have sane content) then return a
11874 * happy little PCI_ERS_RESULT_xxx.
11875 **/
11876static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
11877{
11878 struct i40e_pf *pf = pci_get_drvdata(pdev);
11879 pci_ers_result_t result;
11880 int err;
11881 u32 reg;
11882
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011883 dev_dbg(&pdev->dev, "%s\n", __func__);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011884 if (pci_enable_device_mem(pdev)) {
11885 dev_info(&pdev->dev,
11886 "Cannot re-enable PCI device after reset.\n");
11887 result = PCI_ERS_RESULT_DISCONNECT;
11888 } else {
11889 pci_set_master(pdev);
11890 pci_restore_state(pdev);
11891 pci_save_state(pdev);
11892 pci_wake_from_d3(pdev, false);
11893
11894 reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
11895 if (reg == 0)
11896 result = PCI_ERS_RESULT_RECOVERED;
11897 else
11898 result = PCI_ERS_RESULT_DISCONNECT;
11899 }
11900
11901 err = pci_cleanup_aer_uncorrect_error_status(pdev);
11902 if (err) {
11903 dev_info(&pdev->dev,
11904 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
11905 err);
11906 /* non-fatal, continue */
11907 }
11908
11909 return result;
11910}
11911
11912/**
11913 * i40e_pci_error_resume - restart operations after PCI error recovery
11914 * @pdev: PCI device information struct
11915 *
11916 * Called to allow the driver to bring things back up after PCI error
11917 * and/or reset recovery has finished.
11918 **/
11919static void i40e_pci_error_resume(struct pci_dev *pdev)
11920{
11921 struct i40e_pf *pf = pci_get_drvdata(pdev);
11922
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011923 dev_dbg(&pdev->dev, "%s\n", __func__);
Jacob Keller0da36b92017-04-19 09:25:55 -040011924 if (test_bit(__I40E_SUSPENDED, pf->state))
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011925 return;
11926
Jacob Kellerdfc4ff62017-06-07 05:43:13 -040011927 i40e_handle_reset_warning(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011928}
11929
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011930/**
Joshua Hay1d680052016-12-12 15:44:08 -080011931 * i40e_enable_mc_magic_wake - enable multicast magic packet wake up
11932 * using the mac_address_write admin q function
11933 * @pf: pointer to i40e_pf struct
11934 **/
11935static void i40e_enable_mc_magic_wake(struct i40e_pf *pf)
11936{
11937 struct i40e_hw *hw = &pf->hw;
11938 i40e_status ret;
11939 u8 mac_addr[6];
11940 u16 flags = 0;
11941
11942 /* Get current MAC address in case it's an LAA */
11943 if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) {
11944 ether_addr_copy(mac_addr,
11945 pf->vsi[pf->lan_vsi]->netdev->dev_addr);
11946 } else {
11947 dev_err(&pf->pdev->dev,
11948 "Failed to retrieve MAC address; using default\n");
11949 ether_addr_copy(mac_addr, hw->mac.addr);
11950 }
11951
11952 /* The FW expects the mac address write cmd to first be called with
11953 * one of these flags before calling it again with the multicast
11954 * enable flags.
11955 */
11956 flags = I40E_AQC_WRITE_TYPE_LAA_WOL;
11957
11958 if (hw->func_caps.flex10_enable && hw->partition_id != 1)
11959 flags = I40E_AQC_WRITE_TYPE_LAA_ONLY;
11960
11961 ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
11962 if (ret) {
11963 dev_err(&pf->pdev->dev,
11964 "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up");
11965 return;
11966 }
11967
11968 flags = I40E_AQC_MC_MAG_EN
11969 | I40E_AQC_WOL_PRESERVE_ON_PFR
11970 | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG;
11971 ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
11972 if (ret)
11973 dev_err(&pf->pdev->dev,
11974 "Failed to enable Multicast Magic Packet wake up\n");
11975}
11976
11977/**
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011978 * i40e_shutdown - PCI callback for shutting down
11979 * @pdev: PCI device information struct
11980 **/
11981static void i40e_shutdown(struct pci_dev *pdev)
11982{
11983 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011984 struct i40e_hw *hw = &pf->hw;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011985
Jacob Keller0da36b92017-04-19 09:25:55 -040011986 set_bit(__I40E_SUSPENDED, pf->state);
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030011987 set_bit(__I40E_DOWN, pf->state);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011988 rtnl_lock();
Maciej Sosin373149f2017-04-05 07:50:55 -040011989 i40e_prep_for_reset(pf, true);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011990 rtnl_unlock();
11991
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011992 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11993 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11994
Catherine Sullivan02b42492015-07-10 19:35:59 -040011995 del_timer_sync(&pf->service_timer);
11996 cancel_work_sync(&pf->service_task);
11997 i40e_fdir_teardown(pf);
11998
Mitch Williams921c4672017-03-30 00:46:08 -070011999 /* Client close must be called explicitly here because the timer
12000 * has been stopped.
12001 */
12002 i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
12003
Jacob Kellerd36e41d2017-06-23 04:24:46 -040012004 if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
Joshua Hay1d680052016-12-12 15:44:08 -080012005 i40e_enable_mc_magic_wake(pf);
12006
Jacob Kellerdfc4ff62017-06-07 05:43:13 -040012007 i40e_prep_for_reset(pf, false);
Catherine Sullivan02b42492015-07-10 19:35:59 -040012008
12009 wr32(hw, I40E_PFPM_APM,
12010 (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
12011 wr32(hw, I40E_PFPM_WUFC,
12012 (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
12013
Shannon Nelsone1477582015-02-21 06:44:33 +000012014 i40e_clear_interrupt_scheme(pf);
12015
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012016 if (system_state == SYSTEM_POWER_OFF) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +000012017 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012018 pci_set_power_state(pdev, PCI_D3hot);
12019 }
12020}
12021
12022#ifdef CONFIG_PM
12023/**
12024 * i40e_suspend - PCI callback for moving to D3
12025 * @pdev: PCI device information struct
12026 **/
12027static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
12028{
12029 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +000012030 struct i40e_hw *hw = &pf->hw;
Greg Rose059ff692016-05-16 10:26:38 -070012031 int retval = 0;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012032
Jacob Keller0da36b92017-04-19 09:25:55 -040012033 set_bit(__I40E_SUSPENDED, pf->state);
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030012034 set_bit(__I40E_DOWN, pf->state);
Mitch Williams3932dbf2015-03-31 00:45:04 -070012035
Jacob Kellerd36e41d2017-06-23 04:24:46 -040012036 if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
Joshua Hay1d680052016-12-12 15:44:08 -080012037 i40e_enable_mc_magic_wake(pf);
12038
Jacob Kellerdfc4ff62017-06-07 05:43:13 -040012039 i40e_prep_for_reset(pf, false);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012040
Shannon Nelson8e2773a2013-11-28 06:39:22 +000012041 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
12042 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
12043
Greg Roseb33d3b72016-05-16 10:26:37 -070012044 i40e_stop_misc_vector(pf);
Carolyn Wyborny7c9ae7f2017-06-20 15:16:53 -070012045 if (pf->msix_entries) {
12046 synchronize_irq(pf->msix_entries[0].vector);
12047 free_irq(pf->msix_entries[0].vector, pf);
12048 }
Greg Rose059ff692016-05-16 10:26:38 -070012049 retval = pci_save_state(pdev);
12050 if (retval)
12051 return retval;
12052
Shannon Nelson8e2773a2013-11-28 06:39:22 +000012053 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012054 pci_set_power_state(pdev, PCI_D3hot);
12055
Greg Rose059ff692016-05-16 10:26:38 -070012056 return retval;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012057}
12058
12059/**
12060 * i40e_resume - PCI callback for waking up from D3
12061 * @pdev: PCI device information struct
12062 **/
12063static int i40e_resume(struct pci_dev *pdev)
12064{
12065 struct i40e_pf *pf = pci_get_drvdata(pdev);
12066 u32 err;
12067
12068 pci_set_power_state(pdev, PCI_D0);
12069 pci_restore_state(pdev);
12070 /* pci_restore_state() clears dev->state_saves, so
12071 * call pci_save_state() again to restore it.
12072 */
12073 pci_save_state(pdev);
12074
12075 err = pci_enable_device_mem(pdev);
12076 if (err) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040012077 dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012078 return err;
12079 }
12080 pci_set_master(pdev);
12081
12082 /* no wakeup events while running */
12083 pci_wake_from_d3(pdev, false);
12084
12085 /* handling the reset will rebuild the device state */
Jacob Keller0da36b92017-04-19 09:25:55 -040012086 if (test_and_clear_bit(__I40E_SUSPENDED, pf->state)) {
Mauro S. M. Rodrigues9e6c9c02017-05-12 23:26:56 -030012087 clear_bit(__I40E_DOWN, pf->state);
Carolyn Wyborny7c9ae7f2017-06-20 15:16:53 -070012088 if (pf->msix_entries) {
12089 err = request_irq(pf->msix_entries[0].vector,
12090 i40e_intr, 0, pf->int_name, pf);
12091 if (err) {
12092 dev_err(&pf->pdev->dev,
12093 "request_irq for %s failed: %d\n",
12094 pf->int_name, err);
12095 }
12096 }
Jacob Kellerdfc4ff62017-06-07 05:43:13 -040012097 i40e_reset_and_rebuild(pf, false, false);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012098 }
12099
12100 return 0;
12101}
12102
12103#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000012104static const struct pci_error_handlers i40e_err_handler = {
12105 .error_detected = i40e_pci_error_detected,
12106 .slot_reset = i40e_pci_error_slot_reset,
12107 .resume = i40e_pci_error_resume,
12108};
12109
12110static struct pci_driver i40e_driver = {
12111 .name = i40e_driver_name,
12112 .id_table = i40e_pci_tbl,
12113 .probe = i40e_probe,
12114 .remove = i40e_remove,
Shannon Nelson9007bcc2013-11-26 10:49:23 +000012115#ifdef CONFIG_PM
12116 .suspend = i40e_suspend,
12117 .resume = i40e_resume,
12118#endif
12119 .shutdown = i40e_shutdown,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000012120 .err_handler = &i40e_err_handler,
12121 .sriov_configure = i40e_pci_sriov_configure,
12122};
12123
12124/**
12125 * i40e_init_module - Driver registration routine
12126 *
12127 * i40e_init_module is the first routine called when the driver is
12128 * loaded. All it does is register with the PCI subsystem.
12129 **/
12130static int __init i40e_init_module(void)
12131{
12132 pr_info("%s: %s - version %s\n", i40e_driver_name,
12133 i40e_driver_string, i40e_driver_version_str);
12134 pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
Greg Rose96664482015-02-06 08:52:13 +000012135
Jacob Keller4d5957c2017-06-20 15:16:54 -070012136 /* There is no need to throttle the number of active tasks because
12137 * each device limits its own task using a state bit for scheduling
12138 * the service task, and the device tasks do not interfere with each
12139 * other, so we don't set a max task limit. We must set WQ_MEM_RECLAIM
12140 * since we need to be able to guarantee forward progress even under
12141 * memory pressure.
Jesse Brandeburg2803b162015-12-22 14:25:08 -080012142 */
Jacob Keller4d5957c2017-06-20 15:16:54 -070012143 i40e_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, i40e_driver_name);
Jesse Brandeburg2803b162015-12-22 14:25:08 -080012144 if (!i40e_wq) {
12145 pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
12146 return -ENOMEM;
12147 }
12148
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000012149 i40e_dbg_init();
12150 return pci_register_driver(&i40e_driver);
12151}
12152module_init(i40e_init_module);
12153
12154/**
12155 * i40e_exit_module - Driver exit cleanup routine
12156 *
12157 * i40e_exit_module is called just before the driver is removed
12158 * from memory.
12159 **/
12160static void __exit i40e_exit_module(void)
12161{
12162 pci_unregister_driver(&i40e_driver);
Jesse Brandeburg2803b162015-12-22 14:25:08 -080012163 destroy_workqueue(i40e_wq);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000012164 i40e_dbg_exit();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000012165}
12166module_exit(i40e_exit_module);