blob: 2c285385b4cb92ea497bc974764db669cd40793a [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 Sullivan25941f92014-06-04 01:23:27 +000042#define DRV_VERSION_BUILD 17
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)))
Anjali Singhai Jain327fe042014-06-04 01:23:26 +0000281 pf->tx_timeout_recovery_level = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +0000282 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
Anjali Singhai Jain80f64282013-11-28 06:39:47 +00001330 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
1331 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
1332 return -EADDRNOTAVAIL;
1333
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001334 if (vsi->type == I40E_VSI_MAIN) {
1335 i40e_status ret;
1336 ret = i40e_aq_mac_address_write(&vsi->back->hw,
Shannon Nelsoncc412222014-06-04 01:23:21 +00001337 I40E_AQC_WRITE_TYPE_LAA_WOL,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001338 addr->sa_data, NULL);
1339 if (ret) {
1340 netdev_info(netdev,
1341 "Addr change for Main VSI failed: %d\n",
1342 ret);
1343 return -EADDRNOTAVAIL;
1344 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001345 }
1346
Shannon Nelson6252c7e2014-06-04 01:23:23 +00001347 f = i40e_find_mac(vsi, addr->sa_data, false, true);
1348 if (!f) {
Shannon Nelson6c8ad1b2014-06-04 01:23:22 +00001349 /* In order to be sure to not drop any packets, add the
1350 * new address first then delete the old one.
1351 */
1352 f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY,
1353 false, false);
1354 if (!f)
1355 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001356
Shannon Nelson6c8ad1b2014-06-04 01:23:22 +00001357 i40e_sync_vsi_filters(vsi);
1358 i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
1359 false, false);
1360 i40e_sync_vsi_filters(vsi);
1361 }
1362
Shannon Nelson6252c7e2014-06-04 01:23:23 +00001363 f->is_laa = true;
Shannon Nelson6c8ad1b2014-06-04 01:23:22 +00001364 if (!ether_addr_equal(netdev->dev_addr, addr->sa_data))
1365 ether_addr_copy(netdev->dev_addr, addr->sa_data);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001366
1367 return 0;
1368}
1369
1370/**
1371 * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
1372 * @vsi: the VSI being setup
1373 * @ctxt: VSI context structure
1374 * @enabled_tc: Enabled TCs bitmap
1375 * @is_add: True if called before Add VSI
1376 *
1377 * Setup VSI queue mapping for enabled traffic classes.
1378 **/
1379static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
1380 struct i40e_vsi_context *ctxt,
1381 u8 enabled_tc,
1382 bool is_add)
1383{
1384 struct i40e_pf *pf = vsi->back;
1385 u16 sections = 0;
1386 u8 netdev_tc = 0;
1387 u16 numtc = 0;
1388 u16 qcount;
1389 u8 offset;
1390 u16 qmap;
1391 int i;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001392 u16 num_tc_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001393
1394 sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
1395 offset = 0;
1396
1397 if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
1398 /* Find numtc from enabled TC bitmap */
1399 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1400 if (enabled_tc & (1 << i)) /* TC is enabled */
1401 numtc++;
1402 }
1403 if (!numtc) {
1404 dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
1405 numtc = 1;
1406 }
1407 } else {
1408 /* At least TC0 is enabled in case of non-DCB case */
1409 numtc = 1;
1410 }
1411
1412 vsi->tc_config.numtc = numtc;
1413 vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001414 /* Number of queues per enabled TC */
Anjali Singhai Jaineb051af2014-05-20 08:01:46 +00001415 num_tc_qps = vsi->alloc_queue_pairs/numtc;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001416 num_tc_qps = min_t(int, num_tc_qps, I40E_MAX_QUEUES_PER_TC);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001417
1418 /* Setup queue offset/count for all TCs for given VSI */
1419 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1420 /* See if the given TC is enabled for the given VSI */
1421 if (vsi->tc_config.enabled_tc & (1 << i)) { /* TC is enabled */
1422 int pow, num_qps;
1423
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001424 switch (vsi->type) {
1425 case I40E_VSI_MAIN:
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001426 qcount = min_t(int, pf->rss_size, num_tc_qps);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001427 break;
1428 case I40E_VSI_FDIR:
1429 case I40E_VSI_SRIOV:
1430 case I40E_VSI_VMDQ2:
1431 default:
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001432 qcount = num_tc_qps;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001433 WARN_ON(i != 0);
1434 break;
1435 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001436 vsi->tc_config.tc_info[i].qoffset = offset;
1437 vsi->tc_config.tc_info[i].qcount = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001438
1439 /* find the power-of-2 of the number of queue pairs */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001440 num_qps = qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001441 pow = 0;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001442 while (num_qps && ((1 << pow) < qcount)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001443 pow++;
1444 num_qps >>= 1;
1445 }
1446
1447 vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
1448 qmap =
1449 (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
1450 (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
1451
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08001452 offset += qcount;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001453 } else {
1454 /* TC is not enabled so set the offset to
1455 * default queue and allocate one queue
1456 * for the given TC.
1457 */
1458 vsi->tc_config.tc_info[i].qoffset = 0;
1459 vsi->tc_config.tc_info[i].qcount = 1;
1460 vsi->tc_config.tc_info[i].netdev_tc = 0;
1461
1462 qmap = 0;
1463 }
1464 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
1465 }
1466
1467 /* Set actual Tx/Rx queue pairs */
1468 vsi->num_queue_pairs = offset;
1469
1470 /* Scheduler section valid can only be set for ADD VSI */
1471 if (is_add) {
1472 sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
1473
1474 ctxt->info.up_enable_bits = enabled_tc;
1475 }
1476 if (vsi->type == I40E_VSI_SRIOV) {
1477 ctxt->info.mapping_flags |=
1478 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
1479 for (i = 0; i < vsi->num_queue_pairs; i++)
1480 ctxt->info.queue_mapping[i] =
1481 cpu_to_le16(vsi->base_queue + i);
1482 } else {
1483 ctxt->info.mapping_flags |=
1484 cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
1485 ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
1486 }
1487 ctxt->info.valid_sections |= cpu_to_le16(sections);
1488}
1489
1490/**
1491 * i40e_set_rx_mode - NDO callback to set the netdev filters
1492 * @netdev: network interface device structure
1493 **/
1494static void i40e_set_rx_mode(struct net_device *netdev)
1495{
1496 struct i40e_netdev_priv *np = netdev_priv(netdev);
1497 struct i40e_mac_filter *f, *ftmp;
1498 struct i40e_vsi *vsi = np->vsi;
1499 struct netdev_hw_addr *uca;
1500 struct netdev_hw_addr *mca;
1501 struct netdev_hw_addr *ha;
1502
1503 /* add addr if not already in the filter list */
1504 netdev_for_each_uc_addr(uca, netdev) {
1505 if (!i40e_find_mac(vsi, uca->addr, false, true)) {
1506 if (i40e_is_vsi_in_vlan(vsi))
1507 i40e_put_mac_in_vlan(vsi, uca->addr,
1508 false, true);
1509 else
1510 i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY,
1511 false, true);
1512 }
1513 }
1514
1515 netdev_for_each_mc_addr(mca, netdev) {
1516 if (!i40e_find_mac(vsi, mca->addr, false, true)) {
1517 if (i40e_is_vsi_in_vlan(vsi))
1518 i40e_put_mac_in_vlan(vsi, mca->addr,
1519 false, true);
1520 else
1521 i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY,
1522 false, true);
1523 }
1524 }
1525
1526 /* remove filter if not in netdev list */
1527 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1528 bool found = false;
1529
1530 if (!f->is_netdev)
1531 continue;
1532
1533 if (is_multicast_ether_addr(f->macaddr)) {
1534 netdev_for_each_mc_addr(mca, netdev) {
1535 if (ether_addr_equal(mca->addr, f->macaddr)) {
1536 found = true;
1537 break;
1538 }
1539 }
1540 } else {
1541 netdev_for_each_uc_addr(uca, netdev) {
1542 if (ether_addr_equal(uca->addr, f->macaddr)) {
1543 found = true;
1544 break;
1545 }
1546 }
1547
1548 for_each_dev_addr(netdev, ha) {
1549 if (ether_addr_equal(ha->addr, f->macaddr)) {
1550 found = true;
1551 break;
1552 }
1553 }
1554 }
1555 if (!found)
1556 i40e_del_filter(
1557 vsi, f->macaddr, I40E_VLAN_ANY, false, true);
1558 }
1559
1560 /* check for other flag changes */
1561 if (vsi->current_netdev_flags != vsi->netdev->flags) {
1562 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
1563 vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
1564 }
1565}
1566
1567/**
1568 * i40e_sync_vsi_filters - Update the VSI filter list to the HW
1569 * @vsi: ptr to the VSI
1570 *
1571 * Push any outstanding VSI filter changes through the AdminQ.
1572 *
1573 * Returns 0 or error value
1574 **/
1575int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
1576{
1577 struct i40e_mac_filter *f, *ftmp;
1578 bool promisc_forced_on = false;
1579 bool add_happened = false;
1580 int filter_list_len = 0;
1581 u32 changed_flags = 0;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001582 i40e_status aq_ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001583 struct i40e_pf *pf;
1584 int num_add = 0;
1585 int num_del = 0;
1586 u16 cmd_flags;
1587
1588 /* empty array typed pointers, kcalloc later */
1589 struct i40e_aqc_add_macvlan_element_data *add_list;
1590 struct i40e_aqc_remove_macvlan_element_data *del_list;
1591
1592 while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
1593 usleep_range(1000, 2000);
1594 pf = vsi->back;
1595
1596 if (vsi->netdev) {
1597 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
1598 vsi->current_netdev_flags = vsi->netdev->flags;
1599 }
1600
1601 if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
1602 vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
1603
1604 filter_list_len = pf->hw.aq.asq_buf_size /
1605 sizeof(struct i40e_aqc_remove_macvlan_element_data);
1606 del_list = kcalloc(filter_list_len,
1607 sizeof(struct i40e_aqc_remove_macvlan_element_data),
1608 GFP_KERNEL);
1609 if (!del_list)
1610 return -ENOMEM;
1611
1612 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1613 if (!f->changed)
1614 continue;
1615
1616 if (f->counter != 0)
1617 continue;
1618 f->changed = false;
1619 cmd_flags = 0;
1620
1621 /* add to delete list */
Greg Rose9a173902014-05-22 06:32:02 +00001622 ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001623 del_list[num_del].vlan_tag =
1624 cpu_to_le16((u16)(f->vlan ==
1625 I40E_VLAN_ANY ? 0 : f->vlan));
1626
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001627 cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
1628 del_list[num_del].flags = cmd_flags;
1629 num_del++;
1630
1631 /* unlink from filter list */
1632 list_del(&f->list);
1633 kfree(f);
1634
1635 /* flush a full buffer */
1636 if (num_del == filter_list_len) {
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001637 aq_ret = i40e_aq_remove_macvlan(&pf->hw,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001638 vsi->seid, del_list, num_del,
1639 NULL);
1640 num_del = 0;
1641 memset(del_list, 0, sizeof(*del_list));
1642
Shannon Nelsonfdfe9cb2014-05-20 08:01:39 +00001643 if (aq_ret &&
1644 pf->hw.aq.asq_last_status !=
1645 I40E_AQ_RC_ENOENT)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001646 dev_info(&pf->pdev->dev,
1647 "ignoring delete macvlan error, err %d, aq_err %d while flushing a full buffer\n",
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001648 aq_ret,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001649 pf->hw.aq.asq_last_status);
1650 }
1651 }
1652 if (num_del) {
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001653 aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001654 del_list, num_del, NULL);
1655 num_del = 0;
1656
Shannon Nelsonfdfe9cb2014-05-20 08:01:39 +00001657 if (aq_ret &&
1658 pf->hw.aq.asq_last_status != I40E_AQ_RC_ENOENT)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001659 dev_info(&pf->pdev->dev,
1660 "ignoring delete macvlan error, err %d, aq_err %d\n",
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001661 aq_ret, pf->hw.aq.asq_last_status);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001662 }
1663
1664 kfree(del_list);
1665 del_list = NULL;
1666
1667 /* do all the adds now */
1668 filter_list_len = pf->hw.aq.asq_buf_size /
1669 sizeof(struct i40e_aqc_add_macvlan_element_data),
1670 add_list = kcalloc(filter_list_len,
1671 sizeof(struct i40e_aqc_add_macvlan_element_data),
1672 GFP_KERNEL);
1673 if (!add_list)
1674 return -ENOMEM;
1675
1676 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
1677 if (!f->changed)
1678 continue;
1679
1680 if (f->counter == 0)
1681 continue;
1682 f->changed = false;
1683 add_happened = true;
1684 cmd_flags = 0;
1685
1686 /* add to add array */
Greg Rose9a173902014-05-22 06:32:02 +00001687 ether_addr_copy(add_list[num_add].mac_addr, f->macaddr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001688 add_list[num_add].vlan_tag =
1689 cpu_to_le16(
1690 (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan));
1691 add_list[num_add].queue_number = 0;
1692
1693 cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001694 add_list[num_add].flags = cpu_to_le16(cmd_flags);
1695 num_add++;
1696
1697 /* flush a full buffer */
1698 if (num_add == filter_list_len) {
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001699 aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
1700 add_list, num_add,
1701 NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001702 num_add = 0;
1703
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001704 if (aq_ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001705 break;
1706 memset(add_list, 0, sizeof(*add_list));
1707 }
1708 }
1709 if (num_add) {
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001710 aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
1711 add_list, num_add, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001712 num_add = 0;
1713 }
1714 kfree(add_list);
1715 add_list = NULL;
1716
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001717 if (add_happened && (!aq_ret)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001718 /* do nothing */;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001719 } else if (add_happened && (aq_ret)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001720 dev_info(&pf->pdev->dev,
1721 "add filter failed, err %d, aq_err %d\n",
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001722 aq_ret, pf->hw.aq.asq_last_status);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001723 if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) &&
1724 !test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
1725 &vsi->state)) {
1726 promisc_forced_on = true;
1727 set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
1728 &vsi->state);
1729 dev_info(&pf->pdev->dev, "promiscuous mode forced on\n");
1730 }
1731 }
1732 }
1733
1734 /* check for changes in promiscuous modes */
1735 if (changed_flags & IFF_ALLMULTI) {
1736 bool cur_multipromisc;
1737 cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001738 aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
1739 vsi->seid,
1740 cur_multipromisc,
1741 NULL);
1742 if (aq_ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001743 dev_info(&pf->pdev->dev,
1744 "set multi promisc failed, err %d, aq_err %d\n",
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001745 aq_ret, pf->hw.aq.asq_last_status);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001746 }
1747 if ((changed_flags & IFF_PROMISC) || promisc_forced_on) {
1748 bool cur_promisc;
1749 cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
1750 test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
1751 &vsi->state));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001752 aq_ret = i40e_aq_set_vsi_unicast_promiscuous(&vsi->back->hw,
1753 vsi->seid,
1754 cur_promisc, NULL);
1755 if (aq_ret)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001756 dev_info(&pf->pdev->dev,
1757 "set uni promisc failed, err %d, aq_err %d\n",
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00001758 aq_ret, pf->hw.aq.asq_last_status);
Greg Rose1a103702013-11-28 06:42:39 +00001759 aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
1760 vsi->seid,
1761 cur_promisc, NULL);
1762 if (aq_ret)
1763 dev_info(&pf->pdev->dev,
1764 "set brdcast promisc failed, err %d, aq_err %d\n",
1765 aq_ret, pf->hw.aq.asq_last_status);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001766 }
1767
1768 clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
1769 return 0;
1770}
1771
1772/**
1773 * i40e_sync_filters_subtask - Sync the VSI filter list with HW
1774 * @pf: board private structure
1775 **/
1776static void i40e_sync_filters_subtask(struct i40e_pf *pf)
1777{
1778 int v;
1779
1780 if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
1781 return;
1782 pf->flags &= ~I40E_FLAG_FILTER_SYNC;
1783
Mitch Williams505682c2014-05-20 08:01:37 +00001784 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001785 if (pf->vsi[v] &&
1786 (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED))
1787 i40e_sync_vsi_filters(pf->vsi[v]);
1788 }
1789}
1790
1791/**
1792 * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
1793 * @netdev: network interface device structure
1794 * @new_mtu: new value for maximum frame size
1795 *
1796 * Returns 0 on success, negative on failure
1797 **/
1798static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
1799{
1800 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jesse Brandeburg61a46a42014-04-23 04:50:05 +00001801 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001802 struct i40e_vsi *vsi = np->vsi;
1803
1804 /* MTU < 68 is an error and causes problems on some kernels */
1805 if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
1806 return -EINVAL;
1807
1808 netdev_info(netdev, "changing MTU from %d to %d\n",
1809 netdev->mtu, new_mtu);
1810 netdev->mtu = new_mtu;
1811 if (netif_running(netdev))
1812 i40e_vsi_reinit_locked(vsi);
1813
1814 return 0;
1815}
1816
1817/**
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001818 * i40e_ioctl - Access the hwtstamp interface
1819 * @netdev: network interface device structure
1820 * @ifr: interface request data
1821 * @cmd: ioctl command
1822 **/
1823int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
1824{
1825 struct i40e_netdev_priv *np = netdev_priv(netdev);
1826 struct i40e_pf *pf = np->vsi->back;
1827
1828 switch (cmd) {
1829 case SIOCGHWTSTAMP:
1830 return i40e_ptp_get_ts_config(pf, ifr);
1831 case SIOCSHWTSTAMP:
1832 return i40e_ptp_set_ts_config(pf, ifr);
1833 default:
1834 return -EOPNOTSUPP;
1835 }
1836}
1837
1838/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001839 * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
1840 * @vsi: the vsi being adjusted
1841 **/
1842void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
1843{
1844 struct i40e_vsi_context ctxt;
1845 i40e_status ret;
1846
1847 if ((vsi->info.valid_sections &
1848 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
1849 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
1850 return; /* already enabled */
1851
1852 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
1853 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
1854 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
1855
1856 ctxt.seid = vsi->seid;
1857 memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
1858 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
1859 if (ret) {
1860 dev_info(&vsi->back->pdev->dev,
1861 "%s: update vsi failed, aq_err=%d\n",
1862 __func__, vsi->back->hw.aq.asq_last_status);
1863 }
1864}
1865
1866/**
1867 * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
1868 * @vsi: the vsi being adjusted
1869 **/
1870void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
1871{
1872 struct i40e_vsi_context ctxt;
1873 i40e_status ret;
1874
1875 if ((vsi->info.valid_sections &
1876 cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
1877 ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
1878 I40E_AQ_VSI_PVLAN_EMOD_MASK))
1879 return; /* already disabled */
1880
1881 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
1882 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
1883 I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
1884
1885 ctxt.seid = vsi->seid;
1886 memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
1887 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
1888 if (ret) {
1889 dev_info(&vsi->back->pdev->dev,
1890 "%s: update vsi failed, aq_err=%d\n",
1891 __func__, vsi->back->hw.aq.asq_last_status);
1892 }
1893}
1894
1895/**
1896 * i40e_vlan_rx_register - Setup or shutdown vlan offload
1897 * @netdev: network interface to be adjusted
1898 * @features: netdev features to test if VLAN offload is enabled or not
1899 **/
1900static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
1901{
1902 struct i40e_netdev_priv *np = netdev_priv(netdev);
1903 struct i40e_vsi *vsi = np->vsi;
1904
1905 if (features & NETIF_F_HW_VLAN_CTAG_RX)
1906 i40e_vlan_stripping_enable(vsi);
1907 else
1908 i40e_vlan_stripping_disable(vsi);
1909}
1910
1911/**
1912 * i40e_vsi_add_vlan - Add vsi membership for given vlan
1913 * @vsi: the vsi being configured
1914 * @vid: vlan id to be added (0 = untagged only , -1 = any)
1915 **/
1916int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
1917{
1918 struct i40e_mac_filter *f, *add_f;
1919 bool is_netdev, is_vf;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001920
1921 is_vf = (vsi->type == I40E_VSI_SRIOV);
1922 is_netdev = !!(vsi->netdev);
1923
1924 if (is_netdev) {
1925 add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid,
1926 is_vf, is_netdev);
1927 if (!add_f) {
1928 dev_info(&vsi->back->pdev->dev,
1929 "Could not add vlan filter %d for %pM\n",
1930 vid, vsi->netdev->dev_addr);
1931 return -ENOMEM;
1932 }
1933 }
1934
1935 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1936 add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
1937 if (!add_f) {
1938 dev_info(&vsi->back->pdev->dev,
1939 "Could not add vlan filter %d for %pM\n",
1940 vid, f->macaddr);
1941 return -ENOMEM;
1942 }
1943 }
1944
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001945 /* Now if we add a vlan tag, make sure to check if it is the first
1946 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
1947 * with 0, so we now accept untagged and specified tagged traffic
1948 * (and not any taged and untagged)
1949 */
1950 if (vid > 0) {
1951 if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr,
1952 I40E_VLAN_ANY,
1953 is_vf, is_netdev)) {
1954 i40e_del_filter(vsi, vsi->netdev->dev_addr,
1955 I40E_VLAN_ANY, is_vf, is_netdev);
1956 add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0,
1957 is_vf, is_netdev);
1958 if (!add_f) {
1959 dev_info(&vsi->back->pdev->dev,
1960 "Could not add filter 0 for %pM\n",
1961 vsi->netdev->dev_addr);
1962 return -ENOMEM;
1963 }
1964 }
Greg Rose8d82a7c2014-01-13 16:13:04 -08001965 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001966
Greg Rose8d82a7c2014-01-13 16:13:04 -08001967 /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
1968 if (vid > 0 && !vsi->info.pvid) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001969 list_for_each_entry(f, &vsi->mac_filter_list, list) {
1970 if (i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY,
1971 is_vf, is_netdev)) {
1972 i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY,
1973 is_vf, is_netdev);
1974 add_f = i40e_add_filter(vsi, f->macaddr,
1975 0, is_vf, is_netdev);
1976 if (!add_f) {
1977 dev_info(&vsi->back->pdev->dev,
1978 "Could not add filter 0 for %pM\n",
1979 f->macaddr);
1980 return -ENOMEM;
1981 }
1982 }
1983 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001984 }
1985
Anjali Singhai Jain80f64282013-11-28 06:39:47 +00001986 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
1987 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
1988 return 0;
1989
1990 return i40e_sync_vsi_filters(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001991}
1992
1993/**
1994 * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
1995 * @vsi: the vsi being configured
1996 * @vid: vlan id to be removed (0 = untagged only , -1 = any)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00001997 *
1998 * Return: 0 on success or negative otherwise
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00001999 **/
2000int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
2001{
2002 struct net_device *netdev = vsi->netdev;
2003 struct i40e_mac_filter *f, *add_f;
2004 bool is_vf, is_netdev;
2005 int filter_count = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002006
2007 is_vf = (vsi->type == I40E_VSI_SRIOV);
2008 is_netdev = !!(netdev);
2009
2010 if (is_netdev)
2011 i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev);
2012
2013 list_for_each_entry(f, &vsi->mac_filter_list, list)
2014 i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
2015
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002016 /* go through all the filters for this VSI and if there is only
2017 * vid == 0 it means there are no other filters, so vid 0 must
2018 * be replaced with -1. This signifies that we should from now
2019 * on accept any traffic (with any tag present, or untagged)
2020 */
2021 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2022 if (is_netdev) {
2023 if (f->vlan &&
2024 ether_addr_equal(netdev->dev_addr, f->macaddr))
2025 filter_count++;
2026 }
2027
2028 if (f->vlan)
2029 filter_count++;
2030 }
2031
2032 if (!filter_count && is_netdev) {
2033 i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev);
2034 f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
2035 is_vf, is_netdev);
2036 if (!f) {
2037 dev_info(&vsi->back->pdev->dev,
2038 "Could not add filter %d for %pM\n",
2039 I40E_VLAN_ANY, netdev->dev_addr);
2040 return -ENOMEM;
2041 }
2042 }
2043
2044 if (!filter_count) {
2045 list_for_each_entry(f, &vsi->mac_filter_list, list) {
2046 i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev);
2047 add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY,
2048 is_vf, is_netdev);
2049 if (!add_f) {
2050 dev_info(&vsi->back->pdev->dev,
2051 "Could not add filter %d for %pM\n",
2052 I40E_VLAN_ANY, f->macaddr);
2053 return -ENOMEM;
2054 }
2055 }
2056 }
2057
Anjali Singhai Jain80f64282013-11-28 06:39:47 +00002058 if (test_bit(__I40E_DOWN, &vsi->back->state) ||
2059 test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
2060 return 0;
2061
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002062 return i40e_sync_vsi_filters(vsi);
2063}
2064
2065/**
2066 * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
2067 * @netdev: network interface to be adjusted
2068 * @vid: vlan id to be added
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002069 *
2070 * net_device_ops implementation for adding vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002071 **/
2072static int i40e_vlan_rx_add_vid(struct net_device *netdev,
2073 __always_unused __be16 proto, u16 vid)
2074{
2075 struct i40e_netdev_priv *np = netdev_priv(netdev);
2076 struct i40e_vsi *vsi = np->vsi;
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002077 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002078
2079 if (vid > 4095)
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002080 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002081
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002082 netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid);
2083
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002084 /* If the network stack called us with vid = 0 then
2085 * it is asking to receive priority tagged packets with
2086 * vlan id 0. Our HW receives them by default when configured
2087 * to receive untagged packets so there is no need to add an
2088 * extra filter for vlan 0 tagged packets.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002089 */
Anjali Singhai Jain6982d422014-02-06 05:51:10 +00002090 if (vid)
2091 ret = i40e_vsi_add_vlan(vsi, vid);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002092
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002093 if (!ret && (vid < VLAN_N_VID))
2094 set_bit(vid, vsi->active_vlans);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002095
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002096 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002097}
2098
2099/**
2100 * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2101 * @netdev: network interface to be adjusted
2102 * @vid: vlan id to be removed
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002103 *
Akeem G Abodunrinfdfd9432014-02-11 08:24:15 +00002104 * net_device_ops implementation for removing vlan ids
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002105 **/
2106static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
2107 __always_unused __be16 proto, u16 vid)
2108{
2109 struct i40e_netdev_priv *np = netdev_priv(netdev);
2110 struct i40e_vsi *vsi = np->vsi;
2111
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002112 netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid);
2113
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002114 /* return code is ignored as there is nothing a user
2115 * can do about failure to remove and a log message was
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002116 * already printed from the other function
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002117 */
2118 i40e_vsi_kill_vlan(vsi, vid);
2119
2120 clear_bit(vid, vsi->active_vlans);
Jesse Brandeburg078b5872013-09-25 23:41:14 +00002121
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002122 return 0;
2123}
2124
2125/**
2126 * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
2127 * @vsi: the vsi being brought back up
2128 **/
2129static void i40e_restore_vlan(struct i40e_vsi *vsi)
2130{
2131 u16 vid;
2132
2133 if (!vsi->netdev)
2134 return;
2135
2136 i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
2137
2138 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
2139 i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
2140 vid);
2141}
2142
2143/**
2144 * i40e_vsi_add_pvid - Add pvid for the VSI
2145 * @vsi: the vsi being adjusted
2146 * @vid: the vlan id to set as a PVID
2147 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002148int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002149{
2150 struct i40e_vsi_context ctxt;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002151 i40e_status aq_ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002152
2153 vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
2154 vsi->info.pvid = cpu_to_le16(vid);
Greg Rose6c12fcb2013-11-28 06:39:34 +00002155 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
2156 I40E_AQ_VSI_PVLAN_INSERT_PVID |
Greg Roseb774c7d2013-11-28 06:39:44 +00002157 I40E_AQ_VSI_PVLAN_EMOD_STR;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002158
2159 ctxt.seid = vsi->seid;
2160 memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002161 aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
2162 if (aq_ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002163 dev_info(&vsi->back->pdev->dev,
2164 "%s: update vsi failed, aq_err=%d\n",
2165 __func__, vsi->back->hw.aq.asq_last_status);
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002166 return -ENOENT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002167 }
2168
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00002169 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002170}
2171
2172/**
2173 * i40e_vsi_remove_pvid - Remove the pvid from the VSI
2174 * @vsi: the vsi being adjusted
2175 *
2176 * Just use the vlan_rx_register() service to put it back to normal
2177 **/
2178void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
2179{
Greg Rose6c12fcb2013-11-28 06:39:34 +00002180 i40e_vlan_stripping_disable(vsi);
2181
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002182 vsi->info.pvid = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002183}
2184
2185/**
2186 * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
2187 * @vsi: ptr to the VSI
2188 *
2189 * If this function returns with an error, then it's possible one or
2190 * more of the rings is populated (while the rest are not). It is the
2191 * callers duty to clean those orphaned rings.
2192 *
2193 * Return 0 on success, negative on failure
2194 **/
2195static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
2196{
2197 int i, err = 0;
2198
2199 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00002200 err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002201
2202 return err;
2203}
2204
2205/**
2206 * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
2207 * @vsi: ptr to the VSI
2208 *
2209 * Free VSI's transmit software resources
2210 **/
2211static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
2212{
2213 int i;
2214
Greg Rose8e9dca52013-12-18 13:45:53 +00002215 if (!vsi->tx_rings)
2216 return;
2217
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002218 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002219 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00002220 i40e_free_tx_resources(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002221}
2222
2223/**
2224 * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
2225 * @vsi: ptr to the VSI
2226 *
2227 * If this function returns with an error, then it's possible one or
2228 * more of the rings is populated (while the rest are not). It is the
2229 * callers duty to clean those orphaned rings.
2230 *
2231 * Return 0 on success, negative on failure
2232 **/
2233static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
2234{
2235 int i, err = 0;
2236
2237 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00002238 err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002239 return err;
2240}
2241
2242/**
2243 * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
2244 * @vsi: ptr to the VSI
2245 *
2246 * Free all receive software resources
2247 **/
2248static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
2249{
2250 int i;
2251
Greg Rose8e9dca52013-12-18 13:45:53 +00002252 if (!vsi->rx_rings)
2253 return;
2254
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002255 for (i = 0; i < vsi->num_queue_pairs; i++)
Greg Rose8e9dca52013-12-18 13:45:53 +00002256 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00002257 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002258}
2259
2260/**
2261 * i40e_configure_tx_ring - Configure a transmit ring context and rest
2262 * @ring: The Tx ring to configure
2263 *
2264 * Configure the Tx descriptor ring in the HMC context.
2265 **/
2266static int i40e_configure_tx_ring(struct i40e_ring *ring)
2267{
2268 struct i40e_vsi *vsi = ring->vsi;
2269 u16 pf_q = vsi->base_queue + ring->queue_index;
2270 struct i40e_hw *hw = &vsi->back->hw;
2271 struct i40e_hmc_obj_txq tx_ctx;
2272 i40e_status err = 0;
2273 u32 qtx_ctl = 0;
2274
2275 /* some ATR related tx ring init */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002276 if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002277 ring->atr_sample_rate = vsi->back->atr_sample_rate;
2278 ring->atr_count = 0;
2279 } else {
2280 ring->atr_sample_rate = 0;
2281 }
2282
2283 /* initialize XPS */
2284 if (ring->q_vector && ring->netdev &&
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08002285 vsi->tc_config.numtc <= 1 &&
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002286 !test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
2287 netif_set_xps_queue(ring->netdev,
2288 &ring->q_vector->affinity_mask,
2289 ring->queue_index);
2290
2291 /* clear the context structure first */
2292 memset(&tx_ctx, 0, sizeof(tx_ctx));
2293
2294 tx_ctx.new_context = 1;
2295 tx_ctx.base = (ring->dma / 128);
2296 tx_ctx.qlen = ring->count;
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002297 tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
2298 I40E_FLAG_FD_ATR_ENABLED));
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002299 tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
Jesse Brandeburg1943d8b2014-02-14 02:14:40 +00002300 /* FDIR VSI tx ring can still use RS bit and writebacks */
2301 if (vsi->type != I40E_VSI_FDIR)
2302 tx_ctx.head_wb_ena = 1;
2303 tx_ctx.head_wb_addr = ring->dma +
2304 (ring->count * sizeof(struct i40e_tx_desc));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002305
2306 /* As part of VSI creation/update, FW allocates certain
2307 * Tx arbitration queue sets for each TC enabled for
2308 * the VSI. The FW returns the handles to these queue
2309 * sets as part of the response buffer to Add VSI,
2310 * Update VSI, etc. AQ commands. It is expected that
2311 * these queue set handles be associated with the Tx
2312 * queues by the driver as part of the TX queue context
2313 * initialization. This has to be done regardless of
2314 * DCB as by default everything is mapped to TC0.
2315 */
2316 tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
2317 tx_ctx.rdylist_act = 0;
2318
2319 /* clear the context in the HMC */
2320 err = i40e_clear_lan_tx_queue_context(hw, pf_q);
2321 if (err) {
2322 dev_info(&vsi->back->pdev->dev,
2323 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
2324 ring->queue_index, pf_q, err);
2325 return -ENOMEM;
2326 }
2327
2328 /* set the context in the HMC */
2329 err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
2330 if (err) {
2331 dev_info(&vsi->back->pdev->dev,
2332 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
2333 ring->queue_index, pf_q, err);
2334 return -ENOMEM;
2335 }
2336
2337 /* Now associate this queue with this PCI function */
Shannon Nelson9d8bf542014-01-14 00:49:50 -08002338 if (vsi->type == I40E_VSI_VMDQ2)
2339 qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
2340 else
2341 qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
Shannon Nelson13fd9772013-09-28 07:14:19 +00002342 qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
2343 I40E_QTX_CTL_PF_INDX_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002344 wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
2345 i40e_flush(hw);
2346
2347 clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state);
2348
2349 /* cache tail off for easier writes later */
2350 ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
2351
2352 return 0;
2353}
2354
2355/**
2356 * i40e_configure_rx_ring - Configure a receive ring context
2357 * @ring: The Rx ring to configure
2358 *
2359 * Configure the Rx descriptor ring in the HMC context.
2360 **/
2361static int i40e_configure_rx_ring(struct i40e_ring *ring)
2362{
2363 struct i40e_vsi *vsi = ring->vsi;
2364 u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
2365 u16 pf_q = vsi->base_queue + ring->queue_index;
2366 struct i40e_hw *hw = &vsi->back->hw;
2367 struct i40e_hmc_obj_rxq rx_ctx;
2368 i40e_status err = 0;
2369
2370 ring->state = 0;
2371
2372 /* clear the context structure first */
2373 memset(&rx_ctx, 0, sizeof(rx_ctx));
2374
2375 ring->rx_buf_len = vsi->rx_buf_len;
2376 ring->rx_hdr_len = vsi->rx_hdr_len;
2377
2378 rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
2379 rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
2380
2381 rx_ctx.base = (ring->dma / 128);
2382 rx_ctx.qlen = ring->count;
2383
2384 if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) {
2385 set_ring_16byte_desc_enabled(ring);
2386 rx_ctx.dsize = 0;
2387 } else {
2388 rx_ctx.dsize = 1;
2389 }
2390
2391 rx_ctx.dtype = vsi->dtype;
2392 if (vsi->dtype) {
2393 set_ring_ps_enabled(ring);
2394 rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
2395 I40E_RX_SPLIT_IP |
2396 I40E_RX_SPLIT_TCP_UDP |
2397 I40E_RX_SPLIT_SCTP;
2398 } else {
2399 rx_ctx.hsplit_0 = 0;
2400 }
2401
2402 rx_ctx.rxmax = min_t(u16, vsi->max_frame,
2403 (chain_len * ring->rx_buf_len));
2404 rx_ctx.tphrdesc_ena = 1;
2405 rx_ctx.tphwdesc_ena = 1;
2406 rx_ctx.tphdata_ena = 1;
2407 rx_ctx.tphhead_ena = 1;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00002408 if (hw->revision_id == 0)
2409 rx_ctx.lrxqthresh = 0;
2410 else
2411 rx_ctx.lrxqthresh = 2;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002412 rx_ctx.crcstrip = 1;
2413 rx_ctx.l2tsel = 1;
2414 rx_ctx.showiv = 1;
Catherine Sullivanacb36762014-03-06 09:02:30 +00002415 /* set the prefena field to 1 because the manual says to */
2416 rx_ctx.prefena = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002417
2418 /* clear the context in the HMC */
2419 err = i40e_clear_lan_rx_queue_context(hw, pf_q);
2420 if (err) {
2421 dev_info(&vsi->back->pdev->dev,
2422 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2423 ring->queue_index, pf_q, err);
2424 return -ENOMEM;
2425 }
2426
2427 /* set the context in the HMC */
2428 err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
2429 if (err) {
2430 dev_info(&vsi->back->pdev->dev,
2431 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
2432 ring->queue_index, pf_q, err);
2433 return -ENOMEM;
2434 }
2435
2436 /* cache tail for quicker writes, and clear the reg before use */
2437 ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
2438 writel(0, ring->tail);
2439
2440 i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
2441
2442 return 0;
2443}
2444
2445/**
2446 * i40e_vsi_configure_tx - Configure the VSI for Tx
2447 * @vsi: VSI structure describing this set of rings and resources
2448 *
2449 * Configure the Tx VSI for operation.
2450 **/
2451static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
2452{
2453 int err = 0;
2454 u16 i;
2455
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00002456 for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
2457 err = i40e_configure_tx_ring(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002458
2459 return err;
2460}
2461
2462/**
2463 * i40e_vsi_configure_rx - Configure the VSI for Rx
2464 * @vsi: the VSI being configured
2465 *
2466 * Configure the Rx VSI for operation.
2467 **/
2468static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
2469{
2470 int err = 0;
2471 u16 i;
2472
2473 if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
2474 vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
2475 + ETH_FCS_LEN + VLAN_HLEN;
2476 else
2477 vsi->max_frame = I40E_RXBUFFER_2048;
2478
2479 /* figure out correct receive buffer length */
2480 switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED |
2481 I40E_FLAG_RX_PS_ENABLED)) {
2482 case I40E_FLAG_RX_1BUF_ENABLED:
2483 vsi->rx_hdr_len = 0;
2484 vsi->rx_buf_len = vsi->max_frame;
2485 vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
2486 break;
2487 case I40E_FLAG_RX_PS_ENABLED:
2488 vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
2489 vsi->rx_buf_len = I40E_RXBUFFER_2048;
2490 vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT;
2491 break;
2492 default:
2493 vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
2494 vsi->rx_buf_len = I40E_RXBUFFER_2048;
2495 vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS;
2496 break;
2497 }
2498
2499 /* round up for the chip's needs */
2500 vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len,
2501 (1 << I40E_RXQ_CTX_HBUFF_SHIFT));
2502 vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
2503 (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
2504
2505 /* set up individual rings */
2506 for (i = 0; i < vsi->num_queue_pairs && !err; i++)
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00002507 err = i40e_configure_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002508
2509 return err;
2510}
2511
2512/**
2513 * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
2514 * @vsi: ptr to the VSI
2515 **/
2516static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
2517{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00002518 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002519 u16 qoffset, qcount;
2520 int i, n;
2521
2522 if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED))
2523 return;
2524
2525 for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
2526 if (!(vsi->tc_config.enabled_tc & (1 << n)))
2527 continue;
2528
2529 qoffset = vsi->tc_config.tc_info[n].qoffset;
2530 qcount = vsi->tc_config.tc_info[n].qcount;
2531 for (i = qoffset; i < (qoffset + qcount); i++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00002532 rx_ring = vsi->rx_rings[i];
2533 tx_ring = vsi->tx_rings[i];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002534 rx_ring->dcb_tc = n;
2535 tx_ring->dcb_tc = n;
2536 }
2537 }
2538}
2539
2540/**
2541 * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
2542 * @vsi: ptr to the VSI
2543 **/
2544static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
2545{
2546 if (vsi->netdev)
2547 i40e_set_rx_mode(vsi->netdev);
2548}
2549
2550/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002551 * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
2552 * @vsi: Pointer to the targeted VSI
2553 *
2554 * This function replays the hlist on the hw where all the SB Flow Director
2555 * filters were saved.
2556 **/
2557static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
2558{
2559 struct i40e_fdir_filter *filter;
2560 struct i40e_pf *pf = vsi->back;
2561 struct hlist_node *node;
2562
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002563 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2564 return;
2565
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002566 hlist_for_each_entry_safe(filter, node,
2567 &pf->fdir_filter_list, fdir_node) {
2568 i40e_add_del_fdir(vsi, filter, true);
2569 }
2570}
2571
2572/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002573 * i40e_vsi_configure - Set up the VSI for action
2574 * @vsi: the VSI being configured
2575 **/
2576static int i40e_vsi_configure(struct i40e_vsi *vsi)
2577{
2578 int err;
2579
2580 i40e_set_vsi_rx_mode(vsi);
2581 i40e_restore_vlan(vsi);
2582 i40e_vsi_config_dcb_rings(vsi);
2583 err = i40e_vsi_configure_tx(vsi);
2584 if (!err)
2585 err = i40e_vsi_configure_rx(vsi);
2586
2587 return err;
2588}
2589
2590/**
2591 * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
2592 * @vsi: the VSI being configured
2593 **/
2594static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
2595{
2596 struct i40e_pf *pf = vsi->back;
2597 struct i40e_q_vector *q_vector;
2598 struct i40e_hw *hw = &pf->hw;
2599 u16 vector;
2600 int i, q;
2601 u32 val;
2602 u32 qp;
2603
2604 /* The interrupt indexing is offset by 1 in the PFINT_ITRn
2605 * and PFINT_LNKLSTn registers, e.g.:
2606 * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
2607 */
2608 qp = vsi->base_queue;
2609 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +00002610 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
2611 q_vector = vsi->q_vectors[i];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002612 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
2613 q_vector->rx.latency_range = I40E_LOW_LATENCY;
2614 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
2615 q_vector->rx.itr);
2616 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
2617 q_vector->tx.latency_range = I40E_LOW_LATENCY;
2618 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
2619 q_vector->tx.itr);
2620
2621 /* Linked list for the queuepairs assigned to this vector */
2622 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
2623 for (q = 0; q < q_vector->num_ringpairs; q++) {
2624 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
2625 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
2626 (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
2627 (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
2628 (I40E_QUEUE_TYPE_TX
2629 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
2630
2631 wr32(hw, I40E_QINT_RQCTL(qp), val);
2632
2633 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
2634 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
2635 (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
2636 ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
2637 (I40E_QUEUE_TYPE_RX
2638 << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
2639
2640 /* Terminate the linked list */
2641 if (q == (q_vector->num_ringpairs - 1))
2642 val |= (I40E_QUEUE_END_OF_LIST
2643 << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
2644
2645 wr32(hw, I40E_QINT_TQCTL(qp), val);
2646 qp++;
2647 }
2648 }
2649
2650 i40e_flush(hw);
2651}
2652
2653/**
2654 * i40e_enable_misc_int_causes - enable the non-queue interrupts
2655 * @hw: ptr to the hardware info
2656 **/
2657static void i40e_enable_misc_int_causes(struct i40e_hw *hw)
2658{
2659 u32 val;
2660
2661 /* clear things first */
2662 wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
2663 rd32(hw, I40E_PFINT_ICR0); /* read to clear */
2664
2665 val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
2666 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
2667 I40E_PFINT_ICR0_ENA_GRST_MASK |
2668 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
2669 I40E_PFINT_ICR0_ENA_GPIO_MASK |
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00002670 I40E_PFINT_ICR0_ENA_TIMESYNC_MASK |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002671 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
2672 I40E_PFINT_ICR0_ENA_VFLR_MASK |
2673 I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
2674
2675 wr32(hw, I40E_PFINT_ICR0_ENA, val);
2676
2677 /* SW_ITR_IDX = 0, but don't change INTENA */
Anjali Singhai Jain84ed40e2013-11-26 10:49:32 +00002678 wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
2679 I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002680
2681 /* OTHER_ITR_IDX = 0 */
2682 wr32(hw, I40E_PFINT_STAT_CTL0, 0);
2683}
2684
2685/**
2686 * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
2687 * @vsi: the VSI being configured
2688 **/
2689static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
2690{
Alexander Duyck493fb302013-09-28 07:01:44 +00002691 struct i40e_q_vector *q_vector = vsi->q_vectors[0];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002692 struct i40e_pf *pf = vsi->back;
2693 struct i40e_hw *hw = &pf->hw;
2694 u32 val;
2695
2696 /* set the ITR configuration */
2697 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
2698 q_vector->rx.latency_range = I40E_LOW_LATENCY;
2699 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
2700 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
2701 q_vector->tx.latency_range = I40E_LOW_LATENCY;
2702 wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
2703
2704 i40e_enable_misc_int_causes(hw);
2705
2706 /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
2707 wr32(hw, I40E_PFINT_LNKLST0, 0);
2708
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00002709 /* Associate the queue pair to the vector and enable the queue int */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002710 val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
2711 (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
2712 (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
2713
2714 wr32(hw, I40E_QINT_RQCTL(0), val);
2715
2716 val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
2717 (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
2718 (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
2719
2720 wr32(hw, I40E_QINT_TQCTL(0), val);
2721 i40e_flush(hw);
2722}
2723
2724/**
Mitch Williams2ef28cf2013-11-28 06:39:32 +00002725 * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
2726 * @pf: board private structure
2727 **/
2728void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
2729{
2730 struct i40e_hw *hw = &pf->hw;
2731
2732 wr32(hw, I40E_PFINT_DYN_CTL0,
2733 I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
2734 i40e_flush(hw);
2735}
2736
2737/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002738 * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
2739 * @pf: board private structure
2740 **/
Shannon Nelson116a57d2013-09-28 07:13:59 +00002741void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002742{
2743 struct i40e_hw *hw = &pf->hw;
2744 u32 val;
2745
2746 val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
2747 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
2748 (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
2749
2750 wr32(hw, I40E_PFINT_DYN_CTL0, val);
2751 i40e_flush(hw);
2752}
2753
2754/**
2755 * i40e_irq_dynamic_enable - Enable default interrupt generation settings
2756 * @vsi: pointer to a vsi
2757 * @vector: enable a particular Hw Interrupt vector
2758 **/
2759void i40e_irq_dynamic_enable(struct i40e_vsi *vsi, int vector)
2760{
2761 struct i40e_pf *pf = vsi->back;
2762 struct i40e_hw *hw = &pf->hw;
2763 u32 val;
2764
2765 val = I40E_PFINT_DYN_CTLN_INTENA_MASK |
2766 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
2767 (I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
2768 wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val);
Jesse Brandeburg1022cb62013-09-28 07:13:08 +00002769 /* skip the flush */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002770}
2771
2772/**
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002773 * i40e_irq_dynamic_disable - Disable default interrupt generation settings
2774 * @vsi: pointer to a vsi
2775 * @vector: enable a particular Hw Interrupt vector
2776 **/
2777void i40e_irq_dynamic_disable(struct i40e_vsi *vsi, int vector)
2778{
2779 struct i40e_pf *pf = vsi->back;
2780 struct i40e_hw *hw = &pf->hw;
2781 u32 val;
2782
2783 val = I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
2784 wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val);
2785 i40e_flush(hw);
2786}
2787
2788/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002789 * i40e_msix_clean_rings - MSIX mode Interrupt Handler
2790 * @irq: interrupt number
2791 * @data: pointer to a q_vector
2792 **/
2793static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
2794{
2795 struct i40e_q_vector *q_vector = data;
2796
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00002797 if (!q_vector->tx.ring && !q_vector->rx.ring)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002798 return IRQ_HANDLED;
2799
2800 napi_schedule(&q_vector->napi);
2801
2802 return IRQ_HANDLED;
2803}
2804
2805/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002806 * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
2807 * @vsi: the VSI being configured
2808 * @basename: name for the vector
2809 *
2810 * Allocates MSI-X vectors and requests interrupts from the kernel.
2811 **/
2812static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
2813{
2814 int q_vectors = vsi->num_q_vectors;
2815 struct i40e_pf *pf = vsi->back;
2816 int base = vsi->base_vector;
2817 int rx_int_idx = 0;
2818 int tx_int_idx = 0;
2819 int vector, err;
2820
2821 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck493fb302013-09-28 07:01:44 +00002822 struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002823
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00002824 if (q_vector->tx.ring && q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002825 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2826 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
2827 tx_int_idx++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00002828 } else if (q_vector->rx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002829 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2830 "%s-%s-%d", basename, "rx", rx_int_idx++);
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00002831 } else if (q_vector->tx.ring) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002832 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2833 "%s-%s-%d", basename, "tx", tx_int_idx++);
2834 } else {
2835 /* skip this unused q_vector */
2836 continue;
2837 }
2838 err = request_irq(pf->msix_entries[base + vector].vector,
2839 vsi->irq_handler,
2840 0,
2841 q_vector->name,
2842 q_vector);
2843 if (err) {
2844 dev_info(&pf->pdev->dev,
2845 "%s: request_irq failed, error: %d\n",
2846 __func__, err);
2847 goto free_queue_irqs;
2848 }
2849 /* assign the mask for this irq */
2850 irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
2851 &q_vector->affinity_mask);
2852 }
2853
Shannon Nelson63741842014-04-23 04:50:16 +00002854 vsi->irqs_ready = true;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002855 return 0;
2856
2857free_queue_irqs:
2858 while (vector) {
2859 vector--;
2860 irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
2861 NULL);
2862 free_irq(pf->msix_entries[base + vector].vector,
2863 &(vsi->q_vectors[vector]));
2864 }
2865 return err;
2866}
2867
2868/**
2869 * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
2870 * @vsi: the VSI being un-configured
2871 **/
2872static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
2873{
2874 struct i40e_pf *pf = vsi->back;
2875 struct i40e_hw *hw = &pf->hw;
2876 int base = vsi->base_vector;
2877 int i;
2878
2879 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00002880 wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
2881 wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002882 }
2883
2884 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
2885 for (i = vsi->base_vector;
2886 i < (vsi->num_q_vectors + vsi->base_vector); i++)
2887 wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
2888
2889 i40e_flush(hw);
2890 for (i = 0; i < vsi->num_q_vectors; i++)
2891 synchronize_irq(pf->msix_entries[i + base].vector);
2892 } else {
2893 /* Legacy and MSI mode - this stops all interrupt handling */
2894 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
2895 wr32(hw, I40E_PFINT_DYN_CTL0, 0);
2896 i40e_flush(hw);
2897 synchronize_irq(pf->pdev->irq);
2898 }
2899}
2900
2901/**
2902 * i40e_vsi_enable_irq - Enable IRQ for the given VSI
2903 * @vsi: the VSI being configured
2904 **/
2905static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
2906{
2907 struct i40e_pf *pf = vsi->back;
2908 int i;
2909
2910 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
2911 for (i = vsi->base_vector;
2912 i < (vsi->num_q_vectors + vsi->base_vector); i++)
2913 i40e_irq_dynamic_enable(vsi, i);
2914 } else {
2915 i40e_irq_dynamic_enable_icr0(pf);
2916 }
2917
Jesse Brandeburg1022cb62013-09-28 07:13:08 +00002918 i40e_flush(&pf->hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002919 return 0;
2920}
2921
2922/**
2923 * i40e_stop_misc_vector - Stop the vector that handles non-queue events
2924 * @pf: board private structure
2925 **/
2926static void i40e_stop_misc_vector(struct i40e_pf *pf)
2927{
2928 /* Disable ICR 0 */
2929 wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
2930 i40e_flush(&pf->hw);
2931}
2932
2933/**
2934 * i40e_intr - MSI/Legacy and non-queue interrupt handler
2935 * @irq: interrupt number
2936 * @data: pointer to a q_vector
2937 *
2938 * This is the handler used for all MSI/Legacy interrupts, and deals
2939 * with both queue and non-queue interrupts. This is also used in
2940 * MSIX mode to handle the non-queue interrupts.
2941 **/
2942static irqreturn_t i40e_intr(int irq, void *data)
2943{
2944 struct i40e_pf *pf = (struct i40e_pf *)data;
2945 struct i40e_hw *hw = &pf->hw;
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00002946 irqreturn_t ret = IRQ_NONE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002947 u32 icr0, icr0_remaining;
2948 u32 val, ena_mask;
2949
2950 icr0 = rd32(hw, I40E_PFINT_ICR0);
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00002951 ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002952
Shannon Nelson116a57d2013-09-28 07:13:59 +00002953 /* if sharing a legacy IRQ, we might get called w/o an intr pending */
2954 if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00002955 goto enable_intr;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002956
Shannon Nelsoncd92e722013-11-16 10:00:44 +00002957 /* if interrupt but no bits showing, must be SWINT */
2958 if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
2959 (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
2960 pf->sw_int_count++;
2961
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002962 /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
2963 if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
2964
2965 /* temporarily disable queue cause for NAPI processing */
2966 u32 qval = rd32(hw, I40E_QINT_RQCTL(0));
2967 qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
2968 wr32(hw, I40E_QINT_RQCTL(0), qval);
2969
2970 qval = rd32(hw, I40E_QINT_TQCTL(0));
2971 qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
2972 wr32(hw, I40E_QINT_TQCTL(0), qval);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002973
2974 if (!test_bit(__I40E_DOWN, &pf->state))
Alexander Duyck493fb302013-09-28 07:01:44 +00002975 napi_schedule(&pf->vsi[pf->lan_vsi]->q_vectors[0]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00002976 }
2977
2978 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
2979 ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
2980 set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
2981 }
2982
2983 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
2984 ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
2985 set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
2986 }
2987
2988 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
2989 ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
2990 set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
2991 }
2992
2993 if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
2994 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
2995 set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
2996 ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
2997 val = rd32(hw, I40E_GLGEN_RSTAT);
2998 val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
2999 >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003000 if (val == I40E_RESET_CORER) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003001 pf->corer_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003002 } else if (val == I40E_RESET_GLOBR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003003 pf->globr_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003004 } else if (val == I40E_RESET_EMPR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003005 pf->empr_count++;
Shannon Nelson4eb3f762014-03-06 08:59:58 +00003006 set_bit(__I40E_EMP_RESET_REQUESTED, &pf->state);
3007 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003008 }
3009
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003010 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
3011 icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
3012 dev_info(&pf->pdev->dev, "HMC error interrupt\n");
3013 }
3014
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003015 if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
3016 u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
3017
3018 if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
Jacob Kellercafa1fc2014-04-24 18:05:03 -07003019 icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003020 i40e_ptp_tx_hwtstamp(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003021 }
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00003022 }
3023
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003024 /* If a critical error is pending we have no choice but to reset the
3025 * device.
3026 * Report and mask out any remaining unexpected interrupts.
3027 */
3028 icr0_remaining = icr0 & ena_mask;
3029 if (icr0_remaining) {
3030 dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
3031 icr0_remaining);
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003032 if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003033 (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
Anjali Singhai Jainc0c28972014-02-12 01:45:34 +00003034 (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
Anjali Singhai Jain9c010ee2013-11-28 06:39:20 +00003035 dev_info(&pf->pdev->dev, "device will be reset\n");
3036 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
3037 i40e_service_event_schedule(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003038 }
3039 ena_mask &= ~icr0_remaining;
3040 }
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003041 ret = IRQ_HANDLED;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003042
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003043enable_intr:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003044 /* re-enable interrupt causes */
3045 wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003046 if (!test_bit(__I40E_DOWN, &pf->state)) {
3047 i40e_service_event_schedule(pf);
3048 i40e_irq_dynamic_enable_icr0(pf);
3049 }
3050
Anjali Singhai Jain5e823062013-12-18 13:45:49 +00003051 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003052}
3053
3054/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08003055 * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
3056 * @tx_ring: tx ring to clean
3057 * @budget: how many cleans we're allowed
3058 *
3059 * Returns true if there's any budget left (e.g. the clean is finished)
3060 **/
3061static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
3062{
3063 struct i40e_vsi *vsi = tx_ring->vsi;
3064 u16 i = tx_ring->next_to_clean;
3065 struct i40e_tx_buffer *tx_buf;
3066 struct i40e_tx_desc *tx_desc;
3067
3068 tx_buf = &tx_ring->tx_bi[i];
3069 tx_desc = I40E_TX_DESC(tx_ring, i);
3070 i -= tx_ring->count;
3071
3072 do {
3073 struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
3074
3075 /* if next_to_watch is not set then there is no work pending */
3076 if (!eop_desc)
3077 break;
3078
3079 /* prevent any other reads prior to eop_desc */
3080 read_barrier_depends();
3081
3082 /* if the descriptor isn't done, no work yet to do */
3083 if (!(eop_desc->cmd_type_offset_bsz &
3084 cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
3085 break;
3086
3087 /* clear next_to_watch to prevent false hangs */
3088 tx_buf->next_to_watch = NULL;
3089
3090 /* unmap skb header data */
3091 dma_unmap_single(tx_ring->dev,
3092 dma_unmap_addr(tx_buf, dma),
3093 dma_unmap_len(tx_buf, len),
3094 DMA_TO_DEVICE);
3095
3096 dma_unmap_len_set(tx_buf, len, 0);
3097
3098
3099 /* move to the next desc and buffer to clean */
3100 tx_buf++;
3101 tx_desc++;
3102 i++;
3103 if (unlikely(!i)) {
3104 i -= tx_ring->count;
3105 tx_buf = tx_ring->tx_bi;
3106 tx_desc = I40E_TX_DESC(tx_ring, 0);
3107 }
3108
3109 /* update budget accounting */
3110 budget--;
3111 } while (likely(budget));
3112
3113 i += tx_ring->count;
3114 tx_ring->next_to_clean = i;
3115
3116 if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) {
3117 i40e_irq_dynamic_enable(vsi,
3118 tx_ring->q_vector->v_idx + vsi->base_vector);
3119 }
3120 return budget > 0;
3121}
3122
3123/**
3124 * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
3125 * @irq: interrupt number
3126 * @data: pointer to a q_vector
3127 **/
3128static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
3129{
3130 struct i40e_q_vector *q_vector = data;
3131 struct i40e_vsi *vsi;
3132
3133 if (!q_vector->tx.ring)
3134 return IRQ_HANDLED;
3135
3136 vsi = q_vector->tx.ring->vsi;
3137 i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
3138
3139 return IRQ_HANDLED;
3140}
3141
3142/**
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003143 * i40e_map_vector_to_qp - Assigns the queue pair to the vector
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003144 * @vsi: the VSI being configured
3145 * @v_idx: vector index
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003146 * @qp_idx: queue pair index
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003147 **/
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003148static void map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003149{
Alexander Duyck493fb302013-09-28 07:01:44 +00003150 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00003151 struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
3152 struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003153
3154 tx_ring->q_vector = q_vector;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003155 tx_ring->next = q_vector->tx.ring;
3156 q_vector->tx.ring = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003157 q_vector->tx.count++;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003158
3159 rx_ring->q_vector = q_vector;
3160 rx_ring->next = q_vector->rx.ring;
3161 q_vector->rx.ring = rx_ring;
3162 q_vector->rx.count++;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003163}
3164
3165/**
3166 * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
3167 * @vsi: the VSI being configured
3168 *
3169 * This function maps descriptor rings to the queue-specific vectors
3170 * we were allotted through the MSI-X enabling code. Ideally, we'd have
3171 * one vector per queue pair, but on a constrained vector budget, we
3172 * group the queue pairs as "efficiently" as possible.
3173 **/
3174static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
3175{
3176 int qp_remaining = vsi->num_queue_pairs;
3177 int q_vectors = vsi->num_q_vectors;
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003178 int num_ringpairs;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003179 int v_start = 0;
3180 int qp_idx = 0;
3181
3182 /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
3183 * group them so there are multiple queues per vector.
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003184 * It is also important to go through all the vectors available to be
3185 * sure that if we don't use all the vectors, that the remaining vectors
3186 * are cleared. This is especially important when decreasing the
3187 * number of queues in use.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003188 */
Anjali Singhai Jain70114ec2014-06-03 23:50:14 +00003189 for (; v_start < q_vectors; v_start++) {
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003190 struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
3191
3192 num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
3193
3194 q_vector->num_ringpairs = num_ringpairs;
3195
3196 q_vector->rx.count = 0;
3197 q_vector->tx.count = 0;
3198 q_vector->rx.ring = NULL;
3199 q_vector->tx.ring = NULL;
3200
3201 while (num_ringpairs--) {
3202 map_vector_to_qp(vsi, v_start, qp_idx);
3203 qp_idx++;
3204 qp_remaining--;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003205 }
3206 }
3207}
3208
3209/**
3210 * i40e_vsi_request_irq - Request IRQ from the OS
3211 * @vsi: the VSI being configured
3212 * @basename: name for the vector
3213 **/
3214static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
3215{
3216 struct i40e_pf *pf = vsi->back;
3217 int err;
3218
3219 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
3220 err = i40e_vsi_request_irq_msix(vsi, basename);
3221 else if (pf->flags & I40E_FLAG_MSI_ENABLED)
3222 err = request_irq(pf->pdev->irq, i40e_intr, 0,
3223 pf->misc_int_name, pf);
3224 else
3225 err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
3226 pf->misc_int_name, pf);
3227
3228 if (err)
3229 dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
3230
3231 return err;
3232}
3233
3234#ifdef CONFIG_NET_POLL_CONTROLLER
3235/**
3236 * i40e_netpoll - A Polling 'interrupt'handler
3237 * @netdev: network interface device structure
3238 *
3239 * This is used by netconsole to send skbs without having to re-enable
3240 * interrupts. It's not called while the normal interrupt routine is executing.
3241 **/
3242static void i40e_netpoll(struct net_device *netdev)
3243{
3244 struct i40e_netdev_priv *np = netdev_priv(netdev);
3245 struct i40e_vsi *vsi = np->vsi;
3246 struct i40e_pf *pf = vsi->back;
3247 int i;
3248
3249 /* if interface is down do nothing */
3250 if (test_bit(__I40E_DOWN, &vsi->state))
3251 return;
3252
3253 pf->flags |= I40E_FLAG_IN_NETPOLL;
3254 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3255 for (i = 0; i < vsi->num_q_vectors; i++)
Alexander Duyck493fb302013-09-28 07:01:44 +00003256 i40e_msix_clean_rings(0, vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003257 } else {
3258 i40e_intr(pf->pdev->irq, netdev);
3259 }
3260 pf->flags &= ~I40E_FLAG_IN_NETPOLL;
3261}
3262#endif
3263
3264/**
Neerav Parikh23527302014-06-03 23:50:15 +00003265 * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
3266 * @pf: the PF being configured
3267 * @pf_q: the PF queue
3268 * @enable: enable or disable state of the queue
3269 *
3270 * This routine will wait for the given Tx queue of the PF to reach the
3271 * enabled or disabled state.
3272 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3273 * multiple retries; else will return 0 in case of success.
3274 **/
3275static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3276{
3277 int i;
3278 u32 tx_reg;
3279
3280 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3281 tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
3282 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
3283 break;
3284
3285 udelay(10);
3286 }
3287 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3288 return -ETIMEDOUT;
3289
3290 return 0;
3291}
3292
3293/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003294 * i40e_vsi_control_tx - Start or stop a VSI's rings
3295 * @vsi: the VSI being configured
3296 * @enable: start or stop the rings
3297 **/
3298static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
3299{
3300 struct i40e_pf *pf = vsi->back;
3301 struct i40e_hw *hw = &pf->hw;
Neerav Parikh23527302014-06-03 23:50:15 +00003302 int i, j, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003303 u32 tx_reg;
3304
3305 pf_q = vsi->base_queue;
3306 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Matt Jared351499a2014-04-23 04:50:03 +00003307
3308 /* warn the TX unit of coming changes */
3309 i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
3310 if (!enable)
3311 udelay(10);
3312
Mitch Williams6c5ef622014-02-20 19:29:16 -08003313 for (j = 0; j < 50; j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003314 tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
Mitch Williams6c5ef622014-02-20 19:29:16 -08003315 if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
3316 ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
3317 break;
3318 usleep_range(1000, 2000);
3319 }
Mitch Williamsfda972f2013-11-28 06:39:29 +00003320 /* Skip if the queue is already in the requested state */
Catherine Sullivan7c122002014-03-14 07:32:29 +00003321 if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
Mitch Williamsfda972f2013-11-28 06:39:29 +00003322 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003323
3324 /* turn on/off the queue */
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003325 if (enable) {
3326 wr32(hw, I40E_QTX_HEAD(pf_q), 0);
Mitch Williams6c5ef622014-02-20 19:29:16 -08003327 tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003328 } else {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003329 tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
Shannon Nelsonc5c9eb92013-12-21 05:44:48 +00003330 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003331
3332 wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
3333
3334 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00003335 ret = i40e_pf_txq_wait(pf, pf_q, enable);
3336 if (ret) {
3337 dev_info(&pf->pdev->dev,
3338 "%s: VSI seid %d Tx ring %d %sable timeout\n",
3339 __func__, vsi->seid, pf_q,
3340 (enable ? "en" : "dis"));
3341 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003342 }
3343 }
3344
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003345 if (hw->revision_id == 0)
3346 mdelay(50);
Neerav Parikh23527302014-06-03 23:50:15 +00003347 return ret;
3348}
3349
3350/**
3351 * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
3352 * @pf: the PF being configured
3353 * @pf_q: the PF queue
3354 * @enable: enable or disable state of the queue
3355 *
3356 * This routine will wait for the given Rx queue of the PF to reach the
3357 * enabled or disabled state.
3358 * Returns -ETIMEDOUT in case of failing to reach the requested state after
3359 * multiple retries; else will return 0 in case of success.
3360 **/
3361static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
3362{
3363 int i;
3364 u32 rx_reg;
3365
3366 for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
3367 rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
3368 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
3369 break;
3370
3371 udelay(10);
3372 }
3373 if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
3374 return -ETIMEDOUT;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00003375
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003376 return 0;
3377}
3378
3379/**
3380 * i40e_vsi_control_rx - Start or stop a VSI's rings
3381 * @vsi: the VSI being configured
3382 * @enable: start or stop the rings
3383 **/
3384static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
3385{
3386 struct i40e_pf *pf = vsi->back;
3387 struct i40e_hw *hw = &pf->hw;
Neerav Parikh23527302014-06-03 23:50:15 +00003388 int i, j, pf_q, ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003389 u32 rx_reg;
3390
3391 pf_q = vsi->base_queue;
3392 for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
Mitch Williams6c5ef622014-02-20 19:29:16 -08003393 for (j = 0; j < 50; j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003394 rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
Mitch Williams6c5ef622014-02-20 19:29:16 -08003395 if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
3396 ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
3397 break;
3398 usleep_range(1000, 2000);
3399 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003400
Catherine Sullivan7c122002014-03-14 07:32:29 +00003401 /* Skip if the queue is already in the requested state */
3402 if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
3403 continue;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003404
3405 /* turn on/off the queue */
3406 if (enable)
Mitch Williams6c5ef622014-02-20 19:29:16 -08003407 rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003408 else
Mitch Williams6c5ef622014-02-20 19:29:16 -08003409 rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003410 wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
3411
3412 /* wait for the change to finish */
Neerav Parikh23527302014-06-03 23:50:15 +00003413 ret = i40e_pf_rxq_wait(pf, pf_q, enable);
3414 if (ret) {
3415 dev_info(&pf->pdev->dev,
3416 "%s: VSI seid %d Rx ring %d %sable timeout\n",
3417 __func__, vsi->seid, pf_q,
3418 (enable ? "en" : "dis"));
3419 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003420 }
3421 }
3422
Neerav Parikh23527302014-06-03 23:50:15 +00003423 return ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003424}
3425
3426/**
3427 * i40e_vsi_control_rings - Start or stop a VSI's rings
3428 * @vsi: the VSI being configured
3429 * @enable: start or stop the rings
3430 **/
Mitch Williamsfc18eaa2013-11-28 06:39:27 +00003431int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003432{
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00003433 int ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003434
3435 /* do rx first for enable and last for disable */
3436 if (request) {
3437 ret = i40e_vsi_control_rx(vsi, request);
3438 if (ret)
3439 return ret;
3440 ret = i40e_vsi_control_tx(vsi, request);
3441 } else {
Anjali Singhai Jain3b867b22013-12-21 05:44:44 +00003442 /* Ignore return value, we need to shutdown whatever we can */
3443 i40e_vsi_control_tx(vsi, request);
3444 i40e_vsi_control_rx(vsi, request);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003445 }
3446
3447 return ret;
3448}
3449
3450/**
3451 * i40e_vsi_free_irq - Free the irq association with the OS
3452 * @vsi: the VSI being configured
3453 **/
3454static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
3455{
3456 struct i40e_pf *pf = vsi->back;
3457 struct i40e_hw *hw = &pf->hw;
3458 int base = vsi->base_vector;
3459 u32 val, qp;
3460 int i;
3461
3462 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3463 if (!vsi->q_vectors)
3464 return;
3465
Shannon Nelson63741842014-04-23 04:50:16 +00003466 if (!vsi->irqs_ready)
3467 return;
3468
3469 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003470 for (i = 0; i < vsi->num_q_vectors; i++) {
3471 u16 vector = i + base;
3472
3473 /* free only the irqs that were actually requested */
Shannon Nelson78681b12013-11-28 06:39:36 +00003474 if (!vsi->q_vectors[i] ||
3475 !vsi->q_vectors[i]->num_ringpairs)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003476 continue;
3477
3478 /* clear the affinity_mask in the IRQ descriptor */
3479 irq_set_affinity_hint(pf->msix_entries[vector].vector,
3480 NULL);
3481 free_irq(pf->msix_entries[vector].vector,
Alexander Duyck493fb302013-09-28 07:01:44 +00003482 vsi->q_vectors[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003483
3484 /* Tear down the interrupt queue link list
3485 *
3486 * We know that they come in pairs and always
3487 * the Rx first, then the Tx. To clear the
3488 * link list, stick the EOL value into the
3489 * next_q field of the registers.
3490 */
3491 val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
3492 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
3493 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
3494 val |= I40E_QUEUE_END_OF_LIST
3495 << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
3496 wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
3497
3498 while (qp != I40E_QUEUE_END_OF_LIST) {
3499 u32 next;
3500
3501 val = rd32(hw, I40E_QINT_RQCTL(qp));
3502
3503 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
3504 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
3505 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3506 I40E_QINT_RQCTL_INTEVENT_MASK);
3507
3508 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
3509 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
3510
3511 wr32(hw, I40E_QINT_RQCTL(qp), val);
3512
3513 val = rd32(hw, I40E_QINT_TQCTL(qp));
3514
3515 next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
3516 >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
3517
3518 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
3519 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
3520 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3521 I40E_QINT_TQCTL_INTEVENT_MASK);
3522
3523 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
3524 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
3525
3526 wr32(hw, I40E_QINT_TQCTL(qp), val);
3527 qp = next;
3528 }
3529 }
3530 } else {
3531 free_irq(pf->pdev->irq, pf);
3532
3533 val = rd32(hw, I40E_PFINT_LNKLST0);
3534 qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
3535 >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
3536 val |= I40E_QUEUE_END_OF_LIST
3537 << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
3538 wr32(hw, I40E_PFINT_LNKLST0, val);
3539
3540 val = rd32(hw, I40E_QINT_RQCTL(qp));
3541 val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
3542 I40E_QINT_RQCTL_MSIX0_INDX_MASK |
3543 I40E_QINT_RQCTL_CAUSE_ENA_MASK |
3544 I40E_QINT_RQCTL_INTEVENT_MASK);
3545
3546 val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
3547 I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
3548
3549 wr32(hw, I40E_QINT_RQCTL(qp), val);
3550
3551 val = rd32(hw, I40E_QINT_TQCTL(qp));
3552
3553 val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
3554 I40E_QINT_TQCTL_MSIX0_INDX_MASK |
3555 I40E_QINT_TQCTL_CAUSE_ENA_MASK |
3556 I40E_QINT_TQCTL_INTEVENT_MASK);
3557
3558 val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
3559 I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
3560
3561 wr32(hw, I40E_QINT_TQCTL(qp), val);
3562 }
3563}
3564
3565/**
Alexander Duyck493fb302013-09-28 07:01:44 +00003566 * i40e_free_q_vector - Free memory allocated for specific interrupt vector
3567 * @vsi: the VSI being configured
3568 * @v_idx: Index of vector to be freed
3569 *
3570 * This function frees the memory allocated to the q_vector. In addition if
3571 * NAPI is enabled it will delete any references to the NAPI struct prior
3572 * to freeing the q_vector.
3573 **/
3574static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
3575{
3576 struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003577 struct i40e_ring *ring;
Alexander Duyck493fb302013-09-28 07:01:44 +00003578
3579 if (!q_vector)
3580 return;
3581
3582 /* disassociate q_vector from rings */
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00003583 i40e_for_each_ring(ring, q_vector->tx)
3584 ring->q_vector = NULL;
3585
3586 i40e_for_each_ring(ring, q_vector->rx)
3587 ring->q_vector = NULL;
Alexander Duyck493fb302013-09-28 07:01:44 +00003588
3589 /* only VSI w/ an associated netdev is set up w/ NAPI */
3590 if (vsi->netdev)
3591 netif_napi_del(&q_vector->napi);
3592
3593 vsi->q_vectors[v_idx] = NULL;
3594
3595 kfree_rcu(q_vector, rcu);
3596}
3597
3598/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003599 * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
3600 * @vsi: the VSI being un-configured
3601 *
3602 * This frees the memory allocated to the q_vectors and
3603 * deletes references to the NAPI struct.
3604 **/
3605static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
3606{
3607 int v_idx;
3608
Alexander Duyck493fb302013-09-28 07:01:44 +00003609 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
3610 i40e_free_q_vector(vsi, v_idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003611}
3612
3613/**
3614 * i40e_reset_interrupt_capability - Disable interrupt setup in OS
3615 * @pf: board private structure
3616 **/
3617static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
3618{
3619 /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
3620 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
3621 pci_disable_msix(pf->pdev);
3622 kfree(pf->msix_entries);
3623 pf->msix_entries = NULL;
3624 } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
3625 pci_disable_msi(pf->pdev);
3626 }
3627 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
3628}
3629
3630/**
3631 * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
3632 * @pf: board private structure
3633 *
3634 * We go through and clear interrupt specific resources and reset the structure
3635 * to pre-load conditions
3636 **/
3637static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
3638{
3639 int i;
3640
3641 i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
Mitch Williams505682c2014-05-20 08:01:37 +00003642 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003643 if (pf->vsi[i])
3644 i40e_vsi_free_q_vectors(pf->vsi[i]);
3645 i40e_reset_interrupt_capability(pf);
3646}
3647
3648/**
3649 * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
3650 * @vsi: the VSI being configured
3651 **/
3652static void i40e_napi_enable_all(struct i40e_vsi *vsi)
3653{
3654 int q_idx;
3655
3656 if (!vsi->netdev)
3657 return;
3658
3659 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
Alexander Duyck493fb302013-09-28 07:01:44 +00003660 napi_enable(&vsi->q_vectors[q_idx]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003661}
3662
3663/**
3664 * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
3665 * @vsi: the VSI being configured
3666 **/
3667static void i40e_napi_disable_all(struct i40e_vsi *vsi)
3668{
3669 int q_idx;
3670
3671 if (!vsi->netdev)
3672 return;
3673
3674 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
Alexander Duyck493fb302013-09-28 07:01:44 +00003675 napi_disable(&vsi->q_vectors[q_idx]->napi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003676}
3677
3678/**
Shannon Nelson90ef8d42014-03-14 07:32:26 +00003679 * i40e_vsi_close - Shut down a VSI
3680 * @vsi: the vsi to be quelled
3681 **/
3682static void i40e_vsi_close(struct i40e_vsi *vsi)
3683{
3684 if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
3685 i40e_down(vsi);
3686 i40e_vsi_free_irq(vsi);
3687 i40e_vsi_free_tx_resources(vsi);
3688 i40e_vsi_free_rx_resources(vsi);
3689}
3690
3691/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003692 * i40e_quiesce_vsi - Pause a given VSI
3693 * @vsi: the VSI being paused
3694 **/
3695static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
3696{
3697 if (test_bit(__I40E_DOWN, &vsi->state))
3698 return;
3699
3700 set_bit(__I40E_NEEDS_RESTART, &vsi->state);
3701 if (vsi->netdev && netif_running(vsi->netdev)) {
3702 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
3703 } else {
Shannon Nelson90ef8d42014-03-14 07:32:26 +00003704 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003705 }
3706}
3707
3708/**
3709 * i40e_unquiesce_vsi - Resume a given VSI
3710 * @vsi: the VSI being resumed
3711 **/
3712static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
3713{
3714 if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
3715 return;
3716
3717 clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
3718 if (vsi->netdev && netif_running(vsi->netdev))
3719 vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
3720 else
Shannon Nelson8276f752014-03-14 07:32:27 +00003721 i40e_vsi_open(vsi); /* this clears the DOWN bit */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003722}
3723
3724/**
3725 * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
3726 * @pf: the PF
3727 **/
3728static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
3729{
3730 int v;
3731
Mitch Williams505682c2014-05-20 08:01:37 +00003732 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003733 if (pf->vsi[v])
3734 i40e_quiesce_vsi(pf->vsi[v]);
3735 }
3736}
3737
3738/**
3739 * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
3740 * @pf: the PF
3741 **/
3742static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
3743{
3744 int v;
3745
Mitch Williams505682c2014-05-20 08:01:37 +00003746 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003747 if (pf->vsi[v])
3748 i40e_unquiesce_vsi(pf->vsi[v]);
3749 }
3750}
3751
3752/**
3753 * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
3754 * @dcbcfg: the corresponding DCBx configuration structure
3755 *
3756 * Return the number of TCs from given DCBx configuration
3757 **/
3758static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
3759{
Jesse Brandeburg078b5872013-09-25 23:41:14 +00003760 u8 num_tc = 0;
3761 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003762
3763 /* Scan the ETS Config Priority Table to find
3764 * traffic class enabled for a given priority
3765 * and use the traffic class index to get the
3766 * number of traffic classes enabled
3767 */
3768 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
3769 if (dcbcfg->etscfg.prioritytable[i] > num_tc)
3770 num_tc = dcbcfg->etscfg.prioritytable[i];
3771 }
3772
3773 /* Traffic class index starts from zero so
3774 * increment to return the actual count
3775 */
Jesse Brandeburg078b5872013-09-25 23:41:14 +00003776 return num_tc + 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003777}
3778
3779/**
3780 * i40e_dcb_get_enabled_tc - Get enabled traffic classes
3781 * @dcbcfg: the corresponding DCBx configuration structure
3782 *
3783 * Query the current DCB configuration and return the number of
3784 * traffic classes enabled from the given DCBX config
3785 **/
3786static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
3787{
3788 u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
3789 u8 enabled_tc = 1;
3790 u8 i;
3791
3792 for (i = 0; i < num_tc; i++)
3793 enabled_tc |= 1 << i;
3794
3795 return enabled_tc;
3796}
3797
3798/**
3799 * i40e_pf_get_num_tc - Get enabled traffic classes for PF
3800 * @pf: PF being queried
3801 *
3802 * Return number of traffic classes enabled for the given PF
3803 **/
3804static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
3805{
3806 struct i40e_hw *hw = &pf->hw;
3807 u8 i, enabled_tc;
3808 u8 num_tc = 0;
3809 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
3810
3811 /* If DCB is not enabled then always in single TC */
3812 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
3813 return 1;
3814
3815 /* MFP mode return count of enabled TCs for this PF */
3816 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3817 enabled_tc = pf->hw.func_caps.enabled_tcmap;
3818 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3819 if (enabled_tc & (1 << i))
3820 num_tc++;
3821 }
3822 return num_tc;
3823 }
3824
3825 /* SFP mode will be enabled for all TCs on port */
3826 return i40e_dcb_get_num_tc(dcbcfg);
3827}
3828
3829/**
3830 * i40e_pf_get_default_tc - Get bitmap for first enabled TC
3831 * @pf: PF being queried
3832 *
3833 * Return a bitmap for first enabled traffic class for this PF.
3834 **/
3835static u8 i40e_pf_get_default_tc(struct i40e_pf *pf)
3836{
3837 u8 enabled_tc = pf->hw.func_caps.enabled_tcmap;
3838 u8 i = 0;
3839
3840 if (!enabled_tc)
3841 return 0x1; /* TC0 */
3842
3843 /* Find the first enabled TC */
3844 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3845 if (enabled_tc & (1 << i))
3846 break;
3847 }
3848
3849 return 1 << i;
3850}
3851
3852/**
3853 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
3854 * @pf: PF being queried
3855 *
3856 * Return a bitmap for enabled traffic classes for this PF.
3857 **/
3858static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
3859{
3860 /* If DCB is not enabled for this PF then just return default TC */
3861 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
3862 return i40e_pf_get_default_tc(pf);
3863
3864 /* MFP mode will have enabled TCs set by FW */
3865 if (pf->flags & I40E_FLAG_MFP_ENABLED)
3866 return pf->hw.func_caps.enabled_tcmap;
3867
3868 /* SFP mode we want PF to be enabled for all TCs */
3869 return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
3870}
3871
3872/**
3873 * i40e_vsi_get_bw_info - Query VSI BW Information
3874 * @vsi: the VSI being queried
3875 *
3876 * Returns 0 on success, negative value on failure
3877 **/
3878static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
3879{
3880 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
3881 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
3882 struct i40e_pf *pf = vsi->back;
3883 struct i40e_hw *hw = &pf->hw;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003884 i40e_status aq_ret;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003885 u32 tc_bw_max;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003886 int i;
3887
3888 /* Get the VSI level BW configuration */
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003889 aq_ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
3890 if (aq_ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003891 dev_info(&pf->pdev->dev,
3892 "couldn't get pf vsi bw config, err %d, aq_err %d\n",
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003893 aq_ret, pf->hw.aq.asq_last_status);
3894 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003895 }
3896
3897 /* Get the VSI level BW configuration per TC */
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003898 aq_ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
Jesse Brandeburg6838b532014-01-14 00:49:52 -08003899 NULL);
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003900 if (aq_ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003901 dev_info(&pf->pdev->dev,
3902 "couldn't get pf vsi ets bw config, err %d, aq_err %d\n",
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003903 aq_ret, pf->hw.aq.asq_last_status);
3904 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003905 }
3906
3907 if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
3908 dev_info(&pf->pdev->dev,
3909 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
3910 bw_config.tc_valid_bits,
3911 bw_ets_config.tc_valid_bits);
3912 /* Still continuing */
3913 }
3914
3915 vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
3916 vsi->bw_max_quanta = bw_config.max_bw;
3917 tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
3918 (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
3919 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3920 vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
3921 vsi->bw_ets_limit_credits[i] =
3922 le16_to_cpu(bw_ets_config.credits[i]);
3923 /* 3 bits out of 4 for each TC */
3924 vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
3925 }
Jesse Brandeburg078b5872013-09-25 23:41:14 +00003926
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003927 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003928}
3929
3930/**
3931 * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
3932 * @vsi: the VSI being configured
3933 * @enabled_tc: TC bitmap
3934 * @bw_credits: BW shared credits per TC
3935 *
3936 * Returns 0 on success, negative value on failure
3937 **/
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003938static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003939 u8 *bw_share)
3940{
3941 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003942 i40e_status aq_ret;
3943 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003944
3945 bw_data.tc_valid_bits = enabled_tc;
3946 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
3947 bw_data.tc_bw_credits[i] = bw_share[i];
3948
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003949 aq_ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
3950 NULL);
3951 if (aq_ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003952 dev_info(&vsi->back->pdev->dev,
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00003953 "AQ command Config VSI BW allocation per TC failed = %d\n",
3954 vsi->back->hw.aq.asq_last_status);
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003955 return -EINVAL;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003956 }
3957
3958 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
3959 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
3960
Jesse Brandeburgdcae29b2013-09-13 08:23:20 +00003961 return 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00003962}
3963
3964/**
3965 * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
3966 * @vsi: the VSI being configured
3967 * @enabled_tc: TC map to be enabled
3968 *
3969 **/
3970static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
3971{
3972 struct net_device *netdev = vsi->netdev;
3973 struct i40e_pf *pf = vsi->back;
3974 struct i40e_hw *hw = &pf->hw;
3975 u8 netdev_tc = 0;
3976 int i;
3977 struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
3978
3979 if (!netdev)
3980 return;
3981
3982 if (!enabled_tc) {
3983 netdev_reset_tc(netdev);
3984 return;
3985 }
3986
3987 /* Set up actual enabled TCs on the VSI */
3988 if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
3989 return;
3990
3991 /* set per TC queues for the VSI */
3992 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3993 /* Only set TC queues for enabled tcs
3994 *
3995 * e.g. For a VSI that has TC0 and TC3 enabled the
3996 * enabled_tc bitmap would be 0x00001001; the driver
3997 * will set the numtc for netdev as 2 that will be
3998 * referenced by the netdev layer as TC 0 and 1.
3999 */
4000 if (vsi->tc_config.enabled_tc & (1 << i))
4001 netdev_set_tc_queue(netdev,
4002 vsi->tc_config.tc_info[i].netdev_tc,
4003 vsi->tc_config.tc_info[i].qcount,
4004 vsi->tc_config.tc_info[i].qoffset);
4005 }
4006
4007 /* Assign UP2TC map for the VSI */
4008 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
4009 /* Get the actual TC# for the UP */
4010 u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
4011 /* Get the mapped netdev TC# for the UP */
4012 netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
4013 netdev_set_prio_tc_map(netdev, i, netdev_tc);
4014 }
4015}
4016
4017/**
4018 * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
4019 * @vsi: the VSI being configured
4020 * @ctxt: the ctxt buffer returned from AQ VSI update param command
4021 **/
4022static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
4023 struct i40e_vsi_context *ctxt)
4024{
4025 /* copy just the sections touched not the entire info
4026 * since not all sections are valid as returned by
4027 * update vsi params
4028 */
4029 vsi->info.mapping_flags = ctxt->info.mapping_flags;
4030 memcpy(&vsi->info.queue_mapping,
4031 &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
4032 memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
4033 sizeof(vsi->info.tc_mapping));
4034}
4035
4036/**
4037 * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
4038 * @vsi: VSI to be configured
4039 * @enabled_tc: TC bitmap
4040 *
4041 * This configures a particular VSI for TCs that are mapped to the
4042 * given TC bitmap. It uses default bandwidth share for TCs across
4043 * VSIs to configure TC for a particular VSI.
4044 *
4045 * NOTE:
4046 * It is expected that the VSI queues have been quisced before calling
4047 * this function.
4048 **/
4049static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
4050{
4051 u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
4052 struct i40e_vsi_context ctxt;
4053 int ret = 0;
4054 int i;
4055
4056 /* Check if enabled_tc is same as existing or new TCs */
4057 if (vsi->tc_config.enabled_tc == enabled_tc)
4058 return ret;
4059
4060 /* Enable ETS TCs with equal BW Share for now across all VSIs */
4061 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4062 if (enabled_tc & (1 << i))
4063 bw_share[i] = 1;
4064 }
4065
4066 ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
4067 if (ret) {
4068 dev_info(&vsi->back->pdev->dev,
4069 "Failed configuring TC map %d for VSI %d\n",
4070 enabled_tc, vsi->seid);
4071 goto out;
4072 }
4073
4074 /* Update Queue Pairs Mapping for currently enabled UPs */
4075 ctxt.seid = vsi->seid;
4076 ctxt.pf_num = vsi->back->hw.pf_id;
4077 ctxt.vf_num = 0;
4078 ctxt.uplink_seid = vsi->uplink_seid;
4079 memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
4080 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
4081
4082 /* Update the VSI after updating the VSI queue-mapping information */
4083 ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
4084 if (ret) {
4085 dev_info(&vsi->back->pdev->dev,
4086 "update vsi failed, aq_err=%d\n",
4087 vsi->back->hw.aq.asq_last_status);
4088 goto out;
4089 }
4090 /* update the local VSI info with updated queue map */
4091 i40e_vsi_update_queue_map(vsi, &ctxt);
4092 vsi->info.valid_sections = 0;
4093
4094 /* Update current VSI BW information */
4095 ret = i40e_vsi_get_bw_info(vsi);
4096 if (ret) {
4097 dev_info(&vsi->back->pdev->dev,
4098 "Failed updating vsi bw info, aq_err=%d\n",
4099 vsi->back->hw.aq.asq_last_status);
4100 goto out;
4101 }
4102
4103 /* Update the netdev TC setup */
4104 i40e_vsi_config_netdev_tc(vsi, enabled_tc);
4105out:
4106 return ret;
4107}
4108
4109/**
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004110 * i40e_veb_config_tc - Configure TCs for given VEB
4111 * @veb: given VEB
4112 * @enabled_tc: TC bitmap
4113 *
4114 * Configures given TC bitmap for VEB (switching) element
4115 **/
4116int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
4117{
4118 struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
4119 struct i40e_pf *pf = veb->pf;
4120 int ret = 0;
4121 int i;
4122
4123 /* No TCs or already enabled TCs just return */
4124 if (!enabled_tc || veb->enabled_tc == enabled_tc)
4125 return ret;
4126
4127 bw_data.tc_valid_bits = enabled_tc;
4128 /* bw_data.absolute_credits is not set (relative) */
4129
4130 /* Enable ETS TCs with equal BW Share for now */
4131 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4132 if (enabled_tc & (1 << i))
4133 bw_data.tc_bw_share_credits[i] = 1;
4134 }
4135
4136 ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
4137 &bw_data, NULL);
4138 if (ret) {
4139 dev_info(&pf->pdev->dev,
4140 "veb bw config failed, aq_err=%d\n",
4141 pf->hw.aq.asq_last_status);
4142 goto out;
4143 }
4144
4145 /* Update the BW information */
4146 ret = i40e_veb_get_bw_info(veb);
4147 if (ret) {
4148 dev_info(&pf->pdev->dev,
4149 "Failed getting veb bw config, aq_err=%d\n",
4150 pf->hw.aq.asq_last_status);
4151 }
4152
4153out:
4154 return ret;
4155}
4156
4157#ifdef CONFIG_I40E_DCB
4158/**
4159 * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
4160 * @pf: PF struct
4161 *
4162 * Reconfigure VEB/VSIs on a given PF; it is assumed that
4163 * the caller would've quiesce all the VSIs before calling
4164 * this function
4165 **/
4166static void i40e_dcb_reconfigure(struct i40e_pf *pf)
4167{
4168 u8 tc_map = 0;
4169 int ret;
4170 u8 v;
4171
4172 /* Enable the TCs available on PF to all VEBs */
4173 tc_map = i40e_pf_get_tc_map(pf);
4174 for (v = 0; v < I40E_MAX_VEB; v++) {
4175 if (!pf->veb[v])
4176 continue;
4177 ret = i40e_veb_config_tc(pf->veb[v], tc_map);
4178 if (ret) {
4179 dev_info(&pf->pdev->dev,
4180 "Failed configuring TC for VEB seid=%d\n",
4181 pf->veb[v]->seid);
4182 /* Will try to configure as many components */
4183 }
4184 }
4185
4186 /* Update each VSI */
Mitch Williams505682c2014-05-20 08:01:37 +00004187 for (v = 0; v < pf->num_alloc_vsi; v++) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004188 if (!pf->vsi[v])
4189 continue;
4190
4191 /* - Enable all TCs for the LAN VSI
4192 * - For all others keep them at TC0 for now
4193 */
4194 if (v == pf->lan_vsi)
4195 tc_map = i40e_pf_get_tc_map(pf);
4196 else
4197 tc_map = i40e_pf_get_default_tc(pf);
4198
4199 ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
4200 if (ret) {
4201 dev_info(&pf->pdev->dev,
4202 "Failed configuring TC for VSI seid=%d\n",
4203 pf->vsi[v]->seid);
4204 /* Will try to configure as many components */
4205 } else {
Neerav Parikh0672a092014-04-01 07:11:47 +00004206 /* Re-configure VSI vectors based on updated TC map */
4207 i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004208 if (pf->vsi[v]->netdev)
4209 i40e_dcbnl_set_all(pf->vsi[v]);
4210 }
4211 }
4212}
4213
4214/**
4215 * i40e_init_pf_dcb - Initialize DCB configuration
4216 * @pf: PF being configured
4217 *
4218 * Query the current DCB configuration and cache it
4219 * in the hardware structure
4220 **/
4221static int i40e_init_pf_dcb(struct i40e_pf *pf)
4222{
4223 struct i40e_hw *hw = &pf->hw;
4224 int err = 0;
4225
4226 if (pf->hw.func_caps.npar_enable)
4227 goto out;
4228
4229 /* Get the initial DCB configuration */
4230 err = i40e_init_dcb(hw);
4231 if (!err) {
4232 /* Device/Function is not DCBX capable */
4233 if ((!hw->func_caps.dcb) ||
4234 (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
4235 dev_info(&pf->pdev->dev,
4236 "DCBX offload is not supported or is disabled for this PF.\n");
4237
4238 if (pf->flags & I40E_FLAG_MFP_ENABLED)
4239 goto out;
4240
4241 } else {
4242 /* When status is not DISABLED then DCBX in FW */
4243 pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
4244 DCB_CAP_DCBX_VER_IEEE;
Neerav Parikh4d9b6042014-05-22 06:31:51 +00004245
4246 pf->flags |= I40E_FLAG_DCB_CAPABLE;
4247 /* Enable DCB tagging only when more than one TC */
4248 if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
4249 pf->flags |= I40E_FLAG_DCB_ENABLED;
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004250 }
Neerav Parikh014269f2014-04-01 07:11:48 +00004251 } else {
4252 dev_info(&pf->pdev->dev, "AQ Querying DCB configuration failed: %d\n",
4253 pf->hw.aq.asq_last_status);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004254 }
4255
4256out:
4257 return err;
4258}
4259#endif /* CONFIG_I40E_DCB */
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00004260#define SPEED_SIZE 14
4261#define FC_SIZE 8
4262/**
4263 * i40e_print_link_message - print link up or down
4264 * @vsi: the VSI for which link needs a message
4265 */
4266static void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
4267{
4268 char speed[SPEED_SIZE] = "Unknown";
4269 char fc[FC_SIZE] = "RX/TX";
4270
4271 if (!isup) {
4272 netdev_info(vsi->netdev, "NIC Link is Down\n");
4273 return;
4274 }
4275
4276 switch (vsi->back->hw.phy.link_info.link_speed) {
4277 case I40E_LINK_SPEED_40GB:
4278 strncpy(speed, "40 Gbps", SPEED_SIZE);
4279 break;
4280 case I40E_LINK_SPEED_10GB:
4281 strncpy(speed, "10 Gbps", SPEED_SIZE);
4282 break;
4283 case I40E_LINK_SPEED_1GB:
4284 strncpy(speed, "1000 Mbps", SPEED_SIZE);
4285 break;
4286 default:
4287 break;
4288 }
4289
4290 switch (vsi->back->hw.fc.current_mode) {
4291 case I40E_FC_FULL:
4292 strncpy(fc, "RX/TX", FC_SIZE);
4293 break;
4294 case I40E_FC_TX_PAUSE:
4295 strncpy(fc, "TX", FC_SIZE);
4296 break;
4297 case I40E_FC_RX_PAUSE:
4298 strncpy(fc, "RX", FC_SIZE);
4299 break;
4300 default:
4301 strncpy(fc, "None", FC_SIZE);
4302 break;
4303 }
4304
4305 netdev_info(vsi->netdev, "NIC Link is Up %s Full Duplex, Flow Control: %s\n",
4306 speed, fc);
4307}
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004308
4309/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004310 * i40e_up_complete - Finish the last steps of bringing up a connection
4311 * @vsi: the VSI being configured
4312 **/
4313static int i40e_up_complete(struct i40e_vsi *vsi)
4314{
4315 struct i40e_pf *pf = vsi->back;
4316 int err;
4317
4318 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
4319 i40e_vsi_configure_msix(vsi);
4320 else
4321 i40e_configure_msi_and_legacy(vsi);
4322
4323 /* start rings */
4324 err = i40e_vsi_control_rings(vsi, true);
4325 if (err)
4326 return err;
4327
4328 clear_bit(__I40E_DOWN, &vsi->state);
4329 i40e_napi_enable_all(vsi);
4330 i40e_vsi_enable_irq(vsi);
4331
4332 if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
4333 (vsi->netdev)) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00004334 i40e_print_link_message(vsi, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004335 netif_tx_start_all_queues(vsi->netdev);
4336 netif_carrier_on(vsi->netdev);
Anjali Singhai6d779b42013-09-28 06:00:02 +00004337 } else if (vsi->netdev) {
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00004338 i40e_print_link_message(vsi, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004339 }
Anjali Singhai Jainca64fa42014-02-11 08:26:30 +00004340
4341 /* replay FDIR SB filters */
4342 if (vsi->type == I40E_VSI_FDIR)
4343 i40e_fdir_filter_restore(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004344 i40e_service_event_schedule(pf);
4345
4346 return 0;
4347}
4348
4349/**
4350 * i40e_vsi_reinit_locked - Reset the VSI
4351 * @vsi: the VSI being configured
4352 *
4353 * Rebuild the ring structs after some configuration
4354 * has changed, e.g. MTU size.
4355 **/
4356static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
4357{
4358 struct i40e_pf *pf = vsi->back;
4359
4360 WARN_ON(in_interrupt());
4361 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
4362 usleep_range(1000, 2000);
4363 i40e_down(vsi);
4364
4365 /* Give a VF some time to respond to the reset. The
4366 * two second wait is based upon the watchdog cycle in
4367 * the VF driver.
4368 */
4369 if (vsi->type == I40E_VSI_SRIOV)
4370 msleep(2000);
4371 i40e_up(vsi);
4372 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
4373}
4374
4375/**
4376 * i40e_up - Bring the connection back up after being down
4377 * @vsi: the VSI being configured
4378 **/
4379int i40e_up(struct i40e_vsi *vsi)
4380{
4381 int err;
4382
4383 err = i40e_vsi_configure(vsi);
4384 if (!err)
4385 err = i40e_up_complete(vsi);
4386
4387 return err;
4388}
4389
4390/**
4391 * i40e_down - Shutdown the connection processing
4392 * @vsi: the VSI being stopped
4393 **/
4394void i40e_down(struct i40e_vsi *vsi)
4395{
4396 int i;
4397
4398 /* It is assumed that the caller of this function
4399 * sets the vsi->state __I40E_DOWN bit.
4400 */
4401 if (vsi->netdev) {
4402 netif_carrier_off(vsi->netdev);
4403 netif_tx_disable(vsi->netdev);
4404 }
4405 i40e_vsi_disable_irq(vsi);
4406 i40e_vsi_control_rings(vsi, false);
4407 i40e_napi_disable_all(vsi);
4408
4409 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00004410 i40e_clean_tx_ring(vsi->tx_rings[i]);
4411 i40e_clean_rx_ring(vsi->rx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004412 }
4413}
4414
4415/**
4416 * i40e_setup_tc - configure multiple traffic classes
4417 * @netdev: net device to configure
4418 * @tc: number of traffic classes to enable
4419 **/
4420static int i40e_setup_tc(struct net_device *netdev, u8 tc)
4421{
4422 struct i40e_netdev_priv *np = netdev_priv(netdev);
4423 struct i40e_vsi *vsi = np->vsi;
4424 struct i40e_pf *pf = vsi->back;
4425 u8 enabled_tc = 0;
4426 int ret = -EINVAL;
4427 int i;
4428
4429 /* Check if DCB enabled to continue */
4430 if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
4431 netdev_info(netdev, "DCB is not enabled for adapter\n");
4432 goto exit;
4433 }
4434
4435 /* Check if MFP enabled */
4436 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
4437 netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
4438 goto exit;
4439 }
4440
4441 /* Check whether tc count is within enabled limit */
4442 if (tc > i40e_pf_get_num_tc(pf)) {
4443 netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
4444 goto exit;
4445 }
4446
4447 /* Generate TC map for number of tc requested */
4448 for (i = 0; i < tc; i++)
4449 enabled_tc |= (1 << i);
4450
4451 /* Requesting same TC configuration as already enabled */
4452 if (enabled_tc == vsi->tc_config.enabled_tc)
4453 return 0;
4454
4455 /* Quiesce VSI queues */
4456 i40e_quiesce_vsi(vsi);
4457
4458 /* Configure VSI for enabled TCs */
4459 ret = i40e_vsi_config_tc(vsi, enabled_tc);
4460 if (ret) {
4461 netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
4462 vsi->seid);
4463 goto exit;
4464 }
4465
4466 /* Unquiesce VSI */
4467 i40e_unquiesce_vsi(vsi);
4468
4469exit:
4470 return ret;
4471}
4472
4473/**
4474 * i40e_open - Called when a network interface is made active
4475 * @netdev: network interface device structure
4476 *
4477 * The open entry point is called when a network interface is made
4478 * active by the system (IFF_UP). At this point all resources needed
4479 * for transmit and receive operations are allocated, the interrupt
4480 * handler is registered with the OS, the netdev watchdog subtask is
4481 * enabled, and the stack is notified that the interface is ready.
4482 *
4483 * Returns 0 on success, negative value on failure
4484 **/
4485static int i40e_open(struct net_device *netdev)
4486{
4487 struct i40e_netdev_priv *np = netdev_priv(netdev);
4488 struct i40e_vsi *vsi = np->vsi;
4489 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004490 int err;
4491
Shannon Nelson4eb3f762014-03-06 08:59:58 +00004492 /* disallow open during test or if eeprom is broken */
4493 if (test_bit(__I40E_TESTING, &pf->state) ||
4494 test_bit(__I40E_BAD_EEPROM, &pf->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004495 return -EBUSY;
4496
4497 netif_carrier_off(netdev);
4498
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00004499 err = i40e_vsi_open(vsi);
4500 if (err)
4501 return err;
4502
Jesse Brandeburg059dab62014-04-01 09:07:20 +00004503 /* configure global TSO hardware offload settings */
4504 wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
4505 TCP_FLAG_FIN) >> 16);
4506 wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
4507 TCP_FLAG_FIN |
4508 TCP_FLAG_CWR) >> 16);
4509 wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
4510
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00004511#ifdef CONFIG_I40E_VXLAN
4512 vxlan_get_rx_port(netdev);
4513#endif
4514
4515 return 0;
4516}
4517
4518/**
4519 * i40e_vsi_open -
4520 * @vsi: the VSI to open
4521 *
4522 * Finish initialization of the VSI.
4523 *
4524 * Returns 0 on success, negative value on failure
4525 **/
4526int i40e_vsi_open(struct i40e_vsi *vsi)
4527{
4528 struct i40e_pf *pf = vsi->back;
4529 char int_name[IFNAMSIZ];
4530 int err;
4531
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004532 /* allocate descriptors */
4533 err = i40e_vsi_setup_tx_resources(vsi);
4534 if (err)
4535 goto err_setup_tx;
4536 err = i40e_vsi_setup_rx_resources(vsi);
4537 if (err)
4538 goto err_setup_rx;
4539
4540 err = i40e_vsi_configure(vsi);
4541 if (err)
4542 goto err_setup_rx;
4543
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00004544 if (vsi->netdev) {
4545 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
4546 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
4547 err = i40e_vsi_request_irq(vsi, int_name);
4548 if (err)
4549 goto err_setup_rx;
4550
4551 /* Notify the stack of the actual queue counts. */
4552 err = netif_set_real_num_tx_queues(vsi->netdev,
4553 vsi->num_queue_pairs);
4554 if (err)
4555 goto err_set_queues;
4556
4557 err = netif_set_real_num_rx_queues(vsi->netdev,
4558 vsi->num_queue_pairs);
4559 if (err)
4560 goto err_set_queues;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00004561
4562 } else if (vsi->type == I40E_VSI_FDIR) {
4563 snprintf(int_name, sizeof(int_name) - 1, "%s-fdir",
4564 dev_driver_string(&pf->pdev->dev));
4565 err = i40e_vsi_request_irq(vsi, int_name);
Shannon Nelsonc22e3c62014-03-14 07:32:25 +00004566 } else {
Jean Sacrence9ccb12014-05-01 14:31:18 +00004567 err = -EINVAL;
Elizabeth Kappler6c167f52014-02-15 07:41:38 +00004568 goto err_setup_rx;
4569 }
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00004570
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004571 err = i40e_up_complete(vsi);
4572 if (err)
4573 goto err_up_complete;
4574
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004575 return 0;
4576
4577err_up_complete:
4578 i40e_down(vsi);
Anjali Singhai Jain25946dd2013-11-26 10:49:14 +00004579err_set_queues:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004580 i40e_vsi_free_irq(vsi);
4581err_setup_rx:
4582 i40e_vsi_free_rx_resources(vsi);
4583err_setup_tx:
4584 i40e_vsi_free_tx_resources(vsi);
4585 if (vsi == pf->vsi[pf->lan_vsi])
4586 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
4587
4588 return err;
4589}
4590
4591/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004592 * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
4593 * @pf: Pointer to pf
4594 *
4595 * This function destroys the hlist where all the Flow Director
4596 * filters were saved.
4597 **/
4598static void i40e_fdir_filter_exit(struct i40e_pf *pf)
4599{
4600 struct i40e_fdir_filter *filter;
4601 struct hlist_node *node2;
4602
4603 hlist_for_each_entry_safe(filter, node2,
4604 &pf->fdir_filter_list, fdir_node) {
4605 hlist_del(&filter->fdir_node);
4606 kfree(filter);
4607 }
4608 pf->fdir_pf_active_filters = 0;
4609}
4610
4611/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004612 * i40e_close - Disables a network interface
4613 * @netdev: network interface device structure
4614 *
4615 * The close entry point is called when an interface is de-activated
4616 * by the OS. The hardware is still under the driver's control, but
4617 * this netdev interface is disabled.
4618 *
4619 * Returns 0, this is not allowed to fail
4620 **/
4621static int i40e_close(struct net_device *netdev)
4622{
4623 struct i40e_netdev_priv *np = netdev_priv(netdev);
4624 struct i40e_vsi *vsi = np->vsi;
4625
Shannon Nelson90ef8d42014-03-14 07:32:26 +00004626 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004627
4628 return 0;
4629}
4630
4631/**
4632 * i40e_do_reset - Start a PF or Core Reset sequence
4633 * @pf: board private structure
4634 * @reset_flags: which reset is requested
4635 *
4636 * The essential difference in resets is that the PF Reset
4637 * doesn't clear the packet buffers, doesn't reset the PE
4638 * firmware, and doesn't bother the other PFs on the chip.
4639 **/
4640void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
4641{
4642 u32 val;
4643
4644 WARN_ON(in_interrupt());
4645
Mitch Williams263fc482014-04-23 04:50:11 +00004646 if (i40e_check_asq_alive(&pf->hw))
4647 i40e_vc_notify_reset(pf);
4648
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004649 /* do the biggest reset indicated */
4650 if (reset_flags & (1 << __I40E_GLOBAL_RESET_REQUESTED)) {
4651
4652 /* Request a Global Reset
4653 *
4654 * This will start the chip's countdown to the actual full
4655 * chip reset event, and a warning interrupt to be sent
4656 * to all PFs, including the requestor. Our handler
4657 * for the warning interrupt will deal with the shutdown
4658 * and recovery of the switch setup.
4659 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004660 dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004661 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
4662 val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
4663 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
4664
4665 } else if (reset_flags & (1 << __I40E_CORE_RESET_REQUESTED)) {
4666
4667 /* Request a Core Reset
4668 *
4669 * Same as Global Reset, except does *not* include the MAC/PHY
4670 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004671 dev_dbg(&pf->pdev->dev, "CoreR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004672 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
4673 val |= I40E_GLGEN_RTRIG_CORER_MASK;
4674 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
4675 i40e_flush(&pf->hw);
4676
Shannon Nelson7823fe32013-11-16 10:00:45 +00004677 } else if (reset_flags & (1 << __I40E_EMP_RESET_REQUESTED)) {
4678
4679 /* Request a Firmware Reset
4680 *
4681 * Same as Global reset, plus restarting the
4682 * embedded firmware engine.
4683 */
4684 /* enable EMP Reset */
4685 val = rd32(&pf->hw, I40E_GLGEN_RSTENA_EMP);
4686 val |= I40E_GLGEN_RSTENA_EMP_EMP_RST_ENA_MASK;
4687 wr32(&pf->hw, I40E_GLGEN_RSTENA_EMP, val);
4688
4689 /* force the reset */
4690 val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
4691 val |= I40E_GLGEN_RTRIG_EMPFWR_MASK;
4692 wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
4693 i40e_flush(&pf->hw);
4694
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004695 } else if (reset_flags & (1 << __I40E_PF_RESET_REQUESTED)) {
4696
4697 /* Request a PF Reset
4698 *
4699 * Resets only the PF-specific registers
4700 *
4701 * This goes directly to the tear-down and rebuild of
4702 * the switch, since we need to do all the recovery as
4703 * for the Core Reset.
4704 */
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004705 dev_dbg(&pf->pdev->dev, "PFR requested\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004706 i40e_handle_reset_warning(pf);
4707
4708 } else if (reset_flags & (1 << __I40E_REINIT_REQUESTED)) {
4709 int v;
4710
4711 /* Find the VSI(s) that requested a re-init */
4712 dev_info(&pf->pdev->dev,
4713 "VSI reinit requested\n");
Mitch Williams505682c2014-05-20 08:01:37 +00004714 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004715 struct i40e_vsi *vsi = pf->vsi[v];
4716 if (vsi != NULL &&
4717 test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
4718 i40e_vsi_reinit_locked(pf->vsi[v]);
4719 clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
4720 }
4721 }
4722
4723 /* no further action needed, so return now */
4724 return;
Neerav Parikhb5d06f02014-06-03 23:50:17 +00004725 } else if (reset_flags & (1 << __I40E_DOWN_REQUESTED)) {
4726 int v;
4727
4728 /* Find the VSI(s) that needs to be brought down */
4729 dev_info(&pf->pdev->dev, "VSI down requested\n");
4730 for (v = 0; v < pf->num_alloc_vsi; v++) {
4731 struct i40e_vsi *vsi = pf->vsi[v];
4732 if (vsi != NULL &&
4733 test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) {
4734 set_bit(__I40E_DOWN, &vsi->state);
4735 i40e_down(vsi);
4736 clear_bit(__I40E_DOWN_REQUESTED, &vsi->state);
4737 }
4738 }
4739
4740 /* no further action needed, so return now */
4741 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004742 } else {
4743 dev_info(&pf->pdev->dev,
4744 "bad reset request 0x%08x\n", reset_flags);
4745 return;
4746 }
4747}
4748
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004749#ifdef CONFIG_I40E_DCB
4750/**
4751 * i40e_dcb_need_reconfig - Check if DCB needs reconfig
4752 * @pf: board private structure
4753 * @old_cfg: current DCB config
4754 * @new_cfg: new DCB config
4755 **/
4756bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
4757 struct i40e_dcbx_config *old_cfg,
4758 struct i40e_dcbx_config *new_cfg)
4759{
4760 bool need_reconfig = false;
4761
4762 /* Check if ETS configuration has changed */
4763 if (memcmp(&new_cfg->etscfg,
4764 &old_cfg->etscfg,
4765 sizeof(new_cfg->etscfg))) {
4766 /* If Priority Table has changed reconfig is needed */
4767 if (memcmp(&new_cfg->etscfg.prioritytable,
4768 &old_cfg->etscfg.prioritytable,
4769 sizeof(new_cfg->etscfg.prioritytable))) {
4770 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004771 dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004772 }
4773
4774 if (memcmp(&new_cfg->etscfg.tcbwtable,
4775 &old_cfg->etscfg.tcbwtable,
4776 sizeof(new_cfg->etscfg.tcbwtable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004777 dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004778
4779 if (memcmp(&new_cfg->etscfg.tsatable,
4780 &old_cfg->etscfg.tsatable,
4781 sizeof(new_cfg->etscfg.tsatable)))
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004782 dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004783 }
4784
4785 /* Check if PFC configuration has changed */
4786 if (memcmp(&new_cfg->pfc,
4787 &old_cfg->pfc,
4788 sizeof(new_cfg->pfc))) {
4789 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004790 dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004791 }
4792
4793 /* Check if APP Table has changed */
4794 if (memcmp(&new_cfg->app,
4795 &old_cfg->app,
Dave Jones3d9667a2014-01-27 23:11:09 -05004796 sizeof(new_cfg->app))) {
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004797 need_reconfig = true;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004798 dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
Dave Jones3d9667a2014-01-27 23:11:09 -05004799 }
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004800
4801 return need_reconfig;
4802}
4803
4804/**
4805 * i40e_handle_lldp_event - Handle LLDP Change MIB event
4806 * @pf: board private structure
4807 * @e: event info posted on ARQ
4808 **/
4809static int i40e_handle_lldp_event(struct i40e_pf *pf,
4810 struct i40e_arq_event_info *e)
4811{
4812 struct i40e_aqc_lldp_get_mib *mib =
4813 (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
4814 struct i40e_hw *hw = &pf->hw;
4815 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
4816 struct i40e_dcbx_config tmp_dcbx_cfg;
4817 bool need_reconfig = false;
4818 int ret = 0;
4819 u8 type;
4820
Neerav Parikh4d9b6042014-05-22 06:31:51 +00004821 /* Not DCB capable or capability disabled */
4822 if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
4823 return ret;
4824
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004825 /* Ignore if event is not for Nearest Bridge */
4826 type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
4827 & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
4828 if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
4829 return ret;
4830
4831 /* Check MIB Type and return if event for Remote MIB update */
4832 type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
4833 if (type == I40E_AQ_LLDP_MIB_REMOTE) {
4834 /* Update the remote cached instance and return */
4835 ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
4836 I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
4837 &hw->remote_dcbx_config);
4838 goto exit;
4839 }
4840
4841 /* Convert/store the DCBX data from LLDPDU temporarily */
4842 memset(&tmp_dcbx_cfg, 0, sizeof(tmp_dcbx_cfg));
4843 ret = i40e_lldp_to_dcb_config(e->msg_buf, &tmp_dcbx_cfg);
4844 if (ret) {
4845 /* Error in LLDPDU parsing return */
4846 dev_info(&pf->pdev->dev, "Failed parsing LLDPDU from event buffer\n");
4847 goto exit;
4848 }
4849
4850 /* No change detected in DCBX configs */
4851 if (!memcmp(&tmp_dcbx_cfg, dcbx_cfg, sizeof(tmp_dcbx_cfg))) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004852 dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004853 goto exit;
4854 }
4855
4856 need_reconfig = i40e_dcb_need_reconfig(pf, dcbx_cfg, &tmp_dcbx_cfg);
4857
4858 i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg);
4859
4860 /* Overwrite the new configuration */
4861 *dcbx_cfg = tmp_dcbx_cfg;
4862
4863 if (!need_reconfig)
4864 goto exit;
4865
Neerav Parikh4d9b6042014-05-22 06:31:51 +00004866 /* Enable DCB tagging only when more than one TC */
4867 if (i40e_dcb_get_num_tc(dcbx_cfg) > 1)
4868 pf->flags |= I40E_FLAG_DCB_ENABLED;
4869 else
4870 pf->flags &= ~I40E_FLAG_DCB_ENABLED;
4871
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08004872 /* Reconfiguration needed quiesce all VSIs */
4873 i40e_pf_quiesce_all_vsi(pf);
4874
4875 /* Changes in configuration update VEB/VSI */
4876 i40e_dcb_reconfigure(pf);
4877
4878 i40e_pf_unquiesce_all_vsi(pf);
4879exit:
4880 return ret;
4881}
4882#endif /* CONFIG_I40E_DCB */
4883
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004884/**
Anjali Singhai Jain23326182013-11-26 10:49:22 +00004885 * i40e_do_reset_safe - Protected reset path for userland calls.
4886 * @pf: board private structure
4887 * @reset_flags: which reset is requested
4888 *
4889 **/
4890void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
4891{
4892 rtnl_lock();
4893 i40e_do_reset(pf, reset_flags);
4894 rtnl_unlock();
4895}
4896
4897/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004898 * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
4899 * @pf: board private structure
4900 * @e: event info posted on ARQ
4901 *
4902 * Handler for LAN Queue Overflow Event generated by the firmware for PF
4903 * and VF queues
4904 **/
4905static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
4906 struct i40e_arq_event_info *e)
4907{
4908 struct i40e_aqc_lan_overflow *data =
4909 (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
4910 u32 queue = le32_to_cpu(data->prtdcb_rupto);
4911 u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
4912 struct i40e_hw *hw = &pf->hw;
4913 struct i40e_vf *vf;
4914 u16 vf_id;
4915
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00004916 dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
4917 queue, qtx_ctl);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004918
4919 /* Queue belongs to VF, find the VF and issue VF reset */
4920 if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
4921 >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
4922 vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
4923 >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
4924 vf_id -= hw->func_caps.vf_base_id;
4925 vf = &pf->vf[vf_id];
4926 i40e_vc_notify_vf_reset(vf);
4927 /* Allow VF to process pending reset notification */
4928 msleep(20);
4929 i40e_reset_vf(vf, false);
4930 }
4931}
4932
4933/**
4934 * i40e_service_event_complete - Finish up the service event
4935 * @pf: board private structure
4936 **/
4937static void i40e_service_event_complete(struct i40e_pf *pf)
4938{
4939 BUG_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state));
4940
4941 /* flush memory to make sure state is correct before next watchog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01004942 smp_mb__before_atomic();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00004943 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
4944}
4945
4946/**
Anjali Singhai Jain12957382014-06-04 04:22:47 +00004947 * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
4948 * @pf: board private structure
4949 **/
4950int i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
4951{
4952 int val, fcnt_prog;
4953
4954 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
4955 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
4956 return fcnt_prog;
4957}
4958
4959/**
4960 * i40e_get_current_fd_count - Get the count of total FD filters programmed
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00004961 * @pf: board private structure
4962 **/
4963int i40e_get_current_fd_count(struct i40e_pf *pf)
4964{
4965 int val, fcnt_prog;
4966 val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
4967 fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
4968 ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
4969 I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
4970 return fcnt_prog;
4971}
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00004972/**
4973 * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
4974 * @pf: board private structure
4975 **/
4976void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
4977{
4978 u32 fcnt_prog, fcnt_avail;
4979
4980 /* Check if, FD SB or ATR was auto disabled and if there is enough room
4981 * to re-enable
4982 */
4983 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
4984 (pf->flags & I40E_FLAG_FD_SB_ENABLED))
4985 return;
Anjali Singhai Jain12957382014-06-04 04:22:47 +00004986 fcnt_prog = i40e_get_cur_guaranteed_fd_count(pf);
4987 fcnt_avail = pf->fdir_pf_filter_count;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00004988 if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) {
4989 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
4990 (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
4991 pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
4992 dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
4993 }
4994 }
4995 /* Wait for some more space to be available to turn on ATR */
4996 if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
4997 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
4998 (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
4999 pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
5000 dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table now\n");
5001 }
5002 }
5003}
5004
5005/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005006 * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
5007 * @pf: board private structure
5008 **/
5009static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
5010{
5011 if (!(pf->flags & I40E_FLAG_FDIR_REQUIRES_REINIT))
5012 return;
5013
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005014 /* if interface is down do nothing */
5015 if (test_bit(__I40E_DOWN, &pf->state))
5016 return;
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00005017 i40e_fdir_check_and_reenable(pf);
5018
5019 if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
5020 (pf->flags & I40E_FLAG_FD_SB_ENABLED))
5021 pf->flags &= ~I40E_FLAG_FDIR_REQUIRES_REINIT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005022}
5023
5024/**
5025 * i40e_vsi_link_event - notify VSI of a link event
5026 * @vsi: vsi to be notified
5027 * @link_up: link up or down
5028 **/
5029static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
5030{
5031 if (!vsi)
5032 return;
5033
5034 switch (vsi->type) {
5035 case I40E_VSI_MAIN:
5036 if (!vsi->netdev || !vsi->netdev_registered)
5037 break;
5038
5039 if (link_up) {
5040 netif_carrier_on(vsi->netdev);
5041 netif_tx_wake_all_queues(vsi->netdev);
5042 } else {
5043 netif_carrier_off(vsi->netdev);
5044 netif_tx_stop_all_queues(vsi->netdev);
5045 }
5046 break;
5047
5048 case I40E_VSI_SRIOV:
5049 break;
5050
5051 case I40E_VSI_VMDQ2:
5052 case I40E_VSI_CTRL:
5053 case I40E_VSI_MIRROR:
5054 default:
5055 /* there is no notification for other VSIs */
5056 break;
5057 }
5058}
5059
5060/**
5061 * i40e_veb_link_event - notify elements on the veb of a link event
5062 * @veb: veb to be notified
5063 * @link_up: link up or down
5064 **/
5065static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
5066{
5067 struct i40e_pf *pf;
5068 int i;
5069
5070 if (!veb || !veb->pf)
5071 return;
5072 pf = veb->pf;
5073
5074 /* depth first... */
5075 for (i = 0; i < I40E_MAX_VEB; i++)
5076 if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
5077 i40e_veb_link_event(pf->veb[i], link_up);
5078
5079 /* ... now the local VSIs */
Mitch Williams505682c2014-05-20 08:01:37 +00005080 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005081 if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
5082 i40e_vsi_link_event(pf->vsi[i], link_up);
5083}
5084
5085/**
5086 * i40e_link_event - Update netif_carrier status
5087 * @pf: board private structure
5088 **/
5089static void i40e_link_event(struct i40e_pf *pf)
5090{
5091 bool new_link, old_link;
5092
5093 new_link = (pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP);
5094 old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
5095
5096 if (new_link == old_link)
5097 return;
Anjali Singhai6d779b42013-09-28 06:00:02 +00005098 if (!test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state))
Jesse Brandeburgcf05ed02014-04-23 04:50:12 +00005099 i40e_print_link_message(pf->vsi[pf->lan_vsi], new_link);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005100
5101 /* Notify the base of the switch tree connected to
5102 * the link. Floating VEBs are not notified.
5103 */
5104 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
5105 i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
5106 else
5107 i40e_vsi_link_event(pf->vsi[pf->lan_vsi], new_link);
5108
5109 if (pf->vf)
5110 i40e_vc_notify_link_state(pf);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00005111
5112 if (pf->flags & I40E_FLAG_PTP)
5113 i40e_ptp_set_increment(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005114}
5115
5116/**
5117 * i40e_check_hang_subtask - Check for hung queues and dropped interrupts
5118 * @pf: board private structure
5119 *
5120 * Set the per-queue flags to request a check for stuck queues in the irq
5121 * clean functions, then force interrupts to be sure the irq clean is called.
5122 **/
5123static void i40e_check_hang_subtask(struct i40e_pf *pf)
5124{
5125 int i, v;
5126
5127 /* If we're down or resetting, just bail */
5128 if (test_bit(__I40E_CONFIG_BUSY, &pf->state))
5129 return;
5130
5131 /* for each VSI/netdev
5132 * for each Tx queue
5133 * set the check flag
5134 * for each q_vector
5135 * force an interrupt
5136 */
Mitch Williams505682c2014-05-20 08:01:37 +00005137 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005138 struct i40e_vsi *vsi = pf->vsi[v];
5139 int armed = 0;
5140
5141 if (!pf->vsi[v] ||
5142 test_bit(__I40E_DOWN, &vsi->state) ||
5143 (vsi->netdev && !netif_carrier_ok(vsi->netdev)))
5144 continue;
5145
5146 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00005147 set_check_for_tx_hang(vsi->tx_rings[i]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005148 if (test_bit(__I40E_HANG_CHECK_ARMED,
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00005149 &vsi->tx_rings[i]->state))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005150 armed++;
5151 }
5152
5153 if (armed) {
5154 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
5155 wr32(&vsi->back->hw, I40E_PFINT_DYN_CTL0,
5156 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
5157 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
5158 } else {
5159 u16 vec = vsi->base_vector - 1;
5160 u32 val = (I40E_PFINT_DYN_CTLN_INTENA_MASK |
5161 I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK);
5162 for (i = 0; i < vsi->num_q_vectors; i++, vec++)
5163 wr32(&vsi->back->hw,
5164 I40E_PFINT_DYN_CTLN(vec), val);
5165 }
5166 i40e_flush(&vsi->back->hw);
5167 }
5168 }
5169}
5170
5171/**
5172 * i40e_watchdog_subtask - Check and bring link up
5173 * @pf: board private structure
5174 **/
5175static void i40e_watchdog_subtask(struct i40e_pf *pf)
5176{
5177 int i;
5178
5179 /* if interface is down do nothing */
5180 if (test_bit(__I40E_DOWN, &pf->state) ||
5181 test_bit(__I40E_CONFIG_BUSY, &pf->state))
5182 return;
5183
5184 /* Update the stats for active netdevs so the network stack
5185 * can look at updated numbers whenever it cares to
5186 */
Mitch Williams505682c2014-05-20 08:01:37 +00005187 for (i = 0; i < pf->num_alloc_vsi; i++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005188 if (pf->vsi[i] && pf->vsi[i]->netdev)
5189 i40e_update_stats(pf->vsi[i]);
5190
5191 /* Update the stats for the active switching components */
5192 for (i = 0; i < I40E_MAX_VEB; i++)
5193 if (pf->veb[i])
5194 i40e_update_veb_stats(pf->veb[i]);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00005195
5196 i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005197}
5198
5199/**
5200 * i40e_reset_subtask - Set up for resetting the device and driver
5201 * @pf: board private structure
5202 **/
5203static void i40e_reset_subtask(struct i40e_pf *pf)
5204{
5205 u32 reset_flags = 0;
5206
Anjali Singhai Jain23326182013-11-26 10:49:22 +00005207 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005208 if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
5209 reset_flags |= (1 << __I40E_REINIT_REQUESTED);
5210 clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
5211 }
5212 if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
5213 reset_flags |= (1 << __I40E_PF_RESET_REQUESTED);
5214 clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
5215 }
5216 if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
5217 reset_flags |= (1 << __I40E_CORE_RESET_REQUESTED);
5218 clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
5219 }
5220 if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
5221 reset_flags |= (1 << __I40E_GLOBAL_RESET_REQUESTED);
5222 clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
5223 }
Neerav Parikhb5d06f02014-06-03 23:50:17 +00005224 if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) {
5225 reset_flags |= (1 << __I40E_DOWN_REQUESTED);
5226 clear_bit(__I40E_DOWN_REQUESTED, &pf->state);
5227 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005228
5229 /* If there's a recovery already waiting, it takes
5230 * precedence before starting a new reset sequence.
5231 */
5232 if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
5233 i40e_handle_reset_warning(pf);
Anjali Singhai Jain23326182013-11-26 10:49:22 +00005234 goto unlock;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005235 }
5236
5237 /* If we're already down or resetting, just bail */
5238 if (reset_flags &&
5239 !test_bit(__I40E_DOWN, &pf->state) &&
5240 !test_bit(__I40E_CONFIG_BUSY, &pf->state))
5241 i40e_do_reset(pf, reset_flags);
Anjali Singhai Jain23326182013-11-26 10:49:22 +00005242
5243unlock:
5244 rtnl_unlock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005245}
5246
5247/**
5248 * i40e_handle_link_event - Handle link event
5249 * @pf: board private structure
5250 * @e: event info posted on ARQ
5251 **/
5252static void i40e_handle_link_event(struct i40e_pf *pf,
5253 struct i40e_arq_event_info *e)
5254{
5255 struct i40e_hw *hw = &pf->hw;
5256 struct i40e_aqc_get_link_status *status =
5257 (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
5258 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
5259
5260 /* save off old link status information */
5261 memcpy(&pf->hw.phy.link_info_old, hw_link_info,
5262 sizeof(pf->hw.phy.link_info_old));
5263
5264 /* update link status */
5265 hw_link_info->phy_type = (enum i40e_aq_phy_type)status->phy_type;
5266 hw_link_info->link_speed = (enum i40e_aq_link_speed)status->link_speed;
5267 hw_link_info->link_info = status->link_info;
5268 hw_link_info->an_info = status->an_info;
5269 hw_link_info->ext_info = status->ext_info;
5270 hw_link_info->lse_enable =
5271 le16_to_cpu(status->command_flags) &
5272 I40E_AQ_LSE_ENABLE;
5273
5274 /* process the event */
5275 i40e_link_event(pf);
5276
5277 /* Do a new status request to re-enable LSE reporting
5278 * and load new status information into the hw struct,
5279 * then see if the status changed while processing the
5280 * initial event.
5281 */
5282 i40e_aq_get_link_info(&pf->hw, true, NULL, NULL);
5283 i40e_link_event(pf);
5284}
5285
5286/**
5287 * i40e_clean_adminq_subtask - Clean the AdminQ rings
5288 * @pf: board private structure
5289 **/
5290static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
5291{
5292 struct i40e_arq_event_info event;
5293 struct i40e_hw *hw = &pf->hw;
5294 u16 pending, i = 0;
5295 i40e_status ret;
5296 u16 opcode;
Shannon Nelson86df2422014-05-20 08:01:35 +00005297 u32 oldval;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005298 u32 val;
5299
5300 if (!test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state))
5301 return;
5302
Shannon Nelson86df2422014-05-20 08:01:35 +00005303 /* check for error indications */
5304 val = rd32(&pf->hw, pf->hw.aq.arq.len);
5305 oldval = val;
5306 if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
5307 dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
5308 val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
5309 }
5310 if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
5311 dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
5312 val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
5313 }
5314 if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
5315 dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
5316 val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
5317 }
5318 if (oldval != val)
5319 wr32(&pf->hw, pf->hw.aq.arq.len, val);
5320
5321 val = rd32(&pf->hw, pf->hw.aq.asq.len);
5322 oldval = val;
5323 if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
5324 dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
5325 val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
5326 }
5327 if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
5328 dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
5329 val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
5330 }
5331 if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
5332 dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
5333 val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
5334 }
5335 if (oldval != val)
5336 wr32(&pf->hw, pf->hw.aq.asq.len, val);
5337
Mitch Williams3197ce22013-11-28 06:39:39 +00005338 event.msg_size = I40E_MAX_AQ_BUF_SIZE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005339 event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
5340 if (!event.msg_buf)
5341 return;
5342
5343 do {
Mitch Williams2f019122013-11-28 06:39:33 +00005344 event.msg_size = I40E_MAX_AQ_BUF_SIZE; /* reinit each time */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005345 ret = i40e_clean_arq_element(hw, &event, &pending);
5346 if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
5347 dev_info(&pf->pdev->dev, "No ARQ event found\n");
5348 break;
5349 } else if (ret) {
5350 dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
5351 break;
5352 }
5353
5354 opcode = le16_to_cpu(event.desc.opcode);
5355 switch (opcode) {
5356
5357 case i40e_aqc_opc_get_link_status:
5358 i40e_handle_link_event(pf, &event);
5359 break;
5360 case i40e_aqc_opc_send_msg_to_pf:
5361 ret = i40e_vc_process_vf_msg(pf,
5362 le16_to_cpu(event.desc.retval),
5363 le32_to_cpu(event.desc.cookie_high),
5364 le32_to_cpu(event.desc.cookie_low),
5365 event.msg_buf,
5366 event.msg_size);
5367 break;
5368 case i40e_aqc_opc_lldp_update_mib:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005369 dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005370#ifdef CONFIG_I40E_DCB
5371 rtnl_lock();
5372 ret = i40e_handle_lldp_event(pf, &event);
5373 rtnl_unlock();
5374#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005375 break;
5376 case i40e_aqc_opc_event_lan_overflow:
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005377 dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005378 i40e_handle_lan_overflow_event(pf, &event);
5379 break;
Shannon Nelson0467bc92013-12-18 13:45:58 +00005380 case i40e_aqc_opc_send_msg_to_peer:
5381 dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
5382 break;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005383 default:
5384 dev_info(&pf->pdev->dev,
Shannon Nelson0467bc92013-12-18 13:45:58 +00005385 "ARQ Error: Unknown event 0x%04x received\n",
5386 opcode);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005387 break;
5388 }
5389 } while (pending && (i++ < pf->adminq_work_limit));
5390
5391 clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
5392 /* re-enable Admin queue interrupt cause */
5393 val = rd32(hw, I40E_PFINT_ICR0_ENA);
5394 val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
5395 wr32(hw, I40E_PFINT_ICR0_ENA, val);
5396 i40e_flush(hw);
5397
5398 kfree(event.msg_buf);
5399}
5400
5401/**
Shannon Nelson4eb3f762014-03-06 08:59:58 +00005402 * i40e_verify_eeprom - make sure eeprom is good to use
5403 * @pf: board private structure
5404 **/
5405static void i40e_verify_eeprom(struct i40e_pf *pf)
5406{
5407 int err;
5408
5409 err = i40e_diag_eeprom_test(&pf->hw);
5410 if (err) {
5411 /* retry in case of garbage read */
5412 err = i40e_diag_eeprom_test(&pf->hw);
5413 if (err) {
5414 dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
5415 err);
5416 set_bit(__I40E_BAD_EEPROM, &pf->state);
5417 }
5418 }
5419
5420 if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
5421 dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
5422 clear_bit(__I40E_BAD_EEPROM, &pf->state);
5423 }
5424}
5425
5426/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005427 * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
5428 * @veb: pointer to the VEB instance
5429 *
5430 * This is a recursive function that first builds the attached VSIs then
5431 * recurses in to build the next layer of VEB. We track the connections
5432 * through our own index numbers because the seid's from the HW could
5433 * change across the reset.
5434 **/
5435static int i40e_reconstitute_veb(struct i40e_veb *veb)
5436{
5437 struct i40e_vsi *ctl_vsi = NULL;
5438 struct i40e_pf *pf = veb->pf;
5439 int v, veb_idx;
5440 int ret;
5441
5442 /* build VSI that owns this VEB, temporarily attached to base VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00005443 for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005444 if (pf->vsi[v] &&
5445 pf->vsi[v]->veb_idx == veb->idx &&
5446 pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
5447 ctl_vsi = pf->vsi[v];
5448 break;
5449 }
5450 }
5451 if (!ctl_vsi) {
5452 dev_info(&pf->pdev->dev,
5453 "missing owner VSI for veb_idx %d\n", veb->idx);
5454 ret = -ENOENT;
5455 goto end_reconstitute;
5456 }
5457 if (ctl_vsi != pf->vsi[pf->lan_vsi])
5458 ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
5459 ret = i40e_add_vsi(ctl_vsi);
5460 if (ret) {
5461 dev_info(&pf->pdev->dev,
5462 "rebuild of owner VSI failed: %d\n", ret);
5463 goto end_reconstitute;
5464 }
5465 i40e_vsi_reset_stats(ctl_vsi);
5466
5467 /* create the VEB in the switch and move the VSI onto the VEB */
5468 ret = i40e_add_veb(veb, ctl_vsi);
5469 if (ret)
5470 goto end_reconstitute;
5471
5472 /* create the remaining VSIs attached to this VEB */
Mitch Williams505682c2014-05-20 08:01:37 +00005473 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005474 if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
5475 continue;
5476
5477 if (pf->vsi[v]->veb_idx == veb->idx) {
5478 struct i40e_vsi *vsi = pf->vsi[v];
5479 vsi->uplink_seid = veb->seid;
5480 ret = i40e_add_vsi(vsi);
5481 if (ret) {
5482 dev_info(&pf->pdev->dev,
5483 "rebuild of vsi_idx %d failed: %d\n",
5484 v, ret);
5485 goto end_reconstitute;
5486 }
5487 i40e_vsi_reset_stats(vsi);
5488 }
5489 }
5490
5491 /* create any VEBs attached to this VEB - RECURSION */
5492 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
5493 if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
5494 pf->veb[veb_idx]->uplink_seid = veb->seid;
5495 ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
5496 if (ret)
5497 break;
5498 }
5499 }
5500
5501end_reconstitute:
5502 return ret;
5503}
5504
5505/**
5506 * i40e_get_capabilities - get info about the HW
5507 * @pf: the PF struct
5508 **/
5509static int i40e_get_capabilities(struct i40e_pf *pf)
5510{
5511 struct i40e_aqc_list_capabilities_element_resp *cap_buf;
5512 u16 data_size;
5513 int buf_len;
5514 int err;
5515
5516 buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
5517 do {
5518 cap_buf = kzalloc(buf_len, GFP_KERNEL);
5519 if (!cap_buf)
5520 return -ENOMEM;
5521
5522 /* this loads the data into the hw struct for us */
5523 err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
5524 &data_size,
5525 i40e_aqc_opc_list_func_capabilities,
5526 NULL);
5527 /* data loaded, buffer no longer needed */
5528 kfree(cap_buf);
5529
5530 if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
5531 /* retry with a larger buffer */
5532 buf_len = data_size;
5533 } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
5534 dev_info(&pf->pdev->dev,
5535 "capability discovery failed: aq=%d\n",
5536 pf->hw.aq.asq_last_status);
5537 return -ENODEV;
5538 }
5539 } while (err);
5540
Anjali Singhai Jainac71b7b2014-02-06 05:51:08 +00005541 if (((pf->hw.aq.fw_maj_ver == 2) && (pf->hw.aq.fw_min_ver < 22)) ||
5542 (pf->hw.aq.fw_maj_ver < 2)) {
5543 pf->hw.func_caps.num_msix_vectors++;
5544 pf->hw.func_caps.num_msix_vectors_vf++;
5545 }
5546
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005547 if (pf->hw.debug_mask & I40E_DEBUG_USER)
5548 dev_info(&pf->pdev->dev,
5549 "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",
5550 pf->hw.pf_id, pf->hw.func_caps.num_vfs,
5551 pf->hw.func_caps.num_msix_vectors,
5552 pf->hw.func_caps.num_msix_vectors_vf,
5553 pf->hw.func_caps.fd_filters_guaranteed,
5554 pf->hw.func_caps.fd_filters_best_effort,
5555 pf->hw.func_caps.num_tx_qp,
5556 pf->hw.func_caps.num_vsis);
5557
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00005558#define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
5559 + pf->hw.func_caps.num_vfs)
5560 if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
5561 dev_info(&pf->pdev->dev,
5562 "got num_vsis %d, setting num_vsis to %d\n",
5563 pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
5564 pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
5565 }
5566
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005567 return 0;
5568}
5569
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005570static int i40e_vsi_clear(struct i40e_vsi *vsi);
5571
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005572/**
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005573 * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005574 * @pf: board private structure
5575 **/
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005576static void i40e_fdir_sb_setup(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005577{
5578 struct i40e_vsi *vsi;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005579 int i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005580
Jesse Brandeburg407e0632014-06-03 23:50:12 +00005581 /* quick workaround for an NVM issue that leaves a critical register
5582 * uninitialized
5583 */
5584 if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
5585 static const u32 hkey[] = {
5586 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
5587 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
5588 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
5589 0x95b3a76d};
5590
5591 for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
5592 wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
5593 }
5594
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005595 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005596 return;
5597
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005598 /* find existing VSI and see if it needs configuring */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005599 vsi = NULL;
Mitch Williams505682c2014-05-20 08:01:37 +00005600 for (i = 0; i < pf->num_alloc_vsi; i++) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005601 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005602 vsi = pf->vsi[i];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005603 break;
5604 }
5605 }
5606
5607 /* create a new VSI if none exists */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005608 if (!vsi) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005609 vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
5610 pf->vsi[pf->lan_vsi]->seid, 0);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005611 if (!vsi) {
5612 dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005613 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
5614 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005615 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005616 }
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00005617
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08005618 i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005619}
5620
5621/**
5622 * i40e_fdir_teardown - release the Flow Director resources
5623 * @pf: board private structure
5624 **/
5625static void i40e_fdir_teardown(struct i40e_pf *pf)
5626{
5627 int i;
5628
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00005629 i40e_fdir_filter_exit(pf);
Mitch Williams505682c2014-05-20 08:01:37 +00005630 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005631 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
5632 i40e_vsi_release(pf->vsi[i]);
5633 break;
5634 }
5635 }
5636}
5637
5638/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005639 * i40e_prep_for_reset - prep for the core to reset
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005640 * @pf: board private structure
5641 *
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005642 * Close up the VFs and other things in prep for pf Reset.
5643 **/
Shannon Nelson23cfbe02014-06-04 01:23:14 +00005644static void i40e_prep_for_reset(struct i40e_pf *pf)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005645{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005646 struct i40e_hw *hw = &pf->hw;
Shannon Nelson60442de2014-04-23 04:50:13 +00005647 i40e_status ret = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005648 u32 v;
5649
5650 clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
5651 if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
Shannon Nelson23cfbe02014-06-04 01:23:14 +00005652 return;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005653
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005654 dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005655
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005656 /* quiesce the VSIs and their queues that are not already DOWN */
5657 i40e_pf_quiesce_all_vsi(pf);
5658
Mitch Williams505682c2014-05-20 08:01:37 +00005659 for (v = 0; v < pf->num_alloc_vsi; v++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005660 if (pf->vsi[v])
5661 pf->vsi[v]->seid = 0;
5662 }
5663
5664 i40e_shutdown_adminq(&pf->hw);
5665
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005666 /* call shutdown HMC */
Shannon Nelson60442de2014-04-23 04:50:13 +00005667 if (hw->hmc.hmc_obj) {
5668 ret = i40e_shutdown_lan_hmc(hw);
Shannon Nelson23cfbe02014-06-04 01:23:14 +00005669 if (ret)
Shannon Nelson60442de2014-04-23 04:50:13 +00005670 dev_warn(&pf->pdev->dev,
5671 "shutdown_lan_hmc failed: %d\n", ret);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005672 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005673}
5674
5675/**
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00005676 * i40e_send_version - update firmware with driver version
5677 * @pf: PF struct
5678 */
5679static void i40e_send_version(struct i40e_pf *pf)
5680{
5681 struct i40e_driver_version dv;
5682
5683 dv.major_version = DRV_VERSION_MAJOR;
5684 dv.minor_version = DRV_VERSION_MINOR;
5685 dv.build_version = DRV_VERSION_BUILD;
5686 dv.subbuild_version = 0;
5687 strncpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
5688 i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
5689}
5690
5691/**
Jesse Brandeburg4dda12e2013-12-18 13:46:01 +00005692 * i40e_reset_and_rebuild - reset and rebuild using a saved config
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005693 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00005694 * @reinit: if the Main VSI needs to re-initialized.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005695 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00005696static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005697{
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005698 struct i40e_hw *hw = &pf->hw;
5699 i40e_status ret;
5700 u32 v;
5701
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005702 /* Now we wait for GRST to settle out.
5703 * We don't have to delete the VEBs or VSIs from the hw switch
5704 * because the reset will make them disappear.
5705 */
5706 ret = i40e_pf_reset(hw);
Akeem G Abodunrinb5565402014-04-09 05:59:04 +00005707 if (ret) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005708 dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
Akeem G Abodunrinb5565402014-04-09 05:59:04 +00005709 goto end_core_reset;
5710 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005711 pf->pfr_count++;
5712
5713 if (test_bit(__I40E_DOWN, &pf->state))
5714 goto end_core_reset;
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005715 dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005716
5717 /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
5718 ret = i40e_init_adminq(&pf->hw);
5719 if (ret) {
5720 dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, %d\n", ret);
5721 goto end_core_reset;
5722 }
5723
Shannon Nelson4eb3f762014-03-06 08:59:58 +00005724 /* re-verify the eeprom if we just had an EMP reset */
5725 if (test_bit(__I40E_EMP_RESET_REQUESTED, &pf->state)) {
5726 clear_bit(__I40E_EMP_RESET_REQUESTED, &pf->state);
5727 i40e_verify_eeprom(pf);
5728 }
5729
Shannon Nelsone78ac4bf2014-05-10 04:49:09 +00005730 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005731 ret = i40e_get_capabilities(pf);
5732 if (ret) {
5733 dev_info(&pf->pdev->dev, "i40e_get_capabilities failed, %d\n",
5734 ret);
5735 goto end_core_reset;
5736 }
5737
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005738 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
5739 hw->func_caps.num_rx_qp,
5740 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
5741 if (ret) {
5742 dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
5743 goto end_core_reset;
5744 }
5745 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
5746 if (ret) {
5747 dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
5748 goto end_core_reset;
5749 }
5750
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08005751#ifdef CONFIG_I40E_DCB
5752 ret = i40e_init_pf_dcb(pf);
5753 if (ret) {
5754 dev_info(&pf->pdev->dev, "init_pf_dcb failed: %d\n", ret);
5755 goto end_core_reset;
5756 }
5757#endif /* CONFIG_I40E_DCB */
5758
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005759 /* do basic switch setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00005760 ret = i40e_setup_pf_switch(pf, reinit);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005761 if (ret)
5762 goto end_core_reset;
5763
5764 /* Rebuild the VSIs and VEBs that existed before reset.
5765 * They are still in our local switch element arrays, so only
5766 * need to rebuild the switch model in the HW.
5767 *
5768 * If there were VEBs but the reconstitution failed, we'll try
5769 * try to recover minimal use by getting the basic PF VSI working.
5770 */
5771 if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00005772 dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005773 /* find the one VEB connected to the MAC, and find orphans */
5774 for (v = 0; v < I40E_MAX_VEB; v++) {
5775 if (!pf->veb[v])
5776 continue;
5777
5778 if (pf->veb[v]->uplink_seid == pf->mac_seid ||
5779 pf->veb[v]->uplink_seid == 0) {
5780 ret = i40e_reconstitute_veb(pf->veb[v]);
5781
5782 if (!ret)
5783 continue;
5784
5785 /* If Main VEB failed, we're in deep doodoo,
5786 * so give up rebuilding the switch and set up
5787 * for minimal rebuild of PF VSI.
5788 * If orphan failed, we'll report the error
5789 * but try to keep going.
5790 */
5791 if (pf->veb[v]->uplink_seid == pf->mac_seid) {
5792 dev_info(&pf->pdev->dev,
5793 "rebuild of switch failed: %d, will try to set up simple PF connection\n",
5794 ret);
5795 pf->vsi[pf->lan_vsi]->uplink_seid
5796 = pf->mac_seid;
5797 break;
5798 } else if (pf->veb[v]->uplink_seid == 0) {
5799 dev_info(&pf->pdev->dev,
5800 "rebuild of orphan VEB failed: %d\n",
5801 ret);
5802 }
5803 }
5804 }
5805 }
5806
5807 if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
Shannon Nelsoncde4cbc2014-06-04 01:23:17 +00005808 dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005809 /* no VEB, so rebuild only the Main VSI */
5810 ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
5811 if (ret) {
5812 dev_info(&pf->pdev->dev,
5813 "rebuild of Main VSI failed: %d\n", ret);
5814 goto end_core_reset;
5815 }
5816 }
5817
5818 /* reinit the misc interrupt */
5819 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
5820 ret = i40e_setup_misc_vector(pf);
5821
5822 /* restart the VSIs that were rebuilt and running before the reset */
5823 i40e_pf_unquiesce_all_vsi(pf);
5824
Mitch Williams69f64b22014-02-13 03:48:46 -08005825 if (pf->num_alloc_vfs) {
5826 for (v = 0; v < pf->num_alloc_vfs; v++)
5827 i40e_reset_vf(&pf->vf[v], true);
5828 }
5829
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005830 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00005831 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005832
5833end_core_reset:
5834 clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
5835}
5836
5837/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005838 * i40e_handle_reset_warning - prep for the pf to reset, reset and rebuild
5839 * @pf: board private structure
5840 *
5841 * Close up the VFs and other things in prep for a Core Reset,
5842 * then get ready to rebuild the world.
5843 **/
5844static void i40e_handle_reset_warning(struct i40e_pf *pf)
5845{
Shannon Nelson23cfbe02014-06-04 01:23:14 +00005846 i40e_prep_for_reset(pf);
5847 i40e_reset_and_rebuild(pf, false);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00005848}
5849
5850/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005851 * i40e_handle_mdd_event
5852 * @pf: pointer to the pf structure
5853 *
5854 * Called from the MDD irq handler to identify possibly malicious vfs
5855 **/
5856static void i40e_handle_mdd_event(struct i40e_pf *pf)
5857{
5858 struct i40e_hw *hw = &pf->hw;
5859 bool mdd_detected = false;
Neerav Parikhdf430b12014-06-04 01:23:15 +00005860 bool pf_mdd_detected = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005861 struct i40e_vf *vf;
5862 u32 reg;
5863 int i;
5864
5865 if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
5866 return;
5867
5868 /* find what triggered the MDD event */
5869 reg = rd32(hw, I40E_GL_MDET_TX);
5870 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00005871 u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
5872 I40E_GL_MDET_TX_PF_NUM_SHIFT;
5873 u8 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
5874 I40E_GL_MDET_TX_VF_NUM_SHIFT;
5875 u8 event = (reg & I40E_GL_MDET_TX_EVENT_SHIFT) >>
5876 I40E_GL_MDET_TX_EVENT_SHIFT;
5877 u8 queue = (reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
5878 I40E_GL_MDET_TX_QUEUE_SHIFT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005879 dev_info(&pf->pdev->dev,
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00005880 "Malicious Driver Detection event 0x%02x on TX queue %d pf number 0x%02x vf number 0x%02x\n",
5881 event, queue, pf_num, vf_num);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005882 wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
5883 mdd_detected = true;
5884 }
5885 reg = rd32(hw, I40E_GL_MDET_RX);
5886 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
Anjali Singhai Jain4c33f832014-06-05 00:18:21 +00005887 u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
5888 I40E_GL_MDET_RX_FUNCTION_SHIFT;
5889 u8 event = (reg & I40E_GL_MDET_RX_EVENT_SHIFT) >>
5890 I40E_GL_MDET_RX_EVENT_SHIFT;
5891 u8 queue = (reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
5892 I40E_GL_MDET_RX_QUEUE_SHIFT;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005893 dev_info(&pf->pdev->dev,
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00005894 "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005895 event, queue, func);
5896 wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
5897 mdd_detected = true;
5898 }
5899
Neerav Parikhdf430b12014-06-04 01:23:15 +00005900 if (mdd_detected) {
5901 reg = rd32(hw, I40E_PF_MDET_TX);
5902 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
5903 wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
5904 dev_info(&pf->pdev->dev,
5905 "MDD TX event is for this function 0x%08x, requesting PF reset.\n",
5906 reg);
5907 pf_mdd_detected = true;
5908 }
5909 reg = rd32(hw, I40E_PF_MDET_RX);
5910 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
5911 wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
5912 dev_info(&pf->pdev->dev,
5913 "MDD RX event is for this function 0x%08x, requesting PF reset.\n",
5914 reg);
5915 pf_mdd_detected = true;
5916 }
5917 /* Queue belongs to the PF, initiate a reset */
5918 if (pf_mdd_detected) {
5919 set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
5920 i40e_service_event_schedule(pf);
5921 }
5922 }
5923
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00005924 /* see if one of the VFs needs its hand slapped */
5925 for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
5926 vf = &(pf->vf[i]);
5927 reg = rd32(hw, I40E_VP_MDET_TX(i));
5928 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
5929 wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
5930 vf->num_mdd_events++;
5931 dev_info(&pf->pdev->dev, "MDD TX event on VF %d\n", i);
5932 }
5933
5934 reg = rd32(hw, I40E_VP_MDET_RX(i));
5935 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
5936 wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
5937 vf->num_mdd_events++;
5938 dev_info(&pf->pdev->dev, "MDD RX event on VF %d\n", i);
5939 }
5940
5941 if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
5942 dev_info(&pf->pdev->dev,
5943 "Too many MDD events on VF %d, disabled\n", i);
5944 dev_info(&pf->pdev->dev,
5945 "Use PF Control I/F to re-enable the VF\n");
5946 set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
5947 }
5948 }
5949
5950 /* re-enable mdd interrupt cause */
5951 clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
5952 reg = rd32(hw, I40E_PFINT_ICR0_ENA);
5953 reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
5954 wr32(hw, I40E_PFINT_ICR0_ENA, reg);
5955 i40e_flush(hw);
5956}
5957
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00005958#ifdef CONFIG_I40E_VXLAN
5959/**
5960 * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW
5961 * @pf: board private structure
5962 **/
5963static void i40e_sync_vxlan_filters_subtask(struct i40e_pf *pf)
5964{
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00005965 struct i40e_hw *hw = &pf->hw;
5966 i40e_status ret;
5967 u8 filter_index;
5968 __be16 port;
5969 int i;
5970
5971 if (!(pf->flags & I40E_FLAG_VXLAN_FILTER_SYNC))
5972 return;
5973
5974 pf->flags &= ~I40E_FLAG_VXLAN_FILTER_SYNC;
5975
5976 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
5977 if (pf->pending_vxlan_bitmap & (1 << i)) {
5978 pf->pending_vxlan_bitmap &= ~(1 << i);
5979 port = pf->vxlan_ports[i];
5980 ret = port ?
5981 i40e_aq_add_udp_tunnel(hw, ntohs(port),
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00005982 I40E_AQC_TUNNEL_TYPE_VXLAN,
5983 &filter_index, NULL)
5984 : i40e_aq_del_udp_tunnel(hw, i, NULL);
5985
5986 if (ret) {
5987 dev_info(&pf->pdev->dev, "Failed to execute AQ command for %s port %d with index %d\n",
5988 port ? "adding" : "deleting",
5989 ntohs(port), port ? i : i);
5990
5991 pf->vxlan_ports[i] = 0;
5992 } else {
5993 dev_info(&pf->pdev->dev, "%s port %d with AQ command with index %d\n",
5994 port ? "Added" : "Deleted",
5995 ntohs(port), port ? i : filter_index);
5996 }
5997 }
5998 }
5999}
6000
6001#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006002/**
6003 * i40e_service_task - Run the driver's async subtasks
6004 * @work: pointer to work_struct containing our data
6005 **/
6006static void i40e_service_task(struct work_struct *work)
6007{
6008 struct i40e_pf *pf = container_of(work,
6009 struct i40e_pf,
6010 service_task);
6011 unsigned long start_time = jiffies;
6012
Shannon Nelsone57a2fe2014-06-03 23:50:19 +00006013 /* don't bother with service tasks if a reset is in progress */
6014 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
6015 i40e_service_event_complete(pf);
6016 return;
6017 }
6018
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006019 i40e_reset_subtask(pf);
6020 i40e_handle_mdd_event(pf);
6021 i40e_vc_process_vflr_event(pf);
6022 i40e_watchdog_subtask(pf);
6023 i40e_fdir_reinit_subtask(pf);
6024 i40e_check_hang_subtask(pf);
6025 i40e_sync_filters_subtask(pf);
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00006026#ifdef CONFIG_I40E_VXLAN
6027 i40e_sync_vxlan_filters_subtask(pf);
6028#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006029 i40e_clean_adminq_subtask(pf);
6030
6031 i40e_service_event_complete(pf);
6032
6033 /* If the tasks have taken longer than one timer cycle or there
6034 * is more work to be done, reschedule the service task now
6035 * rather than wait for the timer to tick again.
6036 */
6037 if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
6038 test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
6039 test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
6040 test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
6041 i40e_service_event_schedule(pf);
6042}
6043
6044/**
6045 * i40e_service_timer - timer callback
6046 * @data: pointer to PF struct
6047 **/
6048static void i40e_service_timer(unsigned long data)
6049{
6050 struct i40e_pf *pf = (struct i40e_pf *)data;
6051
6052 mod_timer(&pf->service_timer,
6053 round_jiffies(jiffies + pf->service_timer_period));
6054 i40e_service_event_schedule(pf);
6055}
6056
6057/**
6058 * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
6059 * @vsi: the VSI being configured
6060 **/
6061static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
6062{
6063 struct i40e_pf *pf = vsi->back;
6064
6065 switch (vsi->type) {
6066 case I40E_VSI_MAIN:
6067 vsi->alloc_queue_pairs = pf->num_lan_qps;
6068 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
6069 I40E_REQ_DESCRIPTOR_MULTIPLE);
6070 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
6071 vsi->num_q_vectors = pf->num_lan_msix;
6072 else
6073 vsi->num_q_vectors = 1;
6074
6075 break;
6076
6077 case I40E_VSI_FDIR:
6078 vsi->alloc_queue_pairs = 1;
6079 vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
6080 I40E_REQ_DESCRIPTOR_MULTIPLE);
6081 vsi->num_q_vectors = 1;
6082 break;
6083
6084 case I40E_VSI_VMDQ2:
6085 vsi->alloc_queue_pairs = pf->num_vmdq_qps;
6086 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
6087 I40E_REQ_DESCRIPTOR_MULTIPLE);
6088 vsi->num_q_vectors = pf->num_vmdq_msix;
6089 break;
6090
6091 case I40E_VSI_SRIOV:
6092 vsi->alloc_queue_pairs = pf->num_vf_qps;
6093 vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
6094 I40E_REQ_DESCRIPTOR_MULTIPLE);
6095 break;
6096
6097 default:
6098 WARN_ON(1);
6099 return -ENODATA;
6100 }
6101
6102 return 0;
6103}
6104
6105/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006106 * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
6107 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006108 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006109 *
6110 * On error: returns error code (negative)
6111 * On success: returns 0
6112 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006113static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006114{
6115 int size;
6116 int ret = 0;
6117
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00006118 /* allocate memory for both Tx and Rx ring pointers */
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006119 size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
6120 vsi->tx_rings = kzalloc(size, GFP_KERNEL);
6121 if (!vsi->tx_rings)
6122 return -ENOMEM;
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006123 vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
6124
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006125 if (alloc_qvectors) {
6126 /* allocate memory for q_vector pointers */
6127 size = sizeof(struct i40e_q_vectors *) * vsi->num_q_vectors;
6128 vsi->q_vectors = kzalloc(size, GFP_KERNEL);
6129 if (!vsi->q_vectors) {
6130 ret = -ENOMEM;
6131 goto err_vectors;
6132 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006133 }
6134 return ret;
6135
6136err_vectors:
6137 kfree(vsi->tx_rings);
6138 return ret;
6139}
6140
6141/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006142 * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
6143 * @pf: board private structure
6144 * @type: type of VSI
6145 *
6146 * On error: returns error code (negative)
6147 * On success: returns vsi index in PF (positive)
6148 **/
6149static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
6150{
6151 int ret = -ENODEV;
6152 struct i40e_vsi *vsi;
6153 int vsi_idx;
6154 int i;
6155
6156 /* Need to protect the allocation of the VSIs at the PF level */
6157 mutex_lock(&pf->switch_mutex);
6158
6159 /* VSI list may be fragmented if VSI creation/destruction has
6160 * been happening. We can afford to do a quick scan to look
6161 * for any free VSIs in the list.
6162 *
6163 * find next empty vsi slot, looping back around if necessary
6164 */
6165 i = pf->next_vsi;
Mitch Williams505682c2014-05-20 08:01:37 +00006166 while (i < pf->num_alloc_vsi && pf->vsi[i])
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006167 i++;
Mitch Williams505682c2014-05-20 08:01:37 +00006168 if (i >= pf->num_alloc_vsi) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006169 i = 0;
6170 while (i < pf->next_vsi && pf->vsi[i])
6171 i++;
6172 }
6173
Mitch Williams505682c2014-05-20 08:01:37 +00006174 if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006175 vsi_idx = i; /* Found one! */
6176 } else {
6177 ret = -ENODEV;
Alexander Duyck493fb302013-09-28 07:01:44 +00006178 goto unlock_pf; /* out of VSI slots! */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006179 }
6180 pf->next_vsi = ++i;
6181
6182 vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
6183 if (!vsi) {
6184 ret = -ENOMEM;
Alexander Duyck493fb302013-09-28 07:01:44 +00006185 goto unlock_pf;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006186 }
6187 vsi->type = type;
6188 vsi->back = pf;
6189 set_bit(__I40E_DOWN, &vsi->state);
6190 vsi->flags = 0;
6191 vsi->idx = vsi_idx;
6192 vsi->rx_itr_setting = pf->rx_itr_default;
6193 vsi->tx_itr_setting = pf->tx_itr_default;
6194 vsi->netdev_registered = false;
6195 vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
6196 INIT_LIST_HEAD(&vsi->mac_filter_list);
Shannon Nelson63741842014-04-23 04:50:16 +00006197 vsi->irqs_ready = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006198
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006199 ret = i40e_set_num_rings_in_vsi(vsi);
6200 if (ret)
6201 goto err_rings;
6202
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006203 ret = i40e_vsi_alloc_arrays(vsi, true);
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006204 if (ret)
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006205 goto err_rings;
Alexander Duyck493fb302013-09-28 07:01:44 +00006206
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006207 /* Setup default MSIX irq handler for VSI */
6208 i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
6209
6210 pf->vsi[vsi_idx] = vsi;
6211 ret = vsi_idx;
Alexander Duyck493fb302013-09-28 07:01:44 +00006212 goto unlock_pf;
6213
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006214err_rings:
Alexander Duyck493fb302013-09-28 07:01:44 +00006215 pf->next_vsi = i - 1;
6216 kfree(vsi);
6217unlock_pf:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006218 mutex_unlock(&pf->switch_mutex);
6219 return ret;
6220}
6221
6222/**
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006223 * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
6224 * @type: VSI pointer
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006225 * @free_qvectors: a bool to specify if q_vectors need to be freed.
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006226 *
6227 * On error: returns error code (negative)
6228 * On success: returns 0
6229 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006230static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006231{
6232 /* free the ring and vector containers */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006233 if (free_qvectors) {
6234 kfree(vsi->q_vectors);
6235 vsi->q_vectors = NULL;
6236 }
Anjali Singhai Jainf650a382013-11-20 10:02:55 +00006237 kfree(vsi->tx_rings);
6238 vsi->tx_rings = NULL;
6239 vsi->rx_rings = NULL;
6240}
6241
6242/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006243 * i40e_vsi_clear - Deallocate the VSI provided
6244 * @vsi: the VSI being un-configured
6245 **/
6246static int i40e_vsi_clear(struct i40e_vsi *vsi)
6247{
6248 struct i40e_pf *pf;
6249
6250 if (!vsi)
6251 return 0;
6252
6253 if (!vsi->back)
6254 goto free_vsi;
6255 pf = vsi->back;
6256
6257 mutex_lock(&pf->switch_mutex);
6258 if (!pf->vsi[vsi->idx]) {
6259 dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
6260 vsi->idx, vsi->idx, vsi, vsi->type);
6261 goto unlock_vsi;
6262 }
6263
6264 if (pf->vsi[vsi->idx] != vsi) {
6265 dev_err(&pf->pdev->dev,
6266 "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
6267 pf->vsi[vsi->idx]->idx,
6268 pf->vsi[vsi->idx],
6269 pf->vsi[vsi->idx]->type,
6270 vsi->idx, vsi, vsi->type);
6271 goto unlock_vsi;
6272 }
6273
6274 /* updates the pf for this cleared vsi */
6275 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
6276 i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
6277
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00006278 i40e_vsi_free_arrays(vsi, true);
Alexander Duyck493fb302013-09-28 07:01:44 +00006279
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006280 pf->vsi[vsi->idx] = NULL;
6281 if (vsi->idx < pf->next_vsi)
6282 pf->next_vsi = vsi->idx;
6283
6284unlock_vsi:
6285 mutex_unlock(&pf->switch_mutex);
6286free_vsi:
6287 kfree(vsi);
6288
6289 return 0;
6290}
6291
6292/**
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006293 * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
6294 * @vsi: the VSI being cleaned
6295 **/
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00006296static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006297{
6298 int i;
6299
Greg Rose8e9dca52013-12-18 13:45:53 +00006300 if (vsi->tx_rings && vsi->tx_rings[0]) {
Neerav Parikhd7397642013-11-28 06:39:37 +00006301 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Mitch Williams00403f02013-09-28 07:13:13 +00006302 kfree_rcu(vsi->tx_rings[i], rcu);
6303 vsi->tx_rings[i] = NULL;
6304 vsi->rx_rings[i] = NULL;
6305 }
Shannon Nelsonbe1d5ee2013-11-28 06:39:23 +00006306 }
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006307}
6308
6309/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006310 * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
6311 * @vsi: the VSI being configured
6312 **/
6313static int i40e_alloc_rings(struct i40e_vsi *vsi)
6314{
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00006315 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006316 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006317 int i;
6318
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006319 /* Set basic values in the rings to be used later during open() */
Neerav Parikhd7397642013-11-28 06:39:37 +00006320 for (i = 0; i < vsi->alloc_queue_pairs; i++) {
Shannon Nelsonac6c5e32013-11-20 10:02:57 +00006321 /* allocate space for both Tx and Rx in one shot */
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006322 tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
6323 if (!tx_ring)
6324 goto err_out;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006325
6326 tx_ring->queue_index = i;
6327 tx_ring->reg_idx = vsi->base_queue + i;
6328 tx_ring->ring_active = false;
6329 tx_ring->vsi = vsi;
6330 tx_ring->netdev = vsi->netdev;
6331 tx_ring->dev = &pf->pdev->dev;
6332 tx_ring->count = vsi->num_desc;
6333 tx_ring->size = 0;
6334 tx_ring->dcb_tc = 0;
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006335 vsi->tx_rings[i] = tx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006336
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006337 rx_ring = &tx_ring[1];
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006338 rx_ring->queue_index = i;
6339 rx_ring->reg_idx = vsi->base_queue + i;
6340 rx_ring->ring_active = false;
6341 rx_ring->vsi = vsi;
6342 rx_ring->netdev = vsi->netdev;
6343 rx_ring->dev = &pf->pdev->dev;
6344 rx_ring->count = vsi->num_desc;
6345 rx_ring->size = 0;
6346 rx_ring->dcb_tc = 0;
6347 if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED)
6348 set_ring_16byte_desc_enabled(rx_ring);
6349 else
6350 clear_ring_16byte_desc_enabled(rx_ring);
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006351 vsi->rx_rings[i] = rx_ring;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006352 }
6353
6354 return 0;
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00006355
6356err_out:
6357 i40e_vsi_clear_rings(vsi);
6358 return -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006359}
6360
6361/**
6362 * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
6363 * @pf: board private structure
6364 * @vectors: the number of MSI-X vectors to request
6365 *
6366 * Returns the number of vectors reserved, or error
6367 **/
6368static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
6369{
Alexander Gordeev7b37f372014-02-18 11:11:42 +01006370 vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
6371 I40E_MIN_MSIX, vectors);
6372 if (vectors < 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006373 dev_info(&pf->pdev->dev,
Alexander Gordeev7b37f372014-02-18 11:11:42 +01006374 "MSI-X vector reservation failed: %d\n", vectors);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006375 vectors = 0;
6376 }
6377
6378 return vectors;
6379}
6380
6381/**
6382 * i40e_init_msix - Setup the MSIX capability
6383 * @pf: board private structure
6384 *
6385 * Work with the OS to set up the MSIX vectors needed.
6386 *
6387 * Returns 0 on success, negative on failure
6388 **/
6389static int i40e_init_msix(struct i40e_pf *pf)
6390{
6391 i40e_status err = 0;
6392 struct i40e_hw *hw = &pf->hw;
6393 int v_budget, i;
6394 int vec;
6395
6396 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
6397 return -ENODEV;
6398
6399 /* The number of vectors we'll request will be comprised of:
6400 * - Add 1 for "other" cause for Admin Queue events, etc.
6401 * - The number of LAN queue pairs
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00006402 * - Queues being used for RSS.
6403 * We don't need as many as max_rss_size vectors.
6404 * use rss_size instead in the calculation since that
6405 * is governed by number of cpus in the system.
6406 * - assumes symmetric Tx/Rx pairing
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006407 * - The number of VMDq pairs
6408 * Once we count this up, try the request.
6409 *
6410 * If we can't get what we want, we'll simplify to nearly nothing
6411 * and try again. If that still fails, we punt.
6412 */
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00006413 pf->num_lan_msix = pf->num_lan_qps - (pf->rss_size_max - pf->rss_size);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006414 pf->num_vmdq_msix = pf->num_vmdq_qps;
6415 v_budget = 1 + pf->num_lan_msix;
6416 v_budget += (pf->num_vmdq_vsis * pf->num_vmdq_msix);
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08006417 if (pf->flags & I40E_FLAG_FD_SB_ENABLED)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006418 v_budget++;
6419
6420 /* Scale down if necessary, and the rings will share vectors */
6421 v_budget = min_t(int, v_budget, hw->func_caps.num_msix_vectors);
6422
6423 pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
6424 GFP_KERNEL);
6425 if (!pf->msix_entries)
6426 return -ENOMEM;
6427
6428 for (i = 0; i < v_budget; i++)
6429 pf->msix_entries[i].entry = i;
6430 vec = i40e_reserve_msix_vectors(pf, v_budget);
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00006431
6432 if (vec != v_budget) {
6433 /* If we have limited resources, we will start with no vectors
6434 * for the special features and then allocate vectors to some
6435 * of these features based on the policy and at the end disable
6436 * the features that did not get any vectors.
6437 */
6438 pf->num_vmdq_msix = 0;
6439 }
6440
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006441 if (vec < I40E_MIN_MSIX) {
6442 pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
6443 kfree(pf->msix_entries);
6444 pf->msix_entries = NULL;
6445 return -ENODEV;
6446
6447 } else if (vec == I40E_MIN_MSIX) {
6448 /* Adjust for minimal MSIX use */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006449 pf->num_vmdq_vsis = 0;
6450 pf->num_vmdq_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006451 pf->num_lan_qps = 1;
6452 pf->num_lan_msix = 1;
6453
6454 } else if (vec != v_budget) {
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00006455 /* reserve the misc vector */
6456 vec--;
6457
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006458 /* Scale vector usage down */
6459 pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00006460 pf->num_vmdq_vsis = 1;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006461
6462 /* partition out the remaining vectors */
6463 switch (vec) {
6464 case 2:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006465 pf->num_lan_msix = 1;
6466 break;
6467 case 3:
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006468 pf->num_lan_msix = 2;
6469 break;
6470 default:
6471 pf->num_lan_msix = min_t(int, (vec / 2),
6472 pf->num_lan_qps);
6473 pf->num_vmdq_vsis = min_t(int, (vec - pf->num_lan_msix),
6474 I40E_DEFAULT_NUM_VMDQ_VSI);
6475 break;
6476 }
6477 }
6478
Anjali Singhai Jaina34977b2014-05-21 23:32:43 +00006479 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
6480 (pf->num_vmdq_msix == 0)) {
6481 dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
6482 pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
6483 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006484 return err;
6485}
6486
6487/**
Greg Rose90e04072014-03-06 08:59:57 +00006488 * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
Alexander Duyck493fb302013-09-28 07:01:44 +00006489 * @vsi: the VSI being configured
6490 * @v_idx: index of the vector in the vsi struct
6491 *
6492 * We allocate one q_vector. If allocation fails we return -ENOMEM.
6493 **/
Greg Rose90e04072014-03-06 08:59:57 +00006494static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx)
Alexander Duyck493fb302013-09-28 07:01:44 +00006495{
6496 struct i40e_q_vector *q_vector;
6497
6498 /* allocate q_vector */
6499 q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
6500 if (!q_vector)
6501 return -ENOMEM;
6502
6503 q_vector->vsi = vsi;
6504 q_vector->v_idx = v_idx;
6505 cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
6506 if (vsi->netdev)
6507 netif_napi_add(vsi->netdev, &q_vector->napi,
Jesse Brandeburgeefeace2014-05-10 04:49:13 +00006508 i40e_napi_poll, NAPI_POLL_WEIGHT);
Alexander Duyck493fb302013-09-28 07:01:44 +00006509
Alexander Duyckcd0b6fa2013-09-28 06:00:53 +00006510 q_vector->rx.latency_range = I40E_LOW_LATENCY;
6511 q_vector->tx.latency_range = I40E_LOW_LATENCY;
6512
Alexander Duyck493fb302013-09-28 07:01:44 +00006513 /* tie q_vector and vsi together */
6514 vsi->q_vectors[v_idx] = q_vector;
6515
6516 return 0;
6517}
6518
6519/**
Greg Rose90e04072014-03-06 08:59:57 +00006520 * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006521 * @vsi: the VSI being configured
6522 *
6523 * We allocate one q_vector per queue interrupt. If allocation fails we
6524 * return -ENOMEM.
6525 **/
Greg Rose90e04072014-03-06 08:59:57 +00006526static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006527{
6528 struct i40e_pf *pf = vsi->back;
6529 int v_idx, num_q_vectors;
Alexander Duyck493fb302013-09-28 07:01:44 +00006530 int err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006531
6532 /* if not MSIX, give the one vector only to the LAN VSI */
6533 if (pf->flags & I40E_FLAG_MSIX_ENABLED)
6534 num_q_vectors = vsi->num_q_vectors;
6535 else if (vsi == pf->vsi[pf->lan_vsi])
6536 num_q_vectors = 1;
6537 else
6538 return -EINVAL;
6539
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006540 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
Greg Rose90e04072014-03-06 08:59:57 +00006541 err = i40e_vsi_alloc_q_vector(vsi, v_idx);
Alexander Duyck493fb302013-09-28 07:01:44 +00006542 if (err)
6543 goto err_out;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006544 }
6545
6546 return 0;
Alexander Duyck493fb302013-09-28 07:01:44 +00006547
6548err_out:
6549 while (v_idx--)
6550 i40e_free_q_vector(vsi, v_idx);
6551
6552 return err;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006553}
6554
6555/**
6556 * i40e_init_interrupt_scheme - Determine proper interrupt scheme
6557 * @pf: board private structure to initialize
6558 **/
6559static void i40e_init_interrupt_scheme(struct i40e_pf *pf)
6560{
6561 int err = 0;
6562
6563 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
6564 err = i40e_init_msix(pf);
6565 if (err) {
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08006566 pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
6567 I40E_FLAG_RSS_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00006568 I40E_FLAG_DCB_CAPABLE |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08006569 I40E_FLAG_SRIOV_ENABLED |
6570 I40E_FLAG_FD_SB_ENABLED |
6571 I40E_FLAG_FD_ATR_ENABLED |
6572 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006573
6574 /* rework the queue expectations without MSIX */
6575 i40e_determine_queue_usage(pf);
6576 }
6577 }
6578
6579 if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
6580 (pf->flags & I40E_FLAG_MSI_ENABLED)) {
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08006581 dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006582 err = pci_enable_msi(pf->pdev);
6583 if (err) {
Shannon Nelson958a3e32013-09-28 07:13:28 +00006584 dev_info(&pf->pdev->dev, "MSI init failed - %d\n", err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006585 pf->flags &= ~I40E_FLAG_MSI_ENABLED;
6586 }
6587 }
6588
Shannon Nelson958a3e32013-09-28 07:13:28 +00006589 if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08006590 dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
Shannon Nelson958a3e32013-09-28 07:13:28 +00006591
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006592 /* track first vector for misc interrupts */
6593 err = i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT-1);
6594}
6595
6596/**
6597 * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
6598 * @pf: board private structure
6599 *
6600 * This sets up the handler for MSIX 0, which is used to manage the
6601 * non-queue interrupts, e.g. AdminQ and errors. This is not used
6602 * when in MSI or Legacy interrupt mode.
6603 **/
6604static int i40e_setup_misc_vector(struct i40e_pf *pf)
6605{
6606 struct i40e_hw *hw = &pf->hw;
6607 int err = 0;
6608
6609 /* Only request the irq if this is the first time through, and
6610 * not when we're rebuilding after a Reset
6611 */
6612 if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
6613 err = request_irq(pf->msix_entries[0].vector,
6614 i40e_intr, 0, pf->misc_int_name, pf);
6615 if (err) {
6616 dev_info(&pf->pdev->dev,
Catherine Sullivan77fa28b2014-02-20 19:29:17 -08006617 "request_irq for %s failed: %d\n",
6618 pf->misc_int_name, err);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006619 return -EFAULT;
6620 }
6621 }
6622
6623 i40e_enable_misc_int_causes(hw);
6624
6625 /* associate no queues to the misc vector */
6626 wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
6627 wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
6628
6629 i40e_flush(hw);
6630
6631 i40e_irq_dynamic_enable_icr0(pf);
6632
6633 return err;
6634}
6635
6636/**
6637 * i40e_config_rss - Prepare for RSS if used
6638 * @pf: board private structure
6639 **/
6640static int i40e_config_rss(struct i40e_pf *pf)
6641{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006642 /* Set of random keys generated using kernel random number generator */
6643 static const u32 seed[I40E_PFQF_HKEY_MAX_INDEX + 1] = {0x41b01687,
6644 0x183cfd8c, 0xce880440, 0x580cbc3c, 0x35897377,
6645 0x328b25e1, 0x4fa98922, 0xb7d90c14, 0xd5bad70d,
6646 0xcd15a2c1, 0xe8580225, 0x4a1e9d11, 0xfe5731be};
Anjali Singhai Jain4617e8c2013-11-20 10:02:56 +00006647 struct i40e_hw *hw = &pf->hw;
6648 u32 lut = 0;
6649 int i, j;
6650 u64 hena;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00006651 u32 reg_val;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006652
6653 /* Fill out hash function seed */
6654 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
6655 wr32(hw, I40E_PFQF_HKEY(i), seed[i]);
6656
6657 /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
6658 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
6659 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
Mitch Williams12dc4fe2013-11-28 06:39:32 +00006660 hena |= I40E_DEFAULT_RSS_HENA;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006661 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
6662 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
6663
Carolyn Wybornye157ea32014-06-03 23:50:22 +00006664 /* Check capability and Set table size and register per hw expectation*/
6665 reg_val = rd32(hw, I40E_PFQF_CTL_0);
6666 if (hw->func_caps.rss_table_size == 512) {
6667 reg_val |= I40E_PFQF_CTL_0_HASHLUTSIZE_512;
6668 pf->rss_table_size = 512;
6669 } else {
6670 pf->rss_table_size = 128;
6671 reg_val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_512;
6672 }
6673 wr32(hw, I40E_PFQF_CTL_0, reg_val);
6674
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006675 /* Populate the LUT with max no. of queues in round robin fashion */
Carolyn Wybornye157ea32014-06-03 23:50:22 +00006676 for (i = 0, j = 0; i < pf->rss_table_size; i++, j++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006677
6678 /* The assumption is that lan qp count will be the highest
6679 * qp count for any PF VSI that needs RSS.
6680 * If multiple VSIs need RSS support, all the qp counts
6681 * for those VSIs should be a power of 2 for RSS to work.
6682 * If LAN VSI is the only consumer for RSS then this requirement
6683 * is not necessary.
6684 */
6685 if (j == pf->rss_size)
6686 j = 0;
6687 /* lut = 4-byte sliding window of 4 lut entries */
6688 lut = (lut << 8) | (j &
6689 ((0x1 << pf->hw.func_caps.rss_table_entry_width) - 1));
6690 /* On i = 3, we have 4 entries in lut; write to the register */
6691 if ((i & 3) == 3)
6692 wr32(hw, I40E_PFQF_HLUT(i >> 2), lut);
6693 }
6694 i40e_flush(hw);
6695
6696 return 0;
6697}
6698
6699/**
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00006700 * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
6701 * @pf: board private structure
6702 * @queue_count: the requested queue count for rss.
6703 *
6704 * returns 0 if rss is not enabled, if enabled returns the final rss queue
6705 * count which may be different from the requested queue count.
6706 **/
6707int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
6708{
6709 if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
6710 return 0;
6711
6712 queue_count = min_t(int, queue_count, pf->rss_size_max);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00006713
6714 if (queue_count != pf->rss_size) {
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00006715 i40e_prep_for_reset(pf);
6716
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00006717 pf->rss_size = queue_count;
6718
6719 i40e_reset_and_rebuild(pf, true);
6720 i40e_config_rss(pf);
6721 }
6722 dev_info(&pf->pdev->dev, "RSS count: %d\n", pf->rss_size);
6723 return pf->rss_size;
6724}
6725
6726/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006727 * i40e_sw_init - Initialize general software structures (struct i40e_pf)
6728 * @pf: board private structure to initialize
6729 *
6730 * i40e_sw_init initializes the Adapter private data structure.
6731 * Fields are initialized based on PCI device information and
6732 * OS network device settings (MTU size).
6733 **/
6734static int i40e_sw_init(struct i40e_pf *pf)
6735{
6736 int err = 0;
6737 int size;
6738
6739 pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE,
6740 (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK));
Shannon Nelson27599972013-11-16 10:00:43 +00006741 pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006742 if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) {
6743 if (I40E_DEBUG_USER & debug)
6744 pf->hw.debug_mask = debug;
6745 pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER),
6746 I40E_DEFAULT_MSG_ENABLE);
6747 }
6748
6749 /* Set default capability flags */
6750 pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
6751 I40E_FLAG_MSI_ENABLED |
6752 I40E_FLAG_MSIX_ENABLED |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006753 I40E_FLAG_RX_1BUF_ENABLED;
6754
Mitch Williamsca99eb92014-04-04 04:43:07 +00006755 /* Set default ITR */
6756 pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
6757 pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
6758
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00006759 /* Depending on PF configurations, it is possible that the RSS
6760 * maximum might end up larger than the available queues
6761 */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006762 pf->rss_size_max = 0x1 << pf->hw.func_caps.rss_table_entry_width;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00006763 pf->rss_size_max = min_t(int, pf->rss_size_max,
6764 pf->hw.func_caps.num_tx_qp);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006765 if (pf->hw.func_caps.rss) {
6766 pf->flags |= I40E_FLAG_RSS_ENABLED;
Jesse Brandeburgbf051a32013-11-26 10:49:17 +00006767 pf->rss_size = min_t(int, pf->rss_size_max, num_online_cpus());
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006768 } else {
6769 pf->rss_size = 1;
6770 }
6771
Catherine Sullivan2050bc62013-12-18 13:46:03 +00006772 /* MFP mode enabled */
6773 if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.mfp_mode_1) {
6774 pf->flags |= I40E_FLAG_MFP_ENABLED;
6775 dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
6776 }
6777
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006778 /* FW/NVM is not yet fixed in this regard */
6779 if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
6780 (pf->hw.func_caps.fd_filters_best_effort > 0)) {
6781 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
6782 pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00006783 /* Setup a counter for fd_atr per pf */
6784 pf->fd_atr_cnt_idx = I40E_FD_ATR_STAT_IDX(pf->hw.pf_id);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006785 if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) {
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08006786 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00006787 /* Setup a counter for fd_sb per pf */
6788 pf->fd_sb_cnt_idx = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006789 } else {
6790 dev_info(&pf->pdev->dev,
Anjali Singhai Jain0b675842014-03-06 08:59:51 +00006791 "Flow Director Sideband mode Disabled in MFP mode\n");
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006792 }
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08006793 pf->fdir_pf_filter_count =
6794 pf->hw.func_caps.fd_filters_guaranteed;
6795 pf->hw.fdir_shared_filter_count =
6796 pf->hw.func_caps.fd_filters_best_effort;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006797 }
6798
6799 if (pf->hw.func_caps.vmdq) {
6800 pf->flags |= I40E_FLAG_VMDQ_ENABLED;
6801 pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
6802 pf->num_vmdq_qps = I40E_DEFAULT_QUEUES_PER_VMDQ;
6803 }
6804
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006805#ifdef CONFIG_PCI_IOV
6806 if (pf->hw.func_caps.num_vfs) {
6807 pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
6808 pf->flags |= I40E_FLAG_SRIOV_ENABLED;
6809 pf->num_req_vfs = min_t(int,
6810 pf->hw.func_caps.num_vfs,
6811 I40E_MAX_VF_COUNT);
6812 }
6813#endif /* CONFIG_PCI_IOV */
6814 pf->eeprom_version = 0xDEAD;
6815 pf->lan_veb = I40E_NO_VEB;
6816 pf->lan_vsi = I40E_NO_VSI;
6817
6818 /* set up queue assignment tracking */
6819 size = sizeof(struct i40e_lump_tracking)
6820 + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
6821 pf->qp_pile = kzalloc(size, GFP_KERNEL);
6822 if (!pf->qp_pile) {
6823 err = -ENOMEM;
6824 goto sw_init_done;
6825 }
6826 pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
6827 pf->qp_pile->search_hint = 0;
6828
6829 /* set up vector assignment tracking */
6830 size = sizeof(struct i40e_lump_tracking)
6831 + (sizeof(u16) * pf->hw.func_caps.num_msix_vectors);
6832 pf->irq_pile = kzalloc(size, GFP_KERNEL);
6833 if (!pf->irq_pile) {
6834 kfree(pf->qp_pile);
6835 err = -ENOMEM;
6836 goto sw_init_done;
6837 }
6838 pf->irq_pile->num_entries = pf->hw.func_caps.num_msix_vectors;
6839 pf->irq_pile->search_hint = 0;
6840
Anjali Singhai Jain327fe042014-06-04 01:23:26 +00006841 pf->tx_timeout_recovery_level = 1;
6842
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006843 mutex_init(&pf->switch_mutex);
6844
6845sw_init_done:
6846 return err;
6847}
6848
6849/**
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00006850 * i40e_set_ntuple - set the ntuple feature flag and take action
6851 * @pf: board private structure to initialize
6852 * @features: the feature set that the stack is suggesting
6853 *
6854 * returns a bool to indicate if reset needs to happen
6855 **/
6856bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
6857{
6858 bool need_reset = false;
6859
6860 /* Check if Flow Director n-tuple support was enabled or disabled. If
6861 * the state changed, we need to reset.
6862 */
6863 if (features & NETIF_F_NTUPLE) {
6864 /* Enable filters and mark for reset */
6865 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
6866 need_reset = true;
6867 pf->flags |= I40E_FLAG_FD_SB_ENABLED;
6868 } else {
6869 /* turn off filters, mark for reset and clear SW filter list */
6870 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
6871 need_reset = true;
6872 i40e_fdir_filter_exit(pf);
6873 }
6874 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
6875 /* if ATR was disabled it can be re-enabled. */
6876 if (!(pf->flags & I40E_FLAG_FD_ATR_ENABLED))
6877 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
6878 }
6879 return need_reset;
6880}
6881
6882/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006883 * i40e_set_features - set the netdev feature flags
6884 * @netdev: ptr to the netdev being adjusted
6885 * @features: the feature set that the stack is suggesting
6886 **/
6887static int i40e_set_features(struct net_device *netdev,
6888 netdev_features_t features)
6889{
6890 struct i40e_netdev_priv *np = netdev_priv(netdev);
6891 struct i40e_vsi *vsi = np->vsi;
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00006892 struct i40e_pf *pf = vsi->back;
6893 bool need_reset;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006894
6895 if (features & NETIF_F_HW_VLAN_CTAG_RX)
6896 i40e_vlan_stripping_enable(vsi);
6897 else
6898 i40e_vlan_stripping_disable(vsi);
6899
Anjali Singhai Jain7c3c2882014-02-14 02:14:38 +00006900 need_reset = i40e_set_ntuple(pf, features);
6901
6902 if (need_reset)
6903 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
6904
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00006905 return 0;
6906}
6907
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00006908#ifdef CONFIG_I40E_VXLAN
6909/**
6910 * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port
6911 * @pf: board private structure
6912 * @port: The UDP port to look up
6913 *
6914 * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
6915 **/
6916static u8 i40e_get_vxlan_port_idx(struct i40e_pf *pf, __be16 port)
6917{
6918 u8 i;
6919
6920 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
6921 if (pf->vxlan_ports[i] == port)
6922 return i;
6923 }
6924
6925 return i;
6926}
6927
6928/**
6929 * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
6930 * @netdev: This physical port's netdev
6931 * @sa_family: Socket Family that VXLAN is notifying us about
6932 * @port: New UDP port number that VXLAN started listening to
6933 **/
6934static void i40e_add_vxlan_port(struct net_device *netdev,
6935 sa_family_t sa_family, __be16 port)
6936{
6937 struct i40e_netdev_priv *np = netdev_priv(netdev);
6938 struct i40e_vsi *vsi = np->vsi;
6939 struct i40e_pf *pf = vsi->back;
6940 u8 next_idx;
6941 u8 idx;
6942
6943 if (sa_family == AF_INET6)
6944 return;
6945
6946 idx = i40e_get_vxlan_port_idx(pf, port);
6947
6948 /* Check if port already exists */
6949 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
6950 netdev_info(netdev, "Port %d already offloaded\n", ntohs(port));
6951 return;
6952 }
6953
6954 /* Now check if there is space to add the new port */
6955 next_idx = i40e_get_vxlan_port_idx(pf, 0);
6956
6957 if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
6958 netdev_info(netdev, "Maximum number of UDP ports reached, not adding port %d\n",
6959 ntohs(port));
6960 return;
6961 }
6962
6963 /* New port: add it and mark its index in the bitmap */
6964 pf->vxlan_ports[next_idx] = port;
6965 pf->pending_vxlan_bitmap |= (1 << next_idx);
6966
6967 pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC;
6968}
6969
6970/**
6971 * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
6972 * @netdev: This physical port's netdev
6973 * @sa_family: Socket Family that VXLAN is notifying us about
6974 * @port: UDP port number that VXLAN stopped listening to
6975 **/
6976static void i40e_del_vxlan_port(struct net_device *netdev,
6977 sa_family_t sa_family, __be16 port)
6978{
6979 struct i40e_netdev_priv *np = netdev_priv(netdev);
6980 struct i40e_vsi *vsi = np->vsi;
6981 struct i40e_pf *pf = vsi->back;
6982 u8 idx;
6983
6984 if (sa_family == AF_INET6)
6985 return;
6986
6987 idx = i40e_get_vxlan_port_idx(pf, port);
6988
6989 /* Check if port already exists */
6990 if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
6991 /* if port exists, set it to 0 (mark for deletion)
6992 * and make it pending
6993 */
6994 pf->vxlan_ports[idx] = 0;
6995
6996 pf->pending_vxlan_bitmap |= (1 << idx);
6997
6998 pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC;
6999 } else {
7000 netdev_warn(netdev, "Port %d was not found, not deleting\n",
7001 ntohs(port));
7002 }
7003}
7004
7005#endif
Greg Rose4ba0dea2014-03-06 08:59:55 +00007006#ifdef HAVE_FDB_OPS
7007#ifdef USE_CONST_DEV_UC_CHAR
7008static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
7009 struct net_device *dev,
7010 const unsigned char *addr,
7011 u16 flags)
7012#else
7013static int i40e_ndo_fdb_add(struct ndmsg *ndm,
7014 struct net_device *dev,
7015 unsigned char *addr,
7016 u16 flags)
7017#endif
7018{
7019 struct i40e_netdev_priv *np = netdev_priv(dev);
7020 struct i40e_pf *pf = np->vsi->back;
7021 int err = 0;
7022
7023 if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
7024 return -EOPNOTSUPP;
7025
7026 /* Hardware does not support aging addresses so if a
7027 * ndm_state is given only allow permanent addresses
7028 */
7029 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
7030 netdev_info(dev, "FDB only supports static addresses\n");
7031 return -EINVAL;
7032 }
7033
7034 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
7035 err = dev_uc_add_excl(dev, addr);
7036 else if (is_multicast_ether_addr(addr))
7037 err = dev_mc_add_excl(dev, addr);
7038 else
7039 err = -EINVAL;
7040
7041 /* Only return duplicate errors if NLM_F_EXCL is set */
7042 if (err == -EEXIST && !(flags & NLM_F_EXCL))
7043 err = 0;
7044
7045 return err;
7046}
7047
7048#ifndef USE_DEFAULT_FDB_DEL_DUMP
7049#ifdef USE_CONST_DEV_UC_CHAR
7050static int i40e_ndo_fdb_del(struct ndmsg *ndm,
7051 struct net_device *dev,
7052 const unsigned char *addr)
7053#else
7054static int i40e_ndo_fdb_del(struct ndmsg *ndm,
7055 struct net_device *dev,
7056 unsigned char *addr)
7057#endif
7058{
7059 struct i40e_netdev_priv *np = netdev_priv(dev);
7060 struct i40e_pf *pf = np->vsi->back;
7061 int err = -EOPNOTSUPP;
7062
7063 if (ndm->ndm_state & NUD_PERMANENT) {
7064 netdev_info(dev, "FDB only supports static addresses\n");
7065 return -EINVAL;
7066 }
7067
7068 if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
7069 if (is_unicast_ether_addr(addr))
7070 err = dev_uc_del(dev, addr);
7071 else if (is_multicast_ether_addr(addr))
7072 err = dev_mc_del(dev, addr);
7073 else
7074 err = -EINVAL;
7075 }
7076
7077 return err;
7078}
7079
7080static int i40e_ndo_fdb_dump(struct sk_buff *skb,
7081 struct netlink_callback *cb,
7082 struct net_device *dev,
7083 int idx)
7084{
7085 struct i40e_netdev_priv *np = netdev_priv(dev);
7086 struct i40e_pf *pf = np->vsi->back;
7087
7088 if (pf->flags & I40E_FLAG_SRIOV_ENABLED)
7089 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
7090
7091 return idx;
7092}
7093
7094#endif /* USE_DEFAULT_FDB_DEL_DUMP */
7095#endif /* HAVE_FDB_OPS */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007096static const struct net_device_ops i40e_netdev_ops = {
7097 .ndo_open = i40e_open,
7098 .ndo_stop = i40e_close,
7099 .ndo_start_xmit = i40e_lan_xmit_frame,
7100 .ndo_get_stats64 = i40e_get_netdev_stats_struct,
7101 .ndo_set_rx_mode = i40e_set_rx_mode,
7102 .ndo_validate_addr = eth_validate_addr,
7103 .ndo_set_mac_address = i40e_set_mac,
7104 .ndo_change_mtu = i40e_change_mtu,
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00007105 .ndo_do_ioctl = i40e_ioctl,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007106 .ndo_tx_timeout = i40e_tx_timeout,
7107 .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
7108 .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
7109#ifdef CONFIG_NET_POLL_CONTROLLER
7110 .ndo_poll_controller = i40e_netpoll,
7111#endif
7112 .ndo_setup_tc = i40e_setup_tc,
7113 .ndo_set_features = i40e_set_features,
7114 .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
7115 .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -04007116 .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007117 .ndo_get_vf_config = i40e_ndo_get_vf_config,
Mitch Williams588aefa2014-02-11 08:27:49 +00007118 .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
Mitch Williamsc674d122014-05-20 08:01:40 +00007119 .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofck,
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00007120#ifdef CONFIG_I40E_VXLAN
7121 .ndo_add_vxlan_port = i40e_add_vxlan_port,
7122 .ndo_del_vxlan_port = i40e_del_vxlan_port,
7123#endif
Greg Rose4ba0dea2014-03-06 08:59:55 +00007124#ifdef HAVE_FDB_OPS
7125 .ndo_fdb_add = i40e_ndo_fdb_add,
7126#ifndef USE_DEFAULT_FDB_DEL_DUMP
7127 .ndo_fdb_del = i40e_ndo_fdb_del,
7128 .ndo_fdb_dump = i40e_ndo_fdb_dump,
7129#endif
7130#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007131};
7132
7133/**
7134 * i40e_config_netdev - Setup the netdev flags
7135 * @vsi: the VSI being configured
7136 *
7137 * Returns 0 on success, negative value on failure
7138 **/
7139static int i40e_config_netdev(struct i40e_vsi *vsi)
7140{
Greg Rose1a103702013-11-28 06:42:39 +00007141 u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007142 struct i40e_pf *pf = vsi->back;
7143 struct i40e_hw *hw = &pf->hw;
7144 struct i40e_netdev_priv *np;
7145 struct net_device *netdev;
7146 u8 mac_addr[ETH_ALEN];
7147 int etherdev_size;
7148
7149 etherdev_size = sizeof(struct i40e_netdev_priv);
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00007150 netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007151 if (!netdev)
7152 return -ENOMEM;
7153
7154 vsi->netdev = netdev;
7155 np = netdev_priv(netdev);
7156 np->vsi = vsi;
7157
Or Gerlitzd70e9412014-03-18 10:36:45 +02007158 netdev->hw_enc_features |= NETIF_F_IP_CSUM |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007159 NETIF_F_GSO_UDP_TUNNEL |
Or Gerlitzd70e9412014-03-18 10:36:45 +02007160 NETIF_F_TSO;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007161
7162 netdev->features = NETIF_F_SG |
7163 NETIF_F_IP_CSUM |
7164 NETIF_F_SCTP_CSUM |
7165 NETIF_F_HIGHDMA |
7166 NETIF_F_GSO_UDP_TUNNEL |
7167 NETIF_F_HW_VLAN_CTAG_TX |
7168 NETIF_F_HW_VLAN_CTAG_RX |
7169 NETIF_F_HW_VLAN_CTAG_FILTER |
7170 NETIF_F_IPV6_CSUM |
7171 NETIF_F_TSO |
Jesse Brandeburg059dab62014-04-01 09:07:20 +00007172 NETIF_F_TSO_ECN |
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007173 NETIF_F_TSO6 |
7174 NETIF_F_RXCSUM |
7175 NETIF_F_RXHASH |
7176 0;
7177
Anjali Singhai Jain2e86a0b2014-04-01 07:11:53 +00007178 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
7179 netdev->features |= NETIF_F_NTUPLE;
7180
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007181 /* copy netdev features into list of user selectable features */
7182 netdev->hw_features |= netdev->features;
7183
7184 if (vsi->type == I40E_VSI_MAIN) {
7185 SET_NETDEV_DEV(netdev, &pf->pdev->dev);
Greg Rose9a173902014-05-22 06:32:02 +00007186 ether_addr_copy(mac_addr, hw->mac.perm_addr);
Greg Rose8c27d422014-05-22 06:31:56 +00007187 /* The following two steps are necessary to prevent reception
7188 * of tagged packets - by default the NVM loads a MAC-VLAN
7189 * filter that will accept any tagged packet. This is to
7190 * prevent that during normal operations until a specific
7191 * VLAN tag filter has been set.
7192 */
7193 i40e_rm_default_mac_filter(vsi, mac_addr);
7194 i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007195 } else {
7196 /* relate the VSI_VMDQ name to the VSI_MAIN name */
7197 snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
7198 pf->vsi[pf->lan_vsi]->netdev->name);
7199 random_ether_addr(mac_addr);
7200 i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false);
7201 }
Greg Rose1a103702013-11-28 06:42:39 +00007202 i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007203
Greg Rose9a173902014-05-22 06:32:02 +00007204 ether_addr_copy(netdev->dev_addr, mac_addr);
7205 ether_addr_copy(netdev->perm_addr, mac_addr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007206 /* vlan gets same features (except vlan offload)
7207 * after any tweaks for specific VSI types
7208 */
7209 netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX |
7210 NETIF_F_HW_VLAN_CTAG_RX |
7211 NETIF_F_HW_VLAN_CTAG_FILTER);
7212 netdev->priv_flags |= IFF_UNICAST_FLT;
7213 netdev->priv_flags |= IFF_SUPP_NOFCS;
7214 /* Setup netdev TC information */
7215 i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
7216
7217 netdev->netdev_ops = &i40e_netdev_ops;
7218 netdev->watchdog_timeo = 5 * HZ;
7219 i40e_set_ethtool_ops(netdev);
7220
7221 return 0;
7222}
7223
7224/**
7225 * i40e_vsi_delete - Delete a VSI from the switch
7226 * @vsi: the VSI being removed
7227 *
7228 * Returns 0 on success, negative value on failure
7229 **/
7230static void i40e_vsi_delete(struct i40e_vsi *vsi)
7231{
7232 /* remove default VSI is not allowed */
7233 if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
7234 return;
7235
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007236 i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007237}
7238
7239/**
7240 * i40e_add_vsi - Add a VSI to the switch
7241 * @vsi: the VSI being configured
7242 *
7243 * This initializes a VSI context depending on the VSI type to be added and
7244 * passes it down to the add_vsi aq command.
7245 **/
7246static int i40e_add_vsi(struct i40e_vsi *vsi)
7247{
7248 int ret = -ENODEV;
7249 struct i40e_mac_filter *f, *ftmp;
7250 struct i40e_pf *pf = vsi->back;
7251 struct i40e_hw *hw = &pf->hw;
7252 struct i40e_vsi_context ctxt;
7253 u8 enabled_tc = 0x1; /* TC0 enabled */
7254 int f_count = 0;
7255
7256 memset(&ctxt, 0, sizeof(ctxt));
7257 switch (vsi->type) {
7258 case I40E_VSI_MAIN:
7259 /* The PF's main VSI is already setup as part of the
7260 * device initialization, so we'll not bother with
7261 * the add_vsi call, but we will retrieve the current
7262 * VSI context.
7263 */
7264 ctxt.seid = pf->main_vsi_seid;
7265 ctxt.pf_num = pf->hw.pf_id;
7266 ctxt.vf_num = 0;
7267 ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
7268 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
7269 if (ret) {
7270 dev_info(&pf->pdev->dev,
7271 "couldn't get pf vsi config, err %d, aq_err %d\n",
7272 ret, pf->hw.aq.asq_last_status);
7273 return -ENOENT;
7274 }
7275 memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
7276 vsi->info.valid_sections = 0;
7277
7278 vsi->seid = ctxt.seid;
7279 vsi->id = ctxt.vsi_number;
7280
7281 enabled_tc = i40e_pf_get_tc_map(pf);
7282
7283 /* MFP mode setup queue map and update VSI */
7284 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
7285 memset(&ctxt, 0, sizeof(ctxt));
7286 ctxt.seid = pf->main_vsi_seid;
7287 ctxt.pf_num = pf->hw.pf_id;
7288 ctxt.vf_num = 0;
7289 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
7290 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
7291 if (ret) {
7292 dev_info(&pf->pdev->dev,
7293 "update vsi failed, aq_err=%d\n",
7294 pf->hw.aq.asq_last_status);
7295 ret = -ENOENT;
7296 goto err;
7297 }
7298 /* update the local VSI info queue map */
7299 i40e_vsi_update_queue_map(vsi, &ctxt);
7300 vsi->info.valid_sections = 0;
7301 } else {
7302 /* Default/Main VSI is only enabled for TC0
7303 * reconfigure it to enable all TCs that are
7304 * available on the port in SFP mode.
7305 */
7306 ret = i40e_vsi_config_tc(vsi, enabled_tc);
7307 if (ret) {
7308 dev_info(&pf->pdev->dev,
7309 "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n",
7310 enabled_tc, ret,
7311 pf->hw.aq.asq_last_status);
7312 ret = -ENOENT;
7313 }
7314 }
7315 break;
7316
7317 case I40E_VSI_FDIR:
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08007318 ctxt.pf_num = hw->pf_id;
7319 ctxt.vf_num = 0;
7320 ctxt.uplink_seid = vsi->uplink_seid;
7321 ctxt.connection_type = 0x1; /* regular data port */
7322 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007323 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007324 break;
7325
7326 case I40E_VSI_VMDQ2:
7327 ctxt.pf_num = hw->pf_id;
7328 ctxt.vf_num = 0;
7329 ctxt.uplink_seid = vsi->uplink_seid;
7330 ctxt.connection_type = 0x1; /* regular data port */
7331 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
7332
7333 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
7334
7335 /* This VSI is connected to VEB so the switch_id
7336 * should be set to zero by default.
7337 */
7338 ctxt.info.switch_id = 0;
7339 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
7340 ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
7341
7342 /* Setup the VSI tx/rx queue map for TC0 only for now */
7343 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
7344 break;
7345
7346 case I40E_VSI_SRIOV:
7347 ctxt.pf_num = hw->pf_id;
7348 ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
7349 ctxt.uplink_seid = vsi->uplink_seid;
7350 ctxt.connection_type = 0x1; /* regular data port */
7351 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
7352
7353 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
7354
7355 /* This VSI is connected to VEB so the switch_id
7356 * should be set to zero by default.
7357 */
7358 ctxt.info.switch_id = cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
7359
7360 ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
7361 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
Mitch Williamsc674d122014-05-20 08:01:40 +00007362 if (pf->vf[vsi->vf_id].spoofchk) {
7363 ctxt.info.valid_sections |=
7364 cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
7365 ctxt.info.sec_flags |=
7366 (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
7367 I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
7368 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007369 /* Setup the VSI tx/rx queue map for TC0 only for now */
7370 i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
7371 break;
7372
7373 default:
7374 return -ENODEV;
7375 }
7376
7377 if (vsi->type != I40E_VSI_MAIN) {
7378 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
7379 if (ret) {
7380 dev_info(&vsi->back->pdev->dev,
7381 "add vsi failed, aq_err=%d\n",
7382 vsi->back->hw.aq.asq_last_status);
7383 ret = -ENOENT;
7384 goto err;
7385 }
7386 memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
7387 vsi->info.valid_sections = 0;
7388 vsi->seid = ctxt.seid;
7389 vsi->id = ctxt.vsi_number;
7390 }
7391
7392 /* If macvlan filters already exist, force them to get loaded */
7393 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
7394 f->changed = true;
7395 f_count++;
Shannon Nelson6252c7e2014-06-04 01:23:23 +00007396
7397 if (f->is_laa && vsi->type == I40E_VSI_MAIN) {
7398 i40e_aq_mac_address_write(&vsi->back->hw,
7399 I40E_AQC_WRITE_TYPE_LAA_WOL,
7400 f->macaddr, NULL);
7401 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007402 }
7403 if (f_count) {
7404 vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
7405 pf->flags |= I40E_FLAG_FILTER_SYNC;
7406 }
7407
7408 /* Update VSI BW information */
7409 ret = i40e_vsi_get_bw_info(vsi);
7410 if (ret) {
7411 dev_info(&pf->pdev->dev,
7412 "couldn't get vsi bw info, err %d, aq_err %d\n",
7413 ret, pf->hw.aq.asq_last_status);
7414 /* VSI is already added so not tearing that up */
7415 ret = 0;
7416 }
7417
7418err:
7419 return ret;
7420}
7421
7422/**
7423 * i40e_vsi_release - Delete a VSI and free its resources
7424 * @vsi: the VSI being removed
7425 *
7426 * Returns 0 on success or < 0 on error
7427 **/
7428int i40e_vsi_release(struct i40e_vsi *vsi)
7429{
7430 struct i40e_mac_filter *f, *ftmp;
7431 struct i40e_veb *veb = NULL;
7432 struct i40e_pf *pf;
7433 u16 uplink_seid;
7434 int i, n;
7435
7436 pf = vsi->back;
7437
7438 /* release of a VEB-owner or last VSI is not allowed */
7439 if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
7440 dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
7441 vsi->seid, vsi->uplink_seid);
7442 return -ENODEV;
7443 }
7444 if (vsi == pf->vsi[pf->lan_vsi] &&
7445 !test_bit(__I40E_DOWN, &pf->state)) {
7446 dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
7447 return -ENODEV;
7448 }
7449
7450 uplink_seid = vsi->uplink_seid;
7451 if (vsi->type != I40E_VSI_SRIOV) {
7452 if (vsi->netdev_registered) {
7453 vsi->netdev_registered = false;
7454 if (vsi->netdev) {
7455 /* results in a call to i40e_close() */
7456 unregister_netdev(vsi->netdev);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007457 }
7458 } else {
Shannon Nelson90ef8d42014-03-14 07:32:26 +00007459 i40e_vsi_close(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007460 }
7461 i40e_vsi_disable_irq(vsi);
7462 }
7463
7464 list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
7465 i40e_del_filter(vsi, f->macaddr, f->vlan,
7466 f->is_vf, f->is_netdev);
7467 i40e_sync_vsi_filters(vsi);
7468
7469 i40e_vsi_delete(vsi);
7470 i40e_vsi_free_q_vectors(vsi);
Shannon Nelsona4866592014-02-11 08:24:07 +00007471 if (vsi->netdev) {
7472 free_netdev(vsi->netdev);
7473 vsi->netdev = NULL;
7474 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007475 i40e_vsi_clear_rings(vsi);
7476 i40e_vsi_clear(vsi);
7477
7478 /* If this was the last thing on the VEB, except for the
7479 * controlling VSI, remove the VEB, which puts the controlling
7480 * VSI onto the next level down in the switch.
7481 *
7482 * Well, okay, there's one more exception here: don't remove
7483 * the orphan VEBs yet. We'll wait for an explicit remove request
7484 * from up the network stack.
7485 */
Mitch Williams505682c2014-05-20 08:01:37 +00007486 for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007487 if (pf->vsi[i] &&
7488 pf->vsi[i]->uplink_seid == uplink_seid &&
7489 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
7490 n++; /* count the VSIs */
7491 }
7492 }
7493 for (i = 0; i < I40E_MAX_VEB; i++) {
7494 if (!pf->veb[i])
7495 continue;
7496 if (pf->veb[i]->uplink_seid == uplink_seid)
7497 n++; /* count the VEBs */
7498 if (pf->veb[i]->seid == uplink_seid)
7499 veb = pf->veb[i];
7500 }
7501 if (n == 0 && veb && veb->uplink_seid != 0)
7502 i40e_veb_release(veb);
7503
7504 return 0;
7505}
7506
7507/**
7508 * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
7509 * @vsi: ptr to the VSI
7510 *
7511 * This should only be called after i40e_vsi_mem_alloc() which allocates the
7512 * corresponding SW VSI structure and initializes num_queue_pairs for the
7513 * newly allocated VSI.
7514 *
7515 * Returns 0 on success or negative on failure
7516 **/
7517static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
7518{
7519 int ret = -ENOENT;
7520 struct i40e_pf *pf = vsi->back;
7521
Alexander Duyck493fb302013-09-28 07:01:44 +00007522 if (vsi->q_vectors[0]) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007523 dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
7524 vsi->seid);
7525 return -EEXIST;
7526 }
7527
7528 if (vsi->base_vector) {
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00007529 dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007530 vsi->seid, vsi->base_vector);
7531 return -EEXIST;
7532 }
7533
Greg Rose90e04072014-03-06 08:59:57 +00007534 ret = i40e_vsi_alloc_q_vectors(vsi);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007535 if (ret) {
7536 dev_info(&pf->pdev->dev,
7537 "failed to allocate %d q_vector for VSI %d, ret=%d\n",
7538 vsi->num_q_vectors, vsi->seid, ret);
7539 vsi->num_q_vectors = 0;
7540 goto vector_setup_out;
7541 }
7542
Shannon Nelson958a3e32013-09-28 07:13:28 +00007543 if (vsi->num_q_vectors)
7544 vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
7545 vsi->num_q_vectors, vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007546 if (vsi->base_vector < 0) {
7547 dev_info(&pf->pdev->dev,
Jesse Brandeburgf29eaa32014-02-11 08:24:12 +00007548 "failed to get queue tracking for VSI %d, err=%d\n",
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007549 vsi->seid, vsi->base_vector);
7550 i40e_vsi_free_q_vectors(vsi);
7551 ret = -ENOENT;
7552 goto vector_setup_out;
7553 }
7554
7555vector_setup_out:
7556 return ret;
7557}
7558
7559/**
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00007560 * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
7561 * @vsi: pointer to the vsi.
7562 *
7563 * This re-allocates a vsi's queue resources.
7564 *
7565 * Returns pointer to the successfully allocated and configured VSI sw struct
7566 * on success, otherwise returns NULL on failure.
7567 **/
7568static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
7569{
7570 struct i40e_pf *pf = vsi->back;
7571 u8 enabled_tc;
7572 int ret;
7573
7574 i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
7575 i40e_vsi_clear_rings(vsi);
7576
7577 i40e_vsi_free_arrays(vsi, false);
7578 i40e_set_num_rings_in_vsi(vsi);
7579 ret = i40e_vsi_alloc_arrays(vsi, false);
7580 if (ret)
7581 goto err_vsi;
7582
7583 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
7584 if (ret < 0) {
7585 dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n",
7586 vsi->seid, ret);
7587 goto err_vsi;
7588 }
7589 vsi->base_queue = ret;
7590
7591 /* Update the FW view of the VSI. Force a reset of TC and queue
7592 * layout configurations.
7593 */
7594 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
7595 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
7596 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
7597 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
7598
7599 /* assign it some queues */
7600 ret = i40e_alloc_rings(vsi);
7601 if (ret)
7602 goto err_rings;
7603
7604 /* map all of the rings to the q_vectors */
7605 i40e_vsi_map_rings_to_vectors(vsi);
7606 return vsi;
7607
7608err_rings:
7609 i40e_vsi_free_q_vectors(vsi);
7610 if (vsi->netdev_registered) {
7611 vsi->netdev_registered = false;
7612 unregister_netdev(vsi->netdev);
7613 free_netdev(vsi->netdev);
7614 vsi->netdev = NULL;
7615 }
7616 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
7617err_vsi:
7618 i40e_vsi_clear(vsi);
7619 return NULL;
7620}
7621
7622/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007623 * i40e_vsi_setup - Set up a VSI by a given type
7624 * @pf: board private structure
7625 * @type: VSI type
7626 * @uplink_seid: the switch element to link to
7627 * @param1: usage depends upon VSI type. For VF types, indicates VF id
7628 *
7629 * This allocates the sw VSI structure and its queue resources, then add a VSI
7630 * to the identified VEB.
7631 *
7632 * Returns pointer to the successfully allocated and configure VSI sw struct on
7633 * success, otherwise returns NULL on failure.
7634 **/
7635struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
7636 u16 uplink_seid, u32 param1)
7637{
7638 struct i40e_vsi *vsi = NULL;
7639 struct i40e_veb *veb = NULL;
7640 int ret, i;
7641 int v_idx;
7642
7643 /* The requested uplink_seid must be either
7644 * - the PF's port seid
7645 * no VEB is needed because this is the PF
7646 * or this is a Flow Director special case VSI
7647 * - seid of an existing VEB
7648 * - seid of a VSI that owns an existing VEB
7649 * - seid of a VSI that doesn't own a VEB
7650 * a new VEB is created and the VSI becomes the owner
7651 * - seid of the PF VSI, which is what creates the first VEB
7652 * this is a special case of the previous
7653 *
7654 * Find which uplink_seid we were given and create a new VEB if needed
7655 */
7656 for (i = 0; i < I40E_MAX_VEB; i++) {
7657 if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
7658 veb = pf->veb[i];
7659 break;
7660 }
7661 }
7662
7663 if (!veb && uplink_seid != pf->mac_seid) {
7664
Mitch Williams505682c2014-05-20 08:01:37 +00007665 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007666 if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
7667 vsi = pf->vsi[i];
7668 break;
7669 }
7670 }
7671 if (!vsi) {
7672 dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
7673 uplink_seid);
7674 return NULL;
7675 }
7676
7677 if (vsi->uplink_seid == pf->mac_seid)
7678 veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
7679 vsi->tc_config.enabled_tc);
7680 else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
7681 veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
7682 vsi->tc_config.enabled_tc);
7683
7684 for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
7685 if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
7686 veb = pf->veb[i];
7687 }
7688 if (!veb) {
7689 dev_info(&pf->pdev->dev, "couldn't add VEB\n");
7690 return NULL;
7691 }
7692
7693 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
7694 uplink_seid = veb->seid;
7695 }
7696
7697 /* get vsi sw struct */
7698 v_idx = i40e_vsi_mem_alloc(pf, type);
7699 if (v_idx < 0)
7700 goto err_alloc;
7701 vsi = pf->vsi[v_idx];
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08007702 if (!vsi)
7703 goto err_alloc;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007704 vsi->type = type;
7705 vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
7706
7707 if (type == I40E_VSI_MAIN)
7708 pf->lan_vsi = v_idx;
7709 else if (type == I40E_VSI_SRIOV)
7710 vsi->vf_id = param1;
7711 /* assign it some queues */
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08007712 ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
7713 vsi->idx);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007714 if (ret < 0) {
7715 dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n",
7716 vsi->seid, ret);
7717 goto err_vsi;
7718 }
7719 vsi->base_queue = ret;
7720
7721 /* get a VSI from the hardware */
7722 vsi->uplink_seid = uplink_seid;
7723 ret = i40e_add_vsi(vsi);
7724 if (ret)
7725 goto err_vsi;
7726
7727 switch (vsi->type) {
7728 /* setup the netdev if needed */
7729 case I40E_VSI_MAIN:
7730 case I40E_VSI_VMDQ2:
7731 ret = i40e_config_netdev(vsi);
7732 if (ret)
7733 goto err_netdev;
7734 ret = register_netdev(vsi->netdev);
7735 if (ret)
7736 goto err_netdev;
7737 vsi->netdev_registered = true;
7738 netif_carrier_off(vsi->netdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08007739#ifdef CONFIG_I40E_DCB
7740 /* Setup DCB netlink interface */
7741 i40e_dcbnl_setup(vsi);
7742#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007743 /* fall through */
7744
7745 case I40E_VSI_FDIR:
7746 /* set up vectors and rings if needed */
7747 ret = i40e_vsi_setup_vectors(vsi);
7748 if (ret)
7749 goto err_msix;
7750
7751 ret = i40e_alloc_rings(vsi);
7752 if (ret)
7753 goto err_rings;
7754
7755 /* map all of the rings to the q_vectors */
7756 i40e_vsi_map_rings_to_vectors(vsi);
7757
7758 i40e_vsi_reset_stats(vsi);
7759 break;
7760
7761 default:
7762 /* no netdev or rings for the other VSI types */
7763 break;
7764 }
7765
7766 return vsi;
7767
7768err_rings:
7769 i40e_vsi_free_q_vectors(vsi);
7770err_msix:
7771 if (vsi->netdev_registered) {
7772 vsi->netdev_registered = false;
7773 unregister_netdev(vsi->netdev);
7774 free_netdev(vsi->netdev);
7775 vsi->netdev = NULL;
7776 }
7777err_netdev:
7778 i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
7779err_vsi:
7780 i40e_vsi_clear(vsi);
7781err_alloc:
7782 return NULL;
7783}
7784
7785/**
7786 * i40e_veb_get_bw_info - Query VEB BW information
7787 * @veb: the veb to query
7788 *
7789 * Query the Tx scheduler BW configuration data for given VEB
7790 **/
7791static int i40e_veb_get_bw_info(struct i40e_veb *veb)
7792{
7793 struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
7794 struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
7795 struct i40e_pf *pf = veb->pf;
7796 struct i40e_hw *hw = &pf->hw;
7797 u32 tc_bw_max;
7798 int ret = 0;
7799 int i;
7800
7801 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
7802 &bw_data, NULL);
7803 if (ret) {
7804 dev_info(&pf->pdev->dev,
7805 "query veb bw config failed, aq_err=%d\n",
7806 hw->aq.asq_last_status);
7807 goto out;
7808 }
7809
7810 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
7811 &ets_data, NULL);
7812 if (ret) {
7813 dev_info(&pf->pdev->dev,
7814 "query veb bw ets config failed, aq_err=%d\n",
7815 hw->aq.asq_last_status);
7816 goto out;
7817 }
7818
7819 veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
7820 veb->bw_max_quanta = ets_data.tc_bw_max;
7821 veb->is_abs_credits = bw_data.absolute_credits_enable;
7822 tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
7823 (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
7824 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
7825 veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
7826 veb->bw_tc_limit_credits[i] =
7827 le16_to_cpu(bw_data.tc_bw_limits[i]);
7828 veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
7829 }
7830
7831out:
7832 return ret;
7833}
7834
7835/**
7836 * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
7837 * @pf: board private structure
7838 *
7839 * On error: returns error code (negative)
7840 * On success: returns vsi index in PF (positive)
7841 **/
7842static int i40e_veb_mem_alloc(struct i40e_pf *pf)
7843{
7844 int ret = -ENOENT;
7845 struct i40e_veb *veb;
7846 int i;
7847
7848 /* Need to protect the allocation of switch elements at the PF level */
7849 mutex_lock(&pf->switch_mutex);
7850
7851 /* VEB list may be fragmented if VEB creation/destruction has
7852 * been happening. We can afford to do a quick scan to look
7853 * for any free slots in the list.
7854 *
7855 * find next empty veb slot, looping back around if necessary
7856 */
7857 i = 0;
7858 while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
7859 i++;
7860 if (i >= I40E_MAX_VEB) {
7861 ret = -ENOMEM;
7862 goto err_alloc_veb; /* out of VEB slots! */
7863 }
7864
7865 veb = kzalloc(sizeof(*veb), GFP_KERNEL);
7866 if (!veb) {
7867 ret = -ENOMEM;
7868 goto err_alloc_veb;
7869 }
7870 veb->pf = pf;
7871 veb->idx = i;
7872 veb->enabled_tc = 1;
7873
7874 pf->veb[i] = veb;
7875 ret = i;
7876err_alloc_veb:
7877 mutex_unlock(&pf->switch_mutex);
7878 return ret;
7879}
7880
7881/**
7882 * i40e_switch_branch_release - Delete a branch of the switch tree
7883 * @branch: where to start deleting
7884 *
7885 * This uses recursion to find the tips of the branch to be
7886 * removed, deleting until we get back to and can delete this VEB.
7887 **/
7888static void i40e_switch_branch_release(struct i40e_veb *branch)
7889{
7890 struct i40e_pf *pf = branch->pf;
7891 u16 branch_seid = branch->seid;
7892 u16 veb_idx = branch->idx;
7893 int i;
7894
7895 /* release any VEBs on this VEB - RECURSION */
7896 for (i = 0; i < I40E_MAX_VEB; i++) {
7897 if (!pf->veb[i])
7898 continue;
7899 if (pf->veb[i]->uplink_seid == branch->seid)
7900 i40e_switch_branch_release(pf->veb[i]);
7901 }
7902
7903 /* Release the VSIs on this VEB, but not the owner VSI.
7904 *
7905 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
7906 * the VEB itself, so don't use (*branch) after this loop.
7907 */
Mitch Williams505682c2014-05-20 08:01:37 +00007908 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007909 if (!pf->vsi[i])
7910 continue;
7911 if (pf->vsi[i]->uplink_seid == branch_seid &&
7912 (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
7913 i40e_vsi_release(pf->vsi[i]);
7914 }
7915 }
7916
7917 /* There's one corner case where the VEB might not have been
7918 * removed, so double check it here and remove it if needed.
7919 * This case happens if the veb was created from the debugfs
7920 * commands and no VSIs were added to it.
7921 */
7922 if (pf->veb[veb_idx])
7923 i40e_veb_release(pf->veb[veb_idx]);
7924}
7925
7926/**
7927 * i40e_veb_clear - remove veb struct
7928 * @veb: the veb to remove
7929 **/
7930static void i40e_veb_clear(struct i40e_veb *veb)
7931{
7932 if (!veb)
7933 return;
7934
7935 if (veb->pf) {
7936 struct i40e_pf *pf = veb->pf;
7937
7938 mutex_lock(&pf->switch_mutex);
7939 if (pf->veb[veb->idx] == veb)
7940 pf->veb[veb->idx] = NULL;
7941 mutex_unlock(&pf->switch_mutex);
7942 }
7943
7944 kfree(veb);
7945}
7946
7947/**
7948 * i40e_veb_release - Delete a VEB and free its resources
7949 * @veb: the VEB being removed
7950 **/
7951void i40e_veb_release(struct i40e_veb *veb)
7952{
7953 struct i40e_vsi *vsi = NULL;
7954 struct i40e_pf *pf;
7955 int i, n = 0;
7956
7957 pf = veb->pf;
7958
7959 /* find the remaining VSI and check for extras */
Mitch Williams505682c2014-05-20 08:01:37 +00007960 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007961 if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
7962 n++;
7963 vsi = pf->vsi[i];
7964 }
7965 }
7966 if (n != 1) {
7967 dev_info(&pf->pdev->dev,
7968 "can't remove VEB %d with %d VSIs left\n",
7969 veb->seid, n);
7970 return;
7971 }
7972
7973 /* move the remaining VSI to uplink veb */
7974 vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
7975 if (veb->uplink_seid) {
7976 vsi->uplink_seid = veb->uplink_seid;
7977 if (veb->uplink_seid == pf->mac_seid)
7978 vsi->veb_idx = I40E_NO_VEB;
7979 else
7980 vsi->veb_idx = veb->veb_idx;
7981 } else {
7982 /* floating VEB */
7983 vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
7984 vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
7985 }
7986
7987 i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
7988 i40e_veb_clear(veb);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00007989}
7990
7991/**
7992 * i40e_add_veb - create the VEB in the switch
7993 * @veb: the VEB to be instantiated
7994 * @vsi: the controlling VSI
7995 **/
7996static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
7997{
Greg Rose56747262013-11-28 06:39:37 +00007998 bool is_default = false;
Kevin Scotte1c51b952013-11-20 10:02:51 +00007999 bool is_cloud = false;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008000 int ret;
8001
8002 /* get a VEB from the hardware */
8003 ret = i40e_aq_add_veb(&veb->pf->hw, veb->uplink_seid, vsi->seid,
Kevin Scotte1c51b952013-11-20 10:02:51 +00008004 veb->enabled_tc, is_default,
8005 is_cloud, &veb->seid, NULL);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008006 if (ret) {
8007 dev_info(&veb->pf->pdev->dev,
8008 "couldn't add VEB, err %d, aq_err %d\n",
8009 ret, veb->pf->hw.aq.asq_last_status);
8010 return -EPERM;
8011 }
8012
8013 /* get statistics counter */
8014 ret = i40e_aq_get_veb_parameters(&veb->pf->hw, veb->seid, NULL, NULL,
8015 &veb->stats_idx, NULL, NULL, NULL);
8016 if (ret) {
8017 dev_info(&veb->pf->pdev->dev,
8018 "couldn't get VEB statistics idx, err %d, aq_err %d\n",
8019 ret, veb->pf->hw.aq.asq_last_status);
8020 return -EPERM;
8021 }
8022 ret = i40e_veb_get_bw_info(veb);
8023 if (ret) {
8024 dev_info(&veb->pf->pdev->dev,
8025 "couldn't get VEB bw info, err %d, aq_err %d\n",
8026 ret, veb->pf->hw.aq.asq_last_status);
8027 i40e_aq_delete_element(&veb->pf->hw, veb->seid, NULL);
8028 return -ENOENT;
8029 }
8030
8031 vsi->uplink_seid = veb->seid;
8032 vsi->veb_idx = veb->idx;
8033 vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
8034
8035 return 0;
8036}
8037
8038/**
8039 * i40e_veb_setup - Set up a VEB
8040 * @pf: board private structure
8041 * @flags: VEB setup flags
8042 * @uplink_seid: the switch element to link to
8043 * @vsi_seid: the initial VSI seid
8044 * @enabled_tc: Enabled TC bit-map
8045 *
8046 * This allocates the sw VEB structure and links it into the switch
8047 * It is possible and legal for this to be a duplicate of an already
8048 * existing VEB. It is also possible for both uplink and vsi seids
8049 * to be zero, in order to create a floating VEB.
8050 *
8051 * Returns pointer to the successfully allocated VEB sw struct on
8052 * success, otherwise returns NULL on failure.
8053 **/
8054struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
8055 u16 uplink_seid, u16 vsi_seid,
8056 u8 enabled_tc)
8057{
8058 struct i40e_veb *veb, *uplink_veb = NULL;
8059 int vsi_idx, veb_idx;
8060 int ret;
8061
8062 /* if one seid is 0, the other must be 0 to create a floating relay */
8063 if ((uplink_seid == 0 || vsi_seid == 0) &&
8064 (uplink_seid + vsi_seid != 0)) {
8065 dev_info(&pf->pdev->dev,
8066 "one, not both seid's are 0: uplink=%d vsi=%d\n",
8067 uplink_seid, vsi_seid);
8068 return NULL;
8069 }
8070
8071 /* make sure there is such a vsi and uplink */
Mitch Williams505682c2014-05-20 08:01:37 +00008072 for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008073 if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
8074 break;
Mitch Williams505682c2014-05-20 08:01:37 +00008075 if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008076 dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
8077 vsi_seid);
8078 return NULL;
8079 }
8080
8081 if (uplink_seid && uplink_seid != pf->mac_seid) {
8082 for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
8083 if (pf->veb[veb_idx] &&
8084 pf->veb[veb_idx]->seid == uplink_seid) {
8085 uplink_veb = pf->veb[veb_idx];
8086 break;
8087 }
8088 }
8089 if (!uplink_veb) {
8090 dev_info(&pf->pdev->dev,
8091 "uplink seid %d not found\n", uplink_seid);
8092 return NULL;
8093 }
8094 }
8095
8096 /* get veb sw struct */
8097 veb_idx = i40e_veb_mem_alloc(pf);
8098 if (veb_idx < 0)
8099 goto err_alloc;
8100 veb = pf->veb[veb_idx];
8101 veb->flags = flags;
8102 veb->uplink_seid = uplink_seid;
8103 veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
8104 veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
8105
8106 /* create the VEB in the switch */
8107 ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
8108 if (ret)
8109 goto err_veb;
Shannon Nelson1bb8b932014-04-23 04:49:54 +00008110 if (vsi_idx == pf->lan_vsi)
8111 pf->lan_veb = veb->idx;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008112
8113 return veb;
8114
8115err_veb:
8116 i40e_veb_clear(veb);
8117err_alloc:
8118 return NULL;
8119}
8120
8121/**
8122 * i40e_setup_pf_switch_element - set pf vars based on switch type
8123 * @pf: board private structure
8124 * @ele: element we are building info from
8125 * @num_reported: total number of elements
8126 * @printconfig: should we print the contents
8127 *
8128 * helper function to assist in extracting a few useful SEID values.
8129 **/
8130static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
8131 struct i40e_aqc_switch_config_element_resp *ele,
8132 u16 num_reported, bool printconfig)
8133{
8134 u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
8135 u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
8136 u8 element_type = ele->element_type;
8137 u16 seid = le16_to_cpu(ele->seid);
8138
8139 if (printconfig)
8140 dev_info(&pf->pdev->dev,
8141 "type=%d seid=%d uplink=%d downlink=%d\n",
8142 element_type, seid, uplink_seid, downlink_seid);
8143
8144 switch (element_type) {
8145 case I40E_SWITCH_ELEMENT_TYPE_MAC:
8146 pf->mac_seid = seid;
8147 break;
8148 case I40E_SWITCH_ELEMENT_TYPE_VEB:
8149 /* Main VEB? */
8150 if (uplink_seid != pf->mac_seid)
8151 break;
8152 if (pf->lan_veb == I40E_NO_VEB) {
8153 int v;
8154
8155 /* find existing or else empty VEB */
8156 for (v = 0; v < I40E_MAX_VEB; v++) {
8157 if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
8158 pf->lan_veb = v;
8159 break;
8160 }
8161 }
8162 if (pf->lan_veb == I40E_NO_VEB) {
8163 v = i40e_veb_mem_alloc(pf);
8164 if (v < 0)
8165 break;
8166 pf->lan_veb = v;
8167 }
8168 }
8169
8170 pf->veb[pf->lan_veb]->seid = seid;
8171 pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
8172 pf->veb[pf->lan_veb]->pf = pf;
8173 pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
8174 break;
8175 case I40E_SWITCH_ELEMENT_TYPE_VSI:
8176 if (num_reported != 1)
8177 break;
8178 /* This is immediately after a reset so we can assume this is
8179 * the PF's VSI
8180 */
8181 pf->mac_seid = uplink_seid;
8182 pf->pf_seid = downlink_seid;
8183 pf->main_vsi_seid = seid;
8184 if (printconfig)
8185 dev_info(&pf->pdev->dev,
8186 "pf_seid=%d main_vsi_seid=%d\n",
8187 pf->pf_seid, pf->main_vsi_seid);
8188 break;
8189 case I40E_SWITCH_ELEMENT_TYPE_PF:
8190 case I40E_SWITCH_ELEMENT_TYPE_VF:
8191 case I40E_SWITCH_ELEMENT_TYPE_EMP:
8192 case I40E_SWITCH_ELEMENT_TYPE_BMC:
8193 case I40E_SWITCH_ELEMENT_TYPE_PE:
8194 case I40E_SWITCH_ELEMENT_TYPE_PA:
8195 /* ignore these for now */
8196 break;
8197 default:
8198 dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
8199 element_type, seid);
8200 break;
8201 }
8202}
8203
8204/**
8205 * i40e_fetch_switch_configuration - Get switch config from firmware
8206 * @pf: board private structure
8207 * @printconfig: should we print the contents
8208 *
8209 * Get the current switch configuration from the device and
8210 * extract a few useful SEID values.
8211 **/
8212int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
8213{
8214 struct i40e_aqc_get_switch_config_resp *sw_config;
8215 u16 next_seid = 0;
8216 int ret = 0;
8217 u8 *aq_buf;
8218 int i;
8219
8220 aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
8221 if (!aq_buf)
8222 return -ENOMEM;
8223
8224 sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
8225 do {
8226 u16 num_reported, num_total;
8227
8228 ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
8229 I40E_AQ_LARGE_BUF,
8230 &next_seid, NULL);
8231 if (ret) {
8232 dev_info(&pf->pdev->dev,
8233 "get switch config failed %d aq_err=%x\n",
8234 ret, pf->hw.aq.asq_last_status);
8235 kfree(aq_buf);
8236 return -ENOENT;
8237 }
8238
8239 num_reported = le16_to_cpu(sw_config->header.num_reported);
8240 num_total = le16_to_cpu(sw_config->header.num_total);
8241
8242 if (printconfig)
8243 dev_info(&pf->pdev->dev,
8244 "header: %d reported %d total\n",
8245 num_reported, num_total);
8246
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008247 for (i = 0; i < num_reported; i++) {
8248 struct i40e_aqc_switch_config_element_resp *ele =
8249 &sw_config->element[i];
8250
8251 i40e_setup_pf_switch_element(pf, ele, num_reported,
8252 printconfig);
8253 }
8254 } while (next_seid != 0);
8255
8256 kfree(aq_buf);
8257 return ret;
8258}
8259
8260/**
8261 * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
8262 * @pf: board private structure
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00008263 * @reinit: if the Main VSI needs to re-initialized.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008264 *
8265 * Returns 0 on success, negative value on failure
8266 **/
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00008267static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008268{
Jesse Brandeburg895106a2013-11-26 10:49:16 +00008269 u32 rxfc = 0, txfc = 0, rxfc_reg;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008270 int ret;
8271
8272 /* find out what's out there already */
8273 ret = i40e_fetch_switch_configuration(pf, false);
8274 if (ret) {
8275 dev_info(&pf->pdev->dev,
8276 "couldn't fetch switch config, err %d, aq_err %d\n",
8277 ret, pf->hw.aq.asq_last_status);
8278 return ret;
8279 }
8280 i40e_pf_reset_stats(pf);
8281
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008282 /* first time setup */
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00008283 if (pf->lan_vsi == I40E_NO_VSI || reinit) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008284 struct i40e_vsi *vsi = NULL;
8285 u16 uplink_seid;
8286
8287 /* Set up the PF VSI associated with the PF's main VSI
8288 * that is already in the HW switch
8289 */
8290 if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
8291 uplink_seid = pf->veb[pf->lan_veb]->seid;
8292 else
8293 uplink_seid = pf->mac_seid;
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00008294 if (pf->lan_vsi == I40E_NO_VSI)
8295 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
8296 else if (reinit)
8297 vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008298 if (!vsi) {
8299 dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
8300 i40e_fdir_teardown(pf);
8301 return -EAGAIN;
8302 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008303 } else {
8304 /* force a reset of TC and queue layout configurations */
8305 u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
8306 pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
8307 pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
8308 i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
8309 }
8310 i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
8311
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008312 i40e_fdir_sb_setup(pf);
8313
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008314 /* Setup static PF queue filter control settings */
8315 ret = i40e_setup_pf_filter_control(pf);
8316 if (ret) {
8317 dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
8318 ret);
8319 /* Failure here should not stop continuing other steps */
8320 }
8321
8322 /* enable RSS in the HW, even for only one queue, as the stack can use
8323 * the hash
8324 */
8325 if ((pf->flags & I40E_FLAG_RSS_ENABLED))
8326 i40e_config_rss(pf);
8327
8328 /* fill in link information and enable LSE reporting */
8329 i40e_aq_get_link_info(&pf->hw, true, NULL, NULL);
8330 i40e_link_event(pf);
8331
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00008332 /* Initialize user-specific link properties */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008333 pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
8334 I40E_AQ_AN_COMPLETED) ? true : false);
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00008335 /* requested_mode is set in probe or by ethtool */
8336 if (!pf->fc_autoneg_status)
8337 goto no_autoneg;
8338
8339 if ((pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) &&
8340 (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008341 pf->hw.fc.current_mode = I40E_FC_FULL;
8342 else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX)
8343 pf->hw.fc.current_mode = I40E_FC_TX_PAUSE;
8344 else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX)
8345 pf->hw.fc.current_mode = I40E_FC_RX_PAUSE;
8346 else
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00008347 pf->hw.fc.current_mode = I40E_FC_NONE;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008348
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00008349 /* sync the flow control settings with the auto-neg values */
8350 switch (pf->hw.fc.current_mode) {
8351 case I40E_FC_FULL:
8352 txfc = 1;
8353 rxfc = 1;
8354 break;
8355 case I40E_FC_TX_PAUSE:
8356 txfc = 1;
8357 rxfc = 0;
8358 break;
8359 case I40E_FC_RX_PAUSE:
8360 txfc = 0;
8361 rxfc = 1;
8362 break;
8363 case I40E_FC_NONE:
8364 case I40E_FC_DEFAULT:
8365 txfc = 0;
8366 rxfc = 0;
8367 break;
8368 case I40E_FC_PFC:
8369 /* TBD */
8370 break;
8371 /* no default case, we have to handle all possibilities here */
8372 }
8373
8374 wr32(&pf->hw, I40E_PRTDCB_FCCFG, txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
8375
8376 rxfc_reg = rd32(&pf->hw, I40E_PRTDCB_MFLCN) &
8377 ~I40E_PRTDCB_MFLCN_RFCE_MASK;
8378 rxfc_reg |= (rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT);
8379
8380 wr32(&pf->hw, I40E_PRTDCB_MFLCN, rxfc_reg);
8381
8382 goto fc_complete;
8383
8384no_autoneg:
8385 /* disable L2 flow control, user can turn it on if they wish */
8386 wr32(&pf->hw, I40E_PRTDCB_FCCFG, 0);
8387 wr32(&pf->hw, I40E_PRTDCB_MFLCN, rd32(&pf->hw, I40E_PRTDCB_MFLCN) &
8388 ~I40E_PRTDCB_MFLCN_RFCE_MASK);
8389
8390fc_complete:
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00008391 i40e_ptp_init(pf);
8392
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008393 return ret;
8394}
8395
8396/**
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008397 * i40e_determine_queue_usage - Work out queue distribution
8398 * @pf: board private structure
8399 **/
8400static void i40e_determine_queue_usage(struct i40e_pf *pf)
8401{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008402 int queues_left;
8403
8404 pf->num_lan_qps = 0;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008405
8406 /* Find the max queues to be put into basic use. We'll always be
8407 * using TC0, whether or not DCB is running, and TC0 will get the
8408 * big RSS set.
8409 */
8410 queues_left = pf->hw.func_caps.num_tx_qp;
8411
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008412 if ((queues_left == 1) ||
Frank Zhang9aa7e932014-05-20 08:01:42 +00008413 !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008414 /* one qp for PF, no queues for anything else */
8415 queues_left = 0;
8416 pf->rss_size = pf->num_lan_qps = 1;
8417
8418 /* make sure all the fancies are disabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08008419 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
8420 I40E_FLAG_FD_SB_ENABLED |
8421 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008422 I40E_FLAG_DCB_CAPABLE |
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08008423 I40E_FLAG_SRIOV_ENABLED |
8424 I40E_FLAG_VMDQ_ENABLED);
Frank Zhang9aa7e932014-05-20 08:01:42 +00008425 } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
8426 I40E_FLAG_FD_SB_ENABLED |
Anjali Singhai Jainbbe7d0e2014-05-20 08:01:44 +00008427 I40E_FLAG_FD_ATR_ENABLED |
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008428 I40E_FLAG_DCB_CAPABLE))) {
Frank Zhang9aa7e932014-05-20 08:01:42 +00008429 /* one qp for PF */
8430 pf->rss_size = pf->num_lan_qps = 1;
8431 queues_left -= pf->num_lan_qps;
8432
8433 pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
8434 I40E_FLAG_FD_SB_ENABLED |
8435 I40E_FLAG_FD_ATR_ENABLED |
8436 I40E_FLAG_DCB_ENABLED |
8437 I40E_FLAG_VMDQ_ENABLED);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008438 } else {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008439 /* Not enough queues for all TCs */
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008440 if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008441 (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008442 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008443 dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
8444 }
8445 pf->num_lan_qps = pf->rss_size_max;
8446 queues_left -= pf->num_lan_qps;
8447 }
8448
8449 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
8450 if (queues_left > 1) {
8451 queues_left -= 1; /* save 1 queue for FD */
8452 } else {
8453 pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
8454 dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
8455 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008456 }
8457
8458 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
8459 pf->num_vf_qps && pf->num_req_vfs && queues_left) {
Anjali Singhai Jaincbf61322014-01-17 15:36:35 -08008460 pf->num_req_vfs = min_t(int, pf->num_req_vfs,
8461 (queues_left / pf->num_vf_qps));
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008462 queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
8463 }
8464
8465 if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
8466 pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
8467 pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
8468 (queues_left / pf->num_vmdq_qps));
8469 queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
8470 }
8471
Anjali Singhai Jainf8ff1462013-11-26 10:49:19 +00008472 pf->queues_left = queues_left;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008473}
8474
8475/**
8476 * i40e_setup_pf_filter_control - Setup PF static filter control
8477 * @pf: PF to be setup
8478 *
8479 * i40e_setup_pf_filter_control sets up a pf's initial filter control
8480 * settings. If PE/FCoE are enabled then it will also set the per PF
8481 * based filter sizes required for them. It also enables Flow director,
8482 * ethertype and macvlan type filter settings for the pf.
8483 *
8484 * Returns 0 on success, negative on failure
8485 **/
8486static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
8487{
8488 struct i40e_filter_control_settings *settings = &pf->filter_settings;
8489
8490 settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
8491
8492 /* Flow Director is enabled */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08008493 if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008494 settings->enable_fdir = true;
8495
8496 /* Ethtype and MACVLAN filters enabled for PF */
8497 settings->enable_ethtype = true;
8498 settings->enable_macvlan = true;
8499
8500 if (i40e_set_filter_control(&pf->hw, settings))
8501 return -ENOENT;
8502
8503 return 0;
8504}
8505
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +00008506#define INFO_STRING_LEN 255
8507static void i40e_print_features(struct i40e_pf *pf)
8508{
8509 struct i40e_hw *hw = &pf->hw;
8510 char *buf, *string;
8511
8512 string = kzalloc(INFO_STRING_LEN, GFP_KERNEL);
8513 if (!string) {
8514 dev_err(&pf->pdev->dev, "Features string allocation failed\n");
8515 return;
8516 }
8517
8518 buf = string;
8519
8520 buf += sprintf(string, "Features: PF-id[%d] ", hw->pf_id);
8521#ifdef CONFIG_PCI_IOV
8522 buf += sprintf(buf, "VFs: %d ", pf->num_req_vfs);
8523#endif
8524 buf += sprintf(buf, "VSIs: %d QP: %d ", pf->hw.func_caps.num_vsis,
8525 pf->vsi[pf->lan_vsi]->num_queue_pairs);
8526
8527 if (pf->flags & I40E_FLAG_RSS_ENABLED)
8528 buf += sprintf(buf, "RSS ");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +00008529 if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +00008530 buf += sprintf(buf, "FD_ATR ");
8531 if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
8532 buf += sprintf(buf, "FD_SB ");
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +00008533 buf += sprintf(buf, "NTUPLE ");
Akeem G Abodunrinc6423ff2014-05-10 04:49:08 +00008534 }
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008535 if (pf->flags & I40E_FLAG_DCB_CAPABLE)
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +00008536 buf += sprintf(buf, "DCB ");
8537 if (pf->flags & I40E_FLAG_PTP)
8538 buf += sprintf(buf, "PTP ");
8539
8540 BUG_ON(buf > (string + INFO_STRING_LEN));
8541 dev_info(&pf->pdev->dev, "%s\n", string);
8542 kfree(string);
8543}
8544
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008545/**
8546 * i40e_probe - Device initialization routine
8547 * @pdev: PCI device information struct
8548 * @ent: entry in i40e_pci_tbl
8549 *
8550 * i40e_probe initializes a pf identified by a pci_dev structure.
8551 * The OS initialization, configuring of the pf private structure,
8552 * and a hardware reset occur.
8553 *
8554 * Returns 0 on success, negative on failure
8555 **/
8556static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
8557{
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008558 struct i40e_pf *pf;
8559 struct i40e_hw *hw;
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +00008560 static u16 pfs_found;
Catherine Sullivand4dfb812013-11-28 06:39:21 +00008561 u16 link_status;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008562 int err = 0;
8563 u32 len;
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00008564 u32 i;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008565
8566 err = pci_enable_device_mem(pdev);
8567 if (err)
8568 return err;
8569
8570 /* set up for high or low dma */
Mitch Williams64942942014-02-11 08:26:33 +00008571 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Mitch Williams64942942014-02-11 08:26:33 +00008572 if (err) {
Jean Sacrene3e3bfd2014-03-25 04:30:27 +00008573 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
8574 if (err) {
8575 dev_err(&pdev->dev,
8576 "DMA configuration failed: 0x%x\n", err);
8577 goto err_dma;
8578 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008579 }
8580
8581 /* set up pci connections */
8582 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
8583 IORESOURCE_MEM), i40e_driver_name);
8584 if (err) {
8585 dev_info(&pdev->dev,
8586 "pci_request_selected_regions failed %d\n", err);
8587 goto err_pci_reg;
8588 }
8589
8590 pci_enable_pcie_error_reporting(pdev);
8591 pci_set_master(pdev);
8592
8593 /* Now that we have a PCI connection, we need to do the
8594 * low level device setup. This is primarily setting up
8595 * the Admin Queue structures and then querying for the
8596 * device's current profile information.
8597 */
8598 pf = kzalloc(sizeof(*pf), GFP_KERNEL);
8599 if (!pf) {
8600 err = -ENOMEM;
8601 goto err_pf_alloc;
8602 }
8603 pf->next_vsi = 0;
8604 pf->pdev = pdev;
8605 set_bit(__I40E_DOWN, &pf->state);
8606
8607 hw = &pf->hw;
8608 hw->back = pf;
8609 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
8610 pci_resource_len(pdev, 0));
8611 if (!hw->hw_addr) {
8612 err = -EIO;
8613 dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
8614 (unsigned int)pci_resource_start(pdev, 0),
8615 (unsigned int)pci_resource_len(pdev, 0), err);
8616 goto err_ioremap;
8617 }
8618 hw->vendor_id = pdev->vendor;
8619 hw->device_id = pdev->device;
8620 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
8621 hw->subsystem_vendor_id = pdev->subsystem_vendor;
8622 hw->subsystem_device_id = pdev->subsystem_device;
8623 hw->bus.device = PCI_SLOT(pdev->devfn);
8624 hw->bus.func = PCI_FUNC(pdev->devfn);
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +00008625 pf->instance = pfs_found;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008626
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +00008627 /* do a special CORER for clearing PXE mode once at init */
8628 if (hw->revision_id == 0 &&
8629 (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
8630 wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
8631 i40e_flush(hw);
8632 msleep(200);
8633 pf->corer_count++;
8634
8635 i40e_clear_pxe_mode(hw);
8636 }
8637
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008638 /* Reset here to make sure all is clean and to define PF 'n' */
Shannon Nelson838d41d2014-06-04 20:41:27 +00008639 i40e_clear_hw(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008640 err = i40e_pf_reset(hw);
8641 if (err) {
8642 dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
8643 goto err_pf_reset;
8644 }
8645 pf->pfr_count++;
8646
8647 hw->aq.num_arq_entries = I40E_AQ_LEN;
8648 hw->aq.num_asq_entries = I40E_AQ_LEN;
8649 hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
8650 hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
8651 pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
8652 snprintf(pf->misc_int_name, sizeof(pf->misc_int_name) - 1,
8653 "%s-pf%d:misc",
8654 dev_driver_string(&pf->pdev->dev), pf->hw.pf_id);
8655
8656 err = i40e_init_shared_code(hw);
8657 if (err) {
8658 dev_info(&pdev->dev, "init_shared_code failed: %d\n", err);
8659 goto err_pf_reset;
8660 }
8661
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00008662 /* set up a default setting for link flow control */
8663 pf->hw.fc.requested_mode = I40E_FC_NONE;
8664
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008665 err = i40e_init_adminq(hw);
8666 dev_info(&pdev->dev, "%s\n", i40e_fw_version_str(hw));
8667 if (err) {
8668 dev_info(&pdev->dev,
8669 "init_adminq failed: %d expecting API %02x.%02x\n",
8670 err,
8671 I40E_FW_API_VERSION_MAJOR, I40E_FW_API_VERSION_MINOR);
8672 goto err_pf_reset;
8673 }
8674
Shannon Nelson278b6f62014-06-04 01:41:03 +00008675 if (hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
8676 dev_info(&pdev->dev,
8677 "Note: FW API version %02x.%02x newer than expected %02x.%02x, recommend driver update.\n",
8678 hw->aq.api_maj_ver, hw->aq.api_min_ver,
8679 I40E_FW_API_VERSION_MAJOR, I40E_FW_API_VERSION_MINOR);
8680
8681 if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
8682 hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR-1))
8683 dev_info(&pdev->dev,
8684 "Note: FW API version %02x.%02x older than expected %02x.%02x, recommend nvm update.\n",
8685 hw->aq.api_maj_ver, hw->aq.api_min_ver,
8686 I40E_FW_API_VERSION_MAJOR, I40E_FW_API_VERSION_MINOR);
8687
8688
Shannon Nelson4eb3f762014-03-06 08:59:58 +00008689 i40e_verify_eeprom(pf);
8690
Jesse Brandeburg2c5fe332014-04-23 04:49:57 +00008691 /* Rev 0 hardware was never productized */
8692 if (hw->revision_id < 1)
8693 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");
8694
Shannon Nelson6ff4ef82013-12-21 05:44:49 +00008695 i40e_clear_pxe_mode(hw);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008696 err = i40e_get_capabilities(pf);
8697 if (err)
8698 goto err_adminq_setup;
8699
8700 err = i40e_sw_init(pf);
8701 if (err) {
8702 dev_info(&pdev->dev, "sw_init failed: %d\n", err);
8703 goto err_sw_init;
8704 }
8705
8706 err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
8707 hw->func_caps.num_rx_qp,
8708 pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
8709 if (err) {
8710 dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
8711 goto err_init_lan_hmc;
8712 }
8713
8714 err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
8715 if (err) {
8716 dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
8717 err = -ENOENT;
8718 goto err_configure_lan_hmc;
8719 }
8720
8721 i40e_get_mac_addr(hw, hw->mac.addr);
Jesse Brandeburgf62b5062013-11-28 06:39:27 +00008722 if (!is_valid_ether_addr(hw->mac.addr)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008723 dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
8724 err = -EIO;
8725 goto err_mac_addr;
8726 }
8727 dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
Greg Rose9a173902014-05-22 06:32:02 +00008728 ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008729
8730 pci_set_drvdata(pdev, pf);
8731 pci_save_state(pdev);
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08008732#ifdef CONFIG_I40E_DCB
8733 err = i40e_init_pf_dcb(pf);
8734 if (err) {
8735 dev_info(&pdev->dev, "init_pf_dcb failed: %d\n", err);
Neerav Parikh4d9b6042014-05-22 06:31:51 +00008736 pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
Neerav Parikh014269f2014-04-01 07:11:48 +00008737 /* Continue without DCB enabled */
Neerav Parikh4e3b35b2014-01-17 15:36:37 -08008738 }
8739#endif /* CONFIG_I40E_DCB */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008740
8741 /* set up periodic task facility */
8742 setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
8743 pf->service_timer_period = HZ;
8744
8745 INIT_WORK(&pf->service_task, i40e_service_task);
8746 clear_bit(__I40E_SERVICE_SCHED, &pf->state);
8747 pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
8748 pf->link_check_timeout = jiffies;
8749
Shannon Nelson8e2773a2013-11-28 06:39:22 +00008750 /* WoL defaults to disabled */
8751 pf->wol_en = false;
8752 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
8753
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008754 /* set up the main switch operations */
8755 i40e_determine_queue_usage(pf);
8756 i40e_init_interrupt_scheme(pf);
8757
Mitch Williams505682c2014-05-20 08:01:37 +00008758 /* The number of VSIs reported by the FW is the minimum guaranteed
8759 * to us; HW supports far more and we share the remaining pool with
8760 * the other PFs. We allocate space for more than the guarantee with
8761 * the understanding that we might not get them all later.
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008762 */
Mitch Williams505682c2014-05-20 08:01:37 +00008763 if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
8764 pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
8765 else
8766 pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
8767
8768 /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
8769 len = sizeof(struct i40e_vsi *) * pf->num_alloc_vsi;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008770 pf->vsi = kzalloc(len, GFP_KERNEL);
Wei Yongjuned87ac02013-09-24 05:17:25 +00008771 if (!pf->vsi) {
8772 err = -ENOMEM;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008773 goto err_switch_setup;
Wei Yongjuned87ac02013-09-24 05:17:25 +00008774 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008775
Anjali Singhai Jainbc7d3382013-11-26 10:49:18 +00008776 err = i40e_setup_pf_switch(pf, false);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008777 if (err) {
8778 dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
8779 goto err_vsis;
8780 }
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00008781 /* if FDIR VSI was set up, start it now */
Mitch Williams505682c2014-05-20 08:01:37 +00008782 for (i = 0; i < pf->num_alloc_vsi; i++) {
Shannon Nelson8a9eb7d2014-03-14 07:32:28 +00008783 if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
8784 i40e_vsi_open(pf->vsi[i]);
8785 break;
8786 }
8787 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008788
8789 /* The main driver is (mostly) up and happy. We need to set this state
8790 * before setting up the misc vector or we get a race and the vector
8791 * ends up disabled forever.
8792 */
8793 clear_bit(__I40E_DOWN, &pf->state);
8794
8795 /* In case of MSIX we are going to setup the misc vector right here
8796 * to handle admin queue events etc. In case of legacy and MSI
8797 * the misc functionality and queue processing is combined in
8798 * the same vector and that gets setup at open.
8799 */
8800 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
8801 err = i40e_setup_misc_vector(pf);
8802 if (err) {
8803 dev_info(&pdev->dev,
8804 "setup of misc vector failed: %d\n", err);
8805 goto err_vsis;
8806 }
8807 }
8808
Greg Rosedf805f62014-04-04 04:43:16 +00008809#ifdef CONFIG_PCI_IOV
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008810 /* prep for VF support */
8811 if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
Shannon Nelson4eb3f762014-03-06 08:59:58 +00008812 (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
8813 !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008814 u32 val;
8815
8816 /* disable link interrupts for VFs */
8817 val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
8818 val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
8819 wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
8820 i40e_flush(hw);
Mitch Williams4aeec012014-02-13 03:48:47 -08008821
8822 if (pci_num_vf(pdev)) {
8823 dev_info(&pdev->dev,
8824 "Active VFs found, allocating resources.\n");
8825 err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
8826 if (err)
8827 dev_info(&pdev->dev,
8828 "Error %d allocating resources for existing VFs\n",
8829 err);
8830 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008831 }
Greg Rosedf805f62014-04-04 04:43:16 +00008832#endif /* CONFIG_PCI_IOV */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008833
Anjali Singhai Jain93cd7652013-11-20 10:03:01 +00008834 pfs_found++;
8835
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008836 i40e_dbg_pf_init(pf);
8837
8838 /* tell the firmware that we're starting */
Jesse Brandeburg44033fa2014-04-23 04:50:15 +00008839 i40e_send_version(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008840
8841 /* since everything's happy, start the service_task timer */
8842 mod_timer(&pf->service_timer,
8843 round_jiffies(jiffies + pf->service_timer_period));
8844
Catherine Sullivand4dfb812013-11-28 06:39:21 +00008845 /* Get the negotiated link width and speed from PCI config space */
8846 pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, &link_status);
8847
8848 i40e_set_pci_config_data(hw, link_status);
8849
Jesse Brandeburg69bfb112014-02-11 08:24:13 +00008850 dev_info(&pdev->dev, "PCI-Express: %s %s\n",
Catherine Sullivand4dfb812013-11-28 06:39:21 +00008851 (hw->bus.speed == i40e_bus_speed_8000 ? "Speed 8.0GT/s" :
8852 hw->bus.speed == i40e_bus_speed_5000 ? "Speed 5.0GT/s" :
8853 hw->bus.speed == i40e_bus_speed_2500 ? "Speed 2.5GT/s" :
8854 "Unknown"),
8855 (hw->bus.width == i40e_bus_width_pcie_x8 ? "Width x8" :
8856 hw->bus.width == i40e_bus_width_pcie_x4 ? "Width x4" :
8857 hw->bus.width == i40e_bus_width_pcie_x2 ? "Width x2" :
8858 hw->bus.width == i40e_bus_width_pcie_x1 ? "Width x1" :
8859 "Unknown"));
8860
8861 if (hw->bus.width < i40e_bus_width_pcie_x8 ||
8862 hw->bus.speed < i40e_bus_speed_8000) {
8863 dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
8864 dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
8865 }
8866
Jesse Brandeburg0c22b3d2014-02-11 08:24:14 +00008867 /* print a string summarizing features */
8868 i40e_print_features(pf);
8869
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008870 return 0;
8871
8872 /* Unwind what we've done if something failed in the setup */
8873err_vsis:
8874 set_bit(__I40E_DOWN, &pf->state);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008875 i40e_clear_interrupt_scheme(pf);
8876 kfree(pf->vsi);
Shannon Nelson04b03012013-11-28 06:39:34 +00008877err_switch_setup:
8878 i40e_reset_interrupt_capability(pf);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008879 del_timer_sync(&pf->service_timer);
8880err_mac_addr:
8881err_configure_lan_hmc:
8882 (void)i40e_shutdown_lan_hmc(hw);
8883err_init_lan_hmc:
8884 kfree(pf->qp_pile);
8885 kfree(pf->irq_pile);
8886err_sw_init:
8887err_adminq_setup:
8888 (void)i40e_shutdown_adminq(hw);
8889err_pf_reset:
8890 iounmap(hw->hw_addr);
8891err_ioremap:
8892 kfree(pf);
8893err_pf_alloc:
8894 pci_disable_pcie_error_reporting(pdev);
8895 pci_release_selected_regions(pdev,
8896 pci_select_bars(pdev, IORESOURCE_MEM));
8897err_pci_reg:
8898err_dma:
8899 pci_disable_device(pdev);
8900 return err;
8901}
8902
8903/**
8904 * i40e_remove - Device removal routine
8905 * @pdev: PCI device information struct
8906 *
8907 * i40e_remove is called by the PCI subsystem to alert the driver
8908 * that is should release a PCI device. This could be caused by a
8909 * Hot-Plug event, or because the driver is going to be removed from
8910 * memory.
8911 **/
8912static void i40e_remove(struct pci_dev *pdev)
8913{
8914 struct i40e_pf *pf = pci_get_drvdata(pdev);
8915 i40e_status ret_code;
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008916 int i;
8917
8918 i40e_dbg_pf_exit(pf);
8919
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00008920 i40e_ptp_stop(pf);
8921
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008922 /* no more scheduling of any task */
8923 set_bit(__I40E_DOWN, &pf->state);
8924 del_timer_sync(&pf->service_timer);
8925 cancel_work_sync(&pf->service_task);
8926
Mitch Williamseb2d80b2014-02-13 03:48:48 -08008927 if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
8928 i40e_free_vfs(pf);
8929 pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
8930 }
8931
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008932 i40e_fdir_teardown(pf);
8933
8934 /* If there is a switch structure or any orphans, remove them.
8935 * This will leave only the PF's VSI remaining.
8936 */
8937 for (i = 0; i < I40E_MAX_VEB; i++) {
8938 if (!pf->veb[i])
8939 continue;
8940
8941 if (pf->veb[i]->uplink_seid == pf->mac_seid ||
8942 pf->veb[i]->uplink_seid == 0)
8943 i40e_switch_branch_release(pf->veb[i]);
8944 }
8945
8946 /* Now we can shutdown the PF's VSI, just before we kill
8947 * adminq and hmc.
8948 */
8949 if (pf->vsi[pf->lan_vsi])
8950 i40e_vsi_release(pf->vsi[pf->lan_vsi]);
8951
8952 i40e_stop_misc_vector(pf);
8953 if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
8954 synchronize_irq(pf->msix_entries[0].vector);
8955 free_irq(pf->msix_entries[0].vector, pf);
8956 }
8957
8958 /* shutdown and destroy the HMC */
Shannon Nelson60442de2014-04-23 04:50:13 +00008959 if (pf->hw.hmc.hmc_obj) {
8960 ret_code = i40e_shutdown_lan_hmc(&pf->hw);
8961 if (ret_code)
8962 dev_warn(&pdev->dev,
8963 "Failed to destroy the HMC resources: %d\n",
8964 ret_code);
8965 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008966
8967 /* shutdown the adminq */
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008968 ret_code = i40e_shutdown_adminq(&pf->hw);
8969 if (ret_code)
8970 dev_warn(&pdev->dev,
8971 "Failed to destroy the Admin Queue resources: %d\n",
8972 ret_code);
8973
8974 /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
8975 i40e_clear_interrupt_scheme(pf);
Mitch Williams505682c2014-05-20 08:01:37 +00008976 for (i = 0; i < pf->num_alloc_vsi; i++) {
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008977 if (pf->vsi[i]) {
8978 i40e_vsi_clear_rings(pf->vsi[i]);
8979 i40e_vsi_clear(pf->vsi[i]);
8980 pf->vsi[i] = NULL;
8981 }
8982 }
8983
8984 for (i = 0; i < I40E_MAX_VEB; i++) {
8985 kfree(pf->veb[i]);
8986 pf->veb[i] = NULL;
8987 }
8988
8989 kfree(pf->qp_pile);
8990 kfree(pf->irq_pile);
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008991 kfree(pf->vsi);
8992
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00008993 iounmap(pf->hw.hw_addr);
8994 kfree(pf);
8995 pci_release_selected_regions(pdev,
8996 pci_select_bars(pdev, IORESOURCE_MEM));
8997
8998 pci_disable_pcie_error_reporting(pdev);
8999 pci_disable_device(pdev);
9000}
9001
9002/**
9003 * i40e_pci_error_detected - warning that something funky happened in PCI land
9004 * @pdev: PCI device information struct
9005 *
9006 * Called to warn that something happened and the error handling steps
9007 * are in progress. Allows the driver to quiesce things, be ready for
9008 * remediation.
9009 **/
9010static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
9011 enum pci_channel_state error)
9012{
9013 struct i40e_pf *pf = pci_get_drvdata(pdev);
9014
9015 dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
9016
9017 /* shutdown all operations */
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009018 if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
9019 rtnl_lock();
9020 i40e_prep_for_reset(pf);
9021 rtnl_unlock();
9022 }
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009023
9024 /* Request a slot reset */
9025 return PCI_ERS_RESULT_NEED_RESET;
9026}
9027
9028/**
9029 * i40e_pci_error_slot_reset - a PCI slot reset just happened
9030 * @pdev: PCI device information struct
9031 *
9032 * Called to find if the driver can work with the device now that
9033 * the pci slot has been reset. If a basic connection seems good
9034 * (registers are readable and have sane content) then return a
9035 * happy little PCI_ERS_RESULT_xxx.
9036 **/
9037static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
9038{
9039 struct i40e_pf *pf = pci_get_drvdata(pdev);
9040 pci_ers_result_t result;
9041 int err;
9042 u32 reg;
9043
9044 dev_info(&pdev->dev, "%s\n", __func__);
9045 if (pci_enable_device_mem(pdev)) {
9046 dev_info(&pdev->dev,
9047 "Cannot re-enable PCI device after reset.\n");
9048 result = PCI_ERS_RESULT_DISCONNECT;
9049 } else {
9050 pci_set_master(pdev);
9051 pci_restore_state(pdev);
9052 pci_save_state(pdev);
9053 pci_wake_from_d3(pdev, false);
9054
9055 reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
9056 if (reg == 0)
9057 result = PCI_ERS_RESULT_RECOVERED;
9058 else
9059 result = PCI_ERS_RESULT_DISCONNECT;
9060 }
9061
9062 err = pci_cleanup_aer_uncorrect_error_status(pdev);
9063 if (err) {
9064 dev_info(&pdev->dev,
9065 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
9066 err);
9067 /* non-fatal, continue */
9068 }
9069
9070 return result;
9071}
9072
9073/**
9074 * i40e_pci_error_resume - restart operations after PCI error recovery
9075 * @pdev: PCI device information struct
9076 *
9077 * Called to allow the driver to bring things back up after PCI error
9078 * and/or reset recovery has finished.
9079 **/
9080static void i40e_pci_error_resume(struct pci_dev *pdev)
9081{
9082 struct i40e_pf *pf = pci_get_drvdata(pdev);
9083
9084 dev_info(&pdev->dev, "%s\n", __func__);
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009085 if (test_bit(__I40E_SUSPENDED, &pf->state))
9086 return;
9087
9088 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009089 i40e_handle_reset_warning(pf);
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009090 rtnl_lock();
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009091}
9092
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009093/**
9094 * i40e_shutdown - PCI callback for shutting down
9095 * @pdev: PCI device information struct
9096 **/
9097static void i40e_shutdown(struct pci_dev *pdev)
9098{
9099 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +00009100 struct i40e_hw *hw = &pf->hw;
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009101
9102 set_bit(__I40E_SUSPENDED, &pf->state);
9103 set_bit(__I40E_DOWN, &pf->state);
9104 rtnl_lock();
9105 i40e_prep_for_reset(pf);
9106 rtnl_unlock();
9107
Shannon Nelson8e2773a2013-11-28 06:39:22 +00009108 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
9109 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
9110
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009111 if (system_state == SYSTEM_POWER_OFF) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00009112 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009113 pci_set_power_state(pdev, PCI_D3hot);
9114 }
9115}
9116
9117#ifdef CONFIG_PM
9118/**
9119 * i40e_suspend - PCI callback for moving to D3
9120 * @pdev: PCI device information struct
9121 **/
9122static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
9123{
9124 struct i40e_pf *pf = pci_get_drvdata(pdev);
Shannon Nelson8e2773a2013-11-28 06:39:22 +00009125 struct i40e_hw *hw = &pf->hw;
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009126
9127 set_bit(__I40E_SUSPENDED, &pf->state);
9128 set_bit(__I40E_DOWN, &pf->state);
9129 rtnl_lock();
9130 i40e_prep_for_reset(pf);
9131 rtnl_unlock();
9132
Shannon Nelson8e2773a2013-11-28 06:39:22 +00009133 wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
9134 wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
9135
9136 pci_wake_from_d3(pdev, pf->wol_en);
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009137 pci_set_power_state(pdev, PCI_D3hot);
9138
9139 return 0;
9140}
9141
9142/**
9143 * i40e_resume - PCI callback for waking up from D3
9144 * @pdev: PCI device information struct
9145 **/
9146static int i40e_resume(struct pci_dev *pdev)
9147{
9148 struct i40e_pf *pf = pci_get_drvdata(pdev);
9149 u32 err;
9150
9151 pci_set_power_state(pdev, PCI_D0);
9152 pci_restore_state(pdev);
9153 /* pci_restore_state() clears dev->state_saves, so
9154 * call pci_save_state() again to restore it.
9155 */
9156 pci_save_state(pdev);
9157
9158 err = pci_enable_device_mem(pdev);
9159 if (err) {
9160 dev_err(&pdev->dev,
9161 "%s: Cannot enable PCI device from suspend\n",
9162 __func__);
9163 return err;
9164 }
9165 pci_set_master(pdev);
9166
9167 /* no wakeup events while running */
9168 pci_wake_from_d3(pdev, false);
9169
9170 /* handling the reset will rebuild the device state */
9171 if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
9172 clear_bit(__I40E_DOWN, &pf->state);
9173 rtnl_lock();
9174 i40e_reset_and_rebuild(pf, false);
9175 rtnl_unlock();
9176 }
9177
9178 return 0;
9179}
9180
9181#endif
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009182static const struct pci_error_handlers i40e_err_handler = {
9183 .error_detected = i40e_pci_error_detected,
9184 .slot_reset = i40e_pci_error_slot_reset,
9185 .resume = i40e_pci_error_resume,
9186};
9187
9188static struct pci_driver i40e_driver = {
9189 .name = i40e_driver_name,
9190 .id_table = i40e_pci_tbl,
9191 .probe = i40e_probe,
9192 .remove = i40e_remove,
Shannon Nelson9007bcc2013-11-26 10:49:23 +00009193#ifdef CONFIG_PM
9194 .suspend = i40e_suspend,
9195 .resume = i40e_resume,
9196#endif
9197 .shutdown = i40e_shutdown,
Jesse Brandeburg41c445f2013-09-11 08:39:46 +00009198 .err_handler = &i40e_err_handler,
9199 .sriov_configure = i40e_pci_sriov_configure,
9200};
9201
9202/**
9203 * i40e_init_module - Driver registration routine
9204 *
9205 * i40e_init_module is the first routine called when the driver is
9206 * loaded. All it does is register with the PCI subsystem.
9207 **/
9208static int __init i40e_init_module(void)
9209{
9210 pr_info("%s: %s - version %s\n", i40e_driver_name,
9211 i40e_driver_string, i40e_driver_version_str);
9212 pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
9213 i40e_dbg_init();
9214 return pci_register_driver(&i40e_driver);
9215}
9216module_init(i40e_init_module);
9217
9218/**
9219 * i40e_exit_module - Driver exit cleanup routine
9220 *
9221 * i40e_exit_module is called just before the driver is removed
9222 * from memory.
9223 **/
9224static void __exit i40e_exit_module(void)
9225{
9226 pci_unregister_driver(&i40e_driver);
9227 i40e_dbg_exit();
9228}
9229module_exit(i40e_exit_module);