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