85de8179f42c55f8adef5719a0b050367ffbbae4
[dpdk.git] / lib / librte_eal / linuxapp / kni / ethtool / ixgbe / ixgbe_main.c
1 /*******************************************************************************
2
3   Intel 10 Gigabit PCI Express Linux driver
4   Copyright(c) 1999 - 2012 Intel Corporation.
5
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
15   You should have received a copy of the GNU General Public License along with
16   this program; if not, write to the Free Software Foundation, Inc.,
17   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19   The full GNU General Public License is included in this distribution in
20   the file called "COPYING".
21
22   Contact Information:
23   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26 *******************************************************************************/
27
28 /******************************************************************************
29  Copyright (c)2006 - 2007 Myricom, Inc. for some LRO specific code
30 ******************************************************************************/
31 #include <linux/types.h>
32 #include <linux/module.h>
33 #include <linux/pci.h>
34 #include <linux/netdevice.h>
35 #include <linux/vmalloc.h>
36 #include <linux/highmem.h>
37 #include <linux/string.h>
38 #include <linux/in.h>
39 #include <linux/ip.h>
40 #include <linux/tcp.h>
41 #ifdef HAVE_SCTP
42 #include <linux/sctp.h>
43 #endif
44 #include <linux/pkt_sched.h>
45 #include <linux/ipv6.h>
46 #ifdef NETIF_F_TSO
47 #include <net/checksum.h>
48 #ifdef NETIF_F_TSO6
49 #include <net/ip6_checksum.h>
50 #endif
51 #endif
52 #ifdef SIOCETHTOOL
53 #include <linux/ethtool.h>
54 #endif
55
56 #include "ixgbe.h"
57
58 #undef CONFIG_DCA
59 #undef CONFIG_DCA_MODULE
60
61 char ixgbe_driver_name[] = "ixgbe";
62 static const char ixgbe_driver_string[] =
63                               "Intel(R) 10 Gigabit PCI Express Network Driver";
64 #define DRV_HW_PERF
65
66 #ifndef CONFIG_IXGBE_NAPI
67 #define DRIVERNAPI
68 #else
69 #define DRIVERNAPI "-NAPI"
70 #endif
71
72 #define FPGA
73
74 #define VMDQ_TAG
75
76 #define MAJ 3
77 #define MIN 9
78 #define BUILD 17
79 #define DRV_VERSION     __stringify(MAJ) "." __stringify(MIN) "." \
80                         __stringify(BUILD) DRIVERNAPI DRV_HW_PERF FPGA VMDQ_TAG
81 const char ixgbe_driver_version[] = DRV_VERSION;
82 static const char ixgbe_copyright[] =
83                                 "Copyright (c) 1999-2012 Intel Corporation.";
84
85 /* ixgbe_pci_tbl - PCI Device ID Table
86  *
87  * Wildcard entries (PCI_ANY_ID) should come last
88  * Last entry must be all 0s
89  *
90  * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
91  *   Class, Class Mask, private data (not used) }
92  */
93 DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
94         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598)},
95         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT)},
96         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT)},
97         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT)},
98         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2)},
99         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4)},
100         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT)},
101         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT)},
102         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM)},
103         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR)},
104         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM)},
105         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX)},
106         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4)},
107         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM)},
108         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR)},
109         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP)},
110         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM)},
111         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ)},
112         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4)},
113         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE)},
114         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE)},
115         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM)},
116         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE)},
117         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T)},
118         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2)},
119         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS)},
120         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP)},
121         {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP)},
122         /* required last entry */
123         {0, }
124 };
125
126 #if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE)
127 static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
128                             void *p);
129 static struct notifier_block dca_notifier = {
130         .notifier_call  = ixgbe_notify_dca,
131         .next           = NULL,
132         .priority       = 0
133 };
134
135 #endif
136 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
137 MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
138 MODULE_LICENSE("GPL");
139 MODULE_VERSION(DRV_VERSION);
140
141 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
142
143
144 static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
145 {
146         u32 ctrl_ext;
147
148         /* Let firmware take over control of h/w */
149         ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
150         IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
151                         ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
152 }
153
154 #ifdef NO_VNIC
155 static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
156 {
157         u32 ctrl_ext;
158
159         /* Let firmware know the driver has taken over */
160         ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
161         IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
162                         ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
163 }
164 #endif
165
166
167 static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
168 {
169         struct ixgbe_hw *hw = &adapter->hw;
170         struct ixgbe_hw_stats *hwstats = &adapter->stats;
171         int i;
172         u32 data;
173
174         if ((hw->fc.current_mode != ixgbe_fc_full) &&
175             (hw->fc.current_mode != ixgbe_fc_rx_pause))
176                 return;
177
178         switch (hw->mac.type) {
179         case ixgbe_mac_82598EB:
180                 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
181                 break;
182         default:
183                 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
184         }
185         hwstats->lxoffrxc += data;
186
187         /* refill credits (no tx hang) if we received xoff */
188         if (!data)
189                 return;
190
191         for (i = 0; i < adapter->num_tx_queues; i++)
192                 clear_bit(__IXGBE_HANG_CHECK_ARMED,
193                           &adapter->tx_ring[i]->state);
194 }
195
196 static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
197 {
198         struct ixgbe_hw *hw = &adapter->hw;
199         struct ixgbe_hw_stats *hwstats = &adapter->stats;
200         u32 xoff[8] = {0};
201         int i;
202         bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
203
204 #ifdef HAVE_DCBNL_IEEE
205         if (adapter->ixgbe_ieee_pfc)
206                 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
207
208 #endif
209         if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
210                 ixgbe_update_xoff_rx_lfc(adapter);
211                 return;
212         }
213
214         /* update stats for each tc, only valid with PFC enabled */
215         for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
216                 switch (hw->mac.type) {
217                 case ixgbe_mac_82598EB:
218                         xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
219                         break;
220                 default:
221                         xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
222                 }
223                 hwstats->pxoffrxc[i] += xoff[i];
224         }
225
226         /* disarm tx queues that have received xoff frames */
227         for (i = 0; i < adapter->num_tx_queues; i++) {
228                 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
229                 u8 tc = tx_ring->dcb_tc;
230
231                 if ((tc <= 7) && (xoff[tc]))
232                         clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
233         }
234 }
235
236
237
238
239 #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
240
241
242
243
244 #ifdef HAVE_8021P_SUPPORT
245 /**
246  * ixgbe_vlan_stripping_disable - helper to disable vlan tag stripping
247  * @adapter: driver data
248  */
249 void ixgbe_vlan_stripping_disable(struct ixgbe_adapter *adapter)
250 {
251         struct ixgbe_hw *hw = &adapter->hw;
252         u32 vlnctrl;
253         int i;
254
255         /* leave vlan tag stripping enabled for DCB */
256         if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
257                 return;
258
259         switch (hw->mac.type) {
260         case ixgbe_mac_82598EB:
261                 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
262                 vlnctrl &= ~IXGBE_VLNCTRL_VME;
263                 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
264                 break;
265         case ixgbe_mac_82599EB:
266         case ixgbe_mac_X540:
267                 for (i = 0; i < adapter->num_rx_queues; i++) {
268                         u8 reg_idx = adapter->rx_ring[i]->reg_idx;
269                         vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
270                         vlnctrl &= ~IXGBE_RXDCTL_VME;
271                         IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), vlnctrl);
272                 }
273                 break;
274         default:
275                 break;
276         }
277 }
278
279 #endif
280 /**
281  * ixgbe_vlan_stripping_enable - helper to enable vlan tag stripping
282  * @adapter: driver data
283  */
284 void ixgbe_vlan_stripping_enable(struct ixgbe_adapter *adapter)
285 {
286         struct ixgbe_hw *hw = &adapter->hw;
287         u32 vlnctrl;
288         int i;
289
290         switch (hw->mac.type) {
291         case ixgbe_mac_82598EB:
292                 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
293                 vlnctrl |= IXGBE_VLNCTRL_VME;
294                 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
295                 break;
296         case ixgbe_mac_82599EB:
297         case ixgbe_mac_X540:
298                 for (i = 0; i < adapter->num_rx_queues; i++) {
299                         u8 reg_idx = adapter->rx_ring[i]->reg_idx;
300                         vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
301                         vlnctrl |= IXGBE_RXDCTL_VME;
302                         IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), vlnctrl);
303                 }
304                 break;
305         default:
306                 break;
307         }
308 }
309
310 #ifdef HAVE_VLAN_RX_REGISTER
311 void ixgbe_vlan_mode(struct net_device *netdev, struct vlan_group *grp)
312 #else
313 void ixgbe_vlan_mode(struct net_device *netdev, u32 features)
314 #endif
315 {
316         struct ixgbe_adapter *adapter = netdev_priv(netdev);
317 #ifdef HAVE_VLAN_RX_REGISTER
318
319         //if (!test_bit(__IXGBE_DOWN, &adapter->state))
320         //      ixgbe_irq_disable(adapter);
321
322         adapter->vlgrp = grp;
323
324         //if (!test_bit(__IXGBE_DOWN, &adapter->state))
325         //      ixgbe_irq_enable(adapter, true, true);
326 #endif
327 #ifdef HAVE_8021P_SUPPORT
328 #ifdef HAVE_VLAN_RX_REGISTER
329         bool enable = (grp || (adapter->flags & IXGBE_FLAG_DCB_ENABLED));
330 #else
331         bool enable = !!(features & NETIF_F_HW_VLAN_RX);
332 #endif
333         if (enable)
334                 /* enable VLAN tag insert/strip */
335                 ixgbe_vlan_stripping_enable(adapter);
336         else
337                 /* disable VLAN tag insert/strip */
338                 ixgbe_vlan_stripping_disable(adapter);
339
340 #endif
341 }
342
343 static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
344 {
345 #ifdef NETDEV_HW_ADDR_T_MULTICAST
346         struct netdev_hw_addr *mc_ptr;
347 #else
348         struct dev_mc_list *mc_ptr;
349 #endif
350         struct ixgbe_adapter *adapter = hw->back;
351         u8 *addr = *mc_addr_ptr;
352
353         *vmdq = adapter->num_vfs;
354
355 #ifdef NETDEV_HW_ADDR_T_MULTICAST
356         mc_ptr = container_of(addr, struct netdev_hw_addr, addr[0]);
357         if (mc_ptr->list.next) {
358                 struct netdev_hw_addr *ha;
359
360                 ha = list_entry(mc_ptr->list.next, struct netdev_hw_addr, list);
361                 *mc_addr_ptr = ha->addr;
362         }
363 #else
364         mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
365         if (mc_ptr->next)
366                 *mc_addr_ptr = mc_ptr->next->dmi_addr;
367 #endif
368         else
369                 *mc_addr_ptr = NULL;
370
371         return addr;
372 }
373
374 /**
375  * ixgbe_write_mc_addr_list - write multicast addresses to MTA
376  * @netdev: network interface device structure
377  *
378  * Writes multicast address list to the MTA hash table.
379  * Returns: -ENOMEM on failure
380  *                0 on no addresses written
381  *                X on writing X addresses to MTA
382  **/
383 int ixgbe_write_mc_addr_list(struct net_device *netdev)
384 {
385         struct ixgbe_adapter *adapter = netdev_priv(netdev);
386         struct ixgbe_hw *hw = &adapter->hw;
387 #ifdef NETDEV_HW_ADDR_T_MULTICAST
388         struct netdev_hw_addr *ha;
389 #endif
390         u8  *addr_list = NULL;
391         int addr_count = 0;
392
393         if (!hw->mac.ops.update_mc_addr_list)
394                 return -ENOMEM;
395
396         if (!netif_running(netdev))
397                 return 0;
398
399
400         hw->mac.ops.update_mc_addr_list(hw, NULL, 0,
401                                         ixgbe_addr_list_itr, true);
402
403         if (!netdev_mc_empty(netdev)) {
404 #ifdef NETDEV_HW_ADDR_T_MULTICAST
405                 ha = list_first_entry(&netdev->mc.list,
406                                       struct netdev_hw_addr, list);
407                 addr_list = ha->addr;
408 #else
409                 addr_list = netdev->mc_list->dmi_addr;
410 #endif
411                 addr_count = netdev_mc_count(netdev);
412
413                 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
414                                                 ixgbe_addr_list_itr, false);
415         }
416
417 #ifdef CONFIG_PCI_IOV
418         //ixgbe_restore_vf_multicasts(adapter);
419 #endif
420         return addr_count;
421 }
422
423
424 void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
425 {
426         struct ixgbe_hw *hw = &adapter->hw;
427         int i;
428         for (i = 0; i < hw->mac.num_rar_entries; i++) {
429                 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE) {
430                         hw->mac.ops.set_rar(hw, i, adapter->mac_table[i].addr,
431                                                 adapter->mac_table[i].queue,
432                                                 IXGBE_RAH_AV);
433                 } else {
434                         hw->mac.ops.clear_rar(hw, i);
435                 }
436         }
437 }
438
439 void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
440 {
441         struct ixgbe_hw *hw = &adapter->hw;
442         int i;
443         for (i = 0; i < hw->mac.num_rar_entries; i++) {
444                 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_MODIFIED) {
445                         if (adapter->mac_table[i].state &
446                                         IXGBE_MAC_STATE_IN_USE) {
447                                 hw->mac.ops.set_rar(hw, i,
448                                                 adapter->mac_table[i].addr,
449                                                 adapter->mac_table[i].queue,
450                                                 IXGBE_RAH_AV);
451                         } else {
452                                 hw->mac.ops.clear_rar(hw, i);
453                         }
454                         adapter->mac_table[i].state &=
455                                 ~(IXGBE_MAC_STATE_MODIFIED);
456                 }
457         }
458 }
459
460 int ixgbe_available_rars(struct ixgbe_adapter *adapter)
461 {
462         struct ixgbe_hw *hw = &adapter->hw;
463         int i, count = 0;
464
465         for (i = 0; i < hw->mac.num_rar_entries; i++) {
466                 if (adapter->mac_table[i].state == 0)
467                         count++;
468         }
469         return count;
470 }
471
472 int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue)
473 {
474         struct ixgbe_hw *hw = &adapter->hw;
475         int i;
476
477         if (is_zero_ether_addr(addr))
478                 return 0;
479
480         for (i = 0; i < hw->mac.num_rar_entries; i++) {
481                 if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE)
482                         continue;
483                 adapter->mac_table[i].state |= (IXGBE_MAC_STATE_MODIFIED |
484                                                 IXGBE_MAC_STATE_IN_USE);
485                 memcpy(adapter->mac_table[i].addr, addr, ETH_ALEN);
486                 adapter->mac_table[i].queue = queue;
487                 ixgbe_sync_mac_table(adapter);
488                 return i;
489         }
490         return -ENOMEM;
491 }
492
493 void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
494 {
495         int i;
496         struct ixgbe_hw *hw = &adapter->hw;
497
498         for (i = 0; i < hw->mac.num_rar_entries; i++) {
499                 adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
500                 adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
501                 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
502                 adapter->mac_table[i].queue = 0;
503         }
504         ixgbe_sync_mac_table(adapter);
505 }
506
507 void ixgbe_del_mac_filter_by_index(struct ixgbe_adapter *adapter, int index)
508 {
509         adapter->mac_table[index].state |= IXGBE_MAC_STATE_MODIFIED;
510         adapter->mac_table[index].state &= ~IXGBE_MAC_STATE_IN_USE;
511         memset(adapter->mac_table[index].addr, 0, ETH_ALEN);
512         adapter->mac_table[index].queue = 0;
513         ixgbe_sync_mac_table(adapter);
514 }
515
516 int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, u8* addr, u16 queue)
517 {
518         /* search table for addr, if found, set to 0 and sync */
519         int i;
520         struct ixgbe_hw *hw = &adapter->hw;
521
522         if (is_zero_ether_addr(addr))
523                 return 0;
524         for (i = 0; i < hw->mac.num_rar_entries; i++) {
525                 if (!compare_ether_addr(addr, adapter->mac_table[i].addr) &&
526                     adapter->mac_table[i].queue == queue) {
527                         adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
528                         adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
529                         memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
530                         adapter->mac_table[i].queue = 0;
531                         ixgbe_sync_mac_table(adapter);
532                         return 0;
533                 }
534         }
535         return -ENOMEM;
536 }
537 #ifdef HAVE_SET_RX_MODE
538 /**
539  * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
540  * @netdev: network interface device structure
541  *
542  * Writes unicast address list to the RAR table.
543  * Returns: -ENOMEM on failure/insufficient address space
544  *                0 on no addresses written
545  *                X on writing X addresses to the RAR table
546  **/
547 int ixgbe_write_uc_addr_list(struct ixgbe_adapter *adapter,
548                              struct net_device *netdev, unsigned int vfn)
549 {
550         int count = 0;
551
552         /* return ENOMEM indicating insufficient memory for addresses */
553         if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter))
554                 return -ENOMEM;
555
556         if (!netdev_uc_empty(netdev)) {
557 #ifdef NETDEV_HW_ADDR_T_UNICAST
558                 struct netdev_hw_addr *ha;
559 #else
560                 struct dev_mc_list *ha;
561 #endif
562                 netdev_for_each_uc_addr(ha, netdev) {
563 #ifdef NETDEV_HW_ADDR_T_UNICAST
564                         ixgbe_del_mac_filter(adapter, ha->addr, (u16)vfn);
565                         ixgbe_add_mac_filter(adapter, ha->addr, (u16)vfn);
566 #else
567                         ixgbe_del_mac_filter(adapter, ha->da_addr, (u16)vfn);
568                         ixgbe_add_mac_filter(adapter, ha->da_addr, (u16)vfn);
569 #endif
570                         count++;
571                 }
572         }
573         return count;
574 }
575
576 #endif
577 /**
578  * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
579  * @netdev: network interface device structure
580  *
581  * The set_rx_method entry point is called whenever the unicast/multicast
582  * address list or the network interface flags are updated.  This routine is
583  * responsible for configuring the hardware for proper unicast, multicast and
584  * promiscuous mode.
585  **/
586 void ixgbe_set_rx_mode(struct net_device *netdev)
587 {
588         struct ixgbe_adapter *adapter = netdev_priv(netdev);
589         struct ixgbe_hw *hw = &adapter->hw;
590         u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
591         u32 vlnctrl;
592         int count;
593
594         /* Check for Promiscuous and All Multicast modes */
595         fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
596         vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
597
598         /* set all bits that we expect to always be set */
599         fctrl |= IXGBE_FCTRL_BAM;
600         fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
601         fctrl |= IXGBE_FCTRL_PMCF;
602
603         /* clear the bits we are changing the status of */
604         fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
605         vlnctrl  &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
606
607         if (netdev->flags & IFF_PROMISC) {
608                 hw->addr_ctrl.user_set_promisc = true;
609                 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
610                 vmolr |= IXGBE_VMOLR_MPE;
611         } else {
612                 if (netdev->flags & IFF_ALLMULTI) {
613                         fctrl |= IXGBE_FCTRL_MPE;
614                         vmolr |= IXGBE_VMOLR_MPE;
615                 } else {
616                         /*
617                          * Write addresses to the MTA, if the attempt fails
618                          * then we should just turn on promiscuous mode so
619                          * that we can at least receive multicast traffic
620                          */
621                         count = ixgbe_write_mc_addr_list(netdev);
622                         if (count < 0) {
623                                 fctrl |= IXGBE_FCTRL_MPE;
624                                 vmolr |= IXGBE_VMOLR_MPE;
625                         } else if (count) {
626                                 vmolr |= IXGBE_VMOLR_ROMPE;
627                         }
628                 }
629 #ifdef NETIF_F_HW_VLAN_TX
630                 /* enable hardware vlan filtering */
631                 vlnctrl |= IXGBE_VLNCTRL_VFE;
632 #endif
633                 hw->addr_ctrl.user_set_promisc = false;
634 #ifdef HAVE_SET_RX_MODE
635                 /*
636                  * Write addresses to available RAR registers, if there is not
637                  * sufficient space to store all the addresses then enable
638                  * unicast promiscuous mode
639                  */
640                 count = ixgbe_write_uc_addr_list(adapter, netdev,
641                                                  adapter->num_vfs);
642                 if (count < 0) {
643                         fctrl |= IXGBE_FCTRL_UPE;
644                         vmolr |= IXGBE_VMOLR_ROPE;
645                 }
646 #endif
647         }
648
649         if (hw->mac.type != ixgbe_mac_82598EB) {
650                 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
651                          ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
652                            IXGBE_VMOLR_ROPE);
653                 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
654         }
655
656         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
657         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
658 }
659
660
661
662
663
664
665
666
667 /* Additional bittime to account for IXGBE framing */
668 #define IXGBE_ETH_FRAMING 20
669
670 /*
671  * ixgbe_hpbthresh - calculate high water mark for flow control
672  *
673  * @adapter: board private structure to calculate for
674  * @pb - packet buffer to calculate
675  */
676 static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
677 {
678         struct ixgbe_hw *hw = &adapter->hw;
679         struct net_device *dev = adapter->netdev;
680         int link, tc, kb, marker;
681         u32 dv_id, rx_pba;
682
683         /* Calculate max LAN frame size */
684         tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
685
686 #ifdef IXGBE_FCOE
687         /* FCoE traffic class uses FCOE jumbo frames */
688         if (dev->features & NETIF_F_FCOE_MTU) {
689                 int fcoe_pb = 0;
690
691                 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
692
693                 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
694                         tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
695         }
696 #endif
697
698         /* Calculate delay value for device */
699         switch (hw->mac.type) {
700         case ixgbe_mac_X540:
701                 dv_id = IXGBE_DV_X540(link, tc);
702                 break;
703         default:
704                 dv_id = IXGBE_DV(link, tc);
705                 break;
706         }
707
708         /* Loopback switch introduces additional latency */
709         if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
710                 dv_id += IXGBE_B2BT(tc);
711
712         /* Delay value is calculated in bit times convert to KB */
713         kb = IXGBE_BT2KB(dv_id);
714         rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
715
716         marker = rx_pba - kb;
717
718         /* It is possible that the packet buffer is not large enough
719          * to provide required headroom. In this case throw an error
720          * to user and a do the best we can.
721          */
722         if (marker < 0) {
723                 e_warn(drv, "Packet Buffer(%i) can not provide enough"
724                             "headroom to suppport flow control."
725                             "Decrease MTU or number of traffic classes\n", pb);
726                 marker = tc + 1;
727         }
728
729         return marker;
730 }
731
732 /*
733  * ixgbe_lpbthresh - calculate low water mark for for flow control
734  *
735  * @adapter: board private structure to calculate for
736  * @pb - packet buffer to calculate
737  */
738 static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
739 {
740         struct ixgbe_hw *hw = &adapter->hw;
741         struct net_device *dev = adapter->netdev;
742         int tc;
743         u32 dv_id;
744
745         /* Calculate max LAN frame size */
746         tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
747
748 #ifdef IXGBE_FCOE
749         /* FCoE traffic class uses FCOE jumbo frames */
750         if (dev->features & NETIF_F_FCOE_MTU) {
751                 int fcoe_pb = 0;
752
753                 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
754
755                 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
756                         tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
757         }
758 #endif
759
760         /* Calculate delay value for device */
761         switch (hw->mac.type) {
762         case ixgbe_mac_X540:
763                 dv_id = IXGBE_LOW_DV_X540(tc);
764                 break;
765         default:
766                 dv_id = IXGBE_LOW_DV(tc);
767                 break;
768         }
769
770         /* Delay value is calculated in bit times convert to KB */
771         return IXGBE_BT2KB(dv_id);
772 }
773
774 /*
775  * ixgbe_pbthresh_setup - calculate and setup high low water marks
776  */
777 static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
778 {
779         struct ixgbe_hw *hw = &adapter->hw;
780         int num_tc = netdev_get_num_tc(adapter->netdev);
781         int i;
782
783         if (!num_tc)
784                 num_tc = 1;
785         if (num_tc > IXGBE_DCB_MAX_TRAFFIC_CLASS)
786                 num_tc = IXGBE_DCB_MAX_TRAFFIC_CLASS;
787
788         for (i = 0; i < num_tc; i++) {
789                 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
790                 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
791
792                 /* Low water marks must not be larger than high water marks */
793                 if (hw->fc.low_water[i] > hw->fc.high_water[i])
794                         hw->fc.low_water[i] = 0;
795         }
796
797         for (; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++)
798                 hw->fc.high_water[i] = 0;
799 }
800
801
802
803 #ifdef NO_VNIC
804 static void ixgbe_configure(struct ixgbe_adapter *adapter)
805 {
806         struct ixgbe_hw *hw = &adapter->hw;
807
808         ixgbe_configure_pb(adapter);
809         ixgbe_configure_dcb(adapter);
810
811         ixgbe_set_rx_mode(adapter->netdev);
812 #ifdef NETIF_F_HW_VLAN_TX
813         ixgbe_restore_vlan(adapter);
814 #endif
815
816 #ifdef IXGBE_FCOE
817         if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
818                 ixgbe_configure_fcoe(adapter);
819
820 #endif /* IXGBE_FCOE */
821
822         if (adapter->hw.mac.type != ixgbe_mac_82598EB)
823                 hw->mac.ops.disable_sec_rx_path(hw);
824
825         if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
826                 ixgbe_init_fdir_signature_82599(&adapter->hw,
827                                                 adapter->fdir_pballoc);
828         } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
829                 ixgbe_init_fdir_perfect_82599(&adapter->hw,
830                                               adapter->fdir_pballoc);
831                 ixgbe_fdir_filter_restore(adapter);
832         }
833
834         if (adapter->hw.mac.type != ixgbe_mac_82598EB)
835                 hw->mac.ops.enable_sec_rx_path(hw);
836
837         ixgbe_configure_virtualization(adapter);
838
839         ixgbe_configure_tx(adapter);
840         ixgbe_configure_rx(adapter);
841 }
842 #endif
843
844 static bool ixgbe_is_sfp(struct ixgbe_hw *hw)
845 {
846         switch (hw->phy.type) {
847         case ixgbe_phy_sfp_avago:
848         case ixgbe_phy_sfp_ftl:
849         case ixgbe_phy_sfp_intel:
850         case ixgbe_phy_sfp_unknown:
851         case ixgbe_phy_sfp_passive_tyco:
852         case ixgbe_phy_sfp_passive_unknown:
853         case ixgbe_phy_sfp_active_unknown:
854         case ixgbe_phy_sfp_ftl_active:
855                 return true;
856         case ixgbe_phy_nl:
857                 if (hw->mac.type == ixgbe_mac_82598EB)
858                         return true;
859         default:
860                 return false;
861         }
862 }
863
864
865 /**
866  * ixgbe_clear_vf_stats_counters - Clear out VF stats after reset
867  * @adapter: board private structure
868  *
869  * On a reset we need to clear out the VF stats or accounting gets
870  * messed up because they're not clear on read.
871  **/
872 void ixgbe_clear_vf_stats_counters(struct ixgbe_adapter *adapter)
873 {
874         struct ixgbe_hw *hw = &adapter->hw;
875         int i;
876
877         for (i = 0; i < adapter->num_vfs; i++) {
878                 adapter->vfinfo[i].last_vfstats.gprc =
879                         IXGBE_READ_REG(hw, IXGBE_PVFGPRC(i));
880                 adapter->vfinfo[i].saved_rst_vfstats.gprc +=
881                         adapter->vfinfo[i].vfstats.gprc;
882                 adapter->vfinfo[i].vfstats.gprc = 0;
883                 adapter->vfinfo[i].last_vfstats.gptc =
884                         IXGBE_READ_REG(hw, IXGBE_PVFGPTC(i));
885                 adapter->vfinfo[i].saved_rst_vfstats.gptc +=
886                         adapter->vfinfo[i].vfstats.gptc;
887                 adapter->vfinfo[i].vfstats.gptc = 0;
888                 adapter->vfinfo[i].last_vfstats.gorc =
889                         IXGBE_READ_REG(hw, IXGBE_PVFGORC_LSB(i));
890                 adapter->vfinfo[i].saved_rst_vfstats.gorc +=
891                         adapter->vfinfo[i].vfstats.gorc;
892                 adapter->vfinfo[i].vfstats.gorc = 0;
893                 adapter->vfinfo[i].last_vfstats.gotc =
894                         IXGBE_READ_REG(hw, IXGBE_PVFGOTC_LSB(i));
895                 adapter->vfinfo[i].saved_rst_vfstats.gotc +=
896                         adapter->vfinfo[i].vfstats.gotc;
897                 adapter->vfinfo[i].vfstats.gotc = 0;
898                 adapter->vfinfo[i].last_vfstats.mprc =
899                         IXGBE_READ_REG(hw, IXGBE_PVFMPRC(i));
900                 adapter->vfinfo[i].saved_rst_vfstats.mprc +=
901                         adapter->vfinfo[i].vfstats.mprc;
902                 adapter->vfinfo[i].vfstats.mprc = 0;
903         }
904 }
905
906
907
908 void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
909 {
910 #ifdef NO_VNIC
911         WARN_ON(in_interrupt());
912         /* put off any impending NetWatchDogTimeout */
913         adapter->netdev->trans_start = jiffies;
914
915         while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
916                 usleep_range(1000, 2000);
917         ixgbe_down(adapter);
918         /*
919          * If SR-IOV enabled then wait a bit before bringing the adapter
920          * back up to give the VFs time to respond to the reset.  The
921          * two second wait is based upon the watchdog timer cycle in
922          * the VF driver.
923          */
924         if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
925                 msleep(2000);
926         ixgbe_up(adapter);
927         clear_bit(__IXGBE_RESETTING, &adapter->state);
928 #endif
929 }
930
931 void ixgbe_up(struct ixgbe_adapter *adapter)
932 {
933         /* hardware has been reset, we need to reload some things */
934         //ixgbe_configure(adapter);
935
936         //ixgbe_up_complete(adapter);
937 }
938
939 void ixgbe_reset(struct ixgbe_adapter *adapter)
940 {
941         struct ixgbe_hw *hw = &adapter->hw;
942         struct net_device *netdev = adapter->netdev;
943         int err;
944
945         /* lock SFP init bit to prevent race conditions with the watchdog */
946         while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
947                 usleep_range(1000, 2000);
948
949         /* clear all SFP and link config related flags while holding SFP_INIT */
950         adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
951                              IXGBE_FLAG2_SFP_NEEDS_RESET);
952         adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
953
954         err = hw->mac.ops.init_hw(hw);
955         switch (err) {
956         case 0:
957         case IXGBE_ERR_SFP_NOT_PRESENT:
958         case IXGBE_ERR_SFP_NOT_SUPPORTED:
959                 break;
960         case IXGBE_ERR_MASTER_REQUESTS_PENDING:
961                 e_dev_err("master disable timed out\n");
962                 break;
963         case IXGBE_ERR_EEPROM_VERSION:
964                 /* We are running on a pre-production device, log a warning */
965                 e_dev_warn("This device is a pre-production adapter/LOM. "
966                            "Please be aware there may be issues associated "
967                            "with your hardware.  If you are experiencing "
968                            "problems please contact your Intel or hardware "
969                            "representative who provided you with this "
970                            "hardware.\n");
971                 break;
972         default:
973                 e_dev_err("Hardware Error: %d\n", err);
974         }
975
976         clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
977
978         ixgbe_flush_sw_mac_table(adapter);
979         memcpy(&adapter->mac_table[0].addr, hw->mac.perm_addr,
980                netdev->addr_len);
981         adapter->mac_table[0].queue = adapter->num_vfs;
982         adapter->mac_table[0].state = (IXGBE_MAC_STATE_DEFAULT |
983                                         IXGBE_MAC_STATE_IN_USE);
984         hw->mac.ops.set_rar(hw, 0, adapter->mac_table[0].addr,
985                                 adapter->mac_table[0].queue,
986                                 IXGBE_RAH_AV);
987 }
988
989
990
991
992
993
994 void ixgbe_down(struct ixgbe_adapter *adapter)
995 {
996 #ifdef NO_VNIC
997         struct net_device *netdev = adapter->netdev;
998         struct ixgbe_hw *hw = &adapter->hw;
999         u32 rxctrl;
1000         int i;
1001
1002         /* signal that we are down to the interrupt handler */
1003         set_bit(__IXGBE_DOWN, &adapter->state);
1004
1005         /* disable receives */
1006         rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1007         IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1008
1009         /* disable all enabled rx queues */
1010         for (i = 0; i < adapter->num_rx_queues; i++)
1011                 /* this call also flushes the previous write */
1012                 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
1013
1014         usleep_range(10000, 20000);
1015
1016         netif_tx_stop_all_queues(netdev);
1017
1018         /* call carrier off first to avoid false dev_watchdog timeouts */
1019         netif_carrier_off(netdev);
1020         netif_tx_disable(netdev);
1021
1022         ixgbe_irq_disable(adapter);
1023
1024         ixgbe_napi_disable_all(adapter);
1025
1026         adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
1027                              IXGBE_FLAG2_RESET_REQUESTED);
1028         adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
1029
1030         del_timer_sync(&adapter->service_timer);
1031
1032         if (adapter->num_vfs) {
1033                 /* Clear EITR Select mapping */
1034                 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
1035
1036                 /* Mark all the VFs as inactive */
1037                 for (i = 0 ; i < adapter->num_vfs; i++)
1038                         adapter->vfinfo[i].clear_to_send = 0;
1039
1040                 /* ping all the active vfs to let them know we are going down */
1041                 ixgbe_ping_all_vfs(adapter);
1042
1043                 /* Disable all VFTE/VFRE TX/RX */
1044                 ixgbe_disable_tx_rx(adapter);
1045         }
1046
1047         /* disable transmits in the hardware now that interrupts are off */
1048         for (i = 0; i < adapter->num_tx_queues; i++) {
1049                 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
1050                 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
1051         }
1052
1053         /* Disable the Tx DMA engine on 82599 and X540 */
1054         switch (hw->mac.type) {
1055         case ixgbe_mac_82599EB:
1056         case ixgbe_mac_X540:
1057                 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
1058                                 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
1059                                  ~IXGBE_DMATXCTL_TE));
1060                 break;
1061         default:
1062                 break;
1063         }
1064
1065 #ifdef HAVE_PCI_ERS
1066         if (!pci_channel_offline(adapter->pdev))
1067 #endif
1068                 ixgbe_reset(adapter);
1069         /* power down the optics */
1070         if ((hw->phy.multispeed_fiber) ||
1071             ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
1072              (hw->mac.type == ixgbe_mac_82599EB)))
1073                 ixgbe_disable_tx_laser(hw);
1074
1075         ixgbe_clean_all_tx_rings(adapter);
1076         ixgbe_clean_all_rx_rings(adapter);
1077
1078 #if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE)
1079         /* since we reset the hardware DCA settings were cleared */
1080         ixgbe_setup_dca(adapter);
1081 #endif
1082
1083 #endif /* NO_VNIC */
1084 }
1085
1086 #ifndef NO_VNIC
1087
1088 #undef IXGBE_FCOE
1089
1090 /* Artificial max queue cap per traffic class in DCB mode */
1091 #define DCB_QUEUE_CAP 8
1092
1093 /**
1094  * ixgbe_set_dcb_queues: Allocate queues for a DCB-enabled device
1095  * @adapter: board private structure to initialize
1096  *
1097  * When DCB (Data Center Bridging) is enabled, allocate queues for
1098  * each traffic class.  If multiqueue isn't available,then abort DCB
1099  * initialization.
1100  *
1101  * This function handles all combinations of DCB, RSS, and FCoE.
1102  *
1103  **/
1104 static bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
1105 {
1106        int tcs;
1107 #ifdef HAVE_MQPRIO
1108        int rss_i, i, offset = 0;
1109        struct net_device *dev = adapter->netdev;
1110
1111        /* Map queue offset and counts onto allocated tx queues */
1112        tcs = netdev_get_num_tc(dev);
1113
1114        if (!tcs)
1115               return false;
1116
1117        rss_i = min_t(int, dev->num_tx_queues / tcs, num_online_cpus());
1118
1119        if (rss_i > DCB_QUEUE_CAP)
1120               rss_i = DCB_QUEUE_CAP;
1121
1122        for (i = 0; i < tcs; i++) {
1123               netdev_set_tc_queue(dev, i, rss_i, offset);
1124               offset += rss_i;
1125        }
1126
1127        adapter->num_tx_queues = rss_i * tcs;
1128        adapter->num_rx_queues = rss_i * tcs;
1129
1130 #ifdef IXGBE_FCOE
1131        /* FCoE enabled queues require special configuration indexed
1132         * by feature specific indices and mask. Here we map FCoE
1133         * indices onto the DCB queue pairs allowing FCoE to own
1134         * configuration later.
1135         */
1136
1137        if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1138               struct ixgbe_ring_feature *f;
1139               int tc;
1140               u8 prio_tc[IXGBE_DCB_MAX_USER_PRIORITY] = {0};
1141
1142               ixgbe_dcb_unpack_map_cee(&adapter->dcb_cfg,
1143                                     IXGBE_DCB_TX_CONFIG,
1144                                     prio_tc);
1145               tc = prio_tc[adapter->fcoe.up];
1146
1147               f = &adapter->ring_feature[RING_F_FCOE];
1148               f->indices = min_t(int, rss_i, f->indices);
1149               f->mask = rss_i * tc;
1150        }
1151 #endif /* IXGBE_FCOE */
1152 #else
1153        if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
1154               return false;
1155
1156        /* Enable one Queue per traffic class */
1157        tcs = adapter->tc;
1158        if (!tcs)
1159               return false;
1160
1161 #ifdef IXGBE_FCOE
1162        if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1163               struct ixgbe_ring_feature *f;
1164               int tc = netdev_get_prio_tc_map(adapter->netdev,
1165                                           adapter->fcoe.up);
1166
1167               f = &adapter->ring_feature[RING_F_FCOE];
1168
1169               /*
1170                * We have max 8 queues for FCoE, where 8 the is
1171                * FCoE redirection table size.  We must also share
1172                * ring resources with network traffic so if FCoE TC is
1173                * 4 or greater and we are in 8 TC mode we can only use
1174                * 7 queues.
1175                */
1176               if ((tcs > 4) && (tc >= 4) && (f->indices > 7))
1177                      f->indices = 7;
1178
1179               f->indices = min_t(int, num_online_cpus(), f->indices);
1180               f->mask = tcs;
1181
1182               adapter->num_rx_queues = f->indices + tcs;
1183               adapter->num_tx_queues = f->indices + tcs;
1184
1185               return true;
1186        }
1187
1188 #endif /* IXGBE_FCOE */
1189        adapter->num_rx_queues = tcs;
1190        adapter->num_tx_queues = tcs;
1191 #endif /* HAVE_MQ */
1192
1193        return true;
1194 }
1195
1196 /**
1197  * ixgbe_set_vmdq_queues: Allocate queues for VMDq devices
1198  * @adapter: board private structure to initialize
1199  *
1200  * When VMDq (Virtual Machine Devices queue) is enabled, allocate queues
1201  * and VM pools where appropriate.  If RSS is available, then also try and
1202  * enable RSS and map accordingly.
1203  *
1204  **/
1205 static bool ixgbe_set_vmdq_queues(struct ixgbe_adapter *adapter)
1206 {
1207        int vmdq_i = adapter->ring_feature[RING_F_VMDQ].indices;
1208        int vmdq_m = 0;
1209        int rss_i = adapter->ring_feature[RING_F_RSS].indices;
1210        unsigned long i;
1211        int rss_shift;
1212        bool ret = false;
1213
1214
1215        switch (adapter->flags & (IXGBE_FLAG_RSS_ENABLED
1216                                | IXGBE_FLAG_DCB_ENABLED
1217                                | IXGBE_FLAG_VMDQ_ENABLED)) {
1218
1219        case (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_VMDQ_ENABLED):
1220               switch (adapter->hw.mac.type) {
1221               case ixgbe_mac_82599EB:
1222               case ixgbe_mac_X540:
1223                      vmdq_i = min((int)IXGBE_MAX_VMDQ_INDICES, vmdq_i);
1224                      if (vmdq_i > 32)
1225                             rss_i = 2;
1226                      else
1227                             rss_i = 4;
1228                      i = rss_i;
1229                      rss_shift = find_first_bit(&i, sizeof(i) * 8);
1230                      vmdq_m = ((IXGBE_MAX_VMDQ_INDICES - 1) <<
1231                                rss_shift) & (MAX_RX_QUEUES - 1);
1232                      break;
1233               default:
1234                      break;
1235               }
1236               adapter->num_rx_queues = vmdq_i * rss_i;
1237               adapter->num_tx_queues = min((int)MAX_TX_QUEUES, vmdq_i * rss_i);
1238               ret = true;
1239               break;
1240
1241        case (IXGBE_FLAG_VMDQ_ENABLED):
1242               switch (adapter->hw.mac.type) {
1243               case ixgbe_mac_82598EB:
1244                      vmdq_m = (IXGBE_MAX_VMDQ_INDICES - 1);
1245                      break;
1246               case ixgbe_mac_82599EB:
1247               case ixgbe_mac_X540:
1248                      vmdq_m = (IXGBE_MAX_VMDQ_INDICES - 1) << 1;
1249                      break;
1250               default:
1251                      break;
1252               }
1253               adapter->num_rx_queues = vmdq_i;
1254               adapter->num_tx_queues = vmdq_i;
1255               ret = true;
1256               break;
1257
1258        default:
1259               ret = false;
1260               goto vmdq_queues_out;
1261        }
1262
1263        if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
1264               adapter->num_rx_pools = vmdq_i;
1265               adapter->num_rx_queues_per_pool = adapter->num_rx_queues /
1266                                             vmdq_i;
1267        } else {
1268               adapter->num_rx_pools = adapter->num_rx_queues;
1269               adapter->num_rx_queues_per_pool = 1;
1270        }
1271        /* save the mask for later use */
1272        adapter->ring_feature[RING_F_VMDQ].mask = vmdq_m;
1273 vmdq_queues_out:
1274        return ret;
1275 }
1276
1277 /**
1278  * ixgbe_set_rss_queues: Allocate queues for RSS
1279  * @adapter: board private structure to initialize
1280  *
1281  * This is our "base" multiqueue mode.  RSS (Receive Side Scaling) will try
1282  * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
1283  *
1284  **/
1285 static bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
1286 {
1287        struct ixgbe_ring_feature *f;
1288
1289        if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
1290               adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
1291               return false;
1292        }
1293
1294        /* set mask for 16 queue limit of RSS */
1295        f = &adapter->ring_feature[RING_F_RSS];
1296        f->mask = 0xF;
1297
1298        /*
1299         * Use Flow Director in addition to RSS to ensure the best
1300         * distribution of flows across cores, even when an FDIR flow
1301         * isn't matched.
1302         */
1303        if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
1304               f = &adapter->ring_feature[RING_F_FDIR];
1305
1306               f->indices = min_t(int, num_online_cpus(), f->indices);
1307               f->mask = 0;
1308        }
1309
1310        adapter->num_rx_queues = f->indices;
1311 #ifdef HAVE_TX_MQ
1312        adapter->num_tx_queues = f->indices;
1313 #endif
1314
1315        return true;
1316 }
1317
1318 #ifdef IXGBE_FCOE
1319 /**
1320  * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
1321  * @adapter: board private structure to initialize
1322  *
1323  * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
1324  * The ring feature mask is not used as a mask for FCoE, as it can take any 8
1325  * rx queues out of the max number of rx queues, instead, it is used as the
1326  * index of the first rx queue used by FCoE.
1327  *
1328  **/
1329 static bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
1330 {
1331        struct ixgbe_ring_feature *f;
1332
1333        if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
1334               return false;
1335
1336        ixgbe_set_rss_queues(adapter);
1337
1338        f = &adapter->ring_feature[RING_F_FCOE];
1339        f->indices = min_t(int, num_online_cpus(), f->indices);
1340
1341        /* adding FCoE queues */
1342        f->mask = adapter->num_rx_queues;
1343        adapter->num_rx_queues += f->indices;
1344        adapter->num_tx_queues += f->indices;
1345
1346        return true;
1347 }
1348
1349 #endif /* IXGBE_FCOE */
1350 /*
1351  * ixgbe_set_num_queues: Allocate queues for device, feature dependent
1352  * @adapter: board private structure to initialize
1353  *
1354  * This is the top level queue allocation routine.  The order here is very
1355  * important, starting with the "most" number of features turned on at once,
1356  * and ending with the smallest set of features.  This way large combinations
1357  * can be allocated if they're turned on, and smaller combinations are the
1358  * fallthrough conditions.
1359  *
1360  **/
1361 static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
1362 {
1363        /* Start with base case */
1364        adapter->num_rx_queues = 1;
1365        adapter->num_tx_queues = 1;
1366        adapter->num_rx_pools = adapter->num_rx_queues;
1367        adapter->num_rx_queues_per_pool = 1;
1368
1369        if (ixgbe_set_vmdq_queues(adapter))
1370               return;
1371
1372        if (ixgbe_set_dcb_queues(adapter))
1373               return;
1374
1375 #ifdef IXGBE_FCOE
1376        if (ixgbe_set_fcoe_queues(adapter))
1377               return;
1378
1379 #endif /* IXGBE_FCOE */
1380        ixgbe_set_rss_queues(adapter);
1381 }
1382
1383 #endif
1384
1385
1386 /**
1387  * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
1388  * @adapter: board private structure to initialize
1389  *
1390  * ixgbe_sw_init initializes the Adapter private data structure.
1391  * Fields are initialized based on PCI device information and
1392  * OS network device settings (MTU size).
1393  **/
1394 static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
1395 {
1396         struct ixgbe_hw *hw = &adapter->hw;
1397         struct pci_dev *pdev = adapter->pdev;
1398         int err;
1399
1400         /* PCI config space info */
1401
1402         hw->vendor_id = pdev->vendor;
1403         hw->device_id = pdev->device;
1404         pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
1405         hw->subsystem_vendor_id = pdev->subsystem_vendor;
1406         hw->subsystem_device_id = pdev->subsystem_device;
1407
1408         err = ixgbe_init_shared_code(hw);
1409         if (err) {
1410                 e_err(probe, "init_shared_code failed: %d\n", err);
1411                 goto out;
1412         }
1413         adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
1414                                      hw->mac.num_rar_entries,
1415                                      GFP_ATOMIC);
1416         /* Set capability flags */
1417         switch (hw->mac.type) {
1418         case ixgbe_mac_82598EB:
1419                 adapter->flags |= IXGBE_FLAG_MSI_CAPABLE |
1420                                   IXGBE_FLAG_MSIX_CAPABLE |
1421                                   IXGBE_FLAG_MQ_CAPABLE |
1422                                   IXGBE_FLAG_RSS_CAPABLE;
1423                 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
1424 #if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE)
1425                 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
1426 #endif
1427                 adapter->flags &= ~IXGBE_FLAG_SRIOV_CAPABLE;
1428                 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
1429
1430                 if (hw->device_id == IXGBE_DEV_ID_82598AT)
1431                         adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
1432
1433                 adapter->max_msix_q_vectors = IXGBE_MAX_MSIX_Q_VECTORS_82598;
1434                 break;
1435         case ixgbe_mac_X540:
1436                 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
1437         case ixgbe_mac_82599EB:
1438                 adapter->flags |= IXGBE_FLAG_MSI_CAPABLE |
1439                                   IXGBE_FLAG_MSIX_CAPABLE |
1440                                   IXGBE_FLAG_MQ_CAPABLE |
1441                                   IXGBE_FLAG_RSS_CAPABLE;
1442                 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
1443 #if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE)
1444                 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
1445 #endif
1446                 adapter->flags |= IXGBE_FLAG_SRIOV_CAPABLE;
1447                 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
1448 #ifdef IXGBE_FCOE
1449                 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
1450                 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
1451                 adapter->ring_feature[RING_F_FCOE].indices = 0;
1452 #ifdef CONFIG_DCB
1453                 /* Default traffic class to use for FCoE */
1454                 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
1455                 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
1456                 adapter->fcoe.up_set = IXGBE_FCOE_DEFTC;
1457 #endif
1458 #endif
1459                 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
1460                         adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
1461 #ifndef IXGBE_NO_SMART_SPEED
1462                 hw->phy.smart_speed = ixgbe_smart_speed_on;
1463 #else
1464                 hw->phy.smart_speed = ixgbe_smart_speed_off;
1465 #endif
1466                 adapter->max_msix_q_vectors = IXGBE_MAX_MSIX_Q_VECTORS_82599;
1467         default:
1468                 break;
1469         }
1470
1471         /* n-tuple support exists, always init our spinlock */
1472         //spin_lock_init(&adapter->fdir_perfect_lock);
1473
1474         if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE) {
1475                 int j;
1476                 struct ixgbe_dcb_tc_config *tc;
1477                 int dcb_i = IXGBE_DCB_MAX_TRAFFIC_CLASS;
1478
1479
1480                 adapter->dcb_cfg.num_tcs.pg_tcs = dcb_i;
1481                 adapter->dcb_cfg.num_tcs.pfc_tcs = dcb_i;
1482                 for (j = 0; j < dcb_i; j++) {
1483                         tc = &adapter->dcb_cfg.tc_config[j];
1484                         tc->path[IXGBE_DCB_TX_CONFIG].bwg_id = 0;
1485                         tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent = 100 / dcb_i;
1486                         tc->path[IXGBE_DCB_RX_CONFIG].bwg_id = 0;
1487                         tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent = 100 / dcb_i;
1488                         tc->pfc = ixgbe_dcb_pfc_disabled;
1489                         if (j == 0) {
1490                                 /* total of all TCs bandwidth needs to be 100 */
1491                                 tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent +=
1492                                                                  100 % dcb_i;
1493                                 tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent +=
1494                                                                  100 % dcb_i;
1495                         }
1496                 }
1497
1498                 /* Initialize default user to priority mapping, UPx->TC0 */
1499                 tc = &adapter->dcb_cfg.tc_config[0];
1500                 tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
1501                 tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
1502
1503                 adapter->dcb_cfg.bw_percentage[IXGBE_DCB_TX_CONFIG][0] = 100;
1504                 adapter->dcb_cfg.bw_percentage[IXGBE_DCB_RX_CONFIG][0] = 100;
1505                 adapter->dcb_cfg.rx_pba_cfg = ixgbe_dcb_pba_equal;
1506                 adapter->dcb_cfg.pfc_mode_enable = false;
1507                 adapter->dcb_cfg.round_robin_enable = false;
1508                 adapter->dcb_set_bitmap = 0x00;
1509 #ifdef CONFIG_DCB
1510                 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
1511 #endif /* CONFIG_DCB */
1512
1513                 if (hw->mac.type == ixgbe_mac_X540) {
1514                         adapter->dcb_cfg.num_tcs.pg_tcs = 4;
1515                         adapter->dcb_cfg.num_tcs.pfc_tcs = 4;
1516                 }
1517         }
1518 #ifdef CONFIG_DCB
1519         /* XXX does this need to be initialized even w/o DCB? */
1520         //memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
1521         //       sizeof(adapter->temp_dcb_cfg));
1522
1523 #endif
1524         //if (hw->mac.type == ixgbe_mac_82599EB ||
1525         //    hw->mac.type == ixgbe_mac_X540)
1526         //      hw->mbx.ops.init_params(hw);
1527
1528         /* default flow control settings */
1529         hw->fc.requested_mode = ixgbe_fc_full;
1530         hw->fc.current_mode = ixgbe_fc_full;    /* init for ethtool output */
1531
1532         adapter->last_lfc_mode = hw->fc.current_mode;
1533         ixgbe_pbthresh_setup(adapter);
1534         hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
1535         hw->fc.send_xon = true;
1536         hw->fc.disable_fc_autoneg = false;
1537
1538         /* set default ring sizes */
1539         adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
1540         adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
1541
1542         /* set default work limits */
1543         adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
1544         adapter->rx_work_limit = IXGBE_DEFAULT_RX_WORK;
1545
1546         set_bit(__IXGBE_DOWN, &adapter->state);
1547 out:
1548         return err;
1549 }
1550
1551 /**
1552  * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
1553  * @tx_ring:    tx descriptor ring (for a specific queue) to setup
1554  *
1555  * Return 0 on success, negative on failure
1556  **/
1557 int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
1558 {
1559         struct device *dev = tx_ring->dev;
1560         //int orig_node = dev_to_node(dev);
1561         int numa_node = -1;
1562         int size;
1563
1564         size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
1565
1566         if (tx_ring->q_vector)
1567                 numa_node = tx_ring->q_vector->numa_node;
1568
1569         tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
1570         if (!tx_ring->tx_buffer_info)
1571                 tx_ring->tx_buffer_info = vzalloc(size);
1572         if (!tx_ring->tx_buffer_info)
1573                 goto err;
1574
1575         /* round up to nearest 4K */
1576         tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
1577         tx_ring->size = ALIGN(tx_ring->size, 4096);
1578
1579         //set_dev_node(dev, numa_node);
1580         //tx_ring->desc = dma_alloc_coherent(dev,
1581         //                                 tx_ring->size,
1582         //                                 &tx_ring->dma,
1583         //                                 GFP_KERNEL);
1584         //set_dev_node(dev, orig_node);
1585         //if (!tx_ring->desc)
1586         //      tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
1587         //                                         &tx_ring->dma, GFP_KERNEL);
1588         //if (!tx_ring->desc)
1589         //      goto err;
1590
1591         return 0;
1592
1593 err:
1594         vfree(tx_ring->tx_buffer_info);
1595         tx_ring->tx_buffer_info = NULL;
1596         dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
1597         return -ENOMEM;
1598 }
1599
1600 /**
1601  * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
1602  * @adapter: board private structure
1603  *
1604  * If this function returns with an error, then it's possible one or
1605  * more of the rings is populated (while the rest are not).  It is the
1606  * callers duty to clean those orphaned rings.
1607  *
1608  * Return 0 on success, negative on failure
1609  **/
1610 static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
1611 {
1612         int i, err = 0;
1613
1614         for (i = 0; i < adapter->num_tx_queues; i++) {
1615                 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
1616                 if (!err)
1617                         continue;
1618                 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
1619                 break;
1620         }
1621
1622         return err;
1623 }
1624
1625 /**
1626  * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
1627  * @rx_ring:    rx descriptor ring (for a specific queue) to setup
1628  *
1629  * Returns 0 on success, negative on failure
1630  **/
1631 int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
1632 {
1633         struct device *dev = rx_ring->dev;
1634         //int orig_node = dev_to_node(dev);
1635         int numa_node = -1;
1636         int size;
1637
1638         size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
1639
1640         if (rx_ring->q_vector)
1641                 numa_node = rx_ring->q_vector->numa_node;
1642
1643         rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
1644         if (!rx_ring->rx_buffer_info)
1645                 rx_ring->rx_buffer_info = vzalloc(size);
1646         if (!rx_ring->rx_buffer_info)
1647                 goto err;
1648
1649         /* Round up to nearest 4K */
1650         rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
1651         rx_ring->size = ALIGN(rx_ring->size, 4096);
1652
1653 #ifdef NO_VNIC
1654         set_dev_node(dev, numa_node);
1655         rx_ring->desc = dma_alloc_coherent(dev,
1656                                            rx_ring->size,
1657                                            &rx_ring->dma,
1658                                            GFP_KERNEL);
1659         set_dev_node(dev, orig_node);
1660         if (!rx_ring->desc)
1661                 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
1662                                                    &rx_ring->dma, GFP_KERNEL);
1663         if (!rx_ring->desc)
1664                 goto err;
1665
1666 #ifndef CONFIG_IXGBE_DISABLE_PACKET_SPLIT
1667         ixgbe_init_rx_page_offset(rx_ring);
1668
1669 #endif
1670
1671 #endif /* NO_VNIC */
1672         return 0;
1673 err:
1674         vfree(rx_ring->rx_buffer_info);
1675         rx_ring->rx_buffer_info = NULL;
1676         dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
1677         return -ENOMEM;
1678 }
1679
1680 /**
1681  * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
1682  * @adapter: board private structure
1683  *
1684  * If this function returns with an error, then it's possible one or
1685  * more of the rings is populated (while the rest are not).  It is the
1686  * callers duty to clean those orphaned rings.
1687  *
1688  * Return 0 on success, negative on failure
1689  **/
1690 static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
1691 {
1692         int i, err = 0;
1693
1694         for (i = 0; i < adapter->num_rx_queues; i++) {
1695                 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
1696                 if (!err)
1697                         continue;
1698                 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
1699                 break;
1700         }
1701
1702         return err;
1703 }
1704
1705 /**
1706  * ixgbe_free_tx_resources - Free Tx Resources per Queue
1707  * @tx_ring: Tx descriptor ring for a specific queue
1708  *
1709  * Free all transmit software resources
1710  **/
1711 void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
1712 {
1713         //ixgbe_clean_tx_ring(tx_ring);
1714
1715         vfree(tx_ring->tx_buffer_info);
1716         tx_ring->tx_buffer_info = NULL;
1717
1718         /* if not set, then don't free */
1719         if (!tx_ring->desc)
1720                 return;
1721
1722         //dma_free_coherent(tx_ring->dev, tx_ring->size,
1723         //                tx_ring->desc, tx_ring->dma);
1724
1725         tx_ring->desc = NULL;
1726 }
1727
1728 /**
1729  * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
1730  * @adapter: board private structure
1731  *
1732  * Free all transmit software resources
1733  **/
1734 static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
1735 {
1736         int i;
1737
1738         for (i = 0; i < adapter->num_tx_queues; i++)
1739                 if (adapter->tx_ring[i]->desc)
1740                         ixgbe_free_tx_resources(adapter->tx_ring[i]);
1741 }
1742
1743 /**
1744  * ixgbe_free_rx_resources - Free Rx Resources
1745  * @rx_ring: ring to clean the resources from
1746  *
1747  * Free all receive software resources
1748  **/
1749 void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
1750 {
1751         //ixgbe_clean_rx_ring(rx_ring);
1752
1753         vfree(rx_ring->rx_buffer_info);
1754         rx_ring->rx_buffer_info = NULL;
1755
1756         /* if not set, then don't free */
1757         if (!rx_ring->desc)
1758                 return;
1759
1760         //dma_free_coherent(rx_ring->dev, rx_ring->size,
1761         //                rx_ring->desc, rx_ring->dma);
1762
1763         rx_ring->desc = NULL;
1764 }
1765
1766 /**
1767  * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
1768  * @adapter: board private structure
1769  *
1770  * Free all receive software resources
1771  **/
1772 static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
1773 {
1774         int i;
1775
1776         for (i = 0; i < adapter->num_rx_queues; i++)
1777                 if (adapter->rx_ring[i]->desc)
1778                         ixgbe_free_rx_resources(adapter->rx_ring[i]);
1779 }
1780
1781
1782 /**
1783  * ixgbe_open - Called when a network interface is made active
1784  * @netdev: network interface device structure
1785  *
1786  * Returns 0 on success, negative value on failure
1787  *
1788  * The open entry point is called when a network interface is made
1789  * active by the system (IFF_UP).  At this point all resources needed
1790  * for transmit and receive operations are allocated, the interrupt
1791  * handler is registered with the OS, the watchdog timer is started,
1792  * and the stack is notified that the interface is ready.
1793  **/
1794 //static
1795 int ixgbe_open(struct net_device *netdev)
1796 {
1797         struct ixgbe_adapter *adapter = netdev_priv(netdev);
1798         int err;
1799
1800         /* disallow open during test */
1801         if (test_bit(__IXGBE_TESTING, &adapter->state))
1802                 return -EBUSY;
1803
1804         netif_carrier_off(netdev);
1805
1806         /* allocate transmit descriptors */
1807         err = ixgbe_setup_all_tx_resources(adapter);
1808         if (err)
1809                 goto err_setup_tx;
1810
1811         /* allocate receive descriptors */
1812         err = ixgbe_setup_all_rx_resources(adapter);
1813         if (err)
1814                 goto err_setup_rx;
1815
1816 #ifdef NO_VNIC
1817         ixgbe_configure(adapter);
1818
1819         err = ixgbe_request_irq(adapter);
1820         if (err)
1821                 goto err_req_irq;
1822
1823         ixgbe_up_complete(adapter);
1824
1825 err_req_irq:
1826 #else
1827         return 0;
1828 #endif
1829 err_setup_rx:
1830         ixgbe_free_all_rx_resources(adapter);
1831 err_setup_tx:
1832         ixgbe_free_all_tx_resources(adapter);
1833         ixgbe_reset(adapter);
1834
1835         return err;
1836 }
1837
1838 /**
1839  * ixgbe_close - Disables a network interface
1840  * @netdev: network interface device structure
1841  *
1842  * Returns 0, this is not allowed to fail
1843  *
1844  * The close entry point is called when an interface is de-activated
1845  * by the OS.  The hardware is still under the drivers control, but
1846  * needs to be disabled.  A global MAC reset is issued to stop the
1847  * hardware, and all transmit and receive resources are freed.
1848  **/
1849 //static
1850 int ixgbe_close(struct net_device *netdev)
1851 {
1852         struct ixgbe_adapter *adapter = netdev_priv(netdev);
1853
1854         //ixgbe_down(adapter);
1855         //ixgbe_free_irq(adapter);
1856
1857         //ixgbe_fdir_filter_exit(adapter);
1858
1859         //ixgbe_free_all_tx_resources(adapter);
1860         //ixgbe_free_all_rx_resources(adapter);
1861
1862         ixgbe_release_hw_control(adapter);
1863
1864         return 0;
1865 }
1866
1867
1868
1869
1870
1871 /**
1872  * ixgbe_get_stats - Get System Network Statistics
1873  * @netdev: network interface device structure
1874  *
1875  * Returns the address of the device statistics structure.
1876  * The statistics are actually updated from the timer callback.
1877  **/
1878 //static
1879 struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
1880 {
1881         struct ixgbe_adapter *adapter = netdev_priv(netdev);
1882
1883         /* update the stats data */
1884         ixgbe_update_stats(adapter);
1885
1886 #ifdef HAVE_NETDEV_STATS_IN_NETDEV
1887         /* only return the current stats */
1888         return &netdev->stats;
1889 #else
1890         /* only return the current stats */
1891         return &adapter->net_stats;
1892 #endif /* HAVE_NETDEV_STATS_IN_NETDEV */
1893 }
1894
1895 /**
1896  * ixgbe_update_stats - Update the board statistics counters.
1897  * @adapter: board private structure
1898  **/
1899 void ixgbe_update_stats(struct ixgbe_adapter *adapter)
1900 {
1901 #ifdef HAVE_NETDEV_STATS_IN_NETDEV
1902         struct net_device_stats *net_stats = &adapter->netdev->stats;
1903 #else
1904         struct net_device_stats *net_stats = &adapter->net_stats;
1905 #endif /* HAVE_NETDEV_STATS_IN_NETDEV */
1906         struct ixgbe_hw *hw = &adapter->hw;
1907         struct ixgbe_hw_stats *hwstats = &adapter->stats;
1908         u64 total_mpc = 0;
1909         u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
1910         u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
1911         u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
1912         u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
1913 #ifndef IXGBE_NO_LRO
1914         u32 flushed = 0, coal = 0;
1915         int num_q_vectors = 1;
1916 #endif
1917 #ifdef IXGBE_FCOE
1918         struct ixgbe_fcoe *fcoe = &adapter->fcoe;
1919         unsigned int cpu;
1920         u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
1921 #endif /* IXGBE_FCOE */
1922
1923         printk(KERN_DEBUG "ixgbe_update_stats, tx_queues=%d, rx_queues=%d\n",
1924                         adapter->num_tx_queues, adapter->num_rx_queues);
1925
1926         if (test_bit(__IXGBE_DOWN, &adapter->state) ||
1927             test_bit(__IXGBE_RESETTING, &adapter->state))
1928                 return;
1929
1930 #ifndef IXGBE_NO_LRO
1931         if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
1932                 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1933
1934 #endif
1935         if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
1936                 u64 rsc_count = 0;
1937                 u64 rsc_flush = 0;
1938                 for (i = 0; i < adapter->num_rx_queues; i++) {
1939                         rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
1940                         rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
1941                 }
1942                 adapter->rsc_total_count = rsc_count;
1943                 adapter->rsc_total_flush = rsc_flush;
1944         }
1945
1946 #ifndef IXGBE_NO_LRO
1947         for (i = 0; i < num_q_vectors; i++) {
1948                 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
1949                 if (!q_vector)
1950                         continue;
1951                 flushed += q_vector->lrolist.stats.flushed;
1952                 coal += q_vector->lrolist.stats.coal;
1953         }
1954         adapter->lro_stats.flushed = flushed;
1955         adapter->lro_stats.coal = coal;
1956
1957 #endif
1958         for (i = 0; i < adapter->num_rx_queues; i++) {
1959                 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
1960                 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
1961                 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
1962                 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
1963                 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
1964                 bytes += rx_ring->stats.bytes;
1965                 packets += rx_ring->stats.packets;
1966
1967         }
1968         adapter->non_eop_descs = non_eop_descs;
1969         adapter->alloc_rx_page_failed = alloc_rx_page_failed;
1970         adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
1971         adapter->hw_csum_rx_error = hw_csum_rx_error;
1972         net_stats->rx_bytes = bytes;
1973         net_stats->rx_packets = packets;
1974
1975         bytes = 0;
1976         packets = 0;
1977         /* gather some stats to the adapter struct that are per queue */
1978         for (i = 0; i < adapter->num_tx_queues; i++) {
1979                 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
1980                 restart_queue += tx_ring->tx_stats.restart_queue;
1981                 tx_busy += tx_ring->tx_stats.tx_busy;
1982                 bytes += tx_ring->stats.bytes;
1983                 packets += tx_ring->stats.packets;
1984         }
1985         adapter->restart_queue = restart_queue;
1986         adapter->tx_busy = tx_busy;
1987         net_stats->tx_bytes = bytes;
1988         net_stats->tx_packets = packets;
1989
1990         hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
1991
1992         /* 8 register reads */
1993         for (i = 0; i < 8; i++) {
1994                 /* for packet buffers not used, the register should read 0 */
1995                 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
1996                 missed_rx += mpc;
1997                 hwstats->mpc[i] += mpc;
1998                 total_mpc += hwstats->mpc[i];
1999                 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
2000                 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
2001                 switch (hw->mac.type) {
2002                 case ixgbe_mac_82598EB:
2003                         hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
2004                         hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
2005                         hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
2006                         hwstats->pxonrxc[i] +=
2007                                 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
2008                         break;
2009                 case ixgbe_mac_82599EB:
2010                 case ixgbe_mac_X540:
2011                         hwstats->pxonrxc[i] +=
2012                                 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
2013                         break;
2014                 default:
2015                         break;
2016                 }
2017         }
2018
2019         /*16 register reads */
2020         for (i = 0; i < 16; i++) {
2021                 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
2022                 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
2023                 if ((hw->mac.type == ixgbe_mac_82599EB) ||
2024                     (hw->mac.type == ixgbe_mac_X540)) {
2025                         hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
2026                         IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
2027                         hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
2028                         IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
2029                 }
2030         }
2031
2032         hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
2033         /* work around hardware counting issue */
2034         hwstats->gprc -= missed_rx;
2035
2036         ixgbe_update_xoff_received(adapter);
2037
2038         /* 82598 hardware only has a 32 bit counter in the high register */
2039         switch (hw->mac.type) {
2040         case ixgbe_mac_82598EB:
2041                 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
2042                 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
2043                 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
2044                 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
2045                 break;
2046         case ixgbe_mac_X540:
2047                 /* OS2BMC stats are X540 only*/
2048                 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
2049                 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
2050                 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
2051                 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
2052         case ixgbe_mac_82599EB:
2053                 for (i = 0; i < 16; i++)
2054                         adapter->hw_rx_no_dma_resources +=
2055                                              IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
2056                 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
2057                 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
2058                 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
2059                 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
2060                 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
2061                 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
2062                 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
2063 #ifdef HAVE_TX_MQ
2064                 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
2065                 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
2066 #endif /* HAVE_TX_MQ */
2067 #ifdef IXGBE_FCOE
2068                 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
2069                 hwstats->fclast += IXGBE_READ_REG(hw, IXGBE_FCLAST);
2070                 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
2071                 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
2072                 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
2073                 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
2074                 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
2075                 /* Add up per cpu counters for total ddp aloc fail */
2076                 if (fcoe && fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
2077                         for_each_possible_cpu(cpu) {
2078                                 fcoe_noddp_counts_sum +=
2079                                         *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
2080                                 fcoe_noddp_ext_buff_counts_sum +=
2081                                         *per_cpu_ptr(fcoe->
2082                                                 pcpu_noddp_ext_buff, cpu);
2083                         }
2084                 }
2085                 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
2086                 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
2087
2088 #endif /* IXGBE_FCOE */
2089                 break;
2090         default:
2091                 break;
2092         }
2093         bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
2094         hwstats->bprc += bprc;
2095         hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
2096         if (hw->mac.type == ixgbe_mac_82598EB)
2097                 hwstats->mprc -= bprc;
2098         hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
2099         hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
2100         hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
2101         hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
2102         hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
2103         hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
2104         hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
2105         hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
2106         lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
2107         hwstats->lxontxc += lxon;
2108         lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
2109         hwstats->lxofftxc += lxoff;
2110         hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
2111         hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
2112         /*
2113          * 82598 errata - tx of flow control packets is included in tx counters
2114          */
2115         xon_off_tot = lxon + lxoff;
2116         hwstats->gptc -= xon_off_tot;
2117         hwstats->mptc -= xon_off_tot;
2118         hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
2119         hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
2120         hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
2121         hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
2122         hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
2123         hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
2124         hwstats->ptc64 -= xon_off_tot;
2125         hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
2126         hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
2127         hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
2128         hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
2129         hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
2130         hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
2131         /* Fill out the OS statistics structure */
2132         net_stats->multicast = hwstats->mprc;
2133
2134         /* Rx Errors */
2135         net_stats->rx_errors = hwstats->crcerrs +
2136                                        hwstats->rlec;
2137         net_stats->rx_dropped = 0;
2138         net_stats->rx_length_errors = hwstats->rlec;
2139         net_stats->rx_crc_errors = hwstats->crcerrs;
2140         net_stats->rx_missed_errors = total_mpc;
2141
2142         /*
2143          * VF Stats Collection - skip while resetting because these
2144          * are not clear on read and otherwise you'll sometimes get
2145          * crazy values.
2146          */
2147         if (!test_bit(__IXGBE_RESETTING, &adapter->state)) {
2148                 for (i = 0; i < adapter->num_vfs; i++) {
2149                         UPDATE_VF_COUNTER_32bit(IXGBE_PVFGPRC(i),             \
2150                                         adapter->vfinfo[i].last_vfstats.gprc, \
2151                                         adapter->vfinfo[i].vfstats.gprc);
2152                         UPDATE_VF_COUNTER_32bit(IXGBE_PVFGPTC(i),             \
2153                                         adapter->vfinfo[i].last_vfstats.gptc, \
2154                                         adapter->vfinfo[i].vfstats.gptc);
2155                         UPDATE_VF_COUNTER_36bit(IXGBE_PVFGORC_LSB(i),         \
2156                                         IXGBE_PVFGORC_MSB(i),                 \
2157                                         adapter->vfinfo[i].last_vfstats.gorc, \
2158                                         adapter->vfinfo[i].vfstats.gorc);
2159                         UPDATE_VF_COUNTER_36bit(IXGBE_PVFGOTC_LSB(i),         \
2160                                         IXGBE_PVFGOTC_MSB(i),                 \
2161                                         adapter->vfinfo[i].last_vfstats.gotc, \
2162                                         adapter->vfinfo[i].vfstats.gotc);
2163                         UPDATE_VF_COUNTER_32bit(IXGBE_PVFMPRC(i),             \
2164                                         adapter->vfinfo[i].last_vfstats.mprc, \
2165                                         adapter->vfinfo[i].vfstats.mprc);
2166                 }
2167         }
2168 }
2169
2170
2171 #ifdef NO_VNIC
2172
2173 /**
2174  * ixgbe_watchdog_update_link - update the link status
2175  * @adapter - pointer to the device adapter structure
2176  * @link_speed - pointer to a u32 to store the link_speed
2177  **/
2178 static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
2179 {
2180         struct ixgbe_hw *hw = &adapter->hw;
2181         u32 link_speed = adapter->link_speed;
2182         bool link_up = adapter->link_up;
2183         bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
2184
2185         if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
2186                 return;
2187
2188         if (hw->mac.ops.check_link) {
2189                 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
2190         } else {
2191                 /* always assume link is up, if no check link function */
2192                 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
2193                 link_up = true;
2194         }
2195
2196 #ifdef HAVE_DCBNL_IEEE
2197         if (adapter->ixgbe_ieee_pfc)
2198                 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
2199
2200 #endif
2201         if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
2202                 hw->mac.ops.fc_enable(hw);
2203                 //ixgbe_set_rx_drop_en(adapter);
2204         }
2205
2206         if (link_up ||
2207             time_after(jiffies, (adapter->link_check_timeout +
2208                                  IXGBE_TRY_LINK_TIMEOUT))) {
2209                 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
2210                 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
2211                 IXGBE_WRITE_FLUSH(hw);
2212         }
2213
2214         adapter->link_up = link_up;
2215         adapter->link_speed = link_speed;
2216 }
2217 #endif
2218
2219
2220
2221 #ifdef NO_VNIC
2222
2223 /**
2224  * ixgbe_service_task - manages and runs subtasks
2225  * @work: pointer to work_struct containing our data
2226  **/
2227 static void ixgbe_service_task(struct work_struct *work)
2228 {
2229         //struct ixgbe_adapter *adapter = container_of(work,
2230         //                                           struct ixgbe_adapter,
2231         //                                           service_task);
2232
2233         //ixgbe_reset_subtask(adapter);
2234         //ixgbe_sfp_detection_subtask(adapter);
2235         //ixgbe_sfp_link_config_subtask(adapter);
2236         //ixgbe_check_overtemp_subtask(adapter);
2237         //ixgbe_watchdog_subtask(adapter);
2238 #ifdef HAVE_TX_MQ
2239         //ixgbe_fdir_reinit_subtask(adapter);
2240 #endif
2241         //ixgbe_check_hang_subtask(adapter);
2242
2243         //ixgbe_service_event_complete(adapter);
2244 }
2245
2246
2247
2248
2249 #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
2250                        IXGBE_TXD_CMD_RS)
2251
2252
2253 /**
2254  * ixgbe_set_mac - Change the Ethernet Address of the NIC
2255  * @netdev: network interface device structure
2256  * @p: pointer to an address structure
2257  *
2258  * Returns 0 on success, negative on failure
2259  **/
2260 static int ixgbe_set_mac(struct net_device *netdev, void *p)
2261 {
2262         struct ixgbe_adapter *adapter = netdev_priv(netdev);
2263         struct ixgbe_hw *hw = &adapter->hw;
2264         struct sockaddr *addr = p;
2265         int ret;
2266
2267         if (!is_valid_ether_addr(addr->sa_data))
2268                 return -EADDRNOTAVAIL;
2269
2270         ixgbe_del_mac_filter(adapter, hw->mac.addr,
2271                              adapter->num_vfs);
2272         memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2273         memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
2274
2275
2276         /* set the correct pool for the new PF MAC address in entry 0 */
2277         ret = ixgbe_add_mac_filter(adapter, hw->mac.addr,
2278                                     adapter->num_vfs);
2279         return (ret > 0 ? 0 : ret);
2280 }
2281
2282
2283 /**
2284  * ixgbe_ioctl -
2285  * @netdev:
2286  * @ifreq:
2287  * @cmd:
2288  **/
2289 static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2290 {
2291         switch (cmd) {
2292 #ifdef ETHTOOL_OPS_COMPAT
2293         case SIOCETHTOOL:
2294                 return ethtool_ioctl(ifr);
2295 #endif
2296         default:
2297                 return -EOPNOTSUPP;
2298         }
2299 }
2300 #endif /* NO_VNIC */
2301
2302
2303 void ixgbe_do_reset(struct net_device *netdev)
2304 {
2305         struct ixgbe_adapter *adapter = netdev_priv(netdev);
2306
2307         if (netif_running(netdev))
2308                 ixgbe_reinit_locked(adapter);
2309         else
2310                 ixgbe_reset(adapter);
2311 }
2312
2313
2314
2315
2316
2317
2318 /**
2319  * ixgbe_probe - Device Initialization Routine
2320  * @pdev: PCI device information struct
2321  * @ent: entry in ixgbe_pci_tbl
2322  *
2323  * Returns 0 on success, negative on failure
2324  *
2325  * ixgbe_probe initializes an adapter identified by a pci_dev structure.
2326  * The OS initialization, configuring of the adapter private structure,
2327  * and a hardware reset occur.
2328  **/
2329 //static
2330 int ixgbe_kni_probe(struct pci_dev *pdev,
2331                                  struct net_device **lad_dev)
2332 {
2333         size_t count;
2334         struct net_device *netdev;
2335         struct ixgbe_adapter *adapter = NULL;
2336         struct ixgbe_hw *hw = NULL;
2337         static int cards_found;
2338         int i, err;
2339         u16 offset;
2340         u16 eeprom_verh, eeprom_verl, eeprom_cfg_blkh, eeprom_cfg_blkl;
2341         u32 etrack_id;
2342         u16 build, major, patch;
2343         char *info_string, *i_s_var;
2344         u8 part_str[IXGBE_PBANUM_LENGTH];
2345         enum ixgbe_mac_type mac_type = ixgbe_mac_unknown;
2346 #ifdef HAVE_TX_MQ
2347         unsigned int indices = num_possible_cpus();
2348 #endif /* HAVE_TX_MQ */
2349 #ifdef IXGBE_FCOE
2350         u16 device_caps;
2351 #endif
2352         u16 wol_cap;
2353
2354         err = pci_enable_device_mem(pdev);
2355         if (err)
2356                 return err;
2357
2358
2359 #ifdef NO_VNIC
2360         err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
2361                                            IORESOURCE_MEM), ixgbe_driver_name);
2362         if (err) {
2363                 dev_err(pci_dev_to_dev(pdev),
2364                         "pci_request_selected_regions failed 0x%x\n", err);
2365                 goto err_pci_reg;
2366         }
2367 #endif
2368
2369         /*
2370          * The mac_type is needed before we have the adapter is  set up
2371          * so rather than maintain two devID -> MAC tables we dummy up
2372          * an ixgbe_hw stuct and use ixgbe_set_mac_type.
2373          */
2374         hw = vmalloc(sizeof(struct ixgbe_hw));
2375         if (!hw) {
2376                 pr_info("Unable to allocate memory for early mac "
2377                         "check\n");
2378         } else {
2379                 hw->vendor_id = pdev->vendor;
2380                 hw->device_id = pdev->device;
2381                 ixgbe_set_mac_type(hw);
2382                 mac_type = hw->mac.type;
2383                 vfree(hw);
2384         }
2385
2386 #ifdef NO_VNIC
2387         /*
2388          * Workaround of Silicon errata on 82598. Disable LOs in the PCI switch
2389          * port to which the 82598 is connected to prevent duplicate
2390          * completions caused by LOs.  We need the mac type so that we only
2391          * do this on 82598 devices, ixgbe_set_mac_type does this for us if
2392          * we set it's device ID.
2393          */
2394         if (mac_type == ixgbe_mac_82598EB)
2395                 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S);
2396
2397         pci_enable_pcie_error_reporting(pdev);
2398
2399         pci_set_master(pdev);
2400 #endif
2401
2402 #ifdef HAVE_TX_MQ
2403 #ifdef CONFIG_DCB
2404 #ifdef HAVE_MQPRIO
2405         indices *= IXGBE_DCB_MAX_TRAFFIC_CLASS;
2406 #else
2407         indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
2408 #endif /* HAVE_MQPRIO */
2409 #endif /* CONFIG_DCB */
2410
2411         if (mac_type == ixgbe_mac_82598EB)
2412                 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
2413         else
2414                 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
2415
2416 #ifdef IXGBE_FCOE
2417         indices += min_t(unsigned int, num_possible_cpus(),
2418                          IXGBE_MAX_FCOE_INDICES);
2419 #endif
2420         netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
2421 #else /* HAVE_TX_MQ */
2422         netdev = alloc_etherdev(sizeof(struct ixgbe_adapter));
2423 #endif /* HAVE_TX_MQ */
2424         if (!netdev) {
2425                 err = -ENOMEM;
2426                 goto err_alloc_etherdev;
2427         }
2428
2429         SET_NETDEV_DEV(netdev, &pdev->dev);
2430
2431         adapter = netdev_priv(netdev);
2432         //pci_set_drvdata(pdev, adapter);
2433
2434         adapter->netdev = netdev;
2435         adapter->pdev = pdev;
2436         hw = &adapter->hw;
2437         hw->back = adapter;
2438         adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
2439
2440 #ifdef HAVE_PCI_ERS
2441         /*
2442          * call save state here in standalone driver because it relies on
2443          * adapter struct to exist, and needs to call netdev_priv
2444          */
2445         pci_save_state(pdev);
2446
2447 #endif
2448         hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
2449                               pci_resource_len(pdev, 0));
2450         if (!hw->hw_addr) {
2451                 err = -EIO;
2452                 goto err_ioremap;
2453         }
2454         //ixgbe_assign_netdev_ops(netdev);
2455         ixgbe_set_ethtool_ops(netdev);
2456
2457         strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
2458
2459         adapter->bd_number = cards_found;
2460
2461         /* setup the private structure */
2462         err = ixgbe_sw_init(adapter);
2463         if (err)
2464                 goto err_sw_init;
2465
2466         /* Make it possible the adapter to be woken up via WOL */
2467         switch (adapter->hw.mac.type) {
2468         case ixgbe_mac_82599EB:
2469         case ixgbe_mac_X540:
2470                 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
2471                 break;
2472         default:
2473                 break;
2474         }
2475
2476         /*
2477          * check_options must be called before setup_link to set up
2478          * hw->fc completely
2479          */
2480         //ixgbe_check_options(adapter);
2481
2482 #ifndef NO_VNIC
2483         /* reset_hw fills in the perm_addr as well */
2484         hw->phy.reset_if_overtemp = true;
2485         err = hw->mac.ops.reset_hw(hw);
2486         hw->phy.reset_if_overtemp = false;
2487         if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
2488             hw->mac.type == ixgbe_mac_82598EB) {
2489                 err = 0;
2490         } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2491                 e_dev_err("failed to load because an unsupported SFP+ "
2492                           "module type was detected.\n");
2493                 e_dev_err("Reload the driver after installing a supported "
2494                           "module.\n");
2495                 goto err_sw_init;
2496         } else if (err) {
2497                 e_dev_err("HW Init failed: %d\n", err);
2498                 goto err_sw_init;
2499         }
2500 #endif
2501
2502         //if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
2503         //      ixgbe_probe_vf(adapter);
2504
2505
2506 #ifdef MAX_SKB_FRAGS
2507         netdev->features |= NETIF_F_SG |
2508                             NETIF_F_IP_CSUM;
2509
2510 #ifdef NETIF_F_IPV6_CSUM
2511         netdev->features |= NETIF_F_IPV6_CSUM;
2512 #endif
2513
2514 #ifdef NETIF_F_HW_VLAN_TX
2515         netdev->features |= NETIF_F_HW_VLAN_TX |
2516                             NETIF_F_HW_VLAN_RX;
2517 #endif
2518 #ifdef NETIF_F_TSO
2519         netdev->features |= NETIF_F_TSO;
2520 #endif /* NETIF_F_TSO */
2521 #ifdef NETIF_F_TSO6
2522         netdev->features |= NETIF_F_TSO6;
2523 #endif /* NETIF_F_TSO6 */
2524 #ifdef NETIF_F_RXHASH
2525         netdev->features |= NETIF_F_RXHASH;
2526 #endif /* NETIF_F_RXHASH */
2527
2528 #ifdef HAVE_NDO_SET_FEATURES
2529         netdev->features |= NETIF_F_RXCSUM;
2530
2531         /* copy netdev features into list of user selectable features */
2532         netdev->hw_features |= netdev->features;
2533
2534         /* give us the option of enabling RSC/LRO later */
2535 #ifdef IXGBE_NO_LRO
2536         if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
2537 #endif
2538                 netdev->hw_features |= NETIF_F_LRO;
2539
2540 #else
2541 #ifdef NETIF_F_GRO
2542
2543         /* this is only needed on kernels prior to 2.6.39 */
2544         netdev->features |= NETIF_F_GRO;
2545 #endif /* NETIF_F_GRO */
2546 #endif
2547
2548 #ifdef NETIF_F_HW_VLAN_TX
2549         /* set this bit last since it cannot be part of hw_features */
2550         netdev->features |= NETIF_F_HW_VLAN_FILTER;
2551 #endif
2552         switch (adapter->hw.mac.type) {
2553         case ixgbe_mac_82599EB:
2554         case ixgbe_mac_X540:
2555                 netdev->features |= NETIF_F_SCTP_CSUM;
2556 #ifdef HAVE_NDO_SET_FEATURES
2557                 netdev->hw_features |= NETIF_F_SCTP_CSUM |
2558                                        NETIF_F_NTUPLE;
2559 #endif
2560                 break;
2561         default:
2562                 break;
2563         }
2564
2565 #ifdef HAVE_NETDEV_VLAN_FEATURES
2566         netdev->vlan_features |= NETIF_F_SG |
2567                                  NETIF_F_IP_CSUM |
2568                                  NETIF_F_IPV6_CSUM |
2569                                  NETIF_F_TSO |
2570                                  NETIF_F_TSO6;
2571
2572 #endif /* HAVE_NETDEV_VLAN_FEATURES */
2573         /*
2574          * If perfect filters were enabled in check_options(), enable them
2575          * on the netdevice too.
2576          */
2577         if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
2578                 netdev->features |= NETIF_F_NTUPLE;
2579         if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED)
2580                 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2581         if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
2582                 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2583         if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
2584                 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
2585                 /* clear n-tuple support in the netdev unconditionally */
2586                 netdev->features &= ~NETIF_F_NTUPLE;
2587         }
2588
2589 #ifdef NETIF_F_RXHASH
2590         if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
2591                 netdev->features &= ~NETIF_F_RXHASH;
2592
2593 #endif /* NETIF_F_RXHASH */
2594         if (netdev->features & NETIF_F_LRO) {
2595                 if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
2596                     ((adapter->rx_itr_setting == 1) ||
2597                      (adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR))) {
2598                         adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
2599                 } else if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) {
2600 #ifdef IXGBE_NO_LRO
2601                         e_info(probe, "InterruptThrottleRate set too high, "
2602                                "disabling RSC\n");
2603 #else
2604                         e_info(probe, "InterruptThrottleRate set too high, "
2605                                "falling back to software LRO\n");
2606 #endif
2607                 }
2608         }
2609 #ifdef CONFIG_DCB
2610         //netdev->dcbnl_ops = &dcbnl_ops;
2611 #endif
2612
2613 #ifdef IXGBE_FCOE
2614 #ifdef NETIF_F_FSO
2615         if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
2616                 ixgbe_get_device_caps(hw, &device_caps);
2617                 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) {
2618                         adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
2619                         adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
2620                         e_info(probe, "FCoE offload feature is not available. "
2621                                "Disabling FCoE offload feature\n");
2622                 }
2623 #ifndef HAVE_NETDEV_OPS_FCOE_ENABLE
2624                 else {
2625                         adapter->flags |= IXGBE_FLAG_FCOE_ENABLED;
2626                         adapter->ring_feature[RING_F_FCOE].indices =
2627                                 IXGBE_FCRETA_SIZE;
2628                         netdev->features |= NETIF_F_FSO |
2629                                             NETIF_F_FCOE_CRC |
2630                                             NETIF_F_FCOE_MTU;
2631                         netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX - 1;
2632                 }
2633 #endif /* HAVE_NETDEV_OPS_FCOE_ENABLE */
2634 #ifdef HAVE_NETDEV_VLAN_FEATURES
2635                 netdev->vlan_features |= NETIF_F_FSO |
2636                                          NETIF_F_FCOE_CRC |
2637                                          NETIF_F_FCOE_MTU;
2638 #endif /* HAVE_NETDEV_VLAN_FEATURES */
2639         }
2640 #endif /* NETIF_F_FSO */
2641 #endif /* IXGBE_FCOE */
2642
2643 #endif /* MAX_SKB_FRAGS */
2644         /* make sure the EEPROM is good */
2645         if (hw->eeprom.ops.validate_checksum &&
2646             (hw->eeprom.ops.validate_checksum(hw, NULL) < 0)) {
2647                 e_dev_err("The EEPROM Checksum Is Not Valid\n");
2648                 err = -EIO;
2649                 goto err_sw_init;
2650         }
2651
2652         memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
2653 #ifdef ETHTOOL_GPERMADDR
2654         memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
2655
2656         if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
2657                 e_dev_err("invalid MAC address\n");
2658                 err = -EIO;
2659                 goto err_sw_init;
2660         }
2661 #else
2662         if (ixgbe_validate_mac_addr(netdev->dev_addr)) {
2663                 e_dev_err("invalid MAC address\n");
2664                 err = -EIO;
2665                 goto err_sw_init;
2666         }
2667 #endif
2668         memcpy(&adapter->mac_table[0].addr, hw->mac.perm_addr,
2669                netdev->addr_len);
2670         adapter->mac_table[0].queue = adapter->num_vfs;
2671         adapter->mac_table[0].state = (IXGBE_MAC_STATE_DEFAULT |
2672                                        IXGBE_MAC_STATE_IN_USE);
2673         hw->mac.ops.set_rar(hw, 0, adapter->mac_table[0].addr,
2674                             adapter->mac_table[0].queue,
2675                             IXGBE_RAH_AV);
2676
2677         //setup_timer(&adapter->service_timer, &ixgbe_service_timer,
2678         //          (unsigned long) adapter);
2679
2680         //INIT_WORK(&adapter->service_task, ixgbe_service_task);
2681         //clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
2682
2683         //err = ixgbe_init_interrupt_scheme(adapter);
2684         //if (err)
2685         //      goto err_sw_init;
2686
2687         //adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2688         ixgbe_set_num_queues(adapter);
2689
2690         adapter->wol = 0;
2691         /* WOL not supported for all but the following */
2692         switch (pdev->device) {
2693         case IXGBE_DEV_ID_82599_SFP:
2694                 /* Only these subdevice supports WOL */
2695                 switch (pdev->subsystem_device) {
2696                 case IXGBE_SUBDEV_ID_82599_560FLR:
2697                         /* only support first port */
2698                         if (hw->bus.func != 0)
2699                                 break;
2700                 case IXGBE_SUBDEV_ID_82599_SFP:
2701                         adapter->wol = IXGBE_WUFC_MAG;
2702                         break;
2703                 }
2704                 break;
2705         case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
2706                 /* All except this subdevice support WOL */
2707                 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
2708                         adapter->wol = IXGBE_WUFC_MAG;
2709                 break;
2710         case IXGBE_DEV_ID_82599_KX4:
2711                 adapter->wol = IXGBE_WUFC_MAG;
2712                 break;
2713         case IXGBE_DEV_ID_X540T:
2714                 /* Check eeprom to see if it is enabled */
2715                 ixgbe_read_eeprom(hw, 0x2c, &adapter->eeprom_cap);
2716                 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
2717
2718                 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
2719                     ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
2720                      (hw->bus.func == 0)))
2721                         adapter->wol = IXGBE_WUFC_MAG;
2722                 break;
2723         }
2724         //device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
2725
2726
2727         /*
2728          * Save off EEPROM version number and Option Rom version which
2729          * together make a unique identify for the eeprom
2730          */
2731         ixgbe_read_eeprom(hw, 0x2e, &eeprom_verh);
2732         ixgbe_read_eeprom(hw, 0x2d, &eeprom_verl);
2733
2734         etrack_id = (eeprom_verh << 16) | eeprom_verl;
2735
2736         ixgbe_read_eeprom(hw, 0x17, &offset);
2737
2738         /* Make sure offset to SCSI block is valid */
2739         if (!(offset == 0x0) && !(offset == 0xffff)) {
2740                 ixgbe_read_eeprom(hw, offset + 0x84, &eeprom_cfg_blkh);
2741                 ixgbe_read_eeprom(hw, offset + 0x83, &eeprom_cfg_blkl);
2742
2743                 /* Only display Option Rom if exist */
2744                 if (eeprom_cfg_blkl && eeprom_cfg_blkh) {
2745                         major = eeprom_cfg_blkl >> 8;
2746                         build = (eeprom_cfg_blkl << 8) | (eeprom_cfg_blkh >> 8);
2747                         patch = eeprom_cfg_blkh & 0x00ff;
2748
2749                         snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
2750                                  "0x%08x, %d.%d.%d", etrack_id, major, build,
2751                                  patch);
2752                 } else {
2753                         snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
2754                                  "0x%08x", etrack_id);
2755                 }
2756         } else {
2757                 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
2758                          "0x%08x", etrack_id);
2759         }
2760
2761         /* reset the hardware with the new settings */
2762         err = hw->mac.ops.start_hw(hw);
2763         if (err == IXGBE_ERR_EEPROM_VERSION) {
2764                 /* We are running on a pre-production device, log a warning */
2765                 e_dev_warn("This device is a pre-production adapter/LOM. "
2766                            "Please be aware there may be issues associated "
2767                            "with your hardware.  If you are experiencing "
2768                            "problems please contact your Intel or hardware "
2769                            "representative who provided you with this "
2770                            "hardware.\n");
2771         }
2772         /* pick up the PCI bus settings for reporting later */
2773         if (hw->mac.ops.get_bus_info)
2774                 hw->mac.ops.get_bus_info(hw);
2775
2776         strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
2777         *lad_dev = netdev;
2778
2779         adapter->netdev_registered = true;
2780 #ifdef NO_VNIC
2781         /* power down the optics */
2782         if ((hw->phy.multispeed_fiber) ||
2783             ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
2784              (hw->mac.type == ixgbe_mac_82599EB)))
2785                 ixgbe_disable_tx_laser(hw);
2786
2787         /* carrier off reporting is important to ethtool even BEFORE open */
2788         netif_carrier_off(netdev);
2789         /* keep stopping all the transmit queues for older kernels */
2790         netif_tx_stop_all_queues(netdev);
2791 #endif
2792
2793         /* print all messages at the end so that we use our eth%d name */
2794         /* print bus type/speed/width info */
2795         e_dev_info("(PCI Express:%s:%s) ",
2796                    (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
2797                    hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
2798                    "Unknown"),
2799                    (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
2800                    hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
2801                    hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
2802                    "Unknown"));
2803
2804         /* print the MAC address */
2805         for (i = 0; i < 6; i++)
2806                 pr_cont("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
2807
2808         /* First try to read PBA as a string */
2809         err = ixgbe_read_pba_string(hw, part_str, IXGBE_PBANUM_LENGTH);
2810         if (err)
2811                 strlcpy(part_str, "Unknown", sizeof(part_str));
2812         if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
2813                 e_info(probe, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
2814                        hw->mac.type, hw->phy.type, hw->phy.sfp_type, part_str);
2815         else
2816                 e_info(probe, "MAC: %d, PHY: %d, PBA No: %s\n",
2817                       hw->mac.type, hw->phy.type, part_str);
2818
2819         if (((hw->bus.speed == ixgbe_bus_speed_2500) &&
2820              (hw->bus.width <= ixgbe_bus_width_pcie_x4)) ||
2821             (hw->bus.width <= ixgbe_bus_width_pcie_x2)) {
2822                 e_dev_warn("PCI-Express bandwidth available for this "
2823                            "card is not sufficient for optimal "
2824                            "performance.\n");
2825                 e_dev_warn("For optimal performance a x8 PCI-Express "
2826                            "slot is required.\n");
2827         }
2828
2829 #define INFO_STRING_LEN 255
2830         info_string = kzalloc(INFO_STRING_LEN, GFP_KERNEL);
2831         if (!info_string) {
2832                 e_err(probe, "allocation for info string failed\n");
2833                 goto no_info_string;
2834         }
2835         count = 0;
2836         i_s_var = info_string;
2837         count += snprintf(i_s_var, INFO_STRING_LEN, "Enabled Features: ");
2838
2839         i_s_var = info_string + count;
2840         count += snprintf(i_s_var, (INFO_STRING_LEN - count),
2841                         "RxQ: %d TxQ: %d ", adapter->num_rx_queues,
2842                                         adapter->num_tx_queues);
2843         i_s_var = info_string + count;
2844 #ifdef IXGBE_FCOE
2845         if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
2846                 count += snprintf(i_s_var, INFO_STRING_LEN - count, "FCoE ");
2847                 i_s_var = info_string + count;
2848         }
2849 #endif
2850         if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2851                 count += snprintf(i_s_var, INFO_STRING_LEN - count,
2852                                                         "FdirHash ");
2853                 i_s_var = info_string + count;
2854         }
2855         if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
2856                 count += snprintf(i_s_var, INFO_STRING_LEN - count,
2857                                                 "FdirPerfect ");
2858                 i_s_var = info_string + count;
2859         }
2860         if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2861                 count += snprintf(i_s_var, INFO_STRING_LEN - count, "DCB ");
2862                 i_s_var = info_string + count;
2863         }
2864         if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2865                 count += snprintf(i_s_var, INFO_STRING_LEN - count, "RSS ");
2866                 i_s_var = info_string + count;
2867         }
2868         if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2869                 count += snprintf(i_s_var, INFO_STRING_LEN - count, "DCA ");
2870                 i_s_var = info_string + count;
2871         }
2872         if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
2873                 count += snprintf(i_s_var, INFO_STRING_LEN - count, "RSC ");
2874                 i_s_var = info_string + count;
2875         }
2876 #ifndef IXGBE_NO_LRO
2877         else if (netdev->features & NETIF_F_LRO) {
2878                 count += snprintf(i_s_var, INFO_STRING_LEN - count, "LRO ");
2879                 i_s_var = info_string + count;
2880         }
2881 #endif
2882
2883         BUG_ON(i_s_var > (info_string + INFO_STRING_LEN));
2884         /* end features printing */
2885         e_info(probe, "%s\n", info_string);
2886         kfree(info_string);
2887 no_info_string:
2888
2889         /* firmware requires blank driver version */
2890         ixgbe_set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF);
2891
2892 #if defined(HAVE_NETDEV_STORAGE_ADDRESS) && defined(NETDEV_HW_ADDR_T_SAN)
2893         /* add san mac addr to netdev */
2894         //ixgbe_add_sanmac_netdev(netdev);
2895
2896 #endif /* (HAVE_NETDEV_STORAGE_ADDRESS) && (NETDEV_HW_ADDR_T_SAN) */
2897         e_info(probe, "Intel(R) 10 Gigabit Network Connection\n");
2898         cards_found++;
2899
2900 #ifdef IXGBE_SYSFS
2901         //if (ixgbe_sysfs_init(adapter))
2902         //      e_err(probe, "failed to allocate sysfs resources\n");
2903 #else
2904 #ifdef IXGBE_PROCFS
2905         //if (ixgbe_procfs_init(adapter))
2906         //      e_err(probe, "failed to allocate procfs resources\n");
2907 #endif /* IXGBE_PROCFS */
2908 #endif /* IXGBE_SYSFS */
2909
2910         return 0;
2911
2912 //err_register:
2913         //ixgbe_clear_interrupt_scheme(adapter);
2914         //ixgbe_release_hw_control(adapter);
2915 err_sw_init:
2916         adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
2917         if (adapter->mac_table)
2918                 kfree(adapter->mac_table);
2919         iounmap(hw->hw_addr);
2920 err_ioremap:
2921         free_netdev(netdev);
2922 err_alloc_etherdev:
2923         //pci_release_selected_regions(pdev,
2924         //                           pci_select_bars(pdev, IORESOURCE_MEM));
2925 //err_pci_reg:
2926 //err_dma:
2927         pci_disable_device(pdev);
2928         return err;
2929 }
2930
2931 /**
2932  * ixgbe_remove - Device Removal Routine
2933  * @pdev: PCI device information struct
2934  *
2935  * ixgbe_remove is called by the PCI subsystem to alert the driver
2936  * that it should release a PCI device.  The could be caused by a
2937  * Hot-Plug event, or because the driver is going to be removed from
2938  * memory.
2939  **/
2940 void ixgbe_kni_remove(struct pci_dev *pdev)
2941 {
2942         pci_disable_device(pdev);
2943 }
2944
2945
2946 u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
2947 {
2948         u16 value;
2949         struct ixgbe_adapter *adapter = hw->back;
2950
2951         pci_read_config_word(adapter->pdev, reg, &value);
2952         return value;
2953 }
2954
2955 void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
2956 {
2957         struct ixgbe_adapter *adapter = hw->back;
2958
2959         pci_write_config_word(adapter->pdev, reg, value);
2960 }
2961
2962 void ewarn(struct ixgbe_hw *hw, const char *st, u32 status)
2963 {
2964         struct ixgbe_adapter *adapter = hw->back;
2965
2966         netif_warn(adapter, drv, adapter->netdev,  "%s", st);
2967 }
2968
2969
2970
2971
2972