blob: 2c28621eb30b5aa02e0e7fe6d214f5e4c0b60f72 [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
Alexander Duyck86d5d382009-02-06 23:23:12 +00004 Copyright(c) 2007-2009 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
28#include <linux/module.h>
29#include <linux/types.h>
30#include <linux/init.h>
31#include <linux/vmalloc.h>
32#include <linux/pagemap.h>
33#include <linux/netdevice.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080034#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080036#include <net/checksum.h>
37#include <net/ip6_checksum.h>
Patrick Ohlyc6cb0902009-02-12 05:03:42 +000038#include <linux/net_tstamp.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080039#include <linux/mii.h>
40#include <linux/ethtool.h>
41#include <linux/if_vlan.h>
42#include <linux/pci.h>
Alexander Duyckc54106b2008-10-16 21:26:57 -070043#include <linux/pci-aspm.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080044#include <linux/delay.h>
45#include <linux/interrupt.h>
46#include <linux/if_ether.h>
Alexander Duyck40a914f2008-11-27 00:24:37 -080047#include <linux/aer.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040048#include <linux/prefetch.h>
Jeff Kirsher421e02f2008-10-17 11:08:31 -070049#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -070050#include <linux/dca.h>
51#endif
Auke Kok9d5c8242008-01-24 02:22:38 -080052#include "igb.h"
53
Carolyn Wyborny0d1fe822011-03-11 20:58:19 -080054#define MAJ 3
55#define MIN 0
56#define BUILD 6
57#define KFIX 2
58#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
59__stringify(BUILD) "-k" __stringify(KFIX)
Auke Kok9d5c8242008-01-24 02:22:38 -080060char igb_driver_name[] = "igb";
61char igb_driver_version[] = DRV_VERSION;
62static const char igb_driver_string[] =
63 "Intel(R) Gigabit Ethernet Network Driver";
Carolyn Wyborny4c4b42c2011-02-17 09:02:30 +000064static const char igb_copyright[] = "Copyright (c) 2007-2011 Intel Corporation.";
Auke Kok9d5c8242008-01-24 02:22:38 -080065
Auke Kok9d5c8242008-01-24 02:22:38 -080066static const struct e1000_info *igb_info_tbl[] = {
67 [board_82575] = &e1000_82575_info,
68};
69
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000070static DEFINE_PCI_DEVICE_TABLE(igb_pci_tbl) = {
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +000071 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_COPPER), board_82575 },
72 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_FIBER), board_82575 },
73 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SERDES), board_82575 },
74 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SGMII), board_82575 },
Alexander Duyck55cac242009-11-19 12:42:21 +000075 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER), board_82575 },
76 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_FIBER), board_82575 },
Carolyn Wyborny6493d242011-01-14 05:33:46 +000077 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_QUAD_FIBER), board_82575 },
Alexander Duyck55cac242009-11-19 12:42:21 +000078 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SERDES), board_82575 },
79 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SGMII), board_82575 },
80 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER_DUAL), board_82575 },
Joseph Gasparakis308fb392010-09-22 17:56:44 +000081 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SGMII), board_82575 },
82 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SERDES), board_82575 },
Gasparakis, Joseph1b5dda32010-12-09 01:41:01 +000083 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_BACKPLANE), board_82575 },
84 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SFP), board_82575 },
Alexander Duyck2d064c02008-07-08 15:10:12 -070085 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 },
Alexander Duyck9eb23412009-03-13 20:42:15 +000086 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS), board_82575 },
Alexander Duyck747d49b2009-10-05 06:33:27 +000087 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS_SERDES), board_82575 },
Alexander Duyck2d064c02008-07-08 15:10:12 -070088 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 },
89 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 },
Alexander Duyck4703bf72009-07-23 18:09:48 +000090 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES_QUAD), board_82575 },
Carolyn Wybornyb894fa22010-03-19 06:07:48 +000091 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER_ET2), board_82575 },
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +000092 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER), board_82575 },
Auke Kok9d5c8242008-01-24 02:22:38 -080093 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 },
94 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 },
95 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 },
96 /* required last entry */
97 {0, }
98};
99
100MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
101
102void igb_reset(struct igb_adapter *);
103static int igb_setup_all_tx_resources(struct igb_adapter *);
104static int igb_setup_all_rx_resources(struct igb_adapter *);
105static void igb_free_all_tx_resources(struct igb_adapter *);
106static void igb_free_all_rx_resources(struct igb_adapter *);
Alexander Duyck06cf2662009-10-27 15:53:25 +0000107static void igb_setup_mrqc(struct igb_adapter *);
Auke Kok9d5c8242008-01-24 02:22:38 -0800108static int igb_probe(struct pci_dev *, const struct pci_device_id *);
109static void __devexit igb_remove(struct pci_dev *pdev);
Anders Berggren673b8b72011-02-04 07:32:32 +0000110static void igb_init_hw_timer(struct igb_adapter *adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800111static int igb_sw_init(struct igb_adapter *);
112static int igb_open(struct net_device *);
113static int igb_close(struct net_device *);
114static void igb_configure_tx(struct igb_adapter *);
115static void igb_configure_rx(struct igb_adapter *);
Auke Kok9d5c8242008-01-24 02:22:38 -0800116static void igb_clean_all_tx_rings(struct igb_adapter *);
117static void igb_clean_all_rx_rings(struct igb_adapter *);
Mitch Williams3b644cf2008-06-27 10:59:48 -0700118static void igb_clean_tx_ring(struct igb_ring *);
119static void igb_clean_rx_ring(struct igb_ring *);
Alexander Duyckff41f8d2009-09-03 14:48:56 +0000120static void igb_set_rx_mode(struct net_device *);
Auke Kok9d5c8242008-01-24 02:22:38 -0800121static void igb_update_phy_info(unsigned long);
122static void igb_watchdog(unsigned long);
123static void igb_watchdog_task(struct work_struct *);
Alexander Duyckb1a436c2009-10-27 15:54:43 +0000124static netdev_tx_t igb_xmit_frame_adv(struct sk_buff *skb, struct net_device *);
Eric Dumazet12dcd862010-10-15 17:27:10 +0000125static struct rtnl_link_stats64 *igb_get_stats64(struct net_device *dev,
126 struct rtnl_link_stats64 *stats);
Auke Kok9d5c8242008-01-24 02:22:38 -0800127static int igb_change_mtu(struct net_device *, int);
128static int igb_set_mac(struct net_device *, void *);
Alexander Duyck68d480c2009-10-05 06:33:08 +0000129static void igb_set_uta(struct igb_adapter *adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800130static irqreturn_t igb_intr(int irq, void *);
131static irqreturn_t igb_intr_msi(int irq, void *);
132static irqreturn_t igb_msix_other(int irq, void *);
Alexander Duyck047e0032009-10-27 15:49:27 +0000133static irqreturn_t igb_msix_ring(int irq, void *);
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700134#ifdef CONFIG_IGB_DCA
Alexander Duyck047e0032009-10-27 15:49:27 +0000135static void igb_update_dca(struct igb_q_vector *);
Jeb Cramerfe4506b2008-07-08 15:07:55 -0700136static void igb_setup_dca(struct igb_adapter *);
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700137#endif /* CONFIG_IGB_DCA */
Alexander Duyck047e0032009-10-27 15:49:27 +0000138static bool igb_clean_tx_irq(struct igb_q_vector *);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -0700139static int igb_poll(struct napi_struct *, int);
Alexander Duyck047e0032009-10-27 15:49:27 +0000140static bool igb_clean_rx_irq_adv(struct igb_q_vector *, int *, int);
Auke Kok9d5c8242008-01-24 02:22:38 -0800141static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
142static void igb_tx_timeout(struct net_device *);
143static void igb_reset_task(struct work_struct *);
144static void igb_vlan_rx_register(struct net_device *, struct vlan_group *);
145static void igb_vlan_rx_add_vid(struct net_device *, u16);
146static void igb_vlan_rx_kill_vid(struct net_device *, u16);
147static void igb_restore_vlan(struct igb_adapter *);
Alexander Duyck26ad9172009-10-05 06:32:49 +0000148static void igb_rar_set_qsel(struct igb_adapter *, u8 *, u32 , u8);
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800149static void igb_ping_all_vfs(struct igb_adapter *);
150static void igb_msg_task(struct igb_adapter *);
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800151static void igb_vmm_control(struct igb_adapter *);
Alexander Duyckf2ca0db2009-10-27 23:46:57 +0000152static int igb_set_vf_mac(struct igb_adapter *, int, unsigned char *);
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800153static void igb_restore_vf_multicasts(struct igb_adapter *adapter);
Williams, Mitch A8151d292010-02-10 01:44:24 +0000154static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac);
155static int igb_ndo_set_vf_vlan(struct net_device *netdev,
156 int vf, u16 vlan, u8 qos);
157static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate);
158static int igb_ndo_get_vf_config(struct net_device *netdev, int vf,
159 struct ifla_vf_info *ivi);
Lior Levy17dc5662011-02-08 02:28:46 +0000160static void igb_check_vf_rate_limit(struct igb_adapter *);
Auke Kok9d5c8242008-01-24 02:22:38 -0800161
Auke Kok9d5c8242008-01-24 02:22:38 -0800162#ifdef CONFIG_PM
Rafael J. Wysocki3fe7c4c2009-03-31 21:23:50 +0000163static int igb_suspend(struct pci_dev *, pm_message_t);
Auke Kok9d5c8242008-01-24 02:22:38 -0800164static int igb_resume(struct pci_dev *);
165#endif
166static void igb_shutdown(struct pci_dev *);
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700167#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -0700168static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
169static struct notifier_block dca_notifier = {
170 .notifier_call = igb_notify_dca,
171 .next = NULL,
172 .priority = 0
173};
174#endif
Auke Kok9d5c8242008-01-24 02:22:38 -0800175#ifdef CONFIG_NET_POLL_CONTROLLER
176/* for netdump / net console */
177static void igb_netpoll(struct net_device *);
178#endif
Alexander Duyck37680112009-02-19 20:40:30 -0800179#ifdef CONFIG_PCI_IOV
Alexander Duyck2a3abf62009-04-07 14:37:52 +0000180static unsigned int max_vfs = 0;
181module_param(max_vfs, uint, 0);
182MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate "
183 "per physical function");
184#endif /* CONFIG_PCI_IOV */
185
Auke Kok9d5c8242008-01-24 02:22:38 -0800186static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
187 pci_channel_state_t);
188static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
189static void igb_io_resume(struct pci_dev *);
190
191static struct pci_error_handlers igb_err_handler = {
192 .error_detected = igb_io_error_detected,
193 .slot_reset = igb_io_slot_reset,
194 .resume = igb_io_resume,
195};
196
197
198static struct pci_driver igb_driver = {
199 .name = igb_driver_name,
200 .id_table = igb_pci_tbl,
201 .probe = igb_probe,
202 .remove = __devexit_p(igb_remove),
203#ifdef CONFIG_PM
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300204 /* Power Management Hooks */
Auke Kok9d5c8242008-01-24 02:22:38 -0800205 .suspend = igb_suspend,
206 .resume = igb_resume,
207#endif
208 .shutdown = igb_shutdown,
209 .err_handler = &igb_err_handler
210};
211
212MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
213MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
214MODULE_LICENSE("GPL");
215MODULE_VERSION(DRV_VERSION);
216
Taku Izumic97ec422010-04-27 14:39:30 +0000217struct igb_reg_info {
218 u32 ofs;
219 char *name;
220};
221
222static const struct igb_reg_info igb_reg_info_tbl[] = {
223
224 /* General Registers */
225 {E1000_CTRL, "CTRL"},
226 {E1000_STATUS, "STATUS"},
227 {E1000_CTRL_EXT, "CTRL_EXT"},
228
229 /* Interrupt Registers */
230 {E1000_ICR, "ICR"},
231
232 /* RX Registers */
233 {E1000_RCTL, "RCTL"},
234 {E1000_RDLEN(0), "RDLEN"},
235 {E1000_RDH(0), "RDH"},
236 {E1000_RDT(0), "RDT"},
237 {E1000_RXDCTL(0), "RXDCTL"},
238 {E1000_RDBAL(0), "RDBAL"},
239 {E1000_RDBAH(0), "RDBAH"},
240
241 /* TX Registers */
242 {E1000_TCTL, "TCTL"},
243 {E1000_TDBAL(0), "TDBAL"},
244 {E1000_TDBAH(0), "TDBAH"},
245 {E1000_TDLEN(0), "TDLEN"},
246 {E1000_TDH(0), "TDH"},
247 {E1000_TDT(0), "TDT"},
248 {E1000_TXDCTL(0), "TXDCTL"},
249 {E1000_TDFH, "TDFH"},
250 {E1000_TDFT, "TDFT"},
251 {E1000_TDFHS, "TDFHS"},
252 {E1000_TDFPC, "TDFPC"},
253
254 /* List Terminator */
255 {}
256};
257
258/*
259 * igb_regdump - register printout routine
260 */
261static void igb_regdump(struct e1000_hw *hw, struct igb_reg_info *reginfo)
262{
263 int n = 0;
264 char rname[16];
265 u32 regs[8];
266
267 switch (reginfo->ofs) {
268 case E1000_RDLEN(0):
269 for (n = 0; n < 4; n++)
270 regs[n] = rd32(E1000_RDLEN(n));
271 break;
272 case E1000_RDH(0):
273 for (n = 0; n < 4; n++)
274 regs[n] = rd32(E1000_RDH(n));
275 break;
276 case E1000_RDT(0):
277 for (n = 0; n < 4; n++)
278 regs[n] = rd32(E1000_RDT(n));
279 break;
280 case E1000_RXDCTL(0):
281 for (n = 0; n < 4; n++)
282 regs[n] = rd32(E1000_RXDCTL(n));
283 break;
284 case E1000_RDBAL(0):
285 for (n = 0; n < 4; n++)
286 regs[n] = rd32(E1000_RDBAL(n));
287 break;
288 case E1000_RDBAH(0):
289 for (n = 0; n < 4; n++)
290 regs[n] = rd32(E1000_RDBAH(n));
291 break;
292 case E1000_TDBAL(0):
293 for (n = 0; n < 4; n++)
294 regs[n] = rd32(E1000_RDBAL(n));
295 break;
296 case E1000_TDBAH(0):
297 for (n = 0; n < 4; n++)
298 regs[n] = rd32(E1000_TDBAH(n));
299 break;
300 case E1000_TDLEN(0):
301 for (n = 0; n < 4; n++)
302 regs[n] = rd32(E1000_TDLEN(n));
303 break;
304 case E1000_TDH(0):
305 for (n = 0; n < 4; n++)
306 regs[n] = rd32(E1000_TDH(n));
307 break;
308 case E1000_TDT(0):
309 for (n = 0; n < 4; n++)
310 regs[n] = rd32(E1000_TDT(n));
311 break;
312 case E1000_TXDCTL(0):
313 for (n = 0; n < 4; n++)
314 regs[n] = rd32(E1000_TXDCTL(n));
315 break;
316 default:
317 printk(KERN_INFO "%-15s %08x\n",
318 reginfo->name, rd32(reginfo->ofs));
319 return;
320 }
321
322 snprintf(rname, 16, "%s%s", reginfo->name, "[0-3]");
323 printk(KERN_INFO "%-15s ", rname);
324 for (n = 0; n < 4; n++)
325 printk(KERN_CONT "%08x ", regs[n]);
326 printk(KERN_CONT "\n");
327}
328
329/*
330 * igb_dump - Print registers, tx-rings and rx-rings
331 */
332static void igb_dump(struct igb_adapter *adapter)
333{
334 struct net_device *netdev = adapter->netdev;
335 struct e1000_hw *hw = &adapter->hw;
336 struct igb_reg_info *reginfo;
337 int n = 0;
338 struct igb_ring *tx_ring;
339 union e1000_adv_tx_desc *tx_desc;
340 struct my_u0 { u64 a; u64 b; } *u0;
341 struct igb_buffer *buffer_info;
342 struct igb_ring *rx_ring;
343 union e1000_adv_rx_desc *rx_desc;
344 u32 staterr;
345 int i = 0;
346
347 if (!netif_msg_hw(adapter))
348 return;
349
350 /* Print netdevice Info */
351 if (netdev) {
352 dev_info(&adapter->pdev->dev, "Net device Info\n");
353 printk(KERN_INFO "Device Name state "
354 "trans_start last_rx\n");
355 printk(KERN_INFO "%-15s %016lX %016lX %016lX\n",
356 netdev->name,
357 netdev->state,
358 netdev->trans_start,
359 netdev->last_rx);
360 }
361
362 /* Print Registers */
363 dev_info(&adapter->pdev->dev, "Register Dump\n");
364 printk(KERN_INFO " Register Name Value\n");
365 for (reginfo = (struct igb_reg_info *)igb_reg_info_tbl;
366 reginfo->name; reginfo++) {
367 igb_regdump(hw, reginfo);
368 }
369
370 /* Print TX Ring Summary */
371 if (!netdev || !netif_running(netdev))
372 goto exit;
373
374 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
375 printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ]"
376 " leng ntw timestamp\n");
377 for (n = 0; n < adapter->num_tx_queues; n++) {
378 tx_ring = adapter->tx_ring[n];
379 buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
380 printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n",
381 n, tx_ring->next_to_use, tx_ring->next_to_clean,
382 (u64)buffer_info->dma,
383 buffer_info->length,
384 buffer_info->next_to_watch,
385 (u64)buffer_info->time_stamp);
386 }
387
388 /* Print TX Rings */
389 if (!netif_msg_tx_done(adapter))
390 goto rx_ring_summary;
391
392 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
393
394 /* Transmit Descriptor Formats
395 *
396 * Advanced Transmit Descriptor
397 * +--------------------------------------------------------------+
398 * 0 | Buffer Address [63:0] |
399 * +--------------------------------------------------------------+
400 * 8 | PAYLEN | PORTS |CC|IDX | STA | DCMD |DTYP|MAC|RSV| DTALEN |
401 * +--------------------------------------------------------------+
402 * 63 46 45 40 39 38 36 35 32 31 24 15 0
403 */
404
405 for (n = 0; n < adapter->num_tx_queues; n++) {
406 tx_ring = adapter->tx_ring[n];
407 printk(KERN_INFO "------------------------------------\n");
408 printk(KERN_INFO "TX QUEUE INDEX = %d\n", tx_ring->queue_index);
409 printk(KERN_INFO "------------------------------------\n");
410 printk(KERN_INFO "T [desc] [address 63:0 ] "
411 "[PlPOCIStDDM Ln] [bi->dma ] "
412 "leng ntw timestamp bi->skb\n");
413
414 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
415 tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
416 buffer_info = &tx_ring->buffer_info[i];
417 u0 = (struct my_u0 *)tx_desc;
418 printk(KERN_INFO "T [0x%03X] %016llX %016llX %016llX"
419 " %04X %3X %016llX %p", i,
420 le64_to_cpu(u0->a),
421 le64_to_cpu(u0->b),
422 (u64)buffer_info->dma,
423 buffer_info->length,
424 buffer_info->next_to_watch,
425 (u64)buffer_info->time_stamp,
426 buffer_info->skb);
427 if (i == tx_ring->next_to_use &&
428 i == tx_ring->next_to_clean)
429 printk(KERN_CONT " NTC/U\n");
430 else if (i == tx_ring->next_to_use)
431 printk(KERN_CONT " NTU\n");
432 else if (i == tx_ring->next_to_clean)
433 printk(KERN_CONT " NTC\n");
434 else
435 printk(KERN_CONT "\n");
436
437 if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
438 print_hex_dump(KERN_INFO, "",
439 DUMP_PREFIX_ADDRESS,
440 16, 1, phys_to_virt(buffer_info->dma),
441 buffer_info->length, true);
442 }
443 }
444
445 /* Print RX Rings Summary */
446rx_ring_summary:
447 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
448 printk(KERN_INFO "Queue [NTU] [NTC]\n");
449 for (n = 0; n < adapter->num_rx_queues; n++) {
450 rx_ring = adapter->rx_ring[n];
451 printk(KERN_INFO " %5d %5X %5X\n", n,
452 rx_ring->next_to_use, rx_ring->next_to_clean);
453 }
454
455 /* Print RX Rings */
456 if (!netif_msg_rx_status(adapter))
457 goto exit;
458
459 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
460
461 /* Advanced Receive Descriptor (Read) Format
462 * 63 1 0
463 * +-----------------------------------------------------+
464 * 0 | Packet Buffer Address [63:1] |A0/NSE|
465 * +----------------------------------------------+------+
466 * 8 | Header Buffer Address [63:1] | DD |
467 * +-----------------------------------------------------+
468 *
469 *
470 * Advanced Receive Descriptor (Write-Back) Format
471 *
472 * 63 48 47 32 31 30 21 20 17 16 4 3 0
473 * +------------------------------------------------------+
474 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
475 * | Checksum Ident | | | | Type | Type |
476 * +------------------------------------------------------+
477 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
478 * +------------------------------------------------------+
479 * 63 48 47 32 31 20 19 0
480 */
481
482 for (n = 0; n < adapter->num_rx_queues; n++) {
483 rx_ring = adapter->rx_ring[n];
484 printk(KERN_INFO "------------------------------------\n");
485 printk(KERN_INFO "RX QUEUE INDEX = %d\n", rx_ring->queue_index);
486 printk(KERN_INFO "------------------------------------\n");
487 printk(KERN_INFO "R [desc] [ PktBuf A0] "
488 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
489 "<-- Adv Rx Read format\n");
490 printk(KERN_INFO "RWB[desc] [PcsmIpSHl PtRs] "
491 "[vl er S cks ln] ---------------- [bi->skb] "
492 "<-- Adv Rx Write-Back format\n");
493
494 for (i = 0; i < rx_ring->count; i++) {
495 buffer_info = &rx_ring->buffer_info[i];
496 rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
497 u0 = (struct my_u0 *)rx_desc;
498 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
499 if (staterr & E1000_RXD_STAT_DD) {
500 /* Descriptor Done */
501 printk(KERN_INFO "RWB[0x%03X] %016llX "
502 "%016llX ---------------- %p", i,
503 le64_to_cpu(u0->a),
504 le64_to_cpu(u0->b),
505 buffer_info->skb);
506 } else {
507 printk(KERN_INFO "R [0x%03X] %016llX "
508 "%016llX %016llX %p", i,
509 le64_to_cpu(u0->a),
510 le64_to_cpu(u0->b),
511 (u64)buffer_info->dma,
512 buffer_info->skb);
513
514 if (netif_msg_pktdata(adapter)) {
515 print_hex_dump(KERN_INFO, "",
516 DUMP_PREFIX_ADDRESS,
517 16, 1,
518 phys_to_virt(buffer_info->dma),
519 rx_ring->rx_buffer_len, true);
520 if (rx_ring->rx_buffer_len
521 < IGB_RXBUFFER_1024)
522 print_hex_dump(KERN_INFO, "",
523 DUMP_PREFIX_ADDRESS,
524 16, 1,
525 phys_to_virt(
526 buffer_info->page_dma +
527 buffer_info->page_offset),
528 PAGE_SIZE/2, true);
529 }
530 }
531
532 if (i == rx_ring->next_to_use)
533 printk(KERN_CONT " NTU\n");
534 else if (i == rx_ring->next_to_clean)
535 printk(KERN_CONT " NTC\n");
536 else
537 printk(KERN_CONT "\n");
538
539 }
540 }
541
542exit:
543 return;
544}
545
546
Patrick Ohly38c845c2009-02-12 05:03:41 +0000547/**
Patrick Ohly38c845c2009-02-12 05:03:41 +0000548 * igb_read_clock - read raw cycle counter (to be used by time counter)
549 */
550static cycle_t igb_read_clock(const struct cyclecounter *tc)
551{
552 struct igb_adapter *adapter =
553 container_of(tc, struct igb_adapter, cycles);
554 struct e1000_hw *hw = &adapter->hw;
Alexander Duyckc5b9bd52009-10-27 23:46:01 +0000555 u64 stamp = 0;
556 int shift = 0;
Patrick Ohly38c845c2009-02-12 05:03:41 +0000557
Alexander Duyck55cac242009-11-19 12:42:21 +0000558 /*
559 * The timestamp latches on lowest register read. For the 82580
560 * the lowest register is SYSTIMR instead of SYSTIML. However we never
561 * adjusted TIMINCA so SYSTIMR will just read as all 0s so ignore it.
562 */
563 if (hw->mac.type == e1000_82580) {
564 stamp = rd32(E1000_SYSTIMR) >> 8;
565 shift = IGB_82580_TSYNC_SHIFT;
566 }
567
Alexander Duyckc5b9bd52009-10-27 23:46:01 +0000568 stamp |= (u64)rd32(E1000_SYSTIML) << shift;
569 stamp |= (u64)rd32(E1000_SYSTIMH) << (shift + 32);
Patrick Ohly38c845c2009-02-12 05:03:41 +0000570 return stamp;
571}
572
Auke Kok9d5c8242008-01-24 02:22:38 -0800573/**
Alexander Duyckc0410762010-03-25 13:10:08 +0000574 * igb_get_hw_dev - return device
Auke Kok9d5c8242008-01-24 02:22:38 -0800575 * used by hardware layer to print debugging information
576 **/
Alexander Duyckc0410762010-03-25 13:10:08 +0000577struct net_device *igb_get_hw_dev(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -0800578{
579 struct igb_adapter *adapter = hw->back;
Alexander Duyckc0410762010-03-25 13:10:08 +0000580 return adapter->netdev;
Auke Kok9d5c8242008-01-24 02:22:38 -0800581}
Patrick Ohly38c845c2009-02-12 05:03:41 +0000582
583/**
Auke Kok9d5c8242008-01-24 02:22:38 -0800584 * igb_init_module - Driver Registration Routine
585 *
586 * igb_init_module is the first routine called when the driver is
587 * loaded. All it does is register with the PCI subsystem.
588 **/
589static int __init igb_init_module(void)
590{
591 int ret;
592 printk(KERN_INFO "%s - version %s\n",
593 igb_driver_string, igb_driver_version);
594
595 printk(KERN_INFO "%s\n", igb_copyright);
596
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700597#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -0700598 dca_register_notify(&dca_notifier);
599#endif
Alexander Duyckbbd98fe2009-01-31 00:52:30 -0800600 ret = pci_register_driver(&igb_driver);
Auke Kok9d5c8242008-01-24 02:22:38 -0800601 return ret;
602}
603
604module_init(igb_init_module);
605
606/**
607 * igb_exit_module - Driver Exit Cleanup Routine
608 *
609 * igb_exit_module is called just before the driver is removed
610 * from memory.
611 **/
612static void __exit igb_exit_module(void)
613{
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700614#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -0700615 dca_unregister_notify(&dca_notifier);
616#endif
Auke Kok9d5c8242008-01-24 02:22:38 -0800617 pci_unregister_driver(&igb_driver);
618}
619
620module_exit(igb_exit_module);
621
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800622#define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
623/**
624 * igb_cache_ring_register - Descriptor ring to register mapping
625 * @adapter: board private structure to initialize
626 *
627 * Once we know the feature-set enabled for the device, we'll cache
628 * the register offset the descriptor ring is assigned to.
629 **/
630static void igb_cache_ring_register(struct igb_adapter *adapter)
631{
Alexander Duyckee1b9f02009-10-27 23:49:40 +0000632 int i = 0, j = 0;
Alexander Duyck047e0032009-10-27 15:49:27 +0000633 u32 rbase_offset = adapter->vfs_allocated_count;
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800634
635 switch (adapter->hw.mac.type) {
636 case e1000_82576:
637 /* The queues are allocated for virtualization such that VF 0
638 * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
639 * In order to avoid collision we start at the first free queue
640 * and continue consuming queues in the same sequence
641 */
Alexander Duyckee1b9f02009-10-27 23:49:40 +0000642 if (adapter->vfs_allocated_count) {
Alexander Duycka99955f2009-11-12 18:37:19 +0000643 for (; i < adapter->rss_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +0000644 adapter->rx_ring[i]->reg_idx = rbase_offset +
645 Q_IDX_82576(i);
Alexander Duyckee1b9f02009-10-27 23:49:40 +0000646 }
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800647 case e1000_82575:
Alexander Duyck55cac242009-11-19 12:42:21 +0000648 case e1000_82580:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000649 case e1000_i350:
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800650 default:
Alexander Duyckee1b9f02009-10-27 23:49:40 +0000651 for (; i < adapter->num_rx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +0000652 adapter->rx_ring[i]->reg_idx = rbase_offset + i;
Alexander Duyckee1b9f02009-10-27 23:49:40 +0000653 for (; j < adapter->num_tx_queues; j++)
Alexander Duyck3025a442010-02-17 01:02:39 +0000654 adapter->tx_ring[j]->reg_idx = rbase_offset + j;
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800655 break;
656 }
657}
658
Alexander Duyck047e0032009-10-27 15:49:27 +0000659static void igb_free_queues(struct igb_adapter *adapter)
660{
Alexander Duyck3025a442010-02-17 01:02:39 +0000661 int i;
Alexander Duyck047e0032009-10-27 15:49:27 +0000662
Alexander Duyck3025a442010-02-17 01:02:39 +0000663 for (i = 0; i < adapter->num_tx_queues; i++) {
664 kfree(adapter->tx_ring[i]);
665 adapter->tx_ring[i] = NULL;
666 }
667 for (i = 0; i < adapter->num_rx_queues; i++) {
668 kfree(adapter->rx_ring[i]);
669 adapter->rx_ring[i] = NULL;
670 }
Alexander Duyck047e0032009-10-27 15:49:27 +0000671 adapter->num_rx_queues = 0;
672 adapter->num_tx_queues = 0;
673}
674
Auke Kok9d5c8242008-01-24 02:22:38 -0800675/**
676 * igb_alloc_queues - Allocate memory for all rings
677 * @adapter: board private structure to initialize
678 *
679 * We allocate one ring per queue at run-time since we don't know the
680 * number of queues at compile-time.
681 **/
682static int igb_alloc_queues(struct igb_adapter *adapter)
683{
Alexander Duyck3025a442010-02-17 01:02:39 +0000684 struct igb_ring *ring;
Auke Kok9d5c8242008-01-24 02:22:38 -0800685 int i;
686
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -0700687 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +0000688 ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL);
689 if (!ring)
690 goto err;
Alexander Duyck68fd9912008-11-20 00:48:10 -0800691 ring->count = adapter->tx_ring_count;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -0700692 ring->queue_index = i;
Alexander Duyck59d71982010-04-27 13:09:25 +0000693 ring->dev = &adapter->pdev->dev;
Alexander Duycke694e962009-10-27 15:53:06 +0000694 ring->netdev = adapter->netdev;
Alexander Duyck85ad76b2009-10-27 15:52:46 +0000695 /* For 82575, context index must be unique per ring. */
696 if (adapter->hw.mac.type == e1000_82575)
697 ring->flags = IGB_RING_FLAG_TX_CTX_IDX;
Alexander Duyck3025a442010-02-17 01:02:39 +0000698 adapter->tx_ring[i] = ring;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -0700699 }
Alexander Duyck85ad76b2009-10-27 15:52:46 +0000700
Auke Kok9d5c8242008-01-24 02:22:38 -0800701 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +0000702 ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL);
703 if (!ring)
704 goto err;
Alexander Duyck68fd9912008-11-20 00:48:10 -0800705 ring->count = adapter->rx_ring_count;
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700706 ring->queue_index = i;
Alexander Duyck59d71982010-04-27 13:09:25 +0000707 ring->dev = &adapter->pdev->dev;
Alexander Duycke694e962009-10-27 15:53:06 +0000708 ring->netdev = adapter->netdev;
Alexander Duyck4c844852009-10-27 15:52:07 +0000709 ring->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Alexander Duyck85ad76b2009-10-27 15:52:46 +0000710 ring->flags = IGB_RING_FLAG_RX_CSUM; /* enable rx checksum */
711 /* set flag indicating ring supports SCTP checksum offload */
712 if (adapter->hw.mac.type >= e1000_82576)
713 ring->flags |= IGB_RING_FLAG_RX_SCTP_CSUM;
Alexander Duyck3025a442010-02-17 01:02:39 +0000714 adapter->rx_ring[i] = ring;
Auke Kok9d5c8242008-01-24 02:22:38 -0800715 }
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800716
717 igb_cache_ring_register(adapter);
Alexander Duyck047e0032009-10-27 15:49:27 +0000718
Auke Kok9d5c8242008-01-24 02:22:38 -0800719 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800720
Alexander Duyck047e0032009-10-27 15:49:27 +0000721err:
722 igb_free_queues(adapter);
Alexander Duycka88f10e2008-07-08 15:13:38 -0700723
Alexander Duyck047e0032009-10-27 15:49:27 +0000724 return -ENOMEM;
Alexander Duycka88f10e2008-07-08 15:13:38 -0700725}
726
Auke Kok9d5c8242008-01-24 02:22:38 -0800727#define IGB_N0_QUEUE -1
Alexander Duyck047e0032009-10-27 15:49:27 +0000728static void igb_assign_vector(struct igb_q_vector *q_vector, int msix_vector)
Auke Kok9d5c8242008-01-24 02:22:38 -0800729{
730 u32 msixbm = 0;
Alexander Duyck047e0032009-10-27 15:49:27 +0000731 struct igb_adapter *adapter = q_vector->adapter;
Auke Kok9d5c8242008-01-24 02:22:38 -0800732 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700733 u32 ivar, index;
Alexander Duyck047e0032009-10-27 15:49:27 +0000734 int rx_queue = IGB_N0_QUEUE;
735 int tx_queue = IGB_N0_QUEUE;
736
737 if (q_vector->rx_ring)
738 rx_queue = q_vector->rx_ring->reg_idx;
739 if (q_vector->tx_ring)
740 tx_queue = q_vector->tx_ring->reg_idx;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700741
742 switch (hw->mac.type) {
743 case e1000_82575:
Auke Kok9d5c8242008-01-24 02:22:38 -0800744 /* The 82575 assigns vectors using a bitmask, which matches the
745 bitmask for the EICR/EIMS/EIMC registers. To assign one
746 or more queues to a vector, we write the appropriate bits
747 into the MSIXBM register for that vector. */
Alexander Duyck047e0032009-10-27 15:49:27 +0000748 if (rx_queue > IGB_N0_QUEUE)
Auke Kok9d5c8242008-01-24 02:22:38 -0800749 msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
Alexander Duyck047e0032009-10-27 15:49:27 +0000750 if (tx_queue > IGB_N0_QUEUE)
Auke Kok9d5c8242008-01-24 02:22:38 -0800751 msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
Alexander Duyckfeeb2722010-02-03 21:59:51 +0000752 if (!adapter->msix_entries && msix_vector == 0)
753 msixbm |= E1000_EIMS_OTHER;
Auke Kok9d5c8242008-01-24 02:22:38 -0800754 array_wr32(E1000_MSIXBM(0), msix_vector, msixbm);
Alexander Duyck047e0032009-10-27 15:49:27 +0000755 q_vector->eims_value = msixbm;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700756 break;
757 case e1000_82576:
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800758 /* 82576 uses a table-based method for assigning vectors.
Alexander Duyck2d064c02008-07-08 15:10:12 -0700759 Each queue has a single entry in the table to which we write
760 a vector number along with a "valid" bit. Sadly, the layout
761 of the table is somewhat counterintuitive. */
762 if (rx_queue > IGB_N0_QUEUE) {
Alexander Duyck047e0032009-10-27 15:49:27 +0000763 index = (rx_queue & 0x7);
Alexander Duyck2d064c02008-07-08 15:10:12 -0700764 ivar = array_rd32(E1000_IVAR0, index);
Alexander Duyck047e0032009-10-27 15:49:27 +0000765 if (rx_queue < 8) {
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800766 /* vector goes into low byte of register */
767 ivar = ivar & 0xFFFFFF00;
768 ivar |= msix_vector | E1000_IVAR_VALID;
Alexander Duyck047e0032009-10-27 15:49:27 +0000769 } else {
770 /* vector goes into third byte of register */
771 ivar = ivar & 0xFF00FFFF;
772 ivar |= (msix_vector | E1000_IVAR_VALID) << 16;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700773 }
Alexander Duyck2d064c02008-07-08 15:10:12 -0700774 array_wr32(E1000_IVAR0, index, ivar);
775 }
776 if (tx_queue > IGB_N0_QUEUE) {
Alexander Duyck047e0032009-10-27 15:49:27 +0000777 index = (tx_queue & 0x7);
Alexander Duyck2d064c02008-07-08 15:10:12 -0700778 ivar = array_rd32(E1000_IVAR0, index);
Alexander Duyck047e0032009-10-27 15:49:27 +0000779 if (tx_queue < 8) {
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800780 /* vector goes into second byte of register */
781 ivar = ivar & 0xFFFF00FF;
782 ivar |= (msix_vector | E1000_IVAR_VALID) << 8;
Alexander Duyck047e0032009-10-27 15:49:27 +0000783 } else {
784 /* vector goes into high byte of register */
785 ivar = ivar & 0x00FFFFFF;
786 ivar |= (msix_vector | E1000_IVAR_VALID) << 24;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700787 }
Alexander Duyck2d064c02008-07-08 15:10:12 -0700788 array_wr32(E1000_IVAR0, index, ivar);
789 }
Alexander Duyck047e0032009-10-27 15:49:27 +0000790 q_vector->eims_value = 1 << msix_vector;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700791 break;
Alexander Duyck55cac242009-11-19 12:42:21 +0000792 case e1000_82580:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000793 case e1000_i350:
Alexander Duyck55cac242009-11-19 12:42:21 +0000794 /* 82580 uses the same table-based approach as 82576 but has fewer
795 entries as a result we carry over for queues greater than 4. */
796 if (rx_queue > IGB_N0_QUEUE) {
797 index = (rx_queue >> 1);
798 ivar = array_rd32(E1000_IVAR0, index);
799 if (rx_queue & 0x1) {
800 /* vector goes into third byte of register */
801 ivar = ivar & 0xFF00FFFF;
802 ivar |= (msix_vector | E1000_IVAR_VALID) << 16;
803 } else {
804 /* vector goes into low byte of register */
805 ivar = ivar & 0xFFFFFF00;
806 ivar |= msix_vector | E1000_IVAR_VALID;
807 }
808 array_wr32(E1000_IVAR0, index, ivar);
809 }
810 if (tx_queue > IGB_N0_QUEUE) {
811 index = (tx_queue >> 1);
812 ivar = array_rd32(E1000_IVAR0, index);
813 if (tx_queue & 0x1) {
814 /* vector goes into high byte of register */
815 ivar = ivar & 0x00FFFFFF;
816 ivar |= (msix_vector | E1000_IVAR_VALID) << 24;
817 } else {
818 /* vector goes into second byte of register */
819 ivar = ivar & 0xFFFF00FF;
820 ivar |= (msix_vector | E1000_IVAR_VALID) << 8;
821 }
822 array_wr32(E1000_IVAR0, index, ivar);
823 }
824 q_vector->eims_value = 1 << msix_vector;
825 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700826 default:
827 BUG();
828 break;
829 }
Alexander Duyck26b39272010-02-17 01:00:41 +0000830
831 /* add q_vector eims value to global eims_enable_mask */
832 adapter->eims_enable_mask |= q_vector->eims_value;
833
834 /* configure q_vector to set itr on first interrupt */
835 q_vector->set_itr = 1;
Auke Kok9d5c8242008-01-24 02:22:38 -0800836}
837
838/**
839 * igb_configure_msix - Configure MSI-X hardware
840 *
841 * igb_configure_msix sets up the hardware to properly
842 * generate MSI-X interrupts.
843 **/
844static void igb_configure_msix(struct igb_adapter *adapter)
845{
846 u32 tmp;
847 int i, vector = 0;
848 struct e1000_hw *hw = &adapter->hw;
849
850 adapter->eims_enable_mask = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800851
852 /* set vector for other causes, i.e. link changes */
Alexander Duyck2d064c02008-07-08 15:10:12 -0700853 switch (hw->mac.type) {
854 case e1000_82575:
Auke Kok9d5c8242008-01-24 02:22:38 -0800855 tmp = rd32(E1000_CTRL_EXT);
856 /* enable MSI-X PBA support*/
857 tmp |= E1000_CTRL_EXT_PBA_CLR;
858
859 /* Auto-Mask interrupts upon ICR read. */
860 tmp |= E1000_CTRL_EXT_EIAME;
861 tmp |= E1000_CTRL_EXT_IRCA;
862
863 wr32(E1000_CTRL_EXT, tmp);
Alexander Duyck047e0032009-10-27 15:49:27 +0000864
865 /* enable msix_other interrupt */
866 array_wr32(E1000_MSIXBM(0), vector++,
867 E1000_EIMS_OTHER);
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700868 adapter->eims_other = E1000_EIMS_OTHER;
Auke Kok9d5c8242008-01-24 02:22:38 -0800869
Alexander Duyck2d064c02008-07-08 15:10:12 -0700870 break;
871
872 case e1000_82576:
Alexander Duyck55cac242009-11-19 12:42:21 +0000873 case e1000_82580:
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +0000874 case e1000_i350:
Alexander Duyck047e0032009-10-27 15:49:27 +0000875 /* Turn on MSI-X capability first, or our settings
876 * won't stick. And it will take days to debug. */
877 wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE |
878 E1000_GPIE_PBA | E1000_GPIE_EIAME |
879 E1000_GPIE_NSICR);
Alexander Duyck2d064c02008-07-08 15:10:12 -0700880
Alexander Duyck047e0032009-10-27 15:49:27 +0000881 /* enable msix_other interrupt */
882 adapter->eims_other = 1 << vector;
883 tmp = (vector++ | E1000_IVAR_VALID) << 8;
884
885 wr32(E1000_IVAR_MISC, tmp);
Alexander Duyck2d064c02008-07-08 15:10:12 -0700886 break;
887 default:
888 /* do nothing, since nothing else supports MSI-X */
889 break;
890 } /* switch (hw->mac.type) */
Alexander Duyck047e0032009-10-27 15:49:27 +0000891
892 adapter->eims_enable_mask |= adapter->eims_other;
893
Alexander Duyck26b39272010-02-17 01:00:41 +0000894 for (i = 0; i < adapter->num_q_vectors; i++)
895 igb_assign_vector(adapter->q_vector[i], vector++);
Alexander Duyck047e0032009-10-27 15:49:27 +0000896
Auke Kok9d5c8242008-01-24 02:22:38 -0800897 wrfl();
898}
899
900/**
901 * igb_request_msix - Initialize MSI-X interrupts
902 *
903 * igb_request_msix allocates MSI-X vectors and requests interrupts from the
904 * kernel.
905 **/
906static int igb_request_msix(struct igb_adapter *adapter)
907{
908 struct net_device *netdev = adapter->netdev;
Alexander Duyck047e0032009-10-27 15:49:27 +0000909 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -0800910 int i, err = 0, vector = 0;
911
Auke Kok9d5c8242008-01-24 02:22:38 -0800912 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -0800913 igb_msix_other, 0, netdev->name, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800914 if (err)
915 goto out;
Alexander Duyck047e0032009-10-27 15:49:27 +0000916 vector++;
917
918 for (i = 0; i < adapter->num_q_vectors; i++) {
919 struct igb_q_vector *q_vector = adapter->q_vector[i];
920
921 q_vector->itr_register = hw->hw_addr + E1000_EITR(vector);
922
923 if (q_vector->rx_ring && q_vector->tx_ring)
924 sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
925 q_vector->rx_ring->queue_index);
926 else if (q_vector->tx_ring)
927 sprintf(q_vector->name, "%s-tx-%u", netdev->name,
928 q_vector->tx_ring->queue_index);
929 else if (q_vector->rx_ring)
930 sprintf(q_vector->name, "%s-rx-%u", netdev->name,
931 q_vector->rx_ring->queue_index);
932 else
933 sprintf(q_vector->name, "%s-unused", netdev->name);
934
935 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -0800936 igb_msix_ring, 0, q_vector->name,
Alexander Duyck047e0032009-10-27 15:49:27 +0000937 q_vector);
938 if (err)
939 goto out;
940 vector++;
941 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800942
Auke Kok9d5c8242008-01-24 02:22:38 -0800943 igb_configure_msix(adapter);
944 return 0;
945out:
946 return err;
947}
948
949static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
950{
951 if (adapter->msix_entries) {
952 pci_disable_msix(adapter->pdev);
953 kfree(adapter->msix_entries);
954 adapter->msix_entries = NULL;
Alexander Duyck047e0032009-10-27 15:49:27 +0000955 } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800956 pci_disable_msi(adapter->pdev);
Alexander Duyck047e0032009-10-27 15:49:27 +0000957 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800958}
959
Alexander Duyck047e0032009-10-27 15:49:27 +0000960/**
961 * igb_free_q_vectors - Free memory allocated for interrupt vectors
962 * @adapter: board private structure to initialize
963 *
964 * This function frees the memory allocated to the q_vectors. In addition if
965 * NAPI is enabled it will delete any references to the NAPI struct prior
966 * to freeing the q_vector.
967 **/
968static void igb_free_q_vectors(struct igb_adapter *adapter)
969{
970 int v_idx;
971
972 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
973 struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
974 adapter->q_vector[v_idx] = NULL;
Nick Nunleyfe0592b2010-02-17 01:05:35 +0000975 if (!q_vector)
976 continue;
Alexander Duyck047e0032009-10-27 15:49:27 +0000977 netif_napi_del(&q_vector->napi);
978 kfree(q_vector);
979 }
980 adapter->num_q_vectors = 0;
981}
982
983/**
984 * igb_clear_interrupt_scheme - reset the device to a state of no interrupts
985 *
986 * This function resets the device so that it has 0 rx queues, tx queues, and
987 * MSI-X interrupts allocated.
988 */
989static void igb_clear_interrupt_scheme(struct igb_adapter *adapter)
990{
991 igb_free_queues(adapter);
992 igb_free_q_vectors(adapter);
993 igb_reset_interrupt_capability(adapter);
994}
Auke Kok9d5c8242008-01-24 02:22:38 -0800995
996/**
997 * igb_set_interrupt_capability - set MSI or MSI-X if supported
998 *
999 * Attempt to configure interrupts using the best available
1000 * capabilities of the hardware and kernel.
1001 **/
Ben Hutchings21adef32010-09-27 08:28:39 +00001002static int igb_set_interrupt_capability(struct igb_adapter *adapter)
Auke Kok9d5c8242008-01-24 02:22:38 -08001003{
1004 int err;
1005 int numvecs, i;
1006
Alexander Duyck83b71802009-02-06 23:15:45 +00001007 /* Number of supported queues. */
Alexander Duycka99955f2009-11-12 18:37:19 +00001008 adapter->num_rx_queues = adapter->rss_queues;
Greg Rose5fa85172010-07-01 13:38:16 +00001009 if (adapter->vfs_allocated_count)
1010 adapter->num_tx_queues = 1;
1011 else
1012 adapter->num_tx_queues = adapter->rss_queues;
Alexander Duyck83b71802009-02-06 23:15:45 +00001013
Alexander Duyck047e0032009-10-27 15:49:27 +00001014 /* start with one vector for every rx queue */
1015 numvecs = adapter->num_rx_queues;
1016
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001017 /* if tx handler is separate add 1 for every tx queue */
Alexander Duycka99955f2009-11-12 18:37:19 +00001018 if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS))
1019 numvecs += adapter->num_tx_queues;
Alexander Duyck047e0032009-10-27 15:49:27 +00001020
1021 /* store the number of vectors reserved for queues */
1022 adapter->num_q_vectors = numvecs;
1023
1024 /* add 1 vector for link status interrupts */
1025 numvecs++;
Auke Kok9d5c8242008-01-24 02:22:38 -08001026 adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry),
1027 GFP_KERNEL);
1028 if (!adapter->msix_entries)
1029 goto msi_only;
1030
1031 for (i = 0; i < numvecs; i++)
1032 adapter->msix_entries[i].entry = i;
1033
1034 err = pci_enable_msix(adapter->pdev,
1035 adapter->msix_entries,
1036 numvecs);
1037 if (err == 0)
Alexander Duyck34a20e82008-08-26 04:25:13 -07001038 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001039
1040 igb_reset_interrupt_capability(adapter);
1041
1042 /* If we can't do MSI-X, try MSI */
1043msi_only:
Alexander Duyck2a3abf62009-04-07 14:37:52 +00001044#ifdef CONFIG_PCI_IOV
1045 /* disable SR-IOV for non MSI-X configurations */
1046 if (adapter->vf_data) {
1047 struct e1000_hw *hw = &adapter->hw;
1048 /* disable iov and allow time for transactions to clear */
1049 pci_disable_sriov(adapter->pdev);
1050 msleep(500);
1051
1052 kfree(adapter->vf_data);
1053 adapter->vf_data = NULL;
1054 wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
1055 msleep(100);
1056 dev_info(&adapter->pdev->dev, "IOV Disabled\n");
1057 }
1058#endif
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001059 adapter->vfs_allocated_count = 0;
Alexander Duycka99955f2009-11-12 18:37:19 +00001060 adapter->rss_queues = 1;
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001061 adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
Auke Kok9d5c8242008-01-24 02:22:38 -08001062 adapter->num_rx_queues = 1;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07001063 adapter->num_tx_queues = 1;
Alexander Duyck047e0032009-10-27 15:49:27 +00001064 adapter->num_q_vectors = 1;
Auke Kok9d5c8242008-01-24 02:22:38 -08001065 if (!pci_enable_msi(adapter->pdev))
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07001066 adapter->flags |= IGB_FLAG_HAS_MSI;
Alexander Duyck34a20e82008-08-26 04:25:13 -07001067out:
Ben Hutchings21adef32010-09-27 08:28:39 +00001068 /* Notify the stack of the (possibly) reduced queue counts. */
1069 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
1070 return netif_set_real_num_rx_queues(adapter->netdev,
1071 adapter->num_rx_queues);
Auke Kok9d5c8242008-01-24 02:22:38 -08001072}
1073
1074/**
Alexander Duyck047e0032009-10-27 15:49:27 +00001075 * igb_alloc_q_vectors - Allocate memory for interrupt vectors
1076 * @adapter: board private structure to initialize
1077 *
1078 * We allocate one q_vector per queue interrupt. If allocation fails we
1079 * return -ENOMEM.
1080 **/
1081static int igb_alloc_q_vectors(struct igb_adapter *adapter)
1082{
1083 struct igb_q_vector *q_vector;
1084 struct e1000_hw *hw = &adapter->hw;
1085 int v_idx;
1086
1087 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
1088 q_vector = kzalloc(sizeof(struct igb_q_vector), GFP_KERNEL);
1089 if (!q_vector)
1090 goto err_out;
1091 q_vector->adapter = adapter;
Alexander Duyck047e0032009-10-27 15:49:27 +00001092 q_vector->itr_register = hw->hw_addr + E1000_EITR(0);
1093 q_vector->itr_val = IGB_START_ITR;
Alexander Duyck047e0032009-10-27 15:49:27 +00001094 netif_napi_add(adapter->netdev, &q_vector->napi, igb_poll, 64);
1095 adapter->q_vector[v_idx] = q_vector;
1096 }
1097 return 0;
1098
1099err_out:
Nick Nunleyfe0592b2010-02-17 01:05:35 +00001100 igb_free_q_vectors(adapter);
Alexander Duyck047e0032009-10-27 15:49:27 +00001101 return -ENOMEM;
1102}
1103
1104static void igb_map_rx_ring_to_vector(struct igb_adapter *adapter,
1105 int ring_idx, int v_idx)
1106{
Alexander Duyck3025a442010-02-17 01:02:39 +00001107 struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
Alexander Duyck047e0032009-10-27 15:49:27 +00001108
Alexander Duyck3025a442010-02-17 01:02:39 +00001109 q_vector->rx_ring = adapter->rx_ring[ring_idx];
Alexander Duyck047e0032009-10-27 15:49:27 +00001110 q_vector->rx_ring->q_vector = q_vector;
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001111 q_vector->itr_val = adapter->rx_itr_setting;
1112 if (q_vector->itr_val && q_vector->itr_val <= 3)
1113 q_vector->itr_val = IGB_START_ITR;
Alexander Duyck047e0032009-10-27 15:49:27 +00001114}
1115
1116static void igb_map_tx_ring_to_vector(struct igb_adapter *adapter,
1117 int ring_idx, int v_idx)
1118{
Alexander Duyck3025a442010-02-17 01:02:39 +00001119 struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
Alexander Duyck047e0032009-10-27 15:49:27 +00001120
Alexander Duyck3025a442010-02-17 01:02:39 +00001121 q_vector->tx_ring = adapter->tx_ring[ring_idx];
Alexander Duyck047e0032009-10-27 15:49:27 +00001122 q_vector->tx_ring->q_vector = q_vector;
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00001123 q_vector->itr_val = adapter->tx_itr_setting;
1124 if (q_vector->itr_val && q_vector->itr_val <= 3)
1125 q_vector->itr_val = IGB_START_ITR;
Alexander Duyck047e0032009-10-27 15:49:27 +00001126}
1127
1128/**
1129 * igb_map_ring_to_vector - maps allocated queues to vectors
1130 *
1131 * This function maps the recently allocated queues to vectors.
1132 **/
1133static int igb_map_ring_to_vector(struct igb_adapter *adapter)
1134{
1135 int i;
1136 int v_idx = 0;
1137
1138 if ((adapter->num_q_vectors < adapter->num_rx_queues) ||
1139 (adapter->num_q_vectors < adapter->num_tx_queues))
1140 return -ENOMEM;
1141
1142 if (adapter->num_q_vectors >=
1143 (adapter->num_rx_queues + adapter->num_tx_queues)) {
1144 for (i = 0; i < adapter->num_rx_queues; i++)
1145 igb_map_rx_ring_to_vector(adapter, i, v_idx++);
1146 for (i = 0; i < adapter->num_tx_queues; i++)
1147 igb_map_tx_ring_to_vector(adapter, i, v_idx++);
1148 } else {
1149 for (i = 0; i < adapter->num_rx_queues; i++) {
1150 if (i < adapter->num_tx_queues)
1151 igb_map_tx_ring_to_vector(adapter, i, v_idx);
1152 igb_map_rx_ring_to_vector(adapter, i, v_idx++);
1153 }
1154 for (; i < adapter->num_tx_queues; i++)
1155 igb_map_tx_ring_to_vector(adapter, i, v_idx++);
1156 }
1157 return 0;
1158}
1159
1160/**
1161 * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors
1162 *
1163 * This function initializes the interrupts and allocates all of the queues.
1164 **/
1165static int igb_init_interrupt_scheme(struct igb_adapter *adapter)
1166{
1167 struct pci_dev *pdev = adapter->pdev;
1168 int err;
1169
Ben Hutchings21adef32010-09-27 08:28:39 +00001170 err = igb_set_interrupt_capability(adapter);
1171 if (err)
1172 return err;
Alexander Duyck047e0032009-10-27 15:49:27 +00001173
1174 err = igb_alloc_q_vectors(adapter);
1175 if (err) {
1176 dev_err(&pdev->dev, "Unable to allocate memory for vectors\n");
1177 goto err_alloc_q_vectors;
1178 }
1179
1180 err = igb_alloc_queues(adapter);
1181 if (err) {
1182 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
1183 goto err_alloc_queues;
1184 }
1185
1186 err = igb_map_ring_to_vector(adapter);
1187 if (err) {
1188 dev_err(&pdev->dev, "Invalid q_vector to ring mapping\n");
1189 goto err_map_queues;
1190 }
1191
1192
1193 return 0;
1194err_map_queues:
1195 igb_free_queues(adapter);
1196err_alloc_queues:
1197 igb_free_q_vectors(adapter);
1198err_alloc_q_vectors:
1199 igb_reset_interrupt_capability(adapter);
1200 return err;
1201}
1202
1203/**
Auke Kok9d5c8242008-01-24 02:22:38 -08001204 * igb_request_irq - initialize interrupts
1205 *
1206 * Attempts to configure interrupts using the best available
1207 * capabilities of the hardware and kernel.
1208 **/
1209static int igb_request_irq(struct igb_adapter *adapter)
1210{
1211 struct net_device *netdev = adapter->netdev;
Alexander Duyck047e0032009-10-27 15:49:27 +00001212 struct pci_dev *pdev = adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08001213 int err = 0;
1214
1215 if (adapter->msix_entries) {
1216 err = igb_request_msix(adapter);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001217 if (!err)
Auke Kok9d5c8242008-01-24 02:22:38 -08001218 goto request_done;
Auke Kok9d5c8242008-01-24 02:22:38 -08001219 /* fall back to MSI */
Alexander Duyck047e0032009-10-27 15:49:27 +00001220 igb_clear_interrupt_scheme(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001221 if (!pci_enable_msi(adapter->pdev))
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07001222 adapter->flags |= IGB_FLAG_HAS_MSI;
Auke Kok9d5c8242008-01-24 02:22:38 -08001223 igb_free_all_tx_resources(adapter);
1224 igb_free_all_rx_resources(adapter);
Alexander Duyck047e0032009-10-27 15:49:27 +00001225 adapter->num_tx_queues = 1;
Auke Kok9d5c8242008-01-24 02:22:38 -08001226 adapter->num_rx_queues = 1;
Alexander Duyck047e0032009-10-27 15:49:27 +00001227 adapter->num_q_vectors = 1;
1228 err = igb_alloc_q_vectors(adapter);
1229 if (err) {
1230 dev_err(&pdev->dev,
1231 "Unable to allocate memory for vectors\n");
1232 goto request_done;
1233 }
1234 err = igb_alloc_queues(adapter);
1235 if (err) {
1236 dev_err(&pdev->dev,
1237 "Unable to allocate memory for queues\n");
1238 igb_free_q_vectors(adapter);
1239 goto request_done;
1240 }
1241 igb_setup_all_tx_resources(adapter);
1242 igb_setup_all_rx_resources(adapter);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001243 } else {
Alexander Duyckfeeb2722010-02-03 21:59:51 +00001244 igb_assign_vector(adapter->q_vector[0], 0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001245 }
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001246
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07001247 if (adapter->flags & IGB_FLAG_HAS_MSI) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001248 err = request_irq(adapter->pdev->irq, igb_intr_msi, 0,
Alexander Duyck047e0032009-10-27 15:49:27 +00001249 netdev->name, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001250 if (!err)
1251 goto request_done;
Alexander Duyck047e0032009-10-27 15:49:27 +00001252
Auke Kok9d5c8242008-01-24 02:22:38 -08001253 /* fall back to legacy interrupts */
1254 igb_reset_interrupt_capability(adapter);
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07001255 adapter->flags &= ~IGB_FLAG_HAS_MSI;
Auke Kok9d5c8242008-01-24 02:22:38 -08001256 }
1257
Joe Perchesa0607fd2009-11-18 23:29:17 -08001258 err = request_irq(adapter->pdev->irq, igb_intr, IRQF_SHARED,
Alexander Duyck047e0032009-10-27 15:49:27 +00001259 netdev->name, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001260
Andy Gospodarek6cb5e572008-02-15 14:05:25 -08001261 if (err)
Auke Kok9d5c8242008-01-24 02:22:38 -08001262 dev_err(&adapter->pdev->dev, "Error %d getting interrupt\n",
1263 err);
Auke Kok9d5c8242008-01-24 02:22:38 -08001264
1265request_done:
1266 return err;
1267}
1268
1269static void igb_free_irq(struct igb_adapter *adapter)
1270{
Auke Kok9d5c8242008-01-24 02:22:38 -08001271 if (adapter->msix_entries) {
1272 int vector = 0, i;
1273
Alexander Duyck047e0032009-10-27 15:49:27 +00001274 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001275
Alexander Duyck047e0032009-10-27 15:49:27 +00001276 for (i = 0; i < adapter->num_q_vectors; i++) {
1277 struct igb_q_vector *q_vector = adapter->q_vector[i];
1278 free_irq(adapter->msix_entries[vector++].vector,
1279 q_vector);
1280 }
1281 } else {
1282 free_irq(adapter->pdev->irq, adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001283 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001284}
1285
1286/**
1287 * igb_irq_disable - Mask off interrupt generation on the NIC
1288 * @adapter: board private structure
1289 **/
1290static void igb_irq_disable(struct igb_adapter *adapter)
1291{
1292 struct e1000_hw *hw = &adapter->hw;
1293
Alexander Duyck25568a52009-10-27 23:49:59 +00001294 /*
1295 * we need to be careful when disabling interrupts. The VFs are also
1296 * mapped into these registers and so clearing the bits can cause
1297 * issues on the VF drivers so we only need to clear what we set
1298 */
Auke Kok9d5c8242008-01-24 02:22:38 -08001299 if (adapter->msix_entries) {
Alexander Duyck2dfd1212009-09-03 14:49:15 +00001300 u32 regval = rd32(E1000_EIAM);
1301 wr32(E1000_EIAM, regval & ~adapter->eims_enable_mask);
1302 wr32(E1000_EIMC, adapter->eims_enable_mask);
1303 regval = rd32(E1000_EIAC);
1304 wr32(E1000_EIAC, regval & ~adapter->eims_enable_mask);
Auke Kok9d5c8242008-01-24 02:22:38 -08001305 }
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001306
1307 wr32(E1000_IAM, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001308 wr32(E1000_IMC, ~0);
1309 wrfl();
Emil Tantilov81a61852010-08-02 14:40:52 +00001310 if (adapter->msix_entries) {
1311 int i;
1312 for (i = 0; i < adapter->num_q_vectors; i++)
1313 synchronize_irq(adapter->msix_entries[i].vector);
1314 } else {
1315 synchronize_irq(adapter->pdev->irq);
1316 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001317}
1318
1319/**
1320 * igb_irq_enable - Enable default interrupt generation settings
1321 * @adapter: board private structure
1322 **/
1323static void igb_irq_enable(struct igb_adapter *adapter)
1324{
1325 struct e1000_hw *hw = &adapter->hw;
1326
1327 if (adapter->msix_entries) {
Alexander Duyck25568a52009-10-27 23:49:59 +00001328 u32 ims = E1000_IMS_LSC | E1000_IMS_DOUTSYNC;
Alexander Duyck2dfd1212009-09-03 14:49:15 +00001329 u32 regval = rd32(E1000_EIAC);
1330 wr32(E1000_EIAC, regval | adapter->eims_enable_mask);
1331 regval = rd32(E1000_EIAM);
1332 wr32(E1000_EIAM, regval | adapter->eims_enable_mask);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001333 wr32(E1000_EIMS, adapter->eims_enable_mask);
Alexander Duyck25568a52009-10-27 23:49:59 +00001334 if (adapter->vfs_allocated_count) {
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001335 wr32(E1000_MBVFIMR, 0xFF);
Alexander Duyck25568a52009-10-27 23:49:59 +00001336 ims |= E1000_IMS_VMMB;
1337 }
Alexander Duyck55cac242009-11-19 12:42:21 +00001338 if (adapter->hw.mac.type == e1000_82580)
1339 ims |= E1000_IMS_DRSTA;
1340
Alexander Duyck25568a52009-10-27 23:49:59 +00001341 wr32(E1000_IMS, ims);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001342 } else {
Alexander Duyck55cac242009-11-19 12:42:21 +00001343 wr32(E1000_IMS, IMS_ENABLE_MASK |
1344 E1000_IMS_DRSTA);
1345 wr32(E1000_IAM, IMS_ENABLE_MASK |
1346 E1000_IMS_DRSTA);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001347 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001348}
1349
1350static void igb_update_mng_vlan(struct igb_adapter *adapter)
1351{
Alexander Duyck51466232009-10-27 23:47:35 +00001352 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08001353 u16 vid = adapter->hw.mng_cookie.vlan_id;
1354 u16 old_vid = adapter->mng_vlan_id;
Auke Kok9d5c8242008-01-24 02:22:38 -08001355
Alexander Duyck51466232009-10-27 23:47:35 +00001356 if (hw->mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
1357 /* add VID to filter table */
1358 igb_vfta_set(hw, vid, true);
1359 adapter->mng_vlan_id = vid;
1360 } else {
1361 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
1362 }
1363
1364 if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
1365 (vid != old_vid) &&
1366 !vlan_group_get_device(adapter->vlgrp, old_vid)) {
1367 /* remove VID from filter table */
1368 igb_vfta_set(hw, old_vid, false);
Auke Kok9d5c8242008-01-24 02:22:38 -08001369 }
1370}
1371
1372/**
1373 * igb_release_hw_control - release control of the h/w to f/w
1374 * @adapter: address of board private structure
1375 *
1376 * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
1377 * For ASF and Pass Through versions of f/w this means that the
1378 * driver is no longer loaded.
1379 *
1380 **/
1381static void igb_release_hw_control(struct igb_adapter *adapter)
1382{
1383 struct e1000_hw *hw = &adapter->hw;
1384 u32 ctrl_ext;
1385
1386 /* Let firmware take over control of h/w */
1387 ctrl_ext = rd32(E1000_CTRL_EXT);
1388 wr32(E1000_CTRL_EXT,
1389 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1390}
1391
Auke Kok9d5c8242008-01-24 02:22:38 -08001392/**
1393 * igb_get_hw_control - get control of the h/w from f/w
1394 * @adapter: address of board private structure
1395 *
1396 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
1397 * For ASF and Pass Through versions of f/w this means that
1398 * the driver is loaded.
1399 *
1400 **/
1401static void igb_get_hw_control(struct igb_adapter *adapter)
1402{
1403 struct e1000_hw *hw = &adapter->hw;
1404 u32 ctrl_ext;
1405
1406 /* Let firmware know the driver has taken over */
1407 ctrl_ext = rd32(E1000_CTRL_EXT);
1408 wr32(E1000_CTRL_EXT,
1409 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1410}
1411
Auke Kok9d5c8242008-01-24 02:22:38 -08001412/**
1413 * igb_configure - configure the hardware for RX and TX
1414 * @adapter: private board structure
1415 **/
1416static void igb_configure(struct igb_adapter *adapter)
1417{
1418 struct net_device *netdev = adapter->netdev;
1419 int i;
1420
1421 igb_get_hw_control(adapter);
Alexander Duyckff41f8d2009-09-03 14:48:56 +00001422 igb_set_rx_mode(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001423
1424 igb_restore_vlan(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001425
Alexander Duyck85b430b2009-10-27 15:50:29 +00001426 igb_setup_tctl(adapter);
Alexander Duyck06cf2662009-10-27 15:53:25 +00001427 igb_setup_mrqc(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001428 igb_setup_rctl(adapter);
Alexander Duyck85b430b2009-10-27 15:50:29 +00001429
1430 igb_configure_tx(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001431 igb_configure_rx(adapter);
Alexander Duyck662d7202008-06-27 11:00:29 -07001432
1433 igb_rx_fifo_flush_82575(&adapter->hw);
1434
Alexander Duyckc493ea42009-03-20 00:16:50 +00001435 /* call igb_desc_unused which always leaves
Auke Kok9d5c8242008-01-24 02:22:38 -08001436 * at least 1 descriptor unused to make sure
1437 * next_to_use != next_to_clean */
1438 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +00001439 struct igb_ring *ring = adapter->rx_ring[i];
Alexander Duyckc493ea42009-03-20 00:16:50 +00001440 igb_alloc_rx_buffers_adv(ring, igb_desc_unused(ring));
Auke Kok9d5c8242008-01-24 02:22:38 -08001441 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001442}
1443
Nick Nunley88a268c2010-02-17 01:01:59 +00001444/**
1445 * igb_power_up_link - Power up the phy/serdes link
1446 * @adapter: address of board private structure
1447 **/
1448void igb_power_up_link(struct igb_adapter *adapter)
1449{
1450 if (adapter->hw.phy.media_type == e1000_media_type_copper)
1451 igb_power_up_phy_copper(&adapter->hw);
1452 else
1453 igb_power_up_serdes_link_82575(&adapter->hw);
1454}
1455
1456/**
1457 * igb_power_down_link - Power down the phy/serdes link
1458 * @adapter: address of board private structure
1459 */
1460static void igb_power_down_link(struct igb_adapter *adapter)
1461{
1462 if (adapter->hw.phy.media_type == e1000_media_type_copper)
1463 igb_power_down_phy_copper_82575(&adapter->hw);
1464 else
1465 igb_shutdown_serdes_link_82575(&adapter->hw);
1466}
Auke Kok9d5c8242008-01-24 02:22:38 -08001467
1468/**
1469 * igb_up - Open the interface and prepare it to handle traffic
1470 * @adapter: board private structure
1471 **/
Auke Kok9d5c8242008-01-24 02:22:38 -08001472int igb_up(struct igb_adapter *adapter)
1473{
1474 struct e1000_hw *hw = &adapter->hw;
1475 int i;
1476
1477 /* hardware has been reset, we need to reload some things */
1478 igb_configure(adapter);
1479
1480 clear_bit(__IGB_DOWN, &adapter->state);
1481
Alexander Duyck047e0032009-10-27 15:49:27 +00001482 for (i = 0; i < adapter->num_q_vectors; i++) {
1483 struct igb_q_vector *q_vector = adapter->q_vector[i];
1484 napi_enable(&q_vector->napi);
1485 }
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001486 if (adapter->msix_entries)
Auke Kok9d5c8242008-01-24 02:22:38 -08001487 igb_configure_msix(adapter);
Alexander Duyckfeeb2722010-02-03 21:59:51 +00001488 else
1489 igb_assign_vector(adapter->q_vector[0], 0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001490
1491 /* Clear any pending interrupts. */
1492 rd32(E1000_ICR);
1493 igb_irq_enable(adapter);
1494
Alexander Duyckd4960302009-10-27 15:53:45 +00001495 /* notify VFs that reset has been completed */
1496 if (adapter->vfs_allocated_count) {
1497 u32 reg_data = rd32(E1000_CTRL_EXT);
1498 reg_data |= E1000_CTRL_EXT_PFRSTD;
1499 wr32(E1000_CTRL_EXT, reg_data);
1500 }
1501
Jesse Brandeburg4cb9be72009-04-21 18:42:05 +00001502 netif_tx_start_all_queues(adapter->netdev);
1503
Alexander Duyck25568a52009-10-27 23:49:59 +00001504 /* start the watchdog. */
1505 hw->mac.get_link_status = 1;
1506 schedule_work(&adapter->watchdog_task);
1507
Auke Kok9d5c8242008-01-24 02:22:38 -08001508 return 0;
1509}
1510
1511void igb_down(struct igb_adapter *adapter)
1512{
Auke Kok9d5c8242008-01-24 02:22:38 -08001513 struct net_device *netdev = adapter->netdev;
Alexander Duyck330a6d62009-10-27 23:51:35 +00001514 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08001515 u32 tctl, rctl;
1516 int i;
1517
1518 /* signal that we're down so the interrupt handler does not
1519 * reschedule our watchdog timer */
1520 set_bit(__IGB_DOWN, &adapter->state);
1521
1522 /* disable receives in the hardware */
1523 rctl = rd32(E1000_RCTL);
1524 wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
1525 /* flush and sleep below */
1526
David S. Millerfd2ea0a2008-07-17 01:56:23 -07001527 netif_tx_stop_all_queues(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001528
1529 /* disable transmits in the hardware */
1530 tctl = rd32(E1000_TCTL);
1531 tctl &= ~E1000_TCTL_EN;
1532 wr32(E1000_TCTL, tctl);
1533 /* flush both disables and wait for them to finish */
1534 wrfl();
1535 msleep(10);
1536
Alexander Duyck047e0032009-10-27 15:49:27 +00001537 for (i = 0; i < adapter->num_q_vectors; i++) {
1538 struct igb_q_vector *q_vector = adapter->q_vector[i];
1539 napi_disable(&q_vector->napi);
1540 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001541
Auke Kok9d5c8242008-01-24 02:22:38 -08001542 igb_irq_disable(adapter);
1543
1544 del_timer_sync(&adapter->watchdog_timer);
1545 del_timer_sync(&adapter->phy_info_timer);
1546
Auke Kok9d5c8242008-01-24 02:22:38 -08001547 netif_carrier_off(netdev);
Alexander Duyck04fe6352009-02-06 23:22:32 +00001548
1549 /* record the stats before reset*/
Eric Dumazet12dcd862010-10-15 17:27:10 +00001550 spin_lock(&adapter->stats64_lock);
1551 igb_update_stats(adapter, &adapter->stats64);
1552 spin_unlock(&adapter->stats64_lock);
Alexander Duyck04fe6352009-02-06 23:22:32 +00001553
Auke Kok9d5c8242008-01-24 02:22:38 -08001554 adapter->link_speed = 0;
1555 adapter->link_duplex = 0;
1556
Jeff Kirsher30236822008-06-24 17:01:15 -07001557 if (!pci_channel_offline(adapter->pdev))
1558 igb_reset(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001559 igb_clean_all_tx_rings(adapter);
1560 igb_clean_all_rx_rings(adapter);
Alexander Duyck7e0e99e2009-05-21 13:06:56 +00001561#ifdef CONFIG_IGB_DCA
1562
1563 /* since we reset the hardware DCA settings were cleared */
1564 igb_setup_dca(adapter);
1565#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08001566}
1567
1568void igb_reinit_locked(struct igb_adapter *adapter)
1569{
1570 WARN_ON(in_interrupt());
1571 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
1572 msleep(1);
1573 igb_down(adapter);
1574 igb_up(adapter);
1575 clear_bit(__IGB_RESETTING, &adapter->state);
1576}
1577
1578void igb_reset(struct igb_adapter *adapter)
1579{
Alexander Duyck090b1792009-10-27 23:51:55 +00001580 struct pci_dev *pdev = adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08001581 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001582 struct e1000_mac_info *mac = &hw->mac;
1583 struct e1000_fc_info *fc = &hw->fc;
Auke Kok9d5c8242008-01-24 02:22:38 -08001584 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
1585 u16 hwm;
1586
1587 /* Repartition Pba for greater than 9k mtu
1588 * To take effect CTRL.RST is required.
1589 */
Alexander Duyckfa4dfae2009-02-06 23:21:31 +00001590 switch (mac->type) {
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00001591 case e1000_i350:
Alexander Duyck55cac242009-11-19 12:42:21 +00001592 case e1000_82580:
1593 pba = rd32(E1000_RXPBS);
1594 pba = igb_rxpbs_adjust_82580(pba);
1595 break;
Alexander Duyckfa4dfae2009-02-06 23:21:31 +00001596 case e1000_82576:
Alexander Duyckd249be52009-10-27 23:46:38 +00001597 pba = rd32(E1000_RXPBS);
1598 pba &= E1000_RXPBS_SIZE_MASK_82576;
Alexander Duyckfa4dfae2009-02-06 23:21:31 +00001599 break;
1600 case e1000_82575:
1601 default:
1602 pba = E1000_PBA_34K;
1603 break;
Alexander Duyck2d064c02008-07-08 15:10:12 -07001604 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001605
Alexander Duyck2d064c02008-07-08 15:10:12 -07001606 if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) &&
1607 (mac->type < e1000_82576)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001608 /* adjust PBA for jumbo frames */
1609 wr32(E1000_PBA, pba);
1610
1611 /* To maintain wire speed transmits, the Tx FIFO should be
1612 * large enough to accommodate two full transmit packets,
1613 * rounded up to the next 1KB and expressed in KB. Likewise,
1614 * the Rx FIFO should be large enough to accommodate at least
1615 * one full receive packet and is similarly rounded up and
1616 * expressed in KB. */
1617 pba = rd32(E1000_PBA);
1618 /* upper 16 bits has Tx packet buffer allocation size in KB */
1619 tx_space = pba >> 16;
1620 /* lower 16 bits has Rx packet buffer allocation size in KB */
1621 pba &= 0xffff;
1622 /* the tx fifo also stores 16 bytes of information about the tx
1623 * but don't include ethernet FCS because hardware appends it */
1624 min_tx_space = (adapter->max_frame_size +
Alexander Duyck85e8d002009-02-16 00:00:20 -08001625 sizeof(union e1000_adv_tx_desc) -
Auke Kok9d5c8242008-01-24 02:22:38 -08001626 ETH_FCS_LEN) * 2;
1627 min_tx_space = ALIGN(min_tx_space, 1024);
1628 min_tx_space >>= 10;
1629 /* software strips receive CRC, so leave room for it */
1630 min_rx_space = adapter->max_frame_size;
1631 min_rx_space = ALIGN(min_rx_space, 1024);
1632 min_rx_space >>= 10;
1633
1634 /* If current Tx allocation is less than the min Tx FIFO size,
1635 * and the min Tx FIFO size is less than the current Rx FIFO
1636 * allocation, take space away from current Rx allocation */
1637 if (tx_space < min_tx_space &&
1638 ((min_tx_space - tx_space) < pba)) {
1639 pba = pba - (min_tx_space - tx_space);
1640
1641 /* if short on rx space, rx wins and must trump tx
1642 * adjustment */
1643 if (pba < min_rx_space)
1644 pba = min_rx_space;
1645 }
Alexander Duyck2d064c02008-07-08 15:10:12 -07001646 wr32(E1000_PBA, pba);
Auke Kok9d5c8242008-01-24 02:22:38 -08001647 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001648
1649 /* flow control settings */
1650 /* The high water mark must be low enough to fit one full frame
1651 * (or the size used for early receive) above it in the Rx FIFO.
1652 * Set it to the lower of:
1653 * - 90% of the Rx FIFO size, or
1654 * - the full Rx FIFO size minus one full frame */
1655 hwm = min(((pba << 10) * 9 / 10),
Alexander Duyck2d064c02008-07-08 15:10:12 -07001656 ((pba << 10) - 2 * adapter->max_frame_size));
Auke Kok9d5c8242008-01-24 02:22:38 -08001657
Alexander Duyckd405ea32009-12-23 13:21:27 +00001658 fc->high_water = hwm & 0xFFF0; /* 16-byte granularity */
1659 fc->low_water = fc->high_water - 16;
Auke Kok9d5c8242008-01-24 02:22:38 -08001660 fc->pause_time = 0xFFFF;
1661 fc->send_xon = 1;
Alexander Duyck0cce1192009-07-23 18:10:24 +00001662 fc->current_mode = fc->requested_mode;
Auke Kok9d5c8242008-01-24 02:22:38 -08001663
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001664 /* disable receive for all VFs and wait one second */
1665 if (adapter->vfs_allocated_count) {
1666 int i;
1667 for (i = 0 ; i < adapter->vfs_allocated_count; i++)
Greg Rose8fa7e0f2010-11-06 05:43:21 +00001668 adapter->vf_data[i].flags &= IGB_VF_FLAG_PF_SET_MAC;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001669
1670 /* ping all the active vfs to let them know we are going down */
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00001671 igb_ping_all_vfs(adapter);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08001672
1673 /* disable transmits and receives */
1674 wr32(E1000_VFRE, 0);
1675 wr32(E1000_VFTE, 0);
1676 }
1677
Auke Kok9d5c8242008-01-24 02:22:38 -08001678 /* Allow time for pending master requests to run */
Alexander Duyck330a6d62009-10-27 23:51:35 +00001679 hw->mac.ops.reset_hw(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001680 wr32(E1000_WUC, 0);
1681
Alexander Duyck330a6d62009-10-27 23:51:35 +00001682 if (hw->mac.ops.init_hw(hw))
Alexander Duyck090b1792009-10-27 23:51:55 +00001683 dev_err(&pdev->dev, "Hardware Error\n");
Carolyn Wyborny831ec0b2011-03-11 20:43:54 -08001684 if (hw->mac.type > e1000_82580) {
1685 if (adapter->flags & IGB_FLAG_DMAC) {
1686 u32 reg;
Auke Kok9d5c8242008-01-24 02:22:38 -08001687
Carolyn Wyborny831ec0b2011-03-11 20:43:54 -08001688 /*
1689 * DMA Coalescing high water mark needs to be higher
1690 * than * the * Rx threshold. The Rx threshold is
1691 * currently * pba - 6, so we * should use a high water
1692 * mark of pba * - 4. */
1693 hwm = (pba - 4) << 10;
1694
1695 reg = (((pba-6) << E1000_DMACR_DMACTHR_SHIFT)
1696 & E1000_DMACR_DMACTHR_MASK);
1697
1698 /* transition to L0x or L1 if available..*/
1699 reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK);
1700
1701 /* watchdog timer= +-1000 usec in 32usec intervals */
1702 reg |= (1000 >> 5);
1703 wr32(E1000_DMACR, reg);
1704
1705 /* no lower threshold to disable coalescing(smart fifb)
1706 * -UTRESH=0*/
1707 wr32(E1000_DMCRTRH, 0);
1708
1709 /* set hwm to PBA - 2 * max frame size */
1710 wr32(E1000_FCRTC, hwm);
1711
1712 /*
1713 * This sets the time to wait before requesting tran-
1714 * sition to * low power state to number of usecs needed
1715 * to receive 1 512 * byte frame at gigabit line rate
1716 */
1717 reg = rd32(E1000_DMCTLX);
1718 reg |= IGB_DMCTLX_DCFLUSH_DIS;
1719
1720 /* Delay 255 usec before entering Lx state. */
1721 reg |= 0xFF;
1722 wr32(E1000_DMCTLX, reg);
1723
1724 /* free space in Tx packet buffer to wake from DMAC */
1725 wr32(E1000_DMCTXTH,
1726 (IGB_MIN_TXPBSIZE -
1727 (IGB_TX_BUF_4096 + adapter->max_frame_size))
1728 >> 6);
1729
1730 /* make low power state decision controlled by DMAC */
1731 reg = rd32(E1000_PCIEMISC);
1732 reg |= E1000_PCIEMISC_LX_DECISION;
1733 wr32(E1000_PCIEMISC, reg);
1734 } /* end if IGB_FLAG_DMAC set */
1735 }
Alexander Duyck55cac242009-11-19 12:42:21 +00001736 if (hw->mac.type == e1000_82580) {
1737 u32 reg = rd32(E1000_PCIEMISC);
1738 wr32(E1000_PCIEMISC,
1739 reg & ~E1000_PCIEMISC_LX_DECISION);
1740 }
Nick Nunley88a268c2010-02-17 01:01:59 +00001741 if (!netif_running(adapter->netdev))
1742 igb_power_down_link(adapter);
1743
Auke Kok9d5c8242008-01-24 02:22:38 -08001744 igb_update_mng_vlan(adapter);
1745
1746 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
1747 wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
1748
Alexander Duyck330a6d62009-10-27 23:51:35 +00001749 igb_get_phy_info(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001750}
1751
Stephen Hemminger2e5c6922008-11-19 22:20:44 -08001752static const struct net_device_ops igb_netdev_ops = {
Alexander Duyck559e9c42009-10-27 23:52:50 +00001753 .ndo_open = igb_open,
Stephen Hemminger2e5c6922008-11-19 22:20:44 -08001754 .ndo_stop = igb_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08001755 .ndo_start_xmit = igb_xmit_frame_adv,
Eric Dumazet12dcd862010-10-15 17:27:10 +00001756 .ndo_get_stats64 = igb_get_stats64,
Alexander Duyckff41f8d2009-09-03 14:48:56 +00001757 .ndo_set_rx_mode = igb_set_rx_mode,
1758 .ndo_set_multicast_list = igb_set_rx_mode,
Stephen Hemminger2e5c6922008-11-19 22:20:44 -08001759 .ndo_set_mac_address = igb_set_mac,
1760 .ndo_change_mtu = igb_change_mtu,
1761 .ndo_do_ioctl = igb_ioctl,
1762 .ndo_tx_timeout = igb_tx_timeout,
1763 .ndo_validate_addr = eth_validate_addr,
1764 .ndo_vlan_rx_register = igb_vlan_rx_register,
1765 .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid,
1766 .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid,
Williams, Mitch A8151d292010-02-10 01:44:24 +00001767 .ndo_set_vf_mac = igb_ndo_set_vf_mac,
1768 .ndo_set_vf_vlan = igb_ndo_set_vf_vlan,
1769 .ndo_set_vf_tx_rate = igb_ndo_set_vf_bw,
1770 .ndo_get_vf_config = igb_ndo_get_vf_config,
Stephen Hemminger2e5c6922008-11-19 22:20:44 -08001771#ifdef CONFIG_NET_POLL_CONTROLLER
1772 .ndo_poll_controller = igb_netpoll,
1773#endif
1774};
1775
Taku Izumi42bfd33a2008-06-20 12:10:30 +09001776/**
Auke Kok9d5c8242008-01-24 02:22:38 -08001777 * igb_probe - Device Initialization Routine
1778 * @pdev: PCI device information struct
1779 * @ent: entry in igb_pci_tbl
1780 *
1781 * Returns 0 on success, negative on failure
1782 *
1783 * igb_probe initializes an adapter identified by a pci_dev structure.
1784 * The OS initialization, configuring of the adapter private structure,
1785 * and a hardware reset occur.
1786 **/
1787static int __devinit igb_probe(struct pci_dev *pdev,
1788 const struct pci_device_id *ent)
1789{
1790 struct net_device *netdev;
1791 struct igb_adapter *adapter;
1792 struct e1000_hw *hw;
Alexander Duyck4337e992009-10-27 23:48:31 +00001793 u16 eeprom_data = 0;
Carolyn Wyborny9835fd72010-11-22 17:17:21 +00001794 s32 ret_val;
Alexander Duyck4337e992009-10-27 23:48:31 +00001795 static int global_quad_port_a; /* global quad port a indication */
Auke Kok9d5c8242008-01-24 02:22:38 -08001796 const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
1797 unsigned long mmio_start, mmio_len;
David S. Miller2d6a5e92009-03-17 15:01:30 -07001798 int err, pci_using_dac;
Auke Kok9d5c8242008-01-24 02:22:38 -08001799 u16 eeprom_apme_mask = IGB_EEPROM_APME;
Carolyn Wyborny9835fd72010-11-22 17:17:21 +00001800 u8 part_str[E1000_PBANUM_LENGTH];
Auke Kok9d5c8242008-01-24 02:22:38 -08001801
Andy Gospodarekbded64a2010-07-21 06:40:31 +00001802 /* Catch broken hardware that put the wrong VF device ID in
1803 * the PCIe SR-IOV capability.
1804 */
1805 if (pdev->is_virtfn) {
1806 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
1807 pci_name(pdev), pdev->vendor, pdev->device);
1808 return -EINVAL;
1809 }
1810
Alexander Duyckaed5dec2009-02-06 23:16:04 +00001811 err = pci_enable_device_mem(pdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001812 if (err)
1813 return err;
1814
1815 pci_using_dac = 0;
Alexander Duyck59d71982010-04-27 13:09:25 +00001816 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kok9d5c8242008-01-24 02:22:38 -08001817 if (!err) {
Alexander Duyck59d71982010-04-27 13:09:25 +00001818 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
Auke Kok9d5c8242008-01-24 02:22:38 -08001819 if (!err)
1820 pci_using_dac = 1;
1821 } else {
Alexander Duyck59d71982010-04-27 13:09:25 +00001822 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9d5c8242008-01-24 02:22:38 -08001823 if (err) {
Alexander Duyck59d71982010-04-27 13:09:25 +00001824 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9d5c8242008-01-24 02:22:38 -08001825 if (err) {
1826 dev_err(&pdev->dev, "No usable DMA "
1827 "configuration, aborting\n");
1828 goto err_dma;
1829 }
1830 }
1831 }
1832
Alexander Duyckaed5dec2009-02-06 23:16:04 +00001833 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
1834 IORESOURCE_MEM),
1835 igb_driver_name);
Auke Kok9d5c8242008-01-24 02:22:38 -08001836 if (err)
1837 goto err_pci_reg;
1838
Frans Pop19d5afd2009-10-02 10:04:12 -07001839 pci_enable_pcie_error_reporting(pdev);
Alexander Duyck40a914f2008-11-27 00:24:37 -08001840
Auke Kok9d5c8242008-01-24 02:22:38 -08001841 pci_set_master(pdev);
Auke Kokc682fc22008-04-23 11:09:34 -07001842 pci_save_state(pdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001843
1844 err = -ENOMEM;
Alexander Duyck1bfaf072009-02-19 20:39:23 -08001845 netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
1846 IGB_ABS_MAX_TX_QUEUES);
Auke Kok9d5c8242008-01-24 02:22:38 -08001847 if (!netdev)
1848 goto err_alloc_etherdev;
1849
1850 SET_NETDEV_DEV(netdev, &pdev->dev);
1851
1852 pci_set_drvdata(pdev, netdev);
1853 adapter = netdev_priv(netdev);
1854 adapter->netdev = netdev;
1855 adapter->pdev = pdev;
1856 hw = &adapter->hw;
1857 hw->back = adapter;
1858 adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE;
1859
1860 mmio_start = pci_resource_start(pdev, 0);
1861 mmio_len = pci_resource_len(pdev, 0);
1862
1863 err = -EIO;
Alexander Duyck28b07592009-02-06 23:20:31 +00001864 hw->hw_addr = ioremap(mmio_start, mmio_len);
1865 if (!hw->hw_addr)
Auke Kok9d5c8242008-01-24 02:22:38 -08001866 goto err_ioremap;
1867
Stephen Hemminger2e5c6922008-11-19 22:20:44 -08001868 netdev->netdev_ops = &igb_netdev_ops;
Auke Kok9d5c8242008-01-24 02:22:38 -08001869 igb_set_ethtool_ops(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001870 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9d5c8242008-01-24 02:22:38 -08001871
1872 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
1873
1874 netdev->mem_start = mmio_start;
1875 netdev->mem_end = mmio_start + mmio_len;
1876
Auke Kok9d5c8242008-01-24 02:22:38 -08001877 /* PCI config space info */
1878 hw->vendor_id = pdev->vendor;
1879 hw->device_id = pdev->device;
1880 hw->revision_id = pdev->revision;
1881 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1882 hw->subsystem_device_id = pdev->subsystem_device;
1883
Auke Kok9d5c8242008-01-24 02:22:38 -08001884 /* Copy the default MAC, PHY and NVM function pointers */
1885 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
1886 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
1887 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
1888 /* Initialize skew-specific constants */
1889 err = ei->get_invariants(hw);
1890 if (err)
Alexander Duyck450c87c2009-02-06 23:22:11 +00001891 goto err_sw_init;
Auke Kok9d5c8242008-01-24 02:22:38 -08001892
Alexander Duyck450c87c2009-02-06 23:22:11 +00001893 /* setup the private structure */
Auke Kok9d5c8242008-01-24 02:22:38 -08001894 err = igb_sw_init(adapter);
1895 if (err)
1896 goto err_sw_init;
1897
1898 igb_get_bus_info_pcie(hw);
1899
1900 hw->phy.autoneg_wait_to_complete = false;
Auke Kok9d5c8242008-01-24 02:22:38 -08001901
1902 /* Copper options */
1903 if (hw->phy.media_type == e1000_media_type_copper) {
1904 hw->phy.mdix = AUTO_ALL_MODES;
1905 hw->phy.disable_polarity_correction = false;
1906 hw->phy.ms_type = e1000_ms_hw_default;
1907 }
1908
1909 if (igb_check_reset_block(hw))
1910 dev_info(&pdev->dev,
1911 "PHY reset is blocked due to SOL/IDER session.\n");
1912
1913 netdev->features = NETIF_F_SG |
Alexander Duyck7d8eb292009-02-06 23:18:27 +00001914 NETIF_F_IP_CSUM |
Auke Kok9d5c8242008-01-24 02:22:38 -08001915 NETIF_F_HW_VLAN_TX |
1916 NETIF_F_HW_VLAN_RX |
1917 NETIF_F_HW_VLAN_FILTER;
1918
Alexander Duyck7d8eb292009-02-06 23:18:27 +00001919 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9d5c8242008-01-24 02:22:38 -08001920 netdev->features |= NETIF_F_TSO;
Auke Kok9d5c8242008-01-24 02:22:38 -08001921 netdev->features |= NETIF_F_TSO6;
Herbert Xu5c0999b2009-01-19 15:20:57 -08001922 netdev->features |= NETIF_F_GRO;
Alexander Duyckd3352522008-07-08 15:12:13 -07001923
Jeff Kirsher48f29ff2008-06-05 04:06:27 -07001924 netdev->vlan_features |= NETIF_F_TSO;
1925 netdev->vlan_features |= NETIF_F_TSO6;
Alexander Duyck7d8eb292009-02-06 23:18:27 +00001926 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00001927 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsher48f29ff2008-06-05 04:06:27 -07001928 netdev->vlan_features |= NETIF_F_SG;
1929
Yi Zou7b872a52010-09-22 17:57:58 +00001930 if (pci_using_dac) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001931 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00001932 netdev->vlan_features |= NETIF_F_HIGHDMA;
1933 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001934
Alexander Duyck5b043fb2009-10-27 23:52:31 +00001935 if (hw->mac.type >= e1000_82576)
Jesse Brandeburgb9473562009-04-27 22:36:13 +00001936 netdev->features |= NETIF_F_SCTP_CSUM;
1937
Alexander Duyck330a6d62009-10-27 23:51:35 +00001938 adapter->en_mng_pt = igb_enable_mng_pass_thru(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001939
1940 /* before reading the NVM, reset the controller to put the device in a
1941 * known good starting state */
1942 hw->mac.ops.reset_hw(hw);
1943
1944 /* make sure the NVM is good */
Carolyn Wyborny4322e562011-03-11 20:43:18 -08001945 if (hw->nvm.ops.validate(hw) < 0) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001946 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
1947 err = -EIO;
1948 goto err_eeprom;
1949 }
1950
1951 /* copy the MAC address out of the NVM */
1952 if (hw->mac.ops.read_mac_addr(hw))
1953 dev_err(&pdev->dev, "NVM Read Error\n");
1954
1955 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
1956 memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
1957
1958 if (!is_valid_ether_addr(netdev->perm_addr)) {
1959 dev_err(&pdev->dev, "Invalid MAC Address\n");
1960 err = -EIO;
1961 goto err_eeprom;
1962 }
1963
Joe Perchesc061b182010-08-23 18:20:03 +00001964 setup_timer(&adapter->watchdog_timer, igb_watchdog,
Alexander Duyck0e340482009-03-20 00:17:08 +00001965 (unsigned long) adapter);
Joe Perchesc061b182010-08-23 18:20:03 +00001966 setup_timer(&adapter->phy_info_timer, igb_update_phy_info,
Alexander Duyck0e340482009-03-20 00:17:08 +00001967 (unsigned long) adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001968
1969 INIT_WORK(&adapter->reset_task, igb_reset_task);
1970 INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
1971
Alexander Duyck450c87c2009-02-06 23:22:11 +00001972 /* Initialize link properties that are user-changeable */
Auke Kok9d5c8242008-01-24 02:22:38 -08001973 adapter->fc_autoneg = true;
1974 hw->mac.autoneg = true;
1975 hw->phy.autoneg_advertised = 0x2f;
1976
Alexander Duyck0cce1192009-07-23 18:10:24 +00001977 hw->fc.requested_mode = e1000_fc_default;
1978 hw->fc.current_mode = e1000_fc_default;
Auke Kok9d5c8242008-01-24 02:22:38 -08001979
Auke Kok9d5c8242008-01-24 02:22:38 -08001980 igb_validate_mdi_setting(hw);
1981
Auke Kok9d5c8242008-01-24 02:22:38 -08001982 /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM,
1983 * enable the ACPI Magic Packet filter
1984 */
1985
Alexander Duycka2cf8b62009-03-13 20:41:17 +00001986 if (hw->bus.func == 0)
Alexander Duyck312c75a2009-02-06 23:17:47 +00001987 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
Alexander Duyck55cac242009-11-19 12:42:21 +00001988 else if (hw->mac.type == e1000_82580)
1989 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
1990 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
1991 &eeprom_data);
Alexander Duycka2cf8b62009-03-13 20:41:17 +00001992 else if (hw->bus.func == 1)
1993 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001994
1995 if (eeprom_data & eeprom_apme_mask)
1996 adapter->eeprom_wol |= E1000_WUFC_MAG;
1997
1998 /* now that we have the eeprom settings, apply the special cases where
1999 * the eeprom may be wrong or the board simply won't support wake on
2000 * lan on a particular port */
2001 switch (pdev->device) {
2002 case E1000_DEV_ID_82575GB_QUAD_COPPER:
2003 adapter->eeprom_wol = 0;
2004 break;
2005 case E1000_DEV_ID_82575EB_FIBER_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -07002006 case E1000_DEV_ID_82576_FIBER:
2007 case E1000_DEV_ID_82576_SERDES:
Auke Kok9d5c8242008-01-24 02:22:38 -08002008 /* Wake events only supported on port A for dual fiber
2009 * regardless of eeprom setting */
2010 if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1)
2011 adapter->eeprom_wol = 0;
2012 break;
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +00002013 case E1000_DEV_ID_82576_QUAD_COPPER:
Stefan Assmannd5aa2252010-04-09 09:51:34 +00002014 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
Alexander Duyckc8ea5ea2009-03-13 20:42:35 +00002015 /* if quad port adapter, disable WoL on all but port A */
2016 if (global_quad_port_a != 0)
2017 adapter->eeprom_wol = 0;
2018 else
2019 adapter->flags |= IGB_FLAG_QUAD_PORT_A;
2020 /* Reset for multiple quad port adapters */
2021 if (++global_quad_port_a == 4)
2022 global_quad_port_a = 0;
2023 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08002024 }
2025
2026 /* initialize the wol settings based on the eeprom settings */
2027 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\e1b86d82008-11-07 20:30:37 +00002028 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kok9d5c8242008-01-24 02:22:38 -08002029
2030 /* reset the hardware with the new settings */
2031 igb_reset(adapter);
2032
2033 /* let the f/w know that the h/w is now under the control of the
2034 * driver. */
2035 igb_get_hw_control(adapter);
2036
Auke Kok9d5c8242008-01-24 02:22:38 -08002037 strcpy(netdev->name, "eth%d");
2038 err = register_netdev(netdev);
2039 if (err)
2040 goto err_register;
2041
Jesse Brandeburgb168dfc2009-04-17 20:44:32 +00002042 /* carrier off reporting is important to ethtool even BEFORE open */
2043 netif_carrier_off(netdev);
2044
Jeff Kirsher421e02f2008-10-17 11:08:31 -07002045#ifdef CONFIG_IGB_DCA
Alexander Duyckbbd98fe2009-01-31 00:52:30 -08002046 if (dca_add_requester(&pdev->dev) == 0) {
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07002047 adapter->flags |= IGB_FLAG_DCA_ENABLED;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07002048 dev_info(&pdev->dev, "DCA enabled\n");
Jeb Cramerfe4506b2008-07-08 15:07:55 -07002049 igb_setup_dca(adapter);
2050 }
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00002051
Jeb Cramerfe4506b2008-07-08 15:07:55 -07002052#endif
Anders Berggren673b8b72011-02-04 07:32:32 +00002053 /* do hw tstamp init after resetting */
2054 igb_init_hw_timer(adapter);
2055
Auke Kok9d5c8242008-01-24 02:22:38 -08002056 dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
2057 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07002058 dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n",
Auke Kok9d5c8242008-01-24 02:22:38 -08002059 netdev->name,
Alexander Duyck559e9c42009-10-27 23:52:50 +00002060 ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
Alexander Duyckff846f52010-04-27 01:02:40 +00002061 (hw->bus.speed == e1000_bus_speed_5000) ? "5.0Gb/s" :
Alexander Duyck559e9c42009-10-27 23:52:50 +00002062 "unknown"),
Alexander Duyck59c3de82009-03-31 20:38:00 +00002063 ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
2064 (hw->bus.width == e1000_bus_width_pcie_x2) ? "Width x2" :
2065 (hw->bus.width == e1000_bus_width_pcie_x1) ? "Width x1" :
2066 "unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07002067 netdev->dev_addr);
Auke Kok9d5c8242008-01-24 02:22:38 -08002068
Carolyn Wyborny9835fd72010-11-22 17:17:21 +00002069 ret_val = igb_read_part_string(hw, part_str, E1000_PBANUM_LENGTH);
2070 if (ret_val)
2071 strcpy(part_str, "Unknown");
2072 dev_info(&pdev->dev, "%s: PBA No: %s\n", netdev->name, part_str);
Auke Kok9d5c8242008-01-24 02:22:38 -08002073 dev_info(&pdev->dev,
2074 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
2075 adapter->msix_entries ? "MSI-X" :
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07002076 (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
Auke Kok9d5c8242008-01-24 02:22:38 -08002077 adapter->num_rx_queues, adapter->num_tx_queues);
Carolyn Wyborny09b068d2011-03-11 20:42:13 -08002078 switch (hw->mac.type) {
2079 case e1000_i350:
2080 igb_set_eee_i350(hw);
2081 break;
2082 default:
2083 break;
2084 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002085 return 0;
2086
2087err_register:
2088 igb_release_hw_control(adapter);
2089err_eeprom:
2090 if (!igb_check_reset_block(hw))
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08002091 igb_reset_phy(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002092
2093 if (hw->flash_address)
2094 iounmap(hw->flash_address);
Auke Kok9d5c8242008-01-24 02:22:38 -08002095err_sw_init:
Alexander Duyck047e0032009-10-27 15:49:27 +00002096 igb_clear_interrupt_scheme(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08002097 iounmap(hw->hw_addr);
2098err_ioremap:
2099 free_netdev(netdev);
2100err_alloc_etherdev:
Alexander Duyck559e9c42009-10-27 23:52:50 +00002101 pci_release_selected_regions(pdev,
2102 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9d5c8242008-01-24 02:22:38 -08002103err_pci_reg:
2104err_dma:
2105 pci_disable_device(pdev);
2106 return err;
2107}
2108
2109/**
2110 * igb_remove - Device Removal Routine
2111 * @pdev: PCI device information struct
2112 *
2113 * igb_remove is called by the PCI subsystem to alert the driver
2114 * that it should release a PCI device. The could be caused by a
2115 * Hot-Plug event, or because the driver is going to be removed from
2116 * memory.
2117 **/
2118static void __devexit igb_remove(struct pci_dev *pdev)
2119{
2120 struct net_device *netdev = pci_get_drvdata(pdev);
2121 struct igb_adapter *adapter = netdev_priv(netdev);
Jeb Cramerfe4506b2008-07-08 15:07:55 -07002122 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08002123
Tejun Heo760141a2010-12-12 16:45:14 +01002124 /*
2125 * The watchdog timer may be rescheduled, so explicitly
2126 * disable watchdog from being rescheduled.
2127 */
Auke Kok9d5c8242008-01-24 02:22:38 -08002128 set_bit(__IGB_DOWN, &adapter->state);
2129 del_timer_sync(&adapter->watchdog_timer);
2130 del_timer_sync(&adapter->phy_info_timer);
2131
Tejun Heo760141a2010-12-12 16:45:14 +01002132 cancel_work_sync(&adapter->reset_task);
2133 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9d5c8242008-01-24 02:22:38 -08002134
Jeff Kirsher421e02f2008-10-17 11:08:31 -07002135#ifdef CONFIG_IGB_DCA
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07002136 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
Jeb Cramerfe4506b2008-07-08 15:07:55 -07002137 dev_info(&pdev->dev, "DCA disabled\n");
2138 dca_remove_requester(&pdev->dev);
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07002139 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
Alexander Duyckcbd347a2009-02-15 23:59:44 -08002140 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
Jeb Cramerfe4506b2008-07-08 15:07:55 -07002141 }
2142#endif
2143
Auke Kok9d5c8242008-01-24 02:22:38 -08002144 /* Release control of h/w to f/w. If f/w is AMT enabled, this
2145 * would have already happened in close and is redundant. */
2146 igb_release_hw_control(adapter);
2147
2148 unregister_netdev(netdev);
2149
Alexander Duyck047e0032009-10-27 15:49:27 +00002150 igb_clear_interrupt_scheme(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08002151
Alexander Duyck37680112009-02-19 20:40:30 -08002152#ifdef CONFIG_PCI_IOV
2153 /* reclaim resources allocated to VFs */
2154 if (adapter->vf_data) {
2155 /* disable iov and allow time for transactions to clear */
2156 pci_disable_sriov(pdev);
2157 msleep(500);
2158
2159 kfree(adapter->vf_data);
2160 adapter->vf_data = NULL;
2161 wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
2162 msleep(100);
2163 dev_info(&pdev->dev, "IOV Disabled\n");
2164 }
2165#endif
Alexander Duyck559e9c42009-10-27 23:52:50 +00002166
Alexander Duyck28b07592009-02-06 23:20:31 +00002167 iounmap(hw->hw_addr);
2168 if (hw->flash_address)
2169 iounmap(hw->flash_address);
Alexander Duyck559e9c42009-10-27 23:52:50 +00002170 pci_release_selected_regions(pdev,
2171 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9d5c8242008-01-24 02:22:38 -08002172
2173 free_netdev(netdev);
2174
Frans Pop19d5afd2009-10-02 10:04:12 -07002175 pci_disable_pcie_error_reporting(pdev);
Alexander Duyck40a914f2008-11-27 00:24:37 -08002176
Auke Kok9d5c8242008-01-24 02:22:38 -08002177 pci_disable_device(pdev);
2178}
2179
2180/**
Alexander Duycka6b623e2009-10-27 23:47:53 +00002181 * igb_probe_vfs - Initialize vf data storage and add VFs to pci config space
2182 * @adapter: board private structure to initialize
2183 *
2184 * This function initializes the vf specific data storage and then attempts to
2185 * allocate the VFs. The reason for ordering it this way is because it is much
2186 * mor expensive time wise to disable SR-IOV than it is to allocate and free
2187 * the memory for the VFs.
2188 **/
2189static void __devinit igb_probe_vfs(struct igb_adapter * adapter)
2190{
2191#ifdef CONFIG_PCI_IOV
2192 struct pci_dev *pdev = adapter->pdev;
2193
Alexander Duycka6b623e2009-10-27 23:47:53 +00002194 if (adapter->vfs_allocated_count) {
2195 adapter->vf_data = kcalloc(adapter->vfs_allocated_count,
2196 sizeof(struct vf_data_storage),
2197 GFP_KERNEL);
2198 /* if allocation failed then we do not support SR-IOV */
2199 if (!adapter->vf_data) {
2200 adapter->vfs_allocated_count = 0;
2201 dev_err(&pdev->dev, "Unable to allocate memory for VF "
2202 "Data Storage\n");
2203 }
2204 }
2205
2206 if (pci_enable_sriov(pdev, adapter->vfs_allocated_count)) {
2207 kfree(adapter->vf_data);
2208 adapter->vf_data = NULL;
2209#endif /* CONFIG_PCI_IOV */
2210 adapter->vfs_allocated_count = 0;
2211#ifdef CONFIG_PCI_IOV
2212 } else {
2213 unsigned char mac_addr[ETH_ALEN];
2214 int i;
2215 dev_info(&pdev->dev, "%d vfs allocated\n",
2216 adapter->vfs_allocated_count);
2217 for (i = 0; i < adapter->vfs_allocated_count; i++) {
2218 random_ether_addr(mac_addr);
2219 igb_set_vf_mac(adapter, i, mac_addr);
2220 }
Carolyn Wyborny831ec0b2011-03-11 20:43:54 -08002221 /* DMA Coalescing is not supported in IOV mode. */
2222 if (adapter->flags & IGB_FLAG_DMAC)
2223 adapter->flags &= ~IGB_FLAG_DMAC;
Alexander Duycka6b623e2009-10-27 23:47:53 +00002224 }
2225#endif /* CONFIG_PCI_IOV */
2226}
2227
Alexander Duyck115f4592009-11-12 18:37:00 +00002228
2229/**
2230 * igb_init_hw_timer - Initialize hardware timer used with IEEE 1588 timestamp
2231 * @adapter: board private structure to initialize
2232 *
2233 * igb_init_hw_timer initializes the function pointer and values for the hw
2234 * timer found in hardware.
2235 **/
2236static void igb_init_hw_timer(struct igb_adapter *adapter)
2237{
2238 struct e1000_hw *hw = &adapter->hw;
2239
2240 switch (hw->mac.type) {
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00002241 case e1000_i350:
Alexander Duyck55cac242009-11-19 12:42:21 +00002242 case e1000_82580:
2243 memset(&adapter->cycles, 0, sizeof(adapter->cycles));
2244 adapter->cycles.read = igb_read_clock;
2245 adapter->cycles.mask = CLOCKSOURCE_MASK(64);
2246 adapter->cycles.mult = 1;
2247 /*
2248 * The 82580 timesync updates the system timer every 8ns by 8ns
2249 * and the value cannot be shifted. Instead we need to shift
2250 * the registers to generate a 64bit timer value. As a result
2251 * SYSTIMR/L/H, TXSTMPL/H, RXSTMPL/H all have to be shifted by
2252 * 24 in order to generate a larger value for synchronization.
2253 */
2254 adapter->cycles.shift = IGB_82580_TSYNC_SHIFT;
2255 /* disable system timer temporarily by setting bit 31 */
2256 wr32(E1000_TSAUXC, 0x80000000);
2257 wrfl();
2258
2259 /* Set registers so that rollover occurs soon to test this. */
2260 wr32(E1000_SYSTIMR, 0x00000000);
2261 wr32(E1000_SYSTIML, 0x80000000);
2262 wr32(E1000_SYSTIMH, 0x000000FF);
2263 wrfl();
2264
2265 /* enable system timer by clearing bit 31 */
2266 wr32(E1000_TSAUXC, 0x0);
2267 wrfl();
2268
2269 timecounter_init(&adapter->clock,
2270 &adapter->cycles,
2271 ktime_to_ns(ktime_get_real()));
2272 /*
2273 * Synchronize our NIC clock against system wall clock. NIC
2274 * time stamp reading requires ~3us per sample, each sample
2275 * was pretty stable even under load => only require 10
2276 * samples for each offset comparison.
2277 */
2278 memset(&adapter->compare, 0, sizeof(adapter->compare));
2279 adapter->compare.source = &adapter->clock;
2280 adapter->compare.target = ktime_get_real;
2281 adapter->compare.num_samples = 10;
2282 timecompare_update(&adapter->compare, 0);
2283 break;
Alexander Duyck115f4592009-11-12 18:37:00 +00002284 case e1000_82576:
2285 /*
2286 * Initialize hardware timer: we keep it running just in case
2287 * that some program needs it later on.
2288 */
2289 memset(&adapter->cycles, 0, sizeof(adapter->cycles));
2290 adapter->cycles.read = igb_read_clock;
2291 adapter->cycles.mask = CLOCKSOURCE_MASK(64);
2292 adapter->cycles.mult = 1;
2293 /**
2294 * Scale the NIC clock cycle by a large factor so that
2295 * relatively small clock corrections can be added or
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002296 * subtracted at each clock tick. The drawbacks of a large
Alexander Duyck115f4592009-11-12 18:37:00 +00002297 * factor are a) that the clock register overflows more quickly
2298 * (not such a big deal) and b) that the increment per tick has
2299 * to fit into 24 bits. As a result we need to use a shift of
2300 * 19 so we can fit a value of 16 into the TIMINCA register.
2301 */
2302 adapter->cycles.shift = IGB_82576_TSYNC_SHIFT;
2303 wr32(E1000_TIMINCA,
2304 (1 << E1000_TIMINCA_16NS_SHIFT) |
2305 (16 << IGB_82576_TSYNC_SHIFT));
2306
2307 /* Set registers so that rollover occurs soon to test this. */
2308 wr32(E1000_SYSTIML, 0x00000000);
2309 wr32(E1000_SYSTIMH, 0xFF800000);
2310 wrfl();
2311
2312 timecounter_init(&adapter->clock,
2313 &adapter->cycles,
2314 ktime_to_ns(ktime_get_real()));
2315 /*
2316 * Synchronize our NIC clock against system wall clock. NIC
2317 * time stamp reading requires ~3us per sample, each sample
2318 * was pretty stable even under load => only require 10
2319 * samples for each offset comparison.
2320 */
2321 memset(&adapter->compare, 0, sizeof(adapter->compare));
2322 adapter->compare.source = &adapter->clock;
2323 adapter->compare.target = ktime_get_real;
2324 adapter->compare.num_samples = 10;
2325 timecompare_update(&adapter->compare, 0);
2326 break;
2327 case e1000_82575:
2328 /* 82575 does not support timesync */
2329 default:
2330 break;
2331 }
2332
2333}
2334
Alexander Duycka6b623e2009-10-27 23:47:53 +00002335/**
Auke Kok9d5c8242008-01-24 02:22:38 -08002336 * igb_sw_init - Initialize general software structures (struct igb_adapter)
2337 * @adapter: board private structure to initialize
2338 *
2339 * igb_sw_init initializes the Adapter private data structure.
2340 * Fields are initialized based on PCI device information and
2341 * OS network device settings (MTU size).
2342 **/
2343static int __devinit igb_sw_init(struct igb_adapter *adapter)
2344{
2345 struct e1000_hw *hw = &adapter->hw;
2346 struct net_device *netdev = adapter->netdev;
2347 struct pci_dev *pdev = adapter->pdev;
2348
2349 pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
2350
Alexander Duyck68fd9912008-11-20 00:48:10 -08002351 adapter->tx_ring_count = IGB_DEFAULT_TXD;
2352 adapter->rx_ring_count = IGB_DEFAULT_RXD;
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00002353 adapter->rx_itr_setting = IGB_DEFAULT_ITR;
2354 adapter->tx_itr_setting = IGB_DEFAULT_ITR;
2355
Auke Kok9d5c8242008-01-24 02:22:38 -08002356 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
2357 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
2358
Eric Dumazet12dcd862010-10-15 17:27:10 +00002359 spin_lock_init(&adapter->stats64_lock);
Alexander Duycka6b623e2009-10-27 23:47:53 +00002360#ifdef CONFIG_PCI_IOV
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +00002361 switch (hw->mac.type) {
2362 case e1000_82576:
2363 case e1000_i350:
Stefan Assmann9b082d72011-02-24 20:03:31 +00002364 if (max_vfs > 7) {
2365 dev_warn(&pdev->dev,
2366 "Maximum of 7 VFs per PF, using max\n");
2367 adapter->vfs_allocated_count = 7;
2368 } else
2369 adapter->vfs_allocated_count = max_vfs;
Carolyn Wyborny6b78bb12011-01-20 06:40:45 +00002370 break;
2371 default:
2372 break;
2373 }
Alexander Duycka6b623e2009-10-27 23:47:53 +00002374#endif /* CONFIG_PCI_IOV */
Alexander Duycka99955f2009-11-12 18:37:19 +00002375 adapter->rss_queues = min_t(u32, IGB_MAX_RX_QUEUES, num_online_cpus());
Williams, Mitch A665c8c82011-06-07 14:22:57 -07002376 /* i350 cannot do RSS and SR-IOV at the same time */
2377 if (hw->mac.type == e1000_i350 && adapter->vfs_allocated_count)
2378 adapter->rss_queues = 1;
Alexander Duycka99955f2009-11-12 18:37:19 +00002379
2380 /*
2381 * if rss_queues > 4 or vfs are going to be allocated with rss_queues
2382 * then we should combine the queues into a queue pair in order to
2383 * conserve interrupts due to limited supply
2384 */
2385 if ((adapter->rss_queues > 4) ||
2386 ((adapter->rss_queues > 1) && (adapter->vfs_allocated_count > 6)))
2387 adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
2388
Alexander Duycka6b623e2009-10-27 23:47:53 +00002389 /* This call may decrease the number of queues */
Alexander Duyck047e0032009-10-27 15:49:27 +00002390 if (igb_init_interrupt_scheme(adapter)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08002391 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
2392 return -ENOMEM;
2393 }
2394
Alexander Duycka6b623e2009-10-27 23:47:53 +00002395 igb_probe_vfs(adapter);
2396
Auke Kok9d5c8242008-01-24 02:22:38 -08002397 /* Explicitly disable IRQ since the NIC can be in any state. */
2398 igb_irq_disable(adapter);
2399
Carolyn Wyborny831ec0b2011-03-11 20:43:54 -08002400 if (hw->mac.type == e1000_i350)
2401 adapter->flags &= ~IGB_FLAG_DMAC;
2402
Auke Kok9d5c8242008-01-24 02:22:38 -08002403 set_bit(__IGB_DOWN, &adapter->state);
2404 return 0;
2405}
2406
2407/**
2408 * igb_open - Called when a network interface is made active
2409 * @netdev: network interface device structure
2410 *
2411 * Returns 0 on success, negative value on failure
2412 *
2413 * The open entry point is called when a network interface is made
2414 * active by the system (IFF_UP). At this point all resources needed
2415 * for transmit and receive operations are allocated, the interrupt
2416 * handler is registered with the OS, the watchdog timer is started,
2417 * and the stack is notified that the interface is ready.
2418 **/
2419static int igb_open(struct net_device *netdev)
2420{
2421 struct igb_adapter *adapter = netdev_priv(netdev);
2422 struct e1000_hw *hw = &adapter->hw;
2423 int err;
2424 int i;
2425
2426 /* disallow open during test */
2427 if (test_bit(__IGB_TESTING, &adapter->state))
2428 return -EBUSY;
2429
Jesse Brandeburgb168dfc2009-04-17 20:44:32 +00002430 netif_carrier_off(netdev);
2431
Auke Kok9d5c8242008-01-24 02:22:38 -08002432 /* allocate transmit descriptors */
2433 err = igb_setup_all_tx_resources(adapter);
2434 if (err)
2435 goto err_setup_tx;
2436
2437 /* allocate receive descriptors */
2438 err = igb_setup_all_rx_resources(adapter);
2439 if (err)
2440 goto err_setup_rx;
2441
Nick Nunley88a268c2010-02-17 01:01:59 +00002442 igb_power_up_link(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08002443
Auke Kok9d5c8242008-01-24 02:22:38 -08002444 /* before we allocate an interrupt, we must be ready to handle it.
2445 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
2446 * as soon as we call pci_request_irq, so we have to setup our
2447 * clean_rx handler before we do so. */
2448 igb_configure(adapter);
2449
2450 err = igb_request_irq(adapter);
2451 if (err)
2452 goto err_req_irq;
2453
2454 /* From here on the code is the same as igb_up() */
2455 clear_bit(__IGB_DOWN, &adapter->state);
2456
Alexander Duyck047e0032009-10-27 15:49:27 +00002457 for (i = 0; i < adapter->num_q_vectors; i++) {
2458 struct igb_q_vector *q_vector = adapter->q_vector[i];
2459 napi_enable(&q_vector->napi);
2460 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002461
2462 /* Clear any pending interrupts. */
2463 rd32(E1000_ICR);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07002464
2465 igb_irq_enable(adapter);
2466
Alexander Duyckd4960302009-10-27 15:53:45 +00002467 /* notify VFs that reset has been completed */
2468 if (adapter->vfs_allocated_count) {
2469 u32 reg_data = rd32(E1000_CTRL_EXT);
2470 reg_data |= E1000_CTRL_EXT_PFRSTD;
2471 wr32(E1000_CTRL_EXT, reg_data);
2472 }
2473
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07002474 netif_tx_start_all_queues(netdev);
2475
Alexander Duyck25568a52009-10-27 23:49:59 +00002476 /* start the watchdog. */
2477 hw->mac.get_link_status = 1;
2478 schedule_work(&adapter->watchdog_task);
Auke Kok9d5c8242008-01-24 02:22:38 -08002479
2480 return 0;
2481
2482err_req_irq:
2483 igb_release_hw_control(adapter);
Nick Nunley88a268c2010-02-17 01:01:59 +00002484 igb_power_down_link(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08002485 igb_free_all_rx_resources(adapter);
2486err_setup_rx:
2487 igb_free_all_tx_resources(adapter);
2488err_setup_tx:
2489 igb_reset(adapter);
2490
2491 return err;
2492}
2493
2494/**
2495 * igb_close - Disables a network interface
2496 * @netdev: network interface device structure
2497 *
2498 * Returns 0, this is not allowed to fail
2499 *
2500 * The close entry point is called when an interface is de-activated
2501 * by the OS. The hardware is still under the driver's control, but
2502 * needs to be disabled. A global MAC reset is issued to stop the
2503 * hardware, and all transmit and receive resources are freed.
2504 **/
2505static int igb_close(struct net_device *netdev)
2506{
2507 struct igb_adapter *adapter = netdev_priv(netdev);
2508
2509 WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
2510 igb_down(adapter);
2511
2512 igb_free_irq(adapter);
2513
2514 igb_free_all_tx_resources(adapter);
2515 igb_free_all_rx_resources(adapter);
2516
Auke Kok9d5c8242008-01-24 02:22:38 -08002517 return 0;
2518}
2519
2520/**
2521 * igb_setup_tx_resources - allocate Tx resources (Descriptors)
Auke Kok9d5c8242008-01-24 02:22:38 -08002522 * @tx_ring: tx descriptor ring (for a specific queue) to setup
2523 *
2524 * Return 0 on success, negative on failure
2525 **/
Alexander Duyck80785292009-10-27 15:51:47 +00002526int igb_setup_tx_resources(struct igb_ring *tx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08002527{
Alexander Duyck59d71982010-04-27 13:09:25 +00002528 struct device *dev = tx_ring->dev;
Auke Kok9d5c8242008-01-24 02:22:38 -08002529 int size;
2530
2531 size = sizeof(struct igb_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002532 tx_ring->buffer_info = vzalloc(size);
Auke Kok9d5c8242008-01-24 02:22:38 -08002533 if (!tx_ring->buffer_info)
2534 goto err;
Auke Kok9d5c8242008-01-24 02:22:38 -08002535
2536 /* round up to nearest 4K */
Alexander Duyck85e8d002009-02-16 00:00:20 -08002537 tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
Auke Kok9d5c8242008-01-24 02:22:38 -08002538 tx_ring->size = ALIGN(tx_ring->size, 4096);
2539
Alexander Duyck59d71982010-04-27 13:09:25 +00002540 tx_ring->desc = dma_alloc_coherent(dev,
2541 tx_ring->size,
2542 &tx_ring->dma,
2543 GFP_KERNEL);
Auke Kok9d5c8242008-01-24 02:22:38 -08002544
2545 if (!tx_ring->desc)
2546 goto err;
2547
Auke Kok9d5c8242008-01-24 02:22:38 -08002548 tx_ring->next_to_use = 0;
2549 tx_ring->next_to_clean = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08002550 return 0;
2551
2552err:
2553 vfree(tx_ring->buffer_info);
Alexander Duyck59d71982010-04-27 13:09:25 +00002554 dev_err(dev,
Auke Kok9d5c8242008-01-24 02:22:38 -08002555 "Unable to allocate memory for the transmit descriptor ring\n");
2556 return -ENOMEM;
2557}
2558
2559/**
2560 * igb_setup_all_tx_resources - wrapper to allocate Tx resources
2561 * (Descriptors) for all queues
2562 * @adapter: board private structure
2563 *
2564 * Return 0 on success, negative on failure
2565 **/
2566static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
2567{
Alexander Duyck439705e2009-10-27 23:49:20 +00002568 struct pci_dev *pdev = adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08002569 int i, err = 0;
2570
2571 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +00002572 err = igb_setup_tx_resources(adapter->tx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08002573 if (err) {
Alexander Duyck439705e2009-10-27 23:49:20 +00002574 dev_err(&pdev->dev,
Auke Kok9d5c8242008-01-24 02:22:38 -08002575 "Allocation for Tx Queue %u failed\n", i);
2576 for (i--; i >= 0; i--)
Alexander Duyck3025a442010-02-17 01:02:39 +00002577 igb_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08002578 break;
2579 }
2580 }
2581
Alexander Duycka99955f2009-11-12 18:37:19 +00002582 for (i = 0; i < IGB_ABS_MAX_TX_QUEUES; i++) {
Alexander Duyck439705e2009-10-27 23:49:20 +00002583 int r_idx = i % adapter->num_tx_queues;
Alexander Duyck3025a442010-02-17 01:02:39 +00002584 adapter->multi_tx_table[i] = adapter->tx_ring[r_idx];
Alexander Duyckeebbbdb2009-02-06 23:19:29 +00002585 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002586 return err;
2587}
2588
2589/**
Alexander Duyck85b430b2009-10-27 15:50:29 +00002590 * igb_setup_tctl - configure the transmit control registers
2591 * @adapter: Board private structure
Auke Kok9d5c8242008-01-24 02:22:38 -08002592 **/
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00002593void igb_setup_tctl(struct igb_adapter *adapter)
Auke Kok9d5c8242008-01-24 02:22:38 -08002594{
Auke Kok9d5c8242008-01-24 02:22:38 -08002595 struct e1000_hw *hw = &adapter->hw;
2596 u32 tctl;
Auke Kok9d5c8242008-01-24 02:22:38 -08002597
Alexander Duyck85b430b2009-10-27 15:50:29 +00002598 /* disable queue 0 which is enabled by default on 82575 and 82576 */
2599 wr32(E1000_TXDCTL(0), 0);
Auke Kok9d5c8242008-01-24 02:22:38 -08002600
2601 /* Program the Transmit Control Register */
Auke Kok9d5c8242008-01-24 02:22:38 -08002602 tctl = rd32(E1000_TCTL);
2603 tctl &= ~E1000_TCTL_CT;
2604 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
2605 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2606
2607 igb_config_collision_dist(hw);
2608
Auke Kok9d5c8242008-01-24 02:22:38 -08002609 /* Enable transmits */
2610 tctl |= E1000_TCTL_EN;
2611
2612 wr32(E1000_TCTL, tctl);
2613}
2614
2615/**
Alexander Duyck85b430b2009-10-27 15:50:29 +00002616 * igb_configure_tx_ring - Configure transmit ring after Reset
2617 * @adapter: board private structure
2618 * @ring: tx ring to configure
2619 *
2620 * Configure a transmit ring after a reset.
2621 **/
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00002622void igb_configure_tx_ring(struct igb_adapter *adapter,
2623 struct igb_ring *ring)
Alexander Duyck85b430b2009-10-27 15:50:29 +00002624{
2625 struct e1000_hw *hw = &adapter->hw;
2626 u32 txdctl;
2627 u64 tdba = ring->dma;
2628 int reg_idx = ring->reg_idx;
2629
2630 /* disable the queue */
2631 txdctl = rd32(E1000_TXDCTL(reg_idx));
2632 wr32(E1000_TXDCTL(reg_idx),
2633 txdctl & ~E1000_TXDCTL_QUEUE_ENABLE);
2634 wrfl();
2635 mdelay(10);
2636
2637 wr32(E1000_TDLEN(reg_idx),
2638 ring->count * sizeof(union e1000_adv_tx_desc));
2639 wr32(E1000_TDBAL(reg_idx),
2640 tdba & 0x00000000ffffffffULL);
2641 wr32(E1000_TDBAH(reg_idx), tdba >> 32);
2642
Alexander Duyckfce99e32009-10-27 15:51:27 +00002643 ring->head = hw->hw_addr + E1000_TDH(reg_idx);
2644 ring->tail = hw->hw_addr + E1000_TDT(reg_idx);
2645 writel(0, ring->head);
2646 writel(0, ring->tail);
Alexander Duyck85b430b2009-10-27 15:50:29 +00002647
2648 txdctl |= IGB_TX_PTHRESH;
2649 txdctl |= IGB_TX_HTHRESH << 8;
2650 txdctl |= IGB_TX_WTHRESH << 16;
2651
2652 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
2653 wr32(E1000_TXDCTL(reg_idx), txdctl);
2654}
2655
2656/**
2657 * igb_configure_tx - Configure transmit Unit after Reset
2658 * @adapter: board private structure
2659 *
2660 * Configure the Tx unit of the MAC after a reset.
2661 **/
2662static void igb_configure_tx(struct igb_adapter *adapter)
2663{
2664 int i;
2665
2666 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +00002667 igb_configure_tx_ring(adapter, adapter->tx_ring[i]);
Alexander Duyck85b430b2009-10-27 15:50:29 +00002668}
2669
2670/**
Auke Kok9d5c8242008-01-24 02:22:38 -08002671 * igb_setup_rx_resources - allocate Rx resources (Descriptors)
Auke Kok9d5c8242008-01-24 02:22:38 -08002672 * @rx_ring: rx descriptor ring (for a specific queue) to setup
2673 *
2674 * Returns 0 on success, negative on failure
2675 **/
Alexander Duyck80785292009-10-27 15:51:47 +00002676int igb_setup_rx_resources(struct igb_ring *rx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08002677{
Alexander Duyck59d71982010-04-27 13:09:25 +00002678 struct device *dev = rx_ring->dev;
Auke Kok9d5c8242008-01-24 02:22:38 -08002679 int size, desc_len;
2680
2681 size = sizeof(struct igb_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00002682 rx_ring->buffer_info = vzalloc(size);
Auke Kok9d5c8242008-01-24 02:22:38 -08002683 if (!rx_ring->buffer_info)
2684 goto err;
Auke Kok9d5c8242008-01-24 02:22:38 -08002685
2686 desc_len = sizeof(union e1000_adv_rx_desc);
2687
2688 /* Round up to nearest 4K */
2689 rx_ring->size = rx_ring->count * desc_len;
2690 rx_ring->size = ALIGN(rx_ring->size, 4096);
2691
Alexander Duyck59d71982010-04-27 13:09:25 +00002692 rx_ring->desc = dma_alloc_coherent(dev,
2693 rx_ring->size,
2694 &rx_ring->dma,
2695 GFP_KERNEL);
Auke Kok9d5c8242008-01-24 02:22:38 -08002696
2697 if (!rx_ring->desc)
2698 goto err;
2699
2700 rx_ring->next_to_clean = 0;
2701 rx_ring->next_to_use = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08002702
Auke Kok9d5c8242008-01-24 02:22:38 -08002703 return 0;
2704
2705err:
2706 vfree(rx_ring->buffer_info);
Alexander Duyck439705e2009-10-27 23:49:20 +00002707 rx_ring->buffer_info = NULL;
Alexander Duyck59d71982010-04-27 13:09:25 +00002708 dev_err(dev, "Unable to allocate memory for the receive descriptor"
2709 " ring\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08002710 return -ENOMEM;
2711}
2712
2713/**
2714 * igb_setup_all_rx_resources - wrapper to allocate Rx resources
2715 * (Descriptors) for all queues
2716 * @adapter: board private structure
2717 *
2718 * Return 0 on success, negative on failure
2719 **/
2720static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
2721{
Alexander Duyck439705e2009-10-27 23:49:20 +00002722 struct pci_dev *pdev = adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08002723 int i, err = 0;
2724
2725 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +00002726 err = igb_setup_rx_resources(adapter->rx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08002727 if (err) {
Alexander Duyck439705e2009-10-27 23:49:20 +00002728 dev_err(&pdev->dev,
Auke Kok9d5c8242008-01-24 02:22:38 -08002729 "Allocation for Rx Queue %u failed\n", i);
2730 for (i--; i >= 0; i--)
Alexander Duyck3025a442010-02-17 01:02:39 +00002731 igb_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08002732 break;
2733 }
2734 }
2735
2736 return err;
2737}
2738
2739/**
Alexander Duyck06cf2662009-10-27 15:53:25 +00002740 * igb_setup_mrqc - configure the multiple receive queue control registers
2741 * @adapter: Board private structure
2742 **/
2743static void igb_setup_mrqc(struct igb_adapter *adapter)
2744{
2745 struct e1000_hw *hw = &adapter->hw;
2746 u32 mrqc, rxcsum;
2747 u32 j, num_rx_queues, shift = 0, shift2 = 0;
2748 union e1000_reta {
2749 u32 dword;
2750 u8 bytes[4];
2751 } reta;
2752 static const u8 rsshash[40] = {
2753 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, 0x41, 0x67,
2754 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, 0xd0, 0xca, 0x2b, 0xcb,
2755 0xae, 0x7b, 0x30, 0xb4, 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30,
2756 0xf2, 0x0c, 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa };
2757
2758 /* Fill out hash function seeds */
2759 for (j = 0; j < 10; j++) {
2760 u32 rsskey = rsshash[(j * 4)];
2761 rsskey |= rsshash[(j * 4) + 1] << 8;
2762 rsskey |= rsshash[(j * 4) + 2] << 16;
2763 rsskey |= rsshash[(j * 4) + 3] << 24;
2764 array_wr32(E1000_RSSRK(0), j, rsskey);
2765 }
2766
Alexander Duycka99955f2009-11-12 18:37:19 +00002767 num_rx_queues = adapter->rss_queues;
Alexander Duyck06cf2662009-10-27 15:53:25 +00002768
2769 if (adapter->vfs_allocated_count) {
2770 /* 82575 and 82576 supports 2 RSS queues for VMDq */
2771 switch (hw->mac.type) {
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00002772 case e1000_i350:
Alexander Duyck55cac242009-11-19 12:42:21 +00002773 case e1000_82580:
2774 num_rx_queues = 1;
2775 shift = 0;
2776 break;
Alexander Duyck06cf2662009-10-27 15:53:25 +00002777 case e1000_82576:
2778 shift = 3;
2779 num_rx_queues = 2;
2780 break;
2781 case e1000_82575:
2782 shift = 2;
2783 shift2 = 6;
2784 default:
2785 break;
2786 }
2787 } else {
2788 if (hw->mac.type == e1000_82575)
2789 shift = 6;
2790 }
2791
2792 for (j = 0; j < (32 * 4); j++) {
2793 reta.bytes[j & 3] = (j % num_rx_queues) << shift;
2794 if (shift2)
2795 reta.bytes[j & 3] |= num_rx_queues << shift2;
2796 if ((j & 3) == 3)
2797 wr32(E1000_RETA(j >> 2), reta.dword);
2798 }
2799
2800 /*
2801 * Disable raw packet checksumming so that RSS hash is placed in
2802 * descriptor on writeback. No need to enable TCP/UDP/IP checksum
2803 * offloads as they are enabled by default
2804 */
2805 rxcsum = rd32(E1000_RXCSUM);
2806 rxcsum |= E1000_RXCSUM_PCSD;
2807
2808 if (adapter->hw.mac.type >= e1000_82576)
2809 /* Enable Receive Checksum Offload for SCTP */
2810 rxcsum |= E1000_RXCSUM_CRCOFL;
2811
2812 /* Don't need to set TUOFL or IPOFL, they default to 1 */
2813 wr32(E1000_RXCSUM, rxcsum);
2814
2815 /* If VMDq is enabled then we set the appropriate mode for that, else
2816 * we default to RSS so that an RSS hash is calculated per packet even
2817 * if we are only using one queue */
2818 if (adapter->vfs_allocated_count) {
2819 if (hw->mac.type > e1000_82575) {
2820 /* Set the default pool for the PF's first queue */
2821 u32 vtctl = rd32(E1000_VT_CTL);
2822 vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK |
2823 E1000_VT_CTL_DISABLE_DEF_POOL);
2824 vtctl |= adapter->vfs_allocated_count <<
2825 E1000_VT_CTL_DEFAULT_POOL_SHIFT;
2826 wr32(E1000_VT_CTL, vtctl);
2827 }
Alexander Duycka99955f2009-11-12 18:37:19 +00002828 if (adapter->rss_queues > 1)
Alexander Duyck06cf2662009-10-27 15:53:25 +00002829 mrqc = E1000_MRQC_ENABLE_VMDQ_RSS_2Q;
2830 else
2831 mrqc = E1000_MRQC_ENABLE_VMDQ;
2832 } else {
2833 mrqc = E1000_MRQC_ENABLE_RSS_4Q;
2834 }
2835 igb_vmm_control(adapter);
2836
Alexander Duyck4478a9c2010-07-01 20:01:05 +00002837 /*
2838 * Generate RSS hash based on TCP port numbers and/or
2839 * IPv4/v6 src and dst addresses since UDP cannot be
2840 * hashed reliably due to IP fragmentation
2841 */
2842 mrqc |= E1000_MRQC_RSS_FIELD_IPV4 |
2843 E1000_MRQC_RSS_FIELD_IPV4_TCP |
2844 E1000_MRQC_RSS_FIELD_IPV6 |
2845 E1000_MRQC_RSS_FIELD_IPV6_TCP |
2846 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX;
Alexander Duyck06cf2662009-10-27 15:53:25 +00002847
2848 wr32(E1000_MRQC, mrqc);
2849}
2850
2851/**
Auke Kok9d5c8242008-01-24 02:22:38 -08002852 * igb_setup_rctl - configure the receive control registers
2853 * @adapter: Board private structure
2854 **/
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00002855void igb_setup_rctl(struct igb_adapter *adapter)
Auke Kok9d5c8242008-01-24 02:22:38 -08002856{
2857 struct e1000_hw *hw = &adapter->hw;
2858 u32 rctl;
Auke Kok9d5c8242008-01-24 02:22:38 -08002859
2860 rctl = rd32(E1000_RCTL);
2861
2862 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
Alexander Duyck69d728b2008-11-25 01:04:03 -08002863 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
Auke Kok9d5c8242008-01-24 02:22:38 -08002864
Alexander Duyck69d728b2008-11-25 01:04:03 -08002865 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
Alexander Duyck28b07592009-02-06 23:20:31 +00002866 (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kok9d5c8242008-01-24 02:22:38 -08002867
Auke Kok87cb7e82008-07-08 15:08:29 -07002868 /*
2869 * enable stripping of CRC. It's unlikely this will break BMC
2870 * redirection as it did with e1000. Newer features require
2871 * that the HW strips the CRC.
Alexander Duyck73cd78f2009-02-12 18:16:59 +00002872 */
Auke Kok87cb7e82008-07-08 15:08:29 -07002873 rctl |= E1000_RCTL_SECRC;
Auke Kok9d5c8242008-01-24 02:22:38 -08002874
Alexander Duyck559e9c42009-10-27 23:52:50 +00002875 /* disable store bad packets and clear size bits. */
Alexander Duyckec54d7d2009-01-31 00:52:57 -08002876 rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256);
Auke Kok9d5c8242008-01-24 02:22:38 -08002877
Alexander Duyck6ec43fe2009-10-27 15:50:48 +00002878 /* enable LPE to prevent packets larger than max_frame_size */
2879 rctl |= E1000_RCTL_LPE;
Auke Kok9d5c8242008-01-24 02:22:38 -08002880
Alexander Duyck952f72a2009-10-27 15:51:07 +00002881 /* disable queue 0 to prevent tail write w/o re-config */
2882 wr32(E1000_RXDCTL(0), 0);
Auke Kok9d5c8242008-01-24 02:22:38 -08002883
Alexander Duycke1739522009-02-19 20:39:44 -08002884 /* Attention!!! For SR-IOV PF driver operations you must enable
2885 * queue drop for all VF and PF queues to prevent head of line blocking
2886 * if an un-trusted VF does not provide descriptors to hardware.
2887 */
2888 if (adapter->vfs_allocated_count) {
Alexander Duycke1739522009-02-19 20:39:44 -08002889 /* set all queue drop enable bits */
2890 wr32(E1000_QDE, ALL_QUEUES);
Alexander Duycke1739522009-02-19 20:39:44 -08002891 }
2892
Auke Kok9d5c8242008-01-24 02:22:38 -08002893 wr32(E1000_RCTL, rctl);
2894}
2895
Alexander Duyck7d5753f2009-10-27 23:47:16 +00002896static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
2897 int vfn)
2898{
2899 struct e1000_hw *hw = &adapter->hw;
2900 u32 vmolr;
2901
2902 /* if it isn't the PF check to see if VFs are enabled and
2903 * increase the size to support vlan tags */
2904 if (vfn < adapter->vfs_allocated_count &&
2905 adapter->vf_data[vfn].vlans_enabled)
2906 size += VLAN_TAG_SIZE;
2907
2908 vmolr = rd32(E1000_VMOLR(vfn));
2909 vmolr &= ~E1000_VMOLR_RLPML_MASK;
2910 vmolr |= size | E1000_VMOLR_LPE;
2911 wr32(E1000_VMOLR(vfn), vmolr);
2912
2913 return 0;
2914}
2915
Auke Kok9d5c8242008-01-24 02:22:38 -08002916/**
Alexander Duycke1739522009-02-19 20:39:44 -08002917 * igb_rlpml_set - set maximum receive packet size
2918 * @adapter: board private structure
2919 *
2920 * Configure maximum receivable packet size.
2921 **/
2922static void igb_rlpml_set(struct igb_adapter *adapter)
2923{
2924 u32 max_frame_size = adapter->max_frame_size;
2925 struct e1000_hw *hw = &adapter->hw;
2926 u16 pf_id = adapter->vfs_allocated_count;
2927
2928 if (adapter->vlgrp)
2929 max_frame_size += VLAN_TAG_SIZE;
2930
2931 /* if vfs are enabled we set RLPML to the largest possible request
2932 * size and set the VMOLR RLPML to the size we need */
2933 if (pf_id) {
2934 igb_set_vf_rlpml(adapter, max_frame_size, pf_id);
Alexander Duyck7d5753f2009-10-27 23:47:16 +00002935 max_frame_size = MAX_JUMBO_FRAME_SIZE;
Alexander Duycke1739522009-02-19 20:39:44 -08002936 }
2937
2938 wr32(E1000_RLPML, max_frame_size);
2939}
2940
Williams, Mitch A8151d292010-02-10 01:44:24 +00002941static inline void igb_set_vmolr(struct igb_adapter *adapter,
2942 int vfn, bool aupe)
Alexander Duyck7d5753f2009-10-27 23:47:16 +00002943{
2944 struct e1000_hw *hw = &adapter->hw;
2945 u32 vmolr;
2946
2947 /*
2948 * This register exists only on 82576 and newer so if we are older then
2949 * we should exit and do nothing
2950 */
2951 if (hw->mac.type < e1000_82576)
2952 return;
2953
2954 vmolr = rd32(E1000_VMOLR(vfn));
Williams, Mitch A8151d292010-02-10 01:44:24 +00002955 vmolr |= E1000_VMOLR_STRVLAN; /* Strip vlan tags */
2956 if (aupe)
2957 vmolr |= E1000_VMOLR_AUPE; /* Accept untagged packets */
2958 else
2959 vmolr &= ~(E1000_VMOLR_AUPE); /* Tagged packets ONLY */
Alexander Duyck7d5753f2009-10-27 23:47:16 +00002960
2961 /* clear all bits that might not be set */
2962 vmolr &= ~(E1000_VMOLR_BAM | E1000_VMOLR_RSSE);
2963
Alexander Duycka99955f2009-11-12 18:37:19 +00002964 if (adapter->rss_queues > 1 && vfn == adapter->vfs_allocated_count)
Alexander Duyck7d5753f2009-10-27 23:47:16 +00002965 vmolr |= E1000_VMOLR_RSSE; /* enable RSS */
2966 /*
2967 * for VMDq only allow the VFs and pool 0 to accept broadcast and
2968 * multicast packets
2969 */
2970 if (vfn <= adapter->vfs_allocated_count)
2971 vmolr |= E1000_VMOLR_BAM; /* Accept broadcast */
2972
2973 wr32(E1000_VMOLR(vfn), vmolr);
2974}
2975
Alexander Duycke1739522009-02-19 20:39:44 -08002976/**
Alexander Duyck85b430b2009-10-27 15:50:29 +00002977 * igb_configure_rx_ring - Configure a receive ring after Reset
2978 * @adapter: board private structure
2979 * @ring: receive ring to be configured
2980 *
2981 * Configure the Rx unit of the MAC after a reset.
2982 **/
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00002983void igb_configure_rx_ring(struct igb_adapter *adapter,
2984 struct igb_ring *ring)
Alexander Duyck85b430b2009-10-27 15:50:29 +00002985{
2986 struct e1000_hw *hw = &adapter->hw;
2987 u64 rdba = ring->dma;
2988 int reg_idx = ring->reg_idx;
Alexander Duyck952f72a2009-10-27 15:51:07 +00002989 u32 srrctl, rxdctl;
Alexander Duyck85b430b2009-10-27 15:50:29 +00002990
2991 /* disable the queue */
2992 rxdctl = rd32(E1000_RXDCTL(reg_idx));
2993 wr32(E1000_RXDCTL(reg_idx),
2994 rxdctl & ~E1000_RXDCTL_QUEUE_ENABLE);
2995
2996 /* Set DMA base address registers */
2997 wr32(E1000_RDBAL(reg_idx),
2998 rdba & 0x00000000ffffffffULL);
2999 wr32(E1000_RDBAH(reg_idx), rdba >> 32);
3000 wr32(E1000_RDLEN(reg_idx),
3001 ring->count * sizeof(union e1000_adv_rx_desc));
3002
3003 /* initialize head and tail */
Alexander Duyckfce99e32009-10-27 15:51:27 +00003004 ring->head = hw->hw_addr + E1000_RDH(reg_idx);
3005 ring->tail = hw->hw_addr + E1000_RDT(reg_idx);
3006 writel(0, ring->head);
3007 writel(0, ring->tail);
Alexander Duyck85b430b2009-10-27 15:50:29 +00003008
Alexander Duyck952f72a2009-10-27 15:51:07 +00003009 /* set descriptor configuration */
Alexander Duyck4c844852009-10-27 15:52:07 +00003010 if (ring->rx_buffer_len < IGB_RXBUFFER_1024) {
3011 srrctl = ALIGN(ring->rx_buffer_len, 64) <<
Alexander Duyck952f72a2009-10-27 15:51:07 +00003012 E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
3013#if (PAGE_SIZE / 2) > IGB_RXBUFFER_16384
3014 srrctl |= IGB_RXBUFFER_16384 >>
3015 E1000_SRRCTL_BSIZEPKT_SHIFT;
3016#else
3017 srrctl |= (PAGE_SIZE / 2) >>
3018 E1000_SRRCTL_BSIZEPKT_SHIFT;
3019#endif
3020 srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
3021 } else {
Alexander Duyck4c844852009-10-27 15:52:07 +00003022 srrctl = ALIGN(ring->rx_buffer_len, 1024) >>
Alexander Duyck952f72a2009-10-27 15:51:07 +00003023 E1000_SRRCTL_BSIZEPKT_SHIFT;
3024 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
3025 }
Nick Nunley757b77e2010-03-26 11:36:47 +00003026 if (hw->mac.type == e1000_82580)
3027 srrctl |= E1000_SRRCTL_TIMESTAMP;
Nick Nunleye6bdb6f2010-02-17 01:03:38 +00003028 /* Only set Drop Enable if we are supporting multiple queues */
3029 if (adapter->vfs_allocated_count || adapter->num_rx_queues > 1)
3030 srrctl |= E1000_SRRCTL_DROP_EN;
Alexander Duyck952f72a2009-10-27 15:51:07 +00003031
3032 wr32(E1000_SRRCTL(reg_idx), srrctl);
3033
Alexander Duyck7d5753f2009-10-27 23:47:16 +00003034 /* set filtering for VMDQ pools */
Williams, Mitch A8151d292010-02-10 01:44:24 +00003035 igb_set_vmolr(adapter, reg_idx & 0x7, true);
Alexander Duyck7d5753f2009-10-27 23:47:16 +00003036
Alexander Duyck85b430b2009-10-27 15:50:29 +00003037 /* enable receive descriptor fetching */
3038 rxdctl = rd32(E1000_RXDCTL(reg_idx));
3039 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
3040 rxdctl &= 0xFFF00000;
3041 rxdctl |= IGB_RX_PTHRESH;
3042 rxdctl |= IGB_RX_HTHRESH << 8;
3043 rxdctl |= IGB_RX_WTHRESH << 16;
3044 wr32(E1000_RXDCTL(reg_idx), rxdctl);
3045}
3046
3047/**
Auke Kok9d5c8242008-01-24 02:22:38 -08003048 * igb_configure_rx - Configure receive Unit after Reset
3049 * @adapter: board private structure
3050 *
3051 * Configure the Rx unit of the MAC after a reset.
3052 **/
3053static void igb_configure_rx(struct igb_adapter *adapter)
3054{
Hannes Eder91075842009-02-18 19:36:04 -08003055 int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08003056
Alexander Duyck68d480c2009-10-05 06:33:08 +00003057 /* set UTA to appropriate mode */
3058 igb_set_uta(adapter);
3059
Alexander Duyck26ad9172009-10-05 06:32:49 +00003060 /* set the correct pool for the PF default MAC address in entry 0 */
3061 igb_rar_set_qsel(adapter, adapter->hw.mac.addr, 0,
3062 adapter->vfs_allocated_count);
3063
Alexander Duyck06cf2662009-10-27 15:53:25 +00003064 /* Setup the HW Rx Head and Tail Descriptor Pointers and
3065 * the Base and Length of the Rx Descriptor Ring */
3066 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +00003067 igb_configure_rx_ring(adapter, adapter->rx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08003068}
3069
3070/**
3071 * igb_free_tx_resources - Free Tx Resources per Queue
Auke Kok9d5c8242008-01-24 02:22:38 -08003072 * @tx_ring: Tx descriptor ring for a specific queue
3073 *
3074 * Free all transmit software resources
3075 **/
Alexander Duyck68fd9912008-11-20 00:48:10 -08003076void igb_free_tx_resources(struct igb_ring *tx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08003077{
Mitch Williams3b644cf2008-06-27 10:59:48 -07003078 igb_clean_tx_ring(tx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08003079
3080 vfree(tx_ring->buffer_info);
3081 tx_ring->buffer_info = NULL;
3082
Alexander Duyck439705e2009-10-27 23:49:20 +00003083 /* if not set, then don't free */
3084 if (!tx_ring->desc)
3085 return;
3086
Alexander Duyck59d71982010-04-27 13:09:25 +00003087 dma_free_coherent(tx_ring->dev, tx_ring->size,
3088 tx_ring->desc, tx_ring->dma);
Auke Kok9d5c8242008-01-24 02:22:38 -08003089
3090 tx_ring->desc = NULL;
3091}
3092
3093/**
3094 * igb_free_all_tx_resources - Free Tx Resources for All Queues
3095 * @adapter: board private structure
3096 *
3097 * Free all transmit software resources
3098 **/
3099static void igb_free_all_tx_resources(struct igb_adapter *adapter)
3100{
3101 int i;
3102
3103 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +00003104 igb_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08003105}
3106
Alexander Duyckb1a436c2009-10-27 15:54:43 +00003107void igb_unmap_and_free_tx_resource(struct igb_ring *tx_ring,
3108 struct igb_buffer *buffer_info)
Auke Kok9d5c8242008-01-24 02:22:38 -08003109{
Alexander Duyck6366ad32009-12-02 16:47:18 +00003110 if (buffer_info->dma) {
3111 if (buffer_info->mapped_as_page)
Alexander Duyck59d71982010-04-27 13:09:25 +00003112 dma_unmap_page(tx_ring->dev,
Alexander Duyck6366ad32009-12-02 16:47:18 +00003113 buffer_info->dma,
3114 buffer_info->length,
Alexander Duyck59d71982010-04-27 13:09:25 +00003115 DMA_TO_DEVICE);
Alexander Duyck6366ad32009-12-02 16:47:18 +00003116 else
Alexander Duyck59d71982010-04-27 13:09:25 +00003117 dma_unmap_single(tx_ring->dev,
Alexander Duyck6366ad32009-12-02 16:47:18 +00003118 buffer_info->dma,
3119 buffer_info->length,
Alexander Duyck59d71982010-04-27 13:09:25 +00003120 DMA_TO_DEVICE);
Alexander Duyck6366ad32009-12-02 16:47:18 +00003121 buffer_info->dma = 0;
3122 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003123 if (buffer_info->skb) {
3124 dev_kfree_skb_any(buffer_info->skb);
3125 buffer_info->skb = NULL;
3126 }
3127 buffer_info->time_stamp = 0;
Alexander Duyck6366ad32009-12-02 16:47:18 +00003128 buffer_info->length = 0;
3129 buffer_info->next_to_watch = 0;
3130 buffer_info->mapped_as_page = false;
Auke Kok9d5c8242008-01-24 02:22:38 -08003131}
3132
3133/**
3134 * igb_clean_tx_ring - Free Tx Buffers
Auke Kok9d5c8242008-01-24 02:22:38 -08003135 * @tx_ring: ring to be cleaned
3136 **/
Mitch Williams3b644cf2008-06-27 10:59:48 -07003137static void igb_clean_tx_ring(struct igb_ring *tx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08003138{
3139 struct igb_buffer *buffer_info;
3140 unsigned long size;
3141 unsigned int i;
3142
3143 if (!tx_ring->buffer_info)
3144 return;
3145 /* Free all the Tx ring sk_buffs */
3146
3147 for (i = 0; i < tx_ring->count; i++) {
3148 buffer_info = &tx_ring->buffer_info[i];
Alexander Duyck80785292009-10-27 15:51:47 +00003149 igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
Auke Kok9d5c8242008-01-24 02:22:38 -08003150 }
3151
3152 size = sizeof(struct igb_buffer) * tx_ring->count;
3153 memset(tx_ring->buffer_info, 0, size);
3154
3155 /* Zero out the descriptor ring */
Auke Kok9d5c8242008-01-24 02:22:38 -08003156 memset(tx_ring->desc, 0, tx_ring->size);
3157
3158 tx_ring->next_to_use = 0;
3159 tx_ring->next_to_clean = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08003160}
3161
3162/**
3163 * igb_clean_all_tx_rings - Free Tx Buffers for all queues
3164 * @adapter: board private structure
3165 **/
3166static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
3167{
3168 int i;
3169
3170 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +00003171 igb_clean_tx_ring(adapter->tx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08003172}
3173
3174/**
3175 * igb_free_rx_resources - Free Rx Resources
Auke Kok9d5c8242008-01-24 02:22:38 -08003176 * @rx_ring: ring to clean the resources from
3177 *
3178 * Free all receive software resources
3179 **/
Alexander Duyck68fd9912008-11-20 00:48:10 -08003180void igb_free_rx_resources(struct igb_ring *rx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08003181{
Mitch Williams3b644cf2008-06-27 10:59:48 -07003182 igb_clean_rx_ring(rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08003183
3184 vfree(rx_ring->buffer_info);
3185 rx_ring->buffer_info = NULL;
3186
Alexander Duyck439705e2009-10-27 23:49:20 +00003187 /* if not set, then don't free */
3188 if (!rx_ring->desc)
3189 return;
3190
Alexander Duyck59d71982010-04-27 13:09:25 +00003191 dma_free_coherent(rx_ring->dev, rx_ring->size,
3192 rx_ring->desc, rx_ring->dma);
Auke Kok9d5c8242008-01-24 02:22:38 -08003193
3194 rx_ring->desc = NULL;
3195}
3196
3197/**
3198 * igb_free_all_rx_resources - Free Rx Resources for All Queues
3199 * @adapter: board private structure
3200 *
3201 * Free all receive software resources
3202 **/
3203static void igb_free_all_rx_resources(struct igb_adapter *adapter)
3204{
3205 int i;
3206
3207 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +00003208 igb_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08003209}
3210
3211/**
3212 * igb_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9d5c8242008-01-24 02:22:38 -08003213 * @rx_ring: ring to free buffers from
3214 **/
Mitch Williams3b644cf2008-06-27 10:59:48 -07003215static void igb_clean_rx_ring(struct igb_ring *rx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08003216{
3217 struct igb_buffer *buffer_info;
Auke Kok9d5c8242008-01-24 02:22:38 -08003218 unsigned long size;
3219 unsigned int i;
3220
3221 if (!rx_ring->buffer_info)
3222 return;
Alexander Duyck439705e2009-10-27 23:49:20 +00003223
Auke Kok9d5c8242008-01-24 02:22:38 -08003224 /* Free all the Rx ring sk_buffs */
3225 for (i = 0; i < rx_ring->count; i++) {
3226 buffer_info = &rx_ring->buffer_info[i];
3227 if (buffer_info->dma) {
Alexander Duyck59d71982010-04-27 13:09:25 +00003228 dma_unmap_single(rx_ring->dev,
Alexander Duyck80785292009-10-27 15:51:47 +00003229 buffer_info->dma,
Alexander Duyck4c844852009-10-27 15:52:07 +00003230 rx_ring->rx_buffer_len,
Alexander Duyck59d71982010-04-27 13:09:25 +00003231 DMA_FROM_DEVICE);
Auke Kok9d5c8242008-01-24 02:22:38 -08003232 buffer_info->dma = 0;
3233 }
3234
3235 if (buffer_info->skb) {
3236 dev_kfree_skb(buffer_info->skb);
3237 buffer_info->skb = NULL;
3238 }
Alexander Duyck6ec43fe2009-10-27 15:50:48 +00003239 if (buffer_info->page_dma) {
Alexander Duyck59d71982010-04-27 13:09:25 +00003240 dma_unmap_page(rx_ring->dev,
Alexander Duyck80785292009-10-27 15:51:47 +00003241 buffer_info->page_dma,
Alexander Duyck6ec43fe2009-10-27 15:50:48 +00003242 PAGE_SIZE / 2,
Alexander Duyck59d71982010-04-27 13:09:25 +00003243 DMA_FROM_DEVICE);
Alexander Duyck6ec43fe2009-10-27 15:50:48 +00003244 buffer_info->page_dma = 0;
3245 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003246 if (buffer_info->page) {
Auke Kok9d5c8242008-01-24 02:22:38 -08003247 put_page(buffer_info->page);
3248 buffer_info->page = NULL;
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07003249 buffer_info->page_offset = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08003250 }
3251 }
3252
Auke Kok9d5c8242008-01-24 02:22:38 -08003253 size = sizeof(struct igb_buffer) * rx_ring->count;
3254 memset(rx_ring->buffer_info, 0, size);
3255
3256 /* Zero out the descriptor ring */
3257 memset(rx_ring->desc, 0, rx_ring->size);
3258
3259 rx_ring->next_to_clean = 0;
3260 rx_ring->next_to_use = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08003261}
3262
3263/**
3264 * igb_clean_all_rx_rings - Free Rx Buffers for all queues
3265 * @adapter: board private structure
3266 **/
3267static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
3268{
3269 int i;
3270
3271 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +00003272 igb_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08003273}
3274
3275/**
3276 * igb_set_mac - Change the Ethernet Address of the NIC
3277 * @netdev: network interface device structure
3278 * @p: pointer to an address structure
3279 *
3280 * Returns 0 on success, negative on failure
3281 **/
3282static int igb_set_mac(struct net_device *netdev, void *p)
3283{
3284 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck28b07592009-02-06 23:20:31 +00003285 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08003286 struct sockaddr *addr = p;
3287
3288 if (!is_valid_ether_addr(addr->sa_data))
3289 return -EADDRNOTAVAIL;
3290
3291 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Alexander Duyck28b07592009-02-06 23:20:31 +00003292 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9d5c8242008-01-24 02:22:38 -08003293
Alexander Duyck26ad9172009-10-05 06:32:49 +00003294 /* set the correct pool for the new PF MAC address in entry 0 */
3295 igb_rar_set_qsel(adapter, hw->mac.addr, 0,
3296 adapter->vfs_allocated_count);
Alexander Duycke1739522009-02-19 20:39:44 -08003297
Auke Kok9d5c8242008-01-24 02:22:38 -08003298 return 0;
3299}
3300
3301/**
Alexander Duyck68d480c2009-10-05 06:33:08 +00003302 * igb_write_mc_addr_list - write multicast addresses to MTA
3303 * @netdev: network interface device structure
3304 *
3305 * Writes multicast address list to the MTA hash table.
3306 * Returns: -ENOMEM on failure
3307 * 0 on no addresses written
3308 * X on writing X addresses to MTA
3309 **/
3310static int igb_write_mc_addr_list(struct net_device *netdev)
3311{
3312 struct igb_adapter *adapter = netdev_priv(netdev);
3313 struct e1000_hw *hw = &adapter->hw;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003314 struct netdev_hw_addr *ha;
Alexander Duyck68d480c2009-10-05 06:33:08 +00003315 u8 *mta_list;
Alexander Duyck68d480c2009-10-05 06:33:08 +00003316 int i;
3317
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00003318 if (netdev_mc_empty(netdev)) {
Alexander Duyck68d480c2009-10-05 06:33:08 +00003319 /* nothing to program, so clear mc list */
3320 igb_update_mc_addr_list(hw, NULL, 0);
3321 igb_restore_vf_multicasts(adapter);
3322 return 0;
3323 }
3324
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00003325 mta_list = kzalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
Alexander Duyck68d480c2009-10-05 06:33:08 +00003326 if (!mta_list)
3327 return -ENOMEM;
3328
Alexander Duyck68d480c2009-10-05 06:33:08 +00003329 /* The shared function expects a packed array of only addresses. */
Jiri Pirko48e2f182010-02-22 09:22:26 +00003330 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003331 netdev_for_each_mc_addr(ha, netdev)
3332 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
Alexander Duyck68d480c2009-10-05 06:33:08 +00003333
Alexander Duyck68d480c2009-10-05 06:33:08 +00003334 igb_update_mc_addr_list(hw, mta_list, i);
3335 kfree(mta_list);
3336
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00003337 return netdev_mc_count(netdev);
Alexander Duyck68d480c2009-10-05 06:33:08 +00003338}
3339
3340/**
3341 * igb_write_uc_addr_list - write unicast addresses to RAR table
3342 * @netdev: network interface device structure
3343 *
3344 * Writes unicast address list to the RAR table.
3345 * Returns: -ENOMEM on failure/insufficient address space
3346 * 0 on no addresses written
3347 * X on writing X addresses to the RAR table
3348 **/
3349static int igb_write_uc_addr_list(struct net_device *netdev)
3350{
3351 struct igb_adapter *adapter = netdev_priv(netdev);
3352 struct e1000_hw *hw = &adapter->hw;
3353 unsigned int vfn = adapter->vfs_allocated_count;
3354 unsigned int rar_entries = hw->mac.rar_entry_count - (vfn + 1);
3355 int count = 0;
3356
3357 /* return ENOMEM indicating insufficient memory for addresses */
Jiri Pirko32e7bfc2010-01-25 13:36:10 -08003358 if (netdev_uc_count(netdev) > rar_entries)
Alexander Duyck68d480c2009-10-05 06:33:08 +00003359 return -ENOMEM;
3360
Jiri Pirko32e7bfc2010-01-25 13:36:10 -08003361 if (!netdev_uc_empty(netdev) && rar_entries) {
Alexander Duyck68d480c2009-10-05 06:33:08 +00003362 struct netdev_hw_addr *ha;
Jiri Pirko32e7bfc2010-01-25 13:36:10 -08003363
3364 netdev_for_each_uc_addr(ha, netdev) {
Alexander Duyck68d480c2009-10-05 06:33:08 +00003365 if (!rar_entries)
3366 break;
3367 igb_rar_set_qsel(adapter, ha->addr,
3368 rar_entries--,
3369 vfn);
3370 count++;
3371 }
3372 }
3373 /* write the addresses in reverse order to avoid write combining */
3374 for (; rar_entries > 0 ; rar_entries--) {
3375 wr32(E1000_RAH(rar_entries), 0);
3376 wr32(E1000_RAL(rar_entries), 0);
3377 }
3378 wrfl();
3379
3380 return count;
3381}
3382
3383/**
Alexander Duyckff41f8d2009-09-03 14:48:56 +00003384 * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
Auke Kok9d5c8242008-01-24 02:22:38 -08003385 * @netdev: network interface device structure
3386 *
Alexander Duyckff41f8d2009-09-03 14:48:56 +00003387 * The set_rx_mode entry point is called whenever the unicast or multicast
3388 * address lists or the network interface flags are updated. This routine is
3389 * responsible for configuring the hardware for proper unicast, multicast,
Auke Kok9d5c8242008-01-24 02:22:38 -08003390 * promiscuous mode, and all-multi behavior.
3391 **/
Alexander Duyckff41f8d2009-09-03 14:48:56 +00003392static void igb_set_rx_mode(struct net_device *netdev)
Auke Kok9d5c8242008-01-24 02:22:38 -08003393{
3394 struct igb_adapter *adapter = netdev_priv(netdev);
3395 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck68d480c2009-10-05 06:33:08 +00003396 unsigned int vfn = adapter->vfs_allocated_count;
3397 u32 rctl, vmolr = 0;
3398 int count;
Auke Kok9d5c8242008-01-24 02:22:38 -08003399
3400 /* Check for Promiscuous and All Multicast modes */
Auke Kok9d5c8242008-01-24 02:22:38 -08003401 rctl = rd32(E1000_RCTL);
3402
Alexander Duyck68d480c2009-10-05 06:33:08 +00003403 /* clear the effected bits */
3404 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_VFE);
3405
Patrick McHardy746b9f02008-07-16 20:15:45 -07003406 if (netdev->flags & IFF_PROMISC) {
Auke Kok9d5c8242008-01-24 02:22:38 -08003407 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Alexander Duyck68d480c2009-10-05 06:33:08 +00003408 vmolr |= (E1000_VMOLR_ROPE | E1000_VMOLR_MPME);
Patrick McHardy746b9f02008-07-16 20:15:45 -07003409 } else {
Alexander Duyck68d480c2009-10-05 06:33:08 +00003410 if (netdev->flags & IFF_ALLMULTI) {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003411 rctl |= E1000_RCTL_MPE;
Alexander Duyck68d480c2009-10-05 06:33:08 +00003412 vmolr |= E1000_VMOLR_MPME;
3413 } else {
3414 /*
3415 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003416 * then we should just turn on promiscuous mode so
Alexander Duyck68d480c2009-10-05 06:33:08 +00003417 * that we can at least receive multicast traffic
3418 */
3419 count = igb_write_mc_addr_list(netdev);
3420 if (count < 0) {
3421 rctl |= E1000_RCTL_MPE;
3422 vmolr |= E1000_VMOLR_MPME;
3423 } else if (count) {
3424 vmolr |= E1000_VMOLR_ROMPE;
3425 }
3426 }
3427 /*
3428 * Write addresses to available RAR registers, if there is not
3429 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003430 * unicast promiscuous mode
Alexander Duyck68d480c2009-10-05 06:33:08 +00003431 */
3432 count = igb_write_uc_addr_list(netdev);
3433 if (count < 0) {
Alexander Duyckff41f8d2009-09-03 14:48:56 +00003434 rctl |= E1000_RCTL_UPE;
Alexander Duyck68d480c2009-10-05 06:33:08 +00003435 vmolr |= E1000_VMOLR_ROPE;
3436 }
Patrick McHardy78ed11a2008-07-16 20:16:14 -07003437 rctl |= E1000_RCTL_VFE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003438 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003439 wr32(E1000_RCTL, rctl);
3440
Alexander Duyck68d480c2009-10-05 06:33:08 +00003441 /*
3442 * In order to support SR-IOV and eventually VMDq it is necessary to set
3443 * the VMOLR to enable the appropriate modes. Without this workaround
3444 * we will have issues with VLAN tag stripping not being done for frames
3445 * that are only arriving because we are the default pool
3446 */
3447 if (hw->mac.type < e1000_82576)
Alexander Duyck28fc06f2009-07-23 18:08:54 +00003448 return;
Alexander Duyck28fc06f2009-07-23 18:08:54 +00003449
Alexander Duyck68d480c2009-10-05 06:33:08 +00003450 vmolr |= rd32(E1000_VMOLR(vfn)) &
3451 ~(E1000_VMOLR_ROPE | E1000_VMOLR_MPME | E1000_VMOLR_ROMPE);
3452 wr32(E1000_VMOLR(vfn), vmolr);
Alexander Duyck28fc06f2009-07-23 18:08:54 +00003453 igb_restore_vf_multicasts(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08003454}
3455
Greg Rose13800462010-11-06 02:08:26 +00003456static void igb_check_wvbr(struct igb_adapter *adapter)
3457{
3458 struct e1000_hw *hw = &adapter->hw;
3459 u32 wvbr = 0;
3460
3461 switch (hw->mac.type) {
3462 case e1000_82576:
3463 case e1000_i350:
3464 if (!(wvbr = rd32(E1000_WVBR)))
3465 return;
3466 break;
3467 default:
3468 break;
3469 }
3470
3471 adapter->wvbr |= wvbr;
3472}
3473
3474#define IGB_STAGGERED_QUEUE_OFFSET 8
3475
3476static void igb_spoof_check(struct igb_adapter *adapter)
3477{
3478 int j;
3479
3480 if (!adapter->wvbr)
3481 return;
3482
3483 for(j = 0; j < adapter->vfs_allocated_count; j++) {
3484 if (adapter->wvbr & (1 << j) ||
3485 adapter->wvbr & (1 << (j + IGB_STAGGERED_QUEUE_OFFSET))) {
3486 dev_warn(&adapter->pdev->dev,
3487 "Spoof event(s) detected on VF %d\n", j);
3488 adapter->wvbr &=
3489 ~((1 << j) |
3490 (1 << (j + IGB_STAGGERED_QUEUE_OFFSET)));
3491 }
3492 }
3493}
3494
Auke Kok9d5c8242008-01-24 02:22:38 -08003495/* Need to wait a few seconds after link up to get diagnostic information from
3496 * the phy */
3497static void igb_update_phy_info(unsigned long data)
3498{
3499 struct igb_adapter *adapter = (struct igb_adapter *) data;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08003500 igb_get_phy_info(&adapter->hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08003501}
3502
3503/**
Alexander Duyck4d6b7252009-02-06 23:16:24 +00003504 * igb_has_link - check shared code for link and determine up/down
3505 * @adapter: pointer to driver private info
3506 **/
Nick Nunley31455352010-02-17 01:01:21 +00003507bool igb_has_link(struct igb_adapter *adapter)
Alexander Duyck4d6b7252009-02-06 23:16:24 +00003508{
3509 struct e1000_hw *hw = &adapter->hw;
3510 bool link_active = false;
3511 s32 ret_val = 0;
3512
3513 /* get_link_status is set on LSC (link status) interrupt or
3514 * rx sequence error interrupt. get_link_status will stay
3515 * false until the e1000_check_for_link establishes link
3516 * for copper adapters ONLY
3517 */
3518 switch (hw->phy.media_type) {
3519 case e1000_media_type_copper:
3520 if (hw->mac.get_link_status) {
3521 ret_val = hw->mac.ops.check_for_link(hw);
3522 link_active = !hw->mac.get_link_status;
3523 } else {
3524 link_active = true;
3525 }
3526 break;
Alexander Duyck4d6b7252009-02-06 23:16:24 +00003527 case e1000_media_type_internal_serdes:
3528 ret_val = hw->mac.ops.check_for_link(hw);
3529 link_active = hw->mac.serdes_has_link;
3530 break;
3531 default:
3532 case e1000_media_type_unknown:
3533 break;
3534 }
3535
3536 return link_active;
3537}
3538
Stefan Assmann563988d2011-04-05 04:27:15 +00003539static bool igb_thermal_sensor_event(struct e1000_hw *hw, u32 event)
3540{
3541 bool ret = false;
3542 u32 ctrl_ext, thstat;
3543
3544 /* check for thermal sensor event on i350, copper only */
3545 if (hw->mac.type == e1000_i350) {
3546 thstat = rd32(E1000_THSTAT);
3547 ctrl_ext = rd32(E1000_CTRL_EXT);
3548
3549 if ((hw->phy.media_type == e1000_media_type_copper) &&
3550 !(ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII)) {
3551 ret = !!(thstat & event);
3552 }
3553 }
3554
3555 return ret;
3556}
3557
Alexander Duyck4d6b7252009-02-06 23:16:24 +00003558/**
Auke Kok9d5c8242008-01-24 02:22:38 -08003559 * igb_watchdog - Timer Call-back
3560 * @data: pointer to adapter cast into an unsigned long
3561 **/
3562static void igb_watchdog(unsigned long data)
3563{
3564 struct igb_adapter *adapter = (struct igb_adapter *)data;
3565 /* Do the rest outside of interrupt context */
3566 schedule_work(&adapter->watchdog_task);
3567}
3568
3569static void igb_watchdog_task(struct work_struct *work)
3570{
3571 struct igb_adapter *adapter = container_of(work,
Alexander Duyck559e9c42009-10-27 23:52:50 +00003572 struct igb_adapter,
3573 watchdog_task);
Auke Kok9d5c8242008-01-24 02:22:38 -08003574 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08003575 struct net_device *netdev = adapter->netdev;
Stefan Assmann563988d2011-04-05 04:27:15 +00003576 u32 link;
Alexander Duyck7a6ea552008-08-26 04:25:03 -07003577 int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08003578
Alexander Duyck4d6b7252009-02-06 23:16:24 +00003579 link = igb_has_link(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08003580 if (link) {
3581 if (!netif_carrier_ok(netdev)) {
3582 u32 ctrl;
Alexander Duyck330a6d62009-10-27 23:51:35 +00003583 hw->mac.ops.get_speed_and_duplex(hw,
3584 &adapter->link_speed,
3585 &adapter->link_duplex);
Auke Kok9d5c8242008-01-24 02:22:38 -08003586
3587 ctrl = rd32(E1000_CTRL);
Alexander Duyck527d47c2008-11-27 00:21:39 -08003588 /* Links status message must follow this format */
3589 printk(KERN_INFO "igb: %s NIC Link is Up %d Mbps %s, "
Auke Kok9d5c8242008-01-24 02:22:38 -08003590 "Flow Control: %s\n",
Alexander Duyck559e9c42009-10-27 23:52:50 +00003591 netdev->name,
3592 adapter->link_speed,
3593 adapter->link_duplex == FULL_DUPLEX ?
Auke Kok9d5c8242008-01-24 02:22:38 -08003594 "Full Duplex" : "Half Duplex",
Alexander Duyck559e9c42009-10-27 23:52:50 +00003595 ((ctrl & E1000_CTRL_TFCE) &&
3596 (ctrl & E1000_CTRL_RFCE)) ? "RX/TX" :
3597 ((ctrl & E1000_CTRL_RFCE) ? "RX" :
3598 ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None")));
Auke Kok9d5c8242008-01-24 02:22:38 -08003599
Stefan Assmann563988d2011-04-05 04:27:15 +00003600 /* check for thermal sensor event */
3601 if (igb_thermal_sensor_event(hw, E1000_THSTAT_LINK_THROTTLE)) {
3602 printk(KERN_INFO "igb: %s The network adapter "
3603 "link speed was downshifted "
3604 "because it overheated.\n",
3605 netdev->name);
Carolyn Wyborny7ef5ed12011-03-12 08:59:47 +00003606 }
Stefan Assmann563988d2011-04-05 04:27:15 +00003607
Emil Tantilovd07f3e32010-03-23 18:34:57 +00003608 /* adjust timeout factor according to speed/duplex */
Auke Kok9d5c8242008-01-24 02:22:38 -08003609 adapter->tx_timeout_factor = 1;
3610 switch (adapter->link_speed) {
3611 case SPEED_10:
Auke Kok9d5c8242008-01-24 02:22:38 -08003612 adapter->tx_timeout_factor = 14;
3613 break;
3614 case SPEED_100:
Auke Kok9d5c8242008-01-24 02:22:38 -08003615 /* maybe add some timeout factor ? */
3616 break;
3617 }
3618
3619 netif_carrier_on(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08003620
Alexander Duyck4ae196d2009-02-19 20:40:07 -08003621 igb_ping_all_vfs(adapter);
Lior Levy17dc5662011-02-08 02:28:46 +00003622 igb_check_vf_rate_limit(adapter);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08003623
Alexander Duyck4b1a9872009-02-06 23:19:50 +00003624 /* link state has changed, schedule phy info update */
Auke Kok9d5c8242008-01-24 02:22:38 -08003625 if (!test_bit(__IGB_DOWN, &adapter->state))
3626 mod_timer(&adapter->phy_info_timer,
3627 round_jiffies(jiffies + 2 * HZ));
3628 }
3629 } else {
3630 if (netif_carrier_ok(netdev)) {
3631 adapter->link_speed = 0;
3632 adapter->link_duplex = 0;
Stefan Assmann563988d2011-04-05 04:27:15 +00003633
3634 /* check for thermal sensor event */
3635 if (igb_thermal_sensor_event(hw, E1000_THSTAT_PWR_DOWN)) {
3636 printk(KERN_ERR "igb: %s The network adapter "
3637 "was stopped because it "
3638 "overheated.\n",
Carolyn Wyborny7ef5ed12011-03-12 08:59:47 +00003639 netdev->name);
Carolyn Wyborny7ef5ed12011-03-12 08:59:47 +00003640 }
Stefan Assmann563988d2011-04-05 04:27:15 +00003641
Alexander Duyck527d47c2008-11-27 00:21:39 -08003642 /* Links status message must follow this format */
3643 printk(KERN_INFO "igb: %s NIC Link is Down\n",
3644 netdev->name);
Auke Kok9d5c8242008-01-24 02:22:38 -08003645 netif_carrier_off(netdev);
Alexander Duyck4b1a9872009-02-06 23:19:50 +00003646
Alexander Duyck4ae196d2009-02-19 20:40:07 -08003647 igb_ping_all_vfs(adapter);
3648
Alexander Duyck4b1a9872009-02-06 23:19:50 +00003649 /* link state has changed, schedule phy info update */
Auke Kok9d5c8242008-01-24 02:22:38 -08003650 if (!test_bit(__IGB_DOWN, &adapter->state))
3651 mod_timer(&adapter->phy_info_timer,
3652 round_jiffies(jiffies + 2 * HZ));
3653 }
3654 }
3655
Eric Dumazet12dcd862010-10-15 17:27:10 +00003656 spin_lock(&adapter->stats64_lock);
3657 igb_update_stats(adapter, &adapter->stats64);
3658 spin_unlock(&adapter->stats64_lock);
Auke Kok9d5c8242008-01-24 02:22:38 -08003659
Alexander Duyckdbabb062009-11-12 18:38:16 +00003660 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +00003661 struct igb_ring *tx_ring = adapter->tx_ring[i];
Alexander Duyckdbabb062009-11-12 18:38:16 +00003662 if (!netif_carrier_ok(netdev)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08003663 /* We've lost link, so the controller stops DMA,
3664 * but we've got queued Tx work that's never going
3665 * to get done, so reset controller to flush Tx.
3666 * (Do the reset outside of interrupt context). */
Alexander Duyckdbabb062009-11-12 18:38:16 +00003667 if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) {
3668 adapter->tx_timeout_count++;
3669 schedule_work(&adapter->reset_task);
3670 /* return immediately since reset is imminent */
3671 return;
3672 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003673 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003674
Alexander Duyckdbabb062009-11-12 18:38:16 +00003675 /* Force detection of hung controller every watchdog period */
3676 tx_ring->detect_tx_hung = true;
3677 }
Alexander Duyckf7ba2052009-10-27 23:48:51 +00003678
Auke Kok9d5c8242008-01-24 02:22:38 -08003679 /* Cause software interrupt to ensure rx ring is cleaned */
Alexander Duyck7a6ea552008-08-26 04:25:03 -07003680 if (adapter->msix_entries) {
Alexander Duyck047e0032009-10-27 15:49:27 +00003681 u32 eics = 0;
3682 for (i = 0; i < adapter->num_q_vectors; i++) {
3683 struct igb_q_vector *q_vector = adapter->q_vector[i];
3684 eics |= q_vector->eims_value;
3685 }
Alexander Duyck7a6ea552008-08-26 04:25:03 -07003686 wr32(E1000_EICS, eics);
3687 } else {
3688 wr32(E1000_ICS, E1000_ICS_RXDMT0);
3689 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003690
Greg Rose13800462010-11-06 02:08:26 +00003691 igb_spoof_check(adapter);
3692
Auke Kok9d5c8242008-01-24 02:22:38 -08003693 /* Reset the timer */
3694 if (!test_bit(__IGB_DOWN, &adapter->state))
3695 mod_timer(&adapter->watchdog_timer,
3696 round_jiffies(jiffies + 2 * HZ));
3697}
3698
3699enum latency_range {
3700 lowest_latency = 0,
3701 low_latency = 1,
3702 bulk_latency = 2,
3703 latency_invalid = 255
3704};
3705
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003706/**
3707 * igb_update_ring_itr - update the dynamic ITR value based on packet size
3708 *
3709 * Stores a new ITR value based on strictly on packet size. This
3710 * algorithm is less sophisticated than that used in igb_update_itr,
3711 * due to the difficulty of synchronizing statistics across multiple
Stefan Weileef35c22010-08-06 21:11:15 +02003712 * receive rings. The divisors and thresholds used by this function
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003713 * were determined based on theoretical maximum wire speed and testing
3714 * data, in order to minimize response time while increasing bulk
3715 * throughput.
3716 * This functionality is controlled by the InterruptThrottleRate module
3717 * parameter (see igb_param.c)
3718 * NOTE: This function is called only when operating in a multiqueue
3719 * receive environment.
Alexander Duyck047e0032009-10-27 15:49:27 +00003720 * @q_vector: pointer to q_vector
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003721 **/
Alexander Duyck047e0032009-10-27 15:49:27 +00003722static void igb_update_ring_itr(struct igb_q_vector *q_vector)
Auke Kok9d5c8242008-01-24 02:22:38 -08003723{
Alexander Duyck047e0032009-10-27 15:49:27 +00003724 int new_val = q_vector->itr_val;
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003725 int avg_wire_size = 0;
Alexander Duyck047e0032009-10-27 15:49:27 +00003726 struct igb_adapter *adapter = q_vector->adapter;
Eric Dumazet12dcd862010-10-15 17:27:10 +00003727 struct igb_ring *ring;
3728 unsigned int packets;
Auke Kok9d5c8242008-01-24 02:22:38 -08003729
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003730 /* For non-gigabit speeds, just fix the interrupt rate at 4000
3731 * ints/sec - ITR timer value of 120 ticks.
3732 */
3733 if (adapter->link_speed != SPEED_1000) {
Alexander Duyck047e0032009-10-27 15:49:27 +00003734 new_val = 976;
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003735 goto set_itr_val;
3736 }
Alexander Duyck047e0032009-10-27 15:49:27 +00003737
Eric Dumazet12dcd862010-10-15 17:27:10 +00003738 ring = q_vector->rx_ring;
3739 if (ring) {
3740 packets = ACCESS_ONCE(ring->total_packets);
3741
3742 if (packets)
3743 avg_wire_size = ring->total_bytes / packets;
Alexander Duyck047e0032009-10-27 15:49:27 +00003744 }
3745
Eric Dumazet12dcd862010-10-15 17:27:10 +00003746 ring = q_vector->tx_ring;
3747 if (ring) {
3748 packets = ACCESS_ONCE(ring->total_packets);
3749
3750 if (packets)
3751 avg_wire_size = max_t(u32, avg_wire_size,
3752 ring->total_bytes / packets);
Alexander Duyck047e0032009-10-27 15:49:27 +00003753 }
3754
3755 /* if avg_wire_size isn't set no work was done */
3756 if (!avg_wire_size)
3757 goto clear_counts;
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003758
3759 /* Add 24 bytes to size to account for CRC, preamble, and gap */
3760 avg_wire_size += 24;
3761
3762 /* Don't starve jumbo frames */
3763 avg_wire_size = min(avg_wire_size, 3000);
3764
3765 /* Give a little boost to mid-size frames */
3766 if ((avg_wire_size > 300) && (avg_wire_size < 1200))
3767 new_val = avg_wire_size / 3;
3768 else
3769 new_val = avg_wire_size / 2;
3770
Nick Nunleyabe1c362010-02-17 01:03:19 +00003771 /* when in itr mode 3 do not exceed 20K ints/sec */
3772 if (adapter->rx_itr_setting == 3 && new_val < 196)
3773 new_val = 196;
3774
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003775set_itr_val:
Alexander Duyck047e0032009-10-27 15:49:27 +00003776 if (new_val != q_vector->itr_val) {
3777 q_vector->itr_val = new_val;
3778 q_vector->set_itr = 1;
Auke Kok9d5c8242008-01-24 02:22:38 -08003779 }
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003780clear_counts:
Alexander Duyck047e0032009-10-27 15:49:27 +00003781 if (q_vector->rx_ring) {
3782 q_vector->rx_ring->total_bytes = 0;
3783 q_vector->rx_ring->total_packets = 0;
3784 }
3785 if (q_vector->tx_ring) {
3786 q_vector->tx_ring->total_bytes = 0;
3787 q_vector->tx_ring->total_packets = 0;
3788 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003789}
3790
3791/**
3792 * igb_update_itr - update the dynamic ITR value based on statistics
3793 * Stores a new ITR value based on packets and byte
3794 * counts during the last interrupt. The advantage of per interrupt
3795 * computation is faster updates and more accurate ITR for the current
3796 * traffic pattern. Constants in this function were computed
3797 * based on theoretical maximum wire speed and thresholds were set based
3798 * on testing data as well as attempting to minimize response time
3799 * while increasing bulk throughput.
3800 * this functionality is controlled by the InterruptThrottleRate module
3801 * parameter (see igb_param.c)
3802 * NOTE: These calculations are only valid when operating in a single-
3803 * queue environment.
3804 * @adapter: pointer to adapter
Alexander Duyck047e0032009-10-27 15:49:27 +00003805 * @itr_setting: current q_vector->itr_val
Auke Kok9d5c8242008-01-24 02:22:38 -08003806 * @packets: the number of packets during this measurement interval
3807 * @bytes: the number of bytes during this measurement interval
3808 **/
3809static unsigned int igb_update_itr(struct igb_adapter *adapter, u16 itr_setting,
3810 int packets, int bytes)
3811{
3812 unsigned int retval = itr_setting;
3813
3814 if (packets == 0)
3815 goto update_itr_done;
3816
3817 switch (itr_setting) {
3818 case lowest_latency:
3819 /* handle TSO and jumbo frames */
3820 if (bytes/packets > 8000)
3821 retval = bulk_latency;
3822 else if ((packets < 5) && (bytes > 512))
3823 retval = low_latency;
3824 break;
3825 case low_latency: /* 50 usec aka 20000 ints/s */
3826 if (bytes > 10000) {
3827 /* this if handles the TSO accounting */
3828 if (bytes/packets > 8000) {
3829 retval = bulk_latency;
3830 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
3831 retval = bulk_latency;
3832 } else if ((packets > 35)) {
3833 retval = lowest_latency;
3834 }
3835 } else if (bytes/packets > 2000) {
3836 retval = bulk_latency;
3837 } else if (packets <= 2 && bytes < 512) {
3838 retval = lowest_latency;
3839 }
3840 break;
3841 case bulk_latency: /* 250 usec aka 4000 ints/s */
3842 if (bytes > 25000) {
3843 if (packets > 35)
3844 retval = low_latency;
Alexander Duyck1e5c3d22009-02-12 18:17:21 +00003845 } else if (bytes < 1500) {
Auke Kok9d5c8242008-01-24 02:22:38 -08003846 retval = low_latency;
3847 }
3848 break;
3849 }
3850
3851update_itr_done:
3852 return retval;
3853}
3854
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003855static void igb_set_itr(struct igb_adapter *adapter)
Auke Kok9d5c8242008-01-24 02:22:38 -08003856{
Alexander Duyck047e0032009-10-27 15:49:27 +00003857 struct igb_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9d5c8242008-01-24 02:22:38 -08003858 u16 current_itr;
Alexander Duyck047e0032009-10-27 15:49:27 +00003859 u32 new_itr = q_vector->itr_val;
Auke Kok9d5c8242008-01-24 02:22:38 -08003860
3861 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
3862 if (adapter->link_speed != SPEED_1000) {
3863 current_itr = 0;
3864 new_itr = 4000;
3865 goto set_itr_now;
3866 }
3867
3868 adapter->rx_itr = igb_update_itr(adapter,
3869 adapter->rx_itr,
Alexander Duyck3025a442010-02-17 01:02:39 +00003870 q_vector->rx_ring->total_packets,
3871 q_vector->rx_ring->total_bytes);
Auke Kok9d5c8242008-01-24 02:22:38 -08003872
Alexander Duyck047e0032009-10-27 15:49:27 +00003873 adapter->tx_itr = igb_update_itr(adapter,
3874 adapter->tx_itr,
Alexander Duyck3025a442010-02-17 01:02:39 +00003875 q_vector->tx_ring->total_packets,
3876 q_vector->tx_ring->total_bytes);
Alexander Duyck047e0032009-10-27 15:49:27 +00003877 current_itr = max(adapter->rx_itr, adapter->tx_itr);
Auke Kok9d5c8242008-01-24 02:22:38 -08003878
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003879 /* conservative mode (itr 3) eliminates the lowest_latency setting */
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00003880 if (adapter->rx_itr_setting == 3 && current_itr == lowest_latency)
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003881 current_itr = low_latency;
3882
Auke Kok9d5c8242008-01-24 02:22:38 -08003883 switch (current_itr) {
3884 /* counts and packets in update_itr are dependent on these numbers */
3885 case lowest_latency:
Alexander Duyck78b1f6072009-04-23 11:20:29 +00003886 new_itr = 56; /* aka 70,000 ints/sec */
Auke Kok9d5c8242008-01-24 02:22:38 -08003887 break;
3888 case low_latency:
Alexander Duyck78b1f6072009-04-23 11:20:29 +00003889 new_itr = 196; /* aka 20,000 ints/sec */
Auke Kok9d5c8242008-01-24 02:22:38 -08003890 break;
3891 case bulk_latency:
Alexander Duyck78b1f6072009-04-23 11:20:29 +00003892 new_itr = 980; /* aka 4,000 ints/sec */
Auke Kok9d5c8242008-01-24 02:22:38 -08003893 break;
3894 default:
3895 break;
3896 }
3897
3898set_itr_now:
Alexander Duyck3025a442010-02-17 01:02:39 +00003899 q_vector->rx_ring->total_bytes = 0;
3900 q_vector->rx_ring->total_packets = 0;
3901 q_vector->tx_ring->total_bytes = 0;
3902 q_vector->tx_ring->total_packets = 0;
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003903
Alexander Duyck047e0032009-10-27 15:49:27 +00003904 if (new_itr != q_vector->itr_val) {
Auke Kok9d5c8242008-01-24 02:22:38 -08003905 /* this attempts to bias the interrupt rate towards Bulk
3906 * by adding intermediate steps when interrupt rate is
3907 * increasing */
Alexander Duyck047e0032009-10-27 15:49:27 +00003908 new_itr = new_itr > q_vector->itr_val ?
3909 max((new_itr * q_vector->itr_val) /
3910 (new_itr + (q_vector->itr_val >> 2)),
3911 new_itr) :
Auke Kok9d5c8242008-01-24 02:22:38 -08003912 new_itr;
3913 /* Don't write the value here; it resets the adapter's
3914 * internal timer, and causes us to delay far longer than
3915 * we should between interrupts. Instead, we write the ITR
3916 * value at the beginning of the next interrupt so the timing
3917 * ends up being correct.
3918 */
Alexander Duyck047e0032009-10-27 15:49:27 +00003919 q_vector->itr_val = new_itr;
3920 q_vector->set_itr = 1;
Auke Kok9d5c8242008-01-24 02:22:38 -08003921 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003922}
3923
Auke Kok9d5c8242008-01-24 02:22:38 -08003924#define IGB_TX_FLAGS_CSUM 0x00000001
3925#define IGB_TX_FLAGS_VLAN 0x00000002
3926#define IGB_TX_FLAGS_TSO 0x00000004
3927#define IGB_TX_FLAGS_IPV4 0x00000008
Alexander Duyckcdfd01fc2009-10-27 23:50:57 +00003928#define IGB_TX_FLAGS_TSTAMP 0x00000010
3929#define IGB_TX_FLAGS_VLAN_MASK 0xffff0000
3930#define IGB_TX_FLAGS_VLAN_SHIFT 16
Auke Kok9d5c8242008-01-24 02:22:38 -08003931
Alexander Duyck85ad76b2009-10-27 15:52:46 +00003932static inline int igb_tso_adv(struct igb_ring *tx_ring,
Auke Kok9d5c8242008-01-24 02:22:38 -08003933 struct sk_buff *skb, u32 tx_flags, u8 *hdr_len)
3934{
3935 struct e1000_adv_tx_context_desc *context_desc;
3936 unsigned int i;
3937 int err;
3938 struct igb_buffer *buffer_info;
3939 u32 info = 0, tu_cmd = 0;
Nick Nunley91d4ee32010-02-17 01:04:56 +00003940 u32 mss_l4len_idx;
3941 u8 l4len;
Auke Kok9d5c8242008-01-24 02:22:38 -08003942
3943 if (skb_header_cloned(skb)) {
3944 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3945 if (err)
3946 return err;
3947 }
3948
3949 l4len = tcp_hdrlen(skb);
3950 *hdr_len += l4len;
3951
3952 if (skb->protocol == htons(ETH_P_IP)) {
3953 struct iphdr *iph = ip_hdr(skb);
3954 iph->tot_len = 0;
3955 iph->check = 0;
3956 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
3957 iph->daddr, 0,
3958 IPPROTO_TCP,
3959 0);
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08003960 } else if (skb_is_gso_v6(skb)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08003961 ipv6_hdr(skb)->payload_len = 0;
3962 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
3963 &ipv6_hdr(skb)->daddr,
3964 0, IPPROTO_TCP, 0);
3965 }
3966
3967 i = tx_ring->next_to_use;
3968
3969 buffer_info = &tx_ring->buffer_info[i];
3970 context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i);
3971 /* VLAN MACLEN IPLEN */
3972 if (tx_flags & IGB_TX_FLAGS_VLAN)
3973 info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK);
3974 info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
3975 *hdr_len += skb_network_offset(skb);
3976 info |= skb_network_header_len(skb);
3977 *hdr_len += skb_network_header_len(skb);
3978 context_desc->vlan_macip_lens = cpu_to_le32(info);
3979
3980 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
3981 tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
3982
3983 if (skb->protocol == htons(ETH_P_IP))
3984 tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
3985 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
3986
3987 context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
3988
3989 /* MSS L4LEN IDX */
3990 mss_l4len_idx = (skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT);
3991 mss_l4len_idx |= (l4len << E1000_ADVTXD_L4LEN_SHIFT);
3992
Alexander Duyck73cd78f2009-02-12 18:16:59 +00003993 /* For 82575, context index must be unique per ring. */
Alexander Duyck85ad76b2009-10-27 15:52:46 +00003994 if (tx_ring->flags & IGB_RING_FLAG_TX_CTX_IDX)
3995 mss_l4len_idx |= tx_ring->reg_idx << 4;
Auke Kok9d5c8242008-01-24 02:22:38 -08003996
3997 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
3998 context_desc->seqnum_seed = 0;
3999
4000 buffer_info->time_stamp = jiffies;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08004001 buffer_info->next_to_watch = i;
Auke Kok9d5c8242008-01-24 02:22:38 -08004002 buffer_info->dma = 0;
4003 i++;
4004 if (i == tx_ring->count)
4005 i = 0;
4006
4007 tx_ring->next_to_use = i;
4008
4009 return true;
4010}
4011
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004012static inline bool igb_tx_csum_adv(struct igb_ring *tx_ring,
4013 struct sk_buff *skb, u32 tx_flags)
Auke Kok9d5c8242008-01-24 02:22:38 -08004014{
4015 struct e1000_adv_tx_context_desc *context_desc;
Alexander Duyck59d71982010-04-27 13:09:25 +00004016 struct device *dev = tx_ring->dev;
Auke Kok9d5c8242008-01-24 02:22:38 -08004017 struct igb_buffer *buffer_info;
4018 u32 info = 0, tu_cmd = 0;
Alexander Duyck80785292009-10-27 15:51:47 +00004019 unsigned int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08004020
4021 if ((skb->ip_summed == CHECKSUM_PARTIAL) ||
4022 (tx_flags & IGB_TX_FLAGS_VLAN)) {
4023 i = tx_ring->next_to_use;
4024 buffer_info = &tx_ring->buffer_info[i];
4025 context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i);
4026
4027 if (tx_flags & IGB_TX_FLAGS_VLAN)
4028 info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK);
Alexander Duyckcdfd01fc2009-10-27 23:50:57 +00004029
Auke Kok9d5c8242008-01-24 02:22:38 -08004030 info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
4031 if (skb->ip_summed == CHECKSUM_PARTIAL)
4032 info |= skb_network_header_len(skb);
4033
4034 context_desc->vlan_macip_lens = cpu_to_le32(info);
4035
4036 tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
4037
4038 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Arthur Jonesfa4a7ef2009-03-21 16:55:07 -07004039 __be16 protocol;
4040
4041 if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) {
4042 const struct vlan_ethhdr *vhdr =
4043 (const struct vlan_ethhdr*)skb->data;
4044
4045 protocol = vhdr->h_vlan_encapsulated_proto;
4046 } else {
4047 protocol = skb->protocol;
4048 }
4049
4050 switch (protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004051 case cpu_to_be16(ETH_P_IP):
Auke Kok9d5c8242008-01-24 02:22:38 -08004052 tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
Mitch Williams44b0cda2008-03-07 10:32:13 -08004053 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4054 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburgb9473562009-04-27 22:36:13 +00004055 else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
4056 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_SCTP;
Mitch Williams44b0cda2008-03-07 10:32:13 -08004057 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004058 case cpu_to_be16(ETH_P_IPV6):
Mitch Williams44b0cda2008-03-07 10:32:13 -08004059 /* XXX what about other V6 headers?? */
4060 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4061 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburgb9473562009-04-27 22:36:13 +00004062 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
4063 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_SCTP;
Mitch Williams44b0cda2008-03-07 10:32:13 -08004064 break;
4065 default:
4066 if (unlikely(net_ratelimit()))
Alexander Duyck59d71982010-04-27 13:09:25 +00004067 dev_warn(dev,
Mitch Williams44b0cda2008-03-07 10:32:13 -08004068 "partial checksum but proto=%x!\n",
4069 skb->protocol);
4070 break;
4071 }
Auke Kok9d5c8242008-01-24 02:22:38 -08004072 }
4073
4074 context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
4075 context_desc->seqnum_seed = 0;
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004076 if (tx_ring->flags & IGB_RING_FLAG_TX_CTX_IDX)
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07004077 context_desc->mss_l4len_idx =
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004078 cpu_to_le32(tx_ring->reg_idx << 4);
Auke Kok9d5c8242008-01-24 02:22:38 -08004079
4080 buffer_info->time_stamp = jiffies;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08004081 buffer_info->next_to_watch = i;
Auke Kok9d5c8242008-01-24 02:22:38 -08004082 buffer_info->dma = 0;
4083
4084 i++;
4085 if (i == tx_ring->count)
4086 i = 0;
4087 tx_ring->next_to_use = i;
4088
4089 return true;
4090 }
Auke Kok9d5c8242008-01-24 02:22:38 -08004091 return false;
4092}
4093
4094#define IGB_MAX_TXD_PWR 16
4095#define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR)
4096
Alexander Duyck80785292009-10-27 15:51:47 +00004097static inline int igb_tx_map_adv(struct igb_ring *tx_ring, struct sk_buff *skb,
Alexander Duyck0e014cb2008-12-26 01:33:18 -08004098 unsigned int first)
Auke Kok9d5c8242008-01-24 02:22:38 -08004099{
4100 struct igb_buffer *buffer_info;
Alexander Duyck59d71982010-04-27 13:09:25 +00004101 struct device *dev = tx_ring->dev;
Nick Nunley28739572010-05-04 21:58:07 +00004102 unsigned int hlen = skb_headlen(skb);
Auke Kok9d5c8242008-01-24 02:22:38 -08004103 unsigned int count = 0, i;
4104 unsigned int f;
Nick Nunley28739572010-05-04 21:58:07 +00004105 u16 gso_segs = skb_shinfo(skb)->gso_segs ?: 1;
Auke Kok9d5c8242008-01-24 02:22:38 -08004106
4107 i = tx_ring->next_to_use;
4108
4109 buffer_info = &tx_ring->buffer_info[i];
Nick Nunley28739572010-05-04 21:58:07 +00004110 BUG_ON(hlen >= IGB_MAX_DATA_PER_TXD);
4111 buffer_info->length = hlen;
Auke Kok9d5c8242008-01-24 02:22:38 -08004112 /* set time_stamp *before* dma to help avoid a possible race */
4113 buffer_info->time_stamp = jiffies;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08004114 buffer_info->next_to_watch = i;
Nick Nunley28739572010-05-04 21:58:07 +00004115 buffer_info->dma = dma_map_single(dev, skb->data, hlen,
Alexander Duyck59d71982010-04-27 13:09:25 +00004116 DMA_TO_DEVICE);
4117 if (dma_mapping_error(dev, buffer_info->dma))
Alexander Duyck6366ad32009-12-02 16:47:18 +00004118 goto dma_error;
Auke Kok9d5c8242008-01-24 02:22:38 -08004119
4120 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) {
Nick Nunley28739572010-05-04 21:58:07 +00004121 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[f];
4122 unsigned int len = frag->size;
Auke Kok9d5c8242008-01-24 02:22:38 -08004123
Alexander Duyck85811452010-01-23 01:35:00 -08004124 count++;
Alexander Duyck65689fe2009-03-20 00:17:43 +00004125 i++;
4126 if (i == tx_ring->count)
4127 i = 0;
4128
Auke Kok9d5c8242008-01-24 02:22:38 -08004129 buffer_info = &tx_ring->buffer_info[i];
4130 BUG_ON(len >= IGB_MAX_DATA_PER_TXD);
4131 buffer_info->length = len;
4132 buffer_info->time_stamp = jiffies;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08004133 buffer_info->next_to_watch = i;
Alexander Duyck6366ad32009-12-02 16:47:18 +00004134 buffer_info->mapped_as_page = true;
Alexander Duyck59d71982010-04-27 13:09:25 +00004135 buffer_info->dma = dma_map_page(dev,
Alexander Duyck6366ad32009-12-02 16:47:18 +00004136 frag->page,
4137 frag->page_offset,
4138 len,
Alexander Duyck59d71982010-04-27 13:09:25 +00004139 DMA_TO_DEVICE);
4140 if (dma_mapping_error(dev, buffer_info->dma))
Alexander Duyck6366ad32009-12-02 16:47:18 +00004141 goto dma_error;
4142
Auke Kok9d5c8242008-01-24 02:22:38 -08004143 }
4144
Auke Kok9d5c8242008-01-24 02:22:38 -08004145 tx_ring->buffer_info[i].skb = skb;
Oliver Hartkopp2244d072010-08-17 08:59:14 +00004146 tx_ring->buffer_info[i].tx_flags = skb_shinfo(skb)->tx_flags;
Nick Nunley28739572010-05-04 21:58:07 +00004147 /* multiply data chunks by size of headers */
4148 tx_ring->buffer_info[i].bytecount = ((gso_segs - 1) * hlen) + skb->len;
4149 tx_ring->buffer_info[i].gso_segs = gso_segs;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08004150 tx_ring->buffer_info[first].next_to_watch = i;
Auke Kok9d5c8242008-01-24 02:22:38 -08004151
Alexander Duyckcdfd01fc2009-10-27 23:50:57 +00004152 return ++count;
Alexander Duyck6366ad32009-12-02 16:47:18 +00004153
4154dma_error:
Alexander Duyck59d71982010-04-27 13:09:25 +00004155 dev_err(dev, "TX DMA map failed\n");
Alexander Duyck6366ad32009-12-02 16:47:18 +00004156
4157 /* clear timestamp and dma mappings for failed buffer_info mapping */
4158 buffer_info->dma = 0;
4159 buffer_info->time_stamp = 0;
4160 buffer_info->length = 0;
4161 buffer_info->next_to_watch = 0;
4162 buffer_info->mapped_as_page = false;
Alexander Duyck6366ad32009-12-02 16:47:18 +00004163
4164 /* clear timestamp and dma mappings for remaining portion of packet */
Nick Nunleya77ff702010-02-17 01:06:16 +00004165 while (count--) {
4166 if (i == 0)
4167 i = tx_ring->count;
Alexander Duyck6366ad32009-12-02 16:47:18 +00004168 i--;
Alexander Duyck6366ad32009-12-02 16:47:18 +00004169 buffer_info = &tx_ring->buffer_info[i];
4170 igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
4171 }
4172
4173 return 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08004174}
4175
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004176static inline void igb_tx_queue_adv(struct igb_ring *tx_ring,
Nick Nunley91d4ee32010-02-17 01:04:56 +00004177 u32 tx_flags, int count, u32 paylen,
Auke Kok9d5c8242008-01-24 02:22:38 -08004178 u8 hdr_len)
4179{
Alexander Duyckcdfd01fc2009-10-27 23:50:57 +00004180 union e1000_adv_tx_desc *tx_desc;
Auke Kok9d5c8242008-01-24 02:22:38 -08004181 struct igb_buffer *buffer_info;
4182 u32 olinfo_status = 0, cmd_type_len;
Alexander Duyckcdfd01fc2009-10-27 23:50:57 +00004183 unsigned int i = tx_ring->next_to_use;
Auke Kok9d5c8242008-01-24 02:22:38 -08004184
4185 cmd_type_len = (E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS |
4186 E1000_ADVTXD_DCMD_DEXT);
4187
4188 if (tx_flags & IGB_TX_FLAGS_VLAN)
4189 cmd_type_len |= E1000_ADVTXD_DCMD_VLE;
4190
Patrick Ohly33af6bc2009-02-12 05:03:43 +00004191 if (tx_flags & IGB_TX_FLAGS_TSTAMP)
4192 cmd_type_len |= E1000_ADVTXD_MAC_TSTAMP;
4193
Auke Kok9d5c8242008-01-24 02:22:38 -08004194 if (tx_flags & IGB_TX_FLAGS_TSO) {
4195 cmd_type_len |= E1000_ADVTXD_DCMD_TSE;
4196
4197 /* insert tcp checksum */
4198 olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
4199
4200 /* insert ip checksum */
4201 if (tx_flags & IGB_TX_FLAGS_IPV4)
4202 olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
4203
4204 } else if (tx_flags & IGB_TX_FLAGS_CSUM) {
4205 olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
4206 }
4207
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004208 if ((tx_ring->flags & IGB_RING_FLAG_TX_CTX_IDX) &&
4209 (tx_flags & (IGB_TX_FLAGS_CSUM |
4210 IGB_TX_FLAGS_TSO |
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07004211 IGB_TX_FLAGS_VLAN)))
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004212 olinfo_status |= tx_ring->reg_idx << 4;
Auke Kok9d5c8242008-01-24 02:22:38 -08004213
4214 olinfo_status |= ((paylen - hdr_len) << E1000_ADVTXD_PAYLEN_SHIFT);
4215
Alexander Duyckcdfd01fc2009-10-27 23:50:57 +00004216 do {
Auke Kok9d5c8242008-01-24 02:22:38 -08004217 buffer_info = &tx_ring->buffer_info[i];
4218 tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
4219 tx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
4220 tx_desc->read.cmd_type_len =
4221 cpu_to_le32(cmd_type_len | buffer_info->length);
4222 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckcdfd01fc2009-10-27 23:50:57 +00004223 count--;
Auke Kok9d5c8242008-01-24 02:22:38 -08004224 i++;
4225 if (i == tx_ring->count)
4226 i = 0;
Alexander Duyckcdfd01fc2009-10-27 23:50:57 +00004227 } while (count > 0);
Auke Kok9d5c8242008-01-24 02:22:38 -08004228
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004229 tx_desc->read.cmd_type_len |= cpu_to_le32(IGB_ADVTXD_DCMD);
Auke Kok9d5c8242008-01-24 02:22:38 -08004230 /* Force memory writes to complete before letting h/w
4231 * know there are new descriptors to fetch. (Only
4232 * applicable for weak-ordered memory model archs,
4233 * such as IA-64). */
4234 wmb();
4235
4236 tx_ring->next_to_use = i;
Alexander Duyckfce99e32009-10-27 15:51:27 +00004237 writel(i, tx_ring->tail);
Auke Kok9d5c8242008-01-24 02:22:38 -08004238 /* we need this if more than one processor can write to our tail
4239 * at a time, it syncronizes IO on IA64/Altix systems */
4240 mmiowb();
4241}
4242
Alexander Duycke694e962009-10-27 15:53:06 +00004243static int __igb_maybe_stop_tx(struct igb_ring *tx_ring, int size)
Auke Kok9d5c8242008-01-24 02:22:38 -08004244{
Alexander Duycke694e962009-10-27 15:53:06 +00004245 struct net_device *netdev = tx_ring->netdev;
4246
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004247 netif_stop_subqueue(netdev, tx_ring->queue_index);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004248
Auke Kok9d5c8242008-01-24 02:22:38 -08004249 /* Herbert's original patch had:
4250 * smp_mb__after_netif_stop_queue();
4251 * but since that doesn't exist yet, just open code it. */
4252 smp_mb();
4253
4254 /* We need to check again in a case another CPU has just
4255 * made room available. */
Alexander Duyckc493ea42009-03-20 00:16:50 +00004256 if (igb_desc_unused(tx_ring) < size)
Auke Kok9d5c8242008-01-24 02:22:38 -08004257 return -EBUSY;
4258
4259 /* A reprieve! */
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004260 netif_wake_subqueue(netdev, tx_ring->queue_index);
Eric Dumazet12dcd862010-10-15 17:27:10 +00004261
4262 u64_stats_update_begin(&tx_ring->tx_syncp2);
4263 tx_ring->tx_stats.restart_queue2++;
4264 u64_stats_update_end(&tx_ring->tx_syncp2);
4265
Auke Kok9d5c8242008-01-24 02:22:38 -08004266 return 0;
4267}
4268
Nick Nunley717ba082010-02-17 01:04:18 +00004269static inline int igb_maybe_stop_tx(struct igb_ring *tx_ring, int size)
Auke Kok9d5c8242008-01-24 02:22:38 -08004270{
Alexander Duyckc493ea42009-03-20 00:16:50 +00004271 if (igb_desc_unused(tx_ring) >= size)
Auke Kok9d5c8242008-01-24 02:22:38 -08004272 return 0;
Alexander Duycke694e962009-10-27 15:53:06 +00004273 return __igb_maybe_stop_tx(tx_ring, size);
Auke Kok9d5c8242008-01-24 02:22:38 -08004274}
4275
Alexander Duyckb1a436c2009-10-27 15:54:43 +00004276netdev_tx_t igb_xmit_frame_ring_adv(struct sk_buff *skb,
4277 struct igb_ring *tx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08004278{
Alexander Duyckcdfd01fc2009-10-27 23:50:57 +00004279 int tso = 0, count;
Nick Nunley91d4ee32010-02-17 01:04:56 +00004280 u32 tx_flags = 0;
4281 u16 first;
4282 u8 hdr_len = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08004283
Auke Kok9d5c8242008-01-24 02:22:38 -08004284 /* need: 1 descriptor per page,
4285 * + 2 desc gap to keep tail from touching head,
4286 * + 1 desc for skb->data,
4287 * + 1 desc for context descriptor,
4288 * otherwise try next time */
Alexander Duycke694e962009-10-27 15:53:06 +00004289 if (igb_maybe_stop_tx(tx_ring, skb_shinfo(skb)->nr_frags + 4)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08004290 /* this is a hard error */
Auke Kok9d5c8242008-01-24 02:22:38 -08004291 return NETDEV_TX_BUSY;
4292 }
Patrick Ohly33af6bc2009-02-12 05:03:43 +00004293
Oliver Hartkopp2244d072010-08-17 08:59:14 +00004294 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
4295 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00004296 tx_flags |= IGB_TX_FLAGS_TSTAMP;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00004297 }
Auke Kok9d5c8242008-01-24 02:22:38 -08004298
Jesse Grosseab6d182010-10-20 13:56:03 +00004299 if (vlan_tx_tag_present(skb)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08004300 tx_flags |= IGB_TX_FLAGS_VLAN;
4301 tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
4302 }
4303
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004304 if (skb->protocol == htons(ETH_P_IP))
4305 tx_flags |= IGB_TX_FLAGS_IPV4;
4306
Alexander Duyck0e014cb2008-12-26 01:33:18 -08004307 first = tx_ring->next_to_use;
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004308 if (skb_is_gso(skb)) {
4309 tso = igb_tso_adv(tx_ring, skb, tx_flags, &hdr_len);
Alexander Duyckcdfd01fc2009-10-27 23:50:57 +00004310
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004311 if (tso < 0) {
4312 dev_kfree_skb_any(skb);
4313 return NETDEV_TX_OK;
4314 }
Auke Kok9d5c8242008-01-24 02:22:38 -08004315 }
4316
4317 if (tso)
4318 tx_flags |= IGB_TX_FLAGS_TSO;
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004319 else if (igb_tx_csum_adv(tx_ring, skb, tx_flags) &&
Alexander Duyckbc1cbd32009-02-13 14:45:17 +00004320 (skb->ip_summed == CHECKSUM_PARTIAL))
4321 tx_flags |= IGB_TX_FLAGS_CSUM;
Auke Kok9d5c8242008-01-24 02:22:38 -08004322
Alexander Duyck65689fe2009-03-20 00:17:43 +00004323 /*
Alexander Duyckcdfd01fc2009-10-27 23:50:57 +00004324 * count reflects descriptors mapped, if 0 or less then mapping error
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004325 * has occurred and we need to rewind the descriptor queue
Alexander Duyck65689fe2009-03-20 00:17:43 +00004326 */
Alexander Duyck80785292009-10-27 15:51:47 +00004327 count = igb_tx_map_adv(tx_ring, skb, first);
Alexander Duyck6366ad32009-12-02 16:47:18 +00004328 if (!count) {
Alexander Duyck65689fe2009-03-20 00:17:43 +00004329 dev_kfree_skb_any(skb);
4330 tx_ring->buffer_info[first].time_stamp = 0;
4331 tx_ring->next_to_use = first;
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004332 return NETDEV_TX_OK;
Alexander Duyck65689fe2009-03-20 00:17:43 +00004333 }
Auke Kok9d5c8242008-01-24 02:22:38 -08004334
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004335 igb_tx_queue_adv(tx_ring, tx_flags, count, skb->len, hdr_len);
4336
4337 /* Make sure there is space in the ring for the next send. */
Alexander Duycke694e962009-10-27 15:53:06 +00004338 igb_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 4);
Alexander Duyck85ad76b2009-10-27 15:52:46 +00004339
Auke Kok9d5c8242008-01-24 02:22:38 -08004340 return NETDEV_TX_OK;
4341}
4342
Stephen Hemminger3b29a562009-08-31 19:50:55 +00004343static netdev_tx_t igb_xmit_frame_adv(struct sk_buff *skb,
4344 struct net_device *netdev)
Auke Kok9d5c8242008-01-24 02:22:38 -08004345{
4346 struct igb_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004347 struct igb_ring *tx_ring;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004348 int r_idx = 0;
Alexander Duyckb1a436c2009-10-27 15:54:43 +00004349
4350 if (test_bit(__IGB_DOWN, &adapter->state)) {
4351 dev_kfree_skb_any(skb);
4352 return NETDEV_TX_OK;
4353 }
4354
4355 if (skb->len <= 0) {
4356 dev_kfree_skb_any(skb);
4357 return NETDEV_TX_OK;
4358 }
4359
Alexander Duyck1bfaf072009-02-19 20:39:23 -08004360 r_idx = skb->queue_mapping & (IGB_ABS_MAX_TX_QUEUES - 1);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004361 tx_ring = adapter->multi_tx_table[r_idx];
Auke Kok9d5c8242008-01-24 02:22:38 -08004362
4363 /* This goes back to the question of how to logically map a tx queue
4364 * to a flow. Right now, performance is impacted slightly negatively
4365 * if using multiple tx queues. If the stack breaks away from a
4366 * single qdisc implementation, we can look at this again. */
Alexander Duycke694e962009-10-27 15:53:06 +00004367 return igb_xmit_frame_ring_adv(skb, tx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08004368}
4369
4370/**
4371 * igb_tx_timeout - Respond to a Tx Hang
4372 * @netdev: network interface device structure
4373 **/
4374static void igb_tx_timeout(struct net_device *netdev)
4375{
4376 struct igb_adapter *adapter = netdev_priv(netdev);
4377 struct e1000_hw *hw = &adapter->hw;
4378
4379 /* Do the reset outside of interrupt context */
4380 adapter->tx_timeout_count++;
Alexander Duyckf7ba2052009-10-27 23:48:51 +00004381
Alexander Duyck55cac242009-11-19 12:42:21 +00004382 if (hw->mac.type == e1000_82580)
4383 hw->dev_spec._82575.global_device_reset = true;
4384
Auke Kok9d5c8242008-01-24 02:22:38 -08004385 schedule_work(&adapter->reset_task);
Alexander Duyck265de402009-02-06 23:22:52 +00004386 wr32(E1000_EICS,
4387 (adapter->eims_enable_mask & ~adapter->eims_other));
Auke Kok9d5c8242008-01-24 02:22:38 -08004388}
4389
4390static void igb_reset_task(struct work_struct *work)
4391{
4392 struct igb_adapter *adapter;
4393 adapter = container_of(work, struct igb_adapter, reset_task);
4394
Taku Izumic97ec422010-04-27 14:39:30 +00004395 igb_dump(adapter);
4396 netdev_err(adapter->netdev, "Reset adapter\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08004397 igb_reinit_locked(adapter);
4398}
4399
4400/**
Eric Dumazet12dcd862010-10-15 17:27:10 +00004401 * igb_get_stats64 - Get System Network Statistics
Auke Kok9d5c8242008-01-24 02:22:38 -08004402 * @netdev: network interface device structure
Eric Dumazet12dcd862010-10-15 17:27:10 +00004403 * @stats: rtnl_link_stats64 pointer
Auke Kok9d5c8242008-01-24 02:22:38 -08004404 *
Auke Kok9d5c8242008-01-24 02:22:38 -08004405 **/
Eric Dumazet12dcd862010-10-15 17:27:10 +00004406static struct rtnl_link_stats64 *igb_get_stats64(struct net_device *netdev,
4407 struct rtnl_link_stats64 *stats)
Auke Kok9d5c8242008-01-24 02:22:38 -08004408{
Eric Dumazet12dcd862010-10-15 17:27:10 +00004409 struct igb_adapter *adapter = netdev_priv(netdev);
4410
4411 spin_lock(&adapter->stats64_lock);
4412 igb_update_stats(adapter, &adapter->stats64);
4413 memcpy(stats, &adapter->stats64, sizeof(*stats));
4414 spin_unlock(&adapter->stats64_lock);
4415
4416 return stats;
Auke Kok9d5c8242008-01-24 02:22:38 -08004417}
4418
4419/**
4420 * igb_change_mtu - Change the Maximum Transfer Unit
4421 * @netdev: network interface device structure
4422 * @new_mtu: new value for maximum frame size
4423 *
4424 * Returns 0 on success, negative on failure
4425 **/
4426static int igb_change_mtu(struct net_device *netdev, int new_mtu)
4427{
4428 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck090b1792009-10-27 23:51:55 +00004429 struct pci_dev *pdev = adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08004430 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck4c844852009-10-27 15:52:07 +00004431 u32 rx_buffer_len, i;
Auke Kok9d5c8242008-01-24 02:22:38 -08004432
Alexander Duyckc809d222009-10-27 23:52:13 +00004433 if ((new_mtu < 68) || (max_frame > MAX_JUMBO_FRAME_SIZE)) {
Alexander Duyck090b1792009-10-27 23:51:55 +00004434 dev_err(&pdev->dev, "Invalid MTU setting\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08004435 return -EINVAL;
4436 }
4437
Auke Kok9d5c8242008-01-24 02:22:38 -08004438 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
Alexander Duyck090b1792009-10-27 23:51:55 +00004439 dev_err(&pdev->dev, "MTU > 9216 not supported.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08004440 return -EINVAL;
4441 }
4442
4443 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
4444 msleep(1);
Alexander Duyck73cd78f2009-02-12 18:16:59 +00004445
Auke Kok9d5c8242008-01-24 02:22:38 -08004446 /* igb_down has a dependency on max_frame_size */
4447 adapter->max_frame_size = max_frame;
Alexander Duyck559e9c42009-10-27 23:52:50 +00004448
Auke Kok9d5c8242008-01-24 02:22:38 -08004449 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
4450 * means we reserve 2 more, this pushes us to allocate from the next
4451 * larger slab size.
4452 * i.e. RXBUFFER_2048 --> size-4096 slab
4453 */
4454
Nick Nunley757b77e2010-03-26 11:36:47 +00004455 if (adapter->hw.mac.type == e1000_82580)
4456 max_frame += IGB_TS_HDR_LEN;
4457
Alexander Duyck7d95b712009-10-27 15:50:08 +00004458 if (max_frame <= IGB_RXBUFFER_1024)
Alexander Duyck4c844852009-10-27 15:52:07 +00004459 rx_buffer_len = IGB_RXBUFFER_1024;
Alexander Duyck6ec43fe2009-10-27 15:50:48 +00004460 else if (max_frame <= MAXIMUM_ETHERNET_VLAN_SIZE)
Alexander Duyck4c844852009-10-27 15:52:07 +00004461 rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Alexander Duyck6ec43fe2009-10-27 15:50:48 +00004462 else
Alexander Duyck4c844852009-10-27 15:52:07 +00004463 rx_buffer_len = IGB_RXBUFFER_128;
4464
Nick Nunley757b77e2010-03-26 11:36:47 +00004465 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN + IGB_TS_HDR_LEN) ||
4466 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE + IGB_TS_HDR_LEN))
4467 rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE + IGB_TS_HDR_LEN;
4468
4469 if ((adapter->hw.mac.type == e1000_82580) &&
4470 (rx_buffer_len == IGB_RXBUFFER_128))
4471 rx_buffer_len += IGB_RXBUFFER_64;
4472
Alexander Duyck4c844852009-10-27 15:52:07 +00004473 if (netif_running(netdev))
4474 igb_down(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08004475
Alexander Duyck090b1792009-10-27 23:51:55 +00004476 dev_info(&pdev->dev, "changing MTU from %d to %d\n",
Auke Kok9d5c8242008-01-24 02:22:38 -08004477 netdev->mtu, new_mtu);
4478 netdev->mtu = new_mtu;
4479
Alexander Duyck4c844852009-10-27 15:52:07 +00004480 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyck3025a442010-02-17 01:02:39 +00004481 adapter->rx_ring[i]->rx_buffer_len = rx_buffer_len;
Alexander Duyck4c844852009-10-27 15:52:07 +00004482
Auke Kok9d5c8242008-01-24 02:22:38 -08004483 if (netif_running(netdev))
4484 igb_up(adapter);
4485 else
4486 igb_reset(adapter);
4487
4488 clear_bit(__IGB_RESETTING, &adapter->state);
4489
4490 return 0;
4491}
4492
4493/**
4494 * igb_update_stats - Update the board statistics counters
4495 * @adapter: board private structure
4496 **/
4497
Eric Dumazet12dcd862010-10-15 17:27:10 +00004498void igb_update_stats(struct igb_adapter *adapter,
4499 struct rtnl_link_stats64 *net_stats)
Auke Kok9d5c8242008-01-24 02:22:38 -08004500{
4501 struct e1000_hw *hw = &adapter->hw;
4502 struct pci_dev *pdev = adapter->pdev;
Mitch Williamsfa3d9a62010-03-23 18:34:38 +00004503 u32 reg, mpc;
Auke Kok9d5c8242008-01-24 02:22:38 -08004504 u16 phy_tmp;
Alexander Duyck3f9c0162009-10-27 23:48:12 +00004505 int i;
4506 u64 bytes, packets;
Eric Dumazet12dcd862010-10-15 17:27:10 +00004507 unsigned int start;
4508 u64 _bytes, _packets;
Auke Kok9d5c8242008-01-24 02:22:38 -08004509
4510#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
4511
4512 /*
4513 * Prevent stats update while adapter is being reset, or if the pci
4514 * connection is down.
4515 */
4516 if (adapter->link_speed == 0)
4517 return;
4518 if (pci_channel_offline(pdev))
4519 return;
4520
Alexander Duyck3f9c0162009-10-27 23:48:12 +00004521 bytes = 0;
4522 packets = 0;
4523 for (i = 0; i < adapter->num_rx_queues; i++) {
4524 u32 rqdpc_tmp = rd32(E1000_RQDPC(i)) & 0x0FFF;
Alexander Duyck3025a442010-02-17 01:02:39 +00004525 struct igb_ring *ring = adapter->rx_ring[i];
Eric Dumazet12dcd862010-10-15 17:27:10 +00004526
Alexander Duyck3025a442010-02-17 01:02:39 +00004527 ring->rx_stats.drops += rqdpc_tmp;
Alexander Duyck128e45e2009-11-12 18:37:38 +00004528 net_stats->rx_fifo_errors += rqdpc_tmp;
Eric Dumazet12dcd862010-10-15 17:27:10 +00004529
4530 do {
4531 start = u64_stats_fetch_begin_bh(&ring->rx_syncp);
4532 _bytes = ring->rx_stats.bytes;
4533 _packets = ring->rx_stats.packets;
4534 } while (u64_stats_fetch_retry_bh(&ring->rx_syncp, start));
4535 bytes += _bytes;
4536 packets += _packets;
Alexander Duyck3f9c0162009-10-27 23:48:12 +00004537 }
4538
Alexander Duyck128e45e2009-11-12 18:37:38 +00004539 net_stats->rx_bytes = bytes;
4540 net_stats->rx_packets = packets;
Alexander Duyck3f9c0162009-10-27 23:48:12 +00004541
4542 bytes = 0;
4543 packets = 0;
4544 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyck3025a442010-02-17 01:02:39 +00004545 struct igb_ring *ring = adapter->tx_ring[i];
Eric Dumazet12dcd862010-10-15 17:27:10 +00004546 do {
4547 start = u64_stats_fetch_begin_bh(&ring->tx_syncp);
4548 _bytes = ring->tx_stats.bytes;
4549 _packets = ring->tx_stats.packets;
4550 } while (u64_stats_fetch_retry_bh(&ring->tx_syncp, start));
4551 bytes += _bytes;
4552 packets += _packets;
Alexander Duyck3f9c0162009-10-27 23:48:12 +00004553 }
Alexander Duyck128e45e2009-11-12 18:37:38 +00004554 net_stats->tx_bytes = bytes;
4555 net_stats->tx_packets = packets;
Alexander Duyck3f9c0162009-10-27 23:48:12 +00004556
4557 /* read stats registers */
Auke Kok9d5c8242008-01-24 02:22:38 -08004558 adapter->stats.crcerrs += rd32(E1000_CRCERRS);
4559 adapter->stats.gprc += rd32(E1000_GPRC);
4560 adapter->stats.gorc += rd32(E1000_GORCL);
4561 rd32(E1000_GORCH); /* clear GORCL */
4562 adapter->stats.bprc += rd32(E1000_BPRC);
4563 adapter->stats.mprc += rd32(E1000_MPRC);
4564 adapter->stats.roc += rd32(E1000_ROC);
4565
4566 adapter->stats.prc64 += rd32(E1000_PRC64);
4567 adapter->stats.prc127 += rd32(E1000_PRC127);
4568 adapter->stats.prc255 += rd32(E1000_PRC255);
4569 adapter->stats.prc511 += rd32(E1000_PRC511);
4570 adapter->stats.prc1023 += rd32(E1000_PRC1023);
4571 adapter->stats.prc1522 += rd32(E1000_PRC1522);
4572 adapter->stats.symerrs += rd32(E1000_SYMERRS);
4573 adapter->stats.sec += rd32(E1000_SEC);
4574
Mitch Williamsfa3d9a62010-03-23 18:34:38 +00004575 mpc = rd32(E1000_MPC);
4576 adapter->stats.mpc += mpc;
4577 net_stats->rx_fifo_errors += mpc;
Auke Kok9d5c8242008-01-24 02:22:38 -08004578 adapter->stats.scc += rd32(E1000_SCC);
4579 adapter->stats.ecol += rd32(E1000_ECOL);
4580 adapter->stats.mcc += rd32(E1000_MCC);
4581 adapter->stats.latecol += rd32(E1000_LATECOL);
4582 adapter->stats.dc += rd32(E1000_DC);
4583 adapter->stats.rlec += rd32(E1000_RLEC);
4584 adapter->stats.xonrxc += rd32(E1000_XONRXC);
4585 adapter->stats.xontxc += rd32(E1000_XONTXC);
4586 adapter->stats.xoffrxc += rd32(E1000_XOFFRXC);
4587 adapter->stats.xofftxc += rd32(E1000_XOFFTXC);
4588 adapter->stats.fcruc += rd32(E1000_FCRUC);
4589 adapter->stats.gptc += rd32(E1000_GPTC);
4590 adapter->stats.gotc += rd32(E1000_GOTCL);
4591 rd32(E1000_GOTCH); /* clear GOTCL */
Mitch Williamsfa3d9a62010-03-23 18:34:38 +00004592 adapter->stats.rnbc += rd32(E1000_RNBC);
Auke Kok9d5c8242008-01-24 02:22:38 -08004593 adapter->stats.ruc += rd32(E1000_RUC);
4594 adapter->stats.rfc += rd32(E1000_RFC);
4595 adapter->stats.rjc += rd32(E1000_RJC);
4596 adapter->stats.tor += rd32(E1000_TORH);
4597 adapter->stats.tot += rd32(E1000_TOTH);
4598 adapter->stats.tpr += rd32(E1000_TPR);
4599
4600 adapter->stats.ptc64 += rd32(E1000_PTC64);
4601 adapter->stats.ptc127 += rd32(E1000_PTC127);
4602 adapter->stats.ptc255 += rd32(E1000_PTC255);
4603 adapter->stats.ptc511 += rd32(E1000_PTC511);
4604 adapter->stats.ptc1023 += rd32(E1000_PTC1023);
4605 adapter->stats.ptc1522 += rd32(E1000_PTC1522);
4606
4607 adapter->stats.mptc += rd32(E1000_MPTC);
4608 adapter->stats.bptc += rd32(E1000_BPTC);
4609
Nick Nunley2d0b0f62010-02-17 01:02:59 +00004610 adapter->stats.tpt += rd32(E1000_TPT);
4611 adapter->stats.colc += rd32(E1000_COLC);
Auke Kok9d5c8242008-01-24 02:22:38 -08004612
4613 adapter->stats.algnerrc += rd32(E1000_ALGNERRC);
Nick Nunley43915c7c2010-02-17 01:03:58 +00004614 /* read internal phy specific stats */
4615 reg = rd32(E1000_CTRL_EXT);
4616 if (!(reg & E1000_CTRL_EXT_LINK_MODE_MASK)) {
4617 adapter->stats.rxerrc += rd32(E1000_RXERRC);
4618 adapter->stats.tncrs += rd32(E1000_TNCRS);
4619 }
4620
Auke Kok9d5c8242008-01-24 02:22:38 -08004621 adapter->stats.tsctc += rd32(E1000_TSCTC);
4622 adapter->stats.tsctfc += rd32(E1000_TSCTFC);
4623
4624 adapter->stats.iac += rd32(E1000_IAC);
4625 adapter->stats.icrxoc += rd32(E1000_ICRXOC);
4626 adapter->stats.icrxptc += rd32(E1000_ICRXPTC);
4627 adapter->stats.icrxatc += rd32(E1000_ICRXATC);
4628 adapter->stats.ictxptc += rd32(E1000_ICTXPTC);
4629 adapter->stats.ictxatc += rd32(E1000_ICTXATC);
4630 adapter->stats.ictxqec += rd32(E1000_ICTXQEC);
4631 adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC);
4632 adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC);
4633
4634 /* Fill out the OS statistics structure */
Alexander Duyck128e45e2009-11-12 18:37:38 +00004635 net_stats->multicast = adapter->stats.mprc;
4636 net_stats->collisions = adapter->stats.colc;
Auke Kok9d5c8242008-01-24 02:22:38 -08004637
4638 /* Rx Errors */
4639
4640 /* RLEC on some newer hardware can be incorrect so build
Jesper Dangaard Brouer8c0ab702009-05-26 13:50:31 +00004641 * our own version based on RUC and ROC */
Alexander Duyck128e45e2009-11-12 18:37:38 +00004642 net_stats->rx_errors = adapter->stats.rxerrc +
Auke Kok9d5c8242008-01-24 02:22:38 -08004643 adapter->stats.crcerrs + adapter->stats.algnerrc +
4644 adapter->stats.ruc + adapter->stats.roc +
4645 adapter->stats.cexterr;
Alexander Duyck128e45e2009-11-12 18:37:38 +00004646 net_stats->rx_length_errors = adapter->stats.ruc +
4647 adapter->stats.roc;
4648 net_stats->rx_crc_errors = adapter->stats.crcerrs;
4649 net_stats->rx_frame_errors = adapter->stats.algnerrc;
4650 net_stats->rx_missed_errors = adapter->stats.mpc;
Auke Kok9d5c8242008-01-24 02:22:38 -08004651
4652 /* Tx Errors */
Alexander Duyck128e45e2009-11-12 18:37:38 +00004653 net_stats->tx_errors = adapter->stats.ecol +
4654 adapter->stats.latecol;
4655 net_stats->tx_aborted_errors = adapter->stats.ecol;
4656 net_stats->tx_window_errors = adapter->stats.latecol;
4657 net_stats->tx_carrier_errors = adapter->stats.tncrs;
Auke Kok9d5c8242008-01-24 02:22:38 -08004658
4659 /* Tx Dropped needs to be maintained elsewhere */
4660
4661 /* Phy Stats */
4662 if (hw->phy.media_type == e1000_media_type_copper) {
4663 if ((adapter->link_speed == SPEED_1000) &&
Alexander Duyck73cd78f2009-02-12 18:16:59 +00004664 (!igb_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
Auke Kok9d5c8242008-01-24 02:22:38 -08004665 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
4666 adapter->phy_stats.idle_errors += phy_tmp;
4667 }
4668 }
4669
4670 /* Management Stats */
4671 adapter->stats.mgptc += rd32(E1000_MGTPTC);
4672 adapter->stats.mgprc += rd32(E1000_MGTPRC);
4673 adapter->stats.mgpdc += rd32(E1000_MGTPDC);
Carolyn Wyborny0a915b92011-02-26 07:42:37 +00004674
4675 /* OS2BMC Stats */
4676 reg = rd32(E1000_MANC);
4677 if (reg & E1000_MANC_EN_BMC2OS) {
4678 adapter->stats.o2bgptc += rd32(E1000_O2BGPTC);
4679 adapter->stats.o2bspc += rd32(E1000_O2BSPC);
4680 adapter->stats.b2ospc += rd32(E1000_B2OSPC);
4681 adapter->stats.b2ogprc += rd32(E1000_B2OGPRC);
4682 }
Auke Kok9d5c8242008-01-24 02:22:38 -08004683}
4684
Auke Kok9d5c8242008-01-24 02:22:38 -08004685static irqreturn_t igb_msix_other(int irq, void *data)
4686{
Alexander Duyck047e0032009-10-27 15:49:27 +00004687 struct igb_adapter *adapter = data;
Auke Kok9d5c8242008-01-24 02:22:38 -08004688 struct e1000_hw *hw = &adapter->hw;
PJ Waskiewicz844290e2008-06-27 11:00:39 -07004689 u32 icr = rd32(E1000_ICR);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07004690 /* reading ICR causes bit 31 of EICR to be cleared */
Alexander Duyckdda0e082009-02-06 23:19:08 +00004691
Alexander Duyck7f081d42010-01-07 17:41:00 +00004692 if (icr & E1000_ICR_DRSTA)
4693 schedule_work(&adapter->reset_task);
4694
Alexander Duyck047e0032009-10-27 15:49:27 +00004695 if (icr & E1000_ICR_DOUTSYNC) {
Alexander Duyckdda0e082009-02-06 23:19:08 +00004696 /* HW is reporting DMA is out of sync */
4697 adapter->stats.doosync++;
Greg Rose13800462010-11-06 02:08:26 +00004698 /* The DMA Out of Sync is also indication of a spoof event
4699 * in IOV mode. Check the Wrong VM Behavior register to
4700 * see if it is really a spoof event. */
4701 igb_check_wvbr(adapter);
Alexander Duyckdda0e082009-02-06 23:19:08 +00004702 }
Alexander Duyckeebbbdb2009-02-06 23:19:29 +00004703
Alexander Duyck4ae196d2009-02-19 20:40:07 -08004704 /* Check for a mailbox event */
4705 if (icr & E1000_ICR_VMMB)
4706 igb_msg_task(adapter);
4707
4708 if (icr & E1000_ICR_LSC) {
4709 hw->mac.get_link_status = 1;
4710 /* guard against interrupt when we're going down */
4711 if (!test_bit(__IGB_DOWN, &adapter->state))
4712 mod_timer(&adapter->watchdog_timer, jiffies + 1);
4713 }
4714
Alexander Duyck25568a52009-10-27 23:49:59 +00004715 if (adapter->vfs_allocated_count)
4716 wr32(E1000_IMS, E1000_IMS_LSC |
4717 E1000_IMS_VMMB |
4718 E1000_IMS_DOUTSYNC);
4719 else
4720 wr32(E1000_IMS, E1000_IMS_LSC | E1000_IMS_DOUTSYNC);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07004721 wr32(E1000_EIMS, adapter->eims_other);
Auke Kok9d5c8242008-01-24 02:22:38 -08004722
4723 return IRQ_HANDLED;
4724}
4725
Alexander Duyck047e0032009-10-27 15:49:27 +00004726static void igb_write_itr(struct igb_q_vector *q_vector)
Auke Kok9d5c8242008-01-24 02:22:38 -08004727{
Alexander Duyck26b39272010-02-17 01:00:41 +00004728 struct igb_adapter *adapter = q_vector->adapter;
Alexander Duyck047e0032009-10-27 15:49:27 +00004729 u32 itr_val = q_vector->itr_val & 0x7FFC;
Auke Kok9d5c8242008-01-24 02:22:38 -08004730
Alexander Duyck047e0032009-10-27 15:49:27 +00004731 if (!q_vector->set_itr)
4732 return;
Alexander Duyck73cd78f2009-02-12 18:16:59 +00004733
Alexander Duyck047e0032009-10-27 15:49:27 +00004734 if (!itr_val)
4735 itr_val = 0x4;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004736
Alexander Duyck26b39272010-02-17 01:00:41 +00004737 if (adapter->hw.mac.type == e1000_82575)
4738 itr_val |= itr_val << 16;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004739 else
Alexander Duyck047e0032009-10-27 15:49:27 +00004740 itr_val |= 0x8000000;
4741
4742 writel(itr_val, q_vector->itr_register);
4743 q_vector->set_itr = 0;
4744}
4745
4746static irqreturn_t igb_msix_ring(int irq, void *data)
4747{
4748 struct igb_q_vector *q_vector = data;
4749
4750 /* Write the ITR value calculated from the previous interrupt. */
4751 igb_write_itr(q_vector);
4752
4753 napi_schedule(&q_vector->napi);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07004754
Auke Kok9d5c8242008-01-24 02:22:38 -08004755 return IRQ_HANDLED;
4756}
4757
Jeff Kirsher421e02f2008-10-17 11:08:31 -07004758#ifdef CONFIG_IGB_DCA
Alexander Duyck047e0032009-10-27 15:49:27 +00004759static void igb_update_dca(struct igb_q_vector *q_vector)
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004760{
Alexander Duyck047e0032009-10-27 15:49:27 +00004761 struct igb_adapter *adapter = q_vector->adapter;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004762 struct e1000_hw *hw = &adapter->hw;
4763 int cpu = get_cpu();
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004764
Alexander Duyck047e0032009-10-27 15:49:27 +00004765 if (q_vector->cpu == cpu)
4766 goto out_no_update;
4767
4768 if (q_vector->tx_ring) {
4769 int q = q_vector->tx_ring->reg_idx;
4770 u32 dca_txctrl = rd32(E1000_DCA_TXCTRL(q));
4771 if (hw->mac.type == e1000_82575) {
4772 dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK;
4773 dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
4774 } else {
4775 dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK_82576;
4776 dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) <<
4777 E1000_DCA_TXCTRL_CPUID_SHIFT;
4778 }
4779 dca_txctrl |= E1000_DCA_TXCTRL_DESC_DCA_EN;
4780 wr32(E1000_DCA_TXCTRL(q), dca_txctrl);
4781 }
4782 if (q_vector->rx_ring) {
4783 int q = q_vector->rx_ring->reg_idx;
4784 u32 dca_rxctrl = rd32(E1000_DCA_RXCTRL(q));
4785 if (hw->mac.type == e1000_82575) {
4786 dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK;
4787 dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
4788 } else {
Alexander Duyck2d064c02008-07-08 15:10:12 -07004789 dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK_82576;
Maciej Sosnowski92be7912009-03-13 20:40:21 +00004790 dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) <<
Alexander Duyck2d064c02008-07-08 15:10:12 -07004791 E1000_DCA_RXCTRL_CPUID_SHIFT;
Alexander Duyck2d064c02008-07-08 15:10:12 -07004792 }
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004793 dca_rxctrl |= E1000_DCA_RXCTRL_DESC_DCA_EN;
4794 dca_rxctrl |= E1000_DCA_RXCTRL_HEAD_DCA_EN;
4795 dca_rxctrl |= E1000_DCA_RXCTRL_DATA_DCA_EN;
4796 wr32(E1000_DCA_RXCTRL(q), dca_rxctrl);
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004797 }
Alexander Duyck047e0032009-10-27 15:49:27 +00004798 q_vector->cpu = cpu;
4799out_no_update:
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004800 put_cpu();
4801}
4802
4803static void igb_setup_dca(struct igb_adapter *adapter)
4804{
Alexander Duyck7e0e99e2009-05-21 13:06:56 +00004805 struct e1000_hw *hw = &adapter->hw;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004806 int i;
4807
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07004808 if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004809 return;
4810
Alexander Duyck7e0e99e2009-05-21 13:06:56 +00004811 /* Always use CB2 mode, difference is masked in the CB driver. */
4812 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
4813
Alexander Duyck047e0032009-10-27 15:49:27 +00004814 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck26b39272010-02-17 01:00:41 +00004815 adapter->q_vector[i]->cpu = -1;
4816 igb_update_dca(adapter->q_vector[i]);
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004817 }
4818}
4819
4820static int __igb_notify_dca(struct device *dev, void *data)
4821{
4822 struct net_device *netdev = dev_get_drvdata(dev);
4823 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck090b1792009-10-27 23:51:55 +00004824 struct pci_dev *pdev = adapter->pdev;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004825 struct e1000_hw *hw = &adapter->hw;
4826 unsigned long event = *(unsigned long *)data;
4827
4828 switch (event) {
4829 case DCA_PROVIDER_ADD:
4830 /* if already enabled, don't do it again */
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07004831 if (adapter->flags & IGB_FLAG_DCA_ENABLED)
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004832 break;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004833 if (dca_add_requester(dev) == 0) {
Alexander Duyckbbd98fe2009-01-31 00:52:30 -08004834 adapter->flags |= IGB_FLAG_DCA_ENABLED;
Alexander Duyck090b1792009-10-27 23:51:55 +00004835 dev_info(&pdev->dev, "DCA enabled\n");
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004836 igb_setup_dca(adapter);
4837 break;
4838 }
4839 /* Fall Through since DCA is disabled. */
4840 case DCA_PROVIDER_REMOVE:
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07004841 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004842 /* without this a class_device is left
Alexander Duyck047e0032009-10-27 15:49:27 +00004843 * hanging around in the sysfs model */
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004844 dca_remove_requester(dev);
Alexander Duyck090b1792009-10-27 23:51:55 +00004845 dev_info(&pdev->dev, "DCA disabled\n");
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07004846 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
Alexander Duyckcbd347a2009-02-15 23:59:44 -08004847 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004848 }
4849 break;
4850 }
Alexander Duyckbbd98fe2009-01-31 00:52:30 -08004851
Jeb Cramerfe4506b2008-07-08 15:07:55 -07004852 return 0;
4853}
4854
4855static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
4856 void *p)
4857{
4858 int ret_val;
4859
4860 ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
4861 __igb_notify_dca);
4862
4863 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
4864}
Jeff Kirsher421e02f2008-10-17 11:08:31 -07004865#endif /* CONFIG_IGB_DCA */
Auke Kok9d5c8242008-01-24 02:22:38 -08004866
Alexander Duyck4ae196d2009-02-19 20:40:07 -08004867static void igb_ping_all_vfs(struct igb_adapter *adapter)
4868{
4869 struct e1000_hw *hw = &adapter->hw;
4870 u32 ping;
4871 int i;
4872
4873 for (i = 0 ; i < adapter->vfs_allocated_count; i++) {
4874 ping = E1000_PF_CONTROL_MSG;
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00004875 if (adapter->vf_data[i].flags & IGB_VF_FLAG_CTS)
Alexander Duyck4ae196d2009-02-19 20:40:07 -08004876 ping |= E1000_VT_MSGTYPE_CTS;
4877 igb_write_mbx(hw, &ping, 1, i);
4878 }
4879}
4880
Alexander Duyck7d5753f2009-10-27 23:47:16 +00004881static int igb_set_vf_promisc(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
4882{
4883 struct e1000_hw *hw = &adapter->hw;
4884 u32 vmolr = rd32(E1000_VMOLR(vf));
4885 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
4886
Alexander Duyckd85b90042010-09-22 17:56:20 +00004887 vf_data->flags &= ~(IGB_VF_FLAG_UNI_PROMISC |
Alexander Duyck7d5753f2009-10-27 23:47:16 +00004888 IGB_VF_FLAG_MULTI_PROMISC);
4889 vmolr &= ~(E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
4890
4891 if (*msgbuf & E1000_VF_SET_PROMISC_MULTICAST) {
4892 vmolr |= E1000_VMOLR_MPME;
Alexander Duyckd85b90042010-09-22 17:56:20 +00004893 vf_data->flags |= IGB_VF_FLAG_MULTI_PROMISC;
Alexander Duyck7d5753f2009-10-27 23:47:16 +00004894 *msgbuf &= ~E1000_VF_SET_PROMISC_MULTICAST;
4895 } else {
4896 /*
4897 * if we have hashes and we are clearing a multicast promisc
4898 * flag we need to write the hashes to the MTA as this step
4899 * was previously skipped
4900 */
4901 if (vf_data->num_vf_mc_hashes > 30) {
4902 vmolr |= E1000_VMOLR_MPME;
4903 } else if (vf_data->num_vf_mc_hashes) {
4904 int j;
4905 vmolr |= E1000_VMOLR_ROMPE;
4906 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
4907 igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
4908 }
4909 }
4910
4911 wr32(E1000_VMOLR(vf), vmolr);
4912
4913 /* there are flags left unprocessed, likely not supported */
4914 if (*msgbuf & E1000_VT_MSGINFO_MASK)
4915 return -EINVAL;
4916
4917 return 0;
4918
4919}
4920
Alexander Duyck4ae196d2009-02-19 20:40:07 -08004921static int igb_set_vf_multicasts(struct igb_adapter *adapter,
4922 u32 *msgbuf, u32 vf)
4923{
4924 int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
4925 u16 *hash_list = (u16 *)&msgbuf[1];
4926 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
4927 int i;
4928
Alexander Duyck7d5753f2009-10-27 23:47:16 +00004929 /* salt away the number of multicast addresses assigned
Alexander Duyck4ae196d2009-02-19 20:40:07 -08004930 * to this VF for later use to restore when the PF multi cast
4931 * list changes
4932 */
4933 vf_data->num_vf_mc_hashes = n;
4934
Alexander Duyck7d5753f2009-10-27 23:47:16 +00004935 /* only up to 30 hash values supported */
4936 if (n > 30)
4937 n = 30;
4938
4939 /* store the hashes for later use */
Alexander Duyck4ae196d2009-02-19 20:40:07 -08004940 for (i = 0; i < n; i++)
Joe Perchesa419aef2009-08-18 11:18:35 -07004941 vf_data->vf_mc_hashes[i] = hash_list[i];
Alexander Duyck4ae196d2009-02-19 20:40:07 -08004942
4943 /* Flush and reset the mta with the new values */
Alexander Duyckff41f8d2009-09-03 14:48:56 +00004944 igb_set_rx_mode(adapter->netdev);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08004945
4946 return 0;
4947}
4948
4949static void igb_restore_vf_multicasts(struct igb_adapter *adapter)
4950{
4951 struct e1000_hw *hw = &adapter->hw;
4952 struct vf_data_storage *vf_data;
4953 int i, j;
4954
4955 for (i = 0; i < adapter->vfs_allocated_count; i++) {
Alexander Duyck7d5753f2009-10-27 23:47:16 +00004956 u32 vmolr = rd32(E1000_VMOLR(i));
4957 vmolr &= ~(E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
4958
Alexander Duyck4ae196d2009-02-19 20:40:07 -08004959 vf_data = &adapter->vf_data[i];
Alexander Duyck7d5753f2009-10-27 23:47:16 +00004960
4961 if ((vf_data->num_vf_mc_hashes > 30) ||
4962 (vf_data->flags & IGB_VF_FLAG_MULTI_PROMISC)) {
4963 vmolr |= E1000_VMOLR_MPME;
4964 } else if (vf_data->num_vf_mc_hashes) {
4965 vmolr |= E1000_VMOLR_ROMPE;
4966 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
4967 igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
4968 }
4969 wr32(E1000_VMOLR(i), vmolr);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08004970 }
4971}
4972
4973static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf)
4974{
4975 struct e1000_hw *hw = &adapter->hw;
4976 u32 pool_mask, reg, vid;
4977 int i;
4978
4979 pool_mask = 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
4980
4981 /* Find the vlan filter for this id */
4982 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
4983 reg = rd32(E1000_VLVF(i));
4984
4985 /* remove the vf from the pool */
4986 reg &= ~pool_mask;
4987
4988 /* if pool is empty then remove entry from vfta */
4989 if (!(reg & E1000_VLVF_POOLSEL_MASK) &&
4990 (reg & E1000_VLVF_VLANID_ENABLE)) {
4991 reg = 0;
4992 vid = reg & E1000_VLVF_VLANID_MASK;
4993 igb_vfta_set(hw, vid, false);
4994 }
4995
4996 wr32(E1000_VLVF(i), reg);
4997 }
Alexander Duyckae641bd2009-09-03 14:49:33 +00004998
4999 adapter->vf_data[vf].vlans_enabled = 0;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005000}
5001
5002static s32 igb_vlvf_set(struct igb_adapter *adapter, u32 vid, bool add, u32 vf)
5003{
5004 struct e1000_hw *hw = &adapter->hw;
5005 u32 reg, i;
5006
Alexander Duyck51466232009-10-27 23:47:35 +00005007 /* The vlvf table only exists on 82576 hardware and newer */
5008 if (hw->mac.type < e1000_82576)
5009 return -1;
5010
5011 /* we only need to do this if VMDq is enabled */
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005012 if (!adapter->vfs_allocated_count)
5013 return -1;
5014
5015 /* Find the vlan filter for this id */
5016 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
5017 reg = rd32(E1000_VLVF(i));
5018 if ((reg & E1000_VLVF_VLANID_ENABLE) &&
5019 vid == (reg & E1000_VLVF_VLANID_MASK))
5020 break;
5021 }
5022
5023 if (add) {
5024 if (i == E1000_VLVF_ARRAY_SIZE) {
5025 /* Did not find a matching VLAN ID entry that was
5026 * enabled. Search for a free filter entry, i.e.
5027 * one without the enable bit set
5028 */
5029 for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
5030 reg = rd32(E1000_VLVF(i));
5031 if (!(reg & E1000_VLVF_VLANID_ENABLE))
5032 break;
5033 }
5034 }
5035 if (i < E1000_VLVF_ARRAY_SIZE) {
5036 /* Found an enabled/available entry */
5037 reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
5038
5039 /* if !enabled we need to set this up in vfta */
5040 if (!(reg & E1000_VLVF_VLANID_ENABLE)) {
Alexander Duyck51466232009-10-27 23:47:35 +00005041 /* add VID to filter table */
5042 igb_vfta_set(hw, vid, true);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005043 reg |= E1000_VLVF_VLANID_ENABLE;
5044 }
Alexander Duyckcad6d052009-03-13 20:41:37 +00005045 reg &= ~E1000_VLVF_VLANID_MASK;
5046 reg |= vid;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005047 wr32(E1000_VLVF(i), reg);
Alexander Duyckae641bd2009-09-03 14:49:33 +00005048
5049 /* do not modify RLPML for PF devices */
5050 if (vf >= adapter->vfs_allocated_count)
5051 return 0;
5052
5053 if (!adapter->vf_data[vf].vlans_enabled) {
5054 u32 size;
5055 reg = rd32(E1000_VMOLR(vf));
5056 size = reg & E1000_VMOLR_RLPML_MASK;
5057 size += 4;
5058 reg &= ~E1000_VMOLR_RLPML_MASK;
5059 reg |= size;
5060 wr32(E1000_VMOLR(vf), reg);
5061 }
Alexander Duyckae641bd2009-09-03 14:49:33 +00005062
Alexander Duyck51466232009-10-27 23:47:35 +00005063 adapter->vf_data[vf].vlans_enabled++;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005064 return 0;
5065 }
5066 } else {
5067 if (i < E1000_VLVF_ARRAY_SIZE) {
5068 /* remove vf from the pool */
5069 reg &= ~(1 << (E1000_VLVF_POOLSEL_SHIFT + vf));
5070 /* if pool is empty then remove entry from vfta */
5071 if (!(reg & E1000_VLVF_POOLSEL_MASK)) {
5072 reg = 0;
5073 igb_vfta_set(hw, vid, false);
5074 }
5075 wr32(E1000_VLVF(i), reg);
Alexander Duyckae641bd2009-09-03 14:49:33 +00005076
5077 /* do not modify RLPML for PF devices */
5078 if (vf >= adapter->vfs_allocated_count)
5079 return 0;
5080
5081 adapter->vf_data[vf].vlans_enabled--;
5082 if (!adapter->vf_data[vf].vlans_enabled) {
5083 u32 size;
5084 reg = rd32(E1000_VMOLR(vf));
5085 size = reg & E1000_VMOLR_RLPML_MASK;
5086 size -= 4;
5087 reg &= ~E1000_VMOLR_RLPML_MASK;
5088 reg |= size;
5089 wr32(E1000_VMOLR(vf), reg);
5090 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005091 }
5092 }
Williams, Mitch A8151d292010-02-10 01:44:24 +00005093 return 0;
5094}
5095
5096static void igb_set_vmvir(struct igb_adapter *adapter, u32 vid, u32 vf)
5097{
5098 struct e1000_hw *hw = &adapter->hw;
5099
5100 if (vid)
5101 wr32(E1000_VMVIR(vf), (vid | E1000_VMVIR_VLANA_DEFAULT));
5102 else
5103 wr32(E1000_VMVIR(vf), 0);
5104}
5105
5106static int igb_ndo_set_vf_vlan(struct net_device *netdev,
5107 int vf, u16 vlan, u8 qos)
5108{
5109 int err = 0;
5110 struct igb_adapter *adapter = netdev_priv(netdev);
5111
5112 if ((vf >= adapter->vfs_allocated_count) || (vlan > 4095) || (qos > 7))
5113 return -EINVAL;
5114 if (vlan || qos) {
5115 err = igb_vlvf_set(adapter, vlan, !!vlan, vf);
5116 if (err)
5117 goto out;
5118 igb_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf);
5119 igb_set_vmolr(adapter, vf, !vlan);
5120 adapter->vf_data[vf].pf_vlan = vlan;
5121 adapter->vf_data[vf].pf_qos = qos;
5122 dev_info(&adapter->pdev->dev,
5123 "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
5124 if (test_bit(__IGB_DOWN, &adapter->state)) {
5125 dev_warn(&adapter->pdev->dev,
5126 "The VF VLAN has been set,"
5127 " but the PF device is not up.\n");
5128 dev_warn(&adapter->pdev->dev,
5129 "Bring the PF device up before"
5130 " attempting to use the VF device.\n");
5131 }
5132 } else {
5133 igb_vlvf_set(adapter, adapter->vf_data[vf].pf_vlan,
5134 false, vf);
5135 igb_set_vmvir(adapter, vlan, vf);
5136 igb_set_vmolr(adapter, vf, true);
5137 adapter->vf_data[vf].pf_vlan = 0;
5138 adapter->vf_data[vf].pf_qos = 0;
5139 }
5140out:
5141 return err;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005142}
5143
5144static int igb_set_vf_vlan(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
5145{
5146 int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
5147 int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
5148
5149 return igb_vlvf_set(adapter, vid, add, vf);
5150}
5151
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005152static inline void igb_vf_reset(struct igb_adapter *adapter, u32 vf)
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005153{
Greg Rose8fa7e0f2010-11-06 05:43:21 +00005154 /* clear flags - except flag that indicates PF has set the MAC */
5155 adapter->vf_data[vf].flags &= IGB_VF_FLAG_PF_SET_MAC;
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005156 adapter->vf_data[vf].last_nack = jiffies;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005157
5158 /* reset offloads to defaults */
Williams, Mitch A8151d292010-02-10 01:44:24 +00005159 igb_set_vmolr(adapter, vf, true);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005160
5161 /* reset vlans for device */
5162 igb_clear_vf_vfta(adapter, vf);
Williams, Mitch A8151d292010-02-10 01:44:24 +00005163 if (adapter->vf_data[vf].pf_vlan)
5164 igb_ndo_set_vf_vlan(adapter->netdev, vf,
5165 adapter->vf_data[vf].pf_vlan,
5166 adapter->vf_data[vf].pf_qos);
5167 else
5168 igb_clear_vf_vfta(adapter, vf);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005169
5170 /* reset multicast table array for vf */
5171 adapter->vf_data[vf].num_vf_mc_hashes = 0;
5172
5173 /* Flush and reset the mta with the new values */
Alexander Duyckff41f8d2009-09-03 14:48:56 +00005174 igb_set_rx_mode(adapter->netdev);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005175}
5176
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005177static void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf)
5178{
5179 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
5180
5181 /* generate a new mac address as we were hotplug removed/added */
Williams, Mitch A8151d292010-02-10 01:44:24 +00005182 if (!(adapter->vf_data[vf].flags & IGB_VF_FLAG_PF_SET_MAC))
5183 random_ether_addr(vf_mac);
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005184
5185 /* process remaining reset events */
5186 igb_vf_reset(adapter, vf);
5187}
5188
5189static void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf)
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005190{
5191 struct e1000_hw *hw = &adapter->hw;
5192 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
Alexander Duyckff41f8d2009-09-03 14:48:56 +00005193 int rar_entry = hw->mac.rar_entry_count - (vf + 1);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005194 u32 reg, msgbuf[3];
5195 u8 *addr = (u8 *)(&msgbuf[1]);
5196
5197 /* process all the same items cleared in a function level reset */
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005198 igb_vf_reset(adapter, vf);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005199
5200 /* set vf mac address */
Alexander Duyck26ad9172009-10-05 06:32:49 +00005201 igb_rar_set_qsel(adapter, vf_mac, rar_entry, vf);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005202
5203 /* enable transmit and receive for vf */
5204 reg = rd32(E1000_VFTE);
5205 wr32(E1000_VFTE, reg | (1 << vf));
5206 reg = rd32(E1000_VFRE);
5207 wr32(E1000_VFRE, reg | (1 << vf));
5208
Greg Rose8fa7e0f2010-11-06 05:43:21 +00005209 adapter->vf_data[vf].flags |= IGB_VF_FLAG_CTS;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005210
5211 /* reply to reset with ack and vf mac address */
5212 msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK;
5213 memcpy(addr, vf_mac, 6);
5214 igb_write_mbx(hw, msgbuf, 3, vf);
5215}
5216
5217static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf)
5218{
Greg Rosede42edd2010-07-01 13:39:23 +00005219 /*
5220 * The VF MAC Address is stored in a packed array of bytes
5221 * starting at the second 32 bit word of the msg array
5222 */
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005223 unsigned char *addr = (char *)&msg[1];
5224 int err = -1;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005225
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005226 if (is_valid_ether_addr(addr))
5227 err = igb_set_vf_mac(adapter, vf, addr);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005228
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005229 return err;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005230}
5231
5232static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf)
5233{
5234 struct e1000_hw *hw = &adapter->hw;
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005235 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005236 u32 msg = E1000_VT_MSGTYPE_NACK;
5237
5238 /* if device isn't clear to send it shouldn't be reading either */
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005239 if (!(vf_data->flags & IGB_VF_FLAG_CTS) &&
5240 time_after(jiffies, vf_data->last_nack + (2 * HZ))) {
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005241 igb_write_mbx(hw, &msg, 1, vf);
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005242 vf_data->last_nack = jiffies;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005243 }
5244}
5245
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005246static void igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf)
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005247{
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005248 struct pci_dev *pdev = adapter->pdev;
5249 u32 msgbuf[E1000_VFMAILBOX_SIZE];
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005250 struct e1000_hw *hw = &adapter->hw;
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005251 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005252 s32 retval;
5253
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005254 retval = igb_read_mbx(hw, msgbuf, E1000_VFMAILBOX_SIZE, vf);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005255
Alexander Duyckfef45f42009-12-11 22:57:34 -08005256 if (retval) {
5257 /* if receive failed revoke VF CTS stats and restart init */
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005258 dev_err(&pdev->dev, "Error receiving message from VF\n");
Alexander Duyckfef45f42009-12-11 22:57:34 -08005259 vf_data->flags &= ~IGB_VF_FLAG_CTS;
5260 if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
5261 return;
5262 goto out;
5263 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005264
5265 /* this is a message we already processed, do nothing */
5266 if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK))
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005267 return;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005268
5269 /*
5270 * until the vf completes a reset it should not be
5271 * allowed to start any configuration.
5272 */
5273
5274 if (msgbuf[0] == E1000_VF_RESET) {
5275 igb_vf_reset_msg(adapter, vf);
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005276 return;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005277 }
5278
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005279 if (!(vf_data->flags & IGB_VF_FLAG_CTS)) {
Alexander Duyckfef45f42009-12-11 22:57:34 -08005280 if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
5281 return;
5282 retval = -1;
5283 goto out;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005284 }
5285
5286 switch ((msgbuf[0] & 0xFFFF)) {
5287 case E1000_VF_SET_MAC_ADDR:
Greg Rosea6b5ea32010-11-06 05:42:59 +00005288 retval = -EINVAL;
5289 if (!(vf_data->flags & IGB_VF_FLAG_PF_SET_MAC))
5290 retval = igb_set_vf_mac_addr(adapter, msgbuf, vf);
5291 else
5292 dev_warn(&pdev->dev,
5293 "VF %d attempted to override administratively "
5294 "set MAC address\nReload the VF driver to "
5295 "resume operations\n", vf);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005296 break;
Alexander Duyck7d5753f2009-10-27 23:47:16 +00005297 case E1000_VF_SET_PROMISC:
5298 retval = igb_set_vf_promisc(adapter, msgbuf, vf);
5299 break;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005300 case E1000_VF_SET_MULTICAST:
5301 retval = igb_set_vf_multicasts(adapter, msgbuf, vf);
5302 break;
5303 case E1000_VF_SET_LPE:
5304 retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf);
5305 break;
5306 case E1000_VF_SET_VLAN:
Greg Rosea6b5ea32010-11-06 05:42:59 +00005307 retval = -1;
5308 if (vf_data->pf_vlan)
5309 dev_warn(&pdev->dev,
5310 "VF %d attempted to override administratively "
5311 "set VLAN tag\nReload the VF driver to "
5312 "resume operations\n", vf);
Williams, Mitch A8151d292010-02-10 01:44:24 +00005313 else
5314 retval = igb_set_vf_vlan(adapter, msgbuf, vf);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005315 break;
5316 default:
Alexander Duyck090b1792009-10-27 23:51:55 +00005317 dev_err(&pdev->dev, "Unhandled Msg %08x\n", msgbuf[0]);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005318 retval = -1;
5319 break;
5320 }
5321
Alexander Duyckfef45f42009-12-11 22:57:34 -08005322 msgbuf[0] |= E1000_VT_MSGTYPE_CTS;
5323out:
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005324 /* notify the VF of the results of what it sent us */
5325 if (retval)
5326 msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
5327 else
5328 msgbuf[0] |= E1000_VT_MSGTYPE_ACK;
5329
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005330 igb_write_mbx(hw, msgbuf, 1, vf);
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005331}
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005332
Alexander Duyckf2ca0db2009-10-27 23:46:57 +00005333static void igb_msg_task(struct igb_adapter *adapter)
5334{
5335 struct e1000_hw *hw = &adapter->hw;
5336 u32 vf;
5337
5338 for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
5339 /* process any reset requests */
5340 if (!igb_check_for_rst(hw, vf))
5341 igb_vf_reset_event(adapter, vf);
5342
5343 /* process any messages pending */
5344 if (!igb_check_for_msg(hw, vf))
5345 igb_rcv_msg_from_vf(adapter, vf);
5346
5347 /* process any acks */
5348 if (!igb_check_for_ack(hw, vf))
5349 igb_rcv_ack_from_vf(adapter, vf);
5350 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08005351}
5352
Auke Kok9d5c8242008-01-24 02:22:38 -08005353/**
Alexander Duyck68d480c2009-10-05 06:33:08 +00005354 * igb_set_uta - Set unicast filter table address
5355 * @adapter: board private structure
5356 *
5357 * The unicast table address is a register array of 32-bit registers.
5358 * The table is meant to be used in a way similar to how the MTA is used
5359 * however due to certain limitations in the hardware it is necessary to
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005360 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
5361 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
Alexander Duyck68d480c2009-10-05 06:33:08 +00005362 **/
5363static void igb_set_uta(struct igb_adapter *adapter)
5364{
5365 struct e1000_hw *hw = &adapter->hw;
5366 int i;
5367
5368 /* The UTA table only exists on 82576 hardware and newer */
5369 if (hw->mac.type < e1000_82576)
5370 return;
5371
5372 /* we only need to do this if VMDq is enabled */
5373 if (!adapter->vfs_allocated_count)
5374 return;
5375
5376 for (i = 0; i < hw->mac.uta_reg_count; i++)
5377 array_wr32(E1000_UTA, i, ~0);
5378}
5379
5380/**
Auke Kok9d5c8242008-01-24 02:22:38 -08005381 * igb_intr_msi - Interrupt Handler
5382 * @irq: interrupt number
5383 * @data: pointer to a network interface device structure
5384 **/
5385static irqreturn_t igb_intr_msi(int irq, void *data)
5386{
Alexander Duyck047e0032009-10-27 15:49:27 +00005387 struct igb_adapter *adapter = data;
5388 struct igb_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9d5c8242008-01-24 02:22:38 -08005389 struct e1000_hw *hw = &adapter->hw;
5390 /* read ICR disables interrupts using IAM */
5391 u32 icr = rd32(E1000_ICR);
5392
Alexander Duyck047e0032009-10-27 15:49:27 +00005393 igb_write_itr(q_vector);
Auke Kok9d5c8242008-01-24 02:22:38 -08005394
Alexander Duyck7f081d42010-01-07 17:41:00 +00005395 if (icr & E1000_ICR_DRSTA)
5396 schedule_work(&adapter->reset_task);
5397
Alexander Duyck047e0032009-10-27 15:49:27 +00005398 if (icr & E1000_ICR_DOUTSYNC) {
Alexander Duyckdda0e082009-02-06 23:19:08 +00005399 /* HW is reporting DMA is out of sync */
5400 adapter->stats.doosync++;
5401 }
5402
Auke Kok9d5c8242008-01-24 02:22:38 -08005403 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
5404 hw->mac.get_link_status = 1;
5405 if (!test_bit(__IGB_DOWN, &adapter->state))
5406 mod_timer(&adapter->watchdog_timer, jiffies + 1);
5407 }
5408
Alexander Duyck047e0032009-10-27 15:49:27 +00005409 napi_schedule(&q_vector->napi);
Auke Kok9d5c8242008-01-24 02:22:38 -08005410
5411 return IRQ_HANDLED;
5412}
5413
5414/**
Alexander Duyck4a3c6432009-02-06 23:20:49 +00005415 * igb_intr - Legacy Interrupt Handler
Auke Kok9d5c8242008-01-24 02:22:38 -08005416 * @irq: interrupt number
5417 * @data: pointer to a network interface device structure
5418 **/
5419static irqreturn_t igb_intr(int irq, void *data)
5420{
Alexander Duyck047e0032009-10-27 15:49:27 +00005421 struct igb_adapter *adapter = data;
5422 struct igb_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9d5c8242008-01-24 02:22:38 -08005423 struct e1000_hw *hw = &adapter->hw;
5424 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
5425 * need for the IMC write */
5426 u32 icr = rd32(E1000_ICR);
Auke Kok9d5c8242008-01-24 02:22:38 -08005427 if (!icr)
5428 return IRQ_NONE; /* Not our interrupt */
5429
Alexander Duyck047e0032009-10-27 15:49:27 +00005430 igb_write_itr(q_vector);
Auke Kok9d5c8242008-01-24 02:22:38 -08005431
5432 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
5433 * not set, then the adapter didn't send an interrupt */
5434 if (!(icr & E1000_ICR_INT_ASSERTED))
5435 return IRQ_NONE;
5436
Alexander Duyck7f081d42010-01-07 17:41:00 +00005437 if (icr & E1000_ICR_DRSTA)
5438 schedule_work(&adapter->reset_task);
5439
Alexander Duyck047e0032009-10-27 15:49:27 +00005440 if (icr & E1000_ICR_DOUTSYNC) {
Alexander Duyckdda0e082009-02-06 23:19:08 +00005441 /* HW is reporting DMA is out of sync */
5442 adapter->stats.doosync++;
5443 }
5444
Auke Kok9d5c8242008-01-24 02:22:38 -08005445 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
5446 hw->mac.get_link_status = 1;
5447 /* guard against interrupt when we're going down */
5448 if (!test_bit(__IGB_DOWN, &adapter->state))
5449 mod_timer(&adapter->watchdog_timer, jiffies + 1);
5450 }
5451
Alexander Duyck047e0032009-10-27 15:49:27 +00005452 napi_schedule(&q_vector->napi);
Auke Kok9d5c8242008-01-24 02:22:38 -08005453
5454 return IRQ_HANDLED;
5455}
5456
Alexander Duyck047e0032009-10-27 15:49:27 +00005457static inline void igb_ring_irq_enable(struct igb_q_vector *q_vector)
Alexander Duyck46544252009-02-19 20:39:04 -08005458{
Alexander Duyck047e0032009-10-27 15:49:27 +00005459 struct igb_adapter *adapter = q_vector->adapter;
Alexander Duyck46544252009-02-19 20:39:04 -08005460 struct e1000_hw *hw = &adapter->hw;
5461
Alexander Duyck4fc82ad2009-10-27 23:45:42 +00005462 if ((q_vector->rx_ring && (adapter->rx_itr_setting & 3)) ||
5463 (!q_vector->rx_ring && (adapter->tx_itr_setting & 3))) {
Alexander Duyck047e0032009-10-27 15:49:27 +00005464 if (!adapter->msix_entries)
Alexander Duyck46544252009-02-19 20:39:04 -08005465 igb_set_itr(adapter);
5466 else
Alexander Duyck047e0032009-10-27 15:49:27 +00005467 igb_update_ring_itr(q_vector);
Alexander Duyck46544252009-02-19 20:39:04 -08005468 }
5469
5470 if (!test_bit(__IGB_DOWN, &adapter->state)) {
5471 if (adapter->msix_entries)
Alexander Duyck047e0032009-10-27 15:49:27 +00005472 wr32(E1000_EIMS, q_vector->eims_value);
Alexander Duyck46544252009-02-19 20:39:04 -08005473 else
5474 igb_irq_enable(adapter);
5475 }
5476}
5477
Auke Kok9d5c8242008-01-24 02:22:38 -08005478/**
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07005479 * igb_poll - NAPI Rx polling callback
5480 * @napi: napi polling structure
5481 * @budget: count of how many packets we should handle
Auke Kok9d5c8242008-01-24 02:22:38 -08005482 **/
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07005483static int igb_poll(struct napi_struct *napi, int budget)
Auke Kok9d5c8242008-01-24 02:22:38 -08005484{
Alexander Duyck047e0032009-10-27 15:49:27 +00005485 struct igb_q_vector *q_vector = container_of(napi,
5486 struct igb_q_vector,
5487 napi);
5488 int tx_clean_complete = 1, work_done = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08005489
Jeff Kirsher421e02f2008-10-17 11:08:31 -07005490#ifdef CONFIG_IGB_DCA
Alexander Duyck047e0032009-10-27 15:49:27 +00005491 if (q_vector->adapter->flags & IGB_FLAG_DCA_ENABLED)
5492 igb_update_dca(q_vector);
Jeb Cramerfe4506b2008-07-08 15:07:55 -07005493#endif
Alexander Duyck047e0032009-10-27 15:49:27 +00005494 if (q_vector->tx_ring)
5495 tx_clean_complete = igb_clean_tx_irq(q_vector);
Auke Kok9d5c8242008-01-24 02:22:38 -08005496
Alexander Duyck047e0032009-10-27 15:49:27 +00005497 if (q_vector->rx_ring)
5498 igb_clean_rx_irq_adv(q_vector, &work_done, budget);
5499
5500 if (!tx_clean_complete)
5501 work_done = budget;
Auke Kok9d5c8242008-01-24 02:22:38 -08005502
Alexander Duyck46544252009-02-19 20:39:04 -08005503 /* If not enough Rx work done, exit the polling mode */
Alexander Duyck5e6d5b12009-03-13 20:40:38 +00005504 if (work_done < budget) {
Alexander Duyck46544252009-02-19 20:39:04 -08005505 napi_complete(napi);
Alexander Duyck047e0032009-10-27 15:49:27 +00005506 igb_ring_irq_enable(q_vector);
Alexander Duyck46544252009-02-19 20:39:04 -08005507 }
5508
5509 return work_done;
Auke Kok9d5c8242008-01-24 02:22:38 -08005510}
Al Viro6d8126f2008-03-16 22:23:24 +00005511
Auke Kok9d5c8242008-01-24 02:22:38 -08005512/**
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00005513 * igb_systim_to_hwtstamp - convert system time value to hw timestamp
Patrick Ohly33af6bc2009-02-12 05:03:43 +00005514 * @adapter: board private structure
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00005515 * @shhwtstamps: timestamp structure to update
5516 * @regval: unsigned 64bit system time value.
5517 *
5518 * We need to convert the system time value stored in the RX/TXSTMP registers
5519 * into a hwtstamp which can be used by the upper level timestamping functions
5520 */
5521static void igb_systim_to_hwtstamp(struct igb_adapter *adapter,
5522 struct skb_shared_hwtstamps *shhwtstamps,
5523 u64 regval)
5524{
5525 u64 ns;
5526
Alexander Duyck55cac242009-11-19 12:42:21 +00005527 /*
5528 * The 82580 starts with 1ns at bit 0 in RX/TXSTMPL, shift this up to
5529 * 24 to match clock shift we setup earlier.
5530 */
5531 if (adapter->hw.mac.type == e1000_82580)
5532 regval <<= IGB_82580_TSYNC_SHIFT;
5533
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00005534 ns = timecounter_cyc2time(&adapter->clock, regval);
5535 timecompare_update(&adapter->compare, ns);
5536 memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps));
5537 shhwtstamps->hwtstamp = ns_to_ktime(ns);
5538 shhwtstamps->syststamp = timecompare_transform(&adapter->compare, ns);
5539}
5540
5541/**
5542 * igb_tx_hwtstamp - utility function which checks for TX time stamp
5543 * @q_vector: pointer to q_vector containing needed info
Nick Nunley28739572010-05-04 21:58:07 +00005544 * @buffer: pointer to igb_buffer structure
Patrick Ohly33af6bc2009-02-12 05:03:43 +00005545 *
5546 * If we were asked to do hardware stamping and such a time stamp is
5547 * available, then it must have been for this skb here because we only
5548 * allow only one such packet into the queue.
5549 */
Nick Nunley28739572010-05-04 21:58:07 +00005550static void igb_tx_hwtstamp(struct igb_q_vector *q_vector, struct igb_buffer *buffer_info)
Patrick Ohly33af6bc2009-02-12 05:03:43 +00005551{
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00005552 struct igb_adapter *adapter = q_vector->adapter;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00005553 struct e1000_hw *hw = &adapter->hw;
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00005554 struct skb_shared_hwtstamps shhwtstamps;
5555 u64 regval;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00005556
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00005557 /* if skb does not support hw timestamp or TX stamp not valid exit */
Oliver Hartkopp2244d072010-08-17 08:59:14 +00005558 if (likely(!(buffer_info->tx_flags & SKBTX_HW_TSTAMP)) ||
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00005559 !(rd32(E1000_TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID))
5560 return;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00005561
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00005562 regval = rd32(E1000_TXSTMPL);
5563 regval |= (u64)rd32(E1000_TXSTMPH) << 32;
5564
5565 igb_systim_to_hwtstamp(adapter, &shhwtstamps, regval);
Nick Nunley28739572010-05-04 21:58:07 +00005566 skb_tstamp_tx(buffer_info->skb, &shhwtstamps);
Patrick Ohly33af6bc2009-02-12 05:03:43 +00005567}
5568
5569/**
Auke Kok9d5c8242008-01-24 02:22:38 -08005570 * igb_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyck047e0032009-10-27 15:49:27 +00005571 * @q_vector: pointer to q_vector containing needed info
Auke Kok9d5c8242008-01-24 02:22:38 -08005572 * returns true if ring is completely cleaned
5573 **/
Alexander Duyck047e0032009-10-27 15:49:27 +00005574static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)
Auke Kok9d5c8242008-01-24 02:22:38 -08005575{
Alexander Duyck047e0032009-10-27 15:49:27 +00005576 struct igb_adapter *adapter = q_vector->adapter;
5577 struct igb_ring *tx_ring = q_vector->tx_ring;
Alexander Duycke694e962009-10-27 15:53:06 +00005578 struct net_device *netdev = tx_ring->netdev;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08005579 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08005580 struct igb_buffer *buffer_info;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08005581 union e1000_adv_tx_desc *tx_desc, *eop_desc;
Auke Kok9d5c8242008-01-24 02:22:38 -08005582 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08005583 unsigned int i, eop, count = 0;
5584 bool cleaned = false;
Auke Kok9d5c8242008-01-24 02:22:38 -08005585
Auke Kok9d5c8242008-01-24 02:22:38 -08005586 i = tx_ring->next_to_clean;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08005587 eop = tx_ring->buffer_info[i].next_to_watch;
5588 eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop);
5589
5590 while ((eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)) &&
5591 (count < tx_ring->count)) {
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00005592 rmb(); /* read buffer_info after eop_desc status */
Alexander Duyck0e014cb2008-12-26 01:33:18 -08005593 for (cleaned = false; !cleaned; count++) {
5594 tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
Auke Kok9d5c8242008-01-24 02:22:38 -08005595 buffer_info = &tx_ring->buffer_info[i];
Alexander Duyck0e014cb2008-12-26 01:33:18 -08005596 cleaned = (i == eop);
Auke Kok9d5c8242008-01-24 02:22:38 -08005597
Nick Nunley28739572010-05-04 21:58:07 +00005598 if (buffer_info->skb) {
5599 total_bytes += buffer_info->bytecount;
Auke Kok9d5c8242008-01-24 02:22:38 -08005600 /* gso_segs is currently only valid for tcp */
Nick Nunley28739572010-05-04 21:58:07 +00005601 total_packets += buffer_info->gso_segs;
5602 igb_tx_hwtstamp(q_vector, buffer_info);
Auke Kok9d5c8242008-01-24 02:22:38 -08005603 }
5604
Alexander Duyck80785292009-10-27 15:51:47 +00005605 igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
Alexander Duyck0e014cb2008-12-26 01:33:18 -08005606 tx_desc->wb.status = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08005607
5608 i++;
5609 if (i == tx_ring->count)
5610 i = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08005611 }
Alexander Duyck0e014cb2008-12-26 01:33:18 -08005612 eop = tx_ring->buffer_info[i].next_to_watch;
5613 eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop);
5614 }
5615
Auke Kok9d5c8242008-01-24 02:22:38 -08005616 tx_ring->next_to_clean = i;
5617
Alexander Duyckfc7d3452008-08-26 04:25:08 -07005618 if (unlikely(count &&
Auke Kok9d5c8242008-01-24 02:22:38 -08005619 netif_carrier_ok(netdev) &&
Alexander Duyckc493ea42009-03-20 00:16:50 +00005620 igb_desc_unused(tx_ring) >= IGB_TX_QUEUE_WAKE)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08005621 /* Make sure that anybody stopping the queue after this
5622 * sees the new next_to_clean.
5623 */
5624 smp_mb();
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07005625 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
5626 !(test_bit(__IGB_DOWN, &adapter->state))) {
5627 netif_wake_subqueue(netdev, tx_ring->queue_index);
Eric Dumazet12dcd862010-10-15 17:27:10 +00005628
5629 u64_stats_update_begin(&tx_ring->tx_syncp);
Alexander Duyck04a5fcaa2009-10-27 15:52:27 +00005630 tx_ring->tx_stats.restart_queue++;
Eric Dumazet12dcd862010-10-15 17:27:10 +00005631 u64_stats_update_end(&tx_ring->tx_syncp);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07005632 }
Auke Kok9d5c8242008-01-24 02:22:38 -08005633 }
5634
5635 if (tx_ring->detect_tx_hung) {
5636 /* Detect a transmit hang in hardware, this serializes the
5637 * check with the clearing of time_stamp and movement of i */
5638 tx_ring->detect_tx_hung = false;
5639 if (tx_ring->buffer_info[i].time_stamp &&
5640 time_after(jiffies, tx_ring->buffer_info[i].time_stamp +
Joe Perches8e95a202009-12-03 07:58:21 +00005641 (adapter->tx_timeout_factor * HZ)) &&
5642 !(rd32(E1000_STATUS) & E1000_STATUS_TXOFF)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08005643
Auke Kok9d5c8242008-01-24 02:22:38 -08005644 /* detected Tx unit hang */
Alexander Duyck59d71982010-04-27 13:09:25 +00005645 dev_err(tx_ring->dev,
Auke Kok9d5c8242008-01-24 02:22:38 -08005646 "Detected Tx Unit Hang\n"
Alexander Duyck2d064c02008-07-08 15:10:12 -07005647 " Tx Queue <%d>\n"
Auke Kok9d5c8242008-01-24 02:22:38 -08005648 " TDH <%x>\n"
5649 " TDT <%x>\n"
5650 " next_to_use <%x>\n"
5651 " next_to_clean <%x>\n"
Auke Kok9d5c8242008-01-24 02:22:38 -08005652 "buffer_info[next_to_clean]\n"
5653 " time_stamp <%lx>\n"
Alexander Duyck0e014cb2008-12-26 01:33:18 -08005654 " next_to_watch <%x>\n"
Auke Kok9d5c8242008-01-24 02:22:38 -08005655 " jiffies <%lx>\n"
5656 " desc.status <%x>\n",
Alexander Duyck2d064c02008-07-08 15:10:12 -07005657 tx_ring->queue_index,
Alexander Duyckfce99e32009-10-27 15:51:27 +00005658 readl(tx_ring->head),
5659 readl(tx_ring->tail),
Auke Kok9d5c8242008-01-24 02:22:38 -08005660 tx_ring->next_to_use,
5661 tx_ring->next_to_clean,
Alexander Duyckf7ba2052009-10-27 23:48:51 +00005662 tx_ring->buffer_info[eop].time_stamp,
Alexander Duyck0e014cb2008-12-26 01:33:18 -08005663 eop,
Auke Kok9d5c8242008-01-24 02:22:38 -08005664 jiffies,
Alexander Duyck0e014cb2008-12-26 01:33:18 -08005665 eop_desc->wb.status);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07005666 netif_stop_subqueue(netdev, tx_ring->queue_index);
Auke Kok9d5c8242008-01-24 02:22:38 -08005667 }
5668 }
5669 tx_ring->total_bytes += total_bytes;
5670 tx_ring->total_packets += total_packets;
Eric Dumazet12dcd862010-10-15 17:27:10 +00005671 u64_stats_update_begin(&tx_ring->tx_syncp);
Alexander Duycke21ed352008-07-08 15:07:24 -07005672 tx_ring->tx_stats.bytes += total_bytes;
5673 tx_ring->tx_stats.packets += total_packets;
Eric Dumazet12dcd862010-10-15 17:27:10 +00005674 u64_stats_update_end(&tx_ring->tx_syncp);
Eric Dumazet807540b2010-09-23 05:40:09 +00005675 return count < tx_ring->count;
Auke Kok9d5c8242008-01-24 02:22:38 -08005676}
5677
Auke Kok9d5c8242008-01-24 02:22:38 -08005678/**
5679 * igb_receive_skb - helper function to handle rx indications
Alexander Duyck047e0032009-10-27 15:49:27 +00005680 * @q_vector: structure containing interrupt and ring information
5681 * @skb: packet to send up
5682 * @vlan_tag: vlan tag for packet
Auke Kok9d5c8242008-01-24 02:22:38 -08005683 **/
Alexander Duyck047e0032009-10-27 15:49:27 +00005684static void igb_receive_skb(struct igb_q_vector *q_vector,
5685 struct sk_buff *skb,
5686 u16 vlan_tag)
Auke Kok9d5c8242008-01-24 02:22:38 -08005687{
Alexander Duyck047e0032009-10-27 15:49:27 +00005688 struct igb_adapter *adapter = q_vector->adapter;
Alexander Duyckd3352522008-07-08 15:12:13 -07005689
Alexander Duyck31b24b92010-03-23 18:35:18 +00005690 if (vlan_tag && adapter->vlgrp)
Alexander Duyck047e0032009-10-27 15:49:27 +00005691 vlan_gro_receive(&q_vector->napi, adapter->vlgrp,
5692 vlan_tag, skb);
Alexander Duyck182ff8d2009-04-27 22:35:33 +00005693 else
Alexander Duyck047e0032009-10-27 15:49:27 +00005694 napi_gro_receive(&q_vector->napi, skb);
Auke Kok9d5c8242008-01-24 02:22:38 -08005695}
5696
Alexander Duyck04a5fcaa2009-10-27 15:52:27 +00005697static inline void igb_rx_checksum_adv(struct igb_ring *ring,
Auke Kok9d5c8242008-01-24 02:22:38 -08005698 u32 status_err, struct sk_buff *skb)
5699{
Eric Dumazetbc8acf22010-09-02 13:07:41 -07005700 skb_checksum_none_assert(skb);
Auke Kok9d5c8242008-01-24 02:22:38 -08005701
5702 /* Ignore Checksum bit is set or checksum is disabled through ethtool */
Alexander Duyck85ad76b2009-10-27 15:52:46 +00005703 if (!(ring->flags & IGB_RING_FLAG_RX_CSUM) ||
5704 (status_err & E1000_RXD_STAT_IXSM))
Auke Kok9d5c8242008-01-24 02:22:38 -08005705 return;
Alexander Duyck85ad76b2009-10-27 15:52:46 +00005706
Auke Kok9d5c8242008-01-24 02:22:38 -08005707 /* TCP/UDP checksum error bit is set */
5708 if (status_err &
5709 (E1000_RXDEXT_STATERR_TCPE | E1000_RXDEXT_STATERR_IPE)) {
Jesse Brandeburgb9473562009-04-27 22:36:13 +00005710 /*
5711 * work around errata with sctp packets where the TCPE aka
5712 * L4E bit is set incorrectly on 64 byte (60 byte w/o crc)
5713 * packets, (aka let the stack check the crc32c)
5714 */
Alexander Duyck85ad76b2009-10-27 15:52:46 +00005715 if ((skb->len == 60) &&
Eric Dumazet12dcd862010-10-15 17:27:10 +00005716 (ring->flags & IGB_RING_FLAG_RX_SCTP_CSUM)) {
5717 u64_stats_update_begin(&ring->rx_syncp);
Alexander Duyck04a5fcaa2009-10-27 15:52:27 +00005718 ring->rx_stats.csum_err++;
Eric Dumazet12dcd862010-10-15 17:27:10 +00005719 u64_stats_update_end(&ring->rx_syncp);
5720 }
Auke Kok9d5c8242008-01-24 02:22:38 -08005721 /* let the stack verify checksum errors */
Auke Kok9d5c8242008-01-24 02:22:38 -08005722 return;
5723 }
5724 /* It must be a TCP or UDP packet with a valid checksum */
5725 if (status_err & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))
5726 skb->ip_summed = CHECKSUM_UNNECESSARY;
5727
Alexander Duyck59d71982010-04-27 13:09:25 +00005728 dev_dbg(ring->dev, "cksum success: bits %08X\n", status_err);
Auke Kok9d5c8242008-01-24 02:22:38 -08005729}
5730
Nick Nunley757b77e2010-03-26 11:36:47 +00005731static void igb_rx_hwtstamp(struct igb_q_vector *q_vector, u32 staterr,
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00005732 struct sk_buff *skb)
5733{
5734 struct igb_adapter *adapter = q_vector->adapter;
5735 struct e1000_hw *hw = &adapter->hw;
5736 u64 regval;
5737
5738 /*
5739 * If this bit is set, then the RX registers contain the time stamp. No
5740 * other packet will be time stamped until we read these registers, so
5741 * read the registers to make them available again. Because only one
5742 * packet can be time stamped at a time, we know that the register
5743 * values must belong to this one here and therefore we don't need to
5744 * compare any of the additional attributes stored for it.
5745 *
Oliver Hartkopp2244d072010-08-17 08:59:14 +00005746 * If nothing went wrong, then it should have a shared tx_flags that we
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00005747 * can turn into a skb_shared_hwtstamps.
5748 */
Nick Nunley757b77e2010-03-26 11:36:47 +00005749 if (staterr & E1000_RXDADV_STAT_TSIP) {
5750 u32 *stamp = (u32 *)skb->data;
5751 regval = le32_to_cpu(*(stamp + 2));
5752 regval |= (u64)le32_to_cpu(*(stamp + 3)) << 32;
5753 skb_pull(skb, IGB_TS_HDR_LEN);
5754 } else {
5755 if(!(rd32(E1000_TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
5756 return;
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00005757
Nick Nunley757b77e2010-03-26 11:36:47 +00005758 regval = rd32(E1000_RXSTMPL);
5759 regval |= (u64)rd32(E1000_RXSTMPH) << 32;
5760 }
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00005761
5762 igb_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), regval);
5763}
Alexander Duyck4c844852009-10-27 15:52:07 +00005764static inline u16 igb_get_hlen(struct igb_ring *rx_ring,
Alexander Duyck2d94d8a2009-07-23 18:10:06 +00005765 union e1000_adv_rx_desc *rx_desc)
5766{
5767 /* HW will not DMA in data larger than the given buffer, even if it
5768 * parses the (NFS, of course) header to be larger. In that case, it
5769 * fills the header buffer and spills the rest into the page.
5770 */
5771 u16 hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) &
5772 E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT;
Alexander Duyck4c844852009-10-27 15:52:07 +00005773 if (hlen > rx_ring->rx_buffer_len)
5774 hlen = rx_ring->rx_buffer_len;
Alexander Duyck2d94d8a2009-07-23 18:10:06 +00005775 return hlen;
5776}
5777
Alexander Duyck047e0032009-10-27 15:49:27 +00005778static bool igb_clean_rx_irq_adv(struct igb_q_vector *q_vector,
5779 int *work_done, int budget)
Auke Kok9d5c8242008-01-24 02:22:38 -08005780{
Alexander Duyck047e0032009-10-27 15:49:27 +00005781 struct igb_ring *rx_ring = q_vector->rx_ring;
Alexander Duycke694e962009-10-27 15:53:06 +00005782 struct net_device *netdev = rx_ring->netdev;
Alexander Duyck59d71982010-04-27 13:09:25 +00005783 struct device *dev = rx_ring->dev;
Auke Kok9d5c8242008-01-24 02:22:38 -08005784 union e1000_adv_rx_desc *rx_desc , *next_rxd;
5785 struct igb_buffer *buffer_info , *next_buffer;
5786 struct sk_buff *skb;
Auke Kok9d5c8242008-01-24 02:22:38 -08005787 bool cleaned = false;
5788 int cleaned_count = 0;
Alexander Duyckd1eff352009-11-12 18:38:35 +00005789 int current_node = numa_node_id();
Auke Kok9d5c8242008-01-24 02:22:38 -08005790 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck73cd78f2009-02-12 18:16:59 +00005791 unsigned int i;
Alexander Duyck2d94d8a2009-07-23 18:10:06 +00005792 u32 staterr;
5793 u16 length;
Alexander Duyck047e0032009-10-27 15:49:27 +00005794 u16 vlan_tag;
Auke Kok9d5c8242008-01-24 02:22:38 -08005795
5796 i = rx_ring->next_to_clean;
Alexander Duyck69d3ca52009-02-06 23:15:04 +00005797 buffer_info = &rx_ring->buffer_info[i];
Auke Kok9d5c8242008-01-24 02:22:38 -08005798 rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
5799 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
5800
5801 while (staterr & E1000_RXD_STAT_DD) {
5802 if (*work_done >= budget)
5803 break;
5804 (*work_done)++;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +00005805 rmb(); /* read descriptor and rx_buffer_info after status DD */
Alexander Duyck69d3ca52009-02-06 23:15:04 +00005806
5807 skb = buffer_info->skb;
5808 prefetch(skb->data - NET_IP_ALIGN);
5809 buffer_info->skb = NULL;
5810
5811 i++;
5812 if (i == rx_ring->count)
5813 i = 0;
Alexander Duyck42d07812009-10-27 23:51:16 +00005814
Alexander Duyck69d3ca52009-02-06 23:15:04 +00005815 next_rxd = E1000_RX_DESC_ADV(*rx_ring, i);
5816 prefetch(next_rxd);
5817 next_buffer = &rx_ring->buffer_info[i];
5818
5819 length = le16_to_cpu(rx_desc->wb.upper.length);
5820 cleaned = true;
5821 cleaned_count++;
5822
Alexander Duyck6ec43fe2009-10-27 15:50:48 +00005823 if (buffer_info->dma) {
Alexander Duyck59d71982010-04-27 13:09:25 +00005824 dma_unmap_single(dev, buffer_info->dma,
Alexander Duyck4c844852009-10-27 15:52:07 +00005825 rx_ring->rx_buffer_len,
Alexander Duyck59d71982010-04-27 13:09:25 +00005826 DMA_FROM_DEVICE);
Jesse Brandeburg91615f72009-06-30 12:45:15 +00005827 buffer_info->dma = 0;
Alexander Duyck4c844852009-10-27 15:52:07 +00005828 if (rx_ring->rx_buffer_len >= IGB_RXBUFFER_1024) {
Alexander Duyck6ec43fe2009-10-27 15:50:48 +00005829 skb_put(skb, length);
5830 goto send_up;
5831 }
Alexander Duyck4c844852009-10-27 15:52:07 +00005832 skb_put(skb, igb_get_hlen(rx_ring, rx_desc));
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07005833 }
5834
5835 if (length) {
Alexander Duyck59d71982010-04-27 13:09:25 +00005836 dma_unmap_page(dev, buffer_info->page_dma,
5837 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Auke Kok9d5c8242008-01-24 02:22:38 -08005838 buffer_info->page_dma = 0;
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07005839
Koki Sanagiaa913402010-04-27 01:01:19 +00005840 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07005841 buffer_info->page,
5842 buffer_info->page_offset,
5843 length);
5844
Alexander Duyckd1eff352009-11-12 18:38:35 +00005845 if ((page_count(buffer_info->page) != 1) ||
5846 (page_to_nid(buffer_info->page) != current_node))
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07005847 buffer_info->page = NULL;
5848 else
5849 get_page(buffer_info->page);
Auke Kok9d5c8242008-01-24 02:22:38 -08005850
5851 skb->len += length;
5852 skb->data_len += length;
5853 skb->truesize += length;
Auke Kok9d5c8242008-01-24 02:22:38 -08005854 }
Auke Kok9d5c8242008-01-24 02:22:38 -08005855
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07005856 if (!(staterr & E1000_RXD_STAT_EOP)) {
Alexander Duyckb2d56532008-11-20 00:47:34 -08005857 buffer_info->skb = next_buffer->skb;
5858 buffer_info->dma = next_buffer->dma;
5859 next_buffer->skb = skb;
5860 next_buffer->dma = 0;
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07005861 goto next_desc;
5862 }
Alexander Duyck69d3ca52009-02-06 23:15:04 +00005863send_up:
Auke Kok9d5c8242008-01-24 02:22:38 -08005864 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
5865 dev_kfree_skb_irq(skb);
5866 goto next_desc;
5867 }
Auke Kok9d5c8242008-01-24 02:22:38 -08005868
Nick Nunley757b77e2010-03-26 11:36:47 +00005869 if (staterr & (E1000_RXDADV_STAT_TSIP | E1000_RXDADV_STAT_TS))
5870 igb_rx_hwtstamp(q_vector, staterr, skb);
Auke Kok9d5c8242008-01-24 02:22:38 -08005871 total_bytes += skb->len;
5872 total_packets++;
5873
Alexander Duyck85ad76b2009-10-27 15:52:46 +00005874 igb_rx_checksum_adv(rx_ring, staterr, skb);
Auke Kok9d5c8242008-01-24 02:22:38 -08005875
5876 skb->protocol = eth_type_trans(skb, netdev);
Alexander Duyck047e0032009-10-27 15:49:27 +00005877 skb_record_rx_queue(skb, rx_ring->queue_index);
Auke Kok9d5c8242008-01-24 02:22:38 -08005878
Alexander Duyck047e0032009-10-27 15:49:27 +00005879 vlan_tag = ((staterr & E1000_RXD_STAT_VP) ?
5880 le16_to_cpu(rx_desc->wb.upper.vlan) : 0);
5881
5882 igb_receive_skb(q_vector, skb, vlan_tag);
Auke Kok9d5c8242008-01-24 02:22:38 -08005883
Auke Kok9d5c8242008-01-24 02:22:38 -08005884next_desc:
5885 rx_desc->wb.upper.status_error = 0;
5886
5887 /* return some buffers to hardware, one at a time is too slow */
5888 if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
Mitch Williams3b644cf2008-06-27 10:59:48 -07005889 igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
Auke Kok9d5c8242008-01-24 02:22:38 -08005890 cleaned_count = 0;
5891 }
5892
5893 /* use prefetched values */
5894 rx_desc = next_rxd;
5895 buffer_info = next_buffer;
Auke Kok9d5c8242008-01-24 02:22:38 -08005896 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
5897 }
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07005898
Auke Kok9d5c8242008-01-24 02:22:38 -08005899 rx_ring->next_to_clean = i;
Alexander Duyckc493ea42009-03-20 00:16:50 +00005900 cleaned_count = igb_desc_unused(rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08005901
5902 if (cleaned_count)
Mitch Williams3b644cf2008-06-27 10:59:48 -07005903 igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
Auke Kok9d5c8242008-01-24 02:22:38 -08005904
5905 rx_ring->total_packets += total_packets;
5906 rx_ring->total_bytes += total_bytes;
Eric Dumazet12dcd862010-10-15 17:27:10 +00005907 u64_stats_update_begin(&rx_ring->rx_syncp);
Auke Kok9d5c8242008-01-24 02:22:38 -08005908 rx_ring->rx_stats.packets += total_packets;
5909 rx_ring->rx_stats.bytes += total_bytes;
Eric Dumazet12dcd862010-10-15 17:27:10 +00005910 u64_stats_update_end(&rx_ring->rx_syncp);
Auke Kok9d5c8242008-01-24 02:22:38 -08005911 return cleaned;
5912}
5913
Auke Kok9d5c8242008-01-24 02:22:38 -08005914/**
5915 * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split
5916 * @adapter: address of board private structure
5917 **/
Alexander Duyckd7ee5b32009-10-27 15:54:23 +00005918void igb_alloc_rx_buffers_adv(struct igb_ring *rx_ring, int cleaned_count)
Auke Kok9d5c8242008-01-24 02:22:38 -08005919{
Alexander Duycke694e962009-10-27 15:53:06 +00005920 struct net_device *netdev = rx_ring->netdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08005921 union e1000_adv_rx_desc *rx_desc;
5922 struct igb_buffer *buffer_info;
5923 struct sk_buff *skb;
5924 unsigned int i;
Alexander Duyckdb761762009-02-06 23:15:25 +00005925 int bufsz;
Auke Kok9d5c8242008-01-24 02:22:38 -08005926
5927 i = rx_ring->next_to_use;
5928 buffer_info = &rx_ring->buffer_info[i];
5929
Alexander Duyck4c844852009-10-27 15:52:07 +00005930 bufsz = rx_ring->rx_buffer_len;
Alexander Duyckdb761762009-02-06 23:15:25 +00005931
Auke Kok9d5c8242008-01-24 02:22:38 -08005932 while (cleaned_count--) {
5933 rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
5934
Alexander Duyck6ec43fe2009-10-27 15:50:48 +00005935 if ((bufsz < IGB_RXBUFFER_1024) && !buffer_info->page_dma) {
Auke Kok9d5c8242008-01-24 02:22:38 -08005936 if (!buffer_info->page) {
Alexander Duyck42d07812009-10-27 23:51:16 +00005937 buffer_info->page = netdev_alloc_page(netdev);
Eric Dumazet12dcd862010-10-15 17:27:10 +00005938 if (unlikely(!buffer_info->page)) {
5939 u64_stats_update_begin(&rx_ring->rx_syncp);
Alexander Duyck04a5fcaa2009-10-27 15:52:27 +00005940 rx_ring->rx_stats.alloc_failed++;
Eric Dumazet12dcd862010-10-15 17:27:10 +00005941 u64_stats_update_end(&rx_ring->rx_syncp);
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07005942 goto no_buffers;
5943 }
5944 buffer_info->page_offset = 0;
5945 } else {
5946 buffer_info->page_offset ^= PAGE_SIZE / 2;
Auke Kok9d5c8242008-01-24 02:22:38 -08005947 }
5948 buffer_info->page_dma =
Alexander Duyck59d71982010-04-27 13:09:25 +00005949 dma_map_page(rx_ring->dev, buffer_info->page,
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07005950 buffer_info->page_offset,
5951 PAGE_SIZE / 2,
Alexander Duyck59d71982010-04-27 13:09:25 +00005952 DMA_FROM_DEVICE);
5953 if (dma_mapping_error(rx_ring->dev,
5954 buffer_info->page_dma)) {
Alexander Duyck42d07812009-10-27 23:51:16 +00005955 buffer_info->page_dma = 0;
Eric Dumazet12dcd862010-10-15 17:27:10 +00005956 u64_stats_update_begin(&rx_ring->rx_syncp);
Alexander Duyck42d07812009-10-27 23:51:16 +00005957 rx_ring->rx_stats.alloc_failed++;
Eric Dumazet12dcd862010-10-15 17:27:10 +00005958 u64_stats_update_end(&rx_ring->rx_syncp);
Alexander Duyck42d07812009-10-27 23:51:16 +00005959 goto no_buffers;
5960 }
Auke Kok9d5c8242008-01-24 02:22:38 -08005961 }
5962
Alexander Duyck42d07812009-10-27 23:51:16 +00005963 skb = buffer_info->skb;
5964 if (!skb) {
Eric Dumazet89d71a62009-10-13 05:34:20 +00005965 skb = netdev_alloc_skb_ip_align(netdev, bufsz);
Eric Dumazet12dcd862010-10-15 17:27:10 +00005966 if (unlikely(!skb)) {
5967 u64_stats_update_begin(&rx_ring->rx_syncp);
Alexander Duyck04a5fcaa2009-10-27 15:52:27 +00005968 rx_ring->rx_stats.alloc_failed++;
Eric Dumazet12dcd862010-10-15 17:27:10 +00005969 u64_stats_update_end(&rx_ring->rx_syncp);
Auke Kok9d5c8242008-01-24 02:22:38 -08005970 goto no_buffers;
5971 }
5972
Auke Kok9d5c8242008-01-24 02:22:38 -08005973 buffer_info->skb = skb;
Alexander Duyck42d07812009-10-27 23:51:16 +00005974 }
5975 if (!buffer_info->dma) {
Alexander Duyck59d71982010-04-27 13:09:25 +00005976 buffer_info->dma = dma_map_single(rx_ring->dev,
Alexander Duyck80785292009-10-27 15:51:47 +00005977 skb->data,
Auke Kok9d5c8242008-01-24 02:22:38 -08005978 bufsz,
Alexander Duyck59d71982010-04-27 13:09:25 +00005979 DMA_FROM_DEVICE);
5980 if (dma_mapping_error(rx_ring->dev,
5981 buffer_info->dma)) {
Alexander Duyck42d07812009-10-27 23:51:16 +00005982 buffer_info->dma = 0;
Eric Dumazet12dcd862010-10-15 17:27:10 +00005983 u64_stats_update_begin(&rx_ring->rx_syncp);
Alexander Duyck42d07812009-10-27 23:51:16 +00005984 rx_ring->rx_stats.alloc_failed++;
Eric Dumazet12dcd862010-10-15 17:27:10 +00005985 u64_stats_update_end(&rx_ring->rx_syncp);
Alexander Duyck42d07812009-10-27 23:51:16 +00005986 goto no_buffers;
5987 }
Auke Kok9d5c8242008-01-24 02:22:38 -08005988 }
5989 /* Refresh the desc even if buffer_addrs didn't change because
5990 * each write-back erases this info. */
Alexander Duyck6ec43fe2009-10-27 15:50:48 +00005991 if (bufsz < IGB_RXBUFFER_1024) {
Auke Kok9d5c8242008-01-24 02:22:38 -08005992 rx_desc->read.pkt_addr =
5993 cpu_to_le64(buffer_info->page_dma);
5994 rx_desc->read.hdr_addr = cpu_to_le64(buffer_info->dma);
5995 } else {
Alexander Duyck42d07812009-10-27 23:51:16 +00005996 rx_desc->read.pkt_addr = cpu_to_le64(buffer_info->dma);
Auke Kok9d5c8242008-01-24 02:22:38 -08005997 rx_desc->read.hdr_addr = 0;
5998 }
5999
6000 i++;
6001 if (i == rx_ring->count)
6002 i = 0;
6003 buffer_info = &rx_ring->buffer_info[i];
6004 }
6005
6006no_buffers:
6007 if (rx_ring->next_to_use != i) {
6008 rx_ring->next_to_use = i;
6009 if (i == 0)
6010 i = (rx_ring->count - 1);
6011 else
6012 i--;
6013
6014 /* Force memory writes to complete before letting h/w
6015 * know there are new descriptors to fetch. (Only
6016 * applicable for weak-ordered memory model archs,
6017 * such as IA-64). */
6018 wmb();
Alexander Duyckfce99e32009-10-27 15:51:27 +00006019 writel(i, rx_ring->tail);
Auke Kok9d5c8242008-01-24 02:22:38 -08006020 }
6021}
6022
6023/**
6024 * igb_mii_ioctl -
6025 * @netdev:
6026 * @ifreq:
6027 * @cmd:
6028 **/
6029static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
6030{
6031 struct igb_adapter *adapter = netdev_priv(netdev);
6032 struct mii_ioctl_data *data = if_mii(ifr);
6033
6034 if (adapter->hw.phy.media_type != e1000_media_type_copper)
6035 return -EOPNOTSUPP;
6036
6037 switch (cmd) {
6038 case SIOCGMIIPHY:
6039 data->phy_id = adapter->hw.phy.addr;
6040 break;
6041 case SIOCGMIIREG:
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08006042 if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
6043 &data->val_out))
Auke Kok9d5c8242008-01-24 02:22:38 -08006044 return -EIO;
6045 break;
6046 case SIOCSMIIREG:
6047 default:
6048 return -EOPNOTSUPP;
6049 }
6050 return 0;
6051}
6052
6053/**
Patrick Ohlyc6cb0902009-02-12 05:03:42 +00006054 * igb_hwtstamp_ioctl - control hardware time stamping
6055 * @netdev:
6056 * @ifreq:
6057 * @cmd:
6058 *
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006059 * Outgoing time stamping can be enabled and disabled. Play nice and
6060 * disable it when requested, although it shouldn't case any overhead
6061 * when no packet needs it. At most one packet in the queue may be
6062 * marked for time stamping, otherwise it would be impossible to tell
6063 * for sure to which packet the hardware time stamp belongs.
6064 *
6065 * Incoming time stamping has to be configured via the hardware
6066 * filters. Not all combinations are supported, in particular event
6067 * type has to be specified. Matching the kind of event packet is
6068 * not supported, with the exception of "all V2 events regardless of
6069 * level 2 or 4".
6070 *
Patrick Ohlyc6cb0902009-02-12 05:03:42 +00006071 **/
6072static int igb_hwtstamp_ioctl(struct net_device *netdev,
6073 struct ifreq *ifr, int cmd)
6074{
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006075 struct igb_adapter *adapter = netdev_priv(netdev);
6076 struct e1000_hw *hw = &adapter->hw;
Patrick Ohlyc6cb0902009-02-12 05:03:42 +00006077 struct hwtstamp_config config;
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006078 u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
6079 u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006080 u32 tsync_rx_cfg = 0;
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006081 bool is_l4 = false;
6082 bool is_l2 = false;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006083 u32 regval;
Patrick Ohlyc6cb0902009-02-12 05:03:42 +00006084
6085 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
6086 return -EFAULT;
6087
6088 /* reserved for future extensions */
6089 if (config.flags)
6090 return -EINVAL;
6091
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006092 switch (config.tx_type) {
6093 case HWTSTAMP_TX_OFF:
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006094 tsync_tx_ctl = 0;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006095 case HWTSTAMP_TX_ON:
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006096 break;
6097 default:
6098 return -ERANGE;
6099 }
Patrick Ohlyc6cb0902009-02-12 05:03:42 +00006100
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006101 switch (config.rx_filter) {
6102 case HWTSTAMP_FILTER_NONE:
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006103 tsync_rx_ctl = 0;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006104 break;
6105 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
6106 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
6107 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
6108 case HWTSTAMP_FILTER_ALL:
6109 /*
6110 * register TSYNCRXCFG must be set, therefore it is not
6111 * possible to time stamp both Sync and Delay_Req messages
6112 * => fall back to time stamping all packets
6113 */
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006114 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006115 config.rx_filter = HWTSTAMP_FILTER_ALL;
6116 break;
6117 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006118 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006119 tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE;
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006120 is_l4 = true;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006121 break;
6122 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006123 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006124 tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE;
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006125 is_l4 = true;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006126 break;
6127 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
6128 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006129 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006130 tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE;
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006131 is_l2 = true;
6132 is_l4 = true;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006133 config.rx_filter = HWTSTAMP_FILTER_SOME;
6134 break;
6135 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
6136 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006137 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006138 tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE;
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006139 is_l2 = true;
6140 is_l4 = true;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006141 config.rx_filter = HWTSTAMP_FILTER_SOME;
6142 break;
6143 case HWTSTAMP_FILTER_PTP_V2_EVENT:
6144 case HWTSTAMP_FILTER_PTP_V2_SYNC:
6145 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006146 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006147 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006148 is_l2 = true;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006149 break;
6150 default:
6151 return -ERANGE;
6152 }
6153
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006154 if (hw->mac.type == e1000_82575) {
6155 if (tsync_rx_ctl | tsync_tx_ctl)
6156 return -EINVAL;
6157 return 0;
6158 }
6159
Nick Nunley757b77e2010-03-26 11:36:47 +00006160 /*
6161 * Per-packet timestamping only works if all packets are
6162 * timestamped, so enable timestamping in all packets as
6163 * long as one rx filter was configured.
6164 */
6165 if ((hw->mac.type == e1000_82580) && tsync_rx_ctl) {
6166 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
6167 tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
6168 }
6169
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006170 /* enable/disable TX */
6171 regval = rd32(E1000_TSYNCTXCTL);
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006172 regval &= ~E1000_TSYNCTXCTL_ENABLED;
6173 regval |= tsync_tx_ctl;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006174 wr32(E1000_TSYNCTXCTL, regval);
6175
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006176 /* enable/disable RX */
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006177 regval = rd32(E1000_TSYNCRXCTL);
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006178 regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
6179 regval |= tsync_rx_ctl;
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006180 wr32(E1000_TSYNCRXCTL, regval);
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006181
6182 /* define which PTP packets are time stamped */
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006183 wr32(E1000_TSYNCRXCFG, tsync_rx_cfg);
6184
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006185 /* define ethertype filter for timestamped packets */
6186 if (is_l2)
6187 wr32(E1000_ETQF(3),
6188 (E1000_ETQF_FILTER_ENABLE | /* enable filter */
6189 E1000_ETQF_1588 | /* enable timestamping */
6190 ETH_P_1588)); /* 1588 eth protocol type */
6191 else
6192 wr32(E1000_ETQF(3), 0);
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006193
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006194#define PTP_PORT 319
6195 /* L4 Queue Filter[3]: filter by destination port and protocol */
6196 if (is_l4) {
6197 u32 ftqf = (IPPROTO_UDP /* UDP */
6198 | E1000_FTQF_VF_BP /* VF not compared */
6199 | E1000_FTQF_1588_TIME_STAMP /* Enable Timestamping */
6200 | E1000_FTQF_MASK); /* mask all inputs */
6201 ftqf &= ~E1000_FTQF_MASK_PROTO_BP; /* enable protocol check */
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006202
Alexander Duyckc5b9bd52009-10-27 23:46:01 +00006203 wr32(E1000_IMIR(3), htons(PTP_PORT));
6204 wr32(E1000_IMIREXT(3),
6205 (E1000_IMIREXT_SIZE_BP | E1000_IMIREXT_CTRL_BP));
6206 if (hw->mac.type == e1000_82576) {
6207 /* enable source port check */
6208 wr32(E1000_SPQF(3), htons(PTP_PORT));
6209 ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
6210 }
6211 wr32(E1000_FTQF(3), ftqf);
6212 } else {
6213 wr32(E1000_FTQF(3), E1000_FTQF_MASK);
6214 }
Patrick Ohly33af6bc2009-02-12 05:03:43 +00006215 wrfl();
6216
6217 adapter->hwtstamp_config = config;
6218
6219 /* clear TX/RX time stamp registers, just to be sure */
6220 regval = rd32(E1000_TXSTMPH);
6221 regval = rd32(E1000_RXSTMPH);
6222
6223 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
6224 -EFAULT : 0;
Patrick Ohlyc6cb0902009-02-12 05:03:42 +00006225}
6226
6227/**
Auke Kok9d5c8242008-01-24 02:22:38 -08006228 * igb_ioctl -
6229 * @netdev:
6230 * @ifreq:
6231 * @cmd:
6232 **/
6233static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
6234{
6235 switch (cmd) {
6236 case SIOCGMIIPHY:
6237 case SIOCGMIIREG:
6238 case SIOCSMIIREG:
6239 return igb_mii_ioctl(netdev, ifr, cmd);
Patrick Ohlyc6cb0902009-02-12 05:03:42 +00006240 case SIOCSHWTSTAMP:
6241 return igb_hwtstamp_ioctl(netdev, ifr, cmd);
Auke Kok9d5c8242008-01-24 02:22:38 -08006242 default:
6243 return -EOPNOTSUPP;
6244 }
6245}
6246
Alexander Duyck009bc062009-07-23 18:08:35 +00006247s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
6248{
6249 struct igb_adapter *adapter = hw->back;
6250 u16 cap_offset;
6251
6252 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
6253 if (!cap_offset)
6254 return -E1000_ERR_CONFIG;
6255
6256 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
6257
6258 return 0;
6259}
6260
6261s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
6262{
6263 struct igb_adapter *adapter = hw->back;
6264 u16 cap_offset;
6265
6266 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
6267 if (!cap_offset)
6268 return -E1000_ERR_CONFIG;
6269
6270 pci_write_config_word(adapter->pdev, cap_offset + reg, *value);
6271
6272 return 0;
6273}
6274
Auke Kok9d5c8242008-01-24 02:22:38 -08006275static void igb_vlan_rx_register(struct net_device *netdev,
6276 struct vlan_group *grp)
6277{
6278 struct igb_adapter *adapter = netdev_priv(netdev);
6279 struct e1000_hw *hw = &adapter->hw;
6280 u32 ctrl, rctl;
6281
6282 igb_irq_disable(adapter);
6283 adapter->vlgrp = grp;
6284
6285 if (grp) {
6286 /* enable VLAN tag insert/strip */
6287 ctrl = rd32(E1000_CTRL);
6288 ctrl |= E1000_CTRL_VME;
6289 wr32(E1000_CTRL, ctrl);
6290
Alexander Duyck51466232009-10-27 23:47:35 +00006291 /* Disable CFI check */
Auke Kok9d5c8242008-01-24 02:22:38 -08006292 rctl = rd32(E1000_RCTL);
Auke Kok9d5c8242008-01-24 02:22:38 -08006293 rctl &= ~E1000_RCTL_CFIEN;
6294 wr32(E1000_RCTL, rctl);
Auke Kok9d5c8242008-01-24 02:22:38 -08006295 } else {
6296 /* disable VLAN tag insert/strip */
6297 ctrl = rd32(E1000_CTRL);
6298 ctrl &= ~E1000_CTRL_VME;
6299 wr32(E1000_CTRL, ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08006300 }
6301
Alexander Duycke1739522009-02-19 20:39:44 -08006302 igb_rlpml_set(adapter);
6303
Auke Kok9d5c8242008-01-24 02:22:38 -08006304 if (!test_bit(__IGB_DOWN, &adapter->state))
6305 igb_irq_enable(adapter);
6306}
6307
6308static void igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
6309{
6310 struct igb_adapter *adapter = netdev_priv(netdev);
6311 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006312 int pf_id = adapter->vfs_allocated_count;
Auke Kok9d5c8242008-01-24 02:22:38 -08006313
Alexander Duyck51466232009-10-27 23:47:35 +00006314 /* attempt to add filter to vlvf array */
6315 igb_vlvf_set(adapter, vid, true, pf_id);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006316
Alexander Duyck51466232009-10-27 23:47:35 +00006317 /* add the filter since PF can receive vlans w/o entry in vlvf */
6318 igb_vfta_set(hw, vid, true);
Auke Kok9d5c8242008-01-24 02:22:38 -08006319}
6320
6321static void igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
6322{
6323 struct igb_adapter *adapter = netdev_priv(netdev);
6324 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006325 int pf_id = adapter->vfs_allocated_count;
Alexander Duyck51466232009-10-27 23:47:35 +00006326 s32 err;
Auke Kok9d5c8242008-01-24 02:22:38 -08006327
6328 igb_irq_disable(adapter);
6329 vlan_group_set_device(adapter->vlgrp, vid, NULL);
6330
6331 if (!test_bit(__IGB_DOWN, &adapter->state))
6332 igb_irq_enable(adapter);
6333
Alexander Duyck51466232009-10-27 23:47:35 +00006334 /* remove vlan from VLVF table array */
6335 err = igb_vlvf_set(adapter, vid, false, pf_id);
Auke Kok9d5c8242008-01-24 02:22:38 -08006336
Alexander Duyck51466232009-10-27 23:47:35 +00006337 /* if vid was not present in VLVF just remove it from table */
6338 if (err)
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006339 igb_vfta_set(hw, vid, false);
Auke Kok9d5c8242008-01-24 02:22:38 -08006340}
6341
6342static void igb_restore_vlan(struct igb_adapter *adapter)
6343{
6344 igb_vlan_rx_register(adapter->netdev, adapter->vlgrp);
6345
6346 if (adapter->vlgrp) {
6347 u16 vid;
Jesse Grossb7381272010-10-20 13:56:02 +00006348 for (vid = 0; vid < VLAN_N_VID; vid++) {
Auke Kok9d5c8242008-01-24 02:22:38 -08006349 if (!vlan_group_get_device(adapter->vlgrp, vid))
6350 continue;
6351 igb_vlan_rx_add_vid(adapter->netdev, vid);
6352 }
6353 }
6354}
6355
David Decotigny14ad2512011-04-27 18:32:43 +00006356int igb_set_spd_dplx(struct igb_adapter *adapter, u32 spd, u8 dplx)
Auke Kok9d5c8242008-01-24 02:22:38 -08006357{
Alexander Duyck090b1792009-10-27 23:51:55 +00006358 struct pci_dev *pdev = adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08006359 struct e1000_mac_info *mac = &adapter->hw.mac;
6360
6361 mac->autoneg = 0;
6362
David Decotigny14ad2512011-04-27 18:32:43 +00006363 /* Make sure dplx is at most 1 bit and lsb of speed is not set
6364 * for the switch() below to work */
6365 if ((spd & 1) || (dplx & ~1))
6366 goto err_inval;
6367
Carolyn Wybornycd2638a2010-10-12 22:27:02 +00006368 /* Fiber NIC's only allow 1000 Gbps Full duplex */
6369 if ((adapter->hw.phy.media_type == e1000_media_type_internal_serdes) &&
David Decotigny14ad2512011-04-27 18:32:43 +00006370 spd != SPEED_1000 &&
6371 dplx != DUPLEX_FULL)
6372 goto err_inval;
Carolyn Wybornycd2638a2010-10-12 22:27:02 +00006373
David Decotigny14ad2512011-04-27 18:32:43 +00006374 switch (spd + dplx) {
Auke Kok9d5c8242008-01-24 02:22:38 -08006375 case SPEED_10 + DUPLEX_HALF:
6376 mac->forced_speed_duplex = ADVERTISE_10_HALF;
6377 break;
6378 case SPEED_10 + DUPLEX_FULL:
6379 mac->forced_speed_duplex = ADVERTISE_10_FULL;
6380 break;
6381 case SPEED_100 + DUPLEX_HALF:
6382 mac->forced_speed_duplex = ADVERTISE_100_HALF;
6383 break;
6384 case SPEED_100 + DUPLEX_FULL:
6385 mac->forced_speed_duplex = ADVERTISE_100_FULL;
6386 break;
6387 case SPEED_1000 + DUPLEX_FULL:
6388 mac->autoneg = 1;
6389 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
6390 break;
6391 case SPEED_1000 + DUPLEX_HALF: /* not supported */
6392 default:
David Decotigny14ad2512011-04-27 18:32:43 +00006393 goto err_inval;
Auke Kok9d5c8242008-01-24 02:22:38 -08006394 }
6395 return 0;
David Decotigny14ad2512011-04-27 18:32:43 +00006396
6397err_inval:
6398 dev_err(&pdev->dev, "Unsupported Speed/Duplex configuration\n");
6399 return -EINVAL;
Auke Kok9d5c8242008-01-24 02:22:38 -08006400}
6401
Rafael J. Wysocki3fe7c4c2009-03-31 21:23:50 +00006402static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake)
Auke Kok9d5c8242008-01-24 02:22:38 -08006403{
6404 struct net_device *netdev = pci_get_drvdata(pdev);
6405 struct igb_adapter *adapter = netdev_priv(netdev);
6406 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck2d064c02008-07-08 15:10:12 -07006407 u32 ctrl, rctl, status;
Auke Kok9d5c8242008-01-24 02:22:38 -08006408 u32 wufc = adapter->wol;
6409#ifdef CONFIG_PM
6410 int retval = 0;
6411#endif
6412
6413 netif_device_detach(netdev);
6414
Alexander Duycka88f10e2008-07-08 15:13:38 -07006415 if (netif_running(netdev))
6416 igb_close(netdev);
6417
Alexander Duyck047e0032009-10-27 15:49:27 +00006418 igb_clear_interrupt_scheme(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08006419
6420#ifdef CONFIG_PM
6421 retval = pci_save_state(pdev);
6422 if (retval)
6423 return retval;
6424#endif
6425
6426 status = rd32(E1000_STATUS);
6427 if (status & E1000_STATUS_LU)
6428 wufc &= ~E1000_WUFC_LNKC;
6429
6430 if (wufc) {
6431 igb_setup_rctl(adapter);
Alexander Duyckff41f8d2009-09-03 14:48:56 +00006432 igb_set_rx_mode(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08006433
6434 /* turn on all-multi mode if wake on multicast is enabled */
6435 if (wufc & E1000_WUFC_MC) {
6436 rctl = rd32(E1000_RCTL);
6437 rctl |= E1000_RCTL_MPE;
6438 wr32(E1000_RCTL, rctl);
6439 }
6440
6441 ctrl = rd32(E1000_CTRL);
6442 /* advertise wake from D3Cold */
6443 #define E1000_CTRL_ADVD3WUC 0x00100000
6444 /* phy power management enable */
6445 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
6446 ctrl |= E1000_CTRL_ADVD3WUC;
6447 wr32(E1000_CTRL, ctrl);
6448
Auke Kok9d5c8242008-01-24 02:22:38 -08006449 /* Allow time for pending master requests to run */
Alexander Duyck330a6d62009-10-27 23:51:35 +00006450 igb_disable_pcie_master(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08006451
6452 wr32(E1000_WUC, E1000_WUC_PME_EN);
6453 wr32(E1000_WUFC, wufc);
Auke Kok9d5c8242008-01-24 02:22:38 -08006454 } else {
6455 wr32(E1000_WUC, 0);
6456 wr32(E1000_WUFC, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -08006457 }
6458
Rafael J. Wysocki3fe7c4c2009-03-31 21:23:50 +00006459 *enable_wake = wufc || adapter->en_mng_pt;
6460 if (!*enable_wake)
Nick Nunley88a268c2010-02-17 01:01:59 +00006461 igb_power_down_link(adapter);
6462 else
6463 igb_power_up_link(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08006464
6465 /* Release control of h/w to f/w. If f/w is AMT enabled, this
6466 * would have already happened in close and is redundant. */
6467 igb_release_hw_control(adapter);
6468
6469 pci_disable_device(pdev);
6470
Auke Kok9d5c8242008-01-24 02:22:38 -08006471 return 0;
6472}
6473
6474#ifdef CONFIG_PM
Rafael J. Wysocki3fe7c4c2009-03-31 21:23:50 +00006475static int igb_suspend(struct pci_dev *pdev, pm_message_t state)
6476{
6477 int retval;
6478 bool wake;
6479
6480 retval = __igb_shutdown(pdev, &wake);
6481 if (retval)
6482 return retval;
6483
6484 if (wake) {
6485 pci_prepare_to_sleep(pdev);
6486 } else {
6487 pci_wake_from_d3(pdev, false);
6488 pci_set_power_state(pdev, PCI_D3hot);
6489 }
6490
6491 return 0;
6492}
6493
Auke Kok9d5c8242008-01-24 02:22:38 -08006494static int igb_resume(struct pci_dev *pdev)
6495{
6496 struct net_device *netdev = pci_get_drvdata(pdev);
6497 struct igb_adapter *adapter = netdev_priv(netdev);
6498 struct e1000_hw *hw = &adapter->hw;
6499 u32 err;
6500
6501 pci_set_power_state(pdev, PCI_D0);
6502 pci_restore_state(pdev);
Nick Nunleyb94f2d72010-02-17 01:02:19 +00006503 pci_save_state(pdev);
Taku Izumi42bfd33a2008-06-20 12:10:30 +09006504
Alexander Duyckaed5dec2009-02-06 23:16:04 +00006505 err = pci_enable_device_mem(pdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08006506 if (err) {
6507 dev_err(&pdev->dev,
6508 "igb: Cannot enable PCI device from suspend\n");
6509 return err;
6510 }
6511 pci_set_master(pdev);
6512
6513 pci_enable_wake(pdev, PCI_D3hot, 0);
6514 pci_enable_wake(pdev, PCI_D3cold, 0);
6515
Alexander Duyck047e0032009-10-27 15:49:27 +00006516 if (igb_init_interrupt_scheme(adapter)) {
Alexander Duycka88f10e2008-07-08 15:13:38 -07006517 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
6518 return -ENOMEM;
Auke Kok9d5c8242008-01-24 02:22:38 -08006519 }
6520
Auke Kok9d5c8242008-01-24 02:22:38 -08006521 igb_reset(adapter);
Alexander Duycka8564f02009-02-06 23:21:10 +00006522
6523 /* let the f/w know that the h/w is now under the control of the
6524 * driver. */
6525 igb_get_hw_control(adapter);
6526
Auke Kok9d5c8242008-01-24 02:22:38 -08006527 wr32(E1000_WUS, ~0);
6528
Alexander Duycka88f10e2008-07-08 15:13:38 -07006529 if (netif_running(netdev)) {
6530 err = igb_open(netdev);
6531 if (err)
6532 return err;
6533 }
Auke Kok9d5c8242008-01-24 02:22:38 -08006534
6535 netif_device_attach(netdev);
6536
Auke Kok9d5c8242008-01-24 02:22:38 -08006537 return 0;
6538}
6539#endif
6540
6541static void igb_shutdown(struct pci_dev *pdev)
6542{
Rafael J. Wysocki3fe7c4c2009-03-31 21:23:50 +00006543 bool wake;
6544
6545 __igb_shutdown(pdev, &wake);
6546
6547 if (system_state == SYSTEM_POWER_OFF) {
6548 pci_wake_from_d3(pdev, wake);
6549 pci_set_power_state(pdev, PCI_D3hot);
6550 }
Auke Kok9d5c8242008-01-24 02:22:38 -08006551}
6552
6553#ifdef CONFIG_NET_POLL_CONTROLLER
6554/*
6555 * Polling 'interrupt' - used by things like netconsole to send skbs
6556 * without having to re-enable interrupts. It's not called while
6557 * the interrupt routine is executing.
6558 */
6559static void igb_netpoll(struct net_device *netdev)
6560{
6561 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyckeebbbdb2009-02-06 23:19:29 +00006562 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08006563 int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08006564
Alexander Duyckeebbbdb2009-02-06 23:19:29 +00006565 if (!adapter->msix_entries) {
Alexander Duyck047e0032009-10-27 15:49:27 +00006566 struct igb_q_vector *q_vector = adapter->q_vector[0];
Alexander Duyckeebbbdb2009-02-06 23:19:29 +00006567 igb_irq_disable(adapter);
Alexander Duyck047e0032009-10-27 15:49:27 +00006568 napi_schedule(&q_vector->napi);
Alexander Duyckeebbbdb2009-02-06 23:19:29 +00006569 return;
6570 }
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07006571
Alexander Duyck047e0032009-10-27 15:49:27 +00006572 for (i = 0; i < adapter->num_q_vectors; i++) {
6573 struct igb_q_vector *q_vector = adapter->q_vector[i];
6574 wr32(E1000_EIMC, q_vector->eims_value);
6575 napi_schedule(&q_vector->napi);
Alexander Duyckeebbbdb2009-02-06 23:19:29 +00006576 }
Auke Kok9d5c8242008-01-24 02:22:38 -08006577}
6578#endif /* CONFIG_NET_POLL_CONTROLLER */
6579
6580/**
6581 * igb_io_error_detected - called when PCI error is detected
6582 * @pdev: Pointer to PCI device
6583 * @state: The current pci connection state
6584 *
6585 * This function is called after a PCI bus error affecting
6586 * this device has been detected.
6587 */
6588static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
6589 pci_channel_state_t state)
6590{
6591 struct net_device *netdev = pci_get_drvdata(pdev);
6592 struct igb_adapter *adapter = netdev_priv(netdev);
6593
6594 netif_device_detach(netdev);
6595
Alexander Duyck59ed6ee2009-06-30 12:46:34 +00006596 if (state == pci_channel_io_perm_failure)
6597 return PCI_ERS_RESULT_DISCONNECT;
6598
Auke Kok9d5c8242008-01-24 02:22:38 -08006599 if (netif_running(netdev))
6600 igb_down(adapter);
6601 pci_disable_device(pdev);
6602
6603 /* Request a slot slot reset. */
6604 return PCI_ERS_RESULT_NEED_RESET;
6605}
6606
6607/**
6608 * igb_io_slot_reset - called after the pci bus has been reset.
6609 * @pdev: Pointer to PCI device
6610 *
6611 * Restart the card from scratch, as if from a cold-boot. Implementation
6612 * resembles the first-half of the igb_resume routine.
6613 */
6614static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
6615{
6616 struct net_device *netdev = pci_get_drvdata(pdev);
6617 struct igb_adapter *adapter = netdev_priv(netdev);
6618 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck40a914f2008-11-27 00:24:37 -08006619 pci_ers_result_t result;
Taku Izumi42bfd33a2008-06-20 12:10:30 +09006620 int err;
Auke Kok9d5c8242008-01-24 02:22:38 -08006621
Alexander Duyckaed5dec2009-02-06 23:16:04 +00006622 if (pci_enable_device_mem(pdev)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08006623 dev_err(&pdev->dev,
6624 "Cannot re-enable PCI device after reset.\n");
Alexander Duyck40a914f2008-11-27 00:24:37 -08006625 result = PCI_ERS_RESULT_DISCONNECT;
6626 } else {
6627 pci_set_master(pdev);
6628 pci_restore_state(pdev);
Nick Nunleyb94f2d72010-02-17 01:02:19 +00006629 pci_save_state(pdev);
Alexander Duyck40a914f2008-11-27 00:24:37 -08006630
6631 pci_enable_wake(pdev, PCI_D3hot, 0);
6632 pci_enable_wake(pdev, PCI_D3cold, 0);
6633
6634 igb_reset(adapter);
6635 wr32(E1000_WUS, ~0);
6636 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9d5c8242008-01-24 02:22:38 -08006637 }
Auke Kok9d5c8242008-01-24 02:22:38 -08006638
Jeff Kirsherea943d42008-12-11 20:34:19 -08006639 err = pci_cleanup_aer_uncorrect_error_status(pdev);
6640 if (err) {
6641 dev_err(&pdev->dev, "pci_cleanup_aer_uncorrect_error_status "
6642 "failed 0x%0x\n", err);
6643 /* non-fatal, continue */
6644 }
Auke Kok9d5c8242008-01-24 02:22:38 -08006645
Alexander Duyck40a914f2008-11-27 00:24:37 -08006646 return result;
Auke Kok9d5c8242008-01-24 02:22:38 -08006647}
6648
6649/**
6650 * igb_io_resume - called when traffic can start flowing again.
6651 * @pdev: Pointer to PCI device
6652 *
6653 * This callback is called when the error recovery driver tells us that
6654 * its OK to resume normal operation. Implementation resembles the
6655 * second-half of the igb_resume routine.
6656 */
6657static void igb_io_resume(struct pci_dev *pdev)
6658{
6659 struct net_device *netdev = pci_get_drvdata(pdev);
6660 struct igb_adapter *adapter = netdev_priv(netdev);
6661
Auke Kok9d5c8242008-01-24 02:22:38 -08006662 if (netif_running(netdev)) {
6663 if (igb_up(adapter)) {
6664 dev_err(&pdev->dev, "igb_up failed after reset\n");
6665 return;
6666 }
6667 }
6668
6669 netif_device_attach(netdev);
6670
6671 /* let the f/w know that the h/w is now under the control of the
6672 * driver. */
6673 igb_get_hw_control(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08006674}
6675
Alexander Duyck26ad9172009-10-05 06:32:49 +00006676static void igb_rar_set_qsel(struct igb_adapter *adapter, u8 *addr, u32 index,
6677 u8 qsel)
6678{
6679 u32 rar_low, rar_high;
6680 struct e1000_hw *hw = &adapter->hw;
6681
6682 /* HW expects these in little endian so we reverse the byte order
6683 * from network order (big endian) to little endian
6684 */
6685 rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
6686 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
6687 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
6688
6689 /* Indicate to hardware the Address is Valid. */
6690 rar_high |= E1000_RAH_AV;
6691
6692 if (hw->mac.type == e1000_82575)
6693 rar_high |= E1000_RAH_POOL_1 * qsel;
6694 else
6695 rar_high |= E1000_RAH_POOL_1 << qsel;
6696
6697 wr32(E1000_RAL(index), rar_low);
6698 wrfl();
6699 wr32(E1000_RAH(index), rar_high);
6700 wrfl();
6701}
6702
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006703static int igb_set_vf_mac(struct igb_adapter *adapter,
6704 int vf, unsigned char *mac_addr)
6705{
6706 struct e1000_hw *hw = &adapter->hw;
Alexander Duyckff41f8d2009-09-03 14:48:56 +00006707 /* VF MAC addresses start at end of receive addresses and moves
6708 * torwards the first, as a result a collision should not be possible */
6709 int rar_entry = hw->mac.rar_entry_count - (vf + 1);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006710
Alexander Duyck37680112009-02-19 20:40:30 -08006711 memcpy(adapter->vf_data[vf].vf_mac_addresses, mac_addr, ETH_ALEN);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006712
Alexander Duyck26ad9172009-10-05 06:32:49 +00006713 igb_rar_set_qsel(adapter, mac_addr, rar_entry, vf);
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006714
6715 return 0;
6716}
6717
Williams, Mitch A8151d292010-02-10 01:44:24 +00006718static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
6719{
6720 struct igb_adapter *adapter = netdev_priv(netdev);
6721 if (!is_valid_ether_addr(mac) || (vf >= adapter->vfs_allocated_count))
6722 return -EINVAL;
6723 adapter->vf_data[vf].flags |= IGB_VF_FLAG_PF_SET_MAC;
6724 dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf);
6725 dev_info(&adapter->pdev->dev, "Reload the VF driver to make this"
6726 " change effective.");
6727 if (test_bit(__IGB_DOWN, &adapter->state)) {
6728 dev_warn(&adapter->pdev->dev, "The VF MAC address has been set,"
6729 " but the PF device is not up.\n");
6730 dev_warn(&adapter->pdev->dev, "Bring the PF device up before"
6731 " attempting to use the VF device.\n");
6732 }
6733 return igb_set_vf_mac(adapter, vf, mac);
6734}
6735
Lior Levy17dc5662011-02-08 02:28:46 +00006736static int igb_link_mbps(int internal_link_speed)
6737{
6738 switch (internal_link_speed) {
6739 case SPEED_100:
6740 return 100;
6741 case SPEED_1000:
6742 return 1000;
6743 default:
6744 return 0;
6745 }
6746}
6747
6748static void igb_set_vf_rate_limit(struct e1000_hw *hw, int vf, int tx_rate,
6749 int link_speed)
6750{
6751 int rf_dec, rf_int;
6752 u32 bcnrc_val;
6753
6754 if (tx_rate != 0) {
6755 /* Calculate the rate factor values to set */
6756 rf_int = link_speed / tx_rate;
6757 rf_dec = (link_speed - (rf_int * tx_rate));
6758 rf_dec = (rf_dec * (1<<E1000_RTTBCNRC_RF_INT_SHIFT)) / tx_rate;
6759
6760 bcnrc_val = E1000_RTTBCNRC_RS_ENA;
6761 bcnrc_val |= ((rf_int<<E1000_RTTBCNRC_RF_INT_SHIFT) &
6762 E1000_RTTBCNRC_RF_INT_MASK);
6763 bcnrc_val |= (rf_dec & E1000_RTTBCNRC_RF_DEC_MASK);
6764 } else {
6765 bcnrc_val = 0;
6766 }
6767
6768 wr32(E1000_RTTDQSEL, vf); /* vf X uses queue X */
6769 wr32(E1000_RTTBCNRC, bcnrc_val);
6770}
6771
6772static void igb_check_vf_rate_limit(struct igb_adapter *adapter)
6773{
6774 int actual_link_speed, i;
6775 bool reset_rate = false;
6776
6777 /* VF TX rate limit was not set or not supported */
6778 if ((adapter->vf_rate_link_speed == 0) ||
6779 (adapter->hw.mac.type != e1000_82576))
6780 return;
6781
6782 actual_link_speed = igb_link_mbps(adapter->link_speed);
6783 if (actual_link_speed != adapter->vf_rate_link_speed) {
6784 reset_rate = true;
6785 adapter->vf_rate_link_speed = 0;
6786 dev_info(&adapter->pdev->dev,
6787 "Link speed has been changed. VF Transmit "
6788 "rate is disabled\n");
6789 }
6790
6791 for (i = 0; i < adapter->vfs_allocated_count; i++) {
6792 if (reset_rate)
6793 adapter->vf_data[i].tx_rate = 0;
6794
6795 igb_set_vf_rate_limit(&adapter->hw, i,
6796 adapter->vf_data[i].tx_rate,
6797 actual_link_speed);
6798 }
6799}
6800
Williams, Mitch A8151d292010-02-10 01:44:24 +00006801static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate)
6802{
Lior Levy17dc5662011-02-08 02:28:46 +00006803 struct igb_adapter *adapter = netdev_priv(netdev);
6804 struct e1000_hw *hw = &adapter->hw;
6805 int actual_link_speed;
6806
6807 if (hw->mac.type != e1000_82576)
6808 return -EOPNOTSUPP;
6809
6810 actual_link_speed = igb_link_mbps(adapter->link_speed);
6811 if ((vf >= adapter->vfs_allocated_count) ||
6812 (!(rd32(E1000_STATUS) & E1000_STATUS_LU)) ||
6813 (tx_rate < 0) || (tx_rate > actual_link_speed))
6814 return -EINVAL;
6815
6816 adapter->vf_rate_link_speed = actual_link_speed;
6817 adapter->vf_data[vf].tx_rate = (u16)tx_rate;
6818 igb_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed);
6819
6820 return 0;
Williams, Mitch A8151d292010-02-10 01:44:24 +00006821}
6822
6823static int igb_ndo_get_vf_config(struct net_device *netdev,
6824 int vf, struct ifla_vf_info *ivi)
6825{
6826 struct igb_adapter *adapter = netdev_priv(netdev);
6827 if (vf >= adapter->vfs_allocated_count)
6828 return -EINVAL;
6829 ivi->vf = vf;
6830 memcpy(&ivi->mac, adapter->vf_data[vf].vf_mac_addresses, ETH_ALEN);
Lior Levy17dc5662011-02-08 02:28:46 +00006831 ivi->tx_rate = adapter->vf_data[vf].tx_rate;
Williams, Mitch A8151d292010-02-10 01:44:24 +00006832 ivi->vlan = adapter->vf_data[vf].pf_vlan;
6833 ivi->qos = adapter->vf_data[vf].pf_qos;
6834 return 0;
6835}
6836
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006837static void igb_vmm_control(struct igb_adapter *adapter)
6838{
6839 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck10d8e902009-10-27 15:54:04 +00006840 u32 reg;
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006841
Alexander Duyck52a1dd42010-03-22 14:07:46 +00006842 switch (hw->mac.type) {
6843 case e1000_82575:
6844 default:
6845 /* replication is not supported for 82575 */
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006846 return;
Alexander Duyck52a1dd42010-03-22 14:07:46 +00006847 case e1000_82576:
6848 /* notify HW that the MAC is adding vlan tags */
6849 reg = rd32(E1000_DTXCTL);
6850 reg |= E1000_DTXCTL_VLAN_ADDED;
6851 wr32(E1000_DTXCTL, reg);
6852 case e1000_82580:
6853 /* enable replication vlan tag stripping */
6854 reg = rd32(E1000_RPLOLR);
6855 reg |= E1000_RPLOLR_STRVLAN;
6856 wr32(E1000_RPLOLR, reg);
Alexander Duyckd2ba2ed2010-03-22 14:08:06 +00006857 case e1000_i350:
6858 /* none of the above registers are supported by i350 */
Alexander Duyck52a1dd42010-03-22 14:07:46 +00006859 break;
6860 }
Alexander Duyck10d8e902009-10-27 15:54:04 +00006861
Alexander Duyckd4960302009-10-27 15:53:45 +00006862 if (adapter->vfs_allocated_count) {
6863 igb_vmdq_set_loopback_pf(hw, true);
6864 igb_vmdq_set_replication_pf(hw, true);
Greg Rose13800462010-11-06 02:08:26 +00006865 igb_vmdq_set_anti_spoofing_pf(hw, true,
6866 adapter->vfs_allocated_count);
Alexander Duyckd4960302009-10-27 15:53:45 +00006867 } else {
6868 igb_vmdq_set_loopback_pf(hw, false);
6869 igb_vmdq_set_replication_pf(hw, false);
6870 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -08006871}
6872
Auke Kok9d5c8242008-01-24 02:22:38 -08006873/* igb_main.c */