blob: 06513d9e9fb70855bc46b573eab71bf961ec139e [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
Carolyn Wyborny6e861322012-01-18 22:13:27 +00004 Copyright(c) 2007-2012 Intel Corporation.
Auke Kok9d5c8242008-01-24 02:22:38 -08005
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
Jeff Kirsher876d2d62011-10-21 20:01:34 +000028#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29
Auke Kok9d5c8242008-01-24 02:22:38 -080030#include <linux/module.h>
31#include <linux/types.h>
32#include <linux/init.h>
Jiri Pirkob2cb09b2011-07-21 03:27:27 +000033#include <linux/bitops.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080034#include <linux/vmalloc.h>
35#include <linux/pagemap.h>
36#include <linux/netdevice.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080037#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090038#include <linux/slab.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080039#include <net/checksum.h>
40#include <net/ip6_checksum.h>
Patrick Ohlyc6cb0902009-02-12 05:03:42 +000041#include <linux/net_tstamp.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080042#include <linux/mii.h>
43#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000044#include <linux/if.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080045#include <linux/if_vlan.h>
46#include <linux/pci.h>
Alexander Duyckc54106b2008-10-16 21:26:57 -070047#include <linux/pci-aspm.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080048#include <linux/delay.h>
49#include <linux/interrupt.h>
Alexander Duyck7d13a7d2011-08-26 07:44:32 +000050#include <linux/ip.h>
51#include <linux/tcp.h>
52#include <linux/sctp.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080053#include <linux/if_ether.h>
Alexander Duyck40a914f2008-11-27 00:24:37 -080054#include <linux/aer.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040055#include <linux/prefetch.h>
Yan, Zheng749ab2c2012-01-04 20:23:37 +000056#include <linux/pm_runtime.h>
Jeff Kirsher421e02f2008-10-17 11:08:31 -070057#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -070058#include <linux/dca.h>
59#endif
Auke Kok9d5c8242008-01-24 02:22:38 -080060#include "igb.h"
61
Carolyn Wyborny200e5fd2012-05-31 23:39:30 +000062#define MAJ 4
Carolyn Wyborny66999382012-12-05 02:46:05 +000063#define MIN 1
64#define BUILD 2
Carolyn Wyborny0d1fe822011-03-11 20:58:19 -080065#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Carolyn Wyborny929dd042011-05-26 03:02:26 +000066__stringify(BUILD) "-k"
Auke Kok9d5c8242008-01-24 02:22:38 -080067char igb_driver_name[] = "igb";
68char igb_driver_version[] = DRV_VERSION;
69static const char igb_driver_string[] =
70 "Intel(R) Gigabit Ethernet Network Driver";
Carolyn Wyborny6e861322012-01-18 22:13:27 +000071static const char igb_copyright[] = "Copyright (c) 2007-2012 Intel Corporation.";
Auke Kok9d5c8242008-01-24 02:22:38 -080072
Auke Kok9d5c8242008-01-24 02:22:38 -080073static const struct e1000_info *igb_info_tbl[] = {
74 [board_82575] = &e1000_82575_info,
75};
76
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000077static DEFINE_PCI_DEVICE_TABLE(igb_pci_tbl) = {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +000078 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I211_COPPER), board_82575 },
79 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_COPPER), board_82575 },
80 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_FIBER), board_82575 },
81 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SERDES), board_82575 },
82 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SGMII), board_82575 },
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +000083 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_COPPER), board_82575 },
84 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_FIBER), board_82575 },
85 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SERDES), board_82575 },
86 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SGMII), board_82575 },
Alexander Duyck55cac242009-11-19 12:42:21 +000087 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER), board_82575 },
88 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_FIBER), board_82575 },
Carolyn Wyborny6493d242011-01-14 05:33:46 +000089 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_QUAD_FIBER), board_82575 },
Alexander Duyck55cac242009-11-19 12:42:21 +000090 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SERDES), board_82575 },
91 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SGMII), board_82575 },
92 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER_DUAL), board_82575 },
Joseph Gasparakis308fb392010-09-22 17:56:44 +000093 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SGMII), board_82575 },
94 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SERDES), board_82575 },
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +000095 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_BACKPLANE), board_82575 },
96 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SFP), board_82575 },
Alexander Duyck2d064c02008-07-08 15:10:12 -070097 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 },
Alexander Duyck9eb23412009-03-13 20:42:15 +000098 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS), board_82575 },
Alexander Duyck747d49b2009-10-05 06:33:27 +000099 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS_SERDES), board_82575 },
Alexander Duyck2d064c02008-07-08 15:10:12 -0700100 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 },
101 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 },
Alexander Duyck4703bf72009-07-23 18:09:48 +0000102 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES_QUAD), board_82575 },
Carolyn Wybornyb894fa22010-03-19 06:07:48 +0000103 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER_ET2), board_82575 },
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +0000104 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER), board_82575 },
Auke Kok9d5c8242008-01-24 02:22:38 -0800105 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 },
106 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 },
107 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 },
108 /* required last entry */
109 {0, }
110};
111
112MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
113
114void igb_reset(struct igb_adapter *);
115static int igb_setup_all_tx_resources(struct igb_adapter *);
116static int igb_setup_all_rx_resources(struct igb_adapter *);
117static void igb_free_all_tx_resources(struct igb_adapter *);
118static void igb_free_all_rx_resources(struct igb_adapter *);
Alexander Duyck06cf2662009-10-27 15:53:25 +0000119static void igb_setup_mrqc(struct igb_adapter *);
Auke Kok9d5c8242008-01-24 02:22:38 -0800120static int igb_probe(struct pci_dev *, const struct pci_device_id *);
Bill Pemberton9f9a12f2012-12-03 09:24:25 -0500121static void igb_remove(struct pci_dev *pdev);
Auke Kok9d5c8242008-01-24 02:22:38 -0800122static int igb_sw_init(struct igb_adapter *);
123static int igb_open(struct net_device *);
124static int igb_close(struct net_device *);
Stefan Assmann53c7d062012-12-04 06:00:12 +0000125static void igb_configure(struct igb_adapter *);
Auke Kok9d5c8242008-01-24 02:22:38 -0800126static void igb_configure_tx(struct igb_adapter *);
127static void igb_configure_rx(struct igb_adapter *);
Auke Kok9d5c8242008-01-24 02:22:38 -0800128static void igb_clean_all_tx_rings(struct igb_adapter *);
129static void igb_clean_all_rx_rings(struct igb_adapter *);
Mitch Williams3b644cf2008-06-27 10:59:48 -0700130static void igb_clean_tx_ring(struct igb_ring *);
131static void igb_clean_rx_ring(struct igb_ring *);
Alexander Duyckff41f8d2009-09-03 14:48:56 +0000132static void igb_set_rx_mode(struct net_device *);
Auke Kok9d5c8242008-01-24 02:22:38 -0800133static void igb_update_phy_info(unsigned long);
134static void igb_watchdog(unsigned long);
135static void igb_watchdog_task(struct work_struct *);
Alexander Duyckcd392f52011-08-26 07:43:59 +0000136static netdev_tx_t igb_xmit_frame(struct sk_buff *skb, struct net_device *);
Eric Dumazet12dcd862010-10-15 17:27:10 +0000137static struct rtnl_link_stats64 *igb_get_stats64(struct net_device *dev,
138 struct rtnl_link_stats64 *stats);
Auke Kok9d5c8242008-01-24 02:22:38 -0800139static int igb_change_mtu(struct net_device *, int);
140static int igb_set_mac(struct net_device *, void *);
Alexander Duyck68d480c2009-10-05 06:33:08 +0000141static void igb_set_uta(struct igb_adapter *adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800142static irqreturn_t igb_intr(int irq, void *);
143static irqreturn_t igb_intr_msi(int irq, void *);
144static irqreturn_t igb_msix_other(int irq, void *);
Alexander Duyck047e0032009-10-27 15:49:27 +0000145static irqreturn_t igb_msix_ring(int irq, void *);
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700146#ifdef CONFIG_IGB_DCA
Alexander Duyck047e0032009-10-27 15:49:27 +0000147static void igb_update_dca(struct igb_q_vector *);
Jeb Cramerfe4506b2008-07-08 15:07:55 -0700148static void igb_setup_dca(struct igb_adapter *);
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700149#endif /* CONFIG_IGB_DCA */
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -0700150static int igb_poll(struct napi_struct *, int);
Alexander Duyck13fde972011-10-05 13:35:24 +0000151static bool igb_clean_tx_irq(struct igb_q_vector *);
Alexander Duyckcd392f52011-08-26 07:43:59 +0000152static bool igb_clean_rx_irq(struct igb_q_vector *, int);
Auke Kok9d5c8242008-01-24 02:22:38 -0800153static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
154static void igb_tx_timeout(struct net_device *);
155static void igb_reset_task(struct work_struct *);
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000156static void igb_vlan_mode(struct net_device *netdev, netdev_features_t features);
Jiri Pirko8e586132011-12-08 19:52:37 -0500157static int igb_vlan_rx_add_vid(struct net_device *, u16);
158static int igb_vlan_rx_kill_vid(struct net_device *, u16);
Auke Kok9d5c8242008-01-24 02:22:38 -0800159static void igb_restore_vlan(struct igb_adapter *);
Alexander Duyck26ad9172009-10-05 06:32:49 +0000160static void igb_rar_set_qsel(struct igb_adapter *, u8 *, u32 , u8);
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800161static void igb_ping_all_vfs(struct igb_adapter *);
162static void igb_msg_task(struct igb_adapter *);
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800163static void igb_vmm_control(struct igb_adapter *);
Alexander Duyckf2ca0db2009-10-27 23:46:57 +0000164static int igb_set_vf_mac(struct igb_adapter *, int, unsigned char *);
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800165static void igb_restore_vf_multicasts(struct igb_adapter *adapter);
Williams, Mitch A8151d292010-02-10 01:44:24 +0000166static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac);
167static int igb_ndo_set_vf_vlan(struct net_device *netdev,
168 int vf, u16 vlan, u8 qos);
169static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate);
170static int igb_ndo_get_vf_config(struct net_device *netdev, int vf,
171 struct ifla_vf_info *ivi);
Lior Levy17dc5662011-02-08 02:28:46 +0000172static void igb_check_vf_rate_limit(struct igb_adapter *);
RongQing Li46a01692011-10-18 22:52:35 +0000173
174#ifdef CONFIG_PCI_IOV
Greg Rose0224d662011-10-14 02:57:14 +0000175static int igb_vf_configure(struct igb_adapter *adapter, int vf);
Stefan Assmannf5571472012-08-18 04:06:11 +0000176static bool igb_vfs_are_assigned(struct igb_adapter *adapter);
RongQing Li46a01692011-10-18 22:52:35 +0000177#endif
Auke Kok9d5c8242008-01-24 02:22:38 -0800178
Auke Kok9d5c8242008-01-24 02:22:38 -0800179#ifdef CONFIG_PM
Emil Tantilovd9dd9662012-01-28 08:10:35 +0000180#ifdef CONFIG_PM_SLEEP
Yan, Zheng749ab2c2012-01-04 20:23:37 +0000181static int igb_suspend(struct device *);
Emil Tantilovd9dd9662012-01-28 08:10:35 +0000182#endif
Yan, Zheng749ab2c2012-01-04 20:23:37 +0000183static int igb_resume(struct device *);
184#ifdef CONFIG_PM_RUNTIME
185static int igb_runtime_suspend(struct device *dev);
186static int igb_runtime_resume(struct device *dev);
187static int igb_runtime_idle(struct device *dev);
188#endif
189static const struct dev_pm_ops igb_pm_ops = {
190 SET_SYSTEM_SLEEP_PM_OPS(igb_suspend, igb_resume)
191 SET_RUNTIME_PM_OPS(igb_runtime_suspend, igb_runtime_resume,
192 igb_runtime_idle)
193};
Auke Kok9d5c8242008-01-24 02:22:38 -0800194#endif
195static void igb_shutdown(struct pci_dev *);
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700196#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -0700197static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
198static struct notifier_block dca_notifier = {
199 .notifier_call = igb_notify_dca,
200 .next = NULL,
201 .priority = 0
202};
203#endif
Auke Kok9d5c8242008-01-24 02:22:38 -0800204#ifdef CONFIG_NET_POLL_CONTROLLER
205/* for netdump / net console */
206static void igb_netpoll(struct net_device *);
207#endif
Alexander Duyck37680112009-02-19 20:40:30 -0800208#ifdef CONFIG_PCI_IOV
Alexander Duyck2a3abf62009-04-07 14:37:52 +0000209static unsigned int max_vfs = 0;
210module_param(max_vfs, uint, 0);
211MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate "
212 "per physical function");
213#endif /* CONFIG_PCI_IOV */
214
Auke Kok9d5c8242008-01-24 02:22:38 -0800215static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
216 pci_channel_state_t);
217static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
218static void igb_io_resume(struct pci_dev *);
219
Stephen Hemminger3646f0e2012-09-07 09:33:15 -0700220static const struct pci_error_handlers igb_err_handler = {
Auke Kok9d5c8242008-01-24 02:22:38 -0800221 .error_detected = igb_io_error_detected,
222 .slot_reset = igb_io_slot_reset,
223 .resume = igb_io_resume,
224};
225
Carolyn Wybornyb6e0c412011-10-13 17:29:59 +0000226static void igb_init_dmac(struct igb_adapter *adapter, u32 pba);
Auke Kok9d5c8242008-01-24 02:22:38 -0800227
228static struct pci_driver igb_driver = {
229 .name = igb_driver_name,
230 .id_table = igb_pci_tbl,
231 .probe = igb_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -0500232 .remove = igb_remove,
Auke Kok9d5c8242008-01-24 02:22:38 -0800233#ifdef CONFIG_PM
Yan, Zheng749ab2c2012-01-04 20:23:37 +0000234 .driver.pm = &igb_pm_ops,
Auke Kok9d5c8242008-01-24 02:22:38 -0800235#endif
236 .shutdown = igb_shutdown,
237 .err_handler = &igb_err_handler
238};
239
240MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
241MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
242MODULE_LICENSE("GPL");
243MODULE_VERSION(DRV_VERSION);
244
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000245#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
246static int debug = -1;
247module_param(debug, int, 0);
248MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
249
Taku Izumic97ec422010-04-27 14:39:30 +0000250struct igb_reg_info {
251 u32 ofs;
252 char *name;
253};
254
255static const struct igb_reg_info igb_reg_info_tbl[] = {
256
257 /* General Registers */
258 {E1000_CTRL, "CTRL"},
259 {E1000_STATUS, "STATUS"},
260 {E1000_CTRL_EXT, "CTRL_EXT"},
261
262 /* Interrupt Registers */
263 {E1000_ICR, "ICR"},
264
265 /* RX Registers */
266 {E1000_RCTL, "RCTL"},
267 {E1000_RDLEN(0), "RDLEN"},
268 {E1000_RDH(0), "RDH"},
269 {E1000_RDT(0), "RDT"},
270 {E1000_RXDCTL(0), "RXDCTL"},
271 {E1000_RDBAL(0), "RDBAL"},
272 {E1000_RDBAH(0), "RDBAH"},
273
274 /* TX Registers */
275 {E1000_TCTL, "TCTL"},
276 {E1000_TDBAL(0), "TDBAL"},
277 {E1000_TDBAH(0), "TDBAH"},
278 {E1000_TDLEN(0), "TDLEN"},
279 {E1000_TDH(0), "TDH"},
280 {E1000_TDT(0), "TDT"},
281 {E1000_TXDCTL(0), "TXDCTL"},
282 {E1000_TDFH, "TDFH"},
283 {E1000_TDFT, "TDFT"},
284 {E1000_TDFHS, "TDFHS"},
285 {E1000_TDFPC, "TDFPC"},
286
287 /* List Terminator */
288 {}
289};
290
291/*
292 * igb_regdump - register printout routine
293 */
294static void igb_regdump(struct e1000_hw *hw, struct igb_reg_info *reginfo)
295{
296 int n = 0;
297 char rname[16];
298 u32 regs[8];
299
300 switch (reginfo->ofs) {
301 case E1000_RDLEN(0):
302 for (n = 0; n < 4; n++)
303 regs[n] = rd32(E1000_RDLEN(n));
304 break;
305 case E1000_RDH(0):
306 for (n = 0; n < 4; n++)
307 regs[n] = rd32(E1000_RDH(n));
308 break;
309 case E1000_RDT(0):
310 for (n = 0; n < 4; n++)
311 regs[n] = rd32(E1000_RDT(n));
312 break;
313 case E1000_RXDCTL(0):
314 for (n = 0; n < 4; n++)
315 regs[n] = rd32(E1000_RXDCTL(n));
316 break;
317 case E1000_RDBAL(0):
318 for (n = 0; n < 4; n++)
319 regs[n] = rd32(E1000_RDBAL(n));
320 break;
321 case E1000_RDBAH(0):
322 for (n = 0; n < 4; n++)
323 regs[n] = rd32(E1000_RDBAH(n));
324 break;
325 case E1000_TDBAL(0):
326 for (n = 0; n < 4; n++)
327 regs[n] = rd32(E1000_RDBAL(n));
328 break;
329 case E1000_TDBAH(0):
330 for (n = 0; n < 4; n++)
331 regs[n] = rd32(E1000_TDBAH(n));
332 break;
333 case E1000_TDLEN(0):
334 for (n = 0; n < 4; n++)
335 regs[n] = rd32(E1000_TDLEN(n));
336 break;
337 case E1000_TDH(0):
338 for (n = 0; n < 4; n++)
339 regs[n] = rd32(E1000_TDH(n));
340 break;
341 case E1000_TDT(0):
342 for (n = 0; n < 4; n++)
343 regs[n] = rd32(E1000_TDT(n));
344 break;
345 case E1000_TXDCTL(0):
346 for (n = 0; n < 4; n++)
347 regs[n] = rd32(E1000_TXDCTL(n));
348 break;
349 default:
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000350 pr_info("%-15s %08x\n", reginfo->name, rd32(reginfo->ofs));
Taku Izumic97ec422010-04-27 14:39:30 +0000351 return;
352 }
353
354 snprintf(rname, 16, "%s%s", reginfo->name, "[0-3]");
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000355 pr_info("%-15s %08x %08x %08x %08x\n", rname, regs[0], regs[1],
356 regs[2], regs[3]);
Taku Izumic97ec422010-04-27 14:39:30 +0000357}
358
359/*
360 * igb_dump - Print registers, tx-rings and rx-rings
361 */
362static void igb_dump(struct igb_adapter *adapter)
363{
364 struct net_device *netdev = adapter->netdev;
365 struct e1000_hw *hw = &adapter->hw;
366 struct igb_reg_info *reginfo;
Taku Izumic97ec422010-04-27 14:39:30 +0000367 struct igb_ring *tx_ring;
368 union e1000_adv_tx_desc *tx_desc;
369 struct my_u0 { u64 a; u64 b; } *u0;
Taku Izumic97ec422010-04-27 14:39:30 +0000370 struct igb_ring *rx_ring;
371 union e1000_adv_rx_desc *rx_desc;
372 u32 staterr;
Alexander Duyck6ad4edf2011-08-26 07:45:26 +0000373 u16 i, n;
Taku Izumic97ec422010-04-27 14:39:30 +0000374
375 if (!netif_msg_hw(adapter))
376 return;
377
378 /* Print netdevice Info */
379 if (netdev) {
380 dev_info(&adapter->pdev->dev, "Net device Info\n");
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000381 pr_info("Device Name state trans_start "
382 "last_rx\n");
383 pr_info("%-15s %016lX %016lX %016lX\n", netdev->name,
384 netdev->state, netdev->trans_start, netdev->last_rx);
Taku Izumic97ec422010-04-27 14:39:30 +0000385 }
386
387 /* Print Registers */
388 dev_info(&adapter->pdev->dev, "Register Dump\n");
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000389 pr_info(" Register Name Value\n");
Taku Izumic97ec422010-04-27 14:39:30 +0000390 for (reginfo = (struct igb_reg_info *)igb_reg_info_tbl;
391 reginfo->name; reginfo++) {
392 igb_regdump(hw, reginfo);
393 }
394
395 /* Print TX Ring Summary */
396 if (!netdev || !netif_running(netdev))
397 goto exit;
398
399 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000400 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumic97ec422010-04-27 14:39:30 +0000401 for (n = 0; n < adapter->num_tx_queues; n++) {
Alexander Duyck06034642011-08-26 07:44:22 +0000402 struct igb_tx_buffer *buffer_info;
Taku Izumic97ec422010-04-27 14:39:30 +0000403 tx_ring = adapter->tx_ring[n];
Alexander Duyck06034642011-08-26 07:44:22 +0000404 buffer_info = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000405 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
406 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyckc9f14bf32012-09-18 01:56:27 +0000407 (u64)dma_unmap_addr(buffer_info, dma),
408 dma_unmap_len(buffer_info, len),
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000409 buffer_info->next_to_watch,
410 (u64)buffer_info->time_stamp);
Taku Izumic97ec422010-04-27 14:39:30 +0000411 }
412
413 /* Print TX Rings */
414 if (!netif_msg_tx_done(adapter))
415 goto rx_ring_summary;
416
417 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
418
419 /* Transmit Descriptor Formats
420 *
421 * Advanced Transmit Descriptor
422 * +--------------------------------------------------------------+
423 * 0 | Buffer Address [63:0] |
424 * +--------------------------------------------------------------+
425 * 8 | PAYLEN | PORTS |CC|IDX | STA | DCMD |DTYP|MAC|RSV| DTALEN |
426 * +--------------------------------------------------------------+
427 * 63 46 45 40 39 38 36 35 32 31 24 15 0
428 */
429
430 for (n = 0; n < adapter->num_tx_queues; n++) {
431 tx_ring = adapter->tx_ring[n];
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000432 pr_info("------------------------------------\n");
433 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
434 pr_info("------------------------------------\n");
435 pr_info("T [desc] [address 63:0 ] [PlPOCIStDDM Ln] "
436 "[bi->dma ] leng ntw timestamp "
437 "bi->skb\n");
Taku Izumic97ec422010-04-27 14:39:30 +0000438
439 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000440 const char *next_desc;
Alexander Duyck06034642011-08-26 07:44:22 +0000441 struct igb_tx_buffer *buffer_info;
Alexander Duyck601369062011-08-26 07:44:05 +0000442 tx_desc = IGB_TX_DESC(tx_ring, i);
Alexander Duyck06034642011-08-26 07:44:22 +0000443 buffer_info = &tx_ring->tx_buffer_info[i];
Taku Izumic97ec422010-04-27 14:39:30 +0000444 u0 = (struct my_u0 *)tx_desc;
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000445 if (i == tx_ring->next_to_use &&
446 i == tx_ring->next_to_clean)
447 next_desc = " NTC/U";
448 else if (i == tx_ring->next_to_use)
449 next_desc = " NTU";
450 else if (i == tx_ring->next_to_clean)
451 next_desc = " NTC";
452 else
453 next_desc = "";
454
455 pr_info("T [0x%03X] %016llX %016llX %016llX"
456 " %04X %p %016llX %p%s\n", i,
Taku Izumic97ec422010-04-27 14:39:30 +0000457 le64_to_cpu(u0->a),
458 le64_to_cpu(u0->b),
Alexander Duyckc9f14bf32012-09-18 01:56:27 +0000459 (u64)dma_unmap_addr(buffer_info, dma),
460 dma_unmap_len(buffer_info, len),
Taku Izumic97ec422010-04-27 14:39:30 +0000461 buffer_info->next_to_watch,
462 (u64)buffer_info->time_stamp,
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000463 buffer_info->skb, next_desc);
Taku Izumic97ec422010-04-27 14:39:30 +0000464
Emil Tantilovb6695882012-07-28 05:07:48 +0000465 if (netif_msg_pktdata(adapter) && buffer_info->skb)
Taku Izumic97ec422010-04-27 14:39:30 +0000466 print_hex_dump(KERN_INFO, "",
467 DUMP_PREFIX_ADDRESS,
Emil Tantilovb6695882012-07-28 05:07:48 +0000468 16, 1, buffer_info->skb->data,
Alexander Duyckc9f14bf32012-09-18 01:56:27 +0000469 dma_unmap_len(buffer_info, len),
470 true);
Taku Izumic97ec422010-04-27 14:39:30 +0000471 }
472 }
473
474 /* Print RX Rings Summary */
475rx_ring_summary:
476 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000477 pr_info("Queue [NTU] [NTC]\n");
Taku Izumic97ec422010-04-27 14:39:30 +0000478 for (n = 0; n < adapter->num_rx_queues; n++) {
479 rx_ring = adapter->rx_ring[n];
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000480 pr_info(" %5d %5X %5X\n",
481 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumic97ec422010-04-27 14:39:30 +0000482 }
483
484 /* Print RX Rings */
485 if (!netif_msg_rx_status(adapter))
486 goto exit;
487
488 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
489
490 /* Advanced Receive Descriptor (Read) Format
491 * 63 1 0
492 * +-----------------------------------------------------+
493 * 0 | Packet Buffer Address [63:1] |A0/NSE|
494 * +----------------------------------------------+------+
495 * 8 | Header Buffer Address [63:1] | DD |
496 * +-----------------------------------------------------+
497 *
498 *
499 * Advanced Receive Descriptor (Write-Back) Format
500 *
501 * 63 48 47 32 31 30 21 20 17 16 4 3 0
502 * +------------------------------------------------------+
503 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
504 * | Checksum Ident | | | | Type | Type |
505 * +------------------------------------------------------+
506 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
507 * +------------------------------------------------------+
508 * 63 48 47 32 31 20 19 0
509 */
510
511 for (n = 0; n < adapter->num_rx_queues; n++) {
512 rx_ring = adapter->rx_ring[n];
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000513 pr_info("------------------------------------\n");
514 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
515 pr_info("------------------------------------\n");
516 pr_info("R [desc] [ PktBuf A0] [ HeadBuf DD] "
517 "[bi->dma ] [bi->skb] <-- Adv Rx Read format\n");
518 pr_info("RWB[desc] [PcsmIpSHl PtRs] [vl er S cks ln] -----"
519 "----------- [bi->skb] <-- Adv Rx Write-Back format\n");
Taku Izumic97ec422010-04-27 14:39:30 +0000520
521 for (i = 0; i < rx_ring->count; i++) {
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000522 const char *next_desc;
Alexander Duyck06034642011-08-26 07:44:22 +0000523 struct igb_rx_buffer *buffer_info;
524 buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duyck601369062011-08-26 07:44:05 +0000525 rx_desc = IGB_RX_DESC(rx_ring, i);
Taku Izumic97ec422010-04-27 14:39:30 +0000526 u0 = (struct my_u0 *)rx_desc;
527 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000528
529 if (i == rx_ring->next_to_use)
530 next_desc = " NTU";
531 else if (i == rx_ring->next_to_clean)
532 next_desc = " NTC";
533 else
534 next_desc = "";
535
Taku Izumic97ec422010-04-27 14:39:30 +0000536 if (staterr & E1000_RXD_STAT_DD) {
537 /* Descriptor Done */
Alexander Duyck1a1c2252012-09-25 00:30:52 +0000538 pr_info("%s[0x%03X] %016llX %016llX ---------------- %s\n",
539 "RWB", i,
Taku Izumic97ec422010-04-27 14:39:30 +0000540 le64_to_cpu(u0->a),
541 le64_to_cpu(u0->b),
Alexander Duyck1a1c2252012-09-25 00:30:52 +0000542 next_desc);
Taku Izumic97ec422010-04-27 14:39:30 +0000543 } else {
Alexander Duyck1a1c2252012-09-25 00:30:52 +0000544 pr_info("%s[0x%03X] %016llX %016llX %016llX %s\n",
545 "R ", i,
Taku Izumic97ec422010-04-27 14:39:30 +0000546 le64_to_cpu(u0->a),
547 le64_to_cpu(u0->b),
548 (u64)buffer_info->dma,
Alexander Duyck1a1c2252012-09-25 00:30:52 +0000549 next_desc);
Taku Izumic97ec422010-04-27 14:39:30 +0000550
Emil Tantilovb6695882012-07-28 05:07:48 +0000551 if (netif_msg_pktdata(adapter) &&
Alexander Duyck1a1c2252012-09-25 00:30:52 +0000552 buffer_info->dma && buffer_info->page) {
Alexander Duyck44390ca2011-08-26 07:43:38 +0000553 print_hex_dump(KERN_INFO, "",
554 DUMP_PREFIX_ADDRESS,
555 16, 1,
Emil Tantilovb6695882012-07-28 05:07:48 +0000556 page_address(buffer_info->page) +
557 buffer_info->page_offset,
Alexander Duyckde78d1f2012-09-25 00:31:12 +0000558 IGB_RX_BUFSZ, true);
Taku Izumic97ec422010-04-27 14:39:30 +0000559 }
560 }
Taku Izumic97ec422010-04-27 14:39:30 +0000561 }
562 }
563
564exit:
565 return;
566}
567
Auke Kok9d5c8242008-01-24 02:22:38 -0800568/**
Alexander Duyckc0410762010-03-25 13:10:08 +0000569 * igb_get_hw_dev - return device
Auke Kok9d5c8242008-01-24 02:22:38 -0800570 * used by hardware layer to print debugging information
571 **/
Alexander Duyckc0410762010-03-25 13:10:08 +0000572struct net_device *igb_get_hw_dev(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -0800573{
574 struct igb_adapter *adapter = hw->back;
Alexander Duyckc0410762010-03-25 13:10:08 +0000575 return adapter->netdev;
Auke Kok9d5c8242008-01-24 02:22:38 -0800576}
Patrick Ohly38c845c2009-02-12 05:03:41 +0000577
578/**
Auke Kok9d5c8242008-01-24 02:22:38 -0800579 * igb_init_module - Driver Registration Routine
580 *
581 * igb_init_module is the first routine called when the driver is
582 * loaded. All it does is register with the PCI subsystem.
583 **/
584static int __init igb_init_module(void)
585{
586 int ret;
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000587 pr_info("%s - version %s\n",
Auke Kok9d5c8242008-01-24 02:22:38 -0800588 igb_driver_string, igb_driver_version);
589
Jeff Kirsher876d2d62011-10-21 20:01:34 +0000590 pr_info("%s\n", igb_copyright);
Auke Kok9d5c8242008-01-24 02:22:38 -0800591
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700592#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -0700593 dca_register_notify(&dca_notifier);
594#endif
Alexander Duyckbbd98fe2009-01-31 00:52:30 -0800595 ret = pci_register_driver(&igb_driver);
Auke Kok9d5c8242008-01-24 02:22:38 -0800596 return ret;
597}
598
599module_init(igb_init_module);
600
601/**
602 * igb_exit_module - Driver Exit Cleanup Routine
603 *
604 * igb_exit_module is called just before the driver is removed
605 * from memory.
606 **/
607static void __exit igb_exit_module(void)
608{
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700609#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -0700610 dca_unregister_notify(&dca_notifier);
611#endif
Auke Kok9d5c8242008-01-24 02:22:38 -0800612 pci_unregister_driver(&igb_driver);
613}
614
615module_exit(igb_exit_module);
616
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800617#define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
618/**
619 * igb_cache_ring_register - Descriptor ring to register mapping
620 * @adapter: board private structure to initialize
621 *
622 * Once we know the feature-set enabled for the device, we'll cache
623 * the register offset the descriptor ring is assigned to.
624 **/
625static void igb_cache_ring_register(struct igb_adapter *adapter)
626{
Alexander Duyckee1b9f02009-10-27 23:49:40 +0000627 int i = 0, j = 0;
Alexander Duyck047e0032009-10-27 15:49:27 +0000628 u32 rbase_offset = adapter->vfs_allocated_count;
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800629
630 switch (adapter->hw.mac.type) {
631 case e1000_82576:
632 /* The queues are allocated for virtualization such that VF 0
633 * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
634 * In order to avoid collision we start at the first free queue
635 * and continue consuming queues in the same sequence
636 */
Alexander Duyckee1b9f02009-10-27 23:49:40 +0000637 if (adapter->vfs_allocated_count) {
Alexander Duycka99955f2009-11-12 18:37:19 +0000638 for (; i < adapter->rss_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +0000639 adapter->rx_ring[i]->reg_idx = rbase_offset +
640 Q_IDX_82576(i);
Alexander Duyckee1b9f02009-10-27 23:49:40 +0000641 }
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800642 case e1000_82575:
Alexander Duyck55cac242009-11-19 12:42:21 +0000643 case e1000_82580:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000644 case e1000_i350:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000645 case e1000_i210:
646 case e1000_i211:
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800647 default:
Alexander Duyckee1b9f02009-10-27 23:49:40 +0000648 for (; i < adapter->num_rx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +0000649 adapter->rx_ring[i]->reg_idx = rbase_offset + i;
Alexander Duyckee1b9f02009-10-27 23:49:40 +0000650 for (; j < adapter->num_tx_queues; j++)
Alexander Duyck3025a442010-02-17 01:02:39 +0000651 adapter->tx_ring[j]->reg_idx = rbase_offset + j;
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800652 break;
653 }
654}
655
Alexander Duyck4be000c2011-08-26 07:45:52 +0000656/**
657 * igb_write_ivar - configure ivar for given MSI-X vector
658 * @hw: pointer to the HW structure
659 * @msix_vector: vector number we are allocating to a given ring
660 * @index: row index of IVAR register to write within IVAR table
661 * @offset: column offset of in IVAR, should be multiple of 8
662 *
663 * This function is intended to handle the writing of the IVAR register
664 * for adapters 82576 and newer. The IVAR table consists of 2 columns,
665 * each containing an cause allocation for an Rx and Tx ring, and a
666 * variable number of rows depending on the number of queues supported.
667 **/
668static void igb_write_ivar(struct e1000_hw *hw, int msix_vector,
669 int index, int offset)
670{
671 u32 ivar = array_rd32(E1000_IVAR0, index);
672
673 /* clear any bits that are currently set */
674 ivar &= ~((u32)0xFF << offset);
675
676 /* write vector and valid bit */
677 ivar |= (msix_vector | E1000_IVAR_VALID) << offset;
678
679 array_wr32(E1000_IVAR0, index, ivar);
680}
681
Auke Kok9d5c8242008-01-24 02:22:38 -0800682#define IGB_N0_QUEUE -1
Alexander Duyck047e0032009-10-27 15:49:27 +0000683static void igb_assign_vector(struct igb_q_vector *q_vector, int msix_vector)
Auke Kok9d5c8242008-01-24 02:22:38 -0800684{
Alexander Duyck047e0032009-10-27 15:49:27 +0000685 struct igb_adapter *adapter = q_vector->adapter;
Auke Kok9d5c8242008-01-24 02:22:38 -0800686 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck047e0032009-10-27 15:49:27 +0000687 int rx_queue = IGB_N0_QUEUE;
688 int tx_queue = IGB_N0_QUEUE;
Alexander Duyck4be000c2011-08-26 07:45:52 +0000689 u32 msixbm = 0;
Alexander Duyck047e0032009-10-27 15:49:27 +0000690
Alexander Duyck0ba82992011-08-26 07:45:47 +0000691 if (q_vector->rx.ring)
692 rx_queue = q_vector->rx.ring->reg_idx;
693 if (q_vector->tx.ring)
694 tx_queue = q_vector->tx.ring->reg_idx;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700695
696 switch (hw->mac.type) {
697 case e1000_82575:
Auke Kok9d5c8242008-01-24 02:22:38 -0800698 /* The 82575 assigns vectors using a bitmask, which matches the
699 bitmask for the EICR/EIMS/EIMC registers. To assign one
700 or more queues to a vector, we write the appropriate bits
701 into the MSIXBM register for that vector. */
Alexander Duyck047e0032009-10-27 15:49:27 +0000702 if (rx_queue > IGB_N0_QUEUE)
Auke Kok9d5c8242008-01-24 02:22:38 -0800703 msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
Alexander Duyck047e0032009-10-27 15:49:27 +0000704 if (tx_queue > IGB_N0_QUEUE)
Auke Kok9d5c8242008-01-24 02:22:38 -0800705 msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
Alexander Duyckfeeb2722010-02-03 21:59:51 +0000706 if (!adapter->msix_entries && msix_vector == 0)
707 msixbm |= E1000_EIMS_OTHER;
Auke Kok9d5c8242008-01-24 02:22:38 -0800708 array_wr32(E1000_MSIXBM(0), msix_vector, msixbm);
Alexander Duyck047e0032009-10-27 15:49:27 +0000709 q_vector->eims_value = msixbm;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700710 break;
711 case e1000_82576:
Alexander Duyck4be000c2011-08-26 07:45:52 +0000712 /*
713 * 82576 uses a table that essentially consists of 2 columns
714 * with 8 rows. The ordering is column-major so we use the
715 * lower 3 bits as the row index, and the 4th bit as the
716 * column offset.
717 */
718 if (rx_queue > IGB_N0_QUEUE)
719 igb_write_ivar(hw, msix_vector,
720 rx_queue & 0x7,
721 (rx_queue & 0x8) << 1);
722 if (tx_queue > IGB_N0_QUEUE)
723 igb_write_ivar(hw, msix_vector,
724 tx_queue & 0x7,
725 ((tx_queue & 0x8) << 1) + 8);
Alexander Duyck047e0032009-10-27 15:49:27 +0000726 q_vector->eims_value = 1 << msix_vector;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700727 break;
Alexander Duyck55cac242009-11-19 12:42:21 +0000728 case e1000_82580:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000729 case e1000_i350:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000730 case e1000_i210:
731 case e1000_i211:
Alexander Duyck4be000c2011-08-26 07:45:52 +0000732 /*
733 * On 82580 and newer adapters the scheme is similar to 82576
734 * however instead of ordering column-major we have things
735 * ordered row-major. So we traverse the table by using
736 * bit 0 as the column offset, and the remaining bits as the
737 * row index.
738 */
739 if (rx_queue > IGB_N0_QUEUE)
740 igb_write_ivar(hw, msix_vector,
741 rx_queue >> 1,
742 (rx_queue & 0x1) << 4);
743 if (tx_queue > IGB_N0_QUEUE)
744 igb_write_ivar(hw, msix_vector,
745 tx_queue >> 1,
746 ((tx_queue & 0x1) << 4) + 8);
Alexander Duyck55cac242009-11-19 12:42:21 +0000747 q_vector->eims_value = 1 << msix_vector;
748 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700749 default:
750 BUG();
751 break;
752 }
Alexander Duyck26b39272010-02-17 01:00:41 +0000753
754 /* add q_vector eims value to global eims_enable_mask */
755 adapter->eims_enable_mask |= q_vector->eims_value;
756
757 /* configure q_vector to set itr on first interrupt */
758 q_vector->set_itr = 1;
Auke Kok9d5c8242008-01-24 02:22:38 -0800759}
760
761/**
762 * igb_configure_msix - Configure MSI-X hardware
763 *
764 * igb_configure_msix sets up the hardware to properly
765 * generate MSI-X interrupts.
766 **/
767static void igb_configure_msix(struct igb_adapter *adapter)
768{
769 u32 tmp;
770 int i, vector = 0;
771 struct e1000_hw *hw = &adapter->hw;
772
773 adapter->eims_enable_mask = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800774
775 /* set vector for other causes, i.e. link changes */
Alexander Duyck2d064c02008-07-08 15:10:12 -0700776 switch (hw->mac.type) {
777 case e1000_82575:
Auke Kok9d5c8242008-01-24 02:22:38 -0800778 tmp = rd32(E1000_CTRL_EXT);
779 /* enable MSI-X PBA support*/
780 tmp |= E1000_CTRL_EXT_PBA_CLR;
781
782 /* Auto-Mask interrupts upon ICR read. */
783 tmp |= E1000_CTRL_EXT_EIAME;
784 tmp |= E1000_CTRL_EXT_IRCA;
785
786 wr32(E1000_CTRL_EXT, tmp);
Alexander Duyck047e0032009-10-27 15:49:27 +0000787
788 /* enable msix_other interrupt */
789 array_wr32(E1000_MSIXBM(0), vector++,
790 E1000_EIMS_OTHER);
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700791 adapter->eims_other = E1000_EIMS_OTHER;
Auke Kok9d5c8242008-01-24 02:22:38 -0800792
Alexander Duyck2d064c02008-07-08 15:10:12 -0700793 break;
794
795 case e1000_82576:
Alexander Duyck55cac242009-11-19 12:42:21 +0000796 case e1000_82580:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000797 case e1000_i350:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000798 case e1000_i210:
799 case e1000_i211:
Alexander Duyck047e0032009-10-27 15:49:27 +0000800 /* Turn on MSI-X capability first, or our settings
801 * won't stick. And it will take days to debug. */
802 wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE |
803 E1000_GPIE_PBA | E1000_GPIE_EIAME |
804 E1000_GPIE_NSICR);
Alexander Duyck2d064c02008-07-08 15:10:12 -0700805
Alexander Duyck047e0032009-10-27 15:49:27 +0000806 /* enable msix_other interrupt */
807 adapter->eims_other = 1 << vector;
808 tmp = (vector++ | E1000_IVAR_VALID) << 8;
809
810 wr32(E1000_IVAR_MISC, tmp);
Alexander Duyck2d064c02008-07-08 15:10:12 -0700811 break;
812 default:
813 /* do nothing, since nothing else supports MSI-X */
814 break;
815 } /* switch (hw->mac.type) */
Alexander Duyck047e0032009-10-27 15:49:27 +0000816
817 adapter->eims_enable_mask |= adapter->eims_other;
818
Alexander Duyck26b39272010-02-17 01:00:41 +0000819 for (i = 0; i < adapter->num_q_vectors; i++)
820 igb_assign_vector(adapter->q_vector[i], vector++);
Alexander Duyck047e0032009-10-27 15:49:27 +0000821
Auke Kok9d5c8242008-01-24 02:22:38 -0800822 wrfl();
823}
824
825/**
826 * igb_request_msix - Initialize MSI-X interrupts
827 *
828 * igb_request_msix allocates MSI-X vectors and requests interrupts from the
829 * kernel.
830 **/
831static int igb_request_msix(struct igb_adapter *adapter)
832{
833 struct net_device *netdev = adapter->netdev;
Alexander Duyck047e0032009-10-27 15:49:27 +0000834 struct e1000_hw *hw = &adapter->hw;
Stefan Assmann52285b72012-12-04 06:00:17 +0000835 int i, err = 0, vector = 0, free_vector = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800836
Auke Kok9d5c8242008-01-24 02:22:38 -0800837 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -0800838 igb_msix_other, 0, netdev->name, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800839 if (err)
Stefan Assmann52285b72012-12-04 06:00:17 +0000840 goto err_out;
Alexander Duyck047e0032009-10-27 15:49:27 +0000841
842 for (i = 0; i < adapter->num_q_vectors; i++) {
843 struct igb_q_vector *q_vector = adapter->q_vector[i];
844
Stefan Assmann52285b72012-12-04 06:00:17 +0000845 vector++;
846
Alexander Duyck047e0032009-10-27 15:49:27 +0000847 q_vector->itr_register = hw->hw_addr + E1000_EITR(vector);
848
Alexander Duyck0ba82992011-08-26 07:45:47 +0000849 if (q_vector->rx.ring && q_vector->tx.ring)
Alexander Duyck047e0032009-10-27 15:49:27 +0000850 sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
Alexander Duyck0ba82992011-08-26 07:45:47 +0000851 q_vector->rx.ring->queue_index);
852 else if (q_vector->tx.ring)
Alexander Duyck047e0032009-10-27 15:49:27 +0000853 sprintf(q_vector->name, "%s-tx-%u", netdev->name,
Alexander Duyck0ba82992011-08-26 07:45:47 +0000854 q_vector->tx.ring->queue_index);
855 else if (q_vector->rx.ring)
Alexander Duyck047e0032009-10-27 15:49:27 +0000856 sprintf(q_vector->name, "%s-rx-%u", netdev->name,
Alexander Duyck0ba82992011-08-26 07:45:47 +0000857 q_vector->rx.ring->queue_index);
Alexander Duyck047e0032009-10-27 15:49:27 +0000858 else
859 sprintf(q_vector->name, "%s-unused", netdev->name);
860
861 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -0800862 igb_msix_ring, 0, q_vector->name,
Alexander Duyck047e0032009-10-27 15:49:27 +0000863 q_vector);
864 if (err)
Stefan Assmann52285b72012-12-04 06:00:17 +0000865 goto err_free;
Alexander Duyck047e0032009-10-27 15:49:27 +0000866 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800867
Auke Kok9d5c8242008-01-24 02:22:38 -0800868 igb_configure_msix(adapter);
869 return 0;
Stefan Assmann52285b72012-12-04 06:00:17 +0000870
871err_free:
872 /* free already assigned IRQs */
873 free_irq(adapter->msix_entries[free_vector++].vector, adapter);
874
875 vector--;
876 for (i = 0; i < vector; i++) {
877 free_irq(adapter->msix_entries[free_vector++].vector,
878 adapter->q_vector[i]);
879 }
880err_out:
Auke Kok9d5c8242008-01-24 02:22:38 -0800881 return err;
882}
883
884static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
885{
886 if (adapter->msix_entries) {
887 pci_disable_msix(adapter->pdev);
888 kfree(adapter->msix_entries);
889 adapter->msix_entries = NULL;
Alexander Duyck047e0032009-10-27 15:49:27 +0000890 } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800891 pci_disable_msi(adapter->pdev);
Alexander Duyck047e0032009-10-27 15:49:27 +0000892 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800893}
894
Alexander Duyck047e0032009-10-27 15:49:27 +0000895/**
Alexander Duyck5536d212012-09-25 00:31:17 +0000896 * igb_free_q_vector - Free memory allocated for specific interrupt vector
897 * @adapter: board private structure to initialize
898 * @v_idx: Index of vector to be freed
899 *
900 * This function frees the memory allocated to the q_vector. In addition if
901 * NAPI is enabled it will delete any references to the NAPI struct prior
902 * to freeing the q_vector.
903 **/
904static void igb_free_q_vector(struct igb_adapter *adapter, int v_idx)
905{
906 struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
907
908 if (q_vector->tx.ring)
909 adapter->tx_ring[q_vector->tx.ring->queue_index] = NULL;
910
911 if (q_vector->rx.ring)
912 adapter->tx_ring[q_vector->rx.ring->queue_index] = NULL;
913
914 adapter->q_vector[v_idx] = NULL;
915 netif_napi_del(&q_vector->napi);
916
917 /*
918 * ixgbe_get_stats64() might access the rings on this vector,
919 * we must wait a grace period before freeing it.
920 */
921 kfree_rcu(q_vector, rcu);
922}
923
924/**
Alexander Duyck047e0032009-10-27 15:49:27 +0000925 * igb_free_q_vectors - Free memory allocated for interrupt vectors
926 * @adapter: board private structure to initialize
927 *
928 * This function frees the memory allocated to the q_vectors. In addition if
929 * NAPI is enabled it will delete any references to the NAPI struct prior
930 * to freeing the q_vector.
931 **/
932static void igb_free_q_vectors(struct igb_adapter *adapter)
933{
Alexander Duyck5536d212012-09-25 00:31:17 +0000934 int v_idx = adapter->num_q_vectors;
Alexander Duyck047e0032009-10-27 15:49:27 +0000935
Alexander Duyck5536d212012-09-25 00:31:17 +0000936 adapter->num_tx_queues = 0;
937 adapter->num_rx_queues = 0;
Alexander Duyck047e0032009-10-27 15:49:27 +0000938 adapter->num_q_vectors = 0;
Alexander Duyck5536d212012-09-25 00:31:17 +0000939
940 while (v_idx--)
941 igb_free_q_vector(adapter, v_idx);
Alexander Duyck047e0032009-10-27 15:49:27 +0000942}
943
944/**
945 * igb_clear_interrupt_scheme - reset the device to a state of no interrupts
946 *
947 * This function resets the device so that it has 0 rx queues, tx queues, and
948 * MSI-X interrupts allocated.
949 */
950static void igb_clear_interrupt_scheme(struct igb_adapter *adapter)
951{
Alexander Duyck047e0032009-10-27 15:49:27 +0000952 igb_free_q_vectors(adapter);
953 igb_reset_interrupt_capability(adapter);
954}
Auke Kok9d5c8242008-01-24 02:22:38 -0800955
956/**
957 * igb_set_interrupt_capability - set MSI or MSI-X if supported
958 *
959 * Attempt to configure interrupts using the best available
960 * capabilities of the hardware and kernel.
961 **/
Stefan Assmann53c7d062012-12-04 06:00:12 +0000962static void igb_set_interrupt_capability(struct igb_adapter *adapter, bool msix)
Auke Kok9d5c8242008-01-24 02:22:38 -0800963{
964 int err;
965 int numvecs, i;
966
Stefan Assmann53c7d062012-12-04 06:00:12 +0000967 if (!msix)
968 goto msi_only;
969
Alexander Duyck83b71802009-02-06 23:15:45 +0000970 /* Number of supported queues. */
Alexander Duycka99955f2009-11-12 18:37:19 +0000971 adapter->num_rx_queues = adapter->rss_queues;
Greg Rose5fa85172010-07-01 13:38:16 +0000972 if (adapter->vfs_allocated_count)
973 adapter->num_tx_queues = 1;
974 else
975 adapter->num_tx_queues = adapter->rss_queues;
Alexander Duyck83b71802009-02-06 23:15:45 +0000976
Alexander Duyck047e0032009-10-27 15:49:27 +0000977 /* start with one vector for every rx queue */
978 numvecs = adapter->num_rx_queues;
979
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800980 /* if tx handler is separate add 1 for every tx queue */
Alexander Duycka99955f2009-11-12 18:37:19 +0000981 if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS))
982 numvecs += adapter->num_tx_queues;
Alexander Duyck047e0032009-10-27 15:49:27 +0000983
984 /* store the number of vectors reserved for queues */
985 adapter->num_q_vectors = numvecs;
986
987 /* add 1 vector for link status interrupts */
988 numvecs++;
Auke Kok9d5c8242008-01-24 02:22:38 -0800989 adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry),
990 GFP_KERNEL);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000991
Auke Kok9d5c8242008-01-24 02:22:38 -0800992 if (!adapter->msix_entries)
993 goto msi_only;
994
995 for (i = 0; i < numvecs; i++)
996 adapter->msix_entries[i].entry = i;
997
998 err = pci_enable_msix(adapter->pdev,
999 adapter->msix_entries,
1000 numvecs);
1001 if (err == 0)
Alexander Duyck0c2cc022012-09-25 00:31:22 +00001002 return;
Auke Kok9d5c8242008-01-24 02:22:38 -08001003
1004 igb_reset_interrupt_capability(adapter);
1005
1006 /* If we can't do MSI-X, try MSI */
1007msi_only:
Alexander Duyck2a3abf62009-04-07 14:37:52 +00001008#ifdef CONFIG_PCI_IOV
1009 /* disable SR-IOV for non MSI-X configurations */
1010 if (adapter->vf_data) {
1011 struct e1000_hw *hw = &adapter->hw;
1012 /* disable iov and allow time for transactions to clear */
1013 pci_disable_sriov(adapter->pdev);
1014 msleep(500);
1015
1016 kfree(adapter->vf_data);
1017 adapter->vf_data = NULL;
1018 wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001019 wrfl();
Alexander Duyck2a3abf62009-04-07 14:37:52 +00001020 msleep(100);
1021 dev_info(&adapter->pdev->dev, "IOV Disabled\n");
1022 }
1023#endif
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001024 adapter->vfs_allocated_count = 0;
Alexander Duycka99955f2009-11-12 18:37:19 +00001025 adapter->rss_queues = 1;
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001026 adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
Auke Kok9d5c8242008-01-24 02:22:38 -08001027 adapter->num_rx_queues = 1;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07001028 adapter->num_tx_queues = 1;
Alexander Duyck047e0032009-10-27 15:49:27 +00001029 adapter->num_q_vectors = 1;
Auke Kok9d5c8242008-01-24 02:22:38 -08001030 if (!pci_enable_msi(adapter->pdev))
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07001031 adapter->flags |= IGB_FLAG_HAS_MSI;
Auke Kok9d5c8242008-01-24 02:22:38 -08001032}
1033
Alexander Duyck5536d212012-09-25 00:31:17 +00001034static void igb_add_ring(struct igb_ring *ring,
1035 struct igb_ring_container *head)
1036{
1037 head->ring = ring;
1038 head->count++;
1039}
1040
1041/**
1042 * igb_alloc_q_vector - Allocate memory for a single interrupt vector
1043 * @adapter: board private structure to initialize
1044 * @v_count: q_vectors allocated on adapter, used for ring interleaving
1045 * @v_idx: index of vector in adapter struct
1046 * @txr_count: total number of Tx rings to allocate
1047 * @txr_idx: index of first Tx ring to allocate
1048 * @rxr_count: total number of Rx rings to allocate
1049 * @rxr_idx: index of first Rx ring to allocate
1050 *
1051 * We allocate one q_vector. If allocation fails we return -ENOMEM.
1052 **/
1053static int igb_alloc_q_vector(struct igb_adapter *adapter,
1054 int v_count, int v_idx,
1055 int txr_count, int txr_idx,
1056 int rxr_count, int rxr_idx)
1057{
1058 struct igb_q_vector *q_vector;
1059 struct igb_ring *ring;
1060 int ring_count, size;
1061
1062 /* igb only supports 1 Tx and/or 1 Rx queue per vector */
1063 if (txr_count > 1 || rxr_count > 1)
1064 return -ENOMEM;
1065
1066 ring_count = txr_count + rxr_count;
1067 size = sizeof(struct igb_q_vector) +
1068 (sizeof(struct igb_ring) * ring_count);
1069
1070 /* allocate q_vector and rings */
1071 q_vector = kzalloc(size, GFP_KERNEL);
1072 if (!q_vector)
1073 return -ENOMEM;
1074
1075 /* initialize NAPI */
1076 netif_napi_add(adapter->netdev, &q_vector->napi,
1077 igb_poll, 64);
1078
1079 /* tie q_vector and adapter together */
1080 adapter->q_vector[v_idx] = q_vector;
1081 q_vector->adapter = adapter;
1082
1083 /* initialize work limits */
1084 q_vector->tx.work_limit = adapter->tx_work_limit;
1085
1086 /* initialize ITR configuration */
1087 q_vector->itr_register = adapter->hw.hw_addr + E1000_EITR(0);
1088 q_vector->itr_val = IGB_START_ITR;
1089
1090 /* initialize pointer to rings */
1091 ring = q_vector->ring;
1092
1093 if (txr_count) {
1094 /* assign generic ring traits */
1095 ring->dev = &adapter->pdev->dev;
1096 ring->netdev = adapter->netdev;
1097
1098 /* configure backlink on ring */
1099 ring->q_vector = q_vector;
1100
1101 /* update q_vector Tx values */
1102 igb_add_ring(ring, &q_vector->tx);
1103
1104 /* For 82575, context index must be unique per ring. */
1105 if (adapter->hw.mac.type == e1000_82575)
1106 set_bit(IGB_RING_FLAG_TX_CTX_IDX, &ring->flags);
1107
1108 /* apply Tx specific ring traits */
1109 ring->count = adapter->tx_ring_count;
1110 ring->queue_index = txr_idx;
1111
1112 /* assign ring to adapter */
1113 adapter->tx_ring[txr_idx] = ring;
1114
1115 /* push pointer to next ring */
1116 ring++;
1117 }
1118
1119 if (rxr_count) {
1120 /* assign generic ring traits */
1121 ring->dev = &adapter->pdev->dev;
1122 ring->netdev = adapter->netdev;
1123
1124 /* configure backlink on ring */
1125 ring->q_vector = q_vector;
1126
1127 /* update q_vector Rx values */
1128 igb_add_ring(ring, &q_vector->rx);
1129
1130 /* set flag indicating ring supports SCTP checksum offload */
1131 if (adapter->hw.mac.type >= e1000_82576)
1132 set_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags);
1133
1134 /*
1135 * On i350, i210, and i211, loopback VLAN packets
1136 * have the tag byte-swapped.
1137 * */
1138 if (adapter->hw.mac.type >= e1000_i350)
1139 set_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &ring->flags);
1140
1141 /* apply Rx specific ring traits */
1142 ring->count = adapter->rx_ring_count;
1143 ring->queue_index = rxr_idx;
1144
1145 /* assign ring to adapter */
1146 adapter->rx_ring[rxr_idx] = ring;
1147 }
1148
1149 return 0;
1150}
1151
1152
Auke Kok9d5c8242008-01-24 02:22:38 -08001153/**
Alexander Duyck047e0032009-10-27 15:49:27 +00001154 * igb_alloc_q_vectors - Allocate memory for interrupt vectors
1155 * @adapter: board private structure to initialize
1156 *
1157 * We allocate one q_vector per queue interrupt. If allocation fails we
1158 * return -ENOMEM.
1159 **/
1160static int igb_alloc_q_vectors(struct igb_adapter *adapter)
1161{
Alexander Duyck5536d212012-09-25 00:31:17 +00001162 int q_vectors = adapter->num_q_vectors;
1163 int rxr_remaining = adapter->num_rx_queues;
1164 int txr_remaining = adapter->num_tx_queues;
1165 int rxr_idx = 0, txr_idx = 0, v_idx = 0;
1166 int err;
Alexander Duyck047e0032009-10-27 15:49:27 +00001167
Alexander Duyck5536d212012-09-25 00:31:17 +00001168 if (q_vectors >= (rxr_remaining + txr_remaining)) {
1169 for (; rxr_remaining; v_idx++) {
1170 err = igb_alloc_q_vector(adapter, q_vectors, v_idx,
1171 0, 0, 1, rxr_idx);
1172
1173 if (err)
1174 goto err_out;
1175
1176 /* update counts and index */
1177 rxr_remaining--;
1178 rxr_idx++;
1179 }
1180 }
1181
1182 for (; v_idx < q_vectors; v_idx++) {
1183 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_idx);
1184 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_idx);
1185 err = igb_alloc_q_vector(adapter, q_vectors, v_idx,
1186 tqpv, txr_idx, rqpv, rxr_idx);
1187
1188 if (err)
Alexander Duyck047e0032009-10-27 15:49:27 +00001189 goto err_out;
Alexander Duyck5536d212012-09-25 00:31:17 +00001190
1191 /* update counts and index */
1192 rxr_remaining -= rqpv;
1193 txr_remaining -= tqpv;
1194 rxr_idx++;
1195 txr_idx++;
Alexander Duyck047e0032009-10-27 15:49:27 +00001196 }
Alexander Duyck81c2fc22011-08-26 07:45:20 +00001197
Alexander Duyck047e0032009-10-27 15:49:27 +00001198 return 0;
1199
1200err_out:
Alexander Duyck5536d212012-09-25 00:31:17 +00001201 adapter->num_tx_queues = 0;
1202 adapter->num_rx_queues = 0;
1203 adapter->num_q_vectors = 0;
1204
1205 while (v_idx--)
1206 igb_free_q_vector(adapter, v_idx);
1207
Alexander Duyck047e0032009-10-27 15:49:27 +00001208 return -ENOMEM;
1209}
1210
Alexander Duyck047e0032009-10-27 15:49:27 +00001211/**
1212 * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors
1213 *
1214 * This function initializes the interrupts and allocates all of the queues.
1215 **/
Stefan Assmann53c7d062012-12-04 06:00:12 +00001216static int igb_init_interrupt_scheme(struct igb_adapter *adapter, bool msix)
Alexander Duyck047e0032009-10-27 15:49:27 +00001217{
1218 struct pci_dev *pdev = adapter->pdev;
1219 int err;
1220
Stefan Assmann53c7d062012-12-04 06:00:12 +00001221 igb_set_interrupt_capability(adapter, msix);
Alexander Duyck047e0032009-10-27 15:49:27 +00001222
1223 err = igb_alloc_q_vectors(adapter);
1224 if (err) {
1225 dev_err(&pdev->dev, "Unable to allocate memory for vectors\n");
1226 goto err_alloc_q_vectors;
1227 }
1228
Alexander Duyck5536d212012-09-25 00:31:17 +00001229 igb_cache_ring_register(adapter);
Alexander Duyck047e0032009-10-27 15:49:27 +00001230
1231 return 0;
Alexander Duyck5536d212012-09-25 00:31:17 +00001232
Alexander Duyck047e0032009-10-27 15:49:27 +00001233err_alloc_q_vectors:
1234 igb_reset_interrupt_capability(adapter);
1235 return err;
1236}
1237
1238/**
Auke Kok9d5c8242008-01-24 02:22:38 -08001239 * igb_request_irq - initialize interrupts
1240 *
1241 * Attempts to configure interrupts using the best available
1242 * capabilities of the hardware and kernel.
1243 **/
1244static int igb_request_irq(struct igb_adapter *adapter)
1245{
1246 struct net_device *netdev = adapter->netdev;
Alexander Duyck047e0032009-10-27 15:49:27 +00001247 struct pci_dev *pdev = adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08001248 int err = 0;
1249
1250 if (adapter->msix_entries) {
1251 err = igb_request_msix(adapter);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001252 if (!err)
Auke Kok9d5c8242008-01-24 02:22:38 -08001253 goto request_done;
Auke Kok9d5c8242008-01-24 02:22:38 -08001254 /* fall back to MSI */
Alexander Duyck5536d212012-09-25 00:31:17 +00001255 igb_free_all_tx_resources(adapter);
1256 igb_free_all_rx_resources(adapter);
Stefan Assmann53c7d062012-12-04 06:00:12 +00001257
Alexander Duyck047e0032009-10-27 15:49:27 +00001258 igb_clear_interrupt_scheme(adapter);
Stefan Assmann53c7d062012-12-04 06:00:12 +00001259 err = igb_init_interrupt_scheme(adapter, false);
1260 if (err)
Alexander Duyck047e0032009-10-27 15:49:27 +00001261 goto request_done;
Stefan Assmann53c7d062012-12-04 06:00:12 +00001262
Alexander Duyck047e0032009-10-27 15:49:27 +00001263 igb_setup_all_tx_resources(adapter);
1264 igb_setup_all_rx_resources(adapter);
Stefan Assmann53c7d062012-12-04 06:00:12 +00001265 igb_configure(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001266 }
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001267
Alexander Duyckc74d5882011-08-26 07:46:45 +00001268 igb_assign_vector(adapter->q_vector[0], 0);
1269
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07001270 if (adapter->flags & IGB_FLAG_HAS_MSI) {
Alexander Duyckc74d5882011-08-26 07:46:45 +00001271 err = request_irq(pdev->irq, igb_intr_msi, 0,
Alexander Duyck047e0032009-10-27 15:49:27 +00001272 netdev->name, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001273 if (!err)
1274 goto request_done;
Alexander Duyck047e0032009-10-27 15:49:27 +00001275
Auke Kok9d5c8242008-01-24 02:22:38 -08001276 /* fall back to legacy interrupts */
1277 igb_reset_interrupt_capability(adapter);
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07001278 adapter->flags &= ~IGB_FLAG_HAS_MSI;
Auke Kok9d5c8242008-01-24 02:22:38 -08001279 }
1280
Alexander Duyckc74d5882011-08-26 07:46:45 +00001281 err = request_irq(pdev->irq, igb_intr, IRQF_SHARED,
Alexander Duyck047e0032009-10-27 15:49:27 +00001282 netdev->name, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001283
Andy Gospodarek6cb5e572008-02-15 14:05:25 -08001284 if (err)
Alexander Duyckc74d5882011-08-26 07:46:45 +00001285 dev_err(&pdev->dev, "Error %d getting interrupt\n",
Auke Kok9d5c8242008-01-24 02:22:38 -08001286 err);
Auke Kok9d5c8242008-01-24 02:22:38 -08001287
1288request_done:
1289 return err;
1290}
1291
1292static void igb_free_irq(struct igb_adapter *adapter)
1293{
Auke Kok9d5c8242008-01-24 02:22:38 -08001294 if (adapter->msix_entries) {
1295 int vector = 0, i;
1296
Alexander Duyck047e0032009-10-27 15:49:27 +00001297 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001298
Alexander Duyck0d1ae7f2011-08-26 07:46:34 +00001299 for (i = 0; i < adapter->num_q_vectors; i++)
Alexander Duyck047e0032009-10-27 15:49:27 +00001300 free_irq(adapter->msix_entries[vector++].vector,
Alexander Duyck0d1ae7f2011-08-26 07:46:34 +00001301 adapter->q_vector[i]);
Alexander Duyck047e0032009-10-27 15:49:27 +00001302 } else {
1303 free_irq(adapter->pdev->irq, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001304 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001305}
1306
1307/**
1308 * igb_irq_disable - Mask off interrupt generation on the NIC
1309 * @adapter: board private structure
1310 **/
1311static void igb_irq_disable(struct igb_adapter *adapter)
1312{
1313 struct e1000_hw *hw = &adapter->hw;
1314
Alexander Duyck25568a52009-10-27 23:49:59 +00001315 /*
1316 * we need to be careful when disabling interrupts. The VFs are also
1317 * mapped into these registers and so clearing the bits can cause
1318 * issues on the VF drivers so we only need to clear what we set
1319 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001320 if (adapter->msix_entries) {
Alexander Duyck2dfd1212009-09-03 14:49:15 +00001321 u32 regval = rd32(E1000_EIAM);
1322 wr32(E1000_EIAM, regval & ~adapter->eims_enable_mask);
1323 wr32(E1000_EIMC, adapter->eims_enable_mask);
1324 regval = rd32(E1000_EIAC);
1325 wr32(E1000_EIAC, regval & ~adapter->eims_enable_mask);
Auke Kok9d5c8242008-01-24 02:22:38 -08001326 }
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001327
1328 wr32(E1000_IAM, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001329 wr32(E1000_IMC, ~0);
1330 wrfl();
Emil Tantilov81a61852010-08-02 14:40:52 +00001331 if (adapter->msix_entries) {
1332 int i;
1333 for (i = 0; i < adapter->num_q_vectors; i++)
1334 synchronize_irq(adapter->msix_entries[i].vector);
1335 } else {
1336 synchronize_irq(adapter->pdev->irq);
1337 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001338}
1339
1340/**
1341 * igb_irq_enable - Enable default interrupt generation settings
1342 * @adapter: board private structure
1343 **/
1344static void igb_irq_enable(struct igb_adapter *adapter)
1345{
1346 struct e1000_hw *hw = &adapter->hw;
1347
1348 if (adapter->msix_entries) {
Alexander Duyck06218a82011-08-26 07:46:55 +00001349 u32 ims = E1000_IMS_LSC | E1000_IMS_DOUTSYNC | E1000_IMS_DRSTA;
Alexander Duyck2dfd1212009-09-03 14:49:15 +00001350 u32 regval = rd32(E1000_EIAC);
1351 wr32(E1000_EIAC, regval | adapter->eims_enable_mask);
1352 regval = rd32(E1000_EIAM);
1353 wr32(E1000_EIAM, regval | adapter->eims_enable_mask);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001354 wr32(E1000_EIMS, adapter->eims_enable_mask);
Alexander Duyck25568a52009-10-27 23:49:59 +00001355 if (adapter->vfs_allocated_count) {
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001356 wr32(E1000_MBVFIMR, 0xFF);
Alexander Duyck25568a52009-10-27 23:49:59 +00001357 ims |= E1000_IMS_VMMB;
1358 }
1359 wr32(E1000_IMS, ims);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001360 } else {
Alexander Duyck55cac242009-11-19 12:42:21 +00001361 wr32(E1000_IMS, IMS_ENABLE_MASK |
1362 E1000_IMS_DRSTA);
1363 wr32(E1000_IAM, IMS_ENABLE_MASK |
1364 E1000_IMS_DRSTA);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001365 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001366}
1367
1368static void igb_update_mng_vlan(struct igb_adapter *adapter)
1369{
Alexander Duyck51466232009-10-27 23:47:35 +00001370 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08001371 u16 vid = adapter->hw.mng_cookie.vlan_id;
1372 u16 old_vid = adapter->mng_vlan_id;
Auke Kok9d5c8242008-01-24 02:22:38 -08001373
Alexander Duyck51466232009-10-27 23:47:35 +00001374 if (hw->mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
1375 /* add VID to filter table */
1376 igb_vfta_set(hw, vid, true);
1377 adapter->mng_vlan_id = vid;
1378 } else {
1379 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
1380 }
1381
1382 if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
1383 (vid != old_vid) &&
Jiri Pirkob2cb09b2011-07-21 03:27:27 +00001384 !test_bit(old_vid, adapter->active_vlans)) {
Alexander Duyck51466232009-10-27 23:47:35 +00001385 /* remove VID from filter table */
1386 igb_vfta_set(hw, old_vid, false);
Auke Kok9d5c8242008-01-24 02:22:38 -08001387 }
1388}
1389
1390/**
1391 * igb_release_hw_control - release control of the h/w to f/w
1392 * @adapter: address of board private structure
1393 *
1394 * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
1395 * For ASF and Pass Through versions of f/w this means that the
1396 * driver is no longer loaded.
1397 *
1398 **/
1399static void igb_release_hw_control(struct igb_adapter *adapter)
1400{
1401 struct e1000_hw *hw = &adapter->hw;
1402 u32 ctrl_ext;
1403
1404 /* Let firmware take over control of h/w */
1405 ctrl_ext = rd32(E1000_CTRL_EXT);
1406 wr32(E1000_CTRL_EXT,
1407 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1408}
1409
Auke Kok9d5c8242008-01-24 02:22:38 -08001410/**
1411 * igb_get_hw_control - get control of the h/w from f/w
1412 * @adapter: address of board private structure
1413 *
1414 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
1415 * For ASF and Pass Through versions of f/w this means that
1416 * the driver is loaded.
1417 *
1418 **/
1419static void igb_get_hw_control(struct igb_adapter *adapter)
1420{
1421 struct e1000_hw *hw = &adapter->hw;
1422 u32 ctrl_ext;
1423
1424 /* Let firmware know the driver has taken over */
1425 ctrl_ext = rd32(E1000_CTRL_EXT);
1426 wr32(E1000_CTRL_EXT,
1427 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1428}
1429
Auke Kok9d5c8242008-01-24 02:22:38 -08001430/**
1431 * igb_configure - configure the hardware for RX and TX
1432 * @adapter: private board structure
1433 **/
1434static void igb_configure(struct igb_adapter *adapter)
1435{
1436 struct net_device *netdev = adapter->netdev;
1437 int i;
1438
1439 igb_get_hw_control(adapter);
Alexander Duyckff41f8d2009-09-03 14:48:56 +00001440 igb_set_rx_mode(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001441
1442 igb_restore_vlan(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001443
Alexander Duyck85b430b2009-10-27 15:50:29 +00001444 igb_setup_tctl(adapter);
Alexander Duyck06cf2662009-10-27 15:53:25 +00001445 igb_setup_mrqc(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001446 igb_setup_rctl(adapter);
Alexander Duyck85b430b2009-10-27 15:50:29 +00001447
1448 igb_configure_tx(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001449 igb_configure_rx(adapter);
Alexander Duyck662d7202008-06-27 11:00:29 -07001450
1451 igb_rx_fifo_flush_82575(&adapter->hw);
1452
Alexander Duyckc493ea42009-03-20 00:16:50 +00001453 /* call igb_desc_unused which always leaves
Auke Kok9d5c8242008-01-24 02:22:38 -08001454 * at least 1 descriptor unused to make sure
1455 * next_to_use != next_to_clean */
1456 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +00001457 struct igb_ring *ring = adapter->rx_ring[i];
Alexander Duyckcd392f52011-08-26 07:43:59 +00001458 igb_alloc_rx_buffers(ring, igb_desc_unused(ring));
Auke Kok9d5c8242008-01-24 02:22:38 -08001459 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001460}
1461
Nick Nunley88a268c2010-02-17 01:01:59 +00001462/**
1463 * igb_power_up_link - Power up the phy/serdes link
1464 * @adapter: address of board private structure
1465 **/
1466void igb_power_up_link(struct igb_adapter *adapter)
1467{
Akeem G. Abodunrin76886592012-07-17 04:51:18 +00001468 igb_reset_phy(&adapter->hw);
1469
Nick Nunley88a268c2010-02-17 01:01:59 +00001470 if (adapter->hw.phy.media_type == e1000_media_type_copper)
1471 igb_power_up_phy_copper(&adapter->hw);
1472 else
1473 igb_power_up_serdes_link_82575(&adapter->hw);
1474}
1475
1476/**
1477 * igb_power_down_link - Power down the phy/serdes link
1478 * @adapter: address of board private structure
1479 */
1480static void igb_power_down_link(struct igb_adapter *adapter)
1481{
1482 if (adapter->hw.phy.media_type == e1000_media_type_copper)
1483 igb_power_down_phy_copper_82575(&adapter->hw);
1484 else
1485 igb_shutdown_serdes_link_82575(&adapter->hw);
1486}
Auke Kok9d5c8242008-01-24 02:22:38 -08001487
1488/**
1489 * igb_up - Open the interface and prepare it to handle traffic
1490 * @adapter: board private structure
1491 **/
Auke Kok9d5c8242008-01-24 02:22:38 -08001492int igb_up(struct igb_adapter *adapter)
1493{
1494 struct e1000_hw *hw = &adapter->hw;
1495 int i;
1496
1497 /* hardware has been reset, we need to reload some things */
1498 igb_configure(adapter);
1499
1500 clear_bit(__IGB_DOWN, &adapter->state);
1501
Alexander Duyck0d1ae7f2011-08-26 07:46:34 +00001502 for (i = 0; i < adapter->num_q_vectors; i++)
1503 napi_enable(&(adapter->q_vector[i]->napi));
1504
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001505 if (adapter->msix_entries)
Auke Kok9d5c8242008-01-24 02:22:38 -08001506 igb_configure_msix(adapter);
Alexander Duyckfeeb2722010-02-03 21:59:51 +00001507 else
1508 igb_assign_vector(adapter->q_vector[0], 0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001509
1510 /* Clear any pending interrupts. */
1511 rd32(E1000_ICR);
1512 igb_irq_enable(adapter);
1513
Alexander Duyckd4960302009-10-27 15:53:45 +00001514 /* notify VFs that reset has been completed */
1515 if (adapter->vfs_allocated_count) {
1516 u32 reg_data = rd32(E1000_CTRL_EXT);
1517 reg_data |= E1000_CTRL_EXT_PFRSTD;
1518 wr32(E1000_CTRL_EXT, reg_data);
1519 }
1520
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00001521 netif_tx_start_all_queues(adapter->netdev);
1522
Alexander Duyck25568a52009-10-27 23:49:59 +00001523 /* start the watchdog. */
1524 hw->mac.get_link_status = 1;
1525 schedule_work(&adapter->watchdog_task);
1526
Auke Kok9d5c8242008-01-24 02:22:38 -08001527 return 0;
1528}
1529
1530void igb_down(struct igb_adapter *adapter)
1531{
Auke Kok9d5c8242008-01-24 02:22:38 -08001532 struct net_device *netdev = adapter->netdev;
Alexander Duyck330a6d62009-10-27 23:51:35 +00001533 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08001534 u32 tctl, rctl;
1535 int i;
1536
1537 /* signal that we're down so the interrupt handler does not
1538 * reschedule our watchdog timer */
1539 set_bit(__IGB_DOWN, &adapter->state);
1540
1541 /* disable receives in the hardware */
1542 rctl = rd32(E1000_RCTL);
1543 wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
1544 /* flush and sleep below */
1545
David S. Millerfd2ea0a2008-07-17 01:56:23 -07001546 netif_tx_stop_all_queues(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001547
1548 /* disable transmits in the hardware */
1549 tctl = rd32(E1000_TCTL);
1550 tctl &= ~E1000_TCTL_EN;
1551 wr32(E1000_TCTL, tctl);
1552 /* flush both disables and wait for them to finish */
1553 wrfl();
1554 msleep(10);
1555
Alexander Duyck0d1ae7f2011-08-26 07:46:34 +00001556 for (i = 0; i < adapter->num_q_vectors; i++)
1557 napi_disable(&(adapter->q_vector[i]->napi));
Auke Kok9d5c8242008-01-24 02:22:38 -08001558
Auke Kok9d5c8242008-01-24 02:22:38 -08001559 igb_irq_disable(adapter);
1560
1561 del_timer_sync(&adapter->watchdog_timer);
1562 del_timer_sync(&adapter->phy_info_timer);
1563
Auke Kok9d5c8242008-01-24 02:22:38 -08001564 netif_carrier_off(netdev);
Alexander Duyck04fe6352009-02-06 23:22:32 +00001565
1566 /* record the stats before reset*/
Eric Dumazet12dcd862010-10-15 17:27:10 +00001567 spin_lock(&adapter->stats64_lock);
1568 igb_update_stats(adapter, &adapter->stats64);
1569 spin_unlock(&adapter->stats64_lock);
Alexander Duyck04fe6352009-02-06 23:22:32 +00001570
Auke Kok9d5c8242008-01-24 02:22:38 -08001571 adapter->link_speed = 0;
1572 adapter->link_duplex = 0;
1573
Jeff Kirsher30236822008-06-24 17:01:15 -07001574 if (!pci_channel_offline(adapter->pdev))
1575 igb_reset(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001576 igb_clean_all_tx_rings(adapter);
1577 igb_clean_all_rx_rings(adapter);
Alexander Duyck7e0e99e2009-05-21 13:06:56 +00001578#ifdef CONFIG_IGB_DCA
1579
1580 /* since we reset the hardware DCA settings were cleared */
1581 igb_setup_dca(adapter);
1582#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08001583}
1584
1585void igb_reinit_locked(struct igb_adapter *adapter)
1586{
1587 WARN_ON(in_interrupt());
1588 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
1589 msleep(1);
1590 igb_down(adapter);
1591 igb_up(adapter);
1592 clear_bit(__IGB_RESETTING, &adapter->state);
1593}
1594
1595void igb_reset(struct igb_adapter *adapter)
1596{
Alexander Duyck090b1792009-10-27 23:51:55 +00001597 struct pci_dev *pdev = adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08001598 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001599 struct e1000_mac_info *mac = &hw->mac;
1600 struct e1000_fc_info *fc = &hw->fc;
Matthew Vickd48507f2012-11-08 04:03:58 +00001601 u32 pba = 0, tx_space, min_tx_space, min_rx_space, hwm;
Auke Kok9d5c8242008-01-24 02:22:38 -08001602
1603 /* Repartition Pba for greater than 9k mtu
1604 * To take effect CTRL.RST is required.
1605 */
Alexander Duyckfa4dfae2009-02-06 23:21:31 +00001606 switch (mac->type) {
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001607 case e1000_i350:
Alexander Duyck55cac242009-11-19 12:42:21 +00001608 case e1000_82580:
1609 pba = rd32(E1000_RXPBS);
1610 pba = igb_rxpbs_adjust_82580(pba);
1611 break;
Alexander Duyckfa4dfae2009-02-06 23:21:31 +00001612 case e1000_82576:
Alexander Duyckd249be52009-10-27 23:46:38 +00001613 pba = rd32(E1000_RXPBS);
1614 pba &= E1000_RXPBS_SIZE_MASK_82576;
Alexander Duyckfa4dfae2009-02-06 23:21:31 +00001615 break;
1616 case e1000_82575:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001617 case e1000_i210:
1618 case e1000_i211:
Alexander Duyckfa4dfae2009-02-06 23:21:31 +00001619 default:
1620 pba = E1000_PBA_34K;
1621 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001622 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001623
Alexander Duyck2d064c02008-07-08 15:10:12 -07001624 if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) &&
1625 (mac->type < e1000_82576)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001626 /* adjust PBA for jumbo frames */
1627 wr32(E1000_PBA, pba);
1628
1629 /* To maintain wire speed transmits, the Tx FIFO should be
1630 * large enough to accommodate two full transmit packets,
1631 * rounded up to the next 1KB and expressed in KB. Likewise,
1632 * the Rx FIFO should be large enough to accommodate at least
1633 * one full receive packet and is similarly rounded up and
1634 * expressed in KB. */
1635 pba = rd32(E1000_PBA);
1636 /* upper 16 bits has Tx packet buffer allocation size in KB */
1637 tx_space = pba >> 16;
1638 /* lower 16 bits has Rx packet buffer allocation size in KB */
1639 pba &= 0xffff;
1640 /* the tx fifo also stores 16 bytes of information about the tx
1641 * but don't include ethernet FCS because hardware appends it */
1642 min_tx_space = (adapter->max_frame_size +
Alexander Duyck85e8d002009-02-16 00:00:20 -08001643 sizeof(union e1000_adv_tx_desc) -
Auke Kok9d5c8242008-01-24 02:22:38 -08001644 ETH_FCS_LEN) * 2;
1645 min_tx_space = ALIGN(min_tx_space, 1024);
1646 min_tx_space >>= 10;
1647 /* software strips receive CRC, so leave room for it */
1648 min_rx_space = adapter->max_frame_size;
1649 min_rx_space = ALIGN(min_rx_space, 1024);
1650 min_rx_space >>= 10;
1651
1652 /* If current Tx allocation is less than the min Tx FIFO size,
1653 * and the min Tx FIFO size is less than the current Rx FIFO
1654 * allocation, take space away from current Rx allocation */
1655 if (tx_space < min_tx_space &&
1656 ((min_tx_space - tx_space) < pba)) {
1657 pba = pba - (min_tx_space - tx_space);
1658
1659 /* if short on rx space, rx wins and must trump tx
1660 * adjustment */
1661 if (pba < min_rx_space)
1662 pba = min_rx_space;
1663 }
Alexander Duyck2d064c02008-07-08 15:10:12 -07001664 wr32(E1000_PBA, pba);
Auke Kok9d5c8242008-01-24 02:22:38 -08001665 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001666
1667 /* flow control settings */
1668 /* The high water mark must be low enough to fit one full frame
1669 * (or the size used for early receive) above it in the Rx FIFO.
1670 * Set it to the lower of:
1671 * - 90% of the Rx FIFO size, or
1672 * - the full Rx FIFO size minus one full frame */
1673 hwm = min(((pba << 10) * 9 / 10),
Alexander Duyck2d064c02008-07-08 15:10:12 -07001674 ((pba << 10) - 2 * adapter->max_frame_size));
Auke Kok9d5c8242008-01-24 02:22:38 -08001675
Matthew Vickd48507f2012-11-08 04:03:58 +00001676 fc->high_water = hwm & 0xFFFFFFF0; /* 16-byte granularity */
Alexander Duyckd405ea32009-12-23 13:21:27 +00001677 fc->low_water = fc->high_water - 16;
Auke Kok9d5c8242008-01-24 02:22:38 -08001678 fc->pause_time = 0xFFFF;
1679 fc->send_xon = 1;
Alexander Duyck0cce1192009-07-23 18:10:24 +00001680 fc->current_mode = fc->requested_mode;
Auke Kok9d5c8242008-01-24 02:22:38 -08001681
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001682 /* disable receive for all VFs and wait one second */
1683 if (adapter->vfs_allocated_count) {
1684 int i;
1685 for (i = 0 ; i < adapter->vfs_allocated_count; i++)
Greg Rose8fa7e0f2010-11-06 05:43:21 +00001686 adapter->vf_data[i].flags &= IGB_VF_FLAG_PF_SET_MAC;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001687
1688 /* ping all the active vfs to let them know we are going down */
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00001689 igb_ping_all_vfs(adapter);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001690
1691 /* disable transmits and receives */
1692 wr32(E1000_VFRE, 0);
1693 wr32(E1000_VFTE, 0);
1694 }
1695
Auke Kok9d5c8242008-01-24 02:22:38 -08001696 /* Allow time for pending master requests to run */
Alexander Duyck330a6d62009-10-27 23:51:35 +00001697 hw->mac.ops.reset_hw(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001698 wr32(E1000_WUC, 0);
1699
Alexander Duyck330a6d62009-10-27 23:51:35 +00001700 if (hw->mac.ops.init_hw(hw))
Alexander Duyck090b1792009-10-27 23:51:55 +00001701 dev_err(&pdev->dev, "Hardware Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001702
Matthew Vicka27416b2012-04-18 02:57:44 +00001703 /*
1704 * Flow control settings reset on hardware reset, so guarantee flow
1705 * control is off when forcing speed.
1706 */
1707 if (!hw->mac.autoneg)
1708 igb_force_mac_fc(hw);
1709
Carolyn Wybornyb6e0c412011-10-13 17:29:59 +00001710 igb_init_dmac(adapter, pba);
Nick Nunley88a268c2010-02-17 01:01:59 +00001711 if (!netif_running(adapter->netdev))
1712 igb_power_down_link(adapter);
1713
Auke Kok9d5c8242008-01-24 02:22:38 -08001714 igb_update_mng_vlan(adapter);
1715
1716 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
1717 wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
1718
Matthew Vick1f6e8172012-08-18 07:26:33 +00001719 /* Re-enable PTP, where applicable. */
1720 igb_ptp_reset(adapter);
Matthew Vick1f6e8172012-08-18 07:26:33 +00001721
Alexander Duyck330a6d62009-10-27 23:51:35 +00001722 igb_get_phy_info(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001723}
1724
Michał Mirosławc8f44af2011-11-15 15:29:55 +00001725static netdev_features_t igb_fix_features(struct net_device *netdev,
1726 netdev_features_t features)
Jiri Pirkob2cb09b2011-07-21 03:27:27 +00001727{
1728 /*
1729 * Since there is no support for separate rx/tx vlan accel
1730 * enable/disable make sure tx flag is always in same state as rx.
1731 */
1732 if (features & NETIF_F_HW_VLAN_RX)
1733 features |= NETIF_F_HW_VLAN_TX;
1734 else
1735 features &= ~NETIF_F_HW_VLAN_TX;
1736
1737 return features;
1738}
1739
Michał Mirosławc8f44af2011-11-15 15:29:55 +00001740static int igb_set_features(struct net_device *netdev,
1741 netdev_features_t features)
Michał Mirosławac52caa2011-06-08 08:38:01 +00001742{
Michał Mirosławc8f44af2011-11-15 15:29:55 +00001743 netdev_features_t changed = netdev->features ^ features;
Ben Greear89eaefb2012-03-06 09:41:58 +00001744 struct igb_adapter *adapter = netdev_priv(netdev);
Michał Mirosławac52caa2011-06-08 08:38:01 +00001745
Jiri Pirkob2cb09b2011-07-21 03:27:27 +00001746 if (changed & NETIF_F_HW_VLAN_RX)
1747 igb_vlan_mode(netdev, features);
1748
Ben Greear89eaefb2012-03-06 09:41:58 +00001749 if (!(changed & NETIF_F_RXALL))
1750 return 0;
1751
1752 netdev->features = features;
1753
1754 if (netif_running(netdev))
1755 igb_reinit_locked(adapter);
1756 else
1757 igb_reset(adapter);
1758
Michał Mirosławac52caa2011-06-08 08:38:01 +00001759 return 0;
1760}
1761
Stephen Hemminger2e5c6922008-11-19 22:20:44 -08001762static const struct net_device_ops igb_netdev_ops = {
Alexander Duyck559e9c42009-10-27 23:52:50 +00001763 .ndo_open = igb_open,
Stephen Hemminger2e5c6922008-11-19 22:20:44 -08001764 .ndo_stop = igb_close,
Alexander Duyckcd392f52011-08-26 07:43:59 +00001765 .ndo_start_xmit = igb_xmit_frame,
Eric Dumazet12dcd862010-10-15 17:27:10 +00001766 .ndo_get_stats64 = igb_get_stats64,
Alexander Duyckff41f8d2009-09-03 14:48:56 +00001767 .ndo_set_rx_mode = igb_set_rx_mode,
Stephen Hemminger2e5c6922008-11-19 22:20:44 -08001768 .ndo_set_mac_address = igb_set_mac,
1769 .ndo_change_mtu = igb_change_mtu,
1770 .ndo_do_ioctl = igb_ioctl,
1771 .ndo_tx_timeout = igb_tx_timeout,
1772 .ndo_validate_addr = eth_validate_addr,
Stephen Hemminger2e5c6922008-11-19 22:20:44 -08001773 .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid,
1774 .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid,
Williams, Mitch A8151d292010-02-10 01:44:24 +00001775 .ndo_set_vf_mac = igb_ndo_set_vf_mac,
1776 .ndo_set_vf_vlan = igb_ndo_set_vf_vlan,
1777 .ndo_set_vf_tx_rate = igb_ndo_set_vf_bw,
1778 .ndo_get_vf_config = igb_ndo_get_vf_config,
Stephen Hemminger2e5c6922008-11-19 22:20:44 -08001779#ifdef CONFIG_NET_POLL_CONTROLLER
1780 .ndo_poll_controller = igb_netpoll,
1781#endif
Jiri Pirkob2cb09b2011-07-21 03:27:27 +00001782 .ndo_fix_features = igb_fix_features,
1783 .ndo_set_features = igb_set_features,
Stephen Hemminger2e5c6922008-11-19 22:20:44 -08001784};
1785
Taku Izumi42bfd33a2008-06-20 12:10:30 +09001786/**
Carolyn Wybornyd67974f2012-06-14 16:04:19 +00001787 * igb_set_fw_version - Configure version string for ethtool
1788 * @adapter: adapter struct
1789 *
1790 **/
1791void igb_set_fw_version(struct igb_adapter *adapter)
1792{
1793 struct e1000_hw *hw = &adapter->hw;
Carolyn Wyborny0b1a6f22012-10-18 07:16:19 +00001794 struct e1000_fw_version fw;
Carolyn Wybornyd67974f2012-06-14 16:04:19 +00001795
Carolyn Wyborny0b1a6f22012-10-18 07:16:19 +00001796 igb_get_fw_version(hw, &fw);
Carolyn Wybornyd67974f2012-06-14 16:04:19 +00001797
Carolyn Wyborny0b1a6f22012-10-18 07:16:19 +00001798 switch (hw->mac.type) {
1799 case e1000_i211:
1800 snprintf(adapter->fw_version, sizeof(adapter->fw_version),
1801 "%2d.%2d-%d",
1802 fw.invm_major, fw.invm_minor, fw.invm_img_type);
1803 break;
Carolyn Wybornyd67974f2012-06-14 16:04:19 +00001804
Carolyn Wyborny0b1a6f22012-10-18 07:16:19 +00001805 default:
1806 /* if option is rom valid, display its version too */
1807 if (fw.or_valid) {
1808 snprintf(adapter->fw_version,
1809 sizeof(adapter->fw_version),
1810 "%d.%d, 0x%08x, %d.%d.%d",
1811 fw.eep_major, fw.eep_minor, fw.etrack_id,
1812 fw.or_major, fw.or_build, fw.or_patch);
1813 /* no option rom */
1814 } else {
1815 snprintf(adapter->fw_version,
1816 sizeof(adapter->fw_version),
1817 "%d.%d, 0x%08x",
1818 fw.eep_major, fw.eep_minor, fw.etrack_id);
Carolyn Wybornyd67974f2012-06-14 16:04:19 +00001819 }
Carolyn Wyborny0b1a6f22012-10-18 07:16:19 +00001820 break;
Carolyn Wybornyd67974f2012-06-14 16:04:19 +00001821 }
Carolyn Wybornyd67974f2012-06-14 16:04:19 +00001822 return;
1823}
1824
1825/**
Auke Kok9d5c8242008-01-24 02:22:38 -08001826 * igb_probe - Device Initialization Routine
1827 * @pdev: PCI device information struct
1828 * @ent: entry in igb_pci_tbl
1829 *
1830 * Returns 0 on success, negative on failure
1831 *
1832 * igb_probe initializes an adapter identified by a pci_dev structure.
1833 * The OS initialization, configuring of the adapter private structure,
1834 * and a hardware reset occur.
1835 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05001836static int igb_probe(struct pci_dev *pdev,
Auke Kok9d5c8242008-01-24 02:22:38 -08001837 const struct pci_device_id *ent)
1838{
1839 struct net_device *netdev;
1840 struct igb_adapter *adapter;
1841 struct e1000_hw *hw;
Alexander Duyck4337e992009-10-27 23:48:31 +00001842 u16 eeprom_data = 0;
Carolyn Wyborny9835fd72010-11-22 17:17:21 +00001843 s32 ret_val;
Alexander Duyck4337e992009-10-27 23:48:31 +00001844 static int global_quad_port_a; /* global quad port a indication */
Auke Kok9d5c8242008-01-24 02:22:38 -08001845 const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
1846 unsigned long mmio_start, mmio_len;
David S. Miller2d6a5e92009-03-17 15:01:30 -07001847 int err, pci_using_dac;
Carolyn Wyborny9835fd72010-11-22 17:17:21 +00001848 u8 part_str[E1000_PBANUM_LENGTH];
Auke Kok9d5c8242008-01-24 02:22:38 -08001849
Andy Gospodarekbded64a2010-07-21 06:40:31 +00001850 /* Catch broken hardware that put the wrong VF device ID in
1851 * the PCIe SR-IOV capability.
1852 */
1853 if (pdev->is_virtfn) {
1854 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001855 pci_name(pdev), pdev->vendor, pdev->device);
Andy Gospodarekbded64a2010-07-21 06:40:31 +00001856 return -EINVAL;
1857 }
1858
Alexander Duyckaed5dec2009-02-06 23:16:04 +00001859 err = pci_enable_device_mem(pdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001860 if (err)
1861 return err;
1862
1863 pci_using_dac = 0;
Alexander Duyck59d71982010-04-27 13:09:25 +00001864 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kok9d5c8242008-01-24 02:22:38 -08001865 if (!err) {
Alexander Duyck59d71982010-04-27 13:09:25 +00001866 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kok9d5c8242008-01-24 02:22:38 -08001867 if (!err)
1868 pci_using_dac = 1;
1869 } else {
Alexander Duyck59d71982010-04-27 13:09:25 +00001870 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9d5c8242008-01-24 02:22:38 -08001871 if (err) {
Alexander Duyck59d71982010-04-27 13:09:25 +00001872 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9d5c8242008-01-24 02:22:38 -08001873 if (err) {
1874 dev_err(&pdev->dev, "No usable DMA "
1875 "configuration, aborting\n");
1876 goto err_dma;
1877 }
1878 }
1879 }
1880
Alexander Duyckaed5dec2009-02-06 23:16:04 +00001881 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
1882 IORESOURCE_MEM),
1883 igb_driver_name);
Auke Kok9d5c8242008-01-24 02:22:38 -08001884 if (err)
1885 goto err_pci_reg;
1886
Frans Pop19d5afd2009-10-02 10:04:12 -07001887 pci_enable_pcie_error_reporting(pdev);
Alexander Duyck40a914f2008-11-27 00:24:37 -08001888
Auke Kok9d5c8242008-01-24 02:22:38 -08001889 pci_set_master(pdev);
Auke Kokc682fc22008-04-23 11:09:34 -07001890 pci_save_state(pdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001891
1892 err = -ENOMEM;
Alexander Duyck1bfaf072009-02-19 20:39:23 -08001893 netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
Alexander Duyck1cc3bd82011-08-26 07:44:10 +00001894 IGB_MAX_TX_QUEUES);
Auke Kok9d5c8242008-01-24 02:22:38 -08001895 if (!netdev)
1896 goto err_alloc_etherdev;
1897
1898 SET_NETDEV_DEV(netdev, &pdev->dev);
1899
1900 pci_set_drvdata(pdev, netdev);
1901 adapter = netdev_priv(netdev);
1902 adapter->netdev = netdev;
1903 adapter->pdev = pdev;
1904 hw = &adapter->hw;
1905 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00001906 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9d5c8242008-01-24 02:22:38 -08001907
1908 mmio_start = pci_resource_start(pdev, 0);
1909 mmio_len = pci_resource_len(pdev, 0);
1910
1911 err = -EIO;
Alexander Duyck28b07592009-02-06 23:20:31 +00001912 hw->hw_addr = ioremap(mmio_start, mmio_len);
1913 if (!hw->hw_addr)
Auke Kok9d5c8242008-01-24 02:22:38 -08001914 goto err_ioremap;
1915
Stephen Hemminger2e5c6922008-11-19 22:20:44 -08001916 netdev->netdev_ops = &igb_netdev_ops;
Auke Kok9d5c8242008-01-24 02:22:38 -08001917 igb_set_ethtool_ops(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001918 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9d5c8242008-01-24 02:22:38 -08001919
1920 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
1921
1922 netdev->mem_start = mmio_start;
1923 netdev->mem_end = mmio_start + mmio_len;
1924
Auke Kok9d5c8242008-01-24 02:22:38 -08001925 /* PCI config space info */
1926 hw->vendor_id = pdev->vendor;
1927 hw->device_id = pdev->device;
1928 hw->revision_id = pdev->revision;
1929 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1930 hw->subsystem_device_id = pdev->subsystem_device;
1931
Auke Kok9d5c8242008-01-24 02:22:38 -08001932 /* Copy the default MAC, PHY and NVM function pointers */
1933 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
1934 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
1935 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
1936 /* Initialize skew-specific constants */
1937 err = ei->get_invariants(hw);
1938 if (err)
Alexander Duyck450c87c2009-02-06 23:22:11 +00001939 goto err_sw_init;
Auke Kok9d5c8242008-01-24 02:22:38 -08001940
Alexander Duyck450c87c2009-02-06 23:22:11 +00001941 /* setup the private structure */
Auke Kok9d5c8242008-01-24 02:22:38 -08001942 err = igb_sw_init(adapter);
1943 if (err)
1944 goto err_sw_init;
1945
1946 igb_get_bus_info_pcie(hw);
1947
1948 hw->phy.autoneg_wait_to_complete = false;
Auke Kok9d5c8242008-01-24 02:22:38 -08001949
1950 /* Copper options */
1951 if (hw->phy.media_type == e1000_media_type_copper) {
1952 hw->phy.mdix = AUTO_ALL_MODES;
1953 hw->phy.disable_polarity_correction = false;
1954 hw->phy.ms_type = e1000_ms_hw_default;
1955 }
1956
1957 if (igb_check_reset_block(hw))
1958 dev_info(&pdev->dev,
1959 "PHY reset is blocked due to SOL/IDER session.\n");
1960
Alexander Duyck077887c2011-08-26 07:46:29 +00001961 /*
1962 * features is initialized to 0 in allocation, it might have bits
1963 * set by igb_sw_init so we should use an or instead of an
1964 * assignment.
1965 */
1966 netdev->features |= NETIF_F_SG |
1967 NETIF_F_IP_CSUM |
1968 NETIF_F_IPV6_CSUM |
1969 NETIF_F_TSO |
1970 NETIF_F_TSO6 |
1971 NETIF_F_RXHASH |
1972 NETIF_F_RXCSUM |
1973 NETIF_F_HW_VLAN_RX |
1974 NETIF_F_HW_VLAN_TX;
Michał Mirosławac52caa2011-06-08 08:38:01 +00001975
Alexander Duyck077887c2011-08-26 07:46:29 +00001976 /* copy netdev features into list of user selectable features */
1977 netdev->hw_features |= netdev->features;
Ben Greear89eaefb2012-03-06 09:41:58 +00001978 netdev->hw_features |= NETIF_F_RXALL;
Auke Kok9d5c8242008-01-24 02:22:38 -08001979
Alexander Duyck077887c2011-08-26 07:46:29 +00001980 /* set this bit last since it cannot be part of hw_features */
1981 netdev->features |= NETIF_F_HW_VLAN_FILTER;
1982
1983 netdev->vlan_features |= NETIF_F_TSO |
1984 NETIF_F_TSO6 |
1985 NETIF_F_IP_CSUM |
1986 NETIF_F_IPV6_CSUM |
1987 NETIF_F_SG;
Jeff Kirsher48f29ff2008-06-05 04:06:27 -07001988
Ben Greear6b8f0922012-03-06 09:41:53 +00001989 netdev->priv_flags |= IFF_SUPP_NOFCS;
1990
Yi Zou7b872a52010-09-22 17:57:58 +00001991 if (pci_using_dac) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001992 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00001993 netdev->vlan_features |= NETIF_F_HIGHDMA;
1994 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001995
Michał Mirosławac52caa2011-06-08 08:38:01 +00001996 if (hw->mac.type >= e1000_82576) {
1997 netdev->hw_features |= NETIF_F_SCTP_CSUM;
Jesse Brandeburgb9473562009-04-27 22:36:13 +00001998 netdev->features |= NETIF_F_SCTP_CSUM;
Michał Mirosławac52caa2011-06-08 08:38:01 +00001999 }
Jesse Brandeburgb9473562009-04-27 22:36:13 +00002000
Jiri Pirko01789342011-08-16 06:29:00 +00002001 netdev->priv_flags |= IFF_UNICAST_FLT;
2002
Alexander Duyck330a6d62009-10-27 23:51:35 +00002003 adapter->en_mng_pt = igb_enable_mng_pass_thru(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002004
2005 /* before reading the NVM, reset the controller to put the device in a
2006 * known good starting state */
2007 hw->mac.ops.reset_hw(hw);
2008
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002009 /*
2010 * make sure the NVM is good , i211 parts have special NVM that
2011 * doesn't contain a checksum
2012 */
2013 if (hw->mac.type != e1000_i211) {
2014 if (hw->nvm.ops.validate(hw) < 0) {
2015 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
2016 err = -EIO;
2017 goto err_eeprom;
2018 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002019 }
2020
2021 /* copy the MAC address out of the NVM */
2022 if (hw->mac.ops.read_mac_addr(hw))
2023 dev_err(&pdev->dev, "NVM Read Error\n");
2024
2025 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
2026 memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
2027
2028 if (!is_valid_ether_addr(netdev->perm_addr)) {
2029 dev_err(&pdev->dev, "Invalid MAC Address\n");
2030 err = -EIO;
2031 goto err_eeprom;
2032 }
2033
Carolyn Wybornyd67974f2012-06-14 16:04:19 +00002034 /* get firmware version for ethtool -i */
2035 igb_set_fw_version(adapter);
2036
Joe Perchesc061b182010-08-23 18:20:03 +00002037 setup_timer(&adapter->watchdog_timer, igb_watchdog,
Alexander Duyck0e340482009-03-20 00:17:08 +00002038 (unsigned long) adapter);
Joe Perchesc061b182010-08-23 18:20:03 +00002039 setup_timer(&adapter->phy_info_timer, igb_update_phy_info,
Alexander Duyck0e340482009-03-20 00:17:08 +00002040 (unsigned long) adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08002041
2042 INIT_WORK(&adapter->reset_task, igb_reset_task);
2043 INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
2044
Alexander Duyck450c87c2009-02-06 23:22:11 +00002045 /* Initialize link properties that are user-changeable */
Auke Kok9d5c8242008-01-24 02:22:38 -08002046 adapter->fc_autoneg = true;
2047 hw->mac.autoneg = true;
2048 hw->phy.autoneg_advertised = 0x2f;
2049
Alexander Duyck0cce1192009-07-23 18:10:24 +00002050 hw->fc.requested_mode = e1000_fc_default;
2051 hw->fc.current_mode = e1000_fc_default;
Auke Kok9d5c8242008-01-24 02:22:38 -08002052
Auke Kok9d5c8242008-01-24 02:22:38 -08002053 igb_validate_mdi_setting(hw);
2054
Matthew Vick63d4a8f2012-11-09 05:49:54 +00002055 /* By default, support wake on port A */
Alexander Duycka2cf8b62009-03-13 20:41:17 +00002056 if (hw->bus.func == 0)
Matthew Vick63d4a8f2012-11-09 05:49:54 +00002057 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2058
2059 /* Check the NVM for wake support on non-port A ports */
2060 if (hw->mac.type >= e1000_82580)
Alexander Duyck55cac242009-11-19 12:42:21 +00002061 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2062 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2063 &eeprom_data);
Alexander Duycka2cf8b62009-03-13 20:41:17 +00002064 else if (hw->bus.func == 1)
2065 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08002066
Matthew Vick63d4a8f2012-11-09 05:49:54 +00002067 if (eeprom_data & IGB_EEPROM_APME)
2068 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
Auke Kok9d5c8242008-01-24 02:22:38 -08002069
2070 /* now that we have the eeprom settings, apply the special cases where
2071 * the eeprom may be wrong or the board simply won't support wake on
2072 * lan on a particular port */
2073 switch (pdev->device) {
2074 case E1000_DEV_ID_82575GB_QUAD_COPPER:
Matthew Vick63d4a8f2012-11-09 05:49:54 +00002075 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
Auke Kok9d5c8242008-01-24 02:22:38 -08002076 break;
2077 case E1000_DEV_ID_82575EB_FIBER_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -07002078 case E1000_DEV_ID_82576_FIBER:
2079 case E1000_DEV_ID_82576_SERDES:
Auke Kok9d5c8242008-01-24 02:22:38 -08002080 /* Wake events only supported on port A for dual fiber
2081 * regardless of eeprom setting */
2082 if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1)
Matthew Vick63d4a8f2012-11-09 05:49:54 +00002083 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
Auke Kok9d5c8242008-01-24 02:22:38 -08002084 break;
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +00002085 case E1000_DEV_ID_82576_QUAD_COPPER:
Stefan Assmannd5aa2252010-04-09 09:51:34 +00002086 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +00002087 /* if quad port adapter, disable WoL on all but port A */
2088 if (global_quad_port_a != 0)
Matthew Vick63d4a8f2012-11-09 05:49:54 +00002089 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +00002090 else
2091 adapter->flags |= IGB_FLAG_QUAD_PORT_A;
2092 /* Reset for multiple quad port adapters */
2093 if (++global_quad_port_a == 4)
2094 global_quad_port_a = 0;
2095 break;
Matthew Vick63d4a8f2012-11-09 05:49:54 +00002096 default:
2097 /* If the device can't wake, don't set software support */
2098 if (!device_can_wakeup(&adapter->pdev->dev))
2099 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
Auke Kok9d5c8242008-01-24 02:22:38 -08002100 }
2101
2102 /* initialize the wol settings based on the eeprom settings */
Matthew Vick63d4a8f2012-11-09 05:49:54 +00002103 if (adapter->flags & IGB_FLAG_WOL_SUPPORTED)
2104 adapter->wol |= E1000_WUFC_MAG;
2105
2106 /* Some vendors want WoL disabled by default, but still supported */
2107 if ((hw->mac.type == e1000_i350) &&
2108 (pdev->subsystem_vendor == PCI_VENDOR_ID_HP)) {
2109 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2110 adapter->wol = 0;
2111 }
2112
2113 device_set_wakeup_enable(&adapter->pdev->dev,
2114 adapter->flags & IGB_FLAG_WOL_SUPPORTED);
Auke Kok9d5c8242008-01-24 02:22:38 -08002115
2116 /* reset the hardware with the new settings */
2117 igb_reset(adapter);
2118
2119 /* let the f/w know that the h/w is now under the control of the
2120 * driver. */
2121 igb_get_hw_control(adapter);
2122
Auke Kok9d5c8242008-01-24 02:22:38 -08002123 strcpy(netdev->name, "eth%d");
2124 err = register_netdev(netdev);
2125 if (err)
2126 goto err_register;
2127
Jesse Brandeburgb168dfc2009-04-17 20:44:32 +00002128 /* carrier off reporting is important to ethtool even BEFORE open */
2129 netif_carrier_off(netdev);
2130
Jeff Kirsher421e02f2008-10-17 11:08:31 -07002131#ifdef CONFIG_IGB_DCA
Alexander Duyckbbd98fe2009-01-31 00:52:30 -08002132 if (dca_add_requester(&pdev->dev) == 0) {
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07002133 adapter->flags |= IGB_FLAG_DCA_ENABLED;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07002134 dev_info(&pdev->dev, "DCA enabled\n");
Jeb Cramerfe4506b2008-07-08 15:07:55 -07002135 igb_setup_dca(adapter);
2136 }
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00002137
Jeb Cramerfe4506b2008-07-08 15:07:55 -07002138#endif
Matthew Vick3c89f6d2012-08-10 05:40:43 +00002139
Anders Berggren673b8b72011-02-04 07:32:32 +00002140 /* do hw tstamp init after resetting */
Richard Cochran7ebae812012-03-16 10:55:37 +00002141 igb_ptp_init(adapter);
Anders Berggren673b8b72011-02-04 07:32:32 +00002142
Auke Kok9d5c8242008-01-24 02:22:38 -08002143 dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
2144 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07002145 dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n",
Auke Kok9d5c8242008-01-24 02:22:38 -08002146 netdev->name,
Alexander Duyck559e9c42009-10-27 23:52:50 +00002147 ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
Alexander Duyckff846f52010-04-27 01:02:40 +00002148 (hw->bus.speed == e1000_bus_speed_5000) ? "5.0Gb/s" :
Alexander Duyck559e9c42009-10-27 23:52:50 +00002149 "unknown"),
Alexander Duyck59c3de82009-03-31 20:38:00 +00002150 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
2151 (hw->bus.width == e1000_bus_width_pcie_x2) ? "Width x2" :
2152 (hw->bus.width == e1000_bus_width_pcie_x1) ? "Width x1" :
2153 "unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07002154 netdev->dev_addr);
Auke Kok9d5c8242008-01-24 02:22:38 -08002155
Carolyn Wyborny9835fd72010-11-22 17:17:21 +00002156 ret_val = igb_read_part_string(hw, part_str, E1000_PBANUM_LENGTH);
2157 if (ret_val)
2158 strcpy(part_str, "Unknown");
2159 dev_info(&pdev->dev, "%s: PBA No: %s\n", netdev->name, part_str);
Auke Kok9d5c8242008-01-24 02:22:38 -08002160 dev_info(&pdev->dev,
2161 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
2162 adapter->msix_entries ? "MSI-X" :
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07002163 (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
Auke Kok9d5c8242008-01-24 02:22:38 -08002164 adapter->num_rx_queues, adapter->num_tx_queues);
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002165 switch (hw->mac.type) {
2166 case e1000_i350:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002167 case e1000_i210:
2168 case e1000_i211:
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002169 igb_set_eee_i350(hw);
2170 break;
2171 default:
2172 break;
2173 }
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002174
2175 pm_runtime_put_noidle(&pdev->dev);
Auke Kok9d5c8242008-01-24 02:22:38 -08002176 return 0;
2177
2178err_register:
2179 igb_release_hw_control(adapter);
2180err_eeprom:
2181 if (!igb_check_reset_block(hw))
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08002182 igb_reset_phy(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002183
2184 if (hw->flash_address)
2185 iounmap(hw->flash_address);
Auke Kok9d5c8242008-01-24 02:22:38 -08002186err_sw_init:
Alexander Duyck047e0032009-10-27 15:49:27 +00002187 igb_clear_interrupt_scheme(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08002188 iounmap(hw->hw_addr);
2189err_ioremap:
2190 free_netdev(netdev);
2191err_alloc_etherdev:
Alexander Duyck559e9c42009-10-27 23:52:50 +00002192 pci_release_selected_regions(pdev,
2193 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9d5c8242008-01-24 02:22:38 -08002194err_pci_reg:
2195err_dma:
2196 pci_disable_device(pdev);
2197 return err;
2198}
2199
2200/**
2201 * igb_remove - Device Removal Routine
2202 * @pdev: PCI device information struct
2203 *
2204 * igb_remove is called by the PCI subsystem to alert the driver
2205 * that it should release a PCI device. The could be caused by a
2206 * Hot-Plug event, or because the driver is going to be removed from
2207 * memory.
2208 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002209static void igb_remove(struct pci_dev *pdev)
Auke Kok9d5c8242008-01-24 02:22:38 -08002210{
2211 struct net_device *netdev = pci_get_drvdata(pdev);
2212 struct igb_adapter *adapter = netdev_priv(netdev);
Jeb Cramerfe4506b2008-07-08 15:07:55 -07002213 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08002214
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002215 pm_runtime_get_noresume(&pdev->dev);
Matthew Vicka79f4f82012-08-10 05:40:44 +00002216 igb_ptp_stop(adapter);
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002217
Tejun Heo760141a2010-12-12 16:45:14 +01002218 /*
2219 * The watchdog timer may be rescheduled, so explicitly
2220 * disable watchdog from being rescheduled.
2221 */
Auke Kok9d5c8242008-01-24 02:22:38 -08002222 set_bit(__IGB_DOWN, &adapter->state);
2223 del_timer_sync(&adapter->watchdog_timer);
2224 del_timer_sync(&adapter->phy_info_timer);
2225
Tejun Heo760141a2010-12-12 16:45:14 +01002226 cancel_work_sync(&adapter->reset_task);
2227 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9d5c8242008-01-24 02:22:38 -08002228
Jeff Kirsher421e02f2008-10-17 11:08:31 -07002229#ifdef CONFIG_IGB_DCA
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07002230 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
Jeb Cramerfe4506b2008-07-08 15:07:55 -07002231 dev_info(&pdev->dev, "DCA disabled\n");
2232 dca_remove_requester(&pdev->dev);
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07002233 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
Alexander Duyckcbd347a2009-02-15 23:59:44 -08002234 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
Jeb Cramerfe4506b2008-07-08 15:07:55 -07002235 }
2236#endif
2237
Auke Kok9d5c8242008-01-24 02:22:38 -08002238 /* Release control of h/w to f/w. If f/w is AMT enabled, this
2239 * would have already happened in close and is redundant. */
2240 igb_release_hw_control(adapter);
2241
2242 unregister_netdev(netdev);
2243
Alexander Duyck047e0032009-10-27 15:49:27 +00002244 igb_clear_interrupt_scheme(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08002245
Alexander Duyck37680112009-02-19 20:40:30 -08002246#ifdef CONFIG_PCI_IOV
2247 /* reclaim resources allocated to VFs */
2248 if (adapter->vf_data) {
2249 /* disable iov and allow time for transactions to clear */
Stefan Assmannf5571472012-08-18 04:06:11 +00002250 if (igb_vfs_are_assigned(adapter)) {
2251 dev_info(&pdev->dev, "Unloading driver while VFs are assigned - VFs will not be deallocated\n");
2252 } else {
Greg Rose0224d662011-10-14 02:57:14 +00002253 pci_disable_sriov(pdev);
2254 msleep(500);
Greg Rose0224d662011-10-14 02:57:14 +00002255 }
Alexander Duyck37680112009-02-19 20:40:30 -08002256
2257 kfree(adapter->vf_data);
2258 adapter->vf_data = NULL;
2259 wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00002260 wrfl();
Alexander Duyck37680112009-02-19 20:40:30 -08002261 msleep(100);
2262 dev_info(&pdev->dev, "IOV Disabled\n");
2263 }
2264#endif
Alexander Duyck559e9c42009-10-27 23:52:50 +00002265
Alexander Duyck28b07592009-02-06 23:20:31 +00002266 iounmap(hw->hw_addr);
2267 if (hw->flash_address)
2268 iounmap(hw->flash_address);
Alexander Duyck559e9c42009-10-27 23:52:50 +00002269 pci_release_selected_regions(pdev,
2270 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9d5c8242008-01-24 02:22:38 -08002271
Carolyn Wyborny1128c752011-10-14 00:13:49 +00002272 kfree(adapter->shadow_vfta);
Auke Kok9d5c8242008-01-24 02:22:38 -08002273 free_netdev(netdev);
2274
Frans Pop19d5afd2009-10-02 10:04:12 -07002275 pci_disable_pcie_error_reporting(pdev);
Alexander Duyck40a914f2008-11-27 00:24:37 -08002276
Auke Kok9d5c8242008-01-24 02:22:38 -08002277 pci_disable_device(pdev);
2278}
2279
2280/**
Alexander Duycka6b623e2009-10-27 23:47:53 +00002281 * igb_probe_vfs - Initialize vf data storage and add VFs to pci config space
2282 * @adapter: board private structure to initialize
2283 *
2284 * This function initializes the vf specific data storage and then attempts to
2285 * allocate the VFs. The reason for ordering it this way is because it is much
2286 * mor expensive time wise to disable SR-IOV than it is to allocate and free
2287 * the memory for the VFs.
2288 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002289static void igb_probe_vfs(struct igb_adapter *adapter)
Alexander Duycka6b623e2009-10-27 23:47:53 +00002290{
2291#ifdef CONFIG_PCI_IOV
2292 struct pci_dev *pdev = adapter->pdev;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002293 struct e1000_hw *hw = &adapter->hw;
Stefan Assmannf5571472012-08-18 04:06:11 +00002294 int old_vfs = pci_num_vf(adapter->pdev);
Greg Rose0224d662011-10-14 02:57:14 +00002295 int i;
Alexander Duycka6b623e2009-10-27 23:47:53 +00002296
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002297 /* Virtualization features not supported on i210 family. */
2298 if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211))
2299 return;
2300
Greg Rose0224d662011-10-14 02:57:14 +00002301 if (old_vfs) {
2302 dev_info(&pdev->dev, "%d pre-allocated VFs found - override "
2303 "max_vfs setting of %d\n", old_vfs, max_vfs);
2304 adapter->vfs_allocated_count = old_vfs;
Alexander Duycka6b623e2009-10-27 23:47:53 +00002305 }
2306
Greg Rose0224d662011-10-14 02:57:14 +00002307 if (!adapter->vfs_allocated_count)
2308 return;
2309
2310 adapter->vf_data = kcalloc(adapter->vfs_allocated_count,
2311 sizeof(struct vf_data_storage), GFP_KERNEL);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002312
Greg Rose0224d662011-10-14 02:57:14 +00002313 /* if allocation failed then we do not support SR-IOV */
2314 if (!adapter->vf_data) {
Alexander Duycka6b623e2009-10-27 23:47:53 +00002315 adapter->vfs_allocated_count = 0;
Greg Rose0224d662011-10-14 02:57:14 +00002316 dev_err(&pdev->dev, "Unable to allocate memory for VF "
2317 "Data Storage\n");
2318 goto out;
Alexander Duycka6b623e2009-10-27 23:47:53 +00002319 }
Greg Rose0224d662011-10-14 02:57:14 +00002320
2321 if (!old_vfs) {
2322 if (pci_enable_sriov(pdev, adapter->vfs_allocated_count))
2323 goto err_out;
2324 }
2325 dev_info(&pdev->dev, "%d VFs allocated\n",
2326 adapter->vfs_allocated_count);
2327 for (i = 0; i < adapter->vfs_allocated_count; i++)
2328 igb_vf_configure(adapter, i);
2329
2330 /* DMA Coalescing is not supported in IOV mode. */
2331 adapter->flags &= ~IGB_FLAG_DMAC;
2332 goto out;
2333err_out:
2334 kfree(adapter->vf_data);
2335 adapter->vf_data = NULL;
2336 adapter->vfs_allocated_count = 0;
2337out:
2338 return;
Alexander Duycka6b623e2009-10-27 23:47:53 +00002339#endif /* CONFIG_PCI_IOV */
2340}
2341
Alexander Duyck115f4592009-11-12 18:37:00 +00002342/**
Auke Kok9d5c8242008-01-24 02:22:38 -08002343 * igb_sw_init - Initialize general software structures (struct igb_adapter)
2344 * @adapter: board private structure to initialize
2345 *
2346 * igb_sw_init initializes the Adapter private data structure.
2347 * Fields are initialized based on PCI device information and
2348 * OS network device settings (MTU size).
2349 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -05002350static int igb_sw_init(struct igb_adapter *adapter)
Auke Kok9d5c8242008-01-24 02:22:38 -08002351{
2352 struct e1000_hw *hw = &adapter->hw;
2353 struct net_device *netdev = adapter->netdev;
2354 struct pci_dev *pdev = adapter->pdev;
Matthew Vick374a5422012-05-18 04:54:58 +00002355 u32 max_rss_queues;
Auke Kok9d5c8242008-01-24 02:22:38 -08002356
2357 pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
2358
Alexander Duyck13fde972011-10-05 13:35:24 +00002359 /* set default ring sizes */
Alexander Duyck68fd9912008-11-20 00:48:10 -08002360 adapter->tx_ring_count = IGB_DEFAULT_TXD;
2361 adapter->rx_ring_count = IGB_DEFAULT_RXD;
Alexander Duyck13fde972011-10-05 13:35:24 +00002362
2363 /* set default ITR values */
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002364 adapter->rx_itr_setting = IGB_DEFAULT_ITR;
2365 adapter->tx_itr_setting = IGB_DEFAULT_ITR;
2366
Alexander Duyck13fde972011-10-05 13:35:24 +00002367 /* set default work limits */
2368 adapter->tx_work_limit = IGB_DEFAULT_TX_WORK;
2369
Alexander Duyck153285f2011-08-26 07:43:32 +00002370 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN +
2371 VLAN_HLEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08002372 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
2373
Eric Dumazet12dcd862010-10-15 17:27:10 +00002374 spin_lock_init(&adapter->stats64_lock);
Alexander Duycka6b623e2009-10-27 23:47:53 +00002375#ifdef CONFIG_PCI_IOV
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +00002376 switch (hw->mac.type) {
2377 case e1000_82576:
2378 case e1000_i350:
Stefan Assmann9b082d72011-02-24 20:03:31 +00002379 if (max_vfs > 7) {
2380 dev_warn(&pdev->dev,
2381 "Maximum of 7 VFs per PF, using max\n");
2382 adapter->vfs_allocated_count = 7;
2383 } else
2384 adapter->vfs_allocated_count = max_vfs;
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +00002385 break;
2386 default:
2387 break;
2388 }
Alexander Duycka6b623e2009-10-27 23:47:53 +00002389#endif /* CONFIG_PCI_IOV */
Matthew Vick374a5422012-05-18 04:54:58 +00002390
2391 /* Determine the maximum number of RSS queues supported. */
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002392 switch (hw->mac.type) {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002393 case e1000_i211:
Matthew Vick374a5422012-05-18 04:54:58 +00002394 max_rss_queues = IGB_MAX_RX_QUEUES_I211;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002395 break;
Matthew Vick374a5422012-05-18 04:54:58 +00002396 case e1000_82575:
2397 case e1000_i210:
2398 max_rss_queues = IGB_MAX_RX_QUEUES_82575;
2399 break;
2400 case e1000_i350:
2401 /* I350 cannot do RSS and SR-IOV at the same time */
2402 if (!!adapter->vfs_allocated_count) {
2403 max_rss_queues = 1;
2404 break;
2405 }
2406 /* fall through */
2407 case e1000_82576:
2408 if (!!adapter->vfs_allocated_count) {
2409 max_rss_queues = 2;
2410 break;
2411 }
2412 /* fall through */
2413 case e1000_82580:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002414 default:
Matthew Vick374a5422012-05-18 04:54:58 +00002415 max_rss_queues = IGB_MAX_RX_QUEUES;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002416 break;
2417 }
Alexander Duycka99955f2009-11-12 18:37:19 +00002418
Matthew Vick374a5422012-05-18 04:54:58 +00002419 adapter->rss_queues = min_t(u32, max_rss_queues, num_online_cpus());
2420
2421 /* Determine if we need to pair queues. */
2422 switch (hw->mac.type) {
2423 case e1000_82575:
2424 case e1000_i211:
2425 /* Device supports enough interrupts without queue pairing. */
2426 break;
2427 case e1000_82576:
2428 /*
2429 * If VFs are going to be allocated with RSS queues then we
2430 * should pair the queues in order to conserve interrupts due
2431 * to limited supply.
2432 */
2433 if ((adapter->rss_queues > 1) &&
2434 (adapter->vfs_allocated_count > 6))
2435 adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
2436 /* fall through */
2437 case e1000_82580:
2438 case e1000_i350:
2439 case e1000_i210:
2440 default:
2441 /*
2442 * If rss_queues > half of max_rss_queues, pair the queues in
2443 * order to conserve interrupts due to limited supply.
2444 */
2445 if (adapter->rss_queues > (max_rss_queues / 2))
2446 adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
2447 break;
2448 }
Alexander Duycka99955f2009-11-12 18:37:19 +00002449
Carolyn Wyborny1128c752011-10-14 00:13:49 +00002450 /* Setup and initialize a copy of the hw vlan table array */
2451 adapter->shadow_vfta = kzalloc(sizeof(u32) *
2452 E1000_VLAN_FILTER_TBL_SIZE,
2453 GFP_ATOMIC);
2454
Alexander Duycka6b623e2009-10-27 23:47:53 +00002455 /* This call may decrease the number of queues */
Stefan Assmann53c7d062012-12-04 06:00:12 +00002456 if (igb_init_interrupt_scheme(adapter, true)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08002457 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
2458 return -ENOMEM;
2459 }
2460
Alexander Duycka6b623e2009-10-27 23:47:53 +00002461 igb_probe_vfs(adapter);
2462
Auke Kok9d5c8242008-01-24 02:22:38 -08002463 /* Explicitly disable IRQ since the NIC can be in any state. */
2464 igb_irq_disable(adapter);
2465
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002466 if (hw->mac.type >= e1000_i350)
Carolyn Wyborny831ec0b2011-03-11 20:43:54 -08002467 adapter->flags &= ~IGB_FLAG_DMAC;
2468
Auke Kok9d5c8242008-01-24 02:22:38 -08002469 set_bit(__IGB_DOWN, &adapter->state);
2470 return 0;
2471}
2472
2473/**
2474 * igb_open - Called when a network interface is made active
2475 * @netdev: network interface device structure
2476 *
2477 * Returns 0 on success, negative value on failure
2478 *
2479 * The open entry point is called when a network interface is made
2480 * active by the system (IFF_UP). At this point all resources needed
2481 * for transmit and receive operations are allocated, the interrupt
2482 * handler is registered with the OS, the watchdog timer is started,
2483 * and the stack is notified that the interface is ready.
2484 **/
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002485static int __igb_open(struct net_device *netdev, bool resuming)
Auke Kok9d5c8242008-01-24 02:22:38 -08002486{
2487 struct igb_adapter *adapter = netdev_priv(netdev);
2488 struct e1000_hw *hw = &adapter->hw;
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002489 struct pci_dev *pdev = adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08002490 int err;
2491 int i;
2492
2493 /* disallow open during test */
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002494 if (test_bit(__IGB_TESTING, &adapter->state)) {
2495 WARN_ON(resuming);
Auke Kok9d5c8242008-01-24 02:22:38 -08002496 return -EBUSY;
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002497 }
2498
2499 if (!resuming)
2500 pm_runtime_get_sync(&pdev->dev);
Auke Kok9d5c8242008-01-24 02:22:38 -08002501
Jesse Brandeburgb168dfc2009-04-17 20:44:32 +00002502 netif_carrier_off(netdev);
2503
Auke Kok9d5c8242008-01-24 02:22:38 -08002504 /* allocate transmit descriptors */
2505 err = igb_setup_all_tx_resources(adapter);
2506 if (err)
2507 goto err_setup_tx;
2508
2509 /* allocate receive descriptors */
2510 err = igb_setup_all_rx_resources(adapter);
2511 if (err)
2512 goto err_setup_rx;
2513
Nick Nunley88a268c2010-02-17 01:01:59 +00002514 igb_power_up_link(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08002515
Auke Kok9d5c8242008-01-24 02:22:38 -08002516 /* before we allocate an interrupt, we must be ready to handle it.
2517 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
2518 * as soon as we call pci_request_irq, so we have to setup our
2519 * clean_rx handler before we do so. */
2520 igb_configure(adapter);
2521
2522 err = igb_request_irq(adapter);
2523 if (err)
2524 goto err_req_irq;
2525
Alexander Duyck0c2cc022012-09-25 00:31:22 +00002526 /* Notify the stack of the actual queue counts. */
2527 err = netif_set_real_num_tx_queues(adapter->netdev,
2528 adapter->num_tx_queues);
2529 if (err)
2530 goto err_set_queues;
2531
2532 err = netif_set_real_num_rx_queues(adapter->netdev,
2533 adapter->num_rx_queues);
2534 if (err)
2535 goto err_set_queues;
2536
Auke Kok9d5c8242008-01-24 02:22:38 -08002537 /* From here on the code is the same as igb_up() */
2538 clear_bit(__IGB_DOWN, &adapter->state);
2539
Alexander Duyck0d1ae7f2011-08-26 07:46:34 +00002540 for (i = 0; i < adapter->num_q_vectors; i++)
2541 napi_enable(&(adapter->q_vector[i]->napi));
Auke Kok9d5c8242008-01-24 02:22:38 -08002542
2543 /* Clear any pending interrupts. */
2544 rd32(E1000_ICR);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07002545
2546 igb_irq_enable(adapter);
2547
Alexander Duyckd4960302009-10-27 15:53:45 +00002548 /* notify VFs that reset has been completed */
2549 if (adapter->vfs_allocated_count) {
2550 u32 reg_data = rd32(E1000_CTRL_EXT);
2551 reg_data |= E1000_CTRL_EXT_PFRSTD;
2552 wr32(E1000_CTRL_EXT, reg_data);
2553 }
2554
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07002555 netif_tx_start_all_queues(netdev);
2556
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002557 if (!resuming)
2558 pm_runtime_put(&pdev->dev);
2559
Alexander Duyck25568a52009-10-27 23:49:59 +00002560 /* start the watchdog. */
2561 hw->mac.get_link_status = 1;
2562 schedule_work(&adapter->watchdog_task);
Auke Kok9d5c8242008-01-24 02:22:38 -08002563
2564 return 0;
2565
Alexander Duyck0c2cc022012-09-25 00:31:22 +00002566err_set_queues:
2567 igb_free_irq(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08002568err_req_irq:
2569 igb_release_hw_control(adapter);
Nick Nunley88a268c2010-02-17 01:01:59 +00002570 igb_power_down_link(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08002571 igb_free_all_rx_resources(adapter);
2572err_setup_rx:
2573 igb_free_all_tx_resources(adapter);
2574err_setup_tx:
2575 igb_reset(adapter);
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002576 if (!resuming)
2577 pm_runtime_put(&pdev->dev);
Auke Kok9d5c8242008-01-24 02:22:38 -08002578
2579 return err;
2580}
2581
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002582static int igb_open(struct net_device *netdev)
2583{
2584 return __igb_open(netdev, false);
2585}
2586
Auke Kok9d5c8242008-01-24 02:22:38 -08002587/**
2588 * igb_close - Disables a network interface
2589 * @netdev: network interface device structure
2590 *
2591 * Returns 0, this is not allowed to fail
2592 *
2593 * The close entry point is called when an interface is de-activated
2594 * by the OS. The hardware is still under the driver's control, but
2595 * needs to be disabled. A global MAC reset is issued to stop the
2596 * hardware, and all transmit and receive resources are freed.
2597 **/
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002598static int __igb_close(struct net_device *netdev, bool suspending)
Auke Kok9d5c8242008-01-24 02:22:38 -08002599{
2600 struct igb_adapter *adapter = netdev_priv(netdev);
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002601 struct pci_dev *pdev = adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08002602
2603 WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
Auke Kok9d5c8242008-01-24 02:22:38 -08002604
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002605 if (!suspending)
2606 pm_runtime_get_sync(&pdev->dev);
2607
2608 igb_down(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08002609 igb_free_irq(adapter);
2610
2611 igb_free_all_tx_resources(adapter);
2612 igb_free_all_rx_resources(adapter);
2613
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002614 if (!suspending)
2615 pm_runtime_put_sync(&pdev->dev);
Auke Kok9d5c8242008-01-24 02:22:38 -08002616 return 0;
2617}
2618
Yan, Zheng749ab2c2012-01-04 20:23:37 +00002619static int igb_close(struct net_device *netdev)
2620{
2621 return __igb_close(netdev, false);
2622}
2623
Auke Kok9d5c8242008-01-24 02:22:38 -08002624/**
2625 * igb_setup_tx_resources - allocate Tx resources (Descriptors)
Auke Kok9d5c8242008-01-24 02:22:38 -08002626 * @tx_ring: tx descriptor ring (for a specific queue) to setup
2627 *
2628 * Return 0 on success, negative on failure
2629 **/
Alexander Duyck80785292009-10-27 15:51:47 +00002630int igb_setup_tx_resources(struct igb_ring *tx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08002631{
Alexander Duyck59d71982010-04-27 13:09:25 +00002632 struct device *dev = tx_ring->dev;
Auke Kok9d5c8242008-01-24 02:22:38 -08002633 int size;
2634
Alexander Duyck06034642011-08-26 07:44:22 +00002635 size = sizeof(struct igb_tx_buffer) * tx_ring->count;
Alexander Duyckf33005a2012-09-13 06:27:55 +00002636
2637 tx_ring->tx_buffer_info = vzalloc(size);
Alexander Duyck06034642011-08-26 07:44:22 +00002638 if (!tx_ring->tx_buffer_info)
Auke Kok9d5c8242008-01-24 02:22:38 -08002639 goto err;
Auke Kok9d5c8242008-01-24 02:22:38 -08002640
2641 /* round up to nearest 4K */
Alexander Duyck85e8d002009-02-16 00:00:20 -08002642 tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
Auke Kok9d5c8242008-01-24 02:22:38 -08002643 tx_ring->size = ALIGN(tx_ring->size, 4096);
2644
Alexander Duyck5536d212012-09-25 00:31:17 +00002645 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
2646 &tx_ring->dma, GFP_KERNEL);
Auke Kok9d5c8242008-01-24 02:22:38 -08002647 if (!tx_ring->desc)
2648 goto err;
2649
Auke Kok9d5c8242008-01-24 02:22:38 -08002650 tx_ring->next_to_use = 0;
2651 tx_ring->next_to_clean = 0;
Alexander Duyck81c2fc22011-08-26 07:45:20 +00002652
Auke Kok9d5c8242008-01-24 02:22:38 -08002653 return 0;
2654
2655err:
Alexander Duyck06034642011-08-26 07:44:22 +00002656 vfree(tx_ring->tx_buffer_info);
Alexander Duyckf33005a2012-09-13 06:27:55 +00002657 tx_ring->tx_buffer_info = NULL;
2658 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08002659 return -ENOMEM;
2660}
2661
2662/**
2663 * igb_setup_all_tx_resources - wrapper to allocate Tx resources
2664 * (Descriptors) for all queues
2665 * @adapter: board private structure
2666 *
2667 * Return 0 on success, negative on failure
2668 **/
2669static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
2670{
Alexander Duyck439705e2009-10-27 23:49:20 +00002671 struct pci_dev *pdev = adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08002672 int i, err = 0;
2673
2674 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +00002675 err = igb_setup_tx_resources(adapter->tx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08002676 if (err) {
Alexander Duyck439705e2009-10-27 23:49:20 +00002677 dev_err(&pdev->dev,
Auke Kok9d5c8242008-01-24 02:22:38 -08002678 "Allocation for Tx Queue %u failed\n", i);
2679 for (i--; i >= 0; i--)
Alexander Duyck3025a442010-02-17 01:02:39 +00002680 igb_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08002681 break;
2682 }
2683 }
2684
2685 return err;
2686}
2687
2688/**
Alexander Duyck85b430b2009-10-27 15:50:29 +00002689 * igb_setup_tctl - configure the transmit control registers
2690 * @adapter: Board private structure
Auke Kok9d5c8242008-01-24 02:22:38 -08002691 **/
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00002692void igb_setup_tctl(struct igb_adapter *adapter)
Auke Kok9d5c8242008-01-24 02:22:38 -08002693{
Auke Kok9d5c8242008-01-24 02:22:38 -08002694 struct e1000_hw *hw = &adapter->hw;
2695 u32 tctl;
Auke Kok9d5c8242008-01-24 02:22:38 -08002696
Alexander Duyck85b430b2009-10-27 15:50:29 +00002697 /* disable queue 0 which is enabled by default on 82575 and 82576 */
2698 wr32(E1000_TXDCTL(0), 0);
Auke Kok9d5c8242008-01-24 02:22:38 -08002699
2700 /* Program the Transmit Control Register */
Auke Kok9d5c8242008-01-24 02:22:38 -08002701 tctl = rd32(E1000_TCTL);
2702 tctl &= ~E1000_TCTL_CT;
2703 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2704 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2705
2706 igb_config_collision_dist(hw);
2707
Auke Kok9d5c8242008-01-24 02:22:38 -08002708 /* Enable transmits */
2709 tctl |= E1000_TCTL_EN;
2710
2711 wr32(E1000_TCTL, tctl);
2712}
2713
2714/**
Alexander Duyck85b430b2009-10-27 15:50:29 +00002715 * igb_configure_tx_ring - Configure transmit ring after Reset
2716 * @adapter: board private structure
2717 * @ring: tx ring to configure
2718 *
2719 * Configure a transmit ring after a reset.
2720 **/
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00002721void igb_configure_tx_ring(struct igb_adapter *adapter,
2722 struct igb_ring *ring)
Alexander Duyck85b430b2009-10-27 15:50:29 +00002723{
2724 struct e1000_hw *hw = &adapter->hw;
Alexander Duycka74420e2011-08-26 07:43:27 +00002725 u32 txdctl = 0;
Alexander Duyck85b430b2009-10-27 15:50:29 +00002726 u64 tdba = ring->dma;
2727 int reg_idx = ring->reg_idx;
2728
2729 /* disable the queue */
Alexander Duycka74420e2011-08-26 07:43:27 +00002730 wr32(E1000_TXDCTL(reg_idx), 0);
Alexander Duyck85b430b2009-10-27 15:50:29 +00002731 wrfl();
2732 mdelay(10);
2733
2734 wr32(E1000_TDLEN(reg_idx),
2735 ring->count * sizeof(union e1000_adv_tx_desc));
2736 wr32(E1000_TDBAL(reg_idx),
2737 tdba & 0x00000000ffffffffULL);
2738 wr32(E1000_TDBAH(reg_idx), tdba >> 32);
2739
Alexander Duyckfce99e32009-10-27 15:51:27 +00002740 ring->tail = hw->hw_addr + E1000_TDT(reg_idx);
Alexander Duycka74420e2011-08-26 07:43:27 +00002741 wr32(E1000_TDH(reg_idx), 0);
Alexander Duyckfce99e32009-10-27 15:51:27 +00002742 writel(0, ring->tail);
Alexander Duyck85b430b2009-10-27 15:50:29 +00002743
2744 txdctl |= IGB_TX_PTHRESH;
2745 txdctl |= IGB_TX_HTHRESH << 8;
2746 txdctl |= IGB_TX_WTHRESH << 16;
2747
2748 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
2749 wr32(E1000_TXDCTL(reg_idx), txdctl);
2750}
2751
2752/**
2753 * igb_configure_tx - Configure transmit Unit after Reset
2754 * @adapter: board private structure
2755 *
2756 * Configure the Tx unit of the MAC after a reset.
2757 **/
2758static void igb_configure_tx(struct igb_adapter *adapter)
2759{
2760 int i;
2761
2762 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +00002763 igb_configure_tx_ring(adapter, adapter->tx_ring[i]);
Alexander Duyck85b430b2009-10-27 15:50:29 +00002764}
2765
2766/**
Auke Kok9d5c8242008-01-24 02:22:38 -08002767 * igb_setup_rx_resources - allocate Rx resources (Descriptors)
Auke Kok9d5c8242008-01-24 02:22:38 -08002768 * @rx_ring: rx descriptor ring (for a specific queue) to setup
2769 *
2770 * Returns 0 on success, negative on failure
2771 **/
Alexander Duyck80785292009-10-27 15:51:47 +00002772int igb_setup_rx_resources(struct igb_ring *rx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08002773{
Alexander Duyck59d71982010-04-27 13:09:25 +00002774 struct device *dev = rx_ring->dev;
Alexander Duyckf33005a2012-09-13 06:27:55 +00002775 int size;
Auke Kok9d5c8242008-01-24 02:22:38 -08002776
Alexander Duyck06034642011-08-26 07:44:22 +00002777 size = sizeof(struct igb_rx_buffer) * rx_ring->count;
Alexander Duyckf33005a2012-09-13 06:27:55 +00002778
2779 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyck06034642011-08-26 07:44:22 +00002780 if (!rx_ring->rx_buffer_info)
Auke Kok9d5c8242008-01-24 02:22:38 -08002781 goto err;
Auke Kok9d5c8242008-01-24 02:22:38 -08002782
Auke Kok9d5c8242008-01-24 02:22:38 -08002783 /* Round up to nearest 4K */
Alexander Duyckf33005a2012-09-13 06:27:55 +00002784 rx_ring->size = rx_ring->count * sizeof(union e1000_adv_rx_desc);
Auke Kok9d5c8242008-01-24 02:22:38 -08002785 rx_ring->size = ALIGN(rx_ring->size, 4096);
2786
Alexander Duyck5536d212012-09-25 00:31:17 +00002787 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
2788 &rx_ring->dma, GFP_KERNEL);
Auke Kok9d5c8242008-01-24 02:22:38 -08002789 if (!rx_ring->desc)
2790 goto err;
2791
Alexander Duyckcbc8e552012-09-25 00:31:02 +00002792 rx_ring->next_to_alloc = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08002793 rx_ring->next_to_clean = 0;
2794 rx_ring->next_to_use = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08002795
Auke Kok9d5c8242008-01-24 02:22:38 -08002796 return 0;
2797
2798err:
Alexander Duyck06034642011-08-26 07:44:22 +00002799 vfree(rx_ring->rx_buffer_info);
2800 rx_ring->rx_buffer_info = NULL;
Alexander Duyckf33005a2012-09-13 06:27:55 +00002801 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08002802 return -ENOMEM;
2803}
2804
2805/**
2806 * igb_setup_all_rx_resources - wrapper to allocate Rx resources
2807 * (Descriptors) for all queues
2808 * @adapter: board private structure
2809 *
2810 * Return 0 on success, negative on failure
2811 **/
2812static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
2813{
Alexander Duyck439705e2009-10-27 23:49:20 +00002814 struct pci_dev *pdev = adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08002815 int i, err = 0;
2816
2817 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +00002818 err = igb_setup_rx_resources(adapter->rx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08002819 if (err) {
Alexander Duyck439705e2009-10-27 23:49:20 +00002820 dev_err(&pdev->dev,
Auke Kok9d5c8242008-01-24 02:22:38 -08002821 "Allocation for Rx Queue %u failed\n", i);
2822 for (i--; i >= 0; i--)
Alexander Duyck3025a442010-02-17 01:02:39 +00002823 igb_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08002824 break;
2825 }
2826 }
2827
2828 return err;
2829}
2830
2831/**
Alexander Duyck06cf2662009-10-27 15:53:25 +00002832 * igb_setup_mrqc - configure the multiple receive queue control registers
2833 * @adapter: Board private structure
2834 **/
2835static void igb_setup_mrqc(struct igb_adapter *adapter)
2836{
2837 struct e1000_hw *hw = &adapter->hw;
2838 u32 mrqc, rxcsum;
Alexander Duyck797fd4b2012-09-13 06:28:11 +00002839 u32 j, num_rx_queues, shift = 0;
Alexander Duycka57fe232012-09-13 06:28:16 +00002840 static const u32 rsskey[10] = { 0xDA565A6D, 0xC20E5B25, 0x3D256741,
2841 0xB08FA343, 0xCB2BCAD0, 0xB4307BAE,
2842 0xA32DCB77, 0x0CF23080, 0x3BB7426A,
2843 0xFA01ACBE };
Alexander Duyck06cf2662009-10-27 15:53:25 +00002844
2845 /* Fill out hash function seeds */
Alexander Duycka57fe232012-09-13 06:28:16 +00002846 for (j = 0; j < 10; j++)
2847 wr32(E1000_RSSRK(j), rsskey[j]);
Alexander Duyck06cf2662009-10-27 15:53:25 +00002848
Alexander Duycka99955f2009-11-12 18:37:19 +00002849 num_rx_queues = adapter->rss_queues;
Alexander Duyck06cf2662009-10-27 15:53:25 +00002850
Alexander Duyck797fd4b2012-09-13 06:28:11 +00002851 switch (hw->mac.type) {
2852 case e1000_82575:
2853 shift = 6;
2854 break;
2855 case e1000_82576:
2856 /* 82576 supports 2 RSS queues for SR-IOV */
2857 if (adapter->vfs_allocated_count) {
Alexander Duyck06cf2662009-10-27 15:53:25 +00002858 shift = 3;
2859 num_rx_queues = 2;
Alexander Duyck06cf2662009-10-27 15:53:25 +00002860 }
Alexander Duyck797fd4b2012-09-13 06:28:11 +00002861 break;
2862 default:
2863 break;
Alexander Duyck06cf2662009-10-27 15:53:25 +00002864 }
2865
Alexander Duyck797fd4b2012-09-13 06:28:11 +00002866 /*
2867 * Populate the indirection table 4 entries at a time. To do this
2868 * we are generating the results for n and n+2 and then interleaving
2869 * those with the results with n+1 and n+3.
2870 */
2871 for (j = 0; j < 32; j++) {
2872 /* first pass generates n and n+2 */
2873 u32 base = ((j * 0x00040004) + 0x00020000) * num_rx_queues;
2874 u32 reta = (base & 0x07800780) >> (7 - shift);
2875
2876 /* second pass generates n+1 and n+3 */
2877 base += 0x00010001 * num_rx_queues;
2878 reta |= (base & 0x07800780) << (1 + shift);
2879
2880 wr32(E1000_RETA(j), reta);
Alexander Duyck06cf2662009-10-27 15:53:25 +00002881 }
2882
2883 /*
2884 * Disable raw packet checksumming so that RSS hash is placed in
2885 * descriptor on writeback. No need to enable TCP/UDP/IP checksum
2886 * offloads as they are enabled by default
2887 */
2888 rxcsum = rd32(E1000_RXCSUM);
2889 rxcsum |= E1000_RXCSUM_PCSD;
2890
2891 if (adapter->hw.mac.type >= e1000_82576)
2892 /* Enable Receive Checksum Offload for SCTP */
2893 rxcsum |= E1000_RXCSUM_CRCOFL;
2894
2895 /* Don't need to set TUOFL or IPOFL, they default to 1 */
2896 wr32(E1000_RXCSUM, rxcsum);
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002897
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002898 /* Generate RSS hash based on packet types, TCP/UDP
2899 * port numbers and/or IPv4/v6 src and dst addresses
2900 */
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002901 mrqc = E1000_MRQC_RSS_FIELD_IPV4 |
2902 E1000_MRQC_RSS_FIELD_IPV4_TCP |
2903 E1000_MRQC_RSS_FIELD_IPV6 |
2904 E1000_MRQC_RSS_FIELD_IPV6_TCP |
2905 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX;
Alexander Duyck06cf2662009-10-27 15:53:25 +00002906
Akeem G. Abodunrin039454a2012-11-13 04:03:21 +00002907 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
2908 mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP;
2909 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
2910 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP;
2911
Alexander Duyck06cf2662009-10-27 15:53:25 +00002912 /* If VMDq is enabled then we set the appropriate mode for that, else
2913 * we default to RSS so that an RSS hash is calculated per packet even
2914 * if we are only using one queue */
2915 if (adapter->vfs_allocated_count) {
2916 if (hw->mac.type > e1000_82575) {
2917 /* Set the default pool for the PF's first queue */
2918 u32 vtctl = rd32(E1000_VT_CTL);
2919 vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK |
2920 E1000_VT_CTL_DISABLE_DEF_POOL);
2921 vtctl |= adapter->vfs_allocated_count <<
2922 E1000_VT_CTL_DEFAULT_POOL_SHIFT;
2923 wr32(E1000_VT_CTL, vtctl);
2924 }
Alexander Duycka99955f2009-11-12 18:37:19 +00002925 if (adapter->rss_queues > 1)
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002926 mrqc |= E1000_MRQC_ENABLE_VMDQ_RSS_2Q;
Alexander Duyck06cf2662009-10-27 15:53:25 +00002927 else
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002928 mrqc |= E1000_MRQC_ENABLE_VMDQ;
Alexander Duyck06cf2662009-10-27 15:53:25 +00002929 } else {
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00002930 if (hw->mac.type != e1000_i211)
2931 mrqc |= E1000_MRQC_ENABLE_RSS_4Q;
Alexander Duyck06cf2662009-10-27 15:53:25 +00002932 }
2933 igb_vmm_control(adapter);
2934
Alexander Duyck06cf2662009-10-27 15:53:25 +00002935 wr32(E1000_MRQC, mrqc);
2936}
2937
2938/**
Auke Kok9d5c8242008-01-24 02:22:38 -08002939 * igb_setup_rctl - configure the receive control registers
2940 * @adapter: Board private structure
2941 **/
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00002942void igb_setup_rctl(struct igb_adapter *adapter)
Auke Kok9d5c8242008-01-24 02:22:38 -08002943{
2944 struct e1000_hw *hw = &adapter->hw;
2945 u32 rctl;
Auke Kok9d5c8242008-01-24 02:22:38 -08002946
2947 rctl = rd32(E1000_RCTL);
2948
2949 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
Alexander Duyck69d728b2008-11-25 01:04:03 -08002950 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
Auke Kok9d5c8242008-01-24 02:22:38 -08002951
Alexander Duyck69d728b2008-11-25 01:04:03 -08002952 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
Alexander Duyck28b07592009-02-06 23:20:31 +00002953 (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kok9d5c8242008-01-24 02:22:38 -08002954
Auke Kok87cb7e82008-07-08 15:08:29 -07002955 /*
2956 * enable stripping of CRC. It's unlikely this will break BMC
2957 * redirection as it did with e1000. Newer features require
2958 * that the HW strips the CRC.
Alexander Duyck73cd78f2009-02-12 18:16:59 +00002959 */
Auke Kok87cb7e82008-07-08 15:08:29 -07002960 rctl |= E1000_RCTL_SECRC;
Auke Kok9d5c8242008-01-24 02:22:38 -08002961
Alexander Duyck559e9c42009-10-27 23:52:50 +00002962 /* disable store bad packets and clear size bits. */
Alexander Duyckec54d7d2009-01-31 00:52:57 -08002963 rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256);
Auke Kok9d5c8242008-01-24 02:22:38 -08002964
Alexander Duyck6ec43fe2009-10-27 15:50:48 +00002965 /* enable LPE to prevent packets larger than max_frame_size */
2966 rctl |= E1000_RCTL_LPE;
Auke Kok9d5c8242008-01-24 02:22:38 -08002967
Alexander Duyck952f72a2009-10-27 15:51:07 +00002968 /* disable queue 0 to prevent tail write w/o re-config */
2969 wr32(E1000_RXDCTL(0), 0);
Auke Kok9d5c8242008-01-24 02:22:38 -08002970
Alexander Duycke1739522009-02-19 20:39:44 -08002971 /* Attention!!! For SR-IOV PF driver operations you must enable
2972 * queue drop for all VF and PF queues to prevent head of line blocking
2973 * if an un-trusted VF does not provide descriptors to hardware.
2974 */
2975 if (adapter->vfs_allocated_count) {
Alexander Duycke1739522009-02-19 20:39:44 -08002976 /* set all queue drop enable bits */
2977 wr32(E1000_QDE, ALL_QUEUES);
Alexander Duycke1739522009-02-19 20:39:44 -08002978 }
2979
Ben Greear89eaefb2012-03-06 09:41:58 +00002980 /* This is useful for sniffing bad packets. */
2981 if (adapter->netdev->features & NETIF_F_RXALL) {
2982 /* UPE and MPE will be handled by normal PROMISC logic
2983 * in e1000e_set_rx_mode */
2984 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
2985 E1000_RCTL_BAM | /* RX All Bcast Pkts */
2986 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
2987
2988 rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
2989 E1000_RCTL_DPF | /* Allow filtered pause */
2990 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
2991 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
2992 * and that breaks VLANs.
2993 */
2994 }
2995
Auke Kok9d5c8242008-01-24 02:22:38 -08002996 wr32(E1000_RCTL, rctl);
2997}
2998
Alexander Duyck7d5753f2009-10-27 23:47:16 +00002999static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
3000 int vfn)
3001{
3002 struct e1000_hw *hw = &adapter->hw;
3003 u32 vmolr;
3004
3005 /* if it isn't the PF check to see if VFs are enabled and
3006 * increase the size to support vlan tags */
3007 if (vfn < adapter->vfs_allocated_count &&
3008 adapter->vf_data[vfn].vlans_enabled)
3009 size += VLAN_TAG_SIZE;
3010
3011 vmolr = rd32(E1000_VMOLR(vfn));
3012 vmolr &= ~E1000_VMOLR_RLPML_MASK;
3013 vmolr |= size | E1000_VMOLR_LPE;
3014 wr32(E1000_VMOLR(vfn), vmolr);
3015
3016 return 0;
3017}
3018
Auke Kok9d5c8242008-01-24 02:22:38 -08003019/**
Alexander Duycke1739522009-02-19 20:39:44 -08003020 * igb_rlpml_set - set maximum receive packet size
3021 * @adapter: board private structure
3022 *
3023 * Configure maximum receivable packet size.
3024 **/
3025static void igb_rlpml_set(struct igb_adapter *adapter)
3026{
Alexander Duyck153285f2011-08-26 07:43:32 +00003027 u32 max_frame_size = adapter->max_frame_size;
Alexander Duycke1739522009-02-19 20:39:44 -08003028 struct e1000_hw *hw = &adapter->hw;
3029 u16 pf_id = adapter->vfs_allocated_count;
3030
Alexander Duycke1739522009-02-19 20:39:44 -08003031 if (pf_id) {
3032 igb_set_vf_rlpml(adapter, max_frame_size, pf_id);
Alexander Duyck153285f2011-08-26 07:43:32 +00003033 /*
3034 * If we're in VMDQ or SR-IOV mode, then set global RLPML
3035 * to our max jumbo frame size, in case we need to enable
3036 * jumbo frames on one of the rings later.
3037 * This will not pass over-length frames into the default
3038 * queue because it's gated by the VMOLR.RLPML.
3039 */
Alexander Duyck7d5753f2009-10-27 23:47:16 +00003040 max_frame_size = MAX_JUMBO_FRAME_SIZE;
Alexander Duycke1739522009-02-19 20:39:44 -08003041 }
3042
3043 wr32(E1000_RLPML, max_frame_size);
3044}
3045
Williams, Mitch A8151d292010-02-10 01:44:24 +00003046static inline void igb_set_vmolr(struct igb_adapter *adapter,
3047 int vfn, bool aupe)
Alexander Duyck7d5753f2009-10-27 23:47:16 +00003048{
3049 struct e1000_hw *hw = &adapter->hw;
3050 u32 vmolr;
3051
3052 /*
3053 * This register exists only on 82576 and newer so if we are older then
3054 * we should exit and do nothing
3055 */
3056 if (hw->mac.type < e1000_82576)
3057 return;
3058
3059 vmolr = rd32(E1000_VMOLR(vfn));
Williams, Mitch A8151d292010-02-10 01:44:24 +00003060 vmolr |= E1000_VMOLR_STRVLAN; /* Strip vlan tags */
3061 if (aupe)
3062 vmolr |= E1000_VMOLR_AUPE; /* Accept untagged packets */
3063 else
3064 vmolr &= ~(E1000_VMOLR_AUPE); /* Tagged packets ONLY */
Alexander Duyck7d5753f2009-10-27 23:47:16 +00003065
3066 /* clear all bits that might not be set */
3067 vmolr &= ~(E1000_VMOLR_BAM | E1000_VMOLR_RSSE);
3068
Alexander Duycka99955f2009-11-12 18:37:19 +00003069 if (adapter->rss_queues > 1 && vfn == adapter->vfs_allocated_count)
Alexander Duyck7d5753f2009-10-27 23:47:16 +00003070 vmolr |= E1000_VMOLR_RSSE; /* enable RSS */
3071 /*
3072 * for VMDq only allow the VFs and pool 0 to accept broadcast and
3073 * multicast packets
3074 */
3075 if (vfn <= adapter->vfs_allocated_count)
3076 vmolr |= E1000_VMOLR_BAM; /* Accept broadcast */
3077
3078 wr32(E1000_VMOLR(vfn), vmolr);
3079}
3080
Alexander Duycke1739522009-02-19 20:39:44 -08003081/**
Alexander Duyck85b430b2009-10-27 15:50:29 +00003082 * igb_configure_rx_ring - Configure a receive ring after Reset
3083 * @adapter: board private structure
3084 * @ring: receive ring to be configured
3085 *
3086 * Configure the Rx unit of the MAC after a reset.
3087 **/
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00003088void igb_configure_rx_ring(struct igb_adapter *adapter,
3089 struct igb_ring *ring)
Alexander Duyck85b430b2009-10-27 15:50:29 +00003090{
3091 struct e1000_hw *hw = &adapter->hw;
3092 u64 rdba = ring->dma;
3093 int reg_idx = ring->reg_idx;
Alexander Duycka74420e2011-08-26 07:43:27 +00003094 u32 srrctl = 0, rxdctl = 0;
Alexander Duyck85b430b2009-10-27 15:50:29 +00003095
3096 /* disable the queue */
Alexander Duycka74420e2011-08-26 07:43:27 +00003097 wr32(E1000_RXDCTL(reg_idx), 0);
Alexander Duyck85b430b2009-10-27 15:50:29 +00003098
3099 /* Set DMA base address registers */
3100 wr32(E1000_RDBAL(reg_idx),
3101 rdba & 0x00000000ffffffffULL);
3102 wr32(E1000_RDBAH(reg_idx), rdba >> 32);
3103 wr32(E1000_RDLEN(reg_idx),
3104 ring->count * sizeof(union e1000_adv_rx_desc));
3105
3106 /* initialize head and tail */
Alexander Duyckfce99e32009-10-27 15:51:27 +00003107 ring->tail = hw->hw_addr + E1000_RDT(reg_idx);
Alexander Duycka74420e2011-08-26 07:43:27 +00003108 wr32(E1000_RDH(reg_idx), 0);
Alexander Duyckfce99e32009-10-27 15:51:27 +00003109 writel(0, ring->tail);
Alexander Duyck85b430b2009-10-27 15:50:29 +00003110
Alexander Duyck952f72a2009-10-27 15:51:07 +00003111 /* set descriptor configuration */
Alexander Duyck44390ca2011-08-26 07:43:38 +00003112 srrctl = IGB_RX_HDR_LEN << E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
Alexander Duyckde78d1f2012-09-25 00:31:12 +00003113 srrctl |= IGB_RX_BUFSZ >> E1000_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck1a1c2252012-09-25 00:30:52 +00003114 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
Alexander Duyck06218a82011-08-26 07:46:55 +00003115 if (hw->mac.type >= e1000_82580)
Nick Nunley757b77e2010-03-26 11:36:47 +00003116 srrctl |= E1000_SRRCTL_TIMESTAMP;
Nick Nunleye6bdb6f2010-02-17 01:03:38 +00003117 /* Only set Drop Enable if we are supporting multiple queues */
3118 if (adapter->vfs_allocated_count || adapter->num_rx_queues > 1)
3119 srrctl |= E1000_SRRCTL_DROP_EN;
Alexander Duyck952f72a2009-10-27 15:51:07 +00003120
3121 wr32(E1000_SRRCTL(reg_idx), srrctl);
3122
Alexander Duyck7d5753f2009-10-27 23:47:16 +00003123 /* set filtering for VMDQ pools */
Williams, Mitch A8151d292010-02-10 01:44:24 +00003124 igb_set_vmolr(adapter, reg_idx & 0x7, true);
Alexander Duyck7d5753f2009-10-27 23:47:16 +00003125
Alexander Duyck85b430b2009-10-27 15:50:29 +00003126 rxdctl |= IGB_RX_PTHRESH;
3127 rxdctl |= IGB_RX_HTHRESH << 8;
3128 rxdctl |= IGB_RX_WTHRESH << 16;
Alexander Duycka74420e2011-08-26 07:43:27 +00003129
3130 /* enable receive descriptor fetching */
3131 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
Alexander Duyck85b430b2009-10-27 15:50:29 +00003132 wr32(E1000_RXDCTL(reg_idx), rxdctl);
3133}
3134
3135/**
Auke Kok9d5c8242008-01-24 02:22:38 -08003136 * igb_configure_rx - Configure receive Unit after Reset
3137 * @adapter: board private structure
3138 *
3139 * Configure the Rx unit of the MAC after a reset.
3140 **/
3141static void igb_configure_rx(struct igb_adapter *adapter)
3142{
Hannes Eder91075842009-02-18 19:36:04 -08003143 int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08003144
Alexander Duyck68d480c2009-10-05 06:33:08 +00003145 /* set UTA to appropriate mode */
3146 igb_set_uta(adapter);
3147
Alexander Duyck26ad9172009-10-05 06:32:49 +00003148 /* set the correct pool for the PF default MAC address in entry 0 */
3149 igb_rar_set_qsel(adapter, adapter->hw.mac.addr, 0,
3150 adapter->vfs_allocated_count);
3151
Alexander Duyck06cf2662009-10-27 15:53:25 +00003152 /* Setup the HW Rx Head and Tail Descriptor Pointers and
3153 * the Base and Length of the Rx Descriptor Ring */
3154 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +00003155 igb_configure_rx_ring(adapter, adapter->rx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08003156}
3157
3158/**
3159 * igb_free_tx_resources - Free Tx Resources per Queue
Auke Kok9d5c8242008-01-24 02:22:38 -08003160 * @tx_ring: Tx descriptor ring for a specific queue
3161 *
3162 * Free all transmit software resources
3163 **/
Alexander Duyck68fd9912008-11-20 00:48:10 -08003164void igb_free_tx_resources(struct igb_ring *tx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08003165{
Mitch Williams3b644cf2008-06-27 10:59:48 -07003166 igb_clean_tx_ring(tx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08003167
Alexander Duyck06034642011-08-26 07:44:22 +00003168 vfree(tx_ring->tx_buffer_info);
3169 tx_ring->tx_buffer_info = NULL;
Auke Kok9d5c8242008-01-24 02:22:38 -08003170
Alexander Duyck439705e2009-10-27 23:49:20 +00003171 /* if not set, then don't free */
3172 if (!tx_ring->desc)
3173 return;
3174
Alexander Duyck59d71982010-04-27 13:09:25 +00003175 dma_free_coherent(tx_ring->dev, tx_ring->size,
3176 tx_ring->desc, tx_ring->dma);
Auke Kok9d5c8242008-01-24 02:22:38 -08003177
3178 tx_ring->desc = NULL;
3179}
3180
3181/**
3182 * igb_free_all_tx_resources - Free Tx Resources for All Queues
3183 * @adapter: board private structure
3184 *
3185 * Free all transmit software resources
3186 **/
3187static void igb_free_all_tx_resources(struct igb_adapter *adapter)
3188{
3189 int i;
3190
3191 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +00003192 igb_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08003193}
3194
Alexander Duyckebe42d12011-08-26 07:45:09 +00003195void igb_unmap_and_free_tx_resource(struct igb_ring *ring,
3196 struct igb_tx_buffer *tx_buffer)
Auke Kok9d5c8242008-01-24 02:22:38 -08003197{
Alexander Duyckebe42d12011-08-26 07:45:09 +00003198 if (tx_buffer->skb) {
3199 dev_kfree_skb_any(tx_buffer->skb);
Alexander Duyckc9f14bf32012-09-18 01:56:27 +00003200 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckebe42d12011-08-26 07:45:09 +00003201 dma_unmap_single(ring->dev,
Alexander Duyckc9f14bf32012-09-18 01:56:27 +00003202 dma_unmap_addr(tx_buffer, dma),
3203 dma_unmap_len(tx_buffer, len),
Alexander Duyckebe42d12011-08-26 07:45:09 +00003204 DMA_TO_DEVICE);
Alexander Duyckc9f14bf32012-09-18 01:56:27 +00003205 } else if (dma_unmap_len(tx_buffer, len)) {
Alexander Duyckebe42d12011-08-26 07:45:09 +00003206 dma_unmap_page(ring->dev,
Alexander Duyckc9f14bf32012-09-18 01:56:27 +00003207 dma_unmap_addr(tx_buffer, dma),
3208 dma_unmap_len(tx_buffer, len),
Alexander Duyckebe42d12011-08-26 07:45:09 +00003209 DMA_TO_DEVICE);
Alexander Duyck6366ad32009-12-02 16:47:18 +00003210 }
Alexander Duyckebe42d12011-08-26 07:45:09 +00003211 tx_buffer->next_to_watch = NULL;
3212 tx_buffer->skb = NULL;
Alexander Duyckc9f14bf32012-09-18 01:56:27 +00003213 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckebe42d12011-08-26 07:45:09 +00003214 /* buffer_info must be completely set up in the transmit path */
Auke Kok9d5c8242008-01-24 02:22:38 -08003215}
3216
3217/**
3218 * igb_clean_tx_ring - Free Tx Buffers
Auke Kok9d5c8242008-01-24 02:22:38 -08003219 * @tx_ring: ring to be cleaned
3220 **/
Mitch Williams3b644cf2008-06-27 10:59:48 -07003221static void igb_clean_tx_ring(struct igb_ring *tx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08003222{
Alexander Duyck06034642011-08-26 07:44:22 +00003223 struct igb_tx_buffer *buffer_info;
Auke Kok9d5c8242008-01-24 02:22:38 -08003224 unsigned long size;
Alexander Duyck6ad4edf2011-08-26 07:45:26 +00003225 u16 i;
Auke Kok9d5c8242008-01-24 02:22:38 -08003226
Alexander Duyck06034642011-08-26 07:44:22 +00003227 if (!tx_ring->tx_buffer_info)
Auke Kok9d5c8242008-01-24 02:22:38 -08003228 return;
3229 /* Free all the Tx ring sk_buffs */
3230
3231 for (i = 0; i < tx_ring->count; i++) {
Alexander Duyck06034642011-08-26 07:44:22 +00003232 buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck80785292009-10-27 15:51:47 +00003233 igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
Auke Kok9d5c8242008-01-24 02:22:38 -08003234 }
3235
John Fastabenddad8a3b2012-04-23 12:22:39 +00003236 netdev_tx_reset_queue(txring_txq(tx_ring));
3237
Alexander Duyck06034642011-08-26 07:44:22 +00003238 size = sizeof(struct igb_tx_buffer) * tx_ring->count;
3239 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9d5c8242008-01-24 02:22:38 -08003240
3241 /* Zero out the descriptor ring */
Auke Kok9d5c8242008-01-24 02:22:38 -08003242 memset(tx_ring->desc, 0, tx_ring->size);
3243
3244 tx_ring->next_to_use = 0;
3245 tx_ring->next_to_clean = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08003246}
3247
3248/**
3249 * igb_clean_all_tx_rings - Free Tx Buffers for all queues
3250 * @adapter: board private structure
3251 **/
3252static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
3253{
3254 int i;
3255
3256 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +00003257 igb_clean_tx_ring(adapter->tx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08003258}
3259
3260/**
3261 * igb_free_rx_resources - Free Rx Resources
Auke Kok9d5c8242008-01-24 02:22:38 -08003262 * @rx_ring: ring to clean the resources from
3263 *
3264 * Free all receive software resources
3265 **/
Alexander Duyck68fd9912008-11-20 00:48:10 -08003266void igb_free_rx_resources(struct igb_ring *rx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08003267{
Mitch Williams3b644cf2008-06-27 10:59:48 -07003268 igb_clean_rx_ring(rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08003269
Alexander Duyck06034642011-08-26 07:44:22 +00003270 vfree(rx_ring->rx_buffer_info);
3271 rx_ring->rx_buffer_info = NULL;
Auke Kok9d5c8242008-01-24 02:22:38 -08003272
Alexander Duyck439705e2009-10-27 23:49:20 +00003273 /* if not set, then don't free */
3274 if (!rx_ring->desc)
3275 return;
3276
Alexander Duyck59d71982010-04-27 13:09:25 +00003277 dma_free_coherent(rx_ring->dev, rx_ring->size,
3278 rx_ring->desc, rx_ring->dma);
Auke Kok9d5c8242008-01-24 02:22:38 -08003279
3280 rx_ring->desc = NULL;
3281}
3282
3283/**
3284 * igb_free_all_rx_resources - Free Rx Resources for All Queues
3285 * @adapter: board private structure
3286 *
3287 * Free all receive software resources
3288 **/
3289static void igb_free_all_rx_resources(struct igb_adapter *adapter)
3290{
3291 int i;
3292
3293 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +00003294 igb_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08003295}
3296
3297/**
3298 * igb_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9d5c8242008-01-24 02:22:38 -08003299 * @rx_ring: ring to free buffers from
3300 **/
Mitch Williams3b644cf2008-06-27 10:59:48 -07003301static void igb_clean_rx_ring(struct igb_ring *rx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08003302{
Auke Kok9d5c8242008-01-24 02:22:38 -08003303 unsigned long size;
Alexander Duyckc023cd82011-08-26 07:43:43 +00003304 u16 i;
Auke Kok9d5c8242008-01-24 02:22:38 -08003305
Alexander Duyck1a1c2252012-09-25 00:30:52 +00003306 if (rx_ring->skb)
3307 dev_kfree_skb(rx_ring->skb);
3308 rx_ring->skb = NULL;
3309
Alexander Duyck06034642011-08-26 07:44:22 +00003310 if (!rx_ring->rx_buffer_info)
Auke Kok9d5c8242008-01-24 02:22:38 -08003311 return;
Alexander Duyck439705e2009-10-27 23:49:20 +00003312
Auke Kok9d5c8242008-01-24 02:22:38 -08003313 /* Free all the Rx ring sk_buffs */
3314 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyck06034642011-08-26 07:44:22 +00003315 struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9d5c8242008-01-24 02:22:38 -08003316
Alexander Duyckcbc8e552012-09-25 00:31:02 +00003317 if (!buffer_info->page)
3318 continue;
3319
3320 dma_unmap_page(rx_ring->dev,
3321 buffer_info->dma,
3322 PAGE_SIZE,
3323 DMA_FROM_DEVICE);
3324 __free_page(buffer_info->page);
3325
Alexander Duyck1a1c2252012-09-25 00:30:52 +00003326 buffer_info->page = NULL;
Auke Kok9d5c8242008-01-24 02:22:38 -08003327 }
3328
Alexander Duyck06034642011-08-26 07:44:22 +00003329 size = sizeof(struct igb_rx_buffer) * rx_ring->count;
3330 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9d5c8242008-01-24 02:22:38 -08003331
3332 /* Zero out the descriptor ring */
3333 memset(rx_ring->desc, 0, rx_ring->size);
3334
Alexander Duyckcbc8e552012-09-25 00:31:02 +00003335 rx_ring->next_to_alloc = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08003336 rx_ring->next_to_clean = 0;
3337 rx_ring->next_to_use = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08003338}
3339
3340/**
3341 * igb_clean_all_rx_rings - Free Rx Buffers for all queues
3342 * @adapter: board private structure
3343 **/
3344static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
3345{
3346 int i;
3347
3348 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +00003349 igb_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08003350}
3351
3352/**
3353 * igb_set_mac - Change the Ethernet Address of the NIC
3354 * @netdev: network interface device structure
3355 * @p: pointer to an address structure
3356 *
3357 * Returns 0 on success, negative on failure
3358 **/
3359static int igb_set_mac(struct net_device *netdev, void *p)
3360{
3361 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28b07592009-02-06 23:20:31 +00003362 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08003363 struct sockaddr *addr = p;
3364
3365 if (!is_valid_ether_addr(addr->sa_data))
3366 return -EADDRNOTAVAIL;
3367
3368 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Alexander Duyck28b07592009-02-06 23:20:31 +00003369 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9d5c8242008-01-24 02:22:38 -08003370
Alexander Duyck26ad9172009-10-05 06:32:49 +00003371 /* set the correct pool for the new PF MAC address in entry 0 */
3372 igb_rar_set_qsel(adapter, hw->mac.addr, 0,
3373 adapter->vfs_allocated_count);
Alexander Duycke1739522009-02-19 20:39:44 -08003374
Auke Kok9d5c8242008-01-24 02:22:38 -08003375 return 0;
3376}
3377
3378/**
Alexander Duyck68d480c2009-10-05 06:33:08 +00003379 * igb_write_mc_addr_list - write multicast addresses to MTA
3380 * @netdev: network interface device structure
3381 *
3382 * Writes multicast address list to the MTA hash table.
3383 * Returns: -ENOMEM on failure
3384 * 0 on no addresses written
3385 * X on writing X addresses to MTA
3386 **/
3387static int igb_write_mc_addr_list(struct net_device *netdev)
3388{
3389 struct igb_adapter *adapter = netdev_priv(netdev);
3390 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003391 struct netdev_hw_addr *ha;
Alexander Duyck68d480c2009-10-05 06:33:08 +00003392 u8 *mta_list;
Alexander Duyck68d480c2009-10-05 06:33:08 +00003393 int i;
3394
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00003395 if (netdev_mc_empty(netdev)) {
Alexander Duyck68d480c2009-10-05 06:33:08 +00003396 /* nothing to program, so clear mc list */
3397 igb_update_mc_addr_list(hw, NULL, 0);
3398 igb_restore_vf_multicasts(adapter);
3399 return 0;
3400 }
3401
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00003402 mta_list = kzalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
Alexander Duyck68d480c2009-10-05 06:33:08 +00003403 if (!mta_list)
3404 return -ENOMEM;
3405
Alexander Duyck68d480c2009-10-05 06:33:08 +00003406 /* The shared function expects a packed array of only addresses. */
Jiri Pirko48e2f182010-02-22 09:22:26 +00003407 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003408 netdev_for_each_mc_addr(ha, netdev)
3409 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Alexander Duyck68d480c2009-10-05 06:33:08 +00003410
Alexander Duyck68d480c2009-10-05 06:33:08 +00003411 igb_update_mc_addr_list(hw, mta_list, i);
3412 kfree(mta_list);
3413
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00003414 return netdev_mc_count(netdev);
Alexander Duyck68d480c2009-10-05 06:33:08 +00003415}
3416
3417/**
3418 * igb_write_uc_addr_list - write unicast addresses to RAR table
3419 * @netdev: network interface device structure
3420 *
3421 * Writes unicast address list to the RAR table.
3422 * Returns: -ENOMEM on failure/insufficient address space
3423 * 0 on no addresses written
3424 * X on writing X addresses to the RAR table
3425 **/
3426static int igb_write_uc_addr_list(struct net_device *netdev)
3427{
3428 struct igb_adapter *adapter = netdev_priv(netdev);
3429 struct e1000_hw *hw = &adapter->hw;
3430 unsigned int vfn = adapter->vfs_allocated_count;
3431 unsigned int rar_entries = hw->mac.rar_entry_count - (vfn + 1);
3432 int count = 0;
3433
3434 /* return ENOMEM indicating insufficient memory for addresses */
Jiri Pirko32e7bfc2010-01-25 13:36:10 -08003435 if (netdev_uc_count(netdev) > rar_entries)
Alexander Duyck68d480c2009-10-05 06:33:08 +00003436 return -ENOMEM;
3437
Jiri Pirko32e7bfc2010-01-25 13:36:10 -08003438 if (!netdev_uc_empty(netdev) && rar_entries) {
Alexander Duyck68d480c2009-10-05 06:33:08 +00003439 struct netdev_hw_addr *ha;
Jiri Pirko32e7bfc2010-01-25 13:36:10 -08003440
3441 netdev_for_each_uc_addr(ha, netdev) {
Alexander Duyck68d480c2009-10-05 06:33:08 +00003442 if (!rar_entries)
3443 break;
3444 igb_rar_set_qsel(adapter, ha->addr,
3445 rar_entries--,
3446 vfn);
3447 count++;
3448 }
3449 }
3450 /* write the addresses in reverse order to avoid write combining */
3451 for (; rar_entries > 0 ; rar_entries--) {
3452 wr32(E1000_RAH(rar_entries), 0);
3453 wr32(E1000_RAL(rar_entries), 0);
3454 }
3455 wrfl();
3456
3457 return count;
3458}
3459
3460/**
Alexander Duyckff41f8d2009-09-03 14:48:56 +00003461 * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
Auke Kok9d5c8242008-01-24 02:22:38 -08003462 * @netdev: network interface device structure
3463 *
Alexander Duyckff41f8d2009-09-03 14:48:56 +00003464 * The set_rx_mode entry point is called whenever the unicast or multicast
3465 * address lists or the network interface flags are updated. This routine is
3466 * responsible for configuring the hardware for proper unicast, multicast,
Auke Kok9d5c8242008-01-24 02:22:38 -08003467 * promiscuous mode, and all-multi behavior.
3468 **/
Alexander Duyckff41f8d2009-09-03 14:48:56 +00003469static void igb_set_rx_mode(struct net_device *netdev)
Auke Kok9d5c8242008-01-24 02:22:38 -08003470{
3471 struct igb_adapter *adapter = netdev_priv(netdev);
3472 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck68d480c2009-10-05 06:33:08 +00003473 unsigned int vfn = adapter->vfs_allocated_count;
3474 u32 rctl, vmolr = 0;
3475 int count;
Auke Kok9d5c8242008-01-24 02:22:38 -08003476
3477 /* Check for Promiscuous and All Multicast modes */
Auke Kok9d5c8242008-01-24 02:22:38 -08003478 rctl = rd32(E1000_RCTL);
3479
Alexander Duyck68d480c2009-10-05 06:33:08 +00003480 /* clear the effected bits */
3481 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_VFE);
3482
Patrick McHardy746b9f02008-07-16 20:15:45 -07003483 if (netdev->flags & IFF_PROMISC) {
Auke Kok9d5c8242008-01-24 02:22:38 -08003484 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Alexander Duyck68d480c2009-10-05 06:33:08 +00003485 vmolr |= (E1000_VMOLR_ROPE | E1000_VMOLR_MPME);
Patrick McHardy746b9f02008-07-16 20:15:45 -07003486 } else {
Alexander Duyck68d480c2009-10-05 06:33:08 +00003487 if (netdev->flags & IFF_ALLMULTI) {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003488 rctl |= E1000_RCTL_MPE;
Alexander Duyck68d480c2009-10-05 06:33:08 +00003489 vmolr |= E1000_VMOLR_MPME;
3490 } else {
3491 /*
3492 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003493 * then we should just turn on promiscuous mode so
Alexander Duyck68d480c2009-10-05 06:33:08 +00003494 * that we can at least receive multicast traffic
3495 */
3496 count = igb_write_mc_addr_list(netdev);
3497 if (count < 0) {
3498 rctl |= E1000_RCTL_MPE;
3499 vmolr |= E1000_VMOLR_MPME;
3500 } else if (count) {
3501 vmolr |= E1000_VMOLR_ROMPE;
3502 }
3503 }
3504 /*
3505 * Write addresses to available RAR registers, if there is not
3506 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003507 * unicast promiscuous mode
Alexander Duyck68d480c2009-10-05 06:33:08 +00003508 */
3509 count = igb_write_uc_addr_list(netdev);
3510 if (count < 0) {
Alexander Duyckff41f8d2009-09-03 14:48:56 +00003511 rctl |= E1000_RCTL_UPE;
Alexander Duyck68d480c2009-10-05 06:33:08 +00003512 vmolr |= E1000_VMOLR_ROPE;
3513 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07003514 rctl |= E1000_RCTL_VFE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003515 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003516 wr32(E1000_RCTL, rctl);
3517
Alexander Duyck68d480c2009-10-05 06:33:08 +00003518 /*
3519 * In order to support SR-IOV and eventually VMDq it is necessary to set
3520 * the VMOLR to enable the appropriate modes. Without this workaround
3521 * we will have issues with VLAN tag stripping not being done for frames
3522 * that are only arriving because we are the default pool
3523 */
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00003524 if ((hw->mac.type < e1000_82576) || (hw->mac.type > e1000_i350))
Alexander Duyck28fc06f2009-07-23 18:08:54 +00003525 return;
Alexander Duyck28fc06f2009-07-23 18:08:54 +00003526
Alexander Duyck68d480c2009-10-05 06:33:08 +00003527 vmolr |= rd32(E1000_VMOLR(vfn)) &
3528 ~(E1000_VMOLR_ROPE | E1000_VMOLR_MPME | E1000_VMOLR_ROMPE);
3529 wr32(E1000_VMOLR(vfn), vmolr);
Alexander Duyck28fc06f2009-07-23 18:08:54 +00003530 igb_restore_vf_multicasts(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08003531}
3532
Greg Rose13800462010-11-06 02:08:26 +00003533static void igb_check_wvbr(struct igb_adapter *adapter)
3534{
3535 struct e1000_hw *hw = &adapter->hw;
3536 u32 wvbr = 0;
3537
3538 switch (hw->mac.type) {
3539 case e1000_82576:
3540 case e1000_i350:
3541 if (!(wvbr = rd32(E1000_WVBR)))
3542 return;
3543 break;
3544 default:
3545 break;
3546 }
3547
3548 adapter->wvbr |= wvbr;
3549}
3550
3551#define IGB_STAGGERED_QUEUE_OFFSET 8
3552
3553static void igb_spoof_check(struct igb_adapter *adapter)
3554{
3555 int j;
3556
3557 if (!adapter->wvbr)
3558 return;
3559
3560 for(j = 0; j < adapter->vfs_allocated_count; j++) {
3561 if (adapter->wvbr & (1 << j) ||
3562 adapter->wvbr & (1 << (j + IGB_STAGGERED_QUEUE_OFFSET))) {
3563 dev_warn(&adapter->pdev->dev,
3564 "Spoof event(s) detected on VF %d\n", j);
3565 adapter->wvbr &=
3566 ~((1 << j) |
3567 (1 << (j + IGB_STAGGERED_QUEUE_OFFSET)));
3568 }
3569 }
3570}
3571
Auke Kok9d5c8242008-01-24 02:22:38 -08003572/* Need to wait a few seconds after link up to get diagnostic information from
3573 * the phy */
3574static void igb_update_phy_info(unsigned long data)
3575{
3576 struct igb_adapter *adapter = (struct igb_adapter *) data;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08003577 igb_get_phy_info(&adapter->hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08003578}
3579
3580/**
Alexander Duyck4d6b7252009-02-06 23:16:24 +00003581 * igb_has_link - check shared code for link and determine up/down
3582 * @adapter: pointer to driver private info
3583 **/
Nick Nunley31455352010-02-17 01:01:21 +00003584bool igb_has_link(struct igb_adapter *adapter)
Alexander Duyck4d6b7252009-02-06 23:16:24 +00003585{
3586 struct e1000_hw *hw = &adapter->hw;
3587 bool link_active = false;
3588 s32 ret_val = 0;
3589
3590 /* get_link_status is set on LSC (link status) interrupt or
3591 * rx sequence error interrupt. get_link_status will stay
3592 * false until the e1000_check_for_link establishes link
3593 * for copper adapters ONLY
3594 */
3595 switch (hw->phy.media_type) {
3596 case e1000_media_type_copper:
3597 if (hw->mac.get_link_status) {
3598 ret_val = hw->mac.ops.check_for_link(hw);
3599 link_active = !hw->mac.get_link_status;
3600 } else {
3601 link_active = true;
3602 }
3603 break;
Alexander Duyck4d6b7252009-02-06 23:16:24 +00003604 case e1000_media_type_internal_serdes:
3605 ret_val = hw->mac.ops.check_for_link(hw);
3606 link_active = hw->mac.serdes_has_link;
3607 break;
3608 default:
3609 case e1000_media_type_unknown:
3610 break;
3611 }
3612
3613 return link_active;
3614}
3615
Stefan Assmann563988d2011-04-05 04:27:15 +00003616static bool igb_thermal_sensor_event(struct e1000_hw *hw, u32 event)
3617{
3618 bool ret = false;
3619 u32 ctrl_ext, thstat;
3620
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00003621 /* check for thermal sensor event on i350 copper only */
Stefan Assmann563988d2011-04-05 04:27:15 +00003622 if (hw->mac.type == e1000_i350) {
3623 thstat = rd32(E1000_THSTAT);
3624 ctrl_ext = rd32(E1000_CTRL_EXT);
3625
3626 if ((hw->phy.media_type == e1000_media_type_copper) &&
3627 !(ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII)) {
3628 ret = !!(thstat & event);
3629 }
3630 }
3631
3632 return ret;
3633}
3634
Alexander Duyck4d6b7252009-02-06 23:16:24 +00003635/**
Auke Kok9d5c8242008-01-24 02:22:38 -08003636 * igb_watchdog - Timer Call-back
3637 * @data: pointer to adapter cast into an unsigned long
3638 **/
3639static void igb_watchdog(unsigned long data)
3640{
3641 struct igb_adapter *adapter = (struct igb_adapter *)data;
3642 /* Do the rest outside of interrupt context */
3643 schedule_work(&adapter->watchdog_task);
3644}
3645
3646static void igb_watchdog_task(struct work_struct *work)
3647{
3648 struct igb_adapter *adapter = container_of(work,
Alexander Duyck559e9c42009-10-27 23:52:50 +00003649 struct igb_adapter,
3650 watchdog_task);
Auke Kok9d5c8242008-01-24 02:22:38 -08003651 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08003652 struct net_device *netdev = adapter->netdev;
Stefan Assmann563988d2011-04-05 04:27:15 +00003653 u32 link;
Alexander Duyck7a6ea552008-08-26 04:25:03 -07003654 int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08003655
Alexander Duyck4d6b7252009-02-06 23:16:24 +00003656 link = igb_has_link(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08003657 if (link) {
Yan, Zheng749ab2c2012-01-04 20:23:37 +00003658 /* Cancel scheduled suspend requests. */
3659 pm_runtime_resume(netdev->dev.parent);
3660
Auke Kok9d5c8242008-01-24 02:22:38 -08003661 if (!netif_carrier_ok(netdev)) {
3662 u32 ctrl;
Alexander Duyck330a6d62009-10-27 23:51:35 +00003663 hw->mac.ops.get_speed_and_duplex(hw,
3664 &adapter->link_speed,
3665 &adapter->link_duplex);
Auke Kok9d5c8242008-01-24 02:22:38 -08003666
3667 ctrl = rd32(E1000_CTRL);
Alexander Duyck527d47c2008-11-27 00:21:39 -08003668 /* Links status message must follow this format */
Jeff Kirsher876d2d62011-10-21 20:01:34 +00003669 printk(KERN_INFO "igb: %s NIC Link is Up %d Mbps %s "
3670 "Duplex, Flow Control: %s\n",
Alexander Duyck559e9c42009-10-27 23:52:50 +00003671 netdev->name,
3672 adapter->link_speed,
3673 adapter->link_duplex == FULL_DUPLEX ?
Jeff Kirsher876d2d62011-10-21 20:01:34 +00003674 "Full" : "Half",
3675 (ctrl & E1000_CTRL_TFCE) &&
3676 (ctrl & E1000_CTRL_RFCE) ? "RX/TX" :
3677 (ctrl & E1000_CTRL_RFCE) ? "RX" :
3678 (ctrl & E1000_CTRL_TFCE) ? "TX" : "None");
Auke Kok9d5c8242008-01-24 02:22:38 -08003679
Stefan Assmann563988d2011-04-05 04:27:15 +00003680 /* check for thermal sensor event */
Jeff Kirsher876d2d62011-10-21 20:01:34 +00003681 if (igb_thermal_sensor_event(hw,
3682 E1000_THSTAT_LINK_THROTTLE)) {
3683 netdev_info(netdev, "The network adapter link "
3684 "speed was downshifted because it "
3685 "overheated\n");
Carolyn Wyborny7ef5ed12011-03-12 08:59:47 +00003686 }
Stefan Assmann563988d2011-04-05 04:27:15 +00003687
Emil Tantilovd07f3e32010-03-23 18:34:57 +00003688 /* adjust timeout factor according to speed/duplex */
Auke Kok9d5c8242008-01-24 02:22:38 -08003689 adapter->tx_timeout_factor = 1;
3690 switch (adapter->link_speed) {
3691 case SPEED_10:
Auke Kok9d5c8242008-01-24 02:22:38 -08003692 adapter->tx_timeout_factor = 14;
3693 break;
3694 case SPEED_100:
Auke Kok9d5c8242008-01-24 02:22:38 -08003695 /* maybe add some timeout factor ? */
3696 break;
3697 }
3698
3699 netif_carrier_on(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08003700
Alexander Duyck4ae196d2009-02-19 20:40:07 -08003701 igb_ping_all_vfs(adapter);
Lior Levy17dc5662011-02-08 02:28:46 +00003702 igb_check_vf_rate_limit(adapter);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08003703
Alexander Duyck4b1a9872009-02-06 23:19:50 +00003704 /* link state has changed, schedule phy info update */
Auke Kok9d5c8242008-01-24 02:22:38 -08003705 if (!test_bit(__IGB_DOWN, &adapter->state))
3706 mod_timer(&adapter->phy_info_timer,
3707 round_jiffies(jiffies + 2 * HZ));
3708 }
3709 } else {
3710 if (netif_carrier_ok(netdev)) {
3711 adapter->link_speed = 0;
3712 adapter->link_duplex = 0;
Stefan Assmann563988d2011-04-05 04:27:15 +00003713
3714 /* check for thermal sensor event */
Jeff Kirsher876d2d62011-10-21 20:01:34 +00003715 if (igb_thermal_sensor_event(hw,
3716 E1000_THSTAT_PWR_DOWN)) {
3717 netdev_err(netdev, "The network adapter was "
3718 "stopped because it overheated\n");
Carolyn Wyborny7ef5ed12011-03-12 08:59:47 +00003719 }
Stefan Assmann563988d2011-04-05 04:27:15 +00003720
Alexander Duyck527d47c2008-11-27 00:21:39 -08003721 /* Links status message must follow this format */
3722 printk(KERN_INFO "igb: %s NIC Link is Down\n",
3723 netdev->name);
Auke Kok9d5c8242008-01-24 02:22:38 -08003724 netif_carrier_off(netdev);
Alexander Duyck4b1a9872009-02-06 23:19:50 +00003725
Alexander Duyck4ae196d2009-02-19 20:40:07 -08003726 igb_ping_all_vfs(adapter);
3727
Alexander Duyck4b1a9872009-02-06 23:19:50 +00003728 /* link state has changed, schedule phy info update */
Auke Kok9d5c8242008-01-24 02:22:38 -08003729 if (!test_bit(__IGB_DOWN, &adapter->state))
3730 mod_timer(&adapter->phy_info_timer,
3731 round_jiffies(jiffies + 2 * HZ));
Yan, Zheng749ab2c2012-01-04 20:23:37 +00003732
3733 pm_schedule_suspend(netdev->dev.parent,
3734 MSEC_PER_SEC * 5);
Auke Kok9d5c8242008-01-24 02:22:38 -08003735 }
3736 }
3737
Eric Dumazet12dcd862010-10-15 17:27:10 +00003738 spin_lock(&adapter->stats64_lock);
3739 igb_update_stats(adapter, &adapter->stats64);
3740 spin_unlock(&adapter->stats64_lock);
Auke Kok9d5c8242008-01-24 02:22:38 -08003741
Alexander Duyckdbabb062009-11-12 18:38:16 +00003742 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +00003743 struct igb_ring *tx_ring = adapter->tx_ring[i];
Alexander Duyckdbabb062009-11-12 18:38:16 +00003744 if (!netif_carrier_ok(netdev)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08003745 /* We've lost link, so the controller stops DMA,
3746 * but we've got queued Tx work that's never going
3747 * to get done, so reset controller to flush Tx.
3748 * (Do the reset outside of interrupt context). */
Alexander Duyckdbabb062009-11-12 18:38:16 +00003749 if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) {
3750 adapter->tx_timeout_count++;
3751 schedule_work(&adapter->reset_task);
3752 /* return immediately since reset is imminent */
3753 return;
3754 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003755 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003756
Alexander Duyckdbabb062009-11-12 18:38:16 +00003757 /* Force detection of hung controller every watchdog period */
Alexander Duyck6d095fa2011-08-26 07:46:19 +00003758 set_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
Alexander Duyckdbabb062009-11-12 18:38:16 +00003759 }
Alexander Duyckf7ba2052009-10-27 23:48:51 +00003760
Auke Kok9d5c8242008-01-24 02:22:38 -08003761 /* Cause software interrupt to ensure rx ring is cleaned */
Alexander Duyck7a6ea552008-08-26 04:25:03 -07003762 if (adapter->msix_entries) {
Alexander Duyck047e0032009-10-27 15:49:27 +00003763 u32 eics = 0;
Alexander Duyck0d1ae7f2011-08-26 07:46:34 +00003764 for (i = 0; i < adapter->num_q_vectors; i++)
3765 eics |= adapter->q_vector[i]->eims_value;
Alexander Duyck7a6ea552008-08-26 04:25:03 -07003766 wr32(E1000_EICS, eics);
3767 } else {
3768 wr32(E1000_ICS, E1000_ICS_RXDMT0);
3769 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003770
Greg Rose13800462010-11-06 02:08:26 +00003771 igb_spoof_check(adapter);
3772
Auke Kok9d5c8242008-01-24 02:22:38 -08003773 /* Reset the timer */
3774 if (!test_bit(__IGB_DOWN, &adapter->state))
3775 mod_timer(&adapter->watchdog_timer,
3776 round_jiffies(jiffies + 2 * HZ));
3777}
3778
3779enum latency_range {
3780 lowest_latency = 0,
3781 low_latency = 1,
3782 bulk_latency = 2,
3783 latency_invalid = 255
3784};
3785
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003786/**
3787 * igb_update_ring_itr - update the dynamic ITR value based on packet size
3788 *
3789 * Stores a new ITR value based on strictly on packet size. This
3790 * algorithm is less sophisticated than that used in igb_update_itr,
3791 * due to the difficulty of synchronizing statistics across multiple
Stefan Weileef35c22010-08-06 21:11:15 +02003792 * receive rings. The divisors and thresholds used by this function
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003793 * were determined based on theoretical maximum wire speed and testing
3794 * data, in order to minimize response time while increasing bulk
3795 * throughput.
3796 * This functionality is controlled by the InterruptThrottleRate module
3797 * parameter (see igb_param.c)
3798 * NOTE: This function is called only when operating in a multiqueue
3799 * receive environment.
Alexander Duyck047e0032009-10-27 15:49:27 +00003800 * @q_vector: pointer to q_vector
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003801 **/
Alexander Duyck047e0032009-10-27 15:49:27 +00003802static void igb_update_ring_itr(struct igb_q_vector *q_vector)
Auke Kok9d5c8242008-01-24 02:22:38 -08003803{
Alexander Duyck047e0032009-10-27 15:49:27 +00003804 int new_val = q_vector->itr_val;
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003805 int avg_wire_size = 0;
Alexander Duyck047e0032009-10-27 15:49:27 +00003806 struct igb_adapter *adapter = q_vector->adapter;
Eric Dumazet12dcd862010-10-15 17:27:10 +00003807 unsigned int packets;
Auke Kok9d5c8242008-01-24 02:22:38 -08003808
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003809 /* For non-gigabit speeds, just fix the interrupt rate at 4000
3810 * ints/sec - ITR timer value of 120 ticks.
3811 */
3812 if (adapter->link_speed != SPEED_1000) {
Alexander Duyck0ba82992011-08-26 07:45:47 +00003813 new_val = IGB_4K_ITR;
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003814 goto set_itr_val;
3815 }
Alexander Duyck047e0032009-10-27 15:49:27 +00003816
Alexander Duyck0ba82992011-08-26 07:45:47 +00003817 packets = q_vector->rx.total_packets;
3818 if (packets)
3819 avg_wire_size = q_vector->rx.total_bytes / packets;
Eric Dumazet12dcd862010-10-15 17:27:10 +00003820
Alexander Duyck0ba82992011-08-26 07:45:47 +00003821 packets = q_vector->tx.total_packets;
3822 if (packets)
3823 avg_wire_size = max_t(u32, avg_wire_size,
3824 q_vector->tx.total_bytes / packets);
Alexander Duyck047e0032009-10-27 15:49:27 +00003825
3826 /* if avg_wire_size isn't set no work was done */
3827 if (!avg_wire_size)
3828 goto clear_counts;
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003829
3830 /* Add 24 bytes to size to account for CRC, preamble, and gap */
3831 avg_wire_size += 24;
3832
3833 /* Don't starve jumbo frames */
3834 avg_wire_size = min(avg_wire_size, 3000);
3835
3836 /* Give a little boost to mid-size frames */
3837 if ((avg_wire_size > 300) && (avg_wire_size < 1200))
3838 new_val = avg_wire_size / 3;
3839 else
3840 new_val = avg_wire_size / 2;
3841
Alexander Duyck0ba82992011-08-26 07:45:47 +00003842 /* conservative mode (itr 3) eliminates the lowest_latency setting */
3843 if (new_val < IGB_20K_ITR &&
3844 ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
3845 (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
3846 new_val = IGB_20K_ITR;
Nick Nunleyabe1c362010-02-17 01:03:19 +00003847
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003848set_itr_val:
Alexander Duyck047e0032009-10-27 15:49:27 +00003849 if (new_val != q_vector->itr_val) {
3850 q_vector->itr_val = new_val;
3851 q_vector->set_itr = 1;
Auke Kok9d5c8242008-01-24 02:22:38 -08003852 }
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003853clear_counts:
Alexander Duyck0ba82992011-08-26 07:45:47 +00003854 q_vector->rx.total_bytes = 0;
3855 q_vector->rx.total_packets = 0;
3856 q_vector->tx.total_bytes = 0;
3857 q_vector->tx.total_packets = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08003858}
3859
3860/**
3861 * igb_update_itr - update the dynamic ITR value based on statistics
3862 * Stores a new ITR value based on packets and byte
3863 * counts during the last interrupt. The advantage of per interrupt
3864 * computation is faster updates and more accurate ITR for the current
3865 * traffic pattern. Constants in this function were computed
3866 * based on theoretical maximum wire speed and thresholds were set based
3867 * on testing data as well as attempting to minimize response time
3868 * while increasing bulk throughput.
3869 * this functionality is controlled by the InterruptThrottleRate module
3870 * parameter (see igb_param.c)
3871 * NOTE: These calculations are only valid when operating in a single-
3872 * queue environment.
Alexander Duyck0ba82992011-08-26 07:45:47 +00003873 * @q_vector: pointer to q_vector
3874 * @ring_container: ring info to update the itr for
Auke Kok9d5c8242008-01-24 02:22:38 -08003875 **/
Alexander Duyck0ba82992011-08-26 07:45:47 +00003876static void igb_update_itr(struct igb_q_vector *q_vector,
3877 struct igb_ring_container *ring_container)
Auke Kok9d5c8242008-01-24 02:22:38 -08003878{
Alexander Duyck0ba82992011-08-26 07:45:47 +00003879 unsigned int packets = ring_container->total_packets;
3880 unsigned int bytes = ring_container->total_bytes;
3881 u8 itrval = ring_container->itr;
Auke Kok9d5c8242008-01-24 02:22:38 -08003882
Alexander Duyck0ba82992011-08-26 07:45:47 +00003883 /* no packets, exit with status unchanged */
Auke Kok9d5c8242008-01-24 02:22:38 -08003884 if (packets == 0)
Alexander Duyck0ba82992011-08-26 07:45:47 +00003885 return;
Auke Kok9d5c8242008-01-24 02:22:38 -08003886
Alexander Duyck0ba82992011-08-26 07:45:47 +00003887 switch (itrval) {
Auke Kok9d5c8242008-01-24 02:22:38 -08003888 case lowest_latency:
3889 /* handle TSO and jumbo frames */
3890 if (bytes/packets > 8000)
Alexander Duyck0ba82992011-08-26 07:45:47 +00003891 itrval = bulk_latency;
Auke Kok9d5c8242008-01-24 02:22:38 -08003892 else if ((packets < 5) && (bytes > 512))
Alexander Duyck0ba82992011-08-26 07:45:47 +00003893 itrval = low_latency;
Auke Kok9d5c8242008-01-24 02:22:38 -08003894 break;
3895 case low_latency: /* 50 usec aka 20000 ints/s */
3896 if (bytes > 10000) {
3897 /* this if handles the TSO accounting */
3898 if (bytes/packets > 8000) {
Alexander Duyck0ba82992011-08-26 07:45:47 +00003899 itrval = bulk_latency;
Auke Kok9d5c8242008-01-24 02:22:38 -08003900 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
Alexander Duyck0ba82992011-08-26 07:45:47 +00003901 itrval = bulk_latency;
Auke Kok9d5c8242008-01-24 02:22:38 -08003902 } else if ((packets > 35)) {
Alexander Duyck0ba82992011-08-26 07:45:47 +00003903 itrval = lowest_latency;
Auke Kok9d5c8242008-01-24 02:22:38 -08003904 }
3905 } else if (bytes/packets > 2000) {
Alexander Duyck0ba82992011-08-26 07:45:47 +00003906 itrval = bulk_latency;
Auke Kok9d5c8242008-01-24 02:22:38 -08003907 } else if (packets <= 2 && bytes < 512) {
Alexander Duyck0ba82992011-08-26 07:45:47 +00003908 itrval = lowest_latency;
Auke Kok9d5c8242008-01-24 02:22:38 -08003909 }
3910 break;
3911 case bulk_latency: /* 250 usec aka 4000 ints/s */
3912 if (bytes > 25000) {
3913 if (packets > 35)
Alexander Duyck0ba82992011-08-26 07:45:47 +00003914 itrval = low_latency;
Alexander Duyck1e5c3d22009-02-12 18:17:21 +00003915 } else if (bytes < 1500) {
Alexander Duyck0ba82992011-08-26 07:45:47 +00003916 itrval = low_latency;
Auke Kok9d5c8242008-01-24 02:22:38 -08003917 }
3918 break;
3919 }
3920
Alexander Duyck0ba82992011-08-26 07:45:47 +00003921 /* clear work counters since we have the values we need */
3922 ring_container->total_bytes = 0;
3923 ring_container->total_packets = 0;
3924
3925 /* write updated itr to ring container */
3926 ring_container->itr = itrval;
Auke Kok9d5c8242008-01-24 02:22:38 -08003927}
3928
Alexander Duyck0ba82992011-08-26 07:45:47 +00003929static void igb_set_itr(struct igb_q_vector *q_vector)
Auke Kok9d5c8242008-01-24 02:22:38 -08003930{
Alexander Duyck0ba82992011-08-26 07:45:47 +00003931 struct igb_adapter *adapter = q_vector->adapter;
Alexander Duyck047e0032009-10-27 15:49:27 +00003932 u32 new_itr = q_vector->itr_val;
Alexander Duyck0ba82992011-08-26 07:45:47 +00003933 u8 current_itr = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08003934
3935 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
3936 if (adapter->link_speed != SPEED_1000) {
3937 current_itr = 0;
Alexander Duyck0ba82992011-08-26 07:45:47 +00003938 new_itr = IGB_4K_ITR;
Auke Kok9d5c8242008-01-24 02:22:38 -08003939 goto set_itr_now;
3940 }
3941
Alexander Duyck0ba82992011-08-26 07:45:47 +00003942 igb_update_itr(q_vector, &q_vector->tx);
3943 igb_update_itr(q_vector, &q_vector->rx);
Auke Kok9d5c8242008-01-24 02:22:38 -08003944
Alexander Duyck0ba82992011-08-26 07:45:47 +00003945 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Auke Kok9d5c8242008-01-24 02:22:38 -08003946
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003947 /* conservative mode (itr 3) eliminates the lowest_latency setting */
Alexander Duyck0ba82992011-08-26 07:45:47 +00003948 if (current_itr == lowest_latency &&
3949 ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
3950 (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003951 current_itr = low_latency;
3952
Auke Kok9d5c8242008-01-24 02:22:38 -08003953 switch (current_itr) {
3954 /* counts and packets in update_itr are dependent on these numbers */
3955 case lowest_latency:
Alexander Duyck0ba82992011-08-26 07:45:47 +00003956 new_itr = IGB_70K_ITR; /* 70,000 ints/sec */
Auke Kok9d5c8242008-01-24 02:22:38 -08003957 break;
3958 case low_latency:
Alexander Duyck0ba82992011-08-26 07:45:47 +00003959 new_itr = IGB_20K_ITR; /* 20,000 ints/sec */
Auke Kok9d5c8242008-01-24 02:22:38 -08003960 break;
3961 case bulk_latency:
Alexander Duyck0ba82992011-08-26 07:45:47 +00003962 new_itr = IGB_4K_ITR; /* 4,000 ints/sec */
Auke Kok9d5c8242008-01-24 02:22:38 -08003963 break;
3964 default:
3965 break;
3966 }
3967
3968set_itr_now:
Alexander Duyck047e0032009-10-27 15:49:27 +00003969 if (new_itr != q_vector->itr_val) {
Auke Kok9d5c8242008-01-24 02:22:38 -08003970 /* this attempts to bias the interrupt rate towards Bulk
3971 * by adding intermediate steps when interrupt rate is
3972 * increasing */
Alexander Duyck047e0032009-10-27 15:49:27 +00003973 new_itr = new_itr > q_vector->itr_val ?
3974 max((new_itr * q_vector->itr_val) /
3975 (new_itr + (q_vector->itr_val >> 2)),
Alexander Duyck0ba82992011-08-26 07:45:47 +00003976 new_itr) :
Auke Kok9d5c8242008-01-24 02:22:38 -08003977 new_itr;
3978 /* Don't write the value here; it resets the adapter's
3979 * internal timer, and causes us to delay far longer than
3980 * we should between interrupts. Instead, we write the ITR
3981 * value at the beginning of the next interrupt so the timing
3982 * ends up being correct.
3983 */
Alexander Duyck047e0032009-10-27 15:49:27 +00003984 q_vector->itr_val = new_itr;
3985 q_vector->set_itr = 1;
Auke Kok9d5c8242008-01-24 02:22:38 -08003986 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003987}
3988
Stephen Hemmingerc50b52a2012-01-18 22:13:26 +00003989static void igb_tx_ctxtdesc(struct igb_ring *tx_ring, u32 vlan_macip_lens,
3990 u32 type_tucmd, u32 mss_l4len_idx)
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00003991{
3992 struct e1000_adv_tx_context_desc *context_desc;
3993 u16 i = tx_ring->next_to_use;
3994
3995 context_desc = IGB_TX_CTXTDESC(tx_ring, i);
3996
3997 i++;
3998 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
3999
4000 /* set bits to identify this as an advanced context descriptor */
4001 type_tucmd |= E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
4002
4003 /* For 82575, context index must be unique per ring. */
Alexander Duyck866cff02011-08-26 07:45:36 +00004004 if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004005 mss_l4len_idx |= tx_ring->reg_idx << 4;
4006
4007 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4008 context_desc->seqnum_seed = 0;
4009 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
4010 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
4011}
4012
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004013static int igb_tso(struct igb_ring *tx_ring,
4014 struct igb_tx_buffer *first,
4015 u8 *hdr_len)
Auke Kok9d5c8242008-01-24 02:22:38 -08004016{
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004017 struct sk_buff *skb = first->skb;
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004018 u32 vlan_macip_lens, type_tucmd;
4019 u32 mss_l4len_idx, l4len;
4020
Alexander Duycked6aa102012-11-13 04:03:22 +00004021 if (skb->ip_summed != CHECKSUM_PARTIAL)
4022 return 0;
4023
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004024 if (!skb_is_gso(skb))
4025 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08004026
4027 if (skb_header_cloned(skb)) {
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004028 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
Auke Kok9d5c8242008-01-24 02:22:38 -08004029 if (err)
4030 return err;
4031 }
4032
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004033 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
4034 type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
Auke Kok9d5c8242008-01-24 02:22:38 -08004035
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004036 if (first->protocol == __constant_htons(ETH_P_IP)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08004037 struct iphdr *iph = ip_hdr(skb);
4038 iph->tot_len = 0;
4039 iph->check = 0;
4040 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
4041 iph->daddr, 0,
4042 IPPROTO_TCP,
4043 0);
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004044 type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004045 first->tx_flags |= IGB_TX_FLAGS_TSO |
4046 IGB_TX_FLAGS_CSUM |
4047 IGB_TX_FLAGS_IPV4;
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08004048 } else if (skb_is_gso_v6(skb)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08004049 ipv6_hdr(skb)->payload_len = 0;
4050 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
4051 &ipv6_hdr(skb)->daddr,
4052 0, IPPROTO_TCP, 0);
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004053 first->tx_flags |= IGB_TX_FLAGS_TSO |
4054 IGB_TX_FLAGS_CSUM;
Auke Kok9d5c8242008-01-24 02:22:38 -08004055 }
4056
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004057 /* compute header lengths */
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004058 l4len = tcp_hdrlen(skb);
4059 *hdr_len = skb_transport_offset(skb) + l4len;
Auke Kok9d5c8242008-01-24 02:22:38 -08004060
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004061 /* update gso size and bytecount with header size */
4062 first->gso_segs = skb_shinfo(skb)->gso_segs;
4063 first->bytecount += (first->gso_segs - 1) * *hdr_len;
4064
Auke Kok9d5c8242008-01-24 02:22:38 -08004065 /* MSS L4LEN IDX */
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004066 mss_l4len_idx = l4len << E1000_ADVTXD_L4LEN_SHIFT;
4067 mss_l4len_idx |= skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT;
Auke Kok9d5c8242008-01-24 02:22:38 -08004068
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004069 /* VLAN MACLEN IPLEN */
4070 vlan_macip_lens = skb_network_header_len(skb);
4071 vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004072 vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
Auke Kok9d5c8242008-01-24 02:22:38 -08004073
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004074 igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
Auke Kok9d5c8242008-01-24 02:22:38 -08004075
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004076 return 1;
Auke Kok9d5c8242008-01-24 02:22:38 -08004077}
4078
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004079static void igb_tx_csum(struct igb_ring *tx_ring, struct igb_tx_buffer *first)
Auke Kok9d5c8242008-01-24 02:22:38 -08004080{
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004081 struct sk_buff *skb = first->skb;
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004082 u32 vlan_macip_lens = 0;
4083 u32 mss_l4len_idx = 0;
4084 u32 type_tucmd = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08004085
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004086 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004087 if (!(first->tx_flags & IGB_TX_FLAGS_VLAN))
4088 return;
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004089 } else {
4090 u8 l4_hdr = 0;
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004091 switch (first->protocol) {
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004092 case __constant_htons(ETH_P_IP):
4093 vlan_macip_lens |= skb_network_header_len(skb);
4094 type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
4095 l4_hdr = ip_hdr(skb)->protocol;
4096 break;
4097 case __constant_htons(ETH_P_IPV6):
4098 vlan_macip_lens |= skb_network_header_len(skb);
4099 l4_hdr = ipv6_hdr(skb)->nexthdr;
4100 break;
4101 default:
4102 if (unlikely(net_ratelimit())) {
4103 dev_warn(tx_ring->dev,
4104 "partial checksum but proto=%x!\n",
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004105 first->protocol);
Arthur Jonesfa4a7ef2009-03-21 16:55:07 -07004106 }
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004107 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08004108 }
4109
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004110 switch (l4_hdr) {
4111 case IPPROTO_TCP:
4112 type_tucmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
4113 mss_l4len_idx = tcp_hdrlen(skb) <<
4114 E1000_ADVTXD_L4LEN_SHIFT;
4115 break;
4116 case IPPROTO_SCTP:
4117 type_tucmd |= E1000_ADVTXD_TUCMD_L4T_SCTP;
4118 mss_l4len_idx = sizeof(struct sctphdr) <<
4119 E1000_ADVTXD_L4LEN_SHIFT;
4120 break;
4121 case IPPROTO_UDP:
4122 mss_l4len_idx = sizeof(struct udphdr) <<
4123 E1000_ADVTXD_L4LEN_SHIFT;
4124 break;
4125 default:
4126 if (unlikely(net_ratelimit())) {
4127 dev_warn(tx_ring->dev,
4128 "partial checksum but l4 proto=%x!\n",
4129 l4_hdr);
4130 }
4131 break;
4132 }
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004133
4134 /* update TX checksum flag */
4135 first->tx_flags |= IGB_TX_FLAGS_CSUM;
Auke Kok9d5c8242008-01-24 02:22:38 -08004136 }
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004137
4138 vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004139 vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004140
4141 igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
Auke Kok9d5c8242008-01-24 02:22:38 -08004142}
4143
Alexander Duyck1d9daf42012-11-13 04:03:23 +00004144#define IGB_SET_FLAG(_input, _flag, _result) \
4145 ((_flag <= _result) ? \
4146 ((u32)(_input & _flag) * (_result / _flag)) : \
4147 ((u32)(_input & _flag) / (_flag / _result)))
4148
4149static u32 igb_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duycke032afc2011-08-26 07:44:48 +00004150{
4151 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck1d9daf42012-11-13 04:03:23 +00004152 u32 cmd_type = E1000_ADVTXD_DTYP_DATA |
4153 E1000_ADVTXD_DCMD_DEXT |
4154 E1000_ADVTXD_DCMD_IFCS;
Alexander Duycke032afc2011-08-26 07:44:48 +00004155
4156 /* set HW vlan bit if vlan is present */
Alexander Duyck1d9daf42012-11-13 04:03:23 +00004157 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_VLAN,
4158 (E1000_ADVTXD_DCMD_VLE));
Alexander Duycke032afc2011-08-26 07:44:48 +00004159
4160 /* set segmentation bits for TSO */
Alexander Duyck1d9daf42012-11-13 04:03:23 +00004161 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_TSO,
4162 (E1000_ADVTXD_DCMD_TSE));
4163
4164 /* set timestamp bit if present */
4165 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_TSTAMP,
4166 (E1000_ADVTXD_MAC_TSTAMP));
4167
4168 /* insert frame checksum */
4169 cmd_type ^= IGB_SET_FLAG(skb->no_fcs, 1, E1000_ADVTXD_DCMD_IFCS);
Alexander Duycke032afc2011-08-26 07:44:48 +00004170
4171 return cmd_type;
4172}
4173
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004174static void igb_tx_olinfo_status(struct igb_ring *tx_ring,
4175 union e1000_adv_tx_desc *tx_desc,
4176 u32 tx_flags, unsigned int paylen)
Alexander Duycke032afc2011-08-26 07:44:48 +00004177{
4178 u32 olinfo_status = paylen << E1000_ADVTXD_PAYLEN_SHIFT;
4179
Alexander Duyck1d9daf42012-11-13 04:03:23 +00004180 /* 82575 requires a unique index per ring */
4181 if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
Alexander Duycke032afc2011-08-26 07:44:48 +00004182 olinfo_status |= tx_ring->reg_idx << 4;
4183
4184 /* insert L4 checksum */
Alexander Duyck1d9daf42012-11-13 04:03:23 +00004185 olinfo_status |= IGB_SET_FLAG(tx_flags,
4186 IGB_TX_FLAGS_CSUM,
4187 (E1000_TXD_POPTS_TXSM << 8));
Alexander Duycke032afc2011-08-26 07:44:48 +00004188
Alexander Duyck1d9daf42012-11-13 04:03:23 +00004189 /* insert IPv4 checksum */
4190 olinfo_status |= IGB_SET_FLAG(tx_flags,
4191 IGB_TX_FLAGS_IPV4,
4192 (E1000_TXD_POPTS_IXSM << 8));
Alexander Duycke032afc2011-08-26 07:44:48 +00004193
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004194 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duycke032afc2011-08-26 07:44:48 +00004195}
4196
Alexander Duyckebe42d12011-08-26 07:45:09 +00004197/*
4198 * The largest size we can write to the descriptor is 65535. In order to
4199 * maintain a power of two alignment we have to limit ourselves to 32K.
4200 */
4201#define IGB_MAX_TXD_PWR 15
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004202#define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR)
Auke Kok9d5c8242008-01-24 02:22:38 -08004203
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004204static void igb_tx_map(struct igb_ring *tx_ring,
4205 struct igb_tx_buffer *first,
Alexander Duyckebe42d12011-08-26 07:45:09 +00004206 const u8 hdr_len)
Auke Kok9d5c8242008-01-24 02:22:38 -08004207{
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004208 struct sk_buff *skb = first->skb;
Alexander Duyckc9f14bf32012-09-18 01:56:27 +00004209 struct igb_tx_buffer *tx_buffer;
Alexander Duyckebe42d12011-08-26 07:45:09 +00004210 union e1000_adv_tx_desc *tx_desc;
Alexander Duyck80d07592012-11-13 04:03:24 +00004211 struct skb_frag_struct *frag;
Alexander Duyckebe42d12011-08-26 07:45:09 +00004212 dma_addr_t dma;
Alexander Duyck80d07592012-11-13 04:03:24 +00004213 unsigned int data_len, size;
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004214 u32 tx_flags = first->tx_flags;
Alexander Duyck1d9daf42012-11-13 04:03:23 +00004215 u32 cmd_type = igb_tx_cmd_type(skb, tx_flags);
Alexander Duyckebe42d12011-08-26 07:45:09 +00004216 u16 i = tx_ring->next_to_use;
Alexander Duyckebe42d12011-08-26 07:45:09 +00004217
4218 tx_desc = IGB_TX_DESC(tx_ring, i);
4219
Alexander Duyck80d07592012-11-13 04:03:24 +00004220 igb_tx_olinfo_status(tx_ring, tx_desc, tx_flags, skb->len - hdr_len);
4221
4222 size = skb_headlen(skb);
4223 data_len = skb->data_len;
Alexander Duyckebe42d12011-08-26 07:45:09 +00004224
4225 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Auke Kok9d5c8242008-01-24 02:22:38 -08004226
Alexander Duyck80d07592012-11-13 04:03:24 +00004227 tx_buffer = first;
Alexander Duyck2bbfebe2011-08-26 07:44:59 +00004228
Alexander Duyck80d07592012-11-13 04:03:24 +00004229 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
4230 if (dma_mapping_error(tx_ring->dev, dma))
4231 goto dma_error;
4232
4233 /* record length, and DMA address */
4234 dma_unmap_len_set(tx_buffer, len, size);
4235 dma_unmap_addr_set(tx_buffer, dma, dma);
4236
4237 tx_desc->read.buffer_addr = cpu_to_le64(dma);
4238
Alexander Duyckebe42d12011-08-26 07:45:09 +00004239 while (unlikely(size > IGB_MAX_DATA_PER_TXD)) {
4240 tx_desc->read.cmd_type_len =
Alexander Duyck1d9daf42012-11-13 04:03:23 +00004241 cpu_to_le32(cmd_type ^ IGB_MAX_DATA_PER_TXD);
Auke Kok9d5c8242008-01-24 02:22:38 -08004242
Alexander Duyckebe42d12011-08-26 07:45:09 +00004243 i++;
4244 tx_desc++;
4245 if (i == tx_ring->count) {
4246 tx_desc = IGB_TX_DESC(tx_ring, 0);
4247 i = 0;
4248 }
Alexander Duyck80d07592012-11-13 04:03:24 +00004249 tx_desc->read.olinfo_status = 0;
Alexander Duyckebe42d12011-08-26 07:45:09 +00004250
4251 dma += IGB_MAX_DATA_PER_TXD;
4252 size -= IGB_MAX_DATA_PER_TXD;
4253
Alexander Duyckebe42d12011-08-26 07:45:09 +00004254 tx_desc->read.buffer_addr = cpu_to_le64(dma);
4255 }
4256
4257 if (likely(!data_len))
4258 break;
4259
Alexander Duyck1d9daf42012-11-13 04:03:23 +00004260 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckebe42d12011-08-26 07:45:09 +00004261
Alexander Duyck65689fe2009-03-20 00:17:43 +00004262 i++;
Alexander Duyckebe42d12011-08-26 07:45:09 +00004263 tx_desc++;
4264 if (i == tx_ring->count) {
4265 tx_desc = IGB_TX_DESC(tx_ring, 0);
Alexander Duyck65689fe2009-03-20 00:17:43 +00004266 i = 0;
Alexander Duyckebe42d12011-08-26 07:45:09 +00004267 }
Alexander Duyck80d07592012-11-13 04:03:24 +00004268 tx_desc->read.olinfo_status = 0;
Alexander Duyck65689fe2009-03-20 00:17:43 +00004269
Eric Dumazet9e903e02011-10-18 21:00:24 +00004270 size = skb_frag_size(frag);
Alexander Duyckebe42d12011-08-26 07:45:09 +00004271 data_len -= size;
4272
4273 dma = skb_frag_dma_map(tx_ring->dev, frag, 0,
Alexander Duyck80d07592012-11-13 04:03:24 +00004274 size, DMA_TO_DEVICE);
Alexander Duyck6366ad32009-12-02 16:47:18 +00004275
Alexander Duyckc9f14bf32012-09-18 01:56:27 +00004276 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9d5c8242008-01-24 02:22:38 -08004277 }
4278
Alexander Duyckebe42d12011-08-26 07:45:09 +00004279 /* write last descriptor with RS and EOP bits */
Alexander Duyck1d9daf42012-11-13 04:03:23 +00004280 cmd_type |= size | IGB_TXD_DCMD;
4281 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyck8542db02011-08-26 07:44:43 +00004282
Alexander Duyck80d07592012-11-13 04:03:24 +00004283 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
4284
Alexander Duyck8542db02011-08-26 07:44:43 +00004285 /* set the timestamp */
4286 first->time_stamp = jiffies;
4287
Alexander Duyckebe42d12011-08-26 07:45:09 +00004288 /*
4289 * Force memory writes to complete before letting h/w know there
4290 * are new descriptors to fetch. (Only applicable for weak-ordered
4291 * memory model archs, such as IA-64).
4292 *
4293 * We also need this memory barrier to make certain all of the
4294 * status bits have been updated before next_to_watch is written.
4295 */
Auke Kok9d5c8242008-01-24 02:22:38 -08004296 wmb();
4297
Alexander Duyckebe42d12011-08-26 07:45:09 +00004298 /* set next_to_watch value indicating a packet is present */
4299 first->next_to_watch = tx_desc;
4300
4301 i++;
4302 if (i == tx_ring->count)
4303 i = 0;
4304
Auke Kok9d5c8242008-01-24 02:22:38 -08004305 tx_ring->next_to_use = i;
Alexander Duyckebe42d12011-08-26 07:45:09 +00004306
Alexander Duyckfce99e32009-10-27 15:51:27 +00004307 writel(i, tx_ring->tail);
Alexander Duyckebe42d12011-08-26 07:45:09 +00004308
Auke Kok9d5c8242008-01-24 02:22:38 -08004309 /* we need this if more than one processor can write to our tail
4310 * at a time, it syncronizes IO on IA64/Altix systems */
4311 mmiowb();
Alexander Duyckebe42d12011-08-26 07:45:09 +00004312
4313 return;
4314
4315dma_error:
4316 dev_err(tx_ring->dev, "TX DMA map failed\n");
4317
4318 /* clear dma mappings for failed tx_buffer_info map */
4319 for (;;) {
Alexander Duyckc9f14bf32012-09-18 01:56:27 +00004320 tx_buffer = &tx_ring->tx_buffer_info[i];
4321 igb_unmap_and_free_tx_resource(tx_ring, tx_buffer);
4322 if (tx_buffer == first)
Alexander Duyckebe42d12011-08-26 07:45:09 +00004323 break;
4324 if (i == 0)
4325 i = tx_ring->count;
4326 i--;
4327 }
4328
4329 tx_ring->next_to_use = i;
Auke Kok9d5c8242008-01-24 02:22:38 -08004330}
4331
Alexander Duyck6ad4edf2011-08-26 07:45:26 +00004332static int __igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
Auke Kok9d5c8242008-01-24 02:22:38 -08004333{
Alexander Duycke694e962009-10-27 15:53:06 +00004334 struct net_device *netdev = tx_ring->netdev;
4335
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004336 netif_stop_subqueue(netdev, tx_ring->queue_index);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004337
Auke Kok9d5c8242008-01-24 02:22:38 -08004338 /* Herbert's original patch had:
4339 * smp_mb__after_netif_stop_queue();
4340 * but since that doesn't exist yet, just open code it. */
4341 smp_mb();
4342
4343 /* We need to check again in a case another CPU has just
4344 * made room available. */
Alexander Duyckc493ea42009-03-20 00:16:50 +00004345 if (igb_desc_unused(tx_ring) < size)
Auke Kok9d5c8242008-01-24 02:22:38 -08004346 return -EBUSY;
4347
4348 /* A reprieve! */
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004349 netif_wake_subqueue(netdev, tx_ring->queue_index);
Eric Dumazet12dcd862010-10-15 17:27:10 +00004350
4351 u64_stats_update_begin(&tx_ring->tx_syncp2);
4352 tx_ring->tx_stats.restart_queue2++;
4353 u64_stats_update_end(&tx_ring->tx_syncp2);
4354
Auke Kok9d5c8242008-01-24 02:22:38 -08004355 return 0;
4356}
4357
Alexander Duyck6ad4edf2011-08-26 07:45:26 +00004358static inline int igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
Auke Kok9d5c8242008-01-24 02:22:38 -08004359{
Alexander Duyckc493ea42009-03-20 00:16:50 +00004360 if (igb_desc_unused(tx_ring) >= size)
Auke Kok9d5c8242008-01-24 02:22:38 -08004361 return 0;
Alexander Duycke694e962009-10-27 15:53:06 +00004362 return __igb_maybe_stop_tx(tx_ring, size);
Auke Kok9d5c8242008-01-24 02:22:38 -08004363}
4364
Alexander Duyckcd392f52011-08-26 07:43:59 +00004365netdev_tx_t igb_xmit_frame_ring(struct sk_buff *skb,
4366 struct igb_ring *tx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08004367{
Matthew Vick1f6e8172012-08-18 07:26:33 +00004368 struct igb_adapter *adapter = netdev_priv(tx_ring->netdev);
Alexander Duyck8542db02011-08-26 07:44:43 +00004369 struct igb_tx_buffer *first;
Alexander Duyckebe42d12011-08-26 07:45:09 +00004370 int tso;
Nick Nunley91d4ee32010-02-17 01:04:56 +00004371 u32 tx_flags = 0;
Alexander Duyck31f6adb2011-08-26 07:44:53 +00004372 __be16 protocol = vlan_get_protocol(skb);
Nick Nunley91d4ee32010-02-17 01:04:56 +00004373 u8 hdr_len = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08004374
Auke Kok9d5c8242008-01-24 02:22:38 -08004375 /* need: 1 descriptor per page,
4376 * + 2 desc gap to keep tail from touching head,
4377 * + 1 desc for skb->data,
4378 * + 1 desc for context descriptor,
4379 * otherwise try next time */
Alexander Duycke694e962009-10-27 15:53:06 +00004380 if (igb_maybe_stop_tx(tx_ring, skb_shinfo(skb)->nr_frags + 4)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08004381 /* this is a hard error */
Auke Kok9d5c8242008-01-24 02:22:38 -08004382 return NETDEV_TX_BUSY;
4383 }
Patrick Ohly33af6bc2009-02-12 05:03:43 +00004384
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004385 /* record the location of the first descriptor for this packet */
4386 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
4387 first->skb = skb;
4388 first->bytecount = skb->len;
4389 first->gso_segs = 1;
4390
Matthew Vick1f6e8172012-08-18 07:26:33 +00004391 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
4392 !(adapter->ptp_tx_skb))) {
Oliver Hartkopp2244d072010-08-17 08:59:14 +00004393 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00004394 tx_flags |= IGB_TX_FLAGS_TSTAMP;
Matthew Vick1f6e8172012-08-18 07:26:33 +00004395
4396 adapter->ptp_tx_skb = skb_get(skb);
4397 if (adapter->hw.mac.type == e1000_82576)
4398 schedule_work(&adapter->ptp_tx_work);
Patrick Ohly33af6bc2009-02-12 05:03:43 +00004399 }
Auke Kok9d5c8242008-01-24 02:22:38 -08004400
Jesse Grosseab6d182010-10-20 13:56:03 +00004401 if (vlan_tx_tag_present(skb)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08004402 tx_flags |= IGB_TX_FLAGS_VLAN;
4403 tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
4404 }
4405
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004406 /* record initial flags and protocol */
4407 first->tx_flags = tx_flags;
4408 first->protocol = protocol;
Alexander Duyckcdfd01fc2009-10-27 23:50:57 +00004409
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004410 tso = igb_tso(tx_ring, first, &hdr_len);
4411 if (tso < 0)
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004412 goto out_drop;
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004413 else if (!tso)
4414 igb_tx_csum(tx_ring, first);
Auke Kok9d5c8242008-01-24 02:22:38 -08004415
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004416 igb_tx_map(tx_ring, first, hdr_len);
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004417
4418 /* Make sure there is space in the ring for the next send. */
Alexander Duycke694e962009-10-27 15:53:06 +00004419 igb_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 4);
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004420
Auke Kok9d5c8242008-01-24 02:22:38 -08004421 return NETDEV_TX_OK;
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004422
4423out_drop:
Alexander Duyck7af40ad92011-08-26 07:45:15 +00004424 igb_unmap_and_free_tx_resource(tx_ring, first);
4425
Alexander Duyck7d13a7d2011-08-26 07:44:32 +00004426 return NETDEV_TX_OK;
Auke Kok9d5c8242008-01-24 02:22:38 -08004427}
4428
Alexander Duyck1cc3bd82011-08-26 07:44:10 +00004429static inline struct igb_ring *igb_tx_queue_mapping(struct igb_adapter *adapter,
4430 struct sk_buff *skb)
4431{
4432 unsigned int r_idx = skb->queue_mapping;
4433
4434 if (r_idx >= adapter->num_tx_queues)
4435 r_idx = r_idx % adapter->num_tx_queues;
4436
4437 return adapter->tx_ring[r_idx];
4438}
4439
Alexander Duyckcd392f52011-08-26 07:43:59 +00004440static netdev_tx_t igb_xmit_frame(struct sk_buff *skb,
4441 struct net_device *netdev)
Auke Kok9d5c8242008-01-24 02:22:38 -08004442{
4443 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyckb1a436c2009-10-27 15:54:43 +00004444
4445 if (test_bit(__IGB_DOWN, &adapter->state)) {
4446 dev_kfree_skb_any(skb);
4447 return NETDEV_TX_OK;
4448 }
4449
4450 if (skb->len <= 0) {
4451 dev_kfree_skb_any(skb);
4452 return NETDEV_TX_OK;
4453 }
4454
Alexander Duyck1cc3bd82011-08-26 07:44:10 +00004455 /*
4456 * The minimum packet size with TCTL.PSP set is 17 so pad the skb
4457 * in order to meet this minimum size requirement.
4458 */
Tushar Daveea5ceea2012-09-14 03:43:43 +00004459 if (unlikely(skb->len < 17)) {
4460 if (skb_pad(skb, 17 - skb->len))
Alexander Duyck1cc3bd82011-08-26 07:44:10 +00004461 return NETDEV_TX_OK;
4462 skb->len = 17;
Tushar Daveea5ceea2012-09-14 03:43:43 +00004463 skb_set_tail_pointer(skb, 17);
Alexander Duyck1cc3bd82011-08-26 07:44:10 +00004464 }
Auke Kok9d5c8242008-01-24 02:22:38 -08004465
Alexander Duyck1cc3bd82011-08-26 07:44:10 +00004466 return igb_xmit_frame_ring(skb, igb_tx_queue_mapping(adapter, skb));
Auke Kok9d5c8242008-01-24 02:22:38 -08004467}
4468
4469/**
4470 * igb_tx_timeout - Respond to a Tx Hang
4471 * @netdev: network interface device structure
4472 **/
4473static void igb_tx_timeout(struct net_device *netdev)
4474{
4475 struct igb_adapter *adapter = netdev_priv(netdev);
4476 struct e1000_hw *hw = &adapter->hw;
4477
4478 /* Do the reset outside of interrupt context */
4479 adapter->tx_timeout_count++;
Alexander Duyckf7ba2052009-10-27 23:48:51 +00004480
Alexander Duyck06218a82011-08-26 07:46:55 +00004481 if (hw->mac.type >= e1000_82580)
Alexander Duyck55cac242009-11-19 12:42:21 +00004482 hw->dev_spec._82575.global_device_reset = true;
4483
Auke Kok9d5c8242008-01-24 02:22:38 -08004484 schedule_work(&adapter->reset_task);
Alexander Duyck265de402009-02-06 23:22:52 +00004485 wr32(E1000_EICS,
4486 (adapter->eims_enable_mask & ~adapter->eims_other));
Auke Kok9d5c8242008-01-24 02:22:38 -08004487}
4488
4489static void igb_reset_task(struct work_struct *work)
4490{
4491 struct igb_adapter *adapter;
4492 adapter = container_of(work, struct igb_adapter, reset_task);
4493
Taku Izumic97ec422010-04-27 14:39:30 +00004494 igb_dump(adapter);
4495 netdev_err(adapter->netdev, "Reset adapter\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08004496 igb_reinit_locked(adapter);
4497}
4498
4499/**
Eric Dumazet12dcd862010-10-15 17:27:10 +00004500 * igb_get_stats64 - Get System Network Statistics
Auke Kok9d5c8242008-01-24 02:22:38 -08004501 * @netdev: network interface device structure
Eric Dumazet12dcd862010-10-15 17:27:10 +00004502 * @stats: rtnl_link_stats64 pointer
Auke Kok9d5c8242008-01-24 02:22:38 -08004503 *
Auke Kok9d5c8242008-01-24 02:22:38 -08004504 **/
Eric Dumazet12dcd862010-10-15 17:27:10 +00004505static struct rtnl_link_stats64 *igb_get_stats64(struct net_device *netdev,
4506 struct rtnl_link_stats64 *stats)
Auke Kok9d5c8242008-01-24 02:22:38 -08004507{
Eric Dumazet12dcd862010-10-15 17:27:10 +00004508 struct igb_adapter *adapter = netdev_priv(netdev);
4509
4510 spin_lock(&adapter->stats64_lock);
4511 igb_update_stats(adapter, &adapter->stats64);
4512 memcpy(stats, &adapter->stats64, sizeof(*stats));
4513 spin_unlock(&adapter->stats64_lock);
4514
4515 return stats;
Auke Kok9d5c8242008-01-24 02:22:38 -08004516}
4517
4518/**
4519 * igb_change_mtu - Change the Maximum Transfer Unit
4520 * @netdev: network interface device structure
4521 * @new_mtu: new value for maximum frame size
4522 *
4523 * Returns 0 on success, negative on failure
4524 **/
4525static int igb_change_mtu(struct net_device *netdev, int new_mtu)
4526{
4527 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck090b1792009-10-27 23:51:55 +00004528 struct pci_dev *pdev = adapter->pdev;
Alexander Duyck153285f2011-08-26 07:43:32 +00004529 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
Auke Kok9d5c8242008-01-24 02:22:38 -08004530
Alexander Duyckc809d222009-10-27 23:52:13 +00004531 if ((new_mtu < 68) || (max_frame > MAX_JUMBO_FRAME_SIZE)) {
Alexander Duyck090b1792009-10-27 23:51:55 +00004532 dev_err(&pdev->dev, "Invalid MTU setting\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08004533 return -EINVAL;
4534 }
4535
Alexander Duyck153285f2011-08-26 07:43:32 +00004536#define MAX_STD_JUMBO_FRAME_SIZE 9238
Auke Kok9d5c8242008-01-24 02:22:38 -08004537 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
Alexander Duyck090b1792009-10-27 23:51:55 +00004538 dev_err(&pdev->dev, "MTU > 9216 not supported.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08004539 return -EINVAL;
4540 }
4541
4542 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
4543 msleep(1);
Alexander Duyck73cd78f2009-02-12 18:16:59 +00004544
Auke Kok9d5c8242008-01-24 02:22:38 -08004545 /* igb_down has a dependency on max_frame_size */
4546 adapter->max_frame_size = max_frame;
Alexander Duyck559e9c42009-10-27 23:52:50 +00004547
Alexander Duyck4c844852009-10-27 15:52:07 +00004548 if (netif_running(netdev))
4549 igb_down(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08004550
Alexander Duyck090b1792009-10-27 23:51:55 +00004551 dev_info(&pdev->dev, "changing MTU from %d to %d\n",
Auke Kok9d5c8242008-01-24 02:22:38 -08004552 netdev->mtu, new_mtu);
4553 netdev->mtu = new_mtu;
4554
4555 if (netif_running(netdev))
4556 igb_up(adapter);
4557 else
4558 igb_reset(adapter);
4559
4560 clear_bit(__IGB_RESETTING, &adapter->state);
4561
4562 return 0;
4563}
4564
4565/**
4566 * igb_update_stats - Update the board statistics counters
4567 * @adapter: board private structure
4568 **/
4569
Eric Dumazet12dcd862010-10-15 17:27:10 +00004570void igb_update_stats(struct igb_adapter *adapter,
4571 struct rtnl_link_stats64 *net_stats)
Auke Kok9d5c8242008-01-24 02:22:38 -08004572{
4573 struct e1000_hw *hw = &adapter->hw;
4574 struct pci_dev *pdev = adapter->pdev;
Mitch Williamsfa3d9a62010-03-23 18:34:38 +00004575 u32 reg, mpc;
Auke Kok9d5c8242008-01-24 02:22:38 -08004576 u16 phy_tmp;
Alexander Duyck3f9c0162009-10-27 23:48:12 +00004577 int i;
4578 u64 bytes, packets;
Eric Dumazet12dcd862010-10-15 17:27:10 +00004579 unsigned int start;
4580 u64 _bytes, _packets;
Auke Kok9d5c8242008-01-24 02:22:38 -08004581
4582#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
4583
4584 /*
4585 * Prevent stats update while adapter is being reset, or if the pci
4586 * connection is down.
4587 */
4588 if (adapter->link_speed == 0)
4589 return;
4590 if (pci_channel_offline(pdev))
4591 return;
4592
Alexander Duyck3f9c0162009-10-27 23:48:12 +00004593 bytes = 0;
4594 packets = 0;
4595 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckae1c07a2012-08-08 05:23:22 +00004596 u32 rqdpc = rd32(E1000_RQDPC(i));
Alexander Duyck3025a442010-02-17 01:02:39 +00004597 struct igb_ring *ring = adapter->rx_ring[i];
Eric Dumazet12dcd862010-10-15 17:27:10 +00004598
Alexander Duyckae1c07a2012-08-08 05:23:22 +00004599 if (rqdpc) {
4600 ring->rx_stats.drops += rqdpc;
4601 net_stats->rx_fifo_errors += rqdpc;
4602 }
Eric Dumazet12dcd862010-10-15 17:27:10 +00004603
4604 do {
4605 start = u64_stats_fetch_begin_bh(&ring->rx_syncp);
4606 _bytes = ring->rx_stats.bytes;
4607 _packets = ring->rx_stats.packets;
4608 } while (u64_stats_fetch_retry_bh(&ring->rx_syncp, start));
4609 bytes += _bytes;
4610 packets += _packets;
Alexander Duyck3f9c0162009-10-27 23:48:12 +00004611 }
4612
Alexander Duyck128e45e2009-11-12 18:37:38 +00004613 net_stats->rx_bytes = bytes;
4614 net_stats->rx_packets = packets;
Alexander Duyck3f9c0162009-10-27 23:48:12 +00004615
4616 bytes = 0;
4617 packets = 0;
4618 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +00004619 struct igb_ring *ring = adapter->tx_ring[i];
Eric Dumazet12dcd862010-10-15 17:27:10 +00004620 do {
4621 start = u64_stats_fetch_begin_bh(&ring->tx_syncp);
4622 _bytes = ring->tx_stats.bytes;
4623 _packets = ring->tx_stats.packets;
4624 } while (u64_stats_fetch_retry_bh(&ring->tx_syncp, start));
4625 bytes += _bytes;
4626 packets += _packets;
Alexander Duyck3f9c0162009-10-27 23:48:12 +00004627 }
Alexander Duyck128e45e2009-11-12 18:37:38 +00004628 net_stats->tx_bytes = bytes;
4629 net_stats->tx_packets = packets;
Alexander Duyck3f9c0162009-10-27 23:48:12 +00004630
4631 /* read stats registers */
Auke Kok9d5c8242008-01-24 02:22:38 -08004632 adapter->stats.crcerrs += rd32(E1000_CRCERRS);
4633 adapter->stats.gprc += rd32(E1000_GPRC);
4634 adapter->stats.gorc += rd32(E1000_GORCL);
4635 rd32(E1000_GORCH); /* clear GORCL */
4636 adapter->stats.bprc += rd32(E1000_BPRC);
4637 adapter->stats.mprc += rd32(E1000_MPRC);
4638 adapter->stats.roc += rd32(E1000_ROC);
4639
4640 adapter->stats.prc64 += rd32(E1000_PRC64);
4641 adapter->stats.prc127 += rd32(E1000_PRC127);
4642 adapter->stats.prc255 += rd32(E1000_PRC255);
4643 adapter->stats.prc511 += rd32(E1000_PRC511);
4644 adapter->stats.prc1023 += rd32(E1000_PRC1023);
4645 adapter->stats.prc1522 += rd32(E1000_PRC1522);
4646 adapter->stats.symerrs += rd32(E1000_SYMERRS);
4647 adapter->stats.sec += rd32(E1000_SEC);
4648
Mitch Williamsfa3d9a62010-03-23 18:34:38 +00004649 mpc = rd32(E1000_MPC);
4650 adapter->stats.mpc += mpc;
4651 net_stats->rx_fifo_errors += mpc;
Auke Kok9d5c8242008-01-24 02:22:38 -08004652 adapter->stats.scc += rd32(E1000_SCC);
4653 adapter->stats.ecol += rd32(E1000_ECOL);
4654 adapter->stats.mcc += rd32(E1000_MCC);
4655 adapter->stats.latecol += rd32(E1000_LATECOL);
4656 adapter->stats.dc += rd32(E1000_DC);
4657 adapter->stats.rlec += rd32(E1000_RLEC);
4658 adapter->stats.xonrxc += rd32(E1000_XONRXC);
4659 adapter->stats.xontxc += rd32(E1000_XONTXC);
4660 adapter->stats.xoffrxc += rd32(E1000_XOFFRXC);
4661 adapter->stats.xofftxc += rd32(E1000_XOFFTXC);
4662 adapter->stats.fcruc += rd32(E1000_FCRUC);
4663 adapter->stats.gptc += rd32(E1000_GPTC);
4664 adapter->stats.gotc += rd32(E1000_GOTCL);
4665 rd32(E1000_GOTCH); /* clear GOTCL */
Mitch Williamsfa3d9a62010-03-23 18:34:38 +00004666 adapter->stats.rnbc += rd32(E1000_RNBC);
Auke Kok9d5c8242008-01-24 02:22:38 -08004667 adapter->stats.ruc += rd32(E1000_RUC);
4668 adapter->stats.rfc += rd32(E1000_RFC);
4669 adapter->stats.rjc += rd32(E1000_RJC);
4670 adapter->stats.tor += rd32(E1000_TORH);
4671 adapter->stats.tot += rd32(E1000_TOTH);
4672 adapter->stats.tpr += rd32(E1000_TPR);
4673
4674 adapter->stats.ptc64 += rd32(E1000_PTC64);
4675 adapter->stats.ptc127 += rd32(E1000_PTC127);
4676 adapter->stats.ptc255 += rd32(E1000_PTC255);
4677 adapter->stats.ptc511 += rd32(E1000_PTC511);
4678 adapter->stats.ptc1023 += rd32(E1000_PTC1023);
4679 adapter->stats.ptc1522 += rd32(E1000_PTC1522);
4680
4681 adapter->stats.mptc += rd32(E1000_MPTC);
4682 adapter->stats.bptc += rd32(E1000_BPTC);
4683
Nick Nunley2d0b0f62010-02-17 01:02:59 +00004684 adapter->stats.tpt += rd32(E1000_TPT);
4685 adapter->stats.colc += rd32(E1000_COLC);
Auke Kok9d5c8242008-01-24 02:22:38 -08004686
4687 adapter->stats.algnerrc += rd32(E1000_ALGNERRC);
Nick Nunley43915c7c2010-02-17 01:03:58 +00004688 /* read internal phy specific stats */
4689 reg = rd32(E1000_CTRL_EXT);
4690 if (!(reg & E1000_CTRL_EXT_LINK_MODE_MASK)) {
4691 adapter->stats.rxerrc += rd32(E1000_RXERRC);
Carolyn Wyborny3dbdf962012-09-12 04:36:24 +00004692
4693 /* this stat has invalid values on i210/i211 */
4694 if ((hw->mac.type != e1000_i210) &&
4695 (hw->mac.type != e1000_i211))
4696 adapter->stats.tncrs += rd32(E1000_TNCRS);
Nick Nunley43915c7c2010-02-17 01:03:58 +00004697 }
4698
Auke Kok9d5c8242008-01-24 02:22:38 -08004699 adapter->stats.tsctc += rd32(E1000_TSCTC);
4700 adapter->stats.tsctfc += rd32(E1000_TSCTFC);
4701
4702 adapter->stats.iac += rd32(E1000_IAC);
4703 adapter->stats.icrxoc += rd32(E1000_ICRXOC);
4704 adapter->stats.icrxptc += rd32(E1000_ICRXPTC);
4705 adapter->stats.icrxatc += rd32(E1000_ICRXATC);
4706 adapter->stats.ictxptc += rd32(E1000_ICTXPTC);
4707 adapter->stats.ictxatc += rd32(E1000_ICTXATC);
4708 adapter->stats.ictxqec += rd32(E1000_ICTXQEC);
4709 adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC);
4710 adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC);
4711
4712 /* Fill out the OS statistics structure */
Alexander Duyck128e45e2009-11-12 18:37:38 +00004713 net_stats->multicast = adapter->stats.mprc;
4714 net_stats->collisions = adapter->stats.colc;
Auke Kok9d5c8242008-01-24 02:22:38 -08004715
4716 /* Rx Errors */
4717
4718 /* RLEC on some newer hardware can be incorrect so build
Jesper Dangaard Brouer8c0ab702009-05-26 13:50:31 +00004719 * our own version based on RUC and ROC */
Alexander Duyck128e45e2009-11-12 18:37:38 +00004720 net_stats->rx_errors = adapter->stats.rxerrc +
Auke Kok9d5c8242008-01-24 02:22:38 -08004721 adapter->stats.crcerrs + adapter->stats.algnerrc +
4722 adapter->stats.ruc + adapter->stats.roc +
4723 adapter->stats.cexterr;
Alexander Duyck128e45e2009-11-12 18:37:38 +00004724 net_stats->rx_length_errors = adapter->stats.ruc +
4725 adapter->stats.roc;
4726 net_stats->rx_crc_errors = adapter->stats.crcerrs;
4727 net_stats->rx_frame_errors = adapter->stats.algnerrc;
4728 net_stats->rx_missed_errors = adapter->stats.mpc;
Auke Kok9d5c8242008-01-24 02:22:38 -08004729
4730 /* Tx Errors */
Alexander Duyck128e45e2009-11-12 18:37:38 +00004731 net_stats->tx_errors = adapter->stats.ecol +
4732 adapter->stats.latecol;
4733 net_stats->tx_aborted_errors = adapter->stats.ecol;
4734 net_stats->tx_window_errors = adapter->stats.latecol;
4735 net_stats->tx_carrier_errors = adapter->stats.tncrs;
Auke Kok9d5c8242008-01-24 02:22:38 -08004736
4737 /* Tx Dropped needs to be maintained elsewhere */
4738
4739 /* Phy Stats */
4740 if (hw->phy.media_type == e1000_media_type_copper) {
4741 if ((adapter->link_speed == SPEED_1000) &&
Alexander Duyck73cd78f2009-02-12 18:16:59 +00004742 (!igb_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
Auke Kok9d5c8242008-01-24 02:22:38 -08004743 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
4744 adapter->phy_stats.idle_errors += phy_tmp;
4745 }
4746 }
4747
4748 /* Management Stats */
4749 adapter->stats.mgptc += rd32(E1000_MGTPTC);
4750 adapter->stats.mgprc += rd32(E1000_MGTPRC);
4751 adapter->stats.mgpdc += rd32(E1000_MGTPDC);
Carolyn Wyborny0a915b92011-02-26 07:42:37 +00004752
4753 /* OS2BMC Stats */
4754 reg = rd32(E1000_MANC);
4755 if (reg & E1000_MANC_EN_BMC2OS) {
4756 adapter->stats.o2bgptc += rd32(E1000_O2BGPTC);
4757 adapter->stats.o2bspc += rd32(E1000_O2BSPC);
4758 adapter->stats.b2ospc += rd32(E1000_B2OSPC);
4759 adapter->stats.b2ogprc += rd32(E1000_B2OGPRC);
4760 }
Auke Kok9d5c8242008-01-24 02:22:38 -08004761}
4762
Auke Kok9d5c8242008-01-24 02:22:38 -08004763static irqreturn_t igb_msix_other(int irq, void *data)
4764{
Alexander Duyck047e0032009-10-27 15:49:27 +00004765 struct igb_adapter *adapter = data;
Auke Kok9d5c8242008-01-24 02:22:38 -08004766 struct e1000_hw *hw = &adapter->hw;
PJ Waskiewicz844290e2008-06-27 11:00:39 -07004767 u32 icr = rd32(E1000_ICR);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07004768 /* reading ICR causes bit 31 of EICR to be cleared */
Alexander Duyckdda0e082009-02-06 23:19:08 +00004769
Alexander Duyck7f081d42010-01-07 17:41:00 +00004770 if (icr & E1000_ICR_DRSTA)
4771 schedule_work(&adapter->reset_task);
4772
Alexander Duyck047e0032009-10-27 15:49:27 +00004773 if (icr & E1000_ICR_DOUTSYNC) {
Alexander Duyckdda0e082009-02-06 23:19:08 +00004774 /* HW is reporting DMA is out of sync */
4775 adapter->stats.doosync++;
Greg Rose13800462010-11-06 02:08:26 +00004776 /* The DMA Out of Sync is also indication of a spoof event
4777 * in IOV mode. Check the Wrong VM Behavior register to
4778 * see if it is really a spoof event. */
4779 igb_check_wvbr(adapter);
Alexander Duyckdda0e082009-02-06 23:19:08 +00004780 }
Alexander Duyckeebbbdb2009-02-06 23:19:29 +00004781
Alexander Duyck4ae196d2009-02-19 20:40:07 -08004782 /* Check for a mailbox event */
4783 if (icr & E1000_ICR_VMMB)
4784 igb_msg_task(adapter);
4785
4786 if (icr & E1000_ICR_LSC) {
4787 hw->mac.get_link_status = 1;
4788 /* guard against interrupt when we're going down */
4789 if (!test_bit(__IGB_DOWN, &adapter->state))
4790 mod_timer(&adapter->watchdog_timer, jiffies + 1);
4791 }
4792
Matthew Vick1f6e8172012-08-18 07:26:33 +00004793 if (icr & E1000_ICR_TS) {
4794 u32 tsicr = rd32(E1000_TSICR);
4795
4796 if (tsicr & E1000_TSICR_TXTS) {
4797 /* acknowledge the interrupt */
4798 wr32(E1000_TSICR, E1000_TSICR_TXTS);
4799 /* retrieve hardware timestamp */
4800 schedule_work(&adapter->ptp_tx_work);
4801 }
4802 }
Matthew Vick1f6e8172012-08-18 07:26:33 +00004803
PJ Waskiewicz844290e2008-06-27 11:00:39 -07004804 wr32(E1000_EIMS, adapter->eims_other);
Auke Kok9d5c8242008-01-24 02:22:38 -08004805
4806 return IRQ_HANDLED;
4807}
4808
Alexander Duyck047e0032009-10-27 15:49:27 +00004809static void igb_write_itr(struct igb_q_vector *q_vector)
Auke Kok9d5c8242008-01-24 02:22:38 -08004810{
Alexander Duyck26b39272010-02-17 01:00:41 +00004811 struct igb_adapter *adapter = q_vector->adapter;
Alexander Duyck047e0032009-10-27 15:49:27 +00004812 u32 itr_val = q_vector->itr_val & 0x7FFC;
Auke Kok9d5c8242008-01-24 02:22:38 -08004813
Alexander Duyck047e0032009-10-27 15:49:27 +00004814 if (!q_vector->set_itr)
4815 return;
Alexander Duyck73cd78f2009-02-12 18:16:59 +00004816
Alexander Duyck047e0032009-10-27 15:49:27 +00004817 if (!itr_val)
4818 itr_val = 0x4;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004819
Alexander Duyck26b39272010-02-17 01:00:41 +00004820 if (adapter->hw.mac.type == e1000_82575)
4821 itr_val |= itr_val << 16;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004822 else
Alexander Duyck0ba82992011-08-26 07:45:47 +00004823 itr_val |= E1000_EITR_CNT_IGNR;
Alexander Duyck047e0032009-10-27 15:49:27 +00004824
4825 writel(itr_val, q_vector->itr_register);
4826 q_vector->set_itr = 0;
4827}
4828
4829static irqreturn_t igb_msix_ring(int irq, void *data)
4830{
4831 struct igb_q_vector *q_vector = data;
4832
4833 /* Write the ITR value calculated from the previous interrupt. */
4834 igb_write_itr(q_vector);
4835
4836 napi_schedule(&q_vector->napi);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004837
Auke Kok9d5c8242008-01-24 02:22:38 -08004838 return IRQ_HANDLED;
4839}
4840
Jeff Kirsher421e02f2008-10-17 11:08:31 -07004841#ifdef CONFIG_IGB_DCA
Alexander Duyck6a050042012-09-25 00:31:27 +00004842static void igb_update_tx_dca(struct igb_adapter *adapter,
4843 struct igb_ring *tx_ring,
4844 int cpu)
4845{
4846 struct e1000_hw *hw = &adapter->hw;
4847 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
4848
4849 if (hw->mac.type != e1000_82575)
4850 txctrl <<= E1000_DCA_TXCTRL_CPUID_SHIFT;
4851
4852 /*
4853 * We can enable relaxed ordering for reads, but not writes when
4854 * DCA is enabled. This is due to a known issue in some chipsets
4855 * which will cause the DCA tag to be cleared.
4856 */
4857 txctrl |= E1000_DCA_TXCTRL_DESC_RRO_EN |
4858 E1000_DCA_TXCTRL_DATA_RRO_EN |
4859 E1000_DCA_TXCTRL_DESC_DCA_EN;
4860
4861 wr32(E1000_DCA_TXCTRL(tx_ring->reg_idx), txctrl);
4862}
4863
4864static void igb_update_rx_dca(struct igb_adapter *adapter,
4865 struct igb_ring *rx_ring,
4866 int cpu)
4867{
4868 struct e1000_hw *hw = &adapter->hw;
4869 u32 rxctrl = dca3_get_tag(&adapter->pdev->dev, cpu);
4870
4871 if (hw->mac.type != e1000_82575)
4872 rxctrl <<= E1000_DCA_RXCTRL_CPUID_SHIFT;
4873
4874 /*
4875 * We can enable relaxed ordering for reads, but not writes when
4876 * DCA is enabled. This is due to a known issue in some chipsets
4877 * which will cause the DCA tag to be cleared.
4878 */
4879 rxctrl |= E1000_DCA_RXCTRL_DESC_RRO_EN |
4880 E1000_DCA_RXCTRL_DESC_DCA_EN;
4881
4882 wr32(E1000_DCA_RXCTRL(rx_ring->reg_idx), rxctrl);
4883}
4884
Alexander Duyck047e0032009-10-27 15:49:27 +00004885static void igb_update_dca(struct igb_q_vector *q_vector)
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004886{
Alexander Duyck047e0032009-10-27 15:49:27 +00004887 struct igb_adapter *adapter = q_vector->adapter;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004888 int cpu = get_cpu();
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004889
Alexander Duyck047e0032009-10-27 15:49:27 +00004890 if (q_vector->cpu == cpu)
4891 goto out_no_update;
4892
Alexander Duyck6a050042012-09-25 00:31:27 +00004893 if (q_vector->tx.ring)
4894 igb_update_tx_dca(adapter, q_vector->tx.ring, cpu);
4895
4896 if (q_vector->rx.ring)
4897 igb_update_rx_dca(adapter, q_vector->rx.ring, cpu);
4898
Alexander Duyck047e0032009-10-27 15:49:27 +00004899 q_vector->cpu = cpu;
4900out_no_update:
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004901 put_cpu();
4902}
4903
4904static void igb_setup_dca(struct igb_adapter *adapter)
4905{
Alexander Duyck7e0e99e2009-05-21 13:06:56 +00004906 struct e1000_hw *hw = &adapter->hw;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004907 int i;
4908
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07004909 if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004910 return;
4911
Alexander Duyck7e0e99e2009-05-21 13:06:56 +00004912 /* Always use CB2 mode, difference is masked in the CB driver. */
4913 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
4914
Alexander Duyck047e0032009-10-27 15:49:27 +00004915 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck26b39272010-02-17 01:00:41 +00004916 adapter->q_vector[i]->cpu = -1;
4917 igb_update_dca(adapter->q_vector[i]);
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004918 }
4919}
4920
4921static int __igb_notify_dca(struct device *dev, void *data)
4922{
4923 struct net_device *netdev = dev_get_drvdata(dev);
4924 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck090b1792009-10-27 23:51:55 +00004925 struct pci_dev *pdev = adapter->pdev;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004926 struct e1000_hw *hw = &adapter->hw;
4927 unsigned long event = *(unsigned long *)data;
4928
4929 switch (event) {
4930 case DCA_PROVIDER_ADD:
4931 /* if already enabled, don't do it again */
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07004932 if (adapter->flags & IGB_FLAG_DCA_ENABLED)
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004933 break;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004934 if (dca_add_requester(dev) == 0) {
Alexander Duyckbbd98fe2009-01-31 00:52:30 -08004935 adapter->flags |= IGB_FLAG_DCA_ENABLED;
Alexander Duyck090b1792009-10-27 23:51:55 +00004936 dev_info(&pdev->dev, "DCA enabled\n");
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004937 igb_setup_dca(adapter);
4938 break;
4939 }
4940 /* Fall Through since DCA is disabled. */
4941 case DCA_PROVIDER_REMOVE:
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07004942 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004943 /* without this a class_device is left
Alexander Duyck047e0032009-10-27 15:49:27 +00004944 * hanging around in the sysfs model */
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004945 dca_remove_requester(dev);
Alexander Duyck090b1792009-10-27 23:51:55 +00004946 dev_info(&pdev->dev, "DCA disabled\n");
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07004947 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
Alexander Duyckcbd347a2009-02-15 23:59:44 -08004948 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004949 }
4950 break;
4951 }
Alexander Duyckbbd98fe2009-01-31 00:52:30 -08004952
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004953 return 0;
4954}
4955
4956static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
4957 void *p)
4958{
4959 int ret_val;
4960
4961 ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
4962 __igb_notify_dca);
4963
4964 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
4965}
Jeff Kirsher421e02f2008-10-17 11:08:31 -07004966#endif /* CONFIG_IGB_DCA */
Auke Kok9d5c8242008-01-24 02:22:38 -08004967
Greg Rose0224d662011-10-14 02:57:14 +00004968#ifdef CONFIG_PCI_IOV
4969static int igb_vf_configure(struct igb_adapter *adapter, int vf)
4970{
4971 unsigned char mac_addr[ETH_ALEN];
Greg Rose0224d662011-10-14 02:57:14 +00004972
Joe Perches7efd26d2012-07-12 19:33:06 +00004973 eth_random_addr(mac_addr);
Greg Rose0224d662011-10-14 02:57:14 +00004974 igb_set_vf_mac(adapter, vf, mac_addr);
4975
Stefan Assmannf5571472012-08-18 04:06:11 +00004976 return 0;
Greg Rose0224d662011-10-14 02:57:14 +00004977}
4978
Stefan Assmannf5571472012-08-18 04:06:11 +00004979static bool igb_vfs_are_assigned(struct igb_adapter *adapter)
Greg Rose0224d662011-10-14 02:57:14 +00004980{
Greg Rose0224d662011-10-14 02:57:14 +00004981 struct pci_dev *pdev = adapter->pdev;
Stefan Assmannf5571472012-08-18 04:06:11 +00004982 struct pci_dev *vfdev;
4983 int dev_id;
Greg Rose0224d662011-10-14 02:57:14 +00004984
4985 switch (adapter->hw.mac.type) {
4986 case e1000_82576:
Stefan Assmannf5571472012-08-18 04:06:11 +00004987 dev_id = IGB_82576_VF_DEV_ID;
Greg Rose0224d662011-10-14 02:57:14 +00004988 break;
4989 case e1000_i350:
Stefan Assmannf5571472012-08-18 04:06:11 +00004990 dev_id = IGB_I350_VF_DEV_ID;
Greg Rose0224d662011-10-14 02:57:14 +00004991 break;
4992 default:
Stefan Assmannf5571472012-08-18 04:06:11 +00004993 return false;
Greg Rose0224d662011-10-14 02:57:14 +00004994 }
4995
Stefan Assmannf5571472012-08-18 04:06:11 +00004996 /* loop through all the VFs to see if we own any that are assigned */
4997 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, dev_id, NULL);
4998 while (vfdev) {
4999 /* if we don't own it we don't care */
5000 if (vfdev->is_virtfn && vfdev->physfn == pdev) {
5001 /* if it is assigned we cannot release it */
5002 if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)
Greg Rose0224d662011-10-14 02:57:14 +00005003 return true;
5004 }
Stefan Assmannf5571472012-08-18 04:06:11 +00005005
5006 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, dev_id, vfdev);
Greg Rose0224d662011-10-14 02:57:14 +00005007 }
Stefan Assmannf5571472012-08-18 04:06:11 +00005008
Greg Rose0224d662011-10-14 02:57:14 +00005009 return false;
5010}
5011
5012#endif
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005013static void igb_ping_all_vfs(struct igb_adapter *adapter)
5014{
5015 struct e1000_hw *hw = &adapter->hw;
5016 u32 ping;
5017 int i;
5018
5019 for (i = 0 ; i < adapter->vfs_allocated_count; i++) {
5020 ping = E1000_PF_CONTROL_MSG;
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005021 if (adapter->vf_data[i].flags & IGB_VF_FLAG_CTS)
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005022 ping |= E1000_VT_MSGTYPE_CTS;
5023 igb_write_mbx(hw, &ping, 1, i);
5024 }
5025}
5026
Alexander Duyck7d5753f2009-10-27 23:47:16 +00005027static int igb_set_vf_promisc(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
5028{
5029 struct e1000_hw *hw = &adapter->hw;
5030 u32 vmolr = rd32(E1000_VMOLR(vf));
5031 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
5032
Alexander Duyckd85b90042010-09-22 17:56:20 +00005033 vf_data->flags &= ~(IGB_VF_FLAG_UNI_PROMISC |
Alexander Duyck7d5753f2009-10-27 23:47:16 +00005034 IGB_VF_FLAG_MULTI_PROMISC);
5035 vmolr &= ~(E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
5036
5037 if (*msgbuf & E1000_VF_SET_PROMISC_MULTICAST) {
5038 vmolr |= E1000_VMOLR_MPME;
Alexander Duyckd85b90042010-09-22 17:56:20 +00005039 vf_data->flags |= IGB_VF_FLAG_MULTI_PROMISC;
Alexander Duyck7d5753f2009-10-27 23:47:16 +00005040 *msgbuf &= ~E1000_VF_SET_PROMISC_MULTICAST;
5041 } else {
5042 /*
5043 * if we have hashes and we are clearing a multicast promisc
5044 * flag we need to write the hashes to the MTA as this step
5045 * was previously skipped
5046 */
5047 if (vf_data->num_vf_mc_hashes > 30) {
5048 vmolr |= E1000_VMOLR_MPME;
5049 } else if (vf_data->num_vf_mc_hashes) {
5050 int j;
5051 vmolr |= E1000_VMOLR_ROMPE;
5052 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
5053 igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
5054 }
5055 }
5056
5057 wr32(E1000_VMOLR(vf), vmolr);
5058
5059 /* there are flags left unprocessed, likely not supported */
5060 if (*msgbuf & E1000_VT_MSGINFO_MASK)
5061 return -EINVAL;
5062
5063 return 0;
5064
5065}
5066
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005067static int igb_set_vf_multicasts(struct igb_adapter *adapter,
5068 u32 *msgbuf, u32 vf)
5069{
5070 int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
5071 u16 *hash_list = (u16 *)&msgbuf[1];
5072 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
5073 int i;
5074
Alexander Duyck7d5753f2009-10-27 23:47:16 +00005075 /* salt away the number of multicast addresses assigned
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005076 * to this VF for later use to restore when the PF multi cast
5077 * list changes
5078 */
5079 vf_data->num_vf_mc_hashes = n;
5080
Alexander Duyck7d5753f2009-10-27 23:47:16 +00005081 /* only up to 30 hash values supported */
5082 if (n > 30)
5083 n = 30;
5084
5085 /* store the hashes for later use */
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005086 for (i = 0; i < n; i++)
Joe Perchesa419aef2009-08-18 11:18:35 -07005087 vf_data->vf_mc_hashes[i] = hash_list[i];
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005088
5089 /* Flush and reset the mta with the new values */
Alexander Duyckff41f8d2009-09-03 14:48:56 +00005090 igb_set_rx_mode(adapter->netdev);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005091
5092 return 0;
5093}
5094
5095static void igb_restore_vf_multicasts(struct igb_adapter *adapter)
5096{
5097 struct e1000_hw *hw = &adapter->hw;
5098 struct vf_data_storage *vf_data;
5099 int i, j;
5100
5101 for (i = 0; i < adapter->vfs_allocated_count; i++) {
Alexander Duyck7d5753f2009-10-27 23:47:16 +00005102 u32 vmolr = rd32(E1000_VMOLR(i));
5103 vmolr &= ~(E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
5104
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005105 vf_data = &adapter->vf_data[i];
Alexander Duyck7d5753f2009-10-27 23:47:16 +00005106
5107 if ((vf_data->num_vf_mc_hashes > 30) ||
5108 (vf_data->flags & IGB_VF_FLAG_MULTI_PROMISC)) {
5109 vmolr |= E1000_VMOLR_MPME;
5110 } else if (vf_data->num_vf_mc_hashes) {
5111 vmolr |= E1000_VMOLR_ROMPE;
5112 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
5113 igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
5114 }
5115 wr32(E1000_VMOLR(i), vmolr);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005116 }
5117}
5118
5119static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf)
5120{
5121 struct e1000_hw *hw = &adapter->hw;
5122 u32 pool_mask, reg, vid;
5123 int i;
5124
5125 pool_mask = 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
5126
5127 /* Find the vlan filter for this id */
5128 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
5129 reg = rd32(E1000_VLVF(i));
5130
5131 /* remove the vf from the pool */
5132 reg &= ~pool_mask;
5133
5134 /* if pool is empty then remove entry from vfta */
5135 if (!(reg & E1000_VLVF_POOLSEL_MASK) &&
5136 (reg & E1000_VLVF_VLANID_ENABLE)) {
5137 reg = 0;
5138 vid = reg & E1000_VLVF_VLANID_MASK;
5139 igb_vfta_set(hw, vid, false);
5140 }
5141
5142 wr32(E1000_VLVF(i), reg);
5143 }
Alexander Duyckae641bd2009-09-03 14:49:33 +00005144
5145 adapter->vf_data[vf].vlans_enabled = 0;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005146}
5147
5148static s32 igb_vlvf_set(struct igb_adapter *adapter, u32 vid, bool add, u32 vf)
5149{
5150 struct e1000_hw *hw = &adapter->hw;
5151 u32 reg, i;
5152
Alexander Duyck51466232009-10-27 23:47:35 +00005153 /* The vlvf table only exists on 82576 hardware and newer */
5154 if (hw->mac.type < e1000_82576)
5155 return -1;
5156
5157 /* we only need to do this if VMDq is enabled */
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005158 if (!adapter->vfs_allocated_count)
5159 return -1;
5160
5161 /* Find the vlan filter for this id */
5162 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
5163 reg = rd32(E1000_VLVF(i));
5164 if ((reg & E1000_VLVF_VLANID_ENABLE) &&
5165 vid == (reg & E1000_VLVF_VLANID_MASK))
5166 break;
5167 }
5168
5169 if (add) {
5170 if (i == E1000_VLVF_ARRAY_SIZE) {
5171 /* Did not find a matching VLAN ID entry that was
5172 * enabled. Search for a free filter entry, i.e.
5173 * one without the enable bit set
5174 */
5175 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
5176 reg = rd32(E1000_VLVF(i));
5177 if (!(reg & E1000_VLVF_VLANID_ENABLE))
5178 break;
5179 }
5180 }
5181 if (i < E1000_VLVF_ARRAY_SIZE) {
5182 /* Found an enabled/available entry */
5183 reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
5184
5185 /* if !enabled we need to set this up in vfta */
5186 if (!(reg & E1000_VLVF_VLANID_ENABLE)) {
Alexander Duyck51466232009-10-27 23:47:35 +00005187 /* add VID to filter table */
5188 igb_vfta_set(hw, vid, true);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005189 reg |= E1000_VLVF_VLANID_ENABLE;
5190 }
Alexander Duyckcad6d052009-03-13 20:41:37 +00005191 reg &= ~E1000_VLVF_VLANID_MASK;
5192 reg |= vid;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005193 wr32(E1000_VLVF(i), reg);
Alexander Duyckae641bd2009-09-03 14:49:33 +00005194
5195 /* do not modify RLPML for PF devices */
5196 if (vf >= adapter->vfs_allocated_count)
5197 return 0;
5198
5199 if (!adapter->vf_data[vf].vlans_enabled) {
5200 u32 size;
5201 reg = rd32(E1000_VMOLR(vf));
5202 size = reg & E1000_VMOLR_RLPML_MASK;
5203 size += 4;
5204 reg &= ~E1000_VMOLR_RLPML_MASK;
5205 reg |= size;
5206 wr32(E1000_VMOLR(vf), reg);
5207 }
Alexander Duyckae641bd2009-09-03 14:49:33 +00005208
Alexander Duyck51466232009-10-27 23:47:35 +00005209 adapter->vf_data[vf].vlans_enabled++;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005210 }
5211 } else {
5212 if (i < E1000_VLVF_ARRAY_SIZE) {
5213 /* remove vf from the pool */
5214 reg &= ~(1 << (E1000_VLVF_POOLSEL_SHIFT + vf));
5215 /* if pool is empty then remove entry from vfta */
5216 if (!(reg & E1000_VLVF_POOLSEL_MASK)) {
5217 reg = 0;
5218 igb_vfta_set(hw, vid, false);
5219 }
5220 wr32(E1000_VLVF(i), reg);
Alexander Duyckae641bd2009-09-03 14:49:33 +00005221
5222 /* do not modify RLPML for PF devices */
5223 if (vf >= adapter->vfs_allocated_count)
5224 return 0;
5225
5226 adapter->vf_data[vf].vlans_enabled--;
5227 if (!adapter->vf_data[vf].vlans_enabled) {
5228 u32 size;
5229 reg = rd32(E1000_VMOLR(vf));
5230 size = reg & E1000_VMOLR_RLPML_MASK;
5231 size -= 4;
5232 reg &= ~E1000_VMOLR_RLPML_MASK;
5233 reg |= size;
5234 wr32(E1000_VMOLR(vf), reg);
5235 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005236 }
5237 }
Williams, Mitch A8151d292010-02-10 01:44:24 +00005238 return 0;
5239}
5240
5241static void igb_set_vmvir(struct igb_adapter *adapter, u32 vid, u32 vf)
5242{
5243 struct e1000_hw *hw = &adapter->hw;
5244
5245 if (vid)
5246 wr32(E1000_VMVIR(vf), (vid | E1000_VMVIR_VLANA_DEFAULT));
5247 else
5248 wr32(E1000_VMVIR(vf), 0);
5249}
5250
5251static int igb_ndo_set_vf_vlan(struct net_device *netdev,
5252 int vf, u16 vlan, u8 qos)
5253{
5254 int err = 0;
5255 struct igb_adapter *adapter = netdev_priv(netdev);
5256
5257 if ((vf >= adapter->vfs_allocated_count) || (vlan > 4095) || (qos > 7))
5258 return -EINVAL;
5259 if (vlan || qos) {
5260 err = igb_vlvf_set(adapter, vlan, !!vlan, vf);
5261 if (err)
5262 goto out;
5263 igb_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf);
5264 igb_set_vmolr(adapter, vf, !vlan);
5265 adapter->vf_data[vf].pf_vlan = vlan;
5266 adapter->vf_data[vf].pf_qos = qos;
5267 dev_info(&adapter->pdev->dev,
5268 "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
5269 if (test_bit(__IGB_DOWN, &adapter->state)) {
5270 dev_warn(&adapter->pdev->dev,
5271 "The VF VLAN has been set,"
5272 " but the PF device is not up.\n");
5273 dev_warn(&adapter->pdev->dev,
5274 "Bring the PF device up before"
5275 " attempting to use the VF device.\n");
5276 }
5277 } else {
5278 igb_vlvf_set(adapter, adapter->vf_data[vf].pf_vlan,
5279 false, vf);
5280 igb_set_vmvir(adapter, vlan, vf);
5281 igb_set_vmolr(adapter, vf, true);
5282 adapter->vf_data[vf].pf_vlan = 0;
5283 adapter->vf_data[vf].pf_qos = 0;
5284 }
5285out:
5286 return err;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005287}
5288
5289static int igb_set_vf_vlan(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
5290{
5291 int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
5292 int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
5293
5294 return igb_vlvf_set(adapter, vid, add, vf);
5295}
5296
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005297static inline void igb_vf_reset(struct igb_adapter *adapter, u32 vf)
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005298{
Greg Rose8fa7e0f2010-11-06 05:43:21 +00005299 /* clear flags - except flag that indicates PF has set the MAC */
5300 adapter->vf_data[vf].flags &= IGB_VF_FLAG_PF_SET_MAC;
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005301 adapter->vf_data[vf].last_nack = jiffies;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005302
5303 /* reset offloads to defaults */
Williams, Mitch A8151d292010-02-10 01:44:24 +00005304 igb_set_vmolr(adapter, vf, true);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005305
5306 /* reset vlans for device */
5307 igb_clear_vf_vfta(adapter, vf);
Williams, Mitch A8151d292010-02-10 01:44:24 +00005308 if (adapter->vf_data[vf].pf_vlan)
5309 igb_ndo_set_vf_vlan(adapter->netdev, vf,
5310 adapter->vf_data[vf].pf_vlan,
5311 adapter->vf_data[vf].pf_qos);
5312 else
5313 igb_clear_vf_vfta(adapter, vf);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005314
5315 /* reset multicast table array for vf */
5316 adapter->vf_data[vf].num_vf_mc_hashes = 0;
5317
5318 /* Flush and reset the mta with the new values */
Alexander Duyckff41f8d2009-09-03 14:48:56 +00005319 igb_set_rx_mode(adapter->netdev);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005320}
5321
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005322static void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf)
5323{
5324 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
5325
5326 /* generate a new mac address as we were hotplug removed/added */
Williams, Mitch A8151d292010-02-10 01:44:24 +00005327 if (!(adapter->vf_data[vf].flags & IGB_VF_FLAG_PF_SET_MAC))
Joe Perches7efd26d2012-07-12 19:33:06 +00005328 eth_random_addr(vf_mac);
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005329
5330 /* process remaining reset events */
5331 igb_vf_reset(adapter, vf);
5332}
5333
5334static void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf)
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005335{
5336 struct e1000_hw *hw = &adapter->hw;
5337 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
Alexander Duyckff41f8d2009-09-03 14:48:56 +00005338 int rar_entry = hw->mac.rar_entry_count - (vf + 1);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005339 u32 reg, msgbuf[3];
5340 u8 *addr = (u8 *)(&msgbuf[1]);
5341
5342 /* process all the same items cleared in a function level reset */
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005343 igb_vf_reset(adapter, vf);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005344
5345 /* set vf mac address */
Alexander Duyck26ad9172009-10-05 06:32:49 +00005346 igb_rar_set_qsel(adapter, vf_mac, rar_entry, vf);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005347
5348 /* enable transmit and receive for vf */
5349 reg = rd32(E1000_VFTE);
5350 wr32(E1000_VFTE, reg | (1 << vf));
5351 reg = rd32(E1000_VFRE);
5352 wr32(E1000_VFRE, reg | (1 << vf));
5353
Greg Rose8fa7e0f2010-11-06 05:43:21 +00005354 adapter->vf_data[vf].flags |= IGB_VF_FLAG_CTS;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005355
5356 /* reply to reset with ack and vf mac address */
5357 msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK;
5358 memcpy(addr, vf_mac, 6);
5359 igb_write_mbx(hw, msgbuf, 3, vf);
5360}
5361
5362static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf)
5363{
Greg Rosede42edd2010-07-01 13:39:23 +00005364 /*
5365 * The VF MAC Address is stored in a packed array of bytes
5366 * starting at the second 32 bit word of the msg array
5367 */
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005368 unsigned char *addr = (char *)&msg[1];
5369 int err = -1;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005370
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005371 if (is_valid_ether_addr(addr))
5372 err = igb_set_vf_mac(adapter, vf, addr);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005373
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005374 return err;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005375}
5376
5377static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf)
5378{
5379 struct e1000_hw *hw = &adapter->hw;
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005380 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005381 u32 msg = E1000_VT_MSGTYPE_NACK;
5382
5383 /* if device isn't clear to send it shouldn't be reading either */
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005384 if (!(vf_data->flags & IGB_VF_FLAG_CTS) &&
5385 time_after(jiffies, vf_data->last_nack + (2 * HZ))) {
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005386 igb_write_mbx(hw, &msg, 1, vf);
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005387 vf_data->last_nack = jiffies;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005388 }
5389}
5390
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005391static void igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf)
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005392{
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005393 struct pci_dev *pdev = adapter->pdev;
5394 u32 msgbuf[E1000_VFMAILBOX_SIZE];
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005395 struct e1000_hw *hw = &adapter->hw;
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005396 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005397 s32 retval;
5398
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005399 retval = igb_read_mbx(hw, msgbuf, E1000_VFMAILBOX_SIZE, vf);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005400
Alexander Duyckfef45f42009-12-11 22:57:34 -08005401 if (retval) {
5402 /* if receive failed revoke VF CTS stats and restart init */
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005403 dev_err(&pdev->dev, "Error receiving message from VF\n");
Alexander Duyckfef45f42009-12-11 22:57:34 -08005404 vf_data->flags &= ~IGB_VF_FLAG_CTS;
5405 if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
5406 return;
5407 goto out;
5408 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005409
5410 /* this is a message we already processed, do nothing */
5411 if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK))
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005412 return;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005413
5414 /*
5415 * until the vf completes a reset it should not be
5416 * allowed to start any configuration.
5417 */
5418
5419 if (msgbuf[0] == E1000_VF_RESET) {
5420 igb_vf_reset_msg(adapter, vf);
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005421 return;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005422 }
5423
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005424 if (!(vf_data->flags & IGB_VF_FLAG_CTS)) {
Alexander Duyckfef45f42009-12-11 22:57:34 -08005425 if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
5426 return;
5427 retval = -1;
5428 goto out;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005429 }
5430
5431 switch ((msgbuf[0] & 0xFFFF)) {
5432 case E1000_VF_SET_MAC_ADDR:
Greg Rosea6b5ea32010-11-06 05:42:59 +00005433 retval = -EINVAL;
5434 if (!(vf_data->flags & IGB_VF_FLAG_PF_SET_MAC))
5435 retval = igb_set_vf_mac_addr(adapter, msgbuf, vf);
5436 else
5437 dev_warn(&pdev->dev,
5438 "VF %d attempted to override administratively "
5439 "set MAC address\nReload the VF driver to "
5440 "resume operations\n", vf);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005441 break;
Alexander Duyck7d5753f2009-10-27 23:47:16 +00005442 case E1000_VF_SET_PROMISC:
5443 retval = igb_set_vf_promisc(adapter, msgbuf, vf);
5444 break;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005445 case E1000_VF_SET_MULTICAST:
5446 retval = igb_set_vf_multicasts(adapter, msgbuf, vf);
5447 break;
5448 case E1000_VF_SET_LPE:
5449 retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf);
5450 break;
5451 case E1000_VF_SET_VLAN:
Greg Rosea6b5ea32010-11-06 05:42:59 +00005452 retval = -1;
5453 if (vf_data->pf_vlan)
5454 dev_warn(&pdev->dev,
5455 "VF %d attempted to override administratively "
5456 "set VLAN tag\nReload the VF driver to "
5457 "resume operations\n", vf);
Williams, Mitch A8151d292010-02-10 01:44:24 +00005458 else
5459 retval = igb_set_vf_vlan(adapter, msgbuf, vf);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005460 break;
5461 default:
Alexander Duyck090b1792009-10-27 23:51:55 +00005462 dev_err(&pdev->dev, "Unhandled Msg %08x\n", msgbuf[0]);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005463 retval = -1;
5464 break;
5465 }
5466
Alexander Duyckfef45f42009-12-11 22:57:34 -08005467 msgbuf[0] |= E1000_VT_MSGTYPE_CTS;
5468out:
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005469 /* notify the VF of the results of what it sent us */
5470 if (retval)
5471 msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
5472 else
5473 msgbuf[0] |= E1000_VT_MSGTYPE_ACK;
5474
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005475 igb_write_mbx(hw, msgbuf, 1, vf);
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005476}
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005477
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005478static void igb_msg_task(struct igb_adapter *adapter)
5479{
5480 struct e1000_hw *hw = &adapter->hw;
5481 u32 vf;
5482
5483 for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
5484 /* process any reset requests */
5485 if (!igb_check_for_rst(hw, vf))
5486 igb_vf_reset_event(adapter, vf);
5487
5488 /* process any messages pending */
5489 if (!igb_check_for_msg(hw, vf))
5490 igb_rcv_msg_from_vf(adapter, vf);
5491
5492 /* process any acks */
5493 if (!igb_check_for_ack(hw, vf))
5494 igb_rcv_ack_from_vf(adapter, vf);
5495 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005496}
5497
Auke Kok9d5c8242008-01-24 02:22:38 -08005498/**
Alexander Duyck68d480c2009-10-05 06:33:08 +00005499 * igb_set_uta - Set unicast filter table address
5500 * @adapter: board private structure
5501 *
5502 * The unicast table address is a register array of 32-bit registers.
5503 * The table is meant to be used in a way similar to how the MTA is used
5504 * however due to certain limitations in the hardware it is necessary to
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005505 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
5506 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
Alexander Duyck68d480c2009-10-05 06:33:08 +00005507 **/
5508static void igb_set_uta(struct igb_adapter *adapter)
5509{
5510 struct e1000_hw *hw = &adapter->hw;
5511 int i;
5512
5513 /* The UTA table only exists on 82576 hardware and newer */
5514 if (hw->mac.type < e1000_82576)
5515 return;
5516
5517 /* we only need to do this if VMDq is enabled */
5518 if (!adapter->vfs_allocated_count)
5519 return;
5520
5521 for (i = 0; i < hw->mac.uta_reg_count; i++)
5522 array_wr32(E1000_UTA, i, ~0);
5523}
5524
5525/**
Auke Kok9d5c8242008-01-24 02:22:38 -08005526 * igb_intr_msi - Interrupt Handler
5527 * @irq: interrupt number
5528 * @data: pointer to a network interface device structure
5529 **/
5530static irqreturn_t igb_intr_msi(int irq, void *data)
5531{
Alexander Duyck047e0032009-10-27 15:49:27 +00005532 struct igb_adapter *adapter = data;
5533 struct igb_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9d5c8242008-01-24 02:22:38 -08005534 struct e1000_hw *hw = &adapter->hw;
5535 /* read ICR disables interrupts using IAM */
5536 u32 icr = rd32(E1000_ICR);
5537
Alexander Duyck047e0032009-10-27 15:49:27 +00005538 igb_write_itr(q_vector);
Auke Kok9d5c8242008-01-24 02:22:38 -08005539
Alexander Duyck7f081d42010-01-07 17:41:00 +00005540 if (icr & E1000_ICR_DRSTA)
5541 schedule_work(&adapter->reset_task);
5542
Alexander Duyck047e0032009-10-27 15:49:27 +00005543 if (icr & E1000_ICR_DOUTSYNC) {
Alexander Duyckdda0e082009-02-06 23:19:08 +00005544 /* HW is reporting DMA is out of sync */
5545 adapter->stats.doosync++;
5546 }
5547
Auke Kok9d5c8242008-01-24 02:22:38 -08005548 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
5549 hw->mac.get_link_status = 1;
5550 if (!test_bit(__IGB_DOWN, &adapter->state))
5551 mod_timer(&adapter->watchdog_timer, jiffies + 1);
5552 }
5553
Matthew Vick1f6e8172012-08-18 07:26:33 +00005554 if (icr & E1000_ICR_TS) {
5555 u32 tsicr = rd32(E1000_TSICR);
5556
5557 if (tsicr & E1000_TSICR_TXTS) {
5558 /* acknowledge the interrupt */
5559 wr32(E1000_TSICR, E1000_TSICR_TXTS);
5560 /* retrieve hardware timestamp */
5561 schedule_work(&adapter->ptp_tx_work);
5562 }
5563 }
Matthew Vick1f6e8172012-08-18 07:26:33 +00005564
Alexander Duyck047e0032009-10-27 15:49:27 +00005565 napi_schedule(&q_vector->napi);
Auke Kok9d5c8242008-01-24 02:22:38 -08005566
5567 return IRQ_HANDLED;
5568}
5569
5570/**
Alexander Duyck4a3c6432009-02-06 23:20:49 +00005571 * igb_intr - Legacy Interrupt Handler
Auke Kok9d5c8242008-01-24 02:22:38 -08005572 * @irq: interrupt number
5573 * @data: pointer to a network interface device structure
5574 **/
5575static irqreturn_t igb_intr(int irq, void *data)
5576{
Alexander Duyck047e0032009-10-27 15:49:27 +00005577 struct igb_adapter *adapter = data;
5578 struct igb_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9d5c8242008-01-24 02:22:38 -08005579 struct e1000_hw *hw = &adapter->hw;
5580 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
5581 * need for the IMC write */
5582 u32 icr = rd32(E1000_ICR);
Auke Kok9d5c8242008-01-24 02:22:38 -08005583
5584 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
5585 * not set, then the adapter didn't send an interrupt */
5586 if (!(icr & E1000_ICR_INT_ASSERTED))
5587 return IRQ_NONE;
5588
Alexander Duyck0ba82992011-08-26 07:45:47 +00005589 igb_write_itr(q_vector);
5590
Alexander Duyck7f081d42010-01-07 17:41:00 +00005591 if (icr & E1000_ICR_DRSTA)
5592 schedule_work(&adapter->reset_task);
5593
Alexander Duyck047e0032009-10-27 15:49:27 +00005594 if (icr & E1000_ICR_DOUTSYNC) {
Alexander Duyckdda0e082009-02-06 23:19:08 +00005595 /* HW is reporting DMA is out of sync */
5596 adapter->stats.doosync++;
5597 }
5598
Auke Kok9d5c8242008-01-24 02:22:38 -08005599 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
5600 hw->mac.get_link_status = 1;
5601 /* guard against interrupt when we're going down */
5602 if (!test_bit(__IGB_DOWN, &adapter->state))
5603 mod_timer(&adapter->watchdog_timer, jiffies + 1);
5604 }
5605
Matthew Vick1f6e8172012-08-18 07:26:33 +00005606 if (icr & E1000_ICR_TS) {
5607 u32 tsicr = rd32(E1000_TSICR);
5608
5609 if (tsicr & E1000_TSICR_TXTS) {
5610 /* acknowledge the interrupt */
5611 wr32(E1000_TSICR, E1000_TSICR_TXTS);
5612 /* retrieve hardware timestamp */
5613 schedule_work(&adapter->ptp_tx_work);
5614 }
5615 }
Matthew Vick1f6e8172012-08-18 07:26:33 +00005616
Alexander Duyck047e0032009-10-27 15:49:27 +00005617 napi_schedule(&q_vector->napi);
Auke Kok9d5c8242008-01-24 02:22:38 -08005618
5619 return IRQ_HANDLED;
5620}
5621
Stephen Hemmingerc50b52a2012-01-18 22:13:26 +00005622static void igb_ring_irq_enable(struct igb_q_vector *q_vector)
Alexander Duyck46544252009-02-19 20:39:04 -08005623{
Alexander Duyck047e0032009-10-27 15:49:27 +00005624 struct igb_adapter *adapter = q_vector->adapter;
Alexander Duyck46544252009-02-19 20:39:04 -08005625 struct e1000_hw *hw = &adapter->hw;
5626
Alexander Duyck0ba82992011-08-26 07:45:47 +00005627 if ((q_vector->rx.ring && (adapter->rx_itr_setting & 3)) ||
5628 (!q_vector->rx.ring && (adapter->tx_itr_setting & 3))) {
5629 if ((adapter->num_q_vectors == 1) && !adapter->vf_data)
5630 igb_set_itr(q_vector);
Alexander Duyck46544252009-02-19 20:39:04 -08005631 else
Alexander Duyck047e0032009-10-27 15:49:27 +00005632 igb_update_ring_itr(q_vector);
Alexander Duyck46544252009-02-19 20:39:04 -08005633 }
5634
5635 if (!test_bit(__IGB_DOWN, &adapter->state)) {
5636 if (adapter->msix_entries)
Alexander Duyck047e0032009-10-27 15:49:27 +00005637 wr32(E1000_EIMS, q_vector->eims_value);
Alexander Duyck46544252009-02-19 20:39:04 -08005638 else
5639 igb_irq_enable(adapter);
5640 }
5641}
5642
Auke Kok9d5c8242008-01-24 02:22:38 -08005643/**
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07005644 * igb_poll - NAPI Rx polling callback
5645 * @napi: napi polling structure
5646 * @budget: count of how many packets we should handle
Auke Kok9d5c8242008-01-24 02:22:38 -08005647 **/
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07005648static int igb_poll(struct napi_struct *napi, int budget)
Auke Kok9d5c8242008-01-24 02:22:38 -08005649{
Alexander Duyck047e0032009-10-27 15:49:27 +00005650 struct igb_q_vector *q_vector = container_of(napi,
5651 struct igb_q_vector,
5652 napi);
Alexander Duyck16eb8812011-08-26 07:43:54 +00005653 bool clean_complete = true;
Auke Kok9d5c8242008-01-24 02:22:38 -08005654
Jeff Kirsher421e02f2008-10-17 11:08:31 -07005655#ifdef CONFIG_IGB_DCA
Alexander Duyck047e0032009-10-27 15:49:27 +00005656 if (q_vector->adapter->flags & IGB_FLAG_DCA_ENABLED)
5657 igb_update_dca(q_vector);
Jeb Cramerfe4506b2008-07-08 15:07:55 -07005658#endif
Alexander Duyck0ba82992011-08-26 07:45:47 +00005659 if (q_vector->tx.ring)
Alexander Duyck13fde972011-10-05 13:35:24 +00005660 clean_complete = igb_clean_tx_irq(q_vector);
Auke Kok9d5c8242008-01-24 02:22:38 -08005661
Alexander Duyck0ba82992011-08-26 07:45:47 +00005662 if (q_vector->rx.ring)
Alexander Duyckcd392f52011-08-26 07:43:59 +00005663 clean_complete &= igb_clean_rx_irq(q_vector, budget);
Alexander Duyck047e0032009-10-27 15:49:27 +00005664
Alexander Duyck16eb8812011-08-26 07:43:54 +00005665 /* If all work not completed, return budget and keep polling */
5666 if (!clean_complete)
5667 return budget;
Auke Kok9d5c8242008-01-24 02:22:38 -08005668
Alexander Duyck46544252009-02-19 20:39:04 -08005669 /* If not enough Rx work done, exit the polling mode */
Alexander Duyck16eb8812011-08-26 07:43:54 +00005670 napi_complete(napi);
5671 igb_ring_irq_enable(q_vector);
Alexander Duyck46544252009-02-19 20:39:04 -08005672
Alexander Duyck16eb8812011-08-26 07:43:54 +00005673 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08005674}
Al Viro6d8126f2008-03-16 22:23:24 +00005675
Patrick Ohly33af6bc2009-02-12 05:03:43 +00005676/**
Auke Kok9d5c8242008-01-24 02:22:38 -08005677 * igb_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyck047e0032009-10-27 15:49:27 +00005678 * @q_vector: pointer to q_vector containing needed info
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005679 *
Auke Kok9d5c8242008-01-24 02:22:38 -08005680 * returns true if ring is completely cleaned
5681 **/
Alexander Duyck047e0032009-10-27 15:49:27 +00005682static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)
Auke Kok9d5c8242008-01-24 02:22:38 -08005683{
Alexander Duyck047e0032009-10-27 15:49:27 +00005684 struct igb_adapter *adapter = q_vector->adapter;
Alexander Duyck0ba82992011-08-26 07:45:47 +00005685 struct igb_ring *tx_ring = q_vector->tx.ring;
Alexander Duyck06034642011-08-26 07:44:22 +00005686 struct igb_tx_buffer *tx_buffer;
Alexander Duyckf4128782012-09-13 06:28:01 +00005687 union e1000_adv_tx_desc *tx_desc;
Auke Kok9d5c8242008-01-24 02:22:38 -08005688 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck0ba82992011-08-26 07:45:47 +00005689 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck8542db02011-08-26 07:44:43 +00005690 unsigned int i = tx_ring->next_to_clean;
Auke Kok9d5c8242008-01-24 02:22:38 -08005691
Alexander Duyck13fde972011-10-05 13:35:24 +00005692 if (test_bit(__IGB_DOWN, &adapter->state))
5693 return true;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08005694
Alexander Duyck06034642011-08-26 07:44:22 +00005695 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duyck13fde972011-10-05 13:35:24 +00005696 tx_desc = IGB_TX_DESC(tx_ring, i);
Alexander Duyck8542db02011-08-26 07:44:43 +00005697 i -= tx_ring->count;
Auke Kok9d5c8242008-01-24 02:22:38 -08005698
Alexander Duyckf4128782012-09-13 06:28:01 +00005699 do {
5700 union e1000_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Alexander Duyck8542db02011-08-26 07:44:43 +00005701
5702 /* if next_to_watch is not set then there is no work pending */
5703 if (!eop_desc)
5704 break;
Alexander Duyck13fde972011-10-05 13:35:24 +00005705
Alexander Duyckf4128782012-09-13 06:28:01 +00005706 /* prevent any other reads prior to eop_desc */
5707 rmb();
5708
Alexander Duyck13fde972011-10-05 13:35:24 +00005709 /* if DD is not set pending work has not been completed */
5710 if (!(eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)))
5711 break;
5712
Alexander Duyck8542db02011-08-26 07:44:43 +00005713 /* clear next_to_watch to prevent false hangs */
5714 tx_buffer->next_to_watch = NULL;
Alexander Duyck13fde972011-10-05 13:35:24 +00005715
Alexander Duyckebe42d12011-08-26 07:45:09 +00005716 /* update the statistics for this packet */
5717 total_bytes += tx_buffer->bytecount;
5718 total_packets += tx_buffer->gso_segs;
Alexander Duyck13fde972011-10-05 13:35:24 +00005719
Alexander Duyckebe42d12011-08-26 07:45:09 +00005720 /* free the skb */
5721 dev_kfree_skb_any(tx_buffer->skb);
Alexander Duyckebe42d12011-08-26 07:45:09 +00005722
5723 /* unmap skb header data */
5724 dma_unmap_single(tx_ring->dev,
Alexander Duyckc9f14bf32012-09-18 01:56:27 +00005725 dma_unmap_addr(tx_buffer, dma),
5726 dma_unmap_len(tx_buffer, len),
Alexander Duyckebe42d12011-08-26 07:45:09 +00005727 DMA_TO_DEVICE);
5728
Alexander Duyckc9f14bf32012-09-18 01:56:27 +00005729 /* clear tx_buffer data */
5730 tx_buffer->skb = NULL;
5731 dma_unmap_len_set(tx_buffer, len, 0);
5732
Alexander Duyckebe42d12011-08-26 07:45:09 +00005733 /* clear last DMA location and unmap remaining buffers */
5734 while (tx_desc != eop_desc) {
Alexander Duyck13fde972011-10-05 13:35:24 +00005735 tx_buffer++;
5736 tx_desc++;
Auke Kok9d5c8242008-01-24 02:22:38 -08005737 i++;
Alexander Duyck8542db02011-08-26 07:44:43 +00005738 if (unlikely(!i)) {
5739 i -= tx_ring->count;
Alexander Duyck06034642011-08-26 07:44:22 +00005740 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duyck13fde972011-10-05 13:35:24 +00005741 tx_desc = IGB_TX_DESC(tx_ring, 0);
5742 }
Alexander Duyckebe42d12011-08-26 07:45:09 +00005743
5744 /* unmap any remaining paged data */
Alexander Duyckc9f14bf32012-09-18 01:56:27 +00005745 if (dma_unmap_len(tx_buffer, len)) {
Alexander Duyckebe42d12011-08-26 07:45:09 +00005746 dma_unmap_page(tx_ring->dev,
Alexander Duyckc9f14bf32012-09-18 01:56:27 +00005747 dma_unmap_addr(tx_buffer, dma),
5748 dma_unmap_len(tx_buffer, len),
Alexander Duyckebe42d12011-08-26 07:45:09 +00005749 DMA_TO_DEVICE);
Alexander Duyckc9f14bf32012-09-18 01:56:27 +00005750 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckebe42d12011-08-26 07:45:09 +00005751 }
5752 }
5753
Alexander Duyckebe42d12011-08-26 07:45:09 +00005754 /* move us one more past the eop_desc for start of next pkt */
5755 tx_buffer++;
5756 tx_desc++;
5757 i++;
5758 if (unlikely(!i)) {
5759 i -= tx_ring->count;
5760 tx_buffer = tx_ring->tx_buffer_info;
5761 tx_desc = IGB_TX_DESC(tx_ring, 0);
5762 }
Alexander Duyckf4128782012-09-13 06:28:01 +00005763
5764 /* issue prefetch for next Tx descriptor */
5765 prefetch(tx_desc);
5766
5767 /* update budget accounting */
5768 budget--;
5769 } while (likely(budget));
Alexander Duyck0e014cb2008-12-26 01:33:18 -08005770
Eric Dumazetbdbc0632012-01-04 20:23:36 +00005771 netdev_tx_completed_queue(txring_txq(tx_ring),
5772 total_packets, total_bytes);
Alexander Duyck8542db02011-08-26 07:44:43 +00005773 i += tx_ring->count;
Auke Kok9d5c8242008-01-24 02:22:38 -08005774 tx_ring->next_to_clean = i;
Alexander Duyck13fde972011-10-05 13:35:24 +00005775 u64_stats_update_begin(&tx_ring->tx_syncp);
5776 tx_ring->tx_stats.bytes += total_bytes;
5777 tx_ring->tx_stats.packets += total_packets;
5778 u64_stats_update_end(&tx_ring->tx_syncp);
Alexander Duyck0ba82992011-08-26 07:45:47 +00005779 q_vector->tx.total_bytes += total_bytes;
5780 q_vector->tx.total_packets += total_packets;
Auke Kok9d5c8242008-01-24 02:22:38 -08005781
Alexander Duyck6d095fa2011-08-26 07:46:19 +00005782 if (test_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags)) {
Alexander Duyck13fde972011-10-05 13:35:24 +00005783 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck13fde972011-10-05 13:35:24 +00005784
Auke Kok9d5c8242008-01-24 02:22:38 -08005785 /* Detect a transmit hang in hardware, this serializes the
5786 * check with the clearing of time_stamp and movement of i */
Alexander Duyck6d095fa2011-08-26 07:46:19 +00005787 clear_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
Alexander Duyckf4128782012-09-13 06:28:01 +00005788 if (tx_buffer->next_to_watch &&
Alexander Duyck8542db02011-08-26 07:44:43 +00005789 time_after(jiffies, tx_buffer->time_stamp +
Joe Perches8e95a202009-12-03 07:58:21 +00005790 (adapter->tx_timeout_factor * HZ)) &&
5791 !(rd32(E1000_STATUS) & E1000_STATUS_TXOFF)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08005792
Auke Kok9d5c8242008-01-24 02:22:38 -08005793 /* detected Tx unit hang */
Alexander Duyck59d71982010-04-27 13:09:25 +00005794 dev_err(tx_ring->dev,
Auke Kok9d5c8242008-01-24 02:22:38 -08005795 "Detected Tx Unit Hang\n"
Alexander Duyck2d064c02008-07-08 15:10:12 -07005796 " Tx Queue <%d>\n"
Auke Kok9d5c8242008-01-24 02:22:38 -08005797 " TDH <%x>\n"
5798 " TDT <%x>\n"
5799 " next_to_use <%x>\n"
5800 " next_to_clean <%x>\n"
Auke Kok9d5c8242008-01-24 02:22:38 -08005801 "buffer_info[next_to_clean]\n"
5802 " time_stamp <%lx>\n"
Alexander Duyck8542db02011-08-26 07:44:43 +00005803 " next_to_watch <%p>\n"
Auke Kok9d5c8242008-01-24 02:22:38 -08005804 " jiffies <%lx>\n"
5805 " desc.status <%x>\n",
Alexander Duyck2d064c02008-07-08 15:10:12 -07005806 tx_ring->queue_index,
Alexander Duyck238ac812011-08-26 07:43:48 +00005807 rd32(E1000_TDH(tx_ring->reg_idx)),
Alexander Duyckfce99e32009-10-27 15:51:27 +00005808 readl(tx_ring->tail),
Auke Kok9d5c8242008-01-24 02:22:38 -08005809 tx_ring->next_to_use,
5810 tx_ring->next_to_clean,
Alexander Duyck8542db02011-08-26 07:44:43 +00005811 tx_buffer->time_stamp,
Alexander Duyckf4128782012-09-13 06:28:01 +00005812 tx_buffer->next_to_watch,
Auke Kok9d5c8242008-01-24 02:22:38 -08005813 jiffies,
Alexander Duyckf4128782012-09-13 06:28:01 +00005814 tx_buffer->next_to_watch->wb.status);
Alexander Duyck13fde972011-10-05 13:35:24 +00005815 netif_stop_subqueue(tx_ring->netdev,
5816 tx_ring->queue_index);
5817
5818 /* we are about to reset, no point in enabling stuff */
5819 return true;
Auke Kok9d5c8242008-01-24 02:22:38 -08005820 }
5821 }
Alexander Duyck13fde972011-10-05 13:35:24 +00005822
5823 if (unlikely(total_packets &&
5824 netif_carrier_ok(tx_ring->netdev) &&
5825 igb_desc_unused(tx_ring) >= IGB_TX_QUEUE_WAKE)) {
5826 /* Make sure that anybody stopping the queue after this
5827 * sees the new next_to_clean.
5828 */
5829 smp_mb();
5830 if (__netif_subqueue_stopped(tx_ring->netdev,
5831 tx_ring->queue_index) &&
5832 !(test_bit(__IGB_DOWN, &adapter->state))) {
5833 netif_wake_subqueue(tx_ring->netdev,
5834 tx_ring->queue_index);
5835
5836 u64_stats_update_begin(&tx_ring->tx_syncp);
5837 tx_ring->tx_stats.restart_queue++;
5838 u64_stats_update_end(&tx_ring->tx_syncp);
5839 }
5840 }
5841
5842 return !!budget;
Auke Kok9d5c8242008-01-24 02:22:38 -08005843}
5844
Alexander Duyckcbc8e552012-09-25 00:31:02 +00005845/**
5846 * igb_reuse_rx_page - page flip buffer and store it back on the ring
5847 * @rx_ring: rx descriptor ring to store buffers on
5848 * @old_buff: donor buffer to have page reused
5849 *
5850 * Synchronizes page for reuse by the adapter
5851 **/
5852static void igb_reuse_rx_page(struct igb_ring *rx_ring,
5853 struct igb_rx_buffer *old_buff)
5854{
5855 struct igb_rx_buffer *new_buff;
5856 u16 nta = rx_ring->next_to_alloc;
5857
5858 new_buff = &rx_ring->rx_buffer_info[nta];
5859
5860 /* update, and store next to alloc */
5861 nta++;
5862 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
5863
5864 /* transfer page from old buffer to new buffer */
5865 memcpy(new_buff, old_buff, sizeof(struct igb_rx_buffer));
5866
5867 /* sync the buffer for use by the device */
5868 dma_sync_single_range_for_device(rx_ring->dev, old_buff->dma,
5869 old_buff->page_offset,
Alexander Duyckde78d1f2012-09-25 00:31:12 +00005870 IGB_RX_BUFSZ,
Alexander Duyckcbc8e552012-09-25 00:31:02 +00005871 DMA_FROM_DEVICE);
5872}
5873
5874/**
5875 * igb_add_rx_frag - Add contents of Rx buffer to sk_buff
5876 * @rx_ring: rx descriptor ring to transact packets on
5877 * @rx_buffer: buffer containing page to add
5878 * @rx_desc: descriptor containing length of buffer written by hardware
5879 * @skb: sk_buff to place the data into
5880 *
5881 * This function will add the data contained in rx_buffer->page to the skb.
5882 * This is done either through a direct copy if the data in the buffer is
5883 * less than the skb header size, otherwise it will just attach the page as
5884 * a frag to the skb.
5885 *
5886 * The function will then update the page offset if necessary and return
5887 * true if the buffer can be reused by the adapter.
5888 **/
5889static bool igb_add_rx_frag(struct igb_ring *rx_ring,
5890 struct igb_rx_buffer *rx_buffer,
5891 union e1000_adv_rx_desc *rx_desc,
5892 struct sk_buff *skb)
5893{
5894 struct page *page = rx_buffer->page;
5895 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
5896
5897 if ((size <= IGB_RX_HDR_LEN) && !skb_is_nonlinear(skb)) {
5898 unsigned char *va = page_address(page) + rx_buffer->page_offset;
5899
Alexander Duyckcbc8e552012-09-25 00:31:02 +00005900 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
5901 igb_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
5902 va += IGB_TS_HDR_LEN;
5903 size -= IGB_TS_HDR_LEN;
5904 }
5905
Alexander Duyckcbc8e552012-09-25 00:31:02 +00005906 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
5907
5908 /* we can reuse buffer as-is, just make sure it is local */
5909 if (likely(page_to_nid(page) == numa_node_id()))
5910 return true;
5911
5912 /* this page cannot be reused so discard it */
5913 put_page(page);
5914 return false;
5915 }
5916
5917 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
Alexander Duyckde78d1f2012-09-25 00:31:12 +00005918 rx_buffer->page_offset, size, IGB_RX_BUFSZ);
Alexander Duyckcbc8e552012-09-25 00:31:02 +00005919
5920 /* avoid re-using remote pages */
5921 if (unlikely(page_to_nid(page) != numa_node_id()))
5922 return false;
5923
Alexander Duyckde78d1f2012-09-25 00:31:12 +00005924#if (PAGE_SIZE < 8192)
Alexander Duyckcbc8e552012-09-25 00:31:02 +00005925 /* if we are only owner of page we can reuse it */
5926 if (unlikely(page_count(page) != 1))
5927 return false;
5928
5929 /* flip page offset to other buffer */
Alexander Duyckde78d1f2012-09-25 00:31:12 +00005930 rx_buffer->page_offset ^= IGB_RX_BUFSZ;
Alexander Duyckcbc8e552012-09-25 00:31:02 +00005931
5932 /*
5933 * since we are the only owner of the page and we need to
5934 * increment it, just set the value to 2 in order to avoid
5935 * an unnecessary locked operation
5936 */
5937 atomic_set(&page->_count, 2);
Alexander Duyckde78d1f2012-09-25 00:31:12 +00005938#else
5939 /* move offset up to the next cache line */
5940 rx_buffer->page_offset += SKB_DATA_ALIGN(size);
5941
5942 if (rx_buffer->page_offset > (PAGE_SIZE - IGB_RX_BUFSZ))
5943 return false;
5944
5945 /* bump ref count on page before it is given to the stack */
5946 get_page(page);
5947#endif
Alexander Duyckcbc8e552012-09-25 00:31:02 +00005948
5949 return true;
5950}
5951
Alexander Duyck2e334ee2012-09-25 00:31:07 +00005952static struct sk_buff *igb_fetch_rx_buffer(struct igb_ring *rx_ring,
5953 union e1000_adv_rx_desc *rx_desc,
5954 struct sk_buff *skb)
5955{
5956 struct igb_rx_buffer *rx_buffer;
5957 struct page *page;
5958
5959 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
5960
5961 /*
5962 * This memory barrier is needed to keep us from reading
5963 * any other fields out of the rx_desc until we know the
5964 * RXD_STAT_DD bit is set
5965 */
5966 rmb();
5967
5968 page = rx_buffer->page;
5969 prefetchw(page);
5970
5971 if (likely(!skb)) {
5972 void *page_addr = page_address(page) +
5973 rx_buffer->page_offset;
5974
5975 /* prefetch first cache line of first page */
5976 prefetch(page_addr);
5977#if L1_CACHE_BYTES < 128
5978 prefetch(page_addr + L1_CACHE_BYTES);
5979#endif
5980
5981 /* allocate a skb to store the frags */
5982 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
5983 IGB_RX_HDR_LEN);
5984 if (unlikely(!skb)) {
5985 rx_ring->rx_stats.alloc_failed++;
5986 return NULL;
5987 }
5988
5989 /*
5990 * we will be copying header into skb->data in
5991 * pskb_may_pull so it is in our interest to prefetch
5992 * it now to avoid a possible cache miss
5993 */
5994 prefetchw(skb->data);
5995 }
5996
5997 /* we are reusing so sync this buffer for CPU use */
5998 dma_sync_single_range_for_cpu(rx_ring->dev,
5999 rx_buffer->dma,
6000 rx_buffer->page_offset,
Alexander Duyckde78d1f2012-09-25 00:31:12 +00006001 IGB_RX_BUFSZ,
Alexander Duyck2e334ee2012-09-25 00:31:07 +00006002 DMA_FROM_DEVICE);
6003
6004 /* pull page into skb */
6005 if (igb_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
6006 /* hand second half of page back to the ring */
6007 igb_reuse_rx_page(rx_ring, rx_buffer);
6008 } else {
6009 /* we are not reusing the buffer so unmap it */
6010 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
6011 PAGE_SIZE, DMA_FROM_DEVICE);
6012 }
6013
6014 /* clear contents of rx_buffer */
6015 rx_buffer->page = NULL;
6016
6017 return skb;
6018}
6019
Alexander Duyckcd392f52011-08-26 07:43:59 +00006020static inline void igb_rx_checksum(struct igb_ring *ring,
Alexander Duyck3ceb90f2011-08-26 07:46:03 +00006021 union e1000_adv_rx_desc *rx_desc,
6022 struct sk_buff *skb)
Auke Kok9d5c8242008-01-24 02:22:38 -08006023{
Eric Dumazetbc8acf22010-09-02 13:07:41 -07006024 skb_checksum_none_assert(skb);
Auke Kok9d5c8242008-01-24 02:22:38 -08006025
Alexander Duyck294e7d72011-08-26 07:45:57 +00006026 /* Ignore Checksum bit is set */
Alexander Duyck3ceb90f2011-08-26 07:46:03 +00006027 if (igb_test_staterr(rx_desc, E1000_RXD_STAT_IXSM))
Alexander Duyck294e7d72011-08-26 07:45:57 +00006028 return;
6029
6030 /* Rx checksum disabled via ethtool */
6031 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9d5c8242008-01-24 02:22:38 -08006032 return;
Alexander Duyck85ad76b2009-10-27 15:52:46 +00006033
Auke Kok9d5c8242008-01-24 02:22:38 -08006034 /* TCP/UDP checksum error bit is set */
Alexander Duyck3ceb90f2011-08-26 07:46:03 +00006035 if (igb_test_staterr(rx_desc,
6036 E1000_RXDEXT_STATERR_TCPE |
6037 E1000_RXDEXT_STATERR_IPE)) {
Jesse Brandeburgb9473562009-04-27 22:36:13 +00006038 /*
6039 * work around errata with sctp packets where the TCPE aka
6040 * L4E bit is set incorrectly on 64 byte (60 byte w/o crc)
6041 * packets, (aka let the stack check the crc32c)
6042 */
Alexander Duyck866cff02011-08-26 07:45:36 +00006043 if (!((skb->len == 60) &&
6044 test_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags))) {
Eric Dumazet12dcd862010-10-15 17:27:10 +00006045 u64_stats_update_begin(&ring->rx_syncp);
Alexander Duyck04a5fcaa2009-10-27 15:52:27 +00006046 ring->rx_stats.csum_err++;
Eric Dumazet12dcd862010-10-15 17:27:10 +00006047 u64_stats_update_end(&ring->rx_syncp);
6048 }
Auke Kok9d5c8242008-01-24 02:22:38 -08006049 /* let the stack verify checksum errors */
Auke Kok9d5c8242008-01-24 02:22:38 -08006050 return;
6051 }
6052 /* It must be a TCP or UDP packet with a valid checksum */
Alexander Duyck3ceb90f2011-08-26 07:46:03 +00006053 if (igb_test_staterr(rx_desc, E1000_RXD_STAT_TCPCS |
6054 E1000_RXD_STAT_UDPCS))
Auke Kok9d5c8242008-01-24 02:22:38 -08006055 skb->ip_summed = CHECKSUM_UNNECESSARY;
6056
Alexander Duyck3ceb90f2011-08-26 07:46:03 +00006057 dev_dbg(ring->dev, "cksum success: bits %08X\n",
6058 le32_to_cpu(rx_desc->wb.upper.status_error));
Auke Kok9d5c8242008-01-24 02:22:38 -08006059}
6060
Alexander Duyck077887c2011-08-26 07:46:29 +00006061static inline void igb_rx_hash(struct igb_ring *ring,
6062 union e1000_adv_rx_desc *rx_desc,
6063 struct sk_buff *skb)
6064{
6065 if (ring->netdev->features & NETIF_F_RXHASH)
6066 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
6067}
6068
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006069/**
Alexander Duyck2e334ee2012-09-25 00:31:07 +00006070 * igb_is_non_eop - process handling of non-EOP buffers
6071 * @rx_ring: Rx ring being processed
6072 * @rx_desc: Rx descriptor for current buffer
6073 * @skb: current socket buffer containing buffer in progress
6074 *
6075 * This function updates next to clean. If the buffer is an EOP buffer
6076 * this function exits returning false, otherwise it will place the
6077 * sk_buff in the next buffer to be chained and return true indicating
6078 * that this is in fact a non-EOP buffer.
6079 **/
6080static bool igb_is_non_eop(struct igb_ring *rx_ring,
6081 union e1000_adv_rx_desc *rx_desc)
6082{
6083 u32 ntc = rx_ring->next_to_clean + 1;
6084
6085 /* fetch, update, and store next to clean */
6086 ntc = (ntc < rx_ring->count) ? ntc : 0;
6087 rx_ring->next_to_clean = ntc;
6088
6089 prefetch(IGB_RX_DESC(rx_ring, ntc));
6090
6091 if (likely(igb_test_staterr(rx_desc, E1000_RXD_STAT_EOP)))
6092 return false;
6093
6094 return true;
6095}
6096
6097/**
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006098 * igb_get_headlen - determine size of header for LRO/GRO
6099 * @data: pointer to the start of the headers
6100 * @max_len: total length of section to find headers in
6101 *
6102 * This function is meant to determine the length of headers that will
6103 * be recognized by hardware for LRO, and GRO offloads. The main
6104 * motivation of doing this is to only perform one pull for IPv4 TCP
6105 * packets so that we can do basic things like calculating the gso_size
6106 * based on the average data per packet.
6107 **/
6108static unsigned int igb_get_headlen(unsigned char *data,
6109 unsigned int max_len)
Alexander Duyck2d94d8a2009-07-23 18:10:06 +00006110{
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006111 union {
6112 unsigned char *network;
6113 /* l2 headers */
6114 struct ethhdr *eth;
6115 struct vlan_hdr *vlan;
6116 /* l3 headers */
6117 struct iphdr *ipv4;
6118 struct ipv6hdr *ipv6;
6119 } hdr;
6120 __be16 protocol;
6121 u8 nexthdr = 0; /* default to not TCP */
6122 u8 hlen;
6123
6124 /* this should never happen, but better safe than sorry */
6125 if (max_len < ETH_HLEN)
6126 return max_len;
6127
6128 /* initialize network frame pointer */
6129 hdr.network = data;
6130
6131 /* set first protocol and move network header forward */
6132 protocol = hdr.eth->h_proto;
6133 hdr.network += ETH_HLEN;
6134
6135 /* handle any vlan tag if present */
6136 if (protocol == __constant_htons(ETH_P_8021Q)) {
6137 if ((hdr.network - data) > (max_len - VLAN_HLEN))
6138 return max_len;
6139
6140 protocol = hdr.vlan->h_vlan_encapsulated_proto;
6141 hdr.network += VLAN_HLEN;
6142 }
6143
6144 /* handle L3 protocols */
6145 if (protocol == __constant_htons(ETH_P_IP)) {
6146 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
6147 return max_len;
6148
6149 /* access ihl as a u8 to avoid unaligned access on ia64 */
6150 hlen = (hdr.network[0] & 0x0F) << 2;
6151
6152 /* verify hlen meets minimum size requirements */
6153 if (hlen < sizeof(struct iphdr))
6154 return hdr.network - data;
6155
Alexander Duyckf2fb4ab2012-11-13 01:13:38 +00006156 /* record next protocol if header is present */
6157 if (!hdr.ipv4->frag_off)
6158 nexthdr = hdr.ipv4->protocol;
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006159 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
6160 if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
6161 return max_len;
6162
6163 /* record next protocol */
6164 nexthdr = hdr.ipv6->nexthdr;
Alexander Duyckf2fb4ab2012-11-13 01:13:38 +00006165 hlen = sizeof(struct ipv6hdr);
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006166 } else {
6167 return hdr.network - data;
6168 }
6169
Alexander Duyckf2fb4ab2012-11-13 01:13:38 +00006170 /* relocate pointer to start of L4 header */
6171 hdr.network += hlen;
6172
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006173 /* finally sort out TCP */
6174 if (nexthdr == IPPROTO_TCP) {
6175 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
6176 return max_len;
6177
6178 /* access doff as a u8 to avoid unaligned access on ia64 */
6179 hlen = (hdr.network[12] & 0xF0) >> 2;
6180
6181 /* verify hlen meets minimum size requirements */
6182 if (hlen < sizeof(struct tcphdr))
6183 return hdr.network - data;
6184
6185 hdr.network += hlen;
6186 } else if (nexthdr == IPPROTO_UDP) {
6187 if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
6188 return max_len;
6189
6190 hdr.network += sizeof(struct udphdr);
6191 }
6192
6193 /*
6194 * If everything has gone correctly hdr.network should be the
6195 * data section of the packet and will be the end of the header.
6196 * If not then it probably represents the end of the last recognized
6197 * header.
Alexander Duyck2d94d8a2009-07-23 18:10:06 +00006198 */
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006199 if ((hdr.network - data) < max_len)
6200 return hdr.network - data;
6201 else
6202 return max_len;
6203}
6204
6205/**
6206 * igb_pull_tail - igb specific version of skb_pull_tail
6207 * @rx_ring: rx descriptor ring packet is being transacted on
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006208 * @rx_desc: pointer to the EOP Rx descriptor
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006209 * @skb: pointer to current skb being adjusted
6210 *
6211 * This function is an igb specific version of __pskb_pull_tail. The
6212 * main difference between this version and the original function is that
6213 * this function can make several assumptions about the state of things
6214 * that allow for significant optimizations versus the standard function.
6215 * As a result we can do things like drop a frag and maintain an accurate
6216 * truesize for the skb.
6217 */
6218static void igb_pull_tail(struct igb_ring *rx_ring,
6219 union e1000_adv_rx_desc *rx_desc,
6220 struct sk_buff *skb)
6221{
6222 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
6223 unsigned char *va;
6224 unsigned int pull_len;
6225
6226 /*
6227 * it is valid to use page_address instead of kmap since we are
6228 * working with pages allocated out of the lomem pool per
6229 * alloc_page(GFP_ATOMIC)
6230 */
6231 va = skb_frag_address(frag);
6232
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006233 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
6234 /* retrieve timestamp from buffer */
6235 igb_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
6236
6237 /* update pointers to remove timestamp header */
6238 skb_frag_size_sub(frag, IGB_TS_HDR_LEN);
6239 frag->page_offset += IGB_TS_HDR_LEN;
6240 skb->data_len -= IGB_TS_HDR_LEN;
6241 skb->len -= IGB_TS_HDR_LEN;
6242
6243 /* move va to start of packet data */
6244 va += IGB_TS_HDR_LEN;
6245 }
6246
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006247 /*
6248 * we need the header to contain the greater of either ETH_HLEN or
6249 * 60 bytes if the skb->len is less than 60 for skb_pad.
6250 */
6251 pull_len = igb_get_headlen(va, IGB_RX_HDR_LEN);
6252
6253 /* align pull length to size of long to optimize memcpy performance */
6254 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
6255
6256 /* update all of the pointers */
6257 skb_frag_size_sub(frag, pull_len);
6258 frag->page_offset += pull_len;
6259 skb->data_len -= pull_len;
6260 skb->tail += pull_len;
6261}
6262
6263/**
6264 * igb_cleanup_headers - Correct corrupted or empty headers
6265 * @rx_ring: rx descriptor ring packet is being transacted on
6266 * @rx_desc: pointer to the EOP Rx descriptor
6267 * @skb: pointer to current skb being fixed
6268 *
6269 * Address the case where we are pulling data in on pages only
6270 * and as such no data is present in the skb header.
6271 *
6272 * In addition if skb is not at least 60 bytes we need to pad it so that
6273 * it is large enough to qualify as a valid Ethernet frame.
6274 *
6275 * Returns true if an error was encountered and skb was freed.
6276 **/
6277static bool igb_cleanup_headers(struct igb_ring *rx_ring,
6278 union e1000_adv_rx_desc *rx_desc,
6279 struct sk_buff *skb)
6280{
6281
6282 if (unlikely((igb_test_staterr(rx_desc,
6283 E1000_RXDEXT_ERR_FRAME_ERR_MASK)))) {
6284 struct net_device *netdev = rx_ring->netdev;
6285 if (!(netdev->features & NETIF_F_RXALL)) {
6286 dev_kfree_skb_any(skb);
6287 return true;
6288 }
6289 }
6290
6291 /* place header in linear portion of buffer */
6292 if (skb_is_nonlinear(skb))
6293 igb_pull_tail(rx_ring, rx_desc, skb);
6294
6295 /* if skb_pad returns an error the skb was freed */
6296 if (unlikely(skb->len < 60)) {
6297 int pad_len = 60 - skb->len;
6298
6299 if (skb_pad(skb, pad_len))
6300 return true;
6301 __skb_put(skb, pad_len);
6302 }
6303
6304 return false;
Alexander Duyck2d94d8a2009-07-23 18:10:06 +00006305}
6306
Alexander Duyckdb2ee5b2012-09-25 00:30:57 +00006307/**
6308 * igb_process_skb_fields - Populate skb header fields from Rx descriptor
6309 * @rx_ring: rx descriptor ring packet is being transacted on
6310 * @rx_desc: pointer to the EOP Rx descriptor
6311 * @skb: pointer to current skb being populated
6312 *
6313 * This function checks the ring, descriptor, and packet information in
6314 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
6315 * other fields within the skb.
6316 **/
6317static void igb_process_skb_fields(struct igb_ring *rx_ring,
6318 union e1000_adv_rx_desc *rx_desc,
6319 struct sk_buff *skb)
6320{
6321 struct net_device *dev = rx_ring->netdev;
6322
6323 igb_rx_hash(rx_ring, rx_desc, skb);
6324
6325 igb_rx_checksum(rx_ring, rx_desc, skb);
6326
Alexander Duyckdb2ee5b2012-09-25 00:30:57 +00006327 igb_ptp_rx_hwtstamp(rx_ring->q_vector, rx_desc, skb);
Alexander Duyckdb2ee5b2012-09-25 00:30:57 +00006328
6329 if ((dev->features & NETIF_F_HW_VLAN_RX) &&
6330 igb_test_staterr(rx_desc, E1000_RXD_STAT_VP)) {
6331 u16 vid;
6332 if (igb_test_staterr(rx_desc, E1000_RXDEXT_STATERR_LB) &&
6333 test_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &rx_ring->flags))
6334 vid = be16_to_cpu(rx_desc->wb.upper.vlan);
6335 else
6336 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
6337
6338 __vlan_hwaccel_put_tag(skb, vid);
6339 }
6340
6341 skb_record_rx_queue(skb, rx_ring->queue_index);
6342
6343 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
6344}
6345
Alexander Duyck2e334ee2012-09-25 00:31:07 +00006346static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)
Auke Kok9d5c8242008-01-24 02:22:38 -08006347{
Alexander Duyck0ba82992011-08-26 07:45:47 +00006348 struct igb_ring *rx_ring = q_vector->rx.ring;
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006349 struct sk_buff *skb = rx_ring->skb;
Auke Kok9d5c8242008-01-24 02:22:38 -08006350 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck16eb8812011-08-26 07:43:54 +00006351 u16 cleaned_count = igb_desc_unused(rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08006352
Alexander Duyck2e334ee2012-09-25 00:31:07 +00006353 do {
6354 union e1000_adv_rx_desc *rx_desc;
Auke Kok9d5c8242008-01-24 02:22:38 -08006355
Alexander Duyck2e334ee2012-09-25 00:31:07 +00006356 /* return some buffers to hardware, one at a time is too slow */
6357 if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
6358 igb_alloc_rx_buffers(rx_ring, cleaned_count);
6359 cleaned_count = 0;
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07006360 }
6361
Alexander Duyck2e334ee2012-09-25 00:31:07 +00006362 rx_desc = IGB_RX_DESC(rx_ring, rx_ring->next_to_clean);
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07006363
Alexander Duyck2e334ee2012-09-25 00:31:07 +00006364 if (!igb_test_staterr(rx_desc, E1000_RXD_STAT_DD))
6365 break;
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07006366
Alexander Duyck2e334ee2012-09-25 00:31:07 +00006367 /* retrieve a buffer from the ring */
6368 skb = igb_fetch_rx_buffer(rx_ring, rx_desc, skb);
Alexander Duyck16eb8812011-08-26 07:43:54 +00006369
Alexander Duyck2e334ee2012-09-25 00:31:07 +00006370 /* exit if we failed to retrieve a buffer */
6371 if (!skb)
6372 break;
6373
6374 cleaned_count++;
6375
6376 /* fetch next buffer in frame if non-eop */
6377 if (igb_is_non_eop(rx_ring, rx_desc))
6378 continue;
Alexander Duyck44390ca2011-08-26 07:43:38 +00006379
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006380 /* verify the packet layout is correct */
6381 if (igb_cleanup_headers(rx_ring, rx_desc, skb)) {
6382 skb = NULL;
6383 continue;
Auke Kok9d5c8242008-01-24 02:22:38 -08006384 }
Auke Kok9d5c8242008-01-24 02:22:38 -08006385
Alexander Duyckdb2ee5b2012-09-25 00:30:57 +00006386 /* probably a little skewed due to removing CRC */
Alexander Duyck3ceb90f2011-08-26 07:46:03 +00006387 total_bytes += skb->len;
Alexander Duyck3ceb90f2011-08-26 07:46:03 +00006388
Alexander Duyckdb2ee5b2012-09-25 00:30:57 +00006389 /* populate checksum, timestamp, VLAN, and protocol */
6390 igb_process_skb_fields(rx_ring, rx_desc, skb);
Alexander Duyck3ceb90f2011-08-26 07:46:03 +00006391
Jiri Pirkob2cb09b2011-07-21 03:27:27 +00006392 napi_gro_receive(&q_vector->napi, skb);
Auke Kok9d5c8242008-01-24 02:22:38 -08006393
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006394 /* reset skb pointer */
6395 skb = NULL;
6396
Alexander Duyck2e334ee2012-09-25 00:31:07 +00006397 /* update budget accounting */
6398 total_packets++;
6399 } while (likely(total_packets < budget));
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07006400
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006401 /* place incomplete frames back on ring for completion */
6402 rx_ring->skb = skb;
6403
Eric Dumazet12dcd862010-10-15 17:27:10 +00006404 u64_stats_update_begin(&rx_ring->rx_syncp);
Auke Kok9d5c8242008-01-24 02:22:38 -08006405 rx_ring->rx_stats.packets += total_packets;
6406 rx_ring->rx_stats.bytes += total_bytes;
Eric Dumazet12dcd862010-10-15 17:27:10 +00006407 u64_stats_update_end(&rx_ring->rx_syncp);
Alexander Duyck0ba82992011-08-26 07:45:47 +00006408 q_vector->rx.total_packets += total_packets;
6409 q_vector->rx.total_bytes += total_bytes;
Alexander Duyckc023cd82011-08-26 07:43:43 +00006410
6411 if (cleaned_count)
Alexander Duyckcd392f52011-08-26 07:43:59 +00006412 igb_alloc_rx_buffers(rx_ring, cleaned_count);
Alexander Duyckc023cd82011-08-26 07:43:43 +00006413
Alexander Duyck2e334ee2012-09-25 00:31:07 +00006414 return (total_packets < budget);
Auke Kok9d5c8242008-01-24 02:22:38 -08006415}
6416
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006417static bool igb_alloc_mapped_page(struct igb_ring *rx_ring,
6418 struct igb_rx_buffer *bi)
Alexander Duyckc023cd82011-08-26 07:43:43 +00006419{
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006420 struct page *page = bi->page;
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006421 dma_addr_t dma;
Alexander Duyckc023cd82011-08-26 07:43:43 +00006422
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006423 /* since we are recycling buffers we should seldom need to alloc */
6424 if (likely(page))
Alexander Duyckc023cd82011-08-26 07:43:43 +00006425 return true;
6426
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006427 /* alloc new page for storage */
6428 page = __skb_alloc_page(GFP_ATOMIC | __GFP_COLD, NULL);
6429 if (unlikely(!page)) {
6430 rx_ring->rx_stats.alloc_failed++;
6431 return false;
Alexander Duyckc023cd82011-08-26 07:43:43 +00006432 }
6433
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006434 /* map page for use */
6435 dma = dma_map_page(rx_ring->dev, page, 0, PAGE_SIZE, DMA_FROM_DEVICE);
Alexander Duyckc023cd82011-08-26 07:43:43 +00006436
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006437 /*
6438 * if mapping failed free memory back to system since
6439 * there isn't much point in holding memory we can't use
6440 */
Alexander Duyckc023cd82011-08-26 07:43:43 +00006441 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006442 __free_page(page);
6443
Alexander Duyckc023cd82011-08-26 07:43:43 +00006444 rx_ring->rx_stats.alloc_failed++;
6445 return false;
6446 }
6447
6448 bi->dma = dma;
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006449 bi->page = page;
6450 bi->page_offset = 0;
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006451
Alexander Duyckc023cd82011-08-26 07:43:43 +00006452 return true;
6453}
6454
Auke Kok9d5c8242008-01-24 02:22:38 -08006455/**
Alexander Duyckcd392f52011-08-26 07:43:59 +00006456 * igb_alloc_rx_buffers - Replace used receive buffers; packet split
Auke Kok9d5c8242008-01-24 02:22:38 -08006457 * @adapter: address of board private structure
6458 **/
Alexander Duyckcd392f52011-08-26 07:43:59 +00006459void igb_alloc_rx_buffers(struct igb_ring *rx_ring, u16 cleaned_count)
Auke Kok9d5c8242008-01-24 02:22:38 -08006460{
Auke Kok9d5c8242008-01-24 02:22:38 -08006461 union e1000_adv_rx_desc *rx_desc;
Alexander Duyck06034642011-08-26 07:44:22 +00006462 struct igb_rx_buffer *bi;
Alexander Duyckc023cd82011-08-26 07:43:43 +00006463 u16 i = rx_ring->next_to_use;
Auke Kok9d5c8242008-01-24 02:22:38 -08006464
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006465 /* nothing to do */
6466 if (!cleaned_count)
6467 return;
6468
Alexander Duyck601369062011-08-26 07:44:05 +00006469 rx_desc = IGB_RX_DESC(rx_ring, i);
Alexander Duyck06034642011-08-26 07:44:22 +00006470 bi = &rx_ring->rx_buffer_info[i];
Alexander Duyckc023cd82011-08-26 07:43:43 +00006471 i -= rx_ring->count;
Auke Kok9d5c8242008-01-24 02:22:38 -08006472
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006473 do {
Alexander Duyck1a1c2252012-09-25 00:30:52 +00006474 if (!igb_alloc_mapped_page(rx_ring, bi))
Alexander Duyckc023cd82011-08-26 07:43:43 +00006475 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08006476
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006477 /*
6478 * Refresh the desc even if buffer_addrs didn't change
6479 * because each write-back erases this info.
6480 */
6481 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9d5c8242008-01-24 02:22:38 -08006482
Alexander Duyckc023cd82011-08-26 07:43:43 +00006483 rx_desc++;
6484 bi++;
Auke Kok9d5c8242008-01-24 02:22:38 -08006485 i++;
Alexander Duyckc023cd82011-08-26 07:43:43 +00006486 if (unlikely(!i)) {
Alexander Duyck601369062011-08-26 07:44:05 +00006487 rx_desc = IGB_RX_DESC(rx_ring, 0);
Alexander Duyck06034642011-08-26 07:44:22 +00006488 bi = rx_ring->rx_buffer_info;
Alexander Duyckc023cd82011-08-26 07:43:43 +00006489 i -= rx_ring->count;
6490 }
6491
6492 /* clear the hdr_addr for the next_to_use descriptor */
6493 rx_desc->read.hdr_addr = 0;
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006494
6495 cleaned_count--;
6496 } while (cleaned_count);
Auke Kok9d5c8242008-01-24 02:22:38 -08006497
Alexander Duyckc023cd82011-08-26 07:43:43 +00006498 i += rx_ring->count;
6499
Auke Kok9d5c8242008-01-24 02:22:38 -08006500 if (rx_ring->next_to_use != i) {
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006501 /* record the next descriptor to use */
Auke Kok9d5c8242008-01-24 02:22:38 -08006502 rx_ring->next_to_use = i;
Auke Kok9d5c8242008-01-24 02:22:38 -08006503
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006504 /* update next to alloc since we have filled the ring */
6505 rx_ring->next_to_alloc = i;
6506
6507 /*
6508 * Force memory writes to complete before letting h/w
Auke Kok9d5c8242008-01-24 02:22:38 -08006509 * know there are new descriptors to fetch. (Only
6510 * applicable for weak-ordered memory model archs,
Alexander Duyckcbc8e552012-09-25 00:31:02 +00006511 * such as IA-64).
6512 */
Auke Kok9d5c8242008-01-24 02:22:38 -08006513 wmb();
Alexander Duyckfce99e32009-10-27 15:51:27 +00006514 writel(i, rx_ring->tail);
Auke Kok9d5c8242008-01-24 02:22:38 -08006515 }
6516}
6517
6518/**
6519 * igb_mii_ioctl -
6520 * @netdev:
6521 * @ifreq:
6522 * @cmd:
6523 **/
6524static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
6525{
6526 struct igb_adapter *adapter = netdev_priv(netdev);
6527 struct mii_ioctl_data *data = if_mii(ifr);
6528
6529 if (adapter->hw.phy.media_type != e1000_media_type_copper)
6530 return -EOPNOTSUPP;
6531
6532 switch (cmd) {
6533 case SIOCGMIIPHY:
6534 data->phy_id = adapter->hw.phy.addr;
6535 break;
6536 case SIOCGMIIREG:
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08006537 if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
6538 &data->val_out))
Auke Kok9d5c8242008-01-24 02:22:38 -08006539 return -EIO;
6540 break;
6541 case SIOCSMIIREG:
6542 default:
6543 return -EOPNOTSUPP;
6544 }
6545 return 0;
6546}
6547
6548/**
6549 * igb_ioctl -
6550 * @netdev:
6551 * @ifreq:
6552 * @cmd:
6553 **/
6554static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
6555{
6556 switch (cmd) {
6557 case SIOCGMIIPHY:
6558 case SIOCGMIIREG:
6559 case SIOCSMIIREG:
6560 return igb_mii_ioctl(netdev, ifr, cmd);
Patrick Ohlyc6cb0902009-02-12 05:03:42 +00006561 case SIOCSHWTSTAMP:
Matthew Vicka79f4f82012-08-10 05:40:44 +00006562 return igb_ptp_hwtstamp_ioctl(netdev, ifr, cmd);
Auke Kok9d5c8242008-01-24 02:22:38 -08006563 default:
6564 return -EOPNOTSUPP;
6565 }
6566}
6567
Alexander Duyck009bc062009-07-23 18:08:35 +00006568s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
6569{
6570 struct igb_adapter *adapter = hw->back;
Alexander Duyck009bc062009-07-23 18:08:35 +00006571
Jiang Liu23d028c2012-08-20 13:32:20 -06006572 if (pcie_capability_read_word(adapter->pdev, reg, value))
Alexander Duyck009bc062009-07-23 18:08:35 +00006573 return -E1000_ERR_CONFIG;
6574
Alexander Duyck009bc062009-07-23 18:08:35 +00006575 return 0;
6576}
6577
6578s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
6579{
6580 struct igb_adapter *adapter = hw->back;
Alexander Duyck009bc062009-07-23 18:08:35 +00006581
Jiang Liu23d028c2012-08-20 13:32:20 -06006582 if (pcie_capability_write_word(adapter->pdev, reg, *value))
Alexander Duyck009bc062009-07-23 18:08:35 +00006583 return -E1000_ERR_CONFIG;
6584
Alexander Duyck009bc062009-07-23 18:08:35 +00006585 return 0;
6586}
6587
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006588static void igb_vlan_mode(struct net_device *netdev, netdev_features_t features)
Auke Kok9d5c8242008-01-24 02:22:38 -08006589{
6590 struct igb_adapter *adapter = netdev_priv(netdev);
6591 struct e1000_hw *hw = &adapter->hw;
6592 u32 ctrl, rctl;
Alexander Duyck5faf0302011-08-26 07:46:08 +00006593 bool enable = !!(features & NETIF_F_HW_VLAN_RX);
Auke Kok9d5c8242008-01-24 02:22:38 -08006594
Alexander Duyck5faf0302011-08-26 07:46:08 +00006595 if (enable) {
Auke Kok9d5c8242008-01-24 02:22:38 -08006596 /* enable VLAN tag insert/strip */
6597 ctrl = rd32(E1000_CTRL);
6598 ctrl |= E1000_CTRL_VME;
6599 wr32(E1000_CTRL, ctrl);
6600
Alexander Duyck51466232009-10-27 23:47:35 +00006601 /* Disable CFI check */
Auke Kok9d5c8242008-01-24 02:22:38 -08006602 rctl = rd32(E1000_RCTL);
Auke Kok9d5c8242008-01-24 02:22:38 -08006603 rctl &= ~E1000_RCTL_CFIEN;
6604 wr32(E1000_RCTL, rctl);
Auke Kok9d5c8242008-01-24 02:22:38 -08006605 } else {
6606 /* disable VLAN tag insert/strip */
6607 ctrl = rd32(E1000_CTRL);
6608 ctrl &= ~E1000_CTRL_VME;
6609 wr32(E1000_CTRL, ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08006610 }
6611
Alexander Duycke1739522009-02-19 20:39:44 -08006612 igb_rlpml_set(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08006613}
6614
Jiri Pirko8e586132011-12-08 19:52:37 -05006615static int igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9d5c8242008-01-24 02:22:38 -08006616{
6617 struct igb_adapter *adapter = netdev_priv(netdev);
6618 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006619 int pf_id = adapter->vfs_allocated_count;
Auke Kok9d5c8242008-01-24 02:22:38 -08006620
Alexander Duyck51466232009-10-27 23:47:35 +00006621 /* attempt to add filter to vlvf array */
6622 igb_vlvf_set(adapter, vid, true, pf_id);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006623
Alexander Duyck51466232009-10-27 23:47:35 +00006624 /* add the filter since PF can receive vlans w/o entry in vlvf */
6625 igb_vfta_set(hw, vid, true);
Jiri Pirkob2cb09b2011-07-21 03:27:27 +00006626
6627 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05006628
6629 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08006630}
6631
Jiri Pirko8e586132011-12-08 19:52:37 -05006632static int igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9d5c8242008-01-24 02:22:38 -08006633{
6634 struct igb_adapter *adapter = netdev_priv(netdev);
6635 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006636 int pf_id = adapter->vfs_allocated_count;
Alexander Duyck51466232009-10-27 23:47:35 +00006637 s32 err;
Auke Kok9d5c8242008-01-24 02:22:38 -08006638
Alexander Duyck51466232009-10-27 23:47:35 +00006639 /* remove vlan from VLVF table array */
6640 err = igb_vlvf_set(adapter, vid, false, pf_id);
Auke Kok9d5c8242008-01-24 02:22:38 -08006641
Alexander Duyck51466232009-10-27 23:47:35 +00006642 /* if vid was not present in VLVF just remove it from table */
6643 if (err)
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006644 igb_vfta_set(hw, vid, false);
Jiri Pirkob2cb09b2011-07-21 03:27:27 +00006645
6646 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05006647
6648 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08006649}
6650
6651static void igb_restore_vlan(struct igb_adapter *adapter)
6652{
Jiri Pirkob2cb09b2011-07-21 03:27:27 +00006653 u16 vid;
Auke Kok9d5c8242008-01-24 02:22:38 -08006654
Alexander Duyck5faf0302011-08-26 07:46:08 +00006655 igb_vlan_mode(adapter->netdev, adapter->netdev->features);
6656
Jiri Pirkob2cb09b2011-07-21 03:27:27 +00006657 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
6658 igb_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9d5c8242008-01-24 02:22:38 -08006659}
6660
David Decotigny14ad2512011-04-27 18:32:43 +00006661int igb_set_spd_dplx(struct igb_adapter *adapter, u32 spd, u8 dplx)
Auke Kok9d5c8242008-01-24 02:22:38 -08006662{
Alexander Duyck090b1792009-10-27 23:51:55 +00006663 struct pci_dev *pdev = adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08006664 struct e1000_mac_info *mac = &adapter->hw.mac;
6665
6666 mac->autoneg = 0;
6667
David Decotigny14ad2512011-04-27 18:32:43 +00006668 /* Make sure dplx is at most 1 bit and lsb of speed is not set
6669 * for the switch() below to work */
6670 if ((spd & 1) || (dplx & ~1))
6671 goto err_inval;
6672
Carolyn Wybornycd2638a2010-10-12 22:27:02 +00006673 /* Fiber NIC's only allow 1000 Gbps Full duplex */
6674 if ((adapter->hw.phy.media_type == e1000_media_type_internal_serdes) &&
David Decotigny14ad2512011-04-27 18:32:43 +00006675 spd != SPEED_1000 &&
6676 dplx != DUPLEX_FULL)
6677 goto err_inval;
Carolyn Wybornycd2638a2010-10-12 22:27:02 +00006678
David Decotigny14ad2512011-04-27 18:32:43 +00006679 switch (spd + dplx) {
Auke Kok9d5c8242008-01-24 02:22:38 -08006680 case SPEED_10 + DUPLEX_HALF:
6681 mac->forced_speed_duplex = ADVERTISE_10_HALF;
6682 break;
6683 case SPEED_10 + DUPLEX_FULL:
6684 mac->forced_speed_duplex = ADVERTISE_10_FULL;
6685 break;
6686 case SPEED_100 + DUPLEX_HALF:
6687 mac->forced_speed_duplex = ADVERTISE_100_HALF;
6688 break;
6689 case SPEED_100 + DUPLEX_FULL:
6690 mac->forced_speed_duplex = ADVERTISE_100_FULL;
6691 break;
6692 case SPEED_1000 + DUPLEX_FULL:
6693 mac->autoneg = 1;
6694 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
6695 break;
6696 case SPEED_1000 + DUPLEX_HALF: /* not supported */
6697 default:
David Decotigny14ad2512011-04-27 18:32:43 +00006698 goto err_inval;
Auke Kok9d5c8242008-01-24 02:22:38 -08006699 }
Jesse Brandeburg8376dad2012-07-26 02:31:19 +00006700
6701 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
6702 adapter->hw.phy.mdix = AUTO_ALL_MODES;
6703
Auke Kok9d5c8242008-01-24 02:22:38 -08006704 return 0;
David Decotigny14ad2512011-04-27 18:32:43 +00006705
6706err_inval:
6707 dev_err(&pdev->dev, "Unsupported Speed/Duplex configuration\n");
6708 return -EINVAL;
Auke Kok9d5c8242008-01-24 02:22:38 -08006709}
6710
Yan, Zheng749ab2c2012-01-04 20:23:37 +00006711static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake,
6712 bool runtime)
Auke Kok9d5c8242008-01-24 02:22:38 -08006713{
6714 struct net_device *netdev = pci_get_drvdata(pdev);
6715 struct igb_adapter *adapter = netdev_priv(netdev);
6716 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck2d064c02008-07-08 15:10:12 -07006717 u32 ctrl, rctl, status;
Yan, Zheng749ab2c2012-01-04 20:23:37 +00006718 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
Auke Kok9d5c8242008-01-24 02:22:38 -08006719#ifdef CONFIG_PM
6720 int retval = 0;
6721#endif
6722
6723 netif_device_detach(netdev);
6724
Alexander Duycka88f10e2008-07-08 15:13:38 -07006725 if (netif_running(netdev))
Yan, Zheng749ab2c2012-01-04 20:23:37 +00006726 __igb_close(netdev, true);
Alexander Duycka88f10e2008-07-08 15:13:38 -07006727
Alexander Duyck047e0032009-10-27 15:49:27 +00006728 igb_clear_interrupt_scheme(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08006729
6730#ifdef CONFIG_PM
6731 retval = pci_save_state(pdev);
6732 if (retval)
6733 return retval;
6734#endif
6735
6736 status = rd32(E1000_STATUS);
6737 if (status & E1000_STATUS_LU)
6738 wufc &= ~E1000_WUFC_LNKC;
6739
6740 if (wufc) {
6741 igb_setup_rctl(adapter);
Alexander Duyckff41f8d2009-09-03 14:48:56 +00006742 igb_set_rx_mode(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08006743
6744 /* turn on all-multi mode if wake on multicast is enabled */
6745 if (wufc & E1000_WUFC_MC) {
6746 rctl = rd32(E1000_RCTL);
6747 rctl |= E1000_RCTL_MPE;
6748 wr32(E1000_RCTL, rctl);
6749 }
6750
6751 ctrl = rd32(E1000_CTRL);
6752 /* advertise wake from D3Cold */
6753 #define E1000_CTRL_ADVD3WUC 0x00100000
6754 /* phy power management enable */
6755 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
6756 ctrl |= E1000_CTRL_ADVD3WUC;
6757 wr32(E1000_CTRL, ctrl);
6758
Auke Kok9d5c8242008-01-24 02:22:38 -08006759 /* Allow time for pending master requests to run */
Alexander Duyck330a6d62009-10-27 23:51:35 +00006760 igb_disable_pcie_master(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08006761
6762 wr32(E1000_WUC, E1000_WUC_PME_EN);
6763 wr32(E1000_WUFC, wufc);
Auke Kok9d5c8242008-01-24 02:22:38 -08006764 } else {
6765 wr32(E1000_WUC, 0);
6766 wr32(E1000_WUFC, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -08006767 }
6768
Rafael J. Wysocki3fe7c4c2009-03-31 21:23:50 +00006769 *enable_wake = wufc || adapter->en_mng_pt;
6770 if (!*enable_wake)
Nick Nunley88a268c2010-02-17 01:01:59 +00006771 igb_power_down_link(adapter);
6772 else
6773 igb_power_up_link(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08006774
6775 /* Release control of h/w to f/w. If f/w is AMT enabled, this
6776 * would have already happened in close and is redundant. */
6777 igb_release_hw_control(adapter);
6778
6779 pci_disable_device(pdev);
6780
Auke Kok9d5c8242008-01-24 02:22:38 -08006781 return 0;
6782}
6783
6784#ifdef CONFIG_PM
Emil Tantilovd9dd9662012-01-28 08:10:35 +00006785#ifdef CONFIG_PM_SLEEP
Yan, Zheng749ab2c2012-01-04 20:23:37 +00006786static int igb_suspend(struct device *dev)
Rafael J. Wysocki3fe7c4c2009-03-31 21:23:50 +00006787{
6788 int retval;
6789 bool wake;
Yan, Zheng749ab2c2012-01-04 20:23:37 +00006790 struct pci_dev *pdev = to_pci_dev(dev);
Rafael J. Wysocki3fe7c4c2009-03-31 21:23:50 +00006791
Yan, Zheng749ab2c2012-01-04 20:23:37 +00006792 retval = __igb_shutdown(pdev, &wake, 0);
Rafael J. Wysocki3fe7c4c2009-03-31 21:23:50 +00006793 if (retval)
6794 return retval;
6795
6796 if (wake) {
6797 pci_prepare_to_sleep(pdev);
6798 } else {
6799 pci_wake_from_d3(pdev, false);
6800 pci_set_power_state(pdev, PCI_D3hot);
6801 }
6802
6803 return 0;
6804}
Emil Tantilovd9dd9662012-01-28 08:10:35 +00006805#endif /* CONFIG_PM_SLEEP */
Rafael J. Wysocki3fe7c4c2009-03-31 21:23:50 +00006806
Yan, Zheng749ab2c2012-01-04 20:23:37 +00006807static int igb_resume(struct device *dev)
Auke Kok9d5c8242008-01-24 02:22:38 -08006808{
Yan, Zheng749ab2c2012-01-04 20:23:37 +00006809 struct pci_dev *pdev = to_pci_dev(dev);
Auke Kok9d5c8242008-01-24 02:22:38 -08006810 struct net_device *netdev = pci_get_drvdata(pdev);
6811 struct igb_adapter *adapter = netdev_priv(netdev);
6812 struct e1000_hw *hw = &adapter->hw;
6813 u32 err;
6814
6815 pci_set_power_state(pdev, PCI_D0);
6816 pci_restore_state(pdev);
Nick Nunleyb94f2d72010-02-17 01:02:19 +00006817 pci_save_state(pdev);
Taku Izumi42bfd33a2008-06-20 12:10:30 +09006818
Alexander Duyckaed5dec2009-02-06 23:16:04 +00006819 err = pci_enable_device_mem(pdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08006820 if (err) {
6821 dev_err(&pdev->dev,
6822 "igb: Cannot enable PCI device from suspend\n");
6823 return err;
6824 }
6825 pci_set_master(pdev);
6826
6827 pci_enable_wake(pdev, PCI_D3hot, 0);
6828 pci_enable_wake(pdev, PCI_D3cold, 0);
6829
Stefan Assmann53c7d062012-12-04 06:00:12 +00006830 if (igb_init_interrupt_scheme(adapter, true)) {
Alexander Duycka88f10e2008-07-08 15:13:38 -07006831 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
6832 return -ENOMEM;
Auke Kok9d5c8242008-01-24 02:22:38 -08006833 }
6834
Auke Kok9d5c8242008-01-24 02:22:38 -08006835 igb_reset(adapter);
Alexander Duycka8564f02009-02-06 23:21:10 +00006836
6837 /* let the f/w know that the h/w is now under the control of the
6838 * driver. */
6839 igb_get_hw_control(adapter);
6840
Auke Kok9d5c8242008-01-24 02:22:38 -08006841 wr32(E1000_WUS, ~0);
6842
Yan, Zheng749ab2c2012-01-04 20:23:37 +00006843 if (netdev->flags & IFF_UP) {
Alexander Duyck0c2cc022012-09-25 00:31:22 +00006844 rtnl_lock();
Yan, Zheng749ab2c2012-01-04 20:23:37 +00006845 err = __igb_open(netdev, true);
Alexander Duyck0c2cc022012-09-25 00:31:22 +00006846 rtnl_unlock();
Alexander Duycka88f10e2008-07-08 15:13:38 -07006847 if (err)
6848 return err;
6849 }
Auke Kok9d5c8242008-01-24 02:22:38 -08006850
6851 netif_device_attach(netdev);
Yan, Zheng749ab2c2012-01-04 20:23:37 +00006852 return 0;
6853}
6854
6855#ifdef CONFIG_PM_RUNTIME
6856static int igb_runtime_idle(struct device *dev)
6857{
6858 struct pci_dev *pdev = to_pci_dev(dev);
6859 struct net_device *netdev = pci_get_drvdata(pdev);
6860 struct igb_adapter *adapter = netdev_priv(netdev);
6861
6862 if (!igb_has_link(adapter))
6863 pm_schedule_suspend(dev, MSEC_PER_SEC * 5);
6864
6865 return -EBUSY;
6866}
6867
6868static int igb_runtime_suspend(struct device *dev)
6869{
6870 struct pci_dev *pdev = to_pci_dev(dev);
6871 int retval;
6872 bool wake;
6873
6874 retval = __igb_shutdown(pdev, &wake, 1);
6875 if (retval)
6876 return retval;
6877
6878 if (wake) {
6879 pci_prepare_to_sleep(pdev);
6880 } else {
6881 pci_wake_from_d3(pdev, false);
6882 pci_set_power_state(pdev, PCI_D3hot);
6883 }
Auke Kok9d5c8242008-01-24 02:22:38 -08006884
Auke Kok9d5c8242008-01-24 02:22:38 -08006885 return 0;
6886}
Yan, Zheng749ab2c2012-01-04 20:23:37 +00006887
6888static int igb_runtime_resume(struct device *dev)
6889{
6890 return igb_resume(dev);
6891}
6892#endif /* CONFIG_PM_RUNTIME */
Auke Kok9d5c8242008-01-24 02:22:38 -08006893#endif
6894
6895static void igb_shutdown(struct pci_dev *pdev)
6896{
Rafael J. Wysocki3fe7c4c2009-03-31 21:23:50 +00006897 bool wake;
6898
Yan, Zheng749ab2c2012-01-04 20:23:37 +00006899 __igb_shutdown(pdev, &wake, 0);
Rafael J. Wysocki3fe7c4c2009-03-31 21:23:50 +00006900
6901 if (system_state == SYSTEM_POWER_OFF) {
6902 pci_wake_from_d3(pdev, wake);
6903 pci_set_power_state(pdev, PCI_D3hot);
6904 }
Auke Kok9d5c8242008-01-24 02:22:38 -08006905}
6906
6907#ifdef CONFIG_NET_POLL_CONTROLLER
6908/*
6909 * Polling 'interrupt' - used by things like netconsole to send skbs
6910 * without having to re-enable interrupts. It's not called while
6911 * the interrupt routine is executing.
6912 */
6913static void igb_netpoll(struct net_device *netdev)
6914{
6915 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyckeebbbdb2009-02-06 23:19:29 +00006916 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck0d1ae7f2011-08-26 07:46:34 +00006917 struct igb_q_vector *q_vector;
Auke Kok9d5c8242008-01-24 02:22:38 -08006918 int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08006919
Alexander Duyck047e0032009-10-27 15:49:27 +00006920 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck0d1ae7f2011-08-26 07:46:34 +00006921 q_vector = adapter->q_vector[i];
6922 if (adapter->msix_entries)
6923 wr32(E1000_EIMC, q_vector->eims_value);
6924 else
6925 igb_irq_disable(adapter);
Alexander Duyck047e0032009-10-27 15:49:27 +00006926 napi_schedule(&q_vector->napi);
Alexander Duyckeebbbdb2009-02-06 23:19:29 +00006927 }
Auke Kok9d5c8242008-01-24 02:22:38 -08006928}
6929#endif /* CONFIG_NET_POLL_CONTROLLER */
6930
6931/**
6932 * igb_io_error_detected - called when PCI error is detected
6933 * @pdev: Pointer to PCI device
6934 * @state: The current pci connection state
6935 *
6936 * This function is called after a PCI bus error affecting
6937 * this device has been detected.
6938 */
6939static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
6940 pci_channel_state_t state)
6941{
6942 struct net_device *netdev = pci_get_drvdata(pdev);
6943 struct igb_adapter *adapter = netdev_priv(netdev);
6944
6945 netif_device_detach(netdev);
6946
Alexander Duyck59ed6ee2009-06-30 12:46:34 +00006947 if (state == pci_channel_io_perm_failure)
6948 return PCI_ERS_RESULT_DISCONNECT;
6949
Auke Kok9d5c8242008-01-24 02:22:38 -08006950 if (netif_running(netdev))
6951 igb_down(adapter);
6952 pci_disable_device(pdev);
6953
6954 /* Request a slot slot reset. */
6955 return PCI_ERS_RESULT_NEED_RESET;
6956}
6957
6958/**
6959 * igb_io_slot_reset - called after the pci bus has been reset.
6960 * @pdev: Pointer to PCI device
6961 *
6962 * Restart the card from scratch, as if from a cold-boot. Implementation
6963 * resembles the first-half of the igb_resume routine.
6964 */
6965static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
6966{
6967 struct net_device *netdev = pci_get_drvdata(pdev);
6968 struct igb_adapter *adapter = netdev_priv(netdev);
6969 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck40a914f2008-11-27 00:24:37 -08006970 pci_ers_result_t result;
Taku Izumi42bfd33a2008-06-20 12:10:30 +09006971 int err;
Auke Kok9d5c8242008-01-24 02:22:38 -08006972
Alexander Duyckaed5dec2009-02-06 23:16:04 +00006973 if (pci_enable_device_mem(pdev)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08006974 dev_err(&pdev->dev,
6975 "Cannot re-enable PCI device after reset.\n");
Alexander Duyck40a914f2008-11-27 00:24:37 -08006976 result = PCI_ERS_RESULT_DISCONNECT;
6977 } else {
6978 pci_set_master(pdev);
6979 pci_restore_state(pdev);
Nick Nunleyb94f2d72010-02-17 01:02:19 +00006980 pci_save_state(pdev);
Alexander Duyck40a914f2008-11-27 00:24:37 -08006981
6982 pci_enable_wake(pdev, PCI_D3hot, 0);
6983 pci_enable_wake(pdev, PCI_D3cold, 0);
6984
6985 igb_reset(adapter);
6986 wr32(E1000_WUS, ~0);
6987 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9d5c8242008-01-24 02:22:38 -08006988 }
Auke Kok9d5c8242008-01-24 02:22:38 -08006989
Jeff Kirsherea943d42008-12-11 20:34:19 -08006990 err = pci_cleanup_aer_uncorrect_error_status(pdev);
6991 if (err) {
6992 dev_err(&pdev->dev, "pci_cleanup_aer_uncorrect_error_status "
6993 "failed 0x%0x\n", err);
6994 /* non-fatal, continue */
6995 }
Auke Kok9d5c8242008-01-24 02:22:38 -08006996
Alexander Duyck40a914f2008-11-27 00:24:37 -08006997 return result;
Auke Kok9d5c8242008-01-24 02:22:38 -08006998}
6999
7000/**
7001 * igb_io_resume - called when traffic can start flowing again.
7002 * @pdev: Pointer to PCI device
7003 *
7004 * This callback is called when the error recovery driver tells us that
7005 * its OK to resume normal operation. Implementation resembles the
7006 * second-half of the igb_resume routine.
7007 */
7008static void igb_io_resume(struct pci_dev *pdev)
7009{
7010 struct net_device *netdev = pci_get_drvdata(pdev);
7011 struct igb_adapter *adapter = netdev_priv(netdev);
7012
Auke Kok9d5c8242008-01-24 02:22:38 -08007013 if (netif_running(netdev)) {
7014 if (igb_up(adapter)) {
7015 dev_err(&pdev->dev, "igb_up failed after reset\n");
7016 return;
7017 }
7018 }
7019
7020 netif_device_attach(netdev);
7021
7022 /* let the f/w know that the h/w is now under the control of the
7023 * driver. */
7024 igb_get_hw_control(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08007025}
7026
Alexander Duyck26ad9172009-10-05 06:32:49 +00007027static void igb_rar_set_qsel(struct igb_adapter *adapter, u8 *addr, u32 index,
7028 u8 qsel)
7029{
7030 u32 rar_low, rar_high;
7031 struct e1000_hw *hw = &adapter->hw;
7032
7033 /* HW expects these in little endian so we reverse the byte order
7034 * from network order (big endian) to little endian
7035 */
7036 rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
7037 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
7038 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
7039
7040 /* Indicate to hardware the Address is Valid. */
7041 rar_high |= E1000_RAH_AV;
7042
7043 if (hw->mac.type == e1000_82575)
7044 rar_high |= E1000_RAH_POOL_1 * qsel;
7045 else
7046 rar_high |= E1000_RAH_POOL_1 << qsel;
7047
7048 wr32(E1000_RAL(index), rar_low);
7049 wrfl();
7050 wr32(E1000_RAH(index), rar_high);
7051 wrfl();
7052}
7053
Alexander Duyck4ae196d2009-02-19 20:40:07 -08007054static int igb_set_vf_mac(struct igb_adapter *adapter,
7055 int vf, unsigned char *mac_addr)
7056{
7057 struct e1000_hw *hw = &adapter->hw;
Alexander Duyckff41f8d2009-09-03 14:48:56 +00007058 /* VF MAC addresses start at end of receive addresses and moves
7059 * torwards the first, as a result a collision should not be possible */
7060 int rar_entry = hw->mac.rar_entry_count - (vf + 1);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08007061
Alexander Duyck37680112009-02-19 20:40:30 -08007062 memcpy(adapter->vf_data[vf].vf_mac_addresses, mac_addr, ETH_ALEN);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08007063
Alexander Duyck26ad9172009-10-05 06:32:49 +00007064 igb_rar_set_qsel(adapter, mac_addr, rar_entry, vf);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08007065
7066 return 0;
7067}
7068
Williams, Mitch A8151d292010-02-10 01:44:24 +00007069static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
7070{
7071 struct igb_adapter *adapter = netdev_priv(netdev);
7072 if (!is_valid_ether_addr(mac) || (vf >= adapter->vfs_allocated_count))
7073 return -EINVAL;
7074 adapter->vf_data[vf].flags |= IGB_VF_FLAG_PF_SET_MAC;
7075 dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf);
7076 dev_info(&adapter->pdev->dev, "Reload the VF driver to make this"
7077 " change effective.");
7078 if (test_bit(__IGB_DOWN, &adapter->state)) {
7079 dev_warn(&adapter->pdev->dev, "The VF MAC address has been set,"
7080 " but the PF device is not up.\n");
7081 dev_warn(&adapter->pdev->dev, "Bring the PF device up before"
7082 " attempting to use the VF device.\n");
7083 }
7084 return igb_set_vf_mac(adapter, vf, mac);
7085}
7086
Lior Levy17dc5662011-02-08 02:28:46 +00007087static int igb_link_mbps(int internal_link_speed)
7088{
7089 switch (internal_link_speed) {
7090 case SPEED_100:
7091 return 100;
7092 case SPEED_1000:
7093 return 1000;
7094 default:
7095 return 0;
7096 }
7097}
7098
7099static void igb_set_vf_rate_limit(struct e1000_hw *hw, int vf, int tx_rate,
7100 int link_speed)
7101{
7102 int rf_dec, rf_int;
7103 u32 bcnrc_val;
7104
7105 if (tx_rate != 0) {
7106 /* Calculate the rate factor values to set */
7107 rf_int = link_speed / tx_rate;
7108 rf_dec = (link_speed - (rf_int * tx_rate));
7109 rf_dec = (rf_dec * (1<<E1000_RTTBCNRC_RF_INT_SHIFT)) / tx_rate;
7110
7111 bcnrc_val = E1000_RTTBCNRC_RS_ENA;
7112 bcnrc_val |= ((rf_int<<E1000_RTTBCNRC_RF_INT_SHIFT) &
7113 E1000_RTTBCNRC_RF_INT_MASK);
7114 bcnrc_val |= (rf_dec & E1000_RTTBCNRC_RF_DEC_MASK);
7115 } else {
7116 bcnrc_val = 0;
7117 }
7118
7119 wr32(E1000_RTTDQSEL, vf); /* vf X uses queue X */
Lior Levyf00b0da2011-06-04 06:05:03 +00007120 /*
7121 * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
7122 * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported.
7123 */
7124 wr32(E1000_RTTBCNRM, 0x14);
Lior Levy17dc5662011-02-08 02:28:46 +00007125 wr32(E1000_RTTBCNRC, bcnrc_val);
7126}
7127
7128static void igb_check_vf_rate_limit(struct igb_adapter *adapter)
7129{
7130 int actual_link_speed, i;
7131 bool reset_rate = false;
7132
7133 /* VF TX rate limit was not set or not supported */
7134 if ((adapter->vf_rate_link_speed == 0) ||
7135 (adapter->hw.mac.type != e1000_82576))
7136 return;
7137
7138 actual_link_speed = igb_link_mbps(adapter->link_speed);
7139 if (actual_link_speed != adapter->vf_rate_link_speed) {
7140 reset_rate = true;
7141 adapter->vf_rate_link_speed = 0;
7142 dev_info(&adapter->pdev->dev,
7143 "Link speed has been changed. VF Transmit "
7144 "rate is disabled\n");
7145 }
7146
7147 for (i = 0; i < adapter->vfs_allocated_count; i++) {
7148 if (reset_rate)
7149 adapter->vf_data[i].tx_rate = 0;
7150
7151 igb_set_vf_rate_limit(&adapter->hw, i,
7152 adapter->vf_data[i].tx_rate,
7153 actual_link_speed);
7154 }
7155}
7156
Williams, Mitch A8151d292010-02-10 01:44:24 +00007157static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate)
7158{
Lior Levy17dc5662011-02-08 02:28:46 +00007159 struct igb_adapter *adapter = netdev_priv(netdev);
7160 struct e1000_hw *hw = &adapter->hw;
7161 int actual_link_speed;
7162
7163 if (hw->mac.type != e1000_82576)
7164 return -EOPNOTSUPP;
7165
7166 actual_link_speed = igb_link_mbps(adapter->link_speed);
7167 if ((vf >= adapter->vfs_allocated_count) ||
7168 (!(rd32(E1000_STATUS) & E1000_STATUS_LU)) ||
7169 (tx_rate < 0) || (tx_rate > actual_link_speed))
7170 return -EINVAL;
7171
7172 adapter->vf_rate_link_speed = actual_link_speed;
7173 adapter->vf_data[vf].tx_rate = (u16)tx_rate;
7174 igb_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed);
7175
7176 return 0;
Williams, Mitch A8151d292010-02-10 01:44:24 +00007177}
7178
7179static int igb_ndo_get_vf_config(struct net_device *netdev,
7180 int vf, struct ifla_vf_info *ivi)
7181{
7182 struct igb_adapter *adapter = netdev_priv(netdev);
7183 if (vf >= adapter->vfs_allocated_count)
7184 return -EINVAL;
7185 ivi->vf = vf;
7186 memcpy(&ivi->mac, adapter->vf_data[vf].vf_mac_addresses, ETH_ALEN);
Lior Levy17dc5662011-02-08 02:28:46 +00007187 ivi->tx_rate = adapter->vf_data[vf].tx_rate;
Williams, Mitch A8151d292010-02-10 01:44:24 +00007188 ivi->vlan = adapter->vf_data[vf].pf_vlan;
7189 ivi->qos = adapter->vf_data[vf].pf_qos;
7190 return 0;
7191}
7192
Alexander Duyck4ae196d2009-02-19 20:40:07 -08007193static void igb_vmm_control(struct igb_adapter *adapter)
7194{
7195 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck10d8e902009-10-27 15:54:04 +00007196 u32 reg;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08007197
Alexander Duyck52a1dd42010-03-22 14:07:46 +00007198 switch (hw->mac.type) {
7199 case e1000_82575:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00007200 case e1000_i210:
7201 case e1000_i211:
Alexander Duyck52a1dd42010-03-22 14:07:46 +00007202 default:
7203 /* replication is not supported for 82575 */
Alexander Duyck4ae196d2009-02-19 20:40:07 -08007204 return;
Alexander Duyck52a1dd42010-03-22 14:07:46 +00007205 case e1000_82576:
7206 /* notify HW that the MAC is adding vlan tags */
7207 reg = rd32(E1000_DTXCTL);
7208 reg |= E1000_DTXCTL_VLAN_ADDED;
7209 wr32(E1000_DTXCTL, reg);
7210 case e1000_82580:
7211 /* enable replication vlan tag stripping */
7212 reg = rd32(E1000_RPLOLR);
7213 reg |= E1000_RPLOLR_STRVLAN;
7214 wr32(E1000_RPLOLR, reg);
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00007215 case e1000_i350:
7216 /* none of the above registers are supported by i350 */
Alexander Duyck52a1dd42010-03-22 14:07:46 +00007217 break;
7218 }
Alexander Duyck10d8e902009-10-27 15:54:04 +00007219
Alexander Duyckd4960302009-10-27 15:53:45 +00007220 if (adapter->vfs_allocated_count) {
7221 igb_vmdq_set_loopback_pf(hw, true);
7222 igb_vmdq_set_replication_pf(hw, true);
Greg Rose13800462010-11-06 02:08:26 +00007223 igb_vmdq_set_anti_spoofing_pf(hw, true,
7224 adapter->vfs_allocated_count);
Alexander Duyckd4960302009-10-27 15:53:45 +00007225 } else {
7226 igb_vmdq_set_loopback_pf(hw, false);
7227 igb_vmdq_set_replication_pf(hw, false);
7228 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08007229}
7230
Carolyn Wybornyb6e0c412011-10-13 17:29:59 +00007231static void igb_init_dmac(struct igb_adapter *adapter, u32 pba)
7232{
7233 struct e1000_hw *hw = &adapter->hw;
7234 u32 dmac_thr;
7235 u16 hwm;
7236
7237 if (hw->mac.type > e1000_82580) {
7238 if (adapter->flags & IGB_FLAG_DMAC) {
7239 u32 reg;
7240
7241 /* force threshold to 0. */
7242 wr32(E1000_DMCTXTH, 0);
7243
7244 /*
Matthew Vicke8c626e2011-11-17 08:33:12 +00007245 * DMA Coalescing high water mark needs to be greater
7246 * than the Rx threshold. Set hwm to PBA - max frame
7247 * size in 16B units, capping it at PBA - 6KB.
Carolyn Wybornyb6e0c412011-10-13 17:29:59 +00007248 */
Matthew Vicke8c626e2011-11-17 08:33:12 +00007249 hwm = 64 * pba - adapter->max_frame_size / 16;
7250 if (hwm < 64 * (pba - 6))
7251 hwm = 64 * (pba - 6);
7252 reg = rd32(E1000_FCRTC);
7253 reg &= ~E1000_FCRTC_RTH_COAL_MASK;
7254 reg |= ((hwm << E1000_FCRTC_RTH_COAL_SHIFT)
7255 & E1000_FCRTC_RTH_COAL_MASK);
7256 wr32(E1000_FCRTC, reg);
7257
7258 /*
7259 * Set the DMA Coalescing Rx threshold to PBA - 2 * max
7260 * frame size, capping it at PBA - 10KB.
7261 */
7262 dmac_thr = pba - adapter->max_frame_size / 512;
7263 if (dmac_thr < pba - 10)
7264 dmac_thr = pba - 10;
Carolyn Wybornyb6e0c412011-10-13 17:29:59 +00007265 reg = rd32(E1000_DMACR);
7266 reg &= ~E1000_DMACR_DMACTHR_MASK;
Carolyn Wybornyb6e0c412011-10-13 17:29:59 +00007267 reg |= ((dmac_thr << E1000_DMACR_DMACTHR_SHIFT)
7268 & E1000_DMACR_DMACTHR_MASK);
7269
7270 /* transition to L0x or L1 if available..*/
7271 reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK);
7272
7273 /* watchdog timer= +-1000 usec in 32usec intervals */
7274 reg |= (1000 >> 5);
Matthew Vick0c02dd92012-04-14 05:20:32 +00007275
7276 /* Disable BMC-to-OS Watchdog Enable */
7277 reg &= ~E1000_DMACR_DC_BMC2OSW_EN;
Carolyn Wybornyb6e0c412011-10-13 17:29:59 +00007278 wr32(E1000_DMACR, reg);
7279
7280 /*
7281 * no lower threshold to disable
7282 * coalescing(smart fifb)-UTRESH=0
7283 */
7284 wr32(E1000_DMCRTRH, 0);
Carolyn Wybornyb6e0c412011-10-13 17:29:59 +00007285
7286 reg = (IGB_DMCTLX_DCFLUSH_DIS | 0x4);
7287
7288 wr32(E1000_DMCTLX, reg);
7289
7290 /*
7291 * free space in tx packet buffer to wake from
7292 * DMA coal
7293 */
7294 wr32(E1000_DMCTXTH, (IGB_MIN_TXPBSIZE -
7295 (IGB_TX_BUF_4096 + adapter->max_frame_size)) >> 6);
7296
7297 /*
7298 * make low power state decision controlled
7299 * by DMA coal
7300 */
7301 reg = rd32(E1000_PCIEMISC);
7302 reg &= ~E1000_PCIEMISC_LX_DECISION;
7303 wr32(E1000_PCIEMISC, reg);
7304 } /* endif adapter->dmac is not disabled */
7305 } else if (hw->mac.type == e1000_82580) {
7306 u32 reg = rd32(E1000_PCIEMISC);
7307 wr32(E1000_PCIEMISC, reg & ~E1000_PCIEMISC_LX_DECISION);
7308 wr32(E1000_DMACR, 0);
7309 }
7310}
7311
Auke Kok9d5c8242008-01-24 02:22:38 -08007312/* igb_main.c */