blob: aecf63b3b8ff84254a515089ec9a1409bd5acf16 [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 Pujari36023862016-11-08 13:05:19 -080044#define DRV_VERSION_BUILD 25
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 Kirsherb40c82e2015-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 Kirsherb40c82e2015-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;
Jacob Keller278e7d02016-10-05 09:30:37 -07001155 u64 key;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001156
1157 if (!vsi || !macaddr)
1158 return NULL;
1159
Jacob Keller278e7d02016-10-05 09:30:37 -07001160 key = i40e_addr_to_hkey(macaddr);
1161 hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001162 if ((ether_addr_equal(macaddr, f->macaddr)) &&
Jacob Keller1bc87e82016-10-05 09:30:31 -07001163 (vlan == f->vlan))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001164 return f;
1165 }
1166 return NULL;
1167}
1168
1169/**
1170 * i40e_find_mac - Find a mac addr in the macvlan filters list
1171 * @vsi: the VSI to be searched
1172 * @macaddr: the MAC address we are searching for
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001173 *
1174 * Returns the first filter with the provided MAC address or NULL if
1175 * MAC address was not found
1176 **/
Jacob Keller6622f5c2016-10-05 09:30:32 -07001177struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001178{
1179 struct i40e_mac_filter *f;
Jacob Keller278e7d02016-10-05 09:30:37 -07001180 u64 key;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001181
1182 if (!vsi || !macaddr)
1183 return NULL;
1184
Jacob Keller278e7d02016-10-05 09:30:37 -07001185 key = i40e_addr_to_hkey(macaddr);
1186 hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
Jacob Keller1bc87e82016-10-05 09:30:31 -07001187 if ((ether_addr_equal(macaddr, f->macaddr)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001188 return f;
1189 }
1190 return NULL;
1191}
1192
1193/**
1194 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1195 * @vsi: the VSI to be searched
1196 *
1197 * Returns true if VSI is in vlan mode or false otherwise
1198 **/
1199bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
1200{
Jacob Kellercbebb852016-10-05 09:30:40 -07001201 /* If we have a PVID, always operate in VLAN mode */
1202 if (vsi->info.pvid)
1203 return true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001204
Jacob Kellercbebb852016-10-05 09:30:40 -07001205 /* We need to operate in VLAN mode whenever we have any filters with
1206 * a VLAN other than I40E_VLAN_ALL. We could check the table each
1207 * time, incurring search cost repeatedly. However, we can notice two
1208 * things:
1209 *
1210 * 1) the only place where we can gain a VLAN filter is in
1211 * i40e_add_filter.
1212 *
1213 * 2) the only place where filters are actually removed is in
Jacob Keller0b7c8b52016-10-25 16:08:52 -07001214 * i40e_sync_filters_subtask.
Jacob Kellercbebb852016-10-05 09:30:40 -07001215 *
1216 * Thus, we can simply use a boolean value, has_vlan_filters which we
1217 * will set to true when we add a VLAN filter in i40e_add_filter. Then
1218 * we have to perform the full search after deleting filters in
Jacob Keller0b7c8b52016-10-25 16:08:52 -07001219 * i40e_sync_filters_subtask, but we already have to search
Jacob Kellercbebb852016-10-05 09:30:40 -07001220 * filters here and can perform the check at the same time. This
1221 * results in avoiding embedding a loop for VLAN mode inside another
1222 * loop over all the filters, and should maintain correctness as noted
1223 * above.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001224 */
Jacob Kellercbebb852016-10-05 09:30:40 -07001225 return vsi->has_vlan_filter;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001226}
1227
1228/**
Jacob Keller1596b5d2016-11-08 13:05:15 -08001229 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1230 * @vsi: the PF Main VSI - inappropriate for any other VSI
1231 * @macaddr: the MAC address
1232 *
1233 * Remove whatever filter the firmware set up so the driver can manage
1234 * its own filtering intelligently.
1235 **/
1236static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
1237{
1238 struct i40e_aqc_remove_macvlan_element_data element;
1239 struct i40e_pf *pf = vsi->back;
1240
1241 /* Only appropriate for the PF main VSI */
1242 if (vsi->type != I40E_VSI_MAIN)
1243 return;
1244
1245 memset(&element, 0, sizeof(element));
1246 ether_addr_copy(element.mac_addr, macaddr);
1247 element.vlan_tag = 0;
1248 /* Ignore error returns, some firmware does it this way... */
1249 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
1250 i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1251
1252 memset(&element, 0, sizeof(element));
1253 ether_addr_copy(element.mac_addr, macaddr);
1254 element.vlan_tag = 0;
1255 /* ...and some firmware does it this way. */
1256 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
1257 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
1258 i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1259}
1260
1261/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001262 * i40e_add_filter - Add a mac/vlan filter to the VSI
1263 * @vsi: the VSI to be searched
1264 * @macaddr: the MAC address
1265 * @vlan: the vlan
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001266 *
1267 * Returns ptr to the filter object or NULL when no memory available.
Kiran Patil21659032015-09-30 14:09:03 -04001268 *
Jacob Keller278e7d02016-10-05 09:30:37 -07001269 * NOTE: This function is expected to be called with mac_filter_hash_lock
Kiran Patil21659032015-09-30 14:09:03 -04001270 * being held.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001271 **/
1272struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
Jacob Keller6622f5c2016-10-05 09:30:32 -07001273 const u8 *macaddr, s16 vlan)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001274{
1275 struct i40e_mac_filter *f;
Jacob Keller278e7d02016-10-05 09:30:37 -07001276 u64 key;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001277
1278 if (!vsi || !macaddr)
1279 return NULL;
1280
Jacob Keller1bc87e82016-10-05 09:30:31 -07001281 f = i40e_find_filter(vsi, macaddr, vlan);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001282 if (!f) {
1283 f = kzalloc(sizeof(*f), GFP_ATOMIC);
1284 if (!f)
Jacob Keller1bc87e82016-10-05 09:30:31 -07001285 return NULL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001286
Jacob Kellercbebb852016-10-05 09:30:40 -07001287 /* Update the boolean indicating if we need to function in
1288 * VLAN mode.
1289 */
1290 if (vlan >= 0)
1291 vsi->has_vlan_filter = true;
1292
Greg Rose9a173902014-05-22 06:32:02 +00001293 ether_addr_copy(f->macaddr, macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001294 f->vlan = vlan;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001295 /* If we're in overflow promisc mode, set the state directly
1296 * to failed, so we don't bother to try sending the filter
1297 * to the hardware.
1298 */
1299 if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))
1300 f->state = I40E_FILTER_FAILED;
1301 else
1302 f->state = I40E_FILTER_NEW;
Jacob Keller278e7d02016-10-05 09:30:37 -07001303 INIT_HLIST_NODE(&f->hlist);
1304
1305 key = i40e_addr_to_hkey(macaddr);
1306 hash_add(vsi->mac_filter_hash, &f->hlist, key);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001307
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001308 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1309 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1310 }
1311
Jacob Keller1bc87e82016-10-05 09:30:31 -07001312 /* If we're asked to add a filter that has been marked for removal, it
1313 * is safe to simply restore it to active state. __i40e_del_filter
1314 * will have simply deleted any filters which were previously marked
1315 * NEW or FAILED, so if it is currently marked REMOVE it must have
1316 * previously been ACTIVE. Since we haven't yet run the sync filters
1317 * task, just restore this filter to the ACTIVE state so that the
1318 * sync task leaves it in place
1319 */
1320 if (f->state == I40E_FILTER_REMOVE)
1321 f->state = I40E_FILTER_ACTIVE;
1322
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001323 return f;
1324}
1325
1326/**
Jacob Keller290d2552016-10-05 09:30:36 -07001327 * __i40e_del_filter - Remove a specific filter from the VSI
1328 * @vsi: VSI to remove from
1329 * @f: the filter to remove from the list
1330 *
1331 * This function should be called instead of i40e_del_filter only if you know
1332 * the exact filter you will remove already, such as via i40e_find_filter or
1333 * i40e_find_mac.
Kiran Patil21659032015-09-30 14:09:03 -04001334 *
Jacob Keller278e7d02016-10-05 09:30:37 -07001335 * NOTE: This function is expected to be called with mac_filter_hash_lock
Kiran Patil21659032015-09-30 14:09:03 -04001336 * being held.
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001337 * ANOTHER NOTE: This function MUST be called from within the context of
1338 * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
1339 * instead of list_for_each_entry().
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001340 **/
Jacob Keller290d2552016-10-05 09:30:36 -07001341static void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001342{
Jacob Keller1bc87e82016-10-05 09:30:31 -07001343 if (!f)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001344 return;
1345
Jacob Keller1bc87e82016-10-05 09:30:31 -07001346 if ((f->state == I40E_FILTER_FAILED) ||
1347 (f->state == I40E_FILTER_NEW)) {
1348 /* this one never got added by the FW. Just remove it,
1349 * no need to sync anything.
1350 */
Jacob Keller278e7d02016-10-05 09:30:37 -07001351 hash_del(&f->hlist);
Jacob Keller1bc87e82016-10-05 09:30:31 -07001352 kfree(f);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001353 } else {
Jacob Keller1bc87e82016-10-05 09:30:31 -07001354 f->state = I40E_FILTER_REMOVE;
1355 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1356 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001357 }
1358}
1359
1360/**
Jacob Keller290d2552016-10-05 09:30:36 -07001361 * i40e_del_filter - Remove a MAC/VLAN filter from the VSI
1362 * @vsi: the VSI to be searched
1363 * @macaddr: the MAC address
1364 * @vlan: the VLAN
1365 *
Jacob Keller278e7d02016-10-05 09:30:37 -07001366 * NOTE: This function is expected to be called with mac_filter_hash_lock
Jacob Keller290d2552016-10-05 09:30:36 -07001367 * being held.
1368 * ANOTHER NOTE: This function MUST be called from within the context of
1369 * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
1370 * instead of list_for_each_entry().
1371 **/
1372void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan)
1373{
1374 struct i40e_mac_filter *f;
1375
1376 if (!vsi || !macaddr)
1377 return;
1378
1379 f = i40e_find_filter(vsi, macaddr, vlan);
1380 __i40e_del_filter(vsi, f);
1381}
1382
1383/**
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001384 * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
1385 * @vsi: the VSI to be searched
1386 * @macaddr: the mac address to be filtered
1387 *
Jacob Keller5feb3d72016-10-05 09:30:34 -07001388 * Goes through all the macvlan filters and adds a macvlan filter for each
1389 * unique vlan that already exists. If a PVID has been assigned, instead only
1390 * add the macaddr to that VLAN.
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001391 *
Jacob Keller5feb3d72016-10-05 09:30:34 -07001392 * Returns last filter added on success, else NULL
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001393 **/
1394struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi,
1395 const u8 *macaddr)
1396{
Jacob Keller5feb3d72016-10-05 09:30:34 -07001397 struct i40e_mac_filter *f, *add = NULL;
Jacob Keller278e7d02016-10-05 09:30:37 -07001398 struct hlist_node *h;
1399 int bkt;
Jacob Keller5feb3d72016-10-05 09:30:34 -07001400
1401 if (vsi->info.pvid)
1402 return i40e_add_filter(vsi, macaddr,
1403 le16_to_cpu(vsi->info.pvid));
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001404
Jacob Keller278e7d02016-10-05 09:30:37 -07001405 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Jacob Keller57b341d2016-10-05 09:30:35 -07001406 if (f->state == I40E_FILTER_REMOVE)
1407 continue;
Jacob Keller5feb3d72016-10-05 09:30:34 -07001408 add = i40e_add_filter(vsi, macaddr, f->vlan);
1409 if (!add)
1410 return NULL;
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001411 }
1412
Jacob Keller5feb3d72016-10-05 09:30:34 -07001413 return add;
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001414}
1415
1416/**
1417 * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS
1418 * @vsi: the VSI to be searched
1419 * @macaddr: the mac address to be removed
1420 *
1421 * Removes a given MAC address from a VSI, regardless of VLAN
1422 *
1423 * Returns 0 for success, or error
1424 **/
1425int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, const u8 *macaddr)
1426{
Jacob Keller278e7d02016-10-05 09:30:37 -07001427 struct i40e_mac_filter *f;
1428 struct hlist_node *h;
Jacob Keller290d2552016-10-05 09:30:36 -07001429 bool found = false;
Jacob Keller278e7d02016-10-05 09:30:37 -07001430 int bkt;
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001431
Jacob Keller278e7d02016-10-05 09:30:37 -07001432 WARN(!spin_is_locked(&vsi->mac_filter_hash_lock),
1433 "Missing mac_filter_hash_lock\n");
1434 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Jacob Keller290d2552016-10-05 09:30:36 -07001435 if (ether_addr_equal(macaddr, f->macaddr)) {
1436 __i40e_del_filter(vsi, f);
1437 found = true;
1438 }
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001439 }
Jacob Keller290d2552016-10-05 09:30:36 -07001440
1441 if (found)
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001442 return 0;
Jacob Keller290d2552016-10-05 09:30:36 -07001443 else
1444 return -ENOENT;
Jacob Keller35ec2ff2016-10-05 09:30:33 -07001445}
1446
1447/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001448 * i40e_set_mac - NDO callback to set mac address
1449 * @netdev: network interface device structure
1450 * @p: pointer to an address structure
1451 *
1452 * Returns 0 on success, negative on failure
1453 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001454#ifdef I40E_FCOE
1455int i40e_set_mac(struct net_device *netdev, void *p)
1456#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001457static int i40e_set_mac(struct net_device *netdev, void *p)
Vasu Dev38e00432014-08-01 13:27:03 -07001458#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001459{
1460 struct i40e_netdev_priv *np = netdev_priv(netdev);
1461 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson30650cc2014-07-29 04:01:50 +00001462 struct i40e_pf *pf = vsi->back;
1463 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001464 struct sockaddr *addr = p;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001465
1466 if (!is_valid_ether_addr(addr->sa_data))
1467 return -EADDRNOTAVAIL;
1468
Shannon Nelson30650cc2014-07-29 04:01:50 +00001469 if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
1470 netdev_info(netdev, "already using mac address %pM\n",
1471 addr->sa_data);
1472 return 0;
1473 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001474
Anjali Singhai Jain80f64282013-11-28 06:39:47 +00001475 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
1476 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
1477 return -EADDRNOTAVAIL;
1478
Shannon Nelson30650cc2014-07-29 04:01:50 +00001479 if (ether_addr_equal(hw->mac.addr, addr->sa_data))
1480 netdev_info(netdev, "returning to hw mac address %pM\n",
1481 hw->mac.addr);
1482 else
1483 netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
1484
Jacob Keller278e7d02016-10-05 09:30:37 -07001485 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller1bc87e82016-10-05 09:30:31 -07001486 i40e_del_mac_all_vlan(vsi, netdev->dev_addr);
1487 i40e_put_mac_in_vlan(vsi, addr->sa_data);
Jacob Keller278e7d02016-10-05 09:30:37 -07001488 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001489 ether_addr_copy(netdev->dev_addr, addr->sa_data);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001490 if (vsi->type == I40E_VSI_MAIN) {
1491 i40e_status ret;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001492
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001493 ret = i40e_aq_mac_address_write(&vsi->back->hw,
Shannon Nelsoncc412222014-06-04 01:23:21 +00001494 I40E_AQC_WRITE_TYPE_LAA_WOL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001495 addr->sa_data, NULL);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001496 if (ret)
1497 netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
1498 i40e_stat_str(hw, ret),
1499 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001500 }
1501
Jesse Brandeburgc53934c2016-01-04 10:33:06 -08001502 /* schedule our worker thread which will take care of
1503 * applying the new filter changes
1504 */
1505 i40e_service_event_schedule(vsi->back);
1506 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001507}
1508
1509/**
1510 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1511 * @vsi: the VSI being setup
1512 * @ctxt: VSI context structure
1513 * @enabled_tc: Enabled TCs bitmap
1514 * @is_add: True if called before Add VSI
1515 *
1516 * Setup VSI queue mapping for enabled traffic classes.
1517 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001518#ifdef I40E_FCOE
1519void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1520 struct i40e_vsi_context *ctxt,
1521 u8 enabled_tc,
1522 bool is_add)
1523#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001524static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1525 struct i40e_vsi_context *ctxt,
1526 u8 enabled_tc,
1527 bool is_add)
Vasu Dev38e00432014-08-01 13:27:03 -07001528#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001529{
1530 struct i40e_pf *pf = vsi->back;
1531 u16 sections = 0;
1532 u8 netdev_tc = 0;
1533 u16 numtc = 0;
1534 u16 qcount;
1535 u8 offset;
1536 u16 qmap;
1537 int i;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001538 u16 num_tc_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001539
1540 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
1541 offset = 0;
1542
1543 if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
1544 /* Find numtc from enabled TC bitmap */
1545 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08001546 if (enabled_tc & BIT(i)) /* TC is enabled */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001547 numtc++;
1548 }
1549 if (!numtc) {
1550 dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
1551 numtc = 1;
1552 }
1553 } else {
1554 /* At least TC0 is enabled in case of non-DCB case */
1555 numtc = 1;
1556 }
1557
1558 vsi->tc_config.numtc = numtc;
1559 vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001560 /* Number of queues per enabled TC */
Catherine Sullivan7d644022016-05-16 10:26:41 -07001561 qcount = vsi->alloc_queue_pairs;
1562
Anjali Singhai7f9ff472015-02-21 06:43:19 +00001563 num_tc_qps = qcount / numtc;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04001564 num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001565
1566 /* Setup queue offset/count for all TCs for given VSI */
1567 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1568 /* See if the given TC is enabled for the given VSI */
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08001569 if (vsi->tc_config.enabled_tc & BIT(i)) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001570 /* TC is enabled */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001571 int pow, num_qps;
1572
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001573 switch (vsi->type) {
1574 case I40E_VSI_MAIN:
Helin Zhangacd65442015-10-26 19:44:28 -04001575 qcount = min_t(int, pf->alloc_rss_size,
1576 num_tc_qps);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001577 break;
Vasu Dev38e00432014-08-01 13:27:03 -07001578#ifdef I40E_FCOE
1579 case I40E_VSI_FCOE:
1580 qcount = num_tc_qps;
1581 break;
1582#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001583 case I40E_VSI_FDIR:
1584 case I40E_VSI_SRIOV:
1585 case I40E_VSI_VMDQ2:
1586 default:
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001587 qcount = num_tc_qps;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001588 WARN_ON(i != 0);
1589 break;
1590 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001591 vsi->tc_config.tc_info[i].qoffset = offset;
1592 vsi->tc_config.tc_info[i].qcount = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001593
Shannon Nelson1e200e42015-02-27 09:15:24 +00001594 /* find the next higher power-of-2 of num queue pairs */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001595 num_qps = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001596 pow = 0;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001597 while (num_qps && (BIT_ULL(pow) < qcount)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001598 pow++;
1599 num_qps >>= 1;
1600 }
1601
1602 vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
1603 qmap =
1604 (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
1605 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
1606
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001607 offset += qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001608 } else {
1609 /* TC is not enabled so set the offset to
1610 * default queue and allocate one queue
1611 * for the given TC.
1612 */
1613 vsi->tc_config.tc_info[i].qoffset = 0;
1614 vsi->tc_config.tc_info[i].qcount = 1;
1615 vsi->tc_config.tc_info[i].netdev_tc = 0;
1616
1617 qmap = 0;
1618 }
1619 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
1620 }
1621
1622 /* Set actual Tx/Rx queue pairs */
1623 vsi->num_queue_pairs = offset;
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00001624 if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
1625 if (vsi->req_queue_pairs > 0)
1626 vsi->num_queue_pairs = vsi->req_queue_pairs;
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04001627 else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00001628 vsi->num_queue_pairs = pf->num_lan_msix;
1629 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001630
1631 /* Scheduler section valid can only be set for ADD VSI */
1632 if (is_add) {
1633 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
1634
1635 ctxt->info.up_enable_bits = enabled_tc;
1636 }
1637 if (vsi->type == I40E_VSI_SRIOV) {
1638 ctxt->info.mapping_flags |=
1639 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
1640 for (i = 0; i < vsi->num_queue_pairs; i++)
1641 ctxt->info.queue_mapping[i] =
1642 cpu_to_le16(vsi->base_queue + i);
1643 } else {
1644 ctxt->info.mapping_flags |=
1645 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
1646 ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
1647 }
1648 ctxt->info.valid_sections |= cpu_to_le16(sections);
1649}
1650
1651/**
Jacob Keller6622f5c2016-10-05 09:30:32 -07001652 * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
1653 * @netdev: the netdevice
1654 * @addr: address to add
1655 *
1656 * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
1657 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
1658 */
1659static int i40e_addr_sync(struct net_device *netdev, const u8 *addr)
1660{
1661 struct i40e_netdev_priv *np = netdev_priv(netdev);
1662 struct i40e_vsi *vsi = np->vsi;
1663 struct i40e_mac_filter *f;
1664
1665 if (i40e_is_vsi_in_vlan(vsi))
1666 f = i40e_put_mac_in_vlan(vsi, addr);
1667 else
1668 f = i40e_add_filter(vsi, addr, I40E_VLAN_ANY);
1669
1670 if (f)
1671 return 0;
1672 else
1673 return -ENOMEM;
1674}
1675
1676/**
1677 * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
1678 * @netdev: the netdevice
1679 * @addr: address to add
1680 *
1681 * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
1682 * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
1683 */
1684static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr)
1685{
1686 struct i40e_netdev_priv *np = netdev_priv(netdev);
1687 struct i40e_vsi *vsi = np->vsi;
1688
1689 if (i40e_is_vsi_in_vlan(vsi))
1690 i40e_del_mac_all_vlan(vsi, addr);
1691 else
1692 i40e_del_filter(vsi, addr, I40E_VLAN_ANY);
1693
1694 return 0;
1695}
1696
1697/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001698 * i40e_set_rx_mode - NDO callback to set the netdev filters
1699 * @netdev: network interface device structure
1700 **/
Vasu Dev38e00432014-08-01 13:27:03 -07001701#ifdef I40E_FCOE
1702void i40e_set_rx_mode(struct net_device *netdev)
1703#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001704static void i40e_set_rx_mode(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -07001705#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001706{
1707 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001708 struct i40e_vsi *vsi = np->vsi;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001709
Jacob Keller278e7d02016-10-05 09:30:37 -07001710 spin_lock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -04001711
Jacob Keller6622f5c2016-10-05 09:30:32 -07001712 __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
1713 __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001714
Jacob Keller278e7d02016-10-05 09:30:37 -07001715 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001716
1717 /* check for other flag changes */
1718 if (vsi->current_netdev_flags != vsi->netdev->flags) {
1719 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1720 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1721 }
Jesse Brandeburgc53934c2016-01-04 10:33:06 -08001722
1723 /* schedule our worker thread which will take care of
1724 * applying the new filter changes
1725 */
1726 i40e_service_event_schedule(vsi->back);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001727}
1728
1729/**
Jacob Keller4a2ce272016-10-05 09:30:38 -07001730 * i40e_undo_filter_entries - Undo the changes made to MAC filter entries
1731 * @vsi: Pointer to VSI struct
Kiran Patil21659032015-09-30 14:09:03 -04001732 * @from: Pointer to list which contains MAC filter entries - changes to
1733 * those entries needs to be undone.
1734 *
Jacob Keller4a2ce272016-10-05 09:30:38 -07001735 * MAC filter entries from list were slated to be sent to firmware, either for
1736 * addition or deletion.
Kiran Patil21659032015-09-30 14:09:03 -04001737 **/
Jacob Keller4a2ce272016-10-05 09:30:38 -07001738static void i40e_undo_filter_entries(struct i40e_vsi *vsi,
1739 struct hlist_head *from)
Kiran Patil21659032015-09-30 14:09:03 -04001740{
Jacob Keller278e7d02016-10-05 09:30:37 -07001741 struct i40e_mac_filter *f;
1742 struct hlist_node *h;
Kiran Patil21659032015-09-30 14:09:03 -04001743
Jacob Keller278e7d02016-10-05 09:30:37 -07001744 hlist_for_each_entry_safe(f, h, from, hlist) {
1745 u64 key = i40e_addr_to_hkey(f->macaddr);
1746
Kiran Patil21659032015-09-30 14:09:03 -04001747 /* Move the element back into MAC filter list*/
Jacob Keller278e7d02016-10-05 09:30:37 -07001748 hlist_del(&f->hlist);
1749 hash_add(vsi->mac_filter_hash, &f->hlist, key);
Kiran Patil21659032015-09-30 14:09:03 -04001750 }
1751}
1752
1753/**
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001754 * i40e_update_filter_state - Update filter state based on return data
1755 * from firmware
1756 * @count: Number of filters added
1757 * @add_list: return data from fw
1758 * @head: pointer to first filter in current batch
1759 * @aq_err: status from fw
Kiran Patil21659032015-09-30 14:09:03 -04001760 *
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001761 * MAC filter entries from list were slated to be added to device. Returns
1762 * number of successful filters. Note that 0 does NOT mean success!
Kiran Patil21659032015-09-30 14:09:03 -04001763 **/
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001764static int
1765i40e_update_filter_state(int count,
1766 struct i40e_aqc_add_macvlan_element_data *add_list,
1767 struct i40e_mac_filter *add_head, int aq_err)
Kiran Patil21659032015-09-30 14:09:03 -04001768{
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001769 int retval = 0;
1770 int i;
Kiran Patil21659032015-09-30 14:09:03 -04001771
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001772
1773 if (!aq_err) {
1774 retval = count;
1775 /* Everything's good, mark all filters active. */
1776 for (i = 0; i < count ; i++) {
1777 add_head->state = I40E_FILTER_ACTIVE;
Jacob Keller278e7d02016-10-05 09:30:37 -07001778 add_head = hlist_entry(add_head->hlist.next,
1779 typeof(struct i40e_mac_filter),
1780 hlist);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001781 }
1782 } else if (aq_err == I40E_AQ_RC_ENOSPC) {
1783 /* Device ran out of filter space. Check the return value
1784 * for each filter to see which ones are active.
1785 */
1786 for (i = 0; i < count ; i++) {
1787 if (add_list[i].match_method ==
1788 I40E_AQC_MM_ERR_NO_RES) {
1789 add_head->state = I40E_FILTER_FAILED;
1790 } else {
1791 add_head->state = I40E_FILTER_ACTIVE;
1792 retval++;
1793 }
Jacob Keller278e7d02016-10-05 09:30:37 -07001794 add_head = hlist_entry(add_head->hlist.next,
1795 typeof(struct i40e_mac_filter),
1796 hlist);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001797 }
1798 } else {
1799 /* Some other horrible thing happened, fail all filters */
1800 retval = 0;
1801 for (i = 0; i < count ; i++) {
1802 add_head->state = I40E_FILTER_FAILED;
Jacob Keller278e7d02016-10-05 09:30:37 -07001803 add_head = hlist_entry(add_head->hlist.next,
1804 typeof(struct i40e_mac_filter),
1805 hlist);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001806 }
Kiran Patil21659032015-09-30 14:09:03 -04001807 }
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001808 return retval;
Kiran Patil21659032015-09-30 14:09:03 -04001809}
1810
1811/**
Jacob Keller00936312016-10-05 09:30:41 -07001812 * i40e_aqc_del_filters - Request firmware to delete a set of filters
1813 * @vsi: ptr to the VSI
1814 * @vsi_name: name to display in messages
1815 * @list: the list of filters to send to firmware
1816 * @num_del: the number of filters to delete
1817 * @retval: Set to -EIO on failure to delete
1818 *
1819 * Send a request to firmware via AdminQ to delete a set of filters. Uses
1820 * *retval instead of a return value so that success does not force ret_val to
1821 * be set to 0. This ensures that a sequence of calls to this function
1822 * preserve the previous value of *retval on successful delete.
1823 */
1824static
1825void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name,
1826 struct i40e_aqc_remove_macvlan_element_data *list,
1827 int num_del, int *retval)
1828{
1829 struct i40e_hw *hw = &vsi->back->hw;
1830 i40e_status aq_ret;
1831 int aq_err;
1832
1833 aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL);
1834 aq_err = hw->aq.asq_last_status;
1835
1836 /* Explicitly ignore and do not report when firmware returns ENOENT */
1837 if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
1838 *retval = -EIO;
1839 dev_info(&vsi->back->pdev->dev,
1840 "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
1841 vsi_name, i40e_stat_str(hw, aq_ret),
1842 i40e_aq_str(hw, aq_err));
1843 }
1844}
1845
1846/**
1847 * i40e_aqc_add_filters - Request firmware to add a set of filters
1848 * @vsi: ptr to the VSI
1849 * @vsi_name: name to display in messages
1850 * @list: the list of filters to send to firmware
1851 * @add_head: Position in the add hlist
1852 * @num_add: the number of filters to add
1853 * @promisc_change: set to true on exit if promiscuous mode was forced on
1854 *
1855 * Send a request to firmware via AdminQ to add a chunk of filters. Will set
1856 * promisc_changed to true if the firmware has run out of space for more
1857 * filters.
1858 */
1859static
1860void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
1861 struct i40e_aqc_add_macvlan_element_data *list,
1862 struct i40e_mac_filter *add_head,
1863 int num_add, bool *promisc_changed)
1864{
1865 struct i40e_hw *hw = &vsi->back->hw;
1866 i40e_status aq_ret;
1867 int aq_err, fcnt;
1868
1869 aq_ret = i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL);
1870 aq_err = hw->aq.asq_last_status;
1871 fcnt = i40e_update_filter_state(num_add, list, add_head, aq_ret);
1872 vsi->active_filters += fcnt;
1873
1874 if (fcnt != num_add) {
1875 *promisc_changed = true;
1876 set_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
1877 vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
1878 dev_warn(&vsi->back->pdev->dev,
1879 "Error %s adding RX filters on %s, promiscuous mode forced on\n",
1880 i40e_aq_str(hw, aq_err),
1881 vsi_name);
1882 }
1883}
1884
1885/**
Jacob Keller435c0842016-11-08 13:05:10 -08001886 * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags
1887 * @vsi: pointer to the VSI
1888 * @f: filter data
1889 *
1890 * This function sets or clears the promiscuous broadcast flags for VLAN
1891 * filters in order to properly receive broadcast frames. Assumes that only
1892 * broadcast filters are passed.
1893 **/
1894static
1895void i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name,
1896 struct i40e_mac_filter *f)
1897{
1898 bool enable = f->state == I40E_FILTER_NEW;
1899 struct i40e_hw *hw = &vsi->back->hw;
1900 i40e_status aq_ret;
1901
1902 if (f->vlan == I40E_VLAN_ANY) {
1903 aq_ret = i40e_aq_set_vsi_broadcast(hw,
1904 vsi->seid,
1905 enable,
1906 NULL);
1907 } else {
1908 aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw,
1909 vsi->seid,
1910 enable,
1911 f->vlan,
1912 NULL);
1913 }
1914
1915 if (aq_ret) {
1916 dev_warn(&vsi->back->pdev->dev,
1917 "Error %s setting broadcast promiscuous mode on %s\n",
1918 i40e_aq_str(hw, hw->aq.asq_last_status),
1919 vsi_name);
1920 f->state = I40E_FILTER_FAILED;
1921 } else if (enable) {
1922 f->state = I40E_FILTER_ACTIVE;
1923 }
1924}
1925
1926/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001927 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1928 * @vsi: ptr to the VSI
1929 *
1930 * Push any outstanding VSI filter changes through the AdminQ.
1931 *
1932 * Returns 0 or error value
1933 **/
Jesse Brandeburg17652c62015-11-05 17:01:02 -08001934int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001935{
Jacob Keller278e7d02016-10-05 09:30:37 -07001936 struct hlist_head tmp_add_list, tmp_del_list;
Alan Brady84f5ca62016-10-05 09:30:39 -07001937 struct i40e_mac_filter *f, *add_head = NULL;
Mitch Williams3e25a8f2016-05-16 10:26:32 -07001938 struct i40e_hw *hw = &vsi->back->hw;
Alan Brady84f5ca62016-10-05 09:30:39 -07001939 unsigned int vlan_any_filters = 0;
1940 unsigned int non_vlan_filters = 0;
1941 unsigned int vlan_filters = 0;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001942 bool promisc_changed = false;
Shannon Nelson2d1de822016-05-16 10:26:44 -07001943 char vsi_name[16] = "PF";
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001944 int filter_list_len = 0;
Mitch Williamsea02e902015-11-09 15:35:50 -08001945 i40e_status aq_ret = 0;
Alan Brady84f5ca62016-10-05 09:30:39 -07001946 u32 changed_flags = 0;
Jacob Keller278e7d02016-10-05 09:30:37 -07001947 struct hlist_node *h;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001948 struct i40e_pf *pf;
1949 int num_add = 0;
1950 int num_del = 0;
Alan Brady84f5ca62016-10-05 09:30:39 -07001951 int retval = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001952 u16 cmd_flags;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001953 int list_size;
Jacob Keller278e7d02016-10-05 09:30:37 -07001954 int bkt;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001955
1956 /* empty array typed pointers, kcalloc later */
1957 struct i40e_aqc_add_macvlan_element_data *add_list;
1958 struct i40e_aqc_remove_macvlan_element_data *del_list;
1959
1960 while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
1961 usleep_range(1000, 2000);
1962 pf = vsi->back;
1963
1964 if (vsi->netdev) {
1965 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
1966 vsi->current_netdev_flags = vsi->netdev->flags;
1967 }
1968
Jacob Keller278e7d02016-10-05 09:30:37 -07001969 INIT_HLIST_HEAD(&tmp_add_list);
1970 INIT_HLIST_HEAD(&tmp_del_list);
Kiran Patil21659032015-09-30 14:09:03 -04001971
Shannon Nelson2d1de822016-05-16 10:26:44 -07001972 if (vsi->type == I40E_VSI_SRIOV)
1973 snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
1974 else if (vsi->type != I40E_VSI_MAIN)
1975 snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
1976
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001977 if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
1978 vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
1979
Jacob Keller278e7d02016-10-05 09:30:37 -07001980 spin_lock_bh(&vsi->mac_filter_hash_lock);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001981 /* Create a list of filters to delete. */
Jacob Keller278e7d02016-10-05 09:30:37 -07001982 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001983 if (f->state == I40E_FILTER_REMOVE) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001984 /* Move the element into temporary del_list */
Jacob Keller278e7d02016-10-05 09:30:37 -07001985 hash_del(&f->hlist);
1986 hlist_add_head(&f->hlist, &tmp_del_list);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001987 vsi->active_filters--;
Alan Brady84f5ca62016-10-05 09:30:39 -07001988
1989 /* Avoid counting removed filters */
1990 continue;
Kiran Patil21659032015-09-30 14:09:03 -04001991 }
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001992 if (f->state == I40E_FILTER_NEW) {
Jacob Keller278e7d02016-10-05 09:30:37 -07001993 hash_del(&f->hlist);
1994 hlist_add_head(&f->hlist, &tmp_add_list);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07001995 }
Alan Brady84f5ca62016-10-05 09:30:39 -07001996
1997 /* Count the number of each type of filter we have
1998 * remaining, ignoring any filters we're about to
1999 * delete.
2000 */
2001 if (f->vlan > 0)
2002 vlan_filters++;
2003 else if (!f->vlan)
2004 non_vlan_filters++;
2005 else
2006 vlan_any_filters++;
2007 }
2008
2009 /* We should never have VLAN=-1 filters at the same time as we
2010 * have either VLAN=0 or VLAN>0 filters, so warn about this
2011 * case here to help catch any issues.
2012 */
2013 WARN_ON(vlan_any_filters && (vlan_filters + non_vlan_filters));
2014
2015 /* If we only have VLAN=0 filters remaining, and don't have
2016 * any other VLAN filters, we need to convert these VLAN=0
2017 * filters into VLAN=-1 (I40E_VLAN_ANY) so that we operate
2018 * correctly in non-VLAN mode and receive all traffic tagged
2019 * or untagged.
2020 */
2021 if (non_vlan_filters && !vlan_filters) {
2022 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f,
2023 hlist) {
2024 /* Only replace VLAN=0 filters */
2025 if (f->vlan)
2026 continue;
2027
2028 /* Allocate a replacement element */
2029 add_head = kzalloc(sizeof(*add_head),
2030 GFP_KERNEL);
2031 if (!add_head)
2032 goto err_no_memory_locked;
2033
2034 /* Copy the filter, with new state and VLAN */
2035 *add_head = *f;
2036 add_head->state = I40E_FILTER_NEW;
2037 add_head->vlan = I40E_VLAN_ANY;
2038
2039 /* Move the replacement to the add list */
2040 INIT_HLIST_NODE(&add_head->hlist);
2041 hlist_add_head(&add_head->hlist,
2042 &tmp_add_list);
2043
2044 /* Move the original to the delete list */
2045 f->state = I40E_FILTER_REMOVE;
2046 hash_del(&f->hlist);
2047 hlist_add_head(&f->hlist, &tmp_del_list);
2048 vsi->active_filters--;
2049 }
2050
2051 /* Also update any filters on the tmp_add list */
2052 hlist_for_each_entry(f, &tmp_add_list, hlist) {
2053 if (!f->vlan)
2054 f->vlan = I40E_VLAN_ANY;
2055 }
2056 add_head = NULL;
Kiran Patil21659032015-09-30 14:09:03 -04002057 }
Jacob Keller278e7d02016-10-05 09:30:37 -07002058 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -04002059 }
2060
2061 /* Now process 'del_list' outside the lock */
Jacob Keller278e7d02016-10-05 09:30:37 -07002062 if (!hlist_empty(&tmp_del_list)) {
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002063 filter_list_len = hw->aq.asq_buf_size /
Kiran Patil21659032015-09-30 14:09:03 -04002064 sizeof(struct i40e_aqc_remove_macvlan_element_data);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002065 list_size = filter_list_len *
Shannon Nelsonf1199992015-11-19 11:34:23 -08002066 sizeof(struct i40e_aqc_remove_macvlan_element_data);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002067 del_list = kzalloc(list_size, GFP_ATOMIC);
Jacob Keller4a2ce272016-10-05 09:30:38 -07002068 if (!del_list)
2069 goto err_no_memory;
Kiran Patil21659032015-09-30 14:09:03 -04002070
Jacob Keller278e7d02016-10-05 09:30:37 -07002071 hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002072 cmd_flags = 0;
2073
Jacob Keller435c0842016-11-08 13:05:10 -08002074 /* handle broadcast filters by updating the broadcast
2075 * promiscuous flag instead of deleting a MAC filter.
2076 */
2077 if (is_broadcast_ether_addr(f->macaddr)) {
2078 i40e_aqc_broadcast_filter(vsi, vsi_name, f);
2079
2080 hlist_del(&f->hlist);
2081 kfree(f);
2082 continue;
2083 }
2084
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002085 /* add to delete list */
Greg Rose9a173902014-05-22 06:32:02 +00002086 ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002087 if (f->vlan == I40E_VLAN_ANY) {
2088 del_list[num_del].vlan_tag = 0;
Alan Bradya6cb9142016-09-06 18:05:07 -07002089 cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002090 } else {
2091 del_list[num_del].vlan_tag =
2092 cpu_to_le16((u16)(f->vlan));
2093 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002094
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002095 cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
2096 del_list[num_del].flags = cmd_flags;
2097 num_del++;
2098
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002099 /* flush a full buffer */
2100 if (num_del == filter_list_len) {
Jacob Keller00936312016-10-05 09:30:41 -07002101 i40e_aqc_del_filters(vsi, vsi_name, del_list,
2102 num_del, &retval);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002103 memset(del_list, 0, list_size);
Jacob Keller00936312016-10-05 09:30:41 -07002104 num_del = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002105 }
Kiran Patil21659032015-09-30 14:09:03 -04002106 /* Release memory for MAC filter entries which were
2107 * synced up with HW.
2108 */
Jacob Keller278e7d02016-10-05 09:30:37 -07002109 hlist_del(&f->hlist);
Kiran Patil21659032015-09-30 14:09:03 -04002110 kfree(f);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002111 }
Kiran Patil21659032015-09-30 14:09:03 -04002112
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002113 if (num_del) {
Jacob Keller00936312016-10-05 09:30:41 -07002114 i40e_aqc_del_filters(vsi, vsi_name, del_list,
2115 num_del, &retval);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002116 }
2117
2118 kfree(del_list);
2119 del_list = NULL;
Kiran Patil21659032015-09-30 14:09:03 -04002120 }
2121
Jacob Kellercbebb852016-10-05 09:30:40 -07002122 /* After finishing notifying firmware of the deleted filters, update
2123 * the cached value of vsi->has_vlan_filter. Note that we are safe to
2124 * use just !!vlan_filters here because if we only have VLAN=0 (that
2125 * is, non_vlan_filters) these will all be converted to VLAN=-1 in the
2126 * logic above already so this value would still be correct.
2127 */
2128 vsi->has_vlan_filter = !!vlan_filters;
2129
Jacob Keller278e7d02016-10-05 09:30:37 -07002130 if (!hlist_empty(&tmp_add_list)) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002131 /* Do all the adds now. */
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002132 filter_list_len = hw->aq.asq_buf_size /
Shannon Nelsonf1199992015-11-19 11:34:23 -08002133 sizeof(struct i40e_aqc_add_macvlan_element_data);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002134 list_size = filter_list_len *
2135 sizeof(struct i40e_aqc_add_macvlan_element_data);
2136 add_list = kzalloc(list_size, GFP_ATOMIC);
Jacob Keller4a2ce272016-10-05 09:30:38 -07002137 if (!add_list)
2138 goto err_no_memory;
2139
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002140 num_add = 0;
Jacob Keller435c0842016-11-08 13:05:10 -08002141 hlist_for_each_entry_safe(f, h, &tmp_add_list, hlist) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002142 if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2143 &vsi->state)) {
2144 f->state = I40E_FILTER_FAILED;
2145 continue;
2146 }
Jacob Keller435c0842016-11-08 13:05:10 -08002147
2148 /* handle broadcast filters by updating the broadcast
2149 * promiscuous flag instead of adding a MAC filter.
2150 */
2151 if (is_broadcast_ether_addr(f->macaddr)) {
2152 u64 key = i40e_addr_to_hkey(f->macaddr);
2153 i40e_aqc_broadcast_filter(vsi, vsi_name, f);
2154
2155 hlist_del(&f->hlist);
2156 hash_add(vsi->mac_filter_hash, &f->hlist, key);
2157 continue;
2158 }
2159
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002160 /* add to add array */
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002161 if (num_add == 0)
2162 add_head = f;
2163 cmd_flags = 0;
Greg Rose9a173902014-05-22 06:32:02 +00002164 ether_addr_copy(add_list[num_add].mac_addr, f->macaddr);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002165 if (f->vlan == I40E_VLAN_ANY) {
2166 add_list[num_add].vlan_tag = 0;
2167 cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
2168 } else {
2169 add_list[num_add].vlan_tag =
2170 cpu_to_le16((u16)(f->vlan));
2171 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002172 add_list[num_add].queue_number = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002173 cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002174 add_list[num_add].flags = cpu_to_le16(cmd_flags);
2175 num_add++;
2176
2177 /* flush a full buffer */
2178 if (num_add == filter_list_len) {
Jacob Keller00936312016-10-05 09:30:41 -07002179 i40e_aqc_add_filters(vsi, vsi_name, add_list,
2180 add_head, num_add,
2181 &promisc_changed);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002182 memset(add_list, 0, list_size);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002183 num_add = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002184 }
2185 }
2186 if (num_add) {
Jacob Keller00936312016-10-05 09:30:41 -07002187 i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head,
2188 num_add, &promisc_changed);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002189 }
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002190 /* Now move all of the filters from the temp add list back to
2191 * the VSI's list.
2192 */
Jacob Keller278e7d02016-10-05 09:30:37 -07002193 spin_lock_bh(&vsi->mac_filter_hash_lock);
2194 hlist_for_each_entry_safe(f, h, &tmp_add_list, hlist) {
2195 u64 key = i40e_addr_to_hkey(f->macaddr);
2196
2197 hlist_del(&f->hlist);
2198 hash_add(vsi->mac_filter_hash, &f->hlist, key);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002199 }
Jacob Keller278e7d02016-10-05 09:30:37 -07002200 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002201 kfree(add_list);
2202 add_list = NULL;
2203 }
2204
2205 /* Check to see if we can drop out of overflow promiscuous mode. */
2206 if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state) &&
2207 (vsi->active_filters < vsi->promisc_threshold)) {
2208 int failed_count = 0;
2209 /* See if we have any failed filters. We can't drop out of
2210 * promiscuous until these have all been deleted.
2211 */
Jacob Keller278e7d02016-10-05 09:30:37 -07002212 spin_lock_bh(&vsi->mac_filter_hash_lock);
2213 hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002214 if (f->state == I40E_FILTER_FAILED)
2215 failed_count++;
2216 }
Jacob Keller278e7d02016-10-05 09:30:37 -07002217 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002218 if (!failed_count) {
2219 dev_info(&pf->pdev->dev,
2220 "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
2221 vsi_name);
2222 clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
2223 promisc_changed = true;
2224 vsi->promisc_threshold = 0;
2225 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002226 }
2227
Anjali Singhai Jaina856b5c2016-04-13 03:08:23 -07002228 /* if the VF is not trusted do not do promisc */
2229 if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
2230 clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
2231 goto out;
2232 }
2233
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002234 /* check for changes in promiscuous modes */
2235 if (changed_flags & IFF_ALLMULTI) {
2236 bool cur_multipromisc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002237
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002238 cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
Mitch Williamsea02e902015-11-09 15:35:50 -08002239 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
2240 vsi->seid,
2241 cur_multipromisc,
2242 NULL);
2243 if (aq_ret) {
2244 retval = i40e_aq_rc_to_posix(aq_ret,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002245 hw->aq.asq_last_status);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002246 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002247 "set multi promisc failed on %s, err %s aq_err %s\n",
2248 vsi_name,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002249 i40e_stat_str(hw, aq_ret),
2250 i40e_aq_str(hw, hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002251 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002252 }
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07002253 if ((changed_flags & IFF_PROMISC) ||
2254 (promisc_changed &&
2255 test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002256 bool cur_promisc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -04002257
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002258 cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
2259 test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
2260 &vsi->state));
Anjali Singhai Jain6784ed52016-01-15 14:33:13 -08002261 if ((vsi->type == I40E_VSI_MAIN) &&
2262 (pf->lan_veb != I40E_NO_VEB) &&
2263 !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002264 /* set defport ON for Main VSI instead of true promisc
2265 * this way we will get all unicast/multicast and VLAN
2266 * promisc behavior but will not get VF or VMDq traffic
2267 * replicated on the Main VSI.
2268 */
2269 if (pf->cur_promisc != cur_promisc) {
2270 pf->cur_promisc = cur_promisc;
Mitch Williams5bc16032016-05-16 10:26:43 -07002271 if (cur_promisc)
2272 aq_ret =
2273 i40e_aq_set_default_vsi(hw,
2274 vsi->seid,
2275 NULL);
2276 else
2277 aq_ret =
2278 i40e_aq_clear_default_vsi(hw,
2279 vsi->seid,
2280 NULL);
2281 if (aq_ret) {
2282 retval = i40e_aq_rc_to_posix(aq_ret,
2283 hw->aq.asq_last_status);
2284 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002285 "Set default VSI failed on %s, err %s, aq_err %s\n",
2286 vsi_name,
Mitch Williams5bc16032016-05-16 10:26:43 -07002287 i40e_stat_str(hw, aq_ret),
2288 i40e_aq_str(hw,
2289 hw->aq.asq_last_status));
2290 }
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002291 }
2292 } else {
Mitch Williamsea02e902015-11-09 15:35:50 -08002293 aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002294 hw,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002295 vsi->seid,
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002296 cur_promisc, NULL,
2297 true);
Mitch Williamsea02e902015-11-09 15:35:50 -08002298 if (aq_ret) {
2299 retval =
2300 i40e_aq_rc_to_posix(aq_ret,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002301 hw->aq.asq_last_status);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002302 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002303 "set unicast promisc failed on %s, err %s, aq_err %s\n",
2304 vsi_name,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002305 i40e_stat_str(hw, aq_ret),
2306 i40e_aq_str(hw,
2307 hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002308 }
2309 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002310 hw,
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002311 vsi->seid,
2312 cur_promisc, NULL);
Mitch Williamsea02e902015-11-09 15:35:50 -08002313 if (aq_ret) {
2314 retval =
2315 i40e_aq_rc_to_posix(aq_ret,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002316 hw->aq.asq_last_status);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002317 dev_info(&pf->pdev->dev,
Shannon Nelson2d1de822016-05-16 10:26:44 -07002318 "set multicast promisc failed on %s, err %s, aq_err %s\n",
2319 vsi_name,
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002320 i40e_stat_str(hw, aq_ret),
2321 i40e_aq_str(hw,
2322 hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002323 }
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04002324 }
Mitch Williamsea02e902015-11-09 15:35:50 -08002325 aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
2326 vsi->seid,
2327 cur_promisc, NULL);
2328 if (aq_ret) {
2329 retval = i40e_aq_rc_to_posix(aq_ret,
2330 pf->hw.aq.asq_last_status);
Greg Rose1a103702013-11-28 06:42:39 +00002331 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002332 "set brdcast promisc failed, err %s, aq_err %s\n",
Mitch Williams3e25a8f2016-05-16 10:26:32 -07002333 i40e_stat_str(hw, aq_ret),
2334 i40e_aq_str(hw,
2335 hw->aq.asq_last_status));
Mitch Williamsea02e902015-11-09 15:35:50 -08002336 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002337 }
Mitch Williamsea02e902015-11-09 15:35:50 -08002338out:
Jesse Brandeburg2818ccd2016-01-13 16:51:38 -08002339 /* if something went wrong then set the changed flag so we try again */
2340 if (retval)
2341 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
2342
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002343 clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
Mitch Williamsea02e902015-11-09 15:35:50 -08002344 return retval;
Jacob Keller4a2ce272016-10-05 09:30:38 -07002345
2346err_no_memory:
2347 /* Restore elements on the temporary add and delete lists */
2348 spin_lock_bh(&vsi->mac_filter_hash_lock);
Alan Brady84f5ca62016-10-05 09:30:39 -07002349err_no_memory_locked:
Jacob Keller4a2ce272016-10-05 09:30:38 -07002350 i40e_undo_filter_entries(vsi, &tmp_del_list);
2351 i40e_undo_filter_entries(vsi, &tmp_add_list);
2352 spin_unlock_bh(&vsi->mac_filter_hash_lock);
2353
2354 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
2355 clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
2356 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002357}
2358
2359/**
2360 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
2361 * @pf: board private structure
2362 **/
2363static void i40e_sync_filters_subtask(struct i40e_pf *pf)
2364{
2365 int v;
2366
2367 if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
2368 return;
2369 pf->flags &= ~I40E_FLAG_FILTER_SYNC;
2370
Mitch Williams505682c2014-05-20 08:01:37 +00002371 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002372 if (pf->vsi[v] &&
Jesse Brandeburg17652c62015-11-05 17:01:02 -08002373 (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
2374 int ret = i40e_sync_vsi_filters(pf->vsi[v]);
2375
2376 if (ret) {
2377 /* come back and try again later */
2378 pf->flags |= I40E_FLAG_FILTER_SYNC;
2379 break;
2380 }
2381 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002382 }
2383}
2384
2385/**
2386 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
2387 * @netdev: network interface device structure
2388 * @new_mtu: new value for maximum frame size
2389 *
2390 * Returns 0 on success, negative on failure
2391 **/
2392static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
2393{
2394 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002395 struct i40e_vsi *vsi = np->vsi;
2396
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002397 netdev_info(netdev, "changing MTU from %d to %d\n",
2398 netdev->mtu, new_mtu);
2399 netdev->mtu = new_mtu;
2400 if (netif_running(netdev))
2401 i40e_vsi_reinit_locked(vsi);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06002402 i40e_notify_client_of_l2_param_changes(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002403 return 0;
2404}
2405
2406/**
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002407 * i40e_ioctl - Access the hwtstamp interface
2408 * @netdev: network interface device structure
2409 * @ifr: interface request data
2410 * @cmd: ioctl command
2411 **/
2412int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2413{
2414 struct i40e_netdev_priv *np = netdev_priv(netdev);
2415 struct i40e_pf *pf = np->vsi->back;
2416
2417 switch (cmd) {
2418 case SIOCGHWTSTAMP:
2419 return i40e_ptp_get_ts_config(pf, ifr);
2420 case SIOCSHWTSTAMP:
2421 return i40e_ptp_set_ts_config(pf, ifr);
2422 default:
2423 return -EOPNOTSUPP;
2424 }
2425}
2426
2427/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002428 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
2429 * @vsi: the vsi being adjusted
2430 **/
2431void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
2432{
2433 struct i40e_vsi_context ctxt;
2434 i40e_status ret;
2435
2436 if ((vsi->info.valid_sections &
2437 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2438 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
2439 return; /* already enabled */
2440
2441 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2442 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2443 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
2444
2445 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002446 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002447 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2448 if (ret) {
2449 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002450 "update vlan stripping failed, err %s aq_err %s\n",
2451 i40e_stat_str(&vsi->back->hw, ret),
2452 i40e_aq_str(&vsi->back->hw,
2453 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002454 }
2455}
2456
2457/**
2458 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
2459 * @vsi: the vsi being adjusted
2460 **/
2461void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
2462{
2463 struct i40e_vsi_context ctxt;
2464 i40e_status ret;
2465
2466 if ((vsi->info.valid_sections &
2467 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2468 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
2469 I40E_AQ_VSI_PVLAN_EMOD_MASK))
2470 return; /* already disabled */
2471
2472 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2473 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
2474 I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
2475
2476 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002477 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002478 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2479 if (ret) {
2480 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002481 "update vlan stripping failed, err %s aq_err %s\n",
2482 i40e_stat_str(&vsi->back->hw, ret),
2483 i40e_aq_str(&vsi->back->hw,
2484 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002485 }
2486}
2487
2488/**
2489 * i40e_vlan_rx_register - Setup or shutdown vlan offload
2490 * @netdev: network interface to be adjusted
2491 * @features: netdev features to test if VLAN offload is enabled or not
2492 **/
2493static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
2494{
2495 struct i40e_netdev_priv *np = netdev_priv(netdev);
2496 struct i40e_vsi *vsi = np->vsi;
2497
2498 if (features & NETIF_F_HW_VLAN_CTAG_RX)
2499 i40e_vlan_stripping_enable(vsi);
2500 else
2501 i40e_vlan_stripping_disable(vsi);
2502}
2503
2504/**
2505 * i40e_vsi_add_vlan - Add vsi membership for given vlan
2506 * @vsi: the vsi being configured
2507 * @vid: vlan id to be added (0 = untagged only , -1 = any)
2508 **/
2509int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
2510{
Jacob Keller278e7d02016-10-05 09:30:37 -07002511 struct i40e_mac_filter *f, *add_f, *del_f;
2512 struct hlist_node *h;
2513 int bkt;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002514
Kiran Patil21659032015-09-30 14:09:03 -04002515 /* Locked once because all functions invoked below iterates list*/
Jacob Keller278e7d02016-10-05 09:30:37 -07002516 spin_lock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -04002517
Jacob Keller278e7d02016-10-05 09:30:37 -07002518 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Jacob Keller57b341d2016-10-05 09:30:35 -07002519 if (f->state == I40E_FILTER_REMOVE)
2520 continue;
Jacob Keller1bc87e82016-10-05 09:30:31 -07002521 add_f = i40e_add_filter(vsi, f->macaddr, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002522 if (!add_f) {
2523 dev_info(&vsi->back->pdev->dev,
2524 "Could not add vlan filter %d for %pM\n",
2525 vid, f->macaddr);
Jacob Keller278e7d02016-10-05 09:30:37 -07002526 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002527 return -ENOMEM;
2528 }
2529 }
2530
Jacob Keller3c7cbd42016-11-08 13:05:17 -08002531 /* When we add a new VLAN filter, we need to make sure that all existing
2532 * filters which are marked as vid=-1 (I40E_VLAN_ANY) are converted to
2533 * vid=0. The simplest way is just search for all filters marked as
2534 * vid=-1 and replace them with vid=0. This converts all filters that
2535 * were marked to receive all traffic (tagged or untagged) into
2536 * filters to receive only untagged traffic, so that we don't receive
2537 * tagged traffic for VLANs which we have not configured.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002538 */
Greg Rose8d82a7c2014-01-13 16:13:04 -08002539 if (vid > 0 && !vsi->info.pvid) {
Jacob Keller278e7d02016-10-05 09:30:37 -07002540 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Jacob Keller57b341d2016-10-05 09:30:35 -07002541 if (f->state == I40E_FILTER_REMOVE)
2542 continue;
Jacob Keller290d2552016-10-05 09:30:36 -07002543 del_f = i40e_find_filter(vsi, f->macaddr,
2544 I40E_VLAN_ANY);
2545 if (!del_f)
Kiran Patil21659032015-09-30 14:09:03 -04002546 continue;
Jacob Keller290d2552016-10-05 09:30:36 -07002547 __i40e_del_filter(vsi, del_f);
Jacob Keller1bc87e82016-10-05 09:30:31 -07002548 add_f = i40e_add_filter(vsi, f->macaddr, 0);
Kiran Patil21659032015-09-30 14:09:03 -04002549 if (!add_f) {
2550 dev_info(&vsi->back->pdev->dev,
2551 "Could not add filter 0 for %pM\n",
2552 f->macaddr);
Jacob Keller278e7d02016-10-05 09:30:37 -07002553 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -04002554 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002555 }
2556 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002557 }
2558
Jacob Keller278e7d02016-10-05 09:30:37 -07002559 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -04002560
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002561 /* schedule our worker thread which will take care of
2562 * applying the new filter changes
2563 */
2564 i40e_service_event_schedule(vsi->back);
2565 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002566}
2567
2568/**
2569 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
2570 * @vsi: the vsi being configured
2571 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
2572 **/
Filip Sadowski3aa7b742016-10-11 15:26:58 -07002573void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002574{
Alan Brady84f5ca62016-10-05 09:30:39 -07002575 struct i40e_mac_filter *f;
Jacob Keller278e7d02016-10-05 09:30:37 -07002576 struct hlist_node *h;
Jacob Keller278e7d02016-10-05 09:30:37 -07002577 int bkt;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002578
Kiran Patil21659032015-09-30 14:09:03 -04002579 /* Locked once because all functions invoked below iterates list */
Jacob Keller278e7d02016-10-05 09:30:37 -07002580 spin_lock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -04002581
Jacob Keller278e7d02016-10-05 09:30:37 -07002582 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Jacob Keller290d2552016-10-05 09:30:36 -07002583 if (f->vlan == vid)
2584 __i40e_del_filter(vsi, f);
2585 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002586
Jacob Keller278e7d02016-10-05 09:30:37 -07002587 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -04002588
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002589 /* schedule our worker thread which will take care of
2590 * applying the new filter changes
2591 */
2592 i40e_service_event_schedule(vsi->back);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002593}
2594
2595/**
2596 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2597 * @netdev: network interface to be adjusted
2598 * @vid: vlan id to be added
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002599 *
2600 * net_device_ops implementation for adding vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002601 **/
Vasu Dev38e00432014-08-01 13:27:03 -07002602#ifdef I40E_FCOE
2603int i40e_vlan_rx_add_vid(struct net_device *netdev,
2604 __always_unused __be16 proto, u16 vid)
2605#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002606static int i40e_vlan_rx_add_vid(struct net_device *netdev,
2607 __always_unused __be16 proto, u16 vid)
Vasu Dev38e00432014-08-01 13:27:03 -07002608#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002609{
2610 struct i40e_netdev_priv *np = netdev_priv(netdev);
2611 struct i40e_vsi *vsi = np->vsi;
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002612 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002613
Jacob Keller6a1127852016-10-25 16:08:49 -07002614 if (vid >= VLAN_N_VID)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002615 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002616
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002617 /* If the network stack called us with vid = 0 then
2618 * it is asking to receive priority tagged packets with
2619 * vlan id 0. Our HW receives them by default when configured
2620 * to receive untagged packets so there is no need to add an
2621 * extra filter for vlan 0 tagged packets.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002622 */
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002623 if (vid)
2624 ret = i40e_vsi_add_vlan(vsi, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002625
Jacob Keller6a1127852016-10-25 16:08:49 -07002626 if (!ret)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002627 set_bit(vid, vsi->active_vlans);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002628
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002629 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002630}
2631
2632/**
2633 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2634 * @netdev: network interface to be adjusted
2635 * @vid: vlan id to be removed
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002636 *
Akeem G Abodunrinfdfd9432014-02-11 08:24:15 +00002637 * net_device_ops implementation for removing vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002638 **/
Vasu Dev38e00432014-08-01 13:27:03 -07002639#ifdef I40E_FCOE
2640int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2641 __always_unused __be16 proto, u16 vid)
2642#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002643static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2644 __always_unused __be16 proto, u16 vid)
Vasu Dev38e00432014-08-01 13:27:03 -07002645#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002646{
2647 struct i40e_netdev_priv *np = netdev_priv(netdev);
2648 struct i40e_vsi *vsi = np->vsi;
2649
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002650 /* return code is ignored as there is nothing a user
2651 * can do about failure to remove and a log message was
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002652 * already printed from the other function
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002653 */
2654 i40e_vsi_kill_vlan(vsi, vid);
2655
2656 clear_bit(vid, vsi->active_vlans);
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002657
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002658 return 0;
2659}
2660
2661/**
Tushar Daveb1b15df2016-07-01 10:11:20 -07002662 * i40e_macaddr_init - explicitly write the mac address filters
2663 *
2664 * @vsi: pointer to the vsi
2665 * @macaddr: the MAC address
2666 *
2667 * This is needed when the macaddr has been obtained by other
2668 * means than the default, e.g., from Open Firmware or IDPROM.
2669 * Returns 0 on success, negative on failure
2670 **/
2671static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr)
2672{
2673 int ret;
2674 struct i40e_aqc_add_macvlan_element_data element;
2675
2676 ret = i40e_aq_mac_address_write(&vsi->back->hw,
2677 I40E_AQC_WRITE_TYPE_LAA_WOL,
2678 macaddr, NULL);
2679 if (ret) {
2680 dev_info(&vsi->back->pdev->dev,
2681 "Addr change for VSI failed: %d\n", ret);
2682 return -EADDRNOTAVAIL;
2683 }
2684
2685 memset(&element, 0, sizeof(element));
2686 ether_addr_copy(element.mac_addr, macaddr);
2687 element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
2688 ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL);
2689 if (ret) {
2690 dev_info(&vsi->back->pdev->dev,
2691 "add filter failed err %s aq_err %s\n",
2692 i40e_stat_str(&vsi->back->hw, ret),
2693 i40e_aq_str(&vsi->back->hw,
2694 vsi->back->hw.aq.asq_last_status));
2695 }
2696 return ret;
2697}
2698
2699/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002700 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2701 * @vsi: the vsi being brought back up
2702 **/
2703static void i40e_restore_vlan(struct i40e_vsi *vsi)
2704{
2705 u16 vid;
2706
2707 if (!vsi->netdev)
2708 return;
2709
2710 i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
2711
2712 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
2713 i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
2714 vid);
2715}
2716
2717/**
2718 * i40e_vsi_add_pvid - Add pvid for the VSI
2719 * @vsi: the vsi being adjusted
2720 * @vid: the vlan id to set as a PVID
2721 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002722int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002723{
2724 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002725 i40e_status ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002726
2727 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2728 vsi->info.pvid = cpu_to_le16(vid);
Greg Rose6c12fcb2013-11-28 06:39:34 +00002729 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
2730 I40E_AQ_VSI_PVLAN_INSERT_PVID |
Greg Roseb774c7d2013-11-28 06:39:44 +00002731 I40E_AQ_VSI_PVLAN_EMOD_STR;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002732
2733 ctxt.seid = vsi->seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07002734 ctxt.info = vsi->info;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002735 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2736 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002737 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04002738 "add pvid failed, err %s aq_err %s\n",
2739 i40e_stat_str(&vsi->back->hw, ret),
2740 i40e_aq_str(&vsi->back->hw,
2741 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002742 return -ENOENT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002743 }
2744
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002745 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002746}
2747
2748/**
2749 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2750 * @vsi: the vsi being adjusted
2751 *
2752 * Just use the vlan_rx_register() service to put it back to normal
2753 **/
2754void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
2755{
Greg Rose6c12fcb2013-11-28 06:39:34 +00002756 i40e_vlan_stripping_disable(vsi);
2757
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002758 vsi->info.pvid = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002759}
2760
2761/**
2762 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2763 * @vsi: ptr to the VSI
2764 *
2765 * If this function returns with an error, then it's possible one or
2766 * more of the rings is populated (while the rest are not). It is the
2767 * callers duty to clean those orphaned rings.
2768 *
2769 * Return 0 on success, negative on failure
2770 **/
2771static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
2772{
2773 int i, err = 0;
2774
2775 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002776 err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002777
2778 return err;
2779}
2780
2781/**
2782 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2783 * @vsi: ptr to the VSI
2784 *
2785 * Free VSI's transmit software resources
2786 **/
2787static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
2788{
2789 int i;
2790
Greg Rose8e9dca52013-12-18 13:45:53 +00002791 if (!vsi->tx_rings)
2792 return;
2793
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002794 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002795 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002796 i40e_free_tx_resources(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002797}
2798
2799/**
2800 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2801 * @vsi: ptr to the VSI
2802 *
2803 * If this function returns with an error, then it's possible one or
2804 * more of the rings is populated (while the rest are not). It is the
2805 * callers duty to clean those orphaned rings.
2806 *
2807 * Return 0 on success, negative on failure
2808 **/
2809static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
2810{
2811 int i, err = 0;
2812
2813 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002814 err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
Vasu Dev38e00432014-08-01 13:27:03 -07002815#ifdef I40E_FCOE
2816 i40e_fcoe_setup_ddp_resources(vsi);
2817#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002818 return err;
2819}
2820
2821/**
2822 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2823 * @vsi: ptr to the VSI
2824 *
2825 * Free all receive software resources
2826 **/
2827static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
2828{
2829 int i;
2830
Greg Rose8e9dca52013-12-18 13:45:53 +00002831 if (!vsi->rx_rings)
2832 return;
2833
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002834 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002835 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
Alexander Duyck9f65e152013-09-28 06:00:58 +00002836 i40e_free_rx_resources(vsi->rx_rings[i]);
Vasu Dev38e00432014-08-01 13:27:03 -07002837#ifdef I40E_FCOE
2838 i40e_fcoe_free_ddp_resources(vsi);
2839#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002840}
2841
2842/**
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002843 * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
2844 * @ring: The Tx ring to configure
2845 *
2846 * This enables/disables XPS for a given Tx descriptor ring
2847 * based on the TCs enabled for the VSI that ring belongs to.
2848 **/
2849static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
2850{
2851 struct i40e_vsi *vsi = ring->vsi;
2852 cpumask_var_t mask;
2853
Jesse Brandeburg9a660ee2015-02-26 16:13:22 +00002854 if (!ring->q_vector || !ring->netdev)
2855 return;
2856
2857 /* Single TC mode enable XPS */
2858 if (vsi->tc_config.numtc <= 1) {
2859 if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002860 netif_set_xps_queue(ring->netdev,
2861 &ring->q_vector->affinity_mask,
2862 ring->queue_index);
Jesse Brandeburg9a660ee2015-02-26 16:13:22 +00002863 } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) {
2864 /* Disable XPS to allow selection based on TC */
2865 bitmap_zero(cpumask_bits(mask), nr_cpumask_bits);
2866 netif_set_xps_queue(ring->netdev, mask, ring->queue_index);
2867 free_cpumask_var(mask);
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002868 }
Jesse Brandeburg0e4425e2015-11-05 17:01:01 -08002869
2870 /* schedule our worker thread which will take care of
2871 * applying the new filter changes
2872 */
2873 i40e_service_event_schedule(vsi->back);
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002874}
2875
2876/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002877 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2878 * @ring: The Tx ring to configure
2879 *
2880 * Configure the Tx descriptor ring in the HMC context.
2881 **/
2882static int i40e_configure_tx_ring(struct i40e_ring *ring)
2883{
2884 struct i40e_vsi *vsi = ring->vsi;
2885 u16 pf_q = vsi->base_queue + ring->queue_index;
2886 struct i40e_hw *hw = &vsi->back->hw;
2887 struct i40e_hmc_obj_txq tx_ctx;
2888 i40e_status err = 0;
2889 u32 qtx_ctl = 0;
2890
2891 /* some ATR related tx ring init */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002892 if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002893 ring->atr_sample_rate = vsi->back->atr_sample_rate;
2894 ring->atr_count = 0;
2895 } else {
2896 ring->atr_sample_rate = 0;
2897 }
2898
Neerav Parikh3ffa0372014-11-12 00:19:02 +00002899 /* configure XPS */
2900 i40e_config_xps_tx_ring(ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002901
2902 /* clear the context structure first */
2903 memset(&tx_ctx, 0, sizeof(tx_ctx));
2904
2905 tx_ctx.new_context = 1;
2906 tx_ctx.base = (ring->dma / 128);
2907 tx_ctx.qlen = ring->count;
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002908 tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
2909 I40E_FLAG_FD_ATR_ENABLED));
Vasu Dev38e00432014-08-01 13:27:03 -07002910#ifdef I40E_FCOE
2911 tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
2912#endif
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002913 tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
Jesse Brandeburg1943d8b2014-02-14 02:14:40 +00002914 /* FDIR VSI tx ring can still use RS bit and writebacks */
2915 if (vsi->type != I40E_VSI_FDIR)
2916 tx_ctx.head_wb_ena = 1;
2917 tx_ctx.head_wb_addr = ring->dma +
2918 (ring->count * sizeof(struct i40e_tx_desc));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002919
2920 /* As part of VSI creation/update, FW allocates certain
2921 * Tx arbitration queue sets for each TC enabled for
2922 * the VSI. The FW returns the handles to these queue
2923 * sets as part of the response buffer to Add VSI,
2924 * Update VSI, etc. AQ commands. It is expected that
2925 * these queue set handles be associated with the Tx
2926 * queues by the driver as part of the TX queue context
2927 * initialization. This has to be done regardless of
2928 * DCB as by default everything is mapped to TC0.
2929 */
2930 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
2931 tx_ctx.rdylist_act = 0;
2932
2933 /* clear the context in the HMC */
2934 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2935 if (err) {
2936 dev_info(&vsi->back->pdev->dev,
2937 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2938 ring->queue_index, pf_q, err);
2939 return -ENOMEM;
2940 }
2941
2942 /* set the context in the HMC */
2943 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
2944 if (err) {
2945 dev_info(&vsi->back->pdev->dev,
2946 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2947 ring->queue_index, pf_q, err);
2948 return -ENOMEM;
2949 }
2950
2951 /* Now associate this queue with this PCI function */
Mitch Williams7a28d882014-10-17 03:14:52 +00002952 if (vsi->type == I40E_VSI_VMDQ2) {
Shannon Nelson9d8bf542014-01-14 00:49:50 -08002953 qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
Mitch Williams7a28d882014-10-17 03:14:52 +00002954 qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
2955 I40E_QTX_CTL_VFVM_INDX_MASK;
2956 } else {
Shannon Nelson9d8bf542014-01-14 00:49:50 -08002957 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
Mitch Williams7a28d882014-10-17 03:14:52 +00002958 }
2959
Shannon Nelson13fd977492013-09-28 07:14:19 +00002960 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
2961 I40E_QTX_CTL_PF_INDX_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002962 wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
2963 i40e_flush(hw);
2964
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002965 /* cache tail off for easier writes later */
2966 ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2967
2968 return 0;
2969}
2970
2971/**
2972 * i40e_configure_rx_ring - Configure a receive ring context
2973 * @ring: The Rx ring to configure
2974 *
2975 * Configure the Rx descriptor ring in the HMC context.
2976 **/
2977static int i40e_configure_rx_ring(struct i40e_ring *ring)
2978{
2979 struct i40e_vsi *vsi = ring->vsi;
2980 u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
2981 u16 pf_q = vsi->base_queue + ring->queue_index;
2982 struct i40e_hw *hw = &vsi->back->hw;
2983 struct i40e_hmc_obj_rxq rx_ctx;
2984 i40e_status err = 0;
2985
2986 ring->state = 0;
2987
2988 /* clear the context structure first */
2989 memset(&rx_ctx, 0, sizeof(rx_ctx));
2990
2991 ring->rx_buf_len = vsi->rx_buf_len;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002992
2993 rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002994
2995 rx_ctx.base = (ring->dma / 128);
2996 rx_ctx.qlen = ring->count;
2997
Jesse Brandeburgbec60fc2016-04-18 11:33:47 -07002998 /* use 32 byte descriptors */
2999 rx_ctx.dsize = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003000
Jesse Brandeburgbec60fc2016-04-18 11:33:47 -07003001 /* descriptor type is always zero
3002 * rx_ctx.dtype = 0;
3003 */
Jesse Brandeburgb32bfa12016-04-18 11:33:42 -07003004 rx_ctx.hsplit_0 = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003005
Jesse Brandeburgb32bfa12016-04-18 11:33:42 -07003006 rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003007 if (hw->revision_id == 0)
3008 rx_ctx.lrxqthresh = 0;
3009 else
3010 rx_ctx.lrxqthresh = 2;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003011 rx_ctx.crcstrip = 1;
3012 rx_ctx.l2tsel = 1;
Jesse Brandeburgc4bbac32015-09-28 11:21:48 -07003013 /* this controls whether VLAN is stripped from inner headers */
3014 rx_ctx.showiv = 0;
Vasu Dev38e00432014-08-01 13:27:03 -07003015#ifdef I40E_FCOE
3016 rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
3017#endif
Catherine Sullivanacb36762014-03-06 09:02:30 +00003018 /* set the prefena field to 1 because the manual says to */
3019 rx_ctx.prefena = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003020
3021 /* clear the context in the HMC */
3022 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
3023 if (err) {
3024 dev_info(&vsi->back->pdev->dev,
3025 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3026 ring->queue_index, pf_q, err);
3027 return -ENOMEM;
3028 }
3029
3030 /* set the context in the HMC */
3031 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
3032 if (err) {
3033 dev_info(&vsi->back->pdev->dev,
3034 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
3035 ring->queue_index, pf_q, err);
3036 return -ENOMEM;
3037 }
3038
3039 /* cache tail for quicker writes, and clear the reg before use */
3040 ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
3041 writel(0, ring->tail);
3042
Jesse Brandeburg1a557afc2016-04-20 19:43:37 -07003043 i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003044
3045 return 0;
3046}
3047
3048/**
3049 * i40e_vsi_configure_tx - Configure the VSI for Tx
3050 * @vsi: VSI structure describing this set of rings and resources
3051 *
3052 * Configure the Tx VSI for operation.
3053 **/
3054static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
3055{
3056 int err = 0;
3057 u16 i;
3058
Alexander Duyck9f65e152013-09-28 06:00:58 +00003059 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
3060 err = i40e_configure_tx_ring(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003061
3062 return err;
3063}
3064
3065/**
3066 * i40e_vsi_configure_rx - Configure the VSI for Rx
3067 * @vsi: the VSI being configured
3068 *
3069 * Configure the Rx VSI for operation.
3070 **/
3071static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
3072{
3073 int err = 0;
3074 u16 i;
3075
3076 if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
3077 vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
3078 + ETH_FCS_LEN + VLAN_HLEN;
3079 else
3080 vsi->max_frame = I40E_RXBUFFER_2048;
3081
Jesse Brandeburg1a557afc2016-04-20 19:43:37 -07003082 vsi->rx_buf_len = I40E_RXBUFFER_2048;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003083
Vasu Dev38e00432014-08-01 13:27:03 -07003084#ifdef I40E_FCOE
3085 /* setup rx buffer for FCoE */
3086 if ((vsi->type == I40E_VSI_FCOE) &&
3087 (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) {
Vasu Dev38e00432014-08-01 13:27:03 -07003088 vsi->rx_buf_len = I40E_RXBUFFER_3072;
3089 vsi->max_frame = I40E_RXBUFFER_3072;
Vasu Dev38e00432014-08-01 13:27:03 -07003090 }
3091
3092#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003093 /* round up for the chip's needs */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003094 vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04003095 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003096
3097 /* set up individual rings */
3098 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e152013-09-28 06:00:58 +00003099 err = i40e_configure_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003100
3101 return err;
3102}
3103
3104/**
3105 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
3106 * @vsi: ptr to the VSI
3107 **/
3108static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
3109{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00003110 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003111 u16 qoffset, qcount;
3112 int i, n;
3113
Parikh, Neeravcd238a32015-02-21 06:43:37 +00003114 if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
3115 /* Reset the TC information */
3116 for (i = 0; i < vsi->num_queue_pairs; i++) {
3117 rx_ring = vsi->rx_rings[i];
3118 tx_ring = vsi->tx_rings[i];
3119 rx_ring->dcb_tc = 0;
3120 tx_ring->dcb_tc = 0;
3121 }
3122 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003123
3124 for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04003125 if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003126 continue;
3127
3128 qoffset = vsi->tc_config.tc_info[n].qoffset;
3129 qcount = vsi->tc_config.tc_info[n].qcount;
3130 for (i = qoffset; i < (qoffset + qcount); i++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00003131 rx_ring = vsi->rx_rings[i];
3132 tx_ring = vsi->tx_rings[i];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003133 rx_ring->dcb_tc = n;
3134 tx_ring->dcb_tc = n;
3135 }
3136 }
3137}
3138
3139/**
3140 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
3141 * @vsi: ptr to the VSI
3142 **/
3143static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
3144{
Tushar Daveb1b15df2016-07-01 10:11:20 -07003145 struct i40e_pf *pf = vsi->back;
3146 int err;
3147
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003148 if (vsi->netdev)
3149 i40e_set_rx_mode(vsi->netdev);
Tushar Daveb1b15df2016-07-01 10:11:20 -07003150
3151 if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
3152 err = i40e_macaddr_init(vsi, pf->hw.mac.addr);
3153 if (err) {
3154 dev_warn(&pf->pdev->dev,
3155 "could not set up macaddr; err %d\n", err);
3156 }
3157 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003158}
3159
3160/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003161 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
3162 * @vsi: Pointer to the targeted VSI
3163 *
3164 * This function replays the hlist on the hw where all the SB Flow Director
3165 * filters were saved.
3166 **/
3167static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
3168{
3169 struct i40e_fdir_filter *filter;
3170 struct i40e_pf *pf = vsi->back;
3171 struct hlist_node *node;
3172
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003173 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3174 return;
3175
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003176 hlist_for_each_entry_safe(filter, node,
3177 &pf->fdir_filter_list, fdir_node) {
3178 i40e_add_del_fdir(vsi, filter, true);
3179 }
3180}
3181
3182/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003183 * i40e_vsi_configure - Set up the VSI for action
3184 * @vsi: the VSI being configured
3185 **/
3186static int i40e_vsi_configure(struct i40e_vsi *vsi)
3187{
3188 int err;
3189
3190 i40e_set_vsi_rx_mode(vsi);
3191 i40e_restore_vlan(vsi);
3192 i40e_vsi_config_dcb_rings(vsi);
3193 err = i40e_vsi_configure_tx(vsi);
3194 if (!err)
3195 err = i40e_vsi_configure_rx(vsi);
3196
3197 return err;
3198}
3199
3200/**
3201 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
3202 * @vsi: the VSI being configured
3203 **/
3204static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
3205{
3206 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003207 struct i40e_hw *hw = &pf->hw;
3208 u16 vector;
3209 int i, q;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003210 u32 qp;
3211
3212 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
3213 * and PFINT_LNKLSTn registers, e.g.:
3214 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
3215 */
3216 qp = vsi->base_queue;
3217 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +00003218 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003219 struct i40e_q_vector *q_vector = vsi->q_vectors[i];
3220
Jesse Brandeburgee2319c2015-09-28 14:16:54 -04003221 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Kan Lianga75e8002016-02-19 09:24:04 -05003222 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003223 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3224 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
3225 q_vector->rx.itr);
Kan Lianga75e8002016-02-19 09:24:04 -05003226 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003227 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3228 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
3229 q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003230 wr32(hw, I40E_PFINT_RATEN(vector - 1),
3231 INTRL_USEC_TO_REG(vsi->int_rate_limit));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003232
3233 /* Linked list for the queuepairs assigned to this vector */
3234 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
3235 for (q = 0; q < q_vector->num_ringpairs; q++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04003236 u32 val;
3237
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003238 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3239 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3240 (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
3241 (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
3242 (I40E_QUEUE_TYPE_TX
3243 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
3244
3245 wr32(hw, I40E_QINT_RQCTL(qp), val);
3246
3247 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3248 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3249 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
3250 ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
3251 (I40E_QUEUE_TYPE_RX
3252 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3253
3254 /* Terminate the linked list */
3255 if (q == (q_vector->num_ringpairs - 1))
3256 val |= (I40E_QUEUE_END_OF_LIST
3257 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3258
3259 wr32(hw, I40E_QINT_TQCTL(qp), val);
3260 qp++;
3261 }
3262 }
3263
3264 i40e_flush(hw);
3265}
3266
3267/**
3268 * i40e_enable_misc_int_causes - enable the non-queue interrupts
3269 * @hw: ptr to the hardware info
3270 **/
Jacob Kellerab437b52014-12-14 01:55:08 +00003271static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003272{
Jacob Kellerab437b52014-12-14 01:55:08 +00003273 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003274 u32 val;
3275
3276 /* clear things first */
3277 wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
3278 rd32(hw, I40E_PFINT_ICR0); /* read to clear */
3279
3280 val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
3281 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
3282 I40E_PFINT_ICR0_ENA_GRST_MASK |
3283 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
3284 I40E_PFINT_ICR0_ENA_GPIO_MASK |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003285 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
3286 I40E_PFINT_ICR0_ENA_VFLR_MASK |
3287 I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3288
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003289 if (pf->flags & I40E_FLAG_IWARP_ENABLED)
3290 val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3291
Jacob Kellerab437b52014-12-14 01:55:08 +00003292 if (pf->flags & I40E_FLAG_PTP)
3293 val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
3294
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003295 wr32(hw, I40E_PFINT_ICR0_ENA, val);
3296
3297 /* SW_ITR_IDX = 0, but don't change INTENA */
Anjali Singhai Jain84ed40e2013-11-26 10:49:32 +00003298 wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
3299 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003300
3301 /* OTHER_ITR_IDX = 0 */
3302 wr32(hw, I40E_PFINT_STAT_CTL0, 0);
3303}
3304
3305/**
3306 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
3307 * @vsi: the VSI being configured
3308 **/
3309static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
3310{
Alexander Duyck493fb302013-09-28 07:01:44 +00003311 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003312 struct i40e_pf *pf = vsi->back;
3313 struct i40e_hw *hw = &pf->hw;
3314 u32 val;
3315
3316 /* set the ITR configuration */
Jesse Brandeburgee2319c2015-09-28 14:16:54 -04003317 q_vector->itr_countdown = ITR_COUNTDOWN_START;
Kan Lianga75e8002016-02-19 09:24:04 -05003318 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003319 q_vector->rx.latency_range = I40E_LOW_LATENCY;
3320 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
Kan Lianga75e8002016-02-19 09:24:04 -05003321 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003322 q_vector->tx.latency_range = I40E_LOW_LATENCY;
3323 wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
3324
Jacob Kellerab437b52014-12-14 01:55:08 +00003325 i40e_enable_misc_int_causes(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003326
3327 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
3328 wr32(hw, I40E_PFINT_LNKLST0, 0);
3329
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00003330 /* Associate the queue pair to the vector and enable the queue int */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003331 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3332 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
3333 (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
3334
3335 wr32(hw, I40E_QINT_RQCTL(0), val);
3336
3337 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3338 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
3339 (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
3340
3341 wr32(hw, I40E_QINT_TQCTL(0), val);
3342 i40e_flush(hw);
3343}
3344
3345/**
Mitch Williams2ef28cf2013-11-28 06:39:32 +00003346 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
3347 * @pf: board private structure
3348 **/
3349void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
3350{
3351 struct i40e_hw *hw = &pf->hw;
3352
3353 wr32(hw, I40E_PFINT_DYN_CTL0,
3354 I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
3355 i40e_flush(hw);
3356}
3357
3358/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003359 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
3360 * @pf: board private structure
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003361 * @clearpba: true when all pending interrupt events should be cleared
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003362 **/
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003363void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003364{
3365 struct i40e_hw *hw = &pf->hw;
3366 u32 val;
3367
3368 val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003369 (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003370 (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
3371
3372 wr32(hw, I40E_PFINT_DYN_CTL0, val);
3373 i40e_flush(hw);
3374}
3375
3376/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003377 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
3378 * @irq: interrupt number
3379 * @data: pointer to a q_vector
3380 **/
3381static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
3382{
3383 struct i40e_q_vector *q_vector = data;
3384
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003385 if (!q_vector->tx.ring && !q_vector->rx.ring)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003386 return IRQ_HANDLED;
3387
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003388 napi_schedule_irqoff(&q_vector->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003389
3390 return IRQ_HANDLED;
3391}
3392
3393/**
Alan Brady96db7762016-09-14 16:24:38 -07003394 * i40e_irq_affinity_notify - Callback for affinity changes
3395 * @notify: context as to what irq was changed
3396 * @mask: the new affinity mask
3397 *
3398 * This is a callback function used by the irq_set_affinity_notifier function
3399 * so that we may register to receive changes to the irq affinity masks.
3400 **/
3401static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
3402 const cpumask_t *mask)
3403{
3404 struct i40e_q_vector *q_vector =
3405 container_of(notify, struct i40e_q_vector, affinity_notify);
3406
3407 q_vector->affinity_mask = *mask;
3408}
3409
3410/**
3411 * i40e_irq_affinity_release - Callback for affinity notifier release
3412 * @ref: internal core kernel usage
3413 *
3414 * This is a callback function used by the irq_set_affinity_notifier function
3415 * to inform the current notification subscriber that they will no longer
3416 * receive notifications.
3417 **/
3418static void i40e_irq_affinity_release(struct kref *ref) {}
3419
3420/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003421 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
3422 * @vsi: the VSI being configured
3423 * @basename: name for the vector
3424 *
3425 * Allocates MSI-X vectors and requests interrupts from the kernel.
3426 **/
3427static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
3428{
3429 int q_vectors = vsi->num_q_vectors;
3430 struct i40e_pf *pf = vsi->back;
3431 int base = vsi->base_vector;
3432 int rx_int_idx = 0;
3433 int tx_int_idx = 0;
3434 int vector, err;
Alan Brady96db7762016-09-14 16:24:38 -07003435 int irq_num;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003436
3437 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck493fb302013-09-28 07:01:44 +00003438 struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003439
Alan Brady96db7762016-09-14 16:24:38 -07003440 irq_num = pf->msix_entries[base + vector].vector;
3441
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003442 if (q_vector->tx.ring && q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003443 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3444 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
3445 tx_int_idx++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003446 } else if (q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003447 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3448 "%s-%s-%d", basename, "rx", rx_int_idx++);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003449 } else if (q_vector->tx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003450 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
3451 "%s-%s-%d", basename, "tx", tx_int_idx++);
3452 } else {
3453 /* skip this unused q_vector */
3454 continue;
3455 }
Alan Brady96db7762016-09-14 16:24:38 -07003456 err = request_irq(irq_num,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003457 vsi->irq_handler,
3458 0,
3459 q_vector->name,
3460 q_vector);
3461 if (err) {
3462 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003463 "MSIX request_irq failed, error: %d\n", err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003464 goto free_queue_irqs;
3465 }
Alan Brady96db7762016-09-14 16:24:38 -07003466
3467 /* register for affinity change notifications */
3468 q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
3469 q_vector->affinity_notify.release = i40e_irq_affinity_release;
3470 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003471 /* assign the mask for this irq */
Alan Brady96db7762016-09-14 16:24:38 -07003472 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003473 }
3474
Shannon Nelson63741842014-04-23 04:50:16 +00003475 vsi->irqs_ready = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003476 return 0;
3477
3478free_queue_irqs:
3479 while (vector) {
3480 vector--;
Alan Brady96db7762016-09-14 16:24:38 -07003481 irq_num = pf->msix_entries[base + vector].vector;
3482 irq_set_affinity_notifier(irq_num, NULL);
3483 irq_set_affinity_hint(irq_num, NULL);
3484 free_irq(irq_num, &vsi->q_vectors[vector]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003485 }
3486 return err;
3487}
3488
3489/**
3490 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
3491 * @vsi: the VSI being un-configured
3492 **/
3493static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
3494{
3495 struct i40e_pf *pf = vsi->back;
3496 struct i40e_hw *hw = &pf->hw;
3497 int base = vsi->base_vector;
3498 int i;
3499
3500 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00003501 wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
3502 wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003503 }
3504
3505 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3506 for (i = vsi->base_vector;
3507 i < (vsi->num_q_vectors + vsi->base_vector); i++)
3508 wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
3509
3510 i40e_flush(hw);
3511 for (i = 0; i < vsi->num_q_vectors; i++)
3512 synchronize_irq(pf->msix_entries[i + base].vector);
3513 } else {
3514 /* Legacy and MSI mode - this stops all interrupt handling */
3515 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
3516 wr32(hw, I40E_PFINT_DYN_CTL0, 0);
3517 i40e_flush(hw);
3518 synchronize_irq(pf->pdev->irq);
3519 }
3520}
3521
3522/**
3523 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
3524 * @vsi: the VSI being configured
3525 **/
3526static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
3527{
3528 struct i40e_pf *pf = vsi->back;
3529 int i;
3530
3531 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
Jesse Brandeburg78455482015-07-23 16:54:41 -04003532 for (i = 0; i < vsi->num_q_vectors; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003533 i40e_irq_dynamic_enable(vsi, i);
3534 } else {
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003535 i40e_irq_dynamic_enable_icr0(pf, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003536 }
3537
Jesse Brandeburg1022cb62013-09-28 07:13:08 +00003538 i40e_flush(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003539 return 0;
3540}
3541
3542/**
3543 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
3544 * @pf: board private structure
3545 **/
3546static void i40e_stop_misc_vector(struct i40e_pf *pf)
3547{
3548 /* Disable ICR 0 */
3549 wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
3550 i40e_flush(&pf->hw);
3551}
3552
3553/**
3554 * i40e_intr - MSI/Legacy and non-queue interrupt handler
3555 * @irq: interrupt number
3556 * @data: pointer to a q_vector
3557 *
3558 * This is the handler used for all MSI/Legacy interrupts, and deals
3559 * with both queue and non-queue interrupts. This is also used in
3560 * MSIX mode to handle the non-queue interrupts.
3561 **/
3562static irqreturn_t i40e_intr(int irq, void *data)
3563{
3564 struct i40e_pf *pf = (struct i40e_pf *)data;
3565 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jain5e8230662013-12-18 13:45:49 +00003566 irqreturn_t ret = IRQ_NONE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003567 u32 icr0, icr0_remaining;
3568 u32 val, ena_mask;
3569
3570 icr0 = rd32(hw, I40E_PFINT_ICR0);
Anjali Singhai Jain5e8230662013-12-18 13:45:49 +00003571 ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003572
Shannon Nelson116a57d2013-09-28 07:13:59 +00003573 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
3574 if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
Anjali Singhai Jain5e8230662013-12-18 13:45:49 +00003575 goto enable_intr;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003576
Shannon Nelsoncd92e722013-11-16 10:00:44 +00003577 /* if interrupt but no bits showing, must be SWINT */
3578 if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
3579 (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
3580 pf->sw_int_count++;
3581
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003582 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
3583 (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
3584 ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
3585 icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
Carolyn Wyborny23bb6dc2016-11-08 13:05:12 -08003586 dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n");
Anjali Singhai Jain0d8e1432015-06-05 12:20:32 -04003587 }
3588
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003589 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
3590 if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003591 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
3592 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003593
Anjali Singhai Jaina16ae2d2016-01-15 14:33:16 -08003594 /* We do not have a way to disarm Queue causes while leaving
3595 * interrupt enabled for all other causes, ideally
3596 * interrupt should be disabled while we are in NAPI but
3597 * this is not a performance path and napi_schedule()
3598 * can deal with rescheduling.
3599 */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003600 if (!test_bit(__I40E_DOWN, &pf->state))
Alexander Duyck5d3465a2015-09-29 15:19:50 -07003601 napi_schedule_irqoff(&q_vector->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003602 }
3603
3604 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
3605 ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
3606 set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08003607 i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003608 }
3609
3610 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
3611 ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
3612 set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
3613 }
3614
3615 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
3616 ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
3617 set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
3618 }
3619
3620 if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
3621 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
3622 set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
3623 ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
3624 val = rd32(hw, I40E_GLGEN_RSTAT);
3625 val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
3626 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003627 if (val == I40E_RESET_CORER) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003628 pf->corer_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003629 } else if (val == I40E_RESET_GLOBR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003630 pf->globr_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003631 } else if (val == I40E_RESET_EMPR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003632 pf->empr_count++;
Anjali Singhai Jain9df42d12015-01-24 09:58:40 +00003633 set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003634 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003635 }
3636
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003637 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
3638 icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
3639 dev_info(&pf->pdev->dev, "HMC error interrupt\n");
Anjali Singhai Jain25fc0e62015-03-31 00:45:01 -07003640 dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
3641 rd32(hw, I40E_PFHMC_ERRORINFO),
3642 rd32(hw, I40E_PFHMC_ERRORDATA));
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003643 }
3644
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003645 if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
3646 u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
3647
3648 if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
Jacob Kellercafa1fc2014-04-24 18:05:03 -07003649 icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003650 i40e_ptp_tx_hwtstamp(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003651 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003652 }
3653
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003654 /* If a critical error is pending we have no choice but to reset the
3655 * device.
3656 * Report and mask out any remaining unexpected interrupts.
3657 */
3658 icr0_remaining = icr0 & ena_mask;
3659 if (icr0_remaining) {
3660 dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
3661 icr0_remaining);
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003662 if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003663 (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
Anjali Singhai Jainc0c28972014-02-12 01:45:34 +00003664 (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003665 dev_info(&pf->pdev->dev, "device will be reset\n");
3666 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
3667 i40e_service_event_schedule(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003668 }
3669 ena_mask &= ~icr0_remaining;
3670 }
Anjali Singhai Jain5e8230662013-12-18 13:45:49 +00003671 ret = IRQ_HANDLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003672
Anjali Singhai Jain5e8230662013-12-18 13:45:49 +00003673enable_intr:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003674 /* re-enable interrupt causes */
3675 wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003676 if (!test_bit(__I40E_DOWN, &pf->state)) {
3677 i40e_service_event_schedule(pf);
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08003678 i40e_irq_dynamic_enable_icr0(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003679 }
3680
Anjali Singhai Jain5e8230662013-12-18 13:45:49 +00003681 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003682}
3683
3684/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003685 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3686 * @tx_ring: tx ring to clean
3687 * @budget: how many cleans we're allowed
3688 *
3689 * Returns true if there's any budget left (e.g. the clean is finished)
3690 **/
3691static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
3692{
3693 struct i40e_vsi *vsi = tx_ring->vsi;
3694 u16 i = tx_ring->next_to_clean;
3695 struct i40e_tx_buffer *tx_buf;
3696 struct i40e_tx_desc *tx_desc;
3697
3698 tx_buf = &tx_ring->tx_bi[i];
3699 tx_desc = I40E_TX_DESC(tx_ring, i);
3700 i -= tx_ring->count;
3701
3702 do {
3703 struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
3704
3705 /* if next_to_watch is not set then there is no work pending */
3706 if (!eop_desc)
3707 break;
3708
3709 /* prevent any other reads prior to eop_desc */
3710 read_barrier_depends();
3711
3712 /* if the descriptor isn't done, no work yet to do */
3713 if (!(eop_desc->cmd_type_offset_bsz &
3714 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
3715 break;
3716
3717 /* clear next_to_watch to prevent false hangs */
3718 tx_buf->next_to_watch = NULL;
3719
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003720 tx_desc->buffer_addr = 0;
3721 tx_desc->cmd_type_offset_bsz = 0;
3722 /* move past filter desc */
3723 tx_buf++;
3724 tx_desc++;
3725 i++;
3726 if (unlikely(!i)) {
3727 i -= tx_ring->count;
3728 tx_buf = tx_ring->tx_bi;
3729 tx_desc = I40E_TX_DESC(tx_ring, 0);
3730 }
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003731 /* unmap skb header data */
3732 dma_unmap_single(tx_ring->dev,
3733 dma_unmap_addr(tx_buf, dma),
3734 dma_unmap_len(tx_buf, len),
3735 DMA_TO_DEVICE);
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003736 if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
3737 kfree(tx_buf->raw_buf);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003738
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003739 tx_buf->raw_buf = NULL;
3740 tx_buf->tx_flags = 0;
3741 tx_buf->next_to_watch = NULL;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003742 dma_unmap_len_set(tx_buf, len, 0);
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003743 tx_desc->buffer_addr = 0;
3744 tx_desc->cmd_type_offset_bsz = 0;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003745
Anjali Singhai Jain49d7d932014-06-04 08:45:15 +00003746 /* move us past the eop_desc for start of next FD desc */
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003747 tx_buf++;
3748 tx_desc++;
3749 i++;
3750 if (unlikely(!i)) {
3751 i -= tx_ring->count;
3752 tx_buf = tx_ring->tx_bi;
3753 tx_desc = I40E_TX_DESC(tx_ring, 0);
3754 }
3755
3756 /* update budget accounting */
3757 budget--;
3758 } while (likely(budget));
3759
3760 i += tx_ring->count;
3761 tx_ring->next_to_clean = i;
3762
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003763 if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
Jesse Brandeburg78455482015-07-23 16:54:41 -04003764 i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04003765
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003766 return budget > 0;
3767}
3768
3769/**
3770 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3771 * @irq: interrupt number
3772 * @data: pointer to a q_vector
3773 **/
3774static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
3775{
3776 struct i40e_q_vector *q_vector = data;
3777 struct i40e_vsi *vsi;
3778
3779 if (!q_vector->tx.ring)
3780 return IRQ_HANDLED;
3781
3782 vsi = q_vector->tx.ring->vsi;
3783 i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
3784
3785 return IRQ_HANDLED;
3786}
3787
3788/**
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003789 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003790 * @vsi: the VSI being configured
3791 * @v_idx: vector index
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003792 * @qp_idx: queue pair index
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003793 **/
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04003794static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003795{
Alexander Duyck493fb302013-09-28 07:01:44 +00003796 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyck9f65e152013-09-28 06:00:58 +00003797 struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
3798 struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003799
3800 tx_ring->q_vector = q_vector;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003801 tx_ring->next = q_vector->tx.ring;
3802 q_vector->tx.ring = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003803 q_vector->tx.count++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003804
3805 rx_ring->q_vector = q_vector;
3806 rx_ring->next = q_vector->rx.ring;
3807 q_vector->rx.ring = rx_ring;
3808 q_vector->rx.count++;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003809}
3810
3811/**
3812 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3813 * @vsi: the VSI being configured
3814 *
3815 * This function maps descriptor rings to the queue-specific vectors
3816 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3817 * one vector per queue pair, but on a constrained vector budget, we
3818 * group the queue pairs as "efficiently" as possible.
3819 **/
3820static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
3821{
3822 int qp_remaining = vsi->num_queue_pairs;
3823 int q_vectors = vsi->num_q_vectors;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003824 int num_ringpairs;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003825 int v_start = 0;
3826 int qp_idx = 0;
3827
3828 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3829 * group them so there are multiple queues per vector.
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003830 * It is also important to go through all the vectors available to be
3831 * sure that if we don't use all the vectors, that the remaining vectors
3832 * are cleared. This is especially important when decreasing the
3833 * number of queues in use.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003834 */
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003835 for (; v_start < q_vectors; v_start++) {
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003836 struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
3837
3838 num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
3839
3840 q_vector->num_ringpairs = num_ringpairs;
3841
3842 q_vector->rx.count = 0;
3843 q_vector->tx.count = 0;
3844 q_vector->rx.ring = NULL;
3845 q_vector->tx.ring = NULL;
3846
3847 while (num_ringpairs--) {
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04003848 i40e_map_vector_to_qp(vsi, v_start, qp_idx);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003849 qp_idx++;
3850 qp_remaining--;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003851 }
3852 }
3853}
3854
3855/**
3856 * i40e_vsi_request_irq - Request IRQ from the OS
3857 * @vsi: the VSI being configured
3858 * @basename: name for the vector
3859 **/
3860static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
3861{
3862 struct i40e_pf *pf = vsi->back;
3863 int err;
3864
3865 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
3866 err = i40e_vsi_request_irq_msix(vsi, basename);
3867 else if (pf->flags & I40E_FLAG_MSI_ENABLED)
3868 err = request_irq(pf->pdev->irq, i40e_intr, 0,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00003869 pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003870 else
3871 err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00003872 pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003873
3874 if (err)
3875 dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
3876
3877 return err;
3878}
3879
3880#ifdef CONFIG_NET_POLL_CONTROLLER
3881/**
Jesse Brandeburgd89d9672016-01-04 10:33:02 -08003882 * i40e_netpoll - A Polling 'interrupt' handler
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003883 * @netdev: network interface device structure
3884 *
3885 * This is used by netconsole to send skbs without having to re-enable
3886 * interrupts. It's not called while the normal interrupt routine is executing.
3887 **/
Vasu Dev38e00432014-08-01 13:27:03 -07003888#ifdef I40E_FCOE
3889void i40e_netpoll(struct net_device *netdev)
3890#else
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003891static void i40e_netpoll(struct net_device *netdev)
Vasu Dev38e00432014-08-01 13:27:03 -07003892#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003893{
3894 struct i40e_netdev_priv *np = netdev_priv(netdev);
3895 struct i40e_vsi *vsi = np->vsi;
3896 struct i40e_pf *pf = vsi->back;
3897 int i;
3898
3899 /* if interface is down do nothing */
3900 if (test_bit(__I40E_DOWN, &vsi->state))
3901 return;
3902
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003903 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3904 for (i = 0; i < vsi->num_q_vectors; i++)
Alexander Duyck493fb302013-09-28 07:01:44 +00003905 i40e_msix_clean_rings(0, vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003906 } else {
3907 i40e_intr(pf->pdev->irq, netdev);
3908 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003909}
3910#endif
3911
3912/**
Neerav Parikh23527302014-06-03 23:50:15 +00003913 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3914 * @pf: the PF being configured
3915 * @pf_q: the PF queue
3916 * @enable: enable or disable state of the queue
3917 *
3918 * This routine will wait for the given Tx queue of the PF to reach the
3919 * enabled or disabled state.
3920 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3921 * multiple retries; else will return 0 in case of success.
3922 **/
3923static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3924{
3925 int i;
3926 u32 tx_reg;
3927
3928 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3929 tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
3930 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
3931 break;
3932
Neerav Parikhf98a2002014-09-13 07:40:44 +00003933 usleep_range(10, 20);
Neerav Parikh23527302014-06-03 23:50:15 +00003934 }
3935 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3936 return -ETIMEDOUT;
3937
3938 return 0;
3939}
3940
3941/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003942 * i40e_vsi_control_tx - Start or stop a VSI's rings
3943 * @vsi: the VSI being configured
3944 * @enable: start or stop the rings
3945 **/
3946static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
3947{
3948 struct i40e_pf *pf = vsi->back;
3949 struct i40e_hw *hw = &pf->hw;
Neerav Parikh23527302014-06-03 23:50:15 +00003950 int i, j, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003951 u32 tx_reg;
3952
3953 pf_q = vsi->base_queue;
3954 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Matt Jared351499ab2014-04-23 04:50:03 +00003955
3956 /* warn the TX unit of coming changes */
3957 i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
3958 if (!enable)
Neerav Parikhf98a2002014-09-13 07:40:44 +00003959 usleep_range(10, 20);
Matt Jared351499ab2014-04-23 04:50:03 +00003960
Mitch Williams6c5ef622014-02-20 19:29:16 -08003961 for (j = 0; j < 50; j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003962 tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
Mitch Williams6c5ef622014-02-20 19:29:16 -08003963 if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
3964 ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
3965 break;
3966 usleep_range(1000, 2000);
3967 }
Mitch Williamsfda972f2013-11-28 06:39:29 +00003968 /* Skip if the queue is already in the requested state */
Catherine Sullivan7c1220072014-03-14 07:32:29 +00003969 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
Mitch Williamsfda972f2013-11-28 06:39:29 +00003970 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003971
3972 /* turn on/off the queue */
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003973 if (enable) {
3974 wr32(hw, I40E_QTX_HEAD(pf_q), 0);
Mitch Williams6c5ef622014-02-20 19:29:16 -08003975 tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003976 } else {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003977 tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003978 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003979
3980 wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
Neerav Parikh69129dc2014-11-12 00:18:46 +00003981 /* No waiting for the Tx queue to disable */
3982 if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
3983 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003984
3985 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00003986 ret = i40e_pf_txq_wait(pf, pf_q, enable);
3987 if (ret) {
3988 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04003989 "VSI seid %d Tx ring %d %sable timeout\n",
3990 vsi->seid, pf_q, (enable ? "en" : "dis"));
Neerav Parikh23527302014-06-03 23:50:15 +00003991 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003992 }
3993 }
3994
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003995 if (hw->revision_id == 0)
3996 mdelay(50);
Neerav Parikh23527302014-06-03 23:50:15 +00003997 return ret;
3998}
3999
4000/**
4001 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
4002 * @pf: the PF being configured
4003 * @pf_q: the PF queue
4004 * @enable: enable or disable state of the queue
4005 *
4006 * This routine will wait for the given Rx queue of the PF to reach the
4007 * enabled or disabled state.
4008 * Returns -ETIMEDOUT in case of failing to reach the requested state after
4009 * multiple retries; else will return 0 in case of success.
4010 **/
4011static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
4012{
4013 int i;
4014 u32 rx_reg;
4015
4016 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
4017 rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
4018 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
4019 break;
4020
Neerav Parikhf98a2002014-09-13 07:40:44 +00004021 usleep_range(10, 20);
Neerav Parikh23527302014-06-03 23:50:15 +00004022 }
4023 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
4024 return -ETIMEDOUT;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00004025
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004026 return 0;
4027}
4028
4029/**
4030 * i40e_vsi_control_rx - Start or stop a VSI's rings
4031 * @vsi: the VSI being configured
4032 * @enable: start or stop the rings
4033 **/
4034static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
4035{
4036 struct i40e_pf *pf = vsi->back;
4037 struct i40e_hw *hw = &pf->hw;
Neerav Parikh23527302014-06-03 23:50:15 +00004038 int i, j, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004039 u32 rx_reg;
4040
4041 pf_q = vsi->base_queue;
4042 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Mitch Williams6c5ef622014-02-20 19:29:16 -08004043 for (j = 0; j < 50; j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004044 rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
Mitch Williams6c5ef622014-02-20 19:29:16 -08004045 if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
4046 ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
4047 break;
4048 usleep_range(1000, 2000);
4049 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004050
Catherine Sullivan7c1220072014-03-14 07:32:29 +00004051 /* Skip if the queue is already in the requested state */
4052 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
4053 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004054
4055 /* turn on/off the queue */
4056 if (enable)
Mitch Williams6c5ef622014-02-20 19:29:16 -08004057 rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004058 else
Mitch Williams6c5ef622014-02-20 19:29:16 -08004059 rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004060 wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004061 /* No waiting for the Tx queue to disable */
4062 if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
4063 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004064
4065 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00004066 ret = i40e_pf_rxq_wait(pf, pf_q, enable);
4067 if (ret) {
4068 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004069 "VSI seid %d Rx ring %d %sable timeout\n",
4070 vsi->seid, pf_q, (enable ? "en" : "dis"));
Neerav Parikh23527302014-06-03 23:50:15 +00004071 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004072 }
4073 }
4074
Neerav Parikh23527302014-06-03 23:50:15 +00004075 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004076}
4077
4078/**
Filip Sadowski3aa7b742016-10-11 15:26:58 -07004079 * i40e_vsi_start_rings - Start a VSI's rings
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004080 * @vsi: the VSI being configured
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004081 **/
Filip Sadowski3aa7b742016-10-11 15:26:58 -07004082int i40e_vsi_start_rings(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004083{
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00004084 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004085
4086 /* do rx first for enable and last for disable */
Filip Sadowski3aa7b742016-10-11 15:26:58 -07004087 ret = i40e_vsi_control_rx(vsi, true);
4088 if (ret)
4089 return ret;
4090 ret = i40e_vsi_control_tx(vsi, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004091
4092 return ret;
4093}
4094
4095/**
Filip Sadowski3aa7b742016-10-11 15:26:58 -07004096 * i40e_vsi_stop_rings - Stop a VSI's rings
4097 * @vsi: the VSI being configured
4098 **/
4099void i40e_vsi_stop_rings(struct i40e_vsi *vsi)
4100{
4101 /* do rx first for enable and last for disable
4102 * Ignore return value, we need to shutdown whatever we can
4103 */
4104 i40e_vsi_control_tx(vsi, false);
4105 i40e_vsi_control_rx(vsi, false);
4106}
4107
4108/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004109 * i40e_vsi_free_irq - Free the irq association with the OS
4110 * @vsi: the VSI being configured
4111 **/
4112static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
4113{
4114 struct i40e_pf *pf = vsi->back;
4115 struct i40e_hw *hw = &pf->hw;
4116 int base = vsi->base_vector;
4117 u32 val, qp;
4118 int i;
4119
4120 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4121 if (!vsi->q_vectors)
4122 return;
4123
Shannon Nelson63741842014-04-23 04:50:16 +00004124 if (!vsi->irqs_ready)
4125 return;
4126
4127 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004128 for (i = 0; i < vsi->num_q_vectors; i++) {
Alan Brady96db7762016-09-14 16:24:38 -07004129 int irq_num;
4130 u16 vector;
4131
4132 vector = i + base;
4133 irq_num = pf->msix_entries[vector].vector;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004134
4135 /* free only the irqs that were actually requested */
Shannon Nelson78681b12013-11-28 06:39:36 +00004136 if (!vsi->q_vectors[i] ||
4137 !vsi->q_vectors[i]->num_ringpairs)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004138 continue;
4139
Alan Brady96db7762016-09-14 16:24:38 -07004140 /* clear the affinity notifier in the IRQ descriptor */
4141 irq_set_affinity_notifier(irq_num, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004142 /* clear the affinity_mask in the IRQ descriptor */
Alan Brady96db7762016-09-14 16:24:38 -07004143 irq_set_affinity_hint(irq_num, NULL);
4144 synchronize_irq(irq_num);
4145 free_irq(irq_num, vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004146
4147 /* Tear down the interrupt queue link list
4148 *
4149 * We know that they come in pairs and always
4150 * the Rx first, then the Tx. To clear the
4151 * link list, stick the EOL value into the
4152 * next_q field of the registers.
4153 */
4154 val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
4155 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4156 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4157 val |= I40E_QUEUE_END_OF_LIST
4158 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4159 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
4160
4161 while (qp != I40E_QUEUE_END_OF_LIST) {
4162 u32 next;
4163
4164 val = rd32(hw, I40E_QINT_RQCTL(qp));
4165
4166 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4167 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4168 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4169 I40E_QINT_RQCTL_INTEVENT_MASK);
4170
4171 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4172 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4173
4174 wr32(hw, I40E_QINT_RQCTL(qp), val);
4175
4176 val = rd32(hw, I40E_QINT_TQCTL(qp));
4177
4178 next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
4179 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
4180
4181 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4182 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4183 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4184 I40E_QINT_TQCTL_INTEVENT_MASK);
4185
4186 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4187 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4188
4189 wr32(hw, I40E_QINT_TQCTL(qp), val);
4190 qp = next;
4191 }
4192 }
4193 } else {
4194 free_irq(pf->pdev->irq, pf);
4195
4196 val = rd32(hw, I40E_PFINT_LNKLST0);
4197 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
4198 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
4199 val |= I40E_QUEUE_END_OF_LIST
4200 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
4201 wr32(hw, I40E_PFINT_LNKLST0, val);
4202
4203 val = rd32(hw, I40E_QINT_RQCTL(qp));
4204 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
4205 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
4206 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
4207 I40E_QINT_RQCTL_INTEVENT_MASK);
4208
4209 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
4210 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
4211
4212 wr32(hw, I40E_QINT_RQCTL(qp), val);
4213
4214 val = rd32(hw, I40E_QINT_TQCTL(qp));
4215
4216 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
4217 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
4218 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
4219 I40E_QINT_TQCTL_INTEVENT_MASK);
4220
4221 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
4222 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
4223
4224 wr32(hw, I40E_QINT_TQCTL(qp), val);
4225 }
4226}
4227
4228/**
Alexander Duyck493fb302013-09-28 07:01:44 +00004229 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
4230 * @vsi: the VSI being configured
4231 * @v_idx: Index of vector to be freed
4232 *
4233 * This function frees the memory allocated to the q_vector. In addition if
4234 * NAPI is enabled it will delete any references to the NAPI struct prior
4235 * to freeing the q_vector.
4236 **/
4237static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
4238{
4239 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00004240 struct i40e_ring *ring;
Alexander Duyck493fb302013-09-28 07:01:44 +00004241
4242 if (!q_vector)
4243 return;
4244
4245 /* disassociate q_vector from rings */
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00004246 i40e_for_each_ring(ring, q_vector->tx)
4247 ring->q_vector = NULL;
4248
4249 i40e_for_each_ring(ring, q_vector->rx)
4250 ring->q_vector = NULL;
Alexander Duyck493fb302013-09-28 07:01:44 +00004251
4252 /* only VSI w/ an associated netdev is set up w/ NAPI */
4253 if (vsi->netdev)
4254 netif_napi_del(&q_vector->napi);
4255
4256 vsi->q_vectors[v_idx] = NULL;
4257
4258 kfree_rcu(q_vector, rcu);
4259}
4260
4261/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004262 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
4263 * @vsi: the VSI being un-configured
4264 *
4265 * This frees the memory allocated to the q_vectors and
4266 * deletes references to the NAPI struct.
4267 **/
4268static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
4269{
4270 int v_idx;
4271
Alexander Duyck493fb302013-09-28 07:01:44 +00004272 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
4273 i40e_free_q_vector(vsi, v_idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004274}
4275
4276/**
4277 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
4278 * @pf: board private structure
4279 **/
4280static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
4281{
4282 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
4283 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
4284 pci_disable_msix(pf->pdev);
4285 kfree(pf->msix_entries);
4286 pf->msix_entries = NULL;
Shannon Nelson3b444392015-02-26 16:15:57 +00004287 kfree(pf->irq_pile);
4288 pf->irq_pile = NULL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004289 } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
4290 pci_disable_msi(pf->pdev);
4291 }
4292 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
4293}
4294
4295/**
4296 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
4297 * @pf: board private structure
4298 *
4299 * We go through and clear interrupt specific resources and reset the structure
4300 * to pre-load conditions
4301 **/
4302static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
4303{
4304 int i;
4305
Shannon Nelsone1477582015-02-21 06:44:33 +00004306 i40e_stop_misc_vector(pf);
Shannon Nelson69278392016-03-10 14:59:43 -08004307 if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
Shannon Nelsone1477582015-02-21 06:44:33 +00004308 synchronize_irq(pf->msix_entries[0].vector);
4309 free_irq(pf->msix_entries[0].vector, pf);
4310 }
4311
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06004312 i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
4313 I40E_IWARP_IRQ_PILE_ID);
4314
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004315 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
Mitch Williams505682c2014-05-20 08:01:37 +00004316 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004317 if (pf->vsi[i])
4318 i40e_vsi_free_q_vectors(pf->vsi[i]);
4319 i40e_reset_interrupt_capability(pf);
4320}
4321
4322/**
4323 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4324 * @vsi: the VSI being configured
4325 **/
4326static void i40e_napi_enable_all(struct i40e_vsi *vsi)
4327{
4328 int q_idx;
4329
4330 if (!vsi->netdev)
4331 return;
4332
4333 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
Alexander Duyck493fb302013-09-28 07:01:44 +00004334 napi_enable(&vsi->q_vectors[q_idx]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004335}
4336
4337/**
4338 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4339 * @vsi: the VSI being configured
4340 **/
4341static void i40e_napi_disable_all(struct i40e_vsi *vsi)
4342{
4343 int q_idx;
4344
4345 if (!vsi->netdev)
4346 return;
4347
4348 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
Alexander Duyck493fb302013-09-28 07:01:44 +00004349 napi_disable(&vsi->q_vectors[q_idx]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004350}
4351
4352/**
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004353 * i40e_vsi_close - Shut down a VSI
4354 * @vsi: the vsi to be quelled
4355 **/
4356static void i40e_vsi_close(struct i40e_vsi *vsi)
4357{
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06004358 bool reset = false;
4359
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004360 if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
4361 i40e_down(vsi);
4362 i40e_vsi_free_irq(vsi);
4363 i40e_vsi_free_tx_resources(vsi);
4364 i40e_vsi_free_rx_resources(vsi);
Anjali Singhai Jain92faef82015-07-28 13:02:00 -04004365 vsi->current_netdev_flags = 0;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06004366 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
4367 reset = true;
4368 i40e_notify_client_of_netdev_close(vsi, reset);
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004369}
4370
4371/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004372 * i40e_quiesce_vsi - Pause a given VSI
4373 * @vsi: the VSI being paused
4374 **/
4375static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
4376{
4377 if (test_bit(__I40E_DOWN, &vsi->state))
4378 return;
4379
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004380 /* No need to disable FCoE VSI when Tx suspended */
4381 if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) &&
4382 vsi->type == I40E_VSI_FCOE) {
4383 dev_dbg(&vsi->back->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004384 "VSI seid %d skipping FCoE VSI disable\n", vsi->seid);
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004385 return;
4386 }
4387
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004388 set_bit(__I40E_NEEDS_RESTART, &vsi->state);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004389 if (vsi->netdev && netif_running(vsi->netdev))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004390 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
Jesse Brandeburg6995b362015-08-28 17:55:54 -04004391 else
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004392 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004393}
4394
4395/**
4396 * i40e_unquiesce_vsi - Resume a given VSI
4397 * @vsi: the VSI being resumed
4398 **/
4399static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
4400{
4401 if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
4402 return;
4403
4404 clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
4405 if (vsi->netdev && netif_running(vsi->netdev))
4406 vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
4407 else
Shannon Nelson8276f752014-03-14 07:32:27 +00004408 i40e_vsi_open(vsi); /* this clears the DOWN bit */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004409}
4410
4411/**
4412 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
4413 * @pf: the PF
4414 **/
4415static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
4416{
4417 int v;
4418
Mitch Williams505682c2014-05-20 08:01:37 +00004419 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004420 if (pf->vsi[v])
4421 i40e_quiesce_vsi(pf->vsi[v]);
4422 }
4423}
4424
4425/**
4426 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
4427 * @pf: the PF
4428 **/
4429static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
4430{
4431 int v;
4432
Mitch Williams505682c2014-05-20 08:01:37 +00004433 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004434 if (pf->vsi[v])
4435 i40e_unquiesce_vsi(pf->vsi[v]);
4436 }
4437}
4438
Neerav Parikh69129dc2014-11-12 00:18:46 +00004439#ifdef CONFIG_I40E_DCB
4440/**
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004441 * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
Neerav Parikh69129dc2014-11-12 00:18:46 +00004442 * @vsi: the VSI being configured
4443 *
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004444 * This function waits for the given VSI's queues to be disabled.
Neerav Parikh69129dc2014-11-12 00:18:46 +00004445 **/
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004446static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
Neerav Parikh69129dc2014-11-12 00:18:46 +00004447{
4448 struct i40e_pf *pf = vsi->back;
4449 int i, pf_q, ret;
4450
4451 pf_q = vsi->base_queue;
4452 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4453 /* Check and wait for the disable status of the queue */
4454 ret = i40e_pf_txq_wait(pf, pf_q, false);
4455 if (ret) {
4456 dev_info(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04004457 "VSI seid %d Tx ring %d disable timeout\n",
4458 vsi->seid, pf_q);
Neerav Parikh69129dc2014-11-12 00:18:46 +00004459 return ret;
4460 }
4461 }
4462
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004463 pf_q = vsi->base_queue;
4464 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
4465 /* Check and wait for the disable status of the queue */
4466 ret = i40e_pf_rxq_wait(pf, pf_q, false);
4467 if (ret) {
4468 dev_info(&pf->pdev->dev,
4469 "VSI seid %d Rx ring %d disable timeout\n",
4470 vsi->seid, pf_q);
4471 return ret;
4472 }
4473 }
4474
Neerav Parikh69129dc2014-11-12 00:18:46 +00004475 return 0;
4476}
4477
4478/**
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004479 * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
Neerav Parikh69129dc2014-11-12 00:18:46 +00004480 * @pf: the PF
4481 *
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004482 * This function waits for the queues to be in disabled state for all the
Neerav Parikh69129dc2014-11-12 00:18:46 +00004483 * VSIs that are managed by this PF.
4484 **/
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004485static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
Neerav Parikh69129dc2014-11-12 00:18:46 +00004486{
4487 int v, ret = 0;
4488
4489 for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
Neerav Parikhd341b7a2014-11-12 00:18:51 +00004490 /* No need to wait for FCoE VSI queues */
4491 if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) {
Neerav Parikh3fe06f42016-02-17 16:12:15 -08004492 ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
Neerav Parikh69129dc2014-11-12 00:18:46 +00004493 if (ret)
4494 break;
4495 }
4496 }
4497
4498 return ret;
4499}
4500
4501#endif
Kiran Patilb03a8c12015-09-24 18:13:15 -04004502
4503/**
4504 * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
4505 * @q_idx: TX queue number
4506 * @vsi: Pointer to VSI struct
4507 *
4508 * This function checks specified queue for given VSI. Detects hung condition.
4509 * Sets hung bit since it is two step process. Before next run of service task
4510 * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not,
4511 * hung condition remain unchanged and during subsequent run, this function
4512 * issues SW interrupt to recover from hung condition.
4513 **/
4514static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
4515{
4516 struct i40e_ring *tx_ring = NULL;
4517 struct i40e_pf *pf;
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004518 u32 head, val, tx_pending_hw;
Kiran Patilb03a8c12015-09-24 18:13:15 -04004519 int i;
4520
4521 pf = vsi->back;
4522
4523 /* now that we have an index, find the tx_ring struct */
4524 for (i = 0; i < vsi->num_queue_pairs; i++) {
4525 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
4526 if (q_idx == vsi->tx_rings[i]->queue_index) {
4527 tx_ring = vsi->tx_rings[i];
4528 break;
4529 }
4530 }
4531 }
4532
4533 if (!tx_ring)
4534 return;
4535
4536 /* Read interrupt register */
4537 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
4538 val = rd32(&pf->hw,
4539 I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
4540 tx_ring->vsi->base_vector - 1));
4541 else
4542 val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
4543
4544 head = i40e_get_head(tx_ring);
4545
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004546 tx_pending_hw = i40e_get_tx_pending(tx_ring, false);
Kiran Patilb03a8c12015-09-24 18:13:15 -04004547
Kiran Patil9c6c1252015-11-06 15:26:02 -08004548 /* HW is done executing descriptors, updated HEAD write back,
4549 * but SW hasn't processed those descriptors. If interrupt is
4550 * not generated from this point ON, it could result into
4551 * dev_watchdog detecting timeout on those netdev_queue,
4552 * hence proactively trigger SW interrupt.
Kiran Patilb03a8c12015-09-24 18:13:15 -04004553 */
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004554 if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
Kiran Patil9c6c1252015-11-06 15:26:02 -08004555 /* NAPI Poll didn't run and clear since it was set */
4556 if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT,
4557 &tx_ring->q_vector->hung_detected)) {
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004558 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",
4559 vsi->seid, q_idx, tx_pending_hw,
Kiran Patil9c6c1252015-11-06 15:26:02 -08004560 tx_ring->next_to_clean, head,
4561 tx_ring->next_to_use,
4562 readl(tx_ring->tail));
4563 netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n",
4564 vsi->seid, q_idx, val);
4565 i40e_force_wb(vsi, tx_ring->q_vector);
4566 } else {
4567 /* First Chance - detected possible hung */
4568 set_bit(I40E_Q_VECTOR_HUNG_DETECT,
4569 &tx_ring->q_vector->hung_detected);
4570 }
4571 }
Anjali Singhai Jaindd353102016-01-15 14:33:12 -08004572
4573 /* This is the case where we have interrupts missing,
4574 * so the tx_pending in HW will most likely be 0, but we
4575 * will have tx_pending in SW since the WB happened but the
4576 * interrupt got lost.
4577 */
4578 if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) &&
4579 (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
4580 if (napi_reschedule(&tx_ring->q_vector->napi))
4581 tx_ring->tx_stats.tx_lost_interrupt++;
4582 }
Kiran Patilb03a8c12015-09-24 18:13:15 -04004583}
4584
4585/**
4586 * i40e_detect_recover_hung - Function to detect and recover hung_queues
4587 * @pf: pointer to PF struct
4588 *
4589 * LAN VSI has netdev and netdev has TX queues. This function is to check
4590 * each of those TX queues if they are hung, trigger recovery by issuing
4591 * SW interrupt.
4592 **/
4593static void i40e_detect_recover_hung(struct i40e_pf *pf)
4594{
4595 struct net_device *netdev;
4596 struct i40e_vsi *vsi;
4597 int i;
4598
4599 /* Only for LAN VSI */
4600 vsi = pf->vsi[pf->lan_vsi];
4601
4602 if (!vsi)
4603 return;
4604
4605 /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
4606 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
4607 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
4608 return;
4609
4610 /* Make sure type is MAIN VSI */
4611 if (vsi->type != I40E_VSI_MAIN)
4612 return;
4613
4614 netdev = vsi->netdev;
4615 if (!netdev)
4616 return;
4617
4618 /* Bail out if netif_carrier is not OK */
4619 if (!netif_carrier_ok(netdev))
4620 return;
4621
4622 /* Go thru' TX queues for netdev */
4623 for (i = 0; i < netdev->num_tx_queues; i++) {
4624 struct netdev_queue *q;
4625
4626 q = netdev_get_tx_queue(netdev, i);
4627 if (q)
4628 i40e_detect_recover_hung_queue(i, vsi);
4629 }
4630}
4631
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004632/**
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004633 * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00004634 * @pf: pointer to PF
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004635 *
4636 * Get TC map for ISCSI PF type that will include iSCSI TC
4637 * and LAN TC.
4638 **/
4639static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
4640{
4641 struct i40e_dcb_app_priority_table app;
4642 struct i40e_hw *hw = &pf->hw;
4643 u8 enabled_tc = 1; /* TC0 is always enabled */
4644 u8 tc, i;
4645 /* Get the iSCSI APP TLV */
4646 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4647
4648 for (i = 0; i < dcbcfg->numapps; i++) {
4649 app = dcbcfg->app[i];
4650 if (app.selector == I40E_APP_SEL_TCPIP &&
4651 app.protocolid == I40E_APP_PROTOID_ISCSI) {
4652 tc = dcbcfg->etscfg.prioritytable[app.priority];
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004653 enabled_tc |= BIT(tc);
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004654 break;
4655 }
4656 }
4657
4658 return enabled_tc;
4659}
4660
4661/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004662 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
4663 * @dcbcfg: the corresponding DCBx configuration structure
4664 *
4665 * Return the number of TCs from given DCBx configuration
4666 **/
4667static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
4668{
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004669 int i, tc_unused = 0;
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004670 u8 num_tc = 0;
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004671 u8 ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004672
4673 /* Scan the ETS Config Priority Table to find
4674 * traffic class enabled for a given priority
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004675 * and create a bitmask of enabled TCs
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004676 */
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004677 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
4678 num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
4679
4680 /* Now scan the bitmask to check for
4681 * contiguous TCs starting with TC0
4682 */
4683 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4684 if (num_tc & BIT(i)) {
4685 if (!tc_unused) {
4686 ret++;
4687 } else {
4688 pr_err("Non-contiguous TC - Disabling DCB\n");
4689 return 1;
4690 }
4691 } else {
4692 tc_unused = 1;
4693 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004694 }
4695
Dave Ertmanfbfe12c2016-08-12 09:56:32 -07004696 /* There is always at least TC0 */
4697 if (!ret)
4698 ret = 1;
4699
4700 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004701}
4702
4703/**
4704 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
4705 * @dcbcfg: the corresponding DCBx configuration structure
4706 *
4707 * Query the current DCB configuration and return the number of
4708 * traffic classes enabled from the given DCBX config
4709 **/
4710static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
4711{
4712 u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
4713 u8 enabled_tc = 1;
4714 u8 i;
4715
4716 for (i = 0; i < num_tc; i++)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04004717 enabled_tc |= BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004718
4719 return enabled_tc;
4720}
4721
4722/**
4723 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
4724 * @pf: PF being queried
4725 *
4726 * Return number of traffic classes enabled for the given PF
4727 **/
4728static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
4729{
4730 struct i40e_hw *hw = &pf->hw;
Dave Ertman52a08ca2016-07-27 12:02:34 -07004731 u8 i, enabled_tc = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004732 u8 num_tc = 0;
4733 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4734
4735 /* If DCB is not enabled then always in single TC */
4736 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
4737 return 1;
4738
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004739 /* SFP mode will be enabled for all TCs on port */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004740 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4741 return i40e_dcb_get_num_tc(dcbcfg);
4742
4743 /* MFP mode return count of enabled TCs for this PF */
4744 if (pf->hw.func_caps.iscsi)
4745 enabled_tc = i40e_get_iscsi_tc_map(pf);
4746 else
Neerav Parikhfc51de92015-02-24 06:58:53 +00004747 return 1; /* Only TC0 */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004748
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004749 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004750 if (enabled_tc & BIT(i))
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004751 num_tc++;
4752 }
4753 return num_tc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004754}
4755
4756/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004757 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4758 * @pf: PF being queried
4759 *
4760 * Return a bitmap for enabled traffic classes for this PF.
4761 **/
4762static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
4763{
4764 /* If DCB is not enabled for this PF then just return default TC */
4765 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
David Ertmanea6acb72016-09-20 07:10:50 -07004766 return I40E_DEFAULT_TRAFFIC_CLASS;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004767
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004768 /* SFP mode we want PF to be enabled for all TCs */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004769 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
4770 return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
4771
Neerav Parikhfc51de92015-02-24 06:58:53 +00004772 /* MFP enabled and iSCSI PF type */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00004773 if (pf->hw.func_caps.iscsi)
4774 return i40e_get_iscsi_tc_map(pf);
4775 else
David Ertmanea6acb72016-09-20 07:10:50 -07004776 return I40E_DEFAULT_TRAFFIC_CLASS;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004777}
4778
4779/**
4780 * i40e_vsi_get_bw_info - Query VSI BW Information
4781 * @vsi: the VSI being queried
4782 *
4783 * Returns 0 on success, negative value on failure
4784 **/
4785static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
4786{
4787 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
4788 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
4789 struct i40e_pf *pf = vsi->back;
4790 struct i40e_hw *hw = &pf->hw;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004791 i40e_status ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004792 u32 tc_bw_max;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004793 int i;
4794
4795 /* Get the VSI level BW configuration */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004796 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
4797 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004798 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004799 "couldn't get PF vsi bw config, err %s aq_err %s\n",
4800 i40e_stat_str(&pf->hw, ret),
4801 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004802 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004803 }
4804
4805 /* Get the VSI level BW configuration per TC */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004806 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
4807 NULL);
4808 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004809 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004810 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
4811 i40e_stat_str(&pf->hw, ret),
4812 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004813 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004814 }
4815
4816 if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
4817 dev_info(&pf->pdev->dev,
4818 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
4819 bw_config.tc_valid_bits,
4820 bw_ets_config.tc_valid_bits);
4821 /* Still continuing */
4822 }
4823
4824 vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
4825 vsi->bw_max_quanta = bw_config.max_bw;
4826 tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
4827 (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
4828 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4829 vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
4830 vsi->bw_ets_limit_credits[i] =
4831 le16_to_cpu(bw_ets_config.credits[i]);
4832 /* 3 bits out of 4 for each TC */
4833 vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
4834 }
Jesse Brandeburg078b5872013-09-25 23:41:14 +00004835
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004836 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004837}
4838
4839/**
4840 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
4841 * @vsi: the VSI being configured
4842 * @enabled_tc: TC bitmap
4843 * @bw_credits: BW shared credits per TC
4844 *
4845 * Returns 0 on success, negative value on failure
4846 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004847static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004848 u8 *bw_share)
4849{
4850 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004851 i40e_status ret;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004852 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004853
4854 bw_data.tc_valid_bits = enabled_tc;
4855 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4856 bw_data.tc_bw_credits[i] = bw_share[i];
4857
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04004858 ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
4859 NULL);
4860 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004861 dev_info(&vsi->back->pdev->dev,
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004862 "AQ command Config VSI BW allocation per TC failed = %d\n",
4863 vsi->back->hw.aq.asq_last_status);
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004864 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004865 }
4866
4867 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4868 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
4869
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00004870 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004871}
4872
4873/**
4874 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
4875 * @vsi: the VSI being configured
4876 * @enabled_tc: TC map to be enabled
4877 *
4878 **/
4879static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4880{
4881 struct net_device *netdev = vsi->netdev;
4882 struct i40e_pf *pf = vsi->back;
4883 struct i40e_hw *hw = &pf->hw;
4884 u8 netdev_tc = 0;
4885 int i;
4886 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
4887
4888 if (!netdev)
4889 return;
4890
4891 if (!enabled_tc) {
4892 netdev_reset_tc(netdev);
4893 return;
4894 }
4895
4896 /* Set up actual enabled TCs on the VSI */
4897 if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
4898 return;
4899
4900 /* set per TC queues for the VSI */
4901 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4902 /* Only set TC queues for enabled tcs
4903 *
4904 * e.g. For a VSI that has TC0 and TC3 enabled the
4905 * enabled_tc bitmap would be 0x00001001; the driver
4906 * will set the numtc for netdev as 2 that will be
4907 * referenced by the netdev layer as TC 0 and 1.
4908 */
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004909 if (vsi->tc_config.enabled_tc & BIT(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004910 netdev_set_tc_queue(netdev,
4911 vsi->tc_config.tc_info[i].netdev_tc,
4912 vsi->tc_config.tc_info[i].qcount,
4913 vsi->tc_config.tc_info[i].qoffset);
4914 }
4915
4916 /* Assign UP2TC map for the VSI */
4917 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
4918 /* Get the actual TC# for the UP */
4919 u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
4920 /* Get the mapped netdev TC# for the UP */
4921 netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
4922 netdev_set_prio_tc_map(netdev, i, netdev_tc);
4923 }
4924}
4925
4926/**
4927 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4928 * @vsi: the VSI being configured
4929 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4930 **/
4931static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
4932 struct i40e_vsi_context *ctxt)
4933{
4934 /* copy just the sections touched not the entire info
4935 * since not all sections are valid as returned by
4936 * update vsi params
4937 */
4938 vsi->info.mapping_flags = ctxt->info.mapping_flags;
4939 memcpy(&vsi->info.queue_mapping,
4940 &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
4941 memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
4942 sizeof(vsi->info.tc_mapping));
4943}
4944
4945/**
4946 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4947 * @vsi: VSI to be configured
4948 * @enabled_tc: TC bitmap
4949 *
4950 * This configures a particular VSI for TCs that are mapped to the
4951 * given TC bitmap. It uses default bandwidth share for TCs across
4952 * VSIs to configure TC for a particular VSI.
4953 *
4954 * NOTE:
4955 * It is expected that the VSI queues have been quisced before calling
4956 * this function.
4957 **/
4958static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4959{
4960 u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
4961 struct i40e_vsi_context ctxt;
4962 int ret = 0;
4963 int i;
4964
4965 /* Check if enabled_tc is same as existing or new TCs */
4966 if (vsi->tc_config.enabled_tc == enabled_tc)
4967 return ret;
4968
4969 /* Enable ETS TCs with equal BW Share for now across all VSIs */
4970 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08004971 if (enabled_tc & BIT(i))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004972 bw_share[i] = 1;
4973 }
4974
4975 ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
4976 if (ret) {
4977 dev_info(&vsi->back->pdev->dev,
4978 "Failed configuring TC map %d for VSI %d\n",
4979 enabled_tc, vsi->seid);
4980 goto out;
4981 }
4982
4983 /* Update Queue Pairs Mapping for currently enabled UPs */
4984 ctxt.seid = vsi->seid;
4985 ctxt.pf_num = vsi->back->hw.pf_id;
4986 ctxt.vf_num = 0;
4987 ctxt.uplink_seid = vsi->uplink_seid;
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07004988 ctxt.info = vsi->info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004989 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
4990
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06004991 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
4992 ctxt.info.valid_sections |=
4993 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
4994 ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
4995 }
4996
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004997 /* Update the VSI after updating the VSI queue-mapping information */
4998 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
4999 if (ret) {
5000 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005001 "Update vsi tc config failed, err %s aq_err %s\n",
5002 i40e_stat_str(&vsi->back->hw, ret),
5003 i40e_aq_str(&vsi->back->hw,
5004 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005005 goto out;
5006 }
5007 /* update the local VSI info with updated queue map */
5008 i40e_vsi_update_queue_map(vsi, &ctxt);
5009 vsi->info.valid_sections = 0;
5010
5011 /* Update current VSI BW information */
5012 ret = i40e_vsi_get_bw_info(vsi);
5013 if (ret) {
5014 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005015 "Failed updating vsi bw info, err %s aq_err %s\n",
5016 i40e_stat_str(&vsi->back->hw, ret),
5017 i40e_aq_str(&vsi->back->hw,
5018 vsi->back->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005019 goto out;
5020 }
5021
5022 /* Update the netdev TC setup */
5023 i40e_vsi_config_netdev_tc(vsi, enabled_tc);
5024out:
5025 return ret;
5026}
5027
5028/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005029 * i40e_veb_config_tc - Configure TCs for given VEB
5030 * @veb: given VEB
5031 * @enabled_tc: TC bitmap
5032 *
5033 * Configures given TC bitmap for VEB (switching) element
5034 **/
5035int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
5036{
5037 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
5038 struct i40e_pf *pf = veb->pf;
5039 int ret = 0;
5040 int i;
5041
5042 /* No TCs or already enabled TCs just return */
5043 if (!enabled_tc || veb->enabled_tc == enabled_tc)
5044 return ret;
5045
5046 bw_data.tc_valid_bits = enabled_tc;
5047 /* bw_data.absolute_credits is not set (relative) */
5048
5049 /* Enable ETS TCs with equal BW Share for now */
5050 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08005051 if (enabled_tc & BIT(i))
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005052 bw_data.tc_bw_share_credits[i] = 1;
5053 }
5054
5055 ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
5056 &bw_data, NULL);
5057 if (ret) {
5058 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005059 "VEB bw config failed, err %s aq_err %s\n",
5060 i40e_stat_str(&pf->hw, ret),
5061 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005062 goto out;
5063 }
5064
5065 /* Update the BW information */
5066 ret = i40e_veb_get_bw_info(veb);
5067 if (ret) {
5068 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005069 "Failed getting veb bw config, err %s aq_err %s\n",
5070 i40e_stat_str(&pf->hw, ret),
5071 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005072 }
5073
5074out:
5075 return ret;
5076}
5077
5078#ifdef CONFIG_I40E_DCB
5079/**
5080 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
5081 * @pf: PF struct
5082 *
5083 * Reconfigure VEB/VSIs on a given PF; it is assumed that
5084 * the caller would've quiesce all the VSIs before calling
5085 * this function
5086 **/
5087static void i40e_dcb_reconfigure(struct i40e_pf *pf)
5088{
5089 u8 tc_map = 0;
5090 int ret;
5091 u8 v;
5092
5093 /* Enable the TCs available on PF to all VEBs */
5094 tc_map = i40e_pf_get_tc_map(pf);
5095 for (v = 0; v < I40E_MAX_VEB; v++) {
5096 if (!pf->veb[v])
5097 continue;
5098 ret = i40e_veb_config_tc(pf->veb[v], tc_map);
5099 if (ret) {
5100 dev_info(&pf->pdev->dev,
5101 "Failed configuring TC for VEB seid=%d\n",
5102 pf->veb[v]->seid);
5103 /* Will try to configure as many components */
5104 }
5105 }
5106
5107 /* Update each VSI */
Mitch Williams505682c2014-05-20 08:01:37 +00005108 for (v = 0; v < pf->num_alloc_vsi; v++) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005109 if (!pf->vsi[v])
5110 continue;
5111
5112 /* - Enable all TCs for the LAN VSI
Vasu Dev38e00432014-08-01 13:27:03 -07005113#ifdef I40E_FCOE
5114 * - For FCoE VSI only enable the TC configured
5115 * as per the APP TLV
5116#endif
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005117 * - For all others keep them at TC0 for now
5118 */
5119 if (v == pf->lan_vsi)
5120 tc_map = i40e_pf_get_tc_map(pf);
5121 else
David Ertmanea6acb72016-09-20 07:10:50 -07005122 tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
Vasu Dev38e00432014-08-01 13:27:03 -07005123#ifdef I40E_FCOE
5124 if (pf->vsi[v]->type == I40E_VSI_FCOE)
5125 tc_map = i40e_get_fcoe_tc_map(pf);
5126#endif /* #ifdef I40E_FCOE */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005127
5128 ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
5129 if (ret) {
5130 dev_info(&pf->pdev->dev,
5131 "Failed configuring TC for VSI seid=%d\n",
5132 pf->vsi[v]->seid);
5133 /* Will try to configure as many components */
5134 } else {
Neerav Parikh0672a092014-04-01 07:11:47 +00005135 /* Re-configure VSI vectors based on updated TC map */
5136 i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005137 if (pf->vsi[v]->netdev)
5138 i40e_dcbnl_set_all(pf->vsi[v]);
5139 }
5140 }
5141}
5142
5143/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005144 * i40e_resume_port_tx - Resume port Tx
5145 * @pf: PF struct
5146 *
5147 * Resume a port's Tx and issue a PF reset in case of failure to
5148 * resume.
5149 **/
5150static int i40e_resume_port_tx(struct i40e_pf *pf)
5151{
5152 struct i40e_hw *hw = &pf->hw;
5153 int ret;
5154
5155 ret = i40e_aq_resume_port_tx(hw, NULL);
5156 if (ret) {
5157 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005158 "Resume Port Tx failed, err %s aq_err %s\n",
5159 i40e_stat_str(&pf->hw, ret),
5160 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005161 /* Schedule PF reset to recover */
5162 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
5163 i40e_service_event_schedule(pf);
5164 }
5165
5166 return ret;
5167}
5168
5169/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005170 * i40e_init_pf_dcb - Initialize DCB configuration
5171 * @pf: PF being configured
5172 *
5173 * Query the current DCB configuration and cache it
5174 * in the hardware structure
5175 **/
5176static int i40e_init_pf_dcb(struct i40e_pf *pf)
5177{
5178 struct i40e_hw *hw = &pf->hw;
5179 int err = 0;
5180
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00005181 /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
Neerav Parikhf1bbad32016-01-13 16:51:39 -08005182 if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT)
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00005183 goto out;
5184
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005185 /* Get the initial DCB configuration */
5186 err = i40e_init_dcb(hw);
5187 if (!err) {
5188 /* Device/Function is not DCBX capable */
5189 if ((!hw->func_caps.dcb) ||
5190 (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
5191 dev_info(&pf->pdev->dev,
5192 "DCBX offload is not supported or is disabled for this PF.\n");
5193
5194 if (pf->flags & I40E_FLAG_MFP_ENABLED)
5195 goto out;
5196
5197 } else {
5198 /* When status is not DISABLED then DCBX in FW */
5199 pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
5200 DCB_CAP_DCBX_VER_IEEE;
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005201
5202 pf->flags |= I40E_FLAG_DCB_CAPABLE;
Dave Ertmana0362442016-08-29 17:38:26 -07005203 /* Enable DCB tagging only when more than one TC
5204 * or explicitly disable if only one TC
5205 */
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005206 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
5207 pf->flags |= I40E_FLAG_DCB_ENABLED;
Dave Ertmana0362442016-08-29 17:38:26 -07005208 else
5209 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005210 dev_dbg(&pf->pdev->dev,
5211 "DCBX offload is supported for this PF.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005212 }
Neerav Parikh014269f2014-04-01 07:11:48 +00005213 } else {
Shannon Nelsonaebfc812014-12-11 07:06:38 +00005214 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005215 "Query for DCB configuration failed, err %s aq_err %s\n",
5216 i40e_stat_str(&pf->hw, err),
5217 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005218 }
5219
5220out:
5221 return err;
5222}
5223#endif /* CONFIG_I40E_DCB */
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005224#define SPEED_SIZE 14
5225#define FC_SIZE 8
5226/**
5227 * i40e_print_link_message - print link up or down
5228 * @vsi: the VSI for which link needs a message
5229 */
Matt Jaredc156f852015-08-27 11:42:39 -04005230void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005231{
Filip Sadowski7ec9ba12016-11-08 13:05:13 -08005232 enum i40e_aq_link_speed new_speed;
Shannon Nelsona9165492015-09-03 17:19:00 -04005233 char *speed = "Unknown";
5234 char *fc = "Unknown";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005235
Filip Sadowski7ec9ba12016-11-08 13:05:13 -08005236 new_speed = vsi->back->hw.phy.link_info.link_speed;
5237
5238 if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed))
Matt Jaredc156f852015-08-27 11:42:39 -04005239 return;
5240 vsi->current_isup = isup;
Filip Sadowski7ec9ba12016-11-08 13:05:13 -08005241 vsi->current_speed = new_speed;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005242 if (!isup) {
5243 netdev_info(vsi->netdev, "NIC Link is Down\n");
5244 return;
5245 }
5246
Greg Rose148c2d82014-12-11 07:06:27 +00005247 /* Warn user if link speed on NPAR enabled partition is not at
5248 * least 10GB
5249 */
5250 if (vsi->back->hw.func_caps.npar_enable &&
5251 (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
5252 vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
5253 netdev_warn(vsi->netdev,
5254 "The partition detected link speed that is less than 10Gbps\n");
5255
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005256 switch (vsi->back->hw.phy.link_info.link_speed) {
5257 case I40E_LINK_SPEED_40GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005258 speed = "40 G";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005259 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -07005260 case I40E_LINK_SPEED_20GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005261 speed = "20 G";
Jesse Brandeburgae24b402015-03-27 00:12:09 -07005262 break;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005263 case I40E_LINK_SPEED_10GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005264 speed = "10 G";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005265 break;
5266 case I40E_LINK_SPEED_1GB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005267 speed = "1000 M";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005268 break;
Mitch Williams5960d332014-09-13 07:40:47 +00005269 case I40E_LINK_SPEED_100MB:
Shannon Nelsona9165492015-09-03 17:19:00 -04005270 speed = "100 M";
Mitch Williams5960d332014-09-13 07:40:47 +00005271 break;
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005272 default:
5273 break;
5274 }
5275
5276 switch (vsi->back->hw.fc.current_mode) {
5277 case I40E_FC_FULL:
Shannon Nelsona9165492015-09-03 17:19:00 -04005278 fc = "RX/TX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005279 break;
5280 case I40E_FC_TX_PAUSE:
Shannon Nelsona9165492015-09-03 17:19:00 -04005281 fc = "TX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005282 break;
5283 case I40E_FC_RX_PAUSE:
Shannon Nelsona9165492015-09-03 17:19:00 -04005284 fc = "RX";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005285 break;
5286 default:
Shannon Nelsona9165492015-09-03 17:19:00 -04005287 fc = "None";
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005288 break;
5289 }
5290
Shannon Nelsona9165492015-09-03 17:19:00 -04005291 netdev_info(vsi->netdev, "NIC Link is Up %sbps Full Duplex, Flow Control: %s\n",
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005292 speed, fc);
5293}
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005294
5295/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005296 * i40e_up_complete - Finish the last steps of bringing up a connection
5297 * @vsi: the VSI being configured
5298 **/
5299static int i40e_up_complete(struct i40e_vsi *vsi)
5300{
5301 struct i40e_pf *pf = vsi->back;
5302 int err;
5303
5304 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
5305 i40e_vsi_configure_msix(vsi);
5306 else
5307 i40e_configure_msi_and_legacy(vsi);
5308
5309 /* start rings */
Filip Sadowski3aa7b742016-10-11 15:26:58 -07005310 err = i40e_vsi_start_rings(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005311 if (err)
5312 return err;
5313
5314 clear_bit(__I40E_DOWN, &vsi->state);
5315 i40e_napi_enable_all(vsi);
5316 i40e_vsi_enable_irq(vsi);
5317
5318 if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
5319 (vsi->netdev)) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005320 i40e_print_link_message(vsi, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005321 netif_tx_start_all_queues(vsi->netdev);
5322 netif_carrier_on(vsi->netdev);
Anjali Singhai6d779b42013-09-28 06:00:02 +00005323 } else if (vsi->netdev) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005324 i40e_print_link_message(vsi, false);
Carolyn Wyborny7b592f62014-07-10 07:58:19 +00005325 /* need to check for qualified module here*/
5326 if ((pf->hw.phy.link_info.link_info &
5327 I40E_AQ_MEDIA_AVAILABLE) &&
5328 (!(pf->hw.phy.link_info.an_info &
5329 I40E_AQ_QUALIFIED_MODULE)))
5330 netdev_err(vsi->netdev,
5331 "the driver failed to link because an unqualified module was detected.");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005332 }
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00005333
5334 /* replay FDIR SB filters */
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005335 if (vsi->type == I40E_VSI_FDIR) {
5336 /* reset fd counters */
5337 pf->fd_add_err = pf->fd_atr_cnt = 0;
5338 if (pf->fd_tcp_rule > 0) {
Jacob Keller234dc4e2016-09-06 18:05:09 -07005339 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04005340 if (I40E_DEBUG_FD & pf->hw.debug_mask)
5341 dev_info(&pf->pdev->dev, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005342 pf->fd_tcp_rule = 0;
5343 }
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00005344 i40e_fdir_filter_restore(vsi);
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005345 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06005346
5347 /* On the next run of the service_task, notify any clients of the new
5348 * opened netdev
5349 */
5350 pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005351 i40e_service_event_schedule(pf);
5352
5353 return 0;
5354}
5355
5356/**
5357 * i40e_vsi_reinit_locked - Reset the VSI
5358 * @vsi: the VSI being configured
5359 *
5360 * Rebuild the ring structs after some configuration
5361 * has changed, e.g. MTU size.
5362 **/
5363static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
5364{
5365 struct i40e_pf *pf = vsi->back;
5366
5367 WARN_ON(in_interrupt());
5368 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
5369 usleep_range(1000, 2000);
5370 i40e_down(vsi);
5371
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005372 i40e_up(vsi);
5373 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
5374}
5375
5376/**
5377 * i40e_up - Bring the connection back up after being down
5378 * @vsi: the VSI being configured
5379 **/
5380int i40e_up(struct i40e_vsi *vsi)
5381{
5382 int err;
5383
5384 err = i40e_vsi_configure(vsi);
5385 if (!err)
5386 err = i40e_up_complete(vsi);
5387
5388 return err;
5389}
5390
5391/**
5392 * i40e_down - Shutdown the connection processing
5393 * @vsi: the VSI being stopped
5394 **/
5395void i40e_down(struct i40e_vsi *vsi)
5396{
5397 int i;
5398
5399 /* It is assumed that the caller of this function
5400 * sets the vsi->state __I40E_DOWN bit.
5401 */
5402 if (vsi->netdev) {
5403 netif_carrier_off(vsi->netdev);
5404 netif_tx_disable(vsi->netdev);
5405 }
5406 i40e_vsi_disable_irq(vsi);
Filip Sadowski3aa7b742016-10-11 15:26:58 -07005407 i40e_vsi_stop_rings(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005408 i40e_napi_disable_all(vsi);
5409
5410 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00005411 i40e_clean_tx_ring(vsi->tx_rings[i]);
5412 i40e_clean_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005413 }
Catherine Sullivanf980d442016-05-16 10:26:34 -07005414
5415 i40e_notify_client_of_netdev_close(vsi, false);
5416
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005417}
5418
5419/**
5420 * i40e_setup_tc - configure multiple traffic classes
5421 * @netdev: net device to configure
5422 * @tc: number of traffic classes to enable
5423 **/
5424static int i40e_setup_tc(struct net_device *netdev, u8 tc)
5425{
5426 struct i40e_netdev_priv *np = netdev_priv(netdev);
5427 struct i40e_vsi *vsi = np->vsi;
5428 struct i40e_pf *pf = vsi->back;
5429 u8 enabled_tc = 0;
5430 int ret = -EINVAL;
5431 int i;
5432
5433 /* Check if DCB enabled to continue */
5434 if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
5435 netdev_info(netdev, "DCB is not enabled for adapter\n");
5436 goto exit;
5437 }
5438
5439 /* Check if MFP enabled */
5440 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
5441 netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
5442 goto exit;
5443 }
5444
5445 /* Check whether tc count is within enabled limit */
5446 if (tc > i40e_pf_get_num_tc(pf)) {
5447 netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
5448 goto exit;
5449 }
5450
5451 /* Generate TC map for number of tc requested */
5452 for (i = 0; i < tc; i++)
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08005453 enabled_tc |= BIT(i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005454
5455 /* Requesting same TC configuration as already enabled */
5456 if (enabled_tc == vsi->tc_config.enabled_tc)
5457 return 0;
5458
5459 /* Quiesce VSI queues */
5460 i40e_quiesce_vsi(vsi);
5461
5462 /* Configure VSI for enabled TCs */
5463 ret = i40e_vsi_config_tc(vsi, enabled_tc);
5464 if (ret) {
5465 netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
5466 vsi->seid);
5467 goto exit;
5468 }
5469
5470 /* Unquiesce VSI */
5471 i40e_unquiesce_vsi(vsi);
5472
5473exit:
5474 return ret;
5475}
5476
John Fastabende4c67342016-02-16 21:16:15 -08005477#ifdef I40E_FCOE
John Fastabend16e5cc62016-02-16 21:16:43 -08005478int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
5479 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -08005480#else
John Fastabend16e5cc62016-02-16 21:16:43 -08005481static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
5482 struct tc_to_netdev *tc)
John Fastabende4c67342016-02-16 21:16:15 -08005483#endif
5484{
John Fastabend16e5cc62016-02-16 21:16:43 -08005485 if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO)
John Fastabende4c67342016-02-16 21:16:15 -08005486 return -EINVAL;
John Fastabend16e5cc62016-02-16 21:16:43 -08005487 return i40e_setup_tc(netdev, tc->tc);
John Fastabende4c67342016-02-16 21:16:15 -08005488}
5489
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005490/**
5491 * i40e_open - Called when a network interface is made active
5492 * @netdev: network interface device structure
5493 *
5494 * The open entry point is called when a network interface is made
5495 * active by the system (IFF_UP). At this point all resources needed
5496 * for transmit and receive operations are allocated, the interrupt
5497 * handler is registered with the OS, the netdev watchdog subtask is
5498 * enabled, and the stack is notified that the interface is ready.
5499 *
5500 * Returns 0 on success, negative value on failure
5501 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005502int i40e_open(struct net_device *netdev)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005503{
5504 struct i40e_netdev_priv *np = netdev_priv(netdev);
5505 struct i40e_vsi *vsi = np->vsi;
5506 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005507 int err;
5508
Shannon Nelson4eb3f762014-03-06 08:59:58 +00005509 /* disallow open during test or if eeprom is broken */
5510 if (test_bit(__I40E_TESTING, &pf->state) ||
5511 test_bit(__I40E_BAD_EEPROM, &pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005512 return -EBUSY;
5513
5514 netif_carrier_off(netdev);
5515
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005516 err = i40e_vsi_open(vsi);
5517 if (err)
5518 return err;
5519
Jesse Brandeburg059dab62014-04-01 09:07:20 +00005520 /* configure global TSO hardware offload settings */
5521 wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
5522 TCP_FLAG_FIN) >> 16);
5523 wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
5524 TCP_FLAG_FIN |
5525 TCP_FLAG_CWR) >> 16);
5526 wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
5527
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07005528 udp_tunnel_get_rx_info(netdev);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06005529
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005530 return 0;
5531}
5532
5533/**
5534 * i40e_vsi_open -
5535 * @vsi: the VSI to open
5536 *
5537 * Finish initialization of the VSI.
5538 *
5539 * Returns 0 on success, negative value on failure
5540 **/
5541int i40e_vsi_open(struct i40e_vsi *vsi)
5542{
5543 struct i40e_pf *pf = vsi->back;
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00005544 char int_name[I40E_INT_NAME_STR_LEN];
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005545 int err;
5546
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005547 /* allocate descriptors */
5548 err = i40e_vsi_setup_tx_resources(vsi);
5549 if (err)
5550 goto err_setup_tx;
5551 err = i40e_vsi_setup_rx_resources(vsi);
5552 if (err)
5553 goto err_setup_rx;
5554
5555 err = i40e_vsi_configure(vsi);
5556 if (err)
5557 goto err_setup_rx;
5558
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00005559 if (vsi->netdev) {
5560 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
5561 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
5562 err = i40e_vsi_request_irq(vsi, int_name);
5563 if (err)
5564 goto err_setup_rx;
5565
5566 /* Notify the stack of the actual queue counts. */
5567 err = netif_set_real_num_tx_queues(vsi->netdev,
5568 vsi->num_queue_pairs);
5569 if (err)
5570 goto err_set_queues;
5571
5572 err = netif_set_real_num_rx_queues(vsi->netdev,
5573 vsi->num_queue_pairs);
5574 if (err)
5575 goto err_set_queues;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005576
5577 } else if (vsi->type == I40E_VSI_FDIR) {
Carolyn Wybornye240f672014-12-11 07:06:37 +00005578 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +00005579 dev_driver_string(&pf->pdev->dev),
5580 dev_name(&pf->pdev->dev));
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005581 err = i40e_vsi_request_irq(vsi, int_name);
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +00005582
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00005583 } else {
Jean Sacrence9ccb12014-05-01 14:31:18 +00005584 err = -EINVAL;
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00005585 goto err_setup_rx;
5586 }
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00005587
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005588 err = i40e_up_complete(vsi);
5589 if (err)
5590 goto err_up_complete;
5591
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005592 return 0;
5593
5594err_up_complete:
5595 i40e_down(vsi);
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00005596err_set_queues:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005597 i40e_vsi_free_irq(vsi);
5598err_setup_rx:
5599 i40e_vsi_free_rx_resources(vsi);
5600err_setup_tx:
5601 i40e_vsi_free_tx_resources(vsi);
5602 if (vsi == pf->vsi[pf->lan_vsi])
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005603 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005604
5605 return err;
5606}
5607
5608/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005609 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00005610 * @pf: Pointer to PF
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005611 *
5612 * This function destroys the hlist where all the Flow Director
5613 * filters were saved.
5614 **/
5615static void i40e_fdir_filter_exit(struct i40e_pf *pf)
5616{
5617 struct i40e_fdir_filter *filter;
5618 struct hlist_node *node2;
5619
5620 hlist_for_each_entry_safe(filter, node2,
5621 &pf->fdir_filter_list, fdir_node) {
5622 hlist_del(&filter->fdir_node);
5623 kfree(filter);
5624 }
5625 pf->fdir_pf_active_filters = 0;
5626}
5627
5628/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005629 * i40e_close - Disables a network interface
5630 * @netdev: network interface device structure
5631 *
5632 * The close entry point is called when an interface is de-activated
5633 * by the OS. The hardware is still under the driver's control, but
5634 * this netdev interface is disabled.
5635 *
5636 * Returns 0, this is not allowed to fail
5637 **/
Vasu Dev38e00432014-08-01 13:27:03 -07005638int i40e_close(struct net_device *netdev)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005639{
5640 struct i40e_netdev_priv *np = netdev_priv(netdev);
5641 struct i40e_vsi *vsi = np->vsi;
5642
Shannon Nelson90ef8d42014-03-14 07:32:26 +00005643 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005644
5645 return 0;
5646}
5647
5648/**
5649 * i40e_do_reset - Start a PF or Core Reset sequence
5650 * @pf: board private structure
5651 * @reset_flags: which reset is requested
5652 *
5653 * The essential difference in resets is that the PF Reset
5654 * doesn't clear the packet buffers, doesn't reset the PE
5655 * firmware, and doesn't bother the other PFs on the chip.
5656 **/
5657void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
5658{
5659 u32 val;
5660
5661 WARN_ON(in_interrupt());
5662
Mitch Williams263fc482014-04-23 04:50:11 +00005663
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005664 /* do the biggest reset indicated */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005665 if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005666
5667 /* Request a Global Reset
5668 *
5669 * This will start the chip's countdown to the actual full
5670 * chip reset event, and a warning interrupt to be sent
5671 * to all PFs, including the requestor. Our handler
5672 * for the warning interrupt will deal with the shutdown
5673 * and recovery of the switch setup.
5674 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005675 dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005676 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5677 val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
5678 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5679
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005680 } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005681
5682 /* Request a Core Reset
5683 *
5684 * Same as Global Reset, except does *not* include the MAC/PHY
5685 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005686 dev_dbg(&pf->pdev->dev, "CoreR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005687 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
5688 val |= I40E_GLGEN_RTRIG_CORER_MASK;
5689 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
5690 i40e_flush(&pf->hw);
5691
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005692 } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005693
5694 /* Request a PF Reset
5695 *
5696 * Resets only the PF-specific registers
5697 *
5698 * This goes directly to the tear-down and rebuild of
5699 * the switch, since we need to do all the recovery as
5700 * for the Core Reset.
5701 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005702 dev_dbg(&pf->pdev->dev, "PFR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005703 i40e_handle_reset_warning(pf);
5704
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005705 } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005706 int v;
5707
5708 /* Find the VSI(s) that requested a re-init */
5709 dev_info(&pf->pdev->dev,
5710 "VSI reinit requested\n");
Mitch Williams505682c2014-05-20 08:01:37 +00005711 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005712 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04005713
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005714 if (vsi != NULL &&
5715 test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
5716 i40e_vsi_reinit_locked(pf->vsi[v]);
5717 clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
5718 }
5719 }
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04005720 } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005721 int v;
5722
5723 /* Find the VSI(s) that needs to be brought down */
5724 dev_info(&pf->pdev->dev, "VSI down requested\n");
5725 for (v = 0; v < pf->num_alloc_vsi; v++) {
5726 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04005727
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005728 if (vsi != NULL &&
5729 test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) {
5730 set_bit(__I40E_DOWN, &vsi->state);
5731 i40e_down(vsi);
5732 clear_bit(__I40E_DOWN_REQUESTED, &vsi->state);
5733 }
5734 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005735 } else {
5736 dev_info(&pf->pdev->dev,
5737 "bad reset request 0x%08x\n", reset_flags);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005738 }
5739}
5740
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005741#ifdef CONFIG_I40E_DCB
5742/**
5743 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
5744 * @pf: board private structure
5745 * @old_cfg: current DCB config
5746 * @new_cfg: new DCB config
5747 **/
5748bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
5749 struct i40e_dcbx_config *old_cfg,
5750 struct i40e_dcbx_config *new_cfg)
5751{
5752 bool need_reconfig = false;
5753
5754 /* Check if ETS configuration has changed */
5755 if (memcmp(&new_cfg->etscfg,
5756 &old_cfg->etscfg,
5757 sizeof(new_cfg->etscfg))) {
5758 /* If Priority Table has changed reconfig is needed */
5759 if (memcmp(&new_cfg->etscfg.prioritytable,
5760 &old_cfg->etscfg.prioritytable,
5761 sizeof(new_cfg->etscfg.prioritytable))) {
5762 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005763 dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005764 }
5765
5766 if (memcmp(&new_cfg->etscfg.tcbwtable,
5767 &old_cfg->etscfg.tcbwtable,
5768 sizeof(new_cfg->etscfg.tcbwtable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005769 dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005770
5771 if (memcmp(&new_cfg->etscfg.tsatable,
5772 &old_cfg->etscfg.tsatable,
5773 sizeof(new_cfg->etscfg.tsatable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005774 dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005775 }
5776
5777 /* Check if PFC configuration has changed */
5778 if (memcmp(&new_cfg->pfc,
5779 &old_cfg->pfc,
5780 sizeof(new_cfg->pfc))) {
5781 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005782 dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005783 }
5784
5785 /* Check if APP Table has changed */
5786 if (memcmp(&new_cfg->app,
5787 &old_cfg->app,
Dave Jones3d9667a2014-01-27 23:11:09 -05005788 sizeof(new_cfg->app))) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005789 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005790 dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
Dave Jones3d9667a2014-01-27 23:11:09 -05005791 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005792
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005793 dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005794 return need_reconfig;
5795}
5796
5797/**
5798 * i40e_handle_lldp_event - Handle LLDP Change MIB event
5799 * @pf: board private structure
5800 * @e: event info posted on ARQ
5801 **/
5802static int i40e_handle_lldp_event(struct i40e_pf *pf,
5803 struct i40e_arq_event_info *e)
5804{
5805 struct i40e_aqc_lldp_get_mib *mib =
5806 (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
5807 struct i40e_hw *hw = &pf->hw;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005808 struct i40e_dcbx_config tmp_dcbx_cfg;
5809 bool need_reconfig = false;
5810 int ret = 0;
5811 u8 type;
5812
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005813 /* Not DCB capable or capability disabled */
David Ertmanea6acb72016-09-20 07:10:50 -07005814 if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005815 return ret;
5816
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005817 /* Ignore if event is not for Nearest Bridge */
5818 type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
5819 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005820 dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005821 if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
5822 return ret;
5823
5824 /* Check MIB Type and return if event for Remote MIB update */
5825 type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005826 dev_dbg(&pf->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04005827 "LLDP event mib type %s\n", type ? "remote" : "local");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005828 if (type == I40E_AQ_LLDP_MIB_REMOTE) {
5829 /* Update the remote cached instance and return */
5830 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
5831 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
5832 &hw->remote_dcbx_config);
5833 goto exit;
5834 }
5835
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005836 /* Store the old configuration */
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07005837 tmp_dcbx_cfg = hw->local_dcbx_config;
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005838
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005839 /* Reset the old DCBx configuration data */
5840 memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00005841 /* Get updated DCBX data from firmware */
5842 ret = i40e_get_dcb_config(&pf->hw);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005843 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04005844 dev_info(&pf->pdev->dev,
5845 "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
5846 i40e_stat_str(&pf->hw, ret),
5847 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005848 goto exit;
5849 }
5850
5851 /* No change detected in DCBX configs */
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005852 if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
5853 sizeof(tmp_dcbx_cfg))) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005854 dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005855 goto exit;
5856 }
5857
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005858 need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
5859 &hw->local_dcbx_config);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005860
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005861 i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005862
5863 if (!need_reconfig)
5864 goto exit;
5865
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005866 /* Enable DCB tagging only when more than one TC */
Neerav Parikh750fcbc2015-02-24 06:58:47 +00005867 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
Neerav Parikh4d9b6042014-05-22 06:31:51 +00005868 pf->flags |= I40E_FLAG_DCB_ENABLED;
5869 else
5870 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
5871
Neerav Parikh69129dc2014-11-12 00:18:46 +00005872 set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005873 /* Reconfiguration needed quiesce all VSIs */
5874 i40e_pf_quiesce_all_vsi(pf);
5875
5876 /* Changes in configuration update VEB/VSI */
5877 i40e_dcb_reconfigure(pf);
5878
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005879 ret = i40e_resume_port_tx(pf);
5880
Neerav Parikh69129dc2014-11-12 00:18:46 +00005881 clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005882 /* In case of error no point in resuming VSIs */
Neerav Parikh69129dc2014-11-12 00:18:46 +00005883 if (ret)
5884 goto exit;
5885
Neerav Parikh3fe06f42016-02-17 16:12:15 -08005886 /* Wait for the PF's queues to be disabled */
5887 ret = i40e_pf_wait_queues_disabled(pf);
Parikh, Neerav11e47702015-02-21 06:43:55 +00005888 if (ret) {
5889 /* Schedule PF reset to recover */
5890 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
5891 i40e_service_event_schedule(pf);
5892 } else {
Neerav Parikh2fd75f32014-11-12 00:18:20 +00005893 i40e_pf_unquiesce_all_vsi(pf);
Neerav Parikh85a1aab2016-06-07 09:14:55 -07005894 /* Notify the client for the DCB changes */
5895 i40e_notify_client_of_l2_param_changes(pf->vsi[pf->lan_vsi]);
Parikh, Neerav11e47702015-02-21 06:43:55 +00005896 }
5897
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005898exit:
5899 return ret;
5900}
5901#endif /* CONFIG_I40E_DCB */
5902
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005903/**
Anjali Singhai Jain23326182013-11-26 10:49:22 +00005904 * i40e_do_reset_safe - Protected reset path for userland calls.
5905 * @pf: board private structure
5906 * @reset_flags: which reset is requested
5907 *
5908 **/
5909void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
5910{
5911 rtnl_lock();
5912 i40e_do_reset(pf, reset_flags);
5913 rtnl_unlock();
5914}
5915
5916/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005917 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
5918 * @pf: board private structure
5919 * @e: event info posted on ARQ
5920 *
5921 * Handler for LAN Queue Overflow Event generated by the firmware for PF
5922 * and VF queues
5923 **/
5924static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
5925 struct i40e_arq_event_info *e)
5926{
5927 struct i40e_aqc_lan_overflow *data =
5928 (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
5929 u32 queue = le32_to_cpu(data->prtdcb_rupto);
5930 u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
5931 struct i40e_hw *hw = &pf->hw;
5932 struct i40e_vf *vf;
5933 u16 vf_id;
5934
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005935 dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
5936 queue, qtx_ctl);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005937
5938 /* Queue belongs to VF, find the VF and issue VF reset */
5939 if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
5940 >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
5941 vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
5942 >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
5943 vf_id -= hw->func_caps.vf_base_id;
5944 vf = &pf->vf[vf_id];
5945 i40e_vc_notify_vf_reset(vf);
5946 /* Allow VF to process pending reset notification */
5947 msleep(20);
5948 i40e_reset_vf(vf, false);
5949 }
5950}
5951
5952/**
5953 * i40e_service_event_complete - Finish up the service event
5954 * @pf: board private structure
5955 **/
5956static void i40e_service_event_complete(struct i40e_pf *pf)
5957{
Shannon Nelsonb875f992015-10-21 19:47:03 -04005958 WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005959
5960 /* flush memory to make sure state is correct before next watchog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005961 smp_mb__before_atomic();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005962 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
5963}
5964
5965/**
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005966 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
5967 * @pf: board private structure
5968 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005969u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005970{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005971 u32 val, fcnt_prog;
Anjali Singhai Jain12957382014-06-04 04:22:47 +00005972
5973 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
5974 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
5975 return fcnt_prog;
5976}
5977
5978/**
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005979 * i40e_get_current_fd_count - Get total FD filters programmed for this PF
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005980 * @pf: board private structure
5981 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005982u32 i40e_get_current_fd_count(struct i40e_pf *pf)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005983{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005984 u32 val, fcnt_prog;
5985
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005986 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
5987 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
5988 ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
5989 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
5990 return fcnt_prog;
5991}
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00005992
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005993/**
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00005994 * i40e_get_global_fd_count - Get total FD filters programmed on device
5995 * @pf: board private structure
5996 **/
5997u32 i40e_get_global_fd_count(struct i40e_pf *pf)
5998{
5999 u32 val, fcnt_prog;
6000
6001 val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
6002 fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
6003 ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
6004 I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
6005 return fcnt_prog;
6006}
6007
6008/**
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006009 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
6010 * @pf: board private structure
6011 **/
6012void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
6013{
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04006014 struct i40e_fdir_filter *filter;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006015 u32 fcnt_prog, fcnt_avail;
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04006016 struct hlist_node *node;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006017
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006018 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
6019 return;
6020
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006021 /* Check if, FD SB or ATR was auto disabled and if there is enough room
6022 * to re-enable
6023 */
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006024 fcnt_prog = i40e_get_global_fd_count(pf);
Anjali Singhai Jain12957382014-06-04 04:22:47 +00006025 fcnt_avail = pf->fdir_pf_filter_count;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006026 if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
6027 (pf->fd_add_err == 0) ||
6028 (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006029 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
6030 (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
6031 pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04006032 if (I40E_DEBUG_FD & pf->hw.debug_mask)
6033 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 +00006034 }
6035 }
Jacob Kellera3417d22016-09-06 18:05:10 -07006036
6037 /* Wait for some more space to be available to turn on ATR. We also
6038 * must check that no existing ntuple rules for TCP are in effect
6039 */
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006040 if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
6041 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
Jacob Kellera3417d22016-09-06 18:05:10 -07006042 (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED) &&
6043 (pf->fd_tcp_rule == 0)) {
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006044 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Anjali Singhai Jain2e4875e2015-04-16 20:06:06 -04006045 if (I40E_DEBUG_FD & pf->hw.debug_mask)
Jacob Kellera3417d22016-09-06 18:05:10 -07006046 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 +00006047 }
6048 }
Carolyn Wyborny3487b6c2015-08-27 11:42:38 -04006049
6050 /* if hw had a problem adding a filter, delete it */
6051 if (pf->fd_inv > 0) {
6052 hlist_for_each_entry_safe(filter, node,
6053 &pf->fdir_filter_list, fdir_node) {
6054 if (filter->fd_id == pf->fd_inv) {
6055 hlist_del(&filter->fdir_node);
6056 kfree(filter);
6057 pf->fdir_pf_active_filters--;
6058 }
6059 }
6060 }
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006061}
6062
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006063#define I40E_MIN_FD_FLUSH_INTERVAL 10
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006064#define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006065/**
6066 * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
6067 * @pf: board private structure
6068 **/
6069static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
6070{
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006071 unsigned long min_flush_time;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006072 int flush_wait_retry = 50;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006073 bool disable_atr = false;
6074 int fd_room;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006075 int reg;
6076
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006077 if (!time_after(jiffies, pf->fd_flush_timestamp +
6078 (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
6079 return;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006080
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006081 /* If the flush is happening too quick and we have mostly SB rules we
6082 * should not re-enable ATR for some time.
6083 */
6084 min_flush_time = pf->fd_flush_timestamp +
6085 (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
6086 fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006087
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006088 if (!(time_after(jiffies, min_flush_time)) &&
6089 (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
6090 if (I40E_DEBUG_FD & pf->hw.debug_mask)
6091 dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
6092 disable_atr = true;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006093 }
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006094
6095 pf->fd_flush_timestamp = jiffies;
Jacob Keller234dc4e2016-09-06 18:05:09 -07006096 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006097 /* flush all filters */
6098 wr32(&pf->hw, I40E_PFQF_CTL_1,
6099 I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
6100 i40e_flush(&pf->hw);
6101 pf->fd_flush_cnt++;
6102 pf->fd_add_err = 0;
6103 do {
6104 /* Check FD flush status every 5-6msec */
6105 usleep_range(5000, 6000);
6106 reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
6107 if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
6108 break;
6109 } while (flush_wait_retry--);
6110 if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
6111 dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
6112 } else {
6113 /* replay sideband filters */
6114 i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
6115 if (!disable_atr)
Jacob Keller234dc4e2016-09-06 18:05:09 -07006116 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Jesse Brandeburga5fdaf32015-08-28 17:55:56 -04006117 clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
6118 if (I40E_DEBUG_FD & pf->hw.debug_mask)
6119 dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
6120 }
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006121}
6122
6123/**
6124 * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
6125 * @pf: board private structure
6126 **/
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006127u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006128{
6129 return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
6130}
6131
6132/* We can see up to 256 filter programming desc in transit if the filters are
6133 * being applied really fast; before we see the first
6134 * filter miss error on Rx queue 0. Accumulating enough error messages before
6135 * reacting will make sure we don't cause flush too often.
6136 */
6137#define I40E_MAX_FD_PROGRAM_ERROR 256
6138
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006139/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006140 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
6141 * @pf: board private structure
6142 **/
6143static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
6144{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006145
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006146 /* if interface is down do nothing */
6147 if (test_bit(__I40E_DOWN, &pf->state))
6148 return;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006149
Anjali Singhai Jain04294e32015-02-27 09:15:28 +00006150 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00006151 i40e_fdir_flush_and_replay(pf);
6152
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00006153 i40e_fdir_check_and_reenable(pf);
6154
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006155}
6156
6157/**
6158 * i40e_vsi_link_event - notify VSI of a link event
6159 * @vsi: vsi to be notified
6160 * @link_up: link up or down
6161 **/
6162static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
6163{
Jesse Brandeburg32b5b812014-08-12 06:33:14 +00006164 if (!vsi || test_bit(__I40E_DOWN, &vsi->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006165 return;
6166
6167 switch (vsi->type) {
6168 case I40E_VSI_MAIN:
Vasu Dev38e00432014-08-01 13:27:03 -07006169#ifdef I40E_FCOE
6170 case I40E_VSI_FCOE:
6171#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006172 if (!vsi->netdev || !vsi->netdev_registered)
6173 break;
6174
6175 if (link_up) {
6176 netif_carrier_on(vsi->netdev);
6177 netif_tx_wake_all_queues(vsi->netdev);
6178 } else {
6179 netif_carrier_off(vsi->netdev);
6180 netif_tx_stop_all_queues(vsi->netdev);
6181 }
6182 break;
6183
6184 case I40E_VSI_SRIOV:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006185 case I40E_VSI_VMDQ2:
6186 case I40E_VSI_CTRL:
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06006187 case I40E_VSI_IWARP:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006188 case I40E_VSI_MIRROR:
6189 default:
6190 /* there is no notification for other VSIs */
6191 break;
6192 }
6193}
6194
6195/**
6196 * i40e_veb_link_event - notify elements on the veb of a link event
6197 * @veb: veb to be notified
6198 * @link_up: link up or down
6199 **/
6200static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
6201{
6202 struct i40e_pf *pf;
6203 int i;
6204
6205 if (!veb || !veb->pf)
6206 return;
6207 pf = veb->pf;
6208
6209 /* depth first... */
6210 for (i = 0; i < I40E_MAX_VEB; i++)
6211 if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
6212 i40e_veb_link_event(pf->veb[i], link_up);
6213
6214 /* ... now the local VSIs */
Mitch Williams505682c2014-05-20 08:01:37 +00006215 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006216 if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
6217 i40e_vsi_link_event(pf->vsi[i], link_up);
6218}
6219
6220/**
6221 * i40e_link_event - Update netif_carrier status
6222 * @pf: board private structure
6223 **/
6224static void i40e_link_event(struct i40e_pf *pf)
6225{
Mitch Williams320684c2014-10-17 03:14:43 +00006226 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006227 u8 new_link_speed, old_link_speed;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006228 i40e_status status;
6229 bool new_link, old_link;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006230
Catherine Sullivan1f9610e2015-10-21 19:47:09 -04006231 /* save off old link status information */
6232 pf->hw.phy.link_info_old = pf->hw.phy.link_info;
6233
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006234 /* set this to force the get_link_status call to refresh state */
6235 pf->hw.phy.get_link_info = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006236
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006237 old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04006238
6239 status = i40e_get_link_status(&pf->hw, &new_link);
6240 if (status) {
6241 dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
6242 status);
6243 return;
6244 }
6245
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006246 old_link_speed = pf->hw.phy.link_info_old.link_speed;
6247 new_link_speed = pf->hw.phy.link_info.link_speed;
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006248
6249 if (new_link == old_link &&
Catherine Sullivanfef59dd2014-12-11 07:06:33 +00006250 new_link_speed == old_link_speed &&
Mitch Williams320684c2014-10-17 03:14:43 +00006251 (test_bit(__I40E_DOWN, &vsi->state) ||
6252 new_link == netif_carrier_ok(vsi->netdev)))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006253 return;
Mitch Williams320684c2014-10-17 03:14:43 +00006254
6255 if (!test_bit(__I40E_DOWN, &vsi->state))
6256 i40e_print_link_message(vsi, new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006257
6258 /* Notify the base of the switch tree connected to
6259 * the link. Floating VEBs are not notified.
6260 */
6261 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
6262 i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
6263 else
Mitch Williams320684c2014-10-17 03:14:43 +00006264 i40e_vsi_link_event(vsi, new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006265
6266 if (pf->vf)
6267 i40e_vc_notify_link_state(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00006268
6269 if (pf->flags & I40E_FLAG_PTP)
6270 i40e_ptp_set_increment(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006271}
6272
6273/**
Shannon Nelson21536712014-10-25 10:35:25 +00006274 * i40e_watchdog_subtask - periodic checks not using event driven response
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006275 * @pf: board private structure
6276 **/
6277static void i40e_watchdog_subtask(struct i40e_pf *pf)
6278{
6279 int i;
6280
6281 /* if interface is down do nothing */
6282 if (test_bit(__I40E_DOWN, &pf->state) ||
6283 test_bit(__I40E_CONFIG_BUSY, &pf->state))
6284 return;
6285
Shannon Nelson21536712014-10-25 10:35:25 +00006286 /* make sure we don't do these things too often */
6287 if (time_before(jiffies, (pf->service_timer_previous +
6288 pf->service_timer_period)))
6289 return;
6290 pf->service_timer_previous = jiffies;
6291
Shannon Nelson9ac77262015-08-27 11:42:40 -04006292 if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED)
6293 i40e_link_event(pf);
Shannon Nelson21536712014-10-25 10:35:25 +00006294
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006295 /* Update the stats for active netdevs so the network stack
6296 * can look at updated numbers whenever it cares to
6297 */
Mitch Williams505682c2014-05-20 08:01:37 +00006298 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006299 if (pf->vsi[i] && pf->vsi[i]->netdev)
6300 i40e_update_stats(pf->vsi[i]);
6301
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04006302 if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
6303 /* Update the stats for the active switching components */
6304 for (i = 0; i < I40E_MAX_VEB; i++)
6305 if (pf->veb[i])
6306 i40e_update_veb_stats(pf->veb[i]);
6307 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00006308
6309 i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006310}
6311
6312/**
6313 * i40e_reset_subtask - Set up for resetting the device and driver
6314 * @pf: board private structure
6315 **/
6316static void i40e_reset_subtask(struct i40e_pf *pf)
6317{
6318 u32 reset_flags = 0;
6319
Anjali Singhai Jain23326182013-11-26 10:49:22 +00006320 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006321 if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006322 reset_flags |= BIT(__I40E_REINIT_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006323 clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
6324 }
6325 if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006326 reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006327 clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
6328 }
6329 if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006330 reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006331 clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
6332 }
6333 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006334 reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006335 clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
6336 }
Neerav Parikhb5d06f02014-06-03 23:50:17 +00006337 if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) {
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -08006338 reset_flags |= BIT(__I40E_DOWN_REQUESTED);
Neerav Parikhb5d06f02014-06-03 23:50:17 +00006339 clear_bit(__I40E_DOWN_REQUESTED, &pf->state);
6340 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006341
6342 /* If there's a recovery already waiting, it takes
6343 * precedence before starting a new reset sequence.
6344 */
6345 if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
6346 i40e_handle_reset_warning(pf);
Anjali Singhai Jain23326182013-11-26 10:49:22 +00006347 goto unlock;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006348 }
6349
6350 /* If we're already down or resetting, just bail */
6351 if (reset_flags &&
6352 !test_bit(__I40E_DOWN, &pf->state) &&
6353 !test_bit(__I40E_CONFIG_BUSY, &pf->state))
6354 i40e_do_reset(pf, reset_flags);
Anjali Singhai Jain23326182013-11-26 10:49:22 +00006355
6356unlock:
6357 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006358}
6359
6360/**
6361 * i40e_handle_link_event - Handle link event
6362 * @pf: board private structure
6363 * @e: event info posted on ARQ
6364 **/
6365static void i40e_handle_link_event(struct i40e_pf *pf,
6366 struct i40e_arq_event_info *e)
6367{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006368 struct i40e_aqc_get_link_status *status =
6369 (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006370
Jesse Brandeburg1e701e02014-09-13 07:40:42 +00006371 /* Do a new status request to re-enable LSE reporting
6372 * and load new status information into the hw struct
6373 * This completely ignores any state information
6374 * in the ARQ event info, instead choosing to always
6375 * issue the AQ update link status command.
6376 */
6377 i40e_link_event(pf);
6378
Carolyn Wyborny7b592f62014-07-10 07:58:19 +00006379 /* check for unqualified module, if link is down */
6380 if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
6381 (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
6382 (!(status->link_info & I40E_AQ_LINK_UP)))
6383 dev_err(&pf->pdev->dev,
6384 "The driver failed to link because an unqualified module was detected.\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006385}
6386
6387/**
6388 * i40e_clean_adminq_subtask - Clean the AdminQ rings
6389 * @pf: board private structure
6390 **/
6391static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
6392{
6393 struct i40e_arq_event_info event;
6394 struct i40e_hw *hw = &pf->hw;
6395 u16 pending, i = 0;
6396 i40e_status ret;
6397 u16 opcode;
Shannon Nelson86df2422014-05-20 08:01:35 +00006398 u32 oldval;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006399 u32 val;
6400
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006401 /* Do not run clean AQ when PF reset fails */
6402 if (test_bit(__I40E_RESET_FAILED, &pf->state))
6403 return;
6404
Shannon Nelson86df2422014-05-20 08:01:35 +00006405 /* check for error indications */
6406 val = rd32(&pf->hw, pf->hw.aq.arq.len);
6407 oldval = val;
6408 if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006409 if (hw->debug_mask & I40E_DEBUG_AQ)
6410 dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006411 val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
6412 }
6413 if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006414 if (hw->debug_mask & I40E_DEBUG_AQ)
6415 dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006416 val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
Mitch Williams1d0a4ad2015-12-23 12:05:48 -08006417 pf->arq_overflows++;
Shannon Nelson86df2422014-05-20 08:01:35 +00006418 }
6419 if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006420 if (hw->debug_mask & I40E_DEBUG_AQ)
6421 dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006422 val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
6423 }
6424 if (oldval != val)
6425 wr32(&pf->hw, pf->hw.aq.arq.len, val);
6426
6427 val = rd32(&pf->hw, pf->hw.aq.asq.len);
6428 oldval = val;
6429 if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006430 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6431 dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006432 val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
6433 }
6434 if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006435 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6436 dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006437 val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
6438 }
6439 if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
Mitch Williams75eb73c2015-11-19 11:34:21 -08006440 if (pf->hw.debug_mask & I40E_DEBUG_AQ)
6441 dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
Shannon Nelson86df2422014-05-20 08:01:35 +00006442 val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
6443 }
6444 if (oldval != val)
6445 wr32(&pf->hw, pf->hw.aq.asq.len, val);
6446
Mitch Williams1001dc32014-11-11 20:02:19 +00006447 event.buf_len = I40E_MAX_AQ_BUF_SIZE;
6448 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006449 if (!event.msg_buf)
6450 return;
6451
6452 do {
6453 ret = i40e_clean_arq_element(hw, &event, &pending);
Mitch Williams56497972014-06-04 08:45:18 +00006454 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006455 break;
Mitch Williams56497972014-06-04 08:45:18 +00006456 else if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006457 dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
6458 break;
6459 }
6460
6461 opcode = le16_to_cpu(event.desc.opcode);
6462 switch (opcode) {
6463
6464 case i40e_aqc_opc_get_link_status:
6465 i40e_handle_link_event(pf, &event);
6466 break;
6467 case i40e_aqc_opc_send_msg_to_pf:
6468 ret = i40e_vc_process_vf_msg(pf,
6469 le16_to_cpu(event.desc.retval),
6470 le32_to_cpu(event.desc.cookie_high),
6471 le32_to_cpu(event.desc.cookie_low),
6472 event.msg_buf,
Mitch Williams1001dc32014-11-11 20:02:19 +00006473 event.msg_len);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006474 break;
6475 case i40e_aqc_opc_lldp_update_mib:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006476 dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006477#ifdef CONFIG_I40E_DCB
6478 rtnl_lock();
6479 ret = i40e_handle_lldp_event(pf, &event);
6480 rtnl_unlock();
6481#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006482 break;
6483 case i40e_aqc_opc_event_lan_overflow:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006484 dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006485 i40e_handle_lan_overflow_event(pf, &event);
6486 break;
Shannon Nelson0467bc92013-12-18 13:45:58 +00006487 case i40e_aqc_opc_send_msg_to_peer:
6488 dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
6489 break;
Shannon Nelson91a0f932015-03-19 14:32:01 -07006490 case i40e_aqc_opc_nvm_erase:
6491 case i40e_aqc_opc_nvm_update:
Michal Kosiarz00ada502015-11-19 11:34:20 -08006492 case i40e_aqc_opc_oem_post_update:
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08006493 i40e_debug(&pf->hw, I40E_DEBUG_NVM,
6494 "ARQ NVM operation 0x%04x completed\n",
6495 opcode);
Shannon Nelson91a0f932015-03-19 14:32:01 -07006496 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006497 default:
6498 dev_info(&pf->pdev->dev,
Shannon Nelson56e5ca62016-03-10 14:59:48 -08006499 "ARQ: Unknown event 0x%04x ignored\n",
Shannon Nelson0467bc92013-12-18 13:45:58 +00006500 opcode);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006501 break;
6502 }
6503 } while (pending && (i++ < pf->adminq_work_limit));
6504
6505 clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
6506 /* re-enable Admin queue interrupt cause */
6507 val = rd32(hw, I40E_PFINT_ICR0_ENA);
6508 val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
6509 wr32(hw, I40E_PFINT_ICR0_ENA, val);
6510 i40e_flush(hw);
6511
6512 kfree(event.msg_buf);
6513}
6514
6515/**
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006516 * i40e_verify_eeprom - make sure eeprom is good to use
6517 * @pf: board private structure
6518 **/
6519static void i40e_verify_eeprom(struct i40e_pf *pf)
6520{
6521 int err;
6522
6523 err = i40e_diag_eeprom_test(&pf->hw);
6524 if (err) {
6525 /* retry in case of garbage read */
6526 err = i40e_diag_eeprom_test(&pf->hw);
6527 if (err) {
6528 dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
6529 err);
6530 set_bit(__I40E_BAD_EEPROM, &pf->state);
6531 }
6532 }
6533
6534 if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
6535 dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
6536 clear_bit(__I40E_BAD_EEPROM, &pf->state);
6537 }
6538}
6539
6540/**
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006541 * i40e_enable_pf_switch_lb
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00006542 * @pf: pointer to the PF structure
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006543 *
6544 * enable switch loop back or die - no point in a return value
6545 **/
6546static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
6547{
6548 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6549 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006550 int ret;
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006551
6552 ctxt.seid = pf->main_vsi_seid;
6553 ctxt.pf_num = pf->hw.pf_id;
6554 ctxt.vf_num = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006555 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6556 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006557 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006558 "couldn't get PF vsi config, err %s aq_err %s\n",
6559 i40e_stat_str(&pf->hw, ret),
6560 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006561 return;
6562 }
6563 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6564 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6565 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6566
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006567 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6568 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006569 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006570 "update vsi switch failed, err %s aq_err %s\n",
6571 i40e_stat_str(&pf->hw, ret),
6572 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006573 }
6574}
6575
6576/**
6577 * i40e_disable_pf_switch_lb
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00006578 * @pf: pointer to the PF structure
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006579 *
6580 * disable switch loop back or die - no point in a return value
6581 **/
6582static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
6583{
6584 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
6585 struct i40e_vsi_context ctxt;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006586 int ret;
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006587
6588 ctxt.seid = pf->main_vsi_seid;
6589 ctxt.pf_num = pf->hw.pf_id;
6590 ctxt.vf_num = 0;
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006591 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
6592 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006593 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006594 "couldn't get PF vsi config, err %s aq_err %s\n",
6595 i40e_stat_str(&pf->hw, ret),
6596 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006597 return;
6598 }
6599 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6600 ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6601 ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6602
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006603 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
6604 if (ret) {
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006605 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006606 "update vsi switch failed, err %s aq_err %s\n",
6607 i40e_stat_str(&pf->hw, ret),
6608 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Akeem G Abodunrin386a0af2015-02-27 09:15:25 +00006609 }
6610}
6611
6612/**
Neerav Parikh51616012015-02-06 08:52:14 +00006613 * i40e_config_bridge_mode - Configure the HW bridge mode
6614 * @veb: pointer to the bridge instance
6615 *
6616 * Configure the loop back mode for the LAN VSI that is downlink to the
6617 * specified HW bridge instance. It is expected this function is called
6618 * when a new HW bridge is instantiated.
6619 **/
6620static void i40e_config_bridge_mode(struct i40e_veb *veb)
6621{
6622 struct i40e_pf *pf = veb->pf;
6623
Shannon Nelson6dec1012015-09-28 14:12:30 -04006624 if (pf->hw.debug_mask & I40E_DEBUG_LAN)
6625 dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
6626 veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
Neerav Parikh51616012015-02-06 08:52:14 +00006627 if (veb->bridge_mode & BRIDGE_MODE_VEPA)
6628 i40e_disable_pf_switch_lb(pf);
6629 else
6630 i40e_enable_pf_switch_lb(pf);
6631}
6632
6633/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006634 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
6635 * @veb: pointer to the VEB instance
6636 *
6637 * This is a recursive function that first builds the attached VSIs then
6638 * recurses in to build the next layer of VEB. We track the connections
6639 * through our own index numbers because the seid's from the HW could
6640 * change across the reset.
6641 **/
6642static int i40e_reconstitute_veb(struct i40e_veb *veb)
6643{
6644 struct i40e_vsi *ctl_vsi = NULL;
6645 struct i40e_pf *pf = veb->pf;
6646 int v, veb_idx;
6647 int ret;
6648
6649 /* build VSI that owns this VEB, temporarily attached to base VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00006650 for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006651 if (pf->vsi[v] &&
6652 pf->vsi[v]->veb_idx == veb->idx &&
6653 pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
6654 ctl_vsi = pf->vsi[v];
6655 break;
6656 }
6657 }
6658 if (!ctl_vsi) {
6659 dev_info(&pf->pdev->dev,
6660 "missing owner VSI for veb_idx %d\n", veb->idx);
6661 ret = -ENOENT;
6662 goto end_reconstitute;
6663 }
6664 if (ctl_vsi != pf->vsi[pf->lan_vsi])
6665 ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
6666 ret = i40e_add_vsi(ctl_vsi);
6667 if (ret) {
6668 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006669 "rebuild of veb_idx %d owner VSI failed: %d\n",
6670 veb->idx, ret);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006671 goto end_reconstitute;
6672 }
6673 i40e_vsi_reset_stats(ctl_vsi);
6674
6675 /* create the VEB in the switch and move the VSI onto the VEB */
6676 ret = i40e_add_veb(veb, ctl_vsi);
6677 if (ret)
6678 goto end_reconstitute;
6679
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07006680 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
6681 veb->bridge_mode = BRIDGE_MODE_VEB;
6682 else
6683 veb->bridge_mode = BRIDGE_MODE_VEPA;
Neerav Parikh51616012015-02-06 08:52:14 +00006684 i40e_config_bridge_mode(veb);
Anjali Singhai Jainb64ba082014-11-13 03:06:15 +00006685
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006686 /* create the remaining VSIs attached to this VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00006687 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006688 if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
6689 continue;
6690
6691 if (pf->vsi[v]->veb_idx == veb->idx) {
6692 struct i40e_vsi *vsi = pf->vsi[v];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04006693
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006694 vsi->uplink_seid = veb->seid;
6695 ret = i40e_add_vsi(vsi);
6696 if (ret) {
6697 dev_info(&pf->pdev->dev,
6698 "rebuild of vsi_idx %d failed: %d\n",
6699 v, ret);
6700 goto end_reconstitute;
6701 }
6702 i40e_vsi_reset_stats(vsi);
6703 }
6704 }
6705
6706 /* create any VEBs attached to this VEB - RECURSION */
6707 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
6708 if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
6709 pf->veb[veb_idx]->uplink_seid = veb->seid;
6710 ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
6711 if (ret)
6712 break;
6713 }
6714 }
6715
6716end_reconstitute:
6717 return ret;
6718}
6719
6720/**
6721 * i40e_get_capabilities - get info about the HW
6722 * @pf: the PF struct
6723 **/
6724static int i40e_get_capabilities(struct i40e_pf *pf)
6725{
6726 struct i40e_aqc_list_capabilities_element_resp *cap_buf;
6727 u16 data_size;
6728 int buf_len;
6729 int err;
6730
6731 buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
6732 do {
6733 cap_buf = kzalloc(buf_len, GFP_KERNEL);
6734 if (!cap_buf)
6735 return -ENOMEM;
6736
6737 /* this loads the data into the hw struct for us */
6738 err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
6739 &data_size,
6740 i40e_aqc_opc_list_func_capabilities,
6741 NULL);
6742 /* data loaded, buffer no longer needed */
6743 kfree(cap_buf);
6744
6745 if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
6746 /* retry with a larger buffer */
6747 buf_len = data_size;
6748 } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
6749 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006750 "capability discovery failed, err %s aq_err %s\n",
6751 i40e_stat_str(&pf->hw, err),
6752 i40e_aq_str(&pf->hw,
6753 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006754 return -ENODEV;
6755 }
6756 } while (err);
6757
6758 if (pf->hw.debug_mask & I40E_DEBUG_USER)
6759 dev_info(&pf->pdev->dev,
6760 "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",
6761 pf->hw.pf_id, pf->hw.func_caps.num_vfs,
6762 pf->hw.func_caps.num_msix_vectors,
6763 pf->hw.func_caps.num_msix_vectors_vf,
6764 pf->hw.func_caps.fd_filters_guaranteed,
6765 pf->hw.func_caps.fd_filters_best_effort,
6766 pf->hw.func_caps.num_tx_qp,
6767 pf->hw.func_caps.num_vsis);
6768
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00006769#define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
6770 + pf->hw.func_caps.num_vfs)
6771 if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
6772 dev_info(&pf->pdev->dev,
6773 "got num_vsis %d, setting num_vsis to %d\n",
6774 pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
6775 pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
6776 }
6777
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006778 return 0;
6779}
6780
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006781static int i40e_vsi_clear(struct i40e_vsi *vsi);
6782
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006783/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006784 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006785 * @pf: board private structure
6786 **/
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006787static void i40e_fdir_sb_setup(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006788{
6789 struct i40e_vsi *vsi;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006790
Jesse Brandeburg407e0632014-06-03 23:50:12 +00006791 /* quick workaround for an NVM issue that leaves a critical register
6792 * uninitialized
6793 */
6794 if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
6795 static const u32 hkey[] = {
6796 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
6797 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
6798 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
6799 0x95b3a76d};
Alexander Duyck4b816442016-10-11 15:26:53 -07006800 int i;
Jesse Brandeburg407e0632014-06-03 23:50:12 +00006801
6802 for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
6803 wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
6804 }
6805
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006806 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006807 return;
6808
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006809 /* find existing VSI and see if it needs configuring */
Alexander Duyck4b816442016-10-11 15:26:53 -07006810 vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006811
6812 /* create a new VSI if none exists */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006813 if (!vsi) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006814 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
6815 pf->vsi[pf->lan_vsi]->seid, 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006816 if (!vsi) {
6817 dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006818 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
6819 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006820 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006821 }
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00006822
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006823 i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006824}
6825
6826/**
6827 * i40e_fdir_teardown - release the Flow Director resources
6828 * @pf: board private structure
6829 **/
6830static void i40e_fdir_teardown(struct i40e_pf *pf)
6831{
Alexander Duyck4b816442016-10-11 15:26:53 -07006832 struct i40e_vsi *vsi;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006833
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00006834 i40e_fdir_filter_exit(pf);
Alexander Duyck4b816442016-10-11 15:26:53 -07006835 vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
6836 if (vsi)
6837 i40e_vsi_release(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006838}
6839
6840/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006841 * i40e_prep_for_reset - prep for the core to reset
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006842 * @pf: board private structure
6843 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00006844 * Close up the VFs and other things in prep for PF Reset.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006845 **/
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006846static void i40e_prep_for_reset(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006847{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006848 struct i40e_hw *hw = &pf->hw;
Shannon Nelson60442de2014-04-23 04:50:13 +00006849 i40e_status ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006850 u32 v;
6851
6852 clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
6853 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006854 return;
Mitch Williamsd3ce57342016-03-10 14:59:46 -08006855 if (i40e_check_asq_alive(&pf->hw))
6856 i40e_vc_notify_reset(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006857
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006858 dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006859
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006860 /* quiesce the VSIs and their queues that are not already DOWN */
6861 i40e_pf_quiesce_all_vsi(pf);
6862
Mitch Williams505682c2014-05-20 08:01:37 +00006863 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006864 if (pf->vsi[v])
6865 pf->vsi[v]->seid = 0;
6866 }
6867
6868 i40e_shutdown_adminq(&pf->hw);
6869
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006870 /* call shutdown HMC */
Shannon Nelson60442de2014-04-23 04:50:13 +00006871 if (hw->hmc.hmc_obj) {
6872 ret = i40e_shutdown_lan_hmc(hw);
Shannon Nelson23cfbe02014-06-04 01:23:14 +00006873 if (ret)
Shannon Nelson60442de2014-04-23 04:50:13 +00006874 dev_warn(&pf->pdev->dev,
6875 "shutdown_lan_hmc failed: %d\n", ret);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006876 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006877}
6878
6879/**
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00006880 * i40e_send_version - update firmware with driver version
6881 * @pf: PF struct
6882 */
6883static void i40e_send_version(struct i40e_pf *pf)
6884{
6885 struct i40e_driver_version dv;
6886
6887 dv.major_version = DRV_VERSION_MAJOR;
6888 dv.minor_version = DRV_VERSION_MINOR;
6889 dv.build_version = DRV_VERSION_BUILD;
6890 dv.subbuild_version = 0;
Rickard Strandqvist35a7d802014-07-29 09:26:25 +00006891 strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00006892 i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
6893}
6894
6895/**
Jesse Brandeburg4dda12e2013-12-18 13:46:01 +00006896 * i40e_reset_and_rebuild - reset and rebuild using a saved config
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006897 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006898 * @reinit: if the Main VSI needs to re-initialized.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006899 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006900static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006901{
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006902 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006903 u8 set_fc_aq_fail = 0;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006904 i40e_status ret;
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -04006905 u32 val;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006906 u32 v;
6907
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006908 /* Now we wait for GRST to settle out.
6909 * We don't have to delete the VEBs or VSIs from the hw switch
6910 * because the reset will make them disappear.
6911 */
6912 ret = i40e_pf_reset(hw);
Akeem G Abodunrinb5565402014-04-09 05:59:04 +00006913 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006914 dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006915 set_bit(__I40E_RESET_FAILED, &pf->state);
6916 goto clear_recovery;
Akeem G Abodunrinb5565402014-04-09 05:59:04 +00006917 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006918 pf->pfr_count++;
6919
6920 if (test_bit(__I40E_DOWN, &pf->state))
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006921 goto clear_recovery;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006922 dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006923
6924 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
6925 ret = i40e_init_adminq(&pf->hw);
6926 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006927 dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
6928 i40e_stat_str(&pf->hw, ret),
6929 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00006930 goto clear_recovery;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006931 }
6932
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006933 /* re-verify the eeprom if we just had an EMP reset */
Anjali Singhai Jain9df42d12015-01-24 09:58:40 +00006934 if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state))
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006935 i40e_verify_eeprom(pf);
Shannon Nelson4eb3f762014-03-06 08:59:58 +00006936
Shannon Nelsone78ac4bf2014-05-10 04:49:09 +00006937 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006938 ret = i40e_get_capabilities(pf);
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006939 if (ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006940 goto end_core_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006941
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006942 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
6943 hw->func_caps.num_rx_qp,
6944 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
6945 if (ret) {
6946 dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
6947 goto end_core_reset;
6948 }
6949 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
6950 if (ret) {
6951 dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
6952 goto end_core_reset;
6953 }
6954
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006955#ifdef CONFIG_I40E_DCB
6956 ret = i40e_init_pf_dcb(pf);
6957 if (ret) {
Shannon Nelsonaebfc812014-12-11 07:06:38 +00006958 dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
6959 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
6960 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006961 }
6962#endif /* CONFIG_I40E_DCB */
Vasu Dev38e00432014-08-01 13:27:03 -07006963#ifdef I40E_FCOE
Shannon Nelson21364bc2015-08-26 15:14:13 -04006964 i40e_init_pf_fcoe(pf);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08006965
Vasu Dev38e00432014-08-01 13:27:03 -07006966#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006967 /* do basic switch setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006968 ret = i40e_setup_pf_switch(pf, reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006969 if (ret)
6970 goto end_core_reset;
6971
Shannon Nelson2f0aff42016-01-04 10:33:08 -08006972 /* The driver only wants link up/down and module qualification
6973 * reports from firmware. Note the negative logic.
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00006974 */
6975 ret = i40e_aq_set_phy_int_mask(&pf->hw,
Shannon Nelson2f0aff42016-01-04 10:33:08 -08006976 ~(I40E_AQ_EVENT_LINK_UPDOWN |
Shannon Nelson867a79e2016-03-18 12:18:15 -07006977 I40E_AQ_EVENT_MEDIA_NA |
Shannon Nelson2f0aff42016-01-04 10:33:08 -08006978 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00006979 if (ret)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04006980 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
6981 i40e_stat_str(&pf->hw, ret),
6982 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00006983
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006984 /* make sure our flow control settings are restored */
6985 ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
6986 if (ret)
Neerav Parikh8279e492015-09-03 17:18:50 -04006987 dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
6988 i40e_stat_str(&pf->hw, ret),
6989 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00006990
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006991 /* Rebuild the VSIs and VEBs that existed before reset.
6992 * They are still in our local switch element arrays, so only
6993 * need to rebuild the switch model in the HW.
6994 *
6995 * If there were VEBs but the reconstitution failed, we'll try
6996 * try to recover minimal use by getting the basic PF VSI working.
6997 */
6998 if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00006999 dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007000 /* find the one VEB connected to the MAC, and find orphans */
7001 for (v = 0; v < I40E_MAX_VEB; v++) {
7002 if (!pf->veb[v])
7003 continue;
7004
7005 if (pf->veb[v]->uplink_seid == pf->mac_seid ||
7006 pf->veb[v]->uplink_seid == 0) {
7007 ret = i40e_reconstitute_veb(pf->veb[v]);
7008
7009 if (!ret)
7010 continue;
7011
7012 /* If Main VEB failed, we're in deep doodoo,
7013 * so give up rebuilding the switch and set up
7014 * for minimal rebuild of PF VSI.
7015 * If orphan failed, we'll report the error
7016 * but try to keep going.
7017 */
7018 if (pf->veb[v]->uplink_seid == pf->mac_seid) {
7019 dev_info(&pf->pdev->dev,
7020 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
7021 ret);
7022 pf->vsi[pf->lan_vsi]->uplink_seid
7023 = pf->mac_seid;
7024 break;
7025 } else if (pf->veb[v]->uplink_seid == 0) {
7026 dev_info(&pf->pdev->dev,
7027 "rebuild of orphan VEB failed: %d\n",
7028 ret);
7029 }
7030 }
7031 }
7032 }
7033
7034 if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
Shannon Nelsoncde4cbc2014-06-04 01:23:17 +00007035 dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007036 /* no VEB, so rebuild only the Main VSI */
7037 ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
7038 if (ret) {
7039 dev_info(&pf->pdev->dev,
7040 "rebuild of Main VSI failed: %d\n", ret);
7041 goto end_core_reset;
7042 }
7043 }
7044
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -04007045 /* Reconfigure hardware for allowing smaller MSS in the case
7046 * of TSO, so that we avoid the MDD being fired and causing
7047 * a reset in the case of small MSS+TSO.
7048 */
7049#define I40E_REG_MSS 0x000E64DC
7050#define I40E_REG_MSS_MIN_MASK 0x3FF0000
7051#define I40E_64BYTE_MSS 0x400000
7052 val = rd32(hw, I40E_REG_MSS);
7053 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
7054 val &= ~I40E_REG_MSS_MIN_MASK;
7055 val |= I40E_64BYTE_MSS;
7056 wr32(hw, I40E_REG_MSS, val);
7057 }
7058
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08007059 if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +00007060 msleep(75);
7061 ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
7062 if (ret)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007063 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
7064 i40e_stat_str(&pf->hw, ret),
7065 i40e_aq_str(&pf->hw,
7066 pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +00007067 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007068 /* reinit the misc interrupt */
7069 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7070 ret = i40e_setup_misc_vector(pf);
7071
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -04007072 /* Add a filter to drop all Flow control frames from any VSI from being
7073 * transmitted. By doing so we stop a malicious VF from sending out
7074 * PAUSE or PFC frames and potentially controlling traffic for other
7075 * PF/VF VSIs.
7076 * The FW can still send Flow control frames if enabled.
7077 */
7078 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
7079 pf->main_vsi_seid);
7080
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007081 /* restart the VSIs that were rebuilt and running before the reset */
7082 i40e_pf_unquiesce_all_vsi(pf);
7083
Mitch Williams69f64b22014-02-13 03:48:46 -08007084 if (pf->num_alloc_vfs) {
7085 for (v = 0; v < pf->num_alloc_vfs; v++)
7086 i40e_reset_vf(&pf->vf[v], true);
7087 }
7088
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007089 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00007090 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007091
7092end_core_reset:
Anjali Singhai Jaina316f652014-07-12 07:28:25 +00007093 clear_bit(__I40E_RESET_FAILED, &pf->state);
7094clear_recovery:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007095 clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
7096}
7097
7098/**
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00007099 * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007100 * @pf: board private structure
7101 *
7102 * Close up the VFs and other things in prep for a Core Reset,
7103 * then get ready to rebuild the world.
7104 **/
7105static void i40e_handle_reset_warning(struct i40e_pf *pf)
7106{
Shannon Nelson23cfbe02014-06-04 01:23:14 +00007107 i40e_prep_for_reset(pf);
7108 i40e_reset_and_rebuild(pf, false);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007109}
7110
7111/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007112 * i40e_handle_mdd_event
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00007113 * @pf: pointer to the PF structure
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007114 *
7115 * Called from the MDD irq handler to identify possibly malicious vfs
7116 **/
7117static void i40e_handle_mdd_event(struct i40e_pf *pf)
7118{
7119 struct i40e_hw *hw = &pf->hw;
7120 bool mdd_detected = false;
Neerav Parikhdf430b12014-06-04 01:23:15 +00007121 bool pf_mdd_detected = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007122 struct i40e_vf *vf;
7123 u32 reg;
7124 int i;
7125
7126 if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
7127 return;
7128
7129 /* find what triggered the MDD event */
7130 reg = rd32(hw, I40E_GL_MDET_TX);
7131 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007132 u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
7133 I40E_GL_MDET_TX_PF_NUM_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00007134 u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007135 I40E_GL_MDET_TX_VF_NUM_SHIFT;
Dan Carpenter013f6572014-10-22 20:06:29 -07007136 u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007137 I40E_GL_MDET_TX_EVENT_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00007138 u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
7139 I40E_GL_MDET_TX_QUEUE_SHIFT) -
7140 pf->hw.func_caps.base_queue;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007141 if (netif_msg_tx_err(pf))
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00007142 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 +00007143 event, queue, pf_num, vf_num);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007144 wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
7145 mdd_detected = true;
7146 }
7147 reg = rd32(hw, I40E_GL_MDET_RX);
7148 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007149 u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
7150 I40E_GL_MDET_RX_FUNCTION_SHIFT;
Dan Carpenter013f6572014-10-22 20:06:29 -07007151 u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00007152 I40E_GL_MDET_RX_EVENT_SHIFT;
Mitch Williams2089ad02014-10-17 03:14:53 +00007153 u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
7154 I40E_GL_MDET_RX_QUEUE_SHIFT) -
7155 pf->hw.func_caps.base_queue;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007156 if (netif_msg_rx_err(pf))
7157 dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
7158 event, queue, func);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007159 wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
7160 mdd_detected = true;
7161 }
7162
Neerav Parikhdf430b12014-06-04 01:23:15 +00007163 if (mdd_detected) {
7164 reg = rd32(hw, I40E_PF_MDET_TX);
7165 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
7166 wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007167 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
Neerav Parikhdf430b12014-06-04 01:23:15 +00007168 pf_mdd_detected = true;
7169 }
7170 reg = rd32(hw, I40E_PF_MDET_RX);
7171 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
7172 wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007173 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
Neerav Parikhdf430b12014-06-04 01:23:15 +00007174 pf_mdd_detected = true;
7175 }
7176 /* Queue belongs to the PF, initiate a reset */
7177 if (pf_mdd_detected) {
7178 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
7179 i40e_service_event_schedule(pf);
7180 }
7181 }
7182
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007183 /* see if one of the VFs needs its hand slapped */
7184 for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
7185 vf = &(pf->vf[i]);
7186 reg = rd32(hw, I40E_VP_MDET_TX(i));
7187 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
7188 wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
7189 vf->num_mdd_events++;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007190 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
7191 i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007192 }
7193
7194 reg = rd32(hw, I40E_VP_MDET_RX(i));
7195 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
7196 wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
7197 vf->num_mdd_events++;
Jesse Brandeburgfaf32972014-07-12 07:28:21 +00007198 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
7199 i);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007200 }
7201
7202 if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
7203 dev_info(&pf->pdev->dev,
7204 "Too many MDD events on VF %d, disabled\n", i);
7205 dev_info(&pf->pdev->dev,
7206 "Use PF Control I/F to re-enable the VF\n");
7207 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
7208 }
7209 }
7210
7211 /* re-enable mdd interrupt cause */
7212 clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
7213 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
7214 reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
7215 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
7216 i40e_flush(hw);
7217}
7218
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007219/**
Singhai, Anjali6a899022015-12-14 12:21:18 -08007220 * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007221 * @pf: board private structure
7222 **/
Singhai, Anjali6a899022015-12-14 12:21:18 -08007223static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007224{
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007225 struct i40e_hw *hw = &pf->hw;
7226 i40e_status ret;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007227 __be16 port;
7228 int i;
7229
Singhai, Anjali6a899022015-12-14 12:21:18 -08007230 if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC))
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007231 return;
7232
Singhai, Anjali6a899022015-12-14 12:21:18 -08007233 pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007234
7235 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
Singhai, Anjali6a899022015-12-14 12:21:18 -08007236 if (pf->pending_udp_bitmap & BIT_ULL(i)) {
7237 pf->pending_udp_bitmap &= ~BIT_ULL(i);
7238 port = pf->udp_ports[i].index;
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007239 if (port)
Carolyn Wybornyb3f5c7b2016-08-24 11:33:51 -07007240 ret = i40e_aq_add_udp_tunnel(hw, port,
7241 pf->udp_ports[i].type,
7242 NULL, NULL);
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07007243 else
7244 ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007245
7246 if (ret) {
Carolyn Wyborny730a8f82016-02-17 16:12:16 -08007247 dev_dbg(&pf->pdev->dev,
7248 "%s %s port %d, index %d failed, err %s aq_err %s\n",
7249 pf->udp_ports[i].type ? "vxlan" : "geneve",
7250 port ? "add" : "delete",
7251 ntohs(port), i,
7252 i40e_stat_str(&pf->hw, ret),
7253 i40e_aq_str(&pf->hw,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04007254 pf->hw.aq.asq_last_status));
Singhai, Anjali6a899022015-12-14 12:21:18 -08007255 pf->udp_ports[i].index = 0;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007256 }
7257 }
7258 }
7259}
7260
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007261/**
7262 * i40e_service_task - Run the driver's async subtasks
7263 * @work: pointer to work_struct containing our data
7264 **/
7265static void i40e_service_task(struct work_struct *work)
7266{
7267 struct i40e_pf *pf = container_of(work,
7268 struct i40e_pf,
7269 service_task);
7270 unsigned long start_time = jiffies;
7271
Shannon Nelsone57a2fe2014-06-03 23:50:19 +00007272 /* don't bother with service tasks if a reset is in progress */
7273 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
7274 i40e_service_event_complete(pf);
7275 return;
7276 }
7277
Kiran Patilb03a8c12015-09-24 18:13:15 -04007278 i40e_detect_recover_hung(pf);
Jesse Brandeburg2818ccd2016-01-13 16:51:38 -08007279 i40e_sync_filters_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007280 i40e_reset_subtask(pf);
7281 i40e_handle_mdd_event(pf);
7282 i40e_vc_process_vflr_event(pf);
7283 i40e_watchdog_subtask(pf);
7284 i40e_fdir_reinit_subtask(pf);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007285 i40e_client_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007286 i40e_sync_filters_subtask(pf);
Singhai, Anjali6a899022015-12-14 12:21:18 -08007287 i40e_sync_udp_filters_subtask(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007288 i40e_clean_adminq_subtask(pf);
7289
7290 i40e_service_event_complete(pf);
7291
7292 /* If the tasks have taken longer than one timer cycle or there
7293 * is more work to be done, reschedule the service task now
7294 * rather than wait for the timer to tick again.
7295 */
7296 if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
7297 test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
7298 test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
7299 test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
7300 i40e_service_event_schedule(pf);
7301}
7302
7303/**
7304 * i40e_service_timer - timer callback
7305 * @data: pointer to PF struct
7306 **/
7307static void i40e_service_timer(unsigned long data)
7308{
7309 struct i40e_pf *pf = (struct i40e_pf *)data;
7310
7311 mod_timer(&pf->service_timer,
7312 round_jiffies(jiffies + pf->service_timer_period));
7313 i40e_service_event_schedule(pf);
7314}
7315
7316/**
7317 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
7318 * @vsi: the VSI being configured
7319 **/
7320static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
7321{
7322 struct i40e_pf *pf = vsi->back;
7323
7324 switch (vsi->type) {
7325 case I40E_VSI_MAIN:
7326 vsi->alloc_queue_pairs = pf->num_lan_qps;
7327 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7328 I40E_REQ_DESCRIPTOR_MULTIPLE);
7329 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7330 vsi->num_q_vectors = pf->num_lan_msix;
7331 else
7332 vsi->num_q_vectors = 1;
7333
7334 break;
7335
7336 case I40E_VSI_FDIR:
7337 vsi->alloc_queue_pairs = 1;
7338 vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
7339 I40E_REQ_DESCRIPTOR_MULTIPLE);
Tushar Davea70e4072016-05-16 12:40:53 -07007340 vsi->num_q_vectors = pf->num_fdsb_msix;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007341 break;
7342
7343 case I40E_VSI_VMDQ2:
7344 vsi->alloc_queue_pairs = pf->num_vmdq_qps;
7345 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7346 I40E_REQ_DESCRIPTOR_MULTIPLE);
7347 vsi->num_q_vectors = pf->num_vmdq_msix;
7348 break;
7349
7350 case I40E_VSI_SRIOV:
7351 vsi->alloc_queue_pairs = pf->num_vf_qps;
7352 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7353 I40E_REQ_DESCRIPTOR_MULTIPLE);
7354 break;
7355
Vasu Dev38e00432014-08-01 13:27:03 -07007356#ifdef I40E_FCOE
7357 case I40E_VSI_FCOE:
7358 vsi->alloc_queue_pairs = pf->num_fcoe_qps;
7359 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
7360 I40E_REQ_DESCRIPTOR_MULTIPLE);
7361 vsi->num_q_vectors = pf->num_fcoe_msix;
7362 break;
7363
7364#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007365 default:
7366 WARN_ON(1);
7367 return -ENODATA;
7368 }
7369
7370 return 0;
7371}
7372
7373/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007374 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
7375 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007376 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007377 *
7378 * On error: returns error code (negative)
7379 * On success: returns 0
7380 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007381static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007382{
7383 int size;
7384 int ret = 0;
7385
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00007386 /* allocate memory for both Tx and Rx ring pointers */
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007387 size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
7388 vsi->tx_rings = kzalloc(size, GFP_KERNEL);
7389 if (!vsi->tx_rings)
7390 return -ENOMEM;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007391 vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
7392
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007393 if (alloc_qvectors) {
7394 /* allocate memory for q_vector pointers */
Julia Lawallf57e4fb2014-07-30 03:11:09 +00007395 size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007396 vsi->q_vectors = kzalloc(size, GFP_KERNEL);
7397 if (!vsi->q_vectors) {
7398 ret = -ENOMEM;
7399 goto err_vectors;
7400 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007401 }
7402 return ret;
7403
7404err_vectors:
7405 kfree(vsi->tx_rings);
7406 return ret;
7407}
7408
7409/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007410 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
7411 * @pf: board private structure
7412 * @type: type of VSI
7413 *
7414 * On error: returns error code (negative)
7415 * On success: returns vsi index in PF (positive)
7416 **/
7417static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
7418{
7419 int ret = -ENODEV;
7420 struct i40e_vsi *vsi;
7421 int vsi_idx;
7422 int i;
7423
7424 /* Need to protect the allocation of the VSIs at the PF level */
7425 mutex_lock(&pf->switch_mutex);
7426
7427 /* VSI list may be fragmented if VSI creation/destruction has
7428 * been happening. We can afford to do a quick scan to look
7429 * for any free VSIs in the list.
7430 *
7431 * find next empty vsi slot, looping back around if necessary
7432 */
7433 i = pf->next_vsi;
Mitch Williams505682c2014-05-20 08:01:37 +00007434 while (i < pf->num_alloc_vsi && pf->vsi[i])
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007435 i++;
Mitch Williams505682c2014-05-20 08:01:37 +00007436 if (i >= pf->num_alloc_vsi) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007437 i = 0;
7438 while (i < pf->next_vsi && pf->vsi[i])
7439 i++;
7440 }
7441
Mitch Williams505682c2014-05-20 08:01:37 +00007442 if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007443 vsi_idx = i; /* Found one! */
7444 } else {
7445 ret = -ENODEV;
Alexander Duyck493fb302013-09-28 07:01:44 +00007446 goto unlock_pf; /* out of VSI slots! */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007447 }
7448 pf->next_vsi = ++i;
7449
7450 vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
7451 if (!vsi) {
7452 ret = -ENOMEM;
Alexander Duyck493fb302013-09-28 07:01:44 +00007453 goto unlock_pf;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007454 }
7455 vsi->type = type;
7456 vsi->back = pf;
7457 set_bit(__I40E_DOWN, &vsi->state);
7458 vsi->flags = 0;
7459 vsi->idx = vsi_idx;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04007460 vsi->int_rate_limit = 0;
Anjali Singhai Jain5db4cb52015-02-24 06:58:49 +00007461 vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
7462 pf->rss_table_size : 64;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007463 vsi->netdev_registered = false;
7464 vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
Jacob Keller278e7d02016-10-05 09:30:37 -07007465 hash_init(vsi->mac_filter_hash);
Shannon Nelson63741842014-04-23 04:50:16 +00007466 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007467
Alexander Duyck9f65e152013-09-28 06:00:58 +00007468 ret = i40e_set_num_rings_in_vsi(vsi);
7469 if (ret)
7470 goto err_rings;
7471
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007472 ret = i40e_vsi_alloc_arrays(vsi, true);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007473 if (ret)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007474 goto err_rings;
Alexander Duyck493fb302013-09-28 07:01:44 +00007475
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007476 /* Setup default MSIX irq handler for VSI */
7477 i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
7478
Kiran Patil21659032015-09-30 14:09:03 -04007479 /* Initialize VSI lock */
Jacob Keller278e7d02016-10-05 09:30:37 -07007480 spin_lock_init(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007481 pf->vsi[vsi_idx] = vsi;
7482 ret = vsi_idx;
Alexander Duyck493fb302013-09-28 07:01:44 +00007483 goto unlock_pf;
7484
Alexander Duyck9f65e152013-09-28 06:00:58 +00007485err_rings:
Alexander Duyck493fb302013-09-28 07:01:44 +00007486 pf->next_vsi = i - 1;
7487 kfree(vsi);
7488unlock_pf:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007489 mutex_unlock(&pf->switch_mutex);
7490 return ret;
7491}
7492
7493/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007494 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
7495 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007496 * @free_qvectors: a bool to specify if q_vectors need to be freed.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007497 *
7498 * On error: returns error code (negative)
7499 * On success: returns 0
7500 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007501static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007502{
7503 /* free the ring and vector containers */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007504 if (free_qvectors) {
7505 kfree(vsi->q_vectors);
7506 vsi->q_vectors = NULL;
7507 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00007508 kfree(vsi->tx_rings);
7509 vsi->tx_rings = NULL;
7510 vsi->rx_rings = NULL;
7511}
7512
7513/**
Helin Zhang28c58692015-10-26 19:44:27 -04007514 * i40e_clear_rss_config_user - clear the user configured RSS hash keys
7515 * and lookup table
7516 * @vsi: Pointer to VSI structure
7517 */
7518static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
7519{
7520 if (!vsi)
7521 return;
7522
7523 kfree(vsi->rss_hkey_user);
7524 vsi->rss_hkey_user = NULL;
7525
7526 kfree(vsi->rss_lut_user);
7527 vsi->rss_lut_user = NULL;
7528}
7529
7530/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007531 * i40e_vsi_clear - Deallocate the VSI provided
7532 * @vsi: the VSI being un-configured
7533 **/
7534static int i40e_vsi_clear(struct i40e_vsi *vsi)
7535{
7536 struct i40e_pf *pf;
7537
7538 if (!vsi)
7539 return 0;
7540
7541 if (!vsi->back)
7542 goto free_vsi;
7543 pf = vsi->back;
7544
7545 mutex_lock(&pf->switch_mutex);
7546 if (!pf->vsi[vsi->idx]) {
7547 dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
7548 vsi->idx, vsi->idx, vsi, vsi->type);
7549 goto unlock_vsi;
7550 }
7551
7552 if (pf->vsi[vsi->idx] != vsi) {
7553 dev_err(&pf->pdev->dev,
7554 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
7555 pf->vsi[vsi->idx]->idx,
7556 pf->vsi[vsi->idx],
7557 pf->vsi[vsi->idx]->type,
7558 vsi->idx, vsi, vsi->type);
7559 goto unlock_vsi;
7560 }
7561
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00007562 /* updates the PF for this cleared vsi */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007563 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
7564 i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
7565
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007566 i40e_vsi_free_arrays(vsi, true);
Helin Zhang28c58692015-10-26 19:44:27 -04007567 i40e_clear_rss_config_user(vsi);
Alexander Duyck493fb302013-09-28 07:01:44 +00007568
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007569 pf->vsi[vsi->idx] = NULL;
7570 if (vsi->idx < pf->next_vsi)
7571 pf->next_vsi = vsi->idx;
7572
7573unlock_vsi:
7574 mutex_unlock(&pf->switch_mutex);
7575free_vsi:
7576 kfree(vsi);
7577
7578 return 0;
7579}
7580
7581/**
Alexander Duyck9f65e152013-09-28 06:00:58 +00007582 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
7583 * @vsi: the VSI being cleaned
7584 **/
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00007585static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
Alexander Duyck9f65e152013-09-28 06:00:58 +00007586{
7587 int i;
7588
Greg Rose8e9dca52013-12-18 13:45:53 +00007589 if (vsi->tx_rings && vsi->tx_rings[0]) {
Neerav Parikhd7397642013-11-28 06:39:37 +00007590 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Mitch Williams00403f02013-09-28 07:13:13 +00007591 kfree_rcu(vsi->tx_rings[i], rcu);
7592 vsi->tx_rings[i] = NULL;
7593 vsi->rx_rings[i] = NULL;
7594 }
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00007595 }
Alexander Duyck9f65e152013-09-28 06:00:58 +00007596}
7597
7598/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007599 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
7600 * @vsi: the VSI being configured
7601 **/
7602static int i40e_alloc_rings(struct i40e_vsi *vsi)
7603{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00007604 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007605 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007606 int i;
7607
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007608 /* Set basic values in the rings to be used later during open() */
Neerav Parikhd7397642013-11-28 06:39:37 +00007609 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00007610 /* allocate space for both Tx and Rx in one shot */
Alexander Duyck9f65e152013-09-28 06:00:58 +00007611 tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
7612 if (!tx_ring)
7613 goto err_out;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007614
7615 tx_ring->queue_index = i;
7616 tx_ring->reg_idx = vsi->base_queue + i;
7617 tx_ring->ring_active = false;
7618 tx_ring->vsi = vsi;
7619 tx_ring->netdev = vsi->netdev;
7620 tx_ring->dev = &pf->pdev->dev;
7621 tx_ring->count = vsi->num_desc;
7622 tx_ring->size = 0;
7623 tx_ring->dcb_tc = 0;
Anjali Singhai Jain8e0764b2015-06-05 12:20:30 -04007624 if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
7625 tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
Kan Lianga75e8002016-02-19 09:24:04 -05007626 tx_ring->tx_itr_setting = pf->tx_itr_default;
Alexander Duyck9f65e152013-09-28 06:00:58 +00007627 vsi->tx_rings[i] = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007628
Alexander Duyck9f65e152013-09-28 06:00:58 +00007629 rx_ring = &tx_ring[1];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007630 rx_ring->queue_index = i;
7631 rx_ring->reg_idx = vsi->base_queue + i;
7632 rx_ring->ring_active = false;
7633 rx_ring->vsi = vsi;
7634 rx_ring->netdev = vsi->netdev;
7635 rx_ring->dev = &pf->pdev->dev;
7636 rx_ring->count = vsi->num_desc;
7637 rx_ring->size = 0;
7638 rx_ring->dcb_tc = 0;
Kan Lianga75e8002016-02-19 09:24:04 -05007639 rx_ring->rx_itr_setting = pf->rx_itr_default;
Alexander Duyck9f65e152013-09-28 06:00:58 +00007640 vsi->rx_rings[i] = rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007641 }
7642
7643 return 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00007644
7645err_out:
7646 i40e_vsi_clear_rings(vsi);
7647 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007648}
7649
7650/**
7651 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
7652 * @pf: board private structure
7653 * @vectors: the number of MSI-X vectors to request
7654 *
7655 * Returns the number of vectors reserved, or error
7656 **/
7657static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
7658{
Alexander Gordeev7b37f372014-02-18 11:11:42 +01007659 vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
7660 I40E_MIN_MSIX, vectors);
7661 if (vectors < 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007662 dev_info(&pf->pdev->dev,
Alexander Gordeev7b37f372014-02-18 11:11:42 +01007663 "MSI-X vector reservation failed: %d\n", vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007664 vectors = 0;
7665 }
7666
7667 return vectors;
7668}
7669
7670/**
7671 * i40e_init_msix - Setup the MSIX capability
7672 * @pf: board private structure
7673 *
7674 * Work with the OS to set up the MSIX vectors needed.
7675 *
Shannon Nelson3b444392015-02-26 16:15:57 +00007676 * Returns the number of vectors reserved or negative on failure
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007677 **/
7678static int i40e_init_msix(struct i40e_pf *pf)
7679{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007680 struct i40e_hw *hw = &pf->hw;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007681 int vectors_left;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007682 int v_budget, i;
Shannon Nelson3b444392015-02-26 16:15:57 +00007683 int v_actual;
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007684 int iwarp_requested = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007685
7686 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
7687 return -ENODEV;
7688
7689 /* The number of vectors we'll request will be comprised of:
7690 * - Add 1 for "other" cause for Admin Queue events, etc.
7691 * - The number of LAN queue pairs
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00007692 * - Queues being used for RSS.
7693 * We don't need as many as max_rss_size vectors.
7694 * use rss_size instead in the calculation since that
7695 * is governed by number of cpus in the system.
7696 * - assumes symmetric Tx/Rx pairing
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007697 * - The number of VMDq pairs
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007698 * - The CPU count within the NUMA node if iWARP is enabled
Vasu Dev38e00432014-08-01 13:27:03 -07007699#ifdef I40E_FCOE
7700 * - The number of FCOE qps.
7701#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007702 * Once we count this up, try the request.
7703 *
7704 * If we can't get what we want, we'll simplify to nearly nothing
7705 * and try again. If that still fails, we punt.
7706 */
Shannon Nelson1e200e42015-02-27 09:15:24 +00007707 vectors_left = hw->func_caps.num_msix_vectors;
7708 v_budget = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007709
Shannon Nelson1e200e42015-02-27 09:15:24 +00007710 /* reserve one vector for miscellaneous handler */
7711 if (vectors_left) {
7712 v_budget++;
7713 vectors_left--;
7714 }
7715
7716 /* reserve vectors for the main PF traffic queues */
7717 pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left);
7718 vectors_left -= pf->num_lan_msix;
7719 v_budget += pf->num_lan_msix;
7720
7721 /* reserve one vector for sideband flow director */
7722 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
7723 if (vectors_left) {
Tushar Davea70e4072016-05-16 12:40:53 -07007724 pf->num_fdsb_msix = 1;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007725 v_budget++;
7726 vectors_left--;
7727 } else {
Tushar Davea70e4072016-05-16 12:40:53 -07007728 pf->num_fdsb_msix = 0;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007729 }
7730 }
John W Linville83840e42015-01-14 03:06:28 +00007731
Vasu Dev38e00432014-08-01 13:27:03 -07007732#ifdef I40E_FCOE
Shannon Nelson1e200e42015-02-27 09:15:24 +00007733 /* can we reserve enough for FCoE? */
Vasu Dev38e00432014-08-01 13:27:03 -07007734 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
Shannon Nelson1e200e42015-02-27 09:15:24 +00007735 if (!vectors_left)
7736 pf->num_fcoe_msix = 0;
7737 else if (vectors_left >= pf->num_fcoe_qps)
7738 pf->num_fcoe_msix = pf->num_fcoe_qps;
7739 else
7740 pf->num_fcoe_msix = 1;
Vasu Dev38e00432014-08-01 13:27:03 -07007741 v_budget += pf->num_fcoe_msix;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007742 vectors_left -= pf->num_fcoe_msix;
Vasu Dev38e00432014-08-01 13:27:03 -07007743 }
Shannon Nelson1e200e42015-02-27 09:15:24 +00007744
Vasu Dev38e00432014-08-01 13:27:03 -07007745#endif
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007746 /* can we reserve enough for iWARP? */
7747 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02007748 iwarp_requested = pf->num_iwarp_msix;
7749
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007750 if (!vectors_left)
7751 pf->num_iwarp_msix = 0;
7752 else if (vectors_left < pf->num_iwarp_msix)
7753 pf->num_iwarp_msix = 1;
7754 v_budget += pf->num_iwarp_msix;
7755 vectors_left -= pf->num_iwarp_msix;
7756 }
7757
Shannon Nelson1e200e42015-02-27 09:15:24 +00007758 /* any vectors left over go for VMDq support */
7759 if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
7760 int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
7761 int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
7762
Stefan Assmann9ca57e92016-09-19 13:37:49 +02007763 if (!vectors_left) {
7764 pf->num_vmdq_msix = 0;
7765 pf->num_vmdq_qps = 0;
7766 } else {
7767 /* if we're short on vectors for what's desired, we limit
7768 * the queues per vmdq. If this is still more than are
7769 * available, the user will need to change the number of
7770 * queues/vectors used by the PF later with the ethtool
7771 * channels command
7772 */
7773 if (vmdq_vecs < vmdq_vecs_wanted)
7774 pf->num_vmdq_qps = 1;
7775 pf->num_vmdq_msix = pf->num_vmdq_qps;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007776
Stefan Assmann9ca57e92016-09-19 13:37:49 +02007777 v_budget += vmdq_vecs;
7778 vectors_left -= vmdq_vecs;
7779 }
Shannon Nelson1e200e42015-02-27 09:15:24 +00007780 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007781
7782 pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
7783 GFP_KERNEL);
7784 if (!pf->msix_entries)
7785 return -ENOMEM;
7786
7787 for (i = 0; i < v_budget; i++)
7788 pf->msix_entries[i].entry = i;
Shannon Nelson3b444392015-02-26 16:15:57 +00007789 v_actual = i40e_reserve_msix_vectors(pf, v_budget);
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007790
Shannon Nelson3b444392015-02-26 16:15:57 +00007791 if (v_actual < I40E_MIN_MSIX) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007792 pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
7793 kfree(pf->msix_entries);
7794 pf->msix_entries = NULL;
Guilherme G Piccoli4c95aa52016-09-22 10:03:58 -03007795 pci_disable_msix(pf->pdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007796 return -ENODEV;
7797
Shannon Nelson3b444392015-02-26 16:15:57 +00007798 } else if (v_actual == I40E_MIN_MSIX) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007799 /* Adjust for minimal MSIX use */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007800 pf->num_vmdq_vsis = 0;
7801 pf->num_vmdq_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007802 pf->num_lan_qps = 1;
7803 pf->num_lan_msix = 1;
7804
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02007805 } else if (!vectors_left) {
7806 /* If we have limited resources, we will start with no vectors
7807 * for the special features and then allocate vectors to some
7808 * of these features based on the policy and at the end disable
7809 * the features that did not get any vectors.
7810 */
Shannon Nelson3b444392015-02-26 16:15:57 +00007811 int vec;
7812
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02007813 dev_info(&pf->pdev->dev,
7814 "MSI-X vector limit reached, attempting to redistribute vectors\n");
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007815 /* reserve the misc vector */
Shannon Nelson3b444392015-02-26 16:15:57 +00007816 vec = v_actual - 1;
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007817
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007818 /* Scale vector usage down */
7819 pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007820 pf->num_vmdq_vsis = 1;
Shannon Nelson1e200e42015-02-27 09:15:24 +00007821 pf->num_vmdq_qps = 1;
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02007822#ifdef I40E_FCOE
7823 pf->num_fcoe_qps = 0;
7824 pf->num_fcoe_msix = 0;
7825#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007826
7827 /* partition out the remaining vectors */
7828 switch (vec) {
7829 case 2:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007830 pf->num_lan_msix = 1;
7831 break;
7832 case 3:
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007833 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
7834 pf->num_lan_msix = 1;
7835 pf->num_iwarp_msix = 1;
7836 } else {
7837 pf->num_lan_msix = 2;
7838 }
Vasu Dev38e00432014-08-01 13:27:03 -07007839#ifdef I40E_FCOE
7840 /* give one vector to FCoE */
7841 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
7842 pf->num_lan_msix = 1;
7843 pf->num_fcoe_msix = 1;
7844 }
Vasu Dev38e00432014-08-01 13:27:03 -07007845#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007846 break;
7847 default:
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007848 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
7849 pf->num_iwarp_msix = min_t(int, (vec / 3),
7850 iwarp_requested);
7851 pf->num_vmdq_vsis = min_t(int, (vec / 3),
7852 I40E_DEFAULT_NUM_VMDQ_VSI);
7853 } else {
7854 pf->num_vmdq_vsis = min_t(int, (vec / 2),
7855 I40E_DEFAULT_NUM_VMDQ_VSI);
7856 }
Stefan Assmannabd97a92016-09-19 13:37:51 +02007857 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
7858 pf->num_fdsb_msix = 1;
7859 vec--;
7860 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007861 pf->num_lan_msix = min_t(int,
7862 (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
7863 pf->num_lan_msix);
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02007864 pf->num_lan_qps = pf->num_lan_msix;
Vasu Dev38e00432014-08-01 13:27:03 -07007865#ifdef I40E_FCOE
7866 /* give one vector to FCoE */
7867 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
7868 pf->num_fcoe_msix = 1;
7869 vec--;
7870 }
7871#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007872 break;
7873 }
7874 }
7875
Stefan Assmannabd97a92016-09-19 13:37:51 +02007876 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
7877 (pf->num_fdsb_msix == 0)) {
7878 dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
7879 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
7880 }
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00007881 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
7882 (pf->num_vmdq_msix == 0)) {
7883 dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
7884 pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
7885 }
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007886
7887 if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
7888 (pf->num_iwarp_msix == 0)) {
7889 dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
7890 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
7891 }
Vasu Dev38e00432014-08-01 13:27:03 -07007892#ifdef I40E_FCOE
7893
7894 if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) {
7895 dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n");
7896 pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
7897 }
7898#endif
Stefan Assmann4ce20ab2016-09-19 13:37:50 +02007899 i40e_debug(&pf->hw, I40E_DEBUG_INIT,
7900 "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
7901 pf->num_lan_msix,
7902 pf->num_vmdq_msix * pf->num_vmdq_vsis,
7903 pf->num_fdsb_msix,
7904 pf->num_iwarp_msix);
7905
Shannon Nelson3b444392015-02-26 16:15:57 +00007906 return v_actual;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007907}
7908
7909/**
Greg Rose90e04072014-03-06 08:59:57 +00007910 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
Alexander Duyck493fb302013-09-28 07:01:44 +00007911 * @vsi: the VSI being configured
7912 * @v_idx: index of the vector in the vsi struct
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03007913 * @cpu: cpu to be used on affinity_mask
Alexander Duyck493fb302013-09-28 07:01:44 +00007914 *
7915 * We allocate one q_vector. If allocation fails we return -ENOMEM.
7916 **/
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03007917static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu)
Alexander Duyck493fb302013-09-28 07:01:44 +00007918{
7919 struct i40e_q_vector *q_vector;
7920
7921 /* allocate q_vector */
7922 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
7923 if (!q_vector)
7924 return -ENOMEM;
7925
7926 q_vector->vsi = vsi;
7927 q_vector->v_idx = v_idx;
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03007928 cpumask_set_cpu(cpu, &q_vector->affinity_mask);
7929
Alexander Duyck493fb302013-09-28 07:01:44 +00007930 if (vsi->netdev)
7931 netif_napi_add(vsi->netdev, &q_vector->napi,
Jesse Brandeburgeefeace2014-05-10 04:49:13 +00007932 i40e_napi_poll, NAPI_POLL_WEIGHT);
Alexander Duyck493fb302013-09-28 07:01:44 +00007933
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00007934 q_vector->rx.latency_range = I40E_LOW_LATENCY;
7935 q_vector->tx.latency_range = I40E_LOW_LATENCY;
7936
Alexander Duyck493fb302013-09-28 07:01:44 +00007937 /* tie q_vector and vsi together */
7938 vsi->q_vectors[v_idx] = q_vector;
7939
7940 return 0;
7941}
7942
7943/**
Greg Rose90e04072014-03-06 08:59:57 +00007944 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007945 * @vsi: the VSI being configured
7946 *
7947 * We allocate one q_vector per queue interrupt. If allocation fails we
7948 * return -ENOMEM.
7949 **/
Greg Rose90e04072014-03-06 08:59:57 +00007950static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007951{
7952 struct i40e_pf *pf = vsi->back;
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03007953 int err, v_idx, num_q_vectors, current_cpu;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007954
7955 /* if not MSIX, give the one vector only to the LAN VSI */
7956 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
7957 num_q_vectors = vsi->num_q_vectors;
7958 else if (vsi == pf->vsi[pf->lan_vsi])
7959 num_q_vectors = 1;
7960 else
7961 return -EINVAL;
7962
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03007963 current_cpu = cpumask_first(cpu_online_mask);
7964
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007965 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03007966 err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu);
Alexander Duyck493fb302013-09-28 07:01:44 +00007967 if (err)
7968 goto err_out;
Guilherme G. Piccoli7f6c5532016-06-27 12:16:43 -03007969 current_cpu = cpumask_next(current_cpu, cpu_online_mask);
7970 if (unlikely(current_cpu >= nr_cpu_ids))
7971 current_cpu = cpumask_first(cpu_online_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007972 }
7973
7974 return 0;
Alexander Duyck493fb302013-09-28 07:01:44 +00007975
7976err_out:
7977 while (v_idx--)
7978 i40e_free_q_vector(vsi, v_idx);
7979
7980 return err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007981}
7982
7983/**
7984 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
7985 * @pf: board private structure to initialize
7986 **/
Jesse Brandeburgc11472802015-04-07 19:45:39 -04007987static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007988{
Shannon Nelson3b444392015-02-26 16:15:57 +00007989 int vectors = 0;
7990 ssize_t size;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007991
7992 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
Shannon Nelson3b444392015-02-26 16:15:57 +00007993 vectors = i40e_init_msix(pf);
7994 if (vectors < 0) {
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08007995 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06007996 I40E_FLAG_IWARP_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -07007997#ifdef I40E_FCOE
7998 I40E_FLAG_FCOE_ENABLED |
7999#endif
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08008000 I40E_FLAG_RSS_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008001 I40E_FLAG_DCB_CAPABLE |
Dave Ertmana0362442016-08-29 17:38:26 -07008002 I40E_FLAG_DCB_ENABLED |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08008003 I40E_FLAG_SRIOV_ENABLED |
8004 I40E_FLAG_FD_SB_ENABLED |
8005 I40E_FLAG_FD_ATR_ENABLED |
8006 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008007
8008 /* rework the queue expectations without MSIX */
8009 i40e_determine_queue_usage(pf);
8010 }
8011 }
8012
8013 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
8014 (pf->flags & I40E_FLAG_MSI_ENABLED)) {
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08008015 dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
Shannon Nelson3b444392015-02-26 16:15:57 +00008016 vectors = pci_enable_msi(pf->pdev);
8017 if (vectors < 0) {
8018 dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
8019 vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008020 pf->flags &= ~I40E_FLAG_MSI_ENABLED;
8021 }
Shannon Nelson3b444392015-02-26 16:15:57 +00008022 vectors = 1; /* one MSI or Legacy vector */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008023 }
8024
Shannon Nelson958a3e32013-09-28 07:13:28 +00008025 if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08008026 dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
Shannon Nelson958a3e32013-09-28 07:13:28 +00008027
Shannon Nelson3b444392015-02-26 16:15:57 +00008028 /* set up vector assignment tracking */
8029 size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
8030 pf->irq_pile = kzalloc(size, GFP_KERNEL);
Jesse Brandeburgc11472802015-04-07 19:45:39 -04008031 if (!pf->irq_pile) {
8032 dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n");
8033 return -ENOMEM;
8034 }
Shannon Nelson3b444392015-02-26 16:15:57 +00008035 pf->irq_pile->num_entries = vectors;
8036 pf->irq_pile->search_hint = 0;
8037
Jesse Brandeburgc11472802015-04-07 19:45:39 -04008038 /* track first vector for misc interrupts, ignore return */
Shannon Nelson3b444392015-02-26 16:15:57 +00008039 (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
Jesse Brandeburgc11472802015-04-07 19:45:39 -04008040
8041 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008042}
8043
8044/**
8045 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
8046 * @pf: board private structure
8047 *
8048 * This sets up the handler for MSIX 0, which is used to manage the
8049 * non-queue interrupts, e.g. AdminQ and errors. This is not used
8050 * when in MSI or Legacy interrupt mode.
8051 **/
8052static int i40e_setup_misc_vector(struct i40e_pf *pf)
8053{
8054 struct i40e_hw *hw = &pf->hw;
8055 int err = 0;
8056
8057 /* Only request the irq if this is the first time through, and
8058 * not when we're rebuilding after a Reset
8059 */
8060 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
8061 err = request_irq(pf->msix_entries[0].vector,
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00008062 i40e_intr, 0, pf->int_name, pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008063 if (err) {
8064 dev_info(&pf->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08008065 "request_irq for %s failed: %d\n",
Carolyn Wybornyb294ac72014-12-11 07:06:39 +00008066 pf->int_name, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008067 return -EFAULT;
8068 }
8069 }
8070
Jacob Kellerab437b52014-12-14 01:55:08 +00008071 i40e_enable_misc_int_causes(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008072
8073 /* associate no queues to the misc vector */
8074 wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
8075 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
8076
8077 i40e_flush(hw);
8078
Jesse Brandeburg40d72a52016-01-13 16:51:45 -08008079 i40e_irq_dynamic_enable_icr0(pf, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008080
8081 return err;
8082}
8083
8084/**
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008085 * i40e_config_rss_aq - Prepare for RSS using AQ commands
8086 * @vsi: vsi structure
8087 * @seed: RSS hash seed
8088 **/
Helin Zhange69ff812015-10-21 19:56:22 -04008089static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
8090 u8 *lut, u16 lut_size)
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008091{
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008092 struct i40e_pf *pf = vsi->back;
8093 struct i40e_hw *hw = &pf->hw;
Jacob Keller776b2e12016-07-19 16:23:30 -07008094 int ret = 0;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008095
Jacob Keller776b2e12016-07-19 16:23:30 -07008096 if (seed) {
8097 struct i40e_aqc_get_set_rss_key_data *seed_dw =
8098 (struct i40e_aqc_get_set_rss_key_data *)seed;
8099 ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw);
8100 if (ret) {
8101 dev_info(&pf->pdev->dev,
8102 "Cannot set RSS key, err %s aq_err %s\n",
8103 i40e_stat_str(hw, ret),
8104 i40e_aq_str(hw, hw->aq.asq_last_status));
8105 return ret;
8106 }
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008107 }
Jacob Keller776b2e12016-07-19 16:23:30 -07008108 if (lut) {
8109 bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008110
Jacob Keller776b2e12016-07-19 16:23:30 -07008111 ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
8112 if (ret) {
8113 dev_info(&pf->pdev->dev,
8114 "Cannot set RSS lut, err %s aq_err %s\n",
8115 i40e_stat_str(hw, ret),
8116 i40e_aq_str(hw, hw->aq.asq_last_status));
8117 return ret;
8118 }
8119 }
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008120 return ret;
8121}
8122
8123/**
Anjali Singhai Jain95a73782015-12-22 14:25:04 -08008124 * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
8125 * @vsi: Pointer to vsi structure
8126 * @seed: Buffter to store the hash keys
8127 * @lut: Buffer to store the lookup table entries
8128 * @lut_size: Size of buffer to store the lookup table entries
8129 *
8130 * Return 0 on success, negative on failure
8131 */
8132static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
8133 u8 *lut, u16 lut_size)
8134{
8135 struct i40e_pf *pf = vsi->back;
8136 struct i40e_hw *hw = &pf->hw;
8137 int ret = 0;
8138
8139 if (seed) {
8140 ret = i40e_aq_get_rss_key(hw, vsi->id,
8141 (struct i40e_aqc_get_set_rss_key_data *)seed);
8142 if (ret) {
8143 dev_info(&pf->pdev->dev,
8144 "Cannot get RSS key, err %s aq_err %s\n",
8145 i40e_stat_str(&pf->hw, ret),
8146 i40e_aq_str(&pf->hw,
8147 pf->hw.aq.asq_last_status));
8148 return ret;
8149 }
8150 }
8151
8152 if (lut) {
8153 bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
8154
8155 ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
8156 if (ret) {
8157 dev_info(&pf->pdev->dev,
8158 "Cannot get RSS lut, err %s aq_err %s\n",
8159 i40e_stat_str(&pf->hw, ret),
8160 i40e_aq_str(&pf->hw,
8161 pf->hw.aq.asq_last_status));
8162 return ret;
8163 }
8164 }
8165
8166 return ret;
8167}
8168
8169/**
Jacob Keller0582b962016-07-19 16:23:29 -07008170 * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
8171 * @vsi: VSI structure
8172 **/
8173static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
8174{
8175 u8 seed[I40E_HKEY_ARRAY_SIZE];
8176 struct i40e_pf *pf = vsi->back;
8177 u8 *lut;
8178 int ret;
8179
8180 if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE))
8181 return 0;
8182
Jacob Keller552b9962016-07-19 16:23:31 -07008183 if (!vsi->rss_size)
8184 vsi->rss_size = min_t(int, pf->alloc_rss_size,
8185 vsi->num_queue_pairs);
8186 if (!vsi->rss_size)
8187 return -EINVAL;
8188
Jacob Keller0582b962016-07-19 16:23:29 -07008189 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
8190 if (!lut)
8191 return -ENOMEM;
Jacob Keller552b9962016-07-19 16:23:31 -07008192 /* Use the user configured hash keys and lookup table if there is one,
8193 * otherwise use default
8194 */
8195 if (vsi->rss_lut_user)
8196 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
8197 else
8198 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
8199 if (vsi->rss_hkey_user)
8200 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
8201 else
8202 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
Jacob Keller0582b962016-07-19 16:23:29 -07008203 ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
8204 kfree(lut);
8205
8206 return ret;
8207}
8208
8209/**
Helin Zhang043dd652015-10-21 19:56:23 -04008210 * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
Helin Zhange69ff812015-10-21 19:56:22 -04008211 * @vsi: Pointer to vsi structure
8212 * @seed: RSS hash seed
8213 * @lut: Lookup table
8214 * @lut_size: Lookup table size
8215 *
8216 * Returns 0 on success, negative on failure
8217 **/
8218static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
8219 const u8 *lut, u16 lut_size)
8220{
8221 struct i40e_pf *pf = vsi->back;
8222 struct i40e_hw *hw = &pf->hw;
Mitch Williamsc4e18682016-04-12 08:30:40 -07008223 u16 vf_id = vsi->vf_id;
Helin Zhange69ff812015-10-21 19:56:22 -04008224 u8 i;
8225
8226 /* Fill out hash function seed */
8227 if (seed) {
8228 u32 *seed_dw = (u32 *)seed;
8229
Mitch Williamsc4e18682016-04-12 08:30:40 -07008230 if (vsi->type == I40E_VSI_MAIN) {
8231 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
8232 i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i),
8233 seed_dw[i]);
8234 } else if (vsi->type == I40E_VSI_SRIOV) {
8235 for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
8236 i40e_write_rx_ctl(hw,
8237 I40E_VFQF_HKEY1(i, vf_id),
8238 seed_dw[i]);
8239 } else {
8240 dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
8241 }
Helin Zhange69ff812015-10-21 19:56:22 -04008242 }
8243
8244 if (lut) {
8245 u32 *lut_dw = (u32 *)lut;
8246
Mitch Williamsc4e18682016-04-12 08:30:40 -07008247 if (vsi->type == I40E_VSI_MAIN) {
8248 if (lut_size != I40E_HLUT_ARRAY_SIZE)
8249 return -EINVAL;
8250 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8251 wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
8252 } else if (vsi->type == I40E_VSI_SRIOV) {
8253 if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
8254 return -EINVAL;
8255 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
8256 i40e_write_rx_ctl(hw,
8257 I40E_VFQF_HLUT1(i, vf_id),
8258 lut_dw[i]);
8259 } else {
8260 dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
8261 }
Helin Zhange69ff812015-10-21 19:56:22 -04008262 }
8263 i40e_flush(hw);
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008264
8265 return 0;
8266}
8267
8268/**
Helin Zhang043dd652015-10-21 19:56:23 -04008269 * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
8270 * @vsi: Pointer to VSI structure
8271 * @seed: Buffer to store the keys
8272 * @lut: Buffer to store the lookup table entries
8273 * @lut_size: Size of buffer to store the lookup table entries
8274 *
8275 * Returns 0 on success, negative on failure
8276 */
8277static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
8278 u8 *lut, u16 lut_size)
8279{
8280 struct i40e_pf *pf = vsi->back;
8281 struct i40e_hw *hw = &pf->hw;
8282 u16 i;
8283
8284 if (seed) {
8285 u32 *seed_dw = (u32 *)seed;
8286
8287 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008288 seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
Helin Zhang043dd652015-10-21 19:56:23 -04008289 }
8290 if (lut) {
8291 u32 *lut_dw = (u32 *)lut;
8292
8293 if (lut_size != I40E_HLUT_ARRAY_SIZE)
8294 return -EINVAL;
8295 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8296 lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
8297 }
8298
8299 return 0;
8300}
8301
8302/**
8303 * i40e_config_rss - Configure RSS keys and lut
8304 * @vsi: Pointer to VSI structure
8305 * @seed: RSS hash seed
8306 * @lut: Lookup table
8307 * @lut_size: Lookup table size
8308 *
8309 * Returns 0 on success, negative on failure
8310 */
8311int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
8312{
8313 struct i40e_pf *pf = vsi->back;
8314
8315 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
8316 return i40e_config_rss_aq(vsi, seed, lut, lut_size);
8317 else
8318 return i40e_config_rss_reg(vsi, seed, lut, lut_size);
8319}
8320
8321/**
8322 * i40e_get_rss - Get RSS keys and lut
8323 * @vsi: Pointer to VSI structure
8324 * @seed: Buffer to store the keys
8325 * @lut: Buffer to store the lookup table entries
8326 * lut_size: Size of buffer to store the lookup table entries
8327 *
8328 * Returns 0 on success, negative on failure
8329 */
8330int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
8331{
Anjali Singhai Jain95a73782015-12-22 14:25:04 -08008332 struct i40e_pf *pf = vsi->back;
8333
8334 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
8335 return i40e_get_rss_aq(vsi, seed, lut, lut_size);
8336 else
8337 return i40e_get_rss_reg(vsi, seed, lut, lut_size);
Helin Zhang043dd652015-10-21 19:56:23 -04008338}
8339
8340/**
Helin Zhange69ff812015-10-21 19:56:22 -04008341 * i40e_fill_rss_lut - Fill the RSS lookup table with default values
8342 * @pf: Pointer to board private structure
8343 * @lut: Lookup table
8344 * @rss_table_size: Lookup table size
8345 * @rss_size: Range of queue number for hashing
8346 */
Alan Bradyf1582352016-08-24 11:33:46 -07008347void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
8348 u16 rss_table_size, u16 rss_size)
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008349{
Helin Zhange69ff812015-10-21 19:56:22 -04008350 u16 i;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008351
Helin Zhange69ff812015-10-21 19:56:22 -04008352 for (i = 0; i < rss_table_size; i++)
8353 lut[i] = i % rss_size;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008354}
8355
8356/**
Helin Zhang043dd652015-10-21 19:56:23 -04008357 * i40e_pf_config_rss - Prepare for RSS if used
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008358 * @pf: board private structure
8359 **/
Helin Zhang043dd652015-10-21 19:56:23 -04008360static int i40e_pf_config_rss(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008361{
Anjali Singhai Jain66ddcff2015-02-24 06:58:50 +00008362 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008363 u8 seed[I40E_HKEY_ARRAY_SIZE];
Helin Zhange69ff812015-10-21 19:56:22 -04008364 u8 *lut;
Anjali Singhai Jain4617e8c2013-11-20 10:02:56 +00008365 struct i40e_hw *hw = &pf->hw;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00008366 u32 reg_val;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008367 u64 hena;
Helin Zhange69ff812015-10-21 19:56:22 -04008368 int ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008369
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008370 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008371 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
8372 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008373 hena |= i40e_pf_get_default_rss_hena(pf);
8374
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008375 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
8376 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008377
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008378 /* Determine the RSS table size based on the hardware capabilities */
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008379 reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008380 reg_val = (pf->rss_table_size == 512) ?
8381 (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
8382 (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
Shannon Nelson272cdaf22016-02-17 16:12:21 -08008383 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
Carolyn Wybornye157ea32014-06-03 23:50:22 +00008384
Helin Zhang28c58692015-10-26 19:44:27 -04008385 /* Determine the RSS size of the VSI */
8386 if (!vsi->rss_size)
Helin Zhangacd65442015-10-26 19:44:28 -04008387 vsi->rss_size = min_t(int, pf->alloc_rss_size,
8388 vsi->num_queue_pairs);
Mitch Williamsa4fa59c2016-09-12 14:18:43 -07008389 if (!vsi->rss_size)
8390 return -EINVAL;
Helin Zhang28c58692015-10-26 19:44:27 -04008391
Helin Zhange69ff812015-10-21 19:56:22 -04008392 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
8393 if (!lut)
8394 return -ENOMEM;
8395
Helin Zhang28c58692015-10-26 19:44:27 -04008396 /* Use user configured lut if there is one, otherwise use default */
8397 if (vsi->rss_lut_user)
8398 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
8399 else
8400 i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
Helin Zhange69ff812015-10-21 19:56:22 -04008401
Helin Zhang28c58692015-10-26 19:44:27 -04008402 /* Use user configured hash key if there is one, otherwise
8403 * use default.
8404 */
8405 if (vsi->rss_hkey_user)
8406 memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
8407 else
8408 netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
Helin Zhang043dd652015-10-21 19:56:23 -04008409 ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
Helin Zhange69ff812015-10-21 19:56:22 -04008410 kfree(lut);
8411
8412 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008413}
8414
8415/**
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008416 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
8417 * @pf: board private structure
8418 * @queue_count: the requested queue count for rss.
8419 *
8420 * returns 0 if rss is not enabled, if enabled returns the final rss queue
8421 * count which may be different from the requested queue count.
8422 **/
8423int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
8424{
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008425 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
8426 int new_rss_size;
8427
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008428 if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
8429 return 0;
8430
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008431 new_rss_size = min_t(int, queue_count, pf->rss_size_max);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008432
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +00008433 if (queue_count != vsi->num_queue_pairs) {
8434 vsi->req_queue_pairs = queue_count;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008435 i40e_prep_for_reset(pf);
8436
Helin Zhangacd65442015-10-26 19:44:28 -04008437 pf->alloc_rss_size = new_rss_size;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008438
8439 i40e_reset_and_rebuild(pf, true);
Helin Zhang28c58692015-10-26 19:44:27 -04008440
8441 /* Discard the user configured hash keys and lut, if less
8442 * queues are enabled.
8443 */
8444 if (queue_count < vsi->rss_size) {
8445 i40e_clear_rss_config_user(vsi);
8446 dev_dbg(&pf->pdev->dev,
8447 "discard user configured hash keys and lut\n");
8448 }
8449
8450 /* Reset vsi->rss_size, as number of enabled queues changed */
Helin Zhangacd65442015-10-26 19:44:28 -04008451 vsi->rss_size = min_t(int, pf->alloc_rss_size,
8452 vsi->num_queue_pairs);
Helin Zhang28c58692015-10-26 19:44:27 -04008453
Helin Zhang043dd652015-10-21 19:56:23 -04008454 i40e_pf_config_rss(pf);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008455 }
Lihong Yang12815052016-09-27 11:28:48 -07008456 dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n",
8457 vsi->req_queue_pairs, pf->rss_size_max);
Helin Zhangacd65442015-10-26 19:44:28 -04008458 return pf->alloc_rss_size;
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008459}
8460
8461/**
Greg Rosef4492db2015-02-06 08:52:12 +00008462 * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
8463 * @pf: board private structure
8464 **/
8465i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf)
8466{
8467 i40e_status status;
8468 bool min_valid, max_valid;
8469 u32 max_bw, min_bw;
8470
8471 status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
8472 &min_valid, &max_valid);
8473
8474 if (!status) {
8475 if (min_valid)
8476 pf->npar_min_bw = min_bw;
8477 if (max_valid)
8478 pf->npar_max_bw = max_bw;
8479 }
8480
8481 return status;
8482}
8483
8484/**
8485 * i40e_set_npar_bw_setting - Set BW settings for this PF partition
8486 * @pf: board private structure
8487 **/
8488i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf)
8489{
8490 struct i40e_aqc_configure_partition_bw_data bw_data;
8491 i40e_status status;
8492
Jeff Kirsherb40c82e2015-02-27 09:18:34 +00008493 /* Set the valid bit for this PF */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008494 bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
Greg Rosef4492db2015-02-06 08:52:12 +00008495 bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK;
8496 bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK;
8497
8498 /* Set the new bandwidths */
8499 status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
8500
8501 return status;
8502}
8503
8504/**
8505 * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
8506 * @pf: board private structure
8507 **/
8508i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf)
8509{
8510 /* Commit temporary BW setting to permanent NVM image */
8511 enum i40e_admin_queue_err last_aq_status;
8512 i40e_status ret;
8513 u16 nvm_word;
8514
8515 if (pf->hw.partition_id != 1) {
8516 dev_info(&pf->pdev->dev,
8517 "Commit BW only works on partition 1! This is partition %d",
8518 pf->hw.partition_id);
8519 ret = I40E_NOT_SUPPORTED;
8520 goto bw_commit_out;
8521 }
8522
8523 /* Acquire NVM for read access */
8524 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
8525 last_aq_status = pf->hw.aq.asq_last_status;
8526 if (ret) {
8527 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008528 "Cannot acquire NVM for read access, err %s aq_err %s\n",
8529 i40e_stat_str(&pf->hw, ret),
8530 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008531 goto bw_commit_out;
8532 }
8533
8534 /* Read word 0x10 of NVM - SW compatibility word 1 */
8535 ret = i40e_aq_read_nvm(&pf->hw,
8536 I40E_SR_NVM_CONTROL_WORD,
8537 0x10, sizeof(nvm_word), &nvm_word,
8538 false, NULL);
8539 /* Save off last admin queue command status before releasing
8540 * the NVM
8541 */
8542 last_aq_status = pf->hw.aq.asq_last_status;
8543 i40e_release_nvm(&pf->hw);
8544 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008545 dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
8546 i40e_stat_str(&pf->hw, ret),
8547 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008548 goto bw_commit_out;
8549 }
8550
8551 /* Wait a bit for NVM release to complete */
8552 msleep(50);
8553
8554 /* Acquire NVM for write access */
8555 ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
8556 last_aq_status = pf->hw.aq.asq_last_status;
8557 if (ret) {
8558 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008559 "Cannot acquire NVM for write access, err %s aq_err %s\n",
8560 i40e_stat_str(&pf->hw, ret),
8561 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008562 goto bw_commit_out;
8563 }
8564 /* Write it back out unchanged to initiate update NVM,
8565 * which will force a write of the shadow (alt) RAM to
8566 * the NVM - thus storing the bandwidth values permanently.
8567 */
8568 ret = i40e_aq_update_nvm(&pf->hw,
8569 I40E_SR_NVM_CONTROL_WORD,
8570 0x10, sizeof(nvm_word),
8571 &nvm_word, true, NULL);
8572 /* Save off last admin queue command status before releasing
8573 * the NVM
8574 */
8575 last_aq_status = pf->hw.aq.asq_last_status;
8576 i40e_release_nvm(&pf->hw);
8577 if (ret)
8578 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04008579 "BW settings NOT SAVED, err %s aq_err %s\n",
8580 i40e_stat_str(&pf->hw, ret),
8581 i40e_aq_str(&pf->hw, last_aq_status));
Greg Rosef4492db2015-02-06 08:52:12 +00008582bw_commit_out:
8583
8584 return ret;
8585}
8586
8587/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008588 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
8589 * @pf: board private structure to initialize
8590 *
8591 * i40e_sw_init initializes the Adapter private data structure.
8592 * Fields are initialized based on PCI device information and
8593 * OS network device settings (MTU size).
8594 **/
8595static int i40e_sw_init(struct i40e_pf *pf)
8596{
8597 int err = 0;
8598 int size;
8599
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008600 /* Set default capability flags */
8601 pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
8602 I40E_FLAG_MSI_ENABLED |
Mitch Williams2bc7ee82015-02-06 08:52:11 +00008603 I40E_FLAG_MSIX_ENABLED;
8604
Mitch Williamsca99eb92014-04-04 04:43:07 +00008605 /* Set default ITR */
8606 pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
8607 pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
8608
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008609 /* Depending on PF configurations, it is possible that the RSS
8610 * maximum might end up larger than the available queues
8611 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008612 pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
Helin Zhangacd65442015-10-26 19:44:28 -04008613 pf->alloc_rss_size = 1;
Anjali Singhai Jain5db4cb52015-02-24 06:58:49 +00008614 pf->rss_table_size = pf->hw.func_caps.rss_table_size;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008615 pf->rss_size_max = min_t(int, pf->rss_size_max,
8616 pf->hw.func_caps.num_tx_qp);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008617 if (pf->hw.func_caps.rss) {
8618 pf->flags |= I40E_FLAG_RSS_ENABLED;
Helin Zhangacd65442015-10-26 19:44:28 -04008619 pf->alloc_rss_size = min_t(int, pf->rss_size_max,
8620 num_online_cpus());
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008621 }
8622
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008623 /* MFP mode enabled */
Pawel Orlowskic78b9532015-04-22 19:34:06 -04008624 if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008625 pf->flags |= I40E_FLAG_MFP_ENABLED;
8626 dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
Greg Rosef4492db2015-02-06 08:52:12 +00008627 if (i40e_get_npar_bw_setting(pf))
8628 dev_warn(&pf->pdev->dev,
8629 "Could not get NPAR bw settings\n");
8630 else
8631 dev_info(&pf->pdev->dev,
8632 "Min BW = %8.8x, Max BW = %8.8x\n",
8633 pf->npar_min_bw, pf->npar_max_bw);
Catherine Sullivan2050bc62013-12-18 13:46:03 +00008634 }
8635
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008636 /* FW/NVM is not yet fixed in this regard */
8637 if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
8638 (pf->hw.func_caps.fd_filters_best_effort > 0)) {
8639 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
8640 pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
Shannon Nelson6eae9c62015-09-03 17:18:55 -04008641 if (pf->flags & I40E_FLAG_MFP_ENABLED &&
8642 pf->hw.num_partitions > 1)
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008643 dev_info(&pf->pdev->dev,
Anjali Singhai Jain0b675842014-03-06 08:59:51 +00008644 "Flow Director Sideband mode Disabled in MFP mode\n");
Shannon Nelson6eae9c62015-09-03 17:18:55 -04008645 else
8646 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008647 pf->fdir_pf_filter_count =
8648 pf->hw.func_caps.fd_filters_guaranteed;
8649 pf->hw.fdir_shared_filter_count =
8650 pf->hw.func_caps.fd_filters_best_effort;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008651 }
8652
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008653 if (i40e_is_mac_710(&pf->hw) &&
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08008654 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008655 (pf->hw.aq.fw_maj_ver < 4))) {
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08008656 pf->flags |= I40E_FLAG_RESTART_AUTONEG;
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008657 /* No DCB support for FW < v4.33 */
8658 pf->flags |= I40E_FLAG_NO_DCB_SUPPORT;
8659 }
8660
8661 /* Disable FW LLDP if FW < v4.3 */
8662 if (i40e_is_mac_710(&pf->hw) &&
8663 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
8664 (pf->hw.aq.fw_maj_ver < 4)))
8665 pf->flags |= I40E_FLAG_STOP_FW_LLDP;
8666
8667 /* Use the FW Set LLDP MIB API if FW > v4.40 */
8668 if (i40e_is_mac_710(&pf->hw) &&
8669 (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
8670 (pf->hw.aq.fw_maj_ver >= 5)))
8671 pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB;
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -08008672
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008673 if (pf->hw.func_caps.vmdq) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008674 pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -04008675 pf->flags |= I40E_FLAG_VMDQ_ENABLED;
Jesse Brandeburge9e53662015-10-02 17:57:21 -07008676 pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008677 }
8678
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06008679 if (pf->hw.func_caps.iwarp) {
8680 pf->flags |= I40E_FLAG_IWARP_ENABLED;
8681 /* IWARP needs one extra vector for CQP just like MISC.*/
8682 pf->num_iwarp_msix = (int)num_online_cpus() + 1;
8683 }
8684
Vasu Dev38e00432014-08-01 13:27:03 -07008685#ifdef I40E_FCOE
Shannon Nelson21364bc2015-08-26 15:14:13 -04008686 i40e_init_pf_fcoe(pf);
Vasu Dev38e00432014-08-01 13:27:03 -07008687
8688#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008689#ifdef CONFIG_PCI_IOV
Shannon Nelsonba252f132014-12-11 07:06:34 +00008690 if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008691 pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
8692 pf->flags |= I40E_FLAG_SRIOV_ENABLED;
8693 pf->num_req_vfs = min_t(int,
8694 pf->hw.func_caps.num_vfs,
8695 I40E_MAX_VF_COUNT);
8696 }
8697#endif /* CONFIG_PCI_IOV */
Anjali Singhai Jaind502ce02015-06-05 12:20:26 -04008698 if (pf->hw.mac.type == I40E_MAC_X722) {
8699 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE |
8700 I40E_FLAG_128_QP_RSS_CAPABLE |
8701 I40E_FLAG_HW_ATR_EVICT_CAPABLE |
8702 I40E_FLAG_OUTER_UDP_CSUM_CAPABLE |
8703 I40E_FLAG_WB_ON_ITR_CAPABLE |
Singhai, Anjali6a899022015-12-14 12:21:18 -08008704 I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE |
Jesse Brandeburg8e2cc0e2016-02-29 11:00:24 -08008705 I40E_FLAG_NO_PCI_LINK_CHECK |
Neerav Parikhf1bbad32016-01-13 16:51:39 -08008706 I40E_FLAG_USE_SET_LLDP_MIB |
Singhai, Anjali6a899022015-12-14 12:21:18 -08008707 I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
Anjali Singhaia340c782016-01-06 11:49:28 -08008708 } else if ((pf->hw.aq.api_maj_ver > 1) ||
8709 ((pf->hw.aq.api_maj_ver == 1) &&
8710 (pf->hw.aq.api_min_ver > 4))) {
8711 /* Supported in FW API version higher than 1.4 */
8712 pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08008713 pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
8714 } else {
8715 pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
Anjali Singhai Jaind502ce02015-06-05 12:20:26 -04008716 }
Anjali Singhaia340c782016-01-06 11:49:28 -08008717
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008718 pf->eeprom_version = 0xDEAD;
8719 pf->lan_veb = I40E_NO_VEB;
8720 pf->lan_vsi = I40E_NO_VSI;
8721
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04008722 /* By default FW has this off for performance reasons */
8723 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
8724
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008725 /* set up queue assignment tracking */
8726 size = sizeof(struct i40e_lump_tracking)
8727 + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
8728 pf->qp_pile = kzalloc(size, GFP_KERNEL);
8729 if (!pf->qp_pile) {
8730 err = -ENOMEM;
8731 goto sw_init_done;
8732 }
8733 pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
8734 pf->qp_pile->search_hint = 0;
8735
Anjali Singhai Jain327fe042014-06-04 01:23:26 +00008736 pf->tx_timeout_recovery_level = 1;
8737
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008738 mutex_init(&pf->switch_mutex);
8739
Greg Rosec668a122015-02-26 16:10:39 +00008740 /* If NPAR is enabled nudge the Tx scheduler */
8741 if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf)))
8742 i40e_set_npar_bw_setting(pf);
8743
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008744sw_init_done:
8745 return err;
8746}
8747
8748/**
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008749 * i40e_set_ntuple - set the ntuple feature flag and take action
8750 * @pf: board private structure to initialize
8751 * @features: the feature set that the stack is suggesting
8752 *
8753 * returns a bool to indicate if reset needs to happen
8754 **/
8755bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
8756{
8757 bool need_reset = false;
8758
8759 /* Check if Flow Director n-tuple support was enabled or disabled. If
8760 * the state changed, we need to reset.
8761 */
8762 if (features & NETIF_F_NTUPLE) {
8763 /* Enable filters and mark for reset */
8764 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
8765 need_reset = true;
Tushar Davea70e4072016-05-16 12:40:53 -07008766 /* enable FD_SB only if there is MSI-X vector */
8767 if (pf->num_fdsb_msix > 0)
8768 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008769 } else {
8770 /* turn off filters, mark for reset and clear SW filter list */
8771 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
8772 need_reset = true;
8773 i40e_fdir_filter_exit(pf);
8774 }
8775 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain8a4f34f2014-06-04 08:45:20 +00008776 pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00008777 /* reset fd counters */
8778 pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0;
8779 pf->fdir_pf_active_filters = 0;
Anjali Singhai Jain8a4f34f2014-06-04 08:45:20 +00008780 /* if ATR was auto disabled it can be re-enabled. */
8781 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
Jacob Keller234dc4e2016-09-06 18:05:09 -07008782 (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
Anjali Singhai Jain8a4f34f2014-06-04 08:45:20 +00008783 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Jacob Keller234dc4e2016-09-06 18:05:09 -07008784 if (I40E_DEBUG_FD & pf->hw.debug_mask)
8785 dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
8786 }
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008787 }
8788 return need_reset;
8789}
8790
8791/**
Alan Bradyd8ec9862016-07-27 12:02:38 -07008792 * i40e_clear_rss_lut - clear the rx hash lookup table
8793 * @vsi: the VSI being configured
8794 **/
8795static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
8796{
8797 struct i40e_pf *pf = vsi->back;
8798 struct i40e_hw *hw = &pf->hw;
8799 u16 vf_id = vsi->vf_id;
8800 u8 i;
8801
8802 if (vsi->type == I40E_VSI_MAIN) {
8803 for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
8804 wr32(hw, I40E_PFQF_HLUT(i), 0);
8805 } else if (vsi->type == I40E_VSI_SRIOV) {
8806 for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
8807 i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
8808 } else {
8809 dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
8810 }
8811}
8812
8813/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008814 * i40e_set_features - set the netdev feature flags
8815 * @netdev: ptr to the netdev being adjusted
8816 * @features: the feature set that the stack is suggesting
8817 **/
8818static int i40e_set_features(struct net_device *netdev,
8819 netdev_features_t features)
8820{
8821 struct i40e_netdev_priv *np = netdev_priv(netdev);
8822 struct i40e_vsi *vsi = np->vsi;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008823 struct i40e_pf *pf = vsi->back;
8824 bool need_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008825
Alan Bradyd8ec9862016-07-27 12:02:38 -07008826 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
8827 i40e_pf_config_rss(pf);
8828 else if (!(features & NETIF_F_RXHASH) &&
8829 netdev->features & NETIF_F_RXHASH)
8830 i40e_clear_rss_lut(vsi);
8831
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008832 if (features & NETIF_F_HW_VLAN_CTAG_RX)
8833 i40e_vlan_stripping_enable(vsi);
8834 else
8835 i40e_vlan_stripping_disable(vsi);
8836
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008837 need_reset = i40e_set_ntuple(pf, features);
8838
8839 if (need_reset)
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04008840 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00008841
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008842 return 0;
8843}
8844
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008845/**
Singhai, Anjali6a899022015-12-14 12:21:18 -08008846 * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008847 * @pf: board private structure
8848 * @port: The UDP port to look up
8849 *
8850 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
8851 **/
Singhai, Anjali6a899022015-12-14 12:21:18 -08008852static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, __be16 port)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008853{
8854 u8 i;
8855
8856 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
Singhai, Anjali6a899022015-12-14 12:21:18 -08008857 if (pf->udp_ports[i].index == port)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008858 return i;
8859 }
8860
8861 return i;
8862}
8863
8864/**
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008865 * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008866 * @netdev: This physical port's netdev
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008867 * @ti: Tunnel endpoint information
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008868 **/
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008869static void i40e_udp_tunnel_add(struct net_device *netdev,
8870 struct udp_tunnel_info *ti)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008871{
8872 struct i40e_netdev_priv *np = netdev_priv(netdev);
8873 struct i40e_vsi *vsi = np->vsi;
8874 struct i40e_pf *pf = vsi->back;
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008875 __be16 port = ti->port;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008876 u8 next_idx;
8877 u8 idx;
8878
Singhai, Anjali6a899022015-12-14 12:21:18 -08008879 idx = i40e_get_udp_port_idx(pf, port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008880
8881 /* Check if port already exists */
8882 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008883 netdev_info(netdev, "port %d already offloaded\n",
Shannon Nelsonc22c06c2015-03-31 00:45:04 -07008884 ntohs(port));
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008885 return;
8886 }
8887
8888 /* Now check if there is space to add the new port */
Singhai, Anjali6a899022015-12-14 12:21:18 -08008889 next_idx = i40e_get_udp_port_idx(pf, 0);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008890
8891 if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008892 netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008893 ntohs(port));
8894 return;
8895 }
8896
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008897 switch (ti->type) {
8898 case UDP_TUNNEL_TYPE_VXLAN:
8899 pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
8900 break;
8901 case UDP_TUNNEL_TYPE_GENEVE:
8902 if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
8903 return;
8904 pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
8905 break;
8906 default:
8907 return;
8908 }
8909
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008910 /* New port: add it and mark its index in the bitmap */
Singhai, Anjali6a899022015-12-14 12:21:18 -08008911 pf->udp_ports[next_idx].index = port;
Singhai, Anjali6a899022015-12-14 12:21:18 -08008912 pf->pending_udp_bitmap |= BIT_ULL(next_idx);
8913 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008914}
8915
8916/**
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008917 * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008918 * @netdev: This physical port's netdev
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008919 * @ti: Tunnel endpoint information
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008920 **/
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008921static void i40e_udp_tunnel_del(struct net_device *netdev,
8922 struct udp_tunnel_info *ti)
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008923{
8924 struct i40e_netdev_priv *np = netdev_priv(netdev);
8925 struct i40e_vsi *vsi = np->vsi;
8926 struct i40e_pf *pf = vsi->back;
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008927 __be16 port = ti->port;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008928 u8 idx;
8929
Singhai, Anjali6a899022015-12-14 12:21:18 -08008930 idx = i40e_get_udp_port_idx(pf, port);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008931
8932 /* Check if port already exists */
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008933 if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
8934 goto not_found;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00008935
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008936 switch (ti->type) {
8937 case UDP_TUNNEL_TYPE_VXLAN:
8938 if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
8939 goto not_found;
8940 break;
8941 case UDP_TUNNEL_TYPE_GENEVE:
8942 if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
8943 goto not_found;
8944 break;
8945 default:
8946 goto not_found;
Singhai, Anjali6a899022015-12-14 12:21:18 -08008947 }
8948
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008949 /* if port exists, set it to 0 (mark for deletion)
8950 * and make it pending
8951 */
8952 pf->udp_ports[idx].index = 0;
8953 pf->pending_udp_bitmap |= BIT_ULL(idx);
Singhai, Anjali6a899022015-12-14 12:21:18 -08008954 pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
8955
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07008956 return;
8957not_found:
8958 netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
8959 ntohs(port));
Singhai, Anjali6a899022015-12-14 12:21:18 -08008960}
8961
Neerav Parikh1f224ad2014-02-12 01:45:31 +00008962static int i40e_get_phys_port_id(struct net_device *netdev,
Jiri Pirko02637fc2014-11-28 14:34:16 +01008963 struct netdev_phys_item_id *ppid)
Neerav Parikh1f224ad2014-02-12 01:45:31 +00008964{
8965 struct i40e_netdev_priv *np = netdev_priv(netdev);
8966 struct i40e_pf *pf = np->vsi->back;
8967 struct i40e_hw *hw = &pf->hw;
8968
8969 if (!(pf->flags & I40E_FLAG_PORT_ID_VALID))
8970 return -EOPNOTSUPP;
8971
8972 ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
8973 memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
8974
8975 return 0;
8976}
8977
Jesse Brandeburg2f90ade2014-11-20 16:30:02 -08008978/**
8979 * i40e_ndo_fdb_add - add an entry to the hardware database
8980 * @ndm: the input from the stack
8981 * @tb: pointer to array of nladdr (unused)
8982 * @dev: the net device pointer
8983 * @addr: the MAC address entry being added
8984 * @flags: instructions from stack about fdb operation
8985 */
Greg Rose4ba0dea2014-03-06 08:59:55 +00008986static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
8987 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01008988 const unsigned char *addr, u16 vid,
Greg Rose4ba0dea2014-03-06 08:59:55 +00008989 u16 flags)
Greg Rose4ba0dea2014-03-06 08:59:55 +00008990{
8991 struct i40e_netdev_priv *np = netdev_priv(dev);
8992 struct i40e_pf *pf = np->vsi->back;
8993 int err = 0;
8994
8995 if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
8996 return -EOPNOTSUPP;
8997
Or Gerlitz65891fe2014-12-14 18:19:05 +02008998 if (vid) {
8999 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
9000 return -EINVAL;
9001 }
9002
Greg Rose4ba0dea2014-03-06 08:59:55 +00009003 /* Hardware does not support aging addresses so if a
9004 * ndm_state is given only allow permanent addresses
9005 */
9006 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
9007 netdev_info(dev, "FDB only supports static addresses\n");
9008 return -EINVAL;
9009 }
9010
9011 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
9012 err = dev_uc_add_excl(dev, addr);
9013 else if (is_multicast_ether_addr(addr))
9014 err = dev_mc_add_excl(dev, addr);
9015 else
9016 err = -EINVAL;
9017
9018 /* Only return duplicate errors if NLM_F_EXCL is set */
9019 if (err == -EEXIST && !(flags & NLM_F_EXCL))
9020 err = 0;
9021
9022 return err;
9023}
9024
Neerav Parikh51616012015-02-06 08:52:14 +00009025/**
9026 * i40e_ndo_bridge_setlink - Set the hardware bridge mode
9027 * @dev: the netdev being configured
9028 * @nlh: RTNL message
9029 *
9030 * Inserts a new hardware bridge if not already created and
9031 * enables the bridging mode requested (VEB or VEPA). If the
9032 * hardware bridge has already been inserted and the request
9033 * is to change the mode then that requires a PF reset to
9034 * allow rebuild of the components with required hardware
9035 * bridge mode enabled.
9036 **/
9037static int i40e_ndo_bridge_setlink(struct net_device *dev,
Carolyn Wyborny9df70b62015-04-27 14:57:11 -04009038 struct nlmsghdr *nlh,
9039 u16 flags)
Neerav Parikh51616012015-02-06 08:52:14 +00009040{
9041 struct i40e_netdev_priv *np = netdev_priv(dev);
9042 struct i40e_vsi *vsi = np->vsi;
9043 struct i40e_pf *pf = vsi->back;
9044 struct i40e_veb *veb = NULL;
9045 struct nlattr *attr, *br_spec;
9046 int i, rem;
9047
9048 /* Only for PF VSI for now */
9049 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
9050 return -EOPNOTSUPP;
9051
9052 /* Find the HW bridge for PF VSI */
9053 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
9054 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
9055 veb = pf->veb[i];
9056 }
9057
9058 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
9059
9060 nla_for_each_nested(attr, br_spec, rem) {
9061 __u16 mode;
9062
9063 if (nla_type(attr) != IFLA_BRIDGE_MODE)
9064 continue;
9065
9066 mode = nla_get_u16(attr);
9067 if ((mode != BRIDGE_MODE_VEPA) &&
9068 (mode != BRIDGE_MODE_VEB))
9069 return -EINVAL;
9070
9071 /* Insert a new HW bridge */
9072 if (!veb) {
9073 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
9074 vsi->tc_config.enabled_tc);
9075 if (veb) {
9076 veb->bridge_mode = mode;
9077 i40e_config_bridge_mode(veb);
9078 } else {
9079 /* No Bridge HW offload available */
9080 return -ENOENT;
9081 }
9082 break;
9083 } else if (mode != veb->bridge_mode) {
9084 /* Existing HW bridge but different mode needs reset */
9085 veb->bridge_mode = mode;
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009086 /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
9087 if (mode == BRIDGE_MODE_VEB)
9088 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
9089 else
9090 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
9091 i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
Neerav Parikh51616012015-02-06 08:52:14 +00009092 break;
9093 }
9094 }
9095
9096 return 0;
9097}
9098
9099/**
9100 * i40e_ndo_bridge_getlink - Get the hardware bridge mode
9101 * @skb: skb buff
9102 * @pid: process id
9103 * @seq: RTNL message seq #
9104 * @dev: the netdev being configured
9105 * @filter_mask: unused
Jesse Brandeburgd4b2f9f2015-09-03 17:18:48 -04009106 * @nlflags: netlink flags passed in
Neerav Parikh51616012015-02-06 08:52:14 +00009107 *
9108 * Return the mode in which the hardware bridge is operating in
9109 * i.e VEB or VEPA.
9110 **/
Neerav Parikh51616012015-02-06 08:52:14 +00009111static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
9112 struct net_device *dev,
Carolyn Wyborny9f4ffc42015-08-31 19:54:42 -04009113 u32 __always_unused filter_mask,
9114 int nlflags)
Neerav Parikh51616012015-02-06 08:52:14 +00009115{
9116 struct i40e_netdev_priv *np = netdev_priv(dev);
9117 struct i40e_vsi *vsi = np->vsi;
9118 struct i40e_pf *pf = vsi->back;
9119 struct i40e_veb *veb = NULL;
9120 int i;
9121
9122 /* Only for PF VSI for now */
9123 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
9124 return -EOPNOTSUPP;
9125
9126 /* Find the HW bridge for the PF VSI */
9127 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
9128 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
9129 veb = pf->veb[i];
9130 }
9131
9132 if (!veb)
9133 return 0;
9134
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02009135 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
Huaibin Wang599b0762016-09-26 09:51:18 +02009136 0, 0, nlflags, filter_mask, NULL);
Neerav Parikh51616012015-02-06 08:52:14 +00009137}
Neerav Parikh51616012015-02-06 08:52:14 +00009138
Joe Stringerf44a75e2015-04-14 17:09:14 -07009139/**
9140 * i40e_features_check - Validate encapsulated packet conforms to limits
9141 * @skb: skb buff
Jean Sacren2bc11c62015-09-19 05:08:43 -06009142 * @dev: This physical port's netdev
Joe Stringerf44a75e2015-04-14 17:09:14 -07009143 * @features: Offload features that the stack believes apply
9144 **/
9145static netdev_features_t i40e_features_check(struct sk_buff *skb,
9146 struct net_device *dev,
9147 netdev_features_t features)
9148{
Alexander Duyckf114dca2016-10-25 16:08:46 -07009149 size_t len;
9150
9151 /* No point in doing any of this if neither checksum nor GSO are
9152 * being requested for this frame. We can rule out both by just
9153 * checking for CHECKSUM_PARTIAL
9154 */
9155 if (skb->ip_summed != CHECKSUM_PARTIAL)
9156 return features;
9157
9158 /* We cannot support GSO if the MSS is going to be less than
9159 * 64 bytes. If it is then we need to drop support for GSO.
9160 */
9161 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
9162 features &= ~NETIF_F_GSO_MASK;
9163
9164 /* MACLEN can support at most 63 words */
9165 len = skb_network_header(skb) - skb->data;
9166 if (len & ~(63 * 2))
9167 goto out_err;
9168
9169 /* IPLEN and EIPLEN can support at most 127 dwords */
9170 len = skb_transport_header(skb) - skb_network_header(skb);
9171 if (len & ~(127 * 4))
9172 goto out_err;
9173
9174 if (skb->encapsulation) {
9175 /* L4TUNLEN can support 127 words */
9176 len = skb_inner_network_header(skb) - skb_transport_header(skb);
9177 if (len & ~(127 * 2))
9178 goto out_err;
9179
9180 /* IPLEN can support at most 127 dwords */
9181 len = skb_inner_transport_header(skb) -
9182 skb_inner_network_header(skb);
9183 if (len & ~(127 * 4))
9184 goto out_err;
9185 }
9186
9187 /* No need to validate L4LEN as TCP is the only protocol with a
9188 * a flexible value and we support all possible values supported
9189 * by TCP, which is at most 15 dwords
9190 */
Joe Stringerf44a75e2015-04-14 17:09:14 -07009191
9192 return features;
Alexander Duyckf114dca2016-10-25 16:08:46 -07009193out_err:
9194 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
Joe Stringerf44a75e2015-04-14 17:09:14 -07009195}
9196
Shannon Nelson37a29732015-02-27 09:15:19 +00009197static const struct net_device_ops i40e_netdev_ops = {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009198 .ndo_open = i40e_open,
9199 .ndo_stop = i40e_close,
9200 .ndo_start_xmit = i40e_lan_xmit_frame,
9201 .ndo_get_stats64 = i40e_get_netdev_stats_struct,
9202 .ndo_set_rx_mode = i40e_set_rx_mode,
9203 .ndo_validate_addr = eth_validate_addr,
9204 .ndo_set_mac_address = i40e_set_mac,
9205 .ndo_change_mtu = i40e_change_mtu,
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00009206 .ndo_do_ioctl = i40e_ioctl,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009207 .ndo_tx_timeout = i40e_tx_timeout,
9208 .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
9209 .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
9210#ifdef CONFIG_NET_POLL_CONTROLLER
9211 .ndo_poll_controller = i40e_netpoll,
9212#endif
John Fastabende4c67342016-02-16 21:16:15 -08009213 .ndo_setup_tc = __i40e_setup_tc,
Vasu Dev38e00432014-08-01 13:27:03 -07009214#ifdef I40E_FCOE
9215 .ndo_fcoe_enable = i40e_fcoe_enable,
9216 .ndo_fcoe_disable = i40e_fcoe_disable,
9217#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009218 .ndo_set_features = i40e_set_features,
9219 .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
9220 .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04009221 .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009222 .ndo_get_vf_config = i40e_ndo_get_vf_config,
Mitch Williams588aefa2014-02-11 08:27:49 +00009223 .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
Serey Konge6d90042014-07-12 07:28:14 +00009224 .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
Anjali Singhai Jainc3bbbd22016-04-01 03:56:07 -07009225 .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
Alexander Duyck06a5f7f2016-06-16 12:22:06 -07009226 .ndo_udp_tunnel_add = i40e_udp_tunnel_add,
9227 .ndo_udp_tunnel_del = i40e_udp_tunnel_del,
Neerav Parikh1f224ad2014-02-12 01:45:31 +00009228 .ndo_get_phys_port_id = i40e_get_phys_port_id,
Greg Rose4ba0dea2014-03-06 08:59:55 +00009229 .ndo_fdb_add = i40e_ndo_fdb_add,
Joe Stringerf44a75e2015-04-14 17:09:14 -07009230 .ndo_features_check = i40e_features_check,
Neerav Parikh51616012015-02-06 08:52:14 +00009231 .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
9232 .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009233};
9234
9235/**
9236 * i40e_config_netdev - Setup the netdev flags
9237 * @vsi: the VSI being configured
9238 *
9239 * Returns 0 on success, negative value on failure
9240 **/
9241static int i40e_config_netdev(struct i40e_vsi *vsi)
9242{
9243 struct i40e_pf *pf = vsi->back;
9244 struct i40e_hw *hw = &pf->hw;
9245 struct i40e_netdev_priv *np;
9246 struct net_device *netdev;
Jacob Keller435c0842016-11-08 13:05:10 -08009247 u8 broadcast[ETH_ALEN];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009248 u8 mac_addr[ETH_ALEN];
9249 int etherdev_size;
9250
9251 etherdev_size = sizeof(struct i40e_netdev_priv);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00009252 netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009253 if (!netdev)
9254 return -ENOMEM;
9255
9256 vsi->netdev = netdev;
9257 np = netdev_priv(netdev);
9258 np->vsi = vsi;
9259
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009260 netdev->hw_enc_features |= NETIF_F_SG |
9261 NETIF_F_IP_CSUM |
9262 NETIF_F_IPV6_CSUM |
9263 NETIF_F_HIGHDMA |
9264 NETIF_F_SOFT_FEATURES |
9265 NETIF_F_TSO |
9266 NETIF_F_TSO_ECN |
9267 NETIF_F_TSO6 |
9268 NETIF_F_GSO_GRE |
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04009269 NETIF_F_GSO_GRE_CSUM |
Tom Herbert7e133182016-05-18 09:06:10 -07009270 NETIF_F_GSO_IPXIP4 |
Alexander Duyckbf2d1df2016-05-18 10:44:53 -07009271 NETIF_F_GSO_IPXIP6 |
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009272 NETIF_F_GSO_UDP_TUNNEL |
9273 NETIF_F_GSO_UDP_TUNNEL_CSUM |
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04009274 NETIF_F_GSO_PARTIAL |
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009275 NETIF_F_SCTP_CRC |
9276 NETIF_F_RXHASH |
9277 NETIF_F_RXCSUM |
Jesse Brandeburg5afdaaa2015-12-10 11:38:50 -08009278 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009279
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009280 if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE))
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04009281 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
9282
9283 netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009284
9285 /* record features VLANs can make use of */
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04009286 netdev->vlan_features |= netdev->hw_enc_features |
9287 NETIF_F_TSO_MANGLEID;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009288
Anjali Singhai Jain2e86a0b2014-04-01 07:11:53 +00009289 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009290 netdev->hw_features |= NETIF_F_NTUPLE;
Anjali Singhai Jain2e86a0b2014-04-01 07:11:53 +00009291
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009292 netdev->hw_features |= netdev->hw_enc_features |
9293 NETIF_F_HW_VLAN_CTAG_TX |
9294 NETIF_F_HW_VLAN_CTAG_RX;
9295
9296 netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
Alexander Duyck1c7b4a22016-04-14 17:19:25 -04009297 netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009298
9299 if (vsi->type == I40E_VSI_MAIN) {
9300 SET_NETDEV_DEV(netdev, &pf->pdev->dev);
Greg Rose9a173902014-05-22 06:32:02 +00009301 ether_addr_copy(mac_addr, hw->mac.perm_addr);
Jacob Keller1596b5d2016-11-08 13:05:15 -08009302 /* The following steps are necessary to prevent reception
9303 * of tagged packets - some older NVM configurations load a
9304 * default a MAC-VLAN filter that accepts any tagged packet
9305 * which must be replaced by a normal filter.
9306 */
9307 i40e_rm_default_mac_filter(vsi, mac_addr);
Jacob Keller278e7d02016-10-05 09:30:37 -07009308 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller1bc87e82016-10-05 09:30:31 -07009309 i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY);
Jacob Keller278e7d02016-10-05 09:30:37 -07009310 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009311 } else {
9312 /* relate the VSI_VMDQ name to the VSI_MAIN name */
9313 snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
9314 pf->vsi[pf->lan_vsi]->netdev->name);
9315 random_ether_addr(mac_addr);
Kiran Patil21659032015-09-30 14:09:03 -04009316
Jacob Keller278e7d02016-10-05 09:30:37 -07009317 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller1bc87e82016-10-05 09:30:31 -07009318 i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY);
Jacob Keller278e7d02016-10-05 09:30:37 -07009319 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009320 }
Kiran Patil21659032015-09-30 14:09:03 -04009321
Jacob Keller435c0842016-11-08 13:05:10 -08009322 /* Add the broadcast filter so that we initially will receive
9323 * broadcast packets. Note that when a new VLAN is first added the
9324 * driver will convert all filters marked I40E_VLAN_ANY into VLAN
9325 * specific filters as part of transitioning into "vlan" operation.
9326 * When more VLANs are added, the driver will copy each existing MAC
9327 * filter and add it for the new VLAN.
9328 *
9329 * Broadcast filters are handled specially by
9330 * i40e_sync_filters_subtask, as the driver must to set the broadcast
9331 * promiscuous bit instead of adding this directly as a MAC/VLAN
9332 * filter. The subtask will update the correct broadcast promiscuous
9333 * bits as VLANs become active or inactive.
9334 */
9335 eth_broadcast_addr(broadcast);
9336 spin_lock_bh(&vsi->mac_filter_hash_lock);
9337 i40e_add_filter(vsi, broadcast, I40E_VLAN_ANY);
9338 spin_unlock_bh(&vsi->mac_filter_hash_lock);
9339
Greg Rose9a173902014-05-22 06:32:02 +00009340 ether_addr_copy(netdev->dev_addr, mac_addr);
9341 ether_addr_copy(netdev->perm_addr, mac_addr);
Alexander Duyckb0fe3302016-04-02 00:05:14 -07009342
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009343 netdev->priv_flags |= IFF_UNICAST_FLT;
9344 netdev->priv_flags |= IFF_SUPP_NOFCS;
9345 /* Setup netdev TC information */
9346 i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
9347
9348 netdev->netdev_ops = &i40e_netdev_ops;
9349 netdev->watchdog_timeo = 5 * HZ;
9350 i40e_set_ethtool_ops(netdev);
Vasu Dev38e00432014-08-01 13:27:03 -07009351#ifdef I40E_FCOE
9352 i40e_fcoe_config_netdev(netdev, vsi);
9353#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009354
Jarod Wilson91c527a2016-10-17 15:54:05 -04009355 /* MTU range: 68 - 9706 */
9356 netdev->min_mtu = ETH_MIN_MTU;
9357 netdev->max_mtu = I40E_MAX_RXBUFFER -
9358 (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
9359
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009360 return 0;
9361}
9362
9363/**
9364 * i40e_vsi_delete - Delete a VSI from the switch
9365 * @vsi: the VSI being removed
9366 *
9367 * Returns 0 on success, negative value on failure
9368 **/
9369static void i40e_vsi_delete(struct i40e_vsi *vsi)
9370{
9371 /* remove default VSI is not allowed */
9372 if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
9373 return;
9374
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009375 i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009376}
9377
9378/**
Neerav Parikh51616012015-02-06 08:52:14 +00009379 * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
9380 * @vsi: the VSI being queried
9381 *
9382 * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
9383 **/
9384int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
9385{
9386 struct i40e_veb *veb;
9387 struct i40e_pf *pf = vsi->back;
9388
9389 /* Uplink is not a bridge so default to VEB */
9390 if (vsi->veb_idx == I40E_NO_VEB)
9391 return 1;
9392
9393 veb = pf->veb[vsi->veb_idx];
Akeem G Abodunrin09603ea2015-10-01 14:37:36 -04009394 if (!veb) {
9395 dev_info(&pf->pdev->dev,
9396 "There is no veb associated with the bridge\n");
9397 return -ENOENT;
9398 }
Neerav Parikh51616012015-02-06 08:52:14 +00009399
Akeem G Abodunrin09603ea2015-10-01 14:37:36 -04009400 /* Uplink is a bridge in VEPA mode */
9401 if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
9402 return 0;
9403 } else {
9404 /* Uplink is a bridge in VEB mode */
9405 return 1;
9406 }
9407
9408 /* VEPA is now default bridge, so return 0 */
9409 return 0;
Neerav Parikh51616012015-02-06 08:52:14 +00009410}
9411
9412/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009413 * i40e_add_vsi - Add a VSI to the switch
9414 * @vsi: the VSI being configured
9415 *
9416 * This initializes a VSI context depending on the VSI type to be added and
9417 * passes it down to the add_vsi aq command.
9418 **/
9419static int i40e_add_vsi(struct i40e_vsi *vsi)
9420{
9421 int ret = -ENODEV;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009422 struct i40e_pf *pf = vsi->back;
9423 struct i40e_hw *hw = &pf->hw;
9424 struct i40e_vsi_context ctxt;
Jacob Keller278e7d02016-10-05 09:30:37 -07009425 struct i40e_mac_filter *f;
9426 struct hlist_node *h;
9427 int bkt;
Kiran Patil21659032015-09-30 14:09:03 -04009428
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009429 u8 enabled_tc = 0x1; /* TC0 enabled */
9430 int f_count = 0;
9431
9432 memset(&ctxt, 0, sizeof(ctxt));
9433 switch (vsi->type) {
9434 case I40E_VSI_MAIN:
9435 /* The PF's main VSI is already setup as part of the
9436 * device initialization, so we'll not bother with
9437 * the add_vsi call, but we will retrieve the current
9438 * VSI context.
9439 */
9440 ctxt.seid = pf->main_vsi_seid;
9441 ctxt.pf_num = pf->hw.pf_id;
9442 ctxt.vf_num = 0;
9443 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
9444 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
9445 if (ret) {
9446 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009447 "couldn't get PF vsi config, err %s aq_err %s\n",
9448 i40e_stat_str(&pf->hw, ret),
9449 i40e_aq_str(&pf->hw,
9450 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009451 return -ENOENT;
9452 }
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07009453 vsi->info = ctxt.info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009454 vsi->info.valid_sections = 0;
9455
9456 vsi->seid = ctxt.seid;
9457 vsi->id = ctxt.vsi_number;
9458
9459 enabled_tc = i40e_pf_get_tc_map(pf);
9460
9461 /* MFP mode setup queue map and update VSI */
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00009462 if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
9463 !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009464 memset(&ctxt, 0, sizeof(ctxt));
9465 ctxt.seid = pf->main_vsi_seid;
9466 ctxt.pf_num = pf->hw.pf_id;
9467 ctxt.vf_num = 0;
9468 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
9469 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
9470 if (ret) {
9471 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009472 "update vsi failed, err %s aq_err %s\n",
9473 i40e_stat_str(&pf->hw, ret),
9474 i40e_aq_str(&pf->hw,
9475 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009476 ret = -ENOENT;
9477 goto err;
9478 }
9479 /* update the local VSI info queue map */
9480 i40e_vsi_update_queue_map(vsi, &ctxt);
9481 vsi->info.valid_sections = 0;
9482 } else {
9483 /* Default/Main VSI is only enabled for TC0
9484 * reconfigure it to enable all TCs that are
9485 * available on the port in SFP mode.
Neerav Parikh63d7e5a2014-12-14 01:55:16 +00009486 * For MFP case the iSCSI PF would use this
9487 * flow to enable LAN+iSCSI TC.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009488 */
9489 ret = i40e_vsi_config_tc(vsi, enabled_tc);
9490 if (ret) {
9491 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009492 "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
9493 enabled_tc,
9494 i40e_stat_str(&pf->hw, ret),
9495 i40e_aq_str(&pf->hw,
9496 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009497 ret = -ENOENT;
9498 }
9499 }
9500 break;
9501
9502 case I40E_VSI_FDIR:
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009503 ctxt.pf_num = hw->pf_id;
9504 ctxt.vf_num = 0;
9505 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009506 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009507 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009508 if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
9509 (i40e_is_vsi_uplink_mode_veb(vsi))) {
Neerav Parikh51616012015-02-06 08:52:14 +00009510 ctxt.info.valid_sections |=
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009511 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
Neerav Parikh51616012015-02-06 08:52:14 +00009512 ctxt.info.switch_id =
Anjali Singhai Jainfc608612015-05-08 15:35:57 -07009513 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
Neerav Parikh51616012015-02-06 08:52:14 +00009514 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009515 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009516 break;
9517
9518 case I40E_VSI_VMDQ2:
9519 ctxt.pf_num = hw->pf_id;
9520 ctxt.vf_num = 0;
9521 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009522 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009523 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
9524
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009525 /* This VSI is connected to VEB so the switch_id
9526 * should be set to zero by default.
9527 */
Neerav Parikh51616012015-02-06 08:52:14 +00009528 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
9529 ctxt.info.valid_sections |=
9530 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9531 ctxt.info.switch_id =
9532 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9533 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009534
9535 /* Setup the VSI tx/rx queue map for TC0 only for now */
9536 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9537 break;
9538
9539 case I40E_VSI_SRIOV:
9540 ctxt.pf_num = hw->pf_id;
9541 ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
9542 ctxt.uplink_seid = vsi->uplink_seid;
Neerav Parikh2b18e592015-01-24 09:58:38 +00009543 ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009544 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
9545
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009546 /* This VSI is connected to VEB so the switch_id
9547 * should be set to zero by default.
9548 */
Neerav Parikh51616012015-02-06 08:52:14 +00009549 if (i40e_is_vsi_uplink_mode_veb(vsi)) {
9550 ctxt.info.valid_sections |=
9551 cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
9552 ctxt.info.switch_id =
9553 cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
9554 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009555
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06009556 if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
9557 ctxt.info.valid_sections |=
9558 cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
9559 ctxt.info.queueing_opt_flags |=
Ashish Shah4b28cdb2016-05-03 15:13:17 -07009560 (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
9561 I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06009562 }
9563
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009564 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
9565 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
Mitch Williamsc674d122014-05-20 08:01:40 +00009566 if (pf->vf[vsi->vf_id].spoofchk) {
9567 ctxt.info.valid_sections |=
9568 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
9569 ctxt.info.sec_flags |=
9570 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
9571 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
9572 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009573 /* Setup the VSI tx/rx queue map for TC0 only for now */
9574 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
9575 break;
9576
Vasu Dev38e00432014-08-01 13:27:03 -07009577#ifdef I40E_FCOE
9578 case I40E_VSI_FCOE:
9579 ret = i40e_fcoe_vsi_init(vsi, &ctxt);
9580 if (ret) {
9581 dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n");
9582 return ret;
9583 }
9584 break;
9585
9586#endif /* I40E_FCOE */
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -06009587 case I40E_VSI_IWARP:
9588 /* send down message to iWARP */
9589 break;
9590
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009591 default:
9592 return -ENODEV;
9593 }
9594
9595 if (vsi->type != I40E_VSI_MAIN) {
9596 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
9597 if (ret) {
9598 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009599 "add vsi failed, err %s aq_err %s\n",
9600 i40e_stat_str(&pf->hw, ret),
9601 i40e_aq_str(&pf->hw,
9602 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009603 ret = -ENOENT;
9604 goto err;
9605 }
Jesse Brandeburg1a2f6242015-03-31 00:45:01 -07009606 vsi->info = ctxt.info;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009607 vsi->info.valid_sections = 0;
9608 vsi->seid = ctxt.seid;
9609 vsi->id = ctxt.vsi_number;
9610 }
9611
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07009612 vsi->active_filters = 0;
9613 clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
Jacob Keller278e7d02016-10-05 09:30:37 -07009614 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009615 /* If macvlan filters already exist, force them to get loaded */
Jacob Keller278e7d02016-10-05 09:30:37 -07009616 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
Mitch Williamsc3c7ea22016-06-20 09:10:38 -07009617 f->state = I40E_FILTER_NEW;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009618 f_count++;
9619 }
Jacob Keller278e7d02016-10-05 09:30:37 -07009620 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -04009621
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009622 if (f_count) {
9623 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
9624 pf->flags |= I40E_FLAG_FILTER_SYNC;
9625 }
9626
9627 /* Update VSI BW information */
9628 ret = i40e_vsi_get_bw_info(vsi);
9629 if (ret) {
9630 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009631 "couldn't get vsi bw info, err %s aq_err %s\n",
9632 i40e_stat_str(&pf->hw, ret),
9633 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009634 /* VSI is already added so not tearing that up */
9635 ret = 0;
9636 }
9637
9638err:
9639 return ret;
9640}
9641
9642/**
9643 * i40e_vsi_release - Delete a VSI and free its resources
9644 * @vsi: the VSI being removed
9645 *
9646 * Returns 0 on success or < 0 on error
9647 **/
9648int i40e_vsi_release(struct i40e_vsi *vsi)
9649{
Jacob Keller278e7d02016-10-05 09:30:37 -07009650 struct i40e_mac_filter *f;
9651 struct hlist_node *h;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009652 struct i40e_veb *veb = NULL;
9653 struct i40e_pf *pf;
9654 u16 uplink_seid;
Jacob Keller278e7d02016-10-05 09:30:37 -07009655 int i, n, bkt;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009656
9657 pf = vsi->back;
9658
9659 /* release of a VEB-owner or last VSI is not allowed */
9660 if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
9661 dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
9662 vsi->seid, vsi->uplink_seid);
9663 return -ENODEV;
9664 }
9665 if (vsi == pf->vsi[pf->lan_vsi] &&
9666 !test_bit(__I40E_DOWN, &pf->state)) {
9667 dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
9668 return -ENODEV;
9669 }
9670
9671 uplink_seid = vsi->uplink_seid;
9672 if (vsi->type != I40E_VSI_SRIOV) {
9673 if (vsi->netdev_registered) {
9674 vsi->netdev_registered = false;
9675 if (vsi->netdev) {
9676 /* results in a call to i40e_close() */
9677 unregister_netdev(vsi->netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009678 }
9679 } else {
Shannon Nelson90ef8d42014-03-14 07:32:26 +00009680 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009681 }
9682 i40e_vsi_disable_irq(vsi);
9683 }
9684
Jacob Keller278e7d02016-10-05 09:30:37 -07009685 spin_lock_bh(&vsi->mac_filter_hash_lock);
Jacob Keller6622f5c2016-10-05 09:30:32 -07009686
9687 /* clear the sync flag on all filters */
9688 if (vsi->netdev) {
9689 __dev_uc_unsync(vsi->netdev, NULL);
9690 __dev_mc_unsync(vsi->netdev, NULL);
9691 }
9692
9693 /* make sure any remaining filters are marked for deletion */
Jacob Keller278e7d02016-10-05 09:30:37 -07009694 hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
Jacob Keller290d2552016-10-05 09:30:36 -07009695 __i40e_del_filter(vsi, f);
Jacob Keller6622f5c2016-10-05 09:30:32 -07009696
Jacob Keller278e7d02016-10-05 09:30:37 -07009697 spin_unlock_bh(&vsi->mac_filter_hash_lock);
Kiran Patil21659032015-09-30 14:09:03 -04009698
Jesse Brandeburg17652c62015-11-05 17:01:02 -08009699 i40e_sync_vsi_filters(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009700
9701 i40e_vsi_delete(vsi);
9702 i40e_vsi_free_q_vectors(vsi);
Shannon Nelsona4866592014-02-11 08:24:07 +00009703 if (vsi->netdev) {
9704 free_netdev(vsi->netdev);
9705 vsi->netdev = NULL;
9706 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009707 i40e_vsi_clear_rings(vsi);
9708 i40e_vsi_clear(vsi);
9709
9710 /* If this was the last thing on the VEB, except for the
9711 * controlling VSI, remove the VEB, which puts the controlling
9712 * VSI onto the next level down in the switch.
9713 *
9714 * Well, okay, there's one more exception here: don't remove
9715 * the orphan VEBs yet. We'll wait for an explicit remove request
9716 * from up the network stack.
9717 */
Mitch Williams505682c2014-05-20 08:01:37 +00009718 for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009719 if (pf->vsi[i] &&
9720 pf->vsi[i]->uplink_seid == uplink_seid &&
9721 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
9722 n++; /* count the VSIs */
9723 }
9724 }
9725 for (i = 0; i < I40E_MAX_VEB; i++) {
9726 if (!pf->veb[i])
9727 continue;
9728 if (pf->veb[i]->uplink_seid == uplink_seid)
9729 n++; /* count the VEBs */
9730 if (pf->veb[i]->seid == uplink_seid)
9731 veb = pf->veb[i];
9732 }
9733 if (n == 0 && veb && veb->uplink_seid != 0)
9734 i40e_veb_release(veb);
9735
9736 return 0;
9737}
9738
9739/**
9740 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
9741 * @vsi: ptr to the VSI
9742 *
9743 * This should only be called after i40e_vsi_mem_alloc() which allocates the
9744 * corresponding SW VSI structure and initializes num_queue_pairs for the
9745 * newly allocated VSI.
9746 *
9747 * Returns 0 on success or negative on failure
9748 **/
9749static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
9750{
9751 int ret = -ENOENT;
9752 struct i40e_pf *pf = vsi->back;
9753
Alexander Duyck493fb302013-09-28 07:01:44 +00009754 if (vsi->q_vectors[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009755 dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
9756 vsi->seid);
9757 return -EEXIST;
9758 }
9759
9760 if (vsi->base_vector) {
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00009761 dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009762 vsi->seid, vsi->base_vector);
9763 return -EEXIST;
9764 }
9765
Greg Rose90e04072014-03-06 08:59:57 +00009766 ret = i40e_vsi_alloc_q_vectors(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009767 if (ret) {
9768 dev_info(&pf->pdev->dev,
9769 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
9770 vsi->num_q_vectors, vsi->seid, ret);
9771 vsi->num_q_vectors = 0;
9772 goto vector_setup_out;
9773 }
9774
Anjali Singhai Jain26cdc442015-07-10 19:36:00 -04009775 /* In Legacy mode, we do not have to get any other vector since we
9776 * piggyback on the misc/ICR0 for queue interrupts.
9777 */
9778 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
9779 return ret;
Shannon Nelson958a3e32013-09-28 07:13:28 +00009780 if (vsi->num_q_vectors)
9781 vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
9782 vsi->num_q_vectors, vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009783 if (vsi->base_vector < 0) {
9784 dev_info(&pf->pdev->dev,
Shannon Nelson049a2be2014-10-17 03:14:50 +00009785 "failed to get tracking for %d vectors for VSI %d, err=%d\n",
9786 vsi->num_q_vectors, vsi->seid, vsi->base_vector);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009787 i40e_vsi_free_q_vectors(vsi);
9788 ret = -ENOENT;
9789 goto vector_setup_out;
9790 }
9791
9792vector_setup_out:
9793 return ret;
9794}
9795
9796/**
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009797 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
9798 * @vsi: pointer to the vsi.
9799 *
9800 * This re-allocates a vsi's queue resources.
9801 *
9802 * Returns pointer to the successfully allocated and configured VSI sw struct
9803 * on success, otherwise returns NULL on failure.
9804 **/
9805static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
9806{
John Underwoodf5340392016-02-18 09:19:24 -08009807 struct i40e_pf *pf;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009808 u8 enabled_tc;
9809 int ret;
9810
John Underwoodf5340392016-02-18 09:19:24 -08009811 if (!vsi)
9812 return NULL;
9813
9814 pf = vsi->back;
9815
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009816 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
9817 i40e_vsi_clear_rings(vsi);
9818
9819 i40e_vsi_free_arrays(vsi, false);
9820 i40e_set_num_rings_in_vsi(vsi);
9821 ret = i40e_vsi_alloc_arrays(vsi, false);
9822 if (ret)
9823 goto err_vsi;
9824
9825 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
9826 if (ret < 0) {
Shannon Nelson049a2be2014-10-17 03:14:50 +00009827 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04009828 "failed to get tracking for %d queues for VSI %d err %d\n",
Shannon Nelson049a2be2014-10-17 03:14:50 +00009829 vsi->alloc_queue_pairs, vsi->seid, ret);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009830 goto err_vsi;
9831 }
9832 vsi->base_queue = ret;
9833
9834 /* Update the FW view of the VSI. Force a reset of TC and queue
9835 * layout configurations.
9836 */
9837 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
9838 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
9839 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
9840 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
Jacob Keller1596b5d2016-11-08 13:05:15 -08009841 if (vsi->type == I40E_VSI_MAIN)
9842 i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00009843
9844 /* assign it some queues */
9845 ret = i40e_alloc_rings(vsi);
9846 if (ret)
9847 goto err_rings;
9848
9849 /* map all of the rings to the q_vectors */
9850 i40e_vsi_map_rings_to_vectors(vsi);
9851 return vsi;
9852
9853err_rings:
9854 i40e_vsi_free_q_vectors(vsi);
9855 if (vsi->netdev_registered) {
9856 vsi->netdev_registered = false;
9857 unregister_netdev(vsi->netdev);
9858 free_netdev(vsi->netdev);
9859 vsi->netdev = NULL;
9860 }
9861 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
9862err_vsi:
9863 i40e_vsi_clear(vsi);
9864 return NULL;
9865}
9866
9867/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009868 * i40e_vsi_setup - Set up a VSI by a given type
9869 * @pf: board private structure
9870 * @type: VSI type
9871 * @uplink_seid: the switch element to link to
9872 * @param1: usage depends upon VSI type. For VF types, indicates VF id
9873 *
9874 * This allocates the sw VSI structure and its queue resources, then add a VSI
9875 * to the identified VEB.
9876 *
9877 * Returns pointer to the successfully allocated and configure VSI sw struct on
9878 * success, otherwise returns NULL on failure.
9879 **/
9880struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
9881 u16 uplink_seid, u32 param1)
9882{
9883 struct i40e_vsi *vsi = NULL;
9884 struct i40e_veb *veb = NULL;
9885 int ret, i;
9886 int v_idx;
9887
9888 /* The requested uplink_seid must be either
9889 * - the PF's port seid
9890 * no VEB is needed because this is the PF
9891 * or this is a Flow Director special case VSI
9892 * - seid of an existing VEB
9893 * - seid of a VSI that owns an existing VEB
9894 * - seid of a VSI that doesn't own a VEB
9895 * a new VEB is created and the VSI becomes the owner
9896 * - seid of the PF VSI, which is what creates the first VEB
9897 * this is a special case of the previous
9898 *
9899 * Find which uplink_seid we were given and create a new VEB if needed
9900 */
9901 for (i = 0; i < I40E_MAX_VEB; i++) {
9902 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
9903 veb = pf->veb[i];
9904 break;
9905 }
9906 }
9907
9908 if (!veb && uplink_seid != pf->mac_seid) {
9909
Mitch Williams505682c2014-05-20 08:01:37 +00009910 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009911 if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
9912 vsi = pf->vsi[i];
9913 break;
9914 }
9915 }
9916 if (!vsi) {
9917 dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
9918 uplink_seid);
9919 return NULL;
9920 }
9921
9922 if (vsi->uplink_seid == pf->mac_seid)
9923 veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
9924 vsi->tc_config.enabled_tc);
9925 else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
9926 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
9927 vsi->tc_config.enabled_tc);
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009928 if (veb) {
9929 if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
9930 dev_info(&vsi->back->pdev->dev,
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04009931 "New VSI creation error, uplink seid of LAN VSI expected.\n");
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009932 return NULL;
9933 }
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -04009934 /* We come up by default in VEPA mode if SRIOV is not
9935 * already enabled, in which case we can't force VEPA
9936 * mode.
9937 */
9938 if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
9939 veb->bridge_mode = BRIDGE_MODE_VEPA;
9940 pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
9941 }
Neerav Parikh51616012015-02-06 08:52:14 +00009942 i40e_config_bridge_mode(veb);
Anjali Singhai Jain79c21a82014-11-13 03:06:14 +00009943 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009944 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
9945 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
9946 veb = pf->veb[i];
9947 }
9948 if (!veb) {
9949 dev_info(&pf->pdev->dev, "couldn't add VEB\n");
9950 return NULL;
9951 }
9952
9953 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
9954 uplink_seid = veb->seid;
9955 }
9956
9957 /* get vsi sw struct */
9958 v_idx = i40e_vsi_mem_alloc(pf, type);
9959 if (v_idx < 0)
9960 goto err_alloc;
9961 vsi = pf->vsi[v_idx];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009962 if (!vsi)
9963 goto err_alloc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009964 vsi->type = type;
9965 vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
9966
9967 if (type == I40E_VSI_MAIN)
9968 pf->lan_vsi = v_idx;
9969 else if (type == I40E_VSI_SRIOV)
9970 vsi->vf_id = param1;
9971 /* assign it some queues */
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08009972 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
9973 vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009974 if (ret < 0) {
Shannon Nelson049a2be2014-10-17 03:14:50 +00009975 dev_info(&pf->pdev->dev,
9976 "failed to get tracking for %d queues for VSI %d err=%d\n",
9977 vsi->alloc_queue_pairs, vsi->seid, ret);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009978 goto err_vsi;
9979 }
9980 vsi->base_queue = ret;
9981
9982 /* get a VSI from the hardware */
9983 vsi->uplink_seid = uplink_seid;
9984 ret = i40e_add_vsi(vsi);
9985 if (ret)
9986 goto err_vsi;
9987
9988 switch (vsi->type) {
9989 /* setup the netdev if needed */
9990 case I40E_VSI_MAIN:
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -05009991 /* Apply relevant filters if a platform-specific mac
9992 * address was selected.
9993 */
9994 if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
9995 ret = i40e_macaddr_init(vsi, pf->hw.mac.addr);
9996 if (ret) {
9997 dev_warn(&pf->pdev->dev,
9998 "could not set up macaddr; err %d\n",
9999 ret);
10000 }
10001 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010002 case I40E_VSI_VMDQ2:
Vasu Dev38e00432014-08-01 13:27:03 -070010003 case I40E_VSI_FCOE:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010004 ret = i40e_config_netdev(vsi);
10005 if (ret)
10006 goto err_netdev;
10007 ret = register_netdev(vsi->netdev);
10008 if (ret)
10009 goto err_netdev;
10010 vsi->netdev_registered = true;
10011 netif_carrier_off(vsi->netdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080010012#ifdef CONFIG_I40E_DCB
10013 /* Setup DCB netlink interface */
10014 i40e_dcbnl_setup(vsi);
10015#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010016 /* fall through */
10017
10018 case I40E_VSI_FDIR:
10019 /* set up vectors and rings if needed */
10020 ret = i40e_vsi_setup_vectors(vsi);
10021 if (ret)
10022 goto err_msix;
10023
10024 ret = i40e_alloc_rings(vsi);
10025 if (ret)
10026 goto err_rings;
10027
10028 /* map all of the rings to the q_vectors */
10029 i40e_vsi_map_rings_to_vectors(vsi);
10030
10031 i40e_vsi_reset_stats(vsi);
10032 break;
10033
10034 default:
10035 /* no netdev or rings for the other VSI types */
10036 break;
10037 }
10038
Anjali Singhai Jaine25d00b2015-06-23 19:00:04 -040010039 if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
10040 (vsi->type == I40E_VSI_VMDQ2)) {
10041 ret = i40e_vsi_config_rss(vsi);
10042 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010043 return vsi;
10044
10045err_rings:
10046 i40e_vsi_free_q_vectors(vsi);
10047err_msix:
10048 if (vsi->netdev_registered) {
10049 vsi->netdev_registered = false;
10050 unregister_netdev(vsi->netdev);
10051 free_netdev(vsi->netdev);
10052 vsi->netdev = NULL;
10053 }
10054err_netdev:
10055 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
10056err_vsi:
10057 i40e_vsi_clear(vsi);
10058err_alloc:
10059 return NULL;
10060}
10061
10062/**
10063 * i40e_veb_get_bw_info - Query VEB BW information
10064 * @veb: the veb to query
10065 *
10066 * Query the Tx scheduler BW configuration data for given VEB
10067 **/
10068static int i40e_veb_get_bw_info(struct i40e_veb *veb)
10069{
10070 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
10071 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
10072 struct i40e_pf *pf = veb->pf;
10073 struct i40e_hw *hw = &pf->hw;
10074 u32 tc_bw_max;
10075 int ret = 0;
10076 int i;
10077
10078 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
10079 &bw_data, NULL);
10080 if (ret) {
10081 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010082 "query veb bw config failed, err %s aq_err %s\n",
10083 i40e_stat_str(&pf->hw, ret),
10084 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010085 goto out;
10086 }
10087
10088 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
10089 &ets_data, NULL);
10090 if (ret) {
10091 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010092 "query veb bw ets config failed, err %s aq_err %s\n",
10093 i40e_stat_str(&pf->hw, ret),
10094 i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010095 goto out;
10096 }
10097
10098 veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
10099 veb->bw_max_quanta = ets_data.tc_bw_max;
10100 veb->is_abs_credits = bw_data.absolute_credits_enable;
Neerav Parikh23cd1f02014-11-12 00:18:41 +000010101 veb->enabled_tc = ets_data.tc_valid_bits;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010102 tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
10103 (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
10104 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10105 veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
10106 veb->bw_tc_limit_credits[i] =
10107 le16_to_cpu(bw_data.tc_bw_limits[i]);
10108 veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
10109 }
10110
10111out:
10112 return ret;
10113}
10114
10115/**
10116 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
10117 * @pf: board private structure
10118 *
10119 * On error: returns error code (negative)
10120 * On success: returns vsi index in PF (positive)
10121 **/
10122static int i40e_veb_mem_alloc(struct i40e_pf *pf)
10123{
10124 int ret = -ENOENT;
10125 struct i40e_veb *veb;
10126 int i;
10127
10128 /* Need to protect the allocation of switch elements at the PF level */
10129 mutex_lock(&pf->switch_mutex);
10130
10131 /* VEB list may be fragmented if VEB creation/destruction has
10132 * been happening. We can afford to do a quick scan to look
10133 * for any free slots in the list.
10134 *
10135 * find next empty veb slot, looping back around if necessary
10136 */
10137 i = 0;
10138 while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
10139 i++;
10140 if (i >= I40E_MAX_VEB) {
10141 ret = -ENOMEM;
10142 goto err_alloc_veb; /* out of VEB slots! */
10143 }
10144
10145 veb = kzalloc(sizeof(*veb), GFP_KERNEL);
10146 if (!veb) {
10147 ret = -ENOMEM;
10148 goto err_alloc_veb;
10149 }
10150 veb->pf = pf;
10151 veb->idx = i;
10152 veb->enabled_tc = 1;
10153
10154 pf->veb[i] = veb;
10155 ret = i;
10156err_alloc_veb:
10157 mutex_unlock(&pf->switch_mutex);
10158 return ret;
10159}
10160
10161/**
10162 * i40e_switch_branch_release - Delete a branch of the switch tree
10163 * @branch: where to start deleting
10164 *
10165 * This uses recursion to find the tips of the branch to be
10166 * removed, deleting until we get back to and can delete this VEB.
10167 **/
10168static void i40e_switch_branch_release(struct i40e_veb *branch)
10169{
10170 struct i40e_pf *pf = branch->pf;
10171 u16 branch_seid = branch->seid;
10172 u16 veb_idx = branch->idx;
10173 int i;
10174
10175 /* release any VEBs on this VEB - RECURSION */
10176 for (i = 0; i < I40E_MAX_VEB; i++) {
10177 if (!pf->veb[i])
10178 continue;
10179 if (pf->veb[i]->uplink_seid == branch->seid)
10180 i40e_switch_branch_release(pf->veb[i]);
10181 }
10182
10183 /* Release the VSIs on this VEB, but not the owner VSI.
10184 *
10185 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
10186 * the VEB itself, so don't use (*branch) after this loop.
10187 */
Mitch Williams505682c2014-05-20 08:01:37 +000010188 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010189 if (!pf->vsi[i])
10190 continue;
10191 if (pf->vsi[i]->uplink_seid == branch_seid &&
10192 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
10193 i40e_vsi_release(pf->vsi[i]);
10194 }
10195 }
10196
10197 /* There's one corner case where the VEB might not have been
10198 * removed, so double check it here and remove it if needed.
10199 * This case happens if the veb was created from the debugfs
10200 * commands and no VSIs were added to it.
10201 */
10202 if (pf->veb[veb_idx])
10203 i40e_veb_release(pf->veb[veb_idx]);
10204}
10205
10206/**
10207 * i40e_veb_clear - remove veb struct
10208 * @veb: the veb to remove
10209 **/
10210static void i40e_veb_clear(struct i40e_veb *veb)
10211{
10212 if (!veb)
10213 return;
10214
10215 if (veb->pf) {
10216 struct i40e_pf *pf = veb->pf;
10217
10218 mutex_lock(&pf->switch_mutex);
10219 if (pf->veb[veb->idx] == veb)
10220 pf->veb[veb->idx] = NULL;
10221 mutex_unlock(&pf->switch_mutex);
10222 }
10223
10224 kfree(veb);
10225}
10226
10227/**
10228 * i40e_veb_release - Delete a VEB and free its resources
10229 * @veb: the VEB being removed
10230 **/
10231void i40e_veb_release(struct i40e_veb *veb)
10232{
10233 struct i40e_vsi *vsi = NULL;
10234 struct i40e_pf *pf;
10235 int i, n = 0;
10236
10237 pf = veb->pf;
10238
10239 /* find the remaining VSI and check for extras */
Mitch Williams505682c2014-05-20 08:01:37 +000010240 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010241 if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
10242 n++;
10243 vsi = pf->vsi[i];
10244 }
10245 }
10246 if (n != 1) {
10247 dev_info(&pf->pdev->dev,
10248 "can't remove VEB %d with %d VSIs left\n",
10249 veb->seid, n);
10250 return;
10251 }
10252
10253 /* move the remaining VSI to uplink veb */
10254 vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
10255 if (veb->uplink_seid) {
10256 vsi->uplink_seid = veb->uplink_seid;
10257 if (veb->uplink_seid == pf->mac_seid)
10258 vsi->veb_idx = I40E_NO_VEB;
10259 else
10260 vsi->veb_idx = veb->veb_idx;
10261 } else {
10262 /* floating VEB */
10263 vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
10264 vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
10265 }
10266
10267 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
10268 i40e_veb_clear(veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010269}
10270
10271/**
10272 * i40e_add_veb - create the VEB in the switch
10273 * @veb: the VEB to be instantiated
10274 * @vsi: the controlling VSI
10275 **/
10276static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
10277{
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010278 struct i40e_pf *pf = veb->pf;
Shannon Nelson66fc3602016-01-13 16:51:42 -080010279 bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010280 int ret;
10281
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010282 ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
Mitch Williams5bc16032016-05-16 10:26:43 -070010283 veb->enabled_tc, false,
Shannon Nelson66fc3602016-01-13 16:51:42 -080010284 &veb->seid, enable_stats, NULL);
Mitch Williams5bc16032016-05-16 10:26:43 -070010285
10286 /* get a VEB from the hardware */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010287 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010288 dev_info(&pf->pdev->dev,
10289 "couldn't add VEB, err %s aq_err %s\n",
10290 i40e_stat_str(&pf->hw, ret),
10291 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010292 return -EPERM;
10293 }
10294
10295 /* get statistics counter */
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010296 ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010297 &veb->stats_idx, NULL, NULL, NULL);
10298 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010299 dev_info(&pf->pdev->dev,
10300 "couldn't get VEB statistics idx, err %s aq_err %s\n",
10301 i40e_stat_str(&pf->hw, ret),
10302 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010303 return -EPERM;
10304 }
10305 ret = i40e_veb_get_bw_info(veb);
10306 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010307 dev_info(&pf->pdev->dev,
10308 "couldn't get VEB bw info, err %s aq_err %s\n",
10309 i40e_stat_str(&pf->hw, ret),
10310 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
10311 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010312 return -ENOENT;
10313 }
10314
10315 vsi->uplink_seid = veb->seid;
10316 vsi->veb_idx = veb->idx;
10317 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
10318
10319 return 0;
10320}
10321
10322/**
10323 * i40e_veb_setup - Set up a VEB
10324 * @pf: board private structure
10325 * @flags: VEB setup flags
10326 * @uplink_seid: the switch element to link to
10327 * @vsi_seid: the initial VSI seid
10328 * @enabled_tc: Enabled TC bit-map
10329 *
10330 * This allocates the sw VEB structure and links it into the switch
10331 * It is possible and legal for this to be a duplicate of an already
10332 * existing VEB. It is also possible for both uplink and vsi seids
10333 * to be zero, in order to create a floating VEB.
10334 *
10335 * Returns pointer to the successfully allocated VEB sw struct on
10336 * success, otherwise returns NULL on failure.
10337 **/
10338struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
10339 u16 uplink_seid, u16 vsi_seid,
10340 u8 enabled_tc)
10341{
10342 struct i40e_veb *veb, *uplink_veb = NULL;
10343 int vsi_idx, veb_idx;
10344 int ret;
10345
10346 /* if one seid is 0, the other must be 0 to create a floating relay */
10347 if ((uplink_seid == 0 || vsi_seid == 0) &&
10348 (uplink_seid + vsi_seid != 0)) {
10349 dev_info(&pf->pdev->dev,
10350 "one, not both seid's are 0: uplink=%d vsi=%d\n",
10351 uplink_seid, vsi_seid);
10352 return NULL;
10353 }
10354
10355 /* make sure there is such a vsi and uplink */
Mitch Williams505682c2014-05-20 08:01:37 +000010356 for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010357 if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
10358 break;
Mitch Williams505682c2014-05-20 08:01:37 +000010359 if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010360 dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
10361 vsi_seid);
10362 return NULL;
10363 }
10364
10365 if (uplink_seid && uplink_seid != pf->mac_seid) {
10366 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
10367 if (pf->veb[veb_idx] &&
10368 pf->veb[veb_idx]->seid == uplink_seid) {
10369 uplink_veb = pf->veb[veb_idx];
10370 break;
10371 }
10372 }
10373 if (!uplink_veb) {
10374 dev_info(&pf->pdev->dev,
10375 "uplink seid %d not found\n", uplink_seid);
10376 return NULL;
10377 }
10378 }
10379
10380 /* get veb sw struct */
10381 veb_idx = i40e_veb_mem_alloc(pf);
10382 if (veb_idx < 0)
10383 goto err_alloc;
10384 veb = pf->veb[veb_idx];
10385 veb->flags = flags;
10386 veb->uplink_seid = uplink_seid;
10387 veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
10388 veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
10389
10390 /* create the VEB in the switch */
10391 ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
10392 if (ret)
10393 goto err_veb;
Shannon Nelson1bb8b932014-04-23 04:49:54 +000010394 if (vsi_idx == pf->lan_vsi)
10395 pf->lan_veb = veb->idx;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010396
10397 return veb;
10398
10399err_veb:
10400 i40e_veb_clear(veb);
10401err_alloc:
10402 return NULL;
10403}
10404
10405/**
Jeff Kirsherb40c82e2015-02-27 09:18:34 +000010406 * i40e_setup_pf_switch_element - set PF vars based on switch type
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010407 * @pf: board private structure
10408 * @ele: element we are building info from
10409 * @num_reported: total number of elements
10410 * @printconfig: should we print the contents
10411 *
10412 * helper function to assist in extracting a few useful SEID values.
10413 **/
10414static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
10415 struct i40e_aqc_switch_config_element_resp *ele,
10416 u16 num_reported, bool printconfig)
10417{
10418 u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
10419 u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
10420 u8 element_type = ele->element_type;
10421 u16 seid = le16_to_cpu(ele->seid);
10422
10423 if (printconfig)
10424 dev_info(&pf->pdev->dev,
10425 "type=%d seid=%d uplink=%d downlink=%d\n",
10426 element_type, seid, uplink_seid, downlink_seid);
10427
10428 switch (element_type) {
10429 case I40E_SWITCH_ELEMENT_TYPE_MAC:
10430 pf->mac_seid = seid;
10431 break;
10432 case I40E_SWITCH_ELEMENT_TYPE_VEB:
10433 /* Main VEB? */
10434 if (uplink_seid != pf->mac_seid)
10435 break;
10436 if (pf->lan_veb == I40E_NO_VEB) {
10437 int v;
10438
10439 /* find existing or else empty VEB */
10440 for (v = 0; v < I40E_MAX_VEB; v++) {
10441 if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
10442 pf->lan_veb = v;
10443 break;
10444 }
10445 }
10446 if (pf->lan_veb == I40E_NO_VEB) {
10447 v = i40e_veb_mem_alloc(pf);
10448 if (v < 0)
10449 break;
10450 pf->lan_veb = v;
10451 }
10452 }
10453
10454 pf->veb[pf->lan_veb]->seid = seid;
10455 pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
10456 pf->veb[pf->lan_veb]->pf = pf;
10457 pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
10458 break;
10459 case I40E_SWITCH_ELEMENT_TYPE_VSI:
10460 if (num_reported != 1)
10461 break;
10462 /* This is immediately after a reset so we can assume this is
10463 * the PF's VSI
10464 */
10465 pf->mac_seid = uplink_seid;
10466 pf->pf_seid = downlink_seid;
10467 pf->main_vsi_seid = seid;
10468 if (printconfig)
10469 dev_info(&pf->pdev->dev,
10470 "pf_seid=%d main_vsi_seid=%d\n",
10471 pf->pf_seid, pf->main_vsi_seid);
10472 break;
10473 case I40E_SWITCH_ELEMENT_TYPE_PF:
10474 case I40E_SWITCH_ELEMENT_TYPE_VF:
10475 case I40E_SWITCH_ELEMENT_TYPE_EMP:
10476 case I40E_SWITCH_ELEMENT_TYPE_BMC:
10477 case I40E_SWITCH_ELEMENT_TYPE_PE:
10478 case I40E_SWITCH_ELEMENT_TYPE_PA:
10479 /* ignore these for now */
10480 break;
10481 default:
10482 dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
10483 element_type, seid);
10484 break;
10485 }
10486}
10487
10488/**
10489 * i40e_fetch_switch_configuration - Get switch config from firmware
10490 * @pf: board private structure
10491 * @printconfig: should we print the contents
10492 *
10493 * Get the current switch configuration from the device and
10494 * extract a few useful SEID values.
10495 **/
10496int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
10497{
10498 struct i40e_aqc_get_switch_config_resp *sw_config;
10499 u16 next_seid = 0;
10500 int ret = 0;
10501 u8 *aq_buf;
10502 int i;
10503
10504 aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
10505 if (!aq_buf)
10506 return -ENOMEM;
10507
10508 sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
10509 do {
10510 u16 num_reported, num_total;
10511
10512 ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
10513 I40E_AQ_LARGE_BUF,
10514 &next_seid, NULL);
10515 if (ret) {
10516 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010517 "get switch config failed err %s aq_err %s\n",
10518 i40e_stat_str(&pf->hw, ret),
10519 i40e_aq_str(&pf->hw,
10520 pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010521 kfree(aq_buf);
10522 return -ENOENT;
10523 }
10524
10525 num_reported = le16_to_cpu(sw_config->header.num_reported);
10526 num_total = le16_to_cpu(sw_config->header.num_total);
10527
10528 if (printconfig)
10529 dev_info(&pf->pdev->dev,
10530 "header: %d reported %d total\n",
10531 num_reported, num_total);
10532
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010533 for (i = 0; i < num_reported; i++) {
10534 struct i40e_aqc_switch_config_element_resp *ele =
10535 &sw_config->element[i];
10536
10537 i40e_setup_pf_switch_element(pf, ele, num_reported,
10538 printconfig);
10539 }
10540 } while (next_seid != 0);
10541
10542 kfree(aq_buf);
10543 return ret;
10544}
10545
10546/**
10547 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
10548 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010549 * @reinit: if the Main VSI needs to re-initialized.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010550 *
10551 * Returns 0 on success, negative value on failure
10552 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010553static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010554{
Anjali Singhai Jainb5569892016-05-03 15:13:12 -070010555 u16 flags = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010556 int ret;
10557
10558 /* find out what's out there already */
10559 ret = i40e_fetch_switch_configuration(pf, false);
10560 if (ret) {
10561 dev_info(&pf->pdev->dev,
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040010562 "couldn't fetch switch config, err %s aq_err %s\n",
10563 i40e_stat_str(&pf->hw, ret),
10564 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010565 return ret;
10566 }
10567 i40e_pf_reset_stats(pf);
10568
Anjali Singhai Jainb5569892016-05-03 15:13:12 -070010569 /* set the switch config bit for the whole device to
10570 * support limited promisc or true promisc
10571 * when user requests promisc. The default is limited
10572 * promisc.
10573 */
10574
10575 if ((pf->hw.pf_id == 0) &&
10576 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
10577 flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
10578
10579 if (pf->hw.pf_id == 0) {
10580 u16 valid_flags;
10581
10582 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
10583 ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags,
10584 NULL);
10585 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
10586 dev_info(&pf->pdev->dev,
10587 "couldn't set switch config bits, err %s aq_err %s\n",
10588 i40e_stat_str(&pf->hw, ret),
10589 i40e_aq_str(&pf->hw,
10590 pf->hw.aq.asq_last_status));
10591 /* not a fatal problem, just keep going */
10592 }
10593 }
10594
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010595 /* first time setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010596 if (pf->lan_vsi == I40E_NO_VSI || reinit) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010597 struct i40e_vsi *vsi = NULL;
10598 u16 uplink_seid;
10599
10600 /* Set up the PF VSI associated with the PF's main VSI
10601 * that is already in the HW switch
10602 */
10603 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
10604 uplink_seid = pf->veb[pf->lan_veb]->seid;
10605 else
10606 uplink_seid = pf->mac_seid;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000010607 if (pf->lan_vsi == I40E_NO_VSI)
10608 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
10609 else if (reinit)
10610 vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010611 if (!vsi) {
10612 dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
10613 i40e_fdir_teardown(pf);
10614 return -EAGAIN;
10615 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010616 } else {
10617 /* force a reset of TC and queue layout configurations */
10618 u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
Jesse Brandeburg6995b362015-08-28 17:55:54 -040010619
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010620 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
10621 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
10622 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
10623 }
10624 i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
10625
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010626 i40e_fdir_sb_setup(pf);
10627
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010628 /* Setup static PF queue filter control settings */
10629 ret = i40e_setup_pf_filter_control(pf);
10630 if (ret) {
10631 dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
10632 ret);
10633 /* Failure here should not stop continuing other steps */
10634 }
10635
10636 /* enable RSS in the HW, even for only one queue, as the stack can use
10637 * the hash
10638 */
10639 if ((pf->flags & I40E_FLAG_RSS_ENABLED))
Helin Zhang043dd652015-10-21 19:56:23 -040010640 i40e_pf_config_rss(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010641
10642 /* fill in link information and enable LSE reporting */
Catherine Sullivan0a862b42015-08-31 19:54:53 -040010643 i40e_update_link_info(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010644 i40e_link_event(pf);
10645
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000010646 /* Initialize user-specific link properties */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010647 pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
10648 I40E_AQ_AN_COMPLETED) ? true : false);
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000010649
Jacob Kellerbeb0dff2014-01-11 05:43:19 +000010650 i40e_ptp_init(pf);
10651
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010652 return ret;
10653}
10654
10655/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010656 * i40e_determine_queue_usage - Work out queue distribution
10657 * @pf: board private structure
10658 **/
10659static void i40e_determine_queue_usage(struct i40e_pf *pf)
10660{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010661 int queues_left;
10662
10663 pf->num_lan_qps = 0;
Vasu Dev38e00432014-08-01 13:27:03 -070010664#ifdef I40E_FCOE
10665 pf->num_fcoe_qps = 0;
10666#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010667
10668 /* Find the max queues to be put into basic use. We'll always be
10669 * using TC0, whether or not DCB is running, and TC0 will get the
10670 * big RSS set.
10671 */
10672 queues_left = pf->hw.func_caps.num_tx_qp;
10673
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010674 if ((queues_left == 1) ||
Frank Zhang9aa7e932014-05-20 08:01:42 +000010675 !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010676 /* one qp for PF, no queues for anything else */
10677 queues_left = 0;
Helin Zhangacd65442015-10-26 19:44:28 -040010678 pf->alloc_rss_size = pf->num_lan_qps = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010679
10680 /* make sure all the fancies are disabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010681 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060010682 I40E_FLAG_IWARP_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -070010683#ifdef I40E_FCOE
10684 I40E_FLAG_FCOE_ENABLED |
10685#endif
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010686 I40E_FLAG_FD_SB_ENABLED |
10687 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010688 I40E_FLAG_DCB_CAPABLE |
Dave Ertmana0362442016-08-29 17:38:26 -070010689 I40E_FLAG_DCB_ENABLED |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010690 I40E_FLAG_SRIOV_ENABLED |
10691 I40E_FLAG_VMDQ_ENABLED);
Frank Zhang9aa7e932014-05-20 08:01:42 +000010692 } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
10693 I40E_FLAG_FD_SB_ENABLED |
Anjali Singhai Jainbbe7d0e2014-05-20 08:01:44 +000010694 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010695 I40E_FLAG_DCB_CAPABLE))) {
Frank Zhang9aa7e932014-05-20 08:01:42 +000010696 /* one qp for PF */
Helin Zhangacd65442015-10-26 19:44:28 -040010697 pf->alloc_rss_size = pf->num_lan_qps = 1;
Frank Zhang9aa7e932014-05-20 08:01:42 +000010698 queues_left -= pf->num_lan_qps;
10699
10700 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060010701 I40E_FLAG_IWARP_ENABLED |
Vasu Dev38e00432014-08-01 13:27:03 -070010702#ifdef I40E_FCOE
10703 I40E_FLAG_FCOE_ENABLED |
10704#endif
Frank Zhang9aa7e932014-05-20 08:01:42 +000010705 I40E_FLAG_FD_SB_ENABLED |
10706 I40E_FLAG_FD_ATR_ENABLED |
10707 I40E_FLAG_DCB_ENABLED |
10708 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010709 } else {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010710 /* Not enough queues for all TCs */
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010711 if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010712 (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
Dave Ertmana0362442016-08-29 17:38:26 -070010713 pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
10714 I40E_FLAG_DCB_ENABLED);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010715 dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
10716 }
Anjali Singhai Jain9a3bd2f2015-02-24 06:58:44 +000010717 pf->num_lan_qps = max_t(int, pf->rss_size_max,
10718 num_online_cpus());
10719 pf->num_lan_qps = min_t(int, pf->num_lan_qps,
10720 pf->hw.func_caps.num_tx_qp);
10721
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010722 queues_left -= pf->num_lan_qps;
10723 }
10724
Vasu Dev38e00432014-08-01 13:27:03 -070010725#ifdef I40E_FCOE
10726 if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
10727 if (I40E_DEFAULT_FCOE <= queues_left) {
10728 pf->num_fcoe_qps = I40E_DEFAULT_FCOE;
10729 } else if (I40E_MINIMUM_FCOE <= queues_left) {
10730 pf->num_fcoe_qps = I40E_MINIMUM_FCOE;
10731 } else {
10732 pf->num_fcoe_qps = 0;
10733 pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
10734 dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n");
10735 }
10736
10737 queues_left -= pf->num_fcoe_qps;
10738 }
10739
10740#endif
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010741 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
10742 if (queues_left > 1) {
10743 queues_left -= 1; /* save 1 queue for FD */
10744 } else {
10745 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
10746 dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
10747 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010748 }
10749
10750 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
10751 pf->num_vf_qps && pf->num_req_vfs && queues_left) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080010752 pf->num_req_vfs = min_t(int, pf->num_req_vfs,
10753 (queues_left / pf->num_vf_qps));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010754 queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
10755 }
10756
10757 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
10758 pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
10759 pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
10760 (queues_left / pf->num_vmdq_qps));
10761 queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
10762 }
10763
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +000010764 pf->queues_left = queues_left;
Neerav Parikh8279e492015-09-03 17:18:50 -040010765 dev_dbg(&pf->pdev->dev,
10766 "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
10767 pf->hw.func_caps.num_tx_qp,
10768 !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
Helin Zhangacd65442015-10-26 19:44:28 -040010769 pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
10770 pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
10771 queues_left);
Vasu Dev38e00432014-08-01 13:27:03 -070010772#ifdef I40E_FCOE
Neerav Parikh8279e492015-09-03 17:18:50 -040010773 dev_dbg(&pf->pdev->dev, "fcoe queues = %d\n", pf->num_fcoe_qps);
Vasu Dev38e00432014-08-01 13:27:03 -070010774#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010775}
10776
10777/**
10778 * i40e_setup_pf_filter_control - Setup PF static filter control
10779 * @pf: PF to be setup
10780 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +000010781 * i40e_setup_pf_filter_control sets up a PF's initial filter control
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010782 * settings. If PE/FCoE are enabled then it will also set the per PF
10783 * based filter sizes required for them. It also enables Flow director,
10784 * ethertype and macvlan type filter settings for the pf.
10785 *
10786 * Returns 0 on success, negative on failure
10787 **/
10788static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
10789{
10790 struct i40e_filter_control_settings *settings = &pf->filter_settings;
10791
10792 settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
10793
10794 /* Flow Director is enabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -080010795 if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010796 settings->enable_fdir = true;
10797
10798 /* Ethtype and MACVLAN filters enabled for PF */
10799 settings->enable_ethtype = true;
10800 settings->enable_macvlan = true;
10801
10802 if (i40e_set_filter_control(&pf->hw, settings))
10803 return -ENOENT;
10804
10805 return 0;
10806}
10807
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010808#define INFO_STRING_LEN 255
Shannon Nelson7fd89542015-10-21 19:47:04 -040010809#define REMAIN(__x) (INFO_STRING_LEN - (__x))
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010810static void i40e_print_features(struct i40e_pf *pf)
10811{
10812 struct i40e_hw *hw = &pf->hw;
Joe Perches3b195842015-12-03 04:20:57 -080010813 char *buf;
10814 int i;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010815
Joe Perches3b195842015-12-03 04:20:57 -080010816 buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
10817 if (!buf)
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010818 return;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010819
Joe Perches3b195842015-12-03 04:20:57 -080010820 i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010821#ifdef CONFIG_PCI_IOV
Joe Perches3b195842015-12-03 04:20:57 -080010822 i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010823#endif
Jesse Brandeburg1a557afc2016-04-20 19:43:37 -070010824 i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
Shannon Nelson7fd89542015-10-21 19:47:04 -040010825 pf->hw.func_caps.num_vsis,
Jesse Brandeburg1a557afc2016-04-20 19:43:37 -070010826 pf->vsi[pf->lan_vsi]->num_queue_pairs);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010827 if (pf->flags & I40E_FLAG_RSS_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010828 i += snprintf(&buf[i], REMAIN(i), " RSS");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010829 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010830 i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +000010831 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
Joe Perches3b195842015-12-03 04:20:57 -080010832 i += snprintf(&buf[i], REMAIN(i), " FD_SB");
10833 i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +000010834 }
Neerav Parikh4d9b6042014-05-22 06:31:51 +000010835 if (pf->flags & I40E_FLAG_DCB_CAPABLE)
Joe Perches3b195842015-12-03 04:20:57 -080010836 i += snprintf(&buf[i], REMAIN(i), " DCB");
Joe Perches3b195842015-12-03 04:20:57 -080010837 i += snprintf(&buf[i], REMAIN(i), " VxLAN");
Singhai, Anjali6a899022015-12-14 12:21:18 -080010838 i += snprintf(&buf[i], REMAIN(i), " Geneve");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010839 if (pf->flags & I40E_FLAG_PTP)
Joe Perches3b195842015-12-03 04:20:57 -080010840 i += snprintf(&buf[i], REMAIN(i), " PTP");
Vasu Dev38e00432014-08-01 13:27:03 -070010841#ifdef I40E_FCOE
10842 if (pf->flags & I40E_FLAG_FCOE_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010843 i += snprintf(&buf[i], REMAIN(i), " FCOE");
Vasu Dev38e00432014-08-01 13:27:03 -070010844#endif
Shannon Nelson6dec1012015-09-28 14:12:30 -040010845 if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
Joe Perches3b195842015-12-03 04:20:57 -080010846 i += snprintf(&buf[i], REMAIN(i), " VEB");
Shannon Nelson6dec1012015-09-28 14:12:30 -040010847 else
Joe Perches3b195842015-12-03 04:20:57 -080010848 i += snprintf(&buf[i], REMAIN(i), " VEPA");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010849
Joe Perches3b195842015-12-03 04:20:57 -080010850 dev_info(&pf->pdev->dev, "%s\n", buf);
10851 kfree(buf);
Shannon Nelson7fd89542015-10-21 19:47:04 -040010852 WARN_ON(i > INFO_STRING_LEN);
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000010853}
10854
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010855/**
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010856 * i40e_get_platform_mac_addr - get platform-specific MAC address
10857 *
10858 * @pdev: PCI device information struct
10859 * @pf: board private structure
10860 *
10861 * Look up the MAC address in Open Firmware on systems that support it,
10862 * and use IDPROM on SPARC if no OF address is found. On return, the
10863 * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value
10864 * has been selected.
10865 **/
10866static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
10867{
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010868 pf->flags &= ~I40E_FLAG_PF_MAC;
Sowmini Varadhanba942722016-01-12 19:32:31 -080010869 if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010870 pf->flags |= I40E_FLAG_PF_MAC;
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050010871}
10872
10873/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010874 * i40e_probe - Device initialization routine
10875 * @pdev: PCI device information struct
10876 * @ent: entry in i40e_pci_tbl
10877 *
Jeff Kirsherb40c82e2015-02-27 09:18:34 +000010878 * i40e_probe initializes a PF identified by a pci_dev structure.
10879 * The OS initialization, configuring of the PF private structure,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010880 * and a hardware reset occur.
10881 *
10882 * Returns 0 on success, negative on failure
10883 **/
10884static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
10885{
Catherine Sullivane8278452015-02-06 08:52:08 +000010886 struct i40e_aq_get_phy_abilities_resp abilities;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010887 struct i40e_pf *pf;
10888 struct i40e_hw *hw;
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000010889 static u16 pfs_found;
Shannon Nelson1d5109d2015-08-26 15:14:08 -040010890 u16 wol_nvm_bits;
Catherine Sullivand4dfb812013-11-28 06:39:21 +000010891 u16 link_status;
Jean Sacren6f66a482015-09-19 05:08:45 -060010892 int err;
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -040010893 u32 val;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000010894 u32 i;
Helin Zhang58fc3262015-10-01 14:37:38 -040010895 u8 set_fc_aq_fail;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010896
10897 err = pci_enable_device_mem(pdev);
10898 if (err)
10899 return err;
10900
10901 /* set up for high or low dma */
Mitch Williams64942942014-02-11 08:26:33 +000010902 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +000010903 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +000010904 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
10905 if (err) {
10906 dev_err(&pdev->dev,
10907 "DMA configuration failed: 0x%x\n", err);
10908 goto err_dma;
10909 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010910 }
10911
10912 /* set up pci connections */
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010913 err = pci_request_mem_regions(pdev, i40e_driver_name);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010914 if (err) {
10915 dev_info(&pdev->dev,
10916 "pci_request_selected_regions failed %d\n", err);
10917 goto err_pci_reg;
10918 }
10919
10920 pci_enable_pcie_error_reporting(pdev);
10921 pci_set_master(pdev);
10922
10923 /* Now that we have a PCI connection, we need to do the
10924 * low level device setup. This is primarily setting up
10925 * the Admin Queue structures and then querying for the
10926 * device's current profile information.
10927 */
10928 pf = kzalloc(sizeof(*pf), GFP_KERNEL);
10929 if (!pf) {
10930 err = -ENOMEM;
10931 goto err_pf_alloc;
10932 }
10933 pf->next_vsi = 0;
10934 pf->pdev = pdev;
10935 set_bit(__I40E_DOWN, &pf->state);
10936
10937 hw = &pf->hw;
10938 hw->back = pf;
Anjali Singhai232f4702015-02-26 16:15:39 +000010939
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010940 pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
10941 I40E_MAX_CSR_SPACE);
Anjali Singhai232f4702015-02-26 16:15:39 +000010942
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010943 hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010944 if (!hw->hw_addr) {
10945 err = -EIO;
10946 dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
10947 (unsigned int)pci_resource_start(pdev, 0),
Shannon Nelson2ac8b672015-07-23 16:54:37 -040010948 pf->ioremap_len, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010949 goto err_ioremap;
10950 }
10951 hw->vendor_id = pdev->vendor;
10952 hw->device_id = pdev->device;
10953 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
10954 hw->subsystem_vendor_id = pdev->subsystem_vendor;
10955 hw->subsystem_device_id = pdev->subsystem_device;
10956 hw->bus.device = PCI_SLOT(pdev->devfn);
10957 hw->bus.func = PCI_FUNC(pdev->devfn);
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000010958 pf->instance = pfs_found;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010959
Shannon Nelsonde03d2b2016-03-10 14:59:44 -080010960 /* set up the locks for the AQ, do this only once in probe
10961 * and destroy them only once in remove
10962 */
10963 mutex_init(&hw->aq.asq_mutex);
10964 mutex_init(&hw->aq.arq_mutex);
10965
Alexander Duyck5d4ca232016-09-30 08:21:46 -040010966 pf->msg_enable = netif_msg_init(debug,
10967 NETIF_MSG_DRV |
10968 NETIF_MSG_PROBE |
10969 NETIF_MSG_LINK);
10970 if (debug < -1)
10971 pf->hw.debug_mask = debug;
Shannon Nelson5b5faa42014-10-17 03:14:51 +000010972
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +000010973 /* do a special CORER for clearing PXE mode once at init */
10974 if (hw->revision_id == 0 &&
10975 (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
10976 wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
10977 i40e_flush(hw);
10978 msleep(200);
10979 pf->corer_count++;
10980
10981 i40e_clear_pxe_mode(hw);
10982 }
10983
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010984 /* Reset here to make sure all is clean and to define PF 'n' */
Shannon Nelson838d41d2014-06-04 20:41:27 +000010985 i40e_clear_hw(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000010986 err = i40e_pf_reset(hw);
10987 if (err) {
10988 dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
10989 goto err_pf_reset;
10990 }
10991 pf->pfr_count++;
10992
10993 hw->aq.num_arq_entries = I40E_AQ_LEN;
10994 hw->aq.num_asq_entries = I40E_AQ_LEN;
10995 hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
10996 hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
10997 pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +000010998
Carolyn Wybornyb294ac72014-12-11 07:06:39 +000010999 snprintf(pf->int_name, sizeof(pf->int_name) - 1,
Carolyn Wybornyb2008cb2014-11-11 20:05:26 +000011000 "%s-%s:misc",
11001 dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011002
11003 err = i40e_init_shared_code(hw);
11004 if (err) {
Anjali Singhai Jainb2a75c52015-04-27 14:57:20 -040011005 dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
11006 err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011007 goto err_pf_reset;
11008 }
11009
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +000011010 /* set up a default setting for link flow control */
11011 pf->hw.fc.requested_mode = I40E_FC_NONE;
11012
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011013 err = i40e_init_adminq(hw);
Carolyn Wyborny2b2426a762015-10-26 19:44:35 -040011014 if (err) {
11015 if (err == I40E_ERR_FIRMWARE_API_VERSION)
11016 dev_info(&pdev->dev,
11017 "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");
11018 else
11019 dev_info(&pdev->dev,
11020 "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
11021
11022 goto err_pf_reset;
11023 }
Carolyn Wybornyf0b44442015-08-31 19:54:49 -040011024
Shannon Nelson6dec1012015-09-28 14:12:30 -040011025 /* provide nvm, fw, api versions */
11026 dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
11027 hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
11028 hw->aq.api_maj_ver, hw->aq.api_min_ver,
11029 i40e_nvm_version_str(hw));
Carolyn Wybornyf0b44442015-08-31 19:54:49 -040011030
Catherine Sullivan7aa67612014-07-09 07:46:17 +000011031 if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
11032 hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
Shannon Nelson278b6f62014-06-04 01:41:03 +000011033 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000011034 "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");
11035 else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
11036 hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
Shannon Nelson278b6f62014-06-04 01:41:03 +000011037 dev_info(&pdev->dev,
Catherine Sullivan7aa67612014-07-09 07:46:17 +000011038 "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 +000011039
Shannon Nelson4eb3f762014-03-06 08:59:58 +000011040 i40e_verify_eeprom(pf);
11041
Jesse Brandeburg2c5fe332014-04-23 04:49:57 +000011042 /* Rev 0 hardware was never productized */
11043 if (hw->revision_id < 1)
11044 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");
11045
Shannon Nelson6ff4ef82013-12-21 05:44:49 +000011046 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011047 err = i40e_get_capabilities(pf);
11048 if (err)
11049 goto err_adminq_setup;
11050
11051 err = i40e_sw_init(pf);
11052 if (err) {
11053 dev_info(&pdev->dev, "sw_init failed: %d\n", err);
11054 goto err_sw_init;
11055 }
11056
11057 err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
11058 hw->func_caps.num_rx_qp,
11059 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
11060 if (err) {
11061 dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
11062 goto err_init_lan_hmc;
11063 }
11064
11065 err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
11066 if (err) {
11067 dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
11068 err = -ENOENT;
11069 goto err_configure_lan_hmc;
11070 }
11071
Neerav Parikhb686ece2014-12-14 01:55:11 +000011072 /* Disable LLDP for NICs that have firmware versions lower than v4.3.
11073 * Ignore error return codes because if it was already disabled via
11074 * hardware settings this will fail
11075 */
Neerav Parikhf1bbad32016-01-13 16:51:39 -080011076 if (pf->flags & I40E_FLAG_STOP_FW_LLDP) {
Neerav Parikhb686ece2014-12-14 01:55:11 +000011077 dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
11078 i40e_aq_stop_lldp(hw, true, NULL);
11079 }
11080
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011081 i40e_get_mac_addr(hw, hw->mac.addr);
Sowmini Varadhanb499ffb2015-12-07 15:06:34 -050011082 /* allow a platform config to override the HW addr */
11083 i40e_get_platform_mac_addr(pdev, pf);
Jesse Brandeburgf62b5062013-11-28 06:39:27 +000011084 if (!is_valid_ether_addr(hw->mac.addr)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011085 dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
11086 err = -EIO;
11087 goto err_mac_addr;
11088 }
11089 dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
Greg Rose9a173902014-05-22 06:32:02 +000011090 ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
Neerav Parikh1f224ad2014-02-12 01:45:31 +000011091 i40e_get_port_mac_addr(hw, hw->mac.port_addr);
11092 if (is_valid_ether_addr(hw->mac.port_addr))
11093 pf->flags |= I40E_FLAG_PORT_ID_VALID;
Vasu Dev38e00432014-08-01 13:27:03 -070011094#ifdef I40E_FCOE
11095 err = i40e_get_san_mac_addr(hw, hw->mac.san_addr);
11096 if (err)
11097 dev_info(&pdev->dev,
11098 "(non-fatal) SAN MAC retrieval failed: %d\n", err);
11099 if (!is_valid_ether_addr(hw->mac.san_addr)) {
11100 dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
11101 hw->mac.san_addr);
11102 ether_addr_copy(hw->mac.san_addr, hw->mac.addr);
11103 }
11104 dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr);
11105#endif /* I40E_FCOE */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011106
11107 pci_set_drvdata(pdev, pf);
11108 pci_save_state(pdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080011109#ifdef CONFIG_I40E_DCB
11110 err = i40e_init_pf_dcb(pf);
11111 if (err) {
Shannon Nelsonaebfc812014-12-11 07:06:38 +000011112 dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
David Ertmanc17ef432016-09-30 01:36:21 -070011113 pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED);
Neerav Parikh014269f2014-04-01 07:11:48 +000011114 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080011115 }
11116#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011117
11118 /* set up periodic task facility */
11119 setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
11120 pf->service_timer_period = HZ;
11121
11122 INIT_WORK(&pf->service_task, i40e_service_task);
11123 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
11124 pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011125
Shannon Nelson1d5109d2015-08-26 15:14:08 -040011126 /* NVM bit on means WoL disabled for the port */
11127 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg75f5cea2015-11-19 11:34:14 -080011128 if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
Shannon Nelson1d5109d2015-08-26 15:14:08 -040011129 pf->wol_en = false;
11130 else
11131 pf->wol_en = true;
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011132 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
11133
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011134 /* set up the main switch operations */
11135 i40e_determine_queue_usage(pf);
Jesse Brandeburgc11472802015-04-07 19:45:39 -040011136 err = i40e_init_interrupt_scheme(pf);
11137 if (err)
11138 goto err_switch_setup;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011139
Mitch Williams505682c2014-05-20 08:01:37 +000011140 /* The number of VSIs reported by the FW is the minimum guaranteed
11141 * to us; HW supports far more and we share the remaining pool with
11142 * the other PFs. We allocate space for more than the guarantee with
11143 * the understanding that we might not get them all later.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011144 */
Mitch Williams505682c2014-05-20 08:01:37 +000011145 if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
11146 pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
11147 else
11148 pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
11149
11150 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
Jesse Brandeburgd17038d2015-12-23 12:05:55 -080011151 pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
11152 GFP_KERNEL);
Wei Yongjuned87ac02013-09-24 05:17:25 +000011153 if (!pf->vsi) {
11154 err = -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011155 goto err_switch_setup;
Wei Yongjuned87ac02013-09-24 05:17:25 +000011156 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011157
Anjali Singhai Jainfa11cb32015-05-27 12:06:14 -040011158#ifdef CONFIG_PCI_IOV
11159 /* prep for VF support */
11160 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
11161 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
11162 !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
11163 if (pci_num_vf(pdev))
11164 pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
11165 }
11166#endif
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000011167 err = i40e_setup_pf_switch(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011168 if (err) {
11169 dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
11170 goto err_vsis;
11171 }
Helin Zhang58fc3262015-10-01 14:37:38 -040011172
11173 /* Make sure flow control is set according to current settings */
11174 err = i40e_set_fc(hw, &set_fc_aq_fail, true);
11175 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
11176 dev_dbg(&pf->pdev->dev,
11177 "Set fc with err %s aq_err %s on get_phy_cap\n",
11178 i40e_stat_str(hw, err),
11179 i40e_aq_str(hw, hw->aq.asq_last_status));
11180 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
11181 dev_dbg(&pf->pdev->dev,
11182 "Set fc with err %s aq_err %s on set_phy_config\n",
11183 i40e_stat_str(hw, err),
11184 i40e_aq_str(hw, hw->aq.asq_last_status));
11185 if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
11186 dev_dbg(&pf->pdev->dev,
11187 "Set fc with err %s aq_err %s on get_link_info\n",
11188 i40e_stat_str(hw, err),
11189 i40e_aq_str(hw, hw->aq.asq_last_status));
11190
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000011191 /* if FDIR VSI was set up, start it now */
Mitch Williams505682c2014-05-20 08:01:37 +000011192 for (i = 0; i < pf->num_alloc_vsi; i++) {
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +000011193 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
11194 i40e_vsi_open(pf->vsi[i]);
11195 break;
11196 }
11197 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011198
Shannon Nelson2f0aff42016-01-04 10:33:08 -080011199 /* The driver only wants link up/down and module qualification
11200 * reports from firmware. Note the negative logic.
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000011201 */
11202 err = i40e_aq_set_phy_int_mask(&pf->hw,
Shannon Nelson2f0aff42016-01-04 10:33:08 -080011203 ~(I40E_AQ_EVENT_LINK_UPDOWN |
Shannon Nelson867a79e2016-03-18 12:18:15 -070011204 I40E_AQ_EVENT_MEDIA_NA |
Shannon Nelson2f0aff42016-01-04 10:33:08 -080011205 I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000011206 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040011207 dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
11208 i40e_stat_str(&pf->hw, err),
11209 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +000011210
Anjali Singhai Jain4f2f017c2015-10-21 19:47:07 -040011211 /* Reconfigure hardware for allowing smaller MSS in the case
11212 * of TSO, so that we avoid the MDD being fired and causing
11213 * a reset in the case of small MSS+TSO.
11214 */
11215 val = rd32(hw, I40E_REG_MSS);
11216 if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
11217 val &= ~I40E_REG_MSS_MIN_MASK;
11218 val |= I40E_64BYTE_MSS;
11219 wr32(hw, I40E_REG_MSS, val);
11220 }
11221
Anjali Singhai Jain8eed76f2015-12-09 15:50:31 -080011222 if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
Anjali Singhai Jain025b4a52015-02-24 06:58:46 +000011223 msleep(75);
11224 err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
11225 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040011226 dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
11227 i40e_stat_str(&pf->hw, err),
11228 i40e_aq_str(&pf->hw,
11229 pf->hw.aq.asq_last_status));
Anjali Singhai Jaincafa2ee2014-09-13 07:40:45 +000011230 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011231 /* The main driver is (mostly) up and happy. We need to set this state
11232 * before setting up the misc vector or we get a race and the vector
11233 * ends up disabled forever.
11234 */
11235 clear_bit(__I40E_DOWN, &pf->state);
11236
11237 /* In case of MSIX we are going to setup the misc vector right here
11238 * to handle admin queue events etc. In case of legacy and MSI
11239 * the misc functionality and queue processing is combined in
11240 * the same vector and that gets setup at open.
11241 */
11242 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
11243 err = i40e_setup_misc_vector(pf);
11244 if (err) {
11245 dev_info(&pdev->dev,
11246 "setup of misc vector failed: %d\n", err);
11247 goto err_vsis;
11248 }
11249 }
11250
Greg Rosedf805f62014-04-04 04:43:16 +000011251#ifdef CONFIG_PCI_IOV
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011252 /* prep for VF support */
11253 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
Shannon Nelson4eb3f762014-03-06 08:59:58 +000011254 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
11255 !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011256 /* disable link interrupts for VFs */
11257 val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
11258 val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
11259 wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
11260 i40e_flush(hw);
Mitch Williams4aeec012014-02-13 03:48:47 -080011261
11262 if (pci_num_vf(pdev)) {
11263 dev_info(&pdev->dev,
11264 "Active VFs found, allocating resources.\n");
11265 err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
11266 if (err)
11267 dev_info(&pdev->dev,
11268 "Error %d allocating resources for existing VFs\n",
11269 err);
11270 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011271 }
Greg Rosedf805f62014-04-04 04:43:16 +000011272#endif /* CONFIG_PCI_IOV */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011273
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011274 if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
11275 pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
11276 pf->num_iwarp_msix,
11277 I40E_IWARP_IRQ_PILE_ID);
11278 if (pf->iwarp_base_vector < 0) {
11279 dev_info(&pdev->dev,
11280 "failed to get tracking for %d vectors for IWARP err=%d\n",
11281 pf->num_iwarp_msix, pf->iwarp_base_vector);
11282 pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
11283 }
11284 }
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +000011285
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011286 i40e_dbg_pf_init(pf);
11287
11288 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +000011289 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011290
11291 /* since everything's happy, start the service_task timer */
11292 mod_timer(&pf->service_timer,
11293 round_jiffies(jiffies + pf->service_timer_period));
11294
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011295 /* add this PF to client device list and launch a client service task */
11296 err = i40e_lan_add_device(pf);
11297 if (err)
11298 dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
11299 err);
11300
Vasu Dev38e00432014-08-01 13:27:03 -070011301#ifdef I40E_FCOE
11302 /* create FCoE interface */
11303 i40e_fcoe_vsi_setup(pf);
11304
11305#endif
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011306#define PCI_SPEED_SIZE 8
11307#define PCI_WIDTH_SIZE 8
11308 /* Devices on the IOSF bus do not have this information
11309 * and will report PCI Gen 1 x 1 by default so don't bother
11310 * checking them.
11311 */
11312 if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) {
11313 char speed[PCI_SPEED_SIZE] = "Unknown";
11314 char width[PCI_WIDTH_SIZE] = "Unknown";
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011315
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011316 /* Get the negotiated link width and speed from PCI config
11317 * space
11318 */
11319 pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
11320 &link_status);
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011321
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011322 i40e_set_pci_config_data(hw, link_status);
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011323
Anjali Singhai Jain3fced532015-09-03 17:18:59 -040011324 switch (hw->bus.speed) {
11325 case i40e_bus_speed_8000:
11326 strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
11327 case i40e_bus_speed_5000:
11328 strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
11329 case i40e_bus_speed_2500:
11330 strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
11331 default:
11332 break;
11333 }
11334 switch (hw->bus.width) {
11335 case i40e_bus_width_pcie_x8:
11336 strncpy(width, "8", PCI_WIDTH_SIZE); break;
11337 case i40e_bus_width_pcie_x4:
11338 strncpy(width, "4", PCI_WIDTH_SIZE); break;
11339 case i40e_bus_width_pcie_x2:
11340 strncpy(width, "2", PCI_WIDTH_SIZE); break;
11341 case i40e_bus_width_pcie_x1:
11342 strncpy(width, "1", PCI_WIDTH_SIZE); break;
11343 default:
11344 break;
11345 }
11346
11347 dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
11348 speed, width);
11349
11350 if (hw->bus.width < i40e_bus_width_pcie_x8 ||
11351 hw->bus.speed < i40e_bus_speed_8000) {
11352 dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
11353 dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
11354 }
Catherine Sullivand4dfb812013-11-28 06:39:21 +000011355 }
11356
Catherine Sullivane8278452015-02-06 08:52:08 +000011357 /* get the requested speeds from the fw */
11358 err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
11359 if (err)
Neerav Parikh8279e492015-09-03 17:18:50 -040011360 dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
11361 i40e_stat_str(&pf->hw, err),
11362 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
Catherine Sullivane8278452015-02-06 08:52:08 +000011363 pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
11364
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -040011365 /* get the supported phy types from the fw */
11366 err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
11367 if (err)
11368 dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
11369 i40e_stat_str(&pf->hw, err),
11370 i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
11371 pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type);
11372
Anjali Singhai Jaine7358f52015-10-01 14:37:34 -040011373 /* Add a filter to drop all Flow control frames from any VSI from being
11374 * transmitted. By doing so we stop a malicious VF from sending out
11375 * PAUSE or PFC frames and potentially controlling traffic for other
11376 * PF/VF VSIs.
11377 * The FW can still send Flow control frames if enabled.
11378 */
11379 i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
11380 pf->main_vsi_seid);
11381
Carolyn Wyborny31b606d2016-02-17 16:12:12 -080011382 if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
Henry Tieman4f9b4302016-11-08 13:05:18 -080011383 (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
11384 pf->flags |= I40E_FLAG_PHY_CONTROLS_LEDS;
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -080011385 if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722)
11386 pf->flags |= I40E_FLAG_HAVE_CRT_RETIMER;
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +000011387 /* print a string summarizing features */
11388 i40e_print_features(pf);
11389
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011390 return 0;
11391
11392 /* Unwind what we've done if something failed in the setup */
11393err_vsis:
11394 set_bit(__I40E_DOWN, &pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011395 i40e_clear_interrupt_scheme(pf);
11396 kfree(pf->vsi);
Shannon Nelson04b03012013-11-28 06:39:34 +000011397err_switch_setup:
11398 i40e_reset_interrupt_capability(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011399 del_timer_sync(&pf->service_timer);
11400err_mac_addr:
11401err_configure_lan_hmc:
11402 (void)i40e_shutdown_lan_hmc(hw);
11403err_init_lan_hmc:
11404 kfree(pf->qp_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011405err_sw_init:
11406err_adminq_setup:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011407err_pf_reset:
11408 iounmap(hw->hw_addr);
11409err_ioremap:
11410 kfree(pf);
11411err_pf_alloc:
11412 pci_disable_pcie_error_reporting(pdev);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020011413 pci_release_mem_regions(pdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011414err_pci_reg:
11415err_dma:
11416 pci_disable_device(pdev);
11417 return err;
11418}
11419
11420/**
11421 * i40e_remove - Device removal routine
11422 * @pdev: PCI device information struct
11423 *
11424 * i40e_remove is called by the PCI subsystem to alert the driver
11425 * that is should release a PCI device. This could be caused by a
11426 * Hot-Plug event, or because the driver is going to be removed from
11427 * memory.
11428 **/
11429static void i40e_remove(struct pci_dev *pdev)
11430{
11431 struct i40e_pf *pf = pci_get_drvdata(pdev);
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011432 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011433 i40e_status ret_code;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011434 int i;
11435
11436 i40e_dbg_pf_exit(pf);
11437
Jacob Kellerbeb0dff2014-01-11 05:43:19 +000011438 i40e_ptp_stop(pf);
11439
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011440 /* Disable RSS in hw */
Shannon Nelson272cdaf22016-02-17 16:12:21 -080011441 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
11442 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
Carolyn Wybornybcab2db2015-09-28 14:16:55 -040011443
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011444 /* no more scheduling of any task */
Pandi Kumar Maharajana4618ec2016-02-18 09:19:25 -080011445 set_bit(__I40E_SUSPENDED, &pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011446 set_bit(__I40E_DOWN, &pf->state);
Shannon Nelsonc99abb42016-03-10 14:59:45 -080011447 if (pf->service_timer.data)
11448 del_timer_sync(&pf->service_timer);
11449 if (pf->service_task.func)
11450 cancel_work_sync(&pf->service_task);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011451
Mitch Williamseb2d80b2014-02-13 03:48:48 -080011452 if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
11453 i40e_free_vfs(pf);
11454 pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
11455 }
11456
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011457 i40e_fdir_teardown(pf);
11458
11459 /* If there is a switch structure or any orphans, remove them.
11460 * This will leave only the PF's VSI remaining.
11461 */
11462 for (i = 0; i < I40E_MAX_VEB; i++) {
11463 if (!pf->veb[i])
11464 continue;
11465
11466 if (pf->veb[i]->uplink_seid == pf->mac_seid ||
11467 pf->veb[i]->uplink_seid == 0)
11468 i40e_switch_branch_release(pf->veb[i]);
11469 }
11470
11471 /* Now we can shutdown the PF's VSI, just before we kill
11472 * adminq and hmc.
11473 */
11474 if (pf->vsi[pf->lan_vsi])
11475 i40e_vsi_release(pf->vsi[pf->lan_vsi]);
11476
Anjali Singhai Jaine3219ce2016-01-20 13:40:01 -060011477 /* remove attached clients */
11478 ret_code = i40e_lan_del_device(pf);
11479 if (ret_code) {
11480 dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
11481 ret_code);
11482 }
11483
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011484 /* shutdown and destroy the HMC */
Jesse Brandeburgf734dff2016-01-15 14:33:11 -080011485 if (hw->hmc.hmc_obj) {
11486 ret_code = i40e_shutdown_lan_hmc(hw);
Shannon Nelson60442de2014-04-23 04:50:13 +000011487 if (ret_code)
11488 dev_warn(&pdev->dev,
11489 "Failed to destroy the HMC resources: %d\n",
11490 ret_code);
11491 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011492
11493 /* shutdown the adminq */
Henry Tiemanac9c5c62016-09-06 18:05:11 -070011494 i40e_shutdown_adminq(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011495
Jesse Brandeburg8ddb3322015-11-18 15:47:06 -080011496 /* destroy the locks only once, here */
11497 mutex_destroy(&hw->aq.arq_mutex);
11498 mutex_destroy(&hw->aq.asq_mutex);
11499
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011500 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
11501 i40e_clear_interrupt_scheme(pf);
Mitch Williams505682c2014-05-20 08:01:37 +000011502 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011503 if (pf->vsi[i]) {
11504 i40e_vsi_clear_rings(pf->vsi[i]);
11505 i40e_vsi_clear(pf->vsi[i]);
11506 pf->vsi[i] = NULL;
11507 }
11508 }
11509
11510 for (i = 0; i < I40E_MAX_VEB; i++) {
11511 kfree(pf->veb[i]);
11512 pf->veb[i] = NULL;
11513 }
11514
11515 kfree(pf->qp_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011516 kfree(pf->vsi);
11517
Jesse Brandeburgf734dff2016-01-15 14:33:11 -080011518 iounmap(hw->hw_addr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011519 kfree(pf);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020011520 pci_release_mem_regions(pdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011521
11522 pci_disable_pcie_error_reporting(pdev);
11523 pci_disable_device(pdev);
11524}
11525
11526/**
11527 * i40e_pci_error_detected - warning that something funky happened in PCI land
11528 * @pdev: PCI device information struct
11529 *
11530 * Called to warn that something happened and the error handling steps
11531 * are in progress. Allows the driver to quiesce things, be ready for
11532 * remediation.
11533 **/
11534static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
11535 enum pci_channel_state error)
11536{
11537 struct i40e_pf *pf = pci_get_drvdata(pdev);
11538
11539 dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
11540
Guilherme G Piccoliedfc23ee2016-10-03 00:31:12 -070011541 if (!pf) {
11542 dev_info(&pdev->dev,
11543 "Cannot recover - error happened during device probe\n");
11544 return PCI_ERS_RESULT_DISCONNECT;
11545 }
11546
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011547 /* shutdown all operations */
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011548 if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
11549 rtnl_lock();
11550 i40e_prep_for_reset(pf);
11551 rtnl_unlock();
11552 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011553
11554 /* Request a slot reset */
11555 return PCI_ERS_RESULT_NEED_RESET;
11556}
11557
11558/**
11559 * i40e_pci_error_slot_reset - a PCI slot reset just happened
11560 * @pdev: PCI device information struct
11561 *
11562 * Called to find if the driver can work with the device now that
11563 * the pci slot has been reset. If a basic connection seems good
11564 * (registers are readable and have sane content) then return a
11565 * happy little PCI_ERS_RESULT_xxx.
11566 **/
11567static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
11568{
11569 struct i40e_pf *pf = pci_get_drvdata(pdev);
11570 pci_ers_result_t result;
11571 int err;
11572 u32 reg;
11573
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011574 dev_dbg(&pdev->dev, "%s\n", __func__);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011575 if (pci_enable_device_mem(pdev)) {
11576 dev_info(&pdev->dev,
11577 "Cannot re-enable PCI device after reset.\n");
11578 result = PCI_ERS_RESULT_DISCONNECT;
11579 } else {
11580 pci_set_master(pdev);
11581 pci_restore_state(pdev);
11582 pci_save_state(pdev);
11583 pci_wake_from_d3(pdev, false);
11584
11585 reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
11586 if (reg == 0)
11587 result = PCI_ERS_RESULT_RECOVERED;
11588 else
11589 result = PCI_ERS_RESULT_DISCONNECT;
11590 }
11591
11592 err = pci_cleanup_aer_uncorrect_error_status(pdev);
11593 if (err) {
11594 dev_info(&pdev->dev,
11595 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
11596 err);
11597 /* non-fatal, continue */
11598 }
11599
11600 return result;
11601}
11602
11603/**
11604 * i40e_pci_error_resume - restart operations after PCI error recovery
11605 * @pdev: PCI device information struct
11606 *
11607 * Called to allow the driver to bring things back up after PCI error
11608 * and/or reset recovery has finished.
11609 **/
11610static void i40e_pci_error_resume(struct pci_dev *pdev)
11611{
11612 struct i40e_pf *pf = pci_get_drvdata(pdev);
11613
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011614 dev_dbg(&pdev->dev, "%s\n", __func__);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011615 if (test_bit(__I40E_SUSPENDED, &pf->state))
11616 return;
11617
11618 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011619 i40e_handle_reset_warning(pf);
Vasily Averin4c4935a2015-07-08 15:04:26 +030011620 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011621}
11622
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011623/**
11624 * i40e_shutdown - PCI callback for shutting down
11625 * @pdev: PCI device information struct
11626 **/
11627static void i40e_shutdown(struct pci_dev *pdev)
11628{
11629 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011630 struct i40e_hw *hw = &pf->hw;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011631
11632 set_bit(__I40E_SUSPENDED, &pf->state);
11633 set_bit(__I40E_DOWN, &pf->state);
11634 rtnl_lock();
11635 i40e_prep_for_reset(pf);
11636 rtnl_unlock();
11637
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011638 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11639 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11640
Catherine Sullivan02b42492015-07-10 19:35:59 -040011641 del_timer_sync(&pf->service_timer);
11642 cancel_work_sync(&pf->service_task);
11643 i40e_fdir_teardown(pf);
11644
11645 rtnl_lock();
11646 i40e_prep_for_reset(pf);
11647 rtnl_unlock();
11648
11649 wr32(hw, I40E_PFPM_APM,
11650 (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11651 wr32(hw, I40E_PFPM_WUFC,
11652 (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11653
Shannon Nelsone1477582015-02-21 06:44:33 +000011654 i40e_clear_interrupt_scheme(pf);
11655
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011656 if (system_state == SYSTEM_POWER_OFF) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011657 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011658 pci_set_power_state(pdev, PCI_D3hot);
11659 }
11660}
11661
11662#ifdef CONFIG_PM
11663/**
11664 * i40e_suspend - PCI callback for moving to D3
11665 * @pdev: PCI device information struct
11666 **/
11667static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
11668{
11669 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011670 struct i40e_hw *hw = &pf->hw;
Greg Rose059ff692016-05-16 10:26:38 -070011671 int retval = 0;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011672
11673 set_bit(__I40E_SUSPENDED, &pf->state);
11674 set_bit(__I40E_DOWN, &pf->state);
Mitch Williams3932dbf2015-03-31 00:45:04 -070011675
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011676 rtnl_lock();
11677 i40e_prep_for_reset(pf);
11678 rtnl_unlock();
11679
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011680 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
11681 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
11682
Greg Roseb33d3b72016-05-16 10:26:37 -070011683 i40e_stop_misc_vector(pf);
11684
Greg Rose059ff692016-05-16 10:26:38 -070011685 retval = pci_save_state(pdev);
11686 if (retval)
11687 return retval;
11688
Shannon Nelson8e2773a2013-11-28 06:39:22 +000011689 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011690 pci_set_power_state(pdev, PCI_D3hot);
11691
Greg Rose059ff692016-05-16 10:26:38 -070011692 return retval;
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011693}
11694
11695/**
11696 * i40e_resume - PCI callback for waking up from D3
11697 * @pdev: PCI device information struct
11698 **/
11699static int i40e_resume(struct pci_dev *pdev)
11700{
11701 struct i40e_pf *pf = pci_get_drvdata(pdev);
11702 u32 err;
11703
11704 pci_set_power_state(pdev, PCI_D0);
11705 pci_restore_state(pdev);
11706 /* pci_restore_state() clears dev->state_saves, so
11707 * call pci_save_state() again to restore it.
11708 */
11709 pci_save_state(pdev);
11710
11711 err = pci_enable_device_mem(pdev);
11712 if (err) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -040011713 dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011714 return err;
11715 }
11716 pci_set_master(pdev);
11717
11718 /* no wakeup events while running */
11719 pci_wake_from_d3(pdev, false);
11720
11721 /* handling the reset will rebuild the device state */
11722 if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
11723 clear_bit(__I40E_DOWN, &pf->state);
11724 rtnl_lock();
11725 i40e_reset_and_rebuild(pf, false);
11726 rtnl_unlock();
11727 }
11728
11729 return 0;
11730}
11731
11732#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011733static const struct pci_error_handlers i40e_err_handler = {
11734 .error_detected = i40e_pci_error_detected,
11735 .slot_reset = i40e_pci_error_slot_reset,
11736 .resume = i40e_pci_error_resume,
11737};
11738
11739static struct pci_driver i40e_driver = {
11740 .name = i40e_driver_name,
11741 .id_table = i40e_pci_tbl,
11742 .probe = i40e_probe,
11743 .remove = i40e_remove,
Shannon Nelson9007bcc2013-11-26 10:49:23 +000011744#ifdef CONFIG_PM
11745 .suspend = i40e_suspend,
11746 .resume = i40e_resume,
11747#endif
11748 .shutdown = i40e_shutdown,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011749 .err_handler = &i40e_err_handler,
11750 .sriov_configure = i40e_pci_sriov_configure,
11751};
11752
11753/**
11754 * i40e_init_module - Driver registration routine
11755 *
11756 * i40e_init_module is the first routine called when the driver is
11757 * loaded. All it does is register with the PCI subsystem.
11758 **/
11759static int __init i40e_init_module(void)
11760{
11761 pr_info("%s: %s - version %s\n", i40e_driver_name,
11762 i40e_driver_string, i40e_driver_version_str);
11763 pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
Greg Rose96664482015-02-06 08:52:13 +000011764
Jesse Brandeburg2803b162015-12-22 14:25:08 -080011765 /* we will see if single thread per module is enough for now,
11766 * it can't be any worse than using the system workqueue which
11767 * was already single threaded
11768 */
Jacob Keller6992a6c2016-08-04 11:37:01 -070011769 i40e_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1,
11770 i40e_driver_name);
Jesse Brandeburg2803b162015-12-22 14:25:08 -080011771 if (!i40e_wq) {
11772 pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
11773 return -ENOMEM;
11774 }
11775
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011776 i40e_dbg_init();
11777 return pci_register_driver(&i40e_driver);
11778}
11779module_init(i40e_init_module);
11780
11781/**
11782 * i40e_exit_module - Driver exit cleanup routine
11783 *
11784 * i40e_exit_module is called just before the driver is removed
11785 * from memory.
11786 **/
11787static void __exit i40e_exit_module(void)
11788{
11789 pci_unregister_driver(&i40e_driver);
Jesse Brandeburg2803b162015-12-22 14:25:08 -080011790 destroy_workqueue(i40e_wq);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011791 i40e_dbg_exit();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000011792}
11793module_exit(i40e_exit_module);