blob: 7d52092947dceebf8185a293b694a9bdca82dd42 [file] [log] [blame]
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Catherine Sullivane8278452015-02-06 08:52:08 +00004 * Copyright(c) 2013 - 2015 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
27/* Local includes */
28#include "i40e.h"
Shannon Nelson4eb3f762014-03-06 08:59:58 +000029#include "i40e_diag.h"
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +000030#ifdef CONFIG_I40E_VXLAN
31#include <net/vxlan.h>
32#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000033
34const char i40e_driver_name[] = "i40e";
35static const char i40e_driver_string[] =
36 "Intel(R) Ethernet Connection XL710 Network Driver";
37
38#define DRV_KERN "-k"
39
Catherine Sullivane8e724d2014-07-10 07:58:26 +000040#define DRV_VERSION_MAJOR 1
Catherine Sullivan42d255c2015-03-31 00:45:06 -070041#define DRV_VERSION_MINOR 3
Catherine Sullivand1d39512015-09-28 14:12:44 -040042#define DRV_VERSION_BUILD 34
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000043#define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
44 __stringify(DRV_VERSION_MINOR) "." \
45 __stringify(DRV_VERSION_BUILD) DRV_KERN
46const char i40e_driver_version_str[] = DRV_VERSION;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -080047static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000048
49/* a bit of forward declarations */
50static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
51static void i40e_handle_reset_warning(struct i40e_pf *pf);
52static int i40e_add_vsi(struct i40e_vsi *vsi);
53static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000054static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000055static int i40e_setup_misc_vector(struct i40e_pf *pf);
56static void i40e_determine_queue_usage(struct i40e_pf *pf);
57static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080058static void i40e_fdir_sb_setup(struct i40e_pf *pf);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080059static int i40e_veb_get_bw_info(struct i40e_veb *veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000060
61/* i40e_pci_tbl - PCI Device ID Table
62 *
63 * Last entry must be all 0s
64 *
65 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
66 * Class, Class Mask, private data (not used) }
67 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020068static const struct pci_device_id i40e_pci_tbl[] = {
Shannon Nelsonab600852014-01-17 15:36:39 -080069 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080070 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
71 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_A), 0},
72 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
73 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080074 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
75 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
76 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
Mitch Williams5960d332014-09-13 07:40:47 +000077 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
Shannon Nelsonbc5166b92015-08-26 15:14:10 -040078 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
Jesse Brandeburgae24b402015-03-27 00:12:09 -070079 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040080 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
81 {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
82 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
Shannon Nelson48a3b512015-07-23 16:54:39 -040083 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
84 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000085 /* required last entry */
86 {0, }
87};
88MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
89
90#define I40E_MAX_VF_COUNT 128
91static int debug = -1;
92module_param(debug, int, 0);
93MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
94
95MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
96MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
97MODULE_LICENSE("GPL");
98MODULE_VERSION(DRV_VERSION);
99
100/**
101 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
102 * @hw: pointer to the HW structure
103 * @mem: ptr to mem struct to fill out
104 * @size: size of memory requested
105 * @alignment: what to align the allocation to
106 **/
107int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
108 u64 size, u32 alignment)
109{
110 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
111
112 mem->size = ALIGN(size, alignment);
113 mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
114 &mem->pa, GFP_KERNEL);
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000115 if (!mem->va)
116 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000117
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000118 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000119}
120
121/**
122 * i40e_free_dma_mem_d - OS specific memory free for shared code
123 * @hw: pointer to the HW structure
124 * @mem: ptr to mem struct to free
125 **/
126int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
127{
128 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
129
130 dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
131 mem->va = NULL;
132 mem->pa = 0;
133 mem->size = 0;
134
135 return 0;
136}
137
138/**
139 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
140 * @hw: pointer to the HW structure
141 * @mem: ptr to mem struct to fill out
142 * @size: size of memory requested
143 **/
144int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
145 u32 size)
146{
147 mem->size = size;
148 mem->va = kzalloc(size, GFP_KERNEL);
149
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000150 if (!mem->va)
151 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000152
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000153 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000154}
155
156/**
157 * i40e_free_virt_mem_d - OS specific memory free for shared code
158 * @hw: pointer to the HW structure
159 * @mem: ptr to mem struct to free
160 **/
161int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
162{
163 /* it's ok to kfree a NULL pointer */
164 kfree(mem->va);
165 mem->va = NULL;
166 mem->size = 0;
167
168 return 0;
169}
170
171/**
172 * i40e_get_lump - find a lump of free generic resource
173 * @pf: board private structure
174 * @pile: the pile of resource to search
175 * @needed: the number of items needed
176 * @id: an owner id to stick on the items assigned
177 *
178 * Returns the base item index of the lump, or negative for error
179 *
180 * The search_hint trick and lack of advanced fit-finding only work
181 * because we're highly likely to have all the same size lump requests.
182 * Linear search time and any fragmentation should be minimal.
183 **/
184static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
185 u16 needed, u16 id)
186{
187 int ret = -ENOMEM;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000188 int i, j;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000189
190 if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
191 dev_info(&pf->pdev->dev,
192 "param err: pile=%p needed=%d id=0x%04x\n",
193 pile, needed, id);
194 return -EINVAL;
195 }
196
197 /* start the linear search with an imperfect hint */
198 i = pile->search_hint;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000199 while (i < pile->num_entries) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000200 /* skip already allocated entries */
201 if (pile->list[i] & I40E_PILE_VALID_BIT) {
202 i++;
203 continue;
204 }
205
206 /* do we have enough in this lump? */
207 for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
208 if (pile->list[i+j] & I40E_PILE_VALID_BIT)
209 break;
210 }
211
212 if (j == needed) {
213 /* there was enough, so assign it to the requestor */
214 for (j = 0; j < needed; j++)
215 pile->list[i+j] = id | I40E_PILE_VALID_BIT;
216 ret = i;
217 pile->search_hint = i + j;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000218 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000219 }
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400220
221 /* not enough, so skip over it and continue looking */
222 i += j;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000223 }
224
225 return ret;
226}
227
228/**
229 * i40e_put_lump - return a lump of generic resource
230 * @pile: the pile of resource to search
231 * @index: the base item index
232 * @id: the owner id of the items assigned
233 *
234 * Returns the count of items in the lump
235 **/
236static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
237{
238 int valid_id = (id | I40E_PILE_VALID_BIT);
239 int count = 0;
240 int i;
241
242 if (!pile || index >= pile->num_entries)
243 return -EINVAL;
244
245 for (i = index;
246 i < pile->num_entries && pile->list[i] == valid_id;
247 i++) {
248 pile->list[i] = 0;
249 count++;
250 }
251
252 if (count && index < pile->search_hint)
253 pile->search_hint = index;
254
255 return count;
256}
257
258/**
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700259 * i40e_find_vsi_from_id - searches for the vsi with the given id
260 * @pf - the pf structure to search for the vsi
261 * @id - id of the vsi it is searching for
262 **/
263struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
264{
265 int i;
266
267 for (i = 0; i < pf->num_alloc_vsi; i++)
268 if (pf->vsi[i] && (pf->vsi[i]->id == id))
269 return pf->vsi[i];
270
271 return NULL;
272}
273
274/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000275 * i40e_service_event_schedule - Schedule the service task to wake up
276 * @pf: board private structure
277 *
278 * If not already scheduled, this puts the task into the work queue
279 **/
280static void i40e_service_event_schedule(struct i40e_pf *pf)
281{
282 if (!test_bit(__I40E_DOWN, &pf->state) &&
283 !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) &&
284 !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
285 schedule_work(&pf->service_task);
286}
287
288/**
289 * i40e_tx_timeout - Respond to a Tx Hang
290 * @netdev: network interface device structure
291 *
292 * If any port has noticed a Tx timeout, it is likely that the whole
293 * device is munged, not just the one netdev port, so go for the full
294 * reset.
295 **/
Vasu Dev38e00432014-08-01 13:27:03 -0700296#ifdef I40E_FCOE
297void i40e_tx_timeout(struct net_device *netdev)
298#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000299static void i40e_tx_timeout(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -0700300#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000301{
302 struct i40e_netdev_priv *np = netdev_priv(netdev);
303 struct i40e_vsi *vsi = np->vsi;
304 struct i40e_pf *pf = vsi->back;
Kiran Patilb03a8c12015-09-24 18:13:15 -0400305 struct i40e_ring *tx_ring = NULL;
306 unsigned int i, hung_queue = 0;
307 u32 head, val;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000308
309 pf->tx_timeout_count++;
310
Kiran Patilb03a8c12015-09-24 18:13:15 -0400311 /* find the stopped queue the same way the stack does */
312 for (i = 0; i < netdev->num_tx_queues; i++) {
313 struct netdev_queue *q;
314 unsigned long trans_start;
315
316 q = netdev_get_tx_queue(netdev, i);
317 trans_start = q->trans_start ? : netdev->trans_start;
318 if (netif_xmit_stopped(q) &&
319 time_after(jiffies,
320 (trans_start + netdev->watchdog_timeo))) {
321 hung_queue = i;
322 break;
323 }
324 }
325
326 if (i == netdev->num_tx_queues) {
327 netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
328 } else {
329 /* now that we have an index, find the tx_ring struct */
330 for (i = 0; i < vsi->num_queue_pairs; i++) {
331 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
332 if (hung_queue ==
333 vsi->tx_rings[i]->queue_index) {
334 tx_ring = vsi->tx_rings[i];
335 break;
336 }
337 }
338 }
339 }
340
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000341 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
Kiran Patilb03a8c12015-09-24 18:13:15 -0400342 pf->tx_timeout_recovery_level = 1; /* reset after some time */
343 else if (time_before(jiffies,
344 (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
345 return; /* don't do any new action before the next timeout */
346
347 if (tx_ring) {
348 head = i40e_get_head(tx_ring);
349 /* Read interrupt register */
350 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
351 val = rd32(&pf->hw,
352 I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
353 tx_ring->vsi->base_vector - 1));
354 else
355 val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
356
357 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",
358 vsi->seid, hung_queue, tx_ring->next_to_clean,
359 head, tx_ring->next_to_use,
360 readl(tx_ring->tail), val);
361 }
362
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000363 pf->tx_timeout_last_recovery = jiffies;
Kiran Patilb03a8c12015-09-24 18:13:15 -0400364 netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
365 pf->tx_timeout_recovery_level, hung_queue);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000366
367 switch (pf->tx_timeout_recovery_level) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000368 case 1:
369 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
370 break;
371 case 2:
372 set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
373 break;
374 case 3:
375 set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
376 break;
377 default:
378 netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000379 break;
380 }
Kiran Patilb03a8c12015-09-24 18:13:15 -0400381
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000382 i40e_service_event_schedule(pf);
383 pf->tx_timeout_recovery_level++;
384}
385
386/**
387 * i40e_release_rx_desc - Store the new tail and head values
388 * @rx_ring: ring to bump
389 * @val: new head index
390 **/
391static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val)
392{
393 rx_ring->next_to_use = val;
394
395 /* Force memory writes to complete before letting h/w
396 * know there are new descriptors to fetch. (Only
397 * applicable for weak-ordered memory model archs,
398 * such as IA-64).
399 */
400 wmb();
401 writel(val, rx_ring->tail);
402}
403
404/**
405 * i40e_get_vsi_stats_struct - Get System Network Statistics
406 * @vsi: the VSI we care about
407 *
408 * Returns the address of the device statistics structure.
409 * The statistics are actually updated from the service task.
410 **/
411struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
412{
413 return &vsi->net_stats;
414}
415
416/**
417 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
418 * @netdev: network interface device structure
419 *
420 * Returns the address of the device statistics structure.
421 * The statistics are actually updated from the service task.
422 **/
Vasu Dev38e00432014-08-01 13:27:03 -0700423#ifdef I40E_FCOE
424struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
425 struct net_device *netdev,
426 struct rtnl_link_stats64 *stats)
427#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000428static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
429 struct net_device *netdev,
Alexander Duyck980e9b12013-09-28 06:01:03 +0000430 struct rtnl_link_stats64 *stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700431#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000432{
433 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000434 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000435 struct i40e_vsi *vsi = np->vsi;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000436 struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
437 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000438
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +0000439 if (test_bit(__I40E_DOWN, &vsi->state))
440 return stats;
441
Jesse Brandeburg3c325ce2013-12-14 03:26:45 -0800442 if (!vsi->tx_rings)
443 return stats;
444
Alexander Duyck980e9b12013-09-28 06:01:03 +0000445 rcu_read_lock();
446 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000447 u64 bytes, packets;
448 unsigned int start;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000449
Alexander Duyck980e9b12013-09-28 06:01:03 +0000450 tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
451 if (!tx_ring)
452 continue;
453
454 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700455 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000456 packets = tx_ring->stats.packets;
457 bytes = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700458 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000459
460 stats->tx_packets += packets;
461 stats->tx_bytes += bytes;
462 rx_ring = &tx_ring[1];
463
464 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700465 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000466 packets = rx_ring->stats.packets;
467 bytes = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700468 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000469
470 stats->rx_packets += packets;
471 stats->rx_bytes += bytes;
472 }
473 rcu_read_unlock();
474
Akeem G Abodunrina5282f42014-05-10 04:49:03 +0000475 /* following stats updated by i40e_watchdog_subtask() */
Alexander Duyck980e9b12013-09-28 06:01:03 +0000476 stats->multicast = vsi_stats->multicast;
477 stats->tx_errors = vsi_stats->tx_errors;
478 stats->tx_dropped = vsi_stats->tx_dropped;
479 stats->rx_errors = vsi_stats->rx_errors;
Jesse Brandeburgd8201e22015-07-23 16:54:35 -0400480 stats->rx_dropped = vsi_stats->rx_dropped;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000481 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
482 stats->rx_length_errors = vsi_stats->rx_length_errors;
483
484 return stats;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000485}
486
487/**
488 * i40e_vsi_reset_stats - Resets all stats of the given vsi
489 * @vsi: the VSI to have its stats reset
490 **/
491void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
492{
493 struct rtnl_link_stats64 *ns;
494 int i;
495
496 if (!vsi)
497 return;
498
499 ns = i40e_get_vsi_stats_struct(vsi);
500 memset(ns, 0, sizeof(*ns));
501 memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
502 memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
503 memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
Greg Rose8e9dca52013-12-18 13:45:53 +0000504 if (vsi->rx_rings && vsi->rx_rings[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000505 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400506 memset(&vsi->rx_rings[i]->stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000507 sizeof(vsi->rx_rings[i]->stats));
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400508 memset(&vsi->rx_rings[i]->rx_stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000509 sizeof(vsi->rx_rings[i]->rx_stats));
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400510 memset(&vsi->tx_rings[i]->stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000511 sizeof(vsi->tx_rings[i]->stats));
512 memset(&vsi->tx_rings[i]->tx_stats, 0,
513 sizeof(vsi->tx_rings[i]->tx_stats));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000514 }
Greg Rose8e9dca52013-12-18 13:45:53 +0000515 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000516 vsi->stat_offsets_loaded = false;
517}
518
519/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +0000520 * i40e_pf_reset_stats - Reset all of the stats for the given PF
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000521 * @pf: the PF to be reset
522 **/
523void i40e_pf_reset_stats(struct i40e_pf *pf)
524{
Shannon Nelsone91fdf72014-06-03 23:50:18 +0000525 int i;
526
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000527 memset(&pf->stats, 0, sizeof(pf->stats));
528 memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
529 pf->stat_offsets_loaded = false;
Shannon Nelsone91fdf72014-06-03 23:50:18 +0000530
531 for (i = 0; i < I40E_MAX_VEB; i++) {
532 if (pf->veb[i]) {
533 memset(&pf->veb[i]->stats, 0,
534 sizeof(pf->veb[i]->stats));
535 memset(&pf->veb[i]->stats_offsets, 0,
536 sizeof(pf->veb[i]->stats_offsets));
537 pf->veb[i]->stat_offsets_loaded = false;
538 }
539 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000540}
541
542/**
543 * i40e_stat_update48 - read and update a 48 bit stat from the chip
544 * @hw: ptr to the hardware info
545 * @hireg: the high 32 bit reg to read
546 * @loreg: the low 32 bit reg to read
547 * @offset_loaded: has the initial offset been loaded yet
548 * @offset: ptr to current offset value
549 * @stat: ptr to the stat
550 *
551 * Since the device stats are not reset at PFReset, they likely will not
552 * be zeroed when the driver starts. We'll save the first values read
553 * and use them as offsets to be subtracted from the raw values in order
554 * to report stats that count from zero. In the process, we also manage
555 * the potential roll-over.
556 **/
557static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
558 bool offset_loaded, u64 *offset, u64 *stat)
559{
560 u64 new_data;
561
Shannon Nelsonab600852014-01-17 15:36:39 -0800562 if (hw->device_id == I40E_DEV_ID_QEMU) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000563 new_data = rd32(hw, loreg);
564 new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
565 } else {
566 new_data = rd64(hw, loreg);
567 }
568 if (!offset_loaded)
569 *offset = new_data;
570 if (likely(new_data >= *offset))
571 *stat = new_data - *offset;
572 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400573 *stat = (new_data + BIT_ULL(48)) - *offset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000574 *stat &= 0xFFFFFFFFFFFFULL;
575}
576
577/**
578 * i40e_stat_update32 - read and update a 32 bit stat from the chip
579 * @hw: ptr to the hardware info
580 * @reg: the hw reg to read
581 * @offset_loaded: has the initial offset been loaded yet
582 * @offset: ptr to current offset value
583 * @stat: ptr to the stat
584 **/
585static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
586 bool offset_loaded, u64 *offset, u64 *stat)
587{
588 u32 new_data;
589
590 new_data = rd32(hw, reg);
591 if (!offset_loaded)
592 *offset = new_data;
593 if (likely(new_data >= *offset))
594 *stat = (u32)(new_data - *offset);
595 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400596 *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000597}
598
599/**
600 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
601 * @vsi: the VSI to be updated
602 **/
603void i40e_update_eth_stats(struct i40e_vsi *vsi)
604{
605 int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
606 struct i40e_pf *pf = vsi->back;
607 struct i40e_hw *hw = &pf->hw;
608 struct i40e_eth_stats *oes;
609 struct i40e_eth_stats *es; /* device's eth stats */
610
611 es = &vsi->eth_stats;
612 oes = &vsi->eth_stats_offsets;
613
614 /* Gather up the stats that the hw collects */
615 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
616 vsi->stat_offsets_loaded,
617 &oes->tx_errors, &es->tx_errors);
618 i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
619 vsi->stat_offsets_loaded,
620 &oes->rx_discards, &es->rx_discards);
Shannon Nelson41a9e552014-04-23 04:50:20 +0000621 i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
622 vsi->stat_offsets_loaded,
623 &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
624 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
625 vsi->stat_offsets_loaded,
626 &oes->tx_errors, &es->tx_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000627
628 i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
629 I40E_GLV_GORCL(stat_idx),
630 vsi->stat_offsets_loaded,
631 &oes->rx_bytes, &es->rx_bytes);
632 i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
633 I40E_GLV_UPRCL(stat_idx),
634 vsi->stat_offsets_loaded,
635 &oes->rx_unicast, &es->rx_unicast);
636 i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
637 I40E_GLV_MPRCL(stat_idx),
638 vsi->stat_offsets_loaded,
639 &oes->rx_multicast, &es->rx_multicast);
640 i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
641 I40E_GLV_BPRCL(stat_idx),
642 vsi->stat_offsets_loaded,
643 &oes->rx_broadcast, &es->rx_broadcast);
644
645 i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
646 I40E_GLV_GOTCL(stat_idx),
647 vsi->stat_offsets_loaded,
648 &oes->tx_bytes, &es->tx_bytes);
649 i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
650 I40E_GLV_UPTCL(stat_idx),
651 vsi->stat_offsets_loaded,
652 &oes->tx_unicast, &es->tx_unicast);
653 i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
654 I40E_GLV_MPTCL(stat_idx),
655 vsi->stat_offsets_loaded,
656 &oes->tx_multicast, &es->tx_multicast);
657 i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
658 I40E_GLV_BPTCL(stat_idx),
659 vsi->stat_offsets_loaded,
660 &oes->tx_broadcast, &es->tx_broadcast);
661 vsi->stat_offsets_loaded = true;
662}
663
664/**
665 * i40e_update_veb_stats - Update Switch component statistics
666 * @veb: the VEB being updated
667 **/
668static void i40e_update_veb_stats(struct i40e_veb *veb)
669{
670 struct i40e_pf *pf = veb->pf;
671 struct i40e_hw *hw = &pf->hw;
672 struct i40e_eth_stats *oes;
673 struct i40e_eth_stats *es; /* device's eth stats */
Neerav Parikhfe860af2015-07-10 19:36:02 -0400674 struct i40e_veb_tc_stats *veb_oes;
675 struct i40e_veb_tc_stats *veb_es;
676 int i, idx = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000677
678 idx = veb->stats_idx;
679 es = &veb->stats;
680 oes = &veb->stats_offsets;
Neerav Parikhfe860af2015-07-10 19:36:02 -0400681 veb_es = &veb->tc_stats;
682 veb_oes = &veb->tc_stats_offsets;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000683
684 /* Gather up the stats that the hw collects */
685 i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
686 veb->stat_offsets_loaded,
687 &oes->tx_discards, &es->tx_discards);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000688 if (hw->revision_id > 0)
689 i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
690 veb->stat_offsets_loaded,
691 &oes->rx_unknown_protocol,
692 &es->rx_unknown_protocol);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000693 i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
694 veb->stat_offsets_loaded,
695 &oes->rx_bytes, &es->rx_bytes);
696 i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
697 veb->stat_offsets_loaded,
698 &oes->rx_unicast, &es->rx_unicast);
699 i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
700 veb->stat_offsets_loaded,
701 &oes->rx_multicast, &es->rx_multicast);
702 i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
703 veb->stat_offsets_loaded,
704 &oes->rx_broadcast, &es->rx_broadcast);
705
706 i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
707 veb->stat_offsets_loaded,
708 &oes->tx_bytes, &es->tx_bytes);
709 i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
710 veb->stat_offsets_loaded,
711 &oes->tx_unicast, &es->tx_unicast);
712 i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
713 veb->stat_offsets_loaded,
714 &oes->tx_multicast, &es->tx_multicast);
715 i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
716 veb->stat_offsets_loaded,
717 &oes->tx_broadcast, &es->tx_broadcast);
Neerav Parikhfe860af2015-07-10 19:36:02 -0400718 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
719 i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
720 I40E_GLVEBTC_RPCL(i, idx),
721 veb->stat_offsets_loaded,
722 &veb_oes->tc_rx_packets[i],
723 &veb_es->tc_rx_packets[i]);
724 i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
725 I40E_GLVEBTC_RBCL(i, idx),
726 veb->stat_offsets_loaded,
727 &veb_oes->tc_rx_bytes[i],
728 &veb_es->tc_rx_bytes[i]);
729 i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
730 I40E_GLVEBTC_TPCL(i, idx),
731 veb->stat_offsets_loaded,
732 &veb_oes->tc_tx_packets[i],
733 &veb_es->tc_tx_packets[i]);
734 i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
735 I40E_GLVEBTC_TBCL(i, idx),
736 veb->stat_offsets_loaded,
737 &veb_oes->tc_tx_bytes[i],
738 &veb_es->tc_tx_bytes[i]);
739 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000740 veb->stat_offsets_loaded = true;
741}
742
Vasu Dev38e00432014-08-01 13:27:03 -0700743#ifdef I40E_FCOE
744/**
745 * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
746 * @vsi: the VSI that is capable of doing FCoE
747 **/
748static void i40e_update_fcoe_stats(struct i40e_vsi *vsi)
749{
750 struct i40e_pf *pf = vsi->back;
751 struct i40e_hw *hw = &pf->hw;
752 struct i40e_fcoe_stats *ofs;
753 struct i40e_fcoe_stats *fs; /* device's eth stats */
754 int idx;
755
756 if (vsi->type != I40E_VSI_FCOE)
757 return;
758
759 idx = (pf->pf_seid - I40E_BASE_PF_SEID) + I40E_FCOE_PF_STAT_OFFSET;
760 fs = &vsi->fcoe_stats;
761 ofs = &vsi->fcoe_stats_offsets;
762
763 i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx),
764 vsi->fcoe_stat_offsets_loaded,
765 &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets);
766 i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx),
767 vsi->fcoe_stat_offsets_loaded,
768 &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords);
769 i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx),
770 vsi->fcoe_stat_offsets_loaded,
771 &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped);
772 i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx),
773 vsi->fcoe_stat_offsets_loaded,
774 &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets);
775 i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx),
776 vsi->fcoe_stat_offsets_loaded,
777 &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords);
778 i40e_stat_update32(hw, I40E_GL_FCOECRC(idx),
779 vsi->fcoe_stat_offsets_loaded,
780 &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc);
781 i40e_stat_update32(hw, I40E_GL_FCOELAST(idx),
782 vsi->fcoe_stat_offsets_loaded,
783 &ofs->fcoe_last_error, &fs->fcoe_last_error);
784 i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx),
785 vsi->fcoe_stat_offsets_loaded,
786 &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count);
787
788 vsi->fcoe_stat_offsets_loaded = true;
789}
790
791#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000792/**
793 * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode
794 * @pf: the corresponding PF
795 *
796 * Update the Rx XOFF counter (PAUSE frames) in link flow control mode
797 **/
798static void i40e_update_link_xoff_rx(struct i40e_pf *pf)
799{
800 struct i40e_hw_port_stats *osd = &pf->stats_offsets;
801 struct i40e_hw_port_stats *nsd = &pf->stats;
802 struct i40e_hw *hw = &pf->hw;
803 u64 xoff = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000804
805 if ((hw->fc.current_mode != I40E_FC_FULL) &&
806 (hw->fc.current_mode != I40E_FC_RX_PAUSE))
807 return;
808
809 xoff = nsd->link_xoff_rx;
810 i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
811 pf->stat_offsets_loaded,
812 &osd->link_xoff_rx, &nsd->link_xoff_rx);
813
814 /* No new LFC xoff rx */
815 if (!(nsd->link_xoff_rx - xoff))
816 return;
817
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000818}
819
820/**
821 * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode
822 * @pf: the corresponding PF
823 *
824 * Update the Rx XOFF counter (PAUSE frames) in PFC mode
825 **/
826static void i40e_update_prio_xoff_rx(struct i40e_pf *pf)
827{
828 struct i40e_hw_port_stats *osd = &pf->stats_offsets;
829 struct i40e_hw_port_stats *nsd = &pf->stats;
830 bool xoff[I40E_MAX_TRAFFIC_CLASS] = {false};
831 struct i40e_dcbx_config *dcb_cfg;
832 struct i40e_hw *hw = &pf->hw;
Kiran Patilb03a8c12015-09-24 18:13:15 -0400833 u16 i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000834 u8 tc;
835
836 dcb_cfg = &hw->local_dcbx_config;
837
Neerav Parikhe1208142015-04-16 20:05:58 -0400838 /* Collect Link XOFF stats when PFC is disabled */
839 if (!dcb_cfg->pfc.pfcenable) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000840 i40e_update_link_xoff_rx(pf);
841 return;
842 }
843
844 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
845 u64 prio_xoff = nsd->priority_xoff_rx[i];
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400846
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000847 i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
848 pf->stat_offsets_loaded,
849 &osd->priority_xoff_rx[i],
850 &nsd->priority_xoff_rx[i]);
851
852 /* No new PFC xoff rx */
853 if (!(nsd->priority_xoff_rx[i] - prio_xoff))
854 continue;
855 /* Get the TC for given priority */
856 tc = dcb_cfg->etscfg.prioritytable[i];
857 xoff[tc] = true;
858 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000859}
860
861/**
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000862 * i40e_update_vsi_stats - Update the vsi statistics counters.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000863 * @vsi: the VSI to be updated
864 *
865 * There are a few instances where we store the same stat in a
866 * couple of different structs. This is partly because we have
867 * the netdev stats that need to be filled out, which is slightly
868 * different from the "eth_stats" defined by the chip and used in
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000869 * VF communications. We sort it out here.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000870 **/
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000871static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000872{
873 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000874 struct rtnl_link_stats64 *ons;
875 struct rtnl_link_stats64 *ns; /* netdev stats */
876 struct i40e_eth_stats *oes;
877 struct i40e_eth_stats *es; /* device's eth stats */
878 u32 tx_restart, tx_busy;
Akeem G Abodunrinbf00b372014-10-17 03:14:39 +0000879 struct i40e_ring *p;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000880 u32 rx_page, rx_buf;
Akeem G Abodunrinbf00b372014-10-17 03:14:39 +0000881 u64 bytes, packets;
882 unsigned int start;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400883 u64 tx_linearize;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000884 u64 rx_p, rx_b;
885 u64 tx_p, tx_b;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000886 u16 q;
887
888 if (test_bit(__I40E_DOWN, &vsi->state) ||
889 test_bit(__I40E_CONFIG_BUSY, &pf->state))
890 return;
891
892 ns = i40e_get_vsi_stats_struct(vsi);
893 ons = &vsi->net_stats_offsets;
894 es = &vsi->eth_stats;
895 oes = &vsi->eth_stats_offsets;
896
897 /* Gather up the netdev and vsi stats that the driver collects
898 * on the fly during packet processing
899 */
900 rx_b = rx_p = 0;
901 tx_b = tx_p = 0;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400902 tx_restart = tx_busy = tx_linearize = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000903 rx_page = 0;
904 rx_buf = 0;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000905 rcu_read_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000906 for (q = 0; q < vsi->num_queue_pairs; q++) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000907 /* locate Tx ring */
908 p = ACCESS_ONCE(vsi->tx_rings[q]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000909
Alexander Duyck980e9b12013-09-28 06:01:03 +0000910 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700911 start = u64_stats_fetch_begin_irq(&p->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000912 packets = p->stats.packets;
913 bytes = p->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700914 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000915 tx_b += bytes;
916 tx_p += packets;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000917 tx_restart += p->tx_stats.restart_queue;
918 tx_busy += p->tx_stats.tx_busy;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400919 tx_linearize += p->tx_stats.tx_linearize;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000920
921 /* Rx queue is part of the same block as Tx queue */
922 p = &p[1];
923 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700924 start = u64_stats_fetch_begin_irq(&p->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000925 packets = p->stats.packets;
926 bytes = p->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700927 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000928 rx_b += bytes;
929 rx_p += packets;
Mitch Williams420136c2013-12-18 13:45:59 +0000930 rx_buf += p->rx_stats.alloc_buff_failed;
931 rx_page += p->rx_stats.alloc_page_failed;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000932 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000933 rcu_read_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000934 vsi->tx_restart = tx_restart;
935 vsi->tx_busy = tx_busy;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400936 vsi->tx_linearize = tx_linearize;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000937 vsi->rx_page_failed = rx_page;
938 vsi->rx_buf_failed = rx_buf;
939
940 ns->rx_packets = rx_p;
941 ns->rx_bytes = rx_b;
942 ns->tx_packets = tx_p;
943 ns->tx_bytes = tx_b;
944
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000945 /* update netdev stats from eth stats */
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000946 i40e_update_eth_stats(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000947 ons->tx_errors = oes->tx_errors;
948 ns->tx_errors = es->tx_errors;
949 ons->multicast = oes->rx_multicast;
950 ns->multicast = es->rx_multicast;
Shannon Nelson41a9e552014-04-23 04:50:20 +0000951 ons->rx_dropped = oes->rx_discards;
952 ns->rx_dropped = es->rx_discards;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000953 ons->tx_dropped = oes->tx_discards;
954 ns->tx_dropped = es->tx_discards;
955
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000956 /* pull in a couple PF stats if this is the main vsi */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000957 if (vsi == pf->vsi[pf->lan_vsi]) {
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000958 ns->rx_crc_errors = pf->stats.crc_errors;
959 ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
960 ns->rx_length_errors = pf->stats.rx_length_errors;
961 }
962}
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000963
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000964/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +0000965 * i40e_update_pf_stats - Update the PF statistics counters.
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000966 * @pf: the PF to be updated
967 **/
968static void i40e_update_pf_stats(struct i40e_pf *pf)
969{
970 struct i40e_hw_port_stats *osd = &pf->stats_offsets;
971 struct i40e_hw_port_stats *nsd = &pf->stats;
972 struct i40e_hw *hw = &pf->hw;
973 u32 val;
974 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000975
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000976 i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
977 I40E_GLPRT_GORCL(hw->port),
978 pf->stat_offsets_loaded,
979 &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
980 i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
981 I40E_GLPRT_GOTCL(hw->port),
982 pf->stat_offsets_loaded,
983 &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
984 i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
985 pf->stat_offsets_loaded,
986 &osd->eth.rx_discards,
987 &nsd->eth.rx_discards);
Shannon Nelson532d2832014-04-23 04:50:09 +0000988 i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
989 I40E_GLPRT_UPRCL(hw->port),
990 pf->stat_offsets_loaded,
991 &osd->eth.rx_unicast,
992 &nsd->eth.rx_unicast);
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000993 i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
994 I40E_GLPRT_MPRCL(hw->port),
995 pf->stat_offsets_loaded,
996 &osd->eth.rx_multicast,
997 &nsd->eth.rx_multicast);
Shannon Nelson532d2832014-04-23 04:50:09 +0000998 i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
999 I40E_GLPRT_BPRCL(hw->port),
1000 pf->stat_offsets_loaded,
1001 &osd->eth.rx_broadcast,
1002 &nsd->eth.rx_broadcast);
1003 i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
1004 I40E_GLPRT_UPTCL(hw->port),
1005 pf->stat_offsets_loaded,
1006 &osd->eth.tx_unicast,
1007 &nsd->eth.tx_unicast);
1008 i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
1009 I40E_GLPRT_MPTCL(hw->port),
1010 pf->stat_offsets_loaded,
1011 &osd->eth.tx_multicast,
1012 &nsd->eth.tx_multicast);
1013 i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
1014 I40E_GLPRT_BPTCL(hw->port),
1015 pf->stat_offsets_loaded,
1016 &osd->eth.tx_broadcast,
1017 &nsd->eth.tx_broadcast);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001018
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001019 i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
1020 pf->stat_offsets_loaded,
1021 &osd->tx_dropped_link_down,
1022 &nsd->tx_dropped_link_down);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001023
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001024 i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
1025 pf->stat_offsets_loaded,
1026 &osd->crc_errors, &nsd->crc_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001027
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001028 i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
1029 pf->stat_offsets_loaded,
1030 &osd->illegal_bytes, &nsd->illegal_bytes);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001031
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001032 i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
1033 pf->stat_offsets_loaded,
1034 &osd->mac_local_faults,
1035 &nsd->mac_local_faults);
1036 i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
1037 pf->stat_offsets_loaded,
1038 &osd->mac_remote_faults,
1039 &nsd->mac_remote_faults);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001040
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001041 i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
1042 pf->stat_offsets_loaded,
1043 &osd->rx_length_errors,
1044 &nsd->rx_length_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001045
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001046 i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
1047 pf->stat_offsets_loaded,
1048 &osd->link_xon_rx, &nsd->link_xon_rx);
1049 i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
1050 pf->stat_offsets_loaded,
1051 &osd->link_xon_tx, &nsd->link_xon_tx);
1052 i40e_update_prio_xoff_rx(pf); /* handles I40E_GLPRT_LXOFFRXC */
1053 i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
1054 pf->stat_offsets_loaded,
1055 &osd->link_xoff_tx, &nsd->link_xoff_tx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001056
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001057 for (i = 0; i < 8; i++) {
1058 i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001059 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001060 &osd->priority_xon_rx[i],
1061 &nsd->priority_xon_rx[i]);
1062 i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001063 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001064 &osd->priority_xon_tx[i],
1065 &nsd->priority_xon_tx[i]);
1066 i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001067 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001068 &osd->priority_xoff_tx[i],
1069 &nsd->priority_xoff_tx[i]);
1070 i40e_stat_update32(hw,
1071 I40E_GLPRT_RXON2OFFCNT(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001072 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001073 &osd->priority_xon_2_xoff[i],
1074 &nsd->priority_xon_2_xoff[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001075 }
1076
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001077 i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
1078 I40E_GLPRT_PRC64L(hw->port),
1079 pf->stat_offsets_loaded,
1080 &osd->rx_size_64, &nsd->rx_size_64);
1081 i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
1082 I40E_GLPRT_PRC127L(hw->port),
1083 pf->stat_offsets_loaded,
1084 &osd->rx_size_127, &nsd->rx_size_127);
1085 i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
1086 I40E_GLPRT_PRC255L(hw->port),
1087 pf->stat_offsets_loaded,
1088 &osd->rx_size_255, &nsd->rx_size_255);
1089 i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
1090 I40E_GLPRT_PRC511L(hw->port),
1091 pf->stat_offsets_loaded,
1092 &osd->rx_size_511, &nsd->rx_size_511);
1093 i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
1094 I40E_GLPRT_PRC1023L(hw->port),
1095 pf->stat_offsets_loaded,
1096 &osd->rx_size_1023, &nsd->rx_size_1023);
1097 i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
1098 I40E_GLPRT_PRC1522L(hw->port),
1099 pf->stat_offsets_loaded,
1100 &osd->rx_size_1522, &nsd->rx_size_1522);
1101 i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
1102 I40E_GLPRT_PRC9522L(hw->port),
1103 pf->stat_offsets_loaded,
1104 &osd->rx_size_big, &nsd->rx_size_big);
1105
1106 i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
1107 I40E_GLPRT_PTC64L(hw->port),
1108 pf->stat_offsets_loaded,
1109 &osd->tx_size_64, &nsd->tx_size_64);
1110 i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
1111 I40E_GLPRT_PTC127L(hw->port),
1112 pf->stat_offsets_loaded,
1113 &osd->tx_size_127, &nsd->tx_size_127);
1114 i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
1115 I40E_GLPRT_PTC255L(hw->port),
1116 pf->stat_offsets_loaded,
1117 &osd->tx_size_255, &nsd->tx_size_255);
1118 i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
1119 I40E_GLPRT_PTC511L(hw->port),
1120 pf->stat_offsets_loaded,
1121 &osd->tx_size_511, &nsd->tx_size_511);
1122 i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
1123 I40E_GLPRT_PTC1023L(hw->port),
1124 pf->stat_offsets_loaded,
1125 &osd->tx_size_1023, &nsd->tx_size_1023);
1126 i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
1127 I40E_GLPRT_PTC1522L(hw->port),
1128 pf->stat_offsets_loaded,
1129 &osd->tx_size_1522, &nsd->tx_size_1522);
1130 i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
1131 I40E_GLPRT_PTC9522L(hw->port),
1132 pf->stat_offsets_loaded,
1133 &osd->tx_size_big, &nsd->tx_size_big);
1134
1135 i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
1136 pf->stat_offsets_loaded,
1137 &osd->rx_undersize, &nsd->rx_undersize);
1138 i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
1139 pf->stat_offsets_loaded,
1140 &osd->rx_fragments, &nsd->rx_fragments);
1141 i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
1142 pf->stat_offsets_loaded,
1143 &osd->rx_oversize, &nsd->rx_oversize);
1144 i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
1145 pf->stat_offsets_loaded,
1146 &osd->rx_jabber, &nsd->rx_jabber);
1147
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001148 /* FDIR stats */
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04001149 i40e_stat_update32(hw,
1150 I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001151 pf->stat_offsets_loaded,
1152 &osd->fd_atr_match, &nsd->fd_atr_match);
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04001153 i40e_stat_update32(hw,
1154 I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001155 pf->stat_offsets_loaded,
1156 &osd->fd_sb_match, &nsd->fd_sb_match);
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -04001157 i40e_stat_update32(hw,
1158 I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)),
1159 pf->stat_offsets_loaded,
1160 &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match);
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001161
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001162 val = rd32(hw, I40E_PRTPM_EEE_STAT);
1163 nsd->tx_lpi_status =
1164 (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
1165 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
1166 nsd->rx_lpi_status =
1167 (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
1168 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
1169 i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
1170 pf->stat_offsets_loaded,
1171 &osd->tx_lpi_count, &nsd->tx_lpi_count);
1172 i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
1173 pf->stat_offsets_loaded,
1174 &osd->rx_lpi_count, &nsd->rx_lpi_count);
1175
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -04001176 if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
1177 !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED))
1178 nsd->fd_sb_status = true;
1179 else
1180 nsd->fd_sb_status = false;
1181
1182 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
1183 !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
1184 nsd->fd_atr_status = true;
1185 else
1186 nsd->fd_atr_status = false;
1187
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001188 pf->stat_offsets_loaded = true;
1189}
1190
1191/**
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001192 * i40e_update_stats - Update the various statistics counters.
1193 * @vsi: the VSI to be updated
1194 *
1195 * Update the various stats for this VSI and its related entities.
1196 **/
1197void i40e_update_stats(struct i40e_vsi *vsi)
1198{
1199 struct i40e_pf *pf = vsi->back;
1200
1201 if (vsi == pf->vsi[pf->lan_vsi])
1202 i40e_update_pf_stats(pf);
1203
1204 i40e_update_vsi_stats(vsi);
Vasu Dev38e00432014-08-01 13:27:03 -07001205#ifdef I40E_FCOE
1206 i40e_update_fcoe_stats(vsi);
1207#endif
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001208}
1209
1210/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001211 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1212 * @vsi: the VSI to be searched
1213 * @macaddr: the MAC address
1214 * @vlan: the vlan
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001215 * @is_vf: make sure its a VF filter, else doesn't matter
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001216 * @is_netdev: make sure its a netdev filter, else doesn't matter
1217 *
1218 * Returns ptr to the filter object or NULL
1219 **/
1220static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
1221 u8 *macaddr, s16 vlan,
1222 bool is_vf, bool is_netdev)
1223{
1224 struct i40e_mac_filter *f;
1225
1226 if (!vsi || !macaddr)
1227 return NULL;
1228
1229 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1230 if ((ether_addr_equal(macaddr, f->macaddr)) &&
1231 (vlan == f->vlan) &&
1232 (!is_vf || f->is_vf) &&
1233 (!is_netdev || f->is_netdev))
1234 return f;
1235 }
1236 return NULL;
1237}
1238
1239/**
1240 * i40e_find_mac - Find a mac addr in the macvlan filters list
1241 * @vsi: the VSI to be searched
1242 * @macaddr: the MAC address we are searching for
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001243 * @is_vf: make sure its a VF filter, else doesn't matter
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001244 * @is_netdev: make sure its a netdev filter, else doesn't matter
1245 *
1246 * Returns the first filter with the provided MAC address or NULL if
1247 * MAC address was not found
1248 **/
1249struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr,
1250 bool is_vf, bool is_netdev)
1251{
1252 struct i40e_mac_filter *f;
1253
1254 if (!vsi || !macaddr)
1255 return NULL;
1256
1257 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1258 if ((ether_addr_equal(macaddr, f->macaddr)) &&
1259 (!is_vf || f->is_vf) &&
1260 (!is_netdev || f->is_netdev))
1261 return f;
1262 }
1263 return NULL;
1264}
1265
1266/**
1267 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1268 * @vsi: the VSI to be searched
1269 *
1270 * Returns true if VSI is in vlan mode or false otherwise
1271 **/
1272bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
1273{
1274 struct i40e_mac_filter *f;
1275
1276 /* Only -1 for all the filters denotes not in vlan mode
1277 * so we have to go through all the list in order to make sure
1278 */
1279 list_for_each_entry(f, &vsi->mac_filter_list, list) {
Greg Rosed9b68f82015-07-23 16:54:31 -04001280 if (f->vlan >= 0 || vsi->info.pvid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001281 return true;
1282 }
1283
1284 return false;
1285}
1286
1287/**
1288 * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
1289 * @vsi: the VSI to be searched
1290 * @macaddr: the mac address to be filtered
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001291 * @is_vf: true if it is a VF
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001292 * @is_netdev: true if it is a netdev
1293 *
1294 * Goes through all the macvlan filters and adds a
1295 * macvlan filter for each unique vlan that already exists
1296 *
1297 * Returns first filter found on success, else NULL
1298 **/
1299struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr,
1300 bool is_vf, bool is_netdev)
1301{
1302 struct i40e_mac_filter *f;
1303
1304 list_for_each_entry(f, &vsi->mac_filter_list, list) {
Mitch Williamsecbb44e2015-07-10 19:35:56 -04001305 if (vsi->info.pvid)
1306 f->vlan = le16_to_cpu(vsi->info.pvid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001307 if (!i40e_find_filter(vsi, macaddr, f->vlan,
1308 is_vf, is_netdev)) {
1309 if (!i40e_add_filter(vsi, macaddr, f->vlan,
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08001310 is_vf, is_netdev))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001311 return NULL;
1312 }
1313 }
1314
1315 return list_first_entry_or_null(&vsi->mac_filter_list,
1316 struct i40e_mac_filter, list);
1317}
1318
1319/**
Greg Rose8c27d422014-05-22 06:31:56 +00001320 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1321 * @vsi: the PF Main VSI - inappropriate for any other VSI
1322 * @macaddr: the MAC address
Shannon Nelson30650cc2014-07-29 04:01:50 +00001323 *
1324 * Some older firmware configurations set up a default promiscuous VLAN
1325 * filter that needs to be removed.
Greg Rose8c27d422014-05-22 06:31:56 +00001326 **/
Shannon Nelson30650cc2014-07-29 04:01:50 +00001327static int i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
Greg Rose8c27d422014-05-22 06:31:56 +00001328{
1329 struct i40e_aqc_remove_macvlan_element_data element;
1330 struct i40e_pf *pf = vsi->back;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001331 i40e_status ret;
Greg Rose8c27d422014-05-22 06:31:56 +00001332
1333 /* Only appropriate for the PF main VSI */
1334 if (vsi->type != I40E_VSI_MAIN)
Shannon Nelson30650cc2014-07-29 04:01:50 +00001335 return -EINVAL;
Greg Rose8c27d422014-05-22 06:31:56 +00001336
Shannon Nelson30650cc2014-07-29 04:01:50 +00001337 memset(&element, 0, sizeof(element));
Greg Rose8c27d422014-05-22 06:31:56 +00001338 ether_addr_copy(element.mac_addr, macaddr);
1339 element.vlan_tag = 0;
1340 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
1341 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001342 ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1343 if (ret)
Shannon Nelson30650cc2014-07-29 04:01:50 +00001344 return -ENOENT;
1345
1346 return 0;
Greg Rose8c27d422014-05-22 06:31:56 +00001347}
1348
1349/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001350 * i40e_add_filter - Add a mac/vlan filter to the VSI
1351 * @vsi: the VSI to be searched
1352 * @macaddr: the MAC address
1353 * @vlan: the vlan
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001354 * @is_vf: make sure its a VF filter, else doesn't matter
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001355 * @is_netdev: make sure its a netdev filter, else doesn't matter
1356 *
1357 * Returns ptr to the filter object or NULL when no memory available.
Kiran Patil21659032015-09-30 14:09:03 -04001358 *
1359 * NOTE: This function is expected to be called with mac_filter_list_lock
1360 * being held.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001361 **/
1362struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
1363 u8 *macaddr, s16 vlan,
1364 bool is_vf, bool is_netdev)
1365{
1366 struct i40e_mac_filter *f;
1367
1368 if (!vsi || !macaddr)
1369 return NULL;
1370
1371 f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
1372 if (!f) {
1373 f = kzalloc(sizeof(*f), GFP_ATOMIC);
1374 if (!f)
1375 goto add_filter_out;
1376
Greg Rose9a173902014-05-22 06:32:02 +00001377 ether_addr_copy(f->macaddr, macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001378 f->vlan = vlan;
1379 f->changed = true;
1380
1381 INIT_LIST_HEAD(&f->list);
1382 list_add(&f->list, &vsi->mac_filter_list);
1383 }
1384
1385 /* increment counter and add a new flag if needed */
1386 if (is_vf) {
1387 if (!f->is_vf) {
1388 f->is_vf = true;
1389 f->counter++;
1390 }
1391 } else if (is_netdev) {
1392 if (!f->is_netdev) {
1393 f->is_netdev = true;
1394 f->counter++;
1395 }
1396 } else {
1397 f->counter++;
1398 }
1399
1400 /* changed tells sync_filters_subtask to
1401 * push the filter down to the firmware
1402 */
1403 if (f->changed) {
1404 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1405 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1406 }
1407
1408add_filter_out:
1409 return f;
1410}
1411
1412/**
1413 * i40e_del_filter - Remove a mac/vlan filter from the VSI
1414 * @vsi: the VSI to be searched
1415 * @macaddr: the MAC address
1416 * @vlan: the vlan
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001417 * @is_vf: make sure it's a VF filter, else doesn't matter
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001418 * @is_netdev: make sure it's a netdev filter, else doesn't matter
Kiran Patil21659032015-09-30 14:09:03 -04001419 *
1420 * NOTE: This function is expected to be called with mac_filter_list_lock
1421 * being held.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001422 **/
1423void i40e_del_filter(struct i40e_vsi *vsi,
1424 u8 *macaddr, s16 vlan,
1425 bool is_vf, bool is_netdev)
1426{
1427 struct i40e_mac_filter *f;
1428
1429 if (!vsi || !macaddr)
1430 return;
1431
1432 f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
1433 if (!f || f->counter == 0)
1434 return;
1435
1436 if (is_vf) {
1437 if (f->is_vf) {
1438 f->is_vf = false;
1439 f->counter--;
1440 }
1441 } else if (is_netdev) {
1442 if (f->is_netdev) {
1443 f->is_netdev = false;
1444 f->counter--;
1445 }
1446 } else {
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00001447 /* make sure we don't remove a filter in use by VF or netdev */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001448 int min_f = 0;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001449
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001450 min_f += (f->is_vf ? 1 : 0);
1451 min_f += (f->is_netdev ? 1 : 0);
1452
1453 if (f->counter > min_f)
1454 f->counter--;
1455 }
1456
1457 /* counter == 0 tells sync_filters_subtask to
1458 * remove the filter from the firmware's list
1459 */
1460 if (f->counter == 0) {
1461 f->changed = true;
1462 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1463 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1464 }
1465}
1466
1467/**
1468 * i40e_set_mac - NDO callback to set mac address
1469 * @netdev: network interface device structure
1470 * @p: pointer to an address structure
1471 *
1472 * Returns 0 on success, negative on failure
1473 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001474#ifdef I40E_FCOE
1475int i40e_set_mac(struct net_device *netdev, void *p)
1476#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001477static int i40e_set_mac(struct net_device *netdev, void *p)
Vasu Dev38e00432014-08-01 13:27:03 -07001478#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001479{
1480 struct i40e_netdev_priv *np = netdev_priv(netdev);
1481 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson30650cc2014-07-29 04:01:50 +00001482 struct i40e_pf *pf = vsi->back;
1483 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001484 struct sockaddr *addr = p;
1485 struct i40e_mac_filter *f;
1486
1487 if (!is_valid_ether_addr(addr->sa_data))
1488 return -EADDRNOTAVAIL;
1489
Shannon Nelson30650cc2014-07-29 04:01:50 +00001490 if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
1491 netdev_info(netdev, "already using mac address %pM\n",
1492 addr->sa_data);
1493 return 0;
1494 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001495
Anjali Singhai Jain80f64282013-11-28 06:39:47 +00001496 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
1497 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
1498 return -EADDRNOTAVAIL;
1499
Shannon Nelson30650cc2014-07-29 04:01:50 +00001500 if (ether_addr_equal(hw->mac.addr, addr->sa_data))
1501 netdev_info(netdev, "returning to hw mac address %pM\n",
1502 hw->mac.addr);
1503 else
1504 netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
1505
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001506 if (vsi->type == I40E_VSI_MAIN) {
1507 i40e_status ret;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001508
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001509 ret = i40e_aq_mac_address_write(&vsi->back->hw,
Shannon Nelsoncc412222014-06-04 01:23:21 +00001510 I40E_AQC_WRITE_TYPE_LAA_WOL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001511 addr->sa_data, NULL);
1512 if (ret) {
1513 netdev_info(netdev,
1514 "Addr change for Main VSI failed: %d\n",
1515 ret);
1516 return -EADDRNOTAVAIL;
1517 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001518 }
1519
Shannon Nelson30650cc2014-07-29 04:01:50 +00001520 if (ether_addr_equal(netdev->dev_addr, hw->mac.addr)) {
1521 struct i40e_aqc_remove_macvlan_element_data element;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001522
Shannon Nelson30650cc2014-07-29 04:01:50 +00001523 memset(&element, 0, sizeof(element));
1524 ether_addr_copy(element.mac_addr, netdev->dev_addr);
1525 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
1526 i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1527 } else {
Kiran Patil21659032015-09-30 14:09:03 -04001528 spin_lock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson6c8ad1b2014-06-04 01:23:22 +00001529 i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
1530 false, false);
Kiran Patil21659032015-09-30 14:09:03 -04001531 spin_unlock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson6c8ad1b2014-06-04 01:23:22 +00001532 }
1533
Shannon Nelson30650cc2014-07-29 04:01:50 +00001534 if (ether_addr_equal(addr->sa_data, hw->mac.addr)) {
1535 struct i40e_aqc_add_macvlan_element_data element;
1536
1537 memset(&element, 0, sizeof(element));
1538 ether_addr_copy(element.mac_addr, hw->mac.addr);
1539 element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
1540 i40e_aq_add_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1541 } else {
Kiran Patil21659032015-09-30 14:09:03 -04001542 spin_lock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson30650cc2014-07-29 04:01:50 +00001543 f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY,
1544 false, false);
1545 if (f)
1546 f->is_laa = true;
Kiran Patil21659032015-09-30 14:09:03 -04001547 spin_unlock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson30650cc2014-07-29 04:01:50 +00001548 }
1549
Anjali Singhai30e25612015-09-28 13:37:12 -07001550 i40e_sync_vsi_filters(vsi, false);
Shannon Nelson30650cc2014-07-29 04:01:50 +00001551 ether_addr_copy(netdev->dev_addr, addr->sa_data);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001552
1553 return 0;
1554}
1555
1556/**
1557 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1558 * @vsi: the VSI being setup
1559 * @ctxt: VSI context structure
1560 * @enabled_tc: Enabled TCs bitmap
1561 * @is_add: True if called before Add VSI
1562 *
1563 * Setup VSI queue mapping for enabled traffic classes.
1564 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001565#ifdef I40E_FCOE
1566void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1567 struct i40e_vsi_context *ctxt,
1568 u8 enabled_tc,
1569 bool is_add)
1570#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001571static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1572 struct i40e_vsi_context *ctxt,
1573 u8 enabled_tc,
1574 bool is_add)
Vasu Dev38e00432014-08-01 13:27:03 -07001575#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001576{
1577 struct i40e_pf *pf = vsi->back;
1578 u16 sections = 0;
1579 u8 netdev_tc = 0;
1580 u16 numtc = 0;
1581 u16 qcount;
1582 u8 offset;
1583 u16 qmap;
1584 int i;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001585 u16 num_tc_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001586
1587 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
1588 offset = 0;
1589
1590 if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
1591 /* Find numtc from enabled TC bitmap */
1592 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001593 if (enabled_tc & BIT_ULL(i)) /* TC is enabled */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001594 numtc++;
1595 }
1596 if (!numtc) {
1597 dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
1598 numtc = 1;
1599 }
1600 } else {
1601 /* At least TC0 is enabled in case of non-DCB case */
1602 numtc = 1;
1603 }
1604
1605 vsi->tc_config.numtc = numtc;
1606 vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001607 /* Number of queues per enabled TC */
Anjali Singhai7f9ff472015-02-21 06:43:19 +00001608 /* In MFP case we can have a much lower count of MSIx
1609 * vectors available and so we need to lower the used
1610 * q count.
1611 */
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04001612 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
1613 qcount = min_t(int, vsi->alloc_queue_pairs, pf->num_lan_msix);
1614 else
1615 qcount = vsi->alloc_queue_pairs;
Anjali Singhai7f9ff472015-02-21 06:43:19 +00001616 num_tc_qps = qcount / numtc;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001617 num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001618
1619 /* Setup queue offset/count for all TCs for given VSI */
1620 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1621 /* See if the given TC is enabled for the given VSI */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001622 if (vsi->tc_config.enabled_tc & BIT_ULL(i)) {
1623 /* TC is enabled */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001624 int pow, num_qps;
1625
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001626 switch (vsi->type) {
1627 case I40E_VSI_MAIN:
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001628 qcount = min_t(int, pf->rss_size, num_tc_qps);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001629 break;
Vasu Dev38e00432014-08-01 13:27:03 -07001630#ifdef I40E_FCOE
1631 case I40E_VSI_FCOE:
1632 qcount = num_tc_qps;
1633 break;
1634#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001635 case I40E_VSI_FDIR:
1636 case I40E_VSI_SRIOV:
1637 case I40E_VSI_VMDQ2:
1638 default:
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001639 qcount = num_tc_qps;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001640 WARN_ON(i != 0);
1641 break;
1642 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001643 vsi->tc_config.tc_info[i].qoffset = offset;
1644 vsi->tc_config.tc_info[i].qcount = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001645
Shannon Nelson1e200e42015-02-27 09:15:24 +00001646 /* find the next higher power-of-2 of num queue pairs */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001647 num_qps = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001648 pow = 0;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001649 while (num_qps && (BIT_ULL(pow) < qcount)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001650 pow++;
1651 num_qps >>= 1;
1652 }
1653
1654 vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
1655 qmap =
1656 (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
1657 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
1658
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001659 offset += qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001660 } else {
1661 /* TC is not enabled so set the offset to
1662 * default queue and allocate one queue
1663 * for the given TC.
1664 */
1665 vsi->tc_config.tc_info[i].qoffset = 0;
1666 vsi->tc_config.tc_info[i].qcount = 1;
1667 vsi->tc_config.tc_info[i].netdev_tc = 0;
1668
1669 qmap = 0;
1670 }
1671 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
1672 }
1673
1674 /* Set actual Tx/Rx queue pairs */
1675 vsi->num_queue_pairs = offset;
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00001676 if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
1677 if (vsi->req_queue_pairs > 0)
1678 vsi->num_queue_pairs = vsi->req_queue_pairs;
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04001679 else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00001680 vsi->num_queue_pairs = pf->num_lan_msix;
1681 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001682
1683 /* Scheduler section valid can only be set for ADD VSI */
1684 if (is_add) {
1685 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
1686
1687 ctxt->info.up_enable_bits = enabled_tc;
1688 }
1689 if (vsi->type == I40E_VSI_SRIOV) {
1690 ctxt->info.mapping_flags |=
1691 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
1692 for (i = 0; i < vsi->num_queue_pairs; i++)
1693 ctxt->info.queue_mapping[i] =
1694 cpu_to_le16(vsi->base_queue + i);
1695 } else {
1696 ctxt->info.mapping_flags |=
1697 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
1698 ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
1699 }
1700 ctxt->info.valid_sections |= cpu_to_le16(sections);
1701}
1702
1703/**
1704 * i40e_set_rx_mode - NDO callback to set the netdev filters
1705 * @netdev: network interface device structure
1706 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001707#ifdef I40E_FCOE
1708void i40e_set_rx_mode(struct net_device *netdev)
1709#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001710static void i40e_set_rx_mode(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -07001711#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001712{
1713 struct i40e_netdev_priv *np = netdev_priv(netdev);
1714 struct i40e_mac_filter *f, *ftmp;
1715 struct i40e_vsi *vsi = np->vsi;
1716 struct netdev_hw_addr *uca;
1717 struct netdev_hw_addr *mca;
1718 struct netdev_hw_addr *ha;
1719
Kiran Patil21659032015-09-30 14:09:03 -04001720 spin_lock_bh(&vsi->mac_filter_list_lock);
1721
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001722 /* add addr if not already in the filter list */
1723 netdev_for_each_uc_addr(uca, netdev) {
1724 if (!i40e_find_mac(vsi, uca->addr, false, true)) {
1725 if (i40e_is_vsi_in_vlan(vsi))
1726 i40e_put_mac_in_vlan(vsi, uca->addr,
1727 false, true);
1728 else
1729 i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY,
1730 false, true);
1731 }
1732 }
1733
1734 netdev_for_each_mc_addr(mca, netdev) {
1735 if (!i40e_find_mac(vsi, mca->addr, false, true)) {
1736 if (i40e_is_vsi_in_vlan(vsi))
1737 i40e_put_mac_in_vlan(vsi, mca->addr,
1738 false, true);
1739 else
1740 i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY,
1741 false, true);
1742 }
1743 }
1744
1745 /* remove filter if not in netdev list */
1746 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001747
1748 if (!f->is_netdev)
1749 continue;
1750
Shannon Nelson2f41f332015-08-26 15:14:20 -04001751 netdev_for_each_mc_addr(mca, netdev)
1752 if (ether_addr_equal(mca->addr, f->macaddr))
1753 goto bottom_of_search_loop;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001754
Shannon Nelson2f41f332015-08-26 15:14:20 -04001755 netdev_for_each_uc_addr(uca, netdev)
1756 if (ether_addr_equal(uca->addr, f->macaddr))
1757 goto bottom_of_search_loop;
1758
1759 for_each_dev_addr(netdev, ha)
1760 if (ether_addr_equal(ha->addr, f->macaddr))
1761 goto bottom_of_search_loop;
1762
1763 /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
1764 i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true);
1765
1766bottom_of_search_loop:
1767 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001768 }
Kiran Patil21659032015-09-30 14:09:03 -04001769 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001770
1771 /* check for other flag changes */
1772 if (vsi->current_netdev_flags != vsi->netdev->flags) {
1773 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1774 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1775 }
1776}
1777
1778/**
Kiran Patil21659032015-09-30 14:09:03 -04001779 * i40e_mac_filter_entry_clone - Clones a MAC filter entry
1780 * @src: source MAC filter entry to be clones
1781 *
1782 * Returns the pointer to newly cloned MAC filter entry or NULL
1783 * in case of error
1784 **/
1785static struct i40e_mac_filter *i40e_mac_filter_entry_clone(
1786 struct i40e_mac_filter *src)
1787{
1788 struct i40e_mac_filter *f;
1789
1790 f = kzalloc(sizeof(*f), GFP_ATOMIC);
1791 if (!f)
1792 return NULL;
1793 *f = *src;
1794
1795 INIT_LIST_HEAD(&f->list);
1796
1797 return f;
1798}
1799
1800/**
1801 * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
1802 * @vsi: pointer to vsi struct
1803 * @from: Pointer to list which contains MAC filter entries - changes to
1804 * those entries needs to be undone.
1805 *
1806 * MAC filter entries from list were slated to be removed from device.
1807 **/
1808static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
1809 struct list_head *from)
1810{
1811 struct i40e_mac_filter *f, *ftmp;
1812
1813 list_for_each_entry_safe(f, ftmp, from, list) {
1814 f->changed = true;
1815 /* Move the element back into MAC filter list*/
1816 list_move_tail(&f->list, &vsi->mac_filter_list);
1817 }
1818}
1819
1820/**
1821 * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
1822 * @vsi: pointer to vsi struct
1823 *
1824 * MAC filter entries from list were slated to be added from device.
1825 **/
1826static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi)
1827{
1828 struct i40e_mac_filter *f, *ftmp;
1829
1830 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1831 if (!f->changed && f->counter)
1832 f->changed = true;
1833 }
1834}
1835
1836/**
1837 * i40e_cleanup_add_list - Deletes the element from add list and release
1838 * memory
1839 * @add_list: Pointer to list which contains MAC filter entries
1840 **/
1841static void i40e_cleanup_add_list(struct list_head *add_list)
1842{
1843 struct i40e_mac_filter *f, *ftmp;
1844
1845 list_for_each_entry_safe(f, ftmp, add_list, list) {
1846 list_del(&f->list);
1847 kfree(f);
1848 }
1849}
1850
1851/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001852 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1853 * @vsi: ptr to the VSI
Anjali Singhai30e25612015-09-28 13:37:12 -07001854 * @grab_rtnl: whether RTNL needs to be grabbed
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001855 *
1856 * Push any outstanding VSI filter changes through the AdminQ.
1857 *
1858 * Returns 0 or error value
1859 **/
Anjali Singhai30e25612015-09-28 13:37:12 -07001860int i40e_sync_vsi_filters(struct i40e_vsi *vsi, bool grab_rtnl)
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;
Kiran Patil21659032015-09-30 14:09:03 -04001868 bool err_cond = false;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001869 i40e_status ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001870 struct i40e_pf *pf;
1871 int num_add = 0;
1872 int num_del = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001873 int aq_err = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001874 u16 cmd_flags;
1875
1876 /* empty array typed pointers, kcalloc later */
1877 struct i40e_aqc_add_macvlan_element_data *add_list;
1878 struct i40e_aqc_remove_macvlan_element_data *del_list;
1879
1880 while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
1881 usleep_range(1000, 2000);
1882 pf = vsi->back;
1883
1884 if (vsi->netdev) {
1885 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
1886 vsi->current_netdev_flags = vsi->netdev->flags;
1887 }
1888
Kiran Patil21659032015-09-30 14:09:03 -04001889 INIT_LIST_HEAD(&tmp_del_list);
1890 INIT_LIST_HEAD(&tmp_add_list);
1891
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001892 if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
1893 vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
1894
Kiran Patil21659032015-09-30 14:09:03 -04001895 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001896 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1897 if (!f->changed)
1898 continue;
1899
1900 if (f->counter != 0)
1901 continue;
1902 f->changed = false;
Kiran Patil21659032015-09-30 14:09:03 -04001903
1904 /* Move the element into temporary del_list */
1905 list_move_tail(&f->list, &tmp_del_list);
1906 }
1907
1908 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1909 if (!f->changed)
1910 continue;
1911
1912 if (f->counter == 0)
1913 continue;
1914 f->changed = false;
1915
1916 /* Clone MAC filter entry and add into temporary list */
1917 fclone = i40e_mac_filter_entry_clone(f);
1918 if (!fclone) {
1919 err_cond = true;
1920 break;
1921 }
1922 list_add_tail(&fclone->list, &tmp_add_list);
1923 }
1924
1925 /* if failed to clone MAC filter entry - undo */
1926 if (err_cond) {
1927 i40e_undo_del_filter_entries(vsi, &tmp_del_list);
1928 i40e_undo_add_filter_entries(vsi);
1929 }
1930 spin_unlock_bh(&vsi->mac_filter_list_lock);
1931
1932 if (err_cond)
1933 i40e_cleanup_add_list(&tmp_add_list);
1934 }
1935
1936 /* Now process 'del_list' outside the lock */
1937 if (!list_empty(&tmp_del_list)) {
1938 filter_list_len = pf->hw.aq.asq_buf_size /
1939 sizeof(struct i40e_aqc_remove_macvlan_element_data);
1940 del_list = kcalloc(filter_list_len,
1941 sizeof(struct i40e_aqc_remove_macvlan_element_data),
1942 GFP_KERNEL);
1943 if (!del_list) {
1944 i40e_cleanup_add_list(&tmp_add_list);
1945
1946 /* Undo VSI's MAC filter entry element updates */
1947 spin_lock_bh(&vsi->mac_filter_list_lock);
1948 i40e_undo_del_filter_entries(vsi, &tmp_del_list);
1949 i40e_undo_add_filter_entries(vsi);
1950 spin_unlock_bh(&vsi->mac_filter_list_lock);
1951 return -ENOMEM;
1952 }
1953
1954 list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001955 cmd_flags = 0;
1956
1957 /* add to delete list */
Greg Rose9a173902014-05-22 06:32:02 +00001958 ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001959 del_list[num_del].vlan_tag =
1960 cpu_to_le16((u16)(f->vlan ==
1961 I40E_VLAN_ANY ? 0 : f->vlan));
1962
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001963 cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
1964 del_list[num_del].flags = cmd_flags;
1965 num_del++;
1966
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001967 /* flush a full buffer */
1968 if (num_del == filter_list_len) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001969 ret = i40e_aq_remove_macvlan(&pf->hw,
1970 vsi->seid, del_list, num_del,
1971 NULL);
1972 aq_err = pf->hw.aq.asq_last_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001973 num_del = 0;
1974 memset(del_list, 0, sizeof(*del_list));
1975
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001976 if (ret && aq_err != I40E_AQ_RC_ENOENT)
Kiran Patil21659032015-09-30 14:09:03 -04001977 dev_err(&pf->pdev->dev,
1978 "ignoring delete macvlan error, err %s, aq_err %s while flushing a full buffer\n",
1979 i40e_stat_str(&pf->hw, ret),
1980 i40e_aq_str(&pf->hw, aq_err));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001981 }
Kiran Patil21659032015-09-30 14:09:03 -04001982 /* Release memory for MAC filter entries which were
1983 * synced up with HW.
1984 */
1985 list_del(&f->list);
1986 kfree(f);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001987 }
Kiran Patil21659032015-09-30 14:09:03 -04001988
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001989 if (num_del) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001990 ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001991 del_list, num_del, NULL);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001992 aq_err = pf->hw.aq.asq_last_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001993 num_del = 0;
1994
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001995 if (ret && aq_err != I40E_AQ_RC_ENOENT)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001996 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001997 "ignoring delete macvlan error, err %s aq_err %s\n",
1998 i40e_stat_str(&pf->hw, ret),
1999 i40e_aq_str(&pf->hw, aq_err));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002000 }
2001
2002 kfree(del_list);
2003 del_list = NULL;
Kiran Patil21659032015-09-30 14:09:03 -04002004 }
2005
2006 if (!list_empty(&tmp_add_list)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002007
2008 /* do all the adds now */
2009 filter_list_len = pf->hw.aq.asq_buf_size /
2010 sizeof(struct i40e_aqc_add_macvlan_element_data),
2011 add_list = kcalloc(filter_list_len,
2012 sizeof(struct i40e_aqc_add_macvlan_element_data),
2013 GFP_KERNEL);
Kiran Patil21659032015-09-30 14:09:03 -04002014 if (!add_list) {
2015 /* Purge element from temporary lists */
2016 i40e_cleanup_add_list(&tmp_add_list);
2017
2018 /* Undo add filter entries from VSI MAC filter list */
2019 spin_lock_bh(&vsi->mac_filter_list_lock);
2020 i40e_undo_add_filter_entries(vsi);
2021 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002022 return -ENOMEM;
Kiran Patil21659032015-09-30 14:09:03 -04002023 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002024
Kiran Patil21659032015-09-30 14:09:03 -04002025 list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002026
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002027 add_happened = true;
2028 cmd_flags = 0;
2029
2030 /* add to add array */
Greg Rose9a173902014-05-22 06:32:02 +00002031 ether_addr_copy(add_list[num_add].mac_addr, f->macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002032 add_list[num_add].vlan_tag =
2033 cpu_to_le16(
2034 (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan));
2035 add_list[num_add].queue_number = 0;
2036
2037 cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002038 add_list[num_add].flags = cpu_to_le16(cmd_flags);
2039 num_add++;
2040
2041 /* flush a full buffer */
2042 if (num_add == filter_list_len) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002043 ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
2044 add_list, num_add,
2045 NULL);
2046 aq_err = pf->hw.aq.asq_last_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002047 num_add = 0;
2048
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002049 if (ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002050 break;
2051 memset(add_list, 0, sizeof(*add_list));
2052 }
Kiran Patil21659032015-09-30 14:09:03 -04002053 /* Entries from tmp_add_list were cloned from MAC
2054 * filter list, hence clean those cloned entries
2055 */
2056 list_del(&f->list);
2057 kfree(f);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002058 }
Kiran Patil21659032015-09-30 14:09:03 -04002059
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002060 if (num_add) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002061 ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
2062 add_list, num_add, NULL);
2063 aq_err = pf->hw.aq.asq_last_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002064 num_add = 0;
2065 }
2066 kfree(add_list);
2067 add_list = NULL;
2068
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002069 if (add_happened && ret && aq_err != I40E_AQ_RC_EINVAL) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002070 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002071 "add filter failed, err %s aq_err %s\n",
2072 i40e_stat_str(&pf->hw, ret),
2073 i40e_aq_str(&pf->hw, aq_err));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002074 if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) &&
2075 !test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2076 &vsi->state)) {
2077 promisc_forced_on = true;
2078 set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2079 &vsi->state);
2080 dev_info(&pf->pdev->dev, "promiscuous mode forced on\n");
2081 }
2082 }
2083 }
2084
2085 /* check for changes in promiscuous modes */
2086 if (changed_flags & IFF_ALLMULTI) {
2087 bool cur_multipromisc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002088
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002089 cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002090 ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
2091 vsi->seid,
2092 cur_multipromisc,
2093 NULL);
2094 if (ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002095 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002096 "set multi promisc failed, err %s aq_err %s\n",
2097 i40e_stat_str(&pf->hw, ret),
2098 i40e_aq_str(&pf->hw,
2099 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002100 }
2101 if ((changed_flags & IFF_PROMISC) || promisc_forced_on) {
2102 bool cur_promisc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002103
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002104 cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
2105 test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2106 &vsi->state));
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002107 if (vsi->type == I40E_VSI_MAIN && pf->lan_veb != I40E_NO_VEB) {
2108 /* set defport ON for Main VSI instead of true promisc
2109 * this way we will get all unicast/multicast and VLAN
2110 * promisc behavior but will not get VF or VMDq traffic
2111 * replicated on the Main VSI.
2112 */
2113 if (pf->cur_promisc != cur_promisc) {
2114 pf->cur_promisc = cur_promisc;
Anjali Singhai30e25612015-09-28 13:37:12 -07002115 if (grab_rtnl)
2116 i40e_do_reset_safe(pf,
2117 BIT(__I40E_PF_RESET_REQUESTED));
2118 else
2119 i40e_do_reset(pf,
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002120 BIT(__I40E_PF_RESET_REQUESTED));
2121 }
2122 } else {
2123 ret = i40e_aq_set_vsi_unicast_promiscuous(
2124 &vsi->back->hw,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002125 vsi->seid,
2126 cur_promisc, NULL);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002127 if (ret)
2128 dev_info(&pf->pdev->dev,
2129 "set unicast promisc failed, err %d, aq_err %d\n",
2130 ret, pf->hw.aq.asq_last_status);
2131 ret = i40e_aq_set_vsi_multicast_promiscuous(
2132 &vsi->back->hw,
2133 vsi->seid,
2134 cur_promisc, NULL);
2135 if (ret)
2136 dev_info(&pf->pdev->dev,
2137 "set multicast promisc failed, err %d, aq_err %d\n",
2138 ret, pf->hw.aq.asq_last_status);
2139 }
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002140 ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
2141 vsi->seid,
2142 cur_promisc, NULL);
2143 if (ret)
Greg Rose1a103702013-11-28 06:42:39 +00002144 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002145 "set brdcast promisc failed, err %s, aq_err %s\n",
2146 i40e_stat_str(&pf->hw, ret),
2147 i40e_aq_str(&pf->hw,
2148 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002149 }
2150
2151 clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
2152 return 0;
2153}
2154
2155/**
2156 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2157 * @pf: board private structure
2158 **/
2159static void i40e_sync_filters_subtask(struct i40e_pf *pf)
2160{
2161 int v;
2162
2163 if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
2164 return;
2165 pf->flags &= ~I40E_FLAG_FILTER_SYNC;
2166
Mitch Williams505682c2014-05-20 08:01:37 +00002167 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002168 if (pf->vsi[v] &&
2169 (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED))
Anjali Singhai30e25612015-09-28 13:37:12 -07002170 i40e_sync_vsi_filters(pf->vsi[v], true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002171 }
2172}
2173
2174/**
2175 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2176 * @netdev: network interface device structure
2177 * @new_mtu: new value for maximum frame size
2178 *
2179 * Returns 0 on success, negative on failure
2180 **/
2181static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
2182{
2183 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg61a46a42014-04-23 04:50:05 +00002184 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002185 struct i40e_vsi *vsi = np->vsi;
2186
2187 /* MTU < 68 is an error and causes problems on some kernels */
2188 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
2189 return -EINVAL;
2190
2191 netdev_info(netdev, "changing MTU from %d to %d\n",
2192 netdev->mtu, new_mtu);
2193 netdev->mtu = new_mtu;
2194 if (netif_running(netdev))
2195 i40e_vsi_reinit_locked(vsi);
2196
2197 return 0;
2198}
2199
2200/**
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002201 * i40e_ioctl - Access the hwtstamp interface
2202 * @netdev: network interface device structure
2203 * @ifr: interface request data
2204 * @cmd: ioctl command
2205 **/
2206int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2207{
2208 struct i40e_netdev_priv *np = netdev_priv(netdev);
2209 struct i40e_pf *pf = np->vsi->back;
2210
2211 switch (cmd) {
2212 case SIOCGHWTSTAMP:
2213 return i40e_ptp_get_ts_config(pf, ifr);
2214 case SIOCSHWTSTAMP:
2215 return i40e_ptp_set_ts_config(pf, ifr);
2216 default:
2217 return -EOPNOTSUPP;
2218 }
2219}
2220
2221/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002222 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2223 * @vsi: the vsi being adjusted
2224 **/
2225void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
2226{
2227 struct i40e_vsi_context ctxt;
2228 i40e_status ret;
2229
2230 if ((vsi->info.valid_sections &
2231 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2232 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
2233 return; /* already enabled */
2234
2235 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2236 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2237 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
2238
2239 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002240 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002241 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2242 if (ret) {
2243 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002244 "update vlan stripping failed, err %s aq_err %s\n",
2245 i40e_stat_str(&vsi->back->hw, ret),
2246 i40e_aq_str(&vsi->back->hw,
2247 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002248 }
2249}
2250
2251/**
2252 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2253 * @vsi: the vsi being adjusted
2254 **/
2255void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
2256{
2257 struct i40e_vsi_context ctxt;
2258 i40e_status ret;
2259
2260 if ((vsi->info.valid_sections &
2261 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2262 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
2263 I40E_AQ_VSI_PVLAN_EMOD_MASK))
2264 return; /* already disabled */
2265
2266 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2267 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2268 I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
2269
2270 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002271 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002272 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2273 if (ret) {
2274 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002275 "update vlan stripping failed, err %s aq_err %s\n",
2276 i40e_stat_str(&vsi->back->hw, ret),
2277 i40e_aq_str(&vsi->back->hw,
2278 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002279 }
2280}
2281
2282/**
2283 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2284 * @netdev: network interface to be adjusted
2285 * @features: netdev features to test if VLAN offload is enabled or not
2286 **/
2287static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
2288{
2289 struct i40e_netdev_priv *np = netdev_priv(netdev);
2290 struct i40e_vsi *vsi = np->vsi;
2291
2292 if (features & NETIF_F_HW_VLAN_CTAG_RX)
2293 i40e_vlan_stripping_enable(vsi);
2294 else
2295 i40e_vlan_stripping_disable(vsi);
2296}
2297
2298/**
2299 * i40e_vsi_add_vlan - Add vsi membership for given vlan
2300 * @vsi: the vsi being configured
2301 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2302 **/
2303int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
2304{
2305 struct i40e_mac_filter *f, *add_f;
2306 bool is_netdev, is_vf;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002307
2308 is_vf = (vsi->type == I40E_VSI_SRIOV);
2309 is_netdev = !!(vsi->netdev);
2310
Kiran Patil21659032015-09-30 14:09:03 -04002311 /* Locked once because all functions invoked below iterates list*/
2312 spin_lock_bh(&vsi->mac_filter_list_lock);
2313
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002314 if (is_netdev) {
2315 add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid,
2316 is_vf, is_netdev);
2317 if (!add_f) {
2318 dev_info(&vsi->back->pdev->dev,
2319 "Could not add vlan filter %d for %pM\n",
2320 vid, vsi->netdev->dev_addr);
Kiran Patil21659032015-09-30 14:09:03 -04002321 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002322 return -ENOMEM;
2323 }
2324 }
2325
2326 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2327 add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
2328 if (!add_f) {
2329 dev_info(&vsi->back->pdev->dev,
2330 "Could not add vlan filter %d for %pM\n",
2331 vid, f->macaddr);
Kiran Patil21659032015-09-30 14:09:03 -04002332 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002333 return -ENOMEM;
2334 }
2335 }
2336
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002337 /* Now if we add a vlan tag, make sure to check if it is the first
2338 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
2339 * with 0, so we now accept untagged and specified tagged traffic
2340 * (and not any taged and untagged)
2341 */
2342 if (vid > 0) {
2343 if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr,
2344 I40E_VLAN_ANY,
2345 is_vf, is_netdev)) {
2346 i40e_del_filter(vsi, vsi->netdev->dev_addr,
2347 I40E_VLAN_ANY, is_vf, is_netdev);
2348 add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0,
2349 is_vf, is_netdev);
2350 if (!add_f) {
2351 dev_info(&vsi->back->pdev->dev,
2352 "Could not add filter 0 for %pM\n",
2353 vsi->netdev->dev_addr);
Kiran Patil21659032015-09-30 14:09:03 -04002354 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002355 return -ENOMEM;
2356 }
2357 }
Greg Rose8d82a7c2014-01-13 16:13:04 -08002358 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002359
Greg Rose8d82a7c2014-01-13 16:13:04 -08002360 /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
2361 if (vid > 0 && !vsi->info.pvid) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002362 list_for_each_entry(f, &vsi->mac_filter_list, list) {
Kiran Patil21659032015-09-30 14:09:03 -04002363 if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY,
2364 is_vf, is_netdev))
2365 continue;
2366 i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY,
2367 is_vf, is_netdev);
2368 add_f = i40e_add_filter(vsi, f->macaddr,
2369 0, is_vf, is_netdev);
2370 if (!add_f) {
2371 dev_info(&vsi->back->pdev->dev,
2372 "Could not add filter 0 for %pM\n",
2373 f->macaddr);
2374 spin_unlock_bh(&vsi->mac_filter_list_lock);
2375 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002376 }
2377 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002378 }
2379
Kiran Patil21659032015-09-30 14:09:03 -04002380 /* Make sure to release before sync_vsi_filter because that
2381 * function will lock/unlock as necessary
2382 */
2383 spin_unlock_bh(&vsi->mac_filter_list_lock);
2384
Anjali Singhai Jain80f64282013-11-28 06:39:47 +00002385 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
2386 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
2387 return 0;
2388
Anjali Singhai30e25612015-09-28 13:37:12 -07002389 return i40e_sync_vsi_filters(vsi, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002390}
2391
2392/**
2393 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
2394 * @vsi: the vsi being configured
2395 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002396 *
2397 * Return: 0 on success or negative otherwise
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002398 **/
2399int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
2400{
2401 struct net_device *netdev = vsi->netdev;
2402 struct i40e_mac_filter *f, *add_f;
2403 bool is_vf, is_netdev;
2404 int filter_count = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002405
2406 is_vf = (vsi->type == I40E_VSI_SRIOV);
2407 is_netdev = !!(netdev);
2408
Kiran Patil21659032015-09-30 14:09:03 -04002409 /* Locked once because all functions invoked below iterates list */
2410 spin_lock_bh(&vsi->mac_filter_list_lock);
2411
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002412 if (is_netdev)
2413 i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev);
2414
2415 list_for_each_entry(f, &vsi->mac_filter_list, list)
2416 i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
2417
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002418 /* go through all the filters for this VSI and if there is only
2419 * vid == 0 it means there are no other filters, so vid 0 must
2420 * be replaced with -1. This signifies that we should from now
2421 * on accept any traffic (with any tag present, or untagged)
2422 */
2423 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2424 if (is_netdev) {
2425 if (f->vlan &&
2426 ether_addr_equal(netdev->dev_addr, f->macaddr))
2427 filter_count++;
2428 }
2429
2430 if (f->vlan)
2431 filter_count++;
2432 }
2433
2434 if (!filter_count && is_netdev) {
2435 i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev);
2436 f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
2437 is_vf, is_netdev);
2438 if (!f) {
2439 dev_info(&vsi->back->pdev->dev,
2440 "Could not add filter %d for %pM\n",
2441 I40E_VLAN_ANY, netdev->dev_addr);
Kiran Patil21659032015-09-30 14:09:03 -04002442 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002443 return -ENOMEM;
2444 }
2445 }
2446
2447 if (!filter_count) {
2448 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2449 i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev);
2450 add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY,
Kiran Patil21659032015-09-30 14:09:03 -04002451 is_vf, is_netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002452 if (!add_f) {
2453 dev_info(&vsi->back->pdev->dev,
2454 "Could not add filter %d for %pM\n",
2455 I40E_VLAN_ANY, f->macaddr);
Kiran Patil21659032015-09-30 14:09:03 -04002456 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002457 return -ENOMEM;
2458 }
2459 }
2460 }
2461
Kiran Patil21659032015-09-30 14:09:03 -04002462 /* Make sure to release before sync_vsi_filter because that
2463 * function with lock/unlock as necessary
2464 */
2465 spin_unlock_bh(&vsi->mac_filter_list_lock);
2466
Anjali Singhai Jain80f64282013-11-28 06:39:47 +00002467 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
2468 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
2469 return 0;
2470
Anjali Singhai30e25612015-09-28 13:37:12 -07002471 return i40e_sync_vsi_filters(vsi, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002472}
2473
2474/**
2475 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2476 * @netdev: network interface to be adjusted
2477 * @vid: vlan id to be added
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002478 *
2479 * net_device_ops implementation for adding vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002480 **/
Vasu Dev38e00432014-08-01 13:27:03 -07002481#ifdef I40E_FCOE
2482int i40e_vlan_rx_add_vid(struct net_device *netdev,
2483 __always_unused __be16 proto, u16 vid)
2484#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002485static int i40e_vlan_rx_add_vid(struct net_device *netdev,
2486 __always_unused __be16 proto, u16 vid)
Vasu Dev38e00432014-08-01 13:27:03 -07002487#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002488{
2489 struct i40e_netdev_priv *np = netdev_priv(netdev);
2490 struct i40e_vsi *vsi = np->vsi;
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002491 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002492
2493 if (vid > 4095)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002494 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002495
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002496 netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid);
2497
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002498 /* If the network stack called us with vid = 0 then
2499 * it is asking to receive priority tagged packets with
2500 * vlan id 0. Our HW receives them by default when configured
2501 * to receive untagged packets so there is no need to add an
2502 * extra filter for vlan 0 tagged packets.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002503 */
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002504 if (vid)
2505 ret = i40e_vsi_add_vlan(vsi, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002506
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002507 if (!ret && (vid < VLAN_N_VID))
2508 set_bit(vid, vsi->active_vlans);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002509
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002510 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002511}
2512
2513/**
2514 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2515 * @netdev: network interface to be adjusted
2516 * @vid: vlan id to be removed
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002517 *
Akeem G Abodunrinfdfd9432014-02-11 08:24:15 +00002518 * net_device_ops implementation for removing vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002519 **/
Vasu Dev38e00432014-08-01 13:27:03 -07002520#ifdef I40E_FCOE
2521int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2522 __always_unused __be16 proto, u16 vid)
2523#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002524static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2525 __always_unused __be16 proto, u16 vid)
Vasu Dev38e00432014-08-01 13:27:03 -07002526#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002527{
2528 struct i40e_netdev_priv *np = netdev_priv(netdev);
2529 struct i40e_vsi *vsi = np->vsi;
2530
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002531 netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid);
2532
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002533 /* return code is ignored as there is nothing a user
2534 * can do about failure to remove and a log message was
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002535 * already printed from the other function
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002536 */
2537 i40e_vsi_kill_vlan(vsi, vid);
2538
2539 clear_bit(vid, vsi->active_vlans);
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002540
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002541 return 0;
2542}
2543
2544/**
2545 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2546 * @vsi: the vsi being brought back up
2547 **/
2548static void i40e_restore_vlan(struct i40e_vsi *vsi)
2549{
2550 u16 vid;
2551
2552 if (!vsi->netdev)
2553 return;
2554
2555 i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
2556
2557 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
2558 i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
2559 vid);
2560}
2561
2562/**
2563 * i40e_vsi_add_pvid - Add pvid for the VSI
2564 * @vsi: the vsi being adjusted
2565 * @vid: the vlan id to set as a PVID
2566 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002567int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002568{
2569 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002570 i40e_status ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002571
2572 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2573 vsi->info.pvid = cpu_to_le16(vid);
Greg Rose6c12fcb2013-11-28 06:39:34 +00002574 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
2575 I40E_AQ_VSI_PVLAN_INSERT_PVID |
Greg Roseb774c7d2013-11-28 06:39:44 +00002576 I40E_AQ_VSI_PVLAN_EMOD_STR;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002577
2578 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002579 ctxt.info = vsi->info;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002580 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2581 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002582 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002583 "add pvid failed, err %s aq_err %s\n",
2584 i40e_stat_str(&vsi->back->hw, ret),
2585 i40e_aq_str(&vsi->back->hw,
2586 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002587 return -ENOENT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002588 }
2589
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002590 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002591}
2592
2593/**
2594 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2595 * @vsi: the vsi being adjusted
2596 *
2597 * Just use the vlan_rx_register() service to put it back to normal
2598 **/
2599void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
2600{
Greg Rose6c12fcb2013-11-28 06:39:34 +00002601 i40e_vlan_stripping_disable(vsi);
2602
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002603 vsi->info.pvid = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002604}
2605
2606/**
2607 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2608 * @vsi: ptr to the VSI
2609 *
2610 * If this function returns with an error, then it's possible one or
2611 * more of the rings is populated (while the rest are not). It is the
2612 * callers duty to clean those orphaned rings.
2613 *
2614 * Return 0 on success, negative on failure
2615 **/
2616static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
2617{
2618 int i, err = 0;
2619
2620 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002621 err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002622
2623 return err;
2624}
2625
2626/**
2627 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2628 * @vsi: ptr to the VSI
2629 *
2630 * Free VSI's transmit software resources
2631 **/
2632static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
2633{
2634 int i;
2635
Greg Rose8e9dca52013-12-18 13:45:53 +00002636 if (!vsi->tx_rings)
2637 return;
2638
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002639 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002640 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002641 i40e_free_tx_resources(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002642}
2643
2644/**
2645 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2646 * @vsi: ptr to the VSI
2647 *
2648 * If this function returns with an error, then it's possible one or
2649 * more of the rings is populated (while the rest are not). It is the
2650 * callers duty to clean those orphaned rings.
2651 *
2652 * Return 0 on success, negative on failure
2653 **/
2654static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
2655{
2656 int i, err = 0;
2657
2658 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002659 err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
Vasu Dev38e00432014-08-01 13:27:03 -07002660#ifdef I40E_FCOE
2661 i40e_fcoe_setup_ddp_resources(vsi);
2662#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002663 return err;
2664}
2665
2666/**
2667 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2668 * @vsi: ptr to the VSI
2669 *
2670 * Free all receive software resources
2671 **/
2672static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
2673{
2674 int i;
2675
Greg Rose8e9dca52013-12-18 13:45:53 +00002676 if (!vsi->rx_rings)
2677 return;
2678
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002679 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002680 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002681 i40e_free_rx_resources(vsi->rx_rings[i]);
Vasu Dev38e00432014-08-01 13:27:03 -07002682#ifdef I40E_FCOE
2683 i40e_fcoe_free_ddp_resources(vsi);
2684#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002685}
2686
2687/**
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002688 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
2689 * @ring: The Tx ring to configure
2690 *
2691 * This enables/disables XPS for a given Tx descriptor ring
2692 * based on the TCs enabled for the VSI that ring belongs to.
2693 **/
2694static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
2695{
2696 struct i40e_vsi *vsi = ring->vsi;
2697 cpumask_var_t mask;
2698
Jesse Brandeburg9a660ee2015-02-26 16:13:22 +00002699 if (!ring->q_vector || !ring->netdev)
2700 return;
2701
2702 /* Single TC mode enable XPS */
2703 if (vsi->tc_config.numtc <= 1) {
2704 if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002705 netif_set_xps_queue(ring->netdev,
2706 &ring->q_vector->affinity_mask,
2707 ring->queue_index);
Jesse Brandeburg9a660ee2015-02-26 16:13:22 +00002708 } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) {
2709 /* Disable XPS to allow selection based on TC */
2710 bitmap_zero(cpumask_bits(mask), nr_cpumask_bits);
2711 netif_set_xps_queue(ring->netdev, mask, ring->queue_index);
2712 free_cpumask_var(mask);
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002713 }
2714}
2715
2716/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002717 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2718 * @ring: The Tx ring to configure
2719 *
2720 * Configure the Tx descriptor ring in the HMC context.
2721 **/
2722static int i40e_configure_tx_ring(struct i40e_ring *ring)
2723{
2724 struct i40e_vsi *vsi = ring->vsi;
2725 u16 pf_q = vsi->base_queue + ring->queue_index;
2726 struct i40e_hw *hw = &vsi->back->hw;
2727 struct i40e_hmc_obj_txq tx_ctx;
2728 i40e_status err = 0;
2729 u32 qtx_ctl = 0;
2730
2731 /* some ATR related tx ring init */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002732 if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002733 ring->atr_sample_rate = vsi->back->atr_sample_rate;
2734 ring->atr_count = 0;
2735 } else {
2736 ring->atr_sample_rate = 0;
2737 }
2738
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002739 /* configure XPS */
2740 i40e_config_xps_tx_ring(ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002741
2742 /* clear the context structure first */
2743 memset(&tx_ctx, 0, sizeof(tx_ctx));
2744
2745 tx_ctx.new_context = 1;
2746 tx_ctx.base = (ring->dma / 128);
2747 tx_ctx.qlen = ring->count;
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002748 tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
2749 I40E_FLAG_FD_ATR_ENABLED));
Vasu Dev38e00432014-08-01 13:27:03 -07002750#ifdef I40E_FCOE
2751 tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
2752#endif
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002753 tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
Jesse Brandeburg1943d8b2014-02-14 02:14:40 +00002754 /* FDIR VSI tx ring can still use RS bit and writebacks */
2755 if (vsi->type != I40E_VSI_FDIR)
2756 tx_ctx.head_wb_ena = 1;
2757 tx_ctx.head_wb_addr = ring->dma +
2758 (ring->count * sizeof(struct i40e_tx_desc));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002759
2760 /* As part of VSI creation/update, FW allocates certain
2761 * Tx arbitration queue sets for each TC enabled for
2762 * the VSI. The FW returns the handles to these queue
2763 * sets as part of the response buffer to Add VSI,
2764 * Update VSI, etc. AQ commands. It is expected that
2765 * these queue set handles be associated with the Tx
2766 * queues by the driver as part of the TX queue context
2767 * initialization. This has to be done regardless of
2768 * DCB as by default everything is mapped to TC0.
2769 */
2770 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
2771 tx_ctx.rdylist_act = 0;
2772
2773 /* clear the context in the HMC */
2774 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2775 if (err) {
2776 dev_info(&vsi->back->pdev->dev,
2777 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2778 ring->queue_index, pf_q, err);
2779 return -ENOMEM;
2780 }
2781
2782 /* set the context in the HMC */
2783 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
2784 if (err) {
2785 dev_info(&vsi->back->pdev->dev,
2786 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2787 ring->queue_index, pf_q, err);
2788 return -ENOMEM;
2789 }
2790
2791 /* Now associate this queue with this PCI function */
Mitch Williams7a28d882014-10-17 03:14:52 +00002792 if (vsi->type == I40E_VSI_VMDQ2) {
Shannon Nelson9d8bf542014-01-14 00:49:50 -08002793 qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
Mitch Williams7a28d882014-10-17 03:14:52 +00002794 qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
2795 I40E_QTX_CTL_VFVM_INDX_MASK;
2796 } else {
Shannon Nelson9d8bf542014-01-14 00:49:50 -08002797 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
Mitch Williams7a28d882014-10-17 03:14:52 +00002798 }
2799
Shannon Nelson13fd9772013-09-28 07:14:19 +00002800 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
2801 I40E_QTX_CTL_PF_INDX_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002802 wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
2803 i40e_flush(hw);
2804
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002805 /* cache tail off for easier writes later */
2806 ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2807
2808 return 0;
2809}
2810
2811/**
2812 * i40e_configure_rx_ring - Configure a receive ring context
2813 * @ring: The Rx ring to configure
2814 *
2815 * Configure the Rx descriptor ring in the HMC context.
2816 **/
2817static int i40e_configure_rx_ring(struct i40e_ring *ring)
2818{
2819 struct i40e_vsi *vsi = ring->vsi;
2820 u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
2821 u16 pf_q = vsi->base_queue + ring->queue_index;
2822 struct i40e_hw *hw = &vsi->back->hw;
2823 struct i40e_hmc_obj_rxq rx_ctx;
2824 i40e_status err = 0;
2825
2826 ring->state = 0;
2827
2828 /* clear the context structure first */
2829 memset(&rx_ctx, 0, sizeof(rx_ctx));
2830
2831 ring->rx_buf_len = vsi->rx_buf_len;
2832 ring->rx_hdr_len = vsi->rx_hdr_len;
2833
2834 rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
2835 rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
2836
2837 rx_ctx.base = (ring->dma / 128);
2838 rx_ctx.qlen = ring->count;
2839
2840 if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) {
2841 set_ring_16byte_desc_enabled(ring);
2842 rx_ctx.dsize = 0;
2843 } else {
2844 rx_ctx.dsize = 1;
2845 }
2846
2847 rx_ctx.dtype = vsi->dtype;
2848 if (vsi->dtype) {
2849 set_ring_ps_enabled(ring);
2850 rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
2851 I40E_RX_SPLIT_IP |
2852 I40E_RX_SPLIT_TCP_UDP |
2853 I40E_RX_SPLIT_SCTP;
2854 } else {
2855 rx_ctx.hsplit_0 = 0;
2856 }
2857
2858 rx_ctx.rxmax = min_t(u16, vsi->max_frame,
2859 (chain_len * ring->rx_buf_len));
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00002860 if (hw->revision_id == 0)
2861 rx_ctx.lrxqthresh = 0;
2862 else
2863 rx_ctx.lrxqthresh = 2;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002864 rx_ctx.crcstrip = 1;
2865 rx_ctx.l2tsel = 1;
Jesse Brandeburgc4bbac32015-09-28 11:21:48 -07002866 /* this controls whether VLAN is stripped from inner headers */
2867 rx_ctx.showiv = 0;
Vasu Dev38e00432014-08-01 13:27:03 -07002868#ifdef I40E_FCOE
2869 rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
2870#endif
Catherine Sullivanacb36762014-03-06 09:02:30 +00002871 /* set the prefena field to 1 because the manual says to */
2872 rx_ctx.prefena = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002873
2874 /* clear the context in the HMC */
2875 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
2876 if (err) {
2877 dev_info(&vsi->back->pdev->dev,
2878 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2879 ring->queue_index, pf_q, err);
2880 return -ENOMEM;
2881 }
2882
2883 /* set the context in the HMC */
2884 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
2885 if (err) {
2886 dev_info(&vsi->back->pdev->dev,
2887 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2888 ring->queue_index, pf_q, err);
2889 return -ENOMEM;
2890 }
2891
2892 /* cache tail for quicker writes, and clear the reg before use */
2893 ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
2894 writel(0, ring->tail);
2895
Mitch Williamsa132af22015-01-24 09:58:35 +00002896 if (ring_is_ps_enabled(ring)) {
2897 i40e_alloc_rx_headers(ring);
2898 i40e_alloc_rx_buffers_ps(ring, I40E_DESC_UNUSED(ring));
2899 } else {
2900 i40e_alloc_rx_buffers_1buf(ring, I40E_DESC_UNUSED(ring));
2901 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002902
2903 return 0;
2904}
2905
2906/**
2907 * i40e_vsi_configure_tx - Configure the VSI for Tx
2908 * @vsi: VSI structure describing this set of rings and resources
2909 *
2910 * Configure the Tx VSI for operation.
2911 **/
2912static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
2913{
2914 int err = 0;
2915 u16 i;
2916
Alexander Duyck9f65e152013-09-28 06:00:58 +00002917 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
2918 err = i40e_configure_tx_ring(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002919
2920 return err;
2921}
2922
2923/**
2924 * i40e_vsi_configure_rx - Configure the VSI for Rx
2925 * @vsi: the VSI being configured
2926 *
2927 * Configure the Rx VSI for operation.
2928 **/
2929static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
2930{
2931 int err = 0;
2932 u16 i;
2933
2934 if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
2935 vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
2936 + ETH_FCS_LEN + VLAN_HLEN;
2937 else
2938 vsi->max_frame = I40E_RXBUFFER_2048;
2939
2940 /* figure out correct receive buffer length */
2941 switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED |
2942 I40E_FLAG_RX_PS_ENABLED)) {
2943 case I40E_FLAG_RX_1BUF_ENABLED:
2944 vsi->rx_hdr_len = 0;
2945 vsi->rx_buf_len = vsi->max_frame;
2946 vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
2947 break;
2948 case I40E_FLAG_RX_PS_ENABLED:
2949 vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
2950 vsi->rx_buf_len = I40E_RXBUFFER_2048;
2951 vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT;
2952 break;
2953 default:
2954 vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
2955 vsi->rx_buf_len = I40E_RXBUFFER_2048;
2956 vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS;
2957 break;
2958 }
2959
Vasu Dev38e00432014-08-01 13:27:03 -07002960#ifdef I40E_FCOE
2961 /* setup rx buffer for FCoE */
2962 if ((vsi->type == I40E_VSI_FCOE) &&
2963 (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) {
2964 vsi->rx_hdr_len = 0;
2965 vsi->rx_buf_len = I40E_RXBUFFER_3072;
2966 vsi->max_frame = I40E_RXBUFFER_3072;
2967 vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
2968 }
2969
2970#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002971 /* round up for the chip's needs */
2972 vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len,
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002973 BIT_ULL(I40E_RXQ_CTX_HBUFF_SHIFT));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002974 vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002975 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002976
2977 /* set up individual rings */
2978 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002979 err = i40e_configure_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002980
2981 return err;
2982}
2983
2984/**
2985 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
2986 * @vsi: ptr to the VSI
2987 **/
2988static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
2989{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00002990 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002991 u16 qoffset, qcount;
2992 int i, n;
2993
Parikh, Neeravcd238a32015-02-21 06:43:37 +00002994 if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
2995 /* Reset the TC information */
2996 for (i = 0; i < vsi->num_queue_pairs; i++) {
2997 rx_ring = vsi->rx_rings[i];
2998 tx_ring = vsi->tx_rings[i];
2999 rx_ring->dcb_tc = 0;
3000 tx_ring->dcb_tc = 0;
3001 }
3002 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003003
3004 for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04003005 if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003006 continue;
3007
3008 qoffset = vsi->tc_config.tc_info[n].qoffset;
3009 qcount = vsi->tc_config.tc_info[n].qcount;
3010 for (i = qoffset; i < (qoffset + qcount); i++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00003011 rx_ring = vsi->rx_rings[i];
3012 tx_ring = vsi->tx_rings[i];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003013 rx_ring->dcb_tc = n;
3014 tx_ring->dcb_tc = n;
3015 }
3016 }
3017}
3018
3019/**
3020 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
3021 * @vsi: ptr to the VSI
3022 **/
3023static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
3024{
3025 if (vsi->netdev)
3026 i40e_set_rx_mode(vsi->netdev);
3027}
3028
3029/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003030 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
3031 * @vsi: Pointer to the targeted VSI
3032 *
3033 * This function replays the hlist on the hw where all the SB Flow Director
3034 * filters were saved.
3035 **/
3036static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
3037{
3038 struct i40e_fdir_filter *filter;
3039 struct i40e_pf *pf = vsi->back;
3040 struct hlist_node *node;
3041
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003042 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3043 return;
3044
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003045 hlist_for_each_entry_safe(filter, node,
3046 &pf->fdir_filter_list, fdir_node) {
3047 i40e_add_del_fdir(vsi, filter, true);
3048 }
3049}
3050
3051/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003052 * i40e_vsi_configure - Set up the VSI for action
3053 * @vsi: the VSI being configured
3054 **/
3055static int i40e_vsi_configure(struct i40e_vsi *vsi)
3056{
3057 int err;
3058
3059 i40e_set_vsi_rx_mode(vsi);
3060 i40e_restore_vlan(vsi);
3061 i40e_vsi_config_dcb_rings(vsi);
3062 err = i40e_vsi_configure_tx(vsi);
3063 if (!err)
3064 err = i40e_vsi_configure_rx(vsi);
3065
3066 return err;
3067}
3068
3069/**
3070 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3071 * @vsi: the VSI being configured
3072 **/
3073static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
3074{
3075 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003076 struct i40e_hw *hw = &pf->hw;
3077 u16 vector;
3078 int i, q;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003079 u32 qp;
3080
3081 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3082 * and PFINT_LNKLSTn registers, e.g.:
3083 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3084 */
3085 qp = vsi->base_queue;
3086 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +00003087 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003088 struct i40e_q_vector *q_vector = vsi->q_vectors[i];
3089
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003090 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
3091 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3092 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
3093 q_vector->rx.itr);
3094 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
3095 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3096 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
3097 q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003098 wr32(hw, I40E_PFINT_RATEN(vector - 1),
3099 INTRL_USEC_TO_REG(vsi->int_rate_limit));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003100
3101 /* Linked list for the queuepairs assigned to this vector */
3102 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
3103 for (q = 0; q < q_vector->num_ringpairs; q++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003104 u32 val;
3105
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003106 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3107 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3108 (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
3109 (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
3110 (I40E_QUEUE_TYPE_TX
3111 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
3112
3113 wr32(hw, I40E_QINT_RQCTL(qp), val);
3114
3115 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3116 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3117 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
3118 ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
3119 (I40E_QUEUE_TYPE_RX
3120 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3121
3122 /* Terminate the linked list */
3123 if (q == (q_vector->num_ringpairs - 1))
3124 val |= (I40E_QUEUE_END_OF_LIST
3125 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3126
3127 wr32(hw, I40E_QINT_TQCTL(qp), val);
3128 qp++;
3129 }
3130 }
3131
3132 i40e_flush(hw);
3133}
3134
3135/**
3136 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3137 * @hw: ptr to the hardware info
3138 **/
Jacob Kellerab437b52014-12-14 01:55:08 +00003139static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003140{
Jacob Kellerab437b52014-12-14 01:55:08 +00003141 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003142 u32 val;
3143
3144 /* clear things first */
3145 wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
3146 rd32(hw, I40E_PFINT_ICR0); /* read to clear */
3147
3148 val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
3149 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
3150 I40E_PFINT_ICR0_ENA_GRST_MASK |
3151 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
3152 I40E_PFINT_ICR0_ENA_GPIO_MASK |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003153 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
3154 I40E_PFINT_ICR0_ENA_VFLR_MASK |
3155 I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3156
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003157 if (pf->flags & I40E_FLAG_IWARP_ENABLED)
3158 val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3159
Jacob Kellerab437b52014-12-14 01:55:08 +00003160 if (pf->flags & I40E_FLAG_PTP)
3161 val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
3162
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003163 wr32(hw, I40E_PFINT_ICR0_ENA, val);
3164
3165 /* SW_ITR_IDX = 0, but don't change INTENA */
Anjali Singhai Jain84ed40e2013-11-26 10:49:32 +00003166 wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
3167 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003168
3169 /* OTHER_ITR_IDX = 0 */
3170 wr32(hw, I40E_PFINT_STAT_CTL0, 0);
3171}
3172
3173/**
3174 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3175 * @vsi: the VSI being configured
3176 **/
3177static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
3178{
Alexander Duyck493fb302013-09-28 07:01:44 +00003179 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003180 struct i40e_pf *pf = vsi->back;
3181 struct i40e_hw *hw = &pf->hw;
3182 u32 val;
3183
3184 /* set the ITR configuration */
3185 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
3186 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3187 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
3188 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
3189 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3190 wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
3191
Jacob Kellerab437b52014-12-14 01:55:08 +00003192 i40e_enable_misc_int_causes(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003193
3194 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3195 wr32(hw, I40E_PFINT_LNKLST0, 0);
3196
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00003197 /* Associate the queue pair to the vector and enable the queue int */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003198 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3199 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3200 (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3201
3202 wr32(hw, I40E_QINT_RQCTL(0), val);
3203
3204 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3205 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3206 (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3207
3208 wr32(hw, I40E_QINT_TQCTL(0), val);
3209 i40e_flush(hw);
3210}
3211
3212/**
Mitch Williams2ef28cf2013-11-28 06:39:32 +00003213 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3214 * @pf: board private structure
3215 **/
3216void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
3217{
3218 struct i40e_hw *hw = &pf->hw;
3219
3220 wr32(hw, I40E_PFINT_DYN_CTL0,
3221 I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
3222 i40e_flush(hw);
3223}
3224
3225/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003226 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3227 * @pf: board private structure
3228 **/
Shannon Nelson116a57d2013-09-28 07:13:59 +00003229void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003230{
3231 struct i40e_hw *hw = &pf->hw;
3232 u32 val;
3233
3234 val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
3235 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
3236 (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
3237
3238 wr32(hw, I40E_PFINT_DYN_CTL0, val);
3239 i40e_flush(hw);
3240}
3241
3242/**
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00003243 * i40e_irq_dynamic_disable - Disable default interrupt generation settings
3244 * @vsi: pointer to a vsi
Greg Rose03147772015-01-24 09:58:29 +00003245 * @vector: disable a particular Hw Interrupt vector
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00003246 **/
3247void i40e_irq_dynamic_disable(struct i40e_vsi *vsi, int vector)
3248{
3249 struct i40e_pf *pf = vsi->back;
3250 struct i40e_hw *hw = &pf->hw;
3251 u32 val;
3252
3253 val = I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
3254 wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val);
3255 i40e_flush(hw);
3256}
3257
3258/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003259 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3260 * @irq: interrupt number
3261 * @data: pointer to a q_vector
3262 **/
3263static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
3264{
3265 struct i40e_q_vector *q_vector = data;
3266
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003267 if (!q_vector->tx.ring && !q_vector->rx.ring)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003268 return IRQ_HANDLED;
3269
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003270 napi_schedule_irqoff(&q_vector->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003271
3272 return IRQ_HANDLED;
3273}
3274
3275/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003276 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3277 * @vsi: the VSI being configured
3278 * @basename: name for the vector
3279 *
3280 * Allocates MSI-X vectors and requests interrupts from the kernel.
3281 **/
3282static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
3283{
3284 int q_vectors = vsi->num_q_vectors;
3285 struct i40e_pf *pf = vsi->back;
3286 int base = vsi->base_vector;
3287 int rx_int_idx = 0;
3288 int tx_int_idx = 0;
3289 int vector, err;
3290
3291 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck493fb302013-09-28 07:01:44 +00003292 struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003293
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003294 if (q_vector->tx.ring && q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003295 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3296 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
3297 tx_int_idx++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003298 } else if (q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003299 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3300 "%s-%s-%d", basename, "rx", rx_int_idx++);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003301 } else if (q_vector->tx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003302 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3303 "%s-%s-%d", basename, "tx", tx_int_idx++);
3304 } else {
3305 /* skip this unused q_vector */
3306 continue;
3307 }
3308 err = request_irq(pf->msix_entries[base + vector].vector,
3309 vsi->irq_handler,
3310 0,
3311 q_vector->name,
3312 q_vector);
3313 if (err) {
3314 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003315 "MSIX request_irq failed, error: %d\n", err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003316 goto free_queue_irqs;
3317 }
3318 /* assign the mask for this irq */
3319 irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
3320 &q_vector->affinity_mask);
3321 }
3322
Shannon Nelson63741842014-04-23 04:50:16 +00003323 vsi->irqs_ready = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003324 return 0;
3325
3326free_queue_irqs:
3327 while (vector) {
3328 vector--;
3329 irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
3330 NULL);
3331 free_irq(pf->msix_entries[base + vector].vector,
3332 &(vsi->q_vectors[vector]));
3333 }
3334 return err;
3335}
3336
3337/**
3338 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3339 * @vsi: the VSI being un-configured
3340 **/
3341static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
3342{
3343 struct i40e_pf *pf = vsi->back;
3344 struct i40e_hw *hw = &pf->hw;
3345 int base = vsi->base_vector;
3346 int i;
3347
3348 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00003349 wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
3350 wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003351 }
3352
3353 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3354 for (i = vsi->base_vector;
3355 i < (vsi->num_q_vectors + vsi->base_vector); i++)
3356 wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
3357
3358 i40e_flush(hw);
3359 for (i = 0; i < vsi->num_q_vectors; i++)
3360 synchronize_irq(pf->msix_entries[i + base].vector);
3361 } else {
3362 /* Legacy and MSI mode - this stops all interrupt handling */
3363 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
3364 wr32(hw, I40E_PFINT_DYN_CTL0, 0);
3365 i40e_flush(hw);
3366 synchronize_irq(pf->pdev->irq);
3367 }
3368}
3369
3370/**
3371 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3372 * @vsi: the VSI being configured
3373 **/
3374static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
3375{
3376 struct i40e_pf *pf = vsi->back;
3377 int i;
3378
3379 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
Jesse Brandeburg78455482015-07-23 16:54:41 -04003380 for (i = 0; i < vsi->num_q_vectors; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003381 i40e_irq_dynamic_enable(vsi, i);
3382 } else {
3383 i40e_irq_dynamic_enable_icr0(pf);
3384 }
3385
Jesse Brandeburg1022cb62013-09-28 07:13:08 +00003386 i40e_flush(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003387 return 0;
3388}
3389
3390/**
3391 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3392 * @pf: board private structure
3393 **/
3394static void i40e_stop_misc_vector(struct i40e_pf *pf)
3395{
3396 /* Disable ICR 0 */
3397 wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
3398 i40e_flush(&pf->hw);
3399}
3400
3401/**
3402 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3403 * @irq: interrupt number
3404 * @data: pointer to a q_vector
3405 *
3406 * This is the handler used for all MSI/Legacy interrupts, and deals
3407 * with both queue and non-queue interrupts. This is also used in
3408 * MSIX mode to handle the non-queue interrupts.
3409 **/
3410static irqreturn_t i40e_intr(int irq, void *data)
3411{
3412 struct i40e_pf *pf = (struct i40e_pf *)data;
3413 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003414 irqreturn_t ret = IRQ_NONE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003415 u32 icr0, icr0_remaining;
3416 u32 val, ena_mask;
3417
3418 icr0 = rd32(hw, I40E_PFINT_ICR0);
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003419 ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003420
Shannon Nelson116a57d2013-09-28 07:13:59 +00003421 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3422 if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003423 goto enable_intr;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003424
Shannon Nelsoncd92e722013-11-16 10:00:44 +00003425 /* if interrupt but no bits showing, must be SWINT */
3426 if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
3427 (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
3428 pf->sw_int_count++;
3429
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003430 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
3431 (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
3432 ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3433 icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3434 dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n");
3435 }
3436
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003437 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3438 if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003439 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
3440 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003441
3442 /* temporarily disable queue cause for NAPI processing */
3443 u32 qval = rd32(hw, I40E_QINT_RQCTL(0));
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003444
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003445 qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
3446 wr32(hw, I40E_QINT_RQCTL(0), qval);
3447
3448 qval = rd32(hw, I40E_QINT_TQCTL(0));
3449 qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
3450 wr32(hw, I40E_QINT_TQCTL(0), qval);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003451
3452 if (!test_bit(__I40E_DOWN, &pf->state))
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003453 napi_schedule_irqoff(&q_vector->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003454 }
3455
3456 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
3457 ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3458 set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
3459 }
3460
3461 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
3462 ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
3463 set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
3464 }
3465
3466 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
3467 ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
3468 set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
3469 }
3470
3471 if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
3472 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
3473 set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
3474 ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
3475 val = rd32(hw, I40E_GLGEN_RSTAT);
3476 val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
3477 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003478 if (val == I40E_RESET_CORER) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003479 pf->corer_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003480 } else if (val == I40E_RESET_GLOBR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003481 pf->globr_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003482 } else if (val == I40E_RESET_EMPR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003483 pf->empr_count++;
Anjali Singhai Jain9df42d12015-01-24 09:58:40 +00003484 set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003485 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003486 }
3487
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003488 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
3489 icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
3490 dev_info(&pf->pdev->dev, "HMC error interrupt\n");
Anjali Singhai Jain25fc0e62015-03-31 00:45:01 -07003491 dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
3492 rd32(hw, I40E_PFHMC_ERRORINFO),
3493 rd32(hw, I40E_PFHMC_ERRORDATA));
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003494 }
3495
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003496 if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
3497 u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
3498
3499 if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
Jacob Kellercafa1fc2014-04-24 18:05:03 -07003500 icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003501 i40e_ptp_tx_hwtstamp(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003502 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003503 }
3504
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003505 /* If a critical error is pending we have no choice but to reset the
3506 * device.
3507 * Report and mask out any remaining unexpected interrupts.
3508 */
3509 icr0_remaining = icr0 & ena_mask;
3510 if (icr0_remaining) {
3511 dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
3512 icr0_remaining);
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003513 if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003514 (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
Anjali Singhai Jainc0c28972014-02-12 01:45:34 +00003515 (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003516 dev_info(&pf->pdev->dev, "device will be reset\n");
3517 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
3518 i40e_service_event_schedule(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003519 }
3520 ena_mask &= ~icr0_remaining;
3521 }
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003522 ret = IRQ_HANDLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003523
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003524enable_intr:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003525 /* re-enable interrupt causes */
3526 wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003527 if (!test_bit(__I40E_DOWN, &pf->state)) {
3528 i40e_service_event_schedule(pf);
3529 i40e_irq_dynamic_enable_icr0(pf);
3530 }
3531
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003532 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003533}
3534
3535/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003536 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3537 * @tx_ring: tx ring to clean
3538 * @budget: how many cleans we're allowed
3539 *
3540 * Returns true if there's any budget left (e.g. the clean is finished)
3541 **/
3542static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
3543{
3544 struct i40e_vsi *vsi = tx_ring->vsi;
3545 u16 i = tx_ring->next_to_clean;
3546 struct i40e_tx_buffer *tx_buf;
3547 struct i40e_tx_desc *tx_desc;
3548
3549 tx_buf = &tx_ring->tx_bi[i];
3550 tx_desc = I40E_TX_DESC(tx_ring, i);
3551 i -= tx_ring->count;
3552
3553 do {
3554 struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
3555
3556 /* if next_to_watch is not set then there is no work pending */
3557 if (!eop_desc)
3558 break;
3559
3560 /* prevent any other reads prior to eop_desc */
3561 read_barrier_depends();
3562
3563 /* if the descriptor isn't done, no work yet to do */
3564 if (!(eop_desc->cmd_type_offset_bsz &
3565 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
3566 break;
3567
3568 /* clear next_to_watch to prevent false hangs */
3569 tx_buf->next_to_watch = NULL;
3570
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003571 tx_desc->buffer_addr = 0;
3572 tx_desc->cmd_type_offset_bsz = 0;
3573 /* move past filter desc */
3574 tx_buf++;
3575 tx_desc++;
3576 i++;
3577 if (unlikely(!i)) {
3578 i -= tx_ring->count;
3579 tx_buf = tx_ring->tx_bi;
3580 tx_desc = I40E_TX_DESC(tx_ring, 0);
3581 }
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003582 /* unmap skb header data */
3583 dma_unmap_single(tx_ring->dev,
3584 dma_unmap_addr(tx_buf, dma),
3585 dma_unmap_len(tx_buf, len),
3586 DMA_TO_DEVICE);
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003587 if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
3588 kfree(tx_buf->raw_buf);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003589
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003590 tx_buf->raw_buf = NULL;
3591 tx_buf->tx_flags = 0;
3592 tx_buf->next_to_watch = NULL;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003593 dma_unmap_len_set(tx_buf, len, 0);
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003594 tx_desc->buffer_addr = 0;
3595 tx_desc->cmd_type_offset_bsz = 0;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003596
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003597 /* move us past the eop_desc for start of next FD desc */
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003598 tx_buf++;
3599 tx_desc++;
3600 i++;
3601 if (unlikely(!i)) {
3602 i -= tx_ring->count;
3603 tx_buf = tx_ring->tx_bi;
3604 tx_desc = I40E_TX_DESC(tx_ring, 0);
3605 }
3606
3607 /* update budget accounting */
3608 budget--;
3609 } while (likely(budget));
3610
3611 i += tx_ring->count;
3612 tx_ring->next_to_clean = i;
3613
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003614 if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
Jesse Brandeburg78455482015-07-23 16:54:41 -04003615 i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003616
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003617 return budget > 0;
3618}
3619
3620/**
3621 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3622 * @irq: interrupt number
3623 * @data: pointer to a q_vector
3624 **/
3625static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
3626{
3627 struct i40e_q_vector *q_vector = data;
3628 struct i40e_vsi *vsi;
3629
3630 if (!q_vector->tx.ring)
3631 return IRQ_HANDLED;
3632
3633 vsi = q_vector->tx.ring->vsi;
3634 i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
3635
3636 return IRQ_HANDLED;
3637}
3638
3639/**
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003640 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003641 * @vsi: the VSI being configured
3642 * @v_idx: vector index
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003643 * @qp_idx: queue pair index
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003644 **/
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04003645static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003646{
Alexander Duyck493fb302013-09-28 07:01:44 +00003647 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyck9f65e152013-09-28 06:00:58 +00003648 struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
3649 struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003650
3651 tx_ring->q_vector = q_vector;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003652 tx_ring->next = q_vector->tx.ring;
3653 q_vector->tx.ring = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003654 q_vector->tx.count++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003655
3656 rx_ring->q_vector = q_vector;
3657 rx_ring->next = q_vector->rx.ring;
3658 q_vector->rx.ring = rx_ring;
3659 q_vector->rx.count++;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003660}
3661
3662/**
3663 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3664 * @vsi: the VSI being configured
3665 *
3666 * This function maps descriptor rings to the queue-specific vectors
3667 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3668 * one vector per queue pair, but on a constrained vector budget, we
3669 * group the queue pairs as "efficiently" as possible.
3670 **/
3671static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
3672{
3673 int qp_remaining = vsi->num_queue_pairs;
3674 int q_vectors = vsi->num_q_vectors;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003675 int num_ringpairs;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003676 int v_start = 0;
3677 int qp_idx = 0;
3678
3679 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3680 * group them so there are multiple queues per vector.
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003681 * It is also important to go through all the vectors available to be
3682 * sure that if we don't use all the vectors, that the remaining vectors
3683 * are cleared. This is especially important when decreasing the
3684 * number of queues in use.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003685 */
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003686 for (; v_start < q_vectors; v_start++) {
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003687 struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
3688
3689 num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
3690
3691 q_vector->num_ringpairs = num_ringpairs;
3692
3693 q_vector->rx.count = 0;
3694 q_vector->tx.count = 0;
3695 q_vector->rx.ring = NULL;
3696 q_vector->tx.ring = NULL;
3697
3698 while (num_ringpairs--) {
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04003699 i40e_map_vector_to_qp(vsi, v_start, qp_idx);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003700 qp_idx++;
3701 qp_remaining--;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003702 }
3703 }
3704}
3705
3706/**
3707 * i40e_vsi_request_irq - Request IRQ from the OS
3708 * @vsi: the VSI being configured
3709 * @basename: name for the vector
3710 **/
3711static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
3712{
3713 struct i40e_pf *pf = vsi->back;
3714 int err;
3715
3716 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
3717 err = i40e_vsi_request_irq_msix(vsi, basename);
3718 else if (pf->flags & I40E_FLAG_MSI_ENABLED)
3719 err = request_irq(pf->pdev->irq, i40e_intr, 0,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00003720 pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003721 else
3722 err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00003723 pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003724
3725 if (err)
3726 dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
3727
3728 return err;
3729}
3730
3731#ifdef CONFIG_NET_POLL_CONTROLLER
3732/**
3733 * i40e_netpoll - A Polling 'interrupt'handler
3734 * @netdev: network interface device structure
3735 *
3736 * This is used by netconsole to send skbs without having to re-enable
3737 * interrupts. It's not called while the normal interrupt routine is executing.
3738 **/
Vasu Dev38e00432014-08-01 13:27:03 -07003739#ifdef I40E_FCOE
3740void i40e_netpoll(struct net_device *netdev)
3741#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003742static void i40e_netpoll(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -07003743#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003744{
3745 struct i40e_netdev_priv *np = netdev_priv(netdev);
3746 struct i40e_vsi *vsi = np->vsi;
3747 struct i40e_pf *pf = vsi->back;
3748 int i;
3749
3750 /* if interface is down do nothing */
3751 if (test_bit(__I40E_DOWN, &vsi->state))
3752 return;
3753
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003754 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3755 for (i = 0; i < vsi->num_q_vectors; i++)
Alexander Duyck493fb302013-09-28 07:01:44 +00003756 i40e_msix_clean_rings(0, vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003757 } else {
3758 i40e_intr(pf->pdev->irq, netdev);
3759 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003760}
3761#endif
3762
3763/**
Neerav Parikh23527302014-06-03 23:50:15 +00003764 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3765 * @pf: the PF being configured
3766 * @pf_q: the PF queue
3767 * @enable: enable or disable state of the queue
3768 *
3769 * This routine will wait for the given Tx queue of the PF to reach the
3770 * enabled or disabled state.
3771 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3772 * multiple retries; else will return 0 in case of success.
3773 **/
3774static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3775{
3776 int i;
3777 u32 tx_reg;
3778
3779 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3780 tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
3781 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
3782 break;
3783
Neerav Parikhf98a2002014-09-13 07:40:44 +00003784 usleep_range(10, 20);
Neerav Parikh23527302014-06-03 23:50:15 +00003785 }
3786 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3787 return -ETIMEDOUT;
3788
3789 return 0;
3790}
3791
3792/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003793 * i40e_vsi_control_tx - Start or stop a VSI's rings
3794 * @vsi: the VSI being configured
3795 * @enable: start or stop the rings
3796 **/
3797static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
3798{
3799 struct i40e_pf *pf = vsi->back;
3800 struct i40e_hw *hw = &pf->hw;
Neerav Parikh23527302014-06-03 23:50:15 +00003801 int i, j, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003802 u32 tx_reg;
3803
3804 pf_q = vsi->base_queue;
3805 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Matt Jared351499ab2014-04-23 04:50:03 +00003806
3807 /* warn the TX unit of coming changes */
3808 i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
3809 if (!enable)
Neerav Parikhf98a2002014-09-13 07:40:44 +00003810 usleep_range(10, 20);
Matt Jared351499ab2014-04-23 04:50:03 +00003811
Mitch Williams6c5ef622014-02-20 19:29:16 -08003812 for (j = 0; j < 50; j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003813 tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
Mitch Williams6c5ef622014-02-20 19:29:16 -08003814 if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
3815 ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
3816 break;
3817 usleep_range(1000, 2000);
3818 }
Mitch Williamsfda972f2013-11-28 06:39:29 +00003819 /* Skip if the queue is already in the requested state */
Catherine Sullivan7c122002014-03-14 07:32:29 +00003820 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
Mitch Williamsfda972f2013-11-28 06:39:29 +00003821 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003822
3823 /* turn on/off the queue */
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003824 if (enable) {
3825 wr32(hw, I40E_QTX_HEAD(pf_q), 0);
Mitch Williams6c5ef622014-02-20 19:29:16 -08003826 tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003827 } else {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003828 tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003829 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003830
3831 wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
Neerav Parikh69129dc2014-11-12 00:18:46 +00003832 /* No waiting for the Tx queue to disable */
3833 if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
3834 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003835
3836 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00003837 ret = i40e_pf_txq_wait(pf, pf_q, enable);
3838 if (ret) {
3839 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003840 "VSI seid %d Tx ring %d %sable timeout\n",
3841 vsi->seid, pf_q, (enable ? "en" : "dis"));
Neerav Parikh23527302014-06-03 23:50:15 +00003842 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003843 }
3844 }
3845
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003846 if (hw->revision_id == 0)
3847 mdelay(50);
Neerav Parikh23527302014-06-03 23:50:15 +00003848 return ret;
3849}
3850
3851/**
3852 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
3853 * @pf: the PF being configured
3854 * @pf_q: the PF queue
3855 * @enable: enable or disable state of the queue
3856 *
3857 * This routine will wait for the given Rx queue of the PF to reach the
3858 * enabled or disabled state.
3859 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3860 * multiple retries; else will return 0 in case of success.
3861 **/
3862static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3863{
3864 int i;
3865 u32 rx_reg;
3866
3867 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3868 rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
3869 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
3870 break;
3871
Neerav Parikhf98a2002014-09-13 07:40:44 +00003872 usleep_range(10, 20);
Neerav Parikh23527302014-06-03 23:50:15 +00003873 }
3874 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3875 return -ETIMEDOUT;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003876
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003877 return 0;
3878}
3879
3880/**
3881 * i40e_vsi_control_rx - Start or stop a VSI's rings
3882 * @vsi: the VSI being configured
3883 * @enable: start or stop the rings
3884 **/
3885static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
3886{
3887 struct i40e_pf *pf = vsi->back;
3888 struct i40e_hw *hw = &pf->hw;
Neerav Parikh23527302014-06-03 23:50:15 +00003889 int i, j, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003890 u32 rx_reg;
3891
3892 pf_q = vsi->base_queue;
3893 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Mitch Williams6c5ef622014-02-20 19:29:16 -08003894 for (j = 0; j < 50; j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003895 rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
Mitch Williams6c5ef622014-02-20 19:29:16 -08003896 if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
3897 ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
3898 break;
3899 usleep_range(1000, 2000);
3900 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003901
Catherine Sullivan7c122002014-03-14 07:32:29 +00003902 /* Skip if the queue is already in the requested state */
3903 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
3904 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003905
3906 /* turn on/off the queue */
3907 if (enable)
Mitch Williams6c5ef622014-02-20 19:29:16 -08003908 rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003909 else
Mitch Williams6c5ef622014-02-20 19:29:16 -08003910 rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003911 wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
3912
3913 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00003914 ret = i40e_pf_rxq_wait(pf, pf_q, enable);
3915 if (ret) {
3916 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003917 "VSI seid %d Rx ring %d %sable timeout\n",
3918 vsi->seid, pf_q, (enable ? "en" : "dis"));
Neerav Parikh23527302014-06-03 23:50:15 +00003919 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003920 }
3921 }
3922
Neerav Parikh23527302014-06-03 23:50:15 +00003923 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003924}
3925
3926/**
3927 * i40e_vsi_control_rings - Start or stop a VSI's rings
3928 * @vsi: the VSI being configured
3929 * @enable: start or stop the rings
3930 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00003931int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003932{
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00003933 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003934
3935 /* do rx first for enable and last for disable */
3936 if (request) {
3937 ret = i40e_vsi_control_rx(vsi, request);
3938 if (ret)
3939 return ret;
3940 ret = i40e_vsi_control_tx(vsi, request);
3941 } else {
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00003942 /* Ignore return value, we need to shutdown whatever we can */
3943 i40e_vsi_control_tx(vsi, request);
3944 i40e_vsi_control_rx(vsi, request);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003945 }
3946
3947 return ret;
3948}
3949
3950/**
3951 * i40e_vsi_free_irq - Free the irq association with the OS
3952 * @vsi: the VSI being configured
3953 **/
3954static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
3955{
3956 struct i40e_pf *pf = vsi->back;
3957 struct i40e_hw *hw = &pf->hw;
3958 int base = vsi->base_vector;
3959 u32 val, qp;
3960 int i;
3961
3962 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3963 if (!vsi->q_vectors)
3964 return;
3965
Shannon Nelson63741842014-04-23 04:50:16 +00003966 if (!vsi->irqs_ready)
3967 return;
3968
3969 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003970 for (i = 0; i < vsi->num_q_vectors; i++) {
3971 u16 vector = i + base;
3972
3973 /* free only the irqs that were actually requested */
Shannon Nelson78681b12013-11-28 06:39:36 +00003974 if (!vsi->q_vectors[i] ||
3975 !vsi->q_vectors[i]->num_ringpairs)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003976 continue;
3977
3978 /* clear the affinity_mask in the IRQ descriptor */
3979 irq_set_affinity_hint(pf->msix_entries[vector].vector,
3980 NULL);
3981 free_irq(pf->msix_entries[vector].vector,
Alexander Duyck493fb302013-09-28 07:01:44 +00003982 vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003983
3984 /* Tear down the interrupt queue link list
3985 *
3986 * We know that they come in pairs and always
3987 * the Rx first, then the Tx. To clear the
3988 * link list, stick the EOL value into the
3989 * next_q field of the registers.
3990 */
3991 val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
3992 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
3993 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
3994 val |= I40E_QUEUE_END_OF_LIST
3995 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
3996 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
3997
3998 while (qp != I40E_QUEUE_END_OF_LIST) {
3999 u32 next;
4000
4001 val = rd32(hw, I40E_QINT_RQCTL(qp));
4002
4003 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4004 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4005 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4006 I40E_QINT_RQCTL_INTEVENT_MASK);
4007
4008 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4009 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4010
4011 wr32(hw, I40E_QINT_RQCTL(qp), val);
4012
4013 val = rd32(hw, I40E_QINT_TQCTL(qp));
4014
4015 next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
4016 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
4017
4018 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4019 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4020 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4021 I40E_QINT_TQCTL_INTEVENT_MASK);
4022
4023 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4024 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4025
4026 wr32(hw, I40E_QINT_TQCTL(qp), val);
4027 qp = next;
4028 }
4029 }
4030 } else {
4031 free_irq(pf->pdev->irq, pf);
4032
4033 val = rd32(hw, I40E_PFINT_LNKLST0);
4034 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4035 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4036 val |= I40E_QUEUE_END_OF_LIST
4037 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
4038 wr32(hw, I40E_PFINT_LNKLST0, val);
4039
4040 val = rd32(hw, I40E_QINT_RQCTL(qp));
4041 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4042 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4043 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4044 I40E_QINT_RQCTL_INTEVENT_MASK);
4045
4046 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4047 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4048
4049 wr32(hw, I40E_QINT_RQCTL(qp), val);
4050
4051 val = rd32(hw, I40E_QINT_TQCTL(qp));
4052
4053 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4054 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4055 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4056 I40E_QINT_TQCTL_INTEVENT_MASK);
4057
4058 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4059 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4060
4061 wr32(hw, I40E_QINT_TQCTL(qp), val);
4062 }
4063}
4064
4065/**
Alexander Duyck493fb302013-09-28 07:01:44 +00004066 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4067 * @vsi: the VSI being configured
4068 * @v_idx: Index of vector to be freed
4069 *
4070 * This function frees the memory allocated to the q_vector. In addition if
4071 * NAPI is enabled it will delete any references to the NAPI struct prior
4072 * to freeing the q_vector.
4073 **/
4074static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
4075{
4076 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00004077 struct i40e_ring *ring;
Alexander Duyck493fb302013-09-28 07:01:44 +00004078
4079 if (!q_vector)
4080 return;
4081
4082 /* disassociate q_vector from rings */
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00004083 i40e_for_each_ring(ring, q_vector->tx)
4084 ring->q_vector = NULL;
4085
4086 i40e_for_each_ring(ring, q_vector->rx)
4087 ring->q_vector = NULL;
Alexander Duyck493fb302013-09-28 07:01:44 +00004088
4089 /* only VSI w/ an associated netdev is set up w/ NAPI */
4090 if (vsi->netdev)
4091 netif_napi_del(&q_vector->napi);
4092
4093 vsi->q_vectors[v_idx] = NULL;
4094
4095 kfree_rcu(q_vector, rcu);
4096}
4097
4098/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004099 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4100 * @vsi: the VSI being un-configured
4101 *
4102 * This frees the memory allocated to the q_vectors and
4103 * deletes references to the NAPI struct.
4104 **/
4105static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
4106{
4107 int v_idx;
4108
Alexander Duyck493fb302013-09-28 07:01:44 +00004109 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
4110 i40e_free_q_vector(vsi, v_idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004111}
4112
4113/**
4114 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4115 * @pf: board private structure
4116 **/
4117static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
4118{
4119 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4120 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4121 pci_disable_msix(pf->pdev);
4122 kfree(pf->msix_entries);
4123 pf->msix_entries = NULL;
Shannon Nelson3b444392015-02-26 16:15:57 +00004124 kfree(pf->irq_pile);
4125 pf->irq_pile = NULL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004126 } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
4127 pci_disable_msi(pf->pdev);
4128 }
4129 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
4130}
4131
4132/**
4133 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4134 * @pf: board private structure
4135 *
4136 * We go through and clear interrupt specific resources and reset the structure
4137 * to pre-load conditions
4138 **/
4139static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
4140{
4141 int i;
4142
Shannon Nelsone1477582015-02-21 06:44:33 +00004143 i40e_stop_misc_vector(pf);
4144 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4145 synchronize_irq(pf->msix_entries[0].vector);
4146 free_irq(pf->msix_entries[0].vector, pf);
4147 }
4148
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004149 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
Mitch Williams505682c2014-05-20 08:01:37 +00004150 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004151 if (pf->vsi[i])
4152 i40e_vsi_free_q_vectors(pf->vsi[i]);
4153 i40e_reset_interrupt_capability(pf);
4154}
4155
4156/**
4157 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4158 * @vsi: the VSI being configured
4159 **/
4160static void i40e_napi_enable_all(struct i40e_vsi *vsi)
4161{
4162 int q_idx;
4163
4164 if (!vsi->netdev)
4165 return;
4166
4167 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
Alexander Duyck493fb302013-09-28 07:01:44 +00004168 napi_enable(&vsi->q_vectors[q_idx]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004169}
4170
4171/**
4172 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4173 * @vsi: the VSI being configured
4174 **/
4175static void i40e_napi_disable_all(struct i40e_vsi *vsi)
4176{
4177 int q_idx;
4178
4179 if (!vsi->netdev)
4180 return;
4181
4182 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
Alexander Duyck493fb302013-09-28 07:01:44 +00004183 napi_disable(&vsi->q_vectors[q_idx]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004184}
4185
4186/**
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004187 * i40e_vsi_close - Shut down a VSI
4188 * @vsi: the vsi to be quelled
4189 **/
4190static void i40e_vsi_close(struct i40e_vsi *vsi)
4191{
4192 if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
4193 i40e_down(vsi);
4194 i40e_vsi_free_irq(vsi);
4195 i40e_vsi_free_tx_resources(vsi);
4196 i40e_vsi_free_rx_resources(vsi);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04004197 vsi->current_netdev_flags = 0;
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004198}
4199
4200/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004201 * i40e_quiesce_vsi - Pause a given VSI
4202 * @vsi: the VSI being paused
4203 **/
4204static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
4205{
4206 if (test_bit(__I40E_DOWN, &vsi->state))
4207 return;
4208
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004209 /* No need to disable FCoE VSI when Tx suspended */
4210 if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) &&
4211 vsi->type == I40E_VSI_FCOE) {
4212 dev_dbg(&vsi->back->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004213 "VSI seid %d skipping FCoE VSI disable\n", vsi->seid);
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004214 return;
4215 }
4216
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004217 set_bit(__I40E_NEEDS_RESTART, &vsi->state);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004218 if (vsi->netdev && netif_running(vsi->netdev))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004219 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004220 else
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004221 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004222}
4223
4224/**
4225 * i40e_unquiesce_vsi - Resume a given VSI
4226 * @vsi: the VSI being resumed
4227 **/
4228static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
4229{
4230 if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
4231 return;
4232
4233 clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
4234 if (vsi->netdev && netif_running(vsi->netdev))
4235 vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
4236 else
Shannon Nelson8276f752014-03-14 07:32:27 +00004237 i40e_vsi_open(vsi); /* this clears the DOWN bit */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004238}
4239
4240/**
4241 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4242 * @pf: the PF
4243 **/
4244static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
4245{
4246 int v;
4247
Mitch Williams505682c2014-05-20 08:01:37 +00004248 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004249 if (pf->vsi[v])
4250 i40e_quiesce_vsi(pf->vsi[v]);
4251 }
4252}
4253
4254/**
4255 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4256 * @pf: the PF
4257 **/
4258static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
4259{
4260 int v;
4261
Mitch Williams505682c2014-05-20 08:01:37 +00004262 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004263 if (pf->vsi[v])
4264 i40e_unquiesce_vsi(pf->vsi[v]);
4265 }
4266}
4267
Neerav Parikh69129dc2014-11-12 00:18:46 +00004268#ifdef CONFIG_I40E_DCB
4269/**
4270 * i40e_vsi_wait_txq_disabled - Wait for VSI's queues to be disabled
4271 * @vsi: the VSI being configured
4272 *
4273 * This function waits for the given VSI's Tx queues to be disabled.
4274 **/
4275static int i40e_vsi_wait_txq_disabled(struct i40e_vsi *vsi)
4276{
4277 struct i40e_pf *pf = vsi->back;
4278 int i, pf_q, ret;
4279
4280 pf_q = vsi->base_queue;
4281 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4282 /* Check and wait for the disable status of the queue */
4283 ret = i40e_pf_txq_wait(pf, pf_q, false);
4284 if (ret) {
4285 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004286 "VSI seid %d Tx ring %d disable timeout\n",
4287 vsi->seid, pf_q);
Neerav Parikh69129dc2014-11-12 00:18:46 +00004288 return ret;
4289 }
4290 }
4291
4292 return 0;
4293}
4294
4295/**
4296 * i40e_pf_wait_txq_disabled - Wait for all queues of PF VSIs to be disabled
4297 * @pf: the PF
4298 *
4299 * This function waits for the Tx queues to be in disabled state for all the
4300 * VSIs that are managed by this PF.
4301 **/
4302static int i40e_pf_wait_txq_disabled(struct i40e_pf *pf)
4303{
4304 int v, ret = 0;
4305
4306 for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004307 /* No need to wait for FCoE VSI queues */
4308 if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) {
Neerav Parikh69129dc2014-11-12 00:18:46 +00004309 ret = i40e_vsi_wait_txq_disabled(pf->vsi[v]);
4310 if (ret)
4311 break;
4312 }
4313 }
4314
4315 return ret;
4316}
4317
4318#endif
Kiran Patilb03a8c12015-09-24 18:13:15 -04004319
4320/**
4321 * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
4322 * @q_idx: TX queue number
4323 * @vsi: Pointer to VSI struct
4324 *
4325 * This function checks specified queue for given VSI. Detects hung condition.
4326 * Sets hung bit since it is two step process. Before next run of service task
4327 * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not,
4328 * hung condition remain unchanged and during subsequent run, this function
4329 * issues SW interrupt to recover from hung condition.
4330 **/
4331static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
4332{
4333 struct i40e_ring *tx_ring = NULL;
4334 struct i40e_pf *pf;
4335 u32 head, val, tx_pending;
4336 int i;
4337
4338 pf = vsi->back;
4339
4340 /* now that we have an index, find the tx_ring struct */
4341 for (i = 0; i < vsi->num_queue_pairs; i++) {
4342 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
4343 if (q_idx == vsi->tx_rings[i]->queue_index) {
4344 tx_ring = vsi->tx_rings[i];
4345 break;
4346 }
4347 }
4348 }
4349
4350 if (!tx_ring)
4351 return;
4352
4353 /* Read interrupt register */
4354 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
4355 val = rd32(&pf->hw,
4356 I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
4357 tx_ring->vsi->base_vector - 1));
4358 else
4359 val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
4360
4361 head = i40e_get_head(tx_ring);
4362
4363 tx_pending = i40e_get_tx_pending(tx_ring);
4364
4365 /* Interrupts are disabled and TX pending is non-zero,
4366 * trigger the SW interrupt (don't wait). Worst case
4367 * there will be one extra interrupt which may result
4368 * into not cleaning any queues because queues are cleaned.
4369 */
4370 if (tx_pending && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK)))
4371 i40e_force_wb(vsi, tx_ring->q_vector);
4372}
4373
4374/**
4375 * i40e_detect_recover_hung - Function to detect and recover hung_queues
4376 * @pf: pointer to PF struct
4377 *
4378 * LAN VSI has netdev and netdev has TX queues. This function is to check
4379 * each of those TX queues if they are hung, trigger recovery by issuing
4380 * SW interrupt.
4381 **/
4382static void i40e_detect_recover_hung(struct i40e_pf *pf)
4383{
4384 struct net_device *netdev;
4385 struct i40e_vsi *vsi;
4386 int i;
4387
4388 /* Only for LAN VSI */
4389 vsi = pf->vsi[pf->lan_vsi];
4390
4391 if (!vsi)
4392 return;
4393
4394 /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
4395 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
4396 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
4397 return;
4398
4399 /* Make sure type is MAIN VSI */
4400 if (vsi->type != I40E_VSI_MAIN)
4401 return;
4402
4403 netdev = vsi->netdev;
4404 if (!netdev)
4405 return;
4406
4407 /* Bail out if netif_carrier is not OK */
4408 if (!netif_carrier_ok(netdev))
4409 return;
4410
4411 /* Go thru' TX queues for netdev */
4412 for (i = 0; i < netdev->num_tx_queues; i++) {
4413 struct netdev_queue *q;
4414
4415 q = netdev_get_tx_queue(netdev, i);
4416 if (q)
4417 i40e_detect_recover_hung_queue(i, vsi);
4418 }
4419}
4420
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004421/**
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004422 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00004423 * @pf: pointer to PF
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004424 *
4425 * Get TC map for ISCSI PF type that will include iSCSI TC
4426 * and LAN TC.
4427 **/
4428static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
4429{
4430 struct i40e_dcb_app_priority_table app;
4431 struct i40e_hw *hw = &pf->hw;
4432 u8 enabled_tc = 1; /* TC0 is always enabled */
4433 u8 tc, i;
4434 /* Get the iSCSI APP TLV */
4435 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4436
4437 for (i = 0; i < dcbcfg->numapps; i++) {
4438 app = dcbcfg->app[i];
4439 if (app.selector == I40E_APP_SEL_TCPIP &&
4440 app.protocolid == I40E_APP_PROTOID_ISCSI) {
4441 tc = dcbcfg->etscfg.prioritytable[app.priority];
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004442 enabled_tc |= BIT_ULL(tc);
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004443 break;
4444 }
4445 }
4446
4447 return enabled_tc;
4448}
4449
4450/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004451 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4452 * @dcbcfg: the corresponding DCBx configuration structure
4453 *
4454 * Return the number of TCs from given DCBx configuration
4455 **/
4456static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
4457{
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004458 u8 num_tc = 0;
4459 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004460
4461 /* Scan the ETS Config Priority Table to find
4462 * traffic class enabled for a given priority
4463 * and use the traffic class index to get the
4464 * number of traffic classes enabled
4465 */
4466 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
4467 if (dcbcfg->etscfg.prioritytable[i] > num_tc)
4468 num_tc = dcbcfg->etscfg.prioritytable[i];
4469 }
4470
4471 /* Traffic class index starts from zero so
4472 * increment to return the actual count
4473 */
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004474 return num_tc + 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004475}
4476
4477/**
4478 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4479 * @dcbcfg: the corresponding DCBx configuration structure
4480 *
4481 * Query the current DCB configuration and return the number of
4482 * traffic classes enabled from the given DCBX config
4483 **/
4484static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
4485{
4486 u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
4487 u8 enabled_tc = 1;
4488 u8 i;
4489
4490 for (i = 0; i < num_tc; i++)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004491 enabled_tc |= BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004492
4493 return enabled_tc;
4494}
4495
4496/**
4497 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4498 * @pf: PF being queried
4499 *
4500 * Return number of traffic classes enabled for the given PF
4501 **/
4502static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
4503{
4504 struct i40e_hw *hw = &pf->hw;
4505 u8 i, enabled_tc;
4506 u8 num_tc = 0;
4507 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4508
4509 /* If DCB is not enabled then always in single TC */
4510 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
4511 return 1;
4512
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004513 /* SFP mode will be enabled for all TCs on port */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004514 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4515 return i40e_dcb_get_num_tc(dcbcfg);
4516
4517 /* MFP mode return count of enabled TCs for this PF */
4518 if (pf->hw.func_caps.iscsi)
4519 enabled_tc = i40e_get_iscsi_tc_map(pf);
4520 else
Neerav Parikhfc51de92015-02-24 06:58:53 +00004521 return 1; /* Only TC0 */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004522
4523 /* At least have TC0 */
4524 enabled_tc = (enabled_tc ? enabled_tc : 0x1);
4525 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004526 if (enabled_tc & BIT_ULL(i))
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004527 num_tc++;
4528 }
4529 return num_tc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004530}
4531
4532/**
4533 * i40e_pf_get_default_tc - Get bitmap for first enabled TC
4534 * @pf: PF being queried
4535 *
4536 * Return a bitmap for first enabled traffic class for this PF.
4537 **/
4538static u8 i40e_pf_get_default_tc(struct i40e_pf *pf)
4539{
4540 u8 enabled_tc = pf->hw.func_caps.enabled_tcmap;
4541 u8 i = 0;
4542
4543 if (!enabled_tc)
4544 return 0x1; /* TC0 */
4545
4546 /* Find the first enabled TC */
4547 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004548 if (enabled_tc & BIT_ULL(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004549 break;
4550 }
4551
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004552 return BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004553}
4554
4555/**
4556 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4557 * @pf: PF being queried
4558 *
4559 * Return a bitmap for enabled traffic classes for this PF.
4560 **/
4561static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
4562{
4563 /* If DCB is not enabled for this PF then just return default TC */
4564 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
4565 return i40e_pf_get_default_tc(pf);
4566
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004567 /* SFP mode we want PF to be enabled for all TCs */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004568 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4569 return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
4570
Neerav Parikhfc51de92015-02-24 06:58:53 +00004571 /* MFP enabled and iSCSI PF type */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004572 if (pf->hw.func_caps.iscsi)
4573 return i40e_get_iscsi_tc_map(pf);
4574 else
Neerav Parikhfc51de92015-02-24 06:58:53 +00004575 return i40e_pf_get_default_tc(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004576}
4577
4578/**
4579 * i40e_vsi_get_bw_info - Query VSI BW Information
4580 * @vsi: the VSI being queried
4581 *
4582 * Returns 0 on success, negative value on failure
4583 **/
4584static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
4585{
4586 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
4587 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
4588 struct i40e_pf *pf = vsi->back;
4589 struct i40e_hw *hw = &pf->hw;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004590 i40e_status ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004591 u32 tc_bw_max;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004592 int i;
4593
4594 /* Get the VSI level BW configuration */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004595 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
4596 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004597 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004598 "couldn't get PF vsi bw config, err %s aq_err %s\n",
4599 i40e_stat_str(&pf->hw, ret),
4600 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004601 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004602 }
4603
4604 /* Get the VSI level BW configuration per TC */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004605 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
4606 NULL);
4607 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004608 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004609 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
4610 i40e_stat_str(&pf->hw, ret),
4611 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004612 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004613 }
4614
4615 if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
4616 dev_info(&pf->pdev->dev,
4617 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4618 bw_config.tc_valid_bits,
4619 bw_ets_config.tc_valid_bits);
4620 /* Still continuing */
4621 }
4622
4623 vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
4624 vsi->bw_max_quanta = bw_config.max_bw;
4625 tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
4626 (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
4627 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4628 vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
4629 vsi->bw_ets_limit_credits[i] =
4630 le16_to_cpu(bw_ets_config.credits[i]);
4631 /* 3 bits out of 4 for each TC */
4632 vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
4633 }
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004634
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004635 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004636}
4637
4638/**
4639 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
4640 * @vsi: the VSI being configured
4641 * @enabled_tc: TC bitmap
4642 * @bw_credits: BW shared credits per TC
4643 *
4644 * Returns 0 on success, negative value on failure
4645 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004646static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004647 u8 *bw_share)
4648{
4649 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004650 i40e_status ret;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004651 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004652
4653 bw_data.tc_valid_bits = enabled_tc;
4654 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4655 bw_data.tc_bw_credits[i] = bw_share[i];
4656
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004657 ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
4658 NULL);
4659 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004660 dev_info(&vsi->back->pdev->dev,
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004661 "AQ command Config VSI BW allocation per TC failed = %d\n",
4662 vsi->back->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 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4667 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
4668
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004669 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004670}
4671
4672/**
4673 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
4674 * @vsi: the VSI being configured
4675 * @enabled_tc: TC map to be enabled
4676 *
4677 **/
4678static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4679{
4680 struct net_device *netdev = vsi->netdev;
4681 struct i40e_pf *pf = vsi->back;
4682 struct i40e_hw *hw = &pf->hw;
4683 u8 netdev_tc = 0;
4684 int i;
4685 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4686
4687 if (!netdev)
4688 return;
4689
4690 if (!enabled_tc) {
4691 netdev_reset_tc(netdev);
4692 return;
4693 }
4694
4695 /* Set up actual enabled TCs on the VSI */
4696 if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
4697 return;
4698
4699 /* set per TC queues for the VSI */
4700 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4701 /* Only set TC queues for enabled tcs
4702 *
4703 * e.g. For a VSI that has TC0 and TC3 enabled the
4704 * enabled_tc bitmap would be 0x00001001; the driver
4705 * will set the numtc for netdev as 2 that will be
4706 * referenced by the netdev layer as TC 0 and 1.
4707 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004708 if (vsi->tc_config.enabled_tc & BIT_ULL(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004709 netdev_set_tc_queue(netdev,
4710 vsi->tc_config.tc_info[i].netdev_tc,
4711 vsi->tc_config.tc_info[i].qcount,
4712 vsi->tc_config.tc_info[i].qoffset);
4713 }
4714
4715 /* Assign UP2TC map for the VSI */
4716 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
4717 /* Get the actual TC# for the UP */
4718 u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
4719 /* Get the mapped netdev TC# for the UP */
4720 netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
4721 netdev_set_prio_tc_map(netdev, i, netdev_tc);
4722 }
4723}
4724
4725/**
4726 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4727 * @vsi: the VSI being configured
4728 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4729 **/
4730static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
4731 struct i40e_vsi_context *ctxt)
4732{
4733 /* copy just the sections touched not the entire info
4734 * since not all sections are valid as returned by
4735 * update vsi params
4736 */
4737 vsi->info.mapping_flags = ctxt->info.mapping_flags;
4738 memcpy(&vsi->info.queue_mapping,
4739 &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
4740 memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
4741 sizeof(vsi->info.tc_mapping));
4742}
4743
4744/**
4745 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4746 * @vsi: VSI to be configured
4747 * @enabled_tc: TC bitmap
4748 *
4749 * This configures a particular VSI for TCs that are mapped to the
4750 * given TC bitmap. It uses default bandwidth share for TCs across
4751 * VSIs to configure TC for a particular VSI.
4752 *
4753 * NOTE:
4754 * It is expected that the VSI queues have been quisced before calling
4755 * this function.
4756 **/
4757static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4758{
4759 u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
4760 struct i40e_vsi_context ctxt;
4761 int ret = 0;
4762 int i;
4763
4764 /* Check if enabled_tc is same as existing or new TCs */
4765 if (vsi->tc_config.enabled_tc == enabled_tc)
4766 return ret;
4767
4768 /* Enable ETS TCs with equal BW Share for now across all VSIs */
4769 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004770 if (enabled_tc & BIT_ULL(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004771 bw_share[i] = 1;
4772 }
4773
4774 ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
4775 if (ret) {
4776 dev_info(&vsi->back->pdev->dev,
4777 "Failed configuring TC map %d for VSI %d\n",
4778 enabled_tc, vsi->seid);
4779 goto out;
4780 }
4781
4782 /* Update Queue Pairs Mapping for currently enabled UPs */
4783 ctxt.seid = vsi->seid;
4784 ctxt.pf_num = vsi->back->hw.pf_id;
4785 ctxt.vf_num = 0;
4786 ctxt.uplink_seid = vsi->uplink_seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07004787 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004788 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
4789
4790 /* Update the VSI after updating the VSI queue-mapping information */
4791 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
4792 if (ret) {
4793 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004794 "Update vsi tc config failed, err %s aq_err %s\n",
4795 i40e_stat_str(&vsi->back->hw, ret),
4796 i40e_aq_str(&vsi->back->hw,
4797 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004798 goto out;
4799 }
4800 /* update the local VSI info with updated queue map */
4801 i40e_vsi_update_queue_map(vsi, &ctxt);
4802 vsi->info.valid_sections = 0;
4803
4804 /* Update current VSI BW information */
4805 ret = i40e_vsi_get_bw_info(vsi);
4806 if (ret) {
4807 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004808 "Failed updating vsi bw info, err %s aq_err %s\n",
4809 i40e_stat_str(&vsi->back->hw, ret),
4810 i40e_aq_str(&vsi->back->hw,
4811 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004812 goto out;
4813 }
4814
4815 /* Update the netdev TC setup */
4816 i40e_vsi_config_netdev_tc(vsi, enabled_tc);
4817out:
4818 return ret;
4819}
4820
4821/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004822 * i40e_veb_config_tc - Configure TCs for given VEB
4823 * @veb: given VEB
4824 * @enabled_tc: TC bitmap
4825 *
4826 * Configures given TC bitmap for VEB (switching) element
4827 **/
4828int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
4829{
4830 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
4831 struct i40e_pf *pf = veb->pf;
4832 int ret = 0;
4833 int i;
4834
4835 /* No TCs or already enabled TCs just return */
4836 if (!enabled_tc || veb->enabled_tc == enabled_tc)
4837 return ret;
4838
4839 bw_data.tc_valid_bits = enabled_tc;
4840 /* bw_data.absolute_credits is not set (relative) */
4841
4842 /* Enable ETS TCs with equal BW Share for now */
4843 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004844 if (enabled_tc & BIT_ULL(i))
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004845 bw_data.tc_bw_share_credits[i] = 1;
4846 }
4847
4848 ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
4849 &bw_data, NULL);
4850 if (ret) {
4851 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004852 "VEB bw config failed, err %s aq_err %s\n",
4853 i40e_stat_str(&pf->hw, ret),
4854 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004855 goto out;
4856 }
4857
4858 /* Update the BW information */
4859 ret = i40e_veb_get_bw_info(veb);
4860 if (ret) {
4861 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004862 "Failed getting veb bw config, err %s aq_err %s\n",
4863 i40e_stat_str(&pf->hw, ret),
4864 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004865 }
4866
4867out:
4868 return ret;
4869}
4870
4871#ifdef CONFIG_I40E_DCB
4872/**
4873 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
4874 * @pf: PF struct
4875 *
4876 * Reconfigure VEB/VSIs on a given PF; it is assumed that
4877 * the caller would've quiesce all the VSIs before calling
4878 * this function
4879 **/
4880static void i40e_dcb_reconfigure(struct i40e_pf *pf)
4881{
4882 u8 tc_map = 0;
4883 int ret;
4884 u8 v;
4885
4886 /* Enable the TCs available on PF to all VEBs */
4887 tc_map = i40e_pf_get_tc_map(pf);
4888 for (v = 0; v < I40E_MAX_VEB; v++) {
4889 if (!pf->veb[v])
4890 continue;
4891 ret = i40e_veb_config_tc(pf->veb[v], tc_map);
4892 if (ret) {
4893 dev_info(&pf->pdev->dev,
4894 "Failed configuring TC for VEB seid=%d\n",
4895 pf->veb[v]->seid);
4896 /* Will try to configure as many components */
4897 }
4898 }
4899
4900 /* Update each VSI */
Mitch Williams505682c2014-05-20 08:01:37 +00004901 for (v = 0; v < pf->num_alloc_vsi; v++) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004902 if (!pf->vsi[v])
4903 continue;
4904
4905 /* - Enable all TCs for the LAN VSI
Vasu Dev38e00432014-08-01 13:27:03 -07004906#ifdef I40E_FCOE
4907 * - For FCoE VSI only enable the TC configured
4908 * as per the APP TLV
4909#endif
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004910 * - For all others keep them at TC0 for now
4911 */
4912 if (v == pf->lan_vsi)
4913 tc_map = i40e_pf_get_tc_map(pf);
4914 else
4915 tc_map = i40e_pf_get_default_tc(pf);
Vasu Dev38e00432014-08-01 13:27:03 -07004916#ifdef I40E_FCOE
4917 if (pf->vsi[v]->type == I40E_VSI_FCOE)
4918 tc_map = i40e_get_fcoe_tc_map(pf);
4919#endif /* #ifdef I40E_FCOE */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004920
4921 ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
4922 if (ret) {
4923 dev_info(&pf->pdev->dev,
4924 "Failed configuring TC for VSI seid=%d\n",
4925 pf->vsi[v]->seid);
4926 /* Will try to configure as many components */
4927 } else {
Neerav Parikh0672a092014-04-01 07:11:47 +00004928 /* Re-configure VSI vectors based on updated TC map */
4929 i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004930 if (pf->vsi[v]->netdev)
4931 i40e_dcbnl_set_all(pf->vsi[v]);
4932 }
4933 }
4934}
4935
4936/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00004937 * i40e_resume_port_tx - Resume port Tx
4938 * @pf: PF struct
4939 *
4940 * Resume a port's Tx and issue a PF reset in case of failure to
4941 * resume.
4942 **/
4943static int i40e_resume_port_tx(struct i40e_pf *pf)
4944{
4945 struct i40e_hw *hw = &pf->hw;
4946 int ret;
4947
4948 ret = i40e_aq_resume_port_tx(hw, NULL);
4949 if (ret) {
4950 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004951 "Resume Port Tx failed, err %s aq_err %s\n",
4952 i40e_stat_str(&pf->hw, ret),
4953 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh2fd75f32014-11-12 00:18:20 +00004954 /* Schedule PF reset to recover */
4955 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
4956 i40e_service_event_schedule(pf);
4957 }
4958
4959 return ret;
4960}
4961
4962/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004963 * i40e_init_pf_dcb - Initialize DCB configuration
4964 * @pf: PF being configured
4965 *
4966 * Query the current DCB configuration and cache it
4967 * in the hardware structure
4968 **/
4969static int i40e_init_pf_dcb(struct i40e_pf *pf)
4970{
4971 struct i40e_hw *hw = &pf->hw;
4972 int err = 0;
4973
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00004974 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
4975 if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
4976 (pf->hw.aq.fw_maj_ver < 4))
4977 goto out;
4978
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004979 /* Get the initial DCB configuration */
4980 err = i40e_init_dcb(hw);
4981 if (!err) {
4982 /* Device/Function is not DCBX capable */
4983 if ((!hw->func_caps.dcb) ||
4984 (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
4985 dev_info(&pf->pdev->dev,
4986 "DCBX offload is not supported or is disabled for this PF.\n");
4987
4988 if (pf->flags & I40E_FLAG_MFP_ENABLED)
4989 goto out;
4990
4991 } else {
4992 /* When status is not DISABLED then DCBX in FW */
4993 pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
4994 DCB_CAP_DCBX_VER_IEEE;
Neerav Parikh4d9b6042014-05-22 06:31:51 +00004995
4996 pf->flags |= I40E_FLAG_DCB_CAPABLE;
4997 /* Enable DCB tagging only when more than one TC */
4998 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
4999 pf->flags |= I40E_FLAG_DCB_ENABLED;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005000 dev_dbg(&pf->pdev->dev,
5001 "DCBX offload is supported for this PF.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005002 }
Neerav Parikh014269f2014-04-01 07:11:48 +00005003 } else {
Shannon Nelsonaebfc812014-12-11 07:06:38 +00005004 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005005 "Query for DCB configuration failed, err %s aq_err %s\n",
5006 i40e_stat_str(&pf->hw, err),
5007 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005008 }
5009
5010out:
5011 return err;
5012}
5013#endif /* CONFIG_I40E_DCB */
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005014#define SPEED_SIZE 14
5015#define FC_SIZE 8
5016/**
5017 * i40e_print_link_message - print link up or down
5018 * @vsi: the VSI for which link needs a message
5019 */
Matt Jaredc156f852015-08-27 11:42:39 -04005020void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005021{
Shannon Nelsona9165492015-09-03 17:19:00 -04005022 char *speed = "Unknown";
5023 char *fc = "Unknown";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005024
Matt Jaredc156f852015-08-27 11:42:39 -04005025 if (vsi->current_isup == isup)
5026 return;
5027 vsi->current_isup = isup;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005028 if (!isup) {
5029 netdev_info(vsi->netdev, "NIC Link is Down\n");
5030 return;
5031 }
5032
Greg Rose148c2d82014-12-11 07:06:27 +00005033 /* Warn user if link speed on NPAR enabled partition is not at
5034 * least 10GB
5035 */
5036 if (vsi->back->hw.func_caps.npar_enable &&
5037 (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
5038 vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
5039 netdev_warn(vsi->netdev,
5040 "The partition detected link speed that is less than 10Gbps\n");
5041
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005042 switch (vsi->back->hw.phy.link_info.link_speed) {
5043 case I40E_LINK_SPEED_40GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005044 speed = "40 G";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005045 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -07005046 case I40E_LINK_SPEED_20GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005047 speed = "20 G";
Jesse Brandeburgae24b402015-03-27 00:12:09 -07005048 break;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005049 case I40E_LINK_SPEED_10GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005050 speed = "10 G";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005051 break;
5052 case I40E_LINK_SPEED_1GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005053 speed = "1000 M";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005054 break;
Mitch Williams5960d332014-09-13 07:40:47 +00005055 case I40E_LINK_SPEED_100MB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005056 speed = "100 M";
Mitch Williams5960d332014-09-13 07:40:47 +00005057 break;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005058 default:
5059 break;
5060 }
5061
5062 switch (vsi->back->hw.fc.current_mode) {
5063 case I40E_FC_FULL:
Shannon Nelsona9165492015-09-03 17:19:00 -04005064 fc = "RX/TX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005065 break;
5066 case I40E_FC_TX_PAUSE:
Shannon Nelsona9165492015-09-03 17:19:00 -04005067 fc = "TX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005068 break;
5069 case I40E_FC_RX_PAUSE:
Shannon Nelsona9165492015-09-03 17:19:00 -04005070 fc = "RX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005071 break;
5072 default:
Shannon Nelsona9165492015-09-03 17:19:00 -04005073 fc = "None";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005074 break;
5075 }
5076
Shannon Nelsona9165492015-09-03 17:19:00 -04005077 netdev_info(vsi->netdev, "NIC Link is Up %sbps Full Duplex, Flow Control: %s\n",
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005078 speed, fc);
5079}
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005080
5081/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005082 * i40e_up_complete - Finish the last steps of bringing up a connection
5083 * @vsi: the VSI being configured
5084 **/
5085static int i40e_up_complete(struct i40e_vsi *vsi)
5086{
5087 struct i40e_pf *pf = vsi->back;
5088 int err;
5089
5090 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
5091 i40e_vsi_configure_msix(vsi);
5092 else
5093 i40e_configure_msi_and_legacy(vsi);
5094
5095 /* start rings */
5096 err = i40e_vsi_control_rings(vsi, true);
5097 if (err)
5098 return err;
5099
5100 clear_bit(__I40E_DOWN, &vsi->state);
5101 i40e_napi_enable_all(vsi);
5102 i40e_vsi_enable_irq(vsi);
5103
5104 if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
5105 (vsi->netdev)) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005106 i40e_print_link_message(vsi, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005107 netif_tx_start_all_queues(vsi->netdev);
5108 netif_carrier_on(vsi->netdev);
Anjali Singhai6d779b42013-09-28 06:00:02 +00005109 } else if (vsi->netdev) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005110 i40e_print_link_message(vsi, false);
Carolyn Wyborny7b592f62014-07-10 07:58:19 +00005111 /* need to check for qualified module here*/
5112 if ((pf->hw.phy.link_info.link_info &
5113 I40E_AQ_MEDIA_AVAILABLE) &&
5114 (!(pf->hw.phy.link_info.an_info &
5115 I40E_AQ_QUALIFIED_MODULE)))
5116 netdev_err(vsi->netdev,
5117 "the driver failed to link because an unqualified module was detected.");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005118 }
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00005119
5120 /* replay FDIR SB filters */
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005121 if (vsi->type == I40E_VSI_FDIR) {
5122 /* reset fd counters */
5123 pf->fd_add_err = pf->fd_atr_cnt = 0;
5124 if (pf->fd_tcp_rule > 0) {
5125 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04005126 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5127 dev_info(&pf->pdev->dev, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005128 pf->fd_tcp_rule = 0;
5129 }
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00005130 i40e_fdir_filter_restore(vsi);
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005131 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005132 i40e_service_event_schedule(pf);
5133
5134 return 0;
5135}
5136
5137/**
5138 * i40e_vsi_reinit_locked - Reset the VSI
5139 * @vsi: the VSI being configured
5140 *
5141 * Rebuild the ring structs after some configuration
5142 * has changed, e.g. MTU size.
5143 **/
5144static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
5145{
5146 struct i40e_pf *pf = vsi->back;
5147
5148 WARN_ON(in_interrupt());
5149 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
5150 usleep_range(1000, 2000);
5151 i40e_down(vsi);
5152
5153 /* Give a VF some time to respond to the reset. The
5154 * two second wait is based upon the watchdog cycle in
5155 * the VF driver.
5156 */
5157 if (vsi->type == I40E_VSI_SRIOV)
5158 msleep(2000);
5159 i40e_up(vsi);
5160 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
5161}
5162
5163/**
5164 * i40e_up - Bring the connection back up after being down
5165 * @vsi: the VSI being configured
5166 **/
5167int i40e_up(struct i40e_vsi *vsi)
5168{
5169 int err;
5170
5171 err = i40e_vsi_configure(vsi);
5172 if (!err)
5173 err = i40e_up_complete(vsi);
5174
5175 return err;
5176}
5177
5178/**
5179 * i40e_down - Shutdown the connection processing
5180 * @vsi: the VSI being stopped
5181 **/
5182void i40e_down(struct i40e_vsi *vsi)
5183{
5184 int i;
5185
5186 /* It is assumed that the caller of this function
5187 * sets the vsi->state __I40E_DOWN bit.
5188 */
5189 if (vsi->netdev) {
5190 netif_carrier_off(vsi->netdev);
5191 netif_tx_disable(vsi->netdev);
5192 }
5193 i40e_vsi_disable_irq(vsi);
5194 i40e_vsi_control_rings(vsi, false);
5195 i40e_napi_disable_all(vsi);
5196
5197 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00005198 i40e_clean_tx_ring(vsi->tx_rings[i]);
5199 i40e_clean_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005200 }
5201}
5202
5203/**
5204 * i40e_setup_tc - configure multiple traffic classes
5205 * @netdev: net device to configure
5206 * @tc: number of traffic classes to enable
5207 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005208#ifdef I40E_FCOE
5209int i40e_setup_tc(struct net_device *netdev, u8 tc)
5210#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005211static int i40e_setup_tc(struct net_device *netdev, u8 tc)
Vasu Dev38e00432014-08-01 13:27:03 -07005212#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005213{
5214 struct i40e_netdev_priv *np = netdev_priv(netdev);
5215 struct i40e_vsi *vsi = np->vsi;
5216 struct i40e_pf *pf = vsi->back;
5217 u8 enabled_tc = 0;
5218 int ret = -EINVAL;
5219 int i;
5220
5221 /* Check if DCB enabled to continue */
5222 if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
5223 netdev_info(netdev, "DCB is not enabled for adapter\n");
5224 goto exit;
5225 }
5226
5227 /* Check if MFP enabled */
5228 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
5229 netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
5230 goto exit;
5231 }
5232
5233 /* Check whether tc count is within enabled limit */
5234 if (tc > i40e_pf_get_num_tc(pf)) {
5235 netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
5236 goto exit;
5237 }
5238
5239 /* Generate TC map for number of tc requested */
5240 for (i = 0; i < tc; i++)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005241 enabled_tc |= BIT_ULL(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005242
5243 /* Requesting same TC configuration as already enabled */
5244 if (enabled_tc == vsi->tc_config.enabled_tc)
5245 return 0;
5246
5247 /* Quiesce VSI queues */
5248 i40e_quiesce_vsi(vsi);
5249
5250 /* Configure VSI for enabled TCs */
5251 ret = i40e_vsi_config_tc(vsi, enabled_tc);
5252 if (ret) {
5253 netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
5254 vsi->seid);
5255 goto exit;
5256 }
5257
5258 /* Unquiesce VSI */
5259 i40e_unquiesce_vsi(vsi);
5260
5261exit:
5262 return ret;
5263}
5264
5265/**
5266 * i40e_open - Called when a network interface is made active
5267 * @netdev: network interface device structure
5268 *
5269 * The open entry point is called when a network interface is made
5270 * active by the system (IFF_UP). At this point all resources needed
5271 * for transmit and receive operations are allocated, the interrupt
5272 * handler is registered with the OS, the netdev watchdog subtask is
5273 * enabled, and the stack is notified that the interface is ready.
5274 *
5275 * Returns 0 on success, negative value on failure
5276 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005277int i40e_open(struct net_device *netdev)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005278{
5279 struct i40e_netdev_priv *np = netdev_priv(netdev);
5280 struct i40e_vsi *vsi = np->vsi;
5281 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005282 int err;
5283
Shannon Nelson4eb3f762014-03-06 08:59:58 +00005284 /* disallow open during test or if eeprom is broken */
5285 if (test_bit(__I40E_TESTING, &pf->state) ||
5286 test_bit(__I40E_BAD_EEPROM, &pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005287 return -EBUSY;
5288
5289 netif_carrier_off(netdev);
5290
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005291 err = i40e_vsi_open(vsi);
5292 if (err)
5293 return err;
5294
Jesse Brandeburg059dab62014-04-01 09:07:20 +00005295 /* configure global TSO hardware offload settings */
5296 wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
5297 TCP_FLAG_FIN) >> 16);
5298 wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
5299 TCP_FLAG_FIN |
5300 TCP_FLAG_CWR) >> 16);
5301 wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
5302
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005303#ifdef CONFIG_I40E_VXLAN
5304 vxlan_get_rx_port(netdev);
5305#endif
5306
5307 return 0;
5308}
5309
5310/**
5311 * i40e_vsi_open -
5312 * @vsi: the VSI to open
5313 *
5314 * Finish initialization of the VSI.
5315 *
5316 * Returns 0 on success, negative value on failure
5317 **/
5318int i40e_vsi_open(struct i40e_vsi *vsi)
5319{
5320 struct i40e_pf *pf = vsi->back;
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00005321 char int_name[I40E_INT_NAME_STR_LEN];
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005322 int err;
5323
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005324 /* allocate descriptors */
5325 err = i40e_vsi_setup_tx_resources(vsi);
5326 if (err)
5327 goto err_setup_tx;
5328 err = i40e_vsi_setup_rx_resources(vsi);
5329 if (err)
5330 goto err_setup_rx;
5331
5332 err = i40e_vsi_configure(vsi);
5333 if (err)
5334 goto err_setup_rx;
5335
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00005336 if (vsi->netdev) {
5337 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
5338 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
5339 err = i40e_vsi_request_irq(vsi, int_name);
5340 if (err)
5341 goto err_setup_rx;
5342
5343 /* Notify the stack of the actual queue counts. */
5344 err = netif_set_real_num_tx_queues(vsi->netdev,
5345 vsi->num_queue_pairs);
5346 if (err)
5347 goto err_set_queues;
5348
5349 err = netif_set_real_num_rx_queues(vsi->netdev,
5350 vsi->num_queue_pairs);
5351 if (err)
5352 goto err_set_queues;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005353
5354 } else if (vsi->type == I40E_VSI_FDIR) {
Carolyn Wybornye240f672014-12-11 07:06:37 +00005355 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +00005356 dev_driver_string(&pf->pdev->dev),
5357 dev_name(&pf->pdev->dev));
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005358 err = i40e_vsi_request_irq(vsi, int_name);
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +00005359
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00005360 } else {
Jean Sacrence9ccb12014-05-01 14:31:18 +00005361 err = -EINVAL;
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005362 goto err_setup_rx;
5363 }
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00005364
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005365 err = i40e_up_complete(vsi);
5366 if (err)
5367 goto err_up_complete;
5368
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005369 return 0;
5370
5371err_up_complete:
5372 i40e_down(vsi);
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00005373err_set_queues:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005374 i40e_vsi_free_irq(vsi);
5375err_setup_rx:
5376 i40e_vsi_free_rx_resources(vsi);
5377err_setup_tx:
5378 i40e_vsi_free_tx_resources(vsi);
5379 if (vsi == pf->vsi[pf->lan_vsi])
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005380 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005381
5382 return err;
5383}
5384
5385/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005386 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00005387 * @pf: Pointer to PF
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005388 *
5389 * This function destroys the hlist where all the Flow Director
5390 * filters were saved.
5391 **/
5392static void i40e_fdir_filter_exit(struct i40e_pf *pf)
5393{
5394 struct i40e_fdir_filter *filter;
5395 struct hlist_node *node2;
5396
5397 hlist_for_each_entry_safe(filter, node2,
5398 &pf->fdir_filter_list, fdir_node) {
5399 hlist_del(&filter->fdir_node);
5400 kfree(filter);
5401 }
5402 pf->fdir_pf_active_filters = 0;
5403}
5404
5405/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005406 * i40e_close - Disables a network interface
5407 * @netdev: network interface device structure
5408 *
5409 * The close entry point is called when an interface is de-activated
5410 * by the OS. The hardware is still under the driver's control, but
5411 * this netdev interface is disabled.
5412 *
5413 * Returns 0, this is not allowed to fail
5414 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005415#ifdef I40E_FCOE
5416int i40e_close(struct net_device *netdev)
5417#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005418static int i40e_close(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -07005419#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005420{
5421 struct i40e_netdev_priv *np = netdev_priv(netdev);
5422 struct i40e_vsi *vsi = np->vsi;
5423
Shannon Nelson90ef8d42014-03-14 07:32:26 +00005424 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005425
5426 return 0;
5427}
5428
5429/**
5430 * i40e_do_reset - Start a PF or Core Reset sequence
5431 * @pf: board private structure
5432 * @reset_flags: which reset is requested
5433 *
5434 * The essential difference in resets is that the PF Reset
5435 * doesn't clear the packet buffers, doesn't reset the PE
5436 * firmware, and doesn't bother the other PFs on the chip.
5437 **/
5438void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
5439{
5440 u32 val;
5441
5442 WARN_ON(in_interrupt());
5443
Mitch Williams263fc482014-04-23 04:50:11 +00005444 if (i40e_check_asq_alive(&pf->hw))
5445 i40e_vc_notify_reset(pf);
5446
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005447 /* do the biggest reset indicated */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005448 if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005449
5450 /* Request a Global Reset
5451 *
5452 * This will start the chip's countdown to the actual full
5453 * chip reset event, and a warning interrupt to be sent
5454 * to all PFs, including the requestor. Our handler
5455 * for the warning interrupt will deal with the shutdown
5456 * and recovery of the switch setup.
5457 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005458 dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005459 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5460 val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
5461 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5462
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005463 } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005464
5465 /* Request a Core Reset
5466 *
5467 * Same as Global Reset, except does *not* include the MAC/PHY
5468 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005469 dev_dbg(&pf->pdev->dev, "CoreR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005470 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5471 val |= I40E_GLGEN_RTRIG_CORER_MASK;
5472 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5473 i40e_flush(&pf->hw);
5474
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005475 } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005476
5477 /* Request a PF Reset
5478 *
5479 * Resets only the PF-specific registers
5480 *
5481 * This goes directly to the tear-down and rebuild of
5482 * the switch, since we need to do all the recovery as
5483 * for the Core Reset.
5484 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005485 dev_dbg(&pf->pdev->dev, "PFR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005486 i40e_handle_reset_warning(pf);
5487
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005488 } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005489 int v;
5490
5491 /* Find the VSI(s) that requested a re-init */
5492 dev_info(&pf->pdev->dev,
5493 "VSI reinit requested\n");
Mitch Williams505682c2014-05-20 08:01:37 +00005494 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005495 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04005496
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005497 if (vsi != NULL &&
5498 test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
5499 i40e_vsi_reinit_locked(pf->vsi[v]);
5500 clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
5501 }
5502 }
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005503 } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005504 int v;
5505
5506 /* Find the VSI(s) that needs to be brought down */
5507 dev_info(&pf->pdev->dev, "VSI down requested\n");
5508 for (v = 0; v < pf->num_alloc_vsi; v++) {
5509 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04005510
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005511 if (vsi != NULL &&
5512 test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) {
5513 set_bit(__I40E_DOWN, &vsi->state);
5514 i40e_down(vsi);
5515 clear_bit(__I40E_DOWN_REQUESTED, &vsi->state);
5516 }
5517 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005518 } else {
5519 dev_info(&pf->pdev->dev,
5520 "bad reset request 0x%08x\n", reset_flags);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005521 }
5522}
5523
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005524#ifdef CONFIG_I40E_DCB
5525/**
5526 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
5527 * @pf: board private structure
5528 * @old_cfg: current DCB config
5529 * @new_cfg: new DCB config
5530 **/
5531bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
5532 struct i40e_dcbx_config *old_cfg,
5533 struct i40e_dcbx_config *new_cfg)
5534{
5535 bool need_reconfig = false;
5536
5537 /* Check if ETS configuration has changed */
5538 if (memcmp(&new_cfg->etscfg,
5539 &old_cfg->etscfg,
5540 sizeof(new_cfg->etscfg))) {
5541 /* If Priority Table has changed reconfig is needed */
5542 if (memcmp(&new_cfg->etscfg.prioritytable,
5543 &old_cfg->etscfg.prioritytable,
5544 sizeof(new_cfg->etscfg.prioritytable))) {
5545 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005546 dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005547 }
5548
5549 if (memcmp(&new_cfg->etscfg.tcbwtable,
5550 &old_cfg->etscfg.tcbwtable,
5551 sizeof(new_cfg->etscfg.tcbwtable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005552 dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005553
5554 if (memcmp(&new_cfg->etscfg.tsatable,
5555 &old_cfg->etscfg.tsatable,
5556 sizeof(new_cfg->etscfg.tsatable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005557 dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005558 }
5559
5560 /* Check if PFC configuration has changed */
5561 if (memcmp(&new_cfg->pfc,
5562 &old_cfg->pfc,
5563 sizeof(new_cfg->pfc))) {
5564 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005565 dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005566 }
5567
5568 /* Check if APP Table has changed */
5569 if (memcmp(&new_cfg->app,
5570 &old_cfg->app,
Dave Jones3d9667a2014-01-27 23:11:09 -05005571 sizeof(new_cfg->app))) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005572 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005573 dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
Dave Jones3d9667a2014-01-27 23:11:09 -05005574 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005575
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005576 dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005577 return need_reconfig;
5578}
5579
5580/**
5581 * i40e_handle_lldp_event - Handle LLDP Change MIB event
5582 * @pf: board private structure
5583 * @e: event info posted on ARQ
5584 **/
5585static int i40e_handle_lldp_event(struct i40e_pf *pf,
5586 struct i40e_arq_event_info *e)
5587{
5588 struct i40e_aqc_lldp_get_mib *mib =
5589 (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
5590 struct i40e_hw *hw = &pf->hw;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005591 struct i40e_dcbx_config tmp_dcbx_cfg;
5592 bool need_reconfig = false;
5593 int ret = 0;
5594 u8 type;
5595
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005596 /* Not DCB capable or capability disabled */
5597 if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
5598 return ret;
5599
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005600 /* Ignore if event is not for Nearest Bridge */
5601 type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
5602 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005603 dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005604 if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
5605 return ret;
5606
5607 /* Check MIB Type and return if event for Remote MIB update */
5608 type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005609 dev_dbg(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005610 "LLDP event mib type %s\n", type ? "remote" : "local");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005611 if (type == I40E_AQ_LLDP_MIB_REMOTE) {
5612 /* Update the remote cached instance and return */
5613 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
5614 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
5615 &hw->remote_dcbx_config);
5616 goto exit;
5617 }
5618
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005619 /* Store the old configuration */
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07005620 tmp_dcbx_cfg = hw->local_dcbx_config;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005621
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005622 /* Reset the old DCBx configuration data */
5623 memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005624 /* Get updated DCBX data from firmware */
5625 ret = i40e_get_dcb_config(&pf->hw);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005626 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005627 dev_info(&pf->pdev->dev,
5628 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
5629 i40e_stat_str(&pf->hw, ret),
5630 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005631 goto exit;
5632 }
5633
5634 /* No change detected in DCBX configs */
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005635 if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
5636 sizeof(tmp_dcbx_cfg))) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005637 dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005638 goto exit;
5639 }
5640
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005641 need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
5642 &hw->local_dcbx_config);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005643
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005644 i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005645
5646 if (!need_reconfig)
5647 goto exit;
5648
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005649 /* Enable DCB tagging only when more than one TC */
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005650 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005651 pf->flags |= I40E_FLAG_DCB_ENABLED;
5652 else
5653 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
5654
Neerav Parikh69129dc2014-11-12 00:18:46 +00005655 set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005656 /* Reconfiguration needed quiesce all VSIs */
5657 i40e_pf_quiesce_all_vsi(pf);
5658
5659 /* Changes in configuration update VEB/VSI */
5660 i40e_dcb_reconfigure(pf);
5661
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005662 ret = i40e_resume_port_tx(pf);
5663
Neerav Parikh69129dc2014-11-12 00:18:46 +00005664 clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005665 /* In case of error no point in resuming VSIs */
Neerav Parikh69129dc2014-11-12 00:18:46 +00005666 if (ret)
5667 goto exit;
5668
5669 /* Wait for the PF's Tx queues to be disabled */
5670 ret = i40e_pf_wait_txq_disabled(pf);
Parikh, Neerav11e47702015-02-21 06:43:55 +00005671 if (ret) {
5672 /* Schedule PF reset to recover */
5673 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
5674 i40e_service_event_schedule(pf);
5675 } else {
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005676 i40e_pf_unquiesce_all_vsi(pf);
Parikh, Neerav11e47702015-02-21 06:43:55 +00005677 }
5678
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005679exit:
5680 return ret;
5681}
5682#endif /* CONFIG_I40E_DCB */
5683
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005684/**
Anjali Singhai Jain233261862013-11-26 10:49:22 +00005685 * i40e_do_reset_safe - Protected reset path for userland calls.
5686 * @pf: board private structure
5687 * @reset_flags: which reset is requested
5688 *
5689 **/
5690void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
5691{
5692 rtnl_lock();
5693 i40e_do_reset(pf, reset_flags);
5694 rtnl_unlock();
5695}
5696
5697/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005698 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
5699 * @pf: board private structure
5700 * @e: event info posted on ARQ
5701 *
5702 * Handler for LAN Queue Overflow Event generated by the firmware for PF
5703 * and VF queues
5704 **/
5705static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
5706 struct i40e_arq_event_info *e)
5707{
5708 struct i40e_aqc_lan_overflow *data =
5709 (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
5710 u32 queue = le32_to_cpu(data->prtdcb_rupto);
5711 u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
5712 struct i40e_hw *hw = &pf->hw;
5713 struct i40e_vf *vf;
5714 u16 vf_id;
5715
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005716 dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
5717 queue, qtx_ctl);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005718
5719 /* Queue belongs to VF, find the VF and issue VF reset */
5720 if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
5721 >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
5722 vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
5723 >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
5724 vf_id -= hw->func_caps.vf_base_id;
5725 vf = &pf->vf[vf_id];
5726 i40e_vc_notify_vf_reset(vf);
5727 /* Allow VF to process pending reset notification */
5728 msleep(20);
5729 i40e_reset_vf(vf, false);
5730 }
5731}
5732
5733/**
5734 * i40e_service_event_complete - Finish up the service event
5735 * @pf: board private structure
5736 **/
5737static void i40e_service_event_complete(struct i40e_pf *pf)
5738{
5739 BUG_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state));
5740
5741 /* flush memory to make sure state is correct before next watchog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005742 smp_mb__before_atomic();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005743 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
5744}
5745
5746/**
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005747 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
5748 * @pf: board private structure
5749 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005750u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005751{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005752 u32 val, fcnt_prog;
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005753
5754 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
5755 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
5756 return fcnt_prog;
5757}
5758
5759/**
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005760 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005761 * @pf: board private structure
5762 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005763u32 i40e_get_current_fd_count(struct i40e_pf *pf)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005764{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005765 u32 val, fcnt_prog;
5766
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005767 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
5768 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
5769 ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
5770 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
5771 return fcnt_prog;
5772}
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005773
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005774/**
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005775 * i40e_get_global_fd_count - Get total FD filters programmed on device
5776 * @pf: board private structure
5777 **/
5778u32 i40e_get_global_fd_count(struct i40e_pf *pf)
5779{
5780 u32 val, fcnt_prog;
5781
5782 val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
5783 fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
5784 ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
5785 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
5786 return fcnt_prog;
5787}
5788
5789/**
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005790 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
5791 * @pf: board private structure
5792 **/
5793void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
5794{
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04005795 struct i40e_fdir_filter *filter;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005796 u32 fcnt_prog, fcnt_avail;
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04005797 struct hlist_node *node;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005798
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005799 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
5800 return;
5801
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005802 /* Check if, FD SB or ATR was auto disabled and if there is enough room
5803 * to re-enable
5804 */
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005805 fcnt_prog = i40e_get_global_fd_count(pf);
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005806 fcnt_avail = pf->fdir_pf_filter_count;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005807 if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
5808 (pf->fd_add_err == 0) ||
5809 (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005810 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
5811 (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
5812 pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04005813 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5814 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 +00005815 }
5816 }
5817 /* Wait for some more space to be available to turn on ATR */
5818 if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
5819 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
5820 (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
5821 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04005822 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5823 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 +00005824 }
5825 }
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04005826
5827 /* if hw had a problem adding a filter, delete it */
5828 if (pf->fd_inv > 0) {
5829 hlist_for_each_entry_safe(filter, node,
5830 &pf->fdir_filter_list, fdir_node) {
5831 if (filter->fd_id == pf->fd_inv) {
5832 hlist_del(&filter->fdir_node);
5833 kfree(filter);
5834 pf->fdir_pf_active_filters--;
5835 }
5836 }
5837 }
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005838}
5839
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005840#define I40E_MIN_FD_FLUSH_INTERVAL 10
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005841#define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005842/**
5843 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
5844 * @pf: board private structure
5845 **/
5846static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
5847{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005848 unsigned long min_flush_time;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005849 int flush_wait_retry = 50;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005850 bool disable_atr = false;
5851 int fd_room;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005852 int reg;
5853
Akeem G Abodunrin1790ed02014-10-17 03:14:41 +00005854 if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED)))
5855 return;
5856
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005857 if (!time_after(jiffies, pf->fd_flush_timestamp +
5858 (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
5859 return;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005860
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005861 /* If the flush is happening too quick and we have mostly SB rules we
5862 * should not re-enable ATR for some time.
5863 */
5864 min_flush_time = pf->fd_flush_timestamp +
5865 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
5866 fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005867
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005868 if (!(time_after(jiffies, min_flush_time)) &&
5869 (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
5870 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5871 dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
5872 disable_atr = true;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005873 }
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005874
5875 pf->fd_flush_timestamp = jiffies;
5876 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
5877 /* flush all filters */
5878 wr32(&pf->hw, I40E_PFQF_CTL_1,
5879 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
5880 i40e_flush(&pf->hw);
5881 pf->fd_flush_cnt++;
5882 pf->fd_add_err = 0;
5883 do {
5884 /* Check FD flush status every 5-6msec */
5885 usleep_range(5000, 6000);
5886 reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
5887 if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
5888 break;
5889 } while (flush_wait_retry--);
5890 if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
5891 dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
5892 } else {
5893 /* replay sideband filters */
5894 i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
5895 if (!disable_atr)
5896 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
5897 clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
5898 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5899 dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
5900 }
5901
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005902}
5903
5904/**
5905 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
5906 * @pf: board private structure
5907 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005908u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005909{
5910 return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
5911}
5912
5913/* We can see up to 256 filter programming desc in transit if the filters are
5914 * being applied really fast; before we see the first
5915 * filter miss error on Rx queue 0. Accumulating enough error messages before
5916 * reacting will make sure we don't cause flush too often.
5917 */
5918#define I40E_MAX_FD_PROGRAM_ERROR 256
5919
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005920/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005921 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
5922 * @pf: board private structure
5923 **/
5924static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
5925{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005926
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005927 /* if interface is down do nothing */
5928 if (test_bit(__I40E_DOWN, &pf->state))
5929 return;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005930
Akeem G Abodunrin1790ed02014-10-17 03:14:41 +00005931 if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED)))
5932 return;
5933
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005934 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005935 i40e_fdir_flush_and_replay(pf);
5936
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005937 i40e_fdir_check_and_reenable(pf);
5938
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005939}
5940
5941/**
5942 * i40e_vsi_link_event - notify VSI of a link event
5943 * @vsi: vsi to be notified
5944 * @link_up: link up or down
5945 **/
5946static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
5947{
Jesse Brandeburg32b5b812014-08-12 06:33:14 +00005948 if (!vsi || test_bit(__I40E_DOWN, &vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005949 return;
5950
5951 switch (vsi->type) {
5952 case I40E_VSI_MAIN:
Vasu Dev38e00432014-08-01 13:27:03 -07005953#ifdef I40E_FCOE
5954 case I40E_VSI_FCOE:
5955#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005956 if (!vsi->netdev || !vsi->netdev_registered)
5957 break;
5958
5959 if (link_up) {
5960 netif_carrier_on(vsi->netdev);
5961 netif_tx_wake_all_queues(vsi->netdev);
5962 } else {
5963 netif_carrier_off(vsi->netdev);
5964 netif_tx_stop_all_queues(vsi->netdev);
5965 }
5966 break;
5967
5968 case I40E_VSI_SRIOV:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005969 case I40E_VSI_VMDQ2:
5970 case I40E_VSI_CTRL:
5971 case I40E_VSI_MIRROR:
5972 default:
5973 /* there is no notification for other VSIs */
5974 break;
5975 }
5976}
5977
5978/**
5979 * i40e_veb_link_event - notify elements on the veb of a link event
5980 * @veb: veb to be notified
5981 * @link_up: link up or down
5982 **/
5983static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
5984{
5985 struct i40e_pf *pf;
5986 int i;
5987
5988 if (!veb || !veb->pf)
5989 return;
5990 pf = veb->pf;
5991
5992 /* depth first... */
5993 for (i = 0; i < I40E_MAX_VEB; i++)
5994 if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
5995 i40e_veb_link_event(pf->veb[i], link_up);
5996
5997 /* ... now the local VSIs */
Mitch Williams505682c2014-05-20 08:01:37 +00005998 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005999 if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
6000 i40e_vsi_link_event(pf->vsi[i], link_up);
6001}
6002
6003/**
6004 * i40e_link_event - Update netif_carrier status
6005 * @pf: board private structure
6006 **/
6007static void i40e_link_event(struct i40e_pf *pf)
6008{
Mitch Williams320684c2014-10-17 03:14:43 +00006009 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006010 u8 new_link_speed, old_link_speed;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006011 i40e_status status;
6012 bool new_link, old_link;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006013
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006014 /* set this to force the get_link_status call to refresh state */
6015 pf->hw.phy.get_link_info = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006016
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006017 old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006018
6019 status = i40e_get_link_status(&pf->hw, &new_link);
6020 if (status) {
6021 dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
6022 status);
6023 return;
6024 }
6025
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006026 old_link_speed = pf->hw.phy.link_info_old.link_speed;
6027 new_link_speed = pf->hw.phy.link_info.link_speed;
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006028
6029 if (new_link == old_link &&
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006030 new_link_speed == old_link_speed &&
Mitch Williams320684c2014-10-17 03:14:43 +00006031 (test_bit(__I40E_DOWN, &vsi->state) ||
6032 new_link == netif_carrier_ok(vsi->netdev)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006033 return;
Mitch Williams320684c2014-10-17 03:14:43 +00006034
6035 if (!test_bit(__I40E_DOWN, &vsi->state))
6036 i40e_print_link_message(vsi, new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006037
6038 /* Notify the base of the switch tree connected to
6039 * the link. Floating VEBs are not notified.
6040 */
6041 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
6042 i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
6043 else
Mitch Williams320684c2014-10-17 03:14:43 +00006044 i40e_vsi_link_event(vsi, new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006045
6046 if (pf->vf)
6047 i40e_vc_notify_link_state(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00006048
6049 if (pf->flags & I40E_FLAG_PTP)
6050 i40e_ptp_set_increment(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006051}
6052
6053/**
Shannon Nelson21536712014-10-25 10:35:25 +00006054 * i40e_watchdog_subtask - periodic checks not using event driven response
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006055 * @pf: board private structure
6056 **/
6057static void i40e_watchdog_subtask(struct i40e_pf *pf)
6058{
6059 int i;
6060
6061 /* if interface is down do nothing */
6062 if (test_bit(__I40E_DOWN, &pf->state) ||
6063 test_bit(__I40E_CONFIG_BUSY, &pf->state))
6064 return;
6065
Shannon Nelson21536712014-10-25 10:35:25 +00006066 /* make sure we don't do these things too often */
6067 if (time_before(jiffies, (pf->service_timer_previous +
6068 pf->service_timer_period)))
6069 return;
6070 pf->service_timer_previous = jiffies;
6071
Shannon Nelson9ac77262015-08-27 11:42:40 -04006072 if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED)
6073 i40e_link_event(pf);
Shannon Nelson21536712014-10-25 10:35:25 +00006074
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006075 /* Update the stats for active netdevs so the network stack
6076 * can look at updated numbers whenever it cares to
6077 */
Mitch Williams505682c2014-05-20 08:01:37 +00006078 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006079 if (pf->vsi[i] && pf->vsi[i]->netdev)
6080 i40e_update_stats(pf->vsi[i]);
6081
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04006082 if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
6083 /* Update the stats for the active switching components */
6084 for (i = 0; i < I40E_MAX_VEB; i++)
6085 if (pf->veb[i])
6086 i40e_update_veb_stats(pf->veb[i]);
6087 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00006088
6089 i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006090}
6091
6092/**
6093 * i40e_reset_subtask - Set up for resetting the device and driver
6094 * @pf: board private structure
6095 **/
6096static void i40e_reset_subtask(struct i40e_pf *pf)
6097{
6098 u32 reset_flags = 0;
6099
Anjali Singhai Jain233261862013-11-26 10:49:22 +00006100 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006101 if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04006102 reset_flags |= BIT_ULL(__I40E_REINIT_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006103 clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
6104 }
6105 if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04006106 reset_flags |= BIT_ULL(__I40E_PF_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006107 clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
6108 }
6109 if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04006110 reset_flags |= BIT_ULL(__I40E_CORE_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006111 clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
6112 }
6113 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04006114 reset_flags |= BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006115 clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
6116 }
Neerav Parikhb5d06f02014-06-03 23:50:17 +00006117 if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04006118 reset_flags |= BIT_ULL(__I40E_DOWN_REQUESTED);
Neerav Parikhb5d06f02014-06-03 23:50:17 +00006119 clear_bit(__I40E_DOWN_REQUESTED, &pf->state);
6120 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006121
6122 /* If there's a recovery already waiting, it takes
6123 * precedence before starting a new reset sequence.
6124 */
6125 if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
6126 i40e_handle_reset_warning(pf);
Anjali Singhai Jain233261862013-11-26 10:49:22 +00006127 goto unlock;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006128 }
6129
6130 /* If we're already down or resetting, just bail */
6131 if (reset_flags &&
6132 !test_bit(__I40E_DOWN, &pf->state) &&
6133 !test_bit(__I40E_CONFIG_BUSY, &pf->state))
6134 i40e_do_reset(pf, reset_flags);
Anjali Singhai Jain233261862013-11-26 10:49:22 +00006135
6136unlock:
6137 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006138}
6139
6140/**
6141 * i40e_handle_link_event - Handle link event
6142 * @pf: board private structure
6143 * @e: event info posted on ARQ
6144 **/
6145static void i40e_handle_link_event(struct i40e_pf *pf,
6146 struct i40e_arq_event_info *e)
6147{
6148 struct i40e_hw *hw = &pf->hw;
6149 struct i40e_aqc_get_link_status *status =
6150 (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006151
6152 /* save off old link status information */
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07006153 hw->phy.link_info_old = hw->phy.link_info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006154
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006155 /* Do a new status request to re-enable LSE reporting
6156 * and load new status information into the hw struct
6157 * This completely ignores any state information
6158 * in the ARQ event info, instead choosing to always
6159 * issue the AQ update link status command.
6160 */
6161 i40e_link_event(pf);
6162
Carolyn Wyborny7b592f62014-07-10 07:58:19 +00006163 /* check for unqualified module, if link is down */
6164 if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
6165 (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
6166 (!(status->link_info & I40E_AQ_LINK_UP)))
6167 dev_err(&pf->pdev->dev,
6168 "The driver failed to link because an unqualified module was detected.\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006169}
6170
6171/**
6172 * i40e_clean_adminq_subtask - Clean the AdminQ rings
6173 * @pf: board private structure
6174 **/
6175static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
6176{
6177 struct i40e_arq_event_info event;
6178 struct i40e_hw *hw = &pf->hw;
6179 u16 pending, i = 0;
6180 i40e_status ret;
6181 u16 opcode;
Shannon Nelson86df2422014-05-20 08:01:35 +00006182 u32 oldval;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006183 u32 val;
6184
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006185 /* Do not run clean AQ when PF reset fails */
6186 if (test_bit(__I40E_RESET_FAILED, &pf->state))
6187 return;
6188
Shannon Nelson86df2422014-05-20 08:01:35 +00006189 /* check for error indications */
6190 val = rd32(&pf->hw, pf->hw.aq.arq.len);
6191 oldval = val;
6192 if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
6193 dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
6194 val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
6195 }
6196 if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
6197 dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
6198 val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
6199 }
6200 if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
6201 dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
6202 val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
6203 }
6204 if (oldval != val)
6205 wr32(&pf->hw, pf->hw.aq.arq.len, val);
6206
6207 val = rd32(&pf->hw, pf->hw.aq.asq.len);
6208 oldval = val;
6209 if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
6210 dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
6211 val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
6212 }
6213 if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
6214 dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
6215 val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
6216 }
6217 if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
6218 dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
6219 val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
6220 }
6221 if (oldval != val)
6222 wr32(&pf->hw, pf->hw.aq.asq.len, val);
6223
Mitch Williams1001dc32014-11-11 20:02:19 +00006224 event.buf_len = I40E_MAX_AQ_BUF_SIZE;
6225 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006226 if (!event.msg_buf)
6227 return;
6228
6229 do {
6230 ret = i40e_clean_arq_element(hw, &event, &pending);
Mitch Williams56497972014-06-04 08:45:18 +00006231 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006232 break;
Mitch Williams56497972014-06-04 08:45:18 +00006233 else if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006234 dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
6235 break;
6236 }
6237
6238 opcode = le16_to_cpu(event.desc.opcode);
6239 switch (opcode) {
6240
6241 case i40e_aqc_opc_get_link_status:
6242 i40e_handle_link_event(pf, &event);
6243 break;
6244 case i40e_aqc_opc_send_msg_to_pf:
6245 ret = i40e_vc_process_vf_msg(pf,
6246 le16_to_cpu(event.desc.retval),
6247 le32_to_cpu(event.desc.cookie_high),
6248 le32_to_cpu(event.desc.cookie_low),
6249 event.msg_buf,
Mitch Williams1001dc32014-11-11 20:02:19 +00006250 event.msg_len);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006251 break;
6252 case i40e_aqc_opc_lldp_update_mib:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006253 dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006254#ifdef CONFIG_I40E_DCB
6255 rtnl_lock();
6256 ret = i40e_handle_lldp_event(pf, &event);
6257 rtnl_unlock();
6258#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006259 break;
6260 case i40e_aqc_opc_event_lan_overflow:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006261 dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006262 i40e_handle_lan_overflow_event(pf, &event);
6263 break;
Shannon Nelson0467bc92013-12-18 13:45:58 +00006264 case i40e_aqc_opc_send_msg_to_peer:
6265 dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
6266 break;
Shannon Nelson91a0f932015-03-19 14:32:01 -07006267 case i40e_aqc_opc_nvm_erase:
6268 case i40e_aqc_opc_nvm_update:
6269 i40e_debug(&pf->hw, I40E_DEBUG_NVM, "ARQ NVM operation completed\n");
6270 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006271 default:
6272 dev_info(&pf->pdev->dev,
Shannon Nelson0467bc92013-12-18 13:45:58 +00006273 "ARQ Error: Unknown event 0x%04x received\n",
6274 opcode);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006275 break;
6276 }
6277 } while (pending && (i++ < pf->adminq_work_limit));
6278
6279 clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
6280 /* re-enable Admin queue interrupt cause */
6281 val = rd32(hw, I40E_PFINT_ICR0_ENA);
6282 val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
6283 wr32(hw, I40E_PFINT_ICR0_ENA, val);
6284 i40e_flush(hw);
6285
6286 kfree(event.msg_buf);
6287}
6288
6289/**
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006290 * i40e_verify_eeprom - make sure eeprom is good to use
6291 * @pf: board private structure
6292 **/
6293static void i40e_verify_eeprom(struct i40e_pf *pf)
6294{
6295 int err;
6296
6297 err = i40e_diag_eeprom_test(&pf->hw);
6298 if (err) {
6299 /* retry in case of garbage read */
6300 err = i40e_diag_eeprom_test(&pf->hw);
6301 if (err) {
6302 dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
6303 err);
6304 set_bit(__I40E_BAD_EEPROM, &pf->state);
6305 }
6306 }
6307
6308 if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
6309 dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
6310 clear_bit(__I40E_BAD_EEPROM, &pf->state);
6311 }
6312}
6313
6314/**
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006315 * i40e_enable_pf_switch_lb
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006316 * @pf: pointer to the PF structure
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006317 *
6318 * enable switch loop back or die - no point in a return value
6319 **/
6320static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
6321{
6322 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6323 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006324 int ret;
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006325
6326 ctxt.seid = pf->main_vsi_seid;
6327 ctxt.pf_num = pf->hw.pf_id;
6328 ctxt.vf_num = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006329 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6330 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006331 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006332 "couldn't get PF vsi config, err %s aq_err %s\n",
6333 i40e_stat_str(&pf->hw, ret),
6334 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006335 return;
6336 }
6337 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6338 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6339 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6340
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006341 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6342 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006343 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006344 "update vsi switch failed, err %s aq_err %s\n",
6345 i40e_stat_str(&pf->hw, ret),
6346 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006347 }
6348}
6349
6350/**
6351 * i40e_disable_pf_switch_lb
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006352 * @pf: pointer to the PF structure
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006353 *
6354 * disable switch loop back or die - no point in a return value
6355 **/
6356static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
6357{
6358 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6359 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006360 int ret;
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006361
6362 ctxt.seid = pf->main_vsi_seid;
6363 ctxt.pf_num = pf->hw.pf_id;
6364 ctxt.vf_num = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006365 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6366 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006367 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006368 "couldn't get PF vsi config, err %s aq_err %s\n",
6369 i40e_stat_str(&pf->hw, ret),
6370 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006371 return;
6372 }
6373 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6374 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6375 ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6376
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006377 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6378 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006379 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006380 "update vsi switch failed, err %s aq_err %s\n",
6381 i40e_stat_str(&pf->hw, ret),
6382 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006383 }
6384}
6385
6386/**
Neerav Parikh51616012015-02-06 08:52:14 +00006387 * i40e_config_bridge_mode - Configure the HW bridge mode
6388 * @veb: pointer to the bridge instance
6389 *
6390 * Configure the loop back mode for the LAN VSI that is downlink to the
6391 * specified HW bridge instance. It is expected this function is called
6392 * when a new HW bridge is instantiated.
6393 **/
6394static void i40e_config_bridge_mode(struct i40e_veb *veb)
6395{
6396 struct i40e_pf *pf = veb->pf;
6397
Shannon Nelson6dec1012015-09-28 14:12:30 -04006398 if (pf->hw.debug_mask & I40E_DEBUG_LAN)
6399 dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
6400 veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
Neerav Parikh51616012015-02-06 08:52:14 +00006401 if (veb->bridge_mode & BRIDGE_MODE_VEPA)
6402 i40e_disable_pf_switch_lb(pf);
6403 else
6404 i40e_enable_pf_switch_lb(pf);
6405}
6406
6407/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006408 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
6409 * @veb: pointer to the VEB instance
6410 *
6411 * This is a recursive function that first builds the attached VSIs then
6412 * recurses in to build the next layer of VEB. We track the connections
6413 * through our own index numbers because the seid's from the HW could
6414 * change across the reset.
6415 **/
6416static int i40e_reconstitute_veb(struct i40e_veb *veb)
6417{
6418 struct i40e_vsi *ctl_vsi = NULL;
6419 struct i40e_pf *pf = veb->pf;
6420 int v, veb_idx;
6421 int ret;
6422
6423 /* build VSI that owns this VEB, temporarily attached to base VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00006424 for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006425 if (pf->vsi[v] &&
6426 pf->vsi[v]->veb_idx == veb->idx &&
6427 pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
6428 ctl_vsi = pf->vsi[v];
6429 break;
6430 }
6431 }
6432 if (!ctl_vsi) {
6433 dev_info(&pf->pdev->dev,
6434 "missing owner VSI for veb_idx %d\n", veb->idx);
6435 ret = -ENOENT;
6436 goto end_reconstitute;
6437 }
6438 if (ctl_vsi != pf->vsi[pf->lan_vsi])
6439 ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
6440 ret = i40e_add_vsi(ctl_vsi);
6441 if (ret) {
6442 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006443 "rebuild of veb_idx %d owner VSI failed: %d\n",
6444 veb->idx, ret);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006445 goto end_reconstitute;
6446 }
6447 i40e_vsi_reset_stats(ctl_vsi);
6448
6449 /* create the VEB in the switch and move the VSI onto the VEB */
6450 ret = i40e_add_veb(veb, ctl_vsi);
6451 if (ret)
6452 goto end_reconstitute;
6453
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07006454 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
6455 veb->bridge_mode = BRIDGE_MODE_VEB;
6456 else
6457 veb->bridge_mode = BRIDGE_MODE_VEPA;
Neerav Parikh51616012015-02-06 08:52:14 +00006458 i40e_config_bridge_mode(veb);
Anjali Singhai Jainb64ba082014-11-13 03:06:15 +00006459
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006460 /* create the remaining VSIs attached to this VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00006461 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006462 if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
6463 continue;
6464
6465 if (pf->vsi[v]->veb_idx == veb->idx) {
6466 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04006467
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006468 vsi->uplink_seid = veb->seid;
6469 ret = i40e_add_vsi(vsi);
6470 if (ret) {
6471 dev_info(&pf->pdev->dev,
6472 "rebuild of vsi_idx %d failed: %d\n",
6473 v, ret);
6474 goto end_reconstitute;
6475 }
6476 i40e_vsi_reset_stats(vsi);
6477 }
6478 }
6479
6480 /* create any VEBs attached to this VEB - RECURSION */
6481 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
6482 if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
6483 pf->veb[veb_idx]->uplink_seid = veb->seid;
6484 ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
6485 if (ret)
6486 break;
6487 }
6488 }
6489
6490end_reconstitute:
6491 return ret;
6492}
6493
6494/**
6495 * i40e_get_capabilities - get info about the HW
6496 * @pf: the PF struct
6497 **/
6498static int i40e_get_capabilities(struct i40e_pf *pf)
6499{
6500 struct i40e_aqc_list_capabilities_element_resp *cap_buf;
6501 u16 data_size;
6502 int buf_len;
6503 int err;
6504
6505 buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
6506 do {
6507 cap_buf = kzalloc(buf_len, GFP_KERNEL);
6508 if (!cap_buf)
6509 return -ENOMEM;
6510
6511 /* this loads the data into the hw struct for us */
6512 err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
6513 &data_size,
6514 i40e_aqc_opc_list_func_capabilities,
6515 NULL);
6516 /* data loaded, buffer no longer needed */
6517 kfree(cap_buf);
6518
6519 if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
6520 /* retry with a larger buffer */
6521 buf_len = data_size;
6522 } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
6523 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006524 "capability discovery failed, err %s aq_err %s\n",
6525 i40e_stat_str(&pf->hw, err),
6526 i40e_aq_str(&pf->hw,
6527 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006528 return -ENODEV;
6529 }
6530 } while (err);
6531
6532 if (pf->hw.debug_mask & I40E_DEBUG_USER)
6533 dev_info(&pf->pdev->dev,
6534 "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",
6535 pf->hw.pf_id, pf->hw.func_caps.num_vfs,
6536 pf->hw.func_caps.num_msix_vectors,
6537 pf->hw.func_caps.num_msix_vectors_vf,
6538 pf->hw.func_caps.fd_filters_guaranteed,
6539 pf->hw.func_caps.fd_filters_best_effort,
6540 pf->hw.func_caps.num_tx_qp,
6541 pf->hw.func_caps.num_vsis);
6542
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00006543#define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
6544 + pf->hw.func_caps.num_vfs)
6545 if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
6546 dev_info(&pf->pdev->dev,
6547 "got num_vsis %d, setting num_vsis to %d\n",
6548 pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
6549 pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
6550 }
6551
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006552 return 0;
6553}
6554
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006555static int i40e_vsi_clear(struct i40e_vsi *vsi);
6556
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006557/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006558 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006559 * @pf: board private structure
6560 **/
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006561static void i40e_fdir_sb_setup(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006562{
6563 struct i40e_vsi *vsi;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006564 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006565
Jesse Brandeburg407e0632014-06-03 23:50:12 +00006566 /* quick workaround for an NVM issue that leaves a critical register
6567 * uninitialized
6568 */
6569 if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
6570 static const u32 hkey[] = {
6571 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
6572 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
6573 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
6574 0x95b3a76d};
6575
6576 for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
6577 wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
6578 }
6579
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006580 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006581 return;
6582
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006583 /* find existing VSI and see if it needs configuring */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006584 vsi = NULL;
Mitch Williams505682c2014-05-20 08:01:37 +00006585 for (i = 0; i < pf->num_alloc_vsi; i++) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006586 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006587 vsi = pf->vsi[i];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006588 break;
6589 }
6590 }
6591
6592 /* create a new VSI if none exists */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006593 if (!vsi) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006594 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
6595 pf->vsi[pf->lan_vsi]->seid, 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006596 if (!vsi) {
6597 dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006598 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
6599 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006600 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006601 }
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006602
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006603 i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006604}
6605
6606/**
6607 * i40e_fdir_teardown - release the Flow Director resources
6608 * @pf: board private structure
6609 **/
6610static void i40e_fdir_teardown(struct i40e_pf *pf)
6611{
6612 int i;
6613
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00006614 i40e_fdir_filter_exit(pf);
Mitch Williams505682c2014-05-20 08:01:37 +00006615 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006616 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
6617 i40e_vsi_release(pf->vsi[i]);
6618 break;
6619 }
6620 }
6621}
6622
6623/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006624 * i40e_prep_for_reset - prep for the core to reset
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006625 * @pf: board private structure
6626 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006627 * Close up the VFs and other things in prep for PF Reset.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006628 **/
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006629static void i40e_prep_for_reset(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006630{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006631 struct i40e_hw *hw = &pf->hw;
Shannon Nelson60442de2014-04-23 04:50:13 +00006632 i40e_status ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006633 u32 v;
6634
6635 clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
6636 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006637 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006638
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006639 dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006640
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006641 /* quiesce the VSIs and their queues that are not already DOWN */
6642 i40e_pf_quiesce_all_vsi(pf);
6643
Mitch Williams505682c2014-05-20 08:01:37 +00006644 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006645 if (pf->vsi[v])
6646 pf->vsi[v]->seid = 0;
6647 }
6648
6649 i40e_shutdown_adminq(&pf->hw);
6650
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006651 /* call shutdown HMC */
Shannon Nelson60442de2014-04-23 04:50:13 +00006652 if (hw->hmc.hmc_obj) {
6653 ret = i40e_shutdown_lan_hmc(hw);
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006654 if (ret)
Shannon Nelson60442de2014-04-23 04:50:13 +00006655 dev_warn(&pf->pdev->dev,
6656 "shutdown_lan_hmc failed: %d\n", ret);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006657 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006658}
6659
6660/**
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00006661 * i40e_send_version - update firmware with driver version
6662 * @pf: PF struct
6663 */
6664static void i40e_send_version(struct i40e_pf *pf)
6665{
6666 struct i40e_driver_version dv;
6667
6668 dv.major_version = DRV_VERSION_MAJOR;
6669 dv.minor_version = DRV_VERSION_MINOR;
6670 dv.build_version = DRV_VERSION_BUILD;
6671 dv.subbuild_version = 0;
Rickard Strandqvist35a7d802014-07-29 09:26:25 +00006672 strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00006673 i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
6674}
6675
6676/**
Jesse Brandeburg4dda12e2013-12-18 13:46:01 +00006677 * i40e_reset_and_rebuild - reset and rebuild using a saved config
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006678 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006679 * @reinit: if the Main VSI needs to re-initialized.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006680 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006681static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006682{
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006683 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006684 u8 set_fc_aq_fail = 0;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006685 i40e_status ret;
6686 u32 v;
6687
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006688 /* Now we wait for GRST to settle out.
6689 * We don't have to delete the VEBs or VSIs from the hw switch
6690 * because the reset will make them disappear.
6691 */
6692 ret = i40e_pf_reset(hw);
Akeem G Abodunrinb5565402014-04-09 05:59:04 +00006693 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006694 dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006695 set_bit(__I40E_RESET_FAILED, &pf->state);
6696 goto clear_recovery;
Akeem G Abodunrinb5565402014-04-09 05:59:04 +00006697 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006698 pf->pfr_count++;
6699
6700 if (test_bit(__I40E_DOWN, &pf->state))
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006701 goto clear_recovery;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006702 dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006703
6704 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
6705 ret = i40e_init_adminq(&pf->hw);
6706 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006707 dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
6708 i40e_stat_str(&pf->hw, ret),
6709 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006710 goto clear_recovery;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006711 }
6712
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006713 /* re-verify the eeprom if we just had an EMP reset */
Anjali Singhai Jain9df42d12015-01-24 09:58:40 +00006714 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state))
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006715 i40e_verify_eeprom(pf);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006716
Shannon Nelsone78ac4bf2014-05-10 04:49:09 +00006717 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006718 ret = i40e_get_capabilities(pf);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006719 if (ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006720 goto end_core_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006721
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006722 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
6723 hw->func_caps.num_rx_qp,
6724 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
6725 if (ret) {
6726 dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
6727 goto end_core_reset;
6728 }
6729 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
6730 if (ret) {
6731 dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
6732 goto end_core_reset;
6733 }
6734
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006735#ifdef CONFIG_I40E_DCB
6736 ret = i40e_init_pf_dcb(pf);
6737 if (ret) {
Shannon Nelsonaebfc812014-12-11 07:06:38 +00006738 dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
6739 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
6740 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006741 }
6742#endif /* CONFIG_I40E_DCB */
Vasu Dev38e00432014-08-01 13:27:03 -07006743#ifdef I40E_FCOE
Shannon Nelson21364bc2015-08-26 15:14:13 -04006744 i40e_init_pf_fcoe(pf);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006745
Vasu Dev38e00432014-08-01 13:27:03 -07006746#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006747 /* do basic switch setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006748 ret = i40e_setup_pf_switch(pf, reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006749 if (ret)
6750 goto end_core_reset;
6751
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00006752 /* driver is only interested in link up/down and module qualification
6753 * reports from firmware
6754 */
6755 ret = i40e_aq_set_phy_int_mask(&pf->hw,
6756 I40E_AQ_EVENT_LINK_UPDOWN |
6757 I40E_AQ_EVENT_MODULE_QUAL_FAIL, NULL);
6758 if (ret)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006759 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
6760 i40e_stat_str(&pf->hw, ret),
6761 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00006762
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006763 /* make sure our flow control settings are restored */
6764 ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
6765 if (ret)
Neerav Parikh8279e492015-09-03 17:18:50 -04006766 dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
6767 i40e_stat_str(&pf->hw, ret),
6768 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006769
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006770 /* Rebuild the VSIs and VEBs that existed before reset.
6771 * They are still in our local switch element arrays, so only
6772 * need to rebuild the switch model in the HW.
6773 *
6774 * If there were VEBs but the reconstitution failed, we'll try
6775 * try to recover minimal use by getting the basic PF VSI working.
6776 */
6777 if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006778 dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006779 /* find the one VEB connected to the MAC, and find orphans */
6780 for (v = 0; v < I40E_MAX_VEB; v++) {
6781 if (!pf->veb[v])
6782 continue;
6783
6784 if (pf->veb[v]->uplink_seid == pf->mac_seid ||
6785 pf->veb[v]->uplink_seid == 0) {
6786 ret = i40e_reconstitute_veb(pf->veb[v]);
6787
6788 if (!ret)
6789 continue;
6790
6791 /* If Main VEB failed, we're in deep doodoo,
6792 * so give up rebuilding the switch and set up
6793 * for minimal rebuild of PF VSI.
6794 * If orphan failed, we'll report the error
6795 * but try to keep going.
6796 */
6797 if (pf->veb[v]->uplink_seid == pf->mac_seid) {
6798 dev_info(&pf->pdev->dev,
6799 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
6800 ret);
6801 pf->vsi[pf->lan_vsi]->uplink_seid
6802 = pf->mac_seid;
6803 break;
6804 } else if (pf->veb[v]->uplink_seid == 0) {
6805 dev_info(&pf->pdev->dev,
6806 "rebuild of orphan VEB failed: %d\n",
6807 ret);
6808 }
6809 }
6810 }
6811 }
6812
6813 if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
Shannon Nelsoncde4cbc2014-06-04 01:23:17 +00006814 dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006815 /* no VEB, so rebuild only the Main VSI */
6816 ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
6817 if (ret) {
6818 dev_info(&pf->pdev->dev,
6819 "rebuild of Main VSI failed: %d\n", ret);
6820 goto end_core_reset;
6821 }
6822 }
6823
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00006824 if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
6825 (pf->hw.aq.fw_maj_ver < 4)) {
6826 msleep(75);
6827 ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
6828 if (ret)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006829 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
6830 i40e_stat_str(&pf->hw, ret),
6831 i40e_aq_str(&pf->hw,
6832 pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006833 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006834 /* reinit the misc interrupt */
6835 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
6836 ret = i40e_setup_misc_vector(pf);
6837
6838 /* restart the VSIs that were rebuilt and running before the reset */
6839 i40e_pf_unquiesce_all_vsi(pf);
6840
Mitch Williams69f64b22014-02-13 03:48:46 -08006841 if (pf->num_alloc_vfs) {
6842 for (v = 0; v < pf->num_alloc_vfs; v++)
6843 i40e_reset_vf(&pf->vf[v], true);
6844 }
6845
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006846 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00006847 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006848
6849end_core_reset:
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006850 clear_bit(__I40E_RESET_FAILED, &pf->state);
6851clear_recovery:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006852 clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
6853}
6854
6855/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006856 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006857 * @pf: board private structure
6858 *
6859 * Close up the VFs and other things in prep for a Core Reset,
6860 * then get ready to rebuild the world.
6861 **/
6862static void i40e_handle_reset_warning(struct i40e_pf *pf)
6863{
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006864 i40e_prep_for_reset(pf);
6865 i40e_reset_and_rebuild(pf, false);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006866}
6867
6868/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006869 * i40e_handle_mdd_event
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006870 * @pf: pointer to the PF structure
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006871 *
6872 * Called from the MDD irq handler to identify possibly malicious vfs
6873 **/
6874static void i40e_handle_mdd_event(struct i40e_pf *pf)
6875{
6876 struct i40e_hw *hw = &pf->hw;
6877 bool mdd_detected = false;
Neerav Parikhdf430b12014-06-04 01:23:15 +00006878 bool pf_mdd_detected = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006879 struct i40e_vf *vf;
6880 u32 reg;
6881 int i;
6882
6883 if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
6884 return;
6885
6886 /* find what triggered the MDD event */
6887 reg = rd32(hw, I40E_GL_MDET_TX);
6888 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006889 u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
6890 I40E_GL_MDET_TX_PF_NUM_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00006891 u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006892 I40E_GL_MDET_TX_VF_NUM_SHIFT;
Dan Carpenter013f6572014-10-22 20:06:29 -07006893 u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006894 I40E_GL_MDET_TX_EVENT_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00006895 u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
6896 I40E_GL_MDET_TX_QUEUE_SHIFT) -
6897 pf->hw.func_caps.base_queue;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00006898 if (netif_msg_tx_err(pf))
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006899 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 +00006900 event, queue, pf_num, vf_num);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006901 wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
6902 mdd_detected = true;
6903 }
6904 reg = rd32(hw, I40E_GL_MDET_RX);
6905 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006906 u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
6907 I40E_GL_MDET_RX_FUNCTION_SHIFT;
Dan Carpenter013f6572014-10-22 20:06:29 -07006908 u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006909 I40E_GL_MDET_RX_EVENT_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00006910 u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
6911 I40E_GL_MDET_RX_QUEUE_SHIFT) -
6912 pf->hw.func_caps.base_queue;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00006913 if (netif_msg_rx_err(pf))
6914 dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
6915 event, queue, func);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006916 wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
6917 mdd_detected = true;
6918 }
6919
Neerav Parikhdf430b12014-06-04 01:23:15 +00006920 if (mdd_detected) {
6921 reg = rd32(hw, I40E_PF_MDET_TX);
6922 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
6923 wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00006924 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
Neerav Parikhdf430b12014-06-04 01:23:15 +00006925 pf_mdd_detected = true;
6926 }
6927 reg = rd32(hw, I40E_PF_MDET_RX);
6928 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
6929 wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00006930 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
Neerav Parikhdf430b12014-06-04 01:23:15 +00006931 pf_mdd_detected = true;
6932 }
6933 /* Queue belongs to the PF, initiate a reset */
6934 if (pf_mdd_detected) {
6935 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
6936 i40e_service_event_schedule(pf);
6937 }
6938 }
6939
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006940 /* see if one of the VFs needs its hand slapped */
6941 for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
6942 vf = &(pf->vf[i]);
6943 reg = rd32(hw, I40E_VP_MDET_TX(i));
6944 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
6945 wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
6946 vf->num_mdd_events++;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00006947 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
6948 i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006949 }
6950
6951 reg = rd32(hw, I40E_VP_MDET_RX(i));
6952 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
6953 wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
6954 vf->num_mdd_events++;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00006955 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
6956 i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006957 }
6958
6959 if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
6960 dev_info(&pf->pdev->dev,
6961 "Too many MDD events on VF %d, disabled\n", i);
6962 dev_info(&pf->pdev->dev,
6963 "Use PF Control I/F to re-enable the VF\n");
6964 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
6965 }
6966 }
6967
6968 /* re-enable mdd interrupt cause */
6969 clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
6970 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
6971 reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
6972 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
6973 i40e_flush(hw);
6974}
6975
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00006976#ifdef CONFIG_I40E_VXLAN
6977/**
6978 * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW
6979 * @pf: board private structure
6980 **/
6981static void i40e_sync_vxlan_filters_subtask(struct i40e_pf *pf)
6982{
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00006983 struct i40e_hw *hw = &pf->hw;
6984 i40e_status ret;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00006985 __be16 port;
6986 int i;
6987
6988 if (!(pf->flags & I40E_FLAG_VXLAN_FILTER_SYNC))
6989 return;
6990
6991 pf->flags &= ~I40E_FLAG_VXLAN_FILTER_SYNC;
6992
6993 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04006994 if (pf->pending_vxlan_bitmap & BIT_ULL(i)) {
6995 pf->pending_vxlan_bitmap &= ~BIT_ULL(i);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00006996 port = pf->vxlan_ports[i];
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07006997 if (port)
6998 ret = i40e_aq_add_udp_tunnel(hw, ntohs(port),
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00006999 I40E_AQC_TUNNEL_TYPE_VXLAN,
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007000 NULL, NULL);
7001 else
7002 ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007003
7004 if (ret) {
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007005 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007006 "%s vxlan port %d, index %d failed, err %s aq_err %s\n",
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007007 port ? "add" : "delete",
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007008 ntohs(port), i,
7009 i40e_stat_str(&pf->hw, ret),
7010 i40e_aq_str(&pf->hw,
7011 pf->hw.aq.asq_last_status));
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007012 pf->vxlan_ports[i] = 0;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007013 }
7014 }
7015 }
7016}
7017
7018#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007019/**
7020 * i40e_service_task - Run the driver's async subtasks
7021 * @work: pointer to work_struct containing our data
7022 **/
7023static void i40e_service_task(struct work_struct *work)
7024{
7025 struct i40e_pf *pf = container_of(work,
7026 struct i40e_pf,
7027 service_task);
7028 unsigned long start_time = jiffies;
7029
Shannon Nelsone57a2fe2014-06-03 23:50:19 +00007030 /* don't bother with service tasks if a reset is in progress */
7031 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
7032 i40e_service_event_complete(pf);
7033 return;
7034 }
7035
Kiran Patilb03a8c12015-09-24 18:13:15 -04007036 i40e_detect_recover_hung(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007037 i40e_reset_subtask(pf);
7038 i40e_handle_mdd_event(pf);
7039 i40e_vc_process_vflr_event(pf);
7040 i40e_watchdog_subtask(pf);
7041 i40e_fdir_reinit_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007042 i40e_sync_filters_subtask(pf);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007043#ifdef CONFIG_I40E_VXLAN
7044 i40e_sync_vxlan_filters_subtask(pf);
7045#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007046 i40e_clean_adminq_subtask(pf);
7047
7048 i40e_service_event_complete(pf);
7049
7050 /* If the tasks have taken longer than one timer cycle or there
7051 * is more work to be done, reschedule the service task now
7052 * rather than wait for the timer to tick again.
7053 */
7054 if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
7055 test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
7056 test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
7057 test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
7058 i40e_service_event_schedule(pf);
7059}
7060
7061/**
7062 * i40e_service_timer - timer callback
7063 * @data: pointer to PF struct
7064 **/
7065static void i40e_service_timer(unsigned long data)
7066{
7067 struct i40e_pf *pf = (struct i40e_pf *)data;
7068
7069 mod_timer(&pf->service_timer,
7070 round_jiffies(jiffies + pf->service_timer_period));
7071 i40e_service_event_schedule(pf);
7072}
7073
7074/**
7075 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
7076 * @vsi: the VSI being configured
7077 **/
7078static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
7079{
7080 struct i40e_pf *pf = vsi->back;
7081
7082 switch (vsi->type) {
7083 case I40E_VSI_MAIN:
7084 vsi->alloc_queue_pairs = pf->num_lan_qps;
7085 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7086 I40E_REQ_DESCRIPTOR_MULTIPLE);
7087 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7088 vsi->num_q_vectors = pf->num_lan_msix;
7089 else
7090 vsi->num_q_vectors = 1;
7091
7092 break;
7093
7094 case I40E_VSI_FDIR:
7095 vsi->alloc_queue_pairs = 1;
7096 vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
7097 I40E_REQ_DESCRIPTOR_MULTIPLE);
7098 vsi->num_q_vectors = 1;
7099 break;
7100
7101 case I40E_VSI_VMDQ2:
7102 vsi->alloc_queue_pairs = pf->num_vmdq_qps;
7103 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7104 I40E_REQ_DESCRIPTOR_MULTIPLE);
7105 vsi->num_q_vectors = pf->num_vmdq_msix;
7106 break;
7107
7108 case I40E_VSI_SRIOV:
7109 vsi->alloc_queue_pairs = pf->num_vf_qps;
7110 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7111 I40E_REQ_DESCRIPTOR_MULTIPLE);
7112 break;
7113
Vasu Dev38e00432014-08-01 13:27:03 -07007114#ifdef I40E_FCOE
7115 case I40E_VSI_FCOE:
7116 vsi->alloc_queue_pairs = pf->num_fcoe_qps;
7117 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7118 I40E_REQ_DESCRIPTOR_MULTIPLE);
7119 vsi->num_q_vectors = pf->num_fcoe_msix;
7120 break;
7121
7122#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007123 default:
7124 WARN_ON(1);
7125 return -ENODATA;
7126 }
7127
7128 return 0;
7129}
7130
7131/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007132 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
7133 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007134 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007135 *
7136 * On error: returns error code (negative)
7137 * On success: returns 0
7138 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007139static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007140{
7141 int size;
7142 int ret = 0;
7143
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00007144 /* allocate memory for both Tx and Rx ring pointers */
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007145 size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
7146 vsi->tx_rings = kzalloc(size, GFP_KERNEL);
7147 if (!vsi->tx_rings)
7148 return -ENOMEM;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007149 vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
7150
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007151 if (alloc_qvectors) {
7152 /* allocate memory for q_vector pointers */
Julia Lawallf57e4fb2014-07-30 03:11:09 +00007153 size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007154 vsi->q_vectors = kzalloc(size, GFP_KERNEL);
7155 if (!vsi->q_vectors) {
7156 ret = -ENOMEM;
7157 goto err_vectors;
7158 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007159 }
7160 return ret;
7161
7162err_vectors:
7163 kfree(vsi->tx_rings);
7164 return ret;
7165}
7166
7167/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007168 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
7169 * @pf: board private structure
7170 * @type: type of VSI
7171 *
7172 * On error: returns error code (negative)
7173 * On success: returns vsi index in PF (positive)
7174 **/
7175static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
7176{
7177 int ret = -ENODEV;
7178 struct i40e_vsi *vsi;
7179 int vsi_idx;
7180 int i;
7181
7182 /* Need to protect the allocation of the VSIs at the PF level */
7183 mutex_lock(&pf->switch_mutex);
7184
7185 /* VSI list may be fragmented if VSI creation/destruction has
7186 * been happening. We can afford to do a quick scan to look
7187 * for any free VSIs in the list.
7188 *
7189 * find next empty vsi slot, looping back around if necessary
7190 */
7191 i = pf->next_vsi;
Mitch Williams505682c2014-05-20 08:01:37 +00007192 while (i < pf->num_alloc_vsi && pf->vsi[i])
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007193 i++;
Mitch Williams505682c2014-05-20 08:01:37 +00007194 if (i >= pf->num_alloc_vsi) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007195 i = 0;
7196 while (i < pf->next_vsi && pf->vsi[i])
7197 i++;
7198 }
7199
Mitch Williams505682c2014-05-20 08:01:37 +00007200 if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007201 vsi_idx = i; /* Found one! */
7202 } else {
7203 ret = -ENODEV;
Alexander Duyck493fb302013-09-28 07:01:44 +00007204 goto unlock_pf; /* out of VSI slots! */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007205 }
7206 pf->next_vsi = ++i;
7207
7208 vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
7209 if (!vsi) {
7210 ret = -ENOMEM;
Alexander Duyck493fb302013-09-28 07:01:44 +00007211 goto unlock_pf;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007212 }
7213 vsi->type = type;
7214 vsi->back = pf;
7215 set_bit(__I40E_DOWN, &vsi->state);
7216 vsi->flags = 0;
7217 vsi->idx = vsi_idx;
7218 vsi->rx_itr_setting = pf->rx_itr_default;
7219 vsi->tx_itr_setting = pf->tx_itr_default;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04007220 vsi->int_rate_limit = 0;
Anjali Singhai Jain5db4cb52015-02-24 06:58:49 +00007221 vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
7222 pf->rss_table_size : 64;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007223 vsi->netdev_registered = false;
7224 vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
7225 INIT_LIST_HEAD(&vsi->mac_filter_list);
Shannon Nelson63741842014-04-23 04:50:16 +00007226 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007227
Alexander Duyck9f65e152013-09-28 06:00:58 +00007228 ret = i40e_set_num_rings_in_vsi(vsi);
7229 if (ret)
7230 goto err_rings;
7231
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007232 ret = i40e_vsi_alloc_arrays(vsi, true);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007233 if (ret)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007234 goto err_rings;
Alexander Duyck493fb302013-09-28 07:01:44 +00007235
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007236 /* Setup default MSIX irq handler for VSI */
7237 i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
7238
Kiran Patil21659032015-09-30 14:09:03 -04007239 /* Initialize VSI lock */
7240 spin_lock_init(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007241 pf->vsi[vsi_idx] = vsi;
7242 ret = vsi_idx;
Alexander Duyck493fb302013-09-28 07:01:44 +00007243 goto unlock_pf;
7244
Alexander Duyck9f65e152013-09-28 06:00:58 +00007245err_rings:
Alexander Duyck493fb302013-09-28 07:01:44 +00007246 pf->next_vsi = i - 1;
7247 kfree(vsi);
7248unlock_pf:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007249 mutex_unlock(&pf->switch_mutex);
7250 return ret;
7251}
7252
7253/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007254 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
7255 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007256 * @free_qvectors: a bool to specify if q_vectors need to be freed.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007257 *
7258 * On error: returns error code (negative)
7259 * On success: returns 0
7260 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007261static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007262{
7263 /* free the ring and vector containers */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007264 if (free_qvectors) {
7265 kfree(vsi->q_vectors);
7266 vsi->q_vectors = NULL;
7267 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007268 kfree(vsi->tx_rings);
7269 vsi->tx_rings = NULL;
7270 vsi->rx_rings = NULL;
7271}
7272
7273/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007274 * i40e_vsi_clear - Deallocate the VSI provided
7275 * @vsi: the VSI being un-configured
7276 **/
7277static int i40e_vsi_clear(struct i40e_vsi *vsi)
7278{
7279 struct i40e_pf *pf;
7280
7281 if (!vsi)
7282 return 0;
7283
7284 if (!vsi->back)
7285 goto free_vsi;
7286 pf = vsi->back;
7287
7288 mutex_lock(&pf->switch_mutex);
7289 if (!pf->vsi[vsi->idx]) {
7290 dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
7291 vsi->idx, vsi->idx, vsi, vsi->type);
7292 goto unlock_vsi;
7293 }
7294
7295 if (pf->vsi[vsi->idx] != vsi) {
7296 dev_err(&pf->pdev->dev,
7297 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
7298 pf->vsi[vsi->idx]->idx,
7299 pf->vsi[vsi->idx],
7300 pf->vsi[vsi->idx]->type,
7301 vsi->idx, vsi, vsi->type);
7302 goto unlock_vsi;
7303 }
7304
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00007305 /* updates the PF for this cleared vsi */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007306 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
7307 i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
7308
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007309 i40e_vsi_free_arrays(vsi, true);
Alexander Duyck493fb302013-09-28 07:01:44 +00007310
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007311 pf->vsi[vsi->idx] = NULL;
7312 if (vsi->idx < pf->next_vsi)
7313 pf->next_vsi = vsi->idx;
7314
7315unlock_vsi:
7316 mutex_unlock(&pf->switch_mutex);
7317free_vsi:
7318 kfree(vsi);
7319
7320 return 0;
7321}
7322
7323/**
Alexander Duyck9f65e152013-09-28 06:00:58 +00007324 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
7325 * @vsi: the VSI being cleaned
7326 **/
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00007327static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007328{
7329 int i;
7330
Greg Rose8e9dca52013-12-18 13:45:53 +00007331 if (vsi->tx_rings && vsi->tx_rings[0]) {
Neerav Parikhd7397642013-11-28 06:39:37 +00007332 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Mitch Williams00403f02013-09-28 07:13:13 +00007333 kfree_rcu(vsi->tx_rings[i], rcu);
7334 vsi->tx_rings[i] = NULL;
7335 vsi->rx_rings[i] = NULL;
7336 }
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00007337 }
Alexander Duyck9f65e152013-09-28 06:00:58 +00007338}
7339
7340/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007341 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
7342 * @vsi: the VSI being configured
7343 **/
7344static int i40e_alloc_rings(struct i40e_vsi *vsi)
7345{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00007346 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007347 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007348 int i;
7349
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007350 /* Set basic values in the rings to be used later during open() */
Neerav Parikhd7397642013-11-28 06:39:37 +00007351 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00007352 /* allocate space for both Tx and Rx in one shot */
Alexander Duyck9f65e152013-09-28 06:00:58 +00007353 tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
7354 if (!tx_ring)
7355 goto err_out;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007356
7357 tx_ring->queue_index = i;
7358 tx_ring->reg_idx = vsi->base_queue + i;
7359 tx_ring->ring_active = false;
7360 tx_ring->vsi = vsi;
7361 tx_ring->netdev = vsi->netdev;
7362 tx_ring->dev = &pf->pdev->dev;
7363 tx_ring->count = vsi->num_desc;
7364 tx_ring->size = 0;
7365 tx_ring->dcb_tc = 0;
Anjali Singhai Jain8e0764b2015-06-05 12:20:30 -04007366 if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
7367 tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
Anjali Singhai Jain527274c2015-06-05 12:20:31 -04007368 if (vsi->back->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE)
7369 tx_ring->flags |= I40E_TXR_FLAGS_OUTER_UDP_CSUM;
Alexander Duyck9f65e152013-09-28 06:00:58 +00007370 vsi->tx_rings[i] = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007371
Alexander Duyck9f65e152013-09-28 06:00:58 +00007372 rx_ring = &tx_ring[1];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007373 rx_ring->queue_index = i;
7374 rx_ring->reg_idx = vsi->base_queue + i;
7375 rx_ring->ring_active = false;
7376 rx_ring->vsi = vsi;
7377 rx_ring->netdev = vsi->netdev;
7378 rx_ring->dev = &pf->pdev->dev;
7379 rx_ring->count = vsi->num_desc;
7380 rx_ring->size = 0;
7381 rx_ring->dcb_tc = 0;
7382 if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED)
7383 set_ring_16byte_desc_enabled(rx_ring);
7384 else
7385 clear_ring_16byte_desc_enabled(rx_ring);
Alexander Duyck9f65e152013-09-28 06:00:58 +00007386 vsi->rx_rings[i] = rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007387 }
7388
7389 return 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00007390
7391err_out:
7392 i40e_vsi_clear_rings(vsi);
7393 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007394}
7395
7396/**
7397 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
7398 * @pf: board private structure
7399 * @vectors: the number of MSI-X vectors to request
7400 *
7401 * Returns the number of vectors reserved, or error
7402 **/
7403static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
7404{
Alexander Gordeev7b37f372014-02-18 11:11:42 +01007405 vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
7406 I40E_MIN_MSIX, vectors);
7407 if (vectors < 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007408 dev_info(&pf->pdev->dev,
Alexander Gordeev7b37f372014-02-18 11:11:42 +01007409 "MSI-X vector reservation failed: %d\n", vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007410 vectors = 0;
7411 }
7412
7413 return vectors;
7414}
7415
7416/**
7417 * i40e_init_msix - Setup the MSIX capability
7418 * @pf: board private structure
7419 *
7420 * Work with the OS to set up the MSIX vectors needed.
7421 *
Shannon Nelson3b444392015-02-26 16:15:57 +00007422 * Returns the number of vectors reserved or negative on failure
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007423 **/
7424static int i40e_init_msix(struct i40e_pf *pf)
7425{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007426 struct i40e_hw *hw = &pf->hw;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007427 int vectors_left;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007428 int v_budget, i;
Shannon Nelson3b444392015-02-26 16:15:57 +00007429 int v_actual;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007430
7431 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
7432 return -ENODEV;
7433
7434 /* The number of vectors we'll request will be comprised of:
7435 * - Add 1 for "other" cause for Admin Queue events, etc.
7436 * - The number of LAN queue pairs
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00007437 * - Queues being used for RSS.
7438 * We don't need as many as max_rss_size vectors.
7439 * use rss_size instead in the calculation since that
7440 * is governed by number of cpus in the system.
7441 * - assumes symmetric Tx/Rx pairing
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007442 * - The number of VMDq pairs
Vasu Dev38e00432014-08-01 13:27:03 -07007443#ifdef I40E_FCOE
7444 * - The number of FCOE qps.
7445#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007446 * Once we count this up, try the request.
7447 *
7448 * If we can't get what we want, we'll simplify to nearly nothing
7449 * and try again. If that still fails, we punt.
7450 */
Shannon Nelson1e200e42015-02-27 09:15:24 +00007451 vectors_left = hw->func_caps.num_msix_vectors;
7452 v_budget = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007453
Shannon Nelson1e200e42015-02-27 09:15:24 +00007454 /* reserve one vector for miscellaneous handler */
7455 if (vectors_left) {
7456 v_budget++;
7457 vectors_left--;
7458 }
7459
7460 /* reserve vectors for the main PF traffic queues */
7461 pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left);
7462 vectors_left -= pf->num_lan_msix;
7463 v_budget += pf->num_lan_msix;
7464
7465 /* reserve one vector for sideband flow director */
7466 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
7467 if (vectors_left) {
7468 v_budget++;
7469 vectors_left--;
7470 } else {
7471 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
7472 }
7473 }
John W Linville83840e42015-01-14 03:06:28 +00007474
Vasu Dev38e00432014-08-01 13:27:03 -07007475#ifdef I40E_FCOE
Shannon Nelson1e200e42015-02-27 09:15:24 +00007476 /* can we reserve enough for FCoE? */
Vasu Dev38e00432014-08-01 13:27:03 -07007477 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
Shannon Nelson1e200e42015-02-27 09:15:24 +00007478 if (!vectors_left)
7479 pf->num_fcoe_msix = 0;
7480 else if (vectors_left >= pf->num_fcoe_qps)
7481 pf->num_fcoe_msix = pf->num_fcoe_qps;
7482 else
7483 pf->num_fcoe_msix = 1;
Vasu Dev38e00432014-08-01 13:27:03 -07007484 v_budget += pf->num_fcoe_msix;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007485 vectors_left -= pf->num_fcoe_msix;
Vasu Dev38e00432014-08-01 13:27:03 -07007486 }
Shannon Nelson1e200e42015-02-27 09:15:24 +00007487
Vasu Dev38e00432014-08-01 13:27:03 -07007488#endif
Shannon Nelson1e200e42015-02-27 09:15:24 +00007489 /* any vectors left over go for VMDq support */
7490 if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
7491 int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
7492 int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
7493
7494 /* if we're short on vectors for what's desired, we limit
7495 * the queues per vmdq. If this is still more than are
7496 * available, the user will need to change the number of
7497 * queues/vectors used by the PF later with the ethtool
7498 * channels command
7499 */
7500 if (vmdq_vecs < vmdq_vecs_wanted)
7501 pf->num_vmdq_qps = 1;
7502 pf->num_vmdq_msix = pf->num_vmdq_qps;
7503
7504 v_budget += vmdq_vecs;
7505 vectors_left -= vmdq_vecs;
7506 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007507
7508 pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
7509 GFP_KERNEL);
7510 if (!pf->msix_entries)
7511 return -ENOMEM;
7512
7513 for (i = 0; i < v_budget; i++)
7514 pf->msix_entries[i].entry = i;
Shannon Nelson3b444392015-02-26 16:15:57 +00007515 v_actual = i40e_reserve_msix_vectors(pf, v_budget);
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007516
Shannon Nelson3b444392015-02-26 16:15:57 +00007517 if (v_actual != v_budget) {
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007518 /* If we have limited resources, we will start with no vectors
7519 * for the special features and then allocate vectors to some
7520 * of these features based on the policy and at the end disable
7521 * the features that did not get any vectors.
7522 */
Vasu Dev38e00432014-08-01 13:27:03 -07007523#ifdef I40E_FCOE
7524 pf->num_fcoe_qps = 0;
7525 pf->num_fcoe_msix = 0;
7526#endif
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007527 pf->num_vmdq_msix = 0;
7528 }
7529
Shannon Nelson3b444392015-02-26 16:15:57 +00007530 if (v_actual < I40E_MIN_MSIX) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007531 pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
7532 kfree(pf->msix_entries);
7533 pf->msix_entries = NULL;
7534 return -ENODEV;
7535
Shannon Nelson3b444392015-02-26 16:15:57 +00007536 } else if (v_actual == I40E_MIN_MSIX) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007537 /* Adjust for minimal MSIX use */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007538 pf->num_vmdq_vsis = 0;
7539 pf->num_vmdq_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007540 pf->num_lan_qps = 1;
7541 pf->num_lan_msix = 1;
7542
Shannon Nelson3b444392015-02-26 16:15:57 +00007543 } else if (v_actual != v_budget) {
7544 int vec;
7545
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007546 /* reserve the misc vector */
Shannon Nelson3b444392015-02-26 16:15:57 +00007547 vec = v_actual - 1;
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007548
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007549 /* Scale vector usage down */
7550 pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007551 pf->num_vmdq_vsis = 1;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007552 pf->num_vmdq_qps = 1;
7553 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007554
7555 /* partition out the remaining vectors */
7556 switch (vec) {
7557 case 2:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007558 pf->num_lan_msix = 1;
7559 break;
7560 case 3:
Vasu Dev38e00432014-08-01 13:27:03 -07007561#ifdef I40E_FCOE
7562 /* give one vector to FCoE */
7563 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
7564 pf->num_lan_msix = 1;
7565 pf->num_fcoe_msix = 1;
7566 }
7567#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007568 pf->num_lan_msix = 2;
Vasu Dev38e00432014-08-01 13:27:03 -07007569#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007570 break;
7571 default:
Vasu Dev38e00432014-08-01 13:27:03 -07007572#ifdef I40E_FCOE
7573 /* give one vector to FCoE */
7574 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
7575 pf->num_fcoe_msix = 1;
7576 vec--;
7577 }
7578#endif
Shannon Nelson1e200e42015-02-27 09:15:24 +00007579 /* give the rest to the PF */
7580 pf->num_lan_msix = min_t(int, vec, pf->num_lan_qps);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007581 break;
7582 }
7583 }
7584
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007585 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
7586 (pf->num_vmdq_msix == 0)) {
7587 dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
7588 pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
7589 }
Vasu Dev38e00432014-08-01 13:27:03 -07007590#ifdef I40E_FCOE
7591
7592 if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) {
7593 dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n");
7594 pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
7595 }
7596#endif
Shannon Nelson3b444392015-02-26 16:15:57 +00007597 return v_actual;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007598}
7599
7600/**
Greg Rose90e04072014-03-06 08:59:57 +00007601 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
Alexander Duyck493fb302013-09-28 07:01:44 +00007602 * @vsi: the VSI being configured
7603 * @v_idx: index of the vector in the vsi struct
7604 *
7605 * We allocate one q_vector. If allocation fails we return -ENOMEM.
7606 **/
Greg Rose90e04072014-03-06 08:59:57 +00007607static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx)
Alexander Duyck493fb302013-09-28 07:01:44 +00007608{
7609 struct i40e_q_vector *q_vector;
7610
7611 /* allocate q_vector */
7612 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
7613 if (!q_vector)
7614 return -ENOMEM;
7615
7616 q_vector->vsi = vsi;
7617 q_vector->v_idx = v_idx;
7618 cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
7619 if (vsi->netdev)
7620 netif_napi_add(vsi->netdev, &q_vector->napi,
Jesse Brandeburgeefeace2014-05-10 04:49:13 +00007621 i40e_napi_poll, NAPI_POLL_WEIGHT);
Alexander Duyck493fb302013-09-28 07:01:44 +00007622
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00007623 q_vector->rx.latency_range = I40E_LOW_LATENCY;
7624 q_vector->tx.latency_range = I40E_LOW_LATENCY;
7625
Alexander Duyck493fb302013-09-28 07:01:44 +00007626 /* tie q_vector and vsi together */
7627 vsi->q_vectors[v_idx] = q_vector;
7628
7629 return 0;
7630}
7631
7632/**
Greg Rose90e04072014-03-06 08:59:57 +00007633 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007634 * @vsi: the VSI being configured
7635 *
7636 * We allocate one q_vector per queue interrupt. If allocation fails we
7637 * return -ENOMEM.
7638 **/
Greg Rose90e04072014-03-06 08:59:57 +00007639static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007640{
7641 struct i40e_pf *pf = vsi->back;
7642 int v_idx, num_q_vectors;
Alexander Duyck493fb302013-09-28 07:01:44 +00007643 int err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007644
7645 /* if not MSIX, give the one vector only to the LAN VSI */
7646 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7647 num_q_vectors = vsi->num_q_vectors;
7648 else if (vsi == pf->vsi[pf->lan_vsi])
7649 num_q_vectors = 1;
7650 else
7651 return -EINVAL;
7652
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007653 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
Greg Rose90e04072014-03-06 08:59:57 +00007654 err = i40e_vsi_alloc_q_vector(vsi, v_idx);
Alexander Duyck493fb302013-09-28 07:01:44 +00007655 if (err)
7656 goto err_out;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007657 }
7658
7659 return 0;
Alexander Duyck493fb302013-09-28 07:01:44 +00007660
7661err_out:
7662 while (v_idx--)
7663 i40e_free_q_vector(vsi, v_idx);
7664
7665 return err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007666}
7667
7668/**
7669 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
7670 * @pf: board private structure to initialize
7671 **/
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007672static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007673{
Shannon Nelson3b444392015-02-26 16:15:57 +00007674 int vectors = 0;
7675 ssize_t size;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007676
7677 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
Shannon Nelson3b444392015-02-26 16:15:57 +00007678 vectors = i40e_init_msix(pf);
7679 if (vectors < 0) {
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08007680 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -07007681#ifdef I40E_FCOE
7682 I40E_FLAG_FCOE_ENABLED |
7683#endif
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08007684 I40E_FLAG_RSS_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00007685 I40E_FLAG_DCB_CAPABLE |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08007686 I40E_FLAG_SRIOV_ENABLED |
7687 I40E_FLAG_FD_SB_ENABLED |
7688 I40E_FLAG_FD_ATR_ENABLED |
7689 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007690
7691 /* rework the queue expectations without MSIX */
7692 i40e_determine_queue_usage(pf);
7693 }
7694 }
7695
7696 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
7697 (pf->flags & I40E_FLAG_MSI_ENABLED)) {
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08007698 dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
Shannon Nelson3b444392015-02-26 16:15:57 +00007699 vectors = pci_enable_msi(pf->pdev);
7700 if (vectors < 0) {
7701 dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
7702 vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007703 pf->flags &= ~I40E_FLAG_MSI_ENABLED;
7704 }
Shannon Nelson3b444392015-02-26 16:15:57 +00007705 vectors = 1; /* one MSI or Legacy vector */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007706 }
7707
Shannon Nelson958a3e32013-09-28 07:13:28 +00007708 if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08007709 dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
Shannon Nelson958a3e32013-09-28 07:13:28 +00007710
Shannon Nelson3b444392015-02-26 16:15:57 +00007711 /* set up vector assignment tracking */
7712 size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
7713 pf->irq_pile = kzalloc(size, GFP_KERNEL);
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007714 if (!pf->irq_pile) {
7715 dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n");
7716 return -ENOMEM;
7717 }
Shannon Nelson3b444392015-02-26 16:15:57 +00007718 pf->irq_pile->num_entries = vectors;
7719 pf->irq_pile->search_hint = 0;
7720
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007721 /* track first vector for misc interrupts, ignore return */
Shannon Nelson3b444392015-02-26 16:15:57 +00007722 (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007723
7724 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007725}
7726
7727/**
7728 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
7729 * @pf: board private structure
7730 *
7731 * This sets up the handler for MSIX 0, which is used to manage the
7732 * non-queue interrupts, e.g. AdminQ and errors. This is not used
7733 * when in MSI or Legacy interrupt mode.
7734 **/
7735static int i40e_setup_misc_vector(struct i40e_pf *pf)
7736{
7737 struct i40e_hw *hw = &pf->hw;
7738 int err = 0;
7739
7740 /* Only request the irq if this is the first time through, and
7741 * not when we're rebuilding after a Reset
7742 */
7743 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
7744 err = request_irq(pf->msix_entries[0].vector,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00007745 i40e_intr, 0, pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007746 if (err) {
7747 dev_info(&pf->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08007748 "request_irq for %s failed: %d\n",
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00007749 pf->int_name, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007750 return -EFAULT;
7751 }
7752 }
7753
Jacob Kellerab437b52014-12-14 01:55:08 +00007754 i40e_enable_misc_int_causes(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007755
7756 /* associate no queues to the misc vector */
7757 wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
7758 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
7759
7760 i40e_flush(hw);
7761
7762 i40e_irq_dynamic_enable_icr0(pf);
7763
7764 return err;
7765}
7766
7767/**
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007768 * i40e_config_rss_aq - Prepare for RSS using AQ commands
7769 * @vsi: vsi structure
7770 * @seed: RSS hash seed
7771 **/
7772static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed)
7773{
7774 struct i40e_aqc_get_set_rss_key_data rss_key;
7775 struct i40e_pf *pf = vsi->back;
7776 struct i40e_hw *hw = &pf->hw;
7777 bool pf_lut = false;
7778 u8 *rss_lut;
7779 int ret, i;
7780
7781 memset(&rss_key, 0, sizeof(rss_key));
7782 memcpy(&rss_key, seed, sizeof(rss_key));
7783
7784 rss_lut = kzalloc(pf->rss_table_size, GFP_KERNEL);
7785 if (!rss_lut)
7786 return -ENOMEM;
7787
7788 /* Populate the LUT with max no. of queues in round robin fashion */
7789 for (i = 0; i < vsi->rss_table_size; i++)
7790 rss_lut[i] = i % vsi->rss_size;
7791
7792 ret = i40e_aq_set_rss_key(hw, vsi->id, &rss_key);
7793 if (ret) {
7794 dev_info(&pf->pdev->dev,
7795 "Cannot set RSS key, err %s aq_err %s\n",
7796 i40e_stat_str(&pf->hw, ret),
7797 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai126b63d2015-08-24 13:26:53 -07007798 goto config_rss_aq_out;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007799 }
7800
7801 if (vsi->type == I40E_VSI_MAIN)
7802 pf_lut = true;
7803
7804 ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, rss_lut,
7805 vsi->rss_table_size);
7806 if (ret)
7807 dev_info(&pf->pdev->dev,
7808 "Cannot set RSS lut, err %s aq_err %s\n",
7809 i40e_stat_str(&pf->hw, ret),
7810 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
7811
Anjali Singhai126b63d2015-08-24 13:26:53 -07007812config_rss_aq_out:
7813 kfree(rss_lut);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007814 return ret;
7815}
7816
7817/**
7818 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
7819 * @vsi: VSI structure
7820 **/
7821static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
7822{
7823 u8 seed[I40E_HKEY_ARRAY_SIZE];
7824 struct i40e_pf *pf = vsi->back;
7825
7826 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
7827 vsi->rss_size = min_t(int, pf->rss_size, vsi->num_queue_pairs);
7828
7829 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
7830 return i40e_config_rss_aq(vsi, seed);
7831
7832 return 0;
7833}
7834
7835/**
7836 * i40e_config_rss_reg - Prepare for RSS if used
7837 * @pf: board private structure
7838 * @seed: RSS hash seed
7839 **/
7840static int i40e_config_rss_reg(struct i40e_pf *pf, const u8 *seed)
7841{
7842 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
7843 struct i40e_hw *hw = &pf->hw;
7844 u32 *seed_dw = (u32 *)seed;
7845 u32 current_queue = 0;
7846 u32 lut = 0;
7847 int i, j;
7848
7849 /* Fill out hash function seed */
7850 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
7851 wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
7852
7853 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
7854 lut = 0;
7855 for (j = 0; j < 4; j++) {
7856 if (current_queue == vsi->rss_size)
7857 current_queue = 0;
7858 lut |= ((current_queue) << (8 * j));
7859 current_queue++;
7860 }
7861 wr32(&pf->hw, I40E_PFQF_HLUT(i), lut);
7862 }
7863 i40e_flush(hw);
7864
7865 return 0;
7866}
7867
7868/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007869 * i40e_config_rss - Prepare for RSS if used
7870 * @pf: board private structure
7871 **/
7872static int i40e_config_rss(struct i40e_pf *pf)
7873{
Anjali Singhai Jain66ddcff2015-02-24 06:58:50 +00007874 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007875 u8 seed[I40E_HKEY_ARRAY_SIZE];
Anjali Singhai Jain4617e8c2013-11-20 10:02:56 +00007876 struct i40e_hw *hw = &pf->hw;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00007877 u32 reg_val;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007878 u64 hena;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007879
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007880 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007881
7882 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
7883 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
7884 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007885 hena |= i40e_pf_get_default_rss_hena(pf);
7886
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007887 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
7888 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
7889
Anjali Singhai Jain66ddcff2015-02-24 06:58:50 +00007890 vsi->rss_size = min_t(int, pf->rss_size, vsi->num_queue_pairs);
7891
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007892 /* Determine the RSS table size based on the hardware capabilities */
Carolyn Wybornye157ea32014-06-03 23:50:22 +00007893 reg_val = rd32(hw, I40E_PFQF_CTL_0);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007894 reg_val = (pf->rss_table_size == 512) ?
7895 (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
7896 (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
Carolyn Wybornye157ea32014-06-03 23:50:22 +00007897 wr32(hw, I40E_PFQF_CTL_0, reg_val);
7898
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007899 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
7900 return i40e_config_rss_aq(pf->vsi[pf->lan_vsi], seed);
7901 else
7902 return i40e_config_rss_reg(pf, seed);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007903}
7904
7905/**
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00007906 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
7907 * @pf: board private structure
7908 * @queue_count: the requested queue count for rss.
7909 *
7910 * returns 0 if rss is not enabled, if enabled returns the final rss queue
7911 * count which may be different from the requested queue count.
7912 **/
7913int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
7914{
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00007915 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
7916 int new_rss_size;
7917
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00007918 if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
7919 return 0;
7920
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00007921 new_rss_size = min_t(int, queue_count, pf->rss_size_max);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00007922
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00007923 if (queue_count != vsi->num_queue_pairs) {
7924 vsi->req_queue_pairs = queue_count;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00007925 i40e_prep_for_reset(pf);
7926
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00007927 pf->rss_size = new_rss_size;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00007928
7929 i40e_reset_and_rebuild(pf, true);
7930 i40e_config_rss(pf);
7931 }
7932 dev_info(&pf->pdev->dev, "RSS count: %d\n", pf->rss_size);
7933 return pf->rss_size;
7934}
7935
7936/**
Greg Rosef4492db2015-02-06 08:52:12 +00007937 * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
7938 * @pf: board private structure
7939 **/
7940i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf)
7941{
7942 i40e_status status;
7943 bool min_valid, max_valid;
7944 u32 max_bw, min_bw;
7945
7946 status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
7947 &min_valid, &max_valid);
7948
7949 if (!status) {
7950 if (min_valid)
7951 pf->npar_min_bw = min_bw;
7952 if (max_valid)
7953 pf->npar_max_bw = max_bw;
7954 }
7955
7956 return status;
7957}
7958
7959/**
7960 * i40e_set_npar_bw_setting - Set BW settings for this PF partition
7961 * @pf: board private structure
7962 **/
7963i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf)
7964{
7965 struct i40e_aqc_configure_partition_bw_data bw_data;
7966 i40e_status status;
7967
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00007968 /* Set the valid bit for this PF */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04007969 bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
Greg Rosef4492db2015-02-06 08:52:12 +00007970 bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK;
7971 bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK;
7972
7973 /* Set the new bandwidths */
7974 status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
7975
7976 return status;
7977}
7978
7979/**
7980 * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
7981 * @pf: board private structure
7982 **/
7983i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf)
7984{
7985 /* Commit temporary BW setting to permanent NVM image */
7986 enum i40e_admin_queue_err last_aq_status;
7987 i40e_status ret;
7988 u16 nvm_word;
7989
7990 if (pf->hw.partition_id != 1) {
7991 dev_info(&pf->pdev->dev,
7992 "Commit BW only works on partition 1! This is partition %d",
7993 pf->hw.partition_id);
7994 ret = I40E_NOT_SUPPORTED;
7995 goto bw_commit_out;
7996 }
7997
7998 /* Acquire NVM for read access */
7999 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
8000 last_aq_status = pf->hw.aq.asq_last_status;
8001 if (ret) {
8002 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008003 "Cannot acquire NVM for read access, err %s aq_err %s\n",
8004 i40e_stat_str(&pf->hw, ret),
8005 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008006 goto bw_commit_out;
8007 }
8008
8009 /* Read word 0x10 of NVM - SW compatibility word 1 */
8010 ret = i40e_aq_read_nvm(&pf->hw,
8011 I40E_SR_NVM_CONTROL_WORD,
8012 0x10, sizeof(nvm_word), &nvm_word,
8013 false, NULL);
8014 /* Save off last admin queue command status before releasing
8015 * the NVM
8016 */
8017 last_aq_status = pf->hw.aq.asq_last_status;
8018 i40e_release_nvm(&pf->hw);
8019 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008020 dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
8021 i40e_stat_str(&pf->hw, ret),
8022 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008023 goto bw_commit_out;
8024 }
8025
8026 /* Wait a bit for NVM release to complete */
8027 msleep(50);
8028
8029 /* Acquire NVM for write access */
8030 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
8031 last_aq_status = pf->hw.aq.asq_last_status;
8032 if (ret) {
8033 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008034 "Cannot acquire NVM for write access, err %s aq_err %s\n",
8035 i40e_stat_str(&pf->hw, ret),
8036 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008037 goto bw_commit_out;
8038 }
8039 /* Write it back out unchanged to initiate update NVM,
8040 * which will force a write of the shadow (alt) RAM to
8041 * the NVM - thus storing the bandwidth values permanently.
8042 */
8043 ret = i40e_aq_update_nvm(&pf->hw,
8044 I40E_SR_NVM_CONTROL_WORD,
8045 0x10, sizeof(nvm_word),
8046 &nvm_word, true, NULL);
8047 /* Save off last admin queue command status before releasing
8048 * the NVM
8049 */
8050 last_aq_status = pf->hw.aq.asq_last_status;
8051 i40e_release_nvm(&pf->hw);
8052 if (ret)
8053 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008054 "BW settings NOT SAVED, err %s aq_err %s\n",
8055 i40e_stat_str(&pf->hw, ret),
8056 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008057bw_commit_out:
8058
8059 return ret;
8060}
8061
8062/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008063 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
8064 * @pf: board private structure to initialize
8065 *
8066 * i40e_sw_init initializes the Adapter private data structure.
8067 * Fields are initialized based on PCI device information and
8068 * OS network device settings (MTU size).
8069 **/
8070static int i40e_sw_init(struct i40e_pf *pf)
8071{
8072 int err = 0;
8073 int size;
8074
8075 pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE,
8076 (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK));
Shannon Nelson27599972013-11-16 10:00:43 +00008077 pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008078 if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) {
8079 if (I40E_DEBUG_USER & debug)
8080 pf->hw.debug_mask = debug;
8081 pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER),
8082 I40E_DEFAULT_MSG_ENABLE);
8083 }
8084
8085 /* Set default capability flags */
8086 pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
8087 I40E_FLAG_MSI_ENABLED |
Shannon Nelson9ac77262015-08-27 11:42:40 -04008088 I40E_FLAG_LINK_POLLING_ENABLED |
Mitch Williams2bc7ee82015-02-06 08:52:11 +00008089 I40E_FLAG_MSIX_ENABLED;
8090
8091 if (iommu_present(&pci_bus_type))
8092 pf->flags |= I40E_FLAG_RX_PS_ENABLED;
8093 else
8094 pf->flags |= I40E_FLAG_RX_1BUF_ENABLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008095
Mitch Williamsca99eb92014-04-04 04:43:07 +00008096 /* Set default ITR */
8097 pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
8098 pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
8099
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008100 /* Depending on PF configurations, it is possible that the RSS
8101 * maximum might end up larger than the available queues
8102 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008103 pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
Paul M Stillwell Jrec9a7db2014-07-09 07:46:10 +00008104 pf->rss_size = 1;
Anjali Singhai Jain5db4cb52015-02-24 06:58:49 +00008105 pf->rss_table_size = pf->hw.func_caps.rss_table_size;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008106 pf->rss_size_max = min_t(int, pf->rss_size_max,
8107 pf->hw.func_caps.num_tx_qp);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008108 if (pf->hw.func_caps.rss) {
8109 pf->flags |= I40E_FLAG_RSS_ENABLED;
Jesse Brandeburgbf051a32013-11-26 10:49:17 +00008110 pf->rss_size = min_t(int, pf->rss_size_max, num_online_cpus());
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008111 }
8112
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008113 /* MFP mode enabled */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04008114 if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008115 pf->flags |= I40E_FLAG_MFP_ENABLED;
8116 dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
Greg Rosef4492db2015-02-06 08:52:12 +00008117 if (i40e_get_npar_bw_setting(pf))
8118 dev_warn(&pf->pdev->dev,
8119 "Could not get NPAR bw settings\n");
8120 else
8121 dev_info(&pf->pdev->dev,
8122 "Min BW = %8.8x, Max BW = %8.8x\n",
8123 pf->npar_min_bw, pf->npar_max_bw);
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008124 }
8125
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008126 /* FW/NVM is not yet fixed in this regard */
8127 if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
8128 (pf->hw.func_caps.fd_filters_best_effort > 0)) {
8129 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
8130 pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
Shannon Nelson6eae9c62015-09-03 17:18:55 -04008131 if (pf->flags & I40E_FLAG_MFP_ENABLED &&
8132 pf->hw.num_partitions > 1)
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008133 dev_info(&pf->pdev->dev,
Anjali Singhai Jain0b675842014-03-06 08:59:51 +00008134 "Flow Director Sideband mode Disabled in MFP mode\n");
Shannon Nelson6eae9c62015-09-03 17:18:55 -04008135 else
8136 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008137 pf->fdir_pf_filter_count =
8138 pf->hw.func_caps.fd_filters_guaranteed;
8139 pf->hw.fdir_shared_filter_count =
8140 pf->hw.func_caps.fd_filters_best_effort;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008141 }
8142
8143 if (pf->hw.func_caps.vmdq) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008144 pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008145 pf->flags |= I40E_FLAG_VMDQ_ENABLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008146 }
8147
Vasu Dev38e00432014-08-01 13:27:03 -07008148#ifdef I40E_FCOE
Shannon Nelson21364bc2015-08-26 15:14:13 -04008149 i40e_init_pf_fcoe(pf);
Vasu Dev38e00432014-08-01 13:27:03 -07008150
8151#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008152#ifdef CONFIG_PCI_IOV
Shannon Nelsonba252f132014-12-11 07:06:34 +00008153 if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008154 pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
8155 pf->flags |= I40E_FLAG_SRIOV_ENABLED;
8156 pf->num_req_vfs = min_t(int,
8157 pf->hw.func_caps.num_vfs,
8158 I40E_MAX_VF_COUNT);
8159 }
8160#endif /* CONFIG_PCI_IOV */
Anjali Singhai Jaind502ce02015-06-05 12:20:26 -04008161 if (pf->hw.mac.type == I40E_MAC_X722) {
8162 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE |
8163 I40E_FLAG_128_QP_RSS_CAPABLE |
8164 I40E_FLAG_HW_ATR_EVICT_CAPABLE |
8165 I40E_FLAG_OUTER_UDP_CSUM_CAPABLE |
8166 I40E_FLAG_WB_ON_ITR_CAPABLE |
8167 I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE;
8168 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008169 pf->eeprom_version = 0xDEAD;
8170 pf->lan_veb = I40E_NO_VEB;
8171 pf->lan_vsi = I40E_NO_VSI;
8172
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04008173 /* By default FW has this off for performance reasons */
8174 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
8175
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008176 /* set up queue assignment tracking */
8177 size = sizeof(struct i40e_lump_tracking)
8178 + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
8179 pf->qp_pile = kzalloc(size, GFP_KERNEL);
8180 if (!pf->qp_pile) {
8181 err = -ENOMEM;
8182 goto sw_init_done;
8183 }
8184 pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
8185 pf->qp_pile->search_hint = 0;
8186
Anjali Singhai Jain327fe042014-06-04 01:23:26 +00008187 pf->tx_timeout_recovery_level = 1;
8188
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008189 mutex_init(&pf->switch_mutex);
8190
Greg Rosec668a122015-02-26 16:10:39 +00008191 /* If NPAR is enabled nudge the Tx scheduler */
8192 if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf)))
8193 i40e_set_npar_bw_setting(pf);
8194
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008195sw_init_done:
8196 return err;
8197}
8198
8199/**
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008200 * i40e_set_ntuple - set the ntuple feature flag and take action
8201 * @pf: board private structure to initialize
8202 * @features: the feature set that the stack is suggesting
8203 *
8204 * returns a bool to indicate if reset needs to happen
8205 **/
8206bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
8207{
8208 bool need_reset = false;
8209
8210 /* Check if Flow Director n-tuple support was enabled or disabled. If
8211 * the state changed, we need to reset.
8212 */
8213 if (features & NETIF_F_NTUPLE) {
8214 /* Enable filters and mark for reset */
8215 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
8216 need_reset = true;
8217 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
8218 } else {
8219 /* turn off filters, mark for reset and clear SW filter list */
8220 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
8221 need_reset = true;
8222 i40e_fdir_filter_exit(pf);
8223 }
8224 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain8a4f34f2014-06-04 08:45:20 +00008225 pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00008226 /* reset fd counters */
8227 pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0;
8228 pf->fdir_pf_active_filters = 0;
8229 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04008230 if (I40E_DEBUG_FD & pf->hw.debug_mask)
8231 dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
Anjali Singhai Jain8a4f34f2014-06-04 08:45:20 +00008232 /* if ATR was auto disabled it can be re-enabled. */
8233 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
8234 (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
8235 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008236 }
8237 return need_reset;
8238}
8239
8240/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008241 * i40e_set_features - set the netdev feature flags
8242 * @netdev: ptr to the netdev being adjusted
8243 * @features: the feature set that the stack is suggesting
8244 **/
8245static int i40e_set_features(struct net_device *netdev,
8246 netdev_features_t features)
8247{
8248 struct i40e_netdev_priv *np = netdev_priv(netdev);
8249 struct i40e_vsi *vsi = np->vsi;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008250 struct i40e_pf *pf = vsi->back;
8251 bool need_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008252
8253 if (features & NETIF_F_HW_VLAN_CTAG_RX)
8254 i40e_vlan_stripping_enable(vsi);
8255 else
8256 i40e_vlan_stripping_disable(vsi);
8257
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008258 need_reset = i40e_set_ntuple(pf, features);
8259
8260 if (need_reset)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008261 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008262
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008263 return 0;
8264}
8265
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008266#ifdef CONFIG_I40E_VXLAN
8267/**
8268 * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port
8269 * @pf: board private structure
8270 * @port: The UDP port to look up
8271 *
8272 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
8273 **/
8274static u8 i40e_get_vxlan_port_idx(struct i40e_pf *pf, __be16 port)
8275{
8276 u8 i;
8277
8278 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
8279 if (pf->vxlan_ports[i] == port)
8280 return i;
8281 }
8282
8283 return i;
8284}
8285
8286/**
8287 * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
8288 * @netdev: This physical port's netdev
8289 * @sa_family: Socket Family that VXLAN is notifying us about
8290 * @port: New UDP port number that VXLAN started listening to
8291 **/
8292static void i40e_add_vxlan_port(struct net_device *netdev,
8293 sa_family_t sa_family, __be16 port)
8294{
8295 struct i40e_netdev_priv *np = netdev_priv(netdev);
8296 struct i40e_vsi *vsi = np->vsi;
8297 struct i40e_pf *pf = vsi->back;
8298 u8 next_idx;
8299 u8 idx;
8300
8301 if (sa_family == AF_INET6)
8302 return;
8303
8304 idx = i40e_get_vxlan_port_idx(pf, port);
8305
8306 /* Check if port already exists */
8307 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07008308 netdev_info(netdev, "vxlan port %d already offloaded\n",
8309 ntohs(port));
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008310 return;
8311 }
8312
8313 /* Now check if there is space to add the new port */
8314 next_idx = i40e_get_vxlan_port_idx(pf, 0);
8315
8316 if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07008317 netdev_info(netdev, "maximum number of vxlan UDP ports reached, not adding port %d\n",
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008318 ntohs(port));
8319 return;
8320 }
8321
8322 /* New port: add it and mark its index in the bitmap */
8323 pf->vxlan_ports[next_idx] = port;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008324 pf->pending_vxlan_bitmap |= BIT_ULL(next_idx);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008325 pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC;
8326}
8327
8328/**
8329 * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
8330 * @netdev: This physical port's netdev
8331 * @sa_family: Socket Family that VXLAN is notifying us about
8332 * @port: UDP port number that VXLAN stopped listening to
8333 **/
8334static void i40e_del_vxlan_port(struct net_device *netdev,
8335 sa_family_t sa_family, __be16 port)
8336{
8337 struct i40e_netdev_priv *np = netdev_priv(netdev);
8338 struct i40e_vsi *vsi = np->vsi;
8339 struct i40e_pf *pf = vsi->back;
8340 u8 idx;
8341
8342 if (sa_family == AF_INET6)
8343 return;
8344
8345 idx = i40e_get_vxlan_port_idx(pf, port);
8346
8347 /* Check if port already exists */
8348 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
8349 /* if port exists, set it to 0 (mark for deletion)
8350 * and make it pending
8351 */
8352 pf->vxlan_ports[idx] = 0;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008353 pf->pending_vxlan_bitmap |= BIT_ULL(idx);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008354 pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC;
8355 } else {
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07008356 netdev_warn(netdev, "vxlan port %d was not found, not deleting\n",
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008357 ntohs(port));
8358 }
8359}
8360
8361#endif
Neerav Parikh1f224ad2014-02-12 01:45:31 +00008362static int i40e_get_phys_port_id(struct net_device *netdev,
Jiri Pirko02637fc2014-11-28 14:34:16 +01008363 struct netdev_phys_item_id *ppid)
Neerav Parikh1f224ad2014-02-12 01:45:31 +00008364{
8365 struct i40e_netdev_priv *np = netdev_priv(netdev);
8366 struct i40e_pf *pf = np->vsi->back;
8367 struct i40e_hw *hw = &pf->hw;
8368
8369 if (!(pf->flags & I40E_FLAG_PORT_ID_VALID))
8370 return -EOPNOTSUPP;
8371
8372 ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
8373 memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
8374
8375 return 0;
8376}
8377
Jesse Brandeburg2f90ade2014-11-20 16:30:02 -08008378/**
8379 * i40e_ndo_fdb_add - add an entry to the hardware database
8380 * @ndm: the input from the stack
8381 * @tb: pointer to array of nladdr (unused)
8382 * @dev: the net device pointer
8383 * @addr: the MAC address entry being added
8384 * @flags: instructions from stack about fdb operation
8385 */
Greg Rose4ba0dea2014-03-06 08:59:55 +00008386static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
8387 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01008388 const unsigned char *addr, u16 vid,
Greg Rose4ba0dea2014-03-06 08:59:55 +00008389 u16 flags)
Greg Rose4ba0dea2014-03-06 08:59:55 +00008390{
8391 struct i40e_netdev_priv *np = netdev_priv(dev);
8392 struct i40e_pf *pf = np->vsi->back;
8393 int err = 0;
8394
8395 if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
8396 return -EOPNOTSUPP;
8397
Or Gerlitz65891fe2014-12-14 18:19:05 +02008398 if (vid) {
8399 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
8400 return -EINVAL;
8401 }
8402
Greg Rose4ba0dea2014-03-06 08:59:55 +00008403 /* Hardware does not support aging addresses so if a
8404 * ndm_state is given only allow permanent addresses
8405 */
8406 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
8407 netdev_info(dev, "FDB only supports static addresses\n");
8408 return -EINVAL;
8409 }
8410
8411 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
8412 err = dev_uc_add_excl(dev, addr);
8413 else if (is_multicast_ether_addr(addr))
8414 err = dev_mc_add_excl(dev, addr);
8415 else
8416 err = -EINVAL;
8417
8418 /* Only return duplicate errors if NLM_F_EXCL is set */
8419 if (err == -EEXIST && !(flags & NLM_F_EXCL))
8420 err = 0;
8421
8422 return err;
8423}
8424
Neerav Parikh51616012015-02-06 08:52:14 +00008425/**
8426 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
8427 * @dev: the netdev being configured
8428 * @nlh: RTNL message
8429 *
8430 * Inserts a new hardware bridge if not already created and
8431 * enables the bridging mode requested (VEB or VEPA). If the
8432 * hardware bridge has already been inserted and the request
8433 * is to change the mode then that requires a PF reset to
8434 * allow rebuild of the components with required hardware
8435 * bridge mode enabled.
8436 **/
8437static int i40e_ndo_bridge_setlink(struct net_device *dev,
Carolyn Wyborny9df70b62015-04-27 14:57:11 -04008438 struct nlmsghdr *nlh,
8439 u16 flags)
Neerav Parikh51616012015-02-06 08:52:14 +00008440{
8441 struct i40e_netdev_priv *np = netdev_priv(dev);
8442 struct i40e_vsi *vsi = np->vsi;
8443 struct i40e_pf *pf = vsi->back;
8444 struct i40e_veb *veb = NULL;
8445 struct nlattr *attr, *br_spec;
8446 int i, rem;
8447
8448 /* Only for PF VSI for now */
8449 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
8450 return -EOPNOTSUPP;
8451
8452 /* Find the HW bridge for PF VSI */
8453 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
8454 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
8455 veb = pf->veb[i];
8456 }
8457
8458 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
8459
8460 nla_for_each_nested(attr, br_spec, rem) {
8461 __u16 mode;
8462
8463 if (nla_type(attr) != IFLA_BRIDGE_MODE)
8464 continue;
8465
8466 mode = nla_get_u16(attr);
8467 if ((mode != BRIDGE_MODE_VEPA) &&
8468 (mode != BRIDGE_MODE_VEB))
8469 return -EINVAL;
8470
8471 /* Insert a new HW bridge */
8472 if (!veb) {
8473 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
8474 vsi->tc_config.enabled_tc);
8475 if (veb) {
8476 veb->bridge_mode = mode;
8477 i40e_config_bridge_mode(veb);
8478 } else {
8479 /* No Bridge HW offload available */
8480 return -ENOENT;
8481 }
8482 break;
8483 } else if (mode != veb->bridge_mode) {
8484 /* Existing HW bridge but different mode needs reset */
8485 veb->bridge_mode = mode;
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07008486 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
8487 if (mode == BRIDGE_MODE_VEB)
8488 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
8489 else
8490 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
8491 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Neerav Parikh51616012015-02-06 08:52:14 +00008492 break;
8493 }
8494 }
8495
8496 return 0;
8497}
8498
8499/**
8500 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
8501 * @skb: skb buff
8502 * @pid: process id
8503 * @seq: RTNL message seq #
8504 * @dev: the netdev being configured
8505 * @filter_mask: unused
Jesse Brandeburgd4b2f9f2015-09-03 17:18:48 -04008506 * @nlflags: netlink flags passed in
Neerav Parikh51616012015-02-06 08:52:14 +00008507 *
8508 * Return the mode in which the hardware bridge is operating in
8509 * i.e VEB or VEPA.
8510 **/
Neerav Parikh51616012015-02-06 08:52:14 +00008511static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8512 struct net_device *dev,
Carolyn Wyborny9f4ffc42015-08-31 19:54:42 -04008513 u32 __always_unused filter_mask,
8514 int nlflags)
Neerav Parikh51616012015-02-06 08:52:14 +00008515{
8516 struct i40e_netdev_priv *np = netdev_priv(dev);
8517 struct i40e_vsi *vsi = np->vsi;
8518 struct i40e_pf *pf = vsi->back;
8519 struct i40e_veb *veb = NULL;
8520 int i;
8521
8522 /* Only for PF VSI for now */
8523 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
8524 return -EOPNOTSUPP;
8525
8526 /* Find the HW bridge for the PF VSI */
8527 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
8528 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
8529 veb = pf->veb[i];
8530 }
8531
8532 if (!veb)
8533 return 0;
8534
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02008535 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07008536 nlflags, 0, 0, filter_mask, NULL);
Neerav Parikh51616012015-02-06 08:52:14 +00008537}
Neerav Parikh51616012015-02-06 08:52:14 +00008538
Joe Stringerf44a75e2015-04-14 17:09:14 -07008539#define I40E_MAX_TUNNEL_HDR_LEN 80
8540/**
8541 * i40e_features_check - Validate encapsulated packet conforms to limits
8542 * @skb: skb buff
8543 * @netdev: This physical port's netdev
8544 * @features: Offload features that the stack believes apply
8545 **/
8546static netdev_features_t i40e_features_check(struct sk_buff *skb,
8547 struct net_device *dev,
8548 netdev_features_t features)
8549{
8550 if (skb->encapsulation &&
8551 (skb_inner_mac_header(skb) - skb_transport_header(skb) >
8552 I40E_MAX_TUNNEL_HDR_LEN))
8553 return features & ~(NETIF_F_ALL_CSUM | NETIF_F_GSO_MASK);
8554
8555 return features;
8556}
8557
Shannon Nelson37a29732015-02-27 09:15:19 +00008558static const struct net_device_ops i40e_netdev_ops = {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008559 .ndo_open = i40e_open,
8560 .ndo_stop = i40e_close,
8561 .ndo_start_xmit = i40e_lan_xmit_frame,
8562 .ndo_get_stats64 = i40e_get_netdev_stats_struct,
8563 .ndo_set_rx_mode = i40e_set_rx_mode,
8564 .ndo_validate_addr = eth_validate_addr,
8565 .ndo_set_mac_address = i40e_set_mac,
8566 .ndo_change_mtu = i40e_change_mtu,
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00008567 .ndo_do_ioctl = i40e_ioctl,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008568 .ndo_tx_timeout = i40e_tx_timeout,
8569 .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
8570 .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
8571#ifdef CONFIG_NET_POLL_CONTROLLER
8572 .ndo_poll_controller = i40e_netpoll,
8573#endif
8574 .ndo_setup_tc = i40e_setup_tc,
Vasu Dev38e00432014-08-01 13:27:03 -07008575#ifdef I40E_FCOE
8576 .ndo_fcoe_enable = i40e_fcoe_enable,
8577 .ndo_fcoe_disable = i40e_fcoe_disable,
8578#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008579 .ndo_set_features = i40e_set_features,
8580 .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
8581 .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04008582 .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008583 .ndo_get_vf_config = i40e_ndo_get_vf_config,
Mitch Williams588aefa2014-02-11 08:27:49 +00008584 .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
Serey Konge6d90042014-07-12 07:28:14 +00008585 .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008586#ifdef CONFIG_I40E_VXLAN
8587 .ndo_add_vxlan_port = i40e_add_vxlan_port,
8588 .ndo_del_vxlan_port = i40e_del_vxlan_port,
8589#endif
Neerav Parikh1f224ad2014-02-12 01:45:31 +00008590 .ndo_get_phys_port_id = i40e_get_phys_port_id,
Greg Rose4ba0dea2014-03-06 08:59:55 +00008591 .ndo_fdb_add = i40e_ndo_fdb_add,
Joe Stringerf44a75e2015-04-14 17:09:14 -07008592 .ndo_features_check = i40e_features_check,
Neerav Parikh51616012015-02-06 08:52:14 +00008593 .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
8594 .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008595};
8596
8597/**
8598 * i40e_config_netdev - Setup the netdev flags
8599 * @vsi: the VSI being configured
8600 *
8601 * Returns 0 on success, negative value on failure
8602 **/
8603static int i40e_config_netdev(struct i40e_vsi *vsi)
8604{
Greg Rose1a103702013-11-28 06:42:39 +00008605 u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008606 struct i40e_pf *pf = vsi->back;
8607 struct i40e_hw *hw = &pf->hw;
8608 struct i40e_netdev_priv *np;
8609 struct net_device *netdev;
8610 u8 mac_addr[ETH_ALEN];
8611 int etherdev_size;
8612
8613 etherdev_size = sizeof(struct i40e_netdev_priv);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008614 netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008615 if (!netdev)
8616 return -ENOMEM;
8617
8618 vsi->netdev = netdev;
8619 np = netdev_priv(netdev);
8620 np->vsi = vsi;
8621
Or Gerlitzd70e9412014-03-18 10:36:45 +02008622 netdev->hw_enc_features |= NETIF_F_IP_CSUM |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008623 NETIF_F_GSO_UDP_TUNNEL |
Or Gerlitzd70e9412014-03-18 10:36:45 +02008624 NETIF_F_TSO;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008625
8626 netdev->features = NETIF_F_SG |
8627 NETIF_F_IP_CSUM |
8628 NETIF_F_SCTP_CSUM |
8629 NETIF_F_HIGHDMA |
8630 NETIF_F_GSO_UDP_TUNNEL |
8631 NETIF_F_HW_VLAN_CTAG_TX |
8632 NETIF_F_HW_VLAN_CTAG_RX |
8633 NETIF_F_HW_VLAN_CTAG_FILTER |
8634 NETIF_F_IPV6_CSUM |
8635 NETIF_F_TSO |
Jesse Brandeburg059dab62014-04-01 09:07:20 +00008636 NETIF_F_TSO_ECN |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008637 NETIF_F_TSO6 |
8638 NETIF_F_RXCSUM |
8639 NETIF_F_RXHASH |
8640 0;
8641
Anjali Singhai Jain2e86a0b2014-04-01 07:11:53 +00008642 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
8643 netdev->features |= NETIF_F_NTUPLE;
8644
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008645 /* copy netdev features into list of user selectable features */
8646 netdev->hw_features |= netdev->features;
8647
8648 if (vsi->type == I40E_VSI_MAIN) {
8649 SET_NETDEV_DEV(netdev, &pf->pdev->dev);
Greg Rose9a173902014-05-22 06:32:02 +00008650 ether_addr_copy(mac_addr, hw->mac.perm_addr);
Shannon Nelson30650cc2014-07-29 04:01:50 +00008651 /* The following steps are necessary to prevent reception
8652 * of tagged packets - some older NVM configurations load a
8653 * default a MAC-VLAN filter that accepts any tagged packet
8654 * which must be replaced by a normal filter.
Greg Rose8c27d422014-05-22 06:31:56 +00008655 */
Kiran Patil21659032015-09-30 14:09:03 -04008656 if (!i40e_rm_default_mac_filter(vsi, mac_addr)) {
8657 spin_lock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson30650cc2014-07-29 04:01:50 +00008658 i40e_add_filter(vsi, mac_addr,
8659 I40E_VLAN_ANY, false, true);
Kiran Patil21659032015-09-30 14:09:03 -04008660 spin_unlock_bh(&vsi->mac_filter_list_lock);
8661 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008662 } else {
8663 /* relate the VSI_VMDQ name to the VSI_MAIN name */
8664 snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
8665 pf->vsi[pf->lan_vsi]->netdev->name);
8666 random_ether_addr(mac_addr);
Kiran Patil21659032015-09-30 14:09:03 -04008667
8668 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008669 i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false);
Kiran Patil21659032015-09-30 14:09:03 -04008670 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008671 }
Kiran Patil21659032015-09-30 14:09:03 -04008672
8673 spin_lock_bh(&vsi->mac_filter_list_lock);
Greg Rose1a103702013-11-28 06:42:39 +00008674 i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false);
Kiran Patil21659032015-09-30 14:09:03 -04008675 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008676
Greg Rose9a173902014-05-22 06:32:02 +00008677 ether_addr_copy(netdev->dev_addr, mac_addr);
8678 ether_addr_copy(netdev->perm_addr, mac_addr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008679 /* vlan gets same features (except vlan offload)
8680 * after any tweaks for specific VSI types
8681 */
8682 netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX |
8683 NETIF_F_HW_VLAN_CTAG_RX |
8684 NETIF_F_HW_VLAN_CTAG_FILTER);
8685 netdev->priv_flags |= IFF_UNICAST_FLT;
8686 netdev->priv_flags |= IFF_SUPP_NOFCS;
8687 /* Setup netdev TC information */
8688 i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
8689
8690 netdev->netdev_ops = &i40e_netdev_ops;
8691 netdev->watchdog_timeo = 5 * HZ;
8692 i40e_set_ethtool_ops(netdev);
Vasu Dev38e00432014-08-01 13:27:03 -07008693#ifdef I40E_FCOE
8694 i40e_fcoe_config_netdev(netdev, vsi);
8695#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008696
8697 return 0;
8698}
8699
8700/**
8701 * i40e_vsi_delete - Delete a VSI from the switch
8702 * @vsi: the VSI being removed
8703 *
8704 * Returns 0 on success, negative value on failure
8705 **/
8706static void i40e_vsi_delete(struct i40e_vsi *vsi)
8707{
8708 /* remove default VSI is not allowed */
8709 if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
8710 return;
8711
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008712 i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008713}
8714
8715/**
Neerav Parikh51616012015-02-06 08:52:14 +00008716 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
8717 * @vsi: the VSI being queried
8718 *
8719 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
8720 **/
8721int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
8722{
8723 struct i40e_veb *veb;
8724 struct i40e_pf *pf = vsi->back;
8725
8726 /* Uplink is not a bridge so default to VEB */
8727 if (vsi->veb_idx == I40E_NO_VEB)
8728 return 1;
8729
8730 veb = pf->veb[vsi->veb_idx];
8731 /* Uplink is a bridge in VEPA mode */
8732 if (veb && (veb->bridge_mode & BRIDGE_MODE_VEPA))
8733 return 0;
8734
8735 /* Uplink is a bridge in VEB mode */
8736 return 1;
8737}
8738
8739/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008740 * i40e_add_vsi - Add a VSI to the switch
8741 * @vsi: the VSI being configured
8742 *
8743 * This initializes a VSI context depending on the VSI type to be added and
8744 * passes it down to the add_vsi aq command.
8745 **/
8746static int i40e_add_vsi(struct i40e_vsi *vsi)
8747{
8748 int ret = -ENODEV;
Kiran Patil21659032015-09-30 14:09:03 -04008749 u8 laa_macaddr[ETH_ALEN];
8750 bool found_laa_mac_filter = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008751 struct i40e_pf *pf = vsi->back;
8752 struct i40e_hw *hw = &pf->hw;
8753 struct i40e_vsi_context ctxt;
Kiran Patil21659032015-09-30 14:09:03 -04008754 struct i40e_mac_filter *f, *ftmp;
8755
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008756 u8 enabled_tc = 0x1; /* TC0 enabled */
8757 int f_count = 0;
8758
8759 memset(&ctxt, 0, sizeof(ctxt));
8760 switch (vsi->type) {
8761 case I40E_VSI_MAIN:
8762 /* The PF's main VSI is already setup as part of the
8763 * device initialization, so we'll not bother with
8764 * the add_vsi call, but we will retrieve the current
8765 * VSI context.
8766 */
8767 ctxt.seid = pf->main_vsi_seid;
8768 ctxt.pf_num = pf->hw.pf_id;
8769 ctxt.vf_num = 0;
8770 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
8771 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
8772 if (ret) {
8773 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008774 "couldn't get PF vsi config, err %s aq_err %s\n",
8775 i40e_stat_str(&pf->hw, ret),
8776 i40e_aq_str(&pf->hw,
8777 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008778 return -ENOENT;
8779 }
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07008780 vsi->info = ctxt.info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008781 vsi->info.valid_sections = 0;
8782
8783 vsi->seid = ctxt.seid;
8784 vsi->id = ctxt.vsi_number;
8785
8786 enabled_tc = i40e_pf_get_tc_map(pf);
8787
8788 /* MFP mode setup queue map and update VSI */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00008789 if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
8790 !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008791 memset(&ctxt, 0, sizeof(ctxt));
8792 ctxt.seid = pf->main_vsi_seid;
8793 ctxt.pf_num = pf->hw.pf_id;
8794 ctxt.vf_num = 0;
8795 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
8796 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
8797 if (ret) {
8798 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008799 "update vsi failed, err %s aq_err %s\n",
8800 i40e_stat_str(&pf->hw, ret),
8801 i40e_aq_str(&pf->hw,
8802 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008803 ret = -ENOENT;
8804 goto err;
8805 }
8806 /* update the local VSI info queue map */
8807 i40e_vsi_update_queue_map(vsi, &ctxt);
8808 vsi->info.valid_sections = 0;
8809 } else {
8810 /* Default/Main VSI is only enabled for TC0
8811 * reconfigure it to enable all TCs that are
8812 * available on the port in SFP mode.
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00008813 * For MFP case the iSCSI PF would use this
8814 * flow to enable LAN+iSCSI TC.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008815 */
8816 ret = i40e_vsi_config_tc(vsi, enabled_tc);
8817 if (ret) {
8818 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008819 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
8820 enabled_tc,
8821 i40e_stat_str(&pf->hw, ret),
8822 i40e_aq_str(&pf->hw,
8823 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008824 ret = -ENOENT;
8825 }
8826 }
8827 break;
8828
8829 case I40E_VSI_FDIR:
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008830 ctxt.pf_num = hw->pf_id;
8831 ctxt.vf_num = 0;
8832 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00008833 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008834 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07008835 if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
8836 (i40e_is_vsi_uplink_mode_veb(vsi))) {
Neerav Parikh51616012015-02-06 08:52:14 +00008837 ctxt.info.valid_sections |=
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07008838 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
Neerav Parikh51616012015-02-06 08:52:14 +00008839 ctxt.info.switch_id =
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07008840 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
Neerav Parikh51616012015-02-06 08:52:14 +00008841 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008842 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008843 break;
8844
8845 case I40E_VSI_VMDQ2:
8846 ctxt.pf_num = hw->pf_id;
8847 ctxt.vf_num = 0;
8848 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00008849 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008850 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
8851
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008852 /* This VSI is connected to VEB so the switch_id
8853 * should be set to zero by default.
8854 */
Neerav Parikh51616012015-02-06 08:52:14 +00008855 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
8856 ctxt.info.valid_sections |=
8857 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
8858 ctxt.info.switch_id =
8859 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
8860 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008861
8862 /* Setup the VSI tx/rx queue map for TC0 only for now */
8863 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
8864 break;
8865
8866 case I40E_VSI_SRIOV:
8867 ctxt.pf_num = hw->pf_id;
8868 ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
8869 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00008870 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008871 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
8872
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008873 /* This VSI is connected to VEB so the switch_id
8874 * should be set to zero by default.
8875 */
Neerav Parikh51616012015-02-06 08:52:14 +00008876 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
8877 ctxt.info.valid_sections |=
8878 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
8879 ctxt.info.switch_id =
8880 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
8881 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008882
8883 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
8884 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
Mitch Williamsc674d122014-05-20 08:01:40 +00008885 if (pf->vf[vsi->vf_id].spoofchk) {
8886 ctxt.info.valid_sections |=
8887 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
8888 ctxt.info.sec_flags |=
8889 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
8890 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
8891 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008892 /* Setup the VSI tx/rx queue map for TC0 only for now */
8893 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
8894 break;
8895
Vasu Dev38e00432014-08-01 13:27:03 -07008896#ifdef I40E_FCOE
8897 case I40E_VSI_FCOE:
8898 ret = i40e_fcoe_vsi_init(vsi, &ctxt);
8899 if (ret) {
8900 dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n");
8901 return ret;
8902 }
8903 break;
8904
8905#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008906 default:
8907 return -ENODEV;
8908 }
8909
8910 if (vsi->type != I40E_VSI_MAIN) {
8911 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
8912 if (ret) {
8913 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008914 "add vsi failed, err %s aq_err %s\n",
8915 i40e_stat_str(&pf->hw, ret),
8916 i40e_aq_str(&pf->hw,
8917 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008918 ret = -ENOENT;
8919 goto err;
8920 }
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07008921 vsi->info = ctxt.info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008922 vsi->info.valid_sections = 0;
8923 vsi->seid = ctxt.seid;
8924 vsi->id = ctxt.vsi_number;
8925 }
8926
Kiran Patil21659032015-09-30 14:09:03 -04008927 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008928 /* If macvlan filters already exist, force them to get loaded */
8929 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
8930 f->changed = true;
8931 f_count++;
Shannon Nelson6252c7e2014-06-04 01:23:23 +00008932
Kiran Patil21659032015-09-30 14:09:03 -04008933 /* Expected to have only one MAC filter entry for LAA in list */
Shannon Nelson6252c7e2014-06-04 01:23:23 +00008934 if (f->is_laa && vsi->type == I40E_VSI_MAIN) {
Kiran Patil21659032015-09-30 14:09:03 -04008935 ether_addr_copy(laa_macaddr, f->macaddr);
8936 found_laa_mac_filter = true;
Shannon Nelson6252c7e2014-06-04 01:23:23 +00008937 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008938 }
Kiran Patil21659032015-09-30 14:09:03 -04008939 spin_unlock_bh(&vsi->mac_filter_list_lock);
8940
8941 if (found_laa_mac_filter) {
8942 struct i40e_aqc_remove_macvlan_element_data element;
8943
8944 memset(&element, 0, sizeof(element));
8945 ether_addr_copy(element.mac_addr, laa_macaddr);
8946 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
8947 ret = i40e_aq_remove_macvlan(hw, vsi->seid,
8948 &element, 1, NULL);
8949 if (ret) {
8950 /* some older FW has a different default */
8951 element.flags |=
8952 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
8953 i40e_aq_remove_macvlan(hw, vsi->seid,
8954 &element, 1, NULL);
8955 }
8956
8957 i40e_aq_mac_address_write(hw,
8958 I40E_AQC_WRITE_TYPE_LAA_WOL,
8959 laa_macaddr, NULL);
8960 }
8961
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008962 if (f_count) {
8963 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
8964 pf->flags |= I40E_FLAG_FILTER_SYNC;
8965 }
8966
8967 /* Update VSI BW information */
8968 ret = i40e_vsi_get_bw_info(vsi);
8969 if (ret) {
8970 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008971 "couldn't get vsi bw info, err %s aq_err %s\n",
8972 i40e_stat_str(&pf->hw, ret),
8973 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008974 /* VSI is already added so not tearing that up */
8975 ret = 0;
8976 }
8977
8978err:
8979 return ret;
8980}
8981
8982/**
8983 * i40e_vsi_release - Delete a VSI and free its resources
8984 * @vsi: the VSI being removed
8985 *
8986 * Returns 0 on success or < 0 on error
8987 **/
8988int i40e_vsi_release(struct i40e_vsi *vsi)
8989{
8990 struct i40e_mac_filter *f, *ftmp;
8991 struct i40e_veb *veb = NULL;
8992 struct i40e_pf *pf;
8993 u16 uplink_seid;
8994 int i, n;
8995
8996 pf = vsi->back;
8997
8998 /* release of a VEB-owner or last VSI is not allowed */
8999 if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
9000 dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
9001 vsi->seid, vsi->uplink_seid);
9002 return -ENODEV;
9003 }
9004 if (vsi == pf->vsi[pf->lan_vsi] &&
9005 !test_bit(__I40E_DOWN, &pf->state)) {
9006 dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
9007 return -ENODEV;
9008 }
9009
9010 uplink_seid = vsi->uplink_seid;
9011 if (vsi->type != I40E_VSI_SRIOV) {
9012 if (vsi->netdev_registered) {
9013 vsi->netdev_registered = false;
9014 if (vsi->netdev) {
9015 /* results in a call to i40e_close() */
9016 unregister_netdev(vsi->netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009017 }
9018 } else {
Shannon Nelson90ef8d42014-03-14 07:32:26 +00009019 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009020 }
9021 i40e_vsi_disable_irq(vsi);
9022 }
9023
Kiran Patil21659032015-09-30 14:09:03 -04009024 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009025 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
9026 i40e_del_filter(vsi, f->macaddr, f->vlan,
9027 f->is_vf, f->is_netdev);
Kiran Patil21659032015-09-30 14:09:03 -04009028 spin_unlock_bh(&vsi->mac_filter_list_lock);
9029
Anjali Singhai30e25612015-09-28 13:37:12 -07009030 i40e_sync_vsi_filters(vsi, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009031
9032 i40e_vsi_delete(vsi);
9033 i40e_vsi_free_q_vectors(vsi);
Shannon Nelsona4866592014-02-11 08:24:07 +00009034 if (vsi->netdev) {
9035 free_netdev(vsi->netdev);
9036 vsi->netdev = NULL;
9037 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009038 i40e_vsi_clear_rings(vsi);
9039 i40e_vsi_clear(vsi);
9040
9041 /* If this was the last thing on the VEB, except for the
9042 * controlling VSI, remove the VEB, which puts the controlling
9043 * VSI onto the next level down in the switch.
9044 *
9045 * Well, okay, there's one more exception here: don't remove
9046 * the orphan VEBs yet. We'll wait for an explicit remove request
9047 * from up the network stack.
9048 */
Mitch Williams505682c2014-05-20 08:01:37 +00009049 for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009050 if (pf->vsi[i] &&
9051 pf->vsi[i]->uplink_seid == uplink_seid &&
9052 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
9053 n++; /* count the VSIs */
9054 }
9055 }
9056 for (i = 0; i < I40E_MAX_VEB; i++) {
9057 if (!pf->veb[i])
9058 continue;
9059 if (pf->veb[i]->uplink_seid == uplink_seid)
9060 n++; /* count the VEBs */
9061 if (pf->veb[i]->seid == uplink_seid)
9062 veb = pf->veb[i];
9063 }
9064 if (n == 0 && veb && veb->uplink_seid != 0)
9065 i40e_veb_release(veb);
9066
9067 return 0;
9068}
9069
9070/**
9071 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
9072 * @vsi: ptr to the VSI
9073 *
9074 * This should only be called after i40e_vsi_mem_alloc() which allocates the
9075 * corresponding SW VSI structure and initializes num_queue_pairs for the
9076 * newly allocated VSI.
9077 *
9078 * Returns 0 on success or negative on failure
9079 **/
9080static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
9081{
9082 int ret = -ENOENT;
9083 struct i40e_pf *pf = vsi->back;
9084
Alexander Duyck493fb302013-09-28 07:01:44 +00009085 if (vsi->q_vectors[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009086 dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
9087 vsi->seid);
9088 return -EEXIST;
9089 }
9090
9091 if (vsi->base_vector) {
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00009092 dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009093 vsi->seid, vsi->base_vector);
9094 return -EEXIST;
9095 }
9096
Greg Rose90e04072014-03-06 08:59:57 +00009097 ret = i40e_vsi_alloc_q_vectors(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009098 if (ret) {
9099 dev_info(&pf->pdev->dev,
9100 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
9101 vsi->num_q_vectors, vsi->seid, ret);
9102 vsi->num_q_vectors = 0;
9103 goto vector_setup_out;
9104 }
9105
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04009106 /* In Legacy mode, we do not have to get any other vector since we
9107 * piggyback on the misc/ICR0 for queue interrupts.
9108 */
9109 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
9110 return ret;
Shannon Nelson958a3e32013-09-28 07:13:28 +00009111 if (vsi->num_q_vectors)
9112 vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
9113 vsi->num_q_vectors, vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009114 if (vsi->base_vector < 0) {
9115 dev_info(&pf->pdev->dev,
Shannon Nelson049a2be2014-10-17 03:14:50 +00009116 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
9117 vsi->num_q_vectors, vsi->seid, vsi->base_vector);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009118 i40e_vsi_free_q_vectors(vsi);
9119 ret = -ENOENT;
9120 goto vector_setup_out;
9121 }
9122
9123vector_setup_out:
9124 return ret;
9125}
9126
9127/**
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009128 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
9129 * @vsi: pointer to the vsi.
9130 *
9131 * This re-allocates a vsi's queue resources.
9132 *
9133 * Returns pointer to the successfully allocated and configured VSI sw struct
9134 * on success, otherwise returns NULL on failure.
9135 **/
9136static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
9137{
9138 struct i40e_pf *pf = vsi->back;
9139 u8 enabled_tc;
9140 int ret;
9141
9142 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
9143 i40e_vsi_clear_rings(vsi);
9144
9145 i40e_vsi_free_arrays(vsi, false);
9146 i40e_set_num_rings_in_vsi(vsi);
9147 ret = i40e_vsi_alloc_arrays(vsi, false);
9148 if (ret)
9149 goto err_vsi;
9150
9151 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
9152 if (ret < 0) {
Shannon Nelson049a2be2014-10-17 03:14:50 +00009153 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009154 "failed to get tracking for %d queues for VSI %d err %d\n",
Shannon Nelson049a2be2014-10-17 03:14:50 +00009155 vsi->alloc_queue_pairs, vsi->seid, ret);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009156 goto err_vsi;
9157 }
9158 vsi->base_queue = ret;
9159
9160 /* Update the FW view of the VSI. Force a reset of TC and queue
9161 * layout configurations.
9162 */
9163 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
9164 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
9165 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
9166 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
9167
9168 /* assign it some queues */
9169 ret = i40e_alloc_rings(vsi);
9170 if (ret)
9171 goto err_rings;
9172
9173 /* map all of the rings to the q_vectors */
9174 i40e_vsi_map_rings_to_vectors(vsi);
9175 return vsi;
9176
9177err_rings:
9178 i40e_vsi_free_q_vectors(vsi);
9179 if (vsi->netdev_registered) {
9180 vsi->netdev_registered = false;
9181 unregister_netdev(vsi->netdev);
9182 free_netdev(vsi->netdev);
9183 vsi->netdev = NULL;
9184 }
9185 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
9186err_vsi:
9187 i40e_vsi_clear(vsi);
9188 return NULL;
9189}
9190
9191/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009192 * i40e_vsi_setup - Set up a VSI by a given type
9193 * @pf: board private structure
9194 * @type: VSI type
9195 * @uplink_seid: the switch element to link to
9196 * @param1: usage depends upon VSI type. For VF types, indicates VF id
9197 *
9198 * This allocates the sw VSI structure and its queue resources, then add a VSI
9199 * to the identified VEB.
9200 *
9201 * Returns pointer to the successfully allocated and configure VSI sw struct on
9202 * success, otherwise returns NULL on failure.
9203 **/
9204struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
9205 u16 uplink_seid, u32 param1)
9206{
9207 struct i40e_vsi *vsi = NULL;
9208 struct i40e_veb *veb = NULL;
9209 int ret, i;
9210 int v_idx;
9211
9212 /* The requested uplink_seid must be either
9213 * - the PF's port seid
9214 * no VEB is needed because this is the PF
9215 * or this is a Flow Director special case VSI
9216 * - seid of an existing VEB
9217 * - seid of a VSI that owns an existing VEB
9218 * - seid of a VSI that doesn't own a VEB
9219 * a new VEB is created and the VSI becomes the owner
9220 * - seid of the PF VSI, which is what creates the first VEB
9221 * this is a special case of the previous
9222 *
9223 * Find which uplink_seid we were given and create a new VEB if needed
9224 */
9225 for (i = 0; i < I40E_MAX_VEB; i++) {
9226 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
9227 veb = pf->veb[i];
9228 break;
9229 }
9230 }
9231
9232 if (!veb && uplink_seid != pf->mac_seid) {
9233
Mitch Williams505682c2014-05-20 08:01:37 +00009234 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009235 if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
9236 vsi = pf->vsi[i];
9237 break;
9238 }
9239 }
9240 if (!vsi) {
9241 dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
9242 uplink_seid);
9243 return NULL;
9244 }
9245
9246 if (vsi->uplink_seid == pf->mac_seid)
9247 veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
9248 vsi->tc_config.enabled_tc);
9249 else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
9250 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
9251 vsi->tc_config.enabled_tc);
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009252 if (veb) {
9253 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
9254 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04009255 "New VSI creation error, uplink seid of LAN VSI expected.\n");
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009256 return NULL;
9257 }
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -04009258 /* We come up by default in VEPA mode if SRIOV is not
9259 * already enabled, in which case we can't force VEPA
9260 * mode.
9261 */
9262 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
9263 veb->bridge_mode = BRIDGE_MODE_VEPA;
9264 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
9265 }
Neerav Parikh51616012015-02-06 08:52:14 +00009266 i40e_config_bridge_mode(veb);
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009267 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009268 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
9269 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
9270 veb = pf->veb[i];
9271 }
9272 if (!veb) {
9273 dev_info(&pf->pdev->dev, "couldn't add VEB\n");
9274 return NULL;
9275 }
9276
9277 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
9278 uplink_seid = veb->seid;
9279 }
9280
9281 /* get vsi sw struct */
9282 v_idx = i40e_vsi_mem_alloc(pf, type);
9283 if (v_idx < 0)
9284 goto err_alloc;
9285 vsi = pf->vsi[v_idx];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009286 if (!vsi)
9287 goto err_alloc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009288 vsi->type = type;
9289 vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
9290
9291 if (type == I40E_VSI_MAIN)
9292 pf->lan_vsi = v_idx;
9293 else if (type == I40E_VSI_SRIOV)
9294 vsi->vf_id = param1;
9295 /* assign it some queues */
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009296 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
9297 vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009298 if (ret < 0) {
Shannon Nelson049a2be2014-10-17 03:14:50 +00009299 dev_info(&pf->pdev->dev,
9300 "failed to get tracking for %d queues for VSI %d err=%d\n",
9301 vsi->alloc_queue_pairs, vsi->seid, ret);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009302 goto err_vsi;
9303 }
9304 vsi->base_queue = ret;
9305
9306 /* get a VSI from the hardware */
9307 vsi->uplink_seid = uplink_seid;
9308 ret = i40e_add_vsi(vsi);
9309 if (ret)
9310 goto err_vsi;
9311
9312 switch (vsi->type) {
9313 /* setup the netdev if needed */
9314 case I40E_VSI_MAIN:
9315 case I40E_VSI_VMDQ2:
Vasu Dev38e00432014-08-01 13:27:03 -07009316 case I40E_VSI_FCOE:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009317 ret = i40e_config_netdev(vsi);
9318 if (ret)
9319 goto err_netdev;
9320 ret = register_netdev(vsi->netdev);
9321 if (ret)
9322 goto err_netdev;
9323 vsi->netdev_registered = true;
9324 netif_carrier_off(vsi->netdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08009325#ifdef CONFIG_I40E_DCB
9326 /* Setup DCB netlink interface */
9327 i40e_dcbnl_setup(vsi);
9328#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009329 /* fall through */
9330
9331 case I40E_VSI_FDIR:
9332 /* set up vectors and rings if needed */
9333 ret = i40e_vsi_setup_vectors(vsi);
9334 if (ret)
9335 goto err_msix;
9336
9337 ret = i40e_alloc_rings(vsi);
9338 if (ret)
9339 goto err_rings;
9340
9341 /* map all of the rings to the q_vectors */
9342 i40e_vsi_map_rings_to_vectors(vsi);
9343
9344 i40e_vsi_reset_stats(vsi);
9345 break;
9346
9347 default:
9348 /* no netdev or rings for the other VSI types */
9349 break;
9350 }
9351
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04009352 if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
9353 (vsi->type == I40E_VSI_VMDQ2)) {
9354 ret = i40e_vsi_config_rss(vsi);
9355 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009356 return vsi;
9357
9358err_rings:
9359 i40e_vsi_free_q_vectors(vsi);
9360err_msix:
9361 if (vsi->netdev_registered) {
9362 vsi->netdev_registered = false;
9363 unregister_netdev(vsi->netdev);
9364 free_netdev(vsi->netdev);
9365 vsi->netdev = NULL;
9366 }
9367err_netdev:
9368 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
9369err_vsi:
9370 i40e_vsi_clear(vsi);
9371err_alloc:
9372 return NULL;
9373}
9374
9375/**
9376 * i40e_veb_get_bw_info - Query VEB BW information
9377 * @veb: the veb to query
9378 *
9379 * Query the Tx scheduler BW configuration data for given VEB
9380 **/
9381static int i40e_veb_get_bw_info(struct i40e_veb *veb)
9382{
9383 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
9384 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
9385 struct i40e_pf *pf = veb->pf;
9386 struct i40e_hw *hw = &pf->hw;
9387 u32 tc_bw_max;
9388 int ret = 0;
9389 int i;
9390
9391 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
9392 &bw_data, NULL);
9393 if (ret) {
9394 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009395 "query veb bw config failed, err %s aq_err %s\n",
9396 i40e_stat_str(&pf->hw, ret),
9397 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009398 goto out;
9399 }
9400
9401 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
9402 &ets_data, NULL);
9403 if (ret) {
9404 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009405 "query veb bw ets config failed, err %s aq_err %s\n",
9406 i40e_stat_str(&pf->hw, ret),
9407 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009408 goto out;
9409 }
9410
9411 veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
9412 veb->bw_max_quanta = ets_data.tc_bw_max;
9413 veb->is_abs_credits = bw_data.absolute_credits_enable;
Neerav Parikh23cd1f02014-11-12 00:18:41 +00009414 veb->enabled_tc = ets_data.tc_valid_bits;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009415 tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
9416 (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
9417 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
9418 veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
9419 veb->bw_tc_limit_credits[i] =
9420 le16_to_cpu(bw_data.tc_bw_limits[i]);
9421 veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
9422 }
9423
9424out:
9425 return ret;
9426}
9427
9428/**
9429 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
9430 * @pf: board private structure
9431 *
9432 * On error: returns error code (negative)
9433 * On success: returns vsi index in PF (positive)
9434 **/
9435static int i40e_veb_mem_alloc(struct i40e_pf *pf)
9436{
9437 int ret = -ENOENT;
9438 struct i40e_veb *veb;
9439 int i;
9440
9441 /* Need to protect the allocation of switch elements at the PF level */
9442 mutex_lock(&pf->switch_mutex);
9443
9444 /* VEB list may be fragmented if VEB creation/destruction has
9445 * been happening. We can afford to do a quick scan to look
9446 * for any free slots in the list.
9447 *
9448 * find next empty veb slot, looping back around if necessary
9449 */
9450 i = 0;
9451 while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
9452 i++;
9453 if (i >= I40E_MAX_VEB) {
9454 ret = -ENOMEM;
9455 goto err_alloc_veb; /* out of VEB slots! */
9456 }
9457
9458 veb = kzalloc(sizeof(*veb), GFP_KERNEL);
9459 if (!veb) {
9460 ret = -ENOMEM;
9461 goto err_alloc_veb;
9462 }
9463 veb->pf = pf;
9464 veb->idx = i;
9465 veb->enabled_tc = 1;
9466
9467 pf->veb[i] = veb;
9468 ret = i;
9469err_alloc_veb:
9470 mutex_unlock(&pf->switch_mutex);
9471 return ret;
9472}
9473
9474/**
9475 * i40e_switch_branch_release - Delete a branch of the switch tree
9476 * @branch: where to start deleting
9477 *
9478 * This uses recursion to find the tips of the branch to be
9479 * removed, deleting until we get back to and can delete this VEB.
9480 **/
9481static void i40e_switch_branch_release(struct i40e_veb *branch)
9482{
9483 struct i40e_pf *pf = branch->pf;
9484 u16 branch_seid = branch->seid;
9485 u16 veb_idx = branch->idx;
9486 int i;
9487
9488 /* release any VEBs on this VEB - RECURSION */
9489 for (i = 0; i < I40E_MAX_VEB; i++) {
9490 if (!pf->veb[i])
9491 continue;
9492 if (pf->veb[i]->uplink_seid == branch->seid)
9493 i40e_switch_branch_release(pf->veb[i]);
9494 }
9495
9496 /* Release the VSIs on this VEB, but not the owner VSI.
9497 *
9498 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
9499 * the VEB itself, so don't use (*branch) after this loop.
9500 */
Mitch Williams505682c2014-05-20 08:01:37 +00009501 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009502 if (!pf->vsi[i])
9503 continue;
9504 if (pf->vsi[i]->uplink_seid == branch_seid &&
9505 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
9506 i40e_vsi_release(pf->vsi[i]);
9507 }
9508 }
9509
9510 /* There's one corner case where the VEB might not have been
9511 * removed, so double check it here and remove it if needed.
9512 * This case happens if the veb was created from the debugfs
9513 * commands and no VSIs were added to it.
9514 */
9515 if (pf->veb[veb_idx])
9516 i40e_veb_release(pf->veb[veb_idx]);
9517}
9518
9519/**
9520 * i40e_veb_clear - remove veb struct
9521 * @veb: the veb to remove
9522 **/
9523static void i40e_veb_clear(struct i40e_veb *veb)
9524{
9525 if (!veb)
9526 return;
9527
9528 if (veb->pf) {
9529 struct i40e_pf *pf = veb->pf;
9530
9531 mutex_lock(&pf->switch_mutex);
9532 if (pf->veb[veb->idx] == veb)
9533 pf->veb[veb->idx] = NULL;
9534 mutex_unlock(&pf->switch_mutex);
9535 }
9536
9537 kfree(veb);
9538}
9539
9540/**
9541 * i40e_veb_release - Delete a VEB and free its resources
9542 * @veb: the VEB being removed
9543 **/
9544void i40e_veb_release(struct i40e_veb *veb)
9545{
9546 struct i40e_vsi *vsi = NULL;
9547 struct i40e_pf *pf;
9548 int i, n = 0;
9549
9550 pf = veb->pf;
9551
9552 /* find the remaining VSI and check for extras */
Mitch Williams505682c2014-05-20 08:01:37 +00009553 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009554 if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
9555 n++;
9556 vsi = pf->vsi[i];
9557 }
9558 }
9559 if (n != 1) {
9560 dev_info(&pf->pdev->dev,
9561 "can't remove VEB %d with %d VSIs left\n",
9562 veb->seid, n);
9563 return;
9564 }
9565
9566 /* move the remaining VSI to uplink veb */
9567 vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
9568 if (veb->uplink_seid) {
9569 vsi->uplink_seid = veb->uplink_seid;
9570 if (veb->uplink_seid == pf->mac_seid)
9571 vsi->veb_idx = I40E_NO_VEB;
9572 else
9573 vsi->veb_idx = veb->veb_idx;
9574 } else {
9575 /* floating VEB */
9576 vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
9577 vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
9578 }
9579
9580 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
9581 i40e_veb_clear(veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009582}
9583
9584/**
9585 * i40e_add_veb - create the VEB in the switch
9586 * @veb: the VEB to be instantiated
9587 * @vsi: the controlling VSI
9588 **/
9589static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
9590{
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009591 struct i40e_pf *pf = veb->pf;
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04009592 bool is_default = veb->pf->cur_promisc;
Kevin Scotte1c51b952013-11-20 10:02:51 +00009593 bool is_cloud = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009594 int ret;
9595
9596 /* get a VEB from the hardware */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009597 ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
Kevin Scotte1c51b952013-11-20 10:02:51 +00009598 veb->enabled_tc, is_default,
9599 is_cloud, &veb->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009600 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009601 dev_info(&pf->pdev->dev,
9602 "couldn't add VEB, err %s aq_err %s\n",
9603 i40e_stat_str(&pf->hw, ret),
9604 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009605 return -EPERM;
9606 }
9607
9608 /* get statistics counter */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009609 ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009610 &veb->stats_idx, NULL, NULL, NULL);
9611 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009612 dev_info(&pf->pdev->dev,
9613 "couldn't get VEB statistics idx, err %s aq_err %s\n",
9614 i40e_stat_str(&pf->hw, ret),
9615 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009616 return -EPERM;
9617 }
9618 ret = i40e_veb_get_bw_info(veb);
9619 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009620 dev_info(&pf->pdev->dev,
9621 "couldn't get VEB bw info, err %s aq_err %s\n",
9622 i40e_stat_str(&pf->hw, ret),
9623 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
9624 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009625 return -ENOENT;
9626 }
9627
9628 vsi->uplink_seid = veb->seid;
9629 vsi->veb_idx = veb->idx;
9630 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
9631
9632 return 0;
9633}
9634
9635/**
9636 * i40e_veb_setup - Set up a VEB
9637 * @pf: board private structure
9638 * @flags: VEB setup flags
9639 * @uplink_seid: the switch element to link to
9640 * @vsi_seid: the initial VSI seid
9641 * @enabled_tc: Enabled TC bit-map
9642 *
9643 * This allocates the sw VEB structure and links it into the switch
9644 * It is possible and legal for this to be a duplicate of an already
9645 * existing VEB. It is also possible for both uplink and vsi seids
9646 * to be zero, in order to create a floating VEB.
9647 *
9648 * Returns pointer to the successfully allocated VEB sw struct on
9649 * success, otherwise returns NULL on failure.
9650 **/
9651struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
9652 u16 uplink_seid, u16 vsi_seid,
9653 u8 enabled_tc)
9654{
9655 struct i40e_veb *veb, *uplink_veb = NULL;
9656 int vsi_idx, veb_idx;
9657 int ret;
9658
9659 /* if one seid is 0, the other must be 0 to create a floating relay */
9660 if ((uplink_seid == 0 || vsi_seid == 0) &&
9661 (uplink_seid + vsi_seid != 0)) {
9662 dev_info(&pf->pdev->dev,
9663 "one, not both seid's are 0: uplink=%d vsi=%d\n",
9664 uplink_seid, vsi_seid);
9665 return NULL;
9666 }
9667
9668 /* make sure there is such a vsi and uplink */
Mitch Williams505682c2014-05-20 08:01:37 +00009669 for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009670 if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
9671 break;
Mitch Williams505682c2014-05-20 08:01:37 +00009672 if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009673 dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
9674 vsi_seid);
9675 return NULL;
9676 }
9677
9678 if (uplink_seid && uplink_seid != pf->mac_seid) {
9679 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
9680 if (pf->veb[veb_idx] &&
9681 pf->veb[veb_idx]->seid == uplink_seid) {
9682 uplink_veb = pf->veb[veb_idx];
9683 break;
9684 }
9685 }
9686 if (!uplink_veb) {
9687 dev_info(&pf->pdev->dev,
9688 "uplink seid %d not found\n", uplink_seid);
9689 return NULL;
9690 }
9691 }
9692
9693 /* get veb sw struct */
9694 veb_idx = i40e_veb_mem_alloc(pf);
9695 if (veb_idx < 0)
9696 goto err_alloc;
9697 veb = pf->veb[veb_idx];
9698 veb->flags = flags;
9699 veb->uplink_seid = uplink_seid;
9700 veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
9701 veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
9702
9703 /* create the VEB in the switch */
9704 ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
9705 if (ret)
9706 goto err_veb;
Shannon Nelson1bb8b932014-04-23 04:49:54 +00009707 if (vsi_idx == pf->lan_vsi)
9708 pf->lan_veb = veb->idx;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009709
9710 return veb;
9711
9712err_veb:
9713 i40e_veb_clear(veb);
9714err_alloc:
9715 return NULL;
9716}
9717
9718/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00009719 * i40e_setup_pf_switch_element - set PF vars based on switch type
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009720 * @pf: board private structure
9721 * @ele: element we are building info from
9722 * @num_reported: total number of elements
9723 * @printconfig: should we print the contents
9724 *
9725 * helper function to assist in extracting a few useful SEID values.
9726 **/
9727static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
9728 struct i40e_aqc_switch_config_element_resp *ele,
9729 u16 num_reported, bool printconfig)
9730{
9731 u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
9732 u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
9733 u8 element_type = ele->element_type;
9734 u16 seid = le16_to_cpu(ele->seid);
9735
9736 if (printconfig)
9737 dev_info(&pf->pdev->dev,
9738 "type=%d seid=%d uplink=%d downlink=%d\n",
9739 element_type, seid, uplink_seid, downlink_seid);
9740
9741 switch (element_type) {
9742 case I40E_SWITCH_ELEMENT_TYPE_MAC:
9743 pf->mac_seid = seid;
9744 break;
9745 case I40E_SWITCH_ELEMENT_TYPE_VEB:
9746 /* Main VEB? */
9747 if (uplink_seid != pf->mac_seid)
9748 break;
9749 if (pf->lan_veb == I40E_NO_VEB) {
9750 int v;
9751
9752 /* find existing or else empty VEB */
9753 for (v = 0; v < I40E_MAX_VEB; v++) {
9754 if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
9755 pf->lan_veb = v;
9756 break;
9757 }
9758 }
9759 if (pf->lan_veb == I40E_NO_VEB) {
9760 v = i40e_veb_mem_alloc(pf);
9761 if (v < 0)
9762 break;
9763 pf->lan_veb = v;
9764 }
9765 }
9766
9767 pf->veb[pf->lan_veb]->seid = seid;
9768 pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
9769 pf->veb[pf->lan_veb]->pf = pf;
9770 pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
9771 break;
9772 case I40E_SWITCH_ELEMENT_TYPE_VSI:
9773 if (num_reported != 1)
9774 break;
9775 /* This is immediately after a reset so we can assume this is
9776 * the PF's VSI
9777 */
9778 pf->mac_seid = uplink_seid;
9779 pf->pf_seid = downlink_seid;
9780 pf->main_vsi_seid = seid;
9781 if (printconfig)
9782 dev_info(&pf->pdev->dev,
9783 "pf_seid=%d main_vsi_seid=%d\n",
9784 pf->pf_seid, pf->main_vsi_seid);
9785 break;
9786 case I40E_SWITCH_ELEMENT_TYPE_PF:
9787 case I40E_SWITCH_ELEMENT_TYPE_VF:
9788 case I40E_SWITCH_ELEMENT_TYPE_EMP:
9789 case I40E_SWITCH_ELEMENT_TYPE_BMC:
9790 case I40E_SWITCH_ELEMENT_TYPE_PE:
9791 case I40E_SWITCH_ELEMENT_TYPE_PA:
9792 /* ignore these for now */
9793 break;
9794 default:
9795 dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
9796 element_type, seid);
9797 break;
9798 }
9799}
9800
9801/**
9802 * i40e_fetch_switch_configuration - Get switch config from firmware
9803 * @pf: board private structure
9804 * @printconfig: should we print the contents
9805 *
9806 * Get the current switch configuration from the device and
9807 * extract a few useful SEID values.
9808 **/
9809int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
9810{
9811 struct i40e_aqc_get_switch_config_resp *sw_config;
9812 u16 next_seid = 0;
9813 int ret = 0;
9814 u8 *aq_buf;
9815 int i;
9816
9817 aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
9818 if (!aq_buf)
9819 return -ENOMEM;
9820
9821 sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
9822 do {
9823 u16 num_reported, num_total;
9824
9825 ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
9826 I40E_AQ_LARGE_BUF,
9827 &next_seid, NULL);
9828 if (ret) {
9829 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009830 "get switch config failed err %s aq_err %s\n",
9831 i40e_stat_str(&pf->hw, ret),
9832 i40e_aq_str(&pf->hw,
9833 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009834 kfree(aq_buf);
9835 return -ENOENT;
9836 }
9837
9838 num_reported = le16_to_cpu(sw_config->header.num_reported);
9839 num_total = le16_to_cpu(sw_config->header.num_total);
9840
9841 if (printconfig)
9842 dev_info(&pf->pdev->dev,
9843 "header: %d reported %d total\n",
9844 num_reported, num_total);
9845
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009846 for (i = 0; i < num_reported; i++) {
9847 struct i40e_aqc_switch_config_element_resp *ele =
9848 &sw_config->element[i];
9849
9850 i40e_setup_pf_switch_element(pf, ele, num_reported,
9851 printconfig);
9852 }
9853 } while (next_seid != 0);
9854
9855 kfree(aq_buf);
9856 return ret;
9857}
9858
9859/**
9860 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
9861 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009862 * @reinit: if the Main VSI needs to re-initialized.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009863 *
9864 * Returns 0 on success, negative value on failure
9865 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009866static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009867{
9868 int ret;
9869
9870 /* find out what's out there already */
9871 ret = i40e_fetch_switch_configuration(pf, false);
9872 if (ret) {
9873 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009874 "couldn't fetch switch config, err %s aq_err %s\n",
9875 i40e_stat_str(&pf->hw, ret),
9876 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009877 return ret;
9878 }
9879 i40e_pf_reset_stats(pf);
9880
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009881 /* first time setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009882 if (pf->lan_vsi == I40E_NO_VSI || reinit) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009883 struct i40e_vsi *vsi = NULL;
9884 u16 uplink_seid;
9885
9886 /* Set up the PF VSI associated with the PF's main VSI
9887 * that is already in the HW switch
9888 */
9889 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
9890 uplink_seid = pf->veb[pf->lan_veb]->seid;
9891 else
9892 uplink_seid = pf->mac_seid;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009893 if (pf->lan_vsi == I40E_NO_VSI)
9894 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
9895 else if (reinit)
9896 vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009897 if (!vsi) {
9898 dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
9899 i40e_fdir_teardown(pf);
9900 return -EAGAIN;
9901 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009902 } else {
9903 /* force a reset of TC and queue layout configurations */
9904 u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04009905
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009906 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
9907 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
9908 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
9909 }
9910 i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
9911
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009912 i40e_fdir_sb_setup(pf);
9913
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009914 /* Setup static PF queue filter control settings */
9915 ret = i40e_setup_pf_filter_control(pf);
9916 if (ret) {
9917 dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
9918 ret);
9919 /* Failure here should not stop continuing other steps */
9920 }
9921
9922 /* enable RSS in the HW, even for only one queue, as the stack can use
9923 * the hash
9924 */
9925 if ((pf->flags & I40E_FLAG_RSS_ENABLED))
9926 i40e_config_rss(pf);
9927
9928 /* fill in link information and enable LSE reporting */
Catherine Sullivan0a862b42015-08-31 19:54:53 -04009929 i40e_update_link_info(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009930 i40e_link_event(pf);
9931
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00009932 /* Initialize user-specific link properties */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009933 pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
9934 I40E_AQ_AN_COMPLETED) ? true : false);
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00009935
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00009936 i40e_ptp_init(pf);
9937
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009938 return ret;
9939}
9940
9941/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009942 * i40e_determine_queue_usage - Work out queue distribution
9943 * @pf: board private structure
9944 **/
9945static void i40e_determine_queue_usage(struct i40e_pf *pf)
9946{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009947 int queues_left;
9948
9949 pf->num_lan_qps = 0;
Vasu Dev38e00432014-08-01 13:27:03 -07009950#ifdef I40E_FCOE
9951 pf->num_fcoe_qps = 0;
9952#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009953
9954 /* Find the max queues to be put into basic use. We'll always be
9955 * using TC0, whether or not DCB is running, and TC0 will get the
9956 * big RSS set.
9957 */
9958 queues_left = pf->hw.func_caps.num_tx_qp;
9959
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009960 if ((queues_left == 1) ||
Frank Zhang9aa7e932014-05-20 08:01:42 +00009961 !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009962 /* one qp for PF, no queues for anything else */
9963 queues_left = 0;
9964 pf->rss_size = pf->num_lan_qps = 1;
9965
9966 /* make sure all the fancies are disabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08009967 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -07009968#ifdef I40E_FCOE
9969 I40E_FLAG_FCOE_ENABLED |
9970#endif
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08009971 I40E_FLAG_FD_SB_ENABLED |
9972 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00009973 I40E_FLAG_DCB_CAPABLE |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08009974 I40E_FLAG_SRIOV_ENABLED |
9975 I40E_FLAG_VMDQ_ENABLED);
Frank Zhang9aa7e932014-05-20 08:01:42 +00009976 } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
9977 I40E_FLAG_FD_SB_ENABLED |
Anjali Singhai Jainbbe7d0e2014-05-20 08:01:44 +00009978 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00009979 I40E_FLAG_DCB_CAPABLE))) {
Frank Zhang9aa7e932014-05-20 08:01:42 +00009980 /* one qp for PF */
9981 pf->rss_size = pf->num_lan_qps = 1;
9982 queues_left -= pf->num_lan_qps;
9983
9984 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -07009985#ifdef I40E_FCOE
9986 I40E_FLAG_FCOE_ENABLED |
9987#endif
Frank Zhang9aa7e932014-05-20 08:01:42 +00009988 I40E_FLAG_FD_SB_ENABLED |
9989 I40E_FLAG_FD_ATR_ENABLED |
9990 I40E_FLAG_DCB_ENABLED |
9991 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009992 } else {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009993 /* Not enough queues for all TCs */
Neerav Parikh4d9b6042014-05-22 06:31:51 +00009994 if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009995 (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
Neerav Parikh4d9b6042014-05-22 06:31:51 +00009996 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009997 dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
9998 }
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00009999 pf->num_lan_qps = max_t(int, pf->rss_size_max,
10000 num_online_cpus());
10001 pf->num_lan_qps = min_t(int, pf->num_lan_qps,
10002 pf->hw.func_caps.num_tx_qp);
10003
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010004 queues_left -= pf->num_lan_qps;
10005 }
10006
Vasu Dev38e00432014-08-01 13:27:03 -070010007#ifdef I40E_FCOE
10008 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
10009 if (I40E_DEFAULT_FCOE <= queues_left) {
10010 pf->num_fcoe_qps = I40E_DEFAULT_FCOE;
10011 } else if (I40E_MINIMUM_FCOE <= queues_left) {
10012 pf->num_fcoe_qps = I40E_MINIMUM_FCOE;
10013 } else {
10014 pf->num_fcoe_qps = 0;
10015 pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
10016 dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n");
10017 }
10018
10019 queues_left -= pf->num_fcoe_qps;
10020 }
10021
10022#endif
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010023 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
10024 if (queues_left > 1) {
10025 queues_left -= 1; /* save 1 queue for FD */
10026 } else {
10027 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
10028 dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
10029 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010030 }
10031
10032 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
10033 pf->num_vf_qps && pf->num_req_vfs && queues_left) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010034 pf->num_req_vfs = min_t(int, pf->num_req_vfs,
10035 (queues_left / pf->num_vf_qps));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010036 queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
10037 }
10038
10039 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
10040 pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
10041 pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
10042 (queues_left / pf->num_vmdq_qps));
10043 queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
10044 }
10045
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +000010046 pf->queues_left = queues_left;
Neerav Parikh8279e492015-09-03 17:18:50 -040010047 dev_dbg(&pf->pdev->dev,
10048 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
10049 pf->hw.func_caps.num_tx_qp,
10050 !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
10051 pf->num_lan_qps, pf->rss_size, pf->num_req_vfs, pf->num_vf_qps,
10052 pf->num_vmdq_vsis, pf->num_vmdq_qps, queues_left);
Vasu Dev38e00432014-08-01 13:27:03 -070010053#ifdef I40E_FCOE
Neerav Parikh8279e492015-09-03 17:18:50 -040010054 dev_dbg(&pf->pdev->dev, "fcoe queues = %d\n", pf->num_fcoe_qps);
Vasu Dev38e00432014-08-01 13:27:03 -070010055#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010056}
10057
10058/**
10059 * i40e_setup_pf_filter_control - Setup PF static filter control
10060 * @pf: PF to be setup
10061 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000010062 * i40e_setup_pf_filter_control sets up a PF's initial filter control
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010063 * settings. If PE/FCoE are enabled then it will also set the per PF
10064 * based filter sizes required for them. It also enables Flow director,
10065 * ethertype and macvlan type filter settings for the pf.
10066 *
10067 * Returns 0 on success, negative on failure
10068 **/
10069static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
10070{
10071 struct i40e_filter_control_settings *settings = &pf->filter_settings;
10072
10073 settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
10074
10075 /* Flow Director is enabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010076 if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010077 settings->enable_fdir = true;
10078
10079 /* Ethtype and MACVLAN filters enabled for PF */
10080 settings->enable_ethtype = true;
10081 settings->enable_macvlan = true;
10082
10083 if (i40e_set_filter_control(&pf->hw, settings))
10084 return -ENOENT;
10085
10086 return 0;
10087}
10088
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010089#define INFO_STRING_LEN 255
10090static void i40e_print_features(struct i40e_pf *pf)
10091{
10092 struct i40e_hw *hw = &pf->hw;
10093 char *buf, *string;
10094
10095 string = kzalloc(INFO_STRING_LEN, GFP_KERNEL);
10096 if (!string) {
10097 dev_err(&pf->pdev->dev, "Features string allocation failed\n");
10098 return;
10099 }
10100
10101 buf = string;
10102
10103 buf += sprintf(string, "Features: PF-id[%d] ", hw->pf_id);
10104#ifdef CONFIG_PCI_IOV
10105 buf += sprintf(buf, "VFs: %d ", pf->num_req_vfs);
10106#endif
Mitch Williamsaba237d2015-02-06 08:52:17 +000010107 buf += sprintf(buf, "VSIs: %d QP: %d RX: %s ",
10108 pf->hw.func_caps.num_vsis,
10109 pf->vsi[pf->lan_vsi]->num_queue_pairs,
10110 pf->flags & I40E_FLAG_RX_PS_ENABLED ? "PS" : "1BUF");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010111
10112 if (pf->flags & I40E_FLAG_RSS_ENABLED)
10113 buf += sprintf(buf, "RSS ");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010114 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +000010115 buf += sprintf(buf, "FD_ATR ");
10116 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
10117 buf += sprintf(buf, "FD_SB ");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010118 buf += sprintf(buf, "NTUPLE ");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +000010119 }
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010120 if (pf->flags & I40E_FLAG_DCB_CAPABLE)
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010121 buf += sprintf(buf, "DCB ");
Jesse Brandeburgce6fcb32015-08-28 17:55:59 -040010122#if IS_ENABLED(CONFIG_VXLAN)
10123 buf += sprintf(buf, "VxLAN ");
10124#endif
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010125 if (pf->flags & I40E_FLAG_PTP)
10126 buf += sprintf(buf, "PTP ");
Vasu Dev38e00432014-08-01 13:27:03 -070010127#ifdef I40E_FCOE
10128 if (pf->flags & I40E_FLAG_FCOE_ENABLED)
10129 buf += sprintf(buf, "FCOE ");
10130#endif
Shannon Nelson6dec1012015-09-28 14:12:30 -040010131 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
10132 buf += sprintf(buf, "VEB ");
10133 else
10134 buf += sprintf(buf, "VEPA ");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010135
10136 BUG_ON(buf > (string + INFO_STRING_LEN));
10137 dev_info(&pf->pdev->dev, "%s\n", string);
10138 kfree(string);
10139}
10140
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010141/**
10142 * i40e_probe - Device initialization routine
10143 * @pdev: PCI device information struct
10144 * @ent: entry in i40e_pci_tbl
10145 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000010146 * i40e_probe initializes a PF identified by a pci_dev structure.
10147 * The OS initialization, configuring of the PF private structure,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010148 * and a hardware reset occur.
10149 *
10150 * Returns 0 on success, negative on failure
10151 **/
10152static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
10153{
Catherine Sullivane8278452015-02-06 08:52:08 +000010154 struct i40e_aq_get_phy_abilities_resp abilities;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010155 struct i40e_pf *pf;
10156 struct i40e_hw *hw;
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000010157 static u16 pfs_found;
Shannon Nelson1d5109d2015-08-26 15:14:08 -040010158 u16 wol_nvm_bits;
Catherine Sullivand4dfb812013-11-28 06:39:21 +000010159 u16 link_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010160 int err = 0;
10161 u32 len;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000010162 u32 i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010163
10164 err = pci_enable_device_mem(pdev);
10165 if (err)
10166 return err;
10167
10168 /* set up for high or low dma */
Mitch Williams64942942014-02-11 08:26:33 +000010169 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +000010170 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +000010171 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
10172 if (err) {
10173 dev_err(&pdev->dev,
10174 "DMA configuration failed: 0x%x\n", err);
10175 goto err_dma;
10176 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010177 }
10178
10179 /* set up pci connections */
10180 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
10181 IORESOURCE_MEM), i40e_driver_name);
10182 if (err) {
10183 dev_info(&pdev->dev,
10184 "pci_request_selected_regions failed %d\n", err);
10185 goto err_pci_reg;
10186 }
10187
10188 pci_enable_pcie_error_reporting(pdev);
10189 pci_set_master(pdev);
10190
10191 /* Now that we have a PCI connection, we need to do the
10192 * low level device setup. This is primarily setting up
10193 * the Admin Queue structures and then querying for the
10194 * device's current profile information.
10195 */
10196 pf = kzalloc(sizeof(*pf), GFP_KERNEL);
10197 if (!pf) {
10198 err = -ENOMEM;
10199 goto err_pf_alloc;
10200 }
10201 pf->next_vsi = 0;
10202 pf->pdev = pdev;
10203 set_bit(__I40E_DOWN, &pf->state);
10204
10205 hw = &pf->hw;
10206 hw->back = pf;
Anjali Singhai232f4702015-02-26 16:15:39 +000010207
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010208 pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
10209 I40E_MAX_CSR_SPACE);
Anjali Singhai232f4702015-02-26 16:15:39 +000010210
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010211 hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010212 if (!hw->hw_addr) {
10213 err = -EIO;
10214 dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
10215 (unsigned int)pci_resource_start(pdev, 0),
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010216 pf->ioremap_len, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010217 goto err_ioremap;
10218 }
10219 hw->vendor_id = pdev->vendor;
10220 hw->device_id = pdev->device;
10221 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
10222 hw->subsystem_vendor_id = pdev->subsystem_vendor;
10223 hw->subsystem_device_id = pdev->subsystem_device;
10224 hw->bus.device = PCI_SLOT(pdev->devfn);
10225 hw->bus.func = PCI_FUNC(pdev->devfn);
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000010226 pf->instance = pfs_found;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010227
Shannon Nelson5b5faa42014-10-17 03:14:51 +000010228 if (debug != -1) {
10229 pf->msg_enable = pf->hw.debug_mask;
10230 pf->msg_enable = debug;
10231 }
10232
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +000010233 /* do a special CORER for clearing PXE mode once at init */
10234 if (hw->revision_id == 0 &&
10235 (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
10236 wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
10237 i40e_flush(hw);
10238 msleep(200);
10239 pf->corer_count++;
10240
10241 i40e_clear_pxe_mode(hw);
10242 }
10243
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010244 /* Reset here to make sure all is clean and to define PF 'n' */
Shannon Nelson838d41d2014-06-04 20:41:27 +000010245 i40e_clear_hw(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010246 err = i40e_pf_reset(hw);
10247 if (err) {
10248 dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
10249 goto err_pf_reset;
10250 }
10251 pf->pfr_count++;
10252
10253 hw->aq.num_arq_entries = I40E_AQ_LEN;
10254 hw->aq.num_asq_entries = I40E_AQ_LEN;
10255 hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
10256 hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
10257 pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +000010258
Carolyn Wybornyb294ac72014-12-11 07:06:39 +000010259 snprintf(pf->int_name, sizeof(pf->int_name) - 1,
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +000010260 "%s-%s:misc",
10261 dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010262
10263 err = i40e_init_shared_code(hw);
10264 if (err) {
Anjali Singhai Jainb2a75c52015-04-27 14:57:20 -040010265 dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
10266 err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010267 goto err_pf_reset;
10268 }
10269
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000010270 /* set up a default setting for link flow control */
10271 pf->hw.fc.requested_mode = I40E_FC_NONE;
10272
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010273 err = i40e_init_adminq(hw);
Carolyn Wybornyf0b44442015-08-31 19:54:49 -040010274
Shannon Nelson6dec1012015-09-28 14:12:30 -040010275 /* provide nvm, fw, api versions */
10276 dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
10277 hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
10278 hw->aq.api_maj_ver, hw->aq.api_min_ver,
10279 i40e_nvm_version_str(hw));
Carolyn Wybornyf0b44442015-08-31 19:54:49 -040010280
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010281 if (err) {
10282 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000010283 "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");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010284 goto err_pf_reset;
10285 }
10286
Catherine Sullivan7aa67612014-07-09 07:46:17 +000010287 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
10288 hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
Shannon Nelson278b6f62014-06-04 01:41:03 +000010289 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000010290 "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");
10291 else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
10292 hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
Shannon Nelson278b6f62014-06-04 01:41:03 +000010293 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000010294 "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 +000010295
Shannon Nelson4eb3f762014-03-06 08:59:58 +000010296 i40e_verify_eeprom(pf);
10297
Jesse Brandeburg2c5fe332014-04-23 04:49:57 +000010298 /* Rev 0 hardware was never productized */
10299 if (hw->revision_id < 1)
10300 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");
10301
Shannon Nelson6ff4ef82013-12-21 05:44:49 +000010302 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010303 err = i40e_get_capabilities(pf);
10304 if (err)
10305 goto err_adminq_setup;
10306
10307 err = i40e_sw_init(pf);
10308 if (err) {
10309 dev_info(&pdev->dev, "sw_init failed: %d\n", err);
10310 goto err_sw_init;
10311 }
10312
10313 err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
10314 hw->func_caps.num_rx_qp,
10315 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
10316 if (err) {
10317 dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
10318 goto err_init_lan_hmc;
10319 }
10320
10321 err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
10322 if (err) {
10323 dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
10324 err = -ENOENT;
10325 goto err_configure_lan_hmc;
10326 }
10327
Neerav Parikhb686ece2014-12-14 01:55:11 +000010328 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
10329 * Ignore error return codes because if it was already disabled via
10330 * hardware settings this will fail
10331 */
10332 if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
10333 (pf->hw.aq.fw_maj_ver < 4)) {
10334 dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
10335 i40e_aq_stop_lldp(hw, true, NULL);
10336 }
10337
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010338 i40e_get_mac_addr(hw, hw->mac.addr);
Jesse Brandeburgf62b5062013-11-28 06:39:27 +000010339 if (!is_valid_ether_addr(hw->mac.addr)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010340 dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
10341 err = -EIO;
10342 goto err_mac_addr;
10343 }
10344 dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
Greg Rose9a173902014-05-22 06:32:02 +000010345 ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
Neerav Parikh1f224ad2014-02-12 01:45:31 +000010346 i40e_get_port_mac_addr(hw, hw->mac.port_addr);
10347 if (is_valid_ether_addr(hw->mac.port_addr))
10348 pf->flags |= I40E_FLAG_PORT_ID_VALID;
Vasu Dev38e00432014-08-01 13:27:03 -070010349#ifdef I40E_FCOE
10350 err = i40e_get_san_mac_addr(hw, hw->mac.san_addr);
10351 if (err)
10352 dev_info(&pdev->dev,
10353 "(non-fatal) SAN MAC retrieval failed: %d\n", err);
10354 if (!is_valid_ether_addr(hw->mac.san_addr)) {
10355 dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
10356 hw->mac.san_addr);
10357 ether_addr_copy(hw->mac.san_addr, hw->mac.addr);
10358 }
10359 dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr);
10360#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010361
10362 pci_set_drvdata(pdev, pf);
10363 pci_save_state(pdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080010364#ifdef CONFIG_I40E_DCB
10365 err = i40e_init_pf_dcb(pf);
10366 if (err) {
Shannon Nelsonaebfc812014-12-11 07:06:38 +000010367 dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010368 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
Neerav Parikh014269f2014-04-01 07:11:48 +000010369 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080010370 }
10371#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010372
10373 /* set up periodic task facility */
10374 setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
10375 pf->service_timer_period = HZ;
10376
10377 INIT_WORK(&pf->service_task, i40e_service_task);
10378 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
10379 pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010380
Shannon Nelson1d5109d2015-08-26 15:14:08 -040010381 /* NVM bit on means WoL disabled for the port */
10382 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
10383 if ((1 << hw->port) & wol_nvm_bits || hw->partition_id != 1)
10384 pf->wol_en = false;
10385 else
10386 pf->wol_en = true;
Shannon Nelson8e2773a2013-11-28 06:39:22 +000010387 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
10388
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010389 /* set up the main switch operations */
10390 i40e_determine_queue_usage(pf);
Jesse Brandeburgc11472802015-04-07 19:45:39 -040010391 err = i40e_init_interrupt_scheme(pf);
10392 if (err)
10393 goto err_switch_setup;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010394
Mitch Williams505682c2014-05-20 08:01:37 +000010395 /* The number of VSIs reported by the FW is the minimum guaranteed
10396 * to us; HW supports far more and we share the remaining pool with
10397 * the other PFs. We allocate space for more than the guarantee with
10398 * the understanding that we might not get them all later.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010399 */
Mitch Williams505682c2014-05-20 08:01:37 +000010400 if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
10401 pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
10402 else
10403 pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
10404
10405 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
10406 len = sizeof(struct i40e_vsi *) * pf->num_alloc_vsi;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010407 pf->vsi = kzalloc(len, GFP_KERNEL);
Wei Yongjuned87ac02013-09-24 05:17:25 +000010408 if (!pf->vsi) {
10409 err = -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010410 goto err_switch_setup;
Wei Yongjuned87ac02013-09-24 05:17:25 +000010411 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010412
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -040010413#ifdef CONFIG_PCI_IOV
10414 /* prep for VF support */
10415 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
10416 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
10417 !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
10418 if (pci_num_vf(pdev))
10419 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
10420 }
10421#endif
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010422 err = i40e_setup_pf_switch(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010423 if (err) {
10424 dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
10425 goto err_vsis;
10426 }
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000010427 /* if FDIR VSI was set up, start it now */
Mitch Williams505682c2014-05-20 08:01:37 +000010428 for (i = 0; i < pf->num_alloc_vsi; i++) {
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000010429 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
10430 i40e_vsi_open(pf->vsi[i]);
10431 break;
10432 }
10433 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010434
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000010435 /* driver is only interested in link up/down and module qualification
10436 * reports from firmware
10437 */
10438 err = i40e_aq_set_phy_int_mask(&pf->hw,
10439 I40E_AQ_EVENT_LINK_UPDOWN |
10440 I40E_AQ_EVENT_MODULE_QUAL_FAIL, NULL);
10441 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010442 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
10443 i40e_stat_str(&pf->hw, err),
10444 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000010445
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +000010446 if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
10447 (pf->hw.aq.fw_maj_ver < 4)) {
10448 msleep(75);
10449 err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
10450 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010451 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
10452 i40e_stat_str(&pf->hw, err),
10453 i40e_aq_str(&pf->hw,
10454 pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +000010455 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010456 /* The main driver is (mostly) up and happy. We need to set this state
10457 * before setting up the misc vector or we get a race and the vector
10458 * ends up disabled forever.
10459 */
10460 clear_bit(__I40E_DOWN, &pf->state);
10461
10462 /* In case of MSIX we are going to setup the misc vector right here
10463 * to handle admin queue events etc. In case of legacy and MSI
10464 * the misc functionality and queue processing is combined in
10465 * the same vector and that gets setup at open.
10466 */
10467 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
10468 err = i40e_setup_misc_vector(pf);
10469 if (err) {
10470 dev_info(&pdev->dev,
10471 "setup of misc vector failed: %d\n", err);
10472 goto err_vsis;
10473 }
10474 }
10475
Greg Rosedf805f62014-04-04 04:43:16 +000010476#ifdef CONFIG_PCI_IOV
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010477 /* prep for VF support */
10478 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
Shannon Nelson4eb3f762014-03-06 08:59:58 +000010479 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
10480 !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010481 u32 val;
10482
10483 /* disable link interrupts for VFs */
10484 val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
10485 val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
10486 wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
10487 i40e_flush(hw);
Mitch Williams4aeec012014-02-13 03:48:47 -080010488
10489 if (pci_num_vf(pdev)) {
10490 dev_info(&pdev->dev,
10491 "Active VFs found, allocating resources.\n");
10492 err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
10493 if (err)
10494 dev_info(&pdev->dev,
10495 "Error %d allocating resources for existing VFs\n",
10496 err);
10497 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010498 }
Greg Rosedf805f62014-04-04 04:43:16 +000010499#endif /* CONFIG_PCI_IOV */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010500
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000010501 pfs_found++;
10502
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010503 i40e_dbg_pf_init(pf);
10504
10505 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +000010506 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010507
10508 /* since everything's happy, start the service_task timer */
10509 mod_timer(&pf->service_timer,
10510 round_jiffies(jiffies + pf->service_timer_period));
10511
Vasu Dev38e00432014-08-01 13:27:03 -070010512#ifdef I40E_FCOE
10513 /* create FCoE interface */
10514 i40e_fcoe_vsi_setup(pf);
10515
10516#endif
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040010517#define PCI_SPEED_SIZE 8
10518#define PCI_WIDTH_SIZE 8
10519 /* Devices on the IOSF bus do not have this information
10520 * and will report PCI Gen 1 x 1 by default so don't bother
10521 * checking them.
10522 */
10523 if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) {
10524 char speed[PCI_SPEED_SIZE] = "Unknown";
10525 char width[PCI_WIDTH_SIZE] = "Unknown";
Catherine Sullivand4dfb812013-11-28 06:39:21 +000010526
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040010527 /* Get the negotiated link width and speed from PCI config
10528 * space
10529 */
10530 pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
10531 &link_status);
Catherine Sullivand4dfb812013-11-28 06:39:21 +000010532
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040010533 i40e_set_pci_config_data(hw, link_status);
Catherine Sullivand4dfb812013-11-28 06:39:21 +000010534
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040010535 switch (hw->bus.speed) {
10536 case i40e_bus_speed_8000:
10537 strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
10538 case i40e_bus_speed_5000:
10539 strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
10540 case i40e_bus_speed_2500:
10541 strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
10542 default:
10543 break;
10544 }
10545 switch (hw->bus.width) {
10546 case i40e_bus_width_pcie_x8:
10547 strncpy(width, "8", PCI_WIDTH_SIZE); break;
10548 case i40e_bus_width_pcie_x4:
10549 strncpy(width, "4", PCI_WIDTH_SIZE); break;
10550 case i40e_bus_width_pcie_x2:
10551 strncpy(width, "2", PCI_WIDTH_SIZE); break;
10552 case i40e_bus_width_pcie_x1:
10553 strncpy(width, "1", PCI_WIDTH_SIZE); break;
10554 default:
10555 break;
10556 }
10557
10558 dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
10559 speed, width);
10560
10561 if (hw->bus.width < i40e_bus_width_pcie_x8 ||
10562 hw->bus.speed < i40e_bus_speed_8000) {
10563 dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
10564 dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
10565 }
Catherine Sullivand4dfb812013-11-28 06:39:21 +000010566 }
10567
Catherine Sullivane8278452015-02-06 08:52:08 +000010568 /* get the requested speeds from the fw */
10569 err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
10570 if (err)
Neerav Parikh8279e492015-09-03 17:18:50 -040010571 dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
10572 i40e_stat_str(&pf->hw, err),
10573 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Catherine Sullivane8278452015-02-06 08:52:08 +000010574 pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
10575
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -040010576 /* get the supported phy types from the fw */
10577 err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
10578 if (err)
10579 dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
10580 i40e_stat_str(&pf->hw, err),
10581 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10582 pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type);
10583
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010584 /* print a string summarizing features */
10585 i40e_print_features(pf);
10586
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010587 return 0;
10588
10589 /* Unwind what we've done if something failed in the setup */
10590err_vsis:
10591 set_bit(__I40E_DOWN, &pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010592 i40e_clear_interrupt_scheme(pf);
10593 kfree(pf->vsi);
Shannon Nelson04b03012013-11-28 06:39:34 +000010594err_switch_setup:
10595 i40e_reset_interrupt_capability(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010596 del_timer_sync(&pf->service_timer);
10597err_mac_addr:
10598err_configure_lan_hmc:
10599 (void)i40e_shutdown_lan_hmc(hw);
10600err_init_lan_hmc:
10601 kfree(pf->qp_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010602err_sw_init:
10603err_adminq_setup:
10604 (void)i40e_shutdown_adminq(hw);
10605err_pf_reset:
10606 iounmap(hw->hw_addr);
10607err_ioremap:
10608 kfree(pf);
10609err_pf_alloc:
10610 pci_disable_pcie_error_reporting(pdev);
10611 pci_release_selected_regions(pdev,
10612 pci_select_bars(pdev, IORESOURCE_MEM));
10613err_pci_reg:
10614err_dma:
10615 pci_disable_device(pdev);
10616 return err;
10617}
10618
10619/**
10620 * i40e_remove - Device removal routine
10621 * @pdev: PCI device information struct
10622 *
10623 * i40e_remove is called by the PCI subsystem to alert the driver
10624 * that is should release a PCI device. This could be caused by a
10625 * Hot-Plug event, or because the driver is going to be removed from
10626 * memory.
10627 **/
10628static void i40e_remove(struct pci_dev *pdev)
10629{
10630 struct i40e_pf *pf = pci_get_drvdata(pdev);
10631 i40e_status ret_code;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010632 int i;
10633
10634 i40e_dbg_pf_exit(pf);
10635
Jacob Kellerbeb0dff2014-01-11 05:43:19 +000010636 i40e_ptp_stop(pf);
10637
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010638 /* no more scheduling of any task */
10639 set_bit(__I40E_DOWN, &pf->state);
10640 del_timer_sync(&pf->service_timer);
10641 cancel_work_sync(&pf->service_task);
Mitch A Williams33c62b32015-02-21 06:44:51 +000010642 i40e_fdir_teardown(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010643
Mitch Williamseb2d80b2014-02-13 03:48:48 -080010644 if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
10645 i40e_free_vfs(pf);
10646 pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
10647 }
10648
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010649 i40e_fdir_teardown(pf);
10650
10651 /* If there is a switch structure or any orphans, remove them.
10652 * This will leave only the PF's VSI remaining.
10653 */
10654 for (i = 0; i < I40E_MAX_VEB; i++) {
10655 if (!pf->veb[i])
10656 continue;
10657
10658 if (pf->veb[i]->uplink_seid == pf->mac_seid ||
10659 pf->veb[i]->uplink_seid == 0)
10660 i40e_switch_branch_release(pf->veb[i]);
10661 }
10662
10663 /* Now we can shutdown the PF's VSI, just before we kill
10664 * adminq and hmc.
10665 */
10666 if (pf->vsi[pf->lan_vsi])
10667 i40e_vsi_release(pf->vsi[pf->lan_vsi]);
10668
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010669 /* shutdown and destroy the HMC */
Shannon Nelson60442de2014-04-23 04:50:13 +000010670 if (pf->hw.hmc.hmc_obj) {
10671 ret_code = i40e_shutdown_lan_hmc(&pf->hw);
10672 if (ret_code)
10673 dev_warn(&pdev->dev,
10674 "Failed to destroy the HMC resources: %d\n",
10675 ret_code);
10676 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010677
10678 /* shutdown the adminq */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010679 ret_code = i40e_shutdown_adminq(&pf->hw);
10680 if (ret_code)
10681 dev_warn(&pdev->dev,
10682 "Failed to destroy the Admin Queue resources: %d\n",
10683 ret_code);
10684
10685 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
10686 i40e_clear_interrupt_scheme(pf);
Mitch Williams505682c2014-05-20 08:01:37 +000010687 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010688 if (pf->vsi[i]) {
10689 i40e_vsi_clear_rings(pf->vsi[i]);
10690 i40e_vsi_clear(pf->vsi[i]);
10691 pf->vsi[i] = NULL;
10692 }
10693 }
10694
10695 for (i = 0; i < I40E_MAX_VEB; i++) {
10696 kfree(pf->veb[i]);
10697 pf->veb[i] = NULL;
10698 }
10699
10700 kfree(pf->qp_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010701 kfree(pf->vsi);
10702
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010703 iounmap(pf->hw.hw_addr);
10704 kfree(pf);
10705 pci_release_selected_regions(pdev,
10706 pci_select_bars(pdev, IORESOURCE_MEM));
10707
10708 pci_disable_pcie_error_reporting(pdev);
10709 pci_disable_device(pdev);
10710}
10711
10712/**
10713 * i40e_pci_error_detected - warning that something funky happened in PCI land
10714 * @pdev: PCI device information struct
10715 *
10716 * Called to warn that something happened and the error handling steps
10717 * are in progress. Allows the driver to quiesce things, be ready for
10718 * remediation.
10719 **/
10720static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
10721 enum pci_channel_state error)
10722{
10723 struct i40e_pf *pf = pci_get_drvdata(pdev);
10724
10725 dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
10726
10727 /* shutdown all operations */
Shannon Nelson9007bcc2013-11-26 10:49:23 +000010728 if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
10729 rtnl_lock();
10730 i40e_prep_for_reset(pf);
10731 rtnl_unlock();
10732 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010733
10734 /* Request a slot reset */
10735 return PCI_ERS_RESULT_NEED_RESET;
10736}
10737
10738/**
10739 * i40e_pci_error_slot_reset - a PCI slot reset just happened
10740 * @pdev: PCI device information struct
10741 *
10742 * Called to find if the driver can work with the device now that
10743 * the pci slot has been reset. If a basic connection seems good
10744 * (registers are readable and have sane content) then return a
10745 * happy little PCI_ERS_RESULT_xxx.
10746 **/
10747static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
10748{
10749 struct i40e_pf *pf = pci_get_drvdata(pdev);
10750 pci_ers_result_t result;
10751 int err;
10752 u32 reg;
10753
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040010754 dev_dbg(&pdev->dev, "%s\n", __func__);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010755 if (pci_enable_device_mem(pdev)) {
10756 dev_info(&pdev->dev,
10757 "Cannot re-enable PCI device after reset.\n");
10758 result = PCI_ERS_RESULT_DISCONNECT;
10759 } else {
10760 pci_set_master(pdev);
10761 pci_restore_state(pdev);
10762 pci_save_state(pdev);
10763 pci_wake_from_d3(pdev, false);
10764
10765 reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
10766 if (reg == 0)
10767 result = PCI_ERS_RESULT_RECOVERED;
10768 else
10769 result = PCI_ERS_RESULT_DISCONNECT;
10770 }
10771
10772 err = pci_cleanup_aer_uncorrect_error_status(pdev);
10773 if (err) {
10774 dev_info(&pdev->dev,
10775 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
10776 err);
10777 /* non-fatal, continue */
10778 }
10779
10780 return result;
10781}
10782
10783/**
10784 * i40e_pci_error_resume - restart operations after PCI error recovery
10785 * @pdev: PCI device information struct
10786 *
10787 * Called to allow the driver to bring things back up after PCI error
10788 * and/or reset recovery has finished.
10789 **/
10790static void i40e_pci_error_resume(struct pci_dev *pdev)
10791{
10792 struct i40e_pf *pf = pci_get_drvdata(pdev);
10793
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040010794 dev_dbg(&pdev->dev, "%s\n", __func__);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000010795 if (test_bit(__I40E_SUSPENDED, &pf->state))
10796 return;
10797
10798 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010799 i40e_handle_reset_warning(pf);
Vasily Averin4c4935a2015-07-08 15:04:26 +030010800 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010801}
10802
Shannon Nelson9007bcc2013-11-26 10:49:23 +000010803/**
10804 * i40e_shutdown - PCI callback for shutting down
10805 * @pdev: PCI device information struct
10806 **/
10807static void i40e_shutdown(struct pci_dev *pdev)
10808{
10809 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +000010810 struct i40e_hw *hw = &pf->hw;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000010811
10812 set_bit(__I40E_SUSPENDED, &pf->state);
10813 set_bit(__I40E_DOWN, &pf->state);
10814 rtnl_lock();
10815 i40e_prep_for_reset(pf);
10816 rtnl_unlock();
10817
Shannon Nelson8e2773a2013-11-28 06:39:22 +000010818 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
10819 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
10820
Catherine Sullivan02b42492015-07-10 19:35:59 -040010821 del_timer_sync(&pf->service_timer);
10822 cancel_work_sync(&pf->service_task);
10823 i40e_fdir_teardown(pf);
10824
10825 rtnl_lock();
10826 i40e_prep_for_reset(pf);
10827 rtnl_unlock();
10828
10829 wr32(hw, I40E_PFPM_APM,
10830 (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
10831 wr32(hw, I40E_PFPM_WUFC,
10832 (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
10833
Shannon Nelsone1477582015-02-21 06:44:33 +000010834 i40e_clear_interrupt_scheme(pf);
10835
Shannon Nelson9007bcc2013-11-26 10:49:23 +000010836 if (system_state == SYSTEM_POWER_OFF) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +000010837 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000010838 pci_set_power_state(pdev, PCI_D3hot);
10839 }
10840}
10841
10842#ifdef CONFIG_PM
10843/**
10844 * i40e_suspend - PCI callback for moving to D3
10845 * @pdev: PCI device information struct
10846 **/
10847static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
10848{
10849 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +000010850 struct i40e_hw *hw = &pf->hw;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000010851
10852 set_bit(__I40E_SUSPENDED, &pf->state);
10853 set_bit(__I40E_DOWN, &pf->state);
Mitch Williams3932dbf2015-03-31 00:45:04 -070010854
Shannon Nelson9007bcc2013-11-26 10:49:23 +000010855 rtnl_lock();
10856 i40e_prep_for_reset(pf);
10857 rtnl_unlock();
10858
Shannon Nelson8e2773a2013-11-28 06:39:22 +000010859 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
10860 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
10861
10862 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000010863 pci_set_power_state(pdev, PCI_D3hot);
10864
10865 return 0;
10866}
10867
10868/**
10869 * i40e_resume - PCI callback for waking up from D3
10870 * @pdev: PCI device information struct
10871 **/
10872static int i40e_resume(struct pci_dev *pdev)
10873{
10874 struct i40e_pf *pf = pci_get_drvdata(pdev);
10875 u32 err;
10876
10877 pci_set_power_state(pdev, PCI_D0);
10878 pci_restore_state(pdev);
10879 /* pci_restore_state() clears dev->state_saves, so
10880 * call pci_save_state() again to restore it.
10881 */
10882 pci_save_state(pdev);
10883
10884 err = pci_enable_device_mem(pdev);
10885 if (err) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040010886 dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
Shannon Nelson9007bcc2013-11-26 10:49:23 +000010887 return err;
10888 }
10889 pci_set_master(pdev);
10890
10891 /* no wakeup events while running */
10892 pci_wake_from_d3(pdev, false);
10893
10894 /* handling the reset will rebuild the device state */
10895 if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
10896 clear_bit(__I40E_DOWN, &pf->state);
10897 rtnl_lock();
10898 i40e_reset_and_rebuild(pf, false);
10899 rtnl_unlock();
10900 }
10901
10902 return 0;
10903}
10904
10905#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010906static const struct pci_error_handlers i40e_err_handler = {
10907 .error_detected = i40e_pci_error_detected,
10908 .slot_reset = i40e_pci_error_slot_reset,
10909 .resume = i40e_pci_error_resume,
10910};
10911
10912static struct pci_driver i40e_driver = {
10913 .name = i40e_driver_name,
10914 .id_table = i40e_pci_tbl,
10915 .probe = i40e_probe,
10916 .remove = i40e_remove,
Shannon Nelson9007bcc2013-11-26 10:49:23 +000010917#ifdef CONFIG_PM
10918 .suspend = i40e_suspend,
10919 .resume = i40e_resume,
10920#endif
10921 .shutdown = i40e_shutdown,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010922 .err_handler = &i40e_err_handler,
10923 .sriov_configure = i40e_pci_sriov_configure,
10924};
10925
10926/**
10927 * i40e_init_module - Driver registration routine
10928 *
10929 * i40e_init_module is the first routine called when the driver is
10930 * loaded. All it does is register with the PCI subsystem.
10931 **/
10932static int __init i40e_init_module(void)
10933{
10934 pr_info("%s: %s - version %s\n", i40e_driver_name,
10935 i40e_driver_string, i40e_driver_version_str);
10936 pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
Greg Rose96664482015-02-06 08:52:13 +000010937
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010938 i40e_dbg_init();
10939 return pci_register_driver(&i40e_driver);
10940}
10941module_init(i40e_init_module);
10942
10943/**
10944 * i40e_exit_module - Driver exit cleanup routine
10945 *
10946 * i40e_exit_module is called just before the driver is removed
10947 * from memory.
10948 **/
10949static void __exit i40e_exit_module(void)
10950{
10951 pci_unregister_driver(&i40e_driver);
10952 i40e_dbg_exit();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010953}
10954module_exit(i40e_exit_module);