blob: 44789c2e3f50a78a3303cdb316396dd72a5a9285 [file] [log] [blame]
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Greg Rosedc641b72013-12-18 13:45:51 +00004 * Copyright(c) 2013 - 2014 Intel Corporation.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27/* Local includes */
28#include "i40e.h"
Shannon Nelson4eb3f762014-03-06 08:59:58 +000029#include "i40e_diag.h"
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +000030#ifdef CONFIG_I40E_VXLAN
31#include <net/vxlan.h>
32#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000033
34const char i40e_driver_name[] = "i40e";
35static const char i40e_driver_string[] =
36 "Intel(R) Ethernet Connection XL710 Network Driver";
37
38#define DRV_KERN "-k"
39
40#define DRV_VERSION_MAJOR 0
Catherine Sullivane454d6b2014-04-23 04:50:17 +000041#define DRV_VERSION_MINOR 4
Catherine Sullivan7974d5e2014-06-03 23:50:25 +000042#define DRV_VERSION_BUILD 13
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000043#define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
44 __stringify(DRV_VERSION_MINOR) "." \
45 __stringify(DRV_VERSION_BUILD) DRV_KERN
46const char i40e_driver_version_str[] = DRV_VERSION;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -080047static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000048
49/* a bit of forward declarations */
50static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
51static void i40e_handle_reset_warning(struct i40e_pf *pf);
52static int i40e_add_vsi(struct i40e_vsi *vsi);
53static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +000054static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000055static int i40e_setup_misc_vector(struct i40e_pf *pf);
56static void i40e_determine_queue_usage(struct i40e_pf *pf);
57static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -080058static void i40e_fdir_sb_setup(struct i40e_pf *pf);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -080059static int i40e_veb_get_bw_info(struct i40e_veb *veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000060
61/* i40e_pci_tbl - PCI Device ID Table
62 *
63 * Last entry must be all 0s
64 *
65 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
66 * Class, Class Mask, private data (not used) }
67 */
68static DEFINE_PCI_DEVICE_TABLE(i40e_pci_tbl) = {
Shannon Nelsonab600852014-01-17 15:36:39 -080069 {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080070 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
71 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_A), 0},
72 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
73 {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
Shannon Nelsonab600852014-01-17 15:36:39 -080074 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
75 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
76 {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
Jesse Brandeburg41c445f2013-09-11 08:39:46 +000077 /* required last entry */
78 {0, }
79};
80MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
81
82#define I40E_MAX_VF_COUNT 128
83static int debug = -1;
84module_param(debug, int, 0);
85MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
86
87MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
88MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
89MODULE_LICENSE("GPL");
90MODULE_VERSION(DRV_VERSION);
91
92/**
93 * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
94 * @hw: pointer to the HW structure
95 * @mem: ptr to mem struct to fill out
96 * @size: size of memory requested
97 * @alignment: what to align the allocation to
98 **/
99int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
100 u64 size, u32 alignment)
101{
102 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
103
104 mem->size = ALIGN(size, alignment);
105 mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
106 &mem->pa, GFP_KERNEL);
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000107 if (!mem->va)
108 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000109
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000110 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000111}
112
113/**
114 * i40e_free_dma_mem_d - OS specific memory free for shared code
115 * @hw: pointer to the HW structure
116 * @mem: ptr to mem struct to free
117 **/
118int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
119{
120 struct i40e_pf *pf = (struct i40e_pf *)hw->back;
121
122 dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
123 mem->va = NULL;
124 mem->pa = 0;
125 mem->size = 0;
126
127 return 0;
128}
129
130/**
131 * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
132 * @hw: pointer to the HW structure
133 * @mem: ptr to mem struct to fill out
134 * @size: size of memory requested
135 **/
136int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
137 u32 size)
138{
139 mem->size = size;
140 mem->va = kzalloc(size, GFP_KERNEL);
141
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000142 if (!mem->va)
143 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000144
Jesse Brandeburg93bc73b2013-09-13 08:23:18 +0000145 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000146}
147
148/**
149 * i40e_free_virt_mem_d - OS specific memory free for shared code
150 * @hw: pointer to the HW structure
151 * @mem: ptr to mem struct to free
152 **/
153int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
154{
155 /* it's ok to kfree a NULL pointer */
156 kfree(mem->va);
157 mem->va = NULL;
158 mem->size = 0;
159
160 return 0;
161}
162
163/**
164 * i40e_get_lump - find a lump of free generic resource
165 * @pf: board private structure
166 * @pile: the pile of resource to search
167 * @needed: the number of items needed
168 * @id: an owner id to stick on the items assigned
169 *
170 * Returns the base item index of the lump, or negative for error
171 *
172 * The search_hint trick and lack of advanced fit-finding only work
173 * because we're highly likely to have all the same size lump requests.
174 * Linear search time and any fragmentation should be minimal.
175 **/
176static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
177 u16 needed, u16 id)
178{
179 int ret = -ENOMEM;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000180 int i, j;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000181
182 if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
183 dev_info(&pf->pdev->dev,
184 "param err: pile=%p needed=%d id=0x%04x\n",
185 pile, needed, id);
186 return -EINVAL;
187 }
188
189 /* start the linear search with an imperfect hint */
190 i = pile->search_hint;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000191 while (i < pile->num_entries) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000192 /* skip already allocated entries */
193 if (pile->list[i] & I40E_PILE_VALID_BIT) {
194 i++;
195 continue;
196 }
197
198 /* do we have enough in this lump? */
199 for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
200 if (pile->list[i+j] & I40E_PILE_VALID_BIT)
201 break;
202 }
203
204 if (j == needed) {
205 /* there was enough, so assign it to the requestor */
206 for (j = 0; j < needed; j++)
207 pile->list[i+j] = id | I40E_PILE_VALID_BIT;
208 ret = i;
209 pile->search_hint = i + j;
Jesse Brandeburgddf434a2013-09-13 08:23:19 +0000210 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000211 } else {
212 /* not enough, so skip over it and continue looking */
213 i += j;
214 }
215 }
216
217 return ret;
218}
219
220/**
221 * i40e_put_lump - return a lump of generic resource
222 * @pile: the pile of resource to search
223 * @index: the base item index
224 * @id: the owner id of the items assigned
225 *
226 * Returns the count of items in the lump
227 **/
228static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
229{
230 int valid_id = (id | I40E_PILE_VALID_BIT);
231 int count = 0;
232 int i;
233
234 if (!pile || index >= pile->num_entries)
235 return -EINVAL;
236
237 for (i = index;
238 i < pile->num_entries && pile->list[i] == valid_id;
239 i++) {
240 pile->list[i] = 0;
241 count++;
242 }
243
244 if (count && index < pile->search_hint)
245 pile->search_hint = index;
246
247 return count;
248}
249
250/**
251 * i40e_service_event_schedule - Schedule the service task to wake up
252 * @pf: board private structure
253 *
254 * If not already scheduled, this puts the task into the work queue
255 **/
256static void i40e_service_event_schedule(struct i40e_pf *pf)
257{
258 if (!test_bit(__I40E_DOWN, &pf->state) &&
259 !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) &&
260 !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
261 schedule_work(&pf->service_task);
262}
263
264/**
265 * i40e_tx_timeout - Respond to a Tx Hang
266 * @netdev: network interface device structure
267 *
268 * If any port has noticed a Tx timeout, it is likely that the whole
269 * device is munged, not just the one netdev port, so go for the full
270 * reset.
271 **/
272static void i40e_tx_timeout(struct net_device *netdev)
273{
274 struct i40e_netdev_priv *np = netdev_priv(netdev);
275 struct i40e_vsi *vsi = np->vsi;
276 struct i40e_pf *pf = vsi->back;
277
278 pf->tx_timeout_count++;
279
280 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
281 pf->tx_timeout_recovery_level = 0;
282 pf->tx_timeout_last_recovery = jiffies;
283 netdev_info(netdev, "tx_timeout recovery level %d\n",
284 pf->tx_timeout_recovery_level);
285
286 switch (pf->tx_timeout_recovery_level) {
287 case 0:
288 /* disable and re-enable queues for the VSI */
289 if (in_interrupt()) {
290 set_bit(__I40E_REINIT_REQUESTED, &pf->state);
291 set_bit(__I40E_REINIT_REQUESTED, &vsi->state);
292 } else {
293 i40e_vsi_reinit_locked(vsi);
294 }
295 break;
296 case 1:
297 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
298 break;
299 case 2:
300 set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
301 break;
302 case 3:
303 set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
304 break;
305 default:
306 netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
Neerav Parikhb5d06f02014-06-03 23:50:17 +0000307 set_bit(__I40E_DOWN_REQUESTED, &pf->state);
308 set_bit(__I40E_DOWN_REQUESTED, &vsi->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000309 break;
310 }
311 i40e_service_event_schedule(pf);
312 pf->tx_timeout_recovery_level++;
313}
314
315/**
316 * i40e_release_rx_desc - Store the new tail and head values
317 * @rx_ring: ring to bump
318 * @val: new head index
319 **/
320static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val)
321{
322 rx_ring->next_to_use = val;
323
324 /* Force memory writes to complete before letting h/w
325 * know there are new descriptors to fetch. (Only
326 * applicable for weak-ordered memory model archs,
327 * such as IA-64).
328 */
329 wmb();
330 writel(val, rx_ring->tail);
331}
332
333/**
334 * i40e_get_vsi_stats_struct - Get System Network Statistics
335 * @vsi: the VSI we care about
336 *
337 * Returns the address of the device statistics structure.
338 * The statistics are actually updated from the service task.
339 **/
340struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
341{
342 return &vsi->net_stats;
343}
344
345/**
346 * i40e_get_netdev_stats_struct - Get statistics for netdev interface
347 * @netdev: network interface device structure
348 *
349 * Returns the address of the device statistics structure.
350 * The statistics are actually updated from the service task.
351 **/
352static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
353 struct net_device *netdev,
Alexander Duyck980e9b12013-09-28 06:01:03 +0000354 struct rtnl_link_stats64 *stats)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000355{
356 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000357 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000358 struct i40e_vsi *vsi = np->vsi;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000359 struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
360 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000361
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +0000362 if (test_bit(__I40E_DOWN, &vsi->state))
363 return stats;
364
Jesse Brandeburg3c325ce2013-12-14 03:26:45 -0800365 if (!vsi->tx_rings)
366 return stats;
367
Alexander Duyck980e9b12013-09-28 06:01:03 +0000368 rcu_read_lock();
369 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000370 u64 bytes, packets;
371 unsigned int start;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000372
Alexander Duyck980e9b12013-09-28 06:01:03 +0000373 tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
374 if (!tx_ring)
375 continue;
376
377 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700378 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000379 packets = tx_ring->stats.packets;
380 bytes = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700381 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000382
383 stats->tx_packets += packets;
384 stats->tx_bytes += bytes;
385 rx_ring = &tx_ring[1];
386
387 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700388 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000389 packets = rx_ring->stats.packets;
390 bytes = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700391 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000392
393 stats->rx_packets += packets;
394 stats->rx_bytes += bytes;
395 }
396 rcu_read_unlock();
397
Akeem G Abodunrina5282f42014-05-10 04:49:03 +0000398 /* following stats updated by i40e_watchdog_subtask() */
Alexander Duyck980e9b12013-09-28 06:01:03 +0000399 stats->multicast = vsi_stats->multicast;
400 stats->tx_errors = vsi_stats->tx_errors;
401 stats->tx_dropped = vsi_stats->tx_dropped;
402 stats->rx_errors = vsi_stats->rx_errors;
403 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
404 stats->rx_length_errors = vsi_stats->rx_length_errors;
405
406 return stats;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000407}
408
409/**
410 * i40e_vsi_reset_stats - Resets all stats of the given vsi
411 * @vsi: the VSI to have its stats reset
412 **/
413void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
414{
415 struct rtnl_link_stats64 *ns;
416 int i;
417
418 if (!vsi)
419 return;
420
421 ns = i40e_get_vsi_stats_struct(vsi);
422 memset(ns, 0, sizeof(*ns));
423 memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
424 memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
425 memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
Greg Rose8e9dca52013-12-18 13:45:53 +0000426 if (vsi->rx_rings && vsi->rx_rings[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000427 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e15b2013-09-28 06:00:58 +0000428 memset(&vsi->rx_rings[i]->stats, 0 ,
429 sizeof(vsi->rx_rings[i]->stats));
430 memset(&vsi->rx_rings[i]->rx_stats, 0 ,
431 sizeof(vsi->rx_rings[i]->rx_stats));
432 memset(&vsi->tx_rings[i]->stats, 0 ,
433 sizeof(vsi->tx_rings[i]->stats));
434 memset(&vsi->tx_rings[i]->tx_stats, 0,
435 sizeof(vsi->tx_rings[i]->tx_stats));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000436 }
Greg Rose8e9dca52013-12-18 13:45:53 +0000437 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000438 vsi->stat_offsets_loaded = false;
439}
440
441/**
442 * i40e_pf_reset_stats - Reset all of the stats for the given pf
443 * @pf: the PF to be reset
444 **/
445void i40e_pf_reset_stats(struct i40e_pf *pf)
446{
Shannon Nelsone91fdf72014-06-03 23:50:18 +0000447 int i;
448
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000449 memset(&pf->stats, 0, sizeof(pf->stats));
450 memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
451 pf->stat_offsets_loaded = false;
Shannon Nelsone91fdf72014-06-03 23:50:18 +0000452
453 for (i = 0; i < I40E_MAX_VEB; i++) {
454 if (pf->veb[i]) {
455 memset(&pf->veb[i]->stats, 0,
456 sizeof(pf->veb[i]->stats));
457 memset(&pf->veb[i]->stats_offsets, 0,
458 sizeof(pf->veb[i]->stats_offsets));
459 pf->veb[i]->stat_offsets_loaded = false;
460 }
461 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000462}
463
464/**
465 * i40e_stat_update48 - read and update a 48 bit stat from the chip
466 * @hw: ptr to the hardware info
467 * @hireg: the high 32 bit reg to read
468 * @loreg: the low 32 bit reg to read
469 * @offset_loaded: has the initial offset been loaded yet
470 * @offset: ptr to current offset value
471 * @stat: ptr to the stat
472 *
473 * Since the device stats are not reset at PFReset, they likely will not
474 * be zeroed when the driver starts. We'll save the first values read
475 * and use them as offsets to be subtracted from the raw values in order
476 * to report stats that count from zero. In the process, we also manage
477 * the potential roll-over.
478 **/
479static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
480 bool offset_loaded, u64 *offset, u64 *stat)
481{
482 u64 new_data;
483
Shannon Nelsonab600852014-01-17 15:36:39 -0800484 if (hw->device_id == I40E_DEV_ID_QEMU) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000485 new_data = rd32(hw, loreg);
486 new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
487 } else {
488 new_data = rd64(hw, loreg);
489 }
490 if (!offset_loaded)
491 *offset = new_data;
492 if (likely(new_data >= *offset))
493 *stat = new_data - *offset;
494 else
495 *stat = (new_data + ((u64)1 << 48)) - *offset;
496 *stat &= 0xFFFFFFFFFFFFULL;
497}
498
499/**
500 * i40e_stat_update32 - read and update a 32 bit stat from the chip
501 * @hw: ptr to the hardware info
502 * @reg: the hw reg to read
503 * @offset_loaded: has the initial offset been loaded yet
504 * @offset: ptr to current offset value
505 * @stat: ptr to the stat
506 **/
507static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
508 bool offset_loaded, u64 *offset, u64 *stat)
509{
510 u32 new_data;
511
512 new_data = rd32(hw, reg);
513 if (!offset_loaded)
514 *offset = new_data;
515 if (likely(new_data >= *offset))
516 *stat = (u32)(new_data - *offset);
517 else
518 *stat = (u32)((new_data + ((u64)1 << 32)) - *offset);
519}
520
521/**
522 * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
523 * @vsi: the VSI to be updated
524 **/
525void i40e_update_eth_stats(struct i40e_vsi *vsi)
526{
527 int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
528 struct i40e_pf *pf = vsi->back;
529 struct i40e_hw *hw = &pf->hw;
530 struct i40e_eth_stats *oes;
531 struct i40e_eth_stats *es; /* device's eth stats */
532
533 es = &vsi->eth_stats;
534 oes = &vsi->eth_stats_offsets;
535
536 /* Gather up the stats that the hw collects */
537 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
538 vsi->stat_offsets_loaded,
539 &oes->tx_errors, &es->tx_errors);
540 i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
541 vsi->stat_offsets_loaded,
542 &oes->rx_discards, &es->rx_discards);
Shannon Nelson41a9e552014-04-23 04:50:20 +0000543 i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
544 vsi->stat_offsets_loaded,
545 &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
546 i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
547 vsi->stat_offsets_loaded,
548 &oes->tx_errors, &es->tx_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000549
550 i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
551 I40E_GLV_GORCL(stat_idx),
552 vsi->stat_offsets_loaded,
553 &oes->rx_bytes, &es->rx_bytes);
554 i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
555 I40E_GLV_UPRCL(stat_idx),
556 vsi->stat_offsets_loaded,
557 &oes->rx_unicast, &es->rx_unicast);
558 i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
559 I40E_GLV_MPRCL(stat_idx),
560 vsi->stat_offsets_loaded,
561 &oes->rx_multicast, &es->rx_multicast);
562 i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
563 I40E_GLV_BPRCL(stat_idx),
564 vsi->stat_offsets_loaded,
565 &oes->rx_broadcast, &es->rx_broadcast);
566
567 i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
568 I40E_GLV_GOTCL(stat_idx),
569 vsi->stat_offsets_loaded,
570 &oes->tx_bytes, &es->tx_bytes);
571 i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
572 I40E_GLV_UPTCL(stat_idx),
573 vsi->stat_offsets_loaded,
574 &oes->tx_unicast, &es->tx_unicast);
575 i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
576 I40E_GLV_MPTCL(stat_idx),
577 vsi->stat_offsets_loaded,
578 &oes->tx_multicast, &es->tx_multicast);
579 i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
580 I40E_GLV_BPTCL(stat_idx),
581 vsi->stat_offsets_loaded,
582 &oes->tx_broadcast, &es->tx_broadcast);
583 vsi->stat_offsets_loaded = true;
584}
585
586/**
587 * i40e_update_veb_stats - Update Switch component statistics
588 * @veb: the VEB being updated
589 **/
590static void i40e_update_veb_stats(struct i40e_veb *veb)
591{
592 struct i40e_pf *pf = veb->pf;
593 struct i40e_hw *hw = &pf->hw;
594 struct i40e_eth_stats *oes;
595 struct i40e_eth_stats *es; /* device's eth stats */
596 int idx = 0;
597
598 idx = veb->stats_idx;
599 es = &veb->stats;
600 oes = &veb->stats_offsets;
601
602 /* Gather up the stats that the hw collects */
603 i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
604 veb->stat_offsets_loaded,
605 &oes->tx_discards, &es->tx_discards);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000606 if (hw->revision_id > 0)
607 i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
608 veb->stat_offsets_loaded,
609 &oes->rx_unknown_protocol,
610 &es->rx_unknown_protocol);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000611 i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
612 veb->stat_offsets_loaded,
613 &oes->rx_bytes, &es->rx_bytes);
614 i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
615 veb->stat_offsets_loaded,
616 &oes->rx_unicast, &es->rx_unicast);
617 i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
618 veb->stat_offsets_loaded,
619 &oes->rx_multicast, &es->rx_multicast);
620 i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
621 veb->stat_offsets_loaded,
622 &oes->rx_broadcast, &es->rx_broadcast);
623
624 i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
625 veb->stat_offsets_loaded,
626 &oes->tx_bytes, &es->tx_bytes);
627 i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
628 veb->stat_offsets_loaded,
629 &oes->tx_unicast, &es->tx_unicast);
630 i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
631 veb->stat_offsets_loaded,
632 &oes->tx_multicast, &es->tx_multicast);
633 i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
634 veb->stat_offsets_loaded,
635 &oes->tx_broadcast, &es->tx_broadcast);
636 veb->stat_offsets_loaded = true;
637}
638
639/**
640 * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode
641 * @pf: the corresponding PF
642 *
643 * Update the Rx XOFF counter (PAUSE frames) in link flow control mode
644 **/
645static void i40e_update_link_xoff_rx(struct i40e_pf *pf)
646{
647 struct i40e_hw_port_stats *osd = &pf->stats_offsets;
648 struct i40e_hw_port_stats *nsd = &pf->stats;
649 struct i40e_hw *hw = &pf->hw;
650 u64 xoff = 0;
651 u16 i, v;
652
653 if ((hw->fc.current_mode != I40E_FC_FULL) &&
654 (hw->fc.current_mode != I40E_FC_RX_PAUSE))
655 return;
656
657 xoff = nsd->link_xoff_rx;
658 i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
659 pf->stat_offsets_loaded,
660 &osd->link_xoff_rx, &nsd->link_xoff_rx);
661
662 /* No new LFC xoff rx */
663 if (!(nsd->link_xoff_rx - xoff))
664 return;
665
666 /* Clear the __I40E_HANG_CHECK_ARMED bit for all Tx rings */
Mitch Williams505682c2014-05-20 08:01:37 +0000667 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000668 struct i40e_vsi *vsi = pf->vsi[v];
669
Mitch Williamsddfda802014-05-10 04:49:10 +0000670 if (!vsi || !vsi->tx_rings[0])
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000671 continue;
672
673 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e15b2013-09-28 06:00:58 +0000674 struct i40e_ring *ring = vsi->tx_rings[i];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000675 clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state);
676 }
677 }
678}
679
680/**
681 * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode
682 * @pf: the corresponding PF
683 *
684 * Update the Rx XOFF counter (PAUSE frames) in PFC mode
685 **/
686static void i40e_update_prio_xoff_rx(struct i40e_pf *pf)
687{
688 struct i40e_hw_port_stats *osd = &pf->stats_offsets;
689 struct i40e_hw_port_stats *nsd = &pf->stats;
690 bool xoff[I40E_MAX_TRAFFIC_CLASS] = {false};
691 struct i40e_dcbx_config *dcb_cfg;
692 struct i40e_hw *hw = &pf->hw;
693 u16 i, v;
694 u8 tc;
695
696 dcb_cfg = &hw->local_dcbx_config;
697
698 /* See if DCB enabled with PFC TC */
699 if (!(pf->flags & I40E_FLAG_DCB_ENABLED) ||
700 !(dcb_cfg->pfc.pfcenable)) {
701 i40e_update_link_xoff_rx(pf);
702 return;
703 }
704
705 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
706 u64 prio_xoff = nsd->priority_xoff_rx[i];
707 i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
708 pf->stat_offsets_loaded,
709 &osd->priority_xoff_rx[i],
710 &nsd->priority_xoff_rx[i]);
711
712 /* No new PFC xoff rx */
713 if (!(nsd->priority_xoff_rx[i] - prio_xoff))
714 continue;
715 /* Get the TC for given priority */
716 tc = dcb_cfg->etscfg.prioritytable[i];
717 xoff[tc] = true;
718 }
719
720 /* Clear the __I40E_HANG_CHECK_ARMED bit for Tx rings */
Mitch Williams505682c2014-05-20 08:01:37 +0000721 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000722 struct i40e_vsi *vsi = pf->vsi[v];
723
Mitch Williamsddfda802014-05-10 04:49:10 +0000724 if (!vsi || !vsi->tx_rings[0])
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000725 continue;
726
727 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e15b2013-09-28 06:00:58 +0000728 struct i40e_ring *ring = vsi->tx_rings[i];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000729
730 tc = ring->dcb_tc;
731 if (xoff[tc])
732 clear_bit(__I40E_HANG_CHECK_ARMED,
733 &ring->state);
734 }
735 }
736}
737
738/**
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000739 * i40e_update_vsi_stats - Update the vsi statistics counters.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000740 * @vsi: the VSI to be updated
741 *
742 * There are a few instances where we store the same stat in a
743 * couple of different structs. This is partly because we have
744 * the netdev stats that need to be filled out, which is slightly
745 * different from the "eth_stats" defined by the chip and used in
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000746 * VF communications. We sort it out here.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000747 **/
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000748static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000749{
750 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000751 struct rtnl_link_stats64 *ons;
752 struct rtnl_link_stats64 *ns; /* netdev stats */
753 struct i40e_eth_stats *oes;
754 struct i40e_eth_stats *es; /* device's eth stats */
755 u32 tx_restart, tx_busy;
756 u32 rx_page, rx_buf;
757 u64 rx_p, rx_b;
758 u64 tx_p, tx_b;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000759 u16 q;
760
761 if (test_bit(__I40E_DOWN, &vsi->state) ||
762 test_bit(__I40E_CONFIG_BUSY, &pf->state))
763 return;
764
765 ns = i40e_get_vsi_stats_struct(vsi);
766 ons = &vsi->net_stats_offsets;
767 es = &vsi->eth_stats;
768 oes = &vsi->eth_stats_offsets;
769
770 /* Gather up the netdev and vsi stats that the driver collects
771 * on the fly during packet processing
772 */
773 rx_b = rx_p = 0;
774 tx_b = tx_p = 0;
775 tx_restart = tx_busy = 0;
776 rx_page = 0;
777 rx_buf = 0;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000778 rcu_read_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000779 for (q = 0; q < vsi->num_queue_pairs; q++) {
780 struct i40e_ring *p;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000781 u64 bytes, packets;
782 unsigned int start;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000783
Alexander Duyck980e9b12013-09-28 06:01:03 +0000784 /* locate Tx ring */
785 p = ACCESS_ONCE(vsi->tx_rings[q]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000786
Alexander Duyck980e9b12013-09-28 06:01:03 +0000787 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700788 start = u64_stats_fetch_begin_irq(&p->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000789 packets = p->stats.packets;
790 bytes = p->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700791 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000792 tx_b += bytes;
793 tx_p += packets;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000794 tx_restart += p->tx_stats.restart_queue;
795 tx_busy += p->tx_stats.tx_busy;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000796
797 /* Rx queue is part of the same block as Tx queue */
798 p = &p[1];
799 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700800 start = u64_stats_fetch_begin_irq(&p->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000801 packets = p->stats.packets;
802 bytes = p->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700803 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
Alexander Duyck980e9b12013-09-28 06:01:03 +0000804 rx_b += bytes;
805 rx_p += packets;
Mitch Williams420136c2013-12-18 13:45:59 +0000806 rx_buf += p->rx_stats.alloc_buff_failed;
807 rx_page += p->rx_stats.alloc_page_failed;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000808 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000809 rcu_read_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000810 vsi->tx_restart = tx_restart;
811 vsi->tx_busy = tx_busy;
812 vsi->rx_page_failed = rx_page;
813 vsi->rx_buf_failed = rx_buf;
814
815 ns->rx_packets = rx_p;
816 ns->rx_bytes = rx_b;
817 ns->tx_packets = tx_p;
818 ns->tx_bytes = tx_b;
819
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000820 /* update netdev stats from eth stats */
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000821 i40e_update_eth_stats(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000822 ons->tx_errors = oes->tx_errors;
823 ns->tx_errors = es->tx_errors;
824 ons->multicast = oes->rx_multicast;
825 ns->multicast = es->rx_multicast;
Shannon Nelson41a9e552014-04-23 04:50:20 +0000826 ons->rx_dropped = oes->rx_discards;
827 ns->rx_dropped = es->rx_discards;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000828 ons->tx_dropped = oes->tx_discards;
829 ns->tx_dropped = es->tx_discards;
830
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000831 /* pull in a couple PF stats if this is the main vsi */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000832 if (vsi == pf->vsi[pf->lan_vsi]) {
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000833 ns->rx_crc_errors = pf->stats.crc_errors;
834 ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
835 ns->rx_length_errors = pf->stats.rx_length_errors;
836 }
837}
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000838
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000839/**
840 * i40e_update_pf_stats - Update the pf statistics counters.
841 * @pf: the PF to be updated
842 **/
843static void i40e_update_pf_stats(struct i40e_pf *pf)
844{
845 struct i40e_hw_port_stats *osd = &pf->stats_offsets;
846 struct i40e_hw_port_stats *nsd = &pf->stats;
847 struct i40e_hw *hw = &pf->hw;
848 u32 val;
849 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000850
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000851 i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
852 I40E_GLPRT_GORCL(hw->port),
853 pf->stat_offsets_loaded,
854 &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
855 i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
856 I40E_GLPRT_GOTCL(hw->port),
857 pf->stat_offsets_loaded,
858 &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
859 i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
860 pf->stat_offsets_loaded,
861 &osd->eth.rx_discards,
862 &nsd->eth.rx_discards);
863 i40e_stat_update32(hw, I40E_GLPRT_TDPC(hw->port),
864 pf->stat_offsets_loaded,
865 &osd->eth.tx_discards,
866 &nsd->eth.tx_discards);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000867
Shannon Nelson532d2832014-04-23 04:50:09 +0000868 i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
869 I40E_GLPRT_UPRCL(hw->port),
870 pf->stat_offsets_loaded,
871 &osd->eth.rx_unicast,
872 &nsd->eth.rx_unicast);
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000873 i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
874 I40E_GLPRT_MPRCL(hw->port),
875 pf->stat_offsets_loaded,
876 &osd->eth.rx_multicast,
877 &nsd->eth.rx_multicast);
Shannon Nelson532d2832014-04-23 04:50:09 +0000878 i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
879 I40E_GLPRT_BPRCL(hw->port),
880 pf->stat_offsets_loaded,
881 &osd->eth.rx_broadcast,
882 &nsd->eth.rx_broadcast);
883 i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
884 I40E_GLPRT_UPTCL(hw->port),
885 pf->stat_offsets_loaded,
886 &osd->eth.tx_unicast,
887 &nsd->eth.tx_unicast);
888 i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
889 I40E_GLPRT_MPTCL(hw->port),
890 pf->stat_offsets_loaded,
891 &osd->eth.tx_multicast,
892 &nsd->eth.tx_multicast);
893 i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
894 I40E_GLPRT_BPTCL(hw->port),
895 pf->stat_offsets_loaded,
896 &osd->eth.tx_broadcast,
897 &nsd->eth.tx_broadcast);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000898
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000899 i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
900 pf->stat_offsets_loaded,
901 &osd->tx_dropped_link_down,
902 &nsd->tx_dropped_link_down);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000903
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000904 i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
905 pf->stat_offsets_loaded,
906 &osd->crc_errors, &nsd->crc_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000907
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000908 i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
909 pf->stat_offsets_loaded,
910 &osd->illegal_bytes, &nsd->illegal_bytes);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000911
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000912 i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
913 pf->stat_offsets_loaded,
914 &osd->mac_local_faults,
915 &nsd->mac_local_faults);
916 i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
917 pf->stat_offsets_loaded,
918 &osd->mac_remote_faults,
919 &nsd->mac_remote_faults);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000920
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000921 i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
922 pf->stat_offsets_loaded,
923 &osd->rx_length_errors,
924 &nsd->rx_length_errors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000925
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000926 i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
927 pf->stat_offsets_loaded,
928 &osd->link_xon_rx, &nsd->link_xon_rx);
929 i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
930 pf->stat_offsets_loaded,
931 &osd->link_xon_tx, &nsd->link_xon_tx);
932 i40e_update_prio_xoff_rx(pf); /* handles I40E_GLPRT_LXOFFRXC */
933 i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
934 pf->stat_offsets_loaded,
935 &osd->link_xoff_tx, &nsd->link_xoff_tx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000936
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000937 for (i = 0; i < 8; i++) {
938 i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000939 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000940 &osd->priority_xon_rx[i],
941 &nsd->priority_xon_rx[i]);
942 i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000943 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000944 &osd->priority_xon_tx[i],
945 &nsd->priority_xon_tx[i]);
946 i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000947 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000948 &osd->priority_xoff_tx[i],
949 &nsd->priority_xoff_tx[i]);
950 i40e_stat_update32(hw,
951 I40E_GLPRT_RXON2OFFCNT(hw->port, i),
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000952 pf->stat_offsets_loaded,
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000953 &osd->priority_xon_2_xoff[i],
954 &nsd->priority_xon_2_xoff[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000955 }
956
Shannon Nelson7812fdd2014-04-23 04:50:18 +0000957 i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
958 I40E_GLPRT_PRC64L(hw->port),
959 pf->stat_offsets_loaded,
960 &osd->rx_size_64, &nsd->rx_size_64);
961 i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
962 I40E_GLPRT_PRC127L(hw->port),
963 pf->stat_offsets_loaded,
964 &osd->rx_size_127, &nsd->rx_size_127);
965 i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
966 I40E_GLPRT_PRC255L(hw->port),
967 pf->stat_offsets_loaded,
968 &osd->rx_size_255, &nsd->rx_size_255);
969 i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
970 I40E_GLPRT_PRC511L(hw->port),
971 pf->stat_offsets_loaded,
972 &osd->rx_size_511, &nsd->rx_size_511);
973 i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
974 I40E_GLPRT_PRC1023L(hw->port),
975 pf->stat_offsets_loaded,
976 &osd->rx_size_1023, &nsd->rx_size_1023);
977 i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
978 I40E_GLPRT_PRC1522L(hw->port),
979 pf->stat_offsets_loaded,
980 &osd->rx_size_1522, &nsd->rx_size_1522);
981 i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
982 I40E_GLPRT_PRC9522L(hw->port),
983 pf->stat_offsets_loaded,
984 &osd->rx_size_big, &nsd->rx_size_big);
985
986 i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
987 I40E_GLPRT_PTC64L(hw->port),
988 pf->stat_offsets_loaded,
989 &osd->tx_size_64, &nsd->tx_size_64);
990 i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
991 I40E_GLPRT_PTC127L(hw->port),
992 pf->stat_offsets_loaded,
993 &osd->tx_size_127, &nsd->tx_size_127);
994 i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
995 I40E_GLPRT_PTC255L(hw->port),
996 pf->stat_offsets_loaded,
997 &osd->tx_size_255, &nsd->tx_size_255);
998 i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
999 I40E_GLPRT_PTC511L(hw->port),
1000 pf->stat_offsets_loaded,
1001 &osd->tx_size_511, &nsd->tx_size_511);
1002 i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
1003 I40E_GLPRT_PTC1023L(hw->port),
1004 pf->stat_offsets_loaded,
1005 &osd->tx_size_1023, &nsd->tx_size_1023);
1006 i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
1007 I40E_GLPRT_PTC1522L(hw->port),
1008 pf->stat_offsets_loaded,
1009 &osd->tx_size_1522, &nsd->tx_size_1522);
1010 i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
1011 I40E_GLPRT_PTC9522L(hw->port),
1012 pf->stat_offsets_loaded,
1013 &osd->tx_size_big, &nsd->tx_size_big);
1014
1015 i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
1016 pf->stat_offsets_loaded,
1017 &osd->rx_undersize, &nsd->rx_undersize);
1018 i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
1019 pf->stat_offsets_loaded,
1020 &osd->rx_fragments, &nsd->rx_fragments);
1021 i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
1022 pf->stat_offsets_loaded,
1023 &osd->rx_oversize, &nsd->rx_oversize);
1024 i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
1025 pf->stat_offsets_loaded,
1026 &osd->rx_jabber, &nsd->rx_jabber);
1027
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001028 /* FDIR stats */
1029 i40e_stat_update32(hw, I40E_GLQF_PCNT(pf->fd_atr_cnt_idx),
1030 pf->stat_offsets_loaded,
1031 &osd->fd_atr_match, &nsd->fd_atr_match);
1032 i40e_stat_update32(hw, I40E_GLQF_PCNT(pf->fd_sb_cnt_idx),
1033 pf->stat_offsets_loaded,
1034 &osd->fd_sb_match, &nsd->fd_sb_match);
1035
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001036 val = rd32(hw, I40E_PRTPM_EEE_STAT);
1037 nsd->tx_lpi_status =
1038 (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
1039 I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
1040 nsd->rx_lpi_status =
1041 (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
1042 I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
1043 i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
1044 pf->stat_offsets_loaded,
1045 &osd->tx_lpi_count, &nsd->tx_lpi_count);
1046 i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
1047 pf->stat_offsets_loaded,
1048 &osd->rx_lpi_count, &nsd->rx_lpi_count);
1049
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001050 pf->stat_offsets_loaded = true;
1051}
1052
1053/**
Shannon Nelson7812fdd2014-04-23 04:50:18 +00001054 * i40e_update_stats - Update the various statistics counters.
1055 * @vsi: the VSI to be updated
1056 *
1057 * Update the various stats for this VSI and its related entities.
1058 **/
1059void i40e_update_stats(struct i40e_vsi *vsi)
1060{
1061 struct i40e_pf *pf = vsi->back;
1062
1063 if (vsi == pf->vsi[pf->lan_vsi])
1064 i40e_update_pf_stats(pf);
1065
1066 i40e_update_vsi_stats(vsi);
1067}
1068
1069/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001070 * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
1071 * @vsi: the VSI to be searched
1072 * @macaddr: the MAC address
1073 * @vlan: the vlan
1074 * @is_vf: make sure its a vf filter, else doesn't matter
1075 * @is_netdev: make sure its a netdev filter, else doesn't matter
1076 *
1077 * Returns ptr to the filter object or NULL
1078 **/
1079static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
1080 u8 *macaddr, s16 vlan,
1081 bool is_vf, bool is_netdev)
1082{
1083 struct i40e_mac_filter *f;
1084
1085 if (!vsi || !macaddr)
1086 return NULL;
1087
1088 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1089 if ((ether_addr_equal(macaddr, f->macaddr)) &&
1090 (vlan == f->vlan) &&
1091 (!is_vf || f->is_vf) &&
1092 (!is_netdev || f->is_netdev))
1093 return f;
1094 }
1095 return NULL;
1096}
1097
1098/**
1099 * i40e_find_mac - Find a mac addr in the macvlan filters list
1100 * @vsi: the VSI to be searched
1101 * @macaddr: the MAC address we are searching for
1102 * @is_vf: make sure its a vf filter, else doesn't matter
1103 * @is_netdev: make sure its a netdev filter, else doesn't matter
1104 *
1105 * Returns the first filter with the provided MAC address or NULL if
1106 * MAC address was not found
1107 **/
1108struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr,
1109 bool is_vf, bool is_netdev)
1110{
1111 struct i40e_mac_filter *f;
1112
1113 if (!vsi || !macaddr)
1114 return NULL;
1115
1116 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1117 if ((ether_addr_equal(macaddr, f->macaddr)) &&
1118 (!is_vf || f->is_vf) &&
1119 (!is_netdev || f->is_netdev))
1120 return f;
1121 }
1122 return NULL;
1123}
1124
1125/**
1126 * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
1127 * @vsi: the VSI to be searched
1128 *
1129 * Returns true if VSI is in vlan mode or false otherwise
1130 **/
1131bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
1132{
1133 struct i40e_mac_filter *f;
1134
1135 /* Only -1 for all the filters denotes not in vlan mode
1136 * so we have to go through all the list in order to make sure
1137 */
1138 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1139 if (f->vlan >= 0)
1140 return true;
1141 }
1142
1143 return false;
1144}
1145
1146/**
1147 * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
1148 * @vsi: the VSI to be searched
1149 * @macaddr: the mac address to be filtered
1150 * @is_vf: true if it is a vf
1151 * @is_netdev: true if it is a netdev
1152 *
1153 * Goes through all the macvlan filters and adds a
1154 * macvlan filter for each unique vlan that already exists
1155 *
1156 * Returns first filter found on success, else NULL
1157 **/
1158struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr,
1159 bool is_vf, bool is_netdev)
1160{
1161 struct i40e_mac_filter *f;
1162
1163 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1164 if (!i40e_find_filter(vsi, macaddr, f->vlan,
1165 is_vf, is_netdev)) {
1166 if (!i40e_add_filter(vsi, macaddr, f->vlan,
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08001167 is_vf, is_netdev))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001168 return NULL;
1169 }
1170 }
1171
1172 return list_first_entry_or_null(&vsi->mac_filter_list,
1173 struct i40e_mac_filter, list);
1174}
1175
1176/**
Greg Rose8c27d422014-05-22 06:31:56 +00001177 * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
1178 * @vsi: the PF Main VSI - inappropriate for any other VSI
1179 * @macaddr: the MAC address
1180 **/
1181static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
1182{
1183 struct i40e_aqc_remove_macvlan_element_data element;
1184 struct i40e_pf *pf = vsi->back;
1185 i40e_status aq_ret;
1186
1187 /* Only appropriate for the PF main VSI */
1188 if (vsi->type != I40E_VSI_MAIN)
1189 return;
1190
1191 ether_addr_copy(element.mac_addr, macaddr);
1192 element.vlan_tag = 0;
1193 element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
1194 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
1195 aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
1196 if (aq_ret)
1197 dev_err(&pf->pdev->dev, "Could not remove default MAC-VLAN\n");
1198}
1199
1200/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001201 * i40e_add_filter - Add a mac/vlan filter to the VSI
1202 * @vsi: the VSI to be searched
1203 * @macaddr: the MAC address
1204 * @vlan: the vlan
1205 * @is_vf: make sure its a vf filter, else doesn't matter
1206 * @is_netdev: make sure its a netdev filter, else doesn't matter
1207 *
1208 * Returns ptr to the filter object or NULL when no memory available.
1209 **/
1210struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
1211 u8 *macaddr, s16 vlan,
1212 bool is_vf, bool is_netdev)
1213{
1214 struct i40e_mac_filter *f;
1215
1216 if (!vsi || !macaddr)
1217 return NULL;
1218
1219 f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
1220 if (!f) {
1221 f = kzalloc(sizeof(*f), GFP_ATOMIC);
1222 if (!f)
1223 goto add_filter_out;
1224
Greg Rose9a173902014-05-22 06:32:02 +00001225 ether_addr_copy(f->macaddr, macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001226 f->vlan = vlan;
1227 f->changed = true;
1228
1229 INIT_LIST_HEAD(&f->list);
1230 list_add(&f->list, &vsi->mac_filter_list);
1231 }
1232
1233 /* increment counter and add a new flag if needed */
1234 if (is_vf) {
1235 if (!f->is_vf) {
1236 f->is_vf = true;
1237 f->counter++;
1238 }
1239 } else if (is_netdev) {
1240 if (!f->is_netdev) {
1241 f->is_netdev = true;
1242 f->counter++;
1243 }
1244 } else {
1245 f->counter++;
1246 }
1247
1248 /* changed tells sync_filters_subtask to
1249 * push the filter down to the firmware
1250 */
1251 if (f->changed) {
1252 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1253 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1254 }
1255
1256add_filter_out:
1257 return f;
1258}
1259
1260/**
1261 * i40e_del_filter - Remove a mac/vlan filter from the VSI
1262 * @vsi: the VSI to be searched
1263 * @macaddr: the MAC address
1264 * @vlan: the vlan
1265 * @is_vf: make sure it's a vf filter, else doesn't matter
1266 * @is_netdev: make sure it's a netdev filter, else doesn't matter
1267 **/
1268void i40e_del_filter(struct i40e_vsi *vsi,
1269 u8 *macaddr, s16 vlan,
1270 bool is_vf, bool is_netdev)
1271{
1272 struct i40e_mac_filter *f;
1273
1274 if (!vsi || !macaddr)
1275 return;
1276
1277 f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
1278 if (!f || f->counter == 0)
1279 return;
1280
1281 if (is_vf) {
1282 if (f->is_vf) {
1283 f->is_vf = false;
1284 f->counter--;
1285 }
1286 } else if (is_netdev) {
1287 if (f->is_netdev) {
1288 f->is_netdev = false;
1289 f->counter--;
1290 }
1291 } else {
1292 /* make sure we don't remove a filter in use by vf or netdev */
1293 int min_f = 0;
1294 min_f += (f->is_vf ? 1 : 0);
1295 min_f += (f->is_netdev ? 1 : 0);
1296
1297 if (f->counter > min_f)
1298 f->counter--;
1299 }
1300
1301 /* counter == 0 tells sync_filters_subtask to
1302 * remove the filter from the firmware's list
1303 */
1304 if (f->counter == 0) {
1305 f->changed = true;
1306 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1307 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1308 }
1309}
1310
1311/**
1312 * i40e_set_mac - NDO callback to set mac address
1313 * @netdev: network interface device structure
1314 * @p: pointer to an address structure
1315 *
1316 * Returns 0 on success, negative on failure
1317 **/
1318static int i40e_set_mac(struct net_device *netdev, void *p)
1319{
1320 struct i40e_netdev_priv *np = netdev_priv(netdev);
1321 struct i40e_vsi *vsi = np->vsi;
1322 struct sockaddr *addr = p;
1323 struct i40e_mac_filter *f;
1324
1325 if (!is_valid_ether_addr(addr->sa_data))
1326 return -EADDRNOTAVAIL;
1327
1328 netdev_info(netdev, "set mac address=%pM\n", addr->sa_data);
1329
1330 if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
1331 return 0;
1332
Anjali Singhai Jain80f64282013-11-28 06:39:47 +00001333 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
1334 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
1335 return -EADDRNOTAVAIL;
1336
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001337 if (vsi->type == I40E_VSI_MAIN) {
1338 i40e_status ret;
1339 ret = i40e_aq_mac_address_write(&vsi->back->hw,
Shannon Nelsoncc412222014-06-04 01:23:21 +00001340 I40E_AQC_WRITE_TYPE_LAA_WOL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001341 addr->sa_data, NULL);
1342 if (ret) {
1343 netdev_info(netdev,
1344 "Addr change for Main VSI failed: %d\n",
1345 ret);
1346 return -EADDRNOTAVAIL;
1347 }
1348
Greg Rose9a173902014-05-22 06:32:02 +00001349 ether_addr_copy(vsi->back->hw.mac.addr, addr->sa_data);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001350 }
1351
1352 /* In order to be sure to not drop any packets, add the new address
1353 * then delete the old one.
1354 */
1355 f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, false, false);
1356 if (!f)
1357 return -ENOMEM;
1358
1359 i40e_sync_vsi_filters(vsi);
1360 i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, false, false);
1361 i40e_sync_vsi_filters(vsi);
1362
Greg Rose9a173902014-05-22 06:32:02 +00001363 ether_addr_copy(netdev->dev_addr, addr->sa_data);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001364
1365 return 0;
1366}
1367
1368/**
1369 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1370 * @vsi: the VSI being setup
1371 * @ctxt: VSI context structure
1372 * @enabled_tc: Enabled TCs bitmap
1373 * @is_add: True if called before Add VSI
1374 *
1375 * Setup VSI queue mapping for enabled traffic classes.
1376 **/
1377static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1378 struct i40e_vsi_context *ctxt,
1379 u8 enabled_tc,
1380 bool is_add)
1381{
1382 struct i40e_pf *pf = vsi->back;
1383 u16 sections = 0;
1384 u8 netdev_tc = 0;
1385 u16 numtc = 0;
1386 u16 qcount;
1387 u8 offset;
1388 u16 qmap;
1389 int i;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001390 u16 num_tc_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001391
1392 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
1393 offset = 0;
1394
1395 if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
1396 /* Find numtc from enabled TC bitmap */
1397 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1398 if (enabled_tc & (1 << i)) /* TC is enabled */
1399 numtc++;
1400 }
1401 if (!numtc) {
1402 dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
1403 numtc = 1;
1404 }
1405 } else {
1406 /* At least TC0 is enabled in case of non-DCB case */
1407 numtc = 1;
1408 }
1409
1410 vsi->tc_config.numtc = numtc;
1411 vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001412 /* Number of queues per enabled TC */
Anjali Singhai Jaineb051af2014-05-20 08:01:46 +00001413 num_tc_qps = vsi->alloc_queue_pairs/numtc;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001414 num_tc_qps = min_t(int, num_tc_qps, I40E_MAX_QUEUES_PER_TC);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001415
1416 /* Setup queue offset/count for all TCs for given VSI */
1417 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1418 /* See if the given TC is enabled for the given VSI */
1419 if (vsi->tc_config.enabled_tc & (1 << i)) { /* TC is enabled */
1420 int pow, num_qps;
1421
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001422 switch (vsi->type) {
1423 case I40E_VSI_MAIN:
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001424 qcount = min_t(int, pf->rss_size, num_tc_qps);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001425 break;
1426 case I40E_VSI_FDIR:
1427 case I40E_VSI_SRIOV:
1428 case I40E_VSI_VMDQ2:
1429 default:
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001430 qcount = num_tc_qps;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001431 WARN_ON(i != 0);
1432 break;
1433 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001434 vsi->tc_config.tc_info[i].qoffset = offset;
1435 vsi->tc_config.tc_info[i].qcount = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001436
1437 /* find the power-of-2 of the number of queue pairs */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001438 num_qps = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001439 pow = 0;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001440 while (num_qps && ((1 << pow) < qcount)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001441 pow++;
1442 num_qps >>= 1;
1443 }
1444
1445 vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
1446 qmap =
1447 (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
1448 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
1449
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001450 offset += qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001451 } else {
1452 /* TC is not enabled so set the offset to
1453 * default queue and allocate one queue
1454 * for the given TC.
1455 */
1456 vsi->tc_config.tc_info[i].qoffset = 0;
1457 vsi->tc_config.tc_info[i].qcount = 1;
1458 vsi->tc_config.tc_info[i].netdev_tc = 0;
1459
1460 qmap = 0;
1461 }
1462 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
1463 }
1464
1465 /* Set actual Tx/Rx queue pairs */
1466 vsi->num_queue_pairs = offset;
1467
1468 /* Scheduler section valid can only be set for ADD VSI */
1469 if (is_add) {
1470 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
1471
1472 ctxt->info.up_enable_bits = enabled_tc;
1473 }
1474 if (vsi->type == I40E_VSI_SRIOV) {
1475 ctxt->info.mapping_flags |=
1476 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
1477 for (i = 0; i < vsi->num_queue_pairs; i++)
1478 ctxt->info.queue_mapping[i] =
1479 cpu_to_le16(vsi->base_queue + i);
1480 } else {
1481 ctxt->info.mapping_flags |=
1482 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
1483 ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
1484 }
1485 ctxt->info.valid_sections |= cpu_to_le16(sections);
1486}
1487
1488/**
1489 * i40e_set_rx_mode - NDO callback to set the netdev filters
1490 * @netdev: network interface device structure
1491 **/
1492static void i40e_set_rx_mode(struct net_device *netdev)
1493{
1494 struct i40e_netdev_priv *np = netdev_priv(netdev);
1495 struct i40e_mac_filter *f, *ftmp;
1496 struct i40e_vsi *vsi = np->vsi;
1497 struct netdev_hw_addr *uca;
1498 struct netdev_hw_addr *mca;
1499 struct netdev_hw_addr *ha;
1500
1501 /* add addr if not already in the filter list */
1502 netdev_for_each_uc_addr(uca, netdev) {
1503 if (!i40e_find_mac(vsi, uca->addr, false, true)) {
1504 if (i40e_is_vsi_in_vlan(vsi))
1505 i40e_put_mac_in_vlan(vsi, uca->addr,
1506 false, true);
1507 else
1508 i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY,
1509 false, true);
1510 }
1511 }
1512
1513 netdev_for_each_mc_addr(mca, netdev) {
1514 if (!i40e_find_mac(vsi, mca->addr, false, true)) {
1515 if (i40e_is_vsi_in_vlan(vsi))
1516 i40e_put_mac_in_vlan(vsi, mca->addr,
1517 false, true);
1518 else
1519 i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY,
1520 false, true);
1521 }
1522 }
1523
1524 /* remove filter if not in netdev list */
1525 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1526 bool found = false;
1527
1528 if (!f->is_netdev)
1529 continue;
1530
1531 if (is_multicast_ether_addr(f->macaddr)) {
1532 netdev_for_each_mc_addr(mca, netdev) {
1533 if (ether_addr_equal(mca->addr, f->macaddr)) {
1534 found = true;
1535 break;
1536 }
1537 }
1538 } else {
1539 netdev_for_each_uc_addr(uca, netdev) {
1540 if (ether_addr_equal(uca->addr, f->macaddr)) {
1541 found = true;
1542 break;
1543 }
1544 }
1545
1546 for_each_dev_addr(netdev, ha) {
1547 if (ether_addr_equal(ha->addr, f->macaddr)) {
1548 found = true;
1549 break;
1550 }
1551 }
1552 }
1553 if (!found)
1554 i40e_del_filter(
1555 vsi, f->macaddr, I40E_VLAN_ANY, false, true);
1556 }
1557
1558 /* check for other flag changes */
1559 if (vsi->current_netdev_flags != vsi->netdev->flags) {
1560 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1561 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1562 }
1563}
1564
1565/**
1566 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1567 * @vsi: ptr to the VSI
1568 *
1569 * Push any outstanding VSI filter changes through the AdminQ.
1570 *
1571 * Returns 0 or error value
1572 **/
1573int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
1574{
1575 struct i40e_mac_filter *f, *ftmp;
1576 bool promisc_forced_on = false;
1577 bool add_happened = false;
1578 int filter_list_len = 0;
1579 u32 changed_flags = 0;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001580 i40e_status aq_ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001581 struct i40e_pf *pf;
1582 int num_add = 0;
1583 int num_del = 0;
1584 u16 cmd_flags;
1585
1586 /* empty array typed pointers, kcalloc later */
1587 struct i40e_aqc_add_macvlan_element_data *add_list;
1588 struct i40e_aqc_remove_macvlan_element_data *del_list;
1589
1590 while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
1591 usleep_range(1000, 2000);
1592 pf = vsi->back;
1593
1594 if (vsi->netdev) {
1595 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
1596 vsi->current_netdev_flags = vsi->netdev->flags;
1597 }
1598
1599 if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
1600 vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
1601
1602 filter_list_len = pf->hw.aq.asq_buf_size /
1603 sizeof(struct i40e_aqc_remove_macvlan_element_data);
1604 del_list = kcalloc(filter_list_len,
1605 sizeof(struct i40e_aqc_remove_macvlan_element_data),
1606 GFP_KERNEL);
1607 if (!del_list)
1608 return -ENOMEM;
1609
1610 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1611 if (!f->changed)
1612 continue;
1613
1614 if (f->counter != 0)
1615 continue;
1616 f->changed = false;
1617 cmd_flags = 0;
1618
1619 /* add to delete list */
Greg Rose9a173902014-05-22 06:32:02 +00001620 ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001621 del_list[num_del].vlan_tag =
1622 cpu_to_le16((u16)(f->vlan ==
1623 I40E_VLAN_ANY ? 0 : f->vlan));
1624
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001625 cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
1626 del_list[num_del].flags = cmd_flags;
1627 num_del++;
1628
1629 /* unlink from filter list */
1630 list_del(&f->list);
1631 kfree(f);
1632
1633 /* flush a full buffer */
1634 if (num_del == filter_list_len) {
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001635 aq_ret = i40e_aq_remove_macvlan(&pf->hw,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001636 vsi->seid, del_list, num_del,
1637 NULL);
1638 num_del = 0;
1639 memset(del_list, 0, sizeof(*del_list));
1640
Shannon Nelsonfdfe9cb2014-05-20 08:01:39 +00001641 if (aq_ret &&
1642 pf->hw.aq.asq_last_status !=
1643 I40E_AQ_RC_ENOENT)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001644 dev_info(&pf->pdev->dev,
1645 "ignoring delete macvlan error, err %d, aq_err %d while flushing a full buffer\n",
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001646 aq_ret,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001647 pf->hw.aq.asq_last_status);
1648 }
1649 }
1650 if (num_del) {
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001651 aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001652 del_list, num_del, NULL);
1653 num_del = 0;
1654
Shannon Nelsonfdfe9cb2014-05-20 08:01:39 +00001655 if (aq_ret &&
1656 pf->hw.aq.asq_last_status != I40E_AQ_RC_ENOENT)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001657 dev_info(&pf->pdev->dev,
1658 "ignoring delete macvlan error, err %d, aq_err %d\n",
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001659 aq_ret, pf->hw.aq.asq_last_status);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001660 }
1661
1662 kfree(del_list);
1663 del_list = NULL;
1664
1665 /* do all the adds now */
1666 filter_list_len = pf->hw.aq.asq_buf_size /
1667 sizeof(struct i40e_aqc_add_macvlan_element_data),
1668 add_list = kcalloc(filter_list_len,
1669 sizeof(struct i40e_aqc_add_macvlan_element_data),
1670 GFP_KERNEL);
1671 if (!add_list)
1672 return -ENOMEM;
1673
1674 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1675 if (!f->changed)
1676 continue;
1677
1678 if (f->counter == 0)
1679 continue;
1680 f->changed = false;
1681 add_happened = true;
1682 cmd_flags = 0;
1683
1684 /* add to add array */
Greg Rose9a173902014-05-22 06:32:02 +00001685 ether_addr_copy(add_list[num_add].mac_addr, f->macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001686 add_list[num_add].vlan_tag =
1687 cpu_to_le16(
1688 (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan));
1689 add_list[num_add].queue_number = 0;
1690
1691 cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001692 add_list[num_add].flags = cpu_to_le16(cmd_flags);
1693 num_add++;
1694
1695 /* flush a full buffer */
1696 if (num_add == filter_list_len) {
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001697 aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
1698 add_list, num_add,
1699 NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001700 num_add = 0;
1701
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001702 if (aq_ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001703 break;
1704 memset(add_list, 0, sizeof(*add_list));
1705 }
1706 }
1707 if (num_add) {
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001708 aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
1709 add_list, num_add, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001710 num_add = 0;
1711 }
1712 kfree(add_list);
1713 add_list = NULL;
1714
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001715 if (add_happened && (!aq_ret)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001716 /* do nothing */;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001717 } else if (add_happened && (aq_ret)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001718 dev_info(&pf->pdev->dev,
1719 "add filter failed, err %d, aq_err %d\n",
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001720 aq_ret, pf->hw.aq.asq_last_status);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001721 if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) &&
1722 !test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
1723 &vsi->state)) {
1724 promisc_forced_on = true;
1725 set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
1726 &vsi->state);
1727 dev_info(&pf->pdev->dev, "promiscuous mode forced on\n");
1728 }
1729 }
1730 }
1731
1732 /* check for changes in promiscuous modes */
1733 if (changed_flags & IFF_ALLMULTI) {
1734 bool cur_multipromisc;
1735 cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001736 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
1737 vsi->seid,
1738 cur_multipromisc,
1739 NULL);
1740 if (aq_ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001741 dev_info(&pf->pdev->dev,
1742 "set multi promisc failed, err %d, aq_err %d\n",
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001743 aq_ret, pf->hw.aq.asq_last_status);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001744 }
1745 if ((changed_flags & IFF_PROMISC) || promisc_forced_on) {
1746 bool cur_promisc;
1747 cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
1748 test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
1749 &vsi->state));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001750 aq_ret = i40e_aq_set_vsi_unicast_promiscuous(&vsi->back->hw,
1751 vsi->seid,
1752 cur_promisc, NULL);
1753 if (aq_ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001754 dev_info(&pf->pdev->dev,
1755 "set uni promisc failed, err %d, aq_err %d\n",
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001756 aq_ret, pf->hw.aq.asq_last_status);
Greg Rose1a103702013-11-28 06:42:39 +00001757 aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
1758 vsi->seid,
1759 cur_promisc, NULL);
1760 if (aq_ret)
1761 dev_info(&pf->pdev->dev,
1762 "set brdcast promisc failed, err %d, aq_err %d\n",
1763 aq_ret, pf->hw.aq.asq_last_status);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001764 }
1765
1766 clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
1767 return 0;
1768}
1769
1770/**
1771 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
1772 * @pf: board private structure
1773 **/
1774static void i40e_sync_filters_subtask(struct i40e_pf *pf)
1775{
1776 int v;
1777
1778 if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
1779 return;
1780 pf->flags &= ~I40E_FLAG_FILTER_SYNC;
1781
Mitch Williams505682c2014-05-20 08:01:37 +00001782 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001783 if (pf->vsi[v] &&
1784 (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED))
1785 i40e_sync_vsi_filters(pf->vsi[v]);
1786 }
1787}
1788
1789/**
1790 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
1791 * @netdev: network interface device structure
1792 * @new_mtu: new value for maximum frame size
1793 *
1794 * Returns 0 on success, negative on failure
1795 **/
1796static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
1797{
1798 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg61a46a42014-04-23 04:50:05 +00001799 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001800 struct i40e_vsi *vsi = np->vsi;
1801
1802 /* MTU < 68 is an error and causes problems on some kernels */
1803 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
1804 return -EINVAL;
1805
1806 netdev_info(netdev, "changing MTU from %d to %d\n",
1807 netdev->mtu, new_mtu);
1808 netdev->mtu = new_mtu;
1809 if (netif_running(netdev))
1810 i40e_vsi_reinit_locked(vsi);
1811
1812 return 0;
1813}
1814
1815/**
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001816 * i40e_ioctl - Access the hwtstamp interface
1817 * @netdev: network interface device structure
1818 * @ifr: interface request data
1819 * @cmd: ioctl command
1820 **/
1821int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
1822{
1823 struct i40e_netdev_priv *np = netdev_priv(netdev);
1824 struct i40e_pf *pf = np->vsi->back;
1825
1826 switch (cmd) {
1827 case SIOCGHWTSTAMP:
1828 return i40e_ptp_get_ts_config(pf, ifr);
1829 case SIOCSHWTSTAMP:
1830 return i40e_ptp_set_ts_config(pf, ifr);
1831 default:
1832 return -EOPNOTSUPP;
1833 }
1834}
1835
1836/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001837 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
1838 * @vsi: the vsi being adjusted
1839 **/
1840void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
1841{
1842 struct i40e_vsi_context ctxt;
1843 i40e_status ret;
1844
1845 if ((vsi->info.valid_sections &
1846 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
1847 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
1848 return; /* already enabled */
1849
1850 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
1851 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
1852 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
1853
1854 ctxt.seid = vsi->seid;
1855 memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
1856 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
1857 if (ret) {
1858 dev_info(&vsi->back->pdev->dev,
1859 "%s: update vsi failed, aq_err=%d\n",
1860 __func__, vsi->back->hw.aq.asq_last_status);
1861 }
1862}
1863
1864/**
1865 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
1866 * @vsi: the vsi being adjusted
1867 **/
1868void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
1869{
1870 struct i40e_vsi_context ctxt;
1871 i40e_status ret;
1872
1873 if ((vsi->info.valid_sections &
1874 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
1875 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
1876 I40E_AQ_VSI_PVLAN_EMOD_MASK))
1877 return; /* already disabled */
1878
1879 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
1880 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
1881 I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
1882
1883 ctxt.seid = vsi->seid;
1884 memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
1885 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
1886 if (ret) {
1887 dev_info(&vsi->back->pdev->dev,
1888 "%s: update vsi failed, aq_err=%d\n",
1889 __func__, vsi->back->hw.aq.asq_last_status);
1890 }
1891}
1892
1893/**
1894 * i40e_vlan_rx_register - Setup or shutdown vlan offload
1895 * @netdev: network interface to be adjusted
1896 * @features: netdev features to test if VLAN offload is enabled or not
1897 **/
1898static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
1899{
1900 struct i40e_netdev_priv *np = netdev_priv(netdev);
1901 struct i40e_vsi *vsi = np->vsi;
1902
1903 if (features & NETIF_F_HW_VLAN_CTAG_RX)
1904 i40e_vlan_stripping_enable(vsi);
1905 else
1906 i40e_vlan_stripping_disable(vsi);
1907}
1908
1909/**
1910 * i40e_vsi_add_vlan - Add vsi membership for given vlan
1911 * @vsi: the vsi being configured
1912 * @vid: vlan id to be added (0 = untagged only , -1 = any)
1913 **/
1914int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
1915{
1916 struct i40e_mac_filter *f, *add_f;
1917 bool is_netdev, is_vf;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001918
1919 is_vf = (vsi->type == I40E_VSI_SRIOV);
1920 is_netdev = !!(vsi->netdev);
1921
1922 if (is_netdev) {
1923 add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid,
1924 is_vf, is_netdev);
1925 if (!add_f) {
1926 dev_info(&vsi->back->pdev->dev,
1927 "Could not add vlan filter %d for %pM\n",
1928 vid, vsi->netdev->dev_addr);
1929 return -ENOMEM;
1930 }
1931 }
1932
1933 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1934 add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
1935 if (!add_f) {
1936 dev_info(&vsi->back->pdev->dev,
1937 "Could not add vlan filter %d for %pM\n",
1938 vid, f->macaddr);
1939 return -ENOMEM;
1940 }
1941 }
1942
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001943 /* Now if we add a vlan tag, make sure to check if it is the first
1944 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
1945 * with 0, so we now accept untagged and specified tagged traffic
1946 * (and not any taged and untagged)
1947 */
1948 if (vid > 0) {
1949 if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr,
1950 I40E_VLAN_ANY,
1951 is_vf, is_netdev)) {
1952 i40e_del_filter(vsi, vsi->netdev->dev_addr,
1953 I40E_VLAN_ANY, is_vf, is_netdev);
1954 add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0,
1955 is_vf, is_netdev);
1956 if (!add_f) {
1957 dev_info(&vsi->back->pdev->dev,
1958 "Could not add filter 0 for %pM\n",
1959 vsi->netdev->dev_addr);
1960 return -ENOMEM;
1961 }
1962 }
Greg Rose8d82a7c2014-01-13 16:13:04 -08001963 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001964
Greg Rose8d82a7c2014-01-13 16:13:04 -08001965 /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
1966 if (vid > 0 && !vsi->info.pvid) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001967 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1968 if (i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY,
1969 is_vf, is_netdev)) {
1970 i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY,
1971 is_vf, is_netdev);
1972 add_f = i40e_add_filter(vsi, f->macaddr,
1973 0, is_vf, is_netdev);
1974 if (!add_f) {
1975 dev_info(&vsi->back->pdev->dev,
1976 "Could not add filter 0 for %pM\n",
1977 f->macaddr);
1978 return -ENOMEM;
1979 }
1980 }
1981 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001982 }
1983
Anjali Singhai Jain80f64282013-11-28 06:39:47 +00001984 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
1985 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
1986 return 0;
1987
1988 return i40e_sync_vsi_filters(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001989}
1990
1991/**
1992 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
1993 * @vsi: the vsi being configured
1994 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00001995 *
1996 * Return: 0 on success or negative otherwise
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001997 **/
1998int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
1999{
2000 struct net_device *netdev = vsi->netdev;
2001 struct i40e_mac_filter *f, *add_f;
2002 bool is_vf, is_netdev;
2003 int filter_count = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002004
2005 is_vf = (vsi->type == I40E_VSI_SRIOV);
2006 is_netdev = !!(netdev);
2007
2008 if (is_netdev)
2009 i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev);
2010
2011 list_for_each_entry(f, &vsi->mac_filter_list, list)
2012 i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
2013
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002014 /* go through all the filters for this VSI and if there is only
2015 * vid == 0 it means there are no other filters, so vid 0 must
2016 * be replaced with -1. This signifies that we should from now
2017 * on accept any traffic (with any tag present, or untagged)
2018 */
2019 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2020 if (is_netdev) {
2021 if (f->vlan &&
2022 ether_addr_equal(netdev->dev_addr, f->macaddr))
2023 filter_count++;
2024 }
2025
2026 if (f->vlan)
2027 filter_count++;
2028 }
2029
2030 if (!filter_count && is_netdev) {
2031 i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev);
2032 f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
2033 is_vf, is_netdev);
2034 if (!f) {
2035 dev_info(&vsi->back->pdev->dev,
2036 "Could not add filter %d for %pM\n",
2037 I40E_VLAN_ANY, netdev->dev_addr);
2038 return -ENOMEM;
2039 }
2040 }
2041
2042 if (!filter_count) {
2043 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2044 i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev);
2045 add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY,
2046 is_vf, is_netdev);
2047 if (!add_f) {
2048 dev_info(&vsi->back->pdev->dev,
2049 "Could not add filter %d for %pM\n",
2050 I40E_VLAN_ANY, f->macaddr);
2051 return -ENOMEM;
2052 }
2053 }
2054 }
2055
Anjali Singhai Jain80f64282013-11-28 06:39:47 +00002056 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
2057 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
2058 return 0;
2059
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002060 return i40e_sync_vsi_filters(vsi);
2061}
2062
2063/**
2064 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2065 * @netdev: network interface to be adjusted
2066 * @vid: vlan id to be added
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002067 *
2068 * net_device_ops implementation for adding vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002069 **/
2070static int i40e_vlan_rx_add_vid(struct net_device *netdev,
2071 __always_unused __be16 proto, u16 vid)
2072{
2073 struct i40e_netdev_priv *np = netdev_priv(netdev);
2074 struct i40e_vsi *vsi = np->vsi;
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002075 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002076
2077 if (vid > 4095)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002078 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002079
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002080 netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid);
2081
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002082 /* If the network stack called us with vid = 0 then
2083 * it is asking to receive priority tagged packets with
2084 * vlan id 0. Our HW receives them by default when configured
2085 * to receive untagged packets so there is no need to add an
2086 * extra filter for vlan 0 tagged packets.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002087 */
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002088 if (vid)
2089 ret = i40e_vsi_add_vlan(vsi, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002090
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002091 if (!ret && (vid < VLAN_N_VID))
2092 set_bit(vid, vsi->active_vlans);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002093
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002094 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002095}
2096
2097/**
2098 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2099 * @netdev: network interface to be adjusted
2100 * @vid: vlan id to be removed
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002101 *
Akeem G Abodunrinfdfd9432014-02-11 08:24:15 +00002102 * net_device_ops implementation for removing vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002103 **/
2104static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2105 __always_unused __be16 proto, u16 vid)
2106{
2107 struct i40e_netdev_priv *np = netdev_priv(netdev);
2108 struct i40e_vsi *vsi = np->vsi;
2109
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002110 netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid);
2111
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002112 /* return code is ignored as there is nothing a user
2113 * can do about failure to remove and a log message was
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002114 * already printed from the other function
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002115 */
2116 i40e_vsi_kill_vlan(vsi, vid);
2117
2118 clear_bit(vid, vsi->active_vlans);
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002119
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002120 return 0;
2121}
2122
2123/**
2124 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2125 * @vsi: the vsi being brought back up
2126 **/
2127static void i40e_restore_vlan(struct i40e_vsi *vsi)
2128{
2129 u16 vid;
2130
2131 if (!vsi->netdev)
2132 return;
2133
2134 i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
2135
2136 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
2137 i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
2138 vid);
2139}
2140
2141/**
2142 * i40e_vsi_add_pvid - Add pvid for the VSI
2143 * @vsi: the vsi being adjusted
2144 * @vid: the vlan id to set as a PVID
2145 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002146int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002147{
2148 struct i40e_vsi_context ctxt;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002149 i40e_status aq_ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002150
2151 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2152 vsi->info.pvid = cpu_to_le16(vid);
Greg Rose6c12fcb2013-11-28 06:39:34 +00002153 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
2154 I40E_AQ_VSI_PVLAN_INSERT_PVID |
Greg Roseb774c7d2013-11-28 06:39:44 +00002155 I40E_AQ_VSI_PVLAN_EMOD_STR;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002156
2157 ctxt.seid = vsi->seid;
2158 memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002159 aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2160 if (aq_ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002161 dev_info(&vsi->back->pdev->dev,
2162 "%s: update vsi failed, aq_err=%d\n",
2163 __func__, vsi->back->hw.aq.asq_last_status);
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002164 return -ENOENT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002165 }
2166
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002167 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002168}
2169
2170/**
2171 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2172 * @vsi: the vsi being adjusted
2173 *
2174 * Just use the vlan_rx_register() service to put it back to normal
2175 **/
2176void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
2177{
Greg Rose6c12fcb2013-11-28 06:39:34 +00002178 i40e_vlan_stripping_disable(vsi);
2179
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002180 vsi->info.pvid = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002181}
2182
2183/**
2184 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2185 * @vsi: ptr to the VSI
2186 *
2187 * If this function returns with an error, then it's possible one or
2188 * more of the rings is populated (while the rest are not). It is the
2189 * callers duty to clean those orphaned rings.
2190 *
2191 * Return 0 on success, negative on failure
2192 **/
2193static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
2194{
2195 int i, err = 0;
2196
2197 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00002198 err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002199
2200 return err;
2201}
2202
2203/**
2204 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2205 * @vsi: ptr to the VSI
2206 *
2207 * Free VSI's transmit software resources
2208 **/
2209static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
2210{
2211 int i;
2212
Greg Rose8e9dca52013-12-18 13:45:53 +00002213 if (!vsi->tx_rings)
2214 return;
2215
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002216 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002217 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00002218 i40e_free_tx_resources(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002219}
2220
2221/**
2222 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2223 * @vsi: ptr to the VSI
2224 *
2225 * If this function returns with an error, then it's possible one or
2226 * more of the rings is populated (while the rest are not). It is the
2227 * callers duty to clean those orphaned rings.
2228 *
2229 * Return 0 on success, negative on failure
2230 **/
2231static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
2232{
2233 int i, err = 0;
2234
2235 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00002236 err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002237 return err;
2238}
2239
2240/**
2241 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2242 * @vsi: ptr to the VSI
2243 *
2244 * Free all receive software resources
2245 **/
2246static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
2247{
2248 int i;
2249
Greg Rose8e9dca52013-12-18 13:45:53 +00002250 if (!vsi->rx_rings)
2251 return;
2252
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002253 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002254 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00002255 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002256}
2257
2258/**
2259 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2260 * @ring: The Tx ring to configure
2261 *
2262 * Configure the Tx descriptor ring in the HMC context.
2263 **/
2264static int i40e_configure_tx_ring(struct i40e_ring *ring)
2265{
2266 struct i40e_vsi *vsi = ring->vsi;
2267 u16 pf_q = vsi->base_queue + ring->queue_index;
2268 struct i40e_hw *hw = &vsi->back->hw;
2269 struct i40e_hmc_obj_txq tx_ctx;
2270 i40e_status err = 0;
2271 u32 qtx_ctl = 0;
2272
2273 /* some ATR related tx ring init */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002274 if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002275 ring->atr_sample_rate = vsi->back->atr_sample_rate;
2276 ring->atr_count = 0;
2277 } else {
2278 ring->atr_sample_rate = 0;
2279 }
2280
2281 /* initialize XPS */
2282 if (ring->q_vector && ring->netdev &&
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08002283 vsi->tc_config.numtc <= 1 &&
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002284 !test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
2285 netif_set_xps_queue(ring->netdev,
2286 &ring->q_vector->affinity_mask,
2287 ring->queue_index);
2288
2289 /* clear the context structure first */
2290 memset(&tx_ctx, 0, sizeof(tx_ctx));
2291
2292 tx_ctx.new_context = 1;
2293 tx_ctx.base = (ring->dma / 128);
2294 tx_ctx.qlen = ring->count;
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002295 tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
2296 I40E_FLAG_FD_ATR_ENABLED));
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002297 tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
Jesse Brandeburg1943d8b2014-02-14 02:14:40 +00002298 /* FDIR VSI tx ring can still use RS bit and writebacks */
2299 if (vsi->type != I40E_VSI_FDIR)
2300 tx_ctx.head_wb_ena = 1;
2301 tx_ctx.head_wb_addr = ring->dma +
2302 (ring->count * sizeof(struct i40e_tx_desc));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002303
2304 /* As part of VSI creation/update, FW allocates certain
2305 * Tx arbitration queue sets for each TC enabled for
2306 * the VSI. The FW returns the handles to these queue
2307 * sets as part of the response buffer to Add VSI,
2308 * Update VSI, etc. AQ commands. It is expected that
2309 * these queue set handles be associated with the Tx
2310 * queues by the driver as part of the TX queue context
2311 * initialization. This has to be done regardless of
2312 * DCB as by default everything is mapped to TC0.
2313 */
2314 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
2315 tx_ctx.rdylist_act = 0;
2316
2317 /* clear the context in the HMC */
2318 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2319 if (err) {
2320 dev_info(&vsi->back->pdev->dev,
2321 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2322 ring->queue_index, pf_q, err);
2323 return -ENOMEM;
2324 }
2325
2326 /* set the context in the HMC */
2327 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
2328 if (err) {
2329 dev_info(&vsi->back->pdev->dev,
2330 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2331 ring->queue_index, pf_q, err);
2332 return -ENOMEM;
2333 }
2334
2335 /* Now associate this queue with this PCI function */
Shannon Nelson9d8bf542014-01-14 00:49:50 -08002336 if (vsi->type == I40E_VSI_VMDQ2)
2337 qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
2338 else
2339 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
Shannon Nelson13fd9772013-09-28 07:14:19 +00002340 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
2341 I40E_QTX_CTL_PF_INDX_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002342 wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
2343 i40e_flush(hw);
2344
2345 clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state);
2346
2347 /* cache tail off for easier writes later */
2348 ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2349
2350 return 0;
2351}
2352
2353/**
2354 * i40e_configure_rx_ring - Configure a receive ring context
2355 * @ring: The Rx ring to configure
2356 *
2357 * Configure the Rx descriptor ring in the HMC context.
2358 **/
2359static int i40e_configure_rx_ring(struct i40e_ring *ring)
2360{
2361 struct i40e_vsi *vsi = ring->vsi;
2362 u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
2363 u16 pf_q = vsi->base_queue + ring->queue_index;
2364 struct i40e_hw *hw = &vsi->back->hw;
2365 struct i40e_hmc_obj_rxq rx_ctx;
2366 i40e_status err = 0;
2367
2368 ring->state = 0;
2369
2370 /* clear the context structure first */
2371 memset(&rx_ctx, 0, sizeof(rx_ctx));
2372
2373 ring->rx_buf_len = vsi->rx_buf_len;
2374 ring->rx_hdr_len = vsi->rx_hdr_len;
2375
2376 rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
2377 rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
2378
2379 rx_ctx.base = (ring->dma / 128);
2380 rx_ctx.qlen = ring->count;
2381
2382 if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) {
2383 set_ring_16byte_desc_enabled(ring);
2384 rx_ctx.dsize = 0;
2385 } else {
2386 rx_ctx.dsize = 1;
2387 }
2388
2389 rx_ctx.dtype = vsi->dtype;
2390 if (vsi->dtype) {
2391 set_ring_ps_enabled(ring);
2392 rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
2393 I40E_RX_SPLIT_IP |
2394 I40E_RX_SPLIT_TCP_UDP |
2395 I40E_RX_SPLIT_SCTP;
2396 } else {
2397 rx_ctx.hsplit_0 = 0;
2398 }
2399
2400 rx_ctx.rxmax = min_t(u16, vsi->max_frame,
2401 (chain_len * ring->rx_buf_len));
2402 rx_ctx.tphrdesc_ena = 1;
2403 rx_ctx.tphwdesc_ena = 1;
2404 rx_ctx.tphdata_ena = 1;
2405 rx_ctx.tphhead_ena = 1;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00002406 if (hw->revision_id == 0)
2407 rx_ctx.lrxqthresh = 0;
2408 else
2409 rx_ctx.lrxqthresh = 2;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002410 rx_ctx.crcstrip = 1;
2411 rx_ctx.l2tsel = 1;
2412 rx_ctx.showiv = 1;
Catherine Sullivanacb36762014-03-06 09:02:30 +00002413 /* set the prefena field to 1 because the manual says to */
2414 rx_ctx.prefena = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002415
2416 /* clear the context in the HMC */
2417 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
2418 if (err) {
2419 dev_info(&vsi->back->pdev->dev,
2420 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2421 ring->queue_index, pf_q, err);
2422 return -ENOMEM;
2423 }
2424
2425 /* set the context in the HMC */
2426 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
2427 if (err) {
2428 dev_info(&vsi->back->pdev->dev,
2429 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2430 ring->queue_index, pf_q, err);
2431 return -ENOMEM;
2432 }
2433
2434 /* cache tail for quicker writes, and clear the reg before use */
2435 ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
2436 writel(0, ring->tail);
2437
2438 i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
2439
2440 return 0;
2441}
2442
2443/**
2444 * i40e_vsi_configure_tx - Configure the VSI for Tx
2445 * @vsi: VSI structure describing this set of rings and resources
2446 *
2447 * Configure the Tx VSI for operation.
2448 **/
2449static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
2450{
2451 int err = 0;
2452 u16 i;
2453
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00002454 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
2455 err = i40e_configure_tx_ring(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002456
2457 return err;
2458}
2459
2460/**
2461 * i40e_vsi_configure_rx - Configure the VSI for Rx
2462 * @vsi: the VSI being configured
2463 *
2464 * Configure the Rx VSI for operation.
2465 **/
2466static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
2467{
2468 int err = 0;
2469 u16 i;
2470
2471 if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
2472 vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
2473 + ETH_FCS_LEN + VLAN_HLEN;
2474 else
2475 vsi->max_frame = I40E_RXBUFFER_2048;
2476
2477 /* figure out correct receive buffer length */
2478 switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED |
2479 I40E_FLAG_RX_PS_ENABLED)) {
2480 case I40E_FLAG_RX_1BUF_ENABLED:
2481 vsi->rx_hdr_len = 0;
2482 vsi->rx_buf_len = vsi->max_frame;
2483 vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
2484 break;
2485 case I40E_FLAG_RX_PS_ENABLED:
2486 vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
2487 vsi->rx_buf_len = I40E_RXBUFFER_2048;
2488 vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT;
2489 break;
2490 default:
2491 vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
2492 vsi->rx_buf_len = I40E_RXBUFFER_2048;
2493 vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS;
2494 break;
2495 }
2496
2497 /* round up for the chip's needs */
2498 vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len,
2499 (1 << I40E_RXQ_CTX_HBUFF_SHIFT));
2500 vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
2501 (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
2502
2503 /* set up individual rings */
2504 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00002505 err = i40e_configure_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002506
2507 return err;
2508}
2509
2510/**
2511 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
2512 * @vsi: ptr to the VSI
2513 **/
2514static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
2515{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00002516 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002517 u16 qoffset, qcount;
2518 int i, n;
2519
2520 if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED))
2521 return;
2522
2523 for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
2524 if (!(vsi->tc_config.enabled_tc & (1 << n)))
2525 continue;
2526
2527 qoffset = vsi->tc_config.tc_info[n].qoffset;
2528 qcount = vsi->tc_config.tc_info[n].qcount;
2529 for (i = qoffset; i < (qoffset + qcount); i++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00002530 rx_ring = vsi->rx_rings[i];
2531 tx_ring = vsi->tx_rings[i];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002532 rx_ring->dcb_tc = n;
2533 tx_ring->dcb_tc = n;
2534 }
2535 }
2536}
2537
2538/**
2539 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
2540 * @vsi: ptr to the VSI
2541 **/
2542static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
2543{
2544 if (vsi->netdev)
2545 i40e_set_rx_mode(vsi->netdev);
2546}
2547
2548/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002549 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
2550 * @vsi: Pointer to the targeted VSI
2551 *
2552 * This function replays the hlist on the hw where all the SB Flow Director
2553 * filters were saved.
2554 **/
2555static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
2556{
2557 struct i40e_fdir_filter *filter;
2558 struct i40e_pf *pf = vsi->back;
2559 struct hlist_node *node;
2560
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002561 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2562 return;
2563
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002564 hlist_for_each_entry_safe(filter, node,
2565 &pf->fdir_filter_list, fdir_node) {
2566 i40e_add_del_fdir(vsi, filter, true);
2567 }
2568}
2569
2570/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002571 * i40e_vsi_configure - Set up the VSI for action
2572 * @vsi: the VSI being configured
2573 **/
2574static int i40e_vsi_configure(struct i40e_vsi *vsi)
2575{
2576 int err;
2577
2578 i40e_set_vsi_rx_mode(vsi);
2579 i40e_restore_vlan(vsi);
2580 i40e_vsi_config_dcb_rings(vsi);
2581 err = i40e_vsi_configure_tx(vsi);
2582 if (!err)
2583 err = i40e_vsi_configure_rx(vsi);
2584
2585 return err;
2586}
2587
2588/**
2589 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
2590 * @vsi: the VSI being configured
2591 **/
2592static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
2593{
2594 struct i40e_pf *pf = vsi->back;
2595 struct i40e_q_vector *q_vector;
2596 struct i40e_hw *hw = &pf->hw;
2597 u16 vector;
2598 int i, q;
2599 u32 val;
2600 u32 qp;
2601
2602 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
2603 * and PFINT_LNKLSTn registers, e.g.:
2604 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
2605 */
2606 qp = vsi->base_queue;
2607 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +00002608 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
2609 q_vector = vsi->q_vectors[i];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002610 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
2611 q_vector->rx.latency_range = I40E_LOW_LATENCY;
2612 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
2613 q_vector->rx.itr);
2614 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
2615 q_vector->tx.latency_range = I40E_LOW_LATENCY;
2616 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
2617 q_vector->tx.itr);
2618
2619 /* Linked list for the queuepairs assigned to this vector */
2620 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
2621 for (q = 0; q < q_vector->num_ringpairs; q++) {
2622 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
2623 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
2624 (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
2625 (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
2626 (I40E_QUEUE_TYPE_TX
2627 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
2628
2629 wr32(hw, I40E_QINT_RQCTL(qp), val);
2630
2631 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
2632 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
2633 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
2634 ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
2635 (I40E_QUEUE_TYPE_RX
2636 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
2637
2638 /* Terminate the linked list */
2639 if (q == (q_vector->num_ringpairs - 1))
2640 val |= (I40E_QUEUE_END_OF_LIST
2641 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
2642
2643 wr32(hw, I40E_QINT_TQCTL(qp), val);
2644 qp++;
2645 }
2646 }
2647
2648 i40e_flush(hw);
2649}
2650
2651/**
2652 * i40e_enable_misc_int_causes - enable the non-queue interrupts
2653 * @hw: ptr to the hardware info
2654 **/
2655static void i40e_enable_misc_int_causes(struct i40e_hw *hw)
2656{
2657 u32 val;
2658
2659 /* clear things first */
2660 wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
2661 rd32(hw, I40E_PFINT_ICR0); /* read to clear */
2662
2663 val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
2664 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
2665 I40E_PFINT_ICR0_ENA_GRST_MASK |
2666 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
2667 I40E_PFINT_ICR0_ENA_GPIO_MASK |
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002668 I40E_PFINT_ICR0_ENA_TIMESYNC_MASK |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002669 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
2670 I40E_PFINT_ICR0_ENA_VFLR_MASK |
2671 I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
2672
2673 wr32(hw, I40E_PFINT_ICR0_ENA, val);
2674
2675 /* SW_ITR_IDX = 0, but don't change INTENA */
Anjali Singhai Jain84ed40e2013-11-26 10:49:32 +00002676 wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
2677 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002678
2679 /* OTHER_ITR_IDX = 0 */
2680 wr32(hw, I40E_PFINT_STAT_CTL0, 0);
2681}
2682
2683/**
2684 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
2685 * @vsi: the VSI being configured
2686 **/
2687static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
2688{
Alexander Duyck493fb302013-09-28 07:01:44 +00002689 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002690 struct i40e_pf *pf = vsi->back;
2691 struct i40e_hw *hw = &pf->hw;
2692 u32 val;
2693
2694 /* set the ITR configuration */
2695 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
2696 q_vector->rx.latency_range = I40E_LOW_LATENCY;
2697 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
2698 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
2699 q_vector->tx.latency_range = I40E_LOW_LATENCY;
2700 wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
2701
2702 i40e_enable_misc_int_causes(hw);
2703
2704 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
2705 wr32(hw, I40E_PFINT_LNKLST0, 0);
2706
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00002707 /* Associate the queue pair to the vector and enable the queue int */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002708 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
2709 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
2710 (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
2711
2712 wr32(hw, I40E_QINT_RQCTL(0), val);
2713
2714 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
2715 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
2716 (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
2717
2718 wr32(hw, I40E_QINT_TQCTL(0), val);
2719 i40e_flush(hw);
2720}
2721
2722/**
Mitch Williams2ef28cf2013-11-28 06:39:32 +00002723 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
2724 * @pf: board private structure
2725 **/
2726void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
2727{
2728 struct i40e_hw *hw = &pf->hw;
2729
2730 wr32(hw, I40E_PFINT_DYN_CTL0,
2731 I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
2732 i40e_flush(hw);
2733}
2734
2735/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002736 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
2737 * @pf: board private structure
2738 **/
Shannon Nelson116a57d2013-09-28 07:13:59 +00002739void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002740{
2741 struct i40e_hw *hw = &pf->hw;
2742 u32 val;
2743
2744 val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
2745 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
2746 (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
2747
2748 wr32(hw, I40E_PFINT_DYN_CTL0, val);
2749 i40e_flush(hw);
2750}
2751
2752/**
2753 * i40e_irq_dynamic_enable - Enable default interrupt generation settings
2754 * @vsi: pointer to a vsi
2755 * @vector: enable a particular Hw Interrupt vector
2756 **/
2757void i40e_irq_dynamic_enable(struct i40e_vsi *vsi, int vector)
2758{
2759 struct i40e_pf *pf = vsi->back;
2760 struct i40e_hw *hw = &pf->hw;
2761 u32 val;
2762
2763 val = I40E_PFINT_DYN_CTLN_INTENA_MASK |
2764 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
2765 (I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
2766 wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val);
Jesse Brandeburg1022cb62013-09-28 07:13:08 +00002767 /* skip the flush */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002768}
2769
2770/**
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002771 * i40e_irq_dynamic_disable - Disable default interrupt generation settings
2772 * @vsi: pointer to a vsi
2773 * @vector: enable a particular Hw Interrupt vector
2774 **/
2775void i40e_irq_dynamic_disable(struct i40e_vsi *vsi, int vector)
2776{
2777 struct i40e_pf *pf = vsi->back;
2778 struct i40e_hw *hw = &pf->hw;
2779 u32 val;
2780
2781 val = I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
2782 wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val);
2783 i40e_flush(hw);
2784}
2785
2786/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002787 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
2788 * @irq: interrupt number
2789 * @data: pointer to a q_vector
2790 **/
2791static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
2792{
2793 struct i40e_q_vector *q_vector = data;
2794
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00002795 if (!q_vector->tx.ring && !q_vector->rx.ring)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002796 return IRQ_HANDLED;
2797
2798 napi_schedule(&q_vector->napi);
2799
2800 return IRQ_HANDLED;
2801}
2802
2803/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002804 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
2805 * @vsi: the VSI being configured
2806 * @basename: name for the vector
2807 *
2808 * Allocates MSI-X vectors and requests interrupts from the kernel.
2809 **/
2810static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
2811{
2812 int q_vectors = vsi->num_q_vectors;
2813 struct i40e_pf *pf = vsi->back;
2814 int base = vsi->base_vector;
2815 int rx_int_idx = 0;
2816 int tx_int_idx = 0;
2817 int vector, err;
2818
2819 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck493fb302013-09-28 07:01:44 +00002820 struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002821
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00002822 if (q_vector->tx.ring && q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002823 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2824 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
2825 tx_int_idx++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00002826 } else if (q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002827 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2828 "%s-%s-%d", basename, "rx", rx_int_idx++);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00002829 } else if (q_vector->tx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002830 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2831 "%s-%s-%d", basename, "tx", tx_int_idx++);
2832 } else {
2833 /* skip this unused q_vector */
2834 continue;
2835 }
2836 err = request_irq(pf->msix_entries[base + vector].vector,
2837 vsi->irq_handler,
2838 0,
2839 q_vector->name,
2840 q_vector);
2841 if (err) {
2842 dev_info(&pf->pdev->dev,
2843 "%s: request_irq failed, error: %d\n",
2844 __func__, err);
2845 goto free_queue_irqs;
2846 }
2847 /* assign the mask for this irq */
2848 irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
2849 &q_vector->affinity_mask);
2850 }
2851
Shannon Nelson63741842014-04-23 04:50:16 +00002852 vsi->irqs_ready = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002853 return 0;
2854
2855free_queue_irqs:
2856 while (vector) {
2857 vector--;
2858 irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
2859 NULL);
2860 free_irq(pf->msix_entries[base + vector].vector,
2861 &(vsi->q_vectors[vector]));
2862 }
2863 return err;
2864}
2865
2866/**
2867 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
2868 * @vsi: the VSI being un-configured
2869 **/
2870static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
2871{
2872 struct i40e_pf *pf = vsi->back;
2873 struct i40e_hw *hw = &pf->hw;
2874 int base = vsi->base_vector;
2875 int i;
2876
2877 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00002878 wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
2879 wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002880 }
2881
2882 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
2883 for (i = vsi->base_vector;
2884 i < (vsi->num_q_vectors + vsi->base_vector); i++)
2885 wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
2886
2887 i40e_flush(hw);
2888 for (i = 0; i < vsi->num_q_vectors; i++)
2889 synchronize_irq(pf->msix_entries[i + base].vector);
2890 } else {
2891 /* Legacy and MSI mode - this stops all interrupt handling */
2892 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
2893 wr32(hw, I40E_PFINT_DYN_CTL0, 0);
2894 i40e_flush(hw);
2895 synchronize_irq(pf->pdev->irq);
2896 }
2897}
2898
2899/**
2900 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
2901 * @vsi: the VSI being configured
2902 **/
2903static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
2904{
2905 struct i40e_pf *pf = vsi->back;
2906 int i;
2907
2908 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
2909 for (i = vsi->base_vector;
2910 i < (vsi->num_q_vectors + vsi->base_vector); i++)
2911 i40e_irq_dynamic_enable(vsi, i);
2912 } else {
2913 i40e_irq_dynamic_enable_icr0(pf);
2914 }
2915
Jesse Brandeburg1022cb62013-09-28 07:13:08 +00002916 i40e_flush(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002917 return 0;
2918}
2919
2920/**
2921 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
2922 * @pf: board private structure
2923 **/
2924static void i40e_stop_misc_vector(struct i40e_pf *pf)
2925{
2926 /* Disable ICR 0 */
2927 wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
2928 i40e_flush(&pf->hw);
2929}
2930
2931/**
2932 * i40e_intr - MSI/Legacy and non-queue interrupt handler
2933 * @irq: interrupt number
2934 * @data: pointer to a q_vector
2935 *
2936 * This is the handler used for all MSI/Legacy interrupts, and deals
2937 * with both queue and non-queue interrupts. This is also used in
2938 * MSIX mode to handle the non-queue interrupts.
2939 **/
2940static irqreturn_t i40e_intr(int irq, void *data)
2941{
2942 struct i40e_pf *pf = (struct i40e_pf *)data;
2943 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00002944 irqreturn_t ret = IRQ_NONE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002945 u32 icr0, icr0_remaining;
2946 u32 val, ena_mask;
2947
2948 icr0 = rd32(hw, I40E_PFINT_ICR0);
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00002949 ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002950
Shannon Nelson116a57d2013-09-28 07:13:59 +00002951 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
2952 if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00002953 goto enable_intr;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002954
Shannon Nelsoncd92e722013-11-16 10:00:44 +00002955 /* if interrupt but no bits showing, must be SWINT */
2956 if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
2957 (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
2958 pf->sw_int_count++;
2959
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002960 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
2961 if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
2962
2963 /* temporarily disable queue cause for NAPI processing */
2964 u32 qval = rd32(hw, I40E_QINT_RQCTL(0));
2965 qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
2966 wr32(hw, I40E_QINT_RQCTL(0), qval);
2967
2968 qval = rd32(hw, I40E_QINT_TQCTL(0));
2969 qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
2970 wr32(hw, I40E_QINT_TQCTL(0), qval);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002971
2972 if (!test_bit(__I40E_DOWN, &pf->state))
Alexander Duyck493fb302013-09-28 07:01:44 +00002973 napi_schedule(&pf->vsi[pf->lan_vsi]->q_vectors[0]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002974 }
2975
2976 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
2977 ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
2978 set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
2979 }
2980
2981 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
2982 ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
2983 set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
2984 }
2985
2986 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
2987 ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
2988 set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
2989 }
2990
2991 if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
2992 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
2993 set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
2994 ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
2995 val = rd32(hw, I40E_GLGEN_RSTAT);
2996 val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
2997 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00002998 if (val == I40E_RESET_CORER) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002999 pf->corer_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003000 } else if (val == I40E_RESET_GLOBR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003001 pf->globr_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003002 } else if (val == I40E_RESET_EMPR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003003 pf->empr_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003004 set_bit(__I40E_EMP_RESET_REQUESTED, &pf->state);
3005 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003006 }
3007
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003008 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
3009 icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
3010 dev_info(&pf->pdev->dev, "HMC error interrupt\n");
3011 }
3012
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003013 if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
3014 u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
3015
3016 if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
Jacob Kellercafa1fc2014-04-24 18:05:03 -07003017 icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003018 i40e_ptp_tx_hwtstamp(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003019 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003020 }
3021
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003022 /* If a critical error is pending we have no choice but to reset the
3023 * device.
3024 * Report and mask out any remaining unexpected interrupts.
3025 */
3026 icr0_remaining = icr0 & ena_mask;
3027 if (icr0_remaining) {
3028 dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
3029 icr0_remaining);
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003030 if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003031 (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
Anjali Singhai Jainc0c28972014-02-12 01:45:34 +00003032 (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003033 dev_info(&pf->pdev->dev, "device will be reset\n");
3034 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
3035 i40e_service_event_schedule(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003036 }
3037 ena_mask &= ~icr0_remaining;
3038 }
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003039 ret = IRQ_HANDLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003040
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003041enable_intr:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003042 /* re-enable interrupt causes */
3043 wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003044 if (!test_bit(__I40E_DOWN, &pf->state)) {
3045 i40e_service_event_schedule(pf);
3046 i40e_irq_dynamic_enable_icr0(pf);
3047 }
3048
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003049 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003050}
3051
3052/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003053 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3054 * @tx_ring: tx ring to clean
3055 * @budget: how many cleans we're allowed
3056 *
3057 * Returns true if there's any budget left (e.g. the clean is finished)
3058 **/
3059static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
3060{
3061 struct i40e_vsi *vsi = tx_ring->vsi;
3062 u16 i = tx_ring->next_to_clean;
3063 struct i40e_tx_buffer *tx_buf;
3064 struct i40e_tx_desc *tx_desc;
3065
3066 tx_buf = &tx_ring->tx_bi[i];
3067 tx_desc = I40E_TX_DESC(tx_ring, i);
3068 i -= tx_ring->count;
3069
3070 do {
3071 struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
3072
3073 /* if next_to_watch is not set then there is no work pending */
3074 if (!eop_desc)
3075 break;
3076
3077 /* prevent any other reads prior to eop_desc */
3078 read_barrier_depends();
3079
3080 /* if the descriptor isn't done, no work yet to do */
3081 if (!(eop_desc->cmd_type_offset_bsz &
3082 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
3083 break;
3084
3085 /* clear next_to_watch to prevent false hangs */
3086 tx_buf->next_to_watch = NULL;
3087
3088 /* unmap skb header data */
3089 dma_unmap_single(tx_ring->dev,
3090 dma_unmap_addr(tx_buf, dma),
3091 dma_unmap_len(tx_buf, len),
3092 DMA_TO_DEVICE);
3093
3094 dma_unmap_len_set(tx_buf, len, 0);
3095
3096
3097 /* move to the next desc and buffer to clean */
3098 tx_buf++;
3099 tx_desc++;
3100 i++;
3101 if (unlikely(!i)) {
3102 i -= tx_ring->count;
3103 tx_buf = tx_ring->tx_bi;
3104 tx_desc = I40E_TX_DESC(tx_ring, 0);
3105 }
3106
3107 /* update budget accounting */
3108 budget--;
3109 } while (likely(budget));
3110
3111 i += tx_ring->count;
3112 tx_ring->next_to_clean = i;
3113
3114 if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) {
3115 i40e_irq_dynamic_enable(vsi,
3116 tx_ring->q_vector->v_idx + vsi->base_vector);
3117 }
3118 return budget > 0;
3119}
3120
3121/**
3122 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3123 * @irq: interrupt number
3124 * @data: pointer to a q_vector
3125 **/
3126static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
3127{
3128 struct i40e_q_vector *q_vector = data;
3129 struct i40e_vsi *vsi;
3130
3131 if (!q_vector->tx.ring)
3132 return IRQ_HANDLED;
3133
3134 vsi = q_vector->tx.ring->vsi;
3135 i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
3136
3137 return IRQ_HANDLED;
3138}
3139
3140/**
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003141 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003142 * @vsi: the VSI being configured
3143 * @v_idx: vector index
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003144 * @qp_idx: queue pair index
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003145 **/
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003146static void map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003147{
Alexander Duyck493fb302013-09-28 07:01:44 +00003148 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00003149 struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
3150 struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003151
3152 tx_ring->q_vector = q_vector;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003153 tx_ring->next = q_vector->tx.ring;
3154 q_vector->tx.ring = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003155 q_vector->tx.count++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003156
3157 rx_ring->q_vector = q_vector;
3158 rx_ring->next = q_vector->rx.ring;
3159 q_vector->rx.ring = rx_ring;
3160 q_vector->rx.count++;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003161}
3162
3163/**
3164 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3165 * @vsi: the VSI being configured
3166 *
3167 * This function maps descriptor rings to the queue-specific vectors
3168 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3169 * one vector per queue pair, but on a constrained vector budget, we
3170 * group the queue pairs as "efficiently" as possible.
3171 **/
3172static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
3173{
3174 int qp_remaining = vsi->num_queue_pairs;
3175 int q_vectors = vsi->num_q_vectors;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003176 int num_ringpairs;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003177 int v_start = 0;
3178 int qp_idx = 0;
3179
3180 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3181 * group them so there are multiple queues per vector.
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003182 * It is also important to go through all the vectors available to be
3183 * sure that if we don't use all the vectors, that the remaining vectors
3184 * are cleared. This is especially important when decreasing the
3185 * number of queues in use.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003186 */
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003187 for (; v_start < q_vectors; v_start++) {
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003188 struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
3189
3190 num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
3191
3192 q_vector->num_ringpairs = num_ringpairs;
3193
3194 q_vector->rx.count = 0;
3195 q_vector->tx.count = 0;
3196 q_vector->rx.ring = NULL;
3197 q_vector->tx.ring = NULL;
3198
3199 while (num_ringpairs--) {
3200 map_vector_to_qp(vsi, v_start, qp_idx);
3201 qp_idx++;
3202 qp_remaining--;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003203 }
3204 }
3205}
3206
3207/**
3208 * i40e_vsi_request_irq - Request IRQ from the OS
3209 * @vsi: the VSI being configured
3210 * @basename: name for the vector
3211 **/
3212static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
3213{
3214 struct i40e_pf *pf = vsi->back;
3215 int err;
3216
3217 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
3218 err = i40e_vsi_request_irq_msix(vsi, basename);
3219 else if (pf->flags & I40E_FLAG_MSI_ENABLED)
3220 err = request_irq(pf->pdev->irq, i40e_intr, 0,
3221 pf->misc_int_name, pf);
3222 else
3223 err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
3224 pf->misc_int_name, pf);
3225
3226 if (err)
3227 dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
3228
3229 return err;
3230}
3231
3232#ifdef CONFIG_NET_POLL_CONTROLLER
3233/**
3234 * i40e_netpoll - A Polling 'interrupt'handler
3235 * @netdev: network interface device structure
3236 *
3237 * This is used by netconsole to send skbs without having to re-enable
3238 * interrupts. It's not called while the normal interrupt routine is executing.
3239 **/
3240static void i40e_netpoll(struct net_device *netdev)
3241{
3242 struct i40e_netdev_priv *np = netdev_priv(netdev);
3243 struct i40e_vsi *vsi = np->vsi;
3244 struct i40e_pf *pf = vsi->back;
3245 int i;
3246
3247 /* if interface is down do nothing */
3248 if (test_bit(__I40E_DOWN, &vsi->state))
3249 return;
3250
3251 pf->flags |= I40E_FLAG_IN_NETPOLL;
3252 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3253 for (i = 0; i < vsi->num_q_vectors; i++)
Alexander Duyck493fb302013-09-28 07:01:44 +00003254 i40e_msix_clean_rings(0, vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003255 } else {
3256 i40e_intr(pf->pdev->irq, netdev);
3257 }
3258 pf->flags &= ~I40E_FLAG_IN_NETPOLL;
3259}
3260#endif
3261
3262/**
Neerav Parikh23527302014-06-03 23:50:15 +00003263 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3264 * @pf: the PF being configured
3265 * @pf_q: the PF queue
3266 * @enable: enable or disable state of the queue
3267 *
3268 * This routine will wait for the given Tx queue of the PF to reach the
3269 * enabled or disabled state.
3270 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3271 * multiple retries; else will return 0 in case of success.
3272 **/
3273static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3274{
3275 int i;
3276 u32 tx_reg;
3277
3278 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3279 tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
3280 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
3281 break;
3282
3283 udelay(10);
3284 }
3285 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3286 return -ETIMEDOUT;
3287
3288 return 0;
3289}
3290
3291/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003292 * i40e_vsi_control_tx - Start or stop a VSI's rings
3293 * @vsi: the VSI being configured
3294 * @enable: start or stop the rings
3295 **/
3296static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
3297{
3298 struct i40e_pf *pf = vsi->back;
3299 struct i40e_hw *hw = &pf->hw;
Neerav Parikh23527302014-06-03 23:50:15 +00003300 int i, j, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003301 u32 tx_reg;
3302
3303 pf_q = vsi->base_queue;
3304 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Matt Jared351499a2014-04-23 04:50:03 +00003305
3306 /* warn the TX unit of coming changes */
3307 i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
3308 if (!enable)
3309 udelay(10);
3310
Mitch Williams6c5ef622014-02-20 19:29:16 -08003311 for (j = 0; j < 50; j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003312 tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
Mitch Williams6c5ef622014-02-20 19:29:16 -08003313 if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
3314 ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
3315 break;
3316 usleep_range(1000, 2000);
3317 }
Mitch Williamsfda972f2013-11-28 06:39:29 +00003318 /* Skip if the queue is already in the requested state */
Catherine Sullivan7c122002014-03-14 07:32:29 +00003319 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
Mitch Williamsfda972f2013-11-28 06:39:29 +00003320 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003321
3322 /* turn on/off the queue */
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003323 if (enable) {
3324 wr32(hw, I40E_QTX_HEAD(pf_q), 0);
Mitch Williams6c5ef622014-02-20 19:29:16 -08003325 tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003326 } else {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003327 tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003328 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003329
3330 wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
3331
3332 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00003333 ret = i40e_pf_txq_wait(pf, pf_q, enable);
3334 if (ret) {
3335 dev_info(&pf->pdev->dev,
3336 "%s: VSI seid %d Tx ring %d %sable timeout\n",
3337 __func__, vsi->seid, pf_q,
3338 (enable ? "en" : "dis"));
3339 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003340 }
3341 }
3342
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003343 if (hw->revision_id == 0)
3344 mdelay(50);
Neerav Parikh23527302014-06-03 23:50:15 +00003345 return ret;
3346}
3347
3348/**
3349 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
3350 * @pf: the PF being configured
3351 * @pf_q: the PF queue
3352 * @enable: enable or disable state of the queue
3353 *
3354 * This routine will wait for the given Rx queue of the PF to reach the
3355 * enabled or disabled state.
3356 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3357 * multiple retries; else will return 0 in case of success.
3358 **/
3359static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3360{
3361 int i;
3362 u32 rx_reg;
3363
3364 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3365 rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
3366 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
3367 break;
3368
3369 udelay(10);
3370 }
3371 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3372 return -ETIMEDOUT;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003373
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003374 return 0;
3375}
3376
3377/**
3378 * i40e_vsi_control_rx - Start or stop a VSI's rings
3379 * @vsi: the VSI being configured
3380 * @enable: start or stop the rings
3381 **/
3382static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
3383{
3384 struct i40e_pf *pf = vsi->back;
3385 struct i40e_hw *hw = &pf->hw;
Neerav Parikh23527302014-06-03 23:50:15 +00003386 int i, j, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003387 u32 rx_reg;
3388
3389 pf_q = vsi->base_queue;
3390 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Mitch Williams6c5ef622014-02-20 19:29:16 -08003391 for (j = 0; j < 50; j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003392 rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
Mitch Williams6c5ef622014-02-20 19:29:16 -08003393 if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
3394 ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
3395 break;
3396 usleep_range(1000, 2000);
3397 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003398
Catherine Sullivan7c122002014-03-14 07:32:29 +00003399 /* Skip if the queue is already in the requested state */
3400 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
3401 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003402
3403 /* turn on/off the queue */
3404 if (enable)
Mitch Williams6c5ef622014-02-20 19:29:16 -08003405 rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003406 else
Mitch Williams6c5ef622014-02-20 19:29:16 -08003407 rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003408 wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
3409
3410 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00003411 ret = i40e_pf_rxq_wait(pf, pf_q, enable);
3412 if (ret) {
3413 dev_info(&pf->pdev->dev,
3414 "%s: VSI seid %d Rx ring %d %sable timeout\n",
3415 __func__, vsi->seid, pf_q,
3416 (enable ? "en" : "dis"));
3417 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003418 }
3419 }
3420
Neerav Parikh23527302014-06-03 23:50:15 +00003421 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003422}
3423
3424/**
3425 * i40e_vsi_control_rings - Start or stop a VSI's rings
3426 * @vsi: the VSI being configured
3427 * @enable: start or stop the rings
3428 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00003429int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003430{
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00003431 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003432
3433 /* do rx first for enable and last for disable */
3434 if (request) {
3435 ret = i40e_vsi_control_rx(vsi, request);
3436 if (ret)
3437 return ret;
3438 ret = i40e_vsi_control_tx(vsi, request);
3439 } else {
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00003440 /* Ignore return value, we need to shutdown whatever we can */
3441 i40e_vsi_control_tx(vsi, request);
3442 i40e_vsi_control_rx(vsi, request);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003443 }
3444
3445 return ret;
3446}
3447
3448/**
3449 * i40e_vsi_free_irq - Free the irq association with the OS
3450 * @vsi: the VSI being configured
3451 **/
3452static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
3453{
3454 struct i40e_pf *pf = vsi->back;
3455 struct i40e_hw *hw = &pf->hw;
3456 int base = vsi->base_vector;
3457 u32 val, qp;
3458 int i;
3459
3460 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3461 if (!vsi->q_vectors)
3462 return;
3463
Shannon Nelson63741842014-04-23 04:50:16 +00003464 if (!vsi->irqs_ready)
3465 return;
3466
3467 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003468 for (i = 0; i < vsi->num_q_vectors; i++) {
3469 u16 vector = i + base;
3470
3471 /* free only the irqs that were actually requested */
Shannon Nelson78681b12013-11-28 06:39:36 +00003472 if (!vsi->q_vectors[i] ||
3473 !vsi->q_vectors[i]->num_ringpairs)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003474 continue;
3475
3476 /* clear the affinity_mask in the IRQ descriptor */
3477 irq_set_affinity_hint(pf->msix_entries[vector].vector,
3478 NULL);
3479 free_irq(pf->msix_entries[vector].vector,
Alexander Duyck493fb302013-09-28 07:01:44 +00003480 vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003481
3482 /* Tear down the interrupt queue link list
3483 *
3484 * We know that they come in pairs and always
3485 * the Rx first, then the Tx. To clear the
3486 * link list, stick the EOL value into the
3487 * next_q field of the registers.
3488 */
3489 val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
3490 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
3491 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
3492 val |= I40E_QUEUE_END_OF_LIST
3493 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
3494 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
3495
3496 while (qp != I40E_QUEUE_END_OF_LIST) {
3497 u32 next;
3498
3499 val = rd32(hw, I40E_QINT_RQCTL(qp));
3500
3501 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
3502 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
3503 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3504 I40E_QINT_RQCTL_INTEVENT_MASK);
3505
3506 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
3507 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
3508
3509 wr32(hw, I40E_QINT_RQCTL(qp), val);
3510
3511 val = rd32(hw, I40E_QINT_TQCTL(qp));
3512
3513 next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
3514 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
3515
3516 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
3517 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
3518 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3519 I40E_QINT_TQCTL_INTEVENT_MASK);
3520
3521 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
3522 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
3523
3524 wr32(hw, I40E_QINT_TQCTL(qp), val);
3525 qp = next;
3526 }
3527 }
3528 } else {
3529 free_irq(pf->pdev->irq, pf);
3530
3531 val = rd32(hw, I40E_PFINT_LNKLST0);
3532 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
3533 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
3534 val |= I40E_QUEUE_END_OF_LIST
3535 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
3536 wr32(hw, I40E_PFINT_LNKLST0, val);
3537
3538 val = rd32(hw, I40E_QINT_RQCTL(qp));
3539 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
3540 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
3541 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3542 I40E_QINT_RQCTL_INTEVENT_MASK);
3543
3544 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
3545 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
3546
3547 wr32(hw, I40E_QINT_RQCTL(qp), val);
3548
3549 val = rd32(hw, I40E_QINT_TQCTL(qp));
3550
3551 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
3552 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
3553 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3554 I40E_QINT_TQCTL_INTEVENT_MASK);
3555
3556 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
3557 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
3558
3559 wr32(hw, I40E_QINT_TQCTL(qp), val);
3560 }
3561}
3562
3563/**
Alexander Duyck493fb302013-09-28 07:01:44 +00003564 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
3565 * @vsi: the VSI being configured
3566 * @v_idx: Index of vector to be freed
3567 *
3568 * This function frees the memory allocated to the q_vector. In addition if
3569 * NAPI is enabled it will delete any references to the NAPI struct prior
3570 * to freeing the q_vector.
3571 **/
3572static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
3573{
3574 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003575 struct i40e_ring *ring;
Alexander Duyck493fb302013-09-28 07:01:44 +00003576
3577 if (!q_vector)
3578 return;
3579
3580 /* disassociate q_vector from rings */
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003581 i40e_for_each_ring(ring, q_vector->tx)
3582 ring->q_vector = NULL;
3583
3584 i40e_for_each_ring(ring, q_vector->rx)
3585 ring->q_vector = NULL;
Alexander Duyck493fb302013-09-28 07:01:44 +00003586
3587 /* only VSI w/ an associated netdev is set up w/ NAPI */
3588 if (vsi->netdev)
3589 netif_napi_del(&q_vector->napi);
3590
3591 vsi->q_vectors[v_idx] = NULL;
3592
3593 kfree_rcu(q_vector, rcu);
3594}
3595
3596/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003597 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
3598 * @vsi: the VSI being un-configured
3599 *
3600 * This frees the memory allocated to the q_vectors and
3601 * deletes references to the NAPI struct.
3602 **/
3603static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
3604{
3605 int v_idx;
3606
Alexander Duyck493fb302013-09-28 07:01:44 +00003607 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
3608 i40e_free_q_vector(vsi, v_idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003609}
3610
3611/**
3612 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
3613 * @pf: board private structure
3614 **/
3615static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
3616{
3617 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
3618 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3619 pci_disable_msix(pf->pdev);
3620 kfree(pf->msix_entries);
3621 pf->msix_entries = NULL;
3622 } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
3623 pci_disable_msi(pf->pdev);
3624 }
3625 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
3626}
3627
3628/**
3629 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
3630 * @pf: board private structure
3631 *
3632 * We go through and clear interrupt specific resources and reset the structure
3633 * to pre-load conditions
3634 **/
3635static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
3636{
3637 int i;
3638
3639 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
Mitch Williams505682c2014-05-20 08:01:37 +00003640 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003641 if (pf->vsi[i])
3642 i40e_vsi_free_q_vectors(pf->vsi[i]);
3643 i40e_reset_interrupt_capability(pf);
3644}
3645
3646/**
3647 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
3648 * @vsi: the VSI being configured
3649 **/
3650static void i40e_napi_enable_all(struct i40e_vsi *vsi)
3651{
3652 int q_idx;
3653
3654 if (!vsi->netdev)
3655 return;
3656
3657 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
Alexander Duyck493fb302013-09-28 07:01:44 +00003658 napi_enable(&vsi->q_vectors[q_idx]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003659}
3660
3661/**
3662 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
3663 * @vsi: the VSI being configured
3664 **/
3665static void i40e_napi_disable_all(struct i40e_vsi *vsi)
3666{
3667 int q_idx;
3668
3669 if (!vsi->netdev)
3670 return;
3671
3672 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
Alexander Duyck493fb302013-09-28 07:01:44 +00003673 napi_disable(&vsi->q_vectors[q_idx]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003674}
3675
3676/**
Shannon Nelson90ef8d42014-03-14 07:32:26 +00003677 * i40e_vsi_close - Shut down a VSI
3678 * @vsi: the vsi to be quelled
3679 **/
3680static void i40e_vsi_close(struct i40e_vsi *vsi)
3681{
3682 if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
3683 i40e_down(vsi);
3684 i40e_vsi_free_irq(vsi);
3685 i40e_vsi_free_tx_resources(vsi);
3686 i40e_vsi_free_rx_resources(vsi);
3687}
3688
3689/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003690 * i40e_quiesce_vsi - Pause a given VSI
3691 * @vsi: the VSI being paused
3692 **/
3693static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
3694{
3695 if (test_bit(__I40E_DOWN, &vsi->state))
3696 return;
3697
3698 set_bit(__I40E_NEEDS_RESTART, &vsi->state);
3699 if (vsi->netdev && netif_running(vsi->netdev)) {
3700 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
3701 } else {
Shannon Nelson90ef8d42014-03-14 07:32:26 +00003702 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003703 }
3704}
3705
3706/**
3707 * i40e_unquiesce_vsi - Resume a given VSI
3708 * @vsi: the VSI being resumed
3709 **/
3710static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
3711{
3712 if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
3713 return;
3714
3715 clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
3716 if (vsi->netdev && netif_running(vsi->netdev))
3717 vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
3718 else
Shannon Nelson8276f752014-03-14 07:32:27 +00003719 i40e_vsi_open(vsi); /* this clears the DOWN bit */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003720}
3721
3722/**
3723 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
3724 * @pf: the PF
3725 **/
3726static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
3727{
3728 int v;
3729
Mitch Williams505682c2014-05-20 08:01:37 +00003730 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003731 if (pf->vsi[v])
3732 i40e_quiesce_vsi(pf->vsi[v]);
3733 }
3734}
3735
3736/**
3737 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
3738 * @pf: the PF
3739 **/
3740static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
3741{
3742 int v;
3743
Mitch Williams505682c2014-05-20 08:01:37 +00003744 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003745 if (pf->vsi[v])
3746 i40e_unquiesce_vsi(pf->vsi[v]);
3747 }
3748}
3749
3750/**
3751 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
3752 * @dcbcfg: the corresponding DCBx configuration structure
3753 *
3754 * Return the number of TCs from given DCBx configuration
3755 **/
3756static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
3757{
Jesse Brandeburg078b5872013-09-25 23:41:14 +00003758 u8 num_tc = 0;
3759 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003760
3761 /* Scan the ETS Config Priority Table to find
3762 * traffic class enabled for a given priority
3763 * and use the traffic class index to get the
3764 * number of traffic classes enabled
3765 */
3766 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
3767 if (dcbcfg->etscfg.prioritytable[i] > num_tc)
3768 num_tc = dcbcfg->etscfg.prioritytable[i];
3769 }
3770
3771 /* Traffic class index starts from zero so
3772 * increment to return the actual count
3773 */
Jesse Brandeburg078b5872013-09-25 23:41:14 +00003774 return num_tc + 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003775}
3776
3777/**
3778 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
3779 * @dcbcfg: the corresponding DCBx configuration structure
3780 *
3781 * Query the current DCB configuration and return the number of
3782 * traffic classes enabled from the given DCBX config
3783 **/
3784static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
3785{
3786 u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
3787 u8 enabled_tc = 1;
3788 u8 i;
3789
3790 for (i = 0; i < num_tc; i++)
3791 enabled_tc |= 1 << i;
3792
3793 return enabled_tc;
3794}
3795
3796/**
3797 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
3798 * @pf: PF being queried
3799 *
3800 * Return number of traffic classes enabled for the given PF
3801 **/
3802static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
3803{
3804 struct i40e_hw *hw = &pf->hw;
3805 u8 i, enabled_tc;
3806 u8 num_tc = 0;
3807 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
3808
3809 /* If DCB is not enabled then always in single TC */
3810 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
3811 return 1;
3812
3813 /* MFP mode return count of enabled TCs for this PF */
3814 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3815 enabled_tc = pf->hw.func_caps.enabled_tcmap;
3816 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3817 if (enabled_tc & (1 << i))
3818 num_tc++;
3819 }
3820 return num_tc;
3821 }
3822
3823 /* SFP mode will be enabled for all TCs on port */
3824 return i40e_dcb_get_num_tc(dcbcfg);
3825}
3826
3827/**
3828 * i40e_pf_get_default_tc - Get bitmap for first enabled TC
3829 * @pf: PF being queried
3830 *
3831 * Return a bitmap for first enabled traffic class for this PF.
3832 **/
3833static u8 i40e_pf_get_default_tc(struct i40e_pf *pf)
3834{
3835 u8 enabled_tc = pf->hw.func_caps.enabled_tcmap;
3836 u8 i = 0;
3837
3838 if (!enabled_tc)
3839 return 0x1; /* TC0 */
3840
3841 /* Find the first enabled TC */
3842 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3843 if (enabled_tc & (1 << i))
3844 break;
3845 }
3846
3847 return 1 << i;
3848}
3849
3850/**
3851 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
3852 * @pf: PF being queried
3853 *
3854 * Return a bitmap for enabled traffic classes for this PF.
3855 **/
3856static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
3857{
3858 /* If DCB is not enabled for this PF then just return default TC */
3859 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
3860 return i40e_pf_get_default_tc(pf);
3861
3862 /* MFP mode will have enabled TCs set by FW */
3863 if (pf->flags & I40E_FLAG_MFP_ENABLED)
3864 return pf->hw.func_caps.enabled_tcmap;
3865
3866 /* SFP mode we want PF to be enabled for all TCs */
3867 return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
3868}
3869
3870/**
3871 * i40e_vsi_get_bw_info - Query VSI BW Information
3872 * @vsi: the VSI being queried
3873 *
3874 * Returns 0 on success, negative value on failure
3875 **/
3876static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
3877{
3878 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
3879 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
3880 struct i40e_pf *pf = vsi->back;
3881 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003882 i40e_status aq_ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003883 u32 tc_bw_max;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003884 int i;
3885
3886 /* Get the VSI level BW configuration */
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003887 aq_ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
3888 if (aq_ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003889 dev_info(&pf->pdev->dev,
3890 "couldn't get pf vsi bw config, err %d, aq_err %d\n",
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003891 aq_ret, pf->hw.aq.asq_last_status);
3892 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003893 }
3894
3895 /* Get the VSI level BW configuration per TC */
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003896 aq_ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
Jesse Brandeburg6838b532014-01-14 00:49:52 -08003897 NULL);
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003898 if (aq_ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003899 dev_info(&pf->pdev->dev,
3900 "couldn't get pf vsi ets bw config, err %d, aq_err %d\n",
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003901 aq_ret, pf->hw.aq.asq_last_status);
3902 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003903 }
3904
3905 if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
3906 dev_info(&pf->pdev->dev,
3907 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
3908 bw_config.tc_valid_bits,
3909 bw_ets_config.tc_valid_bits);
3910 /* Still continuing */
3911 }
3912
3913 vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
3914 vsi->bw_max_quanta = bw_config.max_bw;
3915 tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
3916 (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
3917 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3918 vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
3919 vsi->bw_ets_limit_credits[i] =
3920 le16_to_cpu(bw_ets_config.credits[i]);
3921 /* 3 bits out of 4 for each TC */
3922 vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
3923 }
Jesse Brandeburg078b5872013-09-25 23:41:14 +00003924
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003925 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003926}
3927
3928/**
3929 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
3930 * @vsi: the VSI being configured
3931 * @enabled_tc: TC bitmap
3932 * @bw_credits: BW shared credits per TC
3933 *
3934 * Returns 0 on success, negative value on failure
3935 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003936static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003937 u8 *bw_share)
3938{
3939 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003940 i40e_status aq_ret;
3941 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003942
3943 bw_data.tc_valid_bits = enabled_tc;
3944 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
3945 bw_data.tc_bw_credits[i] = bw_share[i];
3946
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003947 aq_ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
3948 NULL);
3949 if (aq_ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003950 dev_info(&vsi->back->pdev->dev,
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00003951 "AQ command Config VSI BW allocation per TC failed = %d\n",
3952 vsi->back->hw.aq.asq_last_status);
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003953 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003954 }
3955
3956 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
3957 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
3958
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003959 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003960}
3961
3962/**
3963 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
3964 * @vsi: the VSI being configured
3965 * @enabled_tc: TC map to be enabled
3966 *
3967 **/
3968static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
3969{
3970 struct net_device *netdev = vsi->netdev;
3971 struct i40e_pf *pf = vsi->back;
3972 struct i40e_hw *hw = &pf->hw;
3973 u8 netdev_tc = 0;
3974 int i;
3975 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
3976
3977 if (!netdev)
3978 return;
3979
3980 if (!enabled_tc) {
3981 netdev_reset_tc(netdev);
3982 return;
3983 }
3984
3985 /* Set up actual enabled TCs on the VSI */
3986 if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
3987 return;
3988
3989 /* set per TC queues for the VSI */
3990 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3991 /* Only set TC queues for enabled tcs
3992 *
3993 * e.g. For a VSI that has TC0 and TC3 enabled the
3994 * enabled_tc bitmap would be 0x00001001; the driver
3995 * will set the numtc for netdev as 2 that will be
3996 * referenced by the netdev layer as TC 0 and 1.
3997 */
3998 if (vsi->tc_config.enabled_tc & (1 << i))
3999 netdev_set_tc_queue(netdev,
4000 vsi->tc_config.tc_info[i].netdev_tc,
4001 vsi->tc_config.tc_info[i].qcount,
4002 vsi->tc_config.tc_info[i].qoffset);
4003 }
4004
4005 /* Assign UP2TC map for the VSI */
4006 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
4007 /* Get the actual TC# for the UP */
4008 u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
4009 /* Get the mapped netdev TC# for the UP */
4010 netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
4011 netdev_set_prio_tc_map(netdev, i, netdev_tc);
4012 }
4013}
4014
4015/**
4016 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4017 * @vsi: the VSI being configured
4018 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4019 **/
4020static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
4021 struct i40e_vsi_context *ctxt)
4022{
4023 /* copy just the sections touched not the entire info
4024 * since not all sections are valid as returned by
4025 * update vsi params
4026 */
4027 vsi->info.mapping_flags = ctxt->info.mapping_flags;
4028 memcpy(&vsi->info.queue_mapping,
4029 &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
4030 memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
4031 sizeof(vsi->info.tc_mapping));
4032}
4033
4034/**
4035 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4036 * @vsi: VSI to be configured
4037 * @enabled_tc: TC bitmap
4038 *
4039 * This configures a particular VSI for TCs that are mapped to the
4040 * given TC bitmap. It uses default bandwidth share for TCs across
4041 * VSIs to configure TC for a particular VSI.
4042 *
4043 * NOTE:
4044 * It is expected that the VSI queues have been quisced before calling
4045 * this function.
4046 **/
4047static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4048{
4049 u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
4050 struct i40e_vsi_context ctxt;
4051 int ret = 0;
4052 int i;
4053
4054 /* Check if enabled_tc is same as existing or new TCs */
4055 if (vsi->tc_config.enabled_tc == enabled_tc)
4056 return ret;
4057
4058 /* Enable ETS TCs with equal BW Share for now across all VSIs */
4059 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4060 if (enabled_tc & (1 << i))
4061 bw_share[i] = 1;
4062 }
4063
4064 ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
4065 if (ret) {
4066 dev_info(&vsi->back->pdev->dev,
4067 "Failed configuring TC map %d for VSI %d\n",
4068 enabled_tc, vsi->seid);
4069 goto out;
4070 }
4071
4072 /* Update Queue Pairs Mapping for currently enabled UPs */
4073 ctxt.seid = vsi->seid;
4074 ctxt.pf_num = vsi->back->hw.pf_id;
4075 ctxt.vf_num = 0;
4076 ctxt.uplink_seid = vsi->uplink_seid;
4077 memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
4078 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
4079
4080 /* Update the VSI after updating the VSI queue-mapping information */
4081 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
4082 if (ret) {
4083 dev_info(&vsi->back->pdev->dev,
4084 "update vsi failed, aq_err=%d\n",
4085 vsi->back->hw.aq.asq_last_status);
4086 goto out;
4087 }
4088 /* update the local VSI info with updated queue map */
4089 i40e_vsi_update_queue_map(vsi, &ctxt);
4090 vsi->info.valid_sections = 0;
4091
4092 /* Update current VSI BW information */
4093 ret = i40e_vsi_get_bw_info(vsi);
4094 if (ret) {
4095 dev_info(&vsi->back->pdev->dev,
4096 "Failed updating vsi bw info, aq_err=%d\n",
4097 vsi->back->hw.aq.asq_last_status);
4098 goto out;
4099 }
4100
4101 /* Update the netdev TC setup */
4102 i40e_vsi_config_netdev_tc(vsi, enabled_tc);
4103out:
4104 return ret;
4105}
4106
4107/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004108 * i40e_veb_config_tc - Configure TCs for given VEB
4109 * @veb: given VEB
4110 * @enabled_tc: TC bitmap
4111 *
4112 * Configures given TC bitmap for VEB (switching) element
4113 **/
4114int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
4115{
4116 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
4117 struct i40e_pf *pf = veb->pf;
4118 int ret = 0;
4119 int i;
4120
4121 /* No TCs or already enabled TCs just return */
4122 if (!enabled_tc || veb->enabled_tc == enabled_tc)
4123 return ret;
4124
4125 bw_data.tc_valid_bits = enabled_tc;
4126 /* bw_data.absolute_credits is not set (relative) */
4127
4128 /* Enable ETS TCs with equal BW Share for now */
4129 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4130 if (enabled_tc & (1 << i))
4131 bw_data.tc_bw_share_credits[i] = 1;
4132 }
4133
4134 ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
4135 &bw_data, NULL);
4136 if (ret) {
4137 dev_info(&pf->pdev->dev,
4138 "veb bw config failed, aq_err=%d\n",
4139 pf->hw.aq.asq_last_status);
4140 goto out;
4141 }
4142
4143 /* Update the BW information */
4144 ret = i40e_veb_get_bw_info(veb);
4145 if (ret) {
4146 dev_info(&pf->pdev->dev,
4147 "Failed getting veb bw config, aq_err=%d\n",
4148 pf->hw.aq.asq_last_status);
4149 }
4150
4151out:
4152 return ret;
4153}
4154
4155#ifdef CONFIG_I40E_DCB
4156/**
4157 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
4158 * @pf: PF struct
4159 *
4160 * Reconfigure VEB/VSIs on a given PF; it is assumed that
4161 * the caller would've quiesce all the VSIs before calling
4162 * this function
4163 **/
4164static void i40e_dcb_reconfigure(struct i40e_pf *pf)
4165{
4166 u8 tc_map = 0;
4167 int ret;
4168 u8 v;
4169
4170 /* Enable the TCs available on PF to all VEBs */
4171 tc_map = i40e_pf_get_tc_map(pf);
4172 for (v = 0; v < I40E_MAX_VEB; v++) {
4173 if (!pf->veb[v])
4174 continue;
4175 ret = i40e_veb_config_tc(pf->veb[v], tc_map);
4176 if (ret) {
4177 dev_info(&pf->pdev->dev,
4178 "Failed configuring TC for VEB seid=%d\n",
4179 pf->veb[v]->seid);
4180 /* Will try to configure as many components */
4181 }
4182 }
4183
4184 /* Update each VSI */
Mitch Williams505682c2014-05-20 08:01:37 +00004185 for (v = 0; v < pf->num_alloc_vsi; v++) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004186 if (!pf->vsi[v])
4187 continue;
4188
4189 /* - Enable all TCs for the LAN VSI
4190 * - For all others keep them at TC0 for now
4191 */
4192 if (v == pf->lan_vsi)
4193 tc_map = i40e_pf_get_tc_map(pf);
4194 else
4195 tc_map = i40e_pf_get_default_tc(pf);
4196
4197 ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
4198 if (ret) {
4199 dev_info(&pf->pdev->dev,
4200 "Failed configuring TC for VSI seid=%d\n",
4201 pf->vsi[v]->seid);
4202 /* Will try to configure as many components */
4203 } else {
Neerav Parikh0672a092014-04-01 07:11:47 +00004204 /* Re-configure VSI vectors based on updated TC map */
4205 i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004206 if (pf->vsi[v]->netdev)
4207 i40e_dcbnl_set_all(pf->vsi[v]);
4208 }
4209 }
4210}
4211
4212/**
4213 * i40e_init_pf_dcb - Initialize DCB configuration
4214 * @pf: PF being configured
4215 *
4216 * Query the current DCB configuration and cache it
4217 * in the hardware structure
4218 **/
4219static int i40e_init_pf_dcb(struct i40e_pf *pf)
4220{
4221 struct i40e_hw *hw = &pf->hw;
4222 int err = 0;
4223
4224 if (pf->hw.func_caps.npar_enable)
4225 goto out;
4226
4227 /* Get the initial DCB configuration */
4228 err = i40e_init_dcb(hw);
4229 if (!err) {
4230 /* Device/Function is not DCBX capable */
4231 if ((!hw->func_caps.dcb) ||
4232 (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
4233 dev_info(&pf->pdev->dev,
4234 "DCBX offload is not supported or is disabled for this PF.\n");
4235
4236 if (pf->flags & I40E_FLAG_MFP_ENABLED)
4237 goto out;
4238
4239 } else {
4240 /* When status is not DISABLED then DCBX in FW */
4241 pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
4242 DCB_CAP_DCBX_VER_IEEE;
Neerav Parikh4d9b6042014-05-22 06:31:51 +00004243
4244 pf->flags |= I40E_FLAG_DCB_CAPABLE;
4245 /* Enable DCB tagging only when more than one TC */
4246 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
4247 pf->flags |= I40E_FLAG_DCB_ENABLED;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004248 }
Neerav Parikh014269f2014-04-01 07:11:48 +00004249 } else {
4250 dev_info(&pf->pdev->dev, "AQ Querying DCB configuration failed: %d\n",
4251 pf->hw.aq.asq_last_status);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004252 }
4253
4254out:
4255 return err;
4256}
4257#endif /* CONFIG_I40E_DCB */
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00004258#define SPEED_SIZE 14
4259#define FC_SIZE 8
4260/**
4261 * i40e_print_link_message - print link up or down
4262 * @vsi: the VSI for which link needs a message
4263 */
4264static void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
4265{
4266 char speed[SPEED_SIZE] = "Unknown";
4267 char fc[FC_SIZE] = "RX/TX";
4268
4269 if (!isup) {
4270 netdev_info(vsi->netdev, "NIC Link is Down\n");
4271 return;
4272 }
4273
4274 switch (vsi->back->hw.phy.link_info.link_speed) {
4275 case I40E_LINK_SPEED_40GB:
4276 strncpy(speed, "40 Gbps", SPEED_SIZE);
4277 break;
4278 case I40E_LINK_SPEED_10GB:
4279 strncpy(speed, "10 Gbps", SPEED_SIZE);
4280 break;
4281 case I40E_LINK_SPEED_1GB:
4282 strncpy(speed, "1000 Mbps", SPEED_SIZE);
4283 break;
4284 default:
4285 break;
4286 }
4287
4288 switch (vsi->back->hw.fc.current_mode) {
4289 case I40E_FC_FULL:
4290 strncpy(fc, "RX/TX", FC_SIZE);
4291 break;
4292 case I40E_FC_TX_PAUSE:
4293 strncpy(fc, "TX", FC_SIZE);
4294 break;
4295 case I40E_FC_RX_PAUSE:
4296 strncpy(fc, "RX", FC_SIZE);
4297 break;
4298 default:
4299 strncpy(fc, "None", FC_SIZE);
4300 break;
4301 }
4302
4303 netdev_info(vsi->netdev, "NIC Link is Up %s Full Duplex, Flow Control: %s\n",
4304 speed, fc);
4305}
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004306
4307/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004308 * i40e_up_complete - Finish the last steps of bringing up a connection
4309 * @vsi: the VSI being configured
4310 **/
4311static int i40e_up_complete(struct i40e_vsi *vsi)
4312{
4313 struct i40e_pf *pf = vsi->back;
4314 int err;
4315
4316 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
4317 i40e_vsi_configure_msix(vsi);
4318 else
4319 i40e_configure_msi_and_legacy(vsi);
4320
4321 /* start rings */
4322 err = i40e_vsi_control_rings(vsi, true);
4323 if (err)
4324 return err;
4325
4326 clear_bit(__I40E_DOWN, &vsi->state);
4327 i40e_napi_enable_all(vsi);
4328 i40e_vsi_enable_irq(vsi);
4329
4330 if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
4331 (vsi->netdev)) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00004332 i40e_print_link_message(vsi, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004333 netif_tx_start_all_queues(vsi->netdev);
4334 netif_carrier_on(vsi->netdev);
Anjali Singhai6d779b42013-09-28 06:00:02 +00004335 } else if (vsi->netdev) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00004336 i40e_print_link_message(vsi, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004337 }
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00004338
4339 /* replay FDIR SB filters */
4340 if (vsi->type == I40E_VSI_FDIR)
4341 i40e_fdir_filter_restore(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004342 i40e_service_event_schedule(pf);
4343
4344 return 0;
4345}
4346
4347/**
4348 * i40e_vsi_reinit_locked - Reset the VSI
4349 * @vsi: the VSI being configured
4350 *
4351 * Rebuild the ring structs after some configuration
4352 * has changed, e.g. MTU size.
4353 **/
4354static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
4355{
4356 struct i40e_pf *pf = vsi->back;
4357
4358 WARN_ON(in_interrupt());
4359 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
4360 usleep_range(1000, 2000);
4361 i40e_down(vsi);
4362
4363 /* Give a VF some time to respond to the reset. The
4364 * two second wait is based upon the watchdog cycle in
4365 * the VF driver.
4366 */
4367 if (vsi->type == I40E_VSI_SRIOV)
4368 msleep(2000);
4369 i40e_up(vsi);
4370 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
4371}
4372
4373/**
4374 * i40e_up - Bring the connection back up after being down
4375 * @vsi: the VSI being configured
4376 **/
4377int i40e_up(struct i40e_vsi *vsi)
4378{
4379 int err;
4380
4381 err = i40e_vsi_configure(vsi);
4382 if (!err)
4383 err = i40e_up_complete(vsi);
4384
4385 return err;
4386}
4387
4388/**
4389 * i40e_down - Shutdown the connection processing
4390 * @vsi: the VSI being stopped
4391 **/
4392void i40e_down(struct i40e_vsi *vsi)
4393{
4394 int i;
4395
4396 /* It is assumed that the caller of this function
4397 * sets the vsi->state __I40E_DOWN bit.
4398 */
4399 if (vsi->netdev) {
4400 netif_carrier_off(vsi->netdev);
4401 netif_tx_disable(vsi->netdev);
4402 }
4403 i40e_vsi_disable_irq(vsi);
4404 i40e_vsi_control_rings(vsi, false);
4405 i40e_napi_disable_all(vsi);
4406
4407 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00004408 i40e_clean_tx_ring(vsi->tx_rings[i]);
4409 i40e_clean_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004410 }
4411}
4412
4413/**
4414 * i40e_setup_tc - configure multiple traffic classes
4415 * @netdev: net device to configure
4416 * @tc: number of traffic classes to enable
4417 **/
4418static int i40e_setup_tc(struct net_device *netdev, u8 tc)
4419{
4420 struct i40e_netdev_priv *np = netdev_priv(netdev);
4421 struct i40e_vsi *vsi = np->vsi;
4422 struct i40e_pf *pf = vsi->back;
4423 u8 enabled_tc = 0;
4424 int ret = -EINVAL;
4425 int i;
4426
4427 /* Check if DCB enabled to continue */
4428 if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
4429 netdev_info(netdev, "DCB is not enabled for adapter\n");
4430 goto exit;
4431 }
4432
4433 /* Check if MFP enabled */
4434 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
4435 netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
4436 goto exit;
4437 }
4438
4439 /* Check whether tc count is within enabled limit */
4440 if (tc > i40e_pf_get_num_tc(pf)) {
4441 netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
4442 goto exit;
4443 }
4444
4445 /* Generate TC map for number of tc requested */
4446 for (i = 0; i < tc; i++)
4447 enabled_tc |= (1 << i);
4448
4449 /* Requesting same TC configuration as already enabled */
4450 if (enabled_tc == vsi->tc_config.enabled_tc)
4451 return 0;
4452
4453 /* Quiesce VSI queues */
4454 i40e_quiesce_vsi(vsi);
4455
4456 /* Configure VSI for enabled TCs */
4457 ret = i40e_vsi_config_tc(vsi, enabled_tc);
4458 if (ret) {
4459 netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
4460 vsi->seid);
4461 goto exit;
4462 }
4463
4464 /* Unquiesce VSI */
4465 i40e_unquiesce_vsi(vsi);
4466
4467exit:
4468 return ret;
4469}
4470
4471/**
4472 * i40e_open - Called when a network interface is made active
4473 * @netdev: network interface device structure
4474 *
4475 * The open entry point is called when a network interface is made
4476 * active by the system (IFF_UP). At this point all resources needed
4477 * for transmit and receive operations are allocated, the interrupt
4478 * handler is registered with the OS, the netdev watchdog subtask is
4479 * enabled, and the stack is notified that the interface is ready.
4480 *
4481 * Returns 0 on success, negative value on failure
4482 **/
4483static int i40e_open(struct net_device *netdev)
4484{
4485 struct i40e_netdev_priv *np = netdev_priv(netdev);
4486 struct i40e_vsi *vsi = np->vsi;
4487 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004488 int err;
4489
Shannon Nelson4eb3f762014-03-06 08:59:58 +00004490 /* disallow open during test or if eeprom is broken */
4491 if (test_bit(__I40E_TESTING, &pf->state) ||
4492 test_bit(__I40E_BAD_EEPROM, &pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004493 return -EBUSY;
4494
4495 netif_carrier_off(netdev);
4496
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00004497 err = i40e_vsi_open(vsi);
4498 if (err)
4499 return err;
4500
Jesse Brandeburg059dab62014-04-01 09:07:20 +00004501 /* configure global TSO hardware offload settings */
4502 wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
4503 TCP_FLAG_FIN) >> 16);
4504 wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
4505 TCP_FLAG_FIN |
4506 TCP_FLAG_CWR) >> 16);
4507 wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
4508
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00004509#ifdef CONFIG_I40E_VXLAN
4510 vxlan_get_rx_port(netdev);
4511#endif
4512
4513 return 0;
4514}
4515
4516/**
4517 * i40e_vsi_open -
4518 * @vsi: the VSI to open
4519 *
4520 * Finish initialization of the VSI.
4521 *
4522 * Returns 0 on success, negative value on failure
4523 **/
4524int i40e_vsi_open(struct i40e_vsi *vsi)
4525{
4526 struct i40e_pf *pf = vsi->back;
4527 char int_name[IFNAMSIZ];
4528 int err;
4529
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004530 /* allocate descriptors */
4531 err = i40e_vsi_setup_tx_resources(vsi);
4532 if (err)
4533 goto err_setup_tx;
4534 err = i40e_vsi_setup_rx_resources(vsi);
4535 if (err)
4536 goto err_setup_rx;
4537
4538 err = i40e_vsi_configure(vsi);
4539 if (err)
4540 goto err_setup_rx;
4541
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00004542 if (vsi->netdev) {
4543 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
4544 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
4545 err = i40e_vsi_request_irq(vsi, int_name);
4546 if (err)
4547 goto err_setup_rx;
4548
4549 /* Notify the stack of the actual queue counts. */
4550 err = netif_set_real_num_tx_queues(vsi->netdev,
4551 vsi->num_queue_pairs);
4552 if (err)
4553 goto err_set_queues;
4554
4555 err = netif_set_real_num_rx_queues(vsi->netdev,
4556 vsi->num_queue_pairs);
4557 if (err)
4558 goto err_set_queues;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00004559
4560 } else if (vsi->type == I40E_VSI_FDIR) {
4561 snprintf(int_name, sizeof(int_name) - 1, "%s-fdir",
4562 dev_driver_string(&pf->pdev->dev));
4563 err = i40e_vsi_request_irq(vsi, int_name);
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00004564 } else {
Jean Sacrence9ccb12014-05-01 14:31:18 +00004565 err = -EINVAL;
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00004566 goto err_setup_rx;
4567 }
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00004568
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004569 err = i40e_up_complete(vsi);
4570 if (err)
4571 goto err_up_complete;
4572
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004573 return 0;
4574
4575err_up_complete:
4576 i40e_down(vsi);
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00004577err_set_queues:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004578 i40e_vsi_free_irq(vsi);
4579err_setup_rx:
4580 i40e_vsi_free_rx_resources(vsi);
4581err_setup_tx:
4582 i40e_vsi_free_tx_resources(vsi);
4583 if (vsi == pf->vsi[pf->lan_vsi])
4584 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
4585
4586 return err;
4587}
4588
4589/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004590 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
4591 * @pf: Pointer to pf
4592 *
4593 * This function destroys the hlist where all the Flow Director
4594 * filters were saved.
4595 **/
4596static void i40e_fdir_filter_exit(struct i40e_pf *pf)
4597{
4598 struct i40e_fdir_filter *filter;
4599 struct hlist_node *node2;
4600
4601 hlist_for_each_entry_safe(filter, node2,
4602 &pf->fdir_filter_list, fdir_node) {
4603 hlist_del(&filter->fdir_node);
4604 kfree(filter);
4605 }
4606 pf->fdir_pf_active_filters = 0;
4607}
4608
4609/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004610 * i40e_close - Disables a network interface
4611 * @netdev: network interface device structure
4612 *
4613 * The close entry point is called when an interface is de-activated
4614 * by the OS. The hardware is still under the driver's control, but
4615 * this netdev interface is disabled.
4616 *
4617 * Returns 0, this is not allowed to fail
4618 **/
4619static int i40e_close(struct net_device *netdev)
4620{
4621 struct i40e_netdev_priv *np = netdev_priv(netdev);
4622 struct i40e_vsi *vsi = np->vsi;
4623
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004624 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004625
4626 return 0;
4627}
4628
4629/**
4630 * i40e_do_reset - Start a PF or Core Reset sequence
4631 * @pf: board private structure
4632 * @reset_flags: which reset is requested
4633 *
4634 * The essential difference in resets is that the PF Reset
4635 * doesn't clear the packet buffers, doesn't reset the PE
4636 * firmware, and doesn't bother the other PFs on the chip.
4637 **/
4638void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
4639{
4640 u32 val;
4641
4642 WARN_ON(in_interrupt());
4643
Mitch Williams263fc482014-04-23 04:50:11 +00004644 if (i40e_check_asq_alive(&pf->hw))
4645 i40e_vc_notify_reset(pf);
4646
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004647 /* do the biggest reset indicated */
4648 if (reset_flags & (1 << __I40E_GLOBAL_RESET_REQUESTED)) {
4649
4650 /* Request a Global Reset
4651 *
4652 * This will start the chip's countdown to the actual full
4653 * chip reset event, and a warning interrupt to be sent
4654 * to all PFs, including the requestor. Our handler
4655 * for the warning interrupt will deal with the shutdown
4656 * and recovery of the switch setup.
4657 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004658 dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004659 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
4660 val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
4661 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
4662
4663 } else if (reset_flags & (1 << __I40E_CORE_RESET_REQUESTED)) {
4664
4665 /* Request a Core Reset
4666 *
4667 * Same as Global Reset, except does *not* include the MAC/PHY
4668 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004669 dev_dbg(&pf->pdev->dev, "CoreR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004670 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
4671 val |= I40E_GLGEN_RTRIG_CORER_MASK;
4672 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
4673 i40e_flush(&pf->hw);
4674
Shannon Nelson7823fe32013-11-16 10:00:45 +00004675 } else if (reset_flags & (1 << __I40E_EMP_RESET_REQUESTED)) {
4676
4677 /* Request a Firmware Reset
4678 *
4679 * Same as Global reset, plus restarting the
4680 * embedded firmware engine.
4681 */
4682 /* enable EMP Reset */
4683 val = rd32(&pf->hw, I40E_GLGEN_RSTENA_EMP);
4684 val |= I40E_GLGEN_RSTENA_EMP_EMP_RST_ENA_MASK;
4685 wr32(&pf->hw, I40E_GLGEN_RSTENA_EMP, val);
4686
4687 /* force the reset */
4688 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
4689 val |= I40E_GLGEN_RTRIG_EMPFWR_MASK;
4690 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
4691 i40e_flush(&pf->hw);
4692
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004693 } else if (reset_flags & (1 << __I40E_PF_RESET_REQUESTED)) {
4694
4695 /* Request a PF Reset
4696 *
4697 * Resets only the PF-specific registers
4698 *
4699 * This goes directly to the tear-down and rebuild of
4700 * the switch, since we need to do all the recovery as
4701 * for the Core Reset.
4702 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004703 dev_dbg(&pf->pdev->dev, "PFR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004704 i40e_handle_reset_warning(pf);
4705
4706 } else if (reset_flags & (1 << __I40E_REINIT_REQUESTED)) {
4707 int v;
4708
4709 /* Find the VSI(s) that requested a re-init */
4710 dev_info(&pf->pdev->dev,
4711 "VSI reinit requested\n");
Mitch Williams505682c2014-05-20 08:01:37 +00004712 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004713 struct i40e_vsi *vsi = pf->vsi[v];
4714 if (vsi != NULL &&
4715 test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
4716 i40e_vsi_reinit_locked(pf->vsi[v]);
4717 clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
4718 }
4719 }
4720
4721 /* no further action needed, so return now */
4722 return;
Neerav Parikhb5d06f02014-06-03 23:50:17 +00004723 } else if (reset_flags & (1 << __I40E_DOWN_REQUESTED)) {
4724 int v;
4725
4726 /* Find the VSI(s) that needs to be brought down */
4727 dev_info(&pf->pdev->dev, "VSI down requested\n");
4728 for (v = 0; v < pf->num_alloc_vsi; v++) {
4729 struct i40e_vsi *vsi = pf->vsi[v];
4730 if (vsi != NULL &&
4731 test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) {
4732 set_bit(__I40E_DOWN, &vsi->state);
4733 i40e_down(vsi);
4734 clear_bit(__I40E_DOWN_REQUESTED, &vsi->state);
4735 }
4736 }
4737
4738 /* no further action needed, so return now */
4739 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004740 } else {
4741 dev_info(&pf->pdev->dev,
4742 "bad reset request 0x%08x\n", reset_flags);
4743 return;
4744 }
4745}
4746
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004747#ifdef CONFIG_I40E_DCB
4748/**
4749 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
4750 * @pf: board private structure
4751 * @old_cfg: current DCB config
4752 * @new_cfg: new DCB config
4753 **/
4754bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
4755 struct i40e_dcbx_config *old_cfg,
4756 struct i40e_dcbx_config *new_cfg)
4757{
4758 bool need_reconfig = false;
4759
4760 /* Check if ETS configuration has changed */
4761 if (memcmp(&new_cfg->etscfg,
4762 &old_cfg->etscfg,
4763 sizeof(new_cfg->etscfg))) {
4764 /* If Priority Table has changed reconfig is needed */
4765 if (memcmp(&new_cfg->etscfg.prioritytable,
4766 &old_cfg->etscfg.prioritytable,
4767 sizeof(new_cfg->etscfg.prioritytable))) {
4768 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004769 dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004770 }
4771
4772 if (memcmp(&new_cfg->etscfg.tcbwtable,
4773 &old_cfg->etscfg.tcbwtable,
4774 sizeof(new_cfg->etscfg.tcbwtable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004775 dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004776
4777 if (memcmp(&new_cfg->etscfg.tsatable,
4778 &old_cfg->etscfg.tsatable,
4779 sizeof(new_cfg->etscfg.tsatable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004780 dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004781 }
4782
4783 /* Check if PFC configuration has changed */
4784 if (memcmp(&new_cfg->pfc,
4785 &old_cfg->pfc,
4786 sizeof(new_cfg->pfc))) {
4787 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004788 dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004789 }
4790
4791 /* Check if APP Table has changed */
4792 if (memcmp(&new_cfg->app,
4793 &old_cfg->app,
Dave Jones3d9667a2014-01-27 23:11:09 -05004794 sizeof(new_cfg->app))) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004795 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004796 dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
Dave Jones3d9667a2014-01-27 23:11:09 -05004797 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004798
4799 return need_reconfig;
4800}
4801
4802/**
4803 * i40e_handle_lldp_event - Handle LLDP Change MIB event
4804 * @pf: board private structure
4805 * @e: event info posted on ARQ
4806 **/
4807static int i40e_handle_lldp_event(struct i40e_pf *pf,
4808 struct i40e_arq_event_info *e)
4809{
4810 struct i40e_aqc_lldp_get_mib *mib =
4811 (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
4812 struct i40e_hw *hw = &pf->hw;
4813 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
4814 struct i40e_dcbx_config tmp_dcbx_cfg;
4815 bool need_reconfig = false;
4816 int ret = 0;
4817 u8 type;
4818
Neerav Parikh4d9b6042014-05-22 06:31:51 +00004819 /* Not DCB capable or capability disabled */
4820 if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
4821 return ret;
4822
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004823 /* Ignore if event is not for Nearest Bridge */
4824 type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
4825 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
4826 if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
4827 return ret;
4828
4829 /* Check MIB Type and return if event for Remote MIB update */
4830 type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
4831 if (type == I40E_AQ_LLDP_MIB_REMOTE) {
4832 /* Update the remote cached instance and return */
4833 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
4834 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
4835 &hw->remote_dcbx_config);
4836 goto exit;
4837 }
4838
4839 /* Convert/store the DCBX data from LLDPDU temporarily */
4840 memset(&tmp_dcbx_cfg, 0, sizeof(tmp_dcbx_cfg));
4841 ret = i40e_lldp_to_dcb_config(e->msg_buf, &tmp_dcbx_cfg);
4842 if (ret) {
4843 /* Error in LLDPDU parsing return */
4844 dev_info(&pf->pdev->dev, "Failed parsing LLDPDU from event buffer\n");
4845 goto exit;
4846 }
4847
4848 /* No change detected in DCBX configs */
4849 if (!memcmp(&tmp_dcbx_cfg, dcbx_cfg, sizeof(tmp_dcbx_cfg))) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004850 dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004851 goto exit;
4852 }
4853
4854 need_reconfig = i40e_dcb_need_reconfig(pf, dcbx_cfg, &tmp_dcbx_cfg);
4855
4856 i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg);
4857
4858 /* Overwrite the new configuration */
4859 *dcbx_cfg = tmp_dcbx_cfg;
4860
4861 if (!need_reconfig)
4862 goto exit;
4863
Neerav Parikh4d9b6042014-05-22 06:31:51 +00004864 /* Enable DCB tagging only when more than one TC */
4865 if (i40e_dcb_get_num_tc(dcbx_cfg) > 1)
4866 pf->flags |= I40E_FLAG_DCB_ENABLED;
4867 else
4868 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
4869
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004870 /* Reconfiguration needed quiesce all VSIs */
4871 i40e_pf_quiesce_all_vsi(pf);
4872
4873 /* Changes in configuration update VEB/VSI */
4874 i40e_dcb_reconfigure(pf);
4875
4876 i40e_pf_unquiesce_all_vsi(pf);
4877exit:
4878 return ret;
4879}
4880#endif /* CONFIG_I40E_DCB */
4881
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004882/**
Anjali Singhai Jain23326182013-11-26 10:49:22 +00004883 * i40e_do_reset_safe - Protected reset path for userland calls.
4884 * @pf: board private structure
4885 * @reset_flags: which reset is requested
4886 *
4887 **/
4888void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
4889{
4890 rtnl_lock();
4891 i40e_do_reset(pf, reset_flags);
4892 rtnl_unlock();
4893}
4894
4895/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004896 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
4897 * @pf: board private structure
4898 * @e: event info posted on ARQ
4899 *
4900 * Handler for LAN Queue Overflow Event generated by the firmware for PF
4901 * and VF queues
4902 **/
4903static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
4904 struct i40e_arq_event_info *e)
4905{
4906 struct i40e_aqc_lan_overflow *data =
4907 (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
4908 u32 queue = le32_to_cpu(data->prtdcb_rupto);
4909 u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
4910 struct i40e_hw *hw = &pf->hw;
4911 struct i40e_vf *vf;
4912 u16 vf_id;
4913
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004914 dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
4915 queue, qtx_ctl);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004916
4917 /* Queue belongs to VF, find the VF and issue VF reset */
4918 if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
4919 >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
4920 vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
4921 >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
4922 vf_id -= hw->func_caps.vf_base_id;
4923 vf = &pf->vf[vf_id];
4924 i40e_vc_notify_vf_reset(vf);
4925 /* Allow VF to process pending reset notification */
4926 msleep(20);
4927 i40e_reset_vf(vf, false);
4928 }
4929}
4930
4931/**
4932 * i40e_service_event_complete - Finish up the service event
4933 * @pf: board private structure
4934 **/
4935static void i40e_service_event_complete(struct i40e_pf *pf)
4936{
4937 BUG_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state));
4938
4939 /* flush memory to make sure state is correct before next watchog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01004940 smp_mb__before_atomic();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004941 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
4942}
4943
4944/**
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00004945 * i40e_get_current_fd_count - Get the count of FD filters programmed in the HW
4946 * @pf: board private structure
4947 **/
4948int i40e_get_current_fd_count(struct i40e_pf *pf)
4949{
4950 int val, fcnt_prog;
4951 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
4952 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
4953 ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
4954 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
4955 return fcnt_prog;
4956}
4957
4958/**
4959 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
4960 * @pf: board private structure
4961 **/
4962void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
4963{
4964 u32 fcnt_prog, fcnt_avail;
4965
4966 /* Check if, FD SB or ATR was auto disabled and if there is enough room
4967 * to re-enable
4968 */
4969 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
4970 (pf->flags & I40E_FLAG_FD_SB_ENABLED))
4971 return;
4972 fcnt_prog = i40e_get_current_fd_count(pf);
Anjali Singhai Jain89132782014-04-09 05:59:01 +00004973 fcnt_avail = i40e_get_fd_cnt_all(pf);
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00004974 if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) {
4975 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
4976 (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
4977 pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
4978 dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
4979 }
4980 }
4981 /* Wait for some more space to be available to turn on ATR */
4982 if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
4983 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
4984 (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
4985 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
4986 dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table now\n");
4987 }
4988 }
4989}
4990
4991/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004992 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
4993 * @pf: board private structure
4994 **/
4995static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
4996{
4997 if (!(pf->flags & I40E_FLAG_FDIR_REQUIRES_REINIT))
4998 return;
4999
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005000 /* if interface is down do nothing */
5001 if (test_bit(__I40E_DOWN, &pf->state))
5002 return;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005003 i40e_fdir_check_and_reenable(pf);
5004
5005 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
5006 (pf->flags & I40E_FLAG_FD_SB_ENABLED))
5007 pf->flags &= ~I40E_FLAG_FDIR_REQUIRES_REINIT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005008}
5009
5010/**
5011 * i40e_vsi_link_event - notify VSI of a link event
5012 * @vsi: vsi to be notified
5013 * @link_up: link up or down
5014 **/
5015static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
5016{
5017 if (!vsi)
5018 return;
5019
5020 switch (vsi->type) {
5021 case I40E_VSI_MAIN:
5022 if (!vsi->netdev || !vsi->netdev_registered)
5023 break;
5024
5025 if (link_up) {
5026 netif_carrier_on(vsi->netdev);
5027 netif_tx_wake_all_queues(vsi->netdev);
5028 } else {
5029 netif_carrier_off(vsi->netdev);
5030 netif_tx_stop_all_queues(vsi->netdev);
5031 }
5032 break;
5033
5034 case I40E_VSI_SRIOV:
5035 break;
5036
5037 case I40E_VSI_VMDQ2:
5038 case I40E_VSI_CTRL:
5039 case I40E_VSI_MIRROR:
5040 default:
5041 /* there is no notification for other VSIs */
5042 break;
5043 }
5044}
5045
5046/**
5047 * i40e_veb_link_event - notify elements on the veb of a link event
5048 * @veb: veb to be notified
5049 * @link_up: link up or down
5050 **/
5051static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
5052{
5053 struct i40e_pf *pf;
5054 int i;
5055
5056 if (!veb || !veb->pf)
5057 return;
5058 pf = veb->pf;
5059
5060 /* depth first... */
5061 for (i = 0; i < I40E_MAX_VEB; i++)
5062 if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
5063 i40e_veb_link_event(pf->veb[i], link_up);
5064
5065 /* ... now the local VSIs */
Mitch Williams505682c2014-05-20 08:01:37 +00005066 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005067 if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
5068 i40e_vsi_link_event(pf->vsi[i], link_up);
5069}
5070
5071/**
5072 * i40e_link_event - Update netif_carrier status
5073 * @pf: board private structure
5074 **/
5075static void i40e_link_event(struct i40e_pf *pf)
5076{
5077 bool new_link, old_link;
5078
5079 new_link = (pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP);
5080 old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
5081
5082 if (new_link == old_link)
5083 return;
Anjali Singhai6d779b42013-09-28 06:00:02 +00005084 if (!test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state))
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005085 i40e_print_link_message(pf->vsi[pf->lan_vsi], new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005086
5087 /* Notify the base of the switch tree connected to
5088 * the link. Floating VEBs are not notified.
5089 */
5090 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
5091 i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
5092 else
5093 i40e_vsi_link_event(pf->vsi[pf->lan_vsi], new_link);
5094
5095 if (pf->vf)
5096 i40e_vc_notify_link_state(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00005097
5098 if (pf->flags & I40E_FLAG_PTP)
5099 i40e_ptp_set_increment(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005100}
5101
5102/**
5103 * i40e_check_hang_subtask - Check for hung queues and dropped interrupts
5104 * @pf: board private structure
5105 *
5106 * Set the per-queue flags to request a check for stuck queues in the irq
5107 * clean functions, then force interrupts to be sure the irq clean is called.
5108 **/
5109static void i40e_check_hang_subtask(struct i40e_pf *pf)
5110{
5111 int i, v;
5112
5113 /* If we're down or resetting, just bail */
5114 if (test_bit(__I40E_CONFIG_BUSY, &pf->state))
5115 return;
5116
5117 /* for each VSI/netdev
5118 * for each Tx queue
5119 * set the check flag
5120 * for each q_vector
5121 * force an interrupt
5122 */
Mitch Williams505682c2014-05-20 08:01:37 +00005123 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005124 struct i40e_vsi *vsi = pf->vsi[v];
5125 int armed = 0;
5126
5127 if (!pf->vsi[v] ||
5128 test_bit(__I40E_DOWN, &vsi->state) ||
5129 (vsi->netdev && !netif_carrier_ok(vsi->netdev)))
5130 continue;
5131
5132 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00005133 set_check_for_tx_hang(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005134 if (test_bit(__I40E_HANG_CHECK_ARMED,
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00005135 &vsi->tx_rings[i]->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005136 armed++;
5137 }
5138
5139 if (armed) {
5140 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
5141 wr32(&vsi->back->hw, I40E_PFINT_DYN_CTL0,
5142 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
5143 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
5144 } else {
5145 u16 vec = vsi->base_vector - 1;
5146 u32 val = (I40E_PFINT_DYN_CTLN_INTENA_MASK |
5147 I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK);
5148 for (i = 0; i < vsi->num_q_vectors; i++, vec++)
5149 wr32(&vsi->back->hw,
5150 I40E_PFINT_DYN_CTLN(vec), val);
5151 }
5152 i40e_flush(&vsi->back->hw);
5153 }
5154 }
5155}
5156
5157/**
5158 * i40e_watchdog_subtask - Check and bring link up
5159 * @pf: board private structure
5160 **/
5161static void i40e_watchdog_subtask(struct i40e_pf *pf)
5162{
5163 int i;
5164
5165 /* if interface is down do nothing */
5166 if (test_bit(__I40E_DOWN, &pf->state) ||
5167 test_bit(__I40E_CONFIG_BUSY, &pf->state))
5168 return;
5169
5170 /* Update the stats for active netdevs so the network stack
5171 * can look at updated numbers whenever it cares to
5172 */
Mitch Williams505682c2014-05-20 08:01:37 +00005173 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005174 if (pf->vsi[i] && pf->vsi[i]->netdev)
5175 i40e_update_stats(pf->vsi[i]);
5176
5177 /* Update the stats for the active switching components */
5178 for (i = 0; i < I40E_MAX_VEB; i++)
5179 if (pf->veb[i])
5180 i40e_update_veb_stats(pf->veb[i]);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00005181
5182 i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005183}
5184
5185/**
5186 * i40e_reset_subtask - Set up for resetting the device and driver
5187 * @pf: board private structure
5188 **/
5189static void i40e_reset_subtask(struct i40e_pf *pf)
5190{
5191 u32 reset_flags = 0;
5192
Anjali Singhai Jain23326182013-11-26 10:49:22 +00005193 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005194 if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
5195 reset_flags |= (1 << __I40E_REINIT_REQUESTED);
5196 clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
5197 }
5198 if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
5199 reset_flags |= (1 << __I40E_PF_RESET_REQUESTED);
5200 clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
5201 }
5202 if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
5203 reset_flags |= (1 << __I40E_CORE_RESET_REQUESTED);
5204 clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
5205 }
5206 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
5207 reset_flags |= (1 << __I40E_GLOBAL_RESET_REQUESTED);
5208 clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
5209 }
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005210 if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) {
5211 reset_flags |= (1 << __I40E_DOWN_REQUESTED);
5212 clear_bit(__I40E_DOWN_REQUESTED, &pf->state);
5213 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005214
5215 /* If there's a recovery already waiting, it takes
5216 * precedence before starting a new reset sequence.
5217 */
5218 if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
5219 i40e_handle_reset_warning(pf);
Anjali Singhai Jain23326182013-11-26 10:49:22 +00005220 goto unlock;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005221 }
5222
5223 /* If we're already down or resetting, just bail */
5224 if (reset_flags &&
5225 !test_bit(__I40E_DOWN, &pf->state) &&
5226 !test_bit(__I40E_CONFIG_BUSY, &pf->state))
5227 i40e_do_reset(pf, reset_flags);
Anjali Singhai Jain23326182013-11-26 10:49:22 +00005228
5229unlock:
5230 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005231}
5232
5233/**
5234 * i40e_handle_link_event - Handle link event
5235 * @pf: board private structure
5236 * @e: event info posted on ARQ
5237 **/
5238static void i40e_handle_link_event(struct i40e_pf *pf,
5239 struct i40e_arq_event_info *e)
5240{
5241 struct i40e_hw *hw = &pf->hw;
5242 struct i40e_aqc_get_link_status *status =
5243 (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
5244 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
5245
5246 /* save off old link status information */
5247 memcpy(&pf->hw.phy.link_info_old, hw_link_info,
5248 sizeof(pf->hw.phy.link_info_old));
5249
5250 /* update link status */
5251 hw_link_info->phy_type = (enum i40e_aq_phy_type)status->phy_type;
5252 hw_link_info->link_speed = (enum i40e_aq_link_speed)status->link_speed;
5253 hw_link_info->link_info = status->link_info;
5254 hw_link_info->an_info = status->an_info;
5255 hw_link_info->ext_info = status->ext_info;
5256 hw_link_info->lse_enable =
5257 le16_to_cpu(status->command_flags) &
5258 I40E_AQ_LSE_ENABLE;
5259
5260 /* process the event */
5261 i40e_link_event(pf);
5262
5263 /* Do a new status request to re-enable LSE reporting
5264 * and load new status information into the hw struct,
5265 * then see if the status changed while processing the
5266 * initial event.
5267 */
5268 i40e_aq_get_link_info(&pf->hw, true, NULL, NULL);
5269 i40e_link_event(pf);
5270}
5271
5272/**
5273 * i40e_clean_adminq_subtask - Clean the AdminQ rings
5274 * @pf: board private structure
5275 **/
5276static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
5277{
5278 struct i40e_arq_event_info event;
5279 struct i40e_hw *hw = &pf->hw;
5280 u16 pending, i = 0;
5281 i40e_status ret;
5282 u16 opcode;
Shannon Nelson86df2422014-05-20 08:01:35 +00005283 u32 oldval;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005284 u32 val;
5285
5286 if (!test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state))
5287 return;
5288
Shannon Nelson86df2422014-05-20 08:01:35 +00005289 /* check for error indications */
5290 val = rd32(&pf->hw, pf->hw.aq.arq.len);
5291 oldval = val;
5292 if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
5293 dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
5294 val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
5295 }
5296 if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
5297 dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
5298 val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
5299 }
5300 if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
5301 dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
5302 val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
5303 }
5304 if (oldval != val)
5305 wr32(&pf->hw, pf->hw.aq.arq.len, val);
5306
5307 val = rd32(&pf->hw, pf->hw.aq.asq.len);
5308 oldval = val;
5309 if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
5310 dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
5311 val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
5312 }
5313 if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
5314 dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
5315 val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
5316 }
5317 if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
5318 dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
5319 val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
5320 }
5321 if (oldval != val)
5322 wr32(&pf->hw, pf->hw.aq.asq.len, val);
5323
Mitch Williams3197ce22013-11-28 06:39:39 +00005324 event.msg_size = I40E_MAX_AQ_BUF_SIZE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005325 event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
5326 if (!event.msg_buf)
5327 return;
5328
5329 do {
Mitch Williams2f019122013-11-28 06:39:33 +00005330 event.msg_size = I40E_MAX_AQ_BUF_SIZE; /* reinit each time */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005331 ret = i40e_clean_arq_element(hw, &event, &pending);
5332 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
5333 dev_info(&pf->pdev->dev, "No ARQ event found\n");
5334 break;
5335 } else if (ret) {
5336 dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
5337 break;
5338 }
5339
5340 opcode = le16_to_cpu(event.desc.opcode);
5341 switch (opcode) {
5342
5343 case i40e_aqc_opc_get_link_status:
5344 i40e_handle_link_event(pf, &event);
5345 break;
5346 case i40e_aqc_opc_send_msg_to_pf:
5347 ret = i40e_vc_process_vf_msg(pf,
5348 le16_to_cpu(event.desc.retval),
5349 le32_to_cpu(event.desc.cookie_high),
5350 le32_to_cpu(event.desc.cookie_low),
5351 event.msg_buf,
5352 event.msg_size);
5353 break;
5354 case i40e_aqc_opc_lldp_update_mib:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005355 dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005356#ifdef CONFIG_I40E_DCB
5357 rtnl_lock();
5358 ret = i40e_handle_lldp_event(pf, &event);
5359 rtnl_unlock();
5360#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005361 break;
5362 case i40e_aqc_opc_event_lan_overflow:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005363 dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005364 i40e_handle_lan_overflow_event(pf, &event);
5365 break;
Shannon Nelson0467bc92013-12-18 13:45:58 +00005366 case i40e_aqc_opc_send_msg_to_peer:
5367 dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
5368 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005369 default:
5370 dev_info(&pf->pdev->dev,
Shannon Nelson0467bc92013-12-18 13:45:58 +00005371 "ARQ Error: Unknown event 0x%04x received\n",
5372 opcode);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005373 break;
5374 }
5375 } while (pending && (i++ < pf->adminq_work_limit));
5376
5377 clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
5378 /* re-enable Admin queue interrupt cause */
5379 val = rd32(hw, I40E_PFINT_ICR0_ENA);
5380 val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
5381 wr32(hw, I40E_PFINT_ICR0_ENA, val);
5382 i40e_flush(hw);
5383
5384 kfree(event.msg_buf);
5385}
5386
5387/**
Shannon Nelson4eb3f762014-03-06 08:59:58 +00005388 * i40e_verify_eeprom - make sure eeprom is good to use
5389 * @pf: board private structure
5390 **/
5391static void i40e_verify_eeprom(struct i40e_pf *pf)
5392{
5393 int err;
5394
5395 err = i40e_diag_eeprom_test(&pf->hw);
5396 if (err) {
5397 /* retry in case of garbage read */
5398 err = i40e_diag_eeprom_test(&pf->hw);
5399 if (err) {
5400 dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
5401 err);
5402 set_bit(__I40E_BAD_EEPROM, &pf->state);
5403 }
5404 }
5405
5406 if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
5407 dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
5408 clear_bit(__I40E_BAD_EEPROM, &pf->state);
5409 }
5410}
5411
5412/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005413 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
5414 * @veb: pointer to the VEB instance
5415 *
5416 * This is a recursive function that first builds the attached VSIs then
5417 * recurses in to build the next layer of VEB. We track the connections
5418 * through our own index numbers because the seid's from the HW could
5419 * change across the reset.
5420 **/
5421static int i40e_reconstitute_veb(struct i40e_veb *veb)
5422{
5423 struct i40e_vsi *ctl_vsi = NULL;
5424 struct i40e_pf *pf = veb->pf;
5425 int v, veb_idx;
5426 int ret;
5427
5428 /* build VSI that owns this VEB, temporarily attached to base VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00005429 for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005430 if (pf->vsi[v] &&
5431 pf->vsi[v]->veb_idx == veb->idx &&
5432 pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
5433 ctl_vsi = pf->vsi[v];
5434 break;
5435 }
5436 }
5437 if (!ctl_vsi) {
5438 dev_info(&pf->pdev->dev,
5439 "missing owner VSI for veb_idx %d\n", veb->idx);
5440 ret = -ENOENT;
5441 goto end_reconstitute;
5442 }
5443 if (ctl_vsi != pf->vsi[pf->lan_vsi])
5444 ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
5445 ret = i40e_add_vsi(ctl_vsi);
5446 if (ret) {
5447 dev_info(&pf->pdev->dev,
5448 "rebuild of owner VSI failed: %d\n", ret);
5449 goto end_reconstitute;
5450 }
5451 i40e_vsi_reset_stats(ctl_vsi);
5452
5453 /* create the VEB in the switch and move the VSI onto the VEB */
5454 ret = i40e_add_veb(veb, ctl_vsi);
5455 if (ret)
5456 goto end_reconstitute;
5457
5458 /* create the remaining VSIs attached to this VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00005459 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005460 if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
5461 continue;
5462
5463 if (pf->vsi[v]->veb_idx == veb->idx) {
5464 struct i40e_vsi *vsi = pf->vsi[v];
5465 vsi->uplink_seid = veb->seid;
5466 ret = i40e_add_vsi(vsi);
5467 if (ret) {
5468 dev_info(&pf->pdev->dev,
5469 "rebuild of vsi_idx %d failed: %d\n",
5470 v, ret);
5471 goto end_reconstitute;
5472 }
5473 i40e_vsi_reset_stats(vsi);
5474 }
5475 }
5476
5477 /* create any VEBs attached to this VEB - RECURSION */
5478 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
5479 if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
5480 pf->veb[veb_idx]->uplink_seid = veb->seid;
5481 ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
5482 if (ret)
5483 break;
5484 }
5485 }
5486
5487end_reconstitute:
5488 return ret;
5489}
5490
5491/**
5492 * i40e_get_capabilities - get info about the HW
5493 * @pf: the PF struct
5494 **/
5495static int i40e_get_capabilities(struct i40e_pf *pf)
5496{
5497 struct i40e_aqc_list_capabilities_element_resp *cap_buf;
5498 u16 data_size;
5499 int buf_len;
5500 int err;
5501
5502 buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
5503 do {
5504 cap_buf = kzalloc(buf_len, GFP_KERNEL);
5505 if (!cap_buf)
5506 return -ENOMEM;
5507
5508 /* this loads the data into the hw struct for us */
5509 err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
5510 &data_size,
5511 i40e_aqc_opc_list_func_capabilities,
5512 NULL);
5513 /* data loaded, buffer no longer needed */
5514 kfree(cap_buf);
5515
5516 if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
5517 /* retry with a larger buffer */
5518 buf_len = data_size;
5519 } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
5520 dev_info(&pf->pdev->dev,
5521 "capability discovery failed: aq=%d\n",
5522 pf->hw.aq.asq_last_status);
5523 return -ENODEV;
5524 }
5525 } while (err);
5526
Anjali Singhai Jainac71b7b2014-02-06 05:51:08 +00005527 if (((pf->hw.aq.fw_maj_ver == 2) && (pf->hw.aq.fw_min_ver < 22)) ||
5528 (pf->hw.aq.fw_maj_ver < 2)) {
5529 pf->hw.func_caps.num_msix_vectors++;
5530 pf->hw.func_caps.num_msix_vectors_vf++;
5531 }
5532
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005533 if (pf->hw.debug_mask & I40E_DEBUG_USER)
5534 dev_info(&pf->pdev->dev,
5535 "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",
5536 pf->hw.pf_id, pf->hw.func_caps.num_vfs,
5537 pf->hw.func_caps.num_msix_vectors,
5538 pf->hw.func_caps.num_msix_vectors_vf,
5539 pf->hw.func_caps.fd_filters_guaranteed,
5540 pf->hw.func_caps.fd_filters_best_effort,
5541 pf->hw.func_caps.num_tx_qp,
5542 pf->hw.func_caps.num_vsis);
5543
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00005544#define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
5545 + pf->hw.func_caps.num_vfs)
5546 if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
5547 dev_info(&pf->pdev->dev,
5548 "got num_vsis %d, setting num_vsis to %d\n",
5549 pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
5550 pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
5551 }
5552
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005553 return 0;
5554}
5555
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005556static int i40e_vsi_clear(struct i40e_vsi *vsi);
5557
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005558/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005559 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005560 * @pf: board private structure
5561 **/
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005562static void i40e_fdir_sb_setup(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005563{
5564 struct i40e_vsi *vsi;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005565 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005566
Jesse Brandeburg407e0632014-06-03 23:50:12 +00005567 /* quick workaround for an NVM issue that leaves a critical register
5568 * uninitialized
5569 */
5570 if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
5571 static const u32 hkey[] = {
5572 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
5573 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
5574 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
5575 0x95b3a76d};
5576
5577 for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
5578 wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
5579 }
5580
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005581 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005582 return;
5583
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005584 /* find existing VSI and see if it needs configuring */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005585 vsi = NULL;
Mitch Williams505682c2014-05-20 08:01:37 +00005586 for (i = 0; i < pf->num_alloc_vsi; i++) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005587 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005588 vsi = pf->vsi[i];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005589 break;
5590 }
5591 }
5592
5593 /* create a new VSI if none exists */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005594 if (!vsi) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005595 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
5596 pf->vsi[pf->lan_vsi]->seid, 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005597 if (!vsi) {
5598 dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005599 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
5600 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005601 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005602 }
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005603
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005604 i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005605}
5606
5607/**
5608 * i40e_fdir_teardown - release the Flow Director resources
5609 * @pf: board private structure
5610 **/
5611static void i40e_fdir_teardown(struct i40e_pf *pf)
5612{
5613 int i;
5614
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005615 i40e_fdir_filter_exit(pf);
Mitch Williams505682c2014-05-20 08:01:37 +00005616 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005617 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
5618 i40e_vsi_release(pf->vsi[i]);
5619 break;
5620 }
5621 }
5622}
5623
5624/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005625 * i40e_prep_for_reset - prep for the core to reset
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005626 * @pf: board private structure
5627 *
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005628 * Close up the VFs and other things in prep for pf Reset.
5629 **/
Shannon Nelson23cfbe02014-06-04 01:23:14 +00005630static void i40e_prep_for_reset(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005631{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005632 struct i40e_hw *hw = &pf->hw;
Shannon Nelson60442de2014-04-23 04:50:13 +00005633 i40e_status ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005634 u32 v;
5635
5636 clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
5637 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
Shannon Nelson23cfbe02014-06-04 01:23:14 +00005638 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005639
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005640 dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005641
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005642 /* quiesce the VSIs and their queues that are not already DOWN */
5643 i40e_pf_quiesce_all_vsi(pf);
5644
Mitch Williams505682c2014-05-20 08:01:37 +00005645 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005646 if (pf->vsi[v])
5647 pf->vsi[v]->seid = 0;
5648 }
5649
5650 i40e_shutdown_adminq(&pf->hw);
5651
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005652 /* call shutdown HMC */
Shannon Nelson60442de2014-04-23 04:50:13 +00005653 if (hw->hmc.hmc_obj) {
5654 ret = i40e_shutdown_lan_hmc(hw);
Shannon Nelson23cfbe02014-06-04 01:23:14 +00005655 if (ret)
Shannon Nelson60442de2014-04-23 04:50:13 +00005656 dev_warn(&pf->pdev->dev,
5657 "shutdown_lan_hmc failed: %d\n", ret);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005658 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005659}
5660
5661/**
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00005662 * i40e_send_version - update firmware with driver version
5663 * @pf: PF struct
5664 */
5665static void i40e_send_version(struct i40e_pf *pf)
5666{
5667 struct i40e_driver_version dv;
5668
5669 dv.major_version = DRV_VERSION_MAJOR;
5670 dv.minor_version = DRV_VERSION_MINOR;
5671 dv.build_version = DRV_VERSION_BUILD;
5672 dv.subbuild_version = 0;
5673 strncpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
5674 i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
5675}
5676
5677/**
Jesse Brandeburg4dda12e2013-12-18 13:46:01 +00005678 * i40e_reset_and_rebuild - reset and rebuild using a saved config
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005679 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00005680 * @reinit: if the Main VSI needs to re-initialized.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005681 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00005682static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005683{
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005684 struct i40e_hw *hw = &pf->hw;
5685 i40e_status ret;
5686 u32 v;
5687
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005688 /* Now we wait for GRST to settle out.
5689 * We don't have to delete the VEBs or VSIs from the hw switch
5690 * because the reset will make them disappear.
5691 */
5692 ret = i40e_pf_reset(hw);
Akeem G Abodunrinb5565402014-04-09 05:59:04 +00005693 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005694 dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
Akeem G Abodunrinb5565402014-04-09 05:59:04 +00005695 goto end_core_reset;
5696 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005697 pf->pfr_count++;
5698
5699 if (test_bit(__I40E_DOWN, &pf->state))
5700 goto end_core_reset;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005701 dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005702
5703 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
5704 ret = i40e_init_adminq(&pf->hw);
5705 if (ret) {
5706 dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, %d\n", ret);
5707 goto end_core_reset;
5708 }
5709
Shannon Nelson4eb3f762014-03-06 08:59:58 +00005710 /* re-verify the eeprom if we just had an EMP reset */
5711 if (test_bit(__I40E_EMP_RESET_REQUESTED, &pf->state)) {
5712 clear_bit(__I40E_EMP_RESET_REQUESTED, &pf->state);
5713 i40e_verify_eeprom(pf);
5714 }
5715
Shannon Nelsone78ac4bf2014-05-10 04:49:09 +00005716 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005717 ret = i40e_get_capabilities(pf);
5718 if (ret) {
5719 dev_info(&pf->pdev->dev, "i40e_get_capabilities failed, %d\n",
5720 ret);
5721 goto end_core_reset;
5722 }
5723
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005724 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
5725 hw->func_caps.num_rx_qp,
5726 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
5727 if (ret) {
5728 dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
5729 goto end_core_reset;
5730 }
5731 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
5732 if (ret) {
5733 dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
5734 goto end_core_reset;
5735 }
5736
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005737#ifdef CONFIG_I40E_DCB
5738 ret = i40e_init_pf_dcb(pf);
5739 if (ret) {
5740 dev_info(&pf->pdev->dev, "init_pf_dcb failed: %d\n", ret);
5741 goto end_core_reset;
5742 }
5743#endif /* CONFIG_I40E_DCB */
5744
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005745 /* do basic switch setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00005746 ret = i40e_setup_pf_switch(pf, reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005747 if (ret)
5748 goto end_core_reset;
5749
5750 /* Rebuild the VSIs and VEBs that existed before reset.
5751 * They are still in our local switch element arrays, so only
5752 * need to rebuild the switch model in the HW.
5753 *
5754 * If there were VEBs but the reconstitution failed, we'll try
5755 * try to recover minimal use by getting the basic PF VSI working.
5756 */
5757 if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005758 dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005759 /* find the one VEB connected to the MAC, and find orphans */
5760 for (v = 0; v < I40E_MAX_VEB; v++) {
5761 if (!pf->veb[v])
5762 continue;
5763
5764 if (pf->veb[v]->uplink_seid == pf->mac_seid ||
5765 pf->veb[v]->uplink_seid == 0) {
5766 ret = i40e_reconstitute_veb(pf->veb[v]);
5767
5768 if (!ret)
5769 continue;
5770
5771 /* If Main VEB failed, we're in deep doodoo,
5772 * so give up rebuilding the switch and set up
5773 * for minimal rebuild of PF VSI.
5774 * If orphan failed, we'll report the error
5775 * but try to keep going.
5776 */
5777 if (pf->veb[v]->uplink_seid == pf->mac_seid) {
5778 dev_info(&pf->pdev->dev,
5779 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
5780 ret);
5781 pf->vsi[pf->lan_vsi]->uplink_seid
5782 = pf->mac_seid;
5783 break;
5784 } else if (pf->veb[v]->uplink_seid == 0) {
5785 dev_info(&pf->pdev->dev,
5786 "rebuild of orphan VEB failed: %d\n",
5787 ret);
5788 }
5789 }
5790 }
5791 }
5792
5793 if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
Shannon Nelsoncde4cbc2014-06-04 01:23:17 +00005794 dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005795 /* no VEB, so rebuild only the Main VSI */
5796 ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
5797 if (ret) {
5798 dev_info(&pf->pdev->dev,
5799 "rebuild of Main VSI failed: %d\n", ret);
5800 goto end_core_reset;
5801 }
5802 }
5803
5804 /* reinit the misc interrupt */
5805 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
5806 ret = i40e_setup_misc_vector(pf);
5807
5808 /* restart the VSIs that were rebuilt and running before the reset */
5809 i40e_pf_unquiesce_all_vsi(pf);
5810
Mitch Williams69f64b22014-02-13 03:48:46 -08005811 if (pf->num_alloc_vfs) {
5812 for (v = 0; v < pf->num_alloc_vfs; v++)
5813 i40e_reset_vf(&pf->vf[v], true);
5814 }
5815
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005816 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00005817 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005818
5819end_core_reset:
5820 clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
5821}
5822
5823/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005824 * i40e_handle_reset_warning - prep for the pf to reset, reset and rebuild
5825 * @pf: board private structure
5826 *
5827 * Close up the VFs and other things in prep for a Core Reset,
5828 * then get ready to rebuild the world.
5829 **/
5830static void i40e_handle_reset_warning(struct i40e_pf *pf)
5831{
Shannon Nelson23cfbe02014-06-04 01:23:14 +00005832 i40e_prep_for_reset(pf);
5833 i40e_reset_and_rebuild(pf, false);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005834}
5835
5836/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005837 * i40e_handle_mdd_event
5838 * @pf: pointer to the pf structure
5839 *
5840 * Called from the MDD irq handler to identify possibly malicious vfs
5841 **/
5842static void i40e_handle_mdd_event(struct i40e_pf *pf)
5843{
5844 struct i40e_hw *hw = &pf->hw;
5845 bool mdd_detected = false;
Neerav Parikhdf430b12014-06-04 01:23:15 +00005846 bool pf_mdd_detected = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005847 struct i40e_vf *vf;
5848 u32 reg;
5849 int i;
5850
5851 if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
5852 return;
5853
5854 /* find what triggered the MDD event */
5855 reg = rd32(hw, I40E_GL_MDET_TX);
5856 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00005857 u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
5858 I40E_GL_MDET_TX_PF_NUM_SHIFT;
5859 u8 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
5860 I40E_GL_MDET_TX_VF_NUM_SHIFT;
5861 u8 event = (reg & I40E_GL_MDET_TX_EVENT_SHIFT) >>
5862 I40E_GL_MDET_TX_EVENT_SHIFT;
5863 u8 queue = (reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
5864 I40E_GL_MDET_TX_QUEUE_SHIFT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005865 dev_info(&pf->pdev->dev,
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00005866 "Malicious Driver Detection event 0x%02x on TX queue %d pf number 0x%02x vf number 0x%02x\n",
5867 event, queue, pf_num, vf_num);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005868 wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
5869 mdd_detected = true;
5870 }
5871 reg = rd32(hw, I40E_GL_MDET_RX);
5872 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00005873 u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
5874 I40E_GL_MDET_RX_FUNCTION_SHIFT;
5875 u8 event = (reg & I40E_GL_MDET_RX_EVENT_SHIFT) >>
5876 I40E_GL_MDET_RX_EVENT_SHIFT;
5877 u8 queue = (reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
5878 I40E_GL_MDET_RX_QUEUE_SHIFT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005879 dev_info(&pf->pdev->dev,
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00005880 "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005881 event, queue, func);
5882 wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
5883 mdd_detected = true;
5884 }
5885
Neerav Parikhdf430b12014-06-04 01:23:15 +00005886 if (mdd_detected) {
5887 reg = rd32(hw, I40E_PF_MDET_TX);
5888 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
5889 wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
5890 dev_info(&pf->pdev->dev,
5891 "MDD TX event is for this function 0x%08x, requesting PF reset.\n",
5892 reg);
5893 pf_mdd_detected = true;
5894 }
5895 reg = rd32(hw, I40E_PF_MDET_RX);
5896 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
5897 wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
5898 dev_info(&pf->pdev->dev,
5899 "MDD RX event is for this function 0x%08x, requesting PF reset.\n",
5900 reg);
5901 pf_mdd_detected = true;
5902 }
5903 /* Queue belongs to the PF, initiate a reset */
5904 if (pf_mdd_detected) {
5905 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
5906 i40e_service_event_schedule(pf);
5907 }
5908 }
5909
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005910 /* see if one of the VFs needs its hand slapped */
5911 for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
5912 vf = &(pf->vf[i]);
5913 reg = rd32(hw, I40E_VP_MDET_TX(i));
5914 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
5915 wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
5916 vf->num_mdd_events++;
5917 dev_info(&pf->pdev->dev, "MDD TX event on VF %d\n", i);
5918 }
5919
5920 reg = rd32(hw, I40E_VP_MDET_RX(i));
5921 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
5922 wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
5923 vf->num_mdd_events++;
5924 dev_info(&pf->pdev->dev, "MDD RX event on VF %d\n", i);
5925 }
5926
5927 if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
5928 dev_info(&pf->pdev->dev,
5929 "Too many MDD events on VF %d, disabled\n", i);
5930 dev_info(&pf->pdev->dev,
5931 "Use PF Control I/F to re-enable the VF\n");
5932 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
5933 }
5934 }
5935
5936 /* re-enable mdd interrupt cause */
5937 clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
5938 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
5939 reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
5940 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
5941 i40e_flush(hw);
5942}
5943
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00005944#ifdef CONFIG_I40E_VXLAN
5945/**
5946 * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW
5947 * @pf: board private structure
5948 **/
5949static void i40e_sync_vxlan_filters_subtask(struct i40e_pf *pf)
5950{
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00005951 struct i40e_hw *hw = &pf->hw;
5952 i40e_status ret;
5953 u8 filter_index;
5954 __be16 port;
5955 int i;
5956
5957 if (!(pf->flags & I40E_FLAG_VXLAN_FILTER_SYNC))
5958 return;
5959
5960 pf->flags &= ~I40E_FLAG_VXLAN_FILTER_SYNC;
5961
5962 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
5963 if (pf->pending_vxlan_bitmap & (1 << i)) {
5964 pf->pending_vxlan_bitmap &= ~(1 << i);
5965 port = pf->vxlan_ports[i];
5966 ret = port ?
5967 i40e_aq_add_udp_tunnel(hw, ntohs(port),
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00005968 I40E_AQC_TUNNEL_TYPE_VXLAN,
5969 &filter_index, NULL)
5970 : i40e_aq_del_udp_tunnel(hw, i, NULL);
5971
5972 if (ret) {
5973 dev_info(&pf->pdev->dev, "Failed to execute AQ command for %s port %d with index %d\n",
5974 port ? "adding" : "deleting",
5975 ntohs(port), port ? i : i);
5976
5977 pf->vxlan_ports[i] = 0;
5978 } else {
5979 dev_info(&pf->pdev->dev, "%s port %d with AQ command with index %d\n",
5980 port ? "Added" : "Deleted",
5981 ntohs(port), port ? i : filter_index);
5982 }
5983 }
5984 }
5985}
5986
5987#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005988/**
5989 * i40e_service_task - Run the driver's async subtasks
5990 * @work: pointer to work_struct containing our data
5991 **/
5992static void i40e_service_task(struct work_struct *work)
5993{
5994 struct i40e_pf *pf = container_of(work,
5995 struct i40e_pf,
5996 service_task);
5997 unsigned long start_time = jiffies;
5998
Shannon Nelsone57a2fe2014-06-03 23:50:19 +00005999 /* don't bother with service tasks if a reset is in progress */
6000 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
6001 i40e_service_event_complete(pf);
6002 return;
6003 }
6004
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006005 i40e_reset_subtask(pf);
6006 i40e_handle_mdd_event(pf);
6007 i40e_vc_process_vflr_event(pf);
6008 i40e_watchdog_subtask(pf);
6009 i40e_fdir_reinit_subtask(pf);
6010 i40e_check_hang_subtask(pf);
6011 i40e_sync_filters_subtask(pf);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00006012#ifdef CONFIG_I40E_VXLAN
6013 i40e_sync_vxlan_filters_subtask(pf);
6014#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006015 i40e_clean_adminq_subtask(pf);
6016
6017 i40e_service_event_complete(pf);
6018
6019 /* If the tasks have taken longer than one timer cycle or there
6020 * is more work to be done, reschedule the service task now
6021 * rather than wait for the timer to tick again.
6022 */
6023 if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
6024 test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
6025 test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
6026 test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
6027 i40e_service_event_schedule(pf);
6028}
6029
6030/**
6031 * i40e_service_timer - timer callback
6032 * @data: pointer to PF struct
6033 **/
6034static void i40e_service_timer(unsigned long data)
6035{
6036 struct i40e_pf *pf = (struct i40e_pf *)data;
6037
6038 mod_timer(&pf->service_timer,
6039 round_jiffies(jiffies + pf->service_timer_period));
6040 i40e_service_event_schedule(pf);
6041}
6042
6043/**
6044 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
6045 * @vsi: the VSI being configured
6046 **/
6047static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
6048{
6049 struct i40e_pf *pf = vsi->back;
6050
6051 switch (vsi->type) {
6052 case I40E_VSI_MAIN:
6053 vsi->alloc_queue_pairs = pf->num_lan_qps;
6054 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
6055 I40E_REQ_DESCRIPTOR_MULTIPLE);
6056 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
6057 vsi->num_q_vectors = pf->num_lan_msix;
6058 else
6059 vsi->num_q_vectors = 1;
6060
6061 break;
6062
6063 case I40E_VSI_FDIR:
6064 vsi->alloc_queue_pairs = 1;
6065 vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
6066 I40E_REQ_DESCRIPTOR_MULTIPLE);
6067 vsi->num_q_vectors = 1;
6068 break;
6069
6070 case I40E_VSI_VMDQ2:
6071 vsi->alloc_queue_pairs = pf->num_vmdq_qps;
6072 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
6073 I40E_REQ_DESCRIPTOR_MULTIPLE);
6074 vsi->num_q_vectors = pf->num_vmdq_msix;
6075 break;
6076
6077 case I40E_VSI_SRIOV:
6078 vsi->alloc_queue_pairs = pf->num_vf_qps;
6079 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
6080 I40E_REQ_DESCRIPTOR_MULTIPLE);
6081 break;
6082
6083 default:
6084 WARN_ON(1);
6085 return -ENODATA;
6086 }
6087
6088 return 0;
6089}
6090
6091/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006092 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
6093 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006094 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006095 *
6096 * On error: returns error code (negative)
6097 * On success: returns 0
6098 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006099static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006100{
6101 int size;
6102 int ret = 0;
6103
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00006104 /* allocate memory for both Tx and Rx ring pointers */
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006105 size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
6106 vsi->tx_rings = kzalloc(size, GFP_KERNEL);
6107 if (!vsi->tx_rings)
6108 return -ENOMEM;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006109 vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
6110
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006111 if (alloc_qvectors) {
6112 /* allocate memory for q_vector pointers */
6113 size = sizeof(struct i40e_q_vectors *) * vsi->num_q_vectors;
6114 vsi->q_vectors = kzalloc(size, GFP_KERNEL);
6115 if (!vsi->q_vectors) {
6116 ret = -ENOMEM;
6117 goto err_vectors;
6118 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006119 }
6120 return ret;
6121
6122err_vectors:
6123 kfree(vsi->tx_rings);
6124 return ret;
6125}
6126
6127/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006128 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
6129 * @pf: board private structure
6130 * @type: type of VSI
6131 *
6132 * On error: returns error code (negative)
6133 * On success: returns vsi index in PF (positive)
6134 **/
6135static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
6136{
6137 int ret = -ENODEV;
6138 struct i40e_vsi *vsi;
6139 int vsi_idx;
6140 int i;
6141
6142 /* Need to protect the allocation of the VSIs at the PF level */
6143 mutex_lock(&pf->switch_mutex);
6144
6145 /* VSI list may be fragmented if VSI creation/destruction has
6146 * been happening. We can afford to do a quick scan to look
6147 * for any free VSIs in the list.
6148 *
6149 * find next empty vsi slot, looping back around if necessary
6150 */
6151 i = pf->next_vsi;
Mitch Williams505682c2014-05-20 08:01:37 +00006152 while (i < pf->num_alloc_vsi && pf->vsi[i])
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006153 i++;
Mitch Williams505682c2014-05-20 08:01:37 +00006154 if (i >= pf->num_alloc_vsi) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006155 i = 0;
6156 while (i < pf->next_vsi && pf->vsi[i])
6157 i++;
6158 }
6159
Mitch Williams505682c2014-05-20 08:01:37 +00006160 if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006161 vsi_idx = i; /* Found one! */
6162 } else {
6163 ret = -ENODEV;
Alexander Duyck493fb302013-09-28 07:01:44 +00006164 goto unlock_pf; /* out of VSI slots! */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006165 }
6166 pf->next_vsi = ++i;
6167
6168 vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
6169 if (!vsi) {
6170 ret = -ENOMEM;
Alexander Duyck493fb302013-09-28 07:01:44 +00006171 goto unlock_pf;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006172 }
6173 vsi->type = type;
6174 vsi->back = pf;
6175 set_bit(__I40E_DOWN, &vsi->state);
6176 vsi->flags = 0;
6177 vsi->idx = vsi_idx;
6178 vsi->rx_itr_setting = pf->rx_itr_default;
6179 vsi->tx_itr_setting = pf->tx_itr_default;
6180 vsi->netdev_registered = false;
6181 vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
6182 INIT_LIST_HEAD(&vsi->mac_filter_list);
Shannon Nelson63741842014-04-23 04:50:16 +00006183 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006184
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006185 ret = i40e_set_num_rings_in_vsi(vsi);
6186 if (ret)
6187 goto err_rings;
6188
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006189 ret = i40e_vsi_alloc_arrays(vsi, true);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006190 if (ret)
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006191 goto err_rings;
Alexander Duyck493fb302013-09-28 07:01:44 +00006192
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006193 /* Setup default MSIX irq handler for VSI */
6194 i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
6195
6196 pf->vsi[vsi_idx] = vsi;
6197 ret = vsi_idx;
Alexander Duyck493fb302013-09-28 07:01:44 +00006198 goto unlock_pf;
6199
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006200err_rings:
Alexander Duyck493fb302013-09-28 07:01:44 +00006201 pf->next_vsi = i - 1;
6202 kfree(vsi);
6203unlock_pf:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006204 mutex_unlock(&pf->switch_mutex);
6205 return ret;
6206}
6207
6208/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006209 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
6210 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006211 * @free_qvectors: a bool to specify if q_vectors need to be freed.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006212 *
6213 * On error: returns error code (negative)
6214 * On success: returns 0
6215 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006216static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006217{
6218 /* free the ring and vector containers */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006219 if (free_qvectors) {
6220 kfree(vsi->q_vectors);
6221 vsi->q_vectors = NULL;
6222 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006223 kfree(vsi->tx_rings);
6224 vsi->tx_rings = NULL;
6225 vsi->rx_rings = NULL;
6226}
6227
6228/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006229 * i40e_vsi_clear - Deallocate the VSI provided
6230 * @vsi: the VSI being un-configured
6231 **/
6232static int i40e_vsi_clear(struct i40e_vsi *vsi)
6233{
6234 struct i40e_pf *pf;
6235
6236 if (!vsi)
6237 return 0;
6238
6239 if (!vsi->back)
6240 goto free_vsi;
6241 pf = vsi->back;
6242
6243 mutex_lock(&pf->switch_mutex);
6244 if (!pf->vsi[vsi->idx]) {
6245 dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
6246 vsi->idx, vsi->idx, vsi, vsi->type);
6247 goto unlock_vsi;
6248 }
6249
6250 if (pf->vsi[vsi->idx] != vsi) {
6251 dev_err(&pf->pdev->dev,
6252 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
6253 pf->vsi[vsi->idx]->idx,
6254 pf->vsi[vsi->idx],
6255 pf->vsi[vsi->idx]->type,
6256 vsi->idx, vsi, vsi->type);
6257 goto unlock_vsi;
6258 }
6259
6260 /* updates the pf for this cleared vsi */
6261 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
6262 i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
6263
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006264 i40e_vsi_free_arrays(vsi, true);
Alexander Duyck493fb302013-09-28 07:01:44 +00006265
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006266 pf->vsi[vsi->idx] = NULL;
6267 if (vsi->idx < pf->next_vsi)
6268 pf->next_vsi = vsi->idx;
6269
6270unlock_vsi:
6271 mutex_unlock(&pf->switch_mutex);
6272free_vsi:
6273 kfree(vsi);
6274
6275 return 0;
6276}
6277
6278/**
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006279 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
6280 * @vsi: the VSI being cleaned
6281 **/
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00006282static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006283{
6284 int i;
6285
Greg Rose8e9dca52013-12-18 13:45:53 +00006286 if (vsi->tx_rings && vsi->tx_rings[0]) {
Neerav Parikhd7397642013-11-28 06:39:37 +00006287 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Mitch Williams00403f02013-09-28 07:13:13 +00006288 kfree_rcu(vsi->tx_rings[i], rcu);
6289 vsi->tx_rings[i] = NULL;
6290 vsi->rx_rings[i] = NULL;
6291 }
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00006292 }
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006293}
6294
6295/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006296 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
6297 * @vsi: the VSI being configured
6298 **/
6299static int i40e_alloc_rings(struct i40e_vsi *vsi)
6300{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00006301 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006302 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006303 int i;
6304
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006305 /* Set basic values in the rings to be used later during open() */
Neerav Parikhd7397642013-11-28 06:39:37 +00006306 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00006307 /* allocate space for both Tx and Rx in one shot */
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006308 tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
6309 if (!tx_ring)
6310 goto err_out;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006311
6312 tx_ring->queue_index = i;
6313 tx_ring->reg_idx = vsi->base_queue + i;
6314 tx_ring->ring_active = false;
6315 tx_ring->vsi = vsi;
6316 tx_ring->netdev = vsi->netdev;
6317 tx_ring->dev = &pf->pdev->dev;
6318 tx_ring->count = vsi->num_desc;
6319 tx_ring->size = 0;
6320 tx_ring->dcb_tc = 0;
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006321 vsi->tx_rings[i] = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006322
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006323 rx_ring = &tx_ring[1];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006324 rx_ring->queue_index = i;
6325 rx_ring->reg_idx = vsi->base_queue + i;
6326 rx_ring->ring_active = false;
6327 rx_ring->vsi = vsi;
6328 rx_ring->netdev = vsi->netdev;
6329 rx_ring->dev = &pf->pdev->dev;
6330 rx_ring->count = vsi->num_desc;
6331 rx_ring->size = 0;
6332 rx_ring->dcb_tc = 0;
6333 if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED)
6334 set_ring_16byte_desc_enabled(rx_ring);
6335 else
6336 clear_ring_16byte_desc_enabled(rx_ring);
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006337 vsi->rx_rings[i] = rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006338 }
6339
6340 return 0;
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006341
6342err_out:
6343 i40e_vsi_clear_rings(vsi);
6344 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006345}
6346
6347/**
6348 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
6349 * @pf: board private structure
6350 * @vectors: the number of MSI-X vectors to request
6351 *
6352 * Returns the number of vectors reserved, or error
6353 **/
6354static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
6355{
Alexander Gordeev7b37f372014-02-18 11:11:42 +01006356 vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
6357 I40E_MIN_MSIX, vectors);
6358 if (vectors < 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006359 dev_info(&pf->pdev->dev,
Alexander Gordeev7b37f372014-02-18 11:11:42 +01006360 "MSI-X vector reservation failed: %d\n", vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006361 vectors = 0;
6362 }
6363
6364 return vectors;
6365}
6366
6367/**
6368 * i40e_init_msix - Setup the MSIX capability
6369 * @pf: board private structure
6370 *
6371 * Work with the OS to set up the MSIX vectors needed.
6372 *
6373 * Returns 0 on success, negative on failure
6374 **/
6375static int i40e_init_msix(struct i40e_pf *pf)
6376{
6377 i40e_status err = 0;
6378 struct i40e_hw *hw = &pf->hw;
6379 int v_budget, i;
6380 int vec;
6381
6382 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
6383 return -ENODEV;
6384
6385 /* The number of vectors we'll request will be comprised of:
6386 * - Add 1 for "other" cause for Admin Queue events, etc.
6387 * - The number of LAN queue pairs
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00006388 * - Queues being used for RSS.
6389 * We don't need as many as max_rss_size vectors.
6390 * use rss_size instead in the calculation since that
6391 * is governed by number of cpus in the system.
6392 * - assumes symmetric Tx/Rx pairing
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006393 * - The number of VMDq pairs
6394 * Once we count this up, try the request.
6395 *
6396 * If we can't get what we want, we'll simplify to nearly nothing
6397 * and try again. If that still fails, we punt.
6398 */
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00006399 pf->num_lan_msix = pf->num_lan_qps - (pf->rss_size_max - pf->rss_size);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006400 pf->num_vmdq_msix = pf->num_vmdq_qps;
6401 v_budget = 1 + pf->num_lan_msix;
6402 v_budget += (pf->num_vmdq_vsis * pf->num_vmdq_msix);
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08006403 if (pf->flags & I40E_FLAG_FD_SB_ENABLED)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006404 v_budget++;
6405
6406 /* Scale down if necessary, and the rings will share vectors */
6407 v_budget = min_t(int, v_budget, hw->func_caps.num_msix_vectors);
6408
6409 pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
6410 GFP_KERNEL);
6411 if (!pf->msix_entries)
6412 return -ENOMEM;
6413
6414 for (i = 0; i < v_budget; i++)
6415 pf->msix_entries[i].entry = i;
6416 vec = i40e_reserve_msix_vectors(pf, v_budget);
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00006417
6418 if (vec != v_budget) {
6419 /* If we have limited resources, we will start with no vectors
6420 * for the special features and then allocate vectors to some
6421 * of these features based on the policy and at the end disable
6422 * the features that did not get any vectors.
6423 */
6424 pf->num_vmdq_msix = 0;
6425 }
6426
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006427 if (vec < I40E_MIN_MSIX) {
6428 pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
6429 kfree(pf->msix_entries);
6430 pf->msix_entries = NULL;
6431 return -ENODEV;
6432
6433 } else if (vec == I40E_MIN_MSIX) {
6434 /* Adjust for minimal MSIX use */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006435 pf->num_vmdq_vsis = 0;
6436 pf->num_vmdq_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006437 pf->num_lan_qps = 1;
6438 pf->num_lan_msix = 1;
6439
6440 } else if (vec != v_budget) {
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00006441 /* reserve the misc vector */
6442 vec--;
6443
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006444 /* Scale vector usage down */
6445 pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00006446 pf->num_vmdq_vsis = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006447
6448 /* partition out the remaining vectors */
6449 switch (vec) {
6450 case 2:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006451 pf->num_lan_msix = 1;
6452 break;
6453 case 3:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006454 pf->num_lan_msix = 2;
6455 break;
6456 default:
6457 pf->num_lan_msix = min_t(int, (vec / 2),
6458 pf->num_lan_qps);
6459 pf->num_vmdq_vsis = min_t(int, (vec - pf->num_lan_msix),
6460 I40E_DEFAULT_NUM_VMDQ_VSI);
6461 break;
6462 }
6463 }
6464
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00006465 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
6466 (pf->num_vmdq_msix == 0)) {
6467 dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
6468 pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
6469 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006470 return err;
6471}
6472
6473/**
Greg Rose90e04072014-03-06 08:59:57 +00006474 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
Alexander Duyck493fb302013-09-28 07:01:44 +00006475 * @vsi: the VSI being configured
6476 * @v_idx: index of the vector in the vsi struct
6477 *
6478 * We allocate one q_vector. If allocation fails we return -ENOMEM.
6479 **/
Greg Rose90e04072014-03-06 08:59:57 +00006480static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx)
Alexander Duyck493fb302013-09-28 07:01:44 +00006481{
6482 struct i40e_q_vector *q_vector;
6483
6484 /* allocate q_vector */
6485 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
6486 if (!q_vector)
6487 return -ENOMEM;
6488
6489 q_vector->vsi = vsi;
6490 q_vector->v_idx = v_idx;
6491 cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
6492 if (vsi->netdev)
6493 netif_napi_add(vsi->netdev, &q_vector->napi,
Jesse Brandeburgeefeace2014-05-10 04:49:13 +00006494 i40e_napi_poll, NAPI_POLL_WEIGHT);
Alexander Duyck493fb302013-09-28 07:01:44 +00006495
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00006496 q_vector->rx.latency_range = I40E_LOW_LATENCY;
6497 q_vector->tx.latency_range = I40E_LOW_LATENCY;
6498
Alexander Duyck493fb302013-09-28 07:01:44 +00006499 /* tie q_vector and vsi together */
6500 vsi->q_vectors[v_idx] = q_vector;
6501
6502 return 0;
6503}
6504
6505/**
Greg Rose90e04072014-03-06 08:59:57 +00006506 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006507 * @vsi: the VSI being configured
6508 *
6509 * We allocate one q_vector per queue interrupt. If allocation fails we
6510 * return -ENOMEM.
6511 **/
Greg Rose90e04072014-03-06 08:59:57 +00006512static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006513{
6514 struct i40e_pf *pf = vsi->back;
6515 int v_idx, num_q_vectors;
Alexander Duyck493fb302013-09-28 07:01:44 +00006516 int err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006517
6518 /* if not MSIX, give the one vector only to the LAN VSI */
6519 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
6520 num_q_vectors = vsi->num_q_vectors;
6521 else if (vsi == pf->vsi[pf->lan_vsi])
6522 num_q_vectors = 1;
6523 else
6524 return -EINVAL;
6525
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006526 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
Greg Rose90e04072014-03-06 08:59:57 +00006527 err = i40e_vsi_alloc_q_vector(vsi, v_idx);
Alexander Duyck493fb302013-09-28 07:01:44 +00006528 if (err)
6529 goto err_out;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006530 }
6531
6532 return 0;
Alexander Duyck493fb302013-09-28 07:01:44 +00006533
6534err_out:
6535 while (v_idx--)
6536 i40e_free_q_vector(vsi, v_idx);
6537
6538 return err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006539}
6540
6541/**
6542 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
6543 * @pf: board private structure to initialize
6544 **/
6545static void i40e_init_interrupt_scheme(struct i40e_pf *pf)
6546{
6547 int err = 0;
6548
6549 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
6550 err = i40e_init_msix(pf);
6551 if (err) {
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08006552 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
6553 I40E_FLAG_RSS_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00006554 I40E_FLAG_DCB_CAPABLE |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08006555 I40E_FLAG_SRIOV_ENABLED |
6556 I40E_FLAG_FD_SB_ENABLED |
6557 I40E_FLAG_FD_ATR_ENABLED |
6558 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006559
6560 /* rework the queue expectations without MSIX */
6561 i40e_determine_queue_usage(pf);
6562 }
6563 }
6564
6565 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
6566 (pf->flags & I40E_FLAG_MSI_ENABLED)) {
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08006567 dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006568 err = pci_enable_msi(pf->pdev);
6569 if (err) {
Shannon Nelson958a3e32013-09-28 07:13:28 +00006570 dev_info(&pf->pdev->dev, "MSI init failed - %d\n", err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006571 pf->flags &= ~I40E_FLAG_MSI_ENABLED;
6572 }
6573 }
6574
Shannon Nelson958a3e32013-09-28 07:13:28 +00006575 if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08006576 dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
Shannon Nelson958a3e32013-09-28 07:13:28 +00006577
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006578 /* track first vector for misc interrupts */
6579 err = i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT-1);
6580}
6581
6582/**
6583 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
6584 * @pf: board private structure
6585 *
6586 * This sets up the handler for MSIX 0, which is used to manage the
6587 * non-queue interrupts, e.g. AdminQ and errors. This is not used
6588 * when in MSI or Legacy interrupt mode.
6589 **/
6590static int i40e_setup_misc_vector(struct i40e_pf *pf)
6591{
6592 struct i40e_hw *hw = &pf->hw;
6593 int err = 0;
6594
6595 /* Only request the irq if this is the first time through, and
6596 * not when we're rebuilding after a Reset
6597 */
6598 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
6599 err = request_irq(pf->msix_entries[0].vector,
6600 i40e_intr, 0, pf->misc_int_name, pf);
6601 if (err) {
6602 dev_info(&pf->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08006603 "request_irq for %s failed: %d\n",
6604 pf->misc_int_name, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006605 return -EFAULT;
6606 }
6607 }
6608
6609 i40e_enable_misc_int_causes(hw);
6610
6611 /* associate no queues to the misc vector */
6612 wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
6613 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
6614
6615 i40e_flush(hw);
6616
6617 i40e_irq_dynamic_enable_icr0(pf);
6618
6619 return err;
6620}
6621
6622/**
6623 * i40e_config_rss - Prepare for RSS if used
6624 * @pf: board private structure
6625 **/
6626static int i40e_config_rss(struct i40e_pf *pf)
6627{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006628 /* Set of random keys generated using kernel random number generator */
6629 static const u32 seed[I40E_PFQF_HKEY_MAX_INDEX + 1] = {0x41b01687,
6630 0x183cfd8c, 0xce880440, 0x580cbc3c, 0x35897377,
6631 0x328b25e1, 0x4fa98922, 0xb7d90c14, 0xd5bad70d,
6632 0xcd15a2c1, 0xe8580225, 0x4a1e9d11, 0xfe5731be};
Anjali Singhai Jain4617e8c2013-11-20 10:02:56 +00006633 struct i40e_hw *hw = &pf->hw;
6634 u32 lut = 0;
6635 int i, j;
6636 u64 hena;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00006637 u32 reg_val;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006638
6639 /* Fill out hash function seed */
6640 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
6641 wr32(hw, I40E_PFQF_HKEY(i), seed[i]);
6642
6643 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
6644 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
6645 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
Mitch Williams12dc4fe2013-11-28 06:39:32 +00006646 hena |= I40E_DEFAULT_RSS_HENA;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006647 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
6648 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
6649
Carolyn Wybornye157ea32014-06-03 23:50:22 +00006650 /* Check capability and Set table size and register per hw expectation*/
6651 reg_val = rd32(hw, I40E_PFQF_CTL_0);
6652 if (hw->func_caps.rss_table_size == 512) {
6653 reg_val |= I40E_PFQF_CTL_0_HASHLUTSIZE_512;
6654 pf->rss_table_size = 512;
6655 } else {
6656 pf->rss_table_size = 128;
6657 reg_val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_512;
6658 }
6659 wr32(hw, I40E_PFQF_CTL_0, reg_val);
6660
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006661 /* Populate the LUT with max no. of queues in round robin fashion */
Carolyn Wybornye157ea32014-06-03 23:50:22 +00006662 for (i = 0, j = 0; i < pf->rss_table_size; i++, j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006663
6664 /* The assumption is that lan qp count will be the highest
6665 * qp count for any PF VSI that needs RSS.
6666 * If multiple VSIs need RSS support, all the qp counts
6667 * for those VSIs should be a power of 2 for RSS to work.
6668 * If LAN VSI is the only consumer for RSS then this requirement
6669 * is not necessary.
6670 */
6671 if (j == pf->rss_size)
6672 j = 0;
6673 /* lut = 4-byte sliding window of 4 lut entries */
6674 lut = (lut << 8) | (j &
6675 ((0x1 << pf->hw.func_caps.rss_table_entry_width) - 1));
6676 /* On i = 3, we have 4 entries in lut; write to the register */
6677 if ((i & 3) == 3)
6678 wr32(hw, I40E_PFQF_HLUT(i >> 2), lut);
6679 }
6680 i40e_flush(hw);
6681
6682 return 0;
6683}
6684
6685/**
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00006686 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
6687 * @pf: board private structure
6688 * @queue_count: the requested queue count for rss.
6689 *
6690 * returns 0 if rss is not enabled, if enabled returns the final rss queue
6691 * count which may be different from the requested queue count.
6692 **/
6693int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
6694{
6695 if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
6696 return 0;
6697
6698 queue_count = min_t(int, queue_count, pf->rss_size_max);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00006699
6700 if (queue_count != pf->rss_size) {
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00006701 i40e_prep_for_reset(pf);
6702
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00006703 pf->rss_size = queue_count;
6704
6705 i40e_reset_and_rebuild(pf, true);
6706 i40e_config_rss(pf);
6707 }
6708 dev_info(&pf->pdev->dev, "RSS count: %d\n", pf->rss_size);
6709 return pf->rss_size;
6710}
6711
6712/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006713 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
6714 * @pf: board private structure to initialize
6715 *
6716 * i40e_sw_init initializes the Adapter private data structure.
6717 * Fields are initialized based on PCI device information and
6718 * OS network device settings (MTU size).
6719 **/
6720static int i40e_sw_init(struct i40e_pf *pf)
6721{
6722 int err = 0;
6723 int size;
6724
6725 pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE,
6726 (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK));
Shannon Nelson27599972013-11-16 10:00:43 +00006727 pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006728 if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) {
6729 if (I40E_DEBUG_USER & debug)
6730 pf->hw.debug_mask = debug;
6731 pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER),
6732 I40E_DEFAULT_MSG_ENABLE);
6733 }
6734
6735 /* Set default capability flags */
6736 pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
6737 I40E_FLAG_MSI_ENABLED |
6738 I40E_FLAG_MSIX_ENABLED |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006739 I40E_FLAG_RX_1BUF_ENABLED;
6740
Mitch Williamsca99eb92014-04-04 04:43:07 +00006741 /* Set default ITR */
6742 pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
6743 pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
6744
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00006745 /* Depending on PF configurations, it is possible that the RSS
6746 * maximum might end up larger than the available queues
6747 */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006748 pf->rss_size_max = 0x1 << pf->hw.func_caps.rss_table_entry_width;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00006749 pf->rss_size_max = min_t(int, pf->rss_size_max,
6750 pf->hw.func_caps.num_tx_qp);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006751 if (pf->hw.func_caps.rss) {
6752 pf->flags |= I40E_FLAG_RSS_ENABLED;
Jesse Brandeburgbf051a32013-11-26 10:49:17 +00006753 pf->rss_size = min_t(int, pf->rss_size_max, num_online_cpus());
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006754 } else {
6755 pf->rss_size = 1;
6756 }
6757
Catherine Sullivan2050bc62013-12-18 13:46:03 +00006758 /* MFP mode enabled */
6759 if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.mfp_mode_1) {
6760 pf->flags |= I40E_FLAG_MFP_ENABLED;
6761 dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
6762 }
6763
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006764 /* FW/NVM is not yet fixed in this regard */
6765 if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
6766 (pf->hw.func_caps.fd_filters_best_effort > 0)) {
6767 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
6768 pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00006769 /* Setup a counter for fd_atr per pf */
6770 pf->fd_atr_cnt_idx = I40E_FD_ATR_STAT_IDX(pf->hw.pf_id);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006771 if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) {
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08006772 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00006773 /* Setup a counter for fd_sb per pf */
6774 pf->fd_sb_cnt_idx = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006775 } else {
6776 dev_info(&pf->pdev->dev,
Anjali Singhai Jain0b675842014-03-06 08:59:51 +00006777 "Flow Director Sideband mode Disabled in MFP mode\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006778 }
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006779 pf->fdir_pf_filter_count =
6780 pf->hw.func_caps.fd_filters_guaranteed;
6781 pf->hw.fdir_shared_filter_count =
6782 pf->hw.func_caps.fd_filters_best_effort;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006783 }
6784
6785 if (pf->hw.func_caps.vmdq) {
6786 pf->flags |= I40E_FLAG_VMDQ_ENABLED;
6787 pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
6788 pf->num_vmdq_qps = I40E_DEFAULT_QUEUES_PER_VMDQ;
6789 }
6790
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006791#ifdef CONFIG_PCI_IOV
6792 if (pf->hw.func_caps.num_vfs) {
6793 pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
6794 pf->flags |= I40E_FLAG_SRIOV_ENABLED;
6795 pf->num_req_vfs = min_t(int,
6796 pf->hw.func_caps.num_vfs,
6797 I40E_MAX_VF_COUNT);
6798 }
6799#endif /* CONFIG_PCI_IOV */
6800 pf->eeprom_version = 0xDEAD;
6801 pf->lan_veb = I40E_NO_VEB;
6802 pf->lan_vsi = I40E_NO_VSI;
6803
6804 /* set up queue assignment tracking */
6805 size = sizeof(struct i40e_lump_tracking)
6806 + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
6807 pf->qp_pile = kzalloc(size, GFP_KERNEL);
6808 if (!pf->qp_pile) {
6809 err = -ENOMEM;
6810 goto sw_init_done;
6811 }
6812 pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
6813 pf->qp_pile->search_hint = 0;
6814
6815 /* set up vector assignment tracking */
6816 size = sizeof(struct i40e_lump_tracking)
6817 + (sizeof(u16) * pf->hw.func_caps.num_msix_vectors);
6818 pf->irq_pile = kzalloc(size, GFP_KERNEL);
6819 if (!pf->irq_pile) {
6820 kfree(pf->qp_pile);
6821 err = -ENOMEM;
6822 goto sw_init_done;
6823 }
6824 pf->irq_pile->num_entries = pf->hw.func_caps.num_msix_vectors;
6825 pf->irq_pile->search_hint = 0;
6826
6827 mutex_init(&pf->switch_mutex);
6828
6829sw_init_done:
6830 return err;
6831}
6832
6833/**
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00006834 * i40e_set_ntuple - set the ntuple feature flag and take action
6835 * @pf: board private structure to initialize
6836 * @features: the feature set that the stack is suggesting
6837 *
6838 * returns a bool to indicate if reset needs to happen
6839 **/
6840bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
6841{
6842 bool need_reset = false;
6843
6844 /* Check if Flow Director n-tuple support was enabled or disabled. If
6845 * the state changed, we need to reset.
6846 */
6847 if (features & NETIF_F_NTUPLE) {
6848 /* Enable filters and mark for reset */
6849 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
6850 need_reset = true;
6851 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
6852 } else {
6853 /* turn off filters, mark for reset and clear SW filter list */
6854 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
6855 need_reset = true;
6856 i40e_fdir_filter_exit(pf);
6857 }
6858 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
6859 /* if ATR was disabled it can be re-enabled. */
6860 if (!(pf->flags & I40E_FLAG_FD_ATR_ENABLED))
6861 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
6862 }
6863 return need_reset;
6864}
6865
6866/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006867 * i40e_set_features - set the netdev feature flags
6868 * @netdev: ptr to the netdev being adjusted
6869 * @features: the feature set that the stack is suggesting
6870 **/
6871static int i40e_set_features(struct net_device *netdev,
6872 netdev_features_t features)
6873{
6874 struct i40e_netdev_priv *np = netdev_priv(netdev);
6875 struct i40e_vsi *vsi = np->vsi;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00006876 struct i40e_pf *pf = vsi->back;
6877 bool need_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006878
6879 if (features & NETIF_F_HW_VLAN_CTAG_RX)
6880 i40e_vlan_stripping_enable(vsi);
6881 else
6882 i40e_vlan_stripping_disable(vsi);
6883
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00006884 need_reset = i40e_set_ntuple(pf, features);
6885
6886 if (need_reset)
6887 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
6888
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006889 return 0;
6890}
6891
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00006892#ifdef CONFIG_I40E_VXLAN
6893/**
6894 * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port
6895 * @pf: board private structure
6896 * @port: The UDP port to look up
6897 *
6898 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
6899 **/
6900static u8 i40e_get_vxlan_port_idx(struct i40e_pf *pf, __be16 port)
6901{
6902 u8 i;
6903
6904 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
6905 if (pf->vxlan_ports[i] == port)
6906 return i;
6907 }
6908
6909 return i;
6910}
6911
6912/**
6913 * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
6914 * @netdev: This physical port's netdev
6915 * @sa_family: Socket Family that VXLAN is notifying us about
6916 * @port: New UDP port number that VXLAN started listening to
6917 **/
6918static void i40e_add_vxlan_port(struct net_device *netdev,
6919 sa_family_t sa_family, __be16 port)
6920{
6921 struct i40e_netdev_priv *np = netdev_priv(netdev);
6922 struct i40e_vsi *vsi = np->vsi;
6923 struct i40e_pf *pf = vsi->back;
6924 u8 next_idx;
6925 u8 idx;
6926
6927 if (sa_family == AF_INET6)
6928 return;
6929
6930 idx = i40e_get_vxlan_port_idx(pf, port);
6931
6932 /* Check if port already exists */
6933 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
6934 netdev_info(netdev, "Port %d already offloaded\n", ntohs(port));
6935 return;
6936 }
6937
6938 /* Now check if there is space to add the new port */
6939 next_idx = i40e_get_vxlan_port_idx(pf, 0);
6940
6941 if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
6942 netdev_info(netdev, "Maximum number of UDP ports reached, not adding port %d\n",
6943 ntohs(port));
6944 return;
6945 }
6946
6947 /* New port: add it and mark its index in the bitmap */
6948 pf->vxlan_ports[next_idx] = port;
6949 pf->pending_vxlan_bitmap |= (1 << next_idx);
6950
6951 pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC;
6952}
6953
6954/**
6955 * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
6956 * @netdev: This physical port's netdev
6957 * @sa_family: Socket Family that VXLAN is notifying us about
6958 * @port: UDP port number that VXLAN stopped listening to
6959 **/
6960static void i40e_del_vxlan_port(struct net_device *netdev,
6961 sa_family_t sa_family, __be16 port)
6962{
6963 struct i40e_netdev_priv *np = netdev_priv(netdev);
6964 struct i40e_vsi *vsi = np->vsi;
6965 struct i40e_pf *pf = vsi->back;
6966 u8 idx;
6967
6968 if (sa_family == AF_INET6)
6969 return;
6970
6971 idx = i40e_get_vxlan_port_idx(pf, port);
6972
6973 /* Check if port already exists */
6974 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
6975 /* if port exists, set it to 0 (mark for deletion)
6976 * and make it pending
6977 */
6978 pf->vxlan_ports[idx] = 0;
6979
6980 pf->pending_vxlan_bitmap |= (1 << idx);
6981
6982 pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC;
6983 } else {
6984 netdev_warn(netdev, "Port %d was not found, not deleting\n",
6985 ntohs(port));
6986 }
6987}
6988
6989#endif
Greg Rose4ba0dea2014-03-06 08:59:55 +00006990#ifdef HAVE_FDB_OPS
6991#ifdef USE_CONST_DEV_UC_CHAR
6992static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
6993 struct net_device *dev,
6994 const unsigned char *addr,
6995 u16 flags)
6996#else
6997static int i40e_ndo_fdb_add(struct ndmsg *ndm,
6998 struct net_device *dev,
6999 unsigned char *addr,
7000 u16 flags)
7001#endif
7002{
7003 struct i40e_netdev_priv *np = netdev_priv(dev);
7004 struct i40e_pf *pf = np->vsi->back;
7005 int err = 0;
7006
7007 if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
7008 return -EOPNOTSUPP;
7009
7010 /* Hardware does not support aging addresses so if a
7011 * ndm_state is given only allow permanent addresses
7012 */
7013 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
7014 netdev_info(dev, "FDB only supports static addresses\n");
7015 return -EINVAL;
7016 }
7017
7018 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
7019 err = dev_uc_add_excl(dev, addr);
7020 else if (is_multicast_ether_addr(addr))
7021 err = dev_mc_add_excl(dev, addr);
7022 else
7023 err = -EINVAL;
7024
7025 /* Only return duplicate errors if NLM_F_EXCL is set */
7026 if (err == -EEXIST && !(flags & NLM_F_EXCL))
7027 err = 0;
7028
7029 return err;
7030}
7031
7032#ifndef USE_DEFAULT_FDB_DEL_DUMP
7033#ifdef USE_CONST_DEV_UC_CHAR
7034static int i40e_ndo_fdb_del(struct ndmsg *ndm,
7035 struct net_device *dev,
7036 const unsigned char *addr)
7037#else
7038static int i40e_ndo_fdb_del(struct ndmsg *ndm,
7039 struct net_device *dev,
7040 unsigned char *addr)
7041#endif
7042{
7043 struct i40e_netdev_priv *np = netdev_priv(dev);
7044 struct i40e_pf *pf = np->vsi->back;
7045 int err = -EOPNOTSUPP;
7046
7047 if (ndm->ndm_state & NUD_PERMANENT) {
7048 netdev_info(dev, "FDB only supports static addresses\n");
7049 return -EINVAL;
7050 }
7051
7052 if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
7053 if (is_unicast_ether_addr(addr))
7054 err = dev_uc_del(dev, addr);
7055 else if (is_multicast_ether_addr(addr))
7056 err = dev_mc_del(dev, addr);
7057 else
7058 err = -EINVAL;
7059 }
7060
7061 return err;
7062}
7063
7064static int i40e_ndo_fdb_dump(struct sk_buff *skb,
7065 struct netlink_callback *cb,
7066 struct net_device *dev,
7067 int idx)
7068{
7069 struct i40e_netdev_priv *np = netdev_priv(dev);
7070 struct i40e_pf *pf = np->vsi->back;
7071
7072 if (pf->flags & I40E_FLAG_SRIOV_ENABLED)
7073 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
7074
7075 return idx;
7076}
7077
7078#endif /* USE_DEFAULT_FDB_DEL_DUMP */
7079#endif /* HAVE_FDB_OPS */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007080static const struct net_device_ops i40e_netdev_ops = {
7081 .ndo_open = i40e_open,
7082 .ndo_stop = i40e_close,
7083 .ndo_start_xmit = i40e_lan_xmit_frame,
7084 .ndo_get_stats64 = i40e_get_netdev_stats_struct,
7085 .ndo_set_rx_mode = i40e_set_rx_mode,
7086 .ndo_validate_addr = eth_validate_addr,
7087 .ndo_set_mac_address = i40e_set_mac,
7088 .ndo_change_mtu = i40e_change_mtu,
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00007089 .ndo_do_ioctl = i40e_ioctl,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007090 .ndo_tx_timeout = i40e_tx_timeout,
7091 .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
7092 .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
7093#ifdef CONFIG_NET_POLL_CONTROLLER
7094 .ndo_poll_controller = i40e_netpoll,
7095#endif
7096 .ndo_setup_tc = i40e_setup_tc,
7097 .ndo_set_features = i40e_set_features,
7098 .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
7099 .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04007100 .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007101 .ndo_get_vf_config = i40e_ndo_get_vf_config,
Mitch Williams588aefa2014-02-11 08:27:49 +00007102 .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
Mitch Williamsc674d122014-05-20 08:01:40 +00007103 .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofck,
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007104#ifdef CONFIG_I40E_VXLAN
7105 .ndo_add_vxlan_port = i40e_add_vxlan_port,
7106 .ndo_del_vxlan_port = i40e_del_vxlan_port,
7107#endif
Greg Rose4ba0dea2014-03-06 08:59:55 +00007108#ifdef HAVE_FDB_OPS
7109 .ndo_fdb_add = i40e_ndo_fdb_add,
7110#ifndef USE_DEFAULT_FDB_DEL_DUMP
7111 .ndo_fdb_del = i40e_ndo_fdb_del,
7112 .ndo_fdb_dump = i40e_ndo_fdb_dump,
7113#endif
7114#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007115};
7116
7117/**
7118 * i40e_config_netdev - Setup the netdev flags
7119 * @vsi: the VSI being configured
7120 *
7121 * Returns 0 on success, negative value on failure
7122 **/
7123static int i40e_config_netdev(struct i40e_vsi *vsi)
7124{
Greg Rose1a103702013-11-28 06:42:39 +00007125 u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007126 struct i40e_pf *pf = vsi->back;
7127 struct i40e_hw *hw = &pf->hw;
7128 struct i40e_netdev_priv *np;
7129 struct net_device *netdev;
7130 u8 mac_addr[ETH_ALEN];
7131 int etherdev_size;
7132
7133 etherdev_size = sizeof(struct i40e_netdev_priv);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00007134 netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007135 if (!netdev)
7136 return -ENOMEM;
7137
7138 vsi->netdev = netdev;
7139 np = netdev_priv(netdev);
7140 np->vsi = vsi;
7141
Or Gerlitzd70e9412014-03-18 10:36:45 +02007142 netdev->hw_enc_features |= NETIF_F_IP_CSUM |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007143 NETIF_F_GSO_UDP_TUNNEL |
Or Gerlitzd70e9412014-03-18 10:36:45 +02007144 NETIF_F_TSO;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007145
7146 netdev->features = NETIF_F_SG |
7147 NETIF_F_IP_CSUM |
7148 NETIF_F_SCTP_CSUM |
7149 NETIF_F_HIGHDMA |
7150 NETIF_F_GSO_UDP_TUNNEL |
7151 NETIF_F_HW_VLAN_CTAG_TX |
7152 NETIF_F_HW_VLAN_CTAG_RX |
7153 NETIF_F_HW_VLAN_CTAG_FILTER |
7154 NETIF_F_IPV6_CSUM |
7155 NETIF_F_TSO |
Jesse Brandeburg059dab62014-04-01 09:07:20 +00007156 NETIF_F_TSO_ECN |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007157 NETIF_F_TSO6 |
7158 NETIF_F_RXCSUM |
7159 NETIF_F_RXHASH |
7160 0;
7161
Anjali Singhai Jain2e86a0b2014-04-01 07:11:53 +00007162 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
7163 netdev->features |= NETIF_F_NTUPLE;
7164
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007165 /* copy netdev features into list of user selectable features */
7166 netdev->hw_features |= netdev->features;
7167
7168 if (vsi->type == I40E_VSI_MAIN) {
7169 SET_NETDEV_DEV(netdev, &pf->pdev->dev);
Greg Rose9a173902014-05-22 06:32:02 +00007170 ether_addr_copy(mac_addr, hw->mac.perm_addr);
Greg Rose8c27d422014-05-22 06:31:56 +00007171 /* The following two steps are necessary to prevent reception
7172 * of tagged packets - by default the NVM loads a MAC-VLAN
7173 * filter that will accept any tagged packet. This is to
7174 * prevent that during normal operations until a specific
7175 * VLAN tag filter has been set.
7176 */
7177 i40e_rm_default_mac_filter(vsi, mac_addr);
7178 i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007179 } else {
7180 /* relate the VSI_VMDQ name to the VSI_MAIN name */
7181 snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
7182 pf->vsi[pf->lan_vsi]->netdev->name);
7183 random_ether_addr(mac_addr);
7184 i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false);
7185 }
Greg Rose1a103702013-11-28 06:42:39 +00007186 i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007187
Greg Rose9a173902014-05-22 06:32:02 +00007188 ether_addr_copy(netdev->dev_addr, mac_addr);
7189 ether_addr_copy(netdev->perm_addr, mac_addr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007190 /* vlan gets same features (except vlan offload)
7191 * after any tweaks for specific VSI types
7192 */
7193 netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX |
7194 NETIF_F_HW_VLAN_CTAG_RX |
7195 NETIF_F_HW_VLAN_CTAG_FILTER);
7196 netdev->priv_flags |= IFF_UNICAST_FLT;
7197 netdev->priv_flags |= IFF_SUPP_NOFCS;
7198 /* Setup netdev TC information */
7199 i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
7200
7201 netdev->netdev_ops = &i40e_netdev_ops;
7202 netdev->watchdog_timeo = 5 * HZ;
7203 i40e_set_ethtool_ops(netdev);
7204
7205 return 0;
7206}
7207
7208/**
7209 * i40e_vsi_delete - Delete a VSI from the switch
7210 * @vsi: the VSI being removed
7211 *
7212 * Returns 0 on success, negative value on failure
7213 **/
7214static void i40e_vsi_delete(struct i40e_vsi *vsi)
7215{
7216 /* remove default VSI is not allowed */
7217 if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
7218 return;
7219
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007220 i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007221}
7222
7223/**
7224 * i40e_add_vsi - Add a VSI to the switch
7225 * @vsi: the VSI being configured
7226 *
7227 * This initializes a VSI context depending on the VSI type to be added and
7228 * passes it down to the add_vsi aq command.
7229 **/
7230static int i40e_add_vsi(struct i40e_vsi *vsi)
7231{
7232 int ret = -ENODEV;
7233 struct i40e_mac_filter *f, *ftmp;
7234 struct i40e_pf *pf = vsi->back;
7235 struct i40e_hw *hw = &pf->hw;
7236 struct i40e_vsi_context ctxt;
7237 u8 enabled_tc = 0x1; /* TC0 enabled */
7238 int f_count = 0;
7239
7240 memset(&ctxt, 0, sizeof(ctxt));
7241 switch (vsi->type) {
7242 case I40E_VSI_MAIN:
7243 /* The PF's main VSI is already setup as part of the
7244 * device initialization, so we'll not bother with
7245 * the add_vsi call, but we will retrieve the current
7246 * VSI context.
7247 */
7248 ctxt.seid = pf->main_vsi_seid;
7249 ctxt.pf_num = pf->hw.pf_id;
7250 ctxt.vf_num = 0;
7251 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
7252 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
7253 if (ret) {
7254 dev_info(&pf->pdev->dev,
7255 "couldn't get pf vsi config, err %d, aq_err %d\n",
7256 ret, pf->hw.aq.asq_last_status);
7257 return -ENOENT;
7258 }
7259 memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
7260 vsi->info.valid_sections = 0;
7261
7262 vsi->seid = ctxt.seid;
7263 vsi->id = ctxt.vsi_number;
7264
7265 enabled_tc = i40e_pf_get_tc_map(pf);
7266
7267 /* MFP mode setup queue map and update VSI */
7268 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
7269 memset(&ctxt, 0, sizeof(ctxt));
7270 ctxt.seid = pf->main_vsi_seid;
7271 ctxt.pf_num = pf->hw.pf_id;
7272 ctxt.vf_num = 0;
7273 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
7274 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
7275 if (ret) {
7276 dev_info(&pf->pdev->dev,
7277 "update vsi failed, aq_err=%d\n",
7278 pf->hw.aq.asq_last_status);
7279 ret = -ENOENT;
7280 goto err;
7281 }
7282 /* update the local VSI info queue map */
7283 i40e_vsi_update_queue_map(vsi, &ctxt);
7284 vsi->info.valid_sections = 0;
7285 } else {
7286 /* Default/Main VSI is only enabled for TC0
7287 * reconfigure it to enable all TCs that are
7288 * available on the port in SFP mode.
7289 */
7290 ret = i40e_vsi_config_tc(vsi, enabled_tc);
7291 if (ret) {
7292 dev_info(&pf->pdev->dev,
7293 "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n",
7294 enabled_tc, ret,
7295 pf->hw.aq.asq_last_status);
7296 ret = -ENOENT;
7297 }
7298 }
7299 break;
7300
7301 case I40E_VSI_FDIR:
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08007302 ctxt.pf_num = hw->pf_id;
7303 ctxt.vf_num = 0;
7304 ctxt.uplink_seid = vsi->uplink_seid;
7305 ctxt.connection_type = 0x1; /* regular data port */
7306 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007307 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007308 break;
7309
7310 case I40E_VSI_VMDQ2:
7311 ctxt.pf_num = hw->pf_id;
7312 ctxt.vf_num = 0;
7313 ctxt.uplink_seid = vsi->uplink_seid;
7314 ctxt.connection_type = 0x1; /* regular data port */
7315 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
7316
7317 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
7318
7319 /* This VSI is connected to VEB so the switch_id
7320 * should be set to zero by default.
7321 */
7322 ctxt.info.switch_id = 0;
7323 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
7324 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
7325
7326 /* Setup the VSI tx/rx queue map for TC0 only for now */
7327 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
7328 break;
7329
7330 case I40E_VSI_SRIOV:
7331 ctxt.pf_num = hw->pf_id;
7332 ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
7333 ctxt.uplink_seid = vsi->uplink_seid;
7334 ctxt.connection_type = 0x1; /* regular data port */
7335 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
7336
7337 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
7338
7339 /* This VSI is connected to VEB so the switch_id
7340 * should be set to zero by default.
7341 */
7342 ctxt.info.switch_id = cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
7343
7344 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
7345 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
Mitch Williamsc674d122014-05-20 08:01:40 +00007346 if (pf->vf[vsi->vf_id].spoofchk) {
7347 ctxt.info.valid_sections |=
7348 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
7349 ctxt.info.sec_flags |=
7350 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
7351 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
7352 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007353 /* Setup the VSI tx/rx queue map for TC0 only for now */
7354 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
7355 break;
7356
7357 default:
7358 return -ENODEV;
7359 }
7360
7361 if (vsi->type != I40E_VSI_MAIN) {
7362 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
7363 if (ret) {
7364 dev_info(&vsi->back->pdev->dev,
7365 "add vsi failed, aq_err=%d\n",
7366 vsi->back->hw.aq.asq_last_status);
7367 ret = -ENOENT;
7368 goto err;
7369 }
7370 memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
7371 vsi->info.valid_sections = 0;
7372 vsi->seid = ctxt.seid;
7373 vsi->id = ctxt.vsi_number;
7374 }
7375
7376 /* If macvlan filters already exist, force them to get loaded */
7377 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
7378 f->changed = true;
7379 f_count++;
7380 }
7381 if (f_count) {
7382 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
7383 pf->flags |= I40E_FLAG_FILTER_SYNC;
7384 }
7385
7386 /* Update VSI BW information */
7387 ret = i40e_vsi_get_bw_info(vsi);
7388 if (ret) {
7389 dev_info(&pf->pdev->dev,
7390 "couldn't get vsi bw info, err %d, aq_err %d\n",
7391 ret, pf->hw.aq.asq_last_status);
7392 /* VSI is already added so not tearing that up */
7393 ret = 0;
7394 }
7395
7396err:
7397 return ret;
7398}
7399
7400/**
7401 * i40e_vsi_release - Delete a VSI and free its resources
7402 * @vsi: the VSI being removed
7403 *
7404 * Returns 0 on success or < 0 on error
7405 **/
7406int i40e_vsi_release(struct i40e_vsi *vsi)
7407{
7408 struct i40e_mac_filter *f, *ftmp;
7409 struct i40e_veb *veb = NULL;
7410 struct i40e_pf *pf;
7411 u16 uplink_seid;
7412 int i, n;
7413
7414 pf = vsi->back;
7415
7416 /* release of a VEB-owner or last VSI is not allowed */
7417 if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
7418 dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
7419 vsi->seid, vsi->uplink_seid);
7420 return -ENODEV;
7421 }
7422 if (vsi == pf->vsi[pf->lan_vsi] &&
7423 !test_bit(__I40E_DOWN, &pf->state)) {
7424 dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
7425 return -ENODEV;
7426 }
7427
7428 uplink_seid = vsi->uplink_seid;
7429 if (vsi->type != I40E_VSI_SRIOV) {
7430 if (vsi->netdev_registered) {
7431 vsi->netdev_registered = false;
7432 if (vsi->netdev) {
7433 /* results in a call to i40e_close() */
7434 unregister_netdev(vsi->netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007435 }
7436 } else {
Shannon Nelson90ef8d42014-03-14 07:32:26 +00007437 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007438 }
7439 i40e_vsi_disable_irq(vsi);
7440 }
7441
7442 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
7443 i40e_del_filter(vsi, f->macaddr, f->vlan,
7444 f->is_vf, f->is_netdev);
7445 i40e_sync_vsi_filters(vsi);
7446
7447 i40e_vsi_delete(vsi);
7448 i40e_vsi_free_q_vectors(vsi);
Shannon Nelsona4866592014-02-11 08:24:07 +00007449 if (vsi->netdev) {
7450 free_netdev(vsi->netdev);
7451 vsi->netdev = NULL;
7452 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007453 i40e_vsi_clear_rings(vsi);
7454 i40e_vsi_clear(vsi);
7455
7456 /* If this was the last thing on the VEB, except for the
7457 * controlling VSI, remove the VEB, which puts the controlling
7458 * VSI onto the next level down in the switch.
7459 *
7460 * Well, okay, there's one more exception here: don't remove
7461 * the orphan VEBs yet. We'll wait for an explicit remove request
7462 * from up the network stack.
7463 */
Mitch Williams505682c2014-05-20 08:01:37 +00007464 for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007465 if (pf->vsi[i] &&
7466 pf->vsi[i]->uplink_seid == uplink_seid &&
7467 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
7468 n++; /* count the VSIs */
7469 }
7470 }
7471 for (i = 0; i < I40E_MAX_VEB; i++) {
7472 if (!pf->veb[i])
7473 continue;
7474 if (pf->veb[i]->uplink_seid == uplink_seid)
7475 n++; /* count the VEBs */
7476 if (pf->veb[i]->seid == uplink_seid)
7477 veb = pf->veb[i];
7478 }
7479 if (n == 0 && veb && veb->uplink_seid != 0)
7480 i40e_veb_release(veb);
7481
7482 return 0;
7483}
7484
7485/**
7486 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
7487 * @vsi: ptr to the VSI
7488 *
7489 * This should only be called after i40e_vsi_mem_alloc() which allocates the
7490 * corresponding SW VSI structure and initializes num_queue_pairs for the
7491 * newly allocated VSI.
7492 *
7493 * Returns 0 on success or negative on failure
7494 **/
7495static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
7496{
7497 int ret = -ENOENT;
7498 struct i40e_pf *pf = vsi->back;
7499
Alexander Duyck493fb302013-09-28 07:01:44 +00007500 if (vsi->q_vectors[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007501 dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
7502 vsi->seid);
7503 return -EEXIST;
7504 }
7505
7506 if (vsi->base_vector) {
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00007507 dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007508 vsi->seid, vsi->base_vector);
7509 return -EEXIST;
7510 }
7511
Greg Rose90e04072014-03-06 08:59:57 +00007512 ret = i40e_vsi_alloc_q_vectors(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007513 if (ret) {
7514 dev_info(&pf->pdev->dev,
7515 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
7516 vsi->num_q_vectors, vsi->seid, ret);
7517 vsi->num_q_vectors = 0;
7518 goto vector_setup_out;
7519 }
7520
Shannon Nelson958a3e32013-09-28 07:13:28 +00007521 if (vsi->num_q_vectors)
7522 vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
7523 vsi->num_q_vectors, vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007524 if (vsi->base_vector < 0) {
7525 dev_info(&pf->pdev->dev,
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00007526 "failed to get queue tracking for VSI %d, err=%d\n",
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007527 vsi->seid, vsi->base_vector);
7528 i40e_vsi_free_q_vectors(vsi);
7529 ret = -ENOENT;
7530 goto vector_setup_out;
7531 }
7532
7533vector_setup_out:
7534 return ret;
7535}
7536
7537/**
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007538 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
7539 * @vsi: pointer to the vsi.
7540 *
7541 * This re-allocates a vsi's queue resources.
7542 *
7543 * Returns pointer to the successfully allocated and configured VSI sw struct
7544 * on success, otherwise returns NULL on failure.
7545 **/
7546static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
7547{
7548 struct i40e_pf *pf = vsi->back;
7549 u8 enabled_tc;
7550 int ret;
7551
7552 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
7553 i40e_vsi_clear_rings(vsi);
7554
7555 i40e_vsi_free_arrays(vsi, false);
7556 i40e_set_num_rings_in_vsi(vsi);
7557 ret = i40e_vsi_alloc_arrays(vsi, false);
7558 if (ret)
7559 goto err_vsi;
7560
7561 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
7562 if (ret < 0) {
7563 dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n",
7564 vsi->seid, ret);
7565 goto err_vsi;
7566 }
7567 vsi->base_queue = ret;
7568
7569 /* Update the FW view of the VSI. Force a reset of TC and queue
7570 * layout configurations.
7571 */
7572 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
7573 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
7574 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
7575 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
7576
7577 /* assign it some queues */
7578 ret = i40e_alloc_rings(vsi);
7579 if (ret)
7580 goto err_rings;
7581
7582 /* map all of the rings to the q_vectors */
7583 i40e_vsi_map_rings_to_vectors(vsi);
7584 return vsi;
7585
7586err_rings:
7587 i40e_vsi_free_q_vectors(vsi);
7588 if (vsi->netdev_registered) {
7589 vsi->netdev_registered = false;
7590 unregister_netdev(vsi->netdev);
7591 free_netdev(vsi->netdev);
7592 vsi->netdev = NULL;
7593 }
7594 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
7595err_vsi:
7596 i40e_vsi_clear(vsi);
7597 return NULL;
7598}
7599
7600/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007601 * i40e_vsi_setup - Set up a VSI by a given type
7602 * @pf: board private structure
7603 * @type: VSI type
7604 * @uplink_seid: the switch element to link to
7605 * @param1: usage depends upon VSI type. For VF types, indicates VF id
7606 *
7607 * This allocates the sw VSI structure and its queue resources, then add a VSI
7608 * to the identified VEB.
7609 *
7610 * Returns pointer to the successfully allocated and configure VSI sw struct on
7611 * success, otherwise returns NULL on failure.
7612 **/
7613struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
7614 u16 uplink_seid, u32 param1)
7615{
7616 struct i40e_vsi *vsi = NULL;
7617 struct i40e_veb *veb = NULL;
7618 int ret, i;
7619 int v_idx;
7620
7621 /* The requested uplink_seid must be either
7622 * - the PF's port seid
7623 * no VEB is needed because this is the PF
7624 * or this is a Flow Director special case VSI
7625 * - seid of an existing VEB
7626 * - seid of a VSI that owns an existing VEB
7627 * - seid of a VSI that doesn't own a VEB
7628 * a new VEB is created and the VSI becomes the owner
7629 * - seid of the PF VSI, which is what creates the first VEB
7630 * this is a special case of the previous
7631 *
7632 * Find which uplink_seid we were given and create a new VEB if needed
7633 */
7634 for (i = 0; i < I40E_MAX_VEB; i++) {
7635 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
7636 veb = pf->veb[i];
7637 break;
7638 }
7639 }
7640
7641 if (!veb && uplink_seid != pf->mac_seid) {
7642
Mitch Williams505682c2014-05-20 08:01:37 +00007643 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007644 if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
7645 vsi = pf->vsi[i];
7646 break;
7647 }
7648 }
7649 if (!vsi) {
7650 dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
7651 uplink_seid);
7652 return NULL;
7653 }
7654
7655 if (vsi->uplink_seid == pf->mac_seid)
7656 veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
7657 vsi->tc_config.enabled_tc);
7658 else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
7659 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
7660 vsi->tc_config.enabled_tc);
7661
7662 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
7663 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
7664 veb = pf->veb[i];
7665 }
7666 if (!veb) {
7667 dev_info(&pf->pdev->dev, "couldn't add VEB\n");
7668 return NULL;
7669 }
7670
7671 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
7672 uplink_seid = veb->seid;
7673 }
7674
7675 /* get vsi sw struct */
7676 v_idx = i40e_vsi_mem_alloc(pf, type);
7677 if (v_idx < 0)
7678 goto err_alloc;
7679 vsi = pf->vsi[v_idx];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08007680 if (!vsi)
7681 goto err_alloc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007682 vsi->type = type;
7683 vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
7684
7685 if (type == I40E_VSI_MAIN)
7686 pf->lan_vsi = v_idx;
7687 else if (type == I40E_VSI_SRIOV)
7688 vsi->vf_id = param1;
7689 /* assign it some queues */
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08007690 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
7691 vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007692 if (ret < 0) {
7693 dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n",
7694 vsi->seid, ret);
7695 goto err_vsi;
7696 }
7697 vsi->base_queue = ret;
7698
7699 /* get a VSI from the hardware */
7700 vsi->uplink_seid = uplink_seid;
7701 ret = i40e_add_vsi(vsi);
7702 if (ret)
7703 goto err_vsi;
7704
7705 switch (vsi->type) {
7706 /* setup the netdev if needed */
7707 case I40E_VSI_MAIN:
7708 case I40E_VSI_VMDQ2:
7709 ret = i40e_config_netdev(vsi);
7710 if (ret)
7711 goto err_netdev;
7712 ret = register_netdev(vsi->netdev);
7713 if (ret)
7714 goto err_netdev;
7715 vsi->netdev_registered = true;
7716 netif_carrier_off(vsi->netdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08007717#ifdef CONFIG_I40E_DCB
7718 /* Setup DCB netlink interface */
7719 i40e_dcbnl_setup(vsi);
7720#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007721 /* fall through */
7722
7723 case I40E_VSI_FDIR:
7724 /* set up vectors and rings if needed */
7725 ret = i40e_vsi_setup_vectors(vsi);
7726 if (ret)
7727 goto err_msix;
7728
7729 ret = i40e_alloc_rings(vsi);
7730 if (ret)
7731 goto err_rings;
7732
7733 /* map all of the rings to the q_vectors */
7734 i40e_vsi_map_rings_to_vectors(vsi);
7735
7736 i40e_vsi_reset_stats(vsi);
7737 break;
7738
7739 default:
7740 /* no netdev or rings for the other VSI types */
7741 break;
7742 }
7743
7744 return vsi;
7745
7746err_rings:
7747 i40e_vsi_free_q_vectors(vsi);
7748err_msix:
7749 if (vsi->netdev_registered) {
7750 vsi->netdev_registered = false;
7751 unregister_netdev(vsi->netdev);
7752 free_netdev(vsi->netdev);
7753 vsi->netdev = NULL;
7754 }
7755err_netdev:
7756 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
7757err_vsi:
7758 i40e_vsi_clear(vsi);
7759err_alloc:
7760 return NULL;
7761}
7762
7763/**
7764 * i40e_veb_get_bw_info - Query VEB BW information
7765 * @veb: the veb to query
7766 *
7767 * Query the Tx scheduler BW configuration data for given VEB
7768 **/
7769static int i40e_veb_get_bw_info(struct i40e_veb *veb)
7770{
7771 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
7772 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
7773 struct i40e_pf *pf = veb->pf;
7774 struct i40e_hw *hw = &pf->hw;
7775 u32 tc_bw_max;
7776 int ret = 0;
7777 int i;
7778
7779 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
7780 &bw_data, NULL);
7781 if (ret) {
7782 dev_info(&pf->pdev->dev,
7783 "query veb bw config failed, aq_err=%d\n",
7784 hw->aq.asq_last_status);
7785 goto out;
7786 }
7787
7788 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
7789 &ets_data, NULL);
7790 if (ret) {
7791 dev_info(&pf->pdev->dev,
7792 "query veb bw ets config failed, aq_err=%d\n",
7793 hw->aq.asq_last_status);
7794 goto out;
7795 }
7796
7797 veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
7798 veb->bw_max_quanta = ets_data.tc_bw_max;
7799 veb->is_abs_credits = bw_data.absolute_credits_enable;
7800 tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
7801 (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
7802 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
7803 veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
7804 veb->bw_tc_limit_credits[i] =
7805 le16_to_cpu(bw_data.tc_bw_limits[i]);
7806 veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
7807 }
7808
7809out:
7810 return ret;
7811}
7812
7813/**
7814 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
7815 * @pf: board private structure
7816 *
7817 * On error: returns error code (negative)
7818 * On success: returns vsi index in PF (positive)
7819 **/
7820static int i40e_veb_mem_alloc(struct i40e_pf *pf)
7821{
7822 int ret = -ENOENT;
7823 struct i40e_veb *veb;
7824 int i;
7825
7826 /* Need to protect the allocation of switch elements at the PF level */
7827 mutex_lock(&pf->switch_mutex);
7828
7829 /* VEB list may be fragmented if VEB creation/destruction has
7830 * been happening. We can afford to do a quick scan to look
7831 * for any free slots in the list.
7832 *
7833 * find next empty veb slot, looping back around if necessary
7834 */
7835 i = 0;
7836 while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
7837 i++;
7838 if (i >= I40E_MAX_VEB) {
7839 ret = -ENOMEM;
7840 goto err_alloc_veb; /* out of VEB slots! */
7841 }
7842
7843 veb = kzalloc(sizeof(*veb), GFP_KERNEL);
7844 if (!veb) {
7845 ret = -ENOMEM;
7846 goto err_alloc_veb;
7847 }
7848 veb->pf = pf;
7849 veb->idx = i;
7850 veb->enabled_tc = 1;
7851
7852 pf->veb[i] = veb;
7853 ret = i;
7854err_alloc_veb:
7855 mutex_unlock(&pf->switch_mutex);
7856 return ret;
7857}
7858
7859/**
7860 * i40e_switch_branch_release - Delete a branch of the switch tree
7861 * @branch: where to start deleting
7862 *
7863 * This uses recursion to find the tips of the branch to be
7864 * removed, deleting until we get back to and can delete this VEB.
7865 **/
7866static void i40e_switch_branch_release(struct i40e_veb *branch)
7867{
7868 struct i40e_pf *pf = branch->pf;
7869 u16 branch_seid = branch->seid;
7870 u16 veb_idx = branch->idx;
7871 int i;
7872
7873 /* release any VEBs on this VEB - RECURSION */
7874 for (i = 0; i < I40E_MAX_VEB; i++) {
7875 if (!pf->veb[i])
7876 continue;
7877 if (pf->veb[i]->uplink_seid == branch->seid)
7878 i40e_switch_branch_release(pf->veb[i]);
7879 }
7880
7881 /* Release the VSIs on this VEB, but not the owner VSI.
7882 *
7883 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
7884 * the VEB itself, so don't use (*branch) after this loop.
7885 */
Mitch Williams505682c2014-05-20 08:01:37 +00007886 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007887 if (!pf->vsi[i])
7888 continue;
7889 if (pf->vsi[i]->uplink_seid == branch_seid &&
7890 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
7891 i40e_vsi_release(pf->vsi[i]);
7892 }
7893 }
7894
7895 /* There's one corner case where the VEB might not have been
7896 * removed, so double check it here and remove it if needed.
7897 * This case happens if the veb was created from the debugfs
7898 * commands and no VSIs were added to it.
7899 */
7900 if (pf->veb[veb_idx])
7901 i40e_veb_release(pf->veb[veb_idx]);
7902}
7903
7904/**
7905 * i40e_veb_clear - remove veb struct
7906 * @veb: the veb to remove
7907 **/
7908static void i40e_veb_clear(struct i40e_veb *veb)
7909{
7910 if (!veb)
7911 return;
7912
7913 if (veb->pf) {
7914 struct i40e_pf *pf = veb->pf;
7915
7916 mutex_lock(&pf->switch_mutex);
7917 if (pf->veb[veb->idx] == veb)
7918 pf->veb[veb->idx] = NULL;
7919 mutex_unlock(&pf->switch_mutex);
7920 }
7921
7922 kfree(veb);
7923}
7924
7925/**
7926 * i40e_veb_release - Delete a VEB and free its resources
7927 * @veb: the VEB being removed
7928 **/
7929void i40e_veb_release(struct i40e_veb *veb)
7930{
7931 struct i40e_vsi *vsi = NULL;
7932 struct i40e_pf *pf;
7933 int i, n = 0;
7934
7935 pf = veb->pf;
7936
7937 /* find the remaining VSI and check for extras */
Mitch Williams505682c2014-05-20 08:01:37 +00007938 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007939 if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
7940 n++;
7941 vsi = pf->vsi[i];
7942 }
7943 }
7944 if (n != 1) {
7945 dev_info(&pf->pdev->dev,
7946 "can't remove VEB %d with %d VSIs left\n",
7947 veb->seid, n);
7948 return;
7949 }
7950
7951 /* move the remaining VSI to uplink veb */
7952 vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
7953 if (veb->uplink_seid) {
7954 vsi->uplink_seid = veb->uplink_seid;
7955 if (veb->uplink_seid == pf->mac_seid)
7956 vsi->veb_idx = I40E_NO_VEB;
7957 else
7958 vsi->veb_idx = veb->veb_idx;
7959 } else {
7960 /* floating VEB */
7961 vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
7962 vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
7963 }
7964
7965 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
7966 i40e_veb_clear(veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007967}
7968
7969/**
7970 * i40e_add_veb - create the VEB in the switch
7971 * @veb: the VEB to be instantiated
7972 * @vsi: the controlling VSI
7973 **/
7974static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
7975{
Greg Rose56747262013-11-28 06:39:37 +00007976 bool is_default = false;
Kevin Scotte1c51b952013-11-20 10:02:51 +00007977 bool is_cloud = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007978 int ret;
7979
7980 /* get a VEB from the hardware */
7981 ret = i40e_aq_add_veb(&veb->pf->hw, veb->uplink_seid, vsi->seid,
Kevin Scotte1c51b952013-11-20 10:02:51 +00007982 veb->enabled_tc, is_default,
7983 is_cloud, &veb->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007984 if (ret) {
7985 dev_info(&veb->pf->pdev->dev,
7986 "couldn't add VEB, err %d, aq_err %d\n",
7987 ret, veb->pf->hw.aq.asq_last_status);
7988 return -EPERM;
7989 }
7990
7991 /* get statistics counter */
7992 ret = i40e_aq_get_veb_parameters(&veb->pf->hw, veb->seid, NULL, NULL,
7993 &veb->stats_idx, NULL, NULL, NULL);
7994 if (ret) {
7995 dev_info(&veb->pf->pdev->dev,
7996 "couldn't get VEB statistics idx, err %d, aq_err %d\n",
7997 ret, veb->pf->hw.aq.asq_last_status);
7998 return -EPERM;
7999 }
8000 ret = i40e_veb_get_bw_info(veb);
8001 if (ret) {
8002 dev_info(&veb->pf->pdev->dev,
8003 "couldn't get VEB bw info, err %d, aq_err %d\n",
8004 ret, veb->pf->hw.aq.asq_last_status);
8005 i40e_aq_delete_element(&veb->pf->hw, veb->seid, NULL);
8006 return -ENOENT;
8007 }
8008
8009 vsi->uplink_seid = veb->seid;
8010 vsi->veb_idx = veb->idx;
8011 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
8012
8013 return 0;
8014}
8015
8016/**
8017 * i40e_veb_setup - Set up a VEB
8018 * @pf: board private structure
8019 * @flags: VEB setup flags
8020 * @uplink_seid: the switch element to link to
8021 * @vsi_seid: the initial VSI seid
8022 * @enabled_tc: Enabled TC bit-map
8023 *
8024 * This allocates the sw VEB structure and links it into the switch
8025 * It is possible and legal for this to be a duplicate of an already
8026 * existing VEB. It is also possible for both uplink and vsi seids
8027 * to be zero, in order to create a floating VEB.
8028 *
8029 * Returns pointer to the successfully allocated VEB sw struct on
8030 * success, otherwise returns NULL on failure.
8031 **/
8032struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
8033 u16 uplink_seid, u16 vsi_seid,
8034 u8 enabled_tc)
8035{
8036 struct i40e_veb *veb, *uplink_veb = NULL;
8037 int vsi_idx, veb_idx;
8038 int ret;
8039
8040 /* if one seid is 0, the other must be 0 to create a floating relay */
8041 if ((uplink_seid == 0 || vsi_seid == 0) &&
8042 (uplink_seid + vsi_seid != 0)) {
8043 dev_info(&pf->pdev->dev,
8044 "one, not both seid's are 0: uplink=%d vsi=%d\n",
8045 uplink_seid, vsi_seid);
8046 return NULL;
8047 }
8048
8049 /* make sure there is such a vsi and uplink */
Mitch Williams505682c2014-05-20 08:01:37 +00008050 for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008051 if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
8052 break;
Mitch Williams505682c2014-05-20 08:01:37 +00008053 if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008054 dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
8055 vsi_seid);
8056 return NULL;
8057 }
8058
8059 if (uplink_seid && uplink_seid != pf->mac_seid) {
8060 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
8061 if (pf->veb[veb_idx] &&
8062 pf->veb[veb_idx]->seid == uplink_seid) {
8063 uplink_veb = pf->veb[veb_idx];
8064 break;
8065 }
8066 }
8067 if (!uplink_veb) {
8068 dev_info(&pf->pdev->dev,
8069 "uplink seid %d not found\n", uplink_seid);
8070 return NULL;
8071 }
8072 }
8073
8074 /* get veb sw struct */
8075 veb_idx = i40e_veb_mem_alloc(pf);
8076 if (veb_idx < 0)
8077 goto err_alloc;
8078 veb = pf->veb[veb_idx];
8079 veb->flags = flags;
8080 veb->uplink_seid = uplink_seid;
8081 veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
8082 veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
8083
8084 /* create the VEB in the switch */
8085 ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
8086 if (ret)
8087 goto err_veb;
Shannon Nelson1bb8b932014-04-23 04:49:54 +00008088 if (vsi_idx == pf->lan_vsi)
8089 pf->lan_veb = veb->idx;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008090
8091 return veb;
8092
8093err_veb:
8094 i40e_veb_clear(veb);
8095err_alloc:
8096 return NULL;
8097}
8098
8099/**
8100 * i40e_setup_pf_switch_element - set pf vars based on switch type
8101 * @pf: board private structure
8102 * @ele: element we are building info from
8103 * @num_reported: total number of elements
8104 * @printconfig: should we print the contents
8105 *
8106 * helper function to assist in extracting a few useful SEID values.
8107 **/
8108static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
8109 struct i40e_aqc_switch_config_element_resp *ele,
8110 u16 num_reported, bool printconfig)
8111{
8112 u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
8113 u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
8114 u8 element_type = ele->element_type;
8115 u16 seid = le16_to_cpu(ele->seid);
8116
8117 if (printconfig)
8118 dev_info(&pf->pdev->dev,
8119 "type=%d seid=%d uplink=%d downlink=%d\n",
8120 element_type, seid, uplink_seid, downlink_seid);
8121
8122 switch (element_type) {
8123 case I40E_SWITCH_ELEMENT_TYPE_MAC:
8124 pf->mac_seid = seid;
8125 break;
8126 case I40E_SWITCH_ELEMENT_TYPE_VEB:
8127 /* Main VEB? */
8128 if (uplink_seid != pf->mac_seid)
8129 break;
8130 if (pf->lan_veb == I40E_NO_VEB) {
8131 int v;
8132
8133 /* find existing or else empty VEB */
8134 for (v = 0; v < I40E_MAX_VEB; v++) {
8135 if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
8136 pf->lan_veb = v;
8137 break;
8138 }
8139 }
8140 if (pf->lan_veb == I40E_NO_VEB) {
8141 v = i40e_veb_mem_alloc(pf);
8142 if (v < 0)
8143 break;
8144 pf->lan_veb = v;
8145 }
8146 }
8147
8148 pf->veb[pf->lan_veb]->seid = seid;
8149 pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
8150 pf->veb[pf->lan_veb]->pf = pf;
8151 pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
8152 break;
8153 case I40E_SWITCH_ELEMENT_TYPE_VSI:
8154 if (num_reported != 1)
8155 break;
8156 /* This is immediately after a reset so we can assume this is
8157 * the PF's VSI
8158 */
8159 pf->mac_seid = uplink_seid;
8160 pf->pf_seid = downlink_seid;
8161 pf->main_vsi_seid = seid;
8162 if (printconfig)
8163 dev_info(&pf->pdev->dev,
8164 "pf_seid=%d main_vsi_seid=%d\n",
8165 pf->pf_seid, pf->main_vsi_seid);
8166 break;
8167 case I40E_SWITCH_ELEMENT_TYPE_PF:
8168 case I40E_SWITCH_ELEMENT_TYPE_VF:
8169 case I40E_SWITCH_ELEMENT_TYPE_EMP:
8170 case I40E_SWITCH_ELEMENT_TYPE_BMC:
8171 case I40E_SWITCH_ELEMENT_TYPE_PE:
8172 case I40E_SWITCH_ELEMENT_TYPE_PA:
8173 /* ignore these for now */
8174 break;
8175 default:
8176 dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
8177 element_type, seid);
8178 break;
8179 }
8180}
8181
8182/**
8183 * i40e_fetch_switch_configuration - Get switch config from firmware
8184 * @pf: board private structure
8185 * @printconfig: should we print the contents
8186 *
8187 * Get the current switch configuration from the device and
8188 * extract a few useful SEID values.
8189 **/
8190int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
8191{
8192 struct i40e_aqc_get_switch_config_resp *sw_config;
8193 u16 next_seid = 0;
8194 int ret = 0;
8195 u8 *aq_buf;
8196 int i;
8197
8198 aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
8199 if (!aq_buf)
8200 return -ENOMEM;
8201
8202 sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
8203 do {
8204 u16 num_reported, num_total;
8205
8206 ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
8207 I40E_AQ_LARGE_BUF,
8208 &next_seid, NULL);
8209 if (ret) {
8210 dev_info(&pf->pdev->dev,
8211 "get switch config failed %d aq_err=%x\n",
8212 ret, pf->hw.aq.asq_last_status);
8213 kfree(aq_buf);
8214 return -ENOENT;
8215 }
8216
8217 num_reported = le16_to_cpu(sw_config->header.num_reported);
8218 num_total = le16_to_cpu(sw_config->header.num_total);
8219
8220 if (printconfig)
8221 dev_info(&pf->pdev->dev,
8222 "header: %d reported %d total\n",
8223 num_reported, num_total);
8224
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008225 for (i = 0; i < num_reported; i++) {
8226 struct i40e_aqc_switch_config_element_resp *ele =
8227 &sw_config->element[i];
8228
8229 i40e_setup_pf_switch_element(pf, ele, num_reported,
8230 printconfig);
8231 }
8232 } while (next_seid != 0);
8233
8234 kfree(aq_buf);
8235 return ret;
8236}
8237
8238/**
8239 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
8240 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00008241 * @reinit: if the Main VSI needs to re-initialized.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008242 *
8243 * Returns 0 on success, negative value on failure
8244 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00008245static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008246{
Jesse Brandeburg895106a2013-11-26 10:49:16 +00008247 u32 rxfc = 0, txfc = 0, rxfc_reg;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008248 int ret;
8249
8250 /* find out what's out there already */
8251 ret = i40e_fetch_switch_configuration(pf, false);
8252 if (ret) {
8253 dev_info(&pf->pdev->dev,
8254 "couldn't fetch switch config, err %d, aq_err %d\n",
8255 ret, pf->hw.aq.asq_last_status);
8256 return ret;
8257 }
8258 i40e_pf_reset_stats(pf);
8259
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008260 /* first time setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00008261 if (pf->lan_vsi == I40E_NO_VSI || reinit) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008262 struct i40e_vsi *vsi = NULL;
8263 u16 uplink_seid;
8264
8265 /* Set up the PF VSI associated with the PF's main VSI
8266 * that is already in the HW switch
8267 */
8268 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
8269 uplink_seid = pf->veb[pf->lan_veb]->seid;
8270 else
8271 uplink_seid = pf->mac_seid;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00008272 if (pf->lan_vsi == I40E_NO_VSI)
8273 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
8274 else if (reinit)
8275 vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008276 if (!vsi) {
8277 dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
8278 i40e_fdir_teardown(pf);
8279 return -EAGAIN;
8280 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008281 } else {
8282 /* force a reset of TC and queue layout configurations */
8283 u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
8284 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
8285 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
8286 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
8287 }
8288 i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
8289
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008290 i40e_fdir_sb_setup(pf);
8291
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008292 /* Setup static PF queue filter control settings */
8293 ret = i40e_setup_pf_filter_control(pf);
8294 if (ret) {
8295 dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
8296 ret);
8297 /* Failure here should not stop continuing other steps */
8298 }
8299
8300 /* enable RSS in the HW, even for only one queue, as the stack can use
8301 * the hash
8302 */
8303 if ((pf->flags & I40E_FLAG_RSS_ENABLED))
8304 i40e_config_rss(pf);
8305
8306 /* fill in link information and enable LSE reporting */
8307 i40e_aq_get_link_info(&pf->hw, true, NULL, NULL);
8308 i40e_link_event(pf);
8309
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00008310 /* Initialize user-specific link properties */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008311 pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
8312 I40E_AQ_AN_COMPLETED) ? true : false);
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00008313 /* requested_mode is set in probe or by ethtool */
8314 if (!pf->fc_autoneg_status)
8315 goto no_autoneg;
8316
8317 if ((pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) &&
8318 (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008319 pf->hw.fc.current_mode = I40E_FC_FULL;
8320 else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX)
8321 pf->hw.fc.current_mode = I40E_FC_TX_PAUSE;
8322 else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX)
8323 pf->hw.fc.current_mode = I40E_FC_RX_PAUSE;
8324 else
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00008325 pf->hw.fc.current_mode = I40E_FC_NONE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008326
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00008327 /* sync the flow control settings with the auto-neg values */
8328 switch (pf->hw.fc.current_mode) {
8329 case I40E_FC_FULL:
8330 txfc = 1;
8331 rxfc = 1;
8332 break;
8333 case I40E_FC_TX_PAUSE:
8334 txfc = 1;
8335 rxfc = 0;
8336 break;
8337 case I40E_FC_RX_PAUSE:
8338 txfc = 0;
8339 rxfc = 1;
8340 break;
8341 case I40E_FC_NONE:
8342 case I40E_FC_DEFAULT:
8343 txfc = 0;
8344 rxfc = 0;
8345 break;
8346 case I40E_FC_PFC:
8347 /* TBD */
8348 break;
8349 /* no default case, we have to handle all possibilities here */
8350 }
8351
8352 wr32(&pf->hw, I40E_PRTDCB_FCCFG, txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
8353
8354 rxfc_reg = rd32(&pf->hw, I40E_PRTDCB_MFLCN) &
8355 ~I40E_PRTDCB_MFLCN_RFCE_MASK;
8356 rxfc_reg |= (rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT);
8357
8358 wr32(&pf->hw, I40E_PRTDCB_MFLCN, rxfc_reg);
8359
8360 goto fc_complete;
8361
8362no_autoneg:
8363 /* disable L2 flow control, user can turn it on if they wish */
8364 wr32(&pf->hw, I40E_PRTDCB_FCCFG, 0);
8365 wr32(&pf->hw, I40E_PRTDCB_MFLCN, rd32(&pf->hw, I40E_PRTDCB_MFLCN) &
8366 ~I40E_PRTDCB_MFLCN_RFCE_MASK);
8367
8368fc_complete:
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00008369 i40e_ptp_init(pf);
8370
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008371 return ret;
8372}
8373
8374/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008375 * i40e_determine_queue_usage - Work out queue distribution
8376 * @pf: board private structure
8377 **/
8378static void i40e_determine_queue_usage(struct i40e_pf *pf)
8379{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008380 int queues_left;
8381
8382 pf->num_lan_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008383
8384 /* Find the max queues to be put into basic use. We'll always be
8385 * using TC0, whether or not DCB is running, and TC0 will get the
8386 * big RSS set.
8387 */
8388 queues_left = pf->hw.func_caps.num_tx_qp;
8389
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008390 if ((queues_left == 1) ||
Frank Zhang9aa7e932014-05-20 08:01:42 +00008391 !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008392 /* one qp for PF, no queues for anything else */
8393 queues_left = 0;
8394 pf->rss_size = pf->num_lan_qps = 1;
8395
8396 /* make sure all the fancies are disabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08008397 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
8398 I40E_FLAG_FD_SB_ENABLED |
8399 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008400 I40E_FLAG_DCB_CAPABLE |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08008401 I40E_FLAG_SRIOV_ENABLED |
8402 I40E_FLAG_VMDQ_ENABLED);
Frank Zhang9aa7e932014-05-20 08:01:42 +00008403 } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
8404 I40E_FLAG_FD_SB_ENABLED |
Anjali Singhai Jainbbe7d0e2014-05-20 08:01:44 +00008405 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008406 I40E_FLAG_DCB_CAPABLE))) {
Frank Zhang9aa7e932014-05-20 08:01:42 +00008407 /* one qp for PF */
8408 pf->rss_size = pf->num_lan_qps = 1;
8409 queues_left -= pf->num_lan_qps;
8410
8411 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
8412 I40E_FLAG_FD_SB_ENABLED |
8413 I40E_FLAG_FD_ATR_ENABLED |
8414 I40E_FLAG_DCB_ENABLED |
8415 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008416 } else {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008417 /* Not enough queues for all TCs */
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008418 if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008419 (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008420 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008421 dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
8422 }
8423 pf->num_lan_qps = pf->rss_size_max;
8424 queues_left -= pf->num_lan_qps;
8425 }
8426
8427 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
8428 if (queues_left > 1) {
8429 queues_left -= 1; /* save 1 queue for FD */
8430 } else {
8431 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
8432 dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
8433 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008434 }
8435
8436 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
8437 pf->num_vf_qps && pf->num_req_vfs && queues_left) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008438 pf->num_req_vfs = min_t(int, pf->num_req_vfs,
8439 (queues_left / pf->num_vf_qps));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008440 queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
8441 }
8442
8443 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
8444 pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
8445 pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
8446 (queues_left / pf->num_vmdq_qps));
8447 queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
8448 }
8449
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008450 pf->queues_left = queues_left;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008451}
8452
8453/**
8454 * i40e_setup_pf_filter_control - Setup PF static filter control
8455 * @pf: PF to be setup
8456 *
8457 * i40e_setup_pf_filter_control sets up a pf's initial filter control
8458 * settings. If PE/FCoE are enabled then it will also set the per PF
8459 * based filter sizes required for them. It also enables Flow director,
8460 * ethertype and macvlan type filter settings for the pf.
8461 *
8462 * Returns 0 on success, negative on failure
8463 **/
8464static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
8465{
8466 struct i40e_filter_control_settings *settings = &pf->filter_settings;
8467
8468 settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
8469
8470 /* Flow Director is enabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08008471 if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008472 settings->enable_fdir = true;
8473
8474 /* Ethtype and MACVLAN filters enabled for PF */
8475 settings->enable_ethtype = true;
8476 settings->enable_macvlan = true;
8477
8478 if (i40e_set_filter_control(&pf->hw, settings))
8479 return -ENOENT;
8480
8481 return 0;
8482}
8483
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +00008484#define INFO_STRING_LEN 255
8485static void i40e_print_features(struct i40e_pf *pf)
8486{
8487 struct i40e_hw *hw = &pf->hw;
8488 char *buf, *string;
8489
8490 string = kzalloc(INFO_STRING_LEN, GFP_KERNEL);
8491 if (!string) {
8492 dev_err(&pf->pdev->dev, "Features string allocation failed\n");
8493 return;
8494 }
8495
8496 buf = string;
8497
8498 buf += sprintf(string, "Features: PF-id[%d] ", hw->pf_id);
8499#ifdef CONFIG_PCI_IOV
8500 buf += sprintf(buf, "VFs: %d ", pf->num_req_vfs);
8501#endif
8502 buf += sprintf(buf, "VSIs: %d QP: %d ", pf->hw.func_caps.num_vsis,
8503 pf->vsi[pf->lan_vsi]->num_queue_pairs);
8504
8505 if (pf->flags & I40E_FLAG_RSS_ENABLED)
8506 buf += sprintf(buf, "RSS ");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +00008507 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +00008508 buf += sprintf(buf, "FD_ATR ");
8509 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
8510 buf += sprintf(buf, "FD_SB ");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +00008511 buf += sprintf(buf, "NTUPLE ");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +00008512 }
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008513 if (pf->flags & I40E_FLAG_DCB_CAPABLE)
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +00008514 buf += sprintf(buf, "DCB ");
8515 if (pf->flags & I40E_FLAG_PTP)
8516 buf += sprintf(buf, "PTP ");
8517
8518 BUG_ON(buf > (string + INFO_STRING_LEN));
8519 dev_info(&pf->pdev->dev, "%s\n", string);
8520 kfree(string);
8521}
8522
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008523/**
8524 * i40e_probe - Device initialization routine
8525 * @pdev: PCI device information struct
8526 * @ent: entry in i40e_pci_tbl
8527 *
8528 * i40e_probe initializes a pf identified by a pci_dev structure.
8529 * The OS initialization, configuring of the pf private structure,
8530 * and a hardware reset occur.
8531 *
8532 * Returns 0 on success, negative on failure
8533 **/
8534static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
8535{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008536 struct i40e_pf *pf;
8537 struct i40e_hw *hw;
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +00008538 static u16 pfs_found;
Catherine Sullivand4dfb812013-11-28 06:39:21 +00008539 u16 link_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008540 int err = 0;
8541 u32 len;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00008542 u32 i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008543
8544 err = pci_enable_device_mem(pdev);
8545 if (err)
8546 return err;
8547
8548 /* set up for high or low dma */
Mitch Williams64942942014-02-11 08:26:33 +00008549 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +00008550 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +00008551 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
8552 if (err) {
8553 dev_err(&pdev->dev,
8554 "DMA configuration failed: 0x%x\n", err);
8555 goto err_dma;
8556 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008557 }
8558
8559 /* set up pci connections */
8560 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
8561 IORESOURCE_MEM), i40e_driver_name);
8562 if (err) {
8563 dev_info(&pdev->dev,
8564 "pci_request_selected_regions failed %d\n", err);
8565 goto err_pci_reg;
8566 }
8567
8568 pci_enable_pcie_error_reporting(pdev);
8569 pci_set_master(pdev);
8570
8571 /* Now that we have a PCI connection, we need to do the
8572 * low level device setup. This is primarily setting up
8573 * the Admin Queue structures and then querying for the
8574 * device's current profile information.
8575 */
8576 pf = kzalloc(sizeof(*pf), GFP_KERNEL);
8577 if (!pf) {
8578 err = -ENOMEM;
8579 goto err_pf_alloc;
8580 }
8581 pf->next_vsi = 0;
8582 pf->pdev = pdev;
8583 set_bit(__I40E_DOWN, &pf->state);
8584
8585 hw = &pf->hw;
8586 hw->back = pf;
8587 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
8588 pci_resource_len(pdev, 0));
8589 if (!hw->hw_addr) {
8590 err = -EIO;
8591 dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
8592 (unsigned int)pci_resource_start(pdev, 0),
8593 (unsigned int)pci_resource_len(pdev, 0), err);
8594 goto err_ioremap;
8595 }
8596 hw->vendor_id = pdev->vendor;
8597 hw->device_id = pdev->device;
8598 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
8599 hw->subsystem_vendor_id = pdev->subsystem_vendor;
8600 hw->subsystem_device_id = pdev->subsystem_device;
8601 hw->bus.device = PCI_SLOT(pdev->devfn);
8602 hw->bus.func = PCI_FUNC(pdev->devfn);
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +00008603 pf->instance = pfs_found;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008604
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008605 /* do a special CORER for clearing PXE mode once at init */
8606 if (hw->revision_id == 0 &&
8607 (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
8608 wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
8609 i40e_flush(hw);
8610 msleep(200);
8611 pf->corer_count++;
8612
8613 i40e_clear_pxe_mode(hw);
8614 }
8615
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008616 /* Reset here to make sure all is clean and to define PF 'n' */
8617 err = i40e_pf_reset(hw);
8618 if (err) {
8619 dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
8620 goto err_pf_reset;
8621 }
8622 pf->pfr_count++;
8623
8624 hw->aq.num_arq_entries = I40E_AQ_LEN;
8625 hw->aq.num_asq_entries = I40E_AQ_LEN;
8626 hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
8627 hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
8628 pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
8629 snprintf(pf->misc_int_name, sizeof(pf->misc_int_name) - 1,
8630 "%s-pf%d:misc",
8631 dev_driver_string(&pf->pdev->dev), pf->hw.pf_id);
8632
8633 err = i40e_init_shared_code(hw);
8634 if (err) {
8635 dev_info(&pdev->dev, "init_shared_code failed: %d\n", err);
8636 goto err_pf_reset;
8637 }
8638
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00008639 /* set up a default setting for link flow control */
8640 pf->hw.fc.requested_mode = I40E_FC_NONE;
8641
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008642 err = i40e_init_adminq(hw);
8643 dev_info(&pdev->dev, "%s\n", i40e_fw_version_str(hw));
8644 if (err) {
8645 dev_info(&pdev->dev,
8646 "init_adminq failed: %d expecting API %02x.%02x\n",
8647 err,
8648 I40E_FW_API_VERSION_MAJOR, I40E_FW_API_VERSION_MINOR);
8649 goto err_pf_reset;
8650 }
8651
Shannon Nelson278b6f62014-06-04 01:41:03 +00008652 if (hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
8653 dev_info(&pdev->dev,
8654 "Note: FW API version %02x.%02x newer than expected %02x.%02x, recommend driver update.\n",
8655 hw->aq.api_maj_ver, hw->aq.api_min_ver,
8656 I40E_FW_API_VERSION_MAJOR, I40E_FW_API_VERSION_MINOR);
8657
8658 if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
8659 hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR-1))
8660 dev_info(&pdev->dev,
8661 "Note: FW API version %02x.%02x older than expected %02x.%02x, recommend nvm update.\n",
8662 hw->aq.api_maj_ver, hw->aq.api_min_ver,
8663 I40E_FW_API_VERSION_MAJOR, I40E_FW_API_VERSION_MINOR);
8664
8665
Shannon Nelson4eb3f762014-03-06 08:59:58 +00008666 i40e_verify_eeprom(pf);
8667
Jesse Brandeburg2c5fe332014-04-23 04:49:57 +00008668 /* Rev 0 hardware was never productized */
8669 if (hw->revision_id < 1)
8670 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");
8671
Shannon Nelson6ff4ef82013-12-21 05:44:49 +00008672 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008673 err = i40e_get_capabilities(pf);
8674 if (err)
8675 goto err_adminq_setup;
8676
8677 err = i40e_sw_init(pf);
8678 if (err) {
8679 dev_info(&pdev->dev, "sw_init failed: %d\n", err);
8680 goto err_sw_init;
8681 }
8682
8683 err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
8684 hw->func_caps.num_rx_qp,
8685 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
8686 if (err) {
8687 dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
8688 goto err_init_lan_hmc;
8689 }
8690
8691 err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
8692 if (err) {
8693 dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
8694 err = -ENOENT;
8695 goto err_configure_lan_hmc;
8696 }
8697
8698 i40e_get_mac_addr(hw, hw->mac.addr);
Jesse Brandeburgf62b5062013-11-28 06:39:27 +00008699 if (!is_valid_ether_addr(hw->mac.addr)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008700 dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
8701 err = -EIO;
8702 goto err_mac_addr;
8703 }
8704 dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
Greg Rose9a173902014-05-22 06:32:02 +00008705 ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008706
8707 pci_set_drvdata(pdev, pf);
8708 pci_save_state(pdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08008709#ifdef CONFIG_I40E_DCB
8710 err = i40e_init_pf_dcb(pf);
8711 if (err) {
8712 dev_info(&pdev->dev, "init_pf_dcb failed: %d\n", err);
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008713 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
Neerav Parikh014269f2014-04-01 07:11:48 +00008714 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08008715 }
8716#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008717
8718 /* set up periodic task facility */
8719 setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
8720 pf->service_timer_period = HZ;
8721
8722 INIT_WORK(&pf->service_task, i40e_service_task);
8723 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
8724 pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
8725 pf->link_check_timeout = jiffies;
8726
Shannon Nelson8e2773a2013-11-28 06:39:22 +00008727 /* WoL defaults to disabled */
8728 pf->wol_en = false;
8729 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
8730
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008731 /* set up the main switch operations */
8732 i40e_determine_queue_usage(pf);
8733 i40e_init_interrupt_scheme(pf);
8734
Mitch Williams505682c2014-05-20 08:01:37 +00008735 /* The number of VSIs reported by the FW is the minimum guaranteed
8736 * to us; HW supports far more and we share the remaining pool with
8737 * the other PFs. We allocate space for more than the guarantee with
8738 * the understanding that we might not get them all later.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008739 */
Mitch Williams505682c2014-05-20 08:01:37 +00008740 if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
8741 pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
8742 else
8743 pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
8744
8745 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
8746 len = sizeof(struct i40e_vsi *) * pf->num_alloc_vsi;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008747 pf->vsi = kzalloc(len, GFP_KERNEL);
Wei Yongjuned87ac02013-09-24 05:17:25 +00008748 if (!pf->vsi) {
8749 err = -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008750 goto err_switch_setup;
Wei Yongjuned87ac02013-09-24 05:17:25 +00008751 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008752
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00008753 err = i40e_setup_pf_switch(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008754 if (err) {
8755 dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
8756 goto err_vsis;
8757 }
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00008758 /* if FDIR VSI was set up, start it now */
Mitch Williams505682c2014-05-20 08:01:37 +00008759 for (i = 0; i < pf->num_alloc_vsi; i++) {
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00008760 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
8761 i40e_vsi_open(pf->vsi[i]);
8762 break;
8763 }
8764 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008765
8766 /* The main driver is (mostly) up and happy. We need to set this state
8767 * before setting up the misc vector or we get a race and the vector
8768 * ends up disabled forever.
8769 */
8770 clear_bit(__I40E_DOWN, &pf->state);
8771
8772 /* In case of MSIX we are going to setup the misc vector right here
8773 * to handle admin queue events etc. In case of legacy and MSI
8774 * the misc functionality and queue processing is combined in
8775 * the same vector and that gets setup at open.
8776 */
8777 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
8778 err = i40e_setup_misc_vector(pf);
8779 if (err) {
8780 dev_info(&pdev->dev,
8781 "setup of misc vector failed: %d\n", err);
8782 goto err_vsis;
8783 }
8784 }
8785
Greg Rosedf805f62014-04-04 04:43:16 +00008786#ifdef CONFIG_PCI_IOV
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008787 /* prep for VF support */
8788 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
Shannon Nelson4eb3f762014-03-06 08:59:58 +00008789 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
8790 !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008791 u32 val;
8792
8793 /* disable link interrupts for VFs */
8794 val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
8795 val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
8796 wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
8797 i40e_flush(hw);
Mitch Williams4aeec012014-02-13 03:48:47 -08008798
8799 if (pci_num_vf(pdev)) {
8800 dev_info(&pdev->dev,
8801 "Active VFs found, allocating resources.\n");
8802 err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
8803 if (err)
8804 dev_info(&pdev->dev,
8805 "Error %d allocating resources for existing VFs\n",
8806 err);
8807 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008808 }
Greg Rosedf805f62014-04-04 04:43:16 +00008809#endif /* CONFIG_PCI_IOV */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008810
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +00008811 pfs_found++;
8812
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008813 i40e_dbg_pf_init(pf);
8814
8815 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00008816 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008817
8818 /* since everything's happy, start the service_task timer */
8819 mod_timer(&pf->service_timer,
8820 round_jiffies(jiffies + pf->service_timer_period));
8821
Catherine Sullivand4dfb812013-11-28 06:39:21 +00008822 /* Get the negotiated link width and speed from PCI config space */
8823 pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, &link_status);
8824
8825 i40e_set_pci_config_data(hw, link_status);
8826
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00008827 dev_info(&pdev->dev, "PCI-Express: %s %s\n",
Catherine Sullivand4dfb812013-11-28 06:39:21 +00008828 (hw->bus.speed == i40e_bus_speed_8000 ? "Speed 8.0GT/s" :
8829 hw->bus.speed == i40e_bus_speed_5000 ? "Speed 5.0GT/s" :
8830 hw->bus.speed == i40e_bus_speed_2500 ? "Speed 2.5GT/s" :
8831 "Unknown"),
8832 (hw->bus.width == i40e_bus_width_pcie_x8 ? "Width x8" :
8833 hw->bus.width == i40e_bus_width_pcie_x4 ? "Width x4" :
8834 hw->bus.width == i40e_bus_width_pcie_x2 ? "Width x2" :
8835 hw->bus.width == i40e_bus_width_pcie_x1 ? "Width x1" :
8836 "Unknown"));
8837
8838 if (hw->bus.width < i40e_bus_width_pcie_x8 ||
8839 hw->bus.speed < i40e_bus_speed_8000) {
8840 dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
8841 dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
8842 }
8843
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +00008844 /* print a string summarizing features */
8845 i40e_print_features(pf);
8846
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008847 return 0;
8848
8849 /* Unwind what we've done if something failed in the setup */
8850err_vsis:
8851 set_bit(__I40E_DOWN, &pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008852 i40e_clear_interrupt_scheme(pf);
8853 kfree(pf->vsi);
Shannon Nelson04b03012013-11-28 06:39:34 +00008854err_switch_setup:
8855 i40e_reset_interrupt_capability(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008856 del_timer_sync(&pf->service_timer);
8857err_mac_addr:
8858err_configure_lan_hmc:
8859 (void)i40e_shutdown_lan_hmc(hw);
8860err_init_lan_hmc:
8861 kfree(pf->qp_pile);
8862 kfree(pf->irq_pile);
8863err_sw_init:
8864err_adminq_setup:
8865 (void)i40e_shutdown_adminq(hw);
8866err_pf_reset:
8867 iounmap(hw->hw_addr);
8868err_ioremap:
8869 kfree(pf);
8870err_pf_alloc:
8871 pci_disable_pcie_error_reporting(pdev);
8872 pci_release_selected_regions(pdev,
8873 pci_select_bars(pdev, IORESOURCE_MEM));
8874err_pci_reg:
8875err_dma:
8876 pci_disable_device(pdev);
8877 return err;
8878}
8879
8880/**
8881 * i40e_remove - Device removal routine
8882 * @pdev: PCI device information struct
8883 *
8884 * i40e_remove is called by the PCI subsystem to alert the driver
8885 * that is should release a PCI device. This could be caused by a
8886 * Hot-Plug event, or because the driver is going to be removed from
8887 * memory.
8888 **/
8889static void i40e_remove(struct pci_dev *pdev)
8890{
8891 struct i40e_pf *pf = pci_get_drvdata(pdev);
8892 i40e_status ret_code;
8893 u32 reg;
8894 int i;
8895
8896 i40e_dbg_pf_exit(pf);
8897
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00008898 i40e_ptp_stop(pf);
8899
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008900 /* no more scheduling of any task */
8901 set_bit(__I40E_DOWN, &pf->state);
8902 del_timer_sync(&pf->service_timer);
8903 cancel_work_sync(&pf->service_task);
8904
Mitch Williamseb2d80b2014-02-13 03:48:48 -08008905 if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
8906 i40e_free_vfs(pf);
8907 pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
8908 }
8909
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008910 i40e_fdir_teardown(pf);
8911
8912 /* If there is a switch structure or any orphans, remove them.
8913 * This will leave only the PF's VSI remaining.
8914 */
8915 for (i = 0; i < I40E_MAX_VEB; i++) {
8916 if (!pf->veb[i])
8917 continue;
8918
8919 if (pf->veb[i]->uplink_seid == pf->mac_seid ||
8920 pf->veb[i]->uplink_seid == 0)
8921 i40e_switch_branch_release(pf->veb[i]);
8922 }
8923
8924 /* Now we can shutdown the PF's VSI, just before we kill
8925 * adminq and hmc.
8926 */
8927 if (pf->vsi[pf->lan_vsi])
8928 i40e_vsi_release(pf->vsi[pf->lan_vsi]);
8929
8930 i40e_stop_misc_vector(pf);
8931 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
8932 synchronize_irq(pf->msix_entries[0].vector);
8933 free_irq(pf->msix_entries[0].vector, pf);
8934 }
8935
8936 /* shutdown and destroy the HMC */
Shannon Nelson60442de2014-04-23 04:50:13 +00008937 if (pf->hw.hmc.hmc_obj) {
8938 ret_code = i40e_shutdown_lan_hmc(&pf->hw);
8939 if (ret_code)
8940 dev_warn(&pdev->dev,
8941 "Failed to destroy the HMC resources: %d\n",
8942 ret_code);
8943 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008944
8945 /* shutdown the adminq */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008946 ret_code = i40e_shutdown_adminq(&pf->hw);
8947 if (ret_code)
8948 dev_warn(&pdev->dev,
8949 "Failed to destroy the Admin Queue resources: %d\n",
8950 ret_code);
8951
8952 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
8953 i40e_clear_interrupt_scheme(pf);
Mitch Williams505682c2014-05-20 08:01:37 +00008954 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008955 if (pf->vsi[i]) {
8956 i40e_vsi_clear_rings(pf->vsi[i]);
8957 i40e_vsi_clear(pf->vsi[i]);
8958 pf->vsi[i] = NULL;
8959 }
8960 }
8961
8962 for (i = 0; i < I40E_MAX_VEB; i++) {
8963 kfree(pf->veb[i]);
8964 pf->veb[i] = NULL;
8965 }
8966
8967 kfree(pf->qp_pile);
8968 kfree(pf->irq_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008969 kfree(pf->vsi);
8970
8971 /* force a PF reset to clean anything leftover */
8972 reg = rd32(&pf->hw, I40E_PFGEN_CTRL);
8973 wr32(&pf->hw, I40E_PFGEN_CTRL, (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
8974 i40e_flush(&pf->hw);
8975
8976 iounmap(pf->hw.hw_addr);
8977 kfree(pf);
8978 pci_release_selected_regions(pdev,
8979 pci_select_bars(pdev, IORESOURCE_MEM));
8980
8981 pci_disable_pcie_error_reporting(pdev);
8982 pci_disable_device(pdev);
8983}
8984
8985/**
8986 * i40e_pci_error_detected - warning that something funky happened in PCI land
8987 * @pdev: PCI device information struct
8988 *
8989 * Called to warn that something happened and the error handling steps
8990 * are in progress. Allows the driver to quiesce things, be ready for
8991 * remediation.
8992 **/
8993static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
8994 enum pci_channel_state error)
8995{
8996 struct i40e_pf *pf = pci_get_drvdata(pdev);
8997
8998 dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
8999
9000 /* shutdown all operations */
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009001 if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
9002 rtnl_lock();
9003 i40e_prep_for_reset(pf);
9004 rtnl_unlock();
9005 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009006
9007 /* Request a slot reset */
9008 return PCI_ERS_RESULT_NEED_RESET;
9009}
9010
9011/**
9012 * i40e_pci_error_slot_reset - a PCI slot reset just happened
9013 * @pdev: PCI device information struct
9014 *
9015 * Called to find if the driver can work with the device now that
9016 * the pci slot has been reset. If a basic connection seems good
9017 * (registers are readable and have sane content) then return a
9018 * happy little PCI_ERS_RESULT_xxx.
9019 **/
9020static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
9021{
9022 struct i40e_pf *pf = pci_get_drvdata(pdev);
9023 pci_ers_result_t result;
9024 int err;
9025 u32 reg;
9026
9027 dev_info(&pdev->dev, "%s\n", __func__);
9028 if (pci_enable_device_mem(pdev)) {
9029 dev_info(&pdev->dev,
9030 "Cannot re-enable PCI device after reset.\n");
9031 result = PCI_ERS_RESULT_DISCONNECT;
9032 } else {
9033 pci_set_master(pdev);
9034 pci_restore_state(pdev);
9035 pci_save_state(pdev);
9036 pci_wake_from_d3(pdev, false);
9037
9038 reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
9039 if (reg == 0)
9040 result = PCI_ERS_RESULT_RECOVERED;
9041 else
9042 result = PCI_ERS_RESULT_DISCONNECT;
9043 }
9044
9045 err = pci_cleanup_aer_uncorrect_error_status(pdev);
9046 if (err) {
9047 dev_info(&pdev->dev,
9048 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
9049 err);
9050 /* non-fatal, continue */
9051 }
9052
9053 return result;
9054}
9055
9056/**
9057 * i40e_pci_error_resume - restart operations after PCI error recovery
9058 * @pdev: PCI device information struct
9059 *
9060 * Called to allow the driver to bring things back up after PCI error
9061 * and/or reset recovery has finished.
9062 **/
9063static void i40e_pci_error_resume(struct pci_dev *pdev)
9064{
9065 struct i40e_pf *pf = pci_get_drvdata(pdev);
9066
9067 dev_info(&pdev->dev, "%s\n", __func__);
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009068 if (test_bit(__I40E_SUSPENDED, &pf->state))
9069 return;
9070
9071 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009072 i40e_handle_reset_warning(pf);
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009073 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009074}
9075
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009076/**
9077 * i40e_shutdown - PCI callback for shutting down
9078 * @pdev: PCI device information struct
9079 **/
9080static void i40e_shutdown(struct pci_dev *pdev)
9081{
9082 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +00009083 struct i40e_hw *hw = &pf->hw;
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009084
9085 set_bit(__I40E_SUSPENDED, &pf->state);
9086 set_bit(__I40E_DOWN, &pf->state);
9087 rtnl_lock();
9088 i40e_prep_for_reset(pf);
9089 rtnl_unlock();
9090
Shannon Nelson8e2773a2013-11-28 06:39:22 +00009091 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
9092 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
9093
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009094 if (system_state == SYSTEM_POWER_OFF) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00009095 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009096 pci_set_power_state(pdev, PCI_D3hot);
9097 }
9098}
9099
9100#ifdef CONFIG_PM
9101/**
9102 * i40e_suspend - PCI callback for moving to D3
9103 * @pdev: PCI device information struct
9104 **/
9105static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
9106{
9107 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +00009108 struct i40e_hw *hw = &pf->hw;
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009109
9110 set_bit(__I40E_SUSPENDED, &pf->state);
9111 set_bit(__I40E_DOWN, &pf->state);
9112 rtnl_lock();
9113 i40e_prep_for_reset(pf);
9114 rtnl_unlock();
9115
Shannon Nelson8e2773a2013-11-28 06:39:22 +00009116 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
9117 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
9118
9119 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009120 pci_set_power_state(pdev, PCI_D3hot);
9121
9122 return 0;
9123}
9124
9125/**
9126 * i40e_resume - PCI callback for waking up from D3
9127 * @pdev: PCI device information struct
9128 **/
9129static int i40e_resume(struct pci_dev *pdev)
9130{
9131 struct i40e_pf *pf = pci_get_drvdata(pdev);
9132 u32 err;
9133
9134 pci_set_power_state(pdev, PCI_D0);
9135 pci_restore_state(pdev);
9136 /* pci_restore_state() clears dev->state_saves, so
9137 * call pci_save_state() again to restore it.
9138 */
9139 pci_save_state(pdev);
9140
9141 err = pci_enable_device_mem(pdev);
9142 if (err) {
9143 dev_err(&pdev->dev,
9144 "%s: Cannot enable PCI device from suspend\n",
9145 __func__);
9146 return err;
9147 }
9148 pci_set_master(pdev);
9149
9150 /* no wakeup events while running */
9151 pci_wake_from_d3(pdev, false);
9152
9153 /* handling the reset will rebuild the device state */
9154 if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
9155 clear_bit(__I40E_DOWN, &pf->state);
9156 rtnl_lock();
9157 i40e_reset_and_rebuild(pf, false);
9158 rtnl_unlock();
9159 }
9160
9161 return 0;
9162}
9163
9164#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009165static const struct pci_error_handlers i40e_err_handler = {
9166 .error_detected = i40e_pci_error_detected,
9167 .slot_reset = i40e_pci_error_slot_reset,
9168 .resume = i40e_pci_error_resume,
9169};
9170
9171static struct pci_driver i40e_driver = {
9172 .name = i40e_driver_name,
9173 .id_table = i40e_pci_tbl,
9174 .probe = i40e_probe,
9175 .remove = i40e_remove,
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009176#ifdef CONFIG_PM
9177 .suspend = i40e_suspend,
9178 .resume = i40e_resume,
9179#endif
9180 .shutdown = i40e_shutdown,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009181 .err_handler = &i40e_err_handler,
9182 .sriov_configure = i40e_pci_sriov_configure,
9183};
9184
9185/**
9186 * i40e_init_module - Driver registration routine
9187 *
9188 * i40e_init_module is the first routine called when the driver is
9189 * loaded. All it does is register with the PCI subsystem.
9190 **/
9191static int __init i40e_init_module(void)
9192{
9193 pr_info("%s: %s - version %s\n", i40e_driver_name,
9194 i40e_driver_string, i40e_driver_version_str);
9195 pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
9196 i40e_dbg_init();
9197 return pci_register_driver(&i40e_driver);
9198}
9199module_init(i40e_init_module);
9200
9201/**
9202 * i40e_exit_module - Driver exit cleanup routine
9203 *
9204 * i40e_exit_module is called just before the driver is removed
9205 * from memory.
9206 **/
9207static void __exit i40e_exit_module(void)
9208{
9209 pci_unregister_driver(&i40e_driver);
9210 i40e_dbg_exit();
9211}
9212module_exit(i40e_exit_module);