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 struct igb_q_vector *new_q_vector;
1227 new_q_vector = kzalloc(size, GFP_KERNEL);
1229 kfree_rcu(q_vector, rcu);
1230 q_vector = new_q_vector;
1232 memset(q_vector, 0, size);
1237 /* initialize NAPI */
1238 netif_napi_add(adapter->netdev, &q_vector->napi,
1241 /* tie q_vector and adapter together */
1242 adapter->q_vector[v_idx] = q_vector;
1243 q_vector->adapter = adapter;
1245 /* initialize work limits */
1246 q_vector->tx.work_limit = adapter->tx_work_limit;
1248 /* initialize ITR configuration */
1249 q_vector->itr_register = adapter->io_addr + E1000_EITR(0);
1250 q_vector->itr_val = IGB_START_ITR;
1252 /* initialize pointer to rings */
1253 ring = q_vector->ring;
1257 /* rx or rx/tx vector */
1258 if (!adapter->rx_itr_setting || adapter->rx_itr_setting > 3)
1259 q_vector->itr_val = adapter->rx_itr_setting;
1261 /* tx only vector */
1262 if (!adapter->tx_itr_setting || adapter->tx_itr_setting > 3)
1263 q_vector->itr_val = adapter->tx_itr_setting;
1267 /* assign generic ring traits */
1268 ring->dev = &adapter->pdev->dev;
1269 ring->netdev = adapter->netdev;
1271 /* configure backlink on ring */
1272 ring->q_vector = q_vector;
1274 /* update q_vector Tx values */
1275 igb_add_ring(ring, &q_vector->tx);
1277 /* For 82575, context index must be unique per ring. */
1278 if (adapter->hw.mac.type == e1000_82575)
1279 set_bit(IGB_RING_FLAG_TX_CTX_IDX, &ring->flags);
1281 /* apply Tx specific ring traits */
1282 ring->count = adapter->tx_ring_count;
1283 ring->queue_index = txr_idx;
1285 u64_stats_init(&ring->tx_syncp);
1286 u64_stats_init(&ring->tx_syncp2);
1288 /* assign ring to adapter */
1289 adapter->tx_ring[txr_idx] = ring;
1291 /* push pointer to next ring */
1296 /* assign generic ring traits */
1297 ring->dev = &adapter->pdev->dev;
1298 ring->netdev = adapter->netdev;
1300 /* configure backlink on ring */
1301 ring->q_vector = q_vector;
1303 /* update q_vector Rx values */
1304 igb_add_ring(ring, &q_vector->rx);
1306 /* set flag indicating ring supports SCTP checksum offload */
1307 if (adapter->hw.mac.type >= e1000_82576)
1308 set_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags);
1310 /* On i350, i354, i210, and i211, loopback VLAN packets
1311 * have the tag byte-swapped.
1313 if (adapter->hw.mac.type >= e1000_i350)
1314 set_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &ring->flags);
1316 /* apply Rx specific ring traits */
1317 ring->count = adapter->rx_ring_count;
1318 ring->queue_index = rxr_idx;
1320 u64_stats_init(&ring->rx_syncp);
1322 /* assign ring to adapter */
1323 adapter->rx_ring[rxr_idx] = ring;
1331 * igb_alloc_q_vectors - Allocate memory for interrupt vectors
1332 * @adapter: board private structure to initialize
1334 * We allocate one q_vector per queue interrupt. If allocation fails we
1337 static int igb_alloc_q_vectors(struct igb_adapter *adapter)
1339 int q_vectors = adapter->num_q_vectors;
1340 int rxr_remaining = adapter->num_rx_queues;
1341 int txr_remaining = adapter->num_tx_queues;
1342 int rxr_idx = 0, txr_idx = 0, v_idx = 0;
1345 if (q_vectors >= (rxr_remaining + txr_remaining)) {
1346 for (; rxr_remaining; v_idx++) {
1347 err = igb_alloc_q_vector(adapter, q_vectors, v_idx,
1353 /* update counts and index */
1359 for (; v_idx < q_vectors; v_idx++) {
1360 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_idx);
1361 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_idx);
1363 err = igb_alloc_q_vector(adapter, q_vectors, v_idx,
1364 tqpv, txr_idx, rqpv, rxr_idx);
1369 /* update counts and index */
1370 rxr_remaining -= rqpv;
1371 txr_remaining -= tqpv;
1379 adapter->num_tx_queues = 0;
1380 adapter->num_rx_queues = 0;
1381 adapter->num_q_vectors = 0;
1384 igb_free_q_vector(adapter, v_idx);
1390 * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors
1391 * @adapter: board private structure to initialize
1392 * @msix: boolean value of MSIX capability
1394 * This function initializes the interrupts and allocates all of the queues.
1396 static int igb_init_interrupt_scheme(struct igb_adapter *adapter, bool msix)
1398 struct pci_dev *pdev = adapter->pdev;
1401 igb_set_interrupt_capability(adapter, msix);
1403 err = igb_alloc_q_vectors(adapter);
1405 dev_err(&pdev->dev, "Unable to allocate memory for vectors\n");
1406 goto err_alloc_q_vectors;
1409 igb_cache_ring_register(adapter);
1413 err_alloc_q_vectors:
1414 igb_reset_interrupt_capability(adapter);
1419 * igb_request_irq - initialize interrupts
1420 * @adapter: board private structure to initialize
1422 * Attempts to configure interrupts using the best available
1423 * capabilities of the hardware and kernel.
1425 static int igb_request_irq(struct igb_adapter *adapter)
1427 struct net_device *netdev = adapter->netdev;
1428 struct pci_dev *pdev = adapter->pdev;
1431 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1432 err = igb_request_msix(adapter);
1435 /* fall back to MSI */
1436 igb_free_all_tx_resources(adapter);
1437 igb_free_all_rx_resources(adapter);
1439 igb_clear_interrupt_scheme(adapter);
1440 err = igb_init_interrupt_scheme(adapter, false);
1444 igb_setup_all_tx_resources(adapter);
1445 igb_setup_all_rx_resources(adapter);
1446 igb_configure(adapter);
1449 igb_assign_vector(adapter->q_vector[0], 0);
1451 if (adapter->flags & IGB_FLAG_HAS_MSI) {
1452 err = request_irq(pdev->irq, igb_intr_msi, 0,
1453 netdev->name, adapter);
1457 /* fall back to legacy interrupts */
1458 igb_reset_interrupt_capability(adapter);
1459 adapter->flags &= ~IGB_FLAG_HAS_MSI;
1462 err = request_irq(pdev->irq, igb_intr, IRQF_SHARED,
1463 netdev->name, adapter);
1466 dev_err(&pdev->dev, "Error %d getting interrupt\n",
1473 static void igb_free_irq(struct igb_adapter *adapter)
1475 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1478 free_irq(adapter->msix_entries[vector++].vector, adapter);
1480 for (i = 0; i < adapter->num_q_vectors; i++)
1481 free_irq(adapter->msix_entries[vector++].vector,
1482 adapter->q_vector[i]);
1484 free_irq(adapter->pdev->irq, adapter);
1489 * igb_irq_disable - Mask off interrupt generation on the NIC
1490 * @adapter: board private structure
1492 static void igb_irq_disable(struct igb_adapter *adapter)
1494 struct e1000_hw *hw = &adapter->hw;
1496 /* we need to be careful when disabling interrupts. The VFs are also
1497 * mapped into these registers and so clearing the bits can cause
1498 * issues on the VF drivers so we only need to clear what we set
1500 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1501 u32 regval = rd32(E1000_EIAM);
1503 wr32(E1000_EIAM, regval & ~adapter->eims_enable_mask);
1504 wr32(E1000_EIMC, adapter->eims_enable_mask);
1505 regval = rd32(E1000_EIAC);
1506 wr32(E1000_EIAC, regval & ~adapter->eims_enable_mask);
1510 wr32(E1000_IMC, ~0);
1512 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1515 for (i = 0; i < adapter->num_q_vectors; i++)
1516 synchronize_irq(adapter->msix_entries[i].vector);
1518 synchronize_irq(adapter->pdev->irq);
1523 * igb_irq_enable - Enable default interrupt generation settings
1524 * @adapter: board private structure
1526 static void igb_irq_enable(struct igb_adapter *adapter)
1528 struct e1000_hw *hw = &adapter->hw;
1530 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
1531 u32 ims = E1000_IMS_LSC | E1000_IMS_DOUTSYNC | E1000_IMS_DRSTA;
1532 u32 regval = rd32(E1000_EIAC);
1534 wr32(E1000_EIAC, regval | adapter->eims_enable_mask);
1535 regval = rd32(E1000_EIAM);
1536 wr32(E1000_EIAM, regval | adapter->eims_enable_mask);
1537 wr32(E1000_EIMS, adapter->eims_enable_mask);
1538 if (adapter->vfs_allocated_count) {
1539 wr32(E1000_MBVFIMR, 0xFF);
1540 ims |= E1000_IMS_VMMB;
1542 wr32(E1000_IMS, ims);
1544 wr32(E1000_IMS, IMS_ENABLE_MASK |
1546 wr32(E1000_IAM, IMS_ENABLE_MASK |
1551 static void igb_update_mng_vlan(struct igb_adapter *adapter)
1553 struct e1000_hw *hw = &adapter->hw;
1554 u16 pf_id = adapter->vfs_allocated_count;
1555 u16 vid = adapter->hw.mng_cookie.vlan_id;
1556 u16 old_vid = adapter->mng_vlan_id;
1558 if (hw->mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
1559 /* add VID to filter table */
1560 igb_vfta_set(hw, vid, pf_id, true, true);
1561 adapter->mng_vlan_id = vid;
1563 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
1566 if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
1568 !test_bit(old_vid, adapter->active_vlans)) {
1569 /* remove VID from filter table */
1570 igb_vfta_set(hw, vid, pf_id, false, true);
1575 * igb_release_hw_control - release control of the h/w to f/w
1576 * @adapter: address of board private structure
1578 * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
1579 * For ASF and Pass Through versions of f/w this means that the
1580 * driver is no longer loaded.
1582 static void igb_release_hw_control(struct igb_adapter *adapter)
1584 struct e1000_hw *hw = &adapter->hw;
1587 /* Let firmware take over control of h/w */
1588 ctrl_ext = rd32(E1000_CTRL_EXT);
1589 wr32(E1000_CTRL_EXT,
1590 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1594 * igb_get_hw_control - get control of the h/w from f/w
1595 * @adapter: address of board private structure
1597 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
1598 * For ASF and Pass Through versions of f/w this means that
1599 * the driver is loaded.
1601 static void igb_get_hw_control(struct igb_adapter *adapter)
1603 struct e1000_hw *hw = &adapter->hw;
1606 /* Let firmware know the driver has taken over */
1607 ctrl_ext = rd32(E1000_CTRL_EXT);
1608 wr32(E1000_CTRL_EXT,
1609 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1613 * igb_configure - configure the hardware for RX and TX
1614 * @adapter: private board structure
1616 static void igb_configure(struct igb_adapter *adapter)
1618 struct net_device *netdev = adapter->netdev;
1621 igb_get_hw_control(adapter);
1622 igb_set_rx_mode(netdev);
1624 igb_restore_vlan(adapter);
1626 igb_setup_tctl(adapter);
1627 igb_setup_mrqc(adapter);
1628 igb_setup_rctl(adapter);
1630 igb_nfc_filter_restore(adapter);
1631 igb_configure_tx(adapter);
1632 igb_configure_rx(adapter);
1634 igb_rx_fifo_flush_82575(&adapter->hw);
1636 /* call igb_desc_unused which always leaves
1637 * at least 1 descriptor unused to make sure
1638 * next_to_use != next_to_clean
1640 for (i = 0; i < adapter->num_rx_queues; i++) {
1641 struct igb_ring *ring = adapter->rx_ring[i];
1642 igb_alloc_rx_buffers(ring, igb_desc_unused(ring));
1647 * igb_power_up_link - Power up the phy/serdes link
1648 * @adapter: address of board private structure
1650 void igb_power_up_link(struct igb_adapter *adapter)
1652 igb_reset_phy(&adapter->hw);
1654 if (adapter->hw.phy.media_type == e1000_media_type_copper)
1655 igb_power_up_phy_copper(&adapter->hw);
1657 igb_power_up_serdes_link_82575(&adapter->hw);
1659 igb_setup_link(&adapter->hw);
1663 * igb_power_down_link - Power down the phy/serdes link
1664 * @adapter: address of board private structure
1666 static void igb_power_down_link(struct igb_adapter *adapter)
1668 if (adapter->hw.phy.media_type == e1000_media_type_copper)
1669 igb_power_down_phy_copper_82575(&adapter->hw);
1671 igb_shutdown_serdes_link_82575(&adapter->hw);
1675 * Detect and switch function for Media Auto Sense
1676 * @adapter: address of the board private structure
1678 static void igb_check_swap_media(struct igb_adapter *adapter)
1680 struct e1000_hw *hw = &adapter->hw;
1681 u32 ctrl_ext, connsw;
1682 bool swap_now = false;
1684 ctrl_ext = rd32(E1000_CTRL_EXT);
1685 connsw = rd32(E1000_CONNSW);
1687 /* need to live swap if current media is copper and we have fiber/serdes
1691 if ((hw->phy.media_type == e1000_media_type_copper) &&
1692 (!(connsw & E1000_CONNSW_AUTOSENSE_EN))) {
1694 } else if ((hw->phy.media_type != e1000_media_type_copper) &&
1695 !(connsw & E1000_CONNSW_SERDESD)) {
1696 /* copper signal takes time to appear */
1697 if (adapter->copper_tries < 4) {
1698 adapter->copper_tries++;
1699 connsw |= E1000_CONNSW_AUTOSENSE_CONF;
1700 wr32(E1000_CONNSW, connsw);
1703 adapter->copper_tries = 0;
1704 if ((connsw & E1000_CONNSW_PHYSD) &&
1705 (!(connsw & E1000_CONNSW_PHY_PDN))) {
1707 connsw &= ~E1000_CONNSW_AUTOSENSE_CONF;
1708 wr32(E1000_CONNSW, connsw);
1716 switch (hw->phy.media_type) {
1717 case e1000_media_type_copper:
1718 netdev_info(adapter->netdev,
1719 "MAS: changing media to fiber/serdes\n");
1721 E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1722 adapter->flags |= IGB_FLAG_MEDIA_RESET;
1723 adapter->copper_tries = 0;
1725 case e1000_media_type_internal_serdes:
1726 case e1000_media_type_fiber:
1727 netdev_info(adapter->netdev,
1728 "MAS: changing media to copper\n");
1730 ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1731 adapter->flags |= IGB_FLAG_MEDIA_RESET;
1734 /* shouldn't get here during regular operation */
1735 netdev_err(adapter->netdev,
1736 "AMS: Invalid media type found, returning\n");
1739 wr32(E1000_CTRL_EXT, ctrl_ext);
1743 * igb_up - Open the interface and prepare it to handle traffic
1744 * @adapter: board private structure
1746 int igb_up(struct igb_adapter *adapter)
1748 struct e1000_hw *hw = &adapter->hw;
1751 /* hardware has been reset, we need to reload some things */
1752 igb_configure(adapter);
1754 clear_bit(__IGB_DOWN, &adapter->state);
1756 for (i = 0; i < adapter->num_q_vectors; i++)
1757 napi_enable(&(adapter->q_vector[i]->napi));
1759 if (adapter->flags & IGB_FLAG_HAS_MSIX)
1760 igb_configure_msix(adapter);
1762 igb_assign_vector(adapter->q_vector[0], 0);
1764 /* Clear any pending interrupts. */
1766 igb_irq_enable(adapter);
1768 /* notify VFs that reset has been completed */
1769 if (adapter->vfs_allocated_count) {
1770 u32 reg_data = rd32(E1000_CTRL_EXT);
1772 reg_data |= E1000_CTRL_EXT_PFRSTD;
1773 wr32(E1000_CTRL_EXT, reg_data);
1776 netif_tx_start_all_queues(adapter->netdev);
1778 /* start the watchdog. */
1779 hw->mac.get_link_status = 1;
1780 schedule_work(&adapter->watchdog_task);
1782 if ((adapter->flags & IGB_FLAG_EEE) &&
1783 (!hw->dev_spec._82575.eee_disable))
1784 adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
1789 void igb_down(struct igb_adapter *adapter)
1791 struct net_device *netdev = adapter->netdev;
1792 struct e1000_hw *hw = &adapter->hw;
1796 /* signal that we're down so the interrupt handler does not
1797 * reschedule our watchdog timer
1799 set_bit(__IGB_DOWN, &adapter->state);
1801 /* disable receives in the hardware */
1802 rctl = rd32(E1000_RCTL);
1803 wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
1804 /* flush and sleep below */
1806 igb_nfc_filter_exit(adapter);
1808 netif_carrier_off(netdev);
1809 netif_tx_stop_all_queues(netdev);
1811 /* disable transmits in the hardware */
1812 tctl = rd32(E1000_TCTL);
1813 tctl &= ~E1000_TCTL_EN;
1814 wr32(E1000_TCTL, tctl);
1815 /* flush both disables and wait for them to finish */
1817 usleep_range(10000, 11000);
1819 igb_irq_disable(adapter);
1821 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
1823 for (i = 0; i < adapter->num_q_vectors; i++) {
1824 if (adapter->q_vector[i]) {
1825 napi_synchronize(&adapter->q_vector[i]->napi);
1826 napi_disable(&adapter->q_vector[i]->napi);
1830 del_timer_sync(&adapter->watchdog_timer);
1831 del_timer_sync(&adapter->phy_info_timer);
1833 /* record the stats before reset*/
1834 spin_lock(&adapter->stats64_lock);
1835 igb_update_stats(adapter);
1836 spin_unlock(&adapter->stats64_lock);
1838 adapter->link_speed = 0;
1839 adapter->link_duplex = 0;
1841 if (!pci_channel_offline(adapter->pdev))
1844 /* clear VLAN promisc flag so VFTA will be updated if necessary */
1845 adapter->flags &= ~IGB_FLAG_VLAN_PROMISC;
1847 igb_clean_all_tx_rings(adapter);
1848 igb_clean_all_rx_rings(adapter);
1849 #ifdef CONFIG_IGB_DCA
1851 /* since we reset the hardware DCA settings were cleared */
1852 igb_setup_dca(adapter);
1856 void igb_reinit_locked(struct igb_adapter *adapter)
1858 WARN_ON(in_interrupt());
1859 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
1860 usleep_range(1000, 2000);
1863 clear_bit(__IGB_RESETTING, &adapter->state);
1866 /** igb_enable_mas - Media Autosense re-enable after swap
1868 * @adapter: adapter struct
1870 static void igb_enable_mas(struct igb_adapter *adapter)
1872 struct e1000_hw *hw = &adapter->hw;
1873 u32 connsw = rd32(E1000_CONNSW);
1875 /* configure for SerDes media detect */
1876 if ((hw->phy.media_type == e1000_media_type_copper) &&
1877 (!(connsw & E1000_CONNSW_SERDESD))) {
1878 connsw |= E1000_CONNSW_ENRGSRC;
1879 connsw |= E1000_CONNSW_AUTOSENSE_EN;
1880 wr32(E1000_CONNSW, connsw);
1885 void igb_reset(struct igb_adapter *adapter)
1887 struct pci_dev *pdev = adapter->pdev;
1888 struct e1000_hw *hw = &adapter->hw;
1889 struct e1000_mac_info *mac = &hw->mac;
1890 struct e1000_fc_info *fc = &hw->fc;
1893 /* Repartition Pba for greater than 9k mtu
1894 * To take effect CTRL.RST is required.
1896 switch (mac->type) {
1900 pba = rd32(E1000_RXPBS);
1901 pba = igb_rxpbs_adjust_82580(pba);
1904 pba = rd32(E1000_RXPBS);
1905 pba &= E1000_RXPBS_SIZE_MASK_82576;
1911 pba = E1000_PBA_34K;
1915 if (mac->type == e1000_82575) {
1916 u32 min_rx_space, min_tx_space, needed_tx_space;
1918 /* write Rx PBA so that hardware can report correct Tx PBA */
1919 wr32(E1000_PBA, pba);
1921 /* To maintain wire speed transmits, the Tx FIFO should be
1922 * large enough to accommodate two full transmit packets,
1923 * rounded up to the next 1KB and expressed in KB. Likewise,
1924 * the Rx FIFO should be large enough to accommodate at least
1925 * one full receive packet and is similarly rounded up and
1928 min_rx_space = DIV_ROUND_UP(MAX_JUMBO_FRAME_SIZE, 1024);
1930 /* The Tx FIFO also stores 16 bytes of information about the Tx
1931 * but don't include Ethernet FCS because hardware appends it.
1932 * We only need to round down to the nearest 512 byte block
1933 * count since the value we care about is 2 frames, not 1.
1935 min_tx_space = adapter->max_frame_size;
1936 min_tx_space += sizeof(union e1000_adv_tx_desc) - ETH_FCS_LEN;
1937 min_tx_space = DIV_ROUND_UP(min_tx_space, 512);
1939 /* upper 16 bits has Tx packet buffer allocation size in KB */
1940 needed_tx_space = min_tx_space - (rd32(E1000_PBA) >> 16);
1942 /* If current Tx allocation is less than the min Tx FIFO size,
1943 * and the min Tx FIFO size is less than the current Rx FIFO
1944 * allocation, take space away from current Rx allocation.
1946 if (needed_tx_space < pba) {
1947 pba -= needed_tx_space;
1949 /* if short on Rx space, Rx wins and must trump Tx
1952 if (pba < min_rx_space)
1956 /* adjust PBA for jumbo frames */
1957 wr32(E1000_PBA, pba);
1960 /* flow control settings
1961 * The high water mark must be low enough to fit one full frame
1962 * after transmitting the pause frame. As such we must have enough
1963 * space to allow for us to complete our current transmit and then
1964 * receive the frame that is in progress from the link partner.
1966 * - the full Rx FIFO size minus one full Tx plus one full Rx frame
1968 hwm = (pba << 10) - (adapter->max_frame_size + MAX_JUMBO_FRAME_SIZE);
1970 fc->high_water = hwm & 0xFFFFFFF0; /* 16-byte granularity */
1971 fc->low_water = fc->high_water - 16;
1972 fc->pause_time = 0xFFFF;
1974 fc->current_mode = fc->requested_mode;
1976 /* disable receive for all VFs and wait one second */
1977 if (adapter->vfs_allocated_count) {
1980 for (i = 0 ; i < adapter->vfs_allocated_count; i++)
1981 adapter->vf_data[i].flags &= IGB_VF_FLAG_PF_SET_MAC;
1983 /* ping all the active vfs to let them know we are going down */
1984 igb_ping_all_vfs(adapter);
1986 /* disable transmits and receives */
1987 wr32(E1000_VFRE, 0);
1988 wr32(E1000_VFTE, 0);
1991 /* Allow time for pending master requests to run */
1992 hw->mac.ops.reset_hw(hw);
1995 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
1996 /* need to resetup here after media swap */
1997 adapter->ei.get_invariants(hw);
1998 adapter->flags &= ~IGB_FLAG_MEDIA_RESET;
2000 if ((mac->type == e1000_82575) &&
2001 (adapter->flags & IGB_FLAG_MAS_ENABLE)) {
2002 igb_enable_mas(adapter);
2004 if (hw->mac.ops.init_hw(hw))
2005 dev_err(&pdev->dev, "Hardware Error\n");
2007 /* RAR registers were cleared during init_hw, clear mac table */
2008 igb_flush_mac_table(adapter);
2009 __dev_uc_unsync(adapter->netdev, NULL);
2011 /* Recover default RAR entry */
2012 igb_set_default_mac_filter(adapter);
2014 /* Flow control settings reset on hardware reset, so guarantee flow
2015 * control is off when forcing speed.
2017 if (!hw->mac.autoneg)
2018 igb_force_mac_fc(hw);
2020 igb_init_dmac(adapter, pba);
2021 #ifdef CONFIG_IGB_HWMON
2022 /* Re-initialize the thermal sensor on i350 devices. */
2023 if (!test_bit(__IGB_DOWN, &adapter->state)) {
2024 if (mac->type == e1000_i350 && hw->bus.func == 0) {
2025 /* If present, re-initialize the external thermal sensor
2029 mac->ops.init_thermal_sensor_thresh(hw);
2033 /* Re-establish EEE setting */
2034 if (hw->phy.media_type == e1000_media_type_copper) {
2035 switch (mac->type) {
2039 igb_set_eee_i350(hw, true, true);
2042 igb_set_eee_i354(hw, true, true);
2048 if (!netif_running(adapter->netdev))
2049 igb_power_down_link(adapter);
2051 igb_update_mng_vlan(adapter);
2053 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
2054 wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
2056 /* Re-enable PTP, where applicable. */
2057 if (adapter->ptp_flags & IGB_PTP_ENABLED)
2058 igb_ptp_reset(adapter);
2060 igb_get_phy_info(hw);
2063 static netdev_features_t igb_fix_features(struct net_device *netdev,
2064 netdev_features_t features)
2066 /* Since there is no support for separate Rx/Tx vlan accel
2067 * enable/disable make sure Tx flag is always in same state as Rx.
2069 if (features & NETIF_F_HW_VLAN_CTAG_RX)
2070 features |= NETIF_F_HW_VLAN_CTAG_TX;
2072 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
2077 static int igb_set_features(struct net_device *netdev,
2078 netdev_features_t features)
2080 netdev_features_t changed = netdev->features ^ features;
2081 struct igb_adapter *adapter = netdev_priv(netdev);
2083 if (changed & NETIF_F_HW_VLAN_CTAG_RX)
2084 igb_vlan_mode(netdev, features);
2086 if (!(changed & (NETIF_F_RXALL | NETIF_F_NTUPLE)))
2089 if (!(features & NETIF_F_NTUPLE)) {
2090 struct hlist_node *node2;
2091 struct igb_nfc_filter *rule;
2093 spin_lock(&adapter->nfc_lock);
2094 hlist_for_each_entry_safe(rule, node2,
2095 &adapter->nfc_filter_list, nfc_node) {
2096 igb_erase_filter(adapter, rule);
2097 hlist_del(&rule->nfc_node);
2100 spin_unlock(&adapter->nfc_lock);
2101 adapter->nfc_filter_count = 0;
2104 netdev->features = features;
2106 if (netif_running(netdev))
2107 igb_reinit_locked(adapter);
2114 static int igb_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
2115 struct net_device *dev,
2116 const unsigned char *addr, u16 vid,
2119 /* guarantee we can provide a unique filter for the unicast address */
2120 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
2121 struct igb_adapter *adapter = netdev_priv(dev);
2122 int vfn = adapter->vfs_allocated_count;
2124 if (netdev_uc_count(dev) >= igb_available_rars(adapter, vfn))
2128 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
2131 #define IGB_MAX_MAC_HDR_LEN 127
2132 #define IGB_MAX_NETWORK_HDR_LEN 511
2134 static netdev_features_t
2135 igb_features_check(struct sk_buff *skb, struct net_device *dev,
2136 netdev_features_t features)
2138 unsigned int network_hdr_len, mac_hdr_len;
2140 /* Make certain the headers can be described by a context descriptor */
2141 mac_hdr_len = skb_network_header(skb) - skb->data;
2142 if (unlikely(mac_hdr_len > IGB_MAX_MAC_HDR_LEN))
2143 return features & ~(NETIF_F_HW_CSUM |
2145 NETIF_F_HW_VLAN_CTAG_TX |
2149 network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
2150 if (unlikely(network_hdr_len > IGB_MAX_NETWORK_HDR_LEN))
2151 return features & ~(NETIF_F_HW_CSUM |
2156 /* We can only support IPV4 TSO in tunnels if we can mangle the
2157 * inner IP ID field, so strip TSO if MANGLEID is not supported.
2159 if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
2160 features &= ~NETIF_F_TSO;
2165 static const struct net_device_ops igb_netdev_ops = {
2166 .ndo_open = igb_open,
2167 .ndo_stop = igb_close,
2168 .ndo_start_xmit = igb_xmit_frame,
2169 .ndo_get_stats64 = igb_get_stats64,
2170 .ndo_set_rx_mode = igb_set_rx_mode,
2171 .ndo_set_mac_address = igb_set_mac,
2172 .ndo_change_mtu = igb_change_mtu,
2173 .ndo_do_ioctl = igb_ioctl,
2174 .ndo_tx_timeout = igb_tx_timeout,
2175 .ndo_validate_addr = eth_validate_addr,
2176 .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid,
2177 .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid,
2178 .ndo_set_vf_mac = igb_ndo_set_vf_mac,
2179 .ndo_set_vf_vlan = igb_ndo_set_vf_vlan,
2180 .ndo_set_vf_rate = igb_ndo_set_vf_bw,
2181 .ndo_set_vf_spoofchk = igb_ndo_set_vf_spoofchk,
2182 .ndo_get_vf_config = igb_ndo_get_vf_config,
2183 #ifdef CONFIG_NET_POLL_CONTROLLER
2184 .ndo_poll_controller = igb_netpoll,
2186 .ndo_fix_features = igb_fix_features,
2187 .ndo_set_features = igb_set_features,
2188 .ndo_fdb_add = igb_ndo_fdb_add,
2189 .ndo_features_check = igb_features_check,
2193 * igb_set_fw_version - Configure version string for ethtool
2194 * @adapter: adapter struct
2196 void igb_set_fw_version(struct igb_adapter *adapter)
2198 struct e1000_hw *hw = &adapter->hw;
2199 struct e1000_fw_version fw;
2201 igb_get_fw_version(hw, &fw);
2203 switch (hw->mac.type) {
2206 if (!(igb_get_flash_presence_i210(hw))) {
2207 snprintf(adapter->fw_version,
2208 sizeof(adapter->fw_version),
2210 fw.invm_major, fw.invm_minor,
2216 /* if option is rom valid, display its version too */
2218 snprintf(adapter->fw_version,
2219 sizeof(adapter->fw_version),
2220 "%d.%d, 0x%08x, %d.%d.%d",
2221 fw.eep_major, fw.eep_minor, fw.etrack_id,
2222 fw.or_major, fw.or_build, fw.or_patch);
2224 } else if (fw.etrack_id != 0X0000) {
2225 snprintf(adapter->fw_version,
2226 sizeof(adapter->fw_version),
2228 fw.eep_major, fw.eep_minor, fw.etrack_id);
2230 snprintf(adapter->fw_version,
2231 sizeof(adapter->fw_version),
2233 fw.eep_major, fw.eep_minor, fw.eep_build);
2240 * igb_init_mas - init Media Autosense feature if enabled in the NVM
2242 * @adapter: adapter struct
2244 static void igb_init_mas(struct igb_adapter *adapter)
2246 struct e1000_hw *hw = &adapter->hw;
2249 hw->nvm.ops.read(hw, NVM_COMPAT, 1, &eeprom_data);
2250 switch (hw->bus.func) {
2252 if (eeprom_data & IGB_MAS_ENABLE_0) {
2253 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2254 netdev_info(adapter->netdev,
2255 "MAS: Enabling Media Autosense for port %d\n",
2260 if (eeprom_data & IGB_MAS_ENABLE_1) {
2261 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2262 netdev_info(adapter->netdev,
2263 "MAS: Enabling Media Autosense for port %d\n",
2268 if (eeprom_data & IGB_MAS_ENABLE_2) {
2269 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2270 netdev_info(adapter->netdev,
2271 "MAS: Enabling Media Autosense for port %d\n",
2276 if (eeprom_data & IGB_MAS_ENABLE_3) {
2277 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2278 netdev_info(adapter->netdev,
2279 "MAS: Enabling Media Autosense for port %d\n",
2284 /* Shouldn't get here */
2285 netdev_err(adapter->netdev,
2286 "MAS: Invalid port configuration, returning\n");
2292 * igb_init_i2c - Init I2C interface
2293 * @adapter: pointer to adapter structure
2295 static s32 igb_init_i2c(struct igb_adapter *adapter)
2299 /* I2C interface supported on i350 devices */
2300 if (adapter->hw.mac.type != e1000_i350)
2303 /* Initialize the i2c bus which is controlled by the registers.
2304 * This bus will use the i2c_algo_bit structue that implements
2305 * the protocol through toggling of the 4 bits in the register.
2307 adapter->i2c_adap.owner = THIS_MODULE;
2308 adapter->i2c_algo = igb_i2c_algo;
2309 adapter->i2c_algo.data = adapter;
2310 adapter->i2c_adap.algo_data = &adapter->i2c_algo;
2311 adapter->i2c_adap.dev.parent = &adapter->pdev->dev;
2312 strlcpy(adapter->i2c_adap.name, "igb BB",
2313 sizeof(adapter->i2c_adap.name));
2314 status = i2c_bit_add_bus(&adapter->i2c_adap);
2319 * igb_probe - Device Initialization Routine
2320 * @pdev: PCI device information struct
2321 * @ent: entry in igb_pci_tbl
2323 * Returns 0 on success, negative on failure
2325 * igb_probe initializes an adapter identified by a pci_dev structure.
2326 * The OS initialization, configuring of the adapter private structure,
2327 * and a hardware reset occur.
2329 static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2331 struct net_device *netdev;
2332 struct igb_adapter *adapter;
2333 struct e1000_hw *hw;
2334 u16 eeprom_data = 0;
2336 static int global_quad_port_a; /* global quad port a indication */
2337 const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
2338 int err, pci_using_dac;
2339 u8 part_str[E1000_PBANUM_LENGTH];
2341 /* Catch broken hardware that put the wrong VF device ID in
2342 * the PCIe SR-IOV capability.
2344 if (pdev->is_virtfn) {
2345 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
2346 pci_name(pdev), pdev->vendor, pdev->device);
2350 err = pci_enable_device_mem(pdev);
2355 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
2359 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2362 "No usable DMA configuration, aborting\n");
2367 err = pci_request_mem_regions(pdev, igb_driver_name);
2371 pci_enable_pcie_error_reporting(pdev);
2373 pci_set_master(pdev);
2374 pci_save_state(pdev);
2377 netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
2380 goto err_alloc_etherdev;
2382 SET_NETDEV_DEV(netdev, &pdev->dev);
2384 pci_set_drvdata(pdev, netdev);
2385 adapter = netdev_priv(netdev);
2386 adapter->netdev = netdev;
2387 adapter->pdev = pdev;
2390 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
2393 adapter->io_addr = pci_iomap(pdev, 0, 0);
2394 if (!adapter->io_addr)
2396 /* hw->hw_addr can be altered, we'll use adapter->io_addr for unmap */
2397 hw->hw_addr = adapter->io_addr;
2399 netdev->netdev_ops = &igb_netdev_ops;
2400 igb_set_ethtool_ops(netdev);
2401 netdev->watchdog_timeo = 5 * HZ;
2403 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
2405 netdev->mem_start = pci_resource_start(pdev, 0);
2406 netdev->mem_end = pci_resource_end(pdev, 0);
2408 /* PCI config space info */
2409 hw->vendor_id = pdev->vendor;
2410 hw->device_id = pdev->device;
2411 hw->revision_id = pdev->revision;
2412 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2413 hw->subsystem_device_id = pdev->subsystem_device;
2415 /* Copy the default MAC, PHY and NVM function pointers */
2416 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
2417 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
2418 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
2419 /* Initialize skew-specific constants */
2420 err = ei->get_invariants(hw);
2424 /* setup the private structure */
2425 err = igb_sw_init(adapter);
2429 igb_get_bus_info_pcie(hw);
2431 hw->phy.autoneg_wait_to_complete = false;
2433 /* Copper options */
2434 if (hw->phy.media_type == e1000_media_type_copper) {
2435 hw->phy.mdix = AUTO_ALL_MODES;
2436 hw->phy.disable_polarity_correction = false;
2437 hw->phy.ms_type = e1000_ms_hw_default;
2440 if (igb_check_reset_block(hw))
2441 dev_info(&pdev->dev,
2442 "PHY reset is blocked due to SOL/IDER session.\n");
2444 /* features is initialized to 0 in allocation, it might have bits
2445 * set by igb_sw_init so we should use an or instead of an
2448 netdev->features |= NETIF_F_SG |
2455 if (hw->mac.type >= e1000_82576)
2456 netdev->features |= NETIF_F_SCTP_CRC;
2458 #define IGB_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
2459 NETIF_F_GSO_GRE_CSUM | \
2460 NETIF_F_GSO_IPXIP4 | \
2461 NETIF_F_GSO_IPXIP6 | \
2462 NETIF_F_GSO_UDP_TUNNEL | \
2463 NETIF_F_GSO_UDP_TUNNEL_CSUM)
2465 netdev->gso_partial_features = IGB_GSO_PARTIAL_FEATURES;
2466 netdev->features |= NETIF_F_GSO_PARTIAL | IGB_GSO_PARTIAL_FEATURES;
2468 /* copy netdev features into list of user selectable features */
2469 netdev->hw_features |= netdev->features |
2470 NETIF_F_HW_VLAN_CTAG_RX |
2471 NETIF_F_HW_VLAN_CTAG_TX |
2474 if (hw->mac.type >= e1000_i350)
2475 netdev->hw_features |= NETIF_F_NTUPLE;
2478 netdev->features |= NETIF_F_HIGHDMA;
2480 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
2481 netdev->mpls_features |= NETIF_F_HW_CSUM;
2482 netdev->hw_enc_features |= netdev->vlan_features;
2484 /* set this bit last since it cannot be part of vlan_features */
2485 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
2486 NETIF_F_HW_VLAN_CTAG_RX |
2487 NETIF_F_HW_VLAN_CTAG_TX;
2489 netdev->priv_flags |= IFF_SUPP_NOFCS;
2491 netdev->priv_flags |= IFF_UNICAST_FLT;
2493 /* MTU range: 68 - 9216 */
2494 netdev->min_mtu = ETH_MIN_MTU;
2495 netdev->max_mtu = MAX_STD_JUMBO_FRAME_SIZE;
2497 adapter->en_mng_pt = igb_enable_mng_pass_thru(hw);
2499 /* before reading the NVM, reset the controller to put the device in a
2500 * known good starting state
2502 hw->mac.ops.reset_hw(hw);
2504 /* make sure the NVM is good , i211/i210 parts can have special NVM
2505 * that doesn't contain a checksum
2507 switch (hw->mac.type) {
2510 if (igb_get_flash_presence_i210(hw)) {
2511 if (hw->nvm.ops.validate(hw) < 0) {
2513 "The NVM Checksum Is Not Valid\n");
2520 if (hw->nvm.ops.validate(hw) < 0) {
2521 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
2528 if (eth_platform_get_mac_address(&pdev->dev, hw->mac.addr)) {
2529 /* copy the MAC address out of the NVM */
2530 if (hw->mac.ops.read_mac_addr(hw))
2531 dev_err(&pdev->dev, "NVM Read Error\n");
2534 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
2536 if (!is_valid_ether_addr(netdev->dev_addr)) {
2537 dev_err(&pdev->dev, "Invalid MAC Address\n");
2542 igb_set_default_mac_filter(adapter);
2544 /* get firmware version for ethtool -i */
2545 igb_set_fw_version(adapter);
2547 /* configure RXPBSIZE and TXPBSIZE */
2548 if (hw->mac.type == e1000_i210) {
2549 wr32(E1000_RXPBS, I210_RXPBSIZE_DEFAULT);
2550 wr32(E1000_TXPBS, I210_TXPBSIZE_DEFAULT);
2553 setup_timer(&adapter->watchdog_timer, igb_watchdog,
2554 (unsigned long) adapter);
2555 setup_timer(&adapter->phy_info_timer, igb_update_phy_info,
2556 (unsigned long) adapter);
2558 INIT_WORK(&adapter->reset_task, igb_reset_task);
2559 INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
2561 /* Initialize link properties that are user-changeable */
2562 adapter->fc_autoneg = true;
2563 hw->mac.autoneg = true;
2564 hw->phy.autoneg_advertised = 0x2f;
2566 hw->fc.requested_mode = e1000_fc_default;
2567 hw->fc.current_mode = e1000_fc_default;
2569 igb_validate_mdi_setting(hw);
2571 /* By default, support wake on port A */
2572 if (hw->bus.func == 0)
2573 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2575 /* Check the NVM for wake support on non-port A ports */
2576 if (hw->mac.type >= e1000_82580)
2577 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
2578 NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
2580 else if (hw->bus.func == 1)
2581 hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
2583 if (eeprom_data & IGB_EEPROM_APME)
2584 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2586 /* now that we have the eeprom settings, apply the special cases where
2587 * the eeprom may be wrong or the board simply won't support wake on
2588 * lan on a particular port
2590 switch (pdev->device) {
2591 case E1000_DEV_ID_82575GB_QUAD_COPPER:
2592 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2594 case E1000_DEV_ID_82575EB_FIBER_SERDES:
2595 case E1000_DEV_ID_82576_FIBER:
2596 case E1000_DEV_ID_82576_SERDES:
2597 /* Wake events only supported on port A for dual fiber
2598 * regardless of eeprom setting
2600 if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1)
2601 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2603 case E1000_DEV_ID_82576_QUAD_COPPER:
2604 case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
2605 /* if quad port adapter, disable WoL on all but port A */
2606 if (global_quad_port_a != 0)
2607 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2609 adapter->flags |= IGB_FLAG_QUAD_PORT_A;
2610 /* Reset for multiple quad port adapters */
2611 if (++global_quad_port_a == 4)
2612 global_quad_port_a = 0;
2615 /* If the device can't wake, don't set software support */
2616 if (!device_can_wakeup(&adapter->pdev->dev))
2617 adapter->flags &= ~IGB_FLAG_WOL_SUPPORTED;
2620 /* initialize the wol settings based on the eeprom settings */
2621 if (adapter->flags & IGB_FLAG_WOL_SUPPORTED)
2622 adapter->wol |= E1000_WUFC_MAG;
2624 /* Some vendors want WoL disabled by default, but still supported */
2625 if ((hw->mac.type == e1000_i350) &&
2626 (pdev->subsystem_vendor == PCI_VENDOR_ID_HP)) {
2627 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2631 /* Some vendors want the ability to Use the EEPROM setting as
2632 * enable/disable only, and not for capability
2634 if (((hw->mac.type == e1000_i350) ||
2635 (hw->mac.type == e1000_i354)) &&
2636 (pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)) {
2637 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2640 if (hw->mac.type == e1000_i350) {
2641 if (((pdev->subsystem_device == 0x5001) ||
2642 (pdev->subsystem_device == 0x5002)) &&
2643 (hw->bus.func == 0)) {
2644 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2647 if (pdev->subsystem_device == 0x1F52)
2648 adapter->flags |= IGB_FLAG_WOL_SUPPORTED;
2651 device_set_wakeup_enable(&adapter->pdev->dev,
2652 adapter->flags & IGB_FLAG_WOL_SUPPORTED);
2654 /* reset the hardware with the new settings */
2657 /* Init the I2C interface */
2658 err = igb_init_i2c(adapter);
2660 dev_err(&pdev->dev, "failed to init i2c interface\n");
2664 /* let the f/w know that the h/w is now under the control of the
2667 igb_get_hw_control(adapter);
2669 strcpy(netdev->name, "eth%d");
2670 err = register_netdev(netdev);
2674 /* carrier off reporting is important to ethtool even BEFORE open */
2675 netif_carrier_off(netdev);
2677 #ifdef CONFIG_IGB_DCA
2678 if (dca_add_requester(&pdev->dev) == 0) {
2679 adapter->flags |= IGB_FLAG_DCA_ENABLED;
2680 dev_info(&pdev->dev, "DCA enabled\n");
2681 igb_setup_dca(adapter);
2685 #ifdef CONFIG_IGB_HWMON
2686 /* Initialize the thermal sensor on i350 devices. */
2687 if (hw->mac.type == e1000_i350 && hw->bus.func == 0) {
2690 /* Read the NVM to determine if this i350 device supports an
2691 * external thermal sensor.
2693 hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_word);
2694 if (ets_word != 0x0000 && ets_word != 0xFFFF)
2695 adapter->ets = true;
2697 adapter->ets = false;
2698 if (igb_sysfs_init(adapter))
2700 "failed to allocate sysfs resources\n");
2702 adapter->ets = false;
2705 /* Check if Media Autosense is enabled */
2707 if (hw->dev_spec._82575.mas_capable)
2708 igb_init_mas(adapter);
2710 /* do hw tstamp init after resetting */
2711 igb_ptp_init(adapter);
2713 dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
2714 /* print bus type/speed/width info, not applicable to i354 */
2715 if (hw->mac.type != e1000_i354) {
2716 dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n",
2718 ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
2719 (hw->bus.speed == e1000_bus_speed_5000) ? "5.0Gb/s" :
2721 ((hw->bus.width == e1000_bus_width_pcie_x4) ?
2723 (hw->bus.width == e1000_bus_width_pcie_x2) ?
2725 (hw->bus.width == e1000_bus_width_pcie_x1) ?
2726 "Width x1" : "unknown"), netdev->dev_addr);
2729 if ((hw->mac.type >= e1000_i210 ||
2730 igb_get_flash_presence_i210(hw))) {
2731 ret_val = igb_read_part_string(hw, part_str,
2732 E1000_PBANUM_LENGTH);
2734 ret_val = -E1000_ERR_INVM_VALUE_NOT_FOUND;
2738 strcpy(part_str, "Unknown");
2739 dev_info(&pdev->dev, "%s: PBA No: %s\n", netdev->name, part_str);
2740 dev_info(&pdev->dev,
2741 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
2742 (adapter->flags & IGB_FLAG_HAS_MSIX) ? "MSI-X" :
2743 (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
2744 adapter->num_rx_queues, adapter->num_tx_queues);
2745 if (hw->phy.media_type == e1000_media_type_copper) {
2746 switch (hw->mac.type) {
2750 /* Enable EEE for internal copper PHY devices */
2751 err = igb_set_eee_i350(hw, true, true);
2753 (!hw->dev_spec._82575.eee_disable)) {
2754 adapter->eee_advert =
2755 MDIO_EEE_100TX | MDIO_EEE_1000T;
2756 adapter->flags |= IGB_FLAG_EEE;
2760 if ((rd32(E1000_CTRL_EXT) &
2761 E1000_CTRL_EXT_LINK_MODE_SGMII)) {
2762 err = igb_set_eee_i354(hw, true, true);
2764 (!hw->dev_spec._82575.eee_disable)) {
2765 adapter->eee_advert =
2766 MDIO_EEE_100TX | MDIO_EEE_1000T;
2767 adapter->flags |= IGB_FLAG_EEE;
2775 pm_runtime_put_noidle(&pdev->dev);
2779 igb_release_hw_control(adapter);
2780 memset(&adapter->i2c_adap, 0, sizeof(adapter->i2c_adap));
2782 if (!igb_check_reset_block(hw))
2785 if (hw->flash_address)
2786 iounmap(hw->flash_address);
2788 kfree(adapter->mac_table);
2789 kfree(adapter->shadow_vfta);
2790 igb_clear_interrupt_scheme(adapter);
2791 #ifdef CONFIG_PCI_IOV
2792 igb_disable_sriov(pdev);
2794 pci_iounmap(pdev, adapter->io_addr);
2796 free_netdev(netdev);
2798 pci_disable_pcie_error_reporting(pdev);
2799 pci_release_mem_regions(pdev);
2802 pci_disable_device(pdev);
2806 #ifdef CONFIG_PCI_IOV
2807 static int igb_disable_sriov(struct pci_dev *pdev)
2809 struct net_device *netdev = pci_get_drvdata(pdev);
2810 struct igb_adapter *adapter = netdev_priv(netdev);
2811 struct e1000_hw *hw = &adapter->hw;
2812 unsigned long flags;
2814 /* reclaim resources allocated to VFs */
2815 if (adapter->vf_data) {
2816 /* disable iov and allow time for transactions to clear */
2817 if (pci_vfs_assigned(pdev)) {
2818 dev_warn(&pdev->dev,
2819 "Cannot deallocate SR-IOV virtual functions while they are assigned - VFs will not be deallocated\n");
2822 pci_disable_sriov(pdev);
2825 spin_lock_irqsave(&adapter->vfs_lock, flags);
2826 kfree(adapter->vf_mac_list);
2827 adapter->vf_mac_list = NULL;
2828 kfree(adapter->vf_data);
2829 adapter->vf_data = NULL;
2830 adapter->vfs_allocated_count = 0;
2831 spin_unlock_irqrestore(&adapter->vfs_lock, flags);
2832 wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
2835 dev_info(&pdev->dev, "IOV Disabled\n");
2837 /* Re-enable DMA Coalescing flag since IOV is turned off */
2838 adapter->flags |= IGB_FLAG_DMAC;
2844 static int igb_enable_sriov(struct pci_dev *pdev, int num_vfs)
2846 struct net_device *netdev = pci_get_drvdata(pdev);
2847 struct igb_adapter *adapter = netdev_priv(netdev);
2848 int old_vfs = pci_num_vf(pdev);
2849 struct vf_mac_filter *mac_list;
2851 int num_vf_mac_filters, i;
2853 if (!(adapter->flags & IGB_FLAG_HAS_MSIX) || num_vfs > 7) {
2861 dev_info(&pdev->dev, "%d pre-allocated VFs found - override max_vfs setting of %d\n",
2863 adapter->vfs_allocated_count = old_vfs;
2865 adapter->vfs_allocated_count = num_vfs;
2867 adapter->vf_data = kcalloc(adapter->vfs_allocated_count,
2868 sizeof(struct vf_data_storage), GFP_KERNEL);
2870 /* if allocation failed then we do not support SR-IOV */
2871 if (!adapter->vf_data) {
2872 adapter->vfs_allocated_count = 0;
2874 "Unable to allocate memory for VF Data Storage\n");
2879 /* Due to the limited number of RAR entries calculate potential
2880 * number of MAC filters available for the VFs. Reserve entries
2881 * for PF default MAC, PF MAC filters and at least one RAR entry
2882 * for each VF for VF MAC.
2884 num_vf_mac_filters = adapter->hw.mac.rar_entry_count -
2885 (1 + IGB_PF_MAC_FILTERS_RESERVED +
2886 adapter->vfs_allocated_count);
2888 adapter->vf_mac_list = kcalloc(num_vf_mac_filters,
2889 sizeof(struct vf_mac_filter),
2892 mac_list = adapter->vf_mac_list;
2893 INIT_LIST_HEAD(&adapter->vf_macs.l);
2895 if (adapter->vf_mac_list) {
2896 /* Initialize list of VF MAC filters */
2897 for (i = 0; i < num_vf_mac_filters; i++) {
2899 mac_list->free = true;
2900 list_add(&mac_list->l, &adapter->vf_macs.l);
2904 /* If we could not allocate memory for the VF MAC filters
2905 * we can continue without this feature but warn user.
2908 "Unable to allocate memory for VF MAC filter list\n");
2911 /* only call pci_enable_sriov() if no VFs are allocated already */
2913 err = pci_enable_sriov(pdev, adapter->vfs_allocated_count);
2917 dev_info(&pdev->dev, "%d VFs allocated\n",
2918 adapter->vfs_allocated_count);
2919 for (i = 0; i < adapter->vfs_allocated_count; i++)
2920 igb_vf_configure(adapter, i);
2922 /* DMA Coalescing is not supported in IOV mode. */
2923 adapter->flags &= ~IGB_FLAG_DMAC;
2927 kfree(adapter->vf_mac_list);
2928 adapter->vf_mac_list = NULL;
2929 kfree(adapter->vf_data);
2930 adapter->vf_data = NULL;
2931 adapter->vfs_allocated_count = 0;
2938 * igb_remove_i2c - Cleanup I2C interface
2939 * @adapter: pointer to adapter structure
2941 static void igb_remove_i2c(struct igb_adapter *adapter)
2943 /* free the adapter bus structure */
2944 i2c_del_adapter(&adapter->i2c_adap);
2948 * igb_remove - Device Removal Routine
2949 * @pdev: PCI device information struct
2951 * igb_remove is called by the PCI subsystem to alert the driver
2952 * that it should release a PCI device. The could be caused by a
2953 * Hot-Plug event, or because the driver is going to be removed from
2956 static void igb_remove(struct pci_dev *pdev)
2958 struct net_device *netdev = pci_get_drvdata(pdev);
2959 struct igb_adapter *adapter = netdev_priv(netdev);
2960 struct e1000_hw *hw = &adapter->hw;
2962 pm_runtime_get_noresume(&pdev->dev);
2963 #ifdef CONFIG_IGB_HWMON
2964 igb_sysfs_exit(adapter);
2966 igb_remove_i2c(adapter);
2967 igb_ptp_stop(adapter);
2968 /* The watchdog timer may be rescheduled, so explicitly
2969 * disable watchdog from being rescheduled.
2971 set_bit(__IGB_DOWN, &adapter->state);
2972 del_timer_sync(&adapter->watchdog_timer);
2973 del_timer_sync(&adapter->phy_info_timer);
2975 cancel_work_sync(&adapter->reset_task);
2976 cancel_work_sync(&adapter->watchdog_task);
2978 #ifdef CONFIG_IGB_DCA
2979 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
2980 dev_info(&pdev->dev, "DCA disabled\n");
2981 dca_remove_requester(&pdev->dev);
2982 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
2983 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
2987 /* Release control of h/w to f/w. If f/w is AMT enabled, this
2988 * would have already happened in close and is redundant.
2990 igb_release_hw_control(adapter);
2992 #ifdef CONFIG_PCI_IOV
2993 igb_disable_sriov(pdev);
2996 unregister_netdev(netdev);
2998 igb_clear_interrupt_scheme(adapter);
3000 pci_iounmap(pdev, adapter->io_addr);
3001 if (hw->flash_address)
3002 iounmap(hw->flash_address);
3003 pci_release_mem_regions(pdev);
3005 kfree(adapter->mac_table);
3006 kfree(adapter->shadow_vfta);
3007 free_netdev(netdev);
3009 pci_disable_pcie_error_reporting(pdev);
3011 pci_disable_device(pdev);
3015 * igb_probe_vfs - Initialize vf data storage and add VFs to pci config space
3016 * @adapter: board private structure to initialize
3018 * This function initializes the vf specific data storage and then attempts to
3019 * allocate the VFs. The reason for ordering it this way is because it is much
3020 * mor expensive time wise to disable SR-IOV than it is to allocate and free
3021 * the memory for the VFs.
3023 static void igb_probe_vfs(struct igb_adapter *adapter)
3025 #ifdef CONFIG_PCI_IOV
3026 struct pci_dev *pdev = adapter->pdev;
3027 struct e1000_hw *hw = &adapter->hw;
3029 /* Virtualization features not supported on i210 and 82580 family. */
3030 if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211) ||
3031 (hw->mac.type == e1000_82580))
3034 /* Of the below we really only want the effect of getting
3035 * IGB_FLAG_HAS_MSIX set (if available), without which
3036 * igb_enable_sriov() has no effect.
3038 igb_set_interrupt_capability(adapter, true);
3039 igb_reset_interrupt_capability(adapter);
3041 pci_sriov_set_totalvfs(pdev, 7);
3042 igb_enable_sriov(pdev, max_vfs);
3044 #endif /* CONFIG_PCI_IOV */
3047 static void igb_init_queue_configuration(struct igb_adapter *adapter)
3049 struct e1000_hw *hw = &adapter->hw;
3052 /* Determine the maximum number of RSS queues supported. */
3053 switch (hw->mac.type) {
3055 max_rss_queues = IGB_MAX_RX_QUEUES_I211;
3059 max_rss_queues = IGB_MAX_RX_QUEUES_82575;
3062 /* I350 cannot do RSS and SR-IOV at the same time */
3063 if (!!adapter->vfs_allocated_count) {
3069 if (!!adapter->vfs_allocated_count) {
3077 max_rss_queues = IGB_MAX_RX_QUEUES;
3081 adapter->rss_queues = min_t(u32, max_rss_queues, num_online_cpus());
3083 igb_set_flag_queue_pairs(adapter, max_rss_queues);
3086 void igb_set_flag_queue_pairs(struct igb_adapter *adapter,
3087 const u32 max_rss_queues)
3089 struct e1000_hw *hw = &adapter->hw;
3091 /* Determine if we need to pair queues. */
3092 switch (hw->mac.type) {
3095 /* Device supports enough interrupts without queue pairing. */
3103 /* If rss_queues > half of max_rss_queues, pair the queues in
3104 * order to conserve interrupts due to limited supply.
3106 if (adapter->rss_queues > (max_rss_queues / 2))
3107 adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
3109 adapter->flags &= ~IGB_FLAG_QUEUE_PAIRS;
3115 * igb_sw_init - Initialize general software structures (struct igb_adapter)
3116 * @adapter: board private structure to initialize
3118 * igb_sw_init initializes the Adapter private data structure.
3119 * Fields are initialized based on PCI device information and
3120 * OS network device settings (MTU size).
3122 static int igb_sw_init(struct igb_adapter *adapter)
3124 struct e1000_hw *hw = &adapter->hw;
3125 struct net_device *netdev = adapter->netdev;
3126 struct pci_dev *pdev = adapter->pdev;
3128 pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
3130 /* set default ring sizes */
3131 adapter->tx_ring_count = IGB_DEFAULT_TXD;
3132 adapter->rx_ring_count = IGB_DEFAULT_RXD;
3134 /* set default ITR values */
3135 adapter->rx_itr_setting = IGB_DEFAULT_ITR;
3136 adapter->tx_itr_setting = IGB_DEFAULT_ITR;
3138 /* set default work limits */
3139 adapter->tx_work_limit = IGB_DEFAULT_TX_WORK;
3141 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN +
3143 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
3145 spin_lock_init(&adapter->nfc_lock);
3146 spin_lock_init(&adapter->stats64_lock);
3148 /* init spinlock to avoid concurrency of VF resources */
3149 spin_lock_init(&adapter->vfs_lock);
3150 #ifdef CONFIG_PCI_IOV
3151 switch (hw->mac.type) {
3155 dev_warn(&pdev->dev,
3156 "Maximum of 7 VFs per PF, using max\n");
3157 max_vfs = adapter->vfs_allocated_count = 7;
3159 adapter->vfs_allocated_count = max_vfs;
3160 if (adapter->vfs_allocated_count)
3161 dev_warn(&pdev->dev,
3162 "Enabling SR-IOV VFs using the module parameter is deprecated - please use the pci sysfs interface.\n");
3167 #endif /* CONFIG_PCI_IOV */
3169 /* Assume MSI-X interrupts, will be checked during IRQ allocation */
3170 adapter->flags |= IGB_FLAG_HAS_MSIX;
3172 adapter->mac_table = kzalloc(sizeof(struct igb_mac_addr) *
3173 hw->mac.rar_entry_count, GFP_ATOMIC);
3174 if (!adapter->mac_table)
3177 igb_probe_vfs(adapter);
3179 igb_init_queue_configuration(adapter);
3181 /* Setup and initialize a copy of the hw vlan table array */
3182 adapter->shadow_vfta = kcalloc(E1000_VLAN_FILTER_TBL_SIZE, sizeof(u32),
3184 if (!adapter->shadow_vfta)
3187 /* This call may decrease the number of queues */
3188 if (igb_init_interrupt_scheme(adapter, true)) {
3189 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
3193 /* Explicitly disable IRQ since the NIC can be in any state. */
3194 igb_irq_disable(adapter);
3196 if (hw->mac.type >= e1000_i350)
3197 adapter->flags &= ~IGB_FLAG_DMAC;
3199 set_bit(__IGB_DOWN, &adapter->state);
3204 * igb_open - Called when a network interface is made active
3205 * @netdev: network interface device structure
3207 * Returns 0 on success, negative value on failure
3209 * The open entry point is called when a network interface is made
3210 * active by the system (IFF_UP). At this point all resources needed
3211 * for transmit and receive operations are allocated, the interrupt
3212 * handler is registered with the OS, the watchdog timer is started,
3213 * and the stack is notified that the interface is ready.
3215 static int __igb_open(struct net_device *netdev, bool resuming)
3217 struct igb_adapter *adapter = netdev_priv(netdev);
3218 struct e1000_hw *hw = &adapter->hw;
3219 struct pci_dev *pdev = adapter->pdev;
3223 /* disallow open during test */
3224 if (test_bit(__IGB_TESTING, &adapter->state)) {
3230 pm_runtime_get_sync(&pdev->dev);
3232 netif_carrier_off(netdev);
3234 /* allocate transmit descriptors */
3235 err = igb_setup_all_tx_resources(adapter);
3239 /* allocate receive descriptors */
3240 err = igb_setup_all_rx_resources(adapter);
3244 igb_power_up_link(adapter);
3246 /* before we allocate an interrupt, we must be ready to handle it.
3247 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
3248 * as soon as we call pci_request_irq, so we have to setup our
3249 * clean_rx handler before we do so.
3251 igb_configure(adapter);
3253 err = igb_request_irq(adapter);
3257 /* Notify the stack of the actual queue counts. */
3258 err = netif_set_real_num_tx_queues(adapter->netdev,
3259 adapter->num_tx_queues);
3261 goto err_set_queues;
3263 err = netif_set_real_num_rx_queues(adapter->netdev,
3264 adapter->num_rx_queues);
3266 goto err_set_queues;
3268 /* From here on the code is the same as igb_up() */
3269 clear_bit(__IGB_DOWN, &adapter->state);
3271 for (i = 0; i < adapter->num_q_vectors; i++)
3272 napi_enable(&(adapter->q_vector[i]->napi));
3274 /* Clear any pending interrupts. */
3277 igb_irq_enable(adapter);
3279 /* notify VFs that reset has been completed */
3280 if (adapter->vfs_allocated_count) {
3281 u32 reg_data = rd32(E1000_CTRL_EXT);
3283 reg_data |= E1000_CTRL_EXT_PFRSTD;
3284 wr32(E1000_CTRL_EXT, reg_data);
3287 netif_tx_start_all_queues(netdev);
3290 pm_runtime_put(&pdev->dev);
3292 /* start the watchdog. */
3293 hw->mac.get_link_status = 1;
3294 schedule_work(&adapter->watchdog_task);
3299 igb_free_irq(adapter);
3301 igb_release_hw_control(adapter);
3302 igb_power_down_link(adapter);
3303 igb_free_all_rx_resources(adapter);
3305 igb_free_all_tx_resources(adapter);
3309 pm_runtime_put(&pdev->dev);
3314 int igb_open(struct net_device *netdev)
3316 return __igb_open(netdev, false);
3320 * igb_close - Disables a network interface
3321 * @netdev: network interface device structure
3323 * Returns 0, this is not allowed to fail
3325 * The close entry point is called when an interface is de-activated
3326 * by the OS. The hardware is still under the driver's control, but
3327 * needs to be disabled. A global MAC reset is issued to stop the
3328 * hardware, and all transmit and receive resources are freed.
3330 static int __igb_close(struct net_device *netdev, bool suspending)
3332 struct igb_adapter *adapter = netdev_priv(netdev);
3333 struct pci_dev *pdev = adapter->pdev;
3335 WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
3338 pm_runtime_get_sync(&pdev->dev);
3341 igb_free_irq(adapter);
3343 igb_free_all_tx_resources(adapter);
3344 igb_free_all_rx_resources(adapter);
3347 pm_runtime_put_sync(&pdev->dev);
3351 int igb_close(struct net_device *netdev)
3353 if (netif_device_present(netdev) || netdev->dismantle)
3354 return __igb_close(netdev, false);
3359 * igb_setup_tx_resources - allocate Tx resources (Descriptors)
3360 * @tx_ring: tx descriptor ring (for a specific queue) to setup
3362 * Return 0 on success, negative on failure
3364 int igb_setup_tx_resources(struct igb_ring *tx_ring)
3366 struct device *dev = tx_ring->dev;
3369 size = sizeof(struct igb_tx_buffer) * tx_ring->count;
3371 tx_ring->tx_buffer_info = vmalloc(size);
3372 if (!tx_ring->tx_buffer_info)
3375 /* round up to nearest 4K */
3376 tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
3377 tx_ring->size = ALIGN(tx_ring->size, 4096);
3379 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
3380 &tx_ring->dma, GFP_KERNEL);
3384 tx_ring->next_to_use = 0;
3385 tx_ring->next_to_clean = 0;
3390 vfree(tx_ring->tx_buffer_info);
3391 tx_ring->tx_buffer_info = NULL;
3392 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
3397 * igb_setup_all_tx_resources - wrapper to allocate Tx resources
3398 * (Descriptors) for all queues
3399 * @adapter: board private structure
3401 * Return 0 on success, negative on failure
3403 static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
3405 struct pci_dev *pdev = adapter->pdev;
3408 for (i = 0; i < adapter->num_tx_queues; i++) {
3409 err = igb_setup_tx_resources(adapter->tx_ring[i]);
3412 "Allocation for Tx Queue %u failed\n", i);
3413 for (i--; i >= 0; i--)
3414 igb_free_tx_resources(adapter->tx_ring[i]);
3423 * igb_setup_tctl - configure the transmit control registers
3424 * @adapter: Board private structure
3426 void igb_setup_tctl(struct igb_adapter *adapter)
3428 struct e1000_hw *hw = &adapter->hw;
3431 /* disable queue 0 which is enabled by default on 82575 and 82576 */
3432 wr32(E1000_TXDCTL(0), 0);
3434 /* Program the Transmit Control Register */
3435 tctl = rd32(E1000_TCTL);
3436 tctl &= ~E1000_TCTL_CT;
3437 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
3438 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
3440 igb_config_collision_dist(hw);
3442 /* Enable transmits */
3443 tctl |= E1000_TCTL_EN;
3445 wr32(E1000_TCTL, tctl);
3449 * igb_configure_tx_ring - Configure transmit ring after Reset
3450 * @adapter: board private structure
3451 * @ring: tx ring to configure
3453 * Configure a transmit ring after a reset.
3455 void igb_configure_tx_ring(struct igb_adapter *adapter,
3456 struct igb_ring *ring)
3458 struct e1000_hw *hw = &adapter->hw;
3460 u64 tdba = ring->dma;
3461 int reg_idx = ring->reg_idx;
3463 /* disable the queue */
3464 wr32(E1000_TXDCTL(reg_idx), 0);
3468 wr32(E1000_TDLEN(reg_idx),
3469 ring->count * sizeof(union e1000_adv_tx_desc));
3470 wr32(E1000_TDBAL(reg_idx),
3471 tdba & 0x00000000ffffffffULL);
3472 wr32(E1000_TDBAH(reg_idx), tdba >> 32);
3474 ring->tail = adapter->io_addr + E1000_TDT(reg_idx);
3475 wr32(E1000_TDH(reg_idx), 0);
3476 writel(0, ring->tail);
3478 txdctl |= IGB_TX_PTHRESH;
3479 txdctl |= IGB_TX_HTHRESH << 8;
3480 txdctl |= IGB_TX_WTHRESH << 16;
3482 /* reinitialize tx_buffer_info */
3483 memset(ring->tx_buffer_info, 0,
3484 sizeof(struct igb_tx_buffer) * ring->count);
3486 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
3487 wr32(E1000_TXDCTL(reg_idx), txdctl);
3491 * igb_configure_tx - Configure transmit Unit after Reset
3492 * @adapter: board private structure
3494 * Configure the Tx unit of the MAC after a reset.
3496 static void igb_configure_tx(struct igb_adapter *adapter)
3500 for (i = 0; i < adapter->num_tx_queues; i++)
3501 igb_configure_tx_ring(adapter, adapter->tx_ring[i]);
3505 * igb_setup_rx_resources - allocate Rx resources (Descriptors)
3506 * @rx_ring: Rx descriptor ring (for a specific queue) to setup
3508 * Returns 0 on success, negative on failure
3510 int igb_setup_rx_resources(struct igb_ring *rx_ring)
3512 struct device *dev = rx_ring->dev;
3515 size = sizeof(struct igb_rx_buffer) * rx_ring->count;
3517 rx_ring->rx_buffer_info = vmalloc(size);
3518 if (!rx_ring->rx_buffer_info)
3521 /* Round up to nearest 4K */
3522 rx_ring->size = rx_ring->count * sizeof(union e1000_adv_rx_desc);
3523 rx_ring->size = ALIGN(rx_ring->size, 4096);
3525 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
3526 &rx_ring->dma, GFP_KERNEL);
3530 rx_ring->next_to_alloc = 0;
3531 rx_ring->next_to_clean = 0;
3532 rx_ring->next_to_use = 0;
3537 vfree(rx_ring->rx_buffer_info);
3538 rx_ring->rx_buffer_info = NULL;
3539 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
3544 * igb_setup_all_rx_resources - wrapper to allocate Rx resources
3545 * (Descriptors) for all queues
3546 * @adapter: board private structure
3548 * Return 0 on success, negative on failure
3550 static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
3552 struct pci_dev *pdev = adapter->pdev;
3555 for (i = 0; i < adapter->num_rx_queues; i++) {
3556 err = igb_setup_rx_resources(adapter->rx_ring[i]);
3559 "Allocation for Rx Queue %u failed\n", i);
3560 for (i--; i >= 0; i--)
3561 igb_free_rx_resources(adapter->rx_ring[i]);
3570 * igb_setup_mrqc - configure the multiple receive queue control registers
3571 * @adapter: Board private structure
3573 static void igb_setup_mrqc(struct igb_adapter *adapter)
3575 struct e1000_hw *hw = &adapter->hw;
3577 u32 j, num_rx_queues;
3580 netdev_rss_key_fill(rss_key, sizeof(rss_key));
3581 for (j = 0; j < 10; j++)
3582 wr32(E1000_RSSRK(j), rss_key[j]);
3584 num_rx_queues = adapter->rss_queues;
3586 switch (hw->mac.type) {
3588 /* 82576 supports 2 RSS queues for SR-IOV */
3589 if (adapter->vfs_allocated_count)
3596 if (adapter->rss_indir_tbl_init != num_rx_queues) {
3597 for (j = 0; j < IGB_RETA_SIZE; j++)
3598 adapter->rss_indir_tbl[j] =
3599 (j * num_rx_queues) / IGB_RETA_SIZE;
3600 adapter->rss_indir_tbl_init = num_rx_queues;
3602 igb_write_rss_indir_tbl(adapter);
3604 /* Disable raw packet checksumming so that RSS hash is placed in
3605 * descriptor on writeback. No need to enable TCP/UDP/IP checksum
3606 * offloads as they are enabled by default
3608 rxcsum = rd32(E1000_RXCSUM);
3609 rxcsum |= E1000_RXCSUM_PCSD;
3611 if (adapter->hw.mac.type >= e1000_82576)
3612 /* Enable Receive Checksum Offload for SCTP */
3613 rxcsum |= E1000_RXCSUM_CRCOFL;
3615 /* Don't need to set TUOFL or IPOFL, they default to 1 */
3616 wr32(E1000_RXCSUM, rxcsum);
3618 /* Generate RSS hash based on packet types, TCP/UDP
3619 * port numbers and/or IPv4/v6 src and dst addresses
3621 mrqc = E1000_MRQC_RSS_FIELD_IPV4 |
3622 E1000_MRQC_RSS_FIELD_IPV4_TCP |
3623 E1000_MRQC_RSS_FIELD_IPV6 |
3624 E1000_MRQC_RSS_FIELD_IPV6_TCP |
3625 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX;
3627 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV4_UDP)
3628 mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP;
3629 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV6_UDP)
3630 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP;
3632 /* If VMDq is enabled then we set the appropriate mode for that, else
3633 * we default to RSS so that an RSS hash is calculated per packet even
3634 * if we are only using one queue
3636 if (adapter->vfs_allocated_count) {
3637 if (hw->mac.type > e1000_82575) {
3638 /* Set the default pool for the PF's first queue */
3639 u32 vtctl = rd32(E1000_VT_CTL);
3641 vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK |
3642 E1000_VT_CTL_DISABLE_DEF_POOL);
3643 vtctl |= adapter->vfs_allocated_count <<
3644 E1000_VT_CTL_DEFAULT_POOL_SHIFT;
3645 wr32(E1000_VT_CTL, vtctl);
3647 if (adapter->rss_queues > 1)
3648 mrqc |= E1000_MRQC_ENABLE_VMDQ_RSS_MQ;
3650 mrqc |= E1000_MRQC_ENABLE_VMDQ;
3652 if (hw->mac.type != e1000_i211)
3653 mrqc |= E1000_MRQC_ENABLE_RSS_MQ;
3655 igb_vmm_control(adapter);
3657 wr32(E1000_MRQC, mrqc);
3661 * igb_setup_rctl - configure the receive control registers
3662 * @adapter: Board private structure
3664 void igb_setup_rctl(struct igb_adapter *adapter)
3666 struct e1000_hw *hw = &adapter->hw;
3669 rctl = rd32(E1000_RCTL);
3671 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
3672 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
3674 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
3675 (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
3677 /* enable stripping of CRC. It's unlikely this will break BMC
3678 * redirection as it did with e1000. Newer features require
3679 * that the HW strips the CRC.
3681 rctl |= E1000_RCTL_SECRC;
3683 /* disable store bad packets and clear size bits. */
3684 rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256);
3686 /* enable LPE to allow for reception of jumbo frames */
3687 rctl |= E1000_RCTL_LPE;
3689 /* disable queue 0 to prevent tail write w/o re-config */
3690 wr32(E1000_RXDCTL(0), 0);
3692 /* Attention!!! For SR-IOV PF driver operations you must enable
3693 * queue drop for all VF and PF queues to prevent head of line blocking
3694 * if an un-trusted VF does not provide descriptors to hardware.
3696 if (adapter->vfs_allocated_count) {
3697 /* set all queue drop enable bits */
3698 wr32(E1000_QDE, ALL_QUEUES);
3701 /* This is useful for sniffing bad packets. */
3702 if (adapter->netdev->features & NETIF_F_RXALL) {
3703 /* UPE and MPE will be handled by normal PROMISC logic
3704 * in e1000e_set_rx_mode
3706 rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
3707 E1000_RCTL_BAM | /* RX All Bcast Pkts */
3708 E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
3710 rctl &= ~(E1000_RCTL_DPF | /* Allow filtered pause */
3711 E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
3712 /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
3713 * and that breaks VLANs.
3717 wr32(E1000_RCTL, rctl);
3720 static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
3723 struct e1000_hw *hw = &adapter->hw;
3726 if (size > MAX_JUMBO_FRAME_SIZE)
3727 size = MAX_JUMBO_FRAME_SIZE;
3729 vmolr = rd32(E1000_VMOLR(vfn));
3730 vmolr &= ~E1000_VMOLR_RLPML_MASK;
3731 vmolr |= size | E1000_VMOLR_LPE;
3732 wr32(E1000_VMOLR(vfn), vmolr);
3737 static inline void igb_set_vf_vlan_strip(struct igb_adapter *adapter,
3738 int vfn, bool enable)
3740 struct e1000_hw *hw = &adapter->hw;
3743 if (hw->mac.type < e1000_82576)
3746 if (hw->mac.type == e1000_i350)
3747 reg = E1000_DVMOLR(vfn);
3749 reg = E1000_VMOLR(vfn);
3753 val |= E1000_VMOLR_STRVLAN;
3755 val &= ~(E1000_VMOLR_STRVLAN);
3759 static inline void igb_set_vmolr(struct igb_adapter *adapter,
3762 struct e1000_hw *hw = &adapter->hw;
3765 /* This register exists only on 82576 and newer so if we are older then
3766 * we should exit and do nothing
3768 if (hw->mac.type < e1000_82576)
3771 vmolr = rd32(E1000_VMOLR(vfn));
3773 vmolr |= E1000_VMOLR_AUPE; /* Accept untagged packets */
3775 vmolr &= ~(E1000_VMOLR_AUPE); /* Tagged packets ONLY */
3777 /* clear all bits that might not be set */
3778 vmolr &= ~(E1000_VMOLR_BAM | E1000_VMOLR_RSSE);
3780 if (adapter->rss_queues > 1 && vfn == adapter->vfs_allocated_count)
3781 vmolr |= E1000_VMOLR_RSSE; /* enable RSS */
3782 /* for VMDq only allow the VFs and pool 0 to accept broadcast and
3785 if (vfn <= adapter->vfs_allocated_count)
3786 vmolr |= E1000_VMOLR_BAM; /* Accept broadcast */
3788 wr32(E1000_VMOLR(vfn), vmolr);
3792 * igb_configure_rx_ring - Configure a receive ring after Reset
3793 * @adapter: board private structure
3794 * @ring: receive ring to be configured
3796 * Configure the Rx unit of the MAC after a reset.
3798 void igb_configure_rx_ring(struct igb_adapter *adapter,
3799 struct igb_ring *ring)
3801 struct e1000_hw *hw = &adapter->hw;
3802 union e1000_adv_rx_desc *rx_desc;
3803 u64 rdba = ring->dma;
3804 int reg_idx = ring->reg_idx;
3805 u32 srrctl = 0, rxdctl = 0;
3807 /* disable the queue */
3808 wr32(E1000_RXDCTL(reg_idx), 0);
3810 /* Set DMA base address registers */
3811 wr32(E1000_RDBAL(reg_idx),
3812 rdba & 0x00000000ffffffffULL);
3813 wr32(E1000_RDBAH(reg_idx), rdba >> 32);
3814 wr32(E1000_RDLEN(reg_idx),
3815 ring->count * sizeof(union e1000_adv_rx_desc));
3817 /* initialize head and tail */
3818 ring->tail = adapter->io_addr + E1000_RDT(reg_idx);
3819 wr32(E1000_RDH(reg_idx), 0);
3820 writel(0, ring->tail);
3822 /* set descriptor configuration */
3823 srrctl = IGB_RX_HDR_LEN << E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
3824 if (ring_uses_large_buffer(ring))
3825 srrctl |= IGB_RXBUFFER_3072 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
3827 srrctl |= IGB_RXBUFFER_2048 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
3828 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
3829 if (hw->mac.type >= e1000_82580)
3830 srrctl |= E1000_SRRCTL_TIMESTAMP;
3831 /* Only set Drop Enable if we are supporting multiple queues */
3832 if (adapter->vfs_allocated_count || adapter->num_rx_queues > 1)
3833 srrctl |= E1000_SRRCTL_DROP_EN;
3835 wr32(E1000_SRRCTL(reg_idx), srrctl);
3837 /* set filtering for VMDQ pools */
3838 igb_set_vmolr(adapter, reg_idx & 0x7, true);
3840 rxdctl |= IGB_RX_PTHRESH;
3841 rxdctl |= IGB_RX_HTHRESH << 8;
3842 rxdctl |= IGB_RX_WTHRESH << 16;
3844 /* initialize rx_buffer_info */
3845 memset(ring->rx_buffer_info, 0,
3846 sizeof(struct igb_rx_buffer) * ring->count);
3848 /* initialize Rx descriptor 0 */
3849 rx_desc = IGB_RX_DESC(ring, 0);
3850 rx_desc->wb.upper.length = 0;
3852 /* enable receive descriptor fetching */
3853 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
3854 wr32(E1000_RXDCTL(reg_idx), rxdctl);
3857 static void igb_set_rx_buffer_len(struct igb_adapter *adapter,
3858 struct igb_ring *rx_ring)
3860 #if (PAGE_SIZE < 8192)
3861 struct e1000_hw *hw = &adapter->hw;
3864 /* set build_skb and buffer size flags */
3865 clear_ring_build_skb_enabled(rx_ring);
3866 clear_ring_uses_large_buffer(rx_ring);
3868 if (adapter->flags & IGB_FLAG_RX_LEGACY)
3871 set_ring_build_skb_enabled(rx_ring);
3873 #if (PAGE_SIZE < 8192)
3874 if (adapter->max_frame_size > IGB_MAX_FRAME_BUILD_SKB ||
3875 rd32(E1000_RCTL) & E1000_RCTL_SBP)
3876 set_ring_uses_large_buffer(rx_ring);
3881 * igb_configure_rx - Configure receive Unit after Reset
3882 * @adapter: board private structure
3884 * Configure the Rx unit of the MAC after a reset.
3886 static void igb_configure_rx(struct igb_adapter *adapter)
3890 /* set the correct pool for the PF default MAC address in entry 0 */
3891 igb_set_default_mac_filter(adapter);
3893 /* Setup the HW Rx Head and Tail Descriptor Pointers and
3894 * the Base and Length of the Rx Descriptor Ring
3896 for (i = 0; i < adapter->num_rx_queues; i++) {
3897 struct igb_ring *rx_ring = adapter->rx_ring[i];
3899 igb_set_rx_buffer_len(adapter, rx_ring);
3900 igb_configure_rx_ring(adapter, rx_ring);
3905 * igb_free_tx_resources - Free Tx Resources per Queue
3906 * @tx_ring: Tx descriptor ring for a specific queue
3908 * Free all transmit software resources
3910 void igb_free_tx_resources(struct igb_ring *tx_ring)
3912 igb_clean_tx_ring(tx_ring);
3914 vfree(tx_ring->tx_buffer_info);
3915 tx_ring->tx_buffer_info = NULL;
3917 /* if not set, then don't free */
3921 dma_free_coherent(tx_ring->dev, tx_ring->size,
3922 tx_ring->desc, tx_ring->dma);
3924 tx_ring->desc = NULL;
3928 * igb_free_all_tx_resources - Free Tx Resources for All Queues
3929 * @adapter: board private structure
3931 * Free all transmit software resources
3933 static void igb_free_all_tx_resources(struct igb_adapter *adapter)
3937 for (i = 0; i < adapter->num_tx_queues; i++)
3938 if (adapter->tx_ring[i])
3939 igb_free_tx_resources(adapter->tx_ring[i]);
3943 * igb_clean_tx_ring - Free Tx Buffers
3944 * @tx_ring: ring to be cleaned
3946 static void igb_clean_tx_ring(struct igb_ring *tx_ring)
3948 u16 i = tx_ring->next_to_clean;
3949 struct igb_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
3951 while (i != tx_ring->next_to_use) {
3952 union e1000_adv_tx_desc *eop_desc, *tx_desc;
3954 /* Free all the Tx ring sk_buffs */
3955 dev_kfree_skb_any(tx_buffer->skb);
3957 /* unmap skb header data */
3958 dma_unmap_single(tx_ring->dev,
3959 dma_unmap_addr(tx_buffer, dma),
3960 dma_unmap_len(tx_buffer, len),
3963 /* check for eop_desc to determine the end of the packet */
3964 eop_desc = tx_buffer->next_to_watch;
3965 tx_desc = IGB_TX_DESC(tx_ring, i);
3967 /* unmap remaining buffers */
3968 while (tx_desc != eop_desc) {
3972 if (unlikely(i == tx_ring->count)) {
3974 tx_buffer = tx_ring->tx_buffer_info;
3975 tx_desc = IGB_TX_DESC(tx_ring, 0);
3978 /* unmap any remaining paged data */
3979 if (dma_unmap_len(tx_buffer, len))
3980 dma_unmap_page(tx_ring->dev,
3981 dma_unmap_addr(tx_buffer, dma),
3982 dma_unmap_len(tx_buffer, len),
3986 tx_buffer->next_to_watch = NULL;
3988 /* move us one more past the eop_desc for start of next pkt */
3991 if (unlikely(i == tx_ring->count)) {
3993 tx_buffer = tx_ring->tx_buffer_info;
3997 /* reset BQL for queue */
3998 netdev_tx_reset_queue(txring_txq(tx_ring));
4000 /* reset next_to_use and next_to_clean */
4001 tx_ring->next_to_use = 0;
4002 tx_ring->next_to_clean = 0;
4006 * igb_clean_all_tx_rings - Free Tx Buffers for all queues
4007 * @adapter: board private structure
4009 static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
4013 for (i = 0; i < adapter->num_tx_queues; i++)
4014 if (adapter->tx_ring[i])
4015 igb_clean_tx_ring(adapter->tx_ring[i]);
4019 * igb_free_rx_resources - Free Rx Resources
4020 * @rx_ring: ring to clean the resources from
4022 * Free all receive software resources
4024 void igb_free_rx_resources(struct igb_ring *rx_ring)
4026 igb_clean_rx_ring(rx_ring);
4028 vfree(rx_ring->rx_buffer_info);
4029 rx_ring->rx_buffer_info = NULL;
4031 /* if not set, then don't free */
4035 dma_free_coherent(rx_ring->dev, rx_ring->size,
4036 rx_ring->desc, rx_ring->dma);
4038 rx_ring->desc = NULL;
4042 * igb_free_all_rx_resources - Free Rx Resources for All Queues
4043 * @adapter: board private structure
4045 * Free all receive software resources
4047 static void igb_free_all_rx_resources(struct igb_adapter *adapter)
4051 for (i = 0; i < adapter->num_rx_queues; i++)
4052 if (adapter->rx_ring[i])
4053 igb_free_rx_resources(adapter->rx_ring[i]);
4057 * igb_clean_rx_ring - Free Rx Buffers per Queue
4058 * @rx_ring: ring to free buffers from
4060 static void igb_clean_rx_ring(struct igb_ring *rx_ring)
4062 u16 i = rx_ring->next_to_clean;
4065 dev_kfree_skb(rx_ring->skb);
4066 rx_ring->skb = NULL;
4068 /* Free all the Rx ring sk_buffs */
4069 while (i != rx_ring->next_to_alloc) {
4070 struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];
4072 /* Invalidate cache lines that may have been written to by
4073 * device so that we avoid corrupting memory.
4075 dma_sync_single_range_for_cpu(rx_ring->dev,
4077 buffer_info->page_offset,
4078 igb_rx_bufsz(rx_ring),
4081 /* free resources associated with mapping */
4082 dma_unmap_page_attrs(rx_ring->dev,
4084 igb_rx_pg_size(rx_ring),
4087 __page_frag_cache_drain(buffer_info->page,
4088 buffer_info->pagecnt_bias);
4091 if (i == rx_ring->count)
4095 rx_ring->next_to_alloc = 0;
4096 rx_ring->next_to_clean = 0;
4097 rx_ring->next_to_use = 0;
4101 * igb_clean_all_rx_rings - Free Rx Buffers for all queues
4102 * @adapter: board private structure
4104 static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
4108 for (i = 0; i < adapter->num_rx_queues; i++)
4109 if (adapter->rx_ring[i])
4110 igb_clean_rx_ring(adapter->rx_ring[i]);
4114 * igb_set_mac - Change the Ethernet Address of the NIC
4115 * @netdev: network interface device structure
4116 * @p: pointer to an address structure
4118 * Returns 0 on success, negative on failure
4120 static int igb_set_mac(struct net_device *netdev, void *p)
4122 struct igb_adapter *adapter = netdev_priv(netdev);
4123 struct e1000_hw *hw = &adapter->hw;
4124 struct sockaddr *addr = p;
4126 if (!is_valid_ether_addr(addr->sa_data))
4127 return -EADDRNOTAVAIL;
4129 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
4130 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
4132 /* set the correct pool for the new PF MAC address in entry 0 */
4133 igb_set_default_mac_filter(adapter);
4139 * igb_write_mc_addr_list - write multicast addresses to MTA
4140 * @netdev: network interface device structure
4142 * Writes multicast address list to the MTA hash table.
4143 * Returns: -ENOMEM on failure
4144 * 0 on no addresses written
4145 * X on writing X addresses to MTA
4147 static int igb_write_mc_addr_list(struct net_device *netdev)
4149 struct igb_adapter *adapter = netdev_priv(netdev);
4150 struct e1000_hw *hw = &adapter->hw;
4151 struct netdev_hw_addr *ha;
4155 if (netdev_mc_empty(netdev)) {
4156 /* nothing to program, so clear mc list */
4157 igb_update_mc_addr_list(hw, NULL, 0);
4158 igb_restore_vf_multicasts(adapter);
4162 mta_list = kzalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
4166 /* The shared function expects a packed array of only addresses. */
4168 netdev_for_each_mc_addr(ha, netdev)
4169 memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
4171 igb_update_mc_addr_list(hw, mta_list, i);
4174 return netdev_mc_count(netdev);
4177 static int igb_vlan_promisc_enable(struct igb_adapter *adapter)
4179 struct e1000_hw *hw = &adapter->hw;
4182 switch (hw->mac.type) {
4186 /* VLAN filtering needed for VLAN prio filter */
4187 if (adapter->netdev->features & NETIF_F_NTUPLE)
4193 /* VLAN filtering needed for pool filtering */
4194 if (adapter->vfs_allocated_count)
4201 /* We are already in VLAN promisc, nothing to do */
4202 if (adapter->flags & IGB_FLAG_VLAN_PROMISC)
4205 if (!adapter->vfs_allocated_count)
4208 /* Add PF to all active pools */
4209 pf_id = adapter->vfs_allocated_count + E1000_VLVF_POOLSEL_SHIFT;
4211 for (i = E1000_VLVF_ARRAY_SIZE; --i;) {
4212 u32 vlvf = rd32(E1000_VLVF(i));
4215 wr32(E1000_VLVF(i), vlvf);
4219 /* Set all bits in the VLAN filter table array */
4220 for (i = E1000_VLAN_FILTER_TBL_SIZE; i--;)
4221 hw->mac.ops.write_vfta(hw, i, ~0U);
4223 /* Set flag so we don't redo unnecessary work */
4224 adapter->flags |= IGB_FLAG_VLAN_PROMISC;
4229 #define VFTA_BLOCK_SIZE 8
4230 static void igb_scrub_vfta(struct igb_adapter *adapter, u32 vfta_offset)
4232 struct e1000_hw *hw = &adapter->hw;
4233 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4234 u32 vid_start = vfta_offset * 32;
4235 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4236 u32 i, vid, word, bits, pf_id;
4238 /* guarantee that we don't scrub out management VLAN */
4239 vid = adapter->mng_vlan_id;
4240 if (vid >= vid_start && vid < vid_end)
4241 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
4243 if (!adapter->vfs_allocated_count)
4246 pf_id = adapter->vfs_allocated_count + E1000_VLVF_POOLSEL_SHIFT;
4248 for (i = E1000_VLVF_ARRAY_SIZE; --i;) {
4249 u32 vlvf = rd32(E1000_VLVF(i));
4251 /* pull VLAN ID from VLVF */
4252 vid = vlvf & VLAN_VID_MASK;
4254 /* only concern ourselves with a certain range */
4255 if (vid < vid_start || vid >= vid_end)
4258 if (vlvf & E1000_VLVF_VLANID_ENABLE) {
4259 /* record VLAN ID in VFTA */
4260 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
4262 /* if PF is part of this then continue */
4263 if (test_bit(vid, adapter->active_vlans))
4267 /* remove PF from the pool */
4269 bits &= rd32(E1000_VLVF(i));
4270 wr32(E1000_VLVF(i), bits);
4274 /* extract values from active_vlans and write back to VFTA */
4275 for (i = VFTA_BLOCK_SIZE; i--;) {
4276 vid = (vfta_offset + i) * 32;
4277 word = vid / BITS_PER_LONG;
4278 bits = vid % BITS_PER_LONG;
4280 vfta[i] |= adapter->active_vlans[word] >> bits;
4282 hw->mac.ops.write_vfta(hw, vfta_offset + i, vfta[i]);
4286 static void igb_vlan_promisc_disable(struct igb_adapter *adapter)
4290 /* We are not in VLAN promisc, nothing to do */
4291 if (!(adapter->flags & IGB_FLAG_VLAN_PROMISC))
4294 /* Set flag so we don't redo unnecessary work */
4295 adapter->flags &= ~IGB_FLAG_VLAN_PROMISC;
4297 for (i = 0; i < E1000_VLAN_FILTER_TBL_SIZE; i += VFTA_BLOCK_SIZE)
4298 igb_scrub_vfta(adapter, i);
4302 * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
4303 * @netdev: network interface device structure
4305 * The set_rx_mode entry point is called whenever the unicast or multicast
4306 * address lists or the network interface flags are updated. This routine is
4307 * responsible for configuring the hardware for proper unicast, multicast,
4308 * promiscuous mode, and all-multi behavior.
4310 static void igb_set_rx_mode(struct net_device *netdev)
4312 struct igb_adapter *adapter = netdev_priv(netdev);
4313 struct e1000_hw *hw = &adapter->hw;
4314 unsigned int vfn = adapter->vfs_allocated_count;
4315 u32 rctl = 0, vmolr = 0, rlpml = MAX_JUMBO_FRAME_SIZE;
4318 /* Check for Promiscuous and All Multicast modes */
4319 if (netdev->flags & IFF_PROMISC) {
4320 rctl |= E1000_RCTL_UPE | E1000_RCTL_MPE;
4321 vmolr |= E1000_VMOLR_MPME;
4323 /* enable use of UTA filter to force packets to default pool */
4324 if (hw->mac.type == e1000_82576)
4325 vmolr |= E1000_VMOLR_ROPE;
4327 if (netdev->flags & IFF_ALLMULTI) {
4328 rctl |= E1000_RCTL_MPE;
4329 vmolr |= E1000_VMOLR_MPME;
4331 /* Write addresses to the MTA, if the attempt fails
4332 * then we should just turn on promiscuous mode so
4333 * that we can at least receive multicast traffic
4335 count = igb_write_mc_addr_list(netdev);
4337 rctl |= E1000_RCTL_MPE;
4338 vmolr |= E1000_VMOLR_MPME;
4340 vmolr |= E1000_VMOLR_ROMPE;
4345 /* Write addresses to available RAR registers, if there is not
4346 * sufficient space to store all the addresses then enable
4347 * unicast promiscuous mode
4349 if (__dev_uc_sync(netdev, igb_uc_sync, igb_uc_unsync)) {
4350 rctl |= E1000_RCTL_UPE;
4351 vmolr |= E1000_VMOLR_ROPE;
4354 /* enable VLAN filtering by default */
4355 rctl |= E1000_RCTL_VFE;
4357 /* disable VLAN filtering for modes that require it */
4358 if ((netdev->flags & IFF_PROMISC) ||
4359 (netdev->features & NETIF_F_RXALL)) {
4360 /* if we fail to set all rules then just clear VFE */
4361 if (igb_vlan_promisc_enable(adapter))
4362 rctl &= ~E1000_RCTL_VFE;
4364 igb_vlan_promisc_disable(adapter);
4367 /* update state of unicast, multicast, and VLAN filtering modes */
4368 rctl |= rd32(E1000_RCTL) & ~(E1000_RCTL_UPE | E1000_RCTL_MPE |
4370 wr32(E1000_RCTL, rctl);
4372 #if (PAGE_SIZE < 8192)
4373 if (!adapter->vfs_allocated_count) {
4374 if (adapter->max_frame_size <= IGB_MAX_FRAME_BUILD_SKB)
4375 rlpml = IGB_MAX_FRAME_BUILD_SKB;
4378 wr32(E1000_RLPML, rlpml);
4380 /* In order to support SR-IOV and eventually VMDq it is necessary to set
4381 * the VMOLR to enable the appropriate modes. Without this workaround
4382 * we will have issues with VLAN tag stripping not being done for frames
4383 * that are only arriving because we are the default pool
4385 if ((hw->mac.type < e1000_82576) || (hw->mac.type > e1000_i350))
4388 /* set UTA to appropriate mode */
4389 igb_set_uta(adapter, !!(vmolr & E1000_VMOLR_ROPE));
4391 vmolr |= rd32(E1000_VMOLR(vfn)) &
4392 ~(E1000_VMOLR_ROPE | E1000_VMOLR_MPME | E1000_VMOLR_ROMPE);
4394 /* enable Rx jumbo frames, restrict as needed to support build_skb */
4395 vmolr &= ~E1000_VMOLR_RLPML_MASK;
4396 #if (PAGE_SIZE < 8192)
4397 if (adapter->max_frame_size <= IGB_MAX_FRAME_BUILD_SKB)
4398 vmolr |= IGB_MAX_FRAME_BUILD_SKB;
4401 vmolr |= MAX_JUMBO_FRAME_SIZE;
4402 vmolr |= E1000_VMOLR_LPE;
4404 wr32(E1000_VMOLR(vfn), vmolr);
4406 igb_restore_vf_multicasts(adapter);
4409 static void igb_check_wvbr(struct igb_adapter *adapter)
4411 struct e1000_hw *hw = &adapter->hw;
4414 switch (hw->mac.type) {
4417 wvbr = rd32(E1000_WVBR);
4425 adapter->wvbr |= wvbr;
4428 #define IGB_STAGGERED_QUEUE_OFFSET 8
4430 static void igb_spoof_check(struct igb_adapter *adapter)
4437 for (j = 0; j < adapter->vfs_allocated_count; j++) {
4438 if (adapter->wvbr & BIT(j) ||
4439 adapter->wvbr & BIT(j + IGB_STAGGERED_QUEUE_OFFSET)) {
4440 dev_warn(&adapter->pdev->dev,
4441 "Spoof event(s) detected on VF %d\n", j);
4444 BIT(j + IGB_STAGGERED_QUEUE_OFFSET));
4449 /* Need to wait a few seconds after link up to get diagnostic information from
4452 static void igb_update_phy_info(unsigned long data)
4454 struct igb_adapter *adapter = (struct igb_adapter *) data;
4455 igb_get_phy_info(&adapter->hw);
4459 * igb_has_link - check shared code for link and determine up/down
4460 * @adapter: pointer to driver private info
4462 bool igb_has_link(struct igb_adapter *adapter)
4464 struct e1000_hw *hw = &adapter->hw;
4465 bool link_active = false;
4467 /* get_link_status is set on LSC (link status) interrupt or
4468 * rx sequence error interrupt. get_link_status will stay
4469 * false until the e1000_check_for_link establishes link
4470 * for copper adapters ONLY
4472 switch (hw->phy.media_type) {
4473 case e1000_media_type_copper:
4474 if (!hw->mac.get_link_status)
4476 case e1000_media_type_internal_serdes:
4477 hw->mac.ops.check_for_link(hw);
4478 link_active = !hw->mac.get_link_status;
4481 case e1000_media_type_unknown:
4485 if (((hw->mac.type == e1000_i210) ||
4486 (hw->mac.type == e1000_i211)) &&
4487 (hw->phy.id == I210_I_PHY_ID)) {
4488 if (!netif_carrier_ok(adapter->netdev)) {
4489 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
4490 } else if (!(adapter->flags & IGB_FLAG_NEED_LINK_UPDATE)) {
4491 adapter->flags |= IGB_FLAG_NEED_LINK_UPDATE;
4492 adapter->link_check_timeout = jiffies;
4499 static bool igb_thermal_sensor_event(struct e1000_hw *hw, u32 event)
4502 u32 ctrl_ext, thstat;
4504 /* check for thermal sensor event on i350 copper only */
4505 if (hw->mac.type == e1000_i350) {
4506 thstat = rd32(E1000_THSTAT);
4507 ctrl_ext = rd32(E1000_CTRL_EXT);
4509 if ((hw->phy.media_type == e1000_media_type_copper) &&
4510 !(ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII))
4511 ret = !!(thstat & event);
4518 * igb_check_lvmmc - check for malformed packets received
4519 * and indicated in LVMMC register
4520 * @adapter: pointer to adapter
4522 static void igb_check_lvmmc(struct igb_adapter *adapter)
4524 struct e1000_hw *hw = &adapter->hw;
4527 lvmmc = rd32(E1000_LVMMC);
4529 if (unlikely(net_ratelimit())) {
4530 netdev_warn(adapter->netdev,
4531 "malformed Tx packet detected and dropped, LVMMC:0x%08x\n",
4538 * igb_watchdog - Timer Call-back
4539 * @data: pointer to adapter cast into an unsigned long
4541 static void igb_watchdog(unsigned long data)
4543 struct igb_adapter *adapter = (struct igb_adapter *)data;
4544 /* Do the rest outside of interrupt context */
4545 schedule_work(&adapter->watchdog_task);
4548 static void igb_watchdog_task(struct work_struct *work)
4550 struct igb_adapter *adapter = container_of(work,
4553 struct e1000_hw *hw = &adapter->hw;
4554 struct e1000_phy_info *phy = &hw->phy;
4555 struct net_device *netdev = adapter->netdev;
4559 u16 phy_data, retry_count = 20;
4561 link = igb_has_link(adapter);
4563 if (adapter->flags & IGB_FLAG_NEED_LINK_UPDATE) {
4564 if (time_after(jiffies, (adapter->link_check_timeout + HZ)))
4565 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
4570 /* Force link down if we have fiber to swap to */
4571 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
4572 if (hw->phy.media_type == e1000_media_type_copper) {
4573 connsw = rd32(E1000_CONNSW);
4574 if (!(connsw & E1000_CONNSW_AUTOSENSE_EN))
4579 /* Perform a reset if the media type changed. */
4580 if (hw->dev_spec._82575.media_changed) {
4581 hw->dev_spec._82575.media_changed = false;
4582 adapter->flags |= IGB_FLAG_MEDIA_RESET;
4585 /* Cancel scheduled suspend requests. */
4586 pm_runtime_resume(netdev->dev.parent);
4588 if (!netif_carrier_ok(netdev)) {
4591 hw->mac.ops.get_speed_and_duplex(hw,
4592 &adapter->link_speed,
4593 &adapter->link_duplex);
4595 ctrl = rd32(E1000_CTRL);
4596 /* Links status message must follow this format */
4598 "igb: %s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
4600 adapter->link_speed,
4601 adapter->link_duplex == FULL_DUPLEX ?
4603 (ctrl & E1000_CTRL_TFCE) &&
4604 (ctrl & E1000_CTRL_RFCE) ? "RX/TX" :
4605 (ctrl & E1000_CTRL_RFCE) ? "RX" :
4606 (ctrl & E1000_CTRL_TFCE) ? "TX" : "None");
4608 /* disable EEE if enabled */
4609 if ((adapter->flags & IGB_FLAG_EEE) &&
4610 (adapter->link_duplex == HALF_DUPLEX)) {
4611 dev_info(&adapter->pdev->dev,
4612 "EEE Disabled: unsupported at half duplex. Re-enable using ethtool when at full duplex.\n");
4613 adapter->hw.dev_spec._82575.eee_disable = true;
4614 adapter->flags &= ~IGB_FLAG_EEE;
4617 /* check if SmartSpeed worked */
4618 igb_check_downshift(hw);
4619 if (phy->speed_downgraded)
4620 netdev_warn(netdev, "Link Speed was downgraded by SmartSpeed\n");
4622 /* check for thermal sensor event */
4623 if (igb_thermal_sensor_event(hw,
4624 E1000_THSTAT_LINK_THROTTLE))
4625 netdev_info(netdev, "The network adapter link speed was downshifted because it overheated\n");
4627 /* adjust timeout factor according to speed/duplex */
4628 adapter->tx_timeout_factor = 1;
4629 switch (adapter->link_speed) {
4631 adapter->tx_timeout_factor = 14;
4634 /* maybe add some timeout factor ? */
4638 if (adapter->link_speed != SPEED_1000 ||
4639 !hw->phy.ops.read_reg)
4642 /* wait for Remote receiver status OK */
4644 if (!igb_read_phy_reg(hw, PHY_1000T_STATUS,
4646 if (!(phy_data & SR_1000T_REMOTE_RX_STATUS) &&
4650 goto retry_read_status;
4651 } else if (!retry_count) {
4652 dev_err(&adapter->pdev->dev, "exceed max 2 second\n");
4655 dev_err(&adapter->pdev->dev, "read 1000Base-T Status Reg\n");
4658 netif_carrier_on(netdev);
4660 igb_ping_all_vfs(adapter);
4661 igb_check_vf_rate_limit(adapter);
4663 /* link state has changed, schedule phy info update */
4664 if (!test_bit(__IGB_DOWN, &adapter->state))
4665 mod_timer(&adapter->phy_info_timer,
4666 round_jiffies(jiffies + 2 * HZ));
4669 if (netif_carrier_ok(netdev)) {
4670 adapter->link_speed = 0;
4671 adapter->link_duplex = 0;
4673 /* check for thermal sensor event */
4674 if (igb_thermal_sensor_event(hw,
4675 E1000_THSTAT_PWR_DOWN)) {
4676 netdev_err(netdev, "The network adapter was stopped because it overheated\n");
4679 /* Links status message must follow this format */
4680 netdev_info(netdev, "igb: %s NIC Link is Down\n",
4682 netif_carrier_off(netdev);
4684 igb_ping_all_vfs(adapter);
4686 /* link state has changed, schedule phy info update */
4687 if (!test_bit(__IGB_DOWN, &adapter->state))
4688 mod_timer(&adapter->phy_info_timer,
4689 round_jiffies(jiffies + 2 * HZ));
4691 /* link is down, time to check for alternate media */
4692 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
4693 igb_check_swap_media(adapter);
4694 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
4695 schedule_work(&adapter->reset_task);
4696 /* return immediately */
4700 pm_schedule_suspend(netdev->dev.parent,
4703 /* also check for alternate media here */
4704 } else if (!netif_carrier_ok(netdev) &&
4705 (adapter->flags & IGB_FLAG_MAS_ENABLE)) {
4706 igb_check_swap_media(adapter);
4707 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
4708 schedule_work(&adapter->reset_task);
4709 /* return immediately */
4715 spin_lock(&adapter->stats64_lock);
4716 igb_update_stats(adapter);
4717 spin_unlock(&adapter->stats64_lock);
4719 for (i = 0; i < adapter->num_tx_queues; i++) {
4720 struct igb_ring *tx_ring = adapter->tx_ring[i];
4721 if (!netif_carrier_ok(netdev)) {
4722 /* We've lost link, so the controller stops DMA,
4723 * but we've got queued Tx work that's never going
4724 * to get done, so reset controller to flush Tx.
4725 * (Do the reset outside of interrupt context).
4727 if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) {
4728 adapter->tx_timeout_count++;
4729 schedule_work(&adapter->reset_task);
4730 /* return immediately since reset is imminent */
4735 /* Force detection of hung controller every watchdog period */
4736 set_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
4739 /* Cause software interrupt to ensure Rx ring is cleaned */
4740 if (adapter->flags & IGB_FLAG_HAS_MSIX) {
4743 for (i = 0; i < adapter->num_q_vectors; i++)
4744 eics |= adapter->q_vector[i]->eims_value;
4745 wr32(E1000_EICS, eics);
4747 wr32(E1000_ICS, E1000_ICS_RXDMT0);
4750 igb_spoof_check(adapter);
4751 igb_ptp_rx_hang(adapter);
4752 igb_ptp_tx_hang(adapter);
4754 /* Check LVMMC register on i350/i354 only */
4755 if ((adapter->hw.mac.type == e1000_i350) ||
4756 (adapter->hw.mac.type == e1000_i354))
4757 igb_check_lvmmc(adapter);
4759 /* Reset the timer */
4760 if (!test_bit(__IGB_DOWN, &adapter->state)) {
4761 if (adapter->flags & IGB_FLAG_NEED_LINK_UPDATE)
4762 mod_timer(&adapter->watchdog_timer,
4763 round_jiffies(jiffies + HZ));
4765 mod_timer(&adapter->watchdog_timer,
4766 round_jiffies(jiffies + 2 * HZ));
4770 enum latency_range {
4774 latency_invalid = 255
4778 * igb_update_ring_itr - update the dynamic ITR value based on packet size
4779 * @q_vector: pointer to q_vector
4781 * Stores a new ITR value based on strictly on packet size. This
4782 * algorithm is less sophisticated than that used in igb_update_itr,
4783 * due to the difficulty of synchronizing statistics across multiple
4784 * receive rings. The divisors and thresholds used by this function
4785 * were determined based on theoretical maximum wire speed and testing
4786 * data, in order to minimize response time while increasing bulk
4788 * This functionality is controlled by ethtool's coalescing settings.
4789 * NOTE: This function is called only when operating in a multiqueue
4790 * receive environment.
4792 static void igb_update_ring_itr(struct igb_q_vector *q_vector)
4794 int new_val = q_vector->itr_val;
4795 int avg_wire_size = 0;
4796 struct igb_adapter *adapter = q_vector->adapter;
4797 unsigned int packets;
4799 /* For non-gigabit speeds, just fix the interrupt rate at 4000
4800 * ints/sec - ITR timer value of 120 ticks.
4802 if (adapter->link_speed != SPEED_1000) {
4803 new_val = IGB_4K_ITR;
4807 packets = q_vector->rx.total_packets;
4809 avg_wire_size = q_vector->rx.total_bytes / packets;
4811 packets = q_vector->tx.total_packets;
4813 avg_wire_size = max_t(u32, avg_wire_size,
4814 q_vector->tx.total_bytes / packets);
4816 /* if avg_wire_size isn't set no work was done */
4820 /* Add 24 bytes to size to account for CRC, preamble, and gap */
4821 avg_wire_size += 24;
4823 /* Don't starve jumbo frames */
4824 avg_wire_size = min(avg_wire_size, 3000);
4826 /* Give a little boost to mid-size frames */
4827 if ((avg_wire_size > 300) && (avg_wire_size < 1200))
4828 new_val = avg_wire_size / 3;
4830 new_val = avg_wire_size / 2;
4832 /* conservative mode (itr 3) eliminates the lowest_latency setting */
4833 if (new_val < IGB_20K_ITR &&
4834 ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
4835 (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
4836 new_val = IGB_20K_ITR;
4839 if (new_val != q_vector->itr_val) {
4840 q_vector->itr_val = new_val;
4841 q_vector->set_itr = 1;
4844 q_vector->rx.total_bytes = 0;
4845 q_vector->rx.total_packets = 0;
4846 q_vector->tx.total_bytes = 0;
4847 q_vector->tx.total_packets = 0;
4851 * igb_update_itr - update the dynamic ITR value based on statistics
4852 * @q_vector: pointer to q_vector
4853 * @ring_container: ring info to update the itr for
4855 * Stores a new ITR value based on packets and byte
4856 * counts during the last interrupt. The advantage of per interrupt
4857 * computation is faster updates and more accurate ITR for the current
4858 * traffic pattern. Constants in this function were computed
4859 * based on theoretical maximum wire speed and thresholds were set based
4860 * on testing data as well as attempting to minimize response time
4861 * while increasing bulk throughput.
4862 * This functionality is controlled by ethtool's coalescing settings.
4863 * NOTE: These calculations are only valid when operating in a single-
4864 * queue environment.
4866 static void igb_update_itr(struct igb_q_vector *q_vector,
4867 struct igb_ring_container *ring_container)
4869 unsigned int packets = ring_container->total_packets;
4870 unsigned int bytes = ring_container->total_bytes;
4871 u8 itrval = ring_container->itr;
4873 /* no packets, exit with status unchanged */
4878 case lowest_latency:
4879 /* handle TSO and jumbo frames */
4880 if (bytes/packets > 8000)
4881 itrval = bulk_latency;
4882 else if ((packets < 5) && (bytes > 512))
4883 itrval = low_latency;
4885 case low_latency: /* 50 usec aka 20000 ints/s */
4886 if (bytes > 10000) {
4887 /* this if handles the TSO accounting */
4888 if (bytes/packets > 8000)
4889 itrval = bulk_latency;
4890 else if ((packets < 10) || ((bytes/packets) > 1200))
4891 itrval = bulk_latency;
4892 else if ((packets > 35))
4893 itrval = lowest_latency;
4894 } else if (bytes/packets > 2000) {
4895 itrval = bulk_latency;
4896 } else if (packets <= 2 && bytes < 512) {
4897 itrval = lowest_latency;
4900 case bulk_latency: /* 250 usec aka 4000 ints/s */
4901 if (bytes > 25000) {
4903 itrval = low_latency;
4904 } else if (bytes < 1500) {
4905 itrval = low_latency;
4910 /* clear work counters since we have the values we need */
4911 ring_container->total_bytes = 0;
4912 ring_container->total_packets = 0;
4914 /* write updated itr to ring container */
4915 ring_container->itr = itrval;
4918 static void igb_set_itr(struct igb_q_vector *q_vector)
4920 struct igb_adapter *adapter = q_vector->adapter;
4921 u32 new_itr = q_vector->itr_val;
4924 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
4925 if (adapter->link_speed != SPEED_1000) {
4927 new_itr = IGB_4K_ITR;
4931 igb_update_itr(q_vector, &q_vector->tx);
4932 igb_update_itr(q_vector, &q_vector->rx);
4934 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
4936 /* conservative mode (itr 3) eliminates the lowest_latency setting */
4937 if (current_itr == lowest_latency &&
4938 ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
4939 (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
4940 current_itr = low_latency;
4942 switch (current_itr) {
4943 /* counts and packets in update_itr are dependent on these numbers */
4944 case lowest_latency:
4945 new_itr = IGB_70K_ITR; /* 70,000 ints/sec */
4948 new_itr = IGB_20K_ITR; /* 20,000 ints/sec */
4951 new_itr = IGB_4K_ITR; /* 4,000 ints/sec */
4958 if (new_itr != q_vector->itr_val) {
4959 /* this attempts to bias the interrupt rate towards Bulk
4960 * by adding intermediate steps when interrupt rate is
4963 new_itr = new_itr > q_vector->itr_val ?
4964 max((new_itr * q_vector->itr_val) /
4965 (new_itr + (q_vector->itr_val >> 2)),
4967 /* Don't write the value here; it resets the adapter's
4968 * internal timer, and causes us to delay far longer than
4969 * we should between interrupts. Instead, we write the ITR
4970 * value at the beginning of the next interrupt so the timing
4971 * ends up being correct.
4973 q_vector->itr_val = new_itr;
4974 q_vector->set_itr = 1;
4978 static void igb_tx_ctxtdesc(struct igb_ring *tx_ring, u32 vlan_macip_lens,
4979 u32 type_tucmd, u32 mss_l4len_idx)
4981 struct e1000_adv_tx_context_desc *context_desc;
4982 u16 i = tx_ring->next_to_use;
4984 context_desc = IGB_TX_CTXTDESC(tx_ring, i);
4987 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
4989 /* set bits to identify this as an advanced context descriptor */
4990 type_tucmd |= E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
4992 /* For 82575, context index must be unique per ring. */
4993 if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
4994 mss_l4len_idx |= tx_ring->reg_idx << 4;
4996 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4997 context_desc->seqnum_seed = 0;
4998 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
4999 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
5002 static int igb_tso(struct igb_ring *tx_ring,
5003 struct igb_tx_buffer *first,
5006 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
5007 struct sk_buff *skb = first->skb;
5017 u32 paylen, l4_offset;
5020 if (skb->ip_summed != CHECKSUM_PARTIAL)
5023 if (!skb_is_gso(skb))
5026 err = skb_cow_head(skb, 0);
5030 ip.hdr = skb_network_header(skb);
5031 l4.hdr = skb_checksum_start(skb);
5033 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5034 type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
5036 /* initialize outer IP header fields */
5037 if (ip.v4->version == 4) {
5038 unsigned char *csum_start = skb_checksum_start(skb);
5039 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
5041 /* IP header will have to cancel out any data that
5042 * is not a part of the outer IP header
5044 ip.v4->check = csum_fold(csum_partial(trans_start,
5045 csum_start - trans_start,
5047 type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
5050 first->tx_flags |= IGB_TX_FLAGS_TSO |
5054 ip.v6->payload_len = 0;
5055 first->tx_flags |= IGB_TX_FLAGS_TSO |
5059 /* determine offset of inner transport header */
5060 l4_offset = l4.hdr - skb->data;
5062 /* compute length of segmentation header */
5063 *hdr_len = (l4.tcp->doff * 4) + l4_offset;
5065 /* remove payload length from inner checksum */
5066 paylen = skb->len - l4_offset;
5067 csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
5069 /* update gso size and bytecount with header size */
5070 first->gso_segs = skb_shinfo(skb)->gso_segs;
5071 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5074 mss_l4len_idx = (*hdr_len - l4_offset) << E1000_ADVTXD_L4LEN_SHIFT;
5075 mss_l4len_idx |= skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT;
5077 /* VLAN MACLEN IPLEN */
5078 vlan_macip_lens = l4.hdr - ip.hdr;
5079 vlan_macip_lens |= (ip.hdr - skb->data) << E1000_ADVTXD_MACLEN_SHIFT;
5080 vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
5082 igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
5087 static inline bool igb_ipv6_csum_is_sctp(struct sk_buff *skb)
5089 unsigned int offset = 0;
5091 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
5093 return offset == skb_checksum_start_offset(skb);
5096 static void igb_tx_csum(struct igb_ring *tx_ring, struct igb_tx_buffer *first)
5098 struct sk_buff *skb = first->skb;
5099 u32 vlan_macip_lens = 0;
5102 if (skb->ip_summed != CHECKSUM_PARTIAL) {
5104 if (!(first->tx_flags & IGB_TX_FLAGS_VLAN))
5109 switch (skb->csum_offset) {
5110 case offsetof(struct tcphdr, check):
5111 type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
5113 case offsetof(struct udphdr, check):
5115 case offsetof(struct sctphdr, checksum):
5116 /* validate that this is actually an SCTP request */
5117 if (((first->protocol == htons(ETH_P_IP)) &&
5118 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
5119 ((first->protocol == htons(ETH_P_IPV6)) &&
5120 igb_ipv6_csum_is_sctp(skb))) {
5121 type_tucmd = E1000_ADVTXD_TUCMD_L4T_SCTP;
5125 skb_checksum_help(skb);
5129 /* update TX checksum flag */
5130 first->tx_flags |= IGB_TX_FLAGS_CSUM;
5131 vlan_macip_lens = skb_checksum_start_offset(skb) -
5132 skb_network_offset(skb);
5134 vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
5135 vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
5137 igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, 0);
5140 #define IGB_SET_FLAG(_input, _flag, _result) \
5141 ((_flag <= _result) ? \
5142 ((u32)(_input & _flag) * (_result / _flag)) : \
5143 ((u32)(_input & _flag) / (_flag / _result)))
5145 static u32 igb_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
5147 /* set type for advanced descriptor with frame checksum insertion */
5148 u32 cmd_type = E1000_ADVTXD_DTYP_DATA |
5149 E1000_ADVTXD_DCMD_DEXT |
5150 E1000_ADVTXD_DCMD_IFCS;
5152 /* set HW vlan bit if vlan is present */
5153 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_VLAN,
5154 (E1000_ADVTXD_DCMD_VLE));
5156 /* set segmentation bits for TSO */
5157 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_TSO,
5158 (E1000_ADVTXD_DCMD_TSE));
5160 /* set timestamp bit if present */
5161 cmd_type |= IGB_SET_FLAG(tx_flags, IGB_TX_FLAGS_TSTAMP,
5162 (E1000_ADVTXD_MAC_TSTAMP));
5164 /* insert frame checksum */
5165 cmd_type ^= IGB_SET_FLAG(skb->no_fcs, 1, E1000_ADVTXD_DCMD_IFCS);
5170 static void igb_tx_olinfo_status(struct igb_ring *tx_ring,
5171 union e1000_adv_tx_desc *tx_desc,
5172 u32 tx_flags, unsigned int paylen)
5174 u32 olinfo_status = paylen << E1000_ADVTXD_PAYLEN_SHIFT;
5176 /* 82575 requires a unique index per ring */
5177 if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
5178 olinfo_status |= tx_ring->reg_idx << 4;
5180 /* insert L4 checksum */
5181 olinfo_status |= IGB_SET_FLAG(tx_flags,
5183 (E1000_TXD_POPTS_TXSM << 8));
5185 /* insert IPv4 checksum */
5186 olinfo_status |= IGB_SET_FLAG(tx_flags,
5188 (E1000_TXD_POPTS_IXSM << 8));
5190 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
5193 static int __igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
5195 struct net_device *netdev = tx_ring->netdev;
5197 netif_stop_subqueue(netdev, tx_ring->queue_index);
5199 /* Herbert's original patch had:
5200 * smp_mb__after_netif_stop_queue();
5201 * but since that doesn't exist yet, just open code it.
5205 /* We need to check again in a case another CPU has just
5206 * made room available.
5208 if (igb_desc_unused(tx_ring) < size)
5212 netif_wake_subqueue(netdev, tx_ring->queue_index);
5214 u64_stats_update_begin(&tx_ring->tx_syncp2);
5215 tx_ring->tx_stats.restart_queue2++;
5216 u64_stats_update_end(&tx_ring->tx_syncp2);
5221 static inline int igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
5223 if (igb_desc_unused(tx_ring) >= size)
5225 return __igb_maybe_stop_tx(tx_ring, size);
5228 static int igb_tx_map(struct igb_ring *tx_ring,
5229 struct igb_tx_buffer *first,
5232 struct sk_buff *skb = first->skb;
5233 struct igb_tx_buffer *tx_buffer;
5234 union e1000_adv_tx_desc *tx_desc;
5235 struct skb_frag_struct *frag;
5237 unsigned int data_len, size;
5238 u32 tx_flags = first->tx_flags;
5239 u32 cmd_type = igb_tx_cmd_type(skb, tx_flags);
5240 u16 i = tx_ring->next_to_use;
5242 tx_desc = IGB_TX_DESC(tx_ring, i);
5244 igb_tx_olinfo_status(tx_ring, tx_desc, tx_flags, skb->len - hdr_len);
5246 size = skb_headlen(skb);
5247 data_len = skb->data_len;
5249 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
5253 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
5254 if (dma_mapping_error(tx_ring->dev, dma))
5257 /* record length, and DMA address */
5258 dma_unmap_len_set(tx_buffer, len, size);
5259 dma_unmap_addr_set(tx_buffer, dma, dma);
5261 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5263 while (unlikely(size > IGB_MAX_DATA_PER_TXD)) {
5264 tx_desc->read.cmd_type_len =
5265 cpu_to_le32(cmd_type ^ IGB_MAX_DATA_PER_TXD);
5269 if (i == tx_ring->count) {
5270 tx_desc = IGB_TX_DESC(tx_ring, 0);
5273 tx_desc->read.olinfo_status = 0;
5275 dma += IGB_MAX_DATA_PER_TXD;
5276 size -= IGB_MAX_DATA_PER_TXD;
5278 tx_desc->read.buffer_addr = cpu_to_le64(dma);
5281 if (likely(!data_len))
5284 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
5288 if (i == tx_ring->count) {
5289 tx_desc = IGB_TX_DESC(tx_ring, 0);
5292 tx_desc->read.olinfo_status = 0;
5294 size = skb_frag_size(frag);
5297 dma = skb_frag_dma_map(tx_ring->dev, frag, 0,
5298 size, DMA_TO_DEVICE);
5300 tx_buffer = &tx_ring->tx_buffer_info[i];
5303 /* write last descriptor with RS and EOP bits */
5304 cmd_type |= size | IGB_TXD_DCMD;
5305 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
5307 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
5309 /* set the timestamp */
5310 first->time_stamp = jiffies;
5312 /* Force memory writes to complete before letting h/w know there
5313 * are new descriptors to fetch. (Only applicable for weak-ordered
5314 * memory model archs, such as IA-64).
5316 * We also need this memory barrier to make certain all of the
5317 * status bits have been updated before next_to_watch is written.
5321 /* set next_to_watch value indicating a packet is present */
5322 first->next_to_watch = tx_desc;
5325 if (i == tx_ring->count)
5328 tx_ring->next_to_use = i;
5330 /* Make sure there is space in the ring for the next send. */
5331 igb_maybe_stop_tx(tx_ring, DESC_NEEDED);
5333 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
5334 writel(i, tx_ring->tail);
5336 /* we need this if more than one processor can write to our tail
5337 * at a time, it synchronizes IO on IA64/Altix systems
5344 dev_err(tx_ring->dev, "TX DMA map failed\n");
5345 tx_buffer = &tx_ring->tx_buffer_info[i];
5347 /* clear dma mappings for failed tx_buffer_info map */
5348 while (tx_buffer != first) {
5349 if (dma_unmap_len(tx_buffer, len))
5350 dma_unmap_page(tx_ring->dev,
5351 dma_unmap_addr(tx_buffer, dma),
5352 dma_unmap_len(tx_buffer, len),
5354 dma_unmap_len_set(tx_buffer, len, 0);
5357 i += tx_ring->count;
5358 tx_buffer = &tx_ring->tx_buffer_info[i];
5361 if (dma_unmap_len(tx_buffer, len))
5362 dma_unmap_single(tx_ring->dev,
5363 dma_unmap_addr(tx_buffer, dma),
5364 dma_unmap_len(tx_buffer, len),
5366 dma_unmap_len_set(tx_buffer, len, 0);
5368 dev_kfree_skb_any(tx_buffer->skb);
5369 tx_buffer->skb = NULL;
5371 tx_ring->next_to_use = i;
5376 netdev_tx_t igb_xmit_frame_ring(struct sk_buff *skb,
5377 struct igb_ring *tx_ring)
5379 struct igb_tx_buffer *first;
5383 u16 count = TXD_USE_COUNT(skb_headlen(skb));
5384 __be16 protocol = vlan_get_protocol(skb);
5387 /* need: 1 descriptor per page * PAGE_SIZE/IGB_MAX_DATA_PER_TXD,
5388 * + 1 desc for skb_headlen/IGB_MAX_DATA_PER_TXD,
5389 * + 2 desc gap to keep tail from touching head,
5390 * + 1 desc for context descriptor,
5391 * otherwise try next time
5393 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
5394 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
5396 if (igb_maybe_stop_tx(tx_ring, count + 3)) {
5397 /* this is a hard error */
5398 return NETDEV_TX_BUSY;
5401 /* record the location of the first descriptor for this packet */
5402 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
5404 first->bytecount = skb->len;
5405 first->gso_segs = 1;
5407 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
5408 struct igb_adapter *adapter = netdev_priv(tx_ring->netdev);
5410 if (adapter->tstamp_config.tx_type & HWTSTAMP_TX_ON &&
5411 !test_and_set_bit_lock(__IGB_PTP_TX_IN_PROGRESS,
5413 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
5414 tx_flags |= IGB_TX_FLAGS_TSTAMP;
5416 adapter->ptp_tx_skb = skb_get(skb);
5417 adapter->ptp_tx_start = jiffies;
5418 if (adapter->hw.mac.type == e1000_82576)
5419 schedule_work(&adapter->ptp_tx_work);
5421 adapter->tx_hwtstamp_skipped++;
5425 skb_tx_timestamp(skb);
5427 if (skb_vlan_tag_present(skb)) {
5428 tx_flags |= IGB_TX_FLAGS_VLAN;
5429 tx_flags |= (skb_vlan_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
5432 /* record initial flags and protocol */
5433 first->tx_flags = tx_flags;
5434 first->protocol = protocol;
5436 tso = igb_tso(tx_ring, first, &hdr_len);
5440 igb_tx_csum(tx_ring, first);
5442 if (igb_tx_map(tx_ring, first, hdr_len))
5443 goto cleanup_tx_tstamp;
5445 return NETDEV_TX_OK;
5448 dev_kfree_skb_any(first->skb);
5451 if (unlikely(tx_flags & IGB_TX_FLAGS_TSTAMP)) {
5452 struct igb_adapter *adapter = netdev_priv(tx_ring->netdev);
5454 dev_kfree_skb_any(adapter->ptp_tx_skb);
5455 adapter->ptp_tx_skb = NULL;
5456 if (adapter->hw.mac.type == e1000_82576)
5457 cancel_work_sync(&adapter->ptp_tx_work);
5458 clear_bit_unlock(__IGB_PTP_TX_IN_PROGRESS, &adapter->state);
5461 return NETDEV_TX_OK;
5464 static inline struct igb_ring *igb_tx_queue_mapping(struct igb_adapter *adapter,
5465 struct sk_buff *skb)
5467 unsigned int r_idx = skb->queue_mapping;
5469 if (r_idx >= adapter->num_tx_queues)
5470 r_idx = r_idx % adapter->num_tx_queues;
5472 return adapter->tx_ring[r_idx];
5475 static netdev_tx_t igb_xmit_frame(struct sk_buff *skb,
5476 struct net_device *netdev)
5478 struct igb_adapter *adapter = netdev_priv(netdev);
5480 /* The minimum packet size with TCTL.PSP set is 17 so pad the skb
5481 * in order to meet this minimum size requirement.
5483 if (skb_put_padto(skb, 17))
5484 return NETDEV_TX_OK;
5486 return igb_xmit_frame_ring(skb, igb_tx_queue_mapping(adapter, skb));
5490 * igb_tx_timeout - Respond to a Tx Hang
5491 * @netdev: network interface device structure
5493 static void igb_tx_timeout(struct net_device *netdev)
5495 struct igb_adapter *adapter = netdev_priv(netdev);
5496 struct e1000_hw *hw = &adapter->hw;
5498 /* Do the reset outside of interrupt context */
5499 adapter->tx_timeout_count++;
5501 if (hw->mac.type >= e1000_82580)
5502 hw->dev_spec._82575.global_device_reset = true;
5504 schedule_work(&adapter->reset_task);
5506 (adapter->eims_enable_mask & ~adapter->eims_other));
5509 static void igb_reset_task(struct work_struct *work)
5511 struct igb_adapter *adapter;
5512 adapter = container_of(work, struct igb_adapter, reset_task);
5515 /* If we're already down or resetting, just bail */
5516 if (test_bit(__IGB_DOWN, &adapter->state) ||
5517 test_bit(__IGB_RESETTING, &adapter->state)) {
5523 netdev_err(adapter->netdev, "Reset adapter\n");
5524 igb_reinit_locked(adapter);
5529 * igb_get_stats64 - Get System Network Statistics
5530 * @netdev: network interface device structure
5531 * @stats: rtnl_link_stats64 pointer
5533 static void igb_get_stats64(struct net_device *netdev,
5534 struct rtnl_link_stats64 *stats)
5536 struct igb_adapter *adapter = netdev_priv(netdev);
5538 spin_lock(&adapter->stats64_lock);
5539 igb_update_stats(adapter);
5540 memcpy(stats, &adapter->stats64, sizeof(*stats));
5541 spin_unlock(&adapter->stats64_lock);
5545 * igb_change_mtu - Change the Maximum Transfer Unit
5546 * @netdev: network interface device structure
5547 * @new_mtu: new value for maximum frame size
5549 * Returns 0 on success, negative on failure
5551 static int igb_change_mtu(struct net_device *netdev, int new_mtu)
5553 struct igb_adapter *adapter = netdev_priv(netdev);
5554 struct pci_dev *pdev = adapter->pdev;
5555 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
5557 /* adjust max frame to be at least the size of a standard frame */
5558 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
5559 max_frame = ETH_FRAME_LEN + ETH_FCS_LEN;
5561 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
5562 usleep_range(1000, 2000);
5564 /* igb_down has a dependency on max_frame_size */
5565 adapter->max_frame_size = max_frame;
5567 if (netif_running(netdev))
5570 dev_info(&pdev->dev, "changing MTU from %d to %d\n",
5571 netdev->mtu, new_mtu);
5572 netdev->mtu = new_mtu;
5574 if (netif_running(netdev))
5579 clear_bit(__IGB_RESETTING, &adapter->state);
5585 * igb_update_stats - Update the board statistics counters
5586 * @adapter: board private structure
5588 void igb_update_stats(struct igb_adapter *adapter)
5590 struct rtnl_link_stats64 *net_stats = &adapter->stats64;
5591 struct e1000_hw *hw = &adapter->hw;
5592 struct pci_dev *pdev = adapter->pdev;
5597 u64 _bytes, _packets;
5599 /* Prevent stats update while adapter is being reset, or if the pci
5600 * connection is down.
5602 if (adapter->link_speed == 0)
5604 if (pci_channel_offline(pdev))
5611 for (i = 0; i < adapter->num_rx_queues; i++) {
5612 struct igb_ring *ring = adapter->rx_ring[i];
5613 u32 rqdpc = rd32(E1000_RQDPC(i));
5614 if (hw->mac.type >= e1000_i210)
5615 wr32(E1000_RQDPC(i), 0);
5618 ring->rx_stats.drops += rqdpc;
5619 net_stats->rx_fifo_errors += rqdpc;
5623 start = u64_stats_fetch_begin_irq(&ring->rx_syncp);
5624 _bytes = ring->rx_stats.bytes;
5625 _packets = ring->rx_stats.packets;
5626 } while (u64_stats_fetch_retry_irq(&ring->rx_syncp, start));
5628 packets += _packets;
5631 net_stats->rx_bytes = bytes;
5632 net_stats->rx_packets = packets;
5636 for (i = 0; i < adapter->num_tx_queues; i++) {
5637 struct igb_ring *ring = adapter->tx_ring[i];
5639 start = u64_stats_fetch_begin_irq(&ring->tx_syncp);
5640 _bytes = ring->tx_stats.bytes;
5641 _packets = ring->tx_stats.packets;
5642 } while (u64_stats_fetch_retry_irq(&ring->tx_syncp, start));
5644 packets += _packets;
5646 net_stats->tx_bytes = bytes;
5647 net_stats->tx_packets = packets;
5650 /* read stats registers */
5651 adapter->stats.crcerrs += rd32(E1000_CRCERRS);
5652 adapter->stats.gprc += rd32(E1000_GPRC);
5653 adapter->stats.gorc += rd32(E1000_GORCL);
5654 rd32(E1000_GORCH); /* clear GORCL */
5655 adapter->stats.bprc += rd32(E1000_BPRC);
5656 adapter->stats.mprc += rd32(E1000_MPRC);
5657 adapter->stats.roc += rd32(E1000_ROC);
5659 adapter->stats.prc64 += rd32(E1000_PRC64);
5660 adapter->stats.prc127 += rd32(E1000_PRC127);
5661 adapter->stats.prc255 += rd32(E1000_PRC255);
5662 adapter->stats.prc511 += rd32(E1000_PRC511);
5663 adapter->stats.prc1023 += rd32(E1000_PRC1023);
5664 adapter->stats.prc1522 += rd32(E1000_PRC1522);
5665 adapter->stats.symerrs += rd32(E1000_SYMERRS);
5666 adapter->stats.sec += rd32(E1000_SEC);
5668 mpc = rd32(E1000_MPC);
5669 adapter->stats.mpc += mpc;
5670 net_stats->rx_fifo_errors += mpc;
5671 adapter->stats.scc += rd32(E1000_SCC);
5672 adapter->stats.ecol += rd32(E1000_ECOL);
5673 adapter->stats.mcc += rd32(E1000_MCC);
5674 adapter->stats.latecol += rd32(E1000_LATECOL);
5675 adapter->stats.dc += rd32(E1000_DC);
5676 adapter->stats.rlec += rd32(E1000_RLEC);
5677 adapter->stats.xonrxc += rd32(E1000_XONRXC);
5678 adapter->stats.xontxc += rd32(E1000_XONTXC);
5679 adapter->stats.xoffrxc += rd32(E1000_XOFFRXC);
5680 adapter->stats.xofftxc += rd32(E1000_XOFFTXC);
5681 adapter->stats.fcruc += rd32(E1000_FCRUC);
5682 adapter->stats.gptc += rd32(E1000_GPTC);
5683 adapter->stats.gotc += rd32(E1000_GOTCL);
5684 rd32(E1000_GOTCH); /* clear GOTCL */
5685 adapter->stats.rnbc += rd32(E1000_RNBC);
5686 adapter->stats.ruc += rd32(E1000_RUC);
5687 adapter->stats.rfc += rd32(E1000_RFC);
5688 adapter->stats.rjc += rd32(E1000_RJC);
5689 adapter->stats.tor += rd32(E1000_TORH);
5690 adapter->stats.tot += rd32(E1000_TOTH);
5691 adapter->stats.tpr += rd32(E1000_TPR);
5693 adapter->stats.ptc64 += rd32(E1000_PTC64);
5694 adapter->stats.ptc127 += rd32(E1000_PTC127);
5695 adapter->stats.ptc255 += rd32(E1000_PTC255);
5696 adapter->stats.ptc511 += rd32(E1000_PTC511);
5697 adapter->stats.ptc1023 += rd32(E1000_PTC1023);
5698 adapter->stats.ptc1522 += rd32(E1000_PTC1522);
5700 adapter->stats.mptc += rd32(E1000_MPTC);
5701 adapter->stats.bptc += rd32(E1000_BPTC);
5703 adapter->stats.tpt += rd32(E1000_TPT);
5704 adapter->stats.colc += rd32(E1000_COLC);
5706 adapter->stats.algnerrc += rd32(E1000_ALGNERRC);
5707 /* read internal phy specific stats */
5708 reg = rd32(E1000_CTRL_EXT);
5709 if (!(reg & E1000_CTRL_EXT_LINK_MODE_MASK)) {
5710 adapter->stats.rxerrc += rd32(E1000_RXERRC);
5712 /* this stat has invalid values on i210/i211 */
5713 if ((hw->mac.type != e1000_i210) &&
5714 (hw->mac.type != e1000_i211))
5715 adapter->stats.tncrs += rd32(E1000_TNCRS);
5718 adapter->stats.tsctc += rd32(E1000_TSCTC);
5719 adapter->stats.tsctfc += rd32(E1000_TSCTFC);
5721 adapter->stats.iac += rd32(E1000_IAC);
5722 adapter->stats.icrxoc += rd32(E1000_ICRXOC);
5723 adapter->stats.icrxptc += rd32(E1000_ICRXPTC);
5724 adapter->stats.icrxatc += rd32(E1000_ICRXATC);
5725 adapter->stats.ictxptc += rd32(E1000_ICTXPTC);
5726 adapter->stats.ictxatc += rd32(E1000_ICTXATC);
5727 adapter->stats.ictxqec += rd32(E1000_ICTXQEC);
5728 adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC);
5729 adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC);
5731 /* Fill out the OS statistics structure */
5732 net_stats->multicast = adapter->stats.mprc;
5733 net_stats->collisions = adapter->stats.colc;
5737 /* RLEC on some newer hardware can be incorrect so build
5738 * our own version based on RUC and ROC
5740 net_stats->rx_errors = adapter->stats.rxerrc +
5741 adapter->stats.crcerrs + adapter->stats.algnerrc +
5742 adapter->stats.ruc + adapter->stats.roc +
5743 adapter->stats.cexterr;
5744 net_stats->rx_length_errors = adapter->stats.ruc +
5746 net_stats->rx_crc_errors = adapter->stats.crcerrs;
5747 net_stats->rx_frame_errors = adapter->stats.algnerrc;
5748 net_stats->rx_missed_errors = adapter->stats.mpc;
5751 net_stats->tx_errors = adapter->stats.ecol +
5752 adapter->stats.latecol;
5753 net_stats->tx_aborted_errors = adapter->stats.ecol;
5754 net_stats->tx_window_errors = adapter->stats.latecol;
5755 net_stats->tx_carrier_errors = adapter->stats.tncrs;
5757 /* Tx Dropped needs to be maintained elsewhere */
5759 /* Management Stats */
5760 adapter->stats.mgptc += rd32(E1000_MGTPTC);
5761 adapter->stats.mgprc += rd32(E1000_MGTPRC);
5762 adapter->stats.mgpdc += rd32(E1000_MGTPDC);
5765 reg = rd32(E1000_MANC);
5766 if (reg & E1000_MANC_EN_BMC2OS) {
5767 adapter->stats.o2bgptc += rd32(E1000_O2BGPTC);
5768 adapter->stats.o2bspc += rd32(E1000_O2BSPC);
5769 adapter->stats.b2ospc += rd32(E1000_B2OSPC);
5770 adapter->stats.b2ogprc += rd32(E1000_B2OGPRC);
5774 static void igb_tsync_interrupt(struct igb_adapter *adapter)
5776 struct e1000_hw *hw = &adapter->hw;
5777 struct ptp_clock_event event;
5778 struct timespec64 ts;
5779 u32 ack = 0, tsauxc, sec, nsec, tsicr = rd32(E1000_TSICR);
5781 if (tsicr & TSINTR_SYS_WRAP) {
5782 event.type = PTP_CLOCK_PPS;
5783 if (adapter->ptp_caps.pps)
5784 ptp_clock_event(adapter->ptp_clock, &event);
5785 ack |= TSINTR_SYS_WRAP;
5788 if (tsicr & E1000_TSICR_TXTS) {
5789 /* retrieve hardware timestamp */
5790 schedule_work(&adapter->ptp_tx_work);
5791 ack |= E1000_TSICR_TXTS;
5794 if (tsicr & TSINTR_TT0) {
5795 spin_lock(&adapter->tmreg_lock);
5796 ts = timespec64_add(adapter->perout[0].start,
5797 adapter->perout[0].period);
5798 /* u32 conversion of tv_sec is safe until y2106 */
5799 wr32(E1000_TRGTTIML0, ts.tv_nsec);
5800 wr32(E1000_TRGTTIMH0, (u32)ts.tv_sec);
5801 tsauxc = rd32(E1000_TSAUXC);
5802 tsauxc |= TSAUXC_EN_TT0;
5803 wr32(E1000_TSAUXC, tsauxc);
5804 adapter->perout[0].start = ts;
5805 spin_unlock(&adapter->tmreg_lock);
5809 if (tsicr & TSINTR_TT1) {
5810 spin_lock(&adapter->tmreg_lock);
5811 ts = timespec64_add(adapter->perout[1].start,
5812 adapter->perout[1].period);
5813 wr32(E1000_TRGTTIML1, ts.tv_nsec);
5814 wr32(E1000_TRGTTIMH1, (u32)ts.tv_sec);
5815 tsauxc = rd32(E1000_TSAUXC);
5816 tsauxc |= TSAUXC_EN_TT1;
5817 wr32(E1000_TSAUXC, tsauxc);
5818 adapter->perout[1].start = ts;
5819 spin_unlock(&adapter->tmreg_lock);
5823 if (tsicr & TSINTR_AUTT0) {
5824 nsec = rd32(E1000_AUXSTMPL0);
5825 sec = rd32(E1000_AUXSTMPH0);
5826 event.type = PTP_CLOCK_EXTTS;
5828 event.timestamp = sec * 1000000000ULL + nsec;
5829 ptp_clock_event(adapter->ptp_clock, &event);
5830 ack |= TSINTR_AUTT0;
5833 if (tsicr & TSINTR_AUTT1) {
5834 nsec = rd32(E1000_AUXSTMPL1);
5835 sec = rd32(E1000_AUXSTMPH1);
5836 event.type = PTP_CLOCK_EXTTS;
5838 event.timestamp = sec * 1000000000ULL + nsec;
5839 ptp_clock_event(adapter->ptp_clock, &event);
5840 ack |= TSINTR_AUTT1;
5843 /* acknowledge the interrupts */
5844 wr32(E1000_TSICR, ack);
5847 static irqreturn_t igb_msix_other(int irq, void *data)
5849 struct igb_adapter *adapter = data;
5850 struct e1000_hw *hw = &adapter->hw;
5851 u32 icr = rd32(E1000_ICR);
5852 /* reading ICR causes bit 31 of EICR to be cleared */
5854 if (icr & E1000_ICR_DRSTA)
5855 schedule_work(&adapter->reset_task);
5857 if (icr & E1000_ICR_DOUTSYNC) {
5858 /* HW is reporting DMA is out of sync */
5859 adapter->stats.doosync++;
5860 /* The DMA Out of Sync is also indication of a spoof event
5861 * in IOV mode. Check the Wrong VM Behavior register to
5862 * see if it is really a spoof event.
5864 igb_check_wvbr(adapter);
5867 /* Check for a mailbox event */
5868 if (icr & E1000_ICR_VMMB)
5869 igb_msg_task(adapter);
5871 if (icr & E1000_ICR_LSC) {
5872 hw->mac.get_link_status = 1;
5873 /* guard against interrupt when we're going down */
5874 if (!test_bit(__IGB_DOWN, &adapter->state))
5875 mod_timer(&adapter->watchdog_timer, jiffies + 1);
5878 if (icr & E1000_ICR_TS)
5879 igb_tsync_interrupt(adapter);
5881 wr32(E1000_EIMS, adapter->eims_other);
5886 static void igb_write_itr(struct igb_q_vector *q_vector)
5888 struct igb_adapter *adapter = q_vector->adapter;
5889 u32 itr_val = q_vector->itr_val & 0x7FFC;
5891 if (!q_vector->set_itr)
5897 if (adapter->hw.mac.type == e1000_82575)
5898 itr_val |= itr_val << 16;
5900 itr_val |= E1000_EITR_CNT_IGNR;
5902 writel(itr_val, q_vector->itr_register);
5903 q_vector->set_itr = 0;
5906 static irqreturn_t igb_msix_ring(int irq, void *data)
5908 struct igb_q_vector *q_vector = data;
5910 /* Write the ITR value calculated from the previous interrupt. */
5911 igb_write_itr(q_vector);
5913 napi_schedule(&q_vector->napi);
5918 #ifdef CONFIG_IGB_DCA
5919 static void igb_update_tx_dca(struct igb_adapter *adapter,
5920 struct igb_ring *tx_ring,
5923 struct e1000_hw *hw = &adapter->hw;
5924 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
5926 if (hw->mac.type != e1000_82575)
5927 txctrl <<= E1000_DCA_TXCTRL_CPUID_SHIFT;
5929 /* We can enable relaxed ordering for reads, but not writes when
5930 * DCA is enabled. This is due to a known issue in some chipsets
5931 * which will cause the DCA tag to be cleared.
5933 txctrl |= E1000_DCA_TXCTRL_DESC_RRO_EN |
5934 E1000_DCA_TXCTRL_DATA_RRO_EN |
5935 E1000_DCA_TXCTRL_DESC_DCA_EN;
5937 wr32(E1000_DCA_TXCTRL(tx_ring->reg_idx), txctrl);
5940 static void igb_update_rx_dca(struct igb_adapter *adapter,
5941 struct igb_ring *rx_ring,
5944 struct e1000_hw *hw = &adapter->hw;
5945 u32 rxctrl = dca3_get_tag(&adapter->pdev->dev, cpu);
5947 if (hw->mac.type != e1000_82575)
5948 rxctrl <<= E1000_DCA_RXCTRL_CPUID_SHIFT;
5950 /* We can enable relaxed ordering for reads, but not writes when
5951 * DCA is enabled. This is due to a known issue in some chipsets
5952 * which will cause the DCA tag to be cleared.
5954 rxctrl |= E1000_DCA_RXCTRL_DESC_RRO_EN |
5955 E1000_DCA_RXCTRL_DESC_DCA_EN;
5957 wr32(E1000_DCA_RXCTRL(rx_ring->reg_idx), rxctrl);
5960 static void igb_update_dca(struct igb_q_vector *q_vector)
5962 struct igb_adapter *adapter = q_vector->adapter;
5963 int cpu = get_cpu();
5965 if (q_vector->cpu == cpu)
5968 if (q_vector->tx.ring)
5969 igb_update_tx_dca(adapter, q_vector->tx.ring, cpu);
5971 if (q_vector->rx.ring)
5972 igb_update_rx_dca(adapter, q_vector->rx.ring, cpu);
5974 q_vector->cpu = cpu;
5979 static void igb_setup_dca(struct igb_adapter *adapter)
5981 struct e1000_hw *hw = &adapter->hw;
5984 if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
5987 /* Always use CB2 mode, difference is masked in the CB driver. */
5988 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
5990 for (i = 0; i < adapter->num_q_vectors; i++) {
5991 adapter->q_vector[i]->cpu = -1;
5992 igb_update_dca(adapter->q_vector[i]);
5996 static int __igb_notify_dca(struct device *dev, void *data)
5998 struct net_device *netdev = dev_get_drvdata(dev);
5999 struct igb_adapter *adapter = netdev_priv(netdev);
6000 struct pci_dev *pdev = adapter->pdev;
6001 struct e1000_hw *hw = &adapter->hw;
6002 unsigned long event = *(unsigned long *)data;
6005 case DCA_PROVIDER_ADD:
6006 /* if already enabled, don't do it again */
6007 if (adapter->flags & IGB_FLAG_DCA_ENABLED)
6009 if (dca_add_requester(dev) == 0) {
6010 adapter->flags |= IGB_FLAG_DCA_ENABLED;
6011 dev_info(&pdev->dev, "DCA enabled\n");
6012 igb_setup_dca(adapter);
6015 /* Fall Through since DCA is disabled. */
6016 case DCA_PROVIDER_REMOVE:
6017 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
6018 /* without this a class_device is left
6019 * hanging around in the sysfs model
6021 dca_remove_requester(dev);
6022 dev_info(&pdev->dev, "DCA disabled\n");
6023 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
6024 wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
6032 static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
6037 ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
6040 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
6042 #endif /* CONFIG_IGB_DCA */
6044 #ifdef CONFIG_PCI_IOV
6045 static int igb_vf_configure(struct igb_adapter *adapter, int vf)
6047 unsigned char mac_addr[ETH_ALEN];
6049 eth_zero_addr(mac_addr);
6050 igb_set_vf_mac(adapter, vf, mac_addr);
6052 /* By default spoof check is enabled for all VFs */
6053 adapter->vf_data[vf].spoofchk_enabled = true;
6059 static void igb_ping_all_vfs(struct igb_adapter *adapter)
6061 struct e1000_hw *hw = &adapter->hw;
6065 for (i = 0 ; i < adapter->vfs_allocated_count; i++) {
6066 ping = E1000_PF_CONTROL_MSG;
6067 if (adapter->vf_data[i].flags & IGB_VF_FLAG_CTS)
6068 ping |= E1000_VT_MSGTYPE_CTS;
6069 igb_write_mbx(hw, &ping, 1, i);
6073 static int igb_set_vf_promisc(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
6075 struct e1000_hw *hw = &adapter->hw;
6076 u32 vmolr = rd32(E1000_VMOLR(vf));
6077 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6079 vf_data->flags &= ~(IGB_VF_FLAG_UNI_PROMISC |
6080 IGB_VF_FLAG_MULTI_PROMISC);
6081 vmolr &= ~(E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
6083 if (*msgbuf & E1000_VF_SET_PROMISC_MULTICAST) {
6084 vmolr |= E1000_VMOLR_MPME;
6085 vf_data->flags |= IGB_VF_FLAG_MULTI_PROMISC;
6086 *msgbuf &= ~E1000_VF_SET_PROMISC_MULTICAST;
6088 /* if we have hashes and we are clearing a multicast promisc
6089 * flag we need to write the hashes to the MTA as this step
6090 * was previously skipped
6092 if (vf_data->num_vf_mc_hashes > 30) {
6093 vmolr |= E1000_VMOLR_MPME;
6094 } else if (vf_data->num_vf_mc_hashes) {
6097 vmolr |= E1000_VMOLR_ROMPE;
6098 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
6099 igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
6103 wr32(E1000_VMOLR(vf), vmolr);
6105 /* there are flags left unprocessed, likely not supported */
6106 if (*msgbuf & E1000_VT_MSGINFO_MASK)
6112 static int igb_set_vf_multicasts(struct igb_adapter *adapter,
6113 u32 *msgbuf, u32 vf)
6115 int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
6116 u16 *hash_list = (u16 *)&msgbuf[1];
6117 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6120 /* salt away the number of multicast addresses assigned
6121 * to this VF for later use to restore when the PF multi cast
6124 vf_data->num_vf_mc_hashes = n;
6126 /* only up to 30 hash values supported */
6130 /* store the hashes for later use */
6131 for (i = 0; i < n; i++)
6132 vf_data->vf_mc_hashes[i] = hash_list[i];
6134 /* Flush and reset the mta with the new values */
6135 igb_set_rx_mode(adapter->netdev);
6140 static void igb_restore_vf_multicasts(struct igb_adapter *adapter)
6142 struct e1000_hw *hw = &adapter->hw;
6143 struct vf_data_storage *vf_data;
6146 for (i = 0; i < adapter->vfs_allocated_count; i++) {
6147 u32 vmolr = rd32(E1000_VMOLR(i));
6149 vmolr &= ~(E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
6151 vf_data = &adapter->vf_data[i];
6153 if ((vf_data->num_vf_mc_hashes > 30) ||
6154 (vf_data->flags & IGB_VF_FLAG_MULTI_PROMISC)) {
6155 vmolr |= E1000_VMOLR_MPME;
6156 } else if (vf_data->num_vf_mc_hashes) {
6157 vmolr |= E1000_VMOLR_ROMPE;
6158 for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
6159 igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
6161 wr32(E1000_VMOLR(i), vmolr);
6165 static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf)
6167 struct e1000_hw *hw = &adapter->hw;
6168 u32 pool_mask, vlvf_mask, i;
6170 /* create mask for VF and other pools */
6171 pool_mask = E1000_VLVF_POOLSEL_MASK;
6172 vlvf_mask = BIT(E1000_VLVF_POOLSEL_SHIFT + vf);
6174 /* drop PF from pool bits */
6175 pool_mask &= ~BIT(E1000_VLVF_POOLSEL_SHIFT +
6176 adapter->vfs_allocated_count);
6178 /* Find the vlan filter for this id */
6179 for (i = E1000_VLVF_ARRAY_SIZE; i--;) {
6180 u32 vlvf = rd32(E1000_VLVF(i));
6181 u32 vfta_mask, vid, vfta;
6183 /* remove the vf from the pool */
6184 if (!(vlvf & vlvf_mask))
6187 /* clear out bit from VLVF */
6190 /* if other pools are present, just remove ourselves */
6191 if (vlvf & pool_mask)
6194 /* if PF is present, leave VFTA */
6195 if (vlvf & E1000_VLVF_POOLSEL_MASK)
6198 vid = vlvf & E1000_VLVF_VLANID_MASK;
6199 vfta_mask = BIT(vid % 32);
6201 /* clear bit from VFTA */
6202 vfta = adapter->shadow_vfta[vid / 32];
6203 if (vfta & vfta_mask)
6204 hw->mac.ops.write_vfta(hw, vid / 32, vfta ^ vfta_mask);
6206 /* clear pool selection enable */
6207 if (adapter->flags & IGB_FLAG_VLAN_PROMISC)
6208 vlvf &= E1000_VLVF_POOLSEL_MASK;
6212 /* clear pool bits */
6213 wr32(E1000_VLVF(i), vlvf);
6217 static int igb_find_vlvf_entry(struct e1000_hw *hw, u32 vlan)
6222 /* short cut the special case */
6226 /* Search for the VLAN id in the VLVF entries */
6227 for (idx = E1000_VLVF_ARRAY_SIZE; --idx;) {
6228 vlvf = rd32(E1000_VLVF(idx));
6229 if ((vlvf & VLAN_VID_MASK) == vlan)
6236 static void igb_update_pf_vlvf(struct igb_adapter *adapter, u32 vid)
6238 struct e1000_hw *hw = &adapter->hw;
6242 idx = igb_find_vlvf_entry(hw, vid);
6246 /* See if any other pools are set for this VLAN filter
6247 * entry other than the PF.
6249 pf_id = adapter->vfs_allocated_count + E1000_VLVF_POOLSEL_SHIFT;
6250 bits = ~BIT(pf_id) & E1000_VLVF_POOLSEL_MASK;
6251 bits &= rd32(E1000_VLVF(idx));
6253 /* Disable the filter so this falls into the default pool. */
6255 if (adapter->flags & IGB_FLAG_VLAN_PROMISC)
6256 wr32(E1000_VLVF(idx), BIT(pf_id));
6258 wr32(E1000_VLVF(idx), 0);
6262 static s32 igb_set_vf_vlan(struct igb_adapter *adapter, u32 vid,
6265 int pf_id = adapter->vfs_allocated_count;
6266 struct e1000_hw *hw = &adapter->hw;
6269 /* If VLAN overlaps with one the PF is currently monitoring make
6270 * sure that we are able to allocate a VLVF entry. This may be
6271 * redundant but it guarantees PF will maintain visibility to
6274 if (add && test_bit(vid, adapter->active_vlans)) {
6275 err = igb_vfta_set(hw, vid, pf_id, true, false);
6280 err = igb_vfta_set(hw, vid, vf, add, false);
6285 /* If we failed to add the VF VLAN or we are removing the VF VLAN
6286 * we may need to drop the PF pool bit in order to allow us to free
6287 * up the VLVF resources.
6289 if (test_bit(vid, adapter->active_vlans) ||
6290 (adapter->flags & IGB_FLAG_VLAN_PROMISC))
6291 igb_update_pf_vlvf(adapter, vid);
6296 static void igb_set_vmvir(struct igb_adapter *adapter, u32 vid, u32 vf)
6298 struct e1000_hw *hw = &adapter->hw;
6301 wr32(E1000_VMVIR(vf), (vid | E1000_VMVIR_VLANA_DEFAULT));
6303 wr32(E1000_VMVIR(vf), 0);
6306 static int igb_enable_port_vlan(struct igb_adapter *adapter, int vf,
6311 err = igb_set_vf_vlan(adapter, vlan, true, vf);
6315 igb_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf);
6316 igb_set_vmolr(adapter, vf, !vlan);
6318 /* revoke access to previous VLAN */
6319 if (vlan != adapter->vf_data[vf].pf_vlan)
6320 igb_set_vf_vlan(adapter, adapter->vf_data[vf].pf_vlan,
6323 adapter->vf_data[vf].pf_vlan = vlan;
6324 adapter->vf_data[vf].pf_qos = qos;
6325 igb_set_vf_vlan_strip(adapter, vf, true);
6326 dev_info(&adapter->pdev->dev,
6327 "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
6328 if (test_bit(__IGB_DOWN, &adapter->state)) {
6329 dev_warn(&adapter->pdev->dev,
6330 "The VF VLAN has been set, but the PF device is not up.\n");
6331 dev_warn(&adapter->pdev->dev,
6332 "Bring the PF device up before attempting to use the VF device.\n");
6338 static int igb_disable_port_vlan(struct igb_adapter *adapter, int vf)
6340 /* Restore tagless access via VLAN 0 */
6341 igb_set_vf_vlan(adapter, 0, true, vf);
6343 igb_set_vmvir(adapter, 0, vf);
6344 igb_set_vmolr(adapter, vf, true);
6346 /* Remove any PF assigned VLAN */
6347 if (adapter->vf_data[vf].pf_vlan)
6348 igb_set_vf_vlan(adapter, adapter->vf_data[vf].pf_vlan,
6351 adapter->vf_data[vf].pf_vlan = 0;
6352 adapter->vf_data[vf].pf_qos = 0;
6353 igb_set_vf_vlan_strip(adapter, vf, false);
6358 static int igb_ndo_set_vf_vlan(struct net_device *netdev, int vf,
6359 u16 vlan, u8 qos, __be16 vlan_proto)
6361 struct igb_adapter *adapter = netdev_priv(netdev);
6363 if ((vf >= adapter->vfs_allocated_count) || (vlan > 4095) || (qos > 7))
6366 if (vlan_proto != htons(ETH_P_8021Q))
6367 return -EPROTONOSUPPORT;
6369 return (vlan || qos) ? igb_enable_port_vlan(adapter, vf, vlan, qos) :
6370 igb_disable_port_vlan(adapter, vf);
6373 static int igb_set_vf_vlan_msg(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
6375 int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
6376 int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
6379 if (adapter->vf_data[vf].pf_vlan)
6382 /* VLAN 0 is a special case, don't allow it to be removed */
6386 ret = igb_set_vf_vlan(adapter, vid, !!add, vf);
6388 igb_set_vf_vlan_strip(adapter, vf, !!vid);
6392 static inline void igb_vf_reset(struct igb_adapter *adapter, u32 vf)
6394 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6396 /* clear flags - except flag that indicates PF has set the MAC */
6397 vf_data->flags &= IGB_VF_FLAG_PF_SET_MAC;
6398 vf_data->last_nack = jiffies;
6400 /* reset vlans for device */
6401 igb_clear_vf_vfta(adapter, vf);
6402 igb_set_vf_vlan(adapter, vf_data->pf_vlan, true, vf);
6403 igb_set_vmvir(adapter, vf_data->pf_vlan |
6404 (vf_data->pf_qos << VLAN_PRIO_SHIFT), vf);
6405 igb_set_vmolr(adapter, vf, !vf_data->pf_vlan);
6406 igb_set_vf_vlan_strip(adapter, vf, !!(vf_data->pf_vlan));
6408 /* reset multicast table array for vf */
6409 adapter->vf_data[vf].num_vf_mc_hashes = 0;
6411 /* Flush and reset the mta with the new values */
6412 igb_set_rx_mode(adapter->netdev);
6415 static void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf)
6417 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
6419 /* clear mac address as we were hotplug removed/added */
6420 if (!(adapter->vf_data[vf].flags & IGB_VF_FLAG_PF_SET_MAC))
6421 eth_zero_addr(vf_mac);
6423 /* process remaining reset events */
6424 igb_vf_reset(adapter, vf);
6427 static void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf)
6429 struct e1000_hw *hw = &adapter->hw;
6430 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
6431 u32 reg, msgbuf[3] = {};
6432 u8 *addr = (u8 *)(&msgbuf[1]);
6434 /* process all the same items cleared in a function level reset */
6435 igb_vf_reset(adapter, vf);
6437 /* set vf mac address */
6438 igb_set_vf_mac(adapter, vf, vf_mac);
6440 /* enable transmit and receive for vf */
6441 reg = rd32(E1000_VFTE);
6442 wr32(E1000_VFTE, reg | BIT(vf));
6443 reg = rd32(E1000_VFRE);
6444 wr32(E1000_VFRE, reg | BIT(vf));
6446 adapter->vf_data[vf].flags |= IGB_VF_FLAG_CTS;
6448 /* reply to reset with ack and vf mac address */
6449 if (!is_zero_ether_addr(vf_mac)) {
6450 msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK;
6451 memcpy(addr, vf_mac, ETH_ALEN);
6453 msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_NACK;
6455 igb_write_mbx(hw, msgbuf, 3, vf);
6458 static void igb_flush_mac_table(struct igb_adapter *adapter)
6460 struct e1000_hw *hw = &adapter->hw;
6463 for (i = 0; i < hw->mac.rar_entry_count; i++) {
6464 adapter->mac_table[i].state &= ~IGB_MAC_STATE_IN_USE;
6465 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
6466 adapter->mac_table[i].queue = 0;
6467 igb_rar_set_index(adapter, i);
6471 static int igb_available_rars(struct igb_adapter *adapter, u8 queue)
6473 struct e1000_hw *hw = &adapter->hw;
6474 /* do not count rar entries reserved for VFs MAC addresses */
6475 int rar_entries = hw->mac.rar_entry_count -
6476 adapter->vfs_allocated_count;
6479 for (i = 0; i < rar_entries; i++) {
6480 /* do not count default entries */
6481 if (adapter->mac_table[i].state & IGB_MAC_STATE_DEFAULT)
6484 /* do not count "in use" entries for different queues */
6485 if ((adapter->mac_table[i].state & IGB_MAC_STATE_IN_USE) &&
6486 (adapter->mac_table[i].queue != queue))
6495 /* Set default MAC address for the PF in the first RAR entry */
6496 static void igb_set_default_mac_filter(struct igb_adapter *adapter)
6498 struct igb_mac_addr *mac_table = &adapter->mac_table[0];
6500 ether_addr_copy(mac_table->addr, adapter->hw.mac.addr);
6501 mac_table->queue = adapter->vfs_allocated_count;
6502 mac_table->state = IGB_MAC_STATE_DEFAULT | IGB_MAC_STATE_IN_USE;
6504 igb_rar_set_index(adapter, 0);
6507 static int igb_add_mac_filter(struct igb_adapter *adapter, const u8 *addr,
6510 struct e1000_hw *hw = &adapter->hw;
6511 int rar_entries = hw->mac.rar_entry_count -
6512 adapter->vfs_allocated_count;
6515 if (is_zero_ether_addr(addr))
6518 /* Search for the first empty entry in the MAC table.
6519 * Do not touch entries at the end of the table reserved for the VF MAC
6522 for (i = 0; i < rar_entries; i++) {
6523 if (adapter->mac_table[i].state & IGB_MAC_STATE_IN_USE)
6526 ether_addr_copy(adapter->mac_table[i].addr, addr);
6527 adapter->mac_table[i].queue = queue;
6528 adapter->mac_table[i].state |= IGB_MAC_STATE_IN_USE;
6530 igb_rar_set_index(adapter, i);
6537 static int igb_del_mac_filter(struct igb_adapter *adapter, const u8 *addr,
6540 struct e1000_hw *hw = &adapter->hw;
6541 int rar_entries = hw->mac.rar_entry_count -
6542 adapter->vfs_allocated_count;
6545 if (is_zero_ether_addr(addr))
6548 /* Search for matching entry in the MAC table based on given address
6549 * and queue. Do not touch entries at the end of the table reserved
6550 * for the VF MAC addresses.
6552 for (i = 0; i < rar_entries; i++) {
6553 if (!(adapter->mac_table[i].state & IGB_MAC_STATE_IN_USE))
6555 if (adapter->mac_table[i].queue != queue)
6557 if (!ether_addr_equal(adapter->mac_table[i].addr, addr))
6560 adapter->mac_table[i].state &= ~IGB_MAC_STATE_IN_USE;
6561 memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
6562 adapter->mac_table[i].queue = 0;
6564 igb_rar_set_index(adapter, i);
6571 static int igb_uc_sync(struct net_device *netdev, const unsigned char *addr)
6573 struct igb_adapter *adapter = netdev_priv(netdev);
6576 ret = igb_add_mac_filter(adapter, addr, adapter->vfs_allocated_count);
6578 return min_t(int, ret, 0);
6581 static int igb_uc_unsync(struct net_device *netdev, const unsigned char *addr)
6583 struct igb_adapter *adapter = netdev_priv(netdev);
6585 igb_del_mac_filter(adapter, addr, adapter->vfs_allocated_count);
6590 static int igb_set_vf_mac_filter(struct igb_adapter *adapter, const int vf,
6591 const u32 info, const u8 *addr)
6593 struct pci_dev *pdev = adapter->pdev;
6594 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6595 struct list_head *pos;
6596 struct vf_mac_filter *entry = NULL;
6600 case E1000_VF_MAC_FILTER_CLR:
6601 /* remove all unicast MAC filters related to the current VF */
6602 list_for_each(pos, &adapter->vf_macs.l) {
6603 entry = list_entry(pos, struct vf_mac_filter, l);
6604 if (entry->vf == vf) {
6607 igb_del_mac_filter(adapter, entry->vf_mac, vf);
6611 case E1000_VF_MAC_FILTER_ADD:
6612 if (vf_data->flags & IGB_VF_FLAG_PF_SET_MAC) {
6613 dev_warn(&pdev->dev,
6614 "VF %d requested MAC filter but is administratively denied\n",
6619 if (!is_valid_ether_addr(addr)) {
6620 dev_warn(&pdev->dev,
6621 "VF %d attempted to set invalid MAC filter\n",
6626 /* try to find empty slot in the list */
6627 list_for_each(pos, &adapter->vf_macs.l) {
6628 entry = list_entry(pos, struct vf_mac_filter, l);
6633 if (entry && entry->free) {
6634 entry->free = false;
6636 ether_addr_copy(entry->vf_mac, addr);
6638 ret = igb_add_mac_filter(adapter, addr, vf);
6639 ret = min_t(int, ret, 0);
6645 dev_warn(&pdev->dev,
6646 "VF %d has requested MAC filter but there is no space for it\n",
6657 static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf)
6659 struct pci_dev *pdev = adapter->pdev;
6660 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6661 u32 info = msg[0] & E1000_VT_MSGINFO_MASK;
6663 /* The VF MAC Address is stored in a packed array of bytes
6664 * starting at the second 32 bit word of the msg array
6666 unsigned char *addr = (unsigned char *)&msg[1];
6670 if (vf_data->flags & IGB_VF_FLAG_PF_SET_MAC) {
6671 dev_warn(&pdev->dev,
6672 "VF %d attempted to override administratively set MAC address\nReload the VF driver to resume operations\n",
6677 if (!is_valid_ether_addr(addr)) {
6678 dev_warn(&pdev->dev,
6679 "VF %d attempted to set invalid MAC\n",
6684 ret = igb_set_vf_mac(adapter, vf, addr);
6686 ret = igb_set_vf_mac_filter(adapter, vf, info, addr);
6692 static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf)
6694 struct e1000_hw *hw = &adapter->hw;
6695 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6696 u32 msg = E1000_VT_MSGTYPE_NACK;
6698 /* if device isn't clear to send it shouldn't be reading either */
6699 if (!(vf_data->flags & IGB_VF_FLAG_CTS) &&
6700 time_after(jiffies, vf_data->last_nack + (2 * HZ))) {
6701 igb_write_mbx(hw, &msg, 1, vf);
6702 vf_data->last_nack = jiffies;
6706 static void igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf)
6708 struct pci_dev *pdev = adapter->pdev;
6709 u32 msgbuf[E1000_VFMAILBOX_SIZE];
6710 struct e1000_hw *hw = &adapter->hw;
6711 struct vf_data_storage *vf_data = &adapter->vf_data[vf];
6714 retval = igb_read_mbx(hw, msgbuf, E1000_VFMAILBOX_SIZE, vf, false);
6717 /* if receive failed revoke VF CTS stats and restart init */
6718 dev_err(&pdev->dev, "Error receiving message from VF\n");
6719 vf_data->flags &= ~IGB_VF_FLAG_CTS;
6720 if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
6725 /* this is a message we already processed, do nothing */
6726 if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK))
6729 /* until the vf completes a reset it should not be
6730 * allowed to start any configuration.
6732 if (msgbuf[0] == E1000_VF_RESET) {
6733 /* unlocks mailbox */
6734 igb_vf_reset_msg(adapter, vf);
6738 if (!(vf_data->flags & IGB_VF_FLAG_CTS)) {
6739 if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
6745 switch ((msgbuf[0] & 0xFFFF)) {
6746 case E1000_VF_SET_MAC_ADDR:
6747 retval = igb_set_vf_mac_addr(adapter, msgbuf, vf);
6749 case E1000_VF_SET_PROMISC:
6750 retval = igb_set_vf_promisc(adapter, msgbuf, vf);
6752 case E1000_VF_SET_MULTICAST:
6753 retval = igb_set_vf_multicasts(adapter, msgbuf, vf);
6755 case E1000_VF_SET_LPE:
6756 retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf);
6758 case E1000_VF_SET_VLAN:
6760 if (vf_data->pf_vlan)
6761 dev_warn(&pdev->dev,
6762 "VF %d attempted to override administratively set VLAN tag\nReload the VF driver to resume operations\n",
6765 retval = igb_set_vf_vlan_msg(adapter, msgbuf, vf);
6768 dev_err(&pdev->dev, "Unhandled Msg %08x\n", msgbuf[0]);
6773 msgbuf[0] |= E1000_VT_MSGTYPE_CTS;
6775 /* notify the VF of the results of what it sent us */
6777 msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
6779 msgbuf[0] |= E1000_VT_MSGTYPE_ACK;
6781 /* unlocks mailbox */
6782 igb_write_mbx(hw, msgbuf, 1, vf);
6786 igb_unlock_mbx(hw, vf);
6789 static void igb_msg_task(struct igb_adapter *adapter)
6791 struct e1000_hw *hw = &adapter->hw;
6792 unsigned long flags;
6795 spin_lock_irqsave(&adapter->vfs_lock, flags);
6796 for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
6797 /* process any reset requests */
6798 if (!igb_check_for_rst(hw, vf))
6799 igb_vf_reset_event(adapter, vf);
6801 /* process any messages pending */
6802 if (!igb_check_for_msg(hw, vf))
6803 igb_rcv_msg_from_vf(adapter, vf);
6805 /* process any acks */
6806 if (!igb_check_for_ack(hw, vf))
6807 igb_rcv_ack_from_vf(adapter, vf);
6809 spin_unlock_irqrestore(&adapter->vfs_lock, flags);
6813 * igb_set_uta - Set unicast filter table address
6814 * @adapter: board private structure
6815 * @set: boolean indicating if we are setting or clearing bits
6817 * The unicast table address is a register array of 32-bit registers.
6818 * The table is meant to be used in a way similar to how the MTA is used
6819 * however due to certain limitations in the hardware it is necessary to
6820 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
6821 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
6823 static void igb_set_uta(struct igb_adapter *adapter, bool set)
6825 struct e1000_hw *hw = &adapter->hw;
6826 u32 uta = set ? ~0 : 0;
6829 /* we only need to do this if VMDq is enabled */
6830 if (!adapter->vfs_allocated_count)
6833 for (i = hw->mac.uta_reg_count; i--;)
6834 array_wr32(E1000_UTA, i, uta);
6838 * igb_intr_msi - Interrupt Handler
6839 * @irq: interrupt number
6840 * @data: pointer to a network interface device structure
6842 static irqreturn_t igb_intr_msi(int irq, void *data)
6844 struct igb_adapter *adapter = data;
6845 struct igb_q_vector *q_vector = adapter->q_vector[0];
6846 struct e1000_hw *hw = &adapter->hw;
6847 /* read ICR disables interrupts using IAM */
6848 u32 icr = rd32(E1000_ICR);
6850 igb_write_itr(q_vector);
6852 if (icr & E1000_ICR_DRSTA)
6853 schedule_work(&adapter->reset_task);
6855 if (icr & E1000_ICR_DOUTSYNC) {
6856 /* HW is reporting DMA is out of sync */
6857 adapter->stats.doosync++;
6860 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
6861 hw->mac.get_link_status = 1;
6862 if (!test_bit(__IGB_DOWN, &adapter->state))
6863 mod_timer(&adapter->watchdog_timer, jiffies + 1);
6866 if (icr & E1000_ICR_TS)
6867 igb_tsync_interrupt(adapter);
6869 napi_schedule(&q_vector->napi);
6875 * igb_intr - Legacy Interrupt Handler
6876 * @irq: interrupt number
6877 * @data: pointer to a network interface device structure
6879 static irqreturn_t igb_intr(int irq, void *data)
6881 struct igb_adapter *adapter = data;
6882 struct igb_q_vector *q_vector = adapter->q_vector[0];
6883 struct e1000_hw *hw = &adapter->hw;
6884 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
6885 * need for the IMC write
6887 u32 icr = rd32(E1000_ICR);
6889 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
6890 * not set, then the adapter didn't send an interrupt
6892 if (!(icr & E1000_ICR_INT_ASSERTED))
6895 igb_write_itr(q_vector);
6897 if (icr & E1000_ICR_DRSTA)
6898 schedule_work(&adapter->reset_task);
6900 if (icr & E1000_ICR_DOUTSYNC) {
6901 /* HW is reporting DMA is out of sync */
6902 adapter->stats.doosync++;
6905 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
6906 hw->mac.get_link_status = 1;
6907 /* guard against interrupt when we're going down */
6908 if (!test_bit(__IGB_DOWN, &adapter->state))
6909 mod_timer(&adapter->watchdog_timer, jiffies + 1);
6912 if (icr & E1000_ICR_TS)
6913 igb_tsync_interrupt(adapter);
6915 napi_schedule(&q_vector->napi);
6920 static void igb_ring_irq_enable(struct igb_q_vector *q_vector)
6922 struct igb_adapter *adapter = q_vector->adapter;
6923 struct e1000_hw *hw = &adapter->hw;
6925 if ((q_vector->rx.ring && (adapter->rx_itr_setting & 3)) ||
6926 (!q_vector->rx.ring && (adapter->tx_itr_setting & 3))) {
6927 if ((adapter->num_q_vectors == 1) && !adapter->vf_data)
6928 igb_set_itr(q_vector);
6930 igb_update_ring_itr(q_vector);
6933 if (!test_bit(__IGB_DOWN, &adapter->state)) {
6934 if (adapter->flags & IGB_FLAG_HAS_MSIX)
6935 wr32(E1000_EIMS, q_vector->eims_value);
6937 igb_irq_enable(adapter);
6942 * igb_poll - NAPI Rx polling callback
6943 * @napi: napi polling structure
6944 * @budget: count of how many packets we should handle
6946 static int igb_poll(struct napi_struct *napi, int budget)
6948 struct igb_q_vector *q_vector = container_of(napi,
6949 struct igb_q_vector,
6951 bool clean_complete = true;
6954 #ifdef CONFIG_IGB_DCA
6955 if (q_vector->adapter->flags & IGB_FLAG_DCA_ENABLED)
6956 igb_update_dca(q_vector);
6958 if (q_vector->tx.ring)
6959 clean_complete = igb_clean_tx_irq(q_vector, budget);
6961 if (q_vector->rx.ring) {
6962 int cleaned = igb_clean_rx_irq(q_vector, budget);
6964 work_done += cleaned;
6965 if (cleaned >= budget)
6966 clean_complete = false;
6969 /* If all work not completed, return budget and keep polling */
6970 if (!clean_complete)
6973 /* If not enough Rx work done, exit the polling mode */
6974 napi_complete_done(napi, work_done);
6975 igb_ring_irq_enable(q_vector);
6981 * igb_clean_tx_irq - Reclaim resources after transmit completes
6982 * @q_vector: pointer to q_vector containing needed info
6983 * @napi_budget: Used to determine if we are in netpoll
6985 * returns true if ring is completely cleaned
6987 static bool igb_clean_tx_irq(struct igb_q_vector *q_vector, int napi_budget)
6989 struct igb_adapter *adapter = q_vector->adapter;
6990 struct igb_ring *tx_ring = q_vector->tx.ring;
6991 struct igb_tx_buffer *tx_buffer;
6992 union e1000_adv_tx_desc *tx_desc;
6993 unsigned int total_bytes = 0, total_packets = 0;
6994 unsigned int budget = q_vector->tx.work_limit;
6995 unsigned int i = tx_ring->next_to_clean;
6997 if (test_bit(__IGB_DOWN, &adapter->state))
7000 tx_buffer = &tx_ring->tx_buffer_info[i];
7001 tx_desc = IGB_TX_DESC(tx_ring, i);
7002 i -= tx_ring->count;
7005 union e1000_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
7007 /* if next_to_watch is not set then there is no work pending */
7011 /* prevent any other reads prior to eop_desc */
7014 /* if DD is not set pending work has not been completed */
7015 if (!(eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)))
7018 /* clear next_to_watch to prevent false hangs */
7019 tx_buffer->next_to_watch = NULL;
7021 /* update the statistics for this packet */
7022 total_bytes += tx_buffer->bytecount;
7023 total_packets += tx_buffer->gso_segs;
7026 napi_consume_skb(tx_buffer->skb, napi_budget);
7028 /* unmap skb header data */
7029 dma_unmap_single(tx_ring->dev,
7030 dma_unmap_addr(tx_buffer, dma),
7031 dma_unmap_len(tx_buffer, len),
7034 /* clear tx_buffer data */
7035 dma_unmap_len_set(tx_buffer, len, 0);
7037 /* clear last DMA location and unmap remaining buffers */
7038 while (tx_desc != eop_desc) {
7043 i -= tx_ring->count;
7044 tx_buffer = tx_ring->tx_buffer_info;
7045 tx_desc = IGB_TX_DESC(tx_ring, 0);
7048 /* unmap any remaining paged data */
7049 if (dma_unmap_len(tx_buffer, len)) {
7050 dma_unmap_page(tx_ring->dev,
7051 dma_unmap_addr(tx_buffer, dma),
7052 dma_unmap_len(tx_buffer, len),
7054 dma_unmap_len_set(tx_buffer, len, 0);
7058 /* move us one more past the eop_desc for start of next pkt */
7063 i -= tx_ring->count;
7064 tx_buffer = tx_ring->tx_buffer_info;
7065 tx_desc = IGB_TX_DESC(tx_ring, 0);
7068 /* issue prefetch for next Tx descriptor */
7071 /* update budget accounting */
7073 } while (likely(budget));
7075 netdev_tx_completed_queue(txring_txq(tx_ring),
7076 total_packets, total_bytes);
7077 i += tx_ring->count;
7078 tx_ring->next_to_clean = i;
7079 u64_stats_update_begin(&tx_ring->tx_syncp);
7080 tx_ring->tx_stats.bytes += total_bytes;
7081 tx_ring->tx_stats.packets += total_packets;
7082 u64_stats_update_end(&tx_ring->tx_syncp);
7083 q_vector->tx.total_bytes += total_bytes;
7084 q_vector->tx.total_packets += total_packets;
7086 if (test_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags)) {
7087 struct e1000_hw *hw = &adapter->hw;
7089 /* Detect a transmit hang in hardware, this serializes the
7090 * check with the clearing of time_stamp and movement of i
7092 clear_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
7093 if (tx_buffer->next_to_watch &&
7094 time_after(jiffies, tx_buffer->time_stamp +
7095 (adapter->tx_timeout_factor * HZ)) &&
7096 !(rd32(E1000_STATUS) & E1000_STATUS_TXOFF)) {
7098 /* detected Tx unit hang */
7099 dev_err(tx_ring->dev,
7100 "Detected Tx Unit Hang\n"
7104 " next_to_use <%x>\n"
7105 " next_to_clean <%x>\n"
7106 "buffer_info[next_to_clean]\n"
7107 " time_stamp <%lx>\n"
7108 " next_to_watch <%p>\n"
7110 " desc.status <%x>\n",
7111 tx_ring->queue_index,
7112 rd32(E1000_TDH(tx_ring->reg_idx)),
7113 readl(tx_ring->tail),
7114 tx_ring->next_to_use,
7115 tx_ring->next_to_clean,
7116 tx_buffer->time_stamp,
7117 tx_buffer->next_to_watch,
7119 tx_buffer->next_to_watch->wb.status);
7120 netif_stop_subqueue(tx_ring->netdev,
7121 tx_ring->queue_index);
7123 /* we are about to reset, no point in enabling stuff */
7128 #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
7129 if (unlikely(total_packets &&
7130 netif_carrier_ok(tx_ring->netdev) &&
7131 igb_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD)) {
7132 /* Make sure that anybody stopping the queue after this
7133 * sees the new next_to_clean.
7136 if (__netif_subqueue_stopped(tx_ring->netdev,
7137 tx_ring->queue_index) &&
7138 !(test_bit(__IGB_DOWN, &adapter->state))) {
7139 netif_wake_subqueue(tx_ring->netdev,
7140 tx_ring->queue_index);
7142 u64_stats_update_begin(&tx_ring->tx_syncp);
7143 tx_ring->tx_stats.restart_queue++;
7144 u64_stats_update_end(&tx_ring->tx_syncp);
7152 * igb_reuse_rx_page - page flip buffer and store it back on the ring
7153 * @rx_ring: rx descriptor ring to store buffers on
7154 * @old_buff: donor buffer to have page reused
7156 * Synchronizes page for reuse by the adapter
7158 static void igb_reuse_rx_page(struct igb_ring *rx_ring,
7159 struct igb_rx_buffer *old_buff)
7161 struct igb_rx_buffer *new_buff;
7162 u16 nta = rx_ring->next_to_alloc;
7164 new_buff = &rx_ring->rx_buffer_info[nta];
7166 /* update, and store next to alloc */
7168 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
7170 /* Transfer page from old buffer to new buffer.
7171 * Move each member individually to avoid possible store
7172 * forwarding stalls.
7174 new_buff->dma = old_buff->dma;
7175 new_buff->page = old_buff->page;
7176 new_buff->page_offset = old_buff->page_offset;
7177 new_buff->pagecnt_bias = old_buff->pagecnt_bias;
7180 static inline bool igb_page_is_reserved(struct page *page)
7182 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
7185 static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer)
7187 unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
7188 struct page *page = rx_buffer->page;
7190 /* avoid re-using remote pages */
7191 if (unlikely(igb_page_is_reserved(page)))
7194 #if (PAGE_SIZE < 8192)
7195 /* if we are only owner of page we can reuse it */
7196 if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
7199 #define IGB_LAST_OFFSET \
7200 (SKB_WITH_OVERHEAD(PAGE_SIZE) - IGB_RXBUFFER_2048)
7202 if (rx_buffer->page_offset > IGB_LAST_OFFSET)
7206 /* If we have drained the page fragment pool we need to update
7207 * the pagecnt_bias and page count so that we fully restock the
7208 * number of references the driver holds.
7210 if (unlikely(!pagecnt_bias)) {
7211 page_ref_add(page, USHRT_MAX);
7212 rx_buffer->pagecnt_bias = USHRT_MAX;
7219 * igb_add_rx_frag - Add contents of Rx buffer to sk_buff
7220 * @rx_ring: rx descriptor ring to transact packets on
7221 * @rx_buffer: buffer containing page to add
7222 * @skb: sk_buff to place the data into
7223 * @size: size of buffer to be added
7225 * This function will add the data contained in rx_buffer->page to the skb.
7227 static void igb_add_rx_frag(struct igb_ring *rx_ring,
7228 struct igb_rx_buffer *rx_buffer,
7229 struct sk_buff *skb,
7232 #if (PAGE_SIZE < 8192)
7233 unsigned int truesize = igb_rx_pg_size(rx_ring) / 2;
7235 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
7236 SKB_DATA_ALIGN(IGB_SKB_PAD + size) :
7237 SKB_DATA_ALIGN(size);
7239 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
7240 rx_buffer->page_offset, size, truesize);
7241 #if (PAGE_SIZE < 8192)
7242 rx_buffer->page_offset ^= truesize;
7244 rx_buffer->page_offset += truesize;
7248 static struct sk_buff *igb_construct_skb(struct igb_ring *rx_ring,
7249 struct igb_rx_buffer *rx_buffer,
7250 union e1000_adv_rx_desc *rx_desc,
7253 void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
7254 #if (PAGE_SIZE < 8192)
7255 unsigned int truesize = igb_rx_pg_size(rx_ring) / 2;
7257 unsigned int truesize = SKB_DATA_ALIGN(size);
7259 unsigned int headlen;
7260 struct sk_buff *skb;
7262 /* prefetch first cache line of first page */
7264 #if L1_CACHE_BYTES < 128
7265 prefetch(va + L1_CACHE_BYTES);
7268 /* allocate a skb to store the frags */
7269 skb = napi_alloc_skb(&rx_ring->q_vector->napi, IGB_RX_HDR_LEN);
7273 if (unlikely(igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))) {
7274 igb_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
7275 va += IGB_TS_HDR_LEN;
7276 size -= IGB_TS_HDR_LEN;
7279 /* Determine available headroom for copy */
7281 if (headlen > IGB_RX_HDR_LEN)
7282 headlen = eth_get_headlen(va, IGB_RX_HDR_LEN);
7284 /* align pull length to size of long to optimize memcpy performance */
7285 memcpy(__skb_put(skb, headlen), va, ALIGN(headlen, sizeof(long)));
7287 /* update all of the pointers */
7290 skb_add_rx_frag(skb, 0, rx_buffer->page,
7291 (va + headlen) - page_address(rx_buffer->page),
7293 #if (PAGE_SIZE < 8192)
7294 rx_buffer->page_offset ^= truesize;
7296 rx_buffer->page_offset += truesize;
7299 rx_buffer->pagecnt_bias++;
7305 static struct sk_buff *igb_build_skb(struct igb_ring *rx_ring,
7306 struct igb_rx_buffer *rx_buffer,
7307 union e1000_adv_rx_desc *rx_desc,
7310 void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
7311 #if (PAGE_SIZE < 8192)
7312 unsigned int truesize = igb_rx_pg_size(rx_ring) / 2;
7314 unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
7315 SKB_DATA_ALIGN(IGB_SKB_PAD + size);
7317 struct sk_buff *skb;
7319 /* prefetch first cache line of first page */
7321 #if L1_CACHE_BYTES < 128
7322 prefetch(va + L1_CACHE_BYTES);
7325 /* build an skb around the page buffer */
7326 skb = build_skb(va - IGB_SKB_PAD, truesize);
7330 /* update pointers within the skb to store the data */
7331 skb_reserve(skb, IGB_SKB_PAD);
7332 __skb_put(skb, size);
7334 /* pull timestamp out of packet data */
7335 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
7336 igb_ptp_rx_pktstamp(rx_ring->q_vector, skb->data, skb);
7337 __skb_pull(skb, IGB_TS_HDR_LEN);
7340 /* update buffer offset */
7341 #if (PAGE_SIZE < 8192)
7342 rx_buffer->page_offset ^= truesize;
7344 rx_buffer->page_offset += truesize;
7350 static inline void igb_rx_checksum(struct igb_ring *ring,
7351 union e1000_adv_rx_desc *rx_desc,
7352 struct sk_buff *skb)
7354 skb_checksum_none_assert(skb);
7356 /* Ignore Checksum bit is set */
7357 if (igb_test_staterr(rx_desc, E1000_RXD_STAT_IXSM))
7360 /* Rx checksum disabled via ethtool */
7361 if (!(ring->netdev->features & NETIF_F_RXCSUM))
7364 /* TCP/UDP checksum error bit is set */
7365 if (igb_test_staterr(rx_desc,
7366 E1000_RXDEXT_STATERR_TCPE |
7367 E1000_RXDEXT_STATERR_IPE)) {
7368 /* work around errata with sctp packets where the TCPE aka
7369 * L4E bit is set incorrectly on 64 byte (60 byte w/o crc)
7370 * packets, (aka let the stack check the crc32c)
7372 if (!((skb->len == 60) &&
7373 test_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags))) {
7374 u64_stats_update_begin(&ring->rx_syncp);
7375 ring->rx_stats.csum_err++;
7376 u64_stats_update_end(&ring->rx_syncp);
7378 /* let the stack verify checksum errors */
7381 /* It must be a TCP or UDP packet with a valid checksum */
7382 if (igb_test_staterr(rx_desc, E1000_RXD_STAT_TCPCS |
7383 E1000_RXD_STAT_UDPCS))
7384 skb->ip_summed = CHECKSUM_UNNECESSARY;
7386 dev_dbg(ring->dev, "cksum success: bits %08X\n",
7387 le32_to_cpu(rx_desc->wb.upper.status_error));
7390 static inline void igb_rx_hash(struct igb_ring *ring,
7391 union e1000_adv_rx_desc *rx_desc,
7392 struct sk_buff *skb)
7394 if (ring->netdev->features & NETIF_F_RXHASH)
7396 le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
7401 * igb_is_non_eop - process handling of non-EOP buffers
7402 * @rx_ring: Rx ring being processed
7403 * @rx_desc: Rx descriptor for current buffer
7404 * @skb: current socket buffer containing buffer in progress
7406 * This function updates next to clean. If the buffer is an EOP buffer
7407 * this function exits returning false, otherwise it will place the
7408 * sk_buff in the next buffer to be chained and return true indicating
7409 * that this is in fact a non-EOP buffer.
7411 static bool igb_is_non_eop(struct igb_ring *rx_ring,
7412 union e1000_adv_rx_desc *rx_desc)
7414 u32 ntc = rx_ring->next_to_clean + 1;
7416 /* fetch, update, and store next to clean */
7417 ntc = (ntc < rx_ring->count) ? ntc : 0;
7418 rx_ring->next_to_clean = ntc;
7420 prefetch(IGB_RX_DESC(rx_ring, ntc));
7422 if (likely(igb_test_staterr(rx_desc, E1000_RXD_STAT_EOP)))
7429 * igb_cleanup_headers - Correct corrupted or empty headers
7430 * @rx_ring: rx descriptor ring packet is being transacted on
7431 * @rx_desc: pointer to the EOP Rx descriptor
7432 * @skb: pointer to current skb being fixed
7434 * Address the case where we are pulling data in on pages only
7435 * and as such no data is present in the skb header.
7437 * In addition if skb is not at least 60 bytes we need to pad it so that
7438 * it is large enough to qualify as a valid Ethernet frame.
7440 * Returns true if an error was encountered and skb was freed.
7442 static bool igb_cleanup_headers(struct igb_ring *rx_ring,
7443 union e1000_adv_rx_desc *rx_desc,
7444 struct sk_buff *skb)
7446 if (unlikely((igb_test_staterr(rx_desc,
7447 E1000_RXDEXT_ERR_FRAME_ERR_MASK)))) {
7448 struct net_device *netdev = rx_ring->netdev;
7449 if (!(netdev->features & NETIF_F_RXALL)) {
7450 dev_kfree_skb_any(skb);
7455 /* if eth_skb_pad returns an error the skb was freed */
7456 if (eth_skb_pad(skb))
7463 * igb_process_skb_fields - Populate skb header fields from Rx descriptor
7464 * @rx_ring: rx descriptor ring packet is being transacted on
7465 * @rx_desc: pointer to the EOP Rx descriptor
7466 * @skb: pointer to current skb being populated
7468 * This function checks the ring, descriptor, and packet information in
7469 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
7470 * other fields within the skb.
7472 static void igb_process_skb_fields(struct igb_ring *rx_ring,
7473 union e1000_adv_rx_desc *rx_desc,
7474 struct sk_buff *skb)
7476 struct net_device *dev = rx_ring->netdev;
7478 igb_rx_hash(rx_ring, rx_desc, skb);
7480 igb_rx_checksum(rx_ring, rx_desc, skb);
7482 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TS) &&
7483 !igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))
7484 igb_ptp_rx_rgtstamp(rx_ring->q_vector, skb);
7486 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
7487 igb_test_staterr(rx_desc, E1000_RXD_STAT_VP)) {
7490 if (igb_test_staterr(rx_desc, E1000_RXDEXT_STATERR_LB) &&
7491 test_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &rx_ring->flags))
7492 vid = be16_to_cpu(rx_desc->wb.upper.vlan);
7494 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
7496 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
7499 skb_record_rx_queue(skb, rx_ring->queue_index);
7501 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
7504 static struct igb_rx_buffer *igb_get_rx_buffer(struct igb_ring *rx_ring,
7505 const unsigned int size)
7507 struct igb_rx_buffer *rx_buffer;
7509 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
7510 prefetchw(rx_buffer->page);
7512 /* we are reusing so sync this buffer for CPU use */
7513 dma_sync_single_range_for_cpu(rx_ring->dev,
7515 rx_buffer->page_offset,
7519 rx_buffer->pagecnt_bias--;
7524 static void igb_put_rx_buffer(struct igb_ring *rx_ring,
7525 struct igb_rx_buffer *rx_buffer)
7527 if (igb_can_reuse_rx_page(rx_buffer)) {
7528 /* hand second half of page back to the ring */
7529 igb_reuse_rx_page(rx_ring, rx_buffer);
7531 /* We are not reusing the buffer so unmap it and free
7532 * any references we are holding to it
7534 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
7535 igb_rx_pg_size(rx_ring), DMA_FROM_DEVICE,
7537 __page_frag_cache_drain(rx_buffer->page,
7538 rx_buffer->pagecnt_bias);
7541 /* clear contents of rx_buffer */
7542 rx_buffer->page = NULL;
7545 static int igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)
7547 struct igb_ring *rx_ring = q_vector->rx.ring;
7548 struct sk_buff *skb = rx_ring->skb;
7549 unsigned int total_bytes = 0, total_packets = 0;
7550 u16 cleaned_count = igb_desc_unused(rx_ring);
7552 while (likely(total_packets < budget)) {
7553 union e1000_adv_rx_desc *rx_desc;
7554 struct igb_rx_buffer *rx_buffer;
7557 /* return some buffers to hardware, one at a time is too slow */
7558 if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
7559 igb_alloc_rx_buffers(rx_ring, cleaned_count);
7563 rx_desc = IGB_RX_DESC(rx_ring, rx_ring->next_to_clean);
7564 size = le16_to_cpu(rx_desc->wb.upper.length);
7568 /* This memory barrier is needed to keep us from reading
7569 * any other fields out of the rx_desc until we know the
7570 * descriptor has been written back
7574 rx_buffer = igb_get_rx_buffer(rx_ring, size);
7576 /* retrieve a buffer from the ring */
7578 igb_add_rx_frag(rx_ring, rx_buffer, skb, size);
7579 else if (ring_uses_build_skb(rx_ring))
7580 skb = igb_build_skb(rx_ring, rx_buffer, rx_desc, size);
7582 skb = igb_construct_skb(rx_ring, rx_buffer,
7585 /* exit if we failed to retrieve a buffer */
7587 rx_ring->rx_stats.alloc_failed++;
7588 rx_buffer->pagecnt_bias++;
7592 igb_put_rx_buffer(rx_ring, rx_buffer);
7595 /* fetch next buffer in frame if non-eop */
7596 if (igb_is_non_eop(rx_ring, rx_desc))
7599 /* verify the packet layout is correct */
7600 if (igb_cleanup_headers(rx_ring, rx_desc, skb)) {
7605 /* probably a little skewed due to removing CRC */
7606 total_bytes += skb->len;
7608 /* populate checksum, timestamp, VLAN, and protocol */
7609 igb_process_skb_fields(rx_ring, rx_desc, skb);
7611 napi_gro_receive(&q_vector->napi, skb);
7613 /* reset skb pointer */
7616 /* update budget accounting */
7620 /* place incomplete frames back on ring for completion */
7623 u64_stats_update_begin(&rx_ring->rx_syncp);
7624 rx_ring->rx_stats.packets += total_packets;
7625 rx_ring->rx_stats.bytes += total_bytes;
7626 u64_stats_update_end(&rx_ring->rx_syncp);
7627 q_vector->rx.total_packets += total_packets;
7628 q_vector->rx.total_bytes += total_bytes;
7631 igb_alloc_rx_buffers(rx_ring, cleaned_count);
7633 return total_packets;
7636 static inline unsigned int igb_rx_offset(struct igb_ring *rx_ring)
7638 return ring_uses_build_skb(rx_ring) ? IGB_SKB_PAD : 0;
7641 static bool igb_alloc_mapped_page(struct igb_ring *rx_ring,
7642 struct igb_rx_buffer *bi)
7644 struct page *page = bi->page;
7647 /* since we are recycling buffers we should seldom need to alloc */
7651 /* alloc new page for storage */
7652 page = dev_alloc_pages(igb_rx_pg_order(rx_ring));
7653 if (unlikely(!page)) {
7654 rx_ring->rx_stats.alloc_failed++;
7658 /* map page for use */
7659 dma = dma_map_page_attrs(rx_ring->dev, page, 0,
7660 igb_rx_pg_size(rx_ring),
7664 /* if mapping failed free memory back to system since
7665 * there isn't much point in holding memory we can't use
7667 if (dma_mapping_error(rx_ring->dev, dma)) {
7668 __free_pages(page, igb_rx_pg_order(rx_ring));
7670 rx_ring->rx_stats.alloc_failed++;
7676 bi->page_offset = igb_rx_offset(rx_ring);
7677 bi->pagecnt_bias = 1;
7683 * igb_alloc_rx_buffers - Replace used receive buffers; packet split
7684 * @adapter: address of board private structure
7686 void igb_alloc_rx_buffers(struct igb_ring *rx_ring, u16 cleaned_count)
7688 union e1000_adv_rx_desc *rx_desc;
7689 struct igb_rx_buffer *bi;
7690 u16 i = rx_ring->next_to_use;
7697 rx_desc = IGB_RX_DESC(rx_ring, i);
7698 bi = &rx_ring->rx_buffer_info[i];
7699 i -= rx_ring->count;
7701 bufsz = igb_rx_bufsz(rx_ring);
7704 if (!igb_alloc_mapped_page(rx_ring, bi))
7707 /* sync the buffer for use by the device */
7708 dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
7709 bi->page_offset, bufsz,
7712 /* Refresh the desc even if buffer_addrs didn't change
7713 * because each write-back erases this info.
7715 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
7721 rx_desc = IGB_RX_DESC(rx_ring, 0);
7722 bi = rx_ring->rx_buffer_info;
7723 i -= rx_ring->count;
7726 /* clear the length for the next_to_use descriptor */
7727 rx_desc->wb.upper.length = 0;
7730 } while (cleaned_count);
7732 i += rx_ring->count;
7734 if (rx_ring->next_to_use != i) {
7735 /* record the next descriptor to use */
7736 rx_ring->next_to_use = i;
7738 /* update next to alloc since we have filled the ring */
7739 rx_ring->next_to_alloc = i;
7741 /* Force memory writes to complete before letting h/w
7742 * know there are new descriptors to fetch. (Only
7743 * applicable for weak-ordered memory model archs,
7747 writel(i, rx_ring->tail);
7757 static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
7759 struct igb_adapter *adapter = netdev_priv(netdev);
7760 struct mii_ioctl_data *data = if_mii(ifr);
7762 if (adapter->hw.phy.media_type != e1000_media_type_copper)
7767 data->phy_id = adapter->hw.phy.addr;
7770 if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
7787 static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
7793 return igb_mii_ioctl(netdev, ifr, cmd);
7795 return igb_ptp_get_ts_config(netdev, ifr);
7797 return igb_ptp_set_ts_config(netdev, ifr);
7803 void igb_read_pci_cfg(struct e1000_hw *hw, u32 reg, u16 *value)
7805 struct igb_adapter *adapter = hw->back;
7807 pci_read_config_word(adapter->pdev, reg, value);
7810 void igb_write_pci_cfg(struct e1000_hw *hw, u32 reg, u16 *value)
7812 struct igb_adapter *adapter = hw->back;
7814 pci_write_config_word(adapter->pdev, reg, *value);
7817 s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
7819 struct igb_adapter *adapter = hw->back;
7821 if (pcie_capability_read_word(adapter->pdev, reg, value))
7822 return -E1000_ERR_CONFIG;
7827 s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
7829 struct igb_adapter *adapter = hw->back;
7831 if (pcie_capability_write_word(adapter->pdev, reg, *value))
7832 return -E1000_ERR_CONFIG;
7837 static void igb_vlan_mode(struct net_device *netdev, netdev_features_t features)
7839 struct igb_adapter *adapter = netdev_priv(netdev);
7840 struct e1000_hw *hw = &adapter->hw;
7842 bool enable = !!(features & NETIF_F_HW_VLAN_CTAG_RX);
7845 /* enable VLAN tag insert/strip */
7846 ctrl = rd32(E1000_CTRL);
7847 ctrl |= E1000_CTRL_VME;
7848 wr32(E1000_CTRL, ctrl);
7850 /* Disable CFI check */
7851 rctl = rd32(E1000_RCTL);
7852 rctl &= ~E1000_RCTL_CFIEN;
7853 wr32(E1000_RCTL, rctl);
7855 /* disable VLAN tag insert/strip */
7856 ctrl = rd32(E1000_CTRL);
7857 ctrl &= ~E1000_CTRL_VME;
7858 wr32(E1000_CTRL, ctrl);
7861 igb_set_vf_vlan_strip(adapter, adapter->vfs_allocated_count, enable);
7864 static int igb_vlan_rx_add_vid(struct net_device *netdev,
7865 __be16 proto, u16 vid)
7867 struct igb_adapter *adapter = netdev_priv(netdev);
7868 struct e1000_hw *hw = &adapter->hw;
7869 int pf_id = adapter->vfs_allocated_count;
7871 /* add the filter since PF can receive vlans w/o entry in vlvf */
7872 if (!vid || !(adapter->flags & IGB_FLAG_VLAN_PROMISC))
7873 igb_vfta_set(hw, vid, pf_id, true, !!vid);
7875 set_bit(vid, adapter->active_vlans);
7880 static int igb_vlan_rx_kill_vid(struct net_device *netdev,
7881 __be16 proto, u16 vid)
7883 struct igb_adapter *adapter = netdev_priv(netdev);
7884 int pf_id = adapter->vfs_allocated_count;
7885 struct e1000_hw *hw = &adapter->hw;
7887 /* remove VID from filter table */
7888 if (vid && !(adapter->flags & IGB_FLAG_VLAN_PROMISC))
7889 igb_vfta_set(hw, vid, pf_id, false, true);
7891 clear_bit(vid, adapter->active_vlans);
7896 static void igb_restore_vlan(struct igb_adapter *adapter)
7900 igb_vlan_mode(adapter->netdev, adapter->netdev->features);
7901 igb_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
7903 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
7904 igb_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
7907 int igb_set_spd_dplx(struct igb_adapter *adapter, u32 spd, u8 dplx)
7909 struct pci_dev *pdev = adapter->pdev;
7910 struct e1000_mac_info *mac = &adapter->hw.mac;
7914 /* Make sure dplx is at most 1 bit and lsb of speed is not set
7915 * for the switch() below to work
7917 if ((spd & 1) || (dplx & ~1))
7920 /* Fiber NIC's only allow 1000 gbps Full duplex
7921 * and 100Mbps Full duplex for 100baseFx sfp
7923 if (adapter->hw.phy.media_type == e1000_media_type_internal_serdes) {
7924 switch (spd + dplx) {
7925 case SPEED_10 + DUPLEX_HALF:
7926 case SPEED_10 + DUPLEX_FULL:
7927 case SPEED_100 + DUPLEX_HALF:
7934 switch (spd + dplx) {
7935 case SPEED_10 + DUPLEX_HALF:
7936 mac->forced_speed_duplex = ADVERTISE_10_HALF;
7938 case SPEED_10 + DUPLEX_FULL:
7939 mac->forced_speed_duplex = ADVERTISE_10_FULL;
7941 case SPEED_100 + DUPLEX_HALF:
7942 mac->forced_speed_duplex = ADVERTISE_100_HALF;
7944 case SPEED_100 + DUPLEX_FULL:
7945 mac->forced_speed_duplex = ADVERTISE_100_FULL;
7947 case SPEED_1000 + DUPLEX_FULL:
7949 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
7951 case SPEED_1000 + DUPLEX_HALF: /* not supported */
7956 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
7957 adapter->hw.phy.mdix = AUTO_ALL_MODES;
7962 dev_err(&pdev->dev, "Unsupported Speed/Duplex configuration\n");
7966 static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake,
7969 struct net_device *netdev = pci_get_drvdata(pdev);
7970 struct igb_adapter *adapter = netdev_priv(netdev);
7971 struct e1000_hw *hw = &adapter->hw;
7972 u32 ctrl, rctl, status;
7973 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
7977 netif_device_detach(netdev);
7979 if (netif_running(netdev))
7980 __igb_close(netdev, true);
7982 igb_ptp_suspend(adapter);
7984 igb_clear_interrupt_scheme(adapter);
7987 status = rd32(E1000_STATUS);
7988 if (status & E1000_STATUS_LU)
7989 wufc &= ~E1000_WUFC_LNKC;
7992 igb_setup_rctl(adapter);
7993 igb_set_rx_mode(netdev);
7995 /* turn on all-multi mode if wake on multicast is enabled */
7996 if (wufc & E1000_WUFC_MC) {
7997 rctl = rd32(E1000_RCTL);
7998 rctl |= E1000_RCTL_MPE;
7999 wr32(E1000_RCTL, rctl);
8002 ctrl = rd32(E1000_CTRL);
8003 ctrl |= E1000_CTRL_ADVD3WUC;
8004 wr32(E1000_CTRL, ctrl);
8006 /* Allow time for pending master requests to run */
8007 igb_disable_pcie_master(hw);
8009 wr32(E1000_WUC, E1000_WUC_PME_EN);
8010 wr32(E1000_WUFC, wufc);
8013 wr32(E1000_WUFC, 0);
8016 wake = wufc || adapter->en_mng_pt;
8018 igb_power_down_link(adapter);
8020 igb_power_up_link(adapter);
8023 *enable_wake = wake;
8025 /* Release control of h/w to f/w. If f/w is AMT enabled, this
8026 * would have already happened in close and is redundant.
8028 igb_release_hw_control(adapter);
8030 pci_disable_device(pdev);
8035 static void igb_deliver_wake_packet(struct net_device *netdev)
8037 struct igb_adapter *adapter = netdev_priv(netdev);
8038 struct e1000_hw *hw = &adapter->hw;
8039 struct sk_buff *skb;
8042 wupl = rd32(E1000_WUPL) & E1000_WUPL_MASK;
8044 /* WUPM stores only the first 128 bytes of the wake packet.
8045 * Read the packet only if we have the whole thing.
8047 if ((wupl == 0) || (wupl > E1000_WUPM_BYTES))
8050 skb = netdev_alloc_skb_ip_align(netdev, E1000_WUPM_BYTES);
8056 /* Ensure reads are 32-bit aligned */
8057 wupl = roundup(wupl, 4);
8059 memcpy_fromio(skb->data, hw->hw_addr + E1000_WUPM_REG(0), wupl);
8061 skb->protocol = eth_type_trans(skb, netdev);
8065 static int __maybe_unused igb_suspend(struct device *dev)
8067 return __igb_shutdown(to_pci_dev(dev), NULL, 0);
8070 static int __maybe_unused igb_resume(struct device *dev)
8072 struct pci_dev *pdev = to_pci_dev(dev);
8073 struct net_device *netdev = pci_get_drvdata(pdev);
8074 struct igb_adapter *adapter = netdev_priv(netdev);
8075 struct e1000_hw *hw = &adapter->hw;
8078 pci_set_power_state(pdev, PCI_D0);
8079 pci_restore_state(pdev);
8080 pci_save_state(pdev);
8082 if (!pci_device_is_present(pdev))
8084 err = pci_enable_device_mem(pdev);
8087 "igb: Cannot enable PCI device from suspend\n");
8090 pci_set_master(pdev);
8092 pci_enable_wake(pdev, PCI_D3hot, 0);
8093 pci_enable_wake(pdev, PCI_D3cold, 0);
8095 if (igb_init_interrupt_scheme(adapter, true)) {
8096 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
8102 /* let the f/w know that the h/w is now under the control of the
8105 igb_get_hw_control(adapter);
8107 val = rd32(E1000_WUS);
8108 if (val & WAKE_PKT_WUS)
8109 igb_deliver_wake_packet(netdev);
8111 wr32(E1000_WUS, ~0);
8114 if (!err && netif_running(netdev))
8115 err = __igb_open(netdev, true);
8118 netif_device_attach(netdev);
8124 static int __maybe_unused igb_runtime_idle(struct device *dev)
8126 struct pci_dev *pdev = to_pci_dev(dev);
8127 struct net_device *netdev = pci_get_drvdata(pdev);
8128 struct igb_adapter *adapter = netdev_priv(netdev);
8130 if (!igb_has_link(adapter))
8131 pm_schedule_suspend(dev, MSEC_PER_SEC * 5);
8136 static int __maybe_unused igb_runtime_suspend(struct device *dev)
8138 return __igb_shutdown(to_pci_dev(dev), NULL, 1);
8141 static int __maybe_unused igb_runtime_resume(struct device *dev)
8143 return igb_resume(dev);
8146 static void igb_shutdown(struct pci_dev *pdev)
8150 __igb_shutdown(pdev, &wake, 0);
8152 if (system_state == SYSTEM_POWER_OFF) {
8153 pci_wake_from_d3(pdev, wake);
8154 pci_set_power_state(pdev, PCI_D3hot);
8158 #ifdef CONFIG_PCI_IOV
8159 static int igb_sriov_reinit(struct pci_dev *dev)
8161 struct net_device *netdev = pci_get_drvdata(dev);
8162 struct igb_adapter *adapter = netdev_priv(netdev);
8163 struct pci_dev *pdev = adapter->pdev;
8167 if (netif_running(netdev))
8172 igb_clear_interrupt_scheme(adapter);
8174 igb_init_queue_configuration(adapter);
8176 if (igb_init_interrupt_scheme(adapter, true)) {
8178 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
8182 if (netif_running(netdev))
8190 static int igb_pci_disable_sriov(struct pci_dev *dev)
8192 int err = igb_disable_sriov(dev);
8195 err = igb_sriov_reinit(dev);
8200 static int igb_pci_enable_sriov(struct pci_dev *dev, int num_vfs)
8202 int err = igb_enable_sriov(dev, num_vfs);
8207 err = igb_sriov_reinit(dev);
8216 static int igb_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
8218 #ifdef CONFIG_PCI_IOV
8220 return igb_pci_disable_sriov(dev);
8222 return igb_pci_enable_sriov(dev, num_vfs);
8227 #ifdef CONFIG_NET_POLL_CONTROLLER
8228 /* Polling 'interrupt' - used by things like netconsole to send skbs
8229 * without having to re-enable interrupts. It's not called while
8230 * the interrupt routine is executing.
8232 static void igb_netpoll(struct net_device *netdev)
8234 struct igb_adapter *adapter = netdev_priv(netdev);
8235 struct e1000_hw *hw = &adapter->hw;
8236 struct igb_q_vector *q_vector;
8239 for (i = 0; i < adapter->num_q_vectors; i++) {
8240 q_vector = adapter->q_vector[i];
8241 if (adapter->flags & IGB_FLAG_HAS_MSIX)
8242 wr32(E1000_EIMC, q_vector->eims_value);
8244 igb_irq_disable(adapter);
8245 napi_schedule(&q_vector->napi);
8248 #endif /* CONFIG_NET_POLL_CONTROLLER */
8251 * igb_io_error_detected - called when PCI error is detected
8252 * @pdev: Pointer to PCI device
8253 * @state: The current pci connection state
8255 * This function is called after a PCI bus error affecting
8256 * this device has been detected.
8258 static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
8259 pci_channel_state_t state)
8261 struct net_device *netdev = pci_get_drvdata(pdev);
8262 struct igb_adapter *adapter = netdev_priv(netdev);
8264 if (state == pci_channel_io_normal) {
8265 dev_warn(&pdev->dev, "Non-correctable non-fatal error reported.\n");
8266 return PCI_ERS_RESULT_CAN_RECOVER;
8269 netif_device_detach(netdev);
8271 if (state == pci_channel_io_perm_failure)
8272 return PCI_ERS_RESULT_DISCONNECT;
8274 if (netif_running(netdev))
8276 pci_disable_device(pdev);
8278 /* Request a slot slot reset. */
8279 return PCI_ERS_RESULT_NEED_RESET;
8283 * igb_io_slot_reset - called after the pci bus has been reset.
8284 * @pdev: Pointer to PCI device
8286 * Restart the card from scratch, as if from a cold-boot. Implementation
8287 * resembles the first-half of the igb_resume routine.
8289 static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
8291 struct net_device *netdev = pci_get_drvdata(pdev);
8292 struct igb_adapter *adapter = netdev_priv(netdev);
8293 struct e1000_hw *hw = &adapter->hw;
8294 pci_ers_result_t result;
8297 if (pci_enable_device_mem(pdev)) {
8299 "Cannot re-enable PCI device after reset.\n");
8300 result = PCI_ERS_RESULT_DISCONNECT;
8302 pci_set_master(pdev);
8303 pci_restore_state(pdev);
8304 pci_save_state(pdev);
8306 pci_enable_wake(pdev, PCI_D3hot, 0);
8307 pci_enable_wake(pdev, PCI_D3cold, 0);
8309 /* In case of PCI error, adapter lose its HW address
8310 * so we should re-assign it here.
8312 hw->hw_addr = adapter->io_addr;
8315 wr32(E1000_WUS, ~0);
8316 result = PCI_ERS_RESULT_RECOVERED;
8319 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8322 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
8324 /* non-fatal, continue */
8331 * igb_io_resume - called when traffic can start flowing again.
8332 * @pdev: Pointer to PCI device
8334 * This callback is called when the error recovery driver tells us that
8335 * its OK to resume normal operation. Implementation resembles the
8336 * second-half of the igb_resume routine.
8338 static void igb_io_resume(struct pci_dev *pdev)
8340 struct net_device *netdev = pci_get_drvdata(pdev);
8341 struct igb_adapter *adapter = netdev_priv(netdev);
8343 if (netif_running(netdev)) {
8344 if (igb_up(adapter)) {
8345 dev_err(&pdev->dev, "igb_up failed after reset\n");
8350 netif_device_attach(netdev);
8352 /* let the f/w know that the h/w is now under the control of the
8355 igb_get_hw_control(adapter);
8359 * igb_rar_set_index - Sync RAL[index] and RAH[index] registers with MAC table
8360 * @adapter: Pointer to adapter structure
8361 * @index: Index of the RAR entry which need to be synced with MAC table
8363 static void igb_rar_set_index(struct igb_adapter *adapter, u32 index)
8365 struct e1000_hw *hw = &adapter->hw;
8366 u32 rar_low, rar_high;
8367 u8 *addr = adapter->mac_table[index].addr;
8369 /* HW expects these to be in network order when they are plugged
8370 * into the registers which are little endian. In order to guarantee
8371 * that ordering we need to do an leXX_to_cpup here in order to be
8372 * ready for the byteswap that occurs with writel
8374 rar_low = le32_to_cpup((__le32 *)(addr));
8375 rar_high = le16_to_cpup((__le16 *)(addr + 4));
8377 /* Indicate to hardware the Address is Valid. */
8378 if (adapter->mac_table[index].state & IGB_MAC_STATE_IN_USE) {
8379 if (is_valid_ether_addr(addr))
8380 rar_high |= E1000_RAH_AV;
8382 switch (hw->mac.type) {
8385 rar_high |= E1000_RAH_POOL_1 *
8386 adapter->mac_table[index].queue;
8389 rar_high |= E1000_RAH_POOL_1 <<
8390 adapter->mac_table[index].queue;
8395 wr32(E1000_RAL(index), rar_low);
8397 wr32(E1000_RAH(index), rar_high);
8401 static int igb_set_vf_mac(struct igb_adapter *adapter,
8402 int vf, unsigned char *mac_addr)
8404 struct e1000_hw *hw = &adapter->hw;
8405 /* VF MAC addresses start at end of receive addresses and moves
8406 * towards the first, as a result a collision should not be possible
8408 int rar_entry = hw->mac.rar_entry_count - (vf + 1);
8409 unsigned char *vf_mac_addr = adapter->vf_data[vf].vf_mac_addresses;
8411 ether_addr_copy(vf_mac_addr, mac_addr);
8412 ether_addr_copy(adapter->mac_table[rar_entry].addr, mac_addr);
8413 adapter->mac_table[rar_entry].queue = vf;
8414 adapter->mac_table[rar_entry].state |= IGB_MAC_STATE_IN_USE;
8415 igb_rar_set_index(adapter, rar_entry);
8420 static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
8422 struct igb_adapter *adapter = netdev_priv(netdev);
8424 if (vf >= adapter->vfs_allocated_count)
8427 /* Setting the VF MAC to 0 reverts the IGB_VF_FLAG_PF_SET_MAC
8428 * flag and allows to overwrite the MAC via VF netdev. This
8429 * is necessary to allow libvirt a way to restore the original
8430 * MAC after unbinding vfio-pci and reloading igbvf after shutting
8433 if (is_zero_ether_addr(mac)) {
8434 adapter->vf_data[vf].flags &= ~IGB_VF_FLAG_PF_SET_MAC;
8435 dev_info(&adapter->pdev->dev,
8436 "remove administratively set MAC on VF %d\n",
8438 } else if (is_valid_ether_addr(mac)) {
8439 adapter->vf_data[vf].flags |= IGB_VF_FLAG_PF_SET_MAC;
8440 dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n",
8442 dev_info(&adapter->pdev->dev,
8443 "Reload the VF driver to make this change effective.");
8444 /* Generate additional warning if PF is down */
8445 if (test_bit(__IGB_DOWN, &adapter->state)) {
8446 dev_warn(&adapter->pdev->dev,
8447 "The VF MAC address has been set, but the PF device is not up.\n");
8448 dev_warn(&adapter->pdev->dev,
8449 "Bring the PF device up before attempting to use the VF device.\n");
8454 return igb_set_vf_mac(adapter, vf, mac);
8457 static int igb_link_mbps(int internal_link_speed)
8459 switch (internal_link_speed) {
8469 static void igb_set_vf_rate_limit(struct e1000_hw *hw, int vf, int tx_rate,
8476 /* Calculate the rate factor values to set */
8477 rf_int = link_speed / tx_rate;
8478 rf_dec = (link_speed - (rf_int * tx_rate));
8479 rf_dec = (rf_dec * BIT(E1000_RTTBCNRC_RF_INT_SHIFT)) /
8482 bcnrc_val = E1000_RTTBCNRC_RS_ENA;
8483 bcnrc_val |= ((rf_int << E1000_RTTBCNRC_RF_INT_SHIFT) &
8484 E1000_RTTBCNRC_RF_INT_MASK);
8485 bcnrc_val |= (rf_dec & E1000_RTTBCNRC_RF_DEC_MASK);
8490 wr32(E1000_RTTDQSEL, vf); /* vf X uses queue X */
8491 /* Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
8492 * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported.
8494 wr32(E1000_RTTBCNRM, 0x14);
8495 wr32(E1000_RTTBCNRC, bcnrc_val);
8498 static void igb_check_vf_rate_limit(struct igb_adapter *adapter)
8500 int actual_link_speed, i;
8501 bool reset_rate = false;
8503 /* VF TX rate limit was not set or not supported */
8504 if ((adapter->vf_rate_link_speed == 0) ||
8505 (adapter->hw.mac.type != e1000_82576))
8508 actual_link_speed = igb_link_mbps(adapter->link_speed);
8509 if (actual_link_speed != adapter->vf_rate_link_speed) {
8511 adapter->vf_rate_link_speed = 0;
8512 dev_info(&adapter->pdev->dev,
8513 "Link speed has been changed. VF Transmit rate is disabled\n");
8516 for (i = 0; i < adapter->vfs_allocated_count; i++) {
8518 adapter->vf_data[i].tx_rate = 0;
8520 igb_set_vf_rate_limit(&adapter->hw, i,
8521 adapter->vf_data[i].tx_rate,
8526 static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf,
8527 int min_tx_rate, int max_tx_rate)
8529 struct igb_adapter *adapter = netdev_priv(netdev);
8530 struct e1000_hw *hw = &adapter->hw;
8531 int actual_link_speed;
8533 if (hw->mac.type != e1000_82576)
8539 actual_link_speed = igb_link_mbps(adapter->link_speed);
8540 if ((vf >= adapter->vfs_allocated_count) ||
8541 (!(rd32(E1000_STATUS) & E1000_STATUS_LU)) ||
8542 (max_tx_rate < 0) ||
8543 (max_tx_rate > actual_link_speed))
8546 adapter->vf_rate_link_speed = actual_link_speed;
8547 adapter->vf_data[vf].tx_rate = (u16)max_tx_rate;
8548 igb_set_vf_rate_limit(hw, vf, max_tx_rate, actual_link_speed);
8553 static int igb_ndo_set_vf_spoofchk(struct net_device *netdev, int vf,
8556 struct igb_adapter *adapter = netdev_priv(netdev);
8557 struct e1000_hw *hw = &adapter->hw;
8558 u32 reg_val, reg_offset;
8560 if (!adapter->vfs_allocated_count)
8563 if (vf >= adapter->vfs_allocated_count)
8566 reg_offset = (hw->mac.type == e1000_82576) ? E1000_DTXSWC : E1000_TXSWC;
8567 reg_val = rd32(reg_offset);
8569 reg_val |= (BIT(vf) |
8570 BIT(vf + E1000_DTXSWC_VLAN_SPOOF_SHIFT));
8572 reg_val &= ~(BIT(vf) |
8573 BIT(vf + E1000_DTXSWC_VLAN_SPOOF_SHIFT));
8574 wr32(reg_offset, reg_val);
8576 adapter->vf_data[vf].spoofchk_enabled = setting;
8580 static int igb_ndo_get_vf_config(struct net_device *netdev,
8581 int vf, struct ifla_vf_info *ivi)
8583 struct igb_adapter *adapter = netdev_priv(netdev);
8584 if (vf >= adapter->vfs_allocated_count)
8587 memcpy(&ivi->mac, adapter->vf_data[vf].vf_mac_addresses, ETH_ALEN);
8588 ivi->max_tx_rate = adapter->vf_data[vf].tx_rate;
8589 ivi->min_tx_rate = 0;
8590 ivi->vlan = adapter->vf_data[vf].pf_vlan;
8591 ivi->qos = adapter->vf_data[vf].pf_qos;
8592 ivi->spoofchk = adapter->vf_data[vf].spoofchk_enabled;
8596 static void igb_vmm_control(struct igb_adapter *adapter)
8598 struct e1000_hw *hw = &adapter->hw;
8601 switch (hw->mac.type) {
8607 /* replication is not supported for 82575 */
8610 /* notify HW that the MAC is adding vlan tags */
8611 reg = rd32(E1000_DTXCTL);
8612 reg |= E1000_DTXCTL_VLAN_ADDED;
8613 wr32(E1000_DTXCTL, reg);
8616 /* enable replication vlan tag stripping */
8617 reg = rd32(E1000_RPLOLR);
8618 reg |= E1000_RPLOLR_STRVLAN;
8619 wr32(E1000_RPLOLR, reg);
8622 /* none of the above registers are supported by i350 */
8626 if (adapter->vfs_allocated_count) {
8627 igb_vmdq_set_loopback_pf(hw, true);
8628 igb_vmdq_set_replication_pf(hw, true);
8629 igb_vmdq_set_anti_spoofing_pf(hw, true,
8630 adapter->vfs_allocated_count);
8632 igb_vmdq_set_loopback_pf(hw, false);
8633 igb_vmdq_set_replication_pf(hw, false);
8637 static void igb_init_dmac(struct igb_adapter *adapter, u32 pba)
8639 struct e1000_hw *hw = &adapter->hw;
8644 if (hw->mac.type > e1000_82580) {
8645 if (adapter->flags & IGB_FLAG_DMAC) {
8646 /* force threshold to 0. */
8647 wr32(E1000_DMCTXTH, 0);
8649 /* DMA Coalescing high water mark needs to be greater
8650 * than the Rx threshold. Set hwm to PBA - max frame
8651 * size in 16B units, capping it at PBA - 6KB.
8653 hwm = 64 * (pba - 6);
8654 reg = rd32(E1000_FCRTC);
8655 reg &= ~E1000_FCRTC_RTH_COAL_MASK;
8656 reg |= ((hwm << E1000_FCRTC_RTH_COAL_SHIFT)
8657 & E1000_FCRTC_RTH_COAL_MASK);
8658 wr32(E1000_FCRTC, reg);
8660 /* Set the DMA Coalescing Rx threshold to PBA - 2 * max
8661 * frame size, capping it at PBA - 10KB.
8663 dmac_thr = pba - 10;
8664 reg = rd32(E1000_DMACR);
8665 reg &= ~E1000_DMACR_DMACTHR_MASK;
8666 reg |= ((dmac_thr << E1000_DMACR_DMACTHR_SHIFT)
8667 & E1000_DMACR_DMACTHR_MASK);
8669 /* transition to L0x or L1 if available..*/
8670 reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK);
8672 /* watchdog timer= +-1000 usec in 32usec intervals */
8675 /* Disable BMC-to-OS Watchdog Enable */
8676 if (hw->mac.type != e1000_i354)
8677 reg &= ~E1000_DMACR_DC_BMC2OSW_EN;
8678 wr32(E1000_DMACR, reg);
8680 /* no lower threshold to disable
8681 * coalescing(smart fifb)-UTRESH=0
8683 wr32(E1000_DMCRTRH, 0);
8685 reg = (IGB_DMCTLX_DCFLUSH_DIS | 0x4);
8687 wr32(E1000_DMCTLX, reg);
8689 /* free space in tx packet buffer to wake from
8692 wr32(E1000_DMCTXTH, (IGB_MIN_TXPBSIZE -
8693 (IGB_TX_BUF_4096 + adapter->max_frame_size)) >> 6);
8696 if (hw->mac.type >= e1000_i210 ||
8697 (adapter->flags & IGB_FLAG_DMAC)) {
8698 reg = rd32(E1000_PCIEMISC);
8699 reg |= E1000_PCIEMISC_LX_DECISION;
8700 wr32(E1000_PCIEMISC, reg);
8701 } /* endif adapter->dmac is not disabled */
8702 } else if (hw->mac.type == e1000_82580) {
8703 u32 reg = rd32(E1000_PCIEMISC);
8705 wr32(E1000_PCIEMISC, reg & ~E1000_PCIEMISC_LX_DECISION);
8706 wr32(E1000_DMACR, 0);
8711 * igb_read_i2c_byte - Reads 8 bit word over I2C
8712 * @hw: pointer to hardware structure
8713 * @byte_offset: byte offset to read
8714 * @dev_addr: device address
8717 * Performs byte read operation over I2C interface at
8718 * a specified device address.
8720 s32 igb_read_i2c_byte(struct e1000_hw *hw, u8 byte_offset,
8721 u8 dev_addr, u8 *data)
8723 struct igb_adapter *adapter = container_of(hw, struct igb_adapter, hw);
8724 struct i2c_client *this_client = adapter->i2c_client;
8729 return E1000_ERR_I2C;
8731 swfw_mask = E1000_SWFW_PHY0_SM;
8733 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
8734 return E1000_ERR_SWFW_SYNC;
8736 status = i2c_smbus_read_byte_data(this_client, byte_offset);
8737 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
8740 return E1000_ERR_I2C;
8748 * igb_write_i2c_byte - Writes 8 bit word over I2C
8749 * @hw: pointer to hardware structure
8750 * @byte_offset: byte offset to write
8751 * @dev_addr: device address
8752 * @data: value to write
8754 * Performs byte write operation over I2C interface at
8755 * a specified device address.
8757 s32 igb_write_i2c_byte(struct e1000_hw *hw, u8 byte_offset,
8758 u8 dev_addr, u8 data)
8760 struct igb_adapter *adapter = container_of(hw, struct igb_adapter, hw);
8761 struct i2c_client *this_client = adapter->i2c_client;
8763 u16 swfw_mask = E1000_SWFW_PHY0_SM;
8766 return E1000_ERR_I2C;
8768 if (hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
8769 return E1000_ERR_SWFW_SYNC;
8770 status = i2c_smbus_write_byte_data(this_client, byte_offset, data);
8771 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
8774 return E1000_ERR_I2C;
8780 int igb_reinit_queues(struct igb_adapter *adapter)
8782 struct net_device *netdev = adapter->netdev;
8783 struct pci_dev *pdev = adapter->pdev;
8786 if (netif_running(netdev))
8789 igb_reset_interrupt_capability(adapter);
8791 if (igb_init_interrupt_scheme(adapter, true)) {
8792 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
8796 if (netif_running(netdev))
8797 err = igb_open(netdev);
8802 static void igb_nfc_filter_exit(struct igb_adapter *adapter)
8804 struct igb_nfc_filter *rule;
8806 spin_lock(&adapter->nfc_lock);
8808 hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node)
8809 igb_erase_filter(adapter, rule);
8811 spin_unlock(&adapter->nfc_lock);
8814 static void igb_nfc_filter_restore(struct igb_adapter *adapter)
8816 struct igb_nfc_filter *rule;
8818 spin_lock(&adapter->nfc_lock);
8820 hlist_for_each_entry(rule, &adapter->nfc_filter_list, nfc_node)
8821 igb_add_filter(adapter, rule);
8823 spin_unlock(&adapter->nfc_lock);