blob: adb2a04930d64cf7367559c6d58672647728f8a4 [file] [log] [blame]
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Jesse Brandeburg2818ccd2016-01-13 16:51:38 -08004 * Copyright(c) 2013 - 2016 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>
30
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000031/* Local includes */
32#include "i40e.h"
Shannon Nelson4eb3f762014-03-06 08:59:58 +000033#include "i40e_diag.h"
Singhai, Anjali6a899022015-12-14 12:21:18 -080034#if IS_ENABLED(CONFIG_VXLAN)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +000035#include <net/vxlan.h>
36#endif
Singhai, Anjali6a899022015-12-14 12:21:18 -080037#if IS_ENABLED(CONFIG_GENEVE)
38#include <net/geneve.h>
39#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000040
41const char i40e_driver_name[] = "i40e";
42static const char i40e_driver_string[] =
43 "Intel(R) Ethernet Connection XL710 Network Driver";
44
45#define DRV_KERN "-k"
46
Catherine Sullivane8e724d2014-07-10 07:58:26 +000047#define DRV_VERSION_MAJOR 1
Catherine Sullivan1c2df9e2015-10-21 19:56:24 -040048#define DRV_VERSION_MINOR 4
Jesse Brandeburgc24215c2016-01-13 16:51:52 -080049#define DRV_VERSION_BUILD 13
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000050#define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
51 __stringify(DRV_VERSION_MINOR) "." \
52 __stringify(DRV_VERSION_BUILD) DRV_KERN
53const char i40e_driver_version_str[] = DRV_VERSION;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -080054static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000055
56/* a bit of forward declarations */
57static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
58static void i40e_handle_reset_warning(struct i40e_pf *pf);
59static int i40e_add_vsi(struct i40e_vsi *vsi);
60static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000061static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000062static int i40e_setup_misc_vector(struct i40e_pf *pf);
63static void i40e_determine_queue_usage(struct i40e_pf *pf);
64static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
Helin Zhange69ff812015-10-21 19:56:22 -040065static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
66 u16 rss_table_size, u16 rss_size);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080067static void i40e_fdir_sb_setup(struct i40e_pf *pf);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080068static int i40e_veb_get_bw_info(struct i40e_veb *veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000069
70/* i40e_pci_tbl - PCI Device ID Table
71 *
72 * Last entry must be all 0s
73 *
74 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
75 * Class, Class Mask, private data (not used) }
76 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020077static const struct pci_device_id i40e_pci_tbl[] = {
Shannon Nelsonab600852014-01-17 15:36:39 -080078 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080079 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080080 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
81 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080082 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
83 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
84 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
Mitch Williams5960d332014-09-13 07:40:47 +000085 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
Shannon Nelsonbc5166b92015-08-26 15:14:10 -040086 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
Jesse Brandeburgae24b402015-03-27 00:12:09 -070087 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
Anjali Singhai Jain35dae512015-12-22 14:25:03 -080088 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0},
89 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0},
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040090 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
91 {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
92 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
Shannon Nelson48a3b512015-07-23 16:54:39 -040093 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
94 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000095 /* required last entry */
96 {0, }
97};
98MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
99
100#define I40E_MAX_VF_COUNT 128
101static int debug = -1;
102module_param(debug, int, 0);
103MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
104
105MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
106MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
107MODULE_LICENSE("GPL");
108MODULE_VERSION(DRV_VERSION);
109
Jesse Brandeburg2803b162015-12-22 14:25:08 -0800110static struct workqueue_struct *i40e_wq;
111
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000112/**
113 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
114 * @hw: pointer to the HW structure
115 * @mem: ptr to mem struct to fill out
116 * @size: size of memory requested
117 * @alignment: what to align the allocation to
118 **/
119int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
120 u64 size, u32 alignment)
121{
122 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
123
124 mem->size = ALIGN(size, alignment);
125 mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
126 &mem->pa, GFP_KERNEL);
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000127 if (!mem->va)
128 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000129
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000130 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000131}
132
133/**
134 * i40e_free_dma_mem_d - OS specific memory free for shared code
135 * @hw: pointer to the HW structure
136 * @mem: ptr to mem struct to free
137 **/
138int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
139{
140 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
141
142 dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
143 mem->va = NULL;
144 mem->pa = 0;
145 mem->size = 0;
146
147 return 0;
148}
149
150/**
151 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
152 * @hw: pointer to the HW structure
153 * @mem: ptr to mem struct to fill out
154 * @size: size of memory requested
155 **/
156int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
157 u32 size)
158{
159 mem->size = size;
160 mem->va = kzalloc(size, GFP_KERNEL);
161
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000162 if (!mem->va)
163 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000164
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000165 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000166}
167
168/**
169 * i40e_free_virt_mem_d - OS specific memory free for shared code
170 * @hw: pointer to the HW structure
171 * @mem: ptr to mem struct to free
172 **/
173int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
174{
175 /* it's ok to kfree a NULL pointer */
176 kfree(mem->va);
177 mem->va = NULL;
178 mem->size = 0;
179
180 return 0;
181}
182
183/**
184 * i40e_get_lump - find a lump of free generic resource
185 * @pf: board private structure
186 * @pile: the pile of resource to search
187 * @needed: the number of items needed
188 * @id: an owner id to stick on the items assigned
189 *
190 * Returns the base item index of the lump, or negative for error
191 *
192 * The search_hint trick and lack of advanced fit-finding only work
193 * because we're highly likely to have all the same size lump requests.
194 * Linear search time and any fragmentation should be minimal.
195 **/
196static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
197 u16 needed, u16 id)
198{
199 int ret = -ENOMEM;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000200 int i, j;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000201
202 if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
203 dev_info(&pf->pdev->dev,
204 "param err: pile=%p needed=%d id=0x%04x\n",
205 pile, needed, id);
206 return -EINVAL;
207 }
208
209 /* start the linear search with an imperfect hint */
210 i = pile->search_hint;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000211 while (i < pile->num_entries) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000212 /* skip already allocated entries */
213 if (pile->list[i] & I40E_PILE_VALID_BIT) {
214 i++;
215 continue;
216 }
217
218 /* do we have enough in this lump? */
219 for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
220 if (pile->list[i+j] & I40E_PILE_VALID_BIT)
221 break;
222 }
223
224 if (j == needed) {
225 /* there was enough, so assign it to the requestor */
226 for (j = 0; j < needed; j++)
227 pile->list[i+j] = id | I40E_PILE_VALID_BIT;
228 ret = i;
229 pile->search_hint = i + j;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000230 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000231 }
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400232
233 /* not enough, so skip over it and continue looking */
234 i += j;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000235 }
236
237 return ret;
238}
239
240/**
241 * i40e_put_lump - return a lump of generic resource
242 * @pile: the pile of resource to search
243 * @index: the base item index
244 * @id: the owner id of the items assigned
245 *
246 * Returns the count of items in the lump
247 **/
248static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
249{
250 int valid_id = (id | I40E_PILE_VALID_BIT);
251 int count = 0;
252 int i;
253
254 if (!pile || index >= pile->num_entries)
255 return -EINVAL;
256
257 for (i = index;
258 i < pile->num_entries && pile->list[i] == valid_id;
259 i++) {
260 pile->list[i] = 0;
261 count++;
262 }
263
264 if (count && index < pile->search_hint)
265 pile->search_hint = index;
266
267 return count;
268}
269
270/**
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700271 * i40e_find_vsi_from_id - searches for the vsi with the given id
272 * @pf - the pf structure to search for the vsi
273 * @id - id of the vsi it is searching for
274 **/
275struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
276{
277 int i;
278
279 for (i = 0; i < pf->num_alloc_vsi; i++)
280 if (pf->vsi[i] && (pf->vsi[i]->id == id))
281 return pf->vsi[i];
282
283 return NULL;
284}
285
286/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000287 * i40e_service_event_schedule - Schedule the service task to wake up
288 * @pf: board private structure
289 *
290 * If not already scheduled, this puts the task into the work queue
291 **/
292static void i40e_service_event_schedule(struct i40e_pf *pf)
293{
294 if (!test_bit(__I40E_DOWN, &pf->state) &&
295 !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) &&
296 !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
Jesse Brandeburg2803b162015-12-22 14:25:08 -0800297 queue_work(i40e_wq, &pf->service_task);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000298}
299
300/**
301 * i40e_tx_timeout - Respond to a Tx Hang
302 * @netdev: network interface device structure
303 *
304 * If any port has noticed a Tx timeout, it is likely that the whole
305 * device is munged, not just the one netdev port, so go for the full
306 * reset.
307 **/
Vasu Dev38e00432014-08-01 13:27:03 -0700308#ifdef I40E_FCOE
309void i40e_tx_timeout(struct net_device *netdev)
310#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000311static void i40e_tx_timeout(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -0700312#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000313{
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);
329 trans_start = q->trans_start ? : netdev->trans_start;
330 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:
381 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
382 break;
383 case 2:
384 set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
385 break;
386 case 3:
387 set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
388 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/**
399 * i40e_release_rx_desc - Store the new tail and head values
400 * @rx_ring: ring to bump
401 * @val: new head index
402 **/
403static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val)
404{
405 rx_ring->next_to_use = val;
406
407 /* Force memory writes to complete before letting h/w
408 * know there are new descriptors to fetch. (Only
409 * applicable for weak-ordered memory model archs,
410 * such as IA-64).
411 */
412 wmb();
413 writel(val, rx_ring->tail);
414}
415
416/**
417 * i40e_get_vsi_stats_struct - Get System Network Statistics
418 * @vsi: the VSI we care about
419 *
420 * Returns the address of the device statistics structure.
421 * The statistics are actually updated from the service task.
422 **/
423struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
424{
425 return &vsi->net_stats;
426}
427
428/**
429 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
430 * @netdev: network interface device structure
431 *
432 * Returns the address of the device statistics structure.
433 * The statistics are actually updated from the service task.
434 **/
Vasu Dev38e00432014-08-01 13:27:03 -0700435#ifdef I40E_FCOE
436struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
437 struct net_device *netdev,
438 struct rtnl_link_stats64 *stats)
439#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000440static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
441 struct net_device *netdev,
Alexander Duyck980e9b12013-09-28 06:01:03 +0000442 struct rtnl_link_stats64 *stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700443#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000444{
445 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000446 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000447 struct i40e_vsi *vsi = np->vsi;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000448 struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
449 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000450
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +0000451 if (test_bit(__I40E_DOWN, &vsi->state))
452 return stats;
453
Jesse Brandeburg3c325ce2013-12-14 03:26:45 -0800454 if (!vsi->tx_rings)
455 return stats;
456
Alexander Duyck980e9b12013-09-28 06:01:03 +0000457 rcu_read_lock();
458 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000459 u64 bytes, packets;
460 unsigned int start;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000461
Alexander Duyck980e9b12013-09-28 06:01:03 +0000462 tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
463 if (!tx_ring)
464 continue;
465
466 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700467 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000468 packets = tx_ring->stats.packets;
469 bytes = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700470 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000471
472 stats->tx_packets += packets;
473 stats->tx_bytes += bytes;
474 rx_ring = &tx_ring[1];
475
476 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700477 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000478 packets = rx_ring->stats.packets;
479 bytes = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700480 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000481
482 stats->rx_packets += packets;
483 stats->rx_bytes += bytes;
484 }
485 rcu_read_unlock();
486
Akeem G Abodunrina5282f42014-05-10 04:49:03 +0000487 /* following stats updated by i40e_watchdog_subtask() */
Alexander Duyck980e9b12013-09-28 06:01:03 +0000488 stats->multicast = vsi_stats->multicast;
489 stats->tx_errors = vsi_stats->tx_errors;
490 stats->tx_dropped = vsi_stats->tx_dropped;
491 stats->rx_errors = vsi_stats->rx_errors;
Jesse Brandeburgd8201e22015-07-23 16:54:35 -0400492 stats->rx_dropped = vsi_stats->rx_dropped;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000493 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
494 stats->rx_length_errors = vsi_stats->rx_length_errors;
495
496 return stats;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000497}
498
499/**
500 * i40e_vsi_reset_stats - Resets all stats of the given vsi
501 * @vsi: the VSI to have its stats reset
502 **/
503void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
504{
505 struct rtnl_link_stats64 *ns;
506 int i;
507
508 if (!vsi)
509 return;
510
511 ns = i40e_get_vsi_stats_struct(vsi);
512 memset(ns, 0, sizeof(*ns));
513 memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
514 memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
515 memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
Greg Rose8e9dca52013-12-18 13:45:53 +0000516 if (vsi->rx_rings && vsi->rx_rings[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000517 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400518 memset(&vsi->rx_rings[i]->stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000519 sizeof(vsi->rx_rings[i]->stats));
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400520 memset(&vsi->rx_rings[i]->rx_stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000521 sizeof(vsi->rx_rings[i]->rx_stats));
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400522 memset(&vsi->tx_rings[i]->stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000523 sizeof(vsi->tx_rings[i]->stats));
524 memset(&vsi->tx_rings[i]->tx_stats, 0,
525 sizeof(vsi->tx_rings[i]->tx_stats));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000526 }
Greg Rose8e9dca52013-12-18 13:45:53 +0000527 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000528 vsi->stat_offsets_loaded = false;
529}
530
531/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +0000532 * i40e_pf_reset_stats - Reset all of the stats for the given PF
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000533 * @pf: the PF to be reset
534 **/
535void i40e_pf_reset_stats(struct i40e_pf *pf)
536{
Shannon Nelsone91fdf72014-06-03 23:50:18 +0000537 int i;
538
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000539 memset(&pf->stats, 0, sizeof(pf->stats));
540 memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
541 pf->stat_offsets_loaded = false;
Shannon Nelsone91fdf72014-06-03 23:50:18 +0000542
543 for (i = 0; i < I40E_MAX_VEB; i++) {
544 if (pf->veb[i]) {
545 memset(&pf->veb[i]->stats, 0,
546 sizeof(pf->veb[i]->stats));
547 memset(&pf->veb[i]->stats_offsets, 0,
548 sizeof(pf->veb[i]->stats_offsets));
549 pf->veb[i]->stat_offsets_loaded = false;
550 }
551 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000552}
553
554/**
555 * i40e_stat_update48 - read and update a 48 bit stat from the chip
556 * @hw: ptr to the hardware info
557 * @hireg: the high 32 bit reg to read
558 * @loreg: the low 32 bit reg to read
559 * @offset_loaded: has the initial offset been loaded yet
560 * @offset: ptr to current offset value
561 * @stat: ptr to the stat
562 *
563 * Since the device stats are not reset at PFReset, they likely will not
564 * be zeroed when the driver starts. We'll save the first values read
565 * and use them as offsets to be subtracted from the raw values in order
566 * to report stats that count from zero. In the process, we also manage
567 * the potential roll-over.
568 **/
569static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
570 bool offset_loaded, u64 *offset, u64 *stat)
571{
572 u64 new_data;
573
Shannon Nelsonab600852014-01-17 15:36:39 -0800574 if (hw->device_id == I40E_DEV_ID_QEMU) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000575 new_data = rd32(hw, loreg);
576 new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
577 } else {
578 new_data = rd64(hw, loreg);
579 }
580 if (!offset_loaded)
581 *offset = new_data;
582 if (likely(new_data >= *offset))
583 *stat = new_data - *offset;
584 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400585 *stat = (new_data + BIT_ULL(48)) - *offset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000586 *stat &= 0xFFFFFFFFFFFFULL;
587}
588
589/**
590 * i40e_stat_update32 - read and update a 32 bit stat from the chip
591 * @hw: ptr to the hardware info
592 * @reg: the hw reg to read
593 * @offset_loaded: has the initial offset been loaded yet
594 * @offset: ptr to current offset value
595 * @stat: ptr to the stat
596 **/
597static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
598 bool offset_loaded, u64 *offset, u64 *stat)
599{
600 u32 new_data;
601
602 new_data = rd32(hw, reg);
603 if (!offset_loaded)
604 *offset = new_data;
605 if (likely(new_data >= *offset))
606 *stat = (u32)(new_data - *offset);
607 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400608 *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000609}
610
611/**
612 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
613 * @vsi: the VSI to be updated
614 **/
615void i40e_update_eth_stats(struct i40e_vsi *vsi)
616{
617 int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
618 struct i40e_pf *pf = vsi->back;
619 struct i40e_hw *hw = &pf->hw;
620 struct i40e_eth_stats *oes;
621 struct i40e_eth_stats *es; /* device's eth stats */
622
623 es = &vsi->eth_stats;
624 oes = &vsi->eth_stats_offsets;
625
626 /* Gather up the stats that the hw collects */
627 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
628 vsi->stat_offsets_loaded,
629 &oes->tx_errors, &es->tx_errors);
630 i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
631 vsi->stat_offsets_loaded,
632 &oes->rx_discards, &es->rx_discards);
Shannon Nelson41a9e552014-04-23 04:50:20 +0000633 i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
634 vsi->stat_offsets_loaded,
635 &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
636 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
637 vsi->stat_offsets_loaded,
638 &oes->tx_errors, &es->tx_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000639
640 i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
641 I40E_GLV_GORCL(stat_idx),
642 vsi->stat_offsets_loaded,
643 &oes->rx_bytes, &es->rx_bytes);
644 i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
645 I40E_GLV_UPRCL(stat_idx),
646 vsi->stat_offsets_loaded,
647 &oes->rx_unicast, &es->rx_unicast);
648 i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
649 I40E_GLV_MPRCL(stat_idx),
650 vsi->stat_offsets_loaded,
651 &oes->rx_multicast, &es->rx_multicast);
652 i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
653 I40E_GLV_BPRCL(stat_idx),
654 vsi->stat_offsets_loaded,
655 &oes->rx_broadcast, &es->rx_broadcast);
656
657 i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
658 I40E_GLV_GOTCL(stat_idx),
659 vsi->stat_offsets_loaded,
660 &oes->tx_bytes, &es->tx_bytes);
661 i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
662 I40E_GLV_UPTCL(stat_idx),
663 vsi->stat_offsets_loaded,
664 &oes->tx_unicast, &es->tx_unicast);
665 i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
666 I40E_GLV_MPTCL(stat_idx),
667 vsi->stat_offsets_loaded,
668 &oes->tx_multicast, &es->tx_multicast);
669 i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
670 I40E_GLV_BPTCL(stat_idx),
671 vsi->stat_offsets_loaded,
672 &oes->tx_broadcast, &es->tx_broadcast);
673 vsi->stat_offsets_loaded = true;
674}
675
676/**
677 * i40e_update_veb_stats - Update Switch component statistics
678 * @veb: the VEB being updated
679 **/
680static void i40e_update_veb_stats(struct i40e_veb *veb)
681{
682 struct i40e_pf *pf = veb->pf;
683 struct i40e_hw *hw = &pf->hw;
684 struct i40e_eth_stats *oes;
685 struct i40e_eth_stats *es; /* device's eth stats */
Neerav Parikhfe860af2015-07-10 19:36:02 -0400686 struct i40e_veb_tc_stats *veb_oes;
687 struct i40e_veb_tc_stats *veb_es;
688 int i, idx = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000689
690 idx = veb->stats_idx;
691 es = &veb->stats;
692 oes = &veb->stats_offsets;
Neerav Parikhfe860af2015-07-10 19:36:02 -0400693 veb_es = &veb->tc_stats;
694 veb_oes = &veb->tc_stats_offsets;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000695
696 /* Gather up the stats that the hw collects */
697 i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
698 veb->stat_offsets_loaded,
699 &oes->tx_discards, &es->tx_discards);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000700 if (hw->revision_id > 0)
701 i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
702 veb->stat_offsets_loaded,
703 &oes->rx_unknown_protocol,
704 &es->rx_unknown_protocol);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000705 i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
706 veb->stat_offsets_loaded,
707 &oes->rx_bytes, &es->rx_bytes);
708 i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
709 veb->stat_offsets_loaded,
710 &oes->rx_unicast, &es->rx_unicast);
711 i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
712 veb->stat_offsets_loaded,
713 &oes->rx_multicast, &es->rx_multicast);
714 i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
715 veb->stat_offsets_loaded,
716 &oes->rx_broadcast, &es->rx_broadcast);
717
718 i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
719 veb->stat_offsets_loaded,
720 &oes->tx_bytes, &es->tx_bytes);
721 i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
722 veb->stat_offsets_loaded,
723 &oes->tx_unicast, &es->tx_unicast);
724 i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
725 veb->stat_offsets_loaded,
726 &oes->tx_multicast, &es->tx_multicast);
727 i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
728 veb->stat_offsets_loaded,
729 &oes->tx_broadcast, &es->tx_broadcast);
Neerav Parikhfe860af2015-07-10 19:36:02 -0400730 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
731 i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
732 I40E_GLVEBTC_RPCL(i, idx),
733 veb->stat_offsets_loaded,
734 &veb_oes->tc_rx_packets[i],
735 &veb_es->tc_rx_packets[i]);
736 i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
737 I40E_GLVEBTC_RBCL(i, idx),
738 veb->stat_offsets_loaded,
739 &veb_oes->tc_rx_bytes[i],
740 &veb_es->tc_rx_bytes[i]);
741 i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
742 I40E_GLVEBTC_TPCL(i, idx),
743 veb->stat_offsets_loaded,
744 &veb_oes->tc_tx_packets[i],
745 &veb_es->tc_tx_packets[i]);
746 i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
747 I40E_GLVEBTC_TBCL(i, idx),
748 veb->stat_offsets_loaded,
749 &veb_oes->tc_tx_bytes[i],
750 &veb_es->tc_tx_bytes[i]);
751 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000752 veb->stat_offsets_loaded = true;
753}
754
Vasu Dev38e00432014-08-01 13:27:03 -0700755#ifdef I40E_FCOE
756/**
757 * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
758 * @vsi: the VSI that is capable of doing FCoE
759 **/
760static void i40e_update_fcoe_stats(struct i40e_vsi *vsi)
761{
762 struct i40e_pf *pf = vsi->back;
763 struct i40e_hw *hw = &pf->hw;
764 struct i40e_fcoe_stats *ofs;
765 struct i40e_fcoe_stats *fs; /* device's eth stats */
766 int idx;
767
768 if (vsi->type != I40E_VSI_FCOE)
769 return;
770
Kiran Patil4147e2c2016-01-15 14:33:14 -0800771 idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET;
Vasu Dev38e00432014-08-01 13:27:03 -0700772 fs = &vsi->fcoe_stats;
773 ofs = &vsi->fcoe_stats_offsets;
774
775 i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx),
776 vsi->fcoe_stat_offsets_loaded,
777 &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets);
778 i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx),
779 vsi->fcoe_stat_offsets_loaded,
780 &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords);
781 i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx),
782 vsi->fcoe_stat_offsets_loaded,
783 &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped);
784 i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx),
785 vsi->fcoe_stat_offsets_loaded,
786 &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets);
787 i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx),
788 vsi->fcoe_stat_offsets_loaded,
789 &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords);
790 i40e_stat_update32(hw, I40E_GL_FCOECRC(idx),
791 vsi->fcoe_stat_offsets_loaded,
792 &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc);
793 i40e_stat_update32(hw, I40E_GL_FCOELAST(idx),
794 vsi->fcoe_stat_offsets_loaded,
795 &ofs->fcoe_last_error, &fs->fcoe_last_error);
796 i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx),
797 vsi->fcoe_stat_offsets_loaded,
798 &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count);
799
800 vsi->fcoe_stat_offsets_loaded = true;
801}
802
803#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000804/**
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000805 * i40e_update_vsi_stats - Update the vsi statistics counters.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000806 * @vsi: the VSI to be updated
807 *
808 * There are a few instances where we store the same stat in a
809 * couple of different structs. This is partly because we have
810 * the netdev stats that need to be filled out, which is slightly
811 * different from the "eth_stats" defined by the chip and used in
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000812 * VF communications. We sort it out here.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000813 **/
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000814static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000815{
816 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000817 struct rtnl_link_stats64 *ons;
818 struct rtnl_link_stats64 *ns; /* netdev stats */
819 struct i40e_eth_stats *oes;
820 struct i40e_eth_stats *es; /* device's eth stats */
821 u32 tx_restart, tx_busy;
Anjali Singhai Jaindd353102016-01-15 14:33:12 -0800822 u64 tx_lost_interrupt;
Akeem G Abodunrinbf00b372014-10-17 03:14:39 +0000823 struct i40e_ring *p;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000824 u32 rx_page, rx_buf;
Akeem G Abodunrinbf00b372014-10-17 03:14:39 +0000825 u64 bytes, packets;
826 unsigned int start;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400827 u64 tx_linearize;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400828 u64 tx_force_wb;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000829 u64 rx_p, rx_b;
830 u64 tx_p, tx_b;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000831 u16 q;
832
833 if (test_bit(__I40E_DOWN, &vsi->state) ||
834 test_bit(__I40E_CONFIG_BUSY, &pf->state))
835 return;
836
837 ns = i40e_get_vsi_stats_struct(vsi);
838 ons = &vsi->net_stats_offsets;
839 es = &vsi->eth_stats;
840 oes = &vsi->eth_stats_offsets;
841
842 /* Gather up the netdev and vsi stats that the driver collects
843 * on the fly during packet processing
844 */
845 rx_b = rx_p = 0;
846 tx_b = tx_p = 0;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400847 tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
Anjali Singhai Jaindd353102016-01-15 14:33:12 -0800848 tx_lost_interrupt = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000849 rx_page = 0;
850 rx_buf = 0;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000851 rcu_read_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000852 for (q = 0; q < vsi->num_queue_pairs; q++) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000853 /* locate Tx ring */
854 p = ACCESS_ONCE(vsi->tx_rings[q]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000855
Alexander Duyck980e9b12013-09-28 06:01:03 +0000856 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700857 start = u64_stats_fetch_begin_irq(&p->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000858 packets = p->stats.packets;
859 bytes = p->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700860 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000861 tx_b += bytes;
862 tx_p += packets;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000863 tx_restart += p->tx_stats.restart_queue;
864 tx_busy += p->tx_stats.tx_busy;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400865 tx_linearize += p->tx_stats.tx_linearize;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400866 tx_force_wb += p->tx_stats.tx_force_wb;
Anjali Singhai Jaindd353102016-01-15 14:33:12 -0800867 tx_lost_interrupt += p->tx_stats.tx_lost_interrupt;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000868
869 /* Rx queue is part of the same block as Tx queue */
870 p = &p[1];
871 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700872 start = u64_stats_fetch_begin_irq(&p->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000873 packets = p->stats.packets;
874 bytes = p->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700875 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000876 rx_b += bytes;
877 rx_p += packets;
Mitch Williams420136c2013-12-18 13:45:59 +0000878 rx_buf += p->rx_stats.alloc_buff_failed;
879 rx_page += p->rx_stats.alloc_page_failed;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000880 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000881 rcu_read_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000882 vsi->tx_restart = tx_restart;
883 vsi->tx_busy = tx_busy;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400884 vsi->tx_linearize = tx_linearize;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400885 vsi->tx_force_wb = tx_force_wb;
Anjali Singhai Jaindd353102016-01-15 14:33:12 -0800886 vsi->tx_lost_interrupt = tx_lost_interrupt;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000887 vsi->rx_page_failed = rx_page;
888 vsi->rx_buf_failed = rx_buf;
889
890 ns->rx_packets = rx_p;
891 ns->rx_bytes = rx_b;
892 ns->tx_packets = tx_p;
893 ns->tx_bytes = tx_b;
894
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000895 /* update netdev stats from eth stats */
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000896 i40e_update_eth_stats(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000897 ons->tx_errors = oes->tx_errors;
898 ns->tx_errors = es->tx_errors;
899 ons->multicast = oes->rx_multicast;
900 ns->multicast = es->rx_multicast;
Shannon Nelson41a9e552014-04-23 04:50:20 +0000901 ons->rx_dropped = oes->rx_discards;
902 ns->rx_dropped = es->rx_discards;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000903 ons->tx_dropped = oes->tx_discards;
904 ns->tx_dropped = es->tx_discards;
905
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000906 /* pull in a couple PF stats if this is the main vsi */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000907 if (vsi == pf->vsi[pf->lan_vsi]) {
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000908 ns->rx_crc_errors = pf->stats.crc_errors;
909 ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
910 ns->rx_length_errors = pf->stats.rx_length_errors;
911 }
912}
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000913
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000914/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +0000915 * i40e_update_pf_stats - Update the PF statistics counters.
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000916 * @pf: the PF to be updated
917 **/
918static void i40e_update_pf_stats(struct i40e_pf *pf)
919{
920 struct i40e_hw_port_stats *osd = &pf->stats_offsets;
921 struct i40e_hw_port_stats *nsd = &pf->stats;
922 struct i40e_hw *hw = &pf->hw;
923 u32 val;
924 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000925
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000926 i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
927 I40E_GLPRT_GORCL(hw->port),
928 pf->stat_offsets_loaded,
929 &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
930 i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
931 I40E_GLPRT_GOTCL(hw->port),
932 pf->stat_offsets_loaded,
933 &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
934 i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
935 pf->stat_offsets_loaded,
936 &osd->eth.rx_discards,
937 &nsd->eth.rx_discards);
Shannon Nelson532d2832014-04-23 04:50:09 +0000938 i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
939 I40E_GLPRT_UPRCL(hw->port),
940 pf->stat_offsets_loaded,
941 &osd->eth.rx_unicast,
942 &nsd->eth.rx_unicast);
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000943 i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
944 I40E_GLPRT_MPRCL(hw->port),
945 pf->stat_offsets_loaded,
946 &osd->eth.rx_multicast,
947 &nsd->eth.rx_multicast);
Shannon Nelson532d2832014-04-23 04:50:09 +0000948 i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
949 I40E_GLPRT_BPRCL(hw->port),
950 pf->stat_offsets_loaded,
951 &osd->eth.rx_broadcast,
952 &nsd->eth.rx_broadcast);
953 i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
954 I40E_GLPRT_UPTCL(hw->port),
955 pf->stat_offsets_loaded,
956 &osd->eth.tx_unicast,
957 &nsd->eth.tx_unicast);
958 i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
959 I40E_GLPRT_MPTCL(hw->port),
960 pf->stat_offsets_loaded,
961 &osd->eth.tx_multicast,
962 &nsd->eth.tx_multicast);
963 i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
964 I40E_GLPRT_BPTCL(hw->port),
965 pf->stat_offsets_loaded,
966 &osd->eth.tx_broadcast,
967 &nsd->eth.tx_broadcast);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000968
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000969 i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
970 pf->stat_offsets_loaded,
971 &osd->tx_dropped_link_down,
972 &nsd->tx_dropped_link_down);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000973
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000974 i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
975 pf->stat_offsets_loaded,
976 &osd->crc_errors, &nsd->crc_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000977
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000978 i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
979 pf->stat_offsets_loaded,
980 &osd->illegal_bytes, &nsd->illegal_bytes);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000981
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000982 i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
983 pf->stat_offsets_loaded,
984 &osd->mac_local_faults,
985 &nsd->mac_local_faults);
986 i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
987 pf->stat_offsets_loaded,
988 &osd->mac_remote_faults,
989 &nsd->mac_remote_faults);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000990
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000991 i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
992 pf->stat_offsets_loaded,
993 &osd->rx_length_errors,
994 &nsd->rx_length_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000995
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000996 i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
997 pf->stat_offsets_loaded,
998 &osd->link_xon_rx, &nsd->link_xon_rx);
999 i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
1000 pf->stat_offsets_loaded,
1001 &osd->link_xon_tx, &nsd->link_xon_tx);
Neerav Parikh95db2392015-11-06 15:26:09 -08001002 i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
1003 pf->stat_offsets_loaded,
1004 &osd->link_xoff_rx, &nsd->link_xoff_rx);
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001005 i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
1006 pf->stat_offsets_loaded,
1007 &osd->link_xoff_tx, &nsd->link_xoff_tx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001008
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001009 for (i = 0; i < 8; i++) {
Neerav Parikh95db2392015-11-06 15:26:09 -08001010 i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
1011 pf->stat_offsets_loaded,
1012 &osd->priority_xoff_rx[i],
1013 &nsd->priority_xoff_rx[i]);
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001014 i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001015 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001016 &osd->priority_xon_rx[i],
1017 &nsd->priority_xon_rx[i]);
1018 i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001019 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001020 &osd->priority_xon_tx[i],
1021 &nsd->priority_xon_tx[i]);
1022 i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001023 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001024 &osd->priority_xoff_tx[i],
1025 &nsd->priority_xoff_tx[i]);
1026 i40e_stat_update32(hw,
1027 I40E_GLPRT_RXON2OFFCNT(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001028 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001029 &osd->priority_xon_2_xoff[i],
1030 &nsd->priority_xon_2_xoff[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001031 }
1032
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001033 i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
1034 I40E_GLPRT_PRC64L(hw->port),
1035 pf->stat_offsets_loaded,
1036 &osd->rx_size_64, &nsd->rx_size_64);
1037 i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
1038 I40E_GLPRT_PRC127L(hw->port),
1039 pf->stat_offsets_loaded,
1040 &osd->rx_size_127, &nsd->rx_size_127);
1041 i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
1042 I40E_GLPRT_PRC255L(hw->port),
1043 pf->stat_offsets_loaded,
1044 &osd->rx_size_255, &nsd->rx_size_255);
1045 i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
1046 I40E_GLPRT_PRC511L(hw->port),
1047 pf->stat_offsets_loaded,
1048 &osd->rx_size_511, &nsd->rx_size_511);
1049 i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
1050 I40E_GLPRT_PRC1023L(hw->port),
1051 pf->stat_offsets_loaded,
1052 &osd->rx_size_1023, &nsd->rx_size_1023);
1053 i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
1054 I40E_GLPRT_PRC1522L(hw->port),
1055 pf->stat_offsets_loaded,
1056 &osd->rx_size_1522, &nsd->rx_size_1522);
1057 i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
1058 I40E_GLPRT_PRC9522L(hw->port),
1059 pf->stat_offsets_loaded,
1060 &osd->rx_size_big, &nsd->rx_size_big);
1061
1062 i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
1063 I40E_GLPRT_PTC64L(hw->port),
1064 pf->stat_offsets_loaded,
1065 &osd->tx_size_64, &nsd->tx_size_64);
1066 i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
1067 I40E_GLPRT_PTC127L(hw->port),
1068 pf->stat_offsets_loaded,
1069 &osd->tx_size_127, &nsd->tx_size_127);
1070 i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
1071 I40E_GLPRT_PTC255L(hw->port),
1072 pf->stat_offsets_loaded,
1073 &osd->tx_size_255, &nsd->tx_size_255);
1074 i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
1075 I40E_GLPRT_PTC511L(hw->port),
1076 pf->stat_offsets_loaded,
1077 &osd->tx_size_511, &nsd->tx_size_511);
1078 i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
1079 I40E_GLPRT_PTC1023L(hw->port),
1080 pf->stat_offsets_loaded,
1081 &osd->tx_size_1023, &nsd->tx_size_1023);
1082 i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
1083 I40E_GLPRT_PTC1522L(hw->port),
1084 pf->stat_offsets_loaded,
1085 &osd->tx_size_1522, &nsd->tx_size_1522);
1086 i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
1087 I40E_GLPRT_PTC9522L(hw->port),
1088 pf->stat_offsets_loaded,
1089 &osd->tx_size_big, &nsd->tx_size_big);
1090
1091 i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
1092 pf->stat_offsets_loaded,
1093 &osd->rx_undersize, &nsd->rx_undersize);
1094 i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
1095 pf->stat_offsets_loaded,
1096 &osd->rx_fragments, &nsd->rx_fragments);
1097 i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
1098 pf->stat_offsets_loaded,
1099 &osd->rx_oversize, &nsd->rx_oversize);
1100 i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
1101 pf->stat_offsets_loaded,
1102 &osd->rx_jabber, &nsd->rx_jabber);
1103
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001104 /* FDIR stats */
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04001105 i40e_stat_update32(hw,
1106 I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001107 pf->stat_offsets_loaded,
1108 &osd->fd_atr_match, &nsd->fd_atr_match);
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04001109 i40e_stat_update32(hw,
1110 I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001111 pf->stat_offsets_loaded,
1112 &osd->fd_sb_match, &nsd->fd_sb_match);
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -04001113 i40e_stat_update32(hw,
1114 I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)),
1115 pf->stat_offsets_loaded,
1116 &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match);
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001117
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001118 val = rd32(hw, I40E_PRTPM_EEE_STAT);
1119 nsd->tx_lpi_status =
1120 (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
1121 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
1122 nsd->rx_lpi_status =
1123 (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
1124 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
1125 i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
1126 pf->stat_offsets_loaded,
1127 &osd->tx_lpi_count, &nsd->tx_lpi_count);
1128 i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
1129 pf->stat_offsets_loaded,
1130 &osd->rx_lpi_count, &nsd->rx_lpi_count);
1131
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -04001132 if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
1133 !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED))
1134 nsd->fd_sb_status = true;
1135 else
1136 nsd->fd_sb_status = false;
1137
1138 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
1139 !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
1140 nsd->fd_atr_status = true;
1141 else
1142 nsd->fd_atr_status = false;
1143
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001144 pf->stat_offsets_loaded = true;
1145}
1146
1147/**
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001148 * i40e_update_stats - Update the various statistics counters.
1149 * @vsi: the VSI to be updated
1150 *
1151 * Update the various stats for this VSI and its related entities.
1152 **/
1153void i40e_update_stats(struct i40e_vsi *vsi)
1154{
1155 struct i40e_pf *pf = vsi->back;
1156
1157 if (vsi == pf->vsi[pf->lan_vsi])
1158 i40e_update_pf_stats(pf);
1159
1160 i40e_update_vsi_stats(vsi);
Vasu Dev38e00432014-08-01 13:27:03 -07001161#ifdef I40E_FCOE
1162 i40e_update_fcoe_stats(vsi);
1163#endif
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001164}
1165
1166/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001167 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1168 * @vsi: the VSI to be searched
1169 * @macaddr: the MAC address
1170 * @vlan: the vlan
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001171 * @is_vf: make sure its a VF filter, else doesn't matter
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001172 * @is_netdev: make sure its a netdev filter, else doesn't matter
1173 *
1174 * Returns ptr to the filter object or NULL
1175 **/
1176static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
1177 u8 *macaddr, s16 vlan,
1178 bool is_vf, bool is_netdev)
1179{
1180 struct i40e_mac_filter *f;
1181
1182 if (!vsi || !macaddr)
1183 return NULL;
1184
1185 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1186 if ((ether_addr_equal(macaddr, f->macaddr)) &&
1187 (vlan == f->vlan) &&
1188 (!is_vf || f->is_vf) &&
1189 (!is_netdev || f->is_netdev))
1190 return f;
1191 }
1192 return NULL;
1193}
1194
1195/**
1196 * i40e_find_mac - Find a mac addr in the macvlan filters list
1197 * @vsi: the VSI to be searched
1198 * @macaddr: the MAC address we are searching for
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001199 * @is_vf: make sure its a VF filter, else doesn't matter
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001200 * @is_netdev: make sure its a netdev filter, else doesn't matter
1201 *
1202 * Returns the first filter with the provided MAC address or NULL if
1203 * MAC address was not found
1204 **/
1205struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr,
1206 bool is_vf, bool is_netdev)
1207{
1208 struct i40e_mac_filter *f;
1209
1210 if (!vsi || !macaddr)
1211 return NULL;
1212
1213 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1214 if ((ether_addr_equal(macaddr, f->macaddr)) &&
1215 (!is_vf || f->is_vf) &&
1216 (!is_netdev || f->is_netdev))
1217 return f;
1218 }
1219 return NULL;
1220}
1221
1222/**
1223 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1224 * @vsi: the VSI to be searched
1225 *
1226 * Returns true if VSI is in vlan mode or false otherwise
1227 **/
1228bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
1229{
1230 struct i40e_mac_filter *f;
1231
1232 /* Only -1 for all the filters denotes not in vlan mode
1233 * so we have to go through all the list in order to make sure
1234 */
1235 list_for_each_entry(f, &vsi->mac_filter_list, list) {
Greg Rosed9b68f82015-07-23 16:54:31 -04001236 if (f->vlan >= 0 || vsi->info.pvid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001237 return true;
1238 }
1239
1240 return false;
1241}
1242
1243/**
1244 * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
1245 * @vsi: the VSI to be searched
1246 * @macaddr: the mac address to be filtered
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001247 * @is_vf: true if it is a VF
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001248 * @is_netdev: true if it is a netdev
1249 *
1250 * Goes through all the macvlan filters and adds a
1251 * macvlan filter for each unique vlan that already exists
1252 *
1253 * Returns first filter found on success, else NULL
1254 **/
1255struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr,
1256 bool is_vf, bool is_netdev)
1257{
1258 struct i40e_mac_filter *f;
1259
1260 list_for_each_entry(f, &vsi->mac_filter_list, list) {
Mitch Williamsecbb44e2015-07-10 19:35:56 -04001261 if (vsi->info.pvid)
1262 f->vlan = le16_to_cpu(vsi->info.pvid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001263 if (!i40e_find_filter(vsi, macaddr, f->vlan,
1264 is_vf, is_netdev)) {
1265 if (!i40e_add_filter(vsi, macaddr, f->vlan,
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08001266 is_vf, is_netdev))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001267 return NULL;
1268 }
1269 }
1270
1271 return list_first_entry_or_null(&vsi->mac_filter_list,
1272 struct i40e_mac_filter, list);
1273}
1274
1275/**
Mitch Williamsb36e9ab2015-11-19 11:34:16 -08001276 * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS
1277 * @vsi: the VSI to be searched
1278 * @macaddr: the mac address to be removed
1279 * @is_vf: true if it is a VF
1280 * @is_netdev: true if it is a netdev
1281 *
1282 * Removes a given MAC address from a VSI, regardless of VLAN
1283 *
1284 * Returns 0 for success, or error
1285 **/
1286int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, u8 *macaddr,
1287 bool is_vf, bool is_netdev)
1288{
1289 struct i40e_mac_filter *f = NULL;
1290 int changed = 0;
1291
1292 WARN(!spin_is_locked(&vsi->mac_filter_list_lock),
1293 "Missing mac_filter_list_lock\n");
1294 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1295 if ((ether_addr_equal(macaddr, f->macaddr)) &&
1296 (is_vf == f->is_vf) &&
1297 (is_netdev == f->is_netdev)) {
1298 f->counter--;
1299 f->changed = true;
1300 changed = 1;
1301 }
1302 }
1303 if (changed) {
1304 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1305 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1306 return 0;
1307 }
1308 return -ENOENT;
1309}
1310
1311/**
Greg Rose8c27d422014-05-22 06:31:56 +00001312 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1313 * @vsi: the PF Main VSI - inappropriate for any other VSI
1314 * @macaddr: the MAC address
Shannon Nelson30650cc2014-07-29 04:01:50 +00001315 *
1316 * Some older firmware configurations set up a default promiscuous VLAN
1317 * filter that needs to be removed.
Greg Rose8c27d422014-05-22 06:31:56 +00001318 **/
Shannon Nelson30650cc2014-07-29 04:01:50 +00001319static int i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
Greg Rose8c27d422014-05-22 06:31:56 +00001320{
1321 struct i40e_aqc_remove_macvlan_element_data element;
1322 struct i40e_pf *pf = vsi->back;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001323 i40e_status ret;
Greg Rose8c27d422014-05-22 06:31:56 +00001324
1325 /* Only appropriate for the PF main VSI */
1326 if (vsi->type != I40E_VSI_MAIN)
Shannon Nelson30650cc2014-07-29 04:01:50 +00001327 return -EINVAL;
Greg Rose8c27d422014-05-22 06:31:56 +00001328
Shannon Nelson30650cc2014-07-29 04:01:50 +00001329 memset(&element, 0, sizeof(element));
Greg Rose8c27d422014-05-22 06:31:56 +00001330 ether_addr_copy(element.mac_addr, macaddr);
1331 element.vlan_tag = 0;
1332 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
1333 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001334 ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1335 if (ret)
Shannon Nelson30650cc2014-07-29 04:01:50 +00001336 return -ENOENT;
1337
1338 return 0;
Greg Rose8c27d422014-05-22 06:31:56 +00001339}
1340
1341/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001342 * i40e_add_filter - Add a mac/vlan filter to the VSI
1343 * @vsi: the VSI to be searched
1344 * @macaddr: the MAC address
1345 * @vlan: the vlan
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001346 * @is_vf: make sure its a VF filter, else doesn't matter
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001347 * @is_netdev: make sure its a netdev filter, else doesn't matter
1348 *
1349 * Returns ptr to the filter object or NULL when no memory available.
Kiran Patil21659032015-09-30 14:09:03 -04001350 *
1351 * NOTE: This function is expected to be called with mac_filter_list_lock
1352 * being held.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001353 **/
1354struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
1355 u8 *macaddr, s16 vlan,
1356 bool is_vf, bool is_netdev)
1357{
1358 struct i40e_mac_filter *f;
1359
1360 if (!vsi || !macaddr)
1361 return NULL;
1362
1363 f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
1364 if (!f) {
1365 f = kzalloc(sizeof(*f), GFP_ATOMIC);
1366 if (!f)
1367 goto add_filter_out;
1368
Greg Rose9a173902014-05-22 06:32:02 +00001369 ether_addr_copy(f->macaddr, macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001370 f->vlan = vlan;
1371 f->changed = true;
1372
1373 INIT_LIST_HEAD(&f->list);
Kiran Patil04d5a212015-12-09 15:50:23 -08001374 list_add_tail(&f->list, &vsi->mac_filter_list);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001375 }
1376
1377 /* increment counter and add a new flag if needed */
1378 if (is_vf) {
1379 if (!f->is_vf) {
1380 f->is_vf = true;
1381 f->counter++;
1382 }
1383 } else if (is_netdev) {
1384 if (!f->is_netdev) {
1385 f->is_netdev = true;
1386 f->counter++;
1387 }
1388 } else {
1389 f->counter++;
1390 }
1391
1392 /* changed tells sync_filters_subtask to
1393 * push the filter down to the firmware
1394 */
1395 if (f->changed) {
1396 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1397 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1398 }
1399
1400add_filter_out:
1401 return f;
1402}
1403
1404/**
1405 * i40e_del_filter - Remove a mac/vlan filter from the VSI
1406 * @vsi: the VSI to be searched
1407 * @macaddr: the MAC address
1408 * @vlan: the vlan
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001409 * @is_vf: make sure it's a VF filter, else doesn't matter
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001410 * @is_netdev: make sure it's a netdev filter, else doesn't matter
Kiran Patil21659032015-09-30 14:09:03 -04001411 *
1412 * NOTE: This function is expected to be called with mac_filter_list_lock
1413 * being held.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001414 **/
1415void i40e_del_filter(struct i40e_vsi *vsi,
1416 u8 *macaddr, s16 vlan,
1417 bool is_vf, bool is_netdev)
1418{
1419 struct i40e_mac_filter *f;
1420
1421 if (!vsi || !macaddr)
1422 return;
1423
1424 f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
1425 if (!f || f->counter == 0)
1426 return;
1427
1428 if (is_vf) {
1429 if (f->is_vf) {
1430 f->is_vf = false;
1431 f->counter--;
1432 }
1433 } else if (is_netdev) {
1434 if (f->is_netdev) {
1435 f->is_netdev = false;
1436 f->counter--;
1437 }
1438 } else {
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001439 /* make sure we don't remove a filter in use by VF or netdev */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001440 int min_f = 0;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001441
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001442 min_f += (f->is_vf ? 1 : 0);
1443 min_f += (f->is_netdev ? 1 : 0);
1444
1445 if (f->counter > min_f)
1446 f->counter--;
1447 }
1448
1449 /* counter == 0 tells sync_filters_subtask to
1450 * remove the filter from the firmware's list
1451 */
1452 if (f->counter == 0) {
1453 f->changed = true;
1454 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1455 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1456 }
1457}
1458
1459/**
1460 * i40e_set_mac - NDO callback to set mac address
1461 * @netdev: network interface device structure
1462 * @p: pointer to an address structure
1463 *
1464 * Returns 0 on success, negative on failure
1465 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001466#ifdef I40E_FCOE
1467int i40e_set_mac(struct net_device *netdev, void *p)
1468#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001469static int i40e_set_mac(struct net_device *netdev, void *p)
Vasu Dev38e00432014-08-01 13:27:03 -07001470#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001471{
1472 struct i40e_netdev_priv *np = netdev_priv(netdev);
1473 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson30650cc2014-07-29 04:01:50 +00001474 struct i40e_pf *pf = vsi->back;
1475 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001476 struct sockaddr *addr = p;
1477 struct i40e_mac_filter *f;
1478
1479 if (!is_valid_ether_addr(addr->sa_data))
1480 return -EADDRNOTAVAIL;
1481
Shannon Nelson30650cc2014-07-29 04:01:50 +00001482 if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
1483 netdev_info(netdev, "already using mac address %pM\n",
1484 addr->sa_data);
1485 return 0;
1486 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001487
Anjali Singhai Jain80f64282013-11-28 06:39:47 +00001488 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
1489 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
1490 return -EADDRNOTAVAIL;
1491
Shannon Nelson30650cc2014-07-29 04:01:50 +00001492 if (ether_addr_equal(hw->mac.addr, addr->sa_data))
1493 netdev_info(netdev, "returning to hw mac address %pM\n",
1494 hw->mac.addr);
1495 else
1496 netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
1497
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001498 if (vsi->type == I40E_VSI_MAIN) {
1499 i40e_status ret;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001500
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001501 ret = i40e_aq_mac_address_write(&vsi->back->hw,
Shannon Nelsoncc412222014-06-04 01:23:21 +00001502 I40E_AQC_WRITE_TYPE_LAA_WOL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001503 addr->sa_data, NULL);
1504 if (ret) {
1505 netdev_info(netdev,
1506 "Addr change for Main VSI failed: %d\n",
1507 ret);
1508 return -EADDRNOTAVAIL;
1509 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001510 }
1511
Shannon Nelson30650cc2014-07-29 04:01:50 +00001512 if (ether_addr_equal(netdev->dev_addr, hw->mac.addr)) {
1513 struct i40e_aqc_remove_macvlan_element_data element;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001514
Shannon Nelson30650cc2014-07-29 04:01:50 +00001515 memset(&element, 0, sizeof(element));
1516 ether_addr_copy(element.mac_addr, netdev->dev_addr);
1517 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
1518 i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1519 } else {
Kiran Patil21659032015-09-30 14:09:03 -04001520 spin_lock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson6c8ad1b2014-06-04 01:23:22 +00001521 i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
1522 false, false);
Kiran Patil21659032015-09-30 14:09:03 -04001523 spin_unlock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson6c8ad1b2014-06-04 01:23:22 +00001524 }
1525
Shannon Nelson30650cc2014-07-29 04:01:50 +00001526 if (ether_addr_equal(addr->sa_data, hw->mac.addr)) {
1527 struct i40e_aqc_add_macvlan_element_data element;
1528
1529 memset(&element, 0, sizeof(element));
1530 ether_addr_copy(element.mac_addr, hw->mac.addr);
1531 element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
1532 i40e_aq_add_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1533 } else {
Kiran Patil21659032015-09-30 14:09:03 -04001534 spin_lock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson30650cc2014-07-29 04:01:50 +00001535 f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY,
1536 false, false);
1537 if (f)
1538 f->is_laa = true;
Kiran Patil21659032015-09-30 14:09:03 -04001539 spin_unlock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson30650cc2014-07-29 04:01:50 +00001540 }
1541
Shannon Nelson30650cc2014-07-29 04:01:50 +00001542 ether_addr_copy(netdev->dev_addr, addr->sa_data);
Mitch Williamsea02e902015-11-09 15:35:50 -08001543
Jesse Brandeburgc53934c2016-01-04 10:33:06 -08001544 /* schedule our worker thread which will take care of
1545 * applying the new filter changes
1546 */
1547 i40e_service_event_schedule(vsi->back);
1548 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001549}
1550
1551/**
1552 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1553 * @vsi: the VSI being setup
1554 * @ctxt: VSI context structure
1555 * @enabled_tc: Enabled TCs bitmap
1556 * @is_add: True if called before Add VSI
1557 *
1558 * Setup VSI queue mapping for enabled traffic classes.
1559 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001560#ifdef I40E_FCOE
1561void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1562 struct i40e_vsi_context *ctxt,
1563 u8 enabled_tc,
1564 bool is_add)
1565#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001566static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1567 struct i40e_vsi_context *ctxt,
1568 u8 enabled_tc,
1569 bool is_add)
Vasu Dev38e00432014-08-01 13:27:03 -07001570#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001571{
1572 struct i40e_pf *pf = vsi->back;
1573 u16 sections = 0;
1574 u8 netdev_tc = 0;
1575 u16 numtc = 0;
1576 u16 qcount;
1577 u8 offset;
1578 u16 qmap;
1579 int i;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001580 u16 num_tc_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001581
1582 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
1583 offset = 0;
1584
1585 if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
1586 /* Find numtc from enabled TC bitmap */
1587 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08001588 if (enabled_tc & BIT(i)) /* TC is enabled */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001589 numtc++;
1590 }
1591 if (!numtc) {
1592 dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
1593 numtc = 1;
1594 }
1595 } else {
1596 /* At least TC0 is enabled in case of non-DCB case */
1597 numtc = 1;
1598 }
1599
1600 vsi->tc_config.numtc = numtc;
1601 vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001602 /* Number of queues per enabled TC */
Anjali Singhai7f9ff472015-02-21 06:43:19 +00001603 /* In MFP case we can have a much lower count of MSIx
1604 * vectors available and so we need to lower the used
1605 * q count.
1606 */
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04001607 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
1608 qcount = min_t(int, vsi->alloc_queue_pairs, pf->num_lan_msix);
1609 else
1610 qcount = vsi->alloc_queue_pairs;
Anjali Singhai7f9ff472015-02-21 06:43:19 +00001611 num_tc_qps = qcount / numtc;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001612 num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001613
1614 /* Setup queue offset/count for all TCs for given VSI */
1615 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1616 /* See if the given TC is enabled for the given VSI */
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08001617 if (vsi->tc_config.enabled_tc & BIT(i)) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001618 /* TC is enabled */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001619 int pow, num_qps;
1620
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001621 switch (vsi->type) {
1622 case I40E_VSI_MAIN:
Helin Zhangacd65442015-10-26 19:44:28 -04001623 qcount = min_t(int, pf->alloc_rss_size,
1624 num_tc_qps);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001625 break;
Vasu Dev38e00432014-08-01 13:27:03 -07001626#ifdef I40E_FCOE
1627 case I40E_VSI_FCOE:
1628 qcount = num_tc_qps;
1629 break;
1630#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001631 case I40E_VSI_FDIR:
1632 case I40E_VSI_SRIOV:
1633 case I40E_VSI_VMDQ2:
1634 default:
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001635 qcount = num_tc_qps;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001636 WARN_ON(i != 0);
1637 break;
1638 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001639 vsi->tc_config.tc_info[i].qoffset = offset;
1640 vsi->tc_config.tc_info[i].qcount = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001641
Shannon Nelson1e200e42015-02-27 09:15:24 +00001642 /* find the next higher power-of-2 of num queue pairs */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001643 num_qps = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001644 pow = 0;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001645 while (num_qps && (BIT_ULL(pow) < qcount)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001646 pow++;
1647 num_qps >>= 1;
1648 }
1649
1650 vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
1651 qmap =
1652 (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
1653 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
1654
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001655 offset += qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001656 } else {
1657 /* TC is not enabled so set the offset to
1658 * default queue and allocate one queue
1659 * for the given TC.
1660 */
1661 vsi->tc_config.tc_info[i].qoffset = 0;
1662 vsi->tc_config.tc_info[i].qcount = 1;
1663 vsi->tc_config.tc_info[i].netdev_tc = 0;
1664
1665 qmap = 0;
1666 }
1667 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
1668 }
1669
1670 /* Set actual Tx/Rx queue pairs */
1671 vsi->num_queue_pairs = offset;
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00001672 if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
1673 if (vsi->req_queue_pairs > 0)
1674 vsi->num_queue_pairs = vsi->req_queue_pairs;
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04001675 else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00001676 vsi->num_queue_pairs = pf->num_lan_msix;
1677 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001678
1679 /* Scheduler section valid can only be set for ADD VSI */
1680 if (is_add) {
1681 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
1682
1683 ctxt->info.up_enable_bits = enabled_tc;
1684 }
1685 if (vsi->type == I40E_VSI_SRIOV) {
1686 ctxt->info.mapping_flags |=
1687 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
1688 for (i = 0; i < vsi->num_queue_pairs; i++)
1689 ctxt->info.queue_mapping[i] =
1690 cpu_to_le16(vsi->base_queue + i);
1691 } else {
1692 ctxt->info.mapping_flags |=
1693 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
1694 ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
1695 }
1696 ctxt->info.valid_sections |= cpu_to_le16(sections);
1697}
1698
1699/**
1700 * i40e_set_rx_mode - NDO callback to set the netdev filters
1701 * @netdev: network interface device structure
1702 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001703#ifdef I40E_FCOE
1704void i40e_set_rx_mode(struct net_device *netdev)
1705#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001706static void i40e_set_rx_mode(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -07001707#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001708{
1709 struct i40e_netdev_priv *np = netdev_priv(netdev);
1710 struct i40e_mac_filter *f, *ftmp;
1711 struct i40e_vsi *vsi = np->vsi;
1712 struct netdev_hw_addr *uca;
1713 struct netdev_hw_addr *mca;
1714 struct netdev_hw_addr *ha;
1715
Kiran Patil21659032015-09-30 14:09:03 -04001716 spin_lock_bh(&vsi->mac_filter_list_lock);
1717
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001718 /* add addr if not already in the filter list */
1719 netdev_for_each_uc_addr(uca, netdev) {
1720 if (!i40e_find_mac(vsi, uca->addr, false, true)) {
1721 if (i40e_is_vsi_in_vlan(vsi))
1722 i40e_put_mac_in_vlan(vsi, uca->addr,
1723 false, true);
1724 else
1725 i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY,
1726 false, true);
1727 }
1728 }
1729
1730 netdev_for_each_mc_addr(mca, netdev) {
1731 if (!i40e_find_mac(vsi, mca->addr, false, true)) {
1732 if (i40e_is_vsi_in_vlan(vsi))
1733 i40e_put_mac_in_vlan(vsi, mca->addr,
1734 false, true);
1735 else
1736 i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY,
1737 false, true);
1738 }
1739 }
1740
1741 /* remove filter if not in netdev list */
1742 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001743
1744 if (!f->is_netdev)
1745 continue;
1746
Shannon Nelson2f41f332015-08-26 15:14:20 -04001747 netdev_for_each_mc_addr(mca, netdev)
1748 if (ether_addr_equal(mca->addr, f->macaddr))
1749 goto bottom_of_search_loop;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001750
Shannon Nelson2f41f332015-08-26 15:14:20 -04001751 netdev_for_each_uc_addr(uca, netdev)
1752 if (ether_addr_equal(uca->addr, f->macaddr))
1753 goto bottom_of_search_loop;
1754
1755 for_each_dev_addr(netdev, ha)
1756 if (ether_addr_equal(ha->addr, f->macaddr))
1757 goto bottom_of_search_loop;
1758
1759 /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
1760 i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true);
1761
1762bottom_of_search_loop:
1763 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001764 }
Kiran Patil21659032015-09-30 14:09:03 -04001765 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001766
1767 /* check for other flag changes */
1768 if (vsi->current_netdev_flags != vsi->netdev->flags) {
1769 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1770 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1771 }
Jesse Brandeburgc53934c2016-01-04 10:33:06 -08001772
1773 /* schedule our worker thread which will take care of
1774 * applying the new filter changes
1775 */
1776 i40e_service_event_schedule(vsi->back);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001777}
1778
1779/**
Kiran Patil21659032015-09-30 14:09:03 -04001780 * i40e_mac_filter_entry_clone - Clones a MAC filter entry
1781 * @src: source MAC filter entry to be clones
1782 *
1783 * Returns the pointer to newly cloned MAC filter entry or NULL
1784 * in case of error
1785 **/
1786static struct i40e_mac_filter *i40e_mac_filter_entry_clone(
1787 struct i40e_mac_filter *src)
1788{
1789 struct i40e_mac_filter *f;
1790
1791 f = kzalloc(sizeof(*f), GFP_ATOMIC);
1792 if (!f)
1793 return NULL;
1794 *f = *src;
1795
1796 INIT_LIST_HEAD(&f->list);
1797
1798 return f;
1799}
1800
1801/**
1802 * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
1803 * @vsi: pointer to vsi struct
1804 * @from: Pointer to list which contains MAC filter entries - changes to
1805 * those entries needs to be undone.
1806 *
1807 * MAC filter entries from list were slated to be removed from device.
1808 **/
1809static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
1810 struct list_head *from)
1811{
1812 struct i40e_mac_filter *f, *ftmp;
1813
1814 list_for_each_entry_safe(f, ftmp, from, list) {
1815 f->changed = true;
1816 /* Move the element back into MAC filter list*/
1817 list_move_tail(&f->list, &vsi->mac_filter_list);
1818 }
1819}
1820
1821/**
1822 * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
1823 * @vsi: pointer to vsi struct
1824 *
1825 * MAC filter entries from list were slated to be added from device.
1826 **/
1827static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi)
1828{
1829 struct i40e_mac_filter *f, *ftmp;
1830
1831 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1832 if (!f->changed && f->counter)
1833 f->changed = true;
1834 }
1835}
1836
1837/**
1838 * i40e_cleanup_add_list - Deletes the element from add list and release
1839 * memory
1840 * @add_list: Pointer to list which contains MAC filter entries
1841 **/
1842static void i40e_cleanup_add_list(struct list_head *add_list)
1843{
1844 struct i40e_mac_filter *f, *ftmp;
1845
1846 list_for_each_entry_safe(f, ftmp, add_list, list) {
1847 list_del(&f->list);
1848 kfree(f);
1849 }
1850}
1851
1852/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001853 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1854 * @vsi: ptr to the VSI
1855 *
1856 * Push any outstanding VSI filter changes through the AdminQ.
1857 *
1858 * Returns 0 or error value
1859 **/
Jesse Brandeburg17652c62015-11-05 17:01:02 -08001860int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001861{
Kiran Patil21659032015-09-30 14:09:03 -04001862 struct list_head tmp_del_list, tmp_add_list;
1863 struct i40e_mac_filter *f, *ftmp, *fclone;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001864 bool promisc_forced_on = false;
1865 bool add_happened = false;
1866 int filter_list_len = 0;
1867 u32 changed_flags = 0;
Mitch Williamsea02e902015-11-09 15:35:50 -08001868 i40e_status aq_ret = 0;
Kiran Patil21659032015-09-30 14:09:03 -04001869 bool err_cond = false;
Mitch Williamsea02e902015-11-09 15:35:50 -08001870 int retval = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001871 struct i40e_pf *pf;
1872 int num_add = 0;
1873 int num_del = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001874 int aq_err = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001875 u16 cmd_flags;
1876
1877 /* empty array typed pointers, kcalloc later */
1878 struct i40e_aqc_add_macvlan_element_data *add_list;
1879 struct i40e_aqc_remove_macvlan_element_data *del_list;
1880
1881 while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
1882 usleep_range(1000, 2000);
1883 pf = vsi->back;
1884
1885 if (vsi->netdev) {
1886 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
1887 vsi->current_netdev_flags = vsi->netdev->flags;
1888 }
1889
Kiran Patil21659032015-09-30 14:09:03 -04001890 INIT_LIST_HEAD(&tmp_del_list);
1891 INIT_LIST_HEAD(&tmp_add_list);
1892
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001893 if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
1894 vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
1895
Kiran Patil21659032015-09-30 14:09:03 -04001896 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001897 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1898 if (!f->changed)
1899 continue;
1900
1901 if (f->counter != 0)
1902 continue;
1903 f->changed = false;
Kiran Patil21659032015-09-30 14:09:03 -04001904
1905 /* Move the element into temporary del_list */
1906 list_move_tail(&f->list, &tmp_del_list);
1907 }
1908
1909 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1910 if (!f->changed)
1911 continue;
1912
1913 if (f->counter == 0)
1914 continue;
1915 f->changed = false;
1916
1917 /* Clone MAC filter entry and add into temporary list */
1918 fclone = i40e_mac_filter_entry_clone(f);
1919 if (!fclone) {
1920 err_cond = true;
1921 break;
1922 }
1923 list_add_tail(&fclone->list, &tmp_add_list);
1924 }
1925
1926 /* if failed to clone MAC filter entry - undo */
1927 if (err_cond) {
1928 i40e_undo_del_filter_entries(vsi, &tmp_del_list);
1929 i40e_undo_add_filter_entries(vsi);
1930 }
1931 spin_unlock_bh(&vsi->mac_filter_list_lock);
1932
Mitch Williamsea02e902015-11-09 15:35:50 -08001933 if (err_cond) {
Kiran Patil21659032015-09-30 14:09:03 -04001934 i40e_cleanup_add_list(&tmp_add_list);
Mitch Williamsea02e902015-11-09 15:35:50 -08001935 retval = -ENOMEM;
1936 goto out;
1937 }
Kiran Patil21659032015-09-30 14:09:03 -04001938 }
1939
1940 /* Now process 'del_list' outside the lock */
1941 if (!list_empty(&tmp_del_list)) {
Shannon Nelsonf1199992015-11-19 11:34:23 -08001942 int del_list_size;
1943
Kiran Patil21659032015-09-30 14:09:03 -04001944 filter_list_len = pf->hw.aq.asq_buf_size /
1945 sizeof(struct i40e_aqc_remove_macvlan_element_data);
Shannon Nelsonf1199992015-11-19 11:34:23 -08001946 del_list_size = filter_list_len *
1947 sizeof(struct i40e_aqc_remove_macvlan_element_data);
Jesse Brandeburg38c3cec2016-01-04 10:33:05 -08001948 del_list = kzalloc(del_list_size, GFP_ATOMIC);
Kiran Patil21659032015-09-30 14:09:03 -04001949 if (!del_list) {
1950 i40e_cleanup_add_list(&tmp_add_list);
1951
1952 /* Undo VSI's MAC filter entry element updates */
1953 spin_lock_bh(&vsi->mac_filter_list_lock);
1954 i40e_undo_del_filter_entries(vsi, &tmp_del_list);
1955 i40e_undo_add_filter_entries(vsi);
1956 spin_unlock_bh(&vsi->mac_filter_list_lock);
Mitch Williamsea02e902015-11-09 15:35:50 -08001957 retval = -ENOMEM;
1958 goto out;
Kiran Patil21659032015-09-30 14:09:03 -04001959 }
1960
1961 list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001962 cmd_flags = 0;
1963
1964 /* add to delete list */
Greg Rose9a173902014-05-22 06:32:02 +00001965 ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001966 del_list[num_del].vlan_tag =
1967 cpu_to_le16((u16)(f->vlan ==
1968 I40E_VLAN_ANY ? 0 : f->vlan));
1969
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001970 cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
1971 del_list[num_del].flags = cmd_flags;
1972 num_del++;
1973
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001974 /* flush a full buffer */
1975 if (num_del == filter_list_len) {
Mitch Williamsea02e902015-11-09 15:35:50 -08001976 aq_ret = i40e_aq_remove_macvlan(&pf->hw,
1977 vsi->seid,
1978 del_list,
1979 num_del,
1980 NULL);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001981 aq_err = pf->hw.aq.asq_last_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001982 num_del = 0;
Shannon Nelsonf1199992015-11-19 11:34:23 -08001983 memset(del_list, 0, del_list_size);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001984
Mitch Williamsea02e902015-11-09 15:35:50 -08001985 if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) {
1986 retval = -EIO;
Kiran Patil21659032015-09-30 14:09:03 -04001987 dev_err(&pf->pdev->dev,
1988 "ignoring delete macvlan error, err %s, aq_err %s while flushing a full buffer\n",
Mitch Williamsea02e902015-11-09 15:35:50 -08001989 i40e_stat_str(&pf->hw, aq_ret),
Kiran Patil21659032015-09-30 14:09:03 -04001990 i40e_aq_str(&pf->hw, aq_err));
Mitch Williamsea02e902015-11-09 15:35:50 -08001991 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001992 }
Kiran Patil21659032015-09-30 14:09:03 -04001993 /* Release memory for MAC filter entries which were
1994 * synced up with HW.
1995 */
1996 list_del(&f->list);
1997 kfree(f);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001998 }
Kiran Patil21659032015-09-30 14:09:03 -04001999
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002000 if (num_del) {
Mitch Williamsea02e902015-11-09 15:35:50 -08002001 aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid,
2002 del_list, num_del,
2003 NULL);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002004 aq_err = pf->hw.aq.asq_last_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002005 num_del = 0;
2006
Mitch Williamsea02e902015-11-09 15:35:50 -08002007 if (aq_ret && aq_err != I40E_AQ_RC_ENOENT)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002008 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002009 "ignoring delete macvlan error, err %s aq_err %s\n",
Mitch Williamsea02e902015-11-09 15:35:50 -08002010 i40e_stat_str(&pf->hw, aq_ret),
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002011 i40e_aq_str(&pf->hw, aq_err));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002012 }
2013
2014 kfree(del_list);
2015 del_list = NULL;
Kiran Patil21659032015-09-30 14:09:03 -04002016 }
2017
2018 if (!list_empty(&tmp_add_list)) {
Shannon Nelsonf1199992015-11-19 11:34:23 -08002019 int add_list_size;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002020
2021 /* do all the adds now */
2022 filter_list_len = pf->hw.aq.asq_buf_size /
2023 sizeof(struct i40e_aqc_add_macvlan_element_data),
Shannon Nelsonf1199992015-11-19 11:34:23 -08002024 add_list_size = filter_list_len *
2025 sizeof(struct i40e_aqc_add_macvlan_element_data);
Jesse Brandeburg38c3cec2016-01-04 10:33:05 -08002026 add_list = kzalloc(add_list_size, GFP_ATOMIC);
Kiran Patil21659032015-09-30 14:09:03 -04002027 if (!add_list) {
2028 /* Purge element from temporary lists */
2029 i40e_cleanup_add_list(&tmp_add_list);
2030
2031 /* Undo add filter entries from VSI MAC filter list */
2032 spin_lock_bh(&vsi->mac_filter_list_lock);
2033 i40e_undo_add_filter_entries(vsi);
2034 spin_unlock_bh(&vsi->mac_filter_list_lock);
Mitch Williamsea02e902015-11-09 15:35:50 -08002035 retval = -ENOMEM;
2036 goto out;
Kiran Patil21659032015-09-30 14:09:03 -04002037 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002038
Kiran Patil21659032015-09-30 14:09:03 -04002039 list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002040
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002041 add_happened = true;
2042 cmd_flags = 0;
2043
2044 /* add to add array */
Greg Rose9a173902014-05-22 06:32:02 +00002045 ether_addr_copy(add_list[num_add].mac_addr, f->macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002046 add_list[num_add].vlan_tag =
2047 cpu_to_le16(
2048 (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan));
2049 add_list[num_add].queue_number = 0;
2050
2051 cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002052 add_list[num_add].flags = cpu_to_le16(cmd_flags);
2053 num_add++;
2054
2055 /* flush a full buffer */
2056 if (num_add == filter_list_len) {
Mitch Williamsea02e902015-11-09 15:35:50 -08002057 aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
2058 add_list, num_add,
2059 NULL);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002060 aq_err = pf->hw.aq.asq_last_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002061 num_add = 0;
2062
Mitch Williamsea02e902015-11-09 15:35:50 -08002063 if (aq_ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002064 break;
Shannon Nelsonf1199992015-11-19 11:34:23 -08002065 memset(add_list, 0, add_list_size);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002066 }
Kiran Patil21659032015-09-30 14:09:03 -04002067 /* Entries from tmp_add_list were cloned from MAC
2068 * filter list, hence clean those cloned entries
2069 */
2070 list_del(&f->list);
2071 kfree(f);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002072 }
Kiran Patil21659032015-09-30 14:09:03 -04002073
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002074 if (num_add) {
Mitch Williamsea02e902015-11-09 15:35:50 -08002075 aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
2076 add_list, num_add, NULL);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002077 aq_err = pf->hw.aq.asq_last_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002078 num_add = 0;
2079 }
2080 kfree(add_list);
2081 add_list = NULL;
2082
Mitch Williamsea02e902015-11-09 15:35:50 -08002083 if (add_happened && aq_ret && aq_err != I40E_AQ_RC_EINVAL) {
2084 retval = i40e_aq_rc_to_posix(aq_ret, aq_err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002085 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002086 "add filter failed, err %s aq_err %s\n",
Mitch Williamsea02e902015-11-09 15:35:50 -08002087 i40e_stat_str(&pf->hw, aq_ret),
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002088 i40e_aq_str(&pf->hw, aq_err));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002089 if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) &&
2090 !test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2091 &vsi->state)) {
2092 promisc_forced_on = true;
2093 set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2094 &vsi->state);
2095 dev_info(&pf->pdev->dev, "promiscuous mode forced on\n");
2096 }
2097 }
2098 }
2099
2100 /* check for changes in promiscuous modes */
2101 if (changed_flags & IFF_ALLMULTI) {
2102 bool cur_multipromisc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002103
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002104 cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
Mitch Williamsea02e902015-11-09 15:35:50 -08002105 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
2106 vsi->seid,
2107 cur_multipromisc,
2108 NULL);
2109 if (aq_ret) {
2110 retval = i40e_aq_rc_to_posix(aq_ret,
2111 pf->hw.aq.asq_last_status);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002112 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002113 "set multi promisc failed, err %s aq_err %s\n",
Mitch Williamsea02e902015-11-09 15:35:50 -08002114 i40e_stat_str(&pf->hw, aq_ret),
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002115 i40e_aq_str(&pf->hw,
2116 pf->hw.aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002117 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002118 }
2119 if ((changed_flags & IFF_PROMISC) || promisc_forced_on) {
2120 bool cur_promisc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002121
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002122 cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
2123 test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2124 &vsi->state));
Anjali Singhai Jain6784ed52016-01-15 14:33:13 -08002125 if ((vsi->type == I40E_VSI_MAIN) &&
2126 (pf->lan_veb != I40E_NO_VEB) &&
2127 !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002128 /* set defport ON for Main VSI instead of true promisc
2129 * this way we will get all unicast/multicast and VLAN
2130 * promisc behavior but will not get VF or VMDq traffic
2131 * replicated on the Main VSI.
2132 */
2133 if (pf->cur_promisc != cur_promisc) {
2134 pf->cur_promisc = cur_promisc;
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002135 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002136 }
2137 } else {
Mitch Williamsea02e902015-11-09 15:35:50 -08002138 aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002139 &vsi->back->hw,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002140 vsi->seid,
2141 cur_promisc, NULL);
Mitch Williamsea02e902015-11-09 15:35:50 -08002142 if (aq_ret) {
2143 retval =
2144 i40e_aq_rc_to_posix(aq_ret,
2145 pf->hw.aq.asq_last_status);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002146 dev_info(&pf->pdev->dev,
2147 "set unicast promisc failed, err %d, aq_err %d\n",
Mitch Williamsea02e902015-11-09 15:35:50 -08002148 aq_ret, pf->hw.aq.asq_last_status);
2149 }
2150 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002151 &vsi->back->hw,
2152 vsi->seid,
2153 cur_promisc, NULL);
Mitch Williamsea02e902015-11-09 15:35:50 -08002154 if (aq_ret) {
2155 retval =
2156 i40e_aq_rc_to_posix(aq_ret,
2157 pf->hw.aq.asq_last_status);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002158 dev_info(&pf->pdev->dev,
2159 "set multicast promisc failed, err %d, aq_err %d\n",
Mitch Williamsea02e902015-11-09 15:35:50 -08002160 aq_ret, pf->hw.aq.asq_last_status);
2161 }
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002162 }
Mitch Williamsea02e902015-11-09 15:35:50 -08002163 aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
2164 vsi->seid,
2165 cur_promisc, NULL);
2166 if (aq_ret) {
2167 retval = i40e_aq_rc_to_posix(aq_ret,
2168 pf->hw.aq.asq_last_status);
Greg Rose1a103702013-11-28 06:42:39 +00002169 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002170 "set brdcast promisc failed, err %s, aq_err %s\n",
Mitch Williamsea02e902015-11-09 15:35:50 -08002171 i40e_stat_str(&pf->hw, aq_ret),
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002172 i40e_aq_str(&pf->hw,
2173 pf->hw.aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002174 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002175 }
Mitch Williamsea02e902015-11-09 15:35:50 -08002176out:
Jesse Brandeburg2818ccd2016-01-13 16:51:38 -08002177 /* if something went wrong then set the changed flag so we try again */
2178 if (retval)
2179 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
2180
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002181 clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
Mitch Williamsea02e902015-11-09 15:35:50 -08002182 return retval;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002183}
2184
2185/**
2186 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2187 * @pf: board private structure
2188 **/
2189static void i40e_sync_filters_subtask(struct i40e_pf *pf)
2190{
2191 int v;
2192
2193 if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
2194 return;
2195 pf->flags &= ~I40E_FLAG_FILTER_SYNC;
2196
Mitch Williams505682c2014-05-20 08:01:37 +00002197 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002198 if (pf->vsi[v] &&
Jesse Brandeburg17652c62015-11-05 17:01:02 -08002199 (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
2200 int ret = i40e_sync_vsi_filters(pf->vsi[v]);
2201
2202 if (ret) {
2203 /* come back and try again later */
2204 pf->flags |= I40E_FLAG_FILTER_SYNC;
2205 break;
2206 }
2207 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002208 }
2209}
2210
2211/**
2212 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2213 * @netdev: network interface device structure
2214 * @new_mtu: new value for maximum frame size
2215 *
2216 * Returns 0 on success, negative on failure
2217 **/
2218static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
2219{
2220 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg61a46a42014-04-23 04:50:05 +00002221 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002222 struct i40e_vsi *vsi = np->vsi;
2223
2224 /* MTU < 68 is an error and causes problems on some kernels */
2225 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
2226 return -EINVAL;
2227
2228 netdev_info(netdev, "changing MTU from %d to %d\n",
2229 netdev->mtu, new_mtu);
2230 netdev->mtu = new_mtu;
2231 if (netif_running(netdev))
2232 i40e_vsi_reinit_locked(vsi);
2233
2234 return 0;
2235}
2236
2237/**
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002238 * i40e_ioctl - Access the hwtstamp interface
2239 * @netdev: network interface device structure
2240 * @ifr: interface request data
2241 * @cmd: ioctl command
2242 **/
2243int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2244{
2245 struct i40e_netdev_priv *np = netdev_priv(netdev);
2246 struct i40e_pf *pf = np->vsi->back;
2247
2248 switch (cmd) {
2249 case SIOCGHWTSTAMP:
2250 return i40e_ptp_get_ts_config(pf, ifr);
2251 case SIOCSHWTSTAMP:
2252 return i40e_ptp_set_ts_config(pf, ifr);
2253 default:
2254 return -EOPNOTSUPP;
2255 }
2256}
2257
2258/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002259 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2260 * @vsi: the vsi being adjusted
2261 **/
2262void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
2263{
2264 struct i40e_vsi_context ctxt;
2265 i40e_status ret;
2266
2267 if ((vsi->info.valid_sections &
2268 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2269 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
2270 return; /* already enabled */
2271
2272 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2273 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2274 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
2275
2276 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002277 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002278 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2279 if (ret) {
2280 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002281 "update vlan stripping failed, err %s aq_err %s\n",
2282 i40e_stat_str(&vsi->back->hw, ret),
2283 i40e_aq_str(&vsi->back->hw,
2284 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002285 }
2286}
2287
2288/**
2289 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2290 * @vsi: the vsi being adjusted
2291 **/
2292void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
2293{
2294 struct i40e_vsi_context ctxt;
2295 i40e_status ret;
2296
2297 if ((vsi->info.valid_sections &
2298 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2299 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
2300 I40E_AQ_VSI_PVLAN_EMOD_MASK))
2301 return; /* already disabled */
2302
2303 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2304 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2305 I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
2306
2307 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002308 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002309 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2310 if (ret) {
2311 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002312 "update vlan stripping failed, err %s aq_err %s\n",
2313 i40e_stat_str(&vsi->back->hw, ret),
2314 i40e_aq_str(&vsi->back->hw,
2315 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002316 }
2317}
2318
2319/**
2320 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2321 * @netdev: network interface to be adjusted
2322 * @features: netdev features to test if VLAN offload is enabled or not
2323 **/
2324static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
2325{
2326 struct i40e_netdev_priv *np = netdev_priv(netdev);
2327 struct i40e_vsi *vsi = np->vsi;
2328
2329 if (features & NETIF_F_HW_VLAN_CTAG_RX)
2330 i40e_vlan_stripping_enable(vsi);
2331 else
2332 i40e_vlan_stripping_disable(vsi);
2333}
2334
2335/**
2336 * i40e_vsi_add_vlan - Add vsi membership for given vlan
2337 * @vsi: the vsi being configured
2338 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2339 **/
2340int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
2341{
2342 struct i40e_mac_filter *f, *add_f;
2343 bool is_netdev, is_vf;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002344
2345 is_vf = (vsi->type == I40E_VSI_SRIOV);
2346 is_netdev = !!(vsi->netdev);
2347
Kiran Patil21659032015-09-30 14:09:03 -04002348 /* Locked once because all functions invoked below iterates list*/
2349 spin_lock_bh(&vsi->mac_filter_list_lock);
2350
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002351 if (is_netdev) {
2352 add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid,
2353 is_vf, is_netdev);
2354 if (!add_f) {
2355 dev_info(&vsi->back->pdev->dev,
2356 "Could not add vlan filter %d for %pM\n",
2357 vid, vsi->netdev->dev_addr);
Kiran Patil21659032015-09-30 14:09:03 -04002358 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002359 return -ENOMEM;
2360 }
2361 }
2362
2363 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2364 add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
2365 if (!add_f) {
2366 dev_info(&vsi->back->pdev->dev,
2367 "Could not add vlan filter %d for %pM\n",
2368 vid, f->macaddr);
Kiran Patil21659032015-09-30 14:09:03 -04002369 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002370 return -ENOMEM;
2371 }
2372 }
2373
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002374 /* Now if we add a vlan tag, make sure to check if it is the first
2375 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
2376 * with 0, so we now accept untagged and specified tagged traffic
2377 * (and not any taged and untagged)
2378 */
2379 if (vid > 0) {
2380 if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr,
2381 I40E_VLAN_ANY,
2382 is_vf, is_netdev)) {
2383 i40e_del_filter(vsi, vsi->netdev->dev_addr,
2384 I40E_VLAN_ANY, is_vf, is_netdev);
2385 add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0,
2386 is_vf, is_netdev);
2387 if (!add_f) {
2388 dev_info(&vsi->back->pdev->dev,
2389 "Could not add filter 0 for %pM\n",
2390 vsi->netdev->dev_addr);
Kiran Patil21659032015-09-30 14:09:03 -04002391 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002392 return -ENOMEM;
2393 }
2394 }
Greg Rose8d82a7c2014-01-13 16:13:04 -08002395 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002396
Greg Rose8d82a7c2014-01-13 16:13:04 -08002397 /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
2398 if (vid > 0 && !vsi->info.pvid) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002399 list_for_each_entry(f, &vsi->mac_filter_list, list) {
Kiran Patil21659032015-09-30 14:09:03 -04002400 if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY,
2401 is_vf, is_netdev))
2402 continue;
2403 i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY,
2404 is_vf, is_netdev);
2405 add_f = i40e_add_filter(vsi, f->macaddr,
2406 0, is_vf, is_netdev);
2407 if (!add_f) {
2408 dev_info(&vsi->back->pdev->dev,
2409 "Could not add filter 0 for %pM\n",
2410 f->macaddr);
2411 spin_unlock_bh(&vsi->mac_filter_list_lock);
2412 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002413 }
2414 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002415 }
2416
Kiran Patil21659032015-09-30 14:09:03 -04002417 spin_unlock_bh(&vsi->mac_filter_list_lock);
2418
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002419 /* schedule our worker thread which will take care of
2420 * applying the new filter changes
2421 */
2422 i40e_service_event_schedule(vsi->back);
2423 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002424}
2425
2426/**
2427 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
2428 * @vsi: the vsi being configured
2429 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002430 *
2431 * Return: 0 on success or negative otherwise
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002432 **/
2433int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
2434{
2435 struct net_device *netdev = vsi->netdev;
2436 struct i40e_mac_filter *f, *add_f;
2437 bool is_vf, is_netdev;
2438 int filter_count = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002439
2440 is_vf = (vsi->type == I40E_VSI_SRIOV);
2441 is_netdev = !!(netdev);
2442
Kiran Patil21659032015-09-30 14:09:03 -04002443 /* Locked once because all functions invoked below iterates list */
2444 spin_lock_bh(&vsi->mac_filter_list_lock);
2445
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002446 if (is_netdev)
2447 i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev);
2448
2449 list_for_each_entry(f, &vsi->mac_filter_list, list)
2450 i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
2451
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002452 /* go through all the filters for this VSI and if there is only
2453 * vid == 0 it means there are no other filters, so vid 0 must
2454 * be replaced with -1. This signifies that we should from now
2455 * on accept any traffic (with any tag present, or untagged)
2456 */
2457 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2458 if (is_netdev) {
2459 if (f->vlan &&
2460 ether_addr_equal(netdev->dev_addr, f->macaddr))
2461 filter_count++;
2462 }
2463
2464 if (f->vlan)
2465 filter_count++;
2466 }
2467
2468 if (!filter_count && is_netdev) {
2469 i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev);
2470 f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
2471 is_vf, is_netdev);
2472 if (!f) {
2473 dev_info(&vsi->back->pdev->dev,
2474 "Could not add filter %d for %pM\n",
2475 I40E_VLAN_ANY, netdev->dev_addr);
Kiran Patil21659032015-09-30 14:09:03 -04002476 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002477 return -ENOMEM;
2478 }
2479 }
2480
2481 if (!filter_count) {
2482 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2483 i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev);
2484 add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY,
Kiran Patil21659032015-09-30 14:09:03 -04002485 is_vf, is_netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002486 if (!add_f) {
2487 dev_info(&vsi->back->pdev->dev,
2488 "Could not add filter %d for %pM\n",
2489 I40E_VLAN_ANY, f->macaddr);
Kiran Patil21659032015-09-30 14:09:03 -04002490 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002491 return -ENOMEM;
2492 }
2493 }
2494 }
2495
Kiran Patil21659032015-09-30 14:09:03 -04002496 spin_unlock_bh(&vsi->mac_filter_list_lock);
2497
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002498 /* schedule our worker thread which will take care of
2499 * applying the new filter changes
2500 */
2501 i40e_service_event_schedule(vsi->back);
2502 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002503}
2504
2505/**
2506 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2507 * @netdev: network interface to be adjusted
2508 * @vid: vlan id to be added
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002509 *
2510 * net_device_ops implementation for adding vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002511 **/
Vasu Dev38e00432014-08-01 13:27:03 -07002512#ifdef I40E_FCOE
2513int i40e_vlan_rx_add_vid(struct net_device *netdev,
2514 __always_unused __be16 proto, u16 vid)
2515#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002516static int i40e_vlan_rx_add_vid(struct net_device *netdev,
2517 __always_unused __be16 proto, u16 vid)
Vasu Dev38e00432014-08-01 13:27:03 -07002518#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002519{
2520 struct i40e_netdev_priv *np = netdev_priv(netdev);
2521 struct i40e_vsi *vsi = np->vsi;
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002522 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002523
2524 if (vid > 4095)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002525 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002526
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002527 netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid);
2528
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002529 /* If the network stack called us with vid = 0 then
2530 * it is asking to receive priority tagged packets with
2531 * vlan id 0. Our HW receives them by default when configured
2532 * to receive untagged packets so there is no need to add an
2533 * extra filter for vlan 0 tagged packets.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002534 */
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002535 if (vid)
2536 ret = i40e_vsi_add_vlan(vsi, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002537
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002538 if (!ret && (vid < VLAN_N_VID))
2539 set_bit(vid, vsi->active_vlans);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002540
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002541 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002542}
2543
2544/**
2545 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2546 * @netdev: network interface to be adjusted
2547 * @vid: vlan id to be removed
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002548 *
Akeem G Abodunrinfdfd9432014-02-11 08:24:15 +00002549 * net_device_ops implementation for removing vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002550 **/
Vasu Dev38e00432014-08-01 13:27:03 -07002551#ifdef I40E_FCOE
2552int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2553 __always_unused __be16 proto, u16 vid)
2554#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002555static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2556 __always_unused __be16 proto, u16 vid)
Vasu Dev38e00432014-08-01 13:27:03 -07002557#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002558{
2559 struct i40e_netdev_priv *np = netdev_priv(netdev);
2560 struct i40e_vsi *vsi = np->vsi;
2561
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002562 netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid);
2563
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002564 /* return code is ignored as there is nothing a user
2565 * can do about failure to remove and a log message was
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002566 * already printed from the other function
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002567 */
2568 i40e_vsi_kill_vlan(vsi, vid);
2569
2570 clear_bit(vid, vsi->active_vlans);
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002571
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002572 return 0;
2573}
2574
2575/**
2576 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2577 * @vsi: the vsi being brought back up
2578 **/
2579static void i40e_restore_vlan(struct i40e_vsi *vsi)
2580{
2581 u16 vid;
2582
2583 if (!vsi->netdev)
2584 return;
2585
2586 i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
2587
2588 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
2589 i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
2590 vid);
2591}
2592
2593/**
2594 * i40e_vsi_add_pvid - Add pvid for the VSI
2595 * @vsi: the vsi being adjusted
2596 * @vid: the vlan id to set as a PVID
2597 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002598int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002599{
2600 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002601 i40e_status ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002602
2603 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2604 vsi->info.pvid = cpu_to_le16(vid);
Greg Rose6c12fcb2013-11-28 06:39:34 +00002605 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
2606 I40E_AQ_VSI_PVLAN_INSERT_PVID |
Greg Roseb774c7d2013-11-28 06:39:44 +00002607 I40E_AQ_VSI_PVLAN_EMOD_STR;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002608
2609 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002610 ctxt.info = vsi->info;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002611 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2612 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002613 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002614 "add pvid failed, err %s aq_err %s\n",
2615 i40e_stat_str(&vsi->back->hw, ret),
2616 i40e_aq_str(&vsi->back->hw,
2617 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002618 return -ENOENT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002619 }
2620
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002621 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002622}
2623
2624/**
2625 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2626 * @vsi: the vsi being adjusted
2627 *
2628 * Just use the vlan_rx_register() service to put it back to normal
2629 **/
2630void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
2631{
Greg Rose6c12fcb2013-11-28 06:39:34 +00002632 i40e_vlan_stripping_disable(vsi);
2633
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002634 vsi->info.pvid = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002635}
2636
2637/**
2638 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2639 * @vsi: ptr to the VSI
2640 *
2641 * If this function returns with an error, then it's possible one or
2642 * more of the rings is populated (while the rest are not). It is the
2643 * callers duty to clean those orphaned rings.
2644 *
2645 * Return 0 on success, negative on failure
2646 **/
2647static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
2648{
2649 int i, err = 0;
2650
2651 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002652 err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002653
2654 return err;
2655}
2656
2657/**
2658 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2659 * @vsi: ptr to the VSI
2660 *
2661 * Free VSI's transmit software resources
2662 **/
2663static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
2664{
2665 int i;
2666
Greg Rose8e9dca52013-12-18 13:45:53 +00002667 if (!vsi->tx_rings)
2668 return;
2669
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002670 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002671 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002672 i40e_free_tx_resources(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002673}
2674
2675/**
2676 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2677 * @vsi: ptr to the VSI
2678 *
2679 * If this function returns with an error, then it's possible one or
2680 * more of the rings is populated (while the rest are not). It is the
2681 * callers duty to clean those orphaned rings.
2682 *
2683 * Return 0 on success, negative on failure
2684 **/
2685static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
2686{
2687 int i, err = 0;
2688
2689 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002690 err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
Vasu Dev38e00432014-08-01 13:27:03 -07002691#ifdef I40E_FCOE
2692 i40e_fcoe_setup_ddp_resources(vsi);
2693#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002694 return err;
2695}
2696
2697/**
2698 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2699 * @vsi: ptr to the VSI
2700 *
2701 * Free all receive software resources
2702 **/
2703static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
2704{
2705 int i;
2706
Greg Rose8e9dca52013-12-18 13:45:53 +00002707 if (!vsi->rx_rings)
2708 return;
2709
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002710 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002711 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002712 i40e_free_rx_resources(vsi->rx_rings[i]);
Vasu Dev38e00432014-08-01 13:27:03 -07002713#ifdef I40E_FCOE
2714 i40e_fcoe_free_ddp_resources(vsi);
2715#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002716}
2717
2718/**
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002719 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
2720 * @ring: The Tx ring to configure
2721 *
2722 * This enables/disables XPS for a given Tx descriptor ring
2723 * based on the TCs enabled for the VSI that ring belongs to.
2724 **/
2725static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
2726{
2727 struct i40e_vsi *vsi = ring->vsi;
2728 cpumask_var_t mask;
2729
Jesse Brandeburg9a660ee2015-02-26 16:13:22 +00002730 if (!ring->q_vector || !ring->netdev)
2731 return;
2732
2733 /* Single TC mode enable XPS */
2734 if (vsi->tc_config.numtc <= 1) {
2735 if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002736 netif_set_xps_queue(ring->netdev,
2737 &ring->q_vector->affinity_mask,
2738 ring->queue_index);
Jesse Brandeburg9a660ee2015-02-26 16:13:22 +00002739 } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) {
2740 /* Disable XPS to allow selection based on TC */
2741 bitmap_zero(cpumask_bits(mask), nr_cpumask_bits);
2742 netif_set_xps_queue(ring->netdev, mask, ring->queue_index);
2743 free_cpumask_var(mask);
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002744 }
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002745
2746 /* schedule our worker thread which will take care of
2747 * applying the new filter changes
2748 */
2749 i40e_service_event_schedule(vsi->back);
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002750}
2751
2752/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002753 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2754 * @ring: The Tx ring to configure
2755 *
2756 * Configure the Tx descriptor ring in the HMC context.
2757 **/
2758static int i40e_configure_tx_ring(struct i40e_ring *ring)
2759{
2760 struct i40e_vsi *vsi = ring->vsi;
2761 u16 pf_q = vsi->base_queue + ring->queue_index;
2762 struct i40e_hw *hw = &vsi->back->hw;
2763 struct i40e_hmc_obj_txq tx_ctx;
2764 i40e_status err = 0;
2765 u32 qtx_ctl = 0;
2766
2767 /* some ATR related tx ring init */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002768 if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002769 ring->atr_sample_rate = vsi->back->atr_sample_rate;
2770 ring->atr_count = 0;
2771 } else {
2772 ring->atr_sample_rate = 0;
2773 }
2774
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002775 /* configure XPS */
2776 i40e_config_xps_tx_ring(ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002777
2778 /* clear the context structure first */
2779 memset(&tx_ctx, 0, sizeof(tx_ctx));
2780
2781 tx_ctx.new_context = 1;
2782 tx_ctx.base = (ring->dma / 128);
2783 tx_ctx.qlen = ring->count;
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002784 tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
2785 I40E_FLAG_FD_ATR_ENABLED));
Vasu Dev38e00432014-08-01 13:27:03 -07002786#ifdef I40E_FCOE
2787 tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
2788#endif
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002789 tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
Jesse Brandeburg1943d8b2014-02-14 02:14:40 +00002790 /* FDIR VSI tx ring can still use RS bit and writebacks */
2791 if (vsi->type != I40E_VSI_FDIR)
2792 tx_ctx.head_wb_ena = 1;
2793 tx_ctx.head_wb_addr = ring->dma +
2794 (ring->count * sizeof(struct i40e_tx_desc));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002795
2796 /* As part of VSI creation/update, FW allocates certain
2797 * Tx arbitration queue sets for each TC enabled for
2798 * the VSI. The FW returns the handles to these queue
2799 * sets as part of the response buffer to Add VSI,
2800 * Update VSI, etc. AQ commands. It is expected that
2801 * these queue set handles be associated with the Tx
2802 * queues by the driver as part of the TX queue context
2803 * initialization. This has to be done regardless of
2804 * DCB as by default everything is mapped to TC0.
2805 */
2806 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
2807 tx_ctx.rdylist_act = 0;
2808
2809 /* clear the context in the HMC */
2810 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2811 if (err) {
2812 dev_info(&vsi->back->pdev->dev,
2813 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2814 ring->queue_index, pf_q, err);
2815 return -ENOMEM;
2816 }
2817
2818 /* set the context in the HMC */
2819 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
2820 if (err) {
2821 dev_info(&vsi->back->pdev->dev,
2822 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2823 ring->queue_index, pf_q, err);
2824 return -ENOMEM;
2825 }
2826
2827 /* Now associate this queue with this PCI function */
Mitch Williams7a28d882014-10-17 03:14:52 +00002828 if (vsi->type == I40E_VSI_VMDQ2) {
Shannon Nelson9d8bf542014-01-14 00:49:50 -08002829 qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
Mitch Williams7a28d882014-10-17 03:14:52 +00002830 qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
2831 I40E_QTX_CTL_VFVM_INDX_MASK;
2832 } else {
Shannon Nelson9d8bf542014-01-14 00:49:50 -08002833 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
Mitch Williams7a28d882014-10-17 03:14:52 +00002834 }
2835
Shannon Nelson13fd9772013-09-28 07:14:19 +00002836 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
2837 I40E_QTX_CTL_PF_INDX_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002838 wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
2839 i40e_flush(hw);
2840
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002841 /* cache tail off for easier writes later */
2842 ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2843
2844 return 0;
2845}
2846
2847/**
2848 * i40e_configure_rx_ring - Configure a receive ring context
2849 * @ring: The Rx ring to configure
2850 *
2851 * Configure the Rx descriptor ring in the HMC context.
2852 **/
2853static int i40e_configure_rx_ring(struct i40e_ring *ring)
2854{
2855 struct i40e_vsi *vsi = ring->vsi;
2856 u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
2857 u16 pf_q = vsi->base_queue + ring->queue_index;
2858 struct i40e_hw *hw = &vsi->back->hw;
2859 struct i40e_hmc_obj_rxq rx_ctx;
2860 i40e_status err = 0;
2861
2862 ring->state = 0;
2863
2864 /* clear the context structure first */
2865 memset(&rx_ctx, 0, sizeof(rx_ctx));
2866
2867 ring->rx_buf_len = vsi->rx_buf_len;
2868 ring->rx_hdr_len = vsi->rx_hdr_len;
2869
2870 rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
2871 rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
2872
2873 rx_ctx.base = (ring->dma / 128);
2874 rx_ctx.qlen = ring->count;
2875
2876 if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) {
2877 set_ring_16byte_desc_enabled(ring);
2878 rx_ctx.dsize = 0;
2879 } else {
2880 rx_ctx.dsize = 1;
2881 }
2882
2883 rx_ctx.dtype = vsi->dtype;
2884 if (vsi->dtype) {
2885 set_ring_ps_enabled(ring);
2886 rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
2887 I40E_RX_SPLIT_IP |
2888 I40E_RX_SPLIT_TCP_UDP |
2889 I40E_RX_SPLIT_SCTP;
2890 } else {
2891 rx_ctx.hsplit_0 = 0;
2892 }
2893
2894 rx_ctx.rxmax = min_t(u16, vsi->max_frame,
2895 (chain_len * ring->rx_buf_len));
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00002896 if (hw->revision_id == 0)
2897 rx_ctx.lrxqthresh = 0;
2898 else
2899 rx_ctx.lrxqthresh = 2;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002900 rx_ctx.crcstrip = 1;
2901 rx_ctx.l2tsel = 1;
Jesse Brandeburgc4bbac32015-09-28 11:21:48 -07002902 /* this controls whether VLAN is stripped from inner headers */
2903 rx_ctx.showiv = 0;
Vasu Dev38e00432014-08-01 13:27:03 -07002904#ifdef I40E_FCOE
2905 rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
2906#endif
Catherine Sullivanacb36762014-03-06 09:02:30 +00002907 /* set the prefena field to 1 because the manual says to */
2908 rx_ctx.prefena = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002909
2910 /* clear the context in the HMC */
2911 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
2912 if (err) {
2913 dev_info(&vsi->back->pdev->dev,
2914 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2915 ring->queue_index, pf_q, err);
2916 return -ENOMEM;
2917 }
2918
2919 /* set the context in the HMC */
2920 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
2921 if (err) {
2922 dev_info(&vsi->back->pdev->dev,
2923 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2924 ring->queue_index, pf_q, err);
2925 return -ENOMEM;
2926 }
2927
2928 /* cache tail for quicker writes, and clear the reg before use */
2929 ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
2930 writel(0, ring->tail);
2931
Mitch Williamsa132af22015-01-24 09:58:35 +00002932 if (ring_is_ps_enabled(ring)) {
2933 i40e_alloc_rx_headers(ring);
2934 i40e_alloc_rx_buffers_ps(ring, I40E_DESC_UNUSED(ring));
2935 } else {
2936 i40e_alloc_rx_buffers_1buf(ring, I40E_DESC_UNUSED(ring));
2937 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002938
2939 return 0;
2940}
2941
2942/**
2943 * i40e_vsi_configure_tx - Configure the VSI for Tx
2944 * @vsi: VSI structure describing this set of rings and resources
2945 *
2946 * Configure the Tx VSI for operation.
2947 **/
2948static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
2949{
2950 int err = 0;
2951 u16 i;
2952
Alexander Duyck9f65e152013-09-28 06:00:58 +00002953 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
2954 err = i40e_configure_tx_ring(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002955
2956 return err;
2957}
2958
2959/**
2960 * i40e_vsi_configure_rx - Configure the VSI for Rx
2961 * @vsi: the VSI being configured
2962 *
2963 * Configure the Rx VSI for operation.
2964 **/
2965static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
2966{
2967 int err = 0;
2968 u16 i;
2969
2970 if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
2971 vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
2972 + ETH_FCS_LEN + VLAN_HLEN;
2973 else
2974 vsi->max_frame = I40E_RXBUFFER_2048;
2975
2976 /* figure out correct receive buffer length */
2977 switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED |
2978 I40E_FLAG_RX_PS_ENABLED)) {
2979 case I40E_FLAG_RX_1BUF_ENABLED:
2980 vsi->rx_hdr_len = 0;
2981 vsi->rx_buf_len = vsi->max_frame;
2982 vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
2983 break;
2984 case I40E_FLAG_RX_PS_ENABLED:
2985 vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
2986 vsi->rx_buf_len = I40E_RXBUFFER_2048;
2987 vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT;
2988 break;
2989 default:
2990 vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
2991 vsi->rx_buf_len = I40E_RXBUFFER_2048;
2992 vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS;
2993 break;
2994 }
2995
Vasu Dev38e00432014-08-01 13:27:03 -07002996#ifdef I40E_FCOE
2997 /* setup rx buffer for FCoE */
2998 if ((vsi->type == I40E_VSI_FCOE) &&
2999 (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) {
3000 vsi->rx_hdr_len = 0;
3001 vsi->rx_buf_len = I40E_RXBUFFER_3072;
3002 vsi->max_frame = I40E_RXBUFFER_3072;
3003 vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
3004 }
3005
3006#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003007 /* round up for the chip's needs */
3008 vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len,
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04003009 BIT_ULL(I40E_RXQ_CTX_HBUFF_SHIFT));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003010 vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04003011 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003012
3013 /* set up individual rings */
3014 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00003015 err = i40e_configure_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003016
3017 return err;
3018}
3019
3020/**
3021 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
3022 * @vsi: ptr to the VSI
3023 **/
3024static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
3025{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00003026 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003027 u16 qoffset, qcount;
3028 int i, n;
3029
Parikh, Neeravcd238a32015-02-21 06:43:37 +00003030 if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
3031 /* Reset the TC information */
3032 for (i = 0; i < vsi->num_queue_pairs; i++) {
3033 rx_ring = vsi->rx_rings[i];
3034 tx_ring = vsi->tx_rings[i];
3035 rx_ring->dcb_tc = 0;
3036 tx_ring->dcb_tc = 0;
3037 }
3038 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003039
3040 for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04003041 if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003042 continue;
3043
3044 qoffset = vsi->tc_config.tc_info[n].qoffset;
3045 qcount = vsi->tc_config.tc_info[n].qcount;
3046 for (i = qoffset; i < (qoffset + qcount); i++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00003047 rx_ring = vsi->rx_rings[i];
3048 tx_ring = vsi->tx_rings[i];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003049 rx_ring->dcb_tc = n;
3050 tx_ring->dcb_tc = n;
3051 }
3052 }
3053}
3054
3055/**
3056 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
3057 * @vsi: ptr to the VSI
3058 **/
3059static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
3060{
3061 if (vsi->netdev)
3062 i40e_set_rx_mode(vsi->netdev);
3063}
3064
3065/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003066 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
3067 * @vsi: Pointer to the targeted VSI
3068 *
3069 * This function replays the hlist on the hw where all the SB Flow Director
3070 * filters were saved.
3071 **/
3072static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
3073{
3074 struct i40e_fdir_filter *filter;
3075 struct i40e_pf *pf = vsi->back;
3076 struct hlist_node *node;
3077
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003078 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3079 return;
3080
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003081 hlist_for_each_entry_safe(filter, node,
3082 &pf->fdir_filter_list, fdir_node) {
3083 i40e_add_del_fdir(vsi, filter, true);
3084 }
3085}
3086
3087/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003088 * i40e_vsi_configure - Set up the VSI for action
3089 * @vsi: the VSI being configured
3090 **/
3091static int i40e_vsi_configure(struct i40e_vsi *vsi)
3092{
3093 int err;
3094
3095 i40e_set_vsi_rx_mode(vsi);
3096 i40e_restore_vlan(vsi);
3097 i40e_vsi_config_dcb_rings(vsi);
3098 err = i40e_vsi_configure_tx(vsi);
3099 if (!err)
3100 err = i40e_vsi_configure_rx(vsi);
3101
3102 return err;
3103}
3104
3105/**
3106 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3107 * @vsi: the VSI being configured
3108 **/
3109static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
3110{
3111 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003112 struct i40e_hw *hw = &pf->hw;
3113 u16 vector;
3114 int i, q;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003115 u32 qp;
3116
3117 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3118 * and PFINT_LNKLSTn registers, e.g.:
3119 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3120 */
3121 qp = vsi->base_queue;
3122 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +00003123 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003124 struct i40e_q_vector *q_vector = vsi->q_vectors[i];
3125
Jesse Brandeburgee2319c2015-09-28 14:16:54 -04003126 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003127 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
3128 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3129 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
3130 q_vector->rx.itr);
3131 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
3132 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3133 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
3134 q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003135 wr32(hw, I40E_PFINT_RATEN(vector - 1),
3136 INTRL_USEC_TO_REG(vsi->int_rate_limit));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003137
3138 /* Linked list for the queuepairs assigned to this vector */
3139 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
3140 for (q = 0; q < q_vector->num_ringpairs; q++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003141 u32 val;
3142
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003143 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3144 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3145 (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
3146 (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
3147 (I40E_QUEUE_TYPE_TX
3148 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
3149
3150 wr32(hw, I40E_QINT_RQCTL(qp), val);
3151
3152 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3153 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3154 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
3155 ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
3156 (I40E_QUEUE_TYPE_RX
3157 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3158
3159 /* Terminate the linked list */
3160 if (q == (q_vector->num_ringpairs - 1))
3161 val |= (I40E_QUEUE_END_OF_LIST
3162 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3163
3164 wr32(hw, I40E_QINT_TQCTL(qp), val);
3165 qp++;
3166 }
3167 }
3168
3169 i40e_flush(hw);
3170}
3171
3172/**
3173 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3174 * @hw: ptr to the hardware info
3175 **/
Jacob Kellerab437b52014-12-14 01:55:08 +00003176static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003177{
Jacob Kellerab437b52014-12-14 01:55:08 +00003178 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003179 u32 val;
3180
3181 /* clear things first */
3182 wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
3183 rd32(hw, I40E_PFINT_ICR0); /* read to clear */
3184
3185 val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
3186 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
3187 I40E_PFINT_ICR0_ENA_GRST_MASK |
3188 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
3189 I40E_PFINT_ICR0_ENA_GPIO_MASK |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003190 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
3191 I40E_PFINT_ICR0_ENA_VFLR_MASK |
3192 I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3193
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003194 if (pf->flags & I40E_FLAG_IWARP_ENABLED)
3195 val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3196
Jacob Kellerab437b52014-12-14 01:55:08 +00003197 if (pf->flags & I40E_FLAG_PTP)
3198 val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
3199
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003200 wr32(hw, I40E_PFINT_ICR0_ENA, val);
3201
3202 /* SW_ITR_IDX = 0, but don't change INTENA */
Anjali Singhai Jain84ed40e2013-11-26 10:49:32 +00003203 wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
3204 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003205
3206 /* OTHER_ITR_IDX = 0 */
3207 wr32(hw, I40E_PFINT_STAT_CTL0, 0);
3208}
3209
3210/**
3211 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3212 * @vsi: the VSI being configured
3213 **/
3214static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
3215{
Alexander Duyck493fb302013-09-28 07:01:44 +00003216 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003217 struct i40e_pf *pf = vsi->back;
3218 struct i40e_hw *hw = &pf->hw;
3219 u32 val;
3220
3221 /* set the ITR configuration */
Jesse Brandeburgee2319c2015-09-28 14:16:54 -04003222 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003223 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
3224 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3225 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
3226 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
3227 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3228 wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
3229
Jacob Kellerab437b52014-12-14 01:55:08 +00003230 i40e_enable_misc_int_causes(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003231
3232 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3233 wr32(hw, I40E_PFINT_LNKLST0, 0);
3234
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00003235 /* Associate the queue pair to the vector and enable the queue int */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003236 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3237 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3238 (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3239
3240 wr32(hw, I40E_QINT_RQCTL(0), val);
3241
3242 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3243 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3244 (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3245
3246 wr32(hw, I40E_QINT_TQCTL(0), val);
3247 i40e_flush(hw);
3248}
3249
3250/**
Mitch Williams2ef28cf2013-11-28 06:39:32 +00003251 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3252 * @pf: board private structure
3253 **/
3254void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
3255{
3256 struct i40e_hw *hw = &pf->hw;
3257
3258 wr32(hw, I40E_PFINT_DYN_CTL0,
3259 I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
3260 i40e_flush(hw);
3261}
3262
3263/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003264 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3265 * @pf: board private structure
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003266 * @clearpba: true when all pending interrupt events should be cleared
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003267 **/
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003268void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003269{
3270 struct i40e_hw *hw = &pf->hw;
3271 u32 val;
3272
3273 val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003274 (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003275 (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
3276
3277 wr32(hw, I40E_PFINT_DYN_CTL0, val);
3278 i40e_flush(hw);
3279}
3280
3281/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003282 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3283 * @irq: interrupt number
3284 * @data: pointer to a q_vector
3285 **/
3286static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
3287{
3288 struct i40e_q_vector *q_vector = data;
3289
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003290 if (!q_vector->tx.ring && !q_vector->rx.ring)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003291 return IRQ_HANDLED;
3292
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003293 napi_schedule_irqoff(&q_vector->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003294
3295 return IRQ_HANDLED;
3296}
3297
3298/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003299 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3300 * @vsi: the VSI being configured
3301 * @basename: name for the vector
3302 *
3303 * Allocates MSI-X vectors and requests interrupts from the kernel.
3304 **/
3305static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
3306{
3307 int q_vectors = vsi->num_q_vectors;
3308 struct i40e_pf *pf = vsi->back;
3309 int base = vsi->base_vector;
3310 int rx_int_idx = 0;
3311 int tx_int_idx = 0;
3312 int vector, err;
3313
3314 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck493fb302013-09-28 07:01:44 +00003315 struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003316
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003317 if (q_vector->tx.ring && q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003318 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3319 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
3320 tx_int_idx++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003321 } else if (q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003322 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3323 "%s-%s-%d", basename, "rx", rx_int_idx++);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003324 } else if (q_vector->tx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003325 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3326 "%s-%s-%d", basename, "tx", tx_int_idx++);
3327 } else {
3328 /* skip this unused q_vector */
3329 continue;
3330 }
3331 err = request_irq(pf->msix_entries[base + vector].vector,
3332 vsi->irq_handler,
3333 0,
3334 q_vector->name,
3335 q_vector);
3336 if (err) {
3337 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003338 "MSIX request_irq failed, error: %d\n", err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003339 goto free_queue_irqs;
3340 }
3341 /* assign the mask for this irq */
3342 irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
3343 &q_vector->affinity_mask);
3344 }
3345
Shannon Nelson63741842014-04-23 04:50:16 +00003346 vsi->irqs_ready = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003347 return 0;
3348
3349free_queue_irqs:
3350 while (vector) {
3351 vector--;
3352 irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
3353 NULL);
3354 free_irq(pf->msix_entries[base + vector].vector,
3355 &(vsi->q_vectors[vector]));
3356 }
3357 return err;
3358}
3359
3360/**
3361 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3362 * @vsi: the VSI being un-configured
3363 **/
3364static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
3365{
3366 struct i40e_pf *pf = vsi->back;
3367 struct i40e_hw *hw = &pf->hw;
3368 int base = vsi->base_vector;
3369 int i;
3370
3371 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00003372 wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
3373 wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003374 }
3375
3376 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3377 for (i = vsi->base_vector;
3378 i < (vsi->num_q_vectors + vsi->base_vector); i++)
3379 wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
3380
3381 i40e_flush(hw);
3382 for (i = 0; i < vsi->num_q_vectors; i++)
3383 synchronize_irq(pf->msix_entries[i + base].vector);
3384 } else {
3385 /* Legacy and MSI mode - this stops all interrupt handling */
3386 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
3387 wr32(hw, I40E_PFINT_DYN_CTL0, 0);
3388 i40e_flush(hw);
3389 synchronize_irq(pf->pdev->irq);
3390 }
3391}
3392
3393/**
3394 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3395 * @vsi: the VSI being configured
3396 **/
3397static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
3398{
3399 struct i40e_pf *pf = vsi->back;
3400 int i;
3401
3402 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
Jesse Brandeburg78455482015-07-23 16:54:41 -04003403 for (i = 0; i < vsi->num_q_vectors; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003404 i40e_irq_dynamic_enable(vsi, i);
3405 } else {
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003406 i40e_irq_dynamic_enable_icr0(pf, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003407 }
3408
Jesse Brandeburg1022cb62013-09-28 07:13:08 +00003409 i40e_flush(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003410 return 0;
3411}
3412
3413/**
3414 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3415 * @pf: board private structure
3416 **/
3417static void i40e_stop_misc_vector(struct i40e_pf *pf)
3418{
3419 /* Disable ICR 0 */
3420 wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
3421 i40e_flush(&pf->hw);
3422}
3423
3424/**
3425 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3426 * @irq: interrupt number
3427 * @data: pointer to a q_vector
3428 *
3429 * This is the handler used for all MSI/Legacy interrupts, and deals
3430 * with both queue and non-queue interrupts. This is also used in
3431 * MSIX mode to handle the non-queue interrupts.
3432 **/
3433static irqreturn_t i40e_intr(int irq, void *data)
3434{
3435 struct i40e_pf *pf = (struct i40e_pf *)data;
3436 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003437 irqreturn_t ret = IRQ_NONE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003438 u32 icr0, icr0_remaining;
3439 u32 val, ena_mask;
3440
3441 icr0 = rd32(hw, I40E_PFINT_ICR0);
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003442 ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003443
Shannon Nelson116a57d2013-09-28 07:13:59 +00003444 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3445 if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003446 goto enable_intr;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003447
Shannon Nelsoncd92e722013-11-16 10:00:44 +00003448 /* if interrupt but no bits showing, must be SWINT */
3449 if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
3450 (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
3451 pf->sw_int_count++;
3452
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003453 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
3454 (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
3455 ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3456 icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3457 dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n");
3458 }
3459
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003460 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3461 if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003462 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
3463 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003464
3465 /* temporarily disable queue cause for NAPI processing */
3466 u32 qval = rd32(hw, I40E_QINT_RQCTL(0));
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003467
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003468 qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
3469 wr32(hw, I40E_QINT_RQCTL(0), qval);
3470
3471 qval = rd32(hw, I40E_QINT_TQCTL(0));
3472 qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
3473 wr32(hw, I40E_QINT_TQCTL(0), qval);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003474
3475 if (!test_bit(__I40E_DOWN, &pf->state))
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003476 napi_schedule_irqoff(&q_vector->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003477 }
3478
3479 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
3480 ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3481 set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
3482 }
3483
3484 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
3485 ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
3486 set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
3487 }
3488
3489 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
3490 ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
3491 set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
3492 }
3493
3494 if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
3495 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
3496 set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
3497 ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
3498 val = rd32(hw, I40E_GLGEN_RSTAT);
3499 val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
3500 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003501 if (val == I40E_RESET_CORER) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003502 pf->corer_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003503 } else if (val == I40E_RESET_GLOBR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003504 pf->globr_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003505 } else if (val == I40E_RESET_EMPR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003506 pf->empr_count++;
Anjali Singhai Jain9df42d12015-01-24 09:58:40 +00003507 set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003508 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003509 }
3510
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003511 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
3512 icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
3513 dev_info(&pf->pdev->dev, "HMC error interrupt\n");
Anjali Singhai Jain25fc0e62015-03-31 00:45:01 -07003514 dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
3515 rd32(hw, I40E_PFHMC_ERRORINFO),
3516 rd32(hw, I40E_PFHMC_ERRORDATA));
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003517 }
3518
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003519 if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
3520 u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
3521
3522 if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
Jacob Kellercafa1fc2014-04-24 18:05:03 -07003523 icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003524 i40e_ptp_tx_hwtstamp(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003525 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003526 }
3527
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003528 /* If a critical error is pending we have no choice but to reset the
3529 * device.
3530 * Report and mask out any remaining unexpected interrupts.
3531 */
3532 icr0_remaining = icr0 & ena_mask;
3533 if (icr0_remaining) {
3534 dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
3535 icr0_remaining);
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003536 if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003537 (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
Anjali Singhai Jainc0c28972014-02-12 01:45:34 +00003538 (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003539 dev_info(&pf->pdev->dev, "device will be reset\n");
3540 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
3541 i40e_service_event_schedule(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003542 }
3543 ena_mask &= ~icr0_remaining;
3544 }
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003545 ret = IRQ_HANDLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003546
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003547enable_intr:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003548 /* re-enable interrupt causes */
3549 wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003550 if (!test_bit(__I40E_DOWN, &pf->state)) {
3551 i40e_service_event_schedule(pf);
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003552 i40e_irq_dynamic_enable_icr0(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003553 }
3554
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003555 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003556}
3557
3558/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003559 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3560 * @tx_ring: tx ring to clean
3561 * @budget: how many cleans we're allowed
3562 *
3563 * Returns true if there's any budget left (e.g. the clean is finished)
3564 **/
3565static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
3566{
3567 struct i40e_vsi *vsi = tx_ring->vsi;
3568 u16 i = tx_ring->next_to_clean;
3569 struct i40e_tx_buffer *tx_buf;
3570 struct i40e_tx_desc *tx_desc;
3571
3572 tx_buf = &tx_ring->tx_bi[i];
3573 tx_desc = I40E_TX_DESC(tx_ring, i);
3574 i -= tx_ring->count;
3575
3576 do {
3577 struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
3578
3579 /* if next_to_watch is not set then there is no work pending */
3580 if (!eop_desc)
3581 break;
3582
3583 /* prevent any other reads prior to eop_desc */
3584 read_barrier_depends();
3585
3586 /* if the descriptor isn't done, no work yet to do */
3587 if (!(eop_desc->cmd_type_offset_bsz &
3588 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
3589 break;
3590
3591 /* clear next_to_watch to prevent false hangs */
3592 tx_buf->next_to_watch = NULL;
3593
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003594 tx_desc->buffer_addr = 0;
3595 tx_desc->cmd_type_offset_bsz = 0;
3596 /* move past filter desc */
3597 tx_buf++;
3598 tx_desc++;
3599 i++;
3600 if (unlikely(!i)) {
3601 i -= tx_ring->count;
3602 tx_buf = tx_ring->tx_bi;
3603 tx_desc = I40E_TX_DESC(tx_ring, 0);
3604 }
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003605 /* unmap skb header data */
3606 dma_unmap_single(tx_ring->dev,
3607 dma_unmap_addr(tx_buf, dma),
3608 dma_unmap_len(tx_buf, len),
3609 DMA_TO_DEVICE);
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003610 if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
3611 kfree(tx_buf->raw_buf);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003612
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003613 tx_buf->raw_buf = NULL;
3614 tx_buf->tx_flags = 0;
3615 tx_buf->next_to_watch = NULL;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003616 dma_unmap_len_set(tx_buf, len, 0);
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003617 tx_desc->buffer_addr = 0;
3618 tx_desc->cmd_type_offset_bsz = 0;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003619
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003620 /* move us past the eop_desc for start of next FD desc */
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003621 tx_buf++;
3622 tx_desc++;
3623 i++;
3624 if (unlikely(!i)) {
3625 i -= tx_ring->count;
3626 tx_buf = tx_ring->tx_bi;
3627 tx_desc = I40E_TX_DESC(tx_ring, 0);
3628 }
3629
3630 /* update budget accounting */
3631 budget--;
3632 } while (likely(budget));
3633
3634 i += tx_ring->count;
3635 tx_ring->next_to_clean = i;
3636
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003637 if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
Jesse Brandeburg78455482015-07-23 16:54:41 -04003638 i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003639
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003640 return budget > 0;
3641}
3642
3643/**
3644 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3645 * @irq: interrupt number
3646 * @data: pointer to a q_vector
3647 **/
3648static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
3649{
3650 struct i40e_q_vector *q_vector = data;
3651 struct i40e_vsi *vsi;
3652
3653 if (!q_vector->tx.ring)
3654 return IRQ_HANDLED;
3655
3656 vsi = q_vector->tx.ring->vsi;
3657 i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
3658
3659 return IRQ_HANDLED;
3660}
3661
3662/**
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003663 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003664 * @vsi: the VSI being configured
3665 * @v_idx: vector index
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003666 * @qp_idx: queue pair index
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003667 **/
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04003668static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003669{
Alexander Duyck493fb302013-09-28 07:01:44 +00003670 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyck9f65e152013-09-28 06:00:58 +00003671 struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
3672 struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003673
3674 tx_ring->q_vector = q_vector;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003675 tx_ring->next = q_vector->tx.ring;
3676 q_vector->tx.ring = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003677 q_vector->tx.count++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003678
3679 rx_ring->q_vector = q_vector;
3680 rx_ring->next = q_vector->rx.ring;
3681 q_vector->rx.ring = rx_ring;
3682 q_vector->rx.count++;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003683}
3684
3685/**
3686 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3687 * @vsi: the VSI being configured
3688 *
3689 * This function maps descriptor rings to the queue-specific vectors
3690 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3691 * one vector per queue pair, but on a constrained vector budget, we
3692 * group the queue pairs as "efficiently" as possible.
3693 **/
3694static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
3695{
3696 int qp_remaining = vsi->num_queue_pairs;
3697 int q_vectors = vsi->num_q_vectors;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003698 int num_ringpairs;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003699 int v_start = 0;
3700 int qp_idx = 0;
3701
3702 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3703 * group them so there are multiple queues per vector.
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003704 * It is also important to go through all the vectors available to be
3705 * sure that if we don't use all the vectors, that the remaining vectors
3706 * are cleared. This is especially important when decreasing the
3707 * number of queues in use.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003708 */
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003709 for (; v_start < q_vectors; v_start++) {
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003710 struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
3711
3712 num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
3713
3714 q_vector->num_ringpairs = num_ringpairs;
3715
3716 q_vector->rx.count = 0;
3717 q_vector->tx.count = 0;
3718 q_vector->rx.ring = NULL;
3719 q_vector->tx.ring = NULL;
3720
3721 while (num_ringpairs--) {
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04003722 i40e_map_vector_to_qp(vsi, v_start, qp_idx);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003723 qp_idx++;
3724 qp_remaining--;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003725 }
3726 }
3727}
3728
3729/**
3730 * i40e_vsi_request_irq - Request IRQ from the OS
3731 * @vsi: the VSI being configured
3732 * @basename: name for the vector
3733 **/
3734static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
3735{
3736 struct i40e_pf *pf = vsi->back;
3737 int err;
3738
3739 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
3740 err = i40e_vsi_request_irq_msix(vsi, basename);
3741 else if (pf->flags & I40E_FLAG_MSI_ENABLED)
3742 err = request_irq(pf->pdev->irq, i40e_intr, 0,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00003743 pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003744 else
3745 err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00003746 pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003747
3748 if (err)
3749 dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
3750
3751 return err;
3752}
3753
3754#ifdef CONFIG_NET_POLL_CONTROLLER
3755/**
Jesse Brandeburgd89d9672016-01-04 10:33:02 -08003756 * i40e_netpoll - A Polling 'interrupt' handler
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003757 * @netdev: network interface device structure
3758 *
3759 * This is used by netconsole to send skbs without having to re-enable
3760 * interrupts. It's not called while the normal interrupt routine is executing.
3761 **/
Vasu Dev38e00432014-08-01 13:27:03 -07003762#ifdef I40E_FCOE
3763void i40e_netpoll(struct net_device *netdev)
3764#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003765static void i40e_netpoll(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -07003766#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003767{
3768 struct i40e_netdev_priv *np = netdev_priv(netdev);
3769 struct i40e_vsi *vsi = np->vsi;
3770 struct i40e_pf *pf = vsi->back;
3771 int i;
3772
3773 /* if interface is down do nothing */
3774 if (test_bit(__I40E_DOWN, &vsi->state))
3775 return;
3776
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003777 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3778 for (i = 0; i < vsi->num_q_vectors; i++)
Alexander Duyck493fb302013-09-28 07:01:44 +00003779 i40e_msix_clean_rings(0, vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003780 } else {
3781 i40e_intr(pf->pdev->irq, netdev);
3782 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003783}
3784#endif
3785
3786/**
Neerav Parikh23527302014-06-03 23:50:15 +00003787 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3788 * @pf: the PF being configured
3789 * @pf_q: the PF queue
3790 * @enable: enable or disable state of the queue
3791 *
3792 * This routine will wait for the given Tx queue of the PF to reach the
3793 * enabled or disabled state.
3794 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3795 * multiple retries; else will return 0 in case of success.
3796 **/
3797static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3798{
3799 int i;
3800 u32 tx_reg;
3801
3802 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3803 tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
3804 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
3805 break;
3806
Neerav Parikhf98a2002014-09-13 07:40:44 +00003807 usleep_range(10, 20);
Neerav Parikh23527302014-06-03 23:50:15 +00003808 }
3809 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3810 return -ETIMEDOUT;
3811
3812 return 0;
3813}
3814
3815/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003816 * i40e_vsi_control_tx - Start or stop a VSI's rings
3817 * @vsi: the VSI being configured
3818 * @enable: start or stop the rings
3819 **/
3820static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
3821{
3822 struct i40e_pf *pf = vsi->back;
3823 struct i40e_hw *hw = &pf->hw;
Neerav Parikh23527302014-06-03 23:50:15 +00003824 int i, j, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003825 u32 tx_reg;
3826
3827 pf_q = vsi->base_queue;
3828 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Matt Jared351499ab2014-04-23 04:50:03 +00003829
3830 /* warn the TX unit of coming changes */
3831 i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
3832 if (!enable)
Neerav Parikhf98a2002014-09-13 07:40:44 +00003833 usleep_range(10, 20);
Matt Jared351499ab2014-04-23 04:50:03 +00003834
Mitch Williams6c5ef622014-02-20 19:29:16 -08003835 for (j = 0; j < 50; j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003836 tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
Mitch Williams6c5ef622014-02-20 19:29:16 -08003837 if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
3838 ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
3839 break;
3840 usleep_range(1000, 2000);
3841 }
Mitch Williamsfda972f2013-11-28 06:39:29 +00003842 /* Skip if the queue is already in the requested state */
Catherine Sullivan7c122002014-03-14 07:32:29 +00003843 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
Mitch Williamsfda972f2013-11-28 06:39:29 +00003844 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003845
3846 /* turn on/off the queue */
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003847 if (enable) {
3848 wr32(hw, I40E_QTX_HEAD(pf_q), 0);
Mitch Williams6c5ef622014-02-20 19:29:16 -08003849 tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003850 } else {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003851 tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003852 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003853
3854 wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
Neerav Parikh69129dc2014-11-12 00:18:46 +00003855 /* No waiting for the Tx queue to disable */
3856 if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
3857 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003858
3859 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00003860 ret = i40e_pf_txq_wait(pf, pf_q, enable);
3861 if (ret) {
3862 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003863 "VSI seid %d Tx ring %d %sable timeout\n",
3864 vsi->seid, pf_q, (enable ? "en" : "dis"));
Neerav Parikh23527302014-06-03 23:50:15 +00003865 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003866 }
3867 }
3868
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003869 if (hw->revision_id == 0)
3870 mdelay(50);
Neerav Parikh23527302014-06-03 23:50:15 +00003871 return ret;
3872}
3873
3874/**
3875 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
3876 * @pf: the PF being configured
3877 * @pf_q: the PF queue
3878 * @enable: enable or disable state of the queue
3879 *
3880 * This routine will wait for the given Rx queue of the PF to reach the
3881 * enabled or disabled state.
3882 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3883 * multiple retries; else will return 0 in case of success.
3884 **/
3885static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3886{
3887 int i;
3888 u32 rx_reg;
3889
3890 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3891 rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
3892 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
3893 break;
3894
Neerav Parikhf98a2002014-09-13 07:40:44 +00003895 usleep_range(10, 20);
Neerav Parikh23527302014-06-03 23:50:15 +00003896 }
3897 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3898 return -ETIMEDOUT;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003899
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003900 return 0;
3901}
3902
3903/**
3904 * i40e_vsi_control_rx - Start or stop a VSI's rings
3905 * @vsi: the VSI being configured
3906 * @enable: start or stop the rings
3907 **/
3908static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
3909{
3910 struct i40e_pf *pf = vsi->back;
3911 struct i40e_hw *hw = &pf->hw;
Neerav Parikh23527302014-06-03 23:50:15 +00003912 int i, j, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003913 u32 rx_reg;
3914
3915 pf_q = vsi->base_queue;
3916 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Mitch Williams6c5ef622014-02-20 19:29:16 -08003917 for (j = 0; j < 50; j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003918 rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
Mitch Williams6c5ef622014-02-20 19:29:16 -08003919 if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
3920 ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
3921 break;
3922 usleep_range(1000, 2000);
3923 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003924
Catherine Sullivan7c122002014-03-14 07:32:29 +00003925 /* Skip if the queue is already in the requested state */
3926 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
3927 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003928
3929 /* turn on/off the queue */
3930 if (enable)
Mitch Williams6c5ef622014-02-20 19:29:16 -08003931 rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003932 else
Mitch Williams6c5ef622014-02-20 19:29:16 -08003933 rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003934 wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
3935
3936 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00003937 ret = i40e_pf_rxq_wait(pf, pf_q, enable);
3938 if (ret) {
3939 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003940 "VSI seid %d Rx ring %d %sable timeout\n",
3941 vsi->seid, pf_q, (enable ? "en" : "dis"));
Neerav Parikh23527302014-06-03 23:50:15 +00003942 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003943 }
3944 }
3945
Neerav Parikh23527302014-06-03 23:50:15 +00003946 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003947}
3948
3949/**
3950 * i40e_vsi_control_rings - Start or stop a VSI's rings
3951 * @vsi: the VSI being configured
3952 * @enable: start or stop the rings
3953 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00003954int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003955{
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00003956 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003957
3958 /* do rx first for enable and last for disable */
3959 if (request) {
3960 ret = i40e_vsi_control_rx(vsi, request);
3961 if (ret)
3962 return ret;
3963 ret = i40e_vsi_control_tx(vsi, request);
3964 } else {
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00003965 /* Ignore return value, we need to shutdown whatever we can */
3966 i40e_vsi_control_tx(vsi, request);
3967 i40e_vsi_control_rx(vsi, request);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003968 }
3969
3970 return ret;
3971}
3972
3973/**
3974 * i40e_vsi_free_irq - Free the irq association with the OS
3975 * @vsi: the VSI being configured
3976 **/
3977static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
3978{
3979 struct i40e_pf *pf = vsi->back;
3980 struct i40e_hw *hw = &pf->hw;
3981 int base = vsi->base_vector;
3982 u32 val, qp;
3983 int i;
3984
3985 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3986 if (!vsi->q_vectors)
3987 return;
3988
Shannon Nelson63741842014-04-23 04:50:16 +00003989 if (!vsi->irqs_ready)
3990 return;
3991
3992 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003993 for (i = 0; i < vsi->num_q_vectors; i++) {
3994 u16 vector = i + base;
3995
3996 /* free only the irqs that were actually requested */
Shannon Nelson78681b12013-11-28 06:39:36 +00003997 if (!vsi->q_vectors[i] ||
3998 !vsi->q_vectors[i]->num_ringpairs)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003999 continue;
4000
4001 /* clear the affinity_mask in the IRQ descriptor */
4002 irq_set_affinity_hint(pf->msix_entries[vector].vector,
4003 NULL);
4004 free_irq(pf->msix_entries[vector].vector,
Alexander Duyck493fb302013-09-28 07:01:44 +00004005 vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004006
4007 /* Tear down the interrupt queue link list
4008 *
4009 * We know that they come in pairs and always
4010 * the Rx first, then the Tx. To clear the
4011 * link list, stick the EOL value into the
4012 * next_q field of the registers.
4013 */
4014 val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
4015 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4016 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4017 val |= I40E_QUEUE_END_OF_LIST
4018 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4019 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
4020
4021 while (qp != I40E_QUEUE_END_OF_LIST) {
4022 u32 next;
4023
4024 val = rd32(hw, I40E_QINT_RQCTL(qp));
4025
4026 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4027 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4028 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4029 I40E_QINT_RQCTL_INTEVENT_MASK);
4030
4031 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4032 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4033
4034 wr32(hw, I40E_QINT_RQCTL(qp), val);
4035
4036 val = rd32(hw, I40E_QINT_TQCTL(qp));
4037
4038 next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
4039 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
4040
4041 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4042 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4043 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4044 I40E_QINT_TQCTL_INTEVENT_MASK);
4045
4046 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4047 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4048
4049 wr32(hw, I40E_QINT_TQCTL(qp), val);
4050 qp = next;
4051 }
4052 }
4053 } else {
4054 free_irq(pf->pdev->irq, pf);
4055
4056 val = rd32(hw, I40E_PFINT_LNKLST0);
4057 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4058 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4059 val |= I40E_QUEUE_END_OF_LIST
4060 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
4061 wr32(hw, I40E_PFINT_LNKLST0, val);
4062
4063 val = rd32(hw, I40E_QINT_RQCTL(qp));
4064 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4065 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4066 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4067 I40E_QINT_RQCTL_INTEVENT_MASK);
4068
4069 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4070 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4071
4072 wr32(hw, I40E_QINT_RQCTL(qp), val);
4073
4074 val = rd32(hw, I40E_QINT_TQCTL(qp));
4075
4076 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4077 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4078 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4079 I40E_QINT_TQCTL_INTEVENT_MASK);
4080
4081 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4082 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4083
4084 wr32(hw, I40E_QINT_TQCTL(qp), val);
4085 }
4086}
4087
4088/**
Alexander Duyck493fb302013-09-28 07:01:44 +00004089 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4090 * @vsi: the VSI being configured
4091 * @v_idx: Index of vector to be freed
4092 *
4093 * This function frees the memory allocated to the q_vector. In addition if
4094 * NAPI is enabled it will delete any references to the NAPI struct prior
4095 * to freeing the q_vector.
4096 **/
4097static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
4098{
4099 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00004100 struct i40e_ring *ring;
Alexander Duyck493fb302013-09-28 07:01:44 +00004101
4102 if (!q_vector)
4103 return;
4104
4105 /* disassociate q_vector from rings */
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00004106 i40e_for_each_ring(ring, q_vector->tx)
4107 ring->q_vector = NULL;
4108
4109 i40e_for_each_ring(ring, q_vector->rx)
4110 ring->q_vector = NULL;
Alexander Duyck493fb302013-09-28 07:01:44 +00004111
4112 /* only VSI w/ an associated netdev is set up w/ NAPI */
4113 if (vsi->netdev)
4114 netif_napi_del(&q_vector->napi);
4115
4116 vsi->q_vectors[v_idx] = NULL;
4117
4118 kfree_rcu(q_vector, rcu);
4119}
4120
4121/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004122 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4123 * @vsi: the VSI being un-configured
4124 *
4125 * This frees the memory allocated to the q_vectors and
4126 * deletes references to the NAPI struct.
4127 **/
4128static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
4129{
4130 int v_idx;
4131
Alexander Duyck493fb302013-09-28 07:01:44 +00004132 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
4133 i40e_free_q_vector(vsi, v_idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004134}
4135
4136/**
4137 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4138 * @pf: board private structure
4139 **/
4140static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
4141{
4142 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4143 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4144 pci_disable_msix(pf->pdev);
4145 kfree(pf->msix_entries);
4146 pf->msix_entries = NULL;
Shannon Nelson3b444392015-02-26 16:15:57 +00004147 kfree(pf->irq_pile);
4148 pf->irq_pile = NULL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004149 } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
4150 pci_disable_msi(pf->pdev);
4151 }
4152 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
4153}
4154
4155/**
4156 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4157 * @pf: board private structure
4158 *
4159 * We go through and clear interrupt specific resources and reset the structure
4160 * to pre-load conditions
4161 **/
4162static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
4163{
4164 int i;
4165
Shannon Nelsone1477582015-02-21 06:44:33 +00004166 i40e_stop_misc_vector(pf);
4167 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4168 synchronize_irq(pf->msix_entries[0].vector);
4169 free_irq(pf->msix_entries[0].vector, pf);
4170 }
4171
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004172 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
Mitch Williams505682c2014-05-20 08:01:37 +00004173 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004174 if (pf->vsi[i])
4175 i40e_vsi_free_q_vectors(pf->vsi[i]);
4176 i40e_reset_interrupt_capability(pf);
4177}
4178
4179/**
4180 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4181 * @vsi: the VSI being configured
4182 **/
4183static void i40e_napi_enable_all(struct i40e_vsi *vsi)
4184{
4185 int q_idx;
4186
4187 if (!vsi->netdev)
4188 return;
4189
4190 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
Alexander Duyck493fb302013-09-28 07:01:44 +00004191 napi_enable(&vsi->q_vectors[q_idx]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004192}
4193
4194/**
4195 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4196 * @vsi: the VSI being configured
4197 **/
4198static void i40e_napi_disable_all(struct i40e_vsi *vsi)
4199{
4200 int q_idx;
4201
4202 if (!vsi->netdev)
4203 return;
4204
4205 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
Alexander Duyck493fb302013-09-28 07:01:44 +00004206 napi_disable(&vsi->q_vectors[q_idx]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004207}
4208
4209/**
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004210 * i40e_vsi_close - Shut down a VSI
4211 * @vsi: the vsi to be quelled
4212 **/
4213static void i40e_vsi_close(struct i40e_vsi *vsi)
4214{
4215 if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
4216 i40e_down(vsi);
4217 i40e_vsi_free_irq(vsi);
4218 i40e_vsi_free_tx_resources(vsi);
4219 i40e_vsi_free_rx_resources(vsi);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04004220 vsi->current_netdev_flags = 0;
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004221}
4222
4223/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004224 * i40e_quiesce_vsi - Pause a given VSI
4225 * @vsi: the VSI being paused
4226 **/
4227static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
4228{
4229 if (test_bit(__I40E_DOWN, &vsi->state))
4230 return;
4231
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004232 /* No need to disable FCoE VSI when Tx suspended */
4233 if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) &&
4234 vsi->type == I40E_VSI_FCOE) {
4235 dev_dbg(&vsi->back->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004236 "VSI seid %d skipping FCoE VSI disable\n", vsi->seid);
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004237 return;
4238 }
4239
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004240 set_bit(__I40E_NEEDS_RESTART, &vsi->state);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004241 if (vsi->netdev && netif_running(vsi->netdev))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004242 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004243 else
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004244 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004245}
4246
4247/**
4248 * i40e_unquiesce_vsi - Resume a given VSI
4249 * @vsi: the VSI being resumed
4250 **/
4251static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
4252{
4253 if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
4254 return;
4255
4256 clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
4257 if (vsi->netdev && netif_running(vsi->netdev))
4258 vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
4259 else
Shannon Nelson8276f752014-03-14 07:32:27 +00004260 i40e_vsi_open(vsi); /* this clears the DOWN bit */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004261}
4262
4263/**
4264 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4265 * @pf: the PF
4266 **/
4267static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
4268{
4269 int v;
4270
Mitch Williams505682c2014-05-20 08:01:37 +00004271 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004272 if (pf->vsi[v])
4273 i40e_quiesce_vsi(pf->vsi[v]);
4274 }
4275}
4276
4277/**
4278 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4279 * @pf: the PF
4280 **/
4281static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
4282{
4283 int v;
4284
Mitch Williams505682c2014-05-20 08:01:37 +00004285 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004286 if (pf->vsi[v])
4287 i40e_unquiesce_vsi(pf->vsi[v]);
4288 }
4289}
4290
Neerav Parikh69129dc2014-11-12 00:18:46 +00004291#ifdef CONFIG_I40E_DCB
4292/**
4293 * i40e_vsi_wait_txq_disabled - Wait for VSI's queues to be disabled
4294 * @vsi: the VSI being configured
4295 *
4296 * This function waits for the given VSI's Tx queues to be disabled.
4297 **/
4298static int i40e_vsi_wait_txq_disabled(struct i40e_vsi *vsi)
4299{
4300 struct i40e_pf *pf = vsi->back;
4301 int i, pf_q, ret;
4302
4303 pf_q = vsi->base_queue;
4304 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4305 /* Check and wait for the disable status of the queue */
4306 ret = i40e_pf_txq_wait(pf, pf_q, false);
4307 if (ret) {
4308 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004309 "VSI seid %d Tx ring %d disable timeout\n",
4310 vsi->seid, pf_q);
Neerav Parikh69129dc2014-11-12 00:18:46 +00004311 return ret;
4312 }
4313 }
4314
4315 return 0;
4316}
4317
4318/**
4319 * i40e_pf_wait_txq_disabled - Wait for all queues of PF VSIs to be disabled
4320 * @pf: the PF
4321 *
4322 * This function waits for the Tx queues to be in disabled state for all the
4323 * VSIs that are managed by this PF.
4324 **/
4325static int i40e_pf_wait_txq_disabled(struct i40e_pf *pf)
4326{
4327 int v, ret = 0;
4328
4329 for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004330 /* No need to wait for FCoE VSI queues */
4331 if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) {
Neerav Parikh69129dc2014-11-12 00:18:46 +00004332 ret = i40e_vsi_wait_txq_disabled(pf->vsi[v]);
4333 if (ret)
4334 break;
4335 }
4336 }
4337
4338 return ret;
4339}
4340
4341#endif
Kiran Patilb03a8c12015-09-24 18:13:15 -04004342
4343/**
4344 * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
4345 * @q_idx: TX queue number
4346 * @vsi: Pointer to VSI struct
4347 *
4348 * This function checks specified queue for given VSI. Detects hung condition.
4349 * Sets hung bit since it is two step process. Before next run of service task
4350 * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not,
4351 * hung condition remain unchanged and during subsequent run, this function
4352 * issues SW interrupt to recover from hung condition.
4353 **/
4354static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
4355{
4356 struct i40e_ring *tx_ring = NULL;
4357 struct i40e_pf *pf;
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004358 u32 head, val, tx_pending_hw;
Kiran Patilb03a8c12015-09-24 18:13:15 -04004359 int i;
4360
4361 pf = vsi->back;
4362
4363 /* now that we have an index, find the tx_ring struct */
4364 for (i = 0; i < vsi->num_queue_pairs; i++) {
4365 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
4366 if (q_idx == vsi->tx_rings[i]->queue_index) {
4367 tx_ring = vsi->tx_rings[i];
4368 break;
4369 }
4370 }
4371 }
4372
4373 if (!tx_ring)
4374 return;
4375
4376 /* Read interrupt register */
4377 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
4378 val = rd32(&pf->hw,
4379 I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
4380 tx_ring->vsi->base_vector - 1));
4381 else
4382 val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
4383
4384 head = i40e_get_head(tx_ring);
4385
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004386 tx_pending_hw = i40e_get_tx_pending(tx_ring, false);
Kiran Patilb03a8c12015-09-24 18:13:15 -04004387
Kiran Patil9c6c1252015-11-06 15:26:02 -08004388 /* HW is done executing descriptors, updated HEAD write back,
4389 * but SW hasn't processed those descriptors. If interrupt is
4390 * not generated from this point ON, it could result into
4391 * dev_watchdog detecting timeout on those netdev_queue,
4392 * hence proactively trigger SW interrupt.
Kiran Patilb03a8c12015-09-24 18:13:15 -04004393 */
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004394 if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
Kiran Patil9c6c1252015-11-06 15:26:02 -08004395 /* NAPI Poll didn't run and clear since it was set */
4396 if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT,
4397 &tx_ring->q_vector->hung_detected)) {
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004398 netdev_info(vsi->netdev, "VSI_seid %d, Hung TX queue %d, tx_pending_hw: %d, NTC:0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x\n",
4399 vsi->seid, q_idx, tx_pending_hw,
Kiran Patil9c6c1252015-11-06 15:26:02 -08004400 tx_ring->next_to_clean, head,
4401 tx_ring->next_to_use,
4402 readl(tx_ring->tail));
4403 netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n",
4404 vsi->seid, q_idx, val);
4405 i40e_force_wb(vsi, tx_ring->q_vector);
4406 } else {
4407 /* First Chance - detected possible hung */
4408 set_bit(I40E_Q_VECTOR_HUNG_DETECT,
4409 &tx_ring->q_vector->hung_detected);
4410 }
4411 }
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004412
4413 /* This is the case where we have interrupts missing,
4414 * so the tx_pending in HW will most likely be 0, but we
4415 * will have tx_pending in SW since the WB happened but the
4416 * interrupt got lost.
4417 */
4418 if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) &&
4419 (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
4420 if (napi_reschedule(&tx_ring->q_vector->napi))
4421 tx_ring->tx_stats.tx_lost_interrupt++;
4422 }
Kiran Patilb03a8c12015-09-24 18:13:15 -04004423}
4424
4425/**
4426 * i40e_detect_recover_hung - Function to detect and recover hung_queues
4427 * @pf: pointer to PF struct
4428 *
4429 * LAN VSI has netdev and netdev has TX queues. This function is to check
4430 * each of those TX queues if they are hung, trigger recovery by issuing
4431 * SW interrupt.
4432 **/
4433static void i40e_detect_recover_hung(struct i40e_pf *pf)
4434{
4435 struct net_device *netdev;
4436 struct i40e_vsi *vsi;
4437 int i;
4438
4439 /* Only for LAN VSI */
4440 vsi = pf->vsi[pf->lan_vsi];
4441
4442 if (!vsi)
4443 return;
4444
4445 /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
4446 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
4447 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
4448 return;
4449
4450 /* Make sure type is MAIN VSI */
4451 if (vsi->type != I40E_VSI_MAIN)
4452 return;
4453
4454 netdev = vsi->netdev;
4455 if (!netdev)
4456 return;
4457
4458 /* Bail out if netif_carrier is not OK */
4459 if (!netif_carrier_ok(netdev))
4460 return;
4461
4462 /* Go thru' TX queues for netdev */
4463 for (i = 0; i < netdev->num_tx_queues; i++) {
4464 struct netdev_queue *q;
4465
4466 q = netdev_get_tx_queue(netdev, i);
4467 if (q)
4468 i40e_detect_recover_hung_queue(i, vsi);
4469 }
4470}
4471
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004472/**
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004473 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00004474 * @pf: pointer to PF
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004475 *
4476 * Get TC map for ISCSI PF type that will include iSCSI TC
4477 * and LAN TC.
4478 **/
4479static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
4480{
4481 struct i40e_dcb_app_priority_table app;
4482 struct i40e_hw *hw = &pf->hw;
4483 u8 enabled_tc = 1; /* TC0 is always enabled */
4484 u8 tc, i;
4485 /* Get the iSCSI APP TLV */
4486 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4487
4488 for (i = 0; i < dcbcfg->numapps; i++) {
4489 app = dcbcfg->app[i];
4490 if (app.selector == I40E_APP_SEL_TCPIP &&
4491 app.protocolid == I40E_APP_PROTOID_ISCSI) {
4492 tc = dcbcfg->etscfg.prioritytable[app.priority];
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004493 enabled_tc |= BIT(tc);
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004494 break;
4495 }
4496 }
4497
4498 return enabled_tc;
4499}
4500
4501/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004502 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4503 * @dcbcfg: the corresponding DCBx configuration structure
4504 *
4505 * Return the number of TCs from given DCBx configuration
4506 **/
4507static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
4508{
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004509 u8 num_tc = 0;
4510 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004511
4512 /* Scan the ETS Config Priority Table to find
4513 * traffic class enabled for a given priority
4514 * and use the traffic class index to get the
4515 * number of traffic classes enabled
4516 */
4517 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
4518 if (dcbcfg->etscfg.prioritytable[i] > num_tc)
4519 num_tc = dcbcfg->etscfg.prioritytable[i];
4520 }
4521
4522 /* Traffic class index starts from zero so
4523 * increment to return the actual count
4524 */
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004525 return num_tc + 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004526}
4527
4528/**
4529 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4530 * @dcbcfg: the corresponding DCBx configuration structure
4531 *
4532 * Query the current DCB configuration and return the number of
4533 * traffic classes enabled from the given DCBX config
4534 **/
4535static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
4536{
4537 u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
4538 u8 enabled_tc = 1;
4539 u8 i;
4540
4541 for (i = 0; i < num_tc; i++)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004542 enabled_tc |= BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004543
4544 return enabled_tc;
4545}
4546
4547/**
4548 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4549 * @pf: PF being queried
4550 *
4551 * Return number of traffic classes enabled for the given PF
4552 **/
4553static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
4554{
4555 struct i40e_hw *hw = &pf->hw;
4556 u8 i, enabled_tc;
4557 u8 num_tc = 0;
4558 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4559
4560 /* If DCB is not enabled then always in single TC */
4561 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
4562 return 1;
4563
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004564 /* SFP mode will be enabled for all TCs on port */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004565 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4566 return i40e_dcb_get_num_tc(dcbcfg);
4567
4568 /* MFP mode return count of enabled TCs for this PF */
4569 if (pf->hw.func_caps.iscsi)
4570 enabled_tc = i40e_get_iscsi_tc_map(pf);
4571 else
Neerav Parikhfc51de92015-02-24 06:58:53 +00004572 return 1; /* Only TC0 */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004573
4574 /* At least have TC0 */
4575 enabled_tc = (enabled_tc ? enabled_tc : 0x1);
4576 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004577 if (enabled_tc & BIT(i))
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004578 num_tc++;
4579 }
4580 return num_tc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004581}
4582
4583/**
4584 * i40e_pf_get_default_tc - Get bitmap for first enabled TC
4585 * @pf: PF being queried
4586 *
4587 * Return a bitmap for first enabled traffic class for this PF.
4588 **/
4589static u8 i40e_pf_get_default_tc(struct i40e_pf *pf)
4590{
4591 u8 enabled_tc = pf->hw.func_caps.enabled_tcmap;
4592 u8 i = 0;
4593
4594 if (!enabled_tc)
4595 return 0x1; /* TC0 */
4596
4597 /* Find the first enabled TC */
4598 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004599 if (enabled_tc & BIT(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004600 break;
4601 }
4602
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004603 return BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004604}
4605
4606/**
4607 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4608 * @pf: PF being queried
4609 *
4610 * Return a bitmap for enabled traffic classes for this PF.
4611 **/
4612static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
4613{
4614 /* If DCB is not enabled for this PF then just return default TC */
4615 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
4616 return i40e_pf_get_default_tc(pf);
4617
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004618 /* SFP mode we want PF to be enabled for all TCs */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004619 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4620 return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
4621
Neerav Parikhfc51de92015-02-24 06:58:53 +00004622 /* MFP enabled and iSCSI PF type */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004623 if (pf->hw.func_caps.iscsi)
4624 return i40e_get_iscsi_tc_map(pf);
4625 else
Neerav Parikhfc51de92015-02-24 06:58:53 +00004626 return i40e_pf_get_default_tc(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004627}
4628
4629/**
4630 * i40e_vsi_get_bw_info - Query VSI BW Information
4631 * @vsi: the VSI being queried
4632 *
4633 * Returns 0 on success, negative value on failure
4634 **/
4635static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
4636{
4637 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
4638 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
4639 struct i40e_pf *pf = vsi->back;
4640 struct i40e_hw *hw = &pf->hw;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004641 i40e_status ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004642 u32 tc_bw_max;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004643 int i;
4644
4645 /* Get the VSI level BW configuration */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004646 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
4647 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004648 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004649 "couldn't get PF vsi bw config, err %s aq_err %s\n",
4650 i40e_stat_str(&pf->hw, ret),
4651 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004652 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004653 }
4654
4655 /* Get the VSI level BW configuration per TC */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004656 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
4657 NULL);
4658 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004659 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004660 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
4661 i40e_stat_str(&pf->hw, ret),
4662 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004663 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004664 }
4665
4666 if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
4667 dev_info(&pf->pdev->dev,
4668 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4669 bw_config.tc_valid_bits,
4670 bw_ets_config.tc_valid_bits);
4671 /* Still continuing */
4672 }
4673
4674 vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
4675 vsi->bw_max_quanta = bw_config.max_bw;
4676 tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
4677 (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
4678 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4679 vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
4680 vsi->bw_ets_limit_credits[i] =
4681 le16_to_cpu(bw_ets_config.credits[i]);
4682 /* 3 bits out of 4 for each TC */
4683 vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
4684 }
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004685
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004686 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004687}
4688
4689/**
4690 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
4691 * @vsi: the VSI being configured
4692 * @enabled_tc: TC bitmap
4693 * @bw_credits: BW shared credits per TC
4694 *
4695 * Returns 0 on success, negative value on failure
4696 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004697static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004698 u8 *bw_share)
4699{
4700 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004701 i40e_status ret;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004702 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004703
4704 bw_data.tc_valid_bits = enabled_tc;
4705 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4706 bw_data.tc_bw_credits[i] = bw_share[i];
4707
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004708 ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
4709 NULL);
4710 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004711 dev_info(&vsi->back->pdev->dev,
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004712 "AQ command Config VSI BW allocation per TC failed = %d\n",
4713 vsi->back->hw.aq.asq_last_status);
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004714 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004715 }
4716
4717 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4718 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
4719
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004720 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004721}
4722
4723/**
4724 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
4725 * @vsi: the VSI being configured
4726 * @enabled_tc: TC map to be enabled
4727 *
4728 **/
4729static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4730{
4731 struct net_device *netdev = vsi->netdev;
4732 struct i40e_pf *pf = vsi->back;
4733 struct i40e_hw *hw = &pf->hw;
4734 u8 netdev_tc = 0;
4735 int i;
4736 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4737
4738 if (!netdev)
4739 return;
4740
4741 if (!enabled_tc) {
4742 netdev_reset_tc(netdev);
4743 return;
4744 }
4745
4746 /* Set up actual enabled TCs on the VSI */
4747 if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
4748 return;
4749
4750 /* set per TC queues for the VSI */
4751 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4752 /* Only set TC queues for enabled tcs
4753 *
4754 * e.g. For a VSI that has TC0 and TC3 enabled the
4755 * enabled_tc bitmap would be 0x00001001; the driver
4756 * will set the numtc for netdev as 2 that will be
4757 * referenced by the netdev layer as TC 0 and 1.
4758 */
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004759 if (vsi->tc_config.enabled_tc & BIT(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004760 netdev_set_tc_queue(netdev,
4761 vsi->tc_config.tc_info[i].netdev_tc,
4762 vsi->tc_config.tc_info[i].qcount,
4763 vsi->tc_config.tc_info[i].qoffset);
4764 }
4765
4766 /* Assign UP2TC map for the VSI */
4767 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
4768 /* Get the actual TC# for the UP */
4769 u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
4770 /* Get the mapped netdev TC# for the UP */
4771 netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
4772 netdev_set_prio_tc_map(netdev, i, netdev_tc);
4773 }
4774}
4775
4776/**
4777 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4778 * @vsi: the VSI being configured
4779 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4780 **/
4781static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
4782 struct i40e_vsi_context *ctxt)
4783{
4784 /* copy just the sections touched not the entire info
4785 * since not all sections are valid as returned by
4786 * update vsi params
4787 */
4788 vsi->info.mapping_flags = ctxt->info.mapping_flags;
4789 memcpy(&vsi->info.queue_mapping,
4790 &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
4791 memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
4792 sizeof(vsi->info.tc_mapping));
4793}
4794
4795/**
4796 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4797 * @vsi: VSI to be configured
4798 * @enabled_tc: TC bitmap
4799 *
4800 * This configures a particular VSI for TCs that are mapped to the
4801 * given TC bitmap. It uses default bandwidth share for TCs across
4802 * VSIs to configure TC for a particular VSI.
4803 *
4804 * NOTE:
4805 * It is expected that the VSI queues have been quisced before calling
4806 * this function.
4807 **/
4808static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4809{
4810 u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
4811 struct i40e_vsi_context ctxt;
4812 int ret = 0;
4813 int i;
4814
4815 /* Check if enabled_tc is same as existing or new TCs */
4816 if (vsi->tc_config.enabled_tc == enabled_tc)
4817 return ret;
4818
4819 /* Enable ETS TCs with equal BW Share for now across all VSIs */
4820 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004821 if (enabled_tc & BIT(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004822 bw_share[i] = 1;
4823 }
4824
4825 ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
4826 if (ret) {
4827 dev_info(&vsi->back->pdev->dev,
4828 "Failed configuring TC map %d for VSI %d\n",
4829 enabled_tc, vsi->seid);
4830 goto out;
4831 }
4832
4833 /* Update Queue Pairs Mapping for currently enabled UPs */
4834 ctxt.seid = vsi->seid;
4835 ctxt.pf_num = vsi->back->hw.pf_id;
4836 ctxt.vf_num = 0;
4837 ctxt.uplink_seid = vsi->uplink_seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07004838 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004839 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
4840
4841 /* Update the VSI after updating the VSI queue-mapping information */
4842 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
4843 if (ret) {
4844 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004845 "Update vsi tc config failed, err %s aq_err %s\n",
4846 i40e_stat_str(&vsi->back->hw, ret),
4847 i40e_aq_str(&vsi->back->hw,
4848 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004849 goto out;
4850 }
4851 /* update the local VSI info with updated queue map */
4852 i40e_vsi_update_queue_map(vsi, &ctxt);
4853 vsi->info.valid_sections = 0;
4854
4855 /* Update current VSI BW information */
4856 ret = i40e_vsi_get_bw_info(vsi);
4857 if (ret) {
4858 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004859 "Failed updating vsi bw info, err %s aq_err %s\n",
4860 i40e_stat_str(&vsi->back->hw, ret),
4861 i40e_aq_str(&vsi->back->hw,
4862 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004863 goto out;
4864 }
4865
4866 /* Update the netdev TC setup */
4867 i40e_vsi_config_netdev_tc(vsi, enabled_tc);
4868out:
4869 return ret;
4870}
4871
4872/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004873 * i40e_veb_config_tc - Configure TCs for given VEB
4874 * @veb: given VEB
4875 * @enabled_tc: TC bitmap
4876 *
4877 * Configures given TC bitmap for VEB (switching) element
4878 **/
4879int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
4880{
4881 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
4882 struct i40e_pf *pf = veb->pf;
4883 int ret = 0;
4884 int i;
4885
4886 /* No TCs or already enabled TCs just return */
4887 if (!enabled_tc || veb->enabled_tc == enabled_tc)
4888 return ret;
4889
4890 bw_data.tc_valid_bits = enabled_tc;
4891 /* bw_data.absolute_credits is not set (relative) */
4892
4893 /* Enable ETS TCs with equal BW Share for now */
4894 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004895 if (enabled_tc & BIT(i))
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004896 bw_data.tc_bw_share_credits[i] = 1;
4897 }
4898
4899 ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
4900 &bw_data, NULL);
4901 if (ret) {
4902 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004903 "VEB bw config failed, err %s aq_err %s\n",
4904 i40e_stat_str(&pf->hw, ret),
4905 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004906 goto out;
4907 }
4908
4909 /* Update the BW information */
4910 ret = i40e_veb_get_bw_info(veb);
4911 if (ret) {
4912 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004913 "Failed getting veb bw config, err %s aq_err %s\n",
4914 i40e_stat_str(&pf->hw, ret),
4915 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004916 }
4917
4918out:
4919 return ret;
4920}
4921
4922#ifdef CONFIG_I40E_DCB
4923/**
4924 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
4925 * @pf: PF struct
4926 *
4927 * Reconfigure VEB/VSIs on a given PF; it is assumed that
4928 * the caller would've quiesce all the VSIs before calling
4929 * this function
4930 **/
4931static void i40e_dcb_reconfigure(struct i40e_pf *pf)
4932{
4933 u8 tc_map = 0;
4934 int ret;
4935 u8 v;
4936
4937 /* Enable the TCs available on PF to all VEBs */
4938 tc_map = i40e_pf_get_tc_map(pf);
4939 for (v = 0; v < I40E_MAX_VEB; v++) {
4940 if (!pf->veb[v])
4941 continue;
4942 ret = i40e_veb_config_tc(pf->veb[v], tc_map);
4943 if (ret) {
4944 dev_info(&pf->pdev->dev,
4945 "Failed configuring TC for VEB seid=%d\n",
4946 pf->veb[v]->seid);
4947 /* Will try to configure as many components */
4948 }
4949 }
4950
4951 /* Update each VSI */
Mitch Williams505682c2014-05-20 08:01:37 +00004952 for (v = 0; v < pf->num_alloc_vsi; v++) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004953 if (!pf->vsi[v])
4954 continue;
4955
4956 /* - Enable all TCs for the LAN VSI
Vasu Dev38e00432014-08-01 13:27:03 -07004957#ifdef I40E_FCOE
4958 * - For FCoE VSI only enable the TC configured
4959 * as per the APP TLV
4960#endif
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004961 * - For all others keep them at TC0 for now
4962 */
4963 if (v == pf->lan_vsi)
4964 tc_map = i40e_pf_get_tc_map(pf);
4965 else
4966 tc_map = i40e_pf_get_default_tc(pf);
Vasu Dev38e00432014-08-01 13:27:03 -07004967#ifdef I40E_FCOE
4968 if (pf->vsi[v]->type == I40E_VSI_FCOE)
4969 tc_map = i40e_get_fcoe_tc_map(pf);
4970#endif /* #ifdef I40E_FCOE */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004971
4972 ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
4973 if (ret) {
4974 dev_info(&pf->pdev->dev,
4975 "Failed configuring TC for VSI seid=%d\n",
4976 pf->vsi[v]->seid);
4977 /* Will try to configure as many components */
4978 } else {
Neerav Parikh0672a092014-04-01 07:11:47 +00004979 /* Re-configure VSI vectors based on updated TC map */
4980 i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004981 if (pf->vsi[v]->netdev)
4982 i40e_dcbnl_set_all(pf->vsi[v]);
4983 }
4984 }
4985}
4986
4987/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00004988 * i40e_resume_port_tx - Resume port Tx
4989 * @pf: PF struct
4990 *
4991 * Resume a port's Tx and issue a PF reset in case of failure to
4992 * resume.
4993 **/
4994static int i40e_resume_port_tx(struct i40e_pf *pf)
4995{
4996 struct i40e_hw *hw = &pf->hw;
4997 int ret;
4998
4999 ret = i40e_aq_resume_port_tx(hw, NULL);
5000 if (ret) {
5001 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005002 "Resume Port Tx failed, err %s aq_err %s\n",
5003 i40e_stat_str(&pf->hw, ret),
5004 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005005 /* Schedule PF reset to recover */
5006 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
5007 i40e_service_event_schedule(pf);
5008 }
5009
5010 return ret;
5011}
5012
5013/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005014 * i40e_init_pf_dcb - Initialize DCB configuration
5015 * @pf: PF being configured
5016 *
5017 * Query the current DCB configuration and cache it
5018 * in the hardware structure
5019 **/
5020static int i40e_init_pf_dcb(struct i40e_pf *pf)
5021{
5022 struct i40e_hw *hw = &pf->hw;
5023 int err = 0;
5024
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00005025 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
Neerav Parikhf1bbad32016-01-13 16:51:39 -08005026 if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT)
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00005027 goto out;
5028
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005029 /* Get the initial DCB configuration */
5030 err = i40e_init_dcb(hw);
5031 if (!err) {
5032 /* Device/Function is not DCBX capable */
5033 if ((!hw->func_caps.dcb) ||
5034 (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
5035 dev_info(&pf->pdev->dev,
5036 "DCBX offload is not supported or is disabled for this PF.\n");
5037
5038 if (pf->flags & I40E_FLAG_MFP_ENABLED)
5039 goto out;
5040
5041 } else {
5042 /* When status is not DISABLED then DCBX in FW */
5043 pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
5044 DCB_CAP_DCBX_VER_IEEE;
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005045
5046 pf->flags |= I40E_FLAG_DCB_CAPABLE;
5047 /* Enable DCB tagging only when more than one TC */
5048 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
5049 pf->flags |= I40E_FLAG_DCB_ENABLED;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005050 dev_dbg(&pf->pdev->dev,
5051 "DCBX offload is supported for this PF.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005052 }
Neerav Parikh014269f2014-04-01 07:11:48 +00005053 } else {
Shannon Nelsonaebfc812014-12-11 07:06:38 +00005054 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005055 "Query for DCB configuration failed, err %s aq_err %s\n",
5056 i40e_stat_str(&pf->hw, err),
5057 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005058 }
5059
5060out:
5061 return err;
5062}
5063#endif /* CONFIG_I40E_DCB */
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005064#define SPEED_SIZE 14
5065#define FC_SIZE 8
5066/**
5067 * i40e_print_link_message - print link up or down
5068 * @vsi: the VSI for which link needs a message
5069 */
Matt Jaredc156f852015-08-27 11:42:39 -04005070void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005071{
Shannon Nelsona9165492015-09-03 17:19:00 -04005072 char *speed = "Unknown";
5073 char *fc = "Unknown";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005074
Matt Jaredc156f852015-08-27 11:42:39 -04005075 if (vsi->current_isup == isup)
5076 return;
5077 vsi->current_isup = isup;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005078 if (!isup) {
5079 netdev_info(vsi->netdev, "NIC Link is Down\n");
5080 return;
5081 }
5082
Greg Rose148c2d82014-12-11 07:06:27 +00005083 /* Warn user if link speed on NPAR enabled partition is not at
5084 * least 10GB
5085 */
5086 if (vsi->back->hw.func_caps.npar_enable &&
5087 (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
5088 vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
5089 netdev_warn(vsi->netdev,
5090 "The partition detected link speed that is less than 10Gbps\n");
5091
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005092 switch (vsi->back->hw.phy.link_info.link_speed) {
5093 case I40E_LINK_SPEED_40GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005094 speed = "40 G";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005095 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -07005096 case I40E_LINK_SPEED_20GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005097 speed = "20 G";
Jesse Brandeburgae24b402015-03-27 00:12:09 -07005098 break;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005099 case I40E_LINK_SPEED_10GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005100 speed = "10 G";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005101 break;
5102 case I40E_LINK_SPEED_1GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005103 speed = "1000 M";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005104 break;
Mitch Williams5960d332014-09-13 07:40:47 +00005105 case I40E_LINK_SPEED_100MB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005106 speed = "100 M";
Mitch Williams5960d332014-09-13 07:40:47 +00005107 break;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005108 default:
5109 break;
5110 }
5111
5112 switch (vsi->back->hw.fc.current_mode) {
5113 case I40E_FC_FULL:
Shannon Nelsona9165492015-09-03 17:19:00 -04005114 fc = "RX/TX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005115 break;
5116 case I40E_FC_TX_PAUSE:
Shannon Nelsona9165492015-09-03 17:19:00 -04005117 fc = "TX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005118 break;
5119 case I40E_FC_RX_PAUSE:
Shannon Nelsona9165492015-09-03 17:19:00 -04005120 fc = "RX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005121 break;
5122 default:
Shannon Nelsona9165492015-09-03 17:19:00 -04005123 fc = "None";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005124 break;
5125 }
5126
Shannon Nelsona9165492015-09-03 17:19:00 -04005127 netdev_info(vsi->netdev, "NIC Link is Up %sbps Full Duplex, Flow Control: %s\n",
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005128 speed, fc);
5129}
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005130
5131/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005132 * i40e_up_complete - Finish the last steps of bringing up a connection
5133 * @vsi: the VSI being configured
5134 **/
5135static int i40e_up_complete(struct i40e_vsi *vsi)
5136{
5137 struct i40e_pf *pf = vsi->back;
5138 int err;
5139
5140 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
5141 i40e_vsi_configure_msix(vsi);
5142 else
5143 i40e_configure_msi_and_legacy(vsi);
5144
5145 /* start rings */
5146 err = i40e_vsi_control_rings(vsi, true);
5147 if (err)
5148 return err;
5149
5150 clear_bit(__I40E_DOWN, &vsi->state);
5151 i40e_napi_enable_all(vsi);
5152 i40e_vsi_enable_irq(vsi);
5153
5154 if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
5155 (vsi->netdev)) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005156 i40e_print_link_message(vsi, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005157 netif_tx_start_all_queues(vsi->netdev);
5158 netif_carrier_on(vsi->netdev);
Anjali Singhai6d779b42013-09-28 06:00:02 +00005159 } else if (vsi->netdev) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005160 i40e_print_link_message(vsi, false);
Carolyn Wyborny7b592f62014-07-10 07:58:19 +00005161 /* need to check for qualified module here*/
5162 if ((pf->hw.phy.link_info.link_info &
5163 I40E_AQ_MEDIA_AVAILABLE) &&
5164 (!(pf->hw.phy.link_info.an_info &
5165 I40E_AQ_QUALIFIED_MODULE)))
5166 netdev_err(vsi->netdev,
5167 "the driver failed to link because an unqualified module was detected.");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005168 }
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00005169
5170 /* replay FDIR SB filters */
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005171 if (vsi->type == I40E_VSI_FDIR) {
5172 /* reset fd counters */
5173 pf->fd_add_err = pf->fd_atr_cnt = 0;
5174 if (pf->fd_tcp_rule > 0) {
5175 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04005176 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5177 dev_info(&pf->pdev->dev, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005178 pf->fd_tcp_rule = 0;
5179 }
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00005180 i40e_fdir_filter_restore(vsi);
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005181 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005182 i40e_service_event_schedule(pf);
5183
5184 return 0;
5185}
5186
5187/**
5188 * i40e_vsi_reinit_locked - Reset the VSI
5189 * @vsi: the VSI being configured
5190 *
5191 * Rebuild the ring structs after some configuration
5192 * has changed, e.g. MTU size.
5193 **/
5194static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
5195{
5196 struct i40e_pf *pf = vsi->back;
5197
5198 WARN_ON(in_interrupt());
5199 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
5200 usleep_range(1000, 2000);
5201 i40e_down(vsi);
5202
5203 /* Give a VF some time to respond to the reset. The
5204 * two second wait is based upon the watchdog cycle in
5205 * the VF driver.
5206 */
5207 if (vsi->type == I40E_VSI_SRIOV)
5208 msleep(2000);
5209 i40e_up(vsi);
5210 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
5211}
5212
5213/**
5214 * i40e_up - Bring the connection back up after being down
5215 * @vsi: the VSI being configured
5216 **/
5217int i40e_up(struct i40e_vsi *vsi)
5218{
5219 int err;
5220
5221 err = i40e_vsi_configure(vsi);
5222 if (!err)
5223 err = i40e_up_complete(vsi);
5224
5225 return err;
5226}
5227
5228/**
5229 * i40e_down - Shutdown the connection processing
5230 * @vsi: the VSI being stopped
5231 **/
5232void i40e_down(struct i40e_vsi *vsi)
5233{
5234 int i;
5235
5236 /* It is assumed that the caller of this function
5237 * sets the vsi->state __I40E_DOWN bit.
5238 */
5239 if (vsi->netdev) {
5240 netif_carrier_off(vsi->netdev);
5241 netif_tx_disable(vsi->netdev);
5242 }
5243 i40e_vsi_disable_irq(vsi);
5244 i40e_vsi_control_rings(vsi, false);
5245 i40e_napi_disable_all(vsi);
5246
5247 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00005248 i40e_clean_tx_ring(vsi->tx_rings[i]);
5249 i40e_clean_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005250 }
5251}
5252
5253/**
5254 * i40e_setup_tc - configure multiple traffic classes
5255 * @netdev: net device to configure
5256 * @tc: number of traffic classes to enable
5257 **/
5258static int i40e_setup_tc(struct net_device *netdev, u8 tc)
5259{
5260 struct i40e_netdev_priv *np = netdev_priv(netdev);
5261 struct i40e_vsi *vsi = np->vsi;
5262 struct i40e_pf *pf = vsi->back;
5263 u8 enabled_tc = 0;
5264 int ret = -EINVAL;
5265 int i;
5266
5267 /* Check if DCB enabled to continue */
5268 if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
5269 netdev_info(netdev, "DCB is not enabled for adapter\n");
5270 goto exit;
5271 }
5272
5273 /* Check if MFP enabled */
5274 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
5275 netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
5276 goto exit;
5277 }
5278
5279 /* Check whether tc count is within enabled limit */
5280 if (tc > i40e_pf_get_num_tc(pf)) {
5281 netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
5282 goto exit;
5283 }
5284
5285 /* Generate TC map for number of tc requested */
5286 for (i = 0; i < tc; i++)
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08005287 enabled_tc |= BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005288
5289 /* Requesting same TC configuration as already enabled */
5290 if (enabled_tc == vsi->tc_config.enabled_tc)
5291 return 0;
5292
5293 /* Quiesce VSI queues */
5294 i40e_quiesce_vsi(vsi);
5295
5296 /* Configure VSI for enabled TCs */
5297 ret = i40e_vsi_config_tc(vsi, enabled_tc);
5298 if (ret) {
5299 netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
5300 vsi->seid);
5301 goto exit;
5302 }
5303
5304 /* Unquiesce VSI */
5305 i40e_unquiesce_vsi(vsi);
5306
5307exit:
5308 return ret;
5309}
5310
John Fastabende4c67342016-02-16 21:16:15 -08005311#ifdef I40E_FCOE
John Fastabend16e5cc62016-02-16 21:16:43 -08005312int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
5313 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -08005314#else
John Fastabend16e5cc62016-02-16 21:16:43 -08005315static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
5316 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -08005317#endif
5318{
John Fastabend16e5cc62016-02-16 21:16:43 -08005319 if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO)
John Fastabende4c67342016-02-16 21:16:15 -08005320 return -EINVAL;
John Fastabend16e5cc62016-02-16 21:16:43 -08005321 return i40e_setup_tc(netdev, tc->tc);
John Fastabende4c67342016-02-16 21:16:15 -08005322}
5323
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005324/**
5325 * i40e_open - Called when a network interface is made active
5326 * @netdev: network interface device structure
5327 *
5328 * The open entry point is called when a network interface is made
5329 * active by the system (IFF_UP). At this point all resources needed
5330 * for transmit and receive operations are allocated, the interrupt
5331 * handler is registered with the OS, the netdev watchdog subtask is
5332 * enabled, and the stack is notified that the interface is ready.
5333 *
5334 * Returns 0 on success, negative value on failure
5335 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005336int i40e_open(struct net_device *netdev)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005337{
5338 struct i40e_netdev_priv *np = netdev_priv(netdev);
5339 struct i40e_vsi *vsi = np->vsi;
5340 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005341 int err;
5342
Shannon Nelson4eb3f762014-03-06 08:59:58 +00005343 /* disallow open during test or if eeprom is broken */
5344 if (test_bit(__I40E_TESTING, &pf->state) ||
5345 test_bit(__I40E_BAD_EEPROM, &pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005346 return -EBUSY;
5347
5348 netif_carrier_off(netdev);
5349
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005350 err = i40e_vsi_open(vsi);
5351 if (err)
5352 return err;
5353
Jesse Brandeburg059dab62014-04-01 09:07:20 +00005354 /* configure global TSO hardware offload settings */
5355 wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
5356 TCP_FLAG_FIN) >> 16);
5357 wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
5358 TCP_FLAG_FIN |
5359 TCP_FLAG_CWR) >> 16);
5360 wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
5361
Singhai, Anjali6633d382015-12-03 23:49:31 -08005362#ifdef CONFIG_I40E_VXLAN
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005363 vxlan_get_rx_port(netdev);
5364#endif
Singhai, Anjalicd866602015-12-14 12:21:21 -08005365#ifdef CONFIG_I40E_GENEVE
Anjali Singhaia340c782016-01-06 11:49:28 -08005366 if (pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)
5367 geneve_get_rx_port(netdev);
Singhai, Anjalicd866602015-12-14 12:21:21 -08005368#endif
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005369
5370 return 0;
5371}
5372
5373/**
5374 * i40e_vsi_open -
5375 * @vsi: the VSI to open
5376 *
5377 * Finish initialization of the VSI.
5378 *
5379 * Returns 0 on success, negative value on failure
5380 **/
5381int i40e_vsi_open(struct i40e_vsi *vsi)
5382{
5383 struct i40e_pf *pf = vsi->back;
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00005384 char int_name[I40E_INT_NAME_STR_LEN];
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005385 int err;
5386
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005387 /* allocate descriptors */
5388 err = i40e_vsi_setup_tx_resources(vsi);
5389 if (err)
5390 goto err_setup_tx;
5391 err = i40e_vsi_setup_rx_resources(vsi);
5392 if (err)
5393 goto err_setup_rx;
5394
5395 err = i40e_vsi_configure(vsi);
5396 if (err)
5397 goto err_setup_rx;
5398
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00005399 if (vsi->netdev) {
5400 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
5401 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
5402 err = i40e_vsi_request_irq(vsi, int_name);
5403 if (err)
5404 goto err_setup_rx;
5405
5406 /* Notify the stack of the actual queue counts. */
5407 err = netif_set_real_num_tx_queues(vsi->netdev,
5408 vsi->num_queue_pairs);
5409 if (err)
5410 goto err_set_queues;
5411
5412 err = netif_set_real_num_rx_queues(vsi->netdev,
5413 vsi->num_queue_pairs);
5414 if (err)
5415 goto err_set_queues;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005416
5417 } else if (vsi->type == I40E_VSI_FDIR) {
Carolyn Wybornye240f672014-12-11 07:06:37 +00005418 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +00005419 dev_driver_string(&pf->pdev->dev),
5420 dev_name(&pf->pdev->dev));
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005421 err = i40e_vsi_request_irq(vsi, int_name);
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +00005422
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00005423 } else {
Jean Sacrence9ccb12014-05-01 14:31:18 +00005424 err = -EINVAL;
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005425 goto err_setup_rx;
5426 }
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00005427
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005428 err = i40e_up_complete(vsi);
5429 if (err)
5430 goto err_up_complete;
5431
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005432 return 0;
5433
5434err_up_complete:
5435 i40e_down(vsi);
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00005436err_set_queues:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005437 i40e_vsi_free_irq(vsi);
5438err_setup_rx:
5439 i40e_vsi_free_rx_resources(vsi);
5440err_setup_tx:
5441 i40e_vsi_free_tx_resources(vsi);
5442 if (vsi == pf->vsi[pf->lan_vsi])
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005443 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005444
5445 return err;
5446}
5447
5448/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005449 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00005450 * @pf: Pointer to PF
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005451 *
5452 * This function destroys the hlist where all the Flow Director
5453 * filters were saved.
5454 **/
5455static void i40e_fdir_filter_exit(struct i40e_pf *pf)
5456{
5457 struct i40e_fdir_filter *filter;
5458 struct hlist_node *node2;
5459
5460 hlist_for_each_entry_safe(filter, node2,
5461 &pf->fdir_filter_list, fdir_node) {
5462 hlist_del(&filter->fdir_node);
5463 kfree(filter);
5464 }
5465 pf->fdir_pf_active_filters = 0;
5466}
5467
5468/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005469 * i40e_close - Disables a network interface
5470 * @netdev: network interface device structure
5471 *
5472 * The close entry point is called when an interface is de-activated
5473 * by the OS. The hardware is still under the driver's control, but
5474 * this netdev interface is disabled.
5475 *
5476 * Returns 0, this is not allowed to fail
5477 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005478#ifdef I40E_FCOE
5479int i40e_close(struct net_device *netdev)
5480#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005481static int i40e_close(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -07005482#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005483{
5484 struct i40e_netdev_priv *np = netdev_priv(netdev);
5485 struct i40e_vsi *vsi = np->vsi;
5486
Shannon Nelson90ef8d42014-03-14 07:32:26 +00005487 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005488
5489 return 0;
5490}
5491
5492/**
5493 * i40e_do_reset - Start a PF or Core Reset sequence
5494 * @pf: board private structure
5495 * @reset_flags: which reset is requested
5496 *
5497 * The essential difference in resets is that the PF Reset
5498 * doesn't clear the packet buffers, doesn't reset the PE
5499 * firmware, and doesn't bother the other PFs on the chip.
5500 **/
5501void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
5502{
5503 u32 val;
5504
5505 WARN_ON(in_interrupt());
5506
Mitch Williams263fc482014-04-23 04:50:11 +00005507 if (i40e_check_asq_alive(&pf->hw))
5508 i40e_vc_notify_reset(pf);
5509
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005510 /* do the biggest reset indicated */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005511 if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005512
5513 /* Request a Global Reset
5514 *
5515 * This will start the chip's countdown to the actual full
5516 * chip reset event, and a warning interrupt to be sent
5517 * to all PFs, including the requestor. Our handler
5518 * for the warning interrupt will deal with the shutdown
5519 * and recovery of the switch setup.
5520 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005521 dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005522 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5523 val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
5524 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5525
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005526 } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005527
5528 /* Request a Core Reset
5529 *
5530 * Same as Global Reset, except does *not* include the MAC/PHY
5531 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005532 dev_dbg(&pf->pdev->dev, "CoreR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005533 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5534 val |= I40E_GLGEN_RTRIG_CORER_MASK;
5535 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5536 i40e_flush(&pf->hw);
5537
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005538 } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005539
5540 /* Request a PF Reset
5541 *
5542 * Resets only the PF-specific registers
5543 *
5544 * This goes directly to the tear-down and rebuild of
5545 * the switch, since we need to do all the recovery as
5546 * for the Core Reset.
5547 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005548 dev_dbg(&pf->pdev->dev, "PFR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005549 i40e_handle_reset_warning(pf);
5550
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005551 } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005552 int v;
5553
5554 /* Find the VSI(s) that requested a re-init */
5555 dev_info(&pf->pdev->dev,
5556 "VSI reinit requested\n");
Mitch Williams505682c2014-05-20 08:01:37 +00005557 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005558 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04005559
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005560 if (vsi != NULL &&
5561 test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
5562 i40e_vsi_reinit_locked(pf->vsi[v]);
5563 clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
5564 }
5565 }
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005566 } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005567 int v;
5568
5569 /* Find the VSI(s) that needs to be brought down */
5570 dev_info(&pf->pdev->dev, "VSI down requested\n");
5571 for (v = 0; v < pf->num_alloc_vsi; v++) {
5572 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04005573
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005574 if (vsi != NULL &&
5575 test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) {
5576 set_bit(__I40E_DOWN, &vsi->state);
5577 i40e_down(vsi);
5578 clear_bit(__I40E_DOWN_REQUESTED, &vsi->state);
5579 }
5580 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005581 } else {
5582 dev_info(&pf->pdev->dev,
5583 "bad reset request 0x%08x\n", reset_flags);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005584 }
5585}
5586
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005587#ifdef CONFIG_I40E_DCB
5588/**
5589 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
5590 * @pf: board private structure
5591 * @old_cfg: current DCB config
5592 * @new_cfg: new DCB config
5593 **/
5594bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
5595 struct i40e_dcbx_config *old_cfg,
5596 struct i40e_dcbx_config *new_cfg)
5597{
5598 bool need_reconfig = false;
5599
5600 /* Check if ETS configuration has changed */
5601 if (memcmp(&new_cfg->etscfg,
5602 &old_cfg->etscfg,
5603 sizeof(new_cfg->etscfg))) {
5604 /* If Priority Table has changed reconfig is needed */
5605 if (memcmp(&new_cfg->etscfg.prioritytable,
5606 &old_cfg->etscfg.prioritytable,
5607 sizeof(new_cfg->etscfg.prioritytable))) {
5608 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005609 dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005610 }
5611
5612 if (memcmp(&new_cfg->etscfg.tcbwtable,
5613 &old_cfg->etscfg.tcbwtable,
5614 sizeof(new_cfg->etscfg.tcbwtable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005615 dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005616
5617 if (memcmp(&new_cfg->etscfg.tsatable,
5618 &old_cfg->etscfg.tsatable,
5619 sizeof(new_cfg->etscfg.tsatable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005620 dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005621 }
5622
5623 /* Check if PFC configuration has changed */
5624 if (memcmp(&new_cfg->pfc,
5625 &old_cfg->pfc,
5626 sizeof(new_cfg->pfc))) {
5627 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005628 dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005629 }
5630
5631 /* Check if APP Table has changed */
5632 if (memcmp(&new_cfg->app,
5633 &old_cfg->app,
Dave Jones3d9667a2014-01-27 23:11:09 -05005634 sizeof(new_cfg->app))) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005635 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005636 dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
Dave Jones3d9667a2014-01-27 23:11:09 -05005637 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005638
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005639 dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005640 return need_reconfig;
5641}
5642
5643/**
5644 * i40e_handle_lldp_event - Handle LLDP Change MIB event
5645 * @pf: board private structure
5646 * @e: event info posted on ARQ
5647 **/
5648static int i40e_handle_lldp_event(struct i40e_pf *pf,
5649 struct i40e_arq_event_info *e)
5650{
5651 struct i40e_aqc_lldp_get_mib *mib =
5652 (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
5653 struct i40e_hw *hw = &pf->hw;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005654 struct i40e_dcbx_config tmp_dcbx_cfg;
5655 bool need_reconfig = false;
5656 int ret = 0;
5657 u8 type;
5658
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005659 /* Not DCB capable or capability disabled */
5660 if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
5661 return ret;
5662
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005663 /* Ignore if event is not for Nearest Bridge */
5664 type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
5665 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005666 dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005667 if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
5668 return ret;
5669
5670 /* Check MIB Type and return if event for Remote MIB update */
5671 type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005672 dev_dbg(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005673 "LLDP event mib type %s\n", type ? "remote" : "local");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005674 if (type == I40E_AQ_LLDP_MIB_REMOTE) {
5675 /* Update the remote cached instance and return */
5676 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
5677 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
5678 &hw->remote_dcbx_config);
5679 goto exit;
5680 }
5681
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005682 /* Store the old configuration */
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07005683 tmp_dcbx_cfg = hw->local_dcbx_config;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005684
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005685 /* Reset the old DCBx configuration data */
5686 memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005687 /* Get updated DCBX data from firmware */
5688 ret = i40e_get_dcb_config(&pf->hw);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005689 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005690 dev_info(&pf->pdev->dev,
5691 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
5692 i40e_stat_str(&pf->hw, ret),
5693 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005694 goto exit;
5695 }
5696
5697 /* No change detected in DCBX configs */
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005698 if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
5699 sizeof(tmp_dcbx_cfg))) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005700 dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005701 goto exit;
5702 }
5703
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005704 need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
5705 &hw->local_dcbx_config);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005706
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005707 i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005708
5709 if (!need_reconfig)
5710 goto exit;
5711
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005712 /* Enable DCB tagging only when more than one TC */
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005713 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005714 pf->flags |= I40E_FLAG_DCB_ENABLED;
5715 else
5716 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
5717
Neerav Parikh69129dc2014-11-12 00:18:46 +00005718 set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005719 /* Reconfiguration needed quiesce all VSIs */
5720 i40e_pf_quiesce_all_vsi(pf);
5721
5722 /* Changes in configuration update VEB/VSI */
5723 i40e_dcb_reconfigure(pf);
5724
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005725 ret = i40e_resume_port_tx(pf);
5726
Neerav Parikh69129dc2014-11-12 00:18:46 +00005727 clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005728 /* In case of error no point in resuming VSIs */
Neerav Parikh69129dc2014-11-12 00:18:46 +00005729 if (ret)
5730 goto exit;
5731
5732 /* Wait for the PF's Tx queues to be disabled */
5733 ret = i40e_pf_wait_txq_disabled(pf);
Parikh, Neerav11e47702015-02-21 06:43:55 +00005734 if (ret) {
5735 /* Schedule PF reset to recover */
5736 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
5737 i40e_service_event_schedule(pf);
5738 } else {
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005739 i40e_pf_unquiesce_all_vsi(pf);
Parikh, Neerav11e47702015-02-21 06:43:55 +00005740 }
5741
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005742exit:
5743 return ret;
5744}
5745#endif /* CONFIG_I40E_DCB */
5746
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005747/**
Anjali Singhai Jain233261862013-11-26 10:49:22 +00005748 * i40e_do_reset_safe - Protected reset path for userland calls.
5749 * @pf: board private structure
5750 * @reset_flags: which reset is requested
5751 *
5752 **/
5753void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
5754{
5755 rtnl_lock();
5756 i40e_do_reset(pf, reset_flags);
5757 rtnl_unlock();
5758}
5759
5760/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005761 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
5762 * @pf: board private structure
5763 * @e: event info posted on ARQ
5764 *
5765 * Handler for LAN Queue Overflow Event generated by the firmware for PF
5766 * and VF queues
5767 **/
5768static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
5769 struct i40e_arq_event_info *e)
5770{
5771 struct i40e_aqc_lan_overflow *data =
5772 (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
5773 u32 queue = le32_to_cpu(data->prtdcb_rupto);
5774 u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
5775 struct i40e_hw *hw = &pf->hw;
5776 struct i40e_vf *vf;
5777 u16 vf_id;
5778
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005779 dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
5780 queue, qtx_ctl);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005781
5782 /* Queue belongs to VF, find the VF and issue VF reset */
5783 if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
5784 >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
5785 vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
5786 >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
5787 vf_id -= hw->func_caps.vf_base_id;
5788 vf = &pf->vf[vf_id];
5789 i40e_vc_notify_vf_reset(vf);
5790 /* Allow VF to process pending reset notification */
5791 msleep(20);
5792 i40e_reset_vf(vf, false);
5793 }
5794}
5795
5796/**
5797 * i40e_service_event_complete - Finish up the service event
5798 * @pf: board private structure
5799 **/
5800static void i40e_service_event_complete(struct i40e_pf *pf)
5801{
Shannon Nelsonb875f992015-10-21 19:47:03 -04005802 WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005803
5804 /* flush memory to make sure state is correct before next watchog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005805 smp_mb__before_atomic();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005806 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
5807}
5808
5809/**
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005810 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
5811 * @pf: board private structure
5812 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005813u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005814{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005815 u32 val, fcnt_prog;
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005816
5817 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
5818 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
5819 return fcnt_prog;
5820}
5821
5822/**
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005823 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005824 * @pf: board private structure
5825 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005826u32 i40e_get_current_fd_count(struct i40e_pf *pf)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005827{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005828 u32 val, fcnt_prog;
5829
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005830 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
5831 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
5832 ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
5833 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
5834 return fcnt_prog;
5835}
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005836
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005837/**
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005838 * i40e_get_global_fd_count - Get total FD filters programmed on device
5839 * @pf: board private structure
5840 **/
5841u32 i40e_get_global_fd_count(struct i40e_pf *pf)
5842{
5843 u32 val, fcnt_prog;
5844
5845 val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
5846 fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
5847 ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
5848 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
5849 return fcnt_prog;
5850}
5851
5852/**
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005853 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
5854 * @pf: board private structure
5855 **/
5856void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
5857{
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04005858 struct i40e_fdir_filter *filter;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005859 u32 fcnt_prog, fcnt_avail;
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04005860 struct hlist_node *node;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005861
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005862 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
5863 return;
5864
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005865 /* Check if, FD SB or ATR was auto disabled and if there is enough room
5866 * to re-enable
5867 */
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005868 fcnt_prog = i40e_get_global_fd_count(pf);
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005869 fcnt_avail = pf->fdir_pf_filter_count;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005870 if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
5871 (pf->fd_add_err == 0) ||
5872 (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005873 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
5874 (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
5875 pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04005876 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5877 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 +00005878 }
5879 }
5880 /* Wait for some more space to be available to turn on ATR */
5881 if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
5882 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
5883 (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
5884 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04005885 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5886 dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table now\n");
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005887 }
5888 }
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04005889
5890 /* if hw had a problem adding a filter, delete it */
5891 if (pf->fd_inv > 0) {
5892 hlist_for_each_entry_safe(filter, node,
5893 &pf->fdir_filter_list, fdir_node) {
5894 if (filter->fd_id == pf->fd_inv) {
5895 hlist_del(&filter->fdir_node);
5896 kfree(filter);
5897 pf->fdir_pf_active_filters--;
5898 }
5899 }
5900 }
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005901}
5902
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005903#define I40E_MIN_FD_FLUSH_INTERVAL 10
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005904#define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005905/**
5906 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
5907 * @pf: board private structure
5908 **/
5909static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
5910{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005911 unsigned long min_flush_time;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005912 int flush_wait_retry = 50;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005913 bool disable_atr = false;
5914 int fd_room;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005915 int reg;
5916
Akeem G Abodunrin1790ed02014-10-17 03:14:41 +00005917 if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED)))
5918 return;
5919
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005920 if (!time_after(jiffies, pf->fd_flush_timestamp +
5921 (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
5922 return;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005923
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005924 /* If the flush is happening too quick and we have mostly SB rules we
5925 * should not re-enable ATR for some time.
5926 */
5927 min_flush_time = pf->fd_flush_timestamp +
5928 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
5929 fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005930
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005931 if (!(time_after(jiffies, min_flush_time)) &&
5932 (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
5933 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5934 dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
5935 disable_atr = true;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005936 }
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005937
5938 pf->fd_flush_timestamp = jiffies;
5939 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
5940 /* flush all filters */
5941 wr32(&pf->hw, I40E_PFQF_CTL_1,
5942 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
5943 i40e_flush(&pf->hw);
5944 pf->fd_flush_cnt++;
5945 pf->fd_add_err = 0;
5946 do {
5947 /* Check FD flush status every 5-6msec */
5948 usleep_range(5000, 6000);
5949 reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
5950 if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
5951 break;
5952 } while (flush_wait_retry--);
5953 if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
5954 dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
5955 } else {
5956 /* replay sideband filters */
5957 i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
5958 if (!disable_atr)
5959 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
5960 clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
5961 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5962 dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
5963 }
5964
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005965}
5966
5967/**
5968 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
5969 * @pf: board private structure
5970 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005971u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005972{
5973 return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
5974}
5975
5976/* We can see up to 256 filter programming desc in transit if the filters are
5977 * being applied really fast; before we see the first
5978 * filter miss error on Rx queue 0. Accumulating enough error messages before
5979 * reacting will make sure we don't cause flush too often.
5980 */
5981#define I40E_MAX_FD_PROGRAM_ERROR 256
5982
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005983/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005984 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
5985 * @pf: board private structure
5986 **/
5987static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
5988{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005989
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005990 /* if interface is down do nothing */
5991 if (test_bit(__I40E_DOWN, &pf->state))
5992 return;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005993
Akeem G Abodunrin1790ed02014-10-17 03:14:41 +00005994 if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED)))
5995 return;
5996
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005997 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005998 i40e_fdir_flush_and_replay(pf);
5999
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006000 i40e_fdir_check_and_reenable(pf);
6001
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006002}
6003
6004/**
6005 * i40e_vsi_link_event - notify VSI of a link event
6006 * @vsi: vsi to be notified
6007 * @link_up: link up or down
6008 **/
6009static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
6010{
Jesse Brandeburg32b5b812014-08-12 06:33:14 +00006011 if (!vsi || test_bit(__I40E_DOWN, &vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006012 return;
6013
6014 switch (vsi->type) {
6015 case I40E_VSI_MAIN:
Vasu Dev38e00432014-08-01 13:27:03 -07006016#ifdef I40E_FCOE
6017 case I40E_VSI_FCOE:
6018#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006019 if (!vsi->netdev || !vsi->netdev_registered)
6020 break;
6021
6022 if (link_up) {
6023 netif_carrier_on(vsi->netdev);
6024 netif_tx_wake_all_queues(vsi->netdev);
6025 } else {
6026 netif_carrier_off(vsi->netdev);
6027 netif_tx_stop_all_queues(vsi->netdev);
6028 }
6029 break;
6030
6031 case I40E_VSI_SRIOV:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006032 case I40E_VSI_VMDQ2:
6033 case I40E_VSI_CTRL:
6034 case I40E_VSI_MIRROR:
6035 default:
6036 /* there is no notification for other VSIs */
6037 break;
6038 }
6039}
6040
6041/**
6042 * i40e_veb_link_event - notify elements on the veb of a link event
6043 * @veb: veb to be notified
6044 * @link_up: link up or down
6045 **/
6046static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
6047{
6048 struct i40e_pf *pf;
6049 int i;
6050
6051 if (!veb || !veb->pf)
6052 return;
6053 pf = veb->pf;
6054
6055 /* depth first... */
6056 for (i = 0; i < I40E_MAX_VEB; i++)
6057 if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
6058 i40e_veb_link_event(pf->veb[i], link_up);
6059
6060 /* ... now the local VSIs */
Mitch Williams505682c2014-05-20 08:01:37 +00006061 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006062 if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
6063 i40e_vsi_link_event(pf->vsi[i], link_up);
6064}
6065
6066/**
6067 * i40e_link_event - Update netif_carrier status
6068 * @pf: board private structure
6069 **/
6070static void i40e_link_event(struct i40e_pf *pf)
6071{
Mitch Williams320684c2014-10-17 03:14:43 +00006072 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006073 u8 new_link_speed, old_link_speed;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006074 i40e_status status;
6075 bool new_link, old_link;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006076
Catherine Sullivan1f9610e2015-10-21 19:47:09 -04006077 /* save off old link status information */
6078 pf->hw.phy.link_info_old = pf->hw.phy.link_info;
6079
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006080 /* set this to force the get_link_status call to refresh state */
6081 pf->hw.phy.get_link_info = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006082
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006083 old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006084
6085 status = i40e_get_link_status(&pf->hw, &new_link);
6086 if (status) {
6087 dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
6088 status);
6089 return;
6090 }
6091
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006092 old_link_speed = pf->hw.phy.link_info_old.link_speed;
6093 new_link_speed = pf->hw.phy.link_info.link_speed;
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006094
6095 if (new_link == old_link &&
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006096 new_link_speed == old_link_speed &&
Mitch Williams320684c2014-10-17 03:14:43 +00006097 (test_bit(__I40E_DOWN, &vsi->state) ||
6098 new_link == netif_carrier_ok(vsi->netdev)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006099 return;
Mitch Williams320684c2014-10-17 03:14:43 +00006100
6101 if (!test_bit(__I40E_DOWN, &vsi->state))
6102 i40e_print_link_message(vsi, new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006103
6104 /* Notify the base of the switch tree connected to
6105 * the link. Floating VEBs are not notified.
6106 */
6107 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
6108 i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
6109 else
Mitch Williams320684c2014-10-17 03:14:43 +00006110 i40e_vsi_link_event(vsi, new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006111
6112 if (pf->vf)
6113 i40e_vc_notify_link_state(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00006114
6115 if (pf->flags & I40E_FLAG_PTP)
6116 i40e_ptp_set_increment(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006117}
6118
6119/**
Shannon Nelson21536712014-10-25 10:35:25 +00006120 * i40e_watchdog_subtask - periodic checks not using event driven response
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006121 * @pf: board private structure
6122 **/
6123static void i40e_watchdog_subtask(struct i40e_pf *pf)
6124{
6125 int i;
6126
6127 /* if interface is down do nothing */
6128 if (test_bit(__I40E_DOWN, &pf->state) ||
6129 test_bit(__I40E_CONFIG_BUSY, &pf->state))
6130 return;
6131
Shannon Nelson21536712014-10-25 10:35:25 +00006132 /* make sure we don't do these things too often */
6133 if (time_before(jiffies, (pf->service_timer_previous +
6134 pf->service_timer_period)))
6135 return;
6136 pf->service_timer_previous = jiffies;
6137
Shannon Nelson9ac77262015-08-27 11:42:40 -04006138 if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED)
6139 i40e_link_event(pf);
Shannon Nelson21536712014-10-25 10:35:25 +00006140
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006141 /* Update the stats for active netdevs so the network stack
6142 * can look at updated numbers whenever it cares to
6143 */
Mitch Williams505682c2014-05-20 08:01:37 +00006144 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006145 if (pf->vsi[i] && pf->vsi[i]->netdev)
6146 i40e_update_stats(pf->vsi[i]);
6147
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04006148 if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
6149 /* Update the stats for the active switching components */
6150 for (i = 0; i < I40E_MAX_VEB; i++)
6151 if (pf->veb[i])
6152 i40e_update_veb_stats(pf->veb[i]);
6153 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00006154
6155 i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006156}
6157
6158/**
6159 * i40e_reset_subtask - Set up for resetting the device and driver
6160 * @pf: board private structure
6161 **/
6162static void i40e_reset_subtask(struct i40e_pf *pf)
6163{
6164 u32 reset_flags = 0;
6165
Anjali Singhai Jain233261862013-11-26 10:49:22 +00006166 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006167 if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006168 reset_flags |= BIT(__I40E_REINIT_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006169 clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
6170 }
6171 if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006172 reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006173 clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
6174 }
6175 if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006176 reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006177 clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
6178 }
6179 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006180 reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006181 clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
6182 }
Neerav Parikhb5d06f02014-06-03 23:50:17 +00006183 if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006184 reset_flags |= BIT(__I40E_DOWN_REQUESTED);
Neerav Parikhb5d06f02014-06-03 23:50:17 +00006185 clear_bit(__I40E_DOWN_REQUESTED, &pf->state);
6186 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006187
6188 /* If there's a recovery already waiting, it takes
6189 * precedence before starting a new reset sequence.
6190 */
6191 if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
6192 i40e_handle_reset_warning(pf);
Anjali Singhai Jain233261862013-11-26 10:49:22 +00006193 goto unlock;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006194 }
6195
6196 /* If we're already down or resetting, just bail */
6197 if (reset_flags &&
6198 !test_bit(__I40E_DOWN, &pf->state) &&
6199 !test_bit(__I40E_CONFIG_BUSY, &pf->state))
6200 i40e_do_reset(pf, reset_flags);
Anjali Singhai Jain233261862013-11-26 10:49:22 +00006201
6202unlock:
6203 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006204}
6205
6206/**
6207 * i40e_handle_link_event - Handle link event
6208 * @pf: board private structure
6209 * @e: event info posted on ARQ
6210 **/
6211static void i40e_handle_link_event(struct i40e_pf *pf,
6212 struct i40e_arq_event_info *e)
6213{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006214 struct i40e_aqc_get_link_status *status =
6215 (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006216
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006217 /* Do a new status request to re-enable LSE reporting
6218 * and load new status information into the hw struct
6219 * This completely ignores any state information
6220 * in the ARQ event info, instead choosing to always
6221 * issue the AQ update link status command.
6222 */
6223 i40e_link_event(pf);
6224
Carolyn Wyborny7b592f62014-07-10 07:58:19 +00006225 /* check for unqualified module, if link is down */
6226 if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
6227 (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
6228 (!(status->link_info & I40E_AQ_LINK_UP)))
6229 dev_err(&pf->pdev->dev,
6230 "The driver failed to link because an unqualified module was detected.\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006231}
6232
6233/**
6234 * i40e_clean_adminq_subtask - Clean the AdminQ rings
6235 * @pf: board private structure
6236 **/
6237static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
6238{
6239 struct i40e_arq_event_info event;
6240 struct i40e_hw *hw = &pf->hw;
6241 u16 pending, i = 0;
6242 i40e_status ret;
6243 u16 opcode;
Shannon Nelson86df2422014-05-20 08:01:35 +00006244 u32 oldval;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006245 u32 val;
6246
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006247 /* Do not run clean AQ when PF reset fails */
6248 if (test_bit(__I40E_RESET_FAILED, &pf->state))
6249 return;
6250
Shannon Nelson86df2422014-05-20 08:01:35 +00006251 /* check for error indications */
6252 val = rd32(&pf->hw, pf->hw.aq.arq.len);
6253 oldval = val;
6254 if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006255 if (hw->debug_mask & I40E_DEBUG_AQ)
6256 dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006257 val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
6258 }
6259 if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006260 if (hw->debug_mask & I40E_DEBUG_AQ)
6261 dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006262 val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
Mitch Williams1d0a4ad2015-12-23 12:05:48 -08006263 pf->arq_overflows++;
Shannon Nelson86df2422014-05-20 08:01:35 +00006264 }
6265 if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006266 if (hw->debug_mask & I40E_DEBUG_AQ)
6267 dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006268 val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
6269 }
6270 if (oldval != val)
6271 wr32(&pf->hw, pf->hw.aq.arq.len, val);
6272
6273 val = rd32(&pf->hw, pf->hw.aq.asq.len);
6274 oldval = val;
6275 if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006276 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6277 dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006278 val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
6279 }
6280 if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006281 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6282 dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006283 val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
6284 }
6285 if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006286 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6287 dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006288 val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
6289 }
6290 if (oldval != val)
6291 wr32(&pf->hw, pf->hw.aq.asq.len, val);
6292
Mitch Williams1001dc32014-11-11 20:02:19 +00006293 event.buf_len = I40E_MAX_AQ_BUF_SIZE;
6294 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006295 if (!event.msg_buf)
6296 return;
6297
6298 do {
6299 ret = i40e_clean_arq_element(hw, &event, &pending);
Mitch Williams56497972014-06-04 08:45:18 +00006300 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006301 break;
Mitch Williams56497972014-06-04 08:45:18 +00006302 else if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006303 dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
6304 break;
6305 }
6306
6307 opcode = le16_to_cpu(event.desc.opcode);
6308 switch (opcode) {
6309
6310 case i40e_aqc_opc_get_link_status:
6311 i40e_handle_link_event(pf, &event);
6312 break;
6313 case i40e_aqc_opc_send_msg_to_pf:
6314 ret = i40e_vc_process_vf_msg(pf,
6315 le16_to_cpu(event.desc.retval),
6316 le32_to_cpu(event.desc.cookie_high),
6317 le32_to_cpu(event.desc.cookie_low),
6318 event.msg_buf,
Mitch Williams1001dc32014-11-11 20:02:19 +00006319 event.msg_len);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006320 break;
6321 case i40e_aqc_opc_lldp_update_mib:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006322 dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006323#ifdef CONFIG_I40E_DCB
6324 rtnl_lock();
6325 ret = i40e_handle_lldp_event(pf, &event);
6326 rtnl_unlock();
6327#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006328 break;
6329 case i40e_aqc_opc_event_lan_overflow:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006330 dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006331 i40e_handle_lan_overflow_event(pf, &event);
6332 break;
Shannon Nelson0467bc92013-12-18 13:45:58 +00006333 case i40e_aqc_opc_send_msg_to_peer:
6334 dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
6335 break;
Shannon Nelson91a0f932015-03-19 14:32:01 -07006336 case i40e_aqc_opc_nvm_erase:
6337 case i40e_aqc_opc_nvm_update:
Michal Kosiarz00ada502015-11-19 11:34:20 -08006338 case i40e_aqc_opc_oem_post_update:
Shannon Nelson91a0f932015-03-19 14:32:01 -07006339 i40e_debug(&pf->hw, I40E_DEBUG_NVM, "ARQ NVM operation completed\n");
6340 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006341 default:
6342 dev_info(&pf->pdev->dev,
Shannon Nelson0467bc92013-12-18 13:45:58 +00006343 "ARQ Error: Unknown event 0x%04x received\n",
6344 opcode);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006345 break;
6346 }
6347 } while (pending && (i++ < pf->adminq_work_limit));
6348
6349 clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
6350 /* re-enable Admin queue interrupt cause */
6351 val = rd32(hw, I40E_PFINT_ICR0_ENA);
6352 val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
6353 wr32(hw, I40E_PFINT_ICR0_ENA, val);
6354 i40e_flush(hw);
6355
6356 kfree(event.msg_buf);
6357}
6358
6359/**
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006360 * i40e_verify_eeprom - make sure eeprom is good to use
6361 * @pf: board private structure
6362 **/
6363static void i40e_verify_eeprom(struct i40e_pf *pf)
6364{
6365 int err;
6366
6367 err = i40e_diag_eeprom_test(&pf->hw);
6368 if (err) {
6369 /* retry in case of garbage read */
6370 err = i40e_diag_eeprom_test(&pf->hw);
6371 if (err) {
6372 dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
6373 err);
6374 set_bit(__I40E_BAD_EEPROM, &pf->state);
6375 }
6376 }
6377
6378 if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
6379 dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
6380 clear_bit(__I40E_BAD_EEPROM, &pf->state);
6381 }
6382}
6383
6384/**
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006385 * i40e_enable_pf_switch_lb
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006386 * @pf: pointer to the PF structure
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006387 *
6388 * enable switch loop back or die - no point in a return value
6389 **/
6390static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
6391{
6392 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6393 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006394 int ret;
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006395
6396 ctxt.seid = pf->main_vsi_seid;
6397 ctxt.pf_num = pf->hw.pf_id;
6398 ctxt.vf_num = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006399 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6400 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006401 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006402 "couldn't get PF vsi config, err %s aq_err %s\n",
6403 i40e_stat_str(&pf->hw, ret),
6404 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006405 return;
6406 }
6407 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6408 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6409 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6410
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006411 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6412 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006413 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006414 "update vsi switch failed, err %s aq_err %s\n",
6415 i40e_stat_str(&pf->hw, ret),
6416 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006417 }
6418}
6419
6420/**
6421 * i40e_disable_pf_switch_lb
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006422 * @pf: pointer to the PF structure
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006423 *
6424 * disable switch loop back or die - no point in a return value
6425 **/
6426static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
6427{
6428 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6429 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006430 int ret;
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006431
6432 ctxt.seid = pf->main_vsi_seid;
6433 ctxt.pf_num = pf->hw.pf_id;
6434 ctxt.vf_num = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006435 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6436 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006437 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006438 "couldn't get PF vsi config, err %s aq_err %s\n",
6439 i40e_stat_str(&pf->hw, ret),
6440 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006441 return;
6442 }
6443 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6444 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6445 ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6446
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006447 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6448 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006449 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006450 "update vsi switch failed, err %s aq_err %s\n",
6451 i40e_stat_str(&pf->hw, ret),
6452 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006453 }
6454}
6455
6456/**
Neerav Parikh51616012015-02-06 08:52:14 +00006457 * i40e_config_bridge_mode - Configure the HW bridge mode
6458 * @veb: pointer to the bridge instance
6459 *
6460 * Configure the loop back mode for the LAN VSI that is downlink to the
6461 * specified HW bridge instance. It is expected this function is called
6462 * when a new HW bridge is instantiated.
6463 **/
6464static void i40e_config_bridge_mode(struct i40e_veb *veb)
6465{
6466 struct i40e_pf *pf = veb->pf;
6467
Shannon Nelson6dec1012015-09-28 14:12:30 -04006468 if (pf->hw.debug_mask & I40E_DEBUG_LAN)
6469 dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
6470 veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
Neerav Parikh51616012015-02-06 08:52:14 +00006471 if (veb->bridge_mode & BRIDGE_MODE_VEPA)
6472 i40e_disable_pf_switch_lb(pf);
6473 else
6474 i40e_enable_pf_switch_lb(pf);
6475}
6476
6477/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006478 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
6479 * @veb: pointer to the VEB instance
6480 *
6481 * This is a recursive function that first builds the attached VSIs then
6482 * recurses in to build the next layer of VEB. We track the connections
6483 * through our own index numbers because the seid's from the HW could
6484 * change across the reset.
6485 **/
6486static int i40e_reconstitute_veb(struct i40e_veb *veb)
6487{
6488 struct i40e_vsi *ctl_vsi = NULL;
6489 struct i40e_pf *pf = veb->pf;
6490 int v, veb_idx;
6491 int ret;
6492
6493 /* build VSI that owns this VEB, temporarily attached to base VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00006494 for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006495 if (pf->vsi[v] &&
6496 pf->vsi[v]->veb_idx == veb->idx &&
6497 pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
6498 ctl_vsi = pf->vsi[v];
6499 break;
6500 }
6501 }
6502 if (!ctl_vsi) {
6503 dev_info(&pf->pdev->dev,
6504 "missing owner VSI for veb_idx %d\n", veb->idx);
6505 ret = -ENOENT;
6506 goto end_reconstitute;
6507 }
6508 if (ctl_vsi != pf->vsi[pf->lan_vsi])
6509 ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
6510 ret = i40e_add_vsi(ctl_vsi);
6511 if (ret) {
6512 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006513 "rebuild of veb_idx %d owner VSI failed: %d\n",
6514 veb->idx, ret);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006515 goto end_reconstitute;
6516 }
6517 i40e_vsi_reset_stats(ctl_vsi);
6518
6519 /* create the VEB in the switch and move the VSI onto the VEB */
6520 ret = i40e_add_veb(veb, ctl_vsi);
6521 if (ret)
6522 goto end_reconstitute;
6523
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07006524 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
6525 veb->bridge_mode = BRIDGE_MODE_VEB;
6526 else
6527 veb->bridge_mode = BRIDGE_MODE_VEPA;
Neerav Parikh51616012015-02-06 08:52:14 +00006528 i40e_config_bridge_mode(veb);
Anjali Singhai Jainb64ba082014-11-13 03:06:15 +00006529
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006530 /* create the remaining VSIs attached to this VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00006531 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006532 if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
6533 continue;
6534
6535 if (pf->vsi[v]->veb_idx == veb->idx) {
6536 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04006537
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006538 vsi->uplink_seid = veb->seid;
6539 ret = i40e_add_vsi(vsi);
6540 if (ret) {
6541 dev_info(&pf->pdev->dev,
6542 "rebuild of vsi_idx %d failed: %d\n",
6543 v, ret);
6544 goto end_reconstitute;
6545 }
6546 i40e_vsi_reset_stats(vsi);
6547 }
6548 }
6549
6550 /* create any VEBs attached to this VEB - RECURSION */
6551 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
6552 if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
6553 pf->veb[veb_idx]->uplink_seid = veb->seid;
6554 ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
6555 if (ret)
6556 break;
6557 }
6558 }
6559
6560end_reconstitute:
6561 return ret;
6562}
6563
6564/**
6565 * i40e_get_capabilities - get info about the HW
6566 * @pf: the PF struct
6567 **/
6568static int i40e_get_capabilities(struct i40e_pf *pf)
6569{
6570 struct i40e_aqc_list_capabilities_element_resp *cap_buf;
6571 u16 data_size;
6572 int buf_len;
6573 int err;
6574
6575 buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
6576 do {
6577 cap_buf = kzalloc(buf_len, GFP_KERNEL);
6578 if (!cap_buf)
6579 return -ENOMEM;
6580
6581 /* this loads the data into the hw struct for us */
6582 err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
6583 &data_size,
6584 i40e_aqc_opc_list_func_capabilities,
6585 NULL);
6586 /* data loaded, buffer no longer needed */
6587 kfree(cap_buf);
6588
6589 if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
6590 /* retry with a larger buffer */
6591 buf_len = data_size;
6592 } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
6593 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006594 "capability discovery failed, err %s aq_err %s\n",
6595 i40e_stat_str(&pf->hw, err),
6596 i40e_aq_str(&pf->hw,
6597 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006598 return -ENODEV;
6599 }
6600 } while (err);
6601
6602 if (pf->hw.debug_mask & I40E_DEBUG_USER)
6603 dev_info(&pf->pdev->dev,
6604 "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",
6605 pf->hw.pf_id, pf->hw.func_caps.num_vfs,
6606 pf->hw.func_caps.num_msix_vectors,
6607 pf->hw.func_caps.num_msix_vectors_vf,
6608 pf->hw.func_caps.fd_filters_guaranteed,
6609 pf->hw.func_caps.fd_filters_best_effort,
6610 pf->hw.func_caps.num_tx_qp,
6611 pf->hw.func_caps.num_vsis);
6612
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00006613#define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
6614 + pf->hw.func_caps.num_vfs)
6615 if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
6616 dev_info(&pf->pdev->dev,
6617 "got num_vsis %d, setting num_vsis to %d\n",
6618 pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
6619 pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
6620 }
6621
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006622 return 0;
6623}
6624
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006625static int i40e_vsi_clear(struct i40e_vsi *vsi);
6626
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006627/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006628 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006629 * @pf: board private structure
6630 **/
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006631static void i40e_fdir_sb_setup(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006632{
6633 struct i40e_vsi *vsi;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006634 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006635
Jesse Brandeburg407e0632014-06-03 23:50:12 +00006636 /* quick workaround for an NVM issue that leaves a critical register
6637 * uninitialized
6638 */
6639 if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
6640 static const u32 hkey[] = {
6641 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
6642 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
6643 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
6644 0x95b3a76d};
6645
6646 for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
6647 wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
6648 }
6649
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006650 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006651 return;
6652
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006653 /* find existing VSI and see if it needs configuring */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006654 vsi = NULL;
Mitch Williams505682c2014-05-20 08:01:37 +00006655 for (i = 0; i < pf->num_alloc_vsi; i++) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006656 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006657 vsi = pf->vsi[i];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006658 break;
6659 }
6660 }
6661
6662 /* create a new VSI if none exists */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006663 if (!vsi) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006664 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
6665 pf->vsi[pf->lan_vsi]->seid, 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006666 if (!vsi) {
6667 dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006668 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
6669 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006670 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006671 }
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006672
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006673 i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006674}
6675
6676/**
6677 * i40e_fdir_teardown - release the Flow Director resources
6678 * @pf: board private structure
6679 **/
6680static void i40e_fdir_teardown(struct i40e_pf *pf)
6681{
6682 int i;
6683
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00006684 i40e_fdir_filter_exit(pf);
Mitch Williams505682c2014-05-20 08:01:37 +00006685 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006686 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
6687 i40e_vsi_release(pf->vsi[i]);
6688 break;
6689 }
6690 }
6691}
6692
6693/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006694 * i40e_prep_for_reset - prep for the core to reset
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006695 * @pf: board private structure
6696 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006697 * Close up the VFs and other things in prep for PF Reset.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006698 **/
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006699static void i40e_prep_for_reset(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006700{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006701 struct i40e_hw *hw = &pf->hw;
Shannon Nelson60442de2014-04-23 04:50:13 +00006702 i40e_status ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006703 u32 v;
6704
6705 clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
6706 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006707 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006708
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006709 dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006710
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006711 /* quiesce the VSIs and their queues that are not already DOWN */
6712 i40e_pf_quiesce_all_vsi(pf);
6713
Mitch Williams505682c2014-05-20 08:01:37 +00006714 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006715 if (pf->vsi[v])
6716 pf->vsi[v]->seid = 0;
6717 }
6718
6719 i40e_shutdown_adminq(&pf->hw);
6720
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006721 /* call shutdown HMC */
Shannon Nelson60442de2014-04-23 04:50:13 +00006722 if (hw->hmc.hmc_obj) {
6723 ret = i40e_shutdown_lan_hmc(hw);
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006724 if (ret)
Shannon Nelson60442de2014-04-23 04:50:13 +00006725 dev_warn(&pf->pdev->dev,
6726 "shutdown_lan_hmc failed: %d\n", ret);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006727 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006728}
6729
6730/**
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00006731 * i40e_send_version - update firmware with driver version
6732 * @pf: PF struct
6733 */
6734static void i40e_send_version(struct i40e_pf *pf)
6735{
6736 struct i40e_driver_version dv;
6737
6738 dv.major_version = DRV_VERSION_MAJOR;
6739 dv.minor_version = DRV_VERSION_MINOR;
6740 dv.build_version = DRV_VERSION_BUILD;
6741 dv.subbuild_version = 0;
Rickard Strandqvist35a7d802014-07-29 09:26:25 +00006742 strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00006743 i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
6744}
6745
6746/**
Jesse Brandeburg4dda12e2013-12-18 13:46:01 +00006747 * i40e_reset_and_rebuild - reset and rebuild using a saved config
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006748 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006749 * @reinit: if the Main VSI needs to re-initialized.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006750 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006751static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006752{
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006753 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006754 u8 set_fc_aq_fail = 0;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006755 i40e_status ret;
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -04006756 u32 val;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006757 u32 v;
6758
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006759 /* Now we wait for GRST to settle out.
6760 * We don't have to delete the VEBs or VSIs from the hw switch
6761 * because the reset will make them disappear.
6762 */
6763 ret = i40e_pf_reset(hw);
Akeem G Abodunrinb5565402014-04-09 05:59:04 +00006764 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006765 dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006766 set_bit(__I40E_RESET_FAILED, &pf->state);
6767 goto clear_recovery;
Akeem G Abodunrinb5565402014-04-09 05:59:04 +00006768 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006769 pf->pfr_count++;
6770
6771 if (test_bit(__I40E_DOWN, &pf->state))
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006772 goto clear_recovery;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006773 dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006774
6775 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
6776 ret = i40e_init_adminq(&pf->hw);
6777 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006778 dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
6779 i40e_stat_str(&pf->hw, ret),
6780 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006781 goto clear_recovery;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006782 }
6783
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006784 /* re-verify the eeprom if we just had an EMP reset */
Anjali Singhai Jain9df42d12015-01-24 09:58:40 +00006785 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state))
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006786 i40e_verify_eeprom(pf);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006787
Shannon Nelsone78ac4bf2014-05-10 04:49:09 +00006788 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006789 ret = i40e_get_capabilities(pf);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006790 if (ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006791 goto end_core_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006792
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006793 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
6794 hw->func_caps.num_rx_qp,
6795 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
6796 if (ret) {
6797 dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
6798 goto end_core_reset;
6799 }
6800 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
6801 if (ret) {
6802 dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
6803 goto end_core_reset;
6804 }
6805
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006806#ifdef CONFIG_I40E_DCB
6807 ret = i40e_init_pf_dcb(pf);
6808 if (ret) {
Shannon Nelsonaebfc812014-12-11 07:06:38 +00006809 dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
6810 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
6811 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006812 }
6813#endif /* CONFIG_I40E_DCB */
Vasu Dev38e00432014-08-01 13:27:03 -07006814#ifdef I40E_FCOE
Shannon Nelson21364bc2015-08-26 15:14:13 -04006815 i40e_init_pf_fcoe(pf);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006816
Vasu Dev38e00432014-08-01 13:27:03 -07006817#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006818 /* do basic switch setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006819 ret = i40e_setup_pf_switch(pf, reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006820 if (ret)
6821 goto end_core_reset;
6822
Shannon Nelson2f0aff42016-01-04 10:33:08 -08006823 /* The driver only wants link up/down and module qualification
6824 * reports from firmware. Note the negative logic.
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00006825 */
6826 ret = i40e_aq_set_phy_int_mask(&pf->hw,
Shannon Nelson2f0aff42016-01-04 10:33:08 -08006827 ~(I40E_AQ_EVENT_LINK_UPDOWN |
6828 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00006829 if (ret)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006830 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
6831 i40e_stat_str(&pf->hw, ret),
6832 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00006833
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006834 /* make sure our flow control settings are restored */
6835 ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
6836 if (ret)
Neerav Parikh8279e492015-09-03 17:18:50 -04006837 dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
6838 i40e_stat_str(&pf->hw, ret),
6839 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006840
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006841 /* Rebuild the VSIs and VEBs that existed before reset.
6842 * They are still in our local switch element arrays, so only
6843 * need to rebuild the switch model in the HW.
6844 *
6845 * If there were VEBs but the reconstitution failed, we'll try
6846 * try to recover minimal use by getting the basic PF VSI working.
6847 */
6848 if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006849 dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006850 /* find the one VEB connected to the MAC, and find orphans */
6851 for (v = 0; v < I40E_MAX_VEB; v++) {
6852 if (!pf->veb[v])
6853 continue;
6854
6855 if (pf->veb[v]->uplink_seid == pf->mac_seid ||
6856 pf->veb[v]->uplink_seid == 0) {
6857 ret = i40e_reconstitute_veb(pf->veb[v]);
6858
6859 if (!ret)
6860 continue;
6861
6862 /* If Main VEB failed, we're in deep doodoo,
6863 * so give up rebuilding the switch and set up
6864 * for minimal rebuild of PF VSI.
6865 * If orphan failed, we'll report the error
6866 * but try to keep going.
6867 */
6868 if (pf->veb[v]->uplink_seid == pf->mac_seid) {
6869 dev_info(&pf->pdev->dev,
6870 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
6871 ret);
6872 pf->vsi[pf->lan_vsi]->uplink_seid
6873 = pf->mac_seid;
6874 break;
6875 } else if (pf->veb[v]->uplink_seid == 0) {
6876 dev_info(&pf->pdev->dev,
6877 "rebuild of orphan VEB failed: %d\n",
6878 ret);
6879 }
6880 }
6881 }
6882 }
6883
6884 if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
Shannon Nelsoncde4cbc2014-06-04 01:23:17 +00006885 dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006886 /* no VEB, so rebuild only the Main VSI */
6887 ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
6888 if (ret) {
6889 dev_info(&pf->pdev->dev,
6890 "rebuild of Main VSI failed: %d\n", ret);
6891 goto end_core_reset;
6892 }
6893 }
6894
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -04006895 /* Reconfigure hardware for allowing smaller MSS in the case
6896 * of TSO, so that we avoid the MDD being fired and causing
6897 * a reset in the case of small MSS+TSO.
6898 */
6899#define I40E_REG_MSS 0x000E64DC
6900#define I40E_REG_MSS_MIN_MASK 0x3FF0000
6901#define I40E_64BYTE_MSS 0x400000
6902 val = rd32(hw, I40E_REG_MSS);
6903 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
6904 val &= ~I40E_REG_MSS_MIN_MASK;
6905 val |= I40E_64BYTE_MSS;
6906 wr32(hw, I40E_REG_MSS, val);
6907 }
6908
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08006909 if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00006910 msleep(75);
6911 ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
6912 if (ret)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006913 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
6914 i40e_stat_str(&pf->hw, ret),
6915 i40e_aq_str(&pf->hw,
6916 pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006917 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006918 /* reinit the misc interrupt */
6919 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
6920 ret = i40e_setup_misc_vector(pf);
6921
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04006922 /* Add a filter to drop all Flow control frames from any VSI from being
6923 * transmitted. By doing so we stop a malicious VF from sending out
6924 * PAUSE or PFC frames and potentially controlling traffic for other
6925 * PF/VF VSIs.
6926 * The FW can still send Flow control frames if enabled.
6927 */
6928 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
6929 pf->main_vsi_seid);
6930
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006931 /* restart the VSIs that were rebuilt and running before the reset */
6932 i40e_pf_unquiesce_all_vsi(pf);
6933
Mitch Williams69f64b22014-02-13 03:48:46 -08006934 if (pf->num_alloc_vfs) {
6935 for (v = 0; v < pf->num_alloc_vfs; v++)
6936 i40e_reset_vf(&pf->vf[v], true);
6937 }
6938
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006939 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00006940 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006941
6942end_core_reset:
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006943 clear_bit(__I40E_RESET_FAILED, &pf->state);
6944clear_recovery:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006945 clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
6946}
6947
6948/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006949 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006950 * @pf: board private structure
6951 *
6952 * Close up the VFs and other things in prep for a Core Reset,
6953 * then get ready to rebuild the world.
6954 **/
6955static void i40e_handle_reset_warning(struct i40e_pf *pf)
6956{
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006957 i40e_prep_for_reset(pf);
6958 i40e_reset_and_rebuild(pf, false);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006959}
6960
6961/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006962 * i40e_handle_mdd_event
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006963 * @pf: pointer to the PF structure
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006964 *
6965 * Called from the MDD irq handler to identify possibly malicious vfs
6966 **/
6967static void i40e_handle_mdd_event(struct i40e_pf *pf)
6968{
6969 struct i40e_hw *hw = &pf->hw;
6970 bool mdd_detected = false;
Neerav Parikhdf430b12014-06-04 01:23:15 +00006971 bool pf_mdd_detected = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006972 struct i40e_vf *vf;
6973 u32 reg;
6974 int i;
6975
6976 if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
6977 return;
6978
6979 /* find what triggered the MDD event */
6980 reg = rd32(hw, I40E_GL_MDET_TX);
6981 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006982 u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
6983 I40E_GL_MDET_TX_PF_NUM_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00006984 u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006985 I40E_GL_MDET_TX_VF_NUM_SHIFT;
Dan Carpenter013f6572014-10-22 20:06:29 -07006986 u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006987 I40E_GL_MDET_TX_EVENT_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00006988 u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
6989 I40E_GL_MDET_TX_QUEUE_SHIFT) -
6990 pf->hw.func_caps.base_queue;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00006991 if (netif_msg_tx_err(pf))
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006992 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 +00006993 event, queue, pf_num, vf_num);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006994 wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
6995 mdd_detected = true;
6996 }
6997 reg = rd32(hw, I40E_GL_MDET_RX);
6998 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006999 u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
7000 I40E_GL_MDET_RX_FUNCTION_SHIFT;
Dan Carpenter013f6572014-10-22 20:06:29 -07007001 u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007002 I40E_GL_MDET_RX_EVENT_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00007003 u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
7004 I40E_GL_MDET_RX_QUEUE_SHIFT) -
7005 pf->hw.func_caps.base_queue;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007006 if (netif_msg_rx_err(pf))
7007 dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
7008 event, queue, func);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007009 wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
7010 mdd_detected = true;
7011 }
7012
Neerav Parikhdf430b12014-06-04 01:23:15 +00007013 if (mdd_detected) {
7014 reg = rd32(hw, I40E_PF_MDET_TX);
7015 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
7016 wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007017 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
Neerav Parikhdf430b12014-06-04 01:23:15 +00007018 pf_mdd_detected = true;
7019 }
7020 reg = rd32(hw, I40E_PF_MDET_RX);
7021 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
7022 wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007023 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
Neerav Parikhdf430b12014-06-04 01:23:15 +00007024 pf_mdd_detected = true;
7025 }
7026 /* Queue belongs to the PF, initiate a reset */
7027 if (pf_mdd_detected) {
7028 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
7029 i40e_service_event_schedule(pf);
7030 }
7031 }
7032
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007033 /* see if one of the VFs needs its hand slapped */
7034 for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
7035 vf = &(pf->vf[i]);
7036 reg = rd32(hw, I40E_VP_MDET_TX(i));
7037 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
7038 wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
7039 vf->num_mdd_events++;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007040 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
7041 i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007042 }
7043
7044 reg = rd32(hw, I40E_VP_MDET_RX(i));
7045 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
7046 wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
7047 vf->num_mdd_events++;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007048 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
7049 i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007050 }
7051
7052 if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
7053 dev_info(&pf->pdev->dev,
7054 "Too many MDD events on VF %d, disabled\n", i);
7055 dev_info(&pf->pdev->dev,
7056 "Use PF Control I/F to re-enable the VF\n");
7057 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
7058 }
7059 }
7060
7061 /* re-enable mdd interrupt cause */
7062 clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
7063 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
7064 reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
7065 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
7066 i40e_flush(hw);
7067}
7068
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007069/**
Singhai, Anjali6a899022015-12-14 12:21:18 -08007070 * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007071 * @pf: board private structure
7072 **/
Singhai, Anjali6a899022015-12-14 12:21:18 -08007073static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007074{
Singhai, Anjali6a899022015-12-14 12:21:18 -08007075#if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007076 struct i40e_hw *hw = &pf->hw;
7077 i40e_status ret;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007078 __be16 port;
7079 int i;
7080
Singhai, Anjali6a899022015-12-14 12:21:18 -08007081 if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC))
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007082 return;
7083
Singhai, Anjali6a899022015-12-14 12:21:18 -08007084 pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007085
7086 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
Singhai, Anjali6a899022015-12-14 12:21:18 -08007087 if (pf->pending_udp_bitmap & BIT_ULL(i)) {
7088 pf->pending_udp_bitmap &= ~BIT_ULL(i);
7089 port = pf->udp_ports[i].index;
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007090 if (port)
7091 ret = i40e_aq_add_udp_tunnel(hw, ntohs(port),
Singhai, Anjali6a899022015-12-14 12:21:18 -08007092 pf->udp_ports[i].type,
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007093 NULL, NULL);
7094 else
7095 ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007096
7097 if (ret) {
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007098 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007099 "%s vxlan port %d, index %d failed, err %s aq_err %s\n",
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007100 port ? "add" : "delete",
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007101 ntohs(port), i,
7102 i40e_stat_str(&pf->hw, ret),
7103 i40e_aq_str(&pf->hw,
7104 pf->hw.aq.asq_last_status));
Singhai, Anjali6a899022015-12-14 12:21:18 -08007105 pf->udp_ports[i].index = 0;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007106 }
7107 }
7108 }
Singhai, Anjali6a899022015-12-14 12:21:18 -08007109#endif
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007110}
7111
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007112/**
7113 * i40e_service_task - Run the driver's async subtasks
7114 * @work: pointer to work_struct containing our data
7115 **/
7116static void i40e_service_task(struct work_struct *work)
7117{
7118 struct i40e_pf *pf = container_of(work,
7119 struct i40e_pf,
7120 service_task);
7121 unsigned long start_time = jiffies;
7122
Shannon Nelsone57a2fe2014-06-03 23:50:19 +00007123 /* don't bother with service tasks if a reset is in progress */
7124 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
7125 i40e_service_event_complete(pf);
7126 return;
7127 }
7128
Kiran Patilb03a8c12015-09-24 18:13:15 -04007129 i40e_detect_recover_hung(pf);
Jesse Brandeburg2818ccd2016-01-13 16:51:38 -08007130 i40e_sync_filters_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007131 i40e_reset_subtask(pf);
7132 i40e_handle_mdd_event(pf);
7133 i40e_vc_process_vflr_event(pf);
7134 i40e_watchdog_subtask(pf);
7135 i40e_fdir_reinit_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007136 i40e_sync_filters_subtask(pf);
Singhai, Anjali6a899022015-12-14 12:21:18 -08007137 i40e_sync_udp_filters_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007138 i40e_clean_adminq_subtask(pf);
7139
7140 i40e_service_event_complete(pf);
7141
7142 /* If the tasks have taken longer than one timer cycle or there
7143 * is more work to be done, reschedule the service task now
7144 * rather than wait for the timer to tick again.
7145 */
7146 if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
7147 test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
7148 test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
7149 test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
7150 i40e_service_event_schedule(pf);
7151}
7152
7153/**
7154 * i40e_service_timer - timer callback
7155 * @data: pointer to PF struct
7156 **/
7157static void i40e_service_timer(unsigned long data)
7158{
7159 struct i40e_pf *pf = (struct i40e_pf *)data;
7160
7161 mod_timer(&pf->service_timer,
7162 round_jiffies(jiffies + pf->service_timer_period));
7163 i40e_service_event_schedule(pf);
7164}
7165
7166/**
7167 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
7168 * @vsi: the VSI being configured
7169 **/
7170static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
7171{
7172 struct i40e_pf *pf = vsi->back;
7173
7174 switch (vsi->type) {
7175 case I40E_VSI_MAIN:
7176 vsi->alloc_queue_pairs = pf->num_lan_qps;
7177 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7178 I40E_REQ_DESCRIPTOR_MULTIPLE);
7179 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7180 vsi->num_q_vectors = pf->num_lan_msix;
7181 else
7182 vsi->num_q_vectors = 1;
7183
7184 break;
7185
7186 case I40E_VSI_FDIR:
7187 vsi->alloc_queue_pairs = 1;
7188 vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
7189 I40E_REQ_DESCRIPTOR_MULTIPLE);
7190 vsi->num_q_vectors = 1;
7191 break;
7192
7193 case I40E_VSI_VMDQ2:
7194 vsi->alloc_queue_pairs = pf->num_vmdq_qps;
7195 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7196 I40E_REQ_DESCRIPTOR_MULTIPLE);
7197 vsi->num_q_vectors = pf->num_vmdq_msix;
7198 break;
7199
7200 case I40E_VSI_SRIOV:
7201 vsi->alloc_queue_pairs = pf->num_vf_qps;
7202 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7203 I40E_REQ_DESCRIPTOR_MULTIPLE);
7204 break;
7205
Vasu Dev38e00432014-08-01 13:27:03 -07007206#ifdef I40E_FCOE
7207 case I40E_VSI_FCOE:
7208 vsi->alloc_queue_pairs = pf->num_fcoe_qps;
7209 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7210 I40E_REQ_DESCRIPTOR_MULTIPLE);
7211 vsi->num_q_vectors = pf->num_fcoe_msix;
7212 break;
7213
7214#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007215 default:
7216 WARN_ON(1);
7217 return -ENODATA;
7218 }
7219
7220 return 0;
7221}
7222
7223/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007224 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
7225 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007226 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007227 *
7228 * On error: returns error code (negative)
7229 * On success: returns 0
7230 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007231static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007232{
7233 int size;
7234 int ret = 0;
7235
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00007236 /* allocate memory for both Tx and Rx ring pointers */
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007237 size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
7238 vsi->tx_rings = kzalloc(size, GFP_KERNEL);
7239 if (!vsi->tx_rings)
7240 return -ENOMEM;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007241 vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
7242
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007243 if (alloc_qvectors) {
7244 /* allocate memory for q_vector pointers */
Julia Lawallf57e4fb2014-07-30 03:11:09 +00007245 size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007246 vsi->q_vectors = kzalloc(size, GFP_KERNEL);
7247 if (!vsi->q_vectors) {
7248 ret = -ENOMEM;
7249 goto err_vectors;
7250 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007251 }
7252 return ret;
7253
7254err_vectors:
7255 kfree(vsi->tx_rings);
7256 return ret;
7257}
7258
7259/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007260 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
7261 * @pf: board private structure
7262 * @type: type of VSI
7263 *
7264 * On error: returns error code (negative)
7265 * On success: returns vsi index in PF (positive)
7266 **/
7267static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
7268{
7269 int ret = -ENODEV;
7270 struct i40e_vsi *vsi;
7271 int vsi_idx;
7272 int i;
7273
7274 /* Need to protect the allocation of the VSIs at the PF level */
7275 mutex_lock(&pf->switch_mutex);
7276
7277 /* VSI list may be fragmented if VSI creation/destruction has
7278 * been happening. We can afford to do a quick scan to look
7279 * for any free VSIs in the list.
7280 *
7281 * find next empty vsi slot, looping back around if necessary
7282 */
7283 i = pf->next_vsi;
Mitch Williams505682c2014-05-20 08:01:37 +00007284 while (i < pf->num_alloc_vsi && pf->vsi[i])
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007285 i++;
Mitch Williams505682c2014-05-20 08:01:37 +00007286 if (i >= pf->num_alloc_vsi) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007287 i = 0;
7288 while (i < pf->next_vsi && pf->vsi[i])
7289 i++;
7290 }
7291
Mitch Williams505682c2014-05-20 08:01:37 +00007292 if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007293 vsi_idx = i; /* Found one! */
7294 } else {
7295 ret = -ENODEV;
Alexander Duyck493fb302013-09-28 07:01:44 +00007296 goto unlock_pf; /* out of VSI slots! */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007297 }
7298 pf->next_vsi = ++i;
7299
7300 vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
7301 if (!vsi) {
7302 ret = -ENOMEM;
Alexander Duyck493fb302013-09-28 07:01:44 +00007303 goto unlock_pf;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007304 }
7305 vsi->type = type;
7306 vsi->back = pf;
7307 set_bit(__I40E_DOWN, &vsi->state);
7308 vsi->flags = 0;
7309 vsi->idx = vsi_idx;
7310 vsi->rx_itr_setting = pf->rx_itr_default;
7311 vsi->tx_itr_setting = pf->tx_itr_default;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04007312 vsi->int_rate_limit = 0;
Anjali Singhai Jain5db4cb52015-02-24 06:58:49 +00007313 vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
7314 pf->rss_table_size : 64;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007315 vsi->netdev_registered = false;
7316 vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
7317 INIT_LIST_HEAD(&vsi->mac_filter_list);
Shannon Nelson63741842014-04-23 04:50:16 +00007318 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007319
Alexander Duyck9f65e152013-09-28 06:00:58 +00007320 ret = i40e_set_num_rings_in_vsi(vsi);
7321 if (ret)
7322 goto err_rings;
7323
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007324 ret = i40e_vsi_alloc_arrays(vsi, true);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007325 if (ret)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007326 goto err_rings;
Alexander Duyck493fb302013-09-28 07:01:44 +00007327
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007328 /* Setup default MSIX irq handler for VSI */
7329 i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
7330
Kiran Patil21659032015-09-30 14:09:03 -04007331 /* Initialize VSI lock */
7332 spin_lock_init(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007333 pf->vsi[vsi_idx] = vsi;
7334 ret = vsi_idx;
Alexander Duyck493fb302013-09-28 07:01:44 +00007335 goto unlock_pf;
7336
Alexander Duyck9f65e152013-09-28 06:00:58 +00007337err_rings:
Alexander Duyck493fb302013-09-28 07:01:44 +00007338 pf->next_vsi = i - 1;
7339 kfree(vsi);
7340unlock_pf:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007341 mutex_unlock(&pf->switch_mutex);
7342 return ret;
7343}
7344
7345/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007346 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
7347 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007348 * @free_qvectors: a bool to specify if q_vectors need to be freed.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007349 *
7350 * On error: returns error code (negative)
7351 * On success: returns 0
7352 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007353static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007354{
7355 /* free the ring and vector containers */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007356 if (free_qvectors) {
7357 kfree(vsi->q_vectors);
7358 vsi->q_vectors = NULL;
7359 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007360 kfree(vsi->tx_rings);
7361 vsi->tx_rings = NULL;
7362 vsi->rx_rings = NULL;
7363}
7364
7365/**
Helin Zhang28c58692015-10-26 19:44:27 -04007366 * i40e_clear_rss_config_user - clear the user configured RSS hash keys
7367 * and lookup table
7368 * @vsi: Pointer to VSI structure
7369 */
7370static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
7371{
7372 if (!vsi)
7373 return;
7374
7375 kfree(vsi->rss_hkey_user);
7376 vsi->rss_hkey_user = NULL;
7377
7378 kfree(vsi->rss_lut_user);
7379 vsi->rss_lut_user = NULL;
7380}
7381
7382/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007383 * i40e_vsi_clear - Deallocate the VSI provided
7384 * @vsi: the VSI being un-configured
7385 **/
7386static int i40e_vsi_clear(struct i40e_vsi *vsi)
7387{
7388 struct i40e_pf *pf;
7389
7390 if (!vsi)
7391 return 0;
7392
7393 if (!vsi->back)
7394 goto free_vsi;
7395 pf = vsi->back;
7396
7397 mutex_lock(&pf->switch_mutex);
7398 if (!pf->vsi[vsi->idx]) {
7399 dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
7400 vsi->idx, vsi->idx, vsi, vsi->type);
7401 goto unlock_vsi;
7402 }
7403
7404 if (pf->vsi[vsi->idx] != vsi) {
7405 dev_err(&pf->pdev->dev,
7406 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
7407 pf->vsi[vsi->idx]->idx,
7408 pf->vsi[vsi->idx],
7409 pf->vsi[vsi->idx]->type,
7410 vsi->idx, vsi, vsi->type);
7411 goto unlock_vsi;
7412 }
7413
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00007414 /* updates the PF for this cleared vsi */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007415 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
7416 i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
7417
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007418 i40e_vsi_free_arrays(vsi, true);
Helin Zhang28c58692015-10-26 19:44:27 -04007419 i40e_clear_rss_config_user(vsi);
Alexander Duyck493fb302013-09-28 07:01:44 +00007420
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007421 pf->vsi[vsi->idx] = NULL;
7422 if (vsi->idx < pf->next_vsi)
7423 pf->next_vsi = vsi->idx;
7424
7425unlock_vsi:
7426 mutex_unlock(&pf->switch_mutex);
7427free_vsi:
7428 kfree(vsi);
7429
7430 return 0;
7431}
7432
7433/**
Alexander Duyck9f65e152013-09-28 06:00:58 +00007434 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
7435 * @vsi: the VSI being cleaned
7436 **/
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00007437static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007438{
7439 int i;
7440
Greg Rose8e9dca52013-12-18 13:45:53 +00007441 if (vsi->tx_rings && vsi->tx_rings[0]) {
Neerav Parikhd7397642013-11-28 06:39:37 +00007442 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Mitch Williams00403f02013-09-28 07:13:13 +00007443 kfree_rcu(vsi->tx_rings[i], rcu);
7444 vsi->tx_rings[i] = NULL;
7445 vsi->rx_rings[i] = NULL;
7446 }
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00007447 }
Alexander Duyck9f65e152013-09-28 06:00:58 +00007448}
7449
7450/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007451 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
7452 * @vsi: the VSI being configured
7453 **/
7454static int i40e_alloc_rings(struct i40e_vsi *vsi)
7455{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00007456 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007457 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007458 int i;
7459
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007460 /* Set basic values in the rings to be used later during open() */
Neerav Parikhd7397642013-11-28 06:39:37 +00007461 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00007462 /* allocate space for both Tx and Rx in one shot */
Alexander Duyck9f65e152013-09-28 06:00:58 +00007463 tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
7464 if (!tx_ring)
7465 goto err_out;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007466
7467 tx_ring->queue_index = i;
7468 tx_ring->reg_idx = vsi->base_queue + i;
7469 tx_ring->ring_active = false;
7470 tx_ring->vsi = vsi;
7471 tx_ring->netdev = vsi->netdev;
7472 tx_ring->dev = &pf->pdev->dev;
7473 tx_ring->count = vsi->num_desc;
7474 tx_ring->size = 0;
7475 tx_ring->dcb_tc = 0;
Anjali Singhai Jain8e0764b2015-06-05 12:20:30 -04007476 if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
7477 tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
Anjali Singhai Jain527274c2015-06-05 12:20:31 -04007478 if (vsi->back->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE)
7479 tx_ring->flags |= I40E_TXR_FLAGS_OUTER_UDP_CSUM;
Alexander Duyck9f65e152013-09-28 06:00:58 +00007480 vsi->tx_rings[i] = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007481
Alexander Duyck9f65e152013-09-28 06:00:58 +00007482 rx_ring = &tx_ring[1];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007483 rx_ring->queue_index = i;
7484 rx_ring->reg_idx = vsi->base_queue + i;
7485 rx_ring->ring_active = false;
7486 rx_ring->vsi = vsi;
7487 rx_ring->netdev = vsi->netdev;
7488 rx_ring->dev = &pf->pdev->dev;
7489 rx_ring->count = vsi->num_desc;
7490 rx_ring->size = 0;
7491 rx_ring->dcb_tc = 0;
7492 if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED)
7493 set_ring_16byte_desc_enabled(rx_ring);
7494 else
7495 clear_ring_16byte_desc_enabled(rx_ring);
Alexander Duyck9f65e152013-09-28 06:00:58 +00007496 vsi->rx_rings[i] = rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007497 }
7498
7499 return 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00007500
7501err_out:
7502 i40e_vsi_clear_rings(vsi);
7503 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007504}
7505
7506/**
7507 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
7508 * @pf: board private structure
7509 * @vectors: the number of MSI-X vectors to request
7510 *
7511 * Returns the number of vectors reserved, or error
7512 **/
7513static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
7514{
Alexander Gordeev7b37f372014-02-18 11:11:42 +01007515 vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
7516 I40E_MIN_MSIX, vectors);
7517 if (vectors < 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007518 dev_info(&pf->pdev->dev,
Alexander Gordeev7b37f372014-02-18 11:11:42 +01007519 "MSI-X vector reservation failed: %d\n", vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007520 vectors = 0;
7521 }
7522
7523 return vectors;
7524}
7525
7526/**
7527 * i40e_init_msix - Setup the MSIX capability
7528 * @pf: board private structure
7529 *
7530 * Work with the OS to set up the MSIX vectors needed.
7531 *
Shannon Nelson3b444392015-02-26 16:15:57 +00007532 * Returns the number of vectors reserved or negative on failure
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007533 **/
7534static int i40e_init_msix(struct i40e_pf *pf)
7535{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007536 struct i40e_hw *hw = &pf->hw;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007537 int vectors_left;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007538 int v_budget, i;
Shannon Nelson3b444392015-02-26 16:15:57 +00007539 int v_actual;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007540
7541 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
7542 return -ENODEV;
7543
7544 /* The number of vectors we'll request will be comprised of:
7545 * - Add 1 for "other" cause for Admin Queue events, etc.
7546 * - The number of LAN queue pairs
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00007547 * - Queues being used for RSS.
7548 * We don't need as many as max_rss_size vectors.
7549 * use rss_size instead in the calculation since that
7550 * is governed by number of cpus in the system.
7551 * - assumes symmetric Tx/Rx pairing
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007552 * - The number of VMDq pairs
Vasu Dev38e00432014-08-01 13:27:03 -07007553#ifdef I40E_FCOE
7554 * - The number of FCOE qps.
7555#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007556 * Once we count this up, try the request.
7557 *
7558 * If we can't get what we want, we'll simplify to nearly nothing
7559 * and try again. If that still fails, we punt.
7560 */
Shannon Nelson1e200e42015-02-27 09:15:24 +00007561 vectors_left = hw->func_caps.num_msix_vectors;
7562 v_budget = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007563
Shannon Nelson1e200e42015-02-27 09:15:24 +00007564 /* reserve one vector for miscellaneous handler */
7565 if (vectors_left) {
7566 v_budget++;
7567 vectors_left--;
7568 }
7569
7570 /* reserve vectors for the main PF traffic queues */
7571 pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left);
7572 vectors_left -= pf->num_lan_msix;
7573 v_budget += pf->num_lan_msix;
7574
7575 /* reserve one vector for sideband flow director */
7576 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
7577 if (vectors_left) {
7578 v_budget++;
7579 vectors_left--;
7580 } else {
7581 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
7582 }
7583 }
John W Linville83840e42015-01-14 03:06:28 +00007584
Vasu Dev38e00432014-08-01 13:27:03 -07007585#ifdef I40E_FCOE
Shannon Nelson1e200e42015-02-27 09:15:24 +00007586 /* can we reserve enough for FCoE? */
Vasu Dev38e00432014-08-01 13:27:03 -07007587 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
Shannon Nelson1e200e42015-02-27 09:15:24 +00007588 if (!vectors_left)
7589 pf->num_fcoe_msix = 0;
7590 else if (vectors_left >= pf->num_fcoe_qps)
7591 pf->num_fcoe_msix = pf->num_fcoe_qps;
7592 else
7593 pf->num_fcoe_msix = 1;
Vasu Dev38e00432014-08-01 13:27:03 -07007594 v_budget += pf->num_fcoe_msix;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007595 vectors_left -= pf->num_fcoe_msix;
Vasu Dev38e00432014-08-01 13:27:03 -07007596 }
Shannon Nelson1e200e42015-02-27 09:15:24 +00007597
Vasu Dev38e00432014-08-01 13:27:03 -07007598#endif
Shannon Nelson1e200e42015-02-27 09:15:24 +00007599 /* any vectors left over go for VMDq support */
7600 if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
7601 int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
7602 int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
7603
7604 /* if we're short on vectors for what's desired, we limit
7605 * the queues per vmdq. If this is still more than are
7606 * available, the user will need to change the number of
7607 * queues/vectors used by the PF later with the ethtool
7608 * channels command
7609 */
7610 if (vmdq_vecs < vmdq_vecs_wanted)
7611 pf->num_vmdq_qps = 1;
7612 pf->num_vmdq_msix = pf->num_vmdq_qps;
7613
7614 v_budget += vmdq_vecs;
7615 vectors_left -= vmdq_vecs;
7616 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007617
7618 pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
7619 GFP_KERNEL);
7620 if (!pf->msix_entries)
7621 return -ENOMEM;
7622
7623 for (i = 0; i < v_budget; i++)
7624 pf->msix_entries[i].entry = i;
Shannon Nelson3b444392015-02-26 16:15:57 +00007625 v_actual = i40e_reserve_msix_vectors(pf, v_budget);
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007626
Shannon Nelson3b444392015-02-26 16:15:57 +00007627 if (v_actual != v_budget) {
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007628 /* If we have limited resources, we will start with no vectors
7629 * for the special features and then allocate vectors to some
7630 * of these features based on the policy and at the end disable
7631 * the features that did not get any vectors.
7632 */
Vasu Dev38e00432014-08-01 13:27:03 -07007633#ifdef I40E_FCOE
7634 pf->num_fcoe_qps = 0;
7635 pf->num_fcoe_msix = 0;
7636#endif
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007637 pf->num_vmdq_msix = 0;
7638 }
7639
Shannon Nelson3b444392015-02-26 16:15:57 +00007640 if (v_actual < I40E_MIN_MSIX) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007641 pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
7642 kfree(pf->msix_entries);
7643 pf->msix_entries = NULL;
7644 return -ENODEV;
7645
Shannon Nelson3b444392015-02-26 16:15:57 +00007646 } else if (v_actual == I40E_MIN_MSIX) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007647 /* Adjust for minimal MSIX use */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007648 pf->num_vmdq_vsis = 0;
7649 pf->num_vmdq_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007650 pf->num_lan_qps = 1;
7651 pf->num_lan_msix = 1;
7652
Shannon Nelson3b444392015-02-26 16:15:57 +00007653 } else if (v_actual != v_budget) {
7654 int vec;
7655
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007656 /* reserve the misc vector */
Shannon Nelson3b444392015-02-26 16:15:57 +00007657 vec = v_actual - 1;
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007658
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007659 /* Scale vector usage down */
7660 pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007661 pf->num_vmdq_vsis = 1;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007662 pf->num_vmdq_qps = 1;
7663 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007664
7665 /* partition out the remaining vectors */
7666 switch (vec) {
7667 case 2:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007668 pf->num_lan_msix = 1;
7669 break;
7670 case 3:
Vasu Dev38e00432014-08-01 13:27:03 -07007671#ifdef I40E_FCOE
7672 /* give one vector to FCoE */
7673 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
7674 pf->num_lan_msix = 1;
7675 pf->num_fcoe_msix = 1;
7676 }
7677#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007678 pf->num_lan_msix = 2;
Vasu Dev38e00432014-08-01 13:27:03 -07007679#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007680 break;
7681 default:
Vasu Dev38e00432014-08-01 13:27:03 -07007682#ifdef I40E_FCOE
7683 /* give one vector to FCoE */
7684 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
7685 pf->num_fcoe_msix = 1;
7686 vec--;
7687 }
7688#endif
Shannon Nelson1e200e42015-02-27 09:15:24 +00007689 /* give the rest to the PF */
7690 pf->num_lan_msix = min_t(int, vec, pf->num_lan_qps);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007691 break;
7692 }
7693 }
7694
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007695 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
7696 (pf->num_vmdq_msix == 0)) {
7697 dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
7698 pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
7699 }
Vasu Dev38e00432014-08-01 13:27:03 -07007700#ifdef I40E_FCOE
7701
7702 if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) {
7703 dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n");
7704 pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
7705 }
7706#endif
Shannon Nelson3b444392015-02-26 16:15:57 +00007707 return v_actual;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007708}
7709
7710/**
Greg Rose90e04072014-03-06 08:59:57 +00007711 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
Alexander Duyck493fb302013-09-28 07:01:44 +00007712 * @vsi: the VSI being configured
7713 * @v_idx: index of the vector in the vsi struct
7714 *
7715 * We allocate one q_vector. If allocation fails we return -ENOMEM.
7716 **/
Greg Rose90e04072014-03-06 08:59:57 +00007717static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx)
Alexander Duyck493fb302013-09-28 07:01:44 +00007718{
7719 struct i40e_q_vector *q_vector;
7720
7721 /* allocate q_vector */
7722 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
7723 if (!q_vector)
7724 return -ENOMEM;
7725
7726 q_vector->vsi = vsi;
7727 q_vector->v_idx = v_idx;
7728 cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
7729 if (vsi->netdev)
7730 netif_napi_add(vsi->netdev, &q_vector->napi,
Jesse Brandeburgeefeace2014-05-10 04:49:13 +00007731 i40e_napi_poll, NAPI_POLL_WEIGHT);
Alexander Duyck493fb302013-09-28 07:01:44 +00007732
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00007733 q_vector->rx.latency_range = I40E_LOW_LATENCY;
7734 q_vector->tx.latency_range = I40E_LOW_LATENCY;
7735
Alexander Duyck493fb302013-09-28 07:01:44 +00007736 /* tie q_vector and vsi together */
7737 vsi->q_vectors[v_idx] = q_vector;
7738
7739 return 0;
7740}
7741
7742/**
Greg Rose90e04072014-03-06 08:59:57 +00007743 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007744 * @vsi: the VSI being configured
7745 *
7746 * We allocate one q_vector per queue interrupt. If allocation fails we
7747 * return -ENOMEM.
7748 **/
Greg Rose90e04072014-03-06 08:59:57 +00007749static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007750{
7751 struct i40e_pf *pf = vsi->back;
7752 int v_idx, num_q_vectors;
Alexander Duyck493fb302013-09-28 07:01:44 +00007753 int err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007754
7755 /* if not MSIX, give the one vector only to the LAN VSI */
7756 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7757 num_q_vectors = vsi->num_q_vectors;
7758 else if (vsi == pf->vsi[pf->lan_vsi])
7759 num_q_vectors = 1;
7760 else
7761 return -EINVAL;
7762
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007763 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
Greg Rose90e04072014-03-06 08:59:57 +00007764 err = i40e_vsi_alloc_q_vector(vsi, v_idx);
Alexander Duyck493fb302013-09-28 07:01:44 +00007765 if (err)
7766 goto err_out;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007767 }
7768
7769 return 0;
Alexander Duyck493fb302013-09-28 07:01:44 +00007770
7771err_out:
7772 while (v_idx--)
7773 i40e_free_q_vector(vsi, v_idx);
7774
7775 return err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007776}
7777
7778/**
7779 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
7780 * @pf: board private structure to initialize
7781 **/
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007782static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007783{
Shannon Nelson3b444392015-02-26 16:15:57 +00007784 int vectors = 0;
7785 ssize_t size;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007786
7787 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
Shannon Nelson3b444392015-02-26 16:15:57 +00007788 vectors = i40e_init_msix(pf);
7789 if (vectors < 0) {
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08007790 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -07007791#ifdef I40E_FCOE
7792 I40E_FLAG_FCOE_ENABLED |
7793#endif
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08007794 I40E_FLAG_RSS_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00007795 I40E_FLAG_DCB_CAPABLE |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08007796 I40E_FLAG_SRIOV_ENABLED |
7797 I40E_FLAG_FD_SB_ENABLED |
7798 I40E_FLAG_FD_ATR_ENABLED |
7799 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007800
7801 /* rework the queue expectations without MSIX */
7802 i40e_determine_queue_usage(pf);
7803 }
7804 }
7805
7806 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
7807 (pf->flags & I40E_FLAG_MSI_ENABLED)) {
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08007808 dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
Shannon Nelson3b444392015-02-26 16:15:57 +00007809 vectors = pci_enable_msi(pf->pdev);
7810 if (vectors < 0) {
7811 dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
7812 vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007813 pf->flags &= ~I40E_FLAG_MSI_ENABLED;
7814 }
Shannon Nelson3b444392015-02-26 16:15:57 +00007815 vectors = 1; /* one MSI or Legacy vector */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007816 }
7817
Shannon Nelson958a3e32013-09-28 07:13:28 +00007818 if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08007819 dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
Shannon Nelson958a3e32013-09-28 07:13:28 +00007820
Shannon Nelson3b444392015-02-26 16:15:57 +00007821 /* set up vector assignment tracking */
7822 size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
7823 pf->irq_pile = kzalloc(size, GFP_KERNEL);
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007824 if (!pf->irq_pile) {
7825 dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n");
7826 return -ENOMEM;
7827 }
Shannon Nelson3b444392015-02-26 16:15:57 +00007828 pf->irq_pile->num_entries = vectors;
7829 pf->irq_pile->search_hint = 0;
7830
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007831 /* track first vector for misc interrupts, ignore return */
Shannon Nelson3b444392015-02-26 16:15:57 +00007832 (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007833
7834 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007835}
7836
7837/**
7838 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
7839 * @pf: board private structure
7840 *
7841 * This sets up the handler for MSIX 0, which is used to manage the
7842 * non-queue interrupts, e.g. AdminQ and errors. This is not used
7843 * when in MSI or Legacy interrupt mode.
7844 **/
7845static int i40e_setup_misc_vector(struct i40e_pf *pf)
7846{
7847 struct i40e_hw *hw = &pf->hw;
7848 int err = 0;
7849
7850 /* Only request the irq if this is the first time through, and
7851 * not when we're rebuilding after a Reset
7852 */
7853 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
7854 err = request_irq(pf->msix_entries[0].vector,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00007855 i40e_intr, 0, pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007856 if (err) {
7857 dev_info(&pf->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08007858 "request_irq for %s failed: %d\n",
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00007859 pf->int_name, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007860 return -EFAULT;
7861 }
7862 }
7863
Jacob Kellerab437b52014-12-14 01:55:08 +00007864 i40e_enable_misc_int_causes(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007865
7866 /* associate no queues to the misc vector */
7867 wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
7868 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
7869
7870 i40e_flush(hw);
7871
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08007872 i40e_irq_dynamic_enable_icr0(pf, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007873
7874 return err;
7875}
7876
7877/**
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007878 * i40e_config_rss_aq - Prepare for RSS using AQ commands
7879 * @vsi: vsi structure
7880 * @seed: RSS hash seed
7881 **/
Helin Zhange69ff812015-10-21 19:56:22 -04007882static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
7883 u8 *lut, u16 lut_size)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007884{
7885 struct i40e_aqc_get_set_rss_key_data rss_key;
7886 struct i40e_pf *pf = vsi->back;
7887 struct i40e_hw *hw = &pf->hw;
7888 bool pf_lut = false;
7889 u8 *rss_lut;
7890 int ret, i;
7891
7892 memset(&rss_key, 0, sizeof(rss_key));
7893 memcpy(&rss_key, seed, sizeof(rss_key));
7894
7895 rss_lut = kzalloc(pf->rss_table_size, GFP_KERNEL);
7896 if (!rss_lut)
7897 return -ENOMEM;
7898
7899 /* Populate the LUT with max no. of queues in round robin fashion */
7900 for (i = 0; i < vsi->rss_table_size; i++)
7901 rss_lut[i] = i % vsi->rss_size;
7902
7903 ret = i40e_aq_set_rss_key(hw, vsi->id, &rss_key);
7904 if (ret) {
7905 dev_info(&pf->pdev->dev,
7906 "Cannot set RSS key, err %s aq_err %s\n",
7907 i40e_stat_str(&pf->hw, ret),
7908 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai126b63d2015-08-24 13:26:53 -07007909 goto config_rss_aq_out;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007910 }
7911
7912 if (vsi->type == I40E_VSI_MAIN)
7913 pf_lut = true;
7914
7915 ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, rss_lut,
7916 vsi->rss_table_size);
7917 if (ret)
7918 dev_info(&pf->pdev->dev,
7919 "Cannot set RSS lut, err %s aq_err %s\n",
7920 i40e_stat_str(&pf->hw, ret),
7921 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
7922
Anjali Singhai126b63d2015-08-24 13:26:53 -07007923config_rss_aq_out:
7924 kfree(rss_lut);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007925 return ret;
7926}
7927
7928/**
7929 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
7930 * @vsi: VSI structure
7931 **/
7932static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
7933{
7934 u8 seed[I40E_HKEY_ARRAY_SIZE];
7935 struct i40e_pf *pf = vsi->back;
Helin Zhange69ff812015-10-21 19:56:22 -04007936 u8 *lut;
7937 int ret;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007938
Helin Zhange69ff812015-10-21 19:56:22 -04007939 if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE))
7940 return 0;
7941
7942 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
7943 if (!lut)
7944 return -ENOMEM;
7945
7946 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007947 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
Helin Zhangacd65442015-10-26 19:44:28 -04007948 vsi->rss_size = min_t(int, pf->alloc_rss_size, vsi->num_queue_pairs);
Helin Zhange69ff812015-10-21 19:56:22 -04007949 ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
7950 kfree(lut);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007951
Helin Zhange69ff812015-10-21 19:56:22 -04007952 return ret;
7953}
7954
7955/**
Anjali Singhai Jain95a73782015-12-22 14:25:04 -08007956 * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
7957 * @vsi: Pointer to vsi structure
7958 * @seed: Buffter to store the hash keys
7959 * @lut: Buffer to store the lookup table entries
7960 * @lut_size: Size of buffer to store the lookup table entries
7961 *
7962 * Return 0 on success, negative on failure
7963 */
7964static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
7965 u8 *lut, u16 lut_size)
7966{
7967 struct i40e_pf *pf = vsi->back;
7968 struct i40e_hw *hw = &pf->hw;
7969 int ret = 0;
7970
7971 if (seed) {
7972 ret = i40e_aq_get_rss_key(hw, vsi->id,
7973 (struct i40e_aqc_get_set_rss_key_data *)seed);
7974 if (ret) {
7975 dev_info(&pf->pdev->dev,
7976 "Cannot get RSS key, err %s aq_err %s\n",
7977 i40e_stat_str(&pf->hw, ret),
7978 i40e_aq_str(&pf->hw,
7979 pf->hw.aq.asq_last_status));
7980 return ret;
7981 }
7982 }
7983
7984 if (lut) {
7985 bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
7986
7987 ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
7988 if (ret) {
7989 dev_info(&pf->pdev->dev,
7990 "Cannot get RSS lut, err %s aq_err %s\n",
7991 i40e_stat_str(&pf->hw, ret),
7992 i40e_aq_str(&pf->hw,
7993 pf->hw.aq.asq_last_status));
7994 return ret;
7995 }
7996 }
7997
7998 return ret;
7999}
8000
8001/**
Helin Zhang043dd652015-10-21 19:56:23 -04008002 * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
Helin Zhange69ff812015-10-21 19:56:22 -04008003 * @vsi: Pointer to vsi structure
8004 * @seed: RSS hash seed
8005 * @lut: Lookup table
8006 * @lut_size: Lookup table size
8007 *
8008 * Returns 0 on success, negative on failure
8009 **/
8010static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
8011 const u8 *lut, u16 lut_size)
8012{
8013 struct i40e_pf *pf = vsi->back;
8014 struct i40e_hw *hw = &pf->hw;
8015 u8 i;
8016
8017 /* Fill out hash function seed */
8018 if (seed) {
8019 u32 *seed_dw = (u32 *)seed;
8020
8021 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
8022 wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
8023 }
8024
8025 if (lut) {
8026 u32 *lut_dw = (u32 *)lut;
8027
8028 if (lut_size != I40E_HLUT_ARRAY_SIZE)
8029 return -EINVAL;
8030
8031 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8032 wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
8033 }
8034 i40e_flush(hw);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008035
8036 return 0;
8037}
8038
8039/**
Helin Zhang043dd652015-10-21 19:56:23 -04008040 * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
8041 * @vsi: Pointer to VSI structure
8042 * @seed: Buffer to store the keys
8043 * @lut: Buffer to store the lookup table entries
8044 * @lut_size: Size of buffer to store the lookup table entries
8045 *
8046 * Returns 0 on success, negative on failure
8047 */
8048static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
8049 u8 *lut, u16 lut_size)
8050{
8051 struct i40e_pf *pf = vsi->back;
8052 struct i40e_hw *hw = &pf->hw;
8053 u16 i;
8054
8055 if (seed) {
8056 u32 *seed_dw = (u32 *)seed;
8057
8058 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
8059 seed_dw[i] = rd32(hw, I40E_PFQF_HKEY(i));
8060 }
8061 if (lut) {
8062 u32 *lut_dw = (u32 *)lut;
8063
8064 if (lut_size != I40E_HLUT_ARRAY_SIZE)
8065 return -EINVAL;
8066 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8067 lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
8068 }
8069
8070 return 0;
8071}
8072
8073/**
8074 * i40e_config_rss - Configure RSS keys and lut
8075 * @vsi: Pointer to VSI structure
8076 * @seed: RSS hash seed
8077 * @lut: Lookup table
8078 * @lut_size: Lookup table size
8079 *
8080 * Returns 0 on success, negative on failure
8081 */
8082int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
8083{
8084 struct i40e_pf *pf = vsi->back;
8085
8086 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
8087 return i40e_config_rss_aq(vsi, seed, lut, lut_size);
8088 else
8089 return i40e_config_rss_reg(vsi, seed, lut, lut_size);
8090}
8091
8092/**
8093 * i40e_get_rss - Get RSS keys and lut
8094 * @vsi: Pointer to VSI structure
8095 * @seed: Buffer to store the keys
8096 * @lut: Buffer to store the lookup table entries
8097 * lut_size: Size of buffer to store the lookup table entries
8098 *
8099 * Returns 0 on success, negative on failure
8100 */
8101int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
8102{
Anjali Singhai Jain95a73782015-12-22 14:25:04 -08008103 struct i40e_pf *pf = vsi->back;
8104
8105 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
8106 return i40e_get_rss_aq(vsi, seed, lut, lut_size);
8107 else
8108 return i40e_get_rss_reg(vsi, seed, lut, lut_size);
Helin Zhang043dd652015-10-21 19:56:23 -04008109}
8110
8111/**
Helin Zhange69ff812015-10-21 19:56:22 -04008112 * i40e_fill_rss_lut - Fill the RSS lookup table with default values
8113 * @pf: Pointer to board private structure
8114 * @lut: Lookup table
8115 * @rss_table_size: Lookup table size
8116 * @rss_size: Range of queue number for hashing
8117 */
8118static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
8119 u16 rss_table_size, u16 rss_size)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008120{
Helin Zhange69ff812015-10-21 19:56:22 -04008121 u16 i;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008122
Helin Zhange69ff812015-10-21 19:56:22 -04008123 for (i = 0; i < rss_table_size; i++)
8124 lut[i] = i % rss_size;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008125}
8126
8127/**
Helin Zhang043dd652015-10-21 19:56:23 -04008128 * i40e_pf_config_rss - Prepare for RSS if used
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008129 * @pf: board private structure
8130 **/
Helin Zhang043dd652015-10-21 19:56:23 -04008131static int i40e_pf_config_rss(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008132{
Anjali Singhai Jain66ddcff2015-02-24 06:58:50 +00008133 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008134 u8 seed[I40E_HKEY_ARRAY_SIZE];
Helin Zhange69ff812015-10-21 19:56:22 -04008135 u8 *lut;
Anjali Singhai Jain4617e8c2013-11-20 10:02:56 +00008136 struct i40e_hw *hw = &pf->hw;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00008137 u32 reg_val;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008138 u64 hena;
Helin Zhange69ff812015-10-21 19:56:22 -04008139 int ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008140
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008141 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
8142 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
8143 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008144 hena |= i40e_pf_get_default_rss_hena(pf);
8145
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008146 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
8147 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
8148
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008149 /* Determine the RSS table size based on the hardware capabilities */
Carolyn Wybornye157ea32014-06-03 23:50:22 +00008150 reg_val = rd32(hw, I40E_PFQF_CTL_0);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008151 reg_val = (pf->rss_table_size == 512) ?
8152 (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
8153 (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
Carolyn Wybornye157ea32014-06-03 23:50:22 +00008154 wr32(hw, I40E_PFQF_CTL_0, reg_val);
8155
Helin Zhang28c58692015-10-26 19:44:27 -04008156 /* Determine the RSS size of the VSI */
8157 if (!vsi->rss_size)
Helin Zhangacd65442015-10-26 19:44:28 -04008158 vsi->rss_size = min_t(int, pf->alloc_rss_size,
8159 vsi->num_queue_pairs);
Helin Zhang28c58692015-10-26 19:44:27 -04008160
Helin Zhange69ff812015-10-21 19:56:22 -04008161 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
8162 if (!lut)
8163 return -ENOMEM;
8164
Helin Zhang28c58692015-10-26 19:44:27 -04008165 /* Use user configured lut if there is one, otherwise use default */
8166 if (vsi->rss_lut_user)
8167 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
8168 else
8169 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
Helin Zhange69ff812015-10-21 19:56:22 -04008170
Helin Zhang28c58692015-10-26 19:44:27 -04008171 /* Use user configured hash key if there is one, otherwise
8172 * use default.
8173 */
8174 if (vsi->rss_hkey_user)
8175 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
8176 else
8177 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
Helin Zhang043dd652015-10-21 19:56:23 -04008178 ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
Helin Zhange69ff812015-10-21 19:56:22 -04008179 kfree(lut);
8180
8181 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008182}
8183
8184/**
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008185 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
8186 * @pf: board private structure
8187 * @queue_count: the requested queue count for rss.
8188 *
8189 * returns 0 if rss is not enabled, if enabled returns the final rss queue
8190 * count which may be different from the requested queue count.
8191 **/
8192int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
8193{
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008194 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
8195 int new_rss_size;
8196
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008197 if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
8198 return 0;
8199
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008200 new_rss_size = min_t(int, queue_count, pf->rss_size_max);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008201
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008202 if (queue_count != vsi->num_queue_pairs) {
8203 vsi->req_queue_pairs = queue_count;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008204 i40e_prep_for_reset(pf);
8205
Helin Zhangacd65442015-10-26 19:44:28 -04008206 pf->alloc_rss_size = new_rss_size;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008207
8208 i40e_reset_and_rebuild(pf, true);
Helin Zhang28c58692015-10-26 19:44:27 -04008209
8210 /* Discard the user configured hash keys and lut, if less
8211 * queues are enabled.
8212 */
8213 if (queue_count < vsi->rss_size) {
8214 i40e_clear_rss_config_user(vsi);
8215 dev_dbg(&pf->pdev->dev,
8216 "discard user configured hash keys and lut\n");
8217 }
8218
8219 /* Reset vsi->rss_size, as number of enabled queues changed */
Helin Zhangacd65442015-10-26 19:44:28 -04008220 vsi->rss_size = min_t(int, pf->alloc_rss_size,
8221 vsi->num_queue_pairs);
Helin Zhang28c58692015-10-26 19:44:27 -04008222
Helin Zhang043dd652015-10-21 19:56:23 -04008223 i40e_pf_config_rss(pf);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008224 }
Helin Zhange36b0b12015-10-26 19:44:36 -04008225 dev_info(&pf->pdev->dev, "RSS count/HW max RSS count: %d/%d\n",
8226 pf->alloc_rss_size, pf->rss_size_max);
Helin Zhangacd65442015-10-26 19:44:28 -04008227 return pf->alloc_rss_size;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008228}
8229
8230/**
Greg Rosef4492db2015-02-06 08:52:12 +00008231 * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
8232 * @pf: board private structure
8233 **/
8234i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf)
8235{
8236 i40e_status status;
8237 bool min_valid, max_valid;
8238 u32 max_bw, min_bw;
8239
8240 status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
8241 &min_valid, &max_valid);
8242
8243 if (!status) {
8244 if (min_valid)
8245 pf->npar_min_bw = min_bw;
8246 if (max_valid)
8247 pf->npar_max_bw = max_bw;
8248 }
8249
8250 return status;
8251}
8252
8253/**
8254 * i40e_set_npar_bw_setting - Set BW settings for this PF partition
8255 * @pf: board private structure
8256 **/
8257i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf)
8258{
8259 struct i40e_aqc_configure_partition_bw_data bw_data;
8260 i40e_status status;
8261
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00008262 /* Set the valid bit for this PF */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008263 bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
Greg Rosef4492db2015-02-06 08:52:12 +00008264 bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK;
8265 bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK;
8266
8267 /* Set the new bandwidths */
8268 status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
8269
8270 return status;
8271}
8272
8273/**
8274 * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
8275 * @pf: board private structure
8276 **/
8277i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf)
8278{
8279 /* Commit temporary BW setting to permanent NVM image */
8280 enum i40e_admin_queue_err last_aq_status;
8281 i40e_status ret;
8282 u16 nvm_word;
8283
8284 if (pf->hw.partition_id != 1) {
8285 dev_info(&pf->pdev->dev,
8286 "Commit BW only works on partition 1! This is partition %d",
8287 pf->hw.partition_id);
8288 ret = I40E_NOT_SUPPORTED;
8289 goto bw_commit_out;
8290 }
8291
8292 /* Acquire NVM for read access */
8293 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
8294 last_aq_status = pf->hw.aq.asq_last_status;
8295 if (ret) {
8296 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008297 "Cannot acquire NVM for read access, err %s aq_err %s\n",
8298 i40e_stat_str(&pf->hw, ret),
8299 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008300 goto bw_commit_out;
8301 }
8302
8303 /* Read word 0x10 of NVM - SW compatibility word 1 */
8304 ret = i40e_aq_read_nvm(&pf->hw,
8305 I40E_SR_NVM_CONTROL_WORD,
8306 0x10, sizeof(nvm_word), &nvm_word,
8307 false, NULL);
8308 /* Save off last admin queue command status before releasing
8309 * the NVM
8310 */
8311 last_aq_status = pf->hw.aq.asq_last_status;
8312 i40e_release_nvm(&pf->hw);
8313 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008314 dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
8315 i40e_stat_str(&pf->hw, ret),
8316 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008317 goto bw_commit_out;
8318 }
8319
8320 /* Wait a bit for NVM release to complete */
8321 msleep(50);
8322
8323 /* Acquire NVM for write access */
8324 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
8325 last_aq_status = pf->hw.aq.asq_last_status;
8326 if (ret) {
8327 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008328 "Cannot acquire NVM for write access, err %s aq_err %s\n",
8329 i40e_stat_str(&pf->hw, ret),
8330 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008331 goto bw_commit_out;
8332 }
8333 /* Write it back out unchanged to initiate update NVM,
8334 * which will force a write of the shadow (alt) RAM to
8335 * the NVM - thus storing the bandwidth values permanently.
8336 */
8337 ret = i40e_aq_update_nvm(&pf->hw,
8338 I40E_SR_NVM_CONTROL_WORD,
8339 0x10, sizeof(nvm_word),
8340 &nvm_word, true, NULL);
8341 /* Save off last admin queue command status before releasing
8342 * the NVM
8343 */
8344 last_aq_status = pf->hw.aq.asq_last_status;
8345 i40e_release_nvm(&pf->hw);
8346 if (ret)
8347 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008348 "BW settings NOT SAVED, err %s aq_err %s\n",
8349 i40e_stat_str(&pf->hw, ret),
8350 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008351bw_commit_out:
8352
8353 return ret;
8354}
8355
8356/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008357 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
8358 * @pf: board private structure to initialize
8359 *
8360 * i40e_sw_init initializes the Adapter private data structure.
8361 * Fields are initialized based on PCI device information and
8362 * OS network device settings (MTU size).
8363 **/
8364static int i40e_sw_init(struct i40e_pf *pf)
8365{
8366 int err = 0;
8367 int size;
8368
8369 pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE,
8370 (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK));
Shannon Nelson27599972013-11-16 10:00:43 +00008371 pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008372 if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) {
8373 if (I40E_DEBUG_USER & debug)
8374 pf->hw.debug_mask = debug;
8375 pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER),
8376 I40E_DEFAULT_MSG_ENABLE);
8377 }
8378
8379 /* Set default capability flags */
8380 pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
8381 I40E_FLAG_MSI_ENABLED |
Shannon Nelson9ac77262015-08-27 11:42:40 -04008382 I40E_FLAG_LINK_POLLING_ENABLED |
Mitch Williams2bc7ee82015-02-06 08:52:11 +00008383 I40E_FLAG_MSIX_ENABLED;
8384
8385 if (iommu_present(&pci_bus_type))
8386 pf->flags |= I40E_FLAG_RX_PS_ENABLED;
8387 else
8388 pf->flags |= I40E_FLAG_RX_1BUF_ENABLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008389
Mitch Williamsca99eb92014-04-04 04:43:07 +00008390 /* Set default ITR */
8391 pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
8392 pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
8393
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008394 /* Depending on PF configurations, it is possible that the RSS
8395 * maximum might end up larger than the available queues
8396 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008397 pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
Helin Zhangacd65442015-10-26 19:44:28 -04008398 pf->alloc_rss_size = 1;
Anjali Singhai Jain5db4cb52015-02-24 06:58:49 +00008399 pf->rss_table_size = pf->hw.func_caps.rss_table_size;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008400 pf->rss_size_max = min_t(int, pf->rss_size_max,
8401 pf->hw.func_caps.num_tx_qp);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008402 if (pf->hw.func_caps.rss) {
8403 pf->flags |= I40E_FLAG_RSS_ENABLED;
Helin Zhangacd65442015-10-26 19:44:28 -04008404 pf->alloc_rss_size = min_t(int, pf->rss_size_max,
8405 num_online_cpus());
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008406 }
8407
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008408 /* MFP mode enabled */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04008409 if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008410 pf->flags |= I40E_FLAG_MFP_ENABLED;
8411 dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
Greg Rosef4492db2015-02-06 08:52:12 +00008412 if (i40e_get_npar_bw_setting(pf))
8413 dev_warn(&pf->pdev->dev,
8414 "Could not get NPAR bw settings\n");
8415 else
8416 dev_info(&pf->pdev->dev,
8417 "Min BW = %8.8x, Max BW = %8.8x\n",
8418 pf->npar_min_bw, pf->npar_max_bw);
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008419 }
8420
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008421 /* FW/NVM is not yet fixed in this regard */
8422 if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
8423 (pf->hw.func_caps.fd_filters_best_effort > 0)) {
8424 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
8425 pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
Shannon Nelson6eae9c62015-09-03 17:18:55 -04008426 if (pf->flags & I40E_FLAG_MFP_ENABLED &&
8427 pf->hw.num_partitions > 1)
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008428 dev_info(&pf->pdev->dev,
Anjali Singhai Jain0b675842014-03-06 08:59:51 +00008429 "Flow Director Sideband mode Disabled in MFP mode\n");
Shannon Nelson6eae9c62015-09-03 17:18:55 -04008430 else
8431 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008432 pf->fdir_pf_filter_count =
8433 pf->hw.func_caps.fd_filters_guaranteed;
8434 pf->hw.fdir_shared_filter_count =
8435 pf->hw.func_caps.fd_filters_best_effort;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008436 }
8437
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008438 if (i40e_is_mac_710(&pf->hw) &&
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08008439 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008440 (pf->hw.aq.fw_maj_ver < 4))) {
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08008441 pf->flags |= I40E_FLAG_RESTART_AUTONEG;
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008442 /* No DCB support for FW < v4.33 */
8443 pf->flags |= I40E_FLAG_NO_DCB_SUPPORT;
8444 }
8445
8446 /* Disable FW LLDP if FW < v4.3 */
8447 if (i40e_is_mac_710(&pf->hw) &&
8448 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
8449 (pf->hw.aq.fw_maj_ver < 4)))
8450 pf->flags |= I40E_FLAG_STOP_FW_LLDP;
8451
8452 /* Use the FW Set LLDP MIB API if FW > v4.40 */
8453 if (i40e_is_mac_710(&pf->hw) &&
8454 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
8455 (pf->hw.aq.fw_maj_ver >= 5)))
8456 pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB;
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08008457
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008458 if (pf->hw.func_caps.vmdq) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008459 pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008460 pf->flags |= I40E_FLAG_VMDQ_ENABLED;
Jesse Brandeburge9e53662015-10-02 17:57:21 -07008461 pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008462 }
8463
Vasu Dev38e00432014-08-01 13:27:03 -07008464#ifdef I40E_FCOE
Shannon Nelson21364bc2015-08-26 15:14:13 -04008465 i40e_init_pf_fcoe(pf);
Vasu Dev38e00432014-08-01 13:27:03 -07008466
8467#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008468#ifdef CONFIG_PCI_IOV
Shannon Nelsonba252f132014-12-11 07:06:34 +00008469 if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008470 pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
8471 pf->flags |= I40E_FLAG_SRIOV_ENABLED;
8472 pf->num_req_vfs = min_t(int,
8473 pf->hw.func_caps.num_vfs,
8474 I40E_MAX_VF_COUNT);
8475 }
8476#endif /* CONFIG_PCI_IOV */
Anjali Singhai Jaind502ce02015-06-05 12:20:26 -04008477 if (pf->hw.mac.type == I40E_MAC_X722) {
8478 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE |
8479 I40E_FLAG_128_QP_RSS_CAPABLE |
8480 I40E_FLAG_HW_ATR_EVICT_CAPABLE |
8481 I40E_FLAG_OUTER_UDP_CSUM_CAPABLE |
8482 I40E_FLAG_WB_ON_ITR_CAPABLE |
Singhai, Anjali6a899022015-12-14 12:21:18 -08008483 I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE |
Catherine Sullivanf8db54cc2015-12-22 14:25:14 -08008484 I40E_FLAG_100M_SGMII_CAPABLE |
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008485 I40E_FLAG_USE_SET_LLDP_MIB |
Singhai, Anjali6a899022015-12-14 12:21:18 -08008486 I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
Anjali Singhaia340c782016-01-06 11:49:28 -08008487 } else if ((pf->hw.aq.api_maj_ver > 1) ||
8488 ((pf->hw.aq.api_maj_ver == 1) &&
8489 (pf->hw.aq.api_min_ver > 4))) {
8490 /* Supported in FW API version higher than 1.4 */
8491 pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08008492 pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
8493 } else {
8494 pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
Anjali Singhai Jaind502ce02015-06-05 12:20:26 -04008495 }
Anjali Singhaia340c782016-01-06 11:49:28 -08008496
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008497 pf->eeprom_version = 0xDEAD;
8498 pf->lan_veb = I40E_NO_VEB;
8499 pf->lan_vsi = I40E_NO_VSI;
8500
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04008501 /* By default FW has this off for performance reasons */
8502 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
8503
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008504 /* set up queue assignment tracking */
8505 size = sizeof(struct i40e_lump_tracking)
8506 + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
8507 pf->qp_pile = kzalloc(size, GFP_KERNEL);
8508 if (!pf->qp_pile) {
8509 err = -ENOMEM;
8510 goto sw_init_done;
8511 }
8512 pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
8513 pf->qp_pile->search_hint = 0;
8514
Anjali Singhai Jain327fe042014-06-04 01:23:26 +00008515 pf->tx_timeout_recovery_level = 1;
8516
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008517 mutex_init(&pf->switch_mutex);
8518
Greg Rosec668a122015-02-26 16:10:39 +00008519 /* If NPAR is enabled nudge the Tx scheduler */
8520 if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf)))
8521 i40e_set_npar_bw_setting(pf);
8522
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008523sw_init_done:
8524 return err;
8525}
8526
8527/**
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008528 * i40e_set_ntuple - set the ntuple feature flag and take action
8529 * @pf: board private structure to initialize
8530 * @features: the feature set that the stack is suggesting
8531 *
8532 * returns a bool to indicate if reset needs to happen
8533 **/
8534bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
8535{
8536 bool need_reset = false;
8537
8538 /* Check if Flow Director n-tuple support was enabled or disabled. If
8539 * the state changed, we need to reset.
8540 */
8541 if (features & NETIF_F_NTUPLE) {
8542 /* Enable filters and mark for reset */
8543 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
8544 need_reset = true;
8545 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
8546 } else {
8547 /* turn off filters, mark for reset and clear SW filter list */
8548 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
8549 need_reset = true;
8550 i40e_fdir_filter_exit(pf);
8551 }
8552 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain8a4f34f2014-06-04 08:45:20 +00008553 pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00008554 /* reset fd counters */
8555 pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0;
8556 pf->fdir_pf_active_filters = 0;
8557 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04008558 if (I40E_DEBUG_FD & pf->hw.debug_mask)
8559 dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
Anjali Singhai Jain8a4f34f2014-06-04 08:45:20 +00008560 /* if ATR was auto disabled it can be re-enabled. */
8561 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
8562 (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
8563 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008564 }
8565 return need_reset;
8566}
8567
8568/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008569 * i40e_set_features - set the netdev feature flags
8570 * @netdev: ptr to the netdev being adjusted
8571 * @features: the feature set that the stack is suggesting
8572 **/
8573static int i40e_set_features(struct net_device *netdev,
8574 netdev_features_t features)
8575{
8576 struct i40e_netdev_priv *np = netdev_priv(netdev);
8577 struct i40e_vsi *vsi = np->vsi;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008578 struct i40e_pf *pf = vsi->back;
8579 bool need_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008580
8581 if (features & NETIF_F_HW_VLAN_CTAG_RX)
8582 i40e_vlan_stripping_enable(vsi);
8583 else
8584 i40e_vlan_stripping_disable(vsi);
8585
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008586 need_reset = i40e_set_ntuple(pf, features);
8587
8588 if (need_reset)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008589 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008590
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008591 return 0;
8592}
8593
Singhai, Anjali6a899022015-12-14 12:21:18 -08008594#if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008595/**
Singhai, Anjali6a899022015-12-14 12:21:18 -08008596 * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008597 * @pf: board private structure
8598 * @port: The UDP port to look up
8599 *
8600 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
8601 **/
Singhai, Anjali6a899022015-12-14 12:21:18 -08008602static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, __be16 port)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008603{
8604 u8 i;
8605
8606 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
Singhai, Anjali6a899022015-12-14 12:21:18 -08008607 if (pf->udp_ports[i].index == port)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008608 return i;
8609 }
8610
8611 return i;
8612}
8613
Singhai, Anjali6a899022015-12-14 12:21:18 -08008614#endif
Eric Dumazet5cae7612016-01-20 19:53:02 -08008615
8616#if IS_ENABLED(CONFIG_VXLAN)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008617/**
8618 * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
8619 * @netdev: This physical port's netdev
8620 * @sa_family: Socket Family that VXLAN is notifying us about
8621 * @port: New UDP port number that VXLAN started listening to
8622 **/
8623static void i40e_add_vxlan_port(struct net_device *netdev,
8624 sa_family_t sa_family, __be16 port)
8625{
8626 struct i40e_netdev_priv *np = netdev_priv(netdev);
8627 struct i40e_vsi *vsi = np->vsi;
8628 struct i40e_pf *pf = vsi->back;
8629 u8 next_idx;
8630 u8 idx;
8631
8632 if (sa_family == AF_INET6)
8633 return;
8634
Singhai, Anjali6a899022015-12-14 12:21:18 -08008635 idx = i40e_get_udp_port_idx(pf, port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008636
8637 /* Check if port already exists */
8638 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07008639 netdev_info(netdev, "vxlan port %d already offloaded\n",
8640 ntohs(port));
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008641 return;
8642 }
8643
8644 /* Now check if there is space to add the new port */
Singhai, Anjali6a899022015-12-14 12:21:18 -08008645 next_idx = i40e_get_udp_port_idx(pf, 0);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008646
8647 if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07008648 netdev_info(netdev, "maximum number of vxlan UDP ports reached, not adding port %d\n",
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008649 ntohs(port));
8650 return;
8651 }
8652
8653 /* New port: add it and mark its index in the bitmap */
Singhai, Anjali6a899022015-12-14 12:21:18 -08008654 pf->udp_ports[next_idx].index = port;
8655 pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
8656 pf->pending_udp_bitmap |= BIT_ULL(next_idx);
8657 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008658}
8659
8660/**
8661 * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
8662 * @netdev: This physical port's netdev
8663 * @sa_family: Socket Family that VXLAN is notifying us about
8664 * @port: UDP port number that VXLAN stopped listening to
8665 **/
8666static void i40e_del_vxlan_port(struct net_device *netdev,
8667 sa_family_t sa_family, __be16 port)
8668{
8669 struct i40e_netdev_priv *np = netdev_priv(netdev);
8670 struct i40e_vsi *vsi = np->vsi;
8671 struct i40e_pf *pf = vsi->back;
8672 u8 idx;
8673
8674 if (sa_family == AF_INET6)
8675 return;
8676
Singhai, Anjali6a899022015-12-14 12:21:18 -08008677 idx = i40e_get_udp_port_idx(pf, port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008678
8679 /* Check if port already exists */
8680 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
8681 /* if port exists, set it to 0 (mark for deletion)
8682 * and make it pending
8683 */
Singhai, Anjali6a899022015-12-14 12:21:18 -08008684 pf->udp_ports[idx].index = 0;
8685 pf->pending_udp_bitmap |= BIT_ULL(idx);
8686 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008687 } else {
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07008688 netdev_warn(netdev, "vxlan port %d was not found, not deleting\n",
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008689 ntohs(port));
8690 }
8691}
Eric Dumazet5cae7612016-01-20 19:53:02 -08008692#endif
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008693
Eric Dumazet5cae7612016-01-20 19:53:02 -08008694#if IS_ENABLED(CONFIG_GENEVE)
Singhai, Anjali6a899022015-12-14 12:21:18 -08008695/**
8696 * i40e_add_geneve_port - Get notifications about GENEVE ports that come up
8697 * @netdev: This physical port's netdev
8698 * @sa_family: Socket Family that GENEVE is notifying us about
8699 * @port: New UDP port number that GENEVE started listening to
8700 **/
8701static void i40e_add_geneve_port(struct net_device *netdev,
8702 sa_family_t sa_family, __be16 port)
8703{
Singhai, Anjali6a899022015-12-14 12:21:18 -08008704 struct i40e_netdev_priv *np = netdev_priv(netdev);
8705 struct i40e_vsi *vsi = np->vsi;
8706 struct i40e_pf *pf = vsi->back;
8707 u8 next_idx;
8708 u8 idx;
8709
Anjali Singhaia340c782016-01-06 11:49:28 -08008710 if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
8711 return;
8712
Singhai, Anjali6a899022015-12-14 12:21:18 -08008713 if (sa_family == AF_INET6)
8714 return;
8715
8716 idx = i40e_get_udp_port_idx(pf, port);
8717
8718 /* Check if port already exists */
8719 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
8720 netdev_info(netdev, "udp port %d already offloaded\n",
8721 ntohs(port));
8722 return;
8723 }
8724
8725 /* Now check if there is space to add the new port */
8726 next_idx = i40e_get_udp_port_idx(pf, 0);
8727
8728 if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
8729 netdev_info(netdev, "maximum number of UDP ports reached, not adding port %d\n",
8730 ntohs(port));
8731 return;
8732 }
8733
8734 /* New port: add it and mark its index in the bitmap */
8735 pf->udp_ports[next_idx].index = port;
8736 pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
8737 pf->pending_udp_bitmap |= BIT_ULL(next_idx);
8738 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
8739
8740 dev_info(&pf->pdev->dev, "adding geneve port %d\n", ntohs(port));
Singhai, Anjali6a899022015-12-14 12:21:18 -08008741}
8742
8743/**
8744 * i40e_del_geneve_port - Get notifications about GENEVE ports that go away
8745 * @netdev: This physical port's netdev
8746 * @sa_family: Socket Family that GENEVE is notifying us about
8747 * @port: UDP port number that GENEVE stopped listening to
8748 **/
8749static void i40e_del_geneve_port(struct net_device *netdev,
8750 sa_family_t sa_family, __be16 port)
8751{
Singhai, Anjali6a899022015-12-14 12:21:18 -08008752 struct i40e_netdev_priv *np = netdev_priv(netdev);
8753 struct i40e_vsi *vsi = np->vsi;
8754 struct i40e_pf *pf = vsi->back;
8755 u8 idx;
8756
8757 if (sa_family == AF_INET6)
8758 return;
8759
Anjali Singhaia340c782016-01-06 11:49:28 -08008760 if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
8761 return;
8762
Singhai, Anjali6a899022015-12-14 12:21:18 -08008763 idx = i40e_get_udp_port_idx(pf, port);
8764
8765 /* Check if port already exists */
8766 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
8767 /* if port exists, set it to 0 (mark for deletion)
8768 * and make it pending
8769 */
8770 pf->udp_ports[idx].index = 0;
8771 pf->pending_udp_bitmap |= BIT_ULL(idx);
8772 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
8773
8774 dev_info(&pf->pdev->dev, "deleting geneve port %d\n",
8775 ntohs(port));
8776 } else {
8777 netdev_warn(netdev, "geneve port %d was not found, not deleting\n",
8778 ntohs(port));
8779 }
Singhai, Anjali6a899022015-12-14 12:21:18 -08008780}
Eric Dumazet5cae7612016-01-20 19:53:02 -08008781#endif
Singhai, Anjali6a899022015-12-14 12:21:18 -08008782
Neerav Parikh1f224ad2014-02-12 01:45:31 +00008783static int i40e_get_phys_port_id(struct net_device *netdev,
Jiri Pirko02637fc2014-11-28 14:34:16 +01008784 struct netdev_phys_item_id *ppid)
Neerav Parikh1f224ad2014-02-12 01:45:31 +00008785{
8786 struct i40e_netdev_priv *np = netdev_priv(netdev);
8787 struct i40e_pf *pf = np->vsi->back;
8788 struct i40e_hw *hw = &pf->hw;
8789
8790 if (!(pf->flags & I40E_FLAG_PORT_ID_VALID))
8791 return -EOPNOTSUPP;
8792
8793 ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
8794 memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
8795
8796 return 0;
8797}
8798
Jesse Brandeburg2f90ade2014-11-20 16:30:02 -08008799/**
8800 * i40e_ndo_fdb_add - add an entry to the hardware database
8801 * @ndm: the input from the stack
8802 * @tb: pointer to array of nladdr (unused)
8803 * @dev: the net device pointer
8804 * @addr: the MAC address entry being added
8805 * @flags: instructions from stack about fdb operation
8806 */
Greg Rose4ba0dea2014-03-06 08:59:55 +00008807static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
8808 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01008809 const unsigned char *addr, u16 vid,
Greg Rose4ba0dea2014-03-06 08:59:55 +00008810 u16 flags)
Greg Rose4ba0dea2014-03-06 08:59:55 +00008811{
8812 struct i40e_netdev_priv *np = netdev_priv(dev);
8813 struct i40e_pf *pf = np->vsi->back;
8814 int err = 0;
8815
8816 if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
8817 return -EOPNOTSUPP;
8818
Or Gerlitz65891fe2014-12-14 18:19:05 +02008819 if (vid) {
8820 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
8821 return -EINVAL;
8822 }
8823
Greg Rose4ba0dea2014-03-06 08:59:55 +00008824 /* Hardware does not support aging addresses so if a
8825 * ndm_state is given only allow permanent addresses
8826 */
8827 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
8828 netdev_info(dev, "FDB only supports static addresses\n");
8829 return -EINVAL;
8830 }
8831
8832 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
8833 err = dev_uc_add_excl(dev, addr);
8834 else if (is_multicast_ether_addr(addr))
8835 err = dev_mc_add_excl(dev, addr);
8836 else
8837 err = -EINVAL;
8838
8839 /* Only return duplicate errors if NLM_F_EXCL is set */
8840 if (err == -EEXIST && !(flags & NLM_F_EXCL))
8841 err = 0;
8842
8843 return err;
8844}
8845
Neerav Parikh51616012015-02-06 08:52:14 +00008846/**
8847 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
8848 * @dev: the netdev being configured
8849 * @nlh: RTNL message
8850 *
8851 * Inserts a new hardware bridge if not already created and
8852 * enables the bridging mode requested (VEB or VEPA). If the
8853 * hardware bridge has already been inserted and the request
8854 * is to change the mode then that requires a PF reset to
8855 * allow rebuild of the components with required hardware
8856 * bridge mode enabled.
8857 **/
8858static int i40e_ndo_bridge_setlink(struct net_device *dev,
Carolyn Wyborny9df70b62015-04-27 14:57:11 -04008859 struct nlmsghdr *nlh,
8860 u16 flags)
Neerav Parikh51616012015-02-06 08:52:14 +00008861{
8862 struct i40e_netdev_priv *np = netdev_priv(dev);
8863 struct i40e_vsi *vsi = np->vsi;
8864 struct i40e_pf *pf = vsi->back;
8865 struct i40e_veb *veb = NULL;
8866 struct nlattr *attr, *br_spec;
8867 int i, rem;
8868
8869 /* Only for PF VSI for now */
8870 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
8871 return -EOPNOTSUPP;
8872
8873 /* Find the HW bridge for PF VSI */
8874 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
8875 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
8876 veb = pf->veb[i];
8877 }
8878
8879 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
8880
8881 nla_for_each_nested(attr, br_spec, rem) {
8882 __u16 mode;
8883
8884 if (nla_type(attr) != IFLA_BRIDGE_MODE)
8885 continue;
8886
8887 mode = nla_get_u16(attr);
8888 if ((mode != BRIDGE_MODE_VEPA) &&
8889 (mode != BRIDGE_MODE_VEB))
8890 return -EINVAL;
8891
8892 /* Insert a new HW bridge */
8893 if (!veb) {
8894 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
8895 vsi->tc_config.enabled_tc);
8896 if (veb) {
8897 veb->bridge_mode = mode;
8898 i40e_config_bridge_mode(veb);
8899 } else {
8900 /* No Bridge HW offload available */
8901 return -ENOENT;
8902 }
8903 break;
8904 } else if (mode != veb->bridge_mode) {
8905 /* Existing HW bridge but different mode needs reset */
8906 veb->bridge_mode = mode;
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07008907 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
8908 if (mode == BRIDGE_MODE_VEB)
8909 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
8910 else
8911 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
8912 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Neerav Parikh51616012015-02-06 08:52:14 +00008913 break;
8914 }
8915 }
8916
8917 return 0;
8918}
8919
8920/**
8921 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
8922 * @skb: skb buff
8923 * @pid: process id
8924 * @seq: RTNL message seq #
8925 * @dev: the netdev being configured
8926 * @filter_mask: unused
Jesse Brandeburgd4b2f9f2015-09-03 17:18:48 -04008927 * @nlflags: netlink flags passed in
Neerav Parikh51616012015-02-06 08:52:14 +00008928 *
8929 * Return the mode in which the hardware bridge is operating in
8930 * i.e VEB or VEPA.
8931 **/
Neerav Parikh51616012015-02-06 08:52:14 +00008932static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8933 struct net_device *dev,
Carolyn Wyborny9f4ffc42015-08-31 19:54:42 -04008934 u32 __always_unused filter_mask,
8935 int nlflags)
Neerav Parikh51616012015-02-06 08:52:14 +00008936{
8937 struct i40e_netdev_priv *np = netdev_priv(dev);
8938 struct i40e_vsi *vsi = np->vsi;
8939 struct i40e_pf *pf = vsi->back;
8940 struct i40e_veb *veb = NULL;
8941 int i;
8942
8943 /* Only for PF VSI for now */
8944 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
8945 return -EOPNOTSUPP;
8946
8947 /* Find the HW bridge for the PF VSI */
8948 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
8949 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
8950 veb = pf->veb[i];
8951 }
8952
8953 if (!veb)
8954 return 0;
8955
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02008956 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07008957 nlflags, 0, 0, filter_mask, NULL);
Neerav Parikh51616012015-02-06 08:52:14 +00008958}
Neerav Parikh51616012015-02-06 08:52:14 +00008959
Singhai, Anjali6a899022015-12-14 12:21:18 -08008960/* Hardware supports L4 tunnel length of 128B (=2^7) which includes
8961 * inner mac plus all inner ethertypes.
8962 */
8963#define I40E_MAX_TUNNEL_HDR_LEN 128
Joe Stringerf44a75e2015-04-14 17:09:14 -07008964/**
8965 * i40e_features_check - Validate encapsulated packet conforms to limits
8966 * @skb: skb buff
Jean Sacren2bc11c62015-09-19 05:08:43 -06008967 * @dev: This physical port's netdev
Joe Stringerf44a75e2015-04-14 17:09:14 -07008968 * @features: Offload features that the stack believes apply
8969 **/
8970static netdev_features_t i40e_features_check(struct sk_buff *skb,
8971 struct net_device *dev,
8972 netdev_features_t features)
8973{
8974 if (skb->encapsulation &&
Singhai, Anjali6a899022015-12-14 12:21:18 -08008975 ((skb_inner_network_header(skb) - skb_transport_header(skb)) >
Joe Stringerf44a75e2015-04-14 17:09:14 -07008976 I40E_MAX_TUNNEL_HDR_LEN))
Tom Herberta1882222015-12-14 11:19:43 -08008977 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
Joe Stringerf44a75e2015-04-14 17:09:14 -07008978
8979 return features;
8980}
8981
Shannon Nelson37a29732015-02-27 09:15:19 +00008982static const struct net_device_ops i40e_netdev_ops = {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008983 .ndo_open = i40e_open,
8984 .ndo_stop = i40e_close,
8985 .ndo_start_xmit = i40e_lan_xmit_frame,
8986 .ndo_get_stats64 = i40e_get_netdev_stats_struct,
8987 .ndo_set_rx_mode = i40e_set_rx_mode,
8988 .ndo_validate_addr = eth_validate_addr,
8989 .ndo_set_mac_address = i40e_set_mac,
8990 .ndo_change_mtu = i40e_change_mtu,
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00008991 .ndo_do_ioctl = i40e_ioctl,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008992 .ndo_tx_timeout = i40e_tx_timeout,
8993 .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
8994 .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
8995#ifdef CONFIG_NET_POLL_CONTROLLER
8996 .ndo_poll_controller = i40e_netpoll,
8997#endif
John Fastabende4c67342016-02-16 21:16:15 -08008998 .ndo_setup_tc = __i40e_setup_tc,
Vasu Dev38e00432014-08-01 13:27:03 -07008999#ifdef I40E_FCOE
9000 .ndo_fcoe_enable = i40e_fcoe_enable,
9001 .ndo_fcoe_disable = i40e_fcoe_disable,
9002#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009003 .ndo_set_features = i40e_set_features,
9004 .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
9005 .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04009006 .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009007 .ndo_get_vf_config = i40e_ndo_get_vf_config,
Mitch Williams588aefa2014-02-11 08:27:49 +00009008 .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
Serey Konge6d90042014-07-12 07:28:14 +00009009 .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
Singhai, Anjali6a899022015-12-14 12:21:18 -08009010#if IS_ENABLED(CONFIG_VXLAN)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00009011 .ndo_add_vxlan_port = i40e_add_vxlan_port,
9012 .ndo_del_vxlan_port = i40e_del_vxlan_port,
9013#endif
Singhai, Anjali6a899022015-12-14 12:21:18 -08009014#if IS_ENABLED(CONFIG_GENEVE)
9015 .ndo_add_geneve_port = i40e_add_geneve_port,
9016 .ndo_del_geneve_port = i40e_del_geneve_port,
9017#endif
Neerav Parikh1f224ad2014-02-12 01:45:31 +00009018 .ndo_get_phys_port_id = i40e_get_phys_port_id,
Greg Rose4ba0dea2014-03-06 08:59:55 +00009019 .ndo_fdb_add = i40e_ndo_fdb_add,
Joe Stringerf44a75e2015-04-14 17:09:14 -07009020 .ndo_features_check = i40e_features_check,
Neerav Parikh51616012015-02-06 08:52:14 +00009021 .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
9022 .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009023};
9024
9025/**
9026 * i40e_config_netdev - Setup the netdev flags
9027 * @vsi: the VSI being configured
9028 *
9029 * Returns 0 on success, negative value on failure
9030 **/
9031static int i40e_config_netdev(struct i40e_vsi *vsi)
9032{
Greg Rose1a103702013-11-28 06:42:39 +00009033 u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009034 struct i40e_pf *pf = vsi->back;
9035 struct i40e_hw *hw = &pf->hw;
9036 struct i40e_netdev_priv *np;
9037 struct net_device *netdev;
9038 u8 mac_addr[ETH_ALEN];
9039 int etherdev_size;
9040
9041 etherdev_size = sizeof(struct i40e_netdev_priv);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00009042 netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009043 if (!netdev)
9044 return -ENOMEM;
9045
9046 vsi->netdev = netdev;
9047 np = netdev_priv(netdev);
9048 np->vsi = vsi;
9049
Jesse Brandeburg5afdaaa2015-12-10 11:38:50 -08009050 netdev->hw_enc_features |= NETIF_F_IP_CSUM |
9051 NETIF_F_GSO_UDP_TUNNEL |
9052 NETIF_F_GSO_GRE |
9053 NETIF_F_TSO |
9054 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009055
9056 netdev->features = NETIF_F_SG |
9057 NETIF_F_IP_CSUM |
Tom Herbert53692b12015-12-14 11:19:41 -08009058 NETIF_F_SCTP_CRC |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009059 NETIF_F_HIGHDMA |
9060 NETIF_F_GSO_UDP_TUNNEL |
Jesse Brandeburgfec31ff2015-10-01 18:25:42 -07009061 NETIF_F_GSO_GRE |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009062 NETIF_F_HW_VLAN_CTAG_TX |
9063 NETIF_F_HW_VLAN_CTAG_RX |
9064 NETIF_F_HW_VLAN_CTAG_FILTER |
9065 NETIF_F_IPV6_CSUM |
9066 NETIF_F_TSO |
Jesse Brandeburg059dab62014-04-01 09:07:20 +00009067 NETIF_F_TSO_ECN |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009068 NETIF_F_TSO6 |
9069 NETIF_F_RXCSUM |
9070 NETIF_F_RXHASH |
9071 0;
9072
Anjali Singhai Jain2e86a0b2014-04-01 07:11:53 +00009073 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
9074 netdev->features |= NETIF_F_NTUPLE;
9075
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009076 /* copy netdev features into list of user selectable features */
9077 netdev->hw_features |= netdev->features;
9078
9079 if (vsi->type == I40E_VSI_MAIN) {
9080 SET_NETDEV_DEV(netdev, &pf->pdev->dev);
Greg Rose9a173902014-05-22 06:32:02 +00009081 ether_addr_copy(mac_addr, hw->mac.perm_addr);
Shannon Nelson30650cc2014-07-29 04:01:50 +00009082 /* The following steps are necessary to prevent reception
9083 * of tagged packets - some older NVM configurations load a
9084 * default a MAC-VLAN filter that accepts any tagged packet
9085 * which must be replaced by a normal filter.
Greg Rose8c27d422014-05-22 06:31:56 +00009086 */
Kiran Patil21659032015-09-30 14:09:03 -04009087 if (!i40e_rm_default_mac_filter(vsi, mac_addr)) {
9088 spin_lock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson30650cc2014-07-29 04:01:50 +00009089 i40e_add_filter(vsi, mac_addr,
9090 I40E_VLAN_ANY, false, true);
Kiran Patil21659032015-09-30 14:09:03 -04009091 spin_unlock_bh(&vsi->mac_filter_list_lock);
9092 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009093 } else {
9094 /* relate the VSI_VMDQ name to the VSI_MAIN name */
9095 snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
9096 pf->vsi[pf->lan_vsi]->netdev->name);
9097 random_ether_addr(mac_addr);
Kiran Patil21659032015-09-30 14:09:03 -04009098
9099 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009100 i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false);
Kiran Patil21659032015-09-30 14:09:03 -04009101 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009102 }
Kiran Patil21659032015-09-30 14:09:03 -04009103
9104 spin_lock_bh(&vsi->mac_filter_list_lock);
Greg Rose1a103702013-11-28 06:42:39 +00009105 i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false);
Kiran Patil21659032015-09-30 14:09:03 -04009106 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009107
Greg Rose9a173902014-05-22 06:32:02 +00009108 ether_addr_copy(netdev->dev_addr, mac_addr);
9109 ether_addr_copy(netdev->perm_addr, mac_addr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009110 /* vlan gets same features (except vlan offload)
9111 * after any tweaks for specific VSI types
9112 */
9113 netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX |
9114 NETIF_F_HW_VLAN_CTAG_RX |
9115 NETIF_F_HW_VLAN_CTAG_FILTER);
9116 netdev->priv_flags |= IFF_UNICAST_FLT;
9117 netdev->priv_flags |= IFF_SUPP_NOFCS;
9118 /* Setup netdev TC information */
9119 i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
9120
9121 netdev->netdev_ops = &i40e_netdev_ops;
9122 netdev->watchdog_timeo = 5 * HZ;
9123 i40e_set_ethtool_ops(netdev);
Vasu Dev38e00432014-08-01 13:27:03 -07009124#ifdef I40E_FCOE
9125 i40e_fcoe_config_netdev(netdev, vsi);
9126#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009127
9128 return 0;
9129}
9130
9131/**
9132 * i40e_vsi_delete - Delete a VSI from the switch
9133 * @vsi: the VSI being removed
9134 *
9135 * Returns 0 on success, negative value on failure
9136 **/
9137static void i40e_vsi_delete(struct i40e_vsi *vsi)
9138{
9139 /* remove default VSI is not allowed */
9140 if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
9141 return;
9142
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009143 i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009144}
9145
9146/**
Neerav Parikh51616012015-02-06 08:52:14 +00009147 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
9148 * @vsi: the VSI being queried
9149 *
9150 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
9151 **/
9152int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
9153{
9154 struct i40e_veb *veb;
9155 struct i40e_pf *pf = vsi->back;
9156
9157 /* Uplink is not a bridge so default to VEB */
9158 if (vsi->veb_idx == I40E_NO_VEB)
9159 return 1;
9160
9161 veb = pf->veb[vsi->veb_idx];
Akeem G Abodunrin09603ea2015-10-01 14:37:36 -04009162 if (!veb) {
9163 dev_info(&pf->pdev->dev,
9164 "There is no veb associated with the bridge\n");
9165 return -ENOENT;
9166 }
Neerav Parikh51616012015-02-06 08:52:14 +00009167
Akeem G Abodunrin09603ea2015-10-01 14:37:36 -04009168 /* Uplink is a bridge in VEPA mode */
9169 if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
9170 return 0;
9171 } else {
9172 /* Uplink is a bridge in VEB mode */
9173 return 1;
9174 }
9175
9176 /* VEPA is now default bridge, so return 0 */
9177 return 0;
Neerav Parikh51616012015-02-06 08:52:14 +00009178}
9179
9180/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009181 * i40e_add_vsi - Add a VSI to the switch
9182 * @vsi: the VSI being configured
9183 *
9184 * This initializes a VSI context depending on the VSI type to be added and
9185 * passes it down to the add_vsi aq command.
9186 **/
9187static int i40e_add_vsi(struct i40e_vsi *vsi)
9188{
9189 int ret = -ENODEV;
Kiran Patil21659032015-09-30 14:09:03 -04009190 u8 laa_macaddr[ETH_ALEN];
9191 bool found_laa_mac_filter = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009192 struct i40e_pf *pf = vsi->back;
9193 struct i40e_hw *hw = &pf->hw;
9194 struct i40e_vsi_context ctxt;
Kiran Patil21659032015-09-30 14:09:03 -04009195 struct i40e_mac_filter *f, *ftmp;
9196
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009197 u8 enabled_tc = 0x1; /* TC0 enabled */
9198 int f_count = 0;
9199
9200 memset(&ctxt, 0, sizeof(ctxt));
9201 switch (vsi->type) {
9202 case I40E_VSI_MAIN:
9203 /* The PF's main VSI is already setup as part of the
9204 * device initialization, so we'll not bother with
9205 * the add_vsi call, but we will retrieve the current
9206 * VSI context.
9207 */
9208 ctxt.seid = pf->main_vsi_seid;
9209 ctxt.pf_num = pf->hw.pf_id;
9210 ctxt.vf_num = 0;
9211 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
9212 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
9213 if (ret) {
9214 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009215 "couldn't get PF vsi config, err %s aq_err %s\n",
9216 i40e_stat_str(&pf->hw, ret),
9217 i40e_aq_str(&pf->hw,
9218 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009219 return -ENOENT;
9220 }
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07009221 vsi->info = ctxt.info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009222 vsi->info.valid_sections = 0;
9223
9224 vsi->seid = ctxt.seid;
9225 vsi->id = ctxt.vsi_number;
9226
9227 enabled_tc = i40e_pf_get_tc_map(pf);
9228
9229 /* MFP mode setup queue map and update VSI */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00009230 if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
9231 !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009232 memset(&ctxt, 0, sizeof(ctxt));
9233 ctxt.seid = pf->main_vsi_seid;
9234 ctxt.pf_num = pf->hw.pf_id;
9235 ctxt.vf_num = 0;
9236 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
9237 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
9238 if (ret) {
9239 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009240 "update vsi failed, err %s aq_err %s\n",
9241 i40e_stat_str(&pf->hw, ret),
9242 i40e_aq_str(&pf->hw,
9243 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009244 ret = -ENOENT;
9245 goto err;
9246 }
9247 /* update the local VSI info queue map */
9248 i40e_vsi_update_queue_map(vsi, &ctxt);
9249 vsi->info.valid_sections = 0;
9250 } else {
9251 /* Default/Main VSI is only enabled for TC0
9252 * reconfigure it to enable all TCs that are
9253 * available on the port in SFP mode.
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00009254 * For MFP case the iSCSI PF would use this
9255 * flow to enable LAN+iSCSI TC.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009256 */
9257 ret = i40e_vsi_config_tc(vsi, enabled_tc);
9258 if (ret) {
9259 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009260 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
9261 enabled_tc,
9262 i40e_stat_str(&pf->hw, ret),
9263 i40e_aq_str(&pf->hw,
9264 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009265 ret = -ENOENT;
9266 }
9267 }
9268 break;
9269
9270 case I40E_VSI_FDIR:
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009271 ctxt.pf_num = hw->pf_id;
9272 ctxt.vf_num = 0;
9273 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009274 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009275 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009276 if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
9277 (i40e_is_vsi_uplink_mode_veb(vsi))) {
Neerav Parikh51616012015-02-06 08:52:14 +00009278 ctxt.info.valid_sections |=
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009279 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
Neerav Parikh51616012015-02-06 08:52:14 +00009280 ctxt.info.switch_id =
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009281 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
Neerav Parikh51616012015-02-06 08:52:14 +00009282 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009283 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009284 break;
9285
9286 case I40E_VSI_VMDQ2:
9287 ctxt.pf_num = hw->pf_id;
9288 ctxt.vf_num = 0;
9289 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009290 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009291 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
9292
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009293 /* This VSI is connected to VEB so the switch_id
9294 * should be set to zero by default.
9295 */
Neerav Parikh51616012015-02-06 08:52:14 +00009296 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
9297 ctxt.info.valid_sections |=
9298 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9299 ctxt.info.switch_id =
9300 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9301 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009302
9303 /* Setup the VSI tx/rx queue map for TC0 only for now */
9304 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9305 break;
9306
9307 case I40E_VSI_SRIOV:
9308 ctxt.pf_num = hw->pf_id;
9309 ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
9310 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009311 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009312 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
9313
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009314 /* This VSI is connected to VEB so the switch_id
9315 * should be set to zero by default.
9316 */
Neerav Parikh51616012015-02-06 08:52:14 +00009317 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
9318 ctxt.info.valid_sections |=
9319 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9320 ctxt.info.switch_id =
9321 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9322 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009323
9324 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
9325 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
Mitch Williamsc674d122014-05-20 08:01:40 +00009326 if (pf->vf[vsi->vf_id].spoofchk) {
9327 ctxt.info.valid_sections |=
9328 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
9329 ctxt.info.sec_flags |=
9330 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
9331 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
9332 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009333 /* Setup the VSI tx/rx queue map for TC0 only for now */
9334 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9335 break;
9336
Vasu Dev38e00432014-08-01 13:27:03 -07009337#ifdef I40E_FCOE
9338 case I40E_VSI_FCOE:
9339 ret = i40e_fcoe_vsi_init(vsi, &ctxt);
9340 if (ret) {
9341 dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n");
9342 return ret;
9343 }
9344 break;
9345
9346#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009347 default:
9348 return -ENODEV;
9349 }
9350
9351 if (vsi->type != I40E_VSI_MAIN) {
9352 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
9353 if (ret) {
9354 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009355 "add vsi failed, err %s aq_err %s\n",
9356 i40e_stat_str(&pf->hw, ret),
9357 i40e_aq_str(&pf->hw,
9358 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009359 ret = -ENOENT;
9360 goto err;
9361 }
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07009362 vsi->info = ctxt.info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009363 vsi->info.valid_sections = 0;
9364 vsi->seid = ctxt.seid;
9365 vsi->id = ctxt.vsi_number;
9366 }
9367
Kiran Patil21659032015-09-30 14:09:03 -04009368 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009369 /* If macvlan filters already exist, force them to get loaded */
9370 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
9371 f->changed = true;
9372 f_count++;
Shannon Nelson6252c7e2014-06-04 01:23:23 +00009373
Kiran Patil21659032015-09-30 14:09:03 -04009374 /* Expected to have only one MAC filter entry for LAA in list */
Shannon Nelson6252c7e2014-06-04 01:23:23 +00009375 if (f->is_laa && vsi->type == I40E_VSI_MAIN) {
Kiran Patil21659032015-09-30 14:09:03 -04009376 ether_addr_copy(laa_macaddr, f->macaddr);
9377 found_laa_mac_filter = true;
Shannon Nelson6252c7e2014-06-04 01:23:23 +00009378 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009379 }
Kiran Patil21659032015-09-30 14:09:03 -04009380 spin_unlock_bh(&vsi->mac_filter_list_lock);
9381
9382 if (found_laa_mac_filter) {
9383 struct i40e_aqc_remove_macvlan_element_data element;
9384
9385 memset(&element, 0, sizeof(element));
9386 ether_addr_copy(element.mac_addr, laa_macaddr);
9387 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
9388 ret = i40e_aq_remove_macvlan(hw, vsi->seid,
9389 &element, 1, NULL);
9390 if (ret) {
9391 /* some older FW has a different default */
9392 element.flags |=
9393 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
9394 i40e_aq_remove_macvlan(hw, vsi->seid,
9395 &element, 1, NULL);
9396 }
9397
9398 i40e_aq_mac_address_write(hw,
9399 I40E_AQC_WRITE_TYPE_LAA_WOL,
9400 laa_macaddr, NULL);
9401 }
9402
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009403 if (f_count) {
9404 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
9405 pf->flags |= I40E_FLAG_FILTER_SYNC;
9406 }
9407
9408 /* Update VSI BW information */
9409 ret = i40e_vsi_get_bw_info(vsi);
9410 if (ret) {
9411 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009412 "couldn't get vsi bw info, err %s aq_err %s\n",
9413 i40e_stat_str(&pf->hw, ret),
9414 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009415 /* VSI is already added so not tearing that up */
9416 ret = 0;
9417 }
9418
9419err:
9420 return ret;
9421}
9422
9423/**
9424 * i40e_vsi_release - Delete a VSI and free its resources
9425 * @vsi: the VSI being removed
9426 *
9427 * Returns 0 on success or < 0 on error
9428 **/
9429int i40e_vsi_release(struct i40e_vsi *vsi)
9430{
9431 struct i40e_mac_filter *f, *ftmp;
9432 struct i40e_veb *veb = NULL;
9433 struct i40e_pf *pf;
9434 u16 uplink_seid;
9435 int i, n;
9436
9437 pf = vsi->back;
9438
9439 /* release of a VEB-owner or last VSI is not allowed */
9440 if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
9441 dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
9442 vsi->seid, vsi->uplink_seid);
9443 return -ENODEV;
9444 }
9445 if (vsi == pf->vsi[pf->lan_vsi] &&
9446 !test_bit(__I40E_DOWN, &pf->state)) {
9447 dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
9448 return -ENODEV;
9449 }
9450
9451 uplink_seid = vsi->uplink_seid;
9452 if (vsi->type != I40E_VSI_SRIOV) {
9453 if (vsi->netdev_registered) {
9454 vsi->netdev_registered = false;
9455 if (vsi->netdev) {
9456 /* results in a call to i40e_close() */
9457 unregister_netdev(vsi->netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009458 }
9459 } else {
Shannon Nelson90ef8d42014-03-14 07:32:26 +00009460 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009461 }
9462 i40e_vsi_disable_irq(vsi);
9463 }
9464
Kiran Patil21659032015-09-30 14:09:03 -04009465 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009466 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
9467 i40e_del_filter(vsi, f->macaddr, f->vlan,
9468 f->is_vf, f->is_netdev);
Kiran Patil21659032015-09-30 14:09:03 -04009469 spin_unlock_bh(&vsi->mac_filter_list_lock);
9470
Jesse Brandeburg17652c62015-11-05 17:01:02 -08009471 i40e_sync_vsi_filters(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009472
9473 i40e_vsi_delete(vsi);
9474 i40e_vsi_free_q_vectors(vsi);
Shannon Nelsona4866592014-02-11 08:24:07 +00009475 if (vsi->netdev) {
9476 free_netdev(vsi->netdev);
9477 vsi->netdev = NULL;
9478 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009479 i40e_vsi_clear_rings(vsi);
9480 i40e_vsi_clear(vsi);
9481
9482 /* If this was the last thing on the VEB, except for the
9483 * controlling VSI, remove the VEB, which puts the controlling
9484 * VSI onto the next level down in the switch.
9485 *
9486 * Well, okay, there's one more exception here: don't remove
9487 * the orphan VEBs yet. We'll wait for an explicit remove request
9488 * from up the network stack.
9489 */
Mitch Williams505682c2014-05-20 08:01:37 +00009490 for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009491 if (pf->vsi[i] &&
9492 pf->vsi[i]->uplink_seid == uplink_seid &&
9493 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
9494 n++; /* count the VSIs */
9495 }
9496 }
9497 for (i = 0; i < I40E_MAX_VEB; i++) {
9498 if (!pf->veb[i])
9499 continue;
9500 if (pf->veb[i]->uplink_seid == uplink_seid)
9501 n++; /* count the VEBs */
9502 if (pf->veb[i]->seid == uplink_seid)
9503 veb = pf->veb[i];
9504 }
9505 if (n == 0 && veb && veb->uplink_seid != 0)
9506 i40e_veb_release(veb);
9507
9508 return 0;
9509}
9510
9511/**
9512 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
9513 * @vsi: ptr to the VSI
9514 *
9515 * This should only be called after i40e_vsi_mem_alloc() which allocates the
9516 * corresponding SW VSI structure and initializes num_queue_pairs for the
9517 * newly allocated VSI.
9518 *
9519 * Returns 0 on success or negative on failure
9520 **/
9521static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
9522{
9523 int ret = -ENOENT;
9524 struct i40e_pf *pf = vsi->back;
9525
Alexander Duyck493fb302013-09-28 07:01:44 +00009526 if (vsi->q_vectors[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009527 dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
9528 vsi->seid);
9529 return -EEXIST;
9530 }
9531
9532 if (vsi->base_vector) {
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00009533 dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009534 vsi->seid, vsi->base_vector);
9535 return -EEXIST;
9536 }
9537
Greg Rose90e04072014-03-06 08:59:57 +00009538 ret = i40e_vsi_alloc_q_vectors(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009539 if (ret) {
9540 dev_info(&pf->pdev->dev,
9541 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
9542 vsi->num_q_vectors, vsi->seid, ret);
9543 vsi->num_q_vectors = 0;
9544 goto vector_setup_out;
9545 }
9546
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04009547 /* In Legacy mode, we do not have to get any other vector since we
9548 * piggyback on the misc/ICR0 for queue interrupts.
9549 */
9550 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
9551 return ret;
Shannon Nelson958a3e32013-09-28 07:13:28 +00009552 if (vsi->num_q_vectors)
9553 vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
9554 vsi->num_q_vectors, vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009555 if (vsi->base_vector < 0) {
9556 dev_info(&pf->pdev->dev,
Shannon Nelson049a2be2014-10-17 03:14:50 +00009557 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
9558 vsi->num_q_vectors, vsi->seid, vsi->base_vector);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009559 i40e_vsi_free_q_vectors(vsi);
9560 ret = -ENOENT;
9561 goto vector_setup_out;
9562 }
9563
9564vector_setup_out:
9565 return ret;
9566}
9567
9568/**
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009569 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
9570 * @vsi: pointer to the vsi.
9571 *
9572 * This re-allocates a vsi's queue resources.
9573 *
9574 * Returns pointer to the successfully allocated and configured VSI sw struct
9575 * on success, otherwise returns NULL on failure.
9576 **/
9577static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
9578{
9579 struct i40e_pf *pf = vsi->back;
9580 u8 enabled_tc;
9581 int ret;
9582
9583 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
9584 i40e_vsi_clear_rings(vsi);
9585
9586 i40e_vsi_free_arrays(vsi, false);
9587 i40e_set_num_rings_in_vsi(vsi);
9588 ret = i40e_vsi_alloc_arrays(vsi, false);
9589 if (ret)
9590 goto err_vsi;
9591
9592 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
9593 if (ret < 0) {
Shannon Nelson049a2be2014-10-17 03:14:50 +00009594 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009595 "failed to get tracking for %d queues for VSI %d err %d\n",
Shannon Nelson049a2be2014-10-17 03:14:50 +00009596 vsi->alloc_queue_pairs, vsi->seid, ret);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009597 goto err_vsi;
9598 }
9599 vsi->base_queue = ret;
9600
9601 /* Update the FW view of the VSI. Force a reset of TC and queue
9602 * layout configurations.
9603 */
9604 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
9605 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
9606 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
9607 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
9608
9609 /* assign it some queues */
9610 ret = i40e_alloc_rings(vsi);
9611 if (ret)
9612 goto err_rings;
9613
9614 /* map all of the rings to the q_vectors */
9615 i40e_vsi_map_rings_to_vectors(vsi);
9616 return vsi;
9617
9618err_rings:
9619 i40e_vsi_free_q_vectors(vsi);
9620 if (vsi->netdev_registered) {
9621 vsi->netdev_registered = false;
9622 unregister_netdev(vsi->netdev);
9623 free_netdev(vsi->netdev);
9624 vsi->netdev = NULL;
9625 }
9626 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
9627err_vsi:
9628 i40e_vsi_clear(vsi);
9629 return NULL;
9630}
9631
9632/**
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -05009633 * i40e_macaddr_init - explicitly write the mac address filters.
9634 *
9635 * @vsi: pointer to the vsi.
9636 * @macaddr: the MAC address
9637 *
9638 * This is needed when the macaddr has been obtained by other
9639 * means than the default, e.g., from Open Firmware or IDPROM.
9640 * Returns 0 on success, negative on failure
9641 **/
9642static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr)
9643{
9644 int ret;
9645 struct i40e_aqc_add_macvlan_element_data element;
9646
9647 ret = i40e_aq_mac_address_write(&vsi->back->hw,
9648 I40E_AQC_WRITE_TYPE_LAA_WOL,
9649 macaddr, NULL);
9650 if (ret) {
9651 dev_info(&vsi->back->pdev->dev,
9652 "Addr change for VSI failed: %d\n", ret);
9653 return -EADDRNOTAVAIL;
9654 }
9655
9656 memset(&element, 0, sizeof(element));
9657 ether_addr_copy(element.mac_addr, macaddr);
9658 element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
9659 ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL);
9660 if (ret) {
9661 dev_info(&vsi->back->pdev->dev,
9662 "add filter failed err %s aq_err %s\n",
9663 i40e_stat_str(&vsi->back->hw, ret),
9664 i40e_aq_str(&vsi->back->hw,
9665 vsi->back->hw.aq.asq_last_status));
9666 }
9667 return ret;
9668}
9669
9670/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009671 * i40e_vsi_setup - Set up a VSI by a given type
9672 * @pf: board private structure
9673 * @type: VSI type
9674 * @uplink_seid: the switch element to link to
9675 * @param1: usage depends upon VSI type. For VF types, indicates VF id
9676 *
9677 * This allocates the sw VSI structure and its queue resources, then add a VSI
9678 * to the identified VEB.
9679 *
9680 * Returns pointer to the successfully allocated and configure VSI sw struct on
9681 * success, otherwise returns NULL on failure.
9682 **/
9683struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
9684 u16 uplink_seid, u32 param1)
9685{
9686 struct i40e_vsi *vsi = NULL;
9687 struct i40e_veb *veb = NULL;
9688 int ret, i;
9689 int v_idx;
9690
9691 /* The requested uplink_seid must be either
9692 * - the PF's port seid
9693 * no VEB is needed because this is the PF
9694 * or this is a Flow Director special case VSI
9695 * - seid of an existing VEB
9696 * - seid of a VSI that owns an existing VEB
9697 * - seid of a VSI that doesn't own a VEB
9698 * a new VEB is created and the VSI becomes the owner
9699 * - seid of the PF VSI, which is what creates the first VEB
9700 * this is a special case of the previous
9701 *
9702 * Find which uplink_seid we were given and create a new VEB if needed
9703 */
9704 for (i = 0; i < I40E_MAX_VEB; i++) {
9705 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
9706 veb = pf->veb[i];
9707 break;
9708 }
9709 }
9710
9711 if (!veb && uplink_seid != pf->mac_seid) {
9712
Mitch Williams505682c2014-05-20 08:01:37 +00009713 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009714 if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
9715 vsi = pf->vsi[i];
9716 break;
9717 }
9718 }
9719 if (!vsi) {
9720 dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
9721 uplink_seid);
9722 return NULL;
9723 }
9724
9725 if (vsi->uplink_seid == pf->mac_seid)
9726 veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
9727 vsi->tc_config.enabled_tc);
9728 else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
9729 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
9730 vsi->tc_config.enabled_tc);
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009731 if (veb) {
9732 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
9733 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04009734 "New VSI creation error, uplink seid of LAN VSI expected.\n");
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009735 return NULL;
9736 }
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -04009737 /* We come up by default in VEPA mode if SRIOV is not
9738 * already enabled, in which case we can't force VEPA
9739 * mode.
9740 */
9741 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
9742 veb->bridge_mode = BRIDGE_MODE_VEPA;
9743 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
9744 }
Neerav Parikh51616012015-02-06 08:52:14 +00009745 i40e_config_bridge_mode(veb);
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009746 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009747 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
9748 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
9749 veb = pf->veb[i];
9750 }
9751 if (!veb) {
9752 dev_info(&pf->pdev->dev, "couldn't add VEB\n");
9753 return NULL;
9754 }
9755
9756 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
9757 uplink_seid = veb->seid;
9758 }
9759
9760 /* get vsi sw struct */
9761 v_idx = i40e_vsi_mem_alloc(pf, type);
9762 if (v_idx < 0)
9763 goto err_alloc;
9764 vsi = pf->vsi[v_idx];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009765 if (!vsi)
9766 goto err_alloc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009767 vsi->type = type;
9768 vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
9769
9770 if (type == I40E_VSI_MAIN)
9771 pf->lan_vsi = v_idx;
9772 else if (type == I40E_VSI_SRIOV)
9773 vsi->vf_id = param1;
9774 /* assign it some queues */
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009775 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
9776 vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009777 if (ret < 0) {
Shannon Nelson049a2be2014-10-17 03:14:50 +00009778 dev_info(&pf->pdev->dev,
9779 "failed to get tracking for %d queues for VSI %d err=%d\n",
9780 vsi->alloc_queue_pairs, vsi->seid, ret);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009781 goto err_vsi;
9782 }
9783 vsi->base_queue = ret;
9784
9785 /* get a VSI from the hardware */
9786 vsi->uplink_seid = uplink_seid;
9787 ret = i40e_add_vsi(vsi);
9788 if (ret)
9789 goto err_vsi;
9790
9791 switch (vsi->type) {
9792 /* setup the netdev if needed */
9793 case I40E_VSI_MAIN:
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -05009794 /* Apply relevant filters if a platform-specific mac
9795 * address was selected.
9796 */
9797 if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
9798 ret = i40e_macaddr_init(vsi, pf->hw.mac.addr);
9799 if (ret) {
9800 dev_warn(&pf->pdev->dev,
9801 "could not set up macaddr; err %d\n",
9802 ret);
9803 }
9804 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009805 case I40E_VSI_VMDQ2:
Vasu Dev38e00432014-08-01 13:27:03 -07009806 case I40E_VSI_FCOE:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009807 ret = i40e_config_netdev(vsi);
9808 if (ret)
9809 goto err_netdev;
9810 ret = register_netdev(vsi->netdev);
9811 if (ret)
9812 goto err_netdev;
9813 vsi->netdev_registered = true;
9814 netif_carrier_off(vsi->netdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08009815#ifdef CONFIG_I40E_DCB
9816 /* Setup DCB netlink interface */
9817 i40e_dcbnl_setup(vsi);
9818#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009819 /* fall through */
9820
9821 case I40E_VSI_FDIR:
9822 /* set up vectors and rings if needed */
9823 ret = i40e_vsi_setup_vectors(vsi);
9824 if (ret)
9825 goto err_msix;
9826
9827 ret = i40e_alloc_rings(vsi);
9828 if (ret)
9829 goto err_rings;
9830
9831 /* map all of the rings to the q_vectors */
9832 i40e_vsi_map_rings_to_vectors(vsi);
9833
9834 i40e_vsi_reset_stats(vsi);
9835 break;
9836
9837 default:
9838 /* no netdev or rings for the other VSI types */
9839 break;
9840 }
9841
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04009842 if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
9843 (vsi->type == I40E_VSI_VMDQ2)) {
9844 ret = i40e_vsi_config_rss(vsi);
9845 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009846 return vsi;
9847
9848err_rings:
9849 i40e_vsi_free_q_vectors(vsi);
9850err_msix:
9851 if (vsi->netdev_registered) {
9852 vsi->netdev_registered = false;
9853 unregister_netdev(vsi->netdev);
9854 free_netdev(vsi->netdev);
9855 vsi->netdev = NULL;
9856 }
9857err_netdev:
9858 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
9859err_vsi:
9860 i40e_vsi_clear(vsi);
9861err_alloc:
9862 return NULL;
9863}
9864
9865/**
9866 * i40e_veb_get_bw_info - Query VEB BW information
9867 * @veb: the veb to query
9868 *
9869 * Query the Tx scheduler BW configuration data for given VEB
9870 **/
9871static int i40e_veb_get_bw_info(struct i40e_veb *veb)
9872{
9873 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
9874 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
9875 struct i40e_pf *pf = veb->pf;
9876 struct i40e_hw *hw = &pf->hw;
9877 u32 tc_bw_max;
9878 int ret = 0;
9879 int i;
9880
9881 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
9882 &bw_data, NULL);
9883 if (ret) {
9884 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009885 "query veb bw config failed, err %s aq_err %s\n",
9886 i40e_stat_str(&pf->hw, ret),
9887 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009888 goto out;
9889 }
9890
9891 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
9892 &ets_data, NULL);
9893 if (ret) {
9894 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009895 "query veb bw ets config failed, err %s aq_err %s\n",
9896 i40e_stat_str(&pf->hw, ret),
9897 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009898 goto out;
9899 }
9900
9901 veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
9902 veb->bw_max_quanta = ets_data.tc_bw_max;
9903 veb->is_abs_credits = bw_data.absolute_credits_enable;
Neerav Parikh23cd1f02014-11-12 00:18:41 +00009904 veb->enabled_tc = ets_data.tc_valid_bits;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009905 tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
9906 (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
9907 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
9908 veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
9909 veb->bw_tc_limit_credits[i] =
9910 le16_to_cpu(bw_data.tc_bw_limits[i]);
9911 veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
9912 }
9913
9914out:
9915 return ret;
9916}
9917
9918/**
9919 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
9920 * @pf: board private structure
9921 *
9922 * On error: returns error code (negative)
9923 * On success: returns vsi index in PF (positive)
9924 **/
9925static int i40e_veb_mem_alloc(struct i40e_pf *pf)
9926{
9927 int ret = -ENOENT;
9928 struct i40e_veb *veb;
9929 int i;
9930
9931 /* Need to protect the allocation of switch elements at the PF level */
9932 mutex_lock(&pf->switch_mutex);
9933
9934 /* VEB list may be fragmented if VEB creation/destruction has
9935 * been happening. We can afford to do a quick scan to look
9936 * for any free slots in the list.
9937 *
9938 * find next empty veb slot, looping back around if necessary
9939 */
9940 i = 0;
9941 while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
9942 i++;
9943 if (i >= I40E_MAX_VEB) {
9944 ret = -ENOMEM;
9945 goto err_alloc_veb; /* out of VEB slots! */
9946 }
9947
9948 veb = kzalloc(sizeof(*veb), GFP_KERNEL);
9949 if (!veb) {
9950 ret = -ENOMEM;
9951 goto err_alloc_veb;
9952 }
9953 veb->pf = pf;
9954 veb->idx = i;
9955 veb->enabled_tc = 1;
9956
9957 pf->veb[i] = veb;
9958 ret = i;
9959err_alloc_veb:
9960 mutex_unlock(&pf->switch_mutex);
9961 return ret;
9962}
9963
9964/**
9965 * i40e_switch_branch_release - Delete a branch of the switch tree
9966 * @branch: where to start deleting
9967 *
9968 * This uses recursion to find the tips of the branch to be
9969 * removed, deleting until we get back to and can delete this VEB.
9970 **/
9971static void i40e_switch_branch_release(struct i40e_veb *branch)
9972{
9973 struct i40e_pf *pf = branch->pf;
9974 u16 branch_seid = branch->seid;
9975 u16 veb_idx = branch->idx;
9976 int i;
9977
9978 /* release any VEBs on this VEB - RECURSION */
9979 for (i = 0; i < I40E_MAX_VEB; i++) {
9980 if (!pf->veb[i])
9981 continue;
9982 if (pf->veb[i]->uplink_seid == branch->seid)
9983 i40e_switch_branch_release(pf->veb[i]);
9984 }
9985
9986 /* Release the VSIs on this VEB, but not the owner VSI.
9987 *
9988 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
9989 * the VEB itself, so don't use (*branch) after this loop.
9990 */
Mitch Williams505682c2014-05-20 08:01:37 +00009991 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009992 if (!pf->vsi[i])
9993 continue;
9994 if (pf->vsi[i]->uplink_seid == branch_seid &&
9995 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
9996 i40e_vsi_release(pf->vsi[i]);
9997 }
9998 }
9999
10000 /* There's one corner case where the VEB might not have been
10001 * removed, so double check it here and remove it if needed.
10002 * This case happens if the veb was created from the debugfs
10003 * commands and no VSIs were added to it.
10004 */
10005 if (pf->veb[veb_idx])
10006 i40e_veb_release(pf->veb[veb_idx]);
10007}
10008
10009/**
10010 * i40e_veb_clear - remove veb struct
10011 * @veb: the veb to remove
10012 **/
10013static void i40e_veb_clear(struct i40e_veb *veb)
10014{
10015 if (!veb)
10016 return;
10017
10018 if (veb->pf) {
10019 struct i40e_pf *pf = veb->pf;
10020
10021 mutex_lock(&pf->switch_mutex);
10022 if (pf->veb[veb->idx] == veb)
10023 pf->veb[veb->idx] = NULL;
10024 mutex_unlock(&pf->switch_mutex);
10025 }
10026
10027 kfree(veb);
10028}
10029
10030/**
10031 * i40e_veb_release - Delete a VEB and free its resources
10032 * @veb: the VEB being removed
10033 **/
10034void i40e_veb_release(struct i40e_veb *veb)
10035{
10036 struct i40e_vsi *vsi = NULL;
10037 struct i40e_pf *pf;
10038 int i, n = 0;
10039
10040 pf = veb->pf;
10041
10042 /* find the remaining VSI and check for extras */
Mitch Williams505682c2014-05-20 08:01:37 +000010043 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010044 if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
10045 n++;
10046 vsi = pf->vsi[i];
10047 }
10048 }
10049 if (n != 1) {
10050 dev_info(&pf->pdev->dev,
10051 "can't remove VEB %d with %d VSIs left\n",
10052 veb->seid, n);
10053 return;
10054 }
10055
10056 /* move the remaining VSI to uplink veb */
10057 vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
10058 if (veb->uplink_seid) {
10059 vsi->uplink_seid = veb->uplink_seid;
10060 if (veb->uplink_seid == pf->mac_seid)
10061 vsi->veb_idx = I40E_NO_VEB;
10062 else
10063 vsi->veb_idx = veb->veb_idx;
10064 } else {
10065 /* floating VEB */
10066 vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
10067 vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
10068 }
10069
10070 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
10071 i40e_veb_clear(veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010072}
10073
10074/**
10075 * i40e_add_veb - create the VEB in the switch
10076 * @veb: the VEB to be instantiated
10077 * @vsi: the controlling VSI
10078 **/
10079static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
10080{
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010081 struct i40e_pf *pf = veb->pf;
Anjali Singhai Jain92faef82015-07-28 13:02:00 -040010082 bool is_default = veb->pf->cur_promisc;
Shannon Nelson66fc3602016-01-13 16:51:42 -080010083 bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010084 int ret;
10085
10086 /* get a VEB from the hardware */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010087 ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
Kevin Scotte1c51b952013-11-20 10:02:51 +000010088 veb->enabled_tc, is_default,
Shannon Nelson66fc3602016-01-13 16:51:42 -080010089 &veb->seid, enable_stats, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010090 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010091 dev_info(&pf->pdev->dev,
10092 "couldn't add VEB, err %s aq_err %s\n",
10093 i40e_stat_str(&pf->hw, ret),
10094 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010095 return -EPERM;
10096 }
10097
10098 /* get statistics counter */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010099 ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010100 &veb->stats_idx, NULL, NULL, NULL);
10101 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010102 dev_info(&pf->pdev->dev,
10103 "couldn't get VEB statistics idx, err %s aq_err %s\n",
10104 i40e_stat_str(&pf->hw, ret),
10105 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010106 return -EPERM;
10107 }
10108 ret = i40e_veb_get_bw_info(veb);
10109 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010110 dev_info(&pf->pdev->dev,
10111 "couldn't get VEB bw info, err %s aq_err %s\n",
10112 i40e_stat_str(&pf->hw, ret),
10113 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10114 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010115 return -ENOENT;
10116 }
10117
10118 vsi->uplink_seid = veb->seid;
10119 vsi->veb_idx = veb->idx;
10120 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
10121
10122 return 0;
10123}
10124
10125/**
10126 * i40e_veb_setup - Set up a VEB
10127 * @pf: board private structure
10128 * @flags: VEB setup flags
10129 * @uplink_seid: the switch element to link to
10130 * @vsi_seid: the initial VSI seid
10131 * @enabled_tc: Enabled TC bit-map
10132 *
10133 * This allocates the sw VEB structure and links it into the switch
10134 * It is possible and legal for this to be a duplicate of an already
10135 * existing VEB. It is also possible for both uplink and vsi seids
10136 * to be zero, in order to create a floating VEB.
10137 *
10138 * Returns pointer to the successfully allocated VEB sw struct on
10139 * success, otherwise returns NULL on failure.
10140 **/
10141struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
10142 u16 uplink_seid, u16 vsi_seid,
10143 u8 enabled_tc)
10144{
10145 struct i40e_veb *veb, *uplink_veb = NULL;
10146 int vsi_idx, veb_idx;
10147 int ret;
10148
10149 /* if one seid is 0, the other must be 0 to create a floating relay */
10150 if ((uplink_seid == 0 || vsi_seid == 0) &&
10151 (uplink_seid + vsi_seid != 0)) {
10152 dev_info(&pf->pdev->dev,
10153 "one, not both seid's are 0: uplink=%d vsi=%d\n",
10154 uplink_seid, vsi_seid);
10155 return NULL;
10156 }
10157
10158 /* make sure there is such a vsi and uplink */
Mitch Williams505682c2014-05-20 08:01:37 +000010159 for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010160 if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
10161 break;
Mitch Williams505682c2014-05-20 08:01:37 +000010162 if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010163 dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
10164 vsi_seid);
10165 return NULL;
10166 }
10167
10168 if (uplink_seid && uplink_seid != pf->mac_seid) {
10169 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
10170 if (pf->veb[veb_idx] &&
10171 pf->veb[veb_idx]->seid == uplink_seid) {
10172 uplink_veb = pf->veb[veb_idx];
10173 break;
10174 }
10175 }
10176 if (!uplink_veb) {
10177 dev_info(&pf->pdev->dev,
10178 "uplink seid %d not found\n", uplink_seid);
10179 return NULL;
10180 }
10181 }
10182
10183 /* get veb sw struct */
10184 veb_idx = i40e_veb_mem_alloc(pf);
10185 if (veb_idx < 0)
10186 goto err_alloc;
10187 veb = pf->veb[veb_idx];
10188 veb->flags = flags;
10189 veb->uplink_seid = uplink_seid;
10190 veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
10191 veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
10192
10193 /* create the VEB in the switch */
10194 ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
10195 if (ret)
10196 goto err_veb;
Shannon Nelson1bb8b932014-04-23 04:49:54 +000010197 if (vsi_idx == pf->lan_vsi)
10198 pf->lan_veb = veb->idx;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010199
10200 return veb;
10201
10202err_veb:
10203 i40e_veb_clear(veb);
10204err_alloc:
10205 return NULL;
10206}
10207
10208/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000010209 * i40e_setup_pf_switch_element - set PF vars based on switch type
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010210 * @pf: board private structure
10211 * @ele: element we are building info from
10212 * @num_reported: total number of elements
10213 * @printconfig: should we print the contents
10214 *
10215 * helper function to assist in extracting a few useful SEID values.
10216 **/
10217static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
10218 struct i40e_aqc_switch_config_element_resp *ele,
10219 u16 num_reported, bool printconfig)
10220{
10221 u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
10222 u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
10223 u8 element_type = ele->element_type;
10224 u16 seid = le16_to_cpu(ele->seid);
10225
10226 if (printconfig)
10227 dev_info(&pf->pdev->dev,
10228 "type=%d seid=%d uplink=%d downlink=%d\n",
10229 element_type, seid, uplink_seid, downlink_seid);
10230
10231 switch (element_type) {
10232 case I40E_SWITCH_ELEMENT_TYPE_MAC:
10233 pf->mac_seid = seid;
10234 break;
10235 case I40E_SWITCH_ELEMENT_TYPE_VEB:
10236 /* Main VEB? */
10237 if (uplink_seid != pf->mac_seid)
10238 break;
10239 if (pf->lan_veb == I40E_NO_VEB) {
10240 int v;
10241
10242 /* find existing or else empty VEB */
10243 for (v = 0; v < I40E_MAX_VEB; v++) {
10244 if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
10245 pf->lan_veb = v;
10246 break;
10247 }
10248 }
10249 if (pf->lan_veb == I40E_NO_VEB) {
10250 v = i40e_veb_mem_alloc(pf);
10251 if (v < 0)
10252 break;
10253 pf->lan_veb = v;
10254 }
10255 }
10256
10257 pf->veb[pf->lan_veb]->seid = seid;
10258 pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
10259 pf->veb[pf->lan_veb]->pf = pf;
10260 pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
10261 break;
10262 case I40E_SWITCH_ELEMENT_TYPE_VSI:
10263 if (num_reported != 1)
10264 break;
10265 /* This is immediately after a reset so we can assume this is
10266 * the PF's VSI
10267 */
10268 pf->mac_seid = uplink_seid;
10269 pf->pf_seid = downlink_seid;
10270 pf->main_vsi_seid = seid;
10271 if (printconfig)
10272 dev_info(&pf->pdev->dev,
10273 "pf_seid=%d main_vsi_seid=%d\n",
10274 pf->pf_seid, pf->main_vsi_seid);
10275 break;
10276 case I40E_SWITCH_ELEMENT_TYPE_PF:
10277 case I40E_SWITCH_ELEMENT_TYPE_VF:
10278 case I40E_SWITCH_ELEMENT_TYPE_EMP:
10279 case I40E_SWITCH_ELEMENT_TYPE_BMC:
10280 case I40E_SWITCH_ELEMENT_TYPE_PE:
10281 case I40E_SWITCH_ELEMENT_TYPE_PA:
10282 /* ignore these for now */
10283 break;
10284 default:
10285 dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
10286 element_type, seid);
10287 break;
10288 }
10289}
10290
10291/**
10292 * i40e_fetch_switch_configuration - Get switch config from firmware
10293 * @pf: board private structure
10294 * @printconfig: should we print the contents
10295 *
10296 * Get the current switch configuration from the device and
10297 * extract a few useful SEID values.
10298 **/
10299int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
10300{
10301 struct i40e_aqc_get_switch_config_resp *sw_config;
10302 u16 next_seid = 0;
10303 int ret = 0;
10304 u8 *aq_buf;
10305 int i;
10306
10307 aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
10308 if (!aq_buf)
10309 return -ENOMEM;
10310
10311 sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
10312 do {
10313 u16 num_reported, num_total;
10314
10315 ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
10316 I40E_AQ_LARGE_BUF,
10317 &next_seid, NULL);
10318 if (ret) {
10319 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010320 "get switch config failed err %s aq_err %s\n",
10321 i40e_stat_str(&pf->hw, ret),
10322 i40e_aq_str(&pf->hw,
10323 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010324 kfree(aq_buf);
10325 return -ENOENT;
10326 }
10327
10328 num_reported = le16_to_cpu(sw_config->header.num_reported);
10329 num_total = le16_to_cpu(sw_config->header.num_total);
10330
10331 if (printconfig)
10332 dev_info(&pf->pdev->dev,
10333 "header: %d reported %d total\n",
10334 num_reported, num_total);
10335
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010336 for (i = 0; i < num_reported; i++) {
10337 struct i40e_aqc_switch_config_element_resp *ele =
10338 &sw_config->element[i];
10339
10340 i40e_setup_pf_switch_element(pf, ele, num_reported,
10341 printconfig);
10342 }
10343 } while (next_seid != 0);
10344
10345 kfree(aq_buf);
10346 return ret;
10347}
10348
10349/**
10350 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
10351 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010352 * @reinit: if the Main VSI needs to re-initialized.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010353 *
10354 * Returns 0 on success, negative value on failure
10355 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010356static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010357{
10358 int ret;
10359
10360 /* find out what's out there already */
10361 ret = i40e_fetch_switch_configuration(pf, false);
10362 if (ret) {
10363 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010364 "couldn't fetch switch config, err %s aq_err %s\n",
10365 i40e_stat_str(&pf->hw, ret),
10366 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010367 return ret;
10368 }
10369 i40e_pf_reset_stats(pf);
10370
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010371 /* first time setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010372 if (pf->lan_vsi == I40E_NO_VSI || reinit) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010373 struct i40e_vsi *vsi = NULL;
10374 u16 uplink_seid;
10375
10376 /* Set up the PF VSI associated with the PF's main VSI
10377 * that is already in the HW switch
10378 */
10379 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
10380 uplink_seid = pf->veb[pf->lan_veb]->seid;
10381 else
10382 uplink_seid = pf->mac_seid;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010383 if (pf->lan_vsi == I40E_NO_VSI)
10384 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
10385 else if (reinit)
10386 vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010387 if (!vsi) {
10388 dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
10389 i40e_fdir_teardown(pf);
10390 return -EAGAIN;
10391 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010392 } else {
10393 /* force a reset of TC and queue layout configurations */
10394 u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -040010395
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010396 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
10397 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
10398 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
10399 }
10400 i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
10401
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010402 i40e_fdir_sb_setup(pf);
10403
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010404 /* Setup static PF queue filter control settings */
10405 ret = i40e_setup_pf_filter_control(pf);
10406 if (ret) {
10407 dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
10408 ret);
10409 /* Failure here should not stop continuing other steps */
10410 }
10411
10412 /* enable RSS in the HW, even for only one queue, as the stack can use
10413 * the hash
10414 */
10415 if ((pf->flags & I40E_FLAG_RSS_ENABLED))
Helin Zhang043dd652015-10-21 19:56:23 -040010416 i40e_pf_config_rss(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010417
10418 /* fill in link information and enable LSE reporting */
Catherine Sullivan0a862b42015-08-31 19:54:53 -040010419 i40e_update_link_info(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010420 i40e_link_event(pf);
10421
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000010422 /* Initialize user-specific link properties */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010423 pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
10424 I40E_AQ_AN_COMPLETED) ? true : false);
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000010425
Jacob Kellerbeb0dff2014-01-11 05:43:19 +000010426 i40e_ptp_init(pf);
10427
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010428 return ret;
10429}
10430
10431/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010432 * i40e_determine_queue_usage - Work out queue distribution
10433 * @pf: board private structure
10434 **/
10435static void i40e_determine_queue_usage(struct i40e_pf *pf)
10436{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010437 int queues_left;
10438
10439 pf->num_lan_qps = 0;
Vasu Dev38e00432014-08-01 13:27:03 -070010440#ifdef I40E_FCOE
10441 pf->num_fcoe_qps = 0;
10442#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010443
10444 /* Find the max queues to be put into basic use. We'll always be
10445 * using TC0, whether or not DCB is running, and TC0 will get the
10446 * big RSS set.
10447 */
10448 queues_left = pf->hw.func_caps.num_tx_qp;
10449
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010450 if ((queues_left == 1) ||
Frank Zhang9aa7e932014-05-20 08:01:42 +000010451 !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010452 /* one qp for PF, no queues for anything else */
10453 queues_left = 0;
Helin Zhangacd65442015-10-26 19:44:28 -040010454 pf->alloc_rss_size = pf->num_lan_qps = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010455
10456 /* make sure all the fancies are disabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010457 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -070010458#ifdef I40E_FCOE
10459 I40E_FLAG_FCOE_ENABLED |
10460#endif
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010461 I40E_FLAG_FD_SB_ENABLED |
10462 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010463 I40E_FLAG_DCB_CAPABLE |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010464 I40E_FLAG_SRIOV_ENABLED |
10465 I40E_FLAG_VMDQ_ENABLED);
Frank Zhang9aa7e932014-05-20 08:01:42 +000010466 } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
10467 I40E_FLAG_FD_SB_ENABLED |
Anjali Singhai Jainbbe7d0e2014-05-20 08:01:44 +000010468 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010469 I40E_FLAG_DCB_CAPABLE))) {
Frank Zhang9aa7e932014-05-20 08:01:42 +000010470 /* one qp for PF */
Helin Zhangacd65442015-10-26 19:44:28 -040010471 pf->alloc_rss_size = pf->num_lan_qps = 1;
Frank Zhang9aa7e932014-05-20 08:01:42 +000010472 queues_left -= pf->num_lan_qps;
10473
10474 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -070010475#ifdef I40E_FCOE
10476 I40E_FLAG_FCOE_ENABLED |
10477#endif
Frank Zhang9aa7e932014-05-20 08:01:42 +000010478 I40E_FLAG_FD_SB_ENABLED |
10479 I40E_FLAG_FD_ATR_ENABLED |
10480 I40E_FLAG_DCB_ENABLED |
10481 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010482 } else {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010483 /* Not enough queues for all TCs */
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010484 if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010485 (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010486 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010487 dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
10488 }
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +000010489 pf->num_lan_qps = max_t(int, pf->rss_size_max,
10490 num_online_cpus());
10491 pf->num_lan_qps = min_t(int, pf->num_lan_qps,
10492 pf->hw.func_caps.num_tx_qp);
10493
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010494 queues_left -= pf->num_lan_qps;
10495 }
10496
Vasu Dev38e00432014-08-01 13:27:03 -070010497#ifdef I40E_FCOE
10498 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
10499 if (I40E_DEFAULT_FCOE <= queues_left) {
10500 pf->num_fcoe_qps = I40E_DEFAULT_FCOE;
10501 } else if (I40E_MINIMUM_FCOE <= queues_left) {
10502 pf->num_fcoe_qps = I40E_MINIMUM_FCOE;
10503 } else {
10504 pf->num_fcoe_qps = 0;
10505 pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
10506 dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n");
10507 }
10508
10509 queues_left -= pf->num_fcoe_qps;
10510 }
10511
10512#endif
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010513 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
10514 if (queues_left > 1) {
10515 queues_left -= 1; /* save 1 queue for FD */
10516 } else {
10517 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
10518 dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
10519 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010520 }
10521
10522 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
10523 pf->num_vf_qps && pf->num_req_vfs && queues_left) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010524 pf->num_req_vfs = min_t(int, pf->num_req_vfs,
10525 (queues_left / pf->num_vf_qps));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010526 queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
10527 }
10528
10529 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
10530 pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
10531 pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
10532 (queues_left / pf->num_vmdq_qps));
10533 queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
10534 }
10535
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +000010536 pf->queues_left = queues_left;
Neerav Parikh8279e492015-09-03 17:18:50 -040010537 dev_dbg(&pf->pdev->dev,
10538 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
10539 pf->hw.func_caps.num_tx_qp,
10540 !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
Helin Zhangacd65442015-10-26 19:44:28 -040010541 pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
10542 pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
10543 queues_left);
Vasu Dev38e00432014-08-01 13:27:03 -070010544#ifdef I40E_FCOE
Neerav Parikh8279e492015-09-03 17:18:50 -040010545 dev_dbg(&pf->pdev->dev, "fcoe queues = %d\n", pf->num_fcoe_qps);
Vasu Dev38e00432014-08-01 13:27:03 -070010546#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010547}
10548
10549/**
10550 * i40e_setup_pf_filter_control - Setup PF static filter control
10551 * @pf: PF to be setup
10552 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000010553 * i40e_setup_pf_filter_control sets up a PF's initial filter control
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010554 * settings. If PE/FCoE are enabled then it will also set the per PF
10555 * based filter sizes required for them. It also enables Flow director,
10556 * ethertype and macvlan type filter settings for the pf.
10557 *
10558 * Returns 0 on success, negative on failure
10559 **/
10560static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
10561{
10562 struct i40e_filter_control_settings *settings = &pf->filter_settings;
10563
10564 settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
10565
10566 /* Flow Director is enabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010567 if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010568 settings->enable_fdir = true;
10569
10570 /* Ethtype and MACVLAN filters enabled for PF */
10571 settings->enable_ethtype = true;
10572 settings->enable_macvlan = true;
10573
10574 if (i40e_set_filter_control(&pf->hw, settings))
10575 return -ENOENT;
10576
10577 return 0;
10578}
10579
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010580#define INFO_STRING_LEN 255
Shannon Nelson7fd89542015-10-21 19:47:04 -040010581#define REMAIN(__x) (INFO_STRING_LEN - (__x))
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010582static void i40e_print_features(struct i40e_pf *pf)
10583{
10584 struct i40e_hw *hw = &pf->hw;
Joe Perches3b195842015-12-03 04:20:57 -080010585 char *buf;
10586 int i;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010587
Joe Perches3b195842015-12-03 04:20:57 -080010588 buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
10589 if (!buf)
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010590 return;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010591
Joe Perches3b195842015-12-03 04:20:57 -080010592 i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010593#ifdef CONFIG_PCI_IOV
Joe Perches3b195842015-12-03 04:20:57 -080010594 i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010595#endif
Joe Perches3b195842015-12-03 04:20:57 -080010596 i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d RX: %s",
Shannon Nelson7fd89542015-10-21 19:47:04 -040010597 pf->hw.func_caps.num_vsis,
10598 pf->vsi[pf->lan_vsi]->num_queue_pairs,
10599 pf->flags & I40E_FLAG_RX_PS_ENABLED ? "PS" : "1BUF");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010600
10601 if (pf->flags & I40E_FLAG_RSS_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010602 i += snprintf(&buf[i], REMAIN(i), " RSS");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010603 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010604 i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +000010605 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
Joe Perches3b195842015-12-03 04:20:57 -080010606 i += snprintf(&buf[i], REMAIN(i), " FD_SB");
10607 i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +000010608 }
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010609 if (pf->flags & I40E_FLAG_DCB_CAPABLE)
Joe Perches3b195842015-12-03 04:20:57 -080010610 i += snprintf(&buf[i], REMAIN(i), " DCB");
Jesse Brandeburgce6fcb32015-08-28 17:55:59 -040010611#if IS_ENABLED(CONFIG_VXLAN)
Joe Perches3b195842015-12-03 04:20:57 -080010612 i += snprintf(&buf[i], REMAIN(i), " VxLAN");
Jesse Brandeburgce6fcb32015-08-28 17:55:59 -040010613#endif
Singhai, Anjali6a899022015-12-14 12:21:18 -080010614#if IS_ENABLED(CONFIG_GENEVE)
10615 i += snprintf(&buf[i], REMAIN(i), " Geneve");
10616#endif
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010617 if (pf->flags & I40E_FLAG_PTP)
Joe Perches3b195842015-12-03 04:20:57 -080010618 i += snprintf(&buf[i], REMAIN(i), " PTP");
Vasu Dev38e00432014-08-01 13:27:03 -070010619#ifdef I40E_FCOE
10620 if (pf->flags & I40E_FLAG_FCOE_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010621 i += snprintf(&buf[i], REMAIN(i), " FCOE");
Vasu Dev38e00432014-08-01 13:27:03 -070010622#endif
Shannon Nelson6dec1012015-09-28 14:12:30 -040010623 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010624 i += snprintf(&buf[i], REMAIN(i), " VEB");
Shannon Nelson6dec1012015-09-28 14:12:30 -040010625 else
Joe Perches3b195842015-12-03 04:20:57 -080010626 i += snprintf(&buf[i], REMAIN(i), " VEPA");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010627
Joe Perches3b195842015-12-03 04:20:57 -080010628 dev_info(&pf->pdev->dev, "%s\n", buf);
10629 kfree(buf);
Shannon Nelson7fd89542015-10-21 19:47:04 -040010630 WARN_ON(i > INFO_STRING_LEN);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010631}
10632
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010633/**
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010634 * i40e_get_platform_mac_addr - get platform-specific MAC address
10635 *
10636 * @pdev: PCI device information struct
10637 * @pf: board private structure
10638 *
10639 * Look up the MAC address in Open Firmware on systems that support it,
10640 * and use IDPROM on SPARC if no OF address is found. On return, the
10641 * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value
10642 * has been selected.
10643 **/
10644static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
10645{
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010646 pf->flags &= ~I40E_FLAG_PF_MAC;
Sowmini Varadhanba942722016-01-12 19:32:31 -080010647 if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010648 pf->flags |= I40E_FLAG_PF_MAC;
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010649}
10650
10651/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010652 * i40e_probe - Device initialization routine
10653 * @pdev: PCI device information struct
10654 * @ent: entry in i40e_pci_tbl
10655 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000010656 * i40e_probe initializes a PF identified by a pci_dev structure.
10657 * The OS initialization, configuring of the PF private structure,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010658 * and a hardware reset occur.
10659 *
10660 * Returns 0 on success, negative on failure
10661 **/
10662static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
10663{
Catherine Sullivane8278452015-02-06 08:52:08 +000010664 struct i40e_aq_get_phy_abilities_resp abilities;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010665 struct i40e_pf *pf;
10666 struct i40e_hw *hw;
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000010667 static u16 pfs_found;
Shannon Nelson1d5109d2015-08-26 15:14:08 -040010668 u16 wol_nvm_bits;
Catherine Sullivand4dfb812013-11-28 06:39:21 +000010669 u16 link_status;
Jean Sacren6f66a482015-09-19 05:08:45 -060010670 int err;
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -040010671 u32 val;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000010672 u32 i;
Helin Zhang58fc3262015-10-01 14:37:38 -040010673 u8 set_fc_aq_fail;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010674
10675 err = pci_enable_device_mem(pdev);
10676 if (err)
10677 return err;
10678
10679 /* set up for high or low dma */
Mitch Williams64942942014-02-11 08:26:33 +000010680 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +000010681 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +000010682 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
10683 if (err) {
10684 dev_err(&pdev->dev,
10685 "DMA configuration failed: 0x%x\n", err);
10686 goto err_dma;
10687 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010688 }
10689
10690 /* set up pci connections */
10691 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
10692 IORESOURCE_MEM), i40e_driver_name);
10693 if (err) {
10694 dev_info(&pdev->dev,
10695 "pci_request_selected_regions failed %d\n", err);
10696 goto err_pci_reg;
10697 }
10698
10699 pci_enable_pcie_error_reporting(pdev);
10700 pci_set_master(pdev);
10701
10702 /* Now that we have a PCI connection, we need to do the
10703 * low level device setup. This is primarily setting up
10704 * the Admin Queue structures and then querying for the
10705 * device's current profile information.
10706 */
10707 pf = kzalloc(sizeof(*pf), GFP_KERNEL);
10708 if (!pf) {
10709 err = -ENOMEM;
10710 goto err_pf_alloc;
10711 }
10712 pf->next_vsi = 0;
10713 pf->pdev = pdev;
10714 set_bit(__I40E_DOWN, &pf->state);
10715
10716 hw = &pf->hw;
10717 hw->back = pf;
Anjali Singhai232f4702015-02-26 16:15:39 +000010718
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010719 pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
10720 I40E_MAX_CSR_SPACE);
Anjali Singhai232f4702015-02-26 16:15:39 +000010721
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010722 hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010723 if (!hw->hw_addr) {
10724 err = -EIO;
10725 dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
10726 (unsigned int)pci_resource_start(pdev, 0),
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010727 pf->ioremap_len, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010728 goto err_ioremap;
10729 }
10730 hw->vendor_id = pdev->vendor;
10731 hw->device_id = pdev->device;
10732 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
10733 hw->subsystem_vendor_id = pdev->subsystem_vendor;
10734 hw->subsystem_device_id = pdev->subsystem_device;
10735 hw->bus.device = PCI_SLOT(pdev->devfn);
10736 hw->bus.func = PCI_FUNC(pdev->devfn);
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000010737 pf->instance = pfs_found;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010738
Shannon Nelson5b5faa42014-10-17 03:14:51 +000010739 if (debug != -1) {
10740 pf->msg_enable = pf->hw.debug_mask;
10741 pf->msg_enable = debug;
10742 }
10743
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +000010744 /* do a special CORER for clearing PXE mode once at init */
10745 if (hw->revision_id == 0 &&
10746 (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
10747 wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
10748 i40e_flush(hw);
10749 msleep(200);
10750 pf->corer_count++;
10751
10752 i40e_clear_pxe_mode(hw);
10753 }
10754
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010755 /* Reset here to make sure all is clean and to define PF 'n' */
Shannon Nelson838d41d2014-06-04 20:41:27 +000010756 i40e_clear_hw(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010757 err = i40e_pf_reset(hw);
10758 if (err) {
10759 dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
10760 goto err_pf_reset;
10761 }
10762 pf->pfr_count++;
10763
10764 hw->aq.num_arq_entries = I40E_AQ_LEN;
10765 hw->aq.num_asq_entries = I40E_AQ_LEN;
10766 hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
10767 hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
10768 pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +000010769
Carolyn Wybornyb294ac72014-12-11 07:06:39 +000010770 snprintf(pf->int_name, sizeof(pf->int_name) - 1,
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +000010771 "%s-%s:misc",
10772 dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010773
10774 err = i40e_init_shared_code(hw);
10775 if (err) {
Anjali Singhai Jainb2a75c52015-04-27 14:57:20 -040010776 dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
10777 err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010778 goto err_pf_reset;
10779 }
10780
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000010781 /* set up a default setting for link flow control */
10782 pf->hw.fc.requested_mode = I40E_FC_NONE;
10783
Jesse Brandeburg8ddb3322015-11-18 15:47:06 -080010784 /* set up the locks for the AQ, do this only once in probe
10785 * and destroy them only once in remove
10786 */
10787 mutex_init(&hw->aq.asq_mutex);
10788 mutex_init(&hw->aq.arq_mutex);
10789
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010790 err = i40e_init_adminq(hw);
Carolyn Wyborny2b2426a762015-10-26 19:44:35 -040010791 if (err) {
10792 if (err == I40E_ERR_FIRMWARE_API_VERSION)
10793 dev_info(&pdev->dev,
10794 "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");
10795 else
10796 dev_info(&pdev->dev,
10797 "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
10798
10799 goto err_pf_reset;
10800 }
Carolyn Wybornyf0b44442015-08-31 19:54:49 -040010801
Shannon Nelson6dec1012015-09-28 14:12:30 -040010802 /* provide nvm, fw, api versions */
10803 dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
10804 hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
10805 hw->aq.api_maj_ver, hw->aq.api_min_ver,
10806 i40e_nvm_version_str(hw));
Carolyn Wybornyf0b44442015-08-31 19:54:49 -040010807
Catherine Sullivan7aa67612014-07-09 07:46:17 +000010808 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
10809 hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
Shannon Nelson278b6f62014-06-04 01:41:03 +000010810 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000010811 "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");
10812 else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
10813 hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
Shannon Nelson278b6f62014-06-04 01:41:03 +000010814 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000010815 "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 +000010816
Shannon Nelson4eb3f762014-03-06 08:59:58 +000010817 i40e_verify_eeprom(pf);
10818
Jesse Brandeburg2c5fe332014-04-23 04:49:57 +000010819 /* Rev 0 hardware was never productized */
10820 if (hw->revision_id < 1)
10821 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");
10822
Shannon Nelson6ff4ef82013-12-21 05:44:49 +000010823 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010824 err = i40e_get_capabilities(pf);
10825 if (err)
10826 goto err_adminq_setup;
10827
10828 err = i40e_sw_init(pf);
10829 if (err) {
10830 dev_info(&pdev->dev, "sw_init failed: %d\n", err);
10831 goto err_sw_init;
10832 }
10833
10834 err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
10835 hw->func_caps.num_rx_qp,
10836 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
10837 if (err) {
10838 dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
10839 goto err_init_lan_hmc;
10840 }
10841
10842 err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
10843 if (err) {
10844 dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
10845 err = -ENOENT;
10846 goto err_configure_lan_hmc;
10847 }
10848
Neerav Parikhb686ece2014-12-14 01:55:11 +000010849 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
10850 * Ignore error return codes because if it was already disabled via
10851 * hardware settings this will fail
10852 */
Neerav Parikhf1bbad32016-01-13 16:51:39 -080010853 if (pf->flags & I40E_FLAG_STOP_FW_LLDP) {
Neerav Parikhb686ece2014-12-14 01:55:11 +000010854 dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
10855 i40e_aq_stop_lldp(hw, true, NULL);
10856 }
10857
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010858 i40e_get_mac_addr(hw, hw->mac.addr);
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010859 /* allow a platform config to override the HW addr */
10860 i40e_get_platform_mac_addr(pdev, pf);
Jesse Brandeburgf62b5062013-11-28 06:39:27 +000010861 if (!is_valid_ether_addr(hw->mac.addr)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010862 dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
10863 err = -EIO;
10864 goto err_mac_addr;
10865 }
10866 dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
Greg Rose9a173902014-05-22 06:32:02 +000010867 ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
Neerav Parikh1f224ad2014-02-12 01:45:31 +000010868 i40e_get_port_mac_addr(hw, hw->mac.port_addr);
10869 if (is_valid_ether_addr(hw->mac.port_addr))
10870 pf->flags |= I40E_FLAG_PORT_ID_VALID;
Vasu Dev38e00432014-08-01 13:27:03 -070010871#ifdef I40E_FCOE
10872 err = i40e_get_san_mac_addr(hw, hw->mac.san_addr);
10873 if (err)
10874 dev_info(&pdev->dev,
10875 "(non-fatal) SAN MAC retrieval failed: %d\n", err);
10876 if (!is_valid_ether_addr(hw->mac.san_addr)) {
10877 dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
10878 hw->mac.san_addr);
10879 ether_addr_copy(hw->mac.san_addr, hw->mac.addr);
10880 }
10881 dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr);
10882#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010883
10884 pci_set_drvdata(pdev, pf);
10885 pci_save_state(pdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080010886#ifdef CONFIG_I40E_DCB
10887 err = i40e_init_pf_dcb(pf);
10888 if (err) {
Shannon Nelsonaebfc812014-12-11 07:06:38 +000010889 dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010890 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
Neerav Parikh014269f2014-04-01 07:11:48 +000010891 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080010892 }
10893#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010894
10895 /* set up periodic task facility */
10896 setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
10897 pf->service_timer_period = HZ;
10898
10899 INIT_WORK(&pf->service_task, i40e_service_task);
10900 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
10901 pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010902
Shannon Nelson1d5109d2015-08-26 15:14:08 -040010903 /* NVM bit on means WoL disabled for the port */
10904 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -080010905 if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
Shannon Nelson1d5109d2015-08-26 15:14:08 -040010906 pf->wol_en = false;
10907 else
10908 pf->wol_en = true;
Shannon Nelson8e2773a2013-11-28 06:39:22 +000010909 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
10910
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010911 /* set up the main switch operations */
10912 i40e_determine_queue_usage(pf);
Jesse Brandeburgc11472802015-04-07 19:45:39 -040010913 err = i40e_init_interrupt_scheme(pf);
10914 if (err)
10915 goto err_switch_setup;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010916
Mitch Williams505682c2014-05-20 08:01:37 +000010917 /* The number of VSIs reported by the FW is the minimum guaranteed
10918 * to us; HW supports far more and we share the remaining pool with
10919 * the other PFs. We allocate space for more than the guarantee with
10920 * the understanding that we might not get them all later.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010921 */
Mitch Williams505682c2014-05-20 08:01:37 +000010922 if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
10923 pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
10924 else
10925 pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
10926
10927 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
Jesse Brandeburgd17038d2015-12-23 12:05:55 -080010928 pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
10929 GFP_KERNEL);
Wei Yongjuned87ac02013-09-24 05:17:25 +000010930 if (!pf->vsi) {
10931 err = -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010932 goto err_switch_setup;
Wei Yongjuned87ac02013-09-24 05:17:25 +000010933 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010934
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -040010935#ifdef CONFIG_PCI_IOV
10936 /* prep for VF support */
10937 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
10938 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
10939 !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
10940 if (pci_num_vf(pdev))
10941 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
10942 }
10943#endif
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010944 err = i40e_setup_pf_switch(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010945 if (err) {
10946 dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
10947 goto err_vsis;
10948 }
Helin Zhang58fc3262015-10-01 14:37:38 -040010949
10950 /* Make sure flow control is set according to current settings */
10951 err = i40e_set_fc(hw, &set_fc_aq_fail, true);
10952 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
10953 dev_dbg(&pf->pdev->dev,
10954 "Set fc with err %s aq_err %s on get_phy_cap\n",
10955 i40e_stat_str(hw, err),
10956 i40e_aq_str(hw, hw->aq.asq_last_status));
10957 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
10958 dev_dbg(&pf->pdev->dev,
10959 "Set fc with err %s aq_err %s on set_phy_config\n",
10960 i40e_stat_str(hw, err),
10961 i40e_aq_str(hw, hw->aq.asq_last_status));
10962 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
10963 dev_dbg(&pf->pdev->dev,
10964 "Set fc with err %s aq_err %s on get_link_info\n",
10965 i40e_stat_str(hw, err),
10966 i40e_aq_str(hw, hw->aq.asq_last_status));
10967
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000010968 /* if FDIR VSI was set up, start it now */
Mitch Williams505682c2014-05-20 08:01:37 +000010969 for (i = 0; i < pf->num_alloc_vsi; i++) {
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000010970 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
10971 i40e_vsi_open(pf->vsi[i]);
10972 break;
10973 }
10974 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010975
Shannon Nelson2f0aff42016-01-04 10:33:08 -080010976 /* The driver only wants link up/down and module qualification
10977 * reports from firmware. Note the negative logic.
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000010978 */
10979 err = i40e_aq_set_phy_int_mask(&pf->hw,
Shannon Nelson2f0aff42016-01-04 10:33:08 -080010980 ~(I40E_AQ_EVENT_LINK_UPDOWN |
10981 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000010982 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010983 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
10984 i40e_stat_str(&pf->hw, err),
10985 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000010986
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -040010987 /* Reconfigure hardware for allowing smaller MSS in the case
10988 * of TSO, so that we avoid the MDD being fired and causing
10989 * a reset in the case of small MSS+TSO.
10990 */
10991 val = rd32(hw, I40E_REG_MSS);
10992 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
10993 val &= ~I40E_REG_MSS_MIN_MASK;
10994 val |= I40E_64BYTE_MSS;
10995 wr32(hw, I40E_REG_MSS, val);
10996 }
10997
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -080010998 if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +000010999 msleep(75);
11000 err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
11001 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040011002 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
11003 i40e_stat_str(&pf->hw, err),
11004 i40e_aq_str(&pf->hw,
11005 pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +000011006 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011007 /* The main driver is (mostly) up and happy. We need to set this state
11008 * before setting up the misc vector or we get a race and the vector
11009 * ends up disabled forever.
11010 */
11011 clear_bit(__I40E_DOWN, &pf->state);
11012
11013 /* In case of MSIX we are going to setup the misc vector right here
11014 * to handle admin queue events etc. In case of legacy and MSI
11015 * the misc functionality and queue processing is combined in
11016 * the same vector and that gets setup at open.
11017 */
11018 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
11019 err = i40e_setup_misc_vector(pf);
11020 if (err) {
11021 dev_info(&pdev->dev,
11022 "setup of misc vector failed: %d\n", err);
11023 goto err_vsis;
11024 }
11025 }
11026
Greg Rosedf805f62014-04-04 04:43:16 +000011027#ifdef CONFIG_PCI_IOV
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011028 /* prep for VF support */
11029 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
Shannon Nelson4eb3f762014-03-06 08:59:58 +000011030 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
11031 !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011032 /* disable link interrupts for VFs */
11033 val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
11034 val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
11035 wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
11036 i40e_flush(hw);
Mitch Williams4aeec012014-02-13 03:48:47 -080011037
11038 if (pci_num_vf(pdev)) {
11039 dev_info(&pdev->dev,
11040 "Active VFs found, allocating resources.\n");
11041 err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
11042 if (err)
11043 dev_info(&pdev->dev,
11044 "Error %d allocating resources for existing VFs\n",
11045 err);
11046 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011047 }
Greg Rosedf805f62014-04-04 04:43:16 +000011048#endif /* CONFIG_PCI_IOV */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011049
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000011050 pfs_found++;
11051
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011052 i40e_dbg_pf_init(pf);
11053
11054 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +000011055 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011056
11057 /* since everything's happy, start the service_task timer */
11058 mod_timer(&pf->service_timer,
11059 round_jiffies(jiffies + pf->service_timer_period));
11060
Vasu Dev38e00432014-08-01 13:27:03 -070011061#ifdef I40E_FCOE
11062 /* create FCoE interface */
11063 i40e_fcoe_vsi_setup(pf);
11064
11065#endif
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011066#define PCI_SPEED_SIZE 8
11067#define PCI_WIDTH_SIZE 8
11068 /* Devices on the IOSF bus do not have this information
11069 * and will report PCI Gen 1 x 1 by default so don't bother
11070 * checking them.
11071 */
11072 if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) {
11073 char speed[PCI_SPEED_SIZE] = "Unknown";
11074 char width[PCI_WIDTH_SIZE] = "Unknown";
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011075
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011076 /* Get the negotiated link width and speed from PCI config
11077 * space
11078 */
11079 pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
11080 &link_status);
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011081
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011082 i40e_set_pci_config_data(hw, link_status);
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011083
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011084 switch (hw->bus.speed) {
11085 case i40e_bus_speed_8000:
11086 strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
11087 case i40e_bus_speed_5000:
11088 strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
11089 case i40e_bus_speed_2500:
11090 strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
11091 default:
11092 break;
11093 }
11094 switch (hw->bus.width) {
11095 case i40e_bus_width_pcie_x8:
11096 strncpy(width, "8", PCI_WIDTH_SIZE); break;
11097 case i40e_bus_width_pcie_x4:
11098 strncpy(width, "4", PCI_WIDTH_SIZE); break;
11099 case i40e_bus_width_pcie_x2:
11100 strncpy(width, "2", PCI_WIDTH_SIZE); break;
11101 case i40e_bus_width_pcie_x1:
11102 strncpy(width, "1", PCI_WIDTH_SIZE); break;
11103 default:
11104 break;
11105 }
11106
11107 dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
11108 speed, width);
11109
11110 if (hw->bus.width < i40e_bus_width_pcie_x8 ||
11111 hw->bus.speed < i40e_bus_speed_8000) {
11112 dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
11113 dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
11114 }
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011115 }
11116
Catherine Sullivane8278452015-02-06 08:52:08 +000011117 /* get the requested speeds from the fw */
11118 err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
11119 if (err)
Neerav Parikh8279e492015-09-03 17:18:50 -040011120 dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
11121 i40e_stat_str(&pf->hw, err),
11122 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Catherine Sullivane8278452015-02-06 08:52:08 +000011123 pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
11124
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -040011125 /* get the supported phy types from the fw */
11126 err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
11127 if (err)
11128 dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
11129 i40e_stat_str(&pf->hw, err),
11130 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
11131 pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type);
11132
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -040011133 /* Add a filter to drop all Flow control frames from any VSI from being
11134 * transmitted. By doing so we stop a malicious VF from sending out
11135 * PAUSE or PFC frames and potentially controlling traffic for other
11136 * PF/VF VSIs.
11137 * The FW can still send Flow control frames if enabled.
11138 */
11139 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
11140 pf->main_vsi_seid);
11141
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011142 /* print a string summarizing features */
11143 i40e_print_features(pf);
11144
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011145 return 0;
11146
11147 /* Unwind what we've done if something failed in the setup */
11148err_vsis:
11149 set_bit(__I40E_DOWN, &pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011150 i40e_clear_interrupt_scheme(pf);
11151 kfree(pf->vsi);
Shannon Nelson04b03012013-11-28 06:39:34 +000011152err_switch_setup:
11153 i40e_reset_interrupt_capability(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011154 del_timer_sync(&pf->service_timer);
11155err_mac_addr:
11156err_configure_lan_hmc:
11157 (void)i40e_shutdown_lan_hmc(hw);
11158err_init_lan_hmc:
11159 kfree(pf->qp_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011160err_sw_init:
11161err_adminq_setup:
11162 (void)i40e_shutdown_adminq(hw);
11163err_pf_reset:
11164 iounmap(hw->hw_addr);
11165err_ioremap:
11166 kfree(pf);
11167err_pf_alloc:
11168 pci_disable_pcie_error_reporting(pdev);
11169 pci_release_selected_regions(pdev,
11170 pci_select_bars(pdev, IORESOURCE_MEM));
11171err_pci_reg:
11172err_dma:
11173 pci_disable_device(pdev);
11174 return err;
11175}
11176
11177/**
11178 * i40e_remove - Device removal routine
11179 * @pdev: PCI device information struct
11180 *
11181 * i40e_remove is called by the PCI subsystem to alert the driver
11182 * that is should release a PCI device. This could be caused by a
11183 * Hot-Plug event, or because the driver is going to be removed from
11184 * memory.
11185 **/
11186static void i40e_remove(struct pci_dev *pdev)
11187{
11188 struct i40e_pf *pf = pci_get_drvdata(pdev);
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011189 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011190 i40e_status ret_code;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011191 int i;
11192
11193 i40e_dbg_pf_exit(pf);
11194
Jacob Kellerbeb0dff2014-01-11 05:43:19 +000011195 i40e_ptp_stop(pf);
11196
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011197 /* Disable RSS in hw */
11198 wr32(hw, I40E_PFQF_HENA(0), 0);
11199 wr32(hw, I40E_PFQF_HENA(1), 0);
11200
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011201 /* no more scheduling of any task */
11202 set_bit(__I40E_DOWN, &pf->state);
11203 del_timer_sync(&pf->service_timer);
11204 cancel_work_sync(&pf->service_task);
11205
Mitch Williamseb2d80b2014-02-13 03:48:48 -080011206 if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
11207 i40e_free_vfs(pf);
11208 pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
11209 }
11210
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011211 i40e_fdir_teardown(pf);
11212
11213 /* If there is a switch structure or any orphans, remove them.
11214 * This will leave only the PF's VSI remaining.
11215 */
11216 for (i = 0; i < I40E_MAX_VEB; i++) {
11217 if (!pf->veb[i])
11218 continue;
11219
11220 if (pf->veb[i]->uplink_seid == pf->mac_seid ||
11221 pf->veb[i]->uplink_seid == 0)
11222 i40e_switch_branch_release(pf->veb[i]);
11223 }
11224
11225 /* Now we can shutdown the PF's VSI, just before we kill
11226 * adminq and hmc.
11227 */
11228 if (pf->vsi[pf->lan_vsi])
11229 i40e_vsi_release(pf->vsi[pf->lan_vsi]);
11230
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011231 /* shutdown and destroy the HMC */
Jesse Brandeburgf734dff2016-01-15 14:33:11 -080011232 if (hw->hmc.hmc_obj) {
11233 ret_code = i40e_shutdown_lan_hmc(hw);
Shannon Nelson60442de2014-04-23 04:50:13 +000011234 if (ret_code)
11235 dev_warn(&pdev->dev,
11236 "Failed to destroy the HMC resources: %d\n",
11237 ret_code);
11238 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011239
11240 /* shutdown the adminq */
Jesse Brandeburgf734dff2016-01-15 14:33:11 -080011241 ret_code = i40e_shutdown_adminq(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011242 if (ret_code)
11243 dev_warn(&pdev->dev,
11244 "Failed to destroy the Admin Queue resources: %d\n",
11245 ret_code);
11246
Jesse Brandeburg8ddb3322015-11-18 15:47:06 -080011247 /* destroy the locks only once, here */
11248 mutex_destroy(&hw->aq.arq_mutex);
11249 mutex_destroy(&hw->aq.asq_mutex);
11250
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011251 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
11252 i40e_clear_interrupt_scheme(pf);
Mitch Williams505682c2014-05-20 08:01:37 +000011253 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011254 if (pf->vsi[i]) {
11255 i40e_vsi_clear_rings(pf->vsi[i]);
11256 i40e_vsi_clear(pf->vsi[i]);
11257 pf->vsi[i] = NULL;
11258 }
11259 }
11260
11261 for (i = 0; i < I40E_MAX_VEB; i++) {
11262 kfree(pf->veb[i]);
11263 pf->veb[i] = NULL;
11264 }
11265
11266 kfree(pf->qp_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011267 kfree(pf->vsi);
11268
Jesse Brandeburgf734dff2016-01-15 14:33:11 -080011269 iounmap(hw->hw_addr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011270 kfree(pf);
11271 pci_release_selected_regions(pdev,
11272 pci_select_bars(pdev, IORESOURCE_MEM));
11273
11274 pci_disable_pcie_error_reporting(pdev);
11275 pci_disable_device(pdev);
11276}
11277
11278/**
11279 * i40e_pci_error_detected - warning that something funky happened in PCI land
11280 * @pdev: PCI device information struct
11281 *
11282 * Called to warn that something happened and the error handling steps
11283 * are in progress. Allows the driver to quiesce things, be ready for
11284 * remediation.
11285 **/
11286static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
11287 enum pci_channel_state error)
11288{
11289 struct i40e_pf *pf = pci_get_drvdata(pdev);
11290
11291 dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
11292
11293 /* shutdown all operations */
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011294 if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
11295 rtnl_lock();
11296 i40e_prep_for_reset(pf);
11297 rtnl_unlock();
11298 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011299
11300 /* Request a slot reset */
11301 return PCI_ERS_RESULT_NEED_RESET;
11302}
11303
11304/**
11305 * i40e_pci_error_slot_reset - a PCI slot reset just happened
11306 * @pdev: PCI device information struct
11307 *
11308 * Called to find if the driver can work with the device now that
11309 * the pci slot has been reset. If a basic connection seems good
11310 * (registers are readable and have sane content) then return a
11311 * happy little PCI_ERS_RESULT_xxx.
11312 **/
11313static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
11314{
11315 struct i40e_pf *pf = pci_get_drvdata(pdev);
11316 pci_ers_result_t result;
11317 int err;
11318 u32 reg;
11319
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011320 dev_dbg(&pdev->dev, "%s\n", __func__);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011321 if (pci_enable_device_mem(pdev)) {
11322 dev_info(&pdev->dev,
11323 "Cannot re-enable PCI device after reset.\n");
11324 result = PCI_ERS_RESULT_DISCONNECT;
11325 } else {
11326 pci_set_master(pdev);
11327 pci_restore_state(pdev);
11328 pci_save_state(pdev);
11329 pci_wake_from_d3(pdev, false);
11330
11331 reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
11332 if (reg == 0)
11333 result = PCI_ERS_RESULT_RECOVERED;
11334 else
11335 result = PCI_ERS_RESULT_DISCONNECT;
11336 }
11337
11338 err = pci_cleanup_aer_uncorrect_error_status(pdev);
11339 if (err) {
11340 dev_info(&pdev->dev,
11341 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
11342 err);
11343 /* non-fatal, continue */
11344 }
11345
11346 return result;
11347}
11348
11349/**
11350 * i40e_pci_error_resume - restart operations after PCI error recovery
11351 * @pdev: PCI device information struct
11352 *
11353 * Called to allow the driver to bring things back up after PCI error
11354 * and/or reset recovery has finished.
11355 **/
11356static void i40e_pci_error_resume(struct pci_dev *pdev)
11357{
11358 struct i40e_pf *pf = pci_get_drvdata(pdev);
11359
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011360 dev_dbg(&pdev->dev, "%s\n", __func__);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011361 if (test_bit(__I40E_SUSPENDED, &pf->state))
11362 return;
11363
11364 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011365 i40e_handle_reset_warning(pf);
Vasily Averin4c4935a2015-07-08 15:04:26 +030011366 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011367}
11368
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011369/**
11370 * i40e_shutdown - PCI callback for shutting down
11371 * @pdev: PCI device information struct
11372 **/
11373static void i40e_shutdown(struct pci_dev *pdev)
11374{
11375 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011376 struct i40e_hw *hw = &pf->hw;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011377
11378 set_bit(__I40E_SUSPENDED, &pf->state);
11379 set_bit(__I40E_DOWN, &pf->state);
11380 rtnl_lock();
11381 i40e_prep_for_reset(pf);
11382 rtnl_unlock();
11383
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011384 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11385 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11386
Catherine Sullivan02b42492015-07-10 19:35:59 -040011387 del_timer_sync(&pf->service_timer);
11388 cancel_work_sync(&pf->service_task);
11389 i40e_fdir_teardown(pf);
11390
11391 rtnl_lock();
11392 i40e_prep_for_reset(pf);
11393 rtnl_unlock();
11394
11395 wr32(hw, I40E_PFPM_APM,
11396 (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11397 wr32(hw, I40E_PFPM_WUFC,
11398 (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11399
Shannon Nelsone1477582015-02-21 06:44:33 +000011400 i40e_clear_interrupt_scheme(pf);
11401
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011402 if (system_state == SYSTEM_POWER_OFF) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011403 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011404 pci_set_power_state(pdev, PCI_D3hot);
11405 }
11406}
11407
11408#ifdef CONFIG_PM
11409/**
11410 * i40e_suspend - PCI callback for moving to D3
11411 * @pdev: PCI device information struct
11412 **/
11413static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
11414{
11415 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011416 struct i40e_hw *hw = &pf->hw;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011417
11418 set_bit(__I40E_SUSPENDED, &pf->state);
11419 set_bit(__I40E_DOWN, &pf->state);
Mitch Williams3932dbf2015-03-31 00:45:04 -070011420
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011421 rtnl_lock();
11422 i40e_prep_for_reset(pf);
11423 rtnl_unlock();
11424
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011425 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11426 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11427
11428 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011429 pci_set_power_state(pdev, PCI_D3hot);
11430
11431 return 0;
11432}
11433
11434/**
11435 * i40e_resume - PCI callback for waking up from D3
11436 * @pdev: PCI device information struct
11437 **/
11438static int i40e_resume(struct pci_dev *pdev)
11439{
11440 struct i40e_pf *pf = pci_get_drvdata(pdev);
11441 u32 err;
11442
11443 pci_set_power_state(pdev, PCI_D0);
11444 pci_restore_state(pdev);
11445 /* pci_restore_state() clears dev->state_saves, so
11446 * call pci_save_state() again to restore it.
11447 */
11448 pci_save_state(pdev);
11449
11450 err = pci_enable_device_mem(pdev);
11451 if (err) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011452 dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011453 return err;
11454 }
11455 pci_set_master(pdev);
11456
11457 /* no wakeup events while running */
11458 pci_wake_from_d3(pdev, false);
11459
11460 /* handling the reset will rebuild the device state */
11461 if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
11462 clear_bit(__I40E_DOWN, &pf->state);
11463 rtnl_lock();
11464 i40e_reset_and_rebuild(pf, false);
11465 rtnl_unlock();
11466 }
11467
11468 return 0;
11469}
11470
11471#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011472static const struct pci_error_handlers i40e_err_handler = {
11473 .error_detected = i40e_pci_error_detected,
11474 .slot_reset = i40e_pci_error_slot_reset,
11475 .resume = i40e_pci_error_resume,
11476};
11477
11478static struct pci_driver i40e_driver = {
11479 .name = i40e_driver_name,
11480 .id_table = i40e_pci_tbl,
11481 .probe = i40e_probe,
11482 .remove = i40e_remove,
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011483#ifdef CONFIG_PM
11484 .suspend = i40e_suspend,
11485 .resume = i40e_resume,
11486#endif
11487 .shutdown = i40e_shutdown,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011488 .err_handler = &i40e_err_handler,
11489 .sriov_configure = i40e_pci_sriov_configure,
11490};
11491
11492/**
11493 * i40e_init_module - Driver registration routine
11494 *
11495 * i40e_init_module is the first routine called when the driver is
11496 * loaded. All it does is register with the PCI subsystem.
11497 **/
11498static int __init i40e_init_module(void)
11499{
11500 pr_info("%s: %s - version %s\n", i40e_driver_name,
11501 i40e_driver_string, i40e_driver_version_str);
11502 pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
Greg Rose96664482015-02-06 08:52:13 +000011503
Jesse Brandeburg2803b162015-12-22 14:25:08 -080011504 /* we will see if single thread per module is enough for now,
11505 * it can't be any worse than using the system workqueue which
11506 * was already single threaded
11507 */
11508 i40e_wq = create_singlethread_workqueue(i40e_driver_name);
11509 if (!i40e_wq) {
11510 pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
11511 return -ENOMEM;
11512 }
11513
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011514 i40e_dbg_init();
11515 return pci_register_driver(&i40e_driver);
11516}
11517module_init(i40e_init_module);
11518
11519/**
11520 * i40e_exit_module - Driver exit cleanup routine
11521 *
11522 * i40e_exit_module is called just before the driver is removed
11523 * from memory.
11524 **/
11525static void __exit i40e_exit_module(void)
11526{
11527 pci_unregister_driver(&i40e_driver);
Jesse Brandeburg2803b162015-12-22 14:25:08 -080011528 destroy_workqueue(i40e_wq);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011529 i40e_dbg_exit();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011530}
11531module_exit(i40e_exit_module);