1 /* Intel(R) Gigabit Ethernet Linux driver
2 * Copyright(c) 2007-2014 Intel Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, see <http://www.gnu.org/licenses/>.
16 * The full GNU General Public License is included in this distribution in
17 * the file called "COPYING".
19 * Contact Information:
20 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
21 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26 #include <linux/module.h>
27 #include <linux/types.h>
28 #include <linux/init.h>
29 #include <linux/bitops.h>
30 #include <linux/vmalloc.h>
31 #include <linux/pagemap.h>
32 #include <linux/netdevice.h>
33 #include <linux/ipv6.h>
34 #include <linux/slab.h>
35 #include <net/checksum.h>
36 #include <net/ip6_checksum.h>
37 #include <linux/net_tstamp.h>
38 #include <linux/mii.h>
39 #include <linux/ethtool.h>
41 #include <linux/if_vlan.h>
42 #include <linux/pci.h>
43 #include <linux/pci-aspm.h>
44 #include <linux/delay.h>
45 #include <linux/interrupt.h>
47 #include <linux/tcp.h>
48 #include <linux/sctp.h>
49 #include <linux/if_ether.h>
50 #include <linux/aer.h>
51 #include <linux/prefetch.h>
52 #include <linux/pm_runtime.h>
53 #include <linux/etherdevice.h>
55 #include <linux/dca.h>
57 #include <linux/i2c.h>
63 #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
64 __stringify(BUILD) "-k"
65 char igb_driver_name[] = "igb";
66 char igb_driver_version[] = DRV_VERSION;
67 static const char igb_driver_string[] =
68 "Intel(R) Gigabit Ethernet Network Driver";
69 static const char igb_copyright[] =
70 "Copyright (c) 2007-2014 Intel Corporation.";
72 static const struct e1000_info *igb_info_tbl[] = {
73 [board_82575] = &e1000_82575_info,
76 static const struct pci_device_id igb_pci_tbl[] = {
77 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_BACKPLANE_1GBPS) },
78 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_SGMII) },
79 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) },
80 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I211_COPPER), board_82575 },
81 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_COPPER), board_82575 },
82 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_FIBER), board_82575 },
83 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SERDES), board_82575 },
84 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SGMII), board_82575 },
85 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_COPPER_FLASHLESS), board_82575 },
86 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I210_SERDES_FLASHLESS), board_82575 },
87 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_COPPER), board_82575 },
88 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_FIBER), board_82575 },
89 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SERDES), board_82575 },
90 { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SGMII), board_82575 },
91 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER), board_82575 },
92 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_FIBER), board_82575 },
93 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_QUAD_FIBER), board_82575 },
94 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SERDES), board_82575 },
95 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SGMII), board_82575 },
96 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER_DUAL), board_82575 },
97 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SGMII), board_82575 },
98 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SERDES), board_82575 },
99 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_BACKPLANE), board_82575 },
100 { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SFP), board_82575 },
101 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 },
102 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS), board_82575 },
103 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS_SERDES), board_82575 },
104 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 },
105 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 },
106 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES_QUAD), board_82575 },
107 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER_ET2), board_82575 },
108 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER), board_82575 },
109 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 },
110 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 },
111 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 },
112 /* required last entry */
116 MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
118 static int igb_setup_all_tx_resources(struct igb_adapter *);
119 static int igb_setup_all_rx_resources(struct igb_adapter *);
120 static void igb_free_all_tx_resources(struct igb_adapter *);
121 static void igb_free_all_rx_resources(struct igb_adapter *);
122 static void igb_setup_mrqc(struct igb_adapter *);
123 static int igb_probe(struct pci_dev *, const struct pci_device_id *);
124 static void igb_remove(struct pci_dev *pdev);
125 static int igb_sw_init(struct igb_adapter *);
126 int igb_open(struct net_device *);
127 int igb_close(struct net_device *);
128 static void igb_configure(struct igb_adapter *);
129 static void igb_configure_tx(struct igb_adapter *);
130 static void igb_configure_rx(struct igb_adapter *);
131 static void igb_clean_all_tx_rings(struct igb_adapter *);
132 static void igb_clean_all_rx_rings(struct igb_adapter *);
133 static void igb_clean_tx_ring(struct igb_ring *);
134 static void igb_clean_rx_ring(struct igb_ring *);
135 static void igb_set_rx_mode(struct net_device *);
136 static void igb_update_phy_info(unsigned long);
137 static void igb_watchdog(unsigned long);
138 static void igb_watchdog_task(struct work_struct *);
139 static netdev_tx_t igb_xmit_frame(struct sk_buff *skb, struct net_device *);
140 static void igb_get_stats64(struct net_device *dev,
141 struct rtnl_link_stats64 *stats);
142 static int igb_change_mtu(struct net_device *, int);
143 static int igb_set_mac(struct net_device *, void *);
144 static void igb_set_uta(struct igb_adapter *adapter, bool set);
145 static irqreturn_t igb_intr(int irq, void *);
146 static irqreturn_t igb_intr_msi(int irq, void *);
147 static irqreturn_t igb_msix_other(int irq, void *);
148 static irqreturn_t igb_msix_ring(int irq, void *);
149 #ifdef CONFIG_IGB_DCA
150 static void igb_update_dca(struct igb_q_vector *);
151 static void igb_setup_dca(struct igb_adapter *);
152 #endif /* CONFIG_IGB_DCA */
153 static int igb_poll(struct napi_struct *, int);
154 static bool igb_clean_tx_irq(struct igb_q_vector *, int);
155 static int igb_clean_rx_irq(struct igb_q_vector *, int);
156 static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
157 static void igb_tx_timeout(struct net_device *);
158 static void igb_reset_task(struct work_struct *);
159 static void igb_vlan_mode(struct net_device *netdev,
160 netdev_features_t features);
161 static int igb_vlan_rx_add_vid(struct net_device *, __be16, u16);
162 static int igb_vlan_rx_kill_vid(struct net_device *, __be16, u16);
163 static void igb_restore_vlan(struct igb_adapter *);
164 static void igb_rar_set_index(struct igb_adapter *, u32);
165 static void igb_ping_all_vfs(struct igb_adapter *);
166 static void igb_msg_task(struct igb_adapter *);
167 static void igb_vmm_control(struct igb_adapter *);
168 static int igb_set_vf_mac(struct igb_adapter *, int, unsigned char *);
169 static void igb_flush_mac_table(struct igb_adapter *);
170 static int igb_available_rars(struct igb_adapter *, u8);
171 static void igb_set_default_mac_filter(struct igb_adapter *);
172 static int igb_uc_sync(struct net_device *, const unsigned char *);
173 static int igb_uc_unsync(struct net_device *, const unsigned char *);
174 static void igb_restore_vf_multicasts(struct igb_adapter *adapter);
175 static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac);
176 static int igb_ndo_set_vf_vlan(struct net_device *netdev,
177 int vf, u16 vlan, u8 qos, __be16 vlan_proto);
178 static int igb_ndo_set_vf_bw(struct net_device *, int, int, int);
179 static int igb_ndo_set_vf_spoofchk(struct net_device *netdev, int vf,
181 static int igb_ndo_get_vf_config(struct net_device *netdev, int vf,
182 struct ifla_vf_info *ivi);
183 static void igb_check_vf_rate_limit(struct igb_adapter *);
184 static void igb_nfc_filter_exit(struct igb_adapter *adapter);
185 static void igb_nfc_filter_restore(struct igb_adapter *adapter);
187 #ifdef CONFIG_PCI_IOV
188 static int igb_vf_configure(struct igb_adapter *adapter, int vf);
189 static int igb_pci_enable_sriov(struct pci_dev *dev, int num_vfs);
190 static int igb_disable_sriov(struct pci_dev *dev);
191 static int igb_pci_disable_sriov(struct pci_dev *dev);
194 static int igb_suspend(struct device *);
195 static int igb_resume(struct device *);
196 static int igb_runtime_suspend(struct device *dev);
197 static int igb_runtime_resume(struct device *dev);
198 static int igb_runtime_idle(struct device *dev);
199 static const struct dev_pm_ops igb_pm_ops = {
200 SET_SYSTEM_SLEEP_PM_OPS(igb_suspend, igb_resume)
201 SET_RUNTIME_PM_OPS(igb_runtime_suspend, igb_runtime_resume,
204 static void igb_shutdown(struct pci_dev *);
205 static int igb_pci_sriov_configure(struct pci_dev *dev, int num_vfs);
206 #ifdef CONFIG_IGB_DCA
207 static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
208 static struct notifier_block dca_notifier = {
209 .notifier_call = igb_notify_dca,
214 #ifdef CONFIG_NET_POLL_CONTROLLER
215 /* for netdump / net console */
216 static void igb_netpoll(struct net_device *);
218 #ifdef CONFIG_PCI_IOV
219 static unsigned int max_vfs;
220 module_param(max_vfs, uint, 0);
221 MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate per physical function");
222 #endif /* CONFIG_PCI_IOV */
224 static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
225 pci_channel_state_t);
226 static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
227 static void igb_io_resume(struct pci_dev *);
229 static const struct pci_error_handlers igb_err_handler = {
230 .error_detected = igb_io_error_detected,
231 .slot_reset = igb_io_slot_reset,
232 .resume = igb_io_resume,
235 static void igb_init_dmac(struct igb_adapter *adapter, u32 pba);
237 static struct pci_driver igb_driver = {
238 .name = igb_driver_name,
239 .id_table = igb_pci_tbl,
241 .remove = igb_remove,
243 .driver.pm = &igb_pm_ops,
245 .shutdown = igb_shutdown,
246 .sriov_configure = igb_pci_sriov_configure,
247 .err_handler = &igb_err_handler
250 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
251 MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
252 MODULE_LICENSE("GPL");
253 MODULE_VERSION(DRV_VERSION);
255 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
256 static int debug = -1;
257 module_param(debug, int, 0);
258 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
260 struct igb_reg_info {
265 static const struct igb_reg_info igb_reg_info_tbl[] = {
267 /* General Registers */
268 {E1000_CTRL, "CTRL"},
269 {E1000_STATUS, "STATUS"},
270 {E1000_CTRL_EXT, "CTRL_EXT"},
272 /* Interrupt Registers */
276 {E1000_RCTL, "RCTL"},
277 {E1000_RDLEN(0), "RDLEN"},
278 {E1000_RDH(0), "RDH"},
279 {E1000_RDT(0), "RDT"},
280 {E1000_RXDCTL(0), "RXDCTL"},
281 {E1000_RDBAL(0), "RDBAL"},
282 {E1000_RDBAH(0), "RDBAH"},
285 {E1000_TCTL, "TCTL"},
286 {E1000_TDBAL(0), "TDBAL"},
287 {E1000_TDBAH(0), "TDBAH"},
288 {E1000_TDLEN(0), "TDLEN"},
289 {E1000_TDH(0), "TDH"},
290 {E1000_TDT(0), "TDT"},
291 {E1000_TXDCTL(0), "TXDCTL"},
292 {E1000_TDFH, "TDFH"},
293 {E1000_TDFT, "TDFT"},
294 {E1000_TDFHS, "TDFHS"},
295 {E1000_TDFPC, "TDFPC"},
297 /* List Terminator */
301 /* igb_regdump - register printout routine */
302 static void igb_regdump(struct e1000_hw *hw, struct igb_reg_info *reginfo)
308 switch (reginfo->ofs) {
310 for (n = 0; n < 4; n++)
311 regs[n] = rd32(E1000_RDLEN(n));
314 for (n = 0; n < 4; n++)
315 regs[n] = rd32(E1000_RDH(n));
318 for (n = 0; n < 4; n++)
319 regs[n] = rd32(E1000_RDT(n));
321 case E1000_RXDCTL(0):
322 for (n = 0; n < 4; n++)
323 regs[n] = rd32(E1000_RXDCTL(n));
326 for (n = 0; n < 4; n++)
327 regs[n] = rd32(E1000_RDBAL(n));
330 for (n = 0; n < 4; n++)
331 regs[n] = rd32(E1000_RDBAH(n));
334 for (n = 0; n < 4; n++)
335 regs[n] = rd32(E1000_RDBAL(n));
338 for (n = 0; n < 4; n++)
339 regs[n] = rd32(E1000_TDBAH(n));
342 for (n = 0; n < 4; n++)
343 regs[n] = rd32(E1000_TDLEN(n));
346 for (n = 0; n < 4; n++)
347 regs[n] = rd32(E1000_TDH(n));
350 for (n = 0; n < 4; n++)
351 regs[n] = rd32(E1000_TDT(n));
353 case E1000_TXDCTL(0):
354 for (n = 0; n < 4; n++)
355 regs[n] = rd32(E1000_TXDCTL(n));
358 pr_info("%-15s %08x\n", reginfo->name, rd32(reginfo->ofs));
362 snprintf(rname, 16, "%s%s", reginfo->name, "[0-3]");
363 pr_info("%-15s %08x %08x %08x %08x\n", rname, regs[0], regs[1],
367 /* igb_dump - Print registers, Tx-rings and Rx-rings */
368 static void igb_dump(struct igb_adapter *adapter)
370 struct net_device *netdev = adapter->netdev;
371 struct e1000_hw *hw = &adapter->hw;
372 struct igb_reg_info *reginfo;
373 struct igb_ring *tx_ring;
374 union e1000_adv_tx_desc *tx_desc;
375 struct my_u0 { u64 a; u64 b; } *u0;
376 struct igb_ring *rx_ring;
377 union e1000_adv_rx_desc *rx_desc;
381 if (!netif_msg_hw(adapter))
384 /* Print netdevice Info */
386 dev_info(&adapter->pdev->dev, "Net device Info\n");
387 pr_info("Device Name state trans_start\n");
388 pr_info("%-15s %016lX %016lX\n", netdev->name,
389 netdev->state, dev_trans_start(netdev));
392 /* Print Registers */
393 dev_info(&adapter->pdev->dev, "Register Dump\n");
394 pr_info(" Register Name Value\n");
395 for (reginfo = (struct igb_reg_info *)igb_reg_info_tbl;
396 reginfo->name; reginfo++) {
397 igb_regdump(hw, reginfo);
400 /* Print TX Ring Summary */
401 if (!netdev || !netif_running(netdev))
404 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
405 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
406 for (n = 0; n < adapter->num_tx_queues; n++) {
407 struct igb_tx_buffer *buffer_info;
408 tx_ring = adapter->tx_ring[n];
409 buffer_info = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
410 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
411 n, tx_ring->next_to_use, tx_ring->next_to_clean,
412 (u64)dma_unmap_addr(buffer_info, dma),
413 dma_unmap_len(buffer_info, len),
414 buffer_info->next_to_watch,
415 (u64)buffer_info->time_stamp);
419 if (!netif_msg_tx_done(adapter))
420 goto rx_ring_summary;
422 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
424 /* Transmit Descriptor Formats
426 * Advanced Transmit Descriptor
427 * +--------------------------------------------------------------+
428 * 0 | Buffer Address [63:0] |
429 * +--------------------------------------------------------------+
430 * 8 | PAYLEN | PORTS |CC|IDX | STA | DCMD |DTYP|MAC|RSV| DTALEN |
431 * +--------------------------------------------------------------+
432 * 63 46 45 40 39 38 36 35 32 31 24 15 0
435 for (n = 0; n < adapter->num_tx_queues; n++) {
436 tx_ring = adapter->tx_ring[n];
437 pr_info("------------------------------------\n");
438 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
439 pr_info("------------------------------------\n");
440 pr_info("T [desc] [address 63:0 ] [PlPOCIStDDM Ln] [bi->dma ] leng ntw timestamp bi->skb\n");
442 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
443 const char *next_desc;
444 struct igb_tx_buffer *buffer_info;
445 tx_desc = IGB_TX_DESC(tx_ring, i);
446 buffer_info = &tx_ring->tx_buffer_info[i];
447 u0 = (struct my_u0 *)tx_desc;
448 if (i == tx_ring->next_to_use &&
449 i == tx_ring->next_to_clean)
450 next_desc = " NTC/U";
451 else if (i == tx_ring->next_to_use)
453 else if (i == tx_ring->next_to_clean)
458 pr_info("T [0x%03X] %016llX %016llX %016llX %04X %p %016llX %p%s\n",
459 i, le64_to_cpu(u0->a),
461 (u64)dma_unmap_addr(buffer_info, dma),
462 dma_unmap_len(buffer_info, len),
463 buffer_info->next_to_watch,
464 (u64)buffer_info->time_stamp,
465 buffer_info->skb, next_desc);
467 if (netif_msg_pktdata(adapter) && buffer_info->skb)
468 print_hex_dump(KERN_INFO, "",
470 16, 1, buffer_info->skb->data,
471 dma_unmap_len(buffer_info, len),
476 /* Print RX Rings Summary */
478 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
479 pr_info("Queue [NTU] [NTC]\n");
480 for (n = 0; n < adapter->num_rx_queues; n++) {
481 rx_ring = adapter->rx_ring[n];
482 pr_info(" %5d %5X %5X\n",
483 n, rx_ring->next_to_use, rx_ring->next_to_clean);
487 if (!netif_msg_rx_status(adapter))
490 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
492 /* Advanced Receive Descriptor (Read) Format
494 * +-----------------------------------------------------+
495 * 0 | Packet Buffer Address [63:1] |A0/NSE|
496 * +----------------------------------------------+------+
497 * 8 | Header Buffer Address [63:1] | DD |
498 * +-----------------------------------------------------+
501 * Advanced Receive Descriptor (Write-Back) Format
503 * 63 48 47 32 31 30 21 20 17 16 4 3 0
504 * +------------------------------------------------------+
505 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
506 * | Checksum Ident | | | | Type | Type |
507 * +------------------------------------------------------+
508 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
509 * +------------------------------------------------------+
510 * 63 48 47 32 31 20 19 0
513 for (n = 0; n < adapter->num_rx_queues; n++) {
514 rx_ring = adapter->rx_ring[n];
515 pr_info("------------------------------------\n");
516 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
517 pr_info("------------------------------------\n");
518 pr_info("R [desc] [ PktBuf A0] [ HeadBuf DD] [bi->dma ] [bi->skb] <-- Adv Rx Read format\n");
519 pr_info("RWB[desc] [PcsmIpSHl PtRs] [vl er S cks ln] ---------------- [bi->skb] <-- Adv Rx Write-Back format\n");
521 for (i = 0; i < rx_ring->count; i++) {
522 const char *next_desc;
523 struct igb_rx_buffer *buffer_info;
524 buffer_info = &rx_ring->rx_buffer_info[i];
525 rx_desc = IGB_RX_DESC(rx_ring, i);
526 u0 = (struct my_u0 *)rx_desc;
527 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
529 if (i == rx_ring->next_to_use)
531 else if (i == rx_ring->next_to_clean)
536 if (staterr & E1000_RXD_STAT_DD) {
537 /* Descriptor Done */
538 pr_info("%s[0x%03X] %016llX %016llX ---------------- %s\n",
544 pr_info("%s[0x%03X] %016llX %016llX %016llX %s\n",
548 (u64)buffer_info->dma,
551 if (netif_msg_pktdata(adapter) &&
552 buffer_info->dma && buffer_info->page) {
553 print_hex_dump(KERN_INFO, "",
556 page_address(buffer_info->page) +
557 buffer_info->page_offset,
558 igb_rx_bufsz(rx_ring), true);
569 * igb_get_i2c_data - Reads the I2C SDA data bit
570 * @hw: pointer to hardware structure
571 * @i2cctl: Current value of I2CCTL register
573 * Returns the I2C data bit value
575 static int igb_get_i2c_data(void *data)
577 struct igb_adapter *adapter = (struct igb_adapter *)data;
578 struct e1000_hw *hw = &adapter->hw;
579 s32 i2cctl = rd32(E1000_I2CPARAMS);
581 return !!(i2cctl & E1000_I2C_DATA_IN);
585 * igb_set_i2c_data - Sets the I2C data bit
586 * @data: pointer to hardware structure
587 * @state: I2C data value (0 or 1) to set
589 * Sets the I2C data bit
591 static void igb_set_i2c_data(void *data, int state)
593 struct igb_adapter *adapter = (struct igb_adapter *)data;
594 struct e1000_hw *hw = &adapter->hw;
595 s32 i2cctl = rd32(E1000_I2CPARAMS);
598 i2cctl |= E1000_I2C_DATA_OUT;
600 i2cctl &= ~E1000_I2C_DATA_OUT;
602 i2cctl &= ~E1000_I2C_DATA_OE_N;
603 i2cctl |= E1000_I2C_CLK_OE_N;
604 wr32(E1000_I2CPARAMS, i2cctl);
610 * igb_set_i2c_clk - Sets the I2C SCL clock
611 * @data: pointer to hardware structure
612 * @state: state to set clock
614 * Sets the I2C clock line to state
616 static void igb_set_i2c_clk(void *data, int state)
618 struct igb_adapter *adapter = (struct igb_adapter *)data;
619 struct e1000_hw *hw = &adapter->hw;
620 s32 i2cctl = rd32(E1000_I2CPARAMS);
623 i2cctl |= E1000_I2C_CLK_OUT;
624 i2cctl &= ~E1000_I2C_CLK_OE_N;
626 i2cctl &= ~E1000_I2C_CLK_OUT;
627 i2cctl &= ~E1000_I2C_CLK_OE_N;
629 wr32(E1000_I2CPARAMS, i2cctl);
634 * igb_get_i2c_clk - Gets the I2C SCL clock state
635 * @data: pointer to hardware structure
637 * Gets the I2C clock state
639 static int igb_get_i2c_clk(void *data)
641 struct igb_adapter *adapter = (struct igb_adapter *)data;
642 struct e1000_hw *hw = &adapter->hw;
643 s32 i2cctl = rd32(E1000_I2CPARAMS);
645 return !!(i2cctl & E1000_I2C_CLK_IN);
648 static const struct i2c_algo_bit_data igb_i2c_algo = {
649 .setsda = igb_set_i2c_data,
650 .setscl = igb_set_i2c_clk,
651 .getsda = igb_get_i2c_data,
652 .getscl = igb_get_i2c_clk,
658 * igb_get_hw_dev - return device
659 * @hw: pointer to hardware structure
661 * used by hardware layer to print debugging information
663 struct net_device *igb_get_hw_dev(struct e1000_hw *hw)
665 struct igb_adapter *adapter = hw->back;
666 return adapter->netdev;
670 * igb_init_module - Driver Registration Routine
672 * igb_init_module is the first routine called when the driver is
673 * loaded. All it does is register with the PCI subsystem.
675 static int __init igb_init_module(void)
679 pr_info("%s - version %s\n",
680 igb_driver_string, igb_driver_version);
681 pr_info("%s\n", igb_copyright);
683 #ifdef CONFIG_IGB_DCA
684 dca_register_notify(&dca_notifier);
686 ret = pci_register_driver(&igb_driver);
690 module_init(igb_init_module);
693 * igb_exit_module - Driver Exit Cleanup Routine
695 * igb_exit_module is called just before the driver is removed
698 static void __exit igb_exit_module(void)
700 #ifdef CONFIG_IGB_DCA
701 dca_unregister_notify(&dca_notifier);
703 pci_unregister_driver(&igb_driver);
706 module_exit(igb_exit_module);
708 #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
710 * igb_cache_ring_register - Descriptor ring to register mapping
711 * @adapter: board private structure to initialize
713 * Once we know the feature-set enabled for the device, we'll cache
714 * the register offset the descriptor ring is assigned to.
716 static void igb_cache_ring_register(struct igb_adapter *adapter)
719 u32 rbase_offset = adapter->vfs_allocated_count;
721 switch (adapter->hw.mac.type) {
723 /* The queues are allocated for virtualization such that VF 0
724 * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
725 * In order to avoid collision we start at the first free queue
726 * and continue consuming queues in the same sequence
728 if (adapter->vfs_allocated_count) {
729 for (; i < adapter->rss_queues; i++)
730 adapter->rx_ring[i]->reg_idx = rbase_offset +
742 for (; i < adapter->num_rx_queues; i++)
743 adapter->rx_ring[i]->reg_idx = rbase_offset + i;
744 for (; j < adapter->num_tx_queues; j++)
745 adapter->tx_ring[j]->reg_idx = rbase_offset + j;
750 u32 igb_rd32(struct e1000_hw *hw, u32 reg)
752 struct igb_adapter *igb = container_of(hw, struct igb_adapter, hw);
753 u8 __iomem *hw_addr = ACCESS_ONCE(hw->hw_addr);
756 if (E1000_REMOVED(hw_addr))
759 value = readl(&hw_addr[reg]);
761 /* reads should not return all F's */
762 if (!(~value) && (!reg || !(~readl(hw_addr)))) {
763 struct net_device *netdev = igb->netdev;
765 netif_device_detach(netdev);
766 netdev_err(netdev, "PCIe link lost, device now detached\n");
773 * igb_write_ivar - configure ivar for given MSI-X vector
774 * @hw: pointer to the HW structure
775 * @msix_vector: vector number we are allocating to a given ring
776 * @index: row index of IVAR register to write within IVAR table
777 * @offset: column offset of in IVAR, should be multiple of 8
779 * This function is intended to handle the writing of the IVAR register
780 * for adapters 82576 and newer. The IVAR table consists of 2 columns,
781 * each containing an cause allocation for an Rx and Tx ring, and a
782 * variable number of rows depending on the number of queues supported.
784 static void igb_write_ivar(struct e1000_hw *hw, int msix_vector,
785 int index, int offset)
787 u32 ivar = array_rd32(E1000_IVAR0, index);
789 /* clear any bits that are currently set */
790 ivar &= ~((u32)0xFF << offset);
792 /* write vector and valid bit */
793 ivar |= (msix_vector | E1000_IVAR_VALID) << offset;
795 array_wr32(E1000_IVAR0, index, ivar);
798 #define IGB_N0_QUEUE -1
799 static void igb_assign_vector(struct igb_q_vector *q_vector, int msix_vector)
801 struct igb_adapter *adapter = q_vector->adapter;
802 struct e1000_hw *hw = &adapter->hw;
803 int rx_queue = IGB_N0_QUEUE;
804 int tx_queue = IGB_N0_QUEUE;
807 if (q_vector->rx.ring)
808 rx_queue = q_vector->rx.ring->reg_idx;
809 if (q_vector->tx.ring)
810 tx_queue = q_vector->tx.ring->reg_idx;
812 switch (hw->mac.type) {
814 /* The 82575 assigns vectors using a bitmask, which matches the
815 * bitmask for the EICR/EIMS/EIMC registers. To assign one
816 * or more queues to a vector, we write the appropriate bits
817 * into the MSIXBM register for that vector.
819 if (rx_queue > IGB_N0_QUEUE)
820 msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
821 if (tx_queue > IGB_N0_QUEUE)
822 msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
823 if (!(adapter->flags & IGB_FLAG_HAS_MSIX) && msix_vector == 0)
824 msixbm |= E1000_EIMS_OTHER;
825 array_wr32(E1000_MSIXBM(0), msix_vector, msixbm);
826 q_vector->eims_value = msixbm;
829 /* 82576 uses a table that essentially consists of 2 columns
830 * with 8 rows. The ordering is column-major so we use the
831 * lower 3 bits as the row index, and the 4th bit as the
834 if (rx_queue > IGB_N0_QUEUE)
835 igb_write_ivar(hw, msix_vector,
837 (rx_queue & 0x8) << 1);
838 if (tx_queue > IGB_N0_QUEUE)
839 igb_write_ivar(hw, msix_vector,
841 ((tx_queue & 0x8) << 1) + 8);
842 q_vector->eims_value = BIT(msix_vector);
849 /* On 82580 and newer adapters the scheme is similar to 82576
850 * however instead of ordering column-major we have things
851 * ordered row-major. So we traverse the table by using
852 * bit 0 as the column offset, and the remaining bits as the
855 if (rx_queue > IGB_N0_QUEUE)
856 igb_write_ivar(hw, msix_vector,
858 (rx_queue & 0x1) << 4);
859 if (tx_queue > IGB_N0_QUEUE)
860 igb_write_ivar(hw, msix_vector,
862 ((tx_queue & 0x1) << 4) + 8);
863 q_vector->eims_value = BIT(msix_vector);
870 /* add q_vector eims value to global eims_enable_mask */
871 adapter->eims_enable_mask |= q_vector->eims_value;
873 /* configure q_vector to set itr on first interrupt */
874 q_vector->set_itr = 1;
878 * igb_configure_msix - Configure MSI-X hardware
879 * @adapter: board private structure to initialize
881 * igb_configure_msix sets up the hardware to properly
882 * generate MSI-X interrupts.
884 static void igb_configure_msix(struct igb_adapter *adapter)
888 struct e1000_hw *hw = &adapter->hw;
890 adapter->eims_enable_mask = 0;
892 /* set vector for other causes, i.e. link changes */
893 switch (hw->mac.type) {
895 tmp = rd32(E1000_CTRL_EXT);
896 /* enable MSI-X PBA support*/
897 tmp |= E1000_CTRL_EXT_PBA_CLR;
899 /* Auto-Mask interrupts upon ICR read. */
900 tmp |= E1000_CTRL_EXT_EIAME;
901 tmp |= E1000_CTRL_EXT_IRCA;
903 wr32(E1000_CTRL_EXT, tmp);
905 /* enable msix_other interrupt */
906 array_wr32(E1000_MSIXBM(0), vector++, E1000_EIMS_OTHER);
907 adapter->eims_other = E1000_EIMS_OTHER;
917 /* Turn on MSI-X capability first, or our settings
918 * won't stick. And it will take days to debug.
920 wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE |
921 E1000_GPIE_PBA | E1000_GPIE_EIAME |
924 /* enable msix_other interrupt */
925 adapter->eims_other = BIT(vector);
926 tmp = (vector++ | E1000_IVAR_VALID) << 8;
928 wr32(E1000_IVAR_MISC, tmp);
931 /* do nothing, since nothing else supports MSI-X */
933 } /* switch (hw->mac.type) */
935 adapter->eims_enable_mask |= adapter->eims_other;
937 for (i = 0; i < adapter->num_q_vectors; i++)
938 igb_assign_vector(adapter->q_vector[i], vector++);
944 * igb_request_msix - Initialize MSI-X interrupts
945 * @adapter: board private structure to initialize
947 * igb_request_msix allocates MSI-X vectors and requests interrupts from the
950 static int igb_request_msix(struct igb_adapter *adapter)
952 unsigned int num_q_vectors = adapter->num_q_vectors;
953 struct net_device *netdev = adapter->netdev;
954 int i, err = 0, vector = 0, free_vector = 0;
956 err = request_irq(adapter->msix_entries[vector].vector,
957 igb_msix_other, 0, netdev->name, adapter);
961 if (num_q_vectors > MAX_Q_VECTORS) {
962 num_q_vectors = MAX_Q_VECTORS;
963 dev_warn(&adapter->pdev->dev,
964 "The number of queue vectors (%d) is higher than max allowed (%d)\n",
965 adapter->num_q_vectors, MAX_Q_VECTORS);
967 for (i = 0; i < num_q_vectors; i++) {
968 struct igb_q_vector *q_vector = adapter->q_vector[i];
972 q_vector->itr_register = adapter->io_addr + E1000_EITR(vector);
974 if (q_vector->rx.ring && q_vector->tx.ring)
975 sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
976 q_vector->rx.ring->queue_index);
977 else if (q_vector->tx.ring)
978 sprintf(q_vector->name, "%s-tx-%u", netdev->name,
979 q_vector->tx.ring->queue_index);
980 else if (q_vector->rx.ring)
981 sprintf(q_vector->name, "%s-rx-%u", netdev->name,
982 q_vector->rx.ring->queue_index);
984 sprintf(q_vector->name, "%s-unused", netdev->name);
986 err = request_irq(adapter->msix_entries[vector].vector,
987 igb_msix_ring, 0, q_vector->name,
993 igb_configure_msix(adapter);
997 /* free already assigned IRQs */
998 free_irq(adapter->msix_entries[free_vector++].vector, adapter);
1001 for (i = 0; i < vector; i++) {
1002 free_irq(adapter->msix_entries[free_vector++].vector,
1003 adapter->q_vector[i]);
1010 * igb_free_q_vector - Free memory allocated for specific interrupt vector
1011 * @adapter: board private structure to initialize
1012 * @v_idx: Index of vector to be freed
1014 * This function frees the memory allocated to the q_vector.
1016 static void igb_free_q_vector(struct igb_adapter *adapter, int v_idx)
1018 struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
1020 adapter->q_vector[v_idx] = NULL;
1022 /* igb_get_stats64() might access the rings on this vector,
1023 * we must wait a grace period before freeing it.
1026 kfree_rcu(q_vector, rcu);
1030 * igb_reset_q_vector - Reset config for interrupt vector
1031 * @adapter: board private structure to initialize
1032 * @v_idx: Index of vector to be reset
1034 * If NAPI is enabled it will delete any references to the
1035 * NAPI struct. This is preparation for igb_free_q_vector.
1037 static void igb_reset_q_vector(struct igb_adapter *adapter, int v_idx)
1039 struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
1041 /* Coming from igb_set_interrupt_capability, the vectors are not yet
1042 * allocated. So, q_vector is NULL so we should stop here.
1047 if (q_vector->tx.ring)
1048 adapter->tx_ring[q_vector->tx.ring->queue_index] = NULL;
1050 if (q_vector->rx.ring)
1051 adapter->rx_ring[q_vector->rx.ring->queue_index] = NULL;
1053 netif_napi_del(&q_vector->napi);
1057 static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
1059 int v_idx = adapter->num_q_vectors;
1061 if (adapter->flags & IGB_FLAG_HAS_MSIX)
1062 pci_disable_msix(adapter->pdev);
1063 else if (adapter->flags & IGB_FLAG_HAS_MSI)
1064 pci_disable_msi(adapter->pdev);
1067 igb_reset_q_vector(adapter, v_idx);
1071 * igb_free_q_vectors - Free memory allocated for interrupt vectors
1072 * @adapter: board private structure to initialize
1074 * This function frees the memory allocated to the q_vectors. In addition if
1075 * NAPI is enabled it will delete any references to the NAPI struct prior
1076 * to freeing the q_vector.
1078 static void igb_free_q_vectors(struct igb_adapter *adapter)
1080 int v_idx = adapter->num_q_vectors;
1082 adapter->num_tx_queues = 0;
1083 adapter->num_rx_queues = 0;
1084 adapter->num_q_vectors = 0;
1087 igb_reset_q_vector(adapter, v_idx);
1088 igb_free_q_vector(adapter, v_idx);
1093 * igb_clear_interrupt_scheme - reset the device to a state of no interrupts
1094 * @adapter: board private structure to initialize
1096 * This function resets the device so that it has 0 Rx queues, Tx queues, and
1097 * MSI-X interrupts allocated.
1099 static void igb_clear_interrupt_scheme(struct igb_adapter *adapter)
1101 igb_free_q_vectors(adapter);
1102 igb_reset_interrupt_capability(adapter);
1106 * igb_set_interrupt_capability - set MSI or MSI-X if supported
1107 * @adapter: board private structure to initialize
1108 * @msix: boolean value of MSIX capability
1110 * Attempt to configure interrupts using the best available
1111 * capabilities of the hardware and kernel.
1113 static void igb_set_interrupt_capability(struct igb_adapter *adapter, bool msix)
1120 adapter->flags |= IGB_FLAG_HAS_MSIX;
1122 /* Number of supported queues. */
1123 adapter->num_rx_queues = adapter->rss_queues;
1124 if (adapter->vfs_allocated_count)
1125 adapter->num_tx_queues = 1;
1127 adapter->num_tx_queues = adapter->rss_queues;
1129 /* start with one vector for every Rx queue */
1130 numvecs = adapter->num_rx_queues;
1132 /* if Tx handler is separate add 1 for every Tx queue */
1133 if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS))
1134 numvecs += adapter->num_tx_queues;
1136 /* store the number of vectors reserved for queues */
1137 adapter->num_q_vectors = numvecs;
1139 /* add 1 vector for link status interrupts */
1141 for (i = 0; i < numvecs; i++)
1142 adapter->msix_entries[i].entry = i;
1144 err = pci_enable_msix_range(adapter->pdev,
1145 adapter->msix_entries,
1151 igb_reset_interrupt_capability(adapter);
1153 /* If we can't do MSI-X, try MSI */
1155 adapter->flags &= ~IGB_FLAG_HAS_MSIX;
1156 #ifdef CONFIG_PCI_IOV
1157 /* disable SR-IOV for non MSI-X configurations */
1158 if (adapter->vf_data) {
1159 struct e1000_hw *hw = &adapter->hw;
1160 /* disable iov and allow time for transactions to clear */
1161 pci_disable_sriov(adapter->pdev);
1164 kfree(adapter->vf_mac_list);
1165 adapter->vf_mac_list = NULL;
1166 kfree(adapter->vf_data);
1167 adapter->vf_data = NULL;
1168 wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
1171 dev_info(&adapter->pdev->dev, "IOV Disabled\n");
1174 adapter->vfs_allocated_count = 0;
1175 adapter->rss_queues = 1;
1176 adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
1177 adapter->num_rx_queues = 1;
1178 adapter->num_tx_queues = 1;
1179 adapter->num_q_vectors = 1;
1180 if (!pci_enable_msi(adapter->pdev))
1181 adapter->flags |= IGB_FLAG_HAS_MSI;
1184 static void igb_add_ring(struct igb_ring *ring,
1185 struct igb_ring_container *head)
1192 * igb_alloc_q_vector - Allocate memory for a single interrupt vector
1193 * @adapter: board private structure to initialize
1194 * @v_count: q_vectors allocated on adapter, used for ring interleaving
1195 * @v_idx: index of vector in adapter struct
1196 * @txr_count: total number of Tx rings to allocate
1197 * @txr_idx: index of first Tx ring to allocate
1198 * @rxr_count: total number of Rx rings to allocate
1199 * @rxr_idx: index of first Rx ring to allocate
1201 * We allocate one q_vector. If allocation fails we return -ENOMEM.
1203 static int igb_alloc_q_vector(struct igb_adapter *adapter,
1204 int v_count, int v_idx,
1205 int txr_count, int txr_idx,
1206 int rxr_count, int rxr_idx)
1208 struct igb_q_vector *q_vector;
1209 struct igb_ring *ring;
1210 int ring_count, size;
1212 /* igb only supports 1 Tx and/or 1 Rx queue per vector */
1213 if (txr_count > 1 || rxr_count > 1)
1216 ring_count = txr_count + rxr_count;
1217 size = sizeof(struct igb_q_vector) +
1218 (sizeof(struct igb_ring) * ring_count);
1220 /* allocate q_vector and rings */
1221 q_vector = adapter->q_vector[v_idx];
1223 q_vector = kzalloc(size, GFP_KERNEL);
1224 } else if (size > ksize(q_vector)) {
1225 kfree_rcu(q_vector, rcu);
1226 q_vector = kzalloc(size, GFP_KERNEL);
1228 memset(q_vector, 0, size);
1233 /* initialize NAPI */
1234 netif_napi_add(adapter->netdev, &q_vector->napi,
1237 /* tie q_vector and adapter together */
1238 adapter->q_vector[v_idx] = q_vector;
1239 q_vector->adapter = adapter;
1241 /* initialize work limits */
1242 q_vector->tx.work_limit = adapter->tx_work_limit;
1244 /* initialize ITR configuration */
1245 q_vector->itr_register = adapter->io_addr + E1000_EITR(0);
1246 q_vector->itr_val = IGB_START_ITR;
1248 /* initialize pointer to rings */
1249 ring = q_vector->ring;
1253 /* rx or rx/tx vector */
1254 if (!adapter->rx_itr_setting || adapter->rx_itr_setting > 3)
1255 q_vector->itr_val = adapter->rx_itr_setting;
1257 /* tx only vector */
1258 if (!adapter->tx_itr_setting || adapter->tx_itr_setting > 3)
1259 q_vector->itr_val = adapter->tx_itr_setting;
1263 /* assign generic ring traits */
1264 ring->dev = &adapter->pdev->dev;
1265 ring->netdev = adapter->netdev;
1267 /* configure backlink on ring */
1268 ring->q_vector = q_vector;
1270 /* update q_vector Tx values */
1271 igb_add_ring(ring, &q_vector->tx);
1273 /* For 82575, context index must be unique per ring. */
1274 if (adapter->hw.mac.type == e1000_82575)
1275 set_bit(IGB_RING_FLAG_TX_CTX_IDX, &ring->flags);
1277 /* apply Tx specific ring traits */
1278 ring->count = adapter->tx_ring_count;
1279 ring->queue_index = txr_idx;
1281 u64_stats_init(&ring->tx_syncp);
1282 u64_stats_init(&ring->tx_syncp2);
1284 /* assign ring to adapter */
1285 adapter->tx_ring[txr_idx] = ring;
1287 /* push pointer to next ring */
1292 /* assign generic ring traits */
1293 ring->dev = &adapter->pdev->dev;
1294 ring->netdev = adapter->netdev;
1296 /* configure backlink on ring */
1297 ring->q_vector = q_vector;
1299 /* update q_vector Rx values */
1300 igb_add_ring(ring, &q_vector->rx);
1302 /* set flag indicating ring supports SCTP checksum offload */
1303 if (adapter->hw.mac.type >= e1000_82576)
1304 set_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags);
1306 /* On i350, i354, i210, and i211, loopback VLAN packets
1307 * have the tag byte-swapped.
1309 if (adapter->hw.mac.type >= e1000_i350)
1310 set_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &ring->flags);
1312 /* apply Rx specific ring traits */
1313 ring->count = adapter->rx_ring_count;
1314 ring->queue_index = rxr_idx;
1316 u64_stats_init(&ring->rx_syncp);
1318 /* assign ring to adapter */
1319 adapter->rx_ring[rxr_idx] = ring;
1327 * igb_alloc_q_vectors - Allocate memory for interrupt vectors
1328 * @adapter: board private structure to initialize
1330 * We allocate one q_vector per queue interrupt. If allocation fails we
1333 static int igb_alloc_q_vectors(struct igb_adapter *adapter)
1335 int q_vectors = adapter->num_q_vectors;
1336 int rxr_remaining = adapter->num_rx_queues;
1337 int txr_remaining = adapter->num_tx_queues;
1338 int rxr_idx = 0, txr_idx = 0, v_idx = 0;
1341 if (q_vectors >= (rxr_remaining + txr_remaining)) {
1342 for (; rxr_remaining; v_idx++) {
1343 err = igb_alloc_q_vector(adapter, q_vectors, v_idx,
1349 /* update counts and index */
1355 for (; v_idx < q_vectors; v_idx++) {
1356 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_idx);
1357 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_idx);
1359 err = igb_alloc_q_vector(adapter, q_vectors, v_idx,
1360 tqpv, txr_idx, rqpv, rxr_idx);
1365 /* update counts and index */
1366 rxr_remaining -= rqpv;
1367 txr_remaining -= tqpv;
1375 adapter->num_tx_queues = 0;
1376 adapter->num_rx_queues = 0;
1377 adapter->num_q_vectors = 0;
1380 igb_free_q_vector(adapter, v_idx);
1386 * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors
1387 * @adapter: board private structure to initialize
1388 * @msix: boolean value of MSIX capability
1390 * This function initializes the interrupts and allocates all of the queues.
1392 static int igb_init_interrupt_scheme(struct igb_adapter *adapter, bool msix)
1394 struct pci_dev *pdev = adapter->pdev;
1397 igb_set_interrupt_capability(adapter, msix);
1399 err = igb_alloc_q_vectors(adapter);
1401 dev_err(&pdev->dev, "Unable to allocate memory for vectors\n");
1402 goto err_alloc_q_vectors;
1405 igb_cache_ring_register(adapter);
1409 err_alloc_q_vectors:
1410 igb_reset_interrupt_capability(adapter);
1415 * igb_request_irq - initialize interrupts
1416 * @adapter: board private structure to initialize
1418 * Attempts to configure interrupts using the best available
1419 * capabilities of the hardware and kernel.
1421 static int igb_request_irq(struct igb_adapter *adapter)
1423 struct net_device *netdev = adapter->netdev;
1424 struct pci_dev *pdev = adapter->pdev;
1427 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1428 err = igb_request_msix(adapter);
1431 /* fall back to MSI */
1432 igb_free_all_tx_resources(adapter);
1433 igb_free_all_rx_resources(adapter);
1435 igb_clear_interrupt_scheme(adapter);
1436 err = igb_init_interrupt_scheme(adapter, false);
1440 igb_setup_all_tx_resources(adapter);
1441 igb_setup_all_rx_resources(adapter);
1442 igb_configure(adapter);
1445 igb_assign_vector(adapter->q_vector[0], 0);
1447 if (adapter->flags & IGB_FLAG_HAS_MSI) {
1448 err = request_irq(pdev->irq, igb_intr_msi, 0,
1449 netdev->name, adapter);
1453 /* fall back to legacy interrupts */
1454 igb_reset_interrupt_capability(adapter);
1455 adapter->flags &= ~IGB_FLAG_HAS_MSI;
1458 err = request_irq(pdev->irq, igb_intr, IRQF_SHARED,
1459 netdev->name, adapter);
1462 dev_err(&pdev->dev, "Error %d getting interrupt\n",
1469 static void igb_free_irq(struct igb_adapter *adapter)
1471 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1474 free_irq(adapter->msix_entries[vector++].vector, adapter);
1476 for (i = 0; i < adapter->num_q_vectors; i++)
1477 free_irq(adapter->msix_entries[vector++].vector,
1478 adapter->q_vector[i]);
1480 free_irq(adapter->pdev->irq, adapter);
1485 * igb_irq_disable - Mask off interrupt generation on the NIC
1486 * @adapter: board private structure
1488 static void igb_irq_disable(struct igb_adapter *adapter)
1490 struct e1000_hw *hw = &adapter->hw;
1492 /* we need to be careful when disabling interrupts. The VFs are also
1493 * mapped into these registers and so clearing the bits can cause
1494 * issues on the VF drivers so we only need to clear what we set
1496 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1497 u32 regval = rd32(E1000_EIAM);
1499 wr32(E1000_EIAM, regval & ~adapter->eims_enable_mask);
1500 wr32(E1000_EIMC, adapter->eims_enable_mask);
1501 regval = rd32(E1000_EIAC);
1502 wr32(E1000_EIAC, regval & ~adapter->eims_enable_mask);
1506 wr32(E1000_IMC, ~0);
1508 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1511 for (i = 0; i < adapter->num_q_vectors; i++)
1512 synchronize_irq(adapter->msix_entries[i].vector);
1514 synchronize_irq(adapter->pdev->irq);
1519 * igb_irq_enable - Enable default interrupt generation settings
1520 * @adapter: board private structure
1522 static void igb_irq_enable(struct igb_adapter *adapter)
1524 struct e1000_hw *hw = &adapter->hw;
1526 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1527 u32 ims = E1000_IMS_LSC | E1000_IMS_DOUTSYNC | E1000_IMS_DRSTA;
1528 u32 regval = rd32(E1000_EIAC);
1530 wr32(E1000_EIAC, regval | adapter->eims_enable_mask);
1531 regval = rd32(E1000_EIAM);
1532 wr32(E1000_EIAM, regval | adapter->eims_enable_mask);
1533 wr32(E1000_EIMS, adapter->eims_enable_mask);
1534 if (adapter->vfs_allocated_count) {
1535 wr32(E1000_MBVFIMR, 0xFF);
1536 ims |= E1000_IMS_VMMB;
1538 wr32(E1000_IMS, ims);
1540 wr32(E1000_IMS, IMS_ENABLE_MASK |
1542 wr32(E1000_IAM, IMS_ENABLE_MASK |
1547 static void igb_update_mng_vlan(struct igb_adapter *adapter)
1549 struct e1000_hw *hw = &adapter->hw;
1550 u16 pf_id = adapter->vfs_allocated_count;
1551 u16 vid = adapter->hw.mng_cookie.vlan_id;
1552 u16 old_vid = adapter->mng_vlan_id;
1554 if (hw->mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
1555 /* add VID to filter table */
1556 igb_vfta_set(hw, vid, pf_id, true, true);
1557 adapter->mng_vlan_id = vid;
1559 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
1562 if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
1564 !test_bit(old_vid, adapter->active_vlans)) {
1565 /* remove VID from filter table */
1566 igb_vfta_set(hw, vid, pf_id, false, true);
1571 * igb_release_hw_control - release control of the h/w to f/w
1572 * @adapter: address of board private structure
1574 * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
1575 * For ASF and Pass Through versions of f/w this means that the
1576 * driver is no longer loaded.
1578 static void igb_release_hw_control(struct igb_adapter *adapter)
1580 struct e1000_hw *hw = &adapter->hw;
1583 /* Let firmware take over control of h/w */
1584 ctrl_ext = rd32(E1000_CTRL_EXT);
1585 wr32(E1000_CTRL_EXT,
1586 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1590 * igb_get_hw_control - get control of the h/w from f/w
1591 * @adapter: address of board private structure
1593 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
1594 * For ASF and Pass Through versions of f/w this means that
1595 * the driver is loaded.
1597 static void igb_get_hw_control(struct igb_adapter *adapter)
1599 struct e1000_hw *hw = &adapter->hw;
1602 /* Let firmware know the driver has taken over */
1603 ctrl_ext = rd32(E1000_CTRL_EXT);
1604 wr32(E1000_CTRL_EXT,
1605 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1609 * igb_configure - configure the hardware for RX and TX
1610 * @adapter: private board structure
1612 static void igb_configure(struct igb_adapter *adapter)
1614 struct net_device *netdev = adapter->netdev;
1617 igb_get_hw_control(adapter);
1618 igb_set_rx_mode(netdev);
1620 igb_restore_vlan(adapter);
1622 igb_setup_tctl(adapter);
1623 igb_setup_mrqc(adapter);
1624 igb_setup_rctl(adapter);
1626 igb_nfc_filter_restore(adapter);
1627 igb_configure_tx(adapter);
1628 igb_configure_rx(adapter);
1630 igb_rx_fifo_flush_82575(&adapter->hw);
1632 /* call igb_desc_unused which always leaves
1633 * at least 1 descriptor unused to make sure
1634 * next_to_use != next_to_clean
1636 for (i = 0; i < adapter->num_rx_queues; i++) {
1637 struct igb_ring *ring = adapter->rx_ring[i];
1638 igb_alloc_rx_buffers(ring, igb_desc_unused(ring));
1643 * igb_power_up_link - Power up the phy/serdes link
1644 * @adapter: address of board private structure
1646 void igb_power_up_link(struct igb_adapter *adapter)
1648 igb_reset_phy(&adapter->hw);
1650 if (adapter->hw.phy.media_type == e1000_media_type_copper)
1651 igb_power_up_phy_copper(&adapter->hw);
1653 igb_power_up_serdes_link_82575(&adapter->hw);
1655 igb_setup_link(&adapter->hw);
1659 * igb_power_down_link - Power down the phy/serdes link
1660 * @adapter: address of board private structure
1662 static void igb_power_down_link(struct igb_adapter *adapter)
1664 if (adapter->hw.phy.media_type == e1000_media_type_copper)
1665 igb_power_down_phy_copper_82575(&adapter->hw);
1667 igb_shutdown_serdes_link_82575(&adapter->hw);
1671 * Detect and switch function for Media Auto Sense
1672 * @adapter: address of the board private structure
1674 static void igb_check_swap_media(struct igb_adapter *adapter)
1676 struct e1000_hw *hw = &adapter->hw;
1677 u32 ctrl_ext, connsw;
1678 bool swap_now = false;
1680 ctrl_ext = rd32(E1000_CTRL_EXT);
1681 connsw = rd32(E1000_CONNSW);
1683 /* need to live swap if current media is copper and we have fiber/serdes
1687 if ((hw->phy.media_type == e1000_media_type_copper) &&
1688 (!(connsw & E1000_CONNSW_AUTOSENSE_EN))) {
1690 } else if ((hw->phy.media_type != e1000_media_type_copper) &&
1691 !(connsw & E1000_CONNSW_SERDESD)) {
1692 /* copper signal takes time to appear */
1693 if (adapter->copper_tries < 4) {
1694 adapter->copper_tries++;
1695 connsw |= E1000_CONNSW_AUTOSENSE_CONF;
1696 wr32(E1000_CONNSW, connsw);
1699 adapter->copper_tries = 0;
1700 if ((connsw & E1000_CONNSW_PHYSD) &&
1701 (!(connsw & E1000_CONNSW_PHY_PDN))) {
1703 connsw &= ~E1000_CONNSW_AUTOSENSE_CONF;
1704 wr32(E1000_CONNSW, connsw);
1712 switch (hw->phy.media_type) {
1713 case e1000_media_type_copper:
1714 netdev_info(adapter->netdev,
1715 "MAS: changing media to fiber/serdes\n");
1717 E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1718 adapter->flags |= IGB_FLAG_MEDIA_RESET;
1719 adapter->copper_tries = 0;
1721 case e1000_media_type_internal_serdes:
1722 case e1000_media_type_fiber:
1723 netdev_info(adapter->netdev,
1724 "MAS: changing media to copper\n");
1726 ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1727 adapter->flags |= IGB_FLAG_MEDIA_RESET;
1730 /* shouldn't get here during regular operation */
1731 netdev_err(adapter->netdev,
1732 "AMS: Invalid media type found, returning\n");
1735 wr32(E1000_CTRL_EXT, ctrl_ext);
1739 * igb_up - Open the interface and prepare it to handle traffic
1740 * @adapter: board private structure
1742 int igb_up(struct igb_adapter *adapter)
1744 struct e1000_hw *hw = &adapter->hw;
1747 /* hardware has been reset, we need to reload some things */
1748 igb_configure(adapter);
1750 clear_bit(__IGB_DOWN, &adapter->state);
1752 for (i = 0; i < adapter->num_q_vectors; i++)
1753 napi_enable(&(adapter->q_vector[i]->napi));
1755 if (adapter->flags & IGB_FLAG_HAS_MSIX)
1756 igb_configure_msix(adapter);
1758 igb_assign_vector(adapter->q_vector[0], 0);
1760 /* Clear any pending interrupts. */
1762 igb_irq_enable(adapter);
1764 /* notify VFs that reset has been completed */
1765 if (adapter->vfs_allocated_count) {
1766 u32 reg_data = rd32(E1000_CTRL_EXT);
1768 reg_data |= E1000_CTRL_EXT_PFRSTD;
1769 wr32(E1000_CTRL_EXT, reg_data);
1772 netif_tx_start_all_queues(adapter->netdev);
1774 /* start the watchdog. */
1775 hw->mac.get_link_status = 1;
1776 schedule_work(&adapter->watchdog_task);
1778 if ((adapter->flags & IGB_FLAG_EEE) &&
1779 (!hw->dev_spec._82575.eee_disable))
1780 adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
1785 void igb_down(struct igb_adapter *adapter)
1787 struct net_device *netdev = adapter->netdev;
1788 struct e1000_hw *hw = &adapter->hw;
1792 /* signal that we're down so the interrupt handler does not
1793 * reschedule our watchdog timer
1795 set_bit(__IGB_DOWN, &adapter->state);
1797 /* disable receives in the hardware */
1798 rctl = rd32(E1000_RCTL);
1799 wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
1800 /* flush and sleep below */
1802 igb_nfc_filter_exit(adapter);
1804 netif_carrier_off(netdev);
1805 netif_tx_stop_all_queues(netdev);
1807 /* disable transmits in the hardware */
1808 tctl = rd32(E1000_TCTL);
1809 tctl &= ~E1000_TCTL_EN;
1810 wr32(E1000_TCTL, tctl);
1811 /* flush both disables and wait for them to finish */
1813 usleep_range(10000, 11000);
1815 igb_irq_disable(adapter);
1817 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
1819 for (i = 0; i < adapter->num_q_vectors; i++) {
1820 if (adapter->q_vector[i]) {
1821 napi_synchronize(&adapter->q_vector[i]->napi);
1822 napi_disable(&adapter->q_vector[i]->napi);
1826 del_timer_sync(&adapter->watchdog_timer);
1827 del_timer_sync(&adapter->phy_info_timer);
1829 /* record the stats before reset*/
1830 spin_lock(&adapter->stats64_lock);
1831 igb_update_stats(adapter);
1832 spin_unlock(&adapter->stats64_lock);
1834 adapter->link_speed = 0;
1835 adapter->link_duplex = 0;
1837 if (!pci_channel_offline(adapter->pdev))
1840 /* clear VLAN promisc flag so VFTA will be updated if necessary */
1841 adapter->flags &= ~IGB_FLAG_VLAN_PROMISC;
1843 igb_clean_all_tx_rings(adapter);
1844 igb_clean_all_rx_rings(adapter);
1845 #ifdef CONFIG_IGB_DCA
1847 /* since we reset the hardware DCA settings were cleared */
1848 igb_setup_dca(adapter);
1852 void igb_reinit_locked(struct igb_adapter *adapter)
1854 WARN_ON(in_interrupt());
1855 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
1856 usleep_range(1000, 2000);
1859 clear_bit(__IGB_RESETTING, &adapter->state);
1862 /** igb_enable_mas - Media Autosense re-enable after swap
1864 * @adapter: adapter struct
1866 static void igb_enable_mas(struct igb_adapter *adapter)
1868 struct e1000_hw *hw = &adapter->hw;
1869 u32 connsw = rd32(E1000_CONNSW);
1871 /* configure for SerDes media detect */
1872 if ((hw->phy.media_type == e1000_media_type_copper) &&
1873 (!(connsw & E1000_CONNSW_SERDESD))) {
1874 connsw |= E1000_CONNSW_ENRGSRC;
1875 connsw |= E1000_CONNSW_AUTOSENSE_EN;
1876 wr32(E1000_CONNSW, connsw);
1881 void igb_reset(struct igb_adapter *adapter)
1883 struct pci_dev *pdev = adapter->pdev;
1884 struct e1000_hw *hw = &adapter->hw;
1885 struct e1000_mac_info *mac = &hw->mac;
1886 struct e1000_fc_info *fc = &hw->fc;
1889 /* Repartition Pba for greater than 9k mtu
1890 * To take effect CTRL.RST is required.
1892 switch (mac->type) {
1896 pba = rd32(E1000_RXPBS);
1897 pba = igb_rxpbs_adjust_82580(pba);
1900 pba = rd32(E1000_RXPBS);
1901 pba &= E1000_RXPBS_SIZE_MASK_82576;
1907 pba = E1000_PBA_34K;
1911 if (mac->type == e1000_82575) {
1912 u32 min_rx_space, min_tx_space, needed_tx_space;
1914 /* write Rx PBA so that hardware can report correct Tx PBA */
1915 wr32(E1000_PBA, pba);
1917 /* To maintain wire speed transmits, the Tx FIFO should be
1918 * large enough to accommodate two full transmit packets,
1919 * rounded up to the next 1KB and expressed in KB. Likewise,
1920 * the Rx FIFO should be large enough to accommodate at least
1921 * one full receive packet and is similarly rounded up and
1924 min_rx_space = DIV_ROUND_UP(MAX_JUMBO_FRAME_SIZE, 1024);
1926 /* The Tx FIFO also stores 16 bytes of information about the Tx
1927 * but don't include Ethernet FCS because hardware appends it.
1928 * We only need to round down to the nearest 512 byte block
1929 * count since the value we care about is 2 frames, not 1.
1931 min_tx_space = adapter->max_frame_size;
1932 min_tx_space += sizeof(union e1000_adv_tx_desc) - ETH_FCS_LEN;
1933 min_tx_space = DIV_ROUND_UP(min_tx_space, 512);
1935 /* upper 16 bits has Tx packet buffer allocation size in KB */
1936 needed_tx_space = min_tx_space - (rd32(E1000_PBA) >> 16);
1938 /* If current Tx allocation is less than the min Tx FIFO size,
1939 * and the min Tx FIFO size is less than the current Rx FIFO
1940 * allocation, take space away from current Rx allocation.
1942 if (needed_tx_space < pba) {
1943 pba -= needed_tx_space;
1945 /* if short on Rx space, Rx wins and must trump Tx
1948 if (pba < min_rx_space)
1952 /* adjust PBA for jumbo frames */
1953 wr32(E1000_PBA, pba);
1956 /* flow control settings
1957 * The high water mark must be low enough to fit one full frame
1958 * after transmitting the pause frame. As such we must have enough
1959 * space to allow for us to complete our current transmit and then
1960 * receive the frame that is in progress from the link partner.
1962 * - the full Rx FIFO size minus one full Tx plus one full Rx frame
1964 hwm = (pba << 10) - (adapter->max_frame_size + MAX_JUMBO_FRAME_SIZE);
1966 fc->high_water = hwm & 0xFFFFFFF0; /* 16-byte granularity */
1967 fc->low_water = fc->high_water - 16;
1968 fc->pause_time = 0xFFFF;
1970 fc->current_mode = fc->requested_mode;
1972 /* disable receive for all VFs and wait one second */
1973 if (adapter->vfs_allocated_count) {
1976 for (i = 0 ; i < adapter->vfs_allocated_count; i++)
1977 adapter->vf_data[i].flags &= IGB_VF_FLAG_PF_SET_MAC;
1979 /* ping all the active vfs to let them know we are going down */
1980 igb_ping_all_vfs(adapter);
1982 /* disable transmits and receives */
1983 wr32(E1000_VFRE, 0);
1984 wr32(E1000_VFTE, 0);
1987 /* Allow time for pending master requests to run */
1988 hw->mac.ops.reset_hw(hw);
1991 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
1992 /* need to resetup here after media swap */
1993 adapter->ei.get_invariants(hw);
1994 adapter->flags &= ~IGB_FLAG_MEDIA_RESET;
1996 if ((mac->type == e1000_82575) &&
1997 (adapter->flags & IGB_FLAG_MAS_ENABLE)) {
1998 igb_enable_mas(adapter);
2000 if (hw->mac.ops.init_hw(hw))
2001 dev_err(&pdev->dev, "Hardware Error\n");
2003 /* RAR registers were cleared during init_hw, clear mac table */
2004 igb_flush_mac_table(adapter);
2005 __dev_uc_unsync(adapter->netdev, NULL);
2007 /* Recover default RAR entry */
2008 igb_set_default_mac_filter(adapter);
2010 /* Flow control settings reset on hardware reset, so guarantee flow
2011 * control is off when forcing speed.
2013 if (!hw->mac.autoneg)
2014 igb_force_mac_fc(hw);
2016 igb_init_dmac(adapter, pba);
2017 #ifdef CONFIG_IGB_HWMON
2018 /* Re-initialize the thermal sensor on i350 devices. */
2019 if (!test_bit(__IGB_DOWN, &adapter->state)) {
2020 if (mac->type == e1000_i350 && hw->bus.func == 0) {
2021 /* If present, re-initialize the external thermal sensor
2025 mac->ops.init_thermal_sensor_thresh(hw);
2029 /* Re-establish EEE setting */
2030 if (hw->phy.media_type == e1000_media_type_copper) {
2031 switch (mac->type) {
2035 igb_set_eee_i350(hw, true, true);
2038 igb_set_eee_i354(hw, true, true);
2044 if (!netif_running(adapter->netdev))
2045 igb_power_down_link(adapter);
2047 igb_update_mng_vlan(adapter);
2049 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2050 wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
2052 /* Re-enable PTP, where applicable. */
2053 if (adapter->ptp_flags & IGB_PTP_ENABLED)
2054 igb_ptp_reset(adapter);
2056 igb_get_phy_info(hw);
2059 static netdev_features_t igb_fix_features(struct net_device *netdev,
2060 netdev_features_t features)
2062 /* Since there is no support for separate Rx/Tx vlan accel
2063 * enable/disable make sure Tx flag is always in same state as Rx.
2065 if (features & NETIF_F_HW_VLAN_CTAG_RX)
2066 features |= NETIF_F_HW_VLAN_CTAG_TX;
2068 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
2073 static int igb_set_features(struct net_device *netdev,
2074 netdev_features_t features)
2076 netdev_features_t changed = netdev->features ^ features;
2077 struct igb_adapter *adapter = netdev_priv(netdev);
2079 if (changed & NETIF_F_HW_VLAN_CTAG_RX)
2080 igb_vlan_mode(netdev, features);
2082 if (!(changed & (NETIF_F_RXALL | NETIF_F_NTUPLE)))
2085 if (!(features & NETIF_F_NTUPLE)) {
2086 struct hlist_node *node2;
2087 struct igb_nfc_filter *rule;
2089 spin_lock(&adapter->nfc_lock);
2090 hlist_for_each_entry_safe(rule, node2,
2091 &adapter->nfc_filter_list, nfc_node) {
2092 igb_erase_filter(adapter, rule);
2093 hlist_del(&rule->nfc_node);
2096 spin_unlock(&adapter->nfc_lock);
2097 adapter->nfc_filter_count = 0;
2100 netdev->features = features;
2102 if (netif_running(netdev))
2103 igb_reinit_locked(adapter);
2110 static int igb_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
2111 struct net_device *dev,
2112 const unsigned char *addr, u16 vid,
2115 /* guarantee we can provide a unique filter for the unicast address */
2116 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
2117 struct igb_adapter *adapter = netdev_priv(dev);
2118 int vfn = adapter->vfs_allocated_count;
2120 if (netdev_uc_count(dev) >= igb_available_rars(adapter, vfn))
2124 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
2127 #define IGB_MAX_MAC_HDR_LEN 127
2128 #define IGB_MAX_NETWORK_HDR_LEN 511
2130 static netdev_features_t
2131 igb_features_check(struct sk_buff *skb, struct net_device *dev,
2132 netdev_features_t features)
2134 unsigned int network_hdr_len, mac_hdr_len;
2136 /* Make certain the headers can be described by a context descriptor */
2137 mac_hdr_len = skb_network_header(skb) - skb->data;
2138 if (unlikely(mac_hdr_len > IGB_MAX_MAC_HDR_LEN))
2139 return features & ~(NETIF_F_HW_CSUM |
2141 NETIF_F_HW_VLAN_CTAG_TX |
2145 network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
2146 if (unlikely(network_hdr_len > IGB_MAX_NETWORK_HDR_LEN))
2147 return features & ~(NETIF_F_HW_CSUM |
2152 /* We can only support IPV4 TSO in tunnels if we can mangle the
2153 * inner IP ID field, so strip TSO if MANGLEID is not supported.
2155 if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
2156 features &= ~NETIF_F_TSO;
2161 static const struct net_device_ops igb_netdev_ops = {
2162 .ndo_open = igb_open,
2163 .ndo_stop = igb_close,
2164 .ndo_start_xmit = igb_xmit_frame,
2165 .ndo_get_stats64 = igb_get_stats64,
2166 .ndo_set_rx_mode = igb_set_rx_mode,
2167 .ndo_set_mac_address = igb_set_mac,
2168 .ndo_change_mtu = igb_change_mtu,
2169 .ndo_do_ioctl = igb_ioctl,
2170 .ndo_tx_timeout = igb_tx_timeout,
2171 .ndo_validate_addr = eth_validate_addr,
2172 .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid,
2173 .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid,
2174 .ndo_set_vf_mac = igb_ndo_set_vf_mac,
2175 .ndo_set_vf_vlan = igb_ndo_set_vf_vlan,
2176 .ndo_set_vf_rate = igb_ndo_set_vf_bw,
2177 .ndo_set_vf_spoofchk = igb_ndo_set_vf_spoofchk,
2178 .ndo_get_vf_config = igb_ndo_get_vf_config,
2179 #ifdef CONFIG_NET_POLL_CONTROLLER
2180 .ndo_poll_controller = igb_netpoll,
2182 .ndo_fix_features = igb_fix_features,
2183 .ndo_set_features = igb_set_features,
2184 .ndo_fdb_add = igb_ndo_fdb_add,
2185 .ndo_features_check = igb_features_check,
2189 * igb_set_fw_version - Configure version string for ethtool
2190 * @adapter: adapter struct
2192 void igb_set_fw_version(struct igb_adapter *adapter)
2194 struct e1000_hw *hw = &adapter->hw;
2195 struct e1000_fw_version fw;
2197 igb_get_fw_version(hw, &fw);
2199 switch (hw->mac.type) {
2202 if (!(igb_get_flash_presence_i210(hw))) {
2203 snprintf(adapter->fw_version,
2204 sizeof(adapter->fw_version),
2206 fw.invm_major, fw.invm_minor,
2212 /* if option is rom valid, display its version too */
2214 snprintf(adapter->fw_version,
2215 sizeof(adapter->fw_version),
2216 "%d.%d, 0x%08x, %d.%d.%d",
2217 fw.eep_major, fw.eep_minor, fw.etrack_id,
2218 fw.or_major, fw.or_build, fw.or_patch);
2220 } else if (fw.etrack_id != 0X0000) {
2221 snprintf(adapter->fw_version,
2222 sizeof(adapter->fw_version),
2224 fw.eep_major, fw.eep_minor, fw.etrack_id);
2226 snprintf(adapter->fw_version,
2227 sizeof(adapter->fw_version),
2229 fw.eep_major, fw.eep_minor, fw.eep_build);
2236 * igb_init_mas - init Media Autosense feature if enabled in the NVM
2238 * @adapter: adapter struct
2240 static void igb_init_mas(struct igb_adapter *adapter)
2242 struct e1000_hw *hw = &adapter->hw;
2245 hw->nvm.ops.read(hw, NVM_COMPAT, 1, &eeprom_data);
2246 switch (hw->bus.func) {
2248 if (eeprom_data & IGB_MAS_ENABLE_0) {
2249 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2250 netdev_info(adapter->netdev,
2251 "MAS: Enabling Media Autosense for port %d\n",
2256 if (eeprom_data & IGB_MAS_ENABLE_1) {
2257 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2258 netdev_info(adapter->netdev,
2259 "MAS: Enabling Media Autosense for port %d\n",
2264 if (eeprom_data & IGB_MAS_ENABLE_2) {
2265 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2266 netdev_info(adapter->netdev,
2267 "MAS: Enabling Media Autosense for port %d\n",
2272 if (eeprom_data & IGB_MAS_ENABLE_3) {
2273 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2274 netdev_info(adapter->netdev,
2275 "MAS: Enabling Media Autosense for port %d\n",
2280 /* Shouldn't get here */
2281 netdev_err(adapter->netdev,
2282 "MAS: Invalid port configuration, returning\n");
2288 * igb_init_i2c - Init I2C interface
2289 * @adapter: pointer to adapter structure
2291 static s32 igb_init_i2c(struct igb_adapter *adapter)
2295 /* I2C interface supported on i350 devices */
2296 if (adapter->hw.mac.type != e1000_i350)
2299 /* Initialize the i2c bus which is controlled by the registers.
2300 * This bus will use the i2c_algo_bit structue that implements
2301 * the protocol through toggling of the 4 bits in the register.
2303 adapter->i2c_adap.owner = THIS_MODULE;
2304 adapter->i2c_algo = igb_i2c_algo;
2305 adapter->i2c_algo.data = adapter;
2306 adapter->i2c_adap.algo_data = &adapter->i2c_algo;
2307 adapter->i2c_adap.dev.parent = &adapter->pdev->dev;
2308 strlcpy(adapter->i2c_adap.name, "igb BB",
2309 sizeof(adapter->i2c_adap.name));
2310 status = i2c_bit_add_bus(&adapter->i2c_adap);
2315 * igb_probe - Device Initialization Routine
2316 * @pdev: PCI device information struct
2317 * @ent: entry in igb_pci_tbl
2319 * Returns 0 on success, negative on failure
2321 * igb_probe initializes an adapter identified by a pci_dev structure.
2322 * The OS initialization, configuring of the adapter private structure,
2323 * and a hardware reset occur.
2325 static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2327 struct net_device *netdev;
2328 struct igb_adapter *adapter;
2329 struct e1000_hw *hw;
2330 u16 eeprom_data = 0;
2332 static int global_quad_port_a; /* global quad port a indication */
2333 const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
2334 int err, pci_using_dac;
2335 u8 part_str[E1000_PBANUM_LENGTH];
2337 /* Catch broken hardware that put the wrong VF device ID in
2338 * the PCIe SR-IOV capability.
2340 if (pdev->is_virtfn) {
2341 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
2342 pci_name(pdev), pdev->vendor, pdev->device);
2346 err = pci_enable_device_mem(pdev);
2351 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
2355 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2358 "No usable DMA configuration, aborting\n");
2363 err = pci_request_mem_regions(pdev, igb_driver_name);
2367 pci_enable_pcie_error_reporting(pdev);
2369 pci_set_master(pdev);
2370 pci_save_state(pdev);
2373 netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
2376 goto err_alloc_etherdev;
2378 SET_NETDEV_DEV(netdev, &pdev->dev);
2380 pci_set_drvdata(pdev, netdev);
2381 adapter = netdev_priv(netdev);
2382 adapter->netdev = netdev;
2383 adapter->pdev = pdev;
2386 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
2389 adapter->io_addr = pci_iomap(pdev, 0, 0);
2390 if (!adapter->io_addr)
2392 /* hw->hw_addr can be altered, we'll use adapter->io_addr for unmap */
2393 hw->hw_addr = adapter->io_addr;
2395 netdev->netdev_ops = &igb_netdev_ops;
2396 igb_set_ethtool_ops(netdev);
2397 netdev->watchdog_timeo = 5 * HZ;
2399 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
2401 netdev->mem_start = pci_resource_start(pdev, 0);
2402 netdev->mem_end = pci_resource_end(pdev, 0);
2404 /* PCI config space info */
2405 hw->vendor_id = pdev->vendor;
2406 hw->device_id = pdev->device;
2407 hw->revision_id = pdev->revision;
2408 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2409 hw->subsystem_device_id = pdev->subsystem_device;
2411 /* Copy the default MAC, PHY and NVM function pointers */
2412 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
2413 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
2414 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
2415 /* Initialize skew-specific constants */
2416 err = ei->get_invariants(hw);
2420 /* setup the private structure */
2421 err = igb_sw_init(adapter);
2425 igb_get_bus_info_pcie(hw);
2427 hw->phy.autoneg_wait_to_complete = false;
2429 /* Copper options */
2430 if (hw->phy.media_type == e1000_media_type_copper) {
2431 hw->phy.mdix = AUTO_ALL_MODES;
2432 hw->phy.disable_polarity_correction = false;
2433 hw->phy.ms_type = e1000_ms_hw_default;
2436 if (igb_check_reset_block(hw))
2437 dev_info(&pdev->dev,
2438 "PHY reset is blocked due to SOL/IDER session.\n");
2440 /* features is initialized to 0 in allocation, it might have bits
2441 * set by igb_sw_init so we should use an or instead of an
2444 netdev->features |= NETIF_F_SG |
2451 if (hw->mac.type >= e1000_82576)
2452 netdev->features |= NETIF_F_SCTP_CRC;
2454 #define IGB_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
2455 NETIF_F_GSO_GRE_CSUM | \
2456 NETIF_F_GSO_IPXIP4 | \
2457 NETIF_F_GSO_IPXIP6 | \
2458 NETIF_F_GSO_UDP_TUNNEL | \
2459 NETIF_F_GSO_UDP_TUNNEL_CSUM)
2461 netdev->gso_partial_features = IGB_GSO_PARTIAL_FEATURES;
2462 netdev->features |= NETIF_F_GSO_PARTIAL | IGB_GSO_PARTIAL_FEATURES;
2464 /* copy netdev features into list of user selectable features */
2465 netdev->hw_features |= netdev->features |
2466 NETIF_F_HW_VLAN_CTAG_RX |
2467 NETIF_F_HW_VLAN_CTAG_TX |
2470 if (hw->mac.type >= e1000_i350)
2471 netdev->hw_features |= NETIF_F_NTUPLE;
2474 netdev->features |= NETIF_F_HIGHDMA;
2476 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
2477 netdev->mpls_features |= NETIF_F_HW_CSUM;
2478 netdev->hw_enc_features |= netdev->vlan_features;
2480 /* set this bit last since it cannot be part of vlan_features */
2481 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
2482 NETIF_F_HW_VLAN_CTAG_RX |
2483 NETIF_F_HW_VLAN_CTAG_TX;
2485 netdev->priv_flags |= IFF_SUPP_NOFCS;
2487 netdev->priv_flags |= IFF_UNICAST_FLT;
2489 /* MTU range: 68 - 9216 */
2490 netdev->min_mtu = ETH_MIN_MTU;
2491 netdev->max_mtu = MAX_STD_JUMBO_FRAME_SIZE;
2493 adapter->en_mng_pt = igb_enable_mng_pass_thru(hw);
2495 /* before reading the NVM, reset the controller to put the device in a
2496 * known good starting state
2498 hw->mac.ops.reset_hw(hw);
2500 /* make sure the NVM is good , i211/i210 parts can have special NVM
2501 * that doesn't contain a checksum
2503 switch (hw->mac.type) {
2506 if (igb_get_flash_presence_i210(hw)) {
2507 if (hw->nvm.ops.validate(hw) < 0) {
2509 "The NVM Checksum Is Not Valid\n");
2516 if (hw->nvm.ops.validate(hw) < 0) {
2517 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
2524 if (eth_platform_get_mac_address(&pdev->dev, hw->mac.addr)) {
2525 /* copy the MAC address out of the NVM */
2526 if (hw->mac.ops.read_mac_addr(hw))
2527 dev_err(&pdev->dev, "NVM Read Error\n");
2530 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
2532 if (!is_valid_ether_addr(netdev->dev_addr)) {
2533 dev_err(&pdev->dev, "Invalid MAC Address\n");
2538 igb_set_default_mac_filter(adapter);
2540 /* get firmware version for ethtool -i */
2541 igb_set_fw_version(adapter);
2543 /* configure RXPBSIZE and TXPBSIZE */
2544 if (hw->mac.type == e1000_i210) {
2545 wr32(E1000_RXPBS, I210_RXPBSIZE_DEFAULT);
2546 wr32(E1000_TXPBS, I210_TXPBSIZE_DEFAULT);
2549 setup_timer(&adapter->watchdog_timer, igb_watchdog,
2550 (unsigned long) adapter);
2551 setup_timer(&adapter->phy_info_timer, igb_update_phy_info,
2552 (unsigned long) adapter);
2554 INIT_WORK(&adapter->reset_task, igb_reset_task);
2555 INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
2557 /* Initialize link properties that are user-changeable */
2558 adapter->fc_autoneg = true;
2559 hw->mac.autoneg = true;
2560 hw->phy.autoneg_advertised = 0x2f;
2562 hw->fc.requested_mode = e1000_fc_default;
2563 hw->fc.current_mode = e1000_fc_default;
2565 igb_validate_mdi_setting(hw);
2567 /* By default, support wake on port A */
2568 if (hw->bus.func == 0)
2569 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2571 /* Check the NVM for wake support on non-port A ports */
2572 if (hw->mac.type >= e1000_82580)
2573 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2574 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2576 else if (hw->bus.func == 1)
2577 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
2579 if (eeprom_data & IGB_EEPROM_APME)
2580 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2582 /* now that we have the eeprom settings, apply the special cases where
2583 * the eeprom may be wrong or the board simply won't support wake on
2584 * lan on a particular port
2586 switch (pdev->device) {
2587 case E1000_DEV_ID_82575GB_QUAD_COPPER:
2588 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2590 case E1000_DEV_ID_82575EB_FIBER_SERDES:
2591 case E1000_DEV_ID_82576_FIBER:
2592 case E1000_DEV_ID_82576_SERDES:
2593 /* Wake events only supported on port A for dual fiber
2594 * regardless of eeprom setting
2596 if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1)
2597 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2599 case E1000_DEV_ID_82576_QUAD_COPPER:
2600 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
2601 /* if quad port adapter, disable WoL on all but port A */
2602 if (global_quad_port_a != 0)
2603 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2605 adapter->flags |= IGB_FLAG_QUAD_PORT_A;
2606 /* Reset for multiple quad port adapters */
2607 if (++global_quad_port_a == 4)
2608 global_quad_port_a = 0;
2611 /* If the device can't wake, don't set software support */
2612 if (!device_can_wakeup(&adapter->pdev->dev))
2613 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2616 /* initialize the wol settings based on the eeprom settings */
2617 if (adapter->flags & IGB_FLAG_WOL_SUPPORTED)
2618 adapter->wol |= E1000_WUFC_MAG;
2620 /* Some vendors want WoL disabled by default, but still supported */
2621 if ((hw->mac.type == e1000_i350) &&
2622 (pdev->subsystem_vendor == PCI_VENDOR_ID_HP)) {
2623 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2627 /* Some vendors want the ability to Use the EEPROM setting as
2628 * enable/disable only, and not for capability
2630 if (((hw->mac.type == e1000_i350) ||
2631 (hw->mac.type == e1000_i354)) &&
2632 (pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)) {
2633 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2636 if (hw->mac.type == e1000_i350) {
2637 if (((pdev->subsystem_device == 0x5001) ||
2638 (pdev->subsystem_device == 0x5002)) &&
2639 (hw->bus.func == 0)) {
2640 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2643 if (pdev->subsystem_device == 0x1F52)
2644 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2647 device_set_wakeup_enable(&adapter->pdev->dev,
2648 adapter->flags & IGB_FLAG_WOL_SUPPORTED);
2650 /* reset the hardware with the new settings */
2653 /* Init the I2C interface */
2654 err = igb_init_i2c(adapter);
2656 dev_err(&pdev->dev, "failed to init i2c interface\n");
2660 /* let the f/w know that the h/w is now under the control of the
2663 igb_get_hw_control(adapter);
2665 strcpy(netdev->name, "eth%d");
2666 err = register_netdev(netdev);
2670 /* carrier off reporting is important to ethtool even BEFORE open */
2671 netif_carrier_off(netdev);
2673 #ifdef CONFIG_IGB_DCA
2674 if (dca_add_requester(&pdev->dev) == 0) {
2675 adapter->flags |= IGB_FLAG_DCA_ENABLED;
2676 dev_info(&pdev->dev, "DCA enabled\n");
2677 igb_setup_dca(adapter);
2681 #ifdef CONFIG_IGB_HWMON
2682 /* Initialize the thermal sensor on i350 devices. */
2683 if (hw->mac.type == e1000_i350 && hw->bus.func == 0) {
2686 /* Read the NVM to determine if this i350 device supports an
2687 * external thermal sensor.
2689 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_word);
2690 if (ets_word != 0x0000 && ets_word != 0xFFFF)
2691 adapter->ets = true;
2693 adapter->ets = false;
2694 if (igb_sysfs_init(adapter))
2696 "failed to allocate sysfs resources\n");
2698 adapter->ets = false;
2701 /* Check if Media Autosense is enabled */
2703 if (hw->dev_spec._82575.mas_capable)
2704 igb_init_mas(adapter);
2706 /* do hw tstamp init after resetting */
2707 igb_ptp_init(adapter);
2709 dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
2710 /* print bus type/speed/width info, not applicable to i354 */
2711 if (hw->mac.type != e1000_i354) {
2712 dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n",
2714 ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
2715 (hw->bus.speed == e1000_bus_speed_5000) ? "5.0Gb/s" :
2717 ((hw->bus.width == e1000_bus_width_pcie_x4) ?
2719 (hw->bus.width == e1000_bus_width_pcie_x2) ?
2721 (hw->bus.width == e1000_bus_width_pcie_x1) ?
2722 "Width x1" : "unknown"), netdev->dev_addr);
2725 if ((hw->mac.type >= e1000_i210 ||
2726 igb_get_flash_presence_i210(hw))) {
2727 ret_val = igb_read_part_string(hw, part_str,
2728 E1000_PBANUM_LENGTH);
2730 ret_val = -E1000_ERR_INVM_VALUE_NOT_FOUND;
2734 strcpy(part_str, "Unknown");
2735 dev_info(&pdev->dev, "%s: PBA No: %s\n", netdev->name, part_str);
2736 dev_info(&pdev->dev,
2737 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
2738 (adapter->flags & IGB_FLAG_HAS_MSIX) ? "MSI-X" :
2739 (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
2740 adapter->num_rx_queues, adapter->num_tx_queues);
2741 if (hw->phy.media_type == e1000_media_type_copper) {
2742 switch (hw->mac.type) {
2746 /* Enable EEE for internal copper PHY devices */
2747 err = igb_set_eee_i350(hw, true, true);
2749 (!hw->dev_spec._82575.eee_disable)) {
2750 adapter->eee_advert =
2751 MDIO_EEE_100TX | MDIO_EEE_1000T;
2752 adapter->flags |= IGB_FLAG_EEE;
2756 if ((rd32(E1000_CTRL_EXT) &
2757 E1000_CTRL_EXT_LINK_MODE_SGMII)) {
2758 err = igb_set_eee_i354(hw, true, true);
2760 (!hw->dev_spec._82575.eee_disable)) {
2761 adapter->eee_advert =
2762 MDIO_EEE_100TX | MDIO_EEE_1000T;
2763 adapter->flags |= IGB_FLAG_EEE;
2771 pm_runtime_put_noidle(&pdev->dev);
2775 igb_release_hw_control(adapter);
2776 memset(&adapter->i2c_adap, 0, sizeof(adapter->i2c_adap));
2778 if (!igb_check_reset_block(hw))
2781 if (hw->flash_address)
2782 iounmap(hw->flash_address);
2784 kfree(adapter->mac_table);
2785 kfree(adapter->shadow_vfta);
2786 igb_clear_interrupt_scheme(adapter);
2787 #ifdef CONFIG_PCI_IOV
2788 igb_disable_sriov(pdev);
2790 pci_iounmap(pdev, adapter->io_addr);
2792 free_netdev(netdev);
2794 pci_disable_pcie_error_reporting(pdev);
2795 pci_release_mem_regions(pdev);
2798 pci_disable_device(pdev);
2802 #ifdef CONFIG_PCI_IOV
2803 static int igb_disable_sriov(struct pci_dev *pdev)
2805 struct net_device *netdev = pci_get_drvdata(pdev);
2806 struct igb_adapter *adapter = netdev_priv(netdev);
2807 struct e1000_hw *hw = &adapter->hw;
2809 /* reclaim resources allocated to VFs */
2810 if (adapter->vf_data) {
2811 /* disable iov and allow time for transactions to clear */
2812 if (pci_vfs_assigned(pdev)) {
2813 dev_warn(&pdev->dev,
2814 "Cannot deallocate SR-IOV virtual functions while they are assigned - VFs will not be deallocated\n");
2817 pci_disable_sriov(pdev);
2821 kfree(adapter->vf_mac_list);
2822 adapter->vf_mac_list = NULL;
2823 kfree(adapter->vf_data);
2824 adapter->vf_data = NULL;
2825 adapter->vfs_allocated_count = 0;
2826 wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
2829 dev_info(&pdev->dev, "IOV Disabled\n");
2831 /* Re-enable DMA Coalescing flag since IOV is turned off */
2832 adapter->flags |= IGB_FLAG_DMAC;
2838 static int igb_enable_sriov(struct pci_dev *pdev, int num_vfs)
2840 struct net_device *netdev = pci_get_drvdata(pdev);
2841 struct igb_adapter *adapter = netdev_priv(netdev);
2842 int old_vfs = pci_num_vf(pdev);
2843 struct vf_mac_filter *mac_list;
2845 int num_vf_mac_filters, i;
2847 if (!(adapter->flags & IGB_FLAG_HAS_MSIX) || num_vfs > 7) {
2855 dev_info(&pdev->dev, "%d pre-allocated VFs found - override max_vfs setting of %d\n",
2857 adapter->vfs_allocated_count = old_vfs;
2859 adapter->vfs_allocated_count = num_vfs;
2861 adapter->vf_data = kcalloc(adapter->vfs_allocated_count,
2862 sizeof(struct vf_data_storage), GFP_KERNEL);
2864 /* if allocation failed then we do not support SR-IOV */
2865 if (!adapter->vf_data) {
2866 adapter->vfs_allocated_count = 0;
2868 "Unable to allocate memory for VF Data Storage\n");
2873 /* Due to the limited number of RAR entries calculate potential
2874 * number of MAC filters available for the VFs. Reserve entries
2875 * for PF default MAC, PF MAC filters and at least one RAR entry
2876 * for each VF for VF MAC.
2878 num_vf_mac_filters = adapter->hw.mac.rar_entry_count -
2879 (1 + IGB_PF_MAC_FILTERS_RESERVED +
2880 adapter->vfs_allocated_count);
2882 adapter->vf_mac_list = kcalloc(num_vf_mac_filters,
2883 sizeof(struct vf_mac_filter),
2886 mac_list = adapter->vf_mac_list;
2887 INIT_LIST_HEAD(&adapter->vf_macs.l);
2889 if (adapter->vf_mac_list) {
2890 /* Initialize list of VF MAC filters */
2891 for (i = 0; i < num_vf_mac_filters; i++) {
2893 mac_list->free = true;
2894 list_add(&mac_list->l, &adapter->vf_macs.l);
2898 /* If we could not allocate memory for the VF MAC filters
2899 * we can continue without this feature but warn user.
2902 "Unable to allocate memory for VF MAC filter list\n");
2905 /* only call pci_enable_sriov() if no VFs are allocated already */
2907 err = pci_enable_sriov(pdev, adapter->vfs_allocated_count);
2911 dev_info(&pdev->dev, "%d VFs allocated\n",
2912 adapter->vfs_allocated_count);
2913 for (i = 0; i < adapter->vfs_allocated_count; i++)
2914 igb_vf_configure(adapter, i);
2916 /* DMA Coalescing is not supported in IOV mode. */
2917 adapter->flags &= ~IGB_FLAG_DMAC;
2921 kfree(adapter->vf_mac_list);
2922 adapter->vf_mac_list = NULL;
2923 kfree(adapter->vf_data);
2924 adapter->vf_data = NULL;
2925 adapter->vfs_allocated_count = 0;
2932 * igb_remove_i2c - Cleanup I2C interface
2933 * @adapter: pointer to adapter structure
2935 static void igb_remove_i2c(struct igb_adapter *adapter)
2937 /* free the adapter bus structure */
2938 i2c_del_adapter(&adapter->i2c_adap);
2942 * igb_remove - Device Removal Routine
2943 * @pdev: PCI device information struct
2945 * igb_remove is called by the PCI subsystem to alert the driver
2946 * that it should release a PCI device. The could be caused by a
2947 * Hot-Plug event, or because the driver is going to be removed from
2950 static void igb_remove(struct pci_dev *pdev)
2952 struct net_device *netdev = pci_get_drvdata(pdev);
2953 struct igb_adapter *adapter = netdev_priv(netdev);
2954 struct e1000_hw *hw = &adapter->hw;
2956 pm_runtime_get_noresume(&pdev->dev);
2957 #ifdef CONFIG_IGB_HWMON
2958 igb_sysfs_exit(adapter);
2960 igb_remove_i2c(adapter);
2961 igb_ptp_stop(adapter);
2962 /* The watchdog timer may be rescheduled, so explicitly
2963 * disable watchdog from being rescheduled.
2965 set_bit(__IGB_DOWN, &adapter->state);
2966 del_timer_sync(&adapter->watchdog_timer);
2967 del_timer_sync(&adapter->phy_info_timer);
2969 cancel_work_sync(&adapter->reset_task);
2970 cancel_work_sync(&adapter->watchdog_task);
2972 #ifdef CONFIG_IGB_DCA
2973 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
2974 dev_info(&pdev->dev, "DCA disabled\n");
2975 dca_remove_requester(&pdev->dev);
2976 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
2977 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
2981 /* Release control of h/w to f/w. If f/w is AMT enabled, this
2982 * would have already happened in close and is redundant.
2984 igb_release_hw_control(adapter);
2986 #ifdef CONFIG_PCI_IOV
2987 igb_disable_sriov(pdev);
2990 unregister_netdev(netdev);
2992 igb_clear_interrupt_scheme(adapter);
2994 pci_iounmap(pdev, adapter->io_addr);
2995 if (hw->flash_address)
2996 iounmap(hw->flash_address);
2997 pci_release_mem_regions(pdev);
2999 kfree(adapter->mac_table);
3000 kfree(adapter->shadow_vfta);
3001 free_netdev(netdev);
3003 pci_disable_pcie_error_reporting(pdev);
3005 pci_disable_device(pdev);
3009 * igb_probe_vfs - Initialize vf data storage and add VFs to pci config space
3010 * @adapter: board private structure to initialize
3012 * This function initializes the vf specific data storage and then attempts to
3013 * allocate the VFs. The reason for ordering it this way is because it is much
3014 * mor expensive time wise to disable SR-IOV than it is to allocate and free
3015 * the memory for the VFs.
3017 static void igb_probe_vfs(struct igb_adapter *adapter)
3019 #ifdef CONFIG_PCI_IOV
3020 struct pci_dev *pdev = adapter->pdev;
3021 struct e1000_hw *hw = &adapter->hw;
3023 /* Virtualization features not supported on i210 family. */
3024 if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211))
3027 /* Of the below we really only want the effect of getting
3028 * IGB_FLAG_HAS_MSIX set (if available), without which
3029 * igb_enable_sriov() has no effect.
3031 igb_set_interrupt_capability(adapter, true);
3032 igb_reset_interrupt_capability(adapter);
3034 pci_sriov_set_totalvfs(pdev, 7);
3035 igb_enable_sriov(pdev, max_vfs);
3037 #endif /* CONFIG_PCI_IOV */
3040 static void igb_init_queue_configuration(struct igb_adapter *adapter)
3042 struct e1000_hw *hw = &adapter->hw;
3045 /* Determine the maximum number of RSS queues supported. */
3046 switch (hw->mac.type) {
3048 max_rss_queues = IGB_MAX_RX_QUEUES_I211;
3052 max_rss_queues = IGB_MAX_RX_QUEUES_82575;
3055 /* I350 cannot do RSS and SR-IOV at the same time */
3056 if (!!adapter->vfs_allocated_count) {
3062 if (!!adapter->vfs_allocated_count) {
3070 max_rss_queues = IGB_MAX_RX_QUEUES;
3074 adapter->rss_queues = min_t(u32, max_rss_queues, num_online_cpus());
3076 igb_set_flag_queue_pairs(adapter, max_rss_queues);
3079 void igb_set_flag_queue_pairs(struct igb_adapter *adapter,
3080 const u32 max_rss_queues)
3082 struct e1000_hw *hw = &adapter->hw;
3084 /* Determine if we need to pair queues. */
3085 switch (hw->mac.type) {
3088 /* Device supports enough interrupts without queue pairing. */
3096 /* If rss_queues > half of max_rss_queues, pair the queues in
3097 * order to conserve interrupts due to limited supply.
3099 if (adapter->rss_queues > (max_rss_queues / 2))
3100 adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
3102 adapter->flags &= ~IGB_FLAG_QUEUE_PAIRS;
3108 * igb_sw_init - Initialize general software structures (struct igb_adapter)
3109 * @adapter: board private structure to initialize
3111 * igb_sw_init initializes the Adapter private data structure.
3112 * Fields are initialized based on PCI device information and
3113 * OS network device settings (MTU size).
3115 static int igb_sw_init(struct igb_adapter *adapter)
3117 struct e1000_hw *hw = &adapter->hw;
3118 struct net_device *netdev = adapter->netdev;
3119 struct pci_dev *pdev = adapter->pdev;
3121 pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
3123 /* set default ring sizes */
3124 adapter->tx_ring_count = IGB_DEFAULT_TXD;
3125 adapter->rx_ring_count = IGB_DEFAULT_RXD;
3127 /* set default ITR values */
3128 adapter->rx_itr_setting = IGB_DEFAULT_ITR;
3129 adapter->tx_itr_setting = IGB_DEFAULT_ITR;
3131 /* set default work limits */
3132 adapter->tx_work_limit = IGB_DEFAULT_TX_WORK;
3134 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN +
3136 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
3138 spin_lock_init(&adapter->nfc_lock);
3139 spin_lock_init(&adapter->stats64_lock);
3140 #ifdef CONFIG_PCI_IOV
3141 switch (hw->mac.type) {
3145 dev_warn(&pdev->dev,
3146 "Maximum of 7 VFs per PF, using max\n");
3147 max_vfs = adapter->vfs_allocated_count = 7;
3149 adapter->vfs_allocated_count = max_vfs;
3150 if (adapter->vfs_allocated_count)
3151 dev_warn(&pdev->dev,
3152 "Enabling SR-IOV VFs using the module parameter is deprecated - please use the pci sysfs interface.\n");
3157 #endif /* CONFIG_PCI_IOV */
3159 /* Assume MSI-X interrupts, will be checked during IRQ allocation */
3160 adapter->flags |= IGB_FLAG_HAS_MSIX;
3162 adapter->mac_table = kzalloc(sizeof(struct igb_mac_addr) *
3163 hw->mac.rar_entry_count, GFP_ATOMIC);
3164 if (!adapter->mac_table)
3167 igb_probe_vfs(adapter);
3169 igb_init_queue_configuration(adapter);
3171 /* Setup and initialize a copy of the hw vlan table array */
3172 adapter->shadow_vfta = kcalloc(E1000_VLAN_FILTER_TBL_SIZE, sizeof(u32),
3174 if (!adapter->shadow_vfta)
3177 /* This call may decrease the number of queues */
3178 if (igb_init_interrupt_scheme(adapter, true)) {
3179 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
3183 /* Explicitly disable IRQ since the NIC can be in any state. */
3184 igb_irq_disable(adapter);
3186 if (hw->mac.type >= e1000_i350)
3187 adapter->flags &= ~IGB_FLAG_DMAC;
3189 set_bit(__IGB_DOWN, &adapter->state);
3194 * igb_open - Called when a network interface is made active
3195 * @netdev: network interface device structure
3197 * Returns 0 on success, negative value on failure
3199 * The open entry point is called when a network interface is made
3200 * active by the system (IFF_UP). At this point all resources needed
3201 * for transmit and receive operations are allocated, the interrupt
3202 * handler is registered with the OS, the watchdog timer is started,
3203 * and the stack is notified that the interface is ready.
3205 static int __igb_open(struct net_device *netdev, bool resuming)
3207 struct igb_adapter *adapter = netdev_priv(netdev);
3208 struct e1000_hw *hw = &adapter->hw;
3209 struct pci_dev *pdev = adapter->pdev;
3213 /* disallow open during test */
3214 if (test_bit(__IGB_TESTING, &adapter->state)) {
3220 pm_runtime_get_sync(&pdev->dev);
3222 netif_carrier_off(netdev);
3224 /* allocate transmit descriptors */
3225 err = igb_setup_all_tx_resources(adapter);
3229 /* allocate receive descriptors */
3230 err = igb_setup_all_rx_resources(adapter);
3234 igb_power_up_link(adapter);
3236 /* before we allocate an interrupt, we must be ready to handle it.
3237 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3238 * as soon as we call pci_request_irq, so we have to setup our
3239 * clean_rx handler before we do so.
3241 igb_configure(adapter);
3243 err = igb_request_irq(adapter);
3247 /* Notify the stack of the actual queue counts. */
3248 err = netif_set_real_num_tx_queues(adapter->netdev,
3249 adapter->num_tx_queues);
3251 goto err_set_queues;
3253 err = netif_set_real_num_rx_queues(adapter->netdev,
3254 adapter->num_rx_queues);
3256 goto err_set_queues;
3258 /* From here on the code is the same as igb_up() */
3259 clear_bit(__IGB_DOWN, &adapter->state);
3261 for (i = 0; i < adapter->num_q_vectors; i++)
3262 napi_enable(&(adapter->q_vector[i]->napi));
3264 /* Clear any pending interrupts. */
3267 igb_irq_enable(adapter);
3269 /* notify VFs that reset has been completed */
3270 if (adapter->vfs_allocated_count) {
3271 u32 reg_data = rd32(E1000_CTRL_EXT);
3273 reg_data |= E1000_CTRL_EXT_PFRSTD;
3274 wr32(E1000_CTRL_EXT, reg_data);
3277 netif_tx_start_all_queues(netdev);
3280 pm_runtime_put(&pdev->dev);
3282 /* start the watchdog. */
3283 hw->mac.get_link_status = 1;
3284 schedule_work(&adapter->watchdog_task);
3289 igb_free_irq(adapter);
3291 igb_release_hw_control(adapter);
3292 igb_power_down_link(adapter);
3293 igb_free_all_rx_resources(adapter);
3295 igb_free_all_tx_resources(adapter);
3299 pm_runtime_put(&pdev->dev);
3304 int igb_open(struct net_device *netdev)
3306 return __igb_open(netdev, false);
3310 * igb_close - Disables a network interface
3311 * @netdev: network interface device structure
3313 * Returns 0, this is not allowed to fail
3315 * The close entry point is called when an interface is de-activated
3316 * by the OS. The hardware is still under the driver's control, but
3317 * needs to be disabled. A global MAC reset is issued to stop the
3318 * hardware, and all transmit and receive resources are freed.
3320 static int __igb_close(struct net_device *netdev, bool suspending)
3322 struct igb_adapter *adapter = netdev_priv(netdev);
3323 struct pci_dev *pdev = adapter->pdev;
3325 WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
3328 pm_runtime_get_sync(&pdev->dev);
3331 igb_free_irq(adapter);
3333 igb_free_all_tx_resources(adapter);
3334 igb_free_all_rx_resources(adapter);
3337 pm_runtime_put_sync(&pdev->dev);
3341 int igb_close(struct net_device *netdev)
3343 if (netif_device_present(netdev) || netdev->dismantle)
3344 return __igb_close(netdev, false);
3349 * igb_setup_tx_resources - allocate Tx resources (Descriptors)
3350 * @tx_ring: tx descriptor ring (for a specific queue) to setup
3352 * Return 0 on success, negative on failure
3354 int igb_setup_tx_resources(struct igb_ring *tx_ring)
3356 struct device *dev = tx_ring->dev;
3359 size = sizeof(struct igb_tx_buffer) * tx_ring->count;
3361 tx_ring->tx_buffer_info = vmalloc(size);
3362 if (!tx_ring->tx_buffer_info)
3365 /* round up to nearest 4K */
3366 tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
3367 tx_ring->size = ALIGN(tx_ring->size, 4096);
3369 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
3370 &tx_ring->dma, GFP_KERNEL);
3374 tx_ring->next_to_use = 0;
3375 tx_ring->next_to_clean = 0;
3380 vfree(tx_ring->tx_buffer_info);
3381 tx_ring->tx_buffer_info = NULL;
3382 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
3387 * igb_setup_all_tx_resources - wrapper to allocate Tx resources
3388 * (Descriptors) for all queues
3389 * @adapter: board private structure
3391 * Return 0 on success, negative on failure
3393 static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
3395 struct pci_dev *pdev = adapter->pdev;
3398 for (i = 0; i < adapter->num_tx_queues; i++) {
3399 err = igb_setup_tx_resources(adapter->tx_ring[i]);
3402 "Allocation for Tx Queue %u failed\n", i);
3403 for (i--; i >= 0; i--)
3404 igb_free_tx_resources(adapter->tx_ring[i]);
3413 * igb_setup_tctl - configure the transmit control registers
3414 * @adapter: Board private structure
3416 void igb_setup_tctl(struct igb_adapter *adapter)
3418 struct e1000_hw *hw = &adapter->hw;
3421 /* disable queue 0 which is enabled by default on 82575 and 82576 */
3422 wr32(E1000_TXDCTL(0), 0);
3424 /* Program the Transmit Control Register */
3425 tctl = rd32(E1000_TCTL);
3426 tctl &= ~E1000_TCTL_CT;
3427 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
3428 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
3430 igb_config_collision_dist(hw);
3432 /* Enable transmits */
3433 tctl |= E1000_TCTL_EN;
3435 wr32(E1000_TCTL, tctl);
3439 * igb_configure_tx_ring - Configure transmit ring after Reset
3440 * @adapter: board private structure
3441 * @ring: tx ring to configure
3443 * Configure a transmit ring after a reset.
3445 void igb_configure_tx_ring(struct igb_adapter *adapter,
3446 struct igb_ring *ring)
3448 struct e1000_hw *hw = &adapter->hw;
3450 u64 tdba = ring->dma;
3451 int reg_idx = ring->reg_idx;
3453 /* disable the queue */
3454 wr32(E1000_TXDCTL(reg_idx), 0);
3458 wr32(E1000_TDLEN(reg_idx),
3459 ring->count * sizeof(union e1000_adv_tx_desc));
3460 wr32(E1000_TDBAL(reg_idx),
3461 tdba & 0x00000000ffffffffULL);
3462 wr32(E1000_TDBAH(reg_idx), tdba >> 32);
3464 ring->tail = adapter->io_addr + E1000_TDT(reg_idx);
3465 wr32(E1000_TDH(reg_idx), 0);
3466 writel(0, ring->tail);
3468 txdctl |= IGB_TX_PTHRESH;
3469 txdctl |= IGB_TX_HTHRESH << 8;
3470 txdctl |= IGB_TX_WTHRESH << 16;
3472 /* reinitialize tx_buffer_info */
3473 memset(ring->tx_buffer_info, 0,
3474 sizeof(struct igb_tx_buffer) * ring->count);
3476 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
3477 wr32(E1000_TXDCTL(reg_idx), txdctl);
3481 * igb_configure_tx - Configure transmit Unit after Reset
3482 * @adapter: board private structure
3484 * Configure the Tx unit of the MAC after a reset.
3486 static void igb_configure_tx(struct igb_adapter *adapter)
3490 for (i = 0; i < adapter->num_tx_queues; i++)
3491 igb_configure_tx_ring(adapter, adapter->tx_ring[i]);
3495 * igb_setup_rx_resources - allocate Rx resources (Descriptors)
3496 * @rx_ring: Rx descriptor ring (for a specific queue) to setup
3498 * Returns 0 on success, negative on failure
3500 int igb_setup_rx_resources(struct igb_ring *rx_ring)
3502 struct device *dev = rx_ring->dev;
3505 size = sizeof(struct igb_rx_buffer) * rx_ring->count;
3507 rx_ring->rx_buffer_info = vmalloc(size);
3508 if (!rx_ring->rx_buffer_info)
3511 /* Round up to nearest 4K */
3512 rx_ring->size = rx_ring->count * sizeof(union e1000_adv_rx_desc);
3513 rx_ring->size = ALIGN(rx_ring->size, 4096);
3515 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
3516 &rx_ring->dma, GFP_KERNEL);
3520 rx_ring->next_to_alloc = 0;
3521 rx_ring->next_to_clean = 0;
3522 rx_ring->next_to_use = 0;
3527 vfree(rx_ring->rx_buffer_info);
3528 rx_ring->rx_buffer_info = NULL;
3529 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
3534 * igb_setup_all_rx_resources - wrapper to allocate Rx resources
3535 * (Descriptors) for all queues
3536 * @adapter: board private structure
3538 * Return 0 on success, negative on failure
3540 static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
3542 struct pci_dev *pdev = adapter->pdev;
3545 for (i = 0; i < adapter->num_rx_queues; i++) {
3546 err = igb_setup_rx_resources(adapter->rx_ring[i]);
3549 "Allocation for Rx Queue %u failed\n", i);
3550 for (i--; i >= 0; i--)
3551 igb_free_rx_resources(adapter->rx_ring[i]);
3560 * igb_setup_mrqc - configure the multiple receive queue control registers
3561 * @adapter: Board private structure
3563 static void igb_setup_mrqc(struct igb_adapter *adapter)
3565 struct e1000_hw *hw = &adapter->hw;
3567 u32 j, num_rx_queues;
3570 netdev_rss_key_fill(rss_key, sizeof(rss_key));
3571 for (j = 0; j < 10; j++)
3572 wr32(E1000_RSSRK(j), rss_key[j]);
3574 num_rx_queues = adapter->rss_queues;
3576 switch (hw->mac.type) {
3578 /* 82576 supports 2 RSS queues for SR-IOV */
3579 if (adapter->vfs_allocated_count)
3586 if (adapter->rss_indir_tbl_init != num_rx_queues) {
3587 for (j = 0; j < IGB_RETA_SIZE; j++)
3588 adapter->rss_indir_tbl[j] =
3589 (j * num_rx_queues) / IGB_RETA_SIZE;
3590 adapter->rss_indir_tbl_init = num_rx_queues;
3592 igb_write_rss_indir_tbl(adapter);
3594 /* Disable raw packet checksumming so that RSS hash is placed in
3595 * descriptor on writeback. No need to enable TCP/UDP/IP checksum
3596 * offloads as they are enabled by default
3598 rxcsum = rd32(E1000_RXCSUM);
3599 rxcsum |= E1000_RXCSUM_PCSD;
3601 if (adapter->hw.mac.type >= e1000_82576)
3602 /* Enable Receive Checksum Offload for SCTP */
3603 rxcsum |= E1000_RXCSUM_CRCOFL;
3605 /* Don't need to set TUOFL or IPOFL, they default to 1 */
3606 wr32(E1000_RXCSUM, rxcsum);
3608 /* Generate RSS hash based on packet types, TCP/UDP
3609 * port numbers and/or IPv4/v6 src and dst addresses
3611 mrqc = E1000_MRQC_RSS_FIELD_IPV4 |
3612 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3613 E1000_MRQC_RSS_FIELD_IPV6 |
3614 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3615 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX;
3617 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
3618 mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP;
3619 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
3620 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP;
3622 /* If VMDq is enabled then we set the appropriate mode for that, else
3623 * we default to RSS so that an RSS hash is calculated per packet even
3624 * if we are only using one queue
3626 if (adapter->vfs_allocated_count) {
3627 if (hw->mac.type > e1000_82575) {
3628 /* Set the default pool for the PF's first queue */
3629 u32 vtctl = rd32(E1000_VT_CTL);
3631 vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK |
3632 E1000_VT_CTL_DISABLE_DEF_POOL);
3633 vtctl |= adapter->vfs_allocated_count <<
3634 E1000_VT_CTL_DEFAULT_POOL_SHIFT;
3635 wr32(E1000_VT_CTL, vtctl);
3637 if (adapter->rss_queues > 1)
3638 mrqc |= E1000_MRQC_ENABLE_VMDQ_RSS_MQ;
3640 mrqc |= E1000_MRQC_ENABLE_VMDQ;
3642 if (hw->mac.type != e1000_i211)
3643 mrqc |= E1000_MRQC_ENABLE_RSS_MQ;
3645 igb_vmm_control(adapter);
3647 wr32(E1000_MRQC, mrqc);
3651 * igb_setup_rctl - configure the receive control registers
3652 * @adapter: Board private structure
3654 void igb_setup_rctl(struct igb_adapter *adapter)
3656 struct e1000_hw *hw = &adapter->hw;
3659 rctl = rd32(E1000_RCTL);
3661 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3662 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
3664 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
3665 (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
3667 /* enable stripping of CRC. It's unlikely this will break BMC
3668 * redirection as it did with e1000. Newer features require
3669 * that the HW strips the CRC.
3671 rctl |= E1000_RCTL_SECRC;
3673 /* disable store bad packets and clear size bits. */
3674 rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256);
3676 /* enable LPE to allow for reception of jumbo frames */
3677 rctl |= E1000_RCTL_LPE;
3679 /* disable queue 0 to prevent tail write w/o re-config */
3680 wr32(E1000_RXDCTL(0), 0);
3682 /* Attention!!! For SR-IOV PF driver operations you must enable
3683 * queue drop for all VF and PF queues to prevent head of line blocking
3684 * if an un-trusted VF does not provide descriptors to hardware.
3686 if (adapter->vfs_allocated_count) {
3687 /* set all queue drop enable bits */
3688 wr32(E1000_QDE, ALL_QUEUES);
3691 /* This is useful for sniffing bad packets. */
3692 if (adapter->netdev->features & NETIF_F_RXALL) {
3693 /* UPE and MPE will be handled by normal PROMISC logic
3694 * in e1000e_set_rx_mode
3696 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3697 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3698 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3700 rctl &= ~(E1000_RCTL_DPF | /* Allow filtered pause */
3701 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3702 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3703 * and that breaks VLANs.
3707 wr32(E1000_RCTL, rctl);
3710 static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
3713 struct e1000_hw *hw = &adapter->hw;
3716 if (size > MAX_JUMBO_FRAME_SIZE)
3717 size = MAX_JUMBO_FRAME_SIZE;
3719 vmolr = rd32(E1000_VMOLR(vfn));
3720 vmolr &= ~E1000_VMOLR_RLPML_MASK;
3721 vmolr |= size | E1000_VMOLR_LPE;
3722 wr32(E1000_VMOLR(vfn), vmolr);
3727 static inline void igb_set_vf_vlan_strip(struct igb_adapter *adapter,
3728 int vfn, bool enable)
3730 struct e1000_hw *hw = &adapter->hw;
3733 if (hw->mac.type < e1000_82576)
3736 if (hw->mac.type == e1000_i350)
3737 reg = E1000_DVMOLR(vfn);
3739 reg = E1000_VMOLR(vfn);
3743 val |= E1000_VMOLR_STRVLAN;
3745 val &= ~(E1000_VMOLR_STRVLAN);
3749 static inline void igb_set_vmolr(struct igb_adapter *adapter,
3752 struct e1000_hw *hw = &adapter->hw;
3755 /* This register exists only on 82576 and newer so if we are older then
3756 * we should exit and do nothing
3758 if (hw->mac.type < e1000_82576)
3761 vmolr = rd32(E1000_VMOLR(vfn));
3763 vmolr |= E1000_VMOLR_AUPE; /* Accept untagged packets */
3765 vmolr &= ~(E1000_VMOLR_AUPE); /* Tagged packets ONLY */
3767 /* clear all bits that might not be set */
3768 vmolr &= ~(E1000_VMOLR_BAM | E1000_VMOLR_RSSE);
3770 if (adapter->rss_queues > 1 && vfn == adapter->vfs_allocated_count)
3771 vmolr |= E1000_VMOLR_RSSE; /* enable RSS */
3772 /* for VMDq only allow the VFs and pool 0 to accept broadcast and
3775 if (vfn <= adapter->vfs_allocated_count)
3776 vmolr |= E1000_VMOLR_BAM; /* Accept broadcast */
3778 wr32(E1000_VMOLR(vfn), vmolr);
3782 * igb_configure_rx_ring - Configure a receive ring after Reset
3783 * @adapter: board private structure
3784 * @ring: receive ring to be configured
3786 * Configure the Rx unit of the MAC after a reset.
3788 void igb_configure_rx_ring(struct igb_adapter *adapter,
3789 struct igb_ring *ring)
3791 struct e1000_hw *hw = &adapter->hw;
3792 union e1000_adv_rx_desc *rx_desc;
3793 u64 rdba = ring->dma;
3794 int reg_idx = ring->reg_idx;
3795 u32 srrctl = 0, rxdctl = 0;
3797 /* disable the queue */
3798 wr32(E1000_RXDCTL(reg_idx), 0);
3800 /* Set DMA base address registers */
3801 wr32(E1000_RDBAL(reg_idx),
3802 rdba & 0x00000000ffffffffULL);
3803 wr32(E1000_RDBAH(reg_idx), rdba >> 32);
3804 wr32(E1000_RDLEN(reg_idx),
3805 ring->count * sizeof(union e1000_adv_rx_desc));
3807 /* initialize head and tail */
3808 ring->tail = adapter->io_addr + E1000_RDT(reg_idx);
3809 wr32(E1000_RDH(reg_idx), 0);
3810 writel(0, ring->tail);
3812 /* set descriptor configuration */
3813 srrctl = IGB_RX_HDR_LEN << E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
3814 if (ring_uses_large_buffer(ring))
3815 srrctl |= IGB_RXBUFFER_3072 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
3817 srrctl |= IGB_RXBUFFER_2048 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
3818 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
3819 if (hw->mac.type >= e1000_82580)
3820 srrctl |= E1000_SRRCTL_TIMESTAMP;
3821 /* Only set Drop Enable if we are supporting multiple queues */
3822 if (adapter->vfs_allocated_count || adapter->num_rx_queues > 1)
3823 srrctl |= E1000_SRRCTL_DROP_EN;
3825 wr32(E1000_SRRCTL(reg_idx), srrctl);
3827 /* set filtering for VMDQ pools */
3828 igb_set_vmolr(adapter, reg_idx & 0x7, true);
3830 rxdctl |= IGB_RX_PTHRESH;
3831 rxdctl |= IGB_RX_HTHRESH << 8;
3832 rxdctl |= IGB_RX_WTHRESH << 16;
3834 /* initialize rx_buffer_info */
3835 memset(ring->rx_buffer_info, 0,
3836 sizeof(struct igb_rx_buffer) * ring->count);
3838 /* initialize Rx descriptor 0 */
3839 rx_desc = IGB_RX_DESC(ring, 0);
3840 rx_desc->wb.upper.length = 0;
3842 /* enable receive descriptor fetching */
3843 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
3844 wr32(E1000_RXDCTL(reg_idx), rxdctl);
3847 static void igb_set_rx_buffer_len(struct igb_adapter *adapter,
3848 struct igb_ring *rx_ring)
3850 /* set build_skb and buffer size flags */
3851 clear_ring_build_skb_enabled(rx_ring);
3852 clear_ring_uses_large_buffer(rx_ring);
3854 if (adapter->flags & IGB_FLAG_RX_LEGACY)
3857 set_ring_build_skb_enabled(rx_ring);
3859 #if (PAGE_SIZE < 8192)
3860 if (adapter->max_frame_size <= IGB_MAX_FRAME_BUILD_SKB)
3863 set_ring_uses_large_buffer(rx_ring);
3868 * igb_configure_rx - Configure receive Unit after Reset
3869 * @adapter: board private structure
3871 * Configure the Rx unit of the MAC after a reset.
3873 static void igb_configure_rx(struct igb_adapter *adapter)
3877 /* set the correct pool for the PF default MAC address in entry 0 */
3878 igb_set_default_mac_filter(adapter);
3880 /* Setup the HW Rx Head and Tail Descriptor Pointers and
3881 * the Base and Length of the Rx Descriptor Ring
3883 for (i = 0; i < adapter->num_rx_queues; i++) {
3884 struct igb_ring *rx_ring = adapter->rx_ring[i];
3886 igb_set_rx_buffer_len(adapter, rx_ring);
3887 igb_configure_rx_ring(adapter, rx_ring);
3892 * igb_free_tx_resources - Free Tx Resources per Queue
3893 * @tx_ring: Tx descriptor ring for a specific queue
3895 * Free all transmit software resources
3897 void igb_free_tx_resources(struct igb_ring *tx_ring)
3899 igb_clean_tx_ring(tx_ring);
3901 vfree(tx_ring->tx_buffer_info);
3902 tx_ring->tx_buffer_info = NULL;
3904 /* if not set, then don't free */
3908 dma_free_coherent(tx_ring->dev, tx_ring->size,
3909 tx_ring->desc, tx_ring->dma);
3911 tx_ring->desc = NULL;
3915 * igb_free_all_tx_resources - Free Tx Resources for All Queues
3916 * @adapter: board private structure
3918 * Free all transmit software resources
3920 static void igb_free_all_tx_resources(struct igb_adapter *adapter)
3924 for (i = 0; i < adapter->num_tx_queues; i++)
3925 if (adapter->tx_ring[i])
3926 igb_free_tx_resources(adapter->tx_ring[i]);
3930 * igb_clean_tx_ring - Free Tx Buffers
3931 * @tx_ring: ring to be cleaned
3933 static void igb_clean_tx_ring(struct igb_ring *tx_ring)
3935 u16 i = tx_ring->next_to_clean;
3936 struct igb_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
3938 while (i != tx_ring->next_to_use) {
3939 union e1000_adv_tx_desc *eop_desc, *tx_desc;
3941 /* Free all the Tx ring sk_buffs */
3942 dev_kfree_skb_any(tx_buffer->skb);
3944 /* unmap skb header data */
3945 dma_unmap_single(tx_ring->dev,
3946 dma_unmap_addr(tx_buffer, dma),
3947 dma_unmap_len(tx_buffer, len),
3950 /* check for eop_desc to determine the end of the packet */
3951 eop_desc = tx_buffer->next_to_watch;
3952 tx_desc = IGB_TX_DESC(tx_ring, i);
3954 /* unmap remaining buffers */
3955 while (tx_desc != eop_desc) {
3959 if (unlikely(i == tx_ring->count)) {
3961 tx_buffer = tx_ring->tx_buffer_info;
3962 tx_desc = IGB_TX_DESC(tx_ring, 0);
3965 /* unmap any remaining paged data */
3966 if (dma_unmap_len(tx_buffer, len))
3967 dma_unmap_page(tx_ring->dev,
3968 dma_unmap_addr(tx_buffer, dma),
3969 dma_unmap_len(tx_buffer, len),
3973 tx_buffer->next_to_watch = NULL;
3975 /* move us one more past the eop_desc for start of next pkt */
3978 if (unlikely(i == tx_ring->count)) {
3980 tx_buffer = tx_ring->tx_buffer_info;
3984 /* reset BQL for queue */
3985 netdev_tx_reset_queue(txring_txq(tx_ring));
3987 /* reset next_to_use and next_to_clean */
3988 tx_ring->next_to_use = 0;
3989 tx_ring->next_to_clean = 0;
3993 * igb_clean_all_tx_rings - Free Tx Buffers for all queues
3994 * @adapter: board private structure
3996 static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
4000 for (i = 0; i < adapter->num_tx_queues; i++)
4001 if (adapter->tx_ring[i])
4002 igb_clean_tx_ring(adapter->tx_ring[i]);
4006 * igb_free_rx_resources - Free Rx Resources
4007 * @rx_ring: ring to clean the resources from
4009 * Free all receive software resources
4011 void igb_free_rx_resources(struct igb_ring *rx_ring)
4013 igb_clean_rx_ring(rx_ring);
4015 vfree(rx_ring->rx_buffer_info);
4016 rx_ring->rx_buffer_info = NULL;
4018 /* if not set, then don't free */
4022 dma_free_coherent(rx_ring->dev, rx_ring->size,
4023 rx_ring->desc, rx_ring->dma);
4025 rx_ring->desc = NULL;
4029 * igb_free_all_rx_resources - Free Rx Resources for All Queues
4030 * @adapter: board private structure
4032 * Free all receive software resources
4034 static void igb_free_all_rx_resources(struct igb_adapter *adapter)
4038 for (i = 0; i < adapter->num_rx_queues; i++)
4039 if (adapter->rx_ring[i])
4040 igb_free_rx_resources(adapter->rx_ring[i]);
4044 * igb_clean_rx_ring - Free Rx Buffers per Queue
4045 * @rx_ring: ring to free buffers from
4047 static void igb_clean_rx_ring(struct igb_ring *rx_ring)
4049 u16 i = rx_ring->next_to_clean;
4052 dev_kfree_skb(rx_ring->skb);
4053 rx_ring->skb = NULL;
4055 /* Free all the Rx ring sk_buffs */
4056 while (i != rx_ring->next_to_alloc) {
4057 struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];
4059 /* Invalidate cache lines that may have been written to by
4060 * device so that we avoid corrupting memory.
4062 dma_sync_single_range_for_cpu(rx_ring->dev,
4064 buffer_info->page_offset,
4065 igb_rx_bufsz(rx_ring),
4068 /* free resources associated with mapping */
4069 dma_unmap_page_attrs(rx_ring->dev,
4071 igb_rx_pg_size(rx_ring),
4074 __page_frag_cache_drain(buffer_info->page,
4075 buffer_info->pagecnt_bias);
4078 if (i == rx_ring->count)
4082 rx_ring->next_to_alloc = 0;
4083 rx_ring->next_to_clean = 0;
4084 rx_ring->next_to_use = 0;
4088 * igb_clean_all_rx_rings - Free Rx Buffers for all queues
4089 * @adapter: board private structure
4091 static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
4095 for (i = 0; i < adapter->num_rx_queues; i++)
4096 if (adapter->rx_ring[i])
4097 igb_clean_rx_ring(adapter->rx_ring[i]);
4101 * igb_set_mac - Change the Ethernet Address of the NIC
4102 * @netdev: network interface device structure
4103 * @p: pointer to an address structure
4105 * Returns 0 on success, negative on failure
4107 static int igb_set_mac(struct net_device *netdev, void *p)
4109 struct igb_adapter *adapter = netdev_priv(netdev);
4110 struct e1000_hw *hw = &adapter->hw;
4111 struct sockaddr *addr = p;
4113 if (!is_valid_ether_addr(addr->sa_data))
4114 return -EADDRNOTAVAIL;
4116 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4117 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
4119 /* set the correct pool for the new PF MAC address in entry 0 */
4120 igb_set_default_mac_filter(adapter);
4126 * igb_write_mc_addr_list - write multicast addresses to MTA
4127 * @netdev: network interface device structure
4129 * Writes multicast address list to the MTA hash table.
4130 * Returns: -ENOMEM on failure
4131 * 0 on no addresses written
4132 * X on writing X addresses to MTA
4134 static int igb_write_mc_addr_list(struct net_device *netdev)
4136 struct igb_adapter *adapter = netdev_priv(netdev);
4137 struct e1000_hw *hw = &adapter->hw;
4138 struct netdev_hw_addr *ha;
4142 if (netdev_mc_empty(netdev)) {
4143 /* nothing to program, so clear mc list */
4144 igb_update_mc_addr_list(hw, NULL, 0);
4145 igb_restore_vf_multicasts(adapter);
4149 mta_list = kzalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
4153 /* The shared function expects a packed array of only addresses. */
4155 netdev_for_each_mc_addr(ha, netdev)
4156 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
4158 igb_update_mc_addr_list(hw, mta_list, i);
4161 return netdev_mc_count(netdev);
4164 static int igb_vlan_promisc_enable(struct igb_adapter *adapter)
4166 struct e1000_hw *hw = &adapter->hw;
4169 switch (hw->mac.type) {
4173 /* VLAN filtering needed for VLAN prio filter */
4174 if (adapter->netdev->features & NETIF_F_NTUPLE)
4180 /* VLAN filtering needed for pool filtering */
4181 if (adapter->vfs_allocated_count)
4188 /* We are already in VLAN promisc, nothing to do */
4189 if (adapter->flags & IGB_FLAG_VLAN_PROMISC)
4192 if (!adapter->vfs_allocated_count)
4195 /* Add PF to all active pools */
4196 pf_id = adapter->vfs_allocated_count + E1000_VLVF_POOLSEL_SHIFT;
4198 for (i = E1000_VLVF_ARRAY_SIZE; --i;) {
4199 u32 vlvf = rd32(E1000_VLVF(i));
4202 wr32(E1000_VLVF(i), vlvf);
4206 /* Set all bits in the VLAN filter table array */
4207 for (i = E1000_VLAN_FILTER_TBL_SIZE; i--;)
4208 hw->mac.ops.write_vfta(hw, i, ~0U);
4210 /* Set flag so we don't redo unnecessary work */
4211 adapter->flags |= IGB_FLAG_VLAN_PROMISC;
4216 #define VFTA_BLOCK_SIZE 8
4217 static void igb_scrub_vfta(struct igb_adapter *adapter, u32 vfta_offset)
4219 struct e1000_hw *hw = &adapter->hw;
4220 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4221 u32 vid_start = vfta_offset * 32;
4222 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4223 u32 i, vid, word, bits, pf_id;
4225 /* guarantee that we don't scrub out management VLAN */
4226 vid = adapter->mng_vlan_id;
4227 if (vid >= vid_start && vid < vid_end)
4228 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
4230 if (!adapter->vfs_allocated_count)
4233 pf_id = adapter->vfs_allocated_count + E1000_VLVF_POOLSEL_SHIFT;
4235 for (i = E1000_VLVF_ARRAY_SIZE; --i;) {
4236 u32 vlvf = rd32(E1000_VLVF(i));
4238 /* pull VLAN ID from VLVF */
4239 vid = vlvf & VLAN_VID_MASK;
4241 /* only concern ourselves with a certain range */
4242 if (vid < vid_start || vid >= vid_end)
4245 if (vlvf & E1000_VLVF_VLANID_ENABLE) {
4246 /* record VLAN ID in VFTA */
4247 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
4249 /* if PF is part of this then continue */
4250 if (test_bit(vid, adapter->active_vlans))
4254 /* remove PF from the pool */
4256 bits &= rd32(E1000_VLVF(i));
4257 wr32(E1000_VLVF(i), bits);
4261 /* extract values from active_vlans and write back to VFTA */
4262 for (i = VFTA_BLOCK_SIZE; i--;) {
4263 vid = (vfta_offset + i) * 32;
4264 word = vid / BITS_PER_LONG;
4265 bits = vid % BITS_PER_LONG;
4267 vfta[i] |= adapter->active_vlans[word] >> bits;
4269 hw->mac.ops.write_vfta(hw, vfta_offset + i, vfta[i]);
4273 static void igb_vlan_promisc_disable(struct igb_adapter *adapter)
4277 /* We are not in VLAN promisc, nothing to do */
4278 if (!(adapter->flags & IGB_FLAG_VLAN_PROMISC))
4281 /* Set flag so we don't redo unnecessary work */
4282 adapter->flags &= ~IGB_FLAG_VLAN_PROMISC;
4284 for (i = 0; i < E1000_VLAN_FILTER_TBL_SIZE; i += VFTA_BLOCK_SIZE)
4285 igb_scrub_vfta(adapter, i);
4289 * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
4290 * @netdev: network interface device structure
4292 * The set_rx_mode entry point is called whenever the unicast or multicast
4293 * address lists or the network interface flags are updated. This routine is
4294 * responsible for configuring the hardware for proper unicast, multicast,
4295 * promiscuous mode, and all-multi behavior.
4297 static void igb_set_rx_mode(struct net_device *netdev)
4299 struct igb_adapter *adapter = netdev_priv(netdev);
4300 struct e1000_hw *hw = &adapter->hw;
4301 unsigned int vfn = adapter->vfs_allocated_count;
4302 u32 rctl = 0, vmolr = 0, rlpml = MAX_JUMBO_FRAME_SIZE;
4305 /* Check for Promiscuous and All Multicast modes */
4306 if (netdev->flags & IFF_PROMISC) {
4307 rctl |= E1000_RCTL_UPE | E1000_RCTL_MPE;
4308 vmolr |= E1000_VMOLR_MPME;
4310 /* enable use of UTA filter to force packets to default pool */
4311 if (hw->mac.type == e1000_82576)
4312 vmolr |= E1000_VMOLR_ROPE;
4314 if (netdev->flags & IFF_ALLMULTI) {
4315 rctl |= E1000_RCTL_MPE;
4316 vmolr |= E1000_VMOLR_MPME;
4318 /* Write addresses to the MTA, if the attempt fails
4319 * then we should just turn on promiscuous mode so
4320 * that we can at least receive multicast traffic
4322 count = igb_write_mc_addr_list(netdev);
4324 rctl |= E1000_RCTL_MPE;
4325 vmolr |= E1000_VMOLR_MPME;
4327 vmolr |= E1000_VMOLR_ROMPE;
4332 /* Write addresses to available RAR registers, if there is not
4333 * sufficient space to store all the addresses then enable
4334 * unicast promiscuous mode
4336 if (__dev_uc_sync(netdev, igb_uc_sync, igb_uc_unsync)) {
4337 rctl |= E1000_RCTL_UPE;
4338 vmolr |= E1000_VMOLR_ROPE;
4341 /* enable VLAN filtering by default */
4342 rctl |= E1000_RCTL_VFE;
4344 /* disable VLAN filtering for modes that require it */
4345 if ((netdev->flags & IFF_PROMISC) ||
4346 (netdev->features & NETIF_F_RXALL)) {
4347 /* if we fail to set all rules then just clear VFE */
4348 if (igb_vlan_promisc_enable(adapter))
4349 rctl &= ~E1000_RCTL_VFE;
4351 igb_vlan_promisc_disable(adapter);
4354 /* update state of unicast, multicast, and VLAN filtering modes */
4355 rctl |= rd32(E1000_RCTL) & ~(E1000_RCTL_UPE | E1000_RCTL_MPE |
4357 wr32(E1000_RCTL, rctl);
4359 #if (PAGE_SIZE < 8192)
4360 if (!adapter->vfs_allocated_count) {
4361 if (adapter->max_frame_size <= IGB_MAX_FRAME_BUILD_SKB)
4362 rlpml = IGB_MAX_FRAME_BUILD_SKB;
4365 wr32(E1000_RLPML, rlpml);
4367 /* In order to support SR-IOV and eventually VMDq it is necessary to set
4368 * the VMOLR to enable the appropriate modes. Without this workaround
4369 * we will have issues with VLAN tag stripping not being done for frames
4370 * that are only arriving because we are the default pool
4372 if ((hw->mac.type < e1000_82576) || (hw->mac.type > e1000_i350))
4375 /* set UTA to appropriate mode */
4376 igb_set_uta(adapter, !!(vmolr & E1000_VMOLR_ROPE));
4378 vmolr |= rd32(E1000_VMOLR(vfn)) &
4379 ~(E1000_VMOLR_ROPE | E1000_VMOLR_MPME | E1000_VMOLR_ROMPE);
4381 /* enable Rx jumbo frames, restrict as needed to support build_skb */
4382 vmolr &= ~E1000_VMOLR_RLPML_MASK;
4383 #if (PAGE_SIZE < 8192)
4384 if (adapter->max_frame_size <= IGB_MAX_FRAME_BUILD_SKB)
4385 vmolr |= IGB_MAX_FRAME_BUILD_SKB;
4388 vmolr |= MAX_JUMBO_FRAME_SIZE;
4389 vmolr |= E1000_VMOLR_LPE;
4391 wr32(E1000_VMOLR(vfn), vmolr);
4393 igb_restore_vf_multicasts(adapter);
4396 static void igb_check_wvbr(struct igb_adapter *adapter)
4398 struct e1000_hw *hw = &adapter->hw;
4401 switch (hw->mac.type) {
4404 wvbr = rd32(E1000_WVBR);
4412 adapter->wvbr |= wvbr;
4415 #define IGB_STAGGERED_QUEUE_OFFSET 8
4417 static void igb_spoof_check(struct igb_adapter *adapter)
4424 for (j = 0; j < adapter->vfs_allocated_count; j++) {
4425 if (adapter->wvbr & BIT(j) ||
4426 adapter->wvbr & BIT(j + IGB_STAGGERED_QUEUE_OFFSET)) {
4427 dev_warn(&adapter->pdev->dev,
4428 "Spoof event(s) detected on VF %d\n", j);
4431 BIT(j + IGB_STAGGERED_QUEUE_OFFSET));
4436 /* Need to wait a few seconds after link up to get diagnostic information from
4439 static void igb_update_phy_info(unsigned long data)
4441 struct igb_adapter *adapter = (struct igb_adapter *) data;
4442 igb_get_phy_info(&adapter->hw);
4446 * igb_has_link - check shared code for link and determine up/down
4447 * @adapter: pointer to driver private info
4449 bool igb_has_link(struct igb_adapter *adapter)
4451 struct e1000_hw *hw = &adapter->hw;
4452 bool link_active = false;
4454 /* get_link_status is set on LSC (link status) interrupt or
4455 * rx sequence error interrupt. get_link_status will stay
4456 * false until the e1000_check_for_link establishes link
4457 * for copper adapters ONLY
4459 switch (hw->phy.media_type) {
4460 case e1000_media_type_copper:
4461 if (!hw->mac.get_link_status)
4463 case e1000_media_type_internal_serdes:
4464 hw->mac.ops.check_for_link(hw);
4465 link_active = !hw->mac.get_link_status;
4468 case e1000_media_type_unknown:
4472 if (((hw->mac.type == e1000_i210) ||
4473 (hw->mac.type == e1000_i211)) &&
4474 (hw->phy.id == I210_I_PHY_ID)) {
4475 if (!netif_carrier_ok(adapter->netdev)) {
4476 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
4477 } else if (!(adapter->flags & IGB_FLAG_NEED_LINK_UPDATE)) {
4478 adapter->flags |= IGB_FLAG_NEED_LINK_UPDATE;
4479 adapter->link_check_timeout = jiffies;
4486 static bool igb_thermal_sensor_event(struct e1000_hw *hw, u32 event)
4489 u32 ctrl_ext, thstat;
4491 /* check for thermal sensor event on i350 copper only */
4492 if (hw->mac.type == e1000_i350) {
4493 thstat = rd32(E1000_THSTAT);
4494 ctrl_ext = rd32(E1000_CTRL_EXT);
4496 if ((hw->phy.media_type == e1000_media_type_copper) &&
4497 !(ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII))
4498 ret = !!(thstat & event);
4505 * igb_check_lvmmc - check for malformed packets received
4506 * and indicated in LVMMC register
4507 * @adapter: pointer to adapter
4509 static void igb_check_lvmmc(struct igb_adapter *adapter)
4511 struct e1000_hw *hw = &adapter->hw;
4514 lvmmc = rd32(E1000_LVMMC);
4516 if (unlikely(net_ratelimit())) {
4517 netdev_warn(adapter->netdev,
4518 "malformed Tx packet detected and dropped, LVMMC:0x%08x\n",
4525 * igb_watchdog - Timer Call-back
4526 * @data: pointer to adapter cast into an unsigned long
4528 static void igb_watchdog(unsigned long data)
4530 struct igb_adapter *adapter = (struct igb_adapter *)data;
4531 /* Do the rest outside of interrupt context */
4532 schedule_work(&adapter->watchdog_task);
4535 static void igb_watchdog_task(struct work_struct *work)
4537 struct igb_adapter *adapter = container_of(work,
4540 struct e1000_hw *hw = &adapter->hw;
4541 struct e1000_phy_info *phy = &hw->phy;
4542 struct net_device *netdev = adapter->netdev;
4546 u16 phy_data, retry_count = 20;
4548 link = igb_has_link(adapter);
4550 if (adapter->flags & IGB_FLAG_NEED_LINK_UPDATE) {
4551 if (time_after(jiffies, (adapter->link_check_timeout + HZ)))
4552 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
4557 /* Force link down if we have fiber to swap to */
4558 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
4559 if (hw->phy.media_type == e1000_media_type_copper) {
4560 connsw = rd32(E1000_CONNSW);
4561 if (!(connsw & E1000_CONNSW_AUTOSENSE_EN))
4566 /* Perform a reset if the media type changed. */
4567 if (hw->dev_spec._82575.media_changed) {
4568 hw->dev_spec._82575.media_changed = false;
4569 adapter->flags |= IGB_FLAG_MEDIA_RESET;
4572 /* Cancel scheduled suspend requests. */
4573 pm_runtime_resume(netdev->dev.parent);
4575 if (!netif_carrier_ok(netdev)) {
4578 hw->mac.ops.get_speed_and_duplex(hw,
4579 &adapter->link_speed,
4580 &adapter->link_duplex);
4582 ctrl = rd32(E1000_CTRL);
4583 /* Links status message must follow this format */
4585 "igb: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4587 adapter->link_speed,
4588 adapter->link_duplex == FULL_DUPLEX ?
4590 (ctrl & E1000_CTRL_TFCE) &&
4591 (ctrl & E1000_CTRL_RFCE) ? "RX/TX" :
4592 (ctrl & E1000_CTRL_RFCE) ? "RX" :
4593 (ctrl & E1000_CTRL_TFCE) ? "TX" : "None");
4595 /* disable EEE if enabled */
4596 if ((adapter->flags & IGB_FLAG_EEE) &&
4597 (adapter->link_duplex == HALF_DUPLEX)) {
4598 dev_info(&adapter->pdev->dev,
4599 "EEE Disabled: unsupported at half duplex. Re-enable using ethtool when at full duplex.\n");
4600 adapter->hw.dev_spec._82575.eee_disable = true;
4601 adapter->flags &= ~IGB_FLAG_EEE;
4604 /* check if SmartSpeed worked */
4605 igb_check_downshift(hw);
4606 if (phy->speed_downgraded)
4607 netdev_warn(netdev, "Link Speed was downgraded by SmartSpeed\n");
4609 /* check for thermal sensor event */
4610 if (igb_thermal_sensor_event(hw,
4611 E1000_THSTAT_LINK_THROTTLE))
4612 netdev_info(netdev, "The network adapter link speed was downshifted because it overheated\n");
4614 /* adjust timeout factor according to speed/duplex */
4615 adapter->tx_timeout_factor = 1;
4616 switch (adapter->link_speed) {
4618 adapter->tx_timeout_factor = 14;
4621 /* maybe add some timeout factor ? */
4625 if (adapter->link_speed != SPEED_1000)
4628 /* wait for Remote receiver status OK */
4630 if (!igb_read_phy_reg(hw, PHY_1000T_STATUS,
4632 if (!(phy_data & SR_1000T_REMOTE_RX_STATUS) &&
4636 goto retry_read_status;
4637 } else if (!retry_count) {
4638 dev_err(&adapter->pdev->dev, "exceed max 2 second\n");
4641 dev_err(&adapter->pdev->dev, "read 1000Base-T Status Reg\n");
4644 netif_carrier_on(netdev);
4646 igb_ping_all_vfs(adapter);
4647 igb_check_vf_rate_limit(adapter);
4649 /* link state has changed, schedule phy info update */
4650 if (!test_bit(__IGB_DOWN, &adapter->state))
4651 mod_timer(&adapter->phy_info_timer,
4652 round_jiffies(jiffies + 2 * HZ));
4655 if (netif_carrier_ok(netdev)) {
4656 adapter->link_speed = 0;
4657 adapter->link_duplex = 0;
4659 /* check for thermal sensor event */
4660 if (igb_thermal_sensor_event(hw,
4661 E1000_THSTAT_PWR_DOWN)) {
4662 netdev_err(netdev, "The network adapter was stopped because it overheated\n");
4665 /* Links status message must follow this format */
4666 netdev_info(netdev, "igb: %s NIC Link is Down\n",
4668 netif_carrier_off(netdev);
4670 igb_ping_all_vfs(adapter);
4672 /* link state has changed, schedule phy info update */
4673 if (!test_bit(__IGB_DOWN, &adapter->state))
4674 mod_timer(&adapter->phy_info_timer,
4675 round_jiffies(jiffies + 2 * HZ));
4677 /* link is down, time to check for alternate media */
4678 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
4679 igb_check_swap_media(adapter);
4680 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
4681 schedule_work(&adapter->reset_task);
4682 /* return immediately */
4686 pm_schedule_suspend(netdev->dev.parent,
4689 /* also check for alternate media here */
4690 } else if (!netif_carrier_ok(netdev) &&
4691 (adapter->flags & IGB_FLAG_MAS_ENABLE)) {
4692 igb_check_swap_media(adapter);
4693 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
4694 schedule_work(&adapter->reset_task);
4695 /* return immediately */
4701 spin_lock(&adapter->stats64_lock);
4702 igb_update_stats(adapter);
4703 spin_unlock(&adapter->stats64_lock);
4705 for (i = 0; i < adapter->num_tx_queues; i++) {
4706 struct igb_ring *tx_ring = adapter->tx_ring[i];
4707 if (!netif_carrier_ok(netdev)) {
4708 /* We've lost link, so the controller stops DMA,
4709 * but we've got queued Tx work that's never going
4710 * to get done, so reset controller to flush Tx.
4711 * (Do the reset outside of interrupt context).
4713 if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) {
4714 adapter->tx_timeout_count++;
4715 schedule_work(&adapter->reset_task);
4716 /* return immediately since reset is imminent */
4721 /* Force detection of hung controller every watchdog period */
4722 set_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
4725 /* Cause software interrupt to ensure Rx ring is cleaned */
4726 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
4729 for (i = 0; i < adapter->num_q_vectors; i++)
4730 eics |= adapter->q_vector[i]->eims_value;
4731 wr32(E1000_EICS, eics);
4733 wr32(E1000_ICS, E1000_ICS_RXDMT0);
4736 igb_spoof_check(adapter);
4737 igb_ptp_rx_hang(adapter);
4738 igb_ptp_tx_hang(adapter);
4740 /* Check LVMMC register on i350/i354 only */
4741 if ((adapter->hw.mac.type == e1000_i350) ||
4742 (adapter->hw.mac.type == e1000_i354))
4743 igb_check_lvmmc(adapter);
4745 /* Reset the timer */
4746 if (!test_bit(__IGB_DOWN, &adapter->state)) {
4747 if (adapter->flags & IGB_FLAG_NEED_LINK_UPDATE)
4748 mod_timer(&adapter->watchdog_timer,
4749 round_jiffies(jiffies + HZ));
4751 mod_timer(&adapter->watchdog_timer,
4752 round_jiffies(jiffies + 2 * HZ));
4756 enum latency_range {
4760 latency_invalid = 255
4764 * igb_update_ring_itr - update the dynamic ITR value based on packet size
4765 * @q_vector: pointer to q_vector
4767 * Stores a new ITR value based on strictly on packet size. This
4768 * algorithm is less sophisticated than that used in igb_update_itr,
4769 * due to the difficulty of synchronizing statistics across multiple
4770 * receive rings. The divisors and thresholds used by this function
4771 * were determined based on theoretical maximum wire speed and testing
4772 * data, in order to minimize response time while increasing bulk
4774 * This functionality is controlled by ethtool's coalescing settings.
4775 * NOTE: This function is called only when operating in a multiqueue
4776 * receive environment.
4778 static void igb_update_ring_itr(struct igb_q_vector *q_vector)
4780 int new_val = q_vector->itr_val;
4781 int avg_wire_size = 0;
4782 struct igb_adapter *adapter = q_vector->adapter;
4783 unsigned int packets;
4785 /* For non-gigabit speeds, just fix the interrupt rate at 4000
4786 * ints/sec - ITR timer value of 120 ticks.
4788 if (adapter->link_speed != SPEED_1000) {
4789 new_val = IGB_4K_ITR;
4793 packets = q_vector->rx.total_packets;
4795 avg_wire_size = q_vector->rx.total_bytes / packets;
4797 packets = q_vector->tx.total_packets;
4799 avg_wire_size = max_t(u32, avg_wire_size,
4800 q_vector->tx.total_bytes / packets);
4802 /* if avg_wire_size isn't set no work was done */
4806 /* Add 24 bytes to size to account for CRC, preamble, and gap */
4807 avg_wire_size += 24;
4809 /* Don't starve jumbo frames */
4810 avg_wire_size = min(avg_wire_size, 3000);
4812 /* Give a little boost to mid-size frames */
4813 if ((avg_wire_size > 300) && (avg_wire_size < 1200))
4814 new_val = avg_wire_size / 3;
4816 new_val = avg_wire_size / 2;
4818 /* conservative mode (itr 3) eliminates the lowest_latency setting */
4819 if (new_val < IGB_20K_ITR &&
4820 ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
4821 (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
4822 new_val = IGB_20K_ITR;
4825 if (new_val != q_vector->itr_val) {
4826 q_vector->itr_val = new_val;
4827 q_vector->set_itr = 1;
4830 q_vector->rx.total_bytes = 0;
4831 q_vector->rx.total_packets = 0;
4832 q_vector->tx.total_bytes = 0;
4833 q_vector->tx.total_packets = 0;
4837 * igb_update_itr - update the dynamic ITR value based on statistics
4838 * @q_vector: pointer to q_vector
4839 * @ring_container: ring info to update the itr for
4841 * Stores a new ITR value based on packets and byte
4842 * counts during the last interrupt. The advantage of per interrupt
4843 * computation is faster updates and more accurate ITR for the current
4844 * traffic pattern. Constants in this function were computed
4845 * based on theoretical maximum wire speed and thresholds were set based
4846 * on testing data as well as attempting to minimize response time
4847 * while increasing bulk throughput.
4848 * This functionality is controlled by ethtool's coalescing settings.
4849 * NOTE: These calculations are only valid when operating in a single-
4850 * queue environment.
4852 static void igb_update_itr(struct igb_q_vector *q_vector,
4853 struct igb_ring_container *ring_container)
4855 unsigned int packets = ring_container->total_packets;
4856 unsigned int bytes = ring_container->total_bytes;
4857 u8 itrval = ring_container->itr;
4859 /* no packets, exit with status unchanged */
4864 case lowest_latency:
4865 /* handle TSO and jumbo frames */
4866 if (bytes/packets > 8000)
4867 itrval = bulk_latency;
4868 else if ((packets < 5) && (bytes > 512))
4869 itrval = low_latency;
4871 case low_latency: /* 50 usec aka 20000 ints/s */
4872 if (bytes > 10000) {
4873 /* this if handles the TSO accounting */
4874 if (bytes/packets > 8000)
4875 itrval = bulk_latency;
4876 else if ((packets < 10) || ((bytes/packets) > 1200))
4877 itrval = bulk_latency;
4878 else if ((packets > 35))
4879 itrval = lowest_latency;
4880 } else if (bytes/packets > 2000) {
4881 itrval = bulk_latency;
4882 } else if (packets <= 2 && bytes < 512) {
4883 itrval = lowest_latency;
4886 case bulk_latency: /* 250 usec aka 4000 ints/s */
4887 if (bytes > 25000) {
4889 itrval = low_latency;
4890 } else if (bytes < 1500) {
4891 itrval = low_latency;
4896 /* clear work counters since we have the values we need */
4897 ring_container->total_bytes = 0;
4898 ring_container->total_packets = 0;
4900 /* write updated itr to ring container */
4901 ring_container->itr = itrval;
4904 static void igb_set_itr(struct igb_q_vector *q_vector)
4906 struct igb_adapter *adapter = q_vector->adapter;
4907 u32 new_itr = q_vector->itr_val;
4910 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
4911 if (adapter->link_speed != SPEED_1000) {
4913 new_itr = IGB_4K_ITR;
4917 igb_update_itr(q_vector, &q_vector->tx);
4918 igb_update_itr(q_vector, &q_vector->rx);
4920 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
4922 /* conservative mode (itr 3) eliminates the lowest_latency setting */
4923 if (current_itr == lowest_latency &&
4924 ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
4925 (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
4926 current_itr = low_latency;
4928 switch (current_itr) {
4929 /* counts and packets in update_itr are dependent on these numbers */
4930 case lowest_latency:
4931 new_itr = IGB_70K_ITR; /* 70,000 ints/sec */
4934 new_itr = IGB_20K_ITR; /* 20,000 ints/sec */
4937 new_itr = IGB_4K_ITR; /* 4,000 ints/sec */
4944 if (new_itr != q_vector->itr_val) {
4945 /* this attempts to bias the interrupt rate towards Bulk
4946 * by adding intermediate steps when interrupt rate is
4949 new_itr = new_itr > q_vector->itr_val ?
4950 max((new_itr * q_vector->itr_val) /
4951 (new_itr + (q_vector->itr_val >> 2)),
4953 /* Don't write the value here; it resets the adapter's
4954 * internal timer, and causes us to delay far longer than
4955 * we should between interrupts. Instead, we write the ITR
4956 * value at the beginning of the next interrupt so the timing
4957 * ends up being correct.
4959 q_vector->itr_val = new_itr;
4960 q_vector->set_itr = 1;
4964 static void igb_tx_ctxtdesc(struct igb_ring *tx_ring, u32 vlan_macip_lens,
4965 u32 type_tucmd, u32 mss_l4len_idx)
4967 struct e1000_adv_tx_context_desc *context_desc;
4968 u16 i = tx_ring->next_to_use;
4970 context_desc = IGB_TX_CTXTDESC(tx_ring, i);
4973 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
4975 /* set bits to identify this as an advanced context descriptor */
4976 type_tucmd |= E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
4978 /* For 82575, context index must be unique per ring. */
4979 if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
4980 mss_l4len_idx |= tx_ring->reg_idx << 4;
4982 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4983 context_desc->seqnum_seed = 0;
4984 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
4985 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
4988 static int igb_tso(struct igb_ring *tx_ring,
4989 struct igb_tx_buffer *first,
4992 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
4993 struct sk_buff *skb = first->skb;
5003 u32 paylen, l4_offset;
5006 if (skb->ip_summed != CHECKSUM_PARTIAL)
5009 if (!skb_is_gso(skb))
5012 err = skb_cow_head(skb, 0);
5016 ip.hdr = skb_network_header(skb);
5017 l4.hdr = skb_checksum_start(skb);
5019 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5020 type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
5022 /* initialize outer IP header fields */
5023 if (ip.v4->version == 4) {
5024 unsigned char *csum_start = skb_checksum_start(skb);
5025 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
5027 /* IP header will have to cancel out any data that
5028 * is not a part of the outer IP header
5030 ip.v4->check = csum_fold(csum_partial(trans_start,
5031 csum_start - trans_start,
5033 type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
5036 first->tx_flags |= IGB_TX_FLAGS_TSO |
5040 ip.v6->payload_len = 0;
5041 first->tx_flags |= IGB_TX_FLAGS_TSO |
5045 /* determine offset of inner transport header */
5046 l4_offset = l4.hdr - skb->data;
5048 /* compute length of segmentation header */
5049 *hdr_len = (l4.tcp->doff * 4) + l4_offset;
5051 /* remove payload length from inner checksum */
5052 paylen = skb->len - l4_offset;
5053 csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
5055 /* update gso size and bytecount with header size */
5056 first->gso_segs = skb_shinfo(skb)->gso_segs;
5057 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5060 mss_l4len_idx = (*hdr_len - l4_offset) << E1000_ADVTXD_L4LEN_SHIFT;
5061 mss_l4len_idx |= skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT;
5063 /* VLAN MACLEN IPLEN */
5064 vlan_macip_lens = l4.hdr - ip.hdr;
5065 vlan_macip_lens |= (ip.hdr - skb->data) << E1000_ADVTXD_MACLEN_SHIFT;
5066 vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
5068 igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
5073 static inline bool igb_ipv6_csum_is_sctp(struct sk_buff *skb)
5075 unsigned int offset = 0;
5077 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
5079 return offset == skb_checksum_start_offset(skb);
5082 static void igb_tx_csum(struct igb_ring *tx_ring, struct igb_tx_buffer *first)
5084 struct sk_buff *skb = first->skb;
5085 u32 vlan_macip_lens = 0;
5088 if (skb->ip_summed != CHECKSUM_PARTIAL) {
5090 if (!(first->tx_flags & IGB_TX_FLAGS_VLAN))
5095 switch (skb->csum_offset) {
5096 case offsetof(struct tcphdr, check):
5097 type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
5099 case offsetof(struct udphdr, check):
5101 case offsetof(struct sctphdr, checksum):
5102 /* validate that this is actually an SCTP request */
5103 if (((first->protocol == htons(ETH_P_IP)) &&
5104 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
5105 ((first->protocol == htons(ETH_P_IPV6)) &&
5106 igb_ipv6_csum_is_sctp(skb))) {
5107 type_tucmd = E1000_ADVTXD_TUCMD_L4T_SCTP;
5111 skb_checksum_help(skb);
5115 /* update TX checksum flag */
5116 first->tx_flags |= IGB_TX_FLAGS_CSUM;
5117 vlan_macip_lens = skb_checksum_start_offset(skb) -
5118 skb_network_offset(skb);
5120 vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
5121 vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
5123 igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, 0);
5126 #define IGB_SET_FLAG(_input, _flag, _result) \
5127 ((_flag <= _result) ? \
5128 ((u32)(_input & _flag) * (_result / _flag)) : \
5129 ((u32)(_input & _flag) / (_flag / _result)))
5131 static u32 igb_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
5133 /* set type for advanced descriptor with frame checksum insertion */
5134 u32 cmd_type = E1000_ADVTXD_DTYP_DATA |
5135 E1000_ADVTXD_DCMD_DEXT |
5136 E1000_ADVTXD_DCMD_IFCS;
5138 /* set HW vlan bit if vlan is present */
5139 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_VLAN,
5140 (E1000_ADVTXD_DCMD_VLE));
5142 /* set segmentation bits for TSO */
5143 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_TSO,
5144 (E1000_ADVTXD_DCMD_TSE));
5146 /* set timestamp bit if present */
5147 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_TSTAMP,
5148 (E1000_ADVTXD_MAC_TSTAMP));
5150 /* insert frame checksum */
5151 cmd_type ^= IGB_SET_FLAG(skb->no_fcs, 1, E1000_ADVTXD_DCMD_IFCS);
5156 static void igb_tx_olinfo_status(struct igb_ring *tx_ring,
5157 union e1000_adv_tx_desc *tx_desc,
5158 u32 tx_flags, unsigned int paylen)
5160 u32 olinfo_status = paylen << E1000_ADVTXD_PAYLEN_SHIFT;
5162 /* 82575 requires a unique index per ring */
5163 if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
5164 olinfo_status |= tx_ring->reg_idx << 4;
5166 /* insert L4 checksum */
5167 olinfo_status |= IGB_SET_FLAG(tx_flags,
5169 (E1000_TXD_POPTS_TXSM << 8));
5171 /* insert IPv4 checksum */
5172 olinfo_status |= IGB_SET_FLAG(tx_flags,
5174 (E1000_TXD_POPTS_IXSM << 8));
5176 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
5179 static int __igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
5181 struct net_device *netdev = tx_ring->netdev;
5183 netif_stop_subqueue(netdev, tx_ring->queue_index);
5185 /* Herbert's original patch had:
5186 * smp_mb__after_netif_stop_queue();
5187 * but since that doesn't exist yet, just open code it.
5191 /* We need to check again in a case another CPU has just
5192 * made room available.
5194 if (igb_desc_unused(tx_ring) < size)
5198 netif_wake_subqueue(netdev, tx_ring->queue_index);
5200 u64_stats_update_begin(&tx_ring->tx_syncp2);
5201 tx_ring->tx_stats.restart_queue2++;
5202 u64_stats_update_end(&tx_ring->tx_syncp2);
5207 static inline int igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
5209 if (igb_desc_unused(tx_ring) >= size)
5211 return __igb_maybe_stop_tx(tx_ring, size);
5214 static int igb_tx_map(struct igb_ring *tx_ring,
5215 struct igb_tx_buffer *first,
5218 struct sk_buff *skb = first->skb;
5219 struct igb_tx_buffer *tx_buffer;
5220 union e1000_adv_tx_desc *tx_desc;
5221 struct skb_frag_struct *frag;
5223 unsigned int data_len, size;
5224 u32 tx_flags = first->tx_flags;
5225 u32 cmd_type = igb_tx_cmd_type(skb, tx_flags);
5226 u16 i = tx_ring->next_to_use;
5228 tx_desc = IGB_TX_DESC(tx_ring, i);
5230 igb_tx_olinfo_status(tx_ring, tx_desc, tx_flags, skb->len - hdr_len);
5232 size = skb_headlen(skb);
5233 data_len = skb->data_len;
5235 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
5239 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
5240 if (dma_mapping_error(tx_ring->dev, dma))
5243 /* record length, and DMA address */
5244 dma_unmap_len_set(tx_buffer, len, size);
5245 dma_unmap_addr_set(tx_buffer, dma, dma);
5247 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5249 while (unlikely(size > IGB_MAX_DATA_PER_TXD)) {
5250 tx_desc->read.cmd_type_len =
5251 cpu_to_le32(cmd_type ^ IGB_MAX_DATA_PER_TXD);
5255 if (i == tx_ring->count) {
5256 tx_desc = IGB_TX_DESC(tx_ring, 0);
5259 tx_desc->read.olinfo_status = 0;
5261 dma += IGB_MAX_DATA_PER_TXD;
5262 size -= IGB_MAX_DATA_PER_TXD;
5264 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5267 if (likely(!data_len))
5270 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
5274 if (i == tx_ring->count) {
5275 tx_desc = IGB_TX_DESC(tx_ring, 0);
5278 tx_desc->read.olinfo_status = 0;
5280 size = skb_frag_size(frag);
5283 dma = skb_frag_dma_map(tx_ring->dev, frag, 0,
5284 size, DMA_TO_DEVICE);
5286 tx_buffer = &tx_ring->tx_buffer_info[i];
5289 /* write last descriptor with RS and EOP bits */
5290 cmd_type |= size | IGB_TXD_DCMD;
5291 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
5293 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
5295 /* set the timestamp */
5296 first->time_stamp = jiffies;
5298 /* Force memory writes to complete before letting h/w know there
5299 * are new descriptors to fetch. (Only applicable for weak-ordered
5300 * memory model archs, such as IA-64).
5302 * We also need this memory barrier to make certain all of the
5303 * status bits have been updated before next_to_watch is written.
5307 /* set next_to_watch value indicating a packet is present */
5308 first->next_to_watch = tx_desc;
5311 if (i == tx_ring->count)
5314 tx_ring->next_to_use = i;
5316 /* Make sure there is space in the ring for the next send. */
5317 igb_maybe_stop_tx(tx_ring, DESC_NEEDED);
5319 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
5320 writel(i, tx_ring->tail);
5322 /* we need this if more than one processor can write to our tail
5323 * at a time, it synchronizes IO on IA64/Altix systems
5330 dev_err(tx_ring->dev, "TX DMA map failed\n");
5331 tx_buffer = &tx_ring->tx_buffer_info[i];
5333 /* clear dma mappings for failed tx_buffer_info map */
5334 while (tx_buffer != first) {
5335 if (dma_unmap_len(tx_buffer, len))
5336 dma_unmap_page(tx_ring->dev,
5337 dma_unmap_addr(tx_buffer, dma),
5338 dma_unmap_len(tx_buffer, len),
5340 dma_unmap_len_set(tx_buffer, len, 0);
5343 i += tx_ring->count;
5344 tx_buffer = &tx_ring->tx_buffer_info[i];
5347 if (dma_unmap_len(tx_buffer, len))
5348 dma_unmap_single(tx_ring->dev,
5349 dma_unmap_addr(tx_buffer, dma),
5350 dma_unmap_len(tx_buffer, len),
5352 dma_unmap_len_set(tx_buffer, len, 0);
5354 dev_kfree_skb_any(tx_buffer->skb);
5355 tx_buffer->skb = NULL;
5357 tx_ring->next_to_use = i;
5362 netdev_tx_t igb_xmit_frame_ring(struct sk_buff *skb,
5363 struct igb_ring *tx_ring)
5365 struct igb_tx_buffer *first;
5369 u16 count = TXD_USE_COUNT(skb_headlen(skb));
5370 __be16 protocol = vlan_get_protocol(skb);
5373 /* need: 1 descriptor per page * PAGE_SIZE/IGB_MAX_DATA_PER_TXD,
5374 * + 1 desc for skb_headlen/IGB_MAX_DATA_PER_TXD,
5375 * + 2 desc gap to keep tail from touching head,
5376 * + 1 desc for context descriptor,
5377 * otherwise try next time
5379 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
5380 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
5382 if (igb_maybe_stop_tx(tx_ring, count + 3)) {
5383 /* this is a hard error */
5384 return NETDEV_TX_BUSY;
5387 /* record the location of the first descriptor for this packet */
5388 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
5390 first->bytecount = skb->len;
5391 first->gso_segs = 1;
5393 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
5394 struct igb_adapter *adapter = netdev_priv(tx_ring->netdev);
5396 if (adapter->tstamp_config.tx_type & HWTSTAMP_TX_ON &&
5397 !test_and_set_bit_lock(__IGB_PTP_TX_IN_PROGRESS,
5399 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5400 tx_flags |= IGB_TX_FLAGS_TSTAMP;
5402 adapter->ptp_tx_skb = skb_get(skb);
5403 adapter->ptp_tx_start = jiffies;
5404 if (adapter->hw.mac.type == e1000_82576)
5405 schedule_work(&adapter->ptp_tx_work);
5407 adapter->tx_hwtstamp_skipped++;
5411 skb_tx_timestamp(skb);
5413 if (skb_vlan_tag_present(skb)) {
5414 tx_flags |= IGB_TX_FLAGS_VLAN;
5415 tx_flags |= (skb_vlan_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
5418 /* record initial flags and protocol */
5419 first->tx_flags = tx_flags;
5420 first->protocol = protocol;
5422 tso = igb_tso(tx_ring, first, &hdr_len);
5426 igb_tx_csum(tx_ring, first);
5428 if (igb_tx_map(tx_ring, first, hdr_len))
5429 goto cleanup_tx_tstamp;
5431 return NETDEV_TX_OK;
5434 dev_kfree_skb_any(first->skb);
5437 if (unlikely(tx_flags & IGB_TX_FLAGS_TSTAMP)) {
5438 struct igb_adapter *adapter = netdev_priv(tx_ring->netdev);
5440 dev_kfree_skb_any(adapter->ptp_tx_skb);
5441 adapter->ptp_tx_skb = NULL;
5442 if (adapter->hw.mac.type == e1000_82576)
5443 cancel_work_sync(&adapter->ptp_tx_work);
5444 clear_bit_unlock(__IGB_PTP_TX_IN_PROGRESS, &adapter->state);
5447 return NETDEV_TX_OK;
5450 static inline struct igb_ring *igb_tx_queue_mapping(struct igb_adapter *adapter,
5451 struct sk_buff *skb)
5453 unsigned int r_idx = skb->queue_mapping;
5455 if (r_idx >= adapter->num_tx_queues)
5456 r_idx = r_idx % adapter->num_tx_queues;
5458 return adapter->tx_ring[r_idx];
5461 static netdev_tx_t igb_xmit_frame(struct sk_buff *skb,
5462 struct net_device *netdev)
5464 struct igb_adapter *adapter = netdev_priv(netdev);
5466 /* The minimum packet size with TCTL.PSP set is 17 so pad the skb
5467 * in order to meet this minimum size requirement.
5469 if (skb_put_padto(skb, 17))
5470 return NETDEV_TX_OK;
5472 return igb_xmit_frame_ring(skb, igb_tx_queue_mapping(adapter, skb));
5476 * igb_tx_timeout - Respond to a Tx Hang
5477 * @netdev: network interface device structure
5479 static void igb_tx_timeout(struct net_device *netdev)
5481 struct igb_adapter *adapter = netdev_priv(netdev);
5482 struct e1000_hw *hw = &adapter->hw;
5484 /* Do the reset outside of interrupt context */
5485 adapter->tx_timeout_count++;
5487 if (hw->mac.type >= e1000_82580)
5488 hw->dev_spec._82575.global_device_reset = true;
5490 schedule_work(&adapter->reset_task);
5492 (adapter->eims_enable_mask & ~adapter->eims_other));
5495 static void igb_reset_task(struct work_struct *work)
5497 struct igb_adapter *adapter;
5498 adapter = container_of(work, struct igb_adapter, reset_task);
5501 /* If we're already down or resetting, just bail */
5502 if (test_bit(__IGB_DOWN, &adapter->state) ||
5503 test_bit(__IGB_RESETTING, &adapter->state)) {
5509 netdev_err(adapter->netdev, "Reset adapter\n");
5510 igb_reinit_locked(adapter);
5515 * igb_get_stats64 - Get System Network Statistics
5516 * @netdev: network interface device structure
5517 * @stats: rtnl_link_stats64 pointer
5519 static void igb_get_stats64(struct net_device *netdev,
5520 struct rtnl_link_stats64 *stats)
5522 struct igb_adapter *adapter = netdev_priv(netdev);
5524 spin_lock(&adapter->stats64_lock);
5525 igb_update_stats(adapter);
5526 memcpy(stats, &adapter->stats64, sizeof(*stats));
5527 spin_unlock(&adapter->stats64_lock);
5531 * igb_change_mtu - Change the Maximum Transfer Unit
5532 * @netdev: network interface device structure
5533 * @new_mtu: new value for maximum frame size
5535 * Returns 0 on success, negative on failure
5537 static int igb_change_mtu(struct net_device *netdev, int new_mtu)
5539 struct igb_adapter *adapter = netdev_priv(netdev);
5540 struct pci_dev *pdev = adapter->pdev;
5541 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
5543 /* adjust max frame to be at least the size of a standard frame */
5544 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
5545 max_frame = ETH_FRAME_LEN + ETH_FCS_LEN;
5547 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
5548 usleep_range(1000, 2000);
5550 /* igb_down has a dependency on max_frame_size */
5551 adapter->max_frame_size = max_frame;
5553 if (netif_running(netdev))
5556 dev_info(&pdev->dev, "changing MTU from %d to %d\n",
5557 netdev->mtu, new_mtu);
5558 netdev->mtu = new_mtu;
5560 if (netif_running(netdev))
5565 clear_bit(__IGB_RESETTING, &adapter->state);
5571 * igb_update_stats - Update the board statistics counters
5572 * @adapter: board private structure
5574 void igb_update_stats(struct igb_adapter *adapter)
5576 struct rtnl_link_stats64 *net_stats = &adapter->stats64;
5577 struct e1000_hw *hw = &adapter->hw;
5578 struct pci_dev *pdev = adapter->pdev;
5583 u64 _bytes, _packets;
5585 /* Prevent stats update while adapter is being reset, or if the pci
5586 * connection is down.
5588 if (adapter->link_speed == 0)
5590 if (pci_channel_offline(pdev))
5597 for (i = 0; i < adapter->num_rx_queues; i++) {
5598 struct igb_ring *ring = adapter->rx_ring[i];
5599 u32 rqdpc = rd32(E1000_RQDPC(i));
5600 if (hw->mac.type >= e1000_i210)
5601 wr32(E1000_RQDPC(i), 0);
5604 ring->rx_stats.drops += rqdpc;
5605 net_stats->rx_fifo_errors += rqdpc;
5609 start = u64_stats_fetch_begin_irq(&ring->rx_syncp);
5610 _bytes = ring->rx_stats.bytes;
5611 _packets = ring->rx_stats.packets;
5612 } while (u64_stats_fetch_retry_irq(&ring->rx_syncp, start));
5614 packets += _packets;
5617 net_stats->rx_bytes = bytes;
5618 net_stats->rx_packets = packets;
5622 for (i = 0; i < adapter->num_tx_queues; i++) {
5623 struct igb_ring *ring = adapter->tx_ring[i];
5625 start = u64_stats_fetch_begin_irq(&ring->tx_syncp);
5626 _bytes = ring->tx_stats.bytes;
5627 _packets = ring->tx_stats.packets;
5628 } while (u64_stats_fetch_retry_irq(&ring->tx_syncp, start));
5630 packets += _packets;
5632 net_stats->tx_bytes = bytes;
5633 net_stats->tx_packets = packets;
5636 /* read stats registers */
5637 adapter->stats.crcerrs += rd32(E1000_CRCERRS);
5638 adapter->stats.gprc += rd32(E1000_GPRC);
5639 adapter->stats.gorc += rd32(E1000_GORCL);
5640 rd32(E1000_GORCH); /* clear GORCL */
5641 adapter->stats.bprc += rd32(E1000_BPRC);
5642 adapter->stats.mprc += rd32(E1000_MPRC);
5643 adapter->stats.roc += rd32(E1000_ROC);
5645 adapter->stats.prc64 += rd32(E1000_PRC64);
5646 adapter->stats.prc127 += rd32(E1000_PRC127);
5647 adapter->stats.prc255 += rd32(E1000_PRC255);
5648 adapter->stats.prc511 += rd32(E1000_PRC511);
5649 adapter->stats.prc1023 += rd32(E1000_PRC1023);
5650 adapter->stats.prc1522 += rd32(E1000_PRC1522);
5651 adapter->stats.symerrs += rd32(E1000_SYMERRS);
5652 adapter->stats.sec += rd32(E1000_SEC);
5654 mpc = rd32(E1000_MPC);
5655 adapter->stats.mpc += mpc;
5656 net_stats->rx_fifo_errors += mpc;
5657 adapter->stats.scc += rd32(E1000_SCC);
5658 adapter->stats.ecol += rd32(E1000_ECOL);
5659 adapter->stats.mcc += rd32(E1000_MCC);
5660 adapter->stats.latecol += rd32(E1000_LATECOL);
5661 adapter->stats.dc += rd32(E1000_DC);
5662 adapter->stats.rlec += rd32(E1000_RLEC);
5663 adapter->stats.xonrxc += rd32(E1000_XONRXC);
5664 adapter->stats.xontxc += rd32(E1000_XONTXC);
5665 adapter->stats.xoffrxc += rd32(E1000_XOFFRXC);
5666 adapter->stats.xofftxc += rd32(E1000_XOFFTXC);
5667 adapter->stats.fcruc += rd32(E1000_FCRUC);
5668 adapter->stats.gptc += rd32(E1000_GPTC);
5669 adapter->stats.gotc += rd32(E1000_GOTCL);
5670 rd32(E1000_GOTCH); /* clear GOTCL */
5671 adapter->stats.rnbc += rd32(E1000_RNBC);
5672 adapter->stats.ruc += rd32(E1000_RUC);
5673 adapter->stats.rfc += rd32(E1000_RFC);
5674 adapter->stats.rjc += rd32(E1000_RJC);
5675 adapter->stats.tor += rd32(E1000_TORH);
5676 adapter->stats.tot += rd32(E1000_TOTH);
5677 adapter->stats.tpr += rd32(E1000_TPR);
5679 adapter->stats.ptc64 += rd32(E1000_PTC64);
5680 adapter->stats.ptc127 += rd32(E1000_PTC127);
5681 adapter->stats.ptc255 += rd32(E1000_PTC255);
5682 adapter->stats.ptc511 += rd32(E1000_PTC511);
5683 adapter->stats.ptc1023 += rd32(E1000_PTC1023);
5684 adapter->stats.ptc1522 += rd32(E1000_PTC1522);
5686 adapter->stats.mptc += rd32(E1000_MPTC);
5687 adapter->stats.bptc += rd32(E1000_BPTC);
5689 adapter->stats.tpt += rd32(E1000_TPT);
5690 adapter->stats.colc += rd32(E1000_COLC);
5692 adapter->stats.algnerrc += rd32(E1000_ALGNERRC);
5693 /* read internal phy specific stats */
5694 reg = rd32(E1000_CTRL_EXT);
5695 if (!(reg & E1000_CTRL_EXT_LINK_MODE_MASK)) {
5696 adapter->stats.rxerrc += rd32(E1000_RXERRC);
5698 /* this stat has invalid values on i210/i211 */
5699 if ((hw->mac.type != e1000_i210) &&
5700 (hw->mac.type != e1000_i211))
5701 adapter->stats.tncrs += rd32(E1000_TNCRS);
5704 adapter->stats.tsctc += rd32(E1000_TSCTC);
5705 adapter->stats.tsctfc += rd32(E1000_TSCTFC);
5707 adapter->stats.iac += rd32(E1000_IAC);
5708 adapter->stats.icrxoc += rd32(E1000_ICRXOC);
5709 adapter->stats.icrxptc += rd32(E1000_ICRXPTC);
5710 adapter->stats.icrxatc += rd32(E1000_ICRXATC);
5711 adapter->stats.ictxptc += rd32(E1000_ICTXPTC);
5712 adapter->stats.ictxatc += rd32(E1000_ICTXATC);
5713 adapter->stats.ictxqec += rd32(E1000_ICTXQEC);
5714 adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC);
5715 adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC);
5717 /* Fill out the OS statistics structure */
5718 net_stats->multicast = adapter->stats.mprc;
5719 net_stats->collisions = adapter->stats.colc;
5723 /* RLEC on some newer hardware can be incorrect so build
5724 * our own version based on RUC and ROC
5726 net_stats->rx_errors = adapter->stats.rxerrc +
5727 adapter->stats.crcerrs + adapter->stats.algnerrc +
5728 adapter->stats.ruc + adapter->stats.roc +
5729 adapter->stats.cexterr;
5730 net_stats->rx_length_errors = adapter->stats.ruc +
5732 net_stats->rx_crc_errors = adapter->stats.crcerrs;
5733 net_stats->rx_frame_errors = adapter->stats.algnerrc;
5734 net_stats->rx_missed_errors = adapter->stats.mpc;
5737 net_stats->tx_errors = adapter->stats.ecol +
5738 adapter->stats.latecol;
5739 net_stats->tx_aborted_errors = adapter->stats.ecol;
5740 net_stats->tx_window_errors = adapter->stats.latecol;
5741 net_stats->tx_carrier_errors = adapter->stats.tncrs;
5743 /* Tx Dropped needs to be maintained elsewhere */
5745 /* Management Stats */
5746 adapter->stats.mgptc += rd32(E1000_MGTPTC);
5747 adapter->stats.mgprc += rd32(E1000_MGTPRC);
5748 adapter->stats.mgpdc += rd32(E1000_MGTPDC);
5751 reg = rd32(E1000_MANC);
5752 if (reg & E1000_MANC_EN_BMC2OS) {
5753 adapter->stats.o2bgptc += rd32(E1000_O2BGPTC);
5754 adapter->stats.o2bspc += rd32(E1000_O2BSPC);
5755 adapter->stats.b2ospc += rd32(E1000_B2OSPC);
5756 adapter->stats.b2ogprc += rd32(E1000_B2OGPRC);
5760 static void igb_tsync_interrupt(struct igb_adapter *adapter)
5762 struct e1000_hw *hw = &adapter->hw;
5763 struct ptp_clock_event event;
5764 struct timespec64 ts;
5765 u32 ack = 0, tsauxc, sec, nsec, tsicr = rd32(E1000_TSICR);
5767 if (tsicr & TSINTR_SYS_WRAP) {
5768 event.type = PTP_CLOCK_PPS;
5769 if (adapter->ptp_caps.pps)
5770 ptp_clock_event(adapter->ptp_clock, &event);
5771 ack |= TSINTR_SYS_WRAP;
5774 if (tsicr & E1000_TSICR_TXTS) {
5775 /* retrieve hardware timestamp */
5776 schedule_work(&adapter->ptp_tx_work);
5777 ack |= E1000_TSICR_TXTS;
5780 if (tsicr & TSINTR_TT0) {
5781 spin_lock(&adapter->tmreg_lock);
5782 ts = timespec64_add(adapter->perout[0].start,
5783 adapter->perout[0].period);
5784 /* u32 conversion of tv_sec is safe until y2106 */
5785 wr32(E1000_TRGTTIML0, ts.tv_nsec);
5786 wr32(E1000_TRGTTIMH0, (u32)ts.tv_sec);
5787 tsauxc = rd32(E1000_TSAUXC);
5788 tsauxc |= TSAUXC_EN_TT0;
5789 wr32(E1000_TSAUXC, tsauxc);
5790 adapter->perout[0].start = ts;
5791 spin_unlock(&adapter->tmreg_lock);
5795 if (tsicr & TSINTR_TT1) {
5796 spin_lock(&adapter->tmreg_lock);
5797 ts = timespec64_add(adapter->perout[1].start,
5798 adapter->perout[1].period);
5799 wr32(E1000_TRGTTIML1, ts.tv_nsec);
5800 wr32(E1000_TRGTTIMH1, (u32)ts.tv_sec);
5801 tsauxc = rd32(E1000_TSAUXC);
5802 tsauxc |= TSAUXC_EN_TT1;
5803 wr32(E1000_TSAUXC, tsauxc);
5804 adapter->perout[1].start = ts;
5805 spin_unlock(&adapter->tmreg_lock);
5809 if (tsicr & TSINTR_AUTT0) {
5810 nsec = rd32(E1000_AUXSTMPL0);
5811 sec = rd32(E1000_AUXSTMPH0);
5812 event.type = PTP_CLOCK_EXTTS;
5814 event.timestamp = sec * 1000000000ULL + nsec;
5815 ptp_clock_event(adapter->ptp_clock, &event);
5816 ack |= TSINTR_AUTT0;
5819 if (tsicr & TSINTR_AUTT1) {
5820 nsec = rd32(E1000_AUXSTMPL1);
5821 sec = rd32(E1000_AUXSTMPH1);
5822 event.type = PTP_CLOCK_EXTTS;
5824 event.timestamp = sec * 1000000000ULL + nsec;
5825 ptp_clock_event(adapter->ptp_clock, &event);
5826 ack |= TSINTR_AUTT1;
5829 /* acknowledge the interrupts */
5830 wr32(E1000_TSICR, ack);
5833 static irqreturn_t igb_msix_other(int irq, void *data)
5835 struct igb_adapter *adapter = data;
5836 struct e1000_hw *hw = &adapter->hw;
5837 u32 icr = rd32(E1000_ICR);
5838 /* reading ICR causes bit 31 of EICR to be cleared */
5840 if (icr & E1000_ICR_DRSTA)
5841 schedule_work(&adapter->reset_task);
5843 if (icr & E1000_ICR_DOUTSYNC) {
5844 /* HW is reporting DMA is out of sync */
5845 adapter->stats.doosync++;
5846 /* The DMA Out of Sync is also indication of a spoof event
5847 * in IOV mode. Check the Wrong VM Behavior register to
5848 * see if it is really a spoof event.
5850 igb_check_wvbr(adapter);
5853 /* Check for a mailbox event */
5854 if (icr & E1000_ICR_VMMB)
5855 igb_msg_task(adapter);
5857 if (icr & E1000_ICR_LSC) {
5858 hw->mac.get_link_status = 1;
5859 /* guard against interrupt when we're going down */
5860 if (!test_bit(__IGB_DOWN, &adapter->state))
5861 mod_timer(&adapter->watchdog_timer, jiffies + 1);
5864 if (icr & E1000_ICR_TS)
5865 igb_tsync_interrupt(adapter);
5867 wr32(E1000_EIMS, adapter->eims_other);
5872 static void igb_write_itr(struct igb_q_vector *q_vector)
5874 struct igb_adapter *adapter = q_vector->adapter;
5875 u32 itr_val = q_vector->itr_val & 0x7FFC;
5877 if (!q_vector->set_itr)
5883 if (adapter->hw.mac.type == e1000_82575)
5884 itr_val |= itr_val << 16;
5886 itr_val |= E1000_EITR_CNT_IGNR;
5888 writel(itr_val, q_vector->itr_register);
5889 q_vector->set_itr = 0;
5892 static irqreturn_t igb_msix_ring(int irq, void *data)
5894 struct igb_q_vector *q_vector = data;
5896 /* Write the ITR value calculated from the previous interrupt. */
5897 igb_write_itr(q_vector);
5899 napi_schedule(&q_vector->napi);
5904 #ifdef CONFIG_IGB_DCA
5905 static void igb_update_tx_dca(struct igb_adapter *adapter,
5906 struct igb_ring *tx_ring,
5909 struct e1000_hw *hw = &adapter->hw;
5910 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
5912 if (hw->mac.type != e1000_82575)
5913 txctrl <<= E1000_DCA_TXCTRL_CPUID_SHIFT;
5915 /* We can enable relaxed ordering for reads, but not writes when
5916 * DCA is enabled. This is due to a known issue in some chipsets
5917 * which will cause the DCA tag to be cleared.
5919 txctrl |= E1000_DCA_TXCTRL_DESC_RRO_EN |
5920 E1000_DCA_TXCTRL_DATA_RRO_EN |
5921 E1000_DCA_TXCTRL_DESC_DCA_EN;
5923 wr32(E1000_DCA_TXCTRL(tx_ring->reg_idx), txctrl);
5926 static void igb_update_rx_dca(struct igb_adapter *adapter,
5927 struct igb_ring *rx_ring,
5930 struct e1000_hw *hw = &adapter->hw;
5931 u32 rxctrl = dca3_get_tag(&adapter->pdev->dev, cpu);
5933 if (hw->mac.type != e1000_82575)
5934 rxctrl <<= E1000_DCA_RXCTRL_CPUID_SHIFT;
5936 /* We can enable relaxed ordering for reads, but not writes when
5937 * DCA is enabled. This is due to a known issue in some chipsets
5938 * which will cause the DCA tag to be cleared.
5940 rxctrl |= E1000_DCA_RXCTRL_DESC_RRO_EN |
5941 E1000_DCA_RXCTRL_DESC_DCA_EN;
5943 wr32(E1000_DCA_RXCTRL(rx_ring->reg_idx), rxctrl);
5946 static void igb_update_dca(struct igb_q_vector *q_vector)
5948 struct igb_adapter *adapter = q_vector->adapter;
5949 int cpu = get_cpu();
5951 if (q_vector->cpu == cpu)
5954 if (q_vector->tx.ring)
5955 igb_update_tx_dca(adapter, q_vector->tx.ring, cpu);
5957 if (q_vector->rx.ring)
5958 igb_update_rx_dca(adapter, q_vector->rx.ring, cpu);
5960 q_vector->cpu = cpu;
5965 static void igb_setup_dca(struct igb_adapter *adapter)
5967 struct e1000_hw *hw = &adapter->hw;
5970 if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
5973 /* Always use CB2 mode, difference is masked in the CB driver. */
5974 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
5976 for (i = 0; i < adapter->num_q_vectors; i++) {
5977 adapter->q_vector[i]->cpu = -1;
5978 igb_update_dca(adapter->q_vector[i]);
5982 static int __igb_notify_dca(struct device *dev, void *data)
5984 struct net_device *netdev = dev_get_drvdata(dev);
5985 struct igb_adapter *adapter = netdev_priv(netdev);
5986 struct pci_dev *pdev = adapter->pdev;
5987 struct e1000_hw *hw = &adapter->hw;
5988 unsigned long event = *(unsigned long *)data;
5991 case DCA_PROVIDER_ADD:
5992 /* if already enabled, don't do it again */
5993 if (adapter->flags & IGB_FLAG_DCA_ENABLED)
5995 if (dca_add_requester(dev) == 0) {
5996 adapter->flags |= IGB_FLAG_DCA_ENABLED;
5997 dev_info(&pdev->dev, "DCA enabled\n");
5998 igb_setup_dca(adapter);
6001 /* Fall Through since DCA is disabled. */
6002 case DCA_PROVIDER_REMOVE:
6003 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
6004 /* without this a class_device is left
6005 * hanging around in the sysfs model
6007 dca_remove_requester(dev);
6008 dev_info(&pdev->dev, "DCA disabled\n");
6009 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
6010 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
6018 static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
6023 ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
6026 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
6028 #endif /* CONFIG_IGB_DCA */
6030 #ifdef CONFIG_PCI_IOV
6031 static int igb_vf_configure(struct igb_adapter *adapter, int vf)
6033 unsigned char mac_addr[ETH_ALEN];
6035 eth_zero_addr(mac_addr);
6036 igb_set_vf_mac(adapter, vf, mac_addr);
6038 /* By default spoof check is enabled for all VFs */
6039 adapter->vf_data[vf].spoofchk_enabled = true;
6045 static void igb_ping_all_vfs(struct igb_adapter *adapter)
6047 struct e1000_hw *hw = &adapter->hw;
6051 for (i = 0 ; i < adapter->vfs_allocated_count; i++) {
6052 ping = E1000_PF_CONTROL_MSG;
6053 if (adapter->vf_data[i].flags & IGB_VF_FLAG_CTS)
6054 ping |= E1000_VT_MSGTYPE_CTS;
6055 igb_write_mbx(hw, &ping, 1, i);
6059 static int igb_set_vf_promisc(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
6061 struct e1000_hw *hw = &adapter->hw;
6062 u32 vmolr = rd32(E1000_VMOLR(vf));
6063 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6065 vf_data->flags &= ~(IGB_VF_FLAG_UNI_PROMISC |
6066 IGB_VF_FLAG_MULTI_PROMISC);
6067 vmolr &= ~(E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
6069 if (*msgbuf & E1000_VF_SET_PROMISC_MULTICAST) {
6070 vmolr |= E1000_VMOLR_MPME;
6071 vf_data->flags |= IGB_VF_FLAG_MULTI_PROMISC;
6072 *msgbuf &= ~E1000_VF_SET_PROMISC_MULTICAST;
6074 /* if we have hashes and we are clearing a multicast promisc
6075 * flag we need to write the hashes to the MTA as this step
6076 * was previously skipped
6078 if (vf_data->num_vf_mc_hashes > 30) {
6079 vmolr |= E1000_VMOLR_MPME;
6080 } else if (vf_data->num_vf_mc_hashes) {
6083 vmolr |= E1000_VMOLR_ROMPE;
6084 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
6085 igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
6089 wr32(E1000_VMOLR(vf), vmolr);
6091 /* there are flags left unprocessed, likely not supported */
6092 if (*msgbuf & E1000_VT_MSGINFO_MASK)
6098 static int igb_set_vf_multicasts(struct igb_adapter *adapter,
6099 u32 *msgbuf, u32 vf)
6101 int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
6102 u16 *hash_list = (u16 *)&msgbuf[1];
6103 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6106 /* salt away the number of multicast addresses assigned
6107 * to this VF for later use to restore when the PF multi cast
6110 vf_data->num_vf_mc_hashes = n;
6112 /* only up to 30 hash values supported */
6116 /* store the hashes for later use */
6117 for (i = 0; i < n; i++)
6118 vf_data->vf_mc_hashes[i] = hash_list[i];
6120 /* Flush and reset the mta with the new values */
6121 igb_set_rx_mode(adapter->netdev);
6126 static void igb_restore_vf_multicasts(struct igb_adapter *adapter)
6128 struct e1000_hw *hw = &adapter->hw;
6129 struct vf_data_storage *vf_data;
6132 for (i = 0; i < adapter->vfs_allocated_count; i++) {
6133 u32 vmolr = rd32(E1000_VMOLR(i));
6135 vmolr &= ~(E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
6137 vf_data = &adapter->vf_data[i];
6139 if ((vf_data->num_vf_mc_hashes > 30) ||
6140 (vf_data->flags & IGB_VF_FLAG_MULTI_PROMISC)) {
6141 vmolr |= E1000_VMOLR_MPME;
6142 } else if (vf_data->num_vf_mc_hashes) {
6143 vmolr |= E1000_VMOLR_ROMPE;
6144 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
6145 igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
6147 wr32(E1000_VMOLR(i), vmolr);
6151 static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf)
6153 struct e1000_hw *hw = &adapter->hw;
6154 u32 pool_mask, vlvf_mask, i;
6156 /* create mask for VF and other pools */
6157 pool_mask = E1000_VLVF_POOLSEL_MASK;
6158 vlvf_mask = BIT(E1000_VLVF_POOLSEL_SHIFT + vf);
6160 /* drop PF from pool bits */
6161 pool_mask &= ~BIT(E1000_VLVF_POOLSEL_SHIFT +
6162 adapter->vfs_allocated_count);
6164 /* Find the vlan filter for this id */
6165 for (i = E1000_VLVF_ARRAY_SIZE; i--;) {
6166 u32 vlvf = rd32(E1000_VLVF(i));
6167 u32 vfta_mask, vid, vfta;
6169 /* remove the vf from the pool */
6170 if (!(vlvf & vlvf_mask))
6173 /* clear out bit from VLVF */
6176 /* if other pools are present, just remove ourselves */
6177 if (vlvf & pool_mask)
6180 /* if PF is present, leave VFTA */
6181 if (vlvf & E1000_VLVF_POOLSEL_MASK)
6184 vid = vlvf & E1000_VLVF_VLANID_MASK;
6185 vfta_mask = BIT(vid % 32);
6187 /* clear bit from VFTA */
6188 vfta = adapter->shadow_vfta[vid / 32];
6189 if (vfta & vfta_mask)
6190 hw->mac.ops.write_vfta(hw, vid / 32, vfta ^ vfta_mask);
6192 /* clear pool selection enable */
6193 if (adapter->flags & IGB_FLAG_VLAN_PROMISC)
6194 vlvf &= E1000_VLVF_POOLSEL_MASK;
6198 /* clear pool bits */
6199 wr32(E1000_VLVF(i), vlvf);
6203 static int igb_find_vlvf_entry(struct e1000_hw *hw, u32 vlan)
6208 /* short cut the special case */
6212 /* Search for the VLAN id in the VLVF entries */
6213 for (idx = E1000_VLVF_ARRAY_SIZE; --idx;) {
6214 vlvf = rd32(E1000_VLVF(idx));
6215 if ((vlvf & VLAN_VID_MASK) == vlan)
6222 static void igb_update_pf_vlvf(struct igb_adapter *adapter, u32 vid)
6224 struct e1000_hw *hw = &adapter->hw;
6228 idx = igb_find_vlvf_entry(hw, vid);
6232 /* See if any other pools are set for this VLAN filter
6233 * entry other than the PF.
6235 pf_id = adapter->vfs_allocated_count + E1000_VLVF_POOLSEL_SHIFT;
6236 bits = ~BIT(pf_id) & E1000_VLVF_POOLSEL_MASK;
6237 bits &= rd32(E1000_VLVF(idx));
6239 /* Disable the filter so this falls into the default pool. */
6241 if (adapter->flags & IGB_FLAG_VLAN_PROMISC)
6242 wr32(E1000_VLVF(idx), BIT(pf_id));
6244 wr32(E1000_VLVF(idx), 0);
6248 static s32 igb_set_vf_vlan(struct igb_adapter *adapter, u32 vid,
6251 int pf_id = adapter->vfs_allocated_count;
6252 struct e1000_hw *hw = &adapter->hw;
6255 /* If VLAN overlaps with one the PF is currently monitoring make
6256 * sure that we are able to allocate a VLVF entry. This may be
6257 * redundant but it guarantees PF will maintain visibility to
6260 if (add && test_bit(vid, adapter->active_vlans)) {
6261 err = igb_vfta_set(hw, vid, pf_id, true, false);
6266 err = igb_vfta_set(hw, vid, vf, add, false);
6271 /* If we failed to add the VF VLAN or we are removing the VF VLAN
6272 * we may need to drop the PF pool bit in order to allow us to free
6273 * up the VLVF resources.
6275 if (test_bit(vid, adapter->active_vlans) ||
6276 (adapter->flags & IGB_FLAG_VLAN_PROMISC))
6277 igb_update_pf_vlvf(adapter, vid);
6282 static void igb_set_vmvir(struct igb_adapter *adapter, u32 vid, u32 vf)
6284 struct e1000_hw *hw = &adapter->hw;
6287 wr32(E1000_VMVIR(vf), (vid | E1000_VMVIR_VLANA_DEFAULT));
6289 wr32(E1000_VMVIR(vf), 0);
6292 static int igb_enable_port_vlan(struct igb_adapter *adapter, int vf,
6297 err = igb_set_vf_vlan(adapter, vlan, true, vf);
6301 igb_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf);
6302 igb_set_vmolr(adapter, vf, !vlan);
6304 /* revoke access to previous VLAN */
6305 if (vlan != adapter->vf_data[vf].pf_vlan)
6306 igb_set_vf_vlan(adapter, adapter->vf_data[vf].pf_vlan,
6309 adapter->vf_data[vf].pf_vlan = vlan;
6310 adapter->vf_data[vf].pf_qos = qos;
6311 igb_set_vf_vlan_strip(adapter, vf, true);
6312 dev_info(&adapter->pdev->dev,
6313 "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
6314 if (test_bit(__IGB_DOWN, &adapter->state)) {
6315 dev_warn(&adapter->pdev->dev,
6316 "The VF VLAN has been set, but the PF device is not up.\n");
6317 dev_warn(&adapter->pdev->dev,
6318 "Bring the PF device up before attempting to use the VF device.\n");
6324 static int igb_disable_port_vlan(struct igb_adapter *adapter, int vf)
6326 /* Restore tagless access via VLAN 0 */
6327 igb_set_vf_vlan(adapter, 0, true, vf);
6329 igb_set_vmvir(adapter, 0, vf);
6330 igb_set_vmolr(adapter, vf, true);
6332 /* Remove any PF assigned VLAN */
6333 if (adapter->vf_data[vf].pf_vlan)
6334 igb_set_vf_vlan(adapter, adapter->vf_data[vf].pf_vlan,
6337 adapter->vf_data[vf].pf_vlan = 0;
6338 adapter->vf_data[vf].pf_qos = 0;
6339 igb_set_vf_vlan_strip(adapter, vf, false);
6344 static int igb_ndo_set_vf_vlan(struct net_device *netdev, int vf,
6345 u16 vlan, u8 qos, __be16 vlan_proto)
6347 struct igb_adapter *adapter = netdev_priv(netdev);
6349 if ((vf >= adapter->vfs_allocated_count) || (vlan > 4095) || (qos > 7))
6352 if (vlan_proto != htons(ETH_P_8021Q))
6353 return -EPROTONOSUPPORT;
6355 return (vlan || qos) ? igb_enable_port_vlan(adapter, vf, vlan, qos) :
6356 igb_disable_port_vlan(adapter, vf);
6359 static int igb_set_vf_vlan_msg(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
6361 int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
6362 int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
6365 if (adapter->vf_data[vf].pf_vlan)
6368 /* VLAN 0 is a special case, don't allow it to be removed */
6372 ret = igb_set_vf_vlan(adapter, vid, !!add, vf);
6374 igb_set_vf_vlan_strip(adapter, vf, !!vid);
6378 static inline void igb_vf_reset(struct igb_adapter *adapter, u32 vf)
6380 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6382 /* clear flags - except flag that indicates PF has set the MAC */
6383 vf_data->flags &= IGB_VF_FLAG_PF_SET_MAC;
6384 vf_data->last_nack = jiffies;
6386 /* reset vlans for device */
6387 igb_clear_vf_vfta(adapter, vf);
6388 igb_set_vf_vlan(adapter, vf_data->pf_vlan, true, vf);
6389 igb_set_vmvir(adapter, vf_data->pf_vlan |
6390 (vf_data->pf_qos << VLAN_PRIO_SHIFT), vf);
6391 igb_set_vmolr(adapter, vf, !vf_data->pf_vlan);
6392 igb_set_vf_vlan_strip(adapter, vf, !!(vf_data->pf_vlan));
6394 /* reset multicast table array for vf */
6395 adapter->vf_data[vf].num_vf_mc_hashes = 0;
6397 /* Flush and reset the mta with the new values */
6398 igb_set_rx_mode(adapter->netdev);
6401 static void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf)
6403 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
6405 /* clear mac address as we were hotplug removed/added */
6406 if (!(adapter->vf_data[vf].flags & IGB_VF_FLAG_PF_SET_MAC))
6407 eth_zero_addr(vf_mac);
6409 /* process remaining reset events */
6410 igb_vf_reset(adapter, vf);
6413 static void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf)
6415 struct e1000_hw *hw = &adapter->hw;
6416 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
6418 u8 *addr = (u8 *)(&msgbuf[1]);
6420 /* process all the same items cleared in a function level reset */
6421 igb_vf_reset(adapter, vf);
6423 /* set vf mac address */
6424 igb_set_vf_mac(adapter, vf, vf_mac);
6426 /* enable transmit and receive for vf */
6427 reg = rd32(E1000_VFTE);
6428 wr32(E1000_VFTE, reg | BIT(vf));
6429 reg = rd32(E1000_VFRE);
6430 wr32(E1000_VFRE, reg | BIT(vf));
6432 adapter->vf_data[vf].flags |= IGB_VF_FLAG_CTS;
6434 /* reply to reset with ack and vf mac address */
6435 if (!is_zero_ether_addr(vf_mac)) {
6436 msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK;
6437 memcpy(addr, vf_mac, ETH_ALEN);
6439 msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_NACK;
6441 igb_write_mbx(hw, msgbuf, 3, vf);
6444 static void igb_flush_mac_table(struct igb_adapter *adapter)
6446 struct e1000_hw *hw = &adapter->hw;
6449 for (i = 0; i < hw->mac.rar_entry_count; i++) {
6450 adapter->mac_table[i].state &= ~IGB_MAC_STATE_IN_USE;
6451 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
6452 adapter->mac_table[i].queue = 0;
6453 igb_rar_set_index(adapter, i);
6457 static int igb_available_rars(struct igb_adapter *adapter, u8 queue)
6459 struct e1000_hw *hw = &adapter->hw;
6460 /* do not count rar entries reserved for VFs MAC addresses */
6461 int rar_entries = hw->mac.rar_entry_count -
6462 adapter->vfs_allocated_count;
6465 for (i = 0; i < rar_entries; i++) {
6466 /* do not count default entries */
6467 if (adapter->mac_table[i].state & IGB_MAC_STATE_DEFAULT)
6470 /* do not count "in use" entries for different queues */
6471 if ((adapter->mac_table[i].state & IGB_MAC_STATE_IN_USE) &&
6472 (adapter->mac_table[i].queue != queue))
6481 /* Set default MAC address for the PF in the first RAR entry */
6482 static void igb_set_default_mac_filter(struct igb_adapter *adapter)
6484 struct igb_mac_addr *mac_table = &adapter->mac_table[0];
6486 ether_addr_copy(mac_table->addr, adapter->hw.mac.addr);
6487 mac_table->queue = adapter->vfs_allocated_count;
6488 mac_table->state = IGB_MAC_STATE_DEFAULT | IGB_MAC_STATE_IN_USE;
6490 igb_rar_set_index(adapter, 0);
6493 static int igb_add_mac_filter(struct igb_adapter *adapter, const u8 *addr,
6496 struct e1000_hw *hw = &adapter->hw;
6497 int rar_entries = hw->mac.rar_entry_count -
6498 adapter->vfs_allocated_count;
6501 if (is_zero_ether_addr(addr))
6504 /* Search for the first empty entry in the MAC table.
6505 * Do not touch entries at the end of the table reserved for the VF MAC
6508 for (i = 0; i < rar_entries; i++) {
6509 if (adapter->mac_table[i].state & IGB_MAC_STATE_IN_USE)
6512 ether_addr_copy(adapter->mac_table[i].addr, addr);
6513 adapter->mac_table[i].queue = queue;
6514 adapter->mac_table[i].state |= IGB_MAC_STATE_IN_USE;
6516 igb_rar_set_index(adapter, i);
6523 static int igb_del_mac_filter(struct igb_adapter *adapter, const u8 *addr,
6526 struct e1000_hw *hw = &adapter->hw;
6527 int rar_entries = hw->mac.rar_entry_count -
6528 adapter->vfs_allocated_count;
6531 if (is_zero_ether_addr(addr))
6534 /* Search for matching entry in the MAC table based on given address
6535 * and queue. Do not touch entries at the end of the table reserved
6536 * for the VF MAC addresses.
6538 for (i = 0; i < rar_entries; i++) {
6539 if (!(adapter->mac_table[i].state & IGB_MAC_STATE_IN_USE))
6541 if (adapter->mac_table[i].queue != queue)
6543 if (!ether_addr_equal(adapter->mac_table[i].addr, addr))
6546 adapter->mac_table[i].state &= ~IGB_MAC_STATE_IN_USE;
6547 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
6548 adapter->mac_table[i].queue = 0;
6550 igb_rar_set_index(adapter, i);
6557 static int igb_uc_sync(struct net_device *netdev, const unsigned char *addr)
6559 struct igb_adapter *adapter = netdev_priv(netdev);
6562 ret = igb_add_mac_filter(adapter, addr, adapter->vfs_allocated_count);
6564 return min_t(int, ret, 0);
6567 static int igb_uc_unsync(struct net_device *netdev, const unsigned char *addr)
6569 struct igb_adapter *adapter = netdev_priv(netdev);
6571 igb_del_mac_filter(adapter, addr, adapter->vfs_allocated_count);
6576 static int igb_set_vf_mac_filter(struct igb_adapter *adapter, const int vf,
6577 const u32 info, const u8 *addr)
6579 struct pci_dev *pdev = adapter->pdev;
6580 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6581 struct list_head *pos;
6582 struct vf_mac_filter *entry = NULL;
6586 case E1000_VF_MAC_FILTER_CLR:
6587 /* remove all unicast MAC filters related to the current VF */
6588 list_for_each(pos, &adapter->vf_macs.l) {
6589 entry = list_entry(pos, struct vf_mac_filter, l);
6590 if (entry->vf == vf) {
6593 igb_del_mac_filter(adapter, entry->vf_mac, vf);
6597 case E1000_VF_MAC_FILTER_ADD:
6598 if (vf_data->flags & IGB_VF_FLAG_PF_SET_MAC) {
6599 dev_warn(&pdev->dev,
6600 "VF %d requested MAC filter but is administratively denied\n",
6605 if (!is_valid_ether_addr(addr)) {
6606 dev_warn(&pdev->dev,
6607 "VF %d attempted to set invalid MAC filter\n",
6612 /* try to find empty slot in the list */
6613 list_for_each(pos, &adapter->vf_macs.l) {
6614 entry = list_entry(pos, struct vf_mac_filter, l);
6619 if (entry && entry->free) {
6620 entry->free = false;
6622 ether_addr_copy(entry->vf_mac, addr);
6624 ret = igb_add_mac_filter(adapter, addr, vf);
6625 ret = min_t(int, ret, 0);
6631 dev_warn(&pdev->dev,
6632 "VF %d has requested MAC filter but there is no space for it\n",
6643 static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf)
6645 struct pci_dev *pdev = adapter->pdev;
6646 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6647 u32 info = msg[0] & E1000_VT_MSGINFO_MASK;
6649 /* The VF MAC Address is stored in a packed array of bytes
6650 * starting at the second 32 bit word of the msg array
6652 unsigned char *addr = (unsigned char *)&msg[1];
6656 if (vf_data->flags & IGB_VF_FLAG_PF_SET_MAC) {
6657 dev_warn(&pdev->dev,
6658 "VF %d attempted to override administratively set MAC address\nReload the VF driver to resume operations\n",
6663 if (!is_valid_ether_addr(addr)) {
6664 dev_warn(&pdev->dev,
6665 "VF %d attempted to set invalid MAC\n",
6670 ret = igb_set_vf_mac(adapter, vf, addr);
6672 ret = igb_set_vf_mac_filter(adapter, vf, info, addr);
6678 static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf)
6680 struct e1000_hw *hw = &adapter->hw;
6681 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6682 u32 msg = E1000_VT_MSGTYPE_NACK;
6684 /* if device isn't clear to send it shouldn't be reading either */
6685 if (!(vf_data->flags & IGB_VF_FLAG_CTS) &&
6686 time_after(jiffies, vf_data->last_nack + (2 * HZ))) {
6687 igb_write_mbx(hw, &msg, 1, vf);
6688 vf_data->last_nack = jiffies;
6692 static void igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf)
6694 struct pci_dev *pdev = adapter->pdev;
6695 u32 msgbuf[E1000_VFMAILBOX_SIZE];
6696 struct e1000_hw *hw = &adapter->hw;
6697 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6700 retval = igb_read_mbx(hw, msgbuf, E1000_VFMAILBOX_SIZE, vf, false);
6703 /* if receive failed revoke VF CTS stats and restart init */
6704 dev_err(&pdev->dev, "Error receiving message from VF\n");
6705 vf_data->flags &= ~IGB_VF_FLAG_CTS;
6706 if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
6711 /* this is a message we already processed, do nothing */
6712 if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK))
6715 /* until the vf completes a reset it should not be
6716 * allowed to start any configuration.
6718 if (msgbuf[0] == E1000_VF_RESET) {
6719 /* unlocks mailbox */
6720 igb_vf_reset_msg(adapter, vf);
6724 if (!(vf_data->flags & IGB_VF_FLAG_CTS)) {
6725 if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
6731 switch ((msgbuf[0] & 0xFFFF)) {
6732 case E1000_VF_SET_MAC_ADDR:
6733 retval = igb_set_vf_mac_addr(adapter, msgbuf, vf);
6735 case E1000_VF_SET_PROMISC:
6736 retval = igb_set_vf_promisc(adapter, msgbuf, vf);
6738 case E1000_VF_SET_MULTICAST:
6739 retval = igb_set_vf_multicasts(adapter, msgbuf, vf);
6741 case E1000_VF_SET_LPE:
6742 retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf);
6744 case E1000_VF_SET_VLAN:
6746 if (vf_data->pf_vlan)
6747 dev_warn(&pdev->dev,
6748 "VF %d attempted to override administratively set VLAN tag\nReload the VF driver to resume operations\n",
6751 retval = igb_set_vf_vlan_msg(adapter, msgbuf, vf);
6754 dev_err(&pdev->dev, "Unhandled Msg %08x\n", msgbuf[0]);
6759 msgbuf[0] |= E1000_VT_MSGTYPE_CTS;
6761 /* notify the VF of the results of what it sent us */
6763 msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
6765 msgbuf[0] |= E1000_VT_MSGTYPE_ACK;
6767 /* unlocks mailbox */
6768 igb_write_mbx(hw, msgbuf, 1, vf);
6772 igb_unlock_mbx(hw, vf);
6775 static void igb_msg_task(struct igb_adapter *adapter)
6777 struct e1000_hw *hw = &adapter->hw;
6780 for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
6781 /* process any reset requests */
6782 if (!igb_check_for_rst(hw, vf))
6783 igb_vf_reset_event(adapter, vf);
6785 /* process any messages pending */
6786 if (!igb_check_for_msg(hw, vf))
6787 igb_rcv_msg_from_vf(adapter, vf);
6789 /* process any acks */
6790 if (!igb_check_for_ack(hw, vf))
6791 igb_rcv_ack_from_vf(adapter, vf);
6796 * igb_set_uta - Set unicast filter table address
6797 * @adapter: board private structure
6798 * @set: boolean indicating if we are setting or clearing bits
6800 * The unicast table address is a register array of 32-bit registers.
6801 * The table is meant to be used in a way similar to how the MTA is used
6802 * however due to certain limitations in the hardware it is necessary to
6803 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
6804 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
6806 static void igb_set_uta(struct igb_adapter *adapter, bool set)
6808 struct e1000_hw *hw = &adapter->hw;
6809 u32 uta = set ? ~0 : 0;
6812 /* we only need to do this if VMDq is enabled */
6813 if (!adapter->vfs_allocated_count)
6816 for (i = hw->mac.uta_reg_count; i--;)
6817 array_wr32(E1000_UTA, i, uta);
6821 * igb_intr_msi - Interrupt Handler
6822 * @irq: interrupt number
6823 * @data: pointer to a network interface device structure
6825 static irqreturn_t igb_intr_msi(int irq, void *data)
6827 struct igb_adapter *adapter = data;
6828 struct igb_q_vector *q_vector = adapter->q_vector[0];
6829 struct e1000_hw *hw = &adapter->hw;
6830 /* read ICR disables interrupts using IAM */
6831 u32 icr = rd32(E1000_ICR);
6833 igb_write_itr(q_vector);
6835 if (icr & E1000_ICR_DRSTA)
6836 schedule_work(&adapter->reset_task);
6838 if (icr & E1000_ICR_DOUTSYNC) {
6839 /* HW is reporting DMA is out of sync */
6840 adapter->stats.doosync++;
6843 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
6844 hw->mac.get_link_status = 1;
6845 if (!test_bit(__IGB_DOWN, &adapter->state))
6846 mod_timer(&adapter->watchdog_timer, jiffies + 1);
6849 if (icr & E1000_ICR_TS)
6850 igb_tsync_interrupt(adapter);
6852 napi_schedule(&q_vector->napi);
6858 * igb_intr - Legacy Interrupt Handler
6859 * @irq: interrupt number
6860 * @data: pointer to a network interface device structure
6862 static irqreturn_t igb_intr(int irq, void *data)
6864 struct igb_adapter *adapter = data;
6865 struct igb_q_vector *q_vector = adapter->q_vector[0];
6866 struct e1000_hw *hw = &adapter->hw;
6867 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
6868 * need for the IMC write
6870 u32 icr = rd32(E1000_ICR);
6872 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
6873 * not set, then the adapter didn't send an interrupt
6875 if (!(icr & E1000_ICR_INT_ASSERTED))
6878 igb_write_itr(q_vector);
6880 if (icr & E1000_ICR_DRSTA)
6881 schedule_work(&adapter->reset_task);
6883 if (icr & E1000_ICR_DOUTSYNC) {
6884 /* HW is reporting DMA is out of sync */
6885 adapter->stats.doosync++;
6888 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
6889 hw->mac.get_link_status = 1;
6890 /* guard against interrupt when we're going down */
6891 if (!test_bit(__IGB_DOWN, &adapter->state))
6892 mod_timer(&adapter->watchdog_timer, jiffies + 1);
6895 if (icr & E1000_ICR_TS)
6896 igb_tsync_interrupt(adapter);
6898 napi_schedule(&q_vector->napi);
6903 static void igb_ring_irq_enable(struct igb_q_vector *q_vector)
6905 struct igb_adapter *adapter = q_vector->adapter;
6906 struct e1000_hw *hw = &adapter->hw;
6908 if ((q_vector->rx.ring && (adapter->rx_itr_setting & 3)) ||
6909 (!q_vector->rx.ring && (adapter->tx_itr_setting & 3))) {
6910 if ((adapter->num_q_vectors == 1) && !adapter->vf_data)
6911 igb_set_itr(q_vector);
6913 igb_update_ring_itr(q_vector);
6916 if (!test_bit(__IGB_DOWN, &adapter->state)) {
6917 if (adapter->flags & IGB_FLAG_HAS_MSIX)
6918 wr32(E1000_EIMS, q_vector->eims_value);
6920 igb_irq_enable(adapter);
6925 * igb_poll - NAPI Rx polling callback
6926 * @napi: napi polling structure
6927 * @budget: count of how many packets we should handle
6929 static int igb_poll(struct napi_struct *napi, int budget)
6931 struct igb_q_vector *q_vector = container_of(napi,
6932 struct igb_q_vector,
6934 bool clean_complete = true;
6937 #ifdef CONFIG_IGB_DCA
6938 if (q_vector->adapter->flags & IGB_FLAG_DCA_ENABLED)
6939 igb_update_dca(q_vector);
6941 if (q_vector->tx.ring)
6942 clean_complete = igb_clean_tx_irq(q_vector, budget);
6944 if (q_vector->rx.ring) {
6945 int cleaned = igb_clean_rx_irq(q_vector, budget);
6947 work_done += cleaned;
6948 if (cleaned >= budget)
6949 clean_complete = false;
6952 /* If all work not completed, return budget and keep polling */
6953 if (!clean_complete)
6956 /* If not enough Rx work done, exit the polling mode */
6957 napi_complete_done(napi, work_done);
6958 igb_ring_irq_enable(q_vector);
6964 * igb_clean_tx_irq - Reclaim resources after transmit completes
6965 * @q_vector: pointer to q_vector containing needed info
6966 * @napi_budget: Used to determine if we are in netpoll
6968 * returns true if ring is completely cleaned
6970 static bool igb_clean_tx_irq(struct igb_q_vector *q_vector, int napi_budget)
6972 struct igb_adapter *adapter = q_vector->adapter;
6973 struct igb_ring *tx_ring = q_vector->tx.ring;
6974 struct igb_tx_buffer *tx_buffer;
6975 union e1000_adv_tx_desc *tx_desc;
6976 unsigned int total_bytes = 0, total_packets = 0;
6977 unsigned int budget = q_vector->tx.work_limit;
6978 unsigned int i = tx_ring->next_to_clean;
6980 if (test_bit(__IGB_DOWN, &adapter->state))
6983 tx_buffer = &tx_ring->tx_buffer_info[i];
6984 tx_desc = IGB_TX_DESC(tx_ring, i);
6985 i -= tx_ring->count;
6988 union e1000_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
6990 /* if next_to_watch is not set then there is no work pending */
6994 /* prevent any other reads prior to eop_desc */
6997 /* if DD is not set pending work has not been completed */
6998 if (!(eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)))
7001 /* clear next_to_watch to prevent false hangs */
7002 tx_buffer->next_to_watch = NULL;
7004 /* update the statistics for this packet */
7005 total_bytes += tx_buffer->bytecount;
7006 total_packets += tx_buffer->gso_segs;
7009 napi_consume_skb(tx_buffer->skb, napi_budget);
7011 /* unmap skb header data */
7012 dma_unmap_single(tx_ring->dev,
7013 dma_unmap_addr(tx_buffer, dma),
7014 dma_unmap_len(tx_buffer, len),
7017 /* clear tx_buffer data */
7018 dma_unmap_len_set(tx_buffer, len, 0);
7020 /* clear last DMA location and unmap remaining buffers */
7021 while (tx_desc != eop_desc) {
7026 i -= tx_ring->count;
7027 tx_buffer = tx_ring->tx_buffer_info;
7028 tx_desc = IGB_TX_DESC(tx_ring, 0);
7031 /* unmap any remaining paged data */
7032 if (dma_unmap_len(tx_buffer, len)) {
7033 dma_unmap_page(tx_ring->dev,
7034 dma_unmap_addr(tx_buffer, dma),
7035 dma_unmap_len(tx_buffer, len),
7037 dma_unmap_len_set(tx_buffer, len, 0);
7041 /* move us one more past the eop_desc for start of next pkt */
7046 i -= tx_ring->count;
7047 tx_buffer = tx_ring->tx_buffer_info;
7048 tx_desc = IGB_TX_DESC(tx_ring, 0);
7051 /* issue prefetch for next Tx descriptor */
7054 /* update budget accounting */
7056 } while (likely(budget));
7058 netdev_tx_completed_queue(txring_txq(tx_ring),
7059 total_packets, total_bytes);
7060 i += tx_ring->count;
7061 tx_ring->next_to_clean = i;
7062 u64_stats_update_begin(&tx_ring->tx_syncp);
7063 tx_ring->tx_stats.bytes += total_bytes;
7064 tx_ring->tx_stats.packets += total_packets;
7065 u64_stats_update_end(&tx_ring->tx_syncp);
7066 q_vector->tx.total_bytes += total_bytes;
7067 q_vector->tx.total_packets += total_packets;
7069 if (test_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags)) {
7070 struct e1000_hw *hw = &adapter->hw;
7072 /* Detect a transmit hang in hardware, this serializes the
7073 * check with the clearing of time_stamp and movement of i
7075 clear_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
7076 if (tx_buffer->next_to_watch &&
7077 time_after(jiffies, tx_buffer->time_stamp +
7078 (adapter->tx_timeout_factor * HZ)) &&
7079 !(rd32(E1000_STATUS) & E1000_STATUS_TXOFF)) {
7081 /* detected Tx unit hang */
7082 dev_err(tx_ring->dev,
7083 "Detected Tx Unit Hang\n"
7087 " next_to_use <%x>\n"
7088 " next_to_clean <%x>\n"
7089 "buffer_info[next_to_clean]\n"
7090 " time_stamp <%lx>\n"
7091 " next_to_watch <%p>\n"
7093 " desc.status <%x>\n",
7094 tx_ring->queue_index,
7095 rd32(E1000_TDH(tx_ring->reg_idx)),
7096 readl(tx_ring->tail),
7097 tx_ring->next_to_use,
7098 tx_ring->next_to_clean,
7099 tx_buffer->time_stamp,
7100 tx_buffer->next_to_watch,
7102 tx_buffer->next_to_watch->wb.status);
7103 netif_stop_subqueue(tx_ring->netdev,
7104 tx_ring->queue_index);
7106 /* we are about to reset, no point in enabling stuff */
7111 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
7112 if (unlikely(total_packets &&
7113 netif_carrier_ok(tx_ring->netdev) &&
7114 igb_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD)) {
7115 /* Make sure that anybody stopping the queue after this
7116 * sees the new next_to_clean.
7119 if (__netif_subqueue_stopped(tx_ring->netdev,
7120 tx_ring->queue_index) &&
7121 !(test_bit(__IGB_DOWN, &adapter->state))) {
7122 netif_wake_subqueue(tx_ring->netdev,
7123 tx_ring->queue_index);
7125 u64_stats_update_begin(&tx_ring->tx_syncp);
7126 tx_ring->tx_stats.restart_queue++;
7127 u64_stats_update_end(&tx_ring->tx_syncp);
7135 * igb_reuse_rx_page - page flip buffer and store it back on the ring
7136 * @rx_ring: rx descriptor ring to store buffers on
7137 * @old_buff: donor buffer to have page reused
7139 * Synchronizes page for reuse by the adapter
7141 static void igb_reuse_rx_page(struct igb_ring *rx_ring,
7142 struct igb_rx_buffer *old_buff)
7144 struct igb_rx_buffer *new_buff;
7145 u16 nta = rx_ring->next_to_alloc;
7147 new_buff = &rx_ring->rx_buffer_info[nta];
7149 /* update, and store next to alloc */
7151 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
7153 /* Transfer page from old buffer to new buffer.
7154 * Move each member individually to avoid possible store
7155 * forwarding stalls.
7157 new_buff->dma = old_buff->dma;
7158 new_buff->page = old_buff->page;
7159 new_buff->page_offset = old_buff->page_offset;
7160 new_buff->pagecnt_bias = old_buff->pagecnt_bias;
7163 static inline bool igb_page_is_reserved(struct page *page)
7165 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
7168 static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer)
7170 unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
7171 struct page *page = rx_buffer->page;
7173 /* avoid re-using remote pages */
7174 if (unlikely(igb_page_is_reserved(page)))
7177 #if (PAGE_SIZE < 8192)
7178 /* if we are only owner of page we can reuse it */
7179 if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
7182 #define IGB_LAST_OFFSET \
7183 (SKB_WITH_OVERHEAD(PAGE_SIZE) - IGB_RXBUFFER_2048)
7185 if (rx_buffer->page_offset > IGB_LAST_OFFSET)
7189 /* If we have drained the page fragment pool we need to update
7190 * the pagecnt_bias and page count so that we fully restock the
7191 * number of references the driver holds.
7193 if (unlikely(!pagecnt_bias)) {
7194 page_ref_add(page, USHRT_MAX);
7195 rx_buffer->pagecnt_bias = USHRT_MAX;
7202 * igb_add_rx_frag - Add contents of Rx buffer to sk_buff
7203 * @rx_ring: rx descriptor ring to transact packets on
7204 * @rx_buffer: buffer containing page to add
7205 * @skb: sk_buff to place the data into
7206 * @size: size of buffer to be added
7208 * This function will add the data contained in rx_buffer->page to the skb.
7210 static void igb_add_rx_frag(struct igb_ring *rx_ring,
7211 struct igb_rx_buffer *rx_buffer,
7212 struct sk_buff *skb,
7215 #if (PAGE_SIZE < 8192)
7216 unsigned int truesize = igb_rx_pg_size(rx_ring) / 2;
7218 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
7219 SKB_DATA_ALIGN(IGB_SKB_PAD + size) :
7220 SKB_DATA_ALIGN(size);
7222 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
7223 rx_buffer->page_offset, size, truesize);
7224 #if (PAGE_SIZE < 8192)
7225 rx_buffer->page_offset ^= truesize;
7227 rx_buffer->page_offset += truesize;
7231 static struct sk_buff *igb_construct_skb(struct igb_ring *rx_ring,
7232 struct igb_rx_buffer *rx_buffer,
7233 union e1000_adv_rx_desc *rx_desc,
7236 void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
7237 #if (PAGE_SIZE < 8192)
7238 unsigned int truesize = igb_rx_pg_size(rx_ring) / 2;
7240 unsigned int truesize = SKB_DATA_ALIGN(size);
7242 unsigned int headlen;
7243 struct sk_buff *skb;
7245 /* prefetch first cache line of first page */
7247 #if L1_CACHE_BYTES < 128
7248 prefetch(va + L1_CACHE_BYTES);
7251 /* allocate a skb to store the frags */
7252 skb = napi_alloc_skb(&rx_ring->q_vector->napi, IGB_RX_HDR_LEN);
7256 if (unlikely(igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))) {
7257 igb_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
7258 va += IGB_TS_HDR_LEN;
7259 size -= IGB_TS_HDR_LEN;
7262 /* Determine available headroom for copy */
7264 if (headlen > IGB_RX_HDR_LEN)
7265 headlen = eth_get_headlen(va, IGB_RX_HDR_LEN);
7267 /* align pull length to size of long to optimize memcpy performance */
7268 memcpy(__skb_put(skb, headlen), va, ALIGN(headlen, sizeof(long)));
7270 /* update all of the pointers */
7273 skb_add_rx_frag(skb, 0, rx_buffer->page,
7274 (va + headlen) - page_address(rx_buffer->page),
7276 #if (PAGE_SIZE < 8192)
7277 rx_buffer->page_offset ^= truesize;
7279 rx_buffer->page_offset += truesize;
7282 rx_buffer->pagecnt_bias++;
7288 static struct sk_buff *igb_build_skb(struct igb_ring *rx_ring,
7289 struct igb_rx_buffer *rx_buffer,
7290 union e1000_adv_rx_desc *rx_desc,
7293 void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
7294 #if (PAGE_SIZE < 8192)
7295 unsigned int truesize = igb_rx_pg_size(rx_ring) / 2;
7297 unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
7298 SKB_DATA_ALIGN(IGB_SKB_PAD + size);
7300 struct sk_buff *skb;
7302 /* prefetch first cache line of first page */
7304 #if L1_CACHE_BYTES < 128
7305 prefetch(va + L1_CACHE_BYTES);
7308 /* build an skb around the page buffer */
7309 skb = build_skb(va - IGB_SKB_PAD, truesize);
7313 /* update pointers within the skb to store the data */
7314 skb_reserve(skb, IGB_SKB_PAD);
7315 __skb_put(skb, size);
7317 /* pull timestamp out of packet data */
7318 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
7319 igb_ptp_rx_pktstamp(rx_ring->q_vector, skb->data, skb);
7320 __skb_pull(skb, IGB_TS_HDR_LEN);
7323 /* update buffer offset */
7324 #if (PAGE_SIZE < 8192)
7325 rx_buffer->page_offset ^= truesize;
7327 rx_buffer->page_offset += truesize;
7333 static inline void igb_rx_checksum(struct igb_ring *ring,
7334 union e1000_adv_rx_desc *rx_desc,
7335 struct sk_buff *skb)
7337 skb_checksum_none_assert(skb);
7339 /* Ignore Checksum bit is set */
7340 if (igb_test_staterr(rx_desc, E1000_RXD_STAT_IXSM))
7343 /* Rx checksum disabled via ethtool */
7344 if (!(ring->netdev->features & NETIF_F_RXCSUM))
7347 /* TCP/UDP checksum error bit is set */
7348 if (igb_test_staterr(rx_desc,
7349 E1000_RXDEXT_STATERR_TCPE |
7350 E1000_RXDEXT_STATERR_IPE)) {
7351 /* work around errata with sctp packets where the TCPE aka
7352 * L4E bit is set incorrectly on 64 byte (60 byte w/o crc)
7353 * packets, (aka let the stack check the crc32c)
7355 if (!((skb->len == 60) &&
7356 test_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags))) {
7357 u64_stats_update_begin(&ring->rx_syncp);
7358 ring->rx_stats.csum_err++;
7359 u64_stats_update_end(&ring->rx_syncp);
7361 /* let the stack verify checksum errors */
7364 /* It must be a TCP or UDP packet with a valid checksum */
7365 if (igb_test_staterr(rx_desc, E1000_RXD_STAT_TCPCS |
7366 E1000_RXD_STAT_UDPCS))
7367 skb->ip_summed = CHECKSUM_UNNECESSARY;
7369 dev_dbg(ring->dev, "cksum success: bits %08X\n",
7370 le32_to_cpu(rx_desc->wb.upper.status_error));
7373 static inline void igb_rx_hash(struct igb_ring *ring,
7374 union e1000_adv_rx_desc *rx_desc,
7375 struct sk_buff *skb)
7377 if (ring->netdev->features & NETIF_F_RXHASH)
7379 le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
7384 * igb_is_non_eop - process handling of non-EOP buffers
7385 * @rx_ring: Rx ring being processed
7386 * @rx_desc: Rx descriptor for current buffer
7387 * @skb: current socket buffer containing buffer in progress
7389 * This function updates next to clean. If the buffer is an EOP buffer
7390 * this function exits returning false, otherwise it will place the
7391 * sk_buff in the next buffer to be chained and return true indicating
7392 * that this is in fact a non-EOP buffer.
7394 static bool igb_is_non_eop(struct igb_ring *rx_ring,
7395 union e1000_adv_rx_desc *rx_desc)
7397 u32 ntc = rx_ring->next_to_clean + 1;
7399 /* fetch, update, and store next to clean */
7400 ntc = (ntc < rx_ring->count) ? ntc : 0;
7401 rx_ring->next_to_clean = ntc;
7403 prefetch(IGB_RX_DESC(rx_ring, ntc));
7405 if (likely(igb_test_staterr(rx_desc, E1000_RXD_STAT_EOP)))
7412 * igb_cleanup_headers - Correct corrupted or empty headers
7413 * @rx_ring: rx descriptor ring packet is being transacted on
7414 * @rx_desc: pointer to the EOP Rx descriptor
7415 * @skb: pointer to current skb being fixed
7417 * Address the case where we are pulling data in on pages only
7418 * and as such no data is present in the skb header.
7420 * In addition if skb is not at least 60 bytes we need to pad it so that
7421 * it is large enough to qualify as a valid Ethernet frame.
7423 * Returns true if an error was encountered and skb was freed.
7425 static bool igb_cleanup_headers(struct igb_ring *rx_ring,
7426 union e1000_adv_rx_desc *rx_desc,
7427 struct sk_buff *skb)
7429 if (unlikely((igb_test_staterr(rx_desc,
7430 E1000_RXDEXT_ERR_FRAME_ERR_MASK)))) {
7431 struct net_device *netdev = rx_ring->netdev;
7432 if (!(netdev->features & NETIF_F_RXALL)) {
7433 dev_kfree_skb_any(skb);
7438 /* if eth_skb_pad returns an error the skb was freed */
7439 if (eth_skb_pad(skb))
7446 * igb_process_skb_fields - Populate skb header fields from Rx descriptor
7447 * @rx_ring: rx descriptor ring packet is being transacted on
7448 * @rx_desc: pointer to the EOP Rx descriptor
7449 * @skb: pointer to current skb being populated
7451 * This function checks the ring, descriptor, and packet information in
7452 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
7453 * other fields within the skb.
7455 static void igb_process_skb_fields(struct igb_ring *rx_ring,
7456 union e1000_adv_rx_desc *rx_desc,
7457 struct sk_buff *skb)
7459 struct net_device *dev = rx_ring->netdev;
7461 igb_rx_hash(rx_ring, rx_desc, skb);
7463 igb_rx_checksum(rx_ring, rx_desc, skb);
7465 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TS) &&
7466 !igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))
7467 igb_ptp_rx_rgtstamp(rx_ring->q_vector, skb);
7469 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
7470 igb_test_staterr(rx_desc, E1000_RXD_STAT_VP)) {
7473 if (igb_test_staterr(rx_desc, E1000_RXDEXT_STATERR_LB) &&
7474 test_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &rx_ring->flags))
7475 vid = be16_to_cpu(rx_desc->wb.upper.vlan);
7477 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
7479 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
7482 skb_record_rx_queue(skb, rx_ring->queue_index);
7484 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
7487 static struct igb_rx_buffer *igb_get_rx_buffer(struct igb_ring *rx_ring,
7488 const unsigned int size)
7490 struct igb_rx_buffer *rx_buffer;
7492 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
7493 prefetchw(rx_buffer->page);
7495 /* we are reusing so sync this buffer for CPU use */
7496 dma_sync_single_range_for_cpu(rx_ring->dev,
7498 rx_buffer->page_offset,
7502 rx_buffer->pagecnt_bias--;
7507 static void igb_put_rx_buffer(struct igb_ring *rx_ring,
7508 struct igb_rx_buffer *rx_buffer)
7510 if (igb_can_reuse_rx_page(rx_buffer)) {
7511 /* hand second half of page back to the ring */
7512 igb_reuse_rx_page(rx_ring, rx_buffer);
7514 /* We are not reusing the buffer so unmap it and free
7515 * any references we are holding to it
7517 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
7518 igb_rx_pg_size(rx_ring), DMA_FROM_DEVICE,
7520 __page_frag_cache_drain(rx_buffer->page,
7521 rx_buffer->pagecnt_bias);
7524 /* clear contents of rx_buffer */
7525 rx_buffer->page = NULL;
7528 static int igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)
7530 struct igb_ring *rx_ring = q_vector->rx.ring;
7531 struct sk_buff *skb = rx_ring->skb;
7532 unsigned int total_bytes = 0, total_packets = 0;
7533 u16 cleaned_count = igb_desc_unused(rx_ring);
7535 while (likely(total_packets < budget)) {
7536 union e1000_adv_rx_desc *rx_desc;
7537 struct igb_rx_buffer *rx_buffer;
7540 /* return some buffers to hardware, one at a time is too slow */
7541 if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
7542 igb_alloc_rx_buffers(rx_ring, cleaned_count);
7546 rx_desc = IGB_RX_DESC(rx_ring, rx_ring->next_to_clean);
7547 size = le16_to_cpu(rx_desc->wb.upper.length);
7551 /* This memory barrier is needed to keep us from reading
7552 * any other fields out of the rx_desc until we know the
7553 * descriptor has been written back
7557 rx_buffer = igb_get_rx_buffer(rx_ring, size);
7559 /* retrieve a buffer from the ring */
7561 igb_add_rx_frag(rx_ring, rx_buffer, skb, size);
7562 else if (ring_uses_build_skb(rx_ring))
7563 skb = igb_build_skb(rx_ring, rx_buffer, rx_desc, size);
7565 skb = igb_construct_skb(rx_ring, rx_buffer,
7568 /* exit if we failed to retrieve a buffer */
7570 rx_ring->rx_stats.alloc_failed++;
7571 rx_buffer->pagecnt_bias++;
7575 igb_put_rx_buffer(rx_ring, rx_buffer);
7578 /* fetch next buffer in frame if non-eop */
7579 if (igb_is_non_eop(rx_ring, rx_desc))
7582 /* verify the packet layout is correct */
7583 if (igb_cleanup_headers(rx_ring, rx_desc, skb)) {
7588 /* probably a little skewed due to removing CRC */
7589 total_bytes += skb->len;
7591 /* populate checksum, timestamp, VLAN, and protocol */
7592 igb_process_skb_fields(rx_ring, rx_desc, skb);
7594 napi_gro_receive(&q_vector->napi, skb);
7596 /* reset skb pointer */
7599 /* update budget accounting */
7603 /* place incomplete frames back on ring for completion */
7606 u64_stats_update_begin(&rx_ring->rx_syncp);
7607 rx_ring->rx_stats.packets += total_packets;
7608 rx_ring->rx_stats.bytes += total_bytes;
7609 u64_stats_update_end(&rx_ring->rx_syncp);
7610 q_vector->rx.total_packets += total_packets;
7611 q_vector->rx.total_bytes += total_bytes;
7614 igb_alloc_rx_buffers(rx_ring, cleaned_count);
7616 return total_packets;
7619 static inline unsigned int igb_rx_offset(struct igb_ring *rx_ring)
7621 return ring_uses_build_skb(rx_ring) ? IGB_SKB_PAD : 0;
7624 static bool igb_alloc_mapped_page(struct igb_ring *rx_ring,
7625 struct igb_rx_buffer *bi)
7627 struct page *page = bi->page;
7630 /* since we are recycling buffers we should seldom need to alloc */
7634 /* alloc new page for storage */
7635 page = dev_alloc_pages(igb_rx_pg_order(rx_ring));
7636 if (unlikely(!page)) {
7637 rx_ring->rx_stats.alloc_failed++;
7641 /* map page for use */
7642 dma = dma_map_page_attrs(rx_ring->dev, page, 0,
7643 igb_rx_pg_size(rx_ring),
7647 /* if mapping failed free memory back to system since
7648 * there isn't much point in holding memory we can't use
7650 if (dma_mapping_error(rx_ring->dev, dma)) {
7651 __free_pages(page, igb_rx_pg_order(rx_ring));
7653 rx_ring->rx_stats.alloc_failed++;
7659 bi->page_offset = igb_rx_offset(rx_ring);
7660 bi->pagecnt_bias = 1;
7666 * igb_alloc_rx_buffers - Replace used receive buffers; packet split
7667 * @adapter: address of board private structure
7669 void igb_alloc_rx_buffers(struct igb_ring *rx_ring, u16 cleaned_count)
7671 union e1000_adv_rx_desc *rx_desc;
7672 struct igb_rx_buffer *bi;
7673 u16 i = rx_ring->next_to_use;
7680 rx_desc = IGB_RX_DESC(rx_ring, i);
7681 bi = &rx_ring->rx_buffer_info[i];
7682 i -= rx_ring->count;
7684 bufsz = igb_rx_bufsz(rx_ring);
7687 if (!igb_alloc_mapped_page(rx_ring, bi))
7690 /* sync the buffer for use by the device */
7691 dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
7692 bi->page_offset, bufsz,
7695 /* Refresh the desc even if buffer_addrs didn't change
7696 * because each write-back erases this info.
7698 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
7704 rx_desc = IGB_RX_DESC(rx_ring, 0);
7705 bi = rx_ring->rx_buffer_info;
7706 i -= rx_ring->count;
7709 /* clear the length for the next_to_use descriptor */
7710 rx_desc->wb.upper.length = 0;
7713 } while (cleaned_count);
7715 i += rx_ring->count;
7717 if (rx_ring->next_to_use != i) {
7718 /* record the next descriptor to use */
7719 rx_ring->next_to_use = i;
7721 /* update next to alloc since we have filled the ring */
7722 rx_ring->next_to_alloc = i;
7724 /* Force memory writes to complete before letting h/w
7725 * know there are new descriptors to fetch. (Only
7726 * applicable for weak-ordered memory model archs,
7730 writel(i, rx_ring->tail);
7740 static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
7742 struct igb_adapter *adapter = netdev_priv(netdev);
7743 struct mii_ioctl_data *data = if_mii(ifr);
7745 if (adapter->hw.phy.media_type != e1000_media_type_copper)
7750 data->phy_id = adapter->hw.phy.addr;
7753 if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
7770 static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
7776 return igb_mii_ioctl(netdev, ifr, cmd);
7778 return igb_ptp_get_ts_config(netdev, ifr);
7780 return igb_ptp_set_ts_config(netdev, ifr);
7786 void igb_read_pci_cfg(struct e1000_hw *hw, u32 reg, u16 *value)
7788 struct igb_adapter *adapter = hw->back;
7790 pci_read_config_word(adapter->pdev, reg, value);
7793 void igb_write_pci_cfg(struct e1000_hw *hw, u32 reg, u16 *value)
7795 struct igb_adapter *adapter = hw->back;
7797 pci_write_config_word(adapter->pdev, reg, *value);
7800 s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
7802 struct igb_adapter *adapter = hw->back;
7804 if (pcie_capability_read_word(adapter->pdev, reg, value))
7805 return -E1000_ERR_CONFIG;
7810 s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
7812 struct igb_adapter *adapter = hw->back;
7814 if (pcie_capability_write_word(adapter->pdev, reg, *value))
7815 return -E1000_ERR_CONFIG;
7820 static void igb_vlan_mode(struct net_device *netdev, netdev_features_t features)
7822 struct igb_adapter *adapter = netdev_priv(netdev);
7823 struct e1000_hw *hw = &adapter->hw;
7825 bool enable = !!(features & NETIF_F_HW_VLAN_CTAG_RX);
7828 /* enable VLAN tag insert/strip */
7829 ctrl = rd32(E1000_CTRL);
7830 ctrl |= E1000_CTRL_VME;
7831 wr32(E1000_CTRL, ctrl);
7833 /* Disable CFI check */
7834 rctl = rd32(E1000_RCTL);
7835 rctl &= ~E1000_RCTL_CFIEN;
7836 wr32(E1000_RCTL, rctl);
7838 /* disable VLAN tag insert/strip */
7839 ctrl = rd32(E1000_CTRL);
7840 ctrl &= ~E1000_CTRL_VME;
7841 wr32(E1000_CTRL, ctrl);
7844 igb_set_vf_vlan_strip(adapter, adapter->vfs_allocated_count, enable);
7847 static int igb_vlan_rx_add_vid(struct net_device *netdev,
7848 __be16 proto, u16 vid)
7850 struct igb_adapter *adapter = netdev_priv(netdev);
7851 struct e1000_hw *hw = &adapter->hw;
7852 int pf_id = adapter->vfs_allocated_count;
7854 /* add the filter since PF can receive vlans w/o entry in vlvf */
7855 if (!vid || !(adapter->flags & IGB_FLAG_VLAN_PROMISC))
7856 igb_vfta_set(hw, vid, pf_id, true, !!vid);
7858 set_bit(vid, adapter->active_vlans);
7863 static int igb_vlan_rx_kill_vid(struct net_device *netdev,
7864 __be16 proto, u16 vid)
7866 struct igb_adapter *adapter = netdev_priv(netdev);
7867 int pf_id = adapter->vfs_allocated_count;
7868 struct e1000_hw *hw = &adapter->hw;
7870 /* remove VID from filter table */
7871 if (vid && !(adapter->flags & IGB_FLAG_VLAN_PROMISC))
7872 igb_vfta_set(hw, vid, pf_id, false, true);
7874 clear_bit(vid, adapter->active_vlans);
7879 static void igb_restore_vlan(struct igb_adapter *adapter)
7883 igb_vlan_mode(adapter->netdev, adapter->netdev->features);
7884 igb_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
7886 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
7887 igb_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
7890 int igb_set_spd_dplx(struct igb_adapter *adapter, u32 spd, u8 dplx)
7892 struct pci_dev *pdev = adapter->pdev;
7893 struct e1000_mac_info *mac = &adapter->hw.mac;
7897 /* Make sure dplx is at most 1 bit and lsb of speed is not set
7898 * for the switch() below to work
7900 if ((spd & 1) || (dplx & ~1))
7903 /* Fiber NIC's only allow 1000 gbps Full duplex
7904 * and 100Mbps Full duplex for 100baseFx sfp
7906 if (adapter->hw.phy.media_type == e1000_media_type_internal_serdes) {
7907 switch (spd + dplx) {
7908 case SPEED_10 + DUPLEX_HALF:
7909 case SPEED_10 + DUPLEX_FULL:
7910 case SPEED_100 + DUPLEX_HALF:
7917 switch (spd + dplx) {
7918 case SPEED_10 + DUPLEX_HALF:
7919 mac->forced_speed_duplex = ADVERTISE_10_HALF;
7921 case SPEED_10 + DUPLEX_FULL:
7922 mac->forced_speed_duplex = ADVERTISE_10_FULL;
7924 case SPEED_100 + DUPLEX_HALF:
7925 mac->forced_speed_duplex = ADVERTISE_100_HALF;
7927 case SPEED_100 + DUPLEX_FULL:
7928 mac->forced_speed_duplex = ADVERTISE_100_FULL;
7930 case SPEED_1000 + DUPLEX_FULL:
7932 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
7934 case SPEED_1000 + DUPLEX_HALF: /* not supported */
7939 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
7940 adapter->hw.phy.mdix = AUTO_ALL_MODES;
7945 dev_err(&pdev->dev, "Unsupported Speed/Duplex configuration\n");
7949 static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake,
7952 struct net_device *netdev = pci_get_drvdata(pdev);
7953 struct igb_adapter *adapter = netdev_priv(netdev);
7954 struct e1000_hw *hw = &adapter->hw;
7955 u32 ctrl, rctl, status;
7956 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
7960 netif_device_detach(netdev);
7962 if (netif_running(netdev))
7963 __igb_close(netdev, true);
7965 igb_ptp_suspend(adapter);
7967 igb_clear_interrupt_scheme(adapter);
7970 status = rd32(E1000_STATUS);
7971 if (status & E1000_STATUS_LU)
7972 wufc &= ~E1000_WUFC_LNKC;
7975 igb_setup_rctl(adapter);
7976 igb_set_rx_mode(netdev);
7978 /* turn on all-multi mode if wake on multicast is enabled */
7979 if (wufc & E1000_WUFC_MC) {
7980 rctl = rd32(E1000_RCTL);
7981 rctl |= E1000_RCTL_MPE;
7982 wr32(E1000_RCTL, rctl);
7985 ctrl = rd32(E1000_CTRL);
7986 ctrl |= E1000_CTRL_ADVD3WUC;
7987 wr32(E1000_CTRL, ctrl);
7989 /* Allow time for pending master requests to run */
7990 igb_disable_pcie_master(hw);
7992 wr32(E1000_WUC, E1000_WUC_PME_EN);
7993 wr32(E1000_WUFC, wufc);
7996 wr32(E1000_WUFC, 0);
7999 wake = wufc || adapter->en_mng_pt;
8001 igb_power_down_link(adapter);
8003 igb_power_up_link(adapter);
8006 *enable_wake = wake;
8008 /* Release control of h/w to f/w. If f/w is AMT enabled, this
8009 * would have already happened in close and is redundant.
8011 igb_release_hw_control(adapter);
8013 pci_disable_device(pdev);
8018 static void igb_deliver_wake_packet(struct net_device *netdev)
8020 struct igb_adapter *adapter = netdev_priv(netdev);
8021 struct e1000_hw *hw = &adapter->hw;
8022 struct sk_buff *skb;
8025 wupl = rd32(E1000_WUPL) & E1000_WUPL_MASK;
8027 /* WUPM stores only the first 128 bytes of the wake packet.
8028 * Read the packet only if we have the whole thing.
8030 if ((wupl == 0) || (wupl > E1000_WUPM_BYTES))
8033 skb = netdev_alloc_skb_ip_align(netdev, E1000_WUPM_BYTES);
8039 /* Ensure reads are 32-bit aligned */
8040 wupl = roundup(wupl, 4);
8042 memcpy_fromio(skb->data, hw->hw_addr + E1000_WUPM_REG(0), wupl);
8044 skb->protocol = eth_type_trans(skb, netdev);
8048 static int __maybe_unused igb_suspend(struct device *dev)
8050 return __igb_shutdown(to_pci_dev(dev), NULL, 0);
8053 static int __maybe_unused igb_resume(struct device *dev)
8055 struct pci_dev *pdev = to_pci_dev(dev);
8056 struct net_device *netdev = pci_get_drvdata(pdev);
8057 struct igb_adapter *adapter = netdev_priv(netdev);
8058 struct e1000_hw *hw = &adapter->hw;
8061 pci_set_power_state(pdev, PCI_D0);
8062 pci_restore_state(pdev);
8063 pci_save_state(pdev);
8065 if (!pci_device_is_present(pdev))
8067 err = pci_enable_device_mem(pdev);
8070 "igb: Cannot enable PCI device from suspend\n");
8073 pci_set_master(pdev);
8075 pci_enable_wake(pdev, PCI_D3hot, 0);
8076 pci_enable_wake(pdev, PCI_D3cold, 0);
8078 if (igb_init_interrupt_scheme(adapter, true)) {
8079 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
8085 /* let the f/w know that the h/w is now under the control of the
8088 igb_get_hw_control(adapter);
8090 val = rd32(E1000_WUS);
8091 if (val & WAKE_PKT_WUS)
8092 igb_deliver_wake_packet(netdev);
8094 wr32(E1000_WUS, ~0);
8097 if (!err && netif_running(netdev))
8098 err = __igb_open(netdev, true);
8101 netif_device_attach(netdev);
8107 static int __maybe_unused igb_runtime_idle(struct device *dev)
8109 struct pci_dev *pdev = to_pci_dev(dev);
8110 struct net_device *netdev = pci_get_drvdata(pdev);
8111 struct igb_adapter *adapter = netdev_priv(netdev);
8113 if (!igb_has_link(adapter))
8114 pm_schedule_suspend(dev, MSEC_PER_SEC * 5);
8119 static int __maybe_unused igb_runtime_suspend(struct device *dev)
8121 return __igb_shutdown(to_pci_dev(dev), NULL, 1);
8124 static int __maybe_unused igb_runtime_resume(struct device *dev)
8126 return igb_resume(dev);
8129 static void igb_shutdown(struct pci_dev *pdev)
8133 __igb_shutdown(pdev, &wake, 0);
8135 if (system_state == SYSTEM_POWER_OFF) {
8136 pci_wake_from_d3(pdev, wake);
8137 pci_set_power_state(pdev, PCI_D3hot);
8141 #ifdef CONFIG_PCI_IOV
8142 static int igb_sriov_reinit(struct pci_dev *dev)
8144 struct net_device *netdev = pci_get_drvdata(dev);
8145 struct igb_adapter *adapter = netdev_priv(netdev);
8146 struct pci_dev *pdev = adapter->pdev;
8150 if (netif_running(netdev))
8155 igb_clear_interrupt_scheme(adapter);
8157 igb_init_queue_configuration(adapter);
8159 if (igb_init_interrupt_scheme(adapter, true)) {
8161 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
8165 if (netif_running(netdev))
8173 static int igb_pci_disable_sriov(struct pci_dev *dev)
8175 int err = igb_disable_sriov(dev);
8178 err = igb_sriov_reinit(dev);
8183 static int igb_pci_enable_sriov(struct pci_dev *dev, int num_vfs)
8185 int err = igb_enable_sriov(dev, num_vfs);
8190 err = igb_sriov_reinit(dev);
8199 static int igb_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
8201 #ifdef CONFIG_PCI_IOV
8203 return igb_pci_disable_sriov(dev);
8205 return igb_pci_enable_sriov(dev, num_vfs);
8210 #ifdef CONFIG_NET_POLL_CONTROLLER
8211 /* Polling 'interrupt' - used by things like netconsole to send skbs
8212 * without having to re-enable interrupts. It's not called while
8213 * the interrupt routine is executing.
8215 static void igb_netpoll(struct net_device *netdev)
8217 struct igb_adapter *adapter = netdev_priv(netdev);
8218 struct e1000_hw *hw = &adapter->hw;
8219 struct igb_q_vector *q_vector;
8222 for (i = 0; i < adapter->num_q_vectors; i++) {
8223 q_vector = adapter->q_vector[i];
8224 if (adapter->flags & IGB_FLAG_HAS_MSIX)
8225 wr32(E1000_EIMC, q_vector->eims_value);
8227 igb_irq_disable(adapter);
8228 napi_schedule(&q_vector->napi);
8231 #endif /* CONFIG_NET_POLL_CONTROLLER */
8234 * igb_io_error_detected - called when PCI error is detected
8235 * @pdev: Pointer to PCI device
8236 * @state: The current pci connection state
8238 * This function is called after a PCI bus error affecting
8239 * this device has been detected.
8241 static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
8242 pci_channel_state_t state)
8244 struct net_device *netdev = pci_get_drvdata(pdev);
8245 struct igb_adapter *adapter = netdev_priv(netdev);
8247 netif_device_detach(netdev);
8249 if (state == pci_channel_io_perm_failure)
8250 return PCI_ERS_RESULT_DISCONNECT;
8252 if (netif_running(netdev))
8254 pci_disable_device(pdev);
8256 /* Request a slot slot reset. */
8257 return PCI_ERS_RESULT_NEED_RESET;
8261 * igb_io_slot_reset - called after the pci bus has been reset.
8262 * @pdev: Pointer to PCI device
8264 * Restart the card from scratch, as if from a cold-boot. Implementation
8265 * resembles the first-half of the igb_resume routine.
8267 static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
8269 struct net_device *netdev = pci_get_drvdata(pdev);
8270 struct igb_adapter *adapter = netdev_priv(netdev);
8271 struct e1000_hw *hw = &adapter->hw;
8272 pci_ers_result_t result;
8275 if (pci_enable_device_mem(pdev)) {
8277 "Cannot re-enable PCI device after reset.\n");
8278 result = PCI_ERS_RESULT_DISCONNECT;
8280 pci_set_master(pdev);
8281 pci_restore_state(pdev);
8282 pci_save_state(pdev);
8284 pci_enable_wake(pdev, PCI_D3hot, 0);
8285 pci_enable_wake(pdev, PCI_D3cold, 0);
8287 /* In case of PCI error, adapter lose its HW address
8288 * so we should re-assign it here.
8290 hw->hw_addr = adapter->io_addr;
8293 wr32(E1000_WUS, ~0);
8294 result = PCI_ERS_RESULT_RECOVERED;
8297 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8300 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
8302 /* non-fatal, continue */
8309 * igb_io_resume - called when traffic can start flowing again.
8310 * @pdev: Pointer to PCI device
8312 * This callback is called when the error recovery driver tells us that
8313 * its OK to resume normal operation. Implementation resembles the
8314 * second-half of the igb_resume routine.
8316 static void igb_io_resume(struct pci_dev *pdev)
8318 struct net_device *netdev = pci_get_drvdata(pdev);
8319 struct igb_adapter *adapter = netdev_priv(netdev);
8321 if (netif_running(netdev)) {
8322 if (igb_up(adapter)) {
8323 dev_err(&pdev->dev, "igb_up failed after reset\n");
8328 netif_device_attach(netdev);
8330 /* let the f/w know that the h/w is now under the control of the
8333 igb_get_hw_control(adapter);
8337 * igb_rar_set_index - Sync RAL[index] and RAH[index] registers with MAC table
8338 * @adapter: Pointer to adapter structure
8339 * @index: Index of the RAR entry which need to be synced with MAC table
8341 static void igb_rar_set_index(struct igb_adapter *adapter, u32 index)
8343 struct e1000_hw *hw = &adapter->hw;
8344 u32 rar_low, rar_high;
8345 u8 *addr = adapter->mac_table[index].addr;
8347 /* HW expects these to be in network order when they are plugged
8348 * into the registers which are little endian. In order to guarantee
8349 * that ordering we need to do an leXX_to_cpup here in order to be
8350 * ready for the byteswap that occurs with writel
8352 rar_low = le32_to_cpup((__le32 *)(addr));
8353 rar_high = le16_to_cpup((__le16 *)(addr + 4));
8355 /* Indicate to hardware the Address is Valid. */
8356 if (adapter->mac_table[index].state & IGB_MAC_STATE_IN_USE) {
8357 if (is_valid_ether_addr(addr))
8358 rar_high |= E1000_RAH_AV;
8360 switch (hw->mac.type) {
8363 rar_high |= E1000_RAH_POOL_1 *
8364 adapter->mac_table[index].queue;
8367 rar_high |= E1000_RAH_POOL_1 <<
8368 adapter->mac_table[index].queue;
8373 wr32(E1000_RAL(index), rar_low);
8375 wr32(E1000_RAH(index), rar_high);
8379 static int igb_set_vf_mac(struct igb_adapter *adapter,
8380 int vf, unsigned char *mac_addr)
8382 struct e1000_hw *hw = &adapter->hw;
8383 /* VF MAC addresses start at end of receive addresses and moves
8384 * towards the first, as a result a collision should not be possible
8386 int rar_entry = hw->mac.rar_entry_count - (vf + 1);
8387 unsigned char *vf_mac_addr = adapter->vf_data[vf].vf_mac_addresses;
8389 ether_addr_copy(vf_mac_addr, mac_addr);
8390 ether_addr_copy(adapter->mac_table[rar_entry].addr, mac_addr);
8391 adapter->mac_table[rar_entry].queue = vf;
8392 adapter->mac_table[rar_entry].state |= IGB_MAC_STATE_IN_USE;
8393 igb_rar_set_index(adapter, rar_entry);
8398 static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
8400 struct igb_adapter *adapter = netdev_priv(netdev);
8402 if (vf >= adapter->vfs_allocated_count)
8405 /* Setting the VF MAC to 0 reverts the IGB_VF_FLAG_PF_SET_MAC
8406 * flag and allows to overwrite the MAC via VF netdev. This
8407 * is necessary to allow libvirt a way to restore the original
8408 * MAC after unbinding vfio-pci and reloading igbvf after shutting
8411 if (is_zero_ether_addr(mac)) {
8412 adapter->vf_data[vf].flags &= ~IGB_VF_FLAG_PF_SET_MAC;
8413 dev_info(&adapter->pdev->dev,
8414 "remove administratively set MAC on VF %d\n",
8416 } else if (is_valid_ether_addr(mac)) {
8417 adapter->vf_data[vf].flags |= IGB_VF_FLAG_PF_SET_MAC;
8418 dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n",
8420 dev_info(&adapter->pdev->dev,
8421 "Reload the VF driver to make this change effective.");
8422 /* Generate additional warning if PF is down */
8423 if (test_bit(__IGB_DOWN, &adapter->state)) {
8424 dev_warn(&adapter->pdev->dev,
8425 "The VF MAC address has been set, but the PF device is not up.\n");
8426 dev_warn(&adapter->pdev->dev,
8427 "Bring the PF device up before attempting to use the VF device.\n");
8432 return igb_set_vf_mac(adapter, vf, mac);
8435 static int igb_link_mbps(int internal_link_speed)
8437 switch (internal_link_speed) {
8447 static void igb_set_vf_rate_limit(struct e1000_hw *hw, int vf, int tx_rate,
8454 /* Calculate the rate factor values to set */
8455 rf_int = link_speed / tx_rate;
8456 rf_dec = (link_speed - (rf_int * tx_rate));
8457 rf_dec = (rf_dec * BIT(E1000_RTTBCNRC_RF_INT_SHIFT)) /
8460 bcnrc_val = E1000_RTTBCNRC_RS_ENA;
8461 bcnrc_val |= ((rf_int << E1000_RTTBCNRC_RF_INT_SHIFT) &
8462 E1000_RTTBCNRC_RF_INT_MASK);
8463 bcnrc_val |= (rf_dec & E1000_RTTBCNRC_RF_DEC_MASK);
8468 wr32(E1000_RTTDQSEL, vf); /* vf X uses queue X */
8469 /* Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
8470 * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported.
8472 wr32(E1000_RTTBCNRM, 0x14);
8473 wr32(E1000_RTTBCNRC, bcnrc_val);
8476 static void igb_check_vf_rate_limit(struct igb_adapter *adapter)
8478 int actual_link_speed, i;
8479 bool reset_rate = false;
8481 /* VF TX rate limit was not set or not supported */
8482 if ((adapter->vf_rate_link_speed == 0) ||
8483 (adapter->hw.mac.type != e1000_82576))
8486 actual_link_speed = igb_link_mbps(adapter->link_speed);
8487 if (actual_link_speed != adapter->vf_rate_link_speed) {
8489 adapter->vf_rate_link_speed = 0;
8490 dev_info(&adapter->pdev->dev,
8491 "Link speed has been changed. VF Transmit rate is disabled\n");
8494 for (i = 0; i < adapter->vfs_allocated_count; i++) {
8496 adapter->vf_data[i].tx_rate = 0;
8498 igb_set_vf_rate_limit(&adapter->hw, i,
8499 adapter->vf_data[i].tx_rate,
8504 static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf,
8505 int min_tx_rate, int max_tx_rate)
8507 struct igb_adapter *adapter = netdev_priv(netdev);
8508 struct e1000_hw *hw = &adapter->hw;
8509 int actual_link_speed;
8511 if (hw->mac.type != e1000_82576)
8517 actual_link_speed = igb_link_mbps(adapter->link_speed);
8518 if ((vf >= adapter->vfs_allocated_count) ||
8519 (!(rd32(E1000_STATUS) & E1000_STATUS_LU)) ||
8520 (max_tx_rate < 0) ||
8521 (max_tx_rate > actual_link_speed))
8524 adapter->vf_rate_link_speed = actual_link_speed;
8525 adapter->vf_data[vf].tx_rate = (u16)max_tx_rate;
8526 igb_set_vf_rate_limit(hw, vf, max_tx_rate, actual_link_speed);
8531 static int igb_ndo_set_vf_spoofchk(struct net_device *netdev, int vf,
8534 struct igb_adapter *adapter = netdev_priv(netdev);
8535 struct e1000_hw *hw = &adapter->hw;
8536 u32 reg_val, reg_offset;
8538 if (!adapter->vfs_allocated_count)
8541 if (vf >= adapter->vfs_allocated_count)
8544 reg_offset = (hw->mac.type == e1000_82576) ? E1000_DTXSWC : E1000_TXSWC;
8545 reg_val = rd32(reg_offset);
8547 reg_val |= (BIT(vf) |
8548 BIT(vf + E1000_DTXSWC_VLAN_SPOOF_SHIFT));
8550 reg_val &= ~(BIT(vf) |
8551 BIT(vf + E1000_DTXSWC_VLAN_SPOOF_SHIFT));
8552 wr32(reg_offset, reg_val);
8554 adapter->vf_data[vf].spoofchk_enabled = setting;
8558 static int igb_ndo_get_vf_config(struct net_device *netdev,
8559 int vf, struct ifla_vf_info *ivi)
8561 struct igb_adapter *adapter = netdev_priv(netdev);
8562 if (vf >= adapter->vfs_allocated_count)
8565 memcpy(&ivi->mac, adapter->vf_data[vf].vf_mac_addresses, ETH_ALEN);
8566 ivi->max_tx_rate = adapter->vf_data[vf].tx_rate;
8567 ivi->min_tx_rate = 0;
8568 ivi->vlan = adapter->vf_data[vf].pf_vlan;
8569 ivi->qos = adapter->vf_data[vf].pf_qos;
8570 ivi->spoofchk = adapter->vf_data[vf].spoofchk_enabled;
8574 static void igb_vmm_control(struct igb_adapter *adapter)
8576 struct e1000_hw *hw = &adapter->hw;
8579 switch (hw->mac.type) {
8585 /* replication is not supported for 82575 */
8588 /* notify HW that the MAC is adding vlan tags */
8589 reg = rd32(E1000_DTXCTL);
8590 reg |= E1000_DTXCTL_VLAN_ADDED;
8591 wr32(E1000_DTXCTL, reg);
8594 /* enable replication vlan tag stripping */
8595 reg = rd32(E1000_RPLOLR);
8596 reg |= E1000_RPLOLR_STRVLAN;
8597 wr32(E1000_RPLOLR, reg);
8600 /* none of the above registers are supported by i350 */
8604 if (adapter->vfs_allocated_count) {
8605 igb_vmdq_set_loopback_pf(hw, true);
8606 igb_vmdq_set_replication_pf(hw, true);
8607 igb_vmdq_set_anti_spoofing_pf(hw, true,
8608 adapter->vfs_allocated_count);
8610 igb_vmdq_set_loopback_pf(hw, false);
8611 igb_vmdq_set_replication_pf(hw, false);
8615 static void igb_init_dmac(struct igb_adapter *adapter, u32 pba)
8617 struct e1000_hw *hw = &adapter->hw;
8621 if (hw->mac.type > e1000_82580) {
8622 if (adapter->flags & IGB_FLAG_DMAC) {
8625 /* force threshold to 0. */
8626 wr32(E1000_DMCTXTH, 0);
8628 /* DMA Coalescing high water mark needs to be greater
8629 * than the Rx threshold. Set hwm to PBA - max frame
8630 * size in 16B units, capping it at PBA - 6KB.
8632 hwm = 64 * (pba - 6);
8633 reg = rd32(E1000_FCRTC);
8634 reg &= ~E1000_FCRTC_RTH_COAL_MASK;
8635 reg |= ((hwm << E1000_FCRTC_RTH_COAL_SHIFT)
8636 & E1000_FCRTC_RTH_COAL_MASK);
8637 wr32(E1000_FCRTC, reg);
8639 /* Set the DMA Coalescing Rx threshold to PBA - 2 * max
8640 * frame size, capping it at PBA - 10KB.
8642 dmac_thr = pba - 10;
8643 reg = rd32(E1000_DMACR);
8644 reg &= ~E1000_DMACR_DMACTHR_MASK;
8645 reg |= ((dmac_thr << E1000_DMACR_DMACTHR_SHIFT)
8646 & E1000_DMACR_DMACTHR_MASK);
8648 /* transition to L0x or L1 if available..*/
8649 reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK);
8651 /* watchdog timer= +-1000 usec in 32usec intervals */
8654 /* Disable BMC-to-OS Watchdog Enable */
8655 if (hw->mac.type != e1000_i354)
8656 reg &= ~E1000_DMACR_DC_BMC2OSW_EN;
8658 wr32(E1000_DMACR, reg);
8660 /* no lower threshold to disable
8661 * coalescing(smart fifb)-UTRESH=0
8663 wr32(E1000_DMCRTRH, 0);
8665 reg = (IGB_DMCTLX_DCFLUSH_DIS | 0x4);
8667 wr32(E1000_DMCTLX, reg);
8669 /* free space in tx packet buffer to wake from
8672 wr32(E1000_DMCTXTH, (IGB_MIN_TXPBSIZE -
8673 (IGB_TX_BUF_4096 + adapter->max_frame_size)) >> 6);
8675 /* make low power state decision controlled
8678 reg = rd32(E1000_PCIEMISC);
8679 reg &= ~E1000_PCIEMISC_LX_DECISION;
8680 wr32(E1000_PCIEMISC, reg);
8681 } /* endif adapter->dmac is not disabled */
8682 } else if (hw->mac.type == e1000_82580) {
8683 u32 reg = rd32(E1000_PCIEMISC);
8685 wr32(E1000_PCIEMISC, reg & ~E1000_PCIEMISC_LX_DECISION);
8686 wr32(E1000_DMACR, 0);
8691 * igb_read_i2c_byte - Reads 8 bit word over I2C
8692 * @hw: pointer to hardware structure
8693 * @byte_offset: byte offset to read
8694 * @dev_addr: device address
8697 * Performs byte read operation over I2C interface at
8698 * a specified device address.
8700 s32 igb_read_i2c_byte(struct e1000_hw *hw, u8 byte_offset,
8701 u8 dev_addr, u8 *data)
8703 struct igb_adapter *adapter = container_of(hw, struct igb_adapter, hw);
8704 struct i2c_client *this_client = adapter->i2c_client;
8709 return E1000_ERR_I2C;
8711 swfw_mask = E1000_SWFW_PHY0_SM;
8713 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
8714 return E1000_ERR_SWFW_SYNC;
8716 status = i2c_smbus_read_byte_data(this_client, byte_offset);
8717 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
8720 return E1000_ERR_I2C;
8728 * igb_write_i2c_byte - Writes 8 bit word over I2C
8729 * @hw: pointer to hardware structure
8730 * @byte_offset: byte offset to write
8731 * @dev_addr: device address
8732 * @data: value to write
8734 * Performs byte write operation over I2C interface at
8735 * a specified device address.
8737 s32 igb_write_i2c_byte(struct e1000_hw *hw, u8 byte_offset,
8738 u8 dev_addr, u8 data)
8740 struct igb_adapter *adapter = container_of(hw, struct igb_adapter, hw);
8741 struct i2c_client *this_client = adapter->i2c_client;
8743 u16 swfw_mask = E1000_SWFW_PHY0_SM;
8746 return E1000_ERR_I2C;
8748 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
8749 return E1000_ERR_SWFW_SYNC;
8750 status = i2c_smbus_write_byte_data(this_client, byte_offset, data);
8751 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
8754 return E1000_ERR_I2C;
8760 int igb_reinit_queues(struct igb_adapter *adapter)
8762 struct net_device *netdev = adapter->netdev;
8763 struct pci_dev *pdev = adapter->pdev;
8766 if (netif_running(netdev))
8769 igb_reset_interrupt_capability(adapter);
8771 if (igb_init_interrupt_scheme(adapter, true)) {
8772 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
8776 if (netif_running(netdev))
8777 err = igb_open(netdev);
8782 static void igb_nfc_filter_exit(struct igb_adapter *adapter)
8784 struct igb_nfc_filter *rule;
8786 spin_lock(&adapter->nfc_lock);
8788 hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node)
8789 igb_erase_filter(adapter, rule);
8791 spin_unlock(&adapter->nfc_lock);
8794 static void igb_nfc_filter_restore(struct igb_adapter *adapter)
8796 struct igb_nfc_filter *rule;
8798 spin_lock(&adapter->nfc_lock);
8800 hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node)
8801 igb_add_filter(adapter, rule);
8803 spin_unlock(&adapter->nfc_lock);