blob: f7fe020e5e2a323a0fd2e82a3be1602540fd4eb0 [file] [log] [blame]
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Jesse Brandeburg2818ccd2016-01-13 16:51:38 -08004 * Copyright(c) 2013 - 2016 Intel Corporation.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050027#include <linux/etherdevice.h>
28#include <linux/of_net.h>
29#include <linux/pci.h>
30
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000031/* Local includes */
32#include "i40e.h"
Shannon Nelson4eb3f762014-03-06 08:59:58 +000033#include "i40e_diag.h"
Alexander Duyck06a5f7f2016-06-16 12:22:06 -070034#include <net/udp_tunnel.h>
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000035
36const char i40e_driver_name[] = "i40e";
37static const char i40e_driver_string[] =
38 "Intel(R) Ethernet Connection XL710 Network Driver";
39
40#define DRV_KERN "-k"
41
Catherine Sullivane8e724d2014-07-10 07:58:26 +000042#define DRV_VERSION_MAJOR 1
Bimmy Pujari07061952016-05-16 10:26:45 -070043#define DRV_VERSION_MINOR 6
Bimmy Pujaricf465fe2016-09-27 11:28:54 -070044#define DRV_VERSION_BUILD 21
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000045#define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
46 __stringify(DRV_VERSION_MINOR) "." \
47 __stringify(DRV_VERSION_BUILD) DRV_KERN
48const char i40e_driver_version_str[] = DRV_VERSION;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -080049static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000050
51/* a bit of forward declarations */
52static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
53static void i40e_handle_reset_warning(struct i40e_pf *pf);
54static int i40e_add_vsi(struct i40e_vsi *vsi);
55static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000056static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000057static int i40e_setup_misc_vector(struct i40e_pf *pf);
58static void i40e_determine_queue_usage(struct i40e_pf *pf);
59static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080060static void i40e_fdir_sb_setup(struct i40e_pf *pf);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080061static int i40e_veb_get_bw_info(struct i40e_veb *veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000062
63/* i40e_pci_tbl - PCI Device ID Table
64 *
65 * Last entry must be all 0s
66 *
67 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
68 * Class, Class Mask, private data (not used) }
69 */
Benoit Taine9baa3c32014-08-08 15:56:03 +020070static const struct pci_device_id i40e_pci_tbl[] = {
Shannon Nelsonab600852014-01-17 15:36:39 -080071 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080072 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080073 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
74 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080075 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
76 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
77 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
Mitch Williams5960d332014-09-13 07:40:47 +000078 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
Shannon Nelsonbc5166b92015-08-26 15:14:10 -040079 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
Jesse Brandeburgae24b402015-03-27 00:12:09 -070080 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
Anjali Singhai Jain35dae512015-12-22 14:25:03 -080081 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0},
82 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0},
Anjali Singhai Jain87e6c1d2015-06-05 12:20:25 -040083 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
84 {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
85 {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
Catherine Sullivand6bf58c2016-03-18 12:18:08 -070086 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0},
Shannon Nelson48a3b512015-07-23 16:54:39 -040087 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
88 {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000089 /* required last entry */
90 {0, }
91};
92MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
93
94#define I40E_MAX_VF_COUNT 128
95static int debug = -1;
Alexander Duyck5d4ca232016-09-30 08:21:46 -040096module_param(debug, uint, 0);
97MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000098
99MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
100MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
101MODULE_LICENSE("GPL");
102MODULE_VERSION(DRV_VERSION);
103
Jesse Brandeburg2803b162015-12-22 14:25:08 -0800104static struct workqueue_struct *i40e_wq;
105
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000106/**
107 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
108 * @hw: pointer to the HW structure
109 * @mem: ptr to mem struct to fill out
110 * @size: size of memory requested
111 * @alignment: what to align the allocation to
112 **/
113int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
114 u64 size, u32 alignment)
115{
116 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
117
118 mem->size = ALIGN(size, alignment);
119 mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
120 &mem->pa, GFP_KERNEL);
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000121 if (!mem->va)
122 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000123
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000124 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000125}
126
127/**
128 * i40e_free_dma_mem_d - OS specific memory free for shared code
129 * @hw: pointer to the HW structure
130 * @mem: ptr to mem struct to free
131 **/
132int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
133{
134 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
135
136 dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
137 mem->va = NULL;
138 mem->pa = 0;
139 mem->size = 0;
140
141 return 0;
142}
143
144/**
145 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
146 * @hw: pointer to the HW structure
147 * @mem: ptr to mem struct to fill out
148 * @size: size of memory requested
149 **/
150int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
151 u32 size)
152{
153 mem->size = size;
154 mem->va = kzalloc(size, GFP_KERNEL);
155
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000156 if (!mem->va)
157 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000158
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000159 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000160}
161
162/**
163 * i40e_free_virt_mem_d - OS specific memory free for shared code
164 * @hw: pointer to the HW structure
165 * @mem: ptr to mem struct to free
166 **/
167int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
168{
169 /* it's ok to kfree a NULL pointer */
170 kfree(mem->va);
171 mem->va = NULL;
172 mem->size = 0;
173
174 return 0;
175}
176
177/**
178 * i40e_get_lump - find a lump of free generic resource
179 * @pf: board private structure
180 * @pile: the pile of resource to search
181 * @needed: the number of items needed
182 * @id: an owner id to stick on the items assigned
183 *
184 * Returns the base item index of the lump, or negative for error
185 *
186 * The search_hint trick and lack of advanced fit-finding only work
187 * because we're highly likely to have all the same size lump requests.
188 * Linear search time and any fragmentation should be minimal.
189 **/
190static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
191 u16 needed, u16 id)
192{
193 int ret = -ENOMEM;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000194 int i, j;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000195
196 if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
197 dev_info(&pf->pdev->dev,
198 "param err: pile=%p needed=%d id=0x%04x\n",
199 pile, needed, id);
200 return -EINVAL;
201 }
202
203 /* start the linear search with an imperfect hint */
204 i = pile->search_hint;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000205 while (i < pile->num_entries) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000206 /* skip already allocated entries */
207 if (pile->list[i] & I40E_PILE_VALID_BIT) {
208 i++;
209 continue;
210 }
211
212 /* do we have enough in this lump? */
213 for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
214 if (pile->list[i+j] & I40E_PILE_VALID_BIT)
215 break;
216 }
217
218 if (j == needed) {
219 /* there was enough, so assign it to the requestor */
220 for (j = 0; j < needed; j++)
221 pile->list[i+j] = id | I40E_PILE_VALID_BIT;
222 ret = i;
223 pile->search_hint = i + j;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000224 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000225 }
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400226
227 /* not enough, so skip over it and continue looking */
228 i += j;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000229 }
230
231 return ret;
232}
233
234/**
235 * i40e_put_lump - return a lump of generic resource
236 * @pile: the pile of resource to search
237 * @index: the base item index
238 * @id: the owner id of the items assigned
239 *
240 * Returns the count of items in the lump
241 **/
242static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
243{
244 int valid_id = (id | I40E_PILE_VALID_BIT);
245 int count = 0;
246 int i;
247
248 if (!pile || index >= pile->num_entries)
249 return -EINVAL;
250
251 for (i = index;
252 i < pile->num_entries && pile->list[i] == valid_id;
253 i++) {
254 pile->list[i] = 0;
255 count++;
256 }
257
258 if (count && index < pile->search_hint)
259 pile->search_hint = index;
260
261 return count;
262}
263
264/**
Anjali Singhai Jainfdf0e0b2015-03-31 00:45:05 -0700265 * i40e_find_vsi_from_id - searches for the vsi with the given id
266 * @pf - the pf structure to search for the vsi
267 * @id - id of the vsi it is searching for
268 **/
269struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
270{
271 int i;
272
273 for (i = 0; i < pf->num_alloc_vsi; i++)
274 if (pf->vsi[i] && (pf->vsi[i]->id == id))
275 return pf->vsi[i];
276
277 return NULL;
278}
279
280/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000281 * i40e_service_event_schedule - Schedule the service task to wake up
282 * @pf: board private structure
283 *
284 * If not already scheduled, this puts the task into the work queue
285 **/
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -0600286void i40e_service_event_schedule(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000287{
288 if (!test_bit(__I40E_DOWN, &pf->state) &&
289 !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) &&
290 !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
Jesse Brandeburg2803b162015-12-22 14:25:08 -0800291 queue_work(i40e_wq, &pf->service_task);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000292}
293
294/**
295 * i40e_tx_timeout - Respond to a Tx Hang
296 * @netdev: network interface device structure
297 *
298 * If any port has noticed a Tx timeout, it is likely that the whole
299 * device is munged, not just the one netdev port, so go for the full
300 * reset.
301 **/
Vasu Dev38e00432014-08-01 13:27:03 -0700302#ifdef I40E_FCOE
303void i40e_tx_timeout(struct net_device *netdev)
304#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000305static void i40e_tx_timeout(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -0700306#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000307{
308 struct i40e_netdev_priv *np = netdev_priv(netdev);
309 struct i40e_vsi *vsi = np->vsi;
310 struct i40e_pf *pf = vsi->back;
Kiran Patilb03a8c12015-09-24 18:13:15 -0400311 struct i40e_ring *tx_ring = NULL;
312 unsigned int i, hung_queue = 0;
313 u32 head, val;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000314
315 pf->tx_timeout_count++;
316
Kiran Patilb03a8c12015-09-24 18:13:15 -0400317 /* find the stopped queue the same way the stack does */
318 for (i = 0; i < netdev->num_tx_queues; i++) {
319 struct netdev_queue *q;
320 unsigned long trans_start;
321
322 q = netdev_get_tx_queue(netdev, i);
Florian Westphal9b366272016-05-03 16:33:14 +0200323 trans_start = q->trans_start;
Kiran Patilb03a8c12015-09-24 18:13:15 -0400324 if (netif_xmit_stopped(q) &&
325 time_after(jiffies,
326 (trans_start + netdev->watchdog_timeo))) {
327 hung_queue = i;
328 break;
329 }
330 }
331
332 if (i == netdev->num_tx_queues) {
333 netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
334 } else {
335 /* now that we have an index, find the tx_ring struct */
336 for (i = 0; i < vsi->num_queue_pairs; i++) {
337 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
338 if (hung_queue ==
339 vsi->tx_rings[i]->queue_index) {
340 tx_ring = vsi->tx_rings[i];
341 break;
342 }
343 }
344 }
345 }
346
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000347 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
Kiran Patilb03a8c12015-09-24 18:13:15 -0400348 pf->tx_timeout_recovery_level = 1; /* reset after some time */
349 else if (time_before(jiffies,
350 (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
351 return; /* don't do any new action before the next timeout */
352
353 if (tx_ring) {
354 head = i40e_get_head(tx_ring);
355 /* Read interrupt register */
356 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
357 val = rd32(&pf->hw,
358 I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
359 tx_ring->vsi->base_vector - 1));
360 else
361 val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
362
363 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",
364 vsi->seid, hung_queue, tx_ring->next_to_clean,
365 head, tx_ring->next_to_use,
366 readl(tx_ring->tail), val);
367 }
368
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000369 pf->tx_timeout_last_recovery = jiffies;
Kiran Patilb03a8c12015-09-24 18:13:15 -0400370 netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
371 pf->tx_timeout_recovery_level, hung_queue);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000372
373 switch (pf->tx_timeout_recovery_level) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000374 case 1:
375 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
376 break;
377 case 2:
378 set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
379 break;
380 case 3:
381 set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
382 break;
383 default:
384 netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000385 break;
386 }
Kiran Patilb03a8c12015-09-24 18:13:15 -0400387
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000388 i40e_service_event_schedule(pf);
389 pf->tx_timeout_recovery_level++;
390}
391
392/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000393 * i40e_get_vsi_stats_struct - Get System Network Statistics
394 * @vsi: the VSI we care about
395 *
396 * Returns the address of the device statistics structure.
397 * The statistics are actually updated from the service task.
398 **/
399struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
400{
401 return &vsi->net_stats;
402}
403
404/**
405 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
406 * @netdev: network interface device structure
407 *
408 * Returns the address of the device statistics structure.
409 * The statistics are actually updated from the service task.
410 **/
Vasu Dev38e00432014-08-01 13:27:03 -0700411#ifdef I40E_FCOE
412struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
413 struct net_device *netdev,
414 struct rtnl_link_stats64 *stats)
415#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000416static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
417 struct net_device *netdev,
Alexander Duyck980e9b12013-09-28 06:01:03 +0000418 struct rtnl_link_stats64 *stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700419#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000420{
421 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000422 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000423 struct i40e_vsi *vsi = np->vsi;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000424 struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
425 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000426
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +0000427 if (test_bit(__I40E_DOWN, &vsi->state))
428 return stats;
429
Jesse Brandeburg3c325ce2013-12-14 03:26:45 -0800430 if (!vsi->tx_rings)
431 return stats;
432
Alexander Duyck980e9b12013-09-28 06:01:03 +0000433 rcu_read_lock();
434 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000435 u64 bytes, packets;
436 unsigned int start;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000437
Alexander Duyck980e9b12013-09-28 06:01:03 +0000438 tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
439 if (!tx_ring)
440 continue;
441
442 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700443 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000444 packets = tx_ring->stats.packets;
445 bytes = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700446 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000447
448 stats->tx_packets += packets;
449 stats->tx_bytes += bytes;
450 rx_ring = &tx_ring[1];
451
452 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700453 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000454 packets = rx_ring->stats.packets;
455 bytes = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700456 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000457
458 stats->rx_packets += packets;
459 stats->rx_bytes += bytes;
460 }
461 rcu_read_unlock();
462
Akeem G Abodunrina5282f42014-05-10 04:49:03 +0000463 /* following stats updated by i40e_watchdog_subtask() */
Alexander Duyck980e9b12013-09-28 06:01:03 +0000464 stats->multicast = vsi_stats->multicast;
465 stats->tx_errors = vsi_stats->tx_errors;
466 stats->tx_dropped = vsi_stats->tx_dropped;
467 stats->rx_errors = vsi_stats->rx_errors;
Jesse Brandeburgd8201e22015-07-23 16:54:35 -0400468 stats->rx_dropped = vsi_stats->rx_dropped;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000469 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
470 stats->rx_length_errors = vsi_stats->rx_length_errors;
471
472 return stats;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000473}
474
475/**
476 * i40e_vsi_reset_stats - Resets all stats of the given vsi
477 * @vsi: the VSI to have its stats reset
478 **/
479void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
480{
481 struct rtnl_link_stats64 *ns;
482 int i;
483
484 if (!vsi)
485 return;
486
487 ns = i40e_get_vsi_stats_struct(vsi);
488 memset(ns, 0, sizeof(*ns));
489 memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
490 memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
491 memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
Greg Rose8e9dca52013-12-18 13:45:53 +0000492 if (vsi->rx_rings && vsi->rx_rings[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000493 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400494 memset(&vsi->rx_rings[i]->stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000495 sizeof(vsi->rx_rings[i]->stats));
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400496 memset(&vsi->rx_rings[i]->rx_stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000497 sizeof(vsi->rx_rings[i]->rx_stats));
Jesse Brandeburg6995b362015-08-28 17:55:54 -0400498 memset(&vsi->tx_rings[i]->stats, 0,
Alexander Duyck9f65e152013-09-28 06:00:58 +0000499 sizeof(vsi->tx_rings[i]->stats));
500 memset(&vsi->tx_rings[i]->tx_stats, 0,
501 sizeof(vsi->tx_rings[i]->tx_stats));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000502 }
Greg Rose8e9dca52013-12-18 13:45:53 +0000503 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000504 vsi->stat_offsets_loaded = false;
505}
506
507/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +0000508 * i40e_pf_reset_stats - Reset all of the stats for the given PF
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000509 * @pf: the PF to be reset
510 **/
511void i40e_pf_reset_stats(struct i40e_pf *pf)
512{
Shannon Nelsone91fdf72014-06-03 23:50:18 +0000513 int i;
514
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000515 memset(&pf->stats, 0, sizeof(pf->stats));
516 memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
517 pf->stat_offsets_loaded = false;
Shannon Nelsone91fdf72014-06-03 23:50:18 +0000518
519 for (i = 0; i < I40E_MAX_VEB; i++) {
520 if (pf->veb[i]) {
521 memset(&pf->veb[i]->stats, 0,
522 sizeof(pf->veb[i]->stats));
523 memset(&pf->veb[i]->stats_offsets, 0,
524 sizeof(pf->veb[i]->stats_offsets));
525 pf->veb[i]->stat_offsets_loaded = false;
526 }
527 }
Catherine Sullivan42bce042016-07-27 12:02:32 -0700528 pf->hw_csum_rx_error = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000529}
530
531/**
532 * i40e_stat_update48 - read and update a 48 bit stat from the chip
533 * @hw: ptr to the hardware info
534 * @hireg: the high 32 bit reg to read
535 * @loreg: the low 32 bit reg to read
536 * @offset_loaded: has the initial offset been loaded yet
537 * @offset: ptr to current offset value
538 * @stat: ptr to the stat
539 *
540 * Since the device stats are not reset at PFReset, they likely will not
541 * be zeroed when the driver starts. We'll save the first values read
542 * and use them as offsets to be subtracted from the raw values in order
543 * to report stats that count from zero. In the process, we also manage
544 * the potential roll-over.
545 **/
546static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
547 bool offset_loaded, u64 *offset, u64 *stat)
548{
549 u64 new_data;
550
Shannon Nelsonab600852014-01-17 15:36:39 -0800551 if (hw->device_id == I40E_DEV_ID_QEMU) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000552 new_data = rd32(hw, loreg);
553 new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
554 } else {
555 new_data = rd64(hw, loreg);
556 }
557 if (!offset_loaded)
558 *offset = new_data;
559 if (likely(new_data >= *offset))
560 *stat = new_data - *offset;
561 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400562 *stat = (new_data + BIT_ULL(48)) - *offset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000563 *stat &= 0xFFFFFFFFFFFFULL;
564}
565
566/**
567 * i40e_stat_update32 - read and update a 32 bit stat from the chip
568 * @hw: ptr to the hardware info
569 * @reg: the hw reg to read
570 * @offset_loaded: has the initial offset been loaded yet
571 * @offset: ptr to current offset value
572 * @stat: ptr to the stat
573 **/
574static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
575 bool offset_loaded, u64 *offset, u64 *stat)
576{
577 u32 new_data;
578
579 new_data = rd32(hw, reg);
580 if (!offset_loaded)
581 *offset = new_data;
582 if (likely(new_data >= *offset))
583 *stat = (u32)(new_data - *offset);
584 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400585 *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000586}
587
588/**
589 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
590 * @vsi: the VSI to be updated
591 **/
592void i40e_update_eth_stats(struct i40e_vsi *vsi)
593{
594 int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
595 struct i40e_pf *pf = vsi->back;
596 struct i40e_hw *hw = &pf->hw;
597 struct i40e_eth_stats *oes;
598 struct i40e_eth_stats *es; /* device's eth stats */
599
600 es = &vsi->eth_stats;
601 oes = &vsi->eth_stats_offsets;
602
603 /* Gather up the stats that the hw collects */
604 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
605 vsi->stat_offsets_loaded,
606 &oes->tx_errors, &es->tx_errors);
607 i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
608 vsi->stat_offsets_loaded,
609 &oes->rx_discards, &es->rx_discards);
Shannon Nelson41a9e552014-04-23 04:50:20 +0000610 i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
611 vsi->stat_offsets_loaded,
612 &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
613 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
614 vsi->stat_offsets_loaded,
615 &oes->tx_errors, &es->tx_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000616
617 i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
618 I40E_GLV_GORCL(stat_idx),
619 vsi->stat_offsets_loaded,
620 &oes->rx_bytes, &es->rx_bytes);
621 i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
622 I40E_GLV_UPRCL(stat_idx),
623 vsi->stat_offsets_loaded,
624 &oes->rx_unicast, &es->rx_unicast);
625 i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
626 I40E_GLV_MPRCL(stat_idx),
627 vsi->stat_offsets_loaded,
628 &oes->rx_multicast, &es->rx_multicast);
629 i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
630 I40E_GLV_BPRCL(stat_idx),
631 vsi->stat_offsets_loaded,
632 &oes->rx_broadcast, &es->rx_broadcast);
633
634 i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
635 I40E_GLV_GOTCL(stat_idx),
636 vsi->stat_offsets_loaded,
637 &oes->tx_bytes, &es->tx_bytes);
638 i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
639 I40E_GLV_UPTCL(stat_idx),
640 vsi->stat_offsets_loaded,
641 &oes->tx_unicast, &es->tx_unicast);
642 i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
643 I40E_GLV_MPTCL(stat_idx),
644 vsi->stat_offsets_loaded,
645 &oes->tx_multicast, &es->tx_multicast);
646 i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
647 I40E_GLV_BPTCL(stat_idx),
648 vsi->stat_offsets_loaded,
649 &oes->tx_broadcast, &es->tx_broadcast);
650 vsi->stat_offsets_loaded = true;
651}
652
653/**
654 * i40e_update_veb_stats - Update Switch component statistics
655 * @veb: the VEB being updated
656 **/
657static void i40e_update_veb_stats(struct i40e_veb *veb)
658{
659 struct i40e_pf *pf = veb->pf;
660 struct i40e_hw *hw = &pf->hw;
661 struct i40e_eth_stats *oes;
662 struct i40e_eth_stats *es; /* device's eth stats */
Neerav Parikhfe860af2015-07-10 19:36:02 -0400663 struct i40e_veb_tc_stats *veb_oes;
664 struct i40e_veb_tc_stats *veb_es;
665 int i, idx = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000666
667 idx = veb->stats_idx;
668 es = &veb->stats;
669 oes = &veb->stats_offsets;
Neerav Parikhfe860af2015-07-10 19:36:02 -0400670 veb_es = &veb->tc_stats;
671 veb_oes = &veb->tc_stats_offsets;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000672
673 /* Gather up the stats that the hw collects */
674 i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
675 veb->stat_offsets_loaded,
676 &oes->tx_discards, &es->tx_discards);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000677 if (hw->revision_id > 0)
678 i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
679 veb->stat_offsets_loaded,
680 &oes->rx_unknown_protocol,
681 &es->rx_unknown_protocol);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000682 i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
683 veb->stat_offsets_loaded,
684 &oes->rx_bytes, &es->rx_bytes);
685 i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
686 veb->stat_offsets_loaded,
687 &oes->rx_unicast, &es->rx_unicast);
688 i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
689 veb->stat_offsets_loaded,
690 &oes->rx_multicast, &es->rx_multicast);
691 i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
692 veb->stat_offsets_loaded,
693 &oes->rx_broadcast, &es->rx_broadcast);
694
695 i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
696 veb->stat_offsets_loaded,
697 &oes->tx_bytes, &es->tx_bytes);
698 i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
699 veb->stat_offsets_loaded,
700 &oes->tx_unicast, &es->tx_unicast);
701 i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
702 veb->stat_offsets_loaded,
703 &oes->tx_multicast, &es->tx_multicast);
704 i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
705 veb->stat_offsets_loaded,
706 &oes->tx_broadcast, &es->tx_broadcast);
Neerav Parikhfe860af2015-07-10 19:36:02 -0400707 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
708 i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
709 I40E_GLVEBTC_RPCL(i, idx),
710 veb->stat_offsets_loaded,
711 &veb_oes->tc_rx_packets[i],
712 &veb_es->tc_rx_packets[i]);
713 i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
714 I40E_GLVEBTC_RBCL(i, idx),
715 veb->stat_offsets_loaded,
716 &veb_oes->tc_rx_bytes[i],
717 &veb_es->tc_rx_bytes[i]);
718 i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
719 I40E_GLVEBTC_TPCL(i, idx),
720 veb->stat_offsets_loaded,
721 &veb_oes->tc_tx_packets[i],
722 &veb_es->tc_tx_packets[i]);
723 i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
724 I40E_GLVEBTC_TBCL(i, idx),
725 veb->stat_offsets_loaded,
726 &veb_oes->tc_tx_bytes[i],
727 &veb_es->tc_tx_bytes[i]);
728 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000729 veb->stat_offsets_loaded = true;
730}
731
Vasu Dev38e00432014-08-01 13:27:03 -0700732#ifdef I40E_FCOE
733/**
734 * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
735 * @vsi: the VSI that is capable of doing FCoE
736 **/
737static void i40e_update_fcoe_stats(struct i40e_vsi *vsi)
738{
739 struct i40e_pf *pf = vsi->back;
740 struct i40e_hw *hw = &pf->hw;
741 struct i40e_fcoe_stats *ofs;
742 struct i40e_fcoe_stats *fs; /* device's eth stats */
743 int idx;
744
745 if (vsi->type != I40E_VSI_FCOE)
746 return;
747
Kiran Patil4147e2c2016-01-15 14:33:14 -0800748 idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET;
Vasu Dev38e00432014-08-01 13:27:03 -0700749 fs = &vsi->fcoe_stats;
750 ofs = &vsi->fcoe_stats_offsets;
751
752 i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx),
753 vsi->fcoe_stat_offsets_loaded,
754 &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets);
755 i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx),
756 vsi->fcoe_stat_offsets_loaded,
757 &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords);
758 i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx),
759 vsi->fcoe_stat_offsets_loaded,
760 &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped);
761 i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx),
762 vsi->fcoe_stat_offsets_loaded,
763 &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets);
764 i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx),
765 vsi->fcoe_stat_offsets_loaded,
766 &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords);
767 i40e_stat_update32(hw, I40E_GL_FCOECRC(idx),
768 vsi->fcoe_stat_offsets_loaded,
769 &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc);
770 i40e_stat_update32(hw, I40E_GL_FCOELAST(idx),
771 vsi->fcoe_stat_offsets_loaded,
772 &ofs->fcoe_last_error, &fs->fcoe_last_error);
773 i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx),
774 vsi->fcoe_stat_offsets_loaded,
775 &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count);
776
777 vsi->fcoe_stat_offsets_loaded = true;
778}
779
780#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000781/**
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000782 * i40e_update_vsi_stats - Update the vsi statistics counters.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000783 * @vsi: the VSI to be updated
784 *
785 * There are a few instances where we store the same stat in a
786 * couple of different structs. This is partly because we have
787 * the netdev stats that need to be filled out, which is slightly
788 * different from the "eth_stats" defined by the chip and used in
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000789 * VF communications. We sort it out here.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000790 **/
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000791static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000792{
793 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000794 struct rtnl_link_stats64 *ons;
795 struct rtnl_link_stats64 *ns; /* netdev stats */
796 struct i40e_eth_stats *oes;
797 struct i40e_eth_stats *es; /* device's eth stats */
798 u32 tx_restart, tx_busy;
Anjali Singhai Jaindd353102016-01-15 14:33:12 -0800799 u64 tx_lost_interrupt;
Akeem G Abodunrinbf00b372014-10-17 03:14:39 +0000800 struct i40e_ring *p;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000801 u32 rx_page, rx_buf;
Akeem G Abodunrinbf00b372014-10-17 03:14:39 +0000802 u64 bytes, packets;
803 unsigned int start;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400804 u64 tx_linearize;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400805 u64 tx_force_wb;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000806 u64 rx_p, rx_b;
807 u64 tx_p, tx_b;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000808 u16 q;
809
810 if (test_bit(__I40E_DOWN, &vsi->state) ||
811 test_bit(__I40E_CONFIG_BUSY, &pf->state))
812 return;
813
814 ns = i40e_get_vsi_stats_struct(vsi);
815 ons = &vsi->net_stats_offsets;
816 es = &vsi->eth_stats;
817 oes = &vsi->eth_stats_offsets;
818
819 /* Gather up the netdev and vsi stats that the driver collects
820 * on the fly during packet processing
821 */
822 rx_b = rx_p = 0;
823 tx_b = tx_p = 0;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400824 tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
Anjali Singhai Jaindd353102016-01-15 14:33:12 -0800825 tx_lost_interrupt = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000826 rx_page = 0;
827 rx_buf = 0;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000828 rcu_read_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000829 for (q = 0; q < vsi->num_queue_pairs; q++) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000830 /* locate Tx ring */
831 p = ACCESS_ONCE(vsi->tx_rings[q]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000832
Alexander Duyck980e9b12013-09-28 06:01:03 +0000833 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700834 start = u64_stats_fetch_begin_irq(&p->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000835 packets = p->stats.packets;
836 bytes = p->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700837 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000838 tx_b += bytes;
839 tx_p += packets;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000840 tx_restart += p->tx_stats.restart_queue;
841 tx_busy += p->tx_stats.tx_busy;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400842 tx_linearize += p->tx_stats.tx_linearize;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400843 tx_force_wb += p->tx_stats.tx_force_wb;
Anjali Singhai Jaindd353102016-01-15 14:33:12 -0800844 tx_lost_interrupt += p->tx_stats.tx_lost_interrupt;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000845
846 /* Rx queue is part of the same block as Tx queue */
847 p = &p[1];
848 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700849 start = u64_stats_fetch_begin_irq(&p->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000850 packets = p->stats.packets;
851 bytes = p->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700852 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000853 rx_b += bytes;
854 rx_p += packets;
Mitch Williams420136c2013-12-18 13:45:59 +0000855 rx_buf += p->rx_stats.alloc_buff_failed;
856 rx_page += p->rx_stats.alloc_page_failed;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000857 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000858 rcu_read_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000859 vsi->tx_restart = tx_restart;
860 vsi->tx_busy = tx_busy;
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -0400861 vsi->tx_linearize = tx_linearize;
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -0400862 vsi->tx_force_wb = tx_force_wb;
Anjali Singhai Jaindd353102016-01-15 14:33:12 -0800863 vsi->tx_lost_interrupt = tx_lost_interrupt;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000864 vsi->rx_page_failed = rx_page;
865 vsi->rx_buf_failed = rx_buf;
866
867 ns->rx_packets = rx_p;
868 ns->rx_bytes = rx_b;
869 ns->tx_packets = tx_p;
870 ns->tx_bytes = tx_b;
871
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000872 /* update netdev stats from eth stats */
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000873 i40e_update_eth_stats(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000874 ons->tx_errors = oes->tx_errors;
875 ns->tx_errors = es->tx_errors;
876 ons->multicast = oes->rx_multicast;
877 ns->multicast = es->rx_multicast;
Shannon Nelson41a9e552014-04-23 04:50:20 +0000878 ons->rx_dropped = oes->rx_discards;
879 ns->rx_dropped = es->rx_discards;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000880 ons->tx_dropped = oes->tx_discards;
881 ns->tx_dropped = es->tx_discards;
882
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000883 /* pull in a couple PF stats if this is the main vsi */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000884 if (vsi == pf->vsi[pf->lan_vsi]) {
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000885 ns->rx_crc_errors = pf->stats.crc_errors;
886 ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
887 ns->rx_length_errors = pf->stats.rx_length_errors;
888 }
889}
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000890
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000891/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +0000892 * i40e_update_pf_stats - Update the PF statistics counters.
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000893 * @pf: the PF to be updated
894 **/
895static void i40e_update_pf_stats(struct i40e_pf *pf)
896{
897 struct i40e_hw_port_stats *osd = &pf->stats_offsets;
898 struct i40e_hw_port_stats *nsd = &pf->stats;
899 struct i40e_hw *hw = &pf->hw;
900 u32 val;
901 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000902
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000903 i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
904 I40E_GLPRT_GORCL(hw->port),
905 pf->stat_offsets_loaded,
906 &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
907 i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
908 I40E_GLPRT_GOTCL(hw->port),
909 pf->stat_offsets_loaded,
910 &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
911 i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
912 pf->stat_offsets_loaded,
913 &osd->eth.rx_discards,
914 &nsd->eth.rx_discards);
Shannon Nelson532d2832014-04-23 04:50:09 +0000915 i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
916 I40E_GLPRT_UPRCL(hw->port),
917 pf->stat_offsets_loaded,
918 &osd->eth.rx_unicast,
919 &nsd->eth.rx_unicast);
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000920 i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
921 I40E_GLPRT_MPRCL(hw->port),
922 pf->stat_offsets_loaded,
923 &osd->eth.rx_multicast,
924 &nsd->eth.rx_multicast);
Shannon Nelson532d2832014-04-23 04:50:09 +0000925 i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
926 I40E_GLPRT_BPRCL(hw->port),
927 pf->stat_offsets_loaded,
928 &osd->eth.rx_broadcast,
929 &nsd->eth.rx_broadcast);
930 i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
931 I40E_GLPRT_UPTCL(hw->port),
932 pf->stat_offsets_loaded,
933 &osd->eth.tx_unicast,
934 &nsd->eth.tx_unicast);
935 i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
936 I40E_GLPRT_MPTCL(hw->port),
937 pf->stat_offsets_loaded,
938 &osd->eth.tx_multicast,
939 &nsd->eth.tx_multicast);
940 i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
941 I40E_GLPRT_BPTCL(hw->port),
942 pf->stat_offsets_loaded,
943 &osd->eth.tx_broadcast,
944 &nsd->eth.tx_broadcast);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000945
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000946 i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
947 pf->stat_offsets_loaded,
948 &osd->tx_dropped_link_down,
949 &nsd->tx_dropped_link_down);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000950
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000951 i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
952 pf->stat_offsets_loaded,
953 &osd->crc_errors, &nsd->crc_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000954
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000955 i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
956 pf->stat_offsets_loaded,
957 &osd->illegal_bytes, &nsd->illegal_bytes);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000958
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000959 i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
960 pf->stat_offsets_loaded,
961 &osd->mac_local_faults,
962 &nsd->mac_local_faults);
963 i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
964 pf->stat_offsets_loaded,
965 &osd->mac_remote_faults,
966 &nsd->mac_remote_faults);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000967
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000968 i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
969 pf->stat_offsets_loaded,
970 &osd->rx_length_errors,
971 &nsd->rx_length_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000972
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000973 i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
974 pf->stat_offsets_loaded,
975 &osd->link_xon_rx, &nsd->link_xon_rx);
976 i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
977 pf->stat_offsets_loaded,
978 &osd->link_xon_tx, &nsd->link_xon_tx);
Neerav Parikh95db2392015-11-06 15:26:09 -0800979 i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
980 pf->stat_offsets_loaded,
981 &osd->link_xoff_rx, &nsd->link_xoff_rx);
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000982 i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
983 pf->stat_offsets_loaded,
984 &osd->link_xoff_tx, &nsd->link_xoff_tx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000985
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000986 for (i = 0; i < 8; i++) {
Neerav Parikh95db2392015-11-06 15:26:09 -0800987 i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
988 pf->stat_offsets_loaded,
989 &osd->priority_xoff_rx[i],
990 &nsd->priority_xoff_rx[i]);
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000991 i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000992 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000993 &osd->priority_xon_rx[i],
994 &nsd->priority_xon_rx[i]);
995 i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000996 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000997 &osd->priority_xon_tx[i],
998 &nsd->priority_xon_tx[i]);
999 i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001000 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001001 &osd->priority_xoff_tx[i],
1002 &nsd->priority_xoff_tx[i]);
1003 i40e_stat_update32(hw,
1004 I40E_GLPRT_RXON2OFFCNT(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001005 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001006 &osd->priority_xon_2_xoff[i],
1007 &nsd->priority_xon_2_xoff[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001008 }
1009
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001010 i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
1011 I40E_GLPRT_PRC64L(hw->port),
1012 pf->stat_offsets_loaded,
1013 &osd->rx_size_64, &nsd->rx_size_64);
1014 i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
1015 I40E_GLPRT_PRC127L(hw->port),
1016 pf->stat_offsets_loaded,
1017 &osd->rx_size_127, &nsd->rx_size_127);
1018 i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
1019 I40E_GLPRT_PRC255L(hw->port),
1020 pf->stat_offsets_loaded,
1021 &osd->rx_size_255, &nsd->rx_size_255);
1022 i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
1023 I40E_GLPRT_PRC511L(hw->port),
1024 pf->stat_offsets_loaded,
1025 &osd->rx_size_511, &nsd->rx_size_511);
1026 i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
1027 I40E_GLPRT_PRC1023L(hw->port),
1028 pf->stat_offsets_loaded,
1029 &osd->rx_size_1023, &nsd->rx_size_1023);
1030 i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
1031 I40E_GLPRT_PRC1522L(hw->port),
1032 pf->stat_offsets_loaded,
1033 &osd->rx_size_1522, &nsd->rx_size_1522);
1034 i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
1035 I40E_GLPRT_PRC9522L(hw->port),
1036 pf->stat_offsets_loaded,
1037 &osd->rx_size_big, &nsd->rx_size_big);
1038
1039 i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
1040 I40E_GLPRT_PTC64L(hw->port),
1041 pf->stat_offsets_loaded,
1042 &osd->tx_size_64, &nsd->tx_size_64);
1043 i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
1044 I40E_GLPRT_PTC127L(hw->port),
1045 pf->stat_offsets_loaded,
1046 &osd->tx_size_127, &nsd->tx_size_127);
1047 i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
1048 I40E_GLPRT_PTC255L(hw->port),
1049 pf->stat_offsets_loaded,
1050 &osd->tx_size_255, &nsd->tx_size_255);
1051 i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
1052 I40E_GLPRT_PTC511L(hw->port),
1053 pf->stat_offsets_loaded,
1054 &osd->tx_size_511, &nsd->tx_size_511);
1055 i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
1056 I40E_GLPRT_PTC1023L(hw->port),
1057 pf->stat_offsets_loaded,
1058 &osd->tx_size_1023, &nsd->tx_size_1023);
1059 i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
1060 I40E_GLPRT_PTC1522L(hw->port),
1061 pf->stat_offsets_loaded,
1062 &osd->tx_size_1522, &nsd->tx_size_1522);
1063 i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
1064 I40E_GLPRT_PTC9522L(hw->port),
1065 pf->stat_offsets_loaded,
1066 &osd->tx_size_big, &nsd->tx_size_big);
1067
1068 i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
1069 pf->stat_offsets_loaded,
1070 &osd->rx_undersize, &nsd->rx_undersize);
1071 i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
1072 pf->stat_offsets_loaded,
1073 &osd->rx_fragments, &nsd->rx_fragments);
1074 i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
1075 pf->stat_offsets_loaded,
1076 &osd->rx_oversize, &nsd->rx_oversize);
1077 i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
1078 pf->stat_offsets_loaded,
1079 &osd->rx_jabber, &nsd->rx_jabber);
1080
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001081 /* FDIR stats */
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04001082 i40e_stat_update32(hw,
1083 I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001084 pf->stat_offsets_loaded,
1085 &osd->fd_atr_match, &nsd->fd_atr_match);
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04001086 i40e_stat_update32(hw,
1087 I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001088 pf->stat_offsets_loaded,
1089 &osd->fd_sb_match, &nsd->fd_sb_match);
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -04001090 i40e_stat_update32(hw,
1091 I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)),
1092 pf->stat_offsets_loaded,
1093 &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match);
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001094
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001095 val = rd32(hw, I40E_PRTPM_EEE_STAT);
1096 nsd->tx_lpi_status =
1097 (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
1098 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
1099 nsd->rx_lpi_status =
1100 (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
1101 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
1102 i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
1103 pf->stat_offsets_loaded,
1104 &osd->tx_lpi_count, &nsd->tx_lpi_count);
1105 i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
1106 pf->stat_offsets_loaded,
1107 &osd->rx_lpi_count, &nsd->rx_lpi_count);
1108
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -04001109 if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
1110 !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED))
1111 nsd->fd_sb_status = true;
1112 else
1113 nsd->fd_sb_status = false;
1114
1115 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
1116 !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
1117 nsd->fd_atr_status = true;
1118 else
1119 nsd->fd_atr_status = false;
1120
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001121 pf->stat_offsets_loaded = true;
1122}
1123
1124/**
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001125 * i40e_update_stats - Update the various statistics counters.
1126 * @vsi: the VSI to be updated
1127 *
1128 * Update the various stats for this VSI and its related entities.
1129 **/
1130void i40e_update_stats(struct i40e_vsi *vsi)
1131{
1132 struct i40e_pf *pf = vsi->back;
1133
1134 if (vsi == pf->vsi[pf->lan_vsi])
1135 i40e_update_pf_stats(pf);
1136
1137 i40e_update_vsi_stats(vsi);
Vasu Dev38e00432014-08-01 13:27:03 -07001138#ifdef I40E_FCOE
1139 i40e_update_fcoe_stats(vsi);
1140#endif
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001141}
1142
1143/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001144 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1145 * @vsi: the VSI to be searched
1146 * @macaddr: the MAC address
1147 * @vlan: the vlan
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001148 *
1149 * Returns ptr to the filter object or NULL
1150 **/
1151static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
Jacob Keller6622f5c2016-10-05 09:30:32 -07001152 const u8 *macaddr, s16 vlan)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001153{
1154 struct i40e_mac_filter *f;
1155
1156 if (!vsi || !macaddr)
1157 return NULL;
1158
1159 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1160 if ((ether_addr_equal(macaddr, f->macaddr)) &&
Jacob Keller1bc87e82016-10-05 09:30:31 -07001161 (vlan == f->vlan))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001162 return f;
1163 }
1164 return NULL;
1165}
1166
1167/**
1168 * i40e_find_mac - Find a mac addr in the macvlan filters list
1169 * @vsi: the VSI to be searched
1170 * @macaddr: the MAC address we are searching for
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001171 *
1172 * Returns the first filter with the provided MAC address or NULL if
1173 * MAC address was not found
1174 **/
Jacob Keller6622f5c2016-10-05 09:30:32 -07001175struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001176{
1177 struct i40e_mac_filter *f;
1178
1179 if (!vsi || !macaddr)
1180 return NULL;
1181
1182 list_for_each_entry(f, &vsi->mac_filter_list, list) {
Jacob Keller1bc87e82016-10-05 09:30:31 -07001183 if ((ether_addr_equal(macaddr, f->macaddr)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001184 return f;
1185 }
1186 return NULL;
1187}
1188
1189/**
1190 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1191 * @vsi: the VSI to be searched
1192 *
1193 * Returns true if VSI is in vlan mode or false otherwise
1194 **/
1195bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
1196{
1197 struct i40e_mac_filter *f;
1198
1199 /* Only -1 for all the filters denotes not in vlan mode
1200 * so we have to go through all the list in order to make sure
1201 */
1202 list_for_each_entry(f, &vsi->mac_filter_list, list) {
Greg Rosed9b68f82015-07-23 16:54:31 -04001203 if (f->vlan >= 0 || vsi->info.pvid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001204 return true;
1205 }
1206
1207 return false;
1208}
1209
1210/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001211 * i40e_add_filter - Add a mac/vlan filter to the VSI
1212 * @vsi: the VSI to be searched
1213 * @macaddr: the MAC address
1214 * @vlan: the vlan
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001215 *
1216 * Returns ptr to the filter object or NULL when no memory available.
Kiran Patil21659032015-09-30 14:09:03 -04001217 *
1218 * NOTE: This function is expected to be called with mac_filter_list_lock
1219 * being held.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001220 **/
1221struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
Jacob Keller6622f5c2016-10-05 09:30:32 -07001222 const u8 *macaddr, s16 vlan)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001223{
1224 struct i40e_mac_filter *f;
1225
1226 if (!vsi || !macaddr)
1227 return NULL;
1228
Kiran Patilf6bd0962016-06-20 09:10:34 -07001229 /* Do not allow broadcast filter to be added since broadcast filter
1230 * is added as part of add VSI for any newly created VSI except
1231 * FDIR VSI
1232 */
1233 if (is_broadcast_ether_addr(macaddr))
1234 return NULL;
1235
Jacob Keller1bc87e82016-10-05 09:30:31 -07001236 f = i40e_find_filter(vsi, macaddr, vlan);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001237 if (!f) {
1238 f = kzalloc(sizeof(*f), GFP_ATOMIC);
1239 if (!f)
Jacob Keller1bc87e82016-10-05 09:30:31 -07001240 return NULL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001241
Greg Rose9a173902014-05-22 06:32:02 +00001242 ether_addr_copy(f->macaddr, macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001243 f->vlan = vlan;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001244 /* If we're in overflow promisc mode, set the state directly
1245 * to failed, so we don't bother to try sending the filter
1246 * to the hardware.
1247 */
1248 if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))
1249 f->state = I40E_FILTER_FAILED;
1250 else
1251 f->state = I40E_FILTER_NEW;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001252 INIT_LIST_HEAD(&f->list);
Kiran Patil04d5a212015-12-09 15:50:23 -08001253 list_add_tail(&f->list, &vsi->mac_filter_list);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001254
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001255 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1256 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1257 }
1258
Jacob Keller1bc87e82016-10-05 09:30:31 -07001259 /* If we're asked to add a filter that has been marked for removal, it
1260 * is safe to simply restore it to active state. __i40e_del_filter
1261 * will have simply deleted any filters which were previously marked
1262 * NEW or FAILED, so if it is currently marked REMOVE it must have
1263 * previously been ACTIVE. Since we haven't yet run the sync filters
1264 * task, just restore this filter to the ACTIVE state so that the
1265 * sync task leaves it in place
1266 */
1267 if (f->state == I40E_FILTER_REMOVE)
1268 f->state = I40E_FILTER_ACTIVE;
1269
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001270 return f;
1271}
1272
1273/**
1274 * i40e_del_filter - Remove a mac/vlan filter from the VSI
1275 * @vsi: the VSI to be searched
1276 * @macaddr: the MAC address
1277 * @vlan: the vlan
Kiran Patil21659032015-09-30 14:09:03 -04001278 *
1279 * NOTE: This function is expected to be called with mac_filter_list_lock
1280 * being held.
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001281 * ANOTHER NOTE: This function MUST be called from within the context of
1282 * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
1283 * instead of list_for_each_entry().
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001284 **/
Jacob Keller6622f5c2016-10-05 09:30:32 -07001285void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001286{
1287 struct i40e_mac_filter *f;
1288
1289 if (!vsi || !macaddr)
1290 return;
1291
Jacob Keller1bc87e82016-10-05 09:30:31 -07001292 f = i40e_find_filter(vsi, macaddr, vlan);
1293 if (!f)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001294 return;
1295
Jacob Keller1bc87e82016-10-05 09:30:31 -07001296 if ((f->state == I40E_FILTER_FAILED) ||
1297 (f->state == I40E_FILTER_NEW)) {
1298 /* this one never got added by the FW. Just remove it,
1299 * no need to sync anything.
1300 */
1301 list_del(&f->list);
1302 kfree(f);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001303 } else {
Jacob Keller1bc87e82016-10-05 09:30:31 -07001304 f->state = I40E_FILTER_REMOVE;
1305 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1306 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001307 }
1308}
1309
1310/**
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001311 * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
1312 * @vsi: the VSI to be searched
1313 * @macaddr: the mac address to be filtered
1314 *
1315 * Goes through all the macvlan filters and adds a
1316 * macvlan filter for each unique vlan that already exists
1317 *
1318 * Returns first filter found on success, else NULL
1319 **/
1320struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi,
1321 const u8 *macaddr)
1322{
1323 struct i40e_mac_filter *f;
1324
1325 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1326 if (vsi->info.pvid)
1327 f->vlan = le16_to_cpu(vsi->info.pvid);
1328 if (!i40e_find_filter(vsi, macaddr, f->vlan)) {
1329 if (!i40e_add_filter(vsi, macaddr, f->vlan))
1330 return NULL;
1331 }
1332 }
1333
1334 return list_first_entry_or_null(&vsi->mac_filter_list,
1335 struct i40e_mac_filter, list);
1336}
1337
1338/**
1339 * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS
1340 * @vsi: the VSI to be searched
1341 * @macaddr: the mac address to be removed
1342 *
1343 * Removes a given MAC address from a VSI, regardless of VLAN
1344 *
1345 * Returns 0 for success, or error
1346 **/
1347int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, const u8 *macaddr)
1348{
1349 struct i40e_mac_filter *f = NULL;
1350 int changed = 0;
1351
1352 WARN(!spin_is_locked(&vsi->mac_filter_list_lock),
1353 "Missing mac_filter_list_lock\n");
1354 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1355 if (ether_addr_equal(macaddr, f->macaddr))
1356 f->state = I40E_FILTER_REMOVE;
1357 }
1358 if (changed) {
1359 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1360 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1361 return 0;
1362 }
1363 return -ENOENT;
1364}
1365
1366/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001367 * i40e_set_mac - NDO callback to set mac address
1368 * @netdev: network interface device structure
1369 * @p: pointer to an address structure
1370 *
1371 * Returns 0 on success, negative on failure
1372 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001373#ifdef I40E_FCOE
1374int i40e_set_mac(struct net_device *netdev, void *p)
1375#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001376static int i40e_set_mac(struct net_device *netdev, void *p)
Vasu Dev38e00432014-08-01 13:27:03 -07001377#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001378{
1379 struct i40e_netdev_priv *np = netdev_priv(netdev);
1380 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson30650cc2014-07-29 04:01:50 +00001381 struct i40e_pf *pf = vsi->back;
1382 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001383 struct sockaddr *addr = p;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001384
1385 if (!is_valid_ether_addr(addr->sa_data))
1386 return -EADDRNOTAVAIL;
1387
Shannon Nelson30650cc2014-07-29 04:01:50 +00001388 if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
1389 netdev_info(netdev, "already using mac address %pM\n",
1390 addr->sa_data);
1391 return 0;
1392 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001393
Anjali Singhai Jain80f64282013-11-28 06:39:47 +00001394 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
1395 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
1396 return -EADDRNOTAVAIL;
1397
Shannon Nelson30650cc2014-07-29 04:01:50 +00001398 if (ether_addr_equal(hw->mac.addr, addr->sa_data))
1399 netdev_info(netdev, "returning to hw mac address %pM\n",
1400 hw->mac.addr);
1401 else
1402 netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
1403
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001404 spin_lock_bh(&vsi->mac_filter_list_lock);
Jacob Keller1bc87e82016-10-05 09:30:31 -07001405 i40e_del_mac_all_vlan(vsi, netdev->dev_addr);
1406 i40e_put_mac_in_vlan(vsi, addr->sa_data);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001407 spin_unlock_bh(&vsi->mac_filter_list_lock);
1408 ether_addr_copy(netdev->dev_addr, addr->sa_data);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001409 if (vsi->type == I40E_VSI_MAIN) {
1410 i40e_status ret;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001411
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001412 ret = i40e_aq_mac_address_write(&vsi->back->hw,
Shannon Nelsoncc412222014-06-04 01:23:21 +00001413 I40E_AQC_WRITE_TYPE_LAA_WOL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001414 addr->sa_data, NULL);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001415 if (ret)
1416 netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
1417 i40e_stat_str(hw, ret),
1418 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001419 }
1420
Jesse Brandeburgc53934c2016-01-04 10:33:06 -08001421 /* schedule our worker thread which will take care of
1422 * applying the new filter changes
1423 */
1424 i40e_service_event_schedule(vsi->back);
1425 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001426}
1427
1428/**
1429 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1430 * @vsi: the VSI being setup
1431 * @ctxt: VSI context structure
1432 * @enabled_tc: Enabled TCs bitmap
1433 * @is_add: True if called before Add VSI
1434 *
1435 * Setup VSI queue mapping for enabled traffic classes.
1436 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001437#ifdef I40E_FCOE
1438void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1439 struct i40e_vsi_context *ctxt,
1440 u8 enabled_tc,
1441 bool is_add)
1442#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001443static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1444 struct i40e_vsi_context *ctxt,
1445 u8 enabled_tc,
1446 bool is_add)
Vasu Dev38e00432014-08-01 13:27:03 -07001447#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001448{
1449 struct i40e_pf *pf = vsi->back;
1450 u16 sections = 0;
1451 u8 netdev_tc = 0;
1452 u16 numtc = 0;
1453 u16 qcount;
1454 u8 offset;
1455 u16 qmap;
1456 int i;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001457 u16 num_tc_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001458
1459 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
1460 offset = 0;
1461
1462 if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
1463 /* Find numtc from enabled TC bitmap */
1464 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08001465 if (enabled_tc & BIT(i)) /* TC is enabled */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001466 numtc++;
1467 }
1468 if (!numtc) {
1469 dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
1470 numtc = 1;
1471 }
1472 } else {
1473 /* At least TC0 is enabled in case of non-DCB case */
1474 numtc = 1;
1475 }
1476
1477 vsi->tc_config.numtc = numtc;
1478 vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001479 /* Number of queues per enabled TC */
Catherine Sullivan7d644022016-05-16 10:26:41 -07001480 qcount = vsi->alloc_queue_pairs;
1481
Anjali Singhai7f9ff472015-02-21 06:43:19 +00001482 num_tc_qps = qcount / numtc;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04001483 num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001484
1485 /* Setup queue offset/count for all TCs for given VSI */
1486 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1487 /* See if the given TC is enabled for the given VSI */
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08001488 if (vsi->tc_config.enabled_tc & BIT(i)) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001489 /* TC is enabled */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001490 int pow, num_qps;
1491
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001492 switch (vsi->type) {
1493 case I40E_VSI_MAIN:
Helin Zhangacd65442015-10-26 19:44:28 -04001494 qcount = min_t(int, pf->alloc_rss_size,
1495 num_tc_qps);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001496 break;
Vasu Dev38e00432014-08-01 13:27:03 -07001497#ifdef I40E_FCOE
1498 case I40E_VSI_FCOE:
1499 qcount = num_tc_qps;
1500 break;
1501#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001502 case I40E_VSI_FDIR:
1503 case I40E_VSI_SRIOV:
1504 case I40E_VSI_VMDQ2:
1505 default:
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001506 qcount = num_tc_qps;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001507 WARN_ON(i != 0);
1508 break;
1509 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001510 vsi->tc_config.tc_info[i].qoffset = offset;
1511 vsi->tc_config.tc_info[i].qcount = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001512
Shannon Nelson1e200e42015-02-27 09:15:24 +00001513 /* find the next higher power-of-2 of num queue pairs */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001514 num_qps = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001515 pow = 0;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001516 while (num_qps && (BIT_ULL(pow) < qcount)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001517 pow++;
1518 num_qps >>= 1;
1519 }
1520
1521 vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
1522 qmap =
1523 (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
1524 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
1525
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001526 offset += qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001527 } else {
1528 /* TC is not enabled so set the offset to
1529 * default queue and allocate one queue
1530 * for the given TC.
1531 */
1532 vsi->tc_config.tc_info[i].qoffset = 0;
1533 vsi->tc_config.tc_info[i].qcount = 1;
1534 vsi->tc_config.tc_info[i].netdev_tc = 0;
1535
1536 qmap = 0;
1537 }
1538 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
1539 }
1540
1541 /* Set actual Tx/Rx queue pairs */
1542 vsi->num_queue_pairs = offset;
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00001543 if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
1544 if (vsi->req_queue_pairs > 0)
1545 vsi->num_queue_pairs = vsi->req_queue_pairs;
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04001546 else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00001547 vsi->num_queue_pairs = pf->num_lan_msix;
1548 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001549
1550 /* Scheduler section valid can only be set for ADD VSI */
1551 if (is_add) {
1552 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
1553
1554 ctxt->info.up_enable_bits = enabled_tc;
1555 }
1556 if (vsi->type == I40E_VSI_SRIOV) {
1557 ctxt->info.mapping_flags |=
1558 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
1559 for (i = 0; i < vsi->num_queue_pairs; i++)
1560 ctxt->info.queue_mapping[i] =
1561 cpu_to_le16(vsi->base_queue + i);
1562 } else {
1563 ctxt->info.mapping_flags |=
1564 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
1565 ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
1566 }
1567 ctxt->info.valid_sections |= cpu_to_le16(sections);
1568}
1569
1570/**
Jacob Keller6622f5c2016-10-05 09:30:32 -07001571 * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
1572 * @netdev: the netdevice
1573 * @addr: address to add
1574 *
1575 * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
1576 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
1577 */
1578static int i40e_addr_sync(struct net_device *netdev, const u8 *addr)
1579{
1580 struct i40e_netdev_priv *np = netdev_priv(netdev);
1581 struct i40e_vsi *vsi = np->vsi;
1582 struct i40e_mac_filter *f;
1583
1584 if (i40e_is_vsi_in_vlan(vsi))
1585 f = i40e_put_mac_in_vlan(vsi, addr);
1586 else
1587 f = i40e_add_filter(vsi, addr, I40E_VLAN_ANY);
1588
1589 if (f)
1590 return 0;
1591 else
1592 return -ENOMEM;
1593}
1594
1595/**
1596 * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
1597 * @netdev: the netdevice
1598 * @addr: address to add
1599 *
1600 * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
1601 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
1602 */
1603static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr)
1604{
1605 struct i40e_netdev_priv *np = netdev_priv(netdev);
1606 struct i40e_vsi *vsi = np->vsi;
1607
1608 if (i40e_is_vsi_in_vlan(vsi))
1609 i40e_del_mac_all_vlan(vsi, addr);
1610 else
1611 i40e_del_filter(vsi, addr, I40E_VLAN_ANY);
1612
1613 return 0;
1614}
1615
1616/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001617 * i40e_set_rx_mode - NDO callback to set the netdev filters
1618 * @netdev: network interface device structure
1619 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001620#ifdef I40E_FCOE
1621void i40e_set_rx_mode(struct net_device *netdev)
1622#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001623static void i40e_set_rx_mode(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -07001624#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001625{
1626 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001627 struct i40e_vsi *vsi = np->vsi;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001628
Kiran Patil21659032015-09-30 14:09:03 -04001629 spin_lock_bh(&vsi->mac_filter_list_lock);
1630
Jacob Keller6622f5c2016-10-05 09:30:32 -07001631 __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
1632 __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001633
Kiran Patil21659032015-09-30 14:09:03 -04001634 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001635
1636 /* check for other flag changes */
1637 if (vsi->current_netdev_flags != vsi->netdev->flags) {
1638 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1639 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1640 }
Jesse Brandeburgc53934c2016-01-04 10:33:06 -08001641
1642 /* schedule our worker thread which will take care of
1643 * applying the new filter changes
1644 */
1645 i40e_service_event_schedule(vsi->back);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001646}
1647
1648/**
Kiran Patil21659032015-09-30 14:09:03 -04001649 * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
1650 * @vsi: pointer to vsi struct
1651 * @from: Pointer to list which contains MAC filter entries - changes to
1652 * those entries needs to be undone.
1653 *
1654 * MAC filter entries from list were slated to be removed from device.
1655 **/
1656static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
1657 struct list_head *from)
1658{
1659 struct i40e_mac_filter *f, *ftmp;
1660
1661 list_for_each_entry_safe(f, ftmp, from, list) {
Kiran Patil21659032015-09-30 14:09:03 -04001662 /* Move the element back into MAC filter list*/
1663 list_move_tail(&f->list, &vsi->mac_filter_list);
1664 }
1665}
1666
1667/**
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001668 * i40e_update_filter_state - Update filter state based on return data
1669 * from firmware
1670 * @count: Number of filters added
1671 * @add_list: return data from fw
1672 * @head: pointer to first filter in current batch
1673 * @aq_err: status from fw
Kiran Patil21659032015-09-30 14:09:03 -04001674 *
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001675 * MAC filter entries from list were slated to be added to device. Returns
1676 * number of successful filters. Note that 0 does NOT mean success!
Kiran Patil21659032015-09-30 14:09:03 -04001677 **/
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001678static int
1679i40e_update_filter_state(int count,
1680 struct i40e_aqc_add_macvlan_element_data *add_list,
1681 struct i40e_mac_filter *add_head, int aq_err)
Kiran Patil21659032015-09-30 14:09:03 -04001682{
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001683 int retval = 0;
1684 int i;
Kiran Patil21659032015-09-30 14:09:03 -04001685
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001686
1687 if (!aq_err) {
1688 retval = count;
1689 /* Everything's good, mark all filters active. */
1690 for (i = 0; i < count ; i++) {
1691 add_head->state = I40E_FILTER_ACTIVE;
1692 add_head = list_next_entry(add_head, list);
1693 }
1694 } else if (aq_err == I40E_AQ_RC_ENOSPC) {
1695 /* Device ran out of filter space. Check the return value
1696 * for each filter to see which ones are active.
1697 */
1698 for (i = 0; i < count ; i++) {
1699 if (add_list[i].match_method ==
1700 I40E_AQC_MM_ERR_NO_RES) {
1701 add_head->state = I40E_FILTER_FAILED;
1702 } else {
1703 add_head->state = I40E_FILTER_ACTIVE;
1704 retval++;
1705 }
1706 add_head = list_next_entry(add_head, list);
1707 }
1708 } else {
1709 /* Some other horrible thing happened, fail all filters */
1710 retval = 0;
1711 for (i = 0; i < count ; i++) {
1712 add_head->state = I40E_FILTER_FAILED;
1713 add_head = list_next_entry(add_head, list);
1714 }
Kiran Patil21659032015-09-30 14:09:03 -04001715 }
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001716 return retval;
Kiran Patil21659032015-09-30 14:09:03 -04001717}
1718
1719/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001720 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1721 * @vsi: ptr to the VSI
1722 *
1723 * Push any outstanding VSI filter changes through the AdminQ.
1724 *
1725 * Returns 0 or error value
1726 **/
Jesse Brandeburg17652c62015-11-05 17:01:02 -08001727int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001728{
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001729 struct i40e_mac_filter *f, *ftmp, *add_head = NULL;
1730 struct list_head tmp_add_list, tmp_del_list;
Mitch Williams3e25a8f2016-05-16 10:26:32 -07001731 struct i40e_hw *hw = &vsi->back->hw;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001732 bool promisc_changed = false;
Shannon Nelson2d1de822016-05-16 10:26:44 -07001733 char vsi_name[16] = "PF";
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001734 int filter_list_len = 0;
1735 u32 changed_flags = 0;
Mitch Williamsea02e902015-11-09 15:35:50 -08001736 i40e_status aq_ret = 0;
Mitch Williamsea02e902015-11-09 15:35:50 -08001737 int retval = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001738 struct i40e_pf *pf;
1739 int num_add = 0;
1740 int num_del = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001741 int aq_err = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001742 u16 cmd_flags;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001743 int list_size;
1744 int fcnt;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001745
1746 /* empty array typed pointers, kcalloc later */
1747 struct i40e_aqc_add_macvlan_element_data *add_list;
1748 struct i40e_aqc_remove_macvlan_element_data *del_list;
1749
1750 while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
1751 usleep_range(1000, 2000);
1752 pf = vsi->back;
1753
1754 if (vsi->netdev) {
1755 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
1756 vsi->current_netdev_flags = vsi->netdev->flags;
1757 }
1758
Kiran Patil21659032015-09-30 14:09:03 -04001759 INIT_LIST_HEAD(&tmp_add_list);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001760 INIT_LIST_HEAD(&tmp_del_list);
Kiran Patil21659032015-09-30 14:09:03 -04001761
Shannon Nelson2d1de822016-05-16 10:26:44 -07001762 if (vsi->type == I40E_VSI_SRIOV)
1763 snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
1764 else if (vsi->type != I40E_VSI_MAIN)
1765 snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
1766
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001767 if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
1768 vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
1769
Kiran Patil21659032015-09-30 14:09:03 -04001770 spin_lock_bh(&vsi->mac_filter_list_lock);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001771 /* Create a list of filters to delete. */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001772 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001773 if (f->state == I40E_FILTER_REMOVE) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001774 /* Move the element into temporary del_list */
1775 list_move_tail(&f->list, &tmp_del_list);
1776 vsi->active_filters--;
Kiran Patil21659032015-09-30 14:09:03 -04001777 }
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001778 if (f->state == I40E_FILTER_NEW) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001779 /* Move the element into temporary add_list */
1780 list_move_tail(&f->list, &tmp_add_list);
1781 }
Kiran Patil21659032015-09-30 14:09:03 -04001782 }
1783 spin_unlock_bh(&vsi->mac_filter_list_lock);
Kiran Patil21659032015-09-30 14:09:03 -04001784 }
1785
1786 /* Now process 'del_list' outside the lock */
1787 if (!list_empty(&tmp_del_list)) {
Mitch Williams3e25a8f2016-05-16 10:26:32 -07001788 filter_list_len = hw->aq.asq_buf_size /
Kiran Patil21659032015-09-30 14:09:03 -04001789 sizeof(struct i40e_aqc_remove_macvlan_element_data);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001790 list_size = filter_list_len *
Shannon Nelsonf1199992015-11-19 11:34:23 -08001791 sizeof(struct i40e_aqc_remove_macvlan_element_data);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001792 del_list = kzalloc(list_size, GFP_ATOMIC);
Kiran Patil21659032015-09-30 14:09:03 -04001793 if (!del_list) {
Kiran Patil21659032015-09-30 14:09:03 -04001794 /* Undo VSI's MAC filter entry element updates */
1795 spin_lock_bh(&vsi->mac_filter_list_lock);
1796 i40e_undo_del_filter_entries(vsi, &tmp_del_list);
Kiran Patil21659032015-09-30 14:09:03 -04001797 spin_unlock_bh(&vsi->mac_filter_list_lock);
Mitch Williamsea02e902015-11-09 15:35:50 -08001798 retval = -ENOMEM;
1799 goto out;
Kiran Patil21659032015-09-30 14:09:03 -04001800 }
1801
1802 list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001803 cmd_flags = 0;
1804
1805 /* add to delete list */
Greg Rose9a173902014-05-22 06:32:02 +00001806 ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001807 if (f->vlan == I40E_VLAN_ANY) {
1808 del_list[num_del].vlan_tag = 0;
Alan Bradya6cb9142016-09-06 18:05:07 -07001809 cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001810 } else {
1811 del_list[num_del].vlan_tag =
1812 cpu_to_le16((u16)(f->vlan));
1813 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001814
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001815 cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
1816 del_list[num_del].flags = cmd_flags;
1817 num_del++;
1818
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001819 /* flush a full buffer */
1820 if (num_del == filter_list_len) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001821 aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid,
1822 del_list,
1823 num_del, NULL);
Mitch Williams3e25a8f2016-05-16 10:26:32 -07001824 aq_err = hw->aq.asq_last_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001825 num_del = 0;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001826 memset(del_list, 0, list_size);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001827
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001828 /* Explicitly ignore and do not report when
1829 * firmware returns ENOENT.
1830 */
1831 if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
Mitch Williamsea02e902015-11-09 15:35:50 -08001832 retval = -EIO;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001833 dev_info(&pf->pdev->dev,
1834 "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
Shannon Nelson2d1de822016-05-16 10:26:44 -07001835 vsi_name,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07001836 i40e_stat_str(hw, aq_ret),
1837 i40e_aq_str(hw, aq_err));
Mitch Williamsea02e902015-11-09 15:35:50 -08001838 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001839 }
Kiran Patil21659032015-09-30 14:09:03 -04001840 /* Release memory for MAC filter entries which were
1841 * synced up with HW.
1842 */
1843 list_del(&f->list);
1844 kfree(f);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001845 }
Kiran Patil21659032015-09-30 14:09:03 -04001846
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001847 if (num_del) {
Mitch Williams3e25a8f2016-05-16 10:26:32 -07001848 aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, del_list,
1849 num_del, NULL);
1850 aq_err = hw->aq.asq_last_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001851 num_del = 0;
1852
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001853 /* Explicitly ignore and do not report when firmware
1854 * returns ENOENT.
1855 */
1856 if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
1857 retval = -EIO;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001858 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07001859 "ignoring delete macvlan error on %s, err %s aq_err %s\n",
1860 vsi_name,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07001861 i40e_stat_str(hw, aq_ret),
1862 i40e_aq_str(hw, aq_err));
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001863 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001864 }
1865
1866 kfree(del_list);
1867 del_list = NULL;
Kiran Patil21659032015-09-30 14:09:03 -04001868 }
1869
1870 if (!list_empty(&tmp_add_list)) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001871 /* Do all the adds now. */
Mitch Williams3e25a8f2016-05-16 10:26:32 -07001872 filter_list_len = hw->aq.asq_buf_size /
Shannon Nelsonf1199992015-11-19 11:34:23 -08001873 sizeof(struct i40e_aqc_add_macvlan_element_data);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001874 list_size = filter_list_len *
1875 sizeof(struct i40e_aqc_add_macvlan_element_data);
1876 add_list = kzalloc(list_size, GFP_ATOMIC);
Kiran Patil21659032015-09-30 14:09:03 -04001877 if (!add_list) {
Mitch Williamsea02e902015-11-09 15:35:50 -08001878 retval = -ENOMEM;
1879 goto out;
Kiran Patil21659032015-09-30 14:09:03 -04001880 }
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001881 num_add = 0;
1882 list_for_each_entry(f, &tmp_add_list, list) {
1883 if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
1884 &vsi->state)) {
1885 f->state = I40E_FILTER_FAILED;
1886 continue;
1887 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001888 /* add to add array */
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001889 if (num_add == 0)
1890 add_head = f;
1891 cmd_flags = 0;
Greg Rose9a173902014-05-22 06:32:02 +00001892 ether_addr_copy(add_list[num_add].mac_addr, f->macaddr);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001893 if (f->vlan == I40E_VLAN_ANY) {
1894 add_list[num_add].vlan_tag = 0;
1895 cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
1896 } else {
1897 add_list[num_add].vlan_tag =
1898 cpu_to_le16((u16)(f->vlan));
1899 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001900 add_list[num_add].queue_number = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001901 cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001902 add_list[num_add].flags = cpu_to_le16(cmd_flags);
1903 num_add++;
1904
1905 /* flush a full buffer */
1906 if (num_add == filter_list_len) {
Mitch Williams3e25a8f2016-05-16 10:26:32 -07001907 aq_ret = i40e_aq_add_macvlan(hw, vsi->seid,
Mitch Williamsea02e902015-11-09 15:35:50 -08001908 add_list, num_add,
1909 NULL);
Mitch Williams3e25a8f2016-05-16 10:26:32 -07001910 aq_err = hw->aq.asq_last_status;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001911 fcnt = i40e_update_filter_state(num_add,
1912 add_list,
1913 add_head,
1914 aq_ret);
1915 vsi->active_filters += fcnt;
1916
1917 if (fcnt != num_add) {
1918 promisc_changed = true;
1919 set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
1920 &vsi->state);
1921 vsi->promisc_threshold =
1922 (vsi->active_filters * 3) / 4;
1923 dev_warn(&pf->pdev->dev,
1924 "Error %s adding RX filters on %s, promiscuous mode forced on\n",
1925 i40e_aq_str(hw, aq_err),
1926 vsi_name);
1927 }
1928 memset(add_list, 0, list_size);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001929 num_add = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001930 }
1931 }
1932 if (num_add) {
Mitch Williams3e25a8f2016-05-16 10:26:32 -07001933 aq_ret = i40e_aq_add_macvlan(hw, vsi->seid,
Mitch Williamsea02e902015-11-09 15:35:50 -08001934 add_list, num_add, NULL);
Mitch Williams3e25a8f2016-05-16 10:26:32 -07001935 aq_err = hw->aq.asq_last_status;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001936 fcnt = i40e_update_filter_state(num_add, add_list,
1937 add_head, aq_ret);
1938 vsi->active_filters += fcnt;
1939 if (fcnt != num_add) {
1940 promisc_changed = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001941 set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
1942 &vsi->state);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001943 vsi->promisc_threshold =
1944 (vsi->active_filters * 3) / 4;
1945 dev_warn(&pf->pdev->dev,
1946 "Error %s adding RX filters on %s, promiscuous mode forced on\n",
1947 i40e_aq_str(hw, aq_err), vsi_name);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001948 }
1949 }
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001950 /* Now move all of the filters from the temp add list back to
1951 * the VSI's list.
1952 */
1953 spin_lock_bh(&vsi->mac_filter_list_lock);
1954 list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) {
1955 list_move_tail(&f->list, &vsi->mac_filter_list);
1956 }
1957 spin_unlock_bh(&vsi->mac_filter_list_lock);
1958 kfree(add_list);
1959 add_list = NULL;
1960 }
1961
1962 /* Check to see if we can drop out of overflow promiscuous mode. */
1963 if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state) &&
1964 (vsi->active_filters < vsi->promisc_threshold)) {
1965 int failed_count = 0;
1966 /* See if we have any failed filters. We can't drop out of
1967 * promiscuous until these have all been deleted.
1968 */
1969 spin_lock_bh(&vsi->mac_filter_list_lock);
1970 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1971 if (f->state == I40E_FILTER_FAILED)
1972 failed_count++;
1973 }
1974 spin_unlock_bh(&vsi->mac_filter_list_lock);
1975 if (!failed_count) {
1976 dev_info(&pf->pdev->dev,
1977 "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
1978 vsi_name);
1979 clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
1980 promisc_changed = true;
1981 vsi->promisc_threshold = 0;
1982 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001983 }
1984
Anjali Singhai Jaina856b5c2016-04-13 03:08:23 -07001985 /* if the VF is not trusted do not do promisc */
1986 if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
1987 clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
1988 goto out;
1989 }
1990
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001991 /* check for changes in promiscuous modes */
1992 if (changed_flags & IFF_ALLMULTI) {
1993 bool cur_multipromisc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001994
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001995 cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
Mitch Williamsea02e902015-11-09 15:35:50 -08001996 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
1997 vsi->seid,
1998 cur_multipromisc,
1999 NULL);
2000 if (aq_ret) {
2001 retval = i40e_aq_rc_to_posix(aq_ret,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002002 hw->aq.asq_last_status);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002003 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002004 "set multi promisc failed on %s, err %s aq_err %s\n",
2005 vsi_name,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002006 i40e_stat_str(hw, aq_ret),
2007 i40e_aq_str(hw, hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002008 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002009 }
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002010 if ((changed_flags & IFF_PROMISC) ||
2011 (promisc_changed &&
2012 test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002013 bool cur_promisc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002014
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002015 cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
2016 test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2017 &vsi->state));
Anjali Singhai Jain6784ed52016-01-15 14:33:13 -08002018 if ((vsi->type == I40E_VSI_MAIN) &&
2019 (pf->lan_veb != I40E_NO_VEB) &&
2020 !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002021 /* set defport ON for Main VSI instead of true promisc
2022 * this way we will get all unicast/multicast and VLAN
2023 * promisc behavior but will not get VF or VMDq traffic
2024 * replicated on the Main VSI.
2025 */
2026 if (pf->cur_promisc != cur_promisc) {
2027 pf->cur_promisc = cur_promisc;
Mitch Williams5bc16032016-05-16 10:26:43 -07002028 if (cur_promisc)
2029 aq_ret =
2030 i40e_aq_set_default_vsi(hw,
2031 vsi->seid,
2032 NULL);
2033 else
2034 aq_ret =
2035 i40e_aq_clear_default_vsi(hw,
2036 vsi->seid,
2037 NULL);
2038 if (aq_ret) {
2039 retval = i40e_aq_rc_to_posix(aq_ret,
2040 hw->aq.asq_last_status);
2041 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002042 "Set default VSI failed on %s, err %s, aq_err %s\n",
2043 vsi_name,
Mitch Williams5bc16032016-05-16 10:26:43 -07002044 i40e_stat_str(hw, aq_ret),
2045 i40e_aq_str(hw,
2046 hw->aq.asq_last_status));
2047 }
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002048 }
2049 } else {
Mitch Williamsea02e902015-11-09 15:35:50 -08002050 aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002051 hw,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002052 vsi->seid,
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002053 cur_promisc, NULL,
2054 true);
Mitch Williamsea02e902015-11-09 15:35:50 -08002055 if (aq_ret) {
2056 retval =
2057 i40e_aq_rc_to_posix(aq_ret,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002058 hw->aq.asq_last_status);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002059 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002060 "set unicast promisc failed on %s, err %s, aq_err %s\n",
2061 vsi_name,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002062 i40e_stat_str(hw, aq_ret),
2063 i40e_aq_str(hw,
2064 hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002065 }
2066 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002067 hw,
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002068 vsi->seid,
2069 cur_promisc, NULL);
Mitch Williamsea02e902015-11-09 15:35:50 -08002070 if (aq_ret) {
2071 retval =
2072 i40e_aq_rc_to_posix(aq_ret,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002073 hw->aq.asq_last_status);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002074 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002075 "set multicast promisc failed on %s, err %s, aq_err %s\n",
2076 vsi_name,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002077 i40e_stat_str(hw, aq_ret),
2078 i40e_aq_str(hw,
2079 hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002080 }
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002081 }
Mitch Williamsea02e902015-11-09 15:35:50 -08002082 aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
2083 vsi->seid,
2084 cur_promisc, NULL);
2085 if (aq_ret) {
2086 retval = i40e_aq_rc_to_posix(aq_ret,
2087 pf->hw.aq.asq_last_status);
Greg Rose1a103702013-11-28 06:42:39 +00002088 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002089 "set brdcast promisc failed, err %s, aq_err %s\n",
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002090 i40e_stat_str(hw, aq_ret),
2091 i40e_aq_str(hw,
2092 hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002093 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002094 }
Mitch Williamsea02e902015-11-09 15:35:50 -08002095out:
Jesse Brandeburg2818ccd2016-01-13 16:51:38 -08002096 /* if something went wrong then set the changed flag so we try again */
2097 if (retval)
2098 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
2099
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002100 clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
Mitch Williamsea02e902015-11-09 15:35:50 -08002101 return retval;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002102}
2103
2104/**
2105 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2106 * @pf: board private structure
2107 **/
2108static void i40e_sync_filters_subtask(struct i40e_pf *pf)
2109{
2110 int v;
2111
2112 if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
2113 return;
2114 pf->flags &= ~I40E_FLAG_FILTER_SYNC;
2115
Mitch Williams505682c2014-05-20 08:01:37 +00002116 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002117 if (pf->vsi[v] &&
Jesse Brandeburg17652c62015-11-05 17:01:02 -08002118 (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
2119 int ret = i40e_sync_vsi_filters(pf->vsi[v]);
2120
2121 if (ret) {
2122 /* come back and try again later */
2123 pf->flags |= I40E_FLAG_FILTER_SYNC;
2124 break;
2125 }
2126 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002127 }
2128}
2129
2130/**
2131 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2132 * @netdev: network interface device structure
2133 * @new_mtu: new value for maximum frame size
2134 *
2135 * Returns 0 on success, negative on failure
2136 **/
2137static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
2138{
2139 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002140 struct i40e_vsi *vsi = np->vsi;
2141
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002142 netdev_info(netdev, "changing MTU from %d to %d\n",
2143 netdev->mtu, new_mtu);
2144 netdev->mtu = new_mtu;
2145 if (netif_running(netdev))
2146 i40e_vsi_reinit_locked(vsi);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06002147 i40e_notify_client_of_l2_param_changes(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002148 return 0;
2149}
2150
2151/**
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002152 * i40e_ioctl - Access the hwtstamp interface
2153 * @netdev: network interface device structure
2154 * @ifr: interface request data
2155 * @cmd: ioctl command
2156 **/
2157int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2158{
2159 struct i40e_netdev_priv *np = netdev_priv(netdev);
2160 struct i40e_pf *pf = np->vsi->back;
2161
2162 switch (cmd) {
2163 case SIOCGHWTSTAMP:
2164 return i40e_ptp_get_ts_config(pf, ifr);
2165 case SIOCSHWTSTAMP:
2166 return i40e_ptp_set_ts_config(pf, ifr);
2167 default:
2168 return -EOPNOTSUPP;
2169 }
2170}
2171
2172/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002173 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2174 * @vsi: the vsi being adjusted
2175 **/
2176void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
2177{
2178 struct i40e_vsi_context ctxt;
2179 i40e_status ret;
2180
2181 if ((vsi->info.valid_sections &
2182 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2183 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
2184 return; /* already enabled */
2185
2186 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2187 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2188 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
2189
2190 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002191 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002192 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2193 if (ret) {
2194 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002195 "update vlan stripping failed, err %s aq_err %s\n",
2196 i40e_stat_str(&vsi->back->hw, ret),
2197 i40e_aq_str(&vsi->back->hw,
2198 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002199 }
2200}
2201
2202/**
2203 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2204 * @vsi: the vsi being adjusted
2205 **/
2206void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
2207{
2208 struct i40e_vsi_context ctxt;
2209 i40e_status ret;
2210
2211 if ((vsi->info.valid_sections &
2212 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2213 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
2214 I40E_AQ_VSI_PVLAN_EMOD_MASK))
2215 return; /* already disabled */
2216
2217 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2218 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2219 I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
2220
2221 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002222 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002223 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2224 if (ret) {
2225 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002226 "update vlan stripping failed, err %s aq_err %s\n",
2227 i40e_stat_str(&vsi->back->hw, ret),
2228 i40e_aq_str(&vsi->back->hw,
2229 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002230 }
2231}
2232
2233/**
2234 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2235 * @netdev: network interface to be adjusted
2236 * @features: netdev features to test if VLAN offload is enabled or not
2237 **/
2238static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
2239{
2240 struct i40e_netdev_priv *np = netdev_priv(netdev);
2241 struct i40e_vsi *vsi = np->vsi;
2242
2243 if (features & NETIF_F_HW_VLAN_CTAG_RX)
2244 i40e_vlan_stripping_enable(vsi);
2245 else
2246 i40e_vlan_stripping_disable(vsi);
2247}
2248
2249/**
2250 * i40e_vsi_add_vlan - Add vsi membership for given vlan
2251 * @vsi: the vsi being configured
2252 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2253 **/
2254int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
2255{
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002256 struct i40e_mac_filter *f, *ftmp, *add_f;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002257
Kiran Patil21659032015-09-30 14:09:03 -04002258 /* Locked once because all functions invoked below iterates list*/
2259 spin_lock_bh(&vsi->mac_filter_list_lock);
2260
Jacob Keller1bc87e82016-10-05 09:30:31 -07002261 if (vsi->netdev) {
2262 add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002263 if (!add_f) {
2264 dev_info(&vsi->back->pdev->dev,
2265 "Could not add vlan filter %d for %pM\n",
2266 vid, vsi->netdev->dev_addr);
Kiran Patil21659032015-09-30 14:09:03 -04002267 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002268 return -ENOMEM;
2269 }
2270 }
2271
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002272 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
Jacob Keller1bc87e82016-10-05 09:30:31 -07002273 add_f = i40e_add_filter(vsi, f->macaddr, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002274 if (!add_f) {
2275 dev_info(&vsi->back->pdev->dev,
2276 "Could not add vlan filter %d for %pM\n",
2277 vid, f->macaddr);
Kiran Patil21659032015-09-30 14:09:03 -04002278 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002279 return -ENOMEM;
2280 }
2281 }
2282
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002283 /* Now if we add a vlan tag, make sure to check if it is the first
2284 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
2285 * with 0, so we now accept untagged and specified tagged traffic
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002286 * (and not all tags along with untagged)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002287 */
2288 if (vid > 0) {
Jacob Keller1bc87e82016-10-05 09:30:31 -07002289 if (vsi->netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr,
2290 I40E_VLAN_ANY)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002291 i40e_del_filter(vsi, vsi->netdev->dev_addr,
Jacob Keller1bc87e82016-10-05 09:30:31 -07002292 I40E_VLAN_ANY);
2293 add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002294 if (!add_f) {
2295 dev_info(&vsi->back->pdev->dev,
2296 "Could not add filter 0 for %pM\n",
2297 vsi->netdev->dev_addr);
Kiran Patil21659032015-09-30 14:09:03 -04002298 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002299 return -ENOMEM;
2300 }
2301 }
Greg Rose8d82a7c2014-01-13 16:13:04 -08002302 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002303
Greg Rose8d82a7c2014-01-13 16:13:04 -08002304 /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
2305 if (vid > 0 && !vsi->info.pvid) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002306 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
Jacob Keller1bc87e82016-10-05 09:30:31 -07002307 if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY))
Kiran Patil21659032015-09-30 14:09:03 -04002308 continue;
Jacob Keller1bc87e82016-10-05 09:30:31 -07002309 i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY);
2310 add_f = i40e_add_filter(vsi, f->macaddr, 0);
Kiran Patil21659032015-09-30 14:09:03 -04002311 if (!add_f) {
2312 dev_info(&vsi->back->pdev->dev,
2313 "Could not add filter 0 for %pM\n",
2314 f->macaddr);
2315 spin_unlock_bh(&vsi->mac_filter_list_lock);
2316 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002317 }
2318 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002319 }
2320
Kiran Patil21659032015-09-30 14:09:03 -04002321 spin_unlock_bh(&vsi->mac_filter_list_lock);
2322
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002323 /* schedule our worker thread which will take care of
2324 * applying the new filter changes
2325 */
2326 i40e_service_event_schedule(vsi->back);
2327 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002328}
2329
2330/**
2331 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
2332 * @vsi: the vsi being configured
2333 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002334 *
2335 * Return: 0 on success or negative otherwise
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002336 **/
2337int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
2338{
2339 struct net_device *netdev = vsi->netdev;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002340 struct i40e_mac_filter *f, *ftmp, *add_f;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002341 int filter_count = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002342
Kiran Patil21659032015-09-30 14:09:03 -04002343 /* Locked once because all functions invoked below iterates list */
2344 spin_lock_bh(&vsi->mac_filter_list_lock);
2345
Jacob Keller1bc87e82016-10-05 09:30:31 -07002346 if (vsi->netdev)
2347 i40e_del_filter(vsi, netdev->dev_addr, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002348
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002349 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
Jacob Keller1bc87e82016-10-05 09:30:31 -07002350 i40e_del_filter(vsi, f->macaddr, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002351
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002352 /* go through all the filters for this VSI and if there is only
2353 * vid == 0 it means there are no other filters, so vid 0 must
2354 * be replaced with -1. This signifies that we should from now
2355 * on accept any traffic (with any tag present, or untagged)
2356 */
2357 list_for_each_entry(f, &vsi->mac_filter_list, list) {
Jacob Keller1bc87e82016-10-05 09:30:31 -07002358 if (vsi->netdev) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002359 if (f->vlan &&
2360 ether_addr_equal(netdev->dev_addr, f->macaddr))
2361 filter_count++;
2362 }
2363
2364 if (f->vlan)
2365 filter_count++;
2366 }
2367
Jacob Keller1bc87e82016-10-05 09:30:31 -07002368 if (!filter_count && vsi->netdev) {
2369 i40e_del_filter(vsi, netdev->dev_addr, 0);
2370 f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002371 if (!f) {
2372 dev_info(&vsi->back->pdev->dev,
2373 "Could not add filter %d for %pM\n",
2374 I40E_VLAN_ANY, 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 }
2379
2380 if (!filter_count) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002381 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
Jacob Keller1bc87e82016-10-05 09:30:31 -07002382 i40e_del_filter(vsi, f->macaddr, 0);
2383 add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002384 if (!add_f) {
2385 dev_info(&vsi->back->pdev->dev,
2386 "Could not add filter %d for %pM\n",
2387 I40E_VLAN_ANY, f->macaddr);
Kiran Patil21659032015-09-30 14:09:03 -04002388 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002389 return -ENOMEM;
2390 }
2391 }
2392 }
2393
Kiran Patil21659032015-09-30 14:09:03 -04002394 spin_unlock_bh(&vsi->mac_filter_list_lock);
2395
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002396 /* schedule our worker thread which will take care of
2397 * applying the new filter changes
2398 */
2399 i40e_service_event_schedule(vsi->back);
2400 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002401}
2402
2403/**
2404 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2405 * @netdev: network interface to be adjusted
2406 * @vid: vlan id to be added
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002407 *
2408 * net_device_ops implementation for adding vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002409 **/
Vasu Dev38e00432014-08-01 13:27:03 -07002410#ifdef I40E_FCOE
2411int i40e_vlan_rx_add_vid(struct net_device *netdev,
2412 __always_unused __be16 proto, u16 vid)
2413#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002414static int i40e_vlan_rx_add_vid(struct net_device *netdev,
2415 __always_unused __be16 proto, u16 vid)
Vasu Dev38e00432014-08-01 13:27:03 -07002416#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002417{
2418 struct i40e_netdev_priv *np = netdev_priv(netdev);
2419 struct i40e_vsi *vsi = np->vsi;
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002420 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002421
2422 if (vid > 4095)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002423 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002424
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002425 /* If the network stack called us with vid = 0 then
2426 * it is asking to receive priority tagged packets with
2427 * vlan id 0. Our HW receives them by default when configured
2428 * to receive untagged packets so there is no need to add an
2429 * extra filter for vlan 0 tagged packets.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002430 */
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002431 if (vid)
2432 ret = i40e_vsi_add_vlan(vsi, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002433
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002434 if (!ret && (vid < VLAN_N_VID))
2435 set_bit(vid, vsi->active_vlans);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002436
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002437 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002438}
2439
2440/**
2441 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2442 * @netdev: network interface to be adjusted
2443 * @vid: vlan id to be removed
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002444 *
Akeem G Abodunrinfdfd9432014-02-11 08:24:15 +00002445 * net_device_ops implementation for removing vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002446 **/
Vasu Dev38e00432014-08-01 13:27:03 -07002447#ifdef I40E_FCOE
2448int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2449 __always_unused __be16 proto, u16 vid)
2450#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002451static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2452 __always_unused __be16 proto, u16 vid)
Vasu Dev38e00432014-08-01 13:27:03 -07002453#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002454{
2455 struct i40e_netdev_priv *np = netdev_priv(netdev);
2456 struct i40e_vsi *vsi = np->vsi;
2457
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002458 /* return code is ignored as there is nothing a user
2459 * can do about failure to remove and a log message was
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002460 * already printed from the other function
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002461 */
2462 i40e_vsi_kill_vlan(vsi, vid);
2463
2464 clear_bit(vid, vsi->active_vlans);
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002465
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002466 return 0;
2467}
2468
2469/**
Tushar Daveb1b15df2016-07-01 10:11:20 -07002470 * i40e_macaddr_init - explicitly write the mac address filters
2471 *
2472 * @vsi: pointer to the vsi
2473 * @macaddr: the MAC address
2474 *
2475 * This is needed when the macaddr has been obtained by other
2476 * means than the default, e.g., from Open Firmware or IDPROM.
2477 * Returns 0 on success, negative on failure
2478 **/
2479static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr)
2480{
2481 int ret;
2482 struct i40e_aqc_add_macvlan_element_data element;
2483
2484 ret = i40e_aq_mac_address_write(&vsi->back->hw,
2485 I40E_AQC_WRITE_TYPE_LAA_WOL,
2486 macaddr, NULL);
2487 if (ret) {
2488 dev_info(&vsi->back->pdev->dev,
2489 "Addr change for VSI failed: %d\n", ret);
2490 return -EADDRNOTAVAIL;
2491 }
2492
2493 memset(&element, 0, sizeof(element));
2494 ether_addr_copy(element.mac_addr, macaddr);
2495 element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
2496 ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL);
2497 if (ret) {
2498 dev_info(&vsi->back->pdev->dev,
2499 "add filter failed err %s aq_err %s\n",
2500 i40e_stat_str(&vsi->back->hw, ret),
2501 i40e_aq_str(&vsi->back->hw,
2502 vsi->back->hw.aq.asq_last_status));
2503 }
2504 return ret;
2505}
2506
2507/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002508 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2509 * @vsi: the vsi being brought back up
2510 **/
2511static void i40e_restore_vlan(struct i40e_vsi *vsi)
2512{
2513 u16 vid;
2514
2515 if (!vsi->netdev)
2516 return;
2517
2518 i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
2519
2520 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
2521 i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
2522 vid);
2523}
2524
2525/**
2526 * i40e_vsi_add_pvid - Add pvid for the VSI
2527 * @vsi: the vsi being adjusted
2528 * @vid: the vlan id to set as a PVID
2529 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002530int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002531{
2532 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002533 i40e_status ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002534
2535 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2536 vsi->info.pvid = cpu_to_le16(vid);
Greg Rose6c12fcb2013-11-28 06:39:34 +00002537 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
2538 I40E_AQ_VSI_PVLAN_INSERT_PVID |
Greg Roseb774c7d2013-11-28 06:39:44 +00002539 I40E_AQ_VSI_PVLAN_EMOD_STR;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002540
2541 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002542 ctxt.info = vsi->info;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002543 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2544 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002545 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002546 "add pvid failed, err %s aq_err %s\n",
2547 i40e_stat_str(&vsi->back->hw, ret),
2548 i40e_aq_str(&vsi->back->hw,
2549 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002550 return -ENOENT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002551 }
2552
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002553 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002554}
2555
2556/**
2557 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2558 * @vsi: the vsi being adjusted
2559 *
2560 * Just use the vlan_rx_register() service to put it back to normal
2561 **/
2562void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
2563{
Greg Rose6c12fcb2013-11-28 06:39:34 +00002564 i40e_vlan_stripping_disable(vsi);
2565
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002566 vsi->info.pvid = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002567}
2568
2569/**
2570 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2571 * @vsi: ptr to the VSI
2572 *
2573 * If this function returns with an error, then it's possible one or
2574 * more of the rings is populated (while the rest are not). It is the
2575 * callers duty to clean those orphaned rings.
2576 *
2577 * Return 0 on success, negative on failure
2578 **/
2579static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
2580{
2581 int i, err = 0;
2582
2583 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002584 err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002585
2586 return err;
2587}
2588
2589/**
2590 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2591 * @vsi: ptr to the VSI
2592 *
2593 * Free VSI's transmit software resources
2594 **/
2595static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
2596{
2597 int i;
2598
Greg Rose8e9dca52013-12-18 13:45:53 +00002599 if (!vsi->tx_rings)
2600 return;
2601
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002602 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002603 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002604 i40e_free_tx_resources(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002605}
2606
2607/**
2608 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2609 * @vsi: ptr to the VSI
2610 *
2611 * If this function returns with an error, then it's possible one or
2612 * more of the rings is populated (while the rest are not). It is the
2613 * callers duty to clean those orphaned rings.
2614 *
2615 * Return 0 on success, negative on failure
2616 **/
2617static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
2618{
2619 int i, err = 0;
2620
2621 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002622 err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
Vasu Dev38e00432014-08-01 13:27:03 -07002623#ifdef I40E_FCOE
2624 i40e_fcoe_setup_ddp_resources(vsi);
2625#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002626 return err;
2627}
2628
2629/**
2630 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2631 * @vsi: ptr to the VSI
2632 *
2633 * Free all receive software resources
2634 **/
2635static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
2636{
2637 int i;
2638
Greg Rose8e9dca52013-12-18 13:45:53 +00002639 if (!vsi->rx_rings)
2640 return;
2641
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002642 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002643 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002644 i40e_free_rx_resources(vsi->rx_rings[i]);
Vasu Dev38e00432014-08-01 13:27:03 -07002645#ifdef I40E_FCOE
2646 i40e_fcoe_free_ddp_resources(vsi);
2647#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002648}
2649
2650/**
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002651 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
2652 * @ring: The Tx ring to configure
2653 *
2654 * This enables/disables XPS for a given Tx descriptor ring
2655 * based on the TCs enabled for the VSI that ring belongs to.
2656 **/
2657static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
2658{
2659 struct i40e_vsi *vsi = ring->vsi;
2660 cpumask_var_t mask;
2661
Jesse Brandeburg9a660ee2015-02-26 16:13:22 +00002662 if (!ring->q_vector || !ring->netdev)
2663 return;
2664
2665 /* Single TC mode enable XPS */
2666 if (vsi->tc_config.numtc <= 1) {
2667 if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002668 netif_set_xps_queue(ring->netdev,
2669 &ring->q_vector->affinity_mask,
2670 ring->queue_index);
Jesse Brandeburg9a660ee2015-02-26 16:13:22 +00002671 } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) {
2672 /* Disable XPS to allow selection based on TC */
2673 bitmap_zero(cpumask_bits(mask), nr_cpumask_bits);
2674 netif_set_xps_queue(ring->netdev, mask, ring->queue_index);
2675 free_cpumask_var(mask);
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002676 }
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002677
2678 /* schedule our worker thread which will take care of
2679 * applying the new filter changes
2680 */
2681 i40e_service_event_schedule(vsi->back);
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002682}
2683
2684/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002685 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2686 * @ring: The Tx ring to configure
2687 *
2688 * Configure the Tx descriptor ring in the HMC context.
2689 **/
2690static int i40e_configure_tx_ring(struct i40e_ring *ring)
2691{
2692 struct i40e_vsi *vsi = ring->vsi;
2693 u16 pf_q = vsi->base_queue + ring->queue_index;
2694 struct i40e_hw *hw = &vsi->back->hw;
2695 struct i40e_hmc_obj_txq tx_ctx;
2696 i40e_status err = 0;
2697 u32 qtx_ctl = 0;
2698
2699 /* some ATR related tx ring init */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002700 if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002701 ring->atr_sample_rate = vsi->back->atr_sample_rate;
2702 ring->atr_count = 0;
2703 } else {
2704 ring->atr_sample_rate = 0;
2705 }
2706
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002707 /* configure XPS */
2708 i40e_config_xps_tx_ring(ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002709
2710 /* clear the context structure first */
2711 memset(&tx_ctx, 0, sizeof(tx_ctx));
2712
2713 tx_ctx.new_context = 1;
2714 tx_ctx.base = (ring->dma / 128);
2715 tx_ctx.qlen = ring->count;
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002716 tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
2717 I40E_FLAG_FD_ATR_ENABLED));
Vasu Dev38e00432014-08-01 13:27:03 -07002718#ifdef I40E_FCOE
2719 tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
2720#endif
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002721 tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
Jesse Brandeburg1943d8b2014-02-14 02:14:40 +00002722 /* FDIR VSI tx ring can still use RS bit and writebacks */
2723 if (vsi->type != I40E_VSI_FDIR)
2724 tx_ctx.head_wb_ena = 1;
2725 tx_ctx.head_wb_addr = ring->dma +
2726 (ring->count * sizeof(struct i40e_tx_desc));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002727
2728 /* As part of VSI creation/update, FW allocates certain
2729 * Tx arbitration queue sets for each TC enabled for
2730 * the VSI. The FW returns the handles to these queue
2731 * sets as part of the response buffer to Add VSI,
2732 * Update VSI, etc. AQ commands. It is expected that
2733 * these queue set handles be associated with the Tx
2734 * queues by the driver as part of the TX queue context
2735 * initialization. This has to be done regardless of
2736 * DCB as by default everything is mapped to TC0.
2737 */
2738 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
2739 tx_ctx.rdylist_act = 0;
2740
2741 /* clear the context in the HMC */
2742 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2743 if (err) {
2744 dev_info(&vsi->back->pdev->dev,
2745 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2746 ring->queue_index, pf_q, err);
2747 return -ENOMEM;
2748 }
2749
2750 /* set the context in the HMC */
2751 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
2752 if (err) {
2753 dev_info(&vsi->back->pdev->dev,
2754 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2755 ring->queue_index, pf_q, err);
2756 return -ENOMEM;
2757 }
2758
2759 /* Now associate this queue with this PCI function */
Mitch Williams7a28d882014-10-17 03:14:52 +00002760 if (vsi->type == I40E_VSI_VMDQ2) {
Shannon Nelson9d8bf542014-01-14 00:49:50 -08002761 qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
Mitch Williams7a28d882014-10-17 03:14:52 +00002762 qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
2763 I40E_QTX_CTL_VFVM_INDX_MASK;
2764 } else {
Shannon Nelson9d8bf542014-01-14 00:49:50 -08002765 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
Mitch Williams7a28d882014-10-17 03:14:52 +00002766 }
2767
Shannon Nelson13fd9772013-09-28 07:14:19 +00002768 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
2769 I40E_QTX_CTL_PF_INDX_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002770 wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
2771 i40e_flush(hw);
2772
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002773 /* cache tail off for easier writes later */
2774 ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2775
2776 return 0;
2777}
2778
2779/**
2780 * i40e_configure_rx_ring - Configure a receive ring context
2781 * @ring: The Rx ring to configure
2782 *
2783 * Configure the Rx descriptor ring in the HMC context.
2784 **/
2785static int i40e_configure_rx_ring(struct i40e_ring *ring)
2786{
2787 struct i40e_vsi *vsi = ring->vsi;
2788 u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
2789 u16 pf_q = vsi->base_queue + ring->queue_index;
2790 struct i40e_hw *hw = &vsi->back->hw;
2791 struct i40e_hmc_obj_rxq rx_ctx;
2792 i40e_status err = 0;
2793
2794 ring->state = 0;
2795
2796 /* clear the context structure first */
2797 memset(&rx_ctx, 0, sizeof(rx_ctx));
2798
2799 ring->rx_buf_len = vsi->rx_buf_len;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002800
2801 rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002802
2803 rx_ctx.base = (ring->dma / 128);
2804 rx_ctx.qlen = ring->count;
2805
Jesse Brandeburgbec60fc2016-04-18 11:33:47 -07002806 /* use 32 byte descriptors */
2807 rx_ctx.dsize = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002808
Jesse Brandeburgbec60fc2016-04-18 11:33:47 -07002809 /* descriptor type is always zero
2810 * rx_ctx.dtype = 0;
2811 */
Jesse Brandeburgb32bfa172016-04-18 11:33:42 -07002812 rx_ctx.hsplit_0 = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002813
Jesse Brandeburgb32bfa172016-04-18 11:33:42 -07002814 rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00002815 if (hw->revision_id == 0)
2816 rx_ctx.lrxqthresh = 0;
2817 else
2818 rx_ctx.lrxqthresh = 2;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002819 rx_ctx.crcstrip = 1;
2820 rx_ctx.l2tsel = 1;
Jesse Brandeburgc4bbac32015-09-28 11:21:48 -07002821 /* this controls whether VLAN is stripped from inner headers */
2822 rx_ctx.showiv = 0;
Vasu Dev38e00432014-08-01 13:27:03 -07002823#ifdef I40E_FCOE
2824 rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
2825#endif
Catherine Sullivanacb36762014-03-06 09:02:30 +00002826 /* set the prefena field to 1 because the manual says to */
2827 rx_ctx.prefena = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002828
2829 /* clear the context in the HMC */
2830 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
2831 if (err) {
2832 dev_info(&vsi->back->pdev->dev,
2833 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2834 ring->queue_index, pf_q, err);
2835 return -ENOMEM;
2836 }
2837
2838 /* set the context in the HMC */
2839 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
2840 if (err) {
2841 dev_info(&vsi->back->pdev->dev,
2842 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2843 ring->queue_index, pf_q, err);
2844 return -ENOMEM;
2845 }
2846
2847 /* cache tail for quicker writes, and clear the reg before use */
2848 ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
2849 writel(0, ring->tail);
2850
Jesse Brandeburg1a557afc2016-04-20 19:43:37 -07002851 i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002852
2853 return 0;
2854}
2855
2856/**
2857 * i40e_vsi_configure_tx - Configure the VSI for Tx
2858 * @vsi: VSI structure describing this set of rings and resources
2859 *
2860 * Configure the Tx VSI for operation.
2861 **/
2862static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
2863{
2864 int err = 0;
2865 u16 i;
2866
Alexander Duyck9f65e152013-09-28 06:00:58 +00002867 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
2868 err = i40e_configure_tx_ring(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002869
2870 return err;
2871}
2872
2873/**
2874 * i40e_vsi_configure_rx - Configure the VSI for Rx
2875 * @vsi: the VSI being configured
2876 *
2877 * Configure the Rx VSI for operation.
2878 **/
2879static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
2880{
2881 int err = 0;
2882 u16 i;
2883
2884 if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
2885 vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
2886 + ETH_FCS_LEN + VLAN_HLEN;
2887 else
2888 vsi->max_frame = I40E_RXBUFFER_2048;
2889
Jesse Brandeburg1a557afc2016-04-20 19:43:37 -07002890 vsi->rx_buf_len = I40E_RXBUFFER_2048;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002891
Vasu Dev38e00432014-08-01 13:27:03 -07002892#ifdef I40E_FCOE
2893 /* setup rx buffer for FCoE */
2894 if ((vsi->type == I40E_VSI_FCOE) &&
2895 (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) {
Vasu Dev38e00432014-08-01 13:27:03 -07002896 vsi->rx_buf_len = I40E_RXBUFFER_3072;
2897 vsi->max_frame = I40E_RXBUFFER_3072;
Vasu Dev38e00432014-08-01 13:27:03 -07002898 }
2899
2900#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002901 /* round up for the chip's needs */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002902 vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002903 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002904
2905 /* set up individual rings */
2906 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002907 err = i40e_configure_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002908
2909 return err;
2910}
2911
2912/**
2913 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
2914 * @vsi: ptr to the VSI
2915 **/
2916static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
2917{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00002918 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002919 u16 qoffset, qcount;
2920 int i, n;
2921
Parikh, Neeravcd238a32015-02-21 06:43:37 +00002922 if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
2923 /* Reset the TC information */
2924 for (i = 0; i < vsi->num_queue_pairs; i++) {
2925 rx_ring = vsi->rx_rings[i];
2926 tx_ring = vsi->tx_rings[i];
2927 rx_ring->dcb_tc = 0;
2928 tx_ring->dcb_tc = 0;
2929 }
2930 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002931
2932 for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002933 if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002934 continue;
2935
2936 qoffset = vsi->tc_config.tc_info[n].qoffset;
2937 qcount = vsi->tc_config.tc_info[n].qcount;
2938 for (i = qoffset; i < (qoffset + qcount); i++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00002939 rx_ring = vsi->rx_rings[i];
2940 tx_ring = vsi->tx_rings[i];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002941 rx_ring->dcb_tc = n;
2942 tx_ring->dcb_tc = n;
2943 }
2944 }
2945}
2946
2947/**
2948 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
2949 * @vsi: ptr to the VSI
2950 **/
2951static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
2952{
Tushar Daveb1b15df2016-07-01 10:11:20 -07002953 struct i40e_pf *pf = vsi->back;
2954 int err;
2955
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002956 if (vsi->netdev)
2957 i40e_set_rx_mode(vsi->netdev);
Tushar Daveb1b15df2016-07-01 10:11:20 -07002958
2959 if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
2960 err = i40e_macaddr_init(vsi, pf->hw.mac.addr);
2961 if (err) {
2962 dev_warn(&pf->pdev->dev,
2963 "could not set up macaddr; err %d\n", err);
2964 }
2965 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002966}
2967
2968/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002969 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
2970 * @vsi: Pointer to the targeted VSI
2971 *
2972 * This function replays the hlist on the hw where all the SB Flow Director
2973 * filters were saved.
2974 **/
2975static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
2976{
2977 struct i40e_fdir_filter *filter;
2978 struct i40e_pf *pf = vsi->back;
2979 struct hlist_node *node;
2980
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002981 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2982 return;
2983
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002984 hlist_for_each_entry_safe(filter, node,
2985 &pf->fdir_filter_list, fdir_node) {
2986 i40e_add_del_fdir(vsi, filter, true);
2987 }
2988}
2989
2990/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002991 * i40e_vsi_configure - Set up the VSI for action
2992 * @vsi: the VSI being configured
2993 **/
2994static int i40e_vsi_configure(struct i40e_vsi *vsi)
2995{
2996 int err;
2997
2998 i40e_set_vsi_rx_mode(vsi);
2999 i40e_restore_vlan(vsi);
3000 i40e_vsi_config_dcb_rings(vsi);
3001 err = i40e_vsi_configure_tx(vsi);
3002 if (!err)
3003 err = i40e_vsi_configure_rx(vsi);
3004
3005 return err;
3006}
3007
3008/**
3009 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3010 * @vsi: the VSI being configured
3011 **/
3012static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
3013{
3014 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003015 struct i40e_hw *hw = &pf->hw;
3016 u16 vector;
3017 int i, q;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003018 u32 qp;
3019
3020 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3021 * and PFINT_LNKLSTn registers, e.g.:
3022 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3023 */
3024 qp = vsi->base_queue;
3025 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +00003026 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003027 struct i40e_q_vector *q_vector = vsi->q_vectors[i];
3028
Jesse Brandeburgee2319c2015-09-28 14:16:54 -04003029 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Kan Lianga75e8002016-02-19 09:24:04 -05003030 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003031 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3032 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
3033 q_vector->rx.itr);
Kan Lianga75e8002016-02-19 09:24:04 -05003034 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003035 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3036 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
3037 q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003038 wr32(hw, I40E_PFINT_RATEN(vector - 1),
3039 INTRL_USEC_TO_REG(vsi->int_rate_limit));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003040
3041 /* Linked list for the queuepairs assigned to this vector */
3042 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
3043 for (q = 0; q < q_vector->num_ringpairs; q++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003044 u32 val;
3045
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003046 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3047 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3048 (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
3049 (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
3050 (I40E_QUEUE_TYPE_TX
3051 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
3052
3053 wr32(hw, I40E_QINT_RQCTL(qp), val);
3054
3055 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3056 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3057 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
3058 ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
3059 (I40E_QUEUE_TYPE_RX
3060 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3061
3062 /* Terminate the linked list */
3063 if (q == (q_vector->num_ringpairs - 1))
3064 val |= (I40E_QUEUE_END_OF_LIST
3065 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3066
3067 wr32(hw, I40E_QINT_TQCTL(qp), val);
3068 qp++;
3069 }
3070 }
3071
3072 i40e_flush(hw);
3073}
3074
3075/**
3076 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3077 * @hw: ptr to the hardware info
3078 **/
Jacob Kellerab437b52014-12-14 01:55:08 +00003079static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003080{
Jacob Kellerab437b52014-12-14 01:55:08 +00003081 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003082 u32 val;
3083
3084 /* clear things first */
3085 wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
3086 rd32(hw, I40E_PFINT_ICR0); /* read to clear */
3087
3088 val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
3089 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
3090 I40E_PFINT_ICR0_ENA_GRST_MASK |
3091 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
3092 I40E_PFINT_ICR0_ENA_GPIO_MASK |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003093 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
3094 I40E_PFINT_ICR0_ENA_VFLR_MASK |
3095 I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3096
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003097 if (pf->flags & I40E_FLAG_IWARP_ENABLED)
3098 val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3099
Jacob Kellerab437b52014-12-14 01:55:08 +00003100 if (pf->flags & I40E_FLAG_PTP)
3101 val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
3102
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003103 wr32(hw, I40E_PFINT_ICR0_ENA, val);
3104
3105 /* SW_ITR_IDX = 0, but don't change INTENA */
Anjali Singhai Jain84ed40e2013-11-26 10:49:32 +00003106 wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
3107 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003108
3109 /* OTHER_ITR_IDX = 0 */
3110 wr32(hw, I40E_PFINT_STAT_CTL0, 0);
3111}
3112
3113/**
3114 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3115 * @vsi: the VSI being configured
3116 **/
3117static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
3118{
Alexander Duyck493fb302013-09-28 07:01:44 +00003119 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003120 struct i40e_pf *pf = vsi->back;
3121 struct i40e_hw *hw = &pf->hw;
3122 u32 val;
3123
3124 /* set the ITR configuration */
Jesse Brandeburgee2319c2015-09-28 14:16:54 -04003125 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Kan Lianga75e8002016-02-19 09:24:04 -05003126 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003127 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3128 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
Kan Lianga75e8002016-02-19 09:24:04 -05003129 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003130 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3131 wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
3132
Jacob Kellerab437b52014-12-14 01:55:08 +00003133 i40e_enable_misc_int_causes(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003134
3135 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3136 wr32(hw, I40E_PFINT_LNKLST0, 0);
3137
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00003138 /* Associate the queue pair to the vector and enable the queue int */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003139 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3140 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3141 (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3142
3143 wr32(hw, I40E_QINT_RQCTL(0), val);
3144
3145 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3146 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3147 (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3148
3149 wr32(hw, I40E_QINT_TQCTL(0), val);
3150 i40e_flush(hw);
3151}
3152
3153/**
Mitch Williams2ef28cf2013-11-28 06:39:32 +00003154 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3155 * @pf: board private structure
3156 **/
3157void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
3158{
3159 struct i40e_hw *hw = &pf->hw;
3160
3161 wr32(hw, I40E_PFINT_DYN_CTL0,
3162 I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
3163 i40e_flush(hw);
3164}
3165
3166/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003167 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3168 * @pf: board private structure
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003169 * @clearpba: true when all pending interrupt events should be cleared
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003170 **/
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003171void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003172{
3173 struct i40e_hw *hw = &pf->hw;
3174 u32 val;
3175
3176 val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003177 (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003178 (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
3179
3180 wr32(hw, I40E_PFINT_DYN_CTL0, val);
3181 i40e_flush(hw);
3182}
3183
3184/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003185 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3186 * @irq: interrupt number
3187 * @data: pointer to a q_vector
3188 **/
3189static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
3190{
3191 struct i40e_q_vector *q_vector = data;
3192
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003193 if (!q_vector->tx.ring && !q_vector->rx.ring)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003194 return IRQ_HANDLED;
3195
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003196 napi_schedule_irqoff(&q_vector->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003197
3198 return IRQ_HANDLED;
3199}
3200
3201/**
Alan Brady96db7762016-09-14 16:24:38 -07003202 * i40e_irq_affinity_notify - Callback for affinity changes
3203 * @notify: context as to what irq was changed
3204 * @mask: the new affinity mask
3205 *
3206 * This is a callback function used by the irq_set_affinity_notifier function
3207 * so that we may register to receive changes to the irq affinity masks.
3208 **/
3209static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
3210 const cpumask_t *mask)
3211{
3212 struct i40e_q_vector *q_vector =
3213 container_of(notify, struct i40e_q_vector, affinity_notify);
3214
3215 q_vector->affinity_mask = *mask;
3216}
3217
3218/**
3219 * i40e_irq_affinity_release - Callback for affinity notifier release
3220 * @ref: internal core kernel usage
3221 *
3222 * This is a callback function used by the irq_set_affinity_notifier function
3223 * to inform the current notification subscriber that they will no longer
3224 * receive notifications.
3225 **/
3226static void i40e_irq_affinity_release(struct kref *ref) {}
3227
3228/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003229 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3230 * @vsi: the VSI being configured
3231 * @basename: name for the vector
3232 *
3233 * Allocates MSI-X vectors and requests interrupts from the kernel.
3234 **/
3235static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
3236{
3237 int q_vectors = vsi->num_q_vectors;
3238 struct i40e_pf *pf = vsi->back;
3239 int base = vsi->base_vector;
3240 int rx_int_idx = 0;
3241 int tx_int_idx = 0;
3242 int vector, err;
Alan Brady96db7762016-09-14 16:24:38 -07003243 int irq_num;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003244
3245 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck493fb302013-09-28 07:01:44 +00003246 struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003247
Alan Brady96db7762016-09-14 16:24:38 -07003248 irq_num = pf->msix_entries[base + vector].vector;
3249
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003250 if (q_vector->tx.ring && q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003251 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3252 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
3253 tx_int_idx++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003254 } else if (q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003255 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3256 "%s-%s-%d", basename, "rx", rx_int_idx++);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003257 } else if (q_vector->tx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003258 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3259 "%s-%s-%d", basename, "tx", tx_int_idx++);
3260 } else {
3261 /* skip this unused q_vector */
3262 continue;
3263 }
Alan Brady96db7762016-09-14 16:24:38 -07003264 err = request_irq(irq_num,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003265 vsi->irq_handler,
3266 0,
3267 q_vector->name,
3268 q_vector);
3269 if (err) {
3270 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003271 "MSIX request_irq failed, error: %d\n", err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003272 goto free_queue_irqs;
3273 }
Alan Brady96db7762016-09-14 16:24:38 -07003274
3275 /* register for affinity change notifications */
3276 q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
3277 q_vector->affinity_notify.release = i40e_irq_affinity_release;
3278 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003279 /* assign the mask for this irq */
Alan Brady96db7762016-09-14 16:24:38 -07003280 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003281 }
3282
Shannon Nelson63741842014-04-23 04:50:16 +00003283 vsi->irqs_ready = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003284 return 0;
3285
3286free_queue_irqs:
3287 while (vector) {
3288 vector--;
Alan Brady96db7762016-09-14 16:24:38 -07003289 irq_num = pf->msix_entries[base + vector].vector;
3290 irq_set_affinity_notifier(irq_num, NULL);
3291 irq_set_affinity_hint(irq_num, NULL);
3292 free_irq(irq_num, &vsi->q_vectors[vector]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003293 }
3294 return err;
3295}
3296
3297/**
3298 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3299 * @vsi: the VSI being un-configured
3300 **/
3301static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
3302{
3303 struct i40e_pf *pf = vsi->back;
3304 struct i40e_hw *hw = &pf->hw;
3305 int base = vsi->base_vector;
3306 int i;
3307
3308 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00003309 wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
3310 wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003311 }
3312
3313 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3314 for (i = vsi->base_vector;
3315 i < (vsi->num_q_vectors + vsi->base_vector); i++)
3316 wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
3317
3318 i40e_flush(hw);
3319 for (i = 0; i < vsi->num_q_vectors; i++)
3320 synchronize_irq(pf->msix_entries[i + base].vector);
3321 } else {
3322 /* Legacy and MSI mode - this stops all interrupt handling */
3323 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
3324 wr32(hw, I40E_PFINT_DYN_CTL0, 0);
3325 i40e_flush(hw);
3326 synchronize_irq(pf->pdev->irq);
3327 }
3328}
3329
3330/**
3331 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3332 * @vsi: the VSI being configured
3333 **/
3334static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
3335{
3336 struct i40e_pf *pf = vsi->back;
3337 int i;
3338
3339 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
Jesse Brandeburg78455482015-07-23 16:54:41 -04003340 for (i = 0; i < vsi->num_q_vectors; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003341 i40e_irq_dynamic_enable(vsi, i);
3342 } else {
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003343 i40e_irq_dynamic_enable_icr0(pf, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003344 }
3345
Jesse Brandeburg1022cb62013-09-28 07:13:08 +00003346 i40e_flush(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003347 return 0;
3348}
3349
3350/**
3351 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3352 * @pf: board private structure
3353 **/
3354static void i40e_stop_misc_vector(struct i40e_pf *pf)
3355{
3356 /* Disable ICR 0 */
3357 wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
3358 i40e_flush(&pf->hw);
3359}
3360
3361/**
3362 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3363 * @irq: interrupt number
3364 * @data: pointer to a q_vector
3365 *
3366 * This is the handler used for all MSI/Legacy interrupts, and deals
3367 * with both queue and non-queue interrupts. This is also used in
3368 * MSIX mode to handle the non-queue interrupts.
3369 **/
3370static irqreturn_t i40e_intr(int irq, void *data)
3371{
3372 struct i40e_pf *pf = (struct i40e_pf *)data;
3373 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003374 irqreturn_t ret = IRQ_NONE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003375 u32 icr0, icr0_remaining;
3376 u32 val, ena_mask;
3377
3378 icr0 = rd32(hw, I40E_PFINT_ICR0);
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003379 ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003380
Shannon Nelson116a57d2013-09-28 07:13:59 +00003381 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3382 if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003383 goto enable_intr;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003384
Shannon Nelsoncd92e722013-11-16 10:00:44 +00003385 /* if interrupt but no bits showing, must be SWINT */
3386 if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
3387 (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
3388 pf->sw_int_count++;
3389
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003390 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
3391 (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
3392 ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3393 icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3394 dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n");
3395 }
3396
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003397 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3398 if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003399 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
3400 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003401
Anjali Singhai Jaina16ae2d2016-01-15 14:33:16 -08003402 /* We do not have a way to disarm Queue causes while leaving
3403 * interrupt enabled for all other causes, ideally
3404 * interrupt should be disabled while we are in NAPI but
3405 * this is not a performance path and napi_schedule()
3406 * can deal with rescheduling.
3407 */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003408 if (!test_bit(__I40E_DOWN, &pf->state))
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003409 napi_schedule_irqoff(&q_vector->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003410 }
3411
3412 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
3413 ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3414 set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08003415 i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003416 }
3417
3418 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
3419 ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
3420 set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
3421 }
3422
3423 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
3424 ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
3425 set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
3426 }
3427
3428 if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
3429 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
3430 set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
3431 ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
3432 val = rd32(hw, I40E_GLGEN_RSTAT);
3433 val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
3434 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003435 if (val == I40E_RESET_CORER) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003436 pf->corer_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003437 } else if (val == I40E_RESET_GLOBR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003438 pf->globr_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003439 } else if (val == I40E_RESET_EMPR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003440 pf->empr_count++;
Anjali Singhai Jain9df42d12015-01-24 09:58:40 +00003441 set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003442 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003443 }
3444
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003445 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
3446 icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
3447 dev_info(&pf->pdev->dev, "HMC error interrupt\n");
Anjali Singhai Jain25fc0e62015-03-31 00:45:01 -07003448 dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
3449 rd32(hw, I40E_PFHMC_ERRORINFO),
3450 rd32(hw, I40E_PFHMC_ERRORDATA));
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003451 }
3452
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003453 if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
3454 u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
3455
3456 if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
Jacob Kellercafa1fc2014-04-24 18:05:03 -07003457 icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003458 i40e_ptp_tx_hwtstamp(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003459 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003460 }
3461
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003462 /* If a critical error is pending we have no choice but to reset the
3463 * device.
3464 * Report and mask out any remaining unexpected interrupts.
3465 */
3466 icr0_remaining = icr0 & ena_mask;
3467 if (icr0_remaining) {
3468 dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
3469 icr0_remaining);
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003470 if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003471 (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
Anjali Singhai Jainc0c28972014-02-12 01:45:34 +00003472 (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003473 dev_info(&pf->pdev->dev, "device will be reset\n");
3474 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
3475 i40e_service_event_schedule(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003476 }
3477 ena_mask &= ~icr0_remaining;
3478 }
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003479 ret = IRQ_HANDLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003480
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003481enable_intr:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003482 /* re-enable interrupt causes */
3483 wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003484 if (!test_bit(__I40E_DOWN, &pf->state)) {
3485 i40e_service_event_schedule(pf);
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003486 i40e_irq_dynamic_enable_icr0(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003487 }
3488
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003489 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003490}
3491
3492/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003493 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3494 * @tx_ring: tx ring to clean
3495 * @budget: how many cleans we're allowed
3496 *
3497 * Returns true if there's any budget left (e.g. the clean is finished)
3498 **/
3499static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
3500{
3501 struct i40e_vsi *vsi = tx_ring->vsi;
3502 u16 i = tx_ring->next_to_clean;
3503 struct i40e_tx_buffer *tx_buf;
3504 struct i40e_tx_desc *tx_desc;
3505
3506 tx_buf = &tx_ring->tx_bi[i];
3507 tx_desc = I40E_TX_DESC(tx_ring, i);
3508 i -= tx_ring->count;
3509
3510 do {
3511 struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
3512
3513 /* if next_to_watch is not set then there is no work pending */
3514 if (!eop_desc)
3515 break;
3516
3517 /* prevent any other reads prior to eop_desc */
3518 read_barrier_depends();
3519
3520 /* if the descriptor isn't done, no work yet to do */
3521 if (!(eop_desc->cmd_type_offset_bsz &
3522 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
3523 break;
3524
3525 /* clear next_to_watch to prevent false hangs */
3526 tx_buf->next_to_watch = NULL;
3527
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003528 tx_desc->buffer_addr = 0;
3529 tx_desc->cmd_type_offset_bsz = 0;
3530 /* move past filter desc */
3531 tx_buf++;
3532 tx_desc++;
3533 i++;
3534 if (unlikely(!i)) {
3535 i -= tx_ring->count;
3536 tx_buf = tx_ring->tx_bi;
3537 tx_desc = I40E_TX_DESC(tx_ring, 0);
3538 }
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003539 /* unmap skb header data */
3540 dma_unmap_single(tx_ring->dev,
3541 dma_unmap_addr(tx_buf, dma),
3542 dma_unmap_len(tx_buf, len),
3543 DMA_TO_DEVICE);
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003544 if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
3545 kfree(tx_buf->raw_buf);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003546
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003547 tx_buf->raw_buf = NULL;
3548 tx_buf->tx_flags = 0;
3549 tx_buf->next_to_watch = NULL;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003550 dma_unmap_len_set(tx_buf, len, 0);
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003551 tx_desc->buffer_addr = 0;
3552 tx_desc->cmd_type_offset_bsz = 0;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003553
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003554 /* move us past the eop_desc for start of next FD desc */
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003555 tx_buf++;
3556 tx_desc++;
3557 i++;
3558 if (unlikely(!i)) {
3559 i -= tx_ring->count;
3560 tx_buf = tx_ring->tx_bi;
3561 tx_desc = I40E_TX_DESC(tx_ring, 0);
3562 }
3563
3564 /* update budget accounting */
3565 budget--;
3566 } while (likely(budget));
3567
3568 i += tx_ring->count;
3569 tx_ring->next_to_clean = i;
3570
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003571 if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
Jesse Brandeburg78455482015-07-23 16:54:41 -04003572 i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003573
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003574 return budget > 0;
3575}
3576
3577/**
3578 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3579 * @irq: interrupt number
3580 * @data: pointer to a q_vector
3581 **/
3582static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
3583{
3584 struct i40e_q_vector *q_vector = data;
3585 struct i40e_vsi *vsi;
3586
3587 if (!q_vector->tx.ring)
3588 return IRQ_HANDLED;
3589
3590 vsi = q_vector->tx.ring->vsi;
3591 i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
3592
3593 return IRQ_HANDLED;
3594}
3595
3596/**
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003597 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003598 * @vsi: the VSI being configured
3599 * @v_idx: vector index
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003600 * @qp_idx: queue pair index
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003601 **/
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04003602static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003603{
Alexander Duyck493fb302013-09-28 07:01:44 +00003604 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyck9f65e152013-09-28 06:00:58 +00003605 struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
3606 struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003607
3608 tx_ring->q_vector = q_vector;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003609 tx_ring->next = q_vector->tx.ring;
3610 q_vector->tx.ring = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003611 q_vector->tx.count++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003612
3613 rx_ring->q_vector = q_vector;
3614 rx_ring->next = q_vector->rx.ring;
3615 q_vector->rx.ring = rx_ring;
3616 q_vector->rx.count++;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003617}
3618
3619/**
3620 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3621 * @vsi: the VSI being configured
3622 *
3623 * This function maps descriptor rings to the queue-specific vectors
3624 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3625 * one vector per queue pair, but on a constrained vector budget, we
3626 * group the queue pairs as "efficiently" as possible.
3627 **/
3628static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
3629{
3630 int qp_remaining = vsi->num_queue_pairs;
3631 int q_vectors = vsi->num_q_vectors;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003632 int num_ringpairs;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003633 int v_start = 0;
3634 int qp_idx = 0;
3635
3636 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3637 * group them so there are multiple queues per vector.
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003638 * It is also important to go through all the vectors available to be
3639 * sure that if we don't use all the vectors, that the remaining vectors
3640 * are cleared. This is especially important when decreasing the
3641 * number of queues in use.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003642 */
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003643 for (; v_start < q_vectors; v_start++) {
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003644 struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
3645
3646 num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
3647
3648 q_vector->num_ringpairs = num_ringpairs;
3649
3650 q_vector->rx.count = 0;
3651 q_vector->tx.count = 0;
3652 q_vector->rx.ring = NULL;
3653 q_vector->tx.ring = NULL;
3654
3655 while (num_ringpairs--) {
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04003656 i40e_map_vector_to_qp(vsi, v_start, qp_idx);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003657 qp_idx++;
3658 qp_remaining--;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003659 }
3660 }
3661}
3662
3663/**
3664 * i40e_vsi_request_irq - Request IRQ from the OS
3665 * @vsi: the VSI being configured
3666 * @basename: name for the vector
3667 **/
3668static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
3669{
3670 struct i40e_pf *pf = vsi->back;
3671 int err;
3672
3673 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
3674 err = i40e_vsi_request_irq_msix(vsi, basename);
3675 else if (pf->flags & I40E_FLAG_MSI_ENABLED)
3676 err = request_irq(pf->pdev->irq, i40e_intr, 0,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00003677 pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003678 else
3679 err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00003680 pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003681
3682 if (err)
3683 dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
3684
3685 return err;
3686}
3687
3688#ifdef CONFIG_NET_POLL_CONTROLLER
3689/**
Jesse Brandeburgd89d9672016-01-04 10:33:02 -08003690 * i40e_netpoll - A Polling 'interrupt' handler
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003691 * @netdev: network interface device structure
3692 *
3693 * This is used by netconsole to send skbs without having to re-enable
3694 * interrupts. It's not called while the normal interrupt routine is executing.
3695 **/
Vasu Dev38e00432014-08-01 13:27:03 -07003696#ifdef I40E_FCOE
3697void i40e_netpoll(struct net_device *netdev)
3698#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003699static void i40e_netpoll(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -07003700#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003701{
3702 struct i40e_netdev_priv *np = netdev_priv(netdev);
3703 struct i40e_vsi *vsi = np->vsi;
3704 struct i40e_pf *pf = vsi->back;
3705 int i;
3706
3707 /* if interface is down do nothing */
3708 if (test_bit(__I40E_DOWN, &vsi->state))
3709 return;
3710
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003711 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3712 for (i = 0; i < vsi->num_q_vectors; i++)
Alexander Duyck493fb302013-09-28 07:01:44 +00003713 i40e_msix_clean_rings(0, vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003714 } else {
3715 i40e_intr(pf->pdev->irq, netdev);
3716 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003717}
3718#endif
3719
3720/**
Neerav Parikh23527302014-06-03 23:50:15 +00003721 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3722 * @pf: the PF being configured
3723 * @pf_q: the PF queue
3724 * @enable: enable or disable state of the queue
3725 *
3726 * This routine will wait for the given Tx queue of the PF to reach the
3727 * enabled or disabled state.
3728 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3729 * multiple retries; else will return 0 in case of success.
3730 **/
3731static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3732{
3733 int i;
3734 u32 tx_reg;
3735
3736 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3737 tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
3738 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
3739 break;
3740
Neerav Parikhf98a2002014-09-13 07:40:44 +00003741 usleep_range(10, 20);
Neerav Parikh23527302014-06-03 23:50:15 +00003742 }
3743 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3744 return -ETIMEDOUT;
3745
3746 return 0;
3747}
3748
3749/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003750 * i40e_vsi_control_tx - Start or stop a VSI's rings
3751 * @vsi: the VSI being configured
3752 * @enable: start or stop the rings
3753 **/
3754static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
3755{
3756 struct i40e_pf *pf = vsi->back;
3757 struct i40e_hw *hw = &pf->hw;
Neerav Parikh23527302014-06-03 23:50:15 +00003758 int i, j, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003759 u32 tx_reg;
3760
3761 pf_q = vsi->base_queue;
3762 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Matt Jared351499ab2014-04-23 04:50:03 +00003763
3764 /* warn the TX unit of coming changes */
3765 i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
3766 if (!enable)
Neerav Parikhf98a2002014-09-13 07:40:44 +00003767 usleep_range(10, 20);
Matt Jared351499ab2014-04-23 04:50:03 +00003768
Mitch Williams6c5ef622014-02-20 19:29:16 -08003769 for (j = 0; j < 50; j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003770 tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
Mitch Williams6c5ef622014-02-20 19:29:16 -08003771 if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
3772 ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
3773 break;
3774 usleep_range(1000, 2000);
3775 }
Mitch Williamsfda972f2013-11-28 06:39:29 +00003776 /* Skip if the queue is already in the requested state */
Catherine Sullivan7c122002014-03-14 07:32:29 +00003777 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
Mitch Williamsfda972f2013-11-28 06:39:29 +00003778 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003779
3780 /* turn on/off the queue */
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003781 if (enable) {
3782 wr32(hw, I40E_QTX_HEAD(pf_q), 0);
Mitch Williams6c5ef622014-02-20 19:29:16 -08003783 tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003784 } else {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003785 tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003786 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003787
3788 wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
Neerav Parikh69129dc2014-11-12 00:18:46 +00003789 /* No waiting for the Tx queue to disable */
3790 if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
3791 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003792
3793 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00003794 ret = i40e_pf_txq_wait(pf, pf_q, enable);
3795 if (ret) {
3796 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003797 "VSI seid %d Tx ring %d %sable timeout\n",
3798 vsi->seid, pf_q, (enable ? "en" : "dis"));
Neerav Parikh23527302014-06-03 23:50:15 +00003799 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003800 }
3801 }
3802
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003803 if (hw->revision_id == 0)
3804 mdelay(50);
Neerav Parikh23527302014-06-03 23:50:15 +00003805 return ret;
3806}
3807
3808/**
3809 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
3810 * @pf: the PF being configured
3811 * @pf_q: the PF queue
3812 * @enable: enable or disable state of the queue
3813 *
3814 * This routine will wait for the given Rx queue of the PF to reach the
3815 * enabled or disabled state.
3816 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3817 * multiple retries; else will return 0 in case of success.
3818 **/
3819static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3820{
3821 int i;
3822 u32 rx_reg;
3823
3824 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3825 rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
3826 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
3827 break;
3828
Neerav Parikhf98a2002014-09-13 07:40:44 +00003829 usleep_range(10, 20);
Neerav Parikh23527302014-06-03 23:50:15 +00003830 }
3831 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3832 return -ETIMEDOUT;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003833
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003834 return 0;
3835}
3836
3837/**
3838 * i40e_vsi_control_rx - Start or stop a VSI's rings
3839 * @vsi: the VSI being configured
3840 * @enable: start or stop the rings
3841 **/
3842static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
3843{
3844 struct i40e_pf *pf = vsi->back;
3845 struct i40e_hw *hw = &pf->hw;
Neerav Parikh23527302014-06-03 23:50:15 +00003846 int i, j, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003847 u32 rx_reg;
3848
3849 pf_q = vsi->base_queue;
3850 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Mitch Williams6c5ef622014-02-20 19:29:16 -08003851 for (j = 0; j < 50; j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003852 rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
Mitch Williams6c5ef622014-02-20 19:29:16 -08003853 if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
3854 ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
3855 break;
3856 usleep_range(1000, 2000);
3857 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003858
Catherine Sullivan7c122002014-03-14 07:32:29 +00003859 /* Skip if the queue is already in the requested state */
3860 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
3861 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003862
3863 /* turn on/off the queue */
3864 if (enable)
Mitch Williams6c5ef622014-02-20 19:29:16 -08003865 rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003866 else
Mitch Williams6c5ef622014-02-20 19:29:16 -08003867 rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003868 wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
Neerav Parikh3fe06f42016-02-17 16:12:15 -08003869 /* No waiting for the Tx queue to disable */
3870 if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
3871 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003872
3873 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00003874 ret = i40e_pf_rxq_wait(pf, pf_q, enable);
3875 if (ret) {
3876 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003877 "VSI seid %d Rx ring %d %sable timeout\n",
3878 vsi->seid, pf_q, (enable ? "en" : "dis"));
Neerav Parikh23527302014-06-03 23:50:15 +00003879 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003880 }
3881 }
3882
Neerav Parikh23527302014-06-03 23:50:15 +00003883 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003884}
3885
3886/**
3887 * i40e_vsi_control_rings - Start or stop a VSI's rings
3888 * @vsi: the VSI being configured
3889 * @enable: start or stop the rings
3890 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00003891int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003892{
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00003893 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003894
3895 /* do rx first for enable and last for disable */
3896 if (request) {
3897 ret = i40e_vsi_control_rx(vsi, request);
3898 if (ret)
3899 return ret;
3900 ret = i40e_vsi_control_tx(vsi, request);
3901 } else {
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00003902 /* Ignore return value, we need to shutdown whatever we can */
3903 i40e_vsi_control_tx(vsi, request);
3904 i40e_vsi_control_rx(vsi, request);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003905 }
3906
3907 return ret;
3908}
3909
3910/**
3911 * i40e_vsi_free_irq - Free the irq association with the OS
3912 * @vsi: the VSI being configured
3913 **/
3914static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
3915{
3916 struct i40e_pf *pf = vsi->back;
3917 struct i40e_hw *hw = &pf->hw;
3918 int base = vsi->base_vector;
3919 u32 val, qp;
3920 int i;
3921
3922 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3923 if (!vsi->q_vectors)
3924 return;
3925
Shannon Nelson63741842014-04-23 04:50:16 +00003926 if (!vsi->irqs_ready)
3927 return;
3928
3929 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003930 for (i = 0; i < vsi->num_q_vectors; i++) {
Alan Brady96db7762016-09-14 16:24:38 -07003931 int irq_num;
3932 u16 vector;
3933
3934 vector = i + base;
3935 irq_num = pf->msix_entries[vector].vector;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003936
3937 /* free only the irqs that were actually requested */
Shannon Nelson78681b12013-11-28 06:39:36 +00003938 if (!vsi->q_vectors[i] ||
3939 !vsi->q_vectors[i]->num_ringpairs)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003940 continue;
3941
Alan Brady96db7762016-09-14 16:24:38 -07003942 /* clear the affinity notifier in the IRQ descriptor */
3943 irq_set_affinity_notifier(irq_num, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003944 /* clear the affinity_mask in the IRQ descriptor */
Alan Brady96db7762016-09-14 16:24:38 -07003945 irq_set_affinity_hint(irq_num, NULL);
3946 synchronize_irq(irq_num);
3947 free_irq(irq_num, vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003948
3949 /* Tear down the interrupt queue link list
3950 *
3951 * We know that they come in pairs and always
3952 * the Rx first, then the Tx. To clear the
3953 * link list, stick the EOL value into the
3954 * next_q field of the registers.
3955 */
3956 val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
3957 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
3958 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
3959 val |= I40E_QUEUE_END_OF_LIST
3960 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
3961 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
3962
3963 while (qp != I40E_QUEUE_END_OF_LIST) {
3964 u32 next;
3965
3966 val = rd32(hw, I40E_QINT_RQCTL(qp));
3967
3968 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
3969 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
3970 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3971 I40E_QINT_RQCTL_INTEVENT_MASK);
3972
3973 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
3974 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
3975
3976 wr32(hw, I40E_QINT_RQCTL(qp), val);
3977
3978 val = rd32(hw, I40E_QINT_TQCTL(qp));
3979
3980 next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
3981 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
3982
3983 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
3984 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
3985 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3986 I40E_QINT_TQCTL_INTEVENT_MASK);
3987
3988 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
3989 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
3990
3991 wr32(hw, I40E_QINT_TQCTL(qp), val);
3992 qp = next;
3993 }
3994 }
3995 } else {
3996 free_irq(pf->pdev->irq, pf);
3997
3998 val = rd32(hw, I40E_PFINT_LNKLST0);
3999 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4000 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4001 val |= I40E_QUEUE_END_OF_LIST
4002 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
4003 wr32(hw, I40E_PFINT_LNKLST0, val);
4004
4005 val = rd32(hw, I40E_QINT_RQCTL(qp));
4006 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4007 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4008 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4009 I40E_QINT_RQCTL_INTEVENT_MASK);
4010
4011 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4012 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4013
4014 wr32(hw, I40E_QINT_RQCTL(qp), val);
4015
4016 val = rd32(hw, I40E_QINT_TQCTL(qp));
4017
4018 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4019 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4020 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4021 I40E_QINT_TQCTL_INTEVENT_MASK);
4022
4023 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4024 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4025
4026 wr32(hw, I40E_QINT_TQCTL(qp), val);
4027 }
4028}
4029
4030/**
Alexander Duyck493fb302013-09-28 07:01:44 +00004031 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4032 * @vsi: the VSI being configured
4033 * @v_idx: Index of vector to be freed
4034 *
4035 * This function frees the memory allocated to the q_vector. In addition if
4036 * NAPI is enabled it will delete any references to the NAPI struct prior
4037 * to freeing the q_vector.
4038 **/
4039static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
4040{
4041 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00004042 struct i40e_ring *ring;
Alexander Duyck493fb302013-09-28 07:01:44 +00004043
4044 if (!q_vector)
4045 return;
4046
4047 /* disassociate q_vector from rings */
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00004048 i40e_for_each_ring(ring, q_vector->tx)
4049 ring->q_vector = NULL;
4050
4051 i40e_for_each_ring(ring, q_vector->rx)
4052 ring->q_vector = NULL;
Alexander Duyck493fb302013-09-28 07:01:44 +00004053
4054 /* only VSI w/ an associated netdev is set up w/ NAPI */
4055 if (vsi->netdev)
4056 netif_napi_del(&q_vector->napi);
4057
4058 vsi->q_vectors[v_idx] = NULL;
4059
4060 kfree_rcu(q_vector, rcu);
4061}
4062
4063/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004064 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4065 * @vsi: the VSI being un-configured
4066 *
4067 * This frees the memory allocated to the q_vectors and
4068 * deletes references to the NAPI struct.
4069 **/
4070static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
4071{
4072 int v_idx;
4073
Alexander Duyck493fb302013-09-28 07:01:44 +00004074 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
4075 i40e_free_q_vector(vsi, v_idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004076}
4077
4078/**
4079 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4080 * @pf: board private structure
4081 **/
4082static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
4083{
4084 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4085 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4086 pci_disable_msix(pf->pdev);
4087 kfree(pf->msix_entries);
4088 pf->msix_entries = NULL;
Shannon Nelson3b444392015-02-26 16:15:57 +00004089 kfree(pf->irq_pile);
4090 pf->irq_pile = NULL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004091 } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
4092 pci_disable_msi(pf->pdev);
4093 }
4094 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
4095}
4096
4097/**
4098 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4099 * @pf: board private structure
4100 *
4101 * We go through and clear interrupt specific resources and reset the structure
4102 * to pre-load conditions
4103 **/
4104static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
4105{
4106 int i;
4107
Shannon Nelsone1477582015-02-21 06:44:33 +00004108 i40e_stop_misc_vector(pf);
Shannon Nelson69278392016-03-10 14:59:43 -08004109 if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
Shannon Nelsone1477582015-02-21 06:44:33 +00004110 synchronize_irq(pf->msix_entries[0].vector);
4111 free_irq(pf->msix_entries[0].vector, pf);
4112 }
4113
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06004114 i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
4115 I40E_IWARP_IRQ_PILE_ID);
4116
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004117 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
Mitch Williams505682c2014-05-20 08:01:37 +00004118 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004119 if (pf->vsi[i])
4120 i40e_vsi_free_q_vectors(pf->vsi[i]);
4121 i40e_reset_interrupt_capability(pf);
4122}
4123
4124/**
4125 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4126 * @vsi: the VSI being configured
4127 **/
4128static void i40e_napi_enable_all(struct i40e_vsi *vsi)
4129{
4130 int q_idx;
4131
4132 if (!vsi->netdev)
4133 return;
4134
4135 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
Alexander Duyck493fb302013-09-28 07:01:44 +00004136 napi_enable(&vsi->q_vectors[q_idx]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004137}
4138
4139/**
4140 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4141 * @vsi: the VSI being configured
4142 **/
4143static void i40e_napi_disable_all(struct i40e_vsi *vsi)
4144{
4145 int q_idx;
4146
4147 if (!vsi->netdev)
4148 return;
4149
4150 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
Alexander Duyck493fb302013-09-28 07:01:44 +00004151 napi_disable(&vsi->q_vectors[q_idx]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004152}
4153
4154/**
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004155 * i40e_vsi_close - Shut down a VSI
4156 * @vsi: the vsi to be quelled
4157 **/
4158static void i40e_vsi_close(struct i40e_vsi *vsi)
4159{
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06004160 bool reset = false;
4161
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004162 if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
4163 i40e_down(vsi);
4164 i40e_vsi_free_irq(vsi);
4165 i40e_vsi_free_tx_resources(vsi);
4166 i40e_vsi_free_rx_resources(vsi);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04004167 vsi->current_netdev_flags = 0;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06004168 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
4169 reset = true;
4170 i40e_notify_client_of_netdev_close(vsi, reset);
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004171}
4172
4173/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004174 * i40e_quiesce_vsi - Pause a given VSI
4175 * @vsi: the VSI being paused
4176 **/
4177static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
4178{
4179 if (test_bit(__I40E_DOWN, &vsi->state))
4180 return;
4181
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004182 /* No need to disable FCoE VSI when Tx suspended */
4183 if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) &&
4184 vsi->type == I40E_VSI_FCOE) {
4185 dev_dbg(&vsi->back->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004186 "VSI seid %d skipping FCoE VSI disable\n", vsi->seid);
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004187 return;
4188 }
4189
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004190 set_bit(__I40E_NEEDS_RESTART, &vsi->state);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004191 if (vsi->netdev && netif_running(vsi->netdev))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004192 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004193 else
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004194 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004195}
4196
4197/**
4198 * i40e_unquiesce_vsi - Resume a given VSI
4199 * @vsi: the VSI being resumed
4200 **/
4201static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
4202{
4203 if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
4204 return;
4205
4206 clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
4207 if (vsi->netdev && netif_running(vsi->netdev))
4208 vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
4209 else
Shannon Nelson8276f752014-03-14 07:32:27 +00004210 i40e_vsi_open(vsi); /* this clears the DOWN bit */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004211}
4212
4213/**
4214 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4215 * @pf: the PF
4216 **/
4217static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
4218{
4219 int v;
4220
Mitch Williams505682c2014-05-20 08:01:37 +00004221 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004222 if (pf->vsi[v])
4223 i40e_quiesce_vsi(pf->vsi[v]);
4224 }
4225}
4226
4227/**
4228 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4229 * @pf: the PF
4230 **/
4231static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
4232{
4233 int v;
4234
Mitch Williams505682c2014-05-20 08:01:37 +00004235 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004236 if (pf->vsi[v])
4237 i40e_unquiesce_vsi(pf->vsi[v]);
4238 }
4239}
4240
Neerav Parikh69129dc2014-11-12 00:18:46 +00004241#ifdef CONFIG_I40E_DCB
4242/**
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004243 * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
Neerav Parikh69129dc2014-11-12 00:18:46 +00004244 * @vsi: the VSI being configured
4245 *
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004246 * This function waits for the given VSI's queues to be disabled.
Neerav Parikh69129dc2014-11-12 00:18:46 +00004247 **/
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004248static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
Neerav Parikh69129dc2014-11-12 00:18:46 +00004249{
4250 struct i40e_pf *pf = vsi->back;
4251 int i, pf_q, ret;
4252
4253 pf_q = vsi->base_queue;
4254 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4255 /* Check and wait for the disable status of the queue */
4256 ret = i40e_pf_txq_wait(pf, pf_q, false);
4257 if (ret) {
4258 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004259 "VSI seid %d Tx ring %d disable timeout\n",
4260 vsi->seid, pf_q);
Neerav Parikh69129dc2014-11-12 00:18:46 +00004261 return ret;
4262 }
4263 }
4264
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004265 pf_q = vsi->base_queue;
4266 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4267 /* Check and wait for the disable status of the queue */
4268 ret = i40e_pf_rxq_wait(pf, pf_q, false);
4269 if (ret) {
4270 dev_info(&pf->pdev->dev,
4271 "VSI seid %d Rx ring %d disable timeout\n",
4272 vsi->seid, pf_q);
4273 return ret;
4274 }
4275 }
4276
Neerav Parikh69129dc2014-11-12 00:18:46 +00004277 return 0;
4278}
4279
4280/**
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004281 * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
Neerav Parikh69129dc2014-11-12 00:18:46 +00004282 * @pf: the PF
4283 *
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004284 * This function waits for the queues to be in disabled state for all the
Neerav Parikh69129dc2014-11-12 00:18:46 +00004285 * VSIs that are managed by this PF.
4286 **/
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004287static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
Neerav Parikh69129dc2014-11-12 00:18:46 +00004288{
4289 int v, ret = 0;
4290
4291 for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004292 /* No need to wait for FCoE VSI queues */
4293 if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) {
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004294 ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
Neerav Parikh69129dc2014-11-12 00:18:46 +00004295 if (ret)
4296 break;
4297 }
4298 }
4299
4300 return ret;
4301}
4302
4303#endif
Kiran Patilb03a8c12015-09-24 18:13:15 -04004304
4305/**
4306 * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
4307 * @q_idx: TX queue number
4308 * @vsi: Pointer to VSI struct
4309 *
4310 * This function checks specified queue for given VSI. Detects hung condition.
4311 * Sets hung bit since it is two step process. Before next run of service task
4312 * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not,
4313 * hung condition remain unchanged and during subsequent run, this function
4314 * issues SW interrupt to recover from hung condition.
4315 **/
4316static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
4317{
4318 struct i40e_ring *tx_ring = NULL;
4319 struct i40e_pf *pf;
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004320 u32 head, val, tx_pending_hw;
Kiran Patilb03a8c12015-09-24 18:13:15 -04004321 int i;
4322
4323 pf = vsi->back;
4324
4325 /* now that we have an index, find the tx_ring struct */
4326 for (i = 0; i < vsi->num_queue_pairs; i++) {
4327 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
4328 if (q_idx == vsi->tx_rings[i]->queue_index) {
4329 tx_ring = vsi->tx_rings[i];
4330 break;
4331 }
4332 }
4333 }
4334
4335 if (!tx_ring)
4336 return;
4337
4338 /* Read interrupt register */
4339 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
4340 val = rd32(&pf->hw,
4341 I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
4342 tx_ring->vsi->base_vector - 1));
4343 else
4344 val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
4345
4346 head = i40e_get_head(tx_ring);
4347
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004348 tx_pending_hw = i40e_get_tx_pending(tx_ring, false);
Kiran Patilb03a8c12015-09-24 18:13:15 -04004349
Kiran Patil9c6c1252015-11-06 15:26:02 -08004350 /* HW is done executing descriptors, updated HEAD write back,
4351 * but SW hasn't processed those descriptors. If interrupt is
4352 * not generated from this point ON, it could result into
4353 * dev_watchdog detecting timeout on those netdev_queue,
4354 * hence proactively trigger SW interrupt.
Kiran Patilb03a8c12015-09-24 18:13:15 -04004355 */
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004356 if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
Kiran Patil9c6c1252015-11-06 15:26:02 -08004357 /* NAPI Poll didn't run and clear since it was set */
4358 if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT,
4359 &tx_ring->q_vector->hung_detected)) {
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004360 netdev_info(vsi->netdev, "VSI_seid %d, Hung TX queue %d, tx_pending_hw: %d, NTC:0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x\n",
4361 vsi->seid, q_idx, tx_pending_hw,
Kiran Patil9c6c1252015-11-06 15:26:02 -08004362 tx_ring->next_to_clean, head,
4363 tx_ring->next_to_use,
4364 readl(tx_ring->tail));
4365 netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n",
4366 vsi->seid, q_idx, val);
4367 i40e_force_wb(vsi, tx_ring->q_vector);
4368 } else {
4369 /* First Chance - detected possible hung */
4370 set_bit(I40E_Q_VECTOR_HUNG_DETECT,
4371 &tx_ring->q_vector->hung_detected);
4372 }
4373 }
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004374
4375 /* This is the case where we have interrupts missing,
4376 * so the tx_pending in HW will most likely be 0, but we
4377 * will have tx_pending in SW since the WB happened but the
4378 * interrupt got lost.
4379 */
4380 if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) &&
4381 (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
4382 if (napi_reschedule(&tx_ring->q_vector->napi))
4383 tx_ring->tx_stats.tx_lost_interrupt++;
4384 }
Kiran Patilb03a8c12015-09-24 18:13:15 -04004385}
4386
4387/**
4388 * i40e_detect_recover_hung - Function to detect and recover hung_queues
4389 * @pf: pointer to PF struct
4390 *
4391 * LAN VSI has netdev and netdev has TX queues. This function is to check
4392 * each of those TX queues if they are hung, trigger recovery by issuing
4393 * SW interrupt.
4394 **/
4395static void i40e_detect_recover_hung(struct i40e_pf *pf)
4396{
4397 struct net_device *netdev;
4398 struct i40e_vsi *vsi;
4399 int i;
4400
4401 /* Only for LAN VSI */
4402 vsi = pf->vsi[pf->lan_vsi];
4403
4404 if (!vsi)
4405 return;
4406
4407 /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
4408 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
4409 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
4410 return;
4411
4412 /* Make sure type is MAIN VSI */
4413 if (vsi->type != I40E_VSI_MAIN)
4414 return;
4415
4416 netdev = vsi->netdev;
4417 if (!netdev)
4418 return;
4419
4420 /* Bail out if netif_carrier is not OK */
4421 if (!netif_carrier_ok(netdev))
4422 return;
4423
4424 /* Go thru' TX queues for netdev */
4425 for (i = 0; i < netdev->num_tx_queues; i++) {
4426 struct netdev_queue *q;
4427
4428 q = netdev_get_tx_queue(netdev, i);
4429 if (q)
4430 i40e_detect_recover_hung_queue(i, vsi);
4431 }
4432}
4433
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004434/**
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004435 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00004436 * @pf: pointer to PF
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004437 *
4438 * Get TC map for ISCSI PF type that will include iSCSI TC
4439 * and LAN TC.
4440 **/
4441static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
4442{
4443 struct i40e_dcb_app_priority_table app;
4444 struct i40e_hw *hw = &pf->hw;
4445 u8 enabled_tc = 1; /* TC0 is always enabled */
4446 u8 tc, i;
4447 /* Get the iSCSI APP TLV */
4448 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4449
4450 for (i = 0; i < dcbcfg->numapps; i++) {
4451 app = dcbcfg->app[i];
4452 if (app.selector == I40E_APP_SEL_TCPIP &&
4453 app.protocolid == I40E_APP_PROTOID_ISCSI) {
4454 tc = dcbcfg->etscfg.prioritytable[app.priority];
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004455 enabled_tc |= BIT(tc);
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004456 break;
4457 }
4458 }
4459
4460 return enabled_tc;
4461}
4462
4463/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004464 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4465 * @dcbcfg: the corresponding DCBx configuration structure
4466 *
4467 * Return the number of TCs from given DCBx configuration
4468 **/
4469static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
4470{
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004471 int i, tc_unused = 0;
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004472 u8 num_tc = 0;
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004473 u8 ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004474
4475 /* Scan the ETS Config Priority Table to find
4476 * traffic class enabled for a given priority
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004477 * and create a bitmask of enabled TCs
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004478 */
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004479 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
4480 num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
4481
4482 /* Now scan the bitmask to check for
4483 * contiguous TCs starting with TC0
4484 */
4485 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4486 if (num_tc & BIT(i)) {
4487 if (!tc_unused) {
4488 ret++;
4489 } else {
4490 pr_err("Non-contiguous TC - Disabling DCB\n");
4491 return 1;
4492 }
4493 } else {
4494 tc_unused = 1;
4495 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004496 }
4497
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004498 /* There is always at least TC0 */
4499 if (!ret)
4500 ret = 1;
4501
4502 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004503}
4504
4505/**
4506 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4507 * @dcbcfg: the corresponding DCBx configuration structure
4508 *
4509 * Query the current DCB configuration and return the number of
4510 * traffic classes enabled from the given DCBX config
4511 **/
4512static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
4513{
4514 u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
4515 u8 enabled_tc = 1;
4516 u8 i;
4517
4518 for (i = 0; i < num_tc; i++)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004519 enabled_tc |= BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004520
4521 return enabled_tc;
4522}
4523
4524/**
4525 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4526 * @pf: PF being queried
4527 *
4528 * Return number of traffic classes enabled for the given PF
4529 **/
4530static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
4531{
4532 struct i40e_hw *hw = &pf->hw;
Dave Ertman52a08ca2016-07-27 12:02:34 -07004533 u8 i, enabled_tc = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004534 u8 num_tc = 0;
4535 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4536
4537 /* If DCB is not enabled then always in single TC */
4538 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
4539 return 1;
4540
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004541 /* SFP mode will be enabled for all TCs on port */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004542 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4543 return i40e_dcb_get_num_tc(dcbcfg);
4544
4545 /* MFP mode return count of enabled TCs for this PF */
4546 if (pf->hw.func_caps.iscsi)
4547 enabled_tc = i40e_get_iscsi_tc_map(pf);
4548 else
Neerav Parikhfc51de92015-02-24 06:58:53 +00004549 return 1; /* Only TC0 */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004550
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004551 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004552 if (enabled_tc & BIT(i))
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004553 num_tc++;
4554 }
4555 return num_tc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004556}
4557
4558/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004559 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4560 * @pf: PF being queried
4561 *
4562 * Return a bitmap for enabled traffic classes for this PF.
4563 **/
4564static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
4565{
4566 /* If DCB is not enabled for this PF then just return default TC */
4567 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
David Ertmanea6acb72016-09-20 07:10:50 -07004568 return I40E_DEFAULT_TRAFFIC_CLASS;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004569
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004570 /* SFP mode we want PF to be enabled for all TCs */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004571 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4572 return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
4573
Neerav Parikhfc51de92015-02-24 06:58:53 +00004574 /* MFP enabled and iSCSI PF type */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004575 if (pf->hw.func_caps.iscsi)
4576 return i40e_get_iscsi_tc_map(pf);
4577 else
David Ertmanea6acb72016-09-20 07:10:50 -07004578 return I40E_DEFAULT_TRAFFIC_CLASS;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004579}
4580
4581/**
4582 * i40e_vsi_get_bw_info - Query VSI BW Information
4583 * @vsi: the VSI being queried
4584 *
4585 * Returns 0 on success, negative value on failure
4586 **/
4587static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
4588{
4589 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
4590 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
4591 struct i40e_pf *pf = vsi->back;
4592 struct i40e_hw *hw = &pf->hw;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004593 i40e_status ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004594 u32 tc_bw_max;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004595 int i;
4596
4597 /* Get the VSI level BW configuration */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004598 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
4599 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004600 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004601 "couldn't get PF vsi bw config, err %s aq_err %s\n",
4602 i40e_stat_str(&pf->hw, ret),
4603 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004604 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004605 }
4606
4607 /* Get the VSI level BW configuration per TC */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004608 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
4609 NULL);
4610 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004611 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004612 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
4613 i40e_stat_str(&pf->hw, ret),
4614 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004615 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004616 }
4617
4618 if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
4619 dev_info(&pf->pdev->dev,
4620 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4621 bw_config.tc_valid_bits,
4622 bw_ets_config.tc_valid_bits);
4623 /* Still continuing */
4624 }
4625
4626 vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
4627 vsi->bw_max_quanta = bw_config.max_bw;
4628 tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
4629 (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
4630 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4631 vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
4632 vsi->bw_ets_limit_credits[i] =
4633 le16_to_cpu(bw_ets_config.credits[i]);
4634 /* 3 bits out of 4 for each TC */
4635 vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
4636 }
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004637
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004638 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004639}
4640
4641/**
4642 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
4643 * @vsi: the VSI being configured
4644 * @enabled_tc: TC bitmap
4645 * @bw_credits: BW shared credits per TC
4646 *
4647 * Returns 0 on success, negative value on failure
4648 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004649static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004650 u8 *bw_share)
4651{
4652 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004653 i40e_status ret;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004654 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004655
4656 bw_data.tc_valid_bits = enabled_tc;
4657 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4658 bw_data.tc_bw_credits[i] = bw_share[i];
4659
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004660 ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
4661 NULL);
4662 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004663 dev_info(&vsi->back->pdev->dev,
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004664 "AQ command Config VSI BW allocation per TC failed = %d\n",
4665 vsi->back->hw.aq.asq_last_status);
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004666 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004667 }
4668
4669 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4670 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
4671
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004672 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004673}
4674
4675/**
4676 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
4677 * @vsi: the VSI being configured
4678 * @enabled_tc: TC map to be enabled
4679 *
4680 **/
4681static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4682{
4683 struct net_device *netdev = vsi->netdev;
4684 struct i40e_pf *pf = vsi->back;
4685 struct i40e_hw *hw = &pf->hw;
4686 u8 netdev_tc = 0;
4687 int i;
4688 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4689
4690 if (!netdev)
4691 return;
4692
4693 if (!enabled_tc) {
4694 netdev_reset_tc(netdev);
4695 return;
4696 }
4697
4698 /* Set up actual enabled TCs on the VSI */
4699 if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
4700 return;
4701
4702 /* set per TC queues for the VSI */
4703 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4704 /* Only set TC queues for enabled tcs
4705 *
4706 * e.g. For a VSI that has TC0 and TC3 enabled the
4707 * enabled_tc bitmap would be 0x00001001; the driver
4708 * will set the numtc for netdev as 2 that will be
4709 * referenced by the netdev layer as TC 0 and 1.
4710 */
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004711 if (vsi->tc_config.enabled_tc & BIT(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004712 netdev_set_tc_queue(netdev,
4713 vsi->tc_config.tc_info[i].netdev_tc,
4714 vsi->tc_config.tc_info[i].qcount,
4715 vsi->tc_config.tc_info[i].qoffset);
4716 }
4717
4718 /* Assign UP2TC map for the VSI */
4719 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
4720 /* Get the actual TC# for the UP */
4721 u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
4722 /* Get the mapped netdev TC# for the UP */
4723 netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
4724 netdev_set_prio_tc_map(netdev, i, netdev_tc);
4725 }
4726}
4727
4728/**
4729 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4730 * @vsi: the VSI being configured
4731 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4732 **/
4733static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
4734 struct i40e_vsi_context *ctxt)
4735{
4736 /* copy just the sections touched not the entire info
4737 * since not all sections are valid as returned by
4738 * update vsi params
4739 */
4740 vsi->info.mapping_flags = ctxt->info.mapping_flags;
4741 memcpy(&vsi->info.queue_mapping,
4742 &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
4743 memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
4744 sizeof(vsi->info.tc_mapping));
4745}
4746
4747/**
4748 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4749 * @vsi: VSI to be configured
4750 * @enabled_tc: TC bitmap
4751 *
4752 * This configures a particular VSI for TCs that are mapped to the
4753 * given TC bitmap. It uses default bandwidth share for TCs across
4754 * VSIs to configure TC for a particular VSI.
4755 *
4756 * NOTE:
4757 * It is expected that the VSI queues have been quisced before calling
4758 * this function.
4759 **/
4760static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4761{
4762 u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
4763 struct i40e_vsi_context ctxt;
4764 int ret = 0;
4765 int i;
4766
4767 /* Check if enabled_tc is same as existing or new TCs */
4768 if (vsi->tc_config.enabled_tc == enabled_tc)
4769 return ret;
4770
4771 /* Enable ETS TCs with equal BW Share for now across all VSIs */
4772 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004773 if (enabled_tc & BIT(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004774 bw_share[i] = 1;
4775 }
4776
4777 ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
4778 if (ret) {
4779 dev_info(&vsi->back->pdev->dev,
4780 "Failed configuring TC map %d for VSI %d\n",
4781 enabled_tc, vsi->seid);
4782 goto out;
4783 }
4784
4785 /* Update Queue Pairs Mapping for currently enabled UPs */
4786 ctxt.seid = vsi->seid;
4787 ctxt.pf_num = vsi->back->hw.pf_id;
4788 ctxt.vf_num = 0;
4789 ctxt.uplink_seid = vsi->uplink_seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07004790 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004791 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
4792
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06004793 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
4794 ctxt.info.valid_sections |=
4795 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
4796 ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
4797 }
4798
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004799 /* Update the VSI after updating the VSI queue-mapping information */
4800 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
4801 if (ret) {
4802 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004803 "Update vsi tc config failed, err %s aq_err %s\n",
4804 i40e_stat_str(&vsi->back->hw, ret),
4805 i40e_aq_str(&vsi->back->hw,
4806 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004807 goto out;
4808 }
4809 /* update the local VSI info with updated queue map */
4810 i40e_vsi_update_queue_map(vsi, &ctxt);
4811 vsi->info.valid_sections = 0;
4812
4813 /* Update current VSI BW information */
4814 ret = i40e_vsi_get_bw_info(vsi);
4815 if (ret) {
4816 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004817 "Failed updating vsi bw info, err %s aq_err %s\n",
4818 i40e_stat_str(&vsi->back->hw, ret),
4819 i40e_aq_str(&vsi->back->hw,
4820 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004821 goto out;
4822 }
4823
4824 /* Update the netdev TC setup */
4825 i40e_vsi_config_netdev_tc(vsi, enabled_tc);
4826out:
4827 return ret;
4828}
4829
4830/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004831 * i40e_veb_config_tc - Configure TCs for given VEB
4832 * @veb: given VEB
4833 * @enabled_tc: TC bitmap
4834 *
4835 * Configures given TC bitmap for VEB (switching) element
4836 **/
4837int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
4838{
4839 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
4840 struct i40e_pf *pf = veb->pf;
4841 int ret = 0;
4842 int i;
4843
4844 /* No TCs or already enabled TCs just return */
4845 if (!enabled_tc || veb->enabled_tc == enabled_tc)
4846 return ret;
4847
4848 bw_data.tc_valid_bits = enabled_tc;
4849 /* bw_data.absolute_credits is not set (relative) */
4850
4851 /* Enable ETS TCs with equal BW Share for now */
4852 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004853 if (enabled_tc & BIT(i))
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004854 bw_data.tc_bw_share_credits[i] = 1;
4855 }
4856
4857 ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
4858 &bw_data, NULL);
4859 if (ret) {
4860 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004861 "VEB bw config failed, err %s aq_err %s\n",
4862 i40e_stat_str(&pf->hw, ret),
4863 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004864 goto out;
4865 }
4866
4867 /* Update the BW information */
4868 ret = i40e_veb_get_bw_info(veb);
4869 if (ret) {
4870 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004871 "Failed getting veb bw config, err %s aq_err %s\n",
4872 i40e_stat_str(&pf->hw, ret),
4873 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004874 }
4875
4876out:
4877 return ret;
4878}
4879
4880#ifdef CONFIG_I40E_DCB
4881/**
4882 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
4883 * @pf: PF struct
4884 *
4885 * Reconfigure VEB/VSIs on a given PF; it is assumed that
4886 * the caller would've quiesce all the VSIs before calling
4887 * this function
4888 **/
4889static void i40e_dcb_reconfigure(struct i40e_pf *pf)
4890{
4891 u8 tc_map = 0;
4892 int ret;
4893 u8 v;
4894
4895 /* Enable the TCs available on PF to all VEBs */
4896 tc_map = i40e_pf_get_tc_map(pf);
4897 for (v = 0; v < I40E_MAX_VEB; v++) {
4898 if (!pf->veb[v])
4899 continue;
4900 ret = i40e_veb_config_tc(pf->veb[v], tc_map);
4901 if (ret) {
4902 dev_info(&pf->pdev->dev,
4903 "Failed configuring TC for VEB seid=%d\n",
4904 pf->veb[v]->seid);
4905 /* Will try to configure as many components */
4906 }
4907 }
4908
4909 /* Update each VSI */
Mitch Williams505682c2014-05-20 08:01:37 +00004910 for (v = 0; v < pf->num_alloc_vsi; v++) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004911 if (!pf->vsi[v])
4912 continue;
4913
4914 /* - Enable all TCs for the LAN VSI
Vasu Dev38e00432014-08-01 13:27:03 -07004915#ifdef I40E_FCOE
4916 * - For FCoE VSI only enable the TC configured
4917 * as per the APP TLV
4918#endif
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004919 * - For all others keep them at TC0 for now
4920 */
4921 if (v == pf->lan_vsi)
4922 tc_map = i40e_pf_get_tc_map(pf);
4923 else
David Ertmanea6acb72016-09-20 07:10:50 -07004924 tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
Vasu Dev38e00432014-08-01 13:27:03 -07004925#ifdef I40E_FCOE
4926 if (pf->vsi[v]->type == I40E_VSI_FCOE)
4927 tc_map = i40e_get_fcoe_tc_map(pf);
4928#endif /* #ifdef I40E_FCOE */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004929
4930 ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
4931 if (ret) {
4932 dev_info(&pf->pdev->dev,
4933 "Failed configuring TC for VSI seid=%d\n",
4934 pf->vsi[v]->seid);
4935 /* Will try to configure as many components */
4936 } else {
Neerav Parikh0672a092014-04-01 07:11:47 +00004937 /* Re-configure VSI vectors based on updated TC map */
4938 i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004939 if (pf->vsi[v]->netdev)
4940 i40e_dcbnl_set_all(pf->vsi[v]);
4941 }
4942 }
4943}
4944
4945/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00004946 * i40e_resume_port_tx - Resume port Tx
4947 * @pf: PF struct
4948 *
4949 * Resume a port's Tx and issue a PF reset in case of failure to
4950 * resume.
4951 **/
4952static int i40e_resume_port_tx(struct i40e_pf *pf)
4953{
4954 struct i40e_hw *hw = &pf->hw;
4955 int ret;
4956
4957 ret = i40e_aq_resume_port_tx(hw, NULL);
4958 if (ret) {
4959 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004960 "Resume Port Tx failed, err %s aq_err %s\n",
4961 i40e_stat_str(&pf->hw, ret),
4962 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh2fd75f32014-11-12 00:18:20 +00004963 /* Schedule PF reset to recover */
4964 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
4965 i40e_service_event_schedule(pf);
4966 }
4967
4968 return ret;
4969}
4970
4971/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004972 * i40e_init_pf_dcb - Initialize DCB configuration
4973 * @pf: PF being configured
4974 *
4975 * Query the current DCB configuration and cache it
4976 * in the hardware structure
4977 **/
4978static int i40e_init_pf_dcb(struct i40e_pf *pf)
4979{
4980 struct i40e_hw *hw = &pf->hw;
4981 int err = 0;
4982
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00004983 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
Neerav Parikhf1bbad32016-01-13 16:51:39 -08004984 if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT)
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00004985 goto out;
4986
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004987 /* Get the initial DCB configuration */
4988 err = i40e_init_dcb(hw);
4989 if (!err) {
4990 /* Device/Function is not DCBX capable */
4991 if ((!hw->func_caps.dcb) ||
4992 (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
4993 dev_info(&pf->pdev->dev,
4994 "DCBX offload is not supported or is disabled for this PF.\n");
4995
4996 if (pf->flags & I40E_FLAG_MFP_ENABLED)
4997 goto out;
4998
4999 } else {
5000 /* When status is not DISABLED then DCBX in FW */
5001 pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
5002 DCB_CAP_DCBX_VER_IEEE;
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005003
5004 pf->flags |= I40E_FLAG_DCB_CAPABLE;
Dave Ertmana0362442016-08-29 17:38:26 -07005005 /* Enable DCB tagging only when more than one TC
5006 * or explicitly disable if only one TC
5007 */
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005008 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
5009 pf->flags |= I40E_FLAG_DCB_ENABLED;
Dave Ertmana0362442016-08-29 17:38:26 -07005010 else
5011 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005012 dev_dbg(&pf->pdev->dev,
5013 "DCBX offload is supported for this PF.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005014 }
Neerav Parikh014269f2014-04-01 07:11:48 +00005015 } else {
Shannon Nelsonaebfc812014-12-11 07:06:38 +00005016 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005017 "Query for DCB configuration failed, err %s aq_err %s\n",
5018 i40e_stat_str(&pf->hw, err),
5019 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005020 }
5021
5022out:
5023 return err;
5024}
5025#endif /* CONFIG_I40E_DCB */
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005026#define SPEED_SIZE 14
5027#define FC_SIZE 8
5028/**
5029 * i40e_print_link_message - print link up or down
5030 * @vsi: the VSI for which link needs a message
5031 */
Matt Jaredc156f852015-08-27 11:42:39 -04005032void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005033{
Shannon Nelsona9165492015-09-03 17:19:00 -04005034 char *speed = "Unknown";
5035 char *fc = "Unknown";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005036
Matt Jaredc156f852015-08-27 11:42:39 -04005037 if (vsi->current_isup == isup)
5038 return;
5039 vsi->current_isup = isup;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005040 if (!isup) {
5041 netdev_info(vsi->netdev, "NIC Link is Down\n");
5042 return;
5043 }
5044
Greg Rose148c2d82014-12-11 07:06:27 +00005045 /* Warn user if link speed on NPAR enabled partition is not at
5046 * least 10GB
5047 */
5048 if (vsi->back->hw.func_caps.npar_enable &&
5049 (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
5050 vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
5051 netdev_warn(vsi->netdev,
5052 "The partition detected link speed that is less than 10Gbps\n");
5053
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005054 switch (vsi->back->hw.phy.link_info.link_speed) {
5055 case I40E_LINK_SPEED_40GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005056 speed = "40 G";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005057 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -07005058 case I40E_LINK_SPEED_20GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005059 speed = "20 G";
Jesse Brandeburgae24b402015-03-27 00:12:09 -07005060 break;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005061 case I40E_LINK_SPEED_10GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005062 speed = "10 G";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005063 break;
5064 case I40E_LINK_SPEED_1GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005065 speed = "1000 M";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005066 break;
Mitch Williams5960d332014-09-13 07:40:47 +00005067 case I40E_LINK_SPEED_100MB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005068 speed = "100 M";
Mitch Williams5960d332014-09-13 07:40:47 +00005069 break;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005070 default:
5071 break;
5072 }
5073
5074 switch (vsi->back->hw.fc.current_mode) {
5075 case I40E_FC_FULL:
Shannon Nelsona9165492015-09-03 17:19:00 -04005076 fc = "RX/TX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005077 break;
5078 case I40E_FC_TX_PAUSE:
Shannon Nelsona9165492015-09-03 17:19:00 -04005079 fc = "TX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005080 break;
5081 case I40E_FC_RX_PAUSE:
Shannon Nelsona9165492015-09-03 17:19:00 -04005082 fc = "RX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005083 break;
5084 default:
Shannon Nelsona9165492015-09-03 17:19:00 -04005085 fc = "None";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005086 break;
5087 }
5088
Shannon Nelsona9165492015-09-03 17:19:00 -04005089 netdev_info(vsi->netdev, "NIC Link is Up %sbps Full Duplex, Flow Control: %s\n",
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005090 speed, fc);
5091}
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005092
5093/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005094 * i40e_up_complete - Finish the last steps of bringing up a connection
5095 * @vsi: the VSI being configured
5096 **/
5097static int i40e_up_complete(struct i40e_vsi *vsi)
5098{
5099 struct i40e_pf *pf = vsi->back;
5100 int err;
5101
5102 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
5103 i40e_vsi_configure_msix(vsi);
5104 else
5105 i40e_configure_msi_and_legacy(vsi);
5106
5107 /* start rings */
5108 err = i40e_vsi_control_rings(vsi, true);
5109 if (err)
5110 return err;
5111
5112 clear_bit(__I40E_DOWN, &vsi->state);
5113 i40e_napi_enable_all(vsi);
5114 i40e_vsi_enable_irq(vsi);
5115
5116 if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
5117 (vsi->netdev)) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005118 i40e_print_link_message(vsi, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005119 netif_tx_start_all_queues(vsi->netdev);
5120 netif_carrier_on(vsi->netdev);
Anjali Singhai6d779b42013-09-28 06:00:02 +00005121 } else if (vsi->netdev) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005122 i40e_print_link_message(vsi, false);
Carolyn Wyborny7b592f62014-07-10 07:58:19 +00005123 /* need to check for qualified module here*/
5124 if ((pf->hw.phy.link_info.link_info &
5125 I40E_AQ_MEDIA_AVAILABLE) &&
5126 (!(pf->hw.phy.link_info.an_info &
5127 I40E_AQ_QUALIFIED_MODULE)))
5128 netdev_err(vsi->netdev,
5129 "the driver failed to link because an unqualified module was detected.");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005130 }
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00005131
5132 /* replay FDIR SB filters */
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005133 if (vsi->type == I40E_VSI_FDIR) {
5134 /* reset fd counters */
5135 pf->fd_add_err = pf->fd_atr_cnt = 0;
5136 if (pf->fd_tcp_rule > 0) {
Jacob Keller234dc4e2016-09-06 18:05:09 -07005137 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04005138 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5139 dev_info(&pf->pdev->dev, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005140 pf->fd_tcp_rule = 0;
5141 }
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00005142 i40e_fdir_filter_restore(vsi);
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005143 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06005144
5145 /* On the next run of the service_task, notify any clients of the new
5146 * opened netdev
5147 */
5148 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005149 i40e_service_event_schedule(pf);
5150
5151 return 0;
5152}
5153
5154/**
5155 * i40e_vsi_reinit_locked - Reset the VSI
5156 * @vsi: the VSI being configured
5157 *
5158 * Rebuild the ring structs after some configuration
5159 * has changed, e.g. MTU size.
5160 **/
5161static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
5162{
5163 struct i40e_pf *pf = vsi->back;
5164
5165 WARN_ON(in_interrupt());
5166 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
5167 usleep_range(1000, 2000);
5168 i40e_down(vsi);
5169
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005170 i40e_up(vsi);
5171 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
5172}
5173
5174/**
5175 * i40e_up - Bring the connection back up after being down
5176 * @vsi: the VSI being configured
5177 **/
5178int i40e_up(struct i40e_vsi *vsi)
5179{
5180 int err;
5181
5182 err = i40e_vsi_configure(vsi);
5183 if (!err)
5184 err = i40e_up_complete(vsi);
5185
5186 return err;
5187}
5188
5189/**
5190 * i40e_down - Shutdown the connection processing
5191 * @vsi: the VSI being stopped
5192 **/
5193void i40e_down(struct i40e_vsi *vsi)
5194{
5195 int i;
5196
5197 /* It is assumed that the caller of this function
5198 * sets the vsi->state __I40E_DOWN bit.
5199 */
5200 if (vsi->netdev) {
5201 netif_carrier_off(vsi->netdev);
5202 netif_tx_disable(vsi->netdev);
5203 }
5204 i40e_vsi_disable_irq(vsi);
5205 i40e_vsi_control_rings(vsi, false);
5206 i40e_napi_disable_all(vsi);
5207
5208 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00005209 i40e_clean_tx_ring(vsi->tx_rings[i]);
5210 i40e_clean_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005211 }
Catherine Sullivanf980d442016-05-16 10:26:34 -07005212
5213 i40e_notify_client_of_netdev_close(vsi, false);
5214
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005215}
5216
5217/**
5218 * i40e_setup_tc - configure multiple traffic classes
5219 * @netdev: net device to configure
5220 * @tc: number of traffic classes to enable
5221 **/
5222static int i40e_setup_tc(struct net_device *netdev, u8 tc)
5223{
5224 struct i40e_netdev_priv *np = netdev_priv(netdev);
5225 struct i40e_vsi *vsi = np->vsi;
5226 struct i40e_pf *pf = vsi->back;
5227 u8 enabled_tc = 0;
5228 int ret = -EINVAL;
5229 int i;
5230
5231 /* Check if DCB enabled to continue */
5232 if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
5233 netdev_info(netdev, "DCB is not enabled for adapter\n");
5234 goto exit;
5235 }
5236
5237 /* Check if MFP enabled */
5238 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
5239 netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
5240 goto exit;
5241 }
5242
5243 /* Check whether tc count is within enabled limit */
5244 if (tc > i40e_pf_get_num_tc(pf)) {
5245 netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
5246 goto exit;
5247 }
5248
5249 /* Generate TC map for number of tc requested */
5250 for (i = 0; i < tc; i++)
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08005251 enabled_tc |= BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005252
5253 /* Requesting same TC configuration as already enabled */
5254 if (enabled_tc == vsi->tc_config.enabled_tc)
5255 return 0;
5256
5257 /* Quiesce VSI queues */
5258 i40e_quiesce_vsi(vsi);
5259
5260 /* Configure VSI for enabled TCs */
5261 ret = i40e_vsi_config_tc(vsi, enabled_tc);
5262 if (ret) {
5263 netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
5264 vsi->seid);
5265 goto exit;
5266 }
5267
5268 /* Unquiesce VSI */
5269 i40e_unquiesce_vsi(vsi);
5270
5271exit:
5272 return ret;
5273}
5274
John Fastabende4c67342016-02-16 21:16:15 -08005275#ifdef I40E_FCOE
John Fastabend16e5cc62016-02-16 21:16:43 -08005276int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
5277 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -08005278#else
John Fastabend16e5cc62016-02-16 21:16:43 -08005279static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
5280 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -08005281#endif
5282{
John Fastabend16e5cc62016-02-16 21:16:43 -08005283 if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO)
John Fastabende4c67342016-02-16 21:16:15 -08005284 return -EINVAL;
John Fastabend16e5cc62016-02-16 21:16:43 -08005285 return i40e_setup_tc(netdev, tc->tc);
John Fastabende4c67342016-02-16 21:16:15 -08005286}
5287
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005288/**
5289 * i40e_open - Called when a network interface is made active
5290 * @netdev: network interface device structure
5291 *
5292 * The open entry point is called when a network interface is made
5293 * active by the system (IFF_UP). At this point all resources needed
5294 * for transmit and receive operations are allocated, the interrupt
5295 * handler is registered with the OS, the netdev watchdog subtask is
5296 * enabled, and the stack is notified that the interface is ready.
5297 *
5298 * Returns 0 on success, negative value on failure
5299 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005300int i40e_open(struct net_device *netdev)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005301{
5302 struct i40e_netdev_priv *np = netdev_priv(netdev);
5303 struct i40e_vsi *vsi = np->vsi;
5304 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005305 int err;
5306
Shannon Nelson4eb3f762014-03-06 08:59:58 +00005307 /* disallow open during test or if eeprom is broken */
5308 if (test_bit(__I40E_TESTING, &pf->state) ||
5309 test_bit(__I40E_BAD_EEPROM, &pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005310 return -EBUSY;
5311
5312 netif_carrier_off(netdev);
5313
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005314 err = i40e_vsi_open(vsi);
5315 if (err)
5316 return err;
5317
Jesse Brandeburg059dab62014-04-01 09:07:20 +00005318 /* configure global TSO hardware offload settings */
5319 wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
5320 TCP_FLAG_FIN) >> 16);
5321 wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
5322 TCP_FLAG_FIN |
5323 TCP_FLAG_CWR) >> 16);
5324 wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
5325
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07005326 udp_tunnel_get_rx_info(netdev);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06005327
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005328 return 0;
5329}
5330
5331/**
5332 * i40e_vsi_open -
5333 * @vsi: the VSI to open
5334 *
5335 * Finish initialization of the VSI.
5336 *
5337 * Returns 0 on success, negative value on failure
5338 **/
5339int i40e_vsi_open(struct i40e_vsi *vsi)
5340{
5341 struct i40e_pf *pf = vsi->back;
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00005342 char int_name[I40E_INT_NAME_STR_LEN];
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005343 int err;
5344
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005345 /* allocate descriptors */
5346 err = i40e_vsi_setup_tx_resources(vsi);
5347 if (err)
5348 goto err_setup_tx;
5349 err = i40e_vsi_setup_rx_resources(vsi);
5350 if (err)
5351 goto err_setup_rx;
5352
5353 err = i40e_vsi_configure(vsi);
5354 if (err)
5355 goto err_setup_rx;
5356
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00005357 if (vsi->netdev) {
5358 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
5359 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
5360 err = i40e_vsi_request_irq(vsi, int_name);
5361 if (err)
5362 goto err_setup_rx;
5363
5364 /* Notify the stack of the actual queue counts. */
5365 err = netif_set_real_num_tx_queues(vsi->netdev,
5366 vsi->num_queue_pairs);
5367 if (err)
5368 goto err_set_queues;
5369
5370 err = netif_set_real_num_rx_queues(vsi->netdev,
5371 vsi->num_queue_pairs);
5372 if (err)
5373 goto err_set_queues;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005374
5375 } else if (vsi->type == I40E_VSI_FDIR) {
Carolyn Wybornye240f672014-12-11 07:06:37 +00005376 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +00005377 dev_driver_string(&pf->pdev->dev),
5378 dev_name(&pf->pdev->dev));
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005379 err = i40e_vsi_request_irq(vsi, int_name);
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +00005380
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00005381 } else {
Jean Sacrence9ccb12014-05-01 14:31:18 +00005382 err = -EINVAL;
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005383 goto err_setup_rx;
5384 }
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00005385
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005386 err = i40e_up_complete(vsi);
5387 if (err)
5388 goto err_up_complete;
5389
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005390 return 0;
5391
5392err_up_complete:
5393 i40e_down(vsi);
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00005394err_set_queues:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005395 i40e_vsi_free_irq(vsi);
5396err_setup_rx:
5397 i40e_vsi_free_rx_resources(vsi);
5398err_setup_tx:
5399 i40e_vsi_free_tx_resources(vsi);
5400 if (vsi == pf->vsi[pf->lan_vsi])
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005401 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005402
5403 return err;
5404}
5405
5406/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005407 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00005408 * @pf: Pointer to PF
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005409 *
5410 * This function destroys the hlist where all the Flow Director
5411 * filters were saved.
5412 **/
5413static void i40e_fdir_filter_exit(struct i40e_pf *pf)
5414{
5415 struct i40e_fdir_filter *filter;
5416 struct hlist_node *node2;
5417
5418 hlist_for_each_entry_safe(filter, node2,
5419 &pf->fdir_filter_list, fdir_node) {
5420 hlist_del(&filter->fdir_node);
5421 kfree(filter);
5422 }
5423 pf->fdir_pf_active_filters = 0;
5424}
5425
5426/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005427 * i40e_close - Disables a network interface
5428 * @netdev: network interface device structure
5429 *
5430 * The close entry point is called when an interface is de-activated
5431 * by the OS. The hardware is still under the driver's control, but
5432 * this netdev interface is disabled.
5433 *
5434 * Returns 0, this is not allowed to fail
5435 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005436int i40e_close(struct net_device *netdev)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005437{
5438 struct i40e_netdev_priv *np = netdev_priv(netdev);
5439 struct i40e_vsi *vsi = np->vsi;
5440
Shannon Nelson90ef8d42014-03-14 07:32:26 +00005441 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005442
5443 return 0;
5444}
5445
5446/**
5447 * i40e_do_reset - Start a PF or Core Reset sequence
5448 * @pf: board private structure
5449 * @reset_flags: which reset is requested
5450 *
5451 * The essential difference in resets is that the PF Reset
5452 * doesn't clear the packet buffers, doesn't reset the PE
5453 * firmware, and doesn't bother the other PFs on the chip.
5454 **/
5455void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
5456{
5457 u32 val;
5458
5459 WARN_ON(in_interrupt());
5460
Mitch Williams263fc482014-04-23 04:50:11 +00005461
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005462 /* do the biggest reset indicated */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005463 if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005464
5465 /* Request a Global Reset
5466 *
5467 * This will start the chip's countdown to the actual full
5468 * chip reset event, and a warning interrupt to be sent
5469 * to all PFs, including the requestor. Our handler
5470 * for the warning interrupt will deal with the shutdown
5471 * and recovery of the switch setup.
5472 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005473 dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005474 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5475 val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
5476 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5477
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005478 } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005479
5480 /* Request a Core Reset
5481 *
5482 * Same as Global Reset, except does *not* include the MAC/PHY
5483 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005484 dev_dbg(&pf->pdev->dev, "CoreR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005485 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5486 val |= I40E_GLGEN_RTRIG_CORER_MASK;
5487 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5488 i40e_flush(&pf->hw);
5489
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005490 } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005491
5492 /* Request a PF Reset
5493 *
5494 * Resets only the PF-specific registers
5495 *
5496 * This goes directly to the tear-down and rebuild of
5497 * the switch, since we need to do all the recovery as
5498 * for the Core Reset.
5499 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005500 dev_dbg(&pf->pdev->dev, "PFR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005501 i40e_handle_reset_warning(pf);
5502
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005503 } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005504 int v;
5505
5506 /* Find the VSI(s) that requested a re-init */
5507 dev_info(&pf->pdev->dev,
5508 "VSI reinit requested\n");
Mitch Williams505682c2014-05-20 08:01:37 +00005509 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005510 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04005511
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005512 if (vsi != NULL &&
5513 test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
5514 i40e_vsi_reinit_locked(pf->vsi[v]);
5515 clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
5516 }
5517 }
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005518 } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005519 int v;
5520
5521 /* Find the VSI(s) that needs to be brought down */
5522 dev_info(&pf->pdev->dev, "VSI down requested\n");
5523 for (v = 0; v < pf->num_alloc_vsi; v++) {
5524 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04005525
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005526 if (vsi != NULL &&
5527 test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) {
5528 set_bit(__I40E_DOWN, &vsi->state);
5529 i40e_down(vsi);
5530 clear_bit(__I40E_DOWN_REQUESTED, &vsi->state);
5531 }
5532 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005533 } else {
5534 dev_info(&pf->pdev->dev,
5535 "bad reset request 0x%08x\n", reset_flags);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005536 }
5537}
5538
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005539#ifdef CONFIG_I40E_DCB
5540/**
5541 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
5542 * @pf: board private structure
5543 * @old_cfg: current DCB config
5544 * @new_cfg: new DCB config
5545 **/
5546bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
5547 struct i40e_dcbx_config *old_cfg,
5548 struct i40e_dcbx_config *new_cfg)
5549{
5550 bool need_reconfig = false;
5551
5552 /* Check if ETS configuration has changed */
5553 if (memcmp(&new_cfg->etscfg,
5554 &old_cfg->etscfg,
5555 sizeof(new_cfg->etscfg))) {
5556 /* If Priority Table has changed reconfig is needed */
5557 if (memcmp(&new_cfg->etscfg.prioritytable,
5558 &old_cfg->etscfg.prioritytable,
5559 sizeof(new_cfg->etscfg.prioritytable))) {
5560 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005561 dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005562 }
5563
5564 if (memcmp(&new_cfg->etscfg.tcbwtable,
5565 &old_cfg->etscfg.tcbwtable,
5566 sizeof(new_cfg->etscfg.tcbwtable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005567 dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005568
5569 if (memcmp(&new_cfg->etscfg.tsatable,
5570 &old_cfg->etscfg.tsatable,
5571 sizeof(new_cfg->etscfg.tsatable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005572 dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005573 }
5574
5575 /* Check if PFC configuration has changed */
5576 if (memcmp(&new_cfg->pfc,
5577 &old_cfg->pfc,
5578 sizeof(new_cfg->pfc))) {
5579 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005580 dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005581 }
5582
5583 /* Check if APP Table has changed */
5584 if (memcmp(&new_cfg->app,
5585 &old_cfg->app,
Dave Jones3d9667a2014-01-27 23:11:09 -05005586 sizeof(new_cfg->app))) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005587 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005588 dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
Dave Jones3d9667a2014-01-27 23:11:09 -05005589 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005590
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005591 dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005592 return need_reconfig;
5593}
5594
5595/**
5596 * i40e_handle_lldp_event - Handle LLDP Change MIB event
5597 * @pf: board private structure
5598 * @e: event info posted on ARQ
5599 **/
5600static int i40e_handle_lldp_event(struct i40e_pf *pf,
5601 struct i40e_arq_event_info *e)
5602{
5603 struct i40e_aqc_lldp_get_mib *mib =
5604 (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
5605 struct i40e_hw *hw = &pf->hw;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005606 struct i40e_dcbx_config tmp_dcbx_cfg;
5607 bool need_reconfig = false;
5608 int ret = 0;
5609 u8 type;
5610
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005611 /* Not DCB capable or capability disabled */
David Ertmanea6acb72016-09-20 07:10:50 -07005612 if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005613 return ret;
5614
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005615 /* Ignore if event is not for Nearest Bridge */
5616 type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
5617 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005618 dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005619 if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
5620 return ret;
5621
5622 /* Check MIB Type and return if event for Remote MIB update */
5623 type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005624 dev_dbg(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005625 "LLDP event mib type %s\n", type ? "remote" : "local");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005626 if (type == I40E_AQ_LLDP_MIB_REMOTE) {
5627 /* Update the remote cached instance and return */
5628 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
5629 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
5630 &hw->remote_dcbx_config);
5631 goto exit;
5632 }
5633
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005634 /* Store the old configuration */
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07005635 tmp_dcbx_cfg = hw->local_dcbx_config;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005636
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005637 /* Reset the old DCBx configuration data */
5638 memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005639 /* Get updated DCBX data from firmware */
5640 ret = i40e_get_dcb_config(&pf->hw);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005641 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005642 dev_info(&pf->pdev->dev,
5643 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
5644 i40e_stat_str(&pf->hw, ret),
5645 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005646 goto exit;
5647 }
5648
5649 /* No change detected in DCBX configs */
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005650 if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
5651 sizeof(tmp_dcbx_cfg))) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005652 dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005653 goto exit;
5654 }
5655
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005656 need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
5657 &hw->local_dcbx_config);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005658
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005659 i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005660
5661 if (!need_reconfig)
5662 goto exit;
5663
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005664 /* Enable DCB tagging only when more than one TC */
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005665 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005666 pf->flags |= I40E_FLAG_DCB_ENABLED;
5667 else
5668 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
5669
Neerav Parikh69129dc2014-11-12 00:18:46 +00005670 set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005671 /* Reconfiguration needed quiesce all VSIs */
5672 i40e_pf_quiesce_all_vsi(pf);
5673
5674 /* Changes in configuration update VEB/VSI */
5675 i40e_dcb_reconfigure(pf);
5676
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005677 ret = i40e_resume_port_tx(pf);
5678
Neerav Parikh69129dc2014-11-12 00:18:46 +00005679 clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005680 /* In case of error no point in resuming VSIs */
Neerav Parikh69129dc2014-11-12 00:18:46 +00005681 if (ret)
5682 goto exit;
5683
Neerav Parikh3fe06f42016-02-17 16:12:15 -08005684 /* Wait for the PF's queues to be disabled */
5685 ret = i40e_pf_wait_queues_disabled(pf);
Parikh, Neerav11e47702015-02-21 06:43:55 +00005686 if (ret) {
5687 /* Schedule PF reset to recover */
5688 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
5689 i40e_service_event_schedule(pf);
5690 } else {
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005691 i40e_pf_unquiesce_all_vsi(pf);
Neerav Parikh85a1aab2016-06-07 09:14:55 -07005692 /* Notify the client for the DCB changes */
5693 i40e_notify_client_of_l2_param_changes(pf->vsi[pf->lan_vsi]);
Parikh, Neerav11e47702015-02-21 06:43:55 +00005694 }
5695
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005696exit:
5697 return ret;
5698}
5699#endif /* CONFIG_I40E_DCB */
5700
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005701/**
Anjali Singhai Jain233261862013-11-26 10:49:22 +00005702 * i40e_do_reset_safe - Protected reset path for userland calls.
5703 * @pf: board private structure
5704 * @reset_flags: which reset is requested
5705 *
5706 **/
5707void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
5708{
5709 rtnl_lock();
5710 i40e_do_reset(pf, reset_flags);
5711 rtnl_unlock();
5712}
5713
5714/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005715 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
5716 * @pf: board private structure
5717 * @e: event info posted on ARQ
5718 *
5719 * Handler for LAN Queue Overflow Event generated by the firmware for PF
5720 * and VF queues
5721 **/
5722static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
5723 struct i40e_arq_event_info *e)
5724{
5725 struct i40e_aqc_lan_overflow *data =
5726 (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
5727 u32 queue = le32_to_cpu(data->prtdcb_rupto);
5728 u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
5729 struct i40e_hw *hw = &pf->hw;
5730 struct i40e_vf *vf;
5731 u16 vf_id;
5732
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005733 dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
5734 queue, qtx_ctl);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005735
5736 /* Queue belongs to VF, find the VF and issue VF reset */
5737 if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
5738 >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
5739 vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
5740 >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
5741 vf_id -= hw->func_caps.vf_base_id;
5742 vf = &pf->vf[vf_id];
5743 i40e_vc_notify_vf_reset(vf);
5744 /* Allow VF to process pending reset notification */
5745 msleep(20);
5746 i40e_reset_vf(vf, false);
5747 }
5748}
5749
5750/**
5751 * i40e_service_event_complete - Finish up the service event
5752 * @pf: board private structure
5753 **/
5754static void i40e_service_event_complete(struct i40e_pf *pf)
5755{
Shannon Nelsonb875f992015-10-21 19:47:03 -04005756 WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005757
5758 /* flush memory to make sure state is correct before next watchog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005759 smp_mb__before_atomic();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005760 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
5761}
5762
5763/**
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005764 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
5765 * @pf: board private structure
5766 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005767u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005768{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005769 u32 val, fcnt_prog;
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005770
5771 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
5772 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
5773 return fcnt_prog;
5774}
5775
5776/**
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005777 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005778 * @pf: board private structure
5779 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005780u32 i40e_get_current_fd_count(struct i40e_pf *pf)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005781{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005782 u32 val, fcnt_prog;
5783
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005784 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
5785 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
5786 ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
5787 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
5788 return fcnt_prog;
5789}
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005790
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005791/**
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005792 * i40e_get_global_fd_count - Get total FD filters programmed on device
5793 * @pf: board private structure
5794 **/
5795u32 i40e_get_global_fd_count(struct i40e_pf *pf)
5796{
5797 u32 val, fcnt_prog;
5798
5799 val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
5800 fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
5801 ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
5802 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
5803 return fcnt_prog;
5804}
5805
5806/**
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005807 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
5808 * @pf: board private structure
5809 **/
5810void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
5811{
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04005812 struct i40e_fdir_filter *filter;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005813 u32 fcnt_prog, fcnt_avail;
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04005814 struct hlist_node *node;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005815
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005816 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
5817 return;
5818
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005819 /* Check if, FD SB or ATR was auto disabled and if there is enough room
5820 * to re-enable
5821 */
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005822 fcnt_prog = i40e_get_global_fd_count(pf);
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005823 fcnt_avail = pf->fdir_pf_filter_count;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005824 if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
5825 (pf->fd_add_err == 0) ||
5826 (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005827 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
5828 (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
5829 pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04005830 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5831 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 +00005832 }
5833 }
Jacob Kellera3417d22016-09-06 18:05:10 -07005834
5835 /* Wait for some more space to be available to turn on ATR. We also
5836 * must check that no existing ntuple rules for TCP are in effect
5837 */
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005838 if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
5839 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
Jacob Kellera3417d22016-09-06 18:05:10 -07005840 (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED) &&
5841 (pf->fd_tcp_rule == 0)) {
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005842 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04005843 if (I40E_DEBUG_FD & pf->hw.debug_mask)
Jacob Kellera3417d22016-09-06 18:05:10 -07005844 dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005845 }
5846 }
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04005847
5848 /* if hw had a problem adding a filter, delete it */
5849 if (pf->fd_inv > 0) {
5850 hlist_for_each_entry_safe(filter, node,
5851 &pf->fdir_filter_list, fdir_node) {
5852 if (filter->fd_id == pf->fd_inv) {
5853 hlist_del(&filter->fdir_node);
5854 kfree(filter);
5855 pf->fdir_pf_active_filters--;
5856 }
5857 }
5858 }
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005859}
5860
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005861#define I40E_MIN_FD_FLUSH_INTERVAL 10
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005862#define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005863/**
5864 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
5865 * @pf: board private structure
5866 **/
5867static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
5868{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005869 unsigned long min_flush_time;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005870 int flush_wait_retry = 50;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005871 bool disable_atr = false;
5872 int fd_room;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005873 int reg;
5874
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005875 if (!time_after(jiffies, pf->fd_flush_timestamp +
5876 (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
5877 return;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005878
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005879 /* If the flush is happening too quick and we have mostly SB rules we
5880 * should not re-enable ATR for some time.
5881 */
5882 min_flush_time = pf->fd_flush_timestamp +
5883 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
5884 fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005885
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005886 if (!(time_after(jiffies, min_flush_time)) &&
5887 (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
5888 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5889 dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
5890 disable_atr = true;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005891 }
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005892
5893 pf->fd_flush_timestamp = jiffies;
Jacob Keller234dc4e2016-09-06 18:05:09 -07005894 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005895 /* flush all filters */
5896 wr32(&pf->hw, I40E_PFQF_CTL_1,
5897 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
5898 i40e_flush(&pf->hw);
5899 pf->fd_flush_cnt++;
5900 pf->fd_add_err = 0;
5901 do {
5902 /* Check FD flush status every 5-6msec */
5903 usleep_range(5000, 6000);
5904 reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
5905 if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
5906 break;
5907 } while (flush_wait_retry--);
5908 if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
5909 dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
5910 } else {
5911 /* replay sideband filters */
5912 i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
5913 if (!disable_atr)
Jacob Keller234dc4e2016-09-06 18:05:09 -07005914 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04005915 clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
5916 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5917 dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
5918 }
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005919}
5920
5921/**
5922 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
5923 * @pf: board private structure
5924 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005925u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005926{
5927 return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
5928}
5929
5930/* We can see up to 256 filter programming desc in transit if the filters are
5931 * being applied really fast; before we see the first
5932 * filter miss error on Rx queue 0. Accumulating enough error messages before
5933 * reacting will make sure we don't cause flush too often.
5934 */
5935#define I40E_MAX_FD_PROGRAM_ERROR 256
5936
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005937/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005938 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
5939 * @pf: board private structure
5940 **/
5941static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
5942{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005943
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005944 /* if interface is down do nothing */
5945 if (test_bit(__I40E_DOWN, &pf->state))
5946 return;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005947
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005948 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005949 i40e_fdir_flush_and_replay(pf);
5950
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005951 i40e_fdir_check_and_reenable(pf);
5952
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005953}
5954
5955/**
5956 * i40e_vsi_link_event - notify VSI of a link event
5957 * @vsi: vsi to be notified
5958 * @link_up: link up or down
5959 **/
5960static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
5961{
Jesse Brandeburg32b5b812014-08-12 06:33:14 +00005962 if (!vsi || test_bit(__I40E_DOWN, &vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005963 return;
5964
5965 switch (vsi->type) {
5966 case I40E_VSI_MAIN:
Vasu Dev38e00432014-08-01 13:27:03 -07005967#ifdef I40E_FCOE
5968 case I40E_VSI_FCOE:
5969#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005970 if (!vsi->netdev || !vsi->netdev_registered)
5971 break;
5972
5973 if (link_up) {
5974 netif_carrier_on(vsi->netdev);
5975 netif_tx_wake_all_queues(vsi->netdev);
5976 } else {
5977 netif_carrier_off(vsi->netdev);
5978 netif_tx_stop_all_queues(vsi->netdev);
5979 }
5980 break;
5981
5982 case I40E_VSI_SRIOV:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005983 case I40E_VSI_VMDQ2:
5984 case I40E_VSI_CTRL:
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06005985 case I40E_VSI_IWARP:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005986 case I40E_VSI_MIRROR:
5987 default:
5988 /* there is no notification for other VSIs */
5989 break;
5990 }
5991}
5992
5993/**
5994 * i40e_veb_link_event - notify elements on the veb of a link event
5995 * @veb: veb to be notified
5996 * @link_up: link up or down
5997 **/
5998static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
5999{
6000 struct i40e_pf *pf;
6001 int i;
6002
6003 if (!veb || !veb->pf)
6004 return;
6005 pf = veb->pf;
6006
6007 /* depth first... */
6008 for (i = 0; i < I40E_MAX_VEB; i++)
6009 if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
6010 i40e_veb_link_event(pf->veb[i], link_up);
6011
6012 /* ... now the local VSIs */
Mitch Williams505682c2014-05-20 08:01:37 +00006013 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006014 if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
6015 i40e_vsi_link_event(pf->vsi[i], link_up);
6016}
6017
6018/**
6019 * i40e_link_event - Update netif_carrier status
6020 * @pf: board private structure
6021 **/
6022static void i40e_link_event(struct i40e_pf *pf)
6023{
Mitch Williams320684c2014-10-17 03:14:43 +00006024 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006025 u8 new_link_speed, old_link_speed;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006026 i40e_status status;
6027 bool new_link, old_link;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006028
Catherine Sullivan1f9610e2015-10-21 19:47:09 -04006029 /* save off old link status information */
6030 pf->hw.phy.link_info_old = pf->hw.phy.link_info;
6031
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006032 /* set this to force the get_link_status call to refresh state */
6033 pf->hw.phy.get_link_info = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006034
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006035 old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006036
6037 status = i40e_get_link_status(&pf->hw, &new_link);
6038 if (status) {
6039 dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
6040 status);
6041 return;
6042 }
6043
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006044 old_link_speed = pf->hw.phy.link_info_old.link_speed;
6045 new_link_speed = pf->hw.phy.link_info.link_speed;
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006046
6047 if (new_link == old_link &&
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006048 new_link_speed == old_link_speed &&
Mitch Williams320684c2014-10-17 03:14:43 +00006049 (test_bit(__I40E_DOWN, &vsi->state) ||
6050 new_link == netif_carrier_ok(vsi->netdev)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006051 return;
Mitch Williams320684c2014-10-17 03:14:43 +00006052
6053 if (!test_bit(__I40E_DOWN, &vsi->state))
6054 i40e_print_link_message(vsi, new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006055
6056 /* Notify the base of the switch tree connected to
6057 * the link. Floating VEBs are not notified.
6058 */
6059 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
6060 i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
6061 else
Mitch Williams320684c2014-10-17 03:14:43 +00006062 i40e_vsi_link_event(vsi, new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006063
6064 if (pf->vf)
6065 i40e_vc_notify_link_state(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00006066
6067 if (pf->flags & I40E_FLAG_PTP)
6068 i40e_ptp_set_increment(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006069}
6070
6071/**
Shannon Nelson21536712014-10-25 10:35:25 +00006072 * i40e_watchdog_subtask - periodic checks not using event driven response
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006073 * @pf: board private structure
6074 **/
6075static void i40e_watchdog_subtask(struct i40e_pf *pf)
6076{
6077 int i;
6078
6079 /* if interface is down do nothing */
6080 if (test_bit(__I40E_DOWN, &pf->state) ||
6081 test_bit(__I40E_CONFIG_BUSY, &pf->state))
6082 return;
6083
Shannon Nelson21536712014-10-25 10:35:25 +00006084 /* make sure we don't do these things too often */
6085 if (time_before(jiffies, (pf->service_timer_previous +
6086 pf->service_timer_period)))
6087 return;
6088 pf->service_timer_previous = jiffies;
6089
Shannon Nelson9ac77262015-08-27 11:42:40 -04006090 if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED)
6091 i40e_link_event(pf);
Shannon Nelson21536712014-10-25 10:35:25 +00006092
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006093 /* Update the stats for active netdevs so the network stack
6094 * can look at updated numbers whenever it cares to
6095 */
Mitch Williams505682c2014-05-20 08:01:37 +00006096 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006097 if (pf->vsi[i] && pf->vsi[i]->netdev)
6098 i40e_update_stats(pf->vsi[i]);
6099
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04006100 if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
6101 /* Update the stats for the active switching components */
6102 for (i = 0; i < I40E_MAX_VEB; i++)
6103 if (pf->veb[i])
6104 i40e_update_veb_stats(pf->veb[i]);
6105 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00006106
6107 i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006108}
6109
6110/**
6111 * i40e_reset_subtask - Set up for resetting the device and driver
6112 * @pf: board private structure
6113 **/
6114static void i40e_reset_subtask(struct i40e_pf *pf)
6115{
6116 u32 reset_flags = 0;
6117
Anjali Singhai Jain233261862013-11-26 10:49:22 +00006118 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006119 if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006120 reset_flags |= BIT(__I40E_REINIT_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006121 clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
6122 }
6123 if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006124 reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006125 clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
6126 }
6127 if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006128 reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006129 clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
6130 }
6131 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006132 reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006133 clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
6134 }
Neerav Parikhb5d06f02014-06-03 23:50:17 +00006135 if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006136 reset_flags |= BIT(__I40E_DOWN_REQUESTED);
Neerav Parikhb5d06f02014-06-03 23:50:17 +00006137 clear_bit(__I40E_DOWN_REQUESTED, &pf->state);
6138 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006139
6140 /* If there's a recovery already waiting, it takes
6141 * precedence before starting a new reset sequence.
6142 */
6143 if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
6144 i40e_handle_reset_warning(pf);
Anjali Singhai Jain233261862013-11-26 10:49:22 +00006145 goto unlock;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006146 }
6147
6148 /* If we're already down or resetting, just bail */
6149 if (reset_flags &&
6150 !test_bit(__I40E_DOWN, &pf->state) &&
6151 !test_bit(__I40E_CONFIG_BUSY, &pf->state))
6152 i40e_do_reset(pf, reset_flags);
Anjali Singhai Jain233261862013-11-26 10:49:22 +00006153
6154unlock:
6155 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006156}
6157
6158/**
6159 * i40e_handle_link_event - Handle link event
6160 * @pf: board private structure
6161 * @e: event info posted on ARQ
6162 **/
6163static void i40e_handle_link_event(struct i40e_pf *pf,
6164 struct i40e_arq_event_info *e)
6165{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006166 struct i40e_aqc_get_link_status *status =
6167 (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006168
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006169 /* Do a new status request to re-enable LSE reporting
6170 * and load new status information into the hw struct
6171 * This completely ignores any state information
6172 * in the ARQ event info, instead choosing to always
6173 * issue the AQ update link status command.
6174 */
6175 i40e_link_event(pf);
6176
Carolyn Wyborny7b592f62014-07-10 07:58:19 +00006177 /* check for unqualified module, if link is down */
6178 if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
6179 (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
6180 (!(status->link_info & I40E_AQ_LINK_UP)))
6181 dev_err(&pf->pdev->dev,
6182 "The driver failed to link because an unqualified module was detected.\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006183}
6184
6185/**
6186 * i40e_clean_adminq_subtask - Clean the AdminQ rings
6187 * @pf: board private structure
6188 **/
6189static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
6190{
6191 struct i40e_arq_event_info event;
6192 struct i40e_hw *hw = &pf->hw;
6193 u16 pending, i = 0;
6194 i40e_status ret;
6195 u16 opcode;
Shannon Nelson86df2422014-05-20 08:01:35 +00006196 u32 oldval;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006197 u32 val;
6198
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006199 /* Do not run clean AQ when PF reset fails */
6200 if (test_bit(__I40E_RESET_FAILED, &pf->state))
6201 return;
6202
Shannon Nelson86df2422014-05-20 08:01:35 +00006203 /* check for error indications */
6204 val = rd32(&pf->hw, pf->hw.aq.arq.len);
6205 oldval = val;
6206 if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006207 if (hw->debug_mask & I40E_DEBUG_AQ)
6208 dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006209 val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
6210 }
6211 if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006212 if (hw->debug_mask & I40E_DEBUG_AQ)
6213 dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006214 val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
Mitch Williams1d0a4ad2015-12-23 12:05:48 -08006215 pf->arq_overflows++;
Shannon Nelson86df2422014-05-20 08:01:35 +00006216 }
6217 if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006218 if (hw->debug_mask & I40E_DEBUG_AQ)
6219 dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006220 val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
6221 }
6222 if (oldval != val)
6223 wr32(&pf->hw, pf->hw.aq.arq.len, val);
6224
6225 val = rd32(&pf->hw, pf->hw.aq.asq.len);
6226 oldval = val;
6227 if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006228 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6229 dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006230 val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
6231 }
6232 if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006233 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6234 dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006235 val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
6236 }
6237 if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006238 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6239 dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006240 val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
6241 }
6242 if (oldval != val)
6243 wr32(&pf->hw, pf->hw.aq.asq.len, val);
6244
Mitch Williams1001dc32014-11-11 20:02:19 +00006245 event.buf_len = I40E_MAX_AQ_BUF_SIZE;
6246 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006247 if (!event.msg_buf)
6248 return;
6249
6250 do {
6251 ret = i40e_clean_arq_element(hw, &event, &pending);
Mitch Williams56497972014-06-04 08:45:18 +00006252 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006253 break;
Mitch Williams56497972014-06-04 08:45:18 +00006254 else if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006255 dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
6256 break;
6257 }
6258
6259 opcode = le16_to_cpu(event.desc.opcode);
6260 switch (opcode) {
6261
6262 case i40e_aqc_opc_get_link_status:
6263 i40e_handle_link_event(pf, &event);
6264 break;
6265 case i40e_aqc_opc_send_msg_to_pf:
6266 ret = i40e_vc_process_vf_msg(pf,
6267 le16_to_cpu(event.desc.retval),
6268 le32_to_cpu(event.desc.cookie_high),
6269 le32_to_cpu(event.desc.cookie_low),
6270 event.msg_buf,
Mitch Williams1001dc32014-11-11 20:02:19 +00006271 event.msg_len);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006272 break;
6273 case i40e_aqc_opc_lldp_update_mib:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006274 dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006275#ifdef CONFIG_I40E_DCB
6276 rtnl_lock();
6277 ret = i40e_handle_lldp_event(pf, &event);
6278 rtnl_unlock();
6279#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006280 break;
6281 case i40e_aqc_opc_event_lan_overflow:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006282 dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006283 i40e_handle_lan_overflow_event(pf, &event);
6284 break;
Shannon Nelson0467bc92013-12-18 13:45:58 +00006285 case i40e_aqc_opc_send_msg_to_peer:
6286 dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
6287 break;
Shannon Nelson91a0f932015-03-19 14:32:01 -07006288 case i40e_aqc_opc_nvm_erase:
6289 case i40e_aqc_opc_nvm_update:
Michal Kosiarz00ada502015-11-19 11:34:20 -08006290 case i40e_aqc_opc_oem_post_update:
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08006291 i40e_debug(&pf->hw, I40E_DEBUG_NVM,
6292 "ARQ NVM operation 0x%04x completed\n",
6293 opcode);
Shannon Nelson91a0f932015-03-19 14:32:01 -07006294 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006295 default:
6296 dev_info(&pf->pdev->dev,
Shannon Nelson56e5ca62016-03-10 14:59:48 -08006297 "ARQ: Unknown event 0x%04x ignored\n",
Shannon Nelson0467bc92013-12-18 13:45:58 +00006298 opcode);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006299 break;
6300 }
6301 } while (pending && (i++ < pf->adminq_work_limit));
6302
6303 clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
6304 /* re-enable Admin queue interrupt cause */
6305 val = rd32(hw, I40E_PFINT_ICR0_ENA);
6306 val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
6307 wr32(hw, I40E_PFINT_ICR0_ENA, val);
6308 i40e_flush(hw);
6309
6310 kfree(event.msg_buf);
6311}
6312
6313/**
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006314 * i40e_verify_eeprom - make sure eeprom is good to use
6315 * @pf: board private structure
6316 **/
6317static void i40e_verify_eeprom(struct i40e_pf *pf)
6318{
6319 int err;
6320
6321 err = i40e_diag_eeprom_test(&pf->hw);
6322 if (err) {
6323 /* retry in case of garbage read */
6324 err = i40e_diag_eeprom_test(&pf->hw);
6325 if (err) {
6326 dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
6327 err);
6328 set_bit(__I40E_BAD_EEPROM, &pf->state);
6329 }
6330 }
6331
6332 if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
6333 dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
6334 clear_bit(__I40E_BAD_EEPROM, &pf->state);
6335 }
6336}
6337
6338/**
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006339 * i40e_enable_pf_switch_lb
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006340 * @pf: pointer to the PF structure
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006341 *
6342 * enable switch loop back or die - no point in a return value
6343 **/
6344static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
6345{
6346 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6347 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006348 int ret;
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006349
6350 ctxt.seid = pf->main_vsi_seid;
6351 ctxt.pf_num = pf->hw.pf_id;
6352 ctxt.vf_num = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006353 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6354 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006355 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006356 "couldn't get PF vsi config, err %s aq_err %s\n",
6357 i40e_stat_str(&pf->hw, ret),
6358 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006359 return;
6360 }
6361 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6362 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6363 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6364
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006365 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6366 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006367 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006368 "update vsi switch failed, err %s aq_err %s\n",
6369 i40e_stat_str(&pf->hw, ret),
6370 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006371 }
6372}
6373
6374/**
6375 * i40e_disable_pf_switch_lb
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006376 * @pf: pointer to the PF structure
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006377 *
6378 * disable switch loop back or die - no point in a return value
6379 **/
6380static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
6381{
6382 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6383 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006384 int ret;
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006385
6386 ctxt.seid = pf->main_vsi_seid;
6387 ctxt.pf_num = pf->hw.pf_id;
6388 ctxt.vf_num = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006389 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6390 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006391 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006392 "couldn't get PF vsi config, err %s aq_err %s\n",
6393 i40e_stat_str(&pf->hw, ret),
6394 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006395 return;
6396 }
6397 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6398 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6399 ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6400
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006401 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6402 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006403 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006404 "update vsi switch failed, err %s aq_err %s\n",
6405 i40e_stat_str(&pf->hw, ret),
6406 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006407 }
6408}
6409
6410/**
Neerav Parikh51616012015-02-06 08:52:14 +00006411 * i40e_config_bridge_mode - Configure the HW bridge mode
6412 * @veb: pointer to the bridge instance
6413 *
6414 * Configure the loop back mode for the LAN VSI that is downlink to the
6415 * specified HW bridge instance. It is expected this function is called
6416 * when a new HW bridge is instantiated.
6417 **/
6418static void i40e_config_bridge_mode(struct i40e_veb *veb)
6419{
6420 struct i40e_pf *pf = veb->pf;
6421
Shannon Nelson6dec1012015-09-28 14:12:30 -04006422 if (pf->hw.debug_mask & I40E_DEBUG_LAN)
6423 dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
6424 veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
Neerav Parikh51616012015-02-06 08:52:14 +00006425 if (veb->bridge_mode & BRIDGE_MODE_VEPA)
6426 i40e_disable_pf_switch_lb(pf);
6427 else
6428 i40e_enable_pf_switch_lb(pf);
6429}
6430
6431/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006432 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
6433 * @veb: pointer to the VEB instance
6434 *
6435 * This is a recursive function that first builds the attached VSIs then
6436 * recurses in to build the next layer of VEB. We track the connections
6437 * through our own index numbers because the seid's from the HW could
6438 * change across the reset.
6439 **/
6440static int i40e_reconstitute_veb(struct i40e_veb *veb)
6441{
6442 struct i40e_vsi *ctl_vsi = NULL;
6443 struct i40e_pf *pf = veb->pf;
6444 int v, veb_idx;
6445 int ret;
6446
6447 /* build VSI that owns this VEB, temporarily attached to base VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00006448 for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006449 if (pf->vsi[v] &&
6450 pf->vsi[v]->veb_idx == veb->idx &&
6451 pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
6452 ctl_vsi = pf->vsi[v];
6453 break;
6454 }
6455 }
6456 if (!ctl_vsi) {
6457 dev_info(&pf->pdev->dev,
6458 "missing owner VSI for veb_idx %d\n", veb->idx);
6459 ret = -ENOENT;
6460 goto end_reconstitute;
6461 }
6462 if (ctl_vsi != pf->vsi[pf->lan_vsi])
6463 ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
6464 ret = i40e_add_vsi(ctl_vsi);
6465 if (ret) {
6466 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006467 "rebuild of veb_idx %d owner VSI failed: %d\n",
6468 veb->idx, ret);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006469 goto end_reconstitute;
6470 }
6471 i40e_vsi_reset_stats(ctl_vsi);
6472
6473 /* create the VEB in the switch and move the VSI onto the VEB */
6474 ret = i40e_add_veb(veb, ctl_vsi);
6475 if (ret)
6476 goto end_reconstitute;
6477
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07006478 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
6479 veb->bridge_mode = BRIDGE_MODE_VEB;
6480 else
6481 veb->bridge_mode = BRIDGE_MODE_VEPA;
Neerav Parikh51616012015-02-06 08:52:14 +00006482 i40e_config_bridge_mode(veb);
Anjali Singhai Jainb64ba082014-11-13 03:06:15 +00006483
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006484 /* create the remaining VSIs attached to this VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00006485 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006486 if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
6487 continue;
6488
6489 if (pf->vsi[v]->veb_idx == veb->idx) {
6490 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04006491
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006492 vsi->uplink_seid = veb->seid;
6493 ret = i40e_add_vsi(vsi);
6494 if (ret) {
6495 dev_info(&pf->pdev->dev,
6496 "rebuild of vsi_idx %d failed: %d\n",
6497 v, ret);
6498 goto end_reconstitute;
6499 }
6500 i40e_vsi_reset_stats(vsi);
6501 }
6502 }
6503
6504 /* create any VEBs attached to this VEB - RECURSION */
6505 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
6506 if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
6507 pf->veb[veb_idx]->uplink_seid = veb->seid;
6508 ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
6509 if (ret)
6510 break;
6511 }
6512 }
6513
6514end_reconstitute:
6515 return ret;
6516}
6517
6518/**
6519 * i40e_get_capabilities - get info about the HW
6520 * @pf: the PF struct
6521 **/
6522static int i40e_get_capabilities(struct i40e_pf *pf)
6523{
6524 struct i40e_aqc_list_capabilities_element_resp *cap_buf;
6525 u16 data_size;
6526 int buf_len;
6527 int err;
6528
6529 buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
6530 do {
6531 cap_buf = kzalloc(buf_len, GFP_KERNEL);
6532 if (!cap_buf)
6533 return -ENOMEM;
6534
6535 /* this loads the data into the hw struct for us */
6536 err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
6537 &data_size,
6538 i40e_aqc_opc_list_func_capabilities,
6539 NULL);
6540 /* data loaded, buffer no longer needed */
6541 kfree(cap_buf);
6542
6543 if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
6544 /* retry with a larger buffer */
6545 buf_len = data_size;
6546 } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
6547 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006548 "capability discovery failed, err %s aq_err %s\n",
6549 i40e_stat_str(&pf->hw, err),
6550 i40e_aq_str(&pf->hw,
6551 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006552 return -ENODEV;
6553 }
6554 } while (err);
6555
6556 if (pf->hw.debug_mask & I40E_DEBUG_USER)
6557 dev_info(&pf->pdev->dev,
6558 "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",
6559 pf->hw.pf_id, pf->hw.func_caps.num_vfs,
6560 pf->hw.func_caps.num_msix_vectors,
6561 pf->hw.func_caps.num_msix_vectors_vf,
6562 pf->hw.func_caps.fd_filters_guaranteed,
6563 pf->hw.func_caps.fd_filters_best_effort,
6564 pf->hw.func_caps.num_tx_qp,
6565 pf->hw.func_caps.num_vsis);
6566
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00006567#define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
6568 + pf->hw.func_caps.num_vfs)
6569 if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
6570 dev_info(&pf->pdev->dev,
6571 "got num_vsis %d, setting num_vsis to %d\n",
6572 pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
6573 pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
6574 }
6575
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006576 return 0;
6577}
6578
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006579static int i40e_vsi_clear(struct i40e_vsi *vsi);
6580
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006581/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006582 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006583 * @pf: board private structure
6584 **/
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006585static void i40e_fdir_sb_setup(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006586{
6587 struct i40e_vsi *vsi;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006588 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006589
Jesse Brandeburg407e0632014-06-03 23:50:12 +00006590 /* quick workaround for an NVM issue that leaves a critical register
6591 * uninitialized
6592 */
6593 if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
6594 static const u32 hkey[] = {
6595 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
6596 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
6597 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
6598 0x95b3a76d};
6599
6600 for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
6601 wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
6602 }
6603
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006604 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006605 return;
6606
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006607 /* find existing VSI and see if it needs configuring */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006608 vsi = NULL;
Mitch Williams505682c2014-05-20 08:01:37 +00006609 for (i = 0; i < pf->num_alloc_vsi; i++) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006610 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006611 vsi = pf->vsi[i];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006612 break;
6613 }
6614 }
6615
6616 /* create a new VSI if none exists */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006617 if (!vsi) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006618 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
6619 pf->vsi[pf->lan_vsi]->seid, 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006620 if (!vsi) {
6621 dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006622 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
6623 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006624 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006625 }
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006626
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006627 i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006628}
6629
6630/**
6631 * i40e_fdir_teardown - release the Flow Director resources
6632 * @pf: board private structure
6633 **/
6634static void i40e_fdir_teardown(struct i40e_pf *pf)
6635{
6636 int i;
6637
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00006638 i40e_fdir_filter_exit(pf);
Mitch Williams505682c2014-05-20 08:01:37 +00006639 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006640 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
6641 i40e_vsi_release(pf->vsi[i]);
6642 break;
6643 }
6644 }
6645}
6646
6647/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006648 * i40e_prep_for_reset - prep for the core to reset
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006649 * @pf: board private structure
6650 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006651 * Close up the VFs and other things in prep for PF Reset.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006652 **/
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006653static void i40e_prep_for_reset(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006654{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006655 struct i40e_hw *hw = &pf->hw;
Shannon Nelson60442de2014-04-23 04:50:13 +00006656 i40e_status ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006657 u32 v;
6658
6659 clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
6660 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006661 return;
Mitch Williamsd3ce57342016-03-10 14:59:46 -08006662 if (i40e_check_asq_alive(&pf->hw))
6663 i40e_vc_notify_reset(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006664
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006665 dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006666
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006667 /* quiesce the VSIs and their queues that are not already DOWN */
6668 i40e_pf_quiesce_all_vsi(pf);
6669
Mitch Williams505682c2014-05-20 08:01:37 +00006670 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006671 if (pf->vsi[v])
6672 pf->vsi[v]->seid = 0;
6673 }
6674
6675 i40e_shutdown_adminq(&pf->hw);
6676
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006677 /* call shutdown HMC */
Shannon Nelson60442de2014-04-23 04:50:13 +00006678 if (hw->hmc.hmc_obj) {
6679 ret = i40e_shutdown_lan_hmc(hw);
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006680 if (ret)
Shannon Nelson60442de2014-04-23 04:50:13 +00006681 dev_warn(&pf->pdev->dev,
6682 "shutdown_lan_hmc failed: %d\n", ret);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006683 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006684}
6685
6686/**
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00006687 * i40e_send_version - update firmware with driver version
6688 * @pf: PF struct
6689 */
6690static void i40e_send_version(struct i40e_pf *pf)
6691{
6692 struct i40e_driver_version dv;
6693
6694 dv.major_version = DRV_VERSION_MAJOR;
6695 dv.minor_version = DRV_VERSION_MINOR;
6696 dv.build_version = DRV_VERSION_BUILD;
6697 dv.subbuild_version = 0;
Rickard Strandqvist35a7d802014-07-29 09:26:25 +00006698 strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00006699 i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
6700}
6701
6702/**
Jesse Brandeburg4dda12e2013-12-18 13:46:01 +00006703 * i40e_reset_and_rebuild - reset and rebuild using a saved config
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006704 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006705 * @reinit: if the Main VSI needs to re-initialized.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006706 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006707static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006708{
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006709 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006710 u8 set_fc_aq_fail = 0;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006711 i40e_status ret;
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -04006712 u32 val;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006713 u32 v;
6714
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006715 /* Now we wait for GRST to settle out.
6716 * We don't have to delete the VEBs or VSIs from the hw switch
6717 * because the reset will make them disappear.
6718 */
6719 ret = i40e_pf_reset(hw);
Akeem G Abodunrinb5565402014-04-09 05:59:04 +00006720 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006721 dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006722 set_bit(__I40E_RESET_FAILED, &pf->state);
6723 goto clear_recovery;
Akeem G Abodunrinb5565402014-04-09 05:59:04 +00006724 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006725 pf->pfr_count++;
6726
6727 if (test_bit(__I40E_DOWN, &pf->state))
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006728 goto clear_recovery;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006729 dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006730
6731 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
6732 ret = i40e_init_adminq(&pf->hw);
6733 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006734 dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
6735 i40e_stat_str(&pf->hw, ret),
6736 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006737 goto clear_recovery;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006738 }
6739
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006740 /* re-verify the eeprom if we just had an EMP reset */
Anjali Singhai Jain9df42d12015-01-24 09:58:40 +00006741 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state))
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006742 i40e_verify_eeprom(pf);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006743
Shannon Nelsone78ac4bf2014-05-10 04:49:09 +00006744 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006745 ret = i40e_get_capabilities(pf);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006746 if (ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006747 goto end_core_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006748
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006749 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
6750 hw->func_caps.num_rx_qp,
6751 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
6752 if (ret) {
6753 dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
6754 goto end_core_reset;
6755 }
6756 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
6757 if (ret) {
6758 dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
6759 goto end_core_reset;
6760 }
6761
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006762#ifdef CONFIG_I40E_DCB
6763 ret = i40e_init_pf_dcb(pf);
6764 if (ret) {
Shannon Nelsonaebfc812014-12-11 07:06:38 +00006765 dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
6766 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
6767 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006768 }
6769#endif /* CONFIG_I40E_DCB */
Vasu Dev38e00432014-08-01 13:27:03 -07006770#ifdef I40E_FCOE
Shannon Nelson21364bc2015-08-26 15:14:13 -04006771 i40e_init_pf_fcoe(pf);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006772
Vasu Dev38e00432014-08-01 13:27:03 -07006773#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006774 /* do basic switch setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006775 ret = i40e_setup_pf_switch(pf, reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006776 if (ret)
6777 goto end_core_reset;
6778
Shannon Nelson2f0aff42016-01-04 10:33:08 -08006779 /* The driver only wants link up/down and module qualification
6780 * reports from firmware. Note the negative logic.
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00006781 */
6782 ret = i40e_aq_set_phy_int_mask(&pf->hw,
Shannon Nelson2f0aff42016-01-04 10:33:08 -08006783 ~(I40E_AQ_EVENT_LINK_UPDOWN |
Shannon Nelson867a79e2016-03-18 12:18:15 -07006784 I40E_AQ_EVENT_MEDIA_NA |
Shannon Nelson2f0aff42016-01-04 10:33:08 -08006785 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00006786 if (ret)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006787 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
6788 i40e_stat_str(&pf->hw, ret),
6789 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00006790
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006791 /* make sure our flow control settings are restored */
6792 ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
6793 if (ret)
Neerav Parikh8279e492015-09-03 17:18:50 -04006794 dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
6795 i40e_stat_str(&pf->hw, ret),
6796 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006797
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006798 /* Rebuild the VSIs and VEBs that existed before reset.
6799 * They are still in our local switch element arrays, so only
6800 * need to rebuild the switch model in the HW.
6801 *
6802 * If there were VEBs but the reconstitution failed, we'll try
6803 * try to recover minimal use by getting the basic PF VSI working.
6804 */
6805 if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006806 dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006807 /* find the one VEB connected to the MAC, and find orphans */
6808 for (v = 0; v < I40E_MAX_VEB; v++) {
6809 if (!pf->veb[v])
6810 continue;
6811
6812 if (pf->veb[v]->uplink_seid == pf->mac_seid ||
6813 pf->veb[v]->uplink_seid == 0) {
6814 ret = i40e_reconstitute_veb(pf->veb[v]);
6815
6816 if (!ret)
6817 continue;
6818
6819 /* If Main VEB failed, we're in deep doodoo,
6820 * so give up rebuilding the switch and set up
6821 * for minimal rebuild of PF VSI.
6822 * If orphan failed, we'll report the error
6823 * but try to keep going.
6824 */
6825 if (pf->veb[v]->uplink_seid == pf->mac_seid) {
6826 dev_info(&pf->pdev->dev,
6827 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
6828 ret);
6829 pf->vsi[pf->lan_vsi]->uplink_seid
6830 = pf->mac_seid;
6831 break;
6832 } else if (pf->veb[v]->uplink_seid == 0) {
6833 dev_info(&pf->pdev->dev,
6834 "rebuild of orphan VEB failed: %d\n",
6835 ret);
6836 }
6837 }
6838 }
6839 }
6840
6841 if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
Shannon Nelsoncde4cbc2014-06-04 01:23:17 +00006842 dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006843 /* no VEB, so rebuild only the Main VSI */
6844 ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
6845 if (ret) {
6846 dev_info(&pf->pdev->dev,
6847 "rebuild of Main VSI failed: %d\n", ret);
6848 goto end_core_reset;
6849 }
6850 }
6851
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -04006852 /* Reconfigure hardware for allowing smaller MSS in the case
6853 * of TSO, so that we avoid the MDD being fired and causing
6854 * a reset in the case of small MSS+TSO.
6855 */
6856#define I40E_REG_MSS 0x000E64DC
6857#define I40E_REG_MSS_MIN_MASK 0x3FF0000
6858#define I40E_64BYTE_MSS 0x400000
6859 val = rd32(hw, I40E_REG_MSS);
6860 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
6861 val &= ~I40E_REG_MSS_MIN_MASK;
6862 val |= I40E_64BYTE_MSS;
6863 wr32(hw, I40E_REG_MSS, val);
6864 }
6865
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08006866 if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00006867 msleep(75);
6868 ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
6869 if (ret)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006870 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
6871 i40e_stat_str(&pf->hw, ret),
6872 i40e_aq_str(&pf->hw,
6873 pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006874 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006875 /* reinit the misc interrupt */
6876 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
6877 ret = i40e_setup_misc_vector(pf);
6878
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04006879 /* Add a filter to drop all Flow control frames from any VSI from being
6880 * transmitted. By doing so we stop a malicious VF from sending out
6881 * PAUSE or PFC frames and potentially controlling traffic for other
6882 * PF/VF VSIs.
6883 * The FW can still send Flow control frames if enabled.
6884 */
6885 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
6886 pf->main_vsi_seid);
6887
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006888 /* restart the VSIs that were rebuilt and running before the reset */
6889 i40e_pf_unquiesce_all_vsi(pf);
6890
Mitch Williams69f64b22014-02-13 03:48:46 -08006891 if (pf->num_alloc_vfs) {
6892 for (v = 0; v < pf->num_alloc_vfs; v++)
6893 i40e_reset_vf(&pf->vf[v], true);
6894 }
6895
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006896 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00006897 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006898
6899end_core_reset:
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006900 clear_bit(__I40E_RESET_FAILED, &pf->state);
6901clear_recovery:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006902 clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
6903}
6904
6905/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006906 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006907 * @pf: board private structure
6908 *
6909 * Close up the VFs and other things in prep for a Core Reset,
6910 * then get ready to rebuild the world.
6911 **/
6912static void i40e_handle_reset_warning(struct i40e_pf *pf)
6913{
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006914 i40e_prep_for_reset(pf);
6915 i40e_reset_and_rebuild(pf, false);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006916}
6917
6918/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006919 * i40e_handle_mdd_event
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006920 * @pf: pointer to the PF structure
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006921 *
6922 * Called from the MDD irq handler to identify possibly malicious vfs
6923 **/
6924static void i40e_handle_mdd_event(struct i40e_pf *pf)
6925{
6926 struct i40e_hw *hw = &pf->hw;
6927 bool mdd_detected = false;
Neerav Parikhdf430b12014-06-04 01:23:15 +00006928 bool pf_mdd_detected = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006929 struct i40e_vf *vf;
6930 u32 reg;
6931 int i;
6932
6933 if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
6934 return;
6935
6936 /* find what triggered the MDD event */
6937 reg = rd32(hw, I40E_GL_MDET_TX);
6938 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006939 u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
6940 I40E_GL_MDET_TX_PF_NUM_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00006941 u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006942 I40E_GL_MDET_TX_VF_NUM_SHIFT;
Dan Carpenter013f6572014-10-22 20:06:29 -07006943 u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006944 I40E_GL_MDET_TX_EVENT_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00006945 u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
6946 I40E_GL_MDET_TX_QUEUE_SHIFT) -
6947 pf->hw.func_caps.base_queue;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00006948 if (netif_msg_tx_err(pf))
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00006949 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 +00006950 event, queue, pf_num, vf_num);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006951 wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
6952 mdd_detected = true;
6953 }
6954 reg = rd32(hw, I40E_GL_MDET_RX);
6955 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006956 u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
6957 I40E_GL_MDET_RX_FUNCTION_SHIFT;
Dan Carpenter013f6572014-10-22 20:06:29 -07006958 u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00006959 I40E_GL_MDET_RX_EVENT_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00006960 u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
6961 I40E_GL_MDET_RX_QUEUE_SHIFT) -
6962 pf->hw.func_caps.base_queue;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00006963 if (netif_msg_rx_err(pf))
6964 dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
6965 event, queue, func);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006966 wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
6967 mdd_detected = true;
6968 }
6969
Neerav Parikhdf430b12014-06-04 01:23:15 +00006970 if (mdd_detected) {
6971 reg = rd32(hw, I40E_PF_MDET_TX);
6972 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
6973 wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00006974 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
Neerav Parikhdf430b12014-06-04 01:23:15 +00006975 pf_mdd_detected = true;
6976 }
6977 reg = rd32(hw, I40E_PF_MDET_RX);
6978 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
6979 wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00006980 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
Neerav Parikhdf430b12014-06-04 01:23:15 +00006981 pf_mdd_detected = true;
6982 }
6983 /* Queue belongs to the PF, initiate a reset */
6984 if (pf_mdd_detected) {
6985 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
6986 i40e_service_event_schedule(pf);
6987 }
6988 }
6989
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006990 /* see if one of the VFs needs its hand slapped */
6991 for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
6992 vf = &(pf->vf[i]);
6993 reg = rd32(hw, I40E_VP_MDET_TX(i));
6994 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
6995 wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
6996 vf->num_mdd_events++;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00006997 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
6998 i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006999 }
7000
7001 reg = rd32(hw, I40E_VP_MDET_RX(i));
7002 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
7003 wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
7004 vf->num_mdd_events++;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007005 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
7006 i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007007 }
7008
7009 if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
7010 dev_info(&pf->pdev->dev,
7011 "Too many MDD events on VF %d, disabled\n", i);
7012 dev_info(&pf->pdev->dev,
7013 "Use PF Control I/F to re-enable the VF\n");
7014 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
7015 }
7016 }
7017
7018 /* re-enable mdd interrupt cause */
7019 clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
7020 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
7021 reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
7022 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
7023 i40e_flush(hw);
7024}
7025
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007026/**
Singhai, Anjali6a899022015-12-14 12:21:18 -08007027 * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007028 * @pf: board private structure
7029 **/
Singhai, Anjali6a899022015-12-14 12:21:18 -08007030static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007031{
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007032 struct i40e_hw *hw = &pf->hw;
7033 i40e_status ret;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007034 __be16 port;
7035 int i;
7036
Singhai, Anjali6a899022015-12-14 12:21:18 -08007037 if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC))
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007038 return;
7039
Singhai, Anjali6a899022015-12-14 12:21:18 -08007040 pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007041
7042 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
Singhai, Anjali6a899022015-12-14 12:21:18 -08007043 if (pf->pending_udp_bitmap & BIT_ULL(i)) {
7044 pf->pending_udp_bitmap &= ~BIT_ULL(i);
7045 port = pf->udp_ports[i].index;
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007046 if (port)
Carolyn Wybornyb3f5c7b2016-08-24 11:33:51 -07007047 ret = i40e_aq_add_udp_tunnel(hw, port,
7048 pf->udp_ports[i].type,
7049 NULL, NULL);
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007050 else
7051 ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007052
7053 if (ret) {
Carolyn Wyborny730a8f82016-02-17 16:12:16 -08007054 dev_dbg(&pf->pdev->dev,
7055 "%s %s port %d, index %d failed, err %s aq_err %s\n",
7056 pf->udp_ports[i].type ? "vxlan" : "geneve",
7057 port ? "add" : "delete",
7058 ntohs(port), i,
7059 i40e_stat_str(&pf->hw, ret),
7060 i40e_aq_str(&pf->hw,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007061 pf->hw.aq.asq_last_status));
Singhai, Anjali6a899022015-12-14 12:21:18 -08007062 pf->udp_ports[i].index = 0;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007063 }
7064 }
7065 }
7066}
7067
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007068/**
7069 * i40e_service_task - Run the driver's async subtasks
7070 * @work: pointer to work_struct containing our data
7071 **/
7072static void i40e_service_task(struct work_struct *work)
7073{
7074 struct i40e_pf *pf = container_of(work,
7075 struct i40e_pf,
7076 service_task);
7077 unsigned long start_time = jiffies;
7078
Shannon Nelsone57a2fe2014-06-03 23:50:19 +00007079 /* don't bother with service tasks if a reset is in progress */
7080 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
7081 i40e_service_event_complete(pf);
7082 return;
7083 }
7084
Kiran Patilb03a8c12015-09-24 18:13:15 -04007085 i40e_detect_recover_hung(pf);
Jesse Brandeburg2818ccd2016-01-13 16:51:38 -08007086 i40e_sync_filters_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007087 i40e_reset_subtask(pf);
7088 i40e_handle_mdd_event(pf);
7089 i40e_vc_process_vflr_event(pf);
7090 i40e_watchdog_subtask(pf);
7091 i40e_fdir_reinit_subtask(pf);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007092 i40e_client_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007093 i40e_sync_filters_subtask(pf);
Singhai, Anjali6a899022015-12-14 12:21:18 -08007094 i40e_sync_udp_filters_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007095 i40e_clean_adminq_subtask(pf);
7096
7097 i40e_service_event_complete(pf);
7098
7099 /* If the tasks have taken longer than one timer cycle or there
7100 * is more work to be done, reschedule the service task now
7101 * rather than wait for the timer to tick again.
7102 */
7103 if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
7104 test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
7105 test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
7106 test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
7107 i40e_service_event_schedule(pf);
7108}
7109
7110/**
7111 * i40e_service_timer - timer callback
7112 * @data: pointer to PF struct
7113 **/
7114static void i40e_service_timer(unsigned long data)
7115{
7116 struct i40e_pf *pf = (struct i40e_pf *)data;
7117
7118 mod_timer(&pf->service_timer,
7119 round_jiffies(jiffies + pf->service_timer_period));
7120 i40e_service_event_schedule(pf);
7121}
7122
7123/**
7124 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
7125 * @vsi: the VSI being configured
7126 **/
7127static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
7128{
7129 struct i40e_pf *pf = vsi->back;
7130
7131 switch (vsi->type) {
7132 case I40E_VSI_MAIN:
7133 vsi->alloc_queue_pairs = pf->num_lan_qps;
7134 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7135 I40E_REQ_DESCRIPTOR_MULTIPLE);
7136 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7137 vsi->num_q_vectors = pf->num_lan_msix;
7138 else
7139 vsi->num_q_vectors = 1;
7140
7141 break;
7142
7143 case I40E_VSI_FDIR:
7144 vsi->alloc_queue_pairs = 1;
7145 vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
7146 I40E_REQ_DESCRIPTOR_MULTIPLE);
Tushar Davea70e4072016-05-16 12:40:53 -07007147 vsi->num_q_vectors = pf->num_fdsb_msix;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007148 break;
7149
7150 case I40E_VSI_VMDQ2:
7151 vsi->alloc_queue_pairs = pf->num_vmdq_qps;
7152 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7153 I40E_REQ_DESCRIPTOR_MULTIPLE);
7154 vsi->num_q_vectors = pf->num_vmdq_msix;
7155 break;
7156
7157 case I40E_VSI_SRIOV:
7158 vsi->alloc_queue_pairs = pf->num_vf_qps;
7159 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7160 I40E_REQ_DESCRIPTOR_MULTIPLE);
7161 break;
7162
Vasu Dev38e00432014-08-01 13:27:03 -07007163#ifdef I40E_FCOE
7164 case I40E_VSI_FCOE:
7165 vsi->alloc_queue_pairs = pf->num_fcoe_qps;
7166 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7167 I40E_REQ_DESCRIPTOR_MULTIPLE);
7168 vsi->num_q_vectors = pf->num_fcoe_msix;
7169 break;
7170
7171#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007172 default:
7173 WARN_ON(1);
7174 return -ENODATA;
7175 }
7176
7177 return 0;
7178}
7179
7180/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007181 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
7182 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007183 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007184 *
7185 * On error: returns error code (negative)
7186 * On success: returns 0
7187 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007188static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007189{
7190 int size;
7191 int ret = 0;
7192
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00007193 /* allocate memory for both Tx and Rx ring pointers */
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007194 size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
7195 vsi->tx_rings = kzalloc(size, GFP_KERNEL);
7196 if (!vsi->tx_rings)
7197 return -ENOMEM;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007198 vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
7199
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007200 if (alloc_qvectors) {
7201 /* allocate memory for q_vector pointers */
Julia Lawallf57e4fb2014-07-30 03:11:09 +00007202 size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007203 vsi->q_vectors = kzalloc(size, GFP_KERNEL);
7204 if (!vsi->q_vectors) {
7205 ret = -ENOMEM;
7206 goto err_vectors;
7207 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007208 }
7209 return ret;
7210
7211err_vectors:
7212 kfree(vsi->tx_rings);
7213 return ret;
7214}
7215
7216/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007217 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
7218 * @pf: board private structure
7219 * @type: type of VSI
7220 *
7221 * On error: returns error code (negative)
7222 * On success: returns vsi index in PF (positive)
7223 **/
7224static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
7225{
7226 int ret = -ENODEV;
7227 struct i40e_vsi *vsi;
7228 int vsi_idx;
7229 int i;
7230
7231 /* Need to protect the allocation of the VSIs at the PF level */
7232 mutex_lock(&pf->switch_mutex);
7233
7234 /* VSI list may be fragmented if VSI creation/destruction has
7235 * been happening. We can afford to do a quick scan to look
7236 * for any free VSIs in the list.
7237 *
7238 * find next empty vsi slot, looping back around if necessary
7239 */
7240 i = pf->next_vsi;
Mitch Williams505682c2014-05-20 08:01:37 +00007241 while (i < pf->num_alloc_vsi && pf->vsi[i])
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007242 i++;
Mitch Williams505682c2014-05-20 08:01:37 +00007243 if (i >= pf->num_alloc_vsi) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007244 i = 0;
7245 while (i < pf->next_vsi && pf->vsi[i])
7246 i++;
7247 }
7248
Mitch Williams505682c2014-05-20 08:01:37 +00007249 if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007250 vsi_idx = i; /* Found one! */
7251 } else {
7252 ret = -ENODEV;
Alexander Duyck493fb302013-09-28 07:01:44 +00007253 goto unlock_pf; /* out of VSI slots! */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007254 }
7255 pf->next_vsi = ++i;
7256
7257 vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
7258 if (!vsi) {
7259 ret = -ENOMEM;
Alexander Duyck493fb302013-09-28 07:01:44 +00007260 goto unlock_pf;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007261 }
7262 vsi->type = type;
7263 vsi->back = pf;
7264 set_bit(__I40E_DOWN, &vsi->state);
7265 vsi->flags = 0;
7266 vsi->idx = vsi_idx;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04007267 vsi->int_rate_limit = 0;
Anjali Singhai Jain5db4cb52015-02-24 06:58:49 +00007268 vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
7269 pf->rss_table_size : 64;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007270 vsi->netdev_registered = false;
7271 vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
7272 INIT_LIST_HEAD(&vsi->mac_filter_list);
Shannon Nelson63741842014-04-23 04:50:16 +00007273 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007274
Alexander Duyck9f65e152013-09-28 06:00:58 +00007275 ret = i40e_set_num_rings_in_vsi(vsi);
7276 if (ret)
7277 goto err_rings;
7278
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007279 ret = i40e_vsi_alloc_arrays(vsi, true);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007280 if (ret)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007281 goto err_rings;
Alexander Duyck493fb302013-09-28 07:01:44 +00007282
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007283 /* Setup default MSIX irq handler for VSI */
7284 i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
7285
Kiran Patil21659032015-09-30 14:09:03 -04007286 /* Initialize VSI lock */
7287 spin_lock_init(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007288 pf->vsi[vsi_idx] = vsi;
7289 ret = vsi_idx;
Alexander Duyck493fb302013-09-28 07:01:44 +00007290 goto unlock_pf;
7291
Alexander Duyck9f65e152013-09-28 06:00:58 +00007292err_rings:
Alexander Duyck493fb302013-09-28 07:01:44 +00007293 pf->next_vsi = i - 1;
7294 kfree(vsi);
7295unlock_pf:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007296 mutex_unlock(&pf->switch_mutex);
7297 return ret;
7298}
7299
7300/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007301 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
7302 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007303 * @free_qvectors: a bool to specify if q_vectors need to be freed.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007304 *
7305 * On error: returns error code (negative)
7306 * On success: returns 0
7307 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007308static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007309{
7310 /* free the ring and vector containers */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007311 if (free_qvectors) {
7312 kfree(vsi->q_vectors);
7313 vsi->q_vectors = NULL;
7314 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007315 kfree(vsi->tx_rings);
7316 vsi->tx_rings = NULL;
7317 vsi->rx_rings = NULL;
7318}
7319
7320/**
Helin Zhang28c58692015-10-26 19:44:27 -04007321 * i40e_clear_rss_config_user - clear the user configured RSS hash keys
7322 * and lookup table
7323 * @vsi: Pointer to VSI structure
7324 */
7325static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
7326{
7327 if (!vsi)
7328 return;
7329
7330 kfree(vsi->rss_hkey_user);
7331 vsi->rss_hkey_user = NULL;
7332
7333 kfree(vsi->rss_lut_user);
7334 vsi->rss_lut_user = NULL;
7335}
7336
7337/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007338 * i40e_vsi_clear - Deallocate the VSI provided
7339 * @vsi: the VSI being un-configured
7340 **/
7341static int i40e_vsi_clear(struct i40e_vsi *vsi)
7342{
7343 struct i40e_pf *pf;
7344
7345 if (!vsi)
7346 return 0;
7347
7348 if (!vsi->back)
7349 goto free_vsi;
7350 pf = vsi->back;
7351
7352 mutex_lock(&pf->switch_mutex);
7353 if (!pf->vsi[vsi->idx]) {
7354 dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
7355 vsi->idx, vsi->idx, vsi, vsi->type);
7356 goto unlock_vsi;
7357 }
7358
7359 if (pf->vsi[vsi->idx] != vsi) {
7360 dev_err(&pf->pdev->dev,
7361 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
7362 pf->vsi[vsi->idx]->idx,
7363 pf->vsi[vsi->idx],
7364 pf->vsi[vsi->idx]->type,
7365 vsi->idx, vsi, vsi->type);
7366 goto unlock_vsi;
7367 }
7368
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00007369 /* updates the PF for this cleared vsi */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007370 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
7371 i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
7372
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007373 i40e_vsi_free_arrays(vsi, true);
Helin Zhang28c58692015-10-26 19:44:27 -04007374 i40e_clear_rss_config_user(vsi);
Alexander Duyck493fb302013-09-28 07:01:44 +00007375
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007376 pf->vsi[vsi->idx] = NULL;
7377 if (vsi->idx < pf->next_vsi)
7378 pf->next_vsi = vsi->idx;
7379
7380unlock_vsi:
7381 mutex_unlock(&pf->switch_mutex);
7382free_vsi:
7383 kfree(vsi);
7384
7385 return 0;
7386}
7387
7388/**
Alexander Duyck9f65e152013-09-28 06:00:58 +00007389 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
7390 * @vsi: the VSI being cleaned
7391 **/
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00007392static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007393{
7394 int i;
7395
Greg Rose8e9dca52013-12-18 13:45:53 +00007396 if (vsi->tx_rings && vsi->tx_rings[0]) {
Neerav Parikhd7397642013-11-28 06:39:37 +00007397 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Mitch Williams00403f02013-09-28 07:13:13 +00007398 kfree_rcu(vsi->tx_rings[i], rcu);
7399 vsi->tx_rings[i] = NULL;
7400 vsi->rx_rings[i] = NULL;
7401 }
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00007402 }
Alexander Duyck9f65e152013-09-28 06:00:58 +00007403}
7404
7405/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007406 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
7407 * @vsi: the VSI being configured
7408 **/
7409static int i40e_alloc_rings(struct i40e_vsi *vsi)
7410{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00007411 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007412 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007413 int i;
7414
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007415 /* Set basic values in the rings to be used later during open() */
Neerav Parikhd7397642013-11-28 06:39:37 +00007416 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00007417 /* allocate space for both Tx and Rx in one shot */
Alexander Duyck9f65e152013-09-28 06:00:58 +00007418 tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
7419 if (!tx_ring)
7420 goto err_out;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007421
7422 tx_ring->queue_index = i;
7423 tx_ring->reg_idx = vsi->base_queue + i;
7424 tx_ring->ring_active = false;
7425 tx_ring->vsi = vsi;
7426 tx_ring->netdev = vsi->netdev;
7427 tx_ring->dev = &pf->pdev->dev;
7428 tx_ring->count = vsi->num_desc;
7429 tx_ring->size = 0;
7430 tx_ring->dcb_tc = 0;
Anjali Singhai Jain8e0764b2015-06-05 12:20:30 -04007431 if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
7432 tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
Kan Lianga75e8002016-02-19 09:24:04 -05007433 tx_ring->tx_itr_setting = pf->tx_itr_default;
Alexander Duyck9f65e152013-09-28 06:00:58 +00007434 vsi->tx_rings[i] = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007435
Alexander Duyck9f65e152013-09-28 06:00:58 +00007436 rx_ring = &tx_ring[1];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007437 rx_ring->queue_index = i;
7438 rx_ring->reg_idx = vsi->base_queue + i;
7439 rx_ring->ring_active = false;
7440 rx_ring->vsi = vsi;
7441 rx_ring->netdev = vsi->netdev;
7442 rx_ring->dev = &pf->pdev->dev;
7443 rx_ring->count = vsi->num_desc;
7444 rx_ring->size = 0;
7445 rx_ring->dcb_tc = 0;
Kan Lianga75e8002016-02-19 09:24:04 -05007446 rx_ring->rx_itr_setting = pf->rx_itr_default;
Alexander Duyck9f65e152013-09-28 06:00:58 +00007447 vsi->rx_rings[i] = rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007448 }
7449
7450 return 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00007451
7452err_out:
7453 i40e_vsi_clear_rings(vsi);
7454 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007455}
7456
7457/**
7458 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
7459 * @pf: board private structure
7460 * @vectors: the number of MSI-X vectors to request
7461 *
7462 * Returns the number of vectors reserved, or error
7463 **/
7464static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
7465{
Alexander Gordeev7b37f372014-02-18 11:11:42 +01007466 vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
7467 I40E_MIN_MSIX, vectors);
7468 if (vectors < 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007469 dev_info(&pf->pdev->dev,
Alexander Gordeev7b37f372014-02-18 11:11:42 +01007470 "MSI-X vector reservation failed: %d\n", vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007471 vectors = 0;
7472 }
7473
7474 return vectors;
7475}
7476
7477/**
7478 * i40e_init_msix - Setup the MSIX capability
7479 * @pf: board private structure
7480 *
7481 * Work with the OS to set up the MSIX vectors needed.
7482 *
Shannon Nelson3b444392015-02-26 16:15:57 +00007483 * Returns the number of vectors reserved or negative on failure
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007484 **/
7485static int i40e_init_msix(struct i40e_pf *pf)
7486{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007487 struct i40e_hw *hw = &pf->hw;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007488 int vectors_left;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007489 int v_budget, i;
Shannon Nelson3b444392015-02-26 16:15:57 +00007490 int v_actual;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007491 int iwarp_requested = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007492
7493 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
7494 return -ENODEV;
7495
7496 /* The number of vectors we'll request will be comprised of:
7497 * - Add 1 for "other" cause for Admin Queue events, etc.
7498 * - The number of LAN queue pairs
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00007499 * - Queues being used for RSS.
7500 * We don't need as many as max_rss_size vectors.
7501 * use rss_size instead in the calculation since that
7502 * is governed by number of cpus in the system.
7503 * - assumes symmetric Tx/Rx pairing
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007504 * - The number of VMDq pairs
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007505 * - The CPU count within the NUMA node if iWARP is enabled
Vasu Dev38e00432014-08-01 13:27:03 -07007506#ifdef I40E_FCOE
7507 * - The number of FCOE qps.
7508#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007509 * Once we count this up, try the request.
7510 *
7511 * If we can't get what we want, we'll simplify to nearly nothing
7512 * and try again. If that still fails, we punt.
7513 */
Shannon Nelson1e200e42015-02-27 09:15:24 +00007514 vectors_left = hw->func_caps.num_msix_vectors;
7515 v_budget = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007516
Shannon Nelson1e200e42015-02-27 09:15:24 +00007517 /* reserve one vector for miscellaneous handler */
7518 if (vectors_left) {
7519 v_budget++;
7520 vectors_left--;
7521 }
7522
7523 /* reserve vectors for the main PF traffic queues */
7524 pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left);
7525 vectors_left -= pf->num_lan_msix;
7526 v_budget += pf->num_lan_msix;
7527
7528 /* reserve one vector for sideband flow director */
7529 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
7530 if (vectors_left) {
Tushar Davea70e4072016-05-16 12:40:53 -07007531 pf->num_fdsb_msix = 1;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007532 v_budget++;
7533 vectors_left--;
7534 } else {
Tushar Davea70e4072016-05-16 12:40:53 -07007535 pf->num_fdsb_msix = 0;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007536 }
7537 }
John W Linville83840e42015-01-14 03:06:28 +00007538
Vasu Dev38e00432014-08-01 13:27:03 -07007539#ifdef I40E_FCOE
Shannon Nelson1e200e42015-02-27 09:15:24 +00007540 /* can we reserve enough for FCoE? */
Vasu Dev38e00432014-08-01 13:27:03 -07007541 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
Shannon Nelson1e200e42015-02-27 09:15:24 +00007542 if (!vectors_left)
7543 pf->num_fcoe_msix = 0;
7544 else if (vectors_left >= pf->num_fcoe_qps)
7545 pf->num_fcoe_msix = pf->num_fcoe_qps;
7546 else
7547 pf->num_fcoe_msix = 1;
Vasu Dev38e00432014-08-01 13:27:03 -07007548 v_budget += pf->num_fcoe_msix;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007549 vectors_left -= pf->num_fcoe_msix;
Vasu Dev38e00432014-08-01 13:27:03 -07007550 }
Shannon Nelson1e200e42015-02-27 09:15:24 +00007551
Vasu Dev38e00432014-08-01 13:27:03 -07007552#endif
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007553 /* can we reserve enough for iWARP? */
7554 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02007555 iwarp_requested = pf->num_iwarp_msix;
7556
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007557 if (!vectors_left)
7558 pf->num_iwarp_msix = 0;
7559 else if (vectors_left < pf->num_iwarp_msix)
7560 pf->num_iwarp_msix = 1;
7561 v_budget += pf->num_iwarp_msix;
7562 vectors_left -= pf->num_iwarp_msix;
7563 }
7564
Shannon Nelson1e200e42015-02-27 09:15:24 +00007565 /* any vectors left over go for VMDq support */
7566 if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
7567 int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
7568 int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
7569
Stefan Assmann9ca57e92016-09-19 13:37:49 +02007570 if (!vectors_left) {
7571 pf->num_vmdq_msix = 0;
7572 pf->num_vmdq_qps = 0;
7573 } else {
7574 /* if we're short on vectors for what's desired, we limit
7575 * the queues per vmdq. If this is still more than are
7576 * available, the user will need to change the number of
7577 * queues/vectors used by the PF later with the ethtool
7578 * channels command
7579 */
7580 if (vmdq_vecs < vmdq_vecs_wanted)
7581 pf->num_vmdq_qps = 1;
7582 pf->num_vmdq_msix = pf->num_vmdq_qps;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007583
Stefan Assmann9ca57e92016-09-19 13:37:49 +02007584 v_budget += vmdq_vecs;
7585 vectors_left -= vmdq_vecs;
7586 }
Shannon Nelson1e200e42015-02-27 09:15:24 +00007587 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007588
7589 pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
7590 GFP_KERNEL);
7591 if (!pf->msix_entries)
7592 return -ENOMEM;
7593
7594 for (i = 0; i < v_budget; i++)
7595 pf->msix_entries[i].entry = i;
Shannon Nelson3b444392015-02-26 16:15:57 +00007596 v_actual = i40e_reserve_msix_vectors(pf, v_budget);
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007597
Shannon Nelson3b444392015-02-26 16:15:57 +00007598 if (v_actual < I40E_MIN_MSIX) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007599 pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
7600 kfree(pf->msix_entries);
7601 pf->msix_entries = NULL;
Guilherme G Piccoli4c95aa52016-09-22 10:03:58 -03007602 pci_disable_msix(pf->pdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007603 return -ENODEV;
7604
Shannon Nelson3b444392015-02-26 16:15:57 +00007605 } else if (v_actual == I40E_MIN_MSIX) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007606 /* Adjust for minimal MSIX use */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007607 pf->num_vmdq_vsis = 0;
7608 pf->num_vmdq_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007609 pf->num_lan_qps = 1;
7610 pf->num_lan_msix = 1;
7611
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02007612 } else if (!vectors_left) {
7613 /* If we have limited resources, we will start with no vectors
7614 * for the special features and then allocate vectors to some
7615 * of these features based on the policy and at the end disable
7616 * the features that did not get any vectors.
7617 */
Shannon Nelson3b444392015-02-26 16:15:57 +00007618 int vec;
7619
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02007620 dev_info(&pf->pdev->dev,
7621 "MSI-X vector limit reached, attempting to redistribute vectors\n");
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007622 /* reserve the misc vector */
Shannon Nelson3b444392015-02-26 16:15:57 +00007623 vec = v_actual - 1;
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007624
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007625 /* Scale vector usage down */
7626 pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007627 pf->num_vmdq_vsis = 1;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007628 pf->num_vmdq_qps = 1;
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02007629#ifdef I40E_FCOE
7630 pf->num_fcoe_qps = 0;
7631 pf->num_fcoe_msix = 0;
7632#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007633
7634 /* partition out the remaining vectors */
7635 switch (vec) {
7636 case 2:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007637 pf->num_lan_msix = 1;
7638 break;
7639 case 3:
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007640 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
7641 pf->num_lan_msix = 1;
7642 pf->num_iwarp_msix = 1;
7643 } else {
7644 pf->num_lan_msix = 2;
7645 }
Vasu Dev38e00432014-08-01 13:27:03 -07007646#ifdef I40E_FCOE
7647 /* give one vector to FCoE */
7648 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
7649 pf->num_lan_msix = 1;
7650 pf->num_fcoe_msix = 1;
7651 }
Vasu Dev38e00432014-08-01 13:27:03 -07007652#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007653 break;
7654 default:
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007655 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
7656 pf->num_iwarp_msix = min_t(int, (vec / 3),
7657 iwarp_requested);
7658 pf->num_vmdq_vsis = min_t(int, (vec / 3),
7659 I40E_DEFAULT_NUM_VMDQ_VSI);
7660 } else {
7661 pf->num_vmdq_vsis = min_t(int, (vec / 2),
7662 I40E_DEFAULT_NUM_VMDQ_VSI);
7663 }
Stefan Assmannabd97a92016-09-19 13:37:51 +02007664 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
7665 pf->num_fdsb_msix = 1;
7666 vec--;
7667 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007668 pf->num_lan_msix = min_t(int,
7669 (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
7670 pf->num_lan_msix);
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02007671 pf->num_lan_qps = pf->num_lan_msix;
Vasu Dev38e00432014-08-01 13:27:03 -07007672#ifdef I40E_FCOE
7673 /* give one vector to FCoE */
7674 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
7675 pf->num_fcoe_msix = 1;
7676 vec--;
7677 }
7678#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007679 break;
7680 }
7681 }
7682
Stefan Assmannabd97a92016-09-19 13:37:51 +02007683 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
7684 (pf->num_fdsb_msix == 0)) {
7685 dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
7686 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
7687 }
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007688 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
7689 (pf->num_vmdq_msix == 0)) {
7690 dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
7691 pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
7692 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007693
7694 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
7695 (pf->num_iwarp_msix == 0)) {
7696 dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
7697 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
7698 }
Vasu Dev38e00432014-08-01 13:27:03 -07007699#ifdef I40E_FCOE
7700
7701 if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) {
7702 dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n");
7703 pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
7704 }
7705#endif
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02007706 i40e_debug(&pf->hw, I40E_DEBUG_INIT,
7707 "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
7708 pf->num_lan_msix,
7709 pf->num_vmdq_msix * pf->num_vmdq_vsis,
7710 pf->num_fdsb_msix,
7711 pf->num_iwarp_msix);
7712
Shannon Nelson3b444392015-02-26 16:15:57 +00007713 return v_actual;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007714}
7715
7716/**
Greg Rose90e04072014-03-06 08:59:57 +00007717 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
Alexander Duyck493fb302013-09-28 07:01:44 +00007718 * @vsi: the VSI being configured
7719 * @v_idx: index of the vector in the vsi struct
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03007720 * @cpu: cpu to be used on affinity_mask
Alexander Duyck493fb302013-09-28 07:01:44 +00007721 *
7722 * We allocate one q_vector. If allocation fails we return -ENOMEM.
7723 **/
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03007724static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu)
Alexander Duyck493fb302013-09-28 07:01:44 +00007725{
7726 struct i40e_q_vector *q_vector;
7727
7728 /* allocate q_vector */
7729 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
7730 if (!q_vector)
7731 return -ENOMEM;
7732
7733 q_vector->vsi = vsi;
7734 q_vector->v_idx = v_idx;
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03007735 cpumask_set_cpu(cpu, &q_vector->affinity_mask);
7736
Alexander Duyck493fb302013-09-28 07:01:44 +00007737 if (vsi->netdev)
7738 netif_napi_add(vsi->netdev, &q_vector->napi,
Jesse Brandeburgeefeace2014-05-10 04:49:13 +00007739 i40e_napi_poll, NAPI_POLL_WEIGHT);
Alexander Duyck493fb302013-09-28 07:01:44 +00007740
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00007741 q_vector->rx.latency_range = I40E_LOW_LATENCY;
7742 q_vector->tx.latency_range = I40E_LOW_LATENCY;
7743
Alexander Duyck493fb302013-09-28 07:01:44 +00007744 /* tie q_vector and vsi together */
7745 vsi->q_vectors[v_idx] = q_vector;
7746
7747 return 0;
7748}
7749
7750/**
Greg Rose90e04072014-03-06 08:59:57 +00007751 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007752 * @vsi: the VSI being configured
7753 *
7754 * We allocate one q_vector per queue interrupt. If allocation fails we
7755 * return -ENOMEM.
7756 **/
Greg Rose90e04072014-03-06 08:59:57 +00007757static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007758{
7759 struct i40e_pf *pf = vsi->back;
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03007760 int err, v_idx, num_q_vectors, current_cpu;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007761
7762 /* if not MSIX, give the one vector only to the LAN VSI */
7763 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7764 num_q_vectors = vsi->num_q_vectors;
7765 else if (vsi == pf->vsi[pf->lan_vsi])
7766 num_q_vectors = 1;
7767 else
7768 return -EINVAL;
7769
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03007770 current_cpu = cpumask_first(cpu_online_mask);
7771
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007772 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03007773 err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu);
Alexander Duyck493fb302013-09-28 07:01:44 +00007774 if (err)
7775 goto err_out;
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03007776 current_cpu = cpumask_next(current_cpu, cpu_online_mask);
7777 if (unlikely(current_cpu >= nr_cpu_ids))
7778 current_cpu = cpumask_first(cpu_online_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007779 }
7780
7781 return 0;
Alexander Duyck493fb302013-09-28 07:01:44 +00007782
7783err_out:
7784 while (v_idx--)
7785 i40e_free_q_vector(vsi, v_idx);
7786
7787 return err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007788}
7789
7790/**
7791 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
7792 * @pf: board private structure to initialize
7793 **/
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007794static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007795{
Shannon Nelson3b444392015-02-26 16:15:57 +00007796 int vectors = 0;
7797 ssize_t size;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007798
7799 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
Shannon Nelson3b444392015-02-26 16:15:57 +00007800 vectors = i40e_init_msix(pf);
7801 if (vectors < 0) {
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08007802 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007803 I40E_FLAG_IWARP_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -07007804#ifdef I40E_FCOE
7805 I40E_FLAG_FCOE_ENABLED |
7806#endif
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08007807 I40E_FLAG_RSS_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00007808 I40E_FLAG_DCB_CAPABLE |
Dave Ertmana0362442016-08-29 17:38:26 -07007809 I40E_FLAG_DCB_ENABLED |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08007810 I40E_FLAG_SRIOV_ENABLED |
7811 I40E_FLAG_FD_SB_ENABLED |
7812 I40E_FLAG_FD_ATR_ENABLED |
7813 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007814
7815 /* rework the queue expectations without MSIX */
7816 i40e_determine_queue_usage(pf);
7817 }
7818 }
7819
7820 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
7821 (pf->flags & I40E_FLAG_MSI_ENABLED)) {
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08007822 dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
Shannon Nelson3b444392015-02-26 16:15:57 +00007823 vectors = pci_enable_msi(pf->pdev);
7824 if (vectors < 0) {
7825 dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
7826 vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007827 pf->flags &= ~I40E_FLAG_MSI_ENABLED;
7828 }
Shannon Nelson3b444392015-02-26 16:15:57 +00007829 vectors = 1; /* one MSI or Legacy vector */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007830 }
7831
Shannon Nelson958a3e32013-09-28 07:13:28 +00007832 if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08007833 dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
Shannon Nelson958a3e32013-09-28 07:13:28 +00007834
Shannon Nelson3b444392015-02-26 16:15:57 +00007835 /* set up vector assignment tracking */
7836 size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
7837 pf->irq_pile = kzalloc(size, GFP_KERNEL);
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007838 if (!pf->irq_pile) {
7839 dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n");
7840 return -ENOMEM;
7841 }
Shannon Nelson3b444392015-02-26 16:15:57 +00007842 pf->irq_pile->num_entries = vectors;
7843 pf->irq_pile->search_hint = 0;
7844
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007845 /* track first vector for misc interrupts, ignore return */
Shannon Nelson3b444392015-02-26 16:15:57 +00007846 (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007847
7848 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007849}
7850
7851/**
7852 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
7853 * @pf: board private structure
7854 *
7855 * This sets up the handler for MSIX 0, which is used to manage the
7856 * non-queue interrupts, e.g. AdminQ and errors. This is not used
7857 * when in MSI or Legacy interrupt mode.
7858 **/
7859static int i40e_setup_misc_vector(struct i40e_pf *pf)
7860{
7861 struct i40e_hw *hw = &pf->hw;
7862 int err = 0;
7863
7864 /* Only request the irq if this is the first time through, and
7865 * not when we're rebuilding after a Reset
7866 */
7867 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
7868 err = request_irq(pf->msix_entries[0].vector,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00007869 i40e_intr, 0, pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007870 if (err) {
7871 dev_info(&pf->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08007872 "request_irq for %s failed: %d\n",
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00007873 pf->int_name, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007874 return -EFAULT;
7875 }
7876 }
7877
Jacob Kellerab437b52014-12-14 01:55:08 +00007878 i40e_enable_misc_int_causes(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007879
7880 /* associate no queues to the misc vector */
7881 wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
7882 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
7883
7884 i40e_flush(hw);
7885
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08007886 i40e_irq_dynamic_enable_icr0(pf, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007887
7888 return err;
7889}
7890
7891/**
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007892 * i40e_config_rss_aq - Prepare for RSS using AQ commands
7893 * @vsi: vsi structure
7894 * @seed: RSS hash seed
7895 **/
Helin Zhange69ff812015-10-21 19:56:22 -04007896static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
7897 u8 *lut, u16 lut_size)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007898{
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007899 struct i40e_pf *pf = vsi->back;
7900 struct i40e_hw *hw = &pf->hw;
Jacob Keller776b2e12016-07-19 16:23:30 -07007901 int ret = 0;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007902
Jacob Keller776b2e12016-07-19 16:23:30 -07007903 if (seed) {
7904 struct i40e_aqc_get_set_rss_key_data *seed_dw =
7905 (struct i40e_aqc_get_set_rss_key_data *)seed;
7906 ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw);
7907 if (ret) {
7908 dev_info(&pf->pdev->dev,
7909 "Cannot set RSS key, err %s aq_err %s\n",
7910 i40e_stat_str(hw, ret),
7911 i40e_aq_str(hw, hw->aq.asq_last_status));
7912 return ret;
7913 }
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007914 }
Jacob Keller776b2e12016-07-19 16:23:30 -07007915 if (lut) {
7916 bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007917
Jacob Keller776b2e12016-07-19 16:23:30 -07007918 ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
7919 if (ret) {
7920 dev_info(&pf->pdev->dev,
7921 "Cannot set RSS lut, err %s aq_err %s\n",
7922 i40e_stat_str(hw, ret),
7923 i40e_aq_str(hw, hw->aq.asq_last_status));
7924 return ret;
7925 }
7926 }
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04007927 return ret;
7928}
7929
7930/**
Anjali Singhai Jain95a73782015-12-22 14:25:04 -08007931 * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
7932 * @vsi: Pointer to vsi structure
7933 * @seed: Buffter to store the hash keys
7934 * @lut: Buffer to store the lookup table entries
7935 * @lut_size: Size of buffer to store the lookup table entries
7936 *
7937 * Return 0 on success, negative on failure
7938 */
7939static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
7940 u8 *lut, u16 lut_size)
7941{
7942 struct i40e_pf *pf = vsi->back;
7943 struct i40e_hw *hw = &pf->hw;
7944 int ret = 0;
7945
7946 if (seed) {
7947 ret = i40e_aq_get_rss_key(hw, vsi->id,
7948 (struct i40e_aqc_get_set_rss_key_data *)seed);
7949 if (ret) {
7950 dev_info(&pf->pdev->dev,
7951 "Cannot get RSS key, err %s aq_err %s\n",
7952 i40e_stat_str(&pf->hw, ret),
7953 i40e_aq_str(&pf->hw,
7954 pf->hw.aq.asq_last_status));
7955 return ret;
7956 }
7957 }
7958
7959 if (lut) {
7960 bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
7961
7962 ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
7963 if (ret) {
7964 dev_info(&pf->pdev->dev,
7965 "Cannot get RSS lut, err %s aq_err %s\n",
7966 i40e_stat_str(&pf->hw, ret),
7967 i40e_aq_str(&pf->hw,
7968 pf->hw.aq.asq_last_status));
7969 return ret;
7970 }
7971 }
7972
7973 return ret;
7974}
7975
7976/**
Jacob Keller0582b962016-07-19 16:23:29 -07007977 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
7978 * @vsi: VSI structure
7979 **/
7980static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
7981{
7982 u8 seed[I40E_HKEY_ARRAY_SIZE];
7983 struct i40e_pf *pf = vsi->back;
7984 u8 *lut;
7985 int ret;
7986
7987 if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE))
7988 return 0;
7989
Jacob Keller552b9962016-07-19 16:23:31 -07007990 if (!vsi->rss_size)
7991 vsi->rss_size = min_t(int, pf->alloc_rss_size,
7992 vsi->num_queue_pairs);
7993 if (!vsi->rss_size)
7994 return -EINVAL;
7995
Jacob Keller0582b962016-07-19 16:23:29 -07007996 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
7997 if (!lut)
7998 return -ENOMEM;
Jacob Keller552b9962016-07-19 16:23:31 -07007999 /* Use the user configured hash keys and lookup table if there is one,
8000 * otherwise use default
8001 */
8002 if (vsi->rss_lut_user)
8003 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
8004 else
8005 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
8006 if (vsi->rss_hkey_user)
8007 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
8008 else
8009 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
Jacob Keller0582b962016-07-19 16:23:29 -07008010 ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
8011 kfree(lut);
8012
8013 return ret;
8014}
8015
8016/**
Helin Zhang043dd652015-10-21 19:56:23 -04008017 * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
Helin Zhange69ff812015-10-21 19:56:22 -04008018 * @vsi: Pointer to vsi structure
8019 * @seed: RSS hash seed
8020 * @lut: Lookup table
8021 * @lut_size: Lookup table size
8022 *
8023 * Returns 0 on success, negative on failure
8024 **/
8025static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
8026 const u8 *lut, u16 lut_size)
8027{
8028 struct i40e_pf *pf = vsi->back;
8029 struct i40e_hw *hw = &pf->hw;
Mitch Williamsc4e18682016-04-12 08:30:40 -07008030 u16 vf_id = vsi->vf_id;
Helin Zhange69ff812015-10-21 19:56:22 -04008031 u8 i;
8032
8033 /* Fill out hash function seed */
8034 if (seed) {
8035 u32 *seed_dw = (u32 *)seed;
8036
Mitch Williamsc4e18682016-04-12 08:30:40 -07008037 if (vsi->type == I40E_VSI_MAIN) {
8038 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
8039 i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i),
8040 seed_dw[i]);
8041 } else if (vsi->type == I40E_VSI_SRIOV) {
8042 for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
8043 i40e_write_rx_ctl(hw,
8044 I40E_VFQF_HKEY1(i, vf_id),
8045 seed_dw[i]);
8046 } else {
8047 dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
8048 }
Helin Zhange69ff812015-10-21 19:56:22 -04008049 }
8050
8051 if (lut) {
8052 u32 *lut_dw = (u32 *)lut;
8053
Mitch Williamsc4e18682016-04-12 08:30:40 -07008054 if (vsi->type == I40E_VSI_MAIN) {
8055 if (lut_size != I40E_HLUT_ARRAY_SIZE)
8056 return -EINVAL;
8057 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8058 wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
8059 } else if (vsi->type == I40E_VSI_SRIOV) {
8060 if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
8061 return -EINVAL;
8062 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
8063 i40e_write_rx_ctl(hw,
8064 I40E_VFQF_HLUT1(i, vf_id),
8065 lut_dw[i]);
8066 } else {
8067 dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
8068 }
Helin Zhange69ff812015-10-21 19:56:22 -04008069 }
8070 i40e_flush(hw);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008071
8072 return 0;
8073}
8074
8075/**
Helin Zhang043dd652015-10-21 19:56:23 -04008076 * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
8077 * @vsi: Pointer to VSI structure
8078 * @seed: Buffer to store the keys
8079 * @lut: Buffer to store the lookup table entries
8080 * @lut_size: Size of buffer to store the lookup table entries
8081 *
8082 * Returns 0 on success, negative on failure
8083 */
8084static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
8085 u8 *lut, u16 lut_size)
8086{
8087 struct i40e_pf *pf = vsi->back;
8088 struct i40e_hw *hw = &pf->hw;
8089 u16 i;
8090
8091 if (seed) {
8092 u32 *seed_dw = (u32 *)seed;
8093
8094 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008095 seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
Helin Zhang043dd652015-10-21 19:56:23 -04008096 }
8097 if (lut) {
8098 u32 *lut_dw = (u32 *)lut;
8099
8100 if (lut_size != I40E_HLUT_ARRAY_SIZE)
8101 return -EINVAL;
8102 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8103 lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
8104 }
8105
8106 return 0;
8107}
8108
8109/**
8110 * i40e_config_rss - Configure RSS keys and lut
8111 * @vsi: Pointer to VSI structure
8112 * @seed: RSS hash seed
8113 * @lut: Lookup table
8114 * @lut_size: Lookup table size
8115 *
8116 * Returns 0 on success, negative on failure
8117 */
8118int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
8119{
8120 struct i40e_pf *pf = vsi->back;
8121
8122 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
8123 return i40e_config_rss_aq(vsi, seed, lut, lut_size);
8124 else
8125 return i40e_config_rss_reg(vsi, seed, lut, lut_size);
8126}
8127
8128/**
8129 * i40e_get_rss - Get RSS keys and lut
8130 * @vsi: Pointer to VSI structure
8131 * @seed: Buffer to store the keys
8132 * @lut: Buffer to store the lookup table entries
8133 * lut_size: Size of buffer to store the lookup table entries
8134 *
8135 * Returns 0 on success, negative on failure
8136 */
8137int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
8138{
Anjali Singhai Jain95a73782015-12-22 14:25:04 -08008139 struct i40e_pf *pf = vsi->back;
8140
8141 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
8142 return i40e_get_rss_aq(vsi, seed, lut, lut_size);
8143 else
8144 return i40e_get_rss_reg(vsi, seed, lut, lut_size);
Helin Zhang043dd652015-10-21 19:56:23 -04008145}
8146
8147/**
Helin Zhange69ff812015-10-21 19:56:22 -04008148 * i40e_fill_rss_lut - Fill the RSS lookup table with default values
8149 * @pf: Pointer to board private structure
8150 * @lut: Lookup table
8151 * @rss_table_size: Lookup table size
8152 * @rss_size: Range of queue number for hashing
8153 */
Alan Bradyf1582352016-08-24 11:33:46 -07008154void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
8155 u16 rss_table_size, u16 rss_size)
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008156{
Helin Zhange69ff812015-10-21 19:56:22 -04008157 u16 i;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008158
Helin Zhange69ff812015-10-21 19:56:22 -04008159 for (i = 0; i < rss_table_size; i++)
8160 lut[i] = i % rss_size;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008161}
8162
8163/**
Helin Zhang043dd652015-10-21 19:56:23 -04008164 * i40e_pf_config_rss - Prepare for RSS if used
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008165 * @pf: board private structure
8166 **/
Helin Zhang043dd652015-10-21 19:56:23 -04008167static int i40e_pf_config_rss(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008168{
Anjali Singhai Jain66ddcff2015-02-24 06:58:50 +00008169 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008170 u8 seed[I40E_HKEY_ARRAY_SIZE];
Helin Zhange69ff812015-10-21 19:56:22 -04008171 u8 *lut;
Anjali Singhai Jain4617e8c2013-11-20 10:02:56 +00008172 struct i40e_hw *hw = &pf->hw;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00008173 u32 reg_val;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008174 u64 hena;
Helin Zhange69ff812015-10-21 19:56:22 -04008175 int ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008176
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008177 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008178 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
8179 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008180 hena |= i40e_pf_get_default_rss_hena(pf);
8181
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008182 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
8183 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008184
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008185 /* Determine the RSS table size based on the hardware capabilities */
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008186 reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008187 reg_val = (pf->rss_table_size == 512) ?
8188 (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
8189 (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008190 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
Carolyn Wybornye157ea32014-06-03 23:50:22 +00008191
Helin Zhang28c58692015-10-26 19:44:27 -04008192 /* Determine the RSS size of the VSI */
8193 if (!vsi->rss_size)
Helin Zhangacd65442015-10-26 19:44:28 -04008194 vsi->rss_size = min_t(int, pf->alloc_rss_size,
8195 vsi->num_queue_pairs);
Mitch Williamsa4fa59c2016-09-12 14:18:43 -07008196 if (!vsi->rss_size)
8197 return -EINVAL;
Helin Zhang28c58692015-10-26 19:44:27 -04008198
Helin Zhange69ff812015-10-21 19:56:22 -04008199 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
8200 if (!lut)
8201 return -ENOMEM;
8202
Helin Zhang28c58692015-10-26 19:44:27 -04008203 /* Use user configured lut if there is one, otherwise use default */
8204 if (vsi->rss_lut_user)
8205 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
8206 else
8207 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
Helin Zhange69ff812015-10-21 19:56:22 -04008208
Helin Zhang28c58692015-10-26 19:44:27 -04008209 /* Use user configured hash key if there is one, otherwise
8210 * use default.
8211 */
8212 if (vsi->rss_hkey_user)
8213 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
8214 else
8215 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
Helin Zhang043dd652015-10-21 19:56:23 -04008216 ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
Helin Zhange69ff812015-10-21 19:56:22 -04008217 kfree(lut);
8218
8219 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008220}
8221
8222/**
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008223 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
8224 * @pf: board private structure
8225 * @queue_count: the requested queue count for rss.
8226 *
8227 * returns 0 if rss is not enabled, if enabled returns the final rss queue
8228 * count which may be different from the requested queue count.
8229 **/
8230int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
8231{
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008232 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
8233 int new_rss_size;
8234
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008235 if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
8236 return 0;
8237
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008238 new_rss_size = min_t(int, queue_count, pf->rss_size_max);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008239
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008240 if (queue_count != vsi->num_queue_pairs) {
8241 vsi->req_queue_pairs = queue_count;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008242 i40e_prep_for_reset(pf);
8243
Helin Zhangacd65442015-10-26 19:44:28 -04008244 pf->alloc_rss_size = new_rss_size;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008245
8246 i40e_reset_and_rebuild(pf, true);
Helin Zhang28c58692015-10-26 19:44:27 -04008247
8248 /* Discard the user configured hash keys and lut, if less
8249 * queues are enabled.
8250 */
8251 if (queue_count < vsi->rss_size) {
8252 i40e_clear_rss_config_user(vsi);
8253 dev_dbg(&pf->pdev->dev,
8254 "discard user configured hash keys and lut\n");
8255 }
8256
8257 /* Reset vsi->rss_size, as number of enabled queues changed */
Helin Zhangacd65442015-10-26 19:44:28 -04008258 vsi->rss_size = min_t(int, pf->alloc_rss_size,
8259 vsi->num_queue_pairs);
Helin Zhang28c58692015-10-26 19:44:27 -04008260
Helin Zhang043dd652015-10-21 19:56:23 -04008261 i40e_pf_config_rss(pf);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008262 }
Lihong Yang12815052016-09-27 11:28:48 -07008263 dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n",
8264 vsi->req_queue_pairs, pf->rss_size_max);
Helin Zhangacd65442015-10-26 19:44:28 -04008265 return pf->alloc_rss_size;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008266}
8267
8268/**
Greg Rosef4492db2015-02-06 08:52:12 +00008269 * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
8270 * @pf: board private structure
8271 **/
8272i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf)
8273{
8274 i40e_status status;
8275 bool min_valid, max_valid;
8276 u32 max_bw, min_bw;
8277
8278 status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
8279 &min_valid, &max_valid);
8280
8281 if (!status) {
8282 if (min_valid)
8283 pf->npar_min_bw = min_bw;
8284 if (max_valid)
8285 pf->npar_max_bw = max_bw;
8286 }
8287
8288 return status;
8289}
8290
8291/**
8292 * i40e_set_npar_bw_setting - Set BW settings for this PF partition
8293 * @pf: board private structure
8294 **/
8295i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf)
8296{
8297 struct i40e_aqc_configure_partition_bw_data bw_data;
8298 i40e_status status;
8299
Jeff Kirsherb40c82e62015-02-27 09:18:34 +00008300 /* Set the valid bit for this PF */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008301 bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
Greg Rosef4492db2015-02-06 08:52:12 +00008302 bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK;
8303 bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK;
8304
8305 /* Set the new bandwidths */
8306 status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
8307
8308 return status;
8309}
8310
8311/**
8312 * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
8313 * @pf: board private structure
8314 **/
8315i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf)
8316{
8317 /* Commit temporary BW setting to permanent NVM image */
8318 enum i40e_admin_queue_err last_aq_status;
8319 i40e_status ret;
8320 u16 nvm_word;
8321
8322 if (pf->hw.partition_id != 1) {
8323 dev_info(&pf->pdev->dev,
8324 "Commit BW only works on partition 1! This is partition %d",
8325 pf->hw.partition_id);
8326 ret = I40E_NOT_SUPPORTED;
8327 goto bw_commit_out;
8328 }
8329
8330 /* Acquire NVM for read access */
8331 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
8332 last_aq_status = pf->hw.aq.asq_last_status;
8333 if (ret) {
8334 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008335 "Cannot acquire NVM for read access, err %s aq_err %s\n",
8336 i40e_stat_str(&pf->hw, ret),
8337 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008338 goto bw_commit_out;
8339 }
8340
8341 /* Read word 0x10 of NVM - SW compatibility word 1 */
8342 ret = i40e_aq_read_nvm(&pf->hw,
8343 I40E_SR_NVM_CONTROL_WORD,
8344 0x10, sizeof(nvm_word), &nvm_word,
8345 false, NULL);
8346 /* Save off last admin queue command status before releasing
8347 * the NVM
8348 */
8349 last_aq_status = pf->hw.aq.asq_last_status;
8350 i40e_release_nvm(&pf->hw);
8351 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008352 dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
8353 i40e_stat_str(&pf->hw, ret),
8354 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008355 goto bw_commit_out;
8356 }
8357
8358 /* Wait a bit for NVM release to complete */
8359 msleep(50);
8360
8361 /* Acquire NVM for write access */
8362 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
8363 last_aq_status = pf->hw.aq.asq_last_status;
8364 if (ret) {
8365 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008366 "Cannot acquire NVM for write access, err %s aq_err %s\n",
8367 i40e_stat_str(&pf->hw, ret),
8368 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008369 goto bw_commit_out;
8370 }
8371 /* Write it back out unchanged to initiate update NVM,
8372 * which will force a write of the shadow (alt) RAM to
8373 * the NVM - thus storing the bandwidth values permanently.
8374 */
8375 ret = i40e_aq_update_nvm(&pf->hw,
8376 I40E_SR_NVM_CONTROL_WORD,
8377 0x10, sizeof(nvm_word),
8378 &nvm_word, true, NULL);
8379 /* Save off last admin queue command status before releasing
8380 * the NVM
8381 */
8382 last_aq_status = pf->hw.aq.asq_last_status;
8383 i40e_release_nvm(&pf->hw);
8384 if (ret)
8385 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008386 "BW settings NOT SAVED, err %s aq_err %s\n",
8387 i40e_stat_str(&pf->hw, ret),
8388 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008389bw_commit_out:
8390
8391 return ret;
8392}
8393
8394/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008395 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
8396 * @pf: board private structure to initialize
8397 *
8398 * i40e_sw_init initializes the Adapter private data structure.
8399 * Fields are initialized based on PCI device information and
8400 * OS network device settings (MTU size).
8401 **/
8402static int i40e_sw_init(struct i40e_pf *pf)
8403{
8404 int err = 0;
8405 int size;
8406
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008407 /* Set default capability flags */
8408 pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
8409 I40E_FLAG_MSI_ENABLED |
Mitch Williams2bc7ee82015-02-06 08:52:11 +00008410 I40E_FLAG_MSIX_ENABLED;
8411
Mitch Williamsca99eb92014-04-04 04:43:07 +00008412 /* Set default ITR */
8413 pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
8414 pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
8415
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008416 /* Depending on PF configurations, it is possible that the RSS
8417 * maximum might end up larger than the available queues
8418 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008419 pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
Helin Zhangacd65442015-10-26 19:44:28 -04008420 pf->alloc_rss_size = 1;
Anjali Singhai Jain5db4cb52015-02-24 06:58:49 +00008421 pf->rss_table_size = pf->hw.func_caps.rss_table_size;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008422 pf->rss_size_max = min_t(int, pf->rss_size_max,
8423 pf->hw.func_caps.num_tx_qp);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008424 if (pf->hw.func_caps.rss) {
8425 pf->flags |= I40E_FLAG_RSS_ENABLED;
Helin Zhangacd65442015-10-26 19:44:28 -04008426 pf->alloc_rss_size = min_t(int, pf->rss_size_max,
8427 num_online_cpus());
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008428 }
8429
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008430 /* MFP mode enabled */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04008431 if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008432 pf->flags |= I40E_FLAG_MFP_ENABLED;
8433 dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
Greg Rosef4492db2015-02-06 08:52:12 +00008434 if (i40e_get_npar_bw_setting(pf))
8435 dev_warn(&pf->pdev->dev,
8436 "Could not get NPAR bw settings\n");
8437 else
8438 dev_info(&pf->pdev->dev,
8439 "Min BW = %8.8x, Max BW = %8.8x\n",
8440 pf->npar_min_bw, pf->npar_max_bw);
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008441 }
8442
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008443 /* FW/NVM is not yet fixed in this regard */
8444 if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
8445 (pf->hw.func_caps.fd_filters_best_effort > 0)) {
8446 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
8447 pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
Shannon Nelson6eae9c62015-09-03 17:18:55 -04008448 if (pf->flags & I40E_FLAG_MFP_ENABLED &&
8449 pf->hw.num_partitions > 1)
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008450 dev_info(&pf->pdev->dev,
Anjali Singhai Jain0b675842014-03-06 08:59:51 +00008451 "Flow Director Sideband mode Disabled in MFP mode\n");
Shannon Nelson6eae9c62015-09-03 17:18:55 -04008452 else
8453 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008454 pf->fdir_pf_filter_count =
8455 pf->hw.func_caps.fd_filters_guaranteed;
8456 pf->hw.fdir_shared_filter_count =
8457 pf->hw.func_caps.fd_filters_best_effort;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008458 }
8459
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008460 if (i40e_is_mac_710(&pf->hw) &&
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08008461 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008462 (pf->hw.aq.fw_maj_ver < 4))) {
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08008463 pf->flags |= I40E_FLAG_RESTART_AUTONEG;
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008464 /* No DCB support for FW < v4.33 */
8465 pf->flags |= I40E_FLAG_NO_DCB_SUPPORT;
8466 }
8467
8468 /* Disable FW LLDP if FW < v4.3 */
8469 if (i40e_is_mac_710(&pf->hw) &&
8470 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
8471 (pf->hw.aq.fw_maj_ver < 4)))
8472 pf->flags |= I40E_FLAG_STOP_FW_LLDP;
8473
8474 /* Use the FW Set LLDP MIB API if FW > v4.40 */
8475 if (i40e_is_mac_710(&pf->hw) &&
8476 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
8477 (pf->hw.aq.fw_maj_ver >= 5)))
8478 pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB;
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08008479
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008480 if (pf->hw.func_caps.vmdq) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008481 pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04008482 pf->flags |= I40E_FLAG_VMDQ_ENABLED;
Jesse Brandeburge9e53662015-10-02 17:57:21 -07008483 pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008484 }
8485
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008486 if (pf->hw.func_caps.iwarp) {
8487 pf->flags |= I40E_FLAG_IWARP_ENABLED;
8488 /* IWARP needs one extra vector for CQP just like MISC.*/
8489 pf->num_iwarp_msix = (int)num_online_cpus() + 1;
8490 }
8491
Vasu Dev38e00432014-08-01 13:27:03 -07008492#ifdef I40E_FCOE
Shannon Nelson21364bc2015-08-26 15:14:13 -04008493 i40e_init_pf_fcoe(pf);
Vasu Dev38e00432014-08-01 13:27:03 -07008494
8495#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008496#ifdef CONFIG_PCI_IOV
Shannon Nelsonba252f132014-12-11 07:06:34 +00008497 if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008498 pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
8499 pf->flags |= I40E_FLAG_SRIOV_ENABLED;
8500 pf->num_req_vfs = min_t(int,
8501 pf->hw.func_caps.num_vfs,
8502 I40E_MAX_VF_COUNT);
8503 }
8504#endif /* CONFIG_PCI_IOV */
Anjali Singhai Jaind502ce02015-06-05 12:20:26 -04008505 if (pf->hw.mac.type == I40E_MAC_X722) {
8506 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE |
8507 I40E_FLAG_128_QP_RSS_CAPABLE |
8508 I40E_FLAG_HW_ATR_EVICT_CAPABLE |
8509 I40E_FLAG_OUTER_UDP_CSUM_CAPABLE |
8510 I40E_FLAG_WB_ON_ITR_CAPABLE |
Singhai, Anjali6a899022015-12-14 12:21:18 -08008511 I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE |
Jesse Brandeburg8e2cc0e2016-02-29 11:00:24 -08008512 I40E_FLAG_NO_PCI_LINK_CHECK |
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008513 I40E_FLAG_USE_SET_LLDP_MIB |
Singhai, Anjali6a899022015-12-14 12:21:18 -08008514 I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
Anjali Singhaia340c782016-01-06 11:49:28 -08008515 } else if ((pf->hw.aq.api_maj_ver > 1) ||
8516 ((pf->hw.aq.api_maj_ver == 1) &&
8517 (pf->hw.aq.api_min_ver > 4))) {
8518 /* Supported in FW API version higher than 1.4 */
8519 pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08008520 pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
8521 } else {
8522 pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
Anjali Singhai Jaind502ce02015-06-05 12:20:26 -04008523 }
Anjali Singhaia340c782016-01-06 11:49:28 -08008524
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008525 pf->eeprom_version = 0xDEAD;
8526 pf->lan_veb = I40E_NO_VEB;
8527 pf->lan_vsi = I40E_NO_VSI;
8528
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04008529 /* By default FW has this off for performance reasons */
8530 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
8531
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008532 /* set up queue assignment tracking */
8533 size = sizeof(struct i40e_lump_tracking)
8534 + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
8535 pf->qp_pile = kzalloc(size, GFP_KERNEL);
8536 if (!pf->qp_pile) {
8537 err = -ENOMEM;
8538 goto sw_init_done;
8539 }
8540 pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
8541 pf->qp_pile->search_hint = 0;
8542
Anjali Singhai Jain327fe042014-06-04 01:23:26 +00008543 pf->tx_timeout_recovery_level = 1;
8544
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008545 mutex_init(&pf->switch_mutex);
8546
Greg Rosec668a122015-02-26 16:10:39 +00008547 /* If NPAR is enabled nudge the Tx scheduler */
8548 if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf)))
8549 i40e_set_npar_bw_setting(pf);
8550
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008551sw_init_done:
8552 return err;
8553}
8554
8555/**
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008556 * i40e_set_ntuple - set the ntuple feature flag and take action
8557 * @pf: board private structure to initialize
8558 * @features: the feature set that the stack is suggesting
8559 *
8560 * returns a bool to indicate if reset needs to happen
8561 **/
8562bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
8563{
8564 bool need_reset = false;
8565
8566 /* Check if Flow Director n-tuple support was enabled or disabled. If
8567 * the state changed, we need to reset.
8568 */
8569 if (features & NETIF_F_NTUPLE) {
8570 /* Enable filters and mark for reset */
8571 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
8572 need_reset = true;
Tushar Davea70e4072016-05-16 12:40:53 -07008573 /* enable FD_SB only if there is MSI-X vector */
8574 if (pf->num_fdsb_msix > 0)
8575 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008576 } else {
8577 /* turn off filters, mark for reset and clear SW filter list */
8578 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
8579 need_reset = true;
8580 i40e_fdir_filter_exit(pf);
8581 }
8582 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain8a4f34f2014-06-04 08:45:20 +00008583 pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00008584 /* reset fd counters */
8585 pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0;
8586 pf->fdir_pf_active_filters = 0;
Anjali Singhai Jain8a4f34f2014-06-04 08:45:20 +00008587 /* if ATR was auto disabled it can be re-enabled. */
8588 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
Jacob Keller234dc4e2016-09-06 18:05:09 -07008589 (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
Anjali Singhai Jain8a4f34f2014-06-04 08:45:20 +00008590 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Jacob Keller234dc4e2016-09-06 18:05:09 -07008591 if (I40E_DEBUG_FD & pf->hw.debug_mask)
8592 dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
8593 }
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008594 }
8595 return need_reset;
8596}
8597
8598/**
Alan Bradyd8ec9862016-07-27 12:02:38 -07008599 * i40e_clear_rss_lut - clear the rx hash lookup table
8600 * @vsi: the VSI being configured
8601 **/
8602static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
8603{
8604 struct i40e_pf *pf = vsi->back;
8605 struct i40e_hw *hw = &pf->hw;
8606 u16 vf_id = vsi->vf_id;
8607 u8 i;
8608
8609 if (vsi->type == I40E_VSI_MAIN) {
8610 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8611 wr32(hw, I40E_PFQF_HLUT(i), 0);
8612 } else if (vsi->type == I40E_VSI_SRIOV) {
8613 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
8614 i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
8615 } else {
8616 dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
8617 }
8618}
8619
8620/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008621 * i40e_set_features - set the netdev feature flags
8622 * @netdev: ptr to the netdev being adjusted
8623 * @features: the feature set that the stack is suggesting
8624 **/
8625static int i40e_set_features(struct net_device *netdev,
8626 netdev_features_t features)
8627{
8628 struct i40e_netdev_priv *np = netdev_priv(netdev);
8629 struct i40e_vsi *vsi = np->vsi;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008630 struct i40e_pf *pf = vsi->back;
8631 bool need_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008632
Alan Bradyd8ec9862016-07-27 12:02:38 -07008633 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
8634 i40e_pf_config_rss(pf);
8635 else if (!(features & NETIF_F_RXHASH) &&
8636 netdev->features & NETIF_F_RXHASH)
8637 i40e_clear_rss_lut(vsi);
8638
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008639 if (features & NETIF_F_HW_VLAN_CTAG_RX)
8640 i40e_vlan_stripping_enable(vsi);
8641 else
8642 i40e_vlan_stripping_disable(vsi);
8643
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008644 need_reset = i40e_set_ntuple(pf, features);
8645
8646 if (need_reset)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008647 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008648
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008649 return 0;
8650}
8651
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008652/**
Singhai, Anjali6a899022015-12-14 12:21:18 -08008653 * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008654 * @pf: board private structure
8655 * @port: The UDP port to look up
8656 *
8657 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
8658 **/
Singhai, Anjali6a899022015-12-14 12:21:18 -08008659static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, __be16 port)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008660{
8661 u8 i;
8662
8663 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
Singhai, Anjali6a899022015-12-14 12:21:18 -08008664 if (pf->udp_ports[i].index == port)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008665 return i;
8666 }
8667
8668 return i;
8669}
8670
8671/**
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008672 * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008673 * @netdev: This physical port's netdev
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008674 * @ti: Tunnel endpoint information
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008675 **/
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008676static void i40e_udp_tunnel_add(struct net_device *netdev,
8677 struct udp_tunnel_info *ti)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008678{
8679 struct i40e_netdev_priv *np = netdev_priv(netdev);
8680 struct i40e_vsi *vsi = np->vsi;
8681 struct i40e_pf *pf = vsi->back;
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008682 __be16 port = ti->port;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008683 u8 next_idx;
8684 u8 idx;
8685
Singhai, Anjali6a899022015-12-14 12:21:18 -08008686 idx = i40e_get_udp_port_idx(pf, port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008687
8688 /* Check if port already exists */
8689 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008690 netdev_info(netdev, "port %d already offloaded\n",
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07008691 ntohs(port));
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008692 return;
8693 }
8694
8695 /* Now check if there is space to add the new port */
Singhai, Anjali6a899022015-12-14 12:21:18 -08008696 next_idx = i40e_get_udp_port_idx(pf, 0);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008697
8698 if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008699 netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008700 ntohs(port));
8701 return;
8702 }
8703
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008704 switch (ti->type) {
8705 case UDP_TUNNEL_TYPE_VXLAN:
8706 pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
8707 break;
8708 case UDP_TUNNEL_TYPE_GENEVE:
8709 if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
8710 return;
8711 pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
8712 break;
8713 default:
8714 return;
8715 }
8716
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008717 /* New port: add it and mark its index in the bitmap */
Singhai, Anjali6a899022015-12-14 12:21:18 -08008718 pf->udp_ports[next_idx].index = port;
Singhai, Anjali6a899022015-12-14 12:21:18 -08008719 pf->pending_udp_bitmap |= BIT_ULL(next_idx);
8720 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008721}
8722
8723/**
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008724 * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008725 * @netdev: This physical port's netdev
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008726 * @ti: Tunnel endpoint information
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008727 **/
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008728static void i40e_udp_tunnel_del(struct net_device *netdev,
8729 struct udp_tunnel_info *ti)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008730{
8731 struct i40e_netdev_priv *np = netdev_priv(netdev);
8732 struct i40e_vsi *vsi = np->vsi;
8733 struct i40e_pf *pf = vsi->back;
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008734 __be16 port = ti->port;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008735 u8 idx;
8736
Singhai, Anjali6a899022015-12-14 12:21:18 -08008737 idx = i40e_get_udp_port_idx(pf, port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008738
8739 /* Check if port already exists */
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008740 if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
8741 goto not_found;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008742
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008743 switch (ti->type) {
8744 case UDP_TUNNEL_TYPE_VXLAN:
8745 if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
8746 goto not_found;
8747 break;
8748 case UDP_TUNNEL_TYPE_GENEVE:
8749 if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
8750 goto not_found;
8751 break;
8752 default:
8753 goto not_found;
Singhai, Anjali6a899022015-12-14 12:21:18 -08008754 }
8755
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008756 /* if port exists, set it to 0 (mark for deletion)
8757 * and make it pending
8758 */
8759 pf->udp_ports[idx].index = 0;
8760 pf->pending_udp_bitmap |= BIT_ULL(idx);
Singhai, Anjali6a899022015-12-14 12:21:18 -08008761 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
8762
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008763 return;
8764not_found:
8765 netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
8766 ntohs(port));
Singhai, Anjali6a899022015-12-14 12:21:18 -08008767}
8768
Neerav Parikh1f224ad2014-02-12 01:45:31 +00008769static int i40e_get_phys_port_id(struct net_device *netdev,
Jiri Pirko02637fc2014-11-28 14:34:16 +01008770 struct netdev_phys_item_id *ppid)
Neerav Parikh1f224ad2014-02-12 01:45:31 +00008771{
8772 struct i40e_netdev_priv *np = netdev_priv(netdev);
8773 struct i40e_pf *pf = np->vsi->back;
8774 struct i40e_hw *hw = &pf->hw;
8775
8776 if (!(pf->flags & I40E_FLAG_PORT_ID_VALID))
8777 return -EOPNOTSUPP;
8778
8779 ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
8780 memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
8781
8782 return 0;
8783}
8784
Jesse Brandeburg2f90ade2014-11-20 16:30:02 -08008785/**
8786 * i40e_ndo_fdb_add - add an entry to the hardware database
8787 * @ndm: the input from the stack
8788 * @tb: pointer to array of nladdr (unused)
8789 * @dev: the net device pointer
8790 * @addr: the MAC address entry being added
8791 * @flags: instructions from stack about fdb operation
8792 */
Greg Rose4ba0dea2014-03-06 08:59:55 +00008793static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
8794 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01008795 const unsigned char *addr, u16 vid,
Greg Rose4ba0dea2014-03-06 08:59:55 +00008796 u16 flags)
Greg Rose4ba0dea2014-03-06 08:59:55 +00008797{
8798 struct i40e_netdev_priv *np = netdev_priv(dev);
8799 struct i40e_pf *pf = np->vsi->back;
8800 int err = 0;
8801
8802 if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
8803 return -EOPNOTSUPP;
8804
Or Gerlitz65891fe2014-12-14 18:19:05 +02008805 if (vid) {
8806 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
8807 return -EINVAL;
8808 }
8809
Greg Rose4ba0dea2014-03-06 08:59:55 +00008810 /* Hardware does not support aging addresses so if a
8811 * ndm_state is given only allow permanent addresses
8812 */
8813 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
8814 netdev_info(dev, "FDB only supports static addresses\n");
8815 return -EINVAL;
8816 }
8817
8818 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
8819 err = dev_uc_add_excl(dev, addr);
8820 else if (is_multicast_ether_addr(addr))
8821 err = dev_mc_add_excl(dev, addr);
8822 else
8823 err = -EINVAL;
8824
8825 /* Only return duplicate errors if NLM_F_EXCL is set */
8826 if (err == -EEXIST && !(flags & NLM_F_EXCL))
8827 err = 0;
8828
8829 return err;
8830}
8831
Neerav Parikh51616012015-02-06 08:52:14 +00008832/**
8833 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
8834 * @dev: the netdev being configured
8835 * @nlh: RTNL message
8836 *
8837 * Inserts a new hardware bridge if not already created and
8838 * enables the bridging mode requested (VEB or VEPA). If the
8839 * hardware bridge has already been inserted and the request
8840 * is to change the mode then that requires a PF reset to
8841 * allow rebuild of the components with required hardware
8842 * bridge mode enabled.
8843 **/
8844static int i40e_ndo_bridge_setlink(struct net_device *dev,
Carolyn Wyborny9df70b62015-04-27 14:57:11 -04008845 struct nlmsghdr *nlh,
8846 u16 flags)
Neerav Parikh51616012015-02-06 08:52:14 +00008847{
8848 struct i40e_netdev_priv *np = netdev_priv(dev);
8849 struct i40e_vsi *vsi = np->vsi;
8850 struct i40e_pf *pf = vsi->back;
8851 struct i40e_veb *veb = NULL;
8852 struct nlattr *attr, *br_spec;
8853 int i, rem;
8854
8855 /* Only for PF VSI for now */
8856 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
8857 return -EOPNOTSUPP;
8858
8859 /* Find the HW bridge for PF VSI */
8860 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
8861 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
8862 veb = pf->veb[i];
8863 }
8864
8865 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
8866
8867 nla_for_each_nested(attr, br_spec, rem) {
8868 __u16 mode;
8869
8870 if (nla_type(attr) != IFLA_BRIDGE_MODE)
8871 continue;
8872
8873 mode = nla_get_u16(attr);
8874 if ((mode != BRIDGE_MODE_VEPA) &&
8875 (mode != BRIDGE_MODE_VEB))
8876 return -EINVAL;
8877
8878 /* Insert a new HW bridge */
8879 if (!veb) {
8880 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
8881 vsi->tc_config.enabled_tc);
8882 if (veb) {
8883 veb->bridge_mode = mode;
8884 i40e_config_bridge_mode(veb);
8885 } else {
8886 /* No Bridge HW offload available */
8887 return -ENOENT;
8888 }
8889 break;
8890 } else if (mode != veb->bridge_mode) {
8891 /* Existing HW bridge but different mode needs reset */
8892 veb->bridge_mode = mode;
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07008893 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
8894 if (mode == BRIDGE_MODE_VEB)
8895 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
8896 else
8897 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
8898 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Neerav Parikh51616012015-02-06 08:52:14 +00008899 break;
8900 }
8901 }
8902
8903 return 0;
8904}
8905
8906/**
8907 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
8908 * @skb: skb buff
8909 * @pid: process id
8910 * @seq: RTNL message seq #
8911 * @dev: the netdev being configured
8912 * @filter_mask: unused
Jesse Brandeburgd4b2f9f2015-09-03 17:18:48 -04008913 * @nlflags: netlink flags passed in
Neerav Parikh51616012015-02-06 08:52:14 +00008914 *
8915 * Return the mode in which the hardware bridge is operating in
8916 * i.e VEB or VEPA.
8917 **/
Neerav Parikh51616012015-02-06 08:52:14 +00008918static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8919 struct net_device *dev,
Carolyn Wyborny9f4ffc42015-08-31 19:54:42 -04008920 u32 __always_unused filter_mask,
8921 int nlflags)
Neerav Parikh51616012015-02-06 08:52:14 +00008922{
8923 struct i40e_netdev_priv *np = netdev_priv(dev);
8924 struct i40e_vsi *vsi = np->vsi;
8925 struct i40e_pf *pf = vsi->back;
8926 struct i40e_veb *veb = NULL;
8927 int i;
8928
8929 /* Only for PF VSI for now */
8930 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
8931 return -EOPNOTSUPP;
8932
8933 /* Find the HW bridge for the PF VSI */
8934 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
8935 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
8936 veb = pf->veb[i];
8937 }
8938
8939 if (!veb)
8940 return 0;
8941
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02008942 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
Huaibin Wang599b0762016-09-26 09:51:18 +02008943 0, 0, nlflags, filter_mask, NULL);
Neerav Parikh51616012015-02-06 08:52:14 +00008944}
Neerav Parikh51616012015-02-06 08:52:14 +00008945
Singhai, Anjali6a899022015-12-14 12:21:18 -08008946/* Hardware supports L4 tunnel length of 128B (=2^7) which includes
8947 * inner mac plus all inner ethertypes.
8948 */
8949#define I40E_MAX_TUNNEL_HDR_LEN 128
Joe Stringerf44a75e2015-04-14 17:09:14 -07008950/**
8951 * i40e_features_check - Validate encapsulated packet conforms to limits
8952 * @skb: skb buff
Jean Sacren2bc11c62015-09-19 05:08:43 -06008953 * @dev: This physical port's netdev
Joe Stringerf44a75e2015-04-14 17:09:14 -07008954 * @features: Offload features that the stack believes apply
8955 **/
8956static netdev_features_t i40e_features_check(struct sk_buff *skb,
8957 struct net_device *dev,
8958 netdev_features_t features)
8959{
8960 if (skb->encapsulation &&
Singhai, Anjali6a899022015-12-14 12:21:18 -08008961 ((skb_inner_network_header(skb) - skb_transport_header(skb)) >
Joe Stringerf44a75e2015-04-14 17:09:14 -07008962 I40E_MAX_TUNNEL_HDR_LEN))
Tom Herberta1882222015-12-14 11:19:43 -08008963 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
Joe Stringerf44a75e2015-04-14 17:09:14 -07008964
8965 return features;
8966}
8967
Shannon Nelson37a29732015-02-27 09:15:19 +00008968static const struct net_device_ops i40e_netdev_ops = {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008969 .ndo_open = i40e_open,
8970 .ndo_stop = i40e_close,
8971 .ndo_start_xmit = i40e_lan_xmit_frame,
8972 .ndo_get_stats64 = i40e_get_netdev_stats_struct,
8973 .ndo_set_rx_mode = i40e_set_rx_mode,
8974 .ndo_validate_addr = eth_validate_addr,
8975 .ndo_set_mac_address = i40e_set_mac,
8976 .ndo_change_mtu = i40e_change_mtu,
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00008977 .ndo_do_ioctl = i40e_ioctl,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008978 .ndo_tx_timeout = i40e_tx_timeout,
8979 .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
8980 .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
8981#ifdef CONFIG_NET_POLL_CONTROLLER
8982 .ndo_poll_controller = i40e_netpoll,
8983#endif
John Fastabende4c67342016-02-16 21:16:15 -08008984 .ndo_setup_tc = __i40e_setup_tc,
Vasu Dev38e00432014-08-01 13:27:03 -07008985#ifdef I40E_FCOE
8986 .ndo_fcoe_enable = i40e_fcoe_enable,
8987 .ndo_fcoe_disable = i40e_fcoe_disable,
8988#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008989 .ndo_set_features = i40e_set_features,
8990 .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
8991 .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04008992 .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008993 .ndo_get_vf_config = i40e_ndo_get_vf_config,
Mitch Williams588aefa2014-02-11 08:27:49 +00008994 .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
Serey Konge6d90042014-07-12 07:28:14 +00008995 .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
Anjali Singhai Jainc3bbbd22016-04-01 03:56:07 -07008996 .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008997 .ndo_udp_tunnel_add = i40e_udp_tunnel_add,
8998 .ndo_udp_tunnel_del = i40e_udp_tunnel_del,
Neerav Parikh1f224ad2014-02-12 01:45:31 +00008999 .ndo_get_phys_port_id = i40e_get_phys_port_id,
Greg Rose4ba0dea2014-03-06 08:59:55 +00009000 .ndo_fdb_add = i40e_ndo_fdb_add,
Joe Stringerf44a75e2015-04-14 17:09:14 -07009001 .ndo_features_check = i40e_features_check,
Neerav Parikh51616012015-02-06 08:52:14 +00009002 .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
9003 .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009004};
9005
9006/**
9007 * i40e_config_netdev - Setup the netdev flags
9008 * @vsi: the VSI being configured
9009 *
9010 * Returns 0 on success, negative value on failure
9011 **/
9012static int i40e_config_netdev(struct i40e_vsi *vsi)
9013{
9014 struct i40e_pf *pf = vsi->back;
9015 struct i40e_hw *hw = &pf->hw;
9016 struct i40e_netdev_priv *np;
9017 struct net_device *netdev;
9018 u8 mac_addr[ETH_ALEN];
9019 int etherdev_size;
9020
9021 etherdev_size = sizeof(struct i40e_netdev_priv);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00009022 netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009023 if (!netdev)
9024 return -ENOMEM;
9025
9026 vsi->netdev = netdev;
9027 np = netdev_priv(netdev);
9028 np->vsi = vsi;
9029
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009030 netdev->hw_enc_features |= NETIF_F_SG |
9031 NETIF_F_IP_CSUM |
9032 NETIF_F_IPV6_CSUM |
9033 NETIF_F_HIGHDMA |
9034 NETIF_F_SOFT_FEATURES |
9035 NETIF_F_TSO |
9036 NETIF_F_TSO_ECN |
9037 NETIF_F_TSO6 |
9038 NETIF_F_GSO_GRE |
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04009039 NETIF_F_GSO_GRE_CSUM |
Tom Herbert7e133182016-05-18 09:06:10 -07009040 NETIF_F_GSO_IPXIP4 |
Alexander Duyckbf2d1df2016-05-18 10:44:53 -07009041 NETIF_F_GSO_IPXIP6 |
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009042 NETIF_F_GSO_UDP_TUNNEL |
9043 NETIF_F_GSO_UDP_TUNNEL_CSUM |
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04009044 NETIF_F_GSO_PARTIAL |
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009045 NETIF_F_SCTP_CRC |
9046 NETIF_F_RXHASH |
9047 NETIF_F_RXCSUM |
Jesse Brandeburg5afdaaa2015-12-10 11:38:50 -08009048 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009049
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009050 if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE))
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04009051 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
9052
9053 netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009054
9055 /* record features VLANs can make use of */
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04009056 netdev->vlan_features |= netdev->hw_enc_features |
9057 NETIF_F_TSO_MANGLEID;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009058
Anjali Singhai Jain2e86a0b2014-04-01 07:11:53 +00009059 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009060 netdev->hw_features |= NETIF_F_NTUPLE;
Anjali Singhai Jain2e86a0b2014-04-01 07:11:53 +00009061
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009062 netdev->hw_features |= netdev->hw_enc_features |
9063 NETIF_F_HW_VLAN_CTAG_TX |
9064 NETIF_F_HW_VLAN_CTAG_RX;
9065
9066 netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04009067 netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009068
9069 if (vsi->type == I40E_VSI_MAIN) {
9070 SET_NETDEV_DEV(netdev, &pf->pdev->dev);
Greg Rose9a173902014-05-22 06:32:02 +00009071 ether_addr_copy(mac_addr, hw->mac.perm_addr);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07009072 spin_lock_bh(&vsi->mac_filter_list_lock);
Jacob Keller1bc87e82016-10-05 09:30:31 -07009073 i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07009074 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009075 } else {
9076 /* relate the VSI_VMDQ name to the VSI_MAIN name */
9077 snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
9078 pf->vsi[pf->lan_vsi]->netdev->name);
9079 random_ether_addr(mac_addr);
Kiran Patil21659032015-09-30 14:09:03 -04009080
9081 spin_lock_bh(&vsi->mac_filter_list_lock);
Jacob Keller1bc87e82016-10-05 09:30:31 -07009082 i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY);
Kiran Patil21659032015-09-30 14:09:03 -04009083 spin_unlock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009084 }
Kiran Patil21659032015-09-30 14:09:03 -04009085
Greg Rose9a173902014-05-22 06:32:02 +00009086 ether_addr_copy(netdev->dev_addr, mac_addr);
9087 ether_addr_copy(netdev->perm_addr, mac_addr);
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009088
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009089 netdev->priv_flags |= IFF_UNICAST_FLT;
9090 netdev->priv_flags |= IFF_SUPP_NOFCS;
9091 /* Setup netdev TC information */
9092 i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
9093
9094 netdev->netdev_ops = &i40e_netdev_ops;
9095 netdev->watchdog_timeo = 5 * HZ;
9096 i40e_set_ethtool_ops(netdev);
Vasu Dev38e00432014-08-01 13:27:03 -07009097#ifdef I40E_FCOE
9098 i40e_fcoe_config_netdev(netdev, vsi);
9099#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009100
Jarod Wilson91c527a2016-10-17 15:54:05 -04009101 /* MTU range: 68 - 9706 */
9102 netdev->min_mtu = ETH_MIN_MTU;
9103 netdev->max_mtu = I40E_MAX_RXBUFFER -
9104 (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
9105
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009106 return 0;
9107}
9108
9109/**
9110 * i40e_vsi_delete - Delete a VSI from the switch
9111 * @vsi: the VSI being removed
9112 *
9113 * Returns 0 on success, negative value on failure
9114 **/
9115static void i40e_vsi_delete(struct i40e_vsi *vsi)
9116{
9117 /* remove default VSI is not allowed */
9118 if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
9119 return;
9120
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009121 i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009122}
9123
9124/**
Neerav Parikh51616012015-02-06 08:52:14 +00009125 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
9126 * @vsi: the VSI being queried
9127 *
9128 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
9129 **/
9130int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
9131{
9132 struct i40e_veb *veb;
9133 struct i40e_pf *pf = vsi->back;
9134
9135 /* Uplink is not a bridge so default to VEB */
9136 if (vsi->veb_idx == I40E_NO_VEB)
9137 return 1;
9138
9139 veb = pf->veb[vsi->veb_idx];
Akeem G Abodunrin09603ea2015-10-01 14:37:36 -04009140 if (!veb) {
9141 dev_info(&pf->pdev->dev,
9142 "There is no veb associated with the bridge\n");
9143 return -ENOENT;
9144 }
Neerav Parikh51616012015-02-06 08:52:14 +00009145
Akeem G Abodunrin09603ea2015-10-01 14:37:36 -04009146 /* Uplink is a bridge in VEPA mode */
9147 if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
9148 return 0;
9149 } else {
9150 /* Uplink is a bridge in VEB mode */
9151 return 1;
9152 }
9153
9154 /* VEPA is now default bridge, so return 0 */
9155 return 0;
Neerav Parikh51616012015-02-06 08:52:14 +00009156}
9157
9158/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009159 * i40e_add_vsi - Add a VSI to the switch
9160 * @vsi: the VSI being configured
9161 *
9162 * This initializes a VSI context depending on the VSI type to be added and
9163 * passes it down to the add_vsi aq command.
9164 **/
9165static int i40e_add_vsi(struct i40e_vsi *vsi)
9166{
9167 int ret = -ENODEV;
Kiran Patilf6bd0962016-06-20 09:10:34 -07009168 i40e_status aq_ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009169 struct i40e_pf *pf = vsi->back;
9170 struct i40e_hw *hw = &pf->hw;
9171 struct i40e_vsi_context ctxt;
Kiran Patil21659032015-09-30 14:09:03 -04009172 struct i40e_mac_filter *f, *ftmp;
9173
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009174 u8 enabled_tc = 0x1; /* TC0 enabled */
9175 int f_count = 0;
9176
9177 memset(&ctxt, 0, sizeof(ctxt));
9178 switch (vsi->type) {
9179 case I40E_VSI_MAIN:
9180 /* The PF's main VSI is already setup as part of the
9181 * device initialization, so we'll not bother with
9182 * the add_vsi call, but we will retrieve the current
9183 * VSI context.
9184 */
9185 ctxt.seid = pf->main_vsi_seid;
9186 ctxt.pf_num = pf->hw.pf_id;
9187 ctxt.vf_num = 0;
9188 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
9189 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
9190 if (ret) {
9191 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009192 "couldn't get PF vsi config, err %s aq_err %s\n",
9193 i40e_stat_str(&pf->hw, ret),
9194 i40e_aq_str(&pf->hw,
9195 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009196 return -ENOENT;
9197 }
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07009198 vsi->info = ctxt.info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009199 vsi->info.valid_sections = 0;
9200
9201 vsi->seid = ctxt.seid;
9202 vsi->id = ctxt.vsi_number;
9203
9204 enabled_tc = i40e_pf_get_tc_map(pf);
9205
9206 /* MFP mode setup queue map and update VSI */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00009207 if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
9208 !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009209 memset(&ctxt, 0, sizeof(ctxt));
9210 ctxt.seid = pf->main_vsi_seid;
9211 ctxt.pf_num = pf->hw.pf_id;
9212 ctxt.vf_num = 0;
9213 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
9214 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
9215 if (ret) {
9216 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009217 "update vsi failed, err %s aq_err %s\n",
9218 i40e_stat_str(&pf->hw, ret),
9219 i40e_aq_str(&pf->hw,
9220 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009221 ret = -ENOENT;
9222 goto err;
9223 }
9224 /* update the local VSI info queue map */
9225 i40e_vsi_update_queue_map(vsi, &ctxt);
9226 vsi->info.valid_sections = 0;
9227 } else {
9228 /* Default/Main VSI is only enabled for TC0
9229 * reconfigure it to enable all TCs that are
9230 * available on the port in SFP mode.
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00009231 * For MFP case the iSCSI PF would use this
9232 * flow to enable LAN+iSCSI TC.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009233 */
9234 ret = i40e_vsi_config_tc(vsi, enabled_tc);
9235 if (ret) {
9236 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009237 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
9238 enabled_tc,
9239 i40e_stat_str(&pf->hw, ret),
9240 i40e_aq_str(&pf->hw,
9241 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009242 ret = -ENOENT;
9243 }
9244 }
9245 break;
9246
9247 case I40E_VSI_FDIR:
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009248 ctxt.pf_num = hw->pf_id;
9249 ctxt.vf_num = 0;
9250 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009251 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009252 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009253 if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
9254 (i40e_is_vsi_uplink_mode_veb(vsi))) {
Neerav Parikh51616012015-02-06 08:52:14 +00009255 ctxt.info.valid_sections |=
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009256 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
Neerav Parikh51616012015-02-06 08:52:14 +00009257 ctxt.info.switch_id =
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009258 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
Neerav Parikh51616012015-02-06 08:52:14 +00009259 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009260 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009261 break;
9262
9263 case I40E_VSI_VMDQ2:
9264 ctxt.pf_num = hw->pf_id;
9265 ctxt.vf_num = 0;
9266 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009267 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009268 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
9269
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009270 /* This VSI is connected to VEB so the switch_id
9271 * should be set to zero by default.
9272 */
Neerav Parikh51616012015-02-06 08:52:14 +00009273 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
9274 ctxt.info.valid_sections |=
9275 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9276 ctxt.info.switch_id =
9277 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9278 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009279
9280 /* Setup the VSI tx/rx queue map for TC0 only for now */
9281 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9282 break;
9283
9284 case I40E_VSI_SRIOV:
9285 ctxt.pf_num = hw->pf_id;
9286 ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
9287 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009288 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009289 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
9290
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009291 /* This VSI is connected to VEB so the switch_id
9292 * should be set to zero by default.
9293 */
Neerav Parikh51616012015-02-06 08:52:14 +00009294 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
9295 ctxt.info.valid_sections |=
9296 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9297 ctxt.info.switch_id =
9298 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9299 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009300
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06009301 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
9302 ctxt.info.valid_sections |=
9303 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
9304 ctxt.info.queueing_opt_flags |=
Ashish Shah4b28cdb2016-05-03 15:13:17 -07009305 (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
9306 I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06009307 }
9308
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009309 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
9310 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
Mitch Williamsc674d122014-05-20 08:01:40 +00009311 if (pf->vf[vsi->vf_id].spoofchk) {
9312 ctxt.info.valid_sections |=
9313 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
9314 ctxt.info.sec_flags |=
9315 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
9316 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
9317 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009318 /* Setup the VSI tx/rx queue map for TC0 only for now */
9319 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9320 break;
9321
Vasu Dev38e00432014-08-01 13:27:03 -07009322#ifdef I40E_FCOE
9323 case I40E_VSI_FCOE:
9324 ret = i40e_fcoe_vsi_init(vsi, &ctxt);
9325 if (ret) {
9326 dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n");
9327 return ret;
9328 }
9329 break;
9330
9331#endif /* I40E_FCOE */
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06009332 case I40E_VSI_IWARP:
9333 /* send down message to iWARP */
9334 break;
9335
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009336 default:
9337 return -ENODEV;
9338 }
9339
9340 if (vsi->type != I40E_VSI_MAIN) {
9341 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
9342 if (ret) {
9343 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009344 "add vsi failed, err %s aq_err %s\n",
9345 i40e_stat_str(&pf->hw, ret),
9346 i40e_aq_str(&pf->hw,
9347 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009348 ret = -ENOENT;
9349 goto err;
9350 }
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07009351 vsi->info = ctxt.info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009352 vsi->info.valid_sections = 0;
9353 vsi->seid = ctxt.seid;
9354 vsi->id = ctxt.vsi_number;
9355 }
Kiran Patilf6bd0962016-06-20 09:10:34 -07009356 /* Except FDIR VSI, for all othet VSI set the broadcast filter */
9357 if (vsi->type != I40E_VSI_FDIR) {
9358 aq_ret = i40e_aq_set_vsi_broadcast(hw, vsi->seid, true, NULL);
9359 if (aq_ret) {
9360 ret = i40e_aq_rc_to_posix(aq_ret,
9361 hw->aq.asq_last_status);
9362 dev_info(&pf->pdev->dev,
9363 "set brdcast promisc failed, err %s, aq_err %s\n",
9364 i40e_stat_str(hw, aq_ret),
9365 i40e_aq_str(hw, hw->aq.asq_last_status));
9366 }
9367 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009368
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07009369 vsi->active_filters = 0;
9370 clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
Kiran Patil21659032015-09-30 14:09:03 -04009371 spin_lock_bh(&vsi->mac_filter_list_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009372 /* If macvlan filters already exist, force them to get loaded */
9373 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07009374 f->state = I40E_FILTER_NEW;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009375 f_count++;
9376 }
Kiran Patil21659032015-09-30 14:09:03 -04009377 spin_unlock_bh(&vsi->mac_filter_list_lock);
9378
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009379 if (f_count) {
9380 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
9381 pf->flags |= I40E_FLAG_FILTER_SYNC;
9382 }
9383
9384 /* Update VSI BW information */
9385 ret = i40e_vsi_get_bw_info(vsi);
9386 if (ret) {
9387 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009388 "couldn't get vsi bw info, err %s aq_err %s\n",
9389 i40e_stat_str(&pf->hw, ret),
9390 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009391 /* VSI is already added so not tearing that up */
9392 ret = 0;
9393 }
9394
9395err:
9396 return ret;
9397}
9398
9399/**
9400 * i40e_vsi_release - Delete a VSI and free its resources
9401 * @vsi: the VSI being removed
9402 *
9403 * Returns 0 on success or < 0 on error
9404 **/
9405int i40e_vsi_release(struct i40e_vsi *vsi)
9406{
9407 struct i40e_mac_filter *f, *ftmp;
9408 struct i40e_veb *veb = NULL;
9409 struct i40e_pf *pf;
9410 u16 uplink_seid;
9411 int i, n;
9412
9413 pf = vsi->back;
9414
9415 /* release of a VEB-owner or last VSI is not allowed */
9416 if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
9417 dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
9418 vsi->seid, vsi->uplink_seid);
9419 return -ENODEV;
9420 }
9421 if (vsi == pf->vsi[pf->lan_vsi] &&
9422 !test_bit(__I40E_DOWN, &pf->state)) {
9423 dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
9424 return -ENODEV;
9425 }
9426
9427 uplink_seid = vsi->uplink_seid;
9428 if (vsi->type != I40E_VSI_SRIOV) {
9429 if (vsi->netdev_registered) {
9430 vsi->netdev_registered = false;
9431 if (vsi->netdev) {
9432 /* results in a call to i40e_close() */
9433 unregister_netdev(vsi->netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009434 }
9435 } else {
Shannon Nelson90ef8d42014-03-14 07:32:26 +00009436 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009437 }
9438 i40e_vsi_disable_irq(vsi);
9439 }
9440
Kiran Patil21659032015-09-30 14:09:03 -04009441 spin_lock_bh(&vsi->mac_filter_list_lock);
Jacob Keller6622f5c2016-10-05 09:30:32 -07009442
9443 /* clear the sync flag on all filters */
9444 if (vsi->netdev) {
9445 __dev_uc_unsync(vsi->netdev, NULL);
9446 __dev_mc_unsync(vsi->netdev, NULL);
9447 }
9448
9449 /* make sure any remaining filters are marked for deletion */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009450 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
Jacob Keller1bc87e82016-10-05 09:30:31 -07009451 i40e_del_filter(vsi, f->macaddr, f->vlan);
Jacob Keller6622f5c2016-10-05 09:30:32 -07009452
Kiran Patil21659032015-09-30 14:09:03 -04009453 spin_unlock_bh(&vsi->mac_filter_list_lock);
9454
Jesse Brandeburg17652c62015-11-05 17:01:02 -08009455 i40e_sync_vsi_filters(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009456
9457 i40e_vsi_delete(vsi);
9458 i40e_vsi_free_q_vectors(vsi);
Shannon Nelsona4866592014-02-11 08:24:07 +00009459 if (vsi->netdev) {
9460 free_netdev(vsi->netdev);
9461 vsi->netdev = NULL;
9462 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009463 i40e_vsi_clear_rings(vsi);
9464 i40e_vsi_clear(vsi);
9465
9466 /* If this was the last thing on the VEB, except for the
9467 * controlling VSI, remove the VEB, which puts the controlling
9468 * VSI onto the next level down in the switch.
9469 *
9470 * Well, okay, there's one more exception here: don't remove
9471 * the orphan VEBs yet. We'll wait for an explicit remove request
9472 * from up the network stack.
9473 */
Mitch Williams505682c2014-05-20 08:01:37 +00009474 for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009475 if (pf->vsi[i] &&
9476 pf->vsi[i]->uplink_seid == uplink_seid &&
9477 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
9478 n++; /* count the VSIs */
9479 }
9480 }
9481 for (i = 0; i < I40E_MAX_VEB; i++) {
9482 if (!pf->veb[i])
9483 continue;
9484 if (pf->veb[i]->uplink_seid == uplink_seid)
9485 n++; /* count the VEBs */
9486 if (pf->veb[i]->seid == uplink_seid)
9487 veb = pf->veb[i];
9488 }
9489 if (n == 0 && veb && veb->uplink_seid != 0)
9490 i40e_veb_release(veb);
9491
9492 return 0;
9493}
9494
9495/**
9496 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
9497 * @vsi: ptr to the VSI
9498 *
9499 * This should only be called after i40e_vsi_mem_alloc() which allocates the
9500 * corresponding SW VSI structure and initializes num_queue_pairs for the
9501 * newly allocated VSI.
9502 *
9503 * Returns 0 on success or negative on failure
9504 **/
9505static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
9506{
9507 int ret = -ENOENT;
9508 struct i40e_pf *pf = vsi->back;
9509
Alexander Duyck493fb302013-09-28 07:01:44 +00009510 if (vsi->q_vectors[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009511 dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
9512 vsi->seid);
9513 return -EEXIST;
9514 }
9515
9516 if (vsi->base_vector) {
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00009517 dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009518 vsi->seid, vsi->base_vector);
9519 return -EEXIST;
9520 }
9521
Greg Rose90e04072014-03-06 08:59:57 +00009522 ret = i40e_vsi_alloc_q_vectors(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009523 if (ret) {
9524 dev_info(&pf->pdev->dev,
9525 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
9526 vsi->num_q_vectors, vsi->seid, ret);
9527 vsi->num_q_vectors = 0;
9528 goto vector_setup_out;
9529 }
9530
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04009531 /* In Legacy mode, we do not have to get any other vector since we
9532 * piggyback on the misc/ICR0 for queue interrupts.
9533 */
9534 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
9535 return ret;
Shannon Nelson958a3e32013-09-28 07:13:28 +00009536 if (vsi->num_q_vectors)
9537 vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
9538 vsi->num_q_vectors, vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009539 if (vsi->base_vector < 0) {
9540 dev_info(&pf->pdev->dev,
Shannon Nelson049a2be2014-10-17 03:14:50 +00009541 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
9542 vsi->num_q_vectors, vsi->seid, vsi->base_vector);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009543 i40e_vsi_free_q_vectors(vsi);
9544 ret = -ENOENT;
9545 goto vector_setup_out;
9546 }
9547
9548vector_setup_out:
9549 return ret;
9550}
9551
9552/**
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009553 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
9554 * @vsi: pointer to the vsi.
9555 *
9556 * This re-allocates a vsi's queue resources.
9557 *
9558 * Returns pointer to the successfully allocated and configured VSI sw struct
9559 * on success, otherwise returns NULL on failure.
9560 **/
9561static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
9562{
John Underwoodf5340392016-02-18 09:19:24 -08009563 struct i40e_pf *pf;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009564 u8 enabled_tc;
9565 int ret;
9566
John Underwoodf5340392016-02-18 09:19:24 -08009567 if (!vsi)
9568 return NULL;
9569
9570 pf = vsi->back;
9571
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009572 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
9573 i40e_vsi_clear_rings(vsi);
9574
9575 i40e_vsi_free_arrays(vsi, false);
9576 i40e_set_num_rings_in_vsi(vsi);
9577 ret = i40e_vsi_alloc_arrays(vsi, false);
9578 if (ret)
9579 goto err_vsi;
9580
9581 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
9582 if (ret < 0) {
Shannon Nelson049a2be2014-10-17 03:14:50 +00009583 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009584 "failed to get tracking for %d queues for VSI %d err %d\n",
Shannon Nelson049a2be2014-10-17 03:14:50 +00009585 vsi->alloc_queue_pairs, vsi->seid, ret);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009586 goto err_vsi;
9587 }
9588 vsi->base_queue = ret;
9589
9590 /* Update the FW view of the VSI. Force a reset of TC and queue
9591 * layout configurations.
9592 */
9593 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
9594 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
9595 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
9596 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
9597
9598 /* assign it some queues */
9599 ret = i40e_alloc_rings(vsi);
9600 if (ret)
9601 goto err_rings;
9602
9603 /* map all of the rings to the q_vectors */
9604 i40e_vsi_map_rings_to_vectors(vsi);
9605 return vsi;
9606
9607err_rings:
9608 i40e_vsi_free_q_vectors(vsi);
9609 if (vsi->netdev_registered) {
9610 vsi->netdev_registered = false;
9611 unregister_netdev(vsi->netdev);
9612 free_netdev(vsi->netdev);
9613 vsi->netdev = NULL;
9614 }
9615 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
9616err_vsi:
9617 i40e_vsi_clear(vsi);
9618 return NULL;
9619}
9620
9621/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009622 * i40e_vsi_setup - Set up a VSI by a given type
9623 * @pf: board private structure
9624 * @type: VSI type
9625 * @uplink_seid: the switch element to link to
9626 * @param1: usage depends upon VSI type. For VF types, indicates VF id
9627 *
9628 * This allocates the sw VSI structure and its queue resources, then add a VSI
9629 * to the identified VEB.
9630 *
9631 * Returns pointer to the successfully allocated and configure VSI sw struct on
9632 * success, otherwise returns NULL on failure.
9633 **/
9634struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
9635 u16 uplink_seid, u32 param1)
9636{
9637 struct i40e_vsi *vsi = NULL;
9638 struct i40e_veb *veb = NULL;
9639 int ret, i;
9640 int v_idx;
9641
9642 /* The requested uplink_seid must be either
9643 * - the PF's port seid
9644 * no VEB is needed because this is the PF
9645 * or this is a Flow Director special case VSI
9646 * - seid of an existing VEB
9647 * - seid of a VSI that owns an existing VEB
9648 * - seid of a VSI that doesn't own a VEB
9649 * a new VEB is created and the VSI becomes the owner
9650 * - seid of the PF VSI, which is what creates the first VEB
9651 * this is a special case of the previous
9652 *
9653 * Find which uplink_seid we were given and create a new VEB if needed
9654 */
9655 for (i = 0; i < I40E_MAX_VEB; i++) {
9656 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
9657 veb = pf->veb[i];
9658 break;
9659 }
9660 }
9661
9662 if (!veb && uplink_seid != pf->mac_seid) {
9663
Mitch Williams505682c2014-05-20 08:01:37 +00009664 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009665 if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
9666 vsi = pf->vsi[i];
9667 break;
9668 }
9669 }
9670 if (!vsi) {
9671 dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
9672 uplink_seid);
9673 return NULL;
9674 }
9675
9676 if (vsi->uplink_seid == pf->mac_seid)
9677 veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
9678 vsi->tc_config.enabled_tc);
9679 else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
9680 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
9681 vsi->tc_config.enabled_tc);
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009682 if (veb) {
9683 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
9684 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04009685 "New VSI creation error, uplink seid of LAN VSI expected.\n");
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009686 return NULL;
9687 }
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -04009688 /* We come up by default in VEPA mode if SRIOV is not
9689 * already enabled, in which case we can't force VEPA
9690 * mode.
9691 */
9692 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
9693 veb->bridge_mode = BRIDGE_MODE_VEPA;
9694 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
9695 }
Neerav Parikh51616012015-02-06 08:52:14 +00009696 i40e_config_bridge_mode(veb);
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009697 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009698 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
9699 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
9700 veb = pf->veb[i];
9701 }
9702 if (!veb) {
9703 dev_info(&pf->pdev->dev, "couldn't add VEB\n");
9704 return NULL;
9705 }
9706
9707 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
9708 uplink_seid = veb->seid;
9709 }
9710
9711 /* get vsi sw struct */
9712 v_idx = i40e_vsi_mem_alloc(pf, type);
9713 if (v_idx < 0)
9714 goto err_alloc;
9715 vsi = pf->vsi[v_idx];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009716 if (!vsi)
9717 goto err_alloc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009718 vsi->type = type;
9719 vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
9720
9721 if (type == I40E_VSI_MAIN)
9722 pf->lan_vsi = v_idx;
9723 else if (type == I40E_VSI_SRIOV)
9724 vsi->vf_id = param1;
9725 /* assign it some queues */
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009726 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
9727 vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009728 if (ret < 0) {
Shannon Nelson049a2be2014-10-17 03:14:50 +00009729 dev_info(&pf->pdev->dev,
9730 "failed to get tracking for %d queues for VSI %d err=%d\n",
9731 vsi->alloc_queue_pairs, vsi->seid, ret);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009732 goto err_vsi;
9733 }
9734 vsi->base_queue = ret;
9735
9736 /* get a VSI from the hardware */
9737 vsi->uplink_seid = uplink_seid;
9738 ret = i40e_add_vsi(vsi);
9739 if (ret)
9740 goto err_vsi;
9741
9742 switch (vsi->type) {
9743 /* setup the netdev if needed */
9744 case I40E_VSI_MAIN:
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -05009745 /* Apply relevant filters if a platform-specific mac
9746 * address was selected.
9747 */
9748 if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
9749 ret = i40e_macaddr_init(vsi, pf->hw.mac.addr);
9750 if (ret) {
9751 dev_warn(&pf->pdev->dev,
9752 "could not set up macaddr; err %d\n",
9753 ret);
9754 }
9755 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009756 case I40E_VSI_VMDQ2:
Vasu Dev38e00432014-08-01 13:27:03 -07009757 case I40E_VSI_FCOE:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009758 ret = i40e_config_netdev(vsi);
9759 if (ret)
9760 goto err_netdev;
9761 ret = register_netdev(vsi->netdev);
9762 if (ret)
9763 goto err_netdev;
9764 vsi->netdev_registered = true;
9765 netif_carrier_off(vsi->netdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08009766#ifdef CONFIG_I40E_DCB
9767 /* Setup DCB netlink interface */
9768 i40e_dcbnl_setup(vsi);
9769#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009770 /* fall through */
9771
9772 case I40E_VSI_FDIR:
9773 /* set up vectors and rings if needed */
9774 ret = i40e_vsi_setup_vectors(vsi);
9775 if (ret)
9776 goto err_msix;
9777
9778 ret = i40e_alloc_rings(vsi);
9779 if (ret)
9780 goto err_rings;
9781
9782 /* map all of the rings to the q_vectors */
9783 i40e_vsi_map_rings_to_vectors(vsi);
9784
9785 i40e_vsi_reset_stats(vsi);
9786 break;
9787
9788 default:
9789 /* no netdev or rings for the other VSI types */
9790 break;
9791 }
9792
Anjali Singhai Jaine25d00b82015-06-23 19:00:04 -04009793 if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
9794 (vsi->type == I40E_VSI_VMDQ2)) {
9795 ret = i40e_vsi_config_rss(vsi);
9796 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009797 return vsi;
9798
9799err_rings:
9800 i40e_vsi_free_q_vectors(vsi);
9801err_msix:
9802 if (vsi->netdev_registered) {
9803 vsi->netdev_registered = false;
9804 unregister_netdev(vsi->netdev);
9805 free_netdev(vsi->netdev);
9806 vsi->netdev = NULL;
9807 }
9808err_netdev:
9809 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
9810err_vsi:
9811 i40e_vsi_clear(vsi);
9812err_alloc:
9813 return NULL;
9814}
9815
9816/**
9817 * i40e_veb_get_bw_info - Query VEB BW information
9818 * @veb: the veb to query
9819 *
9820 * Query the Tx scheduler BW configuration data for given VEB
9821 **/
9822static int i40e_veb_get_bw_info(struct i40e_veb *veb)
9823{
9824 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
9825 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
9826 struct i40e_pf *pf = veb->pf;
9827 struct i40e_hw *hw = &pf->hw;
9828 u32 tc_bw_max;
9829 int ret = 0;
9830 int i;
9831
9832 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
9833 &bw_data, NULL);
9834 if (ret) {
9835 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009836 "query veb bw config failed, err %s aq_err %s\n",
9837 i40e_stat_str(&pf->hw, ret),
9838 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009839 goto out;
9840 }
9841
9842 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
9843 &ets_data, NULL);
9844 if (ret) {
9845 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009846 "query veb bw ets config failed, err %s aq_err %s\n",
9847 i40e_stat_str(&pf->hw, ret),
9848 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009849 goto out;
9850 }
9851
9852 veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
9853 veb->bw_max_quanta = ets_data.tc_bw_max;
9854 veb->is_abs_credits = bw_data.absolute_credits_enable;
Neerav Parikh23cd1f02014-11-12 00:18:41 +00009855 veb->enabled_tc = ets_data.tc_valid_bits;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009856 tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
9857 (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
9858 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
9859 veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
9860 veb->bw_tc_limit_credits[i] =
9861 le16_to_cpu(bw_data.tc_bw_limits[i]);
9862 veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
9863 }
9864
9865out:
9866 return ret;
9867}
9868
9869/**
9870 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
9871 * @pf: board private structure
9872 *
9873 * On error: returns error code (negative)
9874 * On success: returns vsi index in PF (positive)
9875 **/
9876static int i40e_veb_mem_alloc(struct i40e_pf *pf)
9877{
9878 int ret = -ENOENT;
9879 struct i40e_veb *veb;
9880 int i;
9881
9882 /* Need to protect the allocation of switch elements at the PF level */
9883 mutex_lock(&pf->switch_mutex);
9884
9885 /* VEB list may be fragmented if VEB creation/destruction has
9886 * been happening. We can afford to do a quick scan to look
9887 * for any free slots in the list.
9888 *
9889 * find next empty veb slot, looping back around if necessary
9890 */
9891 i = 0;
9892 while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
9893 i++;
9894 if (i >= I40E_MAX_VEB) {
9895 ret = -ENOMEM;
9896 goto err_alloc_veb; /* out of VEB slots! */
9897 }
9898
9899 veb = kzalloc(sizeof(*veb), GFP_KERNEL);
9900 if (!veb) {
9901 ret = -ENOMEM;
9902 goto err_alloc_veb;
9903 }
9904 veb->pf = pf;
9905 veb->idx = i;
9906 veb->enabled_tc = 1;
9907
9908 pf->veb[i] = veb;
9909 ret = i;
9910err_alloc_veb:
9911 mutex_unlock(&pf->switch_mutex);
9912 return ret;
9913}
9914
9915/**
9916 * i40e_switch_branch_release - Delete a branch of the switch tree
9917 * @branch: where to start deleting
9918 *
9919 * This uses recursion to find the tips of the branch to be
9920 * removed, deleting until we get back to and can delete this VEB.
9921 **/
9922static void i40e_switch_branch_release(struct i40e_veb *branch)
9923{
9924 struct i40e_pf *pf = branch->pf;
9925 u16 branch_seid = branch->seid;
9926 u16 veb_idx = branch->idx;
9927 int i;
9928
9929 /* release any VEBs on this VEB - RECURSION */
9930 for (i = 0; i < I40E_MAX_VEB; i++) {
9931 if (!pf->veb[i])
9932 continue;
9933 if (pf->veb[i]->uplink_seid == branch->seid)
9934 i40e_switch_branch_release(pf->veb[i]);
9935 }
9936
9937 /* Release the VSIs on this VEB, but not the owner VSI.
9938 *
9939 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
9940 * the VEB itself, so don't use (*branch) after this loop.
9941 */
Mitch Williams505682c2014-05-20 08:01:37 +00009942 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009943 if (!pf->vsi[i])
9944 continue;
9945 if (pf->vsi[i]->uplink_seid == branch_seid &&
9946 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
9947 i40e_vsi_release(pf->vsi[i]);
9948 }
9949 }
9950
9951 /* There's one corner case where the VEB might not have been
9952 * removed, so double check it here and remove it if needed.
9953 * This case happens if the veb was created from the debugfs
9954 * commands and no VSIs were added to it.
9955 */
9956 if (pf->veb[veb_idx])
9957 i40e_veb_release(pf->veb[veb_idx]);
9958}
9959
9960/**
9961 * i40e_veb_clear - remove veb struct
9962 * @veb: the veb to remove
9963 **/
9964static void i40e_veb_clear(struct i40e_veb *veb)
9965{
9966 if (!veb)
9967 return;
9968
9969 if (veb->pf) {
9970 struct i40e_pf *pf = veb->pf;
9971
9972 mutex_lock(&pf->switch_mutex);
9973 if (pf->veb[veb->idx] == veb)
9974 pf->veb[veb->idx] = NULL;
9975 mutex_unlock(&pf->switch_mutex);
9976 }
9977
9978 kfree(veb);
9979}
9980
9981/**
9982 * i40e_veb_release - Delete a VEB and free its resources
9983 * @veb: the VEB being removed
9984 **/
9985void i40e_veb_release(struct i40e_veb *veb)
9986{
9987 struct i40e_vsi *vsi = NULL;
9988 struct i40e_pf *pf;
9989 int i, n = 0;
9990
9991 pf = veb->pf;
9992
9993 /* find the remaining VSI and check for extras */
Mitch Williams505682c2014-05-20 08:01:37 +00009994 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009995 if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
9996 n++;
9997 vsi = pf->vsi[i];
9998 }
9999 }
10000 if (n != 1) {
10001 dev_info(&pf->pdev->dev,
10002 "can't remove VEB %d with %d VSIs left\n",
10003 veb->seid, n);
10004 return;
10005 }
10006
10007 /* move the remaining VSI to uplink veb */
10008 vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
10009 if (veb->uplink_seid) {
10010 vsi->uplink_seid = veb->uplink_seid;
10011 if (veb->uplink_seid == pf->mac_seid)
10012 vsi->veb_idx = I40E_NO_VEB;
10013 else
10014 vsi->veb_idx = veb->veb_idx;
10015 } else {
10016 /* floating VEB */
10017 vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
10018 vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
10019 }
10020
10021 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
10022 i40e_veb_clear(veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010023}
10024
10025/**
10026 * i40e_add_veb - create the VEB in the switch
10027 * @veb: the VEB to be instantiated
10028 * @vsi: the controlling VSI
10029 **/
10030static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
10031{
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010032 struct i40e_pf *pf = veb->pf;
Shannon Nelson66fc3602016-01-13 16:51:42 -080010033 bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010034 int ret;
10035
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010036 ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
Mitch Williams5bc16032016-05-16 10:26:43 -070010037 veb->enabled_tc, false,
Shannon Nelson66fc3602016-01-13 16:51:42 -080010038 &veb->seid, enable_stats, NULL);
Mitch Williams5bc16032016-05-16 10:26:43 -070010039
10040 /* get a VEB from the hardware */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010041 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010042 dev_info(&pf->pdev->dev,
10043 "couldn't add VEB, err %s aq_err %s\n",
10044 i40e_stat_str(&pf->hw, ret),
10045 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010046 return -EPERM;
10047 }
10048
10049 /* get statistics counter */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010050 ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010051 &veb->stats_idx, NULL, NULL, NULL);
10052 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010053 dev_info(&pf->pdev->dev,
10054 "couldn't get VEB statistics idx, err %s aq_err %s\n",
10055 i40e_stat_str(&pf->hw, ret),
10056 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010057 return -EPERM;
10058 }
10059 ret = i40e_veb_get_bw_info(veb);
10060 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010061 dev_info(&pf->pdev->dev,
10062 "couldn't get VEB bw info, err %s aq_err %s\n",
10063 i40e_stat_str(&pf->hw, ret),
10064 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10065 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010066 return -ENOENT;
10067 }
10068
10069 vsi->uplink_seid = veb->seid;
10070 vsi->veb_idx = veb->idx;
10071 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
10072
10073 return 0;
10074}
10075
10076/**
10077 * i40e_veb_setup - Set up a VEB
10078 * @pf: board private structure
10079 * @flags: VEB setup flags
10080 * @uplink_seid: the switch element to link to
10081 * @vsi_seid: the initial VSI seid
10082 * @enabled_tc: Enabled TC bit-map
10083 *
10084 * This allocates the sw VEB structure and links it into the switch
10085 * It is possible and legal for this to be a duplicate of an already
10086 * existing VEB. It is also possible for both uplink and vsi seids
10087 * to be zero, in order to create a floating VEB.
10088 *
10089 * Returns pointer to the successfully allocated VEB sw struct on
10090 * success, otherwise returns NULL on failure.
10091 **/
10092struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
10093 u16 uplink_seid, u16 vsi_seid,
10094 u8 enabled_tc)
10095{
10096 struct i40e_veb *veb, *uplink_veb = NULL;
10097 int vsi_idx, veb_idx;
10098 int ret;
10099
10100 /* if one seid is 0, the other must be 0 to create a floating relay */
10101 if ((uplink_seid == 0 || vsi_seid == 0) &&
10102 (uplink_seid + vsi_seid != 0)) {
10103 dev_info(&pf->pdev->dev,
10104 "one, not both seid's are 0: uplink=%d vsi=%d\n",
10105 uplink_seid, vsi_seid);
10106 return NULL;
10107 }
10108
10109 /* make sure there is such a vsi and uplink */
Mitch Williams505682c2014-05-20 08:01:37 +000010110 for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010111 if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
10112 break;
Mitch Williams505682c2014-05-20 08:01:37 +000010113 if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010114 dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
10115 vsi_seid);
10116 return NULL;
10117 }
10118
10119 if (uplink_seid && uplink_seid != pf->mac_seid) {
10120 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
10121 if (pf->veb[veb_idx] &&
10122 pf->veb[veb_idx]->seid == uplink_seid) {
10123 uplink_veb = pf->veb[veb_idx];
10124 break;
10125 }
10126 }
10127 if (!uplink_veb) {
10128 dev_info(&pf->pdev->dev,
10129 "uplink seid %d not found\n", uplink_seid);
10130 return NULL;
10131 }
10132 }
10133
10134 /* get veb sw struct */
10135 veb_idx = i40e_veb_mem_alloc(pf);
10136 if (veb_idx < 0)
10137 goto err_alloc;
10138 veb = pf->veb[veb_idx];
10139 veb->flags = flags;
10140 veb->uplink_seid = uplink_seid;
10141 veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
10142 veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
10143
10144 /* create the VEB in the switch */
10145 ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
10146 if (ret)
10147 goto err_veb;
Shannon Nelson1bb8b932014-04-23 04:49:54 +000010148 if (vsi_idx == pf->lan_vsi)
10149 pf->lan_veb = veb->idx;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010150
10151 return veb;
10152
10153err_veb:
10154 i40e_veb_clear(veb);
10155err_alloc:
10156 return NULL;
10157}
10158
10159/**
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000010160 * i40e_setup_pf_switch_element - set PF vars based on switch type
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010161 * @pf: board private structure
10162 * @ele: element we are building info from
10163 * @num_reported: total number of elements
10164 * @printconfig: should we print the contents
10165 *
10166 * helper function to assist in extracting a few useful SEID values.
10167 **/
10168static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
10169 struct i40e_aqc_switch_config_element_resp *ele,
10170 u16 num_reported, bool printconfig)
10171{
10172 u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
10173 u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
10174 u8 element_type = ele->element_type;
10175 u16 seid = le16_to_cpu(ele->seid);
10176
10177 if (printconfig)
10178 dev_info(&pf->pdev->dev,
10179 "type=%d seid=%d uplink=%d downlink=%d\n",
10180 element_type, seid, uplink_seid, downlink_seid);
10181
10182 switch (element_type) {
10183 case I40E_SWITCH_ELEMENT_TYPE_MAC:
10184 pf->mac_seid = seid;
10185 break;
10186 case I40E_SWITCH_ELEMENT_TYPE_VEB:
10187 /* Main VEB? */
10188 if (uplink_seid != pf->mac_seid)
10189 break;
10190 if (pf->lan_veb == I40E_NO_VEB) {
10191 int v;
10192
10193 /* find existing or else empty VEB */
10194 for (v = 0; v < I40E_MAX_VEB; v++) {
10195 if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
10196 pf->lan_veb = v;
10197 break;
10198 }
10199 }
10200 if (pf->lan_veb == I40E_NO_VEB) {
10201 v = i40e_veb_mem_alloc(pf);
10202 if (v < 0)
10203 break;
10204 pf->lan_veb = v;
10205 }
10206 }
10207
10208 pf->veb[pf->lan_veb]->seid = seid;
10209 pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
10210 pf->veb[pf->lan_veb]->pf = pf;
10211 pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
10212 break;
10213 case I40E_SWITCH_ELEMENT_TYPE_VSI:
10214 if (num_reported != 1)
10215 break;
10216 /* This is immediately after a reset so we can assume this is
10217 * the PF's VSI
10218 */
10219 pf->mac_seid = uplink_seid;
10220 pf->pf_seid = downlink_seid;
10221 pf->main_vsi_seid = seid;
10222 if (printconfig)
10223 dev_info(&pf->pdev->dev,
10224 "pf_seid=%d main_vsi_seid=%d\n",
10225 pf->pf_seid, pf->main_vsi_seid);
10226 break;
10227 case I40E_SWITCH_ELEMENT_TYPE_PF:
10228 case I40E_SWITCH_ELEMENT_TYPE_VF:
10229 case I40E_SWITCH_ELEMENT_TYPE_EMP:
10230 case I40E_SWITCH_ELEMENT_TYPE_BMC:
10231 case I40E_SWITCH_ELEMENT_TYPE_PE:
10232 case I40E_SWITCH_ELEMENT_TYPE_PA:
10233 /* ignore these for now */
10234 break;
10235 default:
10236 dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
10237 element_type, seid);
10238 break;
10239 }
10240}
10241
10242/**
10243 * i40e_fetch_switch_configuration - Get switch config from firmware
10244 * @pf: board private structure
10245 * @printconfig: should we print the contents
10246 *
10247 * Get the current switch configuration from the device and
10248 * extract a few useful SEID values.
10249 **/
10250int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
10251{
10252 struct i40e_aqc_get_switch_config_resp *sw_config;
10253 u16 next_seid = 0;
10254 int ret = 0;
10255 u8 *aq_buf;
10256 int i;
10257
10258 aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
10259 if (!aq_buf)
10260 return -ENOMEM;
10261
10262 sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
10263 do {
10264 u16 num_reported, num_total;
10265
10266 ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
10267 I40E_AQ_LARGE_BUF,
10268 &next_seid, NULL);
10269 if (ret) {
10270 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010271 "get switch config failed err %s aq_err %s\n",
10272 i40e_stat_str(&pf->hw, ret),
10273 i40e_aq_str(&pf->hw,
10274 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010275 kfree(aq_buf);
10276 return -ENOENT;
10277 }
10278
10279 num_reported = le16_to_cpu(sw_config->header.num_reported);
10280 num_total = le16_to_cpu(sw_config->header.num_total);
10281
10282 if (printconfig)
10283 dev_info(&pf->pdev->dev,
10284 "header: %d reported %d total\n",
10285 num_reported, num_total);
10286
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010287 for (i = 0; i < num_reported; i++) {
10288 struct i40e_aqc_switch_config_element_resp *ele =
10289 &sw_config->element[i];
10290
10291 i40e_setup_pf_switch_element(pf, ele, num_reported,
10292 printconfig);
10293 }
10294 } while (next_seid != 0);
10295
10296 kfree(aq_buf);
10297 return ret;
10298}
10299
10300/**
10301 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
10302 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010303 * @reinit: if the Main VSI needs to re-initialized.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010304 *
10305 * Returns 0 on success, negative value on failure
10306 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010307static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010308{
Anjali Singhai Jainb5569892016-05-03 15:13:12 -070010309 u16 flags = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010310 int ret;
10311
10312 /* find out what's out there already */
10313 ret = i40e_fetch_switch_configuration(pf, false);
10314 if (ret) {
10315 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010316 "couldn't fetch switch config, err %s aq_err %s\n",
10317 i40e_stat_str(&pf->hw, ret),
10318 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010319 return ret;
10320 }
10321 i40e_pf_reset_stats(pf);
10322
Anjali Singhai Jainb5569892016-05-03 15:13:12 -070010323 /* set the switch config bit for the whole device to
10324 * support limited promisc or true promisc
10325 * when user requests promisc. The default is limited
10326 * promisc.
10327 */
10328
10329 if ((pf->hw.pf_id == 0) &&
10330 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
10331 flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
10332
10333 if (pf->hw.pf_id == 0) {
10334 u16 valid_flags;
10335
10336 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
10337 ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags,
10338 NULL);
10339 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
10340 dev_info(&pf->pdev->dev,
10341 "couldn't set switch config bits, err %s aq_err %s\n",
10342 i40e_stat_str(&pf->hw, ret),
10343 i40e_aq_str(&pf->hw,
10344 pf->hw.aq.asq_last_status));
10345 /* not a fatal problem, just keep going */
10346 }
10347 }
10348
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010349 /* first time setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010350 if (pf->lan_vsi == I40E_NO_VSI || reinit) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010351 struct i40e_vsi *vsi = NULL;
10352 u16 uplink_seid;
10353
10354 /* Set up the PF VSI associated with the PF's main VSI
10355 * that is already in the HW switch
10356 */
10357 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
10358 uplink_seid = pf->veb[pf->lan_veb]->seid;
10359 else
10360 uplink_seid = pf->mac_seid;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010361 if (pf->lan_vsi == I40E_NO_VSI)
10362 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
10363 else if (reinit)
10364 vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010365 if (!vsi) {
10366 dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
10367 i40e_fdir_teardown(pf);
10368 return -EAGAIN;
10369 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010370 } else {
10371 /* force a reset of TC and queue layout configurations */
10372 u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -040010373
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010374 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
10375 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
10376 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
10377 }
10378 i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
10379
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010380 i40e_fdir_sb_setup(pf);
10381
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010382 /* Setup static PF queue filter control settings */
10383 ret = i40e_setup_pf_filter_control(pf);
10384 if (ret) {
10385 dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
10386 ret);
10387 /* Failure here should not stop continuing other steps */
10388 }
10389
10390 /* enable RSS in the HW, even for only one queue, as the stack can use
10391 * the hash
10392 */
10393 if ((pf->flags & I40E_FLAG_RSS_ENABLED))
Helin Zhang043dd652015-10-21 19:56:23 -040010394 i40e_pf_config_rss(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010395
10396 /* fill in link information and enable LSE reporting */
Catherine Sullivan0a862b42015-08-31 19:54:53 -040010397 i40e_update_link_info(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010398 i40e_link_event(pf);
10399
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000010400 /* Initialize user-specific link properties */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010401 pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
10402 I40E_AQ_AN_COMPLETED) ? true : false);
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000010403
Jacob Kellerbeb0dff2014-01-11 05:43:19 +000010404 i40e_ptp_init(pf);
10405
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010406 return ret;
10407}
10408
10409/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010410 * i40e_determine_queue_usage - Work out queue distribution
10411 * @pf: board private structure
10412 **/
10413static void i40e_determine_queue_usage(struct i40e_pf *pf)
10414{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010415 int queues_left;
10416
10417 pf->num_lan_qps = 0;
Vasu Dev38e00432014-08-01 13:27:03 -070010418#ifdef I40E_FCOE
10419 pf->num_fcoe_qps = 0;
10420#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010421
10422 /* Find the max queues to be put into basic use. We'll always be
10423 * using TC0, whether or not DCB is running, and TC0 will get the
10424 * big RSS set.
10425 */
10426 queues_left = pf->hw.func_caps.num_tx_qp;
10427
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010428 if ((queues_left == 1) ||
Frank Zhang9aa7e932014-05-20 08:01:42 +000010429 !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010430 /* one qp for PF, no queues for anything else */
10431 queues_left = 0;
Helin Zhangacd65442015-10-26 19:44:28 -040010432 pf->alloc_rss_size = pf->num_lan_qps = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010433
10434 /* make sure all the fancies are disabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010435 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060010436 I40E_FLAG_IWARP_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -070010437#ifdef I40E_FCOE
10438 I40E_FLAG_FCOE_ENABLED |
10439#endif
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010440 I40E_FLAG_FD_SB_ENABLED |
10441 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010442 I40E_FLAG_DCB_CAPABLE |
Dave Ertmana0362442016-08-29 17:38:26 -070010443 I40E_FLAG_DCB_ENABLED |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010444 I40E_FLAG_SRIOV_ENABLED |
10445 I40E_FLAG_VMDQ_ENABLED);
Frank Zhang9aa7e932014-05-20 08:01:42 +000010446 } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
10447 I40E_FLAG_FD_SB_ENABLED |
Anjali Singhai Jainbbe7d0e2014-05-20 08:01:44 +000010448 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010449 I40E_FLAG_DCB_CAPABLE))) {
Frank Zhang9aa7e932014-05-20 08:01:42 +000010450 /* one qp for PF */
Helin Zhangacd65442015-10-26 19:44:28 -040010451 pf->alloc_rss_size = pf->num_lan_qps = 1;
Frank Zhang9aa7e932014-05-20 08:01:42 +000010452 queues_left -= pf->num_lan_qps;
10453
10454 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060010455 I40E_FLAG_IWARP_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -070010456#ifdef I40E_FCOE
10457 I40E_FLAG_FCOE_ENABLED |
10458#endif
Frank Zhang9aa7e932014-05-20 08:01:42 +000010459 I40E_FLAG_FD_SB_ENABLED |
10460 I40E_FLAG_FD_ATR_ENABLED |
10461 I40E_FLAG_DCB_ENABLED |
10462 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010463 } else {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010464 /* Not enough queues for all TCs */
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010465 if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010466 (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
Dave Ertmana0362442016-08-29 17:38:26 -070010467 pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
10468 I40E_FLAG_DCB_ENABLED);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010469 dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
10470 }
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +000010471 pf->num_lan_qps = max_t(int, pf->rss_size_max,
10472 num_online_cpus());
10473 pf->num_lan_qps = min_t(int, pf->num_lan_qps,
10474 pf->hw.func_caps.num_tx_qp);
10475
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010476 queues_left -= pf->num_lan_qps;
10477 }
10478
Vasu Dev38e00432014-08-01 13:27:03 -070010479#ifdef I40E_FCOE
10480 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
10481 if (I40E_DEFAULT_FCOE <= queues_left) {
10482 pf->num_fcoe_qps = I40E_DEFAULT_FCOE;
10483 } else if (I40E_MINIMUM_FCOE <= queues_left) {
10484 pf->num_fcoe_qps = I40E_MINIMUM_FCOE;
10485 } else {
10486 pf->num_fcoe_qps = 0;
10487 pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
10488 dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n");
10489 }
10490
10491 queues_left -= pf->num_fcoe_qps;
10492 }
10493
10494#endif
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010495 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
10496 if (queues_left > 1) {
10497 queues_left -= 1; /* save 1 queue for FD */
10498 } else {
10499 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
10500 dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
10501 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010502 }
10503
10504 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
10505 pf->num_vf_qps && pf->num_req_vfs && queues_left) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010506 pf->num_req_vfs = min_t(int, pf->num_req_vfs,
10507 (queues_left / pf->num_vf_qps));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010508 queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
10509 }
10510
10511 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
10512 pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
10513 pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
10514 (queues_left / pf->num_vmdq_qps));
10515 queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
10516 }
10517
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +000010518 pf->queues_left = queues_left;
Neerav Parikh8279e492015-09-03 17:18:50 -040010519 dev_dbg(&pf->pdev->dev,
10520 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
10521 pf->hw.func_caps.num_tx_qp,
10522 !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
Helin Zhangacd65442015-10-26 19:44:28 -040010523 pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
10524 pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
10525 queues_left);
Vasu Dev38e00432014-08-01 13:27:03 -070010526#ifdef I40E_FCOE
Neerav Parikh8279e492015-09-03 17:18:50 -040010527 dev_dbg(&pf->pdev->dev, "fcoe queues = %d\n", pf->num_fcoe_qps);
Vasu Dev38e00432014-08-01 13:27:03 -070010528#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010529}
10530
10531/**
10532 * i40e_setup_pf_filter_control - Setup PF static filter control
10533 * @pf: PF to be setup
10534 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000010535 * i40e_setup_pf_filter_control sets up a PF's initial filter control
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010536 * settings. If PE/FCoE are enabled then it will also set the per PF
10537 * based filter sizes required for them. It also enables Flow director,
10538 * ethertype and macvlan type filter settings for the pf.
10539 *
10540 * Returns 0 on success, negative on failure
10541 **/
10542static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
10543{
10544 struct i40e_filter_control_settings *settings = &pf->filter_settings;
10545
10546 settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
10547
10548 /* Flow Director is enabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010549 if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010550 settings->enable_fdir = true;
10551
10552 /* Ethtype and MACVLAN filters enabled for PF */
10553 settings->enable_ethtype = true;
10554 settings->enable_macvlan = true;
10555
10556 if (i40e_set_filter_control(&pf->hw, settings))
10557 return -ENOENT;
10558
10559 return 0;
10560}
10561
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010562#define INFO_STRING_LEN 255
Shannon Nelson7fd89542015-10-21 19:47:04 -040010563#define REMAIN(__x) (INFO_STRING_LEN - (__x))
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010564static void i40e_print_features(struct i40e_pf *pf)
10565{
10566 struct i40e_hw *hw = &pf->hw;
Joe Perches3b195842015-12-03 04:20:57 -080010567 char *buf;
10568 int i;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010569
Joe Perches3b195842015-12-03 04:20:57 -080010570 buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
10571 if (!buf)
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010572 return;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010573
Joe Perches3b195842015-12-03 04:20:57 -080010574 i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010575#ifdef CONFIG_PCI_IOV
Joe Perches3b195842015-12-03 04:20:57 -080010576 i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010577#endif
Jesse Brandeburg1a557afc2016-04-20 19:43:37 -070010578 i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
Shannon Nelson7fd89542015-10-21 19:47:04 -040010579 pf->hw.func_caps.num_vsis,
Jesse Brandeburg1a557afc2016-04-20 19:43:37 -070010580 pf->vsi[pf->lan_vsi]->num_queue_pairs);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010581 if (pf->flags & I40E_FLAG_RSS_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010582 i += snprintf(&buf[i], REMAIN(i), " RSS");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010583 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010584 i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +000010585 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
Joe Perches3b195842015-12-03 04:20:57 -080010586 i += snprintf(&buf[i], REMAIN(i), " FD_SB");
10587 i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +000010588 }
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010589 if (pf->flags & I40E_FLAG_DCB_CAPABLE)
Joe Perches3b195842015-12-03 04:20:57 -080010590 i += snprintf(&buf[i], REMAIN(i), " DCB");
Joe Perches3b195842015-12-03 04:20:57 -080010591 i += snprintf(&buf[i], REMAIN(i), " VxLAN");
Singhai, Anjali6a899022015-12-14 12:21:18 -080010592 i += snprintf(&buf[i], REMAIN(i), " Geneve");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010593 if (pf->flags & I40E_FLAG_PTP)
Joe Perches3b195842015-12-03 04:20:57 -080010594 i += snprintf(&buf[i], REMAIN(i), " PTP");
Vasu Dev38e00432014-08-01 13:27:03 -070010595#ifdef I40E_FCOE
10596 if (pf->flags & I40E_FLAG_FCOE_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010597 i += snprintf(&buf[i], REMAIN(i), " FCOE");
Vasu Dev38e00432014-08-01 13:27:03 -070010598#endif
Shannon Nelson6dec1012015-09-28 14:12:30 -040010599 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010600 i += snprintf(&buf[i], REMAIN(i), " VEB");
Shannon Nelson6dec1012015-09-28 14:12:30 -040010601 else
Joe Perches3b195842015-12-03 04:20:57 -080010602 i += snprintf(&buf[i], REMAIN(i), " VEPA");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010603
Joe Perches3b195842015-12-03 04:20:57 -080010604 dev_info(&pf->pdev->dev, "%s\n", buf);
10605 kfree(buf);
Shannon Nelson7fd89542015-10-21 19:47:04 -040010606 WARN_ON(i > INFO_STRING_LEN);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010607}
10608
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010609/**
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010610 * i40e_get_platform_mac_addr - get platform-specific MAC address
10611 *
10612 * @pdev: PCI device information struct
10613 * @pf: board private structure
10614 *
10615 * Look up the MAC address in Open Firmware on systems that support it,
10616 * and use IDPROM on SPARC if no OF address is found. On return, the
10617 * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value
10618 * has been selected.
10619 **/
10620static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
10621{
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010622 pf->flags &= ~I40E_FLAG_PF_MAC;
Sowmini Varadhanba942722016-01-12 19:32:31 -080010623 if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010624 pf->flags |= I40E_FLAG_PF_MAC;
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010625}
10626
10627/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010628 * i40e_probe - Device initialization routine
10629 * @pdev: PCI device information struct
10630 * @ent: entry in i40e_pci_tbl
10631 *
Jeff Kirsherb40c82e62015-02-27 09:18:34 +000010632 * i40e_probe initializes a PF identified by a pci_dev structure.
10633 * The OS initialization, configuring of the PF private structure,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010634 * and a hardware reset occur.
10635 *
10636 * Returns 0 on success, negative on failure
10637 **/
10638static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
10639{
Catherine Sullivane8278452015-02-06 08:52:08 +000010640 struct i40e_aq_get_phy_abilities_resp abilities;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010641 struct i40e_pf *pf;
10642 struct i40e_hw *hw;
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000010643 static u16 pfs_found;
Shannon Nelson1d5109d2015-08-26 15:14:08 -040010644 u16 wol_nvm_bits;
Catherine Sullivand4dfb812013-11-28 06:39:21 +000010645 u16 link_status;
Jean Sacren6f66a482015-09-19 05:08:45 -060010646 int err;
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -040010647 u32 val;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000010648 u32 i;
Helin Zhang58fc3262015-10-01 14:37:38 -040010649 u8 set_fc_aq_fail;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010650
10651 err = pci_enable_device_mem(pdev);
10652 if (err)
10653 return err;
10654
10655 /* set up for high or low dma */
Mitch Williams64942942014-02-11 08:26:33 +000010656 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +000010657 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +000010658 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
10659 if (err) {
10660 dev_err(&pdev->dev,
10661 "DMA configuration failed: 0x%x\n", err);
10662 goto err_dma;
10663 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010664 }
10665
10666 /* set up pci connections */
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010667 err = pci_request_mem_regions(pdev, i40e_driver_name);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010668 if (err) {
10669 dev_info(&pdev->dev,
10670 "pci_request_selected_regions failed %d\n", err);
10671 goto err_pci_reg;
10672 }
10673
10674 pci_enable_pcie_error_reporting(pdev);
10675 pci_set_master(pdev);
10676
10677 /* Now that we have a PCI connection, we need to do the
10678 * low level device setup. This is primarily setting up
10679 * the Admin Queue structures and then querying for the
10680 * device's current profile information.
10681 */
10682 pf = kzalloc(sizeof(*pf), GFP_KERNEL);
10683 if (!pf) {
10684 err = -ENOMEM;
10685 goto err_pf_alloc;
10686 }
10687 pf->next_vsi = 0;
10688 pf->pdev = pdev;
10689 set_bit(__I40E_DOWN, &pf->state);
10690
10691 hw = &pf->hw;
10692 hw->back = pf;
Anjali Singhai232f4702015-02-26 16:15:39 +000010693
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010694 pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
10695 I40E_MAX_CSR_SPACE);
Anjali Singhai232f4702015-02-26 16:15:39 +000010696
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010697 hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010698 if (!hw->hw_addr) {
10699 err = -EIO;
10700 dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
10701 (unsigned int)pci_resource_start(pdev, 0),
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010702 pf->ioremap_len, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010703 goto err_ioremap;
10704 }
10705 hw->vendor_id = pdev->vendor;
10706 hw->device_id = pdev->device;
10707 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
10708 hw->subsystem_vendor_id = pdev->subsystem_vendor;
10709 hw->subsystem_device_id = pdev->subsystem_device;
10710 hw->bus.device = PCI_SLOT(pdev->devfn);
10711 hw->bus.func = PCI_FUNC(pdev->devfn);
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000010712 pf->instance = pfs_found;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010713
Shannon Nelsonde03d2b2016-03-10 14:59:44 -080010714 /* set up the locks for the AQ, do this only once in probe
10715 * and destroy them only once in remove
10716 */
10717 mutex_init(&hw->aq.asq_mutex);
10718 mutex_init(&hw->aq.arq_mutex);
10719
Alexander Duyck5d4ca232016-09-30 08:21:46 -040010720 pf->msg_enable = netif_msg_init(debug,
10721 NETIF_MSG_DRV |
10722 NETIF_MSG_PROBE |
10723 NETIF_MSG_LINK);
10724 if (debug < -1)
10725 pf->hw.debug_mask = debug;
Shannon Nelson5b5faa42014-10-17 03:14:51 +000010726
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +000010727 /* do a special CORER for clearing PXE mode once at init */
10728 if (hw->revision_id == 0 &&
10729 (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
10730 wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
10731 i40e_flush(hw);
10732 msleep(200);
10733 pf->corer_count++;
10734
10735 i40e_clear_pxe_mode(hw);
10736 }
10737
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010738 /* Reset here to make sure all is clean and to define PF 'n' */
Shannon Nelson838d41d2014-06-04 20:41:27 +000010739 i40e_clear_hw(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010740 err = i40e_pf_reset(hw);
10741 if (err) {
10742 dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
10743 goto err_pf_reset;
10744 }
10745 pf->pfr_count++;
10746
10747 hw->aq.num_arq_entries = I40E_AQ_LEN;
10748 hw->aq.num_asq_entries = I40E_AQ_LEN;
10749 hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
10750 hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
10751 pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +000010752
Carolyn Wybornyb294ac72014-12-11 07:06:39 +000010753 snprintf(pf->int_name, sizeof(pf->int_name) - 1,
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +000010754 "%s-%s:misc",
10755 dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010756
10757 err = i40e_init_shared_code(hw);
10758 if (err) {
Anjali Singhai Jainb2a75c52015-04-27 14:57:20 -040010759 dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
10760 err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010761 goto err_pf_reset;
10762 }
10763
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000010764 /* set up a default setting for link flow control */
10765 pf->hw.fc.requested_mode = I40E_FC_NONE;
10766
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010767 err = i40e_init_adminq(hw);
Carolyn Wyborny2b2426a762015-10-26 19:44:35 -040010768 if (err) {
10769 if (err == I40E_ERR_FIRMWARE_API_VERSION)
10770 dev_info(&pdev->dev,
10771 "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");
10772 else
10773 dev_info(&pdev->dev,
10774 "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
10775
10776 goto err_pf_reset;
10777 }
Carolyn Wybornyf0b44442015-08-31 19:54:49 -040010778
Shannon Nelson6dec1012015-09-28 14:12:30 -040010779 /* provide nvm, fw, api versions */
10780 dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
10781 hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
10782 hw->aq.api_maj_ver, hw->aq.api_min_ver,
10783 i40e_nvm_version_str(hw));
Carolyn Wybornyf0b44442015-08-31 19:54:49 -040010784
Catherine Sullivan7aa67612014-07-09 07:46:17 +000010785 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
10786 hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
Shannon Nelson278b6f62014-06-04 01:41:03 +000010787 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000010788 "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");
10789 else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
10790 hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
Shannon Nelson278b6f62014-06-04 01:41:03 +000010791 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000010792 "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 +000010793
Shannon Nelson4eb3f762014-03-06 08:59:58 +000010794 i40e_verify_eeprom(pf);
10795
Jesse Brandeburg2c5fe332014-04-23 04:49:57 +000010796 /* Rev 0 hardware was never productized */
10797 if (hw->revision_id < 1)
10798 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");
10799
Shannon Nelson6ff4ef82013-12-21 05:44:49 +000010800 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010801 err = i40e_get_capabilities(pf);
10802 if (err)
10803 goto err_adminq_setup;
10804
10805 err = i40e_sw_init(pf);
10806 if (err) {
10807 dev_info(&pdev->dev, "sw_init failed: %d\n", err);
10808 goto err_sw_init;
10809 }
10810
10811 err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
10812 hw->func_caps.num_rx_qp,
10813 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
10814 if (err) {
10815 dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
10816 goto err_init_lan_hmc;
10817 }
10818
10819 err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
10820 if (err) {
10821 dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
10822 err = -ENOENT;
10823 goto err_configure_lan_hmc;
10824 }
10825
Neerav Parikhb686ece2014-12-14 01:55:11 +000010826 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
10827 * Ignore error return codes because if it was already disabled via
10828 * hardware settings this will fail
10829 */
Neerav Parikhf1bbad32016-01-13 16:51:39 -080010830 if (pf->flags & I40E_FLAG_STOP_FW_LLDP) {
Neerav Parikhb686ece2014-12-14 01:55:11 +000010831 dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
10832 i40e_aq_stop_lldp(hw, true, NULL);
10833 }
10834
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010835 i40e_get_mac_addr(hw, hw->mac.addr);
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010836 /* allow a platform config to override the HW addr */
10837 i40e_get_platform_mac_addr(pdev, pf);
Jesse Brandeburgf62b5062013-11-28 06:39:27 +000010838 if (!is_valid_ether_addr(hw->mac.addr)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010839 dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
10840 err = -EIO;
10841 goto err_mac_addr;
10842 }
10843 dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
Greg Rose9a173902014-05-22 06:32:02 +000010844 ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
Neerav Parikh1f224ad2014-02-12 01:45:31 +000010845 i40e_get_port_mac_addr(hw, hw->mac.port_addr);
10846 if (is_valid_ether_addr(hw->mac.port_addr))
10847 pf->flags |= I40E_FLAG_PORT_ID_VALID;
Vasu Dev38e00432014-08-01 13:27:03 -070010848#ifdef I40E_FCOE
10849 err = i40e_get_san_mac_addr(hw, hw->mac.san_addr);
10850 if (err)
10851 dev_info(&pdev->dev,
10852 "(non-fatal) SAN MAC retrieval failed: %d\n", err);
10853 if (!is_valid_ether_addr(hw->mac.san_addr)) {
10854 dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
10855 hw->mac.san_addr);
10856 ether_addr_copy(hw->mac.san_addr, hw->mac.addr);
10857 }
10858 dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr);
10859#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010860
10861 pci_set_drvdata(pdev, pf);
10862 pci_save_state(pdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080010863#ifdef CONFIG_I40E_DCB
10864 err = i40e_init_pf_dcb(pf);
10865 if (err) {
Shannon Nelsonaebfc812014-12-11 07:06:38 +000010866 dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
David Ertmanc17ef432016-09-30 01:36:21 -070010867 pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED);
Neerav Parikh014269f2014-04-01 07:11:48 +000010868 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080010869 }
10870#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010871
10872 /* set up periodic task facility */
10873 setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
10874 pf->service_timer_period = HZ;
10875
10876 INIT_WORK(&pf->service_task, i40e_service_task);
10877 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
10878 pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010879
Shannon Nelson1d5109d2015-08-26 15:14:08 -040010880 /* NVM bit on means WoL disabled for the port */
10881 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -080010882 if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
Shannon Nelson1d5109d2015-08-26 15:14:08 -040010883 pf->wol_en = false;
10884 else
10885 pf->wol_en = true;
Shannon Nelson8e2773a2013-11-28 06:39:22 +000010886 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
10887
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010888 /* set up the main switch operations */
10889 i40e_determine_queue_usage(pf);
Jesse Brandeburgc11472802015-04-07 19:45:39 -040010890 err = i40e_init_interrupt_scheme(pf);
10891 if (err)
10892 goto err_switch_setup;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010893
Mitch Williams505682c2014-05-20 08:01:37 +000010894 /* The number of VSIs reported by the FW is the minimum guaranteed
10895 * to us; HW supports far more and we share the remaining pool with
10896 * the other PFs. We allocate space for more than the guarantee with
10897 * the understanding that we might not get them all later.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010898 */
Mitch Williams505682c2014-05-20 08:01:37 +000010899 if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
10900 pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
10901 else
10902 pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
10903
10904 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
Jesse Brandeburgd17038d2015-12-23 12:05:55 -080010905 pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
10906 GFP_KERNEL);
Wei Yongjuned87ac02013-09-24 05:17:25 +000010907 if (!pf->vsi) {
10908 err = -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010909 goto err_switch_setup;
Wei Yongjuned87ac02013-09-24 05:17:25 +000010910 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010911
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -040010912#ifdef CONFIG_PCI_IOV
10913 /* prep for VF support */
10914 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
10915 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
10916 !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
10917 if (pci_num_vf(pdev))
10918 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
10919 }
10920#endif
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010921 err = i40e_setup_pf_switch(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010922 if (err) {
10923 dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
10924 goto err_vsis;
10925 }
Helin Zhang58fc3262015-10-01 14:37:38 -040010926
10927 /* Make sure flow control is set according to current settings */
10928 err = i40e_set_fc(hw, &set_fc_aq_fail, true);
10929 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
10930 dev_dbg(&pf->pdev->dev,
10931 "Set fc with err %s aq_err %s on get_phy_cap\n",
10932 i40e_stat_str(hw, err),
10933 i40e_aq_str(hw, hw->aq.asq_last_status));
10934 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
10935 dev_dbg(&pf->pdev->dev,
10936 "Set fc with err %s aq_err %s on set_phy_config\n",
10937 i40e_stat_str(hw, err),
10938 i40e_aq_str(hw, hw->aq.asq_last_status));
10939 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
10940 dev_dbg(&pf->pdev->dev,
10941 "Set fc with err %s aq_err %s on get_link_info\n",
10942 i40e_stat_str(hw, err),
10943 i40e_aq_str(hw, hw->aq.asq_last_status));
10944
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000010945 /* if FDIR VSI was set up, start it now */
Mitch Williams505682c2014-05-20 08:01:37 +000010946 for (i = 0; i < pf->num_alloc_vsi; i++) {
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000010947 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
10948 i40e_vsi_open(pf->vsi[i]);
10949 break;
10950 }
10951 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010952
Shannon Nelson2f0aff42016-01-04 10:33:08 -080010953 /* The driver only wants link up/down and module qualification
10954 * reports from firmware. Note the negative logic.
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000010955 */
10956 err = i40e_aq_set_phy_int_mask(&pf->hw,
Shannon Nelson2f0aff42016-01-04 10:33:08 -080010957 ~(I40E_AQ_EVENT_LINK_UPDOWN |
Shannon Nelson867a79e2016-03-18 12:18:15 -070010958 I40E_AQ_EVENT_MEDIA_NA |
Shannon Nelson2f0aff42016-01-04 10:33:08 -080010959 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000010960 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010961 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
10962 i40e_stat_str(&pf->hw, err),
10963 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000010964
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -040010965 /* Reconfigure hardware for allowing smaller MSS in the case
10966 * of TSO, so that we avoid the MDD being fired and causing
10967 * a reset in the case of small MSS+TSO.
10968 */
10969 val = rd32(hw, I40E_REG_MSS);
10970 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
10971 val &= ~I40E_REG_MSS_MIN_MASK;
10972 val |= I40E_64BYTE_MSS;
10973 wr32(hw, I40E_REG_MSS, val);
10974 }
10975
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -080010976 if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +000010977 msleep(75);
10978 err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
10979 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010980 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
10981 i40e_stat_str(&pf->hw, err),
10982 i40e_aq_str(&pf->hw,
10983 pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +000010984 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010985 /* The main driver is (mostly) up and happy. We need to set this state
10986 * before setting up the misc vector or we get a race and the vector
10987 * ends up disabled forever.
10988 */
10989 clear_bit(__I40E_DOWN, &pf->state);
10990
10991 /* In case of MSIX we are going to setup the misc vector right here
10992 * to handle admin queue events etc. In case of legacy and MSI
10993 * the misc functionality and queue processing is combined in
10994 * the same vector and that gets setup at open.
10995 */
10996 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
10997 err = i40e_setup_misc_vector(pf);
10998 if (err) {
10999 dev_info(&pdev->dev,
11000 "setup of misc vector failed: %d\n", err);
11001 goto err_vsis;
11002 }
11003 }
11004
Greg Rosedf805f62014-04-04 04:43:16 +000011005#ifdef CONFIG_PCI_IOV
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011006 /* prep for VF support */
11007 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
Shannon Nelson4eb3f762014-03-06 08:59:58 +000011008 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
11009 !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011010 /* disable link interrupts for VFs */
11011 val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
11012 val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
11013 wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
11014 i40e_flush(hw);
Mitch Williams4aeec012014-02-13 03:48:47 -080011015
11016 if (pci_num_vf(pdev)) {
11017 dev_info(&pdev->dev,
11018 "Active VFs found, allocating resources.\n");
11019 err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
11020 if (err)
11021 dev_info(&pdev->dev,
11022 "Error %d allocating resources for existing VFs\n",
11023 err);
11024 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011025 }
Greg Rosedf805f62014-04-04 04:43:16 +000011026#endif /* CONFIG_PCI_IOV */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011027
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011028 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11029 pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
11030 pf->num_iwarp_msix,
11031 I40E_IWARP_IRQ_PILE_ID);
11032 if (pf->iwarp_base_vector < 0) {
11033 dev_info(&pdev->dev,
11034 "failed to get tracking for %d vectors for IWARP err=%d\n",
11035 pf->num_iwarp_msix, pf->iwarp_base_vector);
11036 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
11037 }
11038 }
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000011039
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011040 i40e_dbg_pf_init(pf);
11041
11042 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +000011043 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011044
11045 /* since everything's happy, start the service_task timer */
11046 mod_timer(&pf->service_timer,
11047 round_jiffies(jiffies + pf->service_timer_period));
11048
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011049 /* add this PF to client device list and launch a client service task */
11050 err = i40e_lan_add_device(pf);
11051 if (err)
11052 dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
11053 err);
11054
Vasu Dev38e00432014-08-01 13:27:03 -070011055#ifdef I40E_FCOE
11056 /* create FCoE interface */
11057 i40e_fcoe_vsi_setup(pf);
11058
11059#endif
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011060#define PCI_SPEED_SIZE 8
11061#define PCI_WIDTH_SIZE 8
11062 /* Devices on the IOSF bus do not have this information
11063 * and will report PCI Gen 1 x 1 by default so don't bother
11064 * checking them.
11065 */
11066 if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) {
11067 char speed[PCI_SPEED_SIZE] = "Unknown";
11068 char width[PCI_WIDTH_SIZE] = "Unknown";
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011069
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011070 /* Get the negotiated link width and speed from PCI config
11071 * space
11072 */
11073 pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
11074 &link_status);
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011075
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011076 i40e_set_pci_config_data(hw, link_status);
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011077
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011078 switch (hw->bus.speed) {
11079 case i40e_bus_speed_8000:
11080 strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
11081 case i40e_bus_speed_5000:
11082 strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
11083 case i40e_bus_speed_2500:
11084 strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
11085 default:
11086 break;
11087 }
11088 switch (hw->bus.width) {
11089 case i40e_bus_width_pcie_x8:
11090 strncpy(width, "8", PCI_WIDTH_SIZE); break;
11091 case i40e_bus_width_pcie_x4:
11092 strncpy(width, "4", PCI_WIDTH_SIZE); break;
11093 case i40e_bus_width_pcie_x2:
11094 strncpy(width, "2", PCI_WIDTH_SIZE); break;
11095 case i40e_bus_width_pcie_x1:
11096 strncpy(width, "1", PCI_WIDTH_SIZE); break;
11097 default:
11098 break;
11099 }
11100
11101 dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
11102 speed, width);
11103
11104 if (hw->bus.width < i40e_bus_width_pcie_x8 ||
11105 hw->bus.speed < i40e_bus_speed_8000) {
11106 dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
11107 dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
11108 }
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011109 }
11110
Catherine Sullivane8278452015-02-06 08:52:08 +000011111 /* get the requested speeds from the fw */
11112 err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
11113 if (err)
Neerav Parikh8279e492015-09-03 17:18:50 -040011114 dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
11115 i40e_stat_str(&pf->hw, err),
11116 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Catherine Sullivane8278452015-02-06 08:52:08 +000011117 pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
11118
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -040011119 /* get the supported phy types from the fw */
11120 err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
11121 if (err)
11122 dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
11123 i40e_stat_str(&pf->hw, err),
11124 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
11125 pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type);
11126
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -040011127 /* Add a filter to drop all Flow control frames from any VSI from being
11128 * transmitted. By doing so we stop a malicious VF from sending out
11129 * PAUSE or PFC frames and potentially controlling traffic for other
11130 * PF/VF VSIs.
11131 * The FW can still send Flow control frames if enabled.
11132 */
11133 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
11134 pf->main_vsi_seid);
11135
Carolyn Wyborny31b606d2016-02-17 16:12:12 -080011136 if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
11137 (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
11138 pf->flags |= I40E_FLAG_HAVE_10GBASET_PHY;
11139
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011140 /* print a string summarizing features */
11141 i40e_print_features(pf);
11142
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011143 return 0;
11144
11145 /* Unwind what we've done if something failed in the setup */
11146err_vsis:
11147 set_bit(__I40E_DOWN, &pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011148 i40e_clear_interrupt_scheme(pf);
11149 kfree(pf->vsi);
Shannon Nelson04b03012013-11-28 06:39:34 +000011150err_switch_setup:
11151 i40e_reset_interrupt_capability(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011152 del_timer_sync(&pf->service_timer);
11153err_mac_addr:
11154err_configure_lan_hmc:
11155 (void)i40e_shutdown_lan_hmc(hw);
11156err_init_lan_hmc:
11157 kfree(pf->qp_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011158err_sw_init:
11159err_adminq_setup:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011160err_pf_reset:
11161 iounmap(hw->hw_addr);
11162err_ioremap:
11163 kfree(pf);
11164err_pf_alloc:
11165 pci_disable_pcie_error_reporting(pdev);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020011166 pci_release_mem_regions(pdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011167err_pci_reg:
11168err_dma:
11169 pci_disable_device(pdev);
11170 return err;
11171}
11172
11173/**
11174 * i40e_remove - Device removal routine
11175 * @pdev: PCI device information struct
11176 *
11177 * i40e_remove is called by the PCI subsystem to alert the driver
11178 * that is should release a PCI device. This could be caused by a
11179 * Hot-Plug event, or because the driver is going to be removed from
11180 * memory.
11181 **/
11182static void i40e_remove(struct pci_dev *pdev)
11183{
11184 struct i40e_pf *pf = pci_get_drvdata(pdev);
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011185 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011186 i40e_status ret_code;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011187 int i;
11188
11189 i40e_dbg_pf_exit(pf);
11190
Jacob Kellerbeb0dff2014-01-11 05:43:19 +000011191 i40e_ptp_stop(pf);
11192
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011193 /* Disable RSS in hw */
Shannon Nelson272cdaf22016-02-17 16:12:21 -080011194 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
11195 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011196
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011197 /* no more scheduling of any task */
Pandi Kumar Maharajana4618ec2016-02-18 09:19:25 -080011198 set_bit(__I40E_SUSPENDED, &pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011199 set_bit(__I40E_DOWN, &pf->state);
Shannon Nelsonc99abb42016-03-10 14:59:45 -080011200 if (pf->service_timer.data)
11201 del_timer_sync(&pf->service_timer);
11202 if (pf->service_task.func)
11203 cancel_work_sync(&pf->service_task);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011204
Mitch Williamseb2d80b2014-02-13 03:48:48 -080011205 if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
11206 i40e_free_vfs(pf);
11207 pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
11208 }
11209
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011210 i40e_fdir_teardown(pf);
11211
11212 /* If there is a switch structure or any orphans, remove them.
11213 * This will leave only the PF's VSI remaining.
11214 */
11215 for (i = 0; i < I40E_MAX_VEB; i++) {
11216 if (!pf->veb[i])
11217 continue;
11218
11219 if (pf->veb[i]->uplink_seid == pf->mac_seid ||
11220 pf->veb[i]->uplink_seid == 0)
11221 i40e_switch_branch_release(pf->veb[i]);
11222 }
11223
11224 /* Now we can shutdown the PF's VSI, just before we kill
11225 * adminq and hmc.
11226 */
11227 if (pf->vsi[pf->lan_vsi])
11228 i40e_vsi_release(pf->vsi[pf->lan_vsi]);
11229
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011230 /* remove attached clients */
11231 ret_code = i40e_lan_del_device(pf);
11232 if (ret_code) {
11233 dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
11234 ret_code);
11235 }
11236
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011237 /* shutdown and destroy the HMC */
Jesse Brandeburgf734dff2016-01-15 14:33:11 -080011238 if (hw->hmc.hmc_obj) {
11239 ret_code = i40e_shutdown_lan_hmc(hw);
Shannon Nelson60442de2014-04-23 04:50:13 +000011240 if (ret_code)
11241 dev_warn(&pdev->dev,
11242 "Failed to destroy the HMC resources: %d\n",
11243 ret_code);
11244 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011245
11246 /* shutdown the adminq */
Henry Tiemanac9c5c62016-09-06 18:05:11 -070011247 i40e_shutdown_adminq(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011248
Jesse Brandeburg8ddb3322015-11-18 15:47:06 -080011249 /* destroy the locks only once, here */
11250 mutex_destroy(&hw->aq.arq_mutex);
11251 mutex_destroy(&hw->aq.asq_mutex);
11252
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011253 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
11254 i40e_clear_interrupt_scheme(pf);
Mitch Williams505682c2014-05-20 08:01:37 +000011255 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011256 if (pf->vsi[i]) {
11257 i40e_vsi_clear_rings(pf->vsi[i]);
11258 i40e_vsi_clear(pf->vsi[i]);
11259 pf->vsi[i] = NULL;
11260 }
11261 }
11262
11263 for (i = 0; i < I40E_MAX_VEB; i++) {
11264 kfree(pf->veb[i]);
11265 pf->veb[i] = NULL;
11266 }
11267
11268 kfree(pf->qp_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011269 kfree(pf->vsi);
11270
Jesse Brandeburgf734dff2016-01-15 14:33:11 -080011271 iounmap(hw->hw_addr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011272 kfree(pf);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020011273 pci_release_mem_regions(pdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011274
11275 pci_disable_pcie_error_reporting(pdev);
11276 pci_disable_device(pdev);
11277}
11278
11279/**
11280 * i40e_pci_error_detected - warning that something funky happened in PCI land
11281 * @pdev: PCI device information struct
11282 *
11283 * Called to warn that something happened and the error handling steps
11284 * are in progress. Allows the driver to quiesce things, be ready for
11285 * remediation.
11286 **/
11287static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
11288 enum pci_channel_state error)
11289{
11290 struct i40e_pf *pf = pci_get_drvdata(pdev);
11291
11292 dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
11293
Guilherme G Piccoliedfc23ee2016-10-03 00:31:12 -070011294 if (!pf) {
11295 dev_info(&pdev->dev,
11296 "Cannot recover - error happened during device probe\n");
11297 return PCI_ERS_RESULT_DISCONNECT;
11298 }
11299
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011300 /* shutdown all operations */
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011301 if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
11302 rtnl_lock();
11303 i40e_prep_for_reset(pf);
11304 rtnl_unlock();
11305 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011306
11307 /* Request a slot reset */
11308 return PCI_ERS_RESULT_NEED_RESET;
11309}
11310
11311/**
11312 * i40e_pci_error_slot_reset - a PCI slot reset just happened
11313 * @pdev: PCI device information struct
11314 *
11315 * Called to find if the driver can work with the device now that
11316 * the pci slot has been reset. If a basic connection seems good
11317 * (registers are readable and have sane content) then return a
11318 * happy little PCI_ERS_RESULT_xxx.
11319 **/
11320static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
11321{
11322 struct i40e_pf *pf = pci_get_drvdata(pdev);
11323 pci_ers_result_t result;
11324 int err;
11325 u32 reg;
11326
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011327 dev_dbg(&pdev->dev, "%s\n", __func__);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011328 if (pci_enable_device_mem(pdev)) {
11329 dev_info(&pdev->dev,
11330 "Cannot re-enable PCI device after reset.\n");
11331 result = PCI_ERS_RESULT_DISCONNECT;
11332 } else {
11333 pci_set_master(pdev);
11334 pci_restore_state(pdev);
11335 pci_save_state(pdev);
11336 pci_wake_from_d3(pdev, false);
11337
11338 reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
11339 if (reg == 0)
11340 result = PCI_ERS_RESULT_RECOVERED;
11341 else
11342 result = PCI_ERS_RESULT_DISCONNECT;
11343 }
11344
11345 err = pci_cleanup_aer_uncorrect_error_status(pdev);
11346 if (err) {
11347 dev_info(&pdev->dev,
11348 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
11349 err);
11350 /* non-fatal, continue */
11351 }
11352
11353 return result;
11354}
11355
11356/**
11357 * i40e_pci_error_resume - restart operations after PCI error recovery
11358 * @pdev: PCI device information struct
11359 *
11360 * Called to allow the driver to bring things back up after PCI error
11361 * and/or reset recovery has finished.
11362 **/
11363static void i40e_pci_error_resume(struct pci_dev *pdev)
11364{
11365 struct i40e_pf *pf = pci_get_drvdata(pdev);
11366
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011367 dev_dbg(&pdev->dev, "%s\n", __func__);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011368 if (test_bit(__I40E_SUSPENDED, &pf->state))
11369 return;
11370
11371 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011372 i40e_handle_reset_warning(pf);
Vasily Averin4c4935a2015-07-08 15:04:26 +030011373 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011374}
11375
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011376/**
11377 * i40e_shutdown - PCI callback for shutting down
11378 * @pdev: PCI device information struct
11379 **/
11380static void i40e_shutdown(struct pci_dev *pdev)
11381{
11382 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011383 struct i40e_hw *hw = &pf->hw;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011384
11385 set_bit(__I40E_SUSPENDED, &pf->state);
11386 set_bit(__I40E_DOWN, &pf->state);
11387 rtnl_lock();
11388 i40e_prep_for_reset(pf);
11389 rtnl_unlock();
11390
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011391 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11392 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11393
Catherine Sullivan02b42492015-07-10 19:35:59 -040011394 del_timer_sync(&pf->service_timer);
11395 cancel_work_sync(&pf->service_task);
11396 i40e_fdir_teardown(pf);
11397
11398 rtnl_lock();
11399 i40e_prep_for_reset(pf);
11400 rtnl_unlock();
11401
11402 wr32(hw, I40E_PFPM_APM,
11403 (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11404 wr32(hw, I40E_PFPM_WUFC,
11405 (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11406
Shannon Nelsone1477582015-02-21 06:44:33 +000011407 i40e_clear_interrupt_scheme(pf);
11408
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011409 if (system_state == SYSTEM_POWER_OFF) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011410 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011411 pci_set_power_state(pdev, PCI_D3hot);
11412 }
11413}
11414
11415#ifdef CONFIG_PM
11416/**
11417 * i40e_suspend - PCI callback for moving to D3
11418 * @pdev: PCI device information struct
11419 **/
11420static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
11421{
11422 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011423 struct i40e_hw *hw = &pf->hw;
Greg Rose059ff692016-05-16 10:26:38 -070011424 int retval = 0;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011425
11426 set_bit(__I40E_SUSPENDED, &pf->state);
11427 set_bit(__I40E_DOWN, &pf->state);
Mitch Williams3932dbf2015-03-31 00:45:04 -070011428
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011429 rtnl_lock();
11430 i40e_prep_for_reset(pf);
11431 rtnl_unlock();
11432
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011433 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11434 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11435
Greg Roseb33d3b72016-05-16 10:26:37 -070011436 i40e_stop_misc_vector(pf);
11437
Greg Rose059ff692016-05-16 10:26:38 -070011438 retval = pci_save_state(pdev);
11439 if (retval)
11440 return retval;
11441
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011442 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011443 pci_set_power_state(pdev, PCI_D3hot);
11444
Greg Rose059ff692016-05-16 10:26:38 -070011445 return retval;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011446}
11447
11448/**
11449 * i40e_resume - PCI callback for waking up from D3
11450 * @pdev: PCI device information struct
11451 **/
11452static int i40e_resume(struct pci_dev *pdev)
11453{
11454 struct i40e_pf *pf = pci_get_drvdata(pdev);
11455 u32 err;
11456
11457 pci_set_power_state(pdev, PCI_D0);
11458 pci_restore_state(pdev);
11459 /* pci_restore_state() clears dev->state_saves, so
11460 * call pci_save_state() again to restore it.
11461 */
11462 pci_save_state(pdev);
11463
11464 err = pci_enable_device_mem(pdev);
11465 if (err) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011466 dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011467 return err;
11468 }
11469 pci_set_master(pdev);
11470
11471 /* no wakeup events while running */
11472 pci_wake_from_d3(pdev, false);
11473
11474 /* handling the reset will rebuild the device state */
11475 if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
11476 clear_bit(__I40E_DOWN, &pf->state);
11477 rtnl_lock();
11478 i40e_reset_and_rebuild(pf, false);
11479 rtnl_unlock();
11480 }
11481
11482 return 0;
11483}
11484
11485#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011486static const struct pci_error_handlers i40e_err_handler = {
11487 .error_detected = i40e_pci_error_detected,
11488 .slot_reset = i40e_pci_error_slot_reset,
11489 .resume = i40e_pci_error_resume,
11490};
11491
11492static struct pci_driver i40e_driver = {
11493 .name = i40e_driver_name,
11494 .id_table = i40e_pci_tbl,
11495 .probe = i40e_probe,
11496 .remove = i40e_remove,
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011497#ifdef CONFIG_PM
11498 .suspend = i40e_suspend,
11499 .resume = i40e_resume,
11500#endif
11501 .shutdown = i40e_shutdown,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011502 .err_handler = &i40e_err_handler,
11503 .sriov_configure = i40e_pci_sriov_configure,
11504};
11505
11506/**
11507 * i40e_init_module - Driver registration routine
11508 *
11509 * i40e_init_module is the first routine called when the driver is
11510 * loaded. All it does is register with the PCI subsystem.
11511 **/
11512static int __init i40e_init_module(void)
11513{
11514 pr_info("%s: %s - version %s\n", i40e_driver_name,
11515 i40e_driver_string, i40e_driver_version_str);
11516 pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
Greg Rose96664482015-02-06 08:52:13 +000011517
Jesse Brandeburg2803b162015-12-22 14:25:08 -080011518 /* we will see if single thread per module is enough for now,
11519 * it can't be any worse than using the system workqueue which
11520 * was already single threaded
11521 */
Jacob Keller6992a6c2016-08-04 11:37:01 -070011522 i40e_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1,
11523 i40e_driver_name);
Jesse Brandeburg2803b162015-12-22 14:25:08 -080011524 if (!i40e_wq) {
11525 pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
11526 return -ENOMEM;
11527 }
11528
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011529 i40e_dbg_init();
11530 return pci_register_driver(&i40e_driver);
11531}
11532module_init(i40e_init_module);
11533
11534/**
11535 * i40e_exit_module - Driver exit cleanup routine
11536 *
11537 * i40e_exit_module is called just before the driver is removed
11538 * from memory.
11539 **/
11540static void __exit i40e_exit_module(void)
11541{
11542 pci_unregister_driver(&i40e_driver);
Jesse Brandeburg2803b162015-12-22 14:25:08 -080011543 destroy_workqueue(i40e_wq);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011544 i40e_dbg_exit();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011545}
11546module_exit(i40e_exit_module);