blob: bd81a9770c5be2b051a3edce1a80eadffcd81f9b [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
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050027#include <linux/etherdevice.h>
28#include <linux/of_net.h>
29#include <linux/pci.h>
30
31#ifdef CONFIG_SPARC
32#include <asm/idprom.h>
33#include <asm/prom.h>
34#endif
35
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000036/* Local includes */
37#include "i40e.h"
Shannon Nelson4eb3f762014-03-06 08:59:58 +000038#include "i40e_diag.h"
Singhai, Anjali6a899022015-12-14 12:21:18 -080039#if IS_ENABLED(CONFIG_VXLAN)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +000040#include <net/vxlan.h>
41#endif
Singhai, Anjali6a899022015-12-14 12:21:18 -080042#if IS_ENABLED(CONFIG_GENEVE)
43#include <net/geneve.h>
44#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000045
46const char i40e_driver_name[] = "i40e";
47static const char i40e_driver_string[] =
48 "Intel(R) Ethernet Connection XL710 Network Driver";
49
50#define DRV_KERN "-k"
51
Catherine Sullivane8e724d2014-07-10 07:58:26 +000052#define DRV_VERSION_MAJOR 1
Catherine Sullivan1c2df9e2015-10-21 19:56:24 -040053#define DRV_VERSION_MINOR 4
Catherine Sullivan4f9e6972015-12-10 11:38:51 -080054#define DRV_VERSION_BUILD 10
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000055#define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
56 __stringify(DRV_VERSION_MINOR) "." \
57 __stringify(DRV_VERSION_BUILD) DRV_KERN
58const char i40e_driver_version_str[] = DRV_VERSION;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -080059static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000060
61/* a bit of forward declarations */
62static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
63static void i40e_handle_reset_warning(struct i40e_pf *pf);
64static int i40e_add_vsi(struct i40e_vsi *vsi);
65static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000066static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000067static int i40e_setup_misc_vector(struct i40e_pf *pf);
68static void i40e_determine_queue_usage(struct i40e_pf *pf);
69static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
Helin Zhange69ff812015-10-21 19:56:22 -040070static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
71 u16 rss_table_size, u16 rss_size);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080072static void i40e_fdir_sb_setup(struct i40e_pf *pf);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080073static int i40e_veb_get_bw_info(struct i40e_veb *veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000074
75/* i40e_pci_tbl - PCI Device ID Table
76 *
77 * Last entry must be all 0s
78 *
79 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
80 * Class, Class Mask, private data (not used) }
81 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020082static const struct pci_device_id i40e_pci_tbl[] = {
Shannon Nelsonab600852014-01-17 15:36:39 -080083 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080084 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080085 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
86 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080087 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
88 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
89 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
Mitch Williams5960d332014-09-13 07:40:47 +000090 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
Shannon Nelsonbc5166b92015-08-26 15:14:10 -040091 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
Jesse Brandeburgae24b402015-03-27 00:12:09 -070092 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
Anjali Singhai Jain35dae512015-12-22 14:25:03 -080093 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0},
94 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0},
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040095 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
96 {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
97 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
Shannon Nelson48a3b512015-07-23 16:54:39 -040098 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
99 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000100 /* required last entry */
101 {0, }
102};
103MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
104
105#define I40E_MAX_VF_COUNT 128
106static int debug = -1;
107module_param(debug, int, 0);
108MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
109
110MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
111MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
112MODULE_LICENSE("GPL");
113MODULE_VERSION(DRV_VERSION);
114
115/**
116 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
117 * @hw: pointer to the HW structure
118 * @mem: ptr to mem struct to fill out
119 * @size: size of memory requested
120 * @alignment: what to align the allocation to
121 **/
122int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
123 u64 size, u32 alignment)
124{
125 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
126
127 mem->size = ALIGN(size, alignment);
128 mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
129 &mem->pa, GFP_KERNEL);
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000130 if (!mem->va)
131 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000132
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000133 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000134}
135
136/**
137 * i40e_free_dma_mem_d - OS specific memory free for shared code
138 * @hw: pointer to the HW structure
139 * @mem: ptr to mem struct to free
140 **/
141int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
142{
143 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
144
145 dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
146 mem->va = NULL;
147 mem->pa = 0;
148 mem->size = 0;
149
150 return 0;
151}
152
153/**
154 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
155 * @hw: pointer to the HW structure
156 * @mem: ptr to mem struct to fill out
157 * @size: size of memory requested
158 **/
159int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
160 u32 size)
161{
162 mem->size = size;
163 mem->va = kzalloc(size, GFP_KERNEL);
164
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000165 if (!mem->va)
166 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000167
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000168 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000169}
170
171/**
172 * i40e_free_virt_mem_d - OS specific memory free for shared code
173 * @hw: pointer to the HW structure
174 * @mem: ptr to mem struct to free
175 **/
176int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
177{
178 /* it's ok to kfree a NULL pointer */
179 kfree(mem->va);
180 mem->va = NULL;
181 mem->size = 0;
182
183 return 0;
184}
185
186/**
187 * i40e_get_lump - find a lump of free generic resource
188 * @pf: board private structure
189 * @pile: the pile of resource to search
190 * @needed: the number of items needed
191 * @id: an owner id to stick on the items assigned
192 *
193 * Returns the base item index of the lump, or negative for error
194 *
195 * The search_hint trick and lack of advanced fit-finding only work
196 * because we're highly likely to have all the same size lump requests.
197 * Linear search time and any fragmentation should be minimal.
198 **/
199static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
200 u16 needed, u16 id)
201{
202 int ret = -ENOMEM;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000203 int i, j;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000204
205 if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
206 dev_info(&pf->pdev->dev,
207 "param err: pile=%p needed=%d id=0x%04x\n",
208 pile, needed, id);
209 return -EINVAL;
210 }
211
212 /* start the linear search with an imperfect hint */
213 i = pile->search_hint;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000214 while (i < pile->num_entries) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000215 /* skip already allocated entries */
216 if (pile->list[i] & I40E_PILE_VALID_BIT) {
217 i++;
218 continue;
219 }
220
221 /* do we have enough in this lump? */
222 for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
223 if (pile->list[i+j] & I40E_PILE_VALID_BIT)
224 break;
225 }
226
227 if (j == needed) {
228 /* there was enough, so assign it to the requestor */
229 for (j = 0; j < needed; j++)
230 pile->list[i+j] = id | I40E_PILE_VALID_BIT;
231 ret = i;
232 pile->search_hint = i + j;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000233 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000234 }
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400235
236 /* not enough, so skip over it and continue looking */
237 i += j;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000238 }
239
240 return ret;
241}
242
243/**
244 * i40e_put_lump - return a lump of generic resource
245 * @pile: the pile of resource to search
246 * @index: the base item index
247 * @id: the owner id of the items assigned
248 *
249 * Returns the count of items in the lump
250 **/
251static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
252{
253 int valid_id = (id | I40E_PILE_VALID_BIT);
254 int count = 0;
255 int i;
256
257 if (!pile || index >= pile->num_entries)
258 return -EINVAL;
259
260 for (i = index;
261 i < pile->num_entries && pile->list[i] == valid_id;
262 i++) {
263 pile->list[i] = 0;
264 count++;
265 }
266
267 if (count && index < pile->search_hint)
268 pile->search_hint = index;
269
270 return count;
271}
272
273/**
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700274 * i40e_find_vsi_from_id - searches for the vsi with the given id
275 * @pf - the pf structure to search for the vsi
276 * @id - id of the vsi it is searching for
277 **/
278struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
279{
280 int i;
281
282 for (i = 0; i < pf->num_alloc_vsi; i++)
283 if (pf->vsi[i] && (pf->vsi[i]->id == id))
284 return pf->vsi[i];
285
286 return NULL;
287}
288
289/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000290 * i40e_service_event_schedule - Schedule the service task to wake up
291 * @pf: board private structure
292 *
293 * If not already scheduled, this puts the task into the work queue
294 **/
295static void i40e_service_event_schedule(struct i40e_pf *pf)
296{
297 if (!test_bit(__I40E_DOWN, &pf->state) &&
298 !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) &&
299 !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
300 schedule_work(&pf->service_task);
301}
302
303/**
304 * i40e_tx_timeout - Respond to a Tx Hang
305 * @netdev: network interface device structure
306 *
307 * If any port has noticed a Tx timeout, it is likely that the whole
308 * device is munged, not just the one netdev port, so go for the full
309 * reset.
310 **/
Vasu Dev38e00432014-08-01 13:27:03 -0700311#ifdef I40E_FCOE
312void i40e_tx_timeout(struct net_device *netdev)
313#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000314static void i40e_tx_timeout(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -0700315#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000316{
317 struct i40e_netdev_priv *np = netdev_priv(netdev);
318 struct i40e_vsi *vsi = np->vsi;
319 struct i40e_pf *pf = vsi->back;
Kiran Patilb03a8c12015-09-24 18:13:15 -0400320 struct i40e_ring *tx_ring = NULL;
321 unsigned int i, hung_queue = 0;
322 u32 head, val;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000323
324 pf->tx_timeout_count++;
325
Kiran Patilb03a8c12015-09-24 18:13:15 -0400326 /* find the stopped queue the same way the stack does */
327 for (i = 0; i < netdev->num_tx_queues; i++) {
328 struct netdev_queue *q;
329 unsigned long trans_start;
330
331 q = netdev_get_tx_queue(netdev, i);
332 trans_start = q->trans_start ? : netdev->trans_start;
333 if (netif_xmit_stopped(q) &&
334 time_after(jiffies,
335 (trans_start + netdev->watchdog_timeo))) {
336 hung_queue = i;
337 break;
338 }
339 }
340
341 if (i == netdev->num_tx_queues) {
342 netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
343 } else {
344 /* now that we have an index, find the tx_ring struct */
345 for (i = 0; i < vsi->num_queue_pairs; i++) {
346 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
347 if (hung_queue ==
348 vsi->tx_rings[i]->queue_index) {
349 tx_ring = vsi->tx_rings[i];
350 break;
351 }
352 }
353 }
354 }
355
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000356 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
Kiran Patilb03a8c12015-09-24 18:13:15 -0400357 pf->tx_timeout_recovery_level = 1; /* reset after some time */
358 else if (time_before(jiffies,
359 (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
360 return; /* don't do any new action before the next timeout */
361
362 if (tx_ring) {
363 head = i40e_get_head(tx_ring);
364 /* Read interrupt register */
365 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
366 val = rd32(&pf->hw,
367 I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
368 tx_ring->vsi->base_vector - 1));
369 else
370 val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
371
372 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",
373 vsi->seid, hung_queue, tx_ring->next_to_clean,
374 head, tx_ring->next_to_use,
375 readl(tx_ring->tail), val);
376 }
377
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000378 pf->tx_timeout_last_recovery = jiffies;
Kiran Patilb03a8c12015-09-24 18:13:15 -0400379 netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
380 pf->tx_timeout_recovery_level, hung_queue);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000381
382 switch (pf->tx_timeout_recovery_level) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000383 case 1:
384 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
385 break;
386 case 2:
387 set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
388 break;
389 case 3:
390 set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
391 break;
392 default:
393 netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000394 break;
395 }
Kiran Patilb03a8c12015-09-24 18:13:15 -0400396
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000397 i40e_service_event_schedule(pf);
398 pf->tx_timeout_recovery_level++;
399}
400
401/**
402 * i40e_release_rx_desc - Store the new tail and head values
403 * @rx_ring: ring to bump
404 * @val: new head index
405 **/
406static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val)
407{
408 rx_ring->next_to_use = val;
409
410 /* Force memory writes to complete before letting h/w
411 * know there are new descriptors to fetch. (Only
412 * applicable for weak-ordered memory model archs,
413 * such as IA-64).
414 */
415 wmb();
416 writel(val, rx_ring->tail);
417}
418
419/**
420 * i40e_get_vsi_stats_struct - Get System Network Statistics
421 * @vsi: the VSI we care about
422 *
423 * Returns the address of the device statistics structure.
424 * The statistics are actually updated from the service task.
425 **/
426struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
427{
428 return &vsi->net_stats;
429}
430
431/**
432 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
433 * @netdev: network interface device structure
434 *
435 * Returns the address of the device statistics structure.
436 * The statistics are actually updated from the service task.
437 **/
Vasu Dev38e00432014-08-01 13:27:03 -0700438#ifdef I40E_FCOE
439struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
440 struct net_device *netdev,
441 struct rtnl_link_stats64 *stats)
442#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000443static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
444 struct net_device *netdev,
Alexander Duyck980e9b12013-09-28 06:01:03 +0000445 struct rtnl_link_stats64 *stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700446#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000447{
448 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000449 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000450 struct i40e_vsi *vsi = np->vsi;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000451 struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
452 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000453
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +0000454 if (test_bit(__I40E_DOWN, &vsi->state))
455 return stats;
456
Jesse Brandeburg3c325ce2013-12-14 03:26:45 -0800457 if (!vsi->tx_rings)
458 return stats;
459
Alexander Duyck980e9b12013-09-28 06:01:03 +0000460 rcu_read_lock();
461 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000462 u64 bytes, packets;
463 unsigned int start;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000464
Alexander Duyck980e9b12013-09-28 06:01:03 +0000465 tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
466 if (!tx_ring)
467 continue;
468
469 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700470 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000471 packets = tx_ring->stats.packets;
472 bytes = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700473 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000474
475 stats->tx_packets += packets;
476 stats->tx_bytes += bytes;
477 rx_ring = &tx_ring[1];
478
479 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700480 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000481 packets = rx_ring->stats.packets;
482 bytes = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700483 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000484
485 stats->rx_packets += packets;
486 stats->rx_bytes += bytes;
487 }
488 rcu_read_unlock();
489
Akeem G Abodunrina5282f42014-05-10 04:49:03 +0000490 /* following stats updated by i40e_watchdog_subtask() */
Alexander Duyck980e9b12013-09-28 06:01:03 +0000491 stats->multicast = vsi_stats->multicast;
492 stats->tx_errors = vsi_stats->tx_errors;
493 stats->tx_dropped = vsi_stats->tx_dropped;
494 stats->rx_errors = vsi_stats->rx_errors;
Jesse Brandeburgd8201e22015-07-23 16:54:35 -0400495 stats->rx_dropped = vsi_stats->rx_dropped;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000496 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
497 stats->rx_length_errors = vsi_stats->rx_length_errors;
498
499 return stats;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000500}
501
502/**
503 * i40e_vsi_reset_stats - Resets all stats of the given vsi
504 * @vsi: the VSI to have its stats reset
505 **/
506void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
507{
508 struct rtnl_link_stats64 *ns;
509 int i;
510
511 if (!vsi)
512 return;
513
514 ns = i40e_get_vsi_stats_struct(vsi);
515 memset(ns, 0, sizeof(*ns));
516 memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
517 memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
518 memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
Greg Rose8e9dca52013-12-18 13:45:53 +0000519 if (vsi->rx_rings && vsi->rx_rings[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000520 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400521 memset(&vsi->rx_rings[i]->stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000522 sizeof(vsi->rx_rings[i]->stats));
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400523 memset(&vsi->rx_rings[i]->rx_stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000524 sizeof(vsi->rx_rings[i]->rx_stats));
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400525 memset(&vsi->tx_rings[i]->stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000526 sizeof(vsi->tx_rings[i]->stats));
527 memset(&vsi->tx_rings[i]->tx_stats, 0,
528 sizeof(vsi->tx_rings[i]->tx_stats));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000529 }
Greg Rose8e9dca52013-12-18 13:45:53 +0000530 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000531 vsi->stat_offsets_loaded = false;
532}
533
534/**
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000535 * i40e_pf_reset_stats - Reset all of the stats for the given PF
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000536 * @pf: the PF to be reset
537 **/
538void i40e_pf_reset_stats(struct i40e_pf *pf)
539{
Shannon Nelsone91fdf72014-06-03 23:50:18 +0000540 int i;
541
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000542 memset(&pf->stats, 0, sizeof(pf->stats));
543 memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
544 pf->stat_offsets_loaded = false;
Shannon Nelsone91fdf72014-06-03 23:50:18 +0000545
546 for (i = 0; i < I40E_MAX_VEB; i++) {
547 if (pf->veb[i]) {
548 memset(&pf->veb[i]->stats, 0,
549 sizeof(pf->veb[i]->stats));
550 memset(&pf->veb[i]->stats_offsets, 0,
551 sizeof(pf->veb[i]->stats_offsets));
552 pf->veb[i]->stat_offsets_loaded = false;
553 }
554 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000555}
556
557/**
558 * i40e_stat_update48 - read and update a 48 bit stat from the chip
559 * @hw: ptr to the hardware info
560 * @hireg: the high 32 bit reg to read
561 * @loreg: the low 32 bit reg to read
562 * @offset_loaded: has the initial offset been loaded yet
563 * @offset: ptr to current offset value
564 * @stat: ptr to the stat
565 *
566 * Since the device stats are not reset at PFReset, they likely will not
567 * be zeroed when the driver starts. We'll save the first values read
568 * and use them as offsets to be subtracted from the raw values in order
569 * to report stats that count from zero. In the process, we also manage
570 * the potential roll-over.
571 **/
572static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
573 bool offset_loaded, u64 *offset, u64 *stat)
574{
575 u64 new_data;
576
Shannon Nelsonab600852014-01-17 15:36:39 -0800577 if (hw->device_id == I40E_DEV_ID_QEMU) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000578 new_data = rd32(hw, loreg);
579 new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
580 } else {
581 new_data = rd64(hw, loreg);
582 }
583 if (!offset_loaded)
584 *offset = new_data;
585 if (likely(new_data >= *offset))
586 *stat = new_data - *offset;
587 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400588 *stat = (new_data + BIT_ULL(48)) - *offset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000589 *stat &= 0xFFFFFFFFFFFFULL;
590}
591
592/**
593 * i40e_stat_update32 - read and update a 32 bit stat from the chip
594 * @hw: ptr to the hardware info
595 * @reg: the hw reg to read
596 * @offset_loaded: has the initial offset been loaded yet
597 * @offset: ptr to current offset value
598 * @stat: ptr to the stat
599 **/
600static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
601 bool offset_loaded, u64 *offset, u64 *stat)
602{
603 u32 new_data;
604
605 new_data = rd32(hw, reg);
606 if (!offset_loaded)
607 *offset = new_data;
608 if (likely(new_data >= *offset))
609 *stat = (u32)(new_data - *offset);
610 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400611 *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000612}
613
614/**
615 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
616 * @vsi: the VSI to be updated
617 **/
618void i40e_update_eth_stats(struct i40e_vsi *vsi)
619{
620 int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
621 struct i40e_pf *pf = vsi->back;
622 struct i40e_hw *hw = &pf->hw;
623 struct i40e_eth_stats *oes;
624 struct i40e_eth_stats *es; /* device's eth stats */
625
626 es = &vsi->eth_stats;
627 oes = &vsi->eth_stats_offsets;
628
629 /* Gather up the stats that the hw collects */
630 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
631 vsi->stat_offsets_loaded,
632 &oes->tx_errors, &es->tx_errors);
633 i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
634 vsi->stat_offsets_loaded,
635 &oes->rx_discards, &es->rx_discards);
Shannon Nelson41a9e552014-04-23 04:50:20 +0000636 i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
637 vsi->stat_offsets_loaded,
638 &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
639 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
640 vsi->stat_offsets_loaded,
641 &oes->tx_errors, &es->tx_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000642
643 i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
644 I40E_GLV_GORCL(stat_idx),
645 vsi->stat_offsets_loaded,
646 &oes->rx_bytes, &es->rx_bytes);
647 i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
648 I40E_GLV_UPRCL(stat_idx),
649 vsi->stat_offsets_loaded,
650 &oes->rx_unicast, &es->rx_unicast);
651 i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
652 I40E_GLV_MPRCL(stat_idx),
653 vsi->stat_offsets_loaded,
654 &oes->rx_multicast, &es->rx_multicast);
655 i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
656 I40E_GLV_BPRCL(stat_idx),
657 vsi->stat_offsets_loaded,
658 &oes->rx_broadcast, &es->rx_broadcast);
659
660 i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
661 I40E_GLV_GOTCL(stat_idx),
662 vsi->stat_offsets_loaded,
663 &oes->tx_bytes, &es->tx_bytes);
664 i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
665 I40E_GLV_UPTCL(stat_idx),
666 vsi->stat_offsets_loaded,
667 &oes->tx_unicast, &es->tx_unicast);
668 i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
669 I40E_GLV_MPTCL(stat_idx),
670 vsi->stat_offsets_loaded,
671 &oes->tx_multicast, &es->tx_multicast);
672 i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
673 I40E_GLV_BPTCL(stat_idx),
674 vsi->stat_offsets_loaded,
675 &oes->tx_broadcast, &es->tx_broadcast);
676 vsi->stat_offsets_loaded = true;
677}
678
679/**
680 * i40e_update_veb_stats - Update Switch component statistics
681 * @veb: the VEB being updated
682 **/
683static void i40e_update_veb_stats(struct i40e_veb *veb)
684{
685 struct i40e_pf *pf = veb->pf;
686 struct i40e_hw *hw = &pf->hw;
687 struct i40e_eth_stats *oes;
688 struct i40e_eth_stats *es; /* device's eth stats */
Neerav Parikhfe860af2015-07-10 19:36:02 -0400689 struct i40e_veb_tc_stats *veb_oes;
690 struct i40e_veb_tc_stats *veb_es;
691 int i, idx = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000692
693 idx = veb->stats_idx;
694 es = &veb->stats;
695 oes = &veb->stats_offsets;
Neerav Parikhfe860af2015-07-10 19:36:02 -0400696 veb_es = &veb->tc_stats;
697 veb_oes = &veb->tc_stats_offsets;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000698
699 /* Gather up the stats that the hw collects */
700 i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
701 veb->stat_offsets_loaded,
702 &oes->tx_discards, &es->tx_discards);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000703 if (hw->revision_id > 0)
704 i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
705 veb->stat_offsets_loaded,
706 &oes->rx_unknown_protocol,
707 &es->rx_unknown_protocol);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000708 i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
709 veb->stat_offsets_loaded,
710 &oes->rx_bytes, &es->rx_bytes);
711 i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
712 veb->stat_offsets_loaded,
713 &oes->rx_unicast, &es->rx_unicast);
714 i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
715 veb->stat_offsets_loaded,
716 &oes->rx_multicast, &es->rx_multicast);
717 i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
718 veb->stat_offsets_loaded,
719 &oes->rx_broadcast, &es->rx_broadcast);
720
721 i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
722 veb->stat_offsets_loaded,
723 &oes->tx_bytes, &es->tx_bytes);
724 i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
725 veb->stat_offsets_loaded,
726 &oes->tx_unicast, &es->tx_unicast);
727 i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
728 veb->stat_offsets_loaded,
729 &oes->tx_multicast, &es->tx_multicast);
730 i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
731 veb->stat_offsets_loaded,
732 &oes->tx_broadcast, &es->tx_broadcast);
Neerav Parikhfe860af2015-07-10 19:36:02 -0400733 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
734 i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
735 I40E_GLVEBTC_RPCL(i, idx),
736 veb->stat_offsets_loaded,
737 &veb_oes->tc_rx_packets[i],
738 &veb_es->tc_rx_packets[i]);
739 i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
740 I40E_GLVEBTC_RBCL(i, idx),
741 veb->stat_offsets_loaded,
742 &veb_oes->tc_rx_bytes[i],
743 &veb_es->tc_rx_bytes[i]);
744 i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
745 I40E_GLVEBTC_TPCL(i, idx),
746 veb->stat_offsets_loaded,
747 &veb_oes->tc_tx_packets[i],
748 &veb_es->tc_tx_packets[i]);
749 i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
750 I40E_GLVEBTC_TBCL(i, idx),
751 veb->stat_offsets_loaded,
752 &veb_oes->tc_tx_bytes[i],
753 &veb_es->tc_tx_bytes[i]);
754 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000755 veb->stat_offsets_loaded = true;
756}
757
Vasu Dev38e00432014-08-01 13:27:03 -0700758#ifdef I40E_FCOE
759/**
760 * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
761 * @vsi: the VSI that is capable of doing FCoE
762 **/
763static void i40e_update_fcoe_stats(struct i40e_vsi *vsi)
764{
765 struct i40e_pf *pf = vsi->back;
766 struct i40e_hw *hw = &pf->hw;
767 struct i40e_fcoe_stats *ofs;
768 struct i40e_fcoe_stats *fs; /* device's eth stats */
769 int idx;
770
771 if (vsi->type != I40E_VSI_FCOE)
772 return;
773
774 idx = (pf->pf_seid - I40E_BASE_PF_SEID) + I40E_FCOE_PF_STAT_OFFSET;
775 fs = &vsi->fcoe_stats;
776 ofs = &vsi->fcoe_stats_offsets;
777
778 i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx),
779 vsi->fcoe_stat_offsets_loaded,
780 &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets);
781 i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx),
782 vsi->fcoe_stat_offsets_loaded,
783 &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords);
784 i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx),
785 vsi->fcoe_stat_offsets_loaded,
786 &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped);
787 i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx),
788 vsi->fcoe_stat_offsets_loaded,
789 &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets);
790 i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx),
791 vsi->fcoe_stat_offsets_loaded,
792 &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords);
793 i40e_stat_update32(hw, I40E_GL_FCOECRC(idx),
794 vsi->fcoe_stat_offsets_loaded,
795 &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc);
796 i40e_stat_update32(hw, I40E_GL_FCOELAST(idx),
797 vsi->fcoe_stat_offsets_loaded,
798 &ofs->fcoe_last_error, &fs->fcoe_last_error);
799 i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx),
800 vsi->fcoe_stat_offsets_loaded,
801 &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count);
802
803 vsi->fcoe_stat_offsets_loaded = true;
804}
805
806#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000807/**
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000808 * i40e_update_vsi_stats - Update the vsi statistics counters.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000809 * @vsi: the VSI to be updated
810 *
811 * There are a few instances where we store the same stat in a
812 * couple of different structs. This is partly because we have
813 * the netdev stats that need to be filled out, which is slightly
814 * different from the "eth_stats" defined by the chip and used in
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000815 * VF communications. We sort it out here.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000816 **/
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000817static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000818{
819 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000820 struct rtnl_link_stats64 *ons;
821 struct rtnl_link_stats64 *ns; /* netdev stats */
822 struct i40e_eth_stats *oes;
823 struct i40e_eth_stats *es; /* device's eth stats */
824 u32 tx_restart, tx_busy;
Akeem G Abodunrinbf00b372014-10-17 03:14:39 +0000825 struct i40e_ring *p;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000826 u32 rx_page, rx_buf;
Akeem G Abodunrinbf00b372014-10-17 03:14:39 +0000827 u64 bytes, packets;
828 unsigned int start;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400829 u64 tx_linearize;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400830 u64 tx_force_wb;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000831 u64 rx_p, rx_b;
832 u64 tx_p, tx_b;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000833 u16 q;
834
835 if (test_bit(__I40E_DOWN, &vsi->state) ||
836 test_bit(__I40E_CONFIG_BUSY, &pf->state))
837 return;
838
839 ns = i40e_get_vsi_stats_struct(vsi);
840 ons = &vsi->net_stats_offsets;
841 es = &vsi->eth_stats;
842 oes = &vsi->eth_stats_offsets;
843
844 /* Gather up the netdev and vsi stats that the driver collects
845 * on the fly during packet processing
846 */
847 rx_b = rx_p = 0;
848 tx_b = tx_p = 0;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400849 tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000850 rx_page = 0;
851 rx_buf = 0;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000852 rcu_read_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000853 for (q = 0; q < vsi->num_queue_pairs; q++) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000854 /* locate Tx ring */
855 p = ACCESS_ONCE(vsi->tx_rings[q]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000856
Alexander Duyck980e9b12013-09-28 06:01:03 +0000857 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700858 start = u64_stats_fetch_begin_irq(&p->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000859 packets = p->stats.packets;
860 bytes = p->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700861 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000862 tx_b += bytes;
863 tx_p += packets;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000864 tx_restart += p->tx_stats.restart_queue;
865 tx_busy += p->tx_stats.tx_busy;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400866 tx_linearize += p->tx_stats.tx_linearize;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400867 tx_force_wb += p->tx_stats.tx_force_wb;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000868
869 /* Rx queue is part of the same block as Tx queue */
870 p = &p[1];
871 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700872 start = u64_stats_fetch_begin_irq(&p->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000873 packets = p->stats.packets;
874 bytes = p->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700875 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000876 rx_b += bytes;
877 rx_p += packets;
Mitch Williams420136c2013-12-18 13:45:59 +0000878 rx_buf += p->rx_stats.alloc_buff_failed;
879 rx_page += p->rx_stats.alloc_page_failed;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000880 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000881 rcu_read_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000882 vsi->tx_restart = tx_restart;
883 vsi->tx_busy = tx_busy;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400884 vsi->tx_linearize = tx_linearize;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400885 vsi->tx_force_wb = tx_force_wb;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000886 vsi->rx_page_failed = rx_page;
887 vsi->rx_buf_failed = rx_buf;
888
889 ns->rx_packets = rx_p;
890 ns->rx_bytes = rx_b;
891 ns->tx_packets = tx_p;
892 ns->tx_bytes = tx_b;
893
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000894 /* update netdev stats from eth stats */
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000895 i40e_update_eth_stats(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000896 ons->tx_errors = oes->tx_errors;
897 ns->tx_errors = es->tx_errors;
898 ons->multicast = oes->rx_multicast;
899 ns->multicast = es->rx_multicast;
Shannon Nelson41a9e552014-04-23 04:50:20 +0000900 ons->rx_dropped = oes->rx_discards;
901 ns->rx_dropped = es->rx_discards;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000902 ons->tx_dropped = oes->tx_discards;
903 ns->tx_dropped = es->tx_discards;
904
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000905 /* pull in a couple PF stats if this is the main vsi */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000906 if (vsi == pf->vsi[pf->lan_vsi]) {
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000907 ns->rx_crc_errors = pf->stats.crc_errors;
908 ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
909 ns->rx_length_errors = pf->stats.rx_length_errors;
910 }
911}
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000912
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000913/**
Jeff Kirsherb40c82e2015-02-27 09:18:34 +0000914 * i40e_update_pf_stats - Update the PF statistics counters.
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000915 * @pf: the PF to be updated
916 **/
917static void i40e_update_pf_stats(struct i40e_pf *pf)
918{
919 struct i40e_hw_port_stats *osd = &pf->stats_offsets;
920 struct i40e_hw_port_stats *nsd = &pf->stats;
921 struct i40e_hw *hw = &pf->hw;
922 u32 val;
923 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000924
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000925 i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
926 I40E_GLPRT_GORCL(hw->port),
927 pf->stat_offsets_loaded,
928 &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
929 i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
930 I40E_GLPRT_GOTCL(hw->port),
931 pf->stat_offsets_loaded,
932 &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
933 i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
934 pf->stat_offsets_loaded,
935 &osd->eth.rx_discards,
936 &nsd->eth.rx_discards);
Shannon Nelson532d2832014-04-23 04:50:09 +0000937 i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
938 I40E_GLPRT_UPRCL(hw->port),
939 pf->stat_offsets_loaded,
940 &osd->eth.rx_unicast,
941 &nsd->eth.rx_unicast);
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000942 i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
943 I40E_GLPRT_MPRCL(hw->port),
944 pf->stat_offsets_loaded,
945 &osd->eth.rx_multicast,
946 &nsd->eth.rx_multicast);
Shannon Nelson532d2832014-04-23 04:50:09 +0000947 i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
948 I40E_GLPRT_BPRCL(hw->port),
949 pf->stat_offsets_loaded,
950 &osd->eth.rx_broadcast,
951 &nsd->eth.rx_broadcast);
952 i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
953 I40E_GLPRT_UPTCL(hw->port),
954 pf->stat_offsets_loaded,
955 &osd->eth.tx_unicast,
956 &nsd->eth.tx_unicast);
957 i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
958 I40E_GLPRT_MPTCL(hw->port),
959 pf->stat_offsets_loaded,
960 &osd->eth.tx_multicast,
961 &nsd->eth.tx_multicast);
962 i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
963 I40E_GLPRT_BPTCL(hw->port),
964 pf->stat_offsets_loaded,
965 &osd->eth.tx_broadcast,
966 &nsd->eth.tx_broadcast);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000967
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000968 i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
969 pf->stat_offsets_loaded,
970 &osd->tx_dropped_link_down,
971 &nsd->tx_dropped_link_down);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000972
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000973 i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
974 pf->stat_offsets_loaded,
975 &osd->crc_errors, &nsd->crc_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000976
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000977 i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
978 pf->stat_offsets_loaded,
979 &osd->illegal_bytes, &nsd->illegal_bytes);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000980
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000981 i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
982 pf->stat_offsets_loaded,
983 &osd->mac_local_faults,
984 &nsd->mac_local_faults);
985 i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
986 pf->stat_offsets_loaded,
987 &osd->mac_remote_faults,
988 &nsd->mac_remote_faults);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000989
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000990 i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
991 pf->stat_offsets_loaded,
992 &osd->rx_length_errors,
993 &nsd->rx_length_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000994
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000995 i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
996 pf->stat_offsets_loaded,
997 &osd->link_xon_rx, &nsd->link_xon_rx);
998 i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
999 pf->stat_offsets_loaded,
1000 &osd->link_xon_tx, &nsd->link_xon_tx);
Neerav Parikh95db2392015-11-06 15:26:09 -08001001 i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
1002 pf->stat_offsets_loaded,
1003 &osd->link_xoff_rx, &nsd->link_xoff_rx);
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001004 i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
1005 pf->stat_offsets_loaded,
1006 &osd->link_xoff_tx, &nsd->link_xoff_tx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001007
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001008 for (i = 0; i < 8; i++) {
Neerav Parikh95db2392015-11-06 15:26:09 -08001009 i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
1010 pf->stat_offsets_loaded,
1011 &osd->priority_xoff_rx[i],
1012 &nsd->priority_xoff_rx[i]);
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001013 i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001014 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001015 &osd->priority_xon_rx[i],
1016 &nsd->priority_xon_rx[i]);
1017 i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001018 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001019 &osd->priority_xon_tx[i],
1020 &nsd->priority_xon_tx[i]);
1021 i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001022 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001023 &osd->priority_xoff_tx[i],
1024 &nsd->priority_xoff_tx[i]);
1025 i40e_stat_update32(hw,
1026 I40E_GLPRT_RXON2OFFCNT(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001027 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001028 &osd->priority_xon_2_xoff[i],
1029 &nsd->priority_xon_2_xoff[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001030 }
1031
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001032 i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
1033 I40E_GLPRT_PRC64L(hw->port),
1034 pf->stat_offsets_loaded,
1035 &osd->rx_size_64, &nsd->rx_size_64);
1036 i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
1037 I40E_GLPRT_PRC127L(hw->port),
1038 pf->stat_offsets_loaded,
1039 &osd->rx_size_127, &nsd->rx_size_127);
1040 i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
1041 I40E_GLPRT_PRC255L(hw->port),
1042 pf->stat_offsets_loaded,
1043 &osd->rx_size_255, &nsd->rx_size_255);
1044 i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
1045 I40E_GLPRT_PRC511L(hw->port),
1046 pf->stat_offsets_loaded,
1047 &osd->rx_size_511, &nsd->rx_size_511);
1048 i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
1049 I40E_GLPRT_PRC1023L(hw->port),
1050 pf->stat_offsets_loaded,
1051 &osd->rx_size_1023, &nsd->rx_size_1023);
1052 i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
1053 I40E_GLPRT_PRC1522L(hw->port),
1054 pf->stat_offsets_loaded,
1055 &osd->rx_size_1522, &nsd->rx_size_1522);
1056 i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
1057 I40E_GLPRT_PRC9522L(hw->port),
1058 pf->stat_offsets_loaded,
1059 &osd->rx_size_big, &nsd->rx_size_big);
1060
1061 i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
1062 I40E_GLPRT_PTC64L(hw->port),
1063 pf->stat_offsets_loaded,
1064 &osd->tx_size_64, &nsd->tx_size_64);
1065 i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
1066 I40E_GLPRT_PTC127L(hw->port),
1067 pf->stat_offsets_loaded,
1068 &osd->tx_size_127, &nsd->tx_size_127);
1069 i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
1070 I40E_GLPRT_PTC255L(hw->port),
1071 pf->stat_offsets_loaded,
1072 &osd->tx_size_255, &nsd->tx_size_255);
1073 i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
1074 I40E_GLPRT_PTC511L(hw->port),
1075 pf->stat_offsets_loaded,
1076 &osd->tx_size_511, &nsd->tx_size_511);
1077 i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
1078 I40E_GLPRT_PTC1023L(hw->port),
1079 pf->stat_offsets_loaded,
1080 &osd->tx_size_1023, &nsd->tx_size_1023);
1081 i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
1082 I40E_GLPRT_PTC1522L(hw->port),
1083 pf->stat_offsets_loaded,
1084 &osd->tx_size_1522, &nsd->tx_size_1522);
1085 i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
1086 I40E_GLPRT_PTC9522L(hw->port),
1087 pf->stat_offsets_loaded,
1088 &osd->tx_size_big, &nsd->tx_size_big);
1089
1090 i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
1091 pf->stat_offsets_loaded,
1092 &osd->rx_undersize, &nsd->rx_undersize);
1093 i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
1094 pf->stat_offsets_loaded,
1095 &osd->rx_fragments, &nsd->rx_fragments);
1096 i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
1097 pf->stat_offsets_loaded,
1098 &osd->rx_oversize, &nsd->rx_oversize);
1099 i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
1100 pf->stat_offsets_loaded,
1101 &osd->rx_jabber, &nsd->rx_jabber);
1102
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001103 /* FDIR stats */
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04001104 i40e_stat_update32(hw,
1105 I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001106 pf->stat_offsets_loaded,
1107 &osd->fd_atr_match, &nsd->fd_atr_match);
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04001108 i40e_stat_update32(hw,
1109 I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001110 pf->stat_offsets_loaded,
1111 &osd->fd_sb_match, &nsd->fd_sb_match);
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -04001112 i40e_stat_update32(hw,
1113 I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)),
1114 pf->stat_offsets_loaded,
1115 &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match);
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001116
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001117 val = rd32(hw, I40E_PRTPM_EEE_STAT);
1118 nsd->tx_lpi_status =
1119 (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
1120 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
1121 nsd->rx_lpi_status =
1122 (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
1123 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
1124 i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
1125 pf->stat_offsets_loaded,
1126 &osd->tx_lpi_count, &nsd->tx_lpi_count);
1127 i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
1128 pf->stat_offsets_loaded,
1129 &osd->rx_lpi_count, &nsd->rx_lpi_count);
1130
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -04001131 if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
1132 !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED))
1133 nsd->fd_sb_status = true;
1134 else
1135 nsd->fd_sb_status = false;
1136
1137 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
1138 !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
1139 nsd->fd_atr_status = true;
1140 else
1141 nsd->fd_atr_status = false;
1142
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001143 pf->stat_offsets_loaded = true;
1144}
1145
1146/**
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001147 * i40e_update_stats - Update the various statistics counters.
1148 * @vsi: the VSI to be updated
1149 *
1150 * Update the various stats for this VSI and its related entities.
1151 **/
1152void i40e_update_stats(struct i40e_vsi *vsi)
1153{
1154 struct i40e_pf *pf = vsi->back;
1155
1156 if (vsi == pf->vsi[pf->lan_vsi])
1157 i40e_update_pf_stats(pf);
1158
1159 i40e_update_vsi_stats(vsi);
Vasu Dev38e00432014-08-01 13:27:03 -07001160#ifdef I40E_FCOE
1161 i40e_update_fcoe_stats(vsi);
1162#endif
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001163}
1164
1165/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001166 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1167 * @vsi: the VSI to be searched
1168 * @macaddr: the MAC address
1169 * @vlan: the vlan
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001170 * @is_vf: make sure its a VF filter, else doesn't matter
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001171 * @is_netdev: make sure its a netdev filter, else doesn't matter
1172 *
1173 * Returns ptr to the filter object or NULL
1174 **/
1175static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
1176 u8 *macaddr, s16 vlan,
1177 bool is_vf, bool is_netdev)
1178{
1179 struct i40e_mac_filter *f;
1180
1181 if (!vsi || !macaddr)
1182 return NULL;
1183
1184 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1185 if ((ether_addr_equal(macaddr, f->macaddr)) &&
1186 (vlan == f->vlan) &&
1187 (!is_vf || f->is_vf) &&
1188 (!is_netdev || f->is_netdev))
1189 return f;
1190 }
1191 return NULL;
1192}
1193
1194/**
1195 * i40e_find_mac - Find a mac addr in the macvlan filters list
1196 * @vsi: the VSI to be searched
1197 * @macaddr: the MAC address we are searching for
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001198 * @is_vf: make sure its a VF filter, else doesn't matter
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001199 * @is_netdev: make sure its a netdev filter, else doesn't matter
1200 *
1201 * Returns the first filter with the provided MAC address or NULL if
1202 * MAC address was not found
1203 **/
1204struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr,
1205 bool is_vf, bool is_netdev)
1206{
1207 struct i40e_mac_filter *f;
1208
1209 if (!vsi || !macaddr)
1210 return NULL;
1211
1212 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1213 if ((ether_addr_equal(macaddr, f->macaddr)) &&
1214 (!is_vf || f->is_vf) &&
1215 (!is_netdev || f->is_netdev))
1216 return f;
1217 }
1218 return NULL;
1219}
1220
1221/**
1222 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1223 * @vsi: the VSI to be searched
1224 *
1225 * Returns true if VSI is in vlan mode or false otherwise
1226 **/
1227bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
1228{
1229 struct i40e_mac_filter *f;
1230
1231 /* Only -1 for all the filters denotes not in vlan mode
1232 * so we have to go through all the list in order to make sure
1233 */
1234 list_for_each_entry(f, &vsi->mac_filter_list, list) {
Greg Rosed9b68f82015-07-23 16:54:31 -04001235 if (f->vlan >= 0 || vsi->info.pvid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001236 return true;
1237 }
1238
1239 return false;
1240}
1241
1242/**
1243 * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
1244 * @vsi: the VSI to be searched
1245 * @macaddr: the mac address to be filtered
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001246 * @is_vf: true if it is a VF
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001247 * @is_netdev: true if it is a netdev
1248 *
1249 * Goes through all the macvlan filters and adds a
1250 * macvlan filter for each unique vlan that already exists
1251 *
1252 * Returns first filter found on success, else NULL
1253 **/
1254struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr,
1255 bool is_vf, bool is_netdev)
1256{
1257 struct i40e_mac_filter *f;
1258
1259 list_for_each_entry(f, &vsi->mac_filter_list, list) {
Mitch Williamsecbb44e2015-07-10 19:35:56 -04001260 if (vsi->info.pvid)
1261 f->vlan = le16_to_cpu(vsi->info.pvid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001262 if (!i40e_find_filter(vsi, macaddr, f->vlan,
1263 is_vf, is_netdev)) {
1264 if (!i40e_add_filter(vsi, macaddr, f->vlan,
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08001265 is_vf, is_netdev))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001266 return NULL;
1267 }
1268 }
1269
1270 return list_first_entry_or_null(&vsi->mac_filter_list,
1271 struct i40e_mac_filter, list);
1272}
1273
1274/**
Mitch Williamsb36e9ab2015-11-19 11:34:16 -08001275 * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS
1276 * @vsi: the VSI to be searched
1277 * @macaddr: the mac address to be removed
1278 * @is_vf: true if it is a VF
1279 * @is_netdev: true if it is a netdev
1280 *
1281 * Removes a given MAC address from a VSI, regardless of VLAN
1282 *
1283 * Returns 0 for success, or error
1284 **/
1285int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, u8 *macaddr,
1286 bool is_vf, bool is_netdev)
1287{
1288 struct i40e_mac_filter *f = NULL;
1289 int changed = 0;
1290
1291 WARN(!spin_is_locked(&vsi->mac_filter_list_lock),
1292 "Missing mac_filter_list_lock\n");
1293 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1294 if ((ether_addr_equal(macaddr, f->macaddr)) &&
1295 (is_vf == f->is_vf) &&
1296 (is_netdev == f->is_netdev)) {
1297 f->counter--;
1298 f->changed = true;
1299 changed = 1;
1300 }
1301 }
1302 if (changed) {
1303 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1304 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1305 return 0;
1306 }
1307 return -ENOENT;
1308}
1309
1310/**
Greg Rose8c27d422014-05-22 06:31:56 +00001311 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1312 * @vsi: the PF Main VSI - inappropriate for any other VSI
1313 * @macaddr: the MAC address
Shannon Nelson30650cc2014-07-29 04:01:50 +00001314 *
1315 * Some older firmware configurations set up a default promiscuous VLAN
1316 * filter that needs to be removed.
Greg Rose8c27d422014-05-22 06:31:56 +00001317 **/
Shannon Nelson30650cc2014-07-29 04:01:50 +00001318static int i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
Greg Rose8c27d422014-05-22 06:31:56 +00001319{
1320 struct i40e_aqc_remove_macvlan_element_data element;
1321 struct i40e_pf *pf = vsi->back;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001322 i40e_status ret;
Greg Rose8c27d422014-05-22 06:31:56 +00001323
1324 /* Only appropriate for the PF main VSI */
1325 if (vsi->type != I40E_VSI_MAIN)
Shannon Nelson30650cc2014-07-29 04:01:50 +00001326 return -EINVAL;
Greg Rose8c27d422014-05-22 06:31:56 +00001327
Shannon Nelson30650cc2014-07-29 04:01:50 +00001328 memset(&element, 0, sizeof(element));
Greg Rose8c27d422014-05-22 06:31:56 +00001329 ether_addr_copy(element.mac_addr, macaddr);
1330 element.vlan_tag = 0;
1331 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
1332 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001333 ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1334 if (ret)
Shannon Nelson30650cc2014-07-29 04:01:50 +00001335 return -ENOENT;
1336
1337 return 0;
Greg Rose8c27d422014-05-22 06:31:56 +00001338}
1339
1340/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001341 * i40e_add_filter - Add a mac/vlan filter to the VSI
1342 * @vsi: the VSI to be searched
1343 * @macaddr: the MAC address
1344 * @vlan: the vlan
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001345 * @is_vf: make sure its a VF filter, else doesn't matter
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001346 * @is_netdev: make sure its a netdev filter, else doesn't matter
1347 *
1348 * Returns ptr to the filter object or NULL when no memory available.
Kiran Patil21659032015-09-30 14:09:03 -04001349 *
1350 * NOTE: This function is expected to be called with mac_filter_list_lock
1351 * being held.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001352 **/
1353struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
1354 u8 *macaddr, s16 vlan,
1355 bool is_vf, bool is_netdev)
1356{
1357 struct i40e_mac_filter *f;
1358
1359 if (!vsi || !macaddr)
1360 return NULL;
1361
1362 f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
1363 if (!f) {
1364 f = kzalloc(sizeof(*f), GFP_ATOMIC);
1365 if (!f)
1366 goto add_filter_out;
1367
Greg Rose9a173902014-05-22 06:32:02 +00001368 ether_addr_copy(f->macaddr, macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001369 f->vlan = vlan;
1370 f->changed = true;
1371
1372 INIT_LIST_HEAD(&f->list);
Kiran Patil04d5a212015-12-09 15:50:23 -08001373 list_add_tail(&f->list, &vsi->mac_filter_list);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001374 }
1375
1376 /* increment counter and add a new flag if needed */
1377 if (is_vf) {
1378 if (!f->is_vf) {
1379 f->is_vf = true;
1380 f->counter++;
1381 }
1382 } else if (is_netdev) {
1383 if (!f->is_netdev) {
1384 f->is_netdev = true;
1385 f->counter++;
1386 }
1387 } else {
1388 f->counter++;
1389 }
1390
1391 /* changed tells sync_filters_subtask to
1392 * push the filter down to the firmware
1393 */
1394 if (f->changed) {
1395 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1396 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1397 }
1398
1399add_filter_out:
1400 return f;
1401}
1402
1403/**
1404 * i40e_del_filter - Remove a mac/vlan filter from the VSI
1405 * @vsi: the VSI to be searched
1406 * @macaddr: the MAC address
1407 * @vlan: the vlan
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001408 * @is_vf: make sure it's a VF filter, else doesn't matter
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001409 * @is_netdev: make sure it's a netdev filter, else doesn't matter
Kiran Patil21659032015-09-30 14:09:03 -04001410 *
1411 * NOTE: This function is expected to be called with mac_filter_list_lock
1412 * being held.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001413 **/
1414void i40e_del_filter(struct i40e_vsi *vsi,
1415 u8 *macaddr, s16 vlan,
1416 bool is_vf, bool is_netdev)
1417{
1418 struct i40e_mac_filter *f;
1419
1420 if (!vsi || !macaddr)
1421 return;
1422
1423 f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
1424 if (!f || f->counter == 0)
1425 return;
1426
1427 if (is_vf) {
1428 if (f->is_vf) {
1429 f->is_vf = false;
1430 f->counter--;
1431 }
1432 } else if (is_netdev) {
1433 if (f->is_netdev) {
1434 f->is_netdev = false;
1435 f->counter--;
1436 }
1437 } else {
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00001438 /* make sure we don't remove a filter in use by VF or netdev */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001439 int min_f = 0;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001440
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001441 min_f += (f->is_vf ? 1 : 0);
1442 min_f += (f->is_netdev ? 1 : 0);
1443
1444 if (f->counter > min_f)
1445 f->counter--;
1446 }
1447
1448 /* counter == 0 tells sync_filters_subtask to
1449 * remove the filter from the firmware's list
1450 */
1451 if (f->counter == 0) {
1452 f->changed = true;
1453 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1454 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1455 }
1456}
1457
1458/**
1459 * i40e_set_mac - NDO callback to set mac address
1460 * @netdev: network interface device structure
1461 * @p: pointer to an address structure
1462 *
1463 * Returns 0 on success, negative on failure
1464 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001465#ifdef I40E_FCOE
1466int i40e_set_mac(struct net_device *netdev, void *p)
1467#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001468static int i40e_set_mac(struct net_device *netdev, void *p)
Vasu Dev38e00432014-08-01 13:27:03 -07001469#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001470{
1471 struct i40e_netdev_priv *np = netdev_priv(netdev);
1472 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson30650cc2014-07-29 04:01:50 +00001473 struct i40e_pf *pf = vsi->back;
1474 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001475 struct sockaddr *addr = p;
1476 struct i40e_mac_filter *f;
1477
1478 if (!is_valid_ether_addr(addr->sa_data))
1479 return -EADDRNOTAVAIL;
1480
Shannon Nelson30650cc2014-07-29 04:01:50 +00001481 if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
1482 netdev_info(netdev, "already using mac address %pM\n",
1483 addr->sa_data);
1484 return 0;
1485 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001486
Anjali Singhai Jain80f64282013-11-28 06:39:47 +00001487 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
1488 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
1489 return -EADDRNOTAVAIL;
1490
Shannon Nelson30650cc2014-07-29 04:01:50 +00001491 if (ether_addr_equal(hw->mac.addr, addr->sa_data))
1492 netdev_info(netdev, "returning to hw mac address %pM\n",
1493 hw->mac.addr);
1494 else
1495 netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
1496
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001497 if (vsi->type == I40E_VSI_MAIN) {
1498 i40e_status ret;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001499
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001500 ret = i40e_aq_mac_address_write(&vsi->back->hw,
Shannon Nelsoncc412222014-06-04 01:23:21 +00001501 I40E_AQC_WRITE_TYPE_LAA_WOL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001502 addr->sa_data, NULL);
1503 if (ret) {
1504 netdev_info(netdev,
1505 "Addr change for Main VSI failed: %d\n",
1506 ret);
1507 return -EADDRNOTAVAIL;
1508 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001509 }
1510
Shannon Nelson30650cc2014-07-29 04:01:50 +00001511 if (ether_addr_equal(netdev->dev_addr, hw->mac.addr)) {
1512 struct i40e_aqc_remove_macvlan_element_data element;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001513
Shannon Nelson30650cc2014-07-29 04:01:50 +00001514 memset(&element, 0, sizeof(element));
1515 ether_addr_copy(element.mac_addr, netdev->dev_addr);
1516 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
1517 i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1518 } else {
Kiran Patil21659032015-09-30 14:09:03 -04001519 spin_lock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson6c8ad1b2014-06-04 01:23:22 +00001520 i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
1521 false, false);
Kiran Patil21659032015-09-30 14:09:03 -04001522 spin_unlock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson6c8ad1b2014-06-04 01:23:22 +00001523 }
1524
Shannon Nelson30650cc2014-07-29 04:01:50 +00001525 if (ether_addr_equal(addr->sa_data, hw->mac.addr)) {
1526 struct i40e_aqc_add_macvlan_element_data element;
1527
1528 memset(&element, 0, sizeof(element));
1529 ether_addr_copy(element.mac_addr, hw->mac.addr);
1530 element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
1531 i40e_aq_add_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1532 } else {
Kiran Patil21659032015-09-30 14:09:03 -04001533 spin_lock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson30650cc2014-07-29 04:01:50 +00001534 f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY,
1535 false, false);
1536 if (f)
1537 f->is_laa = true;
Kiran Patil21659032015-09-30 14:09:03 -04001538 spin_unlock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson30650cc2014-07-29 04:01:50 +00001539 }
1540
Shannon Nelson30650cc2014-07-29 04:01:50 +00001541 ether_addr_copy(netdev->dev_addr, addr->sa_data);
Mitch Williamsea02e902015-11-09 15:35:50 -08001542
1543 return i40e_sync_vsi_filters(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001544}
1545
1546/**
1547 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1548 * @vsi: the VSI being setup
1549 * @ctxt: VSI context structure
1550 * @enabled_tc: Enabled TCs bitmap
1551 * @is_add: True if called before Add VSI
1552 *
1553 * Setup VSI queue mapping for enabled traffic classes.
1554 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001555#ifdef I40E_FCOE
1556void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1557 struct i40e_vsi_context *ctxt,
1558 u8 enabled_tc,
1559 bool is_add)
1560#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001561static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1562 struct i40e_vsi_context *ctxt,
1563 u8 enabled_tc,
1564 bool is_add)
Vasu Dev38e00432014-08-01 13:27:03 -07001565#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001566{
1567 struct i40e_pf *pf = vsi->back;
1568 u16 sections = 0;
1569 u8 netdev_tc = 0;
1570 u16 numtc = 0;
1571 u16 qcount;
1572 u8 offset;
1573 u16 qmap;
1574 int i;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001575 u16 num_tc_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001576
1577 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
1578 offset = 0;
1579
1580 if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
1581 /* Find numtc from enabled TC bitmap */
1582 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08001583 if (enabled_tc & BIT(i)) /* TC is enabled */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001584 numtc++;
1585 }
1586 if (!numtc) {
1587 dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
1588 numtc = 1;
1589 }
1590 } else {
1591 /* At least TC0 is enabled in case of non-DCB case */
1592 numtc = 1;
1593 }
1594
1595 vsi->tc_config.numtc = numtc;
1596 vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001597 /* Number of queues per enabled TC */
Anjali Singhai7f9ff472015-02-21 06:43:19 +00001598 /* In MFP case we can have a much lower count of MSIx
1599 * vectors available and so we need to lower the used
1600 * q count.
1601 */
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04001602 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
1603 qcount = min_t(int, vsi->alloc_queue_pairs, pf->num_lan_msix);
1604 else
1605 qcount = vsi->alloc_queue_pairs;
Anjali Singhai7f9ff472015-02-21 06:43:19 +00001606 num_tc_qps = qcount / numtc;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04001607 num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001608
1609 /* Setup queue offset/count for all TCs for given VSI */
1610 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1611 /* See if the given TC is enabled for the given VSI */
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08001612 if (vsi->tc_config.enabled_tc & BIT(i)) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001613 /* TC is enabled */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001614 int pow, num_qps;
1615
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001616 switch (vsi->type) {
1617 case I40E_VSI_MAIN:
Helin Zhangacd65442015-10-26 19:44:28 -04001618 qcount = min_t(int, pf->alloc_rss_size,
1619 num_tc_qps);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001620 break;
Vasu Dev38e00432014-08-01 13:27:03 -07001621#ifdef I40E_FCOE
1622 case I40E_VSI_FCOE:
1623 qcount = num_tc_qps;
1624 break;
1625#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001626 case I40E_VSI_FDIR:
1627 case I40E_VSI_SRIOV:
1628 case I40E_VSI_VMDQ2:
1629 default:
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001630 qcount = num_tc_qps;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001631 WARN_ON(i != 0);
1632 break;
1633 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001634 vsi->tc_config.tc_info[i].qoffset = offset;
1635 vsi->tc_config.tc_info[i].qcount = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001636
Shannon Nelson1e200e42015-02-27 09:15:24 +00001637 /* find the next higher power-of-2 of num queue pairs */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001638 num_qps = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001639 pow = 0;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001640 while (num_qps && (BIT_ULL(pow) < qcount)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001641 pow++;
1642 num_qps >>= 1;
1643 }
1644
1645 vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
1646 qmap =
1647 (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
1648 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
1649
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001650 offset += qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001651 } else {
1652 /* TC is not enabled so set the offset to
1653 * default queue and allocate one queue
1654 * for the given TC.
1655 */
1656 vsi->tc_config.tc_info[i].qoffset = 0;
1657 vsi->tc_config.tc_info[i].qcount = 1;
1658 vsi->tc_config.tc_info[i].netdev_tc = 0;
1659
1660 qmap = 0;
1661 }
1662 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
1663 }
1664
1665 /* Set actual Tx/Rx queue pairs */
1666 vsi->num_queue_pairs = offset;
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00001667 if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
1668 if (vsi->req_queue_pairs > 0)
1669 vsi->num_queue_pairs = vsi->req_queue_pairs;
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04001670 else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00001671 vsi->num_queue_pairs = pf->num_lan_msix;
1672 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001673
1674 /* Scheduler section valid can only be set for ADD VSI */
1675 if (is_add) {
1676 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
1677
1678 ctxt->info.up_enable_bits = enabled_tc;
1679 }
1680 if (vsi->type == I40E_VSI_SRIOV) {
1681 ctxt->info.mapping_flags |=
1682 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
1683 for (i = 0; i < vsi->num_queue_pairs; i++)
1684 ctxt->info.queue_mapping[i] =
1685 cpu_to_le16(vsi->base_queue + i);
1686 } else {
1687 ctxt->info.mapping_flags |=
1688 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
1689 ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
1690 }
1691 ctxt->info.valid_sections |= cpu_to_le16(sections);
1692}
1693
1694/**
1695 * i40e_set_rx_mode - NDO callback to set the netdev filters
1696 * @netdev: network interface device structure
1697 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001698#ifdef I40E_FCOE
1699void i40e_set_rx_mode(struct net_device *netdev)
1700#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001701static void i40e_set_rx_mode(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -07001702#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001703{
1704 struct i40e_netdev_priv *np = netdev_priv(netdev);
1705 struct i40e_mac_filter *f, *ftmp;
1706 struct i40e_vsi *vsi = np->vsi;
1707 struct netdev_hw_addr *uca;
1708 struct netdev_hw_addr *mca;
1709 struct netdev_hw_addr *ha;
1710
Kiran Patil21659032015-09-30 14:09:03 -04001711 spin_lock_bh(&vsi->mac_filter_list_lock);
1712
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001713 /* add addr if not already in the filter list */
1714 netdev_for_each_uc_addr(uca, netdev) {
1715 if (!i40e_find_mac(vsi, uca->addr, false, true)) {
1716 if (i40e_is_vsi_in_vlan(vsi))
1717 i40e_put_mac_in_vlan(vsi, uca->addr,
1718 false, true);
1719 else
1720 i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY,
1721 false, true);
1722 }
1723 }
1724
1725 netdev_for_each_mc_addr(mca, netdev) {
1726 if (!i40e_find_mac(vsi, mca->addr, false, true)) {
1727 if (i40e_is_vsi_in_vlan(vsi))
1728 i40e_put_mac_in_vlan(vsi, mca->addr,
1729 false, true);
1730 else
1731 i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY,
1732 false, true);
1733 }
1734 }
1735
1736 /* remove filter if not in netdev list */
1737 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001738
1739 if (!f->is_netdev)
1740 continue;
1741
Shannon Nelson2f41f332015-08-26 15:14:20 -04001742 netdev_for_each_mc_addr(mca, netdev)
1743 if (ether_addr_equal(mca->addr, f->macaddr))
1744 goto bottom_of_search_loop;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001745
Shannon Nelson2f41f332015-08-26 15:14:20 -04001746 netdev_for_each_uc_addr(uca, netdev)
1747 if (ether_addr_equal(uca->addr, f->macaddr))
1748 goto bottom_of_search_loop;
1749
1750 for_each_dev_addr(netdev, ha)
1751 if (ether_addr_equal(ha->addr, f->macaddr))
1752 goto bottom_of_search_loop;
1753
1754 /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
1755 i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true);
1756
1757bottom_of_search_loop:
1758 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001759 }
Kiran Patil21659032015-09-30 14:09:03 -04001760 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001761
1762 /* check for other flag changes */
1763 if (vsi->current_netdev_flags != vsi->netdev->flags) {
1764 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1765 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1766 }
1767}
1768
1769/**
Kiran Patil21659032015-09-30 14:09:03 -04001770 * i40e_mac_filter_entry_clone - Clones a MAC filter entry
1771 * @src: source MAC filter entry to be clones
1772 *
1773 * Returns the pointer to newly cloned MAC filter entry or NULL
1774 * in case of error
1775 **/
1776static struct i40e_mac_filter *i40e_mac_filter_entry_clone(
1777 struct i40e_mac_filter *src)
1778{
1779 struct i40e_mac_filter *f;
1780
1781 f = kzalloc(sizeof(*f), GFP_ATOMIC);
1782 if (!f)
1783 return NULL;
1784 *f = *src;
1785
1786 INIT_LIST_HEAD(&f->list);
1787
1788 return f;
1789}
1790
1791/**
1792 * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
1793 * @vsi: pointer to vsi struct
1794 * @from: Pointer to list which contains MAC filter entries - changes to
1795 * those entries needs to be undone.
1796 *
1797 * MAC filter entries from list were slated to be removed from device.
1798 **/
1799static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
1800 struct list_head *from)
1801{
1802 struct i40e_mac_filter *f, *ftmp;
1803
1804 list_for_each_entry_safe(f, ftmp, from, list) {
1805 f->changed = true;
1806 /* Move the element back into MAC filter list*/
1807 list_move_tail(&f->list, &vsi->mac_filter_list);
1808 }
1809}
1810
1811/**
1812 * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
1813 * @vsi: pointer to vsi struct
1814 *
1815 * MAC filter entries from list were slated to be added from device.
1816 **/
1817static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi)
1818{
1819 struct i40e_mac_filter *f, *ftmp;
1820
1821 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1822 if (!f->changed && f->counter)
1823 f->changed = true;
1824 }
1825}
1826
1827/**
1828 * i40e_cleanup_add_list - Deletes the element from add list and release
1829 * memory
1830 * @add_list: Pointer to list which contains MAC filter entries
1831 **/
1832static void i40e_cleanup_add_list(struct list_head *add_list)
1833{
1834 struct i40e_mac_filter *f, *ftmp;
1835
1836 list_for_each_entry_safe(f, ftmp, add_list, list) {
1837 list_del(&f->list);
1838 kfree(f);
1839 }
1840}
1841
1842/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001843 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1844 * @vsi: ptr to the VSI
1845 *
1846 * Push any outstanding VSI filter changes through the AdminQ.
1847 *
1848 * Returns 0 or error value
1849 **/
Jesse Brandeburg17652c62015-11-05 17:01:02 -08001850int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001851{
Kiran Patil21659032015-09-30 14:09:03 -04001852 struct list_head tmp_del_list, tmp_add_list;
1853 struct i40e_mac_filter *f, *ftmp, *fclone;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001854 bool promisc_forced_on = false;
1855 bool add_happened = false;
1856 int filter_list_len = 0;
1857 u32 changed_flags = 0;
Mitch Williamsea02e902015-11-09 15:35:50 -08001858 i40e_status aq_ret = 0;
Kiran Patil21659032015-09-30 14:09:03 -04001859 bool err_cond = false;
Mitch Williamsea02e902015-11-09 15:35:50 -08001860 int retval = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001861 struct i40e_pf *pf;
1862 int num_add = 0;
1863 int num_del = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001864 int aq_err = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001865 u16 cmd_flags;
1866
1867 /* empty array typed pointers, kcalloc later */
1868 struct i40e_aqc_add_macvlan_element_data *add_list;
1869 struct i40e_aqc_remove_macvlan_element_data *del_list;
1870
1871 while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
1872 usleep_range(1000, 2000);
1873 pf = vsi->back;
1874
1875 if (vsi->netdev) {
1876 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
1877 vsi->current_netdev_flags = vsi->netdev->flags;
1878 }
1879
Kiran Patil21659032015-09-30 14:09:03 -04001880 INIT_LIST_HEAD(&tmp_del_list);
1881 INIT_LIST_HEAD(&tmp_add_list);
1882
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001883 if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
1884 vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
1885
Kiran Patil21659032015-09-30 14:09:03 -04001886 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001887 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1888 if (!f->changed)
1889 continue;
1890
1891 if (f->counter != 0)
1892 continue;
1893 f->changed = false;
Kiran Patil21659032015-09-30 14:09:03 -04001894
1895 /* Move the element into temporary del_list */
1896 list_move_tail(&f->list, &tmp_del_list);
1897 }
1898
1899 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1900 if (!f->changed)
1901 continue;
1902
1903 if (f->counter == 0)
1904 continue;
1905 f->changed = false;
1906
1907 /* Clone MAC filter entry and add into temporary list */
1908 fclone = i40e_mac_filter_entry_clone(f);
1909 if (!fclone) {
1910 err_cond = true;
1911 break;
1912 }
1913 list_add_tail(&fclone->list, &tmp_add_list);
1914 }
1915
1916 /* if failed to clone MAC filter entry - undo */
1917 if (err_cond) {
1918 i40e_undo_del_filter_entries(vsi, &tmp_del_list);
1919 i40e_undo_add_filter_entries(vsi);
1920 }
1921 spin_unlock_bh(&vsi->mac_filter_list_lock);
1922
Mitch Williamsea02e902015-11-09 15:35:50 -08001923 if (err_cond) {
Kiran Patil21659032015-09-30 14:09:03 -04001924 i40e_cleanup_add_list(&tmp_add_list);
Mitch Williamsea02e902015-11-09 15:35:50 -08001925 retval = -ENOMEM;
1926 goto out;
1927 }
Kiran Patil21659032015-09-30 14:09:03 -04001928 }
1929
1930 /* Now process 'del_list' outside the lock */
1931 if (!list_empty(&tmp_del_list)) {
Shannon Nelsonf1199992015-11-19 11:34:23 -08001932 int del_list_size;
1933
Kiran Patil21659032015-09-30 14:09:03 -04001934 filter_list_len = pf->hw.aq.asq_buf_size /
1935 sizeof(struct i40e_aqc_remove_macvlan_element_data);
Shannon Nelsonf1199992015-11-19 11:34:23 -08001936 del_list_size = filter_list_len *
1937 sizeof(struct i40e_aqc_remove_macvlan_element_data);
1938 del_list = kzalloc(del_list_size, GFP_KERNEL);
Kiran Patil21659032015-09-30 14:09:03 -04001939 if (!del_list) {
1940 i40e_cleanup_add_list(&tmp_add_list);
1941
1942 /* Undo VSI's MAC filter entry element updates */
1943 spin_lock_bh(&vsi->mac_filter_list_lock);
1944 i40e_undo_del_filter_entries(vsi, &tmp_del_list);
1945 i40e_undo_add_filter_entries(vsi);
1946 spin_unlock_bh(&vsi->mac_filter_list_lock);
Mitch Williamsea02e902015-11-09 15:35:50 -08001947 retval = -ENOMEM;
1948 goto out;
Kiran Patil21659032015-09-30 14:09:03 -04001949 }
1950
1951 list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001952 cmd_flags = 0;
1953
1954 /* add to delete list */
Greg Rose9a173902014-05-22 06:32:02 +00001955 ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001956 del_list[num_del].vlan_tag =
1957 cpu_to_le16((u16)(f->vlan ==
1958 I40E_VLAN_ANY ? 0 : f->vlan));
1959
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001960 cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
1961 del_list[num_del].flags = cmd_flags;
1962 num_del++;
1963
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001964 /* flush a full buffer */
1965 if (num_del == filter_list_len) {
Mitch Williamsea02e902015-11-09 15:35:50 -08001966 aq_ret = i40e_aq_remove_macvlan(&pf->hw,
1967 vsi->seid,
1968 del_list,
1969 num_del,
1970 NULL);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001971 aq_err = pf->hw.aq.asq_last_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001972 num_del = 0;
Shannon Nelsonf1199992015-11-19 11:34:23 -08001973 memset(del_list, 0, del_list_size);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001974
Mitch Williamsea02e902015-11-09 15:35:50 -08001975 if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) {
1976 retval = -EIO;
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",
Mitch Williamsea02e902015-11-09 15:35:50 -08001979 i40e_stat_str(&pf->hw, aq_ret),
Kiran Patil21659032015-09-30 14:09:03 -04001980 i40e_aq_str(&pf->hw, aq_err));
Mitch Williamsea02e902015-11-09 15:35:50 -08001981 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001982 }
Kiran Patil21659032015-09-30 14:09:03 -04001983 /* Release memory for MAC filter entries which were
1984 * synced up with HW.
1985 */
1986 list_del(&f->list);
1987 kfree(f);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001988 }
Kiran Patil21659032015-09-30 14:09:03 -04001989
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001990 if (num_del) {
Mitch Williamsea02e902015-11-09 15:35:50 -08001991 aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid,
1992 del_list, num_del,
1993 NULL);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001994 aq_err = pf->hw.aq.asq_last_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001995 num_del = 0;
1996
Mitch Williamsea02e902015-11-09 15:35:50 -08001997 if (aq_ret && aq_err != I40E_AQ_RC_ENOENT)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001998 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001999 "ignoring delete macvlan error, err %s aq_err %s\n",
Mitch Williamsea02e902015-11-09 15:35:50 -08002000 i40e_stat_str(&pf->hw, aq_ret),
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002001 i40e_aq_str(&pf->hw, aq_err));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002002 }
2003
2004 kfree(del_list);
2005 del_list = NULL;
Kiran Patil21659032015-09-30 14:09:03 -04002006 }
2007
2008 if (!list_empty(&tmp_add_list)) {
Shannon Nelsonf1199992015-11-19 11:34:23 -08002009 int add_list_size;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002010
2011 /* do all the adds now */
2012 filter_list_len = pf->hw.aq.asq_buf_size /
2013 sizeof(struct i40e_aqc_add_macvlan_element_data),
Shannon Nelsonf1199992015-11-19 11:34:23 -08002014 add_list_size = filter_list_len *
2015 sizeof(struct i40e_aqc_add_macvlan_element_data);
2016 add_list = kzalloc(add_list_size, GFP_KERNEL);
Kiran Patil21659032015-09-30 14:09:03 -04002017 if (!add_list) {
2018 /* Purge element from temporary lists */
2019 i40e_cleanup_add_list(&tmp_add_list);
2020
2021 /* Undo add filter entries from VSI MAC filter list */
2022 spin_lock_bh(&vsi->mac_filter_list_lock);
2023 i40e_undo_add_filter_entries(vsi);
2024 spin_unlock_bh(&vsi->mac_filter_list_lock);
Mitch Williamsea02e902015-11-09 15:35:50 -08002025 retval = -ENOMEM;
2026 goto out;
Kiran Patil21659032015-09-30 14:09:03 -04002027 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002028
Kiran Patil21659032015-09-30 14:09:03 -04002029 list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002030
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002031 add_happened = true;
2032 cmd_flags = 0;
2033
2034 /* add to add array */
Greg Rose9a173902014-05-22 06:32:02 +00002035 ether_addr_copy(add_list[num_add].mac_addr, f->macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002036 add_list[num_add].vlan_tag =
2037 cpu_to_le16(
2038 (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan));
2039 add_list[num_add].queue_number = 0;
2040
2041 cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002042 add_list[num_add].flags = cpu_to_le16(cmd_flags);
2043 num_add++;
2044
2045 /* flush a full buffer */
2046 if (num_add == filter_list_len) {
Mitch Williamsea02e902015-11-09 15:35:50 -08002047 aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
2048 add_list, num_add,
2049 NULL);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002050 aq_err = pf->hw.aq.asq_last_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002051 num_add = 0;
2052
Mitch Williamsea02e902015-11-09 15:35:50 -08002053 if (aq_ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002054 break;
Shannon Nelsonf1199992015-11-19 11:34:23 -08002055 memset(add_list, 0, add_list_size);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002056 }
Kiran Patil21659032015-09-30 14:09:03 -04002057 /* Entries from tmp_add_list were cloned from MAC
2058 * filter list, hence clean those cloned entries
2059 */
2060 list_del(&f->list);
2061 kfree(f);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002062 }
Kiran Patil21659032015-09-30 14:09:03 -04002063
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002064 if (num_add) {
Mitch Williamsea02e902015-11-09 15:35:50 -08002065 aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
2066 add_list, num_add, NULL);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002067 aq_err = pf->hw.aq.asq_last_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002068 num_add = 0;
2069 }
2070 kfree(add_list);
2071 add_list = NULL;
2072
Mitch Williamsea02e902015-11-09 15:35:50 -08002073 if (add_happened && aq_ret && aq_err != I40E_AQ_RC_EINVAL) {
2074 retval = i40e_aq_rc_to_posix(aq_ret, aq_err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002075 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002076 "add filter failed, err %s aq_err %s\n",
Mitch Williamsea02e902015-11-09 15:35:50 -08002077 i40e_stat_str(&pf->hw, aq_ret),
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002078 i40e_aq_str(&pf->hw, aq_err));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002079 if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) &&
2080 !test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2081 &vsi->state)) {
2082 promisc_forced_on = true;
2083 set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2084 &vsi->state);
2085 dev_info(&pf->pdev->dev, "promiscuous mode forced on\n");
2086 }
2087 }
2088 }
2089
2090 /* check for changes in promiscuous modes */
2091 if (changed_flags & IFF_ALLMULTI) {
2092 bool cur_multipromisc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002093
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002094 cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
Mitch Williamsea02e902015-11-09 15:35:50 -08002095 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
2096 vsi->seid,
2097 cur_multipromisc,
2098 NULL);
2099 if (aq_ret) {
2100 retval = i40e_aq_rc_to_posix(aq_ret,
2101 pf->hw.aq.asq_last_status);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002102 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002103 "set multi promisc failed, err %s aq_err %s\n",
Mitch Williamsea02e902015-11-09 15:35:50 -08002104 i40e_stat_str(&pf->hw, aq_ret),
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002105 i40e_aq_str(&pf->hw,
2106 pf->hw.aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002107 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002108 }
2109 if ((changed_flags & IFF_PROMISC) || promisc_forced_on) {
2110 bool cur_promisc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002111
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002112 cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
2113 test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2114 &vsi->state));
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002115 if (vsi->type == I40E_VSI_MAIN && pf->lan_veb != I40E_NO_VEB) {
2116 /* set defport ON for Main VSI instead of true promisc
2117 * this way we will get all unicast/multicast and VLAN
2118 * promisc behavior but will not get VF or VMDq traffic
2119 * replicated on the Main VSI.
2120 */
2121 if (pf->cur_promisc != cur_promisc) {
2122 pf->cur_promisc = cur_promisc;
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002123 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002124 }
2125 } else {
Mitch Williamsea02e902015-11-09 15:35:50 -08002126 aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002127 &vsi->back->hw,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002128 vsi->seid,
2129 cur_promisc, NULL);
Mitch Williamsea02e902015-11-09 15:35:50 -08002130 if (aq_ret) {
2131 retval =
2132 i40e_aq_rc_to_posix(aq_ret,
2133 pf->hw.aq.asq_last_status);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002134 dev_info(&pf->pdev->dev,
2135 "set unicast promisc failed, err %d, aq_err %d\n",
Mitch Williamsea02e902015-11-09 15:35:50 -08002136 aq_ret, pf->hw.aq.asq_last_status);
2137 }
2138 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002139 &vsi->back->hw,
2140 vsi->seid,
2141 cur_promisc, NULL);
Mitch Williamsea02e902015-11-09 15:35:50 -08002142 if (aq_ret) {
2143 retval =
2144 i40e_aq_rc_to_posix(aq_ret,
2145 pf->hw.aq.asq_last_status);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002146 dev_info(&pf->pdev->dev,
2147 "set multicast promisc failed, err %d, aq_err %d\n",
Mitch Williamsea02e902015-11-09 15:35:50 -08002148 aq_ret, pf->hw.aq.asq_last_status);
2149 }
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002150 }
Mitch Williamsea02e902015-11-09 15:35:50 -08002151 aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
2152 vsi->seid,
2153 cur_promisc, NULL);
2154 if (aq_ret) {
2155 retval = i40e_aq_rc_to_posix(aq_ret,
2156 pf->hw.aq.asq_last_status);
Greg Rose1a103702013-11-28 06:42:39 +00002157 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002158 "set brdcast promisc failed, err %s, aq_err %s\n",
Mitch Williamsea02e902015-11-09 15:35:50 -08002159 i40e_stat_str(&pf->hw, aq_ret),
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002160 i40e_aq_str(&pf->hw,
2161 pf->hw.aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002162 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002163 }
Mitch Williamsea02e902015-11-09 15:35:50 -08002164out:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002165 clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
Mitch Williamsea02e902015-11-09 15:35:50 -08002166 return retval;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002167}
2168
2169/**
2170 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2171 * @pf: board private structure
2172 **/
2173static void i40e_sync_filters_subtask(struct i40e_pf *pf)
2174{
2175 int v;
2176
2177 if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
2178 return;
2179 pf->flags &= ~I40E_FLAG_FILTER_SYNC;
2180
Mitch Williams505682c2014-05-20 08:01:37 +00002181 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002182 if (pf->vsi[v] &&
Jesse Brandeburg17652c62015-11-05 17:01:02 -08002183 (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
2184 int ret = i40e_sync_vsi_filters(pf->vsi[v]);
2185
2186 if (ret) {
2187 /* come back and try again later */
2188 pf->flags |= I40E_FLAG_FILTER_SYNC;
2189 break;
2190 }
2191 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002192 }
2193}
2194
2195/**
2196 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2197 * @netdev: network interface device structure
2198 * @new_mtu: new value for maximum frame size
2199 *
2200 * Returns 0 on success, negative on failure
2201 **/
2202static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
2203{
2204 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg61a46a42014-04-23 04:50:05 +00002205 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002206 struct i40e_vsi *vsi = np->vsi;
2207
2208 /* MTU < 68 is an error and causes problems on some kernels */
2209 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
2210 return -EINVAL;
2211
2212 netdev_info(netdev, "changing MTU from %d to %d\n",
2213 netdev->mtu, new_mtu);
2214 netdev->mtu = new_mtu;
2215 if (netif_running(netdev))
2216 i40e_vsi_reinit_locked(vsi);
2217
2218 return 0;
2219}
2220
2221/**
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002222 * i40e_ioctl - Access the hwtstamp interface
2223 * @netdev: network interface device structure
2224 * @ifr: interface request data
2225 * @cmd: ioctl command
2226 **/
2227int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2228{
2229 struct i40e_netdev_priv *np = netdev_priv(netdev);
2230 struct i40e_pf *pf = np->vsi->back;
2231
2232 switch (cmd) {
2233 case SIOCGHWTSTAMP:
2234 return i40e_ptp_get_ts_config(pf, ifr);
2235 case SIOCSHWTSTAMP:
2236 return i40e_ptp_set_ts_config(pf, ifr);
2237 default:
2238 return -EOPNOTSUPP;
2239 }
2240}
2241
2242/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002243 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2244 * @vsi: the vsi being adjusted
2245 **/
2246void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
2247{
2248 struct i40e_vsi_context ctxt;
2249 i40e_status ret;
2250
2251 if ((vsi->info.valid_sections &
2252 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2253 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
2254 return; /* already enabled */
2255
2256 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2257 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2258 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
2259
2260 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002261 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002262 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2263 if (ret) {
2264 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002265 "update vlan stripping failed, err %s aq_err %s\n",
2266 i40e_stat_str(&vsi->back->hw, ret),
2267 i40e_aq_str(&vsi->back->hw,
2268 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002269 }
2270}
2271
2272/**
2273 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2274 * @vsi: the vsi being adjusted
2275 **/
2276void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
2277{
2278 struct i40e_vsi_context ctxt;
2279 i40e_status ret;
2280
2281 if ((vsi->info.valid_sections &
2282 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2283 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
2284 I40E_AQ_VSI_PVLAN_EMOD_MASK))
2285 return; /* already disabled */
2286
2287 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2288 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2289 I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
2290
2291 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002292 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002293 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2294 if (ret) {
2295 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002296 "update vlan stripping failed, err %s aq_err %s\n",
2297 i40e_stat_str(&vsi->back->hw, ret),
2298 i40e_aq_str(&vsi->back->hw,
2299 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002300 }
2301}
2302
2303/**
2304 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2305 * @netdev: network interface to be adjusted
2306 * @features: netdev features to test if VLAN offload is enabled or not
2307 **/
2308static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
2309{
2310 struct i40e_netdev_priv *np = netdev_priv(netdev);
2311 struct i40e_vsi *vsi = np->vsi;
2312
2313 if (features & NETIF_F_HW_VLAN_CTAG_RX)
2314 i40e_vlan_stripping_enable(vsi);
2315 else
2316 i40e_vlan_stripping_disable(vsi);
2317}
2318
2319/**
2320 * i40e_vsi_add_vlan - Add vsi membership for given vlan
2321 * @vsi: the vsi being configured
2322 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2323 **/
2324int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
2325{
2326 struct i40e_mac_filter *f, *add_f;
2327 bool is_netdev, is_vf;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002328
2329 is_vf = (vsi->type == I40E_VSI_SRIOV);
2330 is_netdev = !!(vsi->netdev);
2331
Kiran Patil21659032015-09-30 14:09:03 -04002332 /* Locked once because all functions invoked below iterates list*/
2333 spin_lock_bh(&vsi->mac_filter_list_lock);
2334
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002335 if (is_netdev) {
2336 add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid,
2337 is_vf, is_netdev);
2338 if (!add_f) {
2339 dev_info(&vsi->back->pdev->dev,
2340 "Could not add vlan filter %d for %pM\n",
2341 vid, vsi->netdev->dev_addr);
Kiran Patil21659032015-09-30 14:09:03 -04002342 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002343 return -ENOMEM;
2344 }
2345 }
2346
2347 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2348 add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
2349 if (!add_f) {
2350 dev_info(&vsi->back->pdev->dev,
2351 "Could not add vlan filter %d for %pM\n",
2352 vid, f->macaddr);
Kiran Patil21659032015-09-30 14:09:03 -04002353 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002354 return -ENOMEM;
2355 }
2356 }
2357
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002358 /* Now if we add a vlan tag, make sure to check if it is the first
2359 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
2360 * with 0, so we now accept untagged and specified tagged traffic
2361 * (and not any taged and untagged)
2362 */
2363 if (vid > 0) {
2364 if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr,
2365 I40E_VLAN_ANY,
2366 is_vf, is_netdev)) {
2367 i40e_del_filter(vsi, vsi->netdev->dev_addr,
2368 I40E_VLAN_ANY, is_vf, is_netdev);
2369 add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0,
2370 is_vf, is_netdev);
2371 if (!add_f) {
2372 dev_info(&vsi->back->pdev->dev,
2373 "Could not add filter 0 for %pM\n",
2374 vsi->netdev->dev_addr);
Kiran Patil21659032015-09-30 14:09:03 -04002375 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002376 return -ENOMEM;
2377 }
2378 }
Greg Rose8d82a7c2014-01-13 16:13:04 -08002379 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002380
Greg Rose8d82a7c2014-01-13 16:13:04 -08002381 /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
2382 if (vid > 0 && !vsi->info.pvid) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002383 list_for_each_entry(f, &vsi->mac_filter_list, list) {
Kiran Patil21659032015-09-30 14:09:03 -04002384 if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY,
2385 is_vf, is_netdev))
2386 continue;
2387 i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY,
2388 is_vf, is_netdev);
2389 add_f = i40e_add_filter(vsi, f->macaddr,
2390 0, is_vf, is_netdev);
2391 if (!add_f) {
2392 dev_info(&vsi->back->pdev->dev,
2393 "Could not add filter 0 for %pM\n",
2394 f->macaddr);
2395 spin_unlock_bh(&vsi->mac_filter_list_lock);
2396 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002397 }
2398 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002399 }
2400
Kiran Patil21659032015-09-30 14:09:03 -04002401 spin_unlock_bh(&vsi->mac_filter_list_lock);
2402
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002403 /* schedule our worker thread which will take care of
2404 * applying the new filter changes
2405 */
2406 i40e_service_event_schedule(vsi->back);
2407 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002408}
2409
2410/**
2411 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
2412 * @vsi: the vsi being configured
2413 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002414 *
2415 * Return: 0 on success or negative otherwise
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002416 **/
2417int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
2418{
2419 struct net_device *netdev = vsi->netdev;
2420 struct i40e_mac_filter *f, *add_f;
2421 bool is_vf, is_netdev;
2422 int filter_count = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002423
2424 is_vf = (vsi->type == I40E_VSI_SRIOV);
2425 is_netdev = !!(netdev);
2426
Kiran Patil21659032015-09-30 14:09:03 -04002427 /* Locked once because all functions invoked below iterates list */
2428 spin_lock_bh(&vsi->mac_filter_list_lock);
2429
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002430 if (is_netdev)
2431 i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev);
2432
2433 list_for_each_entry(f, &vsi->mac_filter_list, list)
2434 i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
2435
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002436 /* go through all the filters for this VSI and if there is only
2437 * vid == 0 it means there are no other filters, so vid 0 must
2438 * be replaced with -1. This signifies that we should from now
2439 * on accept any traffic (with any tag present, or untagged)
2440 */
2441 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2442 if (is_netdev) {
2443 if (f->vlan &&
2444 ether_addr_equal(netdev->dev_addr, f->macaddr))
2445 filter_count++;
2446 }
2447
2448 if (f->vlan)
2449 filter_count++;
2450 }
2451
2452 if (!filter_count && is_netdev) {
2453 i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev);
2454 f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
2455 is_vf, is_netdev);
2456 if (!f) {
2457 dev_info(&vsi->back->pdev->dev,
2458 "Could not add filter %d for %pM\n",
2459 I40E_VLAN_ANY, netdev->dev_addr);
Kiran Patil21659032015-09-30 14:09:03 -04002460 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002461 return -ENOMEM;
2462 }
2463 }
2464
2465 if (!filter_count) {
2466 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2467 i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev);
2468 add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY,
Kiran Patil21659032015-09-30 14:09:03 -04002469 is_vf, is_netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002470 if (!add_f) {
2471 dev_info(&vsi->back->pdev->dev,
2472 "Could not add filter %d for %pM\n",
2473 I40E_VLAN_ANY, f->macaddr);
Kiran Patil21659032015-09-30 14:09:03 -04002474 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002475 return -ENOMEM;
2476 }
2477 }
2478 }
2479
Kiran Patil21659032015-09-30 14:09:03 -04002480 spin_unlock_bh(&vsi->mac_filter_list_lock);
2481
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002482 /* schedule our worker thread which will take care of
2483 * applying the new filter changes
2484 */
2485 i40e_service_event_schedule(vsi->back);
2486 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002487}
2488
2489/**
2490 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2491 * @netdev: network interface to be adjusted
2492 * @vid: vlan id to be added
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002493 *
2494 * net_device_ops implementation for adding vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002495 **/
Vasu Dev38e00432014-08-01 13:27:03 -07002496#ifdef I40E_FCOE
2497int i40e_vlan_rx_add_vid(struct net_device *netdev,
2498 __always_unused __be16 proto, u16 vid)
2499#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002500static int i40e_vlan_rx_add_vid(struct net_device *netdev,
2501 __always_unused __be16 proto, u16 vid)
Vasu Dev38e00432014-08-01 13:27:03 -07002502#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002503{
2504 struct i40e_netdev_priv *np = netdev_priv(netdev);
2505 struct i40e_vsi *vsi = np->vsi;
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002506 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002507
2508 if (vid > 4095)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002509 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002510
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002511 netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid);
2512
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002513 /* If the network stack called us with vid = 0 then
2514 * it is asking to receive priority tagged packets with
2515 * vlan id 0. Our HW receives them by default when configured
2516 * to receive untagged packets so there is no need to add an
2517 * extra filter for vlan 0 tagged packets.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002518 */
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002519 if (vid)
2520 ret = i40e_vsi_add_vlan(vsi, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002521
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002522 if (!ret && (vid < VLAN_N_VID))
2523 set_bit(vid, vsi->active_vlans);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002524
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002525 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002526}
2527
2528/**
2529 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2530 * @netdev: network interface to be adjusted
2531 * @vid: vlan id to be removed
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002532 *
Akeem G Abodunrinfdfd9432014-02-11 08:24:15 +00002533 * net_device_ops implementation for removing vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002534 **/
Vasu Dev38e00432014-08-01 13:27:03 -07002535#ifdef I40E_FCOE
2536int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2537 __always_unused __be16 proto, u16 vid)
2538#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002539static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2540 __always_unused __be16 proto, u16 vid)
Vasu Dev38e00432014-08-01 13:27:03 -07002541#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002542{
2543 struct i40e_netdev_priv *np = netdev_priv(netdev);
2544 struct i40e_vsi *vsi = np->vsi;
2545
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002546 netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid);
2547
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002548 /* return code is ignored as there is nothing a user
2549 * can do about failure to remove and a log message was
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002550 * already printed from the other function
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002551 */
2552 i40e_vsi_kill_vlan(vsi, vid);
2553
2554 clear_bit(vid, vsi->active_vlans);
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002555
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002556 return 0;
2557}
2558
2559/**
2560 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2561 * @vsi: the vsi being brought back up
2562 **/
2563static void i40e_restore_vlan(struct i40e_vsi *vsi)
2564{
2565 u16 vid;
2566
2567 if (!vsi->netdev)
2568 return;
2569
2570 i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
2571
2572 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
2573 i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
2574 vid);
2575}
2576
2577/**
2578 * i40e_vsi_add_pvid - Add pvid for the VSI
2579 * @vsi: the vsi being adjusted
2580 * @vid: the vlan id to set as a PVID
2581 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002582int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002583{
2584 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002585 i40e_status ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002586
2587 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2588 vsi->info.pvid = cpu_to_le16(vid);
Greg Rose6c12fcb2013-11-28 06:39:34 +00002589 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
2590 I40E_AQ_VSI_PVLAN_INSERT_PVID |
Greg Roseb774c7d2013-11-28 06:39:44 +00002591 I40E_AQ_VSI_PVLAN_EMOD_STR;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002592
2593 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002594 ctxt.info = vsi->info;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002595 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2596 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002597 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002598 "add pvid failed, err %s aq_err %s\n",
2599 i40e_stat_str(&vsi->back->hw, ret),
2600 i40e_aq_str(&vsi->back->hw,
2601 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002602 return -ENOENT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002603 }
2604
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002605 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002606}
2607
2608/**
2609 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2610 * @vsi: the vsi being adjusted
2611 *
2612 * Just use the vlan_rx_register() service to put it back to normal
2613 **/
2614void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
2615{
Greg Rose6c12fcb2013-11-28 06:39:34 +00002616 i40e_vlan_stripping_disable(vsi);
2617
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002618 vsi->info.pvid = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002619}
2620
2621/**
2622 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2623 * @vsi: ptr to the VSI
2624 *
2625 * If this function returns with an error, then it's possible one or
2626 * more of the rings is populated (while the rest are not). It is the
2627 * callers duty to clean those orphaned rings.
2628 *
2629 * Return 0 on success, negative on failure
2630 **/
2631static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
2632{
2633 int i, err = 0;
2634
2635 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002636 err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002637
2638 return err;
2639}
2640
2641/**
2642 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2643 * @vsi: ptr to the VSI
2644 *
2645 * Free VSI's transmit software resources
2646 **/
2647static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
2648{
2649 int i;
2650
Greg Rose8e9dca52013-12-18 13:45:53 +00002651 if (!vsi->tx_rings)
2652 return;
2653
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002654 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002655 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002656 i40e_free_tx_resources(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002657}
2658
2659/**
2660 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2661 * @vsi: ptr to the VSI
2662 *
2663 * If this function returns with an error, then it's possible one or
2664 * more of the rings is populated (while the rest are not). It is the
2665 * callers duty to clean those orphaned rings.
2666 *
2667 * Return 0 on success, negative on failure
2668 **/
2669static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
2670{
2671 int i, err = 0;
2672
2673 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002674 err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
Vasu Dev38e00432014-08-01 13:27:03 -07002675#ifdef I40E_FCOE
2676 i40e_fcoe_setup_ddp_resources(vsi);
2677#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002678 return err;
2679}
2680
2681/**
2682 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2683 * @vsi: ptr to the VSI
2684 *
2685 * Free all receive software resources
2686 **/
2687static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
2688{
2689 int i;
2690
Greg Rose8e9dca52013-12-18 13:45:53 +00002691 if (!vsi->rx_rings)
2692 return;
2693
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002694 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002695 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002696 i40e_free_rx_resources(vsi->rx_rings[i]);
Vasu Dev38e00432014-08-01 13:27:03 -07002697#ifdef I40E_FCOE
2698 i40e_fcoe_free_ddp_resources(vsi);
2699#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002700}
2701
2702/**
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002703 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
2704 * @ring: The Tx ring to configure
2705 *
2706 * This enables/disables XPS for a given Tx descriptor ring
2707 * based on the TCs enabled for the VSI that ring belongs to.
2708 **/
2709static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
2710{
2711 struct i40e_vsi *vsi = ring->vsi;
2712 cpumask_var_t mask;
2713
Jesse Brandeburg9a660ee2015-02-26 16:13:22 +00002714 if (!ring->q_vector || !ring->netdev)
2715 return;
2716
2717 /* Single TC mode enable XPS */
2718 if (vsi->tc_config.numtc <= 1) {
2719 if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002720 netif_set_xps_queue(ring->netdev,
2721 &ring->q_vector->affinity_mask,
2722 ring->queue_index);
Jesse Brandeburg9a660ee2015-02-26 16:13:22 +00002723 } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) {
2724 /* Disable XPS to allow selection based on TC */
2725 bitmap_zero(cpumask_bits(mask), nr_cpumask_bits);
2726 netif_set_xps_queue(ring->netdev, mask, ring->queue_index);
2727 free_cpumask_var(mask);
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002728 }
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002729
2730 /* schedule our worker thread which will take care of
2731 * applying the new filter changes
2732 */
2733 i40e_service_event_schedule(vsi->back);
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002734}
2735
2736/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002737 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2738 * @ring: The Tx ring to configure
2739 *
2740 * Configure the Tx descriptor ring in the HMC context.
2741 **/
2742static int i40e_configure_tx_ring(struct i40e_ring *ring)
2743{
2744 struct i40e_vsi *vsi = ring->vsi;
2745 u16 pf_q = vsi->base_queue + ring->queue_index;
2746 struct i40e_hw *hw = &vsi->back->hw;
2747 struct i40e_hmc_obj_txq tx_ctx;
2748 i40e_status err = 0;
2749 u32 qtx_ctl = 0;
2750
2751 /* some ATR related tx ring init */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002752 if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002753 ring->atr_sample_rate = vsi->back->atr_sample_rate;
2754 ring->atr_count = 0;
2755 } else {
2756 ring->atr_sample_rate = 0;
2757 }
2758
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002759 /* configure XPS */
2760 i40e_config_xps_tx_ring(ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002761
2762 /* clear the context structure first */
2763 memset(&tx_ctx, 0, sizeof(tx_ctx));
2764
2765 tx_ctx.new_context = 1;
2766 tx_ctx.base = (ring->dma / 128);
2767 tx_ctx.qlen = ring->count;
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002768 tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
2769 I40E_FLAG_FD_ATR_ENABLED));
Vasu Dev38e00432014-08-01 13:27:03 -07002770#ifdef I40E_FCOE
2771 tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
2772#endif
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002773 tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
Jesse Brandeburg1943d8b2014-02-14 02:14:40 +00002774 /* FDIR VSI tx ring can still use RS bit and writebacks */
2775 if (vsi->type != I40E_VSI_FDIR)
2776 tx_ctx.head_wb_ena = 1;
2777 tx_ctx.head_wb_addr = ring->dma +
2778 (ring->count * sizeof(struct i40e_tx_desc));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002779
2780 /* As part of VSI creation/update, FW allocates certain
2781 * Tx arbitration queue sets for each TC enabled for
2782 * the VSI. The FW returns the handles to these queue
2783 * sets as part of the response buffer to Add VSI,
2784 * Update VSI, etc. AQ commands. It is expected that
2785 * these queue set handles be associated with the Tx
2786 * queues by the driver as part of the TX queue context
2787 * initialization. This has to be done regardless of
2788 * DCB as by default everything is mapped to TC0.
2789 */
2790 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
2791 tx_ctx.rdylist_act = 0;
2792
2793 /* clear the context in the HMC */
2794 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2795 if (err) {
2796 dev_info(&vsi->back->pdev->dev,
2797 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2798 ring->queue_index, pf_q, err);
2799 return -ENOMEM;
2800 }
2801
2802 /* set the context in the HMC */
2803 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
2804 if (err) {
2805 dev_info(&vsi->back->pdev->dev,
2806 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2807 ring->queue_index, pf_q, err);
2808 return -ENOMEM;
2809 }
2810
2811 /* Now associate this queue with this PCI function */
Mitch Williams7a28d882014-10-17 03:14:52 +00002812 if (vsi->type == I40E_VSI_VMDQ2) {
Shannon Nelson9d8bf542014-01-14 00:49:50 -08002813 qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
Mitch Williams7a28d882014-10-17 03:14:52 +00002814 qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
2815 I40E_QTX_CTL_VFVM_INDX_MASK;
2816 } else {
Shannon Nelson9d8bf542014-01-14 00:49:50 -08002817 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
Mitch Williams7a28d882014-10-17 03:14:52 +00002818 }
2819
Shannon Nelson13fd977492013-09-28 07:14:19 +00002820 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
2821 I40E_QTX_CTL_PF_INDX_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002822 wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
2823 i40e_flush(hw);
2824
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002825 /* cache tail off for easier writes later */
2826 ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2827
2828 return 0;
2829}
2830
2831/**
2832 * i40e_configure_rx_ring - Configure a receive ring context
2833 * @ring: The Rx ring to configure
2834 *
2835 * Configure the Rx descriptor ring in the HMC context.
2836 **/
2837static int i40e_configure_rx_ring(struct i40e_ring *ring)
2838{
2839 struct i40e_vsi *vsi = ring->vsi;
2840 u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
2841 u16 pf_q = vsi->base_queue + ring->queue_index;
2842 struct i40e_hw *hw = &vsi->back->hw;
2843 struct i40e_hmc_obj_rxq rx_ctx;
2844 i40e_status err = 0;
2845
2846 ring->state = 0;
2847
2848 /* clear the context structure first */
2849 memset(&rx_ctx, 0, sizeof(rx_ctx));
2850
2851 ring->rx_buf_len = vsi->rx_buf_len;
2852 ring->rx_hdr_len = vsi->rx_hdr_len;
2853
2854 rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
2855 rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
2856
2857 rx_ctx.base = (ring->dma / 128);
2858 rx_ctx.qlen = ring->count;
2859
2860 if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) {
2861 set_ring_16byte_desc_enabled(ring);
2862 rx_ctx.dsize = 0;
2863 } else {
2864 rx_ctx.dsize = 1;
2865 }
2866
2867 rx_ctx.dtype = vsi->dtype;
2868 if (vsi->dtype) {
2869 set_ring_ps_enabled(ring);
2870 rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
2871 I40E_RX_SPLIT_IP |
2872 I40E_RX_SPLIT_TCP_UDP |
2873 I40E_RX_SPLIT_SCTP;
2874 } else {
2875 rx_ctx.hsplit_0 = 0;
2876 }
2877
2878 rx_ctx.rxmax = min_t(u16, vsi->max_frame,
2879 (chain_len * ring->rx_buf_len));
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00002880 if (hw->revision_id == 0)
2881 rx_ctx.lrxqthresh = 0;
2882 else
2883 rx_ctx.lrxqthresh = 2;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002884 rx_ctx.crcstrip = 1;
2885 rx_ctx.l2tsel = 1;
Jesse Brandeburgc4bbac32015-09-28 11:21:48 -07002886 /* this controls whether VLAN is stripped from inner headers */
2887 rx_ctx.showiv = 0;
Vasu Dev38e00432014-08-01 13:27:03 -07002888#ifdef I40E_FCOE
2889 rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
2890#endif
Catherine Sullivanacb36762014-03-06 09:02:30 +00002891 /* set the prefena field to 1 because the manual says to */
2892 rx_ctx.prefena = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002893
2894 /* clear the context in the HMC */
2895 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
2896 if (err) {
2897 dev_info(&vsi->back->pdev->dev,
2898 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2899 ring->queue_index, pf_q, err);
2900 return -ENOMEM;
2901 }
2902
2903 /* set the context in the HMC */
2904 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
2905 if (err) {
2906 dev_info(&vsi->back->pdev->dev,
2907 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2908 ring->queue_index, pf_q, err);
2909 return -ENOMEM;
2910 }
2911
2912 /* cache tail for quicker writes, and clear the reg before use */
2913 ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
2914 writel(0, ring->tail);
2915
Mitch Williamsa132af22015-01-24 09:58:35 +00002916 if (ring_is_ps_enabled(ring)) {
2917 i40e_alloc_rx_headers(ring);
2918 i40e_alloc_rx_buffers_ps(ring, I40E_DESC_UNUSED(ring));
2919 } else {
2920 i40e_alloc_rx_buffers_1buf(ring, I40E_DESC_UNUSED(ring));
2921 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002922
2923 return 0;
2924}
2925
2926/**
2927 * i40e_vsi_configure_tx - Configure the VSI for Tx
2928 * @vsi: VSI structure describing this set of rings and resources
2929 *
2930 * Configure the Tx VSI for operation.
2931 **/
2932static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
2933{
2934 int err = 0;
2935 u16 i;
2936
Alexander Duyck9f65e152013-09-28 06:00:58 +00002937 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
2938 err = i40e_configure_tx_ring(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002939
2940 return err;
2941}
2942
2943/**
2944 * i40e_vsi_configure_rx - Configure the VSI for Rx
2945 * @vsi: the VSI being configured
2946 *
2947 * Configure the Rx VSI for operation.
2948 **/
2949static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
2950{
2951 int err = 0;
2952 u16 i;
2953
2954 if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
2955 vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
2956 + ETH_FCS_LEN + VLAN_HLEN;
2957 else
2958 vsi->max_frame = I40E_RXBUFFER_2048;
2959
2960 /* figure out correct receive buffer length */
2961 switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED |
2962 I40E_FLAG_RX_PS_ENABLED)) {
2963 case I40E_FLAG_RX_1BUF_ENABLED:
2964 vsi->rx_hdr_len = 0;
2965 vsi->rx_buf_len = vsi->max_frame;
2966 vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
2967 break;
2968 case I40E_FLAG_RX_PS_ENABLED:
2969 vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
2970 vsi->rx_buf_len = I40E_RXBUFFER_2048;
2971 vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT;
2972 break;
2973 default:
2974 vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
2975 vsi->rx_buf_len = I40E_RXBUFFER_2048;
2976 vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS;
2977 break;
2978 }
2979
Vasu Dev38e00432014-08-01 13:27:03 -07002980#ifdef I40E_FCOE
2981 /* setup rx buffer for FCoE */
2982 if ((vsi->type == I40E_VSI_FCOE) &&
2983 (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) {
2984 vsi->rx_hdr_len = 0;
2985 vsi->rx_buf_len = I40E_RXBUFFER_3072;
2986 vsi->max_frame = I40E_RXBUFFER_3072;
2987 vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
2988 }
2989
2990#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002991 /* round up for the chip's needs */
2992 vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len,
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002993 BIT_ULL(I40E_RXQ_CTX_HBUFF_SHIFT));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002994 vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002995 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002996
2997 /* set up individual rings */
2998 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002999 err = i40e_configure_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003000
3001 return err;
3002}
3003
3004/**
3005 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
3006 * @vsi: ptr to the VSI
3007 **/
3008static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
3009{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00003010 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003011 u16 qoffset, qcount;
3012 int i, n;
3013
Parikh, Neeravcd238a32015-02-21 06:43:37 +00003014 if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
3015 /* Reset the TC information */
3016 for (i = 0; i < vsi->num_queue_pairs; i++) {
3017 rx_ring = vsi->rx_rings[i];
3018 tx_ring = vsi->tx_rings[i];
3019 rx_ring->dcb_tc = 0;
3020 tx_ring->dcb_tc = 0;
3021 }
3022 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003023
3024 for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04003025 if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003026 continue;
3027
3028 qoffset = vsi->tc_config.tc_info[n].qoffset;
3029 qcount = vsi->tc_config.tc_info[n].qcount;
3030 for (i = qoffset; i < (qoffset + qcount); i++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00003031 rx_ring = vsi->rx_rings[i];
3032 tx_ring = vsi->tx_rings[i];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003033 rx_ring->dcb_tc = n;
3034 tx_ring->dcb_tc = n;
3035 }
3036 }
3037}
3038
3039/**
3040 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
3041 * @vsi: ptr to the VSI
3042 **/
3043static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
3044{
3045 if (vsi->netdev)
3046 i40e_set_rx_mode(vsi->netdev);
3047}
3048
3049/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003050 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
3051 * @vsi: Pointer to the targeted VSI
3052 *
3053 * This function replays the hlist on the hw where all the SB Flow Director
3054 * filters were saved.
3055 **/
3056static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
3057{
3058 struct i40e_fdir_filter *filter;
3059 struct i40e_pf *pf = vsi->back;
3060 struct hlist_node *node;
3061
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003062 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3063 return;
3064
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003065 hlist_for_each_entry_safe(filter, node,
3066 &pf->fdir_filter_list, fdir_node) {
3067 i40e_add_del_fdir(vsi, filter, true);
3068 }
3069}
3070
3071/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003072 * i40e_vsi_configure - Set up the VSI for action
3073 * @vsi: the VSI being configured
3074 **/
3075static int i40e_vsi_configure(struct i40e_vsi *vsi)
3076{
3077 int err;
3078
3079 i40e_set_vsi_rx_mode(vsi);
3080 i40e_restore_vlan(vsi);
3081 i40e_vsi_config_dcb_rings(vsi);
3082 err = i40e_vsi_configure_tx(vsi);
3083 if (!err)
3084 err = i40e_vsi_configure_rx(vsi);
3085
3086 return err;
3087}
3088
3089/**
3090 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3091 * @vsi: the VSI being configured
3092 **/
3093static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
3094{
3095 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003096 struct i40e_hw *hw = &pf->hw;
3097 u16 vector;
3098 int i, q;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003099 u32 qp;
3100
3101 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3102 * and PFINT_LNKLSTn registers, e.g.:
3103 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3104 */
3105 qp = vsi->base_queue;
3106 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +00003107 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003108 struct i40e_q_vector *q_vector = vsi->q_vectors[i];
3109
Jesse Brandeburgee2319c2015-09-28 14:16:54 -04003110 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003111 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
3112 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3113 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
3114 q_vector->rx.itr);
3115 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
3116 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3117 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
3118 q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003119 wr32(hw, I40E_PFINT_RATEN(vector - 1),
3120 INTRL_USEC_TO_REG(vsi->int_rate_limit));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003121
3122 /* Linked list for the queuepairs assigned to this vector */
3123 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
3124 for (q = 0; q < q_vector->num_ringpairs; q++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003125 u32 val;
3126
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003127 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3128 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3129 (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
3130 (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
3131 (I40E_QUEUE_TYPE_TX
3132 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
3133
3134 wr32(hw, I40E_QINT_RQCTL(qp), val);
3135
3136 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3137 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3138 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
3139 ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
3140 (I40E_QUEUE_TYPE_RX
3141 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3142
3143 /* Terminate the linked list */
3144 if (q == (q_vector->num_ringpairs - 1))
3145 val |= (I40E_QUEUE_END_OF_LIST
3146 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3147
3148 wr32(hw, I40E_QINT_TQCTL(qp), val);
3149 qp++;
3150 }
3151 }
3152
3153 i40e_flush(hw);
3154}
3155
3156/**
3157 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3158 * @hw: ptr to the hardware info
3159 **/
Jacob Kellerab437b52014-12-14 01:55:08 +00003160static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003161{
Jacob Kellerab437b52014-12-14 01:55:08 +00003162 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003163 u32 val;
3164
3165 /* clear things first */
3166 wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
3167 rd32(hw, I40E_PFINT_ICR0); /* read to clear */
3168
3169 val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
3170 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
3171 I40E_PFINT_ICR0_ENA_GRST_MASK |
3172 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
3173 I40E_PFINT_ICR0_ENA_GPIO_MASK |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003174 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
3175 I40E_PFINT_ICR0_ENA_VFLR_MASK |
3176 I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3177
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003178 if (pf->flags & I40E_FLAG_IWARP_ENABLED)
3179 val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3180
Jacob Kellerab437b52014-12-14 01:55:08 +00003181 if (pf->flags & I40E_FLAG_PTP)
3182 val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
3183
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003184 wr32(hw, I40E_PFINT_ICR0_ENA, val);
3185
3186 /* SW_ITR_IDX = 0, but don't change INTENA */
Anjali Singhai Jain84ed40e2013-11-26 10:49:32 +00003187 wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
3188 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003189
3190 /* OTHER_ITR_IDX = 0 */
3191 wr32(hw, I40E_PFINT_STAT_CTL0, 0);
3192}
3193
3194/**
3195 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3196 * @vsi: the VSI being configured
3197 **/
3198static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
3199{
Alexander Duyck493fb302013-09-28 07:01:44 +00003200 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003201 struct i40e_pf *pf = vsi->back;
3202 struct i40e_hw *hw = &pf->hw;
3203 u32 val;
3204
3205 /* set the ITR configuration */
Jesse Brandeburgee2319c2015-09-28 14:16:54 -04003206 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003207 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
3208 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3209 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
3210 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
3211 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3212 wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
3213
Jacob Kellerab437b52014-12-14 01:55:08 +00003214 i40e_enable_misc_int_causes(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003215
3216 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3217 wr32(hw, I40E_PFINT_LNKLST0, 0);
3218
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00003219 /* Associate the queue pair to the vector and enable the queue int */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003220 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3221 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3222 (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3223
3224 wr32(hw, I40E_QINT_RQCTL(0), val);
3225
3226 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3227 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3228 (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3229
3230 wr32(hw, I40E_QINT_TQCTL(0), val);
3231 i40e_flush(hw);
3232}
3233
3234/**
Mitch Williams2ef28cf2013-11-28 06:39:32 +00003235 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3236 * @pf: board private structure
3237 **/
3238void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
3239{
3240 struct i40e_hw *hw = &pf->hw;
3241
3242 wr32(hw, I40E_PFINT_DYN_CTL0,
3243 I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
3244 i40e_flush(hw);
3245}
3246
3247/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003248 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3249 * @pf: board private structure
3250 **/
Shannon Nelson116a57d2013-09-28 07:13:59 +00003251void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003252{
3253 struct i40e_hw *hw = &pf->hw;
3254 u32 val;
3255
3256 val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
3257 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
3258 (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
3259
3260 wr32(hw, I40E_PFINT_DYN_CTL0, val);
3261 i40e_flush(hw);
3262}
3263
3264/**
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00003265 * i40e_irq_dynamic_disable - Disable default interrupt generation settings
3266 * @vsi: pointer to a vsi
Greg Rose03147772015-01-24 09:58:29 +00003267 * @vector: disable a particular Hw Interrupt vector
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00003268 **/
3269void i40e_irq_dynamic_disable(struct i40e_vsi *vsi, int vector)
3270{
3271 struct i40e_pf *pf = vsi->back;
3272 struct i40e_hw *hw = &pf->hw;
3273 u32 val;
3274
3275 val = I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
3276 wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val);
3277 i40e_flush(hw);
3278}
3279
3280/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003281 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3282 * @irq: interrupt number
3283 * @data: pointer to a q_vector
3284 **/
3285static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
3286{
3287 struct i40e_q_vector *q_vector = data;
3288
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003289 if (!q_vector->tx.ring && !q_vector->rx.ring)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003290 return IRQ_HANDLED;
3291
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003292 napi_schedule_irqoff(&q_vector->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003293
3294 return IRQ_HANDLED;
3295}
3296
3297/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003298 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3299 * @vsi: the VSI being configured
3300 * @basename: name for the vector
3301 *
3302 * Allocates MSI-X vectors and requests interrupts from the kernel.
3303 **/
3304static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
3305{
3306 int q_vectors = vsi->num_q_vectors;
3307 struct i40e_pf *pf = vsi->back;
3308 int base = vsi->base_vector;
3309 int rx_int_idx = 0;
3310 int tx_int_idx = 0;
3311 int vector, err;
3312
3313 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck493fb302013-09-28 07:01:44 +00003314 struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003315
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003316 if (q_vector->tx.ring && q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003317 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3318 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
3319 tx_int_idx++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003320 } else if (q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003321 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3322 "%s-%s-%d", basename, "rx", rx_int_idx++);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003323 } else if (q_vector->tx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003324 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3325 "%s-%s-%d", basename, "tx", tx_int_idx++);
3326 } else {
3327 /* skip this unused q_vector */
3328 continue;
3329 }
3330 err = request_irq(pf->msix_entries[base + vector].vector,
3331 vsi->irq_handler,
3332 0,
3333 q_vector->name,
3334 q_vector);
3335 if (err) {
3336 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003337 "MSIX request_irq failed, error: %d\n", err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003338 goto free_queue_irqs;
3339 }
3340 /* assign the mask for this irq */
3341 irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
3342 &q_vector->affinity_mask);
3343 }
3344
Shannon Nelson63741842014-04-23 04:50:16 +00003345 vsi->irqs_ready = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003346 return 0;
3347
3348free_queue_irqs:
3349 while (vector) {
3350 vector--;
3351 irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
3352 NULL);
3353 free_irq(pf->msix_entries[base + vector].vector,
3354 &(vsi->q_vectors[vector]));
3355 }
3356 return err;
3357}
3358
3359/**
3360 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3361 * @vsi: the VSI being un-configured
3362 **/
3363static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
3364{
3365 struct i40e_pf *pf = vsi->back;
3366 struct i40e_hw *hw = &pf->hw;
3367 int base = vsi->base_vector;
3368 int i;
3369
3370 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00003371 wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
3372 wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003373 }
3374
3375 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3376 for (i = vsi->base_vector;
3377 i < (vsi->num_q_vectors + vsi->base_vector); i++)
3378 wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
3379
3380 i40e_flush(hw);
3381 for (i = 0; i < vsi->num_q_vectors; i++)
3382 synchronize_irq(pf->msix_entries[i + base].vector);
3383 } else {
3384 /* Legacy and MSI mode - this stops all interrupt handling */
3385 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
3386 wr32(hw, I40E_PFINT_DYN_CTL0, 0);
3387 i40e_flush(hw);
3388 synchronize_irq(pf->pdev->irq);
3389 }
3390}
3391
3392/**
3393 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3394 * @vsi: the VSI being configured
3395 **/
3396static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
3397{
3398 struct i40e_pf *pf = vsi->back;
3399 int i;
3400
3401 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
Jesse Brandeburg78455482015-07-23 16:54:41 -04003402 for (i = 0; i < vsi->num_q_vectors; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003403 i40e_irq_dynamic_enable(vsi, i);
3404 } else {
3405 i40e_irq_dynamic_enable_icr0(pf);
3406 }
3407
Jesse Brandeburg1022cb62013-09-28 07:13:08 +00003408 i40e_flush(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003409 return 0;
3410}
3411
3412/**
3413 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3414 * @pf: board private structure
3415 **/
3416static void i40e_stop_misc_vector(struct i40e_pf *pf)
3417{
3418 /* Disable ICR 0 */
3419 wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
3420 i40e_flush(&pf->hw);
3421}
3422
3423/**
3424 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3425 * @irq: interrupt number
3426 * @data: pointer to a q_vector
3427 *
3428 * This is the handler used for all MSI/Legacy interrupts, and deals
3429 * with both queue and non-queue interrupts. This is also used in
3430 * MSIX mode to handle the non-queue interrupts.
3431 **/
3432static irqreturn_t i40e_intr(int irq, void *data)
3433{
3434 struct i40e_pf *pf = (struct i40e_pf *)data;
3435 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jain5e8230662013-12-18 13:45:49 +00003436 irqreturn_t ret = IRQ_NONE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003437 u32 icr0, icr0_remaining;
3438 u32 val, ena_mask;
3439
3440 icr0 = rd32(hw, I40E_PFINT_ICR0);
Anjali Singhai Jain5e8230662013-12-18 13:45:49 +00003441 ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003442
Shannon Nelson116a57d2013-09-28 07:13:59 +00003443 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3444 if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
Anjali Singhai Jain5e8230662013-12-18 13:45:49 +00003445 goto enable_intr;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003446
Shannon Nelsoncd92e722013-11-16 10:00:44 +00003447 /* if interrupt but no bits showing, must be SWINT */
3448 if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
3449 (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
3450 pf->sw_int_count++;
3451
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003452 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
3453 (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
3454 ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3455 icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3456 dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n");
3457 }
3458
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003459 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3460 if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003461 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
3462 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003463
3464 /* temporarily disable queue cause for NAPI processing */
3465 u32 qval = rd32(hw, I40E_QINT_RQCTL(0));
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003466
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003467 qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
3468 wr32(hw, I40E_QINT_RQCTL(0), qval);
3469
3470 qval = rd32(hw, I40E_QINT_TQCTL(0));
3471 qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
3472 wr32(hw, I40E_QINT_TQCTL(0), qval);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003473
3474 if (!test_bit(__I40E_DOWN, &pf->state))
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003475 napi_schedule_irqoff(&q_vector->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003476 }
3477
3478 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
3479 ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3480 set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
3481 }
3482
3483 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
3484 ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
3485 set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
3486 }
3487
3488 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
3489 ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
3490 set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
3491 }
3492
3493 if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
3494 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
3495 set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
3496 ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
3497 val = rd32(hw, I40E_GLGEN_RSTAT);
3498 val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
3499 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003500 if (val == I40E_RESET_CORER) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003501 pf->corer_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003502 } else if (val == I40E_RESET_GLOBR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003503 pf->globr_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003504 } else if (val == I40E_RESET_EMPR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003505 pf->empr_count++;
Anjali Singhai Jain9df42d12015-01-24 09:58:40 +00003506 set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003507 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003508 }
3509
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003510 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
3511 icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
3512 dev_info(&pf->pdev->dev, "HMC error interrupt\n");
Anjali Singhai Jain25fc0e62015-03-31 00:45:01 -07003513 dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
3514 rd32(hw, I40E_PFHMC_ERRORINFO),
3515 rd32(hw, I40E_PFHMC_ERRORDATA));
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003516 }
3517
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003518 if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
3519 u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
3520
3521 if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
Jacob Kellercafa1fc2014-04-24 18:05:03 -07003522 icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003523 i40e_ptp_tx_hwtstamp(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003524 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003525 }
3526
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003527 /* If a critical error is pending we have no choice but to reset the
3528 * device.
3529 * Report and mask out any remaining unexpected interrupts.
3530 */
3531 icr0_remaining = icr0 & ena_mask;
3532 if (icr0_remaining) {
3533 dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
3534 icr0_remaining);
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003535 if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003536 (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
Anjali Singhai Jainc0c28972014-02-12 01:45:34 +00003537 (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003538 dev_info(&pf->pdev->dev, "device will be reset\n");
3539 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
3540 i40e_service_event_schedule(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003541 }
3542 ena_mask &= ~icr0_remaining;
3543 }
Anjali Singhai Jain5e8230662013-12-18 13:45:49 +00003544 ret = IRQ_HANDLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003545
Anjali Singhai Jain5e8230662013-12-18 13:45:49 +00003546enable_intr:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003547 /* re-enable interrupt causes */
3548 wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003549 if (!test_bit(__I40E_DOWN, &pf->state)) {
3550 i40e_service_event_schedule(pf);
3551 i40e_irq_dynamic_enable_icr0(pf);
3552 }
3553
Anjali Singhai Jain5e8230662013-12-18 13:45:49 +00003554 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003555}
3556
3557/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003558 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3559 * @tx_ring: tx ring to clean
3560 * @budget: how many cleans we're allowed
3561 *
3562 * Returns true if there's any budget left (e.g. the clean is finished)
3563 **/
3564static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
3565{
3566 struct i40e_vsi *vsi = tx_ring->vsi;
3567 u16 i = tx_ring->next_to_clean;
3568 struct i40e_tx_buffer *tx_buf;
3569 struct i40e_tx_desc *tx_desc;
3570
3571 tx_buf = &tx_ring->tx_bi[i];
3572 tx_desc = I40E_TX_DESC(tx_ring, i);
3573 i -= tx_ring->count;
3574
3575 do {
3576 struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
3577
3578 /* if next_to_watch is not set then there is no work pending */
3579 if (!eop_desc)
3580 break;
3581
3582 /* prevent any other reads prior to eop_desc */
3583 read_barrier_depends();
3584
3585 /* if the descriptor isn't done, no work yet to do */
3586 if (!(eop_desc->cmd_type_offset_bsz &
3587 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
3588 break;
3589
3590 /* clear next_to_watch to prevent false hangs */
3591 tx_buf->next_to_watch = NULL;
3592
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003593 tx_desc->buffer_addr = 0;
3594 tx_desc->cmd_type_offset_bsz = 0;
3595 /* move past filter desc */
3596 tx_buf++;
3597 tx_desc++;
3598 i++;
3599 if (unlikely(!i)) {
3600 i -= tx_ring->count;
3601 tx_buf = tx_ring->tx_bi;
3602 tx_desc = I40E_TX_DESC(tx_ring, 0);
3603 }
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003604 /* unmap skb header data */
3605 dma_unmap_single(tx_ring->dev,
3606 dma_unmap_addr(tx_buf, dma),
3607 dma_unmap_len(tx_buf, len),
3608 DMA_TO_DEVICE);
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003609 if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
3610 kfree(tx_buf->raw_buf);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003611
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003612 tx_buf->raw_buf = NULL;
3613 tx_buf->tx_flags = 0;
3614 tx_buf->next_to_watch = NULL;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003615 dma_unmap_len_set(tx_buf, len, 0);
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003616 tx_desc->buffer_addr = 0;
3617 tx_desc->cmd_type_offset_bsz = 0;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003618
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003619 /* move us past the eop_desc for start of next FD desc */
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003620 tx_buf++;
3621 tx_desc++;
3622 i++;
3623 if (unlikely(!i)) {
3624 i -= tx_ring->count;
3625 tx_buf = tx_ring->tx_bi;
3626 tx_desc = I40E_TX_DESC(tx_ring, 0);
3627 }
3628
3629 /* update budget accounting */
3630 budget--;
3631 } while (likely(budget));
3632
3633 i += tx_ring->count;
3634 tx_ring->next_to_clean = i;
3635
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003636 if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
Jesse Brandeburg78455482015-07-23 16:54:41 -04003637 i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003638
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003639 return budget > 0;
3640}
3641
3642/**
3643 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3644 * @irq: interrupt number
3645 * @data: pointer to a q_vector
3646 **/
3647static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
3648{
3649 struct i40e_q_vector *q_vector = data;
3650 struct i40e_vsi *vsi;
3651
3652 if (!q_vector->tx.ring)
3653 return IRQ_HANDLED;
3654
3655 vsi = q_vector->tx.ring->vsi;
3656 i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
3657
3658 return IRQ_HANDLED;
3659}
3660
3661/**
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003662 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003663 * @vsi: the VSI being configured
3664 * @v_idx: vector index
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003665 * @qp_idx: queue pair index
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003666 **/
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04003667static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003668{
Alexander Duyck493fb302013-09-28 07:01:44 +00003669 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyck9f65e152013-09-28 06:00:58 +00003670 struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
3671 struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003672
3673 tx_ring->q_vector = q_vector;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003674 tx_ring->next = q_vector->tx.ring;
3675 q_vector->tx.ring = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003676 q_vector->tx.count++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003677
3678 rx_ring->q_vector = q_vector;
3679 rx_ring->next = q_vector->rx.ring;
3680 q_vector->rx.ring = rx_ring;
3681 q_vector->rx.count++;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003682}
3683
3684/**
3685 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3686 * @vsi: the VSI being configured
3687 *
3688 * This function maps descriptor rings to the queue-specific vectors
3689 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3690 * one vector per queue pair, but on a constrained vector budget, we
3691 * group the queue pairs as "efficiently" as possible.
3692 **/
3693static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
3694{
3695 int qp_remaining = vsi->num_queue_pairs;
3696 int q_vectors = vsi->num_q_vectors;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003697 int num_ringpairs;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003698 int v_start = 0;
3699 int qp_idx = 0;
3700
3701 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3702 * group them so there are multiple queues per vector.
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003703 * It is also important to go through all the vectors available to be
3704 * sure that if we don't use all the vectors, that the remaining vectors
3705 * are cleared. This is especially important when decreasing the
3706 * number of queues in use.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003707 */
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003708 for (; v_start < q_vectors; v_start++) {
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003709 struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
3710
3711 num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
3712
3713 q_vector->num_ringpairs = num_ringpairs;
3714
3715 q_vector->rx.count = 0;
3716 q_vector->tx.count = 0;
3717 q_vector->rx.ring = NULL;
3718 q_vector->tx.ring = NULL;
3719
3720 while (num_ringpairs--) {
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04003721 i40e_map_vector_to_qp(vsi, v_start, qp_idx);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003722 qp_idx++;
3723 qp_remaining--;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003724 }
3725 }
3726}
3727
3728/**
3729 * i40e_vsi_request_irq - Request IRQ from the OS
3730 * @vsi: the VSI being configured
3731 * @basename: name for the vector
3732 **/
3733static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
3734{
3735 struct i40e_pf *pf = vsi->back;
3736 int err;
3737
3738 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
3739 err = i40e_vsi_request_irq_msix(vsi, basename);
3740 else if (pf->flags & I40E_FLAG_MSI_ENABLED)
3741 err = request_irq(pf->pdev->irq, i40e_intr, 0,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00003742 pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003743 else
3744 err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00003745 pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003746
3747 if (err)
3748 dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
3749
3750 return err;
3751}
3752
3753#ifdef CONFIG_NET_POLL_CONTROLLER
3754/**
3755 * i40e_netpoll - A Polling 'interrupt'handler
3756 * @netdev: network interface device structure
3757 *
3758 * This is used by netconsole to send skbs without having to re-enable
3759 * interrupts. It's not called while the normal interrupt routine is executing.
3760 **/
Vasu Dev38e00432014-08-01 13:27:03 -07003761#ifdef I40E_FCOE
3762void i40e_netpoll(struct net_device *netdev)
3763#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003764static void i40e_netpoll(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -07003765#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003766{
3767 struct i40e_netdev_priv *np = netdev_priv(netdev);
3768 struct i40e_vsi *vsi = np->vsi;
3769 struct i40e_pf *pf = vsi->back;
3770 int i;
3771
3772 /* if interface is down do nothing */
3773 if (test_bit(__I40E_DOWN, &vsi->state))
3774 return;
3775
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003776 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3777 for (i = 0; i < vsi->num_q_vectors; i++)
Alexander Duyck493fb302013-09-28 07:01:44 +00003778 i40e_msix_clean_rings(0, vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003779 } else {
3780 i40e_intr(pf->pdev->irq, netdev);
3781 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003782}
3783#endif
3784
3785/**
Neerav Parikh23527302014-06-03 23:50:15 +00003786 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3787 * @pf: the PF being configured
3788 * @pf_q: the PF queue
3789 * @enable: enable or disable state of the queue
3790 *
3791 * This routine will wait for the given Tx queue of the PF to reach the
3792 * enabled or disabled state.
3793 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3794 * multiple retries; else will return 0 in case of success.
3795 **/
3796static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3797{
3798 int i;
3799 u32 tx_reg;
3800
3801 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3802 tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
3803 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
3804 break;
3805
Neerav Parikhf98a2002014-09-13 07:40:44 +00003806 usleep_range(10, 20);
Neerav Parikh23527302014-06-03 23:50:15 +00003807 }
3808 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3809 return -ETIMEDOUT;
3810
3811 return 0;
3812}
3813
3814/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003815 * i40e_vsi_control_tx - Start or stop a VSI's rings
3816 * @vsi: the VSI being configured
3817 * @enable: start or stop the rings
3818 **/
3819static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
3820{
3821 struct i40e_pf *pf = vsi->back;
3822 struct i40e_hw *hw = &pf->hw;
Neerav Parikh23527302014-06-03 23:50:15 +00003823 int i, j, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003824 u32 tx_reg;
3825
3826 pf_q = vsi->base_queue;
3827 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Matt Jared351499ab2014-04-23 04:50:03 +00003828
3829 /* warn the TX unit of coming changes */
3830 i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
3831 if (!enable)
Neerav Parikhf98a2002014-09-13 07:40:44 +00003832 usleep_range(10, 20);
Matt Jared351499ab2014-04-23 04:50:03 +00003833
Mitch Williams6c5ef622014-02-20 19:29:16 -08003834 for (j = 0; j < 50; j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003835 tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
Mitch Williams6c5ef622014-02-20 19:29:16 -08003836 if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
3837 ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
3838 break;
3839 usleep_range(1000, 2000);
3840 }
Mitch Williamsfda972f2013-11-28 06:39:29 +00003841 /* Skip if the queue is already in the requested state */
Catherine Sullivan7c1220072014-03-14 07:32:29 +00003842 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
Mitch Williamsfda972f2013-11-28 06:39:29 +00003843 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003844
3845 /* turn on/off the queue */
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003846 if (enable) {
3847 wr32(hw, I40E_QTX_HEAD(pf_q), 0);
Mitch Williams6c5ef622014-02-20 19:29:16 -08003848 tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003849 } else {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003850 tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003851 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003852
3853 wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
Neerav Parikh69129dc2014-11-12 00:18:46 +00003854 /* No waiting for the Tx queue to disable */
3855 if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
3856 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003857
3858 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00003859 ret = i40e_pf_txq_wait(pf, pf_q, enable);
3860 if (ret) {
3861 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003862 "VSI seid %d Tx ring %d %sable timeout\n",
3863 vsi->seid, pf_q, (enable ? "en" : "dis"));
Neerav Parikh23527302014-06-03 23:50:15 +00003864 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003865 }
3866 }
3867
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003868 if (hw->revision_id == 0)
3869 mdelay(50);
Neerav Parikh23527302014-06-03 23:50:15 +00003870 return ret;
3871}
3872
3873/**
3874 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
3875 * @pf: the PF being configured
3876 * @pf_q: the PF queue
3877 * @enable: enable or disable state of the queue
3878 *
3879 * This routine will wait for the given Rx queue of the PF to reach the
3880 * enabled or disabled state.
3881 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3882 * multiple retries; else will return 0 in case of success.
3883 **/
3884static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3885{
3886 int i;
3887 u32 rx_reg;
3888
3889 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3890 rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
3891 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
3892 break;
3893
Neerav Parikhf98a2002014-09-13 07:40:44 +00003894 usleep_range(10, 20);
Neerav Parikh23527302014-06-03 23:50:15 +00003895 }
3896 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3897 return -ETIMEDOUT;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003898
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003899 return 0;
3900}
3901
3902/**
3903 * i40e_vsi_control_rx - Start or stop a VSI's rings
3904 * @vsi: the VSI being configured
3905 * @enable: start or stop the rings
3906 **/
3907static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
3908{
3909 struct i40e_pf *pf = vsi->back;
3910 struct i40e_hw *hw = &pf->hw;
Neerav Parikh23527302014-06-03 23:50:15 +00003911 int i, j, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003912 u32 rx_reg;
3913
3914 pf_q = vsi->base_queue;
3915 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Mitch Williams6c5ef622014-02-20 19:29:16 -08003916 for (j = 0; j < 50; j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003917 rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
Mitch Williams6c5ef622014-02-20 19:29:16 -08003918 if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
3919 ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
3920 break;
3921 usleep_range(1000, 2000);
3922 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003923
Catherine Sullivan7c1220072014-03-14 07:32:29 +00003924 /* Skip if the queue is already in the requested state */
3925 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
3926 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003927
3928 /* turn on/off the queue */
3929 if (enable)
Mitch Williams6c5ef622014-02-20 19:29:16 -08003930 rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003931 else
Mitch Williams6c5ef622014-02-20 19:29:16 -08003932 rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003933 wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
3934
3935 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00003936 ret = i40e_pf_rxq_wait(pf, pf_q, enable);
3937 if (ret) {
3938 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003939 "VSI seid %d Rx ring %d %sable timeout\n",
3940 vsi->seid, pf_q, (enable ? "en" : "dis"));
Neerav Parikh23527302014-06-03 23:50:15 +00003941 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003942 }
3943 }
3944
Neerav Parikh23527302014-06-03 23:50:15 +00003945 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003946}
3947
3948/**
3949 * i40e_vsi_control_rings - Start or stop a VSI's rings
3950 * @vsi: the VSI being configured
3951 * @enable: start or stop the rings
3952 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00003953int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003954{
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00003955 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003956
3957 /* do rx first for enable and last for disable */
3958 if (request) {
3959 ret = i40e_vsi_control_rx(vsi, request);
3960 if (ret)
3961 return ret;
3962 ret = i40e_vsi_control_tx(vsi, request);
3963 } else {
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00003964 /* Ignore return value, we need to shutdown whatever we can */
3965 i40e_vsi_control_tx(vsi, request);
3966 i40e_vsi_control_rx(vsi, request);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003967 }
3968
3969 return ret;
3970}
3971
3972/**
3973 * i40e_vsi_free_irq - Free the irq association with the OS
3974 * @vsi: the VSI being configured
3975 **/
3976static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
3977{
3978 struct i40e_pf *pf = vsi->back;
3979 struct i40e_hw *hw = &pf->hw;
3980 int base = vsi->base_vector;
3981 u32 val, qp;
3982 int i;
3983
3984 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3985 if (!vsi->q_vectors)
3986 return;
3987
Shannon Nelson63741842014-04-23 04:50:16 +00003988 if (!vsi->irqs_ready)
3989 return;
3990
3991 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003992 for (i = 0; i < vsi->num_q_vectors; i++) {
3993 u16 vector = i + base;
3994
3995 /* free only the irqs that were actually requested */
Shannon Nelson78681b12013-11-28 06:39:36 +00003996 if (!vsi->q_vectors[i] ||
3997 !vsi->q_vectors[i]->num_ringpairs)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003998 continue;
3999
4000 /* clear the affinity_mask in the IRQ descriptor */
4001 irq_set_affinity_hint(pf->msix_entries[vector].vector,
4002 NULL);
4003 free_irq(pf->msix_entries[vector].vector,
Alexander Duyck493fb302013-09-28 07:01:44 +00004004 vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004005
4006 /* Tear down the interrupt queue link list
4007 *
4008 * We know that they come in pairs and always
4009 * the Rx first, then the Tx. To clear the
4010 * link list, stick the EOL value into the
4011 * next_q field of the registers.
4012 */
4013 val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
4014 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4015 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4016 val |= I40E_QUEUE_END_OF_LIST
4017 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4018 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
4019
4020 while (qp != I40E_QUEUE_END_OF_LIST) {
4021 u32 next;
4022
4023 val = rd32(hw, I40E_QINT_RQCTL(qp));
4024
4025 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4026 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4027 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4028 I40E_QINT_RQCTL_INTEVENT_MASK);
4029
4030 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4031 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4032
4033 wr32(hw, I40E_QINT_RQCTL(qp), val);
4034
4035 val = rd32(hw, I40E_QINT_TQCTL(qp));
4036
4037 next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
4038 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
4039
4040 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4041 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4042 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4043 I40E_QINT_TQCTL_INTEVENT_MASK);
4044
4045 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4046 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4047
4048 wr32(hw, I40E_QINT_TQCTL(qp), val);
4049 qp = next;
4050 }
4051 }
4052 } else {
4053 free_irq(pf->pdev->irq, pf);
4054
4055 val = rd32(hw, I40E_PFINT_LNKLST0);
4056 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4057 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4058 val |= I40E_QUEUE_END_OF_LIST
4059 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
4060 wr32(hw, I40E_PFINT_LNKLST0, val);
4061
4062 val = rd32(hw, I40E_QINT_RQCTL(qp));
4063 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4064 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4065 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4066 I40E_QINT_RQCTL_INTEVENT_MASK);
4067
4068 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4069 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4070
4071 wr32(hw, I40E_QINT_RQCTL(qp), val);
4072
4073 val = rd32(hw, I40E_QINT_TQCTL(qp));
4074
4075 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4076 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4077 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4078 I40E_QINT_TQCTL_INTEVENT_MASK);
4079
4080 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4081 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4082
4083 wr32(hw, I40E_QINT_TQCTL(qp), val);
4084 }
4085}
4086
4087/**
Alexander Duyck493fb302013-09-28 07:01:44 +00004088 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4089 * @vsi: the VSI being configured
4090 * @v_idx: Index of vector to be freed
4091 *
4092 * This function frees the memory allocated to the q_vector. In addition if
4093 * NAPI is enabled it will delete any references to the NAPI struct prior
4094 * to freeing the q_vector.
4095 **/
4096static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
4097{
4098 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00004099 struct i40e_ring *ring;
Alexander Duyck493fb302013-09-28 07:01:44 +00004100
4101 if (!q_vector)
4102 return;
4103
4104 /* disassociate q_vector from rings */
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00004105 i40e_for_each_ring(ring, q_vector->tx)
4106 ring->q_vector = NULL;
4107
4108 i40e_for_each_ring(ring, q_vector->rx)
4109 ring->q_vector = NULL;
Alexander Duyck493fb302013-09-28 07:01:44 +00004110
4111 /* only VSI w/ an associated netdev is set up w/ NAPI */
4112 if (vsi->netdev)
4113 netif_napi_del(&q_vector->napi);
4114
4115 vsi->q_vectors[v_idx] = NULL;
4116
4117 kfree_rcu(q_vector, rcu);
4118}
4119
4120/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004121 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4122 * @vsi: the VSI being un-configured
4123 *
4124 * This frees the memory allocated to the q_vectors and
4125 * deletes references to the NAPI struct.
4126 **/
4127static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
4128{
4129 int v_idx;
4130
Alexander Duyck493fb302013-09-28 07:01:44 +00004131 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
4132 i40e_free_q_vector(vsi, v_idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004133}
4134
4135/**
4136 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4137 * @pf: board private structure
4138 **/
4139static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
4140{
4141 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4142 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4143 pci_disable_msix(pf->pdev);
4144 kfree(pf->msix_entries);
4145 pf->msix_entries = NULL;
Shannon Nelson3b444392015-02-26 16:15:57 +00004146 kfree(pf->irq_pile);
4147 pf->irq_pile = NULL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004148 } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
4149 pci_disable_msi(pf->pdev);
4150 }
4151 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
4152}
4153
4154/**
4155 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4156 * @pf: board private structure
4157 *
4158 * We go through and clear interrupt specific resources and reset the structure
4159 * to pre-load conditions
4160 **/
4161static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
4162{
4163 int i;
4164
Shannon Nelsone1477582015-02-21 06:44:33 +00004165 i40e_stop_misc_vector(pf);
4166 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4167 synchronize_irq(pf->msix_entries[0].vector);
4168 free_irq(pf->msix_entries[0].vector, pf);
4169 }
4170
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004171 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
Mitch Williams505682c2014-05-20 08:01:37 +00004172 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004173 if (pf->vsi[i])
4174 i40e_vsi_free_q_vectors(pf->vsi[i]);
4175 i40e_reset_interrupt_capability(pf);
4176}
4177
4178/**
4179 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4180 * @vsi: the VSI being configured
4181 **/
4182static void i40e_napi_enable_all(struct i40e_vsi *vsi)
4183{
4184 int q_idx;
4185
4186 if (!vsi->netdev)
4187 return;
4188
4189 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
Alexander Duyck493fb302013-09-28 07:01:44 +00004190 napi_enable(&vsi->q_vectors[q_idx]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004191}
4192
4193/**
4194 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4195 * @vsi: the VSI being configured
4196 **/
4197static void i40e_napi_disable_all(struct i40e_vsi *vsi)
4198{
4199 int q_idx;
4200
4201 if (!vsi->netdev)
4202 return;
4203
4204 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
Alexander Duyck493fb302013-09-28 07:01:44 +00004205 napi_disable(&vsi->q_vectors[q_idx]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004206}
4207
4208/**
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004209 * i40e_vsi_close - Shut down a VSI
4210 * @vsi: the vsi to be quelled
4211 **/
4212static void i40e_vsi_close(struct i40e_vsi *vsi)
4213{
4214 if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
4215 i40e_down(vsi);
4216 i40e_vsi_free_irq(vsi);
4217 i40e_vsi_free_tx_resources(vsi);
4218 i40e_vsi_free_rx_resources(vsi);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04004219 vsi->current_netdev_flags = 0;
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004220}
4221
4222/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004223 * i40e_quiesce_vsi - Pause a given VSI
4224 * @vsi: the VSI being paused
4225 **/
4226static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
4227{
4228 if (test_bit(__I40E_DOWN, &vsi->state))
4229 return;
4230
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004231 /* No need to disable FCoE VSI when Tx suspended */
4232 if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) &&
4233 vsi->type == I40E_VSI_FCOE) {
4234 dev_dbg(&vsi->back->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004235 "VSI seid %d skipping FCoE VSI disable\n", vsi->seid);
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004236 return;
4237 }
4238
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004239 set_bit(__I40E_NEEDS_RESTART, &vsi->state);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004240 if (vsi->netdev && netif_running(vsi->netdev))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004241 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004242 else
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004243 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004244}
4245
4246/**
4247 * i40e_unquiesce_vsi - Resume a given VSI
4248 * @vsi: the VSI being resumed
4249 **/
4250static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
4251{
4252 if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
4253 return;
4254
4255 clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
4256 if (vsi->netdev && netif_running(vsi->netdev))
4257 vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
4258 else
Shannon Nelson8276f752014-03-14 07:32:27 +00004259 i40e_vsi_open(vsi); /* this clears the DOWN bit */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004260}
4261
4262/**
4263 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4264 * @pf: the PF
4265 **/
4266static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
4267{
4268 int v;
4269
Mitch Williams505682c2014-05-20 08:01:37 +00004270 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004271 if (pf->vsi[v])
4272 i40e_quiesce_vsi(pf->vsi[v]);
4273 }
4274}
4275
4276/**
4277 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4278 * @pf: the PF
4279 **/
4280static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
4281{
4282 int v;
4283
Mitch Williams505682c2014-05-20 08:01:37 +00004284 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004285 if (pf->vsi[v])
4286 i40e_unquiesce_vsi(pf->vsi[v]);
4287 }
4288}
4289
Neerav Parikh69129dc2014-11-12 00:18:46 +00004290#ifdef CONFIG_I40E_DCB
4291/**
4292 * i40e_vsi_wait_txq_disabled - Wait for VSI's queues to be disabled
4293 * @vsi: the VSI being configured
4294 *
4295 * This function waits for the given VSI's Tx queues to be disabled.
4296 **/
4297static int i40e_vsi_wait_txq_disabled(struct i40e_vsi *vsi)
4298{
4299 struct i40e_pf *pf = vsi->back;
4300 int i, pf_q, ret;
4301
4302 pf_q = vsi->base_queue;
4303 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4304 /* Check and wait for the disable status of the queue */
4305 ret = i40e_pf_txq_wait(pf, pf_q, false);
4306 if (ret) {
4307 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004308 "VSI seid %d Tx ring %d disable timeout\n",
4309 vsi->seid, pf_q);
Neerav Parikh69129dc2014-11-12 00:18:46 +00004310 return ret;
4311 }
4312 }
4313
4314 return 0;
4315}
4316
4317/**
4318 * i40e_pf_wait_txq_disabled - Wait for all queues of PF VSIs to be disabled
4319 * @pf: the PF
4320 *
4321 * This function waits for the Tx queues to be in disabled state for all the
4322 * VSIs that are managed by this PF.
4323 **/
4324static int i40e_pf_wait_txq_disabled(struct i40e_pf *pf)
4325{
4326 int v, ret = 0;
4327
4328 for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004329 /* No need to wait for FCoE VSI queues */
4330 if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) {
Neerav Parikh69129dc2014-11-12 00:18:46 +00004331 ret = i40e_vsi_wait_txq_disabled(pf->vsi[v]);
4332 if (ret)
4333 break;
4334 }
4335 }
4336
4337 return ret;
4338}
4339
4340#endif
Kiran Patilb03a8c12015-09-24 18:13:15 -04004341
4342/**
4343 * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
4344 * @q_idx: TX queue number
4345 * @vsi: Pointer to VSI struct
4346 *
4347 * This function checks specified queue for given VSI. Detects hung condition.
4348 * Sets hung bit since it is two step process. Before next run of service task
4349 * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not,
4350 * hung condition remain unchanged and during subsequent run, this function
4351 * issues SW interrupt to recover from hung condition.
4352 **/
4353static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
4354{
4355 struct i40e_ring *tx_ring = NULL;
4356 struct i40e_pf *pf;
4357 u32 head, val, tx_pending;
4358 int i;
4359
4360 pf = vsi->back;
4361
4362 /* now that we have an index, find the tx_ring struct */
4363 for (i = 0; i < vsi->num_queue_pairs; i++) {
4364 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
4365 if (q_idx == vsi->tx_rings[i]->queue_index) {
4366 tx_ring = vsi->tx_rings[i];
4367 break;
4368 }
4369 }
4370 }
4371
4372 if (!tx_ring)
4373 return;
4374
4375 /* Read interrupt register */
4376 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
4377 val = rd32(&pf->hw,
4378 I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
4379 tx_ring->vsi->base_vector - 1));
4380 else
4381 val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
4382
Kiran Patil9c6c1252015-11-06 15:26:02 -08004383 /* Bail out if interrupts are disabled because napi_poll
4384 * execution in-progress or will get scheduled soon.
4385 * napi_poll cleans TX and RX queues and updates 'next_to_clean'.
4386 */
4387 if (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))
4388 return;
4389
Kiran Patilb03a8c12015-09-24 18:13:15 -04004390 head = i40e_get_head(tx_ring);
4391
4392 tx_pending = i40e_get_tx_pending(tx_ring);
4393
Kiran Patil9c6c1252015-11-06 15:26:02 -08004394 /* HW is done executing descriptors, updated HEAD write back,
4395 * but SW hasn't processed those descriptors. If interrupt is
4396 * not generated from this point ON, it could result into
4397 * dev_watchdog detecting timeout on those netdev_queue,
4398 * hence proactively trigger SW interrupt.
Kiran Patilb03a8c12015-09-24 18:13:15 -04004399 */
Kiran Patil9c6c1252015-11-06 15:26:02 -08004400 if (tx_pending) {
4401 /* NAPI Poll didn't run and clear since it was set */
4402 if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT,
4403 &tx_ring->q_vector->hung_detected)) {
4404 netdev_info(vsi->netdev, "VSI_seid %d, Hung TX queue %d, tx_pending: %d, NTC:0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x\n",
4405 vsi->seid, q_idx, tx_pending,
4406 tx_ring->next_to_clean, head,
4407 tx_ring->next_to_use,
4408 readl(tx_ring->tail));
4409 netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n",
4410 vsi->seid, q_idx, val);
4411 i40e_force_wb(vsi, tx_ring->q_vector);
4412 } else {
4413 /* First Chance - detected possible hung */
4414 set_bit(I40E_Q_VECTOR_HUNG_DETECT,
4415 &tx_ring->q_vector->hung_detected);
4416 }
4417 }
Kiran Patilb03a8c12015-09-24 18:13:15 -04004418}
4419
4420/**
4421 * i40e_detect_recover_hung - Function to detect and recover hung_queues
4422 * @pf: pointer to PF struct
4423 *
4424 * LAN VSI has netdev and netdev has TX queues. This function is to check
4425 * each of those TX queues if they are hung, trigger recovery by issuing
4426 * SW interrupt.
4427 **/
4428static void i40e_detect_recover_hung(struct i40e_pf *pf)
4429{
4430 struct net_device *netdev;
4431 struct i40e_vsi *vsi;
4432 int i;
4433
4434 /* Only for LAN VSI */
4435 vsi = pf->vsi[pf->lan_vsi];
4436
4437 if (!vsi)
4438 return;
4439
4440 /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
4441 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
4442 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
4443 return;
4444
4445 /* Make sure type is MAIN VSI */
4446 if (vsi->type != I40E_VSI_MAIN)
4447 return;
4448
4449 netdev = vsi->netdev;
4450 if (!netdev)
4451 return;
4452
4453 /* Bail out if netif_carrier is not OK */
4454 if (!netif_carrier_ok(netdev))
4455 return;
4456
4457 /* Go thru' TX queues for netdev */
4458 for (i = 0; i < netdev->num_tx_queues; i++) {
4459 struct netdev_queue *q;
4460
4461 q = netdev_get_tx_queue(netdev, i);
4462 if (q)
4463 i40e_detect_recover_hung_queue(i, vsi);
4464 }
4465}
4466
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004467/**
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004468 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00004469 * @pf: pointer to PF
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004470 *
4471 * Get TC map for ISCSI PF type that will include iSCSI TC
4472 * and LAN TC.
4473 **/
4474static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
4475{
4476 struct i40e_dcb_app_priority_table app;
4477 struct i40e_hw *hw = &pf->hw;
4478 u8 enabled_tc = 1; /* TC0 is always enabled */
4479 u8 tc, i;
4480 /* Get the iSCSI APP TLV */
4481 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4482
4483 for (i = 0; i < dcbcfg->numapps; i++) {
4484 app = dcbcfg->app[i];
4485 if (app.selector == I40E_APP_SEL_TCPIP &&
4486 app.protocolid == I40E_APP_PROTOID_ISCSI) {
4487 tc = dcbcfg->etscfg.prioritytable[app.priority];
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004488 enabled_tc |= BIT(tc);
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004489 break;
4490 }
4491 }
4492
4493 return enabled_tc;
4494}
4495
4496/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004497 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4498 * @dcbcfg: the corresponding DCBx configuration structure
4499 *
4500 * Return the number of TCs from given DCBx configuration
4501 **/
4502static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
4503{
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004504 u8 num_tc = 0;
4505 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004506
4507 /* Scan the ETS Config Priority Table to find
4508 * traffic class enabled for a given priority
4509 * and use the traffic class index to get the
4510 * number of traffic classes enabled
4511 */
4512 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
4513 if (dcbcfg->etscfg.prioritytable[i] > num_tc)
4514 num_tc = dcbcfg->etscfg.prioritytable[i];
4515 }
4516
4517 /* Traffic class index starts from zero so
4518 * increment to return the actual count
4519 */
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004520 return num_tc + 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004521}
4522
4523/**
4524 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4525 * @dcbcfg: the corresponding DCBx configuration structure
4526 *
4527 * Query the current DCB configuration and return the number of
4528 * traffic classes enabled from the given DCBX config
4529 **/
4530static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
4531{
4532 u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
4533 u8 enabled_tc = 1;
4534 u8 i;
4535
4536 for (i = 0; i < num_tc; i++)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004537 enabled_tc |= BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004538
4539 return enabled_tc;
4540}
4541
4542/**
4543 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4544 * @pf: PF being queried
4545 *
4546 * Return number of traffic classes enabled for the given PF
4547 **/
4548static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
4549{
4550 struct i40e_hw *hw = &pf->hw;
4551 u8 i, enabled_tc;
4552 u8 num_tc = 0;
4553 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4554
4555 /* If DCB is not enabled then always in single TC */
4556 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
4557 return 1;
4558
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004559 /* SFP mode will be enabled for all TCs on port */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004560 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4561 return i40e_dcb_get_num_tc(dcbcfg);
4562
4563 /* MFP mode return count of enabled TCs for this PF */
4564 if (pf->hw.func_caps.iscsi)
4565 enabled_tc = i40e_get_iscsi_tc_map(pf);
4566 else
Neerav Parikhfc51de92015-02-24 06:58:53 +00004567 return 1; /* Only TC0 */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004568
4569 /* At least have TC0 */
4570 enabled_tc = (enabled_tc ? enabled_tc : 0x1);
4571 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004572 if (enabled_tc & BIT(i))
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004573 num_tc++;
4574 }
4575 return num_tc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004576}
4577
4578/**
4579 * i40e_pf_get_default_tc - Get bitmap for first enabled TC
4580 * @pf: PF being queried
4581 *
4582 * Return a bitmap for first enabled traffic class for this PF.
4583 **/
4584static u8 i40e_pf_get_default_tc(struct i40e_pf *pf)
4585{
4586 u8 enabled_tc = pf->hw.func_caps.enabled_tcmap;
4587 u8 i = 0;
4588
4589 if (!enabled_tc)
4590 return 0x1; /* TC0 */
4591
4592 /* Find the first enabled TC */
4593 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004594 if (enabled_tc & BIT(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004595 break;
4596 }
4597
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004598 return BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004599}
4600
4601/**
4602 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4603 * @pf: PF being queried
4604 *
4605 * Return a bitmap for enabled traffic classes for this PF.
4606 **/
4607static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
4608{
4609 /* If DCB is not enabled for this PF then just return default TC */
4610 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
4611 return i40e_pf_get_default_tc(pf);
4612
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004613 /* SFP mode we want PF to be enabled for all TCs */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004614 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4615 return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
4616
Neerav Parikhfc51de92015-02-24 06:58:53 +00004617 /* MFP enabled and iSCSI PF type */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004618 if (pf->hw.func_caps.iscsi)
4619 return i40e_get_iscsi_tc_map(pf);
4620 else
Neerav Parikhfc51de92015-02-24 06:58:53 +00004621 return i40e_pf_get_default_tc(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004622}
4623
4624/**
4625 * i40e_vsi_get_bw_info - Query VSI BW Information
4626 * @vsi: the VSI being queried
4627 *
4628 * Returns 0 on success, negative value on failure
4629 **/
4630static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
4631{
4632 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
4633 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
4634 struct i40e_pf *pf = vsi->back;
4635 struct i40e_hw *hw = &pf->hw;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004636 i40e_status ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004637 u32 tc_bw_max;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004638 int i;
4639
4640 /* Get the VSI level BW configuration */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004641 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
4642 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004643 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004644 "couldn't get PF vsi bw config, err %s aq_err %s\n",
4645 i40e_stat_str(&pf->hw, ret),
4646 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004647 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004648 }
4649
4650 /* Get the VSI level BW configuration per TC */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004651 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
4652 NULL);
4653 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004654 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004655 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
4656 i40e_stat_str(&pf->hw, ret),
4657 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004658 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004659 }
4660
4661 if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
4662 dev_info(&pf->pdev->dev,
4663 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4664 bw_config.tc_valid_bits,
4665 bw_ets_config.tc_valid_bits);
4666 /* Still continuing */
4667 }
4668
4669 vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
4670 vsi->bw_max_quanta = bw_config.max_bw;
4671 tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
4672 (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
4673 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4674 vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
4675 vsi->bw_ets_limit_credits[i] =
4676 le16_to_cpu(bw_ets_config.credits[i]);
4677 /* 3 bits out of 4 for each TC */
4678 vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
4679 }
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004680
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004681 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004682}
4683
4684/**
4685 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
4686 * @vsi: the VSI being configured
4687 * @enabled_tc: TC bitmap
4688 * @bw_credits: BW shared credits per TC
4689 *
4690 * Returns 0 on success, negative value on failure
4691 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004692static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004693 u8 *bw_share)
4694{
4695 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004696 i40e_status ret;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004697 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004698
4699 bw_data.tc_valid_bits = enabled_tc;
4700 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4701 bw_data.tc_bw_credits[i] = bw_share[i];
4702
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004703 ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
4704 NULL);
4705 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004706 dev_info(&vsi->back->pdev->dev,
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004707 "AQ command Config VSI BW allocation per TC failed = %d\n",
4708 vsi->back->hw.aq.asq_last_status);
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004709 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004710 }
4711
4712 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4713 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
4714
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004715 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004716}
4717
4718/**
4719 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
4720 * @vsi: the VSI being configured
4721 * @enabled_tc: TC map to be enabled
4722 *
4723 **/
4724static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4725{
4726 struct net_device *netdev = vsi->netdev;
4727 struct i40e_pf *pf = vsi->back;
4728 struct i40e_hw *hw = &pf->hw;
4729 u8 netdev_tc = 0;
4730 int i;
4731 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4732
4733 if (!netdev)
4734 return;
4735
4736 if (!enabled_tc) {
4737 netdev_reset_tc(netdev);
4738 return;
4739 }
4740
4741 /* Set up actual enabled TCs on the VSI */
4742 if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
4743 return;
4744
4745 /* set per TC queues for the VSI */
4746 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4747 /* Only set TC queues for enabled tcs
4748 *
4749 * e.g. For a VSI that has TC0 and TC3 enabled the
4750 * enabled_tc bitmap would be 0x00001001; the driver
4751 * will set the numtc for netdev as 2 that will be
4752 * referenced by the netdev layer as TC 0 and 1.
4753 */
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004754 if (vsi->tc_config.enabled_tc & BIT(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004755 netdev_set_tc_queue(netdev,
4756 vsi->tc_config.tc_info[i].netdev_tc,
4757 vsi->tc_config.tc_info[i].qcount,
4758 vsi->tc_config.tc_info[i].qoffset);
4759 }
4760
4761 /* Assign UP2TC map for the VSI */
4762 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
4763 /* Get the actual TC# for the UP */
4764 u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
4765 /* Get the mapped netdev TC# for the UP */
4766 netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
4767 netdev_set_prio_tc_map(netdev, i, netdev_tc);
4768 }
4769}
4770
4771/**
4772 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4773 * @vsi: the VSI being configured
4774 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4775 **/
4776static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
4777 struct i40e_vsi_context *ctxt)
4778{
4779 /* copy just the sections touched not the entire info
4780 * since not all sections are valid as returned by
4781 * update vsi params
4782 */
4783 vsi->info.mapping_flags = ctxt->info.mapping_flags;
4784 memcpy(&vsi->info.queue_mapping,
4785 &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
4786 memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
4787 sizeof(vsi->info.tc_mapping));
4788}
4789
4790/**
4791 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4792 * @vsi: VSI to be configured
4793 * @enabled_tc: TC bitmap
4794 *
4795 * This configures a particular VSI for TCs that are mapped to the
4796 * given TC bitmap. It uses default bandwidth share for TCs across
4797 * VSIs to configure TC for a particular VSI.
4798 *
4799 * NOTE:
4800 * It is expected that the VSI queues have been quisced before calling
4801 * this function.
4802 **/
4803static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4804{
4805 u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
4806 struct i40e_vsi_context ctxt;
4807 int ret = 0;
4808 int i;
4809
4810 /* Check if enabled_tc is same as existing or new TCs */
4811 if (vsi->tc_config.enabled_tc == enabled_tc)
4812 return ret;
4813
4814 /* Enable ETS TCs with equal BW Share for now across all VSIs */
4815 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004816 if (enabled_tc & BIT(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004817 bw_share[i] = 1;
4818 }
4819
4820 ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
4821 if (ret) {
4822 dev_info(&vsi->back->pdev->dev,
4823 "Failed configuring TC map %d for VSI %d\n",
4824 enabled_tc, vsi->seid);
4825 goto out;
4826 }
4827
4828 /* Update Queue Pairs Mapping for currently enabled UPs */
4829 ctxt.seid = vsi->seid;
4830 ctxt.pf_num = vsi->back->hw.pf_id;
4831 ctxt.vf_num = 0;
4832 ctxt.uplink_seid = vsi->uplink_seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07004833 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004834 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
4835
4836 /* Update the VSI after updating the VSI queue-mapping information */
4837 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
4838 if (ret) {
4839 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004840 "Update vsi tc config failed, err %s aq_err %s\n",
4841 i40e_stat_str(&vsi->back->hw, ret),
4842 i40e_aq_str(&vsi->back->hw,
4843 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004844 goto out;
4845 }
4846 /* update the local VSI info with updated queue map */
4847 i40e_vsi_update_queue_map(vsi, &ctxt);
4848 vsi->info.valid_sections = 0;
4849
4850 /* Update current VSI BW information */
4851 ret = i40e_vsi_get_bw_info(vsi);
4852 if (ret) {
4853 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004854 "Failed updating vsi bw info, err %s aq_err %s\n",
4855 i40e_stat_str(&vsi->back->hw, ret),
4856 i40e_aq_str(&vsi->back->hw,
4857 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004858 goto out;
4859 }
4860
4861 /* Update the netdev TC setup */
4862 i40e_vsi_config_netdev_tc(vsi, enabled_tc);
4863out:
4864 return ret;
4865}
4866
4867/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004868 * i40e_veb_config_tc - Configure TCs for given VEB
4869 * @veb: given VEB
4870 * @enabled_tc: TC bitmap
4871 *
4872 * Configures given TC bitmap for VEB (switching) element
4873 **/
4874int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
4875{
4876 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
4877 struct i40e_pf *pf = veb->pf;
4878 int ret = 0;
4879 int i;
4880
4881 /* No TCs or already enabled TCs just return */
4882 if (!enabled_tc || veb->enabled_tc == enabled_tc)
4883 return ret;
4884
4885 bw_data.tc_valid_bits = enabled_tc;
4886 /* bw_data.absolute_credits is not set (relative) */
4887
4888 /* Enable ETS TCs with equal BW Share for now */
4889 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004890 if (enabled_tc & BIT(i))
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004891 bw_data.tc_bw_share_credits[i] = 1;
4892 }
4893
4894 ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
4895 &bw_data, NULL);
4896 if (ret) {
4897 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004898 "VEB bw config failed, err %s aq_err %s\n",
4899 i40e_stat_str(&pf->hw, ret),
4900 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004901 goto out;
4902 }
4903
4904 /* Update the BW information */
4905 ret = i40e_veb_get_bw_info(veb);
4906 if (ret) {
4907 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004908 "Failed getting veb bw config, err %s aq_err %s\n",
4909 i40e_stat_str(&pf->hw, ret),
4910 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004911 }
4912
4913out:
4914 return ret;
4915}
4916
4917#ifdef CONFIG_I40E_DCB
4918/**
4919 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
4920 * @pf: PF struct
4921 *
4922 * Reconfigure VEB/VSIs on a given PF; it is assumed that
4923 * the caller would've quiesce all the VSIs before calling
4924 * this function
4925 **/
4926static void i40e_dcb_reconfigure(struct i40e_pf *pf)
4927{
4928 u8 tc_map = 0;
4929 int ret;
4930 u8 v;
4931
4932 /* Enable the TCs available on PF to all VEBs */
4933 tc_map = i40e_pf_get_tc_map(pf);
4934 for (v = 0; v < I40E_MAX_VEB; v++) {
4935 if (!pf->veb[v])
4936 continue;
4937 ret = i40e_veb_config_tc(pf->veb[v], tc_map);
4938 if (ret) {
4939 dev_info(&pf->pdev->dev,
4940 "Failed configuring TC for VEB seid=%d\n",
4941 pf->veb[v]->seid);
4942 /* Will try to configure as many components */
4943 }
4944 }
4945
4946 /* Update each VSI */
Mitch Williams505682c2014-05-20 08:01:37 +00004947 for (v = 0; v < pf->num_alloc_vsi; v++) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004948 if (!pf->vsi[v])
4949 continue;
4950
4951 /* - Enable all TCs for the LAN VSI
Vasu Dev38e00432014-08-01 13:27:03 -07004952#ifdef I40E_FCOE
4953 * - For FCoE VSI only enable the TC configured
4954 * as per the APP TLV
4955#endif
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004956 * - For all others keep them at TC0 for now
4957 */
4958 if (v == pf->lan_vsi)
4959 tc_map = i40e_pf_get_tc_map(pf);
4960 else
4961 tc_map = i40e_pf_get_default_tc(pf);
Vasu Dev38e00432014-08-01 13:27:03 -07004962#ifdef I40E_FCOE
4963 if (pf->vsi[v]->type == I40E_VSI_FCOE)
4964 tc_map = i40e_get_fcoe_tc_map(pf);
4965#endif /* #ifdef I40E_FCOE */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004966
4967 ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
4968 if (ret) {
4969 dev_info(&pf->pdev->dev,
4970 "Failed configuring TC for VSI seid=%d\n",
4971 pf->vsi[v]->seid);
4972 /* Will try to configure as many components */
4973 } else {
Neerav Parikh0672a092014-04-01 07:11:47 +00004974 /* Re-configure VSI vectors based on updated TC map */
4975 i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004976 if (pf->vsi[v]->netdev)
4977 i40e_dcbnl_set_all(pf->vsi[v]);
4978 }
4979 }
4980}
4981
4982/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00004983 * i40e_resume_port_tx - Resume port Tx
4984 * @pf: PF struct
4985 *
4986 * Resume a port's Tx and issue a PF reset in case of failure to
4987 * resume.
4988 **/
4989static int i40e_resume_port_tx(struct i40e_pf *pf)
4990{
4991 struct i40e_hw *hw = &pf->hw;
4992 int ret;
4993
4994 ret = i40e_aq_resume_port_tx(hw, NULL);
4995 if (ret) {
4996 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004997 "Resume Port Tx failed, err %s aq_err %s\n",
4998 i40e_stat_str(&pf->hw, ret),
4999 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005000 /* Schedule PF reset to recover */
5001 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
5002 i40e_service_event_schedule(pf);
5003 }
5004
5005 return ret;
5006}
5007
5008/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005009 * i40e_init_pf_dcb - Initialize DCB configuration
5010 * @pf: PF being configured
5011 *
5012 * Query the current DCB configuration and cache it
5013 * in the hardware structure
5014 **/
5015static int i40e_init_pf_dcb(struct i40e_pf *pf)
5016{
5017 struct i40e_hw *hw = &pf->hw;
5018 int err = 0;
5019
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00005020 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
5021 if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
5022 (pf->hw.aq.fw_maj_ver < 4))
5023 goto out;
5024
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005025 /* Get the initial DCB configuration */
5026 err = i40e_init_dcb(hw);
5027 if (!err) {
5028 /* Device/Function is not DCBX capable */
5029 if ((!hw->func_caps.dcb) ||
5030 (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
5031 dev_info(&pf->pdev->dev,
5032 "DCBX offload is not supported or is disabled for this PF.\n");
5033
5034 if (pf->flags & I40E_FLAG_MFP_ENABLED)
5035 goto out;
5036
5037 } else {
5038 /* When status is not DISABLED then DCBX in FW */
5039 pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
5040 DCB_CAP_DCBX_VER_IEEE;
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005041
5042 pf->flags |= I40E_FLAG_DCB_CAPABLE;
5043 /* Enable DCB tagging only when more than one TC */
5044 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
5045 pf->flags |= I40E_FLAG_DCB_ENABLED;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005046 dev_dbg(&pf->pdev->dev,
5047 "DCBX offload is supported for this PF.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005048 }
Neerav Parikh014269f2014-04-01 07:11:48 +00005049 } else {
Shannon Nelsonaebfc812014-12-11 07:06:38 +00005050 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005051 "Query for DCB configuration failed, err %s aq_err %s\n",
5052 i40e_stat_str(&pf->hw, err),
5053 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005054 }
5055
5056out:
5057 return err;
5058}
5059#endif /* CONFIG_I40E_DCB */
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005060#define SPEED_SIZE 14
5061#define FC_SIZE 8
5062/**
5063 * i40e_print_link_message - print link up or down
5064 * @vsi: the VSI for which link needs a message
5065 */
Matt Jaredc156f852015-08-27 11:42:39 -04005066void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005067{
Shannon Nelsona9165492015-09-03 17:19:00 -04005068 char *speed = "Unknown";
5069 char *fc = "Unknown";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005070
Matt Jaredc156f852015-08-27 11:42:39 -04005071 if (vsi->current_isup == isup)
5072 return;
5073 vsi->current_isup = isup;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005074 if (!isup) {
5075 netdev_info(vsi->netdev, "NIC Link is Down\n");
5076 return;
5077 }
5078
Greg Rose148c2d82014-12-11 07:06:27 +00005079 /* Warn user if link speed on NPAR enabled partition is not at
5080 * least 10GB
5081 */
5082 if (vsi->back->hw.func_caps.npar_enable &&
5083 (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
5084 vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
5085 netdev_warn(vsi->netdev,
5086 "The partition detected link speed that is less than 10Gbps\n");
5087
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005088 switch (vsi->back->hw.phy.link_info.link_speed) {
5089 case I40E_LINK_SPEED_40GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005090 speed = "40 G";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005091 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -07005092 case I40E_LINK_SPEED_20GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005093 speed = "20 G";
Jesse Brandeburgae24b402015-03-27 00:12:09 -07005094 break;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005095 case I40E_LINK_SPEED_10GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005096 speed = "10 G";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005097 break;
5098 case I40E_LINK_SPEED_1GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005099 speed = "1000 M";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005100 break;
Mitch Williams5960d332014-09-13 07:40:47 +00005101 case I40E_LINK_SPEED_100MB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005102 speed = "100 M";
Mitch Williams5960d332014-09-13 07:40:47 +00005103 break;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005104 default:
5105 break;
5106 }
5107
5108 switch (vsi->back->hw.fc.current_mode) {
5109 case I40E_FC_FULL:
Shannon Nelsona9165492015-09-03 17:19:00 -04005110 fc = "RX/TX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005111 break;
5112 case I40E_FC_TX_PAUSE:
Shannon Nelsona9165492015-09-03 17:19:00 -04005113 fc = "TX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005114 break;
5115 case I40E_FC_RX_PAUSE:
Shannon Nelsona9165492015-09-03 17:19:00 -04005116 fc = "RX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005117 break;
5118 default:
Shannon Nelsona9165492015-09-03 17:19:00 -04005119 fc = "None";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005120 break;
5121 }
5122
Shannon Nelsona9165492015-09-03 17:19:00 -04005123 netdev_info(vsi->netdev, "NIC Link is Up %sbps Full Duplex, Flow Control: %s\n",
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005124 speed, fc);
5125}
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005126
5127/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005128 * i40e_up_complete - Finish the last steps of bringing up a connection
5129 * @vsi: the VSI being configured
5130 **/
5131static int i40e_up_complete(struct i40e_vsi *vsi)
5132{
5133 struct i40e_pf *pf = vsi->back;
5134 int err;
5135
5136 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
5137 i40e_vsi_configure_msix(vsi);
5138 else
5139 i40e_configure_msi_and_legacy(vsi);
5140
5141 /* start rings */
5142 err = i40e_vsi_control_rings(vsi, true);
5143 if (err)
5144 return err;
5145
5146 clear_bit(__I40E_DOWN, &vsi->state);
5147 i40e_napi_enable_all(vsi);
5148 i40e_vsi_enable_irq(vsi);
5149
5150 if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
5151 (vsi->netdev)) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005152 i40e_print_link_message(vsi, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005153 netif_tx_start_all_queues(vsi->netdev);
5154 netif_carrier_on(vsi->netdev);
Anjali Singhai6d779b42013-09-28 06:00:02 +00005155 } else if (vsi->netdev) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005156 i40e_print_link_message(vsi, false);
Carolyn Wyborny7b592f62014-07-10 07:58:19 +00005157 /* need to check for qualified module here*/
5158 if ((pf->hw.phy.link_info.link_info &
5159 I40E_AQ_MEDIA_AVAILABLE) &&
5160 (!(pf->hw.phy.link_info.an_info &
5161 I40E_AQ_QUALIFIED_MODULE)))
5162 netdev_err(vsi->netdev,
5163 "the driver failed to link because an unqualified module was detected.");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005164 }
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00005165
5166 /* replay FDIR SB filters */
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005167 if (vsi->type == I40E_VSI_FDIR) {
5168 /* reset fd counters */
5169 pf->fd_add_err = pf->fd_atr_cnt = 0;
5170 if (pf->fd_tcp_rule > 0) {
5171 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04005172 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5173 dev_info(&pf->pdev->dev, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005174 pf->fd_tcp_rule = 0;
5175 }
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00005176 i40e_fdir_filter_restore(vsi);
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005177 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005178 i40e_service_event_schedule(pf);
5179
5180 return 0;
5181}
5182
5183/**
5184 * i40e_vsi_reinit_locked - Reset the VSI
5185 * @vsi: the VSI being configured
5186 *
5187 * Rebuild the ring structs after some configuration
5188 * has changed, e.g. MTU size.
5189 **/
5190static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
5191{
5192 struct i40e_pf *pf = vsi->back;
5193
5194 WARN_ON(in_interrupt());
5195 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
5196 usleep_range(1000, 2000);
5197 i40e_down(vsi);
5198
5199 /* Give a VF some time to respond to the reset. The
5200 * two second wait is based upon the watchdog cycle in
5201 * the VF driver.
5202 */
5203 if (vsi->type == I40E_VSI_SRIOV)
5204 msleep(2000);
5205 i40e_up(vsi);
5206 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
5207}
5208
5209/**
5210 * i40e_up - Bring the connection back up after being down
5211 * @vsi: the VSI being configured
5212 **/
5213int i40e_up(struct i40e_vsi *vsi)
5214{
5215 int err;
5216
5217 err = i40e_vsi_configure(vsi);
5218 if (!err)
5219 err = i40e_up_complete(vsi);
5220
5221 return err;
5222}
5223
5224/**
5225 * i40e_down - Shutdown the connection processing
5226 * @vsi: the VSI being stopped
5227 **/
5228void i40e_down(struct i40e_vsi *vsi)
5229{
5230 int i;
5231
5232 /* It is assumed that the caller of this function
5233 * sets the vsi->state __I40E_DOWN bit.
5234 */
5235 if (vsi->netdev) {
5236 netif_carrier_off(vsi->netdev);
5237 netif_tx_disable(vsi->netdev);
5238 }
5239 i40e_vsi_disable_irq(vsi);
5240 i40e_vsi_control_rings(vsi, false);
5241 i40e_napi_disable_all(vsi);
5242
5243 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00005244 i40e_clean_tx_ring(vsi->tx_rings[i]);
5245 i40e_clean_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005246 }
5247}
5248
5249/**
5250 * i40e_setup_tc - configure multiple traffic classes
5251 * @netdev: net device to configure
5252 * @tc: number of traffic classes to enable
5253 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005254#ifdef I40E_FCOE
5255int i40e_setup_tc(struct net_device *netdev, u8 tc)
5256#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005257static int i40e_setup_tc(struct net_device *netdev, u8 tc)
Vasu Dev38e00432014-08-01 13:27:03 -07005258#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005259{
5260 struct i40e_netdev_priv *np = netdev_priv(netdev);
5261 struct i40e_vsi *vsi = np->vsi;
5262 struct i40e_pf *pf = vsi->back;
5263 u8 enabled_tc = 0;
5264 int ret = -EINVAL;
5265 int i;
5266
5267 /* Check if DCB enabled to continue */
5268 if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
5269 netdev_info(netdev, "DCB is not enabled for adapter\n");
5270 goto exit;
5271 }
5272
5273 /* Check if MFP enabled */
5274 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
5275 netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
5276 goto exit;
5277 }
5278
5279 /* Check whether tc count is within enabled limit */
5280 if (tc > i40e_pf_get_num_tc(pf)) {
5281 netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
5282 goto exit;
5283 }
5284
5285 /* Generate TC map for number of tc requested */
5286 for (i = 0; i < tc; i++)
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08005287 enabled_tc |= BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005288
5289 /* Requesting same TC configuration as already enabled */
5290 if (enabled_tc == vsi->tc_config.enabled_tc)
5291 return 0;
5292
5293 /* Quiesce VSI queues */
5294 i40e_quiesce_vsi(vsi);
5295
5296 /* Configure VSI for enabled TCs */
5297 ret = i40e_vsi_config_tc(vsi, enabled_tc);
5298 if (ret) {
5299 netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
5300 vsi->seid);
5301 goto exit;
5302 }
5303
5304 /* Unquiesce VSI */
5305 i40e_unquiesce_vsi(vsi);
5306
5307exit:
5308 return ret;
5309}
5310
5311/**
5312 * i40e_open - Called when a network interface is made active
5313 * @netdev: network interface device structure
5314 *
5315 * The open entry point is called when a network interface is made
5316 * active by the system (IFF_UP). At this point all resources needed
5317 * for transmit and receive operations are allocated, the interrupt
5318 * handler is registered with the OS, the netdev watchdog subtask is
5319 * enabled, and the stack is notified that the interface is ready.
5320 *
5321 * Returns 0 on success, negative value on failure
5322 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005323int i40e_open(struct net_device *netdev)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005324{
5325 struct i40e_netdev_priv *np = netdev_priv(netdev);
5326 struct i40e_vsi *vsi = np->vsi;
5327 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005328 int err;
5329
Shannon Nelson4eb3f762014-03-06 08:59:58 +00005330 /* disallow open during test or if eeprom is broken */
5331 if (test_bit(__I40E_TESTING, &pf->state) ||
5332 test_bit(__I40E_BAD_EEPROM, &pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005333 return -EBUSY;
5334
5335 netif_carrier_off(netdev);
5336
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005337 err = i40e_vsi_open(vsi);
5338 if (err)
5339 return err;
5340
Jesse Brandeburg059dab62014-04-01 09:07:20 +00005341 /* configure global TSO hardware offload settings */
5342 wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
5343 TCP_FLAG_FIN) >> 16);
5344 wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
5345 TCP_FLAG_FIN |
5346 TCP_FLAG_CWR) >> 16);
5347 wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
5348
Singhai, Anjali6633d382015-12-03 23:49:31 -08005349#ifdef CONFIG_I40E_VXLAN
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005350 vxlan_get_rx_port(netdev);
5351#endif
Singhai, Anjalicd866602015-12-14 12:21:21 -08005352#ifdef CONFIG_I40E_GENEVE
5353 geneve_get_rx_port(netdev);
5354#endif
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005355
5356 return 0;
5357}
5358
5359/**
5360 * i40e_vsi_open -
5361 * @vsi: the VSI to open
5362 *
5363 * Finish initialization of the VSI.
5364 *
5365 * Returns 0 on success, negative value on failure
5366 **/
5367int i40e_vsi_open(struct i40e_vsi *vsi)
5368{
5369 struct i40e_pf *pf = vsi->back;
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00005370 char int_name[I40E_INT_NAME_STR_LEN];
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005371 int err;
5372
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005373 /* allocate descriptors */
5374 err = i40e_vsi_setup_tx_resources(vsi);
5375 if (err)
5376 goto err_setup_tx;
5377 err = i40e_vsi_setup_rx_resources(vsi);
5378 if (err)
5379 goto err_setup_rx;
5380
5381 err = i40e_vsi_configure(vsi);
5382 if (err)
5383 goto err_setup_rx;
5384
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00005385 if (vsi->netdev) {
5386 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
5387 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
5388 err = i40e_vsi_request_irq(vsi, int_name);
5389 if (err)
5390 goto err_setup_rx;
5391
5392 /* Notify the stack of the actual queue counts. */
5393 err = netif_set_real_num_tx_queues(vsi->netdev,
5394 vsi->num_queue_pairs);
5395 if (err)
5396 goto err_set_queues;
5397
5398 err = netif_set_real_num_rx_queues(vsi->netdev,
5399 vsi->num_queue_pairs);
5400 if (err)
5401 goto err_set_queues;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005402
5403 } else if (vsi->type == I40E_VSI_FDIR) {
Carolyn Wybornye240f672014-12-11 07:06:37 +00005404 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +00005405 dev_driver_string(&pf->pdev->dev),
5406 dev_name(&pf->pdev->dev));
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005407 err = i40e_vsi_request_irq(vsi, int_name);
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +00005408
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00005409 } else {
Jean Sacrence9ccb12014-05-01 14:31:18 +00005410 err = -EINVAL;
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005411 goto err_setup_rx;
5412 }
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00005413
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005414 err = i40e_up_complete(vsi);
5415 if (err)
5416 goto err_up_complete;
5417
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005418 return 0;
5419
5420err_up_complete:
5421 i40e_down(vsi);
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00005422err_set_queues:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005423 i40e_vsi_free_irq(vsi);
5424err_setup_rx:
5425 i40e_vsi_free_rx_resources(vsi);
5426err_setup_tx:
5427 i40e_vsi_free_tx_resources(vsi);
5428 if (vsi == pf->vsi[pf->lan_vsi])
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005429 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005430
5431 return err;
5432}
5433
5434/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005435 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00005436 * @pf: Pointer to PF
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005437 *
5438 * This function destroys the hlist where all the Flow Director
5439 * filters were saved.
5440 **/
5441static void i40e_fdir_filter_exit(struct i40e_pf *pf)
5442{
5443 struct i40e_fdir_filter *filter;
5444 struct hlist_node *node2;
5445
5446 hlist_for_each_entry_safe(filter, node2,
5447 &pf->fdir_filter_list, fdir_node) {
5448 hlist_del(&filter->fdir_node);
5449 kfree(filter);
5450 }
5451 pf->fdir_pf_active_filters = 0;
5452}
5453
5454/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005455 * i40e_close - Disables a network interface
5456 * @netdev: network interface device structure
5457 *
5458 * The close entry point is called when an interface is de-activated
5459 * by the OS. The hardware is still under the driver's control, but
5460 * this netdev interface is disabled.
5461 *
5462 * Returns 0, this is not allowed to fail
5463 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005464#ifdef I40E_FCOE
5465int i40e_close(struct net_device *netdev)
5466#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005467static int i40e_close(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -07005468#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005469{
5470 struct i40e_netdev_priv *np = netdev_priv(netdev);
5471 struct i40e_vsi *vsi = np->vsi;
5472
Shannon Nelson90ef8d42014-03-14 07:32:26 +00005473 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005474
5475 return 0;
5476}
5477
5478/**
5479 * i40e_do_reset - Start a PF or Core Reset sequence
5480 * @pf: board private structure
5481 * @reset_flags: which reset is requested
5482 *
5483 * The essential difference in resets is that the PF Reset
5484 * doesn't clear the packet buffers, doesn't reset the PE
5485 * firmware, and doesn't bother the other PFs on the chip.
5486 **/
5487void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
5488{
5489 u32 val;
5490
5491 WARN_ON(in_interrupt());
5492
Mitch Williams263fc482014-04-23 04:50:11 +00005493 if (i40e_check_asq_alive(&pf->hw))
5494 i40e_vc_notify_reset(pf);
5495
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005496 /* do the biggest reset indicated */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005497 if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005498
5499 /* Request a Global Reset
5500 *
5501 * This will start the chip's countdown to the actual full
5502 * chip reset event, and a warning interrupt to be sent
5503 * to all PFs, including the requestor. Our handler
5504 * for the warning interrupt will deal with the shutdown
5505 * and recovery of the switch setup.
5506 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005507 dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005508 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5509 val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
5510 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5511
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005512 } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005513
5514 /* Request a Core Reset
5515 *
5516 * Same as Global Reset, except does *not* include the MAC/PHY
5517 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005518 dev_dbg(&pf->pdev->dev, "CoreR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005519 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5520 val |= I40E_GLGEN_RTRIG_CORER_MASK;
5521 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5522 i40e_flush(&pf->hw);
5523
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005524 } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005525
5526 /* Request a PF Reset
5527 *
5528 * Resets only the PF-specific registers
5529 *
5530 * This goes directly to the tear-down and rebuild of
5531 * the switch, since we need to do all the recovery as
5532 * for the Core Reset.
5533 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005534 dev_dbg(&pf->pdev->dev, "PFR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005535 i40e_handle_reset_warning(pf);
5536
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005537 } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005538 int v;
5539
5540 /* Find the VSI(s) that requested a re-init */
5541 dev_info(&pf->pdev->dev,
5542 "VSI reinit requested\n");
Mitch Williams505682c2014-05-20 08:01:37 +00005543 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005544 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04005545
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005546 if (vsi != NULL &&
5547 test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
5548 i40e_vsi_reinit_locked(pf->vsi[v]);
5549 clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
5550 }
5551 }
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005552 } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005553 int v;
5554
5555 /* Find the VSI(s) that needs to be brought down */
5556 dev_info(&pf->pdev->dev, "VSI down requested\n");
5557 for (v = 0; v < pf->num_alloc_vsi; v++) {
5558 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04005559
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005560 if (vsi != NULL &&
5561 test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) {
5562 set_bit(__I40E_DOWN, &vsi->state);
5563 i40e_down(vsi);
5564 clear_bit(__I40E_DOWN_REQUESTED, &vsi->state);
5565 }
5566 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005567 } else {
5568 dev_info(&pf->pdev->dev,
5569 "bad reset request 0x%08x\n", reset_flags);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005570 }
5571}
5572
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005573#ifdef CONFIG_I40E_DCB
5574/**
5575 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
5576 * @pf: board private structure
5577 * @old_cfg: current DCB config
5578 * @new_cfg: new DCB config
5579 **/
5580bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
5581 struct i40e_dcbx_config *old_cfg,
5582 struct i40e_dcbx_config *new_cfg)
5583{
5584 bool need_reconfig = false;
5585
5586 /* Check if ETS configuration has changed */
5587 if (memcmp(&new_cfg->etscfg,
5588 &old_cfg->etscfg,
5589 sizeof(new_cfg->etscfg))) {
5590 /* If Priority Table has changed reconfig is needed */
5591 if (memcmp(&new_cfg->etscfg.prioritytable,
5592 &old_cfg->etscfg.prioritytable,
5593 sizeof(new_cfg->etscfg.prioritytable))) {
5594 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005595 dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005596 }
5597
5598 if (memcmp(&new_cfg->etscfg.tcbwtable,
5599 &old_cfg->etscfg.tcbwtable,
5600 sizeof(new_cfg->etscfg.tcbwtable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005601 dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005602
5603 if (memcmp(&new_cfg->etscfg.tsatable,
5604 &old_cfg->etscfg.tsatable,
5605 sizeof(new_cfg->etscfg.tsatable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005606 dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005607 }
5608
5609 /* Check if PFC configuration has changed */
5610 if (memcmp(&new_cfg->pfc,
5611 &old_cfg->pfc,
5612 sizeof(new_cfg->pfc))) {
5613 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005614 dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005615 }
5616
5617 /* Check if APP Table has changed */
5618 if (memcmp(&new_cfg->app,
5619 &old_cfg->app,
Dave Jones3d9667a2014-01-27 23:11:09 -05005620 sizeof(new_cfg->app))) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005621 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005622 dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
Dave Jones3d9667a2014-01-27 23:11:09 -05005623 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005624
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005625 dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005626 return need_reconfig;
5627}
5628
5629/**
5630 * i40e_handle_lldp_event - Handle LLDP Change MIB event
5631 * @pf: board private structure
5632 * @e: event info posted on ARQ
5633 **/
5634static int i40e_handle_lldp_event(struct i40e_pf *pf,
5635 struct i40e_arq_event_info *e)
5636{
5637 struct i40e_aqc_lldp_get_mib *mib =
5638 (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
5639 struct i40e_hw *hw = &pf->hw;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005640 struct i40e_dcbx_config tmp_dcbx_cfg;
5641 bool need_reconfig = false;
5642 int ret = 0;
5643 u8 type;
5644
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005645 /* Not DCB capable or capability disabled */
5646 if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
5647 return ret;
5648
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005649 /* Ignore if event is not for Nearest Bridge */
5650 type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
5651 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005652 dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005653 if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
5654 return ret;
5655
5656 /* Check MIB Type and return if event for Remote MIB update */
5657 type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005658 dev_dbg(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005659 "LLDP event mib type %s\n", type ? "remote" : "local");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005660 if (type == I40E_AQ_LLDP_MIB_REMOTE) {
5661 /* Update the remote cached instance and return */
5662 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
5663 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
5664 &hw->remote_dcbx_config);
5665 goto exit;
5666 }
5667
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005668 /* Store the old configuration */
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07005669 tmp_dcbx_cfg = hw->local_dcbx_config;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005670
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005671 /* Reset the old DCBx configuration data */
5672 memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005673 /* Get updated DCBX data from firmware */
5674 ret = i40e_get_dcb_config(&pf->hw);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005675 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005676 dev_info(&pf->pdev->dev,
5677 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
5678 i40e_stat_str(&pf->hw, ret),
5679 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005680 goto exit;
5681 }
5682
5683 /* No change detected in DCBX configs */
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005684 if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
5685 sizeof(tmp_dcbx_cfg))) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005686 dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005687 goto exit;
5688 }
5689
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005690 need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
5691 &hw->local_dcbx_config);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005692
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005693 i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005694
5695 if (!need_reconfig)
5696 goto exit;
5697
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005698 /* Enable DCB tagging only when more than one TC */
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005699 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005700 pf->flags |= I40E_FLAG_DCB_ENABLED;
5701 else
5702 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
5703
Neerav Parikh69129dc2014-11-12 00:18:46 +00005704 set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005705 /* Reconfiguration needed quiesce all VSIs */
5706 i40e_pf_quiesce_all_vsi(pf);
5707
5708 /* Changes in configuration update VEB/VSI */
5709 i40e_dcb_reconfigure(pf);
5710
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005711 ret = i40e_resume_port_tx(pf);
5712
Neerav Parikh69129dc2014-11-12 00:18:46 +00005713 clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005714 /* In case of error no point in resuming VSIs */
Neerav Parikh69129dc2014-11-12 00:18:46 +00005715 if (ret)
5716 goto exit;
5717
5718 /* Wait for the PF's Tx queues to be disabled */
5719 ret = i40e_pf_wait_txq_disabled(pf);
Parikh, Neerav11e47702015-02-21 06:43:55 +00005720 if (ret) {
5721 /* Schedule PF reset to recover */
5722 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
5723 i40e_service_event_schedule(pf);
5724 } else {
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005725 i40e_pf_unquiesce_all_vsi(pf);
Parikh, Neerav11e47702015-02-21 06:43:55 +00005726 }
5727
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005728exit:
5729 return ret;
5730}
5731#endif /* CONFIG_I40E_DCB */
5732
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005733/**
Anjali Singhai Jain23326182013-11-26 10:49:22 +00005734 * i40e_do_reset_safe - Protected reset path for userland calls.
5735 * @pf: board private structure
5736 * @reset_flags: which reset is requested
5737 *
5738 **/
5739void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
5740{
5741 rtnl_lock();
5742 i40e_do_reset(pf, reset_flags);
5743 rtnl_unlock();
5744}
5745
5746/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005747 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
5748 * @pf: board private structure
5749 * @e: event info posted on ARQ
5750 *
5751 * Handler for LAN Queue Overflow Event generated by the firmware for PF
5752 * and VF queues
5753 **/
5754static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
5755 struct i40e_arq_event_info *e)
5756{
5757 struct i40e_aqc_lan_overflow *data =
5758 (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
5759 u32 queue = le32_to_cpu(data->prtdcb_rupto);
5760 u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
5761 struct i40e_hw *hw = &pf->hw;
5762 struct i40e_vf *vf;
5763 u16 vf_id;
5764
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005765 dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
5766 queue, qtx_ctl);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005767
5768 /* Queue belongs to VF, find the VF and issue VF reset */
5769 if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
5770 >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
5771 vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
5772 >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
5773 vf_id -= hw->func_caps.vf_base_id;
5774 vf = &pf->vf[vf_id];
5775 i40e_vc_notify_vf_reset(vf);
5776 /* Allow VF to process pending reset notification */
5777 msleep(20);
5778 i40e_reset_vf(vf, false);
5779 }
5780}
5781
5782/**
5783 * i40e_service_event_complete - Finish up the service event
5784 * @pf: board private structure
5785 **/
5786static void i40e_service_event_complete(struct i40e_pf *pf)
5787{
Shannon Nelsonb875f992015-10-21 19:47:03 -04005788 WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005789
5790 /* flush memory to make sure state is correct before next watchog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005791 smp_mb__before_atomic();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005792 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
5793}
5794
5795/**
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005796 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
5797 * @pf: board private structure
5798 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005799u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005800{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005801 u32 val, fcnt_prog;
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005802
5803 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
5804 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
5805 return fcnt_prog;
5806}
5807
5808/**
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005809 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005810 * @pf: board private structure
5811 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005812u32 i40e_get_current_fd_count(struct i40e_pf *pf)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005813{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005814 u32 val, fcnt_prog;
5815
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005816 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
5817 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
5818 ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
5819 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
5820 return fcnt_prog;
5821}
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005822
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005823/**
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005824 * i40e_get_global_fd_count - Get total FD filters programmed on device
5825 * @pf: board private structure
5826 **/
5827u32 i40e_get_global_fd_count(struct i40e_pf *pf)
5828{
5829 u32 val, fcnt_prog;
5830
5831 val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
5832 fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
5833 ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
5834 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
5835 return fcnt_prog;
5836}
5837
5838/**
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005839 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
5840 * @pf: board private structure
5841 **/
5842void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
5843{
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04005844 struct i40e_fdir_filter *filter;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005845 u32 fcnt_prog, fcnt_avail;
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04005846 struct hlist_node *node;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005847
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005848 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
5849 return;
5850
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005851 /* Check if, FD SB or ATR was auto disabled and if there is enough room
5852 * to re-enable
5853 */
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005854 fcnt_prog = i40e_get_global_fd_count(pf);
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005855 fcnt_avail = pf->fdir_pf_filter_count;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005856 if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
5857 (pf->fd_add_err == 0) ||
5858 (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005859 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
5860 (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
5861 pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04005862 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5863 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 +00005864 }
5865 }
5866 /* Wait for some more space to be available to turn on ATR */
5867 if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
5868 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
5869 (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
5870 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04005871 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5872 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 +00005873 }
5874 }
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04005875
5876 /* if hw had a problem adding a filter, delete it */
5877 if (pf->fd_inv > 0) {
5878 hlist_for_each_entry_safe(filter, node,
5879 &pf->fdir_filter_list, fdir_node) {
5880 if (filter->fd_id == pf->fd_inv) {
5881 hlist_del(&filter->fdir_node);
5882 kfree(filter);
5883 pf->fdir_pf_active_filters--;
5884 }
5885 }
5886 }
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005887}
5888
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005889#define I40E_MIN_FD_FLUSH_INTERVAL 10
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005890#define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005891/**
5892 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
5893 * @pf: board private structure
5894 **/
5895static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
5896{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005897 unsigned long min_flush_time;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005898 int flush_wait_retry = 50;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005899 bool disable_atr = false;
5900 int fd_room;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005901 int reg;
5902
Akeem G Abodunrin1790ed02014-10-17 03:14:41 +00005903 if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED)))
5904 return;
5905
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005906 if (!time_after(jiffies, pf->fd_flush_timestamp +
5907 (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
5908 return;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005909
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005910 /* If the flush is happening too quick and we have mostly SB rules we
5911 * should not re-enable ATR for some time.
5912 */
5913 min_flush_time = pf->fd_flush_timestamp +
5914 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
5915 fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005916
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005917 if (!(time_after(jiffies, min_flush_time)) &&
5918 (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
5919 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5920 dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
5921 disable_atr = true;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005922 }
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005923
5924 pf->fd_flush_timestamp = jiffies;
5925 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
5926 /* flush all filters */
5927 wr32(&pf->hw, I40E_PFQF_CTL_1,
5928 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
5929 i40e_flush(&pf->hw);
5930 pf->fd_flush_cnt++;
5931 pf->fd_add_err = 0;
5932 do {
5933 /* Check FD flush status every 5-6msec */
5934 usleep_range(5000, 6000);
5935 reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
5936 if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
5937 break;
5938 } while (flush_wait_retry--);
5939 if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
5940 dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
5941 } else {
5942 /* replay sideband filters */
5943 i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
5944 if (!disable_atr)
5945 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
5946 clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
5947 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5948 dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
5949 }
5950
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005951}
5952
5953/**
5954 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
5955 * @pf: board private structure
5956 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005957u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005958{
5959 return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
5960}
5961
5962/* We can see up to 256 filter programming desc in transit if the filters are
5963 * being applied really fast; before we see the first
5964 * filter miss error on Rx queue 0. Accumulating enough error messages before
5965 * reacting will make sure we don't cause flush too often.
5966 */
5967#define I40E_MAX_FD_PROGRAM_ERROR 256
5968
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005969/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005970 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
5971 * @pf: board private structure
5972 **/
5973static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
5974{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005975
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005976 /* if interface is down do nothing */
5977 if (test_bit(__I40E_DOWN, &pf->state))
5978 return;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005979
Akeem G Abodunrin1790ed02014-10-17 03:14:41 +00005980 if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED)))
5981 return;
5982
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005983 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005984 i40e_fdir_flush_and_replay(pf);
5985
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005986 i40e_fdir_check_and_reenable(pf);
5987
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005988}
5989
5990/**
5991 * i40e_vsi_link_event - notify VSI of a link event
5992 * @vsi: vsi to be notified
5993 * @link_up: link up or down
5994 **/
5995static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
5996{
Jesse Brandeburg32b5b812014-08-12 06:33:14 +00005997 if (!vsi || test_bit(__I40E_DOWN, &vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005998 return;
5999
6000 switch (vsi->type) {
6001 case I40E_VSI_MAIN:
Vasu Dev38e00432014-08-01 13:27:03 -07006002#ifdef I40E_FCOE
6003 case I40E_VSI_FCOE:
6004#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006005 if (!vsi->netdev || !vsi->netdev_registered)
6006 break;
6007
6008 if (link_up) {
6009 netif_carrier_on(vsi->netdev);
6010 netif_tx_wake_all_queues(vsi->netdev);
6011 } else {
6012 netif_carrier_off(vsi->netdev);
6013 netif_tx_stop_all_queues(vsi->netdev);
6014 }
6015 break;
6016
6017 case I40E_VSI_SRIOV:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006018 case I40E_VSI_VMDQ2:
6019 case I40E_VSI_CTRL:
6020 case I40E_VSI_MIRROR:
6021 default:
6022 /* there is no notification for other VSIs */
6023 break;
6024 }
6025}
6026
6027/**
6028 * i40e_veb_link_event - notify elements on the veb of a link event
6029 * @veb: veb to be notified
6030 * @link_up: link up or down
6031 **/
6032static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
6033{
6034 struct i40e_pf *pf;
6035 int i;
6036
6037 if (!veb || !veb->pf)
6038 return;
6039 pf = veb->pf;
6040
6041 /* depth first... */
6042 for (i = 0; i < I40E_MAX_VEB; i++)
6043 if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
6044 i40e_veb_link_event(pf->veb[i], link_up);
6045
6046 /* ... now the local VSIs */
Mitch Williams505682c2014-05-20 08:01:37 +00006047 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006048 if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
6049 i40e_vsi_link_event(pf->vsi[i], link_up);
6050}
6051
6052/**
6053 * i40e_link_event - Update netif_carrier status
6054 * @pf: board private structure
6055 **/
6056static void i40e_link_event(struct i40e_pf *pf)
6057{
Mitch Williams320684c2014-10-17 03:14:43 +00006058 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006059 u8 new_link_speed, old_link_speed;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006060 i40e_status status;
6061 bool new_link, old_link;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006062
Catherine Sullivan1f9610e2015-10-21 19:47:09 -04006063 /* save off old link status information */
6064 pf->hw.phy.link_info_old = pf->hw.phy.link_info;
6065
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006066 /* set this to force the get_link_status call to refresh state */
6067 pf->hw.phy.get_link_info = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006068
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006069 old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006070
6071 status = i40e_get_link_status(&pf->hw, &new_link);
6072 if (status) {
6073 dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
6074 status);
6075 return;
6076 }
6077
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006078 old_link_speed = pf->hw.phy.link_info_old.link_speed;
6079 new_link_speed = pf->hw.phy.link_info.link_speed;
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006080
6081 if (new_link == old_link &&
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006082 new_link_speed == old_link_speed &&
Mitch Williams320684c2014-10-17 03:14:43 +00006083 (test_bit(__I40E_DOWN, &vsi->state) ||
6084 new_link == netif_carrier_ok(vsi->netdev)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006085 return;
Mitch Williams320684c2014-10-17 03:14:43 +00006086
6087 if (!test_bit(__I40E_DOWN, &vsi->state))
6088 i40e_print_link_message(vsi, new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006089
6090 /* Notify the base of the switch tree connected to
6091 * the link. Floating VEBs are not notified.
6092 */
6093 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
6094 i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
6095 else
Mitch Williams320684c2014-10-17 03:14:43 +00006096 i40e_vsi_link_event(vsi, new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006097
6098 if (pf->vf)
6099 i40e_vc_notify_link_state(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00006100
6101 if (pf->flags & I40E_FLAG_PTP)
6102 i40e_ptp_set_increment(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006103}
6104
6105/**
Shannon Nelson21536712014-10-25 10:35:25 +00006106 * i40e_watchdog_subtask - periodic checks not using event driven response
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006107 * @pf: board private structure
6108 **/
6109static void i40e_watchdog_subtask(struct i40e_pf *pf)
6110{
6111 int i;
6112
6113 /* if interface is down do nothing */
6114 if (test_bit(__I40E_DOWN, &pf->state) ||
6115 test_bit(__I40E_CONFIG_BUSY, &pf->state))
6116 return;
6117
Shannon Nelson21536712014-10-25 10:35:25 +00006118 /* make sure we don't do these things too often */
6119 if (time_before(jiffies, (pf->service_timer_previous +
6120 pf->service_timer_period)))
6121 return;
6122 pf->service_timer_previous = jiffies;
6123
Shannon Nelson9ac77262015-08-27 11:42:40 -04006124 if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED)
6125 i40e_link_event(pf);
Shannon Nelson21536712014-10-25 10:35:25 +00006126
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006127 /* Update the stats for active netdevs so the network stack
6128 * can look at updated numbers whenever it cares to
6129 */
Mitch Williams505682c2014-05-20 08:01:37 +00006130 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006131 if (pf->vsi[i] && pf->vsi[i]->netdev)
6132 i40e_update_stats(pf->vsi[i]);
6133
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04006134 if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
6135 /* Update the stats for the active switching components */
6136 for (i = 0; i < I40E_MAX_VEB; i++)
6137 if (pf->veb[i])
6138 i40e_update_veb_stats(pf->veb[i]);
6139 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00006140
6141 i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006142}
6143
6144/**
6145 * i40e_reset_subtask - Set up for resetting the device and driver
6146 * @pf: board private structure
6147 **/
6148static void i40e_reset_subtask(struct i40e_pf *pf)
6149{
6150 u32 reset_flags = 0;
6151
Anjali Singhai Jain23326182013-11-26 10:49:22 +00006152 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006153 if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006154 reset_flags |= BIT(__I40E_REINIT_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006155 clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
6156 }
6157 if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006158 reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006159 clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
6160 }
6161 if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006162 reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006163 clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
6164 }
6165 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006166 reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006167 clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
6168 }
Neerav Parikhb5d06f02014-06-03 23:50:17 +00006169 if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006170 reset_flags |= BIT(__I40E_DOWN_REQUESTED);
Neerav Parikhb5d06f02014-06-03 23:50:17 +00006171 clear_bit(__I40E_DOWN_REQUESTED, &pf->state);
6172 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006173
6174 /* If there's a recovery already waiting, it takes
6175 * precedence before starting a new reset sequence.
6176 */
6177 if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
6178 i40e_handle_reset_warning(pf);
Anjali Singhai Jain23326182013-11-26 10:49:22 +00006179 goto unlock;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006180 }
6181
6182 /* If we're already down or resetting, just bail */
6183 if (reset_flags &&
6184 !test_bit(__I40E_DOWN, &pf->state) &&
6185 !test_bit(__I40E_CONFIG_BUSY, &pf->state))
6186 i40e_do_reset(pf, reset_flags);
Anjali Singhai Jain23326182013-11-26 10:49:22 +00006187
6188unlock:
6189 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006190}
6191
6192/**
6193 * i40e_handle_link_event - Handle link event
6194 * @pf: board private structure
6195 * @e: event info posted on ARQ
6196 **/
6197static void i40e_handle_link_event(struct i40e_pf *pf,
6198 struct i40e_arq_event_info *e)
6199{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006200 struct i40e_aqc_get_link_status *status =
6201 (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006202
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006203 /* Do a new status request to re-enable LSE reporting
6204 * and load new status information into the hw struct
6205 * This completely ignores any state information
6206 * in the ARQ event info, instead choosing to always
6207 * issue the AQ update link status command.
6208 */
6209 i40e_link_event(pf);
6210
Carolyn Wyborny7b592f62014-07-10 07:58:19 +00006211 /* check for unqualified module, if link is down */
6212 if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
6213 (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
6214 (!(status->link_info & I40E_AQ_LINK_UP)))
6215 dev_err(&pf->pdev->dev,
6216 "The driver failed to link because an unqualified module was detected.\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006217}
6218
6219/**
6220 * i40e_clean_adminq_subtask - Clean the AdminQ rings
6221 * @pf: board private structure
6222 **/
6223static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
6224{
6225 struct i40e_arq_event_info event;
6226 struct i40e_hw *hw = &pf->hw;
6227 u16 pending, i = 0;
6228 i40e_status ret;
6229 u16 opcode;
Shannon Nelson86df2422014-05-20 08:01:35 +00006230 u32 oldval;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006231 u32 val;
6232
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006233 /* Do not run clean AQ when PF reset fails */
6234 if (test_bit(__I40E_RESET_FAILED, &pf->state))
6235 return;
6236
Shannon Nelson86df2422014-05-20 08:01:35 +00006237 /* check for error indications */
6238 val = rd32(&pf->hw, pf->hw.aq.arq.len);
6239 oldval = val;
6240 if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006241 if (hw->debug_mask & I40E_DEBUG_AQ)
6242 dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006243 val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
6244 }
6245 if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006246 if (hw->debug_mask & I40E_DEBUG_AQ)
6247 dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006248 val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
6249 }
6250 if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006251 if (hw->debug_mask & I40E_DEBUG_AQ)
6252 dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006253 val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
6254 }
6255 if (oldval != val)
6256 wr32(&pf->hw, pf->hw.aq.arq.len, val);
6257
6258 val = rd32(&pf->hw, pf->hw.aq.asq.len);
6259 oldval = val;
6260 if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006261 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6262 dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006263 val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
6264 }
6265 if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006266 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6267 dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006268 val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
6269 }
6270 if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006271 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6272 dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006273 val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
6274 }
6275 if (oldval != val)
6276 wr32(&pf->hw, pf->hw.aq.asq.len, val);
6277
Mitch Williams1001dc32014-11-11 20:02:19 +00006278 event.buf_len = I40E_MAX_AQ_BUF_SIZE;
6279 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006280 if (!event.msg_buf)
6281 return;
6282
6283 do {
6284 ret = i40e_clean_arq_element(hw, &event, &pending);
Mitch Williams56497972014-06-04 08:45:18 +00006285 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006286 break;
Mitch Williams56497972014-06-04 08:45:18 +00006287 else if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006288 dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
6289 break;
6290 }
6291
6292 opcode = le16_to_cpu(event.desc.opcode);
6293 switch (opcode) {
6294
6295 case i40e_aqc_opc_get_link_status:
6296 i40e_handle_link_event(pf, &event);
6297 break;
6298 case i40e_aqc_opc_send_msg_to_pf:
6299 ret = i40e_vc_process_vf_msg(pf,
6300 le16_to_cpu(event.desc.retval),
6301 le32_to_cpu(event.desc.cookie_high),
6302 le32_to_cpu(event.desc.cookie_low),
6303 event.msg_buf,
Mitch Williams1001dc32014-11-11 20:02:19 +00006304 event.msg_len);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006305 break;
6306 case i40e_aqc_opc_lldp_update_mib:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006307 dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006308#ifdef CONFIG_I40E_DCB
6309 rtnl_lock();
6310 ret = i40e_handle_lldp_event(pf, &event);
6311 rtnl_unlock();
6312#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006313 break;
6314 case i40e_aqc_opc_event_lan_overflow:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006315 dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006316 i40e_handle_lan_overflow_event(pf, &event);
6317 break;
Shannon Nelson0467bc92013-12-18 13:45:58 +00006318 case i40e_aqc_opc_send_msg_to_peer:
6319 dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
6320 break;
Shannon Nelson91a0f932015-03-19 14:32:01 -07006321 case i40e_aqc_opc_nvm_erase:
6322 case i40e_aqc_opc_nvm_update:
Michal Kosiarz00ada502015-11-19 11:34:20 -08006323 case i40e_aqc_opc_oem_post_update:
Shannon Nelson91a0f932015-03-19 14:32:01 -07006324 i40e_debug(&pf->hw, I40E_DEBUG_NVM, "ARQ NVM operation completed\n");
6325 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006326 default:
6327 dev_info(&pf->pdev->dev,
Shannon Nelson0467bc92013-12-18 13:45:58 +00006328 "ARQ Error: Unknown event 0x%04x received\n",
6329 opcode);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006330 break;
6331 }
6332 } while (pending && (i++ < pf->adminq_work_limit));
6333
6334 clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
6335 /* re-enable Admin queue interrupt cause */
6336 val = rd32(hw, I40E_PFINT_ICR0_ENA);
6337 val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
6338 wr32(hw, I40E_PFINT_ICR0_ENA, val);
6339 i40e_flush(hw);
6340
6341 kfree(event.msg_buf);
6342}
6343
6344/**
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006345 * i40e_verify_eeprom - make sure eeprom is good to use
6346 * @pf: board private structure
6347 **/
6348static void i40e_verify_eeprom(struct i40e_pf *pf)
6349{
6350 int err;
6351
6352 err = i40e_diag_eeprom_test(&pf->hw);
6353 if (err) {
6354 /* retry in case of garbage read */
6355 err = i40e_diag_eeprom_test(&pf->hw);
6356 if (err) {
6357 dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
6358 err);
6359 set_bit(__I40E_BAD_EEPROM, &pf->state);
6360 }
6361 }
6362
6363 if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
6364 dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
6365 clear_bit(__I40E_BAD_EEPROM, &pf->state);
6366 }
6367}
6368
6369/**
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006370 * i40e_enable_pf_switch_lb
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00006371 * @pf: pointer to the PF structure
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006372 *
6373 * enable switch loop back or die - no point in a return value
6374 **/
6375static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
6376{
6377 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6378 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006379 int ret;
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006380
6381 ctxt.seid = pf->main_vsi_seid;
6382 ctxt.pf_num = pf->hw.pf_id;
6383 ctxt.vf_num = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006384 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6385 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006386 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006387 "couldn't get PF vsi config, err %s aq_err %s\n",
6388 i40e_stat_str(&pf->hw, ret),
6389 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006390 return;
6391 }
6392 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6393 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6394 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6395
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006396 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6397 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006398 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006399 "update vsi switch failed, err %s aq_err %s\n",
6400 i40e_stat_str(&pf->hw, ret),
6401 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006402 }
6403}
6404
6405/**
6406 * i40e_disable_pf_switch_lb
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00006407 * @pf: pointer to the PF structure
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006408 *
6409 * disable switch loop back or die - no point in a return value
6410 **/
6411static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
6412{
6413 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6414 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006415 int ret;
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006416
6417 ctxt.seid = pf->main_vsi_seid;
6418 ctxt.pf_num = pf->hw.pf_id;
6419 ctxt.vf_num = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006420 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6421 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006422 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006423 "couldn't get PF vsi config, err %s aq_err %s\n",
6424 i40e_stat_str(&pf->hw, ret),
6425 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006426 return;
6427 }
6428 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6429 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6430 ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6431
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006432 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6433 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006434 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006435 "update vsi switch failed, err %s aq_err %s\n",
6436 i40e_stat_str(&pf->hw, ret),
6437 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006438 }
6439}
6440
6441/**
Neerav Parikh51616012015-02-06 08:52:14 +00006442 * i40e_config_bridge_mode - Configure the HW bridge mode
6443 * @veb: pointer to the bridge instance
6444 *
6445 * Configure the loop back mode for the LAN VSI that is downlink to the
6446 * specified HW bridge instance. It is expected this function is called
6447 * when a new HW bridge is instantiated.
6448 **/
6449static void i40e_config_bridge_mode(struct i40e_veb *veb)
6450{
6451 struct i40e_pf *pf = veb->pf;
6452
Shannon Nelson6dec1012015-09-28 14:12:30 -04006453 if (pf->hw.debug_mask & I40E_DEBUG_LAN)
6454 dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
6455 veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
Neerav Parikh51616012015-02-06 08:52:14 +00006456 if (veb->bridge_mode & BRIDGE_MODE_VEPA)
6457 i40e_disable_pf_switch_lb(pf);
6458 else
6459 i40e_enable_pf_switch_lb(pf);
6460}
6461
6462/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006463 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
6464 * @veb: pointer to the VEB instance
6465 *
6466 * This is a recursive function that first builds the attached VSIs then
6467 * recurses in to build the next layer of VEB. We track the connections
6468 * through our own index numbers because the seid's from the HW could
6469 * change across the reset.
6470 **/
6471static int i40e_reconstitute_veb(struct i40e_veb *veb)
6472{
6473 struct i40e_vsi *ctl_vsi = NULL;
6474 struct i40e_pf *pf = veb->pf;
6475 int v, veb_idx;
6476 int ret;
6477
6478 /* build VSI that owns this VEB, temporarily attached to base VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00006479 for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006480 if (pf->vsi[v] &&
6481 pf->vsi[v]->veb_idx == veb->idx &&
6482 pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
6483 ctl_vsi = pf->vsi[v];
6484 break;
6485 }
6486 }
6487 if (!ctl_vsi) {
6488 dev_info(&pf->pdev->dev,
6489 "missing owner VSI for veb_idx %d\n", veb->idx);
6490 ret = -ENOENT;
6491 goto end_reconstitute;
6492 }
6493 if (ctl_vsi != pf->vsi[pf->lan_vsi])
6494 ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
6495 ret = i40e_add_vsi(ctl_vsi);
6496 if (ret) {
6497 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006498 "rebuild of veb_idx %d owner VSI failed: %d\n",
6499 veb->idx, ret);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006500 goto end_reconstitute;
6501 }
6502 i40e_vsi_reset_stats(ctl_vsi);
6503
6504 /* create the VEB in the switch and move the VSI onto the VEB */
6505 ret = i40e_add_veb(veb, ctl_vsi);
6506 if (ret)
6507 goto end_reconstitute;
6508
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07006509 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
6510 veb->bridge_mode = BRIDGE_MODE_VEB;
6511 else
6512 veb->bridge_mode = BRIDGE_MODE_VEPA;
Neerav Parikh51616012015-02-06 08:52:14 +00006513 i40e_config_bridge_mode(veb);
Anjali Singhai Jainb64ba082014-11-13 03:06:15 +00006514
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006515 /* create the remaining VSIs attached to this VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00006516 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006517 if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
6518 continue;
6519
6520 if (pf->vsi[v]->veb_idx == veb->idx) {
6521 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04006522
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006523 vsi->uplink_seid = veb->seid;
6524 ret = i40e_add_vsi(vsi);
6525 if (ret) {
6526 dev_info(&pf->pdev->dev,
6527 "rebuild of vsi_idx %d failed: %d\n",
6528 v, ret);
6529 goto end_reconstitute;
6530 }
6531 i40e_vsi_reset_stats(vsi);
6532 }
6533 }
6534
6535 /* create any VEBs attached to this VEB - RECURSION */
6536 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
6537 if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
6538 pf->veb[veb_idx]->uplink_seid = veb->seid;
6539 ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
6540 if (ret)
6541 break;
6542 }
6543 }
6544
6545end_reconstitute:
6546 return ret;
6547}
6548
6549/**
6550 * i40e_get_capabilities - get info about the HW
6551 * @pf: the PF struct
6552 **/
6553static int i40e_get_capabilities(struct i40e_pf *pf)
6554{
6555 struct i40e_aqc_list_capabilities_element_resp *cap_buf;
6556 u16 data_size;
6557 int buf_len;
6558 int err;
6559
6560 buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
6561 do {
6562 cap_buf = kzalloc(buf_len, GFP_KERNEL);
6563 if (!cap_buf)
6564 return -ENOMEM;
6565
6566 /* this loads the data into the hw struct for us */
6567 err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
6568 &data_size,
6569 i40e_aqc_opc_list_func_capabilities,
6570 NULL);
6571 /* data loaded, buffer no longer needed */
6572 kfree(cap_buf);
6573
6574 if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
6575 /* retry with a larger buffer */
6576 buf_len = data_size;
6577 } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
6578 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006579 "capability discovery failed, err %s aq_err %s\n",
6580 i40e_stat_str(&pf->hw, err),
6581 i40e_aq_str(&pf->hw,
6582 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006583 return -ENODEV;
6584 }
6585 } while (err);
6586
6587 if (pf->hw.debug_mask & I40E_DEBUG_USER)
6588 dev_info(&pf->pdev->dev,
6589 "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",
6590 pf->hw.pf_id, pf->hw.func_caps.num_vfs,
6591 pf->hw.func_caps.num_msix_vectors,
6592 pf->hw.func_caps.num_msix_vectors_vf,
6593 pf->hw.func_caps.fd_filters_guaranteed,
6594 pf->hw.func_caps.fd_filters_best_effort,
6595 pf->hw.func_caps.num_tx_qp,
6596 pf->hw.func_caps.num_vsis);
6597
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00006598#define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
6599 + pf->hw.func_caps.num_vfs)
6600 if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
6601 dev_info(&pf->pdev->dev,
6602 "got num_vsis %d, setting num_vsis to %d\n",
6603 pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
6604 pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
6605 }
6606
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006607 return 0;
6608}
6609
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006610static int i40e_vsi_clear(struct i40e_vsi *vsi);
6611
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006612/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006613 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006614 * @pf: board private structure
6615 **/
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006616static void i40e_fdir_sb_setup(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006617{
6618 struct i40e_vsi *vsi;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006619 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006620
Jesse Brandeburg407e0632014-06-03 23:50:12 +00006621 /* quick workaround for an NVM issue that leaves a critical register
6622 * uninitialized
6623 */
6624 if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
6625 static const u32 hkey[] = {
6626 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
6627 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
6628 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
6629 0x95b3a76d};
6630
6631 for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
6632 wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
6633 }
6634
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006635 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006636 return;
6637
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006638 /* find existing VSI and see if it needs configuring */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006639 vsi = NULL;
Mitch Williams505682c2014-05-20 08:01:37 +00006640 for (i = 0; i < pf->num_alloc_vsi; i++) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006641 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006642 vsi = pf->vsi[i];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006643 break;
6644 }
6645 }
6646
6647 /* create a new VSI if none exists */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006648 if (!vsi) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006649 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
6650 pf->vsi[pf->lan_vsi]->seid, 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006651 if (!vsi) {
6652 dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006653 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
6654 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006655 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006656 }
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006657
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006658 i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006659}
6660
6661/**
6662 * i40e_fdir_teardown - release the Flow Director resources
6663 * @pf: board private structure
6664 **/
6665static void i40e_fdir_teardown(struct i40e_pf *pf)
6666{
6667 int i;
6668
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00006669 i40e_fdir_filter_exit(pf);
Mitch Williams505682c2014-05-20 08:01:37 +00006670 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006671 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
6672 i40e_vsi_release(pf->vsi[i]);
6673 break;
6674 }
6675 }
6676}
6677
6678/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006679 * i40e_prep_for_reset - prep for the core to reset
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006680 * @pf: board private structure
6681 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00006682 * Close up the VFs and other things in prep for PF Reset.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006683 **/
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006684static void i40e_prep_for_reset(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006685{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006686 struct i40e_hw *hw = &pf->hw;
Shannon Nelson60442de2014-04-23 04:50:13 +00006687 i40e_status ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006688 u32 v;
6689
6690 clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
6691 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006692 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006693
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006694 dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006695
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006696 /* quiesce the VSIs and their queues that are not already DOWN */
6697 i40e_pf_quiesce_all_vsi(pf);
6698
Mitch Williams505682c2014-05-20 08:01:37 +00006699 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006700 if (pf->vsi[v])
6701 pf->vsi[v]->seid = 0;
6702 }
6703
6704 i40e_shutdown_adminq(&pf->hw);
6705
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006706 /* call shutdown HMC */
Shannon Nelson60442de2014-04-23 04:50:13 +00006707 if (hw->hmc.hmc_obj) {
6708 ret = i40e_shutdown_lan_hmc(hw);
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006709 if (ret)
Shannon Nelson60442de2014-04-23 04:50:13 +00006710 dev_warn(&pf->pdev->dev,
6711 "shutdown_lan_hmc failed: %d\n", ret);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006712 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006713}
6714
6715/**
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00006716 * i40e_send_version - update firmware with driver version
6717 * @pf: PF struct
6718 */
6719static void i40e_send_version(struct i40e_pf *pf)
6720{
6721 struct i40e_driver_version dv;
6722
6723 dv.major_version = DRV_VERSION_MAJOR;
6724 dv.minor_version = DRV_VERSION_MINOR;
6725 dv.build_version = DRV_VERSION_BUILD;
6726 dv.subbuild_version = 0;
Rickard Strandqvist35a7d802014-07-29 09:26:25 +00006727 strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00006728 i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
6729}
6730
6731/**
Jesse Brandeburg4dda12e2013-12-18 13:46:01 +00006732 * i40e_reset_and_rebuild - reset and rebuild using a saved config
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006733 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006734 * @reinit: if the Main VSI needs to re-initialized.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006735 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006736static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006737{
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006738 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006739 u8 set_fc_aq_fail = 0;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006740 i40e_status ret;
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -04006741 u32 val;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006742 u32 v;
6743
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006744 /* Now we wait for GRST to settle out.
6745 * We don't have to delete the VEBs or VSIs from the hw switch
6746 * because the reset will make them disappear.
6747 */
6748 ret = i40e_pf_reset(hw);
Akeem G Abodunrinb5565402014-04-09 05:59:04 +00006749 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006750 dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006751 set_bit(__I40E_RESET_FAILED, &pf->state);
6752 goto clear_recovery;
Akeem G Abodunrinb5565402014-04-09 05:59:04 +00006753 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006754 pf->pfr_count++;
6755
6756 if (test_bit(__I40E_DOWN, &pf->state))
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006757 goto clear_recovery;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006758 dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006759
6760 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
6761 ret = i40e_init_adminq(&pf->hw);
6762 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006763 dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
6764 i40e_stat_str(&pf->hw, ret),
6765 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006766 goto clear_recovery;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006767 }
6768
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006769 /* re-verify the eeprom if we just had an EMP reset */
Anjali Singhai Jain9df42d12015-01-24 09:58:40 +00006770 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state))
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006771 i40e_verify_eeprom(pf);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006772
Shannon Nelsone78ac4bf2014-05-10 04:49:09 +00006773 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006774 ret = i40e_get_capabilities(pf);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006775 if (ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006776 goto end_core_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006777
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006778 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
6779 hw->func_caps.num_rx_qp,
6780 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
6781 if (ret) {
6782 dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
6783 goto end_core_reset;
6784 }
6785 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
6786 if (ret) {
6787 dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
6788 goto end_core_reset;
6789 }
6790
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006791#ifdef CONFIG_I40E_DCB
6792 ret = i40e_init_pf_dcb(pf);
6793 if (ret) {
Shannon Nelsonaebfc812014-12-11 07:06:38 +00006794 dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
6795 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
6796 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006797 }
6798#endif /* CONFIG_I40E_DCB */
Vasu Dev38e00432014-08-01 13:27:03 -07006799#ifdef I40E_FCOE
Shannon Nelson21364bc2015-08-26 15:14:13 -04006800 i40e_init_pf_fcoe(pf);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006801
Vasu Dev38e00432014-08-01 13:27:03 -07006802#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006803 /* do basic switch setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006804 ret = i40e_setup_pf_switch(pf, reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006805 if (ret)
6806 goto end_core_reset;
6807
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00006808 /* driver is only interested in link up/down and module qualification
6809 * reports from firmware
6810 */
6811 ret = i40e_aq_set_phy_int_mask(&pf->hw,
6812 I40E_AQ_EVENT_LINK_UPDOWN |
6813 I40E_AQ_EVENT_MODULE_QUAL_FAIL, NULL);
6814 if (ret)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006815 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
6816 i40e_stat_str(&pf->hw, ret),
6817 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00006818
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006819 /* make sure our flow control settings are restored */
6820 ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
6821 if (ret)
Neerav Parikh8279e492015-09-03 17:18:50 -04006822 dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
6823 i40e_stat_str(&pf->hw, ret),
6824 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006825
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006826 /* Rebuild the VSIs and VEBs that existed before reset.
6827 * They are still in our local switch element arrays, so only
6828 * need to rebuild the switch model in the HW.
6829 *
6830 * If there were VEBs but the reconstitution failed, we'll try
6831 * try to recover minimal use by getting the basic PF VSI working.
6832 */
6833 if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006834 dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006835 /* find the one VEB connected to the MAC, and find orphans */
6836 for (v = 0; v < I40E_MAX_VEB; v++) {
6837 if (!pf->veb[v])
6838 continue;
6839
6840 if (pf->veb[v]->uplink_seid == pf->mac_seid ||
6841 pf->veb[v]->uplink_seid == 0) {
6842 ret = i40e_reconstitute_veb(pf->veb[v]);
6843
6844 if (!ret)
6845 continue;
6846
6847 /* If Main VEB failed, we're in deep doodoo,
6848 * so give up rebuilding the switch and set up
6849 * for minimal rebuild of PF VSI.
6850 * If orphan failed, we'll report the error
6851 * but try to keep going.
6852 */
6853 if (pf->veb[v]->uplink_seid == pf->mac_seid) {
6854 dev_info(&pf->pdev->dev,
6855 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
6856 ret);
6857 pf->vsi[pf->lan_vsi]->uplink_seid
6858 = pf->mac_seid;
6859 break;
6860 } else if (pf->veb[v]->uplink_seid == 0) {
6861 dev_info(&pf->pdev->dev,
6862 "rebuild of orphan VEB failed: %d\n",
6863 ret);
6864 }
6865 }
6866 }
6867 }
6868
6869 if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
Shannon Nelsoncde4cbc2014-06-04 01:23:17 +00006870 dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006871 /* no VEB, so rebuild only the Main VSI */
6872 ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
6873 if (ret) {
6874 dev_info(&pf->pdev->dev,
6875 "rebuild of Main VSI failed: %d\n", ret);
6876 goto end_core_reset;
6877 }
6878 }
6879
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -04006880 /* Reconfigure hardware for allowing smaller MSS in the case
6881 * of TSO, so that we avoid the MDD being fired and causing
6882 * a reset in the case of small MSS+TSO.
6883 */
6884#define I40E_REG_MSS 0x000E64DC
6885#define I40E_REG_MSS_MIN_MASK 0x3FF0000
6886#define I40E_64BYTE_MSS 0x400000
6887 val = rd32(hw, I40E_REG_MSS);
6888 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
6889 val &= ~I40E_REG_MSS_MIN_MASK;
6890 val |= I40E_64BYTE_MSS;
6891 wr32(hw, I40E_REG_MSS, val);
6892 }
6893
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08006894 if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00006895 msleep(75);
6896 ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
6897 if (ret)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006898 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
6899 i40e_stat_str(&pf->hw, ret),
6900 i40e_aq_str(&pf->hw,
6901 pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006902 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006903 /* reinit the misc interrupt */
6904 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
6905 ret = i40e_setup_misc_vector(pf);
6906
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04006907 /* Add a filter to drop all Flow control frames from any VSI from being
6908 * transmitted. By doing so we stop a malicious VF from sending out
6909 * PAUSE or PFC frames and potentially controlling traffic for other
6910 * PF/VF VSIs.
6911 * The FW can still send Flow control frames if enabled.
6912 */
6913 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
6914 pf->main_vsi_seid);
6915
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006916 /* restart the VSIs that were rebuilt and running before the reset */
6917 i40e_pf_unquiesce_all_vsi(pf);
6918
Mitch Williams69f64b22014-02-13 03:48:46 -08006919 if (pf->num_alloc_vfs) {
6920 for (v = 0; v < pf->num_alloc_vfs; v++)
6921 i40e_reset_vf(&pf->vf[v], true);
6922 }
6923
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006924 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00006925 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006926
6927end_core_reset:
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006928 clear_bit(__I40E_RESET_FAILED, &pf->state);
6929clear_recovery:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006930 clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
6931}
6932
6933/**
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00006934 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006935 * @pf: board private structure
6936 *
6937 * Close up the VFs and other things in prep for a Core Reset,
6938 * then get ready to rebuild the world.
6939 **/
6940static void i40e_handle_reset_warning(struct i40e_pf *pf)
6941{
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006942 i40e_prep_for_reset(pf);
6943 i40e_reset_and_rebuild(pf, false);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006944}
6945
6946/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006947 * i40e_handle_mdd_event
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00006948 * @pf: pointer to the PF structure
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006949 *
6950 * Called from the MDD irq handler to identify possibly malicious vfs
6951 **/
6952static void i40e_handle_mdd_event(struct i40e_pf *pf)
6953{
6954 struct i40e_hw *hw = &pf->hw;
6955 bool mdd_detected = false;
Neerav Parikhdf430b12014-06-04 01:23:15 +00006956 bool pf_mdd_detected = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006957 struct i40e_vf *vf;
6958 u32 reg;
6959 int i;
6960
6961 if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
6962 return;
6963
6964 /* find what triggered the MDD event */
6965 reg = rd32(hw, I40E_GL_MDET_TX);
6966 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006967 u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
6968 I40E_GL_MDET_TX_PF_NUM_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00006969 u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006970 I40E_GL_MDET_TX_VF_NUM_SHIFT;
Dan Carpenter013f6572014-10-22 20:06:29 -07006971 u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006972 I40E_GL_MDET_TX_EVENT_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00006973 u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
6974 I40E_GL_MDET_TX_QUEUE_SHIFT) -
6975 pf->hw.func_caps.base_queue;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00006976 if (netif_msg_tx_err(pf))
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00006977 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 +00006978 event, queue, pf_num, vf_num);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006979 wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
6980 mdd_detected = true;
6981 }
6982 reg = rd32(hw, I40E_GL_MDET_RX);
6983 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006984 u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
6985 I40E_GL_MDET_RX_FUNCTION_SHIFT;
Dan Carpenter013f6572014-10-22 20:06:29 -07006986 u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006987 I40E_GL_MDET_RX_EVENT_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00006988 u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
6989 I40E_GL_MDET_RX_QUEUE_SHIFT) -
6990 pf->hw.func_caps.base_queue;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00006991 if (netif_msg_rx_err(pf))
6992 dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
6993 event, queue, func);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006994 wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
6995 mdd_detected = true;
6996 }
6997
Neerav Parikhdf430b12014-06-04 01:23:15 +00006998 if (mdd_detected) {
6999 reg = rd32(hw, I40E_PF_MDET_TX);
7000 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
7001 wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007002 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
Neerav Parikhdf430b12014-06-04 01:23:15 +00007003 pf_mdd_detected = true;
7004 }
7005 reg = rd32(hw, I40E_PF_MDET_RX);
7006 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
7007 wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007008 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
Neerav Parikhdf430b12014-06-04 01:23:15 +00007009 pf_mdd_detected = true;
7010 }
7011 /* Queue belongs to the PF, initiate a reset */
7012 if (pf_mdd_detected) {
7013 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
7014 i40e_service_event_schedule(pf);
7015 }
7016 }
7017
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007018 /* see if one of the VFs needs its hand slapped */
7019 for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
7020 vf = &(pf->vf[i]);
7021 reg = rd32(hw, I40E_VP_MDET_TX(i));
7022 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
7023 wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
7024 vf->num_mdd_events++;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007025 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
7026 i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007027 }
7028
7029 reg = rd32(hw, I40E_VP_MDET_RX(i));
7030 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
7031 wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
7032 vf->num_mdd_events++;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007033 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
7034 i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007035 }
7036
7037 if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
7038 dev_info(&pf->pdev->dev,
7039 "Too many MDD events on VF %d, disabled\n", i);
7040 dev_info(&pf->pdev->dev,
7041 "Use PF Control I/F to re-enable the VF\n");
7042 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
7043 }
7044 }
7045
7046 /* re-enable mdd interrupt cause */
7047 clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
7048 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
7049 reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
7050 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
7051 i40e_flush(hw);
7052}
7053
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007054/**
Singhai, Anjali6a899022015-12-14 12:21:18 -08007055 * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007056 * @pf: board private structure
7057 **/
Singhai, Anjali6a899022015-12-14 12:21:18 -08007058static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007059{
Singhai, Anjali6a899022015-12-14 12:21:18 -08007060#if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007061 struct i40e_hw *hw = &pf->hw;
7062 i40e_status ret;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007063 __be16 port;
7064 int i;
7065
Singhai, Anjali6a899022015-12-14 12:21:18 -08007066 if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC))
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007067 return;
7068
Singhai, Anjali6a899022015-12-14 12:21:18 -08007069 pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007070
7071 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
Singhai, Anjali6a899022015-12-14 12:21:18 -08007072 if (pf->pending_udp_bitmap & BIT_ULL(i)) {
7073 pf->pending_udp_bitmap &= ~BIT_ULL(i);
7074 port = pf->udp_ports[i].index;
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007075 if (port)
7076 ret = i40e_aq_add_udp_tunnel(hw, ntohs(port),
Singhai, Anjali6a899022015-12-14 12:21:18 -08007077 pf->udp_ports[i].type,
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007078 NULL, NULL);
7079 else
7080 ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007081
7082 if (ret) {
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007083 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007084 "%s vxlan port %d, index %d failed, err %s aq_err %s\n",
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007085 port ? "add" : "delete",
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007086 ntohs(port), i,
7087 i40e_stat_str(&pf->hw, ret),
7088 i40e_aq_str(&pf->hw,
7089 pf->hw.aq.asq_last_status));
Singhai, Anjali6a899022015-12-14 12:21:18 -08007090 pf->udp_ports[i].index = 0;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007091 }
7092 }
7093 }
Singhai, Anjali6a899022015-12-14 12:21:18 -08007094#endif
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007095}
7096
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007097/**
7098 * i40e_service_task - Run the driver's async subtasks
7099 * @work: pointer to work_struct containing our data
7100 **/
7101static void i40e_service_task(struct work_struct *work)
7102{
7103 struct i40e_pf *pf = container_of(work,
7104 struct i40e_pf,
7105 service_task);
7106 unsigned long start_time = jiffies;
7107
Shannon Nelsone57a2fe2014-06-03 23:50:19 +00007108 /* don't bother with service tasks if a reset is in progress */
7109 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
7110 i40e_service_event_complete(pf);
7111 return;
7112 }
7113
Kiran Patilb03a8c12015-09-24 18:13:15 -04007114 i40e_detect_recover_hung(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007115 i40e_reset_subtask(pf);
7116 i40e_handle_mdd_event(pf);
7117 i40e_vc_process_vflr_event(pf);
7118 i40e_watchdog_subtask(pf);
7119 i40e_fdir_reinit_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007120 i40e_sync_filters_subtask(pf);
Singhai, Anjali6a899022015-12-14 12:21:18 -08007121 i40e_sync_udp_filters_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007122 i40e_clean_adminq_subtask(pf);
7123
7124 i40e_service_event_complete(pf);
7125
7126 /* If the tasks have taken longer than one timer cycle or there
7127 * is more work to be done, reschedule the service task now
7128 * rather than wait for the timer to tick again.
7129 */
7130 if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
7131 test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
7132 test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
7133 test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
7134 i40e_service_event_schedule(pf);
7135}
7136
7137/**
7138 * i40e_service_timer - timer callback
7139 * @data: pointer to PF struct
7140 **/
7141static void i40e_service_timer(unsigned long data)
7142{
7143 struct i40e_pf *pf = (struct i40e_pf *)data;
7144
7145 mod_timer(&pf->service_timer,
7146 round_jiffies(jiffies + pf->service_timer_period));
7147 i40e_service_event_schedule(pf);
7148}
7149
7150/**
7151 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
7152 * @vsi: the VSI being configured
7153 **/
7154static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
7155{
7156 struct i40e_pf *pf = vsi->back;
7157
7158 switch (vsi->type) {
7159 case I40E_VSI_MAIN:
7160 vsi->alloc_queue_pairs = pf->num_lan_qps;
7161 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7162 I40E_REQ_DESCRIPTOR_MULTIPLE);
7163 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7164 vsi->num_q_vectors = pf->num_lan_msix;
7165 else
7166 vsi->num_q_vectors = 1;
7167
7168 break;
7169
7170 case I40E_VSI_FDIR:
7171 vsi->alloc_queue_pairs = 1;
7172 vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
7173 I40E_REQ_DESCRIPTOR_MULTIPLE);
7174 vsi->num_q_vectors = 1;
7175 break;
7176
7177 case I40E_VSI_VMDQ2:
7178 vsi->alloc_queue_pairs = pf->num_vmdq_qps;
7179 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7180 I40E_REQ_DESCRIPTOR_MULTIPLE);
7181 vsi->num_q_vectors = pf->num_vmdq_msix;
7182 break;
7183
7184 case I40E_VSI_SRIOV:
7185 vsi->alloc_queue_pairs = pf->num_vf_qps;
7186 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7187 I40E_REQ_DESCRIPTOR_MULTIPLE);
7188 break;
7189
Vasu Dev38e00432014-08-01 13:27:03 -07007190#ifdef I40E_FCOE
7191 case I40E_VSI_FCOE:
7192 vsi->alloc_queue_pairs = pf->num_fcoe_qps;
7193 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7194 I40E_REQ_DESCRIPTOR_MULTIPLE);
7195 vsi->num_q_vectors = pf->num_fcoe_msix;
7196 break;
7197
7198#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007199 default:
7200 WARN_ON(1);
7201 return -ENODATA;
7202 }
7203
7204 return 0;
7205}
7206
7207/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007208 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
7209 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007210 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007211 *
7212 * On error: returns error code (negative)
7213 * On success: returns 0
7214 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007215static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007216{
7217 int size;
7218 int ret = 0;
7219
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00007220 /* allocate memory for both Tx and Rx ring pointers */
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007221 size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
7222 vsi->tx_rings = kzalloc(size, GFP_KERNEL);
7223 if (!vsi->tx_rings)
7224 return -ENOMEM;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007225 vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
7226
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007227 if (alloc_qvectors) {
7228 /* allocate memory for q_vector pointers */
Julia Lawallf57e4fb2014-07-30 03:11:09 +00007229 size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007230 vsi->q_vectors = kzalloc(size, GFP_KERNEL);
7231 if (!vsi->q_vectors) {
7232 ret = -ENOMEM;
7233 goto err_vectors;
7234 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007235 }
7236 return ret;
7237
7238err_vectors:
7239 kfree(vsi->tx_rings);
7240 return ret;
7241}
7242
7243/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007244 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
7245 * @pf: board private structure
7246 * @type: type of VSI
7247 *
7248 * On error: returns error code (negative)
7249 * On success: returns vsi index in PF (positive)
7250 **/
7251static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
7252{
7253 int ret = -ENODEV;
7254 struct i40e_vsi *vsi;
7255 int vsi_idx;
7256 int i;
7257
7258 /* Need to protect the allocation of the VSIs at the PF level */
7259 mutex_lock(&pf->switch_mutex);
7260
7261 /* VSI list may be fragmented if VSI creation/destruction has
7262 * been happening. We can afford to do a quick scan to look
7263 * for any free VSIs in the list.
7264 *
7265 * find next empty vsi slot, looping back around if necessary
7266 */
7267 i = pf->next_vsi;
Mitch Williams505682c2014-05-20 08:01:37 +00007268 while (i < pf->num_alloc_vsi && pf->vsi[i])
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007269 i++;
Mitch Williams505682c2014-05-20 08:01:37 +00007270 if (i >= pf->num_alloc_vsi) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007271 i = 0;
7272 while (i < pf->next_vsi && pf->vsi[i])
7273 i++;
7274 }
7275
Mitch Williams505682c2014-05-20 08:01:37 +00007276 if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007277 vsi_idx = i; /* Found one! */
7278 } else {
7279 ret = -ENODEV;
Alexander Duyck493fb302013-09-28 07:01:44 +00007280 goto unlock_pf; /* out of VSI slots! */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007281 }
7282 pf->next_vsi = ++i;
7283
7284 vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
7285 if (!vsi) {
7286 ret = -ENOMEM;
Alexander Duyck493fb302013-09-28 07:01:44 +00007287 goto unlock_pf;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007288 }
7289 vsi->type = type;
7290 vsi->back = pf;
7291 set_bit(__I40E_DOWN, &vsi->state);
7292 vsi->flags = 0;
7293 vsi->idx = vsi_idx;
7294 vsi->rx_itr_setting = pf->rx_itr_default;
7295 vsi->tx_itr_setting = pf->tx_itr_default;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04007296 vsi->int_rate_limit = 0;
Anjali Singhai Jain5db4cb52015-02-24 06:58:49 +00007297 vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
7298 pf->rss_table_size : 64;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007299 vsi->netdev_registered = false;
7300 vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
7301 INIT_LIST_HEAD(&vsi->mac_filter_list);
Shannon Nelson63741842014-04-23 04:50:16 +00007302 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007303
Alexander Duyck9f65e152013-09-28 06:00:58 +00007304 ret = i40e_set_num_rings_in_vsi(vsi);
7305 if (ret)
7306 goto err_rings;
7307
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007308 ret = i40e_vsi_alloc_arrays(vsi, true);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007309 if (ret)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007310 goto err_rings;
Alexander Duyck493fb302013-09-28 07:01:44 +00007311
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007312 /* Setup default MSIX irq handler for VSI */
7313 i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
7314
Kiran Patil21659032015-09-30 14:09:03 -04007315 /* Initialize VSI lock */
7316 spin_lock_init(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007317 pf->vsi[vsi_idx] = vsi;
7318 ret = vsi_idx;
Alexander Duyck493fb302013-09-28 07:01:44 +00007319 goto unlock_pf;
7320
Alexander Duyck9f65e152013-09-28 06:00:58 +00007321err_rings:
Alexander Duyck493fb302013-09-28 07:01:44 +00007322 pf->next_vsi = i - 1;
7323 kfree(vsi);
7324unlock_pf:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007325 mutex_unlock(&pf->switch_mutex);
7326 return ret;
7327}
7328
7329/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007330 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
7331 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007332 * @free_qvectors: a bool to specify if q_vectors need to be freed.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007333 *
7334 * On error: returns error code (negative)
7335 * On success: returns 0
7336 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007337static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007338{
7339 /* free the ring and vector containers */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007340 if (free_qvectors) {
7341 kfree(vsi->q_vectors);
7342 vsi->q_vectors = NULL;
7343 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007344 kfree(vsi->tx_rings);
7345 vsi->tx_rings = NULL;
7346 vsi->rx_rings = NULL;
7347}
7348
7349/**
Helin Zhang28c58692015-10-26 19:44:27 -04007350 * i40e_clear_rss_config_user - clear the user configured RSS hash keys
7351 * and lookup table
7352 * @vsi: Pointer to VSI structure
7353 */
7354static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
7355{
7356 if (!vsi)
7357 return;
7358
7359 kfree(vsi->rss_hkey_user);
7360 vsi->rss_hkey_user = NULL;
7361
7362 kfree(vsi->rss_lut_user);
7363 vsi->rss_lut_user = NULL;
7364}
7365
7366/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007367 * i40e_vsi_clear - Deallocate the VSI provided
7368 * @vsi: the VSI being un-configured
7369 **/
7370static int i40e_vsi_clear(struct i40e_vsi *vsi)
7371{
7372 struct i40e_pf *pf;
7373
7374 if (!vsi)
7375 return 0;
7376
7377 if (!vsi->back)
7378 goto free_vsi;
7379 pf = vsi->back;
7380
7381 mutex_lock(&pf->switch_mutex);
7382 if (!pf->vsi[vsi->idx]) {
7383 dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
7384 vsi->idx, vsi->idx, vsi, vsi->type);
7385 goto unlock_vsi;
7386 }
7387
7388 if (pf->vsi[vsi->idx] != vsi) {
7389 dev_err(&pf->pdev->dev,
7390 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
7391 pf->vsi[vsi->idx]->idx,
7392 pf->vsi[vsi->idx],
7393 pf->vsi[vsi->idx]->type,
7394 vsi->idx, vsi, vsi->type);
7395 goto unlock_vsi;
7396 }
7397
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00007398 /* updates the PF for this cleared vsi */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007399 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
7400 i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
7401
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007402 i40e_vsi_free_arrays(vsi, true);
Helin Zhang28c58692015-10-26 19:44:27 -04007403 i40e_clear_rss_config_user(vsi);
Alexander Duyck493fb302013-09-28 07:01:44 +00007404
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007405 pf->vsi[vsi->idx] = NULL;
7406 if (vsi->idx < pf->next_vsi)
7407 pf->next_vsi = vsi->idx;
7408
7409unlock_vsi:
7410 mutex_unlock(&pf->switch_mutex);
7411free_vsi:
7412 kfree(vsi);
7413
7414 return 0;
7415}
7416
7417/**
Alexander Duyck9f65e152013-09-28 06:00:58 +00007418 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
7419 * @vsi: the VSI being cleaned
7420 **/
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00007421static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007422{
7423 int i;
7424
Greg Rose8e9dca52013-12-18 13:45:53 +00007425 if (vsi->tx_rings && vsi->tx_rings[0]) {
Neerav Parikhd7397642013-11-28 06:39:37 +00007426 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Mitch Williams00403f02013-09-28 07:13:13 +00007427 kfree_rcu(vsi->tx_rings[i], rcu);
7428 vsi->tx_rings[i] = NULL;
7429 vsi->rx_rings[i] = NULL;
7430 }
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00007431 }
Alexander Duyck9f65e152013-09-28 06:00:58 +00007432}
7433
7434/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007435 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
7436 * @vsi: the VSI being configured
7437 **/
7438static int i40e_alloc_rings(struct i40e_vsi *vsi)
7439{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00007440 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007441 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007442 int i;
7443
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007444 /* Set basic values in the rings to be used later during open() */
Neerav Parikhd7397642013-11-28 06:39:37 +00007445 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00007446 /* allocate space for both Tx and Rx in one shot */
Alexander Duyck9f65e152013-09-28 06:00:58 +00007447 tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
7448 if (!tx_ring)
7449 goto err_out;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007450
7451 tx_ring->queue_index = i;
7452 tx_ring->reg_idx = vsi->base_queue + i;
7453 tx_ring->ring_active = false;
7454 tx_ring->vsi = vsi;
7455 tx_ring->netdev = vsi->netdev;
7456 tx_ring->dev = &pf->pdev->dev;
7457 tx_ring->count = vsi->num_desc;
7458 tx_ring->size = 0;
7459 tx_ring->dcb_tc = 0;
Anjali Singhai Jain8e0764b2015-06-05 12:20:30 -04007460 if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
7461 tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
Anjali Singhai Jain527274c2015-06-05 12:20:31 -04007462 if (vsi->back->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE)
7463 tx_ring->flags |= I40E_TXR_FLAGS_OUTER_UDP_CSUM;
Alexander Duyck9f65e152013-09-28 06:00:58 +00007464 vsi->tx_rings[i] = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007465
Alexander Duyck9f65e152013-09-28 06:00:58 +00007466 rx_ring = &tx_ring[1];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007467 rx_ring->queue_index = i;
7468 rx_ring->reg_idx = vsi->base_queue + i;
7469 rx_ring->ring_active = false;
7470 rx_ring->vsi = vsi;
7471 rx_ring->netdev = vsi->netdev;
7472 rx_ring->dev = &pf->pdev->dev;
7473 rx_ring->count = vsi->num_desc;
7474 rx_ring->size = 0;
7475 rx_ring->dcb_tc = 0;
7476 if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED)
7477 set_ring_16byte_desc_enabled(rx_ring);
7478 else
7479 clear_ring_16byte_desc_enabled(rx_ring);
Alexander Duyck9f65e152013-09-28 06:00:58 +00007480 vsi->rx_rings[i] = rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007481 }
7482
7483 return 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00007484
7485err_out:
7486 i40e_vsi_clear_rings(vsi);
7487 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007488}
7489
7490/**
7491 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
7492 * @pf: board private structure
7493 * @vectors: the number of MSI-X vectors to request
7494 *
7495 * Returns the number of vectors reserved, or error
7496 **/
7497static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
7498{
Alexander Gordeev7b37f372014-02-18 11:11:42 +01007499 vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
7500 I40E_MIN_MSIX, vectors);
7501 if (vectors < 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007502 dev_info(&pf->pdev->dev,
Alexander Gordeev7b37f372014-02-18 11:11:42 +01007503 "MSI-X vector reservation failed: %d\n", vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007504 vectors = 0;
7505 }
7506
7507 return vectors;
7508}
7509
7510/**
7511 * i40e_init_msix - Setup the MSIX capability
7512 * @pf: board private structure
7513 *
7514 * Work with the OS to set up the MSIX vectors needed.
7515 *
Shannon Nelson3b444392015-02-26 16:15:57 +00007516 * Returns the number of vectors reserved or negative on failure
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007517 **/
7518static int i40e_init_msix(struct i40e_pf *pf)
7519{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007520 struct i40e_hw *hw = &pf->hw;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007521 int vectors_left;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007522 int v_budget, i;
Shannon Nelson3b444392015-02-26 16:15:57 +00007523 int v_actual;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007524
7525 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
7526 return -ENODEV;
7527
7528 /* The number of vectors we'll request will be comprised of:
7529 * - Add 1 for "other" cause for Admin Queue events, etc.
7530 * - The number of LAN queue pairs
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00007531 * - Queues being used for RSS.
7532 * We don't need as many as max_rss_size vectors.
7533 * use rss_size instead in the calculation since that
7534 * is governed by number of cpus in the system.
7535 * - assumes symmetric Tx/Rx pairing
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007536 * - The number of VMDq pairs
Vasu Dev38e00432014-08-01 13:27:03 -07007537#ifdef I40E_FCOE
7538 * - The number of FCOE qps.
7539#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007540 * Once we count this up, try the request.
7541 *
7542 * If we can't get what we want, we'll simplify to nearly nothing
7543 * and try again. If that still fails, we punt.
7544 */
Shannon Nelson1e200e42015-02-27 09:15:24 +00007545 vectors_left = hw->func_caps.num_msix_vectors;
7546 v_budget = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007547
Shannon Nelson1e200e42015-02-27 09:15:24 +00007548 /* reserve one vector for miscellaneous handler */
7549 if (vectors_left) {
7550 v_budget++;
7551 vectors_left--;
7552 }
7553
7554 /* reserve vectors for the main PF traffic queues */
7555 pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left);
7556 vectors_left -= pf->num_lan_msix;
7557 v_budget += pf->num_lan_msix;
7558
7559 /* reserve one vector for sideband flow director */
7560 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
7561 if (vectors_left) {
7562 v_budget++;
7563 vectors_left--;
7564 } else {
7565 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
7566 }
7567 }
John W Linville83840e42015-01-14 03:06:28 +00007568
Vasu Dev38e00432014-08-01 13:27:03 -07007569#ifdef I40E_FCOE
Shannon Nelson1e200e42015-02-27 09:15:24 +00007570 /* can we reserve enough for FCoE? */
Vasu Dev38e00432014-08-01 13:27:03 -07007571 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
Shannon Nelson1e200e42015-02-27 09:15:24 +00007572 if (!vectors_left)
7573 pf->num_fcoe_msix = 0;
7574 else if (vectors_left >= pf->num_fcoe_qps)
7575 pf->num_fcoe_msix = pf->num_fcoe_qps;
7576 else
7577 pf->num_fcoe_msix = 1;
Vasu Dev38e00432014-08-01 13:27:03 -07007578 v_budget += pf->num_fcoe_msix;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007579 vectors_left -= pf->num_fcoe_msix;
Vasu Dev38e00432014-08-01 13:27:03 -07007580 }
Shannon Nelson1e200e42015-02-27 09:15:24 +00007581
Vasu Dev38e00432014-08-01 13:27:03 -07007582#endif
Shannon Nelson1e200e42015-02-27 09:15:24 +00007583 /* any vectors left over go for VMDq support */
7584 if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
7585 int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
7586 int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
7587
7588 /* if we're short on vectors for what's desired, we limit
7589 * the queues per vmdq. If this is still more than are
7590 * available, the user will need to change the number of
7591 * queues/vectors used by the PF later with the ethtool
7592 * channels command
7593 */
7594 if (vmdq_vecs < vmdq_vecs_wanted)
7595 pf->num_vmdq_qps = 1;
7596 pf->num_vmdq_msix = pf->num_vmdq_qps;
7597
7598 v_budget += vmdq_vecs;
7599 vectors_left -= vmdq_vecs;
7600 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007601
7602 pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
7603 GFP_KERNEL);
7604 if (!pf->msix_entries)
7605 return -ENOMEM;
7606
7607 for (i = 0; i < v_budget; i++)
7608 pf->msix_entries[i].entry = i;
Shannon Nelson3b444392015-02-26 16:15:57 +00007609 v_actual = i40e_reserve_msix_vectors(pf, v_budget);
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007610
Shannon Nelson3b444392015-02-26 16:15:57 +00007611 if (v_actual != v_budget) {
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007612 /* If we have limited resources, we will start with no vectors
7613 * for the special features and then allocate vectors to some
7614 * of these features based on the policy and at the end disable
7615 * the features that did not get any vectors.
7616 */
Vasu Dev38e00432014-08-01 13:27:03 -07007617#ifdef I40E_FCOE
7618 pf->num_fcoe_qps = 0;
7619 pf->num_fcoe_msix = 0;
7620#endif
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007621 pf->num_vmdq_msix = 0;
7622 }
7623
Shannon Nelson3b444392015-02-26 16:15:57 +00007624 if (v_actual < I40E_MIN_MSIX) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007625 pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
7626 kfree(pf->msix_entries);
7627 pf->msix_entries = NULL;
7628 return -ENODEV;
7629
Shannon Nelson3b444392015-02-26 16:15:57 +00007630 } else if (v_actual == I40E_MIN_MSIX) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007631 /* Adjust for minimal MSIX use */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007632 pf->num_vmdq_vsis = 0;
7633 pf->num_vmdq_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007634 pf->num_lan_qps = 1;
7635 pf->num_lan_msix = 1;
7636
Shannon Nelson3b444392015-02-26 16:15:57 +00007637 } else if (v_actual != v_budget) {
7638 int vec;
7639
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007640 /* reserve the misc vector */
Shannon Nelson3b444392015-02-26 16:15:57 +00007641 vec = v_actual - 1;
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007642
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007643 /* Scale vector usage down */
7644 pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007645 pf->num_vmdq_vsis = 1;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007646 pf->num_vmdq_qps = 1;
7647 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007648
7649 /* partition out the remaining vectors */
7650 switch (vec) {
7651 case 2:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007652 pf->num_lan_msix = 1;
7653 break;
7654 case 3:
Vasu Dev38e00432014-08-01 13:27:03 -07007655#ifdef I40E_FCOE
7656 /* give one vector to FCoE */
7657 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
7658 pf->num_lan_msix = 1;
7659 pf->num_fcoe_msix = 1;
7660 }
7661#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007662 pf->num_lan_msix = 2;
Vasu Dev38e00432014-08-01 13:27:03 -07007663#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007664 break;
7665 default:
Vasu Dev38e00432014-08-01 13:27:03 -07007666#ifdef I40E_FCOE
7667 /* give one vector to FCoE */
7668 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
7669 pf->num_fcoe_msix = 1;
7670 vec--;
7671 }
7672#endif
Shannon Nelson1e200e42015-02-27 09:15:24 +00007673 /* give the rest to the PF */
7674 pf->num_lan_msix = min_t(int, vec, pf->num_lan_qps);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007675 break;
7676 }
7677 }
7678
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007679 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
7680 (pf->num_vmdq_msix == 0)) {
7681 dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
7682 pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
7683 }
Vasu Dev38e00432014-08-01 13:27:03 -07007684#ifdef I40E_FCOE
7685
7686 if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) {
7687 dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n");
7688 pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
7689 }
7690#endif
Shannon Nelson3b444392015-02-26 16:15:57 +00007691 return v_actual;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007692}
7693
7694/**
Greg Rose90e04072014-03-06 08:59:57 +00007695 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
Alexander Duyck493fb302013-09-28 07:01:44 +00007696 * @vsi: the VSI being configured
7697 * @v_idx: index of the vector in the vsi struct
7698 *
7699 * We allocate one q_vector. If allocation fails we return -ENOMEM.
7700 **/
Greg Rose90e04072014-03-06 08:59:57 +00007701static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx)
Alexander Duyck493fb302013-09-28 07:01:44 +00007702{
7703 struct i40e_q_vector *q_vector;
7704
7705 /* allocate q_vector */
7706 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
7707 if (!q_vector)
7708 return -ENOMEM;
7709
7710 q_vector->vsi = vsi;
7711 q_vector->v_idx = v_idx;
7712 cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
7713 if (vsi->netdev)
7714 netif_napi_add(vsi->netdev, &q_vector->napi,
Jesse Brandeburgeefeace2014-05-10 04:49:13 +00007715 i40e_napi_poll, NAPI_POLL_WEIGHT);
Alexander Duyck493fb302013-09-28 07:01:44 +00007716
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00007717 q_vector->rx.latency_range = I40E_LOW_LATENCY;
7718 q_vector->tx.latency_range = I40E_LOW_LATENCY;
7719
Alexander Duyck493fb302013-09-28 07:01:44 +00007720 /* tie q_vector and vsi together */
7721 vsi->q_vectors[v_idx] = q_vector;
7722
7723 return 0;
7724}
7725
7726/**
Greg Rose90e04072014-03-06 08:59:57 +00007727 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007728 * @vsi: the VSI being configured
7729 *
7730 * We allocate one q_vector per queue interrupt. If allocation fails we
7731 * return -ENOMEM.
7732 **/
Greg Rose90e04072014-03-06 08:59:57 +00007733static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007734{
7735 struct i40e_pf *pf = vsi->back;
7736 int v_idx, num_q_vectors;
Alexander Duyck493fb302013-09-28 07:01:44 +00007737 int err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007738
7739 /* if not MSIX, give the one vector only to the LAN VSI */
7740 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7741 num_q_vectors = vsi->num_q_vectors;
7742 else if (vsi == pf->vsi[pf->lan_vsi])
7743 num_q_vectors = 1;
7744 else
7745 return -EINVAL;
7746
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007747 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
Greg Rose90e04072014-03-06 08:59:57 +00007748 err = i40e_vsi_alloc_q_vector(vsi, v_idx);
Alexander Duyck493fb302013-09-28 07:01:44 +00007749 if (err)
7750 goto err_out;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007751 }
7752
7753 return 0;
Alexander Duyck493fb302013-09-28 07:01:44 +00007754
7755err_out:
7756 while (v_idx--)
7757 i40e_free_q_vector(vsi, v_idx);
7758
7759 return err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007760}
7761
7762/**
7763 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
7764 * @pf: board private structure to initialize
7765 **/
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007766static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007767{
Shannon Nelson3b444392015-02-26 16:15:57 +00007768 int vectors = 0;
7769 ssize_t size;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007770
7771 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
Shannon Nelson3b444392015-02-26 16:15:57 +00007772 vectors = i40e_init_msix(pf);
7773 if (vectors < 0) {
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08007774 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -07007775#ifdef I40E_FCOE
7776 I40E_FLAG_FCOE_ENABLED |
7777#endif
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08007778 I40E_FLAG_RSS_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00007779 I40E_FLAG_DCB_CAPABLE |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08007780 I40E_FLAG_SRIOV_ENABLED |
7781 I40E_FLAG_FD_SB_ENABLED |
7782 I40E_FLAG_FD_ATR_ENABLED |
7783 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007784
7785 /* rework the queue expectations without MSIX */
7786 i40e_determine_queue_usage(pf);
7787 }
7788 }
7789
7790 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
7791 (pf->flags & I40E_FLAG_MSI_ENABLED)) {
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08007792 dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
Shannon Nelson3b444392015-02-26 16:15:57 +00007793 vectors = pci_enable_msi(pf->pdev);
7794 if (vectors < 0) {
7795 dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
7796 vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007797 pf->flags &= ~I40E_FLAG_MSI_ENABLED;
7798 }
Shannon Nelson3b444392015-02-26 16:15:57 +00007799 vectors = 1; /* one MSI or Legacy vector */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007800 }
7801
Shannon Nelson958a3e32013-09-28 07:13:28 +00007802 if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08007803 dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
Shannon Nelson958a3e32013-09-28 07:13:28 +00007804
Shannon Nelson3b444392015-02-26 16:15:57 +00007805 /* set up vector assignment tracking */
7806 size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
7807 pf->irq_pile = kzalloc(size, GFP_KERNEL);
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007808 if (!pf->irq_pile) {
7809 dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n");
7810 return -ENOMEM;
7811 }
Shannon Nelson3b444392015-02-26 16:15:57 +00007812 pf->irq_pile->num_entries = vectors;
7813 pf->irq_pile->search_hint = 0;
7814
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007815 /* track first vector for misc interrupts, ignore return */
Shannon Nelson3b444392015-02-26 16:15:57 +00007816 (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007817
7818 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007819}
7820
7821/**
7822 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
7823 * @pf: board private structure
7824 *
7825 * This sets up the handler for MSIX 0, which is used to manage the
7826 * non-queue interrupts, e.g. AdminQ and errors. This is not used
7827 * when in MSI or Legacy interrupt mode.
7828 **/
7829static int i40e_setup_misc_vector(struct i40e_pf *pf)
7830{
7831 struct i40e_hw *hw = &pf->hw;
7832 int err = 0;
7833
7834 /* Only request the irq if this is the first time through, and
7835 * not when we're rebuilding after a Reset
7836 */
7837 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
7838 err = request_irq(pf->msix_entries[0].vector,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00007839 i40e_intr, 0, pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007840 if (err) {
7841 dev_info(&pf->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08007842 "request_irq for %s failed: %d\n",
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00007843 pf->int_name, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007844 return -EFAULT;
7845 }
7846 }
7847
Jacob Kellerab437b52014-12-14 01:55:08 +00007848 i40e_enable_misc_int_causes(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007849
7850 /* associate no queues to the misc vector */
7851 wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
7852 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
7853
7854 i40e_flush(hw);
7855
7856 i40e_irq_dynamic_enable_icr0(pf);
7857
7858 return err;
7859}
7860
7861/**
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04007862 * i40e_config_rss_aq - Prepare for RSS using AQ commands
7863 * @vsi: vsi structure
7864 * @seed: RSS hash seed
7865 **/
Helin Zhange69ff812015-10-21 19:56:22 -04007866static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
7867 u8 *lut, u16 lut_size)
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04007868{
7869 struct i40e_aqc_get_set_rss_key_data rss_key;
7870 struct i40e_pf *pf = vsi->back;
7871 struct i40e_hw *hw = &pf->hw;
7872 bool pf_lut = false;
7873 u8 *rss_lut;
7874 int ret, i;
7875
7876 memset(&rss_key, 0, sizeof(rss_key));
7877 memcpy(&rss_key, seed, sizeof(rss_key));
7878
7879 rss_lut = kzalloc(pf->rss_table_size, GFP_KERNEL);
7880 if (!rss_lut)
7881 return -ENOMEM;
7882
7883 /* Populate the LUT with max no. of queues in round robin fashion */
7884 for (i = 0; i < vsi->rss_table_size; i++)
7885 rss_lut[i] = i % vsi->rss_size;
7886
7887 ret = i40e_aq_set_rss_key(hw, vsi->id, &rss_key);
7888 if (ret) {
7889 dev_info(&pf->pdev->dev,
7890 "Cannot set RSS key, err %s aq_err %s\n",
7891 i40e_stat_str(&pf->hw, ret),
7892 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai126b63d2015-08-24 13:26:53 -07007893 goto config_rss_aq_out;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04007894 }
7895
7896 if (vsi->type == I40E_VSI_MAIN)
7897 pf_lut = true;
7898
7899 ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, rss_lut,
7900 vsi->rss_table_size);
7901 if (ret)
7902 dev_info(&pf->pdev->dev,
7903 "Cannot set RSS lut, err %s aq_err %s\n",
7904 i40e_stat_str(&pf->hw, ret),
7905 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
7906
Anjali Singhai126b63d2015-08-24 13:26:53 -07007907config_rss_aq_out:
7908 kfree(rss_lut);
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04007909 return ret;
7910}
7911
7912/**
7913 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
7914 * @vsi: VSI structure
7915 **/
7916static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
7917{
7918 u8 seed[I40E_HKEY_ARRAY_SIZE];
7919 struct i40e_pf *pf = vsi->back;
Helin Zhange69ff812015-10-21 19:56:22 -04007920 u8 *lut;
7921 int ret;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04007922
Helin Zhange69ff812015-10-21 19:56:22 -04007923 if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE))
7924 return 0;
7925
7926 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
7927 if (!lut)
7928 return -ENOMEM;
7929
7930 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04007931 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
Helin Zhangacd65442015-10-26 19:44:28 -04007932 vsi->rss_size = min_t(int, pf->alloc_rss_size, vsi->num_queue_pairs);
Helin Zhange69ff812015-10-21 19:56:22 -04007933 ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
7934 kfree(lut);
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04007935
Helin Zhange69ff812015-10-21 19:56:22 -04007936 return ret;
7937}
7938
7939/**
Anjali Singhai Jain95a73782015-12-22 14:25:04 -08007940 * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
7941 * @vsi: Pointer to vsi structure
7942 * @seed: Buffter to store the hash keys
7943 * @lut: Buffer to store the lookup table entries
7944 * @lut_size: Size of buffer to store the lookup table entries
7945 *
7946 * Return 0 on success, negative on failure
7947 */
7948static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
7949 u8 *lut, u16 lut_size)
7950{
7951 struct i40e_pf *pf = vsi->back;
7952 struct i40e_hw *hw = &pf->hw;
7953 int ret = 0;
7954
7955 if (seed) {
7956 ret = i40e_aq_get_rss_key(hw, vsi->id,
7957 (struct i40e_aqc_get_set_rss_key_data *)seed);
7958 if (ret) {
7959 dev_info(&pf->pdev->dev,
7960 "Cannot get RSS key, err %s aq_err %s\n",
7961 i40e_stat_str(&pf->hw, ret),
7962 i40e_aq_str(&pf->hw,
7963 pf->hw.aq.asq_last_status));
7964 return ret;
7965 }
7966 }
7967
7968 if (lut) {
7969 bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
7970
7971 ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
7972 if (ret) {
7973 dev_info(&pf->pdev->dev,
7974 "Cannot get RSS lut, err %s aq_err %s\n",
7975 i40e_stat_str(&pf->hw, ret),
7976 i40e_aq_str(&pf->hw,
7977 pf->hw.aq.asq_last_status));
7978 return ret;
7979 }
7980 }
7981
7982 return ret;
7983}
7984
7985/**
Helin Zhang043dd652015-10-21 19:56:23 -04007986 * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
Helin Zhange69ff812015-10-21 19:56:22 -04007987 * @vsi: Pointer to vsi structure
7988 * @seed: RSS hash seed
7989 * @lut: Lookup table
7990 * @lut_size: Lookup table size
7991 *
7992 * Returns 0 on success, negative on failure
7993 **/
7994static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
7995 const u8 *lut, u16 lut_size)
7996{
7997 struct i40e_pf *pf = vsi->back;
7998 struct i40e_hw *hw = &pf->hw;
7999 u8 i;
8000
8001 /* Fill out hash function seed */
8002 if (seed) {
8003 u32 *seed_dw = (u32 *)seed;
8004
8005 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
8006 wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
8007 }
8008
8009 if (lut) {
8010 u32 *lut_dw = (u32 *)lut;
8011
8012 if (lut_size != I40E_HLUT_ARRAY_SIZE)
8013 return -EINVAL;
8014
8015 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8016 wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
8017 }
8018 i40e_flush(hw);
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008019
8020 return 0;
8021}
8022
8023/**
Helin Zhang043dd652015-10-21 19:56:23 -04008024 * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
8025 * @vsi: Pointer to VSI structure
8026 * @seed: Buffer to store the keys
8027 * @lut: Buffer to store the lookup table entries
8028 * @lut_size: Size of buffer to store the lookup table entries
8029 *
8030 * Returns 0 on success, negative on failure
8031 */
8032static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
8033 u8 *lut, u16 lut_size)
8034{
8035 struct i40e_pf *pf = vsi->back;
8036 struct i40e_hw *hw = &pf->hw;
8037 u16 i;
8038
8039 if (seed) {
8040 u32 *seed_dw = (u32 *)seed;
8041
8042 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
8043 seed_dw[i] = rd32(hw, I40E_PFQF_HKEY(i));
8044 }
8045 if (lut) {
8046 u32 *lut_dw = (u32 *)lut;
8047
8048 if (lut_size != I40E_HLUT_ARRAY_SIZE)
8049 return -EINVAL;
8050 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8051 lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
8052 }
8053
8054 return 0;
8055}
8056
8057/**
8058 * i40e_config_rss - Configure RSS keys and lut
8059 * @vsi: Pointer to VSI structure
8060 * @seed: RSS hash seed
8061 * @lut: Lookup table
8062 * @lut_size: Lookup table size
8063 *
8064 * Returns 0 on success, negative on failure
8065 */
8066int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
8067{
8068 struct i40e_pf *pf = vsi->back;
8069
8070 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
8071 return i40e_config_rss_aq(vsi, seed, lut, lut_size);
8072 else
8073 return i40e_config_rss_reg(vsi, seed, lut, lut_size);
8074}
8075
8076/**
8077 * i40e_get_rss - Get RSS keys and lut
8078 * @vsi: Pointer to VSI structure
8079 * @seed: Buffer to store the keys
8080 * @lut: Buffer to store the lookup table entries
8081 * lut_size: Size of buffer to store the lookup table entries
8082 *
8083 * Returns 0 on success, negative on failure
8084 */
8085int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
8086{
Anjali Singhai Jain95a73782015-12-22 14:25:04 -08008087 struct i40e_pf *pf = vsi->back;
8088
8089 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
8090 return i40e_get_rss_aq(vsi, seed, lut, lut_size);
8091 else
8092 return i40e_get_rss_reg(vsi, seed, lut, lut_size);
Helin Zhang043dd652015-10-21 19:56:23 -04008093}
8094
8095/**
Helin Zhange69ff812015-10-21 19:56:22 -04008096 * i40e_fill_rss_lut - Fill the RSS lookup table with default values
8097 * @pf: Pointer to board private structure
8098 * @lut: Lookup table
8099 * @rss_table_size: Lookup table size
8100 * @rss_size: Range of queue number for hashing
8101 */
8102static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
8103 u16 rss_table_size, u16 rss_size)
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008104{
Helin Zhange69ff812015-10-21 19:56:22 -04008105 u16 i;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008106
Helin Zhange69ff812015-10-21 19:56:22 -04008107 for (i = 0; i < rss_table_size; i++)
8108 lut[i] = i % rss_size;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008109}
8110
8111/**
Helin Zhang043dd652015-10-21 19:56:23 -04008112 * i40e_pf_config_rss - Prepare for RSS if used
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008113 * @pf: board private structure
8114 **/
Helin Zhang043dd652015-10-21 19:56:23 -04008115static int i40e_pf_config_rss(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008116{
Anjali Singhai Jain66ddcff2015-02-24 06:58:50 +00008117 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008118 u8 seed[I40E_HKEY_ARRAY_SIZE];
Helin Zhange69ff812015-10-21 19:56:22 -04008119 u8 *lut;
Anjali Singhai Jain4617e8c2013-11-20 10:02:56 +00008120 struct i40e_hw *hw = &pf->hw;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00008121 u32 reg_val;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008122 u64 hena;
Helin Zhange69ff812015-10-21 19:56:22 -04008123 int ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008124
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008125 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
8126 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
8127 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008128 hena |= i40e_pf_get_default_rss_hena(pf);
8129
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008130 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
8131 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
8132
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008133 /* Determine the RSS table size based on the hardware capabilities */
Carolyn Wybornye157ea32014-06-03 23:50:22 +00008134 reg_val = rd32(hw, I40E_PFQF_CTL_0);
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008135 reg_val = (pf->rss_table_size == 512) ?
8136 (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
8137 (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
Carolyn Wybornye157ea32014-06-03 23:50:22 +00008138 wr32(hw, I40E_PFQF_CTL_0, reg_val);
8139
Helin Zhang28c58692015-10-26 19:44:27 -04008140 /* Determine the RSS size of the VSI */
8141 if (!vsi->rss_size)
Helin Zhangacd65442015-10-26 19:44:28 -04008142 vsi->rss_size = min_t(int, pf->alloc_rss_size,
8143 vsi->num_queue_pairs);
Helin Zhang28c58692015-10-26 19:44:27 -04008144
Helin Zhange69ff812015-10-21 19:56:22 -04008145 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
8146 if (!lut)
8147 return -ENOMEM;
8148
Helin Zhang28c58692015-10-26 19:44:27 -04008149 /* Use user configured lut if there is one, otherwise use default */
8150 if (vsi->rss_lut_user)
8151 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
8152 else
8153 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
Helin Zhange69ff812015-10-21 19:56:22 -04008154
Helin Zhang28c58692015-10-26 19:44:27 -04008155 /* Use user configured hash key if there is one, otherwise
8156 * use default.
8157 */
8158 if (vsi->rss_hkey_user)
8159 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
8160 else
8161 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
Helin Zhang043dd652015-10-21 19:56:23 -04008162 ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
Helin Zhange69ff812015-10-21 19:56:22 -04008163 kfree(lut);
8164
8165 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008166}
8167
8168/**
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008169 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
8170 * @pf: board private structure
8171 * @queue_count: the requested queue count for rss.
8172 *
8173 * returns 0 if rss is not enabled, if enabled returns the final rss queue
8174 * count which may be different from the requested queue count.
8175 **/
8176int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
8177{
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008178 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
8179 int new_rss_size;
8180
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008181 if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
8182 return 0;
8183
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008184 new_rss_size = min_t(int, queue_count, pf->rss_size_max);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008185
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008186 if (queue_count != vsi->num_queue_pairs) {
8187 vsi->req_queue_pairs = queue_count;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008188 i40e_prep_for_reset(pf);
8189
Helin Zhangacd65442015-10-26 19:44:28 -04008190 pf->alloc_rss_size = new_rss_size;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008191
8192 i40e_reset_and_rebuild(pf, true);
Helin Zhang28c58692015-10-26 19:44:27 -04008193
8194 /* Discard the user configured hash keys and lut, if less
8195 * queues are enabled.
8196 */
8197 if (queue_count < vsi->rss_size) {
8198 i40e_clear_rss_config_user(vsi);
8199 dev_dbg(&pf->pdev->dev,
8200 "discard user configured hash keys and lut\n");
8201 }
8202
8203 /* Reset vsi->rss_size, as number of enabled queues changed */
Helin Zhangacd65442015-10-26 19:44:28 -04008204 vsi->rss_size = min_t(int, pf->alloc_rss_size,
8205 vsi->num_queue_pairs);
Helin Zhang28c58692015-10-26 19:44:27 -04008206
Helin Zhang043dd652015-10-21 19:56:23 -04008207 i40e_pf_config_rss(pf);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008208 }
Helin Zhange36b0b12015-10-26 19:44:36 -04008209 dev_info(&pf->pdev->dev, "RSS count/HW max RSS count: %d/%d\n",
8210 pf->alloc_rss_size, pf->rss_size_max);
Helin Zhangacd65442015-10-26 19:44:28 -04008211 return pf->alloc_rss_size;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008212}
8213
8214/**
Greg Rosef4492db2015-02-06 08:52:12 +00008215 * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
8216 * @pf: board private structure
8217 **/
8218i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf)
8219{
8220 i40e_status status;
8221 bool min_valid, max_valid;
8222 u32 max_bw, min_bw;
8223
8224 status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
8225 &min_valid, &max_valid);
8226
8227 if (!status) {
8228 if (min_valid)
8229 pf->npar_min_bw = min_bw;
8230 if (max_valid)
8231 pf->npar_max_bw = max_bw;
8232 }
8233
8234 return status;
8235}
8236
8237/**
8238 * i40e_set_npar_bw_setting - Set BW settings for this PF partition
8239 * @pf: board private structure
8240 **/
8241i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf)
8242{
8243 struct i40e_aqc_configure_partition_bw_data bw_data;
8244 i40e_status status;
8245
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00008246 /* Set the valid bit for this PF */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008247 bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
Greg Rosef4492db2015-02-06 08:52:12 +00008248 bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK;
8249 bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK;
8250
8251 /* Set the new bandwidths */
8252 status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
8253
8254 return status;
8255}
8256
8257/**
8258 * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
8259 * @pf: board private structure
8260 **/
8261i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf)
8262{
8263 /* Commit temporary BW setting to permanent NVM image */
8264 enum i40e_admin_queue_err last_aq_status;
8265 i40e_status ret;
8266 u16 nvm_word;
8267
8268 if (pf->hw.partition_id != 1) {
8269 dev_info(&pf->pdev->dev,
8270 "Commit BW only works on partition 1! This is partition %d",
8271 pf->hw.partition_id);
8272 ret = I40E_NOT_SUPPORTED;
8273 goto bw_commit_out;
8274 }
8275
8276 /* Acquire NVM for read access */
8277 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
8278 last_aq_status = pf->hw.aq.asq_last_status;
8279 if (ret) {
8280 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008281 "Cannot acquire NVM for read access, err %s aq_err %s\n",
8282 i40e_stat_str(&pf->hw, ret),
8283 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008284 goto bw_commit_out;
8285 }
8286
8287 /* Read word 0x10 of NVM - SW compatibility word 1 */
8288 ret = i40e_aq_read_nvm(&pf->hw,
8289 I40E_SR_NVM_CONTROL_WORD,
8290 0x10, sizeof(nvm_word), &nvm_word,
8291 false, NULL);
8292 /* Save off last admin queue command status before releasing
8293 * the NVM
8294 */
8295 last_aq_status = pf->hw.aq.asq_last_status;
8296 i40e_release_nvm(&pf->hw);
8297 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008298 dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
8299 i40e_stat_str(&pf->hw, ret),
8300 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008301 goto bw_commit_out;
8302 }
8303
8304 /* Wait a bit for NVM release to complete */
8305 msleep(50);
8306
8307 /* Acquire NVM for write access */
8308 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
8309 last_aq_status = pf->hw.aq.asq_last_status;
8310 if (ret) {
8311 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008312 "Cannot acquire NVM for write access, err %s aq_err %s\n",
8313 i40e_stat_str(&pf->hw, ret),
8314 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008315 goto bw_commit_out;
8316 }
8317 /* Write it back out unchanged to initiate update NVM,
8318 * which will force a write of the shadow (alt) RAM to
8319 * the NVM - thus storing the bandwidth values permanently.
8320 */
8321 ret = i40e_aq_update_nvm(&pf->hw,
8322 I40E_SR_NVM_CONTROL_WORD,
8323 0x10, sizeof(nvm_word),
8324 &nvm_word, true, NULL);
8325 /* Save off last admin queue command status before releasing
8326 * the NVM
8327 */
8328 last_aq_status = pf->hw.aq.asq_last_status;
8329 i40e_release_nvm(&pf->hw);
8330 if (ret)
8331 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008332 "BW settings NOT SAVED, err %s aq_err %s\n",
8333 i40e_stat_str(&pf->hw, ret),
8334 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008335bw_commit_out:
8336
8337 return ret;
8338}
8339
8340/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008341 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
8342 * @pf: board private structure to initialize
8343 *
8344 * i40e_sw_init initializes the Adapter private data structure.
8345 * Fields are initialized based on PCI device information and
8346 * OS network device settings (MTU size).
8347 **/
8348static int i40e_sw_init(struct i40e_pf *pf)
8349{
8350 int err = 0;
8351 int size;
8352
8353 pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE,
8354 (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK));
Shannon Nelson27599972013-11-16 10:00:43 +00008355 pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008356 if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) {
8357 if (I40E_DEBUG_USER & debug)
8358 pf->hw.debug_mask = debug;
8359 pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER),
8360 I40E_DEFAULT_MSG_ENABLE);
8361 }
8362
8363 /* Set default capability flags */
8364 pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
8365 I40E_FLAG_MSI_ENABLED |
Shannon Nelson9ac77262015-08-27 11:42:40 -04008366 I40E_FLAG_LINK_POLLING_ENABLED |
Mitch Williams2bc7ee82015-02-06 08:52:11 +00008367 I40E_FLAG_MSIX_ENABLED;
8368
8369 if (iommu_present(&pci_bus_type))
8370 pf->flags |= I40E_FLAG_RX_PS_ENABLED;
8371 else
8372 pf->flags |= I40E_FLAG_RX_1BUF_ENABLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008373
Mitch Williamsca99eb92014-04-04 04:43:07 +00008374 /* Set default ITR */
8375 pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
8376 pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
8377
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008378 /* Depending on PF configurations, it is possible that the RSS
8379 * maximum might end up larger than the available queues
8380 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008381 pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
Helin Zhangacd65442015-10-26 19:44:28 -04008382 pf->alloc_rss_size = 1;
Anjali Singhai Jain5db4cb52015-02-24 06:58:49 +00008383 pf->rss_table_size = pf->hw.func_caps.rss_table_size;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008384 pf->rss_size_max = min_t(int, pf->rss_size_max,
8385 pf->hw.func_caps.num_tx_qp);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008386 if (pf->hw.func_caps.rss) {
8387 pf->flags |= I40E_FLAG_RSS_ENABLED;
Helin Zhangacd65442015-10-26 19:44:28 -04008388 pf->alloc_rss_size = min_t(int, pf->rss_size_max,
8389 num_online_cpus());
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008390 }
8391
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008392 /* MFP mode enabled */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04008393 if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008394 pf->flags |= I40E_FLAG_MFP_ENABLED;
8395 dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
Greg Rosef4492db2015-02-06 08:52:12 +00008396 if (i40e_get_npar_bw_setting(pf))
8397 dev_warn(&pf->pdev->dev,
8398 "Could not get NPAR bw settings\n");
8399 else
8400 dev_info(&pf->pdev->dev,
8401 "Min BW = %8.8x, Max BW = %8.8x\n",
8402 pf->npar_min_bw, pf->npar_max_bw);
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008403 }
8404
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008405 /* FW/NVM is not yet fixed in this regard */
8406 if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
8407 (pf->hw.func_caps.fd_filters_best_effort > 0)) {
8408 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
8409 pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
Shannon Nelson6eae9c62015-09-03 17:18:55 -04008410 if (pf->flags & I40E_FLAG_MFP_ENABLED &&
8411 pf->hw.num_partitions > 1)
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008412 dev_info(&pf->pdev->dev,
Anjali Singhai Jain0b675842014-03-06 08:59:51 +00008413 "Flow Director Sideband mode Disabled in MFP mode\n");
Shannon Nelson6eae9c62015-09-03 17:18:55 -04008414 else
8415 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008416 pf->fdir_pf_filter_count =
8417 pf->hw.func_caps.fd_filters_guaranteed;
8418 pf->hw.fdir_shared_filter_count =
8419 pf->hw.func_caps.fd_filters_best_effort;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008420 }
8421
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08008422 if (((pf->hw.mac.type == I40E_MAC_X710) ||
8423 (pf->hw.mac.type == I40E_MAC_XL710)) &&
8424 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
8425 (pf->hw.aq.fw_maj_ver < 4)))
8426 pf->flags |= I40E_FLAG_RESTART_AUTONEG;
8427
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008428 if (pf->hw.func_caps.vmdq) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008429 pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008430 pf->flags |= I40E_FLAG_VMDQ_ENABLED;
Jesse Brandeburge9e53662015-10-02 17:57:21 -07008431 pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008432 }
8433
Vasu Dev38e00432014-08-01 13:27:03 -07008434#ifdef I40E_FCOE
Shannon Nelson21364bc2015-08-26 15:14:13 -04008435 i40e_init_pf_fcoe(pf);
Vasu Dev38e00432014-08-01 13:27:03 -07008436
8437#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008438#ifdef CONFIG_PCI_IOV
Shannon Nelsonba252f132014-12-11 07:06:34 +00008439 if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008440 pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
8441 pf->flags |= I40E_FLAG_SRIOV_ENABLED;
8442 pf->num_req_vfs = min_t(int,
8443 pf->hw.func_caps.num_vfs,
8444 I40E_MAX_VF_COUNT);
8445 }
8446#endif /* CONFIG_PCI_IOV */
Anjali Singhai Jaind502ce02015-06-05 12:20:26 -04008447 if (pf->hw.mac.type == I40E_MAC_X722) {
8448 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE |
8449 I40E_FLAG_128_QP_RSS_CAPABLE |
8450 I40E_FLAG_HW_ATR_EVICT_CAPABLE |
8451 I40E_FLAG_OUTER_UDP_CSUM_CAPABLE |
8452 I40E_FLAG_WB_ON_ITR_CAPABLE |
Singhai, Anjali6a899022015-12-14 12:21:18 -08008453 I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE |
8454 I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
Anjali Singhai Jaind502ce02015-06-05 12:20:26 -04008455 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008456 pf->eeprom_version = 0xDEAD;
8457 pf->lan_veb = I40E_NO_VEB;
8458 pf->lan_vsi = I40E_NO_VSI;
8459
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04008460 /* By default FW has this off for performance reasons */
8461 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
8462
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008463 /* set up queue assignment tracking */
8464 size = sizeof(struct i40e_lump_tracking)
8465 + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
8466 pf->qp_pile = kzalloc(size, GFP_KERNEL);
8467 if (!pf->qp_pile) {
8468 err = -ENOMEM;
8469 goto sw_init_done;
8470 }
8471 pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
8472 pf->qp_pile->search_hint = 0;
8473
Anjali Singhai Jain327fe042014-06-04 01:23:26 +00008474 pf->tx_timeout_recovery_level = 1;
8475
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008476 mutex_init(&pf->switch_mutex);
8477
Greg Rosec668a122015-02-26 16:10:39 +00008478 /* If NPAR is enabled nudge the Tx scheduler */
8479 if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf)))
8480 i40e_set_npar_bw_setting(pf);
8481
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008482sw_init_done:
8483 return err;
8484}
8485
8486/**
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008487 * i40e_set_ntuple - set the ntuple feature flag and take action
8488 * @pf: board private structure to initialize
8489 * @features: the feature set that the stack is suggesting
8490 *
8491 * returns a bool to indicate if reset needs to happen
8492 **/
8493bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
8494{
8495 bool need_reset = false;
8496
8497 /* Check if Flow Director n-tuple support was enabled or disabled. If
8498 * the state changed, we need to reset.
8499 */
8500 if (features & NETIF_F_NTUPLE) {
8501 /* Enable filters and mark for reset */
8502 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
8503 need_reset = true;
8504 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
8505 } else {
8506 /* turn off filters, mark for reset and clear SW filter list */
8507 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
8508 need_reset = true;
8509 i40e_fdir_filter_exit(pf);
8510 }
8511 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain8a4f34f2014-06-04 08:45:20 +00008512 pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00008513 /* reset fd counters */
8514 pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0;
8515 pf->fdir_pf_active_filters = 0;
8516 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04008517 if (I40E_DEBUG_FD & pf->hw.debug_mask)
8518 dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
Anjali Singhai Jain8a4f34f2014-06-04 08:45:20 +00008519 /* if ATR was auto disabled it can be re-enabled. */
8520 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
8521 (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
8522 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008523 }
8524 return need_reset;
8525}
8526
8527/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008528 * i40e_set_features - set the netdev feature flags
8529 * @netdev: ptr to the netdev being adjusted
8530 * @features: the feature set that the stack is suggesting
8531 **/
8532static int i40e_set_features(struct net_device *netdev,
8533 netdev_features_t features)
8534{
8535 struct i40e_netdev_priv *np = netdev_priv(netdev);
8536 struct i40e_vsi *vsi = np->vsi;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008537 struct i40e_pf *pf = vsi->back;
8538 bool need_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008539
8540 if (features & NETIF_F_HW_VLAN_CTAG_RX)
8541 i40e_vlan_stripping_enable(vsi);
8542 else
8543 i40e_vlan_stripping_disable(vsi);
8544
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008545 need_reset = i40e_set_ntuple(pf, features);
8546
8547 if (need_reset)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008548 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008549
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008550 return 0;
8551}
8552
Singhai, Anjali6a899022015-12-14 12:21:18 -08008553#if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008554/**
Singhai, Anjali6a899022015-12-14 12:21:18 -08008555 * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008556 * @pf: board private structure
8557 * @port: The UDP port to look up
8558 *
8559 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
8560 **/
Singhai, Anjali6a899022015-12-14 12:21:18 -08008561static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, __be16 port)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008562{
8563 u8 i;
8564
8565 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
Singhai, Anjali6a899022015-12-14 12:21:18 -08008566 if (pf->udp_ports[i].index == port)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008567 return i;
8568 }
8569
8570 return i;
8571}
8572
Singhai, Anjali6a899022015-12-14 12:21:18 -08008573#endif
Eric Dumazet5cae7612016-01-20 19:53:02 -08008574
8575#if IS_ENABLED(CONFIG_VXLAN)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008576/**
8577 * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
8578 * @netdev: This physical port's netdev
8579 * @sa_family: Socket Family that VXLAN is notifying us about
8580 * @port: New UDP port number that VXLAN started listening to
8581 **/
8582static void i40e_add_vxlan_port(struct net_device *netdev,
8583 sa_family_t sa_family, __be16 port)
8584{
8585 struct i40e_netdev_priv *np = netdev_priv(netdev);
8586 struct i40e_vsi *vsi = np->vsi;
8587 struct i40e_pf *pf = vsi->back;
8588 u8 next_idx;
8589 u8 idx;
8590
8591 if (sa_family == AF_INET6)
8592 return;
8593
Singhai, Anjali6a899022015-12-14 12:21:18 -08008594 idx = i40e_get_udp_port_idx(pf, port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008595
8596 /* Check if port already exists */
8597 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07008598 netdev_info(netdev, "vxlan port %d already offloaded\n",
8599 ntohs(port));
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008600 return;
8601 }
8602
8603 /* Now check if there is space to add the new port */
Singhai, Anjali6a899022015-12-14 12:21:18 -08008604 next_idx = i40e_get_udp_port_idx(pf, 0);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008605
8606 if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07008607 netdev_info(netdev, "maximum number of vxlan UDP ports reached, not adding port %d\n",
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008608 ntohs(port));
8609 return;
8610 }
8611
8612 /* New port: add it and mark its index in the bitmap */
Singhai, Anjali6a899022015-12-14 12:21:18 -08008613 pf->udp_ports[next_idx].index = port;
8614 pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
8615 pf->pending_udp_bitmap |= BIT_ULL(next_idx);
8616 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008617}
8618
8619/**
8620 * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
8621 * @netdev: This physical port's netdev
8622 * @sa_family: Socket Family that VXLAN is notifying us about
8623 * @port: UDP port number that VXLAN stopped listening to
8624 **/
8625static void i40e_del_vxlan_port(struct net_device *netdev,
8626 sa_family_t sa_family, __be16 port)
8627{
8628 struct i40e_netdev_priv *np = netdev_priv(netdev);
8629 struct i40e_vsi *vsi = np->vsi;
8630 struct i40e_pf *pf = vsi->back;
8631 u8 idx;
8632
8633 if (sa_family == AF_INET6)
8634 return;
8635
Singhai, Anjali6a899022015-12-14 12:21:18 -08008636 idx = i40e_get_udp_port_idx(pf, port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008637
8638 /* Check if port already exists */
8639 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
8640 /* if port exists, set it to 0 (mark for deletion)
8641 * and make it pending
8642 */
Singhai, Anjali6a899022015-12-14 12:21:18 -08008643 pf->udp_ports[idx].index = 0;
8644 pf->pending_udp_bitmap |= BIT_ULL(idx);
8645 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008646 } else {
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07008647 netdev_warn(netdev, "vxlan port %d was not found, not deleting\n",
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008648 ntohs(port));
8649 }
8650}
Eric Dumazet5cae7612016-01-20 19:53:02 -08008651#endif
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008652
Eric Dumazet5cae7612016-01-20 19:53:02 -08008653#if IS_ENABLED(CONFIG_GENEVE)
Singhai, Anjali6a899022015-12-14 12:21:18 -08008654/**
8655 * i40e_add_geneve_port - Get notifications about GENEVE ports that come up
8656 * @netdev: This physical port's netdev
8657 * @sa_family: Socket Family that GENEVE is notifying us about
8658 * @port: New UDP port number that GENEVE started listening to
8659 **/
8660static void i40e_add_geneve_port(struct net_device *netdev,
8661 sa_family_t sa_family, __be16 port)
8662{
Singhai, Anjali6a899022015-12-14 12:21:18 -08008663 struct i40e_netdev_priv *np = netdev_priv(netdev);
8664 struct i40e_vsi *vsi = np->vsi;
8665 struct i40e_pf *pf = vsi->back;
8666 u8 next_idx;
8667 u8 idx;
8668
8669 if (sa_family == AF_INET6)
8670 return;
8671
8672 idx = i40e_get_udp_port_idx(pf, port);
8673
8674 /* Check if port already exists */
8675 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
8676 netdev_info(netdev, "udp port %d already offloaded\n",
8677 ntohs(port));
8678 return;
8679 }
8680
8681 /* Now check if there is space to add the new port */
8682 next_idx = i40e_get_udp_port_idx(pf, 0);
8683
8684 if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
8685 netdev_info(netdev, "maximum number of UDP ports reached, not adding port %d\n",
8686 ntohs(port));
8687 return;
8688 }
8689
8690 /* New port: add it and mark its index in the bitmap */
8691 pf->udp_ports[next_idx].index = port;
8692 pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
8693 pf->pending_udp_bitmap |= BIT_ULL(next_idx);
8694 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
8695
8696 dev_info(&pf->pdev->dev, "adding geneve port %d\n", ntohs(port));
Singhai, Anjali6a899022015-12-14 12:21:18 -08008697}
8698
8699/**
8700 * i40e_del_geneve_port - Get notifications about GENEVE ports that go away
8701 * @netdev: This physical port's netdev
8702 * @sa_family: Socket Family that GENEVE is notifying us about
8703 * @port: UDP port number that GENEVE stopped listening to
8704 **/
8705static void i40e_del_geneve_port(struct net_device *netdev,
8706 sa_family_t sa_family, __be16 port)
8707{
Singhai, Anjali6a899022015-12-14 12:21:18 -08008708 struct i40e_netdev_priv *np = netdev_priv(netdev);
8709 struct i40e_vsi *vsi = np->vsi;
8710 struct i40e_pf *pf = vsi->back;
8711 u8 idx;
8712
8713 if (sa_family == AF_INET6)
8714 return;
8715
8716 idx = i40e_get_udp_port_idx(pf, port);
8717
8718 /* Check if port already exists */
8719 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
8720 /* if port exists, set it to 0 (mark for deletion)
8721 * and make it pending
8722 */
8723 pf->udp_ports[idx].index = 0;
8724 pf->pending_udp_bitmap |= BIT_ULL(idx);
8725 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
8726
8727 dev_info(&pf->pdev->dev, "deleting geneve port %d\n",
8728 ntohs(port));
8729 } else {
8730 netdev_warn(netdev, "geneve port %d was not found, not deleting\n",
8731 ntohs(port));
8732 }
Singhai, Anjali6a899022015-12-14 12:21:18 -08008733}
Eric Dumazet5cae7612016-01-20 19:53:02 -08008734#endif
Singhai, Anjali6a899022015-12-14 12:21:18 -08008735
Neerav Parikh1f224ad2014-02-12 01:45:31 +00008736static int i40e_get_phys_port_id(struct net_device *netdev,
Jiri Pirko02637fc2014-11-28 14:34:16 +01008737 struct netdev_phys_item_id *ppid)
Neerav Parikh1f224ad2014-02-12 01:45:31 +00008738{
8739 struct i40e_netdev_priv *np = netdev_priv(netdev);
8740 struct i40e_pf *pf = np->vsi->back;
8741 struct i40e_hw *hw = &pf->hw;
8742
8743 if (!(pf->flags & I40E_FLAG_PORT_ID_VALID))
8744 return -EOPNOTSUPP;
8745
8746 ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
8747 memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
8748
8749 return 0;
8750}
8751
Jesse Brandeburg2f90ade2014-11-20 16:30:02 -08008752/**
8753 * i40e_ndo_fdb_add - add an entry to the hardware database
8754 * @ndm: the input from the stack
8755 * @tb: pointer to array of nladdr (unused)
8756 * @dev: the net device pointer
8757 * @addr: the MAC address entry being added
8758 * @flags: instructions from stack about fdb operation
8759 */
Greg Rose4ba0dea2014-03-06 08:59:55 +00008760static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
8761 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01008762 const unsigned char *addr, u16 vid,
Greg Rose4ba0dea2014-03-06 08:59:55 +00008763 u16 flags)
Greg Rose4ba0dea2014-03-06 08:59:55 +00008764{
8765 struct i40e_netdev_priv *np = netdev_priv(dev);
8766 struct i40e_pf *pf = np->vsi->back;
8767 int err = 0;
8768
8769 if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
8770 return -EOPNOTSUPP;
8771
Or Gerlitz65891fe2014-12-14 18:19:05 +02008772 if (vid) {
8773 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
8774 return -EINVAL;
8775 }
8776
Greg Rose4ba0dea2014-03-06 08:59:55 +00008777 /* Hardware does not support aging addresses so if a
8778 * ndm_state is given only allow permanent addresses
8779 */
8780 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
8781 netdev_info(dev, "FDB only supports static addresses\n");
8782 return -EINVAL;
8783 }
8784
8785 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
8786 err = dev_uc_add_excl(dev, addr);
8787 else if (is_multicast_ether_addr(addr))
8788 err = dev_mc_add_excl(dev, addr);
8789 else
8790 err = -EINVAL;
8791
8792 /* Only return duplicate errors if NLM_F_EXCL is set */
8793 if (err == -EEXIST && !(flags & NLM_F_EXCL))
8794 err = 0;
8795
8796 return err;
8797}
8798
Neerav Parikh51616012015-02-06 08:52:14 +00008799/**
8800 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
8801 * @dev: the netdev being configured
8802 * @nlh: RTNL message
8803 *
8804 * Inserts a new hardware bridge if not already created and
8805 * enables the bridging mode requested (VEB or VEPA). If the
8806 * hardware bridge has already been inserted and the request
8807 * is to change the mode then that requires a PF reset to
8808 * allow rebuild of the components with required hardware
8809 * bridge mode enabled.
8810 **/
8811static int i40e_ndo_bridge_setlink(struct net_device *dev,
Carolyn Wyborny9df70b62015-04-27 14:57:11 -04008812 struct nlmsghdr *nlh,
8813 u16 flags)
Neerav Parikh51616012015-02-06 08:52:14 +00008814{
8815 struct i40e_netdev_priv *np = netdev_priv(dev);
8816 struct i40e_vsi *vsi = np->vsi;
8817 struct i40e_pf *pf = vsi->back;
8818 struct i40e_veb *veb = NULL;
8819 struct nlattr *attr, *br_spec;
8820 int i, rem;
8821
8822 /* Only for PF VSI for now */
8823 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
8824 return -EOPNOTSUPP;
8825
8826 /* Find the HW bridge for PF VSI */
8827 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
8828 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
8829 veb = pf->veb[i];
8830 }
8831
8832 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
8833
8834 nla_for_each_nested(attr, br_spec, rem) {
8835 __u16 mode;
8836
8837 if (nla_type(attr) != IFLA_BRIDGE_MODE)
8838 continue;
8839
8840 mode = nla_get_u16(attr);
8841 if ((mode != BRIDGE_MODE_VEPA) &&
8842 (mode != BRIDGE_MODE_VEB))
8843 return -EINVAL;
8844
8845 /* Insert a new HW bridge */
8846 if (!veb) {
8847 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
8848 vsi->tc_config.enabled_tc);
8849 if (veb) {
8850 veb->bridge_mode = mode;
8851 i40e_config_bridge_mode(veb);
8852 } else {
8853 /* No Bridge HW offload available */
8854 return -ENOENT;
8855 }
8856 break;
8857 } else if (mode != veb->bridge_mode) {
8858 /* Existing HW bridge but different mode needs reset */
8859 veb->bridge_mode = mode;
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07008860 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
8861 if (mode == BRIDGE_MODE_VEB)
8862 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
8863 else
8864 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
8865 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Neerav Parikh51616012015-02-06 08:52:14 +00008866 break;
8867 }
8868 }
8869
8870 return 0;
8871}
8872
8873/**
8874 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
8875 * @skb: skb buff
8876 * @pid: process id
8877 * @seq: RTNL message seq #
8878 * @dev: the netdev being configured
8879 * @filter_mask: unused
Jesse Brandeburgd4b2f9f2015-09-03 17:18:48 -04008880 * @nlflags: netlink flags passed in
Neerav Parikh51616012015-02-06 08:52:14 +00008881 *
8882 * Return the mode in which the hardware bridge is operating in
8883 * i.e VEB or VEPA.
8884 **/
Neerav Parikh51616012015-02-06 08:52:14 +00008885static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8886 struct net_device *dev,
Carolyn Wyborny9f4ffc42015-08-31 19:54:42 -04008887 u32 __always_unused filter_mask,
8888 int nlflags)
Neerav Parikh51616012015-02-06 08:52:14 +00008889{
8890 struct i40e_netdev_priv *np = netdev_priv(dev);
8891 struct i40e_vsi *vsi = np->vsi;
8892 struct i40e_pf *pf = vsi->back;
8893 struct i40e_veb *veb = NULL;
8894 int i;
8895
8896 /* Only for PF VSI for now */
8897 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
8898 return -EOPNOTSUPP;
8899
8900 /* Find the HW bridge for the PF VSI */
8901 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
8902 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
8903 veb = pf->veb[i];
8904 }
8905
8906 if (!veb)
8907 return 0;
8908
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02008909 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07008910 nlflags, 0, 0, filter_mask, NULL);
Neerav Parikh51616012015-02-06 08:52:14 +00008911}
Neerav Parikh51616012015-02-06 08:52:14 +00008912
Singhai, Anjali6a899022015-12-14 12:21:18 -08008913/* Hardware supports L4 tunnel length of 128B (=2^7) which includes
8914 * inner mac plus all inner ethertypes.
8915 */
8916#define I40E_MAX_TUNNEL_HDR_LEN 128
Joe Stringerf44a75e2015-04-14 17:09:14 -07008917/**
8918 * i40e_features_check - Validate encapsulated packet conforms to limits
8919 * @skb: skb buff
Jean Sacren2bc11c62015-09-19 05:08:43 -06008920 * @dev: This physical port's netdev
Joe Stringerf44a75e2015-04-14 17:09:14 -07008921 * @features: Offload features that the stack believes apply
8922 **/
8923static netdev_features_t i40e_features_check(struct sk_buff *skb,
8924 struct net_device *dev,
8925 netdev_features_t features)
8926{
8927 if (skb->encapsulation &&
Singhai, Anjali6a899022015-12-14 12:21:18 -08008928 ((skb_inner_network_header(skb) - skb_transport_header(skb)) >
Joe Stringerf44a75e2015-04-14 17:09:14 -07008929 I40E_MAX_TUNNEL_HDR_LEN))
Tom Herberta1882222015-12-14 11:19:43 -08008930 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
Joe Stringerf44a75e2015-04-14 17:09:14 -07008931
8932 return features;
8933}
8934
Shannon Nelson37a29732015-02-27 09:15:19 +00008935static const struct net_device_ops i40e_netdev_ops = {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008936 .ndo_open = i40e_open,
8937 .ndo_stop = i40e_close,
8938 .ndo_start_xmit = i40e_lan_xmit_frame,
8939 .ndo_get_stats64 = i40e_get_netdev_stats_struct,
8940 .ndo_set_rx_mode = i40e_set_rx_mode,
8941 .ndo_validate_addr = eth_validate_addr,
8942 .ndo_set_mac_address = i40e_set_mac,
8943 .ndo_change_mtu = i40e_change_mtu,
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00008944 .ndo_do_ioctl = i40e_ioctl,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008945 .ndo_tx_timeout = i40e_tx_timeout,
8946 .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
8947 .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
8948#ifdef CONFIG_NET_POLL_CONTROLLER
8949 .ndo_poll_controller = i40e_netpoll,
8950#endif
8951 .ndo_setup_tc = i40e_setup_tc,
Vasu Dev38e00432014-08-01 13:27:03 -07008952#ifdef I40E_FCOE
8953 .ndo_fcoe_enable = i40e_fcoe_enable,
8954 .ndo_fcoe_disable = i40e_fcoe_disable,
8955#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008956 .ndo_set_features = i40e_set_features,
8957 .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
8958 .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04008959 .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008960 .ndo_get_vf_config = i40e_ndo_get_vf_config,
Mitch Williams588aefa2014-02-11 08:27:49 +00008961 .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
Serey Konge6d90042014-07-12 07:28:14 +00008962 .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
Singhai, Anjali6a899022015-12-14 12:21:18 -08008963#if IS_ENABLED(CONFIG_VXLAN)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008964 .ndo_add_vxlan_port = i40e_add_vxlan_port,
8965 .ndo_del_vxlan_port = i40e_del_vxlan_port,
8966#endif
Singhai, Anjali6a899022015-12-14 12:21:18 -08008967#if IS_ENABLED(CONFIG_GENEVE)
8968 .ndo_add_geneve_port = i40e_add_geneve_port,
8969 .ndo_del_geneve_port = i40e_del_geneve_port,
8970#endif
Neerav Parikh1f224ad2014-02-12 01:45:31 +00008971 .ndo_get_phys_port_id = i40e_get_phys_port_id,
Greg Rose4ba0dea2014-03-06 08:59:55 +00008972 .ndo_fdb_add = i40e_ndo_fdb_add,
Joe Stringerf44a75e2015-04-14 17:09:14 -07008973 .ndo_features_check = i40e_features_check,
Neerav Parikh51616012015-02-06 08:52:14 +00008974 .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
8975 .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008976};
8977
8978/**
8979 * i40e_config_netdev - Setup the netdev flags
8980 * @vsi: the VSI being configured
8981 *
8982 * Returns 0 on success, negative value on failure
8983 **/
8984static int i40e_config_netdev(struct i40e_vsi *vsi)
8985{
Greg Rose1a103702013-11-28 06:42:39 +00008986 u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008987 struct i40e_pf *pf = vsi->back;
8988 struct i40e_hw *hw = &pf->hw;
8989 struct i40e_netdev_priv *np;
8990 struct net_device *netdev;
8991 u8 mac_addr[ETH_ALEN];
8992 int etherdev_size;
8993
8994 etherdev_size = sizeof(struct i40e_netdev_priv);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008995 netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008996 if (!netdev)
8997 return -ENOMEM;
8998
8999 vsi->netdev = netdev;
9000 np = netdev_priv(netdev);
9001 np->vsi = vsi;
9002
Jesse Brandeburg5afdaaa2015-12-10 11:38:50 -08009003 netdev->hw_enc_features |= NETIF_F_IP_CSUM |
9004 NETIF_F_GSO_UDP_TUNNEL |
9005 NETIF_F_GSO_GRE |
9006 NETIF_F_TSO |
9007 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009008
9009 netdev->features = NETIF_F_SG |
9010 NETIF_F_IP_CSUM |
Tom Herbert53692b12015-12-14 11:19:41 -08009011 NETIF_F_SCTP_CRC |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009012 NETIF_F_HIGHDMA |
9013 NETIF_F_GSO_UDP_TUNNEL |
Jesse Brandeburgfec31ff2015-10-01 18:25:42 -07009014 NETIF_F_GSO_GRE |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009015 NETIF_F_HW_VLAN_CTAG_TX |
9016 NETIF_F_HW_VLAN_CTAG_RX |
9017 NETIF_F_HW_VLAN_CTAG_FILTER |
9018 NETIF_F_IPV6_CSUM |
9019 NETIF_F_TSO |
Jesse Brandeburg059dab62014-04-01 09:07:20 +00009020 NETIF_F_TSO_ECN |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009021 NETIF_F_TSO6 |
9022 NETIF_F_RXCSUM |
9023 NETIF_F_RXHASH |
9024 0;
9025
Anjali Singhai Jain2e86a0b2014-04-01 07:11:53 +00009026 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
9027 netdev->features |= NETIF_F_NTUPLE;
9028
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009029 /* copy netdev features into list of user selectable features */
9030 netdev->hw_features |= netdev->features;
9031
9032 if (vsi->type == I40E_VSI_MAIN) {
9033 SET_NETDEV_DEV(netdev, &pf->pdev->dev);
Greg Rose9a173902014-05-22 06:32:02 +00009034 ether_addr_copy(mac_addr, hw->mac.perm_addr);
Shannon Nelson30650cc2014-07-29 04:01:50 +00009035 /* The following steps are necessary to prevent reception
9036 * of tagged packets - some older NVM configurations load a
9037 * default a MAC-VLAN filter that accepts any tagged packet
9038 * which must be replaced by a normal filter.
Greg Rose8c27d422014-05-22 06:31:56 +00009039 */
Kiran Patil21659032015-09-30 14:09:03 -04009040 if (!i40e_rm_default_mac_filter(vsi, mac_addr)) {
9041 spin_lock_bh(&vsi->mac_filter_list_lock);
Shannon Nelson30650cc2014-07-29 04:01:50 +00009042 i40e_add_filter(vsi, mac_addr,
9043 I40E_VLAN_ANY, false, true);
Kiran Patil21659032015-09-30 14:09:03 -04009044 spin_unlock_bh(&vsi->mac_filter_list_lock);
9045 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009046 } else {
9047 /* relate the VSI_VMDQ name to the VSI_MAIN name */
9048 snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
9049 pf->vsi[pf->lan_vsi]->netdev->name);
9050 random_ether_addr(mac_addr);
Kiran Patil21659032015-09-30 14:09:03 -04009051
9052 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009053 i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false);
Kiran Patil21659032015-09-30 14:09:03 -04009054 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009055 }
Kiran Patil21659032015-09-30 14:09:03 -04009056
9057 spin_lock_bh(&vsi->mac_filter_list_lock);
Greg Rose1a103702013-11-28 06:42:39 +00009058 i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false);
Kiran Patil21659032015-09-30 14:09:03 -04009059 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009060
Greg Rose9a173902014-05-22 06:32:02 +00009061 ether_addr_copy(netdev->dev_addr, mac_addr);
9062 ether_addr_copy(netdev->perm_addr, mac_addr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009063 /* vlan gets same features (except vlan offload)
9064 * after any tweaks for specific VSI types
9065 */
9066 netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX |
9067 NETIF_F_HW_VLAN_CTAG_RX |
9068 NETIF_F_HW_VLAN_CTAG_FILTER);
9069 netdev->priv_flags |= IFF_UNICAST_FLT;
9070 netdev->priv_flags |= IFF_SUPP_NOFCS;
9071 /* Setup netdev TC information */
9072 i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
9073
9074 netdev->netdev_ops = &i40e_netdev_ops;
9075 netdev->watchdog_timeo = 5 * HZ;
9076 i40e_set_ethtool_ops(netdev);
Vasu Dev38e00432014-08-01 13:27:03 -07009077#ifdef I40E_FCOE
9078 i40e_fcoe_config_netdev(netdev, vsi);
9079#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009080
9081 return 0;
9082}
9083
9084/**
9085 * i40e_vsi_delete - Delete a VSI from the switch
9086 * @vsi: the VSI being removed
9087 *
9088 * Returns 0 on success, negative value on failure
9089 **/
9090static void i40e_vsi_delete(struct i40e_vsi *vsi)
9091{
9092 /* remove default VSI is not allowed */
9093 if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
9094 return;
9095
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009096 i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009097}
9098
9099/**
Neerav Parikh51616012015-02-06 08:52:14 +00009100 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
9101 * @vsi: the VSI being queried
9102 *
9103 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
9104 **/
9105int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
9106{
9107 struct i40e_veb *veb;
9108 struct i40e_pf *pf = vsi->back;
9109
9110 /* Uplink is not a bridge so default to VEB */
9111 if (vsi->veb_idx == I40E_NO_VEB)
9112 return 1;
9113
9114 veb = pf->veb[vsi->veb_idx];
Akeem G Abodunrin09603ea2015-10-01 14:37:36 -04009115 if (!veb) {
9116 dev_info(&pf->pdev->dev,
9117 "There is no veb associated with the bridge\n");
9118 return -ENOENT;
9119 }
Neerav Parikh51616012015-02-06 08:52:14 +00009120
Akeem G Abodunrin09603ea2015-10-01 14:37:36 -04009121 /* Uplink is a bridge in VEPA mode */
9122 if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
9123 return 0;
9124 } else {
9125 /* Uplink is a bridge in VEB mode */
9126 return 1;
9127 }
9128
9129 /* VEPA is now default bridge, so return 0 */
9130 return 0;
Neerav Parikh51616012015-02-06 08:52:14 +00009131}
9132
9133/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009134 * i40e_add_vsi - Add a VSI to the switch
9135 * @vsi: the VSI being configured
9136 *
9137 * This initializes a VSI context depending on the VSI type to be added and
9138 * passes it down to the add_vsi aq command.
9139 **/
9140static int i40e_add_vsi(struct i40e_vsi *vsi)
9141{
9142 int ret = -ENODEV;
Kiran Patil21659032015-09-30 14:09:03 -04009143 u8 laa_macaddr[ETH_ALEN];
9144 bool found_laa_mac_filter = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009145 struct i40e_pf *pf = vsi->back;
9146 struct i40e_hw *hw = &pf->hw;
9147 struct i40e_vsi_context ctxt;
Kiran Patil21659032015-09-30 14:09:03 -04009148 struct i40e_mac_filter *f, *ftmp;
9149
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009150 u8 enabled_tc = 0x1; /* TC0 enabled */
9151 int f_count = 0;
9152
9153 memset(&ctxt, 0, sizeof(ctxt));
9154 switch (vsi->type) {
9155 case I40E_VSI_MAIN:
9156 /* The PF's main VSI is already setup as part of the
9157 * device initialization, so we'll not bother with
9158 * the add_vsi call, but we will retrieve the current
9159 * VSI context.
9160 */
9161 ctxt.seid = pf->main_vsi_seid;
9162 ctxt.pf_num = pf->hw.pf_id;
9163 ctxt.vf_num = 0;
9164 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
9165 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
9166 if (ret) {
9167 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009168 "couldn't get PF vsi config, err %s aq_err %s\n",
9169 i40e_stat_str(&pf->hw, ret),
9170 i40e_aq_str(&pf->hw,
9171 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009172 return -ENOENT;
9173 }
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07009174 vsi->info = ctxt.info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009175 vsi->info.valid_sections = 0;
9176
9177 vsi->seid = ctxt.seid;
9178 vsi->id = ctxt.vsi_number;
9179
9180 enabled_tc = i40e_pf_get_tc_map(pf);
9181
9182 /* MFP mode setup queue map and update VSI */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00009183 if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
9184 !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009185 memset(&ctxt, 0, sizeof(ctxt));
9186 ctxt.seid = pf->main_vsi_seid;
9187 ctxt.pf_num = pf->hw.pf_id;
9188 ctxt.vf_num = 0;
9189 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
9190 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
9191 if (ret) {
9192 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009193 "update vsi failed, err %s aq_err %s\n",
9194 i40e_stat_str(&pf->hw, ret),
9195 i40e_aq_str(&pf->hw,
9196 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009197 ret = -ENOENT;
9198 goto err;
9199 }
9200 /* update the local VSI info queue map */
9201 i40e_vsi_update_queue_map(vsi, &ctxt);
9202 vsi->info.valid_sections = 0;
9203 } else {
9204 /* Default/Main VSI is only enabled for TC0
9205 * reconfigure it to enable all TCs that are
9206 * available on the port in SFP mode.
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00009207 * For MFP case the iSCSI PF would use this
9208 * flow to enable LAN+iSCSI TC.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009209 */
9210 ret = i40e_vsi_config_tc(vsi, enabled_tc);
9211 if (ret) {
9212 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009213 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
9214 enabled_tc,
9215 i40e_stat_str(&pf->hw, ret),
9216 i40e_aq_str(&pf->hw,
9217 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009218 ret = -ENOENT;
9219 }
9220 }
9221 break;
9222
9223 case I40E_VSI_FDIR:
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009224 ctxt.pf_num = hw->pf_id;
9225 ctxt.vf_num = 0;
9226 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009227 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009228 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009229 if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
9230 (i40e_is_vsi_uplink_mode_veb(vsi))) {
Neerav Parikh51616012015-02-06 08:52:14 +00009231 ctxt.info.valid_sections |=
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009232 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
Neerav Parikh51616012015-02-06 08:52:14 +00009233 ctxt.info.switch_id =
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009234 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
Neerav Parikh51616012015-02-06 08:52:14 +00009235 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009236 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009237 break;
9238
9239 case I40E_VSI_VMDQ2:
9240 ctxt.pf_num = hw->pf_id;
9241 ctxt.vf_num = 0;
9242 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009243 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009244 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
9245
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009246 /* This VSI is connected to VEB so the switch_id
9247 * should be set to zero by default.
9248 */
Neerav Parikh51616012015-02-06 08:52:14 +00009249 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
9250 ctxt.info.valid_sections |=
9251 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9252 ctxt.info.switch_id =
9253 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9254 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009255
9256 /* Setup the VSI tx/rx queue map for TC0 only for now */
9257 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9258 break;
9259
9260 case I40E_VSI_SRIOV:
9261 ctxt.pf_num = hw->pf_id;
9262 ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
9263 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009264 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009265 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
9266
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009267 /* This VSI is connected to VEB so the switch_id
9268 * should be set to zero by default.
9269 */
Neerav Parikh51616012015-02-06 08:52:14 +00009270 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
9271 ctxt.info.valid_sections |=
9272 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9273 ctxt.info.switch_id =
9274 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9275 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009276
9277 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
9278 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
Mitch Williamsc674d122014-05-20 08:01:40 +00009279 if (pf->vf[vsi->vf_id].spoofchk) {
9280 ctxt.info.valid_sections |=
9281 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
9282 ctxt.info.sec_flags |=
9283 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
9284 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
9285 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009286 /* Setup the VSI tx/rx queue map for TC0 only for now */
9287 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9288 break;
9289
Vasu Dev38e00432014-08-01 13:27:03 -07009290#ifdef I40E_FCOE
9291 case I40E_VSI_FCOE:
9292 ret = i40e_fcoe_vsi_init(vsi, &ctxt);
9293 if (ret) {
9294 dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n");
9295 return ret;
9296 }
9297 break;
9298
9299#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009300 default:
9301 return -ENODEV;
9302 }
9303
9304 if (vsi->type != I40E_VSI_MAIN) {
9305 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
9306 if (ret) {
9307 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009308 "add vsi failed, err %s aq_err %s\n",
9309 i40e_stat_str(&pf->hw, ret),
9310 i40e_aq_str(&pf->hw,
9311 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009312 ret = -ENOENT;
9313 goto err;
9314 }
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07009315 vsi->info = ctxt.info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009316 vsi->info.valid_sections = 0;
9317 vsi->seid = ctxt.seid;
9318 vsi->id = ctxt.vsi_number;
9319 }
9320
Kiran Patil21659032015-09-30 14:09:03 -04009321 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009322 /* If macvlan filters already exist, force them to get loaded */
9323 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
9324 f->changed = true;
9325 f_count++;
Shannon Nelson6252c7e2014-06-04 01:23:23 +00009326
Kiran Patil21659032015-09-30 14:09:03 -04009327 /* Expected to have only one MAC filter entry for LAA in list */
Shannon Nelson6252c7e2014-06-04 01:23:23 +00009328 if (f->is_laa && vsi->type == I40E_VSI_MAIN) {
Kiran Patil21659032015-09-30 14:09:03 -04009329 ether_addr_copy(laa_macaddr, f->macaddr);
9330 found_laa_mac_filter = true;
Shannon Nelson6252c7e2014-06-04 01:23:23 +00009331 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009332 }
Kiran Patil21659032015-09-30 14:09:03 -04009333 spin_unlock_bh(&vsi->mac_filter_list_lock);
9334
9335 if (found_laa_mac_filter) {
9336 struct i40e_aqc_remove_macvlan_element_data element;
9337
9338 memset(&element, 0, sizeof(element));
9339 ether_addr_copy(element.mac_addr, laa_macaddr);
9340 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
9341 ret = i40e_aq_remove_macvlan(hw, vsi->seid,
9342 &element, 1, NULL);
9343 if (ret) {
9344 /* some older FW has a different default */
9345 element.flags |=
9346 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
9347 i40e_aq_remove_macvlan(hw, vsi->seid,
9348 &element, 1, NULL);
9349 }
9350
9351 i40e_aq_mac_address_write(hw,
9352 I40E_AQC_WRITE_TYPE_LAA_WOL,
9353 laa_macaddr, NULL);
9354 }
9355
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009356 if (f_count) {
9357 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
9358 pf->flags |= I40E_FLAG_FILTER_SYNC;
9359 }
9360
9361 /* Update VSI BW information */
9362 ret = i40e_vsi_get_bw_info(vsi);
9363 if (ret) {
9364 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009365 "couldn't get vsi bw info, err %s aq_err %s\n",
9366 i40e_stat_str(&pf->hw, ret),
9367 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009368 /* VSI is already added so not tearing that up */
9369 ret = 0;
9370 }
9371
9372err:
9373 return ret;
9374}
9375
9376/**
9377 * i40e_vsi_release - Delete a VSI and free its resources
9378 * @vsi: the VSI being removed
9379 *
9380 * Returns 0 on success or < 0 on error
9381 **/
9382int i40e_vsi_release(struct i40e_vsi *vsi)
9383{
9384 struct i40e_mac_filter *f, *ftmp;
9385 struct i40e_veb *veb = NULL;
9386 struct i40e_pf *pf;
9387 u16 uplink_seid;
9388 int i, n;
9389
9390 pf = vsi->back;
9391
9392 /* release of a VEB-owner or last VSI is not allowed */
9393 if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
9394 dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
9395 vsi->seid, vsi->uplink_seid);
9396 return -ENODEV;
9397 }
9398 if (vsi == pf->vsi[pf->lan_vsi] &&
9399 !test_bit(__I40E_DOWN, &pf->state)) {
9400 dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
9401 return -ENODEV;
9402 }
9403
9404 uplink_seid = vsi->uplink_seid;
9405 if (vsi->type != I40E_VSI_SRIOV) {
9406 if (vsi->netdev_registered) {
9407 vsi->netdev_registered = false;
9408 if (vsi->netdev) {
9409 /* results in a call to i40e_close() */
9410 unregister_netdev(vsi->netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009411 }
9412 } else {
Shannon Nelson90ef8d42014-03-14 07:32:26 +00009413 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009414 }
9415 i40e_vsi_disable_irq(vsi);
9416 }
9417
Kiran Patil21659032015-09-30 14:09:03 -04009418 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009419 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
9420 i40e_del_filter(vsi, f->macaddr, f->vlan,
9421 f->is_vf, f->is_netdev);
Kiran Patil21659032015-09-30 14:09:03 -04009422 spin_unlock_bh(&vsi->mac_filter_list_lock);
9423
Jesse Brandeburg17652c62015-11-05 17:01:02 -08009424 i40e_sync_vsi_filters(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009425
9426 i40e_vsi_delete(vsi);
9427 i40e_vsi_free_q_vectors(vsi);
Shannon Nelsona4866592014-02-11 08:24:07 +00009428 if (vsi->netdev) {
9429 free_netdev(vsi->netdev);
9430 vsi->netdev = NULL;
9431 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009432 i40e_vsi_clear_rings(vsi);
9433 i40e_vsi_clear(vsi);
9434
9435 /* If this was the last thing on the VEB, except for the
9436 * controlling VSI, remove the VEB, which puts the controlling
9437 * VSI onto the next level down in the switch.
9438 *
9439 * Well, okay, there's one more exception here: don't remove
9440 * the orphan VEBs yet. We'll wait for an explicit remove request
9441 * from up the network stack.
9442 */
Mitch Williams505682c2014-05-20 08:01:37 +00009443 for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009444 if (pf->vsi[i] &&
9445 pf->vsi[i]->uplink_seid == uplink_seid &&
9446 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
9447 n++; /* count the VSIs */
9448 }
9449 }
9450 for (i = 0; i < I40E_MAX_VEB; i++) {
9451 if (!pf->veb[i])
9452 continue;
9453 if (pf->veb[i]->uplink_seid == uplink_seid)
9454 n++; /* count the VEBs */
9455 if (pf->veb[i]->seid == uplink_seid)
9456 veb = pf->veb[i];
9457 }
9458 if (n == 0 && veb && veb->uplink_seid != 0)
9459 i40e_veb_release(veb);
9460
9461 return 0;
9462}
9463
9464/**
9465 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
9466 * @vsi: ptr to the VSI
9467 *
9468 * This should only be called after i40e_vsi_mem_alloc() which allocates the
9469 * corresponding SW VSI structure and initializes num_queue_pairs for the
9470 * newly allocated VSI.
9471 *
9472 * Returns 0 on success or negative on failure
9473 **/
9474static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
9475{
9476 int ret = -ENOENT;
9477 struct i40e_pf *pf = vsi->back;
9478
Alexander Duyck493fb302013-09-28 07:01:44 +00009479 if (vsi->q_vectors[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009480 dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
9481 vsi->seid);
9482 return -EEXIST;
9483 }
9484
9485 if (vsi->base_vector) {
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00009486 dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009487 vsi->seid, vsi->base_vector);
9488 return -EEXIST;
9489 }
9490
Greg Rose90e04072014-03-06 08:59:57 +00009491 ret = i40e_vsi_alloc_q_vectors(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009492 if (ret) {
9493 dev_info(&pf->pdev->dev,
9494 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
9495 vsi->num_q_vectors, vsi->seid, ret);
9496 vsi->num_q_vectors = 0;
9497 goto vector_setup_out;
9498 }
9499
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04009500 /* In Legacy mode, we do not have to get any other vector since we
9501 * piggyback on the misc/ICR0 for queue interrupts.
9502 */
9503 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
9504 return ret;
Shannon Nelson958a3e32013-09-28 07:13:28 +00009505 if (vsi->num_q_vectors)
9506 vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
9507 vsi->num_q_vectors, vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009508 if (vsi->base_vector < 0) {
9509 dev_info(&pf->pdev->dev,
Shannon Nelson049a2be2014-10-17 03:14:50 +00009510 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
9511 vsi->num_q_vectors, vsi->seid, vsi->base_vector);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009512 i40e_vsi_free_q_vectors(vsi);
9513 ret = -ENOENT;
9514 goto vector_setup_out;
9515 }
9516
9517vector_setup_out:
9518 return ret;
9519}
9520
9521/**
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009522 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
9523 * @vsi: pointer to the vsi.
9524 *
9525 * This re-allocates a vsi's queue resources.
9526 *
9527 * Returns pointer to the successfully allocated and configured VSI sw struct
9528 * on success, otherwise returns NULL on failure.
9529 **/
9530static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
9531{
9532 struct i40e_pf *pf = vsi->back;
9533 u8 enabled_tc;
9534 int ret;
9535
9536 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
9537 i40e_vsi_clear_rings(vsi);
9538
9539 i40e_vsi_free_arrays(vsi, false);
9540 i40e_set_num_rings_in_vsi(vsi);
9541 ret = i40e_vsi_alloc_arrays(vsi, false);
9542 if (ret)
9543 goto err_vsi;
9544
9545 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
9546 if (ret < 0) {
Shannon Nelson049a2be2014-10-17 03:14:50 +00009547 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009548 "failed to get tracking for %d queues for VSI %d err %d\n",
Shannon Nelson049a2be2014-10-17 03:14:50 +00009549 vsi->alloc_queue_pairs, vsi->seid, ret);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009550 goto err_vsi;
9551 }
9552 vsi->base_queue = ret;
9553
9554 /* Update the FW view of the VSI. Force a reset of TC and queue
9555 * layout configurations.
9556 */
9557 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
9558 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
9559 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
9560 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
9561
9562 /* assign it some queues */
9563 ret = i40e_alloc_rings(vsi);
9564 if (ret)
9565 goto err_rings;
9566
9567 /* map all of the rings to the q_vectors */
9568 i40e_vsi_map_rings_to_vectors(vsi);
9569 return vsi;
9570
9571err_rings:
9572 i40e_vsi_free_q_vectors(vsi);
9573 if (vsi->netdev_registered) {
9574 vsi->netdev_registered = false;
9575 unregister_netdev(vsi->netdev);
9576 free_netdev(vsi->netdev);
9577 vsi->netdev = NULL;
9578 }
9579 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
9580err_vsi:
9581 i40e_vsi_clear(vsi);
9582 return NULL;
9583}
9584
9585/**
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -05009586 * i40e_macaddr_init - explicitly write the mac address filters.
9587 *
9588 * @vsi: pointer to the vsi.
9589 * @macaddr: the MAC address
9590 *
9591 * This is needed when the macaddr has been obtained by other
9592 * means than the default, e.g., from Open Firmware or IDPROM.
9593 * Returns 0 on success, negative on failure
9594 **/
9595static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr)
9596{
9597 int ret;
9598 struct i40e_aqc_add_macvlan_element_data element;
9599
9600 ret = i40e_aq_mac_address_write(&vsi->back->hw,
9601 I40E_AQC_WRITE_TYPE_LAA_WOL,
9602 macaddr, NULL);
9603 if (ret) {
9604 dev_info(&vsi->back->pdev->dev,
9605 "Addr change for VSI failed: %d\n", ret);
9606 return -EADDRNOTAVAIL;
9607 }
9608
9609 memset(&element, 0, sizeof(element));
9610 ether_addr_copy(element.mac_addr, macaddr);
9611 element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
9612 ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL);
9613 if (ret) {
9614 dev_info(&vsi->back->pdev->dev,
9615 "add filter failed err %s aq_err %s\n",
9616 i40e_stat_str(&vsi->back->hw, ret),
9617 i40e_aq_str(&vsi->back->hw,
9618 vsi->back->hw.aq.asq_last_status));
9619 }
9620 return ret;
9621}
9622
9623/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009624 * i40e_vsi_setup - Set up a VSI by a given type
9625 * @pf: board private structure
9626 * @type: VSI type
9627 * @uplink_seid: the switch element to link to
9628 * @param1: usage depends upon VSI type. For VF types, indicates VF id
9629 *
9630 * This allocates the sw VSI structure and its queue resources, then add a VSI
9631 * to the identified VEB.
9632 *
9633 * Returns pointer to the successfully allocated and configure VSI sw struct on
9634 * success, otherwise returns NULL on failure.
9635 **/
9636struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
9637 u16 uplink_seid, u32 param1)
9638{
9639 struct i40e_vsi *vsi = NULL;
9640 struct i40e_veb *veb = NULL;
9641 int ret, i;
9642 int v_idx;
9643
9644 /* The requested uplink_seid must be either
9645 * - the PF's port seid
9646 * no VEB is needed because this is the PF
9647 * or this is a Flow Director special case VSI
9648 * - seid of an existing VEB
9649 * - seid of a VSI that owns an existing VEB
9650 * - seid of a VSI that doesn't own a VEB
9651 * a new VEB is created and the VSI becomes the owner
9652 * - seid of the PF VSI, which is what creates the first VEB
9653 * this is a special case of the previous
9654 *
9655 * Find which uplink_seid we were given and create a new VEB if needed
9656 */
9657 for (i = 0; i < I40E_MAX_VEB; i++) {
9658 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
9659 veb = pf->veb[i];
9660 break;
9661 }
9662 }
9663
9664 if (!veb && uplink_seid != pf->mac_seid) {
9665
Mitch Williams505682c2014-05-20 08:01:37 +00009666 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009667 if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
9668 vsi = pf->vsi[i];
9669 break;
9670 }
9671 }
9672 if (!vsi) {
9673 dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
9674 uplink_seid);
9675 return NULL;
9676 }
9677
9678 if (vsi->uplink_seid == pf->mac_seid)
9679 veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
9680 vsi->tc_config.enabled_tc);
9681 else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
9682 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
9683 vsi->tc_config.enabled_tc);
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009684 if (veb) {
9685 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
9686 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04009687 "New VSI creation error, uplink seid of LAN VSI expected.\n");
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009688 return NULL;
9689 }
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -04009690 /* We come up by default in VEPA mode if SRIOV is not
9691 * already enabled, in which case we can't force VEPA
9692 * mode.
9693 */
9694 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
9695 veb->bridge_mode = BRIDGE_MODE_VEPA;
9696 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
9697 }
Neerav Parikh51616012015-02-06 08:52:14 +00009698 i40e_config_bridge_mode(veb);
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009699 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009700 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
9701 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
9702 veb = pf->veb[i];
9703 }
9704 if (!veb) {
9705 dev_info(&pf->pdev->dev, "couldn't add VEB\n");
9706 return NULL;
9707 }
9708
9709 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
9710 uplink_seid = veb->seid;
9711 }
9712
9713 /* get vsi sw struct */
9714 v_idx = i40e_vsi_mem_alloc(pf, type);
9715 if (v_idx < 0)
9716 goto err_alloc;
9717 vsi = pf->vsi[v_idx];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009718 if (!vsi)
9719 goto err_alloc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009720 vsi->type = type;
9721 vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
9722
9723 if (type == I40E_VSI_MAIN)
9724 pf->lan_vsi = v_idx;
9725 else if (type == I40E_VSI_SRIOV)
9726 vsi->vf_id = param1;
9727 /* assign it some queues */
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009728 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
9729 vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009730 if (ret < 0) {
Shannon Nelson049a2be2014-10-17 03:14:50 +00009731 dev_info(&pf->pdev->dev,
9732 "failed to get tracking for %d queues for VSI %d err=%d\n",
9733 vsi->alloc_queue_pairs, vsi->seid, ret);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009734 goto err_vsi;
9735 }
9736 vsi->base_queue = ret;
9737
9738 /* get a VSI from the hardware */
9739 vsi->uplink_seid = uplink_seid;
9740 ret = i40e_add_vsi(vsi);
9741 if (ret)
9742 goto err_vsi;
9743
9744 switch (vsi->type) {
9745 /* setup the netdev if needed */
9746 case I40E_VSI_MAIN:
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -05009747 /* Apply relevant filters if a platform-specific mac
9748 * address was selected.
9749 */
9750 if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
9751 ret = i40e_macaddr_init(vsi, pf->hw.mac.addr);
9752 if (ret) {
9753 dev_warn(&pf->pdev->dev,
9754 "could not set up macaddr; err %d\n",
9755 ret);
9756 }
9757 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009758 case I40E_VSI_VMDQ2:
Vasu Dev38e00432014-08-01 13:27:03 -07009759 case I40E_VSI_FCOE:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009760 ret = i40e_config_netdev(vsi);
9761 if (ret)
9762 goto err_netdev;
9763 ret = register_netdev(vsi->netdev);
9764 if (ret)
9765 goto err_netdev;
9766 vsi->netdev_registered = true;
9767 netif_carrier_off(vsi->netdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08009768#ifdef CONFIG_I40E_DCB
9769 /* Setup DCB netlink interface */
9770 i40e_dcbnl_setup(vsi);
9771#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009772 /* fall through */
9773
9774 case I40E_VSI_FDIR:
9775 /* set up vectors and rings if needed */
9776 ret = i40e_vsi_setup_vectors(vsi);
9777 if (ret)
9778 goto err_msix;
9779
9780 ret = i40e_alloc_rings(vsi);
9781 if (ret)
9782 goto err_rings;
9783
9784 /* map all of the rings to the q_vectors */
9785 i40e_vsi_map_rings_to_vectors(vsi);
9786
9787 i40e_vsi_reset_stats(vsi);
9788 break;
9789
9790 default:
9791 /* no netdev or rings for the other VSI types */
9792 break;
9793 }
9794
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04009795 if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
9796 (vsi->type == I40E_VSI_VMDQ2)) {
9797 ret = i40e_vsi_config_rss(vsi);
9798 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009799 return vsi;
9800
9801err_rings:
9802 i40e_vsi_free_q_vectors(vsi);
9803err_msix:
9804 if (vsi->netdev_registered) {
9805 vsi->netdev_registered = false;
9806 unregister_netdev(vsi->netdev);
9807 free_netdev(vsi->netdev);
9808 vsi->netdev = NULL;
9809 }
9810err_netdev:
9811 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
9812err_vsi:
9813 i40e_vsi_clear(vsi);
9814err_alloc:
9815 return NULL;
9816}
9817
9818/**
9819 * i40e_veb_get_bw_info - Query VEB BW information
9820 * @veb: the veb to query
9821 *
9822 * Query the Tx scheduler BW configuration data for given VEB
9823 **/
9824static int i40e_veb_get_bw_info(struct i40e_veb *veb)
9825{
9826 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
9827 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
9828 struct i40e_pf *pf = veb->pf;
9829 struct i40e_hw *hw = &pf->hw;
9830 u32 tc_bw_max;
9831 int ret = 0;
9832 int i;
9833
9834 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
9835 &bw_data, NULL);
9836 if (ret) {
9837 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009838 "query veb bw config failed, err %s aq_err %s\n",
9839 i40e_stat_str(&pf->hw, ret),
9840 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009841 goto out;
9842 }
9843
9844 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
9845 &ets_data, NULL);
9846 if (ret) {
9847 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009848 "query veb bw ets config failed, err %s aq_err %s\n",
9849 i40e_stat_str(&pf->hw, ret),
9850 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009851 goto out;
9852 }
9853
9854 veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
9855 veb->bw_max_quanta = ets_data.tc_bw_max;
9856 veb->is_abs_credits = bw_data.absolute_credits_enable;
Neerav Parikh23cd1f02014-11-12 00:18:41 +00009857 veb->enabled_tc = ets_data.tc_valid_bits;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009858 tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
9859 (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
9860 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
9861 veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
9862 veb->bw_tc_limit_credits[i] =
9863 le16_to_cpu(bw_data.tc_bw_limits[i]);
9864 veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
9865 }
9866
9867out:
9868 return ret;
9869}
9870
9871/**
9872 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
9873 * @pf: board private structure
9874 *
9875 * On error: returns error code (negative)
9876 * On success: returns vsi index in PF (positive)
9877 **/
9878static int i40e_veb_mem_alloc(struct i40e_pf *pf)
9879{
9880 int ret = -ENOENT;
9881 struct i40e_veb *veb;
9882 int i;
9883
9884 /* Need to protect the allocation of switch elements at the PF level */
9885 mutex_lock(&pf->switch_mutex);
9886
9887 /* VEB list may be fragmented if VEB creation/destruction has
9888 * been happening. We can afford to do a quick scan to look
9889 * for any free slots in the list.
9890 *
9891 * find next empty veb slot, looping back around if necessary
9892 */
9893 i = 0;
9894 while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
9895 i++;
9896 if (i >= I40E_MAX_VEB) {
9897 ret = -ENOMEM;
9898 goto err_alloc_veb; /* out of VEB slots! */
9899 }
9900
9901 veb = kzalloc(sizeof(*veb), GFP_KERNEL);
9902 if (!veb) {
9903 ret = -ENOMEM;
9904 goto err_alloc_veb;
9905 }
9906 veb->pf = pf;
9907 veb->idx = i;
9908 veb->enabled_tc = 1;
9909
9910 pf->veb[i] = veb;
9911 ret = i;
9912err_alloc_veb:
9913 mutex_unlock(&pf->switch_mutex);
9914 return ret;
9915}
9916
9917/**
9918 * i40e_switch_branch_release - Delete a branch of the switch tree
9919 * @branch: where to start deleting
9920 *
9921 * This uses recursion to find the tips of the branch to be
9922 * removed, deleting until we get back to and can delete this VEB.
9923 **/
9924static void i40e_switch_branch_release(struct i40e_veb *branch)
9925{
9926 struct i40e_pf *pf = branch->pf;
9927 u16 branch_seid = branch->seid;
9928 u16 veb_idx = branch->idx;
9929 int i;
9930
9931 /* release any VEBs on this VEB - RECURSION */
9932 for (i = 0; i < I40E_MAX_VEB; i++) {
9933 if (!pf->veb[i])
9934 continue;
9935 if (pf->veb[i]->uplink_seid == branch->seid)
9936 i40e_switch_branch_release(pf->veb[i]);
9937 }
9938
9939 /* Release the VSIs on this VEB, but not the owner VSI.
9940 *
9941 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
9942 * the VEB itself, so don't use (*branch) after this loop.
9943 */
Mitch Williams505682c2014-05-20 08:01:37 +00009944 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009945 if (!pf->vsi[i])
9946 continue;
9947 if (pf->vsi[i]->uplink_seid == branch_seid &&
9948 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
9949 i40e_vsi_release(pf->vsi[i]);
9950 }
9951 }
9952
9953 /* There's one corner case where the VEB might not have been
9954 * removed, so double check it here and remove it if needed.
9955 * This case happens if the veb was created from the debugfs
9956 * commands and no VSIs were added to it.
9957 */
9958 if (pf->veb[veb_idx])
9959 i40e_veb_release(pf->veb[veb_idx]);
9960}
9961
9962/**
9963 * i40e_veb_clear - remove veb struct
9964 * @veb: the veb to remove
9965 **/
9966static void i40e_veb_clear(struct i40e_veb *veb)
9967{
9968 if (!veb)
9969 return;
9970
9971 if (veb->pf) {
9972 struct i40e_pf *pf = veb->pf;
9973
9974 mutex_lock(&pf->switch_mutex);
9975 if (pf->veb[veb->idx] == veb)
9976 pf->veb[veb->idx] = NULL;
9977 mutex_unlock(&pf->switch_mutex);
9978 }
9979
9980 kfree(veb);
9981}
9982
9983/**
9984 * i40e_veb_release - Delete a VEB and free its resources
9985 * @veb: the VEB being removed
9986 **/
9987void i40e_veb_release(struct i40e_veb *veb)
9988{
9989 struct i40e_vsi *vsi = NULL;
9990 struct i40e_pf *pf;
9991 int i, n = 0;
9992
9993 pf = veb->pf;
9994
9995 /* find the remaining VSI and check for extras */
Mitch Williams505682c2014-05-20 08:01:37 +00009996 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009997 if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
9998 n++;
9999 vsi = pf->vsi[i];
10000 }
10001 }
10002 if (n != 1) {
10003 dev_info(&pf->pdev->dev,
10004 "can't remove VEB %d with %d VSIs left\n",
10005 veb->seid, n);
10006 return;
10007 }
10008
10009 /* move the remaining VSI to uplink veb */
10010 vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
10011 if (veb->uplink_seid) {
10012 vsi->uplink_seid = veb->uplink_seid;
10013 if (veb->uplink_seid == pf->mac_seid)
10014 vsi->veb_idx = I40E_NO_VEB;
10015 else
10016 vsi->veb_idx = veb->veb_idx;
10017 } else {
10018 /* floating VEB */
10019 vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
10020 vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
10021 }
10022
10023 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
10024 i40e_veb_clear(veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010025}
10026
10027/**
10028 * i40e_add_veb - create the VEB in the switch
10029 * @veb: the VEB to be instantiated
10030 * @vsi: the controlling VSI
10031 **/
10032static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
10033{
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010034 struct i40e_pf *pf = veb->pf;
Anjali Singhai Jain92faef82015-07-28 13:02:00 -040010035 bool is_default = veb->pf->cur_promisc;
Kevin Scotte1c51b952013-11-20 10:02:51 +000010036 bool is_cloud = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010037 int ret;
10038
10039 /* get a VEB from the hardware */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010040 ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
Kevin Scotte1c51b952013-11-20 10:02:51 +000010041 veb->enabled_tc, is_default,
10042 is_cloud, &veb->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010043 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010044 dev_info(&pf->pdev->dev,
10045 "couldn't add VEB, err %s aq_err %s\n",
10046 i40e_stat_str(&pf->hw, ret),
10047 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010048 return -EPERM;
10049 }
10050
10051 /* get statistics counter */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010052 ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010053 &veb->stats_idx, NULL, NULL, NULL);
10054 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010055 dev_info(&pf->pdev->dev,
10056 "couldn't get VEB statistics idx, err %s aq_err %s\n",
10057 i40e_stat_str(&pf->hw, ret),
10058 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010059 return -EPERM;
10060 }
10061 ret = i40e_veb_get_bw_info(veb);
10062 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010063 dev_info(&pf->pdev->dev,
10064 "couldn't get VEB bw info, err %s aq_err %s\n",
10065 i40e_stat_str(&pf->hw, ret),
10066 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10067 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010068 return -ENOENT;
10069 }
10070
10071 vsi->uplink_seid = veb->seid;
10072 vsi->veb_idx = veb->idx;
10073 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
10074
10075 return 0;
10076}
10077
10078/**
10079 * i40e_veb_setup - Set up a VEB
10080 * @pf: board private structure
10081 * @flags: VEB setup flags
10082 * @uplink_seid: the switch element to link to
10083 * @vsi_seid: the initial VSI seid
10084 * @enabled_tc: Enabled TC bit-map
10085 *
10086 * This allocates the sw VEB structure and links it into the switch
10087 * It is possible and legal for this to be a duplicate of an already
10088 * existing VEB. It is also possible for both uplink and vsi seids
10089 * to be zero, in order to create a floating VEB.
10090 *
10091 * Returns pointer to the successfully allocated VEB sw struct on
10092 * success, otherwise returns NULL on failure.
10093 **/
10094struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
10095 u16 uplink_seid, u16 vsi_seid,
10096 u8 enabled_tc)
10097{
10098 struct i40e_veb *veb, *uplink_veb = NULL;
10099 int vsi_idx, veb_idx;
10100 int ret;
10101
10102 /* if one seid is 0, the other must be 0 to create a floating relay */
10103 if ((uplink_seid == 0 || vsi_seid == 0) &&
10104 (uplink_seid + vsi_seid != 0)) {
10105 dev_info(&pf->pdev->dev,
10106 "one, not both seid's are 0: uplink=%d vsi=%d\n",
10107 uplink_seid, vsi_seid);
10108 return NULL;
10109 }
10110
10111 /* make sure there is such a vsi and uplink */
Mitch Williams505682c2014-05-20 08:01:37 +000010112 for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010113 if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
10114 break;
Mitch Williams505682c2014-05-20 08:01:37 +000010115 if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010116 dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
10117 vsi_seid);
10118 return NULL;
10119 }
10120
10121 if (uplink_seid && uplink_seid != pf->mac_seid) {
10122 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
10123 if (pf->veb[veb_idx] &&
10124 pf->veb[veb_idx]->seid == uplink_seid) {
10125 uplink_veb = pf->veb[veb_idx];
10126 break;
10127 }
10128 }
10129 if (!uplink_veb) {
10130 dev_info(&pf->pdev->dev,
10131 "uplink seid %d not found\n", uplink_seid);
10132 return NULL;
10133 }
10134 }
10135
10136 /* get veb sw struct */
10137 veb_idx = i40e_veb_mem_alloc(pf);
10138 if (veb_idx < 0)
10139 goto err_alloc;
10140 veb = pf->veb[veb_idx];
10141 veb->flags = flags;
10142 veb->uplink_seid = uplink_seid;
10143 veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
10144 veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
10145
10146 /* create the VEB in the switch */
10147 ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
10148 if (ret)
10149 goto err_veb;
Shannon Nelson1bb8b932014-04-23 04:49:54 +000010150 if (vsi_idx == pf->lan_vsi)
10151 pf->lan_veb = veb->idx;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010152
10153 return veb;
10154
10155err_veb:
10156 i40e_veb_clear(veb);
10157err_alloc:
10158 return NULL;
10159}
10160
10161/**
Jeff Kirsherb40c82e2015-02-27 09:18:34 +000010162 * i40e_setup_pf_switch_element - set PF vars based on switch type
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010163 * @pf: board private structure
10164 * @ele: element we are building info from
10165 * @num_reported: total number of elements
10166 * @printconfig: should we print the contents
10167 *
10168 * helper function to assist in extracting a few useful SEID values.
10169 **/
10170static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
10171 struct i40e_aqc_switch_config_element_resp *ele,
10172 u16 num_reported, bool printconfig)
10173{
10174 u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
10175 u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
10176 u8 element_type = ele->element_type;
10177 u16 seid = le16_to_cpu(ele->seid);
10178
10179 if (printconfig)
10180 dev_info(&pf->pdev->dev,
10181 "type=%d seid=%d uplink=%d downlink=%d\n",
10182 element_type, seid, uplink_seid, downlink_seid);
10183
10184 switch (element_type) {
10185 case I40E_SWITCH_ELEMENT_TYPE_MAC:
10186 pf->mac_seid = seid;
10187 break;
10188 case I40E_SWITCH_ELEMENT_TYPE_VEB:
10189 /* Main VEB? */
10190 if (uplink_seid != pf->mac_seid)
10191 break;
10192 if (pf->lan_veb == I40E_NO_VEB) {
10193 int v;
10194
10195 /* find existing or else empty VEB */
10196 for (v = 0; v < I40E_MAX_VEB; v++) {
10197 if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
10198 pf->lan_veb = v;
10199 break;
10200 }
10201 }
10202 if (pf->lan_veb == I40E_NO_VEB) {
10203 v = i40e_veb_mem_alloc(pf);
10204 if (v < 0)
10205 break;
10206 pf->lan_veb = v;
10207 }
10208 }
10209
10210 pf->veb[pf->lan_veb]->seid = seid;
10211 pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
10212 pf->veb[pf->lan_veb]->pf = pf;
10213 pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
10214 break;
10215 case I40E_SWITCH_ELEMENT_TYPE_VSI:
10216 if (num_reported != 1)
10217 break;
10218 /* This is immediately after a reset so we can assume this is
10219 * the PF's VSI
10220 */
10221 pf->mac_seid = uplink_seid;
10222 pf->pf_seid = downlink_seid;
10223 pf->main_vsi_seid = seid;
10224 if (printconfig)
10225 dev_info(&pf->pdev->dev,
10226 "pf_seid=%d main_vsi_seid=%d\n",
10227 pf->pf_seid, pf->main_vsi_seid);
10228 break;
10229 case I40E_SWITCH_ELEMENT_TYPE_PF:
10230 case I40E_SWITCH_ELEMENT_TYPE_VF:
10231 case I40E_SWITCH_ELEMENT_TYPE_EMP:
10232 case I40E_SWITCH_ELEMENT_TYPE_BMC:
10233 case I40E_SWITCH_ELEMENT_TYPE_PE:
10234 case I40E_SWITCH_ELEMENT_TYPE_PA:
10235 /* ignore these for now */
10236 break;
10237 default:
10238 dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
10239 element_type, seid);
10240 break;
10241 }
10242}
10243
10244/**
10245 * i40e_fetch_switch_configuration - Get switch config from firmware
10246 * @pf: board private structure
10247 * @printconfig: should we print the contents
10248 *
10249 * Get the current switch configuration from the device and
10250 * extract a few useful SEID values.
10251 **/
10252int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
10253{
10254 struct i40e_aqc_get_switch_config_resp *sw_config;
10255 u16 next_seid = 0;
10256 int ret = 0;
10257 u8 *aq_buf;
10258 int i;
10259
10260 aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
10261 if (!aq_buf)
10262 return -ENOMEM;
10263
10264 sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
10265 do {
10266 u16 num_reported, num_total;
10267
10268 ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
10269 I40E_AQ_LARGE_BUF,
10270 &next_seid, NULL);
10271 if (ret) {
10272 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010273 "get switch config failed err %s aq_err %s\n",
10274 i40e_stat_str(&pf->hw, ret),
10275 i40e_aq_str(&pf->hw,
10276 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010277 kfree(aq_buf);
10278 return -ENOENT;
10279 }
10280
10281 num_reported = le16_to_cpu(sw_config->header.num_reported);
10282 num_total = le16_to_cpu(sw_config->header.num_total);
10283
10284 if (printconfig)
10285 dev_info(&pf->pdev->dev,
10286 "header: %d reported %d total\n",
10287 num_reported, num_total);
10288
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010289 for (i = 0; i < num_reported; i++) {
10290 struct i40e_aqc_switch_config_element_resp *ele =
10291 &sw_config->element[i];
10292
10293 i40e_setup_pf_switch_element(pf, ele, num_reported,
10294 printconfig);
10295 }
10296 } while (next_seid != 0);
10297
10298 kfree(aq_buf);
10299 return ret;
10300}
10301
10302/**
10303 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
10304 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010305 * @reinit: if the Main VSI needs to re-initialized.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010306 *
10307 * Returns 0 on success, negative value on failure
10308 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010309static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010310{
10311 int ret;
10312
10313 /* find out what's out there already */
10314 ret = i40e_fetch_switch_configuration(pf, false);
10315 if (ret) {
10316 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010317 "couldn't fetch switch config, err %s aq_err %s\n",
10318 i40e_stat_str(&pf->hw, ret),
10319 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010320 return ret;
10321 }
10322 i40e_pf_reset_stats(pf);
10323
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010324 /* first time setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010325 if (pf->lan_vsi == I40E_NO_VSI || reinit) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010326 struct i40e_vsi *vsi = NULL;
10327 u16 uplink_seid;
10328
10329 /* Set up the PF VSI associated with the PF's main VSI
10330 * that is already in the HW switch
10331 */
10332 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
10333 uplink_seid = pf->veb[pf->lan_veb]->seid;
10334 else
10335 uplink_seid = pf->mac_seid;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010336 if (pf->lan_vsi == I40E_NO_VSI)
10337 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
10338 else if (reinit)
10339 vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010340 if (!vsi) {
10341 dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
10342 i40e_fdir_teardown(pf);
10343 return -EAGAIN;
10344 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010345 } else {
10346 /* force a reset of TC and queue layout configurations */
10347 u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -040010348
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010349 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
10350 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
10351 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
10352 }
10353 i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
10354
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010355 i40e_fdir_sb_setup(pf);
10356
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010357 /* Setup static PF queue filter control settings */
10358 ret = i40e_setup_pf_filter_control(pf);
10359 if (ret) {
10360 dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
10361 ret);
10362 /* Failure here should not stop continuing other steps */
10363 }
10364
10365 /* enable RSS in the HW, even for only one queue, as the stack can use
10366 * the hash
10367 */
10368 if ((pf->flags & I40E_FLAG_RSS_ENABLED))
Helin Zhang043dd652015-10-21 19:56:23 -040010369 i40e_pf_config_rss(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010370
10371 /* fill in link information and enable LSE reporting */
Catherine Sullivan0a862b42015-08-31 19:54:53 -040010372 i40e_update_link_info(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010373 i40e_link_event(pf);
10374
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000010375 /* Initialize user-specific link properties */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010376 pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
10377 I40E_AQ_AN_COMPLETED) ? true : false);
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000010378
Jacob Kellerbeb0dff2014-01-11 05:43:19 +000010379 i40e_ptp_init(pf);
10380
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010381 return ret;
10382}
10383
10384/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010385 * i40e_determine_queue_usage - Work out queue distribution
10386 * @pf: board private structure
10387 **/
10388static void i40e_determine_queue_usage(struct i40e_pf *pf)
10389{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010390 int queues_left;
10391
10392 pf->num_lan_qps = 0;
Vasu Dev38e00432014-08-01 13:27:03 -070010393#ifdef I40E_FCOE
10394 pf->num_fcoe_qps = 0;
10395#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010396
10397 /* Find the max queues to be put into basic use. We'll always be
10398 * using TC0, whether or not DCB is running, and TC0 will get the
10399 * big RSS set.
10400 */
10401 queues_left = pf->hw.func_caps.num_tx_qp;
10402
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010403 if ((queues_left == 1) ||
Frank Zhang9aa7e932014-05-20 08:01:42 +000010404 !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010405 /* one qp for PF, no queues for anything else */
10406 queues_left = 0;
Helin Zhangacd65442015-10-26 19:44:28 -040010407 pf->alloc_rss_size = pf->num_lan_qps = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010408
10409 /* make sure all the fancies are disabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010410 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -070010411#ifdef I40E_FCOE
10412 I40E_FLAG_FCOE_ENABLED |
10413#endif
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010414 I40E_FLAG_FD_SB_ENABLED |
10415 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010416 I40E_FLAG_DCB_CAPABLE |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010417 I40E_FLAG_SRIOV_ENABLED |
10418 I40E_FLAG_VMDQ_ENABLED);
Frank Zhang9aa7e932014-05-20 08:01:42 +000010419 } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
10420 I40E_FLAG_FD_SB_ENABLED |
Anjali Singhai Jainbbe7d0e2014-05-20 08:01:44 +000010421 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010422 I40E_FLAG_DCB_CAPABLE))) {
Frank Zhang9aa7e932014-05-20 08:01:42 +000010423 /* one qp for PF */
Helin Zhangacd65442015-10-26 19:44:28 -040010424 pf->alloc_rss_size = pf->num_lan_qps = 1;
Frank Zhang9aa7e932014-05-20 08:01:42 +000010425 queues_left -= pf->num_lan_qps;
10426
10427 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -070010428#ifdef I40E_FCOE
10429 I40E_FLAG_FCOE_ENABLED |
10430#endif
Frank Zhang9aa7e932014-05-20 08:01:42 +000010431 I40E_FLAG_FD_SB_ENABLED |
10432 I40E_FLAG_FD_ATR_ENABLED |
10433 I40E_FLAG_DCB_ENABLED |
10434 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010435 } else {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010436 /* Not enough queues for all TCs */
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010437 if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010438 (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010439 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010440 dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
10441 }
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +000010442 pf->num_lan_qps = max_t(int, pf->rss_size_max,
10443 num_online_cpus());
10444 pf->num_lan_qps = min_t(int, pf->num_lan_qps,
10445 pf->hw.func_caps.num_tx_qp);
10446
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010447 queues_left -= pf->num_lan_qps;
10448 }
10449
Vasu Dev38e00432014-08-01 13:27:03 -070010450#ifdef I40E_FCOE
10451 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
10452 if (I40E_DEFAULT_FCOE <= queues_left) {
10453 pf->num_fcoe_qps = I40E_DEFAULT_FCOE;
10454 } else if (I40E_MINIMUM_FCOE <= queues_left) {
10455 pf->num_fcoe_qps = I40E_MINIMUM_FCOE;
10456 } else {
10457 pf->num_fcoe_qps = 0;
10458 pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
10459 dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n");
10460 }
10461
10462 queues_left -= pf->num_fcoe_qps;
10463 }
10464
10465#endif
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010466 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
10467 if (queues_left > 1) {
10468 queues_left -= 1; /* save 1 queue for FD */
10469 } else {
10470 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
10471 dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
10472 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010473 }
10474
10475 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
10476 pf->num_vf_qps && pf->num_req_vfs && queues_left) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010477 pf->num_req_vfs = min_t(int, pf->num_req_vfs,
10478 (queues_left / pf->num_vf_qps));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010479 queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
10480 }
10481
10482 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
10483 pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
10484 pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
10485 (queues_left / pf->num_vmdq_qps));
10486 queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
10487 }
10488
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +000010489 pf->queues_left = queues_left;
Neerav Parikh8279e492015-09-03 17:18:50 -040010490 dev_dbg(&pf->pdev->dev,
10491 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
10492 pf->hw.func_caps.num_tx_qp,
10493 !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
Helin Zhangacd65442015-10-26 19:44:28 -040010494 pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
10495 pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
10496 queues_left);
Vasu Dev38e00432014-08-01 13:27:03 -070010497#ifdef I40E_FCOE
Neerav Parikh8279e492015-09-03 17:18:50 -040010498 dev_dbg(&pf->pdev->dev, "fcoe queues = %d\n", pf->num_fcoe_qps);
Vasu Dev38e00432014-08-01 13:27:03 -070010499#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010500}
10501
10502/**
10503 * i40e_setup_pf_filter_control - Setup PF static filter control
10504 * @pf: PF to be setup
10505 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +000010506 * i40e_setup_pf_filter_control sets up a PF's initial filter control
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010507 * settings. If PE/FCoE are enabled then it will also set the per PF
10508 * based filter sizes required for them. It also enables Flow director,
10509 * ethertype and macvlan type filter settings for the pf.
10510 *
10511 * Returns 0 on success, negative on failure
10512 **/
10513static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
10514{
10515 struct i40e_filter_control_settings *settings = &pf->filter_settings;
10516
10517 settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
10518
10519 /* Flow Director is enabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010520 if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010521 settings->enable_fdir = true;
10522
10523 /* Ethtype and MACVLAN filters enabled for PF */
10524 settings->enable_ethtype = true;
10525 settings->enable_macvlan = true;
10526
10527 if (i40e_set_filter_control(&pf->hw, settings))
10528 return -ENOENT;
10529
10530 return 0;
10531}
10532
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010533#define INFO_STRING_LEN 255
Shannon Nelson7fd89542015-10-21 19:47:04 -040010534#define REMAIN(__x) (INFO_STRING_LEN - (__x))
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010535static void i40e_print_features(struct i40e_pf *pf)
10536{
10537 struct i40e_hw *hw = &pf->hw;
Joe Perches3b195842015-12-03 04:20:57 -080010538 char *buf;
10539 int i;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010540
Joe Perches3b195842015-12-03 04:20:57 -080010541 buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
10542 if (!buf)
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010543 return;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010544
Joe Perches3b195842015-12-03 04:20:57 -080010545 i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010546#ifdef CONFIG_PCI_IOV
Joe Perches3b195842015-12-03 04:20:57 -080010547 i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010548#endif
Joe Perches3b195842015-12-03 04:20:57 -080010549 i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d RX: %s",
Shannon Nelson7fd89542015-10-21 19:47:04 -040010550 pf->hw.func_caps.num_vsis,
10551 pf->vsi[pf->lan_vsi]->num_queue_pairs,
10552 pf->flags & I40E_FLAG_RX_PS_ENABLED ? "PS" : "1BUF");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010553
10554 if (pf->flags & I40E_FLAG_RSS_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010555 i += snprintf(&buf[i], REMAIN(i), " RSS");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010556 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010557 i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +000010558 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
Joe Perches3b195842015-12-03 04:20:57 -080010559 i += snprintf(&buf[i], REMAIN(i), " FD_SB");
10560 i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +000010561 }
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010562 if (pf->flags & I40E_FLAG_DCB_CAPABLE)
Joe Perches3b195842015-12-03 04:20:57 -080010563 i += snprintf(&buf[i], REMAIN(i), " DCB");
Jesse Brandeburgce6fcb32015-08-28 17:55:59 -040010564#if IS_ENABLED(CONFIG_VXLAN)
Joe Perches3b195842015-12-03 04:20:57 -080010565 i += snprintf(&buf[i], REMAIN(i), " VxLAN");
Jesse Brandeburgce6fcb32015-08-28 17:55:59 -040010566#endif
Singhai, Anjali6a899022015-12-14 12:21:18 -080010567#if IS_ENABLED(CONFIG_GENEVE)
10568 i += snprintf(&buf[i], REMAIN(i), " Geneve");
10569#endif
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010570 if (pf->flags & I40E_FLAG_PTP)
Joe Perches3b195842015-12-03 04:20:57 -080010571 i += snprintf(&buf[i], REMAIN(i), " PTP");
Vasu Dev38e00432014-08-01 13:27:03 -070010572#ifdef I40E_FCOE
10573 if (pf->flags & I40E_FLAG_FCOE_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010574 i += snprintf(&buf[i], REMAIN(i), " FCOE");
Vasu Dev38e00432014-08-01 13:27:03 -070010575#endif
Shannon Nelson6dec1012015-09-28 14:12:30 -040010576 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010577 i += snprintf(&buf[i], REMAIN(i), " VEB");
Shannon Nelson6dec1012015-09-28 14:12:30 -040010578 else
Joe Perches3b195842015-12-03 04:20:57 -080010579 i += snprintf(&buf[i], REMAIN(i), " VEPA");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010580
Joe Perches3b195842015-12-03 04:20:57 -080010581 dev_info(&pf->pdev->dev, "%s\n", buf);
10582 kfree(buf);
Shannon Nelson7fd89542015-10-21 19:47:04 -040010583 WARN_ON(i > INFO_STRING_LEN);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010584}
10585
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010586/**
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010587 * i40e_get_platform_mac_addr - get platform-specific MAC address
10588 *
10589 * @pdev: PCI device information struct
10590 * @pf: board private structure
10591 *
10592 * Look up the MAC address in Open Firmware on systems that support it,
10593 * and use IDPROM on SPARC if no OF address is found. On return, the
10594 * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value
10595 * has been selected.
10596 **/
10597static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
10598{
10599 struct device_node *dp = pci_device_to_OF_node(pdev);
10600 const unsigned char *addr;
10601 u8 *mac_addr = pf->hw.mac.addr;
10602
10603 pf->flags &= ~I40E_FLAG_PF_MAC;
10604 addr = of_get_mac_address(dp);
10605 if (addr) {
10606 ether_addr_copy(mac_addr, addr);
10607 pf->flags |= I40E_FLAG_PF_MAC;
10608#ifdef CONFIG_SPARC
10609 } else {
10610 ether_addr_copy(mac_addr, idprom->id_ethaddr);
10611 pf->flags |= I40E_FLAG_PF_MAC;
10612#endif /* CONFIG_SPARC */
10613 }
10614}
10615
10616/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010617 * i40e_probe - Device initialization routine
10618 * @pdev: PCI device information struct
10619 * @ent: entry in i40e_pci_tbl
10620 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +000010621 * i40e_probe initializes a PF identified by a pci_dev structure.
10622 * The OS initialization, configuring of the PF private structure,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010623 * and a hardware reset occur.
10624 *
10625 * Returns 0 on success, negative on failure
10626 **/
10627static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
10628{
Catherine Sullivane8278452015-02-06 08:52:08 +000010629 struct i40e_aq_get_phy_abilities_resp abilities;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010630 struct i40e_pf *pf;
10631 struct i40e_hw *hw;
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000010632 static u16 pfs_found;
Shannon Nelson1d5109d2015-08-26 15:14:08 -040010633 u16 wol_nvm_bits;
Catherine Sullivand4dfb812013-11-28 06:39:21 +000010634 u16 link_status;
Jean Sacren6f66a482015-09-19 05:08:45 -060010635 int err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010636 u32 len;
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -040010637 u32 val;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000010638 u32 i;
Helin Zhang58fc3262015-10-01 14:37:38 -040010639 u8 set_fc_aq_fail;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010640
10641 err = pci_enable_device_mem(pdev);
10642 if (err)
10643 return err;
10644
10645 /* set up for high or low dma */
Mitch Williams64942942014-02-11 08:26:33 +000010646 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +000010647 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +000010648 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
10649 if (err) {
10650 dev_err(&pdev->dev,
10651 "DMA configuration failed: 0x%x\n", err);
10652 goto err_dma;
10653 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010654 }
10655
10656 /* set up pci connections */
10657 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
10658 IORESOURCE_MEM), i40e_driver_name);
10659 if (err) {
10660 dev_info(&pdev->dev,
10661 "pci_request_selected_regions failed %d\n", err);
10662 goto err_pci_reg;
10663 }
10664
10665 pci_enable_pcie_error_reporting(pdev);
10666 pci_set_master(pdev);
10667
10668 /* Now that we have a PCI connection, we need to do the
10669 * low level device setup. This is primarily setting up
10670 * the Admin Queue structures and then querying for the
10671 * device's current profile information.
10672 */
10673 pf = kzalloc(sizeof(*pf), GFP_KERNEL);
10674 if (!pf) {
10675 err = -ENOMEM;
10676 goto err_pf_alloc;
10677 }
10678 pf->next_vsi = 0;
10679 pf->pdev = pdev;
10680 set_bit(__I40E_DOWN, &pf->state);
10681
10682 hw = &pf->hw;
10683 hw->back = pf;
Anjali Singhai232f4702015-02-26 16:15:39 +000010684
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010685 pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
10686 I40E_MAX_CSR_SPACE);
Anjali Singhai232f4702015-02-26 16:15:39 +000010687
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010688 hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010689 if (!hw->hw_addr) {
10690 err = -EIO;
10691 dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
10692 (unsigned int)pci_resource_start(pdev, 0),
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010693 pf->ioremap_len, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010694 goto err_ioremap;
10695 }
10696 hw->vendor_id = pdev->vendor;
10697 hw->device_id = pdev->device;
10698 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
10699 hw->subsystem_vendor_id = pdev->subsystem_vendor;
10700 hw->subsystem_device_id = pdev->subsystem_device;
10701 hw->bus.device = PCI_SLOT(pdev->devfn);
10702 hw->bus.func = PCI_FUNC(pdev->devfn);
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000010703 pf->instance = pfs_found;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010704
Shannon Nelson5b5faa42014-10-17 03:14:51 +000010705 if (debug != -1) {
10706 pf->msg_enable = pf->hw.debug_mask;
10707 pf->msg_enable = debug;
10708 }
10709
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +000010710 /* do a special CORER for clearing PXE mode once at init */
10711 if (hw->revision_id == 0 &&
10712 (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
10713 wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
10714 i40e_flush(hw);
10715 msleep(200);
10716 pf->corer_count++;
10717
10718 i40e_clear_pxe_mode(hw);
10719 }
10720
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010721 /* Reset here to make sure all is clean and to define PF 'n' */
Shannon Nelson838d41d2014-06-04 20:41:27 +000010722 i40e_clear_hw(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010723 err = i40e_pf_reset(hw);
10724 if (err) {
10725 dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
10726 goto err_pf_reset;
10727 }
10728 pf->pfr_count++;
10729
10730 hw->aq.num_arq_entries = I40E_AQ_LEN;
10731 hw->aq.num_asq_entries = I40E_AQ_LEN;
10732 hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
10733 hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
10734 pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +000010735
Carolyn Wybornyb294ac72014-12-11 07:06:39 +000010736 snprintf(pf->int_name, sizeof(pf->int_name) - 1,
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +000010737 "%s-%s:misc",
10738 dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010739
10740 err = i40e_init_shared_code(hw);
10741 if (err) {
Anjali Singhai Jainb2a75c52015-04-27 14:57:20 -040010742 dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
10743 err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010744 goto err_pf_reset;
10745 }
10746
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000010747 /* set up a default setting for link flow control */
10748 pf->hw.fc.requested_mode = I40E_FC_NONE;
10749
Jesse Brandeburg8ddb3322015-11-18 15:47:06 -080010750 /* set up the locks for the AQ, do this only once in probe
10751 * and destroy them only once in remove
10752 */
10753 mutex_init(&hw->aq.asq_mutex);
10754 mutex_init(&hw->aq.arq_mutex);
10755
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010756 err = i40e_init_adminq(hw);
Carolyn Wyborny2b2426a762015-10-26 19:44:35 -040010757 if (err) {
10758 if (err == I40E_ERR_FIRMWARE_API_VERSION)
10759 dev_info(&pdev->dev,
10760 "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");
10761 else
10762 dev_info(&pdev->dev,
10763 "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
10764
10765 goto err_pf_reset;
10766 }
Carolyn Wybornyf0b44442015-08-31 19:54:49 -040010767
Shannon Nelson6dec1012015-09-28 14:12:30 -040010768 /* provide nvm, fw, api versions */
10769 dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
10770 hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
10771 hw->aq.api_maj_ver, hw->aq.api_min_ver,
10772 i40e_nvm_version_str(hw));
Carolyn Wybornyf0b44442015-08-31 19:54:49 -040010773
Catherine Sullivan7aa67612014-07-09 07:46:17 +000010774 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
10775 hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
Shannon Nelson278b6f62014-06-04 01:41:03 +000010776 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000010777 "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");
10778 else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
10779 hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
Shannon Nelson278b6f62014-06-04 01:41:03 +000010780 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000010781 "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 +000010782
Shannon Nelson4eb3f762014-03-06 08:59:58 +000010783 i40e_verify_eeprom(pf);
10784
Jesse Brandeburg2c5fe332014-04-23 04:49:57 +000010785 /* Rev 0 hardware was never productized */
10786 if (hw->revision_id < 1)
10787 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");
10788
Shannon Nelson6ff4ef82013-12-21 05:44:49 +000010789 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010790 err = i40e_get_capabilities(pf);
10791 if (err)
10792 goto err_adminq_setup;
10793
10794 err = i40e_sw_init(pf);
10795 if (err) {
10796 dev_info(&pdev->dev, "sw_init failed: %d\n", err);
10797 goto err_sw_init;
10798 }
10799
10800 err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
10801 hw->func_caps.num_rx_qp,
10802 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
10803 if (err) {
10804 dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
10805 goto err_init_lan_hmc;
10806 }
10807
10808 err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
10809 if (err) {
10810 dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
10811 err = -ENOENT;
10812 goto err_configure_lan_hmc;
10813 }
10814
Neerav Parikhb686ece2014-12-14 01:55:11 +000010815 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
10816 * Ignore error return codes because if it was already disabled via
10817 * hardware settings this will fail
10818 */
10819 if (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
10820 (pf->hw.aq.fw_maj_ver < 4)) {
10821 dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
10822 i40e_aq_stop_lldp(hw, true, NULL);
10823 }
10824
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010825 i40e_get_mac_addr(hw, hw->mac.addr);
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010826 /* allow a platform config to override the HW addr */
10827 i40e_get_platform_mac_addr(pdev, pf);
Jesse Brandeburgf62b5062013-11-28 06:39:27 +000010828 if (!is_valid_ether_addr(hw->mac.addr)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010829 dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
10830 err = -EIO;
10831 goto err_mac_addr;
10832 }
10833 dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
Greg Rose9a173902014-05-22 06:32:02 +000010834 ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
Neerav Parikh1f224ad2014-02-12 01:45:31 +000010835 i40e_get_port_mac_addr(hw, hw->mac.port_addr);
10836 if (is_valid_ether_addr(hw->mac.port_addr))
10837 pf->flags |= I40E_FLAG_PORT_ID_VALID;
Vasu Dev38e00432014-08-01 13:27:03 -070010838#ifdef I40E_FCOE
10839 err = i40e_get_san_mac_addr(hw, hw->mac.san_addr);
10840 if (err)
10841 dev_info(&pdev->dev,
10842 "(non-fatal) SAN MAC retrieval failed: %d\n", err);
10843 if (!is_valid_ether_addr(hw->mac.san_addr)) {
10844 dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
10845 hw->mac.san_addr);
10846 ether_addr_copy(hw->mac.san_addr, hw->mac.addr);
10847 }
10848 dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr);
10849#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010850
10851 pci_set_drvdata(pdev, pf);
10852 pci_save_state(pdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080010853#ifdef CONFIG_I40E_DCB
10854 err = i40e_init_pf_dcb(pf);
10855 if (err) {
Shannon Nelsonaebfc812014-12-11 07:06:38 +000010856 dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010857 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
Neerav Parikh014269f2014-04-01 07:11:48 +000010858 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080010859 }
10860#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010861
10862 /* set up periodic task facility */
10863 setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
10864 pf->service_timer_period = HZ;
10865
10866 INIT_WORK(&pf->service_task, i40e_service_task);
10867 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
10868 pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010869
Shannon Nelson1d5109d2015-08-26 15:14:08 -040010870 /* NVM bit on means WoL disabled for the port */
10871 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -080010872 if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
Shannon Nelson1d5109d2015-08-26 15:14:08 -040010873 pf->wol_en = false;
10874 else
10875 pf->wol_en = true;
Shannon Nelson8e2773a2013-11-28 06:39:22 +000010876 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
10877
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010878 /* set up the main switch operations */
10879 i40e_determine_queue_usage(pf);
Jesse Brandeburgc11472802015-04-07 19:45:39 -040010880 err = i40e_init_interrupt_scheme(pf);
10881 if (err)
10882 goto err_switch_setup;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010883
Mitch Williams505682c2014-05-20 08:01:37 +000010884 /* The number of VSIs reported by the FW is the minimum guaranteed
10885 * to us; HW supports far more and we share the remaining pool with
10886 * the other PFs. We allocate space for more than the guarantee with
10887 * the understanding that we might not get them all later.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010888 */
Mitch Williams505682c2014-05-20 08:01:37 +000010889 if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
10890 pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
10891 else
10892 pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
10893
10894 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
10895 len = sizeof(struct i40e_vsi *) * pf->num_alloc_vsi;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010896 pf->vsi = kzalloc(len, GFP_KERNEL);
Wei Yongjuned87ac02013-09-24 05:17:25 +000010897 if (!pf->vsi) {
10898 err = -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010899 goto err_switch_setup;
Wei Yongjuned87ac02013-09-24 05:17:25 +000010900 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010901
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -040010902#ifdef CONFIG_PCI_IOV
10903 /* prep for VF support */
10904 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
10905 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
10906 !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
10907 if (pci_num_vf(pdev))
10908 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
10909 }
10910#endif
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010911 err = i40e_setup_pf_switch(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010912 if (err) {
10913 dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
10914 goto err_vsis;
10915 }
Helin Zhang58fc3262015-10-01 14:37:38 -040010916
10917 /* Make sure flow control is set according to current settings */
10918 err = i40e_set_fc(hw, &set_fc_aq_fail, true);
10919 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
10920 dev_dbg(&pf->pdev->dev,
10921 "Set fc with err %s aq_err %s on get_phy_cap\n",
10922 i40e_stat_str(hw, err),
10923 i40e_aq_str(hw, hw->aq.asq_last_status));
10924 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
10925 dev_dbg(&pf->pdev->dev,
10926 "Set fc with err %s aq_err %s on set_phy_config\n",
10927 i40e_stat_str(hw, err),
10928 i40e_aq_str(hw, hw->aq.asq_last_status));
10929 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
10930 dev_dbg(&pf->pdev->dev,
10931 "Set fc with err %s aq_err %s on get_link_info\n",
10932 i40e_stat_str(hw, err),
10933 i40e_aq_str(hw, hw->aq.asq_last_status));
10934
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000010935 /* if FDIR VSI was set up, start it now */
Mitch Williams505682c2014-05-20 08:01:37 +000010936 for (i = 0; i < pf->num_alloc_vsi; i++) {
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000010937 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
10938 i40e_vsi_open(pf->vsi[i]);
10939 break;
10940 }
10941 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010942
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000010943 /* driver is only interested in link up/down and module qualification
10944 * reports from firmware
10945 */
10946 err = i40e_aq_set_phy_int_mask(&pf->hw,
10947 I40E_AQ_EVENT_LINK_UPDOWN |
10948 I40E_AQ_EVENT_MODULE_QUAL_FAIL, NULL);
10949 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010950 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
10951 i40e_stat_str(&pf->hw, err),
10952 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000010953
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -040010954 /* Reconfigure hardware for allowing smaller MSS in the case
10955 * of TSO, so that we avoid the MDD being fired and causing
10956 * a reset in the case of small MSS+TSO.
10957 */
10958 val = rd32(hw, I40E_REG_MSS);
10959 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
10960 val &= ~I40E_REG_MSS_MIN_MASK;
10961 val |= I40E_64BYTE_MSS;
10962 wr32(hw, I40E_REG_MSS, val);
10963 }
10964
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -080010965 if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +000010966 msleep(75);
10967 err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
10968 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010969 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
10970 i40e_stat_str(&pf->hw, err),
10971 i40e_aq_str(&pf->hw,
10972 pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +000010973 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010974 /* The main driver is (mostly) up and happy. We need to set this state
10975 * before setting up the misc vector or we get a race and the vector
10976 * ends up disabled forever.
10977 */
10978 clear_bit(__I40E_DOWN, &pf->state);
10979
10980 /* In case of MSIX we are going to setup the misc vector right here
10981 * to handle admin queue events etc. In case of legacy and MSI
10982 * the misc functionality and queue processing is combined in
10983 * the same vector and that gets setup at open.
10984 */
10985 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
10986 err = i40e_setup_misc_vector(pf);
10987 if (err) {
10988 dev_info(&pdev->dev,
10989 "setup of misc vector failed: %d\n", err);
10990 goto err_vsis;
10991 }
10992 }
10993
Greg Rosedf805f62014-04-04 04:43:16 +000010994#ifdef CONFIG_PCI_IOV
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010995 /* prep for VF support */
10996 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
Shannon Nelson4eb3f762014-03-06 08:59:58 +000010997 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
10998 !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010999 u32 val;
11000
11001 /* disable link interrupts for VFs */
11002 val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
11003 val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
11004 wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
11005 i40e_flush(hw);
Mitch Williams4aeec012014-02-13 03:48:47 -080011006
11007 if (pci_num_vf(pdev)) {
11008 dev_info(&pdev->dev,
11009 "Active VFs found, allocating resources.\n");
11010 err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
11011 if (err)
11012 dev_info(&pdev->dev,
11013 "Error %d allocating resources for existing VFs\n",
11014 err);
11015 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011016 }
Greg Rosedf805f62014-04-04 04:43:16 +000011017#endif /* CONFIG_PCI_IOV */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011018
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000011019 pfs_found++;
11020
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011021 i40e_dbg_pf_init(pf);
11022
11023 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +000011024 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011025
11026 /* since everything's happy, start the service_task timer */
11027 mod_timer(&pf->service_timer,
11028 round_jiffies(jiffies + pf->service_timer_period));
11029
Vasu Dev38e00432014-08-01 13:27:03 -070011030#ifdef I40E_FCOE
11031 /* create FCoE interface */
11032 i40e_fcoe_vsi_setup(pf);
11033
11034#endif
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011035#define PCI_SPEED_SIZE 8
11036#define PCI_WIDTH_SIZE 8
11037 /* Devices on the IOSF bus do not have this information
11038 * and will report PCI Gen 1 x 1 by default so don't bother
11039 * checking them.
11040 */
11041 if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) {
11042 char speed[PCI_SPEED_SIZE] = "Unknown";
11043 char width[PCI_WIDTH_SIZE] = "Unknown";
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011044
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011045 /* Get the negotiated link width and speed from PCI config
11046 * space
11047 */
11048 pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
11049 &link_status);
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011050
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011051 i40e_set_pci_config_data(hw, link_status);
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011052
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011053 switch (hw->bus.speed) {
11054 case i40e_bus_speed_8000:
11055 strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
11056 case i40e_bus_speed_5000:
11057 strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
11058 case i40e_bus_speed_2500:
11059 strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
11060 default:
11061 break;
11062 }
11063 switch (hw->bus.width) {
11064 case i40e_bus_width_pcie_x8:
11065 strncpy(width, "8", PCI_WIDTH_SIZE); break;
11066 case i40e_bus_width_pcie_x4:
11067 strncpy(width, "4", PCI_WIDTH_SIZE); break;
11068 case i40e_bus_width_pcie_x2:
11069 strncpy(width, "2", PCI_WIDTH_SIZE); break;
11070 case i40e_bus_width_pcie_x1:
11071 strncpy(width, "1", PCI_WIDTH_SIZE); break;
11072 default:
11073 break;
11074 }
11075
11076 dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
11077 speed, width);
11078
11079 if (hw->bus.width < i40e_bus_width_pcie_x8 ||
11080 hw->bus.speed < i40e_bus_speed_8000) {
11081 dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
11082 dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
11083 }
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011084 }
11085
Catherine Sullivane8278452015-02-06 08:52:08 +000011086 /* get the requested speeds from the fw */
11087 err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
11088 if (err)
Neerav Parikh8279e492015-09-03 17:18:50 -040011089 dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
11090 i40e_stat_str(&pf->hw, err),
11091 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Catherine Sullivane8278452015-02-06 08:52:08 +000011092 pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
11093
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -040011094 /* get the supported phy types from the fw */
11095 err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
11096 if (err)
11097 dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
11098 i40e_stat_str(&pf->hw, err),
11099 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
11100 pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type);
11101
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -040011102 /* Add a filter to drop all Flow control frames from any VSI from being
11103 * transmitted. By doing so we stop a malicious VF from sending out
11104 * PAUSE or PFC frames and potentially controlling traffic for other
11105 * PF/VF VSIs.
11106 * The FW can still send Flow control frames if enabled.
11107 */
11108 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
11109 pf->main_vsi_seid);
11110
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011111 /* print a string summarizing features */
11112 i40e_print_features(pf);
11113
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011114 return 0;
11115
11116 /* Unwind what we've done if something failed in the setup */
11117err_vsis:
11118 set_bit(__I40E_DOWN, &pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011119 i40e_clear_interrupt_scheme(pf);
11120 kfree(pf->vsi);
Shannon Nelson04b03012013-11-28 06:39:34 +000011121err_switch_setup:
11122 i40e_reset_interrupt_capability(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011123 del_timer_sync(&pf->service_timer);
11124err_mac_addr:
11125err_configure_lan_hmc:
11126 (void)i40e_shutdown_lan_hmc(hw);
11127err_init_lan_hmc:
11128 kfree(pf->qp_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011129err_sw_init:
11130err_adminq_setup:
11131 (void)i40e_shutdown_adminq(hw);
11132err_pf_reset:
11133 iounmap(hw->hw_addr);
11134err_ioremap:
11135 kfree(pf);
11136err_pf_alloc:
11137 pci_disable_pcie_error_reporting(pdev);
11138 pci_release_selected_regions(pdev,
11139 pci_select_bars(pdev, IORESOURCE_MEM));
11140err_pci_reg:
11141err_dma:
11142 pci_disable_device(pdev);
11143 return err;
11144}
11145
11146/**
11147 * i40e_remove - Device removal routine
11148 * @pdev: PCI device information struct
11149 *
11150 * i40e_remove is called by the PCI subsystem to alert the driver
11151 * that is should release a PCI device. This could be caused by a
11152 * Hot-Plug event, or because the driver is going to be removed from
11153 * memory.
11154 **/
11155static void i40e_remove(struct pci_dev *pdev)
11156{
11157 struct i40e_pf *pf = pci_get_drvdata(pdev);
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011158 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011159 i40e_status ret_code;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011160 int i;
11161
11162 i40e_dbg_pf_exit(pf);
11163
Jacob Kellerbeb0dff2014-01-11 05:43:19 +000011164 i40e_ptp_stop(pf);
11165
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011166 /* Disable RSS in hw */
11167 wr32(hw, I40E_PFQF_HENA(0), 0);
11168 wr32(hw, I40E_PFQF_HENA(1), 0);
11169
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011170 /* no more scheduling of any task */
11171 set_bit(__I40E_DOWN, &pf->state);
11172 del_timer_sync(&pf->service_timer);
11173 cancel_work_sync(&pf->service_task);
11174
Mitch Williamseb2d80b2014-02-13 03:48:48 -080011175 if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
11176 i40e_free_vfs(pf);
11177 pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
11178 }
11179
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011180 i40e_fdir_teardown(pf);
11181
11182 /* If there is a switch structure or any orphans, remove them.
11183 * This will leave only the PF's VSI remaining.
11184 */
11185 for (i = 0; i < I40E_MAX_VEB; i++) {
11186 if (!pf->veb[i])
11187 continue;
11188
11189 if (pf->veb[i]->uplink_seid == pf->mac_seid ||
11190 pf->veb[i]->uplink_seid == 0)
11191 i40e_switch_branch_release(pf->veb[i]);
11192 }
11193
11194 /* Now we can shutdown the PF's VSI, just before we kill
11195 * adminq and hmc.
11196 */
11197 if (pf->vsi[pf->lan_vsi])
11198 i40e_vsi_release(pf->vsi[pf->lan_vsi]);
11199
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011200 /* shutdown and destroy the HMC */
Shannon Nelson60442de2014-04-23 04:50:13 +000011201 if (pf->hw.hmc.hmc_obj) {
11202 ret_code = i40e_shutdown_lan_hmc(&pf->hw);
11203 if (ret_code)
11204 dev_warn(&pdev->dev,
11205 "Failed to destroy the HMC resources: %d\n",
11206 ret_code);
11207 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011208
11209 /* shutdown the adminq */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011210 ret_code = i40e_shutdown_adminq(&pf->hw);
11211 if (ret_code)
11212 dev_warn(&pdev->dev,
11213 "Failed to destroy the Admin Queue resources: %d\n",
11214 ret_code);
11215
Jesse Brandeburg8ddb3322015-11-18 15:47:06 -080011216 /* destroy the locks only once, here */
11217 mutex_destroy(&hw->aq.arq_mutex);
11218 mutex_destroy(&hw->aq.asq_mutex);
11219
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011220 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
11221 i40e_clear_interrupt_scheme(pf);
Mitch Williams505682c2014-05-20 08:01:37 +000011222 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011223 if (pf->vsi[i]) {
11224 i40e_vsi_clear_rings(pf->vsi[i]);
11225 i40e_vsi_clear(pf->vsi[i]);
11226 pf->vsi[i] = NULL;
11227 }
11228 }
11229
11230 for (i = 0; i < I40E_MAX_VEB; i++) {
11231 kfree(pf->veb[i]);
11232 pf->veb[i] = NULL;
11233 }
11234
11235 kfree(pf->qp_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011236 kfree(pf->vsi);
11237
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011238 iounmap(pf->hw.hw_addr);
11239 kfree(pf);
11240 pci_release_selected_regions(pdev,
11241 pci_select_bars(pdev, IORESOURCE_MEM));
11242
11243 pci_disable_pcie_error_reporting(pdev);
11244 pci_disable_device(pdev);
11245}
11246
11247/**
11248 * i40e_pci_error_detected - warning that something funky happened in PCI land
11249 * @pdev: PCI device information struct
11250 *
11251 * Called to warn that something happened and the error handling steps
11252 * are in progress. Allows the driver to quiesce things, be ready for
11253 * remediation.
11254 **/
11255static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
11256 enum pci_channel_state error)
11257{
11258 struct i40e_pf *pf = pci_get_drvdata(pdev);
11259
11260 dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
11261
11262 /* shutdown all operations */
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011263 if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
11264 rtnl_lock();
11265 i40e_prep_for_reset(pf);
11266 rtnl_unlock();
11267 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011268
11269 /* Request a slot reset */
11270 return PCI_ERS_RESULT_NEED_RESET;
11271}
11272
11273/**
11274 * i40e_pci_error_slot_reset - a PCI slot reset just happened
11275 * @pdev: PCI device information struct
11276 *
11277 * Called to find if the driver can work with the device now that
11278 * the pci slot has been reset. If a basic connection seems good
11279 * (registers are readable and have sane content) then return a
11280 * happy little PCI_ERS_RESULT_xxx.
11281 **/
11282static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
11283{
11284 struct i40e_pf *pf = pci_get_drvdata(pdev);
11285 pci_ers_result_t result;
11286 int err;
11287 u32 reg;
11288
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011289 dev_dbg(&pdev->dev, "%s\n", __func__);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011290 if (pci_enable_device_mem(pdev)) {
11291 dev_info(&pdev->dev,
11292 "Cannot re-enable PCI device after reset.\n");
11293 result = PCI_ERS_RESULT_DISCONNECT;
11294 } else {
11295 pci_set_master(pdev);
11296 pci_restore_state(pdev);
11297 pci_save_state(pdev);
11298 pci_wake_from_d3(pdev, false);
11299
11300 reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
11301 if (reg == 0)
11302 result = PCI_ERS_RESULT_RECOVERED;
11303 else
11304 result = PCI_ERS_RESULT_DISCONNECT;
11305 }
11306
11307 err = pci_cleanup_aer_uncorrect_error_status(pdev);
11308 if (err) {
11309 dev_info(&pdev->dev,
11310 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
11311 err);
11312 /* non-fatal, continue */
11313 }
11314
11315 return result;
11316}
11317
11318/**
11319 * i40e_pci_error_resume - restart operations after PCI error recovery
11320 * @pdev: PCI device information struct
11321 *
11322 * Called to allow the driver to bring things back up after PCI error
11323 * and/or reset recovery has finished.
11324 **/
11325static void i40e_pci_error_resume(struct pci_dev *pdev)
11326{
11327 struct i40e_pf *pf = pci_get_drvdata(pdev);
11328
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011329 dev_dbg(&pdev->dev, "%s\n", __func__);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011330 if (test_bit(__I40E_SUSPENDED, &pf->state))
11331 return;
11332
11333 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011334 i40e_handle_reset_warning(pf);
Vasily Averin4c4935a2015-07-08 15:04:26 +030011335 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011336}
11337
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011338/**
11339 * i40e_shutdown - PCI callback for shutting down
11340 * @pdev: PCI device information struct
11341 **/
11342static void i40e_shutdown(struct pci_dev *pdev)
11343{
11344 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011345 struct i40e_hw *hw = &pf->hw;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011346
11347 set_bit(__I40E_SUSPENDED, &pf->state);
11348 set_bit(__I40E_DOWN, &pf->state);
11349 rtnl_lock();
11350 i40e_prep_for_reset(pf);
11351 rtnl_unlock();
11352
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011353 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11354 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11355
Catherine Sullivan02b42492015-07-10 19:35:59 -040011356 del_timer_sync(&pf->service_timer);
11357 cancel_work_sync(&pf->service_task);
11358 i40e_fdir_teardown(pf);
11359
11360 rtnl_lock();
11361 i40e_prep_for_reset(pf);
11362 rtnl_unlock();
11363
11364 wr32(hw, I40E_PFPM_APM,
11365 (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11366 wr32(hw, I40E_PFPM_WUFC,
11367 (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11368
Shannon Nelsone1477582015-02-21 06:44:33 +000011369 i40e_clear_interrupt_scheme(pf);
11370
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011371 if (system_state == SYSTEM_POWER_OFF) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011372 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011373 pci_set_power_state(pdev, PCI_D3hot);
11374 }
11375}
11376
11377#ifdef CONFIG_PM
11378/**
11379 * i40e_suspend - PCI callback for moving to D3
11380 * @pdev: PCI device information struct
11381 **/
11382static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
11383{
11384 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011385 struct i40e_hw *hw = &pf->hw;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011386
11387 set_bit(__I40E_SUSPENDED, &pf->state);
11388 set_bit(__I40E_DOWN, &pf->state);
Mitch Williams3932dbf2015-03-31 00:45:04 -070011389
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011390 rtnl_lock();
11391 i40e_prep_for_reset(pf);
11392 rtnl_unlock();
11393
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011394 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11395 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11396
11397 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011398 pci_set_power_state(pdev, PCI_D3hot);
11399
11400 return 0;
11401}
11402
11403/**
11404 * i40e_resume - PCI callback for waking up from D3
11405 * @pdev: PCI device information struct
11406 **/
11407static int i40e_resume(struct pci_dev *pdev)
11408{
11409 struct i40e_pf *pf = pci_get_drvdata(pdev);
11410 u32 err;
11411
11412 pci_set_power_state(pdev, PCI_D0);
11413 pci_restore_state(pdev);
11414 /* pci_restore_state() clears dev->state_saves, so
11415 * call pci_save_state() again to restore it.
11416 */
11417 pci_save_state(pdev);
11418
11419 err = pci_enable_device_mem(pdev);
11420 if (err) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011421 dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011422 return err;
11423 }
11424 pci_set_master(pdev);
11425
11426 /* no wakeup events while running */
11427 pci_wake_from_d3(pdev, false);
11428
11429 /* handling the reset will rebuild the device state */
11430 if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
11431 clear_bit(__I40E_DOWN, &pf->state);
11432 rtnl_lock();
11433 i40e_reset_and_rebuild(pf, false);
11434 rtnl_unlock();
11435 }
11436
11437 return 0;
11438}
11439
11440#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011441static const struct pci_error_handlers i40e_err_handler = {
11442 .error_detected = i40e_pci_error_detected,
11443 .slot_reset = i40e_pci_error_slot_reset,
11444 .resume = i40e_pci_error_resume,
11445};
11446
11447static struct pci_driver i40e_driver = {
11448 .name = i40e_driver_name,
11449 .id_table = i40e_pci_tbl,
11450 .probe = i40e_probe,
11451 .remove = i40e_remove,
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011452#ifdef CONFIG_PM
11453 .suspend = i40e_suspend,
11454 .resume = i40e_resume,
11455#endif
11456 .shutdown = i40e_shutdown,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011457 .err_handler = &i40e_err_handler,
11458 .sriov_configure = i40e_pci_sriov_configure,
11459};
11460
11461/**
11462 * i40e_init_module - Driver registration routine
11463 *
11464 * i40e_init_module is the first routine called when the driver is
11465 * loaded. All it does is register with the PCI subsystem.
11466 **/
11467static int __init i40e_init_module(void)
11468{
11469 pr_info("%s: %s - version %s\n", i40e_driver_name,
11470 i40e_driver_string, i40e_driver_version_str);
11471 pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
Greg Rose96664482015-02-06 08:52:13 +000011472
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011473 i40e_dbg_init();
11474 return pci_register_driver(&i40e_driver);
11475}
11476module_init(i40e_init_module);
11477
11478/**
11479 * i40e_exit_module - Driver exit cleanup routine
11480 *
11481 * i40e_exit_module is called just before the driver is removed
11482 * from memory.
11483 **/
11484static void __exit i40e_exit_module(void)
11485{
11486 pci_unregister_driver(&i40e_driver);
11487 i40e_dbg_exit();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011488}
11489module_exit(i40e_exit_module);